diff options
Diffstat (limited to 'drivers/iio/common/hid-sensors/hid-sensor-trigger.c')
-rw-r--r-- | drivers/iio/common/hid-sensors/hid-sensor-trigger.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c index 610fc98f88ef..595511022795 100644 --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c | |||
@@ -36,6 +36,8 @@ static int _hid_sensor_power_state(struct hid_sensor_common *st, bool state) | |||
36 | s32 poll_value = 0; | 36 | s32 poll_value = 0; |
37 | 37 | ||
38 | if (state) { | 38 | if (state) { |
39 | if (!atomic_read(&st->user_requested_state)) | ||
40 | return 0; | ||
39 | if (sensor_hub_device_open(st->hsdev)) | 41 | if (sensor_hub_device_open(st->hsdev)) |
40 | return -EIO; | 42 | return -EIO; |
41 | 43 | ||
@@ -52,8 +54,12 @@ static int _hid_sensor_power_state(struct hid_sensor_common *st, bool state) | |||
52 | 54 | ||
53 | poll_value = hid_sensor_read_poll_value(st); | 55 | poll_value = hid_sensor_read_poll_value(st); |
54 | } else { | 56 | } else { |
55 | if (!atomic_dec_and_test(&st->data_ready)) | 57 | int val; |
58 | |||
59 | val = atomic_dec_if_positive(&st->data_ready); | ||
60 | if (val < 0) | ||
56 | return 0; | 61 | return 0; |
62 | |||
57 | sensor_hub_device_close(st->hsdev); | 63 | sensor_hub_device_close(st->hsdev); |
58 | state_val = hid_sensor_get_usage_index(st->hsdev, | 64 | state_val = hid_sensor_get_usage_index(st->hsdev, |
59 | st->power_state.report_id, | 65 | st->power_state.report_id, |
@@ -92,9 +98,11 @@ EXPORT_SYMBOL(hid_sensor_power_state); | |||
92 | 98 | ||
93 | int hid_sensor_power_state(struct hid_sensor_common *st, bool state) | 99 | int hid_sensor_power_state(struct hid_sensor_common *st, bool state) |
94 | { | 100 | { |
101 | |||
95 | #ifdef CONFIG_PM | 102 | #ifdef CONFIG_PM |
96 | int ret; | 103 | int ret; |
97 | 104 | ||
105 | atomic_set(&st->user_requested_state, state); | ||
98 | if (state) | 106 | if (state) |
99 | ret = pm_runtime_get_sync(&st->pdev->dev); | 107 | ret = pm_runtime_get_sync(&st->pdev->dev); |
100 | else { | 108 | else { |
@@ -109,6 +117,7 @@ int hid_sensor_power_state(struct hid_sensor_common *st, bool state) | |||
109 | 117 | ||
110 | return 0; | 118 | return 0; |
111 | #else | 119 | #else |
120 | atomic_set(&st->user_requested_state, state); | ||
112 | return _hid_sensor_power_state(st, state); | 121 | return _hid_sensor_power_state(st, state); |
113 | #endif | 122 | #endif |
114 | } | 123 | } |