iio: gyro: itg3200: add suspend/resume support.
PATCH v2 1/1 iio: gyro: itg3200: add suspend/resume support.
Unless we put the device to sleep when not it use, it wastes 6mA.
If the device is asleep on probe, the 'id' register sometimes mis-reads - so reset first. If the device responds at all a command sent to the address, it is almost certainly the correct device already.
---
v1 of this was sent in November. I got some useful feedback, but then got distracted by something. Sorry for the long gap.
NeilBrown
drivers/iio/gyro/itg3200_core.c +25 -4
@@ -223,6 +223,10 @@ static int itg3200_initial_setup(struct iio_dev *indio_dev)int ret;u8 val; + ret =itg3200_reset (indio_dev); +if (ret) + goto err_ret; + ret =itg3200_read_reg_8 (indio_dev,ITG3200_REG_ADDRESS , &val);if (ret) goto err_ret;
@@ -233,10 +237,6 @@ static int itg3200_initial_setup(struct iio_dev *indio_dev) goto err_ret; } - ret =itg3200_reset (indio_dev); -if (ret) - goto err_ret; - ret =itg3200_enable_full_scale (indio_dev); err_ret:return ret;
@@ -351,6 +351,26 @@ static int itg3200_remove(struct i2c_client *client)return 0 ; } +static int __maybe_unused itg3200_suspend (struct device *dev) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct itg3200 *st =iio_priv (indio_dev); + +dev_dbg (&st->i2c->dev,"suspend device" ); + +return itg3200_write_reg_8 (indio_dev,ITG3200_REG_POWER_MANAGEMENT , +ITG3200_SLEEP ); +} + +static int __maybe_unused itg3200_resume (struct device *dev) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); + +return itg3200_initial_setup (indio_dev); +} + +static SIMPLE_DEV_PM_OPS(itg3200_pm_ops, itg3200_suspend, itg3200_resume); +static const struct i2c_device_id itg3200_id[] = { {"itg3200" ,0 }, { }
@@ -361,6 +381,7 @@ static struct i2c_driver itg3200_driver = { .driver = { .owner = THIS_MODULE, .name = "itg3200", + .pm = &itg3200_pm_ops, }, .id_table = itg3200_id, .probe = itg3200_probe,
Quoted 4 lines · NeilBrown
Unless we put the device to sleep when not it use, it wastes 6mA.
Quoted 8 lines
If the device is asleep on probe, the 'id' register sometimes mis-reads - so reset first. If the device responds at all a command sent to the address, it is almost certainly the correct device already.
Acked-by Manuel Stahl <[email protected]>Acked-by Hartmut Knaack <[email protected]>Signed-off-by NeilBrown <[email protected]>
Applied to the togreg branch of iio.git. Initially pushed out as testing for the autobuilders to play with it.
Thanks,
Jonathan
Quoted 5 lines
---
v1 of this was sent in November. I got some useful feedback, but then got distracted by something. Sorry for the long gap.
NeilBrown
Not to worry, I've got lots of stuff in that category ;(
Quoted 64 lines
drivers/iio/gyro/itg3200_core.c +25
-4@@ -223,6 +223,10 @@ static int itg3200_initial_setup(struct iio_dev *indio_dev)int ret;u8 val; + ret =itg3200_reset (indio_dev); +if (ret) + goto err_ret; + ret =itg3200_read_reg_8 (indio_dev,ITG3200_REG_ADDRESS , &val);if (ret) goto err_ret;@@ -233,10 +237,6 @@ static int itg3200_initial_setup(struct iio_dev *indio_dev) goto err_ret; } - ret =itg3200_reset (indio_dev); -if (ret) - goto err_ret; - ret =itg3200_enable_full_scale (indio_dev); err_ret:return ret;@@ -351,6 +351,26 @@ static int itg3200_remove(struct i2c_client *client)return 0 ; } +static int __maybe_unused itg3200_suspend (struct device *dev) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct itg3200 *st =iio_priv (indio_dev); + +dev_dbg (&st->i2c->dev,"suspend device" ); + +return itg3200_write_reg_8 (indio_dev,ITG3200_REG_POWER_MANAGEMENT , +ITG3200_SLEEP ); +} + +static int __maybe_unused itg3200_resume (struct device *dev) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); + +return itg3200_initial_setup (indio_dev); +} + +static SIMPLE_DEV_PM_OPS(itg3200_pm_ops, itg3200_suspend, itg3200_resume); +static const struct i2c_device_id itg3200_id[] = { {"itg3200" ,0 }, { }@@ -361,6 +381,7 @@ static struct i2c_driver itg3200_driver = { .driver = { .owner = THIS_MODULE, .name = "itg3200", + .pm = &itg3200_pm_ops, }, .id_table = itg3200_id, .probe = itg3200_probe,
NeilBrown schrieb am 24.02.2015 um 03:24:
Quoted 11 lines
Unless we put the device to sleep when not it use, it wastes 6mA.
If the device is asleep on probe, the 'id' register sometimes mis-reads - so reset first. If the device responds at all a command sent to the address, it is almost certainly the correct device already.
Acked-by Manuel Stahl <[email protected]>Acked-by Hartmut Knaack <[email protected]>
I don't recall acking on this. Anyway, no objection on the patch content.
Hartmut
Quoted 70 lines
Signed-off-by NeilBrown <[email protected]>---
v1 of this was sent in November. I got some useful feedback, but then got distracted by something. Sorry for the long gap.
NeilBrowndrivers/iio/gyro/itg3200_core.c +25
-4@@ -223,6 +223,10 @@ static int itg3200_initial_setup(struct iio_dev *indio_dev)int ret;u8 val; + ret =itg3200_reset (indio_dev); +if (ret) + goto err_ret; + ret =itg3200_read_reg_8 (indio_dev,ITG3200_REG_ADDRESS , &val);if (ret) goto err_ret;@@ -233,10 +237,6 @@ static int itg3200_initial_setup(struct iio_dev *indio_dev) goto err_ret; } - ret =itg3200_reset (indio_dev); -if (ret) - goto err_ret; - ret =itg3200_enable_full_scale (indio_dev); err_ret:return ret;@@ -351,6 +351,26 @@ static int itg3200_remove(struct i2c_client *client)return 0 ; } +static int __maybe_unused itg3200_suspend (struct device *dev) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); +struct itg3200 *st =iio_priv (indio_dev); + +dev_dbg (&st->i2c->dev,"suspend device" ); + +return itg3200_write_reg_8 (indio_dev,ITG3200_REG_POWER_MANAGEMENT , +ITG3200_SLEEP ); +} + +static int __maybe_unused itg3200_resume (struct device *dev) +{ +struct iio_dev *indio_dev =dev_get_drvdata (dev); + +return itg3200_initial_setup (indio_dev); +} + +static SIMPLE_DEV_PM_OPS(itg3200_pm_ops, itg3200_suspend, itg3200_resume); +static const struct i2c_device_id itg3200_id[] = { {"itg3200" ,0 }, { }@@ -361,6 +381,7 @@ static struct i2c_driver itg3200_driver = { .driver = { .owner = THIS_MODULE, .name = "itg3200", + .pm = &itg3200_pm_ops, }, .id_table = itg3200_id, .probe = itg3200_probe,