* [PATCH v2 0/2] hid: sensor-hub: Enhance feature report APIs @ 2015-01-17 0:39 ` Srinivas Pandruvada 0 siblings, 0 replies; 17+ messages in thread From: Srinivas Pandruvada @ 2015-01-17 0:39 UTC (permalink / raw) To: jkosina-AlSwsSmVLrQ, jic23-DgEjT+Ai2ygdnm+yROfE0A Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA, linux-input-u79uwXL29TY76Z2rM5mHXA, borneo.antonio-Re5JQEeQqe8AvxtiuMwx3w, Srinivas Pandruvada Current get and set feature report is enhanced to have multiple values in get and set. v2 As suggested by Antonio Borneo, using DIV_ROUND_UP v1 Squashed into two patches one for get and one for set feature report for bisectability. v0 Separate patches for each driver/modules Srinivas Pandruvada (2): HID: hid-sensor-hub: Enhance get feature report API HID: hid-sensor-hub: Enhance feature report set API drivers/hid/hid-sensor-hub.c | 37 +++++++++++++++++++--- .../iio/common/hid-sensors/hid-sensor-attributes.c | 24 +++++++------- .../iio/common/hid-sensors/hid-sensor-trigger.c | 13 ++++---- include/linux/hid-sensor-hub.h | 13 +++++--- 4 files changed, 60 insertions(+), 27 deletions(-) -- 1.9.1 ^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v2 0/2] hid: sensor-hub: Enhance feature report APIs @ 2015-01-17 0:39 ` Srinivas Pandruvada 0 siblings, 0 replies; 17+ messages in thread From: Srinivas Pandruvada @ 2015-01-17 0:39 UTC (permalink / raw) To: jkosina, jic23 Cc: linux-iio, linux-input, borneo.antonio, Srinivas Pandruvada Current get and set feature report is enhanced to have multiple values in get and set. v2 As suggested by Antonio Borneo, using DIV_ROUND_UP v1 Squashed into two patches one for get and one for set feature report for bisectability. v0 Separate patches for each driver/modules Srinivas Pandruvada (2): HID: hid-sensor-hub: Enhance get feature report API HID: hid-sensor-hub: Enhance feature report set API drivers/hid/hid-sensor-hub.c | 37 +++++++++++++++++++--- .../iio/common/hid-sensors/hid-sensor-attributes.c | 24 +++++++------- .../iio/common/hid-sensors/hid-sensor-trigger.c | 13 ++++---- include/linux/hid-sensor-hub.h | 13 +++++--- 4 files changed, 60 insertions(+), 27 deletions(-) -- 1.9.1 ^ permalink raw reply [flat|nested] 17+ messages in thread
[parent not found: <1421455165-3944-1-git-send-email-srinivas.pandruvada-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>]
* [PATCH v2 1/2] HID: hid-sensor-hub: Enhance get feature report API 2015-01-17 0:39 ` Srinivas Pandruvada @ 2015-01-17 0:39 ` Srinivas Pandruvada -1 siblings, 0 replies; 17+ messages in thread From: Srinivas Pandruvada @ 2015-01-17 0:39 UTC (permalink / raw) To: jkosina-AlSwsSmVLrQ, jic23-DgEjT+Ai2ygdnm+yROfE0A Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA, linux-input-u79uwXL29TY76Z2rM5mHXA, borneo.antonio-Re5JQEeQqe8AvxtiuMwx3w, Srinivas Pandruvada Some hid sensor feature report can contain more than one reports. This API can now support receiving multiple values from the feature report. Also update the parameters in the users of this API. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> --- drivers/hid/hid-sensor-hub.c | 15 +++++++++++++-- drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 13 +++++++------ drivers/iio/common/hid-sensors/hid-sensor-trigger.c | 4 ++-- include/linux/hid-sensor-hub.h | 8 +++++--- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c index e54ce10..4d22bd4 100644 --- a/drivers/hid/hid-sensor-hub.c +++ b/drivers/hid/hid-sensor-hub.c @@ -232,10 +232,11 @@ done_proc: EXPORT_SYMBOL_GPL(sensor_hub_set_feature); int sensor_hub_get_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); + int report_size; int ret = 0; mutex_lock(&data->mutex); @@ -247,7 +248,17 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, } hid_hw_request(hsdev->hdev, report, HID_REQ_GET_REPORT); hid_hw_wait(hsdev->hdev); - *value = report->field[field_index]->value[0]; + + /* calculate number of bytes required to read this field */ + report_size = DIV_ROUND_UP(report->field[field_index]->report_size, + 8) * + report->field[field_index]->report_count; + if (!report_size) { + ret = -EINVAL; + goto done_proc; + } + ret = min(report_size, buffer_size); + memcpy(buffer, report->field[field_index]->value, ret); done_proc: mutex_unlock(&data->mutex); diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c index 25b01e1..e1435e9 100644 --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c @@ -153,8 +153,8 @@ s32 hid_sensor_read_poll_value(struct hid_sensor_common *st) int ret; ret = sensor_hub_get_feature(st->hsdev, - st->poll.report_id, - st->poll.index, &value); + st->poll.report_id, + st->poll.index, sizeof(value), &value); if (ret < 0 || value < 0) { return -EINVAL; @@ -174,8 +174,8 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st, int ret; ret = sensor_hub_get_feature(st->hsdev, - st->poll.report_id, - st->poll.index, &value); + st->poll.report_id, + st->poll.index, sizeof(value), &value); if (ret < 0 || value < 0) { *val1 = *val2 = 0; return -EINVAL; @@ -229,8 +229,9 @@ int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st, int ret; ret = sensor_hub_get_feature(st->hsdev, - st->sensitivity.report_id, - st->sensitivity.index, &value); + st->sensitivity.report_id, + st->sensitivity.index, sizeof(value), + &value); if (ret < 0 || value < 0) { *val1 = *val2 = 0; return -EINVAL; diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c index 92068cd..ef0c495 100644 --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c @@ -76,8 +76,8 @@ int hid_sensor_power_state(struct hid_sensor_common *st, bool state) } sensor_hub_get_feature(st->hsdev, st->power_state.report_id, - st->power_state.index, - &state_val); + st->power_state.index, + sizeof(state_val), &state_val); return 0; } EXPORT_SYMBOL(hid_sensor_power_state); diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h index 4173a8f..dfdf6ef 100644 --- a/include/linux/hid-sensor-hub.h +++ b/include/linux/hid-sensor-hub.h @@ -179,13 +179,15 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, * @hsdev: Hub device instance. * @report_id: Report id to look for * @field_index: Field index inside a report -* @value: Place holder for return value +* @buffer_size: size of the buffer +* @buffer: buffer to copy output * * Used to get a field in feature report. For example this can get polling -* interval, sensitivity, activate/deactivate state. +* interval, sensitivity, activate/deactivate state. On success it returns +* number of bytes copied to buffer. On failure, it returns value < 0. */ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, - u32 field_index, s32 *value); + u32 field_index, int buffer_size, void *buffer); /* hid-sensor-attributes */ -- 1.9.1 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v2 1/2] HID: hid-sensor-hub: Enhance get feature report API @ 2015-01-17 0:39 ` Srinivas Pandruvada 0 siblings, 0 replies; 17+ messages in thread From: Srinivas Pandruvada @ 2015-01-17 0:39 UTC (permalink / raw) To: jkosina, jic23 Cc: linux-iio, linux-input, borneo.antonio, Srinivas Pandruvada Some hid sensor feature report can contain more than one reports. This API can now support receiving multiple values from the feature report. Also update the parameters in the users of this API. Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> --- drivers/hid/hid-sensor-hub.c | 15 +++++++++++++-- drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 13 +++++++------ drivers/iio/common/hid-sensors/hid-sensor-trigger.c | 4 ++-- include/linux/hid-sensor-hub.h | 8 +++++--- 4 files changed, 27 insertions(+), 13 deletions(-) diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c index e54ce10..4d22bd4 100644 --- a/drivers/hid/hid-sensor-hub.c +++ b/drivers/hid/hid-sensor-hub.c @@ -232,10 +232,11 @@ done_proc: EXPORT_SYMBOL_GPL(sensor_hub_set_feature); int sensor_hub_get_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); + int report_size; int ret = 0; mutex_lock(&data->mutex); @@ -247,7 +248,17 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, } hid_hw_request(hsdev->hdev, report, HID_REQ_GET_REPORT); hid_hw_wait(hsdev->hdev); - *value = report->field[field_index]->value[0]; + + /* calculate number of bytes required to read this field */ + report_size = DIV_ROUND_UP(report->field[field_index]->report_size, + 8) * + report->field[field_index]->report_count; + if (!report_size) { + ret = -EINVAL; + goto done_proc; + } + ret = min(report_size, buffer_size); + memcpy(buffer, report->field[field_index]->value, ret); done_proc: mutex_unlock(&data->mutex); diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c index 25b01e1..e1435e9 100644 --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c @@ -153,8 +153,8 @@ s32 hid_sensor_read_poll_value(struct hid_sensor_common *st) int ret; ret = sensor_hub_get_feature(st->hsdev, - st->poll.report_id, - st->poll.index, &value); + st->poll.report_id, + st->poll.index, sizeof(value), &value); if (ret < 0 || value < 0) { return -EINVAL; @@ -174,8 +174,8 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st, int ret; ret = sensor_hub_get_feature(st->hsdev, - st->poll.report_id, - st->poll.index, &value); + st->poll.report_id, + st->poll.index, sizeof(value), &value); if (ret < 0 || value < 0) { *val1 = *val2 = 0; return -EINVAL; @@ -229,8 +229,9 @@ int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st, int ret; ret = sensor_hub_get_feature(st->hsdev, - st->sensitivity.report_id, - st->sensitivity.index, &value); + st->sensitivity.report_id, + st->sensitivity.index, sizeof(value), + &value); if (ret < 0 || value < 0) { *val1 = *val2 = 0; return -EINVAL; diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c index 92068cd..ef0c495 100644 --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c @@ -76,8 +76,8 @@ int hid_sensor_power_state(struct hid_sensor_common *st, bool state) } sensor_hub_get_feature(st->hsdev, st->power_state.report_id, - st->power_state.index, - &state_val); + st->power_state.index, + sizeof(state_val), &state_val); return 0; } EXPORT_SYMBOL(hid_sensor_power_state); diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h index 4173a8f..dfdf6ef 100644 --- a/include/linux/hid-sensor-hub.h +++ b/include/linux/hid-sensor-hub.h @@ -179,13 +179,15 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, * @hsdev: Hub device instance. * @report_id: Report id to look for * @field_index: Field index inside a report -* @value: Place holder for return value +* @buffer_size: size of the buffer +* @buffer: buffer to copy output * * Used to get a field in feature report. For example this can get polling -* interval, sensitivity, activate/deactivate state. +* interval, sensitivity, activate/deactivate state. On success it returns +* number of bytes copied to buffer. On failure, it returns value < 0. */ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, - u32 field_index, s32 *value); + u32 field_index, int buffer_size, void *buffer); /* hid-sensor-attributes */ -- 1.9.1 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* Re: [PATCH v2 1/2] HID: hid-sensor-hub: Enhance get feature report API 2015-01-17 0:39 ` Srinivas Pandruvada (?) @ 2015-02-01 10:35 ` Jonathan Cameron [not found] ` <54CE018F.9010600-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> -1 siblings, 1 reply; 17+ messages in thread From: Jonathan Cameron @ 2015-02-01 10:35 UTC (permalink / raw) To: Srinivas Pandruvada, jkosina; +Cc: linux-iio, linux-input, borneo.antonio On 17/01/15 00:39, Srinivas Pandruvada wrote: > Some hid sensor feature report can contain more than one reports. > This API can now support receiving multiple values from the feature > report. > Also update the parameters in the users of this API. > > Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> Oops, commented on old version. Acked-by: Jonathan Cameron <jic23@kernel.org> > --- > drivers/hid/hid-sensor-hub.c | 15 +++++++++++++-- > drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 13 +++++++------ > drivers/iio/common/hid-sensors/hid-sensor-trigger.c | 4 ++-- > include/linux/hid-sensor-hub.h | 8 +++++--- > 4 files changed, 27 insertions(+), 13 deletions(-) > > diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c > index e54ce10..4d22bd4 100644 > --- a/drivers/hid/hid-sensor-hub.c > +++ b/drivers/hid/hid-sensor-hub.c > @@ -232,10 +232,11 @@ done_proc: > EXPORT_SYMBOL_GPL(sensor_hub_set_feature); > > int sensor_hub_get_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); > + int report_size; > int ret = 0; > > mutex_lock(&data->mutex); > @@ -247,7 +248,17 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, > } > hid_hw_request(hsdev->hdev, report, HID_REQ_GET_REPORT); > hid_hw_wait(hsdev->hdev); > - *value = report->field[field_index]->value[0]; > + > + /* calculate number of bytes required to read this field */ > + report_size = DIV_ROUND_UP(report->field[field_index]->report_size, > + 8) * > + report->field[field_index]->report_count; > + if (!report_size) { > + ret = -EINVAL; > + goto done_proc; > + } > + ret = min(report_size, buffer_size); > + memcpy(buffer, report->field[field_index]->value, ret); > > done_proc: > mutex_unlock(&data->mutex); > diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > index 25b01e1..e1435e9 100644 > --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > @@ -153,8 +153,8 @@ s32 hid_sensor_read_poll_value(struct hid_sensor_common *st) > int ret; > > ret = sensor_hub_get_feature(st->hsdev, > - st->poll.report_id, > - st->poll.index, &value); > + st->poll.report_id, > + st->poll.index, sizeof(value), &value); > > if (ret < 0 || value < 0) { > return -EINVAL; > @@ -174,8 +174,8 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st, > int ret; > > ret = sensor_hub_get_feature(st->hsdev, > - st->poll.report_id, > - st->poll.index, &value); > + st->poll.report_id, > + st->poll.index, sizeof(value), &value); > if (ret < 0 || value < 0) { > *val1 = *val2 = 0; > return -EINVAL; > @@ -229,8 +229,9 @@ int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st, > int ret; > > ret = sensor_hub_get_feature(st->hsdev, > - st->sensitivity.report_id, > - st->sensitivity.index, &value); > + st->sensitivity.report_id, > + st->sensitivity.index, sizeof(value), > + &value); > if (ret < 0 || value < 0) { > *val1 = *val2 = 0; > return -EINVAL; > diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > index 92068cd..ef0c495 100644 > --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > @@ -76,8 +76,8 @@ int hid_sensor_power_state(struct hid_sensor_common *st, bool state) > } > > sensor_hub_get_feature(st->hsdev, st->power_state.report_id, > - st->power_state.index, > - &state_val); > + st->power_state.index, > + sizeof(state_val), &state_val); > return 0; > } > EXPORT_SYMBOL(hid_sensor_power_state); > diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h > index 4173a8f..dfdf6ef 100644 > --- a/include/linux/hid-sensor-hub.h > +++ b/include/linux/hid-sensor-hub.h > @@ -179,13 +179,15 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, > * @hsdev: Hub device instance. > * @report_id: Report id to look for > * @field_index: Field index inside a report > -* @value: Place holder for return value > +* @buffer_size: size of the buffer > +* @buffer: buffer to copy output > * > * Used to get a field in feature report. For example this can get polling > -* interval, sensitivity, activate/deactivate state. > +* interval, sensitivity, activate/deactivate state. On success it returns > +* number of bytes copied to buffer. On failure, it returns value < 0. > */ > int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, > - u32 field_index, s32 *value); > + u32 field_index, int buffer_size, void *buffer); > > /* hid-sensor-attributes */ > > ^ permalink raw reply [flat|nested] 17+ messages in thread
[parent not found: <54CE018F.9010600-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>]
* Re: [PATCH v2 1/2] HID: hid-sensor-hub: Enhance get feature report API 2015-02-01 10:35 ` Jonathan Cameron @ 2015-02-17 12:39 ` Jiri Kosina 0 siblings, 0 replies; 17+ messages in thread From: Jiri Kosina @ 2015-02-17 12:39 UTC (permalink / raw) To: Jonathan Cameron Cc: Srinivas Pandruvada, linux-iio-u79uwXL29TY76Z2rM5mHXA, linux-input-u79uwXL29TY76Z2rM5mHXA, borneo.antonio-Re5JQEeQqe8AvxtiuMwx3w On Sun, 1 Feb 2015, Jonathan Cameron wrote: > On 17/01/15 00:39, Srinivas Pandruvada wrote: > > Some hid sensor feature report can contain more than one reports. > > This API can now support receiving multiple values from the feature > > report. > > Also update the parameters in the users of this API. > > > > Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> > Oops, commented on old version. > Acked-by: Jonathan Cameron <jic23-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> I don't seem to have been CCed on v2 submission of this series. Srinivas, could you please resend to me with Jonathan's ack added? -- Jiri Kosina SUSE Labs ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 1/2] HID: hid-sensor-hub: Enhance get feature report API @ 2015-02-17 12:39 ` Jiri Kosina 0 siblings, 0 replies; 17+ messages in thread From: Jiri Kosina @ 2015-02-17 12:39 UTC (permalink / raw) To: Jonathan Cameron Cc: Srinivas Pandruvada, linux-iio, linux-input, borneo.antonio On Sun, 1 Feb 2015, Jonathan Cameron wrote: > On 17/01/15 00:39, Srinivas Pandruvada wrote: > > Some hid sensor feature report can contain more than one reports. > > This API can now support receiving multiple values from the feature > > report. > > Also update the parameters in the users of this API. > > > > Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> > Oops, commented on old version. > Acked-by: Jonathan Cameron <jic23@kernel.org> I don't seem to have been CCed on v2 submission of this series. Srinivas, could you please resend to me with Jonathan's ack added? -- Jiri Kosina SUSE Labs ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 1/2] HID: hid-sensor-hub: Enhance get feature report API 2015-02-17 12:39 ` Jiri Kosina (?) @ 2015-02-17 16:18 ` Srinivas Pandruvada -1 siblings, 0 replies; 17+ messages in thread From: Srinivas Pandruvada @ 2015-02-17 16:18 UTC (permalink / raw) To: Jiri Kosina; +Cc: Jonathan Cameron, linux-iio, linux-input, borneo.antonio Hi Jiri, On Tue, 2015-02-17 at 13:39 +0100, Jiri Kosina wrote: > On Sun, 1 Feb 2015, Jonathan Cameron wrote: > > > On 17/01/15 00:39, Srinivas Pandruvada wrote: > > > Some hid sensor feature report can contain more than one reports. > > > This API can now support receiving multiple values from the feature > > > report. > > > Also update the parameters in the users of this API. > > > > > > Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> > > Oops, commented on old version. > > Acked-by: Jonathan Cameron <jic23@kernel.org> > > I don't seem to have been CCed on v2 submission of this series. Srinivas, > could you please resend to me with Jonathan's ack added? I will resend by addressing comments and adding ack. Thanks, Srinivas > > -- > Jiri Kosina > SUSE Labs ^ permalink raw reply [flat|nested] 17+ messages in thread
[parent not found: <1421455165-3944-2-git-send-email-srinivas.pandruvada-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>]
* Re: [PATCH v2 1/2] HID: hid-sensor-hub: Enhance get feature report API 2015-01-17 0:39 ` Srinivas Pandruvada @ 2015-03-28 20:58 ` Hartmut Knaack -1 siblings, 0 replies; 17+ messages in thread From: Hartmut Knaack @ 2015-03-28 20:58 UTC (permalink / raw) To: Srinivas Pandruvada, jkosina-AlSwsSmVLrQ, jic23-DgEjT+Ai2ygdnm+yROfE0A Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA, linux-input-u79uwXL29TY76Z2rM5mHXA, borneo.antonio-Re5JQEeQqe8AvxtiuMwx3w Srinivas Pandruvada schrieb am 17.01.2015 um 01:39: > Some hid sensor feature report can contain more than one reports. > This API can now support receiving multiple values from the feature > report. > Also update the parameters in the users of this API. > Hi Srinivas, I noticed this series got applied already to linux-input. Yet I was wondering if it wouldn't be better to have size variables like buffer_size, report_size and remaining_bytes (from the next patch) defined as unsigned. Also a minor indentation issue spotted inline, in case you get to work on that section again some time. > Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> > --- > drivers/hid/hid-sensor-hub.c | 15 +++++++++++++-- > drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 13 +++++++------ > drivers/iio/common/hid-sensors/hid-sensor-trigger.c | 4 ++-- > include/linux/hid-sensor-hub.h | 8 +++++--- > 4 files changed, 27 insertions(+), 13 deletions(-) > > diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c > index e54ce10..4d22bd4 100644 > --- a/drivers/hid/hid-sensor-hub.c > +++ b/drivers/hid/hid-sensor-hub.c > @@ -232,10 +232,11 @@ done_proc: > EXPORT_SYMBOL_GPL(sensor_hub_set_feature); > > int sensor_hub_get_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); > + int report_size; > int ret = 0; > > mutex_lock(&data->mutex); > @@ -247,7 +248,17 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, > } > hid_hw_request(hsdev->hdev, report, HID_REQ_GET_REPORT); > hid_hw_wait(hsdev->hdev); > - *value = report->field[field_index]->value[0]; > + > + /* calculate number of bytes required to read this field */ > + report_size = DIV_ROUND_UP(report->field[field_index]->report_size, > + 8) * > + report->field[field_index]->report_count; The last line should not be indented with the opening parenthesis any more. What do you think about this solution: report_size = DIV_ROUND_UP(report->field[field_index]->report_size, 8); report_size *= report->field[field_index]->report_count; > + if (!report_size) { > + ret = -EINVAL; > + goto done_proc; > + } > + ret = min(report_size, buffer_size); > + memcpy(buffer, report->field[field_index]->value, ret); > > done_proc: > mutex_unlock(&data->mutex); > diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > index 25b01e1..e1435e9 100644 > --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > @@ -153,8 +153,8 @@ s32 hid_sensor_read_poll_value(struct hid_sensor_common *st) > int ret; > > ret = sensor_hub_get_feature(st->hsdev, > - st->poll.report_id, > - st->poll.index, &value); > + st->poll.report_id, > + st->poll.index, sizeof(value), &value); > > if (ret < 0 || value < 0) { > return -EINVAL; > @@ -174,8 +174,8 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st, > int ret; > > ret = sensor_hub_get_feature(st->hsdev, > - st->poll.report_id, > - st->poll.index, &value); > + st->poll.report_id, > + st->poll.index, sizeof(value), &value); > if (ret < 0 || value < 0) { > *val1 = *val2 = 0; > return -EINVAL; > @@ -229,8 +229,9 @@ int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st, > int ret; > > ret = sensor_hub_get_feature(st->hsdev, > - st->sensitivity.report_id, > - st->sensitivity.index, &value); > + st->sensitivity.report_id, > + st->sensitivity.index, sizeof(value), > + &value); > if (ret < 0 || value < 0) { > *val1 = *val2 = 0; > return -EINVAL; > diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > index 92068cd..ef0c495 100644 > --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > @@ -76,8 +76,8 @@ int hid_sensor_power_state(struct hid_sensor_common *st, bool state) > } > > sensor_hub_get_feature(st->hsdev, st->power_state.report_id, > - st->power_state.index, > - &state_val); > + st->power_state.index, > + sizeof(state_val), &state_val); > return 0; > } > EXPORT_SYMBOL(hid_sensor_power_state); > diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h > index 4173a8f..dfdf6ef 100644 > --- a/include/linux/hid-sensor-hub.h > +++ b/include/linux/hid-sensor-hub.h > @@ -179,13 +179,15 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, > * @hsdev: Hub device instance. > * @report_id: Report id to look for > * @field_index: Field index inside a report > -* @value: Place holder for return value > +* @buffer_size: size of the buffer > +* @buffer: buffer to copy output > * > * Used to get a field in feature report. For example this can get polling > -* interval, sensitivity, activate/deactivate state. > +* interval, sensitivity, activate/deactivate state. On success it returns > +* number of bytes copied to buffer. On failure, it returns value < 0. > */ > int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, > - u32 field_index, s32 *value); > + u32 field_index, int buffer_size, void *buffer); > > /* hid-sensor-attributes */ > > ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 1/2] HID: hid-sensor-hub: Enhance get feature report API @ 2015-03-28 20:58 ` Hartmut Knaack 0 siblings, 0 replies; 17+ messages in thread From: Hartmut Knaack @ 2015-03-28 20:58 UTC (permalink / raw) To: Srinivas Pandruvada, jkosina, jic23 Cc: linux-iio, linux-input, borneo.antonio Srinivas Pandruvada schrieb am 17.01.2015 um 01:39: > Some hid sensor feature report can contain more than one reports. > This API can now support receiving multiple values from the feature > report. > Also update the parameters in the users of this API. > Hi Srinivas, I noticed this series got applied already to linux-input. Yet I was wondering if it wouldn't be better to have size variables like buffer_size, report_size and remaining_bytes (from the next patch) defined as unsigned. Also a minor indentation issue spotted inline, in case you get to work on that section again some time. > Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> > --- > drivers/hid/hid-sensor-hub.c | 15 +++++++++++++-- > drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 13 +++++++------ > drivers/iio/common/hid-sensors/hid-sensor-trigger.c | 4 ++-- > include/linux/hid-sensor-hub.h | 8 +++++--- > 4 files changed, 27 insertions(+), 13 deletions(-) > > diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c > index e54ce10..4d22bd4 100644 > --- a/drivers/hid/hid-sensor-hub.c > +++ b/drivers/hid/hid-sensor-hub.c > @@ -232,10 +232,11 @@ done_proc: > EXPORT_SYMBOL_GPL(sensor_hub_set_feature); > > int sensor_hub_get_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); > + int report_size; > int ret = 0; > > mutex_lock(&data->mutex); > @@ -247,7 +248,17 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, > } > hid_hw_request(hsdev->hdev, report, HID_REQ_GET_REPORT); > hid_hw_wait(hsdev->hdev); > - *value = report->field[field_index]->value[0]; > + > + /* calculate number of bytes required to read this field */ > + report_size = DIV_ROUND_UP(report->field[field_index]->report_size, > + 8) * > + report->field[field_index]->report_count; The last line should not be indented with the opening parenthesis any more. What do you think about this solution: report_size = DIV_ROUND_UP(report->field[field_index]->report_size, 8); report_size *= report->field[field_index]->report_count; > + if (!report_size) { > + ret = -EINVAL; > + goto done_proc; > + } > + ret = min(report_size, buffer_size); > + memcpy(buffer, report->field[field_index]->value, ret); > > done_proc: > mutex_unlock(&data->mutex); > diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > index 25b01e1..e1435e9 100644 > --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > @@ -153,8 +153,8 @@ s32 hid_sensor_read_poll_value(struct hid_sensor_common *st) > int ret; > > ret = sensor_hub_get_feature(st->hsdev, > - st->poll.report_id, > - st->poll.index, &value); > + st->poll.report_id, > + st->poll.index, sizeof(value), &value); > > if (ret < 0 || value < 0) { > return -EINVAL; > @@ -174,8 +174,8 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st, > int ret; > > ret = sensor_hub_get_feature(st->hsdev, > - st->poll.report_id, > - st->poll.index, &value); > + st->poll.report_id, > + st->poll.index, sizeof(value), &value); > if (ret < 0 || value < 0) { > *val1 = *val2 = 0; > return -EINVAL; > @@ -229,8 +229,9 @@ int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st, > int ret; > > ret = sensor_hub_get_feature(st->hsdev, > - st->sensitivity.report_id, > - st->sensitivity.index, &value); > + st->sensitivity.report_id, > + st->sensitivity.index, sizeof(value), > + &value); > if (ret < 0 || value < 0) { > *val1 = *val2 = 0; > return -EINVAL; > diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > index 92068cd..ef0c495 100644 > --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > @@ -76,8 +76,8 @@ int hid_sensor_power_state(struct hid_sensor_common *st, bool state) > } > > sensor_hub_get_feature(st->hsdev, st->power_state.report_id, > - st->power_state.index, > - &state_val); > + st->power_state.index, > + sizeof(state_val), &state_val); > return 0; > } > EXPORT_SYMBOL(hid_sensor_power_state); > diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h > index 4173a8f..dfdf6ef 100644 > --- a/include/linux/hid-sensor-hub.h > +++ b/include/linux/hid-sensor-hub.h > @@ -179,13 +179,15 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, > * @hsdev: Hub device instance. > * @report_id: Report id to look for > * @field_index: Field index inside a report > -* @value: Place holder for return value > +* @buffer_size: size of the buffer > +* @buffer: buffer to copy output > * > * Used to get a field in feature report. For example this can get polling > -* interval, sensitivity, activate/deactivate state. > +* interval, sensitivity, activate/deactivate state. On success it returns > +* number of bytes copied to buffer. On failure, it returns value < 0. > */ > int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, > - u32 field_index, s32 *value); > + u32 field_index, int buffer_size, void *buffer); > > /* hid-sensor-attributes */ > > ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 1/2] HID: hid-sensor-hub: Enhance get feature report API 2015-03-28 20:58 ` Hartmut Knaack (?) @ 2015-03-30 19:56 ` Srinivas Pandruvada -1 siblings, 0 replies; 17+ messages in thread From: Srinivas Pandruvada @ 2015-03-30 19:56 UTC (permalink / raw) To: Hartmut Knaack; +Cc: jkosina, jic23, linux-iio, linux-input, borneo.antonio On Sat, 2015-03-28 at 21:58 +0100, Hartmut Knaack wrote: > Srinivas Pandruvada schrieb am 17.01.2015 um 01:39: > > Some hid sensor feature report can contain more than one reports. > > This API can now support receiving multiple values from the feature > > report. > > Also update the parameters in the users of this API. > > Hi Hartmut, > Hi Srinivas, > I noticed this series got applied already to linux-input. Yet I was wondering > if it wouldn't be better to have size variables like buffer_size, report_size > and remaining_bytes (from the next patch) defined as unsigned. > Also a minor indentation issue spotted inline, in case you get to work on that > section again some time. > This module will go further enhancements soon, then I will take care of this. Thanks, Srinivas > > Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> > > --- > > drivers/hid/hid-sensor-hub.c | 15 +++++++++++++-- > > drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 13 +++++++------ > > drivers/iio/common/hid-sensors/hid-sensor-trigger.c | 4 ++-- > > include/linux/hid-sensor-hub.h | 8 +++++--- > > 4 files changed, 27 insertions(+), 13 deletions(-) > > > > diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c > > index e54ce10..4d22bd4 100644 > > --- a/drivers/hid/hid-sensor-hub.c > > +++ b/drivers/hid/hid-sensor-hub.c > > @@ -232,10 +232,11 @@ done_proc: > > EXPORT_SYMBOL_GPL(sensor_hub_set_feature); > > > > int sensor_hub_get_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); > > + int report_size; > > int ret = 0; > > > > mutex_lock(&data->mutex); > > @@ -247,7 +248,17 @@ int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, > > } > > hid_hw_request(hsdev->hdev, report, HID_REQ_GET_REPORT); > > hid_hw_wait(hsdev->hdev); > > - *value = report->field[field_index]->value[0]; > > + > > + /* calculate number of bytes required to read this field */ > > + report_size = DIV_ROUND_UP(report->field[field_index]->report_size, > > + 8) * > > + report->field[field_index]->report_count; > The last line should not be indented with the opening parenthesis any more. > What do you think about this solution: > > report_size = DIV_ROUND_UP(report->field[field_index]->report_size, 8); > report_size *= report->field[field_index]->report_count; > > > + if (!report_size) { > > + ret = -EINVAL; > > + goto done_proc; > > + } > > + ret = min(report_size, buffer_size); > > + memcpy(buffer, report->field[field_index]->value, ret); > > > > done_proc: > > mutex_unlock(&data->mutex); > > diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > > index 25b01e1..e1435e9 100644 > > --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > > +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > > @@ -153,8 +153,8 @@ s32 hid_sensor_read_poll_value(struct hid_sensor_common *st) > > int ret; > > > > ret = sensor_hub_get_feature(st->hsdev, > > - st->poll.report_id, > > - st->poll.index, &value); > > + st->poll.report_id, > > + st->poll.index, sizeof(value), &value); > > > > if (ret < 0 || value < 0) { > > return -EINVAL; > > @@ -174,8 +174,8 @@ int hid_sensor_read_samp_freq_value(struct hid_sensor_common *st, > > int ret; > > > > ret = sensor_hub_get_feature(st->hsdev, > > - st->poll.report_id, > > - st->poll.index, &value); > > + st->poll.report_id, > > + st->poll.index, sizeof(value), &value); > > if (ret < 0 || value < 0) { > > *val1 = *val2 = 0; > > return -EINVAL; > > @@ -229,8 +229,9 @@ int hid_sensor_read_raw_hyst_value(struct hid_sensor_common *st, > > int ret; > > > > ret = sensor_hub_get_feature(st->hsdev, > > - st->sensitivity.report_id, > > - st->sensitivity.index, &value); > > + st->sensitivity.report_id, > > + st->sensitivity.index, sizeof(value), > > + &value); > > if (ret < 0 || value < 0) { > > *val1 = *val2 = 0; > > return -EINVAL; > > diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > > index 92068cd..ef0c495 100644 > > --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > > +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > > @@ -76,8 +76,8 @@ int hid_sensor_power_state(struct hid_sensor_common *st, bool state) > > } > > > > sensor_hub_get_feature(st->hsdev, st->power_state.report_id, > > - st->power_state.index, > > - &state_val); > > + st->power_state.index, > > + sizeof(state_val), &state_val); > > return 0; > > } > > EXPORT_SYMBOL(hid_sensor_power_state); > > diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h > > index 4173a8f..dfdf6ef 100644 > > --- a/include/linux/hid-sensor-hub.h > > +++ b/include/linux/hid-sensor-hub.h > > @@ -179,13 +179,15 @@ int sensor_hub_set_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, > > * @hsdev: Hub device instance. > > * @report_id: Report id to look for > > * @field_index: Field index inside a report > > -* @value: Place holder for return value > > +* @buffer_size: size of the buffer > > +* @buffer: buffer to copy output > > * > > * Used to get a field in feature report. For example this can get polling > > -* interval, sensitivity, activate/deactivate state. > > +* interval, sensitivity, activate/deactivate state. On success it returns > > +* number of bytes copied to buffer. On failure, it returns value < 0. > > */ > > int sensor_hub_get_feature(struct hid_sensor_hub_device *hsdev, u32 report_id, > > - u32 field_index, s32 *value); > > + u32 field_index, int buffer_size, void *buffer); > > > > /* hid-sensor-attributes */ > > > > > ^ permalink raw reply [flat|nested] 17+ messages in thread
* [PATCH v2 2/2] HID: hid-sensor-hub: Enhance feature report set API 2015-01-17 0:39 ` Srinivas Pandruvada @ 2015-01-17 0:39 ` Srinivas Pandruvada -1 siblings, 0 replies; 17+ messages in thread From: Srinivas Pandruvada @ 2015-01-17 0:39 UTC (permalink / raw) To: jkosina-AlSwsSmVLrQ, jic23-DgEjT+Ai2ygdnm+yROfE0A Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA, linux-input-u79uwXL29TY76Z2rM5mHXA, borneo.antonio-Re5JQEeQqe8AvxtiuMwx3w, Srinivas Pandruvada 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-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> --- drivers/hid/hid-sensor-hub.c | 22 ++++++++++++++++++++-- .../iio/common/hid-sensors/hid-sensor-attributes.c | 11 +++++------ .../iio/common/hid-sensors/hid-sensor-trigger.c | 9 +++++---- include/linux/hid-sensor-hub.h | 5 +++-- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c index 4d22bd4..7de9d53 100644 --- a/drivers/hid/hid-sensor-hub.c +++ b/drivers/hid/hid-sensor-hub.c @@ -208,10 +208,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 = (__s32 *)buffer; + int i = 0; + int remaining_bytes; + __s32 value; int ret = 0; mutex_lock(&data->mutex); @@ -220,7 +224,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); diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c index e1435e9..e81f434 100644 --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c @@ -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; diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c index ef0c495..910e82a 100644 --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c @@ -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, diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h index dfdf6ef..e899c67 100644 --- a/include/linux/hid-sensor-hub.h +++ b/include/linux/hid-sensor-hub.h @@ -166,13 +166,14 @@ int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev, * @hsdev: Hub device instance. * @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 -- 1.9.1 ^ permalink raw reply related [flat|nested] 17+ messages in thread
* [PATCH v2 2/2] HID: hid-sensor-hub: Enhance feature report set API @ 2015-01-17 0:39 ` Srinivas Pandruvada 0 siblings, 0 replies; 17+ messages in thread From: Srinivas Pandruvada @ 2015-01-17 0:39 UTC (permalink / raw) To: jkosina, jic23 Cc: linux-iio, linux-input, borneo.antonio, Srinivas Pandruvada 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> --- drivers/hid/hid-sensor-hub.c | 22 ++++++++++++++++++++-- .../iio/common/hid-sensors/hid-sensor-attributes.c | 11 +++++------ .../iio/common/hid-sensors/hid-sensor-trigger.c | 9 +++++---- include/linux/hid-sensor-hub.h | 5 +++-- 4 files changed, 33 insertions(+), 14 deletions(-) diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c index 4d22bd4..7de9d53 100644 --- a/drivers/hid/hid-sensor-hub.c +++ b/drivers/hid/hid-sensor-hub.c @@ -208,10 +208,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 = (__s32 *)buffer; + int i = 0; + int remaining_bytes; + __s32 value; int ret = 0; mutex_lock(&data->mutex); @@ -220,7 +224,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); diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c index e1435e9..e81f434 100644 --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c @@ -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; diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c index ef0c495..910e82a 100644 --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c @@ -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, diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h index dfdf6ef..e899c67 100644 --- a/include/linux/hid-sensor-hub.h +++ b/include/linux/hid-sensor-hub.h @@ -166,13 +166,14 @@ int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev, * @hsdev: Hub device instance. * @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 -- 1.9.1 ^ permalink raw reply related [flat|nested] 17+ messages in thread
[parent not found: <1421455165-3944-3-git-send-email-srinivas.pandruvada-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>]
* Re: [PATCH v2 2/2] HID: hid-sensor-hub: Enhance feature report set API 2015-01-17 0:39 ` Srinivas Pandruvada @ 2015-02-01 10:36 ` Jonathan Cameron -1 siblings, 0 replies; 17+ messages in thread From: Jonathan Cameron @ 2015-02-01 10:36 UTC (permalink / raw) To: Srinivas Pandruvada, jkosina-AlSwsSmVLrQ Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA, linux-input-u79uwXL29TY76Z2rM5mHXA, borneo.antonio-Re5JQEeQqe8AvxtiuMwx3w On 17/01/15 00:39, Srinivas Pandruvada wrote: > 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-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> With the unnecessary cast below dropped. Reviewed-by: Jonathan Cameron <jic23-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> > --- > drivers/hid/hid-sensor-hub.c | 22 ++++++++++++++++++++-- > .../iio/common/hid-sensors/hid-sensor-attributes.c | 11 +++++------ > .../iio/common/hid-sensors/hid-sensor-trigger.c | 9 +++++---- > include/linux/hid-sensor-hub.h | 5 +++-- > 4 files changed, 33 insertions(+), 14 deletions(-) > > diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c > index 4d22bd4..7de9d53 100644 > --- a/drivers/hid/hid-sensor-hub.c > +++ b/drivers/hid/hid-sensor-hub.c > @@ -208,10 +208,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 = (__s32 *)buffer; Unnecessary cast given it is coming from a void * > + int i = 0; > + int remaining_bytes; > + __s32 value; > int ret = 0; > > mutex_lock(&data->mutex); > @@ -220,7 +224,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); > > diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > index e1435e9..e81f434 100644 > --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > @@ -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; > > diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > index ef0c495..910e82a 100644 > --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > @@ -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, > diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h > index dfdf6ef..e899c67 100644 > --- a/include/linux/hid-sensor-hub.h > +++ b/include/linux/hid-sensor-hub.h > @@ -166,13 +166,14 @@ int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev, > * @hsdev: Hub device instance. > * @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 > ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 2/2] HID: hid-sensor-hub: Enhance feature report set API @ 2015-02-01 10:36 ` Jonathan Cameron 0 siblings, 0 replies; 17+ messages in thread From: Jonathan Cameron @ 2015-02-01 10:36 UTC (permalink / raw) To: Srinivas Pandruvada, jkosina; +Cc: linux-iio, linux-input, borneo.antonio On 17/01/15 00:39, Srinivas Pandruvada wrote: > 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> With the unnecessary cast below dropped. Reviewed-by: Jonathan Cameron <jic23@kernel.org> > --- > drivers/hid/hid-sensor-hub.c | 22 ++++++++++++++++++++-- > .../iio/common/hid-sensors/hid-sensor-attributes.c | 11 +++++------ > .../iio/common/hid-sensors/hid-sensor-trigger.c | 9 +++++---- > include/linux/hid-sensor-hub.h | 5 +++-- > 4 files changed, 33 insertions(+), 14 deletions(-) > > diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c > index 4d22bd4..7de9d53 100644 > --- a/drivers/hid/hid-sensor-hub.c > +++ b/drivers/hid/hid-sensor-hub.c > @@ -208,10 +208,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 = (__s32 *)buffer; Unnecessary cast given it is coming from a void * > + int i = 0; > + int remaining_bytes; > + __s32 value; > int ret = 0; > > mutex_lock(&data->mutex); > @@ -220,7 +224,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); > > diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > index e1435e9..e81f434 100644 > --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > @@ -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; > > diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > index ef0c495..910e82a 100644 > --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > @@ -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, > diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h > index dfdf6ef..e899c67 100644 > --- a/include/linux/hid-sensor-hub.h > +++ b/include/linux/hid-sensor-hub.h > @@ -166,13 +166,14 @@ int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev, > * @hsdev: Hub device instance. > * @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 > ^ permalink raw reply [flat|nested] 17+ messages in thread
[parent not found: <54CE01BA.8070201-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>]
* Re: [PATCH v2 2/2] HID: hid-sensor-hub: Enhance feature report set API 2015-02-01 10:36 ` Jonathan Cameron @ 2015-02-19 23:37 ` Srinivas Pandruvada -1 siblings, 0 replies; 17+ messages in thread From: Srinivas Pandruvada @ 2015-02-19 23:37 UTC (permalink / raw) To: Jonathan Cameron Cc: jkosina-AlSwsSmVLrQ, linux-iio-u79uwXL29TY76Z2rM5mHXA, linux-input-u79uwXL29TY76Z2rM5mHXA, borneo.antonio-Re5JQEeQqe8AvxtiuMwx3w On Sun, 2015-02-01 at 10:36 +0000, Jonathan Cameron wrote: > On 17/01/15 00:39, Srinivas Pandruvada wrote: > > 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-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> > With the unnecessary cast below dropped. Submitted new version with the suggested change. Thanks, Srinivas > > Reviewed-by: Jonathan Cameron <jic23-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> > > --- > > drivers/hid/hid-sensor-hub.c | 22 ++++++++++++++++++++-- > > .../iio/common/hid-sensors/hid-sensor-attributes.c | 11 +++++------ > > .../iio/common/hid-sensors/hid-sensor-trigger.c | 9 +++++---- > > include/linux/hid-sensor-hub.h | 5 +++-- > > 4 files changed, 33 insertions(+), 14 deletions(-) > > > > diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c > > index 4d22bd4..7de9d53 100644 > > --- a/drivers/hid/hid-sensor-hub.c > > +++ b/drivers/hid/hid-sensor-hub.c > > @@ -208,10 +208,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 = (__s32 *)buffer; > Unnecessary cast given it is coming from a void * > > + int i = 0; > > + int remaining_bytes; > > + __s32 value; > > int ret = 0; > > > > mutex_lock(&data->mutex); > > @@ -220,7 +224,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); > > > > diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > > index e1435e9..e81f434 100644 > > --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > > +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > > @@ -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; > > > > diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > > index ef0c495..910e82a 100644 > > --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > > +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > > @@ -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, > > diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h > > index dfdf6ef..e899c67 100644 > > --- a/include/linux/hid-sensor-hub.h > > +++ b/include/linux/hid-sensor-hub.h > > @@ -166,13 +166,14 @@ int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev, > > * @hsdev: Hub device instance. > > * @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 > > > ^ permalink raw reply [flat|nested] 17+ messages in thread
* Re: [PATCH v2 2/2] HID: hid-sensor-hub: Enhance feature report set API @ 2015-02-19 23:37 ` Srinivas Pandruvada 0 siblings, 0 replies; 17+ messages in thread From: Srinivas Pandruvada @ 2015-02-19 23:37 UTC (permalink / raw) To: Jonathan Cameron; +Cc: jkosina, linux-iio, linux-input, borneo.antonio On Sun, 2015-02-01 at 10:36 +0000, Jonathan Cameron wrote: > On 17/01/15 00:39, Srinivas Pandruvada wrote: > > 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> > With the unnecessary cast below dropped. Submitted new version with the suggested change. Thanks, Srinivas > > Reviewed-by: Jonathan Cameron <jic23@kernel.org> > > --- > > drivers/hid/hid-sensor-hub.c | 22 ++++++++++++++++++++-- > > .../iio/common/hid-sensors/hid-sensor-attributes.c | 11 +++++------ > > .../iio/common/hid-sensors/hid-sensor-trigger.c | 9 +++++---- > > include/linux/hid-sensor-hub.h | 5 +++-- > > 4 files changed, 33 insertions(+), 14 deletions(-) > > > > diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c > > index 4d22bd4..7de9d53 100644 > > --- a/drivers/hid/hid-sensor-hub.c > > +++ b/drivers/hid/hid-sensor-hub.c > > @@ -208,10 +208,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 = (__s32 *)buffer; > Unnecessary cast given it is coming from a void * > > + int i = 0; > > + int remaining_bytes; > > + __s32 value; > > int ret = 0; > > > > mutex_lock(&data->mutex); > > @@ -220,7 +224,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); > > > > diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > > index e1435e9..e81f434 100644 > > --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > > +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c > > @@ -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; > > > > diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > > index ef0c495..910e82a 100644 > > --- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > > +++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c > > @@ -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, > > diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h > > index dfdf6ef..e899c67 100644 > > --- a/include/linux/hid-sensor-hub.h > > +++ b/include/linux/hid-sensor-hub.h > > @@ -166,13 +166,14 @@ int sensor_hub_input_attr_get_raw_value(struct hid_sensor_hub_device *hsdev, > > * @hsdev: Hub device instance. > > * @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 > > > ^ permalink raw reply [flat|nested] 17+ messages in thread
end of thread, other threads:[~2015-03-30 20:00 UTC | newest] Thread overview: 17+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2015-01-17 0:39 [PATCH v2 0/2] hid: sensor-hub: Enhance feature report APIs Srinivas Pandruvada 2015-01-17 0:39 ` Srinivas Pandruvada [not found] ` <1421455165-3944-1-git-send-email-srinivas.pandruvada-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> 2015-01-17 0:39 ` [PATCH v2 1/2] HID: hid-sensor-hub: Enhance get feature report API Srinivas Pandruvada 2015-01-17 0:39 ` Srinivas Pandruvada 2015-02-01 10:35 ` Jonathan Cameron [not found] ` <54CE018F.9010600-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> 2015-02-17 12:39 ` Jiri Kosina 2015-02-17 12:39 ` Jiri Kosina 2015-02-17 16:18 ` Srinivas Pandruvada [not found] ` <1421455165-3944-2-git-send-email-srinivas.pandruvada-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> 2015-03-28 20:58 ` Hartmut Knaack 2015-03-28 20:58 ` Hartmut Knaack 2015-03-30 19:56 ` Srinivas Pandruvada 2015-01-17 0:39 ` [PATCH v2 2/2] HID: hid-sensor-hub: Enhance feature report set API Srinivas Pandruvada 2015-01-17 0:39 ` Srinivas Pandruvada [not found] ` <1421455165-3944-3-git-send-email-srinivas.pandruvada-VuQAYsv1563Yd54FQh9/CA@public.gmane.org> 2015-02-01 10:36 ` Jonathan Cameron 2015-02-01 10:36 ` Jonathan Cameron [not found] ` <54CE01BA.8070201-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org> 2015-02-19 23:37 ` Srinivas Pandruvada 2015-02-19 23:37 ` Srinivas Pandruvada
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.