aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/rtc/rtc-hid-sensor-time.c
diff options
context:
space:
mode:
authorAlexander Holler <holler@ahsoftware.de>2013-07-03 18:07:00 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2013-07-03 19:07:54 -0400
commit7e3c741abdae964b8f8aa9f46cf51143e2d0f686 (patch)
tree4e788e34be0ff993825b50f12e236a49973a8683 /drivers/rtc/rtc-hid-sensor-time.c
parenta2c0b85945e75901906d0aa82ef9a0bea96f85ce (diff)
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: Alexander 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: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'drivers/rtc/rtc-hid-sensor-time.c')
-rw-r--r--drivers/rtc/rtc-hid-sensor-time.c33
1 files changed, 26 insertions, 7 deletions
diff --git a/drivers/rtc/rtc-hid-sensor-time.c b/drivers/rtc/rtc-hid-sensor-time.c
index 63024505dddc..b8c1b106a0b7 100644
--- a/drivers/rtc/rtc-hid-sensor-time.c
+++ b/drivers/rtc/rtc-hid-sensor-time.c
@@ -85,10 +85,13 @@ static int hid_time_capture_sample(struct hid_sensor_hub_device *hsdev,
85 85
86 switch (usage_id) { 86 switch (usage_id) {
87 case HID_USAGE_SENSOR_TIME_YEAR: 87 case HID_USAGE_SENSOR_TIME_YEAR:
88 time_buf->tm_year = *(u8 *)raw_data; 88 if (raw_len == 1) {
89 if (time_buf->tm_year < 70) 89 time_buf->tm_year = *(u8 *)raw_data;
90 /* assume we are in 1970...2069 */ 90 if (time_buf->tm_year < 70)
91 time_buf->tm_year += 100; 91 /* assume we are in 1970...2069 */
92 time_buf->tm_year += 100;
93 } else
94 time_buf->tm_year = *(u16 *)raw_data-1900;
92 break; 95 break;
93 case HID_USAGE_SENSOR_TIME_MONTH: 96 case HID_USAGE_SENSOR_TIME_MONTH:
94 /* sensor sending the month as 1-12, we need 0-11 */ 97 /* sensor sending the month as 1-12, we need 0-11 */
@@ -151,11 +154,27 @@ static int hid_time_parse_report(struct platform_device *pdev,
151 return -EINVAL; 154 return -EINVAL;
152 } 155 }
153 if (time_state->info[i].size != 1) { 156 if (time_state->info[i].size != 1) {
154 dev_err(&pdev->dev, 157 /*
155 "attribute '%s' not 8 bits wide!\n", 158 * The draft for HID-sensors (HUTRR39) currently
159 * doesn't define the range for the year attribute.
160 * Therefor we support both 8 bit (0-99) and 16 bit
161 * (full) as size for the year.
162 */
163 if (time_state->info[i].attrib_id !=
164 HID_USAGE_SENSOR_TIME_YEAR) {
165 dev_err(&pdev->dev,
166 "attribute '%s' not 8 bits wide!\n",
156 hid_time_attrib_name( 167 hid_time_attrib_name(
157 time_state->info[i].attrib_id)); 168 time_state->info[i].attrib_id));
158 return -EINVAL; 169 return -EINVAL;
170 }
171 if (time_state->info[i].size != 2) {
172 dev_err(&pdev->dev,
173 "attribute '%s' not 8 or 16 bits wide!\n",
174 hid_time_attrib_name(
175 time_state->info[i].attrib_id));
176 return -EINVAL;
177 }
159 } 178 }
160 if (time_state->info[i].units != 179 if (time_state->info[i].units !=
161 HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED && 180 HID_USAGE_SENSOR_UNITS_NOT_SPECIFIED &&