OpenCloudOS-Kernel/drivers/iio/common/hid-sensors
Hans de Goede 6f92253024 iio: hid-sensor-trigger: Fix sometimes not powering up the sensor after resume
hid_sensor_set_power_work() powers the sensors back up after a resume
based on the user_requested_state atomic_t.

But hid_sensor_power_state() treats this as a boolean flag, leading to
the following problematic scenario:

1) Some app starts using the iio-sensor in buffered / triggered mode,
   hid_sensor_data_rdy_trigger_set_state(true) gets called, setting
   user_requested_state to 1.
2) Something directly accesses a _raw value through sysfs, leading
   to a call to hid_sensor_power_state(true) followed by
   hid_sensor_power_state(false) call, this sets user_requested_state
   to 1 followed by setting it to 0.
3) Suspend/resume the machine, hid_sensor_set_power_work() now does
   NOT power the sensor back up because user_requested_state (wrongly)
   is 0. Which stops the app using the sensor in buffered mode from
   receiving any new values.

This commit changes user_requested_state to a counter tracking how many
times hid_sensor_power_state(true) was called instead, fixing this.

Cc: Bastien Nocera <hadess@hadess.net>
Cc: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Cc: <Stable@vger.kernel.org>
Signed-off-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
2018-04-21 15:52:35 +01:00
..
Kconfig iio hid-sensor-trigger: add Kconfig depends on IIO_BUFFER 2017-06-13 21:10:14 +01:00
Makefile iio: hid-sensors: respect CONFIG_IIO_TRIGGER 2012-12-27 10:59:50 +00:00
hid-sensor-attributes.c HID: hid-sensor-hub: Force logical minimum to 1 for power and report state 2017-08-09 22:15:59 +02:00
hid-sensor-trigger.c iio: hid-sensor-trigger: Fix sometimes not powering up the sensor after resume 2018-04-21 15:52:35 +01:00
hid-sensor-trigger.h iio: hid_sensor_hub: Common PM functions 2015-01-25 22:55:39 +00:00