aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2010-03-01 13:38:09 -0500
committerLinus Torvalds <torvalds@linux-foundation.org>2010-03-01 13:38:09 -0500
commit8724fdb53d27d7b59b60c8a399cc67f9abfabb33 (patch)
treeda2de791ed4845780376a5e6f844ab69957d565f
parentbc535154137601400ffe44c2a7be047ca041fe06 (diff)
parent35858adbfca13678af99fb31618ef4428d6dedb0 (diff)
Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input
* 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/dtor/input: (62 commits) Input: atkbd - release previously reserved keycodes 248 - 254 Input: add KEY_WPS_BUTTON definition Input: ads7846 - add regulator support Input: winbond-cir - fix suspend/resume Input: gamecon - use pr_err() and friends Input: gamecon - constify some of the setup structures Input: gamecon - simplify pad type handling Input: gamecon - simplify coordinate calculation for PSX Input: gamecon - fix some formatting issues Input: gamecon - add rumble support for N64 pads Input: wacom - add device type to device name string Input: s3c24xx_ts - report touch only when stylus is down Input: s3c24xx_ts - re-enable IRQ on resume Input: wacom - constify product features data Input: wacom - use per-device instance of wacom_features Input: sh_keysc - enable building on SH-Mobile ARM Input: wacom - get features from driver info Input: rotary-encoder - set gpio direction for each requested gpio Input: sh_keysc - update the driver with mode 6 Input: sh_keysc - switch to using bitmaps ...
-rw-r--r--Documentation/feature-removal-schedule.txt23
-rw-r--r--Documentation/input/sentelic.txt124
-rw-r--r--arch/arm/mach-ep93xx/include/mach/ep93xx_keypad.h14
-rw-r--r--drivers/char/keyboard.c29
-rw-r--r--drivers/input/evdev.c2
-rw-r--r--drivers/input/gameport/emu10k1-gp.c2
-rw-r--r--drivers/input/gameport/fm801-gp.c2
-rw-r--r--drivers/input/gameport/gameport.c98
-rw-r--r--drivers/input/gameport/ns558.c2
-rw-r--r--drivers/input/input.c90
-rw-r--r--drivers/input/joydev.c34
-rw-r--r--drivers/input/joystick/Kconfig1
-rw-r--r--drivers/input/joystick/gamecon.c664
-rw-r--r--drivers/input/joystick/xpad.c253
-rw-r--r--drivers/input/keyboard/Kconfig33
-rw-r--r--drivers/input/keyboard/Makefile1
-rw-r--r--drivers/input/keyboard/adp5588-keys.c6
-rw-r--r--drivers/input/keyboard/atkbd.c309
-rw-r--r--drivers/input/keyboard/ep93xx_keypad.c40
-rw-r--r--drivers/input/keyboard/gpio_keys.c318
-rw-r--r--drivers/input/keyboard/imx_keypad.c594
-rw-r--r--drivers/input/keyboard/qt2160.c2
-rw-r--r--drivers/input/keyboard/sh_keysc.c145
-rw-r--r--drivers/input/misc/apanel.c2
-rw-r--r--drivers/input/misc/rotary_encoder.c14
-rw-r--r--drivers/input/misc/uinput.c4
-rw-r--r--drivers/input/misc/winbond-cir.c213
-rw-r--r--drivers/input/mouse/hgpk.c4
-rw-r--r--drivers/input/serio/pcips2.c2
-rw-r--r--drivers/input/serio/serio.c131
-rw-r--r--drivers/input/serio/xilinx_ps2.c6
-rw-r--r--drivers/input/tablet/gtco.c2
-rw-r--r--drivers/input/tablet/wacom.h5
-rw-r--r--drivers/input/tablet/wacom_sys.c70
-rw-r--r--drivers/input/tablet/wacom_wac.c408
-rw-r--r--drivers/input/tablet/wacom_wac.h17
-rw-r--r--drivers/input/touchscreen/Kconfig6
-rw-r--r--drivers/input/touchscreen/ads7846.c28
-rw-r--r--drivers/input/touchscreen/elo.c225
-rw-r--r--drivers/input/touchscreen/mainstone-wm97xx.c3
-rw-r--r--drivers/input/touchscreen/s3c2410_ts.c31
-rw-r--r--drivers/input/touchscreen/tsc2007.c2
-rw-r--r--drivers/input/touchscreen/usbtouchscreen.c317
-rw-r--r--drivers/input/touchscreen/zylonite-wm97xx.c3
-rw-r--r--drivers/input/xen-kbdfront.c2
-rw-r--r--drivers/macintosh/Kconfig7
-rw-r--r--drivers/macintosh/mac_hid.c266
-rw-r--r--include/linux/gameport.h1
-rw-r--r--include/linux/gpio_keys.h1
-rw-r--r--include/linux/input.h17
-rw-r--r--include/linux/input/sh_keysc.h7
-rw-r--r--include/linux/kbd_kern.h3
-rw-r--r--include/linux/serio.h1
53 files changed, 3250 insertions, 1334 deletions
diff --git a/Documentation/feature-removal-schedule.txt b/Documentation/feature-removal-schedule.txt
index ea401495528d..732b1fa48cf2 100644
--- a/Documentation/feature-removal-schedule.txt
+++ b/Documentation/feature-removal-schedule.txt
@@ -538,3 +538,26 @@ Why: Duplicate functionality with the gspca_zc3xx driver, zc0301 only
538 sensors) wich are also supported by the gspca_zc3xx driver 538 sensors) wich are also supported by the gspca_zc3xx driver
539 (which supports 53 USB-ID's in total) 539 (which supports 53 USB-ID's in total)
540Who: Hans de Goede <hdegoede@redhat.com> 540Who: Hans de Goede <hdegoede@redhat.com>
541
542----------------------------
543
544What: corgikbd, spitzkbd, tosakbd driver
545When: 2.6.35
546Files: drivers/input/keyboard/{corgi,spitz,tosa}kbd.c
547Why: We now have a generic GPIO based matrix keyboard driver that
548 are fully capable of handling all the keys on these devices.
549 The original drivers manipulate the GPIO registers directly
550 and so are difficult to maintain.
551Who: Eric Miao <eric.y.miao@gmail.com>
552
553----------------------------
554
555What: corgi_ssp and corgi_ts driver
556When: 2.6.35
557Files: arch/arm/mach-pxa/corgi_ssp.c, drivers/input/touchscreen/corgi_ts.c
558Why: The corgi touchscreen is now deprecated in favour of the generic
559 ads7846.c driver. The noise reduction technique used in corgi_ts.c,
560 that's to wait till vsync before ADC sampling, is also integrated into
561 ads7846 driver now. Provided that the original driver is not generic
562 and is difficult to maintain, it will be removed later.
563Who: Eric Miao <eric.y.miao@gmail.com>
diff --git a/Documentation/input/sentelic.txt b/Documentation/input/sentelic.txt
index f7160a2fb6a2..b35affd5c649 100644
--- a/Documentation/input/sentelic.txt
+++ b/Documentation/input/sentelic.txt
@@ -1,5 +1,5 @@
1Copyright (C) 2002-2008 Sentelic Corporation. 1Copyright (C) 2002-2010 Sentelic Corporation.
2Last update: Oct-31-2008 2Last update: Jan-13-2010
3 3
4============================================================================== 4==============================================================================
5* Finger Sensing Pad Intellimouse Mode(scrolling wheel, 4th and 5th buttons) 5* Finger Sensing Pad Intellimouse Mode(scrolling wheel, 4th and 5th buttons)
@@ -44,7 +44,7 @@ B) MSID 6: Horizontal and Vertical scrolling.
44Packet 1 44Packet 1
45 Bit 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 45 Bit 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
46BYTE |---------------|BYTE |---------------|BYTE|---------------|BYTE|---------------| 46BYTE |---------------|BYTE |---------------|BYTE|---------------|BYTE|---------------|
47 1 |Y|X|y|x|1|M|R|L| 2 |X|X|X|X|X|X|X|X| 3 |Y|Y|Y|Y|Y|Y|Y|Y| 4 | | |B|F|l|r|u|d| 47 1 |Y|X|y|x|1|M|R|L| 2 |X|X|X|X|X|X|X|X| 3 |Y|Y|Y|Y|Y|Y|Y|Y| 4 | | |B|F|r|l|u|d|
48 |---------------| |---------------| |---------------| |---------------| 48 |---------------| |---------------| |---------------| |---------------|
49 49
50Byte 1: Bit7 => Y overflow 50Byte 1: Bit7 => Y overflow
@@ -59,15 +59,15 @@ Byte 2: X Movement(9-bit 2's complement integers)
59Byte 3: Y Movement(9-bit 2's complement integers) 59Byte 3: Y Movement(9-bit 2's complement integers)
60Byte 4: Bit0 => the Vertical scrolling movement downward. 60Byte 4: Bit0 => the Vertical scrolling movement downward.
61 Bit1 => the Vertical scrolling movement upward. 61 Bit1 => the Vertical scrolling movement upward.
62 Bit2 => the Vertical scrolling movement rightward. 62 Bit2 => the Horizontal scrolling movement leftward.
63 Bit3 => the Vertical scrolling movement leftward. 63 Bit3 => the Horizontal scrolling movement rightward.
64 Bit4 => 1 = 4th mouse button is pressed, Forward one page. 64 Bit4 => 1 = 4th mouse button is pressed, Forward one page.
65 0 = 4th mouse button is not pressed. 65 0 = 4th mouse button is not pressed.
66 Bit5 => 1 = 5th mouse button is pressed, Backward one page. 66 Bit5 => 1 = 5th mouse button is pressed, Backward one page.
67 0 = 5th mouse button is not pressed. 67 0 = 5th mouse button is not pressed.
68 68
69C) MSID 7: 69C) MSID 7:
70# FSP uses 2 packets(8 Bytes) data to represent Absolute Position 70# FSP uses 2 packets (8 Bytes) to represent Absolute Position.
71 so we have PACKET NUMBER to identify packets. 71 so we have PACKET NUMBER to identify packets.
72 If PACKET NUMBER is 0, the packet is Packet 1. 72 If PACKET NUMBER is 0, the packet is Packet 1.
73 If PACKET NUMBER is 1, the packet is Packet 2. 73 If PACKET NUMBER is 1, the packet is Packet 2.
@@ -129,7 +129,7 @@ Byte 3: Message Type => 0x00 (Disabled)
129Byte 4: Bit7~Bit0 => Don't Care 129Byte 4: Bit7~Bit0 => Don't Care
130 130
131============================================================================== 131==============================================================================
132* Absolute position for STL3888-A0. 132* Absolute position for STL3888-Ax.
133============================================================================== 133==============================================================================
134Packet 1 (ABSOLUTE POSITION) 134Packet 1 (ABSOLUTE POSITION)
135 Bit 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 135 Bit 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
@@ -179,14 +179,14 @@ Byte 4: Bit1~Bit0 => Y coordinate (xpos[1:0])
179 Bit5~Bit4 => y2_g 179 Bit5~Bit4 => y2_g
180 Bit7~Bit6 => x2_g 180 Bit7~Bit6 => x2_g
181 181
182Notify Packet for STL3888-A0 182Notify Packet for STL3888-Ax
183 Bit 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 183 Bit 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
184BYTE |---------------|BYTE |---------------|BYTE|---------------|BYTE|---------------| 184BYTE |---------------|BYTE |---------------|BYTE|---------------|BYTE|---------------|
185 1 |1|0|1|P|1|M|R|L| 2 |C|C|C|C|C|C|C|C| 3 |0|0|F|F|0|0|0|i| 4 |r|l|d|u|0|0|0|0| 185 1 |1|0|1|P|1|M|R|L| 2 |C|C|C|C|C|C|C|C| 3 |0|0|F|F|0|0|0|i| 4 |r|l|d|u|0|0|0|0|
186 |---------------| |---------------| |---------------| |---------------| 186 |---------------| |---------------| |---------------| |---------------|
187 187
188Byte 1: Bit7~Bit6 => 00, Normal data packet 188Byte 1: Bit7~Bit6 => 00, Normal data packet
189 => 01, Absolute coordination packet 189 => 01, Absolute coordinates packet
190 => 10, Notify packet 190 => 10, Notify packet
191 Bit5 => 1 191 Bit5 => 1
192 Bit4 => when in absolute coordinates mode (valid when EN_PKT_GO is 1): 192 Bit4 => when in absolute coordinates mode (valid when EN_PKT_GO is 1):
@@ -205,15 +205,106 @@ Byte 4: Bit7 => scroll right button
205 Bit6 => scroll left button 205 Bit6 => scroll left button
206 Bit5 => scroll down button 206 Bit5 => scroll down button
207 Bit4 => scroll up button 207 Bit4 => scroll up button
208 * Note that if gesture and additional button (Bit4~Bit7) 208 * Note that if gesture and additional buttoni (Bit4~Bit7)
209 happen at the same time, the button information will not 209 happen at the same time, the button information will not
210 be sent. 210 be sent.
211 Bit3~Bit0 => Reserved
212
213Sample sequence of Multi-finger, Multi-coordinate mode:
214
215 notify packet (valid bit == 1), abs pkt 1, abs pkt 2, abs pkt 1,
216 abs pkt 2, ..., notify packet (valid bit == 0)
217
218==============================================================================
219* Absolute position for STL3888-B0.
220==============================================================================
221Packet 1(ABSOLUTE POSITION)
222 Bit 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
223BYTE |---------------|BYTE |---------------|BYTE|---------------|BYTE|---------------|
224 1 |0|1|V|F|1|0|R|L| 2 |X|X|X|X|X|X|X|X| 3 |Y|Y|Y|Y|Y|Y|Y|Y| 4 |r|l|u|d|X|X|Y|Y|
225 |---------------| |---------------| |---------------| |---------------|
226
227Byte 1: Bit7~Bit6 => 00, Normal data packet
228 => 01, Absolute coordinates packet
229 => 10, Notify packet
230 Bit5 => Valid bit, 0 means that the coordinate is invalid or finger up.
231 When both fingers are up, the last two reports have zero valid
232 bit.
233 Bit4 => finger up/down information. 1: finger down, 0: finger up.
234 Bit3 => 1
235 Bit2 => finger index, 0 is the first finger, 1 is the second finger.
236 Bit1 => Right Button, 1 is pressed, 0 is not pressed.
237 Bit0 => Left Button, 1 is pressed, 0 is not pressed.
238Byte 2: X coordinate (xpos[9:2])
239Byte 3: Y coordinate (ypos[9:2])
240Byte 4: Bit1~Bit0 => Y coordinate (xpos[1:0])
241 Bit3~Bit2 => X coordinate (ypos[1:0])
242 Bit4 => scroll down button
243 Bit5 => scroll up button
244 Bit6 => scroll left button
245 Bit7 => scroll right button
246
247Packet 2 (ABSOLUTE POSITION)
248 Bit 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
249BYTE |---------------|BYTE |---------------|BYTE|---------------|BYTE|---------------|
250 1 |0|1|V|F|1|1|R|L| 2 |X|X|X|X|X|X|X|X| 3 |Y|Y|Y|Y|Y|Y|Y|Y| 4 |r|l|u|d|X|X|Y|Y|
251 |---------------| |---------------| |---------------| |---------------|
252
253Byte 1: Bit7~Bit6 => 00, Normal data packet
254 => 01, Absolute coordination packet
255 => 10, Notify packet
256 Bit5 => Valid bit, 0 means that the coordinate is invalid or finger up.
257 When both fingers are up, the last two reports have zero valid
258 bit.
259 Bit4 => finger up/down information. 1: finger down, 0: finger up.
260 Bit3 => 1
261 Bit2 => finger index, 0 is the first finger, 1 is the second finger.
262 Bit1 => Right Button, 1 is pressed, 0 is not pressed.
263 Bit0 => Left Button, 1 is pressed, 0 is not pressed.
264Byte 2: X coordinate (xpos[9:2])
265Byte 3: Y coordinate (ypos[9:2])
266Byte 4: Bit1~Bit0 => Y coordinate (xpos[1:0])
267 Bit3~Bit2 => X coordinate (ypos[1:0])
268 Bit4 => scroll down button
269 Bit5 => scroll up button
270 Bit6 => scroll left button
271 Bit7 => scroll right button
272
273Notify Packet for STL3888-B0
274 Bit 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0 7 6 5 4 3 2 1 0
275BYTE |---------------|BYTE |---------------|BYTE|---------------|BYTE|---------------|
276 1 |1|0|1|P|1|M|R|L| 2 |C|C|C|C|C|C|C|C| 3 |0|0|F|F|0|0|0|i| 4 |r|l|u|d|0|0|0|0|
277 |---------------| |---------------| |---------------| |---------------|
278
279Byte 1: Bit7~Bit6 => 00, Normal data packet
280 => 01, Absolute coordination packet
281 => 10, Notify packet
282 Bit5 => 1
283 Bit4 => when in absolute coordinate mode (valid when EN_PKT_GO is 1):
284 0: left button is generated by the on-pad command
285 1: left button is generated by the external button
286 Bit3 => 1
287 Bit2 => Middle Button, 1 is pressed, 0 is not pressed.
288 Bit1 => Right Button, 1 is pressed, 0 is not pressed.
289 Bit0 => Left Button, 1 is pressed, 0 is not pressed.
290Byte 2: Message Type => 0xB7 (Multi Finger, Multi Coordinate mode)
291Byte 3: Bit7~Bit6 => Don't care
292 Bit5~Bit4 => Number of fingers
293 Bit3~Bit1 => Reserved
294 Bit0 => 1: enter gesture mode; 0: leaving gesture mode
295Byte 4: Bit7 => scroll right button
296 Bit6 => scroll left button
297 Bit5 => scroll up button
298 Bit4 => scroll down button
299 * Note that if gesture and additional button(Bit4~Bit7)
300 happen at the same time, the button information will not
301 be sent.
211 Bit3~Bit0 => Reserved 302 Bit3~Bit0 => Reserved
212 303
213Sample sequence of Multi-finger, Multi-coordinate mode: 304Sample sequence of Multi-finger, Multi-coordinate mode:
214 305
215 notify packet (valid bit == 1), abs pkt 1, abs pkt 2, abs pkt 1, 306 notify packet (valid bit == 1), abs pkt 1, abs pkt 2, abs pkt 1,
216 abs pkt 2, ..., notify packet(valid bit == 0) 307 abs pkt 2, ..., notify packet (valid bit == 0)
217 308
218============================================================================== 309==============================================================================
219* FSP Enable/Disable packet 310* FSP Enable/Disable packet
@@ -409,7 +500,8 @@ offset width default r/w name
409 0: read only, 1: read/write enable 500 0: read only, 1: read/write enable
410 (Note that following registers does not require clock gating being 501 (Note that following registers does not require clock gating being
411 enabled prior to write: 05 06 07 08 09 0c 0f 10 11 12 16 17 18 23 2e 502 enabled prior to write: 05 06 07 08 09 0c 0f 10 11 12 16 17 18 23 2e
412 40 41 42 43.) 503 40 41 42 43. In addition to that, this bit must be 1 when gesture
504 mode is enabled)
413 505
4140x31 RW on-pad command detection 5060x31 RW on-pad command detection
415 bit7 0 RW on-pad command left button down tag 507 bit7 0 RW on-pad command left button down tag
@@ -463,6 +555,10 @@ offset width default r/w name
463 absolute coordinates; otherwise, host only receives packets with 555 absolute coordinates; otherwise, host only receives packets with
464 relative coordinate.) 556 relative coordinate.)
465 557
558 bit7 0 RW EN_PS2_F2: PS/2 gesture mode 2nd
559 finger packet enable
560 0: disable, 1: enable
561
4660x43 RW on-pad control 5620x43 RW on-pad control
467 bit0 0 RW on-pad control enable 563 bit0 0 RW on-pad control enable
468 0: disable, 1: enable 564 0: disable, 1: enable
diff --git a/arch/arm/mach-ep93xx/include/mach/ep93xx_keypad.h b/arch/arm/mach-ep93xx/include/mach/ep93xx_keypad.h
index 62d17421e48c..1e2f4e97f428 100644
--- a/arch/arm/mach-ep93xx/include/mach/ep93xx_keypad.h
+++ b/arch/arm/mach-ep93xx/include/mach/ep93xx_keypad.h
@@ -5,6 +5,8 @@
5#ifndef __ASM_ARCH_EP93XX_KEYPAD_H 5#ifndef __ASM_ARCH_EP93XX_KEYPAD_H
6#define __ASM_ARCH_EP93XX_KEYPAD_H 6#define __ASM_ARCH_EP93XX_KEYPAD_H
7 7
8struct matrix_keymap_data;
9
8/* flags for the ep93xx_keypad driver */ 10/* flags for the ep93xx_keypad driver */
9#define EP93XX_KEYPAD_DISABLE_3_KEY (1<<0) /* disable 3-key reset */ 11#define EP93XX_KEYPAD_DISABLE_3_KEY (1<<0) /* disable 3-key reset */
10#define EP93XX_KEYPAD_DIAG_MODE (1<<1) /* diagnostic mode */ 12#define EP93XX_KEYPAD_DIAG_MODE (1<<1) /* diagnostic mode */
@@ -15,15 +17,13 @@
15 17
16/** 18/**
17 * struct ep93xx_keypad_platform_data - platform specific device structure 19 * struct ep93xx_keypad_platform_data - platform specific device structure
18 * @matrix_key_map: array of keycodes defining the keypad matrix 20 * @keymap_data: pointer to &matrix_keymap_data
19 * @matrix_key_map_size: ARRAY_SIZE(matrix_key_map) 21 * @debounce: debounce start count; terminal count is 0xff
20 * @debounce: debounce start count; terminal count is 0xff 22 * @prescale: row/column counter pre-scaler load value
21 * @prescale: row/column counter pre-scaler load value 23 * @flags: see above
22 * @flags: see above
23 */ 24 */
24struct ep93xx_keypad_platform_data { 25struct ep93xx_keypad_platform_data {
25 unsigned int *matrix_key_map; 26 struct matrix_keymap_data *keymap_data;
26 int matrix_key_map_size;
27 unsigned int debounce; 27 unsigned int debounce;
28 unsigned int prescale; 28 unsigned int prescale;
29 unsigned int flags; 29 unsigned int flags;
diff --git a/drivers/char/keyboard.c b/drivers/char/keyboard.c
index f706b1dffdb3..ada25bb8941e 100644
--- a/drivers/char/keyboard.c
+++ b/drivers/char/keyboard.c
@@ -1185,11 +1185,6 @@ static void kbd_keycode(unsigned int keycode, int down, int hw_raw)
1185 1185
1186 rep = (down == 2); 1186 rep = (down == 2);
1187 1187
1188#ifdef CONFIG_MAC_EMUMOUSEBTN
1189 if (mac_hid_mouse_emulate_buttons(1, keycode, down))
1190 return;
1191#endif /* CONFIG_MAC_EMUMOUSEBTN */
1192
1193 if ((raw_mode = (kbd->kbdmode == VC_RAW)) && !hw_raw) 1188 if ((raw_mode = (kbd->kbdmode == VC_RAW)) && !hw_raw)
1194 if (emulate_raw(vc, keycode, !down << 7)) 1189 if (emulate_raw(vc, keycode, !down << 7))
1195 if (keycode < BTN_MISC && printk_ratelimit()) 1190 if (keycode < BTN_MISC && printk_ratelimit())
@@ -1328,6 +1323,21 @@ static void kbd_event(struct input_handle *handle, unsigned int event_type,
1328 schedule_console_callback(); 1323 schedule_console_callback();
1329} 1324}
1330 1325
1326static bool kbd_match(struct input_handler *handler, struct input_dev *dev)
1327{
1328 int i;
1329
1330 if (test_bit(EV_SND, dev->evbit))
1331 return true;
1332
1333 if (test_bit(EV_KEY, dev->evbit))
1334 for (i = KEY_RESERVED; i < BTN_MISC; i++)
1335 if (test_bit(i, dev->keybit))
1336 return true;
1337
1338 return false;
1339}
1340
1331/* 1341/*
1332 * When a keyboard (or other input device) is found, the kbd_connect 1342 * When a keyboard (or other input device) is found, the kbd_connect
1333 * function is called. The function then looks at the device, and if it 1343 * function is called. The function then looks at the device, and if it
@@ -1339,14 +1349,6 @@ static int kbd_connect(struct input_handler *handler, struct input_dev *dev,
1339{ 1349{
1340 struct input_handle *handle; 1350 struct input_handle *handle;
1341 int error; 1351 int error;
1342 int i;
1343
1344 for (i = KEY_RESERVED; i < BTN_MISC; i++)
1345 if (test_bit(i, dev->keybit))
1346 break;
1347
1348 if (i == BTN_MISC && !test_bit(EV_SND, dev->evbit))
1349 return -ENODEV;
1350 1352
1351 handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL); 1353 handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
1352 if (!handle) 1354 if (!handle)
@@ -1412,6 +1414,7 @@ MODULE_DEVICE_TABLE(input, kbd_ids);
1412 1414
1413static struct input_handler kbd_handler = { 1415static struct input_handler kbd_handler = {
1414 .event = kbd_event, 1416 .event = kbd_event,
1417 .match = kbd_match,
1415 .connect = kbd_connect, 1418 .connect = kbd_connect,
1416 .disconnect = kbd_disconnect, 1419 .disconnect = kbd_disconnect,
1417 .start = kbd_start, 1420 .start = kbd_start,
diff --git a/drivers/input/evdev.c b/drivers/input/evdev.c
index 258c639571b5..9f9816baeb97 100644
--- a/drivers/input/evdev.c
+++ b/drivers/input/evdev.c
@@ -278,6 +278,8 @@ static int evdev_open(struct inode *inode, struct file *file)
278 goto err_free_client; 278 goto err_free_client;
279 279
280 file->private_data = client; 280 file->private_data = client;
281 nonseekable_open(inode, file);
282
281 return 0; 283 return 0;
282 284
283 err_free_client: 285 err_free_client:
diff --git a/drivers/input/gameport/emu10k1-gp.c b/drivers/input/gameport/emu10k1-gp.c
index b04930f7ea7d..7392992da424 100644
--- a/drivers/input/gameport/emu10k1-gp.c
+++ b/drivers/input/gameport/emu10k1-gp.c
@@ -46,7 +46,7 @@ struct emu {
46 int size; 46 int size;
47}; 47};
48 48
49static struct pci_device_id emu_tbl[] = { 49static const struct pci_device_id emu_tbl[] = {
50 50
51 { 0x1102, 0x7002, PCI_ANY_ID, PCI_ANY_ID }, /* SB Live gameport */ 51 { 0x1102, 0x7002, PCI_ANY_ID, PCI_ANY_ID }, /* SB Live gameport */
52 { 0x1102, 0x7003, PCI_ANY_ID, PCI_ANY_ID }, /* Audigy gameport */ 52 { 0x1102, 0x7003, PCI_ANY_ID, PCI_ANY_ID }, /* Audigy gameport */
diff --git a/drivers/input/gameport/fm801-gp.c b/drivers/input/gameport/fm801-gp.c
index 8a1810f88b9e..14d3f3e208a2 100644
--- a/drivers/input/gameport/fm801-gp.c
+++ b/drivers/input/gameport/fm801-gp.c
@@ -140,7 +140,7 @@ static void __devexit fm801_gp_remove(struct pci_dev *pci)
140 } 140 }
141} 141}
142 142
143static struct pci_device_id fm801_gp_id_table[] = { 143static const struct pci_device_id fm801_gp_id_table[] = {
144 { PCI_VENDOR_ID_FORTEMEDIA, PCI_DEVICE_ID_FM801_GP, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 }, 144 { PCI_VENDOR_ID_FORTEMEDIA, PCI_DEVICE_ID_FM801_GP, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
145 { 0 } 145 { 0 }
146}; 146};
diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
index ac11be08585e..7e18bcf05a66 100644
--- a/drivers/input/gameport/gameport.c
+++ b/drivers/input/gameport/gameport.c
@@ -11,6 +11,8 @@
11 * the Free Software Foundation. 11 * the Free Software Foundation.
12 */ 12 */
13 13
14#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
15
14#include <linux/stddef.h> 16#include <linux/stddef.h>
15#include <linux/module.h> 17#include <linux/module.h>
16#include <linux/ioport.h> 18#include <linux/ioport.h>
@@ -190,9 +192,8 @@ static int gameport_bind_driver(struct gameport *gameport, struct gameport_drive
190 192
191 error = device_bind_driver(&gameport->dev); 193 error = device_bind_driver(&gameport->dev);
192 if (error) { 194 if (error) {
193 printk(KERN_WARNING 195 dev_warn(&gameport->dev,
194 "gameport: device_bind_driver() failed " 196 "device_bind_driver() failed for %s (%s) and %s, error: %d\n",
195 "for %s (%s) and %s, error: %d\n",
196 gameport->phys, gameport->name, 197 gameport->phys, gameport->name,
197 drv->description, error); 198 drv->description, error);
198 drv->disconnect(gameport); 199 drv->disconnect(gameport);
@@ -209,9 +210,9 @@ static void gameport_find_driver(struct gameport *gameport)
209 210
210 error = device_attach(&gameport->dev); 211 error = device_attach(&gameport->dev);
211 if (error < 0) 212 if (error < 0)
212 printk(KERN_WARNING 213 dev_warn(&gameport->dev,
213 "gameport: device_attach() failed for %s (%s), error: %d\n", 214 "device_attach() failed for %s (%s), error: %d\n",
214 gameport->phys, gameport->name, error); 215 gameport->phys, gameport->name, error);
215} 216}
216 217
217 218
@@ -262,17 +263,14 @@ static int gameport_queue_event(void *object, struct module *owner,
262 263
263 event = kmalloc(sizeof(struct gameport_event), GFP_ATOMIC); 264 event = kmalloc(sizeof(struct gameport_event), GFP_ATOMIC);
264 if (!event) { 265 if (!event) {
265 printk(KERN_ERR 266 pr_err("Not enough memory to queue event %d\n", event_type);
266 "gameport: Not enough memory to queue event %d\n",
267 event_type);
268 retval = -ENOMEM; 267 retval = -ENOMEM;
269 goto out; 268 goto out;
270 } 269 }
271 270
272 if (!try_module_get(owner)) { 271 if (!try_module_get(owner)) {
273 printk(KERN_WARNING 272 pr_warning("Can't get module reference, dropping event %d\n",
274 "gameport: Can't get module reference, dropping event %d\n", 273 event_type);
275 event_type);
276 kfree(event); 274 kfree(event);
277 retval = -EINVAL; 275 retval = -EINVAL;
278 goto out; 276 goto out;
@@ -298,14 +296,12 @@ static void gameport_free_event(struct gameport_event *event)
298 296
299static void gameport_remove_duplicate_events(struct gameport_event *event) 297static void gameport_remove_duplicate_events(struct gameport_event *event)
300{ 298{
301 struct list_head *node, *next; 299 struct gameport_event *e, *next;
302 struct gameport_event *e;
303 unsigned long flags; 300 unsigned long flags;
304 301
305 spin_lock_irqsave(&gameport_event_lock, flags); 302 spin_lock_irqsave(&gameport_event_lock, flags);
306 303
307 list_for_each_safe(node, next, &gameport_event_list) { 304 list_for_each_entry_safe(e, next, &gameport_event_list, node) {
308 e = list_entry(node, struct gameport_event, node);
309 if (event->object == e->object) { 305 if (event->object == e->object) {
310 /* 306 /*
311 * If this event is of different type we should not 307 * If this event is of different type we should not
@@ -315,7 +311,7 @@ static void gameport_remove_duplicate_events(struct gameport_event *event)
315 if (event->type != e->type) 311 if (event->type != e->type)
316 break; 312 break;
317 313
318 list_del_init(node); 314 list_del_init(&e->node);
319 gameport_free_event(e); 315 gameport_free_event(e);
320 } 316 }
321 } 317 }
@@ -325,23 +321,18 @@ static void gameport_remove_duplicate_events(struct gameport_event *event)
325 321
326static struct gameport_event *gameport_get_event(void) 322static struct gameport_event *gameport_get_event(void)
327{ 323{
328 struct gameport_event *event; 324 struct gameport_event *event = NULL;
329 struct list_head *node;
330 unsigned long flags; 325 unsigned long flags;
331 326
332 spin_lock_irqsave(&gameport_event_lock, flags); 327 spin_lock_irqsave(&gameport_event_lock, flags);
333 328
334 if (list_empty(&gameport_event_list)) { 329 if (!list_empty(&gameport_event_list)) {
335 spin_unlock_irqrestore(&gameport_event_lock, flags); 330 event = list_first_entry(&gameport_event_list,
336 return NULL; 331 struct gameport_event, node);
332 list_del_init(&event->node);
337 } 333 }
338 334
339 node = gameport_event_list.next;
340 event = list_entry(node, struct gameport_event, node);
341 list_del_init(node);
342
343 spin_unlock_irqrestore(&gameport_event_lock, flags); 335 spin_unlock_irqrestore(&gameport_event_lock, flags);
344
345 return event; 336 return event;
346} 337}
347 338
@@ -360,16 +351,14 @@ static void gameport_handle_event(void)
360 if ((event = gameport_get_event())) { 351 if ((event = gameport_get_event())) {
361 352
362 switch (event->type) { 353 switch (event->type) {
363 case GAMEPORT_REGISTER_PORT:
364 gameport_add_port(event->object);
365 break;
366 354
367 case GAMEPORT_ATTACH_DRIVER: 355 case GAMEPORT_REGISTER_PORT:
368 gameport_attach_driver(event->object); 356 gameport_add_port(event->object);
369 break; 357 break;
370 358
371 default: 359 case GAMEPORT_ATTACH_DRIVER:
372 break; 360 gameport_attach_driver(event->object);
361 break;
373 } 362 }
374 363
375 gameport_remove_duplicate_events(event); 364 gameport_remove_duplicate_events(event);
@@ -385,16 +374,14 @@ static void gameport_handle_event(void)
385 */ 374 */
386static void gameport_remove_pending_events(void *object) 375static void gameport_remove_pending_events(void *object)
387{ 376{
388 struct list_head *node, *next; 377 struct gameport_event *event, *next;
389 struct gameport_event *event;
390 unsigned long flags; 378 unsigned long flags;
391 379
392 spin_lock_irqsave(&gameport_event_lock, flags); 380 spin_lock_irqsave(&gameport_event_lock, flags);
393 381
394 list_for_each_safe(node, next, &gameport_event_list) { 382 list_for_each_entry_safe(event, next, &gameport_event_list, node) {
395 event = list_entry(node, struct gameport_event, node);
396 if (event->object == object) { 383 if (event->object == object) {
397 list_del_init(node); 384 list_del_init(&event->node);
398 gameport_free_event(event); 385 gameport_free_event(event);
399 } 386 }
400 } 387 }
@@ -441,7 +428,6 @@ static int gameport_thread(void *nothing)
441 kthread_should_stop() || !list_empty(&gameport_event_list)); 428 kthread_should_stop() || !list_empty(&gameport_event_list));
442 } while (!kthread_should_stop()); 429 } while (!kthread_should_stop());
443 430
444 printk(KERN_DEBUG "gameport: kgameportd exiting\n");
445 return 0; 431 return 0;
446} 432}
447 433
@@ -453,6 +439,7 @@ static int gameport_thread(void *nothing)
453static ssize_t gameport_show_description(struct device *dev, struct device_attribute *attr, char *buf) 439static ssize_t gameport_show_description(struct device *dev, struct device_attribute *attr, char *buf)
454{ 440{
455 struct gameport *gameport = to_gameport_port(dev); 441 struct gameport *gameport = to_gameport_port(dev);
442
456 return sprintf(buf, "%s\n", gameport->name); 443 return sprintf(buf, "%s\n", gameport->name);
457} 444}
458 445
@@ -521,7 +508,8 @@ static void gameport_init_port(struct gameport *gameport)
521 508
522 mutex_init(&gameport->drv_mutex); 509 mutex_init(&gameport->drv_mutex);
523 device_initialize(&gameport->dev); 510 device_initialize(&gameport->dev);
524 dev_set_name(&gameport->dev, "gameport%lu", (unsigned long)atomic_inc_return(&gameport_no) - 1); 511 dev_set_name(&gameport->dev, "gameport%lu",
512 (unsigned long)atomic_inc_return(&gameport_no) - 1);
525 gameport->dev.bus = &gameport_bus; 513 gameport->dev.bus = &gameport_bus;
526 gameport->dev.release = gameport_release_port; 514 gameport->dev.release = gameport_release_port;
527 if (gameport->parent) 515 if (gameport->parent)
@@ -550,19 +538,17 @@ static void gameport_add_port(struct gameport *gameport)
550 list_add_tail(&gameport->node, &gameport_list); 538 list_add_tail(&gameport->node, &gameport_list);
551 539
552 if (gameport->io) 540 if (gameport->io)
553 printk(KERN_INFO "gameport: %s is %s, io %#x, speed %dkHz\n", 541 dev_info(&gameport->dev, "%s is %s, io %#x, speed %dkHz\n",
554 gameport->name, gameport->phys, gameport->io, gameport->speed); 542 gameport->name, gameport->phys, gameport->io, gameport->speed);
555 else 543 else
556 printk(KERN_INFO "gameport: %s is %s, speed %dkHz\n", 544 dev_info(&gameport->dev, "%s is %s, speed %dkHz\n",
557 gameport->name, gameport->phys, gameport->speed); 545 gameport->name, gameport->phys, gameport->speed);
558 546
559 error = device_add(&gameport->dev); 547 error = device_add(&gameport->dev);
560 if (error) 548 if (error)
561 printk(KERN_ERR 549 dev_err(&gameport->dev,
562 "gameport: device_add() failed for %s (%s), error: %d\n", 550 "device_add() failed for %s (%s), error: %d\n",
563 gameport->phys, gameport->name, error); 551 gameport->phys, gameport->name, error);
564 else
565 gameport->registered = 1;
566} 552}
567 553
568/* 554/*
@@ -584,10 +570,8 @@ static void gameport_destroy_port(struct gameport *gameport)
584 gameport->parent = NULL; 570 gameport->parent = NULL;
585 } 571 }
586 572
587 if (gameport->registered) { 573 if (device_is_registered(&gameport->dev))
588 device_del(&gameport->dev); 574 device_del(&gameport->dev);
589 gameport->registered = 0;
590 }
591 575
592 list_del_init(&gameport->node); 576 list_del_init(&gameport->node);
593 577
@@ -705,8 +689,7 @@ static void gameport_attach_driver(struct gameport_driver *drv)
705 689
706 error = driver_attach(&drv->driver); 690 error = driver_attach(&drv->driver);
707 if (error) 691 if (error)
708 printk(KERN_ERR 692 pr_err("driver_attach() failed for %s, error: %d\n",
709 "gameport: driver_attach() failed for %s, error: %d\n",
710 drv->driver.name, error); 693 drv->driver.name, error);
711} 694}
712 695
@@ -727,8 +710,7 @@ int __gameport_register_driver(struct gameport_driver *drv, struct module *owner
727 710
728 error = driver_register(&drv->driver); 711 error = driver_register(&drv->driver);
729 if (error) { 712 if (error) {
730 printk(KERN_ERR 713 pr_err("driver_register() failed for %s, error: %d\n",
731 "gameport: driver_register() failed for %s, error: %d\n",
732 drv->driver.name, error); 714 drv->driver.name, error);
733 return error; 715 return error;
734 } 716 }
@@ -828,7 +810,7 @@ static int __init gameport_init(void)
828 810
829 error = bus_register(&gameport_bus); 811 error = bus_register(&gameport_bus);
830 if (error) { 812 if (error) {
831 printk(KERN_ERR "gameport: failed to register gameport bus, error: %d\n", error); 813 pr_err("failed to register gameport bus, error: %d\n", error);
832 return error; 814 return error;
833 } 815 }
834 816
@@ -836,7 +818,7 @@ static int __init gameport_init(void)
836 if (IS_ERR(gameport_task)) { 818 if (IS_ERR(gameport_task)) {
837 bus_unregister(&gameport_bus); 819 bus_unregister(&gameport_bus);
838 error = PTR_ERR(gameport_task); 820 error = PTR_ERR(gameport_task);
839 printk(KERN_ERR "gameport: Failed to start kgameportd, error: %d\n", error); 821 pr_err("Failed to start kgameportd, error: %d\n", error);
840 return error; 822 return error;
841 } 823 }
842 824
diff --git a/drivers/input/gameport/ns558.c b/drivers/input/gameport/ns558.c
index db556b71ddda..7c217848613e 100644
--- a/drivers/input/gameport/ns558.c
+++ b/drivers/input/gameport/ns558.c
@@ -166,7 +166,7 @@ static int ns558_isa_probe(int io)
166 166
167#ifdef CONFIG_PNP 167#ifdef CONFIG_PNP
168 168
169static struct pnp_device_id pnp_devids[] = { 169static const struct pnp_device_id pnp_devids[] = {
170 { .id = "@P@0001", .driver_data = 0 }, /* ALS 100 */ 170 { .id = "@P@0001", .driver_data = 0 }, /* ALS 100 */
171 { .id = "@P@0020", .driver_data = 0 }, /* ALS 200 */ 171 { .id = "@P@0020", .driver_data = 0 }, /* ALS 200 */
172 { .id = "@P@1001", .driver_data = 0 }, /* ALS 100+ */ 172 { .id = "@P@1001", .driver_data = 0 }, /* ALS 100+ */
diff --git a/drivers/input/input.c b/drivers/input/input.c
index 86cb2d2196ff..41168d5f8c17 100644
--- a/drivers/input/input.c
+++ b/drivers/input/input.c
@@ -87,12 +87,14 @@ static int input_defuzz_abs_event(int value, int old_val, int fuzz)
87} 87}
88 88
89/* 89/*
90 * Pass event through all open handles. This function is called with 90 * Pass event first through all filters and then, if event has not been
91 * filtered out, through all open handles. This function is called with
91 * dev->event_lock held and interrupts disabled. 92 * dev->event_lock held and interrupts disabled.
92 */ 93 */
93static void input_pass_event(struct input_dev *dev, 94static void input_pass_event(struct input_dev *dev,
94 unsigned int type, unsigned int code, int value) 95 unsigned int type, unsigned int code, int value)
95{ 96{
97 struct input_handler *handler;
96 struct input_handle *handle; 98 struct input_handle *handle;
97 99
98 rcu_read_lock(); 100 rcu_read_lock();
@@ -100,11 +102,25 @@ static void input_pass_event(struct input_dev *dev,
100 handle = rcu_dereference(dev->grab); 102 handle = rcu_dereference(dev->grab);
101 if (handle) 103 if (handle)
102 handle->handler->event(handle, type, code, value); 104 handle->handler->event(handle, type, code, value);
103 else 105 else {
104 list_for_each_entry_rcu(handle, &dev->h_list, d_node) 106 bool filtered = false;
105 if (handle->open) 107
106 handle->handler->event(handle, 108 list_for_each_entry_rcu(handle, &dev->h_list, d_node) {
107 type, code, value); 109 if (!handle->open)
110 continue;
111
112 handler = handle->handler;
113 if (!handler->filter) {
114 if (filtered)
115 break;
116
117 handler->event(handle, type, code, value);
118
119 } else if (handler->filter(handle, type, code, value))
120 filtered = true;
121 }
122 }
123
108 rcu_read_unlock(); 124 rcu_read_unlock();
109} 125}
110 126
@@ -615,12 +631,12 @@ static int input_default_setkeycode(struct input_dev *dev,
615 } 631 }
616 } 632 }
617 633
618 clear_bit(old_keycode, dev->keybit); 634 __clear_bit(old_keycode, dev->keybit);
619 set_bit(keycode, dev->keybit); 635 __set_bit(keycode, dev->keybit);
620 636
621 for (i = 0; i < dev->keycodemax; i++) { 637 for (i = 0; i < dev->keycodemax; i++) {
622 if (input_fetch_keycode(dev, i) == old_keycode) { 638 if (input_fetch_keycode(dev, i) == old_keycode) {
623 set_bit(old_keycode, dev->keybit); 639 __set_bit(old_keycode, dev->keybit);
624 break; /* Setting the bit twice is useless, so break */ 640 break; /* Setting the bit twice is useless, so break */
625 } 641 }
626 } 642 }
@@ -678,6 +694,9 @@ int input_set_keycode(struct input_dev *dev, int scancode, int keycode)
678 if (retval) 694 if (retval)
679 goto out; 695 goto out;
680 696
697 /* Make sure KEY_RESERVED did not get enabled. */
698 __clear_bit(KEY_RESERVED, dev->keybit);
699
681 /* 700 /*
682 * Simulate keyup event if keycode is not present 701 * Simulate keyup event if keycode is not present
683 * in the keymap anymore 702 * in the keymap anymore
@@ -705,12 +724,13 @@ EXPORT_SYMBOL(input_set_keycode);
705 if (i != BITS_TO_LONGS(max)) \ 724 if (i != BITS_TO_LONGS(max)) \
706 continue; 725 continue;
707 726
708static const struct input_device_id *input_match_device(const struct input_device_id *id, 727static const struct input_device_id *input_match_device(struct input_handler *handler,
709 struct input_dev *dev) 728 struct input_dev *dev)
710{ 729{
730 const struct input_device_id *id;
711 int i; 731 int i;
712 732
713 for (; id->flags || id->driver_info; id++) { 733 for (id = handler->id_table; id->flags || id->driver_info; id++) {
714 734
715 if (id->flags & INPUT_DEVICE_ID_MATCH_BUS) 735 if (id->flags & INPUT_DEVICE_ID_MATCH_BUS)
716 if (id->bustype != dev->id.bustype) 736 if (id->bustype != dev->id.bustype)
@@ -738,7 +758,8 @@ static const struct input_device_id *input_match_device(const struct input_devic
738 MATCH_BIT(ffbit, FF_MAX); 758 MATCH_BIT(ffbit, FF_MAX);
739 MATCH_BIT(swbit, SW_MAX); 759 MATCH_BIT(swbit, SW_MAX);
740 760
741 return id; 761 if (!handler->match || handler->match(handler, dev))
762 return id;
742 } 763 }
743 764
744 return NULL; 765 return NULL;
@@ -749,10 +770,7 @@ static int input_attach_handler(struct input_dev *dev, struct input_handler *han
749 const struct input_device_id *id; 770 const struct input_device_id *id;
750 int error; 771 int error;
751 772
752 if (handler->blacklist && input_match_device(handler->blacklist, dev)) 773 id = input_match_device(handler, dev);
753 return -ENODEV;
754
755 id = input_match_device(handler->id_table, dev);
756 if (!id) 774 if (!id)
757 return -ENODEV; 775 return -ENODEV;
758 776
@@ -988,6 +1006,8 @@ static int input_handlers_seq_show(struct seq_file *seq, void *v)
988 union input_seq_state *state = (union input_seq_state *)&seq->private; 1006 union input_seq_state *state = (union input_seq_state *)&seq->private;
989 1007
990 seq_printf(seq, "N: Number=%u Name=%s", state->pos, handler->name); 1008 seq_printf(seq, "N: Number=%u Name=%s", state->pos, handler->name);
1009 if (handler->filter)
1010 seq_puts(seq, " (filter)");
991 if (handler->fops) 1011 if (handler->fops)
992 seq_printf(seq, " Minor=%d", handler->minor); 1012 seq_printf(seq, " Minor=%d", handler->minor);
993 seq_putc(seq, '\n'); 1013 seq_putc(seq, '\n');
@@ -1551,6 +1571,25 @@ void input_set_capability(struct input_dev *dev, unsigned int type, unsigned int
1551} 1571}
1552EXPORT_SYMBOL(input_set_capability); 1572EXPORT_SYMBOL(input_set_capability);
1553 1573
1574#define INPUT_CLEANSE_BITMASK(dev, type, bits) \
1575 do { \
1576 if (!test_bit(EV_##type, dev->evbit)) \
1577 memset(dev->bits##bit, 0, \
1578 sizeof(dev->bits##bit)); \
1579 } while (0)
1580
1581static void input_cleanse_bitmasks(struct input_dev *dev)
1582{
1583 INPUT_CLEANSE_BITMASK(dev, KEY, key);
1584 INPUT_CLEANSE_BITMASK(dev, REL, rel);
1585 INPUT_CLEANSE_BITMASK(dev, ABS, abs);
1586 INPUT_CLEANSE_BITMASK(dev, MSC, msc);
1587 INPUT_CLEANSE_BITMASK(dev, LED, led);
1588 INPUT_CLEANSE_BITMASK(dev, SND, snd);
1589 INPUT_CLEANSE_BITMASK(dev, FF, ff);
1590 INPUT_CLEANSE_BITMASK(dev, SW, sw);
1591}
1592
1554/** 1593/**
1555 * input_register_device - register device with input core 1594 * input_register_device - register device with input core
1556 * @dev: device to be registered 1595 * @dev: device to be registered
@@ -1570,13 +1609,19 @@ int input_register_device(struct input_dev *dev)
1570 const char *path; 1609 const char *path;
1571 int error; 1610 int error;
1572 1611
1612 /* Every input device generates EV_SYN/SYN_REPORT events. */
1573 __set_bit(EV_SYN, dev->evbit); 1613 __set_bit(EV_SYN, dev->evbit);
1574 1614
1615 /* KEY_RESERVED is not supposed to be transmitted to userspace. */
1616 __clear_bit(KEY_RESERVED, dev->keybit);
1617
1618 /* Make sure that bitmasks not mentioned in dev->evbit are clean. */
1619 input_cleanse_bitmasks(dev);
1620
1575 /* 1621 /*
1576 * If delay and period are pre-set by the driver, then autorepeating 1622 * If delay and period are pre-set by the driver, then autorepeating
1577 * is handled by the driver itself and we don't do it in input.c. 1623 * is handled by the driver itself and we don't do it in input.c.
1578 */ 1624 */
1579
1580 init_timer(&dev->timer); 1625 init_timer(&dev->timer);
1581 if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) { 1626 if (!dev->rep[REP_DELAY] && !dev->rep[REP_PERIOD]) {
1582 dev->timer.data = (long) dev; 1627 dev->timer.data = (long) dev;
@@ -1776,7 +1821,16 @@ int input_register_handle(struct input_handle *handle)
1776 error = mutex_lock_interruptible(&dev->mutex); 1821 error = mutex_lock_interruptible(&dev->mutex);
1777 if (error) 1822 if (error)
1778 return error; 1823 return error;
1779 list_add_tail_rcu(&handle->d_node, &dev->h_list); 1824
1825 /*
1826 * Filters go to the head of the list, normal handlers
1827 * to the tail.
1828 */
1829 if (handler->filter)
1830 list_add_rcu(&handle->d_node, &dev->h_list);
1831 else
1832 list_add_tail_rcu(&handle->d_node, &dev->h_list);
1833
1780 mutex_unlock(&dev->mutex); 1834 mutex_unlock(&dev->mutex);
1781 1835
1782 /* 1836 /*
diff --git a/drivers/input/joydev.c b/drivers/input/joydev.c
index b1bd6dd32286..c52bec4d0530 100644
--- a/drivers/input/joydev.c
+++ b/drivers/input/joydev.c
@@ -286,6 +286,8 @@ static int joydev_open(struct inode *inode, struct file *file)
286 goto err_free_client; 286 goto err_free_client;
287 287
288 file->private_data = client; 288 file->private_data = client;
289 nonseekable_open(inode, file);
290
289 return 0; 291 return 0;
290 292
291 err_free_client: 293 err_free_client:
@@ -775,6 +777,20 @@ static void joydev_cleanup(struct joydev *joydev)
775 input_close_device(handle); 777 input_close_device(handle);
776} 778}
777 779
780
781static bool joydev_match(struct input_handler *handler, struct input_dev *dev)
782{
783 /* Avoid touchpads and touchscreens */
784 if (test_bit(EV_KEY, dev->evbit) && test_bit(BTN_TOUCH, dev->keybit))
785 return false;
786
787 /* Avoid tablets, digitisers and similar devices */
788 if (test_bit(EV_KEY, dev->evbit) && test_bit(BTN_DIGI, dev->keybit))
789 return false;
790
791 return true;
792}
793
778static int joydev_connect(struct input_handler *handler, struct input_dev *dev, 794static int joydev_connect(struct input_handler *handler, struct input_dev *dev,
779 const struct input_device_id *id) 795 const struct input_device_id *id)
780{ 796{
@@ -894,22 +910,6 @@ static void joydev_disconnect(struct input_handle *handle)
894 put_device(&joydev->dev); 910 put_device(&joydev->dev);
895} 911}
896 912
897static const struct input_device_id joydev_blacklist[] = {
898 {
899 .flags = INPUT_DEVICE_ID_MATCH_EVBIT |
900 INPUT_DEVICE_ID_MATCH_KEYBIT,
901 .evbit = { BIT_MASK(EV_KEY) },
902 .keybit = { [BIT_WORD(BTN_TOUCH)] = BIT_MASK(BTN_TOUCH) },
903 }, /* Avoid itouchpads and touchscreens */
904 {
905 .flags = INPUT_DEVICE_ID_MATCH_EVBIT |
906 INPUT_DEVICE_ID_MATCH_KEYBIT,
907 .evbit = { BIT_MASK(EV_KEY) },
908 .keybit = { [BIT_WORD(BTN_DIGI)] = BIT_MASK(BTN_DIGI) },
909 }, /* Avoid tablets, digitisers and similar devices */
910 { } /* Terminating entry */
911};
912
913static const struct input_device_id joydev_ids[] = { 913static const struct input_device_id joydev_ids[] = {
914 { 914 {
915 .flags = INPUT_DEVICE_ID_MATCH_EVBIT | 915 .flags = INPUT_DEVICE_ID_MATCH_EVBIT |
@@ -936,13 +936,13 @@ MODULE_DEVICE_TABLE(input, joydev_ids);
936 936
937static struct input_handler joydev_handler = { 937static struct input_handler joydev_handler = {
938 .event = joydev_event, 938 .event = joydev_event,
939 .match = joydev_match,
939 .connect = joydev_connect, 940 .connect = joydev_connect,
940 .disconnect = joydev_disconnect, 941 .disconnect = joydev_disconnect,
941 .fops = &joydev_fops, 942 .fops = &joydev_fops,
942 .minor = JOYDEV_MINOR_BASE, 943 .minor = JOYDEV_MINOR_BASE,
943 .name = "joydev", 944 .name = "joydev",
944 .id_table = joydev_ids, 945 .id_table = joydev_ids,
945 .blacklist = joydev_blacklist,
946}; 946};
947 947
948static int __init joydev_init(void) 948static int __init joydev_init(void)
diff --git a/drivers/input/joystick/Kconfig b/drivers/input/joystick/Kconfig
index b11419590cfe..5b596165b571 100644
--- a/drivers/input/joystick/Kconfig
+++ b/drivers/input/joystick/Kconfig
@@ -221,6 +221,7 @@ config JOYSTICK_DB9
221config JOYSTICK_GAMECON 221config JOYSTICK_GAMECON
222 tristate "Multisystem, NES, SNES, N64, PSX joysticks and gamepads" 222 tristate "Multisystem, NES, SNES, N64, PSX joysticks and gamepads"
223 depends on PARPORT 223 depends on PARPORT
224 select INPUT_FF_MEMLESS
224 ---help--- 225 ---help---
225 Say Y here if you have a Nintendo Entertainment System gamepad, 226 Say Y here if you have a Nintendo Entertainment System gamepad,
226 Super Nintendo Entertainment System gamepad, Nintendo 64 gamepad, 227 Super Nintendo Entertainment System gamepad, Nintendo 64 gamepad,
diff --git a/drivers/input/joystick/gamecon.c b/drivers/input/joystick/gamecon.c
index 07a32aff5a31..ae998d99a5ae 100644
--- a/drivers/input/joystick/gamecon.c
+++ b/drivers/input/joystick/gamecon.c
@@ -30,6 +30,8 @@
30 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic 30 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
31 */ 31 */
32 32
33#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
34
33#include <linux/kernel.h> 35#include <linux/kernel.h>
34#include <linux/delay.h> 36#include <linux/delay.h>
35#include <linux/module.h> 37#include <linux/module.h>
@@ -61,48 +63,73 @@ MODULE_PARM_DESC(map3, "Describes third set of devices");
61 63
62/* see also gs_psx_delay parameter in PSX support section */ 64/* see also gs_psx_delay parameter in PSX support section */
63 65
64#define GC_SNES 1 66enum gc_type {
65#define GC_NES 2 67 GC_NONE = 0,
66#define GC_NES4 3 68 GC_SNES,
67#define GC_MULTI 4 69 GC_NES,
68#define GC_MULTI2 5 70 GC_NES4,
69#define GC_N64 6 71 GC_MULTI,
70#define GC_PSX 7 72 GC_MULTI2,
71#define GC_DDR 8 73 GC_N64,
72#define GC_SNESMOUSE 9 74 GC_PSX,
73 75 GC_DDR,
74#define GC_MAX 9 76 GC_SNESMOUSE,
77 GC_MAX
78};
75 79
76#define GC_REFRESH_TIME HZ/100 80#define GC_REFRESH_TIME HZ/100
77 81
82struct gc_pad {
83 struct input_dev *dev;
84 enum gc_type type;
85 char phys[32];
86};
87
78struct gc { 88struct gc {
79 struct pardevice *pd; 89 struct pardevice *pd;
90 struct gc_pad pads[GC_MAX_DEVICES];
80 struct input_dev *dev[GC_MAX_DEVICES]; 91 struct input_dev *dev[GC_MAX_DEVICES];
81 struct timer_list timer; 92 struct timer_list timer;
82 unsigned char pads[GC_MAX + 1]; 93 int pad_count[GC_MAX];
83 int used; 94 int used;
84 struct mutex mutex; 95 struct mutex mutex;
85 char phys[GC_MAX_DEVICES][32]; 96};
97
98struct gc_subdev {
99 unsigned int idx;
86}; 100};
87 101
88static struct gc *gc_base[3]; 102static struct gc *gc_base[3];
89 103
90static int gc_status_bit[] = { 0x40, 0x80, 0x20, 0x10, 0x08 }; 104static const int gc_status_bit[] = { 0x40, 0x80, 0x20, 0x10, 0x08 };
105
106static const char *gc_names[] = {
107 NULL, "SNES pad", "NES pad", "NES FourPort", "Multisystem joystick",
108 "Multisystem 2-button joystick", "N64 controller", "PSX controller",
109 "PSX DDR controller", "SNES mouse"
110};
91 111
92static char *gc_names[] = { NULL, "SNES pad", "NES pad", "NES FourPort", "Multisystem joystick",
93 "Multisystem 2-button joystick", "N64 controller", "PSX controller",
94 "PSX DDR controller", "SNES mouse" };
95/* 112/*
96 * N64 support. 113 * N64 support.
97 */ 114 */
98 115
99static unsigned char gc_n64_bytes[] = { 0, 1, 13, 15, 14, 12, 10, 11, 2, 3 }; 116static const unsigned char gc_n64_bytes[] = { 0, 1, 13, 15, 14, 12, 10, 11, 2, 3 };
100static short gc_n64_btn[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_TRIGGER, BTN_START }; 117static const short gc_n64_btn[] = {
118 BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z,
119 BTN_TL, BTN_TR, BTN_TRIGGER, BTN_START
120};
101 121
102#define GC_N64_LENGTH 32 /* N64 bit length, not including stop bit */ 122#define GC_N64_LENGTH 32 /* N64 bit length, not including stop bit */
103#define GC_N64_REQUEST_LENGTH 37 /* transmit request sequence is 9 bits long */ 123#define GC_N64_STOP_LENGTH 5 /* Length of encoded stop bit */
124#define GC_N64_CMD_00 0x11111111UL
125#define GC_N64_CMD_01 0xd1111111UL
126#define GC_N64_CMD_03 0xdd111111UL
127#define GC_N64_CMD_1b 0xdd1dd111UL
128#define GC_N64_CMD_c0 0x111111ddUL
129#define GC_N64_CMD_80 0x1111111dUL
130#define GC_N64_STOP_BIT 0x1d /* Encoded stop bit */
131#define GC_N64_REQUEST_DATA GC_N64_CMD_01 /* the request data command */
104#define GC_N64_DELAY 133 /* delay between transmit request, and response ready (us) */ 132#define GC_N64_DELAY 133 /* delay between transmit request, and response ready (us) */
105#define GC_N64_REQUEST 0x1dd1111111ULL /* the request data command (encoded for 000000011) */
106#define GC_N64_DWS 3 /* delay between write segments (required for sound playback because of ISA DMA) */ 133#define GC_N64_DWS 3 /* delay between write segments (required for sound playback because of ISA DMA) */
107 /* GC_N64_DWS > 24 is known to fail */ 134 /* GC_N64_DWS > 24 is known to fail */
108#define GC_N64_POWER_W 0xe2 /* power during write (transmit request) */ 135#define GC_N64_POWER_W 0xe2 /* power during write (transmit request) */
@@ -114,8 +141,40 @@ static short gc_n64_btn[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL,
114#define GC_N64_CLOCK 0x02 /* clock bits for read */ 141#define GC_N64_CLOCK 0x02 /* clock bits for read */
115 142
116/* 143/*
144 * Used for rumble code.
145 */
146
147/* Send encoded command */
148static void gc_n64_send_command(struct gc *gc, unsigned long cmd,
149 unsigned char target)
150{
151 struct parport *port = gc->pd->port;
152 int i;
153
154 for (i = 0; i < GC_N64_LENGTH; i++) {
155 unsigned char data = (cmd >> i) & 1 ? target : 0;
156 parport_write_data(port, GC_N64_POWER_W | data);
157 udelay(GC_N64_DWS);
158 }
159}
160
161/* Send stop bit */
162static void gc_n64_send_stop_bit(struct gc *gc, unsigned char target)
163{
164 struct parport *port = gc->pd->port;
165 int i;
166
167 for (i = 0; i < GC_N64_STOP_LENGTH; i++) {
168 unsigned char data = (GC_N64_STOP_BIT >> i) & 1 ? target : 0;
169 parport_write_data(port, GC_N64_POWER_W | data);
170 udelay(GC_N64_DWS);
171 }
172}
173
174/*
117 * gc_n64_read_packet() reads an N64 packet. 175 * gc_n64_read_packet() reads an N64 packet.
118 * Each pad uses one bit per byte. So all pads connected to this port are read in parallel. 176 * Each pad uses one bit per byte. So all pads connected to this port
177 * are read in parallel.
119 */ 178 */
120 179
121static void gc_n64_read_packet(struct gc *gc, unsigned char *data) 180static void gc_n64_read_packet(struct gc *gc, unsigned char *data)
@@ -128,14 +187,13 @@ static void gc_n64_read_packet(struct gc *gc, unsigned char *data)
128 */ 187 */
129 188
130 local_irq_save(flags); 189 local_irq_save(flags);
131 for (i = 0; i < GC_N64_REQUEST_LENGTH; i++) { 190 gc_n64_send_command(gc, GC_N64_REQUEST_DATA, GC_N64_OUT);
132 parport_write_data(gc->pd->port, GC_N64_POWER_W | ((GC_N64_REQUEST >> i) & 1 ? GC_N64_OUT : 0)); 191 gc_n64_send_stop_bit(gc, GC_N64_OUT);
133 udelay(GC_N64_DWS);
134 }
135 local_irq_restore(flags); 192 local_irq_restore(flags);
136 193
137/* 194/*
138 * Wait for the pad response to be loaded into the 33-bit register of the adapter 195 * Wait for the pad response to be loaded into the 33-bit register
196 * of the adapter.
139 */ 197 */
140 198
141 udelay(GC_N64_DELAY); 199 udelay(GC_N64_DELAY);
@@ -146,13 +204,15 @@ static void gc_n64_read_packet(struct gc *gc, unsigned char *data)
146 204
147 for (i = 0; i < GC_N64_LENGTH; i++) { 205 for (i = 0; i < GC_N64_LENGTH; i++) {
148 parport_write_data(gc->pd->port, GC_N64_POWER_R); 206 parport_write_data(gc->pd->port, GC_N64_POWER_R);
207 udelay(2);
149 data[i] = parport_read_status(gc->pd->port); 208 data[i] = parport_read_status(gc->pd->port);
150 parport_write_data(gc->pd->port, GC_N64_POWER_R | GC_N64_CLOCK); 209 parport_write_data(gc->pd->port, GC_N64_POWER_R | GC_N64_CLOCK);
151 } 210 }
152 211
153/* 212/*
154 * We must wait 200 ms here for the controller to reinitialize before the next read request. 213 * We must wait 200 ms here for the controller to reinitialize before
155 * No worries as long as gc_read is polled less frequently than this. 214 * the next read request. No worries as long as gc_read is polled less
215 * frequently than this.
156 */ 216 */
157 217
158} 218}
@@ -160,45 +220,112 @@ static void gc_n64_read_packet(struct gc *gc, unsigned char *data)
160static void gc_n64_process_packet(struct gc *gc) 220static void gc_n64_process_packet(struct gc *gc)
161{ 221{
162 unsigned char data[GC_N64_LENGTH]; 222 unsigned char data[GC_N64_LENGTH];
163 signed char axes[2];
164 struct input_dev *dev; 223 struct input_dev *dev;
165 int i, j, s; 224 int i, j, s;
225 signed char x, y;
166 226
167 gc_n64_read_packet(gc, data); 227 gc_n64_read_packet(gc, data);
168 228
169 for (i = 0; i < GC_MAX_DEVICES; i++) { 229 for (i = 0; i < GC_MAX_DEVICES; i++) {
170 230
171 dev = gc->dev[i]; 231 if (gc->pads[i].type != GC_N64)
172 if (!dev)
173 continue; 232 continue;
174 233
234 dev = gc->pads[i].dev;
175 s = gc_status_bit[i]; 235 s = gc_status_bit[i];
176 236
177 if (s & gc->pads[GC_N64] & ~(data[8] | data[9])) { 237 if (s & ~(data[8] | data[9])) {
178 238
179 axes[0] = axes[1] = 0; 239 x = y = 0;
180 240
181 for (j = 0; j < 8; j++) { 241 for (j = 0; j < 8; j++) {
182 if (data[23 - j] & s) 242 if (data[23 - j] & s)
183 axes[0] |= 1 << j; 243 x |= 1 << j;
184 if (data[31 - j] & s) 244 if (data[31 - j] & s)
185 axes[1] |= 1 << j; 245 y |= 1 << j;
186 } 246 }
187 247
188 input_report_abs(dev, ABS_X, axes[0]); 248 input_report_abs(dev, ABS_X, x);
189 input_report_abs(dev, ABS_Y, -axes[1]); 249 input_report_abs(dev, ABS_Y, -y);
190 250
191 input_report_abs(dev, ABS_HAT0X, !(s & data[6]) - !(s & data[7])); 251 input_report_abs(dev, ABS_HAT0X,
192 input_report_abs(dev, ABS_HAT0Y, !(s & data[4]) - !(s & data[5])); 252 !(s & data[6]) - !(s & data[7]));
253 input_report_abs(dev, ABS_HAT0Y,
254 !(s & data[4]) - !(s & data[5]));
193 255
194 for (j = 0; j < 10; j++) 256 for (j = 0; j < 10; j++)
195 input_report_key(dev, gc_n64_btn[j], s & data[gc_n64_bytes[j]]); 257 input_report_key(dev, gc_n64_btn[j],
258 s & data[gc_n64_bytes[j]]);
196 259
197 input_sync(dev); 260 input_sync(dev);
198 } 261 }
199 } 262 }
200} 263}
201 264
265static int gc_n64_play_effect(struct input_dev *dev, void *data,
266 struct ff_effect *effect)
267{
268 int i;
269 unsigned long flags;
270 struct gc *gc = input_get_drvdata(dev);
271 struct gc_subdev *sdev = data;
272 unsigned char target = 1 << sdev->idx; /* select desired pin */
273
274 if (effect->type == FF_RUMBLE) {
275 struct ff_rumble_effect *rumble = &effect->u.rumble;
276 unsigned int cmd =
277 rumble->strong_magnitude || rumble->weak_magnitude ?
278 GC_N64_CMD_01 : GC_N64_CMD_00;
279
280 local_irq_save(flags);
281
282 /* Init Rumble - 0x03, 0x80, 0x01, (34)0x80 */
283 gc_n64_send_command(gc, GC_N64_CMD_03, target);
284 gc_n64_send_command(gc, GC_N64_CMD_80, target);
285 gc_n64_send_command(gc, GC_N64_CMD_01, target);
286 for (i = 0; i < 32; i++)
287 gc_n64_send_command(gc, GC_N64_CMD_80, target);
288 gc_n64_send_stop_bit(gc, target);
289
290 udelay(GC_N64_DELAY);
291
292 /* Now start or stop it - 0x03, 0xc0, 0zx1b, (32)0x01/0x00 */
293 gc_n64_send_command(gc, GC_N64_CMD_03, target);
294 gc_n64_send_command(gc, GC_N64_CMD_c0, target);
295 gc_n64_send_command(gc, GC_N64_CMD_1b, target);
296 for (i = 0; i < 32; i++)
297 gc_n64_send_command(gc, cmd, target);
298 gc_n64_send_stop_bit(gc, target);
299
300 local_irq_restore(flags);
301
302 }
303
304 return 0;
305}
306
307static int __init gc_n64_init_ff(struct input_dev *dev, int i)
308{
309 struct gc_subdev *sdev;
310 int err;
311
312 sdev = kmalloc(sizeof(*sdev), GFP_KERNEL);
313 if (!sdev)
314 return -ENOMEM;
315
316 sdev->idx = i;
317
318 input_set_capability(dev, EV_FF, FF_RUMBLE);
319
320 err = input_ff_create_memless(dev, sdev, gc_n64_play_effect);
321 if (err) {
322 kfree(sdev);
323 return err;
324 }
325
326 return 0;
327}
328
202/* 329/*
203 * NES/SNES support. 330 * NES/SNES support.
204 */ 331 */
@@ -214,9 +341,11 @@ static void gc_n64_process_packet(struct gc *gc)
214#define GC_NES_CLOCK 0x01 341#define GC_NES_CLOCK 0x01
215#define GC_NES_LATCH 0x02 342#define GC_NES_LATCH 0x02
216 343
217static unsigned char gc_nes_bytes[] = { 0, 1, 2, 3 }; 344static const unsigned char gc_nes_bytes[] = { 0, 1, 2, 3 };
218static unsigned char gc_snes_bytes[] = { 8, 0, 2, 3, 9, 1, 10, 11 }; 345static const unsigned char gc_snes_bytes[] = { 8, 0, 2, 3, 9, 1, 10, 11 };
219static short gc_snes_btn[] = { BTN_A, BTN_B, BTN_SELECT, BTN_START, BTN_X, BTN_Y, BTN_TL, BTN_TR }; 346static const short gc_snes_btn[] = {
347 BTN_A, BTN_B, BTN_SELECT, BTN_START, BTN_X, BTN_Y, BTN_TL, BTN_TR
348};
220 349
221/* 350/*
222 * gc_nes_read_packet() reads a NES/SNES packet. 351 * gc_nes_read_packet() reads a NES/SNES packet.
@@ -244,40 +373,51 @@ static void gc_nes_read_packet(struct gc *gc, int length, unsigned char *data)
244static void gc_nes_process_packet(struct gc *gc) 373static void gc_nes_process_packet(struct gc *gc)
245{ 374{
246 unsigned char data[GC_SNESMOUSE_LENGTH]; 375 unsigned char data[GC_SNESMOUSE_LENGTH];
376 struct gc_pad *pad;
247 struct input_dev *dev; 377 struct input_dev *dev;
248 int i, j, s, len; 378 int i, j, s, len;
249 char x_rel, y_rel; 379 char x_rel, y_rel;
250 380
251 len = gc->pads[GC_SNESMOUSE] ? GC_SNESMOUSE_LENGTH : 381 len = gc->pad_count[GC_SNESMOUSE] ? GC_SNESMOUSE_LENGTH :
252 (gc->pads[GC_SNES] ? GC_SNES_LENGTH : GC_NES_LENGTH); 382 (gc->pad_count[GC_SNES] ? GC_SNES_LENGTH : GC_NES_LENGTH);
253 383
254 gc_nes_read_packet(gc, len, data); 384 gc_nes_read_packet(gc, len, data);
255 385
256 for (i = 0; i < GC_MAX_DEVICES; i++) { 386 for (i = 0; i < GC_MAX_DEVICES; i++) {
257 387
388 pad = &gc->pads[i];
258 dev = gc->dev[i]; 389 dev = gc->dev[i];
259 if (!dev)
260 continue;
261
262 s = gc_status_bit[i]; 390 s = gc_status_bit[i];
263 391
264 if (s & (gc->pads[GC_NES] | gc->pads[GC_SNES])) { 392 switch (pad->type) {
393
394 case GC_NES:
395
265 input_report_abs(dev, ABS_X, !(s & data[6]) - !(s & data[7])); 396 input_report_abs(dev, ABS_X, !(s & data[6]) - !(s & data[7]));
266 input_report_abs(dev, ABS_Y, !(s & data[4]) - !(s & data[5])); 397 input_report_abs(dev, ABS_Y, !(s & data[4]) - !(s & data[5]));
267 }
268 398
269 if (s & gc->pads[GC_NES])
270 for (j = 0; j < 4; j++) 399 for (j = 0; j < 4; j++)
271 input_report_key(dev, gc_snes_btn[j], s & data[gc_nes_bytes[j]]); 400 input_report_key(dev, gc_snes_btn[j],
401 s & data[gc_nes_bytes[j]]);
402 input_sync(dev);
403 break;
404
405 case GC_SNES:
406
407 input_report_abs(dev, ABS_X, !(s & data[6]) - !(s & data[7]));
408 input_report_abs(dev, ABS_Y, !(s & data[4]) - !(s & data[5]));
272 409
273 if (s & gc->pads[GC_SNES])
274 for (j = 0; j < 8; j++) 410 for (j = 0; j < 8; j++)
275 input_report_key(dev, gc_snes_btn[j], s & data[gc_snes_bytes[j]]); 411 input_report_key(dev, gc_snes_btn[j],
412 s & data[gc_snes_bytes[j]]);
413 input_sync(dev);
414 break;
276 415
277 if (s & gc->pads[GC_SNESMOUSE]) { 416 case GC_SNESMOUSE:
278 /* 417 /*
279 * The 4 unused bits from SNES controllers appear to be ID bits 418 * The 4 unused bits from SNES controllers appear
280 * so use them to make sure iwe are dealing with a mouse. 419 * to be ID bits so use them to make sure we are
420 * dealing with a mouse.
281 * gamepad is connected. This is important since 421 * gamepad is connected. This is important since
282 * my SNES gamepad sends 1's for bits 16-31, which 422 * my SNES gamepad sends 1's for bits 16-31, which
283 * cause the mouse pointer to quickly move to the 423 * cause the mouse pointer to quickly move to the
@@ -310,9 +450,14 @@ static void gc_nes_process_packet(struct gc *gc)
310 y_rel = -y_rel; 450 y_rel = -y_rel;
311 input_report_rel(dev, REL_Y, y_rel); 451 input_report_rel(dev, REL_Y, y_rel);
312 } 452 }
453
454 input_sync(dev);
313 } 455 }
456 break;
457
458 default:
459 break;
314 } 460 }
315 input_sync(dev);
316 } 461 }
317} 462}
318 463
@@ -340,29 +485,35 @@ static void gc_multi_read_packet(struct gc *gc, int length, unsigned char *data)
340static void gc_multi_process_packet(struct gc *gc) 485static void gc_multi_process_packet(struct gc *gc)
341{ 486{
342 unsigned char data[GC_MULTI2_LENGTH]; 487 unsigned char data[GC_MULTI2_LENGTH];
488 int data_len = gc->pad_count[GC_MULTI2] ? GC_MULTI2_LENGTH : GC_MULTI_LENGTH;
489 struct gc_pad *pad;
343 struct input_dev *dev; 490 struct input_dev *dev;
344 int i, s; 491 int i, s;
345 492
346 gc_multi_read_packet(gc, gc->pads[GC_MULTI2] ? GC_MULTI2_LENGTH : GC_MULTI_LENGTH, data); 493 gc_multi_read_packet(gc, data_len, data);
347 494
348 for (i = 0; i < GC_MAX_DEVICES; i++) { 495 for (i = 0; i < GC_MAX_DEVICES; i++) {
349 496 pad = &gc->pads[i];
350 dev = gc->dev[i]; 497 dev = pad->dev;
351 if (!dev)
352 continue;
353
354 s = gc_status_bit[i]; 498 s = gc_status_bit[i];
355 499
356 if (s & (gc->pads[GC_MULTI] | gc->pads[GC_MULTI2])) { 500 switch (pad->type) {
357 input_report_abs(dev, ABS_X, !(s & data[2]) - !(s & data[3])); 501 case GC_MULTI2:
358 input_report_abs(dev, ABS_Y, !(s & data[0]) - !(s & data[1]));
359 input_report_key(dev, BTN_TRIGGER, s & data[4]);
360 }
361
362 if (s & gc->pads[GC_MULTI2])
363 input_report_key(dev, BTN_THUMB, s & data[5]); 502 input_report_key(dev, BTN_THUMB, s & data[5]);
503 /* fall through */
364 504
365 input_sync(dev); 505 case GC_MULTI:
506 input_report_abs(dev, ABS_X,
507 !(s & data[2]) - !(s & data[3]));
508 input_report_abs(dev, ABS_Y,
509 !(s & data[0]) - !(s & data[1]));
510 input_report_key(dev, BTN_TRIGGER, s & data[4]);
511 input_sync(dev);
512 break;
513
514 default:
515 break;
516 }
366 } 517 }
367} 518}
368 519
@@ -398,30 +549,41 @@ static int gc_psx_delay = GC_PSX_DELAY;
398module_param_named(psx_delay, gc_psx_delay, uint, 0); 549module_param_named(psx_delay, gc_psx_delay, uint, 0);
399MODULE_PARM_DESC(psx_delay, "Delay when accessing Sony PSX controller (usecs)"); 550MODULE_PARM_DESC(psx_delay, "Delay when accessing Sony PSX controller (usecs)");
400 551
401static short gc_psx_abs[] = { ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_HAT0X, ABS_HAT0Y }; 552static const short gc_psx_abs[] = {
402static short gc_psx_btn[] = { BTN_TL, BTN_TR, BTN_TL2, BTN_TR2, BTN_A, BTN_B, BTN_X, BTN_Y, 553 ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_HAT0X, ABS_HAT0Y
403 BTN_START, BTN_SELECT, BTN_THUMBL, BTN_THUMBR }; 554};
404static short gc_psx_ddr_btn[] = { BTN_0, BTN_1, BTN_2, BTN_3 }; 555static const short gc_psx_btn[] = {
556 BTN_TL, BTN_TR, BTN_TL2, BTN_TR2, BTN_A, BTN_B, BTN_X, BTN_Y,
557 BTN_START, BTN_SELECT, BTN_THUMBL, BTN_THUMBR
558};
559static const short gc_psx_ddr_btn[] = { BTN_0, BTN_1, BTN_2, BTN_3 };
405 560
406/* 561/*
407 * gc_psx_command() writes 8bit command and reads 8bit data from 562 * gc_psx_command() writes 8bit command and reads 8bit data from
408 * the psx pad. 563 * the psx pad.
409 */ 564 */
410 565
411static void gc_psx_command(struct gc *gc, int b, unsigned char data[GC_MAX_DEVICES]) 566static void gc_psx_command(struct gc *gc, int b, unsigned char *data)
412{ 567{
568 struct parport *port = gc->pd->port;
413 int i, j, cmd, read; 569 int i, j, cmd, read;
414 570
415 for (i = 0; i < GC_MAX_DEVICES; i++) 571 memset(data, 0, GC_MAX_DEVICES);
416 data[i] = 0;
417 572
418 for (i = 0; i < GC_PSX_LENGTH; i++, b >>= 1) { 573 for (i = 0; i < GC_PSX_LENGTH; i++, b >>= 1) {
419 cmd = (b & 1) ? GC_PSX_COMMAND : 0; 574 cmd = (b & 1) ? GC_PSX_COMMAND : 0;
420 parport_write_data(gc->pd->port, cmd | GC_PSX_POWER); 575 parport_write_data(port, cmd | GC_PSX_POWER);
421 udelay(gc_psx_delay); 576 udelay(gc_psx_delay);
422 read = parport_read_status(gc->pd->port) ^ 0x80; 577
423 for (j = 0; j < GC_MAX_DEVICES; j++) 578 read = parport_read_status(port) ^ 0x80;
424 data[j] |= (read & gc_status_bit[j] & (gc->pads[GC_PSX] | gc->pads[GC_DDR])) ? (1 << i) : 0; 579
580 for (j = 0; j < GC_MAX_DEVICES; j++) {
581 struct gc_pad *pad = &gc->pads[i];
582
583 if (pad->type == GC_PSX || pad->type == GC_DDR)
584 data[j] |= (read & gc_status_bit[j]) ? (1 << i) : 0;
585 }
586
425 parport_write_data(gc->pd->port, cmd | GC_PSX_CLOCK | GC_PSX_POWER); 587 parport_write_data(gc->pd->port, cmd | GC_PSX_CLOCK | GC_PSX_POWER);
426 udelay(gc_psx_delay); 588 udelay(gc_psx_delay);
427 } 589 }
@@ -432,31 +594,40 @@ static void gc_psx_command(struct gc *gc, int b, unsigned char data[GC_MAX_DEVIC
432 * device identifier code. 594 * device identifier code.
433 */ 595 */
434 596
435static void gc_psx_read_packet(struct gc *gc, unsigned char data[GC_MAX_DEVICES][GC_PSX_BYTES], 597static void gc_psx_read_packet(struct gc *gc,
598 unsigned char data[GC_MAX_DEVICES][GC_PSX_BYTES],
436 unsigned char id[GC_MAX_DEVICES]) 599 unsigned char id[GC_MAX_DEVICES])
437{ 600{
438 int i, j, max_len = 0; 601 int i, j, max_len = 0;
439 unsigned long flags; 602 unsigned long flags;
440 unsigned char data2[GC_MAX_DEVICES]; 603 unsigned char data2[GC_MAX_DEVICES];
441 604
442 parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER); /* Select pad */ 605 /* Select pad */
606 parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER);
443 udelay(gc_psx_delay); 607 udelay(gc_psx_delay);
444 parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_POWER); /* Deselect, begin command */ 608 /* Deselect, begin command */
609 parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_POWER);
445 udelay(gc_psx_delay); 610 udelay(gc_psx_delay);
446 611
447 local_irq_save(flags); 612 local_irq_save(flags);
448 613
449 gc_psx_command(gc, 0x01, data2); /* Access pad */ 614 gc_psx_command(gc, 0x01, data2); /* Access pad */
450 gc_psx_command(gc, 0x42, id); /* Get device ids */ 615 gc_psx_command(gc, 0x42, id); /* Get device ids */
451 gc_psx_command(gc, 0, data2); /* Dump status */ 616 gc_psx_command(gc, 0, data2); /* Dump status */
617
618 /* Find the longest pad */
619 for (i = 0; i < GC_MAX_DEVICES; i++) {
620 struct gc_pad *pad = &gc->pads[i];
452 621
453 for (i =0; i < GC_MAX_DEVICES; i++) /* Find the longest pad */ 622 if ((pad->type == GC_PSX || pad->type == GC_DDR) &&
454 if((gc_status_bit[i] & (gc->pads[GC_PSX] | gc->pads[GC_DDR])) 623 GC_PSX_LEN(id[i]) > max_len &&
455 && (GC_PSX_LEN(id[i]) > max_len) 624 GC_PSX_LEN(id[i]) <= GC_PSX_BYTES) {
456 && (GC_PSX_LEN(id[i]) <= GC_PSX_BYTES))
457 max_len = GC_PSX_LEN(id[i]); 625 max_len = GC_PSX_LEN(id[i]);
626 }
627 }
458 628
459 for (i = 0; i < max_len; i++) { /* Read in all the data */ 629 /* Read in all the data */
630 for (i = 0; i < max_len; i++) {
460 gc_psx_command(gc, 0, data2); 631 gc_psx_command(gc, 0, data2);
461 for (j = 0; j < GC_MAX_DEVICES; j++) 632 for (j = 0; j < GC_MAX_DEVICES; j++)
462 data[j][i] = data2[j]; 633 data[j][i] = data2[j];
@@ -466,86 +637,104 @@ static void gc_psx_read_packet(struct gc *gc, unsigned char data[GC_MAX_DEVICES]
466 637
467 parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER); 638 parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER);
468 639
469 for(i = 0; i < GC_MAX_DEVICES; i++) /* Set id's to the real value */ 640 /* Set id's to the real value */
641 for (i = 0; i < GC_MAX_DEVICES; i++)
470 id[i] = GC_PSX_ID(id[i]); 642 id[i] = GC_PSX_ID(id[i]);
471} 643}
472 644
473static void gc_psx_process_packet(struct gc *gc) 645static void gc_psx_report_one(struct gc_pad *pad, unsigned char psx_type,
646 unsigned char *data)
474{ 647{
475 unsigned char data[GC_MAX_DEVICES][GC_PSX_BYTES]; 648 struct input_dev *dev = pad->dev;
476 unsigned char id[GC_MAX_DEVICES]; 649 int i;
477 struct input_dev *dev;
478 int i, j;
479 650
480 gc_psx_read_packet(gc, data, id); 651 switch (psx_type) {
481 652
482 for (i = 0; i < GC_MAX_DEVICES; i++) { 653 case GC_PSX_RUMBLE:
483 654
484 dev = gc->dev[i]; 655 input_report_key(dev, BTN_THUMBL, ~data[0] & 0x04);
485 if (!dev) 656 input_report_key(dev, BTN_THUMBR, ~data[0] & 0x02);
486 continue;
487 657
488 switch (id[i]) { 658 case GC_PSX_NEGCON:
659 case GC_PSX_ANALOG:
489 660
490 case GC_PSX_RUMBLE: 661 if (pad->type == GC_DDR) {
662 for (i = 0; i < 4; i++)
663 input_report_key(dev, gc_psx_ddr_btn[i],
664 ~data[0] & (0x10 << i));
665 } else {
666 for (i = 0; i < 4; i++)
667 input_report_abs(dev, gc_psx_abs[i + 2],
668 data[i + 2]);
491 669
492 input_report_key(dev, BTN_THUMBL, ~data[i][0] & 0x04); 670 input_report_abs(dev, ABS_X,
493 input_report_key(dev, BTN_THUMBR, ~data[i][0] & 0x02); 671 !!(data[0] & 0x80) * 128 + !(data[0] & 0x20) * 127);
672 input_report_abs(dev, ABS_Y,
673 !!(data[0] & 0x10) * 128 + !(data[0] & 0x40) * 127);
674 }
494 675
495 case GC_PSX_NEGCON: 676 for (i = 0; i < 8; i++)
496 case GC_PSX_ANALOG: 677 input_report_key(dev, gc_psx_btn[i], ~data[1] & (1 << i));
497 678
498 if (gc->pads[GC_DDR] & gc_status_bit[i]) { 679 input_report_key(dev, BTN_START, ~data[0] & 0x08);
499 for(j = 0; j < 4; j++) 680 input_report_key(dev, BTN_SELECT, ~data[0] & 0x01);
500 input_report_key(dev, gc_psx_ddr_btn[j], ~data[i][0] & (0x10 << j));
501 } else {
502 for (j = 0; j < 4; j++)
503 input_report_abs(dev, gc_psx_abs[j + 2], data[i][j + 2]);
504 681
505 input_report_abs(dev, ABS_X, 128 + !(data[i][0] & 0x20) * 127 - !(data[i][0] & 0x80) * 128); 682 input_sync(dev);
506 input_report_abs(dev, ABS_Y, 128 + !(data[i][0] & 0x40) * 127 - !(data[i][0] & 0x10) * 128);
507 }
508 683
509 for (j = 0; j < 8; j++) 684 break;
510 input_report_key(dev, gc_psx_btn[j], ~data[i][1] & (1 << j));
511 685
512 input_report_key(dev, BTN_START, ~data[i][0] & 0x08); 686 case GC_PSX_NORMAL:
513 input_report_key(dev, BTN_SELECT, ~data[i][0] & 0x01);
514 687
515 input_sync(dev); 688 if (pad->type == GC_DDR) {
689 for (i = 0; i < 4; i++)
690 input_report_key(dev, gc_psx_ddr_btn[i],
691 ~data[0] & (0x10 << i));
692 } else {
693 input_report_abs(dev, ABS_X,
694 !!(data[0] & 0x80) * 128 + !(data[0] & 0x20) * 127);
695 input_report_abs(dev, ABS_Y,
696 !!(data[0] & 0x10) * 128 + !(data[0] & 0x40) * 127);
516 697
517 break; 698 /*
518 699 * For some reason if the extra axes are left unset
519 case GC_PSX_NORMAL: 700 * they drift.
520 if (gc->pads[GC_DDR] & gc_status_bit[i]) { 701 * for (i = 0; i < 4; i++)
521 for(j = 0; j < 4; j++) 702 input_report_abs(dev, gc_psx_abs[i + 2], 128);
522 input_report_key(dev, gc_psx_ddr_btn[j], ~data[i][0] & (0x10 << j)); 703 * This needs to be debugged properly,
523 } else { 704 * maybe fuzz processing needs to be done
524 input_report_abs(dev, ABS_X, 128 + !(data[i][0] & 0x20) * 127 - !(data[i][0] & 0x80) * 128); 705 * in input_sync()
525 input_report_abs(dev, ABS_Y, 128 + !(data[i][0] & 0x40) * 127 - !(data[i][0] & 0x10) * 128); 706 * --vojtech
526 707 */
527 /* for some reason if the extra axes are left unset they drift */ 708 }
528 /* for (j = 0; j < 4; j++)
529 input_report_abs(dev, gc_psx_abs[j + 2], 128);
530 * This needs to be debugged properly,
531 * maybe fuzz processing needs to be done in input_sync()
532 * --vojtech
533 */
534 }
535 709
536 for (j = 0; j < 8; j++) 710 for (i = 0; i < 8; i++)
537 input_report_key(dev, gc_psx_btn[j], ~data[i][1] & (1 << j)); 711 input_report_key(dev, gc_psx_btn[i], ~data[1] & (1 << i));
538 712
539 input_report_key(dev, BTN_START, ~data[i][0] & 0x08); 713 input_report_key(dev, BTN_START, ~data[0] & 0x08);
540 input_report_key(dev, BTN_SELECT, ~data[i][0] & 0x01); 714 input_report_key(dev, BTN_SELECT, ~data[0] & 0x01);
541 715
542 input_sync(dev); 716 input_sync(dev);
543 717
544 break; 718 break;
545 719
546 case 0: /* not a pad, ignore */ 720 default: /* not a pad, ignore */
547 break; 721 break;
548 } 722 }
723}
724
725static void gc_psx_process_packet(struct gc *gc)
726{
727 unsigned char data[GC_MAX_DEVICES][GC_PSX_BYTES];
728 unsigned char id[GC_MAX_DEVICES];
729 struct gc_pad *pad;
730 int i;
731
732 gc_psx_read_packet(gc, data, id);
733
734 for (i = 0; i < GC_MAX_DEVICES; i++) {
735 pad = &gc->pads[i];
736 if (pad->type == GC_PSX || pad->type == GC_DDR)
737 gc_psx_report_one(pad, id[i], data[i]);
549 } 738 }
550} 739}
551 740
@@ -561,28 +750,31 @@ static void gc_timer(unsigned long private)
561 * N64 pads - must be read first, any read confuses them for 200 us 750 * N64 pads - must be read first, any read confuses them for 200 us
562 */ 751 */
563 752
564 if (gc->pads[GC_N64]) 753 if (gc->pad_count[GC_N64])
565 gc_n64_process_packet(gc); 754 gc_n64_process_packet(gc);
566 755
567/* 756/*
568 * NES and SNES pads or mouse 757 * NES and SNES pads or mouse
569 */ 758 */
570 759
571 if (gc->pads[GC_NES] || gc->pads[GC_SNES] || gc->pads[GC_SNESMOUSE]) 760 if (gc->pad_count[GC_NES] ||
761 gc->pad_count[GC_SNES] ||
762 gc->pad_count[GC_SNESMOUSE]) {
572 gc_nes_process_packet(gc); 763 gc_nes_process_packet(gc);
764 }
573 765
574/* 766/*
575 * Multi and Multi2 joysticks 767 * Multi and Multi2 joysticks
576 */ 768 */
577 769
578 if (gc->pads[GC_MULTI] || gc->pads[GC_MULTI2]) 770 if (gc->pad_count[GC_MULTI] || gc->pad_count[GC_MULTI2])
579 gc_multi_process_packet(gc); 771 gc_multi_process_packet(gc);
580 772
581/* 773/*
582 * PSX controllers 774 * PSX controllers
583 */ 775 */
584 776
585 if (gc->pads[GC_PSX] || gc->pads[GC_DDR]) 777 if (gc->pad_count[GC_PSX] || gc->pad_count[GC_DDR])
586 gc_psx_process_packet(gc); 778 gc_psx_process_packet(gc);
587 779
588 mod_timer(&gc->timer, jiffies + GC_REFRESH_TIME); 780 mod_timer(&gc->timer, jiffies + GC_REFRESH_TIME);
@@ -622,25 +814,29 @@ static void gc_close(struct input_dev *dev)
622 814
623static int __init gc_setup_pad(struct gc *gc, int idx, int pad_type) 815static int __init gc_setup_pad(struct gc *gc, int idx, int pad_type)
624{ 816{
817 struct gc_pad *pad = &gc->pads[idx];
625 struct input_dev *input_dev; 818 struct input_dev *input_dev;
626 int i; 819 int i;
627 820 int err;
628 if (!pad_type)
629 return 0;
630 821
631 if (pad_type < 1 || pad_type > GC_MAX) { 822 if (pad_type < 1 || pad_type > GC_MAX) {
632 printk(KERN_WARNING "gamecon.c: Pad type %d unknown\n", pad_type); 823 pr_err("Pad type %d unknown\n", pad_type);
633 return -EINVAL; 824 return -EINVAL;
634 } 825 }
635 826
636 gc->dev[idx] = input_dev = input_allocate_device(); 827 pad->dev = input_dev = input_allocate_device();
637 if (!input_dev) { 828 if (!input_dev) {
638 printk(KERN_ERR "gamecon.c: Not enough memory for input device\n"); 829 pr_err("Not enough memory for input device\n");
639 return -ENOMEM; 830 return -ENOMEM;
640 } 831 }
641 832
833 pad->type = pad_type;
834
835 snprintf(pad->phys, sizeof(pad->phys),
836 "%s/input%d", gc->pd->port->name, idx);
837
642 input_dev->name = gc_names[pad_type]; 838 input_dev->name = gc_names[pad_type];
643 input_dev->phys = gc->phys[idx]; 839 input_dev->phys = pad->phys;
644 input_dev->id.bustype = BUS_PARPORT; 840 input_dev->id.bustype = BUS_PARPORT;
645 input_dev->id.vendor = 0x0001; 841 input_dev->id.vendor = 0x0001;
646 input_dev->id.product = pad_type; 842 input_dev->id.product = pad_type;
@@ -659,61 +855,76 @@ static int __init gc_setup_pad(struct gc *gc, int idx, int pad_type)
659 } else 855 } else
660 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); 856 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
661 857
662 gc->pads[0] |= gc_status_bit[idx]; 858 gc->pad_count[pad_type]++;
663 gc->pads[pad_type] |= gc_status_bit[idx];
664 859
665 switch (pad_type) { 860 switch (pad_type) {
666 861
667 case GC_N64: 862 case GC_N64:
668 for (i = 0; i < 10; i++) 863 for (i = 0; i < 10; i++)
669 set_bit(gc_n64_btn[i], input_dev->keybit); 864 __set_bit(gc_n64_btn[i], input_dev->keybit);
670
671 for (i = 0; i < 2; i++) {
672 input_set_abs_params(input_dev, ABS_X + i, -127, 126, 0, 2);
673 input_set_abs_params(input_dev, ABS_HAT0X + i, -1, 1, 0, 0);
674 }
675
676 break;
677
678 case GC_SNESMOUSE:
679 set_bit(BTN_LEFT, input_dev->keybit);
680 set_bit(BTN_RIGHT, input_dev->keybit);
681 set_bit(REL_X, input_dev->relbit);
682 set_bit(REL_Y, input_dev->relbit);
683 break;
684
685 case GC_SNES:
686 for (i = 4; i < 8; i++)
687 set_bit(gc_snes_btn[i], input_dev->keybit);
688 case GC_NES:
689 for (i = 0; i < 4; i++)
690 set_bit(gc_snes_btn[i], input_dev->keybit);
691 break;
692
693 case GC_MULTI2:
694 set_bit(BTN_THUMB, input_dev->keybit);
695 case GC_MULTI:
696 set_bit(BTN_TRIGGER, input_dev->keybit);
697 break;
698
699 case GC_PSX:
700 for (i = 0; i < 6; i++)
701 input_set_abs_params(input_dev, gc_psx_abs[i], 4, 252, 0, 2);
702 for (i = 0; i < 12; i++)
703 set_bit(gc_psx_btn[i], input_dev->keybit);
704 865
705 break; 866 for (i = 0; i < 2; i++) {
867 input_set_abs_params(input_dev, ABS_X + i, -127, 126, 0, 2);
868 input_set_abs_params(input_dev, ABS_HAT0X + i, -1, 1, 0, 0);
869 }
706 870
707 case GC_DDR: 871 err = gc_n64_init_ff(input_dev, idx);
708 for (i = 0; i < 4; i++) 872 if (err) {
709 set_bit(gc_psx_ddr_btn[i], input_dev->keybit); 873 pr_warning("Failed to initiate rumble for N64 device %d\n", idx);
710 for (i = 0; i < 12; i++) 874 goto err_free_dev;
711 set_bit(gc_psx_btn[i], input_dev->keybit); 875 }
712 876
713 break; 877 break;
878
879 case GC_SNESMOUSE:
880 __set_bit(BTN_LEFT, input_dev->keybit);
881 __set_bit(BTN_RIGHT, input_dev->keybit);
882 __set_bit(REL_X, input_dev->relbit);
883 __set_bit(REL_Y, input_dev->relbit);
884 break;
885
886 case GC_SNES:
887 for (i = 4; i < 8; i++)
888 __set_bit(gc_snes_btn[i], input_dev->keybit);
889 case GC_NES:
890 for (i = 0; i < 4; i++)
891 __set_bit(gc_snes_btn[i], input_dev->keybit);
892 break;
893
894 case GC_MULTI2:
895 __set_bit(BTN_THUMB, input_dev->keybit);
896 case GC_MULTI:
897 __set_bit(BTN_TRIGGER, input_dev->keybit);
898 break;
899
900 case GC_PSX:
901 for (i = 0; i < 6; i++)
902 input_set_abs_params(input_dev,
903 gc_psx_abs[i], 4, 252, 0, 2);
904 for (i = 0; i < 12; i++)
905 __set_bit(gc_psx_btn[i], input_dev->keybit);
906
907 break;
908
909 case GC_DDR:
910 for (i = 0; i < 4; i++)
911 __set_bit(gc_psx_ddr_btn[i], input_dev->keybit);
912 for (i = 0; i < 12; i++)
913 __set_bit(gc_psx_btn[i], input_dev->keybit);
914
915 break;
714 } 916 }
715 917
918 err = input_register_device(pad->dev);
919 if (err)
920 goto err_free_dev;
921
716 return 0; 922 return 0;
923
924err_free_dev:
925 input_free_device(pad->dev);
926 pad->dev = NULL;
927 return err;
717} 928}
718 929
719static struct gc __init *gc_probe(int parport, int *pads, int n_pads) 930static struct gc __init *gc_probe(int parport, int *pads, int n_pads)
@@ -722,52 +933,47 @@ static struct gc __init *gc_probe(int parport, int *pads, int n_pads)
722 struct parport *pp; 933 struct parport *pp;
723 struct pardevice *pd; 934 struct pardevice *pd;
724 int i; 935 int i;
936 int count = 0;
725 int err; 937 int err;
726 938
727 pp = parport_find_number(parport); 939 pp = parport_find_number(parport);
728 if (!pp) { 940 if (!pp) {
729 printk(KERN_ERR "gamecon.c: no such parport\n"); 941 pr_err("no such parport %d\n", parport);
730 err = -EINVAL; 942 err = -EINVAL;
731 goto err_out; 943 goto err_out;
732 } 944 }
733 945
734 pd = parport_register_device(pp, "gamecon", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL); 946 pd = parport_register_device(pp, "gamecon", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);
735 if (!pd) { 947 if (!pd) {
736 printk(KERN_ERR "gamecon.c: parport busy already - lp.o loaded?\n"); 948 pr_err("parport busy already - lp.o loaded?\n");
737 err = -EBUSY; 949 err = -EBUSY;
738 goto err_put_pp; 950 goto err_put_pp;
739 } 951 }
740 952
741 gc = kzalloc(sizeof(struct gc), GFP_KERNEL); 953 gc = kzalloc(sizeof(struct gc), GFP_KERNEL);
742 if (!gc) { 954 if (!gc) {
743 printk(KERN_ERR "gamecon.c: Not enough memory\n"); 955 pr_err("Not enough memory\n");
744 err = -ENOMEM; 956 err = -ENOMEM;
745 goto err_unreg_pardev; 957 goto err_unreg_pardev;
746 } 958 }
747 959
748 mutex_init(&gc->mutex); 960 mutex_init(&gc->mutex);
749 gc->pd = pd; 961 gc->pd = pd;
750 init_timer(&gc->timer); 962 setup_timer(&gc->timer, gc_timer, (long) gc);
751 gc->timer.data = (long) gc;
752 gc->timer.function = gc_timer;
753 963
754 for (i = 0; i < n_pads && i < GC_MAX_DEVICES; i++) { 964 for (i = 0; i < n_pads && i < GC_MAX_DEVICES; i++) {
755 if (!pads[i]) 965 if (!pads[i])
756 continue; 966 continue;
757 967
758 snprintf(gc->phys[i], sizeof(gc->phys[i]),
759 "%s/input%d", gc->pd->port->name, i);
760 err = gc_setup_pad(gc, i, pads[i]); 968 err = gc_setup_pad(gc, i, pads[i]);
761 if (err) 969 if (err)
762 goto err_unreg_devs; 970 goto err_unreg_devs;
763 971
764 err = input_register_device(gc->dev[i]); 972 count++;
765 if (err)
766 goto err_free_dev;
767 } 973 }
768 974
769 if (!gc->pads[0]) { 975 if (count == 0) {
770 printk(KERN_ERR "gamecon.c: No valid devices specified\n"); 976 pr_err("No valid devices specified\n");
771 err = -EINVAL; 977 err = -EINVAL;
772 goto err_free_gc; 978 goto err_free_gc;
773 } 979 }
@@ -775,12 +981,10 @@ static struct gc __init *gc_probe(int parport, int *pads, int n_pads)
775 parport_put_port(pp); 981 parport_put_port(pp);
776 return gc; 982 return gc;
777 983
778 err_free_dev:
779 input_free_device(gc->dev[i]);
780 err_unreg_devs: 984 err_unreg_devs:
781 while (--i >= 0) 985 while (--i >= 0)
782 if (gc->dev[i]) 986 if (gc->pads[i].dev)
783 input_unregister_device(gc->dev[i]); 987 input_unregister_device(gc->pads[i].dev);
784 err_free_gc: 988 err_free_gc:
785 kfree(gc); 989 kfree(gc);
786 err_unreg_pardev: 990 err_unreg_pardev:
@@ -796,8 +1000,8 @@ static void gc_remove(struct gc *gc)
796 int i; 1000 int i;
797 1001
798 for (i = 0; i < GC_MAX_DEVICES; i++) 1002 for (i = 0; i < GC_MAX_DEVICES; i++)
799 if (gc->dev[i]) 1003 if (gc->pads[i].dev)
800 input_unregister_device(gc->dev[i]); 1004 input_unregister_device(gc->pads[i].dev);
801 parport_unregister_device(gc->pd); 1005 parport_unregister_device(gc->pd);
802 kfree(gc); 1006 kfree(gc);
803} 1007}
@@ -813,7 +1017,7 @@ static int __init gc_init(void)
813 continue; 1017 continue;
814 1018
815 if (gc_cfg[i].nargs < 2) { 1019 if (gc_cfg[i].nargs < 2) {
816 printk(KERN_ERR "gamecon.c: at least one device must be specified\n"); 1020 pr_err("at least one device must be specified\n");
817 err = -EINVAL; 1021 err = -EINVAL;
818 break; 1022 break;
819 } 1023 }
diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
index 8a28fb7846dc..9b3353b404da 100644
--- a/drivers/input/joystick/xpad.c
+++ b/drivers/input/joystick/xpad.c
@@ -86,9 +86,8 @@
86 86
87/* xbox d-pads should map to buttons, as is required for DDR pads 87/* xbox d-pads should map to buttons, as is required for DDR pads
88 but we map them to axes when possible to simplify things */ 88 but we map them to axes when possible to simplify things */
89#define MAP_DPAD_TO_BUTTONS 0 89#define MAP_DPAD_TO_BUTTONS (1 << 0)
90#define MAP_DPAD_TO_AXES 1 90#define MAP_TRIGGERS_TO_BUTTONS (1 << 1)
91#define MAP_DPAD_UNKNOWN 2
92 91
93#define XTYPE_XBOX 0 92#define XTYPE_XBOX 0
94#define XTYPE_XBOX360 1 93#define XTYPE_XBOX360 1
@@ -99,57 +98,61 @@ static int dpad_to_buttons;
99module_param(dpad_to_buttons, bool, S_IRUGO); 98module_param(dpad_to_buttons, bool, S_IRUGO);
100MODULE_PARM_DESC(dpad_to_buttons, "Map D-PAD to buttons rather than axes for unknown pads"); 99MODULE_PARM_DESC(dpad_to_buttons, "Map D-PAD to buttons rather than axes for unknown pads");
101 100
101static int triggers_to_buttons;
102module_param(triggers_to_buttons, bool, S_IRUGO);
103MODULE_PARM_DESC(triggers_to_buttons, "Map triggers to buttons rather than axes for unknown pads");
104
102static const struct xpad_device { 105static const struct xpad_device {
103 u16 idVendor; 106 u16 idVendor;
104 u16 idProduct; 107 u16 idProduct;
105 char *name; 108 char *name;
106 u8 dpad_mapping; 109 u8 mapping;
107 u8 xtype; 110 u8 xtype;
108} xpad_device[] = { 111} xpad_device[] = {
109 { 0x045e, 0x0202, "Microsoft X-Box pad v1 (US)", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 112 { 0x045e, 0x0202, "Microsoft X-Box pad v1 (US)", 0, XTYPE_XBOX },
110 { 0x045e, 0x0289, "Microsoft X-Box pad v2 (US)", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 113 { 0x045e, 0x0289, "Microsoft X-Box pad v2 (US)", 0, XTYPE_XBOX },
111 { 0x045e, 0x0285, "Microsoft X-Box pad (Japan)", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 114 { 0x045e, 0x0285, "Microsoft X-Box pad (Japan)", 0, XTYPE_XBOX },
112 { 0x045e, 0x0287, "Microsoft Xbox Controller S", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 115 { 0x045e, 0x0287, "Microsoft Xbox Controller S", 0, XTYPE_XBOX },
113 { 0x045e, 0x0719, "Xbox 360 Wireless Receiver", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W }, 116 { 0x045e, 0x0719, "Xbox 360 Wireless Receiver", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360W },
114 { 0x0c12, 0x8809, "RedOctane Xbox Dance Pad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX }, 117 { 0x0c12, 0x8809, "RedOctane Xbox Dance Pad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
115 { 0x044f, 0x0f07, "Thrustmaster, Inc. Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 118 { 0x044f, 0x0f07, "Thrustmaster, Inc. Controller", 0, XTYPE_XBOX },
116 { 0x046d, 0xc242, "Logitech Chillstream Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX360 }, 119 { 0x046d, 0xc242, "Logitech Chillstream Controller", 0, XTYPE_XBOX360 },
117 { 0x046d, 0xca84, "Logitech Xbox Cordless Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 120 { 0x046d, 0xca84, "Logitech Xbox Cordless Controller", 0, XTYPE_XBOX },
118 { 0x046d, 0xca88, "Logitech Compact Controller for Xbox", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 121 { 0x046d, 0xca88, "Logitech Compact Controller for Xbox", 0, XTYPE_XBOX },
119 { 0x05fd, 0x1007, "Mad Catz Controller (unverified)", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 122 { 0x05fd, 0x1007, "Mad Catz Controller (unverified)", 0, XTYPE_XBOX },
120 { 0x05fd, 0x107a, "InterAct 'PowerPad Pro' X-Box pad (Germany)", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 123 { 0x05fd, 0x107a, "InterAct 'PowerPad Pro' X-Box pad (Germany)", 0, XTYPE_XBOX },
121 { 0x0738, 0x4516, "Mad Catz Control Pad", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 124 { 0x0738, 0x4516, "Mad Catz Control Pad", 0, XTYPE_XBOX },
122 { 0x0738, 0x4522, "Mad Catz LumiCON", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 125 { 0x0738, 0x4522, "Mad Catz LumiCON", 0, XTYPE_XBOX },
123 { 0x0738, 0x4526, "Mad Catz Control Pad Pro", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 126 { 0x0738, 0x4526, "Mad Catz Control Pad Pro", 0, XTYPE_XBOX },
124 { 0x0738, 0x4536, "Mad Catz MicroCON", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 127 { 0x0738, 0x4536, "Mad Catz MicroCON", 0, XTYPE_XBOX },
125 { 0x0738, 0x4540, "Mad Catz Beat Pad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX }, 128 { 0x0738, 0x4540, "Mad Catz Beat Pad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
126 { 0x0738, 0x4556, "Mad Catz Lynx Wireless Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 129 { 0x0738, 0x4556, "Mad Catz Lynx Wireless Controller", 0, XTYPE_XBOX },
127 { 0x0738, 0x4716, "Mad Catz Wired Xbox 360 Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX360 }, 130 { 0x0738, 0x4716, "Mad Catz Wired Xbox 360 Controller", 0, XTYPE_XBOX360 },
128 { 0x0738, 0x4738, "Mad Catz Wired Xbox 360 Controller (SFIV)", MAP_DPAD_TO_AXES, XTYPE_XBOX360 }, 131 { 0x0738, 0x4738, "Mad Catz Wired Xbox 360 Controller (SFIV)", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
129 { 0x0738, 0x6040, "Mad Catz Beat Pad Pro", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX }, 132 { 0x0738, 0x6040, "Mad Catz Beat Pad Pro", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
130 { 0x0c12, 0x8802, "Zeroplus Xbox Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 133 { 0x0c12, 0x8802, "Zeroplus Xbox Controller", 0, XTYPE_XBOX },
131 { 0x0c12, 0x880a, "Pelican Eclipse PL-2023", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 134 { 0x0c12, 0x880a, "Pelican Eclipse PL-2023", 0, XTYPE_XBOX },
132 { 0x0c12, 0x8810, "Zeroplus Xbox Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 135 { 0x0c12, 0x8810, "Zeroplus Xbox Controller", 0, XTYPE_XBOX },
133 { 0x0c12, 0x9902, "HAMA VibraX - *FAULTY HARDWARE*", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 136 { 0x0c12, 0x9902, "HAMA VibraX - *FAULTY HARDWARE*", 0, XTYPE_XBOX },
134 { 0x0e4c, 0x1097, "Radica Gamester Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 137 { 0x0e4c, 0x1097, "Radica Gamester Controller", 0, XTYPE_XBOX },
135 { 0x0e4c, 0x2390, "Radica Games Jtech Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 138 { 0x0e4c, 0x2390, "Radica Games Jtech Controller", 0, XTYPE_XBOX },
136 { 0x0e6f, 0x0003, "Logic3 Freebird wireless Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 139 { 0x0e6f, 0x0003, "Logic3 Freebird wireless Controller", 0, XTYPE_XBOX },
137 { 0x0e6f, 0x0005, "Eclipse wireless Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 140 { 0x0e6f, 0x0005, "Eclipse wireless Controller", 0, XTYPE_XBOX },
138 { 0x0e6f, 0x0006, "Edge wireless Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 141 { 0x0e6f, 0x0006, "Edge wireless Controller", 0, XTYPE_XBOX },
139 { 0x0e6f, 0x0006, "Pelican 'TSZ' Wired Xbox 360 Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX360 }, 142 { 0x0e6f, 0x0006, "Pelican 'TSZ' Wired Xbox 360 Controller", 0, XTYPE_XBOX360 },
140 { 0x0e8f, 0x0201, "SmartJoy Frag Xpad/PS2 adaptor", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 143 { 0x0e8f, 0x0201, "SmartJoy Frag Xpad/PS2 adaptor", 0, XTYPE_XBOX },
141 { 0x0f30, 0x0202, "Joytech Advanced Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 144 { 0x0f30, 0x0202, "Joytech Advanced Controller", 0, XTYPE_XBOX },
142 { 0x0f30, 0x8888, "BigBen XBMiniPad Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 145 { 0x0f30, 0x8888, "BigBen XBMiniPad Controller", 0, XTYPE_XBOX },
143 { 0x102c, 0xff0c, "Joytech Wireless Advanced Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 146 { 0x102c, 0xff0c, "Joytech Wireless Advanced Controller", 0, XTYPE_XBOX },
144 { 0x12ab, 0x8809, "Xbox DDR dancepad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX }, 147 { 0x12ab, 0x8809, "Xbox DDR dancepad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
145 { 0x1430, 0x4748, "RedOctane Guitar Hero X-plorer", MAP_DPAD_TO_AXES, XTYPE_XBOX360 }, 148 { 0x1430, 0x4748, "RedOctane Guitar Hero X-plorer", 0, XTYPE_XBOX360 },
146 { 0x1430, 0x8888, "TX6500+ Dance Pad (first generation)", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX }, 149 { 0x1430, 0x8888, "TX6500+ Dance Pad (first generation)", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX },
147 { 0x146b, 0x0601, "BigBen Interactive XBOX 360 Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX360 }, 150 { 0x146b, 0x0601, "BigBen Interactive XBOX 360 Controller", 0, XTYPE_XBOX360 },
148 { 0x045e, 0x028e, "Microsoft X-Box 360 pad", MAP_DPAD_TO_AXES, XTYPE_XBOX360 }, 151 { 0x045e, 0x028e, "Microsoft X-Box 360 pad", 0, XTYPE_XBOX360 },
149 { 0x1bad, 0x0003, "Harmonix Rock Band Drumkit", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 }, 152 { 0x1bad, 0x0003, "Harmonix Rock Band Drumkit", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX360 },
150 { 0x0f0d, 0x0016, "Hori Real Arcade Pro.EX", MAP_DPAD_TO_AXES, XTYPE_XBOX360 }, 153 { 0x0f0d, 0x0016, "Hori Real Arcade Pro.EX", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 },
151 { 0xffff, 0xffff, "Chinese-made Xbox Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, 154 { 0xffff, 0xffff, "Chinese-made Xbox Controller", 0, XTYPE_XBOX },
152 { 0x0000, 0x0000, "Generic X-Box pad", MAP_DPAD_UNKNOWN, XTYPE_UNKNOWN } 155 { 0x0000, 0x0000, "Generic X-Box pad", 0, XTYPE_UNKNOWN }
153}; 156};
154 157
155/* buttons shared with xbox and xbox360 */ 158/* buttons shared with xbox and xbox360 */
@@ -165,13 +168,20 @@ static const signed short xpad_btn[] = {
165 -1 /* terminating entry */ 168 -1 /* terminating entry */
166}; 169};
167 170
168/* only used if MAP_DPAD_TO_BUTTONS */ 171/* used when dpad is mapped to nuttons */
169static const signed short xpad_btn_pad[] = { 172static const signed short xpad_btn_pad[] = {
170 BTN_LEFT, BTN_RIGHT, /* d-pad left, right */ 173 BTN_LEFT, BTN_RIGHT, /* d-pad left, right */
171 BTN_0, BTN_1, /* d-pad up, down (XXX names??) */ 174 BTN_0, BTN_1, /* d-pad up, down (XXX names??) */
172 -1 /* terminating entry */ 175 -1 /* terminating entry */
173}; 176};
174 177
178/* used when triggers are mapped to buttons */
179static const signed short xpad_btn_triggers[] = {
180 BTN_TL2, BTN_TR2, /* triggers left/right */
181 -1
182};
183
184
175static const signed short xpad360_btn[] = { /* buttons for x360 controller */ 185static const signed short xpad360_btn[] = { /* buttons for x360 controller */
176 BTN_TL, BTN_TR, /* Button LB/RB */ 186 BTN_TL, BTN_TR, /* Button LB/RB */
177 BTN_MODE, /* The big X button */ 187 BTN_MODE, /* The big X button */
@@ -181,16 +191,21 @@ static const signed short xpad360_btn[] = { /* buttons for x360 controller */
181static const signed short xpad_abs[] = { 191static const signed short xpad_abs[] = {
182 ABS_X, ABS_Y, /* left stick */ 192 ABS_X, ABS_Y, /* left stick */
183 ABS_RX, ABS_RY, /* right stick */ 193 ABS_RX, ABS_RY, /* right stick */
184 ABS_Z, ABS_RZ, /* triggers left/right */
185 -1 /* terminating entry */ 194 -1 /* terminating entry */
186}; 195};
187 196
188/* only used if MAP_DPAD_TO_AXES */ 197/* used when dpad is mapped to axes */
189static const signed short xpad_abs_pad[] = { 198static const signed short xpad_abs_pad[] = {
190 ABS_HAT0X, ABS_HAT0Y, /* d-pad axes */ 199 ABS_HAT0X, ABS_HAT0Y, /* d-pad axes */
191 -1 /* terminating entry */ 200 -1 /* terminating entry */
192}; 201};
193 202
203/* used when triggers are mapped to axes */
204static const signed short xpad_abs_triggers[] = {
205 ABS_Z, ABS_RZ, /* triggers left/right */
206 -1
207};
208
194/* Xbox 360 has a vendor-specific class, so we cannot match it with only 209/* Xbox 360 has a vendor-specific class, so we cannot match it with only
195 * USB_INTERFACE_INFO (also specifically refused by USB subsystem), so we 210 * USB_INTERFACE_INFO (also specifically refused by USB subsystem), so we
196 * match against vendor id as well. Wired Xbox 360 devices have protocol 1, 211 * match against vendor id as well. Wired Xbox 360 devices have protocol 1,
@@ -246,7 +261,7 @@ struct usb_xpad {
246 261
247 char phys[64]; /* physical device path */ 262 char phys[64]; /* physical device path */
248 263
249 int dpad_mapping; /* map d-pad to buttons or to axes */ 264 int mapping; /* map d-pad to buttons or to axes */
250 int xtype; /* type of xbox device */ 265 int xtype; /* type of xbox device */
251}; 266};
252 267
@@ -277,20 +292,25 @@ static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *d
277 ~(__s16) le16_to_cpup((__le16 *)(data + 18))); 292 ~(__s16) le16_to_cpup((__le16 *)(data + 18)));
278 293
279 /* triggers left/right */ 294 /* triggers left/right */
280 input_report_abs(dev, ABS_Z, data[10]); 295 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) {
281 input_report_abs(dev, ABS_RZ, data[11]); 296 input_report_key(dev, BTN_TL2, data[10]);
297 input_report_key(dev, BTN_TR2, data[11]);
298 } else {
299 input_report_abs(dev, ABS_Z, data[10]);
300 input_report_abs(dev, ABS_RZ, data[11]);
301 }
282 302
283 /* digital pad */ 303 /* digital pad */
284 if (xpad->dpad_mapping == MAP_DPAD_TO_AXES) { 304 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) {
285 input_report_abs(dev, ABS_HAT0X,
286 !!(data[2] & 0x08) - !!(data[2] & 0x04));
287 input_report_abs(dev, ABS_HAT0Y,
288 !!(data[2] & 0x02) - !!(data[2] & 0x01));
289 } else /* xpad->dpad_mapping == MAP_DPAD_TO_BUTTONS */ {
290 input_report_key(dev, BTN_LEFT, data[2] & 0x04); 305 input_report_key(dev, BTN_LEFT, data[2] & 0x04);
291 input_report_key(dev, BTN_RIGHT, data[2] & 0x08); 306 input_report_key(dev, BTN_RIGHT, data[2] & 0x08);
292 input_report_key(dev, BTN_0, data[2] & 0x01); /* up */ 307 input_report_key(dev, BTN_0, data[2] & 0x01); /* up */
293 input_report_key(dev, BTN_1, data[2] & 0x02); /* down */ 308 input_report_key(dev, BTN_1, data[2] & 0x02); /* down */
309 } else {
310 input_report_abs(dev, ABS_HAT0X,
311 !!(data[2] & 0x08) - !!(data[2] & 0x04));
312 input_report_abs(dev, ABS_HAT0Y,
313 !!(data[2] & 0x02) - !!(data[2] & 0x01));
294 } 314 }
295 315
296 /* start/back buttons and stick press left/right */ 316 /* start/back buttons and stick press left/right */
@@ -328,17 +348,17 @@ static void xpad360_process_packet(struct usb_xpad *xpad,
328 struct input_dev *dev = xpad->dev; 348 struct input_dev *dev = xpad->dev;
329 349
330 /* digital pad */ 350 /* digital pad */
331 if (xpad->dpad_mapping == MAP_DPAD_TO_AXES) { 351 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) {
332 input_report_abs(dev, ABS_HAT0X,
333 !!(data[2] & 0x08) - !!(data[2] & 0x04));
334 input_report_abs(dev, ABS_HAT0Y,
335 !!(data[2] & 0x02) - !!(data[2] & 0x01));
336 } else if (xpad->dpad_mapping == MAP_DPAD_TO_BUTTONS) {
337 /* dpad as buttons (right, left, down, up) */ 352 /* dpad as buttons (right, left, down, up) */
338 input_report_key(dev, BTN_LEFT, data[2] & 0x04); 353 input_report_key(dev, BTN_LEFT, data[2] & 0x04);
339 input_report_key(dev, BTN_RIGHT, data[2] & 0x08); 354 input_report_key(dev, BTN_RIGHT, data[2] & 0x08);
340 input_report_key(dev, BTN_0, data[2] & 0x01); /* up */ 355 input_report_key(dev, BTN_0, data[2] & 0x01); /* up */
341 input_report_key(dev, BTN_1, data[2] & 0x02); /* down */ 356 input_report_key(dev, BTN_1, data[2] & 0x02); /* down */
357 } else {
358 input_report_abs(dev, ABS_HAT0X,
359 !!(data[2] & 0x08) - !!(data[2] & 0x04));
360 input_report_abs(dev, ABS_HAT0Y,
361 !!(data[2] & 0x02) - !!(data[2] & 0x01));
342 } 362 }
343 363
344 /* start/back buttons */ 364 /* start/back buttons */
@@ -371,8 +391,13 @@ static void xpad360_process_packet(struct usb_xpad *xpad,
371 ~(__s16) le16_to_cpup((__le16 *)(data + 12))); 391 ~(__s16) le16_to_cpup((__le16 *)(data + 12)));
372 392
373 /* triggers left/right */ 393 /* triggers left/right */
374 input_report_abs(dev, ABS_Z, data[4]); 394 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) {
375 input_report_abs(dev, ABS_RZ, data[5]); 395 input_report_key(dev, BTN_TL2, data[4]);
396 input_report_key(dev, BTN_TR2, data[5]);
397 } else {
398 input_report_abs(dev, ABS_Z, data[4]);
399 input_report_abs(dev, ABS_RZ, data[5]);
400 }
376 401
377 input_sync(dev); 402 input_sync(dev);
378} 403}
@@ -505,7 +530,7 @@ static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad)
505 struct usb_endpoint_descriptor *ep_irq_out; 530 struct usb_endpoint_descriptor *ep_irq_out;
506 int error = -ENOMEM; 531 int error = -ENOMEM;
507 532
508 if (xpad->xtype != XTYPE_XBOX360) 533 if (xpad->xtype != XTYPE_XBOX360 && xpad->xtype != XTYPE_XBOX)
509 return 0; 534 return 0;
510 535
511 xpad->odata = usb_buffer_alloc(xpad->udev, XPAD_PKT_LEN, 536 xpad->odata = usb_buffer_alloc(xpad->udev, XPAD_PKT_LEN,
@@ -535,13 +560,13 @@ static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad)
535 560
536static void xpad_stop_output(struct usb_xpad *xpad) 561static void xpad_stop_output(struct usb_xpad *xpad)
537{ 562{
538 if (xpad->xtype == XTYPE_XBOX360) 563 if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype == XTYPE_XBOX)
539 usb_kill_urb(xpad->irq_out); 564 usb_kill_urb(xpad->irq_out);
540} 565}
541 566
542static void xpad_deinit_output(struct usb_xpad *xpad) 567static void xpad_deinit_output(struct usb_xpad *xpad)
543{ 568{
544 if (xpad->xtype == XTYPE_XBOX360) { 569 if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype == XTYPE_XBOX) {
545 usb_free_urb(xpad->irq_out); 570 usb_free_urb(xpad->irq_out);
546 usb_buffer_free(xpad->udev, XPAD_PKT_LEN, 571 usb_buffer_free(xpad->udev, XPAD_PKT_LEN,
547 xpad->odata, xpad->odata_dma); 572 xpad->odata, xpad->odata_dma);
@@ -554,24 +579,45 @@ static void xpad_stop_output(struct usb_xpad *xpad) {}
554#endif 579#endif
555 580
556#ifdef CONFIG_JOYSTICK_XPAD_FF 581#ifdef CONFIG_JOYSTICK_XPAD_FF
557static int xpad_play_effect(struct input_dev *dev, void *data, 582static int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect *effect)
558 struct ff_effect *effect)
559{ 583{
560 struct usb_xpad *xpad = input_get_drvdata(dev); 584 struct usb_xpad *xpad = input_get_drvdata(dev);
561 585
562 if (effect->type == FF_RUMBLE) { 586 if (effect->type == FF_RUMBLE) {
563 __u16 strong = effect->u.rumble.strong_magnitude; 587 __u16 strong = effect->u.rumble.strong_magnitude;
564 __u16 weak = effect->u.rumble.weak_magnitude; 588 __u16 weak = effect->u.rumble.weak_magnitude;
565 xpad->odata[0] = 0x00; 589
566 xpad->odata[1] = 0x08; 590 switch (xpad->xtype) {
567 xpad->odata[2] = 0x00; 591
568 xpad->odata[3] = strong / 256; 592 case XTYPE_XBOX:
569 xpad->odata[4] = weak / 256; 593 xpad->odata[0] = 0x00;
570 xpad->odata[5] = 0x00; 594 xpad->odata[1] = 0x06;
571 xpad->odata[6] = 0x00; 595 xpad->odata[2] = 0x00;
572 xpad->odata[7] = 0x00; 596 xpad->odata[3] = strong / 256; /* left actuator */
573 xpad->irq_out->transfer_buffer_length = 8; 597 xpad->odata[4] = 0x00;
574 usb_submit_urb(xpad->irq_out, GFP_ATOMIC); 598 xpad->odata[5] = weak / 256; /* right actuator */
599 xpad->irq_out->transfer_buffer_length = 6;
600
601 return usb_submit_urb(xpad->irq_out, GFP_ATOMIC);
602
603 case XTYPE_XBOX360:
604 xpad->odata[0] = 0x00;
605 xpad->odata[1] = 0x08;
606 xpad->odata[2] = 0x00;
607 xpad->odata[3] = strong / 256; /* left actuator? */
608 xpad->odata[4] = weak / 256; /* right actuator? */
609 xpad->odata[5] = 0x00;
610 xpad->odata[6] = 0x00;
611 xpad->odata[7] = 0x00;
612 xpad->irq_out->transfer_buffer_length = 8;
613
614 return usb_submit_urb(xpad->irq_out, GFP_ATOMIC);
615
616 default:
617 dbg("%s - rumble command sent to unsupported xpad type: %d",
618 __func__, xpad->xtype);
619 return -1;
620 }
575 } 621 }
576 622
577 return 0; 623 return 0;
@@ -579,7 +625,7 @@ static int xpad_play_effect(struct input_dev *dev, void *data,
579 625
580static int xpad_init_ff(struct usb_xpad *xpad) 626static int xpad_init_ff(struct usb_xpad *xpad)
581{ 627{
582 if (xpad->xtype != XTYPE_XBOX360) 628 if (xpad->xtype != XTYPE_XBOX360 && xpad->xtype != XTYPE_XBOX)
583 return 0; 629 return 0;
584 630
585 input_set_capability(xpad->dev, EV_FF, FF_RUMBLE); 631 input_set_capability(xpad->dev, EV_FF, FF_RUMBLE);
@@ -712,11 +758,11 @@ static void xpad_set_up_abs(struct input_dev *input_dev, signed short abs)
712 input_set_abs_params(input_dev, abs, -32768, 32767, 16, 128); 758 input_set_abs_params(input_dev, abs, -32768, 32767, 16, 128);
713 break; 759 break;
714 case ABS_Z: 760 case ABS_Z:
715 case ABS_RZ: /* the triggers */ 761 case ABS_RZ: /* the triggers (if mapped to axes) */
716 input_set_abs_params(input_dev, abs, 0, 255, 0, 0); 762 input_set_abs_params(input_dev, abs, 0, 255, 0, 0);
717 break; 763 break;
718 case ABS_HAT0X: 764 case ABS_HAT0X:
719 case ABS_HAT0Y: /* the d-pad (only if MAP_DPAD_TO_AXES) */ 765 case ABS_HAT0Y: /* the d-pad (only if dpad is mapped to axes */
720 input_set_abs_params(input_dev, abs, -1, 1, 0, 0); 766 input_set_abs_params(input_dev, abs, -1, 1, 0, 0);
721 break; 767 break;
722 } 768 }
@@ -752,10 +798,9 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
752 goto fail2; 798 goto fail2;
753 799
754 xpad->udev = udev; 800 xpad->udev = udev;
755 xpad->dpad_mapping = xpad_device[i].dpad_mapping; 801 xpad->mapping = xpad_device[i].mapping;
756 xpad->xtype = xpad_device[i].xtype; 802 xpad->xtype = xpad_device[i].xtype;
757 if (xpad->dpad_mapping == MAP_DPAD_UNKNOWN) 803
758 xpad->dpad_mapping = !dpad_to_buttons;
759 if (xpad->xtype == XTYPE_UNKNOWN) { 804 if (xpad->xtype == XTYPE_UNKNOWN) {
760 if (intf->cur_altsetting->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC) { 805 if (intf->cur_altsetting->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC) {
761 if (intf->cur_altsetting->desc.bInterfaceProtocol == 129) 806 if (intf->cur_altsetting->desc.bInterfaceProtocol == 129)
@@ -764,7 +809,13 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
764 xpad->xtype = XTYPE_XBOX360; 809 xpad->xtype = XTYPE_XBOX360;
765 } else 810 } else
766 xpad->xtype = XTYPE_XBOX; 811 xpad->xtype = XTYPE_XBOX;
812
813 if (dpad_to_buttons)
814 xpad->mapping |= MAP_DPAD_TO_BUTTONS;
815 if (triggers_to_buttons)
816 xpad->mapping |= MAP_TRIGGERS_TO_BUTTONS;
767 } 817 }
818
768 xpad->dev = input_dev; 819 xpad->dev = input_dev;
769 usb_make_path(udev, xpad->phys, sizeof(xpad->phys)); 820 usb_make_path(udev, xpad->phys, sizeof(xpad->phys));
770 strlcat(xpad->phys, "/input0", sizeof(xpad->phys)); 821 strlcat(xpad->phys, "/input0", sizeof(xpad->phys));
@@ -781,25 +832,37 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id
781 832
782 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 833 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
783 834
784 /* set up buttons */ 835 /* set up standard buttons and axes */
785 for (i = 0; xpad_common_btn[i] >= 0; i++) 836 for (i = 0; xpad_common_btn[i] >= 0; i++)
786 set_bit(xpad_common_btn[i], input_dev->keybit); 837 __set_bit(xpad_common_btn[i], input_dev->keybit);
787 if ((xpad->xtype == XTYPE_XBOX360) || (xpad->xtype == XTYPE_XBOX360W))
788 for (i = 0; xpad360_btn[i] >= 0; i++)
789 set_bit(xpad360_btn[i], input_dev->keybit);
790 else
791 for (i = 0; xpad_btn[i] >= 0; i++)
792 set_bit(xpad_btn[i], input_dev->keybit);
793 if (xpad->dpad_mapping == MAP_DPAD_TO_BUTTONS)
794 for (i = 0; xpad_btn_pad[i] >= 0; i++)
795 set_bit(xpad_btn_pad[i], input_dev->keybit);
796 838
797 /* set up axes */
798 for (i = 0; xpad_abs[i] >= 0; i++) 839 for (i = 0; xpad_abs[i] >= 0; i++)
799 xpad_set_up_abs(input_dev, xpad_abs[i]); 840 xpad_set_up_abs(input_dev, xpad_abs[i]);
800 if (xpad->dpad_mapping == MAP_DPAD_TO_AXES) 841
842 /* Now set up model-specific ones */
843 if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype == XTYPE_XBOX360W) {
844 for (i = 0; xpad360_btn[i] >= 0; i++)
845 __set_bit(xpad360_btn[i], input_dev->keybit);
846 } else {
847 for (i = 0; xpad_btn[i] >= 0; i++)
848 __set_bit(xpad_btn[i], input_dev->keybit);
849 }
850
851 if (xpad->mapping & MAP_DPAD_TO_BUTTONS) {
852 for (i = 0; xpad_btn_pad[i] >= 0; i++)
853 __set_bit(xpad_btn_pad[i], input_dev->keybit);
854 } else {
801 for (i = 0; xpad_abs_pad[i] >= 0; i++) 855 for (i = 0; xpad_abs_pad[i] >= 0; i++)
802 xpad_set_up_abs(input_dev, xpad_abs_pad[i]); 856 xpad_set_up_abs(input_dev, xpad_abs_pad[i]);
857 }
858
859 if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) {
860 for (i = 0; xpad_btn_triggers[i] >= 0; i++)
861 __set_bit(xpad_btn_triggers[i], input_dev->keybit);
862 } else {
863 for (i = 0; xpad_abs_triggers[i] >= 0; i++)
864 xpad_set_up_abs(input_dev, xpad_abs_triggers[i]);
865 }
803 866
804 error = xpad_init_output(intf, xpad); 867 error = xpad_init_output(intf, xpad);
805 if (error) 868 if (error)
diff --git a/drivers/input/keyboard/Kconfig b/drivers/input/keyboard/Kconfig
index 02c836e11813..64c102355f53 100644
--- a/drivers/input/keyboard/Kconfig
+++ b/drivers/input/keyboard/Kconfig
@@ -35,10 +35,10 @@ config KEYBOARD_ADP5520
35 be called adp5520-keys. 35 be called adp5520-keys.
36 36
37config KEYBOARD_ADP5588 37config KEYBOARD_ADP5588
38 tristate "ADP5588 I2C QWERTY Keypad and IO Expander" 38 tristate "ADP5588/87 I2C QWERTY Keypad and IO Expander"
39 depends on I2C 39 depends on I2C
40 help 40 help
41 Say Y here if you want to use a ADP5588 attached to your 41 Say Y here if you want to use a ADP5588/87 attached to your
42 system I2C bus. 42 system I2C bus.
43 43
44 To compile this driver as a module, choose M here: the 44 To compile this driver as a module, choose M here: the
@@ -144,13 +144,15 @@ config KEYBOARD_BFIN
144 module will be called bf54x-keys. 144 module will be called bf54x-keys.
145 145
146config KEYBOARD_CORGI 146config KEYBOARD_CORGI
147 tristate "Corgi keyboard" 147 tristate "Corgi keyboard (deprecated)"
148 depends on PXA_SHARPSL 148 depends on PXA_SHARPSL
149 default y
150 help 149 help
151 Say Y here to enable the keyboard on the Sharp Zaurus SL-C7xx 150 Say Y here to enable the keyboard on the Sharp Zaurus SL-C7xx
152 series of PDAs. 151 series of PDAs.
153 152
153 This driver is now deprecated, use generic GPIO based matrix
154 keyboard driver instead.
155
154 To compile this driver as a module, choose M here: the 156 To compile this driver as a module, choose M here: the
155 module will be called corgikbd. 157 module will be called corgikbd.
156 158
@@ -292,6 +294,15 @@ config KEYBOARD_MAX7359
292 To compile this driver as a module, choose M here: the 294 To compile this driver as a module, choose M here: the
293 module will be called max7359_keypad. 295 module will be called max7359_keypad.
294 296
297config KEYBOARD_IMX
298 tristate "IMX keypad support"
299 depends on ARCH_MXC
300 help
301 Enable support for IMX keypad port.
302
303 To compile this driver as a module, choose M here: the
304 module will be called imx_keypad.
305
295config KEYBOARD_NEWTON 306config KEYBOARD_NEWTON
296 tristate "Newton keyboard" 307 tristate "Newton keyboard"
297 select SERIO 308 select SERIO
@@ -329,13 +340,15 @@ config KEYBOARD_PXA930_ROTARY
329 module will be called pxa930_rotary. 340 module will be called pxa930_rotary.
330 341
331config KEYBOARD_SPITZ 342config KEYBOARD_SPITZ
332 tristate "Spitz keyboard" 343 tristate "Spitz keyboard (deprecated)"
333 depends on PXA_SHARPSL 344 depends on PXA_SHARPSL
334 default y
335 help 345 help
336 Say Y here to enable the keyboard on the Sharp Zaurus SL-C1000, 346 Say Y here to enable the keyboard on the Sharp Zaurus SL-C1000,
337 SL-C3000 and Sl-C3100 series of PDAs. 347 SL-C3000 and Sl-C3100 series of PDAs.
338 348
349 This driver is now deprecated, use generic GPIO based matrix
350 keyboard driver instead.
351
339 To compile this driver as a module, choose M here: the 352 To compile this driver as a module, choose M here: the
340 module will be called spitzkbd. 353 module will be called spitzkbd.
341 354
@@ -363,7 +376,7 @@ config KEYBOARD_SUNKBD
363 376
364config KEYBOARD_SH_KEYSC 377config KEYBOARD_SH_KEYSC
365 tristate "SuperH KEYSC keypad support" 378 tristate "SuperH KEYSC keypad support"
366 depends on SUPERH 379 depends on SUPERH || ARCH_SHMOBILE
367 help 380 help
368 Say Y here if you want to use a keypad attached to the KEYSC block 381 Say Y here if you want to use a keypad attached to the KEYSC block
369 on SuperH processors such as sh7722 and sh7343. 382 on SuperH processors such as sh7722 and sh7343.
@@ -402,12 +415,14 @@ config KEYBOARD_TWL4030
402 module will be called twl4030_keypad. 415 module will be called twl4030_keypad.
403 416
404config KEYBOARD_TOSA 417config KEYBOARD_TOSA
405 tristate "Tosa keyboard" 418 tristate "Tosa keyboard (deprecated)"
406 depends on MACH_TOSA 419 depends on MACH_TOSA
407 default y
408 help 420 help
409 Say Y here to enable the keyboard on the Sharp Zaurus SL-6000x (Tosa) 421 Say Y here to enable the keyboard on the Sharp Zaurus SL-6000x (Tosa)
410 422
423 This driver is now deprecated, use generic GPIO based matrix
424 keyboard driver instead.
425
411 To compile this driver as a module, choose M here: the 426 To compile this driver as a module, choose M here: the
412 module will be called tosakbd. 427 module will be called tosakbd.
413 428
diff --git a/drivers/input/keyboard/Makefile b/drivers/input/keyboard/Makefile
index 78654ef65206..706c6b5ed5f4 100644
--- a/drivers/input/keyboard/Makefile
+++ b/drivers/input/keyboard/Makefile
@@ -17,6 +17,7 @@ obj-$(CONFIG_KEYBOARD_EP93XX) += ep93xx_keypad.o
17obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o 17obj-$(CONFIG_KEYBOARD_GPIO) += gpio_keys.o
18obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o 18obj-$(CONFIG_KEYBOARD_HIL) += hil_kbd.o
19obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o 19obj-$(CONFIG_KEYBOARD_HIL_OLD) += hilkbd.o
20obj-$(CONFIG_KEYBOARD_IMX) += imx_keypad.o
20obj-$(CONFIG_KEYBOARD_HP6XX) += jornada680_kbd.o 21obj-$(CONFIG_KEYBOARD_HP6XX) += jornada680_kbd.o
21obj-$(CONFIG_KEYBOARD_HP7XX) += jornada720_kbd.o 22obj-$(CONFIG_KEYBOARD_HP7XX) += jornada720_kbd.o
22obj-$(CONFIG_KEYBOARD_LKKBD) += lkkbd.o 23obj-$(CONFIG_KEYBOARD_LKKBD) += lkkbd.o
diff --git a/drivers/input/keyboard/adp5588-keys.c b/drivers/input/keyboard/adp5588-keys.c
index 1edb596d927b..b5142d2d5112 100644
--- a/drivers/input/keyboard/adp5588-keys.c
+++ b/drivers/input/keyboard/adp5588-keys.c
@@ -1,6 +1,7 @@
1/* 1/*
2 * File: drivers/input/keyboard/adp5588_keys.c 2 * File: drivers/input/keyboard/adp5588_keys.c
3 * Description: keypad driver for ADP5588 I2C QWERTY Keypad and IO Expander 3 * Description: keypad driver for ADP5588 and ADP5587
4 * I2C QWERTY Keypad and IO Expander
4 * Bugs: Enter bugs at http://blackfin.uclinux.org/ 5 * Bugs: Enter bugs at http://blackfin.uclinux.org/
5 * 6 *
6 * Copyright (C) 2008-2009 Analog Devices Inc. 7 * Copyright (C) 2008-2009 Analog Devices Inc.
@@ -327,6 +328,7 @@ static const struct dev_pm_ops adp5588_dev_pm_ops = {
327 328
328static const struct i2c_device_id adp5588_id[] = { 329static const struct i2c_device_id adp5588_id[] = {
329 { KBUILD_MODNAME, 0 }, 330 { KBUILD_MODNAME, 0 },
331 { "adp5587-keys", 0 },
330 { } 332 { }
331}; 333};
332MODULE_DEVICE_TABLE(i2c, adp5588_id); 334MODULE_DEVICE_TABLE(i2c, adp5588_id);
@@ -357,5 +359,5 @@ module_exit(adp5588_exit);
357 359
358MODULE_LICENSE("GPL"); 360MODULE_LICENSE("GPL");
359MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>"); 361MODULE_AUTHOR("Michael Hennerich <hennerich@blackfin.uclinux.org>");
360MODULE_DESCRIPTION("ADP5588 Keypad driver"); 362MODULE_DESCRIPTION("ADP5588/87 Keypad driver");
361MODULE_ALIAS("platform:adp5588-keys"); 363MODULE_ALIAS("platform:adp5588-keys");
diff --git a/drivers/input/keyboard/atkbd.c b/drivers/input/keyboard/atkbd.c
index 7b4056292eaf..d358ef8623f4 100644
--- a/drivers/input/keyboard/atkbd.c
+++ b/drivers/input/keyboard/atkbd.c
@@ -40,26 +40,26 @@ module_param_named(set, atkbd_set, int, 0);
40MODULE_PARM_DESC(set, "Select keyboard code set (2 = default, 3 = PS/2 native)"); 40MODULE_PARM_DESC(set, "Select keyboard code set (2 = default, 3 = PS/2 native)");
41 41
42#if defined(__i386__) || defined(__x86_64__) || defined(__hppa__) 42#if defined(__i386__) || defined(__x86_64__) || defined(__hppa__)
43static int atkbd_reset; 43static bool atkbd_reset;
44#else 44#else
45static int atkbd_reset = 1; 45static bool atkbd_reset = true;
46#endif 46#endif
47module_param_named(reset, atkbd_reset, bool, 0); 47module_param_named(reset, atkbd_reset, bool, 0);
48MODULE_PARM_DESC(reset, "Reset keyboard during initialization"); 48MODULE_PARM_DESC(reset, "Reset keyboard during initialization");
49 49
50static int atkbd_softrepeat; 50static bool atkbd_softrepeat;
51module_param_named(softrepeat, atkbd_softrepeat, bool, 0); 51module_param_named(softrepeat, atkbd_softrepeat, bool, 0);
52MODULE_PARM_DESC(softrepeat, "Use software keyboard repeat"); 52MODULE_PARM_DESC(softrepeat, "Use software keyboard repeat");
53 53
54static int atkbd_softraw = 1; 54static bool atkbd_softraw = true;
55module_param_named(softraw, atkbd_softraw, bool, 0); 55module_param_named(softraw, atkbd_softraw, bool, 0);
56MODULE_PARM_DESC(softraw, "Use software generated rawmode"); 56MODULE_PARM_DESC(softraw, "Use software generated rawmode");
57 57
58static int atkbd_scroll; 58static bool atkbd_scroll;
59module_param_named(scroll, atkbd_scroll, bool, 0); 59module_param_named(scroll, atkbd_scroll, bool, 0);
60MODULE_PARM_DESC(scroll, "Enable scroll-wheel on MS Office and similar keyboards"); 60MODULE_PARM_DESC(scroll, "Enable scroll-wheel on MS Office and similar keyboards");
61 61
62static int atkbd_extra; 62static bool atkbd_extra;
63module_param_named(extra, atkbd_extra, bool, 0); 63module_param_named(extra, atkbd_extra, bool, 0);
64MODULE_PARM_DESC(extra, "Enable extra LEDs and keys on IBM RapidAcces, EzKey and similar keyboards"); 64MODULE_PARM_DESC(extra, "Enable extra LEDs and keys on IBM RapidAcces, EzKey and similar keyboards");
65 65
@@ -153,16 +153,16 @@ static const unsigned short atkbd_unxlate_table[128] = {
153#define ATKBD_RET_HANGEUL 0xf2 153#define ATKBD_RET_HANGEUL 0xf2
154#define ATKBD_RET_ERR 0xff 154#define ATKBD_RET_ERR 0xff
155 155
156#define ATKBD_KEY_UNKNOWN 0 156#define ATKBD_KEY_UNKNOWN 0
157#define ATKBD_KEY_NULL 255 157#define ATKBD_KEY_NULL 255
158 158
159#define ATKBD_SCR_1 254 159#define ATKBD_SCR_1 0xfffe
160#define ATKBD_SCR_2 253 160#define ATKBD_SCR_2 0xfffd
161#define ATKBD_SCR_4 252 161#define ATKBD_SCR_4 0xfffc
162#define ATKBD_SCR_8 251 162#define ATKBD_SCR_8 0xfffb
163#define ATKBD_SCR_CLICK 250 163#define ATKBD_SCR_CLICK 0xfffa
164#define ATKBD_SCR_LEFT 249 164#define ATKBD_SCR_LEFT 0xfff9
165#define ATKBD_SCR_RIGHT 248 165#define ATKBD_SCR_RIGHT 0xfff8
166 166
167#define ATKBD_SPECIAL ATKBD_SCR_RIGHT 167#define ATKBD_SPECIAL ATKBD_SCR_RIGHT
168 168
@@ -177,7 +177,7 @@ static const unsigned short atkbd_unxlate_table[128] = {
177#define ATKBD_XL_HANJA 0x20 177#define ATKBD_XL_HANJA 0x20
178 178
179static const struct { 179static const struct {
180 unsigned char keycode; 180 unsigned short keycode;
181 unsigned char set2; 181 unsigned char set2;
182} atkbd_scroll_keys[] = { 182} atkbd_scroll_keys[] = {
183 { ATKBD_SCR_1, 0xc5 }, 183 { ATKBD_SCR_1, 0xc5 },
@@ -206,18 +206,18 @@ struct atkbd {
206 unsigned short keycode[ATKBD_KEYMAP_SIZE]; 206 unsigned short keycode[ATKBD_KEYMAP_SIZE];
207 DECLARE_BITMAP(force_release_mask, ATKBD_KEYMAP_SIZE); 207 DECLARE_BITMAP(force_release_mask, ATKBD_KEYMAP_SIZE);
208 unsigned char set; 208 unsigned char set;
209 unsigned char translated; 209 bool translated;
210 unsigned char extra; 210 bool extra;
211 unsigned char write; 211 bool write;
212 unsigned char softrepeat; 212 bool softrepeat;
213 unsigned char softraw; 213 bool softraw;
214 unsigned char scroll; 214 bool scroll;
215 unsigned char enabled; 215 bool enabled;
216 216
217 /* Accessed only from interrupt */ 217 /* Accessed only from interrupt */
218 unsigned char emul; 218 unsigned char emul;
219 unsigned char resend; 219 bool resend;
220 unsigned char release; 220 bool release;
221 unsigned long xl_bit; 221 unsigned long xl_bit;
222 unsigned int last; 222 unsigned int last;
223 unsigned long time; 223 unsigned long time;
@@ -301,18 +301,18 @@ static const unsigned int xl_table[] = {
301 * Checks if we should mangle the scancode to extract 'release' bit 301 * Checks if we should mangle the scancode to extract 'release' bit
302 * in translated mode. 302 * in translated mode.
303 */ 303 */
304static int atkbd_need_xlate(unsigned long xl_bit, unsigned char code) 304static bool atkbd_need_xlate(unsigned long xl_bit, unsigned char code)
305{ 305{
306 int i; 306 int i;
307 307
308 if (code == ATKBD_RET_EMUL0 || code == ATKBD_RET_EMUL1) 308 if (code == ATKBD_RET_EMUL0 || code == ATKBD_RET_EMUL1)
309 return 0; 309 return false;
310 310
311 for (i = 0; i < ARRAY_SIZE(xl_table); i++) 311 for (i = 0; i < ARRAY_SIZE(xl_table); i++)
312 if (code == xl_table[i]) 312 if (code == xl_table[i])
313 return test_bit(i, &xl_bit); 313 return test_bit(i, &xl_bit);
314 314
315 return 1; 315 return true;
316} 316}
317 317
318/* 318/*
@@ -359,7 +359,7 @@ static unsigned int atkbd_compat_scancode(struct atkbd *atkbd, unsigned int code
359 */ 359 */
360 360
361static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data, 361static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
362 unsigned int flags) 362 unsigned int flags)
363{ 363{
364 struct atkbd *atkbd = serio_get_drvdata(serio); 364 struct atkbd *atkbd = serio_get_drvdata(serio);
365 struct input_dev *dev = atkbd->dev; 365 struct input_dev *dev = atkbd->dev;
@@ -368,20 +368,18 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
368 int value; 368 int value;
369 unsigned short keycode; 369 unsigned short keycode;
370 370
371#ifdef ATKBD_DEBUG 371 dev_dbg(&serio->dev, "Received %02x flags %02x\n", data, flags);
372 printk(KERN_DEBUG "atkbd.c: Received %02x flags %02x\n", data, flags);
373#endif
374 372
375#if !defined(__i386__) && !defined (__x86_64__) 373#if !defined(__i386__) && !defined (__x86_64__)
376 if ((flags & (SERIO_FRAME | SERIO_PARITY)) && (~flags & SERIO_TIMEOUT) && !atkbd->resend && atkbd->write) { 374 if ((flags & (SERIO_FRAME | SERIO_PARITY)) && (~flags & SERIO_TIMEOUT) && !atkbd->resend && atkbd->write) {
377 printk(KERN_WARNING "atkbd.c: frame/parity error: %02x\n", flags); 375 dev_warn(&serio->dev, "Frame/parity error: %02x\n", flags);
378 serio_write(serio, ATKBD_CMD_RESEND); 376 serio_write(serio, ATKBD_CMD_RESEND);
379 atkbd->resend = 1; 377 atkbd->resend = true;
380 goto out; 378 goto out;
381 } 379 }
382 380
383 if (!flags && data == ATKBD_RET_ACK) 381 if (!flags && data == ATKBD_RET_ACK)
384 atkbd->resend = 0; 382 atkbd->resend = false;
385#endif 383#endif
386 384
387 if (unlikely(atkbd->ps2dev.flags & PS2_FLAG_ACK)) 385 if (unlikely(atkbd->ps2dev.flags & PS2_FLAG_ACK))
@@ -412,32 +410,32 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
412 } 410 }
413 411
414 switch (code) { 412 switch (code) {
415 case ATKBD_RET_BAT: 413 case ATKBD_RET_BAT:
416 atkbd->enabled = 0; 414 atkbd->enabled = false;
417 serio_reconnect(atkbd->ps2dev.serio); 415 serio_reconnect(atkbd->ps2dev.serio);
418 goto out; 416 goto out;
419 case ATKBD_RET_EMUL0: 417 case ATKBD_RET_EMUL0:
420 atkbd->emul = 1; 418 atkbd->emul = 1;
421 goto out; 419 goto out;
422 case ATKBD_RET_EMUL1: 420 case ATKBD_RET_EMUL1:
423 atkbd->emul = 2; 421 atkbd->emul = 2;
424 goto out; 422 goto out;
425 case ATKBD_RET_RELEASE: 423 case ATKBD_RET_RELEASE:
426 atkbd->release = 1; 424 atkbd->release = true;
427 goto out; 425 goto out;
428 case ATKBD_RET_ACK: 426 case ATKBD_RET_ACK:
429 case ATKBD_RET_NAK: 427 case ATKBD_RET_NAK:
430 if (printk_ratelimit()) 428 if (printk_ratelimit())
431 printk(KERN_WARNING "atkbd.c: Spurious %s on %s. " 429 dev_warn(&serio->dev,
432 "Some program might be trying access hardware directly.\n", 430 "Spurious %s on %s. "
433 data == ATKBD_RET_ACK ? "ACK" : "NAK", serio->phys); 431 "Some program might be trying access hardware directly.\n",
434 goto out; 432 data == ATKBD_RET_ACK ? "ACK" : "NAK", serio->phys);
435 case ATKBD_RET_ERR: 433 goto out;
436 atkbd->err_count++; 434 case ATKBD_RET_ERR:
437#ifdef ATKBD_DEBUG 435 atkbd->err_count++;
438 printk(KERN_DEBUG "atkbd.c: Keyboard on %s reports too many keys pressed.\n", serio->phys); 436 dev_dbg(&serio->dev, "Keyboard on %s reports too many keys pressed.\n",
439#endif 437 serio->phys);
440 goto out; 438 goto out;
441 } 439 }
442 440
443 code = atkbd_compat_scancode(atkbd, code); 441 code = atkbd_compat_scancode(atkbd, code);
@@ -451,71 +449,72 @@ static irqreturn_t atkbd_interrupt(struct serio *serio, unsigned char data,
451 input_event(dev, EV_MSC, MSC_SCAN, code); 449 input_event(dev, EV_MSC, MSC_SCAN, code);
452 450
453 switch (keycode) { 451 switch (keycode) {
454 case ATKBD_KEY_NULL: 452 case ATKBD_KEY_NULL:
455 break; 453 break;
456 case ATKBD_KEY_UNKNOWN: 454 case ATKBD_KEY_UNKNOWN:
457 printk(KERN_WARNING 455 dev_warn(&serio->dev,
458 "atkbd.c: Unknown key %s (%s set %d, code %#x on %s).\n", 456 "Unknown key %s (%s set %d, code %#x on %s).\n",
459 atkbd->release ? "released" : "pressed", 457 atkbd->release ? "released" : "pressed",
460 atkbd->translated ? "translated" : "raw", 458 atkbd->translated ? "translated" : "raw",
461 atkbd->set, code, serio->phys); 459 atkbd->set, code, serio->phys);
462 printk(KERN_WARNING 460 dev_warn(&serio->dev,
463 "atkbd.c: Use 'setkeycodes %s%02x <keycode>' to make it known.\n", 461 "Use 'setkeycodes %s%02x <keycode>' to make it known.\n",
464 code & 0x80 ? "e0" : "", code & 0x7f); 462 code & 0x80 ? "e0" : "", code & 0x7f);
465 input_sync(dev); 463 input_sync(dev);
466 break; 464 break;
467 case ATKBD_SCR_1: 465 case ATKBD_SCR_1:
468 scroll = 1 - atkbd->release * 2; 466 scroll = 1;
469 break; 467 break;
470 case ATKBD_SCR_2: 468 case ATKBD_SCR_2:
471 scroll = 2 - atkbd->release * 4; 469 scroll = 2;
472 break; 470 break;
473 case ATKBD_SCR_4: 471 case ATKBD_SCR_4:
474 scroll = 4 - atkbd->release * 8; 472 scroll = 4;
475 break; 473 break;
476 case ATKBD_SCR_8: 474 case ATKBD_SCR_8:
477 scroll = 8 - atkbd->release * 16; 475 scroll = 8;
478 break; 476 break;
479 case ATKBD_SCR_CLICK: 477 case ATKBD_SCR_CLICK:
480 click = !atkbd->release; 478 click = !atkbd->release;
481 break; 479 break;
482 case ATKBD_SCR_LEFT: 480 case ATKBD_SCR_LEFT:
483 hscroll = -1; 481 hscroll = -1;
484 break; 482 break;
485 case ATKBD_SCR_RIGHT: 483 case ATKBD_SCR_RIGHT:
486 hscroll = 1; 484 hscroll = 1;
487 break; 485 break;
488 default: 486 default:
489 if (atkbd->release) { 487 if (atkbd->release) {
490 value = 0; 488 value = 0;
491 atkbd->last = 0; 489 atkbd->last = 0;
492 } else if (!atkbd->softrepeat && test_bit(keycode, dev->key)) { 490 } else if (!atkbd->softrepeat && test_bit(keycode, dev->key)) {
493 /* Workaround Toshiba laptop multiple keypress */ 491 /* Workaround Toshiba laptop multiple keypress */
494 value = time_before(jiffies, atkbd->time) && atkbd->last == code ? 1 : 2; 492 value = time_before(jiffies, atkbd->time) && atkbd->last == code ? 1 : 2;
495 } else { 493 } else {
496 value = 1; 494 value = 1;
497 atkbd->last = code; 495 atkbd->last = code;
498 atkbd->time = jiffies + msecs_to_jiffies(dev->rep[REP_DELAY]) / 2; 496 atkbd->time = jiffies + msecs_to_jiffies(dev->rep[REP_DELAY]) / 2;
499 } 497 }
500 498
501 input_event(dev, EV_KEY, keycode, value); 499 input_event(dev, EV_KEY, keycode, value);
502 input_sync(dev); 500 input_sync(dev);
503 501
504 if (value && test_bit(code, atkbd->force_release_mask)) { 502 if (value && test_bit(code, atkbd->force_release_mask)) {
505 input_report_key(dev, keycode, 0); 503 input_report_key(dev, keycode, 0);
506 input_sync(dev); 504 input_sync(dev);
507 } 505 }
508 } 506 }
509 507
510 if (atkbd->scroll) { 508 if (atkbd->scroll) {
511 if (click != -1) 509 if (click != -1)
512 input_report_key(dev, BTN_MIDDLE, click); 510 input_report_key(dev, BTN_MIDDLE, click);
513 input_report_rel(dev, REL_WHEEL, scroll); 511 input_report_rel(dev, REL_WHEEL,
512 atkbd->release ? -scroll : scroll);
514 input_report_rel(dev, REL_HWHEEL, hscroll); 513 input_report_rel(dev, REL_HWHEEL, hscroll);
515 input_sync(dev); 514 input_sync(dev);
516 } 515 }
517 516
518 atkbd->release = 0; 517 atkbd->release = false;
519out: 518out:
520 return IRQ_HANDLED; 519 return IRQ_HANDLED;
521} 520}
@@ -634,17 +633,18 @@ static int atkbd_event(struct input_dev *dev,
634 633
635 switch (type) { 634 switch (type) {
636 635
637 case EV_LED: 636 case EV_LED:
638 atkbd_schedule_event_work(atkbd, ATKBD_LED_EVENT_BIT); 637 atkbd_schedule_event_work(atkbd, ATKBD_LED_EVENT_BIT);
639 return 0; 638 return 0;
640 639
641 case EV_REP: 640 case EV_REP:
642 if (!atkbd->softrepeat) 641 if (!atkbd->softrepeat)
643 atkbd_schedule_event_work(atkbd, ATKBD_REP_EVENT_BIT); 642 atkbd_schedule_event_work(atkbd, ATKBD_REP_EVENT_BIT);
644 return 0; 643 return 0;
645 }
646 644
647 return -1; 645 default:
646 return -1;
647 }
648} 648}
649 649
650/* 650/*
@@ -655,7 +655,7 @@ static int atkbd_event(struct input_dev *dev,
655static inline void atkbd_enable(struct atkbd *atkbd) 655static inline void atkbd_enable(struct atkbd *atkbd)
656{ 656{
657 serio_pause_rx(atkbd->ps2dev.serio); 657 serio_pause_rx(atkbd->ps2dev.serio);
658 atkbd->enabled = 1; 658 atkbd->enabled = true;
659 serio_continue_rx(atkbd->ps2dev.serio); 659 serio_continue_rx(atkbd->ps2dev.serio);
660} 660}
661 661
@@ -667,7 +667,7 @@ static inline void atkbd_enable(struct atkbd *atkbd)
667static inline void atkbd_disable(struct atkbd *atkbd) 667static inline void atkbd_disable(struct atkbd *atkbd)
668{ 668{
669 serio_pause_rx(atkbd->ps2dev.serio); 669 serio_pause_rx(atkbd->ps2dev.serio);
670 atkbd->enabled = 0; 670 atkbd->enabled = false;
671 serio_continue_rx(atkbd->ps2dev.serio); 671 serio_continue_rx(atkbd->ps2dev.serio);
672} 672}
673 673
@@ -688,7 +688,9 @@ static int atkbd_probe(struct atkbd *atkbd)
688 688
689 if (atkbd_reset) 689 if (atkbd_reset)
690 if (ps2_command(ps2dev, NULL, ATKBD_CMD_RESET_BAT)) 690 if (ps2_command(ps2dev, NULL, ATKBD_CMD_RESET_BAT))
691 printk(KERN_WARNING "atkbd.c: keyboard reset failed on %s\n", ps2dev->serio->phys); 691 dev_warn(&ps2dev->serio->dev,
692 "keyboard reset failed on %s\n",
693 ps2dev->serio->phys);
692 694
693/* 695/*
694 * Then we check the keyboard ID. We should get 0xab83 under normal conditions. 696 * Then we check the keyboard ID. We should get 0xab83 under normal conditions.
@@ -718,8 +720,9 @@ static int atkbd_probe(struct atkbd *atkbd)
718 atkbd->id = (param[0] << 8) | param[1]; 720 atkbd->id = (param[0] << 8) | param[1];
719 721
720 if (atkbd->id == 0xaca1 && atkbd->translated) { 722 if (atkbd->id == 0xaca1 && atkbd->translated) {
721 printk(KERN_ERR "atkbd.c: NCD terminal keyboards are only supported on non-translating\n"); 723 dev_err(&ps2dev->serio->dev,
722 printk(KERN_ERR "atkbd.c: controllers. Use i8042.direct=1 to disable translation.\n"); 724 "NCD terminal keyboards are only supported on non-translating controlelrs. "
725 "Use i8042.direct=1 to disable translation.\n");
723 return -1; 726 return -1;
724 } 727 }
725 728
@@ -737,7 +740,7 @@ static int atkbd_select_set(struct atkbd *atkbd, int target_set, int allow_extra
737 struct ps2dev *ps2dev = &atkbd->ps2dev; 740 struct ps2dev *ps2dev = &atkbd->ps2dev;
738 unsigned char param[2]; 741 unsigned char param[2];
739 742
740 atkbd->extra = 0; 743 atkbd->extra = false;
741/* 744/*
742 * For known special keyboards we can go ahead and set the correct set. 745 * For known special keyboards we can go ahead and set the correct set.
743 * We check for NCD PS/2 Sun, NorthGate OmniKey 101 and 746 * We check for NCD PS/2 Sun, NorthGate OmniKey 101 and
@@ -756,7 +759,7 @@ static int atkbd_select_set(struct atkbd *atkbd, int target_set, int allow_extra
756 if (allow_extra) { 759 if (allow_extra) {
757 param[0] = 0x71; 760 param[0] = 0x71;
758 if (!ps2_command(ps2dev, param, ATKBD_CMD_EX_ENABLE)) { 761 if (!ps2_command(ps2dev, param, ATKBD_CMD_EX_ENABLE)) {
759 atkbd->extra = 1; 762 atkbd->extra = true;
760 return 2; 763 return 2;
761 } 764 }
762 } 765 }
@@ -821,7 +824,8 @@ static int atkbd_activate(struct atkbd *atkbd)
821 */ 824 */
822 825
823 if (ps2_command(ps2dev, NULL, ATKBD_CMD_ENABLE)) { 826 if (ps2_command(ps2dev, NULL, ATKBD_CMD_ENABLE)) {
824 printk(KERN_ERR "atkbd.c: Failed to enable keyboard on %s\n", 827 dev_err(&ps2dev->serio->dev,
828 "Failed to enable keyboard on %s\n",
825 ps2dev->serio->phys); 829 ps2dev->serio->phys);
826 return -1; 830 return -1;
827 } 831 }
@@ -1070,9 +1074,13 @@ static void atkbd_set_device_attrs(struct atkbd *atkbd)
1070 input_dev->keycodesize = sizeof(unsigned short); 1074 input_dev->keycodesize = sizeof(unsigned short);
1071 input_dev->keycodemax = ARRAY_SIZE(atkbd_set2_keycode); 1075 input_dev->keycodemax = ARRAY_SIZE(atkbd_set2_keycode);
1072 1076
1073 for (i = 0; i < ATKBD_KEYMAP_SIZE; i++) 1077 for (i = 0; i < ATKBD_KEYMAP_SIZE; i++) {
1074 if (atkbd->keycode[i] && atkbd->keycode[i] < ATKBD_SPECIAL) 1078 if (atkbd->keycode[i] != KEY_RESERVED &&
1079 atkbd->keycode[i] != ATKBD_KEY_NULL &&
1080 atkbd->keycode[i] < ATKBD_SPECIAL) {
1075 __set_bit(atkbd->keycode[i], input_dev->keybit); 1081 __set_bit(atkbd->keycode[i], input_dev->keybit);
1082 }
1083 }
1076} 1084}
1077 1085
1078/* 1086/*
@@ -1100,12 +1108,14 @@ static int atkbd_connect(struct serio *serio, struct serio_driver *drv)
1100 1108
1101 switch (serio->id.type) { 1109 switch (serio->id.type) {
1102 1110
1103 case SERIO_8042_XL: 1111 case SERIO_8042_XL:
1104 atkbd->translated = 1; 1112 atkbd->translated = true;
1105 case SERIO_8042: 1113 /* Fall through */
1106 if (serio->write) 1114
1107 atkbd->write = 1; 1115 case SERIO_8042:
1108 break; 1116 if (serio->write)
1117 atkbd->write = true;
1118 break;
1109 } 1119 }
1110 1120
1111 atkbd->softraw = atkbd_softraw; 1121 atkbd->softraw = atkbd_softraw;
@@ -1113,7 +1123,7 @@ static int atkbd_connect(struct serio *serio, struct serio_driver *drv)
1113 atkbd->scroll = atkbd_scroll; 1123 atkbd->scroll = atkbd_scroll;
1114 1124
1115 if (atkbd->softrepeat) 1125 if (atkbd->softrepeat)
1116 atkbd->softraw = 1; 1126 atkbd->softraw = true;
1117 1127
1118 serio_set_drvdata(serio, atkbd); 1128 serio_set_drvdata(serio, atkbd);
1119 1129
@@ -1172,7 +1182,8 @@ static int atkbd_reconnect(struct serio *serio)
1172 int retval = -1; 1182 int retval = -1;
1173 1183
1174 if (!atkbd || !drv) { 1184 if (!atkbd || !drv) {
1175 printk(KERN_DEBUG "atkbd: reconnect request, but serio is disconnected, ignoring...\n"); 1185 dev_dbg(&serio->dev,
1186 "reconnect request, but serio is disconnected, ignoring...\n");
1176 return -1; 1187 return -1;
1177 } 1188 }
1178 1189
@@ -1286,7 +1297,8 @@ static ssize_t atkbd_set_extra(struct atkbd *atkbd, const char *buf, size_t coun
1286 struct input_dev *old_dev, *new_dev; 1297 struct input_dev *old_dev, *new_dev;
1287 unsigned long value; 1298 unsigned long value;
1288 int err; 1299 int err;
1289 unsigned char old_extra, old_set; 1300 bool old_extra;
1301 unsigned char old_set;
1290 1302
1291 if (!atkbd->write) 1303 if (!atkbd->write)
1292 return -EIO; 1304 return -EIO;
@@ -1369,7 +1381,7 @@ static ssize_t atkbd_set_scroll(struct atkbd *atkbd, const char *buf, size_t cou
1369 struct input_dev *old_dev, *new_dev; 1381 struct input_dev *old_dev, *new_dev;
1370 unsigned long value; 1382 unsigned long value;
1371 int err; 1383 int err;
1372 unsigned char old_scroll; 1384 bool old_scroll;
1373 1385
1374 if (strict_strtoul(buf, 10, &value) || value > 1) 1386 if (strict_strtoul(buf, 10, &value) || value > 1)
1375 return -EINVAL; 1387 return -EINVAL;
@@ -1413,7 +1425,8 @@ static ssize_t atkbd_set_set(struct atkbd *atkbd, const char *buf, size_t count)
1413 struct input_dev *old_dev, *new_dev; 1425 struct input_dev *old_dev, *new_dev;
1414 unsigned long value; 1426 unsigned long value;
1415 int err; 1427 int err;
1416 unsigned char old_set, old_extra; 1428 unsigned char old_set;
1429 bool old_extra;
1417 1430
1418 if (!atkbd->write) 1431 if (!atkbd->write)
1419 return -EIO; 1432 return -EIO;
@@ -1463,7 +1476,7 @@ static ssize_t atkbd_set_softrepeat(struct atkbd *atkbd, const char *buf, size_t
1463 struct input_dev *old_dev, *new_dev; 1476 struct input_dev *old_dev, *new_dev;
1464 unsigned long value; 1477 unsigned long value;
1465 int err; 1478 int err;
1466 unsigned char old_softrepeat, old_softraw; 1479 bool old_softrepeat, old_softraw;
1467 1480
1468 if (!atkbd->write) 1481 if (!atkbd->write)
1469 return -EIO; 1482 return -EIO;
@@ -1483,7 +1496,7 @@ static ssize_t atkbd_set_softrepeat(struct atkbd *atkbd, const char *buf, size_t
1483 atkbd->dev = new_dev; 1496 atkbd->dev = new_dev;
1484 atkbd->softrepeat = value; 1497 atkbd->softrepeat = value;
1485 if (atkbd->softrepeat) 1498 if (atkbd->softrepeat)
1486 atkbd->softraw = 1; 1499 atkbd->softraw = true;
1487 atkbd_set_device_attrs(atkbd); 1500 atkbd_set_device_attrs(atkbd);
1488 1501
1489 err = input_register_device(atkbd->dev); 1502 err = input_register_device(atkbd->dev);
@@ -1513,7 +1526,7 @@ static ssize_t atkbd_set_softraw(struct atkbd *atkbd, const char *buf, size_t co
1513 struct input_dev *old_dev, *new_dev; 1526 struct input_dev *old_dev, *new_dev;
1514 unsigned long value; 1527 unsigned long value;
1515 int err; 1528 int err;
1516 unsigned char old_softraw; 1529 bool old_softraw;
1517 1530
1518 if (strict_strtoul(buf, 10, &value) || value > 1) 1531 if (strict_strtoul(buf, 10, &value) || value > 1)
1519 return -EINVAL; 1532 return -EINVAL;
diff --git a/drivers/input/keyboard/ep93xx_keypad.c b/drivers/input/keyboard/ep93xx_keypad.c
index e45740429f7e..bd25a3af1664 100644
--- a/drivers/input/keyboard/ep93xx_keypad.c
+++ b/drivers/input/keyboard/ep93xx_keypad.c
@@ -69,7 +69,7 @@ struct ep93xx_keypad {
69 69
70 void __iomem *mmio_base; 70 void __iomem *mmio_base;
71 71
72 unsigned int matrix_keycodes[EP93XX_MATRIX_SIZE]; 72 unsigned short keycodes[EP93XX_MATRIX_SIZE];
73 73
74 int key1; 74 int key1;
75 int key2; 75 int key2;
@@ -79,24 +79,6 @@ struct ep93xx_keypad {
79 bool enabled; 79 bool enabled;
80}; 80};
81 81
82static void ep93xx_keypad_build_keycode(struct ep93xx_keypad *keypad)
83{
84 struct ep93xx_keypad_platform_data *pdata = keypad->pdata;
85 struct input_dev *input_dev = keypad->input_dev;
86 unsigned int *key;
87 int i;
88
89 key = &pdata->matrix_key_map[0];
90 for (i = 0; i < pdata->matrix_key_map_size; i++, key++) {
91 int row = KEY_ROW(*key);
92 int col = KEY_COL(*key);
93 int code = KEY_VAL(*key);
94
95 keypad->matrix_keycodes[(row << 3) + col] = code;
96 __set_bit(code, input_dev->keybit);
97 }
98}
99
100static irqreturn_t ep93xx_keypad_irq_handler(int irq, void *dev_id) 82static irqreturn_t ep93xx_keypad_irq_handler(int irq, void *dev_id)
101{ 83{
102 struct ep93xx_keypad *keypad = dev_id; 84 struct ep93xx_keypad *keypad = dev_id;
@@ -107,10 +89,10 @@ static irqreturn_t ep93xx_keypad_irq_handler(int irq, void *dev_id)
107 status = __raw_readl(keypad->mmio_base + KEY_REG); 89 status = __raw_readl(keypad->mmio_base + KEY_REG);
108 90
109 keycode = (status & KEY_REG_KEY1_MASK) >> KEY_REG_KEY1_SHIFT; 91 keycode = (status & KEY_REG_KEY1_MASK) >> KEY_REG_KEY1_SHIFT;
110 key1 = keypad->matrix_keycodes[keycode]; 92 key1 = keypad->keycodes[keycode];
111 93
112 keycode = (status & KEY_REG_KEY2_MASK) >> KEY_REG_KEY2_SHIFT; 94 keycode = (status & KEY_REG_KEY2_MASK) >> KEY_REG_KEY2_SHIFT;
113 key2 = keypad->matrix_keycodes[keycode]; 95 key2 = keypad->keycodes[keycode];
114 96
115 if (status & KEY_REG_2KEYS) { 97 if (status & KEY_REG_2KEYS) {
116 if (keypad->key1 && key1 != keypad->key1 && key2 != keypad->key1) 98 if (keypad->key1 && key1 != keypad->key1 && key2 != keypad->key1)
@@ -256,6 +238,7 @@ static int ep93xx_keypad_resume(struct platform_device *pdev)
256static int __devinit ep93xx_keypad_probe(struct platform_device *pdev) 238static int __devinit ep93xx_keypad_probe(struct platform_device *pdev)
257{ 239{
258 struct ep93xx_keypad *keypad; 240 struct ep93xx_keypad *keypad;
241 const struct matrix_keymap_data *keymap_data;
259 struct input_dev *input_dev; 242 struct input_dev *input_dev;
260 struct resource *res; 243 struct resource *res;
261 int err; 244 int err;
@@ -270,6 +253,12 @@ static int __devinit ep93xx_keypad_probe(struct platform_device *pdev)
270 goto failed_free; 253 goto failed_free;
271 } 254 }
272 255
256 keymap_data = keypad->pdata->keymap_data;
257 if (!keymap_data) {
258 err = -EINVAL;
259 goto failed_free;
260 }
261
273 keypad->irq = platform_get_irq(pdev, 0); 262 keypad->irq = platform_get_irq(pdev, 0);
274 if (!keypad->irq) { 263 if (!keypad->irq) {
275 err = -ENXIO; 264 err = -ENXIO;
@@ -317,9 +306,9 @@ static int __devinit ep93xx_keypad_probe(struct platform_device *pdev)
317 input_dev->open = ep93xx_keypad_open; 306 input_dev->open = ep93xx_keypad_open;
318 input_dev->close = ep93xx_keypad_close; 307 input_dev->close = ep93xx_keypad_close;
319 input_dev->dev.parent = &pdev->dev; 308 input_dev->dev.parent = &pdev->dev;
320 input_dev->keycode = keypad->matrix_keycodes; 309 input_dev->keycode = keypad->keycodes;
321 input_dev->keycodesize = sizeof(keypad->matrix_keycodes[0]); 310 input_dev->keycodesize = sizeof(keypad->keycodes[0]);
322 input_dev->keycodemax = ARRAY_SIZE(keypad->matrix_keycodes); 311 input_dev->keycodemax = ARRAY_SIZE(keypad->keycodes);
323 312
324 input_set_drvdata(input_dev, keypad); 313 input_set_drvdata(input_dev, keypad);
325 314
@@ -327,7 +316,8 @@ static int __devinit ep93xx_keypad_probe(struct platform_device *pdev)
327 if (keypad->pdata->flags & EP93XX_KEYPAD_AUTOREPEAT) 316 if (keypad->pdata->flags & EP93XX_KEYPAD_AUTOREPEAT)
328 input_dev->evbit[0] |= BIT_MASK(EV_REP); 317 input_dev->evbit[0] |= BIT_MASK(EV_REP);
329 318
330 ep93xx_keypad_build_keycode(keypad); 319 matrix_keypad_build_keymap(keymap_data, 3,
320 input_dev->keycode, input_dev->keybit);
331 platform_set_drvdata(pdev, keypad); 321 platform_set_drvdata(pdev, keypad);
332 322
333 err = request_irq(keypad->irq, ep93xx_keypad_irq_handler, 323 err = request_irq(keypad->irq, ep93xx_keypad_irq_handler,
diff --git a/drivers/input/keyboard/gpio_keys.c b/drivers/input/keyboard/gpio_keys.c
index 1aff3b76effd..2b708aa85553 100644
--- a/drivers/input/keyboard/gpio_keys.c
+++ b/drivers/input/keyboard/gpio_keys.c
@@ -30,13 +30,289 @@ struct gpio_button_data {
30 struct input_dev *input; 30 struct input_dev *input;
31 struct timer_list timer; 31 struct timer_list timer;
32 struct work_struct work; 32 struct work_struct work;
33 bool disabled;
33}; 34};
34 35
35struct gpio_keys_drvdata { 36struct gpio_keys_drvdata {
36 struct input_dev *input; 37 struct input_dev *input;
38 struct mutex disable_lock;
39 unsigned int n_buttons;
37 struct gpio_button_data data[0]; 40 struct gpio_button_data data[0];
38}; 41};
39 42
43/*
44 * SYSFS interface for enabling/disabling keys and switches:
45 *
46 * There are 4 attributes under /sys/devices/platform/gpio-keys/
47 * keys [ro] - bitmap of keys (EV_KEY) which can be
48 * disabled
49 * switches [ro] - bitmap of switches (EV_SW) which can be
50 * disabled
51 * disabled_keys [rw] - bitmap of keys currently disabled
52 * disabled_switches [rw] - bitmap of switches currently disabled
53 *
54 * Userland can change these values and hence disable event generation
55 * for each key (or switch). Disabling a key means its interrupt line
56 * is disabled.
57 *
58 * For example, if we have following switches set up as gpio-keys:
59 * SW_DOCK = 5
60 * SW_CAMERA_LENS_COVER = 9
61 * SW_KEYPAD_SLIDE = 10
62 * SW_FRONT_PROXIMITY = 11
63 * This is read from switches:
64 * 11-9,5
65 * Next we want to disable proximity (11) and dock (5), we write:
66 * 11,5
67 * to file disabled_switches. Now proximity and dock IRQs are disabled.
68 * This can be verified by reading the file disabled_switches:
69 * 11,5
70 * If we now want to enable proximity (11) switch we write:
71 * 5
72 * to disabled_switches.
73 *
74 * We can disable only those keys which don't allow sharing the irq.
75 */
76
77/**
78 * get_n_events_by_type() - returns maximum number of events per @type
79 * @type: type of button (%EV_KEY, %EV_SW)
80 *
81 * Return value of this function can be used to allocate bitmap
82 * large enough to hold all bits for given type.
83 */
84static inline int get_n_events_by_type(int type)
85{
86 BUG_ON(type != EV_SW && type != EV_KEY);
87
88 return (type == EV_KEY) ? KEY_CNT : SW_CNT;
89}
90
91/**
92 * gpio_keys_disable_button() - disables given GPIO button
93 * @bdata: button data for button to be disabled
94 *
95 * Disables button pointed by @bdata. This is done by masking
96 * IRQ line. After this function is called, button won't generate
97 * input events anymore. Note that one can only disable buttons
98 * that don't share IRQs.
99 *
100 * Make sure that @bdata->disable_lock is locked when entering
101 * this function to avoid races when concurrent threads are
102 * disabling buttons at the same time.
103 */
104static void gpio_keys_disable_button(struct gpio_button_data *bdata)
105{
106 if (!bdata->disabled) {
107 /*
108 * Disable IRQ and possible debouncing timer.
109 */
110 disable_irq(gpio_to_irq(bdata->button->gpio));
111 if (bdata->button->debounce_interval)
112 del_timer_sync(&bdata->timer);
113
114 bdata->disabled = true;
115 }
116}
117
118/**
119 * gpio_keys_enable_button() - enables given GPIO button
120 * @bdata: button data for button to be disabled
121 *
122 * Enables given button pointed by @bdata.
123 *
124 * Make sure that @bdata->disable_lock is locked when entering
125 * this function to avoid races with concurrent threads trying
126 * to enable the same button at the same time.
127 */
128static void gpio_keys_enable_button(struct gpio_button_data *bdata)
129{
130 if (bdata->disabled) {
131 enable_irq(gpio_to_irq(bdata->button->gpio));
132 bdata->disabled = false;
133 }
134}
135
136/**
137 * gpio_keys_attr_show_helper() - fill in stringified bitmap of buttons
138 * @ddata: pointer to drvdata
139 * @buf: buffer where stringified bitmap is written
140 * @type: button type (%EV_KEY, %EV_SW)
141 * @only_disabled: does caller want only those buttons that are
142 * currently disabled or all buttons that can be
143 * disabled
144 *
145 * This function writes buttons that can be disabled to @buf. If
146 * @only_disabled is true, then @buf contains only those buttons
147 * that are currently disabled. Returns 0 on success or negative
148 * errno on failure.
149 */
150static ssize_t gpio_keys_attr_show_helper(struct gpio_keys_drvdata *ddata,
151 char *buf, unsigned int type,
152 bool only_disabled)
153{
154 int n_events = get_n_events_by_type(type);
155 unsigned long *bits;
156 ssize_t ret;
157 int i;
158
159 bits = kcalloc(BITS_TO_LONGS(n_events), sizeof(*bits), GFP_KERNEL);
160 if (!bits)
161 return -ENOMEM;
162
163 for (i = 0; i < ddata->n_buttons; i++) {
164 struct gpio_button_data *bdata = &ddata->data[i];
165
166 if (bdata->button->type != type)
167 continue;
168
169 if (only_disabled && !bdata->disabled)
170 continue;
171
172 __set_bit(bdata->button->code, bits);
173 }
174
175 ret = bitmap_scnlistprintf(buf, PAGE_SIZE - 2, bits, n_events);
176 buf[ret++] = '\n';
177 buf[ret] = '\0';
178
179 kfree(bits);
180
181 return ret;
182}
183
184/**
185 * gpio_keys_attr_store_helper() - enable/disable buttons based on given bitmap
186 * @ddata: pointer to drvdata
187 * @buf: buffer from userspace that contains stringified bitmap
188 * @type: button type (%EV_KEY, %EV_SW)
189 *
190 * This function parses stringified bitmap from @buf and disables/enables
191 * GPIO buttons accordinly. Returns 0 on success and negative error
192 * on failure.
193 */
194static ssize_t gpio_keys_attr_store_helper(struct gpio_keys_drvdata *ddata,
195 const char *buf, unsigned int type)
196{
197 int n_events = get_n_events_by_type(type);
198 unsigned long *bits;
199 ssize_t error;
200 int i;
201
202 bits = kcalloc(BITS_TO_LONGS(n_events), sizeof(*bits), GFP_KERNEL);
203 if (!bits)
204 return -ENOMEM;
205
206 error = bitmap_parselist(buf, bits, n_events);
207 if (error)
208 goto out;
209
210 /* First validate */
211 for (i = 0; i < ddata->n_buttons; i++) {
212 struct gpio_button_data *bdata = &ddata->data[i];
213
214 if (bdata->button->type != type)
215 continue;
216
217 if (test_bit(bdata->button->code, bits) &&
218 !bdata->button->can_disable) {
219 error = -EINVAL;
220 goto out;
221 }
222 }
223
224 mutex_lock(&ddata->disable_lock);
225
226 for (i = 0; i < ddata->n_buttons; i++) {
227 struct gpio_button_data *bdata = &ddata->data[i];
228
229 if (bdata->button->type != type)
230 continue;
231
232 if (test_bit(bdata->button->code, bits))
233 gpio_keys_disable_button(bdata);
234 else
235 gpio_keys_enable_button(bdata);
236 }
237
238 mutex_unlock(&ddata->disable_lock);
239
240out:
241 kfree(bits);
242 return error;
243}
244
245#define ATTR_SHOW_FN(name, type, only_disabled) \
246static ssize_t gpio_keys_show_##name(struct device *dev, \
247 struct device_attribute *attr, \
248 char *buf) \
249{ \
250 struct platform_device *pdev = to_platform_device(dev); \
251 struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev); \
252 \
253 return gpio_keys_attr_show_helper(ddata, buf, \
254 type, only_disabled); \
255}
256
257ATTR_SHOW_FN(keys, EV_KEY, false);
258ATTR_SHOW_FN(switches, EV_SW, false);
259ATTR_SHOW_FN(disabled_keys, EV_KEY, true);
260ATTR_SHOW_FN(disabled_switches, EV_SW, true);
261
262/*
263 * ATTRIBUTES:
264 *
265 * /sys/devices/platform/gpio-keys/keys [ro]
266 * /sys/devices/platform/gpio-keys/switches [ro]
267 */
268static DEVICE_ATTR(keys, S_IRUGO, gpio_keys_show_keys, NULL);
269static DEVICE_ATTR(switches, S_IRUGO, gpio_keys_show_switches, NULL);
270
271#define ATTR_STORE_FN(name, type) \
272static ssize_t gpio_keys_store_##name(struct device *dev, \
273 struct device_attribute *attr, \
274 const char *buf, \
275 size_t count) \
276{ \
277 struct platform_device *pdev = to_platform_device(dev); \
278 struct gpio_keys_drvdata *ddata = platform_get_drvdata(pdev); \
279 ssize_t error; \
280 \
281 error = gpio_keys_attr_store_helper(ddata, buf, type); \
282 if (error) \
283 return error; \
284 \
285 return count; \
286}
287
288ATTR_STORE_FN(disabled_keys, EV_KEY);
289ATTR_STORE_FN(disabled_switches, EV_SW);
290
291/*
292 * ATTRIBUTES:
293 *
294 * /sys/devices/platform/gpio-keys/disabled_keys [rw]
295 * /sys/devices/platform/gpio-keys/disables_switches [rw]
296 */
297static DEVICE_ATTR(disabled_keys, S_IWUSR | S_IRUGO,
298 gpio_keys_show_disabled_keys,
299 gpio_keys_store_disabled_keys);
300static DEVICE_ATTR(disabled_switches, S_IWUSR | S_IRUGO,
301 gpio_keys_show_disabled_switches,
302 gpio_keys_store_disabled_switches);
303
304static struct attribute *gpio_keys_attrs[] = {
305 &dev_attr_keys.attr,
306 &dev_attr_switches.attr,
307 &dev_attr_disabled_keys.attr,
308 &dev_attr_disabled_switches.attr,
309 NULL,
310};
311
312static struct attribute_group gpio_keys_attr_group = {
313 .attrs = gpio_keys_attrs,
314};
315
40static void gpio_keys_report_event(struct gpio_button_data *bdata) 316static void gpio_keys_report_event(struct gpio_button_data *bdata)
41{ 317{
42 struct gpio_keys_button *button = bdata->button; 318 struct gpio_keys_button *button = bdata->button;
@@ -79,11 +355,13 @@ static irqreturn_t gpio_keys_isr(int irq, void *dev_id)
79 return IRQ_HANDLED; 355 return IRQ_HANDLED;
80} 356}
81 357
82static int __devinit gpio_keys_setup_key(struct device *dev, 358static int __devinit gpio_keys_setup_key(struct platform_device *pdev,
83 struct gpio_button_data *bdata, 359 struct gpio_button_data *bdata,
84 struct gpio_keys_button *button) 360 struct gpio_keys_button *button)
85{ 361{
86 char *desc = button->desc ? button->desc : "gpio_keys"; 362 char *desc = button->desc ? button->desc : "gpio_keys";
363 struct device *dev = &pdev->dev;
364 unsigned long irqflags;
87 int irq, error; 365 int irq, error;
88 366
89 setup_timer(&bdata->timer, gpio_keys_timer, (unsigned long)bdata); 367 setup_timer(&bdata->timer, gpio_keys_timer, (unsigned long)bdata);
@@ -112,10 +390,15 @@ static int __devinit gpio_keys_setup_key(struct device *dev,
112 goto fail3; 390 goto fail3;
113 } 391 }
114 392
115 error = request_irq(irq, gpio_keys_isr, 393 irqflags = IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING;
116 IRQF_SHARED | 394 /*
117 IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, 395 * If platform has specified that the button can be disabled,
118 desc, bdata); 396 * we don't want it to share the interrupt line.
397 */
398 if (!button->can_disable)
399 irqflags |= IRQF_SHARED;
400
401 error = request_irq(irq, gpio_keys_isr, irqflags, desc, bdata);
119 if (error) { 402 if (error) {
120 dev_err(dev, "Unable to claim irq %d; error %d\n", 403 dev_err(dev, "Unable to claim irq %d; error %d\n",
121 irq, error); 404 irq, error);
@@ -149,6 +432,10 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
149 goto fail1; 432 goto fail1;
150 } 433 }
151 434
435 ddata->input = input;
436 ddata->n_buttons = pdata->nbuttons;
437 mutex_init(&ddata->disable_lock);
438
152 platform_set_drvdata(pdev, ddata); 439 platform_set_drvdata(pdev, ddata);
153 440
154 input->name = pdev->name; 441 input->name = pdev->name;
@@ -164,8 +451,6 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
164 if (pdata->rep) 451 if (pdata->rep)
165 __set_bit(EV_REP, input->evbit); 452 __set_bit(EV_REP, input->evbit);
166 453
167 ddata->input = input;
168
169 for (i = 0; i < pdata->nbuttons; i++) { 454 for (i = 0; i < pdata->nbuttons; i++) {
170 struct gpio_keys_button *button = &pdata->buttons[i]; 455 struct gpio_keys_button *button = &pdata->buttons[i];
171 struct gpio_button_data *bdata = &ddata->data[i]; 456 struct gpio_button_data *bdata = &ddata->data[i];
@@ -174,7 +459,7 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
174 bdata->input = input; 459 bdata->input = input;
175 bdata->button = button; 460 bdata->button = button;
176 461
177 error = gpio_keys_setup_key(dev, bdata, button); 462 error = gpio_keys_setup_key(pdev, bdata, button);
178 if (error) 463 if (error)
179 goto fail2; 464 goto fail2;
180 465
@@ -184,13 +469,20 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
184 input_set_capability(input, type, button->code); 469 input_set_capability(input, type, button->code);
185 } 470 }
186 471
187 error = input_register_device(input); 472 error = sysfs_create_group(&pdev->dev.kobj, &gpio_keys_attr_group);
188 if (error) { 473 if (error) {
189 dev_err(dev, "Unable to register input device, " 474 dev_err(dev, "Unable to export keys/switches, error: %d\n",
190 "error: %d\n", error); 475 error);
191 goto fail2; 476 goto fail2;
192 } 477 }
193 478
479 error = input_register_device(input);
480 if (error) {
481 dev_err(dev, "Unable to register input device, error: %d\n",
482 error);
483 goto fail3;
484 }
485
194 /* get current state of buttons */ 486 /* get current state of buttons */
195 for (i = 0; i < pdata->nbuttons; i++) 487 for (i = 0; i < pdata->nbuttons; i++)
196 gpio_keys_report_event(&ddata->data[i]); 488 gpio_keys_report_event(&ddata->data[i]);
@@ -200,6 +492,8 @@ static int __devinit gpio_keys_probe(struct platform_device *pdev)
200 492
201 return 0; 493 return 0;
202 494
495 fail3:
496 sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);
203 fail2: 497 fail2:
204 while (--i >= 0) { 498 while (--i >= 0) {
205 free_irq(gpio_to_irq(pdata->buttons[i].gpio), &ddata->data[i]); 499 free_irq(gpio_to_irq(pdata->buttons[i].gpio), &ddata->data[i]);
@@ -224,6 +518,8 @@ static int __devexit gpio_keys_remove(struct platform_device *pdev)
224 struct input_dev *input = ddata->input; 518 struct input_dev *input = ddata->input;
225 int i; 519 int i;
226 520
521 sysfs_remove_group(&pdev->dev.kobj, &gpio_keys_attr_group);
522
227 device_init_wakeup(&pdev->dev, 0); 523 device_init_wakeup(&pdev->dev, 0);
228 524
229 for (i = 0; i < pdata->nbuttons; i++) { 525 for (i = 0; i < pdata->nbuttons; i++) {
diff --git a/drivers/input/keyboard/imx_keypad.c b/drivers/input/keyboard/imx_keypad.c
new file mode 100644
index 000000000000..2ee5b798024d
--- /dev/null
+++ b/drivers/input/keyboard/imx_keypad.c
@@ -0,0 +1,594 @@
1/*
2 * Driver for the IMX keypad port.
3 * Copyright (C) 2009 Alberto Panizzo <maramaopercheseimorto@gmail.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
8 *
9 * <<Power management needs to be implemented>>.
10 */
11
12#include <linux/clk.h>
13#include <linux/delay.h>
14#include <linux/device.h>
15#include <linux/err.h>
16#include <linux/init.h>
17#include <linux/input/matrix_keypad.h>
18#include <linux/interrupt.h>
19#include <linux/io.h>
20#include <linux/jiffies.h>
21#include <linux/kernel.h>
22#include <linux/module.h>
23#include <linux/platform_device.h>
24#include <linux/timer.h>
25
26/*
27 * Keypad Controller registers (halfword)
28 */
29#define KPCR 0x00 /* Keypad Control Register */
30
31#define KPSR 0x02 /* Keypad Status Register */
32#define KBD_STAT_KPKD (0x1 << 0) /* Key Press Interrupt Status bit (w1c) */
33#define KBD_STAT_KPKR (0x1 << 1) /* Key Release Interrupt Status bit (w1c) */
34#define KBD_STAT_KDSC (0x1 << 2) /* Key Depress Synch Chain Status bit (w1c)*/
35#define KBD_STAT_KRSS (0x1 << 3) /* Key Release Synch Status bit (w1c)*/
36#define KBD_STAT_KDIE (0x1 << 8) /* Key Depress Interrupt Enable Status bit */
37#define KBD_STAT_KRIE (0x1 << 9) /* Key Release Interrupt Enable */
38#define KBD_STAT_KPPEN (0x1 << 10) /* Keypad Clock Enable */
39
40#define KDDR 0x04 /* Keypad Data Direction Register */
41#define KPDR 0x06 /* Keypad Data Register */
42
43#define MAX_MATRIX_KEY_ROWS 8
44#define MAX_MATRIX_KEY_COLS 8
45#define MATRIX_ROW_SHIFT 3
46
47#define MAX_MATRIX_KEY_NUM (MAX_MATRIX_KEY_ROWS * MAX_MATRIX_KEY_COLS)
48
49struct imx_keypad {
50
51 struct clk *clk;
52 struct input_dev *input_dev;
53 void __iomem *mmio_base;
54
55 int irq;
56 struct timer_list check_matrix_timer;
57
58 /*
59 * The matrix is stable only if no changes are detected after
60 * IMX_KEYPAD_SCANS_FOR_STABILITY scans
61 */
62#define IMX_KEYPAD_SCANS_FOR_STABILITY 3
63 int stable_count;
64
65 bool enabled;
66
67 /* Masks for enabled rows/cols */
68 unsigned short rows_en_mask;
69 unsigned short cols_en_mask;
70
71 unsigned short keycodes[MAX_MATRIX_KEY_NUM];
72
73 /*
74 * Matrix states:
75 * -stable: achieved after a complete debounce process.
76 * -unstable: used in the debouncing process.
77 */
78 unsigned short matrix_stable_state[MAX_MATRIX_KEY_COLS];
79 unsigned short matrix_unstable_state[MAX_MATRIX_KEY_COLS];
80};
81
82/* Scan the matrix and return the new state in *matrix_volatile_state. */
83static void imx_keypad_scan_matrix(struct imx_keypad *keypad,
84 unsigned short *matrix_volatile_state)
85{
86 int col;
87 unsigned short reg_val;
88
89 for (col = 0; col < MAX_MATRIX_KEY_COLS; col++) {
90 if ((keypad->cols_en_mask & (1 << col)) == 0)
91 continue;
92 /*
93 * Discharge keypad capacitance:
94 * 2. write 1s on column data.
95 * 3. configure columns as totem-pole to discharge capacitance.
96 * 4. configure columns as open-drain.
97 */
98 reg_val = readw(keypad->mmio_base + KPDR);
99 reg_val |= 0xff00;
100 writew(reg_val, keypad->mmio_base + KPDR);
101
102 reg_val = readw(keypad->mmio_base + KPCR);
103 reg_val &= ~((keypad->cols_en_mask & 0xff) << 8);
104 writew(reg_val, keypad->mmio_base + KPCR);
105
106 udelay(2);
107
108 reg_val = readw(keypad->mmio_base + KPCR);
109 reg_val |= (keypad->cols_en_mask & 0xff) << 8;
110 writew(reg_val, keypad->mmio_base + KPCR);
111
112 /*
113 * 5. Write a single column to 0, others to 1.
114 * 6. Sample row inputs and save data.
115 * 7. Repeat steps 2 - 6 for remaining columns.
116 */
117 reg_val = readw(keypad->mmio_base + KPDR);
118 reg_val &= ~(1 << (8 + col));
119 writew(reg_val, keypad->mmio_base + KPDR);
120
121 /*
122 * Delay added to avoid propagating the 0 from column to row
123 * when scanning.
124 */
125 udelay(5);
126
127 /*
128 * 1s in matrix_volatile_state[col] means key pressures
129 * throw data from non enabled rows.
130 */
131 reg_val = readw(keypad->mmio_base + KPDR);
132 matrix_volatile_state[col] = (~reg_val) & keypad->rows_en_mask;
133 }
134
135 /*
136 * Return in standby mode:
137 * 9. write 0s to columns
138 */
139 reg_val = readw(keypad->mmio_base + KPDR);
140 reg_val &= 0x00ff;
141 writew(reg_val, keypad->mmio_base + KPDR);
142}
143
144/*
145 * Compare the new matrix state (volatile) with the stable one stored in
146 * keypad->matrix_stable_state and fire events if changes are detected.
147 */
148static void imx_keypad_fire_events(struct imx_keypad *keypad,
149 unsigned short *matrix_volatile_state)
150{
151 struct input_dev *input_dev = keypad->input_dev;
152 int row, col;
153
154 for (col = 0; col < MAX_MATRIX_KEY_COLS; col++) {
155 unsigned short bits_changed;
156 int code;
157
158 if ((keypad->cols_en_mask & (1 << col)) == 0)
159 continue; /* Column is not enabled */
160
161 bits_changed = keypad->matrix_stable_state[col] ^
162 matrix_volatile_state[col];
163
164 if (bits_changed == 0)
165 continue; /* Column does not contain changes */
166
167 for (row = 0; row < MAX_MATRIX_KEY_ROWS; row++) {
168 if ((keypad->rows_en_mask & (1 << row)) == 0)
169 continue; /* Row is not enabled */
170 if ((bits_changed & (1 << row)) == 0)
171 continue; /* Row does not contain changes */
172
173 code = MATRIX_SCAN_CODE(row, col, MATRIX_ROW_SHIFT);
174 input_event(input_dev, EV_MSC, MSC_SCAN, code);
175 input_report_key(input_dev, keypad->keycodes[code],
176 matrix_volatile_state[col] & (1 << row));
177 dev_dbg(&input_dev->dev, "Event code: %d, val: %d",
178 keypad->keycodes[code],
179 matrix_volatile_state[col] & (1 << row));
180 }
181 }
182 input_sync(input_dev);
183}
184
185/*
186 * imx_keypad_check_for_events is the timer handler.
187 */
188static void imx_keypad_check_for_events(unsigned long data)
189{
190 struct imx_keypad *keypad = (struct imx_keypad *) data;
191 unsigned short matrix_volatile_state[MAX_MATRIX_KEY_COLS];
192 unsigned short reg_val;
193 bool state_changed, is_zero_matrix;
194 int i;
195
196 memset(matrix_volatile_state, 0, sizeof(matrix_volatile_state));
197
198 imx_keypad_scan_matrix(keypad, matrix_volatile_state);
199
200 state_changed = false;
201 for (i = 0; i < MAX_MATRIX_KEY_COLS; i++) {
202 if ((keypad->cols_en_mask & (1 << i)) == 0)
203 continue;
204
205 if (keypad->matrix_unstable_state[i] ^ matrix_volatile_state[i]) {
206 state_changed = true;
207 break;
208 }
209 }
210
211 /*
212 * If the matrix state is changed from the previous scan
213 * (Re)Begin the debouncing process, saving the new state in
214 * keypad->matrix_unstable_state.
215 * else
216 * Increase the count of number of scans with a stable state.
217 */
218 if (state_changed) {
219 memcpy(keypad->matrix_unstable_state, matrix_volatile_state,
220 sizeof(matrix_volatile_state));
221 keypad->stable_count = 0;
222 } else
223 keypad->stable_count++;
224
225 /*
226 * If the matrix is not as stable as we want reschedule scan
227 * in the near future.
228 */
229 if (keypad->stable_count < IMX_KEYPAD_SCANS_FOR_STABILITY) {
230 mod_timer(&keypad->check_matrix_timer,
231 jiffies + msecs_to_jiffies(10));
232 return;
233 }
234
235 /*
236 * If the matrix state is stable, fire the events and save the new
237 * stable state. Note, if the matrix is kept stable for longer
238 * (keypad->stable_count > IMX_KEYPAD_SCANS_FOR_STABILITY) all
239 * events have already been generated.
240 */
241 if (keypad->stable_count == IMX_KEYPAD_SCANS_FOR_STABILITY) {
242 imx_keypad_fire_events(keypad, matrix_volatile_state);
243
244 memcpy(keypad->matrix_stable_state, matrix_volatile_state,
245 sizeof(matrix_volatile_state));
246 }
247
248 is_zero_matrix = true;
249 for (i = 0; i < MAX_MATRIX_KEY_COLS; i++) {
250 if (matrix_volatile_state[i] != 0) {
251 is_zero_matrix = false;
252 break;
253 }
254 }
255
256
257 if (is_zero_matrix) {
258 /*
259 * All keys have been released. Enable only the KDI
260 * interrupt for future key presses (clear the KDI
261 * status bit and its sync chain before that).
262 */
263 reg_val = readw(keypad->mmio_base + KPSR);
264 reg_val |= KBD_STAT_KPKD | KBD_STAT_KDSC;
265 writew(reg_val, keypad->mmio_base + KPSR);
266
267 reg_val = readw(keypad->mmio_base + KPSR);
268 reg_val |= KBD_STAT_KDIE;
269 reg_val &= ~KBD_STAT_KRIE;
270 writew(reg_val, keypad->mmio_base + KPSR);
271 } else {
272 /*
273 * Some keys are still pressed. Schedule a rescan in
274 * attempt to detect multiple key presses and enable
275 * the KRI interrupt to react quickly to key release
276 * event.
277 */
278 mod_timer(&keypad->check_matrix_timer,
279 jiffies + msecs_to_jiffies(60));
280
281 reg_val = readw(keypad->mmio_base + KPSR);
282 reg_val |= KBD_STAT_KPKR | KBD_STAT_KRSS;
283 writew(reg_val, keypad->mmio_base + KPSR);
284
285 reg_val = readw(keypad->mmio_base + KPSR);
286 reg_val |= KBD_STAT_KRIE;
287 reg_val &= ~KBD_STAT_KDIE;
288 writew(reg_val, keypad->mmio_base + KPSR);
289 }
290}
291
292static irqreturn_t imx_keypad_irq_handler(int irq, void *dev_id)
293{
294 struct imx_keypad *keypad = dev_id;
295 unsigned short reg_val;
296
297 reg_val = readw(keypad->mmio_base + KPSR);
298
299 /* Disable both interrupt types */
300 reg_val &= ~(KBD_STAT_KRIE | KBD_STAT_KDIE);
301 /* Clear interrupts status bits */
302 reg_val |= KBD_STAT_KPKR | KBD_STAT_KPKD;
303 writew(reg_val, keypad->mmio_base + KPSR);
304
305 if (keypad->enabled) {
306 /* The matrix is supposed to be changed */
307 keypad->stable_count = 0;
308
309 /* Schedule the scanning procedure near in the future */
310 mod_timer(&keypad->check_matrix_timer,
311 jiffies + msecs_to_jiffies(2));
312 }
313
314 return IRQ_HANDLED;
315}
316
317static void imx_keypad_config(struct imx_keypad *keypad)
318{
319 unsigned short reg_val;
320
321 /*
322 * Include enabled rows in interrupt generation (KPCR[7:0])
323 * Configure keypad columns as open-drain (KPCR[15:8])
324 */
325 reg_val = readw(keypad->mmio_base + KPCR);
326 reg_val |= keypad->rows_en_mask & 0xff; /* rows */
327 reg_val |= (keypad->cols_en_mask & 0xff) << 8; /* cols */
328 writew(reg_val, keypad->mmio_base + KPCR);
329
330 /* Write 0's to KPDR[15:8] (Colums) */
331 reg_val = readw(keypad->mmio_base + KPDR);
332 reg_val &= 0x00ff;
333 writew(reg_val, keypad->mmio_base + KPDR);
334
335 /* Configure columns as output, rows as input (KDDR[15:0]) */
336 writew(0xff00, keypad->mmio_base + KDDR);
337
338 /*
339 * Clear Key Depress and Key Release status bit.
340 * Clear both synchronizer chain.
341 */
342 reg_val = readw(keypad->mmio_base + KPSR);
343 reg_val |= KBD_STAT_KPKR | KBD_STAT_KPKD |
344 KBD_STAT_KDSC | KBD_STAT_KRSS;
345 writew(reg_val, keypad->mmio_base + KPSR);
346
347 /* Enable KDI and disable KRI (avoid false release events). */
348 reg_val |= KBD_STAT_KDIE;
349 reg_val &= ~KBD_STAT_KRIE;
350 writew(reg_val, keypad->mmio_base + KPSR);
351}
352
353static void imx_keypad_inhibit(struct imx_keypad *keypad)
354{
355 unsigned short reg_val;
356
357 /* Inhibit KDI and KRI interrupts. */
358 reg_val = readw(keypad->mmio_base + KPSR);
359 reg_val &= ~(KBD_STAT_KRIE | KBD_STAT_KDIE);
360 writew(reg_val, keypad->mmio_base + KPSR);
361
362 /* Colums as open drain and disable all rows */
363 writew(0xff00, keypad->mmio_base + KPCR);
364}
365
366static void imx_keypad_close(struct input_dev *dev)
367{
368 struct imx_keypad *keypad = input_get_drvdata(dev);
369
370 dev_dbg(&dev->dev, ">%s\n", __func__);
371
372 /* Mark keypad as being inactive */
373 keypad->enabled = false;
374 synchronize_irq(keypad->irq);
375 del_timer_sync(&keypad->check_matrix_timer);
376
377 imx_keypad_inhibit(keypad);
378
379 /* Disable clock unit */
380 clk_disable(keypad->clk);
381}
382
383static int imx_keypad_open(struct input_dev *dev)
384{
385 struct imx_keypad *keypad = input_get_drvdata(dev);
386
387 dev_dbg(&dev->dev, ">%s\n", __func__);
388
389 /* We became active from now */
390 keypad->enabled = true;
391
392 /* Enable the kpp clock */
393 clk_enable(keypad->clk);
394 imx_keypad_config(keypad);
395
396 /* Sanity control, not all the rows must be actived now. */
397 if ((readw(keypad->mmio_base + KPDR) & keypad->rows_en_mask) == 0) {
398 dev_err(&dev->dev,
399 "too many keys pressed, control pins initialisation\n");
400 goto open_err;
401 }
402
403 return 0;
404
405open_err:
406 imx_keypad_close(dev);
407 return -EIO;
408}
409
410static int __devinit imx_keypad_probe(struct platform_device *pdev)
411{
412 const struct matrix_keymap_data *keymap_data = pdev->dev.platform_data;
413 struct imx_keypad *keypad;
414 struct input_dev *input_dev;
415 struct resource *res;
416 int irq, error, i;
417
418 if (keymap_data == NULL) {
419 dev_err(&pdev->dev, "no keymap defined\n");
420 return -EINVAL;
421 }
422
423 irq = platform_get_irq(pdev, 0);
424 if (irq < 0) {
425 dev_err(&pdev->dev, "no irq defined in platform data\n");
426 return -EINVAL;
427 }
428
429 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
430 if (res == NULL) {
431 dev_err(&pdev->dev, "no I/O memory defined in platform data\n");
432 return -EINVAL;
433 }
434
435 res = request_mem_region(res->start, resource_size(res), pdev->name);
436 if (res == NULL) {
437 dev_err(&pdev->dev, "failed to request I/O memory\n");
438 return -EBUSY;
439 }
440
441 input_dev = input_allocate_device();
442 if (!input_dev) {
443 dev_err(&pdev->dev, "failed to allocate the input device\n");
444 error = -ENOMEM;
445 goto failed_rel_mem;
446 }
447
448 keypad = kzalloc(sizeof(struct imx_keypad), GFP_KERNEL);
449 if (!keypad) {
450 dev_err(&pdev->dev, "not enough memory for driver data\n");
451 error = -ENOMEM;
452 goto failed_free_input;
453 }
454
455 keypad->input_dev = input_dev;
456 keypad->irq = irq;
457 keypad->stable_count = 0;
458
459 setup_timer(&keypad->check_matrix_timer,
460 imx_keypad_check_for_events, (unsigned long) keypad);
461
462 keypad->mmio_base = ioremap(res->start, resource_size(res));
463 if (keypad->mmio_base == NULL) {
464 dev_err(&pdev->dev, "failed to remap I/O memory\n");
465 error = -ENOMEM;
466 goto failed_free_priv;
467 }
468
469 keypad->clk = clk_get(&pdev->dev, "kpp");
470 if (IS_ERR(keypad->clk)) {
471 dev_err(&pdev->dev, "failed to get keypad clock\n");
472 error = PTR_ERR(keypad->clk);
473 goto failed_unmap;
474 }
475
476 /* Search for rows and cols enabled */
477 for (i = 0; i < keymap_data->keymap_size; i++) {
478 keypad->rows_en_mask |= 1 << KEY_ROW(keymap_data->keymap[i]);
479 keypad->cols_en_mask |= 1 << KEY_COL(keymap_data->keymap[i]);
480 }
481
482 if (keypad->rows_en_mask > ((1 << MAX_MATRIX_KEY_ROWS) - 1) ||
483 keypad->cols_en_mask > ((1 << MAX_MATRIX_KEY_COLS) - 1)) {
484 dev_err(&pdev->dev,
485 "invalid key data (too many rows or colums)\n");
486 error = -EINVAL;
487 goto failed_clock_put;
488 }
489 dev_dbg(&pdev->dev, "enabled rows mask: %x\n", keypad->rows_en_mask);
490 dev_dbg(&pdev->dev, "enabled cols mask: %x\n", keypad->cols_en_mask);
491
492 /* Init the Input device */
493 input_dev->name = pdev->name;
494 input_dev->id.bustype = BUS_HOST;
495 input_dev->dev.parent = &pdev->dev;
496 input_dev->open = imx_keypad_open;
497 input_dev->close = imx_keypad_close;
498 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REP);
499 input_dev->keycode = keypad->keycodes;
500 input_dev->keycodesize = sizeof(keypad->keycodes[0]);
501 input_dev->keycodemax = ARRAY_SIZE(keypad->keycodes);
502
503 matrix_keypad_build_keymap(keymap_data, MATRIX_ROW_SHIFT,
504 keypad->keycodes, input_dev->keybit);
505
506 input_set_capability(input_dev, EV_MSC, MSC_SCAN);
507 input_set_drvdata(input_dev, keypad);
508
509 /* Ensure that the keypad will stay dormant until opened */
510 imx_keypad_inhibit(keypad);
511
512 error = request_irq(irq, imx_keypad_irq_handler, IRQF_DISABLED,
513 pdev->name, keypad);
514 if (error) {
515 dev_err(&pdev->dev, "failed to request IRQ\n");
516 goto failed_clock_put;
517 }
518
519 /* Register the input device */
520 error = input_register_device(input_dev);
521 if (error) {
522 dev_err(&pdev->dev, "failed to register input device\n");
523 goto failed_free_irq;
524 }
525
526 platform_set_drvdata(pdev, keypad);
527 device_init_wakeup(&pdev->dev, 1);
528
529 return 0;
530
531failed_free_irq:
532 free_irq(irq, pdev);
533failed_clock_put:
534 clk_put(keypad->clk);
535failed_unmap:
536 iounmap(keypad->mmio_base);
537failed_free_priv:
538 kfree(keypad);
539failed_free_input:
540 input_free_device(input_dev);
541failed_rel_mem:
542 release_mem_region(res->start, resource_size(res));
543 return error;
544}
545
546static int __devexit imx_keypad_remove(struct platform_device *pdev)
547{
548 struct imx_keypad *keypad = platform_get_drvdata(pdev);
549 struct resource *res;
550
551 dev_dbg(&pdev->dev, ">%s\n", __func__);
552
553 platform_set_drvdata(pdev, NULL);
554
555 input_unregister_device(keypad->input_dev);
556
557 free_irq(keypad->irq, keypad);
558 clk_put(keypad->clk);
559
560 iounmap(keypad->mmio_base);
561 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
562 release_mem_region(res->start, resource_size(res));
563
564 kfree(keypad);
565
566 return 0;
567}
568
569static struct platform_driver imx_keypad_driver = {
570 .driver = {
571 .name = "imx-keypad",
572 .owner = THIS_MODULE,
573 },
574 .probe = imx_keypad_probe,
575 .remove = __devexit_p(imx_keypad_remove),
576};
577
578static int __init imx_keypad_init(void)
579{
580 return platform_driver_register(&imx_keypad_driver);
581}
582
583static void __exit imx_keypad_exit(void)
584{
585 platform_driver_unregister(&imx_keypad_driver);
586}
587
588module_init(imx_keypad_init);
589module_exit(imx_keypad_exit);
590
591MODULE_AUTHOR("Alberto Panizzo <maramaopercheseimorto@gmail.com>");
592MODULE_DESCRIPTION("IMX Keypad Port Driver");
593MODULE_LICENSE("GPL v2");
594MODULE_ALIAS("platform:imx-keypad");
diff --git a/drivers/input/keyboard/qt2160.c b/drivers/input/keyboard/qt2160.c
index 191cc51d6cf8..31f30087b591 100644
--- a/drivers/input/keyboard/qt2160.c
+++ b/drivers/input/keyboard/qt2160.c
@@ -362,7 +362,7 @@ static int __devexit qt2160_remove(struct i2c_client *client)
362 return 0; 362 return 0;
363} 363}
364 364
365static struct i2c_device_id qt2160_idtable[] = { 365static const struct i2c_device_id qt2160_idtable[] = {
366 { "qt2160", 0, }, 366 { "qt2160", 0, },
367 { } 367 { }
368}; 368};
diff --git a/drivers/input/keyboard/sh_keysc.c b/drivers/input/keyboard/sh_keysc.c
index 8e9380bfed40..854e2035cd6e 100644
--- a/drivers/input/keyboard/sh_keysc.c
+++ b/drivers/input/keyboard/sh_keysc.c
@@ -19,101 +19,141 @@
19#include <linux/platform_device.h> 19#include <linux/platform_device.h>
20#include <linux/input.h> 20#include <linux/input.h>
21#include <linux/input/sh_keysc.h> 21#include <linux/input/sh_keysc.h>
22#include <linux/bitmap.h>
22#include <linux/clk.h> 23#include <linux/clk.h>
23#include <linux/io.h> 24#include <linux/io.h>
24 25
25#define KYCR1_OFFS 0x00
26#define KYCR2_OFFS 0x04
27#define KYINDR_OFFS 0x08
28#define KYOUTDR_OFFS 0x0c
29
30#define KYCR2_IRQ_LEVEL 0x10
31#define KYCR2_IRQ_DISABLED 0x00
32
33static const struct { 26static const struct {
34 unsigned char kymd, keyout, keyin; 27 unsigned char kymd, keyout, keyin;
35} sh_keysc_mode[] = { 28} sh_keysc_mode[] = {
36 [SH_KEYSC_MODE_1] = { 0, 6, 5 }, 29 [SH_KEYSC_MODE_1] = { 0, 6, 5 },
37 [SH_KEYSC_MODE_2] = { 1, 5, 6 }, 30 [SH_KEYSC_MODE_2] = { 1, 5, 6 },
38 [SH_KEYSC_MODE_3] = { 2, 4, 7 }, 31 [SH_KEYSC_MODE_3] = { 2, 4, 7 },
32 [SH_KEYSC_MODE_4] = { 3, 6, 6 },
33 [SH_KEYSC_MODE_5] = { 4, 6, 7 },
34 [SH_KEYSC_MODE_6] = { 5, 7, 7 },
39}; 35};
40 36
41struct sh_keysc_priv { 37struct sh_keysc_priv {
42 void __iomem *iomem_base; 38 void __iomem *iomem_base;
43 struct clk *clk; 39 struct clk *clk;
44 unsigned long last_keys; 40 DECLARE_BITMAP(last_keys, SH_KEYSC_MAXKEYS);
45 struct input_dev *input; 41 struct input_dev *input;
46 struct sh_keysc_info pdata; 42 struct sh_keysc_info pdata;
47}; 43};
48 44
45#define KYCR1 0
46#define KYCR2 1
47#define KYINDR 2
48#define KYOUTDR 3
49
50#define KYCR2_IRQ_LEVEL 0x10
51#define KYCR2_IRQ_DISABLED 0x00
52
53static unsigned long sh_keysc_read(struct sh_keysc_priv *p, int reg_nr)
54{
55 return ioread16(p->iomem_base + (reg_nr << 2));
56}
57
58static void sh_keysc_write(struct sh_keysc_priv *p, int reg_nr,
59 unsigned long value)
60{
61 iowrite16(value, p->iomem_base + (reg_nr << 2));
62}
63
64static void sh_keysc_level_mode(struct sh_keysc_priv *p,
65 unsigned long keys_set)
66{
67 struct sh_keysc_info *pdata = &p->pdata;
68
69 sh_keysc_write(p, KYOUTDR, 0);
70 sh_keysc_write(p, KYCR2, KYCR2_IRQ_LEVEL | (keys_set << 8));
71
72 if (pdata->kycr2_delay)
73 udelay(pdata->kycr2_delay);
74}
75
76static void sh_keysc_map_dbg(struct device *dev, unsigned long *map,
77 const char *str)
78{
79 int k;
80
81 for (k = 0; k < BITS_TO_LONGS(SH_KEYSC_MAXKEYS); k++)
82 dev_dbg(dev, "%s[%d] 0x%lx\n", str, k, map[k]);
83}
84
49static irqreturn_t sh_keysc_isr(int irq, void *dev_id) 85static irqreturn_t sh_keysc_isr(int irq, void *dev_id)
50{ 86{
51 struct platform_device *pdev = dev_id; 87 struct platform_device *pdev = dev_id;
52 struct sh_keysc_priv *priv = platform_get_drvdata(pdev); 88 struct sh_keysc_priv *priv = platform_get_drvdata(pdev);
53 struct sh_keysc_info *pdata = &priv->pdata; 89 struct sh_keysc_info *pdata = &priv->pdata;
54 unsigned long keys, keys1, keys0, mask; 90 int keyout_nr = sh_keysc_mode[pdata->mode].keyout;
91 int keyin_nr = sh_keysc_mode[pdata->mode].keyin;
92 DECLARE_BITMAP(keys, SH_KEYSC_MAXKEYS);
93 DECLARE_BITMAP(keys0, SH_KEYSC_MAXKEYS);
94 DECLARE_BITMAP(keys1, SH_KEYSC_MAXKEYS);
55 unsigned char keyin_set, tmp; 95 unsigned char keyin_set, tmp;
56 int i, k; 96 int i, k, n;
57 97
58 dev_dbg(&pdev->dev, "isr!\n"); 98 dev_dbg(&pdev->dev, "isr!\n");
59 99
60 keys1 = ~0; 100 bitmap_fill(keys1, SH_KEYSC_MAXKEYS);
61 keys0 = 0; 101 bitmap_zero(keys0, SH_KEYSC_MAXKEYS);
62 102
63 do { 103 do {
64 keys = 0; 104 bitmap_zero(keys, SH_KEYSC_MAXKEYS);
65 keyin_set = 0; 105 keyin_set = 0;
66 106
67 iowrite16(KYCR2_IRQ_DISABLED, priv->iomem_base + KYCR2_OFFS); 107 sh_keysc_write(priv, KYCR2, KYCR2_IRQ_DISABLED);
108
109 for (i = 0; i < keyout_nr; i++) {
110 n = keyin_nr * i;
68 111
69 for (i = 0; i < sh_keysc_mode[pdata->mode].keyout; i++) { 112 /* drive one KEYOUT pin low, read KEYIN pins */
70 iowrite16(0xfff ^ (3 << (i * 2)), 113 sh_keysc_write(priv, KYOUTDR, 0xffff ^ (3 << (i * 2)));
71 priv->iomem_base + KYOUTDR_OFFS);
72 udelay(pdata->delay); 114 udelay(pdata->delay);
73 tmp = ioread16(priv->iomem_base + KYINDR_OFFS); 115 tmp = sh_keysc_read(priv, KYINDR);
74 keys |= tmp << (sh_keysc_mode[pdata->mode].keyin * i);
75 tmp ^= (1 << sh_keysc_mode[pdata->mode].keyin) - 1;
76 keyin_set |= tmp;
77 }
78 116
79 iowrite16(0, priv->iomem_base + KYOUTDR_OFFS); 117 /* set bit if key press has been detected */
80 iowrite16(KYCR2_IRQ_LEVEL | (keyin_set << 8), 118 for (k = 0; k < keyin_nr; k++) {
81 priv->iomem_base + KYCR2_OFFS); 119 if (tmp & (1 << k))
120 __set_bit(n + k, keys);
121 }
82 122
83 if (pdata->kycr2_delay) 123 /* keep track of which KEYIN bits that have been set */
84 udelay(pdata->kycr2_delay); 124 keyin_set |= tmp ^ ((1 << keyin_nr) - 1);
125 }
85 126
86 keys ^= ~0; 127 sh_keysc_level_mode(priv, keyin_set);
87 keys &= (1 << (sh_keysc_mode[pdata->mode].keyin *
88 sh_keysc_mode[pdata->mode].keyout)) - 1;
89 keys1 &= keys;
90 keys0 |= keys;
91 128
92 dev_dbg(&pdev->dev, "keys 0x%08lx\n", keys); 129 bitmap_complement(keys, keys, SH_KEYSC_MAXKEYS);
130 bitmap_and(keys1, keys1, keys, SH_KEYSC_MAXKEYS);
131 bitmap_or(keys0, keys0, keys, SH_KEYSC_MAXKEYS);
93 132
94 } while (ioread16(priv->iomem_base + KYCR2_OFFS) & 0x01); 133 sh_keysc_map_dbg(&pdev->dev, keys, "keys");
95 134
96 dev_dbg(&pdev->dev, "last_keys 0x%08lx keys0 0x%08lx keys1 0x%08lx\n", 135 } while (sh_keysc_read(priv, KYCR2) & 0x01);
97 priv->last_keys, keys0, keys1); 136
137 sh_keysc_map_dbg(&pdev->dev, priv->last_keys, "last_keys");
138 sh_keysc_map_dbg(&pdev->dev, keys0, "keys0");
139 sh_keysc_map_dbg(&pdev->dev, keys1, "keys1");
98 140
99 for (i = 0; i < SH_KEYSC_MAXKEYS; i++) { 141 for (i = 0; i < SH_KEYSC_MAXKEYS; i++) {
100 k = pdata->keycodes[i]; 142 k = pdata->keycodes[i];
101 if (!k) 143 if (!k)
102 continue; 144 continue;
103 145
104 mask = 1 << i; 146 if (test_bit(i, keys0) == test_bit(i, priv->last_keys))
105
106 if (!((priv->last_keys ^ keys0) & mask))
107 continue; 147 continue;
108 148
109 if ((keys1 | keys0) & mask) { 149 if (test_bit(i, keys1) || test_bit(i, keys0)) {
110 input_event(priv->input, EV_KEY, k, 1); 150 input_event(priv->input, EV_KEY, k, 1);
111 priv->last_keys |= mask; 151 __set_bit(i, priv->last_keys);
112 } 152 }
113 153
114 if (!(keys1 & mask)) { 154 if (!test_bit(i, keys1)) {
115 input_event(priv->input, EV_KEY, k, 0); 155 input_event(priv->input, EV_KEY, k, 0);
116 priv->last_keys &= ~mask; 156 __clear_bit(i, priv->last_keys);
117 } 157 }
118 158
119 } 159 }
@@ -122,8 +162,6 @@ static irqreturn_t sh_keysc_isr(int irq, void *dev_id)
122 return IRQ_HANDLED; 162 return IRQ_HANDLED;
123} 163}
124 164
125#define res_size(res) ((res)->end - (res)->start + 1)
126
127static int __devinit sh_keysc_probe(struct platform_device *pdev) 165static int __devinit sh_keysc_probe(struct platform_device *pdev)
128{ 166{
129 struct sh_keysc_priv *priv; 167 struct sh_keysc_priv *priv;
@@ -164,7 +202,7 @@ static int __devinit sh_keysc_probe(struct platform_device *pdev)
164 memcpy(&priv->pdata, pdev->dev.platform_data, sizeof(priv->pdata)); 202 memcpy(&priv->pdata, pdev->dev.platform_data, sizeof(priv->pdata));
165 pdata = &priv->pdata; 203 pdata = &priv->pdata;
166 204
167 priv->iomem_base = ioremap_nocache(res->start, res_size(res)); 205 priv->iomem_base = ioremap_nocache(res->start, resource_size(res));
168 if (priv->iomem_base == NULL) { 206 if (priv->iomem_base == NULL) {
169 dev_err(&pdev->dev, "failed to remap I/O memory\n"); 207 dev_err(&pdev->dev, "failed to remap I/O memory\n");
170 error = -ENXIO; 208 error = -ENXIO;
@@ -220,10 +258,9 @@ static int __devinit sh_keysc_probe(struct platform_device *pdev)
220 258
221 clk_enable(priv->clk); 259 clk_enable(priv->clk);
222 260
223 iowrite16((sh_keysc_mode[pdata->mode].kymd << 8) | 261 sh_keysc_write(priv, KYCR1, (sh_keysc_mode[pdata->mode].kymd << 8) |
224 pdata->scan_timing, priv->iomem_base + KYCR1_OFFS); 262 pdata->scan_timing);
225 iowrite16(0, priv->iomem_base + KYOUTDR_OFFS); 263 sh_keysc_level_mode(priv, 0);
226 iowrite16(KYCR2_IRQ_LEVEL, priv->iomem_base + KYCR2_OFFS);
227 264
228 device_init_wakeup(&pdev->dev, 1); 265 device_init_wakeup(&pdev->dev, 1);
229 266
@@ -248,7 +285,7 @@ static int __devexit sh_keysc_remove(struct platform_device *pdev)
248{ 285{
249 struct sh_keysc_priv *priv = platform_get_drvdata(pdev); 286 struct sh_keysc_priv *priv = platform_get_drvdata(pdev);
250 287
251 iowrite16(KYCR2_IRQ_DISABLED, priv->iomem_base + KYCR2_OFFS); 288 sh_keysc_write(priv, KYCR2, KYCR2_IRQ_DISABLED);
252 289
253 input_unregister_device(priv->input); 290 input_unregister_device(priv->input);
254 free_irq(platform_get_irq(pdev, 0), pdev); 291 free_irq(platform_get_irq(pdev, 0), pdev);
@@ -270,7 +307,7 @@ static int sh_keysc_suspend(struct device *dev)
270 int irq = platform_get_irq(pdev, 0); 307 int irq = platform_get_irq(pdev, 0);
271 unsigned short value; 308 unsigned short value;
272 309
273 value = ioread16(priv->iomem_base + KYCR1_OFFS); 310 value = sh_keysc_read(priv, KYCR1);
274 311
275 if (device_may_wakeup(dev)) { 312 if (device_may_wakeup(dev)) {
276 value |= 0x80; 313 value |= 0x80;
@@ -279,7 +316,7 @@ static int sh_keysc_suspend(struct device *dev)
279 value &= ~0x80; 316 value &= ~0x80;
280 } 317 }
281 318
282 iowrite16(value, priv->iomem_base + KYCR1_OFFS); 319 sh_keysc_write(priv, KYCR1, value);
283 320
284 return 0; 321 return 0;
285} 322}
diff --git a/drivers/input/misc/apanel.c b/drivers/input/misc/apanel.c
index 71b82434264d..a8d2b8db4e35 100644
--- a/drivers/input/misc/apanel.c
+++ b/drivers/input/misc/apanel.c
@@ -149,7 +149,7 @@ static void apanel_shutdown(struct i2c_client *client)
149 apanel_remove(client); 149 apanel_remove(client);
150} 150}
151 151
152static struct i2c_device_id apanel_id[] = { 152static const struct i2c_device_id apanel_id[] = {
153 { "fujitsu_apanel", 0 }, 153 { "fujitsu_apanel", 0 },
154 { } 154 { }
155}; 155};
diff --git a/drivers/input/misc/rotary_encoder.c b/drivers/input/misc/rotary_encoder.c
index 3b9f588fc747..4ae07935985e 100644
--- a/drivers/input/misc/rotary_encoder.c
+++ b/drivers/input/misc/rotary_encoder.c
@@ -152,6 +152,13 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev)
152 goto exit_unregister_input; 152 goto exit_unregister_input;
153 } 153 }
154 154
155 err = gpio_direction_input(pdata->gpio_a);
156 if (err) {
157 dev_err(&pdev->dev, "unable to set GPIO %d for input\n",
158 pdata->gpio_a);
159 goto exit_unregister_input;
160 }
161
155 err = gpio_request(pdata->gpio_b, DRV_NAME); 162 err = gpio_request(pdata->gpio_b, DRV_NAME);
156 if (err) { 163 if (err) {
157 dev_err(&pdev->dev, "unable to request GPIO %d\n", 164 dev_err(&pdev->dev, "unable to request GPIO %d\n",
@@ -159,6 +166,13 @@ static int __devinit rotary_encoder_probe(struct platform_device *pdev)
159 goto exit_free_gpio_a; 166 goto exit_free_gpio_a;
160 } 167 }
161 168
169 err = gpio_direction_input(pdata->gpio_b);
170 if (err) {
171 dev_err(&pdev->dev, "unable to set GPIO %d for input\n",
172 pdata->gpio_b);
173 goto exit_free_gpio_a;
174 }
175
162 /* request the IRQs */ 176 /* request the IRQs */
163 err = request_irq(encoder->irq_a, &rotary_encoder_irq, 177 err = request_irq(encoder->irq_a, &rotary_encoder_irq,
164 IORESOURCE_IRQ_HIGHEDGE | IORESOURCE_IRQ_LOWEDGE, 178 IORESOURCE_IRQ_HIGHEDGE | IORESOURCE_IRQ_LOWEDGE,
diff --git a/drivers/input/misc/uinput.c b/drivers/input/misc/uinput.c
index d3f57245420a..1477466076ad 100644
--- a/drivers/input/misc/uinput.c
+++ b/drivers/input/misc/uinput.c
@@ -34,7 +34,6 @@
34#include <linux/slab.h> 34#include <linux/slab.h>
35#include <linux/module.h> 35#include <linux/module.h>
36#include <linux/init.h> 36#include <linux/init.h>
37#include <linux/smp_lock.h>
38#include <linux/fs.h> 37#include <linux/fs.h>
39#include <linux/miscdevice.h> 38#include <linux/miscdevice.h>
40#include <linux/uinput.h> 39#include <linux/uinput.h>
@@ -284,7 +283,6 @@ static int uinput_open(struct inode *inode, struct file *file)
284 if (!newdev) 283 if (!newdev)
285 return -ENOMEM; 284 return -ENOMEM;
286 285
287 lock_kernel();
288 mutex_init(&newdev->mutex); 286 mutex_init(&newdev->mutex);
289 spin_lock_init(&newdev->requests_lock); 287 spin_lock_init(&newdev->requests_lock);
290 init_waitqueue_head(&newdev->requests_waitq); 288 init_waitqueue_head(&newdev->requests_waitq);
@@ -292,7 +290,7 @@ static int uinput_open(struct inode *inode, struct file *file)
292 newdev->state = UIST_NEW_DEVICE; 290 newdev->state = UIST_NEW_DEVICE;
293 291
294 file->private_data = newdev; 292 file->private_data = newdev;
295 unlock_kernel(); 293 nonseekable_open(inode, file);
296 294
297 return 0; 295 return 0;
298} 296}
diff --git a/drivers/input/misc/winbond-cir.c b/drivers/input/misc/winbond-cir.c
index c8f5a9a3fa14..cbec3dfdd42b 100644
--- a/drivers/input/misc/winbond-cir.c
+++ b/drivers/input/misc/winbond-cir.c
@@ -538,6 +538,7 @@ wbcir_reset_irdata(struct wbcir_data *data)
538 data->irdata_count = 0; 538 data->irdata_count = 0;
539 data->irdata_off = 0; 539 data->irdata_off = 0;
540 data->irdata_error = 0; 540 data->irdata_error = 0;
541 data->idle_count = 0;
541} 542}
542 543
543/* Adds one bit of irdata */ 544/* Adds one bit of irdata */
@@ -1006,7 +1007,6 @@ wbcir_irq_handler(int irqno, void *cookie)
1006 } 1007 }
1007 1008
1008 wbcir_reset_irdata(data); 1009 wbcir_reset_irdata(data);
1009 data->idle_count = 0;
1010 } 1010 }
1011 1011
1012out: 1012out:
@@ -1018,7 +1018,7 @@ out:
1018 1018
1019/***************************************************************************** 1019/*****************************************************************************
1020 * 1020 *
1021 * SUSPEND/RESUME FUNCTIONS 1021 * SETUP/INIT/SUSPEND/RESUME FUNCTIONS
1022 * 1022 *
1023 *****************************************************************************/ 1023 *****************************************************************************/
1024 1024
@@ -1197,7 +1197,16 @@ finish:
1197 } 1197 }
1198 1198
1199 /* Disable interrupts */ 1199 /* Disable interrupts */
1200 wbcir_select_bank(data, WBCIR_BANK_0);
1200 outb(WBCIR_IRQ_NONE, data->sbase + WBCIR_REG_SP3_IER); 1201 outb(WBCIR_IRQ_NONE, data->sbase + WBCIR_REG_SP3_IER);
1202
1203 /*
1204 * ACPI will set the HW disable bit for SP3 which means that the
1205 * output signals are left in an undefined state which may cause
1206 * spurious interrupts which we need to ignore until the hardware
1207 * is reinitialized.
1208 */
1209 disable_irq(data->irq);
1201} 1210}
1202 1211
1203static int 1212static int
@@ -1207,37 +1216,15 @@ wbcir_suspend(struct pnp_dev *device, pm_message_t state)
1207 return 0; 1216 return 0;
1208} 1217}
1209 1218
1210static int
1211wbcir_resume(struct pnp_dev *device)
1212{
1213 struct wbcir_data *data = pnp_get_drvdata(device);
1214
1215 /* Clear BUFF_EN, Clear END_EN, Clear MATCH_EN */
1216 wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_EV_EN, 0x00, 0x07);
1217
1218 /* Clear CEIR_EN */
1219 wbcir_set_bits(data->wbase + WBCIR_REG_WCEIR_CTL, 0x00, 0x01);
1220
1221 /* Enable interrupts */
1222 wbcir_reset_irdata(data);
1223 outb(WBCIR_IRQ_RX | WBCIR_IRQ_ERR, data->sbase + WBCIR_REG_SP3_IER);
1224
1225 return 0;
1226}
1227
1228
1229
1230/*****************************************************************************
1231 *
1232 * SETUP/INIT FUNCTIONS
1233 *
1234 *****************************************************************************/
1235
1236static void 1219static void
1237wbcir_cfg_ceir(struct wbcir_data *data) 1220wbcir_init_hw(struct wbcir_data *data)
1238{ 1221{
1239 u8 tmp; 1222 u8 tmp;
1240 1223
1224 /* Disable interrupts */
1225 wbcir_select_bank(data, WBCIR_BANK_0);
1226 outb(WBCIR_IRQ_NONE, data->sbase + WBCIR_REG_SP3_IER);
1227
1241 /* Set PROT_SEL, RX_INV, Clear CEIR_EN (needed for the led) */ 1228 /* Set PROT_SEL, RX_INV, Clear CEIR_EN (needed for the led) */
1242 tmp = protocol << 4; 1229 tmp = protocol << 4;
1243 if (invert) 1230 if (invert)
@@ -1264,6 +1251,93 @@ wbcir_cfg_ceir(struct wbcir_data *data)
1264 * set SP3_IRRX_SW to binary 01, helpfully not documented 1251 * set SP3_IRRX_SW to binary 01, helpfully not documented
1265 */ 1252 */
1266 outb(0x10, data->ebase + WBCIR_REG_ECEIR_CTS); 1253 outb(0x10, data->ebase + WBCIR_REG_ECEIR_CTS);
1254
1255 /* Enable extended mode */
1256 wbcir_select_bank(data, WBCIR_BANK_2);
1257 outb(WBCIR_EXT_ENABLE, data->sbase + WBCIR_REG_SP3_EXCR1);
1258
1259 /*
1260 * Configure baud generator, IR data will be sampled at
1261 * a bitrate of: (24Mhz * prescaler) / (divisor * 16).
1262 *
1263 * The ECIR registers include a flag to change the
1264 * 24Mhz clock freq to 48Mhz.
1265 *
1266 * It's not documented in the specs, but fifo levels
1267 * other than 16 seems to be unsupported.
1268 */
1269
1270 /* prescaler 1.0, tx/rx fifo lvl 16 */
1271 outb(0x30, data->sbase + WBCIR_REG_SP3_EXCR2);
1272
1273 /* Set baud divisor to generate one byte per bit/cell */
1274 switch (protocol) {
1275 case IR_PROTOCOL_RC5:
1276 outb(0xA7, data->sbase + WBCIR_REG_SP3_BGDL);
1277 break;
1278 case IR_PROTOCOL_RC6:
1279 outb(0x53, data->sbase + WBCIR_REG_SP3_BGDL);
1280 break;
1281 case IR_PROTOCOL_NEC:
1282 outb(0x69, data->sbase + WBCIR_REG_SP3_BGDL);
1283 break;
1284 }
1285 outb(0x00, data->sbase + WBCIR_REG_SP3_BGDH);
1286
1287 /* Set CEIR mode */
1288 wbcir_select_bank(data, WBCIR_BANK_0);
1289 outb(0xC0, data->sbase + WBCIR_REG_SP3_MCR);
1290 inb(data->sbase + WBCIR_REG_SP3_LSR); /* Clear LSR */
1291 inb(data->sbase + WBCIR_REG_SP3_MSR); /* Clear MSR */
1292
1293 /* Disable RX demod, run-length encoding/decoding, set freq span */
1294 wbcir_select_bank(data, WBCIR_BANK_7);
1295 outb(0x10, data->sbase + WBCIR_REG_SP3_RCCFG);
1296
1297 /* Disable timer */
1298 wbcir_select_bank(data, WBCIR_BANK_4);
1299 outb(0x00, data->sbase + WBCIR_REG_SP3_IRCR1);
1300
1301 /* Enable MSR interrupt, Clear AUX_IRX */
1302 wbcir_select_bank(data, WBCIR_BANK_5);
1303 outb(0x00, data->sbase + WBCIR_REG_SP3_IRCR2);
1304
1305 /* Disable CRC */
1306 wbcir_select_bank(data, WBCIR_BANK_6);
1307 outb(0x20, data->sbase + WBCIR_REG_SP3_IRCR3);
1308
1309 /* Set RX/TX (de)modulation freq, not really used */
1310 wbcir_select_bank(data, WBCIR_BANK_7);
1311 outb(0xF2, data->sbase + WBCIR_REG_SP3_IRRXDC);
1312 outb(0x69, data->sbase + WBCIR_REG_SP3_IRTXMC);
1313
1314 /* Set invert and pin direction */
1315 if (invert)
1316 outb(0x10, data->sbase + WBCIR_REG_SP3_IRCFG4);
1317 else
1318 outb(0x00, data->sbase + WBCIR_REG_SP3_IRCFG4);
1319
1320 /* Set FIFO thresholds (RX = 8, TX = 3), reset RX/TX */
1321 wbcir_select_bank(data, WBCIR_BANK_0);
1322 outb(0x97, data->sbase + WBCIR_REG_SP3_FCR);
1323
1324 /* Clear AUX status bits */
1325 outb(0xE0, data->sbase + WBCIR_REG_SP3_ASCR);
1326
1327 /* Enable interrupts */
1328 wbcir_reset_irdata(data);
1329 outb(WBCIR_IRQ_RX | WBCIR_IRQ_ERR, data->sbase + WBCIR_REG_SP3_IER);
1330}
1331
1332static int
1333wbcir_resume(struct pnp_dev *device)
1334{
1335 struct wbcir_data *data = pnp_get_drvdata(device);
1336
1337 wbcir_init_hw(data);
1338 enable_irq(data->irq);
1339
1340 return 0;
1267} 1341}
1268 1342
1269static int __devinit 1343static int __devinit
@@ -1393,86 +1467,7 @@ wbcir_probe(struct pnp_dev *device, const struct pnp_device_id *dev_id)
1393 1467
1394 device_init_wakeup(&device->dev, 1); 1468 device_init_wakeup(&device->dev, 1);
1395 1469
1396 wbcir_cfg_ceir(data); 1470 wbcir_init_hw(data);
1397
1398 /* Disable interrupts */
1399 wbcir_select_bank(data, WBCIR_BANK_0);
1400 outb(WBCIR_IRQ_NONE, data->sbase + WBCIR_REG_SP3_IER);
1401
1402 /* Enable extended mode */
1403 wbcir_select_bank(data, WBCIR_BANK_2);
1404 outb(WBCIR_EXT_ENABLE, data->sbase + WBCIR_REG_SP3_EXCR1);
1405
1406 /*
1407 * Configure baud generator, IR data will be sampled at
1408 * a bitrate of: (24Mhz * prescaler) / (divisor * 16).
1409 *
1410 * The ECIR registers include a flag to change the
1411 * 24Mhz clock freq to 48Mhz.
1412 *
1413 * It's not documented in the specs, but fifo levels
1414 * other than 16 seems to be unsupported.
1415 */
1416
1417 /* prescaler 1.0, tx/rx fifo lvl 16 */
1418 outb(0x30, data->sbase + WBCIR_REG_SP3_EXCR2);
1419
1420 /* Set baud divisor to generate one byte per bit/cell */
1421 switch (protocol) {
1422 case IR_PROTOCOL_RC5:
1423 outb(0xA7, data->sbase + WBCIR_REG_SP3_BGDL);
1424 break;
1425 case IR_PROTOCOL_RC6:
1426 outb(0x53, data->sbase + WBCIR_REG_SP3_BGDL);
1427 break;
1428 case IR_PROTOCOL_NEC:
1429 outb(0x69, data->sbase + WBCIR_REG_SP3_BGDL);
1430 break;
1431 }
1432 outb(0x00, data->sbase + WBCIR_REG_SP3_BGDH);
1433
1434 /* Set CEIR mode */
1435 wbcir_select_bank(data, WBCIR_BANK_0);
1436 outb(0xC0, data->sbase + WBCIR_REG_SP3_MCR);
1437 inb(data->sbase + WBCIR_REG_SP3_LSR); /* Clear LSR */
1438 inb(data->sbase + WBCIR_REG_SP3_MSR); /* Clear MSR */
1439
1440 /* Disable RX demod, run-length encoding/decoding, set freq span */
1441 wbcir_select_bank(data, WBCIR_BANK_7);
1442 outb(0x10, data->sbase + WBCIR_REG_SP3_RCCFG);
1443
1444 /* Disable timer */
1445 wbcir_select_bank(data, WBCIR_BANK_4);
1446 outb(0x00, data->sbase + WBCIR_REG_SP3_IRCR1);
1447
1448 /* Enable MSR interrupt, Clear AUX_IRX */
1449 wbcir_select_bank(data, WBCIR_BANK_5);
1450 outb(0x00, data->sbase + WBCIR_REG_SP3_IRCR2);
1451
1452 /* Disable CRC */
1453 wbcir_select_bank(data, WBCIR_BANK_6);
1454 outb(0x20, data->sbase + WBCIR_REG_SP3_IRCR3);
1455
1456 /* Set RX/TX (de)modulation freq, not really used */
1457 wbcir_select_bank(data, WBCIR_BANK_7);
1458 outb(0xF2, data->sbase + WBCIR_REG_SP3_IRRXDC);
1459 outb(0x69, data->sbase + WBCIR_REG_SP3_IRTXMC);
1460
1461 /* Set invert and pin direction */
1462 if (invert)
1463 outb(0x10, data->sbase + WBCIR_REG_SP3_IRCFG4);
1464 else
1465 outb(0x00, data->sbase + WBCIR_REG_SP3_IRCFG4);
1466
1467 /* Set FIFO thresholds (RX = 8, TX = 3), reset RX/TX */
1468 wbcir_select_bank(data, WBCIR_BANK_0);
1469 outb(0x97, data->sbase + WBCIR_REG_SP3_FCR);
1470
1471 /* Clear AUX status bits */
1472 outb(0xE0, data->sbase + WBCIR_REG_SP3_ASCR);
1473
1474 /* Enable interrupts */
1475 outb(WBCIR_IRQ_RX | WBCIR_IRQ_ERR, data->sbase + WBCIR_REG_SP3_IER);
1476 1471
1477 return 0; 1472 return 0;
1478 1473
diff --git a/drivers/input/mouse/hgpk.c b/drivers/input/mouse/hgpk.c
index 90be30e93556..9169d1591c1f 100644
--- a/drivers/input/mouse/hgpk.c
+++ b/drivers/input/mouse/hgpk.c
@@ -68,10 +68,6 @@ module_param(post_interrupt_delay, int, 0644);
68MODULE_PARM_DESC(post_interrupt_delay, 68MODULE_PARM_DESC(post_interrupt_delay,
69 "delay (ms) before recal after recal interrupt detected"); 69 "delay (ms) before recal after recal interrupt detected");
70 70
71static int autorecal = 1;
72module_param(autorecal, int, 0644);
73MODULE_PARM_DESC(autorecal, "enable recalibration in the driver");
74
75/* 71/*
76 * When the touchpad gets ultra-sensitive, one can keep their finger 1/2" 72 * When the touchpad gets ultra-sensitive, one can keep their finger 1/2"
77 * above the pad and still have it send packets. This causes a jump cursor 73 * above the pad and still have it send packets. This causes a jump cursor
diff --git a/drivers/input/serio/pcips2.c b/drivers/input/serio/pcips2.c
index 1dacbe0d9348..797314be7af2 100644
--- a/drivers/input/serio/pcips2.c
+++ b/drivers/input/serio/pcips2.c
@@ -186,7 +186,7 @@ static void __devexit pcips2_remove(struct pci_dev *dev)
186 pci_disable_device(dev); 186 pci_disable_device(dev);
187} 187}
188 188
189static struct pci_device_id pcips2_ids[] = { 189static const struct pci_device_id pcips2_ids[] = {
190 { 190 {
191 .vendor = 0x14f2, /* MOBILITY */ 191 .vendor = 0x14f2, /* MOBILITY */
192 .device = 0x0123, /* Keyboard */ 192 .device = 0x0123, /* Keyboard */
diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
index e0f30186d513..c3b626e9eae7 100644
--- a/drivers/input/serio/serio.c
+++ b/drivers/input/serio/serio.c
@@ -26,6 +26,8 @@
26 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic 26 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
27 */ 27 */
28 28
29#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
29#include <linux/stddef.h> 31#include <linux/stddef.h>
30#include <linux/module.h> 32#include <linux/module.h>
31#include <linux/serio.h> 33#include <linux/serio.h>
@@ -119,11 +121,10 @@ static int serio_bind_driver(struct serio *serio, struct serio_driver *drv)
119 121
120 error = device_bind_driver(&serio->dev); 122 error = device_bind_driver(&serio->dev);
121 if (error) { 123 if (error) {
122 printk(KERN_WARNING 124 dev_warn(&serio->dev,
123 "serio: device_bind_driver() failed " 125 "device_bind_driver() failed for %s (%s) and %s, error: %d\n",
124 "for %s (%s) and %s, error: %d\n", 126 serio->phys, serio->name,
125 serio->phys, serio->name, 127 drv->description, error);
126 drv->description, error);
127 serio_disconnect_driver(serio); 128 serio_disconnect_driver(serio);
128 serio->dev.driver = NULL; 129 serio->dev.driver = NULL;
129 return error; 130 return error;
@@ -138,9 +139,9 @@ static void serio_find_driver(struct serio *serio)
138 139
139 error = device_attach(&serio->dev); 140 error = device_attach(&serio->dev);
140 if (error < 0) 141 if (error < 0)
141 printk(KERN_WARNING 142 dev_warn(&serio->dev,
142 "serio: device_attach() failed for %s (%s), error: %d\n", 143 "device_attach() failed for %s (%s), error: %d\n",
143 serio->phys, serio->name, error); 144 serio->phys, serio->name, error);
144} 145}
145 146
146 147
@@ -194,17 +195,14 @@ static int serio_queue_event(void *object, struct module *owner,
194 195
195 event = kmalloc(sizeof(struct serio_event), GFP_ATOMIC); 196 event = kmalloc(sizeof(struct serio_event), GFP_ATOMIC);
196 if (!event) { 197 if (!event) {
197 printk(KERN_ERR 198 pr_err("Not enough memory to queue event %d\n", event_type);
198 "serio: Not enough memory to queue event %d\n",
199 event_type);
200 retval = -ENOMEM; 199 retval = -ENOMEM;
201 goto out; 200 goto out;
202 } 201 }
203 202
204 if (!try_module_get(owner)) { 203 if (!try_module_get(owner)) {
205 printk(KERN_WARNING 204 pr_warning("Can't get module reference, dropping event %d\n",
206 "serio: Can't get module reference, dropping event %d\n", 205 event_type);
207 event_type);
208 kfree(event); 206 kfree(event);
209 retval = -EINVAL; 207 retval = -EINVAL;
210 goto out; 208 goto out;
@@ -230,14 +228,12 @@ static void serio_free_event(struct serio_event *event)
230 228
231static void serio_remove_duplicate_events(struct serio_event *event) 229static void serio_remove_duplicate_events(struct serio_event *event)
232{ 230{
233 struct list_head *node, *next; 231 struct serio_event *e, *next;
234 struct serio_event *e;
235 unsigned long flags; 232 unsigned long flags;
236 233
237 spin_lock_irqsave(&serio_event_lock, flags); 234 spin_lock_irqsave(&serio_event_lock, flags);
238 235
239 list_for_each_safe(node, next, &serio_event_list) { 236 list_for_each_entry_safe(e, next, &serio_event_list, node) {
240 e = list_entry(node, struct serio_event, node);
241 if (event->object == e->object) { 237 if (event->object == e->object) {
242 /* 238 /*
243 * If this event is of different type we should not 239 * If this event is of different type we should not
@@ -247,7 +243,7 @@ static void serio_remove_duplicate_events(struct serio_event *event)
247 if (event->type != e->type) 243 if (event->type != e->type)
248 break; 244 break;
249 245
250 list_del_init(node); 246 list_del_init(&e->node);
251 serio_free_event(e); 247 serio_free_event(e);
252 } 248 }
253 } 249 }
@@ -258,23 +254,18 @@ static void serio_remove_duplicate_events(struct serio_event *event)
258 254
259static struct serio_event *serio_get_event(void) 255static struct serio_event *serio_get_event(void)
260{ 256{
261 struct serio_event *event; 257 struct serio_event *event = NULL;
262 struct list_head *node;
263 unsigned long flags; 258 unsigned long flags;
264 259
265 spin_lock_irqsave(&serio_event_lock, flags); 260 spin_lock_irqsave(&serio_event_lock, flags);
266 261
267 if (list_empty(&serio_event_list)) { 262 if (!list_empty(&serio_event_list)) {
268 spin_unlock_irqrestore(&serio_event_lock, flags); 263 event = list_first_entry(&serio_event_list,
269 return NULL; 264 struct serio_event, node);
265 list_del_init(&event->node);
270 } 266 }
271 267
272 node = serio_event_list.next;
273 event = list_entry(node, struct serio_event, node);
274 list_del_init(node);
275
276 spin_unlock_irqrestore(&serio_event_lock, flags); 268 spin_unlock_irqrestore(&serio_event_lock, flags);
277
278 return event; 269 return event;
279} 270}
280 271
@@ -287,29 +278,27 @@ static void serio_handle_event(void)
287 while ((event = serio_get_event())) { 278 while ((event = serio_get_event())) {
288 279
289 switch (event->type) { 280 switch (event->type) {
290 case SERIO_REGISTER_PORT:
291 serio_add_port(event->object);
292 break;
293 281
294 case SERIO_RECONNECT_PORT: 282 case SERIO_REGISTER_PORT:
295 serio_reconnect_port(event->object); 283 serio_add_port(event->object);
296 break; 284 break;
297 285
298 case SERIO_RESCAN_PORT: 286 case SERIO_RECONNECT_PORT:
299 serio_disconnect_port(event->object); 287 serio_reconnect_port(event->object);
300 serio_find_driver(event->object); 288 break;
301 break;
302 289
303 case SERIO_RECONNECT_CHAIN: 290 case SERIO_RESCAN_PORT:
304 serio_reconnect_chain(event->object); 291 serio_disconnect_port(event->object);
305 break; 292 serio_find_driver(event->object);
293 break;
306 294
307 case SERIO_ATTACH_DRIVER: 295 case SERIO_RECONNECT_CHAIN:
308 serio_attach_driver(event->object); 296 serio_reconnect_chain(event->object);
309 break; 297 break;
310 298
311 default: 299 case SERIO_ATTACH_DRIVER:
312 break; 300 serio_attach_driver(event->object);
301 break;
313 } 302 }
314 303
315 serio_remove_duplicate_events(event); 304 serio_remove_duplicate_events(event);
@@ -325,16 +314,14 @@ static void serio_handle_event(void)
325 */ 314 */
326static void serio_remove_pending_events(void *object) 315static void serio_remove_pending_events(void *object)
327{ 316{
328 struct list_head *node, *next; 317 struct serio_event *event, *next;
329 struct serio_event *event;
330 unsigned long flags; 318 unsigned long flags;
331 319
332 spin_lock_irqsave(&serio_event_lock, flags); 320 spin_lock_irqsave(&serio_event_lock, flags);
333 321
334 list_for_each_safe(node, next, &serio_event_list) { 322 list_for_each_entry_safe(event, next, &serio_event_list, node) {
335 event = list_entry(node, struct serio_event, node);
336 if (event->object == object) { 323 if (event->object == object) {
337 list_del_init(node); 324 list_del_init(&event->node);
338 serio_free_event(event); 325 serio_free_event(event);
339 } 326 }
340 } 327 }
@@ -380,7 +367,6 @@ static int serio_thread(void *nothing)
380 kthread_should_stop() || !list_empty(&serio_event_list)); 367 kthread_should_stop() || !list_empty(&serio_event_list));
381 } while (!kthread_should_stop()); 368 } while (!kthread_should_stop());
382 369
383 printk(KERN_DEBUG "serio: kseriod exiting\n");
384 return 0; 370 return 0;
385} 371}
386 372
@@ -445,6 +431,11 @@ static struct attribute_group serio_id_attr_group = {
445 .attrs = serio_device_id_attrs, 431 .attrs = serio_device_id_attrs,
446}; 432};
447 433
434static const struct attribute_group *serio_device_attr_groups[] = {
435 &serio_id_attr_group,
436 NULL
437};
438
448static ssize_t serio_rebind_driver(struct device *dev, struct device_attribute *attr, const char *buf, size_t count) 439static ssize_t serio_rebind_driver(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
449{ 440{
450 struct serio *serio = to_serio_port(dev); 441 struct serio *serio = to_serio_port(dev);
@@ -532,6 +523,7 @@ static void serio_init_port(struct serio *serio)
532 (long)atomic_inc_return(&serio_no) - 1); 523 (long)atomic_inc_return(&serio_no) - 1);
533 serio->dev.bus = &serio_bus; 524 serio->dev.bus = &serio_bus;
534 serio->dev.release = serio_release_port; 525 serio->dev.release = serio_release_port;
526 serio->dev.groups = serio_device_attr_groups;
535 if (serio->parent) { 527 if (serio->parent) {
536 serio->dev.parent = &serio->parent->dev; 528 serio->dev.parent = &serio->parent->dev;
537 serio->depth = serio->parent->depth + 1; 529 serio->depth = serio->parent->depth + 1;
@@ -555,21 +547,15 @@ static void serio_add_port(struct serio *serio)
555 } 547 }
556 548
557 list_add_tail(&serio->node, &serio_list); 549 list_add_tail(&serio->node, &serio_list);
550
558 if (serio->start) 551 if (serio->start)
559 serio->start(serio); 552 serio->start(serio);
553
560 error = device_add(&serio->dev); 554 error = device_add(&serio->dev);
561 if (error) 555 if (error)
562 printk(KERN_ERR 556 dev_err(&serio->dev,
563 "serio: device_add() failed for %s (%s), error: %d\n", 557 "device_add() failed for %s (%s), error: %d\n",
564 serio->phys, serio->name, error); 558 serio->phys, serio->name, error);
565 else {
566 serio->registered = true;
567 error = sysfs_create_group(&serio->dev.kobj, &serio_id_attr_group);
568 if (error)
569 printk(KERN_ERR
570 "serio: sysfs_create_group() failed for %s (%s), error: %d\n",
571 serio->phys, serio->name, error);
572 }
573} 559}
574 560
575/* 561/*
@@ -596,11 +582,8 @@ static void serio_destroy_port(struct serio *serio)
596 serio->parent = NULL; 582 serio->parent = NULL;
597 } 583 }
598 584
599 if (serio->registered) { 585 if (device_is_registered(&serio->dev))
600 sysfs_remove_group(&serio->dev.kobj, &serio_id_attr_group);
601 device_del(&serio->dev); 586 device_del(&serio->dev);
602 serio->registered = false;
603 }
604 587
605 list_del_init(&serio->node); 588 list_del_init(&serio->node);
606 serio_remove_pending_events(serio); 589 serio_remove_pending_events(serio);
@@ -798,9 +781,8 @@ static void serio_attach_driver(struct serio_driver *drv)
798 781
799 error = driver_attach(&drv->driver); 782 error = driver_attach(&drv->driver);
800 if (error) 783 if (error)
801 printk(KERN_WARNING 784 pr_warning("driver_attach() failed for %s with error %d\n",
802 "serio: driver_attach() failed for %s with error %d\n", 785 drv->driver.name, error);
803 drv->driver.name, error);
804} 786}
805 787
806int __serio_register_driver(struct serio_driver *drv, struct module *owner, const char *mod_name) 788int __serio_register_driver(struct serio_driver *drv, struct module *owner, const char *mod_name)
@@ -820,8 +802,7 @@ int __serio_register_driver(struct serio_driver *drv, struct module *owner, cons
820 802
821 error = driver_register(&drv->driver); 803 error = driver_register(&drv->driver);
822 if (error) { 804 if (error) {
823 printk(KERN_ERR 805 pr_err("driver_register() failed for %s, error: %d\n",
824 "serio: driver_register() failed for %s, error: %d\n",
825 drv->driver.name, error); 806 drv->driver.name, error);
826 return error; 807 return error;
827 } 808 }
@@ -987,7 +968,7 @@ irqreturn_t serio_interrupt(struct serio *serio,
987 968
988 if (likely(serio->drv)) { 969 if (likely(serio->drv)) {
989 ret = serio->drv->interrupt(serio, data, dfl); 970 ret = serio->drv->interrupt(serio, data, dfl);
990 } else if (!dfl && serio->registered) { 971 } else if (!dfl && device_is_registered(&serio->dev)) {
991 serio_rescan(serio); 972 serio_rescan(serio);
992 ret = IRQ_HANDLED; 973 ret = IRQ_HANDLED;
993 } 974 }
@@ -1018,7 +999,7 @@ static int __init serio_init(void)
1018 999
1019 error = bus_register(&serio_bus); 1000 error = bus_register(&serio_bus);
1020 if (error) { 1001 if (error) {
1021 printk(KERN_ERR "serio: failed to register serio bus, error: %d\n", error); 1002 pr_err("Failed to register serio bus, error: %d\n", error);
1022 return error; 1003 return error;
1023 } 1004 }
1024 1005
@@ -1026,7 +1007,7 @@ static int __init serio_init(void)
1026 if (IS_ERR(serio_task)) { 1007 if (IS_ERR(serio_task)) {
1027 bus_unregister(&serio_bus); 1008 bus_unregister(&serio_bus);
1028 error = PTR_ERR(serio_task); 1009 error = PTR_ERR(serio_task);
1029 printk(KERN_ERR "serio: Failed to start kseriod, error: %d\n", error); 1010 pr_err("Failed to start kseriod, error: %d\n", error);
1030 return error; 1011 return error;
1031 } 1012 }
1032 1013
diff --git a/drivers/input/serio/xilinx_ps2.c b/drivers/input/serio/xilinx_ps2.c
index ebb22f88c842..8298e1f68234 100644
--- a/drivers/input/serio/xilinx_ps2.c
+++ b/drivers/input/serio/xilinx_ps2.c
@@ -270,7 +270,7 @@ static int __devinit xps2_of_probe(struct of_device *ofdev,
270 drvdata->irq = r_irq.start; 270 drvdata->irq = r_irq.start;
271 271
272 phys_addr = r_mem.start; 272 phys_addr = r_mem.start;
273 remap_size = r_mem.end - r_mem.start + 1; 273 remap_size = resource_size(&r_mem);
274 if (!request_mem_region(phys_addr, remap_size, DRIVER_NAME)) { 274 if (!request_mem_region(phys_addr, remap_size, DRIVER_NAME)) {
275 dev_err(dev, "Couldn't lock memory region at 0x%08llX\n", 275 dev_err(dev, "Couldn't lock memory region at 0x%08llX\n",
276 (unsigned long long)phys_addr); 276 (unsigned long long)phys_addr);
@@ -344,7 +344,7 @@ static int __devexit xps2_of_remove(struct of_device *of_dev)
344 if (of_address_to_resource(of_dev->node, 0, &r_mem)) 344 if (of_address_to_resource(of_dev->node, 0, &r_mem))
345 dev_err(dev, "invalid address\n"); 345 dev_err(dev, "invalid address\n");
346 else 346 else
347 release_mem_region(r_mem.start, r_mem.end - r_mem.start + 1); 347 release_mem_region(r_mem.start, resource_size(&r_mem));
348 348
349 kfree(drvdata); 349 kfree(drvdata);
350 350
@@ -354,7 +354,7 @@ static int __devexit xps2_of_remove(struct of_device *of_dev)
354} 354}
355 355
356/* Match table for of_platform binding */ 356/* Match table for of_platform binding */
357static struct of_device_id xps2_of_match[] __devinitdata = { 357static const struct of_device_id xps2_of_match[] __devinitconst = {
358 { .compatible = "xlnx,xps-ps2-1.00.a", }, 358 { .compatible = "xlnx,xps-ps2-1.00.a", },
359 { /* end of list */ }, 359 { /* end of list */ },
360}; 360};
diff --git a/drivers/input/tablet/gtco.c b/drivers/input/tablet/gtco.c
index 3d32d3f4e486..866a9ee1af1a 100644
--- a/drivers/input/tablet/gtco.c
+++ b/drivers/input/tablet/gtco.c
@@ -92,7 +92,7 @@ Scott Hill shill@gtcocalcomp.com
92/* DATA STRUCTURES */ 92/* DATA STRUCTURES */
93 93
94/* Device table */ 94/* Device table */
95static struct usb_device_id gtco_usbid_table [] = { 95static const struct usb_device_id gtco_usbid_table[] = {
96 { USB_DEVICE(VENDOR_ID_GTCO, PID_400) }, 96 { USB_DEVICE(VENDOR_ID_GTCO, PID_400) },
97 { USB_DEVICE(VENDOR_ID_GTCO, PID_401) }, 97 { USB_DEVICE(VENDOR_ID_GTCO, PID_401) },
98 { USB_DEVICE(VENDOR_ID_GTCO, PID_1000) }, 98 { USB_DEVICE(VENDOR_ID_GTCO, PID_1000) },
diff --git a/drivers/input/tablet/wacom.h b/drivers/input/tablet/wacom.h
index 16310f368dab..8fef1b689c69 100644
--- a/drivers/input/tablet/wacom.h
+++ b/drivers/input/tablet/wacom.h
@@ -85,6 +85,7 @@
85#include <linux/kernel.h> 85#include <linux/kernel.h>
86#include <linux/slab.h> 86#include <linux/slab.h>
87#include <linux/module.h> 87#include <linux/module.h>
88#include <linux/mod_devicetable.h>
88#include <linux/init.h> 89#include <linux/init.h>
89#include <linux/usb/input.h> 90#include <linux/usb/input.h>
90#include <asm/unaligned.h> 91#include <asm/unaligned.h>
@@ -120,6 +121,8 @@ struct wacom_combo {
120 struct urb *urb; 121 struct urb *urb;
121}; 122};
122 123
124extern const struct usb_device_id wacom_ids[];
125
123extern int wacom_wac_irq(struct wacom_wac * wacom_wac, void * wcombo); 126extern int wacom_wac_irq(struct wacom_wac * wacom_wac, void * wcombo);
124extern void wacom_report_abs(void *wcombo, unsigned int abs_type, int abs_data); 127extern void wacom_report_abs(void *wcombo, unsigned int abs_type, int abs_data);
125extern void wacom_report_rel(void *wcombo, unsigned int rel_type, int rel_data); 128extern void wacom_report_rel(void *wcombo, unsigned int rel_type, int rel_data);
@@ -142,7 +145,5 @@ extern void input_dev_mo(struct input_dev *input_dev, struct wacom_wac *wacom_wa
142extern void input_dev_bee(struct input_dev *input_dev, struct wacom_wac *wacom_wac); 145extern void input_dev_bee(struct input_dev *input_dev, struct wacom_wac *wacom_wac);
143extern __u16 wacom_le16_to_cpu(unsigned char *data); 146extern __u16 wacom_le16_to_cpu(unsigned char *data);
144extern __u16 wacom_be16_to_cpu(unsigned char *data); 147extern __u16 wacom_be16_to_cpu(unsigned char *data);
145extern struct wacom_features *get_wacom_feature(const struct usb_device_id *id);
146extern const struct usb_device_id *get_device_table(void);
147 148
148#endif 149#endif
diff --git a/drivers/input/tablet/wacom_sys.c b/drivers/input/tablet/wacom_sys.c
index 072f33b3b2b0..a1770e6feeec 100644
--- a/drivers/input/tablet/wacom_sys.c
+++ b/drivers/input/tablet/wacom_sys.c
@@ -211,7 +211,8 @@ void input_dev_g(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
211 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_RUBBER) | 211 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_RUBBER) |
212 BIT_MASK(BTN_TOOL_PEN) | BIT_MASK(BTN_STYLUS) | 212 BIT_MASK(BTN_TOOL_PEN) | BIT_MASK(BTN_STYLUS) |
213 BIT_MASK(BTN_TOOL_MOUSE) | BIT_MASK(BTN_STYLUS2); 213 BIT_MASK(BTN_TOOL_MOUSE) | BIT_MASK(BTN_STYLUS2);
214 input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom_wac->features->distance_max, 0, 0); 214 input_set_abs_params(input_dev, ABS_DISTANCE,
215 0, wacom_wac->features.distance_max, 0, 0);
215} 216}
216 217
217void input_dev_i3s(struct input_dev *input_dev, struct wacom_wac *wacom_wac) 218void input_dev_i3s(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
@@ -261,7 +262,8 @@ void input_dev_i(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
261 BIT_MASK(BTN_TOOL_MOUSE) | BIT_MASK(BTN_TOOL_BRUSH) | 262 BIT_MASK(BTN_TOOL_MOUSE) | BIT_MASK(BTN_TOOL_BRUSH) |
262 BIT_MASK(BTN_TOOL_PENCIL) | BIT_MASK(BTN_TOOL_AIRBRUSH) | 263 BIT_MASK(BTN_TOOL_PENCIL) | BIT_MASK(BTN_TOOL_AIRBRUSH) |
263 BIT_MASK(BTN_TOOL_LENS) | BIT_MASK(BTN_STYLUS2); 264 BIT_MASK(BTN_TOOL_LENS) | BIT_MASK(BTN_STYLUS2);
264 input_set_abs_params(input_dev, ABS_DISTANCE, 0, wacom_wac->features->distance_max, 0, 0); 265 input_set_abs_params(input_dev, ABS_DISTANCE,
266 0, wacom_wac->features.distance_max, 0, 0);
265 input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0); 267 input_set_abs_params(input_dev, ABS_WHEEL, 0, 1023, 0, 0);
266 input_set_abs_params(input_dev, ABS_TILT_X, 0, 127, 0, 0); 268 input_set_abs_params(input_dev, ABS_TILT_X, 0, 127, 0, 0);
267 input_set_abs_params(input_dev, ABS_TILT_Y, 0, 127, 0, 0); 269 input_set_abs_params(input_dev, ABS_TILT_Y, 0, 127, 0, 0);
@@ -282,17 +284,19 @@ void input_dev_pt(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
282 284
283void input_dev_tpc(struct input_dev *input_dev, struct wacom_wac *wacom_wac) 285void input_dev_tpc(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
284{ 286{
285 if (wacom_wac->features->device_type == BTN_TOOL_DOUBLETAP || 287 struct wacom_features *features = &wacom_wac->features;
286 wacom_wac->features->device_type == BTN_TOOL_TRIPLETAP) { 288
287 input_set_abs_params(input_dev, ABS_RX, 0, wacom_wac->features->x_phy, 0, 0); 289 if (features->device_type == BTN_TOOL_DOUBLETAP ||
288 input_set_abs_params(input_dev, ABS_RY, 0, wacom_wac->features->y_phy, 0, 0); 290 features->device_type == BTN_TOOL_TRIPLETAP) {
289 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_DOUBLETAP); 291 input_set_abs_params(input_dev, ABS_RX, 0, features->x_phy, 0, 0);
292 input_set_abs_params(input_dev, ABS_RY, 0, features->y_phy, 0, 0);
293 __set_bit(BTN_TOOL_DOUBLETAP, input_dev->keybit);
290 } 294 }
291} 295}
292 296
293void input_dev_tpc2fg(struct input_dev *input_dev, struct wacom_wac *wacom_wac) 297void input_dev_tpc2fg(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
294{ 298{
295 if (wacom_wac->features->device_type == BTN_TOOL_TRIPLETAP) { 299 if (wacom_wac->features.device_type == BTN_TOOL_TRIPLETAP) {
296 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_TRIPLETAP); 300 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOOL_TRIPLETAP);
297 input_dev->evbit[0] |= BIT_MASK(EV_MSC); 301 input_dev->evbit[0] |= BIT_MASK(EV_MSC);
298 input_dev->mscbit[0] |= BIT_MASK(MSC_SERIAL); 302 input_dev->mscbit[0] |= BIT_MASK(MSC_SERIAL);
@@ -532,21 +536,38 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
532 struct wacom_wac *wacom_wac; 536 struct wacom_wac *wacom_wac;
533 struct wacom_features *features; 537 struct wacom_features *features;
534 struct input_dev *input_dev; 538 struct input_dev *input_dev;
535 int error = -ENOMEM; 539 int error;
540
541 if (!id->driver_info)
542 return -EINVAL;
536 543
537 wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL); 544 wacom = kzalloc(sizeof(struct wacom), GFP_KERNEL);
538 wacom_wac = kzalloc(sizeof(struct wacom_wac), GFP_KERNEL); 545 wacom_wac = kzalloc(sizeof(struct wacom_wac), GFP_KERNEL);
539 input_dev = input_allocate_device(); 546 input_dev = input_allocate_device();
540 if (!wacom || !input_dev || !wacom_wac) 547 if (!wacom || !input_dev || !wacom_wac) {
548 error = -ENOMEM;
541 goto fail1; 549 goto fail1;
550 }
542 551
543 wacom_wac->data = usb_buffer_alloc(dev, WACOM_PKGLEN_MAX, GFP_KERNEL, &wacom->data_dma); 552 wacom_wac->features = *((struct wacom_features *)id->driver_info);
544 if (!wacom_wac->data) 553 features = &wacom_wac->features;
554 if (features->pktlen > WACOM_PKGLEN_MAX) {
555 error = -EINVAL;
545 goto fail1; 556 goto fail1;
557 }
558
559 wacom_wac->data = usb_buffer_alloc(dev, WACOM_PKGLEN_MAX,
560 GFP_KERNEL, &wacom->data_dma);
561 if (!wacom_wac->data) {
562 error = -ENOMEM;
563 goto fail1;
564 }
546 565
547 wacom->irq = usb_alloc_urb(0, GFP_KERNEL); 566 wacom->irq = usb_alloc_urb(0, GFP_KERNEL);
548 if (!wacom->irq) 567 if (!wacom->irq) {
568 error = -ENOMEM;
549 goto fail2; 569 goto fail2;
570 }
550 571
551 wacom->usbdev = dev; 572 wacom->usbdev = dev;
552 wacom->dev = input_dev; 573 wacom->dev = input_dev;
@@ -555,11 +576,6 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
555 usb_make_path(dev, wacom->phys, sizeof(wacom->phys)); 576 usb_make_path(dev, wacom->phys, sizeof(wacom->phys));
556 strlcat(wacom->phys, "/input0", sizeof(wacom->phys)); 577 strlcat(wacom->phys, "/input0", sizeof(wacom->phys));
557 578
558 wacom_wac->features = features = get_wacom_feature(id);
559 BUG_ON(features->pktlen > WACOM_PKGLEN_MAX);
560
561 input_dev->name = wacom_wac->features->name;
562 wacom->wacom_wac = wacom_wac;
563 usb_to_input_id(dev, &input_dev->id); 579 usb_to_input_id(dev, &input_dev->id);
564 580
565 input_dev->dev.parent = &intf->dev; 581 input_dev->dev.parent = &intf->dev;
@@ -576,6 +592,19 @@ static int wacom_probe(struct usb_interface *intf, const struct usb_device_id *i
576 if (error) 592 if (error)
577 goto fail2; 593 goto fail2;
578 594
595 strlcpy(wacom_wac->name, features->name, sizeof(wacom_wac->name));
596
597 if (features->type == TABLETPC || features->type == TABLETPC2FG) {
598 /* Append the device type to the name */
599 strlcat(wacom_wac->name,
600 features->device_type == BTN_TOOL_PEN ?
601 " Pen" : " Finger",
602 sizeof(wacom_wac->name));
603 }
604
605 input_dev->name = wacom_wac->name;
606 wacom->wacom_wac = wacom_wac;
607
579 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); 608 input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
580 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOUCH); 609 input_dev->keybit[BIT_WORD(BTN_DIGI)] |= BIT_MASK(BTN_TOUCH);
581 610
@@ -640,7 +669,7 @@ static int wacom_suspend(struct usb_interface *intf, pm_message_t message)
640static int wacom_resume(struct usb_interface *intf) 669static int wacom_resume(struct usb_interface *intf)
641{ 670{
642 struct wacom *wacom = usb_get_intfdata(intf); 671 struct wacom *wacom = usb_get_intfdata(intf);
643 struct wacom_features *features = wacom->wacom_wac->features; 672 struct wacom_features *features = &wacom->wacom_wac->features;
644 int rv; 673 int rv;
645 674
646 mutex_lock(&wacom->lock); 675 mutex_lock(&wacom->lock);
@@ -663,6 +692,7 @@ static int wacom_reset_resume(struct usb_interface *intf)
663 692
664static struct usb_driver wacom_driver = { 693static struct usb_driver wacom_driver = {
665 .name = "wacom", 694 .name = "wacom",
695 .id_table = wacom_ids,
666 .probe = wacom_probe, 696 .probe = wacom_probe,
667 .disconnect = wacom_disconnect, 697 .disconnect = wacom_disconnect,
668 .suspend = wacom_suspend, 698 .suspend = wacom_suspend,
@@ -674,7 +704,7 @@ static struct usb_driver wacom_driver = {
674static int __init wacom_init(void) 704static int __init wacom_init(void)
675{ 705{
676 int result; 706 int result;
677 wacom_driver.id_table = get_device_table(); 707
678 result = usb_register(&wacom_driver); 708 result = usb_register(&wacom_driver);
679 if (result == 0) 709 if (result == 0)
680 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":" 710 printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_VERSION ":"
diff --git a/drivers/input/tablet/wacom_wac.c b/drivers/input/tablet/wacom_wac.c
index 1056f149fe31..3d81443e683a 100644
--- a/drivers/input/tablet/wacom_wac.c
+++ b/drivers/input/tablet/wacom_wac.c
@@ -55,6 +55,7 @@ static int wacom_penpartner_irq(struct wacom_wac *wacom, void *wcombo)
55 55
56static int wacom_pl_irq(struct wacom_wac *wacom, void *wcombo) 56static int wacom_pl_irq(struct wacom_wac *wacom, void *wcombo)
57{ 57{
58 struct wacom_features *features = &wacom->features;
58 unsigned char *data = wacom->data; 59 unsigned char *data = wacom->data;
59 int prox, pressure; 60 int prox, pressure;
60 61
@@ -68,9 +69,9 @@ static int wacom_pl_irq(struct wacom_wac *wacom, void *wcombo)
68 if (prox) { 69 if (prox) {
69 wacom->id[0] = ERASER_DEVICE_ID; 70 wacom->id[0] = ERASER_DEVICE_ID;
70 pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1)); 71 pressure = (signed char)((data[7] << 1) | ((data[4] >> 2) & 1));
71 if (wacom->features->pressure_max > 255) 72 if (features->pressure_max > 255)
72 pressure = (pressure << 1) | ((data[4] >> 6) & 1); 73 pressure = (pressure << 1) | ((data[4] >> 6) & 1);
73 pressure += (wacom->features->pressure_max + 1) / 2; 74 pressure += (features->pressure_max + 1) / 2;
74 75
75 /* 76 /*
76 * if going from out of proximity into proximity select between the eraser 77 * if going from out of proximity into proximity select between the eraser
@@ -152,6 +153,7 @@ static int wacom_ptu_irq(struct wacom_wac *wacom, void *wcombo)
152 153
153static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo) 154static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
154{ 155{
156 struct wacom_features *features = &wacom->features;
155 unsigned char *data = wacom->data; 157 unsigned char *data = wacom->data;
156 int x, y, rw; 158 int x, y, rw;
157 static int penData = 0; 159 static int penData = 0;
@@ -179,8 +181,7 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
179 181
180 case 2: /* Mouse with wheel */ 182 case 2: /* Mouse with wheel */
181 wacom_report_key(wcombo, BTN_MIDDLE, data[1] & 0x04); 183 wacom_report_key(wcombo, BTN_MIDDLE, data[1] & 0x04);
182 if (wacom->features->type == WACOM_G4 || 184 if (features->type == WACOM_G4 || features->type == WACOM_MO) {
183 wacom->features->type == WACOM_MO) {
184 rw = data[7] & 0x04 ? (data[7] & 0x03)-4 : (data[7] & 0x03); 185 rw = data[7] & 0x04 ? (data[7] & 0x03)-4 : (data[7] & 0x03);
185 wacom_report_rel(wcombo, REL_WHEEL, -rw); 186 wacom_report_rel(wcombo, REL_WHEEL, -rw);
186 } else 187 } else
@@ -192,8 +193,7 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
192 wacom->id[0] = CURSOR_DEVICE_ID; 193 wacom->id[0] = CURSOR_DEVICE_ID;
193 wacom_report_key(wcombo, BTN_LEFT, data[1] & 0x01); 194 wacom_report_key(wcombo, BTN_LEFT, data[1] & 0x01);
194 wacom_report_key(wcombo, BTN_RIGHT, data[1] & 0x02); 195 wacom_report_key(wcombo, BTN_RIGHT, data[1] & 0x02);
195 if (wacom->features->type == WACOM_G4 || 196 if (features->type == WACOM_G4 || features->type == WACOM_MO)
196 wacom->features->type == WACOM_MO)
197 wacom_report_abs(wcombo, ABS_DISTANCE, data[6] & 0x3f); 197 wacom_report_abs(wcombo, ABS_DISTANCE, data[6] & 0x3f);
198 else 198 else
199 wacom_report_abs(wcombo, ABS_DISTANCE, data[7] & 0x3f); 199 wacom_report_abs(wcombo, ABS_DISTANCE, data[7] & 0x3f);
@@ -230,7 +230,7 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
230 } 230 }
231 231
232 /* send pad data */ 232 /* send pad data */
233 switch (wacom->features->type) { 233 switch (features->type) {
234 case WACOM_G4: 234 case WACOM_G4:
235 if (data[7] & 0xf8) { 235 if (data[7] & 0xf8) {
236 if (penData) { 236 if (penData) {
@@ -300,11 +300,12 @@ static int wacom_graphire_irq(struct wacom_wac *wacom, void *wcombo)
300 300
301static int wacom_intuos_inout(struct wacom_wac *wacom, void *wcombo) 301static int wacom_intuos_inout(struct wacom_wac *wacom, void *wcombo)
302{ 302{
303 struct wacom_features *features = &wacom->features;
303 unsigned char *data = wacom->data; 304 unsigned char *data = wacom->data;
304 int idx = 0; 305 int idx = 0;
305 306
306 /* tool number */ 307 /* tool number */
307 if (wacom->features->type == INTUOS) 308 if (features->type == INTUOS)
308 idx = data[1] & 0x01; 309 idx = data[1] & 0x01;
309 310
310 /* Enter report */ 311 /* Enter report */
@@ -402,7 +403,7 @@ static int wacom_intuos_inout(struct wacom_wac *wacom, void *wcombo)
402 wacom_report_key(wcombo, BTN_STYLUS2, 0); 403 wacom_report_key(wcombo, BTN_STYLUS2, 0);
403 wacom_report_key(wcombo, BTN_TOUCH, 0); 404 wacom_report_key(wcombo, BTN_TOUCH, 0);
404 wacom_report_abs(wcombo, ABS_WHEEL, 0); 405 wacom_report_abs(wcombo, ABS_WHEEL, 0);
405 if (wacom->features->type >= INTUOS3S) 406 if (features->type >= INTUOS3S)
406 wacom_report_abs(wcombo, ABS_Z, 0); 407 wacom_report_abs(wcombo, ABS_Z, 0);
407 } 408 }
408 wacom_report_key(wcombo, wacom->tool[idx], 0); 409 wacom_report_key(wcombo, wacom->tool[idx], 0);
@@ -416,13 +417,14 @@ static int wacom_intuos_inout(struct wacom_wac *wacom, void *wcombo)
416 417
417static void wacom_intuos_general(struct wacom_wac *wacom, void *wcombo) 418static void wacom_intuos_general(struct wacom_wac *wacom, void *wcombo)
418{ 419{
420 struct wacom_features *features = &wacom->features;
419 unsigned char *data = wacom->data; 421 unsigned char *data = wacom->data;
420 unsigned int t; 422 unsigned int t;
421 423
422 /* general pen packet */ 424 /* general pen packet */
423 if ((data[1] & 0xb8) == 0xa0) { 425 if ((data[1] & 0xb8) == 0xa0) {
424 t = (data[6] << 2) | ((data[7] >> 6) & 3); 426 t = (data[6] << 2) | ((data[7] >> 6) & 3);
425 if (wacom->features->type >= INTUOS4S && wacom->features->type <= INTUOS4L) 427 if (features->type >= INTUOS4S && features->type <= INTUOS4L)
426 t = (t << 1) | (data[1] & 1); 428 t = (t << 1) | (data[1] & 1);
427 wacom_report_abs(wcombo, ABS_PRESSURE, t); 429 wacom_report_abs(wcombo, ABS_PRESSURE, t);
428 wacom_report_abs(wcombo, ABS_TILT_X, 430 wacom_report_abs(wcombo, ABS_TILT_X,
@@ -446,6 +448,7 @@ static void wacom_intuos_general(struct wacom_wac *wacom, void *wcombo)
446 448
447static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo) 449static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
448{ 450{
451 struct wacom_features *features = &wacom->features;
449 unsigned char *data = wacom->data; 452 unsigned char *data = wacom->data;
450 unsigned int t; 453 unsigned int t;
451 int idx = 0, result; 454 int idx = 0, result;
@@ -457,7 +460,7 @@ static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
457 } 460 }
458 461
459 /* tool number */ 462 /* tool number */
460 if (wacom->features->type == INTUOS) 463 if (features->type == INTUOS)
461 idx = data[1] & 0x01; 464 idx = data[1] & 0x01;
462 465
463 /* pad packets. Works as a second tool and is always in prox */ 466 /* pad packets. Works as a second tool and is always in prox */
@@ -466,7 +469,7 @@ static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
466 if (wacom->tool[1] != BTN_TOOL_FINGER) 469 if (wacom->tool[1] != BTN_TOOL_FINGER)
467 wacom->tool[1] = BTN_TOOL_FINGER; 470 wacom->tool[1] = BTN_TOOL_FINGER;
468 471
469 if (wacom->features->type >= INTUOS4S && wacom->features->type <= INTUOS4L) { 472 if (features->type >= INTUOS4S && features->type <= INTUOS4L) {
470 wacom_report_key(wcombo, BTN_0, (data[2] & 0x01)); 473 wacom_report_key(wcombo, BTN_0, (data[2] & 0x01));
471 wacom_report_key(wcombo, BTN_1, (data[3] & 0x01)); 474 wacom_report_key(wcombo, BTN_1, (data[3] & 0x01));
472 wacom_report_key(wcombo, BTN_2, (data[3] & 0x02)); 475 wacom_report_key(wcombo, BTN_2, (data[3] & 0x02));
@@ -480,7 +483,7 @@ static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
480 /* Out of proximity, clear wheel value. */ 483 /* Out of proximity, clear wheel value. */
481 wacom_report_abs(wcombo, ABS_WHEEL, 0); 484 wacom_report_abs(wcombo, ABS_WHEEL, 0);
482 } 485 }
483 if (wacom->features->type != INTUOS4S) { 486 if (features->type != INTUOS4S) {
484 wacom_report_key(wcombo, BTN_7, (data[3] & 0x40)); 487 wacom_report_key(wcombo, BTN_7, (data[3] & 0x40));
485 wacom_report_key(wcombo, BTN_8, (data[3] & 0x80)); 488 wacom_report_key(wcombo, BTN_8, (data[3] & 0x80));
486 } 489 }
@@ -528,18 +531,20 @@ static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
528 return 0; 531 return 0;
529 532
530 /* Only large Intuos support Lense Cursor */ 533 /* Only large Intuos support Lense Cursor */
531 if ((wacom->tool[idx] == BTN_TOOL_LENS) 534 if (wacom->tool[idx] == BTN_TOOL_LENS &&
532 && ((wacom->features->type == INTUOS3) 535 (features->type == INTUOS3 ||
533 || (wacom->features->type == INTUOS3S) 536 features->type == INTUOS3S ||
534 || (wacom->features->type == INTUOS4) 537 features->type == INTUOS4 ||
535 || (wacom->features->type == INTUOS4S))) 538 features->type == INTUOS4S)) {
539
536 return 0; 540 return 0;
541 }
537 542
538 /* Cintiq doesn't send data when RDY bit isn't set */ 543 /* Cintiq doesn't send data when RDY bit isn't set */
539 if ((wacom->features->type == CINTIQ) && !(data[1] & 0x40)) 544 if (features->type == CINTIQ && !(data[1] & 0x40))
540 return 0; 545 return 0;
541 546
542 if (wacom->features->type >= INTUOS3S) { 547 if (features->type >= INTUOS3S) {
543 wacom_report_abs(wcombo, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1)); 548 wacom_report_abs(wcombo, ABS_X, (data[2] << 9) | (data[3] << 1) | ((data[9] >> 1) & 1));
544 wacom_report_abs(wcombo, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1)); 549 wacom_report_abs(wcombo, ABS_Y, (data[4] << 9) | (data[5] << 1) | (data[9] & 1));
545 wacom_report_abs(wcombo, ABS_DISTANCE, ((data[9] >> 2) & 0x3f)); 550 wacom_report_abs(wcombo, ABS_DISTANCE, ((data[9] >> 2) & 0x3f));
@@ -557,7 +562,7 @@ static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
557 562
558 if (data[1] & 0x02) { 563 if (data[1] & 0x02) {
559 /* Rotation packet */ 564 /* Rotation packet */
560 if (wacom->features->type >= INTUOS3S) { 565 if (features->type >= INTUOS3S) {
561 /* I3 marker pen rotation */ 566 /* I3 marker pen rotation */
562 t = (data[6] << 3) | ((data[7] >> 5) & 7); 567 t = (data[6] << 3) | ((data[7] >> 5) & 7);
563 t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) : 568 t = (data[7] & 0x20) ? ((t > 900) ? ((t-1) / 2 - 1350) :
@@ -570,7 +575,7 @@ static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
570 ((t - 1) / 2) : -t / 2); 575 ((t - 1) / 2) : -t / 2);
571 } 576 }
572 577
573 } else if (!(data[1] & 0x10) && wacom->features->type < INTUOS3S) { 578 } else if (!(data[1] & 0x10) && features->type < INTUOS3S) {
574 /* 4D mouse packet */ 579 /* 4D mouse packet */
575 wacom_report_key(wcombo, BTN_LEFT, data[8] & 0x01); 580 wacom_report_key(wcombo, BTN_LEFT, data[8] & 0x01);
576 wacom_report_key(wcombo, BTN_MIDDLE, data[8] & 0x02); 581 wacom_report_key(wcombo, BTN_MIDDLE, data[8] & 0x02);
@@ -583,7 +588,7 @@ static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
583 588
584 } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) { 589 } else if (wacom->tool[idx] == BTN_TOOL_MOUSE) {
585 /* I4 mouse */ 590 /* I4 mouse */
586 if (wacom->features->type >= INTUOS4S && wacom->features->type <= INTUOS4L) { 591 if (features->type >= INTUOS4S && features->type <= INTUOS4L) {
587 wacom_report_key(wcombo, BTN_LEFT, data[6] & 0x01); 592 wacom_report_key(wcombo, BTN_LEFT, data[6] & 0x01);
588 wacom_report_key(wcombo, BTN_MIDDLE, data[6] & 0x02); 593 wacom_report_key(wcombo, BTN_MIDDLE, data[6] & 0x02);
589 wacom_report_key(wcombo, BTN_RIGHT, data[6] & 0x04); 594 wacom_report_key(wcombo, BTN_RIGHT, data[6] & 0x04);
@@ -604,13 +609,13 @@ static int wacom_intuos_irq(struct wacom_wac *wacom, void *wcombo)
604 - ((data[8] & 0x02) >> 1)); 609 - ((data[8] & 0x02) >> 1));
605 610
606 /* I3 2D mouse side buttons */ 611 /* I3 2D mouse side buttons */
607 if (wacom->features->type >= INTUOS3S && wacom->features->type <= INTUOS3L) { 612 if (features->type >= INTUOS3S && features->type <= INTUOS3L) {
608 wacom_report_key(wcombo, BTN_SIDE, data[8] & 0x40); 613 wacom_report_key(wcombo, BTN_SIDE, data[8] & 0x40);
609 wacom_report_key(wcombo, BTN_EXTRA, data[8] & 0x20); 614 wacom_report_key(wcombo, BTN_EXTRA, data[8] & 0x20);
610 } 615 }
611 } 616 }
612 } else if ((wacom->features->type < INTUOS3S || wacom->features->type == INTUOS3L || 617 } else if ((features->type < INTUOS3S || features->type == INTUOS3L ||
613 wacom->features->type == INTUOS4L) && 618 features->type == INTUOS4L) &&
614 wacom->tool[idx] == BTN_TOOL_LENS) { 619 wacom->tool[idx] == BTN_TOOL_LENS) {
615 /* Lens cursor packets */ 620 /* Lens cursor packets */
616 wacom_report_key(wcombo, BTN_LEFT, data[8] & 0x01); 621 wacom_report_key(wcombo, BTN_LEFT, data[8] & 0x01);
@@ -718,6 +723,7 @@ static void wacom_tpc_touch_in(struct wacom_wac *wacom, void *wcombo)
718 723
719static int wacom_tpc_irq(struct wacom_wac *wacom, void *wcombo) 724static int wacom_tpc_irq(struct wacom_wac *wacom, void *wcombo)
720{ 725{
726 struct wacom_features *features = &wacom->features;
721 char *data = wacom->data; 727 char *data = wacom->data;
722 int prox = 0, pressure, idx = -1; 728 int prox = 0, pressure, idx = -1;
723 static int stylusInProx, touchInProx = 1, touchOut; 729 static int stylusInProx, touchInProx = 1, touchOut;
@@ -791,7 +797,7 @@ static int wacom_tpc_irq(struct wacom_wac *wacom, void *wcombo)
791 wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[4])); 797 wacom_report_abs(wcombo, ABS_Y, wacom_le16_to_cpu(&data[4]));
792 pressure = ((data[7] & 0x01) << 8) | data[6]; 798 pressure = ((data[7] & 0x01) << 8) | data[6];
793 if (pressure < 0) 799 if (pressure < 0)
794 pressure = wacom->features->pressure_max + pressure + 1; 800 pressure = features->pressure_max + pressure + 1;
795 wacom_report_abs(wcombo, ABS_PRESSURE, pressure); 801 wacom_report_abs(wcombo, ABS_PRESSURE, pressure);
796 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x05); 802 wacom_report_key(wcombo, BTN_TOUCH, data[1] & 0x05);
797 } else { 803 } else {
@@ -815,7 +821,7 @@ static int wacom_tpc_irq(struct wacom_wac *wacom, void *wcombo)
815 821
816int wacom_wac_irq(struct wacom_wac *wacom_wac, void *wcombo) 822int wacom_wac_irq(struct wacom_wac *wacom_wac, void *wcombo)
817{ 823{
818 switch (wacom_wac->features->type) { 824 switch (wacom_wac->features.type) {
819 case PENPARTNER: 825 case PENPARTNER:
820 return wacom_penpartner_irq(wacom_wac, wcombo); 826 return wacom_penpartner_irq(wacom_wac, wcombo);
821 827
@@ -853,7 +859,7 @@ int wacom_wac_irq(struct wacom_wac *wacom_wac, void *wcombo)
853 859
854void wacom_init_input_dev(struct input_dev *input_dev, struct wacom_wac *wacom_wac) 860void wacom_init_input_dev(struct input_dev *input_dev, struct wacom_wac *wacom_wac)
855{ 861{
856 switch (wacom_wac->features->type) { 862 switch (wacom_wac->features.type) {
857 case WACOM_MO: 863 case WACOM_MO:
858 input_dev_mo(input_dev, wacom_wac); 864 input_dev_mo(input_dev, wacom_wac);
859 case WACOM_G4: 865 case WACOM_G4:
@@ -888,7 +894,7 @@ void wacom_init_input_dev(struct input_dev *input_dev, struct wacom_wac *wacom_w
888 /* fall through */ 894 /* fall through */
889 case TABLETPC: 895 case TABLETPC:
890 input_dev_tpc(input_dev, wacom_wac); 896 input_dev_tpc(input_dev, wacom_wac);
891 if (wacom_wac->features->device_type != BTN_TOOL_PEN) 897 if (wacom_wac->features.device_type != BTN_TOOL_PEN)
892 break; /* no need to process stylus stuff */ 898 break; /* no need to process stylus stuff */
893 899
894 /* fall through */ 900 /* fall through */
@@ -903,153 +909,201 @@ void wacom_init_input_dev(struct input_dev *input_dev, struct wacom_wac *wacom_w
903 return; 909 return;
904} 910}
905 911
906static struct wacom_features wacom_features[] = { 912static const struct wacom_features wacom_features_0x00 =
907 { "Wacom Penpartner", WACOM_PKGLEN_PENPRTN, 5040, 3780, 255, 0, PENPARTNER }, 913 { "Wacom Penpartner", WACOM_PKGLEN_PENPRTN, 5040, 3780, 255, 0, PENPARTNER };
908 { "Wacom Graphire", WACOM_PKGLEN_GRAPHIRE, 10206, 7422, 511, 63, GRAPHIRE }, 914static const struct wacom_features wacom_features_0x10 =
909 { "Wacom Graphire2 4x5", WACOM_PKGLEN_GRAPHIRE, 10206, 7422, 511, 63, GRAPHIRE }, 915 { "Wacom Graphire", WACOM_PKGLEN_GRAPHIRE, 10206, 7422, 511, 63, GRAPHIRE };
910 { "Wacom Graphire2 5x7", WACOM_PKGLEN_GRAPHIRE, 13918, 10206, 511, 63, GRAPHIRE }, 916static const struct wacom_features wacom_features_0x11 =
911 { "Wacom Graphire3", WACOM_PKGLEN_GRAPHIRE, 10208, 7424, 511, 63, GRAPHIRE }, 917 { "Wacom Graphire2 4x5", WACOM_PKGLEN_GRAPHIRE, 10206, 7422, 511, 63, GRAPHIRE };
912 { "Wacom Graphire3 6x8", WACOM_PKGLEN_GRAPHIRE, 16704, 12064, 511, 63, GRAPHIRE }, 918static const struct wacom_features wacom_features_0x12 =
913 { "Wacom Graphire4 4x5", WACOM_PKGLEN_GRAPHIRE, 10208, 7424, 511, 63, WACOM_G4 }, 919 { "Wacom Graphire2 5x7", WACOM_PKGLEN_GRAPHIRE, 13918, 10206, 511, 63, GRAPHIRE };
914 { "Wacom Graphire4 6x8", WACOM_PKGLEN_GRAPHIRE, 16704, 12064, 511, 63, WACOM_G4 }, 920static const struct wacom_features wacom_features_0x13 =
915 { "Wacom BambooFun 4x5", WACOM_PKGLEN_BBFUN, 14760, 9225, 511, 63, WACOM_MO }, 921 { "Wacom Graphire3", WACOM_PKGLEN_GRAPHIRE, 10208, 7424, 511, 63, GRAPHIRE };
916 { "Wacom BambooFun 6x8", WACOM_PKGLEN_BBFUN, 21648, 13530, 511, 63, WACOM_MO }, 922static const struct wacom_features wacom_features_0x14 =
917 { "Wacom Bamboo1 Medium", WACOM_PKGLEN_GRAPHIRE, 16704, 12064, 511, 63, GRAPHIRE }, 923 { "Wacom Graphire3 6x8", WACOM_PKGLEN_GRAPHIRE, 16704, 12064, 511, 63, GRAPHIRE };
918 { "Wacom Volito", WACOM_PKGLEN_GRAPHIRE, 5104, 3712, 511, 63, GRAPHIRE }, 924static const struct wacom_features wacom_features_0x15 =
919 { "Wacom PenStation2", WACOM_PKGLEN_GRAPHIRE, 3250, 2320, 255, 63, GRAPHIRE }, 925 { "Wacom Graphire4 4x5", WACOM_PKGLEN_GRAPHIRE, 10208, 7424, 511, 63, WACOM_G4 };
920 { "Wacom Volito2 4x5", WACOM_PKGLEN_GRAPHIRE, 5104, 3712, 511, 63, GRAPHIRE }, 926static const struct wacom_features wacom_features_0x16 =
921 { "Wacom Volito2 2x3", WACOM_PKGLEN_GRAPHIRE, 3248, 2320, 511, 63, GRAPHIRE }, 927 { "Wacom Graphire4 6x8", WACOM_PKGLEN_GRAPHIRE, 16704, 12064, 511, 63, WACOM_G4 };
922 { "Wacom PenPartner2", WACOM_PKGLEN_GRAPHIRE, 3250, 2320, 511, 63, GRAPHIRE }, 928static const struct wacom_features wacom_features_0x17 =
923 { "Wacom Bamboo", WACOM_PKGLEN_BBFUN, 14760, 9225, 511, 63, WACOM_MO }, 929 { "Wacom BambooFun 4x5", WACOM_PKGLEN_BBFUN, 14760, 9225, 511, 63, WACOM_MO };
924 { "Wacom Bamboo1", WACOM_PKGLEN_GRAPHIRE, 5104, 3712, 511, 63, GRAPHIRE }, 930static const struct wacom_features wacom_features_0x18 =
925 { "Wacom Intuos 4x5", WACOM_PKGLEN_INTUOS, 12700, 10600, 1023, 31, INTUOS }, 931 { "Wacom BambooFun 6x8", WACOM_PKGLEN_BBFUN, 21648, 13530, 511, 63, WACOM_MO };
926 { "Wacom Intuos 6x8", WACOM_PKGLEN_INTUOS, 20320, 16240, 1023, 31, INTUOS }, 932static const struct wacom_features wacom_features_0x19 =
927 { "Wacom Intuos 9x12", WACOM_PKGLEN_INTUOS, 30480, 24060, 1023, 31, INTUOS }, 933 { "Wacom Bamboo1 Medium", WACOM_PKGLEN_GRAPHIRE, 16704, 12064, 511, 63, GRAPHIRE };
928 { "Wacom Intuos 12x12", WACOM_PKGLEN_INTUOS, 30480, 31680, 1023, 31, INTUOS }, 934static const struct wacom_features wacom_features_0x60 =
929 { "Wacom Intuos 12x18", WACOM_PKGLEN_INTUOS, 45720, 31680, 1023, 31, INTUOS }, 935 { "Wacom Volito", WACOM_PKGLEN_GRAPHIRE, 5104, 3712, 511, 63, GRAPHIRE };
930 { "Wacom PL400", WACOM_PKGLEN_GRAPHIRE, 5408, 4056, 255, 0, PL }, 936static const struct wacom_features wacom_features_0x61 =
931 { "Wacom PL500", WACOM_PKGLEN_GRAPHIRE, 6144, 4608, 255, 0, PL }, 937 { "Wacom PenStation2", WACOM_PKGLEN_GRAPHIRE, 3250, 2320, 255, 63, GRAPHIRE };
932 { "Wacom PL600", WACOM_PKGLEN_GRAPHIRE, 6126, 4604, 255, 0, PL }, 938static const struct wacom_features wacom_features_0x62 =
933 { "Wacom PL600SX", WACOM_PKGLEN_GRAPHIRE, 6260, 5016, 255, 0, PL }, 939 { "Wacom Volito2 4x5", WACOM_PKGLEN_GRAPHIRE, 5104, 3712, 511, 63, GRAPHIRE };
934 { "Wacom PL550", WACOM_PKGLEN_GRAPHIRE, 6144, 4608, 511, 0, PL }, 940static const struct wacom_features wacom_features_0x63 =
935 { "Wacom PL800", WACOM_PKGLEN_GRAPHIRE, 7220, 5780, 511, 0, PL }, 941 { "Wacom Volito2 2x3", WACOM_PKGLEN_GRAPHIRE, 3248, 2320, 511, 63, GRAPHIRE };
936 { "Wacom PL700", WACOM_PKGLEN_GRAPHIRE, 6758, 5406, 511, 0, PL }, 942static const struct wacom_features wacom_features_0x64 =
937 { "Wacom PL510", WACOM_PKGLEN_GRAPHIRE, 6282, 4762, 511, 0, PL }, 943 { "Wacom PenPartner2", WACOM_PKGLEN_GRAPHIRE, 3250, 2320, 511, 63, GRAPHIRE };
938 { "Wacom DTU710", WACOM_PKGLEN_GRAPHIRE, 34080, 27660, 511, 0, PL }, 944static const struct wacom_features wacom_features_0x65 =
939 { "Wacom DTF521", WACOM_PKGLEN_GRAPHIRE, 6282, 4762, 511, 0, PL }, 945 { "Wacom Bamboo", WACOM_PKGLEN_BBFUN, 14760, 9225, 511, 63, WACOM_MO };
940 { "Wacom DTF720", WACOM_PKGLEN_GRAPHIRE, 6858, 5506, 511, 0, PL }, 946static const struct wacom_features wacom_features_0x69 =
941 { "Wacom DTF720a", WACOM_PKGLEN_GRAPHIRE, 6858, 5506, 511, 0, PL }, 947 { "Wacom Bamboo1", WACOM_PKGLEN_GRAPHIRE, 5104, 3712, 511, 63, GRAPHIRE };
942 { "Wacom Cintiq Partner", WACOM_PKGLEN_GRAPHIRE, 20480, 15360, 511, 0, PTU }, 948static const struct wacom_features wacom_features_0x20 =
943 { "Wacom Intuos2 4x5", WACOM_PKGLEN_INTUOS, 12700, 10600, 1023, 31, INTUOS }, 949 { "Wacom Intuos 4x5", WACOM_PKGLEN_INTUOS, 12700, 10600, 1023, 31, INTUOS };
944 { "Wacom Intuos2 6x8", WACOM_PKGLEN_INTUOS, 20320, 16240, 1023, 31, INTUOS }, 950static const struct wacom_features wacom_features_0x21 =
945 { "Wacom Intuos2 9x12", WACOM_PKGLEN_INTUOS, 30480, 24060, 1023, 31, INTUOS }, 951 { "Wacom Intuos 6x8", WACOM_PKGLEN_INTUOS, 20320, 16240, 1023, 31, INTUOS };
946 { "Wacom Intuos2 12x12", WACOM_PKGLEN_INTUOS, 30480, 31680, 1023, 31, INTUOS }, 952static const struct wacom_features wacom_features_0x22 =
947 { "Wacom Intuos2 12x18", WACOM_PKGLEN_INTUOS, 45720, 31680, 1023, 31, INTUOS }, 953 { "Wacom Intuos 9x12", WACOM_PKGLEN_INTUOS, 30480, 24060, 1023, 31, INTUOS };
948 { "Wacom Intuos3 4x5", WACOM_PKGLEN_INTUOS, 25400, 20320, 1023, 63, INTUOS3S }, 954static const struct wacom_features wacom_features_0x23 =
949 { "Wacom Intuos3 6x8", WACOM_PKGLEN_INTUOS, 40640, 30480, 1023, 63, INTUOS3 }, 955 { "Wacom Intuos 12x12", WACOM_PKGLEN_INTUOS, 30480, 31680, 1023, 31, INTUOS };
950 { "Wacom Intuos3 9x12", WACOM_PKGLEN_INTUOS, 60960, 45720, 1023, 63, INTUOS3 }, 956static const struct wacom_features wacom_features_0x24 =
951 { "Wacom Intuos3 12x12", WACOM_PKGLEN_INTUOS, 60960, 60960, 1023, 63, INTUOS3L }, 957 { "Wacom Intuos 12x18", WACOM_PKGLEN_INTUOS, 45720, 31680, 1023, 31, INTUOS };
952 { "Wacom Intuos3 12x19", WACOM_PKGLEN_INTUOS, 97536, 60960, 1023, 63, INTUOS3L }, 958static const struct wacom_features wacom_features_0x30 =
953 { "Wacom Intuos3 6x11", WACOM_PKGLEN_INTUOS, 54204, 31750, 1023, 63, INTUOS3 }, 959 { "Wacom PL400", WACOM_PKGLEN_GRAPHIRE, 5408, 4056, 255, 0, PL };
954 { "Wacom Intuos3 4x6", WACOM_PKGLEN_INTUOS, 31496, 19685, 1023, 63, INTUOS3S }, 960static const struct wacom_features wacom_features_0x31 =
955 { "Wacom Intuos4 4x6", WACOM_PKGLEN_INTUOS, 31496, 19685, 2047, 63, INTUOS4S }, 961 { "Wacom PL500", WACOM_PKGLEN_GRAPHIRE, 6144, 4608, 255, 0, PL };
956 { "Wacom Intuos4 6x9", WACOM_PKGLEN_INTUOS, 44704, 27940, 2047, 63, INTUOS4 }, 962static const struct wacom_features wacom_features_0x32 =
957 { "Wacom Intuos4 8x13", WACOM_PKGLEN_INTUOS, 65024, 40640, 2047, 63, INTUOS4L }, 963 { "Wacom PL600", WACOM_PKGLEN_GRAPHIRE, 6126, 4604, 255, 0, PL };
958 { "Wacom Intuos4 12x19", WACOM_PKGLEN_INTUOS, 97536, 60960, 2047, 63, INTUOS4L }, 964static const struct wacom_features wacom_features_0x33 =
959 { "Wacom Cintiq 21UX", WACOM_PKGLEN_INTUOS, 87200, 65600, 1023, 63, CINTIQ }, 965 { "Wacom PL600SX", WACOM_PKGLEN_GRAPHIRE, 6260, 5016, 255, 0, PL };
960 { "Wacom Cintiq 20WSX", WACOM_PKGLEN_INTUOS, 86680, 54180, 1023, 63, WACOM_BEE }, 966static const struct wacom_features wacom_features_0x34 =
961 { "Wacom Cintiq 12WX", WACOM_PKGLEN_INTUOS, 53020, 33440, 1023, 63, WACOM_BEE }, 967 { "Wacom PL550", WACOM_PKGLEN_GRAPHIRE, 6144, 4608, 511, 0, PL };
962 { "Wacom DTU1931", WACOM_PKGLEN_GRAPHIRE, 37832, 30305, 511, 0, PL }, 968static const struct wacom_features wacom_features_0x35 =
963 { "Wacom ISDv4 90", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 255, 0, TABLETPC }, 969 { "Wacom PL800", WACOM_PKGLEN_GRAPHIRE, 7220, 5780, 511, 0, PL };
964 { "Wacom ISDv4 93", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 255, 0, TABLETPC }, 970static const struct wacom_features wacom_features_0x37 =
965 { "Wacom ISDv4 9A", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 255, 0, TABLETPC }, 971 { "Wacom PL700", WACOM_PKGLEN_GRAPHIRE, 6758, 5406, 511, 0, PL };
966 { "Wacom ISDv4 9F", WACOM_PKGLEN_PENABLED, 26202, 16325, 255, 0, TABLETPC }, 972static const struct wacom_features wacom_features_0x38 =
967 { "Wacom ISDv4 E2", WACOM_PKGLEN_TPC2FG, 26202, 16325, 255, 0, TABLETPC2FG }, 973 { "Wacom PL510", WACOM_PKGLEN_GRAPHIRE, 6282, 4762, 511, 0, PL };
968 { "Wacom ISDv4 E3", WACOM_PKGLEN_TPC2FG, 26202, 16325, 255, 0, TABLETPC2FG }, 974static const struct wacom_features wacom_features_0x39 =
969 { "Wacom Intuos2 6x8", WACOM_PKGLEN_INTUOS, 20320, 16240, 1023, 31, INTUOS }, 975 { "Wacom DTU710", WACOM_PKGLEN_GRAPHIRE, 34080, 27660, 511, 0, PL };
976static const struct wacom_features wacom_features_0xC4 =
977 { "Wacom DTF521", WACOM_PKGLEN_GRAPHIRE, 6282, 4762, 511, 0, PL };
978static const struct wacom_features wacom_features_0xC0 =
979 { "Wacom DTF720", WACOM_PKGLEN_GRAPHIRE, 6858, 5506, 511, 0, PL };
980static const struct wacom_features wacom_features_0xC2 =
981 { "Wacom DTF720a", WACOM_PKGLEN_GRAPHIRE, 6858, 5506, 511, 0, PL };
982static const struct wacom_features wacom_features_0x03 =
983 { "Wacom Cintiq Partner", WACOM_PKGLEN_GRAPHIRE, 20480, 15360, 511, 0, PTU };
984static const struct wacom_features wacom_features_0x41 =
985 { "Wacom Intuos2 4x5", WACOM_PKGLEN_INTUOS, 12700, 10600, 1023, 31, INTUOS };
986static const struct wacom_features wacom_features_0x42 =
987 { "Wacom Intuos2 6x8", WACOM_PKGLEN_INTUOS, 20320, 16240, 1023, 31, INTUOS };
988static const struct wacom_features wacom_features_0x43 =
989 { "Wacom Intuos2 9x12", WACOM_PKGLEN_INTUOS, 30480, 24060, 1023, 31, INTUOS };
990static const struct wacom_features wacom_features_0x44 =
991 { "Wacom Intuos2 12x12", WACOM_PKGLEN_INTUOS, 30480, 31680, 1023, 31, INTUOS };
992static const struct wacom_features wacom_features_0x45 =
993 { "Wacom Intuos2 12x18", WACOM_PKGLEN_INTUOS, 45720, 31680, 1023, 31, INTUOS };
994static const struct wacom_features wacom_features_0xB0 =
995 { "Wacom Intuos3 4x5", WACOM_PKGLEN_INTUOS, 25400, 20320, 1023, 63, INTUOS3S };
996static const struct wacom_features wacom_features_0xB1 =
997 { "Wacom Intuos3 6x8", WACOM_PKGLEN_INTUOS, 40640, 30480, 1023, 63, INTUOS3 };
998static const struct wacom_features wacom_features_0xB2 =
999 { "Wacom Intuos3 9x12", WACOM_PKGLEN_INTUOS, 60960, 45720, 1023, 63, INTUOS3 };
1000static const struct wacom_features wacom_features_0xB3 =
1001 { "Wacom Intuos3 12x12", WACOM_PKGLEN_INTUOS, 60960, 60960, 1023, 63, INTUOS3L };
1002static const struct wacom_features wacom_features_0xB4 =
1003 { "Wacom Intuos3 12x19", WACOM_PKGLEN_INTUOS, 97536, 60960, 1023, 63, INTUOS3L };
1004static const struct wacom_features wacom_features_0xB5 =
1005 { "Wacom Intuos3 6x11", WACOM_PKGLEN_INTUOS, 54204, 31750, 1023, 63, INTUOS3 };
1006static const struct wacom_features wacom_features_0xB7 =
1007 { "Wacom Intuos3 4x6", WACOM_PKGLEN_INTUOS, 31496, 19685, 1023, 63, INTUOS3S };
1008static const struct wacom_features wacom_features_0xB8 =
1009 { "Wacom Intuos4 4x6", WACOM_PKGLEN_INTUOS, 31496, 19685, 2047, 63, INTUOS4S };
1010static const struct wacom_features wacom_features_0xB9 =
1011 { "Wacom Intuos4 6x9", WACOM_PKGLEN_INTUOS, 44704, 27940, 2047, 63, INTUOS4 };
1012static const struct wacom_features wacom_features_0xBA =
1013 { "Wacom Intuos4 8x13", WACOM_PKGLEN_INTUOS, 65024, 40640, 2047, 63, INTUOS4L };
1014static const struct wacom_features wacom_features_0xBB =
1015 { "Wacom Intuos4 12x19", WACOM_PKGLEN_INTUOS, 97536, 60960, 2047, 63, INTUOS4L };
1016static const struct wacom_features wacom_features_0x3F =
1017 { "Wacom Cintiq 21UX", WACOM_PKGLEN_INTUOS, 87200, 65600, 1023, 63, CINTIQ };
1018static const struct wacom_features wacom_features_0xC5 =
1019 { "Wacom Cintiq 20WSX", WACOM_PKGLEN_INTUOS, 86680, 54180, 1023, 63, WACOM_BEE };
1020static const struct wacom_features wacom_features_0xC6 =
1021 { "Wacom Cintiq 12WX", WACOM_PKGLEN_INTUOS, 53020, 33440, 1023, 63, WACOM_BEE };
1022static const struct wacom_features wacom_features_0xC7 =
1023 { "Wacom DTU1931", WACOM_PKGLEN_GRAPHIRE, 37832, 30305, 511, 0, PL };
1024static const struct wacom_features wacom_features_0x90 =
1025 { "Wacom ISDv4 90", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 255, 0, TABLETPC };
1026static const struct wacom_features wacom_features_0x93 =
1027 { "Wacom ISDv4 93", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 255, 0, TABLETPC };
1028static const struct wacom_features wacom_features_0x9A =
1029 { "Wacom ISDv4 9A", WACOM_PKGLEN_GRAPHIRE, 26202, 16325, 255, 0, TABLETPC };
1030static const struct wacom_features wacom_features_0x9F =
1031 { "Wacom ISDv4 9F", WACOM_PKGLEN_PENABLED, 26202, 16325, 255, 0, TABLETPC };
1032static const struct wacom_features wacom_features_0xE2 =
1033 { "Wacom ISDv4 E2", WACOM_PKGLEN_TPC2FG, 26202, 16325, 255, 0, TABLETPC2FG };
1034static const struct wacom_features wacom_features_0xE3 =
1035 { "Wacom ISDv4 E3", WACOM_PKGLEN_TPC2FG, 26202, 16325, 255, 0, TABLETPC2FG };
1036static const struct wacom_features wacom_features_0x47 =
1037 { "Wacom Intuos2 6x8", WACOM_PKGLEN_INTUOS, 20320, 16240, 1023, 31, INTUOS };
1038
1039#define USB_DEVICE_WACOM(prod) \
1040 USB_DEVICE(USB_VENDOR_ID_WACOM, prod), \
1041 .driver_info = (kernel_ulong_t)&wacom_features_##prod
1042
1043const struct usb_device_id wacom_ids[] = {
1044 { USB_DEVICE_WACOM(0x00) },
1045 { USB_DEVICE_WACOM(0x10) },
1046 { USB_DEVICE_WACOM(0x11) },
1047 { USB_DEVICE_WACOM(0x12) },
1048 { USB_DEVICE_WACOM(0x13) },
1049 { USB_DEVICE_WACOM(0x14) },
1050 { USB_DEVICE_WACOM(0x15) },
1051 { USB_DEVICE_WACOM(0x16) },
1052 { USB_DEVICE_WACOM(0x17) },
1053 { USB_DEVICE_WACOM(0x18) },
1054 { USB_DEVICE_WACOM(0x19) },
1055 { USB_DEVICE_WACOM(0x60) },
1056 { USB_DEVICE_WACOM(0x61) },
1057 { USB_DEVICE_WACOM(0x62) },
1058 { USB_DEVICE_WACOM(0x63) },
1059 { USB_DEVICE_WACOM(0x64) },
1060 { USB_DEVICE_WACOM(0x65) },
1061 { USB_DEVICE_WACOM(0x69) },
1062 { USB_DEVICE_WACOM(0x20) },
1063 { USB_DEVICE_WACOM(0x21) },
1064 { USB_DEVICE_WACOM(0x22) },
1065 { USB_DEVICE_WACOM(0x23) },
1066 { USB_DEVICE_WACOM(0x24) },
1067 { USB_DEVICE_WACOM(0x30) },
1068 { USB_DEVICE_WACOM(0x31) },
1069 { USB_DEVICE_WACOM(0x32) },
1070 { USB_DEVICE_WACOM(0x33) },
1071 { USB_DEVICE_WACOM(0x34) },
1072 { USB_DEVICE_WACOM(0x35) },
1073 { USB_DEVICE_WACOM(0x37) },
1074 { USB_DEVICE_WACOM(0x38) },
1075 { USB_DEVICE_WACOM(0x39) },
1076 { USB_DEVICE_WACOM(0xC4) },
1077 { USB_DEVICE_WACOM(0xC0) },
1078 { USB_DEVICE_WACOM(0xC2) },
1079 { USB_DEVICE_WACOM(0x03) },
1080 { USB_DEVICE_WACOM(0x41) },
1081 { USB_DEVICE_WACOM(0x42) },
1082 { USB_DEVICE_WACOM(0x43) },
1083 { USB_DEVICE_WACOM(0x44) },
1084 { USB_DEVICE_WACOM(0x45) },
1085 { USB_DEVICE_WACOM(0xB0) },
1086 { USB_DEVICE_WACOM(0xB1) },
1087 { USB_DEVICE_WACOM(0xB2) },
1088 { USB_DEVICE_WACOM(0xB3) },
1089 { USB_DEVICE_WACOM(0xB4) },
1090 { USB_DEVICE_WACOM(0xB5) },
1091 { USB_DEVICE_WACOM(0xB7) },
1092 { USB_DEVICE_WACOM(0xB8) },
1093 { USB_DEVICE_WACOM(0xB9) },
1094 { USB_DEVICE_WACOM(0xBA) },
1095 { USB_DEVICE_WACOM(0xBB) },
1096 { USB_DEVICE_WACOM(0x3F) },
1097 { USB_DEVICE_WACOM(0xC5) },
1098 { USB_DEVICE_WACOM(0xC6) },
1099 { USB_DEVICE_WACOM(0xC7) },
1100 { USB_DEVICE_WACOM(0x90) },
1101 { USB_DEVICE_WACOM(0x93) },
1102 { USB_DEVICE_WACOM(0x9A) },
1103 { USB_DEVICE_WACOM(0x9F) },
1104 { USB_DEVICE_WACOM(0xE2) },
1105 { USB_DEVICE_WACOM(0xE3) },
1106 { USB_DEVICE_WACOM(0x47) },
970 { } 1107 { }
971}; 1108};
972
973static struct usb_device_id wacom_ids[] = {
974 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x00) },
975 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x10) },
976 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x11) },
977 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x12) },
978 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x13) },
979 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x14) },
980 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x15) },
981 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x16) },
982 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x17) },
983 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x18) },
984 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x19) },
985 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x60) },
986 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x61) },
987 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x62) },
988 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x63) },
989 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x64) },
990 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x65) },
991 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x69) },
992 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x20) },
993 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x21) },
994 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x22) },
995 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x23) },
996 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x24) },
997 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x30) },
998 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x31) },
999 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x32) },
1000 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x33) },
1001 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x34) },
1002 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x35) },
1003 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x37) },
1004 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x38) },
1005 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x39) },
1006 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC4) },
1007 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC0) },
1008 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC2) },
1009 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x03) },
1010 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x41) },
1011 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x42) },
1012 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x43) },
1013 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x44) },
1014 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x45) },
1015 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB0) },
1016 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB1) },
1017 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB2) },
1018 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB3) },
1019 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB4) },
1020 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB5) },
1021 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB7) },
1022 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB8) },
1023 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xB9) },
1024 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xBA) },
1025 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xBB) },
1026 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x3F) },
1027 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC5) },
1028 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC6) },
1029 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xC7) },
1030 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x90) },
1031 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x93) },
1032 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x9A) },
1033 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x9F) },
1034 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xE2) },
1035 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0xE3) },
1036 { USB_DEVICE(USB_VENDOR_ID_WACOM, 0x47) },
1037 { }
1038};
1039
1040const struct usb_device_id *get_device_table(void)
1041{
1042 const struct usb_device_id *id_table = wacom_ids;
1043
1044 return id_table;
1045}
1046
1047struct wacom_features * get_wacom_feature(const struct usb_device_id *id)
1048{
1049 int index = id - wacom_ids;
1050 struct wacom_features *wf = &wacom_features[index];
1051
1052 return wf;
1053}
1054
1055MODULE_DEVICE_TABLE(usb, wacom_ids); 1109MODULE_DEVICE_TABLE(usb, wacom_ids);
diff --git a/drivers/input/tablet/wacom_wac.h b/drivers/input/tablet/wacom_wac.h
index ee01e1902785..8590b1e8ec37 100644
--- a/drivers/input/tablet/wacom_wac.h
+++ b/drivers/input/tablet/wacom_wac.h
@@ -15,11 +15,11 @@
15/* packet length for individual models */ 15/* packet length for individual models */
16#define WACOM_PKGLEN_PENPRTN 7 16#define WACOM_PKGLEN_PENPRTN 7
17#define WACOM_PKGLEN_GRAPHIRE 8 17#define WACOM_PKGLEN_GRAPHIRE 8
18#define WACOM_PKGLEN_BBFUN 9 18#define WACOM_PKGLEN_BBFUN 9
19#define WACOM_PKGLEN_INTUOS 10 19#define WACOM_PKGLEN_INTUOS 10
20#define WACOM_PKGLEN_PENABLED 8 20#define WACOM_PKGLEN_PENABLED 8
21#define WACOM_PKGLEN_TPC1FG 5 21#define WACOM_PKGLEN_TPC1FG 5
22#define WACOM_PKGLEN_TPC2FG 14 22#define WACOM_PKGLEN_TPC2FG 14
23 23
24/* device IDs */ 24/* device IDs */
25#define STYLUS_DEVICE_ID 0x02 25#define STYLUS_DEVICE_ID 0x02
@@ -58,7 +58,7 @@ enum {
58}; 58};
59 59
60struct wacom_features { 60struct wacom_features {
61 char *name; 61 const char *name;
62 int pktlen; 62 int pktlen;
63 int x_max; 63 int x_max;
64 int y_max; 64 int y_max;
@@ -73,11 +73,12 @@ struct wacom_features {
73}; 73};
74 74
75struct wacom_wac { 75struct wacom_wac {
76 char name[64];
76 unsigned char *data; 77 unsigned char *data;
77 int tool[2]; 78 int tool[2];
78 int id[2]; 79 int id[2];
79 __u32 serial[2]; 80 __u32 serial[2];
80 struct wacom_features *features; 81 struct wacom_features features;
81}; 82};
82 83
83#endif 84#endif
diff --git a/drivers/input/touchscreen/Kconfig b/drivers/input/touchscreen/Kconfig
index dfafc76da4fb..6457e060ae49 100644
--- a/drivers/input/touchscreen/Kconfig
+++ b/drivers/input/touchscreen/Kconfig
@@ -90,7 +90,6 @@ config TOUCHSCREEN_CORGI
90 tristate "SharpSL (Corgi and Spitz series) touchscreen driver (DEPRECATED)" 90 tristate "SharpSL (Corgi and Spitz series) touchscreen driver (DEPRECATED)"
91 depends on PXA_SHARPSL 91 depends on PXA_SHARPSL
92 select CORGI_SSP_DEPRECATED 92 select CORGI_SSP_DEPRECATED
93 default y
94 help 93 help
95 Say Y here to enable the driver for the touchscreen on the 94 Say Y here to enable the driver for the touchscreen on the
96 Sharp SL-C7xx and SL-Cxx00 series of PDAs. 95 Sharp SL-C7xx and SL-Cxx00 series of PDAs.
@@ -537,6 +536,11 @@ config TOUCHSCREEN_USB_ETT_TC5UH
537 bool "ET&T TC5UH touchscreen controler support" if EMBEDDED 536 bool "ET&T TC5UH touchscreen controler support" if EMBEDDED
538 depends on TOUCHSCREEN_USB_COMPOSITE 537 depends on TOUCHSCREEN_USB_COMPOSITE
539 538
539config TOUCHSCREEN_USB_NEXIO
540 default y
541 bool "NEXIO/iNexio device support" if EMBEDDED
542 depends on TOUCHSCREEN_USB_COMPOSITE
543
540config TOUCHSCREEN_TOUCHIT213 544config TOUCHSCREEN_TOUCHIT213
541 tristate "Sahara TouchIT-213 touchscreen" 545 tristate "Sahara TouchIT-213 touchscreen"
542 select SERIO 546 select SERIO
diff --git a/drivers/input/touchscreen/ads7846.c b/drivers/input/touchscreen/ads7846.c
index 52d2ca147d8f..8b05d8e97543 100644
--- a/drivers/input/touchscreen/ads7846.c
+++ b/drivers/input/touchscreen/ads7846.c
@@ -27,6 +27,7 @@
27#include <linux/gpio.h> 27#include <linux/gpio.h>
28#include <linux/spi/spi.h> 28#include <linux/spi/spi.h>
29#include <linux/spi/ads7846.h> 29#include <linux/spi/ads7846.h>
30#include <linux/regulator/consumer.h>
30#include <asm/irq.h> 31#include <asm/irq.h>
31 32
32/* 33/*
@@ -85,6 +86,7 @@ struct ads7846 {
85 char name[32]; 86 char name[32];
86 87
87 struct spi_device *spi; 88 struct spi_device *spi;
89 struct regulator *reg;
88 90
89#if defined(CONFIG_HWMON) || defined(CONFIG_HWMON_MODULE) 91#if defined(CONFIG_HWMON) || defined(CONFIG_HWMON_MODULE)
90 struct attribute_group *attr_group; 92 struct attribute_group *attr_group;
@@ -788,6 +790,8 @@ static void ads7846_disable(struct ads7846 *ts)
788 } 790 }
789 } 791 }
790 792
793 regulator_disable(ts->reg);
794
791 /* we know the chip's in lowpower mode since we always 795 /* we know the chip's in lowpower mode since we always
792 * leave it that way after every request 796 * leave it that way after every request
793 */ 797 */
@@ -799,6 +803,8 @@ static void ads7846_enable(struct ads7846 *ts)
799 if (!ts->disabled) 803 if (!ts->disabled)
800 return; 804 return;
801 805
806 regulator_enable(ts->reg);
807
802 ts->disabled = 0; 808 ts->disabled = 0;
803 ts->irq_disabled = 0; 809 ts->irq_disabled = 0;
804 enable_irq(ts->spi->irq); 810 enable_irq(ts->spi->irq);
@@ -1139,6 +1145,19 @@ static int __devinit ads7846_probe(struct spi_device *spi)
1139 1145
1140 ts->last_msg = m; 1146 ts->last_msg = m;
1141 1147
1148 ts->reg = regulator_get(&spi->dev, "vcc");
1149 if (IS_ERR(ts->reg)) {
1150 dev_err(&spi->dev, "unable to get regulator: %ld\n",
1151 PTR_ERR(ts->reg));
1152 goto err_free_gpio;
1153 }
1154
1155 err = regulator_enable(ts->reg);
1156 if (err) {
1157 dev_err(&spi->dev, "unable to enable regulator: %d\n", err);
1158 goto err_put_regulator;
1159 }
1160
1142 if (request_irq(spi->irq, ads7846_irq, IRQF_TRIGGER_FALLING, 1161 if (request_irq(spi->irq, ads7846_irq, IRQF_TRIGGER_FALLING,
1143 spi->dev.driver->name, ts)) { 1162 spi->dev.driver->name, ts)) {
1144 dev_info(&spi->dev, 1163 dev_info(&spi->dev,
@@ -1148,7 +1167,7 @@ static int __devinit ads7846_probe(struct spi_device *spi)
1148 spi->dev.driver->name, ts); 1167 spi->dev.driver->name, ts);
1149 if (err) { 1168 if (err) {
1150 dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq); 1169 dev_dbg(&spi->dev, "irq %d busy?\n", spi->irq);
1151 goto err_free_gpio; 1170 goto err_disable_regulator;
1152 } 1171 }
1153 } 1172 }
1154 1173
@@ -1180,6 +1199,10 @@ static int __devinit ads7846_probe(struct spi_device *spi)
1180 ads784x_hwmon_unregister(spi, ts); 1199 ads784x_hwmon_unregister(spi, ts);
1181 err_free_irq: 1200 err_free_irq:
1182 free_irq(spi->irq, ts); 1201 free_irq(spi->irq, ts);
1202 err_disable_regulator:
1203 regulator_disable(ts->reg);
1204 err_put_regulator:
1205 regulator_put(ts->reg);
1183 err_free_gpio: 1206 err_free_gpio:
1184 if (ts->gpio_pendown != -1) 1207 if (ts->gpio_pendown != -1)
1185 gpio_free(ts->gpio_pendown); 1208 gpio_free(ts->gpio_pendown);
@@ -1208,6 +1231,9 @@ static int __devexit ads7846_remove(struct spi_device *spi)
1208 /* suspend left the IRQ disabled */ 1231 /* suspend left the IRQ disabled */
1209 enable_irq(ts->spi->irq); 1232 enable_irq(ts->spi->irq);
1210 1233
1234 regulator_disable(ts->reg);
1235 regulator_put(ts->reg);
1236
1211 if (ts->gpio_pendown != -1) 1237 if (ts->gpio_pendown != -1)
1212 gpio_free(ts->gpio_pendown); 1238 gpio_free(ts->gpio_pendown);
1213 1239
diff --git a/drivers/input/touchscreen/elo.c b/drivers/input/touchscreen/elo.c
index 8f38c5e55ce6..486d31ba9c09 100644
--- a/drivers/input/touchscreen/elo.c
+++ b/drivers/input/touchscreen/elo.c
@@ -72,45 +72,49 @@ static void elo_process_data_10(struct elo *elo, unsigned char data)
72 struct input_dev *dev = elo->dev; 72 struct input_dev *dev = elo->dev;
73 73
74 elo->data[elo->idx] = data; 74 elo->data[elo->idx] = data;
75 switch (elo->idx++) {
76 case 0:
77 elo->csum = 0xaa;
78 if (data != ELO10_LEAD_BYTE) {
79 pr_debug("elo: unsynchronized data: 0x%02x\n", data);
80 elo->idx = 0;
81 }
82 break;
83 75
84 case 9: 76 switch (elo->idx++) {
77 case 0:
78 elo->csum = 0xaa;
79 if (data != ELO10_LEAD_BYTE) {
80 dev_dbg(&elo->serio->dev,
81 "unsynchronized data: 0x%02x\n", data);
85 elo->idx = 0; 82 elo->idx = 0;
86 if (data != elo->csum) { 83 }
87 pr_debug("elo: bad checksum: 0x%02x, expected 0x%02x\n", 84 break;
88 data, elo->csum); 85
89 break; 86 case 9:
90 } 87 elo->idx = 0;
91 if (elo->data[1] != elo->expected_packet) { 88 if (data != elo->csum) {
92 if (elo->data[1] != ELO10_TOUCH_PACKET) 89 dev_dbg(&elo->serio->dev,
93 pr_debug("elo: unexpected packet: 0x%02x\n", 90 "bad checksum: 0x%02x, expected 0x%02x\n",
94 elo->data[1]); 91 data, elo->csum);
95 break; 92 break;
96 } 93 }
97 if (likely(elo->data[1] == ELO10_TOUCH_PACKET)) { 94 if (elo->data[1] != elo->expected_packet) {
98 input_report_abs(dev, ABS_X, (elo->data[4] << 8) | elo->data[3]); 95 if (elo->data[1] != ELO10_TOUCH_PACKET)
99 input_report_abs(dev, ABS_Y, (elo->data[6] << 8) | elo->data[5]); 96 dev_dbg(&elo->serio->dev,
100 if (elo->data[2] & ELO10_PRESSURE) 97 "unexpected packet: 0x%02x\n",
101 input_report_abs(dev, ABS_PRESSURE, 98 elo->data[1]);
102 (elo->data[8] << 8) | elo->data[7]);
103 input_report_key(dev, BTN_TOUCH, elo->data[2] & ELO10_TOUCH);
104 input_sync(dev);
105 } else if (elo->data[1] == ELO10_ACK_PACKET) {
106 if (elo->data[2] == '0')
107 elo->expected_packet = ELO10_TOUCH_PACKET;
108 complete(&elo->cmd_done);
109 } else {
110 memcpy(elo->response, &elo->data[1], ELO10_PACKET_LEN);
111 elo->expected_packet = ELO10_ACK_PACKET;
112 }
113 break; 99 break;
100 }
101 if (likely(elo->data[1] == ELO10_TOUCH_PACKET)) {
102 input_report_abs(dev, ABS_X, (elo->data[4] << 8) | elo->data[3]);
103 input_report_abs(dev, ABS_Y, (elo->data[6] << 8) | elo->data[5]);
104 if (elo->data[2] & ELO10_PRESSURE)
105 input_report_abs(dev, ABS_PRESSURE,
106 (elo->data[8] << 8) | elo->data[7]);
107 input_report_key(dev, BTN_TOUCH, elo->data[2] & ELO10_TOUCH);
108 input_sync(dev);
109 } else if (elo->data[1] == ELO10_ACK_PACKET) {
110 if (elo->data[2] == '0')
111 elo->expected_packet = ELO10_TOUCH_PACKET;
112 complete(&elo->cmd_done);
113 } else {
114 memcpy(elo->response, &elo->data[1], ELO10_PACKET_LEN);
115 elo->expected_packet = ELO10_ACK_PACKET;
116 }
117 break;
114 } 118 }
115 elo->csum += data; 119 elo->csum += data;
116} 120}
@@ -123,42 +127,53 @@ static void elo_process_data_6(struct elo *elo, unsigned char data)
123 127
124 switch (elo->idx++) { 128 switch (elo->idx++) {
125 129
126 case 0: if ((data & 0xc0) != 0xc0) elo->idx = 0; break; 130 case 0:
127 case 1: if ((data & 0xc0) != 0x80) elo->idx = 0; break; 131 if ((data & 0xc0) != 0xc0)
128 case 2: if ((data & 0xc0) != 0x40) elo->idx = 0; break; 132 elo->idx = 0;
129 133 break;
130 case 3:
131 if (data & 0xc0) {
132 elo->idx = 0;
133 break;
134 }
135 134
136 input_report_abs(dev, ABS_X, ((elo->data[0] & 0x3f) << 6) | (elo->data[1] & 0x3f)); 135 case 1:
137 input_report_abs(dev, ABS_Y, ((elo->data[2] & 0x3f) << 6) | (elo->data[3] & 0x3f)); 136 if ((data & 0xc0) != 0x80)
137 elo->idx = 0;
138 break;
138 139
139 if (elo->id == 2) { 140 case 2:
140 input_report_key(dev, BTN_TOUCH, 1); 141 if ((data & 0xc0) != 0x40)
141 input_sync(dev); 142 elo->idx = 0;
142 elo->idx = 0; 143 break;
143 }
144 144
145 case 3:
146 if (data & 0xc0) {
147 elo->idx = 0;
145 break; 148 break;
149 }
146 150
147 case 4: 151 input_report_abs(dev, ABS_X, ((elo->data[0] & 0x3f) << 6) | (elo->data[1] & 0x3f));
148 if (data) { 152 input_report_abs(dev, ABS_Y, ((elo->data[2] & 0x3f) << 6) | (elo->data[3] & 0x3f));
149 input_sync(dev);
150 elo->idx = 0;
151 }
152 break;
153 153
154 case 5: 154 if (elo->id == 2) {
155 if ((data & 0xf0) == 0) { 155 input_report_key(dev, BTN_TOUCH, 1);
156 input_report_abs(dev, ABS_PRESSURE, elo->data[5]);
157 input_report_key(dev, BTN_TOUCH, !!elo->data[5]);
158 }
159 input_sync(dev); 156 input_sync(dev);
160 elo->idx = 0; 157 elo->idx = 0;
161 break; 158 }
159
160 break;
161
162 case 4:
163 if (data) {
164 input_sync(dev);
165 elo->idx = 0;
166 }
167 break;
168
169 case 5:
170 if ((data & 0xf0) == 0) {
171 input_report_abs(dev, ABS_PRESSURE, elo->data[5]);
172 input_report_key(dev, BTN_TOUCH, !!elo->data[5]);
173 }
174 input_sync(dev);
175 elo->idx = 0;
176 break;
162 } 177 }
163} 178}
164 179
@@ -170,17 +185,17 @@ static void elo_process_data_3(struct elo *elo, unsigned char data)
170 185
171 switch (elo->idx++) { 186 switch (elo->idx++) {
172 187
173 case 0: 188 case 0:
174 if ((data & 0x7f) != 0x01) 189 if ((data & 0x7f) != 0x01)
175 elo->idx = 0;
176 break;
177 case 2:
178 input_report_key(dev, BTN_TOUCH, !(elo->data[1] & 0x80));
179 input_report_abs(dev, ABS_X, elo->data[1]);
180 input_report_abs(dev, ABS_Y, elo->data[2]);
181 input_sync(dev);
182 elo->idx = 0; 190 elo->idx = 0;
183 break; 191 break;
192 case 2:
193 input_report_key(dev, BTN_TOUCH, !(elo->data[1] & 0x80));
194 input_report_abs(dev, ABS_X, elo->data[1]);
195 input_report_abs(dev, ABS_Y, elo->data[2]);
196 input_sync(dev);
197 elo->idx = 0;
198 break;
184 } 199 }
185} 200}
186 201
@@ -189,19 +204,19 @@ static irqreturn_t elo_interrupt(struct serio *serio,
189{ 204{
190 struct elo *elo = serio_get_drvdata(serio); 205 struct elo *elo = serio_get_drvdata(serio);
191 206
192 switch(elo->id) { 207 switch (elo->id) {
193 case 0: 208 case 0:
194 elo_process_data_10(elo, data); 209 elo_process_data_10(elo, data);
195 break; 210 break;
196 211
197 case 1: 212 case 1:
198 case 2: 213 case 2:
199 elo_process_data_6(elo, data); 214 elo_process_data_6(elo, data);
200 break; 215 break;
201 216
202 case 3: 217 case 3:
203 elo_process_data_3(elo, data); 218 elo_process_data_3(elo, data);
204 break; 219 break;
205 } 220 }
206 221
207 return IRQ_HANDLED; 222 return IRQ_HANDLED;
@@ -261,10 +276,10 @@ static int elo_setup_10(struct elo *elo)
261 if (packet[3] & ELO10_PRESSURE) 276 if (packet[3] & ELO10_PRESSURE)
262 input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0); 277 input_set_abs_params(dev, ABS_PRESSURE, 0, 255, 0, 0);
263 278
264 printk(KERN_INFO "elo: %sTouch touchscreen, fw: %02x.%02x, " 279 dev_info(&elo->serio->dev,
265 "features: 0x%02x, controller: 0x%02x\n", 280 "%sTouch touchscreen, fw: %02x.%02x, features: 0x%02x, controller: 0x%02x\n",
266 elo_types[(packet[1] -'0') & 0x03], 281 elo_types[(packet[1] -'0') & 0x03],
267 packet[5], packet[4], packet[3], packet[7]); 282 packet[5], packet[4], packet[3], packet[7]);
268 283
269 return 0; 284 return 0;
270} 285}
@@ -330,24 +345,24 @@ static int elo_connect(struct serio *serio, struct serio_driver *drv)
330 345
331 switch (elo->id) { 346 switch (elo->id) {
332 347
333 case 0: /* 10-byte protocol */ 348 case 0: /* 10-byte protocol */
334 if (elo_setup_10(elo)) 349 if (elo_setup_10(elo))
335 goto fail3; 350 goto fail3;
336 351
337 break; 352 break;
338 353
339 case 1: /* 6-byte protocol */ 354 case 1: /* 6-byte protocol */
340 input_set_abs_params(input_dev, ABS_PRESSURE, 0, 15, 0, 0); 355 input_set_abs_params(input_dev, ABS_PRESSURE, 0, 15, 0, 0);
341 356
342 case 2: /* 4-byte protocol */ 357 case 2: /* 4-byte protocol */
343 input_set_abs_params(input_dev, ABS_X, 96, 4000, 0, 0); 358 input_set_abs_params(input_dev, ABS_X, 96, 4000, 0, 0);
344 input_set_abs_params(input_dev, ABS_Y, 96, 4000, 0, 0); 359 input_set_abs_params(input_dev, ABS_Y, 96, 4000, 0, 0);
345 break; 360 break;
346 361
347 case 3: /* 3-byte protocol */ 362 case 3: /* 3-byte protocol */
348 input_set_abs_params(input_dev, ABS_X, 0, 255, 0, 0); 363 input_set_abs_params(input_dev, ABS_X, 0, 255, 0, 0);
349 input_set_abs_params(input_dev, ABS_Y, 0, 255, 0, 0); 364 input_set_abs_params(input_dev, ABS_Y, 0, 255, 0, 0);
350 break; 365 break;
351 } 366 }
352 367
353 err = input_register_device(elo->dev); 368 err = input_register_device(elo->dev);
diff --git a/drivers/input/touchscreen/mainstone-wm97xx.c b/drivers/input/touchscreen/mainstone-wm97xx.c
index 6cdcf2a6e036..b6b8b1c7ecea 100644
--- a/drivers/input/touchscreen/mainstone-wm97xx.c
+++ b/drivers/input/touchscreen/mainstone-wm97xx.c
@@ -153,6 +153,9 @@ static int wm97xx_acc_pen_down(struct wm97xx *wm)
153 if (pressure) 153 if (pressure)
154 p = MODR; 154 p = MODR;
155 155
156 dev_dbg(wm->dev, "Raw coordinates: x=%x, y=%x, p=%x\n",
157 x, y, p);
158
156 /* are samples valid */ 159 /* are samples valid */
157 if ((x & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_X || 160 if ((x & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_X ||
158 (y & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_Y || 161 (y & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_Y ||
diff --git a/drivers/input/touchscreen/s3c2410_ts.c b/drivers/input/touchscreen/s3c2410_ts.c
index 6386b441ef85..3755a47d053c 100644
--- a/drivers/input/touchscreen/s3c2410_ts.c
+++ b/drivers/input/touchscreen/s3c2410_ts.c
@@ -128,27 +128,29 @@ static void touch_timer_fire(unsigned long data)
128 128
129 down = get_down(data0, data1); 129 down = get_down(data0, data1);
130 130
131 if (ts.count == (1 << ts.shift)) { 131 if (down) {
132 ts.xp >>= ts.shift; 132 if (ts.count == (1 << ts.shift)) {
133 ts.yp >>= ts.shift; 133 ts.xp >>= ts.shift;
134 ts.yp >>= ts.shift;
134 135
135 dev_dbg(ts.dev, "%s: X=%lu, Y=%lu, count=%d\n", 136 dev_dbg(ts.dev, "%s: X=%lu, Y=%lu, count=%d\n",
136 __func__, ts.xp, ts.yp, ts.count); 137 __func__, ts.xp, ts.yp, ts.count);
137 138
138 input_report_abs(ts.input, ABS_X, ts.xp); 139 input_report_abs(ts.input, ABS_X, ts.xp);
139 input_report_abs(ts.input, ABS_Y, ts.yp); 140 input_report_abs(ts.input, ABS_Y, ts.yp);
140 141
141 input_report_key(ts.input, BTN_TOUCH, 1); 142 input_report_key(ts.input, BTN_TOUCH, 1);
142 input_sync(ts.input); 143 input_sync(ts.input);
143 144
144 ts.xp = 0; 145 ts.xp = 0;
145 ts.yp = 0; 146 ts.yp = 0;
146 ts.count = 0; 147 ts.count = 0;
147 } 148 }
148 149
149 if (down) {
150 s3c_adc_start(ts.client, 0, 1 << ts.shift); 150 s3c_adc_start(ts.client, 0, 1 << ts.shift);
151 } else { 151 } else {
152 ts.xp = 0;
153 ts.yp = 0;
152 ts.count = 0; 154 ts.count = 0;
153 155
154 input_report_key(ts.input, BTN_TOUCH, 0); 156 input_report_key(ts.input, BTN_TOUCH, 0);
@@ -401,6 +403,7 @@ static int s3c2410ts_resume(struct device *dev)
401 struct s3c2410_ts_mach_info *info = pdev->dev.platform_data; 403 struct s3c2410_ts_mach_info *info = pdev->dev.platform_data;
402 404
403 clk_enable(ts.clock); 405 clk_enable(ts.clock);
406 enable_irq(ts.irq_tc);
404 407
405 /* Initialise registers */ 408 /* Initialise registers */
406 if ((info->delay & 0xffff) > 0) 409 if ((info->delay & 0xffff) > 0)
diff --git a/drivers/input/touchscreen/tsc2007.c b/drivers/input/touchscreen/tsc2007.c
index 7ef0d1420d3c..be23780e8a3e 100644
--- a/drivers/input/touchscreen/tsc2007.c
+++ b/drivers/input/touchscreen/tsc2007.c
@@ -358,7 +358,7 @@ static int __devexit tsc2007_remove(struct i2c_client *client)
358 return 0; 358 return 0;
359} 359}
360 360
361static struct i2c_device_id tsc2007_idtable[] = { 361static const struct i2c_device_id tsc2007_idtable[] = {
362 { "tsc2007", 0 }, 362 { "tsc2007", 0 },
363 { } 363 { }
364}; 364};
diff --git a/drivers/input/touchscreen/usbtouchscreen.c b/drivers/input/touchscreen/usbtouchscreen.c
index 5256123a5228..99330bbdbac7 100644
--- a/drivers/input/touchscreen/usbtouchscreen.c
+++ b/drivers/input/touchscreen/usbtouchscreen.c
@@ -15,6 +15,7 @@
15 * - GoTop Super_Q2/GogoPen/PenPower tablets 15 * - GoTop Super_Q2/GogoPen/PenPower tablets
16 * - JASTEC USB touch controller/DigiTech DTR-02U 16 * - JASTEC USB touch controller/DigiTech DTR-02U
17 * - Zytronic capacitive touchscreen 17 * - Zytronic capacitive touchscreen
18 * - NEXIO/iNexio
18 * 19 *
19 * Copyright (C) 2004-2007 by Daniel Ritz <daniel.ritz@gmx.ch> 20 * Copyright (C) 2004-2007 by Daniel Ritz <daniel.ritz@gmx.ch>
20 * Copyright (C) by Todd E. Johnson (mtouchusb.c) 21 * Copyright (C) by Todd E. Johnson (mtouchusb.c)
@@ -95,6 +96,7 @@ struct usbtouch_device_info {
95 96
96 int (*read_data) (struct usbtouch_usb *usbtouch, unsigned char *pkt); 97 int (*read_data) (struct usbtouch_usb *usbtouch, unsigned char *pkt);
97 int (*init) (struct usbtouch_usb *usbtouch); 98 int (*init) (struct usbtouch_usb *usbtouch);
99 void (*exit) (struct usbtouch_usb *usbtouch);
98}; 100};
99 101
100/* a usbtouch device */ 102/* a usbtouch device */
@@ -104,11 +106,12 @@ struct usbtouch_usb {
104 unsigned char *buffer; 106 unsigned char *buffer;
105 int buf_len; 107 int buf_len;
106 struct urb *irq; 108 struct urb *irq;
107 struct usb_device *udev; 109 struct usb_interface *interface;
108 struct input_dev *input; 110 struct input_dev *input;
109 struct usbtouch_device_info *type; 111 struct usbtouch_device_info *type;
110 char name[128]; 112 char name[128];
111 char phys[64]; 113 char phys[64];
114 void *priv;
112 115
113 int x, y; 116 int x, y;
114 int touch, press; 117 int touch, press;
@@ -133,6 +136,7 @@ enum {
133 DEVTYPE_E2I, 136 DEVTYPE_E2I,
134 DEVTYPE_ZYTRONIC, 137 DEVTYPE_ZYTRONIC,
135 DEVTYPE_TC5UH, 138 DEVTYPE_TC5UH,
139 DEVTYPE_NEXIO,
136}; 140};
137 141
138#define USB_DEVICE_HID_CLASS(vend, prod) \ 142#define USB_DEVICE_HID_CLASS(vend, prod) \
@@ -144,7 +148,7 @@ enum {
144 .bInterfaceClass = USB_INTERFACE_CLASS_HID, \ 148 .bInterfaceClass = USB_INTERFACE_CLASS_HID, \
145 .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE 149 .bInterfaceProtocol = USB_INTERFACE_PROTOCOL_MOUSE
146 150
147static struct usb_device_id usbtouch_devices[] = { 151static const struct usb_device_id usbtouch_devices[] = {
148#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX 152#ifdef CONFIG_TOUCHSCREEN_USB_EGALAX
149 /* ignore the HID capable devices, handled by usbhid */ 153 /* ignore the HID capable devices, handled by usbhid */
150 {USB_DEVICE_HID_CLASS(0x0eef, 0x0001), .driver_info = DEVTYPE_IGNORE}, 154 {USB_DEVICE_HID_CLASS(0x0eef, 0x0001), .driver_info = DEVTYPE_IGNORE},
@@ -222,6 +226,14 @@ static struct usb_device_id usbtouch_devices[] = {
222 {USB_DEVICE(0x0664, 0x0309), .driver_info = DEVTYPE_TC5UH}, 226 {USB_DEVICE(0x0664, 0x0309), .driver_info = DEVTYPE_TC5UH},
223#endif 227#endif
224 228
229#ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
230 /* data interface only */
231 {USB_DEVICE_AND_INTERFACE_INFO(0x10f0, 0x2002, 0x0a, 0x00, 0x00),
232 .driver_info = DEVTYPE_NEXIO},
233 {USB_DEVICE_AND_INTERFACE_INFO(0x1870, 0x0001, 0x0a, 0x00, 0x00),
234 .driver_info = DEVTYPE_NEXIO},
235#endif
236
225 {} 237 {}
226}; 238};
227 239
@@ -234,8 +246,9 @@ static struct usb_device_id usbtouch_devices[] = {
234static int e2i_init(struct usbtouch_usb *usbtouch) 246static int e2i_init(struct usbtouch_usb *usbtouch)
235{ 247{
236 int ret; 248 int ret;
249 struct usb_device *udev = interface_to_usbdev(usbtouch->interface);
237 250
238 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0), 251 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
239 0x01, 0x02, 0x0000, 0x0081, 252 0x01, 0x02, 0x0000, 0x0081,
240 NULL, 0, USB_CTRL_SET_TIMEOUT); 253 NULL, 0, USB_CTRL_SET_TIMEOUT);
241 254
@@ -344,8 +357,9 @@ static int mtouch_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
344static int mtouch_init(struct usbtouch_usb *usbtouch) 357static int mtouch_init(struct usbtouch_usb *usbtouch)
345{ 358{
346 int ret, i; 359 int ret, i;
360 struct usb_device *udev = interface_to_usbdev(usbtouch->interface);
347 361
348 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0), 362 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
349 MTOUCHUSB_RESET, 363 MTOUCHUSB_RESET,
350 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 364 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
351 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT); 365 1, 0, NULL, 0, USB_CTRL_SET_TIMEOUT);
@@ -356,7 +370,7 @@ static int mtouch_init(struct usbtouch_usb *usbtouch)
356 msleep(150); 370 msleep(150);
357 371
358 for (i = 0; i < 3; i++) { 372 for (i = 0; i < 3; i++) {
359 ret = usb_control_msg(usbtouch->udev, usb_rcvctrlpipe(usbtouch->udev, 0), 373 ret = usb_control_msg(udev, usb_rcvctrlpipe(udev, 0),
360 MTOUCHUSB_ASYNC_REPORT, 374 MTOUCHUSB_ASYNC_REPORT,
361 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, 375 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE,
362 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT); 376 1, 1, NULL, 0, USB_CTRL_SET_TIMEOUT);
@@ -489,7 +503,7 @@ static int gunze_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
489 503
490static int dmc_tsc10_init(struct usbtouch_usb *usbtouch) 504static int dmc_tsc10_init(struct usbtouch_usb *usbtouch)
491{ 505{
492 struct usb_device *dev = usbtouch->udev; 506 struct usb_device *dev = interface_to_usbdev(usbtouch->interface);
493 int ret = -ENOMEM; 507 int ret = -ENOMEM;
494 unsigned char *buf; 508 unsigned char *buf;
495 509
@@ -690,6 +704,229 @@ static int zytronic_read_data(struct usbtouch_usb *dev, unsigned char *pkt)
690#endif 704#endif
691 705
692/***************************************************************************** 706/*****************************************************************************
707 * NEXIO Part
708 */
709#ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
710
711#define NEXIO_TIMEOUT 5000
712#define NEXIO_BUFSIZE 1024
713#define NEXIO_THRESHOLD 50
714
715struct nexio_priv {
716 struct urb *ack;
717 unsigned char *ack_buf;
718};
719
720struct nexio_touch_packet {
721 u8 flags; /* 0xe1 = touch, 0xe1 = release */
722 __be16 data_len; /* total bytes of touch data */
723 __be16 x_len; /* bytes for X axis */
724 __be16 y_len; /* bytes for Y axis */
725 u8 data[];
726} __attribute__ ((packed));
727
728static unsigned char nexio_ack_pkt[2] = { 0xaa, 0x02 };
729static unsigned char nexio_init_pkt[4] = { 0x82, 0x04, 0x0a, 0x0f };
730
731static void nexio_ack_complete(struct urb *urb)
732{
733}
734
735static int nexio_init(struct usbtouch_usb *usbtouch)
736{
737 struct usb_device *dev = interface_to_usbdev(usbtouch->interface);
738 struct usb_host_interface *interface = usbtouch->interface->cur_altsetting;
739 struct nexio_priv *priv;
740 int ret = -ENOMEM;
741 int actual_len, i;
742 unsigned char *buf;
743 char *firmware_ver = NULL, *device_name = NULL;
744 int input_ep = 0, output_ep = 0;
745
746 /* find first input and output endpoint */
747 for (i = 0; i < interface->desc.bNumEndpoints; i++) {
748 if (!input_ep &&
749 usb_endpoint_dir_in(&interface->endpoint[i].desc))
750 input_ep = interface->endpoint[i].desc.bEndpointAddress;
751 if (!output_ep &&
752 usb_endpoint_dir_out(&interface->endpoint[i].desc))
753 output_ep = interface->endpoint[i].desc.bEndpointAddress;
754 }
755 if (!input_ep || !output_ep)
756 return -ENXIO;
757
758 buf = kmalloc(NEXIO_BUFSIZE, GFP_KERNEL);
759 if (!buf)
760 goto out_buf;
761
762 /* two empty reads */
763 for (i = 0; i < 2; i++) {
764 ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, input_ep),
765 buf, NEXIO_BUFSIZE, &actual_len,
766 NEXIO_TIMEOUT);
767 if (ret < 0)
768 goto out_buf;
769 }
770
771 /* send init command */
772 memcpy(buf, nexio_init_pkt, sizeof(nexio_init_pkt));
773 ret = usb_bulk_msg(dev, usb_sndbulkpipe(dev, output_ep),
774 buf, sizeof(nexio_init_pkt), &actual_len,
775 NEXIO_TIMEOUT);
776 if (ret < 0)
777 goto out_buf;
778
779 /* read replies */
780 for (i = 0; i < 3; i++) {
781 memset(buf, 0, NEXIO_BUFSIZE);
782 ret = usb_bulk_msg(dev, usb_rcvbulkpipe(dev, input_ep),
783 buf, NEXIO_BUFSIZE, &actual_len,
784 NEXIO_TIMEOUT);
785 if (ret < 0 || actual_len < 1 || buf[1] != actual_len)
786 continue;
787 switch (buf[0]) {
788 case 0x83: /* firmware version */
789 if (!firmware_ver)
790 firmware_ver = kstrdup(&buf[2], GFP_KERNEL);
791 break;
792 case 0x84: /* device name */
793 if (!device_name)
794 device_name = kstrdup(&buf[2], GFP_KERNEL);
795 break;
796 }
797 }
798
799 printk(KERN_INFO "Nexio device: %s, firmware version: %s\n",
800 device_name, firmware_ver);
801
802 kfree(firmware_ver);
803 kfree(device_name);
804
805 /* prepare ACK URB */
806 ret = -ENOMEM;
807
808 usbtouch->priv = kmalloc(sizeof(struct nexio_priv), GFP_KERNEL);
809 if (!usbtouch->priv)
810 goto out_buf;
811
812 priv = usbtouch->priv;
813
814 priv->ack_buf = kmalloc(sizeof(nexio_ack_pkt), GFP_KERNEL);
815 if (!priv->ack_buf)
816 goto err_priv;
817
818 memcpy(priv->ack_buf, nexio_ack_pkt, sizeof(nexio_ack_pkt));
819
820 priv->ack = usb_alloc_urb(0, GFP_KERNEL);
821 if (!priv->ack) {
822 dbg("%s - usb_alloc_urb failed: usbtouch->ack", __func__);
823 goto err_ack_buf;
824 }
825
826 usb_fill_bulk_urb(priv->ack, dev, usb_sndbulkpipe(dev, output_ep),
827 priv->ack_buf, sizeof(nexio_ack_pkt),
828 nexio_ack_complete, usbtouch);
829 ret = 0;
830 goto out_buf;
831
832err_ack_buf:
833 kfree(priv->ack_buf);
834err_priv:
835 kfree(priv);
836out_buf:
837 kfree(buf);
838 return ret;
839}
840
841static void nexio_exit(struct usbtouch_usb *usbtouch)
842{
843 struct nexio_priv *priv = usbtouch->priv;
844
845 usb_kill_urb(priv->ack);
846 usb_free_urb(priv->ack);
847 kfree(priv->ack_buf);
848 kfree(priv);
849}
850
851static int nexio_read_data(struct usbtouch_usb *usbtouch, unsigned char *pkt)
852{
853 int x, y, begin_x, begin_y, end_x, end_y, w, h, ret;
854 struct nexio_touch_packet *packet = (void *) pkt;
855 struct nexio_priv *priv = usbtouch->priv;
856
857 /* got touch data? */
858 if ((pkt[0] & 0xe0) != 0xe0)
859 return 0;
860
861 /* send ACK */
862 ret = usb_submit_urb(priv->ack, GFP_ATOMIC);
863
864 if (!usbtouch->type->max_xc) {
865 usbtouch->type->max_xc = 2 * be16_to_cpu(packet->x_len);
866 input_set_abs_params(usbtouch->input, ABS_X, 0,
867 2 * be16_to_cpu(packet->x_len), 0, 0);
868 usbtouch->type->max_yc = 2 * be16_to_cpu(packet->y_len);
869 input_set_abs_params(usbtouch->input, ABS_Y, 0,
870 2 * be16_to_cpu(packet->y_len), 0, 0);
871 }
872 /*
873 * The device reports state of IR sensors on X and Y axes.
874 * Each byte represents "darkness" percentage (0-100) of one element.
875 * 17" touchscreen reports only 64 x 52 bytes so the resolution is low.
876 * This also means that there's a limited multi-touch capability but
877 * it's disabled (and untested) here as there's no X driver for that.
878 */
879 begin_x = end_x = begin_y = end_y = -1;
880 for (x = 0; x < be16_to_cpu(packet->x_len); x++) {
881 if (begin_x == -1 && packet->data[x] > NEXIO_THRESHOLD) {
882 begin_x = x;
883 continue;
884 }
885 if (end_x == -1 && begin_x != -1 && packet->data[x] < NEXIO_THRESHOLD) {
886 end_x = x - 1;
887 for (y = be16_to_cpu(packet->x_len);
888 y < be16_to_cpu(packet->data_len); y++) {
889 if (begin_y == -1 && packet->data[y] > NEXIO_THRESHOLD) {
890 begin_y = y - be16_to_cpu(packet->x_len);
891 continue;
892 }
893 if (end_y == -1 &&
894 begin_y != -1 && packet->data[y] < NEXIO_THRESHOLD) {
895 end_y = y - 1 - be16_to_cpu(packet->x_len);
896 w = end_x - begin_x;
897 h = end_y - begin_y;
898#if 0
899 /* multi-touch */
900 input_report_abs(usbtouch->input,
901 ABS_MT_TOUCH_MAJOR, max(w,h));
902 input_report_abs(usbtouch->input,
903 ABS_MT_TOUCH_MINOR, min(x,h));
904 input_report_abs(usbtouch->input,
905 ABS_MT_POSITION_X, 2*begin_x+w);
906 input_report_abs(usbtouch->input,
907 ABS_MT_POSITION_Y, 2*begin_y+h);
908 input_report_abs(usbtouch->input,
909 ABS_MT_ORIENTATION, w > h);
910 input_mt_sync(usbtouch->input);
911#endif
912 /* single touch */
913 usbtouch->x = 2 * begin_x + w;
914 usbtouch->y = 2 * begin_y + h;
915 usbtouch->touch = packet->flags & 0x01;
916 begin_y = end_y = -1;
917 return 1;
918 }
919 }
920 begin_x = end_x = -1;
921 }
922
923 }
924 return 0;
925}
926#endif
927
928
929/*****************************************************************************
693 * the different device descriptors 930 * the different device descriptors
694 */ 931 */
695#ifdef MULTI_PACKET 932#ifdef MULTI_PACKET
@@ -873,6 +1110,16 @@ static struct usbtouch_device_info usbtouch_dev_info[] = {
873 .read_data = tc5uh_read_data, 1110 .read_data = tc5uh_read_data,
874 }, 1111 },
875#endif 1112#endif
1113
1114#ifdef CONFIG_TOUCHSCREEN_USB_NEXIO
1115 [DEVTYPE_NEXIO] = {
1116 .rept_size = 128,
1117 .irq_always = true,
1118 .read_data = nexio_read_data,
1119 .init = nexio_init,
1120 .exit = nexio_exit,
1121 },
1122#endif
876}; 1123};
877 1124
878 1125
@@ -998,6 +1245,7 @@ static void usbtouch_irq(struct urb *urb)
998 case -ECONNRESET: 1245 case -ECONNRESET:
999 case -ENOENT: 1246 case -ENOENT:
1000 case -ESHUTDOWN: 1247 case -ESHUTDOWN:
1248 case -EPIPE:
1001 /* this urb is terminated, clean up */ 1249 /* this urb is terminated, clean up */
1002 dbg("%s - urb shutting down with status: %d", 1250 dbg("%s - urb shutting down with status: %d",
1003 __func__, urb->status); 1251 __func__, urb->status);
@@ -1021,7 +1269,7 @@ static int usbtouch_open(struct input_dev *input)
1021{ 1269{
1022 struct usbtouch_usb *usbtouch = input_get_drvdata(input); 1270 struct usbtouch_usb *usbtouch = input_get_drvdata(input);
1023 1271
1024 usbtouch->irq->dev = usbtouch->udev; 1272 usbtouch->irq->dev = interface_to_usbdev(usbtouch->interface);
1025 1273
1026 if (!usbtouch->type->irq_always) { 1274 if (!usbtouch->type->irq_always) {
1027 if (usb_submit_urb(usbtouch->irq, GFP_KERNEL)) 1275 if (usb_submit_urb(usbtouch->irq, GFP_KERNEL))
@@ -1048,13 +1296,23 @@ static void usbtouch_free_buffers(struct usb_device *udev,
1048 kfree(usbtouch->buffer); 1296 kfree(usbtouch->buffer);
1049} 1297}
1050 1298
1299static struct usb_endpoint_descriptor *
1300usbtouch_get_input_endpoint(struct usb_host_interface *interface)
1301{
1302 int i;
1303
1304 for (i = 0; i < interface->desc.bNumEndpoints; i++)
1305 if (usb_endpoint_dir_in(&interface->endpoint[i].desc))
1306 return &interface->endpoint[i].desc;
1307
1308 return NULL;
1309}
1051 1310
1052static int usbtouch_probe(struct usb_interface *intf, 1311static int usbtouch_probe(struct usb_interface *intf,
1053 const struct usb_device_id *id) 1312 const struct usb_device_id *id)
1054{ 1313{
1055 struct usbtouch_usb *usbtouch; 1314 struct usbtouch_usb *usbtouch;
1056 struct input_dev *input_dev; 1315 struct input_dev *input_dev;
1057 struct usb_host_interface *interface;
1058 struct usb_endpoint_descriptor *endpoint; 1316 struct usb_endpoint_descriptor *endpoint;
1059 struct usb_device *udev = interface_to_usbdev(intf); 1317 struct usb_device *udev = interface_to_usbdev(intf);
1060 struct usbtouch_device_info *type; 1318 struct usbtouch_device_info *type;
@@ -1064,8 +1322,9 @@ static int usbtouch_probe(struct usb_interface *intf,
1064 if (id->driver_info == DEVTYPE_IGNORE) 1322 if (id->driver_info == DEVTYPE_IGNORE)
1065 return -ENODEV; 1323 return -ENODEV;
1066 1324
1067 interface = intf->cur_altsetting; 1325 endpoint = usbtouch_get_input_endpoint(intf->cur_altsetting);
1068 endpoint = &interface->endpoint[0].desc; 1326 if (!endpoint)
1327 return -ENXIO;
1069 1328
1070 usbtouch = kzalloc(sizeof(struct usbtouch_usb), GFP_KERNEL); 1329 usbtouch = kzalloc(sizeof(struct usbtouch_usb), GFP_KERNEL);
1071 input_dev = input_allocate_device(); 1330 input_dev = input_allocate_device();
@@ -1094,7 +1353,7 @@ static int usbtouch_probe(struct usb_interface *intf,
1094 goto out_free_buffers; 1353 goto out_free_buffers;
1095 } 1354 }
1096 1355
1097 usbtouch->udev = udev; 1356 usbtouch->interface = intf;
1098 usbtouch->input = input_dev; 1357 usbtouch->input = input_dev;
1099 1358
1100 if (udev->manufacturer) 1359 if (udev->manufacturer)
@@ -1133,12 +1392,18 @@ static int usbtouch_probe(struct usb_interface *intf,
1133 input_set_abs_params(input_dev, ABS_PRESSURE, type->min_press, 1392 input_set_abs_params(input_dev, ABS_PRESSURE, type->min_press,
1134 type->max_press, 0, 0); 1393 type->max_press, 0, 0);
1135 1394
1136 usb_fill_int_urb(usbtouch->irq, usbtouch->udev, 1395 if (usb_endpoint_type(endpoint) == USB_ENDPOINT_XFER_INT)
1137 usb_rcvintpipe(usbtouch->udev, endpoint->bEndpointAddress), 1396 usb_fill_int_urb(usbtouch->irq, udev,
1397 usb_rcvintpipe(udev, endpoint->bEndpointAddress),
1138 usbtouch->data, type->rept_size, 1398 usbtouch->data, type->rept_size,
1139 usbtouch_irq, usbtouch, endpoint->bInterval); 1399 usbtouch_irq, usbtouch, endpoint->bInterval);
1400 else
1401 usb_fill_bulk_urb(usbtouch->irq, udev,
1402 usb_rcvbulkpipe(udev, endpoint->bEndpointAddress),
1403 usbtouch->data, type->rept_size,
1404 usbtouch_irq, usbtouch);
1140 1405
1141 usbtouch->irq->dev = usbtouch->udev; 1406 usbtouch->irq->dev = udev;
1142 usbtouch->irq->transfer_dma = usbtouch->data_dma; 1407 usbtouch->irq->transfer_dma = usbtouch->data_dma;
1143 usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; 1408 usbtouch->irq->transfer_flags |= URB_NO_TRANSFER_DMA_MAP;
1144 1409
@@ -1147,23 +1412,37 @@ static int usbtouch_probe(struct usb_interface *intf,
1147 err = type->init(usbtouch); 1412 err = type->init(usbtouch);
1148 if (err) { 1413 if (err) {
1149 dbg("%s - type->init() failed, err: %d", __func__, err); 1414 dbg("%s - type->init() failed, err: %d", __func__, err);
1150 goto out_free_buffers; 1415 goto out_free_urb;
1151 } 1416 }
1152 } 1417 }
1153 1418
1154 err = input_register_device(usbtouch->input); 1419 err = input_register_device(usbtouch->input);
1155 if (err) { 1420 if (err) {
1156 dbg("%s - input_register_device failed, err: %d", __func__, err); 1421 dbg("%s - input_register_device failed, err: %d", __func__, err);
1157 goto out_free_buffers; 1422 goto out_do_exit;
1158 } 1423 }
1159 1424
1160 usb_set_intfdata(intf, usbtouch); 1425 usb_set_intfdata(intf, usbtouch);
1161 1426
1162 if (usbtouch->type->irq_always) 1427 if (usbtouch->type->irq_always) {
1163 usb_submit_urb(usbtouch->irq, GFP_KERNEL); 1428 err = usb_submit_urb(usbtouch->irq, GFP_KERNEL);
1429 if (err) {
1430 err("%s - usb_submit_urb failed with result: %d",
1431 __func__, err);
1432 goto out_unregister_input;
1433 }
1434 }
1164 1435
1165 return 0; 1436 return 0;
1166 1437
1438out_unregister_input:
1439 input_unregister_device(input_dev);
1440 input_dev = NULL;
1441out_do_exit:
1442 if (type->exit)
1443 type->exit(usbtouch);
1444out_free_urb:
1445 usb_free_urb(usbtouch->irq);
1167out_free_buffers: 1446out_free_buffers:
1168 usbtouch_free_buffers(udev, usbtouch); 1447 usbtouch_free_buffers(udev, usbtouch);
1169out_free: 1448out_free:
@@ -1186,6 +1465,8 @@ static void usbtouch_disconnect(struct usb_interface *intf)
1186 /* this will stop IO via close */ 1465 /* this will stop IO via close */
1187 input_unregister_device(usbtouch->input); 1466 input_unregister_device(usbtouch->input);
1188 usb_free_urb(usbtouch->irq); 1467 usb_free_urb(usbtouch->irq);
1468 if (usbtouch->type->exit)
1469 usbtouch->type->exit(usbtouch);
1189 usbtouch_free_buffers(interface_to_usbdev(intf), usbtouch); 1470 usbtouch_free_buffers(interface_to_usbdev(intf), usbtouch);
1190 kfree(usbtouch); 1471 kfree(usbtouch);
1191} 1472}
diff --git a/drivers/input/touchscreen/zylonite-wm97xx.c b/drivers/input/touchscreen/zylonite-wm97xx.c
index eca54dbdf493..048849867643 100644
--- a/drivers/input/touchscreen/zylonite-wm97xx.c
+++ b/drivers/input/touchscreen/zylonite-wm97xx.c
@@ -118,6 +118,9 @@ static int wm97xx_acc_pen_down(struct wm97xx *wm)
118 if (pressure) 118 if (pressure)
119 p = MODR; 119 p = MODR;
120 120
121 dev_dbg(wm->dev, "Raw coordinates: x=%x, y=%x, p=%x\n",
122 x, y, p);
123
121 /* are samples valid */ 124 /* are samples valid */
122 if ((x & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_X || 125 if ((x & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_X ||
123 (y & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_Y || 126 (y & WM97XX_ADCSRC_MASK) != WM97XX_ADCSEL_Y ||
diff --git a/drivers/input/xen-kbdfront.c b/drivers/input/xen-kbdfront.c
index c721c0a23eb8..d30436fee476 100644
--- a/drivers/input/xen-kbdfront.c
+++ b/drivers/input/xen-kbdfront.c
@@ -321,7 +321,7 @@ InitWait:
321 } 321 }
322} 322}
323 323
324static struct xenbus_device_id xenkbd_ids[] = { 324static const struct xenbus_device_id xenkbd_ids[] = {
325 { "vkbd" }, 325 { "vkbd" },
326 { "" } 326 { "" }
327}; 327};
diff --git a/drivers/macintosh/Kconfig b/drivers/macintosh/Kconfig
index 3d906833948d..fd85bde283a0 100644
--- a/drivers/macintosh/Kconfig
+++ b/drivers/macintosh/Kconfig
@@ -171,8 +171,8 @@ config INPUT_ADBHID
171 If unsure, say Y. 171 If unsure, say Y.
172 172
173config MAC_EMUMOUSEBTN 173config MAC_EMUMOUSEBTN
174 bool "Support for mouse button 2+3 emulation" 174 tristate "Support for mouse button 2+3 emulation"
175 select INPUT 175 depends on SYSCTL && INPUT
176 help 176 help
177 This provides generic support for emulating the 2nd and 3rd mouse 177 This provides generic support for emulating the 2nd and 3rd mouse
178 button with keypresses. If you say Y here, the emulation is still 178 button with keypresses. If you say Y here, the emulation is still
@@ -184,6 +184,9 @@ config MAC_EMUMOUSEBTN
184 184
185 If you have an Apple machine with a 1-button mouse, say Y here. 185 If you have an Apple machine with a 1-button mouse, say Y here.
186 186
187 To compile this driver as a module, choose M here: the
188 module will be called mac_hid.
189
187config THERM_WINDTUNNEL 190config THERM_WINDTUNNEL
188 tristate "Support for thermal management on Windtunnel G4s" 191 tristate "Support for thermal management on Windtunnel G4s"
189 depends on I2C && I2C_POWERMAC && PPC_PMAC && !PPC_PMAC64 192 depends on I2C && I2C_POWERMAC && PPC_PMAC && !PPC_PMAC64
diff --git a/drivers/macintosh/mac_hid.c b/drivers/macintosh/mac_hid.c
index 7b4ef5bb556b..e943d2a29253 100644
--- a/drivers/macintosh/mac_hid.c
+++ b/drivers/macintosh/mac_hid.c
@@ -13,17 +13,197 @@
13#include <linux/sysctl.h> 13#include <linux/sysctl.h>
14#include <linux/input.h> 14#include <linux/input.h>
15#include <linux/module.h> 15#include <linux/module.h>
16#include <linux/kbd_kern.h>
17 16
17MODULE_LICENSE("GPL");
18 18
19static struct input_dev *emumousebtn;
20static int emumousebtn_input_register(void);
21static int mouse_emulate_buttons; 19static int mouse_emulate_buttons;
22static int mouse_button2_keycode = KEY_RIGHTCTRL; /* right control key */ 20static int mouse_button2_keycode = KEY_RIGHTCTRL; /* right control key */
23static int mouse_button3_keycode = KEY_RIGHTALT; /* right option key */ 21static int mouse_button3_keycode = KEY_RIGHTALT; /* right option key */
24static int mouse_last_keycode;
25 22
26#if defined(CONFIG_SYSCTL) 23static struct input_dev *mac_hid_emumouse_dev;
24
25static int mac_hid_create_emumouse(void)
26{
27 static struct lock_class_key mac_hid_emumouse_dev_event_class;
28 static struct lock_class_key mac_hid_emumouse_dev_mutex_class;
29 int err;
30
31 mac_hid_emumouse_dev = input_allocate_device();
32 if (!mac_hid_emumouse_dev)
33 return -ENOMEM;
34
35 lockdep_set_class(&mac_hid_emumouse_dev->event_lock,
36 &mac_hid_emumouse_dev_event_class);
37 lockdep_set_class(&mac_hid_emumouse_dev->mutex,
38 &mac_hid_emumouse_dev_mutex_class);
39
40 mac_hid_emumouse_dev->name = "Macintosh mouse button emulation";
41 mac_hid_emumouse_dev->id.bustype = BUS_ADB;
42 mac_hid_emumouse_dev->id.vendor = 0x0001;
43 mac_hid_emumouse_dev->id.product = 0x0001;
44 mac_hid_emumouse_dev->id.version = 0x0100;
45
46 mac_hid_emumouse_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
47 mac_hid_emumouse_dev->keybit[BIT_WORD(BTN_MOUSE)] =
48 BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
49 mac_hid_emumouse_dev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
50
51 err = input_register_device(mac_hid_emumouse_dev);
52 if (err) {
53 input_free_device(mac_hid_emumouse_dev);
54 mac_hid_emumouse_dev = NULL;
55 return err;
56 }
57
58 return 0;
59}
60
61static void mac_hid_destroy_emumouse(void)
62{
63 input_unregister_device(mac_hid_emumouse_dev);
64 mac_hid_emumouse_dev = NULL;
65}
66
67static bool mac_hid_emumouse_filter(struct input_handle *handle,
68 unsigned int type, unsigned int code,
69 int value)
70{
71 unsigned int btn;
72
73 if (type != EV_KEY)
74 return false;
75
76 if (code == mouse_button2_keycode)
77 btn = BTN_MIDDLE;
78 else if (code == mouse_button3_keycode)
79 btn = BTN_RIGHT;
80 else
81 return false;
82
83 input_report_key(mac_hid_emumouse_dev, btn, value);
84 input_sync(mac_hid_emumouse_dev);
85
86 return true;
87}
88
89static int mac_hid_emumouse_connect(struct input_handler *handler,
90 struct input_dev *dev,
91 const struct input_device_id *id)
92{
93 struct input_handle *handle;
94 int error;
95
96 /* Don't bind to ourselves */
97 if (dev == mac_hid_emumouse_dev)
98 return -ENODEV;
99
100 handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL);
101 if (!handle)
102 return -ENOMEM;
103
104 handle->dev = dev;
105 handle->handler = handler;
106 handle->name = "mac-button-emul";
107
108 error = input_register_handle(handle);
109 if (error) {
110 printk(KERN_ERR
111 "mac_hid: Failed to register button emulation handle, "
112 "error %d\n", error);
113 goto err_free;
114 }
115
116 error = input_open_device(handle);
117 if (error) {
118 printk(KERN_ERR
119 "mac_hid: Failed to open input device, error %d\n",
120 error);
121 goto err_unregister;
122 }
123
124 return 0;
125
126 err_unregister:
127 input_unregister_handle(handle);
128 err_free:
129 kfree(handle);
130 return error;
131}
132
133static void mac_hid_emumouse_disconnect(struct input_handle *handle)
134{
135 input_close_device(handle);
136 input_unregister_handle(handle);
137 kfree(handle);
138}
139
140static const struct input_device_id mac_hid_emumouse_ids[] = {
141 {
142 .flags = INPUT_DEVICE_ID_MATCH_EVBIT,
143 .evbit = { BIT_MASK(EV_KEY) },
144 },
145 { },
146};
147
148MODULE_DEVICE_TABLE(input, mac_hid_emumouse_ids);
149
150static struct input_handler mac_hid_emumouse_handler = {
151 .filter = mac_hid_emumouse_filter,
152 .connect = mac_hid_emumouse_connect,
153 .disconnect = mac_hid_emumouse_disconnect,
154 .name = "mac-button-emul",
155 .id_table = mac_hid_emumouse_ids,
156};
157
158static int mac_hid_start_emulation(void)
159{
160 int err;
161
162 err = mac_hid_create_emumouse();
163 if (err)
164 return err;
165
166 err = input_register_handler(&mac_hid_emumouse_handler);
167 if (err) {
168 mac_hid_destroy_emumouse();
169 return err;
170 }
171
172 return 0;
173}
174
175static void mac_hid_stop_emulation(void)
176{
177 input_unregister_handler(&mac_hid_emumouse_handler);
178 mac_hid_destroy_emumouse();
179}
180
181static int mac_hid_toggle_emumouse(ctl_table *table, int write,
182 void __user *buffer, size_t *lenp,
183 loff_t *ppos)
184{
185 int *valp = table->data;
186 int old_val = *valp;
187 int rc;
188
189 rc = proc_dointvec(table, write, buffer, lenp, ppos);
190
191 if (rc == 0 && write && *valp != old_val) {
192 if (*valp == 1)
193 rc = mac_hid_start_emulation();
194 else if (*valp == 0)
195 mac_hid_stop_emulation();
196 else
197 rc = -EINVAL;
198 }
199
200 /* Restore the old value in case of error */
201 if (rc)
202 *valp = old_val;
203
204 return rc;
205}
206
27/* file(s) in /proc/sys/dev/mac_hid */ 207/* file(s) in /proc/sys/dev/mac_hid */
28static ctl_table mac_hid_files[] = { 208static ctl_table mac_hid_files[] = {
29 { 209 {
@@ -31,7 +211,7 @@ static ctl_table mac_hid_files[] = {
31 .data = &mouse_emulate_buttons, 211 .data = &mouse_emulate_buttons,
32 .maxlen = sizeof(int), 212 .maxlen = sizeof(int),
33 .mode = 0644, 213 .mode = 0644,
34 .proc_handler = proc_dointvec, 214 .proc_handler = mac_hid_toggle_emumouse,
35 }, 215 },
36 { 216 {
37 .procname = "mouse_button2_keycode", 217 .procname = "mouse_button2_keycode",
@@ -74,75 +254,21 @@ static ctl_table mac_hid_root_dir[] = {
74 254
75static struct ctl_table_header *mac_hid_sysctl_header; 255static struct ctl_table_header *mac_hid_sysctl_header;
76 256
77#endif /* endif CONFIG_SYSCTL */ 257static int __init mac_hid_init(void)
78
79int mac_hid_mouse_emulate_buttons(int caller, unsigned int keycode, int down)
80{
81 switch (caller) {
82 case 1:
83 /* Called from keyboard.c */
84 if (mouse_emulate_buttons
85 && (keycode == mouse_button2_keycode
86 || keycode == mouse_button3_keycode)) {
87 if (mouse_emulate_buttons == 1) {
88 input_report_key(emumousebtn,
89 keycode == mouse_button2_keycode ? BTN_MIDDLE : BTN_RIGHT,
90 down);
91 input_sync(emumousebtn);
92 return 1;
93 }
94 mouse_last_keycode = down ? keycode : 0;
95 }
96 break;
97 }
98 return 0;
99}
100
101static struct lock_class_key emumousebtn_event_class;
102static struct lock_class_key emumousebtn_mutex_class;
103
104static int emumousebtn_input_register(void)
105{ 258{
106 int ret; 259 mac_hid_sysctl_header = register_sysctl_table(mac_hid_root_dir);
107 260 if (!mac_hid_sysctl_header)
108 emumousebtn = input_allocate_device();
109 if (!emumousebtn)
110 return -ENOMEM; 261 return -ENOMEM;
111 262
112 lockdep_set_class(&emumousebtn->event_lock, &emumousebtn_event_class); 263 return 0;
113 lockdep_set_class(&emumousebtn->mutex, &emumousebtn_mutex_class);
114
115 emumousebtn->name = "Macintosh mouse button emulation";
116 emumousebtn->id.bustype = BUS_ADB;
117 emumousebtn->id.vendor = 0x0001;
118 emumousebtn->id.product = 0x0001;
119 emumousebtn->id.version = 0x0100;
120
121 emumousebtn->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
122 emumousebtn->keybit[BIT_WORD(BTN_MOUSE)] = BIT_MASK(BTN_LEFT) |
123 BIT_MASK(BTN_MIDDLE) | BIT_MASK(BTN_RIGHT);
124 emumousebtn->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y);
125
126 ret = input_register_device(emumousebtn);
127 if (ret)
128 input_free_device(emumousebtn);
129
130 return ret;
131} 264}
265module_init(mac_hid_init);
132 266
133static int __init mac_hid_init(void) 267static void __exit mac_hid_exit(void)
134{ 268{
135 int err; 269 unregister_sysctl_table(mac_hid_sysctl_header);
136
137 err = emumousebtn_input_register();
138 if (err)
139 return err;
140
141#if defined(CONFIG_SYSCTL)
142 mac_hid_sysctl_header = register_sysctl_table(mac_hid_root_dir);
143#endif /* CONFIG_SYSCTL */
144 270
145 return 0; 271 if (mouse_emulate_buttons)
272 mac_hid_stop_emulation();
146} 273}
147 274module_exit(mac_hid_exit);
148device_initcall(mac_hid_init);
diff --git a/include/linux/gameport.h b/include/linux/gameport.h
index 1bc08541c2b9..48e68da097f6 100644
--- a/include/linux/gameport.h
+++ b/include/linux/gameport.h
@@ -46,7 +46,6 @@ struct gameport {
46 struct mutex drv_mutex; /* protects serio->drv so attributes can pin driver */ 46 struct mutex drv_mutex; /* protects serio->drv so attributes can pin driver */
47 47
48 struct device dev; 48 struct device dev;
49 unsigned int registered; /* port has been fully registered with driver core */
50 49
51 struct list_head node; 50 struct list_head node;
52}; 51};
diff --git a/include/linux/gpio_keys.h b/include/linux/gpio_keys.h
index 1289fa7623ca..cd0b3f30f48e 100644
--- a/include/linux/gpio_keys.h
+++ b/include/linux/gpio_keys.h
@@ -10,6 +10,7 @@ struct gpio_keys_button {
10 int type; /* input event type (EV_KEY, EV_SW) */ 10 int type; /* input event type (EV_KEY, EV_SW) */
11 int wakeup; /* configure the button as a wake-up source */ 11 int wakeup; /* configure the button as a wake-up source */
12 int debounce_interval; /* debounce ticks interval in msecs */ 12 int debounce_interval; /* debounce ticks interval in msecs */
13 bool can_disable;
13}; 14};
14 15
15struct gpio_keys_platform_data { 16struct gpio_keys_platform_data {
diff --git a/include/linux/input.h b/include/linux/input.h
index f44ee9114401..dc24effb6d0e 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -378,7 +378,7 @@ struct input_absinfo {
378#define KEY_WIMAX 246 378#define KEY_WIMAX 246
379#define KEY_RFKILL 247 /* Key that controls all radios */ 379#define KEY_RFKILL 247 /* Key that controls all radios */
380 380
381/* Range 248 - 255 is reserved for special needs of AT keyboard driver */ 381/* Code 255 is reserved for special needs of AT keyboard driver */
382 382
383#define BTN_MISC 0x100 383#define BTN_MISC 0x100
384#define BTN_0 0x100 384#define BTN_0 0x100
@@ -597,6 +597,7 @@ struct input_absinfo {
597#define KEY_NUMERIC_POUND 0x20b 597#define KEY_NUMERIC_POUND 0x20b
598 598
599#define KEY_CAMERA_FOCUS 0x210 599#define KEY_CAMERA_FOCUS 0x210
600#define KEY_WPS_BUTTON 0x211 /* WiFi Protected Setup key */
600 601
601#define BTN_TRIGGER_HAPPY 0x2c0 602#define BTN_TRIGGER_HAPPY 0x2c0
602#define BTN_TRIGGER_HAPPY1 0x2c0 603#define BTN_TRIGGER_HAPPY1 0x2c0
@@ -1242,6 +1243,10 @@ struct input_handle;
1242 * @event: event handler. This method is being called by input core with 1243 * @event: event handler. This method is being called by input core with
1243 * interrupts disabled and dev->event_lock spinlock held and so 1244 * interrupts disabled and dev->event_lock spinlock held and so
1244 * it may not sleep 1245 * it may not sleep
1246 * @filter: similar to @event; separates normal event handlers from
1247 * "filters".
1248 * @match: called after comparing device's id with handler's id_table
1249 * to perform fine-grained matching between device and handler
1245 * @connect: called when attaching a handler to an input device 1250 * @connect: called when attaching a handler to an input device
1246 * @disconnect: disconnects a handler from input device 1251 * @disconnect: disconnects a handler from input device
1247 * @start: starts handler for given handle. This function is called by 1252 * @start: starts handler for given handle. This function is called by
@@ -1253,8 +1258,6 @@ struct input_handle;
1253 * @name: name of the handler, to be shown in /proc/bus/input/handlers 1258 * @name: name of the handler, to be shown in /proc/bus/input/handlers
1254 * @id_table: pointer to a table of input_device_ids this driver can 1259 * @id_table: pointer to a table of input_device_ids this driver can
1255 * handle 1260 * handle
1256 * @blacklist: pointer to a table of input_device_ids this driver should
1257 * ignore even if they match @id_table
1258 * @h_list: list of input handles associated with the handler 1261 * @h_list: list of input handles associated with the handler
1259 * @node: for placing the driver onto input_handler_list 1262 * @node: for placing the driver onto input_handler_list
1260 * 1263 *
@@ -1263,6 +1266,11 @@ struct input_handle;
1263 * same time. All of them will get their copy of input event generated by 1266 * same time. All of them will get their copy of input event generated by
1264 * the device. 1267 * the device.
1265 * 1268 *
1269 * The very same structure is used to implement input filters. Input core
1270 * allows filters to run first and will not pass event to regular handlers
1271 * if any of the filters indicate that the event should be filtered (by
1272 * returning %true from their filter() method).
1273 *
1266 * Note that input core serializes calls to connect() and disconnect() 1274 * Note that input core serializes calls to connect() and disconnect()
1267 * methods. 1275 * methods.
1268 */ 1276 */
@@ -1271,6 +1279,8 @@ struct input_handler {
1271 void *private; 1279 void *private;
1272 1280
1273 void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value); 1281 void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
1282 bool (*filter)(struct input_handle *handle, unsigned int type, unsigned int code, int value);
1283 bool (*match)(struct input_handler *handler, struct input_dev *dev);
1274 int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id); 1284 int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id);
1275 void (*disconnect)(struct input_handle *handle); 1285 void (*disconnect)(struct input_handle *handle);
1276 void (*start)(struct input_handle *handle); 1286 void (*start)(struct input_handle *handle);
@@ -1280,7 +1290,6 @@ struct input_handler {
1280 const char *name; 1290 const char *name;
1281 1291
1282 const struct input_device_id *id_table; 1292 const struct input_device_id *id_table;
1283 const struct input_device_id *blacklist;
1284 1293
1285 struct list_head h_list; 1294 struct list_head h_list;
1286 struct list_head node; 1295 struct list_head node;
diff --git a/include/linux/input/sh_keysc.h b/include/linux/input/sh_keysc.h
index c211b5cf08e6..649dc7f12925 100644
--- a/include/linux/input/sh_keysc.h
+++ b/include/linux/input/sh_keysc.h
@@ -1,14 +1,15 @@
1#ifndef __SH_KEYSC_H__ 1#ifndef __SH_KEYSC_H__
2#define __SH_KEYSC_H__ 2#define __SH_KEYSC_H__
3 3
4#define SH_KEYSC_MAXKEYS 30 4#define SH_KEYSC_MAXKEYS 49
5 5
6struct sh_keysc_info { 6struct sh_keysc_info {
7 enum { SH_KEYSC_MODE_1, SH_KEYSC_MODE_2, SH_KEYSC_MODE_3 } mode; 7 enum { SH_KEYSC_MODE_1, SH_KEYSC_MODE_2, SH_KEYSC_MODE_3,
8 SH_KEYSC_MODE_4, SH_KEYSC_MODE_5, SH_KEYSC_MODE_6 } mode;
8 int scan_timing; /* 0 -> 7, see KYCR1, SCN[2:0] */ 9 int scan_timing; /* 0 -> 7, see KYCR1, SCN[2:0] */
9 int delay; 10 int delay;
10 int kycr2_delay; 11 int kycr2_delay;
11 int keycodes[SH_KEYSC_MAXKEYS]; 12 int keycodes[SH_KEYSC_MAXKEYS]; /* KEYIN * KEYOUT */
12}; 13};
13 14
14#endif /* __SH_KEYSC_H__ */ 15#endif /* __SH_KEYSC_H__ */
diff --git a/include/linux/kbd_kern.h b/include/linux/kbd_kern.h
index 8bdb16bfe5fb..506ad20c18f8 100644
--- a/include/linux/kbd_kern.h
+++ b/include/linux/kbd_kern.h
@@ -161,7 +161,4 @@ static inline void con_schedule_flip(struct tty_struct *t)
161 schedule_delayed_work(&t->buf.work, 0); 161 schedule_delayed_work(&t->buf.work, 0);
162} 162}
163 163
164/* mac_hid.c */
165extern int mac_hid_mouse_emulate_buttons(int, unsigned int, int);
166
167#endif 164#endif
diff --git a/include/linux/serio.h b/include/linux/serio.h
index 813d26c247ec..64b473066b9a 100644
--- a/include/linux/serio.h
+++ b/include/linux/serio.h
@@ -30,7 +30,6 @@ struct serio {
30 char phys[32]; 30 char phys[32];
31 31
32 bool manual_bind; 32 bool manual_bind;
33 bool registered; /* port has been fully registered with driver core */
34 33
35 struct serio_device_id id; 34 struct serio_device_id id;
36 35