Skip to content

Commit 3950e03

Browse files
spandruvadaJiri Kosina
authored andcommitted
HID: hid-sensor-hub: Enhance feature report set API
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 <[email protected]> Reviewed-by: Jonathan Cameron <[email protected]> Signed-off-by: Jiri Kosina <[email protected]>
1 parent 6adc83f commit 3950e03

File tree

4 files changed

+33
-14
lines changed

4 files changed

+33
-14
lines changed

drivers/hid/hid-sensor-hub.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,14 @@ int sensor_hub_remove_callback(struct hid_sensor_hub_device *hsdev,
199199
EXPORT_SYMBOL_GPL(sensor_hub_remove_callback);
200200

201201
int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
202-
u32 field_index, s32 value)
202+
u32 field_index, int buffer_size, void *buffer)
203203
{
204204
struct hid_report *report;
205205
struct sensor_hub_data *data = hid_get_drvdata(hsdev->hdev);
206+
__s32 *buf32 = buffer;
207+
int i = 0;
208+
int remaining_bytes;
209+
__s32 value;
206210
int ret = 0;
207211

208212
mutex_lock(&data->mutex);
@@ -211,7 +215,21 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
211215
ret = -EINVAL;
212216
goto done_proc;
213217
}
214-
hid_set_field(report->field[field_index], 0, value);
218+
219+
remaining_bytes = do_div(buffer_size, sizeof(__s32));
220+
if (buffer_size) {
221+
for (i = 0; i < buffer_size; ++i) {
222+
hid_set_field(report->field[field_index], i,
223+
cpu_to_le32(*buf32));
224+
++buf32;
225+
}
226+
}
227+
if (remaining_bytes) {
228+
value = 0;
229+
memcpy(&value, (u8 *)buf32, remaining_bytes);
230+
hid_set_field(report->field[field_index], i,
231+
cpu_to_le32(value));
232+
}
215233
hid_hw_request(hsdev->hdev, report, HID_REQ_SET_REPORT);
216234
hid_hw_wait(hsdev->hdev);
217235

drivers/iio/common/hid-sensors/hid-sensor-attributes.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -212,9 +212,8 @@ int hid_sensor_write_samp_freq_value(struct hid_sensor_common *st,
212212
else
213213
value = 0;
214214
}
215-
ret = sensor_hub_set_feature(st->hsdev,
216-
st->poll.report_id,
217-
st->poll.index, value);
215+
ret = sensor_hub_set_feature(st->hsdev, st->poll.report_id,
216+
st->poll.index, sizeof(value), &value);
218217
if (ret < 0 || value < 0)
219218
ret = -EINVAL;
220219

@@ -254,9 +253,9 @@ int hid_sensor_write_raw_hyst_value(struct hid_sensor_common *st,
254253
value = convert_to_vtf_format(st->sensitivity.size,
255254
st->sensitivity.unit_expo,
256255
val1, val2);
257-
ret = sensor_hub_set_feature(st->hsdev,
258-
st->sensitivity.report_id,
259-
st->sensitivity.index, value);
256+
ret = sensor_hub_set_feature(st->hsdev, st->sensitivity.report_id,
257+
st->sensitivity.index, sizeof(value),
258+
&value);
260259
if (ret < 0 || value < 0)
261260
ret = -EINVAL;
262261

drivers/iio/common/hid-sensors/hid-sensor-trigger.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,16 @@ int hid_sensor_power_state(struct hid_sensor_common *st, bool state)
6464
if (state_val >= 0) {
6565
state_val += st->power_state.logical_minimum;
6666
sensor_hub_set_feature(st->hsdev, st->power_state.report_id,
67-
st->power_state.index,
68-
(s32)state_val);
67+
st->power_state.index, sizeof(state_val),
68+
&state_val);
6969
}
7070

7171
if (report_val >= 0) {
7272
report_val += st->report_state.logical_minimum;
7373
sensor_hub_set_feature(st->hsdev, st->report_state.report_id,
74-
st->report_state.index,
75-
(s32)report_val);
74+
st->report_state.index,
75+
sizeof(report_val),
76+
&report_val);
7677
}
7778

7879
sensor_hub_get_feature(st->hsdev, st->power_state.report_id,

include/linux/hid-sensor-hub.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,13 +194,14 @@ int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev,
194194
* sensor_hub_set_feature() - Feature set request
195195
* @report_id: Report id to look for
196196
* @field_index: Field index inside a report
197-
* @value: Value to set
197+
* @buffer_size: size of the buffer
198+
* @buffer: buffer to use in the feature set
198199
*
199200
* Used to set a field in feature report. For example this can set polling
200201
* interval, sensitivity, activate/deactivate state.
201202
*/
202203
int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id,
203-
u32 field_index, s32 value);
204+
u32 field_index, int buffer_size, void *buffer);
204205

205206
/**
206207
* sensor_hub_get_feature() - Feature get request

0 commit comments

Comments
 (0)