From: Daniel Baluta Date: Wed, 3 Dec 2014 13:31:51 +0000 (+0200) Subject: iio: imu: kmx61: Add PM sleep support X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=3b9c40e604ee61e69a8aff6e1a426a6250ff4361;p=linux-beck.git iio: imu: kmx61: Add PM sleep support Per sensor state (ACTIVE/STANDBY) is saved in driver's private data (acc_stby/mag_stby) and restored when resume is called. Signed-off-by: Daniel Baluta Signed-off-by: Jonathan Cameron --- diff --git a/drivers/iio/imu/kmx61.c b/drivers/iio/imu/kmx61.c index f3007dd664fc..98d58e1b6c6b 100644 --- a/drivers/iio/imu/kmx61.c +++ b/drivers/iio/imu/kmx61.c @@ -16,6 +16,7 @@ #include #include #include +#include #include #include #include @@ -796,6 +797,33 @@ static int kmx61_remove(struct i2c_client *client) return 0; } +#ifdef CONFIG_PM_SLEEP +static int kmx61_suspend(struct device *dev) +{ + int ret; + struct kmx61_data *data = i2c_get_clientdata(to_i2c_client(dev)); + + mutex_lock(&data->lock); + ret = kmx61_set_mode(data, KMX61_ALL_STBY, KMX61_ACC | KMX61_MAG, + false); + mutex_unlock(&data->lock); + + return ret; +} + +static int kmx61_resume(struct device *dev) +{ + u8 stby = 0; + struct kmx61_data *data = i2c_get_clientdata(to_i2c_client(dev)); + + if (data->acc_stby) + stby |= KMX61_ACC_STBY_BIT; + if (data->mag_stby) + stby |= KMX61_MAG_STBY_BIT; + + return kmx61_set_mode(data, stby, KMX61_ACC | KMX61_MAG, true); +} +#endif #ifdef CONFIG_PM_RUNTIME static int kmx61_runtime_suspend(struct device *dev) @@ -825,6 +853,7 @@ static int kmx61_runtime_resume(struct device *dev) #endif static const struct dev_pm_ops kmx61_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(kmx61_suspend, kmx61_resume) SET_RUNTIME_PM_OPS(kmx61_runtime_suspend, kmx61_runtime_resume, NULL) };