Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp5206787imw; Wed, 20 Jul 2022 00:44:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vtN5jxoqQOI3AETptce23VJZ14qRd9Qu9Zihnj4en7UZ1cdgRGYOyqbkpz+a+BZdFsOpGF X-Received: by 2002:a17:90b:164a:b0:1ef:e6ae:4b56 with SMTP id il10-20020a17090b164a00b001efe6ae4b56mr3889642pjb.5.1658303057440; Wed, 20 Jul 2022 00:44:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658303057; cv=none; d=google.com; s=arc-20160816; b=lZRRj7pNxK1wSAeww7bf8kY1Tuo5DxkApNZwTtmBfStnsxW+nNILLp6ls3F79nS1yC J8uognNxGse1m/e0YsZ0Ie5gumdBpKGtHXXRncL0ar8KTxbZRgYeokCOILl6pwqdTDts OsoXWN9hcCYNqC5RFiJV31ST6JlGSAYS6zEWBHqDAHPbyt3gPD/p7TRCGY6eFmJnz7DF z4Vk4zmYsgnGSfRAKzx+X73BchJEBilEeDZu7OCR6o7y/PV8+o0FrLQM+hyrQaQ44/81 zmavWiWNRhrRX5C8RI/khyq57vQMMgx9hwLR9sXlv2HWdmFSfHrrr4ngUaaG1RThjrqN 1PvA== 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; bh=JdYJ/ZKgvMxxEay4lT0Hzl2ynjAFUEuOklsAtBNNNhM=; b=CUdA+rXb86lhFjrcAp3geHELThx4DeTL5pXaCUoUxB5jzYcFJk3jnMLPt5Y+GzmuTC AFFqSrMbLrKXF9GAzHehXy7VdjQjxbYwPKlAPDKAB5X5oenUGM5zAHWioGfPXrQh27/w oE9ZKGRKU2c2xkafS+sIeKr+J3T7TjhzcPZCBFeVYCvxhs9fG6fNksSvv6vUnHfBCdLO fWNt8Ef444LTaMCC4oZcT66OTzzGXxsCJFhxmhPMIZX7S/3s40K7mwY/nrtdfJ10c4g6 mKkTDWx/cgI4e2I7XtcC4uzw0I51K63Svqx3Q+fuOF98X2LDuFHHz99gv4kVRyj+xWZG mI4w== ARC-Authentication-Results: i=1; mx.google.com; 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 t7-20020a170902e84700b0016a2bfe5c7csi23834811plg.172.2022.07.20.00.44.02; Wed, 20 Jul 2022 00:44:17 -0700 (PDT) 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; 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 S239826AbiGTHg2 (ORCPT + 99 others); Wed, 20 Jul 2022 03:36:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239858AbiGTHg0 (ORCPT ); Wed, 20 Jul 2022 03:36:26 -0400 Received: from smtp.smtpout.orange.fr (smtp06.smtpout.orange.fr [80.12.242.128]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB3E3491FD for ; Wed, 20 Jul 2022 00:36:25 -0700 (PDT) Received: from [192.168.1.18] ([90.11.190.129]) by smtp.orange.fr with ESMTPA id E4FpoOQ7fAZYmE4FpoFLhi; Wed, 20 Jul 2022 09:36:23 +0200 X-ME-Helo: [192.168.1.18] X-ME-Auth: YWZlNiIxYWMyZDliZWIzOTcwYTEyYzlhMmU3ZiQ1M2U2MzfzZDfyZTMxZTBkMTYyNDBjNDJlZmQ3ZQ== X-ME-Date: Wed, 20 Jul 2022 09:36:23 +0200 X-ME-IP: 90.11.190.129 Message-ID: <772469b0-c279-6762-091d-821c58717941@wanadoo.fr> Date: Wed, 20 Jul 2022 09:36:21 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.9.1 Subject: Re: [PATCH v2 3/3] media: i2c: ak7375: Add regulator management Content-Language: fr To: Jacopo Mondi , Yassine Oudjana Cc: Mauro Carvalho Chehab , Rob Herring , Krzysztof Kozlowski , Tianshu Qiu , Bingbu Cao , Yassine Oudjana , 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> <20220711173123.55abjsli3tmqgegj@uno.localdomain> From: Christophe JAILLET In-Reply-To: <20220711173123.55abjsli3tmqgegj@uno.localdomain> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,NICE_REPLY_A, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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 Le 11/07/2022 à 19:31, Jacopo Mondi a écrit : > Hi Yassine, > > On Mon, Jul 11, 2022 at 06:40:39PM +0400, 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 >> --- >> 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)); > > Why are you using %pe here ? Your return value is not a pointer > (Also, missing \n at the end of the string) > > From Documentation/core-api/printk-formats.rst: > %pe -ENOSPC > > For printing error pointers (i.e. a pointer for which IS_ERR() is true) > as a symbolic error name. Error values for which no symbolic name is > known are printed in decimal, while a non-ERR_PTR passed as the > argument to %pe gets treated as ordinary %p. > Nit: using: + return dev_err_probe(&client->dev, ret, "Failed to get regulators); would be even simpler. CJ >> + 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) { >> -- >> 2.37.0 >> >