Skip to contentSkip to conversation

iio: hid_Sensors: fix crash during trigger unregister

PATCH Applied Srinivas Pandruvada 2 participants 17 messages Oct 30, 2013 – Dec 7, 2013

Subsystems (3)
lore
Share & tools
lore

Srinivas Pandruvada

author maintainer
#0 lore raw

PATCH v3 1/8 iio: hid_Sensors: fix crash during trigger unregister

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.

---
 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                      | 3 +++
 7 files changed, 20 insertions(+), 14 deletions(-)
drivers/iio/accel/hid-sensor-accel-3d.c +3 -2
index 46d22f3..7fbe136 100644
@@ -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);
 
drivers/iio/common/hid-sensors/hid-sensor-trigger.c +4 -5
index dbc9141..363f8d2 100644
@@ -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->trigger);
+	iio_trigger_free(attrb->trigger);
 }
 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->trigger = trig;
 
 	return ret;
 
drivers/iio/common/hid-sensors/hid-sensor-trigger.h +1 -1
index 9a87314..ca02f78 100644
@@ -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
drivers/iio/gyro/hid-sensor-gyro-3d.c +3 -2
index c688d97..74bbed7 100644
@@ -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);
 
drivers/iio/light/hid-sensor-als.c +3 -2
index e59d00c..c104bda 100644
@@ -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_attributes);
 	iio_triggered_buffer_cleanup(indio_dev);
 	kfree(indio_dev->channels);
 
drivers/iio/magnetometer/hid-sensor-magn-3d.c +3 -2
index a98460b..ff7b9da 100644
@@ -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);
 
include/linux/hid-sensor-hub.h +3 -0
index a265af2..206a2af 100644
@@ -21,6 +21,8 @@
 
 #include <linux/hid.h>
 #include <linux/hid-sensor-ids.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/trigger.h>
 
 /**
  * struct hid_sensor_hub_attribute_info - Attribute info
@@ -184,6 +186,7 @@ struct hid_sensor_common {
 	struct platform_device *pdev;
 	unsigned usage_id;
 	bool data_ready;
+	struct iio_trigger *trigger;
 	struct hid_sensor_hub_attribute_info poll;
 	struct hid_sensor_hub_attribute_info report_state;
 	struct hid_sensor_hub_attribute_info power_state;
Signature · 1 line
1.8.3.2
author maintainer
#1 lore raw

PATCH v3 2/8 iio: hid-sensors: accelerometer: Add sensitivity

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.

---
 drivers/iio/accel/hid-sensor-accel-3d.c | 12 ++++++++++++
 include/linux/hid-sensor-ids.h          |  1 +
 2 files changed, 13 insertions(+)
drivers/iio/accel/hid-sensor-accel-3d.c +12 -0
index 7fbe136..b89ba92 100644
@@ -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;
 }
 
include/linux/hid-sensor-ids.h +1 -0
index 8323775..bd97d60 100644
@@ -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
Signature · 1 line
1.8.3.2
maintainer
#2 lore raw

Re: [PATCH v3 2/8] iio: hid-sensors: accelerometer: Add sensitivity

Quoted 6 lines · 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.

The defines needed for this bled into patch 6. Please build test you individual patches to makes sure they can be bisected.

Anyhow fixed that up and applied to the togreg branch of iio.git

Quoted 41 lines
---
 drivers/iio/accel/hid-sensor-accel-3d.c | 12 ++++++++++++
 include/linux/hid-sensor-ids.h          |  1 +
 2 files changed, 13 insertions(+)
drivers/iio/accel/hid-sensor-accel-3d.c +12 -0
index 7fbe136..b89ba92 100644
@@ -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;
 }
 
include/linux/hid-sensor-ids.h +1 -0
index 8323775..bd97d60 100644
@@ -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
author maintainer
#3 lore raw

PATCH v3 3/8 iio: hid-sensors: gyro : Add sensitivity

In reply to 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.

---
 drivers/iio/gyro/hid-sensor-gyro-3d.c | 11 +++++++++++
 include/linux/hid-sensor-ids.h        |  1 +
 2 files changed, 12 insertions(+)
drivers/iio/gyro/hid-sensor-gyro-3d.c +11 -0
index 74bbed7..d665ec3 100644
@@ -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;
 }
 
include/linux/hid-sensor-ids.h +1 -0
index bd97d60..6473d93 100644
@@ -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
Signature · 1 line
1.8.3.2
maintainer Applied
#4 lore raw

Re: [PATCH v3 3/8] iio: hid-sensors: gyro : Add sensitivity

Quoted 6 lines · 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.

Applied

Quoted 40 lines
---
 drivers/iio/gyro/hid-sensor-gyro-3d.c | 11 +++++++++++
 include/linux/hid-sensor-ids.h        |  1 +
 2 files changed, 12 insertions(+)
drivers/iio/gyro/hid-sensor-gyro-3d.c +11 -0
index 74bbed7..d665ec3 100644
@@ -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;
 }
 
include/linux/hid-sensor-ids.h +1 -0
index bd97d60..6473d93 100644
@@ -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
author maintainer
#5 lore raw

PATCH v3 4/8 iio: hid-sensors: light/als : Add sensitivity

In reply to 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.

---
 drivers/iio/light/hid-sensor-als.c | 11 +++++++++++
 include/linux/hid-sensor-ids.h     |  1 +
 2 files changed, 12 insertions(+)
drivers/iio/light/hid-sensor-als.c +11 -0
index c104bda..b518488 100644
@@ -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;
 }
 
include/linux/hid-sensor-ids.h +1 -0
index 6473d93..c7d62c7 100644
@@ -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) */
Signature · 1 line
1.8.3.2
author maintainer
#6 lore raw

PATCH v3 5/8 iio: hid-sensors: magnetometer : Add sensitivity

In reply to 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.

---
 drivers/iio/magnetometer/hid-sensor-magn-3d.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/iio/magnetometer/hid-sensor-magn-3d.c +12 -0
index ff7b9da..db9f27b 100644
@@ -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;
 }
 
Signature · 1 line
1.8.3.2
maintainer
#7 lore raw

Re: [PATCH v3 5/8] iio: hid-sensors: magnetometer : Add sensitivity

Quoted 6 lines · 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.

This is dependent on defines that don't exist. I'm guessing they are later in the series, so please fix this up.

Jonathan

Quoted 28 lines
---
 drivers/iio/magnetometer/hid-sensor-magn-3d.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)
drivers/iio/magnetometer/hid-sensor-magn-3d.c +12 -0
index ff7b9da..db9f27b 100644
@@ -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;
 }
 
author maintainer
#8 lore raw

PATCH v3 6/8 iio: hid-sensors: Added Inclinometer 3D

In reply to 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.

---
 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
drivers/iio/Kconfig +1 -0
index 90cf0cd..73ff5bb 100644
@@ -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
drivers/iio/Makefile +1 -0
index bcf7e9e..c682e1b 100644
@@ -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/
drivers/iio/orientation/Kconfig new file +19 -0
new file mode 100644
index 0000000..58c62c8
@@ -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
drivers/iio/orientation/Makefile new file +6 -0
new file mode 100644
index 0000000..2c97572
@@ -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
drivers/iio/orientation/hid-sensor-incl-3d.c new file +428 -0

428 lines not on this page · raw message

include/linux/hid-sensor-ids.h +9 -0
index c7d62c7..a3f863d 100644
@@ -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
@@ -132,4 +137,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
Signature · 1 line
1.8.3.2
author maintainer
#9 lore raw

PATCH v3 7/8 iio: Add quaternion channel

In reply to Srinivas Pandruvada

A quaternion channel type is added. Here channel information is composed of four components: a vector with x, y, z coordinates and a w rotation. Reusing x, y, z channel modifiers, but added "w" component in the modifier list.

---
 drivers/iio/industrialio-core.c | 2 ++
 include/linux/iio/types.h       | 2 ++
 2 files changed, 4 insertions(+)
drivers/iio/industrialio-core.c +2 -0
index f95c697..b754f50 100644
@@ -66,6 +66,7 @@ static const char * const iio_chan_type_name_spec[] = {
 	[IIO_ALTVOLTAGE] = "altvoltage",
 	[IIO_CCT] = "cct",
 	[IIO_PRESSURE] = "pressure",
+	[IIO_QUAT_ROT] = "quat_rot",
 };
 
 static const char * const iio_modifier_names[] = {
@@ -80,6 +81,7 @@ static const char * const iio_modifier_names[] = {
 	[IIO_MOD_LIGHT_RED] = "red",
 	[IIO_MOD_LIGHT_GREEN] = "green",
 	[IIO_MOD_LIGHT_BLUE] = "blue",
+	[IIO_MOD_W] = "w",
 };
 
 /* relies on pairs of these shared then separate */
include/linux/iio/types.h +2 -0
index 88bf0f0..4565f5c 100644
@@ -29,6 +29,7 @@ enum iio_chan_type {
 	IIO_ALTVOLTAGE,
 	IIO_CCT,
 	IIO_PRESSURE,
+	IIO_QUAT_ROT,
 };
 
 enum iio_modifier {
@@ -52,6 +53,7 @@ enum iio_modifier {
 	IIO_MOD_LIGHT_RED,
 	IIO_MOD_LIGHT_GREEN,
 	IIO_MOD_LIGHT_BLUE,
+	IIO_MOD_W,
 };
 
 #define IIO_VAL_INT 1
Signature · 1 line
1.8.3.2
maintainer
#10 lore raw

Re: [PATCH v3 7/8] iio: Add quaternion channel

Quoted 6 lines · Srinivas Pandruvada

A quaternion channel type is added. Here channel information is composed of four components: a vector with x, y, z coordinates and a w rotation. Reusing x, y, z channel modifiers, but added "w" component in the modifier list.

In brief I am against this for the same reason I didn't like this before. A quaternion has no meaning if it isn't all present. Hence we need to ensure that it is always presented to userspace with all four components present.

I'll hopefully have a few mins at the weekend to to bash out some example code for how I would suggest we handle this.

If you could repost the patches before this one with everything that should be in them then hopefully we can take those whilst still 'discussing' how to handle the last 2!

Jonathan

Quoted 46 lines
---
 drivers/iio/industrialio-core.c | 2 ++
 include/linux/iio/types.h       | 2 ++
 2 files changed, 4 insertions(+)
drivers/iio/industrialio-core.c +2 -0
index f95c697..b754f50 100644
@@ -66,6 +66,7 @@ static const char * const iio_chan_type_name_spec[] = {
 	[IIO_ALTVOLTAGE] = "altvoltage",
 	[IIO_CCT] = "cct",
 	[IIO_PRESSURE] = "pressure",
+	[IIO_QUAT_ROT] = "quat_rot",
 };
 
 static const char * const iio_modifier_names[] = {
@@ -80,6 +81,7 @@ static const char * const iio_modifier_names[] = {
 	[IIO_MOD_LIGHT_RED] = "red",
 	[IIO_MOD_LIGHT_GREEN] = "green",
 	[IIO_MOD_LIGHT_BLUE] = "blue",
+	[IIO_MOD_W] = "w",
 };
 
 /* relies on pairs of these shared then separate */
include/linux/iio/types.h +2 -0
index 88bf0f0..4565f5c 100644
@@ -29,6 +29,7 @@ enum iio_chan_type {
 	IIO_ALTVOLTAGE,
 	IIO_CCT,
 	IIO_PRESSURE,
+	IIO_QUAT_ROT,
 };
 
 enum iio_modifier {
@@ -52,6 +53,7 @@ enum iio_modifier {
 	IIO_MOD_LIGHT_RED,
 	IIO_MOD_LIGHT_GREEN,
 	IIO_MOD_LIGHT_BLUE,
+	IIO_MOD_W,
 };
 
 #define IIO_VAL_INT 1
author maintainer
#11 lore raw

Re: [PATCH v3 7/8] iio: Add quaternion channel

Quoted 12 lines · Jonathan Cameron
Quoted 6 lines · Srinivas Pandruvada

A quaternion channel type is added. Here channel information is composed of four components: a vector with x, y, z coordinates and a w rotation. Reusing x, y, z channel modifiers, but added "w" component in the modifier list.

In brief I am against this for the same reason I didn't like this before. A quaternion has no meaning if it isn't all present. Hence we need to ensure that it is always presented to userspace with all four components present.

Quoted 6 lines

I'll hopefully have a few mins at the weekend to to bash out some example code for how I would suggest we handle this.

If you could repost the patches before this one with everything that should be in them then hopefully we can take those whilst still 'discussing' how to handle the last 2!

Sorry about the issues with previous patches. I was trying to order new driver at the end and missed dependencies. I have applied all patches which I am sending after this email safely apply to fixes-togreg branch. For the last two, I will wait for your suggestion.

Thanks,
Srinivas

Quoted 53 lines

Jonathan

Quoted 39 lines
---
  drivers/iio/industrialio-core.c | 2 ++
  include/linux/iio/types.h       | 2 ++
  2 files changed, 4 insertions(+)
drivers/iio/industrialio-core.c +2 -0
index f95c697..b754f50 100644
@@ -66,6 +66,7 @@ static const char * const iio_chan_type_name_spec[] = {
  	[IIO_ALTVOLTAGE] = "altvoltage",
  	[IIO_CCT] = "cct",
  	[IIO_PRESSURE] = "pressure",
+	[IIO_QUAT_ROT] = "quat_rot",
  };
 
  static const char * const iio_modifier_names[] = {
@@ -80,6 +81,7 @@ static const char * const iio_modifier_names[] = {
  	[IIO_MOD_LIGHT_RED] = "red",
  	[IIO_MOD_LIGHT_GREEN] = "green",
  	[IIO_MOD_LIGHT_BLUE] = "blue",
+	[IIO_MOD_W] = "w",
  };
 
  /* relies on pairs of these shared then separate */
include/linux/iio/types.h +1 -0
index 88bf0f0..4565f5c 100644
@@ -29,6 +29,7 @@ enum iio_chan_type {
  	IIO_ALTVOLTAGE,
  	IIO_CCT,
  	IIO_PRESSURE,
+	IIO_QUAT_ROT,
  };
 
  enum iio_modifier {

include/linux/iio/types.h enum iio_modifier { · line 59

Quoted 7 lines
include/linux/iio/types.h +1 -0
@@ -52,6 +53,7 @@ enum iio_modifier {
  	IIO_MOD_LIGHT_RED,
  	IIO_MOD_LIGHT_GREEN,
  	IIO_MOD_LIGHT_BLUE,
+	IIO_MOD_W,
  };
 
  #define IIO_VAL_INT 1

--
To unsubscribe from this list: send the line "unsubscribe linux-iio" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#12 lore raw

Re: [PATCH v3 7/8] iio: Add quaternion channel

Quoted 21 lines · Srinivas Pandruvada
Quoted 7 lines · Jonathan Cameron
Quoted 6 lines · Srinivas Pandruvada

A quaternion channel type is added. Here channel information is composed of four components: a vector with x, y, z coordinates and a w rotation. Reusing x, y, z channel modifiers, but added "w" component in the modifier list.

Signed-off-by Srinivas Pandruvada

<[email protected]>

Quoted 1 line

In brief I am against this for the same reason I didn't like this

before.

Quoted 1 line

A quaternion has no meaning if it isn't all present. Hence we need

to

Quoted 1 line

ensure that it is always presented to userspace with all four

components

Quoted 3 lines

present.

I'll hopefully have a few mins at the weekend to to bash out some

example

Quoted 2 lines

code for how I would suggest we handle this.

Quoted 7 lines
Quoted 1 line

If you could repost the patches before this one with everything that

should

Quoted 2 lines

be in them then hopefully we can take those whilst still 'discussing' how to handle the last 2!

Sorry about the issues with previous patches. I was trying to order new

driver at the end and missed dependencies.

Not to worry. We all make that mistake occasionally!

Quoted 67 lines

I have applied all patches which I am sending after this email safely apply to fixes-togreg branch.
For the last two, I will wait for your suggestion.

Thanks,
Srinivas

Quoted 8 lines

Jonathan

Review

Quoted 6 lines
---
  drivers/iio/industrialio-core.c | 2 ++
  include/linux/iio/types.h       | 2 ++
  2 files changed, 4 insertions(+)
(quoted diff) +0 -0

b/drivers/iio/industrialio-core.c

Quoted 4 lines

drivers/iio/industrialio-core.c static const char * const

Quoted 4 lines

index f95c697..b754f50 100644

drivers/iio/industrialio-core.c +0 -0
@@ -66,6 +66,7 @@ static const char * const

iio_chan_type_name_spec[] = {

Quoted 34 lines
Quoted 34 lines
drivers/iio/industrialio-core.c +2 -0
  	[IIO_ALTVOLTAGE] = "altvoltage",
  	[IIO_CCT] = "cct",
  	[IIO_PRESSURE] = "pressure",
+	[IIO_QUAT_ROT] = "quat_rot",
  };
 
  static const char * const iio_modifier_names[] = {
@@ -80,6 +81,7 @@ static const char * const iio_modifier_names[] = {
  	[IIO_MOD_LIGHT_RED] = "red",
  	[IIO_MOD_LIGHT_GREEN] = "green",
  	[IIO_MOD_LIGHT_BLUE] = "blue",
+	[IIO_MOD_W] = "w",
  };
 
  /* relies on pairs of these shared then separate */
include/linux/iio/types.h +2 -0
index 88bf0f0..4565f5c 100644
@@ -29,6 +29,7 @@ enum iio_chan_type {
  	IIO_ALTVOLTAGE,
  	IIO_CCT,
  	IIO_PRESSURE,
+	IIO_QUAT_ROT,
  };
 
  enum iio_modifier {
@@ -52,6 +53,7 @@ enum iio_modifier {
  	IIO_MOD_LIGHT_RED,
  	IIO_MOD_LIGHT_GREEN,
  	IIO_MOD_LIGHT_BLUE,
+	IIO_MOD_W,
  };
 
Quoted 4 lines

include/linux/iio/types.h enum iio_modifier { · line 59

Quoted 2 lines
include/linux/iio/types.h +0 -0
  #define IIO_VAL_INT 1

--
To unsubscribe from this list: send the line "unsubscribe linux-iio"

in

Quoted 3 lines

the body of a message to [email protected]
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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 1 line
Sent from my Android phone with K-9 Mail. Please excuse my brevity.
author maintainer
#13 lore raw

Re: [PATCH v3 7/8] iio: Add quaternion channel

Hi Jonathan,

Quoted 19 lines · Jonathan Cameron
Quoted 17 lines · Srinivas Pandruvada
Quoted 7 lines · Jonathan Cameron
Quoted 6 lines · Srinivas Pandruvada

A quaternion channel type is added. Here channel information is composed of four components: a vector with x, y, z coordinates and a w rotation. Reusing x, y, z channel modifiers, but added "w" component in the modifier list.

Signed-off-by Srinivas Pandruvada

<[email protected]>

Quoted 1 line

In brief I am against this for the same reason I didn't like this

before.

Quoted 1 line

A quaternion has no meaning if it isn't all present. Hence we need

to

Quoted 1 line

ensure that it is always presented to userspace with all four

components

Quoted 2 lines

present.

Quoted 8 lines
Quoted 8 lines
Quoted 1 line

I'll hopefully have a few mins at the weekend to to bash out some

example

Quoted 3 lines

code for how I would suggest we handle this.

If you could repost the patches before this one with everything that

should

Quoted 2 lines

be in them then hopefully we can take those whilst still 'discussing' how to handle the last 2!

If you get chance, please send me some info on how you want to handle this.

Thanks,
Srinivas

Quoted 69 lines
Quoted 3 lines

Sorry about the issues with previous patches. I was trying to order new

driver at the end and missed dependencies.

Not to worry. We all make that mistake occasionally!

Quoted 65 lines

I have applied all patches which I am sending after this email safely apply to fixes-togreg branch.
For the last two, I will wait for your suggestion.

Thanks,
Srinivas

Quoted 7 lines

Jonathan

Review

Quoted 6 lines
---
   drivers/iio/industrialio-core.c | 2 ++
   include/linux/iio/types.h       | 2 ++
   2 files changed, 4 insertions(+)
(quoted diff) +0 -0

b/drivers/iio/industrialio-core.c

Quoted 4 lines

drivers/iio/industrialio-core.c static const char * const

Quoted 4 lines

index f95c697..b754f50 100644

drivers/iio/industrialio-core.c +0 -0
@@ -66,6 +66,7 @@ static const char * const

iio_chan_type_name_spec[] = {

Quoted 34 lines
Quoted 34 lines
drivers/iio/industrialio-core.c +2 -0
   	[IIO_ALTVOLTAGE] = "altvoltage",
   	[IIO_CCT] = "cct",
   	[IIO_PRESSURE] = "pressure",
+	[IIO_QUAT_ROT] = "quat_rot",
   };
 
   static const char * const iio_modifier_names[] = {
@@ -80,6 +81,7 @@ static const char * const iio_modifier_names[] = {
   	[IIO_MOD_LIGHT_RED] = "red",
   	[IIO_MOD_LIGHT_GREEN] = "green",
   	[IIO_MOD_LIGHT_BLUE] = "blue",
+	[IIO_MOD_W] = "w",
   };
 
   /* relies on pairs of these shared then separate */
include/linux/iio/types.h +2 -0
index 88bf0f0..4565f5c 100644
@@ -29,6 +29,7 @@ enum iio_chan_type {
   	IIO_ALTVOLTAGE,
   	IIO_CCT,
   	IIO_PRESSURE,
+	IIO_QUAT_ROT,
   };
 
   enum iio_modifier {
@@ -52,6 +53,7 @@ enum iio_modifier {
   	IIO_MOD_LIGHT_RED,
   	IIO_MOD_LIGHT_GREEN,
   	IIO_MOD_LIGHT_BLUE,
+	IIO_MOD_W,
   };
 
Quoted 4 lines

include/linux/iio/types.h enum iio_modifier { · line 59

Quoted 2 lines
include/linux/iio/types.h +0 -0
   #define IIO_VAL_INT 1

--
To unsubscribe from this list: send the line "unsubscribe linux-iio"

in

Quoted 3 lines

the body of a message to [email protected]
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 [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

maintainer
#14 lore raw

Re: [PATCH v3 7/8] iio: Add quaternion channel

Quoted 23 lines · Srinivas Pandruvada

Hi Jonathan,

Quoted 20 lines · Jonathan Cameron
Quoted 18 lines · Srinivas Pandruvada
Quoted 7 lines · Jonathan Cameron
Quoted 6 lines · Srinivas Pandruvada

A quaternion channel type is added. Here channel information is composed of four components: a vector with x, y, z coordinates and a w rotation. Reusing x, y, z channel modifiers, but added "w" component in the modifier list.

Signed-off-by Srinivas Pandruvada

<[email protected]>

Quoted 1 line

In brief I am against this for the same reason I didn't like this

before.

Quoted 1 line

A quaternion has no meaning if it isn't all present. Hence we need

to

Quoted 1 line

ensure that it is always presented to userspace with all four

components

Quoted 3 lines

present.

I'll hopefully have a few mins at the weekend to to bash out some

Quoted 9 lines
Quoted 7 lines
Quoted 7 lines

example

Quoted 3 lines

code for how I would suggest we handle this.

If you could repost the patches before this one with everything that

should

Quoted 2 lines

be in them then hopefully we can take those whilst still 'discussing' how to handle the last 2!

If you get chance, please send me some info on how you want to handle this.

Sorry for the delay on this - I might get time tomorrow to go into this in more detail but maybe not so I'll give a very brief outline here.

Constraints:

1) Quaternions may have 4 elements but they all interact in a way that makes them effectively a 'single value'. Thus they need to be handled as one.

Solutions

1) Introduce a IIO_VAL_* - probably IIO_VAL_QUATERNION
2) Introduced a replacement for read_raw that has the following form int (*read)(struct iio_dev *indio_dev,
struct iio_chan_spec const *chan, int *vals,
long mask);
- for previous cases vals[0] <- val and vals[1] <- val2
- for quaternion vals[0] <- i component, vals[1] <- j component etc

3) Add a case to iio_read_channel_info in industrialio-core.c to handle the new type and pretty print it appropriately - possibly expand iio_format_value to handle the new parameters.

4) Buffered support is only trickier in that the buffer element needs describing and there is a lot of possible flexibility in there...

current format is :

[be|le]:[s|u]bits/storagebits[>>shift].

Reasonable to assume that whole thing is either be or le and that elements are byte aligned plus all are signed (but need to state this)

Hence perhaps either

[be|le]:[s|u]bitsI/storagebitsI,bitsJ/storagebitsJ,bitsK/storagebitsK,bitsA/storagebitsA

or we assume that the elements are effectively independent but have the same placement and indicated perhaps as

be:s12/16x4 or similar?

Either way this would need some extensions to the struct iio_chan_spec substructure scan_type.

Quoted 69 lines

Thanks,
Srinivas

Quoted 65 lines
Quoted 3 lines

Sorry about the issues with previous patches. I was trying to order new

driver at the end and missed dependencies.

Not to worry. We all make that mistake occasionally!

Quoted 61 lines

I have applied all patches which I am sending after this email safely apply to fixes-togreg branch.
For the last two, I will wait for your suggestion.

Thanks,
Srinivas

Quoted 7 lines

Jonathan

Review

Quoted 6 lines
---
   drivers/iio/industrialio-core.c | 2 ++
   include/linux/iio/types.h       | 2 ++
   2 files changed, 4 insertions(+)
(quoted diff) +0 -0

b/drivers/iio/industrialio-core.c

Quoted 4 lines

drivers/iio/industrialio-core.c static const char * const

Quoted 4 lines

index f95c697..b754f50 100644

drivers/iio/industrialio-core.c +0 -0
@@ -66,6 +66,7 @@ static const char * const

iio_chan_type_name_spec[] = {

Quoted 24 lines
Quoted 24 lines
drivers/iio/industrialio-core.c +2 -0
       [IIO_ALTVOLTAGE] = "altvoltage",
       [IIO_CCT] = "cct",
       [IIO_PRESSURE] = "pressure",
+    [IIO_QUAT_ROT] = "quat_rot",
   };
      static const char * const iio_modifier_names[] = {
@@ -80,6 +81,7 @@ static const char * const iio_modifier_names[] = {
       [IIO_MOD_LIGHT_RED] = "red",
       [IIO_MOD_LIGHT_GREEN] = "green",
       [IIO_MOD_LIGHT_BLUE] = "blue",
+    [IIO_MOD_W] = "w",
   };
      /* relies on pairs of these shared then separate */
include/linux/iio/types.h +1 -0
index 88bf0f0..4565f5c 100644
@@ -29,6 +29,7 @@ enum iio_chan_type {
       IIO_ALTVOLTAGE,
       IIO_CCT,
       IIO_PRESSURE,
+    IIO_QUAT_ROT,
   };
      enum iio_modifier {
Quoted 10 lines
Quoted 8 lines
include/linux/iio/types.h +1 -0
@@ -52,6 +53,7 @@ enum iio_modifier {
       IIO_MOD_LIGHT_RED,
       IIO_MOD_LIGHT_GREEN,
       IIO_MOD_LIGHT_BLUE,
+    IIO_MOD_W,
   };
      #define IIO_VAL_INT 1
 
Signature · 1 line
To unsubscribe from this list: send the line "unsubscribe linux-iio"

in

Quoted 3 lines

the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Signature · 3 lines
To unsubscribe from this list: send the line "unsubscribe linux-iio" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
author maintainer
#15 lore raw

PATCH v3 8/8 iio: hid-sensors: Added device rotation support

In reply to 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 of quaternion rotation components.

---
 drivers/iio/orientation/Kconfig               |  11 +
 drivers/iio/orientation/Makefile              |   1 +
 drivers/iio/orientation/hid-sensor-rotation.c | 406 ++++++++++++++++++++++++++
 include/linux/hid-sensor-ids.h                |   1 +
 4 files changed, 419 insertions(+)
 create mode 100644 drivers/iio/orientation/hid-sensor-rotation.c
drivers/iio/orientation/Kconfig +11 -0
index 58c62c8..da8bd8a 100644
@@ -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
drivers/iio/orientation/Makefile +1 -0
index 2c97572..4734dab 100644
@@ -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
drivers/iio/orientation/hid-sensor-rotation.c new file +406 -0

406 lines not on this page · raw message

include/linux/hid-sensor-ids.h +1 -0
index a3f863d..a264ec7 100644
@@ -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
Signature · 1 line
1.8.3.2
maintainer Applied
#16 lore raw
In reply to Srinivas Pandruvada
Quoted 7 lines · 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.

Applied to the fixes-togreg branch of iio.git

Will be a little while before this hits mainline because of the unusual merge window timings.

Thanks,

Jonathan

Quoted 176 lines
---
 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                      | 3 +++
 7 files changed, 20 insertions(+), 14 deletions(-)
drivers/iio/accel/hid-sensor-accel-3d.c +3 -2
index 46d22f3..7fbe136 100644
@@ -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);
 
drivers/iio/common/hid-sensors/hid-sensor-trigger.c +4 -5
index dbc9141..363f8d2 100644
@@ -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->trigger);
+	iio_trigger_free(attrb->trigger);
 }
 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->trigger = trig;
 
 	return ret;
 
drivers/iio/common/hid-sensors/hid-sensor-trigger.h +1 -1
index 9a87314..ca02f78 100644
@@ -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
drivers/iio/gyro/hid-sensor-gyro-3d.c +3 -2
index c688d97..74bbed7 100644
@@ -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);
 
drivers/iio/light/hid-sensor-als.c +3 -2
index e59d00c..c104bda 100644
@@ -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_attributes);
 	iio_triggered_buffer_cleanup(indio_dev);
 	kfree(indio_dev->channels);
 
drivers/iio/magnetometer/hid-sensor-magn-3d.c +3 -2
index a98460b..ff7b9da 100644
@@ -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);
 
include/linux/hid-sensor-hub.h +3 -0
index a265af2..206a2af 100644
@@ -21,6 +21,8 @@
 
 #include <linux/hid.h>
 #include <linux/hid-sensor-ids.h>
+#include <linux/iio/iio.h>
+#include <linux/iio/trigger.h>
 
 /**
  * struct hid_sensor_hub_attribute_info - Attribute info
@@ -184,6 +186,7 @@ struct hid_sensor_common {
 	struct platform_device *pdev;
 	unsigned usage_id;
 	bool data_ready;
+	struct iio_trigger *trigger;
 	struct hid_sensor_hub_attribute_info poll;
 	struct hid_sensor_hub_attribute_info report_state;
 	struct hid_sensor_hub_attribute_info power_state;