Skip to contentSkip to conversation

st_lsm6dsx: add vdd-vddio power regulator

PATCH In review Lorenzo Bianconi 2 participants 7 messages Nov 17, 2020 – Nov 23, 2020

Subsystems (3)
lore
Share & tools
lore

Lorenzo Bianconi

author maintainer
#0 lore raw

v2 cover st_lsm6dsx: add vdd-vddio power regulator

Introduce support to control VDD and VDDIO power lines available on st_lsm6dsx devices

Changes since v1:
- rebase patch 2/2 ontop of st_lsm6dsx dt yaml conversion

Lorenzo Bianconi (2):
iio: imu: st_lsm6dsx: add vdd-vddio voltage regulator
dt-bindings: iio: imu: st_lsm6dsx: introduce vdd-vddio regulators
bindings

 .../bindings/iio/imu/st,lsm6dsx.yaml          |  6 +++
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h       |  3 ++
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c  | 42 +++++++++++++++++++
 3 files changed, 51 insertions(+)
Signature · 1 line
2.26.2
author maintainer
#1 lore raw

PATCH v2 1/2 iio: imu: st_lsm6dsx: add vdd-vddio voltage regulator

Like all other ST sensors, st_lsm6dsx devices have VDD and VDDIO power lines. Introduce voltage regulators to control them.

---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |  3 ++
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 42 ++++++++++++++++++++
 2 files changed, 45 insertions(+)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +3 -0
index 1f31657a7a0e..4b4ec39d4400 100644
@@ -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;
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +42 -0

54 lines not on this page · raw message

Signature · 1 line
2.26.2
author maintainer
#6 lore raw

PATCH v2 2/2 dt-bindings: iio: imu: st_lsm6dsx: introduce vdd-vddio regulators bindings

In reply to Lorenzo Bianconi
---
 Documentation/devicetree/bindings/iio/imu/st,lsm6dsx.yaml | 6 ++++++
 1 file changed, 6 insertions(+)
Documentation/devicetree/bindings/iio/imu/st,lsm6dsx.yaml +6 -0
index 49d0687e0c06..fc545a130b30 100644
@@ -42,6 +42,12 @@ properties:
 
   spi-max-frequency: true
 
+  vdd-supply:
+    description: if defined provides VDD power to the sensor.
+
+  vddio-supply:
+    description: if defined provides VDD IO power to the sensor.
+
   st,drdy-int-pin:
     $ref: '/schemas/types.yaml#/definitions/uint32'
     description: |
Signature · 1 line
2.26.2
maintainer
#2 lore raw

Re: [PATCH v2 1/2] iio: imu: st_lsm6dsx: add vdd-vddio voltage regulator

In reply to Lorenzo Bianconi
Quoted 4 lines · On Tue, 17 Nov 2020 17:47:25 +0100 Lorenzo Bianconi <[email protected]> wrote:

Like all other ST sensors, st_lsm6dsx devices have VDD and VDDIO power lines. Introduce voltage regulators to control them.

Oops. I should have pointed out the dev_err_probe more appropriate to avoid complaining when we just tried to probe to early in the sequence and will try again later. I'll hopefully fix this up an apply once I've picked up my own patch to do the yaml conversion.

Jonathan

Quoted 93 lines
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |  3 ++
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 42 ++++++++++++++++++++
 2 files changed, 45 insertions(+)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +3 -0
index 1f31657a7a0e..4b4ec39d4400 100644
@@ -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;
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +42 -0
index 5e584c6026f1..fde46377826c 100644
@@ -2533,6 +2533,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)
 {
@@ -2552,6 +2586,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;
author maintainer
#3 lore raw

Re: [PATCH v2 1/2] iio: imu: st_lsm6dsx: add vdd-vddio voltage regulator

Quoted 12 lines
Quoted 4 lines · On Tue, 17 Nov 2020 17:47:25 +0100 Lorenzo Bianconi <[email protected]> wrote:

Like all other ST sensors, st_lsm6dsx devices have VDD and VDDIO power lines. Introduce voltage regulators to control them.

Oops. I should have pointed out the dev_err_probe more appropriate to avoid complaining when we just tried to probe to early in the sequence and will try again later. I'll hopefully fix this up an apply once I've picked up my own patch to do the yaml conversion.

ack, fine for me otherwise I can just send v3. Up to you.

Regards,
Lorenzo

Quoted 96 lines

Jonathan

Quoted 93 lines
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |  3 ++
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 42 ++++++++++++++++++++
 2 files changed, 45 insertions(+)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +3 -0
index 1f31657a7a0e..4b4ec39d4400 100644
@@ -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;
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +42 -0
index 5e584c6026f1..fde46377826c 100644
@@ -2533,6 +2533,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)
 {
@@ -2552,6 +2586,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;
maintainer
#4 lore raw

Re: [PATCH v2 1/2] iio: imu: st_lsm6dsx: add vdd-vddio voltage regulator

Quoted 6 lines · On Sun, 22 Nov 2020 11:36:44 +0100 Lorenzo Bianconi <[email protected]> wrote:
Quoted 6 lines
Quoted 3 lines · On Tue, 17 Nov 2020 17:47:25 +0100 Lorenzo Bianconi <[email protected]> wrote:

Like all other ST sensors, st_lsm6dsx devices have VDD and VDDIO power lines. Introduce voltage regulators to control them.

Quoted 8 lines
Quoted 6 lines
Quoted 1 line

Oops. I should have pointed out the dev_err_probe more appropriate to avoid complaining when we just tried to probe to early in the sequence and will try again later. I'll hopefully fix this up an apply once I've picked up my own patch to do the yaml conversion.

ack, fine for me otherwise I can just send v3. Up to you.

I've done it and applied both this and patch 2 to the togreg branch of iio.git (having earlier applied the binding conversion patch).

Please take a quick look and make sure it all looks right to you.

Thanks,

Jonathan

Quoted 100 lines

Regards,
Lorenzo

Quoted 96 lines

Jonathan

Quoted 93 lines
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |  3 ++
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 42 ++++++++++++++++++++
 2 files changed, 45 insertions(+)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +3 -0
index 1f31657a7a0e..4b4ec39d4400 100644
@@ -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;
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +42 -0
index 5e584c6026f1..fde46377826c 100644
@@ -2533,6 +2533,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)
 {
@@ -2552,6 +2586,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;  
author maintainer
#5 lore raw

Re: [PATCH v2 1/2] iio: imu: st_lsm6dsx: add vdd-vddio voltage regulator

Quoted 16 lines
Quoted 13 lines · On Sun, 22 Nov 2020 11:36:44 +0100 Lorenzo Bianconi <[email protected]> wrote:
Quoted 12 lines
Quoted 4 lines · On Tue, 17 Nov 2020 17:47:25 +0100 Lorenzo Bianconi <[email protected]> wrote:

Like all other ST sensors, st_lsm6dsx devices have VDD and VDDIO power lines. Introduce voltage regulators to control them.

Oops. I should have pointed out the dev_err_probe more appropriate to avoid complaining when we just tried to probe to early in the sequence and will try again later. I'll hopefully fix this up an apply once I've picked up my own patch to do the yaml conversion.

Quoted 5 lines
Quoted 1 line

ack, fine for me otherwise I can just send v3. Up to you.

I've done it and applied both this and patch 2 to the togreg branch of iio.git (having earlier applied the binding conversion patch).

Please take a quick look and make sure it all looks right to you.

ack, it is fine, thanks Jonathan.

Regards,
Lorenzo

Quoted 106 lines

Thanks,

Jonathan

Quoted 100 lines

Regards,
Lorenzo

Quoted 96 lines

Jonathan

Quoted 93 lines
---
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h      |  3 ++
 drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c | 42 ++++++++++++++++++++
 2 files changed, 45 insertions(+)
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx.h +3 -0
index 1f31657a7a0e..4b4ec39d4400 100644
@@ -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;
drivers/iio/imu/st_lsm6dsx/st_lsm6dsx_core.c +42 -0
index 5e584c6026f1..fde46377826c 100644
@@ -2533,6 +2533,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)
 {
@@ -2552,6 +2586,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;