All the mail mirrored from lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/9] iio: hid_Sensors: fix crash during trigger unregister
@ 2013-10-23 19:11 Srinivas Pandruvada
  2013-10-23 19:11 ` [PATCH v2 2/9] iio: hid-sensors: Add connection type Srinivas Pandruvada
                   ` (8 more replies)
  0 siblings, 9 replies; 19+ messages in thread
From: Srinivas Pandruvada @ 2013-10-23 19:11 UTC (permalink / raw
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

We can't store the trigger instance created by iio_trigger_alloc, in
trig field of iio_device structure. This needs to be stored in the
driver private data. Othewise it can result in crash during module
unload. Hence created a trig_ptr in the common data structure
for each HID sensor IIO driver and storing here.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/accel/hid-sensor-accel-3d.c             | 5 +++--
 drivers/iio/common/hid-sensors/hid-sensor-trigger.c | 9 ++++-----
 drivers/iio/common/hid-sensors/hid-sensor-trigger.h | 2 +-
 drivers/iio/gyro/hid-sensor-gyro-3d.c               | 5 +++--
 drivers/iio/light/hid-sensor-als.c                  | 5 +++--
 drivers/iio/magnetometer/hid-sensor-magn-3d.c       | 5 +++--
 include/linux/hid-sensor-hub.h                      | 1 +
 7 files changed, 18 insertions(+), 14 deletions(-)

diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
index 46d22f3..7fbe136 100644
--- a/drivers/iio/accel/hid-sensor-accel-3d.c
+++ b/drivers/iio/accel/hid-sensor-accel-3d.c
@@ -349,7 +349,7 @@ static int hid_accel_3d_probe(struct platform_device *pdev)
 error_iio_unreg:
 	iio_device_unregister(indio_dev);
 error_remove_trigger:
-	hid_sensor_remove_trigger(indio_dev);
+	hid_sensor_remove_trigger(&accel_state->common_attributes);
 error_unreg_buffer_funcs:
 	iio_triggered_buffer_cleanup(indio_dev);
 error_free_dev_mem:
@@ -362,10 +362,11 @@ static int hid_accel_3d_remove(struct platform_device *pdev)
 {
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
+	struct accel_3d_state *accel_state = iio_priv(indio_dev);
 
 	sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_ACCEL_3D);
 	iio_device_unregister(indio_dev);
-	hid_sensor_remove_trigger(indio_dev);
+	hid_sensor_remove_trigger(&accel_state->common_attributes);
 	iio_triggered_buffer_cleanup(indio_dev);
 	kfree(indio_dev->channels);
 
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
index dbc9141..759582d 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
@@ -71,11 +71,10 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
 	return 0;
 }
 
-void hid_sensor_remove_trigger(struct iio_dev *indio_dev)
+void hid_sensor_remove_trigger(struct hid_sensor_common *attrb)
 {
-	iio_trigger_unregister(indio_dev->trig);
-	iio_trigger_free(indio_dev->trig);
-	indio_dev->trig = NULL;
+	iio_trigger_unregister(attrb->trig_ptr);
+	iio_trigger_free(attrb->trig_ptr);
 }
 EXPORT_SYMBOL(hid_sensor_remove_trigger);
 
@@ -106,7 +105,7 @@ int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
 		dev_err(&indio_dev->dev, "Trigger Register Failed\n");
 		goto error_free_trig;
 	}
-	indio_dev->trig = trig;
+	indio_dev->trig = attrb->trig_ptr = trig;
 
 	return ret;
 
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.h b/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
index 9a87314..ca02f78 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.h
@@ -21,6 +21,6 @@
 
 int hid_sensor_setup_trigger(struct iio_dev *indio_dev, const char *name,
 				struct hid_sensor_common *attrb);
-void hid_sensor_remove_trigger(struct iio_dev *indio_dev);
+void hid_sensor_remove_trigger(struct hid_sensor_common *attrb);
 
 #endif
diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
index c688d97..74bbed7 100644
--- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
+++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
@@ -347,7 +347,7 @@ static int hid_gyro_3d_probe(struct platform_device *pdev)
 error_iio_unreg:
 	iio_device_unregister(indio_dev);
 error_remove_trigger:
-	hid_sensor_remove_trigger(indio_dev);
+	hid_sensor_remove_trigger(&gyro_state->common_attributes);
 error_unreg_buffer_funcs:
 	iio_triggered_buffer_cleanup(indio_dev);
 error_free_dev_mem:
@@ -360,10 +360,11 @@ static int hid_gyro_3d_remove(struct platform_device *pdev)
 {
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
+	struct gyro_3d_state *gyro_state = iio_priv(indio_dev);
 
 	sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_GYRO_3D);
 	iio_device_unregister(indio_dev);
-	hid_sensor_remove_trigger(indio_dev);
+	hid_sensor_remove_trigger(&gyro_state->common_attributes);
 	iio_triggered_buffer_cleanup(indio_dev);
 	kfree(indio_dev->channels);
 
diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
index e59d00c..771c919 100644
--- a/drivers/iio/light/hid-sensor-als.c
+++ b/drivers/iio/light/hid-sensor-als.c
@@ -313,7 +313,7 @@ static int hid_als_probe(struct platform_device *pdev)
 error_iio_unreg:
 	iio_device_unregister(indio_dev);
 error_remove_trigger:
-	hid_sensor_remove_trigger(indio_dev);
+	hid_sensor_remove_trigger(&als_state->common_attributes);
 error_unreg_buffer_funcs:
 	iio_triggered_buffer_cleanup(indio_dev);
 error_free_dev_mem:
@@ -326,10 +326,11 @@ static int hid_als_remove(struct platform_device *pdev)
 {
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
+	struct als_state *als_state = iio_priv(indio_dev);
 
 	sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_ALS);
 	iio_device_unregister(indio_dev);
-	hid_sensor_remove_trigger(indio_dev);
+	hid_sensor_remove_trigger(&als_state->common_attribute);
 	iio_triggered_buffer_cleanup(indio_dev);
 	kfree(indio_dev->channels);
 
diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
index a98460b..ff7b9da 100644
--- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c
+++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
@@ -350,7 +350,7 @@ static int hid_magn_3d_probe(struct platform_device *pdev)
 error_iio_unreg:
 	iio_device_unregister(indio_dev);
 error_remove_trigger:
-	hid_sensor_remove_trigger(indio_dev);
+	hid_sensor_remove_trigger(&magn_state->common_attributes);
 error_unreg_buffer_funcs:
 	iio_triggered_buffer_cleanup(indio_dev);
 error_free_dev_mem:
@@ -363,10 +363,11 @@ static int hid_magn_3d_remove(struct platform_device *pdev)
 {
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
+	struct magn_3d_state *magn_state = iio_priv(indio_dev);
 
 	sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_COMPASS_3D);
 	iio_device_unregister(indio_dev);
-	hid_sensor_remove_trigger(indio_dev);
+	hid_sensor_remove_trigger(&magn_state->common_attributes);
 	iio_triggered_buffer_cleanup(indio_dev);
 	kfree(indio_dev->channels);
 
diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h
index a265af2..107baec4 100644
--- a/include/linux/hid-sensor-hub.h
+++ b/include/linux/hid-sensor-hub.h
@@ -184,6 +184,7 @@ struct hid_sensor_common {
 	struct platform_device *pdev;
 	unsigned usage_id;
 	bool data_ready;
+	void *trig_ptr;
 	struct hid_sensor_hub_attribute_info poll;
 	struct hid_sensor_hub_attribute_info report_state;
 	struct hid_sensor_hub_attribute_info power_state;
-- 
1.8.3.2


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

* [PATCH v2 2/9] iio: hid-sensors: Add connection type
  2013-10-23 19:11 [PATCH v2 1/9] iio: hid_Sensors: fix crash during trigger unregister Srinivas Pandruvada
@ 2013-10-23 19:11 ` Srinivas Pandruvada
  2013-10-23 19:11 ` [PATCH v2 3/9] iio: hid-sensors: accelerometer: Add sensitivity Srinivas Pandruvada
                   ` (7 subsequent siblings)
  8 siblings, 0 replies; 19+ messages in thread
From: Srinivas Pandruvada @ 2013-10-23 19:11 UTC (permalink / raw
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

Some sensor hub firmware are very strict about the connection type
setting. The connection type specifies whether it is an integrated
or external sensor hub.
By default choosing integrated type unless changed via a module
param.
Also a fix a minor typo for POWER_STATE.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/common/hid-sensors/hid-sensor-attributes.c | 12 +++++++++---
 drivers/iio/common/hid-sensors/hid-sensor-trigger.c    |  8 ++++++++
 include/linux/hid-sensor-hub.h                         |  1 +
 include/linux/hid-sensor-ids.h                         |  6 +++++-
 4 files changed, 23 insertions(+), 4 deletions(-)

diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index 75b5473..dacd98d 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -226,7 +226,7 @@ int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
 
 	sensor_hub_input_get_attribute_info(hsdev,
 					HID_FEATURE_REPORT, usage_id,
-					HID_USAGE_SENSOR_PROY_POWER_STATE,
+					HID_USAGE_SENSOR_PROT_POWER_STATE,
 					&st->power_state);
 
 	sensor_hub_input_get_attribute_info(hsdev,
@@ -234,11 +234,17 @@ int hid_sensor_parse_common_attributes(struct hid_sensor_hub_device *hsdev,
 			HID_USAGE_SENSOR_PROP_SENSITIVITY_ABS,
 			 &st->sensitivity);
 
-	hid_dbg(hsdev->hdev, "common attributes: %x:%x, %x:%x, %x:%x %x:%x\n",
+	sensor_hub_input_get_attribute_info(hsdev,
+				HID_FEATURE_REPORT, usage_id,
+				HID_USAGE_SENSOR_PROP_SENSOR_CONNECTION_TYPE,
+				&st->conn_type);
+
+	hid_dbg(hsdev->hdev, "common attributes: %x:%x, %x:%x, %x:%x %x:%x %x:%x\n",
 			st->poll.index, st->poll.report_id,
 			st->report_state.index, st->report_state.report_id,
 			st->power_state.index, st->power_state.report_id,
-			st->sensitivity.index, st->sensitivity.report_id);
+			st->sensitivity.index, st->sensitivity.report_id,
+			st->conn_type.index, st->conn_type.report_id);
 
 	return 0;
 }
diff --git a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
index 759582d..9aff8c3 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-trigger.c
@@ -34,6 +34,10 @@ module_param(hid_sensor_named_array_base, int, 0644);
 MODULE_PARM_DESC(hid_sensor_named_array_base,
 	"HID SENSOR NAMED ARRAY BASE (0 or 1).");
 
+static int hid_sensor_conn_type = HID_USAGE_SENSOR_PROP_CONNEC_TYPE_PC_INT_ENUM;
+module_param(hid_sensor_conn_type, int, 0644);
+MODULE_PARM_DESC(hid_sensor_conn_type, "HID SENSOR CONNECT TYPE (1 to 3).");
+
 static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
 						bool state)
 {
@@ -68,6 +72,10 @@ static int hid_sensor_data_rdy_trigger_set_state(struct iio_trigger *trig,
 					st->report_state.index,
 					(s32)report_state);
 
+	sensor_hub_set_feature(st->hsdev, st->conn_type.report_id,
+					st->conn_type.index,
+					hid_sensor_conn_type);
+
 	return 0;
 }
 
diff --git a/include/linux/hid-sensor-hub.h b/include/linux/hid-sensor-hub.h
index 107baec4..27116b4 100644
--- a/include/linux/hid-sensor-hub.h
+++ b/include/linux/hid-sensor-hub.h
@@ -189,6 +189,7 @@ struct hid_sensor_common {
 	struct hid_sensor_hub_attribute_info report_state;
 	struct hid_sensor_hub_attribute_info power_state;
 	struct hid_sensor_hub_attribute_info sensitivity;
+	struct hid_sensor_hub_attribute_info conn_type;
 };
 
 /* Convert from hid unit expo to regular exponent */
diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h
index 8323775..714e3e1 100644
--- a/include/linux/hid-sensor-ids.h
+++ b/include/linux/hid-sensor-ids.h
@@ -106,6 +106,7 @@
 #define HID_USAGE_SENSOR_UNITS_DEGREES_PER_SECOND		0x15
 
 /* Common selectors */
+#define HID_USAGE_SENSOR_PROP_SENSOR_CONNECTION_TYPE		0x200309
 #define HID_USAGE_SENSOR_PROP_REPORT_INTERVAL			0x20030E
 #define HID_USAGE_SENSOR_PROP_SENSITIVITY_ABS			0x20030F
 #define HID_USAGE_SENSOR_PROP_SENSITIVITY_RANGE_PCT		0x200310
@@ -115,7 +116,10 @@
 #define HID_USAGE_SENSOR_PROP_RANGE_MAXIMUM			0x200314
 #define HID_USAGE_SENSOR_PROP_RANGE_MINIMUM			0x200315
 #define HID_USAGE_SENSOR_PROP_REPORT_STATE			0x200316
-#define HID_USAGE_SENSOR_PROY_POWER_STATE			0x200319
+#define HID_USAGE_SENSOR_PROT_POWER_STATE			0x200319
+
+/* Default connection type */
+#define HID_USAGE_SENSOR_PROP_CONNEC_TYPE_PC_INT_ENUM		0x01
 
 /* Power state enumerations */
 #define HID_USAGE_SENSOR_PROP_POWER_STATE_UNDEFINED_ENUM		0x00
-- 
1.8.3.2


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

* [PATCH v2 3/9] iio: hid-sensors: accelerometer: Add sensitivity
  2013-10-23 19:11 [PATCH v2 1/9] iio: hid_Sensors: fix crash during trigger unregister Srinivas Pandruvada
  2013-10-23 19:11 ` [PATCH v2 2/9] iio: hid-sensors: Add connection type Srinivas Pandruvada
@ 2013-10-23 19:11 ` Srinivas Pandruvada
  2013-10-23 19:11 ` [PATCH v2 4/9] iio: hid-sensors: gyro : " Srinivas Pandruvada
                   ` (6 subsequent siblings)
  8 siblings, 0 replies; 19+ messages in thread
From: Srinivas Pandruvada @ 2013-10-23 19:11 UTC (permalink / raw
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

A number of Properties that can be applied to Data Fields are per data
field basis or for all data fields. Adding sensitivity field for all
accelerometer fields, which is most commonly used in currently
available sensor hubs.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/accel/hid-sensor-accel-3d.c | 12 ++++++++++++
 include/linux/hid-sensor-ids.h          |  1 +
 2 files changed, 13 insertions(+)

diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c
index 7fbe136..b89ba92 100644
--- a/drivers/iio/accel/hid-sensor-accel-3d.c
+++ b/drivers/iio/accel/hid-sensor-accel-3d.c
@@ -261,6 +261,18 @@ static int accel_3d_parse_report(struct platform_device *pdev,
 			st->accel[1].index, st->accel[1].report_id,
 			st->accel[2].index, st->accel[2].report_id);
 
+	/* Set Sensitivity field ids, when there is no individual modifier */
+	if (st->common_attributes.sensitivity.index < 0) {
+		sensor_hub_input_get_attribute_info(hsdev,
+			HID_FEATURE_REPORT, usage_id,
+			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
+			HID_USAGE_SENSOR_DATA_ACCELERATION,
+			&st->common_attributes.sensitivity);
+		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
+			st->common_attributes.sensitivity.index,
+			st->common_attributes.sensitivity.report_id);
+	}
+
 	return ret;
 }
 
diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h
index 714e3e1..d9efa2b 100644
--- a/include/linux/hid-sensor-ids.h
+++ b/include/linux/hid-sensor-ids.h
@@ -23,6 +23,7 @@
 
 /* Accel 3D (200073) */
 #define HID_USAGE_SENSOR_ACCEL_3D				0x200073
+#define HID_USAGE_SENSOR_DATA_ACCELERATION			0x200452
 #define HID_USAGE_SENSOR_ACCEL_X_AXIS				0x200453
 #define HID_USAGE_SENSOR_ACCEL_Y_AXIS				0x200454
 #define HID_USAGE_SENSOR_ACCEL_Z_AXIS				0x200455
-- 
1.8.3.2

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

* [PATCH v2 4/9] iio: hid-sensors: gyro : Add sensitivity
  2013-10-23 19:11 [PATCH v2 1/9] iio: hid_Sensors: fix crash during trigger unregister Srinivas Pandruvada
  2013-10-23 19:11 ` [PATCH v2 2/9] iio: hid-sensors: Add connection type Srinivas Pandruvada
  2013-10-23 19:11 ` [PATCH v2 3/9] iio: hid-sensors: accelerometer: Add sensitivity Srinivas Pandruvada
@ 2013-10-23 19:11 ` Srinivas Pandruvada
  2013-10-23 19:11 ` [PATCH v2 5/9] iio: hid-sensors: light/als " Srinivas Pandruvada
                   ` (5 subsequent siblings)
  8 siblings, 0 replies; 19+ messages in thread
From: Srinivas Pandruvada @ 2013-10-23 19:11 UTC (permalink / raw
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

A number of Properties that can be applied to Data Fields are per data
field basis or for all data fields. Adding sensitivity field for all
gyro fields, which is most commonly used in currently available
sensor hubs.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/gyro/hid-sensor-gyro-3d.c | 11 +++++++++++
 include/linux/hid-sensor-ids.h        |  1 +
 2 files changed, 12 insertions(+)

diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c
index 74bbed7..d665ec3 100644
--- a/drivers/iio/gyro/hid-sensor-gyro-3d.c
+++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c
@@ -261,6 +261,17 @@ static int gyro_3d_parse_report(struct platform_device *pdev,
 			st->gyro[1].index, st->gyro[1].report_id,
 			st->gyro[2].index, st->gyro[2].report_id);
 
+	/* Set Sensitivity field ids, when there is no individual modifier */
+	if (st->common_attributes.sensitivity.index < 0) {
+		sensor_hub_input_get_attribute_info(hsdev,
+			HID_FEATURE_REPORT, usage_id,
+			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
+			HID_USAGE_SENSOR_DATA_ANGL_VELOCITY,
+			&st->common_attributes.sensitivity);
+		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
+			st->common_attributes.sensitivity.index,
+			st->common_attributes.sensitivity.report_id);
+	}
 	return ret;
 }
 
diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h
index d9efa2b..73cd4ee 100644
--- a/include/linux/hid-sensor-ids.h
+++ b/include/linux/hid-sensor-ids.h
@@ -34,6 +34,7 @@
 
 /* Gyro 3D: (200076) */
 #define HID_USAGE_SENSOR_GYRO_3D				0x200076
+#define HID_USAGE_SENSOR_DATA_ANGL_VELOCITY			0x200456
 #define HID_USAGE_SENSOR_ANGL_VELOCITY_X_AXIS			0x200457
 #define HID_USAGE_SENSOR_ANGL_VELOCITY_Y_AXIS			0x200458
 #define HID_USAGE_SENSOR_ANGL_VELOCITY_Z_AXIS			0x200459
-- 
1.8.3.2


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

* [PATCH v2 5/9] iio: hid-sensors: light/als : Add sensitivity
  2013-10-23 19:11 [PATCH v2 1/9] iio: hid_Sensors: fix crash during trigger unregister Srinivas Pandruvada
                   ` (2 preceding siblings ...)
  2013-10-23 19:11 ` [PATCH v2 4/9] iio: hid-sensors: gyro : " Srinivas Pandruvada
@ 2013-10-23 19:11 ` Srinivas Pandruvada
  2013-10-23 19:11 ` [PATCH v2 6/9] iio: hid-sensors: magnetometer " Srinivas Pandruvada
                   ` (4 subsequent siblings)
  8 siblings, 0 replies; 19+ messages in thread
From: Srinivas Pandruvada @ 2013-10-23 19:11 UTC (permalink / raw
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

A number of Properties that can be applied to Data Fields are per data
field basis or for all data fields. Adding sensitivity field for all
als fields, which is most commonly used in currently available
sensor hubs.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/light/hid-sensor-als.c | 13 ++++++++++++-
 include/linux/hid-sensor-ids.h     |  1 +
 2 files changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c
index 771c919..b518488 100644
--- a/drivers/iio/light/hid-sensor-als.c
+++ b/drivers/iio/light/hid-sensor-als.c
@@ -228,6 +228,17 @@ static int als_parse_report(struct platform_device *pdev,
 	dev_dbg(&pdev->dev, "als %x:%x\n", st->als_illum.index,
 			st->als_illum.report_id);
 
+	/* Set Sensitivity field ids, when there is no individual modifier */
+	if (st->common_attributes.sensitivity.index < 0) {
+		sensor_hub_input_get_attribute_info(hsdev,
+			HID_FEATURE_REPORT, usage_id,
+			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
+			HID_USAGE_SENSOR_DATA_LIGHT,
+			&st->common_attributes.sensitivity);
+		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
+			st->common_attributes.sensitivity.index,
+			st->common_attributes.sensitivity.report_id);
+	}
 	return ret;
 }
 
@@ -330,7 +341,7 @@ static int hid_als_remove(struct platform_device *pdev)
 
 	sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_ALS);
 	iio_device_unregister(indio_dev);
-	hid_sensor_remove_trigger(&als_state->common_attribute);
+	hid_sensor_remove_trigger(&als_state->common_attributes);
 	iio_triggered_buffer_cleanup(indio_dev);
 	kfree(indio_dev->channels);
 
diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h
index 73cd4ee..3f349fa 100644
--- a/include/linux/hid-sensor-ids.h
+++ b/include/linux/hid-sensor-ids.h
@@ -30,6 +30,7 @@
 
 /* ALS (200041) */
 #define HID_USAGE_SENSOR_ALS					0x200041
+#define HID_USAGE_SENSOR_DATA_LIGHT				0x2004d0
 #define HID_USAGE_SENSOR_LIGHT_ILLUM				0x2004d1
 
 /* Gyro 3D: (200076) */
-- 
1.8.3.2


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

* [PATCH v2 6/9] iio: hid-sensors: magnetometer : Add sensitivity
  2013-10-23 19:11 [PATCH v2 1/9] iio: hid_Sensors: fix crash during trigger unregister Srinivas Pandruvada
                   ` (3 preceding siblings ...)
  2013-10-23 19:11 ` [PATCH v2 5/9] iio: hid-sensors: light/als " Srinivas Pandruvada
@ 2013-10-23 19:11 ` Srinivas Pandruvada
  2013-10-23 19:11 ` [PATCH v2 7/9] iio: hid-sensors: Added Inclinometer 3D Srinivas Pandruvada
                   ` (3 subsequent siblings)
  8 siblings, 0 replies; 19+ messages in thread
From: Srinivas Pandruvada @ 2013-10-23 19:11 UTC (permalink / raw
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

A number of Properties that can be applied to Data Fields are per data
field basis or for all data fields. Adding sensitivity field for all
magnetometer fields, which is most commonly used in currently available
sensor hubs.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/magnetometer/hid-sensor-magn-3d.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
index ff7b9da..db9f27b 100644
--- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c
+++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c
@@ -262,6 +262,18 @@ static int magn_3d_parse_report(struct platform_device *pdev,
 			st->magn[1].index, st->magn[1].report_id,
 			st->magn[2].index, st->magn[2].report_id);
 
+	/* Set Sensitivity field ids, when there is no individual modifier */
+	if (st->common_attributes.sensitivity.index < 0) {
+		sensor_hub_input_get_attribute_info(hsdev,
+			HID_FEATURE_REPORT, usage_id,
+			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
+			HID_USAGE_SENSOR_DATA_ORIENTATION,
+			&st->common_attributes.sensitivity);
+		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
+			st->common_attributes.sensitivity.index,
+			st->common_attributes.sensitivity.report_id);
+	}
+
 	return ret;
 }
 
-- 
1.8.3.2


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

* [PATCH v2 7/9] iio: hid-sensors: Added Inclinometer 3D
  2013-10-23 19:11 [PATCH v2 1/9] iio: hid_Sensors: fix crash during trigger unregister Srinivas Pandruvada
                   ` (4 preceding siblings ...)
  2013-10-23 19:11 ` [PATCH v2 6/9] iio: hid-sensors: magnetometer " Srinivas Pandruvada
@ 2013-10-23 19:11 ` Srinivas Pandruvada
  2013-10-24 11:06   ` Jonathan Cameron
  2013-10-23 19:11 ` [PATCH v2 8/9] iio: Add channel modifiers for Quaternion Rotations Srinivas Pandruvada
                   ` (2 subsequent siblings)
  8 siblings, 1 reply; 19+ messages in thread
From: Srinivas Pandruvada @ 2013-10-23 19:11 UTC (permalink / raw
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

Added usage id processing for Inclinometer 3D. This uses IIO
interfaces for triggered buffer to present data to user
mode.This uses HID sensor framework for registering callback
events from the sensor hub.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/Kconfig                          |   1 +
 drivers/iio/Makefile                         |   1 +
 drivers/iio/orientation/Kconfig              |  19 ++
 drivers/iio/orientation/Makefile             |   6 +
 drivers/iio/orientation/hid-sensor-incl-3d.c | 428 +++++++++++++++++++++++++++
 include/linux/hid-sensor-ids.h               |   9 +
 6 files changed, 464 insertions(+)
 create mode 100644 drivers/iio/orientation/Kconfig
 create mode 100644 drivers/iio/orientation/Makefile
 create mode 100644 drivers/iio/orientation/hid-sensor-incl-3d.c

diff --git a/drivers/iio/Kconfig b/drivers/iio/Kconfig
index 90cf0cd..73ff5bb 100644
--- a/drivers/iio/Kconfig
+++ b/drivers/iio/Kconfig
@@ -68,6 +68,7 @@ source "drivers/iio/gyro/Kconfig"
 source "drivers/iio/imu/Kconfig"
 source "drivers/iio/light/Kconfig"
 source "drivers/iio/magnetometer/Kconfig"
+source "drivers/iio/orientation/Kconfig"
 if IIO_TRIGGER
    source "drivers/iio/trigger/Kconfig"
 endif #IIO_TRIGGER
diff --git a/drivers/iio/Makefile b/drivers/iio/Makefile
index bcf7e9e..c682e1b 100644
--- a/drivers/iio/Makefile
+++ b/drivers/iio/Makefile
@@ -21,6 +21,7 @@ obj-y += frequency/
 obj-y += imu/
 obj-y += light/
 obj-y += magnetometer/
+obj-y += orientation/
 obj-y += pressure/
 obj-y += temperature/
 obj-y += trigger/
diff --git a/drivers/iio/orientation/Kconfig b/drivers/iio/orientation/Kconfig
new file mode 100644
index 0000000..58c62c8
--- /dev/null
+++ b/drivers/iio/orientation/Kconfig
@@ -0,0 +1,19 @@
+#
+# Inclinometer sensors
+#
+# When adding new entries keep the list in alphabetical order
+
+menu "Inclinometer sensors"
+
+config HID_SENSOR_INCLINOMETER_3D
+	depends on HID_SENSOR_HUB
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+	select HID_SENSOR_IIO_COMMON
+	select HID_SENSOR_IIO_TRIGGER
+	tristate "HID Inclinometer 3D"
+	help
+	  Say yes here to build support for the HID SENSOR
+	  Inclinometer 3D.
+
+endmenu
diff --git a/drivers/iio/orientation/Makefile b/drivers/iio/orientation/Makefile
new file mode 100644
index 0000000..2c97572
--- /dev/null
+++ b/drivers/iio/orientation/Makefile
@@ -0,0 +1,6 @@
+#
+# Makefile for industrial I/O Inclinometer sensor drivers
+#
+
+# When adding new entries keep the list in alphabetical order
+obj-$(CONFIG_HID_SENSOR_INCLINOMETER_3D) += hid-sensor-incl-3d.o
diff --git a/drivers/iio/orientation/hid-sensor-incl-3d.c b/drivers/iio/orientation/hid-sensor-incl-3d.c
new file mode 100644
index 0000000..148d4e5
--- /dev/null
+++ b/drivers/iio/orientation/hid-sensor-incl-3d.c
@@ -0,0 +1,428 @@
+/*
+ * HID Sensors Driver
+ * Copyright (c) 2013, 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.
+ *
+ */
+
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/slab.h>
+#include <linux/hid-sensor-hub.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
+#include "../common/hid-sensors/hid-sensor-trigger.h"
+
+enum incl_3d_channel {
+	CHANNEL_SCAN_INDEX_X,
+	CHANNEL_SCAN_INDEX_Y,
+	CHANNEL_SCAN_INDEX_Z,
+	INCLI_3D_CHANNEL_MAX,
+};
+
+struct incl_3d_state {
+	struct hid_sensor_hub_callbacks callbacks;
+	struct hid_sensor_common common_attributes;
+	struct hid_sensor_hub_attribute_info incl[INCLI_3D_CHANNEL_MAX];
+	u32 incl_val[INCLI_3D_CHANNEL_MAX];
+};
+
+static const u32 incl_3d_addresses[INCLI_3D_CHANNEL_MAX] = {
+	HID_USAGE_SENSOR_ORIENT_TILT_X,
+	HID_USAGE_SENSOR_ORIENT_TILT_Y,
+	HID_USAGE_SENSOR_ORIENT_TILT_Z
+};
+
+/* Channel definitions */
+static const struct iio_chan_spec incl_3d_channels[] = {
+	{
+		.type = IIO_INCLI,
+		.modified = 1,
+		.channel2 = IIO_MOD_X,
+		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
+		BIT(IIO_CHAN_INFO_SCALE) |
+		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_HYSTERESIS),
+		.scan_index = CHANNEL_SCAN_INDEX_X,
+	}, {
+		.type = IIO_INCLI,
+		.modified = 1,
+		.channel2 = IIO_MOD_Y,
+		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
+		BIT(IIO_CHAN_INFO_SCALE) |
+		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_HYSTERESIS),
+		.scan_index = CHANNEL_SCAN_INDEX_Y,
+	}, {
+		.type = IIO_INCLI,
+		.modified = 1,
+		.channel2 = IIO_MOD_Z,
+		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
+		BIT(IIO_CHAN_INFO_SCALE) |
+		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_HYSTERESIS),
+		.scan_index = CHANNEL_SCAN_INDEX_Z,
+	}
+};
+
+/* Adjust channel real bits based on report descriptor */
+static void incl_3d_adjust_channel_bit_mask(struct iio_chan_spec *channels,
+						int channel, int size)
+{
+	channels[channel].scan_type.sign = 's';
+	/* Real storage bits will change based on the report desc. */
+	channels[channel].scan_type.realbits = size * 8;
+	/* Maximum size of a sample to capture is u32 */
+	channels[channel].scan_type.storagebits = sizeof(u32) * 8;
+}
+
+/* Channel read_raw handler */
+static int incl_3d_read_raw(struct iio_dev *indio_dev,
+			      struct iio_chan_spec const *chan,
+			      int *val, int *val2,
+			      long mask)
+{
+	struct incl_3d_state *incl_state = iio_priv(indio_dev);
+	int report_id = -1;
+	u32 address;
+	int ret_type;
+
+	*val = 0;
+	*val2 = 0;
+	switch (mask) {
+	case 0:
+		report_id =
+			incl_state->incl[chan->scan_index].report_id;
+		address = incl_3d_addresses[chan->scan_index];
+		if (report_id >= 0)
+			*val = sensor_hub_input_attr_get_raw_value(
+				incl_state->common_attributes.hsdev,
+				HID_USAGE_SENSOR_INCLINOMETER_3D, address,
+				report_id);
+		else {
+			return -EINVAL;
+		}
+		ret_type = IIO_VAL_INT;
+		break;
+	case IIO_CHAN_INFO_SCALE:
+		*val = incl_state->incl[CHANNEL_SCAN_INDEX_X].units;
+		ret_type = IIO_VAL_INT;
+		break;
+	case IIO_CHAN_INFO_OFFSET:
+		*val = hid_sensor_convert_exponent(
+			incl_state->incl[CHANNEL_SCAN_INDEX_X].unit_expo);
+		ret_type = IIO_VAL_INT;
+		break;
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		ret_type = hid_sensor_read_samp_freq_value(
+			&incl_state->common_attributes, val, val2);
+		break;
+	case IIO_CHAN_INFO_HYSTERESIS:
+		ret_type = hid_sensor_read_raw_hyst_value(
+			&incl_state->common_attributes, val, val2);
+		break;
+	default:
+		ret_type = -EINVAL;
+		break;
+	}
+
+	return ret_type;
+}
+
+/* Channel write_raw handler */
+static int incl_3d_write_raw(struct iio_dev *indio_dev,
+			       struct iio_chan_spec const *chan,
+			       int val,
+			       int val2,
+			       long mask)
+{
+	struct incl_3d_state *incl_state = iio_priv(indio_dev);
+	int ret;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		ret = hid_sensor_write_samp_freq_value(
+				&incl_state->common_attributes, val, val2);
+		break;
+	case IIO_CHAN_INFO_HYSTERESIS:
+		ret = hid_sensor_write_raw_hyst_value(
+				&incl_state->common_attributes, val, val2);
+		break;
+	default:
+		ret = -EINVAL;
+	}
+
+	return ret;
+}
+
+static const struct iio_info incl_3d_info = {
+	.driver_module = THIS_MODULE,
+	.read_raw = &incl_3d_read_raw,
+	.write_raw = &incl_3d_write_raw,
+};
+
+/* Function to push data to buffer */
+static void hid_sensor_push_data(struct iio_dev *indio_dev, u8 *data, int len)
+{
+	dev_dbg(&indio_dev->dev, "hid_sensor_push_data\n");
+	iio_push_to_buffers(indio_dev, (u8 *)data);
+}
+
+/* Callback handler to send event after all samples are received and captured */
+static int incl_3d_proc_event(struct hid_sensor_hub_device *hsdev,
+				unsigned usage_id,
+				void *priv)
+{
+	struct iio_dev *indio_dev = platform_get_drvdata(priv);
+	struct incl_3d_state *incl_state = iio_priv(indio_dev);
+
+	dev_dbg(&indio_dev->dev, "incl_3d_proc_event [%d]\n",
+				incl_state->common_attributes.data_ready);
+	if (incl_state->common_attributes.data_ready)
+		hid_sensor_push_data(indio_dev,
+				(u8 *)incl_state->incl_val,
+				sizeof(incl_state->incl_val));
+
+	return 0;
+}
+
+/* Capture samples in local storage */
+static int incl_3d_capture_sample(struct hid_sensor_hub_device *hsdev,
+				unsigned usage_id,
+				size_t raw_len, char *raw_data,
+				void *priv)
+{
+	struct iio_dev *indio_dev = platform_get_drvdata(priv);
+	struct incl_3d_state *incl_state = iio_priv(indio_dev);
+	int ret = 0;
+
+	switch (usage_id) {
+	case HID_USAGE_SENSOR_ORIENT_TILT_X:
+		incl_state->incl_val[CHANNEL_SCAN_INDEX_X] = *(u32 *)raw_data;
+	break;
+	case HID_USAGE_SENSOR_ORIENT_TILT_Y:
+		incl_state->incl_val[CHANNEL_SCAN_INDEX_Y] = *(u32 *)raw_data;
+	break;
+	case HID_USAGE_SENSOR_ORIENT_TILT_Z:
+		incl_state->incl_val[CHANNEL_SCAN_INDEX_Z] = *(u32 *)raw_data;
+	break;
+	default:
+		ret = -EINVAL;
+		break;
+	}
+
+	return ret;
+}
+
+/* Parse report which is specific to an usage id*/
+static int incl_3d_parse_report(struct platform_device *pdev,
+				struct hid_sensor_hub_device *hsdev,
+				struct iio_chan_spec *channels,
+				unsigned usage_id,
+				struct incl_3d_state *st)
+{
+	int ret;
+
+	ret = sensor_hub_input_get_attribute_info(hsdev,
+				HID_INPUT_REPORT,
+				usage_id,
+				HID_USAGE_SENSOR_ORIENT_TILT_X,
+				&st->incl[CHANNEL_SCAN_INDEX_X]);
+	if (ret)
+		return ret;
+	incl_3d_adjust_channel_bit_mask(channels,
+				CHANNEL_SCAN_INDEX_X,
+				st->incl[CHANNEL_SCAN_INDEX_X].size);
+
+	ret = sensor_hub_input_get_attribute_info(hsdev,
+				HID_INPUT_REPORT,
+				usage_id,
+				HID_USAGE_SENSOR_ORIENT_TILT_Y,
+				&st->incl[CHANNEL_SCAN_INDEX_Y]);
+	if (ret)
+		return ret;
+	incl_3d_adjust_channel_bit_mask(channels,
+				CHANNEL_SCAN_INDEX_Y,
+				st->incl[CHANNEL_SCAN_INDEX_Y].size);
+
+	ret = sensor_hub_input_get_attribute_info(hsdev,
+				HID_INPUT_REPORT,
+				usage_id,
+				HID_USAGE_SENSOR_ORIENT_TILT_Z,
+				&st->incl[CHANNEL_SCAN_INDEX_Z]);
+	if (ret)
+		return ret;
+	incl_3d_adjust_channel_bit_mask(channels,
+				CHANNEL_SCAN_INDEX_Z,
+				st->incl[CHANNEL_SCAN_INDEX_Z].size);
+
+	dev_dbg(&pdev->dev, "incl_3d %x:%x, %x:%x, %x:%x\n",
+			st->incl[0].index,
+			st->incl[0].report_id,
+			st->incl[1].index, st->incl[1].report_id,
+			st->incl[2].index, st->incl[2].report_id);
+
+	/* Set Sensitivity field ids, when there is no individual modifier */
+	if (st->common_attributes.sensitivity.index < 0) {
+		sensor_hub_input_get_attribute_info(hsdev,
+			HID_FEATURE_REPORT, usage_id,
+			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
+			HID_USAGE_SENSOR_DATA_ORIENTATION,
+			&st->common_attributes.sensitivity);
+		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
+			st->common_attributes.sensitivity.index,
+			st->common_attributes.sensitivity.report_id);
+	}
+	return ret;
+}
+
+/* Function to initialize the processing for usage id */
+static int hid_incl_3d_probe(struct platform_device *pdev)
+{
+	int ret;
+	static char *name = "incli_3d";
+	struct iio_dev *indio_dev;
+	struct incl_3d_state *incl_state;
+	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct iio_chan_spec *channels;
+
+	indio_dev = devm_iio_device_alloc(&pdev->dev,
+					  sizeof(struct incl_3d_state));
+	if (indio_dev == NULL)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, indio_dev);
+
+	incl_state = iio_priv(indio_dev);
+	incl_state->common_attributes.hsdev = hsdev;
+	incl_state->common_attributes.pdev = pdev;
+
+	ret = hid_sensor_parse_common_attributes(hsdev,
+				HID_USAGE_SENSOR_INCLINOMETER_3D,
+				&incl_state->common_attributes);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to setup common attributes\n");
+		return ret;
+	}
+
+	channels = kmemdup(incl_3d_channels, sizeof(incl_3d_channels),
+			   GFP_KERNEL);
+	if (!channels) {
+		dev_err(&pdev->dev, "failed to duplicate channels\n");
+		return -ENOMEM;
+	}
+
+	ret = incl_3d_parse_report(pdev, hsdev, channels,
+				HID_USAGE_SENSOR_INCLINOMETER_3D, incl_state);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to setup attributes\n");
+		goto error_free_dev_mem;
+	}
+
+	indio_dev->channels = channels;
+	indio_dev->num_channels = ARRAY_SIZE(incl_3d_channels);
+	indio_dev->dev.parent = &pdev->dev;
+	indio_dev->info = &incl_3d_info;
+	indio_dev->name = name;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+
+	ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
+		NULL, NULL);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
+		goto error_free_dev_mem;
+	}
+	incl_state->common_attributes.data_ready = false;
+	ret = hid_sensor_setup_trigger(indio_dev, name,
+					&incl_state->common_attributes);
+	if (ret) {
+		dev_err(&pdev->dev, "trigger setup failed\n");
+		goto error_unreg_buffer_funcs;
+	}
+
+	ret = iio_device_register(indio_dev);
+	if (ret) {
+		dev_err(&pdev->dev, "device register failed\n");
+		goto error_remove_trigger;
+	}
+
+	incl_state->callbacks.send_event = incl_3d_proc_event;
+	incl_state->callbacks.capture_sample = incl_3d_capture_sample;
+	incl_state->callbacks.pdev = pdev;
+	ret = sensor_hub_register_callback(hsdev,
+					HID_USAGE_SENSOR_INCLINOMETER_3D,
+					&incl_state->callbacks);
+	if (ret) {
+		dev_err(&pdev->dev, "callback reg failed\n");
+		goto error_iio_unreg;
+	}
+
+	return 0;
+
+error_iio_unreg:
+	iio_device_unregister(indio_dev);
+error_remove_trigger:
+	hid_sensor_remove_trigger(&incl_state->common_attributes);
+error_unreg_buffer_funcs:
+	iio_triggered_buffer_cleanup(indio_dev);
+error_free_dev_mem:
+	kfree(indio_dev->channels);
+	return ret;
+}
+
+/* Function to deinitialize the processing for usage id */
+static int hid_incl_3d_remove(struct platform_device *pdev)
+{
+	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
+	struct incl_3d_state *incl_state = iio_priv(indio_dev);
+
+	sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_INCLINOMETER_3D);
+	iio_device_unregister(indio_dev);
+	hid_sensor_remove_trigger(&incl_state->common_attributes);
+	iio_triggered_buffer_cleanup(indio_dev);
+	kfree(indio_dev->channels);
+
+	return 0;
+}
+
+static struct platform_device_id hid_incl_3d_ids[] = {
+	{
+		/* Format: HID-SENSOR-usage_id_in_hex_lowercase */
+		.name = "HID-SENSOR-200086",
+	},
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(platform, hid_incl_3d_ids);
+
+static struct platform_driver hid_incl_3d_platform_driver = {
+	.id_table = hid_incl_3d_ids,
+	.driver = {
+		.name	= KBUILD_MODNAME,
+		.owner	= THIS_MODULE,
+	},
+	.probe		= hid_incl_3d_probe,
+	.remove		= hid_incl_3d_remove,
+};
+module_platform_driver(hid_incl_3d_platform_driver);
+
+MODULE_DESCRIPTION("HID Sensor Inclinometer 3D");
+MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h
index 3f349fa..9521286 100644
--- a/include/linux/hid-sensor-ids.h
+++ b/include/linux/hid-sensor-ids.h
@@ -42,6 +42,7 @@
 
 /* ORIENTATION: Compass 3D: (200083) */
 #define HID_USAGE_SENSOR_COMPASS_3D				0x200083
+#define HID_USAGE_SENSOR_DATA_ORIENTATION			0x200470
 #define HID_USAGE_SENSOR_ORIENT_MAGN_HEADING			0x200471
 #define HID_USAGE_SENSOR_ORIENT_MAGN_HEADING_X			0x200472
 #define HID_USAGE_SENSOR_ORIENT_MAGN_HEADING_Y			0x200473
@@ -57,10 +58,14 @@
 #define HID_USAGE_SENSOR_ORIENT_DISTANCE_Y			0x20047B
 #define HID_USAGE_SENSOR_ORIENT_DISTANCE_Z			0x20047C
 #define HID_USAGE_SENSOR_ORIENT_DISTANCE_OUT_OF_RANGE		0x20047D
+
+/* ORIENTATION: Inclinometer 3D: (200086) */
+#define HID_USAGE_SENSOR_INCLINOMETER_3D			0x200086
 #define HID_USAGE_SENSOR_ORIENT_TILT				0x20047E
 #define HID_USAGE_SENSOR_ORIENT_TILT_X				0x20047F
 #define HID_USAGE_SENSOR_ORIENT_TILT_Y				0x200480
 #define HID_USAGE_SENSOR_ORIENT_TILT_Z				0x200481
+
 #define HID_USAGE_SENSOR_ORIENT_ROTATION_MATRIX			0x200482
 #define HID_USAGE_SENSOR_ORIENT_QUATERNION			0x200483
 #define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX			0x200484
@@ -136,4 +141,8 @@
 #define HID_USAGE_SENSOR_PROP_REPORTING_STATE_NO_EVENTS_ENUM		0x00
 #define HID_USAGE_SENSOR_PROP_REPORTING_STATE_ALL_EVENTS_ENUM		0x01
 
+/* Per data field properties */
+#define HID_USAGE_SENSOR_DATA_MOD_NONE					0x00
+#define HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS		0x1000
+
 #endif
-- 
1.8.3.2


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

* [PATCH v2 8/9] iio: Add channel modifiers for Quaternion Rotations
  2013-10-23 19:11 [PATCH v2 1/9] iio: hid_Sensors: fix crash during trigger unregister Srinivas Pandruvada
                   ` (5 preceding siblings ...)
  2013-10-23 19:11 ` [PATCH v2 7/9] iio: hid-sensors: Added Inclinometer 3D Srinivas Pandruvada
@ 2013-10-23 19:11 ` Srinivas Pandruvada
  2013-10-24 11:18   ` Jonathan Cameron
  2013-10-23 19:11 ` [PATCH v2 9/9] iio: hid-sensors: Added device rotation support Srinivas Pandruvada
  2013-10-24 10:42 ` [PATCH v2 1/9] iio: hid_Sensors: fix crash during trigger unregister Jonathan Cameron
  8 siblings, 1 reply; 19+ messages in thread
From: Srinivas Pandruvada @ 2013-10-23 19:11 UTC (permalink / raw
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

A quaternion is composed of four components: a vector with x, y, z
coordinates and a w rotation. Added channel modifiers for exporting
these four components via user space.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/industrialio-core.c | 4 ++++
 include/linux/iio/types.h       | 4 ++++
 2 files changed, 8 insertions(+)

diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
index f95c697..4ffaead 100644
--- a/drivers/iio/industrialio-core.c
+++ b/drivers/iio/industrialio-core.c
@@ -80,6 +80,10 @@ static const char * const iio_modifier_names[] = {
 	[IIO_MOD_LIGHT_RED] = "red",
 	[IIO_MOD_LIGHT_GREEN] = "green",
 	[IIO_MOD_LIGHT_BLUE] = "blue",
+	[IIO_MOD_QUATERNION_X] = "quat_x",
+	[IIO_MOD_QUATERNION_Y] = "quat_y",
+	[IIO_MOD_QUATERNION_Z] = "quat_z",
+	[IIO_MOD_QUATERNION_W] = "quat_w",
 };
 
 /* relies on pairs of these shared then separate */
diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
index 88bf0f0..ac2345c 100644
--- a/include/linux/iio/types.h
+++ b/include/linux/iio/types.h
@@ -52,6 +52,10 @@ enum iio_modifier {
 	IIO_MOD_LIGHT_RED,
 	IIO_MOD_LIGHT_GREEN,
 	IIO_MOD_LIGHT_BLUE,
+	IIO_MOD_QUATERNION_X,
+	IIO_MOD_QUATERNION_Y,
+	IIO_MOD_QUATERNION_Z,
+	IIO_MOD_QUATERNION_W,
 };
 
 #define IIO_VAL_INT 1
-- 
1.8.3.2


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

* [PATCH v2 9/9] iio: hid-sensors: Added device rotation support
  2013-10-23 19:11 [PATCH v2 1/9] iio: hid_Sensors: fix crash during trigger unregister Srinivas Pandruvada
                   ` (6 preceding siblings ...)
  2013-10-23 19:11 ` [PATCH v2 8/9] iio: Add channel modifiers for Quaternion Rotations Srinivas Pandruvada
@ 2013-10-23 19:11 ` Srinivas Pandruvada
  2013-10-24 10:42 ` [PATCH v2 1/9] iio: hid_Sensors: fix crash during trigger unregister Jonathan Cameron
  8 siblings, 0 replies; 19+ messages in thread
From: Srinivas Pandruvada @ 2013-10-23 19:11 UTC (permalink / raw
  To: jic23; +Cc: linux-iio, Srinivas Pandruvada

Added usage id processing for device rotation. This uses IIO
interfaces for triggered buffer to present data to user
mode.This uses HID sensor framework for registering callback
events from the sensor hub.
Data is exported to user space in the form quaternion rotation
components.

Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
 drivers/iio/orientation/Kconfig               |  11 +
 drivers/iio/orientation/Makefile              |   1 +
 drivers/iio/orientation/hid-sensor-rotation.c | 426 ++++++++++++++++++++++++++
 include/linux/hid-sensor-ids.h                |   1 +
 4 files changed, 439 insertions(+)
 create mode 100644 drivers/iio/orientation/hid-sensor-rotation.c

diff --git a/drivers/iio/orientation/Kconfig b/drivers/iio/orientation/Kconfig
index 58c62c8..da8bd8a 100644
--- a/drivers/iio/orientation/Kconfig
+++ b/drivers/iio/orientation/Kconfig
@@ -16,4 +16,15 @@ config HID_SENSOR_INCLINOMETER_3D
 	  Say yes here to build support for the HID SENSOR
 	  Inclinometer 3D.
 
+config HID_SENSOR_DEVICE_ROTATION
+	depends on HID_SENSOR_HUB
+	select IIO_BUFFER
+	select IIO_TRIGGERED_BUFFER
+	select HID_SENSOR_IIO_COMMON
+	select HID_SENSOR_IIO_TRIGGER
+	tristate "HID Device Rotation"
+	help
+	  Say yes here to build support for the HID SENSOR
+	  device rotation.
+
 endmenu
diff --git a/drivers/iio/orientation/Makefile b/drivers/iio/orientation/Makefile
index 2c97572..4734dab 100644
--- a/drivers/iio/orientation/Makefile
+++ b/drivers/iio/orientation/Makefile
@@ -4,3 +4,4 @@
 
 # When adding new entries keep the list in alphabetical order
 obj-$(CONFIG_HID_SENSOR_INCLINOMETER_3D) += hid-sensor-incl-3d.o
+obj-$(CONFIG_HID_SENSOR_DEVICE_ROTATION) += hid-sensor-rotation.o
diff --git a/drivers/iio/orientation/hid-sensor-rotation.c b/drivers/iio/orientation/hid-sensor-rotation.c
new file mode 100644
index 0000000..95b4463
--- /dev/null
+++ b/drivers/iio/orientation/hid-sensor-rotation.c
@@ -0,0 +1,426 @@
+/*
+ * HID Sensors Driver
+ * Copyright (c) 2013, 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.
+ *
+ */
+
+#include <linux/device.h>
+#include <linux/platform_device.h>
+#include <linux/module.h>
+#include <linux/interrupt.h>
+#include <linux/irq.h>
+#include <linux/slab.h>
+#include <linux/hid-sensor-hub.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/sysfs.h>
+#include <linux/iio/buffer.h>
+#include <linux/iio/trigger_consumer.h>
+#include <linux/iio/triggered_buffer.h>
+#include "../common/hid-sensors/hid-sensor-trigger.h"
+
+enum dev_rot_channel {
+	CHANNEL_SCAN_INDEX_X,
+	CHANNEL_SCAN_INDEX_Y,
+	CHANNEL_SCAN_INDEX_Z,
+	CHANNEL_SCAN_INDEX_W,
+	DEV_ROT_CHANNEL_MAX,
+};
+
+struct dev_rot_state {
+	struct hid_sensor_hub_callbacks callbacks;
+	struct hid_sensor_common common_attributes;
+	struct hid_sensor_hub_attribute_info incl[DEV_ROT_CHANNEL_MAX];
+	u32 incl_val[DEV_ROT_CHANNEL_MAX];
+};
+
+static const u32 dev_rot_addresses[DEV_ROT_CHANNEL_MAX] = {
+	HID_USAGE_SENSOR_ORIENT_QUATERNION,
+	HID_USAGE_SENSOR_ORIENT_QUATERNION,
+	HID_USAGE_SENSOR_ORIENT_QUATERNION,
+	HID_USAGE_SENSOR_ORIENT_QUATERNION
+};
+
+/* Channel definitions */
+static const struct iio_chan_spec dev_rot_channels[] = {
+	{
+		.type = IIO_ROT,
+		.modified = 1,
+		.channel2 = IIO_MOD_QUATERNION_X,
+		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
+		BIT(IIO_CHAN_INFO_SCALE) |
+		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_HYSTERESIS),
+		.scan_index = CHANNEL_SCAN_INDEX_X,
+	}, {
+		.type = IIO_ROT,
+		.modified = 1,
+		.channel2 = IIO_MOD_QUATERNION_Y,
+		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
+		BIT(IIO_CHAN_INFO_SCALE) |
+		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_HYSTERESIS),
+		.scan_index = CHANNEL_SCAN_INDEX_Y,
+	}, {
+		.type = IIO_ROT,
+		.modified = 1,
+		.channel2 = IIO_MOD_QUATERNION_Z,
+		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
+		BIT(IIO_CHAN_INFO_SCALE) |
+		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_HYSTERESIS),
+		.scan_index = CHANNEL_SCAN_INDEX_Z,
+	}, {
+		.type = IIO_ROT,
+		.modified = 1,
+		.channel2 = IIO_MOD_QUATERNION_W,
+		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
+		BIT(IIO_CHAN_INFO_SCALE) |
+		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+		BIT(IIO_CHAN_INFO_HYSTERESIS),
+		.scan_index = CHANNEL_SCAN_INDEX_W,
+	}
+};
+
+/* Adjust channel real bits based on report descriptor */
+static void dev_rot_adjust_channel_bit_mask(struct iio_chan_spec *channels,
+						int channel, int size)
+{
+	channels[channel].scan_type.sign = 's';
+	/* Real storage bits will change based on the report desc. */
+	channels[channel].scan_type.realbits = size * 8;
+	/* Maximum size of a sample to capture is u32 */
+	channels[channel].scan_type.storagebits = sizeof(u32) * 8;
+}
+
+/* Channel read_raw handler */
+static int dev_rot_read_raw(struct iio_dev *indio_dev,
+			      struct iio_chan_spec const *chan,
+			      int *val, int *val2,
+			      long mask)
+{
+	struct dev_rot_state *rot_state = iio_priv(indio_dev);
+	int report_id = -1;
+	u32 address;
+	int ret_type;
+
+	*val = 0;
+	*val2 = 0;
+	switch (mask) {
+	case 0:
+		report_id =
+			rot_state->incl[chan->scan_index].report_id;
+		address = dev_rot_addresses[chan->scan_index];
+		if (report_id >= 0)
+			*val = sensor_hub_input_attr_get_raw_value(
+				rot_state->common_attributes.hsdev,
+				HID_USAGE_SENSOR_DEVICE_ORIENTATION, address,
+				report_id);
+		else {
+			return -EINVAL;
+		}
+		ret_type = IIO_VAL_INT;
+		break;
+	case IIO_CHAN_INFO_SCALE:
+		*val = rot_state->incl[CHANNEL_SCAN_INDEX_X].units;
+		ret_type = IIO_VAL_INT;
+		break;
+	case IIO_CHAN_INFO_OFFSET:
+		*val = hid_sensor_convert_exponent(
+			rot_state->incl[CHANNEL_SCAN_INDEX_X].unit_expo);
+		ret_type = IIO_VAL_INT;
+		break;
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		ret_type = hid_sensor_read_samp_freq_value(
+			&rot_state->common_attributes, val, val2);
+		break;
+	case IIO_CHAN_INFO_HYSTERESIS:
+		ret_type = hid_sensor_read_raw_hyst_value(
+			&rot_state->common_attributes, val, val2);
+		break;
+	default:
+		ret_type = -EINVAL;
+		break;
+	}
+
+	return ret_type;
+}
+
+/* Channel write_raw handler */
+static int dev_rot_write_raw(struct iio_dev *indio_dev,
+			       struct iio_chan_spec const *chan,
+			       int val,
+			       int val2,
+			       long mask)
+{
+	struct dev_rot_state *rot_state = iio_priv(indio_dev);
+	int ret;
+
+	switch (mask) {
+	case IIO_CHAN_INFO_SAMP_FREQ:
+		ret = hid_sensor_write_samp_freq_value(
+				&rot_state->common_attributes, val, val2);
+		break;
+	case IIO_CHAN_INFO_HYSTERESIS:
+		ret = hid_sensor_write_raw_hyst_value(
+				&rot_state->common_attributes, val, val2);
+		break;
+	default:
+		ret = -EINVAL;
+	}
+
+	return ret;
+}
+
+static const struct iio_info dev_rot_info = {
+	.driver_module = THIS_MODULE,
+	.read_raw = &dev_rot_read_raw,
+	.write_raw = &dev_rot_write_raw,
+};
+
+/* Function to push data to buffer */
+static void hid_sensor_push_data(struct iio_dev *indio_dev, u8 *data, int len)
+{
+	dev_dbg(&indio_dev->dev, "hid_sensor_push_data >>\n");
+	iio_push_to_buffers(indio_dev, (u8 *)data);
+	dev_dbg(&indio_dev->dev, "hid_sensor_push_data <<\n");
+
+}
+
+/* Callback handler to send event after all samples are received and captured */
+static int dev_rot_proc_event(struct hid_sensor_hub_device *hsdev,
+				unsigned usage_id,
+				void *priv)
+{
+	struct iio_dev *indio_dev = platform_get_drvdata(priv);
+	struct dev_rot_state *rot_state = iio_priv(indio_dev);
+
+	dev_dbg(&indio_dev->dev, "dev_rot_proc_event [%d]\n",
+				rot_state->common_attributes.data_ready);
+
+	if (rot_state->common_attributes.data_ready)
+		hid_sensor_push_data(indio_dev,
+				(u8 *)rot_state->incl_val,
+				sizeof(rot_state->incl_val));
+
+	return 0;
+}
+
+/* Capture samples in local storage */
+static int dev_rot_capture_sample(struct hid_sensor_hub_device *hsdev,
+				unsigned usage_id,
+				size_t raw_len, char *raw_data,
+				void *priv)
+{
+	struct iio_dev *indio_dev = platform_get_drvdata(priv);
+	struct dev_rot_state *rot_state = iio_priv(indio_dev);
+
+	if (usage_id == HID_USAGE_SENSOR_ORIENT_QUATERNION) {
+		memcpy(rot_state->incl_val, raw_data,
+					sizeof(rot_state->incl_val));
+		dev_dbg(&indio_dev->dev, "Recd Quat len:%lu::%lu\n", raw_len,
+						sizeof(rot_state->incl_val));
+	}
+
+	return 0;
+}
+
+/* Parse report which is specific to an usage id*/
+static int dev_rot_parse_report(struct platform_device *pdev,
+				struct hid_sensor_hub_device *hsdev,
+				struct iio_chan_spec *channels,
+				unsigned usage_id,
+				struct dev_rot_state *st)
+{
+	int ret;
+
+	ret = sensor_hub_input_get_attribute_info(hsdev,
+				HID_INPUT_REPORT,
+				usage_id,
+				HID_USAGE_SENSOR_ORIENT_QUATERNION,
+				&st->incl[CHANNEL_SCAN_INDEX_X]);
+	if (ret)
+		return ret;
+	dev_rot_adjust_channel_bit_mask(channels,
+				CHANNEL_SCAN_INDEX_X,
+				st->incl[CHANNEL_SCAN_INDEX_X].size/4);
+
+	dev_rot_adjust_channel_bit_mask(channels,
+				CHANNEL_SCAN_INDEX_Y,
+				st->incl[CHANNEL_SCAN_INDEX_X].size/4);
+
+	dev_rot_adjust_channel_bit_mask(channels,
+				CHANNEL_SCAN_INDEX_Z,
+				st->incl[CHANNEL_SCAN_INDEX_X].size/4);
+
+	dev_rot_adjust_channel_bit_mask(channels,
+				CHANNEL_SCAN_INDEX_W,
+				st->incl[CHANNEL_SCAN_INDEX_X].size/4);
+
+	dev_dbg(&pdev->dev, "dev_rot %x:%x, %x:%x, %x:%x\n",
+			st->incl[0].index,
+			st->incl[0].report_id,
+			st->incl[1].index, st->incl[1].report_id,
+			st->incl[2].index, st->incl[2].report_id);
+
+	dev_dbg(&pdev->dev, "dev_rot: attrib size %d\n",
+				st->incl[CHANNEL_SCAN_INDEX_X].size);
+
+	/* Set Sensitivity field ids, when there is no individual modifier */
+	if (st->common_attributes.sensitivity.index < 0) {
+		sensor_hub_input_get_attribute_info(hsdev,
+			HID_FEATURE_REPORT, usage_id,
+			HID_USAGE_SENSOR_DATA_MOD_CHANGE_SENSITIVITY_ABS |
+			HID_USAGE_SENSOR_DATA_ORIENTATION,
+			&st->common_attributes.sensitivity);
+		dev_dbg(&pdev->dev, "Sensitivity index:report %d:%d\n",
+			st->common_attributes.sensitivity.index,
+			st->common_attributes.sensitivity.report_id);
+	}
+	return 0;
+}
+
+/* Function to initialize the processing for usage id */
+static int hid_dev_rot_probe(struct platform_device *pdev)
+{
+	int ret;
+	static char *name = "dev_rotation";
+	struct iio_dev *indio_dev;
+	struct dev_rot_state *rot_state;
+	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct iio_chan_spec *channels;
+
+	indio_dev = devm_iio_device_alloc(&pdev->dev,
+					  sizeof(struct dev_rot_state));
+	if (indio_dev == NULL)
+		return -ENOMEM;
+
+	platform_set_drvdata(pdev, indio_dev);
+
+	rot_state = iio_priv(indio_dev);
+	rot_state->common_attributes.hsdev = hsdev;
+	rot_state->common_attributes.pdev = pdev;
+
+	ret = hid_sensor_parse_common_attributes(hsdev,
+				HID_USAGE_SENSOR_DEVICE_ORIENTATION,
+				&rot_state->common_attributes);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to setup common attributes\n");
+		return ret;
+	}
+
+	channels = kmemdup(dev_rot_channels, sizeof(dev_rot_channels),
+			   GFP_KERNEL);
+	if (!channels) {
+		dev_err(&pdev->dev, "failed to duplicate channels\n");
+		return -ENOMEM;
+	}
+
+	ret = dev_rot_parse_report(pdev, hsdev, channels,
+			HID_USAGE_SENSOR_DEVICE_ORIENTATION, rot_state);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to setup attributes\n");
+		goto error_free_dev_mem;
+	}
+
+	indio_dev->channels = channels;
+	indio_dev->num_channels = ARRAY_SIZE(dev_rot_channels);
+	indio_dev->dev.parent = &pdev->dev;
+	indio_dev->info = &dev_rot_info;
+	indio_dev->name = name;
+	indio_dev->modes = INDIO_DIRECT_MODE;
+
+	ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
+		NULL, NULL);
+	if (ret) {
+		dev_err(&pdev->dev, "failed to initialize trigger buffer\n");
+		goto error_free_dev_mem;
+	}
+	rot_state->common_attributes.data_ready = false;
+	ret = hid_sensor_setup_trigger(indio_dev, name,
+					&rot_state->common_attributes);
+	if (ret) {
+		dev_err(&pdev->dev, "trigger setup failed\n");
+		goto error_unreg_buffer_funcs;
+	}
+
+	ret = iio_device_register(indio_dev);
+	if (ret) {
+		dev_err(&pdev->dev, "device register failed\n");
+		goto error_remove_trigger;
+	}
+
+	rot_state->callbacks.send_event = dev_rot_proc_event;
+	rot_state->callbacks.capture_sample = dev_rot_capture_sample;
+	rot_state->callbacks.pdev = pdev;
+	ret = sensor_hub_register_callback(hsdev,
+					HID_USAGE_SENSOR_DEVICE_ORIENTATION,
+					&rot_state->callbacks);
+	if (ret) {
+		dev_err(&pdev->dev, "callback reg failed\n");
+		goto error_iio_unreg;
+	}
+
+	return 0;
+
+error_iio_unreg:
+	iio_device_unregister(indio_dev);
+error_remove_trigger:
+	hid_sensor_remove_trigger(&rot_state->common_attributes);
+error_unreg_buffer_funcs:
+	iio_triggered_buffer_cleanup(indio_dev);
+error_free_dev_mem:
+	kfree(indio_dev->channels);
+	return ret;
+}
+
+/* Function to deinitialize the processing for usage id */
+static int hid_dev_rot_remove(struct platform_device *pdev)
+{
+	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
+	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
+	struct dev_rot_state *rot_state = iio_priv(indio_dev);
+
+	sensor_hub_remove_callback(hsdev, HID_USAGE_SENSOR_DEVICE_ORIENTATION);
+	iio_device_unregister(indio_dev);
+	hid_sensor_remove_trigger(&rot_state->common_attributes);
+	iio_triggered_buffer_cleanup(indio_dev);
+	kfree(indio_dev->channels);
+
+	return 0;
+}
+
+static struct platform_device_id hid_dev_rot_ids[] = {
+	{
+		/* Format: HID-SENSOR-usage_id_in_hex_lowercase */
+		.name = "HID-SENSOR-20008a",
+	},
+	{ /* sentinel */ }
+};
+MODULE_DEVICE_TABLE(platform, hid_dev_rot_ids);
+
+static struct platform_driver hid_dev_rot_platform_driver = {
+	.id_table = hid_dev_rot_ids,
+	.driver = {
+		.name	= KBUILD_MODNAME,
+		.owner	= THIS_MODULE,
+	},
+	.probe		= hid_dev_rot_probe,
+	.remove		= hid_dev_rot_remove,
+};
+module_platform_driver(hid_dev_rot_platform_driver);
+
+MODULE_DESCRIPTION("HID Sensor Device Rotation");
+MODULE_AUTHOR("Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>");
+MODULE_LICENSE("GPL");
diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h
index 9521286..72f029c 100644
--- a/include/linux/hid-sensor-ids.h
+++ b/include/linux/hid-sensor-ids.h
@@ -66,6 +66,7 @@
 #define HID_USAGE_SENSOR_ORIENT_TILT_Y				0x200480
 #define HID_USAGE_SENSOR_ORIENT_TILT_Z				0x200481
 
+#define HID_USAGE_SENSOR_DEVICE_ORIENTATION			0x20008A
 #define HID_USAGE_SENSOR_ORIENT_ROTATION_MATRIX			0x200482
 #define HID_USAGE_SENSOR_ORIENT_QUATERNION			0x200483
 #define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX			0x200484
-- 
1.8.3.2


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

* Re: [PATCH v2 1/9] iio: hid_Sensors: fix crash during trigger unregister
  2013-10-23 19:11 [PATCH v2 1/9] iio: hid_Sensors: fix crash during trigger unregister Srinivas Pandruvada
                   ` (7 preceding siblings ...)
  2013-10-23 19:11 ` [PATCH v2 9/9] iio: hid-sensors: Added device rotation support Srinivas Pandruvada
@ 2013-10-24 10:42 ` Jonathan Cameron
  2013-10-24 15:21   ` Lars-Peter Clausen
  8 siblings, 1 reply; 19+ messages in thread
From: Jonathan Cameron @ 2013-10-24 10:42 UTC (permalink / raw
  To: Srinivas Pandruvada; +Cc: linux-iio

On 10/23/13 20:11, Srinivas Pandruvada wrote:
> We can't store the trigger instance created by iio_trigger_alloc, in
> trig field of iio_device structure. This needs to be stored in the
> driver private data. Othewise it can result in crash during module
> unload. Hence created a trig_ptr in the common data structure
> for each HID sensor IIO driver and storing here.
>
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Other than the use of a void * this is fine. Please fix that little issue
up...
> --- a/include/linux/hid-sensor-hub.h
> +++ b/include/linux/hid-sensor-hub.h
> @@ -184,6 +184,7 @@ struct hid_sensor_common {
>  	struct platform_device *pdev;
>  	unsigned usage_id;
>  	bool data_ready;
> +	void *trig_ptr;
Why a void *?  It's struct iio_trigger *
Just put
struct iio_trigger;
above if you want to (reasonably) avoid including the
header.  Don't use a void pointer unless you really have no way
of knowing what the type is.

>  	struct hid_sensor_hub_attribute_info poll;
>  	struct hid_sensor_hub_attribute_info report_state;
>  	struct hid_sensor_hub_attribute_info power_state;
>

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

* Re: [PATCH v2 7/9] iio: hid-sensors: Added Inclinometer 3D
  2013-10-23 19:11 ` [PATCH v2 7/9] iio: hid-sensors: Added Inclinometer 3D Srinivas Pandruvada
@ 2013-10-24 11:06   ` Jonathan Cameron
  2013-10-24 11:11     ` Jonathan Cameron
  0 siblings, 1 reply; 19+ messages in thread
From: Jonathan Cameron @ 2013-10-24 11:06 UTC (permalink / raw
  To: Srinivas Pandruvada; +Cc: linux-iio

On 10/23/13 20:11, Srinivas Pandruvada wrote:
> Added usage id processing for Inclinometer 3D. This uses IIO
> interfaces for triggered buffer to present data to user
> mode.This uses HID sensor framework for registering callback
> events from the sensor hub.
>
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Looks good.  One little comment inline... I'd probably not have mentioned that
but as there is going to be another version fo the series, might as well tidy
it up ;)

Thanks,

> +/* Channel definitions */
> +static const struct iio_chan_spec incl_3d_channels[] = {
> +	{
> +		.type = IIO_INCLI,
> +		.modified = 1,
> +		.channel2 = IIO_MOD_X,
> +		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
> +		BIT(IIO_CHAN_INFO_SCALE) |
> +		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
> +		BIT(IIO_CHAN_INFO_HYSTERESIS),
> +		.scan_index = CHANNEL_SCAN_INDEX_X,
> +	}, {
> +		.type = IIO_INCLI,
> +		.modified = 1,
> +		.channel2 = IIO_MOD_Y,
> +		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
> +		BIT(IIO_CHAN_INFO_SCALE) |
> +		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
> +		BIT(IIO_CHAN_INFO_HYSTERESIS),
> +		.scan_index = CHANNEL_SCAN_INDEX_Y,
> +	}, {
> +		.type = IIO_INCLI,
> +		.modified = 1,
> +		.channel2 = IIO_MOD_Z,
> +		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
> +		BIT(IIO_CHAN_INFO_SCALE) |
> +		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
> +		BIT(IIO_CHAN_INFO_HYSTERESIS),
> +		.scan_index = CHANNEL_SCAN_INDEX_Z,
> +	}
> +};
> +
> +/* Adjust channel real bits based on report 
This would be cleaner if it just took the channel in question?
so
static void incl_3d_adjust_channel_bit_mask(struct iio_chan_spec *chan,
					    int size)
{
	chan->scan_type.sign = 's';
	/* Real storage bits will change based on the report desc. */
	chan->scan_type.realbits = size * 8;
	/* Maximum size of a sample to capture is u32 */
	chan->scan_type.storagebits = sizeof(u32) * 8;
}

then call as

	incl_3d_adjust_channel_bit_mask(&channels[CHANNEL_SCAN_INDEX_X],
				st->incl[CHANNEL_SCAN_INDEX_X].size);

> +static void incl_3d_adjust_channel_bit_mask(struct iio_chan_spec *channels,
> +						int channel, int size)
> +{
> +	channels[channel].scan_type.sign = 's';
> +	/* Real storage bits will change based on the report desc. */
> +	channels[channel].scan_type.realbits = size * 8;
> +	/* Maximum size of a sample to capture is u32 */
> +	channels[channel].scan_type.storagebits = sizeof(u32) * 8;
> +}
> +
...

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

* Re: [PATCH v2 7/9] iio: hid-sensors: Added Inclinometer 3D
  2013-10-24 11:06   ` Jonathan Cameron
@ 2013-10-24 11:11     ` Jonathan Cameron
  0 siblings, 0 replies; 19+ messages in thread
From: Jonathan Cameron @ 2013-10-24 11:11 UTC (permalink / raw
  To: Srinivas Pandruvada; +Cc: linux-iio

On 10/24/13 12:06, Jonathan Cameron wrote:
> On 10/23/13 20:11, Srinivas Pandruvada wrote:
>> Added usage id processing for Inclinometer 3D. This uses IIO
>> interfaces for triggered buffer to present data to user
>> mode.This uses HID sensor framework for registering callback
>> events from the sensor hub.
>>
>> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> Looks good.  One little comment inline... I'd probably not have mentioned that
> but as there is going to be another version fo the series, might as well tidy
> it up ;)

Just noticed another point to fix.  In read raw you have case 0:
We long ago defined IIO_CHAN_INFO_RAW to be 0 so please use the enum
rather than 0.

I'm guessing this might want some tidy up patches for any other remaining uses as well.

> 
> Thanks,
> 
>> +/* Channel definitions */
>> +static const struct iio_chan_spec incl_3d_channels[] = {
>> +	{
>> +		.type = IIO_INCLI,
>> +		.modified = 1,
>> +		.channel2 = IIO_MOD_X,
>> +		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
>> +		BIT(IIO_CHAN_INFO_SCALE) |
>> +		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
>> +		BIT(IIO_CHAN_INFO_HYSTERESIS),
>> +		.scan_index = CHANNEL_SCAN_INDEX_X,
>> +	}, {
>> +		.type = IIO_INCLI,
>> +		.modified = 1,
>> +		.channel2 = IIO_MOD_Y,
>> +		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
>> +		BIT(IIO_CHAN_INFO_SCALE) |
>> +		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
>> +		BIT(IIO_CHAN_INFO_HYSTERESIS),
>> +		.scan_index = CHANNEL_SCAN_INDEX_Y,
>> +	}, {
>> +		.type = IIO_INCLI,
>> +		.modified = 1,
>> +		.channel2 = IIO_MOD_Z,
>> +		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_OFFSET) |
>> +		BIT(IIO_CHAN_INFO_SCALE) |
>> +		BIT(IIO_CHAN_INFO_SAMP_FREQ) |
>> +		BIT(IIO_CHAN_INFO_HYSTERESIS),
>> +		.scan_index = CHANNEL_SCAN_INDEX_Z,
>> +	}
>> +};
>> +
>> +/* Adjust channel real bits based on report 
> This would be cleaner if it just took the channel in question?
> so
> static void incl_3d_adjust_channel_bit_mask(struct iio_chan_spec *chan,
> 					    int size)
> {
> 	chan->scan_type.sign = 's';
> 	/* Real storage bits will change based on the report desc. */
> 	chan->scan_type.realbits = size * 8;
> 	/* Maximum size of a sample to capture is u32 */
> 	chan->scan_type.storagebits = sizeof(u32) * 8;
> }
> 
> then call as
> 
> 	incl_3d_adjust_channel_bit_mask(&channels[CHANNEL_SCAN_INDEX_X],
> 				st->incl[CHANNEL_SCAN_INDEX_X].size);
> 
>> +static void incl_3d_adjust_channel_bit_mask(struct iio_chan_spec *channels,
>> +						int channel, int size)
>> +{
>> +	channels[channel].scan_type.sign = 's';
>> +	/* Real storage bits will change based on the report desc. */
>> +	channels[channel].scan_type.realbits = size * 8;
>> +	/* Maximum size of a sample to capture is u32 */
>> +	channels[channel].scan_type.storagebits = sizeof(u32) * 8;
>> +}
>> +
> ...
> --
> 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
> 

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

* Re: [PATCH v2 8/9] iio: Add channel modifiers for Quaternion Rotations
  2013-10-23 19:11 ` [PATCH v2 8/9] iio: Add channel modifiers for Quaternion Rotations Srinivas Pandruvada
@ 2013-10-24 11:18   ` Jonathan Cameron
  2013-10-24 15:17     ` Srinivas Pandruvada
  0 siblings, 1 reply; 19+ messages in thread
From: Jonathan Cameron @ 2013-10-24 11:18 UTC (permalink / raw
  To: Srinivas Pandruvada; +Cc: linux-iio, Lars-Peter Clausen, Peter Meerwald

On 10/23/13 20:11, Srinivas Pandruvada wrote:
> A quaternion is composed of four components: a vector with x, y, z
> coordinates and a w rotation. Added channel modifiers for exporting
> these four components via user space.
> 
> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Quaternions are one of the 'interesting' cases that make me wonder if we need
a slightly more generic form of read_raw.  The quaternion only has meaning
with an associated scale.  Hence you really have to guarantee that you can grab all
4 components together.

Do we need to rethink how the read callback works?

Mind you, if we do that then we need to extend the description of the buffer element
in the scan_mask.  We could define a compound description for a channel, but that is 'interesting'.

I also don't like this being defined as type IIO_ROT - the units (such as exist are different).
See next patch for what I'm referring to here.

I've cc'd a few people who might have views on this.



> ---
>  drivers/iio/industrialio-core.c | 4 ++++
>  include/linux/iio/types.h       | 4 ++++
>  2 files changed, 8 insertions(+)
> 
> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
> index f95c697..4ffaead 100644
> --- a/drivers/iio/industrialio-core.c
> +++ b/drivers/iio/industrialio-core.c
> @@ -80,6 +80,10 @@ static const char * const iio_modifier_names[] = {
>  	[IIO_MOD_LIGHT_RED] = "red",
>  	[IIO_MOD_LIGHT_GREEN] = "green",
>  	[IIO_MOD_LIGHT_BLUE] = "blue",
> +	[IIO_MOD_QUATERNION_X] = "quat_x",
> +	[IIO_MOD_QUATERNION_Y] = "quat_y",
> +	[IIO_MOD_QUATERNION_Z] = "quat_z",
> +	[IIO_MOD_QUATERNION_W] = "quat_w",
>  };
>  
>  /* relies on pairs of these shared then separate */
> diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
> index 88bf0f0..ac2345c 100644
> --- a/include/linux/iio/types.h
> +++ b/include/linux/iio/types.h
> @@ -52,6 +52,10 @@ enum iio_modifier {
>  	IIO_MOD_LIGHT_RED,
>  	IIO_MOD_LIGHT_GREEN,
>  	IIO_MOD_LIGHT_BLUE,
> +	IIO_MOD_QUATERNION_X,
> +	IIO_MOD_QUATERNION_Y,
> +	IIO_MOD_QUATERNION_Z,
> +	IIO_MOD_QUATERNION_W,
>  };
>  
>  #define IIO_VAL_INT 1
> 

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

* Re: [PATCH v2 8/9] iio: Add channel modifiers for Quaternion Rotations
  2013-10-24 11:18   ` Jonathan Cameron
@ 2013-10-24 15:17     ` Srinivas Pandruvada
  2013-10-24 16:20       ` Jonathan Cameron
  0 siblings, 1 reply; 19+ messages in thread
From: Srinivas Pandruvada @ 2013-10-24 15:17 UTC (permalink / raw
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen, Peter Meerwald

Hi Jonathan,
On 10/24/2013 04:18 AM, Jonathan Cameron wrote:
> On 10/23/13 20:11, Srinivas Pandruvada wrote:
>> A quaternion is composed of four components: a vector with x, y, z
>> coordinates and a w rotation. Added channel modifiers for exporting
>> these four components via user space.
>>
>> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> Quaternions are one of the 'interesting' cases that make me wonder if we need
> a slightly more generic form of read_raw.  The quaternion only has meaning
> with an associated scale.  Hence you really have to guarantee that you can grab all
> 4 components together.
>
> Do we need to rethink how the read callback works?
>
> Mind you, if we do that then we need to extend the description of the buffer element
> in the scan_mask.  We could define a compound description for a channel, but that is 'interesting'.
>
> I also don't like this being defined as type IIO_ROT - the units (such as exist are different).
> See next patch for what I'm referring to here.
I didn't receive your next patch with comments. Can you please resend?
Thanks,
Srinivas
> I've cc'd a few people who might have views on this.
>
>
>
>> ---
>>   drivers/iio/industrialio-core.c | 4 ++++
>>   include/linux/iio/types.h       | 4 ++++
>>   2 files changed, 8 insertions(+)
>>
>> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
>> index f95c697..4ffaead 100644
>> --- a/drivers/iio/industrialio-core.c
>> +++ b/drivers/iio/industrialio-core.c
>> @@ -80,6 +80,10 @@ static const char * const iio_modifier_names[] = {
>>   	[IIO_MOD_LIGHT_RED] = "red",
>>   	[IIO_MOD_LIGHT_GREEN] = "green",
>>   	[IIO_MOD_LIGHT_BLUE] = "blue",
>> +	[IIO_MOD_QUATERNION_X] = "quat_x",
>> +	[IIO_MOD_QUATERNION_Y] = "quat_y",
>> +	[IIO_MOD_QUATERNION_Z] = "quat_z",
>> +	[IIO_MOD_QUATERNION_W] = "quat_w",
>>   };
>>   
>>   /* relies on pairs of these shared then separate */
>> diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
>> index 88bf0f0..ac2345c 100644
>> --- a/include/linux/iio/types.h
>> +++ b/include/linux/iio/types.h
>> @@ -52,6 +52,10 @@ enum iio_modifier {
>>   	IIO_MOD_LIGHT_RED,
>>   	IIO_MOD_LIGHT_GREEN,
>>   	IIO_MOD_LIGHT_BLUE,
>> +	IIO_MOD_QUATERNION_X,
>> +	IIO_MOD_QUATERNION_Y,
>> +	IIO_MOD_QUATERNION_Z,
>> +	IIO_MOD_QUATERNION_W,
>>   };
>>   
>>   #define IIO_VAL_INT 1
>>


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

* Re: [PATCH v2 1/9] iio: hid_Sensors: fix crash during trigger unregister
  2013-10-24 10:42 ` [PATCH v2 1/9] iio: hid_Sensors: fix crash during trigger unregister Jonathan Cameron
@ 2013-10-24 15:21   ` Lars-Peter Clausen
  2013-10-24 15:40     ` Srinivas Pandruvada
  0 siblings, 1 reply; 19+ messages in thread
From: Lars-Peter Clausen @ 2013-10-24 15:21 UTC (permalink / raw
  To: Jonathan Cameron; +Cc: Srinivas Pandruvada, linux-iio

On 10/24/2013 12:42 PM, Jonathan Cameron wrote:
> On 10/23/13 20:11, Srinivas Pandruvada wrote:
>> We can't store the trigger instance created by iio_trigger_alloc, in
>> trig field of iio_device structure. This needs to be stored in the
>> driver private data. Othewise it can result in crash during module
>> unload. Hence created a trig_ptr in the common data structure
>> for each HID sensor IIO driver and storing here.
>>
>> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
> Other than the use of a void * this is fine. Please fix that little issue
> up...
>> --- a/include/linux/hid-sensor-hub.h
>> +++ b/include/linux/hid-sensor-hub.h
>> @@ -184,6 +184,7 @@ struct hid_sensor_common {
>>  	struct platform_device *pdev;
>>  	unsigned usage_id;
>>  	bool data_ready;
>> +	void *trig_ptr;
> Why a void *?  It's struct iio_trigger *
> Just put
> struct iio_trigger;
> above if you want to (reasonably) avoid including the
> header.  Don't use a void pointer unless you really have no way
> of knowing what the type is.

Also just 'trigger' might be a better name then 'trig_ptr'.

> 
>>  	struct hid_sensor_hub_attribute_info poll;
>>  	struct hid_sensor_hub_attribute_info report_state;
>>  	struct hid_sensor_hub_attribute_info power_state;
>>
> --
> 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
> 

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

* Re: [PATCH v2 1/9] iio: hid_Sensors: fix crash during trigger unregister
  2013-10-24 15:21   ` Lars-Peter Clausen
@ 2013-10-24 15:40     ` Srinivas Pandruvada
  0 siblings, 0 replies; 19+ messages in thread
From: Srinivas Pandruvada @ 2013-10-24 15:40 UTC (permalink / raw
  To: Lars-Peter Clausen; +Cc: Jonathan Cameron, linux-iio

On 10/24/2013 08:21 AM, Lars-Peter Clausen wrote:
> On 10/24/2013 12:42 PM, Jonathan Cameron wrote:
>> On 10/23/13 20:11, Srinivas Pandruvada wrote:
>>> We can't store the trigger instance created by iio_trigger_alloc, in
>>> trig field of iio_device structure. This needs to be stored in the
>>> driver private data. Othewise it can result in crash during module
>>> unload. Hence created a trig_ptr in the common data structure
>>> for each HID sensor IIO driver and storing here.
>>>
>>> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
>> Other than the use of a void * this is fine. Please fix that little issue
>> up...
>>> --- a/include/linux/hid-sensor-hub.h
>>> +++ b/include/linux/hid-sensor-hub.h
>>> @@ -184,6 +184,7 @@ struct hid_sensor_common {
>>>   	struct platform_device *pdev;
>>>   	unsigned usage_id;
>>>   	bool data_ready;
>>> +	void *trig_ptr;
>> Why a void *?  It's struct iio_trigger *
>> Just put
>> struct iio_trigger;
>> above if you want to (reasonably) avoid including the
>> header.  Don't use a void pointer unless you really have no way
>> of knowing what the type is.
> Also just 'trigger' might be a better name then 'trig_ptr'.
Will change in next patch along with the suggestions from Jonathan.

Thanks,
Srinivas
>>>   	struct hid_sensor_hub_attribute_info poll;
>>>   	struct hid_sensor_hub_attribute_info report_state;
>>>   	struct hid_sensor_hub_attribute_info power_state;
>>>
>> --
>> 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
>>
> --
> 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
>


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

* Re: [PATCH v2 8/9] iio: Add channel modifiers for Quaternion Rotations
  2013-10-24 15:17     ` Srinivas Pandruvada
@ 2013-10-24 16:20       ` Jonathan Cameron
  2013-10-28 23:44         ` Srinivas Pandruvada
  0 siblings, 1 reply; 19+ messages in thread
From: Jonathan Cameron @ 2013-10-24 16:20 UTC (permalink / raw
  To: Srinivas Pandruvada; +Cc: linux-iio, Lars-Peter Clausen, Peter Meerwald

On 10/24/13 16:17, Srinivas Pandruvada wrote:
> Hi Jonathan,
> On 10/24/2013 04:18 AM, Jonathan Cameron wrote:
>> On 10/23/13 20:11, Srinivas Pandruvada wrote:
>>> A quaternion is composed of four components: a vector with x, y, z
>>> coordinates and a w rotation. Added channel modifiers for exporting
>>> these four components via user space.
>>>
>>> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
>> Quaternions are one of the 'interesting' cases that make me wonder if we need
>> a slightly more generic form of read_raw.  The quaternion only has meaning
>> with an associated scale.  Hence you really have to guarantee that you can grab all
>> 4 components together.
>>
>> Do we need to rethink how the read callback works?
>>
>> Mind you, if we do that then we need to extend the description of the buffer element
>> in the scan_mask.  We could define a compound description for a channel, but that is 'interesting'.
>>
>> I also don't like this being defined as type IIO_ROT - the units (such as exist are different).
>> See next patch for what I'm referring to here.
> I didn't receive your next patch with comments. Can you please resend?
> Thanks,
Sorry for not being clear, I simply meant the IIO_ROT bit was in the next batch,
but as it is connected to my comment here, didn't want to start another discussion
in reply to that patch.

(hence I never replied to that patch)
> Srinivas
>> I've cc'd a few people who might have views on this.
>>
>>
>>
>>> ---
>>>   drivers/iio/industrialio-core.c | 4 ++++
>>>   include/linux/iio/types.h       | 4 ++++
>>>   2 files changed, 8 insertions(+)
>>>
>>> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
>>> index f95c697..4ffaead 100644
>>> --- a/drivers/iio/industrialio-core.c
>>> +++ b/drivers/iio/industrialio-core.c
>>> @@ -80,6 +80,10 @@ static const char * const iio_modifier_names[] = {
>>>       [IIO_MOD_LIGHT_RED] = "red",
>>>       [IIO_MOD_LIGHT_GREEN] = "green",
>>>       [IIO_MOD_LIGHT_BLUE] = "blue",
>>> +    [IIO_MOD_QUATERNION_X] = "quat_x",
>>> +    [IIO_MOD_QUATERNION_Y] = "quat_y",
>>> +    [IIO_MOD_QUATERNION_Z] = "quat_z",
>>> +    [IIO_MOD_QUATERNION_W] = "quat_w",
>>>   };
>>>     /* relies on pairs of these shared then separate */
>>> diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
>>> index 88bf0f0..ac2345c 100644
>>> --- a/include/linux/iio/types.h
>>> +++ b/include/linux/iio/types.h
>>> @@ -52,6 +52,10 @@ enum iio_modifier {
>>>       IIO_MOD_LIGHT_RED,
>>>       IIO_MOD_LIGHT_GREEN,
>>>       IIO_MOD_LIGHT_BLUE,
>>> +    IIO_MOD_QUATERNION_X,
>>> +    IIO_MOD_QUATERNION_Y,
>>> +    IIO_MOD_QUATERNION_Z,
>>> +    IIO_MOD_QUATERNION_W,
>>>   };
>>>     #define IIO_VAL_INT 1
>>>
> 
> -- 
> 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

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

* Re: [PATCH v2 8/9] iio: Add channel modifiers for Quaternion Rotations
  2013-10-24 16:20       ` Jonathan Cameron
@ 2013-10-28 23:44         ` Srinivas Pandruvada
  2013-10-29  6:54           ` Jonathan Cameron
  0 siblings, 1 reply; 19+ messages in thread
From: Srinivas Pandruvada @ 2013-10-28 23:44 UTC (permalink / raw
  To: Jonathan Cameron; +Cc: linux-iio, Lars-Peter Clausen, Peter Meerwald

On 10/24/2013 09:20 AM, Jonathan Cameron wrote:
> On 10/24/13 16:17, Srinivas Pandruvada wrote:
>> Hi Jonathan,
>> On 10/24/2013 04:18 AM, Jonathan Cameron wrote:
>>> On 10/23/13 20:11, Srinivas Pandruvada wrote:
>>>> A quaternion is composed of four components: a vector with x, y, z
>>>> coordinates and a w rotation. Added channel modifiers for exporting
>>>> these four components via user space.
>>>>
>>>> Signed-off-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
>>> Quaternions are one of the 'interesting' cases that make me wonder if we need
>>> a slightly more generic form of read_raw.  The quaternion only has meaning
>>> with an associated scale.  Hence you really have to guarantee that you can grab all
>>> 4 components together.
What if we add two members in iio_chan_info:
IIO_CHAN_INFO_TRIG_RAW_SYNC  (WR): To trigger a read of and store sample 
in internal memory
(As per HID sensor spec you have to read/write all quaternion components 
together, data is also packed together. )
IIO_CHAN_INFO_RAW_SYNC  (RD): To return individual channel raw data 
captured during IIO_CHAN_INFO_TRIG_RAW_SYNC
In this way four reads will give all component data but they are related 
to each other.
>>>
>>> Do we need to rethink how the read callback works?
>>>
>>> Mind you, if we do that then we need to extend the description of the buffer element
>>> in the scan_mask.  We could define a compound description for a channel, but that is 'interesting'.
For scan elements we have to specify a way so that the scan_elem doesn't 
contain per channel enable/disable.
We create one global channel enable sysfs entry. This is what you are 
thinking?

Thanks,
Srinivas


>>> I also don't like this being defined as type IIO_ROT - the units (such as exist are different).
>>> See next patch for what I'm referring to here.
>> I didn't receive your next patch with comments. Can you please resend?
>> Thanks,
> Sorry for not being clear, I simply meant the IIO_ROT bit was in the next batch,
> but as it is connected to my comment here, didn't want to start another discussion
> in reply to that patch.
>
> (hence I never replied to that patch)
>> Srinivas
>>> I've cc'd a few people who might have views on this.
>>>
>>>
>>>
>>>> ---
>>>>    drivers/iio/industrialio-core.c | 4 ++++
>>>>    include/linux/iio/types.h       | 4 ++++
>>>>    2 files changed, 8 insertions(+)
>>>>
>>>> diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
>>>> index f95c697..4ffaead 100644
>>>> --- a/drivers/iio/industrialio-core.c
>>>> +++ b/drivers/iio/industrialio-core.c
>>>> @@ -80,6 +80,10 @@ static const char * const iio_modifier_names[] = {
>>>>        [IIO_MOD_LIGHT_RED] = "red",
>>>>        [IIO_MOD_LIGHT_GREEN] = "green",
>>>>        [IIO_MOD_LIGHT_BLUE] = "blue",
>>>> +    [IIO_MOD_QUATERNION_X] = "quat_x",
>>>> +    [IIO_MOD_QUATERNION_Y] = "quat_y",
>>>> +    [IIO_MOD_QUATERNION_Z] = "quat_z",
>>>> +    [IIO_MOD_QUATERNION_W] = "quat_w",
>>>>    };
>>>>      /* relies on pairs of these shared then separate */
>>>> diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
>>>> index 88bf0f0..ac2345c 100644
>>>> --- a/include/linux/iio/types.h
>>>> +++ b/include/linux/iio/types.h
>>>> @@ -52,6 +52,10 @@ enum iio_modifier {
>>>>        IIO_MOD_LIGHT_RED,
>>>>        IIO_MOD_LIGHT_GREEN,
>>>>        IIO_MOD_LIGHT_BLUE,
>>>> +    IIO_MOD_QUATERNION_X,
>>>> +    IIO_MOD_QUATERNION_Y,
>>>> +    IIO_MOD_QUATERNION_Z,
>>>> +    IIO_MOD_QUATERNION_W,
>>>>    };
>>>>      #define IIO_VAL_INT 1
>>>>
>> -- 
>> 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

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

* Re: [PATCH v2 8/9] iio: Add channel modifiers for Quaternion Rotations
  2013-10-28 23:44         ` Srinivas Pandruvada
@ 2013-10-29  6:54           ` Jonathan Cameron
  0 siblings, 0 replies; 19+ messages in thread
From: Jonathan Cameron @ 2013-10-29  6:54 UTC (permalink / raw
  To: Srinivas Pandruvada; +Cc: linux-iio, Lars-Peter Clausen, Peter Meerwald



Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> wrote:
>On 10/24/2013 09:20 AM, Jonathan Cameron wrote:
>> On 10/24/13 16:17, Srinivas Pandruvada wrote:
>>> Hi Jonathan,
>>> On 10/24/2013 04:18 AM, Jonathan Cameron wrote:
>>>> On 10/23/13 20:11, Srinivas Pandruvada wrote:
>>>>> A quaternion is composed of four components: a vector with x, y, z
>>>>> coordinates and a w rotation. Added channel modifiers for
>exporting
>>>>> these four components via user space.
>>>>>
>>>>> Signed-off-by: Srinivas Pandruvada
><srinivas.pandruvada@linux.intel.com>
>>>> Quaternions are one of the 'interesting' cases that make me wonder
>if we need
>>>> a slightly more generic form of read_raw.  The quaternion only has
>meaning
>>>> with an associated scale.  Hence you really have to guarantee that
>you can grab all
>>>> 4 components together.
>What if we add two members in iio_chan_info:
>IIO_CHAN_INFO_TRIG_RAW_SYNC  (WR): To trigger a read of and store
>sample 
>in internal memory
>(As per HID sensor spec you have to read/write all quaternion
>components 
>together, data is also packed together. )
>IIO_CHAN_INFO_RAW_SYNC  (RD): To return individual channel raw data 
>captured during IIO_CHAN_INFO_TRIG_RAW_SYNC
>In this way four reads will give all component data but they are
>related 
>to each other.
That is a bit ugly. I would rather consider a single channel that outputs all 4 components and change the handling to cope.
If people want synchronized data across multiple normal channels then they should be using the buffer...
>>>>
>>>> Do we need to rethink how the read callback works?
>>>>
>>>> Mind you, if we do that then we need to extend the description of
>the buffer element
>>>> in the scan_mask.  We could define a compound description for a
>channel, but that is 'interesting'.
>For scan elements we have to specify a way so that the scan_elem
>doesn't 
>contain per channel enable/disable.
>We create one global channel enable sysfs entry. This is what you are 
>thinking?
No. Either we have a single channel which contains all 4 components or just handle them separately. If anyone requests only some of them from user space it does not matter to us even if the data will be useless.
>
>Thanks,
>Srinivas
>
>
>>>> I also don't like this being defined as type IIO_ROT - the units
>(such as exist are different).
>>>> See next patch for what I'm referring to here.
>>> I didn't receive your next patch with comments. Can you please
>resend?
>>> Thanks,
>> Sorry for not being clear, I simply meant the IIO_ROT bit was in the
>next batch,
>> but as it is connected to my comment here, didn't want to start
>another discussion
>> in reply to that patch.
>>
>> (hence I never replied to that patch)
>>> Srinivas
>>>> I've cc'd a few people who might have views on this.
>>>>
>>>>
>>>>
>>>>> ---
>>>>>    drivers/iio/industrialio-core.c | 4 ++++
>>>>>    include/linux/iio/types.h       | 4 ++++
>>>>>    2 files changed, 8 insertions(+)
>>>>>
>>>>> diff --git a/drivers/iio/industrialio-core.c
>b/drivers/iio/industrialio-core.c
>>>>> index f95c697..4ffaead 100644
>>>>> --- a/drivers/iio/industrialio-core.c
>>>>> +++ b/drivers/iio/industrialio-core.c
>>>>> @@ -80,6 +80,10 @@ static const char * const iio_modifier_names[]
>= {
>>>>>        [IIO_MOD_LIGHT_RED] = "red",
>>>>>        [IIO_MOD_LIGHT_GREEN] = "green",
>>>>>        [IIO_MOD_LIGHT_BLUE] = "blue",
>>>>> +    [IIO_MOD_QUATERNION_X] = "quat_x",
>>>>> +    [IIO_MOD_QUATERNION_Y] = "quat_y",
>>>>> +    [IIO_MOD_QUATERNION_Z] = "quat_z",
>>>>> +    [IIO_MOD_QUATERNION_W] = "quat_w",
>>>>>    };
>>>>>      /* relies on pairs of these shared then separate */
>>>>> diff --git a/include/linux/iio/types.h b/include/linux/iio/types.h
>>>>> index 88bf0f0..ac2345c 100644
>>>>> --- a/include/linux/iio/types.h
>>>>> +++ b/include/linux/iio/types.h
>>>>> @@ -52,6 +52,10 @@ enum iio_modifier {
>>>>>        IIO_MOD_LIGHT_RED,
>>>>>        IIO_MOD_LIGHT_GREEN,
>>>>>        IIO_MOD_LIGHT_BLUE,
>>>>> +    IIO_MOD_QUATERNION_X,
>>>>> +    IIO_MOD_QUATERNION_Y,
>>>>> +    IIO_MOD_QUATERNION_Z,
>>>>> +    IIO_MOD_QUATERNION_W,
>>>>>    };
>>>>>      #define IIO_VAL_INT 1
>>>>>
>>> -- 
>>> 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
>
>--
>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] 19+ messages in thread

end of thread, other threads:[~2013-10-29  6:54 UTC | newest]

Thread overview: 19+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-23 19:11 [PATCH v2 1/9] iio: hid_Sensors: fix crash during trigger unregister Srinivas Pandruvada
2013-10-23 19:11 ` [PATCH v2 2/9] iio: hid-sensors: Add connection type Srinivas Pandruvada
2013-10-23 19:11 ` [PATCH v2 3/9] iio: hid-sensors: accelerometer: Add sensitivity Srinivas Pandruvada
2013-10-23 19:11 ` [PATCH v2 4/9] iio: hid-sensors: gyro : " Srinivas Pandruvada
2013-10-23 19:11 ` [PATCH v2 5/9] iio: hid-sensors: light/als " Srinivas Pandruvada
2013-10-23 19:11 ` [PATCH v2 6/9] iio: hid-sensors: magnetometer " Srinivas Pandruvada
2013-10-23 19:11 ` [PATCH v2 7/9] iio: hid-sensors: Added Inclinometer 3D Srinivas Pandruvada
2013-10-24 11:06   ` Jonathan Cameron
2013-10-24 11:11     ` Jonathan Cameron
2013-10-23 19:11 ` [PATCH v2 8/9] iio: Add channel modifiers for Quaternion Rotations Srinivas Pandruvada
2013-10-24 11:18   ` Jonathan Cameron
2013-10-24 15:17     ` Srinivas Pandruvada
2013-10-24 16:20       ` Jonathan Cameron
2013-10-28 23:44         ` Srinivas Pandruvada
2013-10-29  6:54           ` Jonathan Cameron
2013-10-23 19:11 ` [PATCH v2 9/9] iio: hid-sensors: Added device rotation support Srinivas Pandruvada
2013-10-24 10:42 ` [PATCH v2 1/9] iio: hid_Sensors: fix crash during trigger unregister Jonathan Cameron
2013-10-24 15:21   ` Lars-Peter Clausen
2013-10-24 15:40     ` Srinivas Pandruvada

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.