From: Bin Yang Date: Wed, 19 Oct 2016 07:03:24 +0000 (+0800) Subject: input: sensors: reinit sensors register when system resume X-Git-Tag: firefly_0821_release~1377 X-Git-Url: http://demsky.eecs.uci.edu/git/?a=commitdiff_plain;h=bcd98f38f48f0832f97a37a0e51833b8199300e2;p=firefly-linux-kernel-4.4.55.git input: sensors: reinit sensors register when system resume For some sensors are designed to support poweroff when system suspend, so we need reinit register when system resume. Change-Id: I4d61dc318562336781aa1010d1fbad447cc76b83 Signed-off-by: Bin Yang --- diff --git a/drivers/input/sensors/sensor-dev.c b/drivers/input/sensors/sensor-dev.c index cd18a44f397a..01bbf40ce2b8 100755 --- a/drivers/input/sensors/sensor-dev.c +++ b/drivers/input/sensors/sensor-dev.c @@ -394,7 +394,39 @@ static void sensor_resume(struct early_suspend *h) sensor->ops->resume(sensor->client); } #endif - + +#ifdef CONFIG_PM +static int sensor_of_suspend(struct device *dev) +{ + struct sensor_private_data *sensor = dev_get_drvdata(dev); + + if (sensor->ops->suspend) + sensor->ops->suspend(sensor->client); + + return 0; +} + +static int sensor_of_resume(struct device *dev) +{ + struct sensor_private_data *sensor = dev_get_drvdata(dev); + + if (sensor->ops->resume) + sensor->ops->resume(sensor->client); + if (sensor->pdata->power_off_in_suspend) + sensor_initial(sensor->client); + + return 0; +} + +static const struct dev_pm_ops sensor_pm_ops = { + SET_SYSTEM_SLEEP_PM_OPS(sensor_of_suspend, sensor_of_resume) +}; + +#define SENSOR_PM_OPS (&sensor_pm_ops) +#else +#define SENSOR_PM_OPS NULL +#endif + static int angle_dev_open(struct inode *inode, struct file *file) { //struct sensor_private_data *sensor = g_sensor[SENSOR_TYPE_ACCEL]; @@ -1806,7 +1838,9 @@ int sensor_probe(struct i2c_client *client, const struct i2c_device_id *devid) of_property_read_u8(np,"address",&(pdata->address)); of_get_property(np, "project_name", pdata->project_name); - + + of_property_read_u32(np, "power-off-in-suspend", + &pdata->power_off_in_suspend); switch(pdata->layout) { @@ -2304,10 +2338,11 @@ static struct i2c_driver sensor_driver = { .remove = sensor_remove, .shutdown = sensor_shut_down, .id_table = sensor_id, - .driver = { - .owner = THIS_MODULE, - .name = "sensors", - .of_match_table = of_match_ptr(sensor_dt_ids), + .driver = { + .owner = THIS_MODULE, + .name = "sensors", + .of_match_table = of_match_ptr(sensor_dt_ids), + .pm = SENSOR_PM_OPS, }, }; diff --git a/include/linux/sensor-dev.h b/include/linux/sensor-dev.h index d979edcc4b2a..b6a48b161cf3 100755 --- a/include/linux/sensor-dev.h +++ b/include/linux/sensor-dev.h @@ -202,6 +202,7 @@ struct sensor_platform_data { signed char orientation[9]; short m_layout[4][3][3]; int* project_name; + int power_off_in_suspend; }; struct gsensor_platform_data {