Lines Matching +full:sensor +full:- +full:hub

1 // SPDX-License-Identifier: GPL-2.0-only
3 * HID Sensor Time Driver
9 #include <linux/hid-sensor-hub.h>
55 spin_lock_irqsave(&time_state->lock_last_time, flags); in hid_time_proc_event()
56 time_state->last_time = time_state->time_buf; in hid_time_proc_event()
57 spin_unlock_irqrestore(&time_state->lock_last_time, flags); in hid_time_proc_event()
58 complete(&time_state->comp_last_time); in hid_time_proc_event()
72 return (u32)(~0U); /* 0xff... or -1 to denote an error */ in hid_time_value()
81 struct rtc_time *time_buf = &time_state->time_buf; in hid_time_capture_sample()
86 * The draft for HID-sensors (HUTRR39) currently doesn't define in hid_time_capture_sample()
88 * 8 bit (0-99) and 16 or 32 bits (full) as size for the year. in hid_time_capture_sample()
91 time_buf->tm_year = *(u8 *)raw_data; in hid_time_capture_sample()
92 if (time_buf->tm_year < 70) in hid_time_capture_sample()
94 time_buf->tm_year += 100; in hid_time_capture_sample()
96 time_buf->tm_year = in hid_time_capture_sample()
97 (int)hid_time_value(raw_len, raw_data)-1900; in hid_time_capture_sample()
100 /* sensors are sending the month as 1-12, we need 0-11 */ in hid_time_capture_sample()
101 time_buf->tm_mon = (int)hid_time_value(raw_len, raw_data)-1; in hid_time_capture_sample()
104 time_buf->tm_mday = (int)hid_time_value(raw_len, raw_data); in hid_time_capture_sample()
107 time_buf->tm_hour = (int)hid_time_value(raw_len, raw_data); in hid_time_capture_sample()
110 time_buf->tm_min = (int)hid_time_value(raw_len, raw_data); in hid_time_capture_sample()
113 time_buf->tm_sec = (int)hid_time_value(raw_len, raw_data); in hid_time_capture_sample()
116 return -EINVAL; in hid_time_capture_sample()
145 &time_state->info[i]) < 0) in hid_time_parse_report()
146 return -EINVAL; in hid_time_parse_report()
148 report_id = time_state->info[0].report_id; in hid_time_parse_report()
150 dev_err(&pdev->dev, "bad report ID!\n"); in hid_time_parse_report()
151 return -EINVAL; in hid_time_parse_report()
154 if (time_state->info[i].report_id != report_id) { in hid_time_parse_report()
155 dev_err(&pdev->dev, in hid_time_parse_report()
157 return -EINVAL; in hid_time_parse_report()
159 if (time_state->info[i].size == 3 || in hid_time_parse_report()
160 time_state->info[i].size > 4) { in hid_time_parse_report()
161 dev_err(&pdev->dev, in hid_time_parse_report()
164 time_state->info[i].attrib_id)); in hid_time_parse_report()
165 return -EINVAL; in hid_time_parse_report()
167 if (time_state->info[i].units != in hid_time_parse_report()
170 !(time_state->info[i].attrib_id == in hid_time_parse_report()
172 time_state->info[i].units == in hid_time_parse_report()
174 dev_err(&pdev->dev, in hid_time_parse_report()
177 time_state->info[i].attrib_id)); in hid_time_parse_report()
178 return -EINVAL; in hid_time_parse_report()
180 if (time_state->info[i].unit_expo) { in hid_time_parse_report()
181 dev_err(&pdev->dev, in hid_time_parse_report()
184 time_state->info[i].attrib_id)); in hid_time_parse_report()
185 return -EINVAL; in hid_time_parse_report()
198 reinit_completion(&time_state->comp_last_time); in hid_rtc_read_time()
200 sensor_hub_input_attr_get_raw_value(time_state->common_attributes.hsdev, in hid_rtc_read_time()
202 time_state->info[0].report_id, SENSOR_HUB_SYNC, false); in hid_rtc_read_time()
205 &time_state->comp_last_time, HZ*6); in hid_rtc_read_time()
208 spin_lock_irqsave(&time_state->lock_last_time, flags); in hid_rtc_read_time()
209 *tm = time_state->last_time; in hid_rtc_read_time()
210 spin_unlock_irqrestore(&time_state->lock_last_time, flags); in hid_rtc_read_time()
214 return -EIO; /* timeouted */ in hid_rtc_read_time()
215 return ret; /* killed (-ERESTARTSYS) */ in hid_rtc_read_time()
225 struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); in hid_time_probe()
226 struct hid_time_state *time_state = devm_kzalloc(&pdev->dev, in hid_time_probe()
230 return -ENOMEM; in hid_time_probe()
234 spin_lock_init(&time_state->lock_last_time); in hid_time_probe()
235 init_completion(&time_state->comp_last_time); in hid_time_probe()
236 time_state->common_attributes.hsdev = hsdev; in hid_time_probe()
237 time_state->common_attributes.pdev = pdev; in hid_time_probe()
241 &time_state->common_attributes, in hid_time_probe()
245 dev_err(&pdev->dev, "failed to setup common attributes!\n"); in hid_time_probe()
252 dev_err(&pdev->dev, "failed to setup attributes!\n"); in hid_time_probe()
256 time_state->callbacks.send_event = hid_time_proc_event; in hid_time_probe()
257 time_state->callbacks.capture_sample = hid_time_capture_sample; in hid_time_probe()
258 time_state->callbacks.pdev = pdev; in hid_time_probe()
260 &time_state->callbacks); in hid_time_probe()
262 dev_err(&pdev->dev, "register callback failed!\n"); in hid_time_probe()
268 dev_err(&pdev->dev, "failed to open sensor hub device!\n"); in hid_time_probe()
276 hid_device_io_start(hsdev->hdev); in hid_time_probe()
278 time_state->rtc = devm_rtc_device_register(&pdev->dev, in hid_time_probe()
279 "hid-sensor-time", &hid_time_rtc_ops, in hid_time_probe()
282 if (IS_ERR(time_state->rtc)) { in hid_time_probe()
283 hid_device_io_stop(hsdev->hdev); in hid_time_probe()
284 ret = PTR_ERR(time_state->rtc); in hid_time_probe()
285 time_state->rtc = NULL; in hid_time_probe()
286 dev_err(&pdev->dev, "rtc device register failed!\n"); in hid_time_probe()
301 struct hid_sensor_hub_device *hsdev = dev_get_platdata(&pdev->dev); in hid_time_remove()
309 /* Format: HID-SENSOR-usage_id_in_hex_lowercase */
310 .name = "HID-SENSOR-2000a0",
326 MODULE_DESCRIPTION("HID Sensor Time");