aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hid/hid-input.c
diff options
context:
space:
mode:
authorJiri Slaby <jirislaby@gmail.com>2008-06-18 17:36:49 -0400
committerJiri Kosina <jkosina@suse.cz>2008-10-14 17:50:49 -0400
commit8c19a51591d06f5226499972567f528cf6066bb7 (patch)
treeacfa47c0cb371c8b87f7282d19c627e44032dbe2 /drivers/hid/hid-input.c
parentd458a9dfc4de24870b8c747484b1988726534bee (diff)
HID: move apple quirks
Move them from the core code to a separate driver. Signed-off-by: Jiri Slaby <jslaby@suse.cz> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Diffstat (limited to 'drivers/hid/hid-input.c')
-rw-r--r--drivers/hid/hid-input.c221
1 files changed, 1 insertions, 220 deletions
diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 4f2bac010f59..76ddf23f1965 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -32,11 +32,6 @@
32#include <linux/hid.h> 32#include <linux/hid.h>
33#include <linux/hid-debug.h> 33#include <linux/hid-debug.h>
34 34
35static int hid_apple_fnmode = 1;
36module_param_named(pb_fnmode, hid_apple_fnmode, int, 0644);
37MODULE_PARM_DESC(pb_fnmode,
38 "Mode of fn key on Apple keyboards (0 = disabled, 1 = fkeyslast, 2 = fkeysfirst)");
39
40#define unk KEY_UNKNOWN 35#define unk KEY_UNKNOWN
41 36
42static const unsigned char hid_keyboard[256] = { 37static const unsigned char hid_keyboard[256] = {
@@ -73,202 +68,6 @@ static const struct {
73#define map_key_clear(c) hid_map_usage_clear(hidinput, usage, &bit, \ 68#define map_key_clear(c) hid_map_usage_clear(hidinput, usage, &bit, \
74 &max, EV_KEY, (c)) 69 &max, EV_KEY, (c))
75 70
76#ifdef CONFIG_USB_HIDINPUT_POWERBOOK
77
78struct hidinput_key_translation {
79 u16 from;
80 u16 to;
81 u8 flags;
82};
83
84#define APPLE_FLAG_FKEY 0x01
85
86static struct hidinput_key_translation apple_fn_keys[] = {
87 { KEY_BACKSPACE, KEY_DELETE },
88 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
89 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
90 { KEY_F3, KEY_FN_F5, APPLE_FLAG_FKEY }, /* Exposé */
91 { KEY_F4, KEY_FN_F4, APPLE_FLAG_FKEY }, /* Dashboard */
92 { KEY_F5, KEY_KBDILLUMDOWN, APPLE_FLAG_FKEY },
93 { KEY_F6, KEY_KBDILLUMUP, APPLE_FLAG_FKEY },
94 { KEY_F7, KEY_PREVIOUSSONG, APPLE_FLAG_FKEY },
95 { KEY_F8, KEY_PLAYPAUSE, APPLE_FLAG_FKEY },
96 { KEY_F9, KEY_NEXTSONG, APPLE_FLAG_FKEY },
97 { KEY_F10, KEY_MUTE, APPLE_FLAG_FKEY },
98 { KEY_F11, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
99 { KEY_F12, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
100 { KEY_UP, KEY_PAGEUP },
101 { KEY_DOWN, KEY_PAGEDOWN },
102 { KEY_LEFT, KEY_HOME },
103 { KEY_RIGHT, KEY_END },
104 { }
105};
106
107static struct hidinput_key_translation powerbook_fn_keys[] = {
108 { KEY_BACKSPACE, KEY_DELETE },
109 { KEY_F1, KEY_BRIGHTNESSDOWN, APPLE_FLAG_FKEY },
110 { KEY_F2, KEY_BRIGHTNESSUP, APPLE_FLAG_FKEY },
111 { KEY_F3, KEY_MUTE, APPLE_FLAG_FKEY },
112 { KEY_F4, KEY_VOLUMEDOWN, APPLE_FLAG_FKEY },
113 { KEY_F5, KEY_VOLUMEUP, APPLE_FLAG_FKEY },
114 { KEY_F6, KEY_NUMLOCK, APPLE_FLAG_FKEY },
115 { KEY_F7, KEY_SWITCHVIDEOMODE, APPLE_FLAG_FKEY },
116 { KEY_F8, KEY_KBDILLUMTOGGLE, APPLE_FLAG_FKEY },
117 { KEY_F9, KEY_KBDILLUMDOWN, APPLE_FLAG_FKEY },
118 { KEY_F10, KEY_KBDILLUMUP, APPLE_FLAG_FKEY },
119 { KEY_UP, KEY_PAGEUP },
120 { KEY_DOWN, KEY_PAGEDOWN },
121 { KEY_LEFT, KEY_HOME },
122 { KEY_RIGHT, KEY_END },
123 { }
124};
125
126static struct hidinput_key_translation powerbook_numlock_keys[] = {
127 { KEY_J, KEY_KP1 },
128 { KEY_K, KEY_KP2 },
129 { KEY_L, KEY_KP3 },
130 { KEY_U, KEY_KP4 },
131 { KEY_I, KEY_KP5 },
132 { KEY_O, KEY_KP6 },
133 { KEY_7, KEY_KP7 },
134 { KEY_8, KEY_KP8 },
135 { KEY_9, KEY_KP9 },
136 { KEY_M, KEY_KP0 },
137 { KEY_DOT, KEY_KPDOT },
138 { KEY_SLASH, KEY_KPPLUS },
139 { KEY_SEMICOLON, KEY_KPMINUS },
140 { KEY_P, KEY_KPASTERISK },
141 { KEY_MINUS, KEY_KPEQUAL },
142 { KEY_0, KEY_KPSLASH },
143 { KEY_F6, KEY_NUMLOCK },
144 { KEY_KPENTER, KEY_KPENTER },
145 { KEY_BACKSPACE, KEY_BACKSPACE },
146 { }
147};
148
149static struct hidinput_key_translation apple_iso_keyboard[] = {
150 { KEY_GRAVE, KEY_102ND },
151 { KEY_102ND, KEY_GRAVE },
152 { }
153};
154
155static struct hidinput_key_translation *find_translation(struct hidinput_key_translation *table, u16 from)
156{
157 struct hidinput_key_translation *trans;
158
159 /* Look for the translation */
160 for (trans = table; trans->from; trans++)
161 if (trans->from == from)
162 return trans;
163
164 return NULL;
165}
166
167int hidinput_apple_event(struct hid_device *hid, struct input_dev *input,
168 struct hid_usage *usage, __s32 value)
169{
170 struct hidinput_key_translation *trans;
171
172 if (usage->code == KEY_FN) {
173 if (value) hid->quirks |= HID_QUIRK_APPLE_FN_ON;
174 else hid->quirks &= ~HID_QUIRK_APPLE_FN_ON;
175
176 input_event(input, usage->type, usage->code, value);
177
178 return 1;
179 }
180
181 if (hid_apple_fnmode) {
182 int do_translate;
183
184 trans = find_translation((hid->product < 0x220 ||
185 hid->product >= 0x300) ?
186 powerbook_fn_keys : apple_fn_keys,
187 usage->code);
188 if (trans) {
189 if (test_bit(usage->code, hid->apple_pressed_fn))
190 do_translate = 1;
191 else if (trans->flags & APPLE_FLAG_FKEY)
192 do_translate =
193 (hid_apple_fnmode == 2 && (hid->quirks & HID_QUIRK_APPLE_FN_ON)) ||
194 (hid_apple_fnmode == 1 && !(hid->quirks & HID_QUIRK_APPLE_FN_ON));
195 else
196 do_translate = (hid->quirks & HID_QUIRK_APPLE_FN_ON);
197
198 if (do_translate) {
199 if (value)
200 set_bit(usage->code, hid->apple_pressed_fn);
201 else
202 clear_bit(usage->code, hid->apple_pressed_fn);
203
204 input_event(input, usage->type, trans->to, value);
205
206 return 1;
207 }
208 }
209
210 if (hid->quirks & HID_QUIRK_APPLE_NUMLOCK_EMULATION && (
211 test_bit(usage->code, hid->pb_pressed_numlock) ||
212 test_bit(LED_NUML, input->led))) {
213 trans = find_translation(powerbook_numlock_keys, usage->code);
214
215 if (trans) {
216 if (value)
217 set_bit(usage->code, hid->pb_pressed_numlock);
218 else
219 clear_bit(usage->code, hid->pb_pressed_numlock);
220
221 input_event(input, usage->type, trans->to, value);
222 }
223
224 return 1;
225 }
226 }
227
228 if (hid->quirks & HID_QUIRK_APPLE_ISO_KEYBOARD) {
229 trans = find_translation(apple_iso_keyboard, usage->code);
230 if (trans) {
231 input_event(input, usage->type, trans->to, value);
232 return 1;
233 }
234 }
235
236 return 0;
237}
238
239static void hidinput_apple_setup(struct input_dev *input)
240{
241 struct hidinput_key_translation *trans;
242
243 set_bit(KEY_NUMLOCK, input->keybit);
244
245 /* Enable all needed keys */
246 for (trans = apple_fn_keys; trans->from; trans++)
247 set_bit(trans->to, input->keybit);
248
249 for (trans = powerbook_fn_keys; trans->from; trans++)
250 set_bit(trans->to, input->keybit);
251
252 for (trans = powerbook_numlock_keys; trans->from; trans++)
253 set_bit(trans->to, input->keybit);
254
255 for (trans = apple_iso_keyboard; trans->from; trans++)
256 set_bit(trans->to, input->keybit);
257
258}
259#else
260inline int hidinput_apple_event(struct hid_device *hid,
261 struct input_dev *input,
262 struct hid_usage *usage, __s32 value)
263{
264 return 0;
265}
266
267static inline void hidinput_apple_setup(struct input_dev *input)
268{
269}
270#endif
271
272static inline int match_scancode(int code, int scancode) 71static inline int match_scancode(int code, int scancode)
273{ 72{
274 if (scancode == 0) 73 if (scancode == 0)
@@ -696,16 +495,7 @@ static void hidinput_configure_usage(struct hid_input *hidinput, struct hid_fiel
696 case HID_UP_CUSTOM: /* Reported on Logitech and Apple USB keyboards */ 495 case HID_UP_CUSTOM: /* Reported on Logitech and Apple USB keyboards */
697 496
698 set_bit(EV_REP, input->evbit); 497 set_bit(EV_REP, input->evbit);
699 switch(usage->hid & HID_USAGE) { 498 goto ignore;
700 case 0x003:
701 /* The fn key on Apple USB keyboards */
702 map_key_clear(KEY_FN);
703 hidinput_apple_setup(input);
704 break;
705
706 default: goto ignore;
707 }
708 break;
709 499
710 case HID_UP_LOGIVENDOR: 500 case HID_UP_LOGIVENDOR:
711 501
@@ -742,15 +532,6 @@ mapped:
742 hidinput, field, usage, &bit, &max) < 0) 532 hidinput, field, usage, &bit, &max) < 0)
743 goto ignore; 533 goto ignore;
744 534
745 if (device->quirks & HID_QUIRK_MIGHTYMOUSE) {
746 if (usage->hid == HID_GD_Z)
747 map_rel(REL_HWHEEL);
748 else if (usage->code == BTN_1)
749 map_key(BTN_2);
750 else if (usage->code == BTN_2)
751 map_key(BTN_1);
752 }
753
754 if ((device->quirks & (HID_QUIRK_2WHEEL_MOUSE_HACK_7 | HID_QUIRK_2WHEEL_MOUSE_HACK_5 | 535 if ((device->quirks & (HID_QUIRK_2WHEEL_MOUSE_HACK_7 | HID_QUIRK_2WHEEL_MOUSE_HACK_5 |
755 HID_QUIRK_2WHEEL_MOUSE_HACK_B8)) && (usage->type == EV_REL) && 536 HID_QUIRK_2WHEEL_MOUSE_HACK_B8)) && (usage->type == EV_REL) &&
756 (usage->code == REL_WHEEL)) 537 (usage->code == REL_WHEEL))