linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH, 0/7] HID Sensor Driver
@ 2012-06-06 15:39 srinivas pandruvada
       [not found] ` <1338997164-5077-1-git-send-email-srinivas.pandruvada-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
                   ` (4 more replies)
  0 siblings, 5 replies; 16+ messages in thread
From: srinivas pandruvada @ 2012-06-06 15:39 UTC (permalink / raw)
  To: linux-input-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA, srinivas pandruvada

This submits a set of patches to enable USB HID Sensor driver.
It is implemented as a HID driver and exports sensor interface
via Linux IIO interfaces. This implements a basic usage id processing
for Accelerometer 3D, Gyro 3D, Magnetometer 3D and ALS.

Srinivas pandruvada (5):
  HID-Sensors: Common attributes and interfaces
  HID-Sensors: Added accelerometer 3D
  HID-Sensors: Added Gyro 3D
  HID-Sensors: Added Compass 3D
  HID-Sensors: Added ALS

srinivas pandruvada (2):
  HID-Sensors: Add Intel HID sensor
  HID-Sensors: Sensor framework

 drivers/hid/hid-core.c                             |    6 +
 drivers/hid/hid-ids.h                              |    5 +
 drivers/staging/Kconfig                            |    2 +
 drivers/staging/Makefile                           |    1 +
 drivers/staging/hid-sensors/Kconfig                |   19 +
 drivers/staging/hid-sensors/Makefile               |   16 +
 drivers/staging/hid-sensors/hid-sensor-accel-3d.c  |  387 +++++++++++
 drivers/staging/hid-sensors/hid-sensor-als.c       |  326 +++++++++
 .../staging/hid-sensors/hid-sensor-attributes.c    |  203 ++++++
 .../staging/hid-sensors/hid-sensor-attributes.h    |   67 ++
 .../staging/hid-sensors/hid-sensor-compass-3d.c    |  385 +++++++++++
 drivers/staging/hid-sensors/hid-sensor-gyro-3d.c   |  384 +++++++++++
 drivers/staging/hid-sensors/hid-sensor-hub.c       |  709 ++++++++++++++++++++
 drivers/staging/hid-sensors/hid-sensor-ids.h       |  117 ++++
 drivers/staging/hid-sensors/hid-sensor-interface.h |   93 +++
 drivers/staging/hid-sensors/hid-sensor-ring.c      |  104 +++
 drivers/staging/hid-sensors/hid-sensor-trigger.c   |   81 +++
 17 files changed, 2905 insertions(+), 0 deletions(-)
 create mode 100644 drivers/staging/hid-sensors/Kconfig
 create mode 100644 drivers/staging/hid-sensors/Makefile
 create mode 100644 drivers/staging/hid-sensors/hid-sensor-accel-3d.c
 create mode 100644 drivers/staging/hid-sensors/hid-sensor-als.c
 create mode 100644 drivers/staging/hid-sensors/hid-sensor-attributes.c
 create mode 100644 drivers/staging/hid-sensors/hid-sensor-attributes.h
 create mode 100644 drivers/staging/hid-sensors/hid-sensor-compass-3d.c
 create mode 100644 drivers/staging/hid-sensors/hid-sensor-gyro-3d.c
 create mode 100644 drivers/staging/hid-sensors/hid-sensor-hub.c
 create mode 100644 drivers/staging/hid-sensors/hid-sensor-ids.h
 create mode 100644 drivers/staging/hid-sensors/hid-sensor-interface.h
 create mode 100644 drivers/staging/hid-sensors/hid-sensor-ring.c
 create mode 100644 drivers/staging/hid-sensors/hid-sensor-trigger.c

-- 
1.7.7.6

^ permalink raw reply	[flat|nested] 16+ messages in thread

* [PATCH, 1/7] HID-Sensors: Add Intel HID sensor
       [not found] ` <1338997164-5077-1-git-send-email-srinivas.pandruvada-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
@ 2012-06-06 15:39   ` srinivas pandruvada
  2012-06-06 15:39   ` [PATCH, 2/7] HID-Sensors: Sensor framework srinivas pandruvada
  2012-06-06 15:39   ` [PATCH, 3/7] HID-Sensors: Common attributes and interfaces srinivas pandruvada
  2 siblings, 0 replies; 16+ messages in thread
From: srinivas pandruvada @ 2012-06-06 15:39 UTC (permalink / raw)
  To: linux-input-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA, srinivas pandruvada

Added Intel vendor id/product id and added in the list
for ignoring Intel vendor id/product id for HID.

Signed-off-by: srinivas pandruvada <srinivas.pandruvada-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
 drivers/hid/hid-core.c |    6 ++++++
 drivers/hid/hid-ids.h  |    5 +++++
 2 files changed, 11 insertions(+), 0 deletions(-)

diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
index f160aab..fad31c5 100644
--- a/drivers/hid/hid-core.c
+++ b/drivers/hid/hid-core.c
@@ -1444,6 +1444,12 @@ static const struct hid_device_id hid_have_special_driver[] = {
  	{ HID_USB_DEVICE(USB_VENDOR_ID_IDEACOM, USB_DEVICE_ID_IDEACOM_IDC6650) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_HOLTEK, USB_DEVICE_ID_HOLTEK_ON_LINE_GRIP) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_ILITEK, USB_DEVICE_ID_ILITEK_MULTITOUCH) },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_INTEL_8086,
+					USB_DEVICE_ID_SENSOR_HUB_1020) },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_INTEL_8087,
+					USB_DEVICE_ID_SENSOR_HUB_09FA) },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_INTEL_8087,
+					USB_DEVICE_ID_SENSOR_HUB_09FA) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_IRTOUCHSYSTEMS, USB_DEVICE_ID_IRTOUCH_INFRARED_USB) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_KENSINGTON, USB_DEVICE_ID_KS_SLIMBLADE) },
 	{ HID_USB_DEVICE(USB_VENDOR_ID_KEYTOUCH, USB_DEVICE_ID_KEYTOUCH_IEC) },
diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h
index 7409750..928fe57 100644
--- a/drivers/hid/hid-ids.h
+++ b/drivers/hid/hid-ids.h
@@ -401,6 +401,11 @@
 #define USB_VENDOR_ID_IMATION		0x0718
 #define USB_DEVICE_ID_DISC_STAKKA	0xd000
 
+#define USB_VENDOR_ID_INTEL_8086	0x8086
+#define USB_VENDOR_ID_INTEL_8087	0x8087
+#define USB_DEVICE_ID_SENSOR_HUB_1020	0x1020
+#define USB_DEVICE_ID_SENSOR_HUB_09FA	0x09FA
+
 #define USB_VENDOR_ID_IRTOUCHSYSTEMS	0x6615
 #define USB_DEVICE_ID_IRTOUCH_INFRARED_USB	0x0070
 
-- 
1.7.7.6

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH, 2/7] HID-Sensors: Sensor framework
       [not found] ` <1338997164-5077-1-git-send-email-srinivas.pandruvada-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
  2012-06-06 15:39   ` [PATCH, 1/7] HID-Sensors: Add Intel HID sensor srinivas pandruvada
@ 2012-06-06 15:39   ` srinivas pandruvada
  2012-06-06 15:39   ` [PATCH, 3/7] HID-Sensors: Common attributes and interfaces srinivas pandruvada
  2 siblings, 0 replies; 16+ messages in thread
From: srinivas pandruvada @ 2012-06-06 15:39 UTC (permalink / raw)
  To: linux-input-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA, srinivas pandruvada

Adding processing for HID Sensor usage table as defined by
HID 1.12, Request #: HUTRR39, dated 05 May, 2011.
This driver uses HID driver framework to register, send and
receive events.
This delegated the actual usage id processing to different
modules, which are registered statically.

Signed-off-by: srinivas pandruvada <srinivas.pandruvada-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
 drivers/staging/Kconfig                            |    2 +
 drivers/staging/Makefile                           |    1 +
 drivers/staging/hid-sensors/Kconfig                |   19 +
 drivers/staging/hid-sensors/Makefile               |    9 +
 drivers/staging/hid-sensors/hid-sensor-hub.c       |  705 ++++++++++++++++++++
 drivers/staging/hid-sensors/hid-sensor-ids.h       |  117 ++++
 drivers/staging/hid-sensors/hid-sensor-interface.h |   75 ++
 7 files changed, 928 insertions(+), 0 deletions(-)
 create mode 100644 drivers/staging/hid-sensors/Kconfig
 create mode 100644 drivers/staging/hid-sensors/Makefile
 create mode 100644 drivers/staging/hid-sensors/hid-sensor-hub.c
 create mode 100644 drivers/staging/hid-sensors/hid-sensor-ids.h
 create mode 100644 drivers/staging/hid-sensors/hid-sensor-interface.h

diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig
index 97d412d..562700a 100644
--- a/drivers/staging/Kconfig
+++ b/drivers/staging/Kconfig
@@ -80,6 +80,8 @@ source "drivers/staging/sep/Kconfig"
 
 source "drivers/staging/iio/Kconfig"
 
+source "drivers/staging/hid-sensors/Kconfig"
+
 source "drivers/staging/zram/Kconfig"
 
 source "drivers/staging/zcache/Kconfig"
diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile
index ffe7d44..f53f0d4 100644
--- a/drivers/staging/Makefile
+++ b/drivers/staging/Makefile
@@ -32,6 +32,7 @@ obj-$(CONFIG_VT6656)		+= vt6656/
 obj-$(CONFIG_VME_BUS)		+= vme/
 obj-$(CONFIG_DX_SEP)            += sep/
 obj-$(CONFIG_IIO)		+= iio/
+obj-$(CONFIG_HID_SENSORS)	+= hid-sensors/
 obj-$(CONFIG_ZRAM)		+= zram/
 obj-$(CONFIG_ZCACHE)		+= zcache/
 obj-$(CONFIG_ZSMALLOC)		+= zsmalloc/
diff --git a/drivers/staging/hid-sensors/Kconfig b/drivers/staging/hid-sensors/Kconfig
new file mode 100644
index 0000000..be442f8
--- /dev/null
+++ b/drivers/staging/hid-sensors/Kconfig
@@ -0,0 +1,19 @@
+#
+# Sensor HUB subsytem configuration
+#
+
+menuconfig HID_SENSORS
+	tristate "HID Sensor Core"
+	select USB_HID
+	select IIO
+	select IIO_RING_BUFFER
+	select IIO_SW_RING
+	help
+	  Support for HID Sensor hub based on HID 1.12 sensor usage table
+
+menuconfig HID_SENSOR_DEBUG
+	tristate "HID Sensor debug support"
+	depends on HID_SENSORS
+	default n
+	help
+	  Debug support for Hid sensors
diff --git a/drivers/staging/hid-sensors/Makefile b/drivers/staging/hid-sensors/Makefile
new file mode 100644
index 0000000..13591b2
--- /dev/null
+++ b/drivers/staging/hid-sensors/Makefile
@@ -0,0 +1,9 @@
+#
+# Makefile for the HID Sensors.
+#
+ccflags-y += -Idrivers/hid
+ccflags-y += -Idrivers/staging
+ccflags-$(CONFIG_HID_SENSOR_DEBUG) += -DDEBUG
+
+hid-sensors-y := hid-sensor-hub.o
+obj-$(CONFIG_HID_SENSORS) += hid-sensors.o
diff --git a/drivers/staging/hid-sensors/hid-sensor-hub.c b/drivers/staging/hid-sensors/hid-sensor-hub.c
new file mode 100644
index 0000000..384e0d0
--- /dev/null
+++ b/drivers/staging/hid-sensors/hid-sensor-hub.c
@@ -0,0 +1,705 @@
+/*
+ * HID Sensors Driver
+ * Copyright (c) 2012, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+#include <linux/device.h>
+#include <linux/hid.h>
+#include <linux/usb.h>
+#include "usbhid/usbhid.h"
+#include <linux/module.h>
+#include <linux/slab.h>
+
+#include "hid-ids.h"
+#include "hid-sensor-ids.h"
+#include "hid-sensor-interface.h"
+
+#define RAW_BUFFER_SIZE	128
+#define sensor_hub_in_report(id, dev) sensor_hub_report(id, dev,\
+							HID_INPUT_REPORT)
+#define sensor_hub_out_report(id, dev) sensor_hub_report(id, dev,\
+							HID_OUTPUT_REPORT)
+#define sensor_hub_feature_report(id, dev) sensor_hub_report(id, dev,\
+							HID_FEATURE_REPORT)
+
+/* Description of in-progress IO operation, used for operations
+ * that trigger response from device */
+struct sensor_hub_pending {
+	struct completion ready;
+	u32 usage_id;
+	u32 attr_usage_id;
+	int raw_size;
+	u8 raw_data[RAW_BUFFER_SIZE];
+};
+
+struct sensor_hub_data {
+	struct hid_device *hdev;
+	struct mutex mutex;
+	spinlock_t lock;
+	struct sensor_hub_pending *pending;
+};
+
+struct sensor_hub_callbacks_list {
+	u32 usage_id;
+	struct sensor_hub_callbacks* (*reg_callback)(void);
+	int initialized;
+	void *priv;
+};
+
+static struct sensor_hub_callbacks_list usage_callbacks[] = {
+	{0}
+};
+
+/* Utility functions */
+
+static int sensor_hub_check_for_sensor_page(struct hid_device *hdev)
+{
+	int i;
+	int ret = -1;
+
+	for (i = 0; i < hdev->maxcollection; i++) {
+		struct hid_collection *col = &hdev->collection[i];
+		if (col->type == HID_COLLECTION_PHYSICAL &&
+		   (col->usage & HID_USAGE_PAGE) == HID_UP_SENSOR) {
+			ret = 0;
+			break;
+		}
+	}
+	return ret;
+}
+
+static struct hid_report *sensor_hub_report(int id, struct hid_device *hdev,
+						int dir)
+{
+	struct list_head *feature_report_list =
+					&hdev->report_enum[dir].report_list;
+	struct hid_report *report = NULL;
+
+	list_for_each_entry(report, feature_report_list, list) {
+		if (report->id == id)
+			return report;
+	}
+	hid_warn(hdev, "No report with id 0x%x found\n", id);
+	return NULL;
+}
+
+static struct sensor_hub_callbacks *sensor_hub_get_callback(u32 usage_id,
+							void **priv)
+{
+	int j;
+	struct sensor_hub_callbacks *callback = NULL;
+
+	j = 0;
+	while (usage_callbacks[j].usage_id != 0) {
+		if (usage_callbacks[j].initialized &&
+			usage_callbacks[j].usage_id == usage_id) {
+			callback = usage_callbacks[j].reg_callback();
+			*priv = usage_callbacks[j].priv;
+			break;
+		}
+		++j;
+	}
+	return callback;
+}
+
+static int sensor_hub_init_callbacks(struct hid_device *hdev)
+{
+	int i, j;
+	int ret = 0;
+	struct sensor_hub_callbacks *callback;
+
+	for (i = 0; i < hdev->maxcollection; ++i) {
+		struct hid_collection *collection = &hdev->collection[i];
+		hid_dbg(hdev, "c:%d t:0x%x u:0x%x l:0x%x\n",
+				i, collection->type,
+				collection->usage, collection->level);
+		j = 0;
+		while (usage_callbacks[j].usage_id != 0) {
+			if (collection->usage == usage_callbacks[j].usage_id) {
+				callback = usage_callbacks[j].reg_callback();
+				ret = callback->enter(hdev, collection->usage,
+					&usage_callbacks[j].priv);
+				if (ret) {
+					hid_err(hdev, "Failed:usage id:0x%x\n",
+						collection->usage);
+					break;
+				}
+				usage_callbacks[j].initialized = 1;
+			}
+			++j;
+		}
+	}
+	return ret;
+}
+
+#if (defined CONFIG_HID_SENSOR_DEBUG) || \
+	(defined CONFIG_HID_SENSOR_DEBUG_MODULE)
+static void dump_report(struct hid_device *hdev)
+{
+	int i, j;
+	struct hid_report *report;
+	struct hid_field *field;
+	struct hid_report_enum *report_enum;
+
+	hid_dbg(hdev, "Bus:0x%x Vendor:0x%x Product:0x%x\n", hdev->bus,
+			hdev->vendor, hdev->product);
+	hid_dbg(hdev, "rsize=%d, max_collections:%d\n", hdev->rsize,
+			hdev->maxcollection);
+	for (i = 0; i < hdev->maxcollection; ++i) {
+		struct hid_collection *collection = &hdev->collection[i];
+		hid_dbg(hdev, "c:%d t:0x%x u:0x%x l:0x%x\n",
+				 i, collection->type, collection->usage,
+				collection->level);
+	}
+
+	hid_dbg(hdev, "report_enum[HID_INPUT_REPORT]\n");
+	report_enum = &hdev->report_enum[HID_INPUT_REPORT];
+	list_for_each_entry(report, &report_enum->report_list, list) {
+		hid_dbg(hdev, "Report id:%x\n", report->id);
+		for (i = 0; i < report->maxfield; ++i) {
+			field = report->field[i];
+			for (j = 0; j < field->maxusage; ++j) {
+				hid_dbg(hdev, "usage hid:%x c_index:%x\n",
+				field->usage[j].hid,
+				field->usage[j].collection_index);
+			}
+			hid_dbg(hdev, "units:%x expo:%x\n",
+				field->unit,
+				field->unit_exponent);
+		}
+	}
+
+	hid_dbg(hdev, "report_enum[HID_OUTPUT_REPORT]\n");
+	report_enum = &hdev->report_enum[HID_OUTPUT_REPORT];
+	list_for_each_entry(report, &report_enum->report_list, list) {
+		hid_dbg(hdev, "Report id:%x\n", report->id);
+		for (i = 0; i < report->maxfield; ++i) {
+			field = report->field[i];
+			for (j = 0; j < field->maxusage; ++j) {
+				hid_dbg(hdev, "usage hid:%x c_index:%x\n",
+				field->usage[j].hid,
+				field->usage[j].collection_index);
+			}
+			hid_dbg(hdev, "units:%x expo:%x\n",
+				field->unit,
+				field->unit_exponent);
+
+		}
+	}
+
+	hid_dbg(hdev, "report_enum[HID_FEATURE_REPORT]\n");
+	report_enum = &hdev->report_enum[HID_FEATURE_REPORT];
+	list_for_each_entry(report, &report_enum->report_list, list) {
+		hid_dbg(hdev, "Report id:%x\n", report->id);
+		for (i = 0; i < report->maxfield; ++i) {
+			field = report->field[i];
+			for (j = 0; j < field->maxusage; ++j) {
+				hid_dbg(hdev, "u hid:%x c_index:%x\n",
+				field->usage[j].hid,
+				field->usage[j].collection_index);
+			}
+			hid_dbg(hdev, "units:%x expo:%x\n",
+				field->unit,
+				field->unit_exponent);
+		}
+	}
+}
+
+static void dump_raw_data(struct hid_device *hdev, int size, u8 *pdata)
+{
+	int j = 0;
+
+	for (j = 0; j < size; ++j)
+		hid_dbg(hdev, "0x%x\n", *pdata++);
+}
+#endif
+
+int sensor_hub_set_feature(struct hid_device *hdev, u32 report_id,
+				u32 field_index, s32 value)
+{
+	struct hid_report *report;
+	struct sensor_hub_data *data =  hid_get_drvdata(hdev);
+	int ret = 0;
+
+	mutex_lock(&data->mutex);
+	report = sensor_hub_feature_report(report_id, hdev);
+	if (!report) {
+		ret = -EINVAL;
+		goto done_proc;
+	}
+	if (field_index >=  report->maxfield) {
+		ret = -EINVAL;
+		goto done_proc;
+	}
+	hid_set_field(report->field[field_index], 0, value);
+	usbhid_submit_report(hdev, report, USB_DIR_OUT);
+	usbhid_wait_io(hdev);
+done_proc:
+	mutex_unlock(&data->mutex);
+	return ret;
+}
+
+int sensor_hub_get_feature(struct hid_device *hdev, u32 report_id,
+				u32 field_index, s32 *value)
+{
+	struct hid_report *report;
+	struct sensor_hub_data *data =  hid_get_drvdata(hdev);
+	int ret = 0;
+
+	mutex_lock(&data->mutex);
+	report = sensor_hub_feature_report(report_id, hdev);
+	if (!report) {
+		ret = -EINVAL;
+		goto done_proc;
+	}
+	if (field_index >=  report->maxfield) {
+		ret = -EINVAL;
+		goto done_proc;
+	}
+	usbhid_submit_report(hdev, report, USB_DIR_IN);
+	usbhid_wait_io(hdev);
+	*value = report->field[field_index]->value[0];
+done_proc:
+	mutex_unlock(&data->mutex);
+	return ret;
+}
+
+static int sensor_hub_get_report_id(struct hid_device *hdev, u8 type,
+					u32 usage_id, u32 field_usage_id,
+					int *index)
+{
+	int ret = -1;
+	int i, j;
+	int collection_index = -1;
+	struct hid_report *report;
+	struct hid_field *field;
+	struct hid_report_enum *report_enum;
+
+	*index = 0;
+	for (i = 0; i < hdev->maxcollection; ++i) {
+		struct hid_collection *collection = &hdev->collection[i];
+		if (usage_id == collection->usage) {
+			collection_index = i;
+			break;
+		}
+	}
+	if (collection_index == -1)
+		goto err_ret;
+
+	report_enum = &hdev->report_enum[type];
+	list_for_each_entry(report, &report_enum->report_list, list) {
+		for (i = 0; i < report->maxfield; ++i) {
+			field = report->field[i];
+			for (j = 0; j < field->maxusage; ++j) {
+				if (field->usage[j].hid == field_usage_id &&
+					field->usage[j].collection_index ==
+							collection_index)  {
+					*index = i;
+					ret = report->id;
+					hid_dbg(hdev, "Found usage hid\n");
+					hid_dbg(hdev, "r:%x id:%x c:%x f:%x\n",
+					ret, field->usage[j].hid,
+					field->usage[j].collection_index,
+					*index);
+					break;
+				}
+			}
+		}
+	}
+
+err_ret:
+	return ret;
+}
+
+/* Interface functions for sensor usage id clients */
+int sensor_hub_get_field_usage_index(struct hid_device *hdev, u32 *report_id,
+					u32 usage_id, u32 field_usage_id)
+{
+	int id;
+	int index = -1;
+
+	id = sensor_hub_get_report_id(hdev, HID_INPUT_REPORT, usage_id,
+					field_usage_id, &index);
+	if (id >= 0) {
+		*report_id = id;
+		goto done_proc;
+	}
+
+	id = sensor_hub_get_report_id(hdev, HID_OUTPUT_REPORT, usage_id,
+					field_usage_id, &index);
+	if (id >= 0) {
+		*report_id = id;
+		goto done_proc;
+	}
+
+	id = sensor_hub_get_report_id(hdev, HID_FEATURE_REPORT, usage_id,
+					field_usage_id, &index);
+	if (id >= 0) {
+		*report_id = id;
+		goto done_proc;
+	}
+
+done_proc:
+	return index;
+}
+
+ssize_t sensor_hub_input_attr_get_value(struct hid_device *hdev, u32 usage_id,
+					u32 attr_usage_id, u32 report_id,
+					u32 buf_len, u8 *buf)
+{
+	int len = -1;
+	struct sensor_hub_data *data =  hid_get_drvdata(hdev);
+	struct sensor_hub_pending *work;
+	unsigned long flags;
+	struct hid_report *report;
+
+	work = kzalloc(sizeof(*work), GFP_KERNEL);
+	if (!work)
+		return len;
+
+	init_completion(&work->ready);
+	work->usage_id = usage_id;
+	work->attr_usage_id = attr_usage_id;
+	work->raw_size = 0;
+
+	mutex_lock(&data->mutex);
+	spin_lock_irqsave(&data->lock, flags);
+	data->pending = work;
+	report = sensor_hub_in_report(report_id, data->hdev);
+	if (!report)
+		goto err_free;
+	usbhid_submit_report(data->hdev, report, USB_DIR_IN);
+	spin_unlock_irqrestore(&data->lock, flags);
+	wait_for_completion_interruptible_timeout(&work->ready, HZ*5);
+	if (work->raw_size)
+		len = snprintf(buf, buf_len, "%x\n", *(u32 *)work->raw_data);
+
+err_free:
+	data->pending = NULL;
+	mutex_unlock(&data->mutex);
+
+	kfree(work);
+	return len;
+}
+
+
+int sensor_hub_input_get_attribute_info(struct hid_device *hdev , u8 type,
+					u32 usage_id,
+					u32 attr_usage_id,
+				struct hid_sensor_hub_attribute_info *info)
+{
+	int ret = -1;
+	int i, j;
+	int collection_index = -1;
+	struct hid_report *report;
+	struct hid_field *field;
+	struct hid_report_enum *report_enum;
+
+	/* Initialize with defaults */
+	info->usage_id = usage_id;
+	info->attrib_id =  attr_usage_id;
+	info->report_id = -1;
+	info->index = -1;
+	info->units = -1;
+	info->unit_expo = -1;
+
+	for (i = 0; i < hdev->maxcollection; ++i) {
+		struct hid_collection *collection = &hdev->collection[i];
+		if (usage_id == collection->usage) {
+			collection_index = i;
+			break;
+		}
+	}
+	if (collection_index == -1)
+		goto err_ret;
+
+	report_enum = &hdev->report_enum[type];
+	list_for_each_entry(report, &report_enum->report_list, list) {
+		for (i = 0; i < report->maxfield; ++i) {
+			field = report->field[i];
+			for (j = 0; j < field->maxusage; ++j) {
+				if (field->usage[j].hid == attr_usage_id &&
+					field->usage[j].collection_index ==
+					collection_index)  {
+					info->index = i;
+					info->report_id = report->id;
+					info->units = field->unit;
+					info->unit_expo = field->unit_exponent;
+					break;
+				}
+			}
+		}
+	}
+err_ret:
+	return ret;
+
+}
+
+#ifdef CONFIG_PM
+static int sensor_hub_suspend(struct hid_device *hdev, pm_message_t message)
+{
+	int j;
+	struct sensor_hub_callbacks *callback;
+
+	hid_dbg(hdev, " sensor_hub_suspend\n");
+	j = 0;
+	while (usage_callbacks[j].usage_id != 0) {
+		if (usage_callbacks[j].initialized) {
+			callback = usage_callbacks[j].reg_callback();
+			if (callback->suspend)
+				callback->suspend(hdev,
+						  usage_callbacks[j].priv);
+		}
+		++j;
+	}
+	return 0;
+}
+
+static int sensor_hub_resume(struct hid_device *hdev)
+{
+	int j;
+	struct sensor_hub_callbacks *callback;
+
+	hid_dbg(hdev, " sensor_hub_resume\n");
+	j = 0;
+	while (usage_callbacks[j].usage_id != 0) {
+		if (usage_callbacks[j].initialized) {
+			callback = usage_callbacks[j].reg_callback();
+			if (callback->resume)
+				callback->resume(hdev,
+					usage_callbacks[j].priv);
+		}
+		++j;
+	}
+	return 0;
+}
+
+static int sensor_hub_reset_resume(struct hid_device *hdev)
+{
+	return 0;
+}
+#endif
+
+/*
+ * Handle raw report as sent by device
+ */
+static int sensor_hub_raw_event(struct hid_device *hdev,
+		struct hid_report *report, u8 *raw_data, int size)
+{
+	int i;
+	u8 *ptr;
+	int sz;
+	struct sensor_hub_data *pdata = hid_get_drvdata(hdev);
+	unsigned long flags;
+	struct sensor_hub_callbacks *callback = NULL;
+	struct hid_collection *collection = NULL;
+	void *priv = NULL;
+
+	hid_dbg(hdev, "sensor_hub_raw_event report id:0x%x size:%d type:%d\n",
+			 report->id, size, report->type);
+	hid_dbg(hdev, "maxfield:%d\n", report->maxfield);
+#if (defined CONFIG_HID_SENSOR_DEBUG) || \
+	(defined CONFIG_HID_SENSOR_DEBUG_MODULE)
+	dump_raw_data(hdev, size, raw_data);
+#endif
+	if (report->type != HID_INPUT_REPORT)
+		return 1;
+
+	ptr = raw_data;
+	ptr++; /*Skip report id*/
+
+	if (!report)
+		goto err_report;
+
+	spin_lock_irqsave(&pdata->lock, flags);
+
+	for (i = 0; i < report->maxfield; ++i) {
+
+		hid_dbg(hdev, "%d collection_index:%x hid:%x sz:%x\n",
+				i, report->field[i]->usage->collection_index,
+				report->field[i]->usage->hid,
+				report->field[i]->report_size/8);
+
+		sz = report->field[i]->report_size/8;
+		if (pdata->pending && pdata->pending->attr_usage_id ==
+				report->field[i]->usage->hid) {
+			hid_dbg(hdev, "data was pending ...\n");
+			sz = (sz > RAW_BUFFER_SIZE) ? RAW_BUFFER_SIZE : sz;
+			memcpy(pdata->pending->raw_data, ptr, sz);
+			pdata->pending->raw_size  = sz;
+			complete(&pdata->pending->ready);
+		}
+		collection = &hdev->collection[
+				report->field[i]->usage->collection_index];
+		hid_dbg(hdev, "collection->usage %x\n",
+					collection->usage);
+		callback = sensor_hub_get_callback(collection->usage,
+							   &priv);
+		if (callback && callback->capture_sample) {
+			callback->capture_sample(hdev,
+			report->field[i]->usage->hid, sz, ptr, priv);
+		}
+		ptr += sz;
+	}
+	if (callback && collection && callback->send_event)
+		callback->send_event(hdev, collection->usage, priv);
+
+	spin_unlock_irqrestore(&pdata->lock, flags);
+
+err_report:
+	return 1;
+}
+
+static int sensor_hub_probe(struct hid_device *hdev,
+				const struct hid_device_id *id)
+{
+	int ret;
+	struct sensor_hub_data *sd;
+
+	sd = kzalloc(sizeof(struct sensor_hub_data), GFP_KERNEL);
+	if (!sd) {
+		hid_err(hdev, "cannot allocate Sensor data\n");
+		return -ENOMEM;
+	}
+	hid_set_drvdata(hdev, sd);
+	sd->hdev = hdev;
+	spin_lock_init(&sd->lock);
+	mutex_init(&sd->mutex);
+	ret = hid_parse(hdev);
+	if (ret) {
+		hid_err(hdev, "parse failed\n");
+		goto err_free;
+	}
+#if (defined CONFIG_HID_SENSOR_DEBUG) || \
+	(defined CONFIG_HID_SENSOR_DEBUG_MODULE)
+	dump_report(hdev);
+#endif
+	if (sensor_hub_check_for_sensor_page(hdev) < 0) {
+		hid_err(hdev, "sensor page not found\n");
+		goto err_free;
+	}
+	INIT_LIST_HEAD(&hdev->inputs);
+
+	hdev->claimed = HID_CLAIMED_INPUT;
+	ret = hid_hw_start(hdev, 0);
+	if (ret) {
+		hid_err(hdev, "hw start failed\n");
+		goto err_free;
+	}
+	ret = hid_hw_open(hdev);
+	if (ret) {
+		hid_hw_stop(hdev);
+		hid_err(hdev, "failed to open input interrupt pipe\n");
+		goto err_close;
+	}
+
+	ret = sensor_hub_init_callbacks(hdev);
+	if (ret < 0)
+		goto err_stop_hw;
+	return ret;
+
+err_close:
+	hid_hw_stop(hdev);
+err_stop_hw:
+	hid_hw_close(hdev);
+err_free:
+	kfree(sd);
+
+	return ret;
+}
+
+static void sensor_hub_remove(struct hid_device *hdev)
+{
+	struct sensor_hub_data *data = hid_get_drvdata(hdev);
+	unsigned long flags;
+	int j, ret;
+	struct sensor_hub_callbacks *callback;
+
+	hid_dbg(hdev, " hardware removed\n");
+
+	hdev->claimed &= ~HID_CLAIMED_INPUT;
+
+	hid_hw_stop(hdev);
+	hid_hw_close(hdev);
+
+	j = 0;
+	while (usage_callbacks[j].usage_id != 0) {
+		if (usage_callbacks[j].initialized) {
+			callback = usage_callbacks[j].reg_callback();
+			ret = callback->exit(hdev, usage_callbacks[j].priv);
+			if (ret) {
+				hid_err(hdev, "callback exit failed\n");
+				break;
+			}
+		}
+			++j;
+	}
+
+	hid_set_drvdata(hdev, NULL);
+
+	spin_lock_irqsave(&data->lock, flags);
+	if (data->pending)
+		complete(&data->pending->ready);
+	spin_unlock_irqrestore(&data->lock, flags);
+
+	mutex_destroy(&data->mutex);
+	kfree(data);
+}
+
+static const struct hid_device_id sensor_hub_devices[] = {
+	{ HID_USB_DEVICE(USB_VENDOR_ID_INTEL_8086,
+			USB_DEVICE_ID_SENSOR_HUB_1020) },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_INTEL_8087,
+			USB_DEVICE_ID_SENSOR_HUB_09FA) },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_INTEL_8087,
+			USB_DEVICE_ID_SENSOR_HUB_09FA) },
+	{ HID_USB_DEVICE(USB_VENDOR_ID_STANTUM_STM,
+			USB_DEVICE_ID_SENSOR_HUB_7014) },
+	{ }
+};
+
+static const struct hid_usage_id sensor_hub_grabbed_usages[] = {
+	{ HID_ANY_ID, HID_ANY_ID, HID_ANY_ID },
+	{ HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1 }
+};
+
+static struct hid_driver sensor_hub_driver = {
+	.name = "hid-sensor-hub",
+	.id_table = sensor_hub_devices,
+	.probe = sensor_hub_probe,
+	.remove = sensor_hub_remove,
+	.raw_event = sensor_hub_raw_event,
+#ifdef CONFIG_PM
+	.suspend = sensor_hub_suspend,
+	.resume =  sensor_hub_resume,
+	.reset_resume =  sensor_hub_reset_resume,
+#endif
+};
+
+static int __init sensor_hub_init(void)
+{
+	return hid_register_driver(&sensor_hub_driver);
+}
+
+static void __exit sensor_hub_exit(void)
+{
+	hid_unregister_driver(&sensor_hub_driver);
+}
+
+
+module_init(sensor_hub_init);
+module_exit(sensor_hub_exit);
+MODULE_LICENSE("GPL");
diff --git a/drivers/staging/hid-sensors/hid-sensor-ids.h b/drivers/staging/hid-sensors/hid-sensor-ids.h
new file mode 100644
index 0000000..553f366
--- /dev/null
+++ b/drivers/staging/hid-sensors/hid-sensor-ids.h
@@ -0,0 +1,117 @@
+/*
+ * HID Sensors Driver
+ * Copyright (c) 2012, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+#ifndef _HID_SENSORS_IDS_H
+#define _HID_SENSORS_IDS_H
+
+#include "hid-ids.h"
+
+#define HID_UP_SENSOR		0x00200000
+#define HID_SENSOR_POLLING      0x0020030E
+#define HID_SENSOR_REPORT_STATE 0x00200316
+
+
+/* Accel 3D (200073) */
+#define HID_USAGE_SENSOR_ACCEL_3D				0x200073
+#define HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS	0x200453
+#define HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS	0x200454
+#define HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS	0x200455
+
+/* ALS (200041) */
+#define HID_USAGE_SENSOR_ALS				        0x200041
+#define HID_USAGE_SENSOR_DATA_LIGHT_ILLUMINANCE			0x2004d1
+
+/* Compass 3D: (200083) */
+
+/* Gyro 3D: (200076) */
+#define HID_USAGE_SENSOR_GYRO_3D				0x200076
+#define HID_USAGE_SENSOR_DATA_MOTION_ANGULAR_VELOCITY_X_AXIS	0x200457
+#define HID_USAGE_SENSOR_DATA_MOTION_ANGULAR_VELOCITY_Y_AXIS	0x200458
+#define HID_USAGE_SENSOR_DATA_MOTION_ANGULAR_VELOCITY_Z_AXIS	0x200459
+
+/*ORIENTATION: Compass 3D: (200083) */
+#define HID_USAGE_SENSOR_COMPASS_3D				0x200083
+#define HID_USAGE_SENSOR_DATA_ORIENTATION_MAGNETIC_HEADING	0x200471
+#define HID_USAGE_SENSOR_DATA_ORIENTATION_MAGNETIC_HEADING_X	0x200472
+#define HID_USAGE_SENSOR_DATA_ORIENTATION_MAGNETIC_HEADING_Y	0x200473
+#define HID_USAGE_SENSOR_DATA_ORIENTATION_MAGNETIC_HEADING_Z	0x200474
+
+#define HID_USAGE_SENSOR_DATA_ORIENTATION_COMPENSATED_MAGNETIC_NORTH 0x200475
+#define HID_USAGE_SENSOR_DATA_ORIENTATION_COMPENSATED_TRUE_NORTH 0x200476
+#define HID_USAGE_SENSOR_DATA_ORIENTATION_MAGNETIC_NORTH	0x200477
+#define HID_USAGE_SENSOR_DATA_ORIENTATION_TRUE_NORTH		0x200478
+
+#define HID_USAGE_SENSOR_DATA_ORIENTATION_DISTANCE		0x200479
+#define HID_USAGE_SENSOR_DATA_ORIENTATION_DISTANCE_X		0x20047A
+#define HID_USAGE_SENSOR_DATA_ORIENTATION_DISTANCE_Y		0x20047B
+#define HID_USAGE_SENSOR_DATA_ORIENTATION_DISTANCE_Z		0x20047C
+#define HID_USAGE_SENSOR_DATA_ORIENTATION_DISTANCE_OUT_OF_RANGE 0x20047D
+#define HID_USAGE_SENSOR_DATA_ORIENTATION_TILT			0x20047E
+#define HID_USAGE_SENSOR_DATA_ORIENTATION_TILT_X		0x20047F
+#define HID_USAGE_SENSOR_DATA_ORIENTATION_TILT_Y		0x200480
+#define HID_USAGE_SENSOR_DATA_ORIENTATION_TILT_Z		0x200481
+#define HID_USAGE_SENSOR_DATA_ORIENTATION_ROTATION_MATRIX	0x200482
+#define HID_USAGE_SENSOR_DATA_ORIENTATION_QUATERNION		0x200483
+#define HID_USAGE_SENSOR_DATA_ORIENTATION_MAGNETIC_FLUX		0x200484
+
+#define HID_USAGE_SENSOR_DATA_ORIENTATION_MAGNETIC_FLUX_X_AXIS	0x200485
+#define HID_USAGE_SENSOR_DATA_ORIENTATION_MAGNETIC_FLUX_Y_AXIS	0x200486
+#define HID_USAGE_SENSOR_DATA_ORIENTATION_MAGNETIC_FLUX_Z_AXIS	0x200487
+
+/* Units */
+#define HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED	0x00
+#define HID_USAGE_SENSOR_UNITS_LUX		0x01
+#define HID_USAGE_SENSOR_UNITS_KELVIN		(0x01, 0x00, 0x01, 0x00)
+#define HID_USAGE_SENSOR_UNITS_FAHRENHEIT	(0x03, 0x00, 0x01, 0x00)
+#define HID_USAGE_SENSOR_UNITS_PASCAL		(0xF1, 0xE1)
+#define HID_USAGE_SENSOR_UNITS_NEWTON		(0x11, 0xE1)
+#define HID_USAGE_SENSOR_UNITS_METERS_PER_SECOND (0x11, 0xF0)
+#define HID_USAGE_SENSOR_UNITS_METERS_PER_SEC_SQRD (0x11, 0xE0)
+#define HID_USAGE_SENSOR_UNITS_FARAD		(0xE1, 0x4F, 0x20, 0x00)
+#define HID_USAGE_SENSOR_UNITS_AMPERE		(0x01, 0x00, 0x10, 0x00)
+#define HID_USAGE_SENSOR_UNITS_WATT		(0x21, 0xd1)
+#define HID_USAGE_SENSOR_UNITS_HENRY		(0x21, 0xE1, 0xE0, 0x00)
+#define HID_USAGE_SENSOR_UNITS_OHM		(0x21, 0xD1, 0xE0, 0x00)
+#define HID_USAGE_SENSOR_UNITS_VOLT		(0x21, 0xD1, 0xF0, 0x00)
+#define HID_USAGE_SENSOR_UNITS_HERTZ		(0x01, 0xF0)
+#define HID_USAGE_SENSOR_UNITS_DEGREES_PER_SEC_SQRD (0x14, 0xE0)
+#define HID_USAGE_SENSOR_UNITS_RADIANS		0x12
+#define HID_USAGE_SENSOR_UNITS_RADIANS_PER_SECOND (0x12, 0xF0)
+#define HID_USAGE_SENSOR_UNITS_RADIANS_PER_SEC_SQRD (0x12, 0xE0)
+#define HID_USAGE_SENSOR_UNITS_SECOND		(0x01, 0x10)
+#define HID_USAGE_SENSOR_UNITS_GAUSS		(0x01, 0xE1, 0xF0, 0x00)
+#define HID_USAGE_SENSOR_UNITS_GRAM		(0x01, 0x01)
+#define HID_USAGE_SENSOR_UNITS_CENTIMETER	0x11
+#define HID_USAGE_SENSOR_UNITS_G		0x1A
+#define HID_USAGE_SENSOR_UNITS_MILLISECOND	0x19
+#define HID_USAGE_SENSOR_UNITS_PERCENT		0x17
+#define HID_USAGE_SENSOR_UNITS_DEGREES		0x14
+#define HID_USAGE_SENSOR_UNITS_DEGREES_PER_SECOND 0x15
+
+/* Common selectors */
+#define HID_USAGE_SENSOR_PROPERTY_REPORT_INTERVAL		0x20030E
+#define HID_USAGE_SENSOR_PROPERTY_CHANGE_SENSITIVITY_ABS	0x20030F
+#define HID_USAGE_SENSOR_PROPERTY_CHANGE_SENSITIVITY_RANGE_PCT	0x200310
+#define HID_USAGE_SENSOR_PROPERTY_CHANGE_SENSITIVITY_REL_PCT	0x200311
+#define HID_USAGE_SENSOR_PROPERTY_ACCURACY			0x200312
+#define HID_USAGE_SENSOR_PROPERTY_RESOLUTION			0x200313
+#define HID_USAGE_SENSOR_PROPERTY_RANGE_MAXIMUM			0x200314
+#define HID_USAGE_SENSOR_PROPERTY_RANGE_MINIMUM			0x200315
+#define HID_USAGE_SENSOR_PROPERTY_REPORTING_STATE		0x200316
+
+#endif
diff --git a/drivers/staging/hid-sensors/hid-sensor-interface.h b/drivers/staging/hid-sensors/hid-sensor-interface.h
new file mode 100644
index 0000000..18a2e09
--- /dev/null
+++ b/drivers/staging/hid-sensors/hid-sensor-interface.h
@@ -0,0 +1,75 @@
+/*
+ * HID Sensors Driver
+ * Copyright (c) 2012, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+#ifndef _HID_SENSORS_INTERFACE_H
+#define _HID_SENSORS_INTERFACE_H
+
+#include <linux/device.h>
+#include <linux/hid.h>
+#include <linux/usb.h>
+#include "usbhid/usbhid.h"
+#include <linux/module.h>
+#include <linux/slab.h>
+#include "iio/iio.h"
+#include "iio/sysfs.h"
+#include "iio/ring_sw.h"
+#include "iio/trigger.h"
+
+struct hid_sensor_hub_attribute_info {
+	u32 usage_id;
+	u32 attrib_id;
+	s32 report_id;
+	s32 index;
+	s32 units;
+	s32 unit_expo;
+};
+
+struct hid_sensor_attributes {
+	struct hid_device *hdev;
+	unsigned usage_id;
+	bool data_ready;
+	struct hid_sensor_hub_attribute_info poll;
+	struct hid_sensor_hub_attribute_info activate;
+	struct hid_sensor_hub_attribute_info sensitivity;
+	void *private;
+};
+
+struct sensor_hub_callbacks {
+	int (*enter)(struct hid_device *hdev, u32 usage_id, void **priv);
+	int (*exit)(struct hid_device *hdev, void *priv);
+	int (*suspend)(struct hid_device *hdev, void *priv);
+	int (*resume)(struct hid_device *hdev, void *priv);
+	int (*capture_sample)(struct hid_device *hdev, u32 usage_id,
+				size_t raw_len, char *raw_data, void *priv);
+	int (*send_event)(struct hid_device *hdev, u32 usage_id, void *priv);
+};
+
+/* Hid sensor hub core interfaces */
+int sensor_hub_input_get_attribute_info(struct hid_device *hdev, u8 type,
+				u32 usage_id, u32 attr_usage_id,
+				struct hid_sensor_hub_attribute_info *info);
+int sensor_hub_set_feature(struct hid_device *dev, u32 report_id,
+					u32 field_index, s32 value);
+int sensor_hub_get_feature(struct hid_device *hdev, u32 report_id,
+				u32 field_index, s32 *value);
+ssize_t sensor_hub_input_attr_get_value(struct hid_device *hdev, u32 usage_id,
+					u32 attr_usage_id, u32 report_id,
+					u32 buf_len, u8 *buf);
+int sensor_hub_input_get_unit_expo(struct hid_device *hdev, u32 field_usage_id,
+					s32 *unit, s32 *unit_expo);
+#endif
-- 
1.7.7.6

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH, 3/7] HID-Sensors: Common attributes and interfaces
       [not found] ` <1338997164-5077-1-git-send-email-srinivas.pandruvada-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
  2012-06-06 15:39   ` [PATCH, 1/7] HID-Sensors: Add Intel HID sensor srinivas pandruvada
  2012-06-06 15:39   ` [PATCH, 2/7] HID-Sensors: Sensor framework srinivas pandruvada
@ 2012-06-06 15:39   ` srinivas pandruvada
       [not found]     ` <1338997164-5077-4-git-send-email-srinivas.pandruvada-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
  2 siblings, 1 reply; 16+ messages in thread
From: srinivas pandruvada @ 2012-06-06 15:39 UTC (permalink / raw)
  To: linux-input-u79uwXL29TY76Z2rM5mHXA
  Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA, Srinivas pandruvada

From: Srinivas pandruvada <srinivas.pandruvada-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>

Added IIO Ring interface and trigger functions, which can be
used by all sensors. In addition a set of interface functions
for setting common attributes for all sensors like polling
interval, sensitivity and activate etc.

Signed-off-by: Srinivas pandruvada <srinivas.pandruvada-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
---
 drivers/staging/hid-sensors/Makefile               |    3 +
 .../staging/hid-sensors/hid-sensor-attributes.c    |  203 ++++++++++++++++++++
 .../staging/hid-sensors/hid-sensor-attributes.h    |   67 +++++++
 drivers/staging/hid-sensors/hid-sensor-interface.h |   12 ++
 drivers/staging/hid-sensors/hid-sensor-ring.c      |  104 ++++++++++
 drivers/staging/hid-sensors/hid-sensor-trigger.c   |   81 ++++++++
 6 files changed, 470 insertions(+), 0 deletions(-)
 create mode 100644 drivers/staging/hid-sensors/hid-sensor-attributes.c
 create mode 100644 drivers/staging/hid-sensors/hid-sensor-attributes.h
 create mode 100644 drivers/staging/hid-sensors/hid-sensor-ring.c
 create mode 100644 drivers/staging/hid-sensors/hid-sensor-trigger.c

diff --git a/drivers/staging/hid-sensors/Makefile b/drivers/staging/hid-sensors/Makefile
index 13591b2..9a03953 100644
--- a/drivers/staging/hid-sensors/Makefile
+++ b/drivers/staging/hid-sensors/Makefile
@@ -6,4 +6,7 @@ ccflags-y += -Idrivers/staging
 ccflags-$(CONFIG_HID_SENSOR_DEBUG) += -DDEBUG
 
 hid-sensors-y := hid-sensor-hub.o
+hid-sensors-y += hid-sensor-attributes.o
+hid-sensors-y += hid-sensor-ring.o
+hid-sensors-y += hid-sensor-trigger.o
 obj-$(CONFIG_HID_SENSORS) += hid-sensors.o
diff --git a/drivers/staging/hid-sensors/hid-sensor-attributes.c b/drivers/staging/hid-sensors/hid-sensor-attributes.c
new file mode 100644
index 0000000..6f07d50
--- /dev/null
+++ b/drivers/staging/hid-sensors/hid-sensor-attributes.c
@@ -0,0 +1,203 @@
+/*
+ * HID Sensors Driver
+ * Copyright (c) 2012, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/mutex.h>
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/spi/spi.h>
+#include <linux/slab.h>
+#include <linux/sysfs.h>
+
+#include "iio/iio.h"
+#include "iio/sysfs.h"
+#include "hid-sensor-ids.h"
+#include "hid-sensor-interface.h"
+
+ssize_t hid_sensor_read_poll_interval(struct device *dev,
+				struct device_attribute *attr,
+				char *buf)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	__s32 value;
+	int len;
+	int ret;
+
+	ret = sensor_hub_get_feature(st->hdev,
+			st->poll.report_id,
+			st->poll.index, &value);
+	if (ret < 0 || value < 0)
+		len = sprintf(buf, "0\n");
+	else
+		len = sprintf(buf, "units:0x%2x,exp:0x%x,value:0x%2x\n",
+			st->poll.units, st->poll.unit_expo, value);
+	return len;
+}
+
+
+ssize_t hid_sensor_write_poll_interval(struct device *dev,
+		struct device_attribute *attr,
+		const char *buf, size_t len)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	long int value;
+	int ret;
+
+	if (kstrtol(buf, 10, &value) < 0)
+		return -EINVAL;
+
+	if (value <= 0)
+		value = 0;
+
+	ret = sensor_hub_set_feature(st->hdev,
+		st->poll.report_id,
+		st->poll.index,
+		value);
+
+	if (ret < 0)
+		return ret;
+	return strlen(buf);
+
+}
+
+ssize_t hid_sensor_read_report_state(struct device *dev,
+				struct device_attribute *attr,
+				char *buf)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	long int value;
+	int len;
+	int ret;
+
+	ret = sensor_hub_get_feature(st->hdev,
+			st->activate.report_id,
+			st->activate.index, (s32 *)&value);
+	if (ret < 0 || value < 0)
+		len = sprintf(buf, "0\n");
+	else
+		len = sprintf(buf, "units:0x%2x,exp:0x%x,value:0x%2x\n",
+			st->activate.units, st->activate.unit_expo,
+			(unsigned int)value);
+	return len;
+
+}
+
+ssize_t hid_sensor_write_report_state(struct device *dev,
+		struct device_attribute *attr,
+		const char *buf, size_t len)
+{
+
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	int ret;
+	long int value;
+
+	if (kstrtol(buf, 10, &value) < 0)
+		return -EINVAL;
+
+	ret = sensor_hub_set_feature(st->hdev, st->activate.report_id,
+					st->activate.index,
+					(s32)value);
+	if (ret < 0)
+		return ret;
+
+	return strlen(buf);
+}
+
+ssize_t hid_sensor_read_sensitivity(struct device *dev,
+				struct device_attribute *attr,
+				char *buf)
+{
+
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	__s32 value;
+	int len;
+	int ret;
+
+	ret = sensor_hub_get_feature(st->hdev,
+		st->sensitivity.report_id,
+		st->sensitivity.index, &value);
+	if (ret < 0 || value < 0)
+		len = sprintf(buf, "0\n");
+	else
+		len = sprintf(buf, "units:0x%2x,exp:0x%x,value:0x%2x\n",
+				st->sensitivity.units,
+				st->sensitivity.unit_expo, value);
+	return len;
+}
+
+
+ssize_t hid_sensor_write_sensitivity(struct device *dev,
+		struct device_attribute *attr,
+		const char *buf, size_t len)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	long int value;
+	int ret;
+
+	if (kstrtol(buf, 10, &value) < 0)
+		return -EINVAL;
+
+	if (value <= 0)
+		value = 0;
+
+	ret = sensor_hub_set_feature(st->hdev,
+		st->sensitivity.report_id,
+		st->sensitivity.index,
+		value);
+
+	if (ret < 0)
+		return ret;
+
+	return strlen(buf);
+}
+
+
+
+int hid_sensor_parse_common_attributes(struct hid_device *hdev, u32 usage_id,
+					struct hid_sensor_attributes *st)
+{
+	int ret;
+
+	ret = sensor_hub_input_get_attribute_info(hdev,
+					HID_FEATURE_REPORT, usage_id,
+					HID_SENSOR_POLLING, &st->poll);
+
+	ret = sensor_hub_input_get_attribute_info(hdev,
+					HID_FEATURE_REPORT, usage_id,
+					HID_SENSOR_REPORT_STATE,
+					&st->activate);
+
+	ret = sensor_hub_input_get_attribute_info(hdev,
+			HID_FEATURE_REPORT, usage_id,
+			HID_USAGE_SENSOR_PROPERTY_CHANGE_SENSITIVITY_ABS,
+			 &st->sensitivity);
+
+	hid_dbg(hdev, "common attributes: %x:%x, %x:%x, %x:%x\n",
+			st->poll.index, st->poll.report_id,
+			st->activate.index, st->activate.report_id,
+			st->sensitivity.index, st->sensitivity.report_id);
+
+	return 0;
+}
diff --git a/drivers/staging/hid-sensors/hid-sensor-attributes.h b/drivers/staging/hid-sensors/hid-sensor-attributes.h
new file mode 100644
index 0000000..b1f4ac9
--- /dev/null
+++ b/drivers/staging/hid-sensors/hid-sensor-attributes.h
@@ -0,0 +1,67 @@
+/*
+ * HID Sensors Driver
+ * Copyright (c) 2012, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+#ifndef _HID_SENSORS_ATTRIBUTES_H
+#define _HID_SENSORS_ATTRIBUTES_H
+
+/* Common sysfs attributes for HID sensors */
+
+int hid_sensor_parse_common_attributes(struct hid_device *hdev, u32 usage_id,
+					struct hid_sensor_attributes *st);
+
+ssize_t hid_sensor_read_poll_interval(struct device *dev,
+				struct device_attribute *attr,
+				char *buf);
+ssize_t hid_sensor_write_poll_interval(struct device *dev,
+		struct device_attribute *attr,
+		const char *buf, size_t len);
+
+ssize_t hid_sensor_read_report_state(struct device *dev,
+				struct device_attribute *attr,
+				char *buf);
+ssize_t hid_sensor_write_report_state(struct device *dev,
+		struct device_attribute *attr,
+		const char *buf, size_t len);
+ssize_t hid_sensor_read_sensitivity(struct device *dev,
+				struct device_attribute *attr,
+				char *buf);
+ssize_t hid_sensor_write_sensitivity(struct device *dev,
+		struct device_attribute *attr,
+		const char *buf, size_t len);
+
+
+#define IIO_DEV_ATTR_POLL_INTERVAL(_mode, _show, _store, _addr)  \
+	IIO_DEVICE_ATTR(poll_interval, _mode, _show, _store, _addr)
+#define IIO_DEV_ATTR_SENSITIVITY(_mode, _show, _store, _addr)        \
+	IIO_DEVICE_ATTR(sensitivity, _mode, _show, _store, _addr)
+#define IIO_DEV_ATTR_REPORT_STATE(_mode, _show, _store, _addr)        \
+	IIO_DEVICE_ATTR(activate, _mode, _show, _store, _addr)
+
+static IIO_DEV_ATTR_POLL_INTERVAL(S_IWUSR | S_IRUSR,
+			hid_sensor_read_poll_interval,
+			hid_sensor_write_poll_interval,
+			HID_SENSOR_POLLING);
+static IIO_DEV_ATTR_SENSITIVITY(S_IWUSR | S_IRUSR,
+			hid_sensor_read_sensitivity,
+			hid_sensor_write_sensitivity,
+			HID_USAGE_SENSOR_PROPERTY_CHANGE_SENSITIVITY_ABS);
+static IIO_DEV_ATTR_REPORT_STATE(S_IWUSR | S_IRUSR,
+			hid_sensor_read_report_state,
+			hid_sensor_write_report_state,
+			HID_SENSOR_REPORT_STATE);
+#endif
diff --git a/drivers/staging/hid-sensors/hid-sensor-interface.h b/drivers/staging/hid-sensors/hid-sensor-interface.h
index 18a2e09..477494f 100644
--- a/drivers/staging/hid-sensors/hid-sensor-interface.h
+++ b/drivers/staging/hid-sensors/hid-sensor-interface.h
@@ -72,4 +72,16 @@ ssize_t sensor_hub_input_attr_get_value(struct hid_device *hdev, u32 usage_id,
 					u32 buf_len, u8 *buf);
 int sensor_hub_input_get_unit_expo(struct hid_device *hdev, u32 field_usage_id,
 					s32 *unit, s32 *unit_expo);
+
+/* Common IIO Ring Processing Functions */
+int hid_sensor_configure_ring(struct iio_dev *indio_dev);
+void hid_sensor_ring_cleanup(struct iio_dev *indio_dev);
+void hid_sensor_ring_set_datum_size(struct iio_dev *indio_dev, int size);
+void hid_sensor_push_data_to_ring(struct iio_dev *indio_dev, u8 *data,
+								int len);
+
+/* Trigger functions */
+int hid_sensor_setup_trigger(struct iio_dev *indio_dev, char *name);
+void hid_sensor_remove_trigger(struct iio_dev *indio_dev);
+
 #endif
diff --git a/drivers/staging/hid-sensors/hid-sensor-ring.c b/drivers/staging/hid-sensors/hid-sensor-ring.c
new file mode 100644
index 0000000..c63ff26
--- /dev/null
+++ b/drivers/staging/hid-sensors/hid-sensor-ring.c
@@ -0,0 +1,104 @@
+/*
+ * HID Sensors Driver
+ * Copyright (c) 2012, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/mutex.h>
+#include <linux/device.h>
+#include <linux/kernel.h>
+#include <linux/spi/spi.h>
+#include <linux/slab.h>
+#include <linux/sysfs.h>
+
+#include "iio/iio.h"
+#include "iio/sysfs.h"
+#include "iio/ring_sw.h"
+#include "iio/trigger_consumer.h"
+#include "iio/trigger.h"
+
+static const struct iio_buffer_setup_ops hid_sensors_buffer_setup_ops = {
+	.preenable = &iio_sw_buffer_preenable,
+	.postenable = &iio_triggered_buffer_postenable,
+	.predisable = &iio_triggered_buffer_predisable,
+};
+
+static irqreturn_t hid_sensor_trigger_handler(int irq, void *p)
+{
+	return IRQ_HANDLED;
+}
+
+void hid_sensor_push_data_to_ring(struct iio_dev *indio_dev, u8 *data, int len)
+{
+	struct iio_buffer *ring = indio_dev->buffer;
+	s64 timestamp = iio_get_time_ns();
+	int datum_sz;
+
+	if (!ring)
+		return;
+	datum_sz = ring->access->get_bytes_per_datum(ring);
+	if (len > datum_sz) {
+		dev_err(&indio_dev->dev, "Datum size mismatch %d:%d\n", len,
+				datum_sz);
+		return;
+	} else if (datum_sz > 0 && datum_sz != len) {
+		dev_dbg(&indio_dev->dev, "Updating Datum size%d:%d\n", len,
+				datum_sz);
+		if (ring->access->set_bytes_per_datum)
+			ring->access->set_bytes_per_datum(ring, len);
+	}
+
+
+	ring->access->store_to(ring, (u8 *)data, timestamp);
+}
+
+int hid_sensor_configure_ring(struct iio_dev *indio_dev)
+{
+	struct iio_buffer *ring;
+	int ret = 0;
+
+	ring = iio_sw_rb_allocate(indio_dev);
+	if (!ring)
+		return -ENOMEM;
+
+	ring->scan_timestamp = true;
+	indio_dev->buffer = ring;
+	indio_dev->setup_ops = &hid_sensors_buffer_setup_ops;
+
+	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
+						 &hid_sensor_trigger_handler,
+						 IRQF_ONESHOT,
+						 indio_dev,
+						 "hid_sensor%d",
+						 indio_dev->id);
+	if (indio_dev->pollfunc == NULL) {
+		ret = -ENOMEM;
+		goto error_iio_free;
+	}
+
+	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
+
+	return ret;
+error_iio_free:
+	iio_sw_rb_free(indio_dev->buffer);
+	return ret;
+}
+
+void hid_sensor_ring_cleanup(struct iio_dev *indio_dev)
+{
+	iio_sw_rb_free(indio_dev->buffer);
+}
diff --git a/drivers/staging/hid-sensors/hid-sensor-trigger.c b/drivers/staging/hid-sensors/hid-sensor-trigger.c
new file mode 100644
index 0000000..49d8740
--- /dev/null
+++ b/drivers/staging/hid-sensors/hid-sensor-trigger.c
@@ -0,0 +1,81 @@
+/*
+ * HID Sensors Driver
+ * Copyright (c) 2012, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+#include <linux/device.h>
+#include <linux/hid.h>
+#include <linux/usb.h>
+#include "usbhid/usbhid.h"
+#include <linux/module.h>
+#include <linux/slab.h>
+#include "iio/iio.h"
+#include "iio/trigger.h"
+#include "hid-sensor-interface.h"
+
+static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
+						bool state)
+{
+	struct iio_dev *indio_dev = trig->private_data;
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+
+
+	st->data_ready = state;
+
+	return 0;
+}
+
+void hid_sensor_remove_trigger(struct iio_dev *indio_dev)
+{
+	if (indio_dev->trig) {
+		iio_trigger_unregister(indio_dev->trig);
+		iio_free_trigger(indio_dev->trig);
+	}
+}
+
+static const struct iio_trigger_ops hid_sensor_trigger_ops = {
+	.owner = THIS_MODULE,
+	.set_trigger_state = &hid_sensor_data_rdy_trigger_set_state,
+};
+
+int hid_sensor_setup_trigger(struct iio_dev *indio_dev, char *name)
+{
+	int ret;
+	struct iio_trigger *trig;
+
+	trig = iio_allocate_trigger("%s-dev%d", name, indio_dev->id);
+	if (trig == NULL) {
+		ret = -ENOMEM;
+		goto error_ret;
+	}
+
+	trig->dev.parent = indio_dev->dev.parent;
+	trig->private_data = (void *)indio_dev;
+	trig->ops = &hid_sensor_trigger_ops;
+	ret = iio_trigger_register(trig);
+
+	/* select default trigger */
+	indio_dev->trig = trig;
+	if (ret)
+		goto error_free_trig;
+
+	return ret;
+
+error_free_trig:
+	iio_free_trigger(trig);
+error_ret:
+	return ret;
+}
-- 
1.7.7.6

^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH, 4/7] HID-Sensors: Added accelerometer 3D
  2012-06-06 15:39 [PATCH, 0/7] HID Sensor Driver srinivas pandruvada
       [not found] ` <1338997164-5077-1-git-send-email-srinivas.pandruvada-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
@ 2012-06-06 15:39 ` srinivas pandruvada
  2012-06-06 16:28   ` Jonathan Cameron
  2012-06-06 15:39 ` [PATCH, 5/7] HID-Sensors: Added Gyro 3D srinivas pandruvada
                   ` (2 subsequent siblings)
  4 siblings, 1 reply; 16+ messages in thread
From: srinivas pandruvada @ 2012-06-06 15:39 UTC (permalink / raw)
  To: linux-input; +Cc: linux-iio, Srinivas pandruvada

From: Srinivas pandruvada <srinivas.pandruvada@intel.com>

Added usage id processing for Accelrometer 3D. This uses IIO
interfaces "ring/buffer and trigger interface" to present
data to user mode.

Signed-off-by: Srinivas pandruvada <srinivas.pandruvada@intel.com>
---
 drivers/staging/hid-sensors/Makefile               |    1 +
 drivers/staging/hid-sensors/hid-sensor-accel-3d.c  |  387 ++++++++++++++++++++
 drivers/staging/hid-sensors/hid-sensor-hub.c       |    1 +
 drivers/staging/hid-sensors/hid-sensor-interface.h |    3 +
 4 files changed, 392 insertions(+), 0 deletions(-)
 create mode 100644 drivers/staging/hid-sensors/hid-sensor-accel-3d.c

diff --git a/drivers/staging/hid-sensors/Makefile b/drivers/staging/hid-sensors/Makefile
index 9a03953..4412079 100644
--- a/drivers/staging/hid-sensors/Makefile
+++ b/drivers/staging/hid-sensors/Makefile
@@ -9,4 +9,5 @@ hid-sensors-y := hid-sensor-hub.o
 hid-sensors-y += hid-sensor-attributes.o
 hid-sensors-y += hid-sensor-ring.o
 hid-sensors-y += hid-sensor-trigger.o
+hid-sensors-y += hid-sensor-accel-3d.o
 obj-$(CONFIG_HID_SENSORS) += hid-sensors.o
diff --git a/drivers/staging/hid-sensors/hid-sensor-accel-3d.c b/drivers/staging/hid-sensors/hid-sensor-accel-3d.c
new file mode 100644
index 0000000..ffe2639
--- /dev/null
+++ b/drivers/staging/hid-sensors/hid-sensor-accel-3d.c
@@ -0,0 +1,387 @@
+/*
+ * HID Sensors Driver
+ * Copyright (c) 2012, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+#include <linux/device.h>
+#include <linux/hid.h>
+#include <linux/usb.h>
+#include "usbhid/usbhid.h"
+#include <linux/module.h>
+#include <linux/slab.h>
+#include "iio/iio.h"
+#include "iio/sysfs.h"
+#include "iio/ring_sw.h"
+#include "iio/trigger.h"
+#include "hid-sensor-ids.h"
+#include "hid-sensor-interface.h"
+#include "hid-sensor-attributes.h"
+
+
+struct accel_3d_sample {
+	u16 x_sz;
+	u32 accel_x;
+	u16 y_sz;
+	u32 accel_y;
+	u16 z_sz;
+	u32 accel_z;
+} __packed;
+
+struct accel_3d_state {
+	struct hid_sensor_hub_attribute_info accel_x;
+	struct hid_sensor_hub_attribute_info accel_y;
+	struct hid_sensor_hub_attribute_info accel_z;
+	struct accel_3d_sample accel_sample_data;
+};
+
+
+enum accel_3d_chan {
+	ACCEL_X_Y_Z,
+};
+
+enum accel_3d_scan {
+	ACCEL_3D_SCAN_ACC_X_Y_Z,
+};
+
+static struct iio_chan_spec accel_3d_channels[] = {
+	IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_X_AND_Y_AND_Z,
+	IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
+	IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
+	ACCEL_X_Y_Z, ACCEL_3D_SCAN_ACC_X_Y_Z,
+		 IIO_ST('u', sizeof(struct accel_3d_sample) * 8,
+		sizeof(struct accel_3d_sample) * 8, 0), 0),
+};
+
+static ssize_t accel_3d_read_accel(struct device *dev,
+				struct device_attribute *attr,
+				char *buf)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	struct accel_3d_state *accel_state =
+			(struct accel_3d_state *)st->private;
+	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
+	int report_id = -1;
+
+	switch (this_attr->address) {
+	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS:
+		report_id = accel_state->accel_x.report_id;
+		break;
+	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS:
+		report_id = accel_state->accel_y.report_id;
+		break;
+	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS:
+		report_id = accel_state->accel_z.report_id;
+		break;
+	default:
+		break;
+	}
+	if (report_id < 0)
+		return -EINVAL;
+
+	return sensor_hub_input_attr_get_value(st->hdev,
+			HID_USAGE_SENSOR_ACCEL_3D, this_attr->address,
+			report_id, 4, buf);
+}
+
+static int accel_3d_read_raw(struct iio_dev *indio_dev,
+			      struct iio_chan_spec const *chan,
+			      int *val, int *val2,
+			      long mask)
+{
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	struct accel_3d_state *accel_state =
+			(struct accel_3d_state *)st->private;
+	*val = 0;
+	*val2 = 0;
+
+	switch (mask) {
+	case 0:
+		break;
+	case IIO_CHAN_INFO_SCALE:
+		*val = accel_state->accel_x.units;
+		break;
+	case IIO_CHAN_INFO_OFFSET:
+		*val = accel_state->accel_x.unit_expo;
+		break;
+	default:
+		break;
+
+	}
+	return IIO_VAL_INT;
+}
+
+static int accel_3d_write_raw(struct iio_dev *indio_dev,
+			       struct iio_chan_spec const *chan,
+			       int val,
+			       int val2,
+			       long mask)
+{
+	printk(KERN_ERR "%s\n", __func__);
+
+	return 0;
+}
+
+/* Usage specific attributes */
+#define IIO_DEV_ATTR_ACCEL_OFFSET(_mode, _show, _store, _addr)  \
+	IIO_DEVICE_ATTR(accel_offset, _mode, _show, _store, _addr)
+
+#define IIO_DEV_ATTR_ACCEL_X_OFFSET(_mode, _show, _store, _addr)        \
+	IIO_DEVICE_ATTR(accel_x_offset, _mode, _show, _store, _addr)
+
+#define IIO_DEV_ATTR_ACCEL_Y_OFFSET(_mode, _show, _store, _addr)        \
+	IIO_DEVICE_ATTR(accel_y_offset, _mode, _show, _store, _addr)
+
+#define IIO_DEV_ATTR_ACCEL_Z_OFFSET(_mode, _show, _store, _addr)        \
+	IIO_DEVICE_ATTR(accel_z_offset, _mode, _show, _store, _addr)
+
+#define IIO_DEV_ATTR_ACCEL_SENSITIVITY(_mode, _show, _store, _addr)        \
+	IIO_DEVICE_ATTR(accel_sensitivity, _mode, _show, _store, _addr)
+
+static IIO_DEV_ATTR_ACCEL_X_OFFSET(S_IWUSR | S_IRUGO, accel_3d_read_accel,
+		 NULL, HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS);
+static IIO_DEV_ATTR_ACCEL_Y_OFFSET(S_IWUSR | S_IRUGO, accel_3d_read_accel,
+		 NULL, HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS);
+static IIO_DEV_ATTR_ACCEL_Z_OFFSET(S_IWUSR | S_IRUGO, accel_3d_read_accel,
+		 NULL, HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS);
+
+static struct attribute *accel_3d_attributes[] = {
+	/* common attributes */
+	&iio_dev_attr_poll_interval.dev_attr.attr,
+	&iio_dev_attr_sensitivity.dev_attr.attr,
+	&iio_dev_attr_activate.dev_attr.attr,
+	/* Usage specific attributes */
+	&iio_dev_attr_accel_x_offset.dev_attr.attr,
+	&iio_dev_attr_accel_y_offset.dev_attr.attr,
+	&iio_dev_attr_accel_z_offset.dev_attr.attr,
+	NULL,
+};
+
+static const struct attribute_group accel_3d_attribute_group = {
+	.attrs = accel_3d_attributes,
+};
+
+static const struct iio_info accel_3d_info = {
+	.attrs = &accel_3d_attribute_group,
+	.driver_module = THIS_MODULE,
+	.read_raw = &accel_3d_read_raw,
+	.write_raw = &accel_3d_write_raw,
+};
+
+
+/* Function to push data to IIO ring */
+int accel_3d_proc_event(struct hid_device *hdev, unsigned usage_id, void *priv)
+{
+	struct iio_dev *indio_dev = (struct iio_dev *)priv;
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	struct accel_3d_state *accel_state =
+			(struct accel_3d_state *)st->private;
+
+	hid_dbg(hdev, "accel_3d_proc_event\n");
+	if (st->data_ready)
+		hid_sensor_push_data_to_ring(indio_dev,
+				(u8 *)&accel_state->accel_sample_data,
+				sizeof(struct accel_3d_sample));
+	else
+		hid_dbg(hdev, "accel_3d_proc_event data not ready\n");
+	return 0;
+}
+
+/* Capture samples in local storage */
+int accel_3d_capture_sample(struct hid_device *hdev, unsigned usage_id,
+				 size_t raw_len, char *raw_data, void *priv)
+{
+	struct iio_dev *indio_dev = (struct iio_dev *)priv;
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	struct accel_3d_state *accel_state =
+			(struct accel_3d_state *)st->private;
+
+	switch (usage_id) {
+	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS:
+		accel_state->accel_sample_data.x_sz = raw_len;
+		accel_state->accel_sample_data.accel_x =
+		*(u32 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS:
+		accel_state->accel_sample_data.y_sz = raw_len;
+		accel_state->accel_sample_data.accel_y =
+		*(u32 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS:
+		accel_state->accel_sample_data.z_sz = raw_len;
+		accel_state->accel_sample_data.accel_z =
+		*(u32 *)raw_data;
+		break;
+	default:
+		break;
+	}
+	return 0;
+}
+
+
+/* Parse report which is specific to an usage id*/
+static int accel_3d_parse_report(struct hid_device *hdev, unsigned usage_id,
+				struct accel_3d_state *st)
+{
+	int ret;
+
+	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
+			usage_id,
+			HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS,
+			&st->accel_x);
+	if (!ret)
+		hid_dbg(hdev, "No Accel X attribute\n");
+
+
+	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
+			usage_id,
+			HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS,
+			&st->accel_y);
+	if (!ret)
+		hid_dbg(hdev, "No Accel Y attribute\n");
+
+
+	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
+			usage_id,
+			HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS,
+			&st->accel_z);
+	if (!ret)
+		hid_dbg(hdev, "No Accel Z attribute\n");
+
+	hid_dbg(hdev, "accel_3d %x:%x, %x:%x, %x:%x\n", st->accel_x.index,
+			st->accel_x.report_id,
+			st->accel_y.index, st->accel_y.report_id,
+			st->accel_z.index, st->accel_z.report_id);
+
+	return 0;
+}
+
+/* Entry function to initialize the processing for usage id */
+static int accel_3d_enter(struct hid_device *hdev, unsigned usage_id,
+				void **priv)
+{
+	int ret = 0;
+	static char *name = "accel_3d";
+	struct iio_dev *indio_dev;
+	struct accel_3d_state *accel_state;
+	struct hid_sensor_attributes *st;
+
+	accel_state = kzalloc(sizeof(struct accel_3d_state), GFP_KERNEL);
+	if (accel_state == NULL) {
+		ret = -ENOMEM;
+		goto error_ret;
+	}
+
+	indio_dev = iio_allocate_device(sizeof(struct hid_sensor_attributes));
+	if (indio_dev == NULL) {
+		ret = -ENOMEM;
+		goto error_free_state;
+	}
+	st = iio_priv(indio_dev);
+	st->usage_id = usage_id;
+	st->hdev = hdev;
+	st->private = (void *)accel_state;
+
+	ret = hid_sensor_parse_common_attributes(hdev, usage_id, st);
+	if (ret) {
+		hid_err(hdev, "failed to setup common attributes\n");
+		goto error_free_dev;
+	}
+	ret = accel_3d_parse_report(hdev, usage_id, accel_state);
+	if (ret) {
+		hid_err(hdev, "failed to setup attributes\n");
+		goto error_free_dev;
+	}
+
+	indio_dev->channels = accel_3d_channels;
+	indio_dev->num_channels =
+				ARRAY_SIZE(accel_3d_channels);
+	indio_dev->dev.parent = &hdev->dev;
+	indio_dev->info = &accel_3d_info;
+	indio_dev->name = name;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+
+	ret = hid_sensor_configure_ring(indio_dev);
+	if (ret) {
+		hid_err(hdev, "failed to initialize the ring\n");
+		goto error_free_dev;
+	}
+
+	ret = iio_buffer_register(indio_dev,
+					accel_3d_channels,
+					ARRAY_SIZE(accel_3d_channels));
+	if (ret) {
+		hid_err(hdev, "failed to initialize the ring\n");
+		goto error_unreg_ring_funcs;
+	}
+	st->data_ready = true;
+	ret = hid_sensor_setup_trigger(indio_dev, name);
+	if (ret < 0) {
+		hid_err(hdev, "trigger setup failed\n");
+		goto error_uninit_ring;
+	}
+
+	ret = iio_device_register(indio_dev);
+	if (ret) {
+		hid_err(hdev, "device register failed\n");
+		goto error_remove_trigger;
+	}
+	*priv = (void *)indio_dev;
+	return ret;
+
+error_remove_trigger:
+		hid_sensor_remove_trigger(indio_dev);
+error_uninit_ring:
+		iio_buffer_unregister(indio_dev);
+error_unreg_ring_funcs:
+		hid_sensor_ring_cleanup(indio_dev);
+error_free_dev:
+		iio_free_device(indio_dev);
+error_free_state:
+		kfree(accel_state);
+error_ret:
+		return ret;
+}
+
+static int accel_3d_exit(struct hid_device *hdev, void *priv)
+{
+	int ret = 0;
+	struct iio_dev *indio_dev = (struct iio_dev *)priv;
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	struct accel_3d_state *accel_state =
+			(struct accel_3d_state *)st->private;
+
+	iio_device_unregister(indio_dev);
+	hid_sensor_remove_trigger(indio_dev);
+	iio_buffer_unregister(indio_dev);
+	hid_sensor_ring_cleanup(indio_dev);
+	iio_free_device(indio_dev);
+
+	kfree(accel_state);
+	return ret;
+}
+
+static struct sensor_hub_callbacks accel_3d_callbacks = {
+	.enter = accel_3d_enter,
+	.exit = accel_3d_exit,
+	.send_event = accel_3d_proc_event,
+	.capture_sample = accel_3d_capture_sample,
+};
+
+struct sensor_hub_callbacks  *accel_3d_register_callbacks(void)
+{
+	return &accel_3d_callbacks;
+}
diff --git a/drivers/staging/hid-sensors/hid-sensor-hub.c b/drivers/staging/hid-sensors/hid-sensor-hub.c
index 384e0d0..55ae562 100644
--- a/drivers/staging/hid-sensors/hid-sensor-hub.c
+++ b/drivers/staging/hid-sensors/hid-sensor-hub.c
@@ -60,6 +60,7 @@ struct sensor_hub_callbacks_list {
 };
 
 static struct sensor_hub_callbacks_list usage_callbacks[] = {
+	{HID_USAGE_SENSOR_ACCEL_3D, accel_3d_register_callbacks},
 	{0}
 };
 
diff --git a/drivers/staging/hid-sensors/hid-sensor-interface.h b/drivers/staging/hid-sensors/hid-sensor-interface.h
index 477494f..3f4fe57 100644
--- a/drivers/staging/hid-sensors/hid-sensor-interface.h
+++ b/drivers/staging/hid-sensors/hid-sensor-interface.h
@@ -84,4 +84,7 @@ void hid_sensor_push_data_to_ring(struct iio_dev *indio_dev, u8 *data,
 int hid_sensor_setup_trigger(struct iio_dev *indio_dev, char *name);
 void hid_sensor_remove_trigger(struct iio_dev *indio_dev);
 
+/* Sensor usage id processing callbacks */
+struct sensor_hub_callbacks  *accel_3d_register_callbacks(void);
+
 #endif
-- 
1.7.7.6


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH, 5/7] HID-Sensors: Added Gyro 3D
  2012-06-06 15:39 [PATCH, 0/7] HID Sensor Driver srinivas pandruvada
       [not found] ` <1338997164-5077-1-git-send-email-srinivas.pandruvada-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
  2012-06-06 15:39 ` [PATCH, 4/7] HID-Sensors: Added accelerometer 3D srinivas pandruvada
@ 2012-06-06 15:39 ` srinivas pandruvada
  2012-06-06 15:39 ` [PATCH, 6/7] HID-Sensors: Added Compass 3D srinivas pandruvada
  2012-06-06 15:39 ` [PATCH, 7/7] HID-Sensors: Added ALS srinivas pandruvada
  4 siblings, 0 replies; 16+ messages in thread
From: srinivas pandruvada @ 2012-06-06 15:39 UTC (permalink / raw)
  To: linux-input; +Cc: linux-iio, Srinivas pandruvada

From: Srinivas pandruvada <srinivas.pandruvada@intel.com>

Added usage id processing for Gyro 3D. This uses IIO
interfaces "ring/buffer and trigger interface" to present
data to user mode.

Signed-off-by: Srinivas pandruvada <srinivas.pandruvada@intel.com>
---
 drivers/staging/hid-sensors/Makefile               |    1 +
 drivers/staging/hid-sensors/hid-sensor-gyro-3d.c   |  384 ++++++++++++++++++++
 drivers/staging/hid-sensors/hid-sensor-hub.c       |    1 +
 drivers/staging/hid-sensors/hid-sensor-interface.h |    1 +
 4 files changed, 387 insertions(+), 0 deletions(-)
 create mode 100644 drivers/staging/hid-sensors/hid-sensor-gyro-3d.c

diff --git a/drivers/staging/hid-sensors/Makefile b/drivers/staging/hid-sensors/Makefile
index 4412079..9c975a0 100644
--- a/drivers/staging/hid-sensors/Makefile
+++ b/drivers/staging/hid-sensors/Makefile
@@ -10,4 +10,5 @@ hid-sensors-y += hid-sensor-attributes.o
 hid-sensors-y += hid-sensor-ring.o
 hid-sensors-y += hid-sensor-trigger.o
 hid-sensors-y += hid-sensor-accel-3d.o
+hid-sensors-y += hid-sensor-gyro-3d.o
 obj-$(CONFIG_HID_SENSORS) += hid-sensors.o
diff --git a/drivers/staging/hid-sensors/hid-sensor-gyro-3d.c b/drivers/staging/hid-sensors/hid-sensor-gyro-3d.c
new file mode 100644
index 0000000..33db581
--- /dev/null
+++ b/drivers/staging/hid-sensors/hid-sensor-gyro-3d.c
@@ -0,0 +1,384 @@
+/*
+ * HID Sensors Driver
+ * Copyright (c) 2012, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+#include <linux/device.h>
+#include <linux/hid.h>
+#include <linux/usb.h>
+#include "usbhid/usbhid.h"
+#include <linux/module.h>
+#include <linux/slab.h>
+#include "iio/iio.h"
+#include "iio/sysfs.h"
+#include "iio/ring_sw.h"
+#include "iio/trigger.h"
+#include "hid-sensor-ids.h"
+#include "hid-sensor-interface.h"
+#include "hid-sensor-attributes.h"
+
+
+struct gyro_3d_sample {
+	u16 x_sz;
+	u32 gyro_x;
+	u16 y_sz;
+	u32 gyro_y;
+	u16 z_sz;
+	u32 gyro_z;
+} __packed;
+
+struct gyro_3d_state {
+	struct hid_sensor_hub_attribute_info gyro_x;
+	struct hid_sensor_hub_attribute_info gyro_y;
+	struct hid_sensor_hub_attribute_info gyro_z;
+	struct gyro_3d_sample gyro_sample_data;
+};
+
+
+enum gyro_3d_chan {
+	GYRO_X_Y_Z,
+};
+
+enum gyro_3d_scan {
+	GYRO_3D_SCAN_ACC_X_Y_Z,
+};
+
+static struct iio_chan_spec gyro_3d_channels[] = {
+	IIO_CHAN(IIO_ANGL_VEL, 1, 0, 0, NULL, 0, IIO_MOD_X_AND_Y_AND_Z,
+	IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
+	IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
+	GYRO_X_Y_Z, GYRO_3D_SCAN_ACC_X_Y_Z,
+		 IIO_ST('u', sizeof(struct gyro_3d_sample) * 8,
+			sizeof(struct gyro_3d_sample) * 8 , 0), 0),
+};
+
+static ssize_t gyro_3d_read_gyro(struct device *dev,
+				struct device_attribute *attr,
+				char *buf)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	struct gyro_3d_state *gyro_state =
+			(struct gyro_3d_state *)st->private;
+	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
+	int report_id = -1;
+
+	switch (this_attr->address) {
+	case HID_USAGE_SENSOR_DATA_MOTION_ANGULAR_VELOCITY_X_AXIS:
+		report_id = gyro_state->gyro_x.report_id;
+		break;
+	case HID_USAGE_SENSOR_DATA_MOTION_ANGULAR_VELOCITY_Y_AXIS:
+		report_id = gyro_state->gyro_y.report_id;
+		break;
+	case HID_USAGE_SENSOR_DATA_MOTION_ANGULAR_VELOCITY_Z_AXIS:
+		report_id = gyro_state->gyro_z.report_id;
+		break;
+	default:
+		break;
+	}
+	if (report_id < 0)
+		return -EINVAL;
+
+	return sensor_hub_input_attr_get_value(st->hdev,
+			HID_USAGE_SENSOR_GYRO_3D, this_attr->address,
+			report_id, 4, buf);
+}
+
+static int gyro_3d_read_raw(struct iio_dev *indio_dev,
+			      struct iio_chan_spec const *chan,
+			      int *val, int *val2,
+			      long mask)
+{
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	struct gyro_3d_state *gyro_state =
+			(struct gyro_3d_state *)st->private;
+	*val = 0;
+	*val2 = 0;
+
+	switch (mask) {
+	case 0:
+		break;
+	case IIO_CHAN_INFO_SCALE:
+		*val = gyro_state->gyro_x.units;
+		break;
+	case IIO_CHAN_INFO_OFFSET:
+		*val = gyro_state->gyro_x.unit_expo;
+		break;
+	default:
+		break;
+
+	}
+	return IIO_VAL_INT;
+}
+
+static int gyro_3d_write_raw(struct iio_dev *indio_dev,
+			       struct iio_chan_spec const *chan,
+			       int val,
+			       int val2,
+			       long mask)
+{
+	printk(KERN_ERR "%s\n", __func__);
+
+	return 0;
+}
+
+/* Usage specific attributes */
+#define IIO_DEV_ATTR_GYRO_OFFSET(_mode, _show, _store, _addr)  \
+	IIO_DEVICE_ATTR(gyro_offset, _mode, _show, _store, _addr)
+
+#define IIO_DEV_ATTR_GYRO_X_OFFSET(_mode, _show, _store, _addr)        \
+	IIO_DEVICE_ATTR(gyro_x_offset, _mode, _show, _store, _addr)
+
+#define IIO_DEV_ATTR_GYRO_Y_OFFSET(_mode, _show, _store, _addr)        \
+	IIO_DEVICE_ATTR(gyro_y_offset, _mode, _show, _store, _addr)
+
+#define IIO_DEV_ATTR_GYRO_Z_OFFSET(_mode, _show, _store, _addr)        \
+	IIO_DEVICE_ATTR(gyro_z_offset, _mode, _show, _store, _addr)
+
+static IIO_DEV_ATTR_GYRO_X_OFFSET(S_IWUSR | S_IRUGO, gyro_3d_read_gyro,
+		 NULL, HID_USAGE_SENSOR_DATA_MOTION_ANGULAR_VELOCITY_X_AXIS);
+static IIO_DEV_ATTR_GYRO_Y_OFFSET(S_IWUSR | S_IRUGO, gyro_3d_read_gyro,
+		 NULL, HID_USAGE_SENSOR_DATA_MOTION_ANGULAR_VELOCITY_Y_AXIS);
+static IIO_DEV_ATTR_GYRO_Z_OFFSET(S_IWUSR | S_IRUGO, gyro_3d_read_gyro,
+		 NULL, HID_USAGE_SENSOR_DATA_MOTION_ANGULAR_VELOCITY_Z_AXIS);
+
+static struct attribute *gyro_3d_attributes[] = {
+	/* common attributes */
+	&iio_dev_attr_poll_interval.dev_attr.attr,
+	&iio_dev_attr_sensitivity.dev_attr.attr,
+	&iio_dev_attr_activate.dev_attr.attr,
+	/* Usage specific attributes */
+	&iio_dev_attr_gyro_x_offset.dev_attr.attr,
+	&iio_dev_attr_gyro_y_offset.dev_attr.attr,
+	&iio_dev_attr_gyro_z_offset.dev_attr.attr,
+	NULL,
+};
+
+static const struct attribute_group gyro_3d_attribute_group = {
+	.attrs = gyro_3d_attributes,
+};
+
+static const struct iio_info gyro_3d_info = {
+	.attrs = &gyro_3d_attribute_group,
+	.driver_module = THIS_MODULE,
+	.read_raw = &gyro_3d_read_raw,
+	.write_raw = &gyro_3d_write_raw,
+};
+
+
+/* Function to push data to IIO ring */
+int gyro_3d_proc_event(struct hid_device *hdev, unsigned usage_id, void *priv)
+{
+	struct iio_dev *indio_dev = (struct iio_dev *)priv;
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	struct gyro_3d_state *gyro_state =
+			(struct gyro_3d_state *)st->private;
+
+	hid_dbg(hdev, "gyro_3d_proc_event\n");
+	if (st->data_ready)
+		hid_sensor_push_data_to_ring(indio_dev,
+				(u8 *)&gyro_state->gyro_sample_data,
+				sizeof(struct gyro_3d_sample));
+	else
+		hid_dbg(hdev, "gyro_3d_proc_event data not ready\n");
+	return 0;
+}
+
+/* Capture samples in local storage */
+int gyro_3d_capture_sample(struct hid_device *hdev, unsigned usage_id,
+				 size_t raw_len, char *raw_data, void *priv)
+{
+	struct iio_dev *indio_dev = (struct iio_dev *)priv;
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	struct gyro_3d_state *gyro_state =
+			(struct gyro_3d_state *)st->private;
+
+	switch (usage_id) {
+	case HID_USAGE_SENSOR_DATA_MOTION_ANGULAR_VELOCITY_X_AXIS:
+		gyro_state->gyro_sample_data.x_sz = raw_len;
+		gyro_state->gyro_sample_data.gyro_x =
+		*(u32 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_DATA_MOTION_ANGULAR_VELOCITY_Y_AXIS:
+		gyro_state->gyro_sample_data.y_sz = raw_len;
+		gyro_state->gyro_sample_data.gyro_y =
+		*(u32 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_DATA_MOTION_ANGULAR_VELOCITY_Z_AXIS:
+		gyro_state->gyro_sample_data.z_sz = raw_len;
+		gyro_state->gyro_sample_data.gyro_z =
+		*(u32 *)raw_data;
+		break;
+	default:
+		break;
+	}
+	return 0;
+}
+
+
+/* Parse report which is specific to an usage id*/
+static int gyro_3d_parse_report(struct hid_device *hdev, unsigned usage_id,
+				struct gyro_3d_state *st)
+{
+	int ret;
+
+	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
+			usage_id,
+			HID_USAGE_SENSOR_DATA_MOTION_ANGULAR_VELOCITY_X_AXIS,
+			&st->gyro_x);
+	if (!ret)
+		hid_dbg(hdev, "No Gyro X attribute\n");
+
+
+	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
+			usage_id,
+			HID_USAGE_SENSOR_DATA_MOTION_ANGULAR_VELOCITY_Y_AXIS,
+			&st->gyro_y);
+	if (!ret)
+		hid_dbg(hdev, "No Gyro Y attribute\n");
+
+
+	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
+			usage_id,
+			HID_USAGE_SENSOR_DATA_MOTION_ANGULAR_VELOCITY_Z_AXIS,
+			&st->gyro_z);
+	if (!ret)
+		hid_dbg(hdev, "No Gyro Z attribute\n");
+
+	hid_dbg(hdev, "gyro_3d %x:%x, %x:%x, %x:%x\n", st->gyro_x.index,
+			st->gyro_x.report_id,
+			st->gyro_y.index, st->gyro_y.report_id,
+			st->gyro_z.index, st->gyro_z.report_id);
+
+	return 0;
+}
+
+/* Entry function to initialize the processing for usage id */
+static int gyro_3d_enter(struct hid_device *hdev, unsigned usage_id,
+				void **priv)
+{
+	int ret = 0;
+	static char *name = "gyro_3d";
+	struct iio_dev *indio_dev;
+	struct gyro_3d_state *gyro_state;
+	struct hid_sensor_attributes *st;
+
+	gyro_state = kzalloc(sizeof(struct gyro_3d_state), GFP_KERNEL);
+	if (gyro_state == NULL) {
+		ret = -ENOMEM;
+		goto error_ret;
+	}
+
+	indio_dev = iio_allocate_device(sizeof(struct hid_sensor_attributes));
+	if (indio_dev == NULL) {
+		ret = -ENOMEM;
+		goto error_free_state;
+	}
+	st = iio_priv(indio_dev);
+	st->usage_id = usage_id;
+	st->hdev = hdev;
+	st->private = (void *)gyro_state;
+
+	ret = hid_sensor_parse_common_attributes(hdev, usage_id, st);
+	if (ret) {
+		hid_err(hdev, "failed to setup common attributes\n");
+		goto error_free_dev;
+	}
+	ret = gyro_3d_parse_report(hdev, usage_id, gyro_state);
+	if (ret) {
+		hid_err(hdev, "failed to setup attributes\n");
+		goto error_free_dev;
+	}
+
+	indio_dev->channels = gyro_3d_channels;
+	indio_dev->num_channels =
+				ARRAY_SIZE(gyro_3d_channels);
+	indio_dev->dev.parent = &hdev->dev;
+	indio_dev->info = &gyro_3d_info;
+	indio_dev->name = name;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+
+	ret = hid_sensor_configure_ring(indio_dev);
+	if (ret) {
+		hid_err(hdev, "failed to initialize the ring\n");
+		goto error_free_dev;
+	}
+
+	ret = iio_buffer_register(indio_dev,
+					gyro_3d_channels,
+					ARRAY_SIZE(gyro_3d_channels));
+	if (ret) {
+		hid_err(hdev, "failed to initialize the ring\n");
+		goto error_unreg_ring_funcs;
+	}
+	st->data_ready = true;
+	ret = hid_sensor_setup_trigger(indio_dev, name);
+	if (ret < 0) {
+		hid_err(hdev, "trigger setup failed\n");
+		goto error_uninit_ring;
+	}
+
+	ret = iio_device_register(indio_dev);
+	if (ret) {
+		hid_err(hdev, "device register failed\n");
+		goto error_remove_trigger;
+	}
+	*priv = (void *)indio_dev;
+	return ret;
+
+error_remove_trigger:
+		hid_sensor_remove_trigger(indio_dev);
+error_uninit_ring:
+		iio_buffer_unregister(indio_dev);
+error_unreg_ring_funcs:
+		hid_sensor_ring_cleanup(indio_dev);
+error_free_dev:
+		iio_free_device(indio_dev);
+error_free_state:
+		kfree(gyro_state);
+error_ret:
+		return ret;
+}
+
+static int gyro_3d_exit(struct hid_device *hdev, void *priv)
+{
+	int ret = 0;
+	struct iio_dev *indio_dev = (struct iio_dev *)priv;
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	struct gyro_3d_state *gyro_state =
+			(struct gyro_3d_state *)st->private;
+
+	iio_device_unregister(indio_dev);
+	hid_sensor_remove_trigger(indio_dev);
+	iio_buffer_unregister(indio_dev);
+	hid_sensor_ring_cleanup(indio_dev);
+	iio_free_device(indio_dev);
+
+	kfree(gyro_state);
+	return ret;
+}
+
+static struct sensor_hub_callbacks gyro_3d_callbacks = {
+	.enter = gyro_3d_enter,
+	.exit = gyro_3d_exit,
+	.send_event = gyro_3d_proc_event,
+	.capture_sample = gyro_3d_capture_sample,
+};
+
+struct sensor_hub_callbacks  *gyro_3d_register_callbacks(void)
+{
+	return &gyro_3d_callbacks;
+}
diff --git a/drivers/staging/hid-sensors/hid-sensor-hub.c b/drivers/staging/hid-sensors/hid-sensor-hub.c
index 55ae562..f98b5fe 100644
--- a/drivers/staging/hid-sensors/hid-sensor-hub.c
+++ b/drivers/staging/hid-sensors/hid-sensor-hub.c
@@ -61,6 +61,7 @@ struct sensor_hub_callbacks_list {
 
 static struct sensor_hub_callbacks_list usage_callbacks[] = {
 	{HID_USAGE_SENSOR_ACCEL_3D, accel_3d_register_callbacks},
+	{HID_USAGE_SENSOR_GYRO_3D, gyro_3d_register_callbacks},
 	{0}
 };
 
diff --git a/drivers/staging/hid-sensors/hid-sensor-interface.h b/drivers/staging/hid-sensors/hid-sensor-interface.h
index 3f4fe57..b242d87 100644
--- a/drivers/staging/hid-sensors/hid-sensor-interface.h
+++ b/drivers/staging/hid-sensors/hid-sensor-interface.h
@@ -86,5 +86,6 @@ void hid_sensor_remove_trigger(struct iio_dev *indio_dev);
 
 /* Sensor usage id processing callbacks */
 struct sensor_hub_callbacks  *accel_3d_register_callbacks(void);
+struct sensor_hub_callbacks  *gyro_3d_register_callbacks(void);
 
 #endif
-- 
1.7.7.6


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH, 6/7] HID-Sensors: Added Compass 3D
  2012-06-06 15:39 [PATCH, 0/7] HID Sensor Driver srinivas pandruvada
                   ` (2 preceding siblings ...)
  2012-06-06 15:39 ` [PATCH, 5/7] HID-Sensors: Added Gyro 3D srinivas pandruvada
@ 2012-06-06 15:39 ` srinivas pandruvada
  2012-06-06 15:39 ` [PATCH, 7/7] HID-Sensors: Added ALS srinivas pandruvada
  4 siblings, 0 replies; 16+ messages in thread
From: srinivas pandruvada @ 2012-06-06 15:39 UTC (permalink / raw)
  To: linux-input; +Cc: linux-iio, Srinivas pandruvada

From: Srinivas pandruvada <srinivas.pandruvada@intel.com>

Added usage id processing for Compass 3D. This uses IIO
interfaces "ring/buffer and trigger interface" to present
data to user mode.

Signed-off-by: Srinivas pandruvada <srinivas.pandruvada@intel.com>
---
 drivers/staging/hid-sensors/Makefile               |    1 +
 .../staging/hid-sensors/hid-sensor-compass-3d.c    |  385 ++++++++++++++++++++
 drivers/staging/hid-sensors/hid-sensor-hub.c       |    1 +
 drivers/staging/hid-sensors/hid-sensor-interface.h |    1 +
 4 files changed, 388 insertions(+), 0 deletions(-)
 create mode 100644 drivers/staging/hid-sensors/hid-sensor-compass-3d.c

diff --git a/drivers/staging/hid-sensors/Makefile b/drivers/staging/hid-sensors/Makefile
index 9c975a0..9762232 100644
--- a/drivers/staging/hid-sensors/Makefile
+++ b/drivers/staging/hid-sensors/Makefile
@@ -11,4 +11,5 @@ hid-sensors-y += hid-sensor-ring.o
 hid-sensors-y += hid-sensor-trigger.o
 hid-sensors-y += hid-sensor-accel-3d.o
 hid-sensors-y += hid-sensor-gyro-3d.o
+hid-sensors-y += hid-sensor-compass-3d.o
 obj-$(CONFIG_HID_SENSORS) += hid-sensors.o
diff --git a/drivers/staging/hid-sensors/hid-sensor-compass-3d.c b/drivers/staging/hid-sensors/hid-sensor-compass-3d.c
new file mode 100644
index 0000000..fb24059
--- /dev/null
+++ b/drivers/staging/hid-sensors/hid-sensor-compass-3d.c
@@ -0,0 +1,385 @@
+/*
+ * HID Sensors Driver
+ * Copyright (c) 2012, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+#include <linux/device.h>
+#include <linux/hid.h>
+#include <linux/usb.h>
+#include "usbhid/usbhid.h"
+#include <linux/module.h>
+#include <linux/slab.h>
+#include "iio/iio.h"
+#include "iio/sysfs.h"
+#include "iio/ring_sw.h"
+#include "iio/trigger.h"
+#include "hid-sensor-ids.h"
+#include "hid-sensor-interface.h"
+#include "hid-sensor-attributes.h"
+
+
+struct compass_3d_sample {
+	u16 x_sz;
+	u32 compass_x;
+	u16 y_sz;
+	u32 compass_y;
+	u16 z_sz;
+	u32 compass_z;
+} __packed;
+
+struct compass_3d_state {
+	struct hid_sensor_hub_attribute_info compass_x;
+	struct hid_sensor_hub_attribute_info compass_y;
+	struct hid_sensor_hub_attribute_info compass_z;
+	struct compass_3d_sample compass_sample_data;
+};
+
+
+enum compass_3d_chan {
+	COMPASS_X_Y_Z,
+};
+
+enum compass_3d_scan {
+	COMPASS_3D_SCAN_ACC_X_Y_Z,
+};
+
+static struct iio_chan_spec compass_3d_channels[] = {
+	IIO_CHAN(IIO_MAGN, 1, 0, 0, NULL, 0, IIO_MOD_X_AND_Y_AND_Z,
+	IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
+	IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
+	COMPASS_X_Y_Z, COMPASS_3D_SCAN_ACC_X_Y_Z,
+		 IIO_ST('u', sizeof(struct compass_3d_sample) * 8,
+			 sizeof(struct compass_3d_sample) * 8, 0), 0),
+};
+
+static ssize_t compass_3d_read_compass(struct device *dev,
+				struct device_attribute *attr,
+				char *buf)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	struct compass_3d_state *compass_state =
+			(struct compass_3d_state *)st->private;
+	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
+	int report_id = -1;
+
+	switch (this_attr->address) {
+	case HID_USAGE_SENSOR_DATA_ORIENTATION_MAGNETIC_FLUX_X_AXIS:
+		report_id = compass_state->compass_x.report_id;
+		break;
+	case HID_USAGE_SENSOR_DATA_ORIENTATION_MAGNETIC_FLUX_Y_AXIS:
+		report_id = compass_state->compass_y.report_id;
+		break;
+	case HID_USAGE_SENSOR_DATA_ORIENTATION_MAGNETIC_FLUX_Z_AXIS:
+		report_id = compass_state->compass_z.report_id;
+		break;
+	default:
+		break;
+	}
+	if (report_id < 0)
+		return -EINVAL;
+
+	return sensor_hub_input_attr_get_value(st->hdev,
+			HID_USAGE_SENSOR_COMPASS_3D, this_attr->address,
+			report_id, 4, buf);
+}
+
+static int compass_3d_read_raw(struct iio_dev *indio_dev,
+			      struct iio_chan_spec const *chan,
+			      int *val, int *val2,
+			      long mask)
+{
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	struct compass_3d_state *compass_state =
+			(struct compass_3d_state *)st->private;
+	*val = 0;
+	*val2 = 0;
+
+	switch (mask) {
+	case 0:
+		break;
+	case IIO_CHAN_INFO_SCALE:
+		*val = compass_state->compass_x.units;
+		break;
+	case IIO_CHAN_INFO_OFFSET:
+		*val = compass_state->compass_x.unit_expo;
+		break;
+	default:
+		break;
+
+	}
+	return IIO_VAL_INT;
+}
+
+static int compass_3d_write_raw(struct iio_dev *indio_dev,
+			       struct iio_chan_spec const *chan,
+			       int val,
+			       int val2,
+			       long mask)
+{
+	printk(KERN_ERR "%s\n", __func__);
+
+	return 0;
+}
+
+/* Usage specific attributes */
+#define IIO_DEV_ATTR_MAGN_OFFSET(_mode, _show, _store, _addr)  \
+	IIO_DEVICE_ATTR(compass_offset, _mode, _show, _store, _addr)
+
+#define IIO_DEV_ATTR_MAGN_X_OFFSET(_mode, _show, _store, _addr)        \
+	IIO_DEVICE_ATTR(compass_x_offset, _mode, _show, _store, _addr)
+
+#define IIO_DEV_ATTR_MAGN_Y_OFFSET(_mode, _show, _store, _addr)        \
+	IIO_DEVICE_ATTR(compass_y_offset, _mode, _show, _store, _addr)
+
+#define IIO_DEV_ATTR_MAGN_Z_OFFSET(_mode, _show, _store, _addr)        \
+	IIO_DEVICE_ATTR(compass_z_offset, _mode, _show, _store, _addr)
+
+static IIO_DEV_ATTR_MAGN_X_OFFSET(S_IWUSR | S_IRUGO, compass_3d_read_compass,
+		 NULL, HID_USAGE_SENSOR_DATA_ORIENTATION_MAGNETIC_FLUX_X_AXIS);
+static IIO_DEV_ATTR_MAGN_Y_OFFSET(S_IWUSR | S_IRUGO, compass_3d_read_compass,
+		 NULL, HID_USAGE_SENSOR_DATA_ORIENTATION_MAGNETIC_FLUX_Y_AXIS);
+static IIO_DEV_ATTR_MAGN_Z_OFFSET(S_IWUSR | S_IRUGO, compass_3d_read_compass,
+		 NULL, HID_USAGE_SENSOR_DATA_ORIENTATION_MAGNETIC_FLUX_Z_AXIS);
+
+static struct attribute *compass_3d_attributes[] = {
+	/* common attributes */
+	&iio_dev_attr_poll_interval.dev_attr.attr,
+	&iio_dev_attr_sensitivity.dev_attr.attr,
+	&iio_dev_attr_activate.dev_attr.attr,
+	/* Usage specific attributes */
+	&iio_dev_attr_compass_x_offset.dev_attr.attr,
+	&iio_dev_attr_compass_y_offset.dev_attr.attr,
+	&iio_dev_attr_compass_z_offset.dev_attr.attr,
+	NULL,
+};
+
+static const struct attribute_group compass_3d_attribute_group = {
+	.attrs = compass_3d_attributes,
+};
+
+static const struct iio_info compass_3d_info = {
+	.attrs = &compass_3d_attribute_group,
+	.driver_module = THIS_MODULE,
+	.read_raw = &compass_3d_read_raw,
+	.write_raw = &compass_3d_write_raw,
+};
+
+
+/* Function to push data to IIO ring */
+int compass_3d_proc_event(struct hid_device *hdev, unsigned usage_id,
+			void *priv)
+{
+	struct iio_dev *indio_dev = (struct iio_dev *)priv;
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	struct compass_3d_state *compass_state =
+			(struct compass_3d_state *)st->private;
+
+	hid_dbg(hdev, "compass_3d_proc_event\n");
+	if (st->data_ready)
+		hid_sensor_push_data_to_ring(indio_dev,
+				(u8 *)&compass_state->compass_sample_data,
+				sizeof(struct compass_3d_sample));
+	else
+		hid_dbg(hdev, "compass_3d_proc_event data not ready\n");
+	return 0;
+}
+
+/* Capture samples in local storage */
+int compass_3d_capture_sample(struct hid_device *hdev, unsigned usage_id,
+				 size_t raw_len, char *raw_data, void *priv)
+{
+	struct iio_dev *indio_dev = (struct iio_dev *)priv;
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	struct compass_3d_state *compass_state =
+			(struct compass_3d_state *)st->private;
+
+	switch (usage_id) {
+	case HID_USAGE_SENSOR_DATA_ORIENTATION_MAGNETIC_FLUX_X_AXIS:
+		compass_state->compass_sample_data.x_sz = raw_len;
+		compass_state->compass_sample_data.compass_x =
+		*(u32 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_DATA_ORIENTATION_MAGNETIC_FLUX_Y_AXIS:
+		compass_state->compass_sample_data.y_sz = raw_len;
+		compass_state->compass_sample_data.compass_y =
+		*(u32 *)raw_data;
+		break;
+	case HID_USAGE_SENSOR_DATA_ORIENTATION_MAGNETIC_FLUX_Z_AXIS:
+		compass_state->compass_sample_data.z_sz = raw_len;
+		compass_state->compass_sample_data.compass_z =
+		*(u32 *)raw_data;
+		break;
+	default:
+		break;
+	}
+	return 0;
+}
+
+
+/* Parse report which is specific to an usage id*/
+static int compass_3d_parse_report(struct hid_device *hdev, unsigned usage_id,
+				struct compass_3d_state *st)
+{
+	int ret;
+
+	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
+			usage_id,
+			HID_USAGE_SENSOR_DATA_ORIENTATION_MAGNETIC_FLUX_X_AXIS,
+			&st->compass_x);
+	if (!ret)
+		hid_dbg(hdev, "No Gyro X attribute\n");
+
+
+	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
+			usage_id,
+			HID_USAGE_SENSOR_DATA_ORIENTATION_MAGNETIC_FLUX_Y_AXIS,
+			&st->compass_y);
+	if (!ret)
+		hid_dbg(hdev, "No Gyro Y attribute\n");
+
+
+	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
+			usage_id,
+			HID_USAGE_SENSOR_DATA_ORIENTATION_MAGNETIC_FLUX_Z_AXIS,
+			&st->compass_z);
+	if (!ret)
+		hid_dbg(hdev, "No Gyro Z attribute\n");
+
+	hid_dbg(hdev, "compass_3d %x:%x, %x:%x, %x:%x\n", st->compass_x.index,
+			st->compass_x.report_id,
+			st->compass_y.index, st->compass_y.report_id,
+			st->compass_z.index, st->compass_z.report_id);
+
+	return 0;
+}
+
+/* Entry function to initialize the processing for usage id */
+static int compass_3d_enter(struct hid_device *hdev, unsigned usage_id,
+				void **priv)
+{
+	int ret = 0;
+	static char *name = "compass_3d";
+	struct iio_dev *indio_dev;
+	struct compass_3d_state *compass_state;
+	struct hid_sensor_attributes *st;
+
+	compass_state = kzalloc(sizeof(struct compass_3d_state), GFP_KERNEL);
+	if (compass_state == NULL) {
+		ret = -ENOMEM;
+		goto error_ret;
+	}
+
+	indio_dev = iio_allocate_device(sizeof(struct hid_sensor_attributes));
+	if (indio_dev == NULL) {
+		ret = -ENOMEM;
+		goto error_free_state;
+	}
+	st = iio_priv(indio_dev);
+	st->usage_id = usage_id;
+	st->hdev = hdev;
+	st->private = (void *)compass_state;
+
+	ret = hid_sensor_parse_common_attributes(hdev, usage_id, st);
+	if (ret) {
+		hid_err(hdev, "failed to setup common attributes\n");
+		goto error_free_dev;
+	}
+	ret = compass_3d_parse_report(hdev, usage_id, compass_state);
+	if (ret) {
+		hid_err(hdev, "failed to setup attributes\n");
+		goto error_free_dev;
+	}
+
+	indio_dev->channels = compass_3d_channels;
+	indio_dev->num_channels =
+				ARRAY_SIZE(compass_3d_channels);
+	indio_dev->dev.parent = &hdev->dev;
+	indio_dev->info = &compass_3d_info;
+	indio_dev->name = name;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+
+	ret = hid_sensor_configure_ring(indio_dev);
+	if (ret) {
+		hid_err(hdev, "failed to initialize the ring\n");
+		goto error_free_dev;
+	}
+
+	ret = iio_buffer_register(indio_dev,
+					compass_3d_channels,
+					ARRAY_SIZE(compass_3d_channels));
+	if (ret) {
+		hid_err(hdev, "failed to initialize the ring\n");
+		goto error_unreg_ring_funcs;
+	}
+	st->data_ready = true;
+	ret = hid_sensor_setup_trigger(indio_dev, name);
+	if (ret < 0) {
+		hid_err(hdev, "trigger setup failed\n");
+		goto error_uninit_ring;
+	}
+
+	ret = iio_device_register(indio_dev);
+	if (ret) {
+		hid_err(hdev, "device register failed\n");
+		goto error_remove_trigger;
+	}
+	*priv = (void *)indio_dev;
+	return ret;
+
+error_remove_trigger:
+		hid_sensor_remove_trigger(indio_dev);
+error_uninit_ring:
+		iio_buffer_unregister(indio_dev);
+error_unreg_ring_funcs:
+		hid_sensor_ring_cleanup(indio_dev);
+error_free_dev:
+		iio_free_device(indio_dev);
+error_free_state:
+		kfree(compass_state);
+error_ret:
+		return ret;
+}
+
+static int compass_3d_exit(struct hid_device *hdev, void *priv)
+{
+	int ret = 0;
+	struct iio_dev *indio_dev = (struct iio_dev *)priv;
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	struct compass_3d_state *compass_state =
+			(struct compass_3d_state *)st->private;
+
+	iio_device_unregister(indio_dev);
+	hid_sensor_remove_trigger(indio_dev);
+	iio_buffer_unregister(indio_dev);
+	hid_sensor_ring_cleanup(indio_dev);
+	iio_free_device(indio_dev);
+
+	kfree(compass_state);
+	return ret;
+}
+
+static struct sensor_hub_callbacks compass_3d_callbacks = {
+	.enter = compass_3d_enter,
+	.exit = compass_3d_exit,
+	.send_event = compass_3d_proc_event,
+	.capture_sample = compass_3d_capture_sample,
+};
+
+struct sensor_hub_callbacks  *compass_3d_register_callbacks(void)
+{
+	return &compass_3d_callbacks;
+}
diff --git a/drivers/staging/hid-sensors/hid-sensor-hub.c b/drivers/staging/hid-sensors/hid-sensor-hub.c
index f98b5fe..d61affa 100644
--- a/drivers/staging/hid-sensors/hid-sensor-hub.c
+++ b/drivers/staging/hid-sensors/hid-sensor-hub.c
@@ -62,6 +62,7 @@ struct sensor_hub_callbacks_list {
 static struct sensor_hub_callbacks_list usage_callbacks[] = {
 	{HID_USAGE_SENSOR_ACCEL_3D, accel_3d_register_callbacks},
 	{HID_USAGE_SENSOR_GYRO_3D, gyro_3d_register_callbacks},
+	{HID_USAGE_SENSOR_COMPASS_3D, compass_3d_register_callbacks},
 	{0}
 };
 
diff --git a/drivers/staging/hid-sensors/hid-sensor-interface.h b/drivers/staging/hid-sensors/hid-sensor-interface.h
index b242d87..b0df328 100644
--- a/drivers/staging/hid-sensors/hid-sensor-interface.h
+++ b/drivers/staging/hid-sensors/hid-sensor-interface.h
@@ -87,5 +87,6 @@ void hid_sensor_remove_trigger(struct iio_dev *indio_dev);
 /* Sensor usage id processing callbacks */
 struct sensor_hub_callbacks  *accel_3d_register_callbacks(void);
 struct sensor_hub_callbacks  *gyro_3d_register_callbacks(void);
+struct sensor_hub_callbacks  *compass_3d_register_callbacks(void);
 
 #endif
-- 
1.7.7.6


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* [PATCH, 7/7] HID-Sensors: Added ALS
  2012-06-06 15:39 [PATCH, 0/7] HID Sensor Driver srinivas pandruvada
                   ` (3 preceding siblings ...)
  2012-06-06 15:39 ` [PATCH, 6/7] HID-Sensors: Added Compass 3D srinivas pandruvada
@ 2012-06-06 15:39 ` srinivas pandruvada
  4 siblings, 0 replies; 16+ messages in thread
From: srinivas pandruvada @ 2012-06-06 15:39 UTC (permalink / raw)
  To: linux-input; +Cc: linux-iio, Srinivas pandruvada

From: Srinivas pandruvada <srinivas.pandruvada@intel.com>

Added usage id processing for ALS. This uses IIO
interfaces "ring/buffer and trigger interface" to present
data to user mode.

Signed-off-by: srinivas pandruvada <srinivas.pandruvada@intel.com>
---
 drivers/staging/hid-sensors/Makefile               |    1 +
 drivers/staging/hid-sensors/hid-sensor-als.c       |  326 ++++++++++++++++++++
 drivers/staging/hid-sensors/hid-sensor-hub.c       |    1 +
 drivers/staging/hid-sensors/hid-sensor-interface.h |    1 +
 4 files changed, 329 insertions(+), 0 deletions(-)
 create mode 100644 drivers/staging/hid-sensors/hid-sensor-als.c

diff --git a/drivers/staging/hid-sensors/Makefile b/drivers/staging/hid-sensors/Makefile
index 9762232..e8d728a 100644
--- a/drivers/staging/hid-sensors/Makefile
+++ b/drivers/staging/hid-sensors/Makefile
@@ -12,4 +12,5 @@ hid-sensors-y += hid-sensor-trigger.o
 hid-sensors-y += hid-sensor-accel-3d.o
 hid-sensors-y += hid-sensor-gyro-3d.o
 hid-sensors-y += hid-sensor-compass-3d.o
+hid-sensors-y += hid-sensor-als.o
 obj-$(CONFIG_HID_SENSORS) += hid-sensors.o
diff --git a/drivers/staging/hid-sensors/hid-sensor-als.c b/drivers/staging/hid-sensors/hid-sensor-als.c
new file mode 100644
index 0000000..360e0c2
--- /dev/null
+++ b/drivers/staging/hid-sensors/hid-sensor-als.c
@@ -0,0 +1,326 @@
+/*
+ * HID Sensors Driver
+ * Copyright (c) 2012, Intel Corporation.
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms and conditions of the GNU General Public License,
+ * version 2, as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along with
+ * this program; if not, write to the Free Software Foundation, Inc.,
+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ */
+#include <linux/device.h>
+#include <linux/hid.h>
+#include <linux/usb.h>
+#include "usbhid/usbhid.h"
+#include <linux/module.h>
+#include <linux/slab.h>
+#include "iio/iio.h"
+#include "iio/sysfs.h"
+#include "iio/ring_sw.h"
+#include "iio/trigger.h"
+#include "hid-sensor-ids.h"
+#include "hid-sensor-interface.h"
+#include "hid-sensor-attributes.h"
+
+
+struct als_sample {
+	u16 illum;
+	u16 chromocity;
+} __packed;
+
+struct als_state {
+	struct hid_sensor_hub_attribute_info als_illum;
+	struct hid_sensor_hub_attribute_info als_chromocity;
+	struct als_sample als_sample_data;
+};
+
+
+enum als_chan {
+	ALS_ILLUM,
+};
+
+enum als_scan {
+	ALS_ILLUM_SCAN_ILLUM,
+};
+
+static struct iio_chan_spec als_channels[] = {
+	IIO_CHAN(IIO_INTENSITY, 1, 0, 0, NULL, 0, IIO_MOD_LIGHT_BOTH,
+	IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
+	IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
+	ALS_ILLUM, ALS_ILLUM_SCAN_ILLUM,
+	IIO_ST('u', 32, 32, 32), 0),
+};
+
+static ssize_t als_read(struct device *dev,
+				struct device_attribute *attr,
+				char *buf)
+{
+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	struct als_state *als_state =
+			(struct als_state *)st->private;
+	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
+	int report_id = -1;
+
+	switch (this_attr->address) {
+	case HID_USAGE_SENSOR_DATA_LIGHT_ILLUMINANCE:
+		report_id = als_state->als_illum.report_id;
+		break;
+
+	default:
+		break;
+	}
+	if (report_id < 0)
+		return -EINVAL;
+
+	return sensor_hub_input_attr_get_value(st->hdev,
+			HID_USAGE_SENSOR_ALS, this_attr->address,
+			report_id, 4, buf);
+}
+
+static int als_read_raw(struct iio_dev *indio_dev,
+			      struct iio_chan_spec const *chan,
+			      int *val, int *val2,
+			      long mask)
+{
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	struct als_state *als_state =
+			(struct als_state *)st->private;
+	*val = 0;
+	*val2 = 0;
+
+	switch (mask) {
+	case 0:
+		break;
+	case IIO_CHAN_INFO_SCALE:
+		*val = als_state->als_illum.units;
+		break;
+	case IIO_CHAN_INFO_OFFSET:
+		*val = als_state->als_illum.unit_expo;
+		break;
+	default:
+		break;
+
+	}
+	return IIO_VAL_INT;
+}
+
+static int als_write_raw(struct iio_dev *indio_dev,
+			       struct iio_chan_spec const *chan,
+			       int val,
+			       int val2,
+			       long mask)
+{
+	printk(KERN_ERR "%s\n", __func__);
+
+	return 0;
+}
+
+/* Usage specific attributes */
+static DEVICE_ATTR(illuminance0_input, S_IRUGO, als_read, NULL);
+
+static struct attribute *als_attributes[] = {
+	/* common attributes */
+	&iio_dev_attr_poll_interval.dev_attr.attr,
+	&iio_dev_attr_sensitivity.dev_attr.attr,
+	&iio_dev_attr_activate.dev_attr.attr,
+	/* Usage specific attributes */
+	&dev_attr_illuminance0_input.attr,
+	NULL,
+};
+
+static const struct attribute_group als_attribute_group = {
+	.attrs = als_attributes,
+};
+
+static const struct iio_info als_info = {
+	.attrs = &als_attribute_group,
+	.driver_module = THIS_MODULE,
+	.read_raw = &als_read_raw,
+	.write_raw = &als_write_raw,
+};
+
+
+/* Function to push data to IIO ring */
+int als_proc_event(struct hid_device *hdev, unsigned usage_id, void *priv)
+{
+	struct iio_dev *indio_dev = (struct iio_dev *)priv;
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	struct als_state *als_state =
+			(struct als_state *)st->private;
+
+	hid_dbg(hdev, "als_proc_event\n");
+	if (st->data_ready)
+		hid_sensor_push_data_to_ring(indio_dev,
+				(u8 *)&als_state->als_sample_data,
+				sizeof(struct als_sample));
+	else
+		hid_dbg(hdev, "als_proc_event data not ready\n");
+	return 0;
+}
+
+/* Capture samples in local storage */
+int als_capture_sample(struct hid_device *hdev, unsigned usage_id,
+				 size_t raw_len, char *raw_data, void *priv)
+{
+	struct iio_dev *indio_dev = (struct iio_dev *)priv;
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	struct als_state *als_state =
+			(struct als_state *)st->private;
+
+	switch (usage_id) {
+	case HID_USAGE_SENSOR_DATA_LIGHT_ILLUMINANCE:
+		als_state->als_sample_data.illum =
+		*(u32 *)raw_data;
+		break;
+	default:
+		break;
+	}
+	return 0;
+}
+
+
+/* Parse report which is specific to an usage id*/
+static int als_parse_report(struct hid_device *hdev, unsigned usage_id,
+				struct als_state *st)
+{
+	int ret;
+
+	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
+			usage_id,
+			HID_USAGE_SENSOR_DATA_LIGHT_ILLUMINANCE,
+			&st->als_illum);
+	if (!ret)
+		hid_dbg(hdev, "No Light Illum attribute\n");
+
+
+	hid_dbg(hdev, "als %x:%x\n", st->als_illum.index,
+			st->als_illum.report_id);
+
+	return 0;
+}
+
+/* Entry function to initialize the processing for usage id */
+static int als_enter(struct hid_device *hdev, unsigned usage_id,
+				void **priv)
+{
+	int ret = 0;
+	static char *name = "als";
+	struct iio_dev *indio_dev;
+	struct als_state *als_state;
+	struct hid_sensor_attributes *st;
+
+	als_state = kzalloc(sizeof(struct als_state), GFP_KERNEL);
+	if (als_state == NULL) {
+		ret = -ENOMEM;
+		goto error_ret;
+	}
+
+	indio_dev = iio_allocate_device(sizeof(struct hid_sensor_attributes));
+	if (indio_dev == NULL) {
+		ret = -ENOMEM;
+		goto error_free_state;
+	}
+	st = iio_priv(indio_dev);
+	st->usage_id = usage_id;
+	st->hdev = hdev;
+	st->private = (void *)als_state;
+
+	ret = hid_sensor_parse_common_attributes(hdev, usage_id, st);
+	if (ret) {
+		hid_err(hdev, "failed to setup common attributes\n");
+		goto error_free_dev;
+	}
+	ret = als_parse_report(hdev, usage_id, als_state);
+	if (ret) {
+		hid_err(hdev, "failed to setup attributes\n");
+		goto error_free_dev;
+	}
+
+	indio_dev->channels = als_channels;
+	indio_dev->num_channels =
+				ARRAY_SIZE(als_channels);
+	indio_dev->dev.parent = &hdev->dev;
+	indio_dev->info = &als_info;
+	indio_dev->name = name;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+
+	ret = hid_sensor_configure_ring(indio_dev);
+	if (ret) {
+		hid_err(hdev, "failed to initialize the ring\n");
+		goto error_free_dev;
+	}
+
+	ret = iio_buffer_register(indio_dev,
+					als_channels,
+					ARRAY_SIZE(als_channels));
+	if (ret) {
+		hid_err(hdev, "failed to initialize the ring\n");
+		goto error_unreg_ring_funcs;
+	}
+	st->data_ready = true;
+	ret = hid_sensor_setup_trigger(indio_dev, name);
+	if (ret < 0) {
+		hid_err(hdev, "trigger setup failed\n");
+		goto error_uninit_ring;
+	}
+
+	ret = iio_device_register(indio_dev);
+	if (ret) {
+		hid_err(hdev, "device register failed\n");
+		goto error_remove_trigger;
+	}
+	*priv = (void *)indio_dev;
+	return ret;
+
+error_remove_trigger:
+		hid_sensor_remove_trigger(indio_dev);
+error_uninit_ring:
+		iio_buffer_unregister(indio_dev);
+error_unreg_ring_funcs:
+		hid_sensor_ring_cleanup(indio_dev);
+error_free_dev:
+		iio_free_device(indio_dev);
+error_free_state:
+		kfree(als_state);
+error_ret:
+		return ret;
+}
+
+static int als_exit(struct hid_device *hdev, void *priv)
+{
+	int ret = 0;
+	struct iio_dev *indio_dev = (struct iio_dev *)priv;
+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
+	struct als_state *als_state =
+			(struct als_state *)st->private;
+
+	iio_device_unregister(indio_dev);
+	hid_sensor_remove_trigger(indio_dev);
+	iio_buffer_unregister(indio_dev);
+	hid_sensor_ring_cleanup(indio_dev);
+	iio_free_device(indio_dev);
+
+	kfree(als_state);
+	return ret;
+}
+
+static struct sensor_hub_callbacks als_callbacks = {
+	.enter = als_enter,
+	.exit = als_exit,
+	.send_event = als_proc_event,
+	.capture_sample = als_capture_sample,
+};
+
+struct sensor_hub_callbacks  *als_register_callbacks(void)
+{
+	return &als_callbacks;
+}
diff --git a/drivers/staging/hid-sensors/hid-sensor-hub.c b/drivers/staging/hid-sensors/hid-sensor-hub.c
index d61affa..6d724da 100644
--- a/drivers/staging/hid-sensors/hid-sensor-hub.c
+++ b/drivers/staging/hid-sensors/hid-sensor-hub.c
@@ -63,6 +63,7 @@ static struct sensor_hub_callbacks_list usage_callbacks[] = {
 	{HID_USAGE_SENSOR_ACCEL_3D, accel_3d_register_callbacks},
 	{HID_USAGE_SENSOR_GYRO_3D, gyro_3d_register_callbacks},
 	{HID_USAGE_SENSOR_COMPASS_3D, compass_3d_register_callbacks},
+	{HID_USAGE_SENSOR_ALS, als_register_callbacks},
 	{0}
 };
 
diff --git a/drivers/staging/hid-sensors/hid-sensor-interface.h b/drivers/staging/hid-sensors/hid-sensor-interface.h
index b0df328..2d283ae 100644
--- a/drivers/staging/hid-sensors/hid-sensor-interface.h
+++ b/drivers/staging/hid-sensors/hid-sensor-interface.h
@@ -88,5 +88,6 @@ void hid_sensor_remove_trigger(struct iio_dev *indio_dev);
 struct sensor_hub_callbacks  *accel_3d_register_callbacks(void);
 struct sensor_hub_callbacks  *gyro_3d_register_callbacks(void);
 struct sensor_hub_callbacks  *compass_3d_register_callbacks(void);
+struct sensor_hub_callbacks  *als_register_callbacks(void);
 
 #endif
-- 
1.7.7.6


^ permalink raw reply related	[flat|nested] 16+ messages in thread

* Re: [PATCH, 4/7] HID-Sensors: Added accelerometer 3D
  2012-06-06 15:39 ` [PATCH, 4/7] HID-Sensors: Added accelerometer 3D srinivas pandruvada
@ 2012-06-06 16:28   ` Jonathan Cameron
  2012-06-06 16:57     ` Pandruvada, Srinivas
  0 siblings, 1 reply; 16+ messages in thread
From: Jonathan Cameron @ 2012-06-06 16:28 UTC (permalink / raw)
  To: srinivas pandruvada, linux-input; +Cc: linux-iio



srinivas pandruvada <srinivas.pandruvada@intel.com> wrote:

>From: Srinivas pandruvada <srinivas.pandruvada@intel.com>
>
>Added usage id processing for Accelrometer 3D. This uses IIO
>interfaces "ring/buffer and trigger interface" to present
>data to user mode.

I do not understand the data format.  The way iio describes the format is done through sysfs attrs built from the iio_Chan spec... that way a scan is made up of a number of channel readings each taken at roughly the same time.  However each is separately described.  Perhaps the description needs extending.  Please describe the format.
>
>Signed-off-by: Srinivas pandruvada <srinivas.pandruvada@intel.com>
>---
> drivers/staging/hid-sensors/Makefile               |    1 +
>drivers/staging/hid-sensors/hid-sensor-accel-3d.c  |  387
>++++++++++++++++++++
> drivers/staging/hid-sensors/hid-sensor-hub.c       |    1 +
> drivers/staging/hid-sensors/hid-sensor-interface.h |    3 +
> 4 files changed, 392 insertions(+), 0 deletions(-)
> create mode 100644 drivers/staging/hid-sensors/hid-sensor-accel-3d.c
>
>diff --git a/drivers/staging/hid-sensors/Makefile
>b/drivers/staging/hid-sensors/Makefile
>index 9a03953..4412079 100644
>--- a/drivers/staging/hid-sensors/Makefile
>+++ b/drivers/staging/hid-sensors/Makefile
>@@ -9,4 +9,5 @@ hid-sensors-y := hid-sensor-hub.o
> hid-sensors-y += hid-sensor-attributes.o
> hid-sensors-y += hid-sensor-ring.o
> hid-sensors-y += hid-sensor-trigger.o
>+hid-sensors-y += hid-sensor-accel-3d.o
> obj-$(CONFIG_HID_SENSORS) += hid-sensors.o
>diff --git a/drivers/staging/hid-sensors/hid-sensor-accel-3d.c
>b/drivers/staging/hid-sensors/hid-sensor-accel-3d.c
>new file mode 100644
>index 0000000..ffe2639
>--- /dev/null
>+++ b/drivers/staging/hid-sensors/hid-sensor-accel-3d.c
>@@ -0,0 +1,387 @@
>+/*
>+ * HID Sensors Driver
>+ * Copyright (c) 2012, Intel Corporation.
>+ *
>+ * This program is free software; you can redistribute it and/or
>modify it
>+ * under the terms and conditions of the GNU General Public License,
>+ * version 2, as published by the Free Software Foundation.
>+ *
>+ * This program is distributed in the hope it will be useful, but
>WITHOUT
>+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
>or
>+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
>License for
>+ * more details.
>+ *
>+ * You should have received a copy of the GNU General Public License
>along with
>+ * this program; if not, write to the Free Software Foundation, Inc.,
>+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
>+ *
>+ */
>+#include <linux/device.h>
>+#include <linux/hid.h>
>+#include <linux/usb.h>
>+#include "usbhid/usbhid.h"
>+#include <linux/module.h>
>+#include <linux/slab.h>
>+#include "iio/iio.h"
>+#include "iio/sysfs.h"
>+#include "iio/ring_sw.h"
>+#include "iio/trigger.h"
>+#include "hid-sensor-ids.h"
>+#include "hid-sensor-interface.h"
>+#include "hid-sensor-attributes.h"
>+
>+
>+struct accel_3d_sample {
>+	u16 x_sz;
>+	u32 accel_x;
>+	u16 y_sz;
>+	u32 accel_y;
>+	u16 z_sz;
>+	u32 accel_z;
>+} __packed;
>+
>+struct accel_3d_state {
>+	struct hid_sensor_hub_attribute_info accel_x;
>+	struct hid_sensor_hub_attribute_info accel_y;
>+	struct hid_sensor_hub_attribute_info accel_z;
>+	struct accel_3d_sample accel_sample_data;
>+};
>+
>+
>+enum accel_3d_chan {
>+	ACCEL_X_Y_Z,
>+};
>+
>+enum accel_3d_scan {
>+	ACCEL_3D_SCAN_ACC_X_Y_Z,
>+};
>+
>+static struct iio_chan_spec accel_3d_channels[] = {
>+	IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_X_AND_Y_AND_Z,
>+	IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
>+	IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
>+	ACCEL_X_Y_Z, ACCEL_3D_SCAN_ACC_X_Y_Z,
>+		 IIO_ST('u', sizeof(struct accel_3d_sample) * 8,
>+		sizeof(struct accel_3d_sample) * 8, 0), 0),
>+};
>+
>+static ssize_t accel_3d_read_accel(struct device *dev,
>+				struct device_attribute *attr,
>+				char *buf)
>+{
>+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
>+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>+	struct accel_3d_state *accel_state =
>+			(struct accel_3d_state *)st->private;
>+	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
>+	int report_id = -1;
>+
>+	switch (this_attr->address) {
>+	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS:
>+		report_id = accel_state->accel_x.report_id;
>+		break;
>+	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS:
>+		report_id = accel_state->accel_y.report_id;
>+		break;
>+	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS:
>+		report_id = accel_state->accel_z.report_id;
>+		break;
>+	default:
>+		break;
>+	}
>+	if (report_id < 0)
>+		return -EINVAL;
>+
>+	return sensor_hub_input_attr_get_value(st->hdev,
>+			HID_USAGE_SENSOR_ACCEL_3D, this_attr->address,
>+			report_id, 4, buf);
>+}
>+
>+static int accel_3d_read_raw(struct iio_dev *indio_dev,
>+			      struct iio_chan_spec const *chan,
>+			      int *val, int *val2,
>+			      long mask)
>+{
>+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>+	struct accel_3d_state *accel_state =
>+			(struct accel_3d_state *)st->private;
>+	*val = 0;
>+	*val2 = 0;
>+
>+	switch (mask) {
>+	case 0:
>+		break;
>+	case IIO_CHAN_INFO_SCALE:
>+		*val = accel_state->accel_x.units;
>+		break;
>+	case IIO_CHAN_INFO_OFFSET:
>+		*val = accel_state->accel_x.unit_expo;
>+		break;
>+	default:
>+		break;
>+
>+	}
>+	return IIO_VAL_INT;
>+}
>+
>+static int accel_3d_write_raw(struct iio_dev *indio_dev,
>+			       struct iio_chan_spec const *chan,
>+			       int val,
>+			       int val2,
>+			       long mask)
>+{
>+	printk(KERN_ERR "%s\n", __func__);
>+
>+	return 0;
>+}
>+
>+/* Usage specific attributes */
>+#define IIO_DEV_ATTR_ACCEL_OFFSET(_mode, _show, _store, _addr)  \
>+	IIO_DEVICE_ATTR(accel_offset, _mode, _show, _store, _addr)
>+
>+#define IIO_DEV_ATTR_ACCEL_X_OFFSET(_mode, _show, _store, _addr)      
> \
>+	IIO_DEVICE_ATTR(accel_x_offset, _mode, _show, _store, _addr)
>+
>+#define IIO_DEV_ATTR_ACCEL_Y_OFFSET(_mode, _show, _store, _addr)      
> \
>+	IIO_DEVICE_ATTR(accel_y_offset, _mode, _show, _store, _addr)
>+
>+#define IIO_DEV_ATTR_ACCEL_Z_OFFSET(_mode, _show, _store, _addr)      
> \
>+	IIO_DEVICE_ATTR(accel_z_offset, _mode, _show, _store, _addr)
>+
>+#define IIO_DEV_ATTR_ACCEL_SENSITIVITY(_mode, _show, _store, _addr)   
>    \
>+	IIO_DEVICE_ATTR(accel_sensitivity, _mode, _show, _store, _addr)
>+
>+static IIO_DEV_ATTR_ACCEL_X_OFFSET(S_IWUSR | S_IRUGO,
>accel_3d_read_accel,
>+		 NULL, HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS);
>+static IIO_DEV_ATTR_ACCEL_Y_OFFSET(S_IWUSR | S_IRUGO,
>accel_3d_read_accel,
>+		 NULL, HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS);
>+static IIO_DEV_ATTR_ACCEL_Z_OFFSET(S_IWUSR | S_IRUGO,
>accel_3d_read_accel,
>+		 NULL, HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS);
>+
>+static struct attribute *accel_3d_attributes[] = {
>+	/* common attributes */
>+	&iio_dev_attr_poll_interval.dev_attr.attr,
>+	&iio_dev_attr_sensitivity.dev_attr.attr,
>+	&iio_dev_attr_activate.dev_attr.attr,
>+	/* Usage specific attributes */
>+	&iio_dev_attr_accel_x_offset.dev_attr.attr,
>+	&iio_dev_attr_accel_y_offset.dev_attr.attr,
>+	&iio_dev_attr_accel_z_offset.dev_attr.attr,
>+	NULL,
>+};
>+
>+static const struct attribute_group accel_3d_attribute_group = {
>+	.attrs = accel_3d_attributes,
>+};
>+
>+static const struct iio_info accel_3d_info = {
>+	.attrs = &accel_3d_attribute_group,
>+	.driver_module = THIS_MODULE,
>+	.read_raw = &accel_3d_read_raw,
>+	.write_raw = &accel_3d_write_raw,
>+};
>+
>+
>+/* Function to push data to IIO ring */
>+int accel_3d_proc_event(struct hid_device *hdev, unsigned usage_id,
>void *priv)
>+{
>+	struct iio_dev *indio_dev = (struct iio_dev *)priv;
>+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>+	struct accel_3d_state *accel_state =
>+			(struct accel_3d_state *)st->private;
>+
>+	hid_dbg(hdev, "accel_3d_proc_event\n");
>+	if (st->data_ready)
>+		hid_sensor_push_data_to_ring(indio_dev,
>+				(u8 *)&accel_state->accel_sample_data,
>+				sizeof(struct accel_3d_sample));
>+	else
>+		hid_dbg(hdev, "accel_3d_proc_event data not ready\n");
>+	return 0;
>+}
>+
>+/* Capture samples in local storage */
>+int accel_3d_capture_sample(struct hid_device *hdev, unsigned
>usage_id,
>+				 size_t raw_len, char *raw_data, void *priv)
>+{
>+	struct iio_dev *indio_dev = (struct iio_dev *)priv;
>+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>+	struct accel_3d_state *accel_state =
>+			(struct accel_3d_state *)st->private;
>+
>+	switch (usage_id) {
>+	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS:
>+		accel_state->accel_sample_data.x_sz = raw_len;
>+		accel_state->accel_sample_data.accel_x =
>+		*(u32 *)raw_data;
>+		break;
>+	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS:
>+		accel_state->accel_sample_data.y_sz = raw_len;
>+		accel_state->accel_sample_data.accel_y =
>+		*(u32 *)raw_data;
>+		break;
>+	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS:
>+		accel_state->accel_sample_data.z_sz = raw_len;
>+		accel_state->accel_sample_data.accel_z =
>+		*(u32 *)raw_data;
>+		break;
>+	default:
>+		break;
>+	}
>+	return 0;
>+}
>+
>+
>+/* Parse report which is specific to an usage id*/
>+static int accel_3d_parse_report(struct hid_device *hdev, unsigned
>usage_id,
>+				struct accel_3d_state *st)
>+{
>+	int ret;
>+
>+	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
>+			usage_id,
>+			HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS,
>+			&st->accel_x);
>+	if (!ret)
>+		hid_dbg(hdev, "No Accel X attribute\n");
>+
>+
>+	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
>+			usage_id,
>+			HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS,
>+			&st->accel_y);
>+	if (!ret)
>+		hid_dbg(hdev, "No Accel Y attribute\n");
>+
>+
>+	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
>+			usage_id,
>+			HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS,
>+			&st->accel_z);
>+	if (!ret)
>+		hid_dbg(hdev, "No Accel Z attribute\n");
>+
>+	hid_dbg(hdev, "accel_3d %x:%x, %x:%x, %x:%x\n", st->accel_x.index,
>+			st->accel_x.report_id,
>+			st->accel_y.index, st->accel_y.report_id,
>+			st->accel_z.index, st->accel_z.report_id);
>+
>+	return 0;
>+}
>+
>+/* Entry function to initialize the processing for usage id */
>+static int accel_3d_enter(struct hid_device *hdev, unsigned usage_id,
>+				void **priv)
>+{
>+	int ret = 0;
>+	static char *name = "accel_3d";
>+	struct iio_dev *indio_dev;
>+	struct accel_3d_state *accel_state;
>+	struct hid_sensor_attributes *st;
>+
>+	accel_state = kzalloc(sizeof(struct accel_3d_state), GFP_KERNEL);
>+	if (accel_state == NULL) {
>+		ret = -ENOMEM;
>+		goto error_ret;
>+	}
>+
>+	indio_dev = iio_allocate_device(sizeof(struct
>hid_sensor_attributes));
>+	if (indio_dev == NULL) {
>+		ret = -ENOMEM;
>+		goto error_free_state;
>+	}
>+	st = iio_priv(indio_dev);
>+	st->usage_id = usage_id;
>+	st->hdev = hdev;
>+	st->private = (void *)accel_state;
>+
>+	ret = hid_sensor_parse_common_attributes(hdev, usage_id, st);
>+	if (ret) {
>+		hid_err(hdev, "failed to setup common attributes\n");
>+		goto error_free_dev;
>+	}
>+	ret = accel_3d_parse_report(hdev, usage_id, accel_state);
>+	if (ret) {
>+		hid_err(hdev, "failed to setup attributes\n");
>+		goto error_free_dev;
>+	}
>+
>+	indio_dev->channels = accel_3d_channels;
>+	indio_dev->num_channels =
>+				ARRAY_SIZE(accel_3d_channels);
>+	indio_dev->dev.parent = &hdev->dev;
>+	indio_dev->info = &accel_3d_info;
>+	indio_dev->name = name;
>+	indio_dev->modes = INDIO_DIRECT_MODE;
>+
>+	ret = hid_sensor_configure_ring(indio_dev);
>+	if (ret) {
>+		hid_err(hdev, "failed to initialize the ring\n");
>+		goto error_free_dev;
>+	}
>+
>+	ret = iio_buffer_register(indio_dev,
>+					accel_3d_channels,
>+					ARRAY_SIZE(accel_3d_channels));
>+	if (ret) {
>+		hid_err(hdev, "failed to initialize the ring\n");
>+		goto error_unreg_ring_funcs;
>+	}
>+	st->data_ready = true;
>+	ret = hid_sensor_setup_trigger(indio_dev, name);
>+	if (ret < 0) {
>+		hid_err(hdev, "trigger setup failed\n");
>+		goto error_uninit_ring;
>+	}
>+
>+	ret = iio_device_register(indio_dev);
>+	if (ret) {
>+		hid_err(hdev, "device register failed\n");
>+		goto error_remove_trigger;
>+	}
>+	*priv = (void *)indio_dev;
>+	return ret;
>+
>+error_remove_trigger:
>+		hid_sensor_remove_trigger(indio_dev);
>+error_uninit_ring:
>+		iio_buffer_unregister(indio_dev);
>+error_unreg_ring_funcs:
>+		hid_sensor_ring_cleanup(indio_dev);
>+error_free_dev:
>+		iio_free_device(indio_dev);
>+error_free_state:
>+		kfree(accel_state);
>+error_ret:
>+		return ret;
>+}
>+
>+static int accel_3d_exit(struct hid_device *hdev, void *priv)
>+{
>+	int ret = 0;
>+	struct iio_dev *indio_dev = (struct iio_dev *)priv;
>+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>+	struct accel_3d_state *accel_state =
>+			(struct accel_3d_state *)st->private;
>+
>+	iio_device_unregister(indio_dev);
>+	hid_sensor_remove_trigger(indio_dev);
>+	iio_buffer_unregister(indio_dev);
>+	hid_sensor_ring_cleanup(indio_dev);
>+	iio_free_device(indio_dev);
>+
>+	kfree(accel_state);
>+	return ret;
>+}
>+
>+static struct sensor_hub_callbacks accel_3d_callbacks = {
>+	.enter = accel_3d_enter,
>+	.exit = accel_3d_exit,
>+	.send_event = accel_3d_proc_event,
>+	.capture_sample = accel_3d_capture_sample,
>+};
>+
>+struct sensor_hub_callbacks  *accel_3d_register_callbacks(void)
>+{
>+	return &accel_3d_callbacks;
>+}
>diff --git a/drivers/staging/hid-sensors/hid-sensor-hub.c
>b/drivers/staging/hid-sensors/hid-sensor-hub.c
>index 384e0d0..55ae562 100644
>--- a/drivers/staging/hid-sensors/hid-sensor-hub.c
>+++ b/drivers/staging/hid-sensors/hid-sensor-hub.c
>@@ -60,6 +60,7 @@ struct sensor_hub_callbacks_list {
> };
> 
> static struct sensor_hub_callbacks_list usage_callbacks[] = {
>+	{HID_USAGE_SENSOR_ACCEL_3D, accel_3d_register_callbacks},
> 	{0}
> };
> 
>diff --git a/drivers/staging/hid-sensors/hid-sensor-interface.h
>b/drivers/staging/hid-sensors/hid-sensor-interface.h
>index 477494f..3f4fe57 100644
>--- a/drivers/staging/hid-sensors/hid-sensor-interface.h
>+++ b/drivers/staging/hid-sensors/hid-sensor-interface.h
>@@ -84,4 +84,7 @@ void hid_sensor_push_data_to_ring(struct iio_dev
>*indio_dev, u8 *data,
> int hid_sensor_setup_trigger(struct iio_dev *indio_dev, char *name);
> void hid_sensor_remove_trigger(struct iio_dev *indio_dev);
> 
>+/* Sensor usage id processing callbacks */
>+struct sensor_hub_callbacks  *accel_3d_register_callbacks(void);
>+
> #endif
>-- 
>1.7.7.6
>
>--
>To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>the body of a message to majordomo@vger.kernel.org
>More majordomo info at  http://vger.kernel.org/majordomo-info.html

-- 
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* RE: [PATCH, 4/7] HID-Sensors: Added accelerometer 3D
  2012-06-06 16:28   ` Jonathan Cameron
@ 2012-06-06 16:57     ` Pandruvada, Srinivas
       [not found]       ` <4FA419E87744DF4DAECD5BCE1214B7A91931B547-P5GAC/sN6hk64kNsxIetb7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
  0 siblings, 1 reply; 16+ messages in thread
From: Pandruvada, Srinivas @ 2012-06-06 16:57 UTC (permalink / raw)
  To: Jonathan Cameron, linux-input@vger.kernel.org; +Cc: linux-iio@vger.kernel.org

The USB sensor spec has a report structure which it sends as part of report descriptor we get during initial plug in. This report structure describes elements and their sizes. For example, it may say that an Accelerometer X axis value as 4 bytes long and what is the exponent and unit. Also it sends what control elements it has.
The sequence is
- Set sensitivity, interval, activate sys-fs interface. The USB sensor will send an event by USB-IN report when the captured sample is changed by sensitivity value and stable for at least interval. Also you need to activate the sensor so that the usb will start sending events.

- Once USB report with the captured sample arrives, I format the data as defined in " struct accel_3d_sample" below and push to IIO ring buffer.
I define a single channel
	IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_X_AND_Y_AND_Z,
	IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
	IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
	ACCEL_X_Y_Z, ACCEL_3D_SCAN_ACC_X_Y_Z,
		 IIO_ST('u', sizeof(struct accel_3d_sample) * 8,
		sizeof(struct accel_3d_sample) * 8, 0), 0), };

Please suggest me if this is not the way IIO channel used. 

Thanks,
Srinivas



-----Original Message-----
From: Jonathan Cameron [mailto:jic23@cam.ac.uk] 
Sent: Wednesday, June 06, 2012 9:29 AM
To: Pandruvada, Srinivas; linux-input@vger.kernel.org
Cc: linux-iio@vger.kernel.org
Subject: Re: [PATCH, 4/7] HID-Sensors: Added accelerometer 3D



srinivas pandruvada <srinivas.pandruvada@intel.com> wrote:

>From: Srinivas pandruvada <srinivas.pandruvada@intel.com>
>
>Added usage id processing for Accelrometer 3D. This uses IIO interfaces 
>"ring/buffer and trigger interface" to present data to user mode.

I do not understand the data format.  The way iio describes the format is done through sysfs attrs built from the iio_Chan spec... that way a scan is made up of a number of channel readings each taken at roughly the same time.  However each is separately described.  Perhaps the description needs extending.  Please describe the format.
>
>Signed-off-by: Srinivas pandruvada <srinivas.pandruvada@intel.com>
>---
> drivers/staging/hid-sensors/Makefile               |    1 +
>drivers/staging/hid-sensors/hid-sensor-accel-3d.c  |  387
>++++++++++++++++++++
> drivers/staging/hid-sensors/hid-sensor-hub.c       |    1 +
> drivers/staging/hid-sensors/hid-sensor-interface.h |    3 +
> 4 files changed, 392 insertions(+), 0 deletions(-) create mode 100644 
> drivers/staging/hid-sensors/hid-sensor-accel-3d.c
>
>diff --git a/drivers/staging/hid-sensors/Makefile
>b/drivers/staging/hid-sensors/Makefile
>index 9a03953..4412079 100644
>--- a/drivers/staging/hid-sensors/Makefile
>+++ b/drivers/staging/hid-sensors/Makefile
>@@ -9,4 +9,5 @@ hid-sensors-y := hid-sensor-hub.o  hid-sensors-y += 
>hid-sensor-attributes.o  hid-sensors-y += hid-sensor-ring.o  
>hid-sensors-y += hid-sensor-trigger.o
>+hid-sensors-y += hid-sensor-accel-3d.o
> obj-$(CONFIG_HID_SENSORS) += hid-sensors.o diff --git 
>a/drivers/staging/hid-sensors/hid-sensor-accel-3d.c
>b/drivers/staging/hid-sensors/hid-sensor-accel-3d.c
>new file mode 100644
>index 0000000..ffe2639
>--- /dev/null
>+++ b/drivers/staging/hid-sensors/hid-sensor-accel-3d.c
>@@ -0,0 +1,387 @@
>+/*
>+ * HID Sensors Driver
>+ * Copyright (c) 2012, Intel Corporation.
>+ *
>+ * This program is free software; you can redistribute it and/or
>modify it
>+ * under the terms and conditions of the GNU General Public License,
>+ * version 2, as published by the Free Software Foundation.
>+ *
>+ * This program is distributed in the hope it will be useful, but
>WITHOUT
>+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
>or
>+ * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
>License for
>+ * more details.
>+ *
>+ * You should have received a copy of the GNU General Public License
>along with
>+ * this program; if not, write to the Free Software Foundation, Inc.,
>+ * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
>+ *
>+ */
>+#include <linux/device.h>
>+#include <linux/hid.h>
>+#include <linux/usb.h>
>+#include "usbhid/usbhid.h"
>+#include <linux/module.h>
>+#include <linux/slab.h>
>+#include "iio/iio.h"
>+#include "iio/sysfs.h"
>+#include "iio/ring_sw.h"
>+#include "iio/trigger.h"
>+#include "hid-sensor-ids.h"
>+#include "hid-sensor-interface.h"
>+#include "hid-sensor-attributes.h"
>+
>+
>+struct accel_3d_sample {
>+	u16 x_sz;
>+	u32 accel_x;
>+	u16 y_sz;
>+	u32 accel_y;
>+	u16 z_sz;
>+	u32 accel_z;
>+} __packed;
>+
>+struct accel_3d_state {
>+	struct hid_sensor_hub_attribute_info accel_x;
>+	struct hid_sensor_hub_attribute_info accel_y;
>+	struct hid_sensor_hub_attribute_info accel_z;
>+	struct accel_3d_sample accel_sample_data; };
>+
>+
>+enum accel_3d_chan {
>+	ACCEL_X_Y_Z,
>+};
>+
>+enum accel_3d_scan {
>+	ACCEL_3D_SCAN_ACC_X_Y_Z,
>+};
>+
>+static struct iio_chan_spec accel_3d_channels[] = {
>+	IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_X_AND_Y_AND_Z,
>+	IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
>+	IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
>+	ACCEL_X_Y_Z, ACCEL_3D_SCAN_ACC_X_Y_Z,
>+		 IIO_ST('u', sizeof(struct accel_3d_sample) * 8,
>+		sizeof(struct accel_3d_sample) * 8, 0), 0), };
>+
>+static ssize_t accel_3d_read_accel(struct device *dev,
>+				struct device_attribute *attr,
>+				char *buf)
>+{
>+	struct iio_dev *indio_dev = dev_get_drvdata(dev);
>+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>+	struct accel_3d_state *accel_state =
>+			(struct accel_3d_state *)st->private;
>+	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
>+	int report_id = -1;
>+
>+	switch (this_attr->address) {
>+	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS:
>+		report_id = accel_state->accel_x.report_id;
>+		break;
>+	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS:
>+		report_id = accel_state->accel_y.report_id;
>+		break;
>+	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS:
>+		report_id = accel_state->accel_z.report_id;
>+		break;
>+	default:
>+		break;
>+	}
>+	if (report_id < 0)
>+		return -EINVAL;
>+
>+	return sensor_hub_input_attr_get_value(st->hdev,
>+			HID_USAGE_SENSOR_ACCEL_3D, this_attr->address,
>+			report_id, 4, buf);
>+}
>+
>+static int accel_3d_read_raw(struct iio_dev *indio_dev,
>+			      struct iio_chan_spec const *chan,
>+			      int *val, int *val2,
>+			      long mask)
>+{
>+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>+	struct accel_3d_state *accel_state =
>+			(struct accel_3d_state *)st->private;
>+	*val = 0;
>+	*val2 = 0;
>+
>+	switch (mask) {
>+	case 0:
>+		break;
>+	case IIO_CHAN_INFO_SCALE:
>+		*val = accel_state->accel_x.units;
>+		break;
>+	case IIO_CHAN_INFO_OFFSET:
>+		*val = accel_state->accel_x.unit_expo;
>+		break;
>+	default:
>+		break;
>+
>+	}
>+	return IIO_VAL_INT;
>+}
>+
>+static int accel_3d_write_raw(struct iio_dev *indio_dev,
>+			       struct iio_chan_spec const *chan,
>+			       int val,
>+			       int val2,
>+			       long mask)
>+{
>+	printk(KERN_ERR "%s\n", __func__);
>+
>+	return 0;
>+}
>+
>+/* Usage specific attributes */
>+#define IIO_DEV_ATTR_ACCEL_OFFSET(_mode, _show, _store, _addr)  \
>+	IIO_DEVICE_ATTR(accel_offset, _mode, _show, _store, _addr)
>+
>+#define IIO_DEV_ATTR_ACCEL_X_OFFSET(_mode, _show, _store, _addr)      
> \
>+	IIO_DEVICE_ATTR(accel_x_offset, _mode, _show, _store, _addr)
>+
>+#define IIO_DEV_ATTR_ACCEL_Y_OFFSET(_mode, _show, _store, _addr)      
> \
>+	IIO_DEVICE_ATTR(accel_y_offset, _mode, _show, _store, _addr)
>+
>+#define IIO_DEV_ATTR_ACCEL_Z_OFFSET(_mode, _show, _store, _addr)      
> \
>+	IIO_DEVICE_ATTR(accel_z_offset, _mode, _show, _store, _addr)
>+
>+#define IIO_DEV_ATTR_ACCEL_SENSITIVITY(_mode, _show, _store, _addr)   
>    \
>+	IIO_DEVICE_ATTR(accel_sensitivity, _mode, _show, _store, _addr)
>+
>+static IIO_DEV_ATTR_ACCEL_X_OFFSET(S_IWUSR | S_IRUGO,
>accel_3d_read_accel,
>+		 NULL, HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS);
>+static IIO_DEV_ATTR_ACCEL_Y_OFFSET(S_IWUSR | S_IRUGO,
>accel_3d_read_accel,
>+		 NULL, HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS);
>+static IIO_DEV_ATTR_ACCEL_Z_OFFSET(S_IWUSR | S_IRUGO,
>accel_3d_read_accel,
>+		 NULL, HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS);
>+
>+static struct attribute *accel_3d_attributes[] = {
>+	/* common attributes */
>+	&iio_dev_attr_poll_interval.dev_attr.attr,
>+	&iio_dev_attr_sensitivity.dev_attr.attr,
>+	&iio_dev_attr_activate.dev_attr.attr,
>+	/* Usage specific attributes */
>+	&iio_dev_attr_accel_x_offset.dev_attr.attr,
>+	&iio_dev_attr_accel_y_offset.dev_attr.attr,
>+	&iio_dev_attr_accel_z_offset.dev_attr.attr,
>+	NULL,
>+};
>+
>+static const struct attribute_group accel_3d_attribute_group = {
>+	.attrs = accel_3d_attributes,
>+};
>+
>+static const struct iio_info accel_3d_info = {
>+	.attrs = &accel_3d_attribute_group,
>+	.driver_module = THIS_MODULE,
>+	.read_raw = &accel_3d_read_raw,
>+	.write_raw = &accel_3d_write_raw,
>+};
>+
>+
>+/* Function to push data to IIO ring */ int accel_3d_proc_event(struct 
>+hid_device *hdev, unsigned usage_id,
>void *priv)
>+{
>+	struct iio_dev *indio_dev = (struct iio_dev *)priv;
>+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>+	struct accel_3d_state *accel_state =
>+			(struct accel_3d_state *)st->private;
>+
>+	hid_dbg(hdev, "accel_3d_proc_event\n");
>+	if (st->data_ready)
>+		hid_sensor_push_data_to_ring(indio_dev,
>+				(u8 *)&accel_state->accel_sample_data,
>+				sizeof(struct accel_3d_sample));
>+	else
>+		hid_dbg(hdev, "accel_3d_proc_event data not ready\n");
>+	return 0;
>+}
>+
>+/* Capture samples in local storage */ int 
>+accel_3d_capture_sample(struct hid_device *hdev, unsigned
>usage_id,
>+				 size_t raw_len, char *raw_data, void *priv) {
>+	struct iio_dev *indio_dev = (struct iio_dev *)priv;
>+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>+	struct accel_3d_state *accel_state =
>+			(struct accel_3d_state *)st->private;
>+
>+	switch (usage_id) {
>+	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS:
>+		accel_state->accel_sample_data.x_sz = raw_len;
>+		accel_state->accel_sample_data.accel_x =
>+		*(u32 *)raw_data;
>+		break;
>+	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS:
>+		accel_state->accel_sample_data.y_sz = raw_len;
>+		accel_state->accel_sample_data.accel_y =
>+		*(u32 *)raw_data;
>+		break;
>+	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS:
>+		accel_state->accel_sample_data.z_sz = raw_len;
>+		accel_state->accel_sample_data.accel_z =
>+		*(u32 *)raw_data;
>+		break;
>+	default:
>+		break;
>+	}
>+	return 0;
>+}
>+
>+
>+/* Parse report which is specific to an usage id*/ static int 
>+accel_3d_parse_report(struct hid_device *hdev, unsigned
>usage_id,
>+				struct accel_3d_state *st)
>+{
>+	int ret;
>+
>+	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
>+			usage_id,
>+			HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS,
>+			&st->accel_x);
>+	if (!ret)
>+		hid_dbg(hdev, "No Accel X attribute\n");
>+
>+
>+	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
>+			usage_id,
>+			HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS,
>+			&st->accel_y);
>+	if (!ret)
>+		hid_dbg(hdev, "No Accel Y attribute\n");
>+
>+
>+	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
>+			usage_id,
>+			HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS,
>+			&st->accel_z);
>+	if (!ret)
>+		hid_dbg(hdev, "No Accel Z attribute\n");
>+
>+	hid_dbg(hdev, "accel_3d %x:%x, %x:%x, %x:%x\n", st->accel_x.index,
>+			st->accel_x.report_id,
>+			st->accel_y.index, st->accel_y.report_id,
>+			st->accel_z.index, st->accel_z.report_id);
>+
>+	return 0;
>+}
>+
>+/* Entry function to initialize the processing for usage id */ static 
>+int accel_3d_enter(struct hid_device *hdev, unsigned usage_id,
>+				void **priv)
>+{
>+	int ret = 0;
>+	static char *name = "accel_3d";
>+	struct iio_dev *indio_dev;
>+	struct accel_3d_state *accel_state;
>+	struct hid_sensor_attributes *st;
>+
>+	accel_state = kzalloc(sizeof(struct accel_3d_state), GFP_KERNEL);
>+	if (accel_state == NULL) {
>+		ret = -ENOMEM;
>+		goto error_ret;
>+	}
>+
>+	indio_dev = iio_allocate_device(sizeof(struct
>hid_sensor_attributes));
>+	if (indio_dev == NULL) {
>+		ret = -ENOMEM;
>+		goto error_free_state;
>+	}
>+	st = iio_priv(indio_dev);
>+	st->usage_id = usage_id;
>+	st->hdev = hdev;
>+	st->private = (void *)accel_state;
>+
>+	ret = hid_sensor_parse_common_attributes(hdev, usage_id, st);
>+	if (ret) {
>+		hid_err(hdev, "failed to setup common attributes\n");
>+		goto error_free_dev;
>+	}
>+	ret = accel_3d_parse_report(hdev, usage_id, accel_state);
>+	if (ret) {
>+		hid_err(hdev, "failed to setup attributes\n");
>+		goto error_free_dev;
>+	}
>+
>+	indio_dev->channels = accel_3d_channels;
>+	indio_dev->num_channels =
>+				ARRAY_SIZE(accel_3d_channels);
>+	indio_dev->dev.parent = &hdev->dev;
>+	indio_dev->info = &accel_3d_info;
>+	indio_dev->name = name;
>+	indio_dev->modes = INDIO_DIRECT_MODE;
>+
>+	ret = hid_sensor_configure_ring(indio_dev);
>+	if (ret) {
>+		hid_err(hdev, "failed to initialize the ring\n");
>+		goto error_free_dev;
>+	}
>+
>+	ret = iio_buffer_register(indio_dev,
>+					accel_3d_channels,
>+					ARRAY_SIZE(accel_3d_channels));
>+	if (ret) {
>+		hid_err(hdev, "failed to initialize the ring\n");
>+		goto error_unreg_ring_funcs;
>+	}
>+	st->data_ready = true;
>+	ret = hid_sensor_setup_trigger(indio_dev, name);
>+	if (ret < 0) {
>+		hid_err(hdev, "trigger setup failed\n");
>+		goto error_uninit_ring;
>+	}
>+
>+	ret = iio_device_register(indio_dev);
>+	if (ret) {
>+		hid_err(hdev, "device register failed\n");
>+		goto error_remove_trigger;
>+	}
>+	*priv = (void *)indio_dev;
>+	return ret;
>+
>+error_remove_trigger:
>+		hid_sensor_remove_trigger(indio_dev);
>+error_uninit_ring:
>+		iio_buffer_unregister(indio_dev);
>+error_unreg_ring_funcs:
>+		hid_sensor_ring_cleanup(indio_dev);
>+error_free_dev:
>+		iio_free_device(indio_dev);
>+error_free_state:
>+		kfree(accel_state);
>+error_ret:
>+		return ret;
>+}
>+
>+static int accel_3d_exit(struct hid_device *hdev, void *priv) {
>+	int ret = 0;
>+	struct iio_dev *indio_dev = (struct iio_dev *)priv;
>+	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>+	struct accel_3d_state *accel_state =
>+			(struct accel_3d_state *)st->private;
>+
>+	iio_device_unregister(indio_dev);
>+	hid_sensor_remove_trigger(indio_dev);
>+	iio_buffer_unregister(indio_dev);
>+	hid_sensor_ring_cleanup(indio_dev);
>+	iio_free_device(indio_dev);
>+
>+	kfree(accel_state);
>+	return ret;
>+}
>+
>+static struct sensor_hub_callbacks accel_3d_callbacks = {
>+	.enter = accel_3d_enter,
>+	.exit = accel_3d_exit,
>+	.send_event = accel_3d_proc_event,
>+	.capture_sample = accel_3d_capture_sample, };
>+
>+struct sensor_hub_callbacks  *accel_3d_register_callbacks(void)
>+{
>+	return &accel_3d_callbacks;
>+}
>diff --git a/drivers/staging/hid-sensors/hid-sensor-hub.c
>b/drivers/staging/hid-sensors/hid-sensor-hub.c
>index 384e0d0..55ae562 100644
>--- a/drivers/staging/hid-sensors/hid-sensor-hub.c
>+++ b/drivers/staging/hid-sensors/hid-sensor-hub.c
>@@ -60,6 +60,7 @@ struct sensor_hub_callbacks_list {  };
> 
> static struct sensor_hub_callbacks_list usage_callbacks[] = {
>+	{HID_USAGE_SENSOR_ACCEL_3D, accel_3d_register_callbacks},
> 	{0}
> };
> 
>diff --git a/drivers/staging/hid-sensors/hid-sensor-interface.h
>b/drivers/staging/hid-sensors/hid-sensor-interface.h
>index 477494f..3f4fe57 100644
>--- a/drivers/staging/hid-sensors/hid-sensor-interface.h
>+++ b/drivers/staging/hid-sensors/hid-sensor-interface.h
>@@ -84,4 +84,7 @@ void hid_sensor_push_data_to_ring(struct iio_dev 
>*indio_dev, u8 *data,  int hid_sensor_setup_trigger(struct iio_dev 
>*indio_dev, char *name);  void hid_sensor_remove_trigger(struct iio_dev 
>*indio_dev);
> 
>+/* Sensor usage id processing callbacks */ struct sensor_hub_callbacks  
>+*accel_3d_register_callbacks(void);
>+
> #endif
>--
>1.7.7.6
>
>--
>To unsubscribe from this list: send the line "unsubscribe linux-iio" in 
>the body of a message to majordomo@vger.kernel.org More majordomo info 
>at  http://vger.kernel.org/majordomo-info.html

--
Sent from my Android phone with K-9 Mail. Please excuse my brevity.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* RE: [PATCH, 4/7] HID-Sensors: Added accelerometer 3D
  2012-06-06 17:07         ` Lars-Peter Clausen
@ 2012-06-06 17:06           ` Pandruvada, Srinivas
  0 siblings, 0 replies; 16+ messages in thread
From: Pandruvada, Srinivas @ 2012-06-06 17:06 UTC (permalink / raw)
  To: Lars-Peter Clausen
  Cc: Jonathan Cameron, linux-input@vger.kernel.org,
	linux-iio@vger.kernel.org

Yes. You can download from:
www.usb.org/developers/hidpage/HUTRR39b.pdf

Thanks,
Srinivas

-----Original Message-----
From: Lars-Peter Clausen [mailto:lars@metafoo.de] 
Sent: Wednesday, June 06, 2012 10:07 AM
To: Pandruvada, Srinivas
Cc: Jonathan Cameron; linux-input@vger.kernel.org; linux-iio@vger.kernel.org
Subject: Re: [PATCH, 4/7] HID-Sensors: Added accelerometer 3D

On 06/06/2012 06:57 PM, Pandruvada, Srinivas wrote:
> The USB sensor spec has a report structure which it sends as part of report descriptor we get during initial plug in. [...]

Is the USB sensor spec publicly available somewhere?

Thanks,
- Lars


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH, 4/7] HID-Sensors: Added accelerometer 3D
       [not found]       ` <4FA419E87744DF4DAECD5BCE1214B7A91931B547-P5GAC/sN6hk64kNsxIetb7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
@ 2012-06-06 17:07         ` Lars-Peter Clausen
  2012-06-06 17:06           ` Pandruvada, Srinivas
  2012-06-07  8:10         ` Jonathan Cameron
  1 sibling, 1 reply; 16+ messages in thread
From: Lars-Peter Clausen @ 2012-06-06 17:07 UTC (permalink / raw)
  To: Pandruvada, Srinivas
  Cc: Jonathan Cameron,
	linux-input-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org

On 06/06/2012 06:57 PM, Pandruvada, Srinivas wrote:
> The USB sensor spec has a report structure which it sends as part of report descriptor we get during initial plug in. [...]

Is the USB sensor spec publicly available somewhere?

Thanks,
- Lars

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH, 3/7] HID-Sensors: Common attributes and interfaces
       [not found]     ` <1338997164-5077-4-git-send-email-srinivas.pandruvada-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
@ 2012-06-07  7:54       ` Jonathan Cameron
  0 siblings, 0 replies; 16+ messages in thread
From: Jonathan Cameron @ 2012-06-07  7:54 UTC (permalink / raw)
  To: srinivas pandruvada
  Cc: linux-input-u79uwXL29TY76Z2rM5mHXA,
	linux-iio-u79uwXL29TY76Z2rM5mHXA

On 6/6/2012 4:39 PM, srinivas pandruvada wrote:
> From: Srinivas pandruvada<srinivas.pandruvada-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
>
> Added IIO Ring interface and trigger functions, which can be
> used by all sensors. In addition a set of interface functions
> for setting common attributes for all sensors like polling
> interval, sensitivity and activate etc.

Couple of quick points as I'm probably not going to get time to review
this today.

ring_sw is pretty certain to go away - please switch to kfifo. You may
need the poll patch I sent out the other day...

We have a fairly tight abi definition.  Now it can be
extended of course, but only with a very good reason.  Quite
a few of your elements really don't conform to it.

I'm not yet sure how to handle the fact these devices are outputing
a very unusual form of floating point (actually I suspect almost
none of them them actually use that)  Perhaps a useful exercise is
for you to list some examples of the formats that are actually found
in devices?  If we have to support true floating point then we will
but it is going to be very painful.

Probably the most important element of IIO (and any other subsystem)
is generality. Hence drivers often need to blugeon data into the formats
that are expected.

Few quick comments inline.
>
> Signed-off-by: Srinivas pandruvada<srinivas.pandruvada-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> ---
>   drivers/staging/hid-sensors/Makefile               |    3 +
>   .../staging/hid-sensors/hid-sensor-attributes.c    |  203 ++++++++++++++++++++
>   .../staging/hid-sensors/hid-sensor-attributes.h    |   67 +++++++
>   drivers/staging/hid-sensors/hid-sensor-interface.h |   12 ++
>   drivers/staging/hid-sensors/hid-sensor-ring.c      |  104 ++++++++++
>   drivers/staging/hid-sensors/hid-sensor-trigger.c   |   81 ++++++++
>   6 files changed, 470 insertions(+), 0 deletions(-)
>   create mode 100644 drivers/staging/hid-sensors/hid-sensor-attributes.c
>   create mode 100644 drivers/staging/hid-sensors/hid-sensor-attributes.h
>   create mode 100644 drivers/staging/hid-sensors/hid-sensor-ring.c
>   create mode 100644 drivers/staging/hid-sensors/hid-sensor-trigger.c
>
> diff --git a/drivers/staging/hid-sensors/Makefile b/drivers/staging/hid-sensors/Makefile
> index 13591b2..9a03953 100644
> --- a/drivers/staging/hid-sensors/Makefile
> +++ b/drivers/staging/hid-sensors/Makefile
> @@ -6,4 +6,7 @@ ccflags-y += -Idrivers/staging
>   ccflags-$(CONFIG_HID_SENSOR_DEBUG) += -DDEBUG
>
>   hid-sensors-y := hid-sensor-hub.o
> +hid-sensors-y += hid-sensor-attributes.o
> +hid-sensors-y += hid-sensor-ring.o
> +hid-sensors-y += hid-sensor-trigger.o
>   obj-$(CONFIG_HID_SENSORS) += hid-sensors.o
> diff --git a/drivers/staging/hid-sensors/hid-sensor-attributes.c b/drivers/staging/hid-sensors/hid-sensor-attributes.c
> new file mode 100644
> index 0000000..6f07d50
> --- /dev/null
> +++ b/drivers/staging/hid-sensors/hid-sensor-attributes.c
> @@ -0,0 +1,203 @@
> +/*
> + * HID Sensors Driver
> + * Copyright (c) 2012, Intel Corporation.
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> + * more details.
> + *
> + * You should have received a copy of the GNU General Public License along with
> + * this program; if not, write to the Free Software Foundation, Inc.,
> + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
> + *
> + */
> +#include<linux/interrupt.h>
> +#include<linux/irq.h>
> +#include<linux/mutex.h>
> +#include<linux/device.h>
> +#include<linux/kernel.h>
> +#include<linux/spi/spi.h>
> +#include<linux/slab.h>
> +#include<linux/sysfs.h>
> +
> +#include "iio/iio.h"
> +#include "iio/sysfs.h"
> +#include "hid-sensor-ids.h"
> +#include "hid-sensor-interface.h"
> +
> +ssize_t hid_sensor_read_poll_interval(struct device *dev,
> +				struct device_attribute *attr,
> +				char *buf)
> +{
> +	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> +	struct hid_sensor_attributes *st = iio_priv(indio_dev);
> +	__s32 value;
> +	int len;
> +	int ret;
> +
> +	ret = sensor_hub_get_feature(st->hdev,
> +			st->poll.report_id,
> +			st->poll.index,&value);
> +	if (ret<  0 || value<  0)
> +		len = sprintf(buf, "0\n");
> +	else
> +		len = sprintf(buf, "units:0x%2x,exp:0x%x,value:0x%2x\n",
> +			st->poll.units, st->poll.unit_expo, value);
It's sampling_frequency for iio and it's in hz.
> +	return len;
> +}
> +
> +
> +ssize_t hid_sensor_write_poll_interval(struct device *dev,
> +		struct device_attribute *attr,
> +		const char *buf, size_t len)
> +{
> +	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> +	struct hid_sensor_attributes *st = iio_priv(indio_dev);
> +	long int value;
> +	int ret;
> +
> +	if (kstrtol(buf, 10,&value)<  0)
> +		return -EINVAL;
> +
> +	if (value<= 0)
> +		value = 0;
> +
> +	ret = sensor_hub_set_feature(st->hdev,
> +		st->poll.report_id,
> +		st->poll.index,
> +		value);
This implies to my mind that the units are fixed for a given
device?  Anyhow you also need to convert from hz here.
> +
> +	if (ret<  0)
> +		return ret;
> +	return strlen(buf);
> +
> +}
> +
> +ssize_t hid_sensor_read_report_state(struct device *dev,
> +				struct device_attribute *attr,
> +				char *buf)
> +{
> +	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> +	struct hid_sensor_attributes *st = iio_priv(indio_dev);
> +	long int value;
> +	int len;
> +	int ret;
> +
> +	ret = sensor_hub_get_feature(st->hdev,
> +			st->activate.report_id,
> +			st->activate.index, (s32 *)&value);
> +	if (ret<  0 || value<  0)
> +		len = sprintf(buf, "0\n");
> +	else
> +		len = sprintf(buf, "units:0x%2x,exp:0x%x,value:0x%2x\n",
> +			st->activate.units, st->activate.unit_expo,
> +			(unsigned int)value);
> +	return len;
> +
> +}
> +
> +ssize_t hid_sensor_write_report_state(struct device *dev,
> +		struct device_attribute *attr,
> +		const char *buf, size_t len)
> +{
> +
> +	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> +	struct hid_sensor_attributes *st = iio_priv(indio_dev);
> +	int ret;
> +	long int value;
> +
> +	if (kstrtol(buf, 10,&value)<  0)
> +		return -EINVAL;
> +
> +	ret = sensor_hub_set_feature(st->hdev, st->activate.report_id,
> +					st->activate.index,
> +					(s32)value);
> +	if (ret<  0)
> +		return ret;
> +
> +	return strlen(buf);
> +}
> +
> +ssize_t hid_sensor_read_sensitivity(struct device *dev,
> +				struct device_attribute *attr,
> +				char *buf)
> +{
> +
> +	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> +	struct hid_sensor_attributes *st = iio_priv(indio_dev);
> +	__s32 value;
> +	int len;
> +	int ret;
> +
> +	ret = sensor_hub_get_feature(st->hdev,
> +		st->sensitivity.report_id,
> +		st->sensitivity.index,&value);
> +	if (ret<  0 || value<  0)
> +		len = sprintf(buf, "0\n");
> +	else
> +		len = sprintf(buf, "units:0x%2x,exp:0x%x,value:0x%2x\n",
> +				st->sensitivity.units,
> +				st->sensitivity.unit_expo, value);
> +	return len;
> +}
> +
> +
> +ssize_t hid_sensor_write_sensitivity(struct device *dev,
> +		struct device_attribute *attr,
> +		const char *buf, size_t len)
> +{
> +	struct iio_dev *indio_dev = dev_get_drvdata(dev);
> +	struct hid_sensor_attributes *st = iio_priv(indio_dev);
> +	long int value;
> +	int ret;
> +
> +	if (kstrtol(buf, 10,&value)<  0)
> +		return -EINVAL;
> +
> +	if (value<= 0)
> +		value = 0;
> +
> +	ret = sensor_hub_set_feature(st->hdev,
> +		st->sensitivity.report_id,
> +		st->sensitivity.index,
> +		value);
> +
> +	if (ret<  0)
> +		return ret;
> +
> +	return strlen(buf);
> +}
> +
> +
> +
> +int hid_sensor_parse_common_attributes(struct hid_device *hdev, u32 usage_id,
> +					struct hid_sensor_attributes *st)
> +{
> +	int ret;
> +
> +	ret = sensor_hub_input_get_attribute_info(hdev,
> +					HID_FEATURE_REPORT, usage_id,
> +					HID_SENSOR_POLLING,&st->poll);
> +
> +	ret = sensor_hub_input_get_attribute_info(hdev,
> +					HID_FEATURE_REPORT, usage_id,
> +					HID_SENSOR_REPORT_STATE,
> +					&st->activate);
> +
> +	ret = sensor_hub_input_get_attribute_info(hdev,
> +			HID_FEATURE_REPORT, usage_id,
> +			HID_USAGE_SENSOR_PROPERTY_CHANGE_SENSITIVITY_ABS,
> +			&st->sensitivity);
> +
> +	hid_dbg(hdev, "common attributes: %x:%x, %x:%x, %x:%x\n",
> +			st->poll.index, st->poll.report_id,
> +			st->activate.index, st->activate.report_id,
> +			st->sensitivity.index, st->sensitivity.report_id);
> +
> +	return 0;
> +}
> diff --git a/drivers/staging/hid-sensors/hid-sensor-attributes.h b/drivers/staging/hid-sensors/hid-sensor-attributes.h
> new file mode 100644
> index 0000000..b1f4ac9
> --- /dev/null
> +++ b/drivers/staging/hid-sensors/hid-sensor-attributes.h
> @@ -0,0 +1,67 @@
> +/*
> + * HID Sensors Driver
> + * Copyright (c) 2012, Intel Corporation.
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> + * more details.
> + *
> + * You should have received a copy of the GNU General Public License along with
> + * this program; if not, write to the Free Software Foundation, Inc.,
> + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
> + *
> + */
> +#ifndef _HID_SENSORS_ATTRIBUTES_H
> +#define _HID_SENSORS_ATTRIBUTES_H
> +
> +/* Common sysfs attributes for HID sensors */
> +
> +int hid_sensor_parse_common_attributes(struct hid_device *hdev, u32 usage_id,
> +					struct hid_sensor_attributes *st);
> +
> +ssize_t hid_sensor_read_poll_interval(struct device *dev,
> +				struct device_attribute *attr,
> +				char *buf);
> +ssize_t hid_sensor_write_poll_interval(struct device *dev,
> +		struct device_attribute *attr,
> +		const char *buf, size_t len);
> +
> +ssize_t hid_sensor_read_report_state(struct device *dev,
> +				struct device_attribute *attr,
> +				char *buf);
> +ssize_t hid_sensor_write_report_state(struct device *dev,
> +		struct device_attribute *attr,
> +		const char *buf, size_t len);
> +ssize_t hid_sensor_read_sensitivity(struct device *dev,
> +				struct device_attribute *attr,
> +				char *buf);
> +ssize_t hid_sensor_write_sensitivity(struct device *dev,
> +		struct device_attribute *attr,
> +		const char *buf, size_t len);
> +
> +
> +#define IIO_DEV_ATTR_POLL_INTERVAL(_mode, _show, _store, _addr)  \
> +	IIO_DEVICE_ATTR(poll_interval, _mode, _show, _store, _addr)
sampling_frequency
> +#define IIO_DEV_ATTR_SENSITIVITY(_mode, _show, _store, _addr)        \
> +	IIO_DEVICE_ATTR(sensitivity, _mode, _show, _store, _addr)
probably maps to hysteresis. Also this one is weird given it's probably 
a parameter of the trigger rather than the sensor read out...  hmm.
> +#define IIO_DEV_ATTR_REPORT_STATE(_mode, _show, _store, _addr)        \
> +	IIO_DEVICE_ATTR(activate, _mode, _show, _store, _addr)
This one needs some docs (sorry if I've missed them).  I'd almost 
guarantee this will map to something more standard....
> +
> +static IIO_DEV_ATTR_POLL_INTERVAL(S_IWUSR | S_IRUSR,
> +			hid_sensor_read_poll_interval,
> +			hid_sensor_write_poll_interval,
> +			HID_SENSOR_POLLING);
> +static IIO_DEV_ATTR_SENSITIVITY(S_IWUSR | S_IRUSR,
> +			hid_sensor_read_sensitivity,
> +			hid_sensor_write_sensitivity,
> +			HID_USAGE_SENSOR_PROPERTY_CHANGE_SENSITIVITY_ABS);
> +static IIO_DEV_ATTR_REPORT_STATE(S_IWUSR | S_IRUSR,
> +			hid_sensor_read_report_state,
> +			hid_sensor_write_report_state,
> +			HID_SENSOR_REPORT_STATE);
> +#endif
> diff --git a/drivers/staging/hid-sensors/hid-sensor-interface.h b/drivers/staging/hid-sensors/hid-sensor-interface.h
> index 18a2e09..477494f 100644
> --- a/drivers/staging/hid-sensors/hid-sensor-interface.h
> +++ b/drivers/staging/hid-sensors/hid-sensor-interface.h
> @@ -72,4 +72,16 @@ ssize_t sensor_hub_input_attr_get_value(struct hid_device *hdev, u32 usage_id,
>   					u32 buf_len, u8 *buf);
>   int sensor_hub_input_get_unit_expo(struct hid_device *hdev, u32 field_usage_id,
>   					s32 *unit, s32 *unit_expo);
> +
> +/* Common IIO Ring Processing Functions */
> +int hid_sensor_configure_ring(struct iio_dev *indio_dev);
> +void hid_sensor_ring_cleanup(struct iio_dev *indio_dev);
> +void hid_sensor_ring_set_datum_size(struct iio_dev *indio_dev, int size);
> +void hid_sensor_push_data_to_ring(struct iio_dev *indio_dev, u8 *data,
> +								int len);
> +
> +/* Trigger functions */
> +int hid_sensor_setup_trigger(struct iio_dev *indio_dev, char *name);
> +void hid_sensor_remove_trigger(struct iio_dev *indio_dev);
> +
>   #endif
> diff --git a/drivers/staging/hid-sensors/hid-sensor-ring.c b/drivers/staging/hid-sensors/hid-sensor-ring.c
> new file mode 100644
> index 0000000..c63ff26
> --- /dev/null
> +++ b/drivers/staging/hid-sensors/hid-sensor-ring.c
> @@ -0,0 +1,104 @@
> +/*
> + * HID Sensors Driver
> + * Copyright (c) 2012, Intel Corporation.
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> + * more details.
> + *
> + * You should have received a copy of the GNU General Public License along with
> + * this program; if not, write to the Free Software Foundation, Inc.,
> + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
> + *
> + */
> +#include<linux/interrupt.h>
> +#include<linux/irq.h>
> +#include<linux/mutex.h>
> +#include<linux/device.h>
> +#include<linux/kernel.h>
> +#include<linux/spi/spi.h>
> +#include<linux/slab.h>
> +#include<linux/sysfs.h>
> +
> +#include "iio/iio.h"
> +#include "iio/sysfs.h"
> +#include "iio/ring_sw.h"
> +#include "iio/trigger_consumer.h"
> +#include "iio/trigger.h"
> +
> +static const struct iio_buffer_setup_ops hid_sensors_buffer_setup_ops = {
> +	.preenable =&iio_sw_buffer_preenable,
> +	.postenable =&iio_triggered_buffer_postenable,
> +	.predisable =&iio_triggered_buffer_predisable,
> +};
Not that I've reviews them yet, but a lot of this looks similar to the
patch series Lars-Peter sent out the other day.
[PATCH 0/9] iio: Add helper function for initializing triggered buffers
> +
> +static irqreturn_t hid_sensor_trigger_handler(int irq, void *p)
> +{
> +	return IRQ_HANDLED;
That's novel...
> +}
> +
> +void hid_sensor_push_data_to_ring(struct iio_dev *indio_dev, u8 *data, int len)
> +{
> +	struct iio_buffer *ring = indio_dev->buffer;
> +	s64 timestamp = iio_get_time_ns();
> +	int datum_sz;
> +
> +	if (!ring)
> +		return;
> +	datum_sz = ring->access->get_bytes_per_datum(ring);
> +	if (len>  datum_sz) {
> +		dev_err(&indio_dev->dev, "Datum size mismatch %d:%d\n", len,
> +				datum_sz);
> +		return;
> +	} else if (datum_sz>  0&&  datum_sz != len) {
> +		dev_dbg(&indio_dev->dev, "Updating Datum size%d:%d\n", len,
> +				datum_sz);
> +		if (ring->access->set_bytes_per_datum)
> +			ring->access->set_bytes_per_datum(ring, len);
You don't want to do this (and my gut feeling is it won't work).  Buffer 
size should be set up during the bring up of the buffer not on
an element read.
> +	}
Do a read through and clean up white space.  One blank line is almost 
always enough and certainly is here!
> +
> +
> +	ring->access->store_to(ring, (u8 *)data, timestamp);
> +}
> +
This one maps directly to one of Lars-Peter's suggestions.  As they
say - great minds think alike!
> +int hid_sensor_configure_ring(struct iio_dev *indio_dev)
> +{
> +	struct iio_buffer *ring;
> +	int ret = 0;
> +
> +	ring = iio_sw_rb_allocate(indio_dev);
> +	if (!ring)
> +		return -ENOMEM;
> +
> +	ring->scan_timestamp = true;
> +	indio_dev->buffer = ring;
> +	indio_dev->setup_ops =&hid_sensors_buffer_setup_ops;
> +
> +	indio_dev->pollfunc = iio_alloc_pollfunc(&iio_pollfunc_store_time,
> +						&hid_sensor_trigger_handler,
> +						 IRQF_ONESHOT,
> +						 indio_dev,
> +						 "hid_sensor%d",
> +						 indio_dev->id);
> +	if (indio_dev->pollfunc == NULL) {
> +		ret = -ENOMEM;
> +		goto error_iio_free;
> +	}
> +
> +	indio_dev->modes |= INDIO_BUFFER_TRIGGERED;
> +
> +	return ret;
> +error_iio_free:
> +	iio_sw_rb_free(indio_dev->buffer);
> +	return ret;
> +}
> +
> +void hid_sensor_ring_cleanup(struct iio_dev *indio_dev)
> +{
> +	iio_sw_rb_free(indio_dev->buffer);
> +}
> diff --git a/drivers/staging/hid-sensors/hid-sensor-trigger.c b/drivers/staging/hid-sensors/hid-sensor-trigger.c
> new file mode 100644
> index 0000000..49d8740
> --- /dev/null
> +++ b/drivers/staging/hid-sensors/hid-sensor-trigger.c
> @@ -0,0 +1,81 @@
> +/*
> + * HID Sensors Driver
> + * Copyright (c) 2012, Intel Corporation.
> + *
> + * This program is free software; you can redistribute it and/or modify it
> + * under the terms and conditions of the GNU General Public License,
> + * version 2, as published by the Free Software Foundation.
> + *
> + * This program is distributed in the hope it will be useful, but WITHOUT
> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
> + * more details.
> + *
> + * You should have received a copy of the GNU General Public License along with
> + * this program; if not, write to the Free Software Foundation, Inc.,
> + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
> + *
> + */
> +#include<linux/device.h>
> +#include<linux/hid.h>
> +#include<linux/usb.h>
> +#include "usbhid/usbhid.h"
> +#include<linux/module.h>
> +#include<linux/slab.h>
> +#include "iio/iio.h"
> +#include "iio/trigger.h"
> +#include "hid-sensor-interface.h"
> +
> +static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
> +						bool state)
> +{
> +	struct iio_dev *indio_dev = trig->private_data;
> +	struct hid_sensor_attributes *st = iio_priv(indio_dev);
> +
again 1 blank line is plenty.  I'm fussy about this one ;)
> +
> +	st->data_ready = state;
> +
> +	return 0;
> +}
> +
> +void hid_sensor_remove_trigger(struct iio_dev *indio_dev)
> +{
Hmm. The need for this check smells bad... I'd expect the driver
to have a higher level knowledge of whether this exists...
> +	if (indio_dev->trig) {
> +		iio_trigger_unregister(indio_dev->trig);
> +		iio_free_trigger(indio_dev->trig);
> +	}
> +}
> +
> +static const struct iio_trigger_ops hid_sensor_trigger_ops = {
> +	.owner = THIS_MODULE,
> +	.set_trigger_state =&hid_sensor_data_rdy_trigger_set_state,
> +};
> +
> +int hid_sensor_setup_trigger(struct iio_dev *indio_dev, char *name)
> +{
> +	int ret;
> +	struct iio_trigger *trig;
> +
> +	trig = iio_allocate_trigger("%s-dev%d", name, indio_dev->id);
> +	if (trig == NULL) {
> +		ret = -ENOMEM;
> +		goto error_ret;
> +	}
> +
> +	trig->dev.parent = indio_dev->dev.parent;
> +	trig->private_data = (void *)indio_dev;
> +	trig->ops =&hid_sensor_trigger_ops;
> +	ret = iio_trigger_register(trig);
> +
> +	/* select default trigger */
> +	indio_dev->trig = trig;
> +	if (ret)
> +		goto error_free_trig;
> +
> +	return ret;
> +
> +error_free_trig:
> +	iio_free_trigger(trig);
> +error_ret:
> +	return ret;
> +}

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH, 4/7] HID-Sensors: Added accelerometer 3D
       [not found]       ` <4FA419E87744DF4DAECD5BCE1214B7A91931B547-P5GAC/sN6hk64kNsxIetb7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
  2012-06-06 17:07         ` Lars-Peter Clausen
@ 2012-06-07  8:10         ` Jonathan Cameron
       [not found]           ` <4FD06212.7000204-KWPb1pKIrIJaa/9Udqfwiw@public.gmane.org>
  1 sibling, 1 reply; 16+ messages in thread
From: Jonathan Cameron @ 2012-06-07  8:10 UTC (permalink / raw)
  To: Pandruvada, Srinivas
  Cc: linux-input-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org

On 6/6/2012 5:57 PM, Pandruvada, Srinivas wrote:
> The USB sensor spec has a report structure which it sends as part of report descriptor we get during initial plug in. This report structure describes elements and their sizes. For example, it may say that an Accelerometer X axis value as 4 bytes long and what is the exponent and unit. Also it sends what control elements it has.
> The sequence is
> - Set sensitivity, interval, activate sys-fs interface. The USB sensor will send an event by USB-IN report when the captured sample is changed by sensitivity value and stable for at least interval. Also you need to activate the sensor so that the usb will start sending events.
>
> - Once USB report with the captured sample arrives, I format the data as defined in " struct accel_3d_sample" below and push to IIO ring buffer.
> I define a single channel
> 	IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_X_AND_Y_AND_Z,
> 	IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
> 	IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
> 	ACCEL_X_Y_Z, ACCEL_3D_SCAN_ACC_X_Y_Z,
> 		 IIO_ST('u', sizeof(struct accel_3d_sample) * 8,
> 		sizeof(struct accel_3d_sample) * 8, 0), 0), };
>
> Please suggest me if this is not the way IIO channel used.
You have 3 channels here.  The iio buffer interface will handle the
fact that they are 'at the same time' on it's own.

Btw I've killed off that macro so this won't build against current 
tree...  Feel free if sensible to define a local macro.  The global one
was a maintenance nightmare hence we scrapped it...

Sketching out what you should have

{
          .type = IIO_ACCEL,
          .modified = 1,
          .channel2 = IIO_MOD_X,
          .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
  		      IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
          .scan_index = 0,
          .scan_type = {
               .sign = 's',
               .realbits = 12,
               .storagebits = 16,
          },
}, {
          .type = IIO_ACCEL,
          .modified = 1,
          .channel2 = IIO_MOD_Y,
          .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
  		      IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
          .scan_index = 1,
          .scan_type = {
               .sign = 's',
               .realbits = 12,
               .storagebits = 16,
          },
}, {
          .type = IIO_ACCEL,
          .modified = 1,
          .channel2 = IIO_MOD_Y,
          .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
  		      IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
          .scan_index = 2,
          .scan_type = {
               .sign = 's',
               .realbits = 12,
               .storagebits = 16,
          },
Actually given you had scale and offset for your combined channel, those 
should probably be the SHARED versions.

The scan type is for a device that needs bits masked...

Hope that is enough for you to be getting on with.  Feel free to
post a v2 without waiting for a formal review!

Jonathan
> Thanks,
> Srinivas
>
>
>
> -----Original Message-----
> From: Jonathan Cameron [mailto:jic23-KWPb1pKIrIJaa/9Udqfwiw@public.gmane.org]
> Sent: Wednesday, June 06, 2012 9:29 AM
> To: Pandruvada, Srinivas; linux-input-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> Subject: Re: [PATCH, 4/7] HID-Sensors: Added accelerometer 3D
>
>
>
> srinivas pandruvada<srinivas.pandruvada-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>  wrote:
>
>> From: Srinivas pandruvada<srinivas.pandruvada-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
>>
>> Added usage id processing for Accelrometer 3D. This uses IIO interfaces
>> "ring/buffer and trigger interface" to present data to user mode.
>
> I do not understand the data format.  The way iio describes the format is done through sysfs attrs built from the iio_Chan spec... that way a scan is made up of a number of channel readings each taken at roughly the same time.  However each is separately described.  Perhaps the description needs extending.  Please describe the format.
>>
>> Signed-off-by: Srinivas pandruvada<srinivas.pandruvada-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
>> ---
>> drivers/staging/hid-sensors/Makefile               |    1 +
>> drivers/staging/hid-sensors/hid-sensor-accel-3d.c  |  387
>> ++++++++++++++++++++
>> drivers/staging/hid-sensors/hid-sensor-hub.c       |    1 +
>> drivers/staging/hid-sensors/hid-sensor-interface.h |    3 +
>> 4 files changed, 392 insertions(+), 0 deletions(-) create mode 100644
>> drivers/staging/hid-sensors/hid-sensor-accel-3d.c
>>
>> diff --git a/drivers/staging/hid-sensors/Makefile
>> b/drivers/staging/hid-sensors/Makefile
>> index 9a03953..4412079 100644
>> --- a/drivers/staging/hid-sensors/Makefile
>> +++ b/drivers/staging/hid-sensors/Makefile
>> @@ -9,4 +9,5 @@ hid-sensors-y := hid-sensor-hub.o  hid-sensors-y +=
>> hid-sensor-attributes.o  hid-sensors-y += hid-sensor-ring.o
>> hid-sensors-y += hid-sensor-trigger.o
>> +hid-sensors-y += hid-sensor-accel-3d.o
>> obj-$(CONFIG_HID_SENSORS) += hid-sensors.o diff --git
>> a/drivers/staging/hid-sensors/hid-sensor-accel-3d.c
>> b/drivers/staging/hid-sensors/hid-sensor-accel-3d.c
>> new file mode 100644
>> index 0000000..ffe2639
>> --- /dev/null
>> +++ b/drivers/staging/hid-sensors/hid-sensor-accel-3d.c
>> @@ -0,0 +1,387 @@
>> +/*
>> + * HID Sensors Driver
>> + * Copyright (c) 2012, Intel Corporation.
>> + *
>> + * This program is free software; you can redistribute it and/or
>> modify it
>> + * under the terms and conditions of the GNU General Public License,
>> + * version 2, as published by the Free Software Foundation.
>> + *
>> + * This program is distributed in the hope it will be useful, but
>> WITHOUT
>> + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
>> or
>> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
>> License for
>> + * more details.
>> + *
>> + * You should have received a copy of the GNU General Public License
>> along with
>> + * this program; if not, write to the Free Software Foundation, Inc.,
>> + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
>> + *
>> + */
>> +#include<linux/device.h>
>> +#include<linux/hid.h>
>> +#include<linux/usb.h>
>> +#include "usbhid/usbhid.h"
>> +#include<linux/module.h>
>> +#include<linux/slab.h>
>> +#include "iio/iio.h"
>> +#include "iio/sysfs.h"
>> +#include "iio/ring_sw.h"
>> +#include "iio/trigger.h"
>> +#include "hid-sensor-ids.h"
>> +#include "hid-sensor-interface.h"
>> +#include "hid-sensor-attributes.h"
>> +
>> +
>> +struct accel_3d_sample {
>> +	u16 x_sz;
>> +	u32 accel_x;
>> +	u16 y_sz;
>> +	u32 accel_y;
>> +	u16 z_sz;
>> +	u32 accel_z;
>> +} __packed;
>> +
>> +struct accel_3d_state {
>> +	struct hid_sensor_hub_attribute_info accel_x;
>> +	struct hid_sensor_hub_attribute_info accel_y;
>> +	struct hid_sensor_hub_attribute_info accel_z;
>> +	struct accel_3d_sample accel_sample_data; };
>> +
>> +
>> +enum accel_3d_chan {
>> +	ACCEL_X_Y_Z,
>> +};
>> +
>> +enum accel_3d_scan {
>> +	ACCEL_3D_SCAN_ACC_X_Y_Z,
>> +};
>> +
>> +static struct iio_chan_spec accel_3d_channels[] = {
>> +	IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_X_AND_Y_AND_Z,
>> +	IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
>> +	IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
>> +	ACCEL_X_Y_Z, ACCEL_3D_SCAN_ACC_X_Y_Z,
>> +		 IIO_ST('u', sizeof(struct accel_3d_sample) * 8,
>> +		sizeof(struct accel_3d_sample) * 8, 0), 0), };
>> +
>> +static ssize_t accel_3d_read_accel(struct device *dev,
>> +				struct device_attribute *attr,
>> +				char *buf)
>> +{
>> +	struct iio_dev *indio_dev = dev_get_drvdata(dev);
>> +	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>> +	struct accel_3d_state *accel_state =
>> +			(struct accel_3d_state *)st->private;
>> +	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
>> +	int report_id = -1;
>> +
>> +	switch (this_attr->address) {
>> +	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS:
>> +		report_id = accel_state->accel_x.report_id;
>> +		break;
>> +	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS:
>> +		report_id = accel_state->accel_y.report_id;
>> +		break;
>> +	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS:
>> +		report_id = accel_state->accel_z.report_id;
>> +		break;
>> +	default:
>> +		break;
>> +	}
>> +	if (report_id<  0)
>> +		return -EINVAL;
>> +
>> +	return sensor_hub_input_attr_get_value(st->hdev,
>> +			HID_USAGE_SENSOR_ACCEL_3D, this_attr->address,
>> +			report_id, 4, buf);
>> +}
>> +
>> +static int accel_3d_read_raw(struct iio_dev *indio_dev,
>> +			      struct iio_chan_spec const *chan,
>> +			      int *val, int *val2,
>> +			      long mask)
>> +{
>> +	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>> +	struct accel_3d_state *accel_state =
>> +			(struct accel_3d_state *)st->private;
>> +	*val = 0;
>> +	*val2 = 0;
>> +
>> +	switch (mask) {
>> +	case 0:
>> +		break;
>> +	case IIO_CHAN_INFO_SCALE:
>> +		*val = accel_state->accel_x.units;
>> +		break;
>> +	case IIO_CHAN_INFO_OFFSET:
>> +		*val = accel_state->accel_x.unit_expo;
>> +		break;
>> +	default:
>> +		break;
>> +
>> +	}
>> +	return IIO_VAL_INT;
>> +}
>> +
>> +static int accel_3d_write_raw(struct iio_dev *indio_dev,
>> +			       struct iio_chan_spec const *chan,
>> +			       int val,
>> +			       int val2,
>> +			       long mask)
>> +{
>> +	printk(KERN_ERR "%s\n", __func__);
>> +
>> +	return 0;
>> +}
>> +
>> +/* Usage specific attributes */
>> +#define IIO_DEV_ATTR_ACCEL_OFFSET(_mode, _show, _store, _addr)  \
>> +	IIO_DEVICE_ATTR(accel_offset, _mode, _show, _store, _addr)
>> +
>> +#define IIO_DEV_ATTR_ACCEL_X_OFFSET(_mode, _show, _store, _addr)
>> \
>> +	IIO_DEVICE_ATTR(accel_x_offset, _mode, _show, _store, _addr)
>> +
>> +#define IIO_DEV_ATTR_ACCEL_Y_OFFSET(_mode, _show, _store, _addr)
>> \
>> +	IIO_DEVICE_ATTR(accel_y_offset, _mode, _show, _store, _addr)
>> +
>> +#define IIO_DEV_ATTR_ACCEL_Z_OFFSET(_mode, _show, _store, _addr)
>> \
>> +	IIO_DEVICE_ATTR(accel_z_offset, _mode, _show, _store, _addr)
>> +
>> +#define IIO_DEV_ATTR_ACCEL_SENSITIVITY(_mode, _show, _store, _addr)
>>     \
>> +	IIO_DEVICE_ATTR(accel_sensitivity, _mode, _show, _store, _addr)
>> +
>> +static IIO_DEV_ATTR_ACCEL_X_OFFSET(S_IWUSR | S_IRUGO,
>> accel_3d_read_accel,
>> +		 NULL, HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS);
>> +static IIO_DEV_ATTR_ACCEL_Y_OFFSET(S_IWUSR | S_IRUGO,
>> accel_3d_read_accel,
>> +		 NULL, HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS);
>> +static IIO_DEV_ATTR_ACCEL_Z_OFFSET(S_IWUSR | S_IRUGO,
>> accel_3d_read_accel,
>> +		 NULL, HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS);
>> +
>> +static struct attribute *accel_3d_attributes[] = {
>> +	/* common attributes */
>> +	&iio_dev_attr_poll_interval.dev_attr.attr,
>> +	&iio_dev_attr_sensitivity.dev_attr.attr,
>> +	&iio_dev_attr_activate.dev_attr.attr,
>> +	/* Usage specific attributes */
>> +	&iio_dev_attr_accel_x_offset.dev_attr.attr,
>> +	&iio_dev_attr_accel_y_offset.dev_attr.attr,
>> +	&iio_dev_attr_accel_z_offset.dev_attr.attr,
>> +	NULL,
>> +};
>> +
>> +static const struct attribute_group accel_3d_attribute_group = {
>> +	.attrs = accel_3d_attributes,
>> +};
>> +
>> +static const struct iio_info accel_3d_info = {
>> +	.attrs =&accel_3d_attribute_group,
>> +	.driver_module = THIS_MODULE,
>> +	.read_raw =&accel_3d_read_raw,
>> +	.write_raw =&accel_3d_write_raw,
>> +};
>> +
>> +
>> +/* Function to push data to IIO ring */ int accel_3d_proc_event(struct
>> +hid_device *hdev, unsigned usage_id,
>> void *priv)
>> +{
>> +	struct iio_dev *indio_dev = (struct iio_dev *)priv;
>> +	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>> +	struct accel_3d_state *accel_state =
>> +			(struct accel_3d_state *)st->private;
>> +
>> +	hid_dbg(hdev, "accel_3d_proc_event\n");
>> +	if (st->data_ready)
>> +		hid_sensor_push_data_to_ring(indio_dev,
>> +				(u8 *)&accel_state->accel_sample_data,
>> +				sizeof(struct accel_3d_sample));
>> +	else
>> +		hid_dbg(hdev, "accel_3d_proc_event data not ready\n");
>> +	return 0;
>> +}
>> +
>> +/* Capture samples in local storage */ int
>> +accel_3d_capture_sample(struct hid_device *hdev, unsigned
>> usage_id,
>> +				 size_t raw_len, char *raw_data, void *priv) {
>> +	struct iio_dev *indio_dev = (struct iio_dev *)priv;
>> +	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>> +	struct accel_3d_state *accel_state =
>> +			(struct accel_3d_state *)st->private;
>> +
>> +	switch (usage_id) {
>> +	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS:
>> +		accel_state->accel_sample_data.x_sz = raw_len;
>> +		accel_state->accel_sample_data.accel_x =
>> +		*(u32 *)raw_data;
>> +		break;
>> +	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS:
>> +		accel_state->accel_sample_data.y_sz = raw_len;
>> +		accel_state->accel_sample_data.accel_y =
>> +		*(u32 *)raw_data;
>> +		break;
>> +	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS:
>> +		accel_state->accel_sample_data.z_sz = raw_len;
>> +		accel_state->accel_sample_data.accel_z =
>> +		*(u32 *)raw_data;
>> +		break;
>> +	default:
>> +		break;
>> +	}
>> +	return 0;
>> +}
>> +
>> +
>> +/* Parse report which is specific to an usage id*/ static int
>> +accel_3d_parse_report(struct hid_device *hdev, unsigned
>> usage_id,
>> +				struct accel_3d_state *st)
>> +{
>> +	int ret;
>> +
>> +	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
>> +			usage_id,
>> +			HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS,
>> +			&st->accel_x);
>> +	if (!ret)
>> +		hid_dbg(hdev, "No Accel X attribute\n");
>> +
>> +
>> +	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
>> +			usage_id,
>> +			HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS,
>> +			&st->accel_y);
>> +	if (!ret)
>> +		hid_dbg(hdev, "No Accel Y attribute\n");
>> +
>> +
>> +	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
>> +			usage_id,
>> +			HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS,
>> +			&st->accel_z);
>> +	if (!ret)
>> +		hid_dbg(hdev, "No Accel Z attribute\n");
>> +
>> +	hid_dbg(hdev, "accel_3d %x:%x, %x:%x, %x:%x\n", st->accel_x.index,
>> +			st->accel_x.report_id,
>> +			st->accel_y.index, st->accel_y.report_id,
>> +			st->accel_z.index, st->accel_z.report_id);
>> +
>> +	return 0;
>> +}
>> +
>> +/* Entry function to initialize the processing for usage id */ static
>> +int accel_3d_enter(struct hid_device *hdev, unsigned usage_id,
>> +				void **priv)
>> +{
>> +	int ret = 0;
>> +	static char *name = "accel_3d";
>> +	struct iio_dev *indio_dev;
>> +	struct accel_3d_state *accel_state;
>> +	struct hid_sensor_attributes *st;
>> +
>> +	accel_state = kzalloc(sizeof(struct accel_3d_state), GFP_KERNEL);
>> +	if (accel_state == NULL) {
>> +		ret = -ENOMEM;
>> +		goto error_ret;
>> +	}
>> +
>> +	indio_dev = iio_allocate_device(sizeof(struct
>> hid_sensor_attributes));
>> +	if (indio_dev == NULL) {
>> +		ret = -ENOMEM;
>> +		goto error_free_state;
>> +	}
>> +	st = iio_priv(indio_dev);
>> +	st->usage_id = usage_id;
>> +	st->hdev = hdev;
>> +	st->private = (void *)accel_state;
>> +
>> +	ret = hid_sensor_parse_common_attributes(hdev, usage_id, st);
>> +	if (ret) {
>> +		hid_err(hdev, "failed to setup common attributes\n");
>> +		goto error_free_dev;
>> +	}
>> +	ret = accel_3d_parse_report(hdev, usage_id, accel_state);
>> +	if (ret) {
>> +		hid_err(hdev, "failed to setup attributes\n");
>> +		goto error_free_dev;
>> +	}
>> +
>> +	indio_dev->channels = accel_3d_channels;
>> +	indio_dev->num_channels =
>> +				ARRAY_SIZE(accel_3d_channels);
>> +	indio_dev->dev.parent =&hdev->dev;
>> +	indio_dev->info =&accel_3d_info;
>> +	indio_dev->name = name;
>> +	indio_dev->modes = INDIO_DIRECT_MODE;
>> +
>> +	ret = hid_sensor_configure_ring(indio_dev);
>> +	if (ret) {
>> +		hid_err(hdev, "failed to initialize the ring\n");
>> +		goto error_free_dev;
>> +	}
>> +
>> +	ret = iio_buffer_register(indio_dev,
>> +					accel_3d_channels,
>> +					ARRAY_SIZE(accel_3d_channels));
>> +	if (ret) {
>> +		hid_err(hdev, "failed to initialize the ring\n");
>> +		goto error_unreg_ring_funcs;
>> +	}
>> +	st->data_ready = true;
>> +	ret = hid_sensor_setup_trigger(indio_dev, name);
>> +	if (ret<  0) {
>> +		hid_err(hdev, "trigger setup failed\n");
>> +		goto error_uninit_ring;
>> +	}
>> +
>> +	ret = iio_device_register(indio_dev);
>> +	if (ret) {
>> +		hid_err(hdev, "device register failed\n");
>> +		goto error_remove_trigger;
>> +	}
>> +	*priv = (void *)indio_dev;
>> +	return ret;
>> +
>> +error_remove_trigger:
>> +		hid_sensor_remove_trigger(indio_dev);
>> +error_uninit_ring:
>> +		iio_buffer_unregister(indio_dev);
>> +error_unreg_ring_funcs:
>> +		hid_sensor_ring_cleanup(indio_dev);
>> +error_free_dev:
>> +		iio_free_device(indio_dev);
>> +error_free_state:
>> +		kfree(accel_state);
>> +error_ret:
>> +		return ret;
>> +}
>> +
>> +static int accel_3d_exit(struct hid_device *hdev, void *priv) {
>> +	int ret = 0;
>> +	struct iio_dev *indio_dev = (struct iio_dev *)priv;
>> +	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>> +	struct accel_3d_state *accel_state =
>> +			(struct accel_3d_state *)st->private;
>> +
>> +	iio_device_unregister(indio_dev);
>> +	hid_sensor_remove_trigger(indio_dev);
>> +	iio_buffer_unregister(indio_dev);
>> +	hid_sensor_ring_cleanup(indio_dev);
>> +	iio_free_device(indio_dev);
>> +
>> +	kfree(accel_state);
>> +	return ret;
>> +}
>> +
>> +static struct sensor_hub_callbacks accel_3d_callbacks = {
>> +	.enter = accel_3d_enter,
>> +	.exit = accel_3d_exit,
>> +	.send_event = accel_3d_proc_event,
>> +	.capture_sample = accel_3d_capture_sample, };
>> +
>> +struct sensor_hub_callbacks  *accel_3d_register_callbacks(void)
>> +{
>> +	return&accel_3d_callbacks;
>> +}
>> diff --git a/drivers/staging/hid-sensors/hid-sensor-hub.c
>> b/drivers/staging/hid-sensors/hid-sensor-hub.c
>> index 384e0d0..55ae562 100644
>> --- a/drivers/staging/hid-sensors/hid-sensor-hub.c
>> +++ b/drivers/staging/hid-sensors/hid-sensor-hub.c
>> @@ -60,6 +60,7 @@ struct sensor_hub_callbacks_list {  };
>>
>> static struct sensor_hub_callbacks_list usage_callbacks[] = {
>> +	{HID_USAGE_SENSOR_ACCEL_3D, accel_3d_register_callbacks},
>> 	{0}
>> };
>>
>> diff --git a/drivers/staging/hid-sensors/hid-sensor-interface.h
>> b/drivers/staging/hid-sensors/hid-sensor-interface.h
>> index 477494f..3f4fe57 100644
>> --- a/drivers/staging/hid-sensors/hid-sensor-interface.h
>> +++ b/drivers/staging/hid-sensors/hid-sensor-interface.h
>> @@ -84,4 +84,7 @@ void hid_sensor_push_data_to_ring(struct iio_dev
>> *indio_dev, u8 *data,  int hid_sensor_setup_trigger(struct iio_dev
>> *indio_dev, char *name);  void hid_sensor_remove_trigger(struct iio_dev
>> *indio_dev);
>>
>> +/* Sensor usage id processing callbacks */ struct sensor_hub_callbacks
>> +*accel_3d_register_callbacks(void);
>> +
>> #endif
>> --
>> 1.7.7.6
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
>> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org More majordomo info
>> at  http://vger.kernel.org/majordomo-info.html
>
> --
> Sent from my Android phone with K-9 Mail. Please excuse my brevity.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* RE: [PATCH, 4/7] HID-Sensors: Added accelerometer 3D
       [not found]           ` <4FD06212.7000204-KWPb1pKIrIJaa/9Udqfwiw@public.gmane.org>
@ 2012-06-07 15:41             ` Pandruvada, Srinivas
  2012-06-07 20:27               ` Jonathan Cameron
  0 siblings, 1 reply; 16+ messages in thread
From: Pandruvada, Srinivas @ 2012-06-07 15:41 UTC (permalink / raw)
  To: Jonathan Cameron
  Cc: linux-input-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org

Thanks for your excellent comments. I think I get some idea now.

Do you think the place for this driver is in "staging/iio/hid-sensors"?

Thanks,
Srinivas






-----Original Message-----
From: Jonathan Cameron [mailto:jic23@cam.ac.uk] 
Sent: Thursday, June 07, 2012 1:11 AM
To: Pandruvada, Srinivas
Cc: linux-input@vger.kernel.org; linux-iio@vger.kernel.org
Subject: Re: [PATCH, 4/7] HID-Sensors: Added accelerometer 3D

On 6/6/2012 5:57 PM, Pandruvada, Srinivas wrote:
> The USB sensor spec has a report structure which it sends as part of report descriptor we get during initial plug in. This report structure describes elements and their sizes. For example, it may say that an Accelerometer X axis value as 4 bytes long and what is the exponent and unit. Also it sends what control elements it has.
> The sequence is
> - Set sensitivity, interval, activate sys-fs interface. The USB sensor will send an event by USB-IN report when the captured sample is changed by sensitivity value and stable for at least interval. Also you need to activate the sensor so that the usb will start sending events.
>
> - Once USB report with the captured sample arrives, I format the data as defined in " struct accel_3d_sample" below and push to IIO ring buffer.
> I define a single channel
> 	IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_X_AND_Y_AND_Z,
> 	IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
> 	IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
> 	ACCEL_X_Y_Z, ACCEL_3D_SCAN_ACC_X_Y_Z,
> 		 IIO_ST('u', sizeof(struct accel_3d_sample) * 8,
> 		sizeof(struct accel_3d_sample) * 8, 0), 0), };
>
> Please suggest me if this is not the way IIO channel used.
You have 3 channels here.  The iio buffer interface will handle the fact that they are 'at the same time' on it's own.

Btw I've killed off that macro so this won't build against current tree...  Feel free if sensible to define a local macro.  The global one was a maintenance nightmare hence we scrapped it...

Sketching out what you should have

{
          .type = IIO_ACCEL,
          .modified = 1,
          .channel2 = IIO_MOD_X,
          .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
  		      IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
          .scan_index = 0,
          .scan_type = {
               .sign = 's',
               .realbits = 12,
               .storagebits = 16,
          },
}, {
          .type = IIO_ACCEL,
          .modified = 1,
          .channel2 = IIO_MOD_Y,
          .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
  		      IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
          .scan_index = 1,
          .scan_type = {
               .sign = 's',
               .realbits = 12,
               .storagebits = 16,
          },
}, {
          .type = IIO_ACCEL,
          .modified = 1,
          .channel2 = IIO_MOD_Y,
          .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
  		      IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
          .scan_index = 2,
          .scan_type = {
               .sign = 's',
               .realbits = 12,
               .storagebits = 16,
          },
Actually given you had scale and offset for your combined channel, those should probably be the SHARED versions.

The scan type is for a device that needs bits masked...

Hope that is enough for you to be getting on with.  Feel free to post a v2 without waiting for a formal review!

Jonathan
> Thanks,
> Srinivas
>
>
>
> -----Original Message-----
> From: Jonathan Cameron [mailto:jic23@cam.ac.uk]
> Sent: Wednesday, June 06, 2012 9:29 AM
> To: Pandruvada, Srinivas; linux-input@vger.kernel.org
> Cc: linux-iio@vger.kernel.org
> Subject: Re: [PATCH, 4/7] HID-Sensors: Added accelerometer 3D
>
>
>
> srinivas pandruvada<srinivas.pandruvada@intel.com>  wrote:
>
>> From: Srinivas pandruvada<srinivas.pandruvada@intel.com>
>>
>> Added usage id processing for Accelrometer 3D. This uses IIO 
>> interfaces "ring/buffer and trigger interface" to present data to user mode.
>
> I do not understand the data format.  The way iio describes the format is done through sysfs attrs built from the iio_Chan spec... that way a scan is made up of a number of channel readings each taken at roughly the same time.  However each is separately described.  Perhaps the description needs extending.  Please describe the format.
>>
>> Signed-off-by: Srinivas pandruvada<srinivas.pandruvada@intel.com>
>> ---
>> drivers/staging/hid-sensors/Makefile               |    1 +
>> drivers/staging/hid-sensors/hid-sensor-accel-3d.c  |  387
>> ++++++++++++++++++++
>> drivers/staging/hid-sensors/hid-sensor-hub.c       |    1 +
>> drivers/staging/hid-sensors/hid-sensor-interface.h |    3 +
>> 4 files changed, 392 insertions(+), 0 deletions(-) create mode 100644 
>> drivers/staging/hid-sensors/hid-sensor-accel-3d.c
>>
>> diff --git a/drivers/staging/hid-sensors/Makefile
>> b/drivers/staging/hid-sensors/Makefile
>> index 9a03953..4412079 100644
>> --- a/drivers/staging/hid-sensors/Makefile
>> +++ b/drivers/staging/hid-sensors/Makefile
>> @@ -9,4 +9,5 @@ hid-sensors-y := hid-sensor-hub.o  hid-sensors-y += 
>> hid-sensor-attributes.o  hid-sensors-y += hid-sensor-ring.o 
>> hid-sensors-y += hid-sensor-trigger.o
>> +hid-sensors-y += hid-sensor-accel-3d.o
>> obj-$(CONFIG_HID_SENSORS) += hid-sensors.o diff --git 
>> a/drivers/staging/hid-sensors/hid-sensor-accel-3d.c
>> b/drivers/staging/hid-sensors/hid-sensor-accel-3d.c
>> new file mode 100644
>> index 0000000..ffe2639
>> --- /dev/null
>> +++ b/drivers/staging/hid-sensors/hid-sensor-accel-3d.c
>> @@ -0,0 +1,387 @@
>> +/*
>> + * HID Sensors Driver
>> + * Copyright (c) 2012, Intel Corporation.
>> + *
>> + * This program is free software; you can redistribute it and/or
>> modify it
>> + * under the terms and conditions of the GNU General Public License,
>> + * version 2, as published by the Free Software Foundation.
>> + *
>> + * This program is distributed in the hope it will be useful, but
>> WITHOUT
>> + * ANY WARRANTY; without even the implied warranty of 
>> + MERCHANTABILITY
>> or
>> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
>> License for
>> + * more details.
>> + *
>> + * You should have received a copy of the GNU General Public License
>> along with
>> + * this program; if not, write to the Free Software Foundation, 
>> +Inc.,
>> + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
>> + *
>> + */
>> +#include<linux/device.h>
>> +#include<linux/hid.h>
>> +#include<linux/usb.h>
>> +#include "usbhid/usbhid.h"
>> +#include<linux/module.h>
>> +#include<linux/slab.h>
>> +#include "iio/iio.h"
>> +#include "iio/sysfs.h"
>> +#include "iio/ring_sw.h"
>> +#include "iio/trigger.h"
>> +#include "hid-sensor-ids.h"
>> +#include "hid-sensor-interface.h"
>> +#include "hid-sensor-attributes.h"
>> +
>> +
>> +struct accel_3d_sample {
>> +	u16 x_sz;
>> +	u32 accel_x;
>> +	u16 y_sz;
>> +	u32 accel_y;
>> +	u16 z_sz;
>> +	u32 accel_z;
>> +} __packed;
>> +
>> +struct accel_3d_state {
>> +	struct hid_sensor_hub_attribute_info accel_x;
>> +	struct hid_sensor_hub_attribute_info accel_y;
>> +	struct hid_sensor_hub_attribute_info accel_z;
>> +	struct accel_3d_sample accel_sample_data; };
>> +
>> +
>> +enum accel_3d_chan {
>> +	ACCEL_X_Y_Z,
>> +};
>> +
>> +enum accel_3d_scan {
>> +	ACCEL_3D_SCAN_ACC_X_Y_Z,
>> +};
>> +
>> +static struct iio_chan_spec accel_3d_channels[] = {
>> +	IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_X_AND_Y_AND_Z,
>> +	IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
>> +	IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
>> +	ACCEL_X_Y_Z, ACCEL_3D_SCAN_ACC_X_Y_Z,
>> +		 IIO_ST('u', sizeof(struct accel_3d_sample) * 8,
>> +		sizeof(struct accel_3d_sample) * 8, 0), 0), };
>> +
>> +static ssize_t accel_3d_read_accel(struct device *dev,
>> +				struct device_attribute *attr,
>> +				char *buf)
>> +{
>> +	struct iio_dev *indio_dev = dev_get_drvdata(dev);
>> +	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>> +	struct accel_3d_state *accel_state =
>> +			(struct accel_3d_state *)st->private;
>> +	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
>> +	int report_id = -1;
>> +
>> +	switch (this_attr->address) {
>> +	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS:
>> +		report_id = accel_state->accel_x.report_id;
>> +		break;
>> +	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS:
>> +		report_id = accel_state->accel_y.report_id;
>> +		break;
>> +	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS:
>> +		report_id = accel_state->accel_z.report_id;
>> +		break;
>> +	default:
>> +		break;
>> +	}
>> +	if (report_id<  0)
>> +		return -EINVAL;
>> +
>> +	return sensor_hub_input_attr_get_value(st->hdev,
>> +			HID_USAGE_SENSOR_ACCEL_3D, this_attr->address,
>> +			report_id, 4, buf);
>> +}
>> +
>> +static int accel_3d_read_raw(struct iio_dev *indio_dev,
>> +			      struct iio_chan_spec const *chan,
>> +			      int *val, int *val2,
>> +			      long mask)
>> +{
>> +	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>> +	struct accel_3d_state *accel_state =
>> +			(struct accel_3d_state *)st->private;
>> +	*val = 0;
>> +	*val2 = 0;
>> +
>> +	switch (mask) {
>> +	case 0:
>> +		break;
>> +	case IIO_CHAN_INFO_SCALE:
>> +		*val = accel_state->accel_x.units;
>> +		break;
>> +	case IIO_CHAN_INFO_OFFSET:
>> +		*val = accel_state->accel_x.unit_expo;
>> +		break;
>> +	default:
>> +		break;
>> +
>> +	}
>> +	return IIO_VAL_INT;
>> +}
>> +
>> +static int accel_3d_write_raw(struct iio_dev *indio_dev,
>> +			       struct iio_chan_spec const *chan,
>> +			       int val,
>> +			       int val2,
>> +			       long mask)
>> +{
>> +	printk(KERN_ERR "%s\n", __func__);
>> +
>> +	return 0;
>> +}
>> +
>> +/* Usage specific attributes */
>> +#define IIO_DEV_ATTR_ACCEL_OFFSET(_mode, _show, _store, _addr)  \
>> +	IIO_DEVICE_ATTR(accel_offset, _mode, _show, _store, _addr)
>> +
>> +#define IIO_DEV_ATTR_ACCEL_X_OFFSET(_mode, _show, _store, _addr)
>> \
>> +	IIO_DEVICE_ATTR(accel_x_offset, _mode, _show, _store, _addr)
>> +
>> +#define IIO_DEV_ATTR_ACCEL_Y_OFFSET(_mode, _show, _store, _addr)
>> \
>> +	IIO_DEVICE_ATTR(accel_y_offset, _mode, _show, _store, _addr)
>> +
>> +#define IIO_DEV_ATTR_ACCEL_Z_OFFSET(_mode, _show, _store, _addr)
>> \
>> +	IIO_DEVICE_ATTR(accel_z_offset, _mode, _show, _store, _addr)
>> +
>> +#define IIO_DEV_ATTR_ACCEL_SENSITIVITY(_mode, _show, _store, _addr)
>>     \
>> +	IIO_DEVICE_ATTR(accel_sensitivity, _mode, _show, _store, _addr)
>> +
>> +static IIO_DEV_ATTR_ACCEL_X_OFFSET(S_IWUSR | S_IRUGO,
>> accel_3d_read_accel,
>> +		 NULL, HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS);
>> +static IIO_DEV_ATTR_ACCEL_Y_OFFSET(S_IWUSR | S_IRUGO,
>> accel_3d_read_accel,
>> +		 NULL, HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS);
>> +static IIO_DEV_ATTR_ACCEL_Z_OFFSET(S_IWUSR | S_IRUGO,
>> accel_3d_read_accel,
>> +		 NULL, HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS);
>> +
>> +static struct attribute *accel_3d_attributes[] = {
>> +	/* common attributes */
>> +	&iio_dev_attr_poll_interval.dev_attr.attr,
>> +	&iio_dev_attr_sensitivity.dev_attr.attr,
>> +	&iio_dev_attr_activate.dev_attr.attr,
>> +	/* Usage specific attributes */
>> +	&iio_dev_attr_accel_x_offset.dev_attr.attr,
>> +	&iio_dev_attr_accel_y_offset.dev_attr.attr,
>> +	&iio_dev_attr_accel_z_offset.dev_attr.attr,
>> +	NULL,
>> +};
>> +
>> +static const struct attribute_group accel_3d_attribute_group = {
>> +	.attrs = accel_3d_attributes,
>> +};
>> +
>> +static const struct iio_info accel_3d_info = {
>> +	.attrs =&accel_3d_attribute_group,
>> +	.driver_module = THIS_MODULE,
>> +	.read_raw =&accel_3d_read_raw,
>> +	.write_raw =&accel_3d_write_raw,
>> +};
>> +
>> +
>> +/* Function to push data to IIO ring */ int 
>> +accel_3d_proc_event(struct hid_device *hdev, unsigned usage_id,
>> void *priv)
>> +{
>> +	struct iio_dev *indio_dev = (struct iio_dev *)priv;
>> +	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>> +	struct accel_3d_state *accel_state =
>> +			(struct accel_3d_state *)st->private;
>> +
>> +	hid_dbg(hdev, "accel_3d_proc_event\n");
>> +	if (st->data_ready)
>> +		hid_sensor_push_data_to_ring(indio_dev,
>> +				(u8 *)&accel_state->accel_sample_data,
>> +				sizeof(struct accel_3d_sample));
>> +	else
>> +		hid_dbg(hdev, "accel_3d_proc_event data not ready\n");
>> +	return 0;
>> +}
>> +
>> +/* Capture samples in local storage */ int 
>> +accel_3d_capture_sample(struct hid_device *hdev, unsigned
>> usage_id,
>> +				 size_t raw_len, char *raw_data, void *priv) {
>> +	struct iio_dev *indio_dev = (struct iio_dev *)priv;
>> +	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>> +	struct accel_3d_state *accel_state =
>> +			(struct accel_3d_state *)st->private;
>> +
>> +	switch (usage_id) {
>> +	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS:
>> +		accel_state->accel_sample_data.x_sz = raw_len;
>> +		accel_state->accel_sample_data.accel_x =
>> +		*(u32 *)raw_data;
>> +		break;
>> +	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS:
>> +		accel_state->accel_sample_data.y_sz = raw_len;
>> +		accel_state->accel_sample_data.accel_y =
>> +		*(u32 *)raw_data;
>> +		break;
>> +	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS:
>> +		accel_state->accel_sample_data.z_sz = raw_len;
>> +		accel_state->accel_sample_data.accel_z =
>> +		*(u32 *)raw_data;
>> +		break;
>> +	default:
>> +		break;
>> +	}
>> +	return 0;
>> +}
>> +
>> +
>> +/* Parse report which is specific to an usage id*/ static int 
>> +accel_3d_parse_report(struct hid_device *hdev, unsigned
>> usage_id,
>> +				struct accel_3d_state *st)
>> +{
>> +	int ret;
>> +
>> +	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
>> +			usage_id,
>> +			HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS,
>> +			&st->accel_x);
>> +	if (!ret)
>> +		hid_dbg(hdev, "No Accel X attribute\n");
>> +
>> +
>> +	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
>> +			usage_id,
>> +			HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS,
>> +			&st->accel_y);
>> +	if (!ret)
>> +		hid_dbg(hdev, "No Accel Y attribute\n");
>> +
>> +
>> +	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
>> +			usage_id,
>> +			HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS,
>> +			&st->accel_z);
>> +	if (!ret)
>> +		hid_dbg(hdev, "No Accel Z attribute\n");
>> +
>> +	hid_dbg(hdev, "accel_3d %x:%x, %x:%x, %x:%x\n", st->accel_x.index,
>> +			st->accel_x.report_id,
>> +			st->accel_y.index, st->accel_y.report_id,
>> +			st->accel_z.index, st->accel_z.report_id);
>> +
>> +	return 0;
>> +}
>> +
>> +/* Entry function to initialize the processing for usage id */ 
>> +static int accel_3d_enter(struct hid_device *hdev, unsigned usage_id,
>> +				void **priv)
>> +{
>> +	int ret = 0;
>> +	static char *name = "accel_3d";
>> +	struct iio_dev *indio_dev;
>> +	struct accel_3d_state *accel_state;
>> +	struct hid_sensor_attributes *st;
>> +
>> +	accel_state = kzalloc(sizeof(struct accel_3d_state), GFP_KERNEL);
>> +	if (accel_state == NULL) {
>> +		ret = -ENOMEM;
>> +		goto error_ret;
>> +	}
>> +
>> +	indio_dev = iio_allocate_device(sizeof(struct
>> hid_sensor_attributes));
>> +	if (indio_dev == NULL) {
>> +		ret = -ENOMEM;
>> +		goto error_free_state;
>> +	}
>> +	st = iio_priv(indio_dev);
>> +	st->usage_id = usage_id;
>> +	st->hdev = hdev;
>> +	st->private = (void *)accel_state;
>> +
>> +	ret = hid_sensor_parse_common_attributes(hdev, usage_id, st);
>> +	if (ret) {
>> +		hid_err(hdev, "failed to setup common attributes\n");
>> +		goto error_free_dev;
>> +	}
>> +	ret = accel_3d_parse_report(hdev, usage_id, accel_state);
>> +	if (ret) {
>> +		hid_err(hdev, "failed to setup attributes\n");
>> +		goto error_free_dev;
>> +	}
>> +
>> +	indio_dev->channels = accel_3d_channels;
>> +	indio_dev->num_channels =
>> +				ARRAY_SIZE(accel_3d_channels);
>> +	indio_dev->dev.parent =&hdev->dev;
>> +	indio_dev->info =&accel_3d_info;
>> +	indio_dev->name = name;
>> +	indio_dev->modes = INDIO_DIRECT_MODE;
>> +
>> +	ret = hid_sensor_configure_ring(indio_dev);
>> +	if (ret) {
>> +		hid_err(hdev, "failed to initialize the ring\n");
>> +		goto error_free_dev;
>> +	}
>> +
>> +	ret = iio_buffer_register(indio_dev,
>> +					accel_3d_channels,
>> +					ARRAY_SIZE(accel_3d_channels));
>> +	if (ret) {
>> +		hid_err(hdev, "failed to initialize the ring\n");
>> +		goto error_unreg_ring_funcs;
>> +	}
>> +	st->data_ready = true;
>> +	ret = hid_sensor_setup_trigger(indio_dev, name);
>> +	if (ret<  0) {
>> +		hid_err(hdev, "trigger setup failed\n");
>> +		goto error_uninit_ring;
>> +	}
>> +
>> +	ret = iio_device_register(indio_dev);
>> +	if (ret) {
>> +		hid_err(hdev, "device register failed\n");
>> +		goto error_remove_trigger;
>> +	}
>> +	*priv = (void *)indio_dev;
>> +	return ret;
>> +
>> +error_remove_trigger:
>> +		hid_sensor_remove_trigger(indio_dev);
>> +error_uninit_ring:
>> +		iio_buffer_unregister(indio_dev);
>> +error_unreg_ring_funcs:
>> +		hid_sensor_ring_cleanup(indio_dev);
>> +error_free_dev:
>> +		iio_free_device(indio_dev);
>> +error_free_state:
>> +		kfree(accel_state);
>> +error_ret:
>> +		return ret;
>> +}
>> +
>> +static int accel_3d_exit(struct hid_device *hdev, void *priv) {
>> +	int ret = 0;
>> +	struct iio_dev *indio_dev = (struct iio_dev *)priv;
>> +	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>> +	struct accel_3d_state *accel_state =
>> +			(struct accel_3d_state *)st->private;
>> +
>> +	iio_device_unregister(indio_dev);
>> +	hid_sensor_remove_trigger(indio_dev);
>> +	iio_buffer_unregister(indio_dev);
>> +	hid_sensor_ring_cleanup(indio_dev);
>> +	iio_free_device(indio_dev);
>> +
>> +	kfree(accel_state);
>> +	return ret;
>> +}
>> +
>> +static struct sensor_hub_callbacks accel_3d_callbacks = {
>> +	.enter = accel_3d_enter,
>> +	.exit = accel_3d_exit,
>> +	.send_event = accel_3d_proc_event,
>> +	.capture_sample = accel_3d_capture_sample, };
>> +
>> +struct sensor_hub_callbacks  *accel_3d_register_callbacks(void)
>> +{
>> +	return&accel_3d_callbacks;
>> +}
>> diff --git a/drivers/staging/hid-sensors/hid-sensor-hub.c
>> b/drivers/staging/hid-sensors/hid-sensor-hub.c
>> index 384e0d0..55ae562 100644
>> --- a/drivers/staging/hid-sensors/hid-sensor-hub.c
>> +++ b/drivers/staging/hid-sensors/hid-sensor-hub.c
>> @@ -60,6 +60,7 @@ struct sensor_hub_callbacks_list {  };
>>
>> static struct sensor_hub_callbacks_list usage_callbacks[] = {
>> +	{HID_USAGE_SENSOR_ACCEL_3D, accel_3d_register_callbacks},
>> 	{0}
>> };
>>
>> diff --git a/drivers/staging/hid-sensors/hid-sensor-interface.h
>> b/drivers/staging/hid-sensors/hid-sensor-interface.h
>> index 477494f..3f4fe57 100644
>> --- a/drivers/staging/hid-sensors/hid-sensor-interface.h
>> +++ b/drivers/staging/hid-sensors/hid-sensor-interface.h
>> @@ -84,4 +84,7 @@ void hid_sensor_push_data_to_ring(struct iio_dev 
>> *indio_dev, u8 *data,  int hid_sensor_setup_trigger(struct iio_dev 
>> *indio_dev, char *name);  void hid_sensor_remove_trigger(struct 
>> iio_dev *indio_dev);
>>
>> +/* Sensor usage id processing callbacks */ struct 
>> +sensor_hub_callbacks *accel_3d_register_callbacks(void);
>> +
>> #endif
>> --
>> 1.7.7.6
>>
>> --
>> To unsubscribe from this list: send the line "unsubscribe linux-iio" 
>> in the body of a message to majordomo@vger.kernel.org More majordomo 
>> info at  http://vger.kernel.org/majordomo-info.html
>
> --
> Sent from my Android phone with K-9 Mail. Please excuse my brevity.


^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: [PATCH, 4/7] HID-Sensors: Added accelerometer 3D
  2012-06-07 15:41             ` Pandruvada, Srinivas
@ 2012-06-07 20:27               ` Jonathan Cameron
  0 siblings, 0 replies; 16+ messages in thread
From: Jonathan Cameron @ 2012-06-07 20:27 UTC (permalink / raw)
  To: Pandruvada, Srinivas
  Cc: Jonathan Cameron, linux-input@vger.kernel.org,
	linux-iio@vger.kernel.org

On 06/07/2012 04:41 PM, Pandruvada, Srinivas wrote:
> Thanks for your excellent comments. I think I get some idea now.
> 
> Do you think the place for this driver is in "staging/iio/hid-sensors"?
Firstly don't put it in staging unless you have non iio related reasons!
The iio core is now out in drivers/iio.
Secondly the question is whether to treat the individual sensor
components as individual drivers (and the core as effectively and mfd)
or to treat it all as one big 'compound' sensor, similar to we do with
IMUs. As it currently stands it is a compound sensor.

The mfd route breaks the various components into independent modules
with a core handling the data and interrupt flow to and from the
hardware.  Might be worth doing for a clean result...

Also note that there are some patches changing the route of data
into the buffers under review.  You might want to develop with
those in place as quite a few of your elements will probably want
bridging to input (which relies on that series...)

The series.
[PATCH 0/4 V2] staging:iio: Add support for multiple buffer.
> 
> Thanks,
> Srinivas
> 
> 
> 
> 
> 
> 
> -----Original Message-----
> From: Jonathan Cameron [mailto:jic23@cam.ac.uk] 
> Sent: Thursday, June 07, 2012 1:11 AM
> To: Pandruvada, Srinivas
> Cc: linux-input@vger.kernel.org; linux-iio@vger.kernel.org
> Subject: Re: [PATCH, 4/7] HID-Sensors: Added accelerometer 3D
> 
> On 6/6/2012 5:57 PM, Pandruvada, Srinivas wrote:
>> The USB sensor spec has a report structure which it sends as part of report descriptor we get during initial plug in. This report structure describes elements and their sizes. For example, it may say that an Accelerometer X axis value as 4 bytes long and what is the exponent and unit. Also it sends what control elements it has.
>> The sequence is
>> - Set sensitivity, interval, activate sys-fs interface. The USB sensor will send an event by USB-IN report when the captured sample is changed by sensitivity value and stable for at least interval. Also you need to activate the sensor so that the usb will start sending events.
>>
>> - Once USB report with the captured sample arrives, I format the data as defined in " struct accel_3d_sample" below and push to IIO ring buffer.
>> I define a single channel
>> 	IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_X_AND_Y_AND_Z,
>> 	IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
>> 	IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
>> 	ACCEL_X_Y_Z, ACCEL_3D_SCAN_ACC_X_Y_Z,
>> 		 IIO_ST('u', sizeof(struct accel_3d_sample) * 8,
>> 		sizeof(struct accel_3d_sample) * 8, 0), 0), };
>>
>> Please suggest me if this is not the way IIO channel used.
> You have 3 channels here.  The iio buffer interface will handle the fact that they are 'at the same time' on it's own.
> 
> Btw I've killed off that macro so this won't build against current tree...  Feel free if sensible to define a local macro.  The global one was a maintenance nightmare hence we scrapped it...
> 
> Sketching out what you should have
> 
> {
>           .type = IIO_ACCEL,
>           .modified = 1,
>           .channel2 = IIO_MOD_X,
>           .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
>   		      IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
>           .scan_index = 0,
>           .scan_type = {
>                .sign = 's',
>                .realbits = 12,
>                .storagebits = 16,
>           },
> }, {
>           .type = IIO_ACCEL,
>           .modified = 1,
>           .channel2 = IIO_MOD_Y,
>           .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
>   		      IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
>           .scan_index = 1,
>           .scan_type = {
>                .sign = 's',
>                .realbits = 12,
>                .storagebits = 16,
>           },
> }, {
>           .type = IIO_ACCEL,
>           .modified = 1,
>           .channel2 = IIO_MOD_Y,
>           .info_mask = IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
>   		      IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
>           .scan_index = 2,
>           .scan_type = {
>                .sign = 's',
>                .realbits = 12,
>                .storagebits = 16,
>           },
> Actually given you had scale and offset for your combined channel, those should probably be the SHARED versions.
> 
> The scan type is for a device that needs bits masked...
> 
> Hope that is enough for you to be getting on with.  Feel free to post a v2 without waiting for a formal review!
> 
> Jonathan
>> Thanks,
>> Srinivas
>>
>>
>>
>> -----Original Message-----
>> From: Jonathan Cameron [mailto:jic23@cam.ac.uk]
>> Sent: Wednesday, June 06, 2012 9:29 AM
>> To: Pandruvada, Srinivas; linux-input@vger.kernel.org
>> Cc: linux-iio@vger.kernel.org
>> Subject: Re: [PATCH, 4/7] HID-Sensors: Added accelerometer 3D
>>
>>
>>
>> srinivas pandruvada<srinivas.pandruvada@intel.com>  wrote:
>>
>>> From: Srinivas pandruvada<srinivas.pandruvada@intel.com>
>>>
>>> Added usage id processing for Accelrometer 3D. This uses IIO 
>>> interfaces "ring/buffer and trigger interface" to present data to user mode.
>>
>> I do not understand the data format.  The way iio describes the format is done through sysfs attrs built from the iio_Chan spec... that way a scan is made up of a number of channel readings each taken at roughly the same time.  However each is separately described.  Perhaps the description needs extending.  Please describe the format.
>>>
>>> Signed-off-by: Srinivas pandruvada<srinivas.pandruvada@intel.com>
>>> ---
>>> drivers/staging/hid-sensors/Makefile               |    1 +
>>> drivers/staging/hid-sensors/hid-sensor-accel-3d.c  |  387
>>> ++++++++++++++++++++
>>> drivers/staging/hid-sensors/hid-sensor-hub.c       |    1 +
>>> drivers/staging/hid-sensors/hid-sensor-interface.h |    3 +
>>> 4 files changed, 392 insertions(+), 0 deletions(-) create mode 100644 
>>> drivers/staging/hid-sensors/hid-sensor-accel-3d.c
>>>
>>> diff --git a/drivers/staging/hid-sensors/Makefile
>>> b/drivers/staging/hid-sensors/Makefile
>>> index 9a03953..4412079 100644
>>> --- a/drivers/staging/hid-sensors/Makefile
>>> +++ b/drivers/staging/hid-sensors/Makefile
>>> @@ -9,4 +9,5 @@ hid-sensors-y := hid-sensor-hub.o  hid-sensors-y += 
>>> hid-sensor-attributes.o  hid-sensors-y += hid-sensor-ring.o 
>>> hid-sensors-y += hid-sensor-trigger.o
>>> +hid-sensors-y += hid-sensor-accel-3d.o
>>> obj-$(CONFIG_HID_SENSORS) += hid-sensors.o diff --git 
>>> a/drivers/staging/hid-sensors/hid-sensor-accel-3d.c
>>> b/drivers/staging/hid-sensors/hid-sensor-accel-3d.c
>>> new file mode 100644
>>> index 0000000..ffe2639
>>> --- /dev/null
>>> +++ b/drivers/staging/hid-sensors/hid-sensor-accel-3d.c
>>> @@ -0,0 +1,387 @@
>>> +/*
>>> + * HID Sensors Driver
>>> + * Copyright (c) 2012, Intel Corporation.
>>> + *
>>> + * This program is free software; you can redistribute it and/or
>>> modify it
>>> + * under the terms and conditions of the GNU General Public License,
>>> + * version 2, as published by the Free Software Foundation.
>>> + *
>>> + * This program is distributed in the hope it will be useful, but
>>> WITHOUT
>>> + * ANY WARRANTY; without even the implied warranty of 
>>> + MERCHANTABILITY
>>> or
>>> + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
>>> License for
>>> + * more details.
>>> + *
>>> + * You should have received a copy of the GNU General Public License
>>> along with
>>> + * this program; if not, write to the Free Software Foundation, 
>>> +Inc.,
>>> + * 51 Franklin St - Fifth Floor, Boston, MA 02110-1301 USA.
>>> + *
>>> + */
>>> +#include<linux/device.h>
>>> +#include<linux/hid.h>
>>> +#include<linux/usb.h>
>>> +#include "usbhid/usbhid.h"
>>> +#include<linux/module.h>
>>> +#include<linux/slab.h>
>>> +#include "iio/iio.h"
>>> +#include "iio/sysfs.h"
>>> +#include "iio/ring_sw.h"
>>> +#include "iio/trigger.h"
>>> +#include "hid-sensor-ids.h"
>>> +#include "hid-sensor-interface.h"
>>> +#include "hid-sensor-attributes.h"
>>> +
>>> +
>>> +struct accel_3d_sample {
>>> +	u16 x_sz;
>>> +	u32 accel_x;
>>> +	u16 y_sz;
>>> +	u32 accel_y;
>>> +	u16 z_sz;
>>> +	u32 accel_z;
>>> +} __packed;
>>> +
>>> +struct accel_3d_state {
>>> +	struct hid_sensor_hub_attribute_info accel_x;
>>> +	struct hid_sensor_hub_attribute_info accel_y;
>>> +	struct hid_sensor_hub_attribute_info accel_z;
>>> +	struct accel_3d_sample accel_sample_data; };
>>> +
>>> +
>>> +enum accel_3d_chan {
>>> +	ACCEL_X_Y_Z,
>>> +};
>>> +
>>> +enum accel_3d_scan {
>>> +	ACCEL_3D_SCAN_ACC_X_Y_Z,
>>> +};
>>> +
>>> +static struct iio_chan_spec accel_3d_channels[] = {
>>> +	IIO_CHAN(IIO_ACCEL, 1, 0, 0, NULL, 0, IIO_MOD_X_AND_Y_AND_Z,
>>> +	IIO_CHAN_INFO_SCALE_SEPARATE_BIT |
>>> +	IIO_CHAN_INFO_OFFSET_SEPARATE_BIT,
>>> +	ACCEL_X_Y_Z, ACCEL_3D_SCAN_ACC_X_Y_Z,
>>> +		 IIO_ST('u', sizeof(struct accel_3d_sample) * 8,
>>> +		sizeof(struct accel_3d_sample) * 8, 0), 0), };
>>> +
>>> +static ssize_t accel_3d_read_accel(struct device *dev,
>>> +				struct device_attribute *attr,
>>> +				char *buf)
>>> +{
>>> +	struct iio_dev *indio_dev = dev_get_drvdata(dev);
>>> +	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>>> +	struct accel_3d_state *accel_state =
>>> +			(struct accel_3d_state *)st->private;
>>> +	struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
>>> +	int report_id = -1;
>>> +
>>> +	switch (this_attr->address) {
>>> +	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS:
>>> +		report_id = accel_state->accel_x.report_id;
>>> +		break;
>>> +	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS:
>>> +		report_id = accel_state->accel_y.report_id;
>>> +		break;
>>> +	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS:
>>> +		report_id = accel_state->accel_z.report_id;
>>> +		break;
>>> +	default:
>>> +		break;
>>> +	}
>>> +	if (report_id<  0)
>>> +		return -EINVAL;
>>> +
>>> +	return sensor_hub_input_attr_get_value(st->hdev,
>>> +			HID_USAGE_SENSOR_ACCEL_3D, this_attr->address,
>>> +			report_id, 4, buf);
>>> +}
>>> +
>>> +static int accel_3d_read_raw(struct iio_dev *indio_dev,
>>> +			      struct iio_chan_spec const *chan,
>>> +			      int *val, int *val2,
>>> +			      long mask)
>>> +{
>>> +	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>>> +	struct accel_3d_state *accel_state =
>>> +			(struct accel_3d_state *)st->private;
>>> +	*val = 0;
>>> +	*val2 = 0;
>>> +
>>> +	switch (mask) {
>>> +	case 0:
>>> +		break;
>>> +	case IIO_CHAN_INFO_SCALE:
>>> +		*val = accel_state->accel_x.units;
>>> +		break;
>>> +	case IIO_CHAN_INFO_OFFSET:
>>> +		*val = accel_state->accel_x.unit_expo;
>>> +		break;
>>> +	default:
>>> +		break;
>>> +
>>> +	}
>>> +	return IIO_VAL_INT;
>>> +}
>>> +
>>> +static int accel_3d_write_raw(struct iio_dev *indio_dev,
>>> +			       struct iio_chan_spec const *chan,
>>> +			       int val,
>>> +			       int val2,
>>> +			       long mask)
>>> +{
>>> +	printk(KERN_ERR "%s\n", __func__);
>>> +
>>> +	return 0;
>>> +}
>>> +
>>> +/* Usage specific attributes */
>>> +#define IIO_DEV_ATTR_ACCEL_OFFSET(_mode, _show, _store, _addr)  \
>>> +	IIO_DEVICE_ATTR(accel_offset, _mode, _show, _store, _addr)
>>> +
>>> +#define IIO_DEV_ATTR_ACCEL_X_OFFSET(_mode, _show, _store, _addr)
>>> \
>>> +	IIO_DEVICE_ATTR(accel_x_offset, _mode, _show, _store, _addr)
>>> +
>>> +#define IIO_DEV_ATTR_ACCEL_Y_OFFSET(_mode, _show, _store, _addr)
>>> \
>>> +	IIO_DEVICE_ATTR(accel_y_offset, _mode, _show, _store, _addr)
>>> +
>>> +#define IIO_DEV_ATTR_ACCEL_Z_OFFSET(_mode, _show, _store, _addr)
>>> \
>>> +	IIO_DEVICE_ATTR(accel_z_offset, _mode, _show, _store, _addr)
>>> +
>>> +#define IIO_DEV_ATTR_ACCEL_SENSITIVITY(_mode, _show, _store, _addr)
>>>     \
>>> +	IIO_DEVICE_ATTR(accel_sensitivity, _mode, _show, _store, _addr)
>>> +
>>> +static IIO_DEV_ATTR_ACCEL_X_OFFSET(S_IWUSR | S_IRUGO,
>>> accel_3d_read_accel,
>>> +		 NULL, HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS);
>>> +static IIO_DEV_ATTR_ACCEL_Y_OFFSET(S_IWUSR | S_IRUGO,
>>> accel_3d_read_accel,
>>> +		 NULL, HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS);
>>> +static IIO_DEV_ATTR_ACCEL_Z_OFFSET(S_IWUSR | S_IRUGO,
>>> accel_3d_read_accel,
>>> +		 NULL, HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS);
>>> +
>>> +static struct attribute *accel_3d_attributes[] = {
>>> +	/* common attributes */
>>> +	&iio_dev_attr_poll_interval.dev_attr.attr,
>>> +	&iio_dev_attr_sensitivity.dev_attr.attr,
>>> +	&iio_dev_attr_activate.dev_attr.attr,
>>> +	/* Usage specific attributes */
>>> +	&iio_dev_attr_accel_x_offset.dev_attr.attr,
>>> +	&iio_dev_attr_accel_y_offset.dev_attr.attr,
>>> +	&iio_dev_attr_accel_z_offset.dev_attr.attr,
>>> +	NULL,
>>> +};
>>> +
>>> +static const struct attribute_group accel_3d_attribute_group = {
>>> +	.attrs = accel_3d_attributes,
>>> +};
>>> +
>>> +static const struct iio_info accel_3d_info = {
>>> +	.attrs =&accel_3d_attribute_group,
>>> +	.driver_module = THIS_MODULE,
>>> +	.read_raw =&accel_3d_read_raw,
>>> +	.write_raw =&accel_3d_write_raw,
>>> +};
>>> +
>>> +
>>> +/* Function to push data to IIO ring */ int 
>>> +accel_3d_proc_event(struct hid_device *hdev, unsigned usage_id,
>>> void *priv)
>>> +{
>>> +	struct iio_dev *indio_dev = (struct iio_dev *)priv;
>>> +	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>>> +	struct accel_3d_state *accel_state =
>>> +			(struct accel_3d_state *)st->private;
>>> +
>>> +	hid_dbg(hdev, "accel_3d_proc_event\n");
>>> +	if (st->data_ready)
>>> +		hid_sensor_push_data_to_ring(indio_dev,
>>> +				(u8 *)&accel_state->accel_sample_data,
>>> +				sizeof(struct accel_3d_sample));
>>> +	else
>>> +		hid_dbg(hdev, "accel_3d_proc_event data not ready\n");
>>> +	return 0;
>>> +}
>>> +
>>> +/* Capture samples in local storage */ int 
>>> +accel_3d_capture_sample(struct hid_device *hdev, unsigned
>>> usage_id,
>>> +				 size_t raw_len, char *raw_data, void *priv) {
>>> +	struct iio_dev *indio_dev = (struct iio_dev *)priv;
>>> +	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>>> +	struct accel_3d_state *accel_state =
>>> +			(struct accel_3d_state *)st->private;
>>> +
>>> +	switch (usage_id) {
>>> +	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS:
>>> +		accel_state->accel_sample_data.x_sz = raw_len;
>>> +		accel_state->accel_sample_data.accel_x =
>>> +		*(u32 *)raw_data;
>>> +		break;
>>> +	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS:
>>> +		accel_state->accel_sample_data.y_sz = raw_len;
>>> +		accel_state->accel_sample_data.accel_y =
>>> +		*(u32 *)raw_data;
>>> +		break;
>>> +	case HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS:
>>> +		accel_state->accel_sample_data.z_sz = raw_len;
>>> +		accel_state->accel_sample_data.accel_z =
>>> +		*(u32 *)raw_data;
>>> +		break;
>>> +	default:
>>> +		break;
>>> +	}
>>> +	return 0;
>>> +}
>>> +
>>> +
>>> +/* Parse report which is specific to an usage id*/ static int 
>>> +accel_3d_parse_report(struct hid_device *hdev, unsigned
>>> usage_id,
>>> +				struct accel_3d_state *st)
>>> +{
>>> +	int ret;
>>> +
>>> +	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
>>> +			usage_id,
>>> +			HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_X_AXIS,
>>> +			&st->accel_x);
>>> +	if (!ret)
>>> +		hid_dbg(hdev, "No Accel X attribute\n");
>>> +
>>> +
>>> +	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
>>> +			usage_id,
>>> +			HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Y_AXIS,
>>> +			&st->accel_y);
>>> +	if (!ret)
>>> +		hid_dbg(hdev, "No Accel Y attribute\n");
>>> +
>>> +
>>> +	ret = sensor_hub_input_get_attribute_info(hdev, HID_INPUT_REPORT,
>>> +			usage_id,
>>> +			HID_USAGE_SENSOR_DATA_MOTION_ACCELERATION_Z_AXIS,
>>> +			&st->accel_z);
>>> +	if (!ret)
>>> +		hid_dbg(hdev, "No Accel Z attribute\n");
>>> +
>>> +	hid_dbg(hdev, "accel_3d %x:%x, %x:%x, %x:%x\n", st->accel_x.index,
>>> +			st->accel_x.report_id,
>>> +			st->accel_y.index, st->accel_y.report_id,
>>> +			st->accel_z.index, st->accel_z.report_id);
>>> +
>>> +	return 0;
>>> +}
>>> +
>>> +/* Entry function to initialize the processing for usage id */ 
>>> +static int accel_3d_enter(struct hid_device *hdev, unsigned usage_id,
>>> +				void **priv)
>>> +{
>>> +	int ret = 0;
>>> +	static char *name = "accel_3d";
>>> +	struct iio_dev *indio_dev;
>>> +	struct accel_3d_state *accel_state;
>>> +	struct hid_sensor_attributes *st;
>>> +
>>> +	accel_state = kzalloc(sizeof(struct accel_3d_state), GFP_KERNEL);
>>> +	if (accel_state == NULL) {
>>> +		ret = -ENOMEM;
>>> +		goto error_ret;
>>> +	}
>>> +
>>> +	indio_dev = iio_allocate_device(sizeof(struct
>>> hid_sensor_attributes));
>>> +	if (indio_dev == NULL) {
>>> +		ret = -ENOMEM;
>>> +		goto error_free_state;
>>> +	}
>>> +	st = iio_priv(indio_dev);
>>> +	st->usage_id = usage_id;
>>> +	st->hdev = hdev;
>>> +	st->private = (void *)accel_state;
>>> +
>>> +	ret = hid_sensor_parse_common_attributes(hdev, usage_id, st);
>>> +	if (ret) {
>>> +		hid_err(hdev, "failed to setup common attributes\n");
>>> +		goto error_free_dev;
>>> +	}
>>> +	ret = accel_3d_parse_report(hdev, usage_id, accel_state);
>>> +	if (ret) {
>>> +		hid_err(hdev, "failed to setup attributes\n");
>>> +		goto error_free_dev;
>>> +	}
>>> +
>>> +	indio_dev->channels = accel_3d_channels;
>>> +	indio_dev->num_channels =
>>> +				ARRAY_SIZE(accel_3d_channels);
>>> +	indio_dev->dev.parent =&hdev->dev;
>>> +	indio_dev->info =&accel_3d_info;
>>> +	indio_dev->name = name;
>>> +	indio_dev->modes = INDIO_DIRECT_MODE;
>>> +
>>> +	ret = hid_sensor_configure_ring(indio_dev);
>>> +	if (ret) {
>>> +		hid_err(hdev, "failed to initialize the ring\n");
>>> +		goto error_free_dev;
>>> +	}
>>> +
>>> +	ret = iio_buffer_register(indio_dev,
>>> +					accel_3d_channels,
>>> +					ARRAY_SIZE(accel_3d_channels));
>>> +	if (ret) {
>>> +		hid_err(hdev, "failed to initialize the ring\n");
>>> +		goto error_unreg_ring_funcs;
>>> +	}
>>> +	st->data_ready = true;
>>> +	ret = hid_sensor_setup_trigger(indio_dev, name);
>>> +	if (ret<  0) {
>>> +		hid_err(hdev, "trigger setup failed\n");
>>> +		goto error_uninit_ring;
>>> +	}
>>> +
>>> +	ret = iio_device_register(indio_dev);
>>> +	if (ret) {
>>> +		hid_err(hdev, "device register failed\n");
>>> +		goto error_remove_trigger;
>>> +	}
>>> +	*priv = (void *)indio_dev;
>>> +	return ret;
>>> +
>>> +error_remove_trigger:
>>> +		hid_sensor_remove_trigger(indio_dev);
>>> +error_uninit_ring:
>>> +		iio_buffer_unregister(indio_dev);
>>> +error_unreg_ring_funcs:
>>> +		hid_sensor_ring_cleanup(indio_dev);
>>> +error_free_dev:
>>> +		iio_free_device(indio_dev);
>>> +error_free_state:
>>> +		kfree(accel_state);
>>> +error_ret:
>>> +		return ret;
>>> +}
>>> +
>>> +static int accel_3d_exit(struct hid_device *hdev, void *priv) {
>>> +	int ret = 0;
>>> +	struct iio_dev *indio_dev = (struct iio_dev *)priv;
>>> +	struct hid_sensor_attributes *st = iio_priv(indio_dev);
>>> +	struct accel_3d_state *accel_state =
>>> +			(struct accel_3d_state *)st->private;
>>> +
>>> +	iio_device_unregister(indio_dev);
>>> +	hid_sensor_remove_trigger(indio_dev);
>>> +	iio_buffer_unregister(indio_dev);
>>> +	hid_sensor_ring_cleanup(indio_dev);
>>> +	iio_free_device(indio_dev);
>>> +
>>> +	kfree(accel_state);
>>> +	return ret;
>>> +}
>>> +
>>> +static struct sensor_hub_callbacks accel_3d_callbacks = {
>>> +	.enter = accel_3d_enter,
>>> +	.exit = accel_3d_exit,
>>> +	.send_event = accel_3d_proc_event,
>>> +	.capture_sample = accel_3d_capture_sample, };
>>> +
>>> +struct sensor_hub_callbacks  *accel_3d_register_callbacks(void)
>>> +{
>>> +	return&accel_3d_callbacks;
>>> +}
>>> diff --git a/drivers/staging/hid-sensors/hid-sensor-hub.c
>>> b/drivers/staging/hid-sensors/hid-sensor-hub.c
>>> index 384e0d0..55ae562 100644
>>> --- a/drivers/staging/hid-sensors/hid-sensor-hub.c
>>> +++ b/drivers/staging/hid-sensors/hid-sensor-hub.c
>>> @@ -60,6 +60,7 @@ struct sensor_hub_callbacks_list {  };
>>>
>>> static struct sensor_hub_callbacks_list usage_callbacks[] = {
>>> +	{HID_USAGE_SENSOR_ACCEL_3D, accel_3d_register_callbacks},
>>> 	{0}
>>> };
>>>
>>> diff --git a/drivers/staging/hid-sensors/hid-sensor-interface.h
>>> b/drivers/staging/hid-sensors/hid-sensor-interface.h
>>> index 477494f..3f4fe57 100644
>>> --- a/drivers/staging/hid-sensors/hid-sensor-interface.h
>>> +++ b/drivers/staging/hid-sensors/hid-sensor-interface.h
>>> @@ -84,4 +84,7 @@ void hid_sensor_push_data_to_ring(struct iio_dev 
>>> *indio_dev, u8 *data,  int hid_sensor_setup_trigger(struct iio_dev 
>>> *indio_dev, char *name);  void hid_sensor_remove_trigger(struct 
>>> iio_dev *indio_dev);
>>>
>>> +/* Sensor usage id processing callbacks */ struct 
>>> +sensor_hub_callbacks *accel_3d_register_callbacks(void);
>>> +
>>> #endif
>>> --
>>> 1.7.7.6
>>>
>>> --
>>> To unsubscribe from this list: send the line "unsubscribe linux-iio" 
>>> in the body of a message to majordomo@vger.kernel.org More majordomo 
>>> info at  http://vger.kernel.org/majordomo-info.html
>>
>> --
>> Sent from my Android phone with K-9 Mail. Please excuse my brevity.
> 


^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2012-06-07 19:27 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-06-06 15:39 [PATCH, 0/7] HID Sensor Driver srinivas pandruvada
     [not found] ` <1338997164-5077-1-git-send-email-srinivas.pandruvada-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2012-06-06 15:39   ` [PATCH, 1/7] HID-Sensors: Add Intel HID sensor srinivas pandruvada
2012-06-06 15:39   ` [PATCH, 2/7] HID-Sensors: Sensor framework srinivas pandruvada
2012-06-06 15:39   ` [PATCH, 3/7] HID-Sensors: Common attributes and interfaces srinivas pandruvada
     [not found]     ` <1338997164-5077-4-git-send-email-srinivas.pandruvada-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2012-06-07  7:54       ` Jonathan Cameron
2012-06-06 15:39 ` [PATCH, 4/7] HID-Sensors: Added accelerometer 3D srinivas pandruvada
2012-06-06 16:28   ` Jonathan Cameron
2012-06-06 16:57     ` Pandruvada, Srinivas
     [not found]       ` <4FA419E87744DF4DAECD5BCE1214B7A91931B547-P5GAC/sN6hk64kNsxIetb7fspsVTdybXVpNB7YpNyf8@public.gmane.org>
2012-06-06 17:07         ` Lars-Peter Clausen
2012-06-06 17:06           ` Pandruvada, Srinivas
2012-06-07  8:10         ` Jonathan Cameron
     [not found]           ` <4FD06212.7000204-KWPb1pKIrIJaa/9Udqfwiw@public.gmane.org>
2012-06-07 15:41             ` Pandruvada, Srinivas
2012-06-07 20:27               ` Jonathan Cameron
2012-06-06 15:39 ` [PATCH, 5/7] HID-Sensors: Added Gyro 3D srinivas pandruvada
2012-06-06 15:39 ` [PATCH, 6/7] HID-Sensors: Added Compass 3D srinivas pandruvada
2012-06-06 15:39 ` [PATCH, 7/7] HID-Sensors: Added ALS srinivas pandruvada

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