Try to get sample timestamp from sensor hub first, if failed then use system timestamp. Signed-off-by: Ye Xiang <xiang.ye@xxxxxxxxx> --- 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