From patchwork Wed Nov 1 13:13:52 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 160542 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:abcd:0:b0:403:3b70:6f57 with SMTP id f13csp408771vqx; Wed, 1 Nov 2023 06:14:33 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEgoOTuWPePYf/MuHo85N4UmlIwxB0sDl5QUClYhlxdcJ7Hbj2A3bypH++piJWQgg715ZWN X-Received: by 2002:a05:6a20:7487:b0:17e:498c:7553 with SMTP id p7-20020a056a20748700b0017e498c7553mr14492006pzd.51.1698844472963; Wed, 01 Nov 2023 06:14:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1698844472; cv=none; d=google.com; s=arc-20160816; b=pwf68VIii+vcDA3hggsSfvWQtnUuUM3pDcPEfutcjlyhZ6ZJ/63JyZbOTn9Sf7jkAr KcPZjeItOOLXHUeLDVklaUgYydlj2R+r7w56+EktzQQ5XX8oUxcRba4lhUy1OuXtz7Ay m5nuvbqpP3/jSoC4xopDP245Pas1Ly/5eHNgm5BIS2Y65c8R085W+mxglWqx0I4qZ2y4 tQCeGSnaY4yWk9uEgbohCyKOfGdd5MYIsPaPQSIdaT1mjM5crXHmRnHD+D+McQ4Z1NdI 5dHE2j/hR8nLXycV7BdMoq8Hguuhy12DM6zCO4hUanQwzqna0fRVbUsDbDdkf0djZbKt v1eg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=S0cqoO4ULZEk3tjCjNQPGpvL4UCucxWW2rS+zzf6Bkk=; fh=pzDjuBW6iTH3lRufj60HcOrI13gwrAMAibI8ac4xXMg=; b=zBG+vDJORunTYmk6lAiC8mHzGREK4zzyRHxKoWdwWXVB1nuSiG5e2tnboKXPQoA8XH f4jXpRVq9fdhTDfzovjKWP1YvqyTeXQPdJt/TomtiUxJCC7sS7CR3KUQHAj/wgRFfu7c TZ+gFoqPQRYe3MzqPsejBtT/7CQVad7ISFOipiZVhR2+t3w6KFN78wDI7kqvLGCTw0tC ukldECCWHnrlK2w1ixkYEkBvk0eCXdI1Ek90BdWI6+H9Dw8/1AGInvGCgItqTdQKcGJq iMTnhe42d7QLYQ+PCwZQ4FwNhbNu723M6rQhe81V5Y/OY7OWgMa4/rhBq5gcERdNPqIB yw9w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=bImg6fEe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id n4-20020a170902e54400b001cc5ada2b94si3136927plf.366.2023.11.01.06.14.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 01 Nov 2023 06:14:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b=bImg6fEe; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 00C1280E0686; Wed, 1 Nov 2023 06:14:28 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343916AbjKANOX (ORCPT + 35 others); Wed, 1 Nov 2023 09:14:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36554 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1344095AbjKANOS (ORCPT ); Wed, 1 Nov 2023 09:14:18 -0400 Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4691410D; Wed, 1 Nov 2023 06:14:12 -0700 (PDT) Received: from Monstersaurus.local (aztw-30-b2-v4wan-166917-cust845.vm26.cable.virginm.net [82.37.23.78]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 9774FEBA; Wed, 1 Nov 2023 14:13:44 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1698844424; bh=rWqdVjp7cdOWjdFZPS8Nn5D09Y53JzqDLSoZWcTjgF4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=bImg6fEeNxbDUz7l93KsXXvYgzoCcsZJtiYswKpRuhZhICoR7oxMvu3IDaeVdHY+Q XLubV0n9hBYo05GmNQQW3fCAC6KKv110dM7rTVKwaMc0DWxKc6QbdIDXQgdo58pdZz Fluc25+lMvmCDC/zsOyoNeF1u8ySBnbyZzpSnrcM= From: Kieran Bingham To: devicetree@vger.kernel.org, linux-media@vger.kernel.org Cc: Kieran Bingham , "Paul J. Murphy" , Daniele Alessandrelli , Sakari Ailus , Mauro Carvalho Chehab , linux-kernel@vger.kernel.org (open list) Subject: [PATCH v2 4/6] media: i2c: imx335: Enable regulator supplies Date: Wed, 1 Nov 2023 13:13:52 +0000 Message-Id: <20231101131354.2333498-5-kieran.bingham@ideasonboard.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20231101131354.2333498-1-kieran.bingham@ideasonboard.com> References: <20231101131354.2333498-1-kieran.bingham@ideasonboard.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 01 Nov 2023 06:14:28 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1781367542071051769 X-GMAIL-MSGID: 1781367542071051769 Provide support for enabling and disabling regulator supplies to control power to the camera sensor. While updating the power on function, document that a sleep is represented as 'T4' in the datasheet power on sequence. Signed-off-by: Kieran Bingham --- v2: - document 'supplies' member variable - disable regulators in error path - Remove 'unhelpful' comments Signed-off-by: Kieran Bingham --- drivers/media/i2c/imx335.c | 38 ++++++++++++++++++++++++++++++++++++-- 1 file changed, 36 insertions(+), 2 deletions(-) diff --git a/drivers/media/i2c/imx335.c b/drivers/media/i2c/imx335.c index 31c612c6bdd8..f17ce40b9c77 100644 --- a/drivers/media/i2c/imx335.c +++ b/drivers/media/i2c/imx335.c @@ -75,6 +75,14 @@ struct imx335_reg_list { const struct imx335_reg *regs; }; +static const char * const imx335_supply_name[] = { + "avdd", /* Analog (2.9V) supply */ + "ovdd", /* Digital I/O (1.8V) supply */ + "dvdd", /* Digital Core (1.2V) supply */ +}; + +#define IMX335_NUM_SUPPLIES ARRAY_SIZE(imx335_supply_name) + /** * struct imx335_mode - imx335 sensor mode structure * @width: Frame width @@ -108,6 +116,7 @@ struct imx335_mode { * @sd: V4L2 sub-device * @pad: Media pad. Only one pad supported * @reset_gpio: Sensor reset gpio + * @supplies: Regulator supplies to handle power control * @inclk: Sensor input clock * @ctrl_handler: V4L2 control handler * @link_freq_ctrl: Pointer to link frequency control @@ -126,6 +135,8 @@ struct imx335 { struct v4l2_subdev sd; struct media_pad pad; struct gpio_desc *reset_gpio; + struct regulator_bulk_data supplies[IMX335_NUM_SUPPLIES]; + struct clk *inclk; struct v4l2_ctrl_handler ctrl_handler; struct v4l2_ctrl *link_freq_ctrl; @@ -781,6 +792,17 @@ static int imx335_parse_hw_config(struct imx335 *imx335) return PTR_ERR(imx335->reset_gpio); } + for (i = 0; i < IMX335_NUM_SUPPLIES; i++) + imx335->supplies[i].supply = imx335_supply_name[i]; + + ret = devm_regulator_bulk_get(imx335->dev, + IMX335_NUM_SUPPLIES, + imx335->supplies); + if (ret) { + dev_err(imx335->dev, "Failed to get regulators\n"); + return ret; + } + /* Get sensor input clock */ imx335->inclk = devm_clk_get(imx335->dev, NULL); if (IS_ERR(imx335->inclk)) { @@ -863,6 +885,17 @@ static int imx335_power_on(struct device *dev) struct imx335 *imx335 = to_imx335(sd); int ret; + ret = regulator_bulk_enable(IMX335_NUM_SUPPLIES, + imx335->supplies); + if (ret) { + dev_err(dev, "%s: failed to enable regulators\n", + __func__); + return ret; + } + + usleep_range(500, 550); /* Tlow */ + + /* Set XCLR */ gpiod_set_value_cansleep(imx335->reset_gpio, 1); ret = clk_prepare_enable(imx335->inclk); @@ -871,12 +904,13 @@ static int imx335_power_on(struct device *dev) goto error_reset; } - usleep_range(20, 22); + usleep_range(20, 22); /* T4 */ return 0; error_reset: gpiod_set_value_cansleep(imx335->reset_gpio, 0); + regulator_bulk_disable(IMX335_NUM_SUPPLIES, imx335->supplies); return ret; } @@ -893,8 +927,8 @@ static int imx335_power_off(struct device *dev) struct imx335 *imx335 = to_imx335(sd); gpiod_set_value_cansleep(imx335->reset_gpio, 0); - clk_disable_unprepare(imx335->inclk); + regulator_bulk_disable(IMX335_NUM_SUPPLIES, imx335->supplies); return 0; }