Following up from [1], this is the first round of patches to convert the
ADC drivers to use devm_regulator_get_enable_read_voltage().
Some of these are trivial but some aren't so I'm breaking them up into
smaller series to spread out the review load (and my work load).
[1]: https://lore.kernel.org/linux-iio/20240429-regulator-get-enable-get-votlage-v2-0-b1f11ab766c1@baylibre.com
---
Changes in v2:
- avoid else in return value checks
- fix unintentional changes in behavior
- use macros instead of comments for internal reference voltage
- Link to v1: https://lore.kernel.org/r/20240531-iio-adc-ref-supply-refactor-v1-0-4b313c0615ad@baylibre.com
---
David Lechner (5):
iio: adc: ad7192: use devm_regulator_get_enable_read_voltage
iio: adc: ad7266: use devm_regulator_get_enable_read_voltage
iio: adc: ad7292: use devm_regulator_get_enable_read_voltage
iio: adc: ad7793: use devm_regulator_get_enable_read_voltage
iio: adc: ad7944: use devm_regulator_get_enable_read_voltage
drivers/iio/adc/ad7192.c | 100 +++++++++++++++++------------------------------
drivers/iio/adc/ad7266.c | 33 +++-------------
drivers/iio/adc/ad7292.c | 36 +++--------------
drivers/iio/adc/ad7793.c | 24 ++----------
drivers/iio/adc/ad7944.c | 54 ++++++-------------------
5 files changed, 62 insertions(+), 185 deletions(-)
---
base-commit: cc1ce839526a65620778617da0b022bd88e8a139
change-id: 20240531-iio-adc-ref-supply-refactor-93f962d40c23
This makes use of the new devm_regulator_get_enable_read_voltage()
function to reduce boilerplate code.
Signed-off-by: David Lechner <[email protected]>
---
v2 changes:
* avoid else in return value check
* use macro instead of comment to document internal reference voltage
---
drivers/iio/adc/ad7292.c | 36 ++++++------------------------------
1 file changed, 6 insertions(+), 30 deletions(-)
diff --git a/drivers/iio/adc/ad7292.c b/drivers/iio/adc/ad7292.c
index 6aadd14f459d..87ffe66058a1 100644
--- a/drivers/iio/adc/ad7292.c
+++ b/drivers/iio/adc/ad7292.c
@@ -17,6 +17,8 @@
#define ADI_VENDOR_ID 0x0018
+#define AD7292_INTERNAL_REF_MV 1250
+
/* AD7292 registers definition */
#define AD7292_REG_VENDOR_ID 0x00
#define AD7292_REG_CONF_BANK 0x05
@@ -79,7 +81,6 @@ static const struct iio_chan_spec ad7292_channels_diff[] = {
struct ad7292_state {
struct spi_device *spi;
- struct regulator *reg;
unsigned short vref_mv;
__be16 d16 __aligned(IIO_DMA_MINALIGN);
@@ -250,13 +251,6 @@ static const struct iio_info ad7292_info = {
.read_raw = ad7292_read_raw,
};
-static void ad7292_regulator_disable(void *data)
-{
- struct ad7292_state *st = data;
-
- regulator_disable(st->reg);
-}
-
static int ad7292_probe(struct spi_device *spi)
{
struct ad7292_state *st;
@@ -277,29 +271,11 @@ static int ad7292_probe(struct spi_device *spi)
return -EINVAL;
}
- st->reg = devm_regulator_get_optional(&spi->dev, "vref");
- if (!IS_ERR(st->reg)) {
- ret = regulator_enable(st->reg);
- if (ret) {
- dev_err(&spi->dev,
- "Failed to enable external vref supply\n");
- return ret;
- }
-
- ret = devm_add_action_or_reset(&spi->dev,
- ad7292_regulator_disable, st);
- if (ret)
- return ret;
-
- ret = regulator_get_voltage(st->reg);
- if (ret < 0)
- return ret;
+ ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref");
+ if (ret < 0 && ret == -ENODEV)
+ return ret;
- st->vref_mv = ret / 1000;
- } else {
- /* Use the internal voltage reference. */
- st->vref_mv = 1250;
- }
+ st->vref_mv = ret == -ENODEV ? AD7292_INTERNAL_REF_MV : ret / 1000;
indio_dev->name = spi_get_device_id(spi)->name;
indio_dev->modes = INDIO_DIRECT_MODE;
--
2.45.2
This makes use of the new devm_regulator_get_enable_read_voltage()
function to reduce boilerplate code.
Signed-off-by: David Lechner <[email protected]>
---
v2 changes:
- don't read voltage from refin regulator
- avoid else in return value checks
---
drivers/iio/adc/ad7944.c | 54 +++++++++++-------------------------------------
1 file changed, 12 insertions(+), 42 deletions(-)
diff --git a/drivers/iio/adc/ad7944.c b/drivers/iio/adc/ad7944.c
index e2cb64cef476..f8bf03feba07 100644
--- a/drivers/iio/adc/ad7944.c
+++ b/drivers/iio/adc/ad7944.c
@@ -464,23 +464,17 @@ static const char * const ad7944_power_supplies[] = {
"avdd", "dvdd", "bvdd", "vio"
};
-static void ad7944_ref_disable(void *ref)
-{
- regulator_disable(ref);
-}
-
static int ad7944_probe(struct spi_device *spi)
{
const struct ad7944_chip_info *chip_info;
struct device *dev = &spi->dev;
struct iio_dev *indio_dev;
struct ad7944_adc *adc;
- bool have_refin = false;
- struct regulator *ref;
+ bool have_refin;
struct iio_chan_spec *chain_chan;
unsigned long *chain_scan_masks;
u32 n_chain_dev;
- int ret;
+ int ret, ref_mv;
indio_dev = devm_iio_device_alloc(dev, sizeof(*adc));
if (!indio_dev)
@@ -531,47 +525,23 @@ static int ad7944_probe(struct spi_device *spi)
* - external reference: REF is connected, REFIN is not connected
*/
- ref = devm_regulator_get_optional(dev, "ref");
- if (IS_ERR(ref)) {
- if (PTR_ERR(ref) != -ENODEV)
- return dev_err_probe(dev, PTR_ERR(ref),
- "failed to get REF supply\n");
+ ret = devm_regulator_get_enable_read_voltage(dev, "ref");
+ if (ret < 0 && ret != -ENODEV)
+ return dev_err_probe(dev, ret, "failed to get REF voltage\n");
- ref = NULL;
- }
+ ref_mv = ret == -ENODEV ? 0 : ret / 1000;
ret = devm_regulator_get_enable_optional(dev, "refin");
- if (ret == 0)
- have_refin = true;
- else if (ret != -ENODEV)
- return dev_err_probe(dev, ret,
- "failed to get and enable REFIN supply\n");
+ if (ret < 0 && ret == -ENODEV)
+ return dev_err_probe(dev, ret, "failed to get REFIN voltage\n");
+
+ have_refin = ret != -ENODEV;
- if (have_refin && ref)
+ if (have_refin && ref_mv)
return dev_err_probe(dev, -EINVAL,
"cannot have both refin and ref supplies\n");
- if (ref) {
- ret = regulator_enable(ref);
- if (ret)
- return dev_err_probe(dev, ret,
- "failed to enable REF supply\n");
-
- ret = devm_add_action_or_reset(dev, ad7944_ref_disable, ref);
- if (ret)
- return ret;
-
- ret = regulator_get_voltage(ref);
- if (ret < 0)
- return dev_err_probe(dev, ret,
- "failed to get REF voltage\n");
-
- /* external reference */
- adc->ref_mv = ret / 1000;
- } else {
- /* internal reference */
- adc->ref_mv = AD7944_INTERNAL_REF_MV;
- }
+ adc->ref_mv = ref_mv ?: AD7944_INTERNAL_REF_MV;
adc->cnv = devm_gpiod_get_optional(dev, "cnv", GPIOD_OUT_LOW);
if (IS_ERR(adc->cnv))
--
2.45.2
This makes use of the new devm_regulator_get_enable_read_voltage()
function to reduce boilerplate code.
Signed-off-by: David Lechner <[email protected]>
---
v2 changes:
- avoid else in return value check
- use macro instead of comment to explain internal reference voltage
---
drivers/iio/adc/ad7266.c | 33 ++++++---------------------------
1 file changed, 6 insertions(+), 27 deletions(-)
diff --git a/drivers/iio/adc/ad7266.c b/drivers/iio/adc/ad7266.c
index 353a97f9c086..874d2dc34f92 100644
--- a/drivers/iio/adc/ad7266.c
+++ b/drivers/iio/adc/ad7266.c
@@ -23,9 +23,10 @@
#include <linux/platform_data/ad7266.h>
+#define AD7266_INTERNAL_REF_MV 2500
+
struct ad7266_state {
struct spi_device *spi;
- struct regulator *reg;
unsigned long vref_mv;
struct spi_transfer single_xfer[3];
@@ -377,11 +378,6 @@ static const char * const ad7266_gpio_labels[] = {
"ad0", "ad1", "ad2",
};
-static void ad7266_reg_disable(void *reg)
-{
- regulator_disable(reg);
-}
-
static int ad7266_probe(struct spi_device *spi)
{
struct ad7266_platform_data *pdata = spi->dev.platform_data;
@@ -396,28 +392,11 @@ static int ad7266_probe(struct spi_device *spi)
st = iio_priv(indio_dev);
- st->reg = devm_regulator_get_optional(&spi->dev, "vref");
- if (!IS_ERR(st->reg)) {
- ret = regulator_enable(st->reg);
- if (ret)
- return ret;
-
- ret = devm_add_action_or_reset(&spi->dev, ad7266_reg_disable, st->reg);
- if (ret)
- return ret;
-
- ret = regulator_get_voltage(st->reg);
- if (ret < 0)
- return ret;
+ ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref");
+ if (ret < 0 && ret != -ENODEV)
+ return ret;
- st->vref_mv = ret / 1000;
- } else {
- /* Any other error indicates that the regulator does exist */
- if (PTR_ERR(st->reg) != -ENODEV)
- return PTR_ERR(st->reg);
- /* Use internal reference */
- st->vref_mv = 2500;
- }
+ st->vref_mv = ret == -ENODEV ? AD7266_INTERNAL_REF_MV : ret / 1000;
if (pdata) {
st->fixed_addr = pdata->fixed_addr;
--
2.45.2
On 6/14/24 10:11 AM, Nuno Sá wrote:
> On Wed, 2024-06-12 at 16:03 -0500, David Lechner wrote:
>> This makes use of the new devm_regulator_get_enable_read_voltage()
>> function to reduce boilerplate code.
>>
>> Signed-off-by: David Lechner <[email protected]>
>> ---
>> v2 changes:
>> * avoid else in return value check
>> * use macro instead of comment to document internal reference voltage
>> ---
>> drivers/iio/adc/ad7292.c | 36 ++++++------------------------------
>> 1 file changed, 6 insertions(+), 30 deletions(-)
>>
>> diff --git a/drivers/iio/adc/ad7292.c b/drivers/iio/adc/ad7292.c
>> index 6aadd14f459d..87ffe66058a1 100644
>> --- a/drivers/iio/adc/ad7292.c
>> +++ b/drivers/iio/adc/ad7292.c
>> @@ -17,6 +17,8 @@
>>
>> #define ADI_VENDOR_ID 0x0018
>>
>> +#define AD7292_INTERNAL_REF_MV 1250
>> +
>> /* AD7292 registers definition */
>> #define AD7292_REG_VENDOR_ID 0x00
>> #define AD7292_REG_CONF_BANK 0x05
>> @@ -79,7 +81,6 @@ static const struct iio_chan_spec ad7292_channels_diff[] = {
>>
>> struct ad7292_state {
>> struct spi_device *spi;
>> - struct regulator *reg;
>> unsigned short vref_mv;
>>
>> __be16 d16 __aligned(IIO_DMA_MINALIGN);
>> @@ -250,13 +251,6 @@ static const struct iio_info ad7292_info = {
>> .read_raw = ad7292_read_raw,
>> };
>>
>> -static void ad7292_regulator_disable(void *data)
>> -{
>> - struct ad7292_state *st = data;
>> -
>> - regulator_disable(st->reg);
>> -}
>> -
>> static int ad7292_probe(struct spi_device *spi)
>> {
>> struct ad7292_state *st;
>> @@ -277,29 +271,11 @@ static int ad7292_probe(struct spi_device *spi)
>> return -EINVAL;
>> }
>>
>> - st->reg = devm_regulator_get_optional(&spi->dev, "vref");
>> - if (!IS_ERR(st->reg)) {
>> - ret = regulator_enable(st->reg);
>> - if (ret) {
>> - dev_err(&spi->dev,
>> - "Failed to enable external vref supply\n");
>> - return ret;
>> - }
>> -
>> - ret = devm_add_action_or_reset(&spi->dev,
>> - ad7292_regulator_disable, st);
>> - if (ret)
>> - return ret;
>> -
>> - ret = regulator_get_voltage(st->reg);
>> - if (ret < 0)
>> - return ret;
>> + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref");
>> + if (ret < 0 && ret == -ENODEV)
>
> ret != -ENODEV?
yup, I messed this one up
>
> - Nuno Sá
>
On Wed, 2024-06-12 at 16:03 -0500, David Lechner wrote:
> This makes use of the new devm_regulator_get_enable_read_voltage()
> function to reduce boilerplate code.
>
> Signed-off-by: David Lechner <[email protected]>
> ---
>
> v2 changes:
> - don't read voltage from refin regulator
> - avoid else in return value checks
> ---
> drivers/iio/adc/ad7944.c | 54 +++++++++++-------------------------------------
> 1 file changed, 12 insertions(+), 42 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7944.c b/drivers/iio/adc/ad7944.c
> index e2cb64cef476..f8bf03feba07 100644
> --- a/drivers/iio/adc/ad7944.c
> +++ b/drivers/iio/adc/ad7944.c
> @@ -464,23 +464,17 @@ static const char * const ad7944_power_supplies[] = {
> "avdd", "dvdd", "bvdd", "vio"
> };
>
> -static void ad7944_ref_disable(void *ref)
> -{
> - regulator_disable(ref);
> -}
> -
> static int ad7944_probe(struct spi_device *spi)
> {
> const struct ad7944_chip_info *chip_info;
> struct device *dev = &spi->dev;
> struct iio_dev *indio_dev;
> struct ad7944_adc *adc;
> - bool have_refin = false;
> - struct regulator *ref;
> + bool have_refin;
> struct iio_chan_spec *chain_chan;
> unsigned long *chain_scan_masks;
> u32 n_chain_dev;
> - int ret;
> + int ret, ref_mv;
>
> indio_dev = devm_iio_device_alloc(dev, sizeof(*adc));
> if (!indio_dev)
> @@ -531,47 +525,23 @@ static int ad7944_probe(struct spi_device *spi)
> * - external reference: REF is connected, REFIN is not connected
> */
>
> - ref = devm_regulator_get_optional(dev, "ref");
> - if (IS_ERR(ref)) {
> - if (PTR_ERR(ref) != -ENODEV)
> - return dev_err_probe(dev, PTR_ERR(ref),
> - "failed to get REF supply\n");
> + ret = devm_regulator_get_enable_read_voltage(dev, "ref");
> + if (ret < 0 && ret != -ENODEV)
> + return dev_err_probe(dev, ret, "failed to get REF voltage\n");
>
> - ref = NULL;
> - }
> + ref_mv = ret == -ENODEV ? 0 : ret / 1000;
>
> ret = devm_regulator_get_enable_optional(dev, "refin");
> - if (ret == 0)
> - have_refin = true;
> - else if (ret != -ENODEV)
> - return dev_err_probe(dev, ret,
> - "failed to get and enable REFIN supply\n");
> + if (ret < 0 && ret == -ENODEV)
> + return dev_err_probe(dev, ret, "failed to get REFIN voltage\n");
> +
ret != -ENODEV right?
- Nuno Sá
On Wed, 2024-06-12 at 16:03 -0500, David Lechner wrote:
> Following up from [1], this is the first round of patches to convert the
> ADC drivers to use devm_regulator_get_enable_read_voltage().
>
> Some of these are trivial but some aren't so I'm breaking them up into
> smaller series to spread out the review load (and my work load).
>
> [1]:
> https://lore.kernel.org/linux-iio/20240429-regulator-get-enable-get-votlage-v2-0-b1f11ab766c1@baylibre.com
>
> ---
Just two things that look like typos... With that:
Reviewed-by: Nuno Sa <[email protected]>
On Wed, 2024-06-12 at 16:03 -0500, David Lechner wrote:
> This makes use of the new devm_regulator_get_enable_read_voltage()
> function to reduce boilerplate code.
>
> Signed-off-by: David Lechner <[email protected]>
> ---
> v2 changes:
> * avoid else in return value check
> * use macro instead of comment to document internal reference voltage
> ---
> drivers/iio/adc/ad7292.c | 36 ++++++------------------------------
> 1 file changed, 6 insertions(+), 30 deletions(-)
>
> diff --git a/drivers/iio/adc/ad7292.c b/drivers/iio/adc/ad7292.c
> index 6aadd14f459d..87ffe66058a1 100644
> --- a/drivers/iio/adc/ad7292.c
> +++ b/drivers/iio/adc/ad7292.c
> @@ -17,6 +17,8 @@
>
> #define ADI_VENDOR_ID 0x0018
>
> +#define AD7292_INTERNAL_REF_MV 1250
> +
> /* AD7292 registers definition */
> #define AD7292_REG_VENDOR_ID 0x00
> #define AD7292_REG_CONF_BANK 0x05
> @@ -79,7 +81,6 @@ static const struct iio_chan_spec ad7292_channels_diff[] = {
>
> struct ad7292_state {
> struct spi_device *spi;
> - struct regulator *reg;
> unsigned short vref_mv;
>
> __be16 d16 __aligned(IIO_DMA_MINALIGN);
> @@ -250,13 +251,6 @@ static const struct iio_info ad7292_info = {
> .read_raw = ad7292_read_raw,
> };
>
> -static void ad7292_regulator_disable(void *data)
> -{
> - struct ad7292_state *st = data;
> -
> - regulator_disable(st->reg);
> -}
> -
> static int ad7292_probe(struct spi_device *spi)
> {
> struct ad7292_state *st;
> @@ -277,29 +271,11 @@ static int ad7292_probe(struct spi_device *spi)
> return -EINVAL;
> }
>
> - st->reg = devm_regulator_get_optional(&spi->dev, "vref");
> - if (!IS_ERR(st->reg)) {
> - ret = regulator_enable(st->reg);
> - if (ret) {
> - dev_err(&spi->dev,
> - "Failed to enable external vref supply\n");
> - return ret;
> - }
> -
> - ret = devm_add_action_or_reset(&spi->dev,
> - ad7292_regulator_disable, st);
> - if (ret)
> - return ret;
> -
> - ret = regulator_get_voltage(st->reg);
> - if (ret < 0)
> - return ret;
> + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref");
> + if (ret < 0 && ret == -ENODEV)
ret != -ENODEV?
- Nuno Sá
On 6/14/24 10:16 AM, Nuno Sá wrote:
> On Wed, 2024-06-12 at 16:03 -0500, David Lechner wrote:
>> This makes use of the new devm_regulator_get_enable_read_voltage()
>> function to reduce boilerplate code.
>>
>> Signed-off-by: David Lechner <[email protected]>
>> ---
>>
>> v2 changes:
>> - don't read voltage from refin regulator
>> - avoid else in return value checks
>> ---
>> drivers/iio/adc/ad7944.c | 54 +++++++++++-------------------------------------
>> 1 file changed, 12 insertions(+), 42 deletions(-)
>>
>> diff --git a/drivers/iio/adc/ad7944.c b/drivers/iio/adc/ad7944.c
>> index e2cb64cef476..f8bf03feba07 100644
>> --- a/drivers/iio/adc/ad7944.c
>> +++ b/drivers/iio/adc/ad7944.c
>> @@ -464,23 +464,17 @@ static const char * const ad7944_power_supplies[] = {
>> "avdd", "dvdd", "bvdd", "vio"
>> };
>>
>> -static void ad7944_ref_disable(void *ref)
>> -{
>> - regulator_disable(ref);
>> -}
>> -
>> static int ad7944_probe(struct spi_device *spi)
>> {
>> const struct ad7944_chip_info *chip_info;
>> struct device *dev = &spi->dev;
>> struct iio_dev *indio_dev;
>> struct ad7944_adc *adc;
>> - bool have_refin = false;
>> - struct regulator *ref;
>> + bool have_refin;
>> struct iio_chan_spec *chain_chan;
>> unsigned long *chain_scan_masks;
>> u32 n_chain_dev;
>> - int ret;
>> + int ret, ref_mv;
>>
>> indio_dev = devm_iio_device_alloc(dev, sizeof(*adc));
>> if (!indio_dev)
>> @@ -531,47 +525,23 @@ static int ad7944_probe(struct spi_device *spi)
>> * - external reference: REF is connected, REFIN is not connected
>> */
>>
>> - ref = devm_regulator_get_optional(dev, "ref");
>> - if (IS_ERR(ref)) {
>> - if (PTR_ERR(ref) != -ENODEV)
>> - return dev_err_probe(dev, PTR_ERR(ref),
>> - "failed to get REF supply\n");
>> + ret = devm_regulator_get_enable_read_voltage(dev, "ref");
>> + if (ret < 0 && ret != -ENODEV)
>> + return dev_err_probe(dev, ret, "failed to get REF voltage\n");
>>
>> - ref = NULL;
>> - }
>> + ref_mv = ret == -ENODEV ? 0 : ret / 1000;
>>
>> ret = devm_regulator_get_enable_optional(dev, "refin");
>> - if (ret == 0)
>> - have_refin = true;
>> - else if (ret != -ENODEV)
>> - return dev_err_probe(dev, ret,
>> - "failed to get and enable REFIN supply\n");
>> + if (ret < 0 && ret == -ENODEV)
>> + return dev_err_probe(dev, ret, "failed to get REFIN voltage\n");
>> +
>
> ret != -ENODEV right?
oof, yeah messed that one too
>
> - Nuno Sá
>
>
On Wed, 12 Jun 2024 16:03:06 -0500
David Lechner <[email protected]> wrote:
> This makes use of the new devm_regulator_get_enable_read_voltage()
> function to reduce boilerplate code.
>
> Signed-off-by: David Lechner <[email protected]>
Applied.
Thanks,
On Fri, 14 Jun 2024 10:16:26 -0500
David Lechner <[email protected]> wrote:
> On 6/14/24 10:11 AM, Nuno Sá wrote:
> > On Wed, 2024-06-12 at 16:03 -0500, David Lechner wrote:
> >> This makes use of the new devm_regulator_get_enable_read_voltage()
> >> function to reduce boilerplate code.
> >>
> >> Signed-off-by: David Lechner <[email protected]>
> >> ---
> >> v2 changes:
> >> * avoid else in return value check
> >> * use macro instead of comment to document internal reference voltage
> >> ---
> >> drivers/iio/adc/ad7292.c | 36 ++++++------------------------------
> >> 1 file changed, 6 insertions(+), 30 deletions(-)
> >>
> >> diff --git a/drivers/iio/adc/ad7292.c b/drivers/iio/adc/ad7292.c
> >> index 6aadd14f459d..87ffe66058a1 100644
> >> --- a/drivers/iio/adc/ad7292.c
> >> +++ b/drivers/iio/adc/ad7292.c
> >> @@ -17,6 +17,8 @@
> >>
> >> #define ADI_VENDOR_ID 0x0018
> >>
> >> +#define AD7292_INTERNAL_REF_MV 1250
> >> +
> >> /* AD7292 registers definition */
> >> #define AD7292_REG_VENDOR_ID 0x00
> >> #define AD7292_REG_CONF_BANK 0x05
> >> @@ -79,7 +81,6 @@ static const struct iio_chan_spec ad7292_channels_diff[] = {
> >>
> >> struct ad7292_state {
> >> struct spi_device *spi;
> >> - struct regulator *reg;
> >> unsigned short vref_mv;
> >>
> >> __be16 d16 __aligned(IIO_DMA_MINALIGN);
> >> @@ -250,13 +251,6 @@ static const struct iio_info ad7292_info = {
> >> .read_raw = ad7292_read_raw,
> >> };
> >>
> >> -static void ad7292_regulator_disable(void *data)
> >> -{
> >> - struct ad7292_state *st = data;
> >> -
> >> - regulator_disable(st->reg);
> >> -}
> >> -
> >> static int ad7292_probe(struct spi_device *spi)
> >> {
> >> struct ad7292_state *st;
> >> @@ -277,29 +271,11 @@ static int ad7292_probe(struct spi_device *spi)
> >> return -EINVAL;
> >> }
> >>
> >> - st->reg = devm_regulator_get_optional(&spi->dev, "vref");
> >> - if (!IS_ERR(st->reg)) {
> >> - ret = regulator_enable(st->reg);
> >> - if (ret) {
> >> - dev_err(&spi->dev,
> >> - "Failed to enable external vref supply\n");
> >> - return ret;
> >> - }
> >> -
> >> - ret = devm_add_action_or_reset(&spi->dev,
> >> - ad7292_regulator_disable, st);
> >> - if (ret)
> >> - return ret;
> >> -
> >> - ret = regulator_get_voltage(st->reg);
> >> - if (ret < 0)
> >> - return ret;
> >> + ret = devm_regulator_get_enable_read_voltage(&spi->dev, "vref");
> >> + if (ret < 0 && ret == -ENODEV)
> >
> > ret != -ENODEV?
>
> yup, I messed this one up
Fixed up whilst applying. Applied
>
> >
> > - Nuno Sá
> >
>
On Fri, 14 Jun 2024 10:19:43 -0500
David Lechner <[email protected]> wrote:
> On 6/14/24 10:16 AM, Nuno Sá wrote:
> > On Wed, 2024-06-12 at 16:03 -0500, David Lechner wrote:
> >> This makes use of the new devm_regulator_get_enable_read_voltage()
> >> function to reduce boilerplate code.
> >>
> >> Signed-off-by: David Lechner <[email protected]>
> >> ---
> >>
> >> v2 changes:
> >> - don't read voltage from refin regulator
> >> - avoid else in return value checks
> >> ---
> >> drivers/iio/adc/ad7944.c | 54 +++++++++++-------------------------------------
> >> 1 file changed, 12 insertions(+), 42 deletions(-)
> >>
> >> diff --git a/drivers/iio/adc/ad7944.c b/drivers/iio/adc/ad7944.c
> >> index e2cb64cef476..f8bf03feba07 100644
> >> --- a/drivers/iio/adc/ad7944.c
> >> +++ b/drivers/iio/adc/ad7944.c
> >> @@ -464,23 +464,17 @@ static const char * const ad7944_power_supplies[] = {
> >> "avdd", "dvdd", "bvdd", "vio"
> >> };
> >>
> >> -static void ad7944_ref_disable(void *ref)
> >> -{
> >> - regulator_disable(ref);
> >> -}
> >> -
> >> static int ad7944_probe(struct spi_device *spi)
> >> {
> >> const struct ad7944_chip_info *chip_info;
> >> struct device *dev = &spi->dev;
> >> struct iio_dev *indio_dev;
> >> struct ad7944_adc *adc;
> >> - bool have_refin = false;
> >> - struct regulator *ref;
> >> + bool have_refin;
> >> struct iio_chan_spec *chain_chan;
> >> unsigned long *chain_scan_masks;
> >> u32 n_chain_dev;
> >> - int ret;
> >> + int ret, ref_mv;
> >>
> >> indio_dev = devm_iio_device_alloc(dev, sizeof(*adc));
> >> if (!indio_dev)
> >> @@ -531,47 +525,23 @@ static int ad7944_probe(struct spi_device *spi)
> >> * - external reference: REF is connected, REFIN is not connected
> >> */
> >>
> >> - ref = devm_regulator_get_optional(dev, "ref");
> >> - if (IS_ERR(ref)) {
> >> - if (PTR_ERR(ref) != -ENODEV)
> >> - return dev_err_probe(dev, PTR_ERR(ref),
> >> - "failed to get REF supply\n");
> >> + ret = devm_regulator_get_enable_read_voltage(dev, "ref");
> >> + if (ret < 0 && ret != -ENODEV)
> >> + return dev_err_probe(dev, ret, "failed to get REF voltage\n");
> >>
> >> - ref = NULL;
> >> - }
> >> + ref_mv = ret == -ENODEV ? 0 : ret / 1000;
> >>
> >> ret = devm_regulator_get_enable_optional(dev, "refin");
> >> - if (ret == 0)
> >> - have_refin = true;
> >> - else if (ret != -ENODEV)
> >> - return dev_err_probe(dev, ret,
> >> - "failed to get and enable REFIN supply\n");
> >> + if (ret < 0 && ret == -ENODEV)
> >> + return dev_err_probe(dev, ret, "failed to get REFIN voltage\n");
> >> +
> >
> > ret != -ENODEV right?
>
> oof, yeah messed that one too
>
Fixed up as well and applied.
Enough patches bouncing around that I'd rather clear these little things by
hand than see the patch again :)
Jonathan
> >
> > - Nuno Sá
> >
> >
>