Commit 7e3c741a authored by Alexander Holler's avatar Alexander Holler Committed by Linus Torvalds

rtc: rtc-hid-sensor-time: allow full years (16bit) in HID reports

The draft for HID-sensors (HUTRR39) currently doesn't define the range
for the attribute year.  Asking one of the authors revealed that full
years (e.g.  2013 instead of just 13) were meant.

So we now allow both, 8 bit and 16 bit values for the attribute year and
assuming full years when the value is 16 bits wide.

We will still support 8 bit values until the specification gets final
(and maybe defines a way to set the time too).
Signed-off-by: default avatarAlexander Holler <holler@ahsoftware.de>
Cc: Alessandro Zummo <a.zummo@towertech.it>
Cc: Lars-Peter Clausen <lars@metafoo.de>
Cc: Jonathan Cameron <jic23@cam.ac.uk>
Cc: Jiri Kosina <jkosina@suse.cz>
Cc: John Stultz <john.stultz@linaro.org>
Cc: Jingoo Han <jg1.han@samsung.com>
Signed-off-by: default avatarAndrew Morton <akpm@linux-foundation.org>
Signed-off-by: default avatarLinus Torvalds <torvalds@linux-foundation.org>
parent a2c0b859
...@@ -85,10 +85,13 @@ static int hid_time_capture_sample(struct hid_sensor_hub_device *hsdev, ...@@ -85,10 +85,13 @@ static int hid_time_capture_sample(struct hid_sensor_hub_device *hsdev,
switch (usage_id) { switch (usage_id) {
case HID_USAGE_SENSOR_TIME_YEAR: case HID_USAGE_SENSOR_TIME_YEAR:
if (raw_len == 1) {
time_buf->tm_year = *(u8 *)raw_data; time_buf->tm_year = *(u8 *)raw_data;
if (time_buf->tm_year < 70) if (time_buf->tm_year < 70)
/* assume we are in 1970...2069 */ /* assume we are in 1970...2069 */
time_buf->tm_year += 100; time_buf->tm_year += 100;
} else
time_buf->tm_year = *(u16 *)raw_data-1900;
break; break;
case HID_USAGE_SENSOR_TIME_MONTH: case HID_USAGE_SENSOR_TIME_MONTH:
/* sensor sending the month as 1-12, we need 0-11 */ /* sensor sending the month as 1-12, we need 0-11 */
...@@ -151,12 +154,28 @@ static int hid_time_parse_report(struct platform_device *pdev, ...@@ -151,12 +154,28 @@ static int hid_time_parse_report(struct platform_device *pdev,
return -EINVAL; return -EINVAL;
} }
if (time_state->info[i].size != 1) { if (time_state->info[i].size != 1) {
/*
* The draft for HID-sensors (HUTRR39) currently
* doesn't define the range for the year attribute.
* Therefor we support both 8 bit (0-99) and 16 bit
* (full) as size for the year.
*/
if (time_state->info[i].attrib_id !=
HID_USAGE_SENSOR_TIME_YEAR) {
dev_err(&pdev->dev, dev_err(&pdev->dev,
"attribute '%s' not 8 bits wide!\n", "attribute '%s' not 8 bits wide!\n",
hid_time_attrib_name( hid_time_attrib_name(
time_state->info[i].attrib_id)); time_state->info[i].attrib_id));
return -EINVAL; return -EINVAL;
} }
if (time_state->info[i].size != 2) {
dev_err(&pdev->dev,
"attribute '%s' not 8 or 16 bits wide!\n",
hid_time_attrib_name(
time_state->info[i].attrib_id));
return -EINVAL;
}
}
if (time_state->info[i].units != if (time_state->info[i].units !=
HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED && HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED &&
/* allow attribute seconds with unit seconds */ /* allow attribute seconds with unit seconds */
......
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