diff options
Diffstat (limited to 'drivers/iio/light/hid-sensor-prox.c')
-rw-r--r-- | drivers/iio/light/hid-sensor-prox.c | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/drivers/iio/light/hid-sensor-prox.c b/drivers/iio/light/hid-sensor-prox.c index 1894ab196f97..d203ef4d892f 100644 --- a/drivers/iio/light/hid-sensor-prox.c +++ b/drivers/iio/light/hid-sensor-prox.c @@ -21,6 +21,7 @@ #include <linux/interrupt.h> #include <linux/irq.h> #include <linux/slab.h> +#include <linux/delay.h> #include <linux/hid-sensor-hub.h> #include <linux/iio/iio.h> #include <linux/iio/sysfs.h> @@ -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; } @@ -176,9 +190,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 +310,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) { |