Commit 141e7633 authored by Ye Xiang's avatar Ye Xiang Committed by Jonathan Cameron

iio: hid-sensor-temperature: Fix issues of timestamp channel

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: 59d0f2da ("iio: hid: Add temperature sensor support")
Signed-off-by: default avatarYe Xiang <xiang.ye@intel.com>
Cc: <Stable@vger.kernel.org>
Link: https://lore.kernel.org/r/20210303063615.12130-4-xiang.ye@intel.comSigned-off-by: default avatarJonathan Cameron <Jonathan.Cameron@huawei.com>
parent 37e89e57
...@@ -15,7 +15,10 @@ ...@@ -15,7 +15,10 @@
struct temperature_state { struct temperature_state {
struct hid_sensor_common common_attributes; struct hid_sensor_common common_attributes;
struct hid_sensor_hub_attribute_info temperature_attr; 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_pre_decml;
int scale_post_decml; int scale_post_decml;
int scale_precision; int scale_precision;
...@@ -32,7 +35,7 @@ static const struct iio_chan_spec temperature_channels[] = { ...@@ -32,7 +35,7 @@ static const struct iio_chan_spec temperature_channels[] = {
BIT(IIO_CHAN_INFO_SAMP_FREQ) | BIT(IIO_CHAN_INFO_SAMP_FREQ) |
BIT(IIO_CHAN_INFO_HYSTERESIS), BIT(IIO_CHAN_INFO_HYSTERESIS),
}, },
IIO_CHAN_SOFT_TIMESTAMP(3), IIO_CHAN_SOFT_TIMESTAMP(1),
}; };
/* Adjust channel real bits based on report descriptor */ /* Adjust channel real bits based on report descriptor */
...@@ -123,9 +126,8 @@ static int temperature_proc_event(struct hid_sensor_hub_device *hsdev, ...@@ -123,9 +126,8 @@ static int temperature_proc_event(struct hid_sensor_hub_device *hsdev,
struct temperature_state *temp_st = iio_priv(indio_dev); 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))
iio_push_to_buffers_with_timestamp(indio_dev, iio_push_to_buffers_with_timestamp(indio_dev, &temp_st->scan,
&temp_st->temperature_data, iio_get_time_ns(indio_dev));
iio_get_time_ns(indio_dev));
return 0; return 0;
} }
...@@ -140,7 +142,7 @@ static int temperature_capture_sample(struct hid_sensor_hub_device *hsdev, ...@@ -140,7 +142,7 @@ static int temperature_capture_sample(struct hid_sensor_hub_device *hsdev,
switch (usage_id) { switch (usage_id) {
case HID_USAGE_SENSOR_DATA_ENVIRONMENTAL_TEMPERATURE: case HID_USAGE_SENSOR_DATA_ENVIRONMENTAL_TEMPERATURE:
temp_st->temperature_data = *(s32 *)raw_data; temp_st->scan.temperature_data = *(s32 *)raw_data;
return 0; return 0;
default: default:
return -EINVAL; return -EINVAL;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment