From: Jonathan Cameron <Jonathan.Cameron@Huawei.com>
To: Lorenzo Bianconi <lorenzo@kernel.org>
Cc: <jic23@kernel.org>, <lorenzo.bianconi@redhat.com>,
<linux-iio@vger.kernel.org>, <devicetree@vger.kernel.org>
Subject: Re: [PATCH 1/2] iio: imu: st_lsm6dsx: add vdd-vddio voltage regulator
Date: Tue, 17 Nov 2020 16:07:23 +0000 [thread overview]
Message-ID: <20201117160723.00003ac2@Huawei.com> (raw)
In-Reply-To: <823bbe45fc7b7feb144bd16a6757816ba5e67b86.1605625579.git.lorenzo@kernel.org>
On Tue, 17 Nov 2020 16:11:37 +0100
Lorenzo Bianconi <lorenzo@kernel.org> wrote:
> Like all other ST sensors, st_lsm6dsx devices have VDD and VDDIO power
> lines. Introduce voltage regulators to control them.
>
> Signed-off-by: Lorenzo Bianconi <lorenzo@kernel.org>
Looks good to me.
> ---
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h | 3 ++
> drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 42 ++++++++++++++++++++
> 2 files changed, 45 insertions(+)
>
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> index 1f31657a7a0e..4b4ec39d4400 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h
> @@ -13,6 +13,7 @@
>
> #include <linux/device.h>
> #include <linux/iio/iio.h>
> +#include <linux/regulator/consumer.h>
>
> #define ST_LSM6DS3_DEV_NAME "lsm6ds3"
> #define ST_LSM6DS3H_DEV_NAME "lsm6ds3h"
> @@ -368,6 +369,7 @@ struct st_lsm6dsx_sensor {
> * struct st_lsm6dsx_hw - ST IMU MEMS hw instance
> * @dev: Pointer to instance of struct device (I2C or SPI).
> * @regmap: Register map of the device.
> + * @regulators: VDD/VDDIO voltage regulators.
> * @irq: Device interrupt line (I2C or SPI).
> * @fifo_lock: Mutex to prevent concurrent access to the hw FIFO.
> * @conf_lock: Mutex to prevent concurrent FIFO configuration update.
> @@ -390,6 +392,7 @@ struct st_lsm6dsx_sensor {
> struct st_lsm6dsx_hw {
> struct device *dev;
> struct regmap *regmap;
> + struct regulator_bulk_data regulators[2];
> int irq;
>
> struct mutex fifo_lock;
> diff --git a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> index da91f5e7e86d..8b9b724121a8 100644
> --- a/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> +++ b/drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c
> @@ -2549,6 +2549,40 @@ static int st_lsm6dsx_irq_setup(struct st_lsm6dsx_hw *hw)
> return 0;
> }
>
> +static int st_lsm6dsx_init_regulators(struct device *dev)
> +{
> + struct st_lsm6dsx_hw *hw = dev_get_drvdata(dev);
> + int err;
> +
> + /* vdd-vddio power regulators */
> + hw->regulators[0].supply = "vdd";
> + hw->regulators[1].supply = "vddio";
> + err = devm_regulator_bulk_get(dev, ARRAY_SIZE(hw->regulators),
> + hw->regulators);
> + if (err) {
> + dev_err(dev, "failed to get regulators: %d\n", err);
> + return err;
> + }
> +
> + err = regulator_bulk_enable(ARRAY_SIZE(hw->regulators),
> + hw->regulators);
> + if (err) {
> + dev_err(dev, "failed to enable regulators: %d\n", err);
> + return err;
> + }
> +
> + msleep(50);
> +
> + return 0;
> +}
> +
> +static void st_lsm6dsx_chip_uninit(void *data)
> +{
> + struct st_lsm6dsx_hw *hw = data;
> +
> + regulator_bulk_disable(ARRAY_SIZE(hw->regulators), hw->regulators);
> +}
> +
> int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
> struct regmap *regmap)
> {
> @@ -2568,6 +2602,14 @@ int st_lsm6dsx_probe(struct device *dev, int irq, int hw_id,
> mutex_init(&hw->conf_lock);
> mutex_init(&hw->page_lock);
>
> + err = st_lsm6dsx_init_regulators(dev);
> + if (err)
> + return err;
> +
> + err = devm_add_action_or_reset(dev, st_lsm6dsx_chip_uninit, hw);
> + if (err)
> + return err;
> +
> hw->buff = devm_kzalloc(dev, ST_LSM6DSX_BUFF_SIZE, GFP_KERNEL);
> if (!hw->buff)
> return -ENOMEM;
next prev parent reply other threads:[~2020-11-17 16:07 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-17 15:11 [PATCH 0/2] st_lsm6dsx: add vdd-vddio power regulator Lorenzo Bianconi
2020-11-17 15:11 ` [PATCH 1/2] iio: imu: st_lsm6dsx: add vdd-vddio voltage regulator Lorenzo Bianconi
2020-11-17 16:07 ` Jonathan Cameron [this message]
2020-11-17 15:11 ` [PATCH 2/2] dt-bindings: iio: imu: st_lsm6dsx: introduce vdd-vddio regulators bindings Lorenzo Bianconi
2020-11-17 16:06 ` Jonathan Cameron
2020-11-17 16:17 ` Lorenzo Bianconi
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=20201117160723.00003ac2@Huawei.com \
--to=jonathan.cameron@huawei.com \
--cc=devicetree@vger.kernel.org \
--cc=jic23@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=lorenzo.bianconi@redhat.com \
--cc=lorenzo@kernel.org \
/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).