summaryrefslogtreecommitdiff
blob: e2fbf9200e8c3445d5237e6a555c6f0cc50569d0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
From: Nicolas Boichat <nicolas@boichat.ch>


---

 drivers/hid/hid-input.c         |   48 +++++++++++++++++++++++++++++++++---
 drivers/hid/usbhid/hid-quirks.c |   52 +++++++++++++++++++++++++++++++++++++++
 include/linux/hid.h             |    1 +
 3 files changed, 97 insertions(+), 4 deletions(-)


diff --git a/drivers/hid/hid-input.c b/drivers/hid/hid-input.c
index 0b27da7..a39de6c 100644
--- a/drivers/hid/hid-input.c
+++ b/drivers/hid/hid-input.c
@@ -119,6 +119,30 @@ static struct hidinput_key_translation powerbook_fn_keys[] = {
 	{ }
 };
 
+static struct hidinput_key_translation apple_keyboard_fn_keys[] = {
+       { KEY_BACKSPACE, KEY_DELETE },
+	{ KEY_F1,	KEY_BRIGHTNESSDOWN,	POWERBOOK_FLAG_FKEY },
+	{ KEY_F2,	KEY_BRIGHTNESSUP,	POWERBOOK_FLAG_FKEY },
+	{ KEY_F3,	KEY_CYCLEWINDOWS,	POWERBOOK_FLAG_FKEY },
+	{ KEY_F4,	KEY_CONFIG,		POWERBOOK_FLAG_FKEY },
+	{ KEY_F7,	KEY_PREVIOUSSONG,	POWERBOOK_FLAG_FKEY },
+	{ KEY_F8,	KEY_PLAYPAUSE,		POWERBOOK_FLAG_FKEY },
+	{ KEY_F9,	KEY_NEXTSONG,		POWERBOOK_FLAG_FKEY },
+	{ KEY_F10,	KEY_MUTE,		POWERBOOK_FLAG_FKEY },
+	{ KEY_F11,	KEY_VOLUMEDOWN,		POWERBOOK_FLAG_FKEY },
+	{ KEY_F12,	KEY_VOLUMEUP,		POWERBOOK_FLAG_FKEY },
+       { KEY_UP,       KEY_PAGEUP },
+       { KEY_DOWN,     KEY_PAGEDOWN },
+       { KEY_LEFT,     KEY_HOME },
+       { KEY_RIGHT,    KEY_END },
+	{ }
+};
+
+static struct hidinput_key_translation apple_keyboard[] = {
+        { KEY_VOLUMEUP,	KEY_EJECTCD },
+        { }
+};
+
 static struct hidinput_key_translation powerbook_numlock_keys[] = {
 	{ KEY_J,        KEY_KP1 },
 	{ KEY_K,        KEY_KP2 },
@@ -176,8 +200,10 @@ static int hidinput_pb_event(struct hid_device *hid, struct input_dev *input,
 
 	if (hid_pb_fnmode) {
 		int do_translate;
-
-		trans = find_translation(powerbook_fn_keys, usage->code);
+		if (hid->quirks & HID_QUIRK_APPLE_KEYBOARD)
+			trans = find_translation(apple_keyboard_fn_keys, usage->code);
+		else 
+			trans = find_translation(powerbook_fn_keys, usage->code);
 		if (trans) {
 			if (test_bit(usage->code, hid->pb_pressed_fn))
 				do_translate = 1;
@@ -200,8 +226,8 @@ static int hidinput_pb_event(struct hid_device *hid, struct input_dev *input,
 			}
 		}
 
-		if (test_bit(usage->code, hid->pb_pressed_numlock) ||
-				test_bit(LED_NUML, input->led)) {
+		if (!(hid->quirks & HID_QUIRK_APPLE_KEYBOARD) && (test_bit(usage->code, hid->pb_pressed_numlock) ||
+				test_bit(LED_NUML, input->led))) {
 			trans = find_translation(powerbook_numlock_keys, usage->code);
 
 			if (trans) {
@@ -217,6 +243,14 @@ static int hidinput_pb_event(struct hid_device *hid, struct input_dev *input,
 		}
 	}
 
+	if (hid->quirks & HID_QUIRK_APPLE_KEYBOARD) {
+		trans = find_translation(apple_keyboard, usage->code);
+		if (trans) {
+			input_event(input, usage->type, trans->to, value);
+			return 1;
+		}
+	}
+
 	if (hid->quirks & HID_QUIRK_POWERBOOK_ISO_KEYBOARD) {
 		trans = find_translation(powerbook_iso_keyboard, usage->code);
 		if (trans) {
@@ -241,6 +275,12 @@ static void hidinput_pb_setup(struct input_dev *input)
 	for (trans = powerbook_numlock_keys; trans->from; trans++)
 		set_bit(trans->to, input->keybit);
 
+	for (trans = apple_keyboard_fn_keys; trans->from; trans++)
+		set_bit(trans->to, input->keybit);
+
+	for (trans = apple_keyboard; trans->from; trans++)
+		set_bit(trans->to, input->keybit);
+
 	for (trans = powerbook_iso_keyboard; trans->from; trans++)
 		set_bit(trans->to, input->keybit);
 
diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c
index a255285..8d21c83 100644
--- a/drivers/hid/usbhid/hid-quirks.c
+++ b/drivers/hid/usbhid/hid-quirks.c
@@ -59,6 +59,32 @@
 #define USB_DEVICE_ID_APPLE_GEYSER4_ANSI	0x021a
 #define USB_DEVICE_ID_APPLE_GEYSER4_ISO	0x021b
 #define USB_DEVICE_ID_APPLE_GEYSER4_JIS	0x021c
+
+/* Apple 2007 Wired keyboards */
+#define USB_DEVICE_ID_APPLE_KEYBOARD_ANSI	0x0220
+#define USB_DEVICE_ID_APPLE_KEYBOARD_ISO	0x0221
+#define USB_DEVICE_ID_APPLE_KEYBOARD_JIS	0x0222
+
+/* macbook3,1 keyboards */
+#define USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI    0x0229
+#define USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO     0x022a
+#define USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS     0x022b
+
+/* Apple WellSpring keyboard + trackpad */
+#define USB_PRODUCT_ID_WELLSPRING_ANSI   0x0223
+#define USB_PRODUCT_ID_WELLSPRING_ISO    0x0224
+#define USB_PRODUCT_ID_WELLSPRING_JIS    0x0225
+
+/* Apple WellSpring II keyboard + trackpad */
+#define USB_PRODUCT_ID_WELLSPRING2_ANSI   0x0230
+#define USB_PRODUCT_ID_WELLSPRING2_ISO    0x0231
+#define USB_PRODUCT_ID_WELLSPRING2_JIS    0x0232
+
+/* Apple 2007 Wireless keyboards */
+#define USB_DEVICE_ID_APPLE_WIRELESS_KEYBOARD_ANSI	0x022c
+#define USB_DEVICE_ID_APPLE_WIRELESS_KEYBOARD_ISO	0x022d
+#define USB_DEVICE_ID_APPLE_WIRELESS_KEYBOARD_JIS	0x022e
+
 #define USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY	0x030a
 #define USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY	0x030b
 #define USB_DEVICE_ID_APPLE_IRCONTROL4	0x8242
@@ -551,6 +577,32 @@ static const struct hid_blacklist {
 	{ USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ANSI, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
 	{ USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE | HID_QUIRK_POWERBOOK_ISO_KEYBOARD},
 	{ USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_JIS, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
+
+	/* Apple 2007 Wired keyboards */
+	{ USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_KEYBOARD_ANSI, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE | HID_QUIRK_APPLE_KEYBOARD},
+	{ USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_KEYBOARD_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE | HID_QUIRK_APPLE_KEYBOARD | HID_QUIRK_POWERBOOK_ISO_KEYBOARD},
+	{ USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_KEYBOARD_JIS, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE | HID_QUIRK_APPLE_KEYBOARD},
+
+	/* macbook3,1 keyboards */
+       { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ANSI, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE | HID_QUIRK_APPLE_KEYBOARD},
+       { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE | HID_QUIRK_APPLE_KEYBOARD | HID_QUIRK_POWERBOOK_ISO_KEYBOARD},
+       { USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER4_HF_JIS, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE | HID_QUIRK_APPLE_KEYBOARD},
+
+	/* Apple 2007 Wireless keyboards */
+	{ USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WIRELESS_KEYBOARD_ANSI, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE | HID_QUIRK_APPLE_KEYBOARD},
+	{ USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WIRELESS_KEYBOARD_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE | HID_QUIRK_APPLE_KEYBOARD | HID_QUIRK_POWERBOOK_ISO_KEYBOARD},
+	{ USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_WIRELESS_KEYBOARD_JIS, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE | HID_QUIRK_APPLE_KEYBOARD},
+
+	/* Apple WellSpring keyboard + trackpad */
+        { USB_VENDOR_ID_APPLE, USB_PRODUCT_ID_WELLSPRING_ANSI, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_APPLE_KEYBOARD},
+        { USB_VENDOR_ID_APPLE, USB_PRODUCT_ID_WELLSPRING_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_APPLE_KEYBOARD | HID_QUIRK_POWERBOOK_ISO_KEYBOARD},
+        { USB_VENDOR_ID_APPLE, USB_PRODUCT_ID_WELLSPRING_JIS, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_APPLE_KEYBOARD},
+
+	/* Apple WellSpring II keyboard + trackpad */
+        { USB_VENDOR_ID_APPLE, USB_PRODUCT_ID_WELLSPRING2_ANSI, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_APPLE_KEYBOARD},
+        { USB_VENDOR_ID_APPLE, USB_PRODUCT_ID_WELLSPRING2_ISO, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_APPLE_KEYBOARD | HID_QUIRK_POWERBOOK_ISO_KEYBOARD},
+        { USB_VENDOR_ID_APPLE, USB_PRODUCT_ID_WELLSPRING2_JIS, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_APPLE_KEYBOARD},
+
 	{ USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
 	{ USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY, HID_QUIRK_POWERBOOK_HAS_FN | HID_QUIRK_IGNORE_MOUSE },
 
diff --git a/include/linux/hid.h b/include/linux/hid.h
index 6e35b92..04b26b5 100644
--- a/include/linux/hid.h
+++ b/include/linux/hid.h
@@ -281,6 +281,7 @@ struct hid_item {
 #define HID_QUIRK_LOGITECH_IGNORE_DOUBLED_WHEEL	0x00400000
 #define HID_QUIRK_LOGITECH_EXPANDED_KEYMAP	0x00800000
 #define HID_QUIRK_IGNORE_HIDINPUT		0x01000000
+#define HID_QUIRK_APPLE_KEYBOARD		0x02000000
 
 /*
  * Separate quirks for runtime report descriptor fixup