Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp14365080rwb; Sun, 27 Nov 2022 23:14:08 -0800 (PST) X-Google-Smtp-Source: AA0mqf5y3D5nFjuyMIKJ5mYKdw8aIlmCsS7xmsBBnBUT5BbBRC0k0gGNmbx4C43M8PV9KMJL9ETC X-Received: by 2002:aa7:8054:0:b0:56c:4303:a93d with SMTP id y20-20020aa78054000000b0056c4303a93dmr34742294pfm.73.1669619648372; Sun, 27 Nov 2022 23:14:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669619648; cv=none; d=google.com; s=arc-20160816; b=uYyI4JCkvoatadMZIwHQUlFBuTHJK8EIdrysEC1s5CUmGZBv3NW8YdLBvVfySPAgqn 9tC8Wy0Yvb51LJhncuJNi6FJqsBIpdkJeGocLNxpp0m569d2KmDuE1hmMgAwxcrKLVuF 30lP2f4x0IwGxLOTVGrQyFqPXWrY5aZ0VYHsb06DieULUoGBaOa+yW4FBnMJJUc5TtgW eV2cVv3eYen0aGhulqi1kILGod4r0+Juvae8cCdnq3/8focjqulPvJB1JlJDZn2YZyfN QCb4TiQghJff0XYIjPPJaQ0PjO4tVTGRNkkDRsv/pHUviKcami7wy3jjdzXxACRWeQfJ 78+w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :references:cc:to:content-language:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=VKjz8gD5IMtfdzgtZtVJhoNtPTXcYw82O5kFCgB1RmM=; b=yg7AXPGJeqnijUD0GREekZ8cvhIzU1z24g+Ub3BGUgguFwUCt8sVogfGsP5ce8/be8 AnqE266pjw/4l3o0cVeVbc+cY7X8DWkEoAd4XNPU0oytWA5IIbUYJFUyx4Ui4lrmqHMf MsxF9mrmpbu5AA/70v8D3g+QjqHZBCJgUEHGxY8fO5P2PWtzjHo1CyASXHiONl5Qtic0 JdziOpcFBaF3TH9KEAQijI2enOXNvWq1jReR0OwGC1gYqz7uK+Lcadf5yCiOPR/E9HQg WV+GB6AT3ez7A/efXn+e6gSVcQB42+CtszbB1VzXUI0ofMGl8wbGT6TBK2r+o3A6jVF1 mZZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b="m/QaDU7A"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id s13-20020a63b40d000000b0046e96b9ecfdsi10538997pgf.801.2022.11.27.23.13.56; Sun, 27 Nov 2022 23:14:08 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass (test mode) header.i=@ideasonboard.com header.s=mail header.b="m/QaDU7A"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229888AbiK1GsG (ORCPT + 84 others); Mon, 28 Nov 2022 01:48:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46658 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229580AbiK1GsD (ORCPT ); Mon, 28 Nov 2022 01:48:03 -0500 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 9D47612757; Sun, 27 Nov 2022 22:48:02 -0800 (PST) Received: from [IPV6:2401:4900:1f3f:3634:f7a:4485:ffcd:6086] (unknown [IPv6:2401:4900:1f3f:3634:f7a:4485:ffcd:6086]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id EAE12501; Mon, 28 Nov 2022 07:47:58 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1669618081; bh=pd1CRI9zY886IetD27393HGIIGdEb/SCZqgHWG/FVrE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=m/QaDU7AYKyZYRrILRAB1tmbV9aHtUMXzWLui4QchwCJS15alFQ1Sa2YbMwkM9aUs bpIx4HZ57MQk9bXByoX2kTj4DUF0ssHQ77jqJTaIukT5wgQv+ZibNG/y8OqPWsO4Z/ 5IRifeCA8VtnTsDTB/CeltwUMlg7eyi6wvyeR/Hc= Message-ID: <6817bff2-6183-ee22-6492-55f51b98c1d6@ideasonboard.com> Date: Mon, 28 Nov 2022 12:17:05 +0530 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH v2 3/3] media: i2c: ak7375: Add regulator management Content-Language: en-US To: Yassine Oudjana , Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Tianshu Qiu , Bingbu Cao Cc: Yassine Oudjana , Jacopo Mondi , linux-media@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org References: <20220711144039.232196-1-y.oudjana@protonmail.com> <20220711144039.232196-4-y.oudjana@protonmail.com> From: Umang Jain In-Reply-To: <20220711144039.232196-4-y.oudjana@protonmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-2.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A,SPF_HELO_PASS, SPF_PASS 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 Hi Yassine, I have tested this VCM with autofocus algorithm plumbed in libcamera [1] On 7/11/22 8:10 PM, Yassine Oudjana wrote: > From: Yassine Oudjana > > Make the driver get needed regulators on probe and enable/disable > them on runtime PM callbacks. > > Signed-off-by: Yassine Oudjana Tested-by: Umang Jain [1] https://patchwork.libcamera.org/project/libcamera/list/?series=3174 > --- > Changes since v1: > - Reorganize variable declaration > - Change the power-on delay range to 3000-3500 microseconds. > > drivers/media/i2c/ak7375.c | 39 ++++++++++++++++++++++++++++++++++++++ > 1 file changed, 39 insertions(+) > > diff --git a/drivers/media/i2c/ak7375.c b/drivers/media/i2c/ak7375.c > index 40b1a4aa846c..c2b2542a0056 100644 > --- a/drivers/media/i2c/ak7375.c > +++ b/drivers/media/i2c/ak7375.c > @@ -6,6 +6,7 @@ > #include > #include > #include > +#include > #include > #include > > @@ -23,17 +24,32 @@ > */ > #define AK7375_CTRL_STEPS 64 > #define AK7375_CTRL_DELAY_US 1000 > +/* > + * The vcm takes around 3 ms to power on and start taking > + * I2C messages. This value was found experimentally due to > + * lack of documentation. > + */ > +#define AK7375_POWER_DELAY_US 3000 > > #define AK7375_REG_POSITION 0x0 > #define AK7375_REG_CONT 0x2 > #define AK7375_MODE_ACTIVE 0x0 > #define AK7375_MODE_STANDBY 0x40 > > +static const char * const ak7375_supply_names[] = { > + "vdd", > + "vio", > +}; > + > +#define AK7375_NUM_SUPPLIES ARRAY_SIZE(ak7375_supply_names) > + > /* ak7375 device structure */ > struct ak7375_device { > struct v4l2_ctrl_handler ctrls_vcm; > struct v4l2_subdev sd; > struct v4l2_ctrl *focus; > + struct regulator_bulk_data supplies[AK7375_NUM_SUPPLIES]; > + > /* active or standby mode */ > bool active; > }; > @@ -133,12 +149,24 @@ static int ak7375_probe(struct i2c_client *client) > { > struct ak7375_device *ak7375_dev; > int ret; > + int i; > > ak7375_dev = devm_kzalloc(&client->dev, sizeof(*ak7375_dev), > GFP_KERNEL); > if (!ak7375_dev) > return -ENOMEM; > > + for (i = 0; i < AK7375_NUM_SUPPLIES; i++) > + ak7375_dev->supplies[i].supply = ak7375_supply_names[i]; > + > + ret = devm_regulator_bulk_get(&client->dev, AK7375_NUM_SUPPLIES, > + ak7375_dev->supplies); > + if (ret) { > + dev_err(&client->dev, "Failed to get regulators: %pe", > + ERR_PTR(ret)); > + return ret; > + } > + > v4l2_i2c_subdev_init(&ak7375_dev->sd, client, &ak7375_ops); > ak7375_dev->sd.flags |= V4L2_SUBDEV_FL_HAS_DEVNODE; > ak7375_dev->sd.internal_ops = &ak7375_int_ops; > @@ -210,6 +238,10 @@ static int __maybe_unused ak7375_vcm_suspend(struct device *dev) > if (ret) > dev_err(dev, "%s I2C failure: %d\n", __func__, ret); > > + ret = regulator_bulk_disable(AK7375_NUM_SUPPLIES, ak7375_dev->supplies); > + if (ret) > + return ret; > + > ak7375_dev->active = false; > > return 0; > @@ -230,6 +262,13 @@ static int __maybe_unused ak7375_vcm_resume(struct device *dev) > if (ak7375_dev->active) > return 0; > > + ret = regulator_bulk_enable(AK7375_NUM_SUPPLIES, ak7375_dev->supplies); > + if (ret) > + return ret; > + > + /* Wait for vcm to become ready */ > + usleep_range(AK7375_POWER_DELAY_US, AK7375_POWER_DELAY_US + 500); > + > ret = ak7375_i2c_write(ak7375_dev, AK7375_REG_CONT, > AK7375_MODE_ACTIVE, 1); > if (ret) { >