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] HID: hid-sensor-hub: Add collection device
Date: Tue,  6 Jan 2015 16:58:48 -0800	[thread overview]
Message-ID: <1420592328-9942-25-git-send-email-srinivas.pandruvada@linux.intel.com> (raw)
In-Reply-To: <1420592328-9942-1-git-send-email-srinivas.pandruvada@linux.intel.com>

HID sensor hub exports several sensor which are fusion sensors, where
data is interpreted from one or more sensors. Some of them can't be
exported via IIO like sysfs as the user space download some firmware,
which defines what sensor will look like. They can be a part of a
collection.
Creating a MFD cell for a collection to write a standalone driver
to manage collections. Most of the time they will be propritery drivers
may not be even upstreamed. This patch allows framework to have
capability to write such drivers.

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

diff --git a/drivers/hid/hid-sensor-hub.c b/drivers/hid/hid-sensor-hub.c
index 84290e5..7403b25 100644
--- a/drivers/hid/hid-sensor-hub.c
+++ b/drivers/hid/hid-sensor-hub.c
@@ -119,11 +119,12 @@ static struct hid_sensor_hub_callbacks *sensor_hub_get_callback(
 
 	spin_lock_irqsave(&pdata->dyn_callback_lock, flags);
 	list_for_each_entry(callback, &pdata->dyn_callback_list, list)
-		if (callback->usage_id == usage_id &&
+		if (callback->usage_id == HID_USAGE_SENSOR_TYPE_COLLECTION ||
+			(callback->usage_id == usage_id &&
 			(collection_index >=
 				callback->hsdev->start_collection_index) &&
 			(collection_index <
-				callback->hsdev->end_collection_index)) {
+				callback->hsdev->end_collection_index))) {
 			*priv = callback->priv;
 			*hsdev = callback->hsdev;
 			spin_unlock_irqrestore(&pdata->dyn_callback_lock,
@@ -159,7 +160,12 @@ int sensor_hub_register_callback(struct hid_sensor_hub_device *hsdev,
 	callback->usage_callback = usage_callback;
 	callback->usage_id = usage_id;
 	callback->priv = NULL;
-	list_add_tail(&callback->list, &pdata->dyn_callback_list);
+	/* Give higher priority to collection device, so add to front */
+	if (usage_id == HID_USAGE_SENSOR_TYPE_COLLECTION)
+		list_add(&callback->list, &pdata->dyn_callback_list);
+	else
+		list_add_tail(&callback->list, &pdata->dyn_callback_list);
+
 	spin_unlock_irqrestore(&pdata->dyn_callback_lock, flags);
 
 	return 0;
@@ -590,6 +596,37 @@ static __u8 *sensor_hub_report_fixup(struct hid_device *hdev, __u8 *rdesc,
 	return rdesc;
 }
 
+static int sensor_hub_add_collection_device(struct hid_device *hdev,
+					    struct sensor_hub_data *sd)
+{
+	struct hid_sensor_hub_device *hsdev;
+	char *name;
+
+	hsdev = devm_kzalloc(&hdev->dev, sizeof(*hsdev), GFP_KERNEL);
+	if (!hsdev)
+		return -ENOMEM;
+
+	hsdev->hdev = hdev;
+	hsdev->vendor_id = hdev->vendor;
+	hsdev->product_id = hdev->product;
+	hsdev->usage = HID_USAGE_SENSOR_TYPE_COLLECTION;
+	mutex_init(&hsdev->mutex);
+	name = devm_kasprintf(&hdev->dev, GFP_KERNEL, "HID-SENSOR-%x",
+			      HID_USAGE_SENSOR_TYPE_COLLECTION);
+	if (name == NULL) {
+		hid_err(hdev, "Failed MFD device name\n");
+		return -ENOMEM;
+	}
+	sd->hid_sensor_hub_client_devs[sd->hid_sensor_client_cnt].name = name;
+	sd->hid_sensor_hub_client_devs[
+			sd->hid_sensor_client_cnt].platform_data = hsdev;
+	sd->hid_sensor_hub_client_devs[
+			sd->hid_sensor_client_cnt].pdata_size = sizeof(*hsdev);
+	sd->hid_sensor_client_cnt++;
+
+	return 0;
+}
+
 static int sensor_hub_probe(struct hid_device *hdev,
 				const struct hid_device_id *id)
 {
@@ -634,7 +671,8 @@ static int sensor_hub_probe(struct hid_device *hdev,
 		ret = -EINVAL;
 		goto err_stop_hw;
 	}
-	sd->hid_sensor_hub_client_devs = devm_kzalloc(&hdev->dev, dev_cnt *
+	sd->hid_sensor_hub_client_devs = devm_kzalloc(&hdev->dev,
+						      (dev_cnt + 1) *
 						      sizeof(struct mfd_cell),
 						      GFP_KERNEL);
 	if (sd->hid_sensor_hub_client_devs == NULL) {
@@ -688,6 +726,10 @@ static int sensor_hub_probe(struct hid_device *hdev,
 	if (last_hsdev)
 		last_hsdev->end_collection_index = i;
 
+	ret = sensor_hub_add_collection_device(hdev, sd);
+	if (ret)
+		goto err_stop_hw;
+
 	ret = mfd_add_hotplug_devices(&hdev->dev,
 			sd->hid_sensor_hub_client_devs,
 			sd->hid_sensor_client_cnt);
diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h
index 109f0e6..300ffea 100644
--- a/include/linux/hid-sensor-ids.h
+++ b/include/linux/hid-sensor-ids.h
@@ -21,6 +21,8 @@
 
 #define HID_MAX_PHY_DEVICES					0xFF
 
+#define HID_USAGE_SENSOR_TYPE_COLLECTION			0x200001
+
 /* Accel 3D (200073) */
 #define HID_USAGE_SENSOR_ACCEL_3D				0x200073
 #define HID_USAGE_SENSOR_DATA_ACCELERATION			0x200452
-- 
1.9.1


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

Thread overview: 29+ 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 ` [PATCH 1/4] HID: hid-sensor-hub: Enhance feature report API 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 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
2015-01-07  0:58 ` [PATCH 8/9] iio: hid-sensor-press: " 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 ` Srinivas Pandruvada [this message]
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

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-25-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).