From 56ff6be608659ac06d4e3cc5827476efa29d610f Mon Sep 17 00:00:00 2001 From: Srinivas Pandruvada Date: Sat, 19 Apr 2014 00:22:00 +0100 Subject: 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 Signed-off-by: Jonathan Cameron --- drivers/iio/light/hid-sensor-prox.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'drivers/iio/light/hid-sensor-prox.c') diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c index 1894ab196f9..07e98ec8e9f 100644 --- a/drivers/iio/light/hid-sensor-prox.c +++ b/drivers/iio/light/hid-sensor-prox.c @@ -176,9 +176,8 @@ static int prox_proc_event(struct hid_sensor_hub_device *hsdev, struct iio_dev *indio_dev = platform_get_drvdata(priv); struct prox_state *prox_state = iio_priv(indio_dev); - dev_dbg(&indio_dev->dev, "prox_proc_event [%d]\n", - prox_state->common_attributes.data_ready); - if (prox_state->common_attributes.data_ready) + dev_dbg(&indio_dev->dev, "prox_proc_event\n"); + if (atomic_read(&prox_state->common_attributes.data_ready)) hid_sensor_push_data(indio_dev, &prox_state->human_presence, sizeof(prox_state->human_presence)); @@ -297,7 +296,7 @@ static int hid_prox_probe(struct platform_device *pdev) dev_err(&pdev->dev, "failed to initialize trigger buffer\n"); goto error_free_dev_mem; } - prox_state->common_attributes.data_ready = false; + atomic_set(&prox_state->common_attributes.data_ready, 0); ret = hid_sensor_setup_trigger(indio_dev, name, &prox_state->common_attributes); if (ret) { -- cgit v1.2.3-70-g09d2 From 1eef062042751822e9f9de418b0f712c6f9b93e8 Mon Sep 17 00:00:00 2001 From: Srinivas Pandruvada Date: Sat, 19 Apr 2014 00:22:00 +0100 Subject: iio: hid-sensors: Proximity: Raw read support Added support for raw reading of channel. If the sensor is powered off, it will turn on for reading value. Signed-off-by: Srinivas Pandruvada Signed-off-by: Jonathan Cameron --- drivers/iio/light/hid-sensor-prox.c | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'drivers/iio/light/hid-sensor-prox.c') diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c index 07e98ec8e9f..d203ef4d892 100644 --- a/drivers/iio/light/hid-sensor-prox.c +++ b/drivers/iio/light/hid-sensor-prox.c @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -75,6 +76,7 @@ static int prox_read_raw(struct iio_dev *indio_dev, u32 address; int ret; int ret_type; + s32 poll_value; *val = 0; *val2 = 0; @@ -90,12 +92,24 @@ static int prox_read_raw(struct iio_dev *indio_dev, report_id = -1; break; } - if (report_id >= 0) + if (report_id >= 0) { + poll_value = hid_sensor_read_poll_value( + &prox_state->common_attributes); + if (poll_value < 0) + return -EINVAL; + + hid_sensor_power_state(&prox_state->common_attributes, + true); + + msleep_interruptible(poll_value * 2); + *val = sensor_hub_input_attr_get_raw_value( prox_state->common_attributes.hsdev, HID_USAGE_SENSOR_PROX, address, report_id); - else { + hid_sensor_power_state(&prox_state->common_attributes, + false); + } else { *val = 0; return -EINVAL; } -- cgit v1.2.3-70-g09d2