Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

hid-sensor: Fix suspend/resume delay

By default all the sensors are runtime suspended state (lowest power
state). During Linux suspend process, all the run time suspended
devices are resumed and then suspended. This caused all sensors to
power up and introduced delay in suspend time, when we introduced
runtime PM for HID sensors. The opposite process happens during resume
process.

To fix this, we do powerup process of the sensors only when the request
is issued from user (raw or tiggerred). In this way when runtime,
resume calls for powerup it will simply return as this will not match
user requested state.

Note this is a regression fix as the increase in suspend / resume
times can be substantial (report of 8 seconds on Len's laptop!)

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Tested-by: Len Brown <len.brown@intel.com>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>

authored by

Srinivas Pandruvada and committed by
Jonathan Cameron
1e25aa96 e5d73218

+11 -1
+10 -1
drivers/iio/common/hid-sensors/hid-sensor-trigger.c
··· 36 36 s32 poll_value = 0; 37 37 38 38 if (state) { 39 + if (!atomic_read(&st->user_requested_state)) 40 + return 0; 39 41 if (sensor_hub_device_open(st->hsdev)) 40 42 return -EIO; 41 43 ··· 54 52 55 53 poll_value = hid_sensor_read_poll_value(st); 56 54 } else { 57 - if (!atomic_dec_and_test(&st->data_ready)) 55 + int val; 56 + 57 + val = atomic_dec_if_positive(&st->data_ready); 58 + if (val < 0) 58 59 return 0; 60 + 59 61 sensor_hub_device_close(st->hsdev); 60 62 state_val = hid_sensor_get_usage_index(st->hsdev, 61 63 st->power_state.report_id, ··· 98 92 99 93 int hid_sensor_power_state(struct hid_sensor_common *st, bool state) 100 94 { 95 + 101 96 #ifdef CONFIG_PM 102 97 int ret; 103 98 99 + atomic_set(&st->user_requested_state, state); 104 100 if (state) 105 101 ret = pm_runtime_get_sync(&st->pdev->dev); 106 102 else { ··· 117 109 118 110 return 0; 119 111 #else 112 + atomic_set(&st->user_requested_state, state); 120 113 return _hid_sensor_power_state(st, state); 121 114 #endif 122 115 }
+1
include/linux/hid-sensor-hub.h
··· 230 230 struct platform_device *pdev; 231 231 unsigned usage_id; 232 232 atomic_t data_ready; 233 + atomic_t user_requested_state; 233 234 struct iio_trigger *trigger; 234 235 struct hid_sensor_hub_attribute_info poll; 235 236 struct hid_sensor_hub_attribute_info report_state;