Message ID | 20230308094024.14115-3-clamor95@gmail.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp238248wrd; Wed, 8 Mar 2023 01:58:21 -0800 (PST) X-Google-Smtp-Source: AK7set+hS9Hwjl75SQuuAMmE/vmQm9EFA4ldrMp/4emFnC2iRzGngaay0fDYKcPkeMKfTadJiQnm X-Received: by 2002:a17:90a:53:b0:234:d1c:f112 with SMTP id 19-20020a17090a005300b002340d1cf112mr18592515pjb.0.1678269501676; Wed, 08 Mar 2023 01:58:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1678269501; cv=none; d=google.com; s=arc-20160816; b=BTk2K90YLcMOHuw2jUwJTRV3BoiEu1vQttUbYzug0zj8dBkXFW+fcMQOuivvAPQ1rJ phQ8ybrvHL1j/05XOeDnkCIAUnI99rO60QBO5JPMF3RVdeyI5N/Efv6SBF0R7dBEPoMU slTyTy20tcJ0VCau8h/B72gFu1LP/Ze0jjCjK/wJpTR1tFNLmejGo7bcJpBgXAoZU4gd IXsFKHel68l29rEYCiGJPyYllsPh3Ay+92yRgxlEVv6tSA35d6B9EWimZqgLjP0CD0iH FsCB3/CBhrg2AEcYwz79ZavEq7UyYq7FdNUWVNN4f/HOuN+nsocqc9xk24M3f7xYhsmA f3Zw== 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=Z7A7ncxskY+Crxu5hf4wRrmUlrJ73jGGH1lawChBwQk=; b=piAnH+ILnhv61rgLlRWupN9uJXOf8qtml4ZnAU1WbqeUkbK+CNbX1XhQxq8lv1cPYR FLoATYpDpU38wEYoKaDlTyDgF6SQ5SCDHA1vJMOUH2JYra2HKl/K32ur76+FLbBiPEIw Vwd0f9vxfxKKtLRVh9BkelnkNDkYkXULQz6pSotsncwgJXscZaxGBzwPFACl6xhmRmYF AEWHOET38mVMAAP0+OL0goZO/vyTO7BhC9bXHCdBO22VQL2m5snK4Xd181el35JSZLwS Geq/AXDrqwIZfqlEoMlNs5bnQvL7yFdaIXXaJgAs+/nMIKJskkqtQZEhPPs1I4vuj6xi nDkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=O3LGEKkH; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id a12-20020a17090a8c0c00b002340ba8a402si13697916pjo.54.2023.03.08.01.58.08; Wed, 08 Mar 2023 01:58:21 -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 header.i=@gmail.com header.s=20210112 header.b=O3LGEKkH; 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; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229947AbjCHJkv (ORCPT <rfc822;toshivichauhan@gmail.com> + 99 others); Wed, 8 Mar 2023 04:40:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50504 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229905AbjCHJko (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 8 Mar 2023 04:40:44 -0500 Received: from mail-ed1-x52c.google.com (mail-ed1-x52c.google.com [IPv6:2a00:1450:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECB28B1B15; Wed, 8 Mar 2023 01:40:39 -0800 (PST) Received: by mail-ed1-x52c.google.com with SMTP id j11so43650413edq.4; Wed, 08 Mar 2023 01:40:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678268438; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Z7A7ncxskY+Crxu5hf4wRrmUlrJ73jGGH1lawChBwQk=; b=O3LGEKkH6fFEw+/snzPC4P8/QhOhtUN5oxoQjgXnsPfjvU2V3SJvvUUsymPK2zQ3QL PA4jzopDlVRSQg7O0UyU6eTrZC0nzWfpZncJ0PSzVjo6phyIRdOK8fS2qLdylSM5jq38 v+jAHuk2a3kd74oocwONf3birziI0N7+Nj7UgNZm3HvRZununWwq5M81arPhdNh56UoI SDzQAzJ9tbC7bzY/j3mO8FuylJO371JEBDc4JNY+w9QJKSpBLQCoIkthZe+vtuOTzIQL Qlnmuynk8qWAZ1MK9GrglFmFX3uu6Q1rRy4WKNYrcL27ssyj0gctg4+DbHkNEx85ITJ9 JUkw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678268438; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Z7A7ncxskY+Crxu5hf4wRrmUlrJ73jGGH1lawChBwQk=; b=nAAvY+06QllyixNVmXwLd1h2AD4NM9CXPMygW35GF6gElU/oA3yD892FccxpNmgmpo I1jeYj3QjulyVP9HoQG//dE5wGpPYgWifrKzvD2jal1iSwM2jSTcDyyAkqtJDPsASwen E7E2wtnUeQI57AidK7zFLD+ZtCLKS6iVkbOlKnDCMGHzw1iInlR5+yHJOizOcG/4IP0t X1sx6+kB3rS3czAtFpL96QzU/huvyQNglunfTHYgUUkJHJGr7tFZno/+qwN6kOAbrUEO igZHq30TGMO2OOl3ImbsYiEmR4axH50rkZvXxaMsfAcTC//fO0lI2+E8EQT+fH70Jd78 figw== X-Gm-Message-State: AO0yUKXog6l5ObNCBjcKcBKK70opnuqzYizdgltrW+Wr/fSxxXPbSeL5 wnLS1GPv9bq1hqTjHdCYOcs= X-Received: by 2002:aa7:d60b:0:b0:4bd:94b9:b8a8 with SMTP id c11-20020aa7d60b000000b004bd94b9b8a8mr14864191edr.26.1678268438466; Wed, 08 Mar 2023 01:40:38 -0800 (PST) Received: from xeon.. ([188.163.112.76]) by smtp.gmail.com with ESMTPSA id h17-20020a17090634d100b008ee5356801dsm7240014ejb.187.2023.03.08.01.40.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Mar 2023 01:40:38 -0800 (PST) From: Svyatoslav Ryhel <clamor95@gmail.com> To: Guenter Roeck <linux@roeck-us.net>, Jean Delvare <jdelvare@suse.com>, Rob Herring <robh+dt@kernel.org>, Krzysztof Kozlowski <krzysztof.kozlowski+dt@linaro.org>, Liam Girdwood <lgirdwood@gmail.com>, Mark Brown <broonie@kernel.org> Cc: linux-hwmon@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 2/2] hwmon: ina2xx: add optional regulator support Date: Wed, 8 Mar 2023 11:40:24 +0200 Message-Id: <20230308094024.14115-3-clamor95@gmail.com> X-Mailer: git-send-email 2.37.2 In-Reply-To: <20230308094024.14115-1-clamor95@gmail.com> References: <20230308094024.14115-1-clamor95@gmail.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,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: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1759793121203414267?= X-GMAIL-MSGID: =?utf-8?q?1759793121203414267?= |
Series |
Add optional power supply for INA2XX
|
|
Commit Message
Svyatoslav Ryhel
March 8, 2023, 9:40 a.m. UTC
Some devices may need a specific supply provided
for this sensor to work properly, like p895 does.
Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com>
---
drivers/hwmon/ina2xx.c | 12 ++++++++++++
1 file changed, 12 insertions(+)
Comments
On 08/03/2023 10:40, Svyatoslav Ryhel wrote: > Some devices may need a specific supply provided > for this sensor to work properly, like p895 does. > > Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com> > --- > drivers/hwmon/ina2xx.c | 12 ++++++++++++ > 1 file changed, 12 insertions(+) > > diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c > index 00fc70305a89..4a3e2b1bbe8b 100644 > --- a/drivers/hwmon/ina2xx.c > +++ b/drivers/hwmon/ina2xx.c > @@ -119,6 +119,7 @@ struct ina2xx_data { > long power_lsb_uW; > struct mutex config_lock; > struct regmap *regmap; > + struct regulator *vdd_supply; > > const struct attribute_group *groups[INA2XX_MAX_ATTRIBUTE_GROUPS]; > }; > @@ -656,6 +657,17 @@ static int ina2xx_probe(struct i2c_client *client) > return PTR_ERR(data->regmap); > } > > + data->vdd_supply = devm_regulator_get_optional(dev, "vdd"); > + if (IS_ERR(data->vdd_supply)) > + return dev_err_probe(dev, PTR_ERR(data->vdd_supply), > + "failed to get vdd regulator\n"); > + > + ret = regulator_enable(data->vdd_supply); > + if (ret < 0) { > + dev_err(dev, "failed to enable vdd power supply\n"); > + return ret; And where is disable? On each error path, removal etc. Best regards, Krzysztof
ср, 8 бер. 2023 р. о 12:25 Krzysztof Kozlowski <krzysztof.kozlowski@linaro.org> пише: > > On 08/03/2023 10:40, Svyatoslav Ryhel wrote: > > Some devices may need a specific supply provided > > for this sensor to work properly, like p895 does. > > > > Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com> > > --- > > drivers/hwmon/ina2xx.c | 12 ++++++++++++ > > 1 file changed, 12 insertions(+) > > > > diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c > > index 00fc70305a89..4a3e2b1bbe8b 100644 > > --- a/drivers/hwmon/ina2xx.c > > +++ b/drivers/hwmon/ina2xx.c > > @@ -119,6 +119,7 @@ struct ina2xx_data { > > long power_lsb_uW; > > struct mutex config_lock; > > struct regmap *regmap; > > + struct regulator *vdd_supply; > > > > const struct attribute_group *groups[INA2XX_MAX_ATTRIBUTE_GROUPS]; > > }; > > @@ -656,6 +657,17 @@ static int ina2xx_probe(struct i2c_client *client) > > return PTR_ERR(data->regmap); > > } > > > > + data->vdd_supply = devm_regulator_get_optional(dev, "vdd"); > > + if (IS_ERR(data->vdd_supply)) > > + return dev_err_probe(dev, PTR_ERR(data->vdd_supply), > > + "failed to get vdd regulator\n"); > > + > > + ret = regulator_enable(data->vdd_supply); > > + if (ret < 0) { > > + dev_err(dev, "failed to enable vdd power supply\n"); > > + return ret; > > And where is disable? On each error path, removal etc. > error path ok, should I create a remove function just to disable the regulator? > Best regards, > Krzysztof >
On 08/03/2023 11:35, Svyatoslav Ryhel wrote: > ср, 8 бер. 2023 р. о 12:25 Krzysztof Kozlowski > <krzysztof.kozlowski@linaro.org> пише: >> >> On 08/03/2023 10:40, Svyatoslav Ryhel wrote: >>> Some devices may need a specific supply provided >>> for this sensor to work properly, like p895 does. >>> >>> Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com> >>> --- >>> drivers/hwmon/ina2xx.c | 12 ++++++++++++ >>> 1 file changed, 12 insertions(+) >>> >>> diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c >>> index 00fc70305a89..4a3e2b1bbe8b 100644 >>> --- a/drivers/hwmon/ina2xx.c >>> +++ b/drivers/hwmon/ina2xx.c >>> @@ -119,6 +119,7 @@ struct ina2xx_data { >>> long power_lsb_uW; >>> struct mutex config_lock; >>> struct regmap *regmap; >>> + struct regulator *vdd_supply; >>> >>> const struct attribute_group *groups[INA2XX_MAX_ATTRIBUTE_GROUPS]; >>> }; >>> @@ -656,6 +657,17 @@ static int ina2xx_probe(struct i2c_client *client) >>> return PTR_ERR(data->regmap); >>> } >>> >>> + data->vdd_supply = devm_regulator_get_optional(dev, "vdd"); >>> + if (IS_ERR(data->vdd_supply)) >>> + return dev_err_probe(dev, PTR_ERR(data->vdd_supply), >>> + "failed to get vdd regulator\n"); >>> + >>> + ret = regulator_enable(data->vdd_supply); >>> + if (ret < 0) { >>> + dev_err(dev, "failed to enable vdd power supply\n"); >>> + return ret; >> >> And where is disable? On each error path, removal etc. >> > > error path ok, should I create a remove function just to disable the regulator? Unbind device. Then bind. Then unbind. Then check regulator status (/sys/kernel/debug). Do you have the answer now? Best regards, Krzysztof
On 3/8/23 02:35, Svyatoslav Ryhel wrote: > ср, 8 бер. 2023 р. о 12:25 Krzysztof Kozlowski > <krzysztof.kozlowski@linaro.org> пише: >> >> On 08/03/2023 10:40, Svyatoslav Ryhel wrote: >>> Some devices may need a specific supply provided >>> for this sensor to work properly, like p895 does. >>> >>> Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com> >>> --- >>> drivers/hwmon/ina2xx.c | 12 ++++++++++++ >>> 1 file changed, 12 insertions(+) >>> >>> diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c >>> index 00fc70305a89..4a3e2b1bbe8b 100644 >>> --- a/drivers/hwmon/ina2xx.c >>> +++ b/drivers/hwmon/ina2xx.c >>> @@ -119,6 +119,7 @@ struct ina2xx_data { >>> long power_lsb_uW; >>> struct mutex config_lock; >>> struct regmap *regmap; >>> + struct regulator *vdd_supply; >>> >>> const struct attribute_group *groups[INA2XX_MAX_ATTRIBUTE_GROUPS]; >>> }; >>> @@ -656,6 +657,17 @@ static int ina2xx_probe(struct i2c_client *client) >>> return PTR_ERR(data->regmap); >>> } >>> >>> + data->vdd_supply = devm_regulator_get_optional(dev, "vdd"); >>> + if (IS_ERR(data->vdd_supply)) >>> + return dev_err_probe(dev, PTR_ERR(data->vdd_supply), >>> + "failed to get vdd regulator\n"); >>> + >>> + ret = regulator_enable(data->vdd_supply); >>> + if (ret < 0) { >>> + dev_err(dev, "failed to enable vdd power supply\n"); >>> + return ret; >> >> And where is disable? On each error path, removal etc. >> > > error path ok, should I create a remove function just to disable the regulator? > Use devm_add_action_or_reset(). Guenter >> Best regards, >> Krzysztof >>
8 березня 2023 р. 13:13:18 GMT+02:00, Guenter Roeck <linux@roeck-us.net> написав(-ла): >On 3/8/23 02:35, Svyatoslav Ryhel wrote: >> ср, 8 бер. 2023 р. о 12:25 Krzysztof Kozlowski >> <krzysztof.kozlowski@linaro.org> пише: >>> >>> On 08/03/2023 10:40, Svyatoslav Ryhel wrote: >>>> Some devices may need a specific supply provided >>>> for this sensor to work properly, like p895 does. >>>> >>>> Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com> >>>> --- >>>> drivers/hwmon/ina2xx.c | 12 ++++++++++++ >>>> 1 file changed, 12 insertions(+) >>>> >>>> diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c >>>> index 00fc70305a89..4a3e2b1bbe8b 100644 >>>> --- a/drivers/hwmon/ina2xx.c >>>> +++ b/drivers/hwmon/ina2xx.c >>>> @@ -119,6 +119,7 @@ struct ina2xx_data { >>>> long power_lsb_uW; >>>> struct mutex config_lock; >>>> struct regmap *regmap; >>>> + struct regulator *vdd_supply; >>>> >>>> const struct attribute_group *groups[INA2XX_MAX_ATTRIBUTE_GROUPS]; >>>> }; >>>> @@ -656,6 +657,17 @@ static int ina2xx_probe(struct i2c_client *client) >>>> return PTR_ERR(data->regmap); >>>> } >>>> >>>> + data->vdd_supply = devm_regulator_get_optional(dev, "vdd"); >>>> + if (IS_ERR(data->vdd_supply)) >>>> + return dev_err_probe(dev, PTR_ERR(data->vdd_supply), >>>> + "failed to get vdd regulator\n"); >>>> + >>>> + ret = regulator_enable(data->vdd_supply); >>>> + if (ret < 0) { >>>> + dev_err(dev, "failed to enable vdd power supply\n"); >>>> + return ret; >>> >>> And where is disable? On each error path, removal etc. >>> >> >> error path ok, should I create a remove function just to disable the regulator? >> >Use devm_add_action_or_reset(). > >Guenter > That is good suggestion. Thanks! Best regards, Svyatoslav R. >>> Best regards, >>> Krzysztof >>> >
On 3/8/23 03:19, Svyatoslav Ryhel wrote: > > 8 березня 2023 р. 13:13:18 GMT+02:00, Guenter Roeck <linux@roeck-us.net> написав(-ла): >> On 3/8/23 02:35, Svyatoslav Ryhel wrote: >>> ср, 8 бер. 2023 р. о 12:25 Krzysztof Kozlowski >>> <krzysztof.kozlowski@linaro.org> пише: >>>> On 08/03/2023 10:40, Svyatoslav Ryhel wrote: >>>>> Some devices may need a specific supply provided >>>>> for this sensor to work properly, like p895 does. >>>>> >>>>> Signed-off-by: Svyatoslav Ryhel <clamor95@gmail.com> >>>>> --- >>>>> drivers/hwmon/ina2xx.c | 12 ++++++++++++ >>>>> 1 file changed, 12 insertions(+) >>>>> >>>>> diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c >>>>> index 00fc70305a89..4a3e2b1bbe8b 100644 >>>>> --- a/drivers/hwmon/ina2xx.c >>>>> +++ b/drivers/hwmon/ina2xx.c >>>>> @@ -119,6 +119,7 @@ struct ina2xx_data { >>>>> long power_lsb_uW; >>>>> struct mutex config_lock; >>>>> struct regmap *regmap; >>>>> + struct regulator *vdd_supply; >>>>> >>>>> const struct attribute_group *groups[INA2XX_MAX_ATTRIBUTE_GROUPS]; >>>>> }; >>>>> @@ -656,6 +657,17 @@ static int ina2xx_probe(struct i2c_client *client) >>>>> return PTR_ERR(data->regmap); >>>>> } >>>>> >>>>> + data->vdd_supply = devm_regulator_get_optional(dev, "vdd"); >>>>> + if (IS_ERR(data->vdd_supply)) >>>>> + return dev_err_probe(dev, PTR_ERR(data->vdd_supply), >>>>> + "failed to get vdd regulator\n"); >>>>> + >>>>> + ret = regulator_enable(data->vdd_supply); >>>>> + if (ret < 0) { >>>>> + dev_err(dev, "failed to enable vdd power supply\n"); >>>>> + return ret; >>>> And where is disable? On each error path, removal etc. >>>> >>> error path ok, should I create a remove function just to disable the regulator? >>> >> Use devm_add_action_or_reset(). >> >> Guenter >> > That is good suggestion. Thanks! There is a new function devm_regulator_get_enable(). It will both request the regulator and enable in and then automatically disable and free it when the device is removed. The API can be slightly confusing in this regard. In your case you also want to use the non-optional API. The optional API is for cases where you need to know whether a regulator is connected or not. If you do not need to know use the non-optional API, if no regulator is specified the regulator framework will just a return a noop regulator as a placeholder. The optional version will actually return an error if no regulator is specified, so with your patch existing users of this driver will break.
diff --git a/drivers/hwmon/ina2xx.c b/drivers/hwmon/ina2xx.c index 00fc70305a89..4a3e2b1bbe8b 100644 --- a/drivers/hwmon/ina2xx.c +++ b/drivers/hwmon/ina2xx.c @@ -119,6 +119,7 @@ struct ina2xx_data { long power_lsb_uW; struct mutex config_lock; struct regmap *regmap; + struct regulator *vdd_supply; const struct attribute_group *groups[INA2XX_MAX_ATTRIBUTE_GROUPS]; }; @@ -656,6 +657,17 @@ static int ina2xx_probe(struct i2c_client *client) return PTR_ERR(data->regmap); } + data->vdd_supply = devm_regulator_get_optional(dev, "vdd"); + if (IS_ERR(data->vdd_supply)) + return dev_err_probe(dev, PTR_ERR(data->vdd_supply), + "failed to get vdd regulator\n"); + + ret = regulator_enable(data->vdd_supply); + if (ret < 0) { + dev_err(dev, "failed to enable vdd power supply\n"); + return ret; + } + ret = ina2xx_init(data); if (ret < 0) { dev_err(dev, "error configuring the device: %d\n", ret);