This source file includes following definitions.
- icade_find_translation
- icade_event
- icade_input_mapping
- icade_input_mapped
1
2
3
4
5
6
7
8
9
10
11
12 #include <linux/device.h>
13 #include <linux/hid.h>
14 #include <linux/module.h>
15
16 #include "hid-ids.h"
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123 #define ICADE_MAX_USAGE 29
124
125 struct icade_key {
126 u16 to;
127 u8 press:1;
128 };
129
130 static const struct icade_key icade_usage_table[30] = {
131 [26] = { KEY_UP, 1 },
132 [8] = { KEY_UP, 0 },
133 [7] = { KEY_RIGHT, 1 },
134 [6] = { KEY_RIGHT, 0 },
135 [27] = { KEY_DOWN, 1 },
136 [29] = { KEY_DOWN, 0 },
137 [4] = { KEY_LEFT, 1 },
138 [20] = { KEY_LEFT, 0 },
139 [28] = { BTN_A, 1 },
140 [23] = { BTN_A, 0 },
141 [11] = { BTN_B, 1 },
142 [21] = { BTN_B, 0 },
143 [24] = { BTN_C, 1 },
144 [9] = { BTN_C, 0 },
145 [13] = { BTN_X, 1 },
146 [17] = { BTN_X, 0 },
147 [12] = { BTN_Y, 1 },
148 [16] = { BTN_Y, 0 },
149 [14] = { BTN_Z, 1 },
150 [19] = { BTN_Z, 0 },
151 [18] = { BTN_THUMBL, 1 },
152 [10] = { BTN_THUMBL, 0 },
153 [15] = { BTN_THUMBR, 1 },
154 [25] = { BTN_THUMBR, 0 },
155 };
156
157 static const struct icade_key *icade_find_translation(u16 from)
158 {
159 if (from > ICADE_MAX_USAGE)
160 return NULL;
161 return &icade_usage_table[from];
162 }
163
164 static int icade_event(struct hid_device *hdev, struct hid_field *field,
165 struct hid_usage *usage, __s32 value)
166 {
167 const struct icade_key *trans;
168
169 if (!(hdev->claimed & HID_CLAIMED_INPUT) || !field->hidinput ||
170 !usage->type)
171 return 0;
172
173
174 if (!value)
175 return 1;
176
177 trans = icade_find_translation(usage->hid & HID_USAGE);
178
179 if (!trans)
180 return 1;
181
182 input_event(field->hidinput->input, usage->type,
183 trans->to, trans->press);
184
185 return 1;
186 }
187
188 static int icade_input_mapping(struct hid_device *hdev, struct hid_input *hi,
189 struct hid_field *field, struct hid_usage *usage,
190 unsigned long **bit, int *max)
191 {
192 const struct icade_key *trans;
193
194 if ((usage->hid & HID_USAGE_PAGE) == HID_UP_KEYBOARD) {
195 trans = icade_find_translation(usage->hid & HID_USAGE);
196
197 if (!trans)
198 return -1;
199
200 hid_map_usage(hi, usage, bit, max, EV_KEY, trans->to);
201 set_bit(trans->to, hi->input->keybit);
202
203 return 1;
204 }
205
206
207 return -1;
208
209 }
210
211 static int icade_input_mapped(struct hid_device *hdev, struct hid_input *hi,
212 struct hid_field *field, struct hid_usage *usage,
213 unsigned long **bit, int *max)
214 {
215 if (usage->type == EV_KEY)
216 set_bit(usage->type, hi->input->evbit);
217
218 return -1;
219 }
220
221 static const struct hid_device_id icade_devices[] = {
222 { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_ION, USB_DEVICE_ID_ICADE) },
223
224 { }
225 };
226 MODULE_DEVICE_TABLE(hid, icade_devices);
227
228 static struct hid_driver icade_driver = {
229 .name = "icade",
230 .id_table = icade_devices,
231 .event = icade_event,
232 .input_mapped = icade_input_mapped,
233 .input_mapping = icade_input_mapping,
234 };
235 module_hid_driver(icade_driver);
236
237 MODULE_LICENSE("GPL");
238 MODULE_AUTHOR("Bastien Nocera <hadess@hadess.net>");
239 MODULE_DESCRIPTION("ION iCade input driver");