diff options
author | Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> | 2014-04-19 01:22:00 +0200 |
---|---|---|
committer | Jonathan Cameron <jic23@kernel.org> | 2014-05-05 11:59:49 +0200 |
commit | 56ff6be608659ac06d4e3cc5827476efa29d610f (patch) | |
tree | 8d08e07b518db810f8f6bee492ba7dba08683b84 /drivers/iio/common/hid-sensors | |
parent | iio: hid-sensors: Pressure: adjust scale and offset (diff) | |
download | linux-56ff6be608659ac06d4e3cc5827476efa29d610f.tar.xz linux-56ff6be608659ac06d4e3cc5827476efa29d610f.zip |
iio: hid-sensors: Add API to power on/off
Added an API to allow client drivers to turn ON and OFF sensors for
quick read. Added data_read as counting varaible instead of boolean,
so that sensor is powered off only when last user released it.
Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
Diffstat (limited to 'drivers/iio/common/hid-sensors')
-rw-r--r-- | drivers/iio/common/hid-sensors/hid-sensor-trigger.c | 17 | ||||
-rw-r--r-- | drivers/iio/common/hid-sensors/hid-sensor-trigger.h | 1 |
2 files changed, 14 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 @@ #include <linux/iio/sysfs.h> #include "hid-sensor-trigger.h" -static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, - bool state) +int hid_sensor_power_state(struct hid_sensor_common *st, bool state) { - struct hid_sensor_common *st = iio_trigger_get_drvdata(trig); int state_val; int report_val; if (state) { if (sensor_hub_device_open(st->hsdev)) return -EIO; + + atomic_inc(&st->data_ready); + state_val = hid_sensor_get_usage_index(st->hsdev, st->power_state.report_id, st->power_state.index, @@ -47,6 +48,8 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, st->report_state.index, HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM); } else { + if (!atomic_dec_and_test(&st->data_ready)) + return 0; sensor_hub_device_close(st->hsdev); state_val = hid_sensor_get_usage_index(st->hsdev, st->power_state.report_id, @@ -57,7 +60,6 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, st->report_state.index, HID_USAGE_SENSOR_PROP_REPORTING_STATE_NO_EVENTS_ENUM); } - st->data_ready = state; if (state_val >= 0) { state_val += st->power_state.logical_minimum; @@ -75,6 +77,13 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, return 0; } +EXPORT_SYMBOL(hid_sensor_power_state); + +static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig, + bool state) +{ + return hid_sensor_power_state(iio_trigger_get_drvdata(trig), state); +} void hid_sensor_remove_trigger(struct hid_sensor_common *attrb) { diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.h b/drivers/iio/common/hid-sensors/hid-sensor-trigger.h index ca02f7811aa8..0f8e78c249d3 100644 --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.h +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.h @@ -22,5 +22,6 @@ int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name, struct hid_sensor_common *attrb); void hid_sensor_remove_trigger(struct hid_sensor_common *attrb); +int hid_sensor_power_state(struct hid_sensor_common *st, bool state); #endif |