linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 1/3] iio: hid-sensor-rotation: Add relative orientation sensor hid support
@ 2017-05-07 10:24 Song Hongyan
  2017-05-07 10:24 ` [PATCH v2 2/3] iio: hid-sensor-rotation: Add geomagnetic " Song Hongyan
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Song Hongyan @ 2017-05-07 10:24 UTC (permalink / raw)
  To: linux-input, linux-iio; +Cc: jikos, jic23, srinivas.pandruvada, Song Hongyan

Relative orientation(AG) sensor is a 6dof orientation sensor,
it depends on acceleration and gyroscope sensor data. It gives
a quaternion describing the orientation of the device relative
to an initial orientation. It is a standard HID sensor.

More information can be found in:
http://www.usb.org/developers/hidpage/HUTRR59_-_Usages_for_Wearables.pdf

Relative orientation(AG) sensor and dev rotation sensor have same
channels and share channel usage id. So the most of the code for
relative orientation sensor can be reused.

Signed-off-by: Song Hongyan <hongyan.song@intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
Reviewed-by: Xu Even <even.xu@intel.com>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
---
changes: change name definition select statement from "if ...else" to "switch ...case"
fix typo of "relative" in comment.

 drivers/iio/orientation/hid-sensor-rotation.c | 28 +++++++++++++++++++--------
 include/linux/hid-sensor-ids.h                |  1 +
 2 files changed, 21 insertions(+), 8 deletions(-)

diff --git a/drivers/iio/orientation/hid-sensor-rotation.c b/drivers/iio/orientation/hid-sensor-rotation.c
index a97e802c..4d953c2 100644
--- a/drivers/iio/orientation/hid-sensor-rotation.c
+++ b/drivers/iio/orientation/hid-sensor-rotation.c
@@ -218,7 +218,7 @@ static int dev_rot_parse_report(struct platform_device *pdev,
 static int hid_dev_rot_probe(struct platform_device *pdev)
 {
 	int ret;
-	static char *name = "dev_rotation";
+	static char *name;
 	struct iio_dev *indio_dev;
 	struct dev_rot_state *rot_state;
 	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
@@ -234,8 +234,18 @@ static int hid_dev_rot_probe(struct platform_device *pdev)
 	rot_state->common_attributes.hsdev = hsdev;
 	rot_state->common_attributes.pdev = pdev;
 
-	ret = hid_sensor_parse_common_attributes(hsdev,
-				HID_USAGE_SENSOR_DEVICE_ORIENTATION,
+	switch (hsdev->usage) {
+	case HID_USAGE_SENSOR_DEVICE_ORIENTATION:
+		name = "dev_rotation";
+		break;
+	case HID_USAGE_SENSOR_RELATIVE_ORIENTATION:
+		name = "relative_orientation";
+		break;
+	default:
+		return -EINVAL;
+	}
+
+	ret = hid_sensor_parse_common_attributes(hsdev, hsdev->usage,
 				&rot_state->common_attributes);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup common attributes\n");
@@ -252,8 +262,7 @@ static int hid_dev_rot_probe(struct platform_device *pdev)
 
 	ret = dev_rot_parse_report(pdev, hsdev,
 				   (struct iio_chan_spec *)indio_dev->channels,
-				   HID_USAGE_SENSOR_DEVICE_ORIENTATION,
-				   rot_state);
+					hsdev->usage, rot_state);
 	if (ret) {
 		dev_err(&pdev->dev, "failed to setup attributes\n");
 		return ret;
@@ -288,8 +297,7 @@ static int hid_dev_rot_probe(struct platform_device *pdev)
 	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,
+	ret = sensor_hub_register_callback(hsdev, hsdev->usage,
 					&rot_state->callbacks);
 	if (ret) {
 		dev_err(&pdev->dev, "callback reg failed\n");
@@ -314,7 +322,7 @@ static int hid_dev_rot_remove(struct platform_device *pdev)
 	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);
+	sensor_hub_remove_callback(hsdev, hsdev->usage);
 	iio_device_unregister(indio_dev);
 	hid_sensor_remove_trigger(&rot_state->common_attributes);
 	iio_triggered_buffer_cleanup(indio_dev);
@@ -327,6 +335,10 @@ static int hid_dev_rot_remove(struct platform_device *pdev)
 		/* Format: HID-SENSOR-usage_id_in_hex_lowercase */
 		.name = "HID-SENSOR-20008a",
 	},
+	{
+		/* Relative orientation(AG) sensor */
+		.name = "HID-SENSOR-20008e",
+	},
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(platform, hid_dev_rot_ids);
diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h
index 30c7dc4..b61b985 100644
--- a/include/linux/hid-sensor-ids.h
+++ b/include/linux/hid-sensor-ids.h
@@ -82,6 +82,7 @@
 #define HID_USAGE_SENSOR_ORIENT_TILT_Z				0x200481
 
 #define HID_USAGE_SENSOR_DEVICE_ORIENTATION			0x20008A
+#define HID_USAGE_SENSOR_RELATIVE_ORIENTATION			0x20008E
 #define HID_USAGE_SENSOR_ORIENT_ROTATION_MATRIX			0x200482
 #define HID_USAGE_SENSOR_ORIENT_QUATERNION			0x200483
 #define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX			0x200484
-- 
1.9.1


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

* [PATCH v2 2/3] iio: hid-sensor-rotation: Add geomagnetic orientation sensor hid support.
  2017-05-07 10:24 [PATCH v2 1/3] iio: hid-sensor-rotation: Add relative orientation sensor hid support Song Hongyan
@ 2017-05-07 10:24 ` Song Hongyan
  2017-05-07 11:12   ` Jonathan Cameron
       [not found] ` <1494152666-25632-1-git-send-email-hongyan.song-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
  2017-05-07 11:11 ` [PATCH v2 1/3] iio: hid-sensor-rotation: Add relative orientation sensor hid support Jonathan Cameron
  2 siblings, 1 reply; 6+ messages in thread
From: Song Hongyan @ 2017-05-07 10:24 UTC (permalink / raw)
  To: linux-input, linux-iio; +Cc: jikos, jic23, srinivas.pandruvada, Song Hongyan

Geomagnetic orientation(AM) sensor is one kind of orientation 6dof sensor.
It gives the device rotation in respect to the earth center and the
magnetic north. The sensor is implemented through use of an accelerometer
and magnetometer do not use gyroscope. It is a standard HID sensor.

More information can be found in:
http://www.usb.org/developers/hidpage/HUTRR59_-_Usages_for_Wearables.pdf

Geomagnetic orientation(AM) sensor and dev rotation sensor have same
channel and share channel usage id. So the most of the code for relative
orientation sensor can be reused.

Signed-off-by: Song Hongyan <hongyan.song@intel.com>
---
 drivers/iio/orientation/hid-sensor-rotation.c | 7 +++++++
 include/linux/hid-sensor-ids.h                | 1 +
 2 files changed, 8 insertions(+)

diff --git a/drivers/iio/orientation/hid-sensor-rotation.c b/drivers/iio/orientation/hid-sensor-rotation.c
index 4d953c2..60d3517 100644
--- a/drivers/iio/orientation/hid-sensor-rotation.c
+++ b/drivers/iio/orientation/hid-sensor-rotation.c
@@ -241,6 +241,9 @@ static int hid_dev_rot_probe(struct platform_device *pdev)
 	case HID_USAGE_SENSOR_RELATIVE_ORIENTATION:
 		name = "relative_orientation";
 		break;
+	case HID_USAGE_SENSOR_GEOMAGNETIC_ORIENTATION:
+		name = "geomagnetic_orientation";
+		break;
 	default:
 		return -EINVAL;
 	}
@@ -339,6 +342,10 @@ static int hid_dev_rot_remove(struct platform_device *pdev)
 		/* Relative orientation(AG) sensor */
 		.name = "HID-SENSOR-20008e",
 	},
+	{
+		/* Geomagnetic orientation(AM) sensor */
+		.name = "HID-SENSOR-2000c1",
+	},
 	{ /* sentinel */ }
 };
 MODULE_DEVICE_TABLE(platform, hid_dev_rot_ids);
diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h
index b61b985..4fc47e5 100644
--- a/include/linux/hid-sensor-ids.h
+++ b/include/linux/hid-sensor-ids.h
@@ -83,6 +83,7 @@
 
 #define HID_USAGE_SENSOR_DEVICE_ORIENTATION			0x20008A
 #define HID_USAGE_SENSOR_RELATIVE_ORIENTATION			0x20008E
+#define HID_USAGE_SENSOR_GEOMAGNETIC_ORIENTATION		0x2000C1
 #define HID_USAGE_SENSOR_ORIENT_ROTATION_MATRIX			0x200482
 #define HID_USAGE_SENSOR_ORIENT_QUATERNION			0x200483
 #define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX			0x200484
-- 
1.9.1


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

* [PATCH v2 3/3] iio: hid-sensor-rotation: Add "scale" and "offset" properties parse support
       [not found] ` <1494152666-25632-1-git-send-email-hongyan.song-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
@ 2017-05-07 10:24   ` Song Hongyan
       [not found]     ` <1494152666-25632-3-git-send-email-hongyan.song-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Song Hongyan @ 2017-05-07 10:24 UTC (permalink / raw)
  To: linux-input-u79uwXL29TY76Z2rM5mHXA,
	linux-iio-u79uwXL29TY76Z2rM5mHXA
  Cc: jikos-DgEjT+Ai2ygdnm+yROfE0A, jic23-DgEjT+Ai2ygdnm+yROfE0A,
	srinivas.pandruvada-ral2JQCrhuEAvxtiuMwx3w, Song Hongyan

Add orientation sensor "scale" and "offset" parse support.
These two properties are needed for exponent data conversion.

Signed-off-by: Song Hongyan <hongyan.song-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Reviewed-by: Andy Shevchenko <andriy.shevchenko-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Reviewed-by: Xu Even <even.xu-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Acked-by: Srinivas Pandruvada <srinivas.pandruvada-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
---
 .../iio/common/hid-sensors/hid-sensor-attributes.c   |  6 ++++++
 drivers/iio/orientation/hid-sensor-rotation.c        | 20 ++++++++++++++++++++
 2 files changed, 26 insertions(+)

diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
index 01e02b9..420f28f 100644
--- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
+++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
@@ -62,6 +62,12 @@
 	{HID_USAGE_SENSOR_TIME_TIMESTAMP, 0, 1000000000, 0},
 	{HID_USAGE_SENSOR_TIME_TIMESTAMP, HID_USAGE_SENSOR_UNITS_MILLISECOND,
 		1000000, 0},
+
+	{HID_USAGE_SENSOR_DEVICE_ORIENTATION, 0, 1, 0},
+
+	{HID_USAGE_SENSOR_RELATIVE_ORIENTATION, 0, 1, 0},
+
+	{HID_USAGE_SENSOR_GEOMAGNETIC_ORIENTATION, 0, 1, 0},
 };
 
 static int pow_10(unsigned power)
diff --git a/drivers/iio/orientation/hid-sensor-rotation.c b/drivers/iio/orientation/hid-sensor-rotation.c
index 60d3517..e9fa86c 100644
--- a/drivers/iio/orientation/hid-sensor-rotation.c
+++ b/drivers/iio/orientation/hid-sensor-rotation.c
@@ -31,6 +31,10 @@ struct dev_rot_state {
 	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info quaternion;
 	u32 sampled_vals[4];
+	int scale_pre_decml;
+	int scale_post_decml;
+	int scale_precision;
+	int value_offset;
 };
 
 /* Channel definitions */
@@ -41,6 +45,8 @@ struct dev_rot_state {
 		.channel2 = IIO_MOD_QUATERNION,
 		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
 		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) |
+					BIT(IIO_CHAN_INFO_OFFSET) |
+					BIT(IIO_CHAN_INFO_SCALE) |
 					BIT(IIO_CHAN_INFO_HYSTERESIS)
 	}
 };
@@ -80,6 +86,15 @@ static int dev_rot_read_raw(struct iio_dev *indio_dev,
 		} else
 			ret_type = -EINVAL;
 		break;
+	case IIO_CHAN_INFO_SCALE:
+		vals[0] = rot_state->scale_pre_decml;
+		vals[1] = rot_state->scale_post_decml;
+		return rot_state->scale_precision;
+
+	case IIO_CHAN_INFO_OFFSET:
+		*vals = rot_state->value_offset;
+		return IIO_VAL_INT;
+
 	case IIO_CHAN_INFO_SAMP_FREQ:
 		ret_type = hid_sensor_read_samp_freq_value(
 			&rot_state->common_attributes, &vals[0], &vals[1]);
@@ -199,6 +214,11 @@ static int dev_rot_parse_report(struct platform_device *pdev,
 	dev_dbg(&pdev->dev, "dev_rot: attrib size %d\n",
 				st->quaternion.size);
 
+	st->scale_precision = hid_sensor_format_scale(
+				hsdev->usage,
+				&st->quaternion,
+				&st->scale_pre_decml, &st->scale_post_decml);
+
 	/* Set Sensitivity field ids, when there is no individual modifier */
 	if (st->common_attributes.sensitivity.index < 0) {
 		sensor_hub_input_get_attribute_info(hsdev,
-- 
1.9.1

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

* Re: [PATCH v2 1/3] iio: hid-sensor-rotation: Add relative orientation sensor hid support
  2017-05-07 10:24 [PATCH v2 1/3] iio: hid-sensor-rotation: Add relative orientation sensor hid support Song Hongyan
  2017-05-07 10:24 ` [PATCH v2 2/3] iio: hid-sensor-rotation: Add geomagnetic " Song Hongyan
       [not found] ` <1494152666-25632-1-git-send-email-hongyan.song-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
@ 2017-05-07 11:11 ` Jonathan Cameron
  2 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2017-05-07 11:11 UTC (permalink / raw)
  To: Song Hongyan, linux-input, linux-iio; +Cc: jikos, srinivas.pandruvada

On 07/05/17 11:24, Song Hongyan wrote:
> Relative orientation(AG) sensor is a 6dof orientation sensor,
> it depends on acceleration and gyroscope sensor data. It gives
> a quaternion describing the orientation of the device relative
> to an initial orientation. It is a standard HID sensor.
> 
> More information can be found in:
> http://www.usb.org/developers/hidpage/HUTRR59_-_Usages_for_Wearables.pdf
> 
> Relative orientation(AG) sensor and dev rotation sensor have same
> channels and share channel usage id. So the most of the code for
> relative orientation sensor can be reused.
> 
> Signed-off-by: Song Hongyan <hongyan.song@intel.com>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko@intel.com>
> Reviewed-by: Xu Even <even.xu@intel.com>
> Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com>
Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan
> ---
> changes: change name definition select statement from "if ...else" to "switch ...case"
> fix typo of "relative" in comment.
> 
>  drivers/iio/orientation/hid-sensor-rotation.c | 28 +++++++++++++++++++--------
>  include/linux/hid-sensor-ids.h                |  1 +
>  2 files changed, 21 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/iio/orientation/hid-sensor-rotation.c b/drivers/iio/orientation/hid-sensor-rotation.c
> index a97e802c..4d953c2 100644
> --- a/drivers/iio/orientation/hid-sensor-rotation.c
> +++ b/drivers/iio/orientation/hid-sensor-rotation.c
> @@ -218,7 +218,7 @@ static int dev_rot_parse_report(struct platform_device *pdev,
>  static int hid_dev_rot_probe(struct platform_device *pdev)
>  {
>  	int ret;
> -	static char *name = "dev_rotation";
> +	static char *name;
>  	struct iio_dev *indio_dev;
>  	struct dev_rot_state *rot_state;
>  	struct hid_sensor_hub_device *hsdev = pdev->dev.platform_data;
> @@ -234,8 +234,18 @@ static int hid_dev_rot_probe(struct platform_device *pdev)
>  	rot_state->common_attributes.hsdev = hsdev;
>  	rot_state->common_attributes.pdev = pdev;
>  
> -	ret = hid_sensor_parse_common_attributes(hsdev,
> -				HID_USAGE_SENSOR_DEVICE_ORIENTATION,
> +	switch (hsdev->usage) {
> +	case HID_USAGE_SENSOR_DEVICE_ORIENTATION:
> +		name = "dev_rotation";
> +		break;
> +	case HID_USAGE_SENSOR_RELATIVE_ORIENTATION:
> +		name = "relative_orientation";
> +		break;
> +	default:
> +		return -EINVAL;
> +	}
> +
> +	ret = hid_sensor_parse_common_attributes(hsdev, hsdev->usage,
>  				&rot_state->common_attributes);
>  	if (ret) {
>  		dev_err(&pdev->dev, "failed to setup common attributes\n");
> @@ -252,8 +262,7 @@ static int hid_dev_rot_probe(struct platform_device *pdev)
>  
>  	ret = dev_rot_parse_report(pdev, hsdev,
>  				   (struct iio_chan_spec *)indio_dev->channels,
> -				   HID_USAGE_SENSOR_DEVICE_ORIENTATION,
> -				   rot_state);
> +					hsdev->usage, rot_state);
>  	if (ret) {
>  		dev_err(&pdev->dev, "failed to setup attributes\n");
>  		return ret;
> @@ -288,8 +297,7 @@ static int hid_dev_rot_probe(struct platform_device *pdev)
>  	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,
> +	ret = sensor_hub_register_callback(hsdev, hsdev->usage,
>  					&rot_state->callbacks);
>  	if (ret) {
>  		dev_err(&pdev->dev, "callback reg failed\n");
> @@ -314,7 +322,7 @@ static int hid_dev_rot_remove(struct platform_device *pdev)
>  	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);
> +	sensor_hub_remove_callback(hsdev, hsdev->usage);
>  	iio_device_unregister(indio_dev);
>  	hid_sensor_remove_trigger(&rot_state->common_attributes);
>  	iio_triggered_buffer_cleanup(indio_dev);
> @@ -327,6 +335,10 @@ static int hid_dev_rot_remove(struct platform_device *pdev)
>  		/* Format: HID-SENSOR-usage_id_in_hex_lowercase */
>  		.name = "HID-SENSOR-20008a",
>  	},
> +	{
> +		/* Relative orientation(AG) sensor */
> +		.name = "HID-SENSOR-20008e",
> +	},
>  	{ /* sentinel */ }
>  };
>  MODULE_DEVICE_TABLE(platform, hid_dev_rot_ids);
> diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h
> index 30c7dc4..b61b985 100644
> --- a/include/linux/hid-sensor-ids.h
> +++ b/include/linux/hid-sensor-ids.h
> @@ -82,6 +82,7 @@
>  #define HID_USAGE_SENSOR_ORIENT_TILT_Z				0x200481
>  
>  #define HID_USAGE_SENSOR_DEVICE_ORIENTATION			0x20008A
> +#define HID_USAGE_SENSOR_RELATIVE_ORIENTATION			0x20008E
>  #define HID_USAGE_SENSOR_ORIENT_ROTATION_MATRIX			0x200482
>  #define HID_USAGE_SENSOR_ORIENT_QUATERNION			0x200483
>  #define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX			0x200484
> 


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

* Re: [PATCH v2 2/3] iio: hid-sensor-rotation: Add geomagnetic orientation sensor hid support.
  2017-05-07 10:24 ` [PATCH v2 2/3] iio: hid-sensor-rotation: Add geomagnetic " Song Hongyan
@ 2017-05-07 11:12   ` Jonathan Cameron
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2017-05-07 11:12 UTC (permalink / raw)
  To: Song Hongyan, linux-input, linux-iio; +Cc: jikos, srinivas.pandruvada

On 07/05/17 11:24, Song Hongyan wrote:
> Geomagnetic orientation(AM) sensor is one kind of orientation 6dof sensor.
> It gives the device rotation in respect to the earth center and the
> magnetic north. The sensor is implemented through use of an accelerometer
> and magnetometer do not use gyroscope. It is a standard HID sensor.
> 
> More information can be found in:
> http://www.usb.org/developers/hidpage/HUTRR59_-_Usages_for_Wearables.pdf
> 
> Geomagnetic orientation(AM) sensor and dev rotation sensor have same
> channel and share channel usage id. So the most of the code for relative
> orientation sensor can be reused.
> 
> Signed-off-by: Song Hongyan <hongyan.song@intel.com>
Applied to the togreg branch of iio.git and pushed out as testing for
the autobuilders to play with it.

Thanks,

Jonathan
> ---
>  drivers/iio/orientation/hid-sensor-rotation.c | 7 +++++++
>  include/linux/hid-sensor-ids.h                | 1 +
>  2 files changed, 8 insertions(+)
> 
> diff --git a/drivers/iio/orientation/hid-sensor-rotation.c b/drivers/iio/orientation/hid-sensor-rotation.c
> index 4d953c2..60d3517 100644
> --- a/drivers/iio/orientation/hid-sensor-rotation.c
> +++ b/drivers/iio/orientation/hid-sensor-rotation.c
> @@ -241,6 +241,9 @@ static int hid_dev_rot_probe(struct platform_device *pdev)
>  	case HID_USAGE_SENSOR_RELATIVE_ORIENTATION:
>  		name = "relative_orientation";
>  		break;
> +	case HID_USAGE_SENSOR_GEOMAGNETIC_ORIENTATION:
> +		name = "geomagnetic_orientation";
> +		break;
>  	default:
>  		return -EINVAL;
>  	}
> @@ -339,6 +342,10 @@ static int hid_dev_rot_remove(struct platform_device *pdev)
>  		/* Relative orientation(AG) sensor */
>  		.name = "HID-SENSOR-20008e",
>  	},
> +	{
> +		/* Geomagnetic orientation(AM) sensor */
> +		.name = "HID-SENSOR-2000c1",
> +	},
>  	{ /* sentinel */ }
>  };
>  MODULE_DEVICE_TABLE(platform, hid_dev_rot_ids);
> diff --git a/include/linux/hid-sensor-ids.h b/include/linux/hid-sensor-ids.h
> index b61b985..4fc47e5 100644
> --- a/include/linux/hid-sensor-ids.h
> +++ b/include/linux/hid-sensor-ids.h
> @@ -83,6 +83,7 @@
>  
>  #define HID_USAGE_SENSOR_DEVICE_ORIENTATION			0x20008A
>  #define HID_USAGE_SENSOR_RELATIVE_ORIENTATION			0x20008E
> +#define HID_USAGE_SENSOR_GEOMAGNETIC_ORIENTATION		0x2000C1
>  #define HID_USAGE_SENSOR_ORIENT_ROTATION_MATRIX			0x200482
>  #define HID_USAGE_SENSOR_ORIENT_QUATERNION			0x200483
>  #define HID_USAGE_SENSOR_ORIENT_MAGN_FLUX			0x200484
> 


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

* Re: [PATCH v2 3/3] iio: hid-sensor-rotation: Add "scale" and "offset" properties parse support
       [not found]     ` <1494152666-25632-3-git-send-email-hongyan.song-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
@ 2017-05-07 11:13       ` Jonathan Cameron
  0 siblings, 0 replies; 6+ messages in thread
From: Jonathan Cameron @ 2017-05-07 11:13 UTC (permalink / raw)
  To: Song Hongyan, linux-input-u79uwXL29TY76Z2rM5mHXA,
	linux-iio-u79uwXL29TY76Z2rM5mHXA
  Cc: jikos-DgEjT+Ai2ygdnm+yROfE0A,
	srinivas.pandruvada-ral2JQCrhuEAvxtiuMwx3w

On 07/05/17 11:24, Song Hongyan wrote:
> Add orientation sensor "scale" and "offset" parse support.
> These two properties are needed for exponent data conversion.
> 
> Signed-off-by: Song Hongyan <hongyan.song-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> Reviewed-by: Andy Shevchenko <andriy.shevchenko-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> Reviewed-by: Xu Even <even.xu-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
> Acked-by: Srinivas Pandruvada <srinivas.pandruvada-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Applied but with some fuzz as a couple of other hid sensor additions
had crossed with this patch. Please check I didn't mess up the
merge!

Thanks,

Jonathan
> ---
>  .../iio/common/hid-sensors/hid-sensor-attributes.c   |  6 ++++++
>  drivers/iio/orientation/hid-sensor-rotation.c        | 20 ++++++++++++++++++++
>  2 files changed, 26 insertions(+)
> 
> diff --git a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> index 01e02b9..420f28f 100644
> --- a/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> +++ b/drivers/iio/common/hid-sensors/hid-sensor-attributes.c
> @@ -62,6 +62,12 @@
>  	{HID_USAGE_SENSOR_TIME_TIMESTAMP, 0, 1000000000, 0},
>  	{HID_USAGE_SENSOR_TIME_TIMESTAMP, HID_USAGE_SENSOR_UNITS_MILLISECOND,
>  		1000000, 0},
> +
> +	{HID_USAGE_SENSOR_DEVICE_ORIENTATION, 0, 1, 0},
> +
> +	{HID_USAGE_SENSOR_RELATIVE_ORIENTATION, 0, 1, 0},
> +
> +	{HID_USAGE_SENSOR_GEOMAGNETIC_ORIENTATION, 0, 1, 0},
>  };
>  
>  static int pow_10(unsigned power)
> diff --git a/drivers/iio/orientation/hid-sensor-rotation.c b/drivers/iio/orientation/hid-sensor-rotation.c
> index 60d3517..e9fa86c 100644
> --- a/drivers/iio/orientation/hid-sensor-rotation.c
> +++ b/drivers/iio/orientation/hid-sensor-rotation.c
> @@ -31,6 +31,10 @@ struct dev_rot_state {
>  	struct hid_sensor_common common_attributes;
>  	struct hid_sensor_hub_attribute_info quaternion;
>  	u32 sampled_vals[4];
> +	int scale_pre_decml;
> +	int scale_post_decml;
> +	int scale_precision;
> +	int value_offset;
>  };
>  
>  /* Channel definitions */
> @@ -41,6 +45,8 @@ struct dev_rot_state {
>  		.channel2 = IIO_MOD_QUATERNION,
>  		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
>  		.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SAMP_FREQ) |
> +					BIT(IIO_CHAN_INFO_OFFSET) |
> +					BIT(IIO_CHAN_INFO_SCALE) |
>  					BIT(IIO_CHAN_INFO_HYSTERESIS)
>  	}
>  };
> @@ -80,6 +86,15 @@ static int dev_rot_read_raw(struct iio_dev *indio_dev,
>  		} else
>  			ret_type = -EINVAL;
>  		break;
> +	case IIO_CHAN_INFO_SCALE:
> +		vals[0] = rot_state->scale_pre_decml;
> +		vals[1] = rot_state->scale_post_decml;
> +		return rot_state->scale_precision;
> +
> +	case IIO_CHAN_INFO_OFFSET:
> +		*vals = rot_state->value_offset;
> +		return IIO_VAL_INT;
> +
>  	case IIO_CHAN_INFO_SAMP_FREQ:
>  		ret_type = hid_sensor_read_samp_freq_value(
>  			&rot_state->common_attributes, &vals[0], &vals[1]);
> @@ -199,6 +214,11 @@ static int dev_rot_parse_report(struct platform_device *pdev,
>  	dev_dbg(&pdev->dev, "dev_rot: attrib size %d\n",
>  				st->quaternion.size);
>  
> +	st->scale_precision = hid_sensor_format_scale(
> +				hsdev->usage,
> +				&st->quaternion,
> +				&st->scale_pre_decml, &st->scale_post_decml);
> +
>  	/* Set Sensitivity field ids, when there is no individual modifier */
>  	if (st->common_attributes.sensitivity.index < 0) {
>  		sensor_hub_input_get_attribute_info(hsdev,
> 

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

end of thread, other threads:[~2017-05-07 22:23 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-05-07 10:24 [PATCH v2 1/3] iio: hid-sensor-rotation: Add relative orientation sensor hid support Song Hongyan
2017-05-07 10:24 ` [PATCH v2 2/3] iio: hid-sensor-rotation: Add geomagnetic " Song Hongyan
2017-05-07 11:12   ` Jonathan Cameron
     [not found] ` <1494152666-25632-1-git-send-email-hongyan.song-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2017-05-07 10:24   ` [PATCH v2 3/3] iio: hid-sensor-rotation: Add "scale" and "offset" properties parse support Song Hongyan
     [not found]     ` <1494152666-25632-3-git-send-email-hongyan.song-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2017-05-07 11:13       ` Jonathan Cameron
2017-05-07 11:11 ` [PATCH v2 1/3] iio: hid-sensor-rotation: Add relative orientation sensor hid support Jonathan Cameron

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).