HID: hid-sensor-hub: Enhance feature report set API
authorSrinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Thu, 19 Feb 2015 23:35:26 +0000 (15:35 -0800)
committerJiri Kosina <jkosina@suse.cz>
Mon, 23 Feb 2015 14:20:00 +0000 (15:20 +0100)
Current API only allows setting one offset in the field. This API
is extended to set multiple offsets in the field report.
Also update parameters in the users of this API.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Reviewed-by: Jonathan Cameron <jic23@kernel.org>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
drivers/hid/hid-sensor-hub.c
drivers/iio/common/hid-sensors/hid-sensor-attributes.c
drivers/iio/common/hid-sensors/hid-sensor-trigger.c
include/linux/hid-sensor-hub.h

index c025c489270d1fbd4b589acfd64ed5161dec060b..44da796fa4fd020f0be67ef9fa60f50f156b9296 100644 (file)
@@ -199,10 +199,14 @@ int sensor_hub_remove_callback(struct hid_sensor_hub_device *hsdev,
 EXPORT_SYMBOL_GPL(sensor_hub_remove_callback);
 
 int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
-                               u32 field_index, s32 value)
+                          u32 field_index, int buffer_size, void *buffer)
 {
        struct hid_report *report;
        struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev);
+       __s32 *buf32 = buffer;
+       int i = 0;
+       int remaining_bytes;
+       __s32 value;
        int ret = 0;
 
        mutex_lock(&data->mutex);
@@ -211,7 +215,21 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
                ret = -EINVAL;
                goto done_proc;
        }
-       hid_set_field(report->field[field_index], 0, value);
+
+       remaining_bytes = do_div(buffer_size, sizeof(__s32));
+       if (buffer_size) {
+               for (i = 0; i < buffer_size; ++i) {
+                       hid_set_field(report->field[field_index], i,
+                                     cpu_to_le32(*buf32));
+                       ++buf32;
+               }
+       }
+       if (remaining_bytes) {
+               value = 0;
+               memcpy(&value, (u8 *)buf32, remaining_bytes);
+               hid_set_field(report->field[field_index], i,
+                             cpu_to_le32(value));
+       }
        hid_hw_request(hsdev->hdev, report, HID_REQ_SET_REPORT);
        hid_hw_wait(hsdev->hdev);
 
index e1435e98636dec2aebe55c4d20fd9f3f6a4513b4..e81f434760f4c778c604c7d2e102bfa79adef9b2 100644 (file)
@@ -212,9 +212,8 @@ int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
                else
                        value = 0;
        }
-       ret = sensor_hub_set_feature(st->hsdev,
-               st->poll.report_id,
-               st->poll.index, value);
+       ret = sensor_hub_set_feature(st->hsdev, st->poll.report_id,
+                                    st->poll.index, sizeof(value), &value);
        if (ret < 0 || value < 0)
                ret = -EINVAL;
 
@@ -254,9 +253,9 @@ int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
        value = convert_to_vtf_format(st->sensitivity.size,
                                st->sensitivity.unit_expo,
                                val1, val2);
-       ret = sensor_hub_set_feature(st->hsdev,
-               st->sensitivity.report_id,
-               st->sensitivity.index, value);
+       ret = sensor_hub_set_feature(st->hsdev, st->sensitivity.report_id,
+                                    st->sensitivity.index, sizeof(value),
+                                    &value);
        if (ret < 0 || value < 0)
                ret = -EINVAL;
 
index ef0c495a8ef99d66b270a27075186f7241750fff..910e82a7d06ef750166882256a1a13697693476a 100644 (file)
@@ -64,15 +64,16 @@ int hid_sensor_power_state(struct hid_sensor_common *st, bool state)
        if (state_val >= 0) {
                state_val += st->power_state.logical_minimum;
                sensor_hub_set_feature(st->hsdev, st->power_state.report_id,
-                                       st->power_state.index,
-                                       (s32)state_val);
+                                      st->power_state.index, sizeof(state_val),
+                                      &state_val);
        }
 
        if (report_val >= 0) {
                report_val += st->report_state.logical_minimum;
                sensor_hub_set_feature(st->hsdev, st->report_state.report_id,
-                                       st->report_state.index,
-                                       (s32)report_val);
+                                      st->report_state.index,
+                                      sizeof(report_val),
+                                      &report_val);
        }
 
        sensor_hub_get_feature(st->hsdev, st->power_state.report_id,
index 1db3320666690dc26006298c522062783d9bde84..4a2fdbabfcf1f554c77b7ed52c9ef5c02f2214bc 100644 (file)
@@ -194,13 +194,14 @@ int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
 * sensor_hub_set_feature() - Feature set request
 * @report_id:  Report id to look for
 * @field_index:        Field index inside a report
-* @value:      Value to set
+* @buffer_size: size of the buffer
+* @buffer:     buffer to use in the feature set
 *
 * Used to set a field in feature report. For example this can set polling
 * interval, sensitivity, activate/deactivate state.
 */
 int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
-                       u32 field_index, s32 value);
+                          u32 field_index, int buffer_size, void *buffer);
 
 /**
 * sensor_hub_get_feature() - Feature get request