linux-input.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 0/4] Fix humidity and temperature timestamp channel issues
@ 2021-03-03  6:36 Ye Xiang
  2021-03-03  6:36 ` [PATCH 1/4] iio: hid-sensor-humidity: Fix alignment issue of timestamp channel Ye Xiang
                   ` (3 more replies)
  0 siblings, 4 replies; 7+ messages in thread
From: Ye Xiang @ 2021-03-03  6:36 UTC (permalink / raw)
  To: jikos, jic23, srinivas.pandruvada
  Cc: linux-input, linux-iio, linux-kernel, Ye Xiang

This patch series fixes timestamp issues for humidity and temperature sensor.

Ye Xiang (4):
  iio: hid-sensor-humidity: Fix alignment issue of timestamp channel
  iio: hid-sensor-humidity: Get sample timestamp from sensor hub
  iio: hid-sensor-temperature: Fix issues of timestamp channel
  iio: hid-sensor-temperature: Get sample timestamp from sensor hub

 drivers/iio/humidity/hid-sensor-humidity.c    | 24 ++++++++++++-----
 .../iio/temperature/hid-sensor-temperature.c  | 26 ++++++++++++++-----
 2 files changed, 37 insertions(+), 13 deletions(-)

-- 
2.17.1


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

* [PATCH 1/4] iio: hid-sensor-humidity: Fix alignment issue of timestamp channel
  2021-03-03  6:36 [PATCH 0/4] Fix humidity and temperature timestamp channel issues Ye Xiang
@ 2021-03-03  6:36 ` Ye Xiang
  2021-03-06 17:05   ` Jonathan Cameron
  2021-03-03  6:36 ` [PATCH 2/4] iio: hid-sensor-humidity: Get sample timestamp from sensor hub Ye Xiang
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 7+ messages in thread
From: Ye Xiang @ 2021-03-03  6:36 UTC (permalink / raw)
  To: jikos, jic23, srinivas.pandruvada
  Cc: linux-input, linux-iio, linux-kernel, Ye Xiang

This patch ensures that, there is sufficient space and correct
alignment for the timestamp.

Fixes: d7ed89d5aadf ("iio: hid: Add humidity sensor support")
Signed-off-by: Ye Xiang <xiang.ye@intel.com>
---
 drivers/iio/humidity/hid-sensor-humidity.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/humidity/hid-sensor-humidity.c b/drivers/iio/humidity/hid-sensor-humidity.c
index ec88ae3f233d..74383abc0d44 100644
--- a/drivers/iio/humidity/hid-sensor-humidity.c
+++ b/drivers/iio/humidity/hid-sensor-humidity.c
@@ -15,7 +15,10 @@
 struct hid_humidity_state {
 	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info humidity_attr;
-	s32 humidity_data;
+	struct {
+		s32 humidity_data;
+		u64 timestamp __aligned(8);
+	} scan;
 	int scale_pre_decml;
 	int scale_post_decml;
 	int scale_precision;
@@ -129,9 +132,8 @@ static int humidity_proc_event(struct hid_sensor_hub_device *hsdev,
 	struct hid_humidity_state *humid_st = iio_priv(indio_dev);
 
 	if (atomic_read(&humid_st->common_attributes.data_ready))
-		iio_push_to_buffers_with_timestamp(indio_dev,
-					&humid_st->humidity_data,
-					iio_get_time_ns(indio_dev));
+		iio_push_to_buffers_with_timestamp(indio_dev, &humid_st->scan,
+						   iio_get_time_ns(indio_dev));
 
 	return 0;
 }
@@ -146,7 +148,7 @@ static int humidity_capture_sample(struct hid_sensor_hub_device *hsdev,
 
 	switch (usage_id) {
 	case HID_USAGE_SENSOR_ATMOSPHERIC_HUMIDITY:
-		humid_st->humidity_data = *(s32 *)raw_data;
+		humid_st->scan.humidity_data = *(s32 *)raw_data;
 
 		return 0;
 	default:
-- 
2.17.1


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

* [PATCH 2/4] iio: hid-sensor-humidity: Get sample timestamp from sensor hub
  2021-03-03  6:36 [PATCH 0/4] Fix humidity and temperature timestamp channel issues Ye Xiang
  2021-03-03  6:36 ` [PATCH 1/4] iio: hid-sensor-humidity: Fix alignment issue of timestamp channel Ye Xiang
@ 2021-03-03  6:36 ` Ye Xiang
  2021-03-03  6:36 ` [PATCH 3/4] iio: hid-sensor-temperature: Fix issues of timestamp channel Ye Xiang
  2021-03-03  6:36 ` [PATCH 4/4] iio: hid-sensor-temperature: Get sample timestamp from sensor hub Ye Xiang
  3 siblings, 0 replies; 7+ messages in thread
From: Ye Xiang @ 2021-03-03  6:36 UTC (permalink / raw)
  To: jikos, jic23, srinivas.pandruvada
  Cc: linux-input, linux-iio, linux-kernel, Ye Xiang

Try to get sample timestamp from sensor hub first, if failed
then use system timestamp.

Signed-off-by: Ye Xiang <xiang.ye@intel.com>
---
 drivers/iio/humidity/hid-sensor-humidity.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/humidity/hid-sensor-humidity.c b/drivers/iio/humidity/hid-sensor-humidity.c
index 74383abc0d44..f7b4c76ed94f 100644
--- a/drivers/iio/humidity/hid-sensor-humidity.c
+++ b/drivers/iio/humidity/hid-sensor-humidity.c
@@ -23,6 +23,7 @@ struct hid_humidity_state {
 	int scale_post_decml;
 	int scale_precision;
 	int value_offset;
+	s64 timestamp;
 };
 
 static const u32 humidity_sensitivity_addresses[] = {
@@ -131,9 +132,14 @@ static int humidity_proc_event(struct hid_sensor_hub_device *hsdev,
 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
 	struct hid_humidity_state *humid_st = iio_priv(indio_dev);
 
-	if (atomic_read(&humid_st->common_attributes.data_ready))
+	if (atomic_read(&humid_st->common_attributes.data_ready)) {
+		if (!humid_st->timestamp)
+			humid_st->timestamp = iio_get_time_ns(indio_dev);
+
 		iio_push_to_buffers_with_timestamp(indio_dev, &humid_st->scan,
-						   iio_get_time_ns(indio_dev));
+						   humid_st->timestamp);
+		humid_st->timestamp = 0;
+	}
 
 	return 0;
 }
@@ -151,6 +157,10 @@ static int humidity_capture_sample(struct hid_sensor_hub_device *hsdev,
 		humid_st->scan.humidity_data = *(s32 *)raw_data;
 
 		return 0;
+	case HID_USAGE_SENSOR_TIME_TIMESTAMP:
+		humid_st->timestamp = hid_sensor_convert_timestamp(&humid_st->common_attributes,
+								   *(s64 *)raw_data);
+		return 0;
 	default:
 		return -EINVAL;
 	}
-- 
2.17.1


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

* [PATCH 3/4] iio: hid-sensor-temperature: Fix issues of timestamp channel
  2021-03-03  6:36 [PATCH 0/4] Fix humidity and temperature timestamp channel issues Ye Xiang
  2021-03-03  6:36 ` [PATCH 1/4] iio: hid-sensor-humidity: Fix alignment issue of timestamp channel Ye Xiang
  2021-03-03  6:36 ` [PATCH 2/4] iio: hid-sensor-humidity: Get sample timestamp from sensor hub Ye Xiang
@ 2021-03-03  6:36 ` Ye Xiang
  2021-03-06 17:07   ` Jonathan Cameron
  2021-03-03  6:36 ` [PATCH 4/4] iio: hid-sensor-temperature: Get sample timestamp from sensor hub Ye Xiang
  3 siblings, 1 reply; 7+ messages in thread
From: Ye Xiang @ 2021-03-03  6:36 UTC (permalink / raw)
  To: jikos, jic23, srinivas.pandruvada
  Cc: linux-input, linux-iio, linux-kernel, Ye Xiang

This patch fixes 2 issues of timestamp channel:
1. This patch ensures that there is sufficient space and correct
alignment for the timestamp.
2. Correct the timestamp channel scan index.

Fixes: 59d0f2da3569 ("iio: hid: Add temperature sensor support")
Signed-off-by: Ye Xiang <xiang.ye@intel.com>
---
 drivers/iio/temperature/hid-sensor-temperature.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)

diff --git a/drivers/iio/temperature/hid-sensor-temperature.c b/drivers/iio/temperature/hid-sensor-temperature.c
index e3d38cbcf354..dc534ed784c3 100644
--- a/drivers/iio/temperature/hid-sensor-temperature.c
+++ b/drivers/iio/temperature/hid-sensor-temperature.c
@@ -15,7 +15,10 @@
 struct temperature_state {
 	struct hid_sensor_common common_attributes;
 	struct hid_sensor_hub_attribute_info temperature_attr;
-	s32 temperature_data;
+	struct {
+		s32 temperature_data;
+		u64 timestamp __aligned(8);
+	} scan;
 	int scale_pre_decml;
 	int scale_post_decml;
 	int scale_precision;
@@ -36,7 +39,7 @@ static const struct iio_chan_spec temperature_channels[] = {
 			BIT(IIO_CHAN_INFO_SAMP_FREQ) |
 			BIT(IIO_CHAN_INFO_HYSTERESIS),
 	},
-	IIO_CHAN_SOFT_TIMESTAMP(3),
+	IIO_CHAN_SOFT_TIMESTAMP(1),
 };
 
 /* Adjust channel real bits based on report descriptor */
@@ -127,9 +130,8 @@ static int temperature_proc_event(struct hid_sensor_hub_device *hsdev,
 	struct temperature_state *temp_st = iio_priv(indio_dev);
 
 	if (atomic_read(&temp_st->common_attributes.data_ready))
-		iio_push_to_buffers_with_timestamp(indio_dev,
-				&temp_st->temperature_data,
-				iio_get_time_ns(indio_dev));
+		iio_push_to_buffers_with_timestamp(indio_dev, &temp_st->scan,
+						   iio_get_time_ns(indio_dev));
 
 	return 0;
 }
@@ -144,7 +146,7 @@ static int temperature_capture_sample(struct hid_sensor_hub_device *hsdev,
 
 	switch (usage_id) {
 	case HID_USAGE_SENSOR_DATA_ENVIRONMENTAL_TEMPERATURE:
-		temp_st->temperature_data = *(s32 *)raw_data;
+		temp_st->scan.temperature_data = *(s32 *)raw_data;
 		return 0;
 	default:
 		return -EINVAL;
-- 
2.17.1


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

* [PATCH 4/4] iio: hid-sensor-temperature: Get sample timestamp from sensor hub
  2021-03-03  6:36 [PATCH 0/4] Fix humidity and temperature timestamp channel issues Ye Xiang
                   ` (2 preceding siblings ...)
  2021-03-03  6:36 ` [PATCH 3/4] iio: hid-sensor-temperature: Fix issues of timestamp channel Ye Xiang
@ 2021-03-03  6:36 ` Ye Xiang
  3 siblings, 0 replies; 7+ messages in thread
From: Ye Xiang @ 2021-03-03  6:36 UTC (permalink / raw)
  To: jikos, jic23, srinivas.pandruvada
  Cc: linux-input, linux-iio, linux-kernel, Ye Xiang

Try to get sample timestamp from sensor hub first, if failed
then use system timestamp.

Signed-off-by: Ye Xiang <xiang.ye@intel.com>
---
 drivers/iio/temperature/hid-sensor-temperature.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/temperature/hid-sensor-temperature.c b/drivers/iio/temperature/hid-sensor-temperature.c
index dc534ed784c3..0d8110735779 100644
--- a/drivers/iio/temperature/hid-sensor-temperature.c
+++ b/drivers/iio/temperature/hid-sensor-temperature.c
@@ -23,6 +23,7 @@ struct temperature_state {
 	int scale_post_decml;
 	int scale_precision;
 	int value_offset;
+	s64 timestamp;
 };
 
 static const u32 temperature_sensitivity_addresses[] = {
@@ -129,9 +130,14 @@ static int temperature_proc_event(struct hid_sensor_hub_device *hsdev,
 	struct iio_dev *indio_dev = platform_get_drvdata(pdev);
 	struct temperature_state *temp_st = iio_priv(indio_dev);
 
-	if (atomic_read(&temp_st->common_attributes.data_ready))
+	if (atomic_read(&temp_st->common_attributes.data_ready)) {
+		if (!temp_st->timestamp)
+			temp_st->timestamp = iio_get_time_ns(indio_dev);
+
 		iio_push_to_buffers_with_timestamp(indio_dev, &temp_st->scan,
-						   iio_get_time_ns(indio_dev));
+						   temp_st->timestamp);
+		temp_st->timestamp = 0;
+	}
 
 	return 0;
 }
@@ -148,6 +154,10 @@ static int temperature_capture_sample(struct hid_sensor_hub_device *hsdev,
 	case HID_USAGE_SENSOR_DATA_ENVIRONMENTAL_TEMPERATURE:
 		temp_st->scan.temperature_data = *(s32 *)raw_data;
 		return 0;
+	case HID_USAGE_SENSOR_TIME_TIMESTAMP:
+		temp_st->timestamp = hid_sensor_convert_timestamp(&temp_st->common_attributes,
+								  *(s64 *)raw_data);
+		return 0;
 	default:
 		return -EINVAL;
 	}
-- 
2.17.1


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

* Re: [PATCH 1/4] iio: hid-sensor-humidity: Fix alignment issue of timestamp channel
  2021-03-03  6:36 ` [PATCH 1/4] iio: hid-sensor-humidity: Fix alignment issue of timestamp channel Ye Xiang
@ 2021-03-06 17:05   ` Jonathan Cameron
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2021-03-06 17:05 UTC (permalink / raw)
  To: Ye Xiang; +Cc: jikos, srinivas.pandruvada, linux-input, linux-iio, linux-kernel

On Wed,  3 Mar 2021 14:36:12 +0800
Ye Xiang <xiang.ye@intel.com> wrote:

> This patch ensures that, there is sufficient space and correct
> alignment for the timestamp.
> 
> Fixes: d7ed89d5aadf ("iio: hid: Add humidity sensor support")
> Signed-off-by: Ye Xiang <xiang.ye@intel.com>
ouch.  I guess we were trampling over the next few elements and somehow
getting away with it (mostly).

Applied to the fixes-togreg branch of iio.git and marked for stable.

As the next patch isn't a fix, we'll have to wait for this to get
upstream and round the loop so I can apply the next patch via the
slower path.  Give me a poke if I seem to have lost it once the
dependency is in my togreg branch.

thanks,

Jonathan


> ---
>  drivers/iio/humidity/hid-sensor-humidity.c | 12 +++++++-----
>  1 file changed, 7 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/iio/humidity/hid-sensor-humidity.c b/drivers/iio/humidity/hid-sensor-humidity.c
> index ec88ae3f233d..74383abc0d44 100644
> --- a/drivers/iio/humidity/hid-sensor-humidity.c
> +++ b/drivers/iio/humidity/hid-sensor-humidity.c
> @@ -15,7 +15,10 @@
>  struct hid_humidity_state {
>  	struct hid_sensor_common common_attributes;
>  	struct hid_sensor_hub_attribute_info humidity_attr;
> -	s32 humidity_data;
> +	struct {
> +		s32 humidity_data;
> +		u64 timestamp __aligned(8);
> +	} scan;
>  	int scale_pre_decml;
>  	int scale_post_decml;
>  	int scale_precision;
> @@ -129,9 +132,8 @@ static int humidity_proc_event(struct hid_sensor_hub_device *hsdev,
>  	struct hid_humidity_state *humid_st = iio_priv(indio_dev);
>  
>  	if (atomic_read(&humid_st->common_attributes.data_ready))
> -		iio_push_to_buffers_with_timestamp(indio_dev,
> -					&humid_st->humidity_data,
> -					iio_get_time_ns(indio_dev));
> +		iio_push_to_buffers_with_timestamp(indio_dev, &humid_st->scan,
> +						   iio_get_time_ns(indio_dev));
>  
>  	return 0;
>  }
> @@ -146,7 +148,7 @@ static int humidity_capture_sample(struct hid_sensor_hub_device *hsdev,
>  
>  	switch (usage_id) {
>  	case HID_USAGE_SENSOR_ATMOSPHERIC_HUMIDITY:
> -		humid_st->humidity_data = *(s32 *)raw_data;
> +		humid_st->scan.humidity_data = *(s32 *)raw_data;
>  
>  		return 0;
>  	default:


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

* Re: [PATCH 3/4] iio: hid-sensor-temperature: Fix issues of timestamp channel
  2021-03-03  6:36 ` [PATCH 3/4] iio: hid-sensor-temperature: Fix issues of timestamp channel Ye Xiang
@ 2021-03-06 17:07   ` Jonathan Cameron
  0 siblings, 0 replies; 7+ messages in thread
From: Jonathan Cameron @ 2021-03-06 17:07 UTC (permalink / raw)
  To: Ye Xiang; +Cc: jikos, srinivas.pandruvada, linux-input, linux-iio, linux-kernel

On Wed,  3 Mar 2021 14:36:14 +0800
Ye Xiang <xiang.ye@intel.com> wrote:

> This patch fixes 2 issues of timestamp channel:
> 1. This patch ensures that there is sufficient space and correct
> alignment for the timestamp.
> 2. Correct the timestamp channel scan index.
This isn't technically a bug because channel index numbers just need
to be monotonic.  Still it's a reasonable tidy up given 1.
> 
> Fixes: 59d0f2da3569 ("iio: hid: Add temperature sensor support")
> Signed-off-by: Ye Xiang <xiang.ye@intel.com>
Applied to the fixes togreg branch of iio.git and marked for stable.
Patch 4 is not a fix (I think) so will have to wait for this to
be upstream.

Jonathan

> ---
>  drivers/iio/temperature/hid-sensor-temperature.c | 14 ++++++++------
>  1 file changed, 8 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/iio/temperature/hid-sensor-temperature.c b/drivers/iio/temperature/hid-sensor-temperature.c
> index e3d38cbcf354..dc534ed784c3 100644
> --- a/drivers/iio/temperature/hid-sensor-temperature.c
> +++ b/drivers/iio/temperature/hid-sensor-temperature.c
> @@ -15,7 +15,10 @@
>  struct temperature_state {
>  	struct hid_sensor_common common_attributes;
>  	struct hid_sensor_hub_attribute_info temperature_attr;
> -	s32 temperature_data;
> +	struct {
> +		s32 temperature_data;
> +		u64 timestamp __aligned(8);
> +	} scan;
>  	int scale_pre_decml;
>  	int scale_post_decml;
>  	int scale_precision;
> @@ -36,7 +39,7 @@ static const struct iio_chan_spec temperature_channels[] = {
>  			BIT(IIO_CHAN_INFO_SAMP_FREQ) |
>  			BIT(IIO_CHAN_INFO_HYSTERESIS),
>  	},
> -	IIO_CHAN_SOFT_TIMESTAMP(3),
> +	IIO_CHAN_SOFT_TIMESTAMP(1),
>  };
>  
>  /* Adjust channel real bits based on report descriptor */
> @@ -127,9 +130,8 @@ static int temperature_proc_event(struct hid_sensor_hub_device *hsdev,
>  	struct temperature_state *temp_st = iio_priv(indio_dev);
>  
>  	if (atomic_read(&temp_st->common_attributes.data_ready))
> -		iio_push_to_buffers_with_timestamp(indio_dev,
> -				&temp_st->temperature_data,
> -				iio_get_time_ns(indio_dev));
> +		iio_push_to_buffers_with_timestamp(indio_dev, &temp_st->scan,
> +						   iio_get_time_ns(indio_dev));
>  
>  	return 0;
>  }
> @@ -144,7 +146,7 @@ static int temperature_capture_sample(struct hid_sensor_hub_device *hsdev,
>  
>  	switch (usage_id) {
>  	case HID_USAGE_SENSOR_DATA_ENVIRONMENTAL_TEMPERATURE:
> -		temp_st->temperature_data = *(s32 *)raw_data;
> +		temp_st->scan.temperature_data = *(s32 *)raw_data;
>  		return 0;
>  	default:
>  		return -EINVAL;


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

end of thread, other threads:[~2021-03-06 17:08 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-03-03  6:36 [PATCH 0/4] Fix humidity and temperature timestamp channel issues Ye Xiang
2021-03-03  6:36 ` [PATCH 1/4] iio: hid-sensor-humidity: Fix alignment issue of timestamp channel Ye Xiang
2021-03-06 17:05   ` Jonathan Cameron
2021-03-03  6:36 ` [PATCH 2/4] iio: hid-sensor-humidity: Get sample timestamp from sensor hub Ye Xiang
2021-03-03  6:36 ` [PATCH 3/4] iio: hid-sensor-temperature: Fix issues of timestamp channel Ye Xiang
2021-03-06 17:07   ` Jonathan Cameron
2021-03-03  6:36 ` [PATCH 4/4] iio: hid-sensor-temperature: Get sample timestamp from sensor hub Ye Xiang

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