HID: hid-sensor-hub: Extend API for async reads
authorSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Thu, 19 Feb 2015 23:33:56 +0000 (15:33 -0800)
committerJiri Kosina <jkosina@suse.cz>
Mon, 23 Feb 2015 14:16:37 +0000 (15:16 +0100)
Add additional flag to read in async mode. In this mode the caller will get
reply via registered callback for capture_sample. Callbacks can be registered
using sensor_hub_register_callback function. The usage id parameter of the
capture_sample can be matched with the usage id of the requested attribute.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Acked-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/hid-sensor-hub.c
drivers/iio/accel/hid-sensor-accel-3d.c
drivers/iio/gyro/hid-sensor-gyro-3d.c
drivers/iio/light/hid-sensor-als.c
drivers/iio/light/hid-sensor-prox.c
drivers/iio/magnetometer/hid-sensor-magn-3d.c
drivers/iio/orientation/hid-sensor-incl-3d.c
drivers/iio/pressure/hid-sensor-press.c
drivers/rtc/rtc-hid-sensor-time.c
include/linux/hid-sensor-hub.h

index c325f85fa3a69d7f63799aa2da242d44034ba239..0a916236316413c074da93f0a6d42e58f07c7360 100644 (file)
@@ -250,48 +250,53 @@ EXPORT_SYMBOL_GPL(sensor_hub_get_feature);
 
 int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
                                        u32 usage_id,
-                                       u32 attr_usage_id, u32 report_id)
+                                       u32 attr_usage_id, u32 report_id,
+                                       enum sensor_hub_read_flags flag)
 {
        struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev);
        unsigned long flags;
        struct hid_report *report;
        int ret_val = 0;
 
-       mutex_lock(&hsdev->mutex);
-       memset(&hsdev->pending, 0, sizeof(hsdev->pending));
-       init_completion(&hsdev->pending.ready);
-       hsdev->pending.usage_id = usage_id;
-       hsdev->pending.attr_usage_id = attr_usage_id;
-       hsdev->pending.raw_size = 0;
-
-       spin_lock_irqsave(&data->lock, flags);
-       hsdev->pending.status = true;
-       spin_unlock_irqrestore(&data->lock, flags);
-       report = sensor_hub_report(report_id, hsdev->hdev, HID_INPUT_REPORT);
+       report = sensor_hub_report(report_id, hsdev->hdev,
+                                  HID_INPUT_REPORT);
        if (!report)
-               goto err_free;
+               return -EINVAL;
 
+       mutex_lock(&hsdev->mutex);
+       if (flag == SENSOR_HUB_SYNC) {
+               memset(&hsdev->pending, 0, sizeof(hsdev->pending));
+               init_completion(&hsdev->pending.ready);
+               hsdev->pending.usage_id = usage_id;
+               hsdev->pending.attr_usage_id = attr_usage_id;
+               hsdev->pending.raw_size = 0;
+
+               spin_lock_irqsave(&data->lock, flags);
+               hsdev->pending.status = true;
+               spin_unlock_irqrestore(&data->lock, flags);
+       }
        mutex_lock(&data->mutex);
        hid_hw_request(hsdev->hdev, report, HID_REQ_GET_REPORT);
        mutex_unlock(&data->mutex);
-       wait_for_completion_interruptible_timeout(&hsdev->pending.ready, HZ*5);
-       switch (hsdev->pending.raw_size) {
-       case 1:
-               ret_val = *(u8 *)hsdev->pending.raw_data;
-               break;
-       case 2:
-               ret_val = *(u16 *)hsdev->pending.raw_data;
-               break;
-       case 4:
-               ret_val = *(u32 *)hsdev->pending.raw_data;
-               break;
-       default:
-               ret_val = 0;
+       if (flag == SENSOR_HUB_SYNC) {
+               wait_for_completion_interruptible_timeout(
+                                               &hsdev->pending.ready, HZ*5);
+               switch (hsdev->pending.raw_size) {
+               case 1:
+                       ret_val = *(u8 *)hsdev->pending.raw_data;
+                       break;
+               case 2:
+                       ret_val = *(u16 *)hsdev->pending.raw_data;
+                       break;
+               case 4:
+                       ret_val = *(u32 *)hsdev->pending.raw_data;
+                       break;
+               default:
+                       ret_val = 0;
+               }
+               kfree(hsdev->pending.raw_data);
+               hsdev->pending.status = false;
        }
-       kfree(hsdev->pending.raw_data);
-
-err_free:
-       hsdev->pending.status = false;
        mutex_unlock(&hsdev->mutex);
 
        return ret_val;
index d5d95317003ac8dd44ed29220fd343a538aee673..0085c2faeaaa268fb671fb72b798ec99f0c5eab6 100644 (file)
@@ -130,7 +130,8 @@ static int accel_3d_read_raw(struct iio_dev *indio_dev,
                        *val = sensor_hub_input_attr_get_raw_value(
                                        accel_state->common_attributes.hsdev,
                                        HID_USAGE_SENSOR_ACCEL_3D, address,
-                                       report_id);
+                                       report_id,
+                                       SENSOR_HUB_SYNC);
                else {
                        *val = 0;
                        hid_sensor_power_state(&accel_state->common_attributes,
index a3ea1e8785d748c3f5afe63f62447589cd849c5b..bdcd105aba26f98703f65c2d23a1638c83a6e059 100644 (file)
@@ -130,7 +130,8 @@ static int gyro_3d_read_raw(struct iio_dev *indio_dev,
                        *val = sensor_hub_input_attr_get_raw_value(
                                        gyro_state->common_attributes.hsdev,
                                        HID_USAGE_SENSOR_GYRO_3D, address,
-                                       report_id);
+                                       report_id,
+                                       SENSOR_HUB_SYNC);
                else {
                        *val = 0;
                        hid_sensor_power_state(&gyro_state->common_attributes,
index a5283d75c0961da4d1a8aea12c0e902a98af618f..321862da626b70cc08b751d131e0e5191cd4c708 100644 (file)
@@ -109,7 +109,8 @@ static int als_read_raw(struct iio_dev *indio_dev,
                        *val = sensor_hub_input_attr_get_raw_value(
                                        als_state->common_attributes.hsdev,
                                        HID_USAGE_SENSOR_ALS, address,
-                                       report_id);
+                                       report_id,
+                                       SENSOR_HUB_SYNC);
                        hid_sensor_power_state(&als_state->common_attributes,
                                                false);
                } else {
index f5a514698fd8614e43b1f99fa4a460f303757764..db9c60e4727625f8d52117a2f367487d495face4 100644 (file)
@@ -105,7 +105,8 @@ static int prox_read_raw(struct iio_dev *indio_dev,
                        *val = sensor_hub_input_attr_get_raw_value(
                                prox_state->common_attributes.hsdev,
                                HID_USAGE_SENSOR_PROX, address,
-                               report_id);
+                               report_id,
+                               SENSOR_HUB_SYNC);
                        hid_sensor_power_state(&prox_state->common_attributes,
                                                false);
                } else {
index 6294575d2777a102de395fae921a9e40b2e6b86f..4d299f39ffd1294ccfae4c368f7b9d0239ed6b03 100644 (file)
@@ -178,7 +178,8 @@ static int magn_3d_read_raw(struct iio_dev *indio_dev,
                        *val = sensor_hub_input_attr_get_raw_value(
                                magn_state->common_attributes.hsdev,
                                HID_USAGE_SENSOR_COMPASS_3D, address,
-                               report_id);
+                               report_id,
+                               SENSOR_HUB_SYNC);
                else {
                        *val = 0;
                        hid_sensor_power_state(&magn_state->common_attributes,
index 1ff181bbbcef8b1d7b744441965cedc835325e69..45bed080b4a6785b058354b4913a4e2ea386f007 100644 (file)
@@ -132,7 +132,8 @@ static int incl_3d_read_raw(struct iio_dev *indio_dev,
                        *val = sensor_hub_input_attr_get_raw_value(
                                incl_state->common_attributes.hsdev,
                                HID_USAGE_SENSOR_INCLINOMETER_3D, address,
-                               report_id);
+                               report_id,
+                               SENSOR_HUB_SYNC);
                else {
                        hid_sensor_power_state(&incl_state->common_attributes,
                                                false);
index 764928682df2fb0d8489627b3436d4ac4f31a829..ac150f0c8b0200897603df7dce15a9a1a2bae49f 100644 (file)
@@ -108,7 +108,8 @@ static int press_read_raw(struct iio_dev *indio_dev,
                        *val = sensor_hub_input_attr_get_raw_value(
                                press_state->common_attributes.hsdev,
                                HID_USAGE_SENSOR_PRESSURE, address,
-                               report_id);
+                               report_id,
+                               SENSOR_HUB_SYNC);
                        hid_sensor_power_state(&press_state->common_attributes,
                                                false);
                } else {
index ae7c2ba440cf45e9ca2cf234ac17409645d2b5be..af4f85a66b39f0ed9689db01bfe05f9656471468 100644 (file)
@@ -213,7 +213,7 @@ static int hid_rtc_read_time(struct device *dev, struct rtc_time *tm)
        /* get a report with all values through requesting one value */
        sensor_hub_input_attr_get_raw_value(time_state->common_attributes.hsdev,
                        HID_USAGE_SENSOR_TIME, hid_time_addresses[0],
-                       time_state->info[0].report_id);
+                       time_state->info[0].report_id, SENSOR_HUB_SYNC);
        /* wait for all values (event) */
        ret = wait_for_completion_killable_timeout(
                        &time_state->comp_last_time, HZ*6);
index 60a34277ddf28c2dd503dba44f89e31cd8831178..4c49b041922d21d5e6fb9bf4bbe1e9704ba6f339 100644 (file)
@@ -169,19 +169,27 @@ int sensor_hub_input_get_attribute_info(struct hid_sensor_hub_device *hsdev,
                        struct hid_sensor_hub_attribute_info *info);
 
 /**
-* sensor_hub_input_attr_get_raw_value() - Synchronous read request
+* sensor_hub_input_attr_get_raw_value() - Attribute read request
 * @usage_id:   Attribute usage id of parent physical device as per spec
 * @attr_usage_id:      Attribute usage id as per spec
 * @report_id:  Report id to look for
+* @flag:      Synchronous or asynchronous read
 *
-* Issues a synchronous read request for an input attribute. Returns
-* data upto 32 bits. Since client can get events, so this call should
-* not be used for data paths, this will impact performance.
+* Issues a synchronous or asynchronous read request for an input attribute.
+* Returns data upto 32 bits.
 */
 
+enum sensor_hub_read_flags {
+       SENSOR_HUB_SYNC,
+       SENSOR_HUB_ASYNC,
+};
+
 int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
-                       u32 usage_id,
-                       u32 attr_usage_id, u32 report_id);
+                                       u32 usage_id,
+                                       u32 attr_usage_id, u32 report_id,
+                                       enum sensor_hub_read_flags flag
+);
+
 /**
 * sensor_hub_set_feature() - Feature set request
 * @report_id:  Report id to look for