aboutsummaryrefslogtreecommitdiffstats
path: root/drivers
diff options
context:
space:
mode:
authorSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>2017-04-07 20:13:17 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2017-05-25 09:44:41 -0400
commit6bee0b1fe4eda64055cbf48a556fd77211f63078 (patch)
tree2a5cad514478797bac64e943f9486ec632b71958 /drivers
parenta99462b13dff9de2aa7941aaad8b4ed10edbb629 (diff)
iio: hid-sensor: Store restore poll and hysteresis on S3
commit 5d9854eaea776441b38a9a45b4e6879524c4f48c upstream. This change undo the change done by 'commit 3bec24747446 ("iio: hid-sensor-trigger: Change get poll value function order to avoid sensor properties losing after resume from S3")' as this breaks some USB/i2c sensor hubs. Instead of relying on HW for restoring poll and hysteresis, driver stores and restores on resume (S3). In this way user space modified settings are not lost for any kind of sensor hub behavior. In this change, whenever user space modifies sampling frequency or hysteresis driver will get the feature value from the hub and store in the per device hid_sensor_common data structure. On resume callback from S3, system will set the feature to sensor hub, if user space ever modified the feature value. Fixes: 3bec24747446 ("iio: hid-sensor-trigger: Change get poll value function order to avoid sensor properties losing after resume from S3") Reported-by: Ritesh Raj Sarraf <rrs@researchut.com> Tested-by: Ritesh Raj Sarraf <rrs@researchut.com> Tested-by: Song, Hongyan <hongyan.song@intel.com> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Signed-off-by: Jonathan Cameron <jic23@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers')
-rw-r--r--drivers/iio/common/hid-sensors/hid-sensor-attributes.c26
-rw-r--r--drivers/iio/common/hid-sensors/hid-sensor-trigger.c20
2 files changed, 41 insertions, 5 deletions
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index b5beea53d6f6..ab646a90e3da 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -217,7 +217,15 @@ int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
217 if (ret < 0 || value < 0) 217 if (ret < 0 || value < 0)
218 ret = -EINVAL; 218 ret = -EINVAL;
219 219
220 return ret; 220 ret = sensor_hub_get_feature(st->hsdev,
221 st->poll.report_id,
222 st->poll.index, sizeof(value), &value);
223 if (ret < 0 || value < 0)
224 return -EINVAL;
225
226 st->poll_interval = value;
227
228 return 0;
221} 229}
222EXPORT_SYMBOL(hid_sensor_write_samp_freq_value); 230EXPORT_SYMBOL(hid_sensor_write_samp_freq_value);
223 231
@@ -259,7 +267,16 @@ int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
259 if (ret < 0 || value < 0) 267 if (ret < 0 || value < 0)
260 ret = -EINVAL; 268 ret = -EINVAL;
261 269
262 return ret; 270 ret = sensor_hub_get_feature(st->hsdev,
271 st->sensitivity.report_id,
272 st->sensitivity.index, sizeof(value),
273 &value);
274 if (ret < 0 || value < 0)
275 return -EINVAL;
276
277 st->raw_hystersis = value;
278
279 return 0;
263} 280}
264EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value); 281EXPORT_SYMBOL(hid_sensor_write_raw_hyst_value);
265 282
@@ -355,6 +372,9 @@ int hid_sensor_get_reporting_interval(struct hid_sensor_hub_device *hsdev,
355 /* Default unit of measure is milliseconds */ 372 /* Default unit of measure is milliseconds */
356 if (st->poll.units == 0) 373 if (st->poll.units == 0)
357 st->poll.units = HID_USAGE_SENSOR_UNITS_MILLISECOND; 374 st->poll.units = HID_USAGE_SENSOR_UNITS_MILLISECOND;
375
376 st->poll_interval = -1;
377
358 return 0; 378 return 0;
359 379
360} 380}
@@ -377,6 +397,8 @@ int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
377 HID_USAGE_SENSOR_PROY_POWER_STATE, 397 HID_USAGE_SENSOR_PROY_POWER_STATE,
378 &st->power_state); 398 &st->power_state);
379 399
400 st->raw_hystersis = -1;
401
380 sensor_hub_input_get_attribute_info(hsdev, 402 sensor_hub_input_get_attribute_info(hsdev,
381 HID_FEATURE_REPORT, usage_id, 403 HID_FEATURE_REPORT, usage_id,
382 HID_USAGE_SENSOR_PROP_SENSITIVITY_ABS, 404 HID_USAGE_SENSOR_PROP_SENSITIVITY_ABS,
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
index ecf592d69043..60829340a82e 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
@@ -51,6 +51,8 @@ static int _hid_sensor_power_state(struct hid_sensor_common *st, bool state)
51 st->report_state.report_id, 51 st->report_state.report_id,
52 st->report_state.index, 52 st->report_state.index,
53 HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM); 53 HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM);
54
55 poll_value = hid_sensor_read_poll_value(st);
54 } else { 56 } else {
55 int val; 57 int val;
56 58
@@ -87,9 +89,7 @@ static int _hid_sensor_power_state(struct hid_sensor_common *st, bool state)
87 sensor_hub_get_feature(st->hsdev, st->power_state.report_id, 89 sensor_hub_get_feature(st->hsdev, st->power_state.report_id,
88 st->power_state.index, 90 st->power_state.index,
89 sizeof(state_val), &state_val); 91 sizeof(state_val), &state_val);
90 if (state) 92 if (state && poll_value)
91 poll_value = hid_sensor_read_poll_value(st);
92 if (poll_value > 0)
93 msleep_interruptible(poll_value * 2); 93 msleep_interruptible(poll_value * 2);
94 94
95 return 0; 95 return 0;
@@ -127,6 +127,20 @@ static void hid_sensor_set_power_work(struct work_struct *work)
127 struct hid_sensor_common *attrb = container_of(work, 127 struct hid_sensor_common *attrb = container_of(work,
128 struct hid_sensor_common, 128 struct hid_sensor_common,
129 work); 129 work);
130
131 if (attrb->poll_interval >= 0)
132 sensor_hub_set_feature(attrb->hsdev, attrb->poll.report_id,
133 attrb->poll.index,
134 sizeof(attrb->poll_interval),
135 &attrb->poll_interval);
136
137 if (attrb->raw_hystersis >= 0)
138 sensor_hub_set_feature(attrb->hsdev,
139 attrb->sensitivity.report_id,
140 attrb->sensitivity.index,
141 sizeof(attrb->raw_hystersis),
142 &attrb->raw_hystersis);
143
130 _hid_sensor_power_state(attrb, true); 144 _hid_sensor_power_state(attrb, true);
131} 145}
132 146