[PATCH v2 06/14] iio: accel: bma220: add get regulator check

Petre Rodan posted 14 patches 3 weeks, 1 day ago
There is a newer version of this series
[PATCH v2 06/14] iio: accel: bma220: add get regulator check
Posted by Petre Rodan 3 weeks, 1 day ago
Add devm_regulator_bulk_get_enable() to device probe().

Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
---
no change
---
 drivers/iio/accel/bma220_core.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c
index 6bc2e5c3fb6cebd50209acbcc2d5340630c27cd1..b6f1374a9cca52966c1055113710061a7284cf5a 100644
--- a/drivers/iio/accel/bma220_core.c
+++ b/drivers/iio/accel/bma220_core.c
@@ -11,6 +11,7 @@
 #include <linux/module.h>
 #include <linux/mutex.h>
 #include <linux/pm.h>
+#include <linux/regulator/consumer.h>
 #include <linux/types.h>
 #include <linux/spi/spi.h>
 
@@ -205,6 +206,13 @@ static const struct iio_info bma220_info = {
 static int bma220_init(struct spi_device *spi)
 {
 	int ret;
+	static const char * const regulator_names[] = { "vddd", "vddio", "vdda" };
+
+	ret = devm_regulator_bulk_get_enable(&spi->dev,
+					     ARRAY_SIZE(regulator_names),
+					     regulator_names);
+	if (ret)
+		return dev_err_probe(&spi->dev, ret, "Failed to get regulators\n");
 
 	ret = bma220_read_reg(spi, BMA220_REG_ID);
 	if (ret != BMA220_CHIP_ID)

-- 
2.49.1
Re: [PATCH v2 06/14] iio: accel: bma220: add get regulator check
Posted by Jonathan Cameron 3 weeks, 1 day ago
On Wed, 10 Sep 2025 10:57:11 +0300
Petre Rodan <petre.rodan@subdimension.ro> wrote:

I don't follow the 'add get regulator check' of the patch description.
This is ensuring they are powered up if necessary.  So I'd
just go with the vague: "turn power supplies on"


> Add devm_regulator_bulk_get_enable() to device probe().
> 
> Signed-off-by: Petre Rodan <petre.rodan@subdimension.ro>
> ---
> no change
> ---
>  drivers/iio/accel/bma220_core.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/drivers/iio/accel/bma220_core.c b/drivers/iio/accel/bma220_core.c
> index 6bc2e5c3fb6cebd50209acbcc2d5340630c27cd1..b6f1374a9cca52966c1055113710061a7284cf5a 100644
> --- a/drivers/iio/accel/bma220_core.c
> +++ b/drivers/iio/accel/bma220_core.c
> @@ -11,6 +11,7 @@
>  #include <linux/module.h>
>  #include <linux/mutex.h>
>  #include <linux/pm.h>
> +#include <linux/regulator/consumer.h>
>  #include <linux/types.h>
>  #include <linux/spi/spi.h>
>  
> @@ -205,6 +206,13 @@ static const struct iio_info bma220_info = {
>  static int bma220_init(struct spi_device *spi)
>  {
>  	int ret;
> +	static const char * const regulator_names[] = { "vddd", "vddio", "vdda" };
> +
> +	ret = devm_regulator_bulk_get_enable(&spi->dev,
> +					     ARRAY_SIZE(regulator_names),
> +					     regulator_names);
> +	if (ret)
> +		return dev_err_probe(&spi->dev, ret, "Failed to get regulators\n");
>  
>  	ret = bma220_read_reg(spi, BMA220_REG_ID);
>  	if (ret != BMA220_CHIP_ID)
>
Re: [PATCH v2 06/14] iio: accel: bma220: add get regulator check
Posted by Petre Rodan 3 weeks, 1 day ago
Hello Jonathan,

thank you for the blazing fast feedback!

On Wed, Sep 10, 2025 at 06:58:41PM +0100, Jonathan Cameron wrote:
> On Wed, 10 Sep 2025 10:57:11 +0300
> Petre Rodan <petre.rodan@subdimension.ro> wrote:
> 
> I don't follow the 'add get regulator check' of the patch description.
> This is ensuring they are powered up if necessary.  So I'd
> just go with the vague: "turn power supplies on"

to be honest I added this just because I've seen the devm_regulator_bulk_get_enable() function used all over the place in iio code.
but looking at the linux/regulator/consumers.h header I was more puzzled.
just some forward declarations and then static functions doing exactly nothing.
I'm afraid to ask what that is all about. placeholder for a future API?

best regards,
peter

> > +#include <linux/regulator/consumer.h>
> >  #include <linux/types.h>
> >  #include <linux/spi/spi.h>
> >  
> > @@ -205,6 +206,13 @@ static const struct iio_info bma220_info = {
> >  static int bma220_init(struct spi_device *spi)
> >  {
> >  	int ret;
> > +	static const char * const regulator_names[] = { "vddd", "vddio", "vdda" };
> > +
> > +	ret = devm_regulator_bulk_get_enable(&spi->dev,
> > +					     ARRAY_SIZE(regulator_names),
> > +					     regulator_names);
> > +	if (ret)
> > +		return dev_err_probe(&spi->dev, ret, "Failed to get regulators\n");
Re: [PATCH v2 06/14] iio: accel: bma220: add get regulator check
Posted by Andy Shevchenko 3 weeks, 1 day ago
On Wed, Sep 10, 2025 at 9:52 PM Petre Rodan <petre.rodan@subdimension.ro> wrote:
> On Wed, Sep 10, 2025 at 06:58:41PM +0100, Jonathan Cameron wrote:
> > On Wed, 10 Sep 2025 10:57:11 +0300
> > Petre Rodan <petre.rodan@subdimension.ro> wrote:
> >
> > I don't follow the 'add get regulator check' of the patch description.
> > This is ensuring they are powered up if necessary.  So I'd
> > just go with the vague: "turn power supplies on"
>
> to be honest I added this just because I've seen the devm_regulator_bulk_get_enable() function used all over the place in iio code.
> but looking at the linux/regulator/consumers.h header I was more puzzled.
> just some forward declarations and then static functions doing exactly nothing.
> I'm afraid to ask what that is all about. placeholder for a future API?

You probably see two things in one place:
1/ declaration of the function that is implemented in the C-code
2/ stub for the case when implementation is switched off (usually via
kernel configuration).

I recommend using elixir.bootlin.com to browse the code, or locally
via cscope or similar.


-- 
With Best Regards,
Andy Shevchenko