diff mbox series

[15/15] iio: sx9310: Enable vdd and svdd regulators at probe

Message ID 20200728091057.15.Iaf4d717d1908ef22c88922b556e1eb803ae019c6@changeid (mailing list archive)
State New, archived
Headers show
Series sx9310 iio driver updates | expand

Commit Message

Daniel Campello July 28, 2020, 3:12 p.m. UTC
From: Stephen Boyd <swboyd@chromium.org>

Enable the main power supply (vdd) and digital IO power supply (svdd)
during probe so that the i2c communication and device works properly on
boards that aggressively power gate these supplies.

Reviewed-by: Douglas Anderson <dianders@chromium.org>
Signed-off-by: Stephen Boyd <swboyd@chromium.org>
Signed-off-by: Daniel Campello <campello@chromium.org>
---

 drivers/iio/proximity/sx9310.c | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

Comments

Andy Shevchenko July 28, 2020, 6:21 p.m. UTC | #1
On Tue, Jul 28, 2020 at 6:14 PM Daniel Campello <campello@chromium.org> wrote:
>
> From: Stephen Boyd <swboyd@chromium.org>
>
> Enable the main power supply (vdd) and digital IO power supply (svdd)
> during probe so that the i2c communication and device works properly on
> boards that aggressively power gate these supplies.
>
> Reviewed-by: Douglas Anderson <dianders@chromium.org>
> Signed-off-by: Stephen Boyd <swboyd@chromium.org>
> Signed-off-by: Daniel Campello <campello@chromium.org>

Again wrong order.
After fixing,
Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com>

> ---
>
>  drivers/iio/proximity/sx9310.c | 26 ++++++++++++++++++++++++++
>  1 file changed, 26 insertions(+)
>
> diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c
> index 202018b726e32f..24a2360b6314ef 100644
> --- a/drivers/iio/proximity/sx9310.c
> +++ b/drivers/iio/proximity/sx9310.c
> @@ -18,6 +18,7 @@
>  #include <linux/module.h>
>  #include <linux/pm.h>
>  #include <linux/regmap.h>
> +#include <linux/regulator/consumer.h>
>  #include <linux/slab.h>
>
>  #include <linux/iio/buffer.h>
> @@ -118,6 +119,7 @@ struct sx9310_data {
>         struct i2c_client *client;
>         struct iio_trigger *trig;
>         struct regmap *regmap;
> +       struct regulator_bulk_data supplies[2];
>         /*
>          * Last reading of the proximity status for each channel.
>          * We only send an event to user space when this changes.
> @@ -873,6 +875,13 @@ static int sx9310_set_indio_dev_name(struct device *dev,
>         return 0;
>  }
>
> +static void sx9310_regulator_disable(void *_data)
> +{
> +       struct sx9310_data *data = _data;
> +
> +       regulator_bulk_disable(ARRAY_SIZE(data->supplies), data->supplies);
> +}
> +
>  static int sx9310_probe(struct i2c_client *client)
>  {
>         int ret;
> @@ -886,6 +895,8 @@ static int sx9310_probe(struct i2c_client *client)
>
>         data = iio_priv(indio_dev);
>         data->client = client;
> +       data->supplies[0].supply = "vdd";
> +       data->supplies[1].supply = "svdd";
>         mutex_init(&data->mutex);
>         init_completion(&data->completion);
>
> @@ -893,6 +904,21 @@ static int sx9310_probe(struct i2c_client *client)
>         if (IS_ERR(data->regmap))
>                 return PTR_ERR(data->regmap);
>
> +       ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(data->supplies),
> +                                     data->supplies);
> +       if (ret)
> +               return ret;
> +
> +       ret = regulator_bulk_enable(ARRAY_SIZE(data->supplies), data->supplies);
> +       if (ret)
> +               return ret;
> +       /* Must wait for Tpor time after initial power up */
> +       usleep_range(1000, 1100);
> +
> +       ret = devm_add_action_or_reset(dev, sx9310_regulator_disable, data);
> +       if (ret)
> +               return ret;
> +
>         ret = regmap_read(data->regmap, SX9310_REG_WHOAMI, &data->whoami);
>         if (ret) {
>                 dev_err(dev, "error in reading WHOAMI register: %d\n", ret);
> --
> 2.28.0.rc0.142.g3c755180ce-goog
>
diff mbox series

Patch

diff --git a/drivers/iio/proximity/sx9310.c b/drivers/iio/proximity/sx9310.c
index 202018b726e32f..24a2360b6314ef 100644
--- a/drivers/iio/proximity/sx9310.c
+++ b/drivers/iio/proximity/sx9310.c
@@ -18,6 +18,7 @@ 
 #include <linux/module.h>
 #include <linux/pm.h>
 #include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
 #include <linux/slab.h>
 
 #include <linux/iio/buffer.h>
@@ -118,6 +119,7 @@  struct sx9310_data {
 	struct i2c_client *client;
 	struct iio_trigger *trig;
 	struct regmap *regmap;
+	struct regulator_bulk_data supplies[2];
 	/*
 	 * Last reading of the proximity status for each channel.
 	 * We only send an event to user space when this changes.
@@ -873,6 +875,13 @@  static int sx9310_set_indio_dev_name(struct device *dev,
 	return 0;
 }
 
+static void sx9310_regulator_disable(void *_data)
+{
+	struct sx9310_data *data = _data;
+
+	regulator_bulk_disable(ARRAY_SIZE(data->supplies), data->supplies);
+}
+
 static int sx9310_probe(struct i2c_client *client)
 {
 	int ret;
@@ -886,6 +895,8 @@  static int sx9310_probe(struct i2c_client *client)
 
 	data = iio_priv(indio_dev);
 	data->client = client;
+	data->supplies[0].supply = "vdd";
+	data->supplies[1].supply = "svdd";
 	mutex_init(&data->mutex);
 	init_completion(&data->completion);
 
@@ -893,6 +904,21 @@  static int sx9310_probe(struct i2c_client *client)
 	if (IS_ERR(data->regmap))
 		return PTR_ERR(data->regmap);
 
+	ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(data->supplies),
+				      data->supplies);
+	if (ret)
+		return ret;
+
+	ret = regulator_bulk_enable(ARRAY_SIZE(data->supplies), data->supplies);
+	if (ret)
+		return ret;
+	/* Must wait for Tpor time after initial power up */
+	usleep_range(1000, 1100);
+
+	ret = devm_add_action_or_reset(dev, sx9310_regulator_disable, data);
+	if (ret)
+		return ret;
+
 	ret = regmap_read(data->regmap, SX9310_REG_WHOAMI, &data->whoami);
 	if (ret) {
 		dev_err(dev, "error in reading WHOAMI register: %d\n", ret);