19 #include <linux/device.h>
20 #include <linux/hid.h>
23 #include <linux/module.h>
24 #include <linux/slab.h>
26 #include <linux/list.h>
85 static int sensor_hub_check_for_sensor_page(
struct hid_device *hdev)
108 if (report->
id ==
id)
111 hid_warn(hdev,
"No report with id 0x%x found\n",
id);
116 static int sensor_hub_get_physical_device_count(
124 field = report->
field[0];
133 static void sensor_hub_fill_attr_info(
153 if (callback->usage_id == usage_id) {
154 *priv = callback->
priv;
172 if (callback->
usage_id == usage_id) {
176 callback = kzalloc(
sizeof(*callback),
GFP_ATOMIC);
199 if (callback->
usage_id == usage_id) {
219 if (!report || (field_index >= report->
maxfield)) {
243 if (!report || (field_index >= report->
maxfield)) {
249 *value = report->
field[field_index]->value[0];
261 u32 attr_usage_id,
u32 report_id)
270 init_completion(&data->
pending.ready);
271 data->
pending.usage_id = usage_id;
272 data->
pending.attr_usage_id = attr_usage_id;
279 spin_unlock_irqrestore(&data->
lock, flags);
283 spin_unlock_irqrestore(&data->
lock, flags);
285 switch (data->
pending.raw_size) {
316 int collection_index = -1;
332 if (usage_id == collection->
usage) {
333 collection_index =
i;
337 if (collection_index == -1)
345 field->
logical == attr_usage_id) {
346 sensor_hub_fill_attr_info(info, i, report->
id,
352 if (field->
usage[j].hid ==
354 field->
usage[j].collection_index ==
356 sensor_hub_fill_attr_info(info,
382 hid_dbg(hdev,
" sensor_hub_suspend\n");
394 static int sensor_hub_resume(
struct hid_device *hdev)
399 hid_dbg(hdev,
" sensor_hub_resume\n");
411 static int sensor_hub_reset_resume(
struct hid_device *hdev)
419 static int sensor_hub_raw_event(
struct hid_device *hdev,
431 hid_dbg(hdev,
"sensor_hub_raw_event report id:0x%x size:%d type:%d\n",
432 report->
id, size, report->
type);
447 hid_dbg(hdev,
"%d collection_index:%x hid:%x sz:%x\n",
448 i, report->
field[i]->usage->collection_index,
449 report->
field[i]->usage->hid,
450 report->
field[i]->report_size/8);
452 sz = report->
field[
i]->report_size/8;
454 report->
field[i]->usage->hid) {
455 hid_dbg(hdev,
"data was pending ...\n");
465 report->
field[
i]->usage->collection_index];
466 hid_dbg(hdev,
"collection->usage %x\n",
468 callback = sensor_hub_get_callback(pdata->
hsdev->hdev,
469 report->
field[i]->physical,
472 if (report->
field[i]->logical)
474 report->
field[i]->logical, sz, ptr,
478 report->
field[i]->usage->hid, sz, ptr,
483 if (callback && collection && callback->
send_event)
486 spin_unlock_irqrestore(&pdata->
lock, flags);
492 static int sensor_hub_probe(
struct hid_device *hdev,
506 hid_err(hdev,
"cannot allocate Sensor data\n");
511 hid_err(hdev,
"cannot allocate hid_sensor_hub_device\n");
515 hid_set_drvdata(hdev, sd);
516 sd->
hsdev->hdev = hdev;
522 ret = hid_parse(hdev);
524 hid_err(hdev,
"parse failed\n");
527 if (sensor_hub_check_for_sensor_page(hdev) < 0) {
528 hid_err(hdev,
"sensor page not found\n");
531 INIT_LIST_HEAD(&hdev->
inputs);
533 ret = hid_hw_start(hdev, 0);
535 hid_err(hdev,
"hw start failed\n");
538 ret = hid_hw_open(hdev);
540 hid_err(hdev,
"failed to open input interrupt pipe\n");
548 dev_cnt = sensor_hub_get_physical_device_count(report_enum);
550 hid_err(hdev,
"Invalid Physical device count\n");
558 hid_err(hdev,
"Failed to allocate memory for mfd cells\n");
563 hid_dbg(hdev,
"Report id:%x\n", report->
id);
564 field = report->
field[0];
570 hid_err(hdev,
"Failed MFD device name\n");
582 hid_dbg(hdev,
"Adding %s:%p\n", name, sd);
609 static void sensor_hub_remove(
struct hid_device *hdev)
615 hid_dbg(hdev,
" hardware removed\n");
621 spin_unlock_irqrestore(&data->
lock, flags);
626 hid_set_drvdata(hdev,
NULL);
647 static const struct hid_usage_id sensor_hub_grabbed_usages[] = {
652 static struct hid_driver sensor_hub_driver = {
653 .name =
"hid-sensor-hub",
654 .id_table = sensor_hub_devices,
655 .probe = sensor_hub_probe,
656 .remove = sensor_hub_remove,
657 .raw_event = sensor_hub_raw_event,
659 .suspend = sensor_hub_suspend,
660 .resume = sensor_hub_resume,
661 .reset_resume = sensor_hub_reset_resume,
665 static int __init sensor_hub_init(
void)
670 static void __exit sensor_hub_exit(
void)