linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
To: jkosina@suse.cz, jic23@kernel.org
Cc: linux-iio@vger.kernel.org, linux-input@vger.kernel.org,
	Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Subject: [PATCH 1/4] HID: hid-sensor-hub: Enhance feature report API
Date: Tue,  6 Jan 2015 16:58:26 -0800	[thread overview]
Message-ID: <1420592328-9942-3-git-send-email-srinivas.pandruvada@linux.intel.com> (raw)
In-Reply-To: <1420592328-9942-1-git-send-email-srinivas.pandruvada@linux.intel.com>

Some hid sensor feature report can contain more than one reports.
This API can now support receiving multiple values from the feature
report.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/hid/hid-sensor-hub.c   | 16 ++++++++++++++--
 include/linux/hid-sensor-hub.h |  8 +++++---
 2 files changed, 19 insertions(+), 5 deletions(-)

diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
index e54ce10..0ad5813 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,18 @@ 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 = report->field[field_index]->report_size / 8;
+	if (report->field[field_index]->report_size % 8)
+		++report_size;
+	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/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


  parent reply	other threads:[~2015-01-07  0:59 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-01-07  0:58 [PATCH] HID: hid-sensor-hub: Correct documentation Srinivas Pandruvada
2015-01-07  0:58 ` [PATCH] HID: sensor-hub: correct dyn_callback_lock IRQ-safe change Srinivas Pandruvada
2015-01-07  0:58 ` Srinivas Pandruvada [this message]
2015-01-07  0:58 ` [PATCH 3/4] HID: hid-sensor-hub: Enhance feature report set API Srinivas Pandruvada
2015-01-07  0:58 ` [PATCH 4/4] iio: hid_sensor_hub: update parameters to set feature report Srinivas Pandruvada
2015-01-07  0:58 ` [PATCH 1/9] HID: hid-sensor-hub: Extend API for async reads Srinivas Pandruvada
2015-01-07  0:58 ` [PATCH 5/9] iio: hid-sensor-prox: Adjust parameter for attribute read Srinivas Pandruvada
     [not found] ` <1420592328-9942-1-git-send-email-srinivas.pandruvada-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2015-01-07  0:58   ` [PATCH 2/4] iio: hid_sensor_hub: update parameters to get feature report Srinivas Pandruvada
2015-01-07  0:58   ` [PATCH] HID: hid-sensor-hub: Allow parallel synchronous reads Srinivas Pandruvada
2015-01-07  0:58   ` [PATCH 2/9] iio: hid-sensor-accel-3d: Adjust parameter for attribute read Srinivas Pandruvada
2015-01-07  0:58   ` [PATCH 3/9] iio: hid-sensor-gyro-3d: " Srinivas Pandruvada
2015-01-07  0:58   ` [PATCH 4/9] iio: hid-sensor-als: " Srinivas Pandruvada
2015-01-07  0:58   ` [PATCH 6/9] iio: hid-sensor-magn-3d: " Srinivas Pandruvada
2015-01-07  0:58   ` [PATCH 7/9] iio: hid-sensor-incl-3d: " Srinivas Pandruvada
2015-01-07  0:58   ` [PATCH 2/8] iio: hid-sensor-accel-3d: Introduce PM Srinivas Pandruvada
2015-01-07  0:58 ` [PATCH 8/9] iio: hid-sensor-press: Adjust parameter for attribute read Srinivas Pandruvada
2015-01-07  0:58 ` [PATCH 9/9] drivers/rtc/rtc-hid-sensor-time.c: " Srinivas Pandruvada
2015-01-07  0:58 ` [PATCH 1/8] iio: hid_sensor_hub: Common PM functions Srinivas Pandruvada
2015-01-07  0:58 ` [PATCH 3/8] iio: hid-sensor-gyro-3d: Introduce PM Srinivas Pandruvada
2015-01-07  0:58 ` [PATCH 4/8] iio: hid-sensor-als: " Srinivas Pandruvada
2015-01-07  0:58 ` [PATCH 5/8] iio: hid-sensor-prox: " Srinivas Pandruvada
2015-01-07  0:58 ` [PATCH 6/8] iio: hid-sensor-magn-3d: " Srinivas Pandruvada
2015-01-07  0:58 ` [PATCH 7/8] iio: hid-sensor-incl-3d: " Srinivas Pandruvada
2015-01-07  0:58 ` [PATCH 8/8] iio: hid-sensor-press: " Srinivas Pandruvada
2015-01-07  0:58 ` [PATCH] HID: hid-sensor-hub: Add collection device Srinivas Pandruvada
2015-01-07  8:48 ` [PATCH] HID: hid-sensor-hub: Correct documentation Jiri Kosina
     [not found]   ` <alpine.LNX.2.00.1501070946540.25732-ztGlSCb7Y1iN3ZZ/Hiejyg@public.gmane.org>
2015-01-07 16:01     ` Srinivas Pandruvada
     [not found]       ` <1420646463.4459.126.camel-hINH/TbAiWppyMZ9rn1DP+ejPoqOX1/hEvhb3Hwu1Ks@public.gmane.org>
2015-01-07 16:27         ` Jiri Kosina
     [not found]           ` <alpine.LNX.2.00.1501071718240.25732-ztGlSCb7Y1iN3ZZ/Hiejyg@public.gmane.org>
2015-01-07 16:35             ` Srinivas Pandruvada
  -- strict thread matches above, loose matches on Subject: below --
2015-01-07 18:31 [PATCH 0/4] Enhance feature report APIs Srinivas Pandruvada
     [not found] ` <1420655508-6736-1-git-send-email-srinivas.pandruvada-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2015-01-07 18:31   ` [PATCH 1/4] HID: hid-sensor-hub: Enhance feature report API Srinivas Pandruvada

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1420592328-9942-3-git-send-email-srinivas.pandruvada@linux.intel.com \
    --to=srinivas.pandruvada@linux.intel.com \
    --cc=jic23@kernel.org \
    --cc=jkosina@suse.cz \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-input@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).