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 | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c index dbefbdaf7cd1..73282cee0c81 100644 --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c | |||
@@ -28,16 +28,17 @@ | |||
28 | #include <linux/iio/sysfs.h> | 28 | #include <linux/iio/sysfs.h> |
29 | #include "hid-sensor-trigger.h" | 29 | #include "hid-sensor-trigger.h" |
30 | 30 | ||
31 | static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, | 31 | int hid_sensor_power_state(struct hid_sensor_common *st, bool state) |
32 | bool state) | ||
33 | { | 32 | { |
34 | struct hid_sensor_common *st = iio_trigger_get_drvdata(trig); | ||
35 | int state_val; | 33 | int state_val; |
36 | int report_val; | 34 | int report_val; |
37 | 35 | ||
38 | if (state) { | 36 | if (state) { |
39 | if (sensor_hub_device_open(st->hsdev)) | 37 | if (sensor_hub_device_open(st->hsdev)) |
40 | return -EIO; | 38 | return -EIO; |
39 | |||
40 | atomic_inc(&st->data_ready); | ||
41 | |||
41 | state_val = hid_sensor_get_usage_index(st->hsdev, | 42 | state_val = hid_sensor_get_usage_index(st->hsdev, |
42 | st->power_state.report_id, | 43 | st->power_state.report_id, |
43 | st->power_state.index, | 44 | st->power_state.index, |
@@ -47,6 +48,8 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, | |||
47 | st->report_state.index, | 48 | st->report_state.index, |
48 | HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM); | 49 | HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM); |
49 | } else { | 50 | } else { |
51 | if (!atomic_dec_and_test(&st->data_ready)) | ||
52 | return 0; | ||
50 | sensor_hub_device_close(st->hsdev); | 53 | sensor_hub_device_close(st->hsdev); |
51 | state_val = hid_sensor_get_usage_index(st->hsdev, | 54 | state_val = hid_sensor_get_usage_index(st->hsdev, |
52 | st->power_state.report_id, | 55 | st->power_state.report_id, |
@@ -57,7 +60,6 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, | |||
57 | st->report_state.index, | 60 | st->report_state.index, |
58 | HID_USAGE_SENSOR_PROP_REPORTING_STATE_NO_EVENTS_ENUM); | 61 | HID_USAGE_SENSOR_PROP_REPORTING_STATE_NO_EVENTS_ENUM); |
59 | } | 62 | } |
60 | st->data_ready = state; | ||
61 | 63 | ||
62 | if (state_val >= 0) { | 64 | if (state_val >= 0) { |
63 | state_val += st->power_state.logical_minimum; | 65 | state_val += st->power_state.logical_minimum; |
@@ -75,6 +77,13 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, | |||
75 | 77 | ||
76 | return 0; | 78 | return 0; |
77 | } | 79 | } |
80 | EXPORT_SYMBOL(hid_sensor_power_state); | ||
81 | |||
82 | static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, | ||
83 | bool state) | ||
84 | { | ||
85 | return hid_sensor_power_state(iio_trigger_get_drvdata(trig), state); | ||
86 | } | ||
78 | 87 | ||
79 | void hid_sensor_remove_trigger(struct hid_sensor_common *attrb) | 88 | void hid_sensor_remove_trigger(struct hid_sensor_common *attrb) |
80 | { | 89 | { |