From: Ye Xiang <xiang.ye@intel.com>
To: jikos@kernel.org, jic23@kernel.org, srinivas.pandruvada@linux.intel.com
Cc: linux-input@vger.kernel.org, linux-iio@vger.kernel.org,
linux-kernel@vger.kernel.org, Ye Xiang <xiang.ye@intel.com>
Subject: [PATCH 4/4] iio: hid-sensor-temperature: Get sample timestamp from sensor hub
Date: Wed, 3 Mar 2021 14:36:15 +0800 [thread overview]
Message-ID: <20210303063615.12130-5-xiang.ye@intel.com> (raw)
In-Reply-To: <20210303063615.12130-1-xiang.ye@intel.com>
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
prev parent reply other threads:[~2021-03-03 12:58 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
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 ` Ye Xiang [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210303063615.12130-5-xiang.ye@intel.com \
--to=xiang.ye@intel.com \
--cc=jic23@kernel.org \
--cc=jikos@kernel.org \
--cc=linux-iio@vger.kernel.org \
--cc=linux-input@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=srinivas.pandruvada@linux.intel.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox