2019-11-07 18:47:22

by Stephan Gerhold

[permalink] [raw]
Subject: [PATCH v2 1/2] dt-bindings: iio: imo: mpu6050: add vdd-supply

inv_mpu6050 now supports an additional vdd-supply; document it.

Reviewed-by: Linus Walleij <[email protected]>
Signed-off-by: Stephan Gerhold <[email protected]>
---
Changes in v2:
- Add Reviewed-by from Linus Walleij

v1: https://lore.kernel.org/linux-iio/[email protected]/
---
Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt | 1 +
1 file changed, 1 insertion(+)

diff --git a/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt b/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
index 268bf7568e19..c5ee8a20af9f 100644
--- a/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
+++ b/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
@@ -21,6 +21,7 @@ Required properties:
bindings.

Optional properties:
+ - vdd-supply: regulator phandle for VDD supply
- vddio-supply: regulator phandle for VDDIO supply
- mount-matrix: an optional 3x3 mounting rotation matrix
- i2c-gate node. These devices also support an auxiliary i2c bus. This is
--
2.23.0


2019-11-07 18:47:39

by Stephan Gerhold

[permalink] [raw]
Subject: [PATCH v2 2/2] iio: imu: mpu6050: Add support for vdd-supply regulator

MPU6050 has two power supply pins: VDD and VLOGIC, but the
mpu6050 driver only supports enabling one of them at the moment.
In some cases, they may need to be enabled separately.

Add an additional "vdd-supply" that stays enabled for as long as
the driver is loaded. We cannot turn off the VDD regulator during
suspend as this would cause register settings (FSR, sampling rate, ...)
to be lost.

Signed-off-by: Stephan Gerhold <[email protected]>
---
Changes in v2:
- Keep "vdd-supply" enabled during suspend to prevent register
settings from getting lost.
- Revert convertion to bulk regulator API (does not work well
when regulators need to be enabled/disabled separately)

v1: https://lore.kernel.org/linux-iio/[email protected]/
---
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 43 +++++++++++++++++-----
drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 4 +-
2 files changed, 37 insertions(+), 10 deletions(-)

diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
index 354030e9bed5..661a829478f5 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -1140,14 +1140,14 @@ static int inv_check_and_setup_chip(struct inv_mpu6050_state *st)
return result;
}

-static int inv_mpu_core_enable_regulator(struct inv_mpu6050_state *st)
+static int inv_mpu_core_enable_regulator_vddio(struct inv_mpu6050_state *st)
{
int result;

result = regulator_enable(st->vddio_supply);
if (result) {
dev_err(regmap_get_device(st->map),
- "Failed to enable regulator: %d\n", result);
+ "Failed to enable vddio regulator: %d\n", result);
} else {
/* Give the device a little bit of time to start up. */
usleep_range(35000, 70000);
@@ -1156,21 +1156,29 @@ static int inv_mpu_core_enable_regulator(struct inv_mpu6050_state *st)
return result;
}

-static int inv_mpu_core_disable_regulator(struct inv_mpu6050_state *st)
+static int inv_mpu_core_disable_regulator_vddio(struct inv_mpu6050_state *st)
{
int result;

result = regulator_disable(st->vddio_supply);
if (result)
dev_err(regmap_get_device(st->map),
- "Failed to disable regulator: %d\n", result);
+ "Failed to disable vddio regulator: %d\n", result);

return result;
}

static void inv_mpu_core_disable_regulator_action(void *_data)
{
- inv_mpu_core_disable_regulator(_data);
+ struct inv_mpu6050_state *st = _data;
+ int result;
+
+ result = regulator_disable(st->vdd_supply);
+ if (result)
+ dev_err(regmap_get_device(st->map),
+ "Failed to disable vdd regulator: %d\n", result);
+
+ inv_mpu_core_disable_regulator_vddio(st);
}

int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
@@ -1239,6 +1247,15 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
return -EINVAL;
}

+ st->vdd_supply = devm_regulator_get(dev, "vdd");
+ if (IS_ERR(st->vdd_supply)) {
+ if (PTR_ERR(st->vdd_supply) != -EPROBE_DEFER)
+ dev_err(dev, "Failed to get vdd regulator %d\n",
+ (int)PTR_ERR(st->vdd_supply));
+
+ return PTR_ERR(st->vdd_supply);
+ }
+
st->vddio_supply = devm_regulator_get(dev, "vddio");
if (IS_ERR(st->vddio_supply)) {
if (PTR_ERR(st->vddio_supply) != -EPROBE_DEFER)
@@ -1248,9 +1265,17 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
return PTR_ERR(st->vddio_supply);
}

- result = inv_mpu_core_enable_regulator(st);
- if (result)
+ result = regulator_enable(st->vdd_supply);
+ if (result) {
+ dev_err(dev, "Failed to enable vdd regulator: %d\n", result);
return result;
+ }
+
+ result = inv_mpu_core_enable_regulator_vddio(st);
+ if (result) {
+ regulator_disable(st->vdd_supply);
+ return result;
+ }

result = devm_add_action_or_reset(dev, inv_mpu_core_disable_regulator_action,
st);
@@ -1352,7 +1377,7 @@ static int inv_mpu_resume(struct device *dev)
int result;

mutex_lock(&st->lock);
- result = inv_mpu_core_enable_regulator(st);
+ result = inv_mpu_core_enable_regulator_vddio(st);
if (result)
goto out_unlock;

@@ -1370,7 +1395,7 @@ static int inv_mpu_suspend(struct device *dev)

mutex_lock(&st->lock);
result = inv_mpu6050_set_power_itg(st, false);
- inv_mpu_core_disable_regulator(st);
+ inv_mpu_core_disable_regulator_vddio(st);
mutex_unlock(&st->lock);

return result;
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
index 52fcf45050a5..4fcf683b9c63 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
@@ -130,7 +130,8 @@ struct inv_mpu6050_hw {
* @chip_period: chip internal period estimation (~1kHz).
* @it_timestamp: timestamp from previous interrupt.
* @data_timestamp: timestamp for next data sample.
- * @vddio_supply voltage regulator for the chip.
+ * @vdd_supply: VDD voltage regulator for the chip.
+ * @vddio_supply I/O voltage regulator for the chip.
* @magn_disabled: magnetometer disabled for backward compatibility reason.
* @magn_raw_to_gauss: coefficient to convert mag raw value to Gauss.
* @magn_orient: magnetometer sensor chip orientation if available.
@@ -154,6 +155,7 @@ struct inv_mpu6050_state {
s64 chip_period;
s64 it_timestamp;
s64 data_timestamp;
+ struct regulator *vdd_supply;
struct regulator *vddio_supply;
bool magn_disabled;
s32 magn_raw_to_gauss[3];
--
2.23.0

2019-11-08 12:25:34

by Jean-Baptiste Maneyrol

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] dt-bindings: iio: imo: mpu6050: add vdd-supply

Reviewed-by: Jean-Baptiste Maneyrol <[email protected]>

Best regards,
JB

From: [email protected] <[email protected]> on behalf of Stephan Gerhold <[email protected]>

Sent: Thursday, November 7, 2019 19:43

To: Jonathan Cameron <[email protected]>

Cc: Hartmut Knaack <[email protected]>; Lars-Peter Clausen <[email protected]>; Peter Meerwald-Stadler <[email protected]>; Rob Herring <[email protected]>; Mark Rutland <[email protected]>; Linus Walleij <[email protected]>; Brian Masney <[email protected]>;
Jonathan Marek <[email protected]>; Jean-Baptiste Maneyrol <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>;
Stephan Gerhold <[email protected]>

Subject: [PATCH v2 1/2] dt-bindings: iio: imo: mpu6050: add vdd-supply

?


?CAUTION: This email originated from outside of the organization. Please make sure the sender is who they say they are and do not click links or open attachments unless you recognize the sender and know the content is safe.



inv_mpu6050 now supports an additional vdd-supply; document it.







Reviewed-by: Linus Walleij <[email protected]>



Signed-off-by: Stephan Gerhold <[email protected]>



---



Changes in v2:



? - Add Reviewed-by from Linus Walleij







v1:
https://urldefense.proofpoint.com/v2/url?u=https-3A__lore.kernel.org_linux-2Diio_20191106183536.123070-2D1-2Dstephan-40gerhold.net_&d=DwIDAg&c=WoJWtq5JV8YrKnzRxvD8NxmTP_1wxfE0prPmo0NeZwg&r=4jiDX_1brsSWfCjfA6Ovj1d4h9MF8q7Xk5aBwG28mVk&m=O82MQPnLTvlD0nxDzFW1KS3aZpWiI3qYUZwJUy_qqxc&s=ddvzqy0PywWDCnge7xbJIhpqN9NltbLrzi4EBVdeA_o&e=




---



?Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt | 1 +



?1 file changed, 1 insertion(+)







diff --git a/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt b/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt



index 268bf7568e19..c5ee8a20af9f 100644



--- a/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt



+++ b/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt



@@ -21,6 +21,7 @@ Required properties:



?? bindings.



?



?Optional properties:



+ - vdd-supply: regulator phandle for VDD supply



? - vddio-supply: regulator phandle for VDDIO supply



? - mount-matrix: an optional 3x3 mounting rotation matrix



? - i2c-gate node.? These devices also support an auxiliary i2c bus.? This is



--



2.23.0







2019-11-10 15:31:31

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] dt-bindings: iio: imo: mpu6050: add vdd-supply

On Thu, 7 Nov 2019 19:43:41 +0100
Stephan Gerhold <[email protected]> wrote:

> inv_mpu6050 now supports an additional vdd-supply; document it.
>
> Reviewed-by: Linus Walleij <[email protected]>
> Signed-off-by: Stephan Gerhold <[email protected]>
Applied with imo->imu in the patch title.

Thanks,

Jonathan

> ---
> Changes in v2:
> - Add Reviewed-by from Linus Walleij
>
> v1: https://lore.kernel.org/linux-iio/[email protected]/
> ---
> Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt b/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
> index 268bf7568e19..c5ee8a20af9f 100644
> --- a/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
> +++ b/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
> @@ -21,6 +21,7 @@ Required properties:
> bindings.
>
> Optional properties:
> + - vdd-supply: regulator phandle for VDD supply
> - vddio-supply: regulator phandle for VDDIO supply
> - mount-matrix: an optional 3x3 mounting rotation matrix
> - i2c-gate node. These devices also support an auxiliary i2c bus. This is

2019-11-10 15:34:59

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v2 2/2] iio: imu: mpu6050: Add support for vdd-supply regulator

On Thu, 7 Nov 2019 19:43:42 +0100
Stephan Gerhold <[email protected]> wrote:

> MPU6050 has two power supply pins: VDD and VLOGIC, but the
> mpu6050 driver only supports enabling one of them at the moment.
> In some cases, they may need to be enabled separately.
>
> Add an additional "vdd-supply" that stays enabled for as long as
> the driver is loaded. We cannot turn off the VDD regulator during
> suspend as this would cause register settings (FSR, sampling rate, ...)
> to be lost.
>
> Signed-off-by: Stephan Gerhold <[email protected]>

Looks good to me.

Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to poke it.

Thanks

Jonathan

> ---
> Changes in v2:
> - Keep "vdd-supply" enabled during suspend to prevent register
> settings from getting lost.
> - Revert convertion to bulk regulator API (does not work well
> when regulators need to be enabled/disabled separately)
>
> v1: https://lore.kernel.org/linux-iio/[email protected]/
> ---
> drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 43 +++++++++++++++++-----
> drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h | 4 +-
> 2 files changed, 37 insertions(+), 10 deletions(-)
>
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> index 354030e9bed5..661a829478f5 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -1140,14 +1140,14 @@ static int inv_check_and_setup_chip(struct inv_mpu6050_state *st)
> return result;
> }
>
> -static int inv_mpu_core_enable_regulator(struct inv_mpu6050_state *st)
> +static int inv_mpu_core_enable_regulator_vddio(struct inv_mpu6050_state *st)
> {
> int result;
>
> result = regulator_enable(st->vddio_supply);
> if (result) {
> dev_err(regmap_get_device(st->map),
> - "Failed to enable regulator: %d\n", result);
> + "Failed to enable vddio regulator: %d\n", result);
> } else {
> /* Give the device a little bit of time to start up. */
> usleep_range(35000, 70000);
> @@ -1156,21 +1156,29 @@ static int inv_mpu_core_enable_regulator(struct inv_mpu6050_state *st)
> return result;
> }
>
> -static int inv_mpu_core_disable_regulator(struct inv_mpu6050_state *st)
> +static int inv_mpu_core_disable_regulator_vddio(struct inv_mpu6050_state *st)
> {
> int result;
>
> result = regulator_disable(st->vddio_supply);
> if (result)
> dev_err(regmap_get_device(st->map),
> - "Failed to disable regulator: %d\n", result);
> + "Failed to disable vddio regulator: %d\n", result);
>
> return result;
> }
>
> static void inv_mpu_core_disable_regulator_action(void *_data)
> {
> - inv_mpu_core_disable_regulator(_data);
> + struct inv_mpu6050_state *st = _data;
> + int result;
> +
> + result = regulator_disable(st->vdd_supply);
> + if (result)
> + dev_err(regmap_get_device(st->map),
> + "Failed to disable vdd regulator: %d\n", result);
> +
> + inv_mpu_core_disable_regulator_vddio(st);
> }
>
> int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
> @@ -1239,6 +1247,15 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
> return -EINVAL;
> }
>
> + st->vdd_supply = devm_regulator_get(dev, "vdd");
> + if (IS_ERR(st->vdd_supply)) {
> + if (PTR_ERR(st->vdd_supply) != -EPROBE_DEFER)
> + dev_err(dev, "Failed to get vdd regulator %d\n",
> + (int)PTR_ERR(st->vdd_supply));
> +
> + return PTR_ERR(st->vdd_supply);
> + }
> +
> st->vddio_supply = devm_regulator_get(dev, "vddio");
> if (IS_ERR(st->vddio_supply)) {
> if (PTR_ERR(st->vddio_supply) != -EPROBE_DEFER)
> @@ -1248,9 +1265,17 @@ int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
> return PTR_ERR(st->vddio_supply);
> }
>
> - result = inv_mpu_core_enable_regulator(st);
> - if (result)
> + result = regulator_enable(st->vdd_supply);
> + if (result) {
> + dev_err(dev, "Failed to enable vdd regulator: %d\n", result);
> return result;
> + }
> +
> + result = inv_mpu_core_enable_regulator_vddio(st);
> + if (result) {
> + regulator_disable(st->vdd_supply);
> + return result;
> + }
>
> result = devm_add_action_or_reset(dev, inv_mpu_core_disable_regulator_action,
> st);
> @@ -1352,7 +1377,7 @@ static int inv_mpu_resume(struct device *dev)
> int result;
>
> mutex_lock(&st->lock);
> - result = inv_mpu_core_enable_regulator(st);
> + result = inv_mpu_core_enable_regulator_vddio(st);
> if (result)
> goto out_unlock;
>
> @@ -1370,7 +1395,7 @@ static int inv_mpu_suspend(struct device *dev)
>
> mutex_lock(&st->lock);
> result = inv_mpu6050_set_power_itg(st, false);
> - inv_mpu_core_disable_regulator(st);
> + inv_mpu_core_disable_regulator_vddio(st);
> mutex_unlock(&st->lock);
>
> return result;
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> index 52fcf45050a5..4fcf683b9c63 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_iio.h
> @@ -130,7 +130,8 @@ struct inv_mpu6050_hw {
> * @chip_period: chip internal period estimation (~1kHz).
> * @it_timestamp: timestamp from previous interrupt.
> * @data_timestamp: timestamp for next data sample.
> - * @vddio_supply voltage regulator for the chip.
> + * @vdd_supply: VDD voltage regulator for the chip.
> + * @vddio_supply I/O voltage regulator for the chip.
> * @magn_disabled: magnetometer disabled for backward compatibility reason.
> * @magn_raw_to_gauss: coefficient to convert mag raw value to Gauss.
> * @magn_orient: magnetometer sensor chip orientation if available.
> @@ -154,6 +155,7 @@ struct inv_mpu6050_state {
> s64 chip_period;
> s64 it_timestamp;
> s64 data_timestamp;
> + struct regulator *vdd_supply;
> struct regulator *vddio_supply;
> bool magn_disabled;
> s32 magn_raw_to_gauss[3];

2019-11-10 16:07:59

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v2 1/2] dt-bindings: iio: imo: mpu6050: add vdd-supply

On Fri, 8 Nov 2019 12:11:46 +0000
Jean-Baptiste Maneyrol <[email protected]> wrote:

> Reviewed-by: Jean-Baptiste Maneyrol <[email protected]>
Hi Jean-Baptiste,

I'm assuming that applies for both patches given you gave comments on
v1 that applied to patch 2!

Thanks,

Jonathan

>
> Best regards,
> JB
>
> From: [email protected] <[email protected]> on behalf of Stephan Gerhold <[email protected]>
>
> Sent: Thursday, November 7, 2019 19:43
>
> To: Jonathan Cameron <[email protected]>
>
> Cc: Hartmut Knaack <[email protected]>; Lars-Peter Clausen <[email protected]>; Peter Meerwald-Stadler <[email protected]>; Rob Herring <[email protected]>; Mark Rutland <[email protected]>; Linus Walleij <[email protected]>; Brian Masney <[email protected]>;
> Jonathan Marek <[email protected]>; Jean-Baptiste Maneyrol <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>; [email protected] <[email protected]>;
> Stephan Gerhold <[email protected]>
>
> Subject: [PATCH v2 1/2] dt-bindings: iio: imo: mpu6050: add vdd-supply
>
>  
>
>
>  CAUTION: This email originated from outside of the organization. Please make sure the sender is who they say they are and do not click links or open attachments unless you recognize the sender and know the content is safe.
>
>
>
> inv_mpu6050 now supports an additional vdd-supply; document it.
>
>
>
>
>
>
>
> Reviewed-by: Linus Walleij <[email protected]>
>
>
>
> Signed-off-by: Stephan Gerhold <[email protected]>
>
>
>
> ---
>
>
>
> Changes in v2:
>
>
>
>   - Add Reviewed-by from Linus Walleij
>
>
>
>
>
>
>
> v1:
> https://urldefense.proofpoint.com/v2/url?u=https-3A__lore.kernel.org_linux-2Diio_20191106183536.123070-2D1-2Dstephan-40gerhold.net_&d=DwIDAg&c=WoJWtq5JV8YrKnzRxvD8NxmTP_1wxfE0prPmo0NeZwg&r=4jiDX_1brsSWfCjfA6Ovj1d4h9MF8q7Xk5aBwG28mVk&m=O82MQPnLTvlD0nxDzFW1KS3aZpWiI3qYUZwJUy_qqxc&s=ddvzqy0PywWDCnge7xbJIhpqN9NltbLrzi4EBVdeA_o&e=
>
>
>
>
> ---
>
>
>
>  Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt | 1 +
>
>
>
>  1 file changed, 1 insertion(+)
>
>
>
>
>
>
>
> diff --git a/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt b/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
>
>
>
> index 268bf7568e19..c5ee8a20af9f 100644
>
>
>
> --- a/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
>
>
>
> +++ b/Documentation/devicetree/bindings/iio/imu/inv_mpu6050.txt
>
>
>
> @@ -21,6 +21,7 @@ Required properties:
>
>
>
>    bindings.
>
>
>
>  
>
>
>
>  Optional properties:
>
>
>
> + - vdd-supply: regulator phandle for VDD supply
>
>
>
>   - vddio-supply: regulator phandle for VDDIO supply
>
>
>
>   - mount-matrix: an optional 3x3 mounting rotation matrix
>
>
>
>   - i2c-gate node.  These devices also support an auxiliary i2c bus.  This is
>
>
>