From patchwork Thu Nov 28 15:23:35 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13888165 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 9EF7E847B for ; Thu, 28 Nov 2024 15:23:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732807434; cv=none; b=gGWRW2S45h/b1wMVu6siXhtkRLWauPHAXtMnK9LEsQpFPj0hpM2iWH9yrFy/jFH0rmBBGZkDy2ZiQcwk/Jp8DKPC0P0W/3P2icJ/lCB77b+9QJVGOBgO0OnGk1XeAiVkvBD0CL3fJLMribi1pUynd7WIVsmyBP6wq1NuT5+uMAc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732807434; c=relaxed/simple; bh=xoG/VHpr+QoxBmHeYUYAzAJ5O6ry77abPWPhs2PwPxA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=KnRjteVwifS9bDj29z35WEKmAJSXKS1N6+/oXzpEfx8A9kbncnwoDHIMNxBU2h6PXq4QrSiCJ8Tg2Twkg5lITlSCwGriTOzmGwODFzFpMAg8p5Hz/CNzcEck8tdq23zJRlGWlkDf7SK3BetOpzePg8PkBzCugsjvKd3Mg+0NUqI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=FKdfNihd; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FKdfNihd" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732807431; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vLGFkY7C3wP0n8eTAaprK6q2X74+CdPRsHkduFusCyM=; b=FKdfNihdkBsYgtFxkHcpvXiaY4ZhLDBxh55O4+LGCnl27O+cMxEtPPMahjOOxk05+Y5lHg UeYJCeXfX522a2PrUPoZsW1xl853F1hKwtWydXEnDhqcvbIGR5W7x7zpZGTOpfLL3qYuL2 tOrndgWgcooO7aEFM+LbT66jOdwi7vc= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-22-2V6JzWGdNvmF85kFn1GJyQ-1; Thu, 28 Nov 2024 10:23:47 -0500 X-MC-Unique: 2V6JzWGdNvmF85kFn1GJyQ-1 X-Mimecast-MFC-AGG-ID: 2V6JzWGdNvmF85kFn1GJyQ Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id ACEC019560A3; Thu, 28 Nov 2024 15:23:46 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.193.119]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id A99B6195608A; Thu, 28 Nov 2024 15:23:44 +0000 (UTC) From: Hans de Goede To: Tianshu Qiu , Sakari Ailus , Bingbu Cao Cc: Hans de Goede , linux-media@vger.kernel.org Subject: [PATCH 1/4] media: ov2740: Debug log chip ID Date: Thu, 28 Nov 2024 16:23:35 +0100 Message-ID: <20241128152338.4583-2-hdegoede@redhat.com> In-Reply-To: <20241128152338.4583-1-hdegoede@redhat.com> References: <20241128152338.4583-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Calling the identify function may get delayed till the first stream-on, add a dev_dbg() to it so that we know when it has run. This is useful to debug bring-up problems related to regulators / clks / GPIOs. Signed-off-by: Hans de Goede --- drivers/media/i2c/ov2740.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/media/i2c/ov2740.c b/drivers/media/i2c/ov2740.c index 387c529d9736..e7a611967b40 100644 --- a/drivers/media/i2c/ov2740.c +++ b/drivers/media/i2c/ov2740.c @@ -644,6 +644,8 @@ static int ov2740_identify_module(struct ov2740 *ov2740) return -ENXIO; } + dev_dbg(&client->dev, "chip id: %x\n", val); + ov2740->identified = true; return 0; From patchwork Thu Nov 28 15:23:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13888166 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03B93199253 for ; Thu, 28 Nov 2024 15:23:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732807439; cv=none; b=rnaf29+tZ4eJgL2QRQ+Vhv+2RzSQu0ZFibZ4PvwzaEUsWpAUyae5bUlzgnEyPzKSDccLRn7qcUaQgEa8MTC+g9xw3PnS3MDHX7yDhzNd5kJOseASEAACkhf5+bthqfNFW0LFnN3Kh2IN6tegJHR/IZzdy/2izVQmRasQhwXBy8g= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732807439; c=relaxed/simple; bh=fsmNA5zn091LnVslxdBPWwKHwDzJf5S4jEX1B1cFVrE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cCwPh3/WywYnVXo1t+Fd44j4MfijvOEN1n0AHuj6hVV2/9b9FW1VXHVbrrCL6TbRB9RcIexKnekXuBUC8m8cDjkXoSZcjYsG/7PlAk0J8ibJneBCt6OTxfb6PxvJiQIb+BQ+TQdr7th0txVKXgVGGFQug3WVZ11yJGYzC9KROGU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=PtZQLiOI; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PtZQLiOI" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732807435; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xNVIZ6mq27cS4rItESewJ3EUgT5RCW9F0JluKeyqQFE=; b=PtZQLiOINJLd9dyZ+sFPYvIqBdrKmBwVZauxUXKA8UqL4CQ/HEG7VM7xRXV+rMWmCLCHXE /05YlMaEHjJMhbfbl7vZ7mUix8xPLSvrDS7/pg3/q7JnC4ddzre50PMIjs2/GfQ1GwlzRU 7/W8NLo4qT4ZieK0cbz6PoBv95axrps= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-301-wNhiZlpzPtyZAjrJManvqA-1; Thu, 28 Nov 2024 10:23:50 -0500 X-MC-Unique: wNhiZlpzPtyZAjrJManvqA-1 X-Mimecast-MFC-AGG-ID: wNhiZlpzPtyZAjrJManvqA Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 71D951955F33; Thu, 28 Nov 2024 15:23:49 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.193.119]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 48AA0195608A; Thu, 28 Nov 2024 15:23:46 +0000 (UTC) From: Hans de Goede To: Tianshu Qiu , Sakari Ailus , Bingbu Cao Cc: Hans de Goede , linux-media@vger.kernel.org Subject: [PATCH 2/4] media: ov2740: Add camera orientation and sensor rotation controls Date: Thu, 28 Nov 2024 16:23:36 +0100 Message-ID: <20241128152338.4583-3-hdegoede@redhat.com> In-Reply-To: <20241128152338.4583-1-hdegoede@redhat.com> References: <20241128152338.4583-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 Add camera orientation and sensor rotation controls using the v4l2_fwnode_device_parse() and v4l2_ctrl_new_fwnode_properties() helpers. Signed-off-by: Hans de Goede --- drivers/media/i2c/ov2740.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/drivers/media/i2c/ov2740.c b/drivers/media/i2c/ov2740.c index e7a611967b40..998e1977978d 100644 --- a/drivers/media/i2c/ov2740.c +++ b/drivers/media/i2c/ov2740.c @@ -755,15 +755,17 @@ static const struct v4l2_ctrl_ops ov2740_ctrl_ops = { static int ov2740_init_controls(struct ov2740 *ov2740) { + struct i2c_client *client = v4l2_get_subdevdata(&ov2740->sd); struct v4l2_ctrl_handler *ctrl_hdlr; const struct ov2740_mode *cur_mode; s64 exposure_max, h_blank, pixel_rate; u32 vblank_min, vblank_max, vblank_default; + struct v4l2_fwnode_device_properties props; int size; int ret; ctrl_hdlr = &ov2740->ctrl_handler; - ret = v4l2_ctrl_handler_init(ctrl_hdlr, 8); + ret = v4l2_ctrl_handler_init(ctrl_hdlr, 10); if (ret) return ret; @@ -813,6 +815,13 @@ static int ov2740_init_controls(struct ov2740 *ov2740) V4L2_CID_TEST_PATTERN, ARRAY_SIZE(ov2740_test_pattern_menu) - 1, 0, 0, ov2740_test_pattern_menu); + + ret = v4l2_fwnode_device_parse(&client->dev, &props); + if (ret) + return ret; + + v4l2_ctrl_new_fwnode_properties(ctrl_hdlr, &ov2740_ctrl_ops, &props); + if (ctrl_hdlr->error) { v4l2_ctrl_handler_free(ctrl_hdlr); return ctrl_hdlr->error; From patchwork Thu Nov 28 15:23:37 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13888168 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2A94D1BB6A0 for ; Thu, 28 Nov 2024 15:23:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732807442; cv=none; b=r53Q3cqtGwuQvZa20Jjj8zO3RpXDaqYLSmnVk5EO0+e1GdoxqwATss5VmYmIO9a8gXfwZeVDbD4h8aHCH8dJ9l8TmlRMBYcvdr+MGWGRMnveLLpAOZM3Eqyk4rGo2cIdENMQaSgWIXrNbdJoiD0fE7zlZD/7YYAhl8b0NwIcWpU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732807442; c=relaxed/simple; bh=BoO73raussRA7CNeRG2fXLuf5/3JLbH82UaHoSFRqow=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=EPFgsjsjYlgtSAERCmvvUENbwgf3PCO22GkCH8YH+OD9GgXcbJRF+TrMjX5pwwemy81vJdSdpF3/vPPb+5r5m88qRiLujZ+FKl9r9YwN94wBHEyaImoUVgBNJJjaxw4ns6rJtMe+aCYvgKlV0lX/tAd3FlEYradwEhh/TTwqJh0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=BBwlR2c0; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="BBwlR2c0" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732807439; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xnpBELolWXPjgsDU9LMfupQlXW2NYouC49hueeD7KrQ=; b=BBwlR2c0vllJ4MX0dvfoXi4VU5Zt4RYNkdZsquiRAtT+W0ejcim1gTwKxiHHNHTZueK2Jz crlOxpIdn41ftKTtKmdK1XDzTNWMX4NHwipo9MX/3Zcc2IDhQug0hanh1Rcw+5KmztIp56 VSi8W7E3+fOuS4Ai4XcRDJmcZv0LhBU= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-219-ERAyju75MmCXicA4_GvOzA-1; Thu, 28 Nov 2024 10:23:55 -0500 X-MC-Unique: ERAyju75MmCXicA4_GvOzA-1 X-Mimecast-MFC-AGG-ID: ERAyju75MmCXicA4_GvOzA Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 205F41956058; Thu, 28 Nov 2024 15:23:52 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.193.119]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 0E69D195608A; Thu, 28 Nov 2024 15:23:49 +0000 (UTC) From: Hans de Goede To: Tianshu Qiu , Sakari Ailus , Bingbu Cao Cc: Hans de Goede , linux-media@vger.kernel.org Subject: [PATCH 3/4] media: ov2740: Add powerdown GPIO support Date: Thu, 28 Nov 2024 16:23:37 +0100 Message-ID: <20241128152338.4583-4-hdegoede@redhat.com> In-Reply-To: <20241128152338.4583-1-hdegoede@redhat.com> References: <20241128152338.4583-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 The ov2740 sensor has both reset and power_down inputs according to the datasheet one or the other should always be tied to DOVDD but on some designs both are attached to GPIOs. Add support for controlling both a reset and a powerdown GPIO. Signed-off-by: Hans de Goede Acked-by: Ricardo Ribalda --- drivers/media/i2c/ov2740.c | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/ov2740.c b/drivers/media/i2c/ov2740.c index 998e1977978d..14d0a0588cc2 100644 --- a/drivers/media/i2c/ov2740.c +++ b/drivers/media/i2c/ov2740.c @@ -525,6 +525,7 @@ struct ov2740 { /* GPIOs, clocks */ struct gpio_desc *reset_gpio; + struct gpio_desc *powerdown_gpio; struct clk *clk; /* Current mode */ @@ -1306,6 +1307,7 @@ static int ov2740_suspend(struct device *dev) struct ov2740 *ov2740 = to_ov2740(sd); gpiod_set_value_cansleep(ov2740->reset_gpio, 1); + gpiod_set_value_cansleep(ov2740->powerdown_gpio, 1); clk_disable_unprepare(ov2740->clk); return 0; } @@ -1320,6 +1322,7 @@ static int ov2740_resume(struct device *dev) if (ret) return ret; + gpiod_set_value_cansleep(ov2740->powerdown_gpio, 0); gpiod_set_value_cansleep(ov2740->reset_gpio, 0); msleep(20); @@ -1348,9 +1351,17 @@ static int ov2740_probe(struct i2c_client *client) if (IS_ERR(ov2740->reset_gpio)) { return dev_err_probe(dev, PTR_ERR(ov2740->reset_gpio), "failed to get reset GPIO\n"); - } else if (ov2740->reset_gpio) { + } + + ov2740->powerdown_gpio = devm_gpiod_get_optional(dev, "powerdown", GPIOD_OUT_HIGH); + if (IS_ERR(ov2740->powerdown_gpio)) { + return dev_err_probe(dev, PTR_ERR(ov2740->powerdown_gpio), + "failed to get powerdown GPIO\n"); + } + + if (ov2740->reset_gpio || ov2740->powerdown_gpio) { /* - * Ensure reset is asserted for at least 20 ms before + * Ensure reset/powerdown is asserted for at least 20 ms before * ov2740_resume() deasserts it. */ msleep(20); From patchwork Thu Nov 28 15:23:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans de Goede X-Patchwork-Id: 13888167 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id B5E091AA786 for ; Thu, 28 Nov 2024 15:23:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732807440; cv=none; b=Od0tGA+aNuDmYfFF2Zuj6b5TTIoFwJlM+WjlInxAFUtlYO8FNsMsv2u6NZZklrVFmGPpuKYTkxXju6OZAB7+lY3Cg/Fz+sJWZpMJZ2jpUYfCTz0yQmDQpJ0VVBE7Cz+xgxGdeY4aQd/UoluDPWKIcjt7mJ65FqsvJ6oQf7v9wSc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1732807440; c=relaxed/simple; bh=JYgHlUb3YN8+8fn39STft8qQzAmLWRHEtMbF/VNfKOU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Wl9Z6DNN221pof9EZ7xrqoTrJkJ6AC/L77Y3fO7CRZI9lQCO0V1kRVKQHm4Nc5Q9f/cgRPUqD/FSkIJpp8KfFv2+tviBFl8KkDBZxM7DA0V9B0dg3v6EPn8uBbgnmO2dTGhjtWfmByrqNPJVGgSZZuWnoHHbzhNLwwo1UN1eX3U= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=eAGEDzAv; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="eAGEDzAv" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1732807437; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BClqDHz1MUSrqKr7/8QlyH7q12CXxzhXJgq0LP5VI/U=; b=eAGEDzAvvzFJ5ZFMlzN3BhXOt384zZ3kD0/uk26wptpRIDIuxe18ZnofK6pdnMHiZBvxl6 GGg9xZ4+3jVYgChb0iKohT0c4QWVc3IjYQmH8S0Y1fewaqInOpuweAXeEfkR/KUEXrDnFb TEFqmyCZiN3YJqBTq3cOGeCA1vhRkQU= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-643-moo1d8epP8eF1rTBjjLjXw-1; Thu, 28 Nov 2024 10:23:56 -0500 X-MC-Unique: moo1d8epP8eF1rTBjjLjXw-1 X-Mimecast-MFC-AGG-ID: moo1d8epP8eF1rTBjjLjXw Received: from mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.15]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 0BD7C1955F45; Thu, 28 Nov 2024 15:23:55 +0000 (UTC) Received: from x1.localdomain.com (unknown [10.39.193.119]) by mx-prod-int-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id B0C991956095; Thu, 28 Nov 2024 15:23:52 +0000 (UTC) From: Hans de Goede To: Tianshu Qiu , Sakari Ailus , Bingbu Cao Cc: Hans de Goede , linux-media@vger.kernel.org Subject: [PATCH 4/4] media: ov2740: Add regulator support Date: Thu, 28 Nov 2024 16:23:38 +0100 Message-ID: <20241128152338.4583-5-hdegoede@redhat.com> In-Reply-To: <20241128152338.4583-1-hdegoede@redhat.com> References: <20241128152338.4583-1-hdegoede@redhat.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.0 on 10.30.177.15 On some designs the regulators for the AVDD / DOVDD / DVDD power rails are controlled by Linux. Add support to the driver for getting regulators for these 3 rails and for enabling these regulators when necessary. The datasheet specifies a delay of 0ns between enabling the regulators, IOW they can all 3 be enabled at the same time. This allows using the bulk regulator API. The regulator core will provide dummy regulators for the 3 power-rails when necessary. Signed-off-by: Hans de Goede Acked-by: Ricardo Ribalda --- drivers/media/i2c/ov2740.c | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/drivers/media/i2c/ov2740.c b/drivers/media/i2c/ov2740.c index 14d0a0588cc2..c766c1f83e12 100644 --- a/drivers/media/i2c/ov2740.c +++ b/drivers/media/i2c/ov2740.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -76,6 +77,14 @@ /* OTP registers from sensor */ #define OV2740_REG_OTP_CUSTOMER 0x7010 +static const char * const ov2740_supply_name[] = { + "AVDD", + "DOVDD", + "DVDD", +}; + +#define OV2740_NUM_SUPPLIES ARRAY_SIZE(ov2740_supply_name) + struct nvm_data { struct nvmem_device *nvmem; struct regmap *regmap; @@ -523,10 +532,11 @@ struct ov2740 { struct v4l2_ctrl *hblank; struct v4l2_ctrl *exposure; - /* GPIOs, clocks */ + /* GPIOs, clocks, regulators */ struct gpio_desc *reset_gpio; struct gpio_desc *powerdown_gpio; struct clk *clk; + struct regulator_bulk_data supplies[OV2740_NUM_SUPPLIES]; /* Current mode */ const struct ov2740_mode *cur_mode; @@ -1309,6 +1319,7 @@ static int ov2740_suspend(struct device *dev) gpiod_set_value_cansleep(ov2740->reset_gpio, 1); gpiod_set_value_cansleep(ov2740->powerdown_gpio, 1); clk_disable_unprepare(ov2740->clk); + regulator_bulk_disable(OV2740_NUM_SUPPLIES, ov2740->supplies); return 0; } @@ -1318,10 +1329,16 @@ static int ov2740_resume(struct device *dev) struct ov2740 *ov2740 = to_ov2740(sd); int ret; - ret = clk_prepare_enable(ov2740->clk); + ret = regulator_bulk_enable(OV2740_NUM_SUPPLIES, ov2740->supplies); if (ret) return ret; + ret = clk_prepare_enable(ov2740->clk); + if (ret) { + regulator_bulk_disable(OV2740_NUM_SUPPLIES, ov2740->supplies); + return ret; + } + gpiod_set_value_cansleep(ov2740->powerdown_gpio, 0); gpiod_set_value_cansleep(ov2740->reset_gpio, 0); msleep(20); @@ -1334,7 +1351,7 @@ static int ov2740_probe(struct i2c_client *client) struct device *dev = &client->dev; struct ov2740 *ov2740; bool full_power; - int ret; + int i, ret; ov2740 = devm_kzalloc(&client->dev, sizeof(*ov2740), GFP_KERNEL); if (!ov2740) @@ -1372,6 +1389,13 @@ static int ov2740_probe(struct i2c_client *client) return dev_err_probe(dev, PTR_ERR(ov2740->clk), "failed to get clock\n"); + for (i = 0; i < OV2740_NUM_SUPPLIES; i++) + ov2740->supplies[i].supply = ov2740_supply_name[i]; + + ret = devm_regulator_bulk_get(dev, OV2740_NUM_SUPPLIES, ov2740->supplies); + if (ret) + return dev_err_probe(dev, ret, "failed to get regulators\n"); + full_power = acpi_dev_state_d0(&client->dev); if (full_power) { /* ACPI does not always clear the reset GPIO / enable the clock */