devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/2] dt-bindings: iio: magnetometer: bmc150: Document regulator supplies
@ 2021-01-09 15:23 Stephan Gerhold
  2021-01-09 15:23 ` [PATCH v2 2/2] iio: magnetometer: bmc150: Add rudimentary regulator support Stephan Gerhold
  2021-01-09 19:26 ` [PATCH v2 1/2] dt-bindings: iio: magnetometer: bmc150: Document regulator supplies Jonathan Cameron
  0 siblings, 2 replies; 3+ messages in thread
From: Stephan Gerhold @ 2021-01-09 15:23 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Lars-Peter Clausen, Peter Meerwald-Stadler, Rob Herring,
	linux-iio, devicetree, Linus Walleij, Stephan Gerhold,
	Rob Herring

BMC150 needs VDD and VDDIO regulators that might need to be explicitly
enabled. Document support for vdd/vddio-supply to implement this.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
---
Changes in v2: Picked up Reviewed-by:, split patch series from bmg160
---
 .../bindings/iio/magnetometer/bosch,bmc150_magn.yaml           | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/Documentation/devicetree/bindings/iio/magnetometer/bosch,bmc150_magn.yaml b/Documentation/devicetree/bindings/iio/magnetometer/bosch,bmc150_magn.yaml
index cdef7aeba708..2867ab6bf9b0 100644
--- a/Documentation/devicetree/bindings/iio/magnetometer/bosch,bmc150_magn.yaml
+++ b/Documentation/devicetree/bindings/iio/magnetometer/bosch,bmc150_magn.yaml
@@ -30,6 +30,9 @@ properties:
   reg:
     maxItems: 1
 
+  vdd-supply: true
+  vddio-supply: true
+
   interrupts:
     maxItems: 1
 
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2 2/2] iio: magnetometer: bmc150: Add rudimentary regulator support
  2021-01-09 15:23 [PATCH v2 1/2] dt-bindings: iio: magnetometer: bmc150: Document regulator supplies Stephan Gerhold
@ 2021-01-09 15:23 ` Stephan Gerhold
  2021-01-09 19:26 ` [PATCH v2 1/2] dt-bindings: iio: magnetometer: bmc150: Document regulator supplies Jonathan Cameron
  1 sibling, 0 replies; 3+ messages in thread
From: Stephan Gerhold @ 2021-01-09 15:23 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: Lars-Peter Clausen, Peter Meerwald-Stadler, Rob Herring,
	linux-iio, devicetree, Linus Walleij, Stephan Gerhold

BMC150 needs VDD and VDDIO regulators that might need to be explicitly
enabled. Add some rudimentary support to obtain and enable these
regulators during probe() and disable them during remove()
or on the error path.

Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Signed-off-by: Stephan Gerhold <stephan@gerhold.net>
---
This is mostly copy-paste of
079c1c3f2082 ("iio: accel: bmc150-accel: Add rudimentary regulator support")
from Linus Walleij but for the BMC150 magnetometer driver.

Changes in v2: Picked up Reviewed-by:, split patch series from bmg160
---
 drivers/iio/magnetometer/bmc150_magn.c | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/magnetometer/bmc150_magn.c b/drivers/iio/magnetometer/bmc150_magn.c
index fa09fcab620a..b2f3129e1b4f 100644
--- a/drivers/iio/magnetometer/bmc150_magn.c
+++ b/drivers/iio/magnetometer/bmc150_magn.c
@@ -25,6 +25,7 @@
 #include <linux/iio/trigger_consumer.h>
 #include <linux/iio/triggered_buffer.h>
 #include <linux/regmap.h>
+#include <linux/regulator/consumer.h>
 
 #include "bmc150_magn.h"
 
@@ -135,6 +136,7 @@ struct bmc150_magn_data {
 	 */
 	struct mutex mutex;
 	struct regmap *regmap;
+	struct regulator_bulk_data regulators[2];
 	struct iio_mount_matrix orientation;
 	/* 4 x 32 bits for x, y z, 4 bytes align, 64 bits timestamp */
 	s32 buffer[6];
@@ -692,12 +694,24 @@ static int bmc150_magn_init(struct bmc150_magn_data *data)
 	int ret, chip_id;
 	struct bmc150_magn_preset preset;
 
+	ret = regulator_bulk_enable(ARRAY_SIZE(data->regulators),
+				    data->regulators);
+	if (ret < 0) {
+		dev_err(data->dev, "Failed to enable regulators: %d\n", ret);
+		return ret;
+	}
+	/*
+	 * 3ms power-on time according to datasheet, let's better
+	 * be safe than sorry and set this delay to 5ms.
+	 */
+	msleep(5);
+
 	ret = bmc150_magn_set_power_mode(data, BMC150_MAGN_POWER_MODE_SUSPEND,
 					 false);
 	if (ret < 0) {
 		dev_err(data->dev,
 			"Failed to bring up device from suspend mode\n");
-		return ret;
+		goto err_regulator_disable;
 	}
 
 	ret = regmap_read(data->regmap, BMC150_MAGN_REG_CHIP_ID, &chip_id);
@@ -752,6 +766,8 @@ static int bmc150_magn_init(struct bmc150_magn_data *data)
 
 err_poweroff:
 	bmc150_magn_set_power_mode(data, BMC150_MAGN_POWER_MODE_SUSPEND, true);
+err_regulator_disable:
+	regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
 	return ret;
 }
 
@@ -867,6 +883,13 @@ int bmc150_magn_probe(struct device *dev, struct regmap *regmap,
 	data->irq = irq;
 	data->dev = dev;
 
+	data->regulators[0].supply = "vdd";
+	data->regulators[1].supply = "vddio";
+	ret = devm_regulator_bulk_get(dev, ARRAY_SIZE(data->regulators),
+				      data->regulators);
+	if (ret)
+		return dev_err_probe(dev, ret, "failed to get regulators\n");
+
 	ret = iio_read_mount_matrix(dev, "mount-matrix",
 				&data->orientation);
 	if (ret)
@@ -984,6 +1007,7 @@ int bmc150_magn_remove(struct device *dev)
 	bmc150_magn_set_power_mode(data, BMC150_MAGN_POWER_MODE_SUSPEND, true);
 	mutex_unlock(&data->mutex);
 
+	regulator_bulk_disable(ARRAY_SIZE(data->regulators), data->regulators);
 	return 0;
 }
 EXPORT_SYMBOL(bmc150_magn_remove);
-- 
2.30.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v2 1/2] dt-bindings: iio: magnetometer: bmc150: Document regulator supplies
  2021-01-09 15:23 [PATCH v2 1/2] dt-bindings: iio: magnetometer: bmc150: Document regulator supplies Stephan Gerhold
  2021-01-09 15:23 ` [PATCH v2 2/2] iio: magnetometer: bmc150: Add rudimentary regulator support Stephan Gerhold
@ 2021-01-09 19:26 ` Jonathan Cameron
  1 sibling, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2021-01-09 19:26 UTC (permalink / raw)
  To: Stephan Gerhold
  Cc: Lars-Peter Clausen, Peter Meerwald-Stadler, Rob Herring,
	linux-iio, devicetree, Linus Walleij, Rob Herring

On Sat,  9 Jan 2021 16:23:26 +0100
Stephan Gerhold <stephan@gerhold.net> wrote:

> BMC150 needs VDD and VDDIO regulators that might need to be explicitly
> enabled. Document support for vdd/vddio-supply to implement this.
> 
> Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
> Reviewed-by: Rob Herring <robh@kernel.org>
> Signed-off-by: Stephan Gerhold <stephan@gerhold.net>

Thanks for the quick resend!

Series applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to poke at it and see if they can find anything we missed.

Jonathan
> ---
> Changes in v2: Picked up Reviewed-by:, split patch series from bmg160
> ---
>  .../bindings/iio/magnetometer/bosch,bmc150_magn.yaml           | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/Documentation/devicetree/bindings/iio/magnetometer/bosch,bmc150_magn.yaml b/Documentation/devicetree/bindings/iio/magnetometer/bosch,bmc150_magn.yaml
> index cdef7aeba708..2867ab6bf9b0 100644
> --- a/Documentation/devicetree/bindings/iio/magnetometer/bosch,bmc150_magn.yaml
> +++ b/Documentation/devicetree/bindings/iio/magnetometer/bosch,bmc150_magn.yaml
> @@ -30,6 +30,9 @@ properties:
>    reg:
>      maxItems: 1
>  
> +  vdd-supply: true
> +  vddio-supply: true
> +
>    interrupts:
>      maxItems: 1
>  


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2021-01-09 19:27 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-09 15:23 [PATCH v2 1/2] dt-bindings: iio: magnetometer: bmc150: Document regulator supplies Stephan Gerhold
2021-01-09 15:23 ` [PATCH v2 2/2] iio: magnetometer: bmc150: Add rudimentary regulator support Stephan Gerhold
2021-01-09 19:26 ` [PATCH v2 1/2] dt-bindings: iio: magnetometer: bmc150: Document regulator supplies Jonathan Cameron

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).