linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Linus Walleij <linus.walleij@linaro.org>
Cc: linux-iio@vger.kernel.org, Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	linux-input@vger.kernel.org
Subject: Re: [PATCH 3/3] iio: accel: bmc150-accel: Add rudimentary regulator support
Date: Sun, 1 Nov 2020 20:52:19 +0000	[thread overview]
Message-ID: <20201101205219.63ca6485@archlinux> (raw)
In-Reply-To: <20201101122833.1111424-3-linus.walleij@linaro.org>

On Sun,  1 Nov 2020 13:28:33 +0100
Linus Walleij <linus.walleij@linaro.org> wrote:

> These Bosch accelerometers have two supplies, VDD and VDDIO.
> Add some rudimentary support to obtain and enable these
> regulators during probe() and disable them during remove()
> or on the errorpath.
> 
> Signed-off-by: Linus Walleij <linus.walleij@linaro.org>
Minor suggestion inline using new dev_err_probe()

thanks,

Jonathan
> ---
>  drivers/iio/accel/bmc150-accel-core.c | 37 +++++++++++++++++++++++++--
>  1 file changed, 35 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c
> index 0dafe4052856..a69a4f54d69a 100644
> --- a/drivers/iio/accel/bmc150-accel-core.c
> +++ b/drivers/iio/accel/bmc150-accel-core.c
> @@ -28,6 +28,7 @@
>  #include <linux/iio/trigger_consumer.h>
>  #include <linux/iio/triggered_buffer.h>
>  #include <linux/regmap.h>
> +#include <linux/regulator/consumer.h>
>  
>  #include "bmc150-accel.h"
>  
> @@ -184,6 +185,7 @@ enum bmc150_accel_trigger_id {
>  
>  struct bmc150_accel_data {
>  	struct regmap *regmap;
> +	struct regulator_bulk_data regulators[2];
>  	int irq;
>  	struct bmc150_accel_interrupt interrupts[BMC150_ACCEL_INTERRUPTS];
>  	struct bmc150_accel_trigger triggers[BMC150_ACCEL_TRIGGERS];
> @@ -1593,10 +1595,35 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
>  				     &data->orientation);
>  	if (ret)
>  		return ret;
> +	/*
> +	 * VDD   is the analog and digital domain voltage supply
> +	 * VDDIO is the digital I/O voltage supply
> +	 */
> +	data->regulators[0].supply = "vdd";
> +	data->regulators[1].supply = "vddio";
> +	ret = devm_regulator_bulk_get(dev,
> +				      ARRAY_SIZE(data->regulators),
> +				      data->regulators);
> +	if (ret) {
> +		if (ret != -EPROBE_DEFER)
> +			dev_err(dev, "Failed to get regulators %d\n", ret);
We have a magic print function for this now

return dev_err_probe(ret, "Failed to get regulators\n");

should do the job I think...

> +		return ret;
> +	}
> +	ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators),
> +				    data->regulators);
> +	if (ret) {
> +		dev_err(dev, "failed to enable regulators: %d\n", ret);
> +		return ret;
> +	}
> +	/*
> +	 * 2ms or 3ms power-on time according to datasheets, let's better
> +	 * be safe than sorry and set this delay to 5ms.
> +	 */
> +	msleep(5);
>  
>  	ret = bmc150_accel_chip_init(data);
>  	if (ret < 0)
> -		return ret;
> +		goto err_disable_regulators;
>  
>  	mutex_init(&data->mutex);
>  
> @@ -1613,7 +1640,7 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
>  					 &bmc150_accel_buffer_ops);
>  	if (ret < 0) {
>  		dev_err(dev, "Failed: iio triggered buffer setup\n");
> -		return ret;
> +		goto err_disable_regulators;
>  	}
>  
>  	if (data->irq > 0) {
> @@ -1674,6 +1701,9 @@ int bmc150_accel_core_probe(struct device *dev, struct regmap *regmap, int irq,
>  	bmc150_accel_unregister_triggers(data, BMC150_ACCEL_TRIGGERS - 1);
>  err_buffer_cleanup:
>  	iio_triggered_buffer_cleanup(indio_dev);
> +err_disable_regulators:
> +	regulator_bulk_disable(ARRAY_SIZE(data->regulators),
> +			       data->regulators);
>  
>  	return ret;
>  }
> @@ -1698,6 +1728,9 @@ int bmc150_accel_core_remove(struct device *dev)
>  	bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_DEEP_SUSPEND, 0);
>  	mutex_unlock(&data->mutex);
>  
> +	regulator_bulk_disable(ARRAY_SIZE(data->regulators),
> +			       data->regulators);
> +
>  	return 0;
>  }
>  EXPORT_SYMBOL_GPL(bmc150_accel_core_remove);


  reply	other threads:[~2020-11-01 20:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-01 12:28 [PATCH 1/3] iio: accel: bmc150-accel: Add DT bindings Linus Walleij
2020-11-01 12:28 ` [PATCH 2/3] iio: accel: bmc150-accel: Add support for BMA222 Linus Walleij
2020-11-01 20:47   ` Jonathan Cameron
2020-11-01 12:28 ` [PATCH 3/3] iio: accel: bmc150-accel: Add rudimentary regulator support Linus Walleij
2020-11-01 20:52   ` Jonathan Cameron [this message]
2020-11-01 20:44 ` [PATCH 1/3] iio: accel: bmc150-accel: Add DT bindings Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201101205219.63ca6485@archlinux \
    --to=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linus.walleij@linaro.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).