Skip to content

Commit 141e763

Browse files
yeapajic23
authored andcommitted
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: 59d0f2d ("iio: hid: Add temperature sensor support") Signed-off-by: Ye Xiang <[email protected]> Cc: <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jonathan Cameron <[email protected]>
1 parent 37e89e5 commit 141e763

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

drivers/iio/temperature/hid-sensor-temperature.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,10 @@
1515
struct temperature_state {
1616
struct hid_sensor_common common_attributes;
1717
struct hid_sensor_hub_attribute_info temperature_attr;
18-
s32 temperature_data;
18+
struct {
19+
s32 temperature_data;
20+
u64 timestamp __aligned(8);
21+
} scan;
1922
int scale_pre_decml;
2023
int scale_post_decml;
2124
int scale_precision;
@@ -32,7 +35,7 @@ static const struct iio_chan_spec temperature_channels[] = {
3235
BIT(IIO_CHAN_INFO_SAMP_FREQ) |
3336
BIT(IIO_CHAN_INFO_HYSTERESIS),
3437
},
35-
IIO_CHAN_SOFT_TIMESTAMP(3),
38+
IIO_CHAN_SOFT_TIMESTAMP(1),
3639
};
3740

3841
/* Adjust channel real bits based on report descriptor */
@@ -123,9 +126,8 @@ static int temperature_proc_event(struct hid_sensor_hub_device *hsdev,
123126
struct temperature_state *temp_st = iio_priv(indio_dev);
124127

125128
if (atomic_read(&temp_st->common_attributes.data_ready))
126-
iio_push_to_buffers_with_timestamp(indio_dev,
127-
&temp_st->temperature_data,
128-
iio_get_time_ns(indio_dev));
129+
iio_push_to_buffers_with_timestamp(indio_dev, &temp_st->scan,
130+
iio_get_time_ns(indio_dev));
129131

130132
return 0;
131133
}
@@ -140,7 +142,7 @@ static int temperature_capture_sample(struct hid_sensor_hub_device *hsdev,
140142

141143
switch (usage_id) {
142144
case HID_USAGE_SENSOR_DATA_ENVIRONMENTAL_TEMPERATURE:
143-
temp_st->temperature_data = *(s32 *)raw_data;
145+
temp_st->scan.temperature_data = *(s32 *)raw_data;
144146
return 0;
145147
default:
146148
return -EINVAL;

0 commit comments

Comments
 (0)