diff options
author | Petri Gynther <pgynther@google.com> | 2015-10-26 04:15:58 -0400 |
---|---|---|
committer | Dmitry Torokhov <dmitry.torokhov@gmail.com> | 2015-10-26 04:39:08 -0400 |
commit | 34fc1322e7aaaa74f3f9e5194a2e85bae522d3c2 (patch) | |
tree | 82b378d82376009fa137c8b7ded6b90df4df619a | |
parent | 05f216ddca08728fcb7b1eb3808159b81b48c124 (diff) |
HID: hid-gfrm: Google Fiber TV Box remote controls
Add HID driver for Google Fiber TV Box remote controls
Signed-off-by: Petri Gynther <pgynther@google.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
-rw-r--r-- | drivers/hid/Kconfig | 6 | ||||
-rw-r--r-- | drivers/hid/Makefile | 1 | ||||
-rw-r--r-- | drivers/hid/hid-gfrm.c | 158 |
3 files changed, 165 insertions, 0 deletions
diff --git a/drivers/hid/Kconfig b/drivers/hid/Kconfig index 6ab51ae3c39d..7245b7f8767f 100644 --- a/drivers/hid/Kconfig +++ b/drivers/hid/Kconfig | |||
@@ -257,6 +257,12 @@ config HID_GEMBIRD | |||
257 | ---help--- | 257 | ---help--- |
258 | Support for Gembird JPD-DualForce 2. | 258 | Support for Gembird JPD-DualForce 2. |
259 | 259 | ||
260 | config HID_GFRM | ||
261 | tristate "Google Fiber TV Box remote control support" | ||
262 | depends on HID | ||
263 | ---help--- | ||
264 | Support for Google Fiber TV Box remote controls | ||
265 | |||
260 | config HID_HOLTEK | 266 | config HID_HOLTEK |
261 | tristate "Holtek HID devices" | 267 | tristate "Holtek HID devices" |
262 | depends on USB_HID | 268 | depends on USB_HID |
diff --git a/drivers/hid/Makefile b/drivers/hid/Makefile index e6441bc7dae4..571d176d22df 100644 --- a/drivers/hid/Makefile +++ b/drivers/hid/Makefile | |||
@@ -37,6 +37,7 @@ obj-$(CONFIG_HID_ELECOM) += hid-elecom.o | |||
37 | obj-$(CONFIG_HID_ELO) += hid-elo.o | 37 | obj-$(CONFIG_HID_ELO) += hid-elo.o |
38 | obj-$(CONFIG_HID_EZKEY) += hid-ezkey.o | 38 | obj-$(CONFIG_HID_EZKEY) += hid-ezkey.o |
39 | obj-$(CONFIG_HID_GEMBIRD) += hid-gembird.o | 39 | obj-$(CONFIG_HID_GEMBIRD) += hid-gembird.o |
40 | obj-$(CONFIG_HID_GFRM) += hid-gfrm.o | ||
40 | obj-$(CONFIG_HID_GT683R) += hid-gt683r.o | 41 | obj-$(CONFIG_HID_GT683R) += hid-gt683r.o |
41 | obj-$(CONFIG_HID_GYRATION) += hid-gyration.o | 42 | obj-$(CONFIG_HID_GYRATION) += hid-gyration.o |
42 | obj-$(CONFIG_HID_HOLTEK) += hid-holtek-kbd.o | 43 | obj-$(CONFIG_HID_HOLTEK) += hid-holtek-kbd.o |
diff --git a/drivers/hid/hid-gfrm.c b/drivers/hid/hid-gfrm.c new file mode 100644 index 000000000000..4d7b7e7f0792 --- /dev/null +++ b/drivers/hid/hid-gfrm.c | |||
@@ -0,0 +1,158 @@ | |||
1 | /* | ||
2 | * HID driver for Google Fiber TV Box remote controls | ||
3 | * | ||
4 | * Copyright (c) 2014-2015 Google Inc. | ||
5 | * | ||
6 | * Author: Petri Gynther <pgynther@google.com> | ||
7 | * | ||
8 | * This program is free software; you can redistribute it and/or modify it | ||
9 | * under the terms of the GNU General Public License as published by the Free | ||
10 | * Software Foundation; either version 2 of the License, or (at your option) | ||
11 | * any later version. | ||
12 | */ | ||
13 | #include <linux/device.h> | ||
14 | #include <linux/hid.h> | ||
15 | #include <linux/input.h> | ||
16 | #include <linux/module.h> | ||
17 | |||
18 | #include "hid-ids.h" | ||
19 | |||
20 | #define GFRM100 1 /* Google Fiber GFRM100 (Bluetooth classic) */ | ||
21 | #define GFRM200 2 /* Google Fiber GFRM200 (Bluetooth LE) */ | ||
22 | |||
23 | #define GFRM100_SEARCH_KEY_REPORT_ID 0xF7 | ||
24 | #define GFRM100_SEARCH_KEY_DOWN 0x0 | ||
25 | #define GFRM100_SEARCH_KEY_AUDIO_DATA 0x1 | ||
26 | #define GFRM100_SEARCH_KEY_UP 0x2 | ||
27 | |||
28 | static u8 search_key_dn[3] = {0x40, 0x21, 0x02}; | ||
29 | static u8 search_key_up[3] = {0x40, 0x00, 0x00}; | ||
30 | |||
31 | static int gfrm_input_mapping(struct hid_device *hdev, struct hid_input *hi, | ||
32 | struct hid_field *field, struct hid_usage *usage, | ||
33 | unsigned long **bit, int *max) | ||
34 | { | ||
35 | unsigned long hdev_type = (unsigned long) hid_get_drvdata(hdev); | ||
36 | |||
37 | if (hdev_type == GFRM100) { | ||
38 | if (usage->hid == (HID_UP_CONSUMER | 0x4)) { | ||
39 | /* Consumer.0004 -> KEY_INFO */ | ||
40 | hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_INFO); | ||
41 | return 1; | ||
42 | } | ||
43 | |||
44 | if (usage->hid == (HID_UP_CONSUMER | 0x41)) { | ||
45 | /* Consumer.0041 -> KEY_OK */ | ||
46 | hid_map_usage_clear(hi, usage, bit, max, EV_KEY, KEY_OK); | ||
47 | return 1; | ||
48 | } | ||
49 | } | ||
50 | |||
51 | return 0; | ||
52 | } | ||
53 | |||
54 | static int gfrm_raw_event(struct hid_device *hdev, struct hid_report *report, | ||
55 | u8 *data, int size) | ||
56 | { | ||
57 | unsigned long hdev_type = (unsigned long) hid_get_drvdata(hdev); | ||
58 | int ret = 0; | ||
59 | |||
60 | if (hdev_type != GFRM100) | ||
61 | return 0; | ||
62 | |||
63 | if (size < 2 || data[0] != GFRM100_SEARCH_KEY_REPORT_ID) | ||
64 | return 0; | ||
65 | |||
66 | /* | ||
67 | * Convert GFRM100 Search key reports into Consumer.0221 (Key.Search) | ||
68 | * reports. Ignore audio data. | ||
69 | */ | ||
70 | switch (data[1]) { | ||
71 | case GFRM100_SEARCH_KEY_DOWN: | ||
72 | ret = hid_report_raw_event(hdev, HID_INPUT_REPORT, search_key_dn, | ||
73 | sizeof(search_key_dn), 1); | ||
74 | break; | ||
75 | |||
76 | case GFRM100_SEARCH_KEY_AUDIO_DATA: | ||
77 | break; | ||
78 | |||
79 | case GFRM100_SEARCH_KEY_UP: | ||
80 | ret = hid_report_raw_event(hdev, HID_INPUT_REPORT, search_key_up, | ||
81 | sizeof(search_key_up), 1); | ||
82 | break; | ||
83 | |||
84 | default: | ||
85 | break; | ||
86 | } | ||
87 | |||
88 | return (ret < 0) ? ret : -1; | ||
89 | } | ||
90 | |||
91 | static void gfrm_input_configured(struct hid_device *hid, struct hid_input *hidinput) | ||
92 | { | ||
93 | /* | ||
94 | * Enable software autorepeat with: | ||
95 | * - repeat delay: 400 msec | ||
96 | * - repeat period: 100 msec | ||
97 | */ | ||
98 | input_enable_softrepeat(hidinput->input, 400, 100); | ||
99 | } | ||
100 | |||
101 | static int gfrm_probe(struct hid_device *hdev, const struct hid_device_id *id) | ||
102 | { | ||
103 | int ret; | ||
104 | |||
105 | hid_set_drvdata(hdev, (void *) id->driver_data); | ||
106 | |||
107 | ret = hid_parse(hdev); | ||
108 | if (ret) | ||
109 | goto done; | ||
110 | |||
111 | if (id->driver_data == GFRM100) { | ||
112 | /* | ||
113 | * GFRM100 HID Report Descriptor does not describe the Search | ||
114 | * key reports. Thus, we need to add it manually here, so that | ||
115 | * those reports reach gfrm_raw_event() from hid_input_report(). | ||
116 | */ | ||
117 | if (!hid_register_report(hdev, HID_INPUT_REPORT, | ||
118 | GFRM100_SEARCH_KEY_REPORT_ID)) { | ||
119 | ret = -ENOMEM; | ||
120 | goto done; | ||
121 | } | ||
122 | } | ||
123 | |||
124 | ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); | ||
125 | done: | ||
126 | return ret; | ||
127 | } | ||
128 | |||
129 | static void gfrm_remove(struct hid_device *hdev) | ||
130 | { | ||
131 | hid_hw_stop(hdev); | ||
132 | hid_set_drvdata(hdev, NULL); | ||
133 | } | ||
134 | |||
135 | static const struct hid_device_id gfrm_devices[] = { | ||
136 | { HID_BLUETOOTH_DEVICE(0x58, 0x2000), | ||
137 | .driver_data = GFRM100 }, | ||
138 | { HID_BLUETOOTH_DEVICE(0x471, 0x2210), | ||
139 | .driver_data = GFRM200 }, | ||
140 | { } | ||
141 | }; | ||
142 | MODULE_DEVICE_TABLE(hid, gfrm_devices); | ||
143 | |||
144 | static struct hid_driver gfrm_driver = { | ||
145 | .name = "gfrm", | ||
146 | .id_table = gfrm_devices, | ||
147 | .probe = gfrm_probe, | ||
148 | .remove = gfrm_remove, | ||
149 | .input_mapping = gfrm_input_mapping, | ||
150 | .raw_event = gfrm_raw_event, | ||
151 | .input_configured = gfrm_input_configured, | ||
152 | }; | ||
153 | |||
154 | module_hid_driver(gfrm_driver); | ||
155 | |||
156 | MODULE_AUTHOR("Petri Gynther <pgynther@google.com>"); | ||
157 | MODULE_DESCRIPTION("Google Fiber TV Box remote control driver"); | ||
158 | MODULE_LICENSE("GPL"); | ||