* [PATCH 1/2] iio: imu: inv_mpu6050: clean set_power_itg and fix usage
@ 2018-03-30 14:25 Jean-Baptiste Maneyrol
2018-04-04 15:07 ` [PATCH v2 " Jean-Baptiste Maneyrol
0 siblings, 1 reply; 3+ messages in thread
From: Jean-Baptiste Maneyrol @ 2018-03-30 14:25 UTC (permalink / raw)
To: linux-iio
Rewrite set_power_itg. Failing when turning power off is
no more decreasing the counter now and sleeping only happens
when effectively turning the chip on. Fix also usage in init
function (setting power on one time is sufficient to ensure
chip is effectively on).
Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
---
drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 44 ++++++++++++++++----------=
----
1 file changed, 24 insertions(+), 20 deletions(-)
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/i=
nv_mpu6050/inv_mpu_core.c
index 7d64be3..f17fbfa 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -185,26 +185,29 @@ int inv_mpu6050_switch_engine(struct inv_mpu6050_stat=
e *st, bool en, u32 mask)
=20
int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_on)
{
- int result =3D 0;
+ int result;
=20
if (power_on) {
- if (!st->powerup_count)
+ if (!st->powerup_count) {
result =3D regmap_write(st->map, st->reg->pwr_mgmt_1, 0);
- if (!result)
- st->powerup_count++;
+ if (result)
+ return result;
+ usleep_range(INV_MPU6050_REG_UP_TIME_MIN,
+ INV_MPU6050_REG_UP_TIME_MAX);
+ }
+ st->powerup_count++;
} else {
- st->powerup_count--;
- if (!st->powerup_count)
+ if (st->powerup_count =3D=3D 1) {
result =3D regmap_write(st->map, st->reg->pwr_mgmt_1,
INV_MPU6050_BIT_SLEEP);
+ if (result)
+ return result;
+ }
+ st->powerup_count--;
}
=20
- if (result)
- return result;
-
- if (power_on)
- usleep_range(INV_MPU6050_REG_UP_TIME_MIN,
- INV_MPU6050_REG_UP_TIME_MAX);
+ dev_dbg(regmap_get_device(st->map), "set power %d, count=3D%u\n",
+ power_on, st->powerup_count);
=20
return 0;
}
@@ -850,14 +853,11 @@ static int inv_check_and_setup_chip(struct inv_mpu605=
0_state *st)
msleep(INV_MPU6050_POWER_UP_TIME);
=20
/*
- * toggle power state. After reset, the sleep bit could be on
- * or off depending on the OTP settings. Toggling power would
+ * Turn power on. After reset, the sleep bit could be on
+ * or off depending on the OTP settings. Turning power on
* make it in a definite state as well as making the hardware
* state align with the software state
*/
- result =3D inv_mpu6050_set_power_itg(st, false);
- if (result)
- return result;
result =3D inv_mpu6050_set_power_itg(st, true);
if (result)
return result;
@@ -865,13 +865,17 @@ static int inv_check_and_setup_chip(struct inv_mpu605=
0_state *st)
result =3D inv_mpu6050_switch_engine(st, false,
INV_MPU6050_BIT_PWR_ACCL_STBY);
if (result)
- return result;
+ goto error_power_off;
result =3D inv_mpu6050_switch_engine(st, false,
INV_MPU6050_BIT_PWR_GYRO_STBY);
if (result)
- return result;
+ goto error_power_off;
=20
- return 0;
+ return inv_mpu6050_set_power_itg(st, false);
+
+error_power_off:
+ inv_mpu6050_set_power_itg(st, false);
+ return result;
}
=20
int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
--=20
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread* [PATCH v2 1/2] iio: imu: inv_mpu6050: clean set_power_itg and fix usage
2018-03-30 14:25 [PATCH 1/2] iio: imu: inv_mpu6050: clean set_power_itg and fix usage Jean-Baptiste Maneyrol
@ 2018-04-04 15:07 ` Jean-Baptiste Maneyrol
2018-04-08 16:02 ` Jonathan Cameron
0 siblings, 1 reply; 3+ messages in thread
From: Jean-Baptiste Maneyrol @ 2018-04-04 15:07 UTC (permalink / raw)
To: linux-iio, Jonathan Cameron
Rewrite set_power_itg. Failing when turning power off is
no more decreasing the counter now and sleeping only happens
when effectively turning the chip on. Fix also usage in init
function (setting power on one time is sufficient to ensure
chip is effectively on).
Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
---
=A0drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 44 ++++++++++++++++--------=
------
=A01 file changed, 24 insertions(+), 20 deletions(-)
diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/i=
nv_mpu6050/inv_mpu_core.c
index 7d64be3..f17fbfa 100644
--- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
+++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
@@ -185,26 +185,29 @@ int inv_mpu6050_switch_engine(struct inv_mpu6050_stat=
e *st, bool en, u32 mask)
=A0int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_o=
n)
=A0{
-=A0=A0=A0=A0=A0=A0 int result =3D 0;
+=A0=A0=A0=A0=A0=A0 int result;
=A0=A0=A0=A0=A0=A0=A0 if (power_on) {
-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if (!st->powerup_count)
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if (!st->powerup_count) {
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 resul=
t =3D regmap_write(st->map, st->reg->pwr_mgmt_1, 0);
-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if (!result)
-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 st->pow=
erup_count++;
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if (res=
ult)
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0 return result;
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 usleep_=
range(INV_MPU6050_REG_UP_TIME_MIN,
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 INV_MPU6050_REG_UP_TIME_MAX);
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 }
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 st->powerup_count++;
=A0=A0=A0=A0=A0=A0=A0 } else {
-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 st->powerup_count--;
-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if (!st->powerup_count)
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if (st->powerup_count =3D=3D 1)=
{
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 resul=
t =3D regmap_write(st->map, st->reg->pwr_mgmt_1,
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 INV_MPU6050_BI=
T_SLEEP);
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 if (res=
ult)
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0 return result;
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 }
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 st->powerup_count--;
=A0=A0=A0=A0=A0=A0=A0 }
-=A0=A0=A0=A0=A0=A0 if (result)
-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return result;
-
-=A0=A0=A0=A0=A0=A0 if (power_on)
-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 usleep_range(INV_MPU6050_REG_UP=
_TIME_MIN,
-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0 INV_MPU6050_REG_UP_TIME_MAX);
+=A0=A0=A0=A0=A0=A0 dev_dbg(regmap_get_device(st->map), "set power %d, coun=
t=3D%u\n",
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 power_on, st->powerup_count);
=A0=A0=A0=A0=A0=A0=A0 return 0;
=A0}
@@ -850,14 +853,11 @@ static int inv_check_and_setup_chip(struct inv_mpu605=
0_state *st)
=A0=A0=A0=A0=A0=A0=A0 msleep(INV_MPU6050_POWER_UP_TIME);
=A0=A0=A0=A0=A0=A0=A0 /*
-=A0=A0=A0=A0=A0=A0=A0 * toggle power state. After reset, the sleep bit cou=
ld be on
-=A0=A0=A0=A0=A0=A0=A0 * or off depending on the OTP settings. Toggling pow=
er would
+=A0=A0=A0=A0=A0=A0=A0 * Turn power on. After reset, the sleep bit could be=
on
+=A0=A0=A0=A0=A0=A0=A0 * or off depending on the OTP settings. Turning powe=
r on
=A0=A0=A0=A0=A0=A0=A0=A0 * make it in a definite state as well as making th=
e hardware
=A0=A0=A0=A0=A0=A0=A0=A0 * state align with the software state
=A0=A0=A0=A0=A0=A0=A0=A0 */
-=A0=A0=A0=A0=A0=A0 result =3D inv_mpu6050_set_power_itg(st, false);
-=A0=A0=A0=A0=A0=A0 if (result)
-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return result;
=A0=A0=A0=A0=A0=A0=A0 result =3D inv_mpu6050_set_power_itg(st, true);
=A0=A0=A0=A0=A0=A0=A0 if (result)
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return result;
@@ -865,13 +865,17 @@ static int inv_check_and_setup_chip(struct inv_mpu605=
0_state *st)
=A0=A0=A0=A0=A0=A0=A0 result =3D inv_mpu6050_switch_engine(st, false,
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 INV_MPU6050_BIT_PWR_ACC=
L_STBY);
=A0=A0=A0=A0=A0=A0=A0 if (result)
-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return result;
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 goto error_power_off;
=A0=A0=A0=A0=A0=A0=A0 result =3D inv_mpu6050_switch_engine(st, false,
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=
=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 INV_MPU6050_BIT_PWR_GYR=
O_STBY);
=A0=A0=A0=A0=A0=A0=A0 if (result)
-=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 return result;
+=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0=A0 goto error_power_off;
-=A0=A0=A0=A0=A0=A0 return 0;
+=A0=A0=A0=A0=A0=A0 return inv_mpu6050_set_power_itg(st, false);
+
+error_power_off:
+=A0=A0=A0=A0=A0=A0 inv_mpu6050_set_power_itg(st, false);
+=A0=A0=A0=A0=A0=A0 return result;
=A0}
=A0int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
--
2.7.4
^ permalink raw reply related [flat|nested] 3+ messages in thread* Re: [PATCH v2 1/2] iio: imu: inv_mpu6050: clean set_power_itg and fix usage
2018-04-04 15:07 ` [PATCH v2 " Jean-Baptiste Maneyrol
@ 2018-04-08 16:02 ` Jonathan Cameron
0 siblings, 0 replies; 3+ messages in thread
From: Jonathan Cameron @ 2018-04-08 16:02 UTC (permalink / raw)
To: Jean-Baptiste Maneyrol; +Cc: linux-iio
On Wed, 4 Apr 2018 15:07:22 +0000
Jean-Baptiste Maneyrol <JManeyrol@invensense.com> wrote:
> Rewrite set_power_itg. Failing when turning power off is
> no more decreasing the counter now and sleeping only happens
> when effectively turning the chip on. Fix also usage in init
> function (setting power on one time is sufficient to ensure
> chip is effectively on).
>
> Signed-off-by: Jean-Baptiste Maneyrol <jmaneyrol@invensense.com>
Hi Jean-Baptiste,
I'm having trouble with your patches for some reason. Looks
like something in your email system is replacing tabs with spaces
and generally messing things up.
It doesn't seem to be universal as the ones you sent a day after
this appear to be fine.
Could you take a look and see if you can figure out what is wrong.
Thanks,
Jonathan
> ---
> drivers/iio/imu/inv_mpu6050/inv_mpu_core.c | 44 ++++++++++++++++--------------
> 1 file changed, 24 insertions(+), 20 deletions(-)
>
> diff --git a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> index 7d64be3..f17fbfa 100644
> --- a/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> +++ b/drivers/iio/imu/inv_mpu6050/inv_mpu_core.c
> @@ -185,26 +185,29 @@ int inv_mpu6050_switch_engine(struct inv_mpu6050_state *st, bool en, u32 mask)
>
> int inv_mpu6050_set_power_itg(struct inv_mpu6050_state *st, bool power_on)
> {
> - int result = 0;
> + int result;
>
> if (power_on) {
> - if (!st->powerup_count)
> + if (!st->powerup_count) {
> result = regmap_write(st->map, st->reg->pwr_mgmt_1, 0);
> - if (!result)
> - st->powerup_count++;
> + if (result)
> + return result;
> + usleep_range(INV_MPU6050_REG_UP_TIME_MIN,
> + INV_MPU6050_REG_UP_TIME_MAX);
> + }
> + st->powerup_count++;
> } else {
> - st->powerup_count--;
> - if (!st->powerup_count)
> + if (st->powerup_count == 1) {
> result = regmap_write(st->map, st->reg->pwr_mgmt_1,
> INV_MPU6050_BIT_SLEEP);
> + if (result)
> + return result;
> + }
> + st->powerup_count--;
> }
>
> - if (result)
> - return result;
> -
> - if (power_on)
> - usleep_range(INV_MPU6050_REG_UP_TIME_MIN,
> - INV_MPU6050_REG_UP_TIME_MAX);
> + dev_dbg(regmap_get_device(st->map), "set power %d, count=%u\n",
> + power_on, st->powerup_count);
>
> return 0;
> }
> @@ -850,14 +853,11 @@ static int inv_check_and_setup_chip(struct inv_mpu6050_state *st)
> msleep(INV_MPU6050_POWER_UP_TIME);
>
> /*
> - * toggle power state. After reset, the sleep bit could be on
> - * or off depending on the OTP settings. Toggling power would
> + * Turn power on. After reset, the sleep bit could be on
> + * or off depending on the OTP settings. Turning power on
> * make it in a definite state as well as making the hardware
> * state align with the software state
> */
> - result = inv_mpu6050_set_power_itg(st, false);
> - if (result)
> - return result;
> result = inv_mpu6050_set_power_itg(st, true);
> if (result)
> return result;
> @@ -865,13 +865,17 @@ static int inv_check_and_setup_chip(struct inv_mpu6050_state *st)
> result = inv_mpu6050_switch_engine(st, false,
> INV_MPU6050_BIT_PWR_ACCL_STBY);
> if (result)
> - return result;
> + goto error_power_off;
> result = inv_mpu6050_switch_engine(st, false,
> INV_MPU6050_BIT_PWR_GYRO_STBY);
> if (result)
> - return result;
> + goto error_power_off;
>
> - return 0;
> + return inv_mpu6050_set_power_itg(st, false);
> +
> +error_power_off:
> + inv_mpu6050_set_power_itg(st, false);
> + return result;
> }
>
> int inv_mpu_core_probe(struct regmap *regmap, int irq, const char *name,
> --
> 2.7.4
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2018-04-08 16:02 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-03-30 14:25 [PATCH 1/2] iio: imu: inv_mpu6050: clean set_power_itg and fix usage Jean-Baptiste Maneyrol
2018-04-04 15:07 ` [PATCH v2 " Jean-Baptiste Maneyrol
2018-04-08 16:02 ` Jonathan Cameron
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox