lkml.org 
[lkml]   [2021]   [Mar]   [3]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 4/4] iio: hid-sensor-temperature: Get sample timestamp from sensor hub
Date
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
\
 
 \ /
  Last update: 2021-03-03 15:11    [W:0.059 / U:1.960 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site