diff options
author | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-05-30 19:16:45 -0400 |
---|---|---|
committer | Andrea Bastoni <bastoni@cs.unc.edu> | 2010-05-30 19:16:45 -0400 |
commit | ada47b5fe13d89735805b566185f4885f5a3f750 (patch) | |
tree | 644b88f8a71896307d71438e9b3af49126ffb22b /drivers/input/joystick | |
parent | 43e98717ad40a4ae64545b5ba047c7b86aa44f4f (diff) | |
parent | 3280f21d43ee541f97f8cda5792150d2dbec20d5 (diff) |
Merge branch 'wip-2.6.34' into old-private-masterarchived-private-master
Diffstat (limited to 'drivers/input/joystick')
-rw-r--r-- | drivers/input/joystick/Kconfig | 1 | ||||
-rw-r--r-- | drivers/input/joystick/db9.c | 1 | ||||
-rw-r--r-- | drivers/input/joystick/gamecon.c | 667 | ||||
-rw-r--r-- | drivers/input/joystick/gf2k.c | 2 | ||||
-rw-r--r-- | drivers/input/joystick/iforce/iforce-main.c | 35 | ||||
-rw-r--r-- | drivers/input/joystick/iforce/iforce-usb.c | 30 | ||||
-rw-r--r-- | drivers/input/joystick/iforce/iforce.h | 2 | ||||
-rw-r--r-- | drivers/input/joystick/turbografx.c | 1 | ||||
-rw-r--r-- | drivers/input/joystick/xpad.c | 254 |
9 files changed, 622 insertions, 371 deletions
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 | |||
221 | config JOYSTICK_GAMECON | 221 | config 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/db9.c b/drivers/input/joystick/db9.c index 523959484753..8e7de5c7754f 100644 --- a/drivers/input/joystick/db9.c +++ b/drivers/input/joystick/db9.c | |||
@@ -36,6 +36,7 @@ | |||
36 | #include <linux/parport.h> | 36 | #include <linux/parport.h> |
37 | #include <linux/input.h> | 37 | #include <linux/input.h> |
38 | #include <linux/mutex.h> | 38 | #include <linux/mutex.h> |
39 | #include <linux/slab.h> | ||
39 | 40 | ||
40 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); | 41 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); |
41 | MODULE_DESCRIPTION("Atari, Amstrad, Commodore, Amiga, Sega, etc. joystick driver"); | 42 | MODULE_DESCRIPTION("Atari, Amstrad, Commodore, Amiga, Sega, etc. joystick driver"); |
diff --git a/drivers/input/joystick/gamecon.c b/drivers/input/joystick/gamecon.c index 07a32aff5a31..fbd62abb66f9 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> |
@@ -37,6 +39,7 @@ | |||
37 | #include <linux/parport.h> | 39 | #include <linux/parport.h> |
38 | #include <linux/input.h> | 40 | #include <linux/input.h> |
39 | #include <linux/mutex.h> | 41 | #include <linux/mutex.h> |
42 | #include <linux/slab.h> | ||
40 | 43 | ||
41 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); | 44 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); |
42 | MODULE_DESCRIPTION("NES, SNES, N64, MultiSystem, PSX gamepad driver"); | 45 | MODULE_DESCRIPTION("NES, SNES, N64, MultiSystem, PSX gamepad driver"); |
@@ -61,48 +64,73 @@ MODULE_PARM_DESC(map3, "Describes third set of devices"); | |||
61 | 64 | ||
62 | /* see also gs_psx_delay parameter in PSX support section */ | 65 | /* see also gs_psx_delay parameter in PSX support section */ |
63 | 66 | ||
64 | #define GC_SNES 1 | 67 | enum gc_type { |
65 | #define GC_NES 2 | 68 | GC_NONE = 0, |
66 | #define GC_NES4 3 | 69 | GC_SNES, |
67 | #define GC_MULTI 4 | 70 | GC_NES, |
68 | #define GC_MULTI2 5 | 71 | GC_NES4, |
69 | #define GC_N64 6 | 72 | GC_MULTI, |
70 | #define GC_PSX 7 | 73 | GC_MULTI2, |
71 | #define GC_DDR 8 | 74 | GC_N64, |
72 | #define GC_SNESMOUSE 9 | 75 | GC_PSX, |
73 | 76 | GC_DDR, | |
74 | #define GC_MAX 9 | 77 | GC_SNESMOUSE, |
78 | GC_MAX | ||
79 | }; | ||
75 | 80 | ||
76 | #define GC_REFRESH_TIME HZ/100 | 81 | #define GC_REFRESH_TIME HZ/100 |
77 | 82 | ||
83 | struct gc_pad { | ||
84 | struct input_dev *dev; | ||
85 | enum gc_type type; | ||
86 | char phys[32]; | ||
87 | }; | ||
88 | |||
78 | struct gc { | 89 | struct gc { |
79 | struct pardevice *pd; | 90 | struct pardevice *pd; |
91 | struct gc_pad pads[GC_MAX_DEVICES]; | ||
80 | struct input_dev *dev[GC_MAX_DEVICES]; | 92 | struct input_dev *dev[GC_MAX_DEVICES]; |
81 | struct timer_list timer; | 93 | struct timer_list timer; |
82 | unsigned char pads[GC_MAX + 1]; | 94 | int pad_count[GC_MAX]; |
83 | int used; | 95 | int used; |
84 | struct mutex mutex; | 96 | struct mutex mutex; |
85 | char phys[GC_MAX_DEVICES][32]; | 97 | }; |
98 | |||
99 | struct gc_subdev { | ||
100 | unsigned int idx; | ||
86 | }; | 101 | }; |
87 | 102 | ||
88 | static struct gc *gc_base[3]; | 103 | static struct gc *gc_base[3]; |
89 | 104 | ||
90 | static int gc_status_bit[] = { 0x40, 0x80, 0x20, 0x10, 0x08 }; | 105 | static const int gc_status_bit[] = { 0x40, 0x80, 0x20, 0x10, 0x08 }; |
106 | |||
107 | static const char *gc_names[] = { | ||
108 | NULL, "SNES pad", "NES pad", "NES FourPort", "Multisystem joystick", | ||
109 | "Multisystem 2-button joystick", "N64 controller", "PSX controller", | ||
110 | "PSX DDR controller", "SNES mouse" | ||
111 | }; | ||
91 | 112 | ||
92 | static 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 | /* | 113 | /* |
96 | * N64 support. | 114 | * N64 support. |
97 | */ | 115 | */ |
98 | 116 | ||
99 | static unsigned char gc_n64_bytes[] = { 0, 1, 13, 15, 14, 12, 10, 11, 2, 3 }; | 117 | static const unsigned char gc_n64_bytes[] = { 0, 1, 13, 15, 14, 12, 10, 11, 2, 3 }; |
100 | static short gc_n64_btn[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_TRIGGER, BTN_START }; | 118 | static const short gc_n64_btn[] = { |
119 | BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, | ||
120 | BTN_TL, BTN_TR, BTN_TRIGGER, BTN_START | ||
121 | }; | ||
101 | 122 | ||
102 | #define GC_N64_LENGTH 32 /* N64 bit length, not including stop bit */ | 123 | #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 */ | 124 | #define GC_N64_STOP_LENGTH 5 /* Length of encoded stop bit */ |
125 | #define GC_N64_CMD_00 0x11111111UL | ||
126 | #define GC_N64_CMD_01 0xd1111111UL | ||
127 | #define GC_N64_CMD_03 0xdd111111UL | ||
128 | #define GC_N64_CMD_1b 0xdd1dd111UL | ||
129 | #define GC_N64_CMD_c0 0x111111ddUL | ||
130 | #define GC_N64_CMD_80 0x1111111dUL | ||
131 | #define GC_N64_STOP_BIT 0x1d /* Encoded stop bit */ | ||
132 | #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) */ | 133 | #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) */ | 134 | #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 */ | 135 | /* GC_N64_DWS > 24 is known to fail */ |
108 | #define GC_N64_POWER_W 0xe2 /* power during write (transmit request) */ | 136 | #define GC_N64_POWER_W 0xe2 /* power during write (transmit request) */ |
@@ -114,8 +142,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 */ | 142 | #define GC_N64_CLOCK 0x02 /* clock bits for read */ |
115 | 143 | ||
116 | /* | 144 | /* |
145 | * Used for rumble code. | ||
146 | */ | ||
147 | |||
148 | /* Send encoded command */ | ||
149 | static void gc_n64_send_command(struct gc *gc, unsigned long cmd, | ||
150 | unsigned char target) | ||
151 | { | ||
152 | struct parport *port = gc->pd->port; | ||
153 | int i; | ||
154 | |||
155 | for (i = 0; i < GC_N64_LENGTH; i++) { | ||
156 | unsigned char data = (cmd >> i) & 1 ? target : 0; | ||
157 | parport_write_data(port, GC_N64_POWER_W | data); | ||
158 | udelay(GC_N64_DWS); | ||
159 | } | ||
160 | } | ||
161 | |||
162 | /* Send stop bit */ | ||
163 | static void gc_n64_send_stop_bit(struct gc *gc, unsigned char target) | ||
164 | { | ||
165 | struct parport *port = gc->pd->port; | ||
166 | int i; | ||
167 | |||
168 | for (i = 0; i < GC_N64_STOP_LENGTH; i++) { | ||
169 | unsigned char data = (GC_N64_STOP_BIT >> i) & 1 ? target : 0; | ||
170 | parport_write_data(port, GC_N64_POWER_W | data); | ||
171 | udelay(GC_N64_DWS); | ||
172 | } | ||
173 | } | ||
174 | |||
175 | /* | ||
117 | * gc_n64_read_packet() reads an N64 packet. | 176 | * 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. | 177 | * Each pad uses one bit per byte. So all pads connected to this port |
178 | * are read in parallel. | ||
119 | */ | 179 | */ |
120 | 180 | ||
121 | static void gc_n64_read_packet(struct gc *gc, unsigned char *data) | 181 | static void gc_n64_read_packet(struct gc *gc, unsigned char *data) |
@@ -128,14 +188,13 @@ static void gc_n64_read_packet(struct gc *gc, unsigned char *data) | |||
128 | */ | 188 | */ |
129 | 189 | ||
130 | local_irq_save(flags); | 190 | local_irq_save(flags); |
131 | for (i = 0; i < GC_N64_REQUEST_LENGTH; i++) { | 191 | 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)); | 192 | gc_n64_send_stop_bit(gc, GC_N64_OUT); |
133 | udelay(GC_N64_DWS); | ||
134 | } | ||
135 | local_irq_restore(flags); | 193 | local_irq_restore(flags); |
136 | 194 | ||
137 | /* | 195 | /* |
138 | * Wait for the pad response to be loaded into the 33-bit register of the adapter | 196 | * Wait for the pad response to be loaded into the 33-bit register |
197 | * of the adapter. | ||
139 | */ | 198 | */ |
140 | 199 | ||
141 | udelay(GC_N64_DELAY); | 200 | udelay(GC_N64_DELAY); |
@@ -146,13 +205,15 @@ static void gc_n64_read_packet(struct gc *gc, unsigned char *data) | |||
146 | 205 | ||
147 | for (i = 0; i < GC_N64_LENGTH; i++) { | 206 | for (i = 0; i < GC_N64_LENGTH; i++) { |
148 | parport_write_data(gc->pd->port, GC_N64_POWER_R); | 207 | parport_write_data(gc->pd->port, GC_N64_POWER_R); |
208 | udelay(2); | ||
149 | data[i] = parport_read_status(gc->pd->port); | 209 | data[i] = parport_read_status(gc->pd->port); |
150 | parport_write_data(gc->pd->port, GC_N64_POWER_R | GC_N64_CLOCK); | 210 | parport_write_data(gc->pd->port, GC_N64_POWER_R | GC_N64_CLOCK); |
151 | } | 211 | } |
152 | 212 | ||
153 | /* | 213 | /* |
154 | * We must wait 200 ms here for the controller to reinitialize before the next read request. | 214 | * 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. | 215 | * the next read request. No worries as long as gc_read is polled less |
216 | * frequently than this. | ||
156 | */ | 217 | */ |
157 | 218 | ||
158 | } | 219 | } |
@@ -160,45 +221,112 @@ static void gc_n64_read_packet(struct gc *gc, unsigned char *data) | |||
160 | static void gc_n64_process_packet(struct gc *gc) | 221 | static void gc_n64_process_packet(struct gc *gc) |
161 | { | 222 | { |
162 | unsigned char data[GC_N64_LENGTH]; | 223 | unsigned char data[GC_N64_LENGTH]; |
163 | signed char axes[2]; | ||
164 | struct input_dev *dev; | 224 | struct input_dev *dev; |
165 | int i, j, s; | 225 | int i, j, s; |
226 | signed char x, y; | ||
166 | 227 | ||
167 | gc_n64_read_packet(gc, data); | 228 | gc_n64_read_packet(gc, data); |
168 | 229 | ||
169 | for (i = 0; i < GC_MAX_DEVICES; i++) { | 230 | for (i = 0; i < GC_MAX_DEVICES; i++) { |
170 | 231 | ||
171 | dev = gc->dev[i]; | 232 | if (gc->pads[i].type != GC_N64) |
172 | if (!dev) | ||
173 | continue; | 233 | continue; |
174 | 234 | ||
235 | dev = gc->pads[i].dev; | ||
175 | s = gc_status_bit[i]; | 236 | s = gc_status_bit[i]; |
176 | 237 | ||
177 | if (s & gc->pads[GC_N64] & ~(data[8] | data[9])) { | 238 | if (s & ~(data[8] | data[9])) { |
178 | 239 | ||
179 | axes[0] = axes[1] = 0; | 240 | x = y = 0; |
180 | 241 | ||
181 | for (j = 0; j < 8; j++) { | 242 | for (j = 0; j < 8; j++) { |
182 | if (data[23 - j] & s) | 243 | if (data[23 - j] & s) |
183 | axes[0] |= 1 << j; | 244 | x |= 1 << j; |
184 | if (data[31 - j] & s) | 245 | if (data[31 - j] & s) |
185 | axes[1] |= 1 << j; | 246 | y |= 1 << j; |
186 | } | 247 | } |
187 | 248 | ||
188 | input_report_abs(dev, ABS_X, axes[0]); | 249 | input_report_abs(dev, ABS_X, x); |
189 | input_report_abs(dev, ABS_Y, -axes[1]); | 250 | input_report_abs(dev, ABS_Y, -y); |
190 | 251 | ||
191 | input_report_abs(dev, ABS_HAT0X, !(s & data[6]) - !(s & data[7])); | 252 | input_report_abs(dev, ABS_HAT0X, |
192 | input_report_abs(dev, ABS_HAT0Y, !(s & data[4]) - !(s & data[5])); | 253 | !(s & data[6]) - !(s & data[7])); |
254 | input_report_abs(dev, ABS_HAT0Y, | ||
255 | !(s & data[4]) - !(s & data[5])); | ||
193 | 256 | ||
194 | for (j = 0; j < 10; j++) | 257 | for (j = 0; j < 10; j++) |
195 | input_report_key(dev, gc_n64_btn[j], s & data[gc_n64_bytes[j]]); | 258 | input_report_key(dev, gc_n64_btn[j], |
259 | s & data[gc_n64_bytes[j]]); | ||
196 | 260 | ||
197 | input_sync(dev); | 261 | input_sync(dev); |
198 | } | 262 | } |
199 | } | 263 | } |
200 | } | 264 | } |
201 | 265 | ||
266 | static int gc_n64_play_effect(struct input_dev *dev, void *data, | ||
267 | struct ff_effect *effect) | ||
268 | { | ||
269 | int i; | ||
270 | unsigned long flags; | ||
271 | struct gc *gc = input_get_drvdata(dev); | ||
272 | struct gc_subdev *sdev = data; | ||
273 | unsigned char target = 1 << sdev->idx; /* select desired pin */ | ||
274 | |||
275 | if (effect->type == FF_RUMBLE) { | ||
276 | struct ff_rumble_effect *rumble = &effect->u.rumble; | ||
277 | unsigned int cmd = | ||
278 | rumble->strong_magnitude || rumble->weak_magnitude ? | ||
279 | GC_N64_CMD_01 : GC_N64_CMD_00; | ||
280 | |||
281 | local_irq_save(flags); | ||
282 | |||
283 | /* Init Rumble - 0x03, 0x80, 0x01, (34)0x80 */ | ||
284 | gc_n64_send_command(gc, GC_N64_CMD_03, target); | ||
285 | gc_n64_send_command(gc, GC_N64_CMD_80, target); | ||
286 | gc_n64_send_command(gc, GC_N64_CMD_01, target); | ||
287 | for (i = 0; i < 32; i++) | ||
288 | gc_n64_send_command(gc, GC_N64_CMD_80, target); | ||
289 | gc_n64_send_stop_bit(gc, target); | ||
290 | |||
291 | udelay(GC_N64_DELAY); | ||
292 | |||
293 | /* Now start or stop it - 0x03, 0xc0, 0zx1b, (32)0x01/0x00 */ | ||
294 | gc_n64_send_command(gc, GC_N64_CMD_03, target); | ||
295 | gc_n64_send_command(gc, GC_N64_CMD_c0, target); | ||
296 | gc_n64_send_command(gc, GC_N64_CMD_1b, target); | ||
297 | for (i = 0; i < 32; i++) | ||
298 | gc_n64_send_command(gc, cmd, target); | ||
299 | gc_n64_send_stop_bit(gc, target); | ||
300 | |||
301 | local_irq_restore(flags); | ||
302 | |||
303 | } | ||
304 | |||
305 | return 0; | ||
306 | } | ||
307 | |||
308 | static int __init gc_n64_init_ff(struct input_dev *dev, int i) | ||
309 | { | ||
310 | struct gc_subdev *sdev; | ||
311 | int err; | ||
312 | |||
313 | sdev = kmalloc(sizeof(*sdev), GFP_KERNEL); | ||
314 | if (!sdev) | ||
315 | return -ENOMEM; | ||
316 | |||
317 | sdev->idx = i; | ||
318 | |||
319 | input_set_capability(dev, EV_FF, FF_RUMBLE); | ||
320 | |||
321 | err = input_ff_create_memless(dev, sdev, gc_n64_play_effect); | ||
322 | if (err) { | ||
323 | kfree(sdev); | ||
324 | return err; | ||
325 | } | ||
326 | |||
327 | return 0; | ||
328 | } | ||
329 | |||
202 | /* | 330 | /* |
203 | * NES/SNES support. | 331 | * NES/SNES support. |
204 | */ | 332 | */ |
@@ -214,9 +342,11 @@ static void gc_n64_process_packet(struct gc *gc) | |||
214 | #define GC_NES_CLOCK 0x01 | 342 | #define GC_NES_CLOCK 0x01 |
215 | #define GC_NES_LATCH 0x02 | 343 | #define GC_NES_LATCH 0x02 |
216 | 344 | ||
217 | static unsigned char gc_nes_bytes[] = { 0, 1, 2, 3 }; | 345 | static const unsigned char gc_nes_bytes[] = { 0, 1, 2, 3 }; |
218 | static unsigned char gc_snes_bytes[] = { 8, 0, 2, 3, 9, 1, 10, 11 }; | 346 | static const unsigned char gc_snes_bytes[] = { 8, 0, 2, 3, 9, 1, 10, 11 }; |
219 | static short gc_snes_btn[] = { BTN_A, BTN_B, BTN_SELECT, BTN_START, BTN_X, BTN_Y, BTN_TL, BTN_TR }; | 347 | static const short gc_snes_btn[] = { |
348 | BTN_A, BTN_B, BTN_SELECT, BTN_START, BTN_X, BTN_Y, BTN_TL, BTN_TR | ||
349 | }; | ||
220 | 350 | ||
221 | /* | 351 | /* |
222 | * gc_nes_read_packet() reads a NES/SNES packet. | 352 | * gc_nes_read_packet() reads a NES/SNES packet. |
@@ -244,40 +374,51 @@ static void gc_nes_read_packet(struct gc *gc, int length, unsigned char *data) | |||
244 | static void gc_nes_process_packet(struct gc *gc) | 374 | static void gc_nes_process_packet(struct gc *gc) |
245 | { | 375 | { |
246 | unsigned char data[GC_SNESMOUSE_LENGTH]; | 376 | unsigned char data[GC_SNESMOUSE_LENGTH]; |
377 | struct gc_pad *pad; | ||
247 | struct input_dev *dev; | 378 | struct input_dev *dev; |
248 | int i, j, s, len; | 379 | int i, j, s, len; |
249 | char x_rel, y_rel; | 380 | char x_rel, y_rel; |
250 | 381 | ||
251 | len = gc->pads[GC_SNESMOUSE] ? GC_SNESMOUSE_LENGTH : | 382 | len = gc->pad_count[GC_SNESMOUSE] ? GC_SNESMOUSE_LENGTH : |
252 | (gc->pads[GC_SNES] ? GC_SNES_LENGTH : GC_NES_LENGTH); | 383 | (gc->pad_count[GC_SNES] ? GC_SNES_LENGTH : GC_NES_LENGTH); |
253 | 384 | ||
254 | gc_nes_read_packet(gc, len, data); | 385 | gc_nes_read_packet(gc, len, data); |
255 | 386 | ||
256 | for (i = 0; i < GC_MAX_DEVICES; i++) { | 387 | for (i = 0; i < GC_MAX_DEVICES; i++) { |
257 | 388 | ||
389 | pad = &gc->pads[i]; | ||
258 | dev = gc->dev[i]; | 390 | dev = gc->dev[i]; |
259 | if (!dev) | ||
260 | continue; | ||
261 | |||
262 | s = gc_status_bit[i]; | 391 | s = gc_status_bit[i]; |
263 | 392 | ||
264 | if (s & (gc->pads[GC_NES] | gc->pads[GC_SNES])) { | 393 | switch (pad->type) { |
394 | |||
395 | case GC_NES: | ||
396 | |||
265 | input_report_abs(dev, ABS_X, !(s & data[6]) - !(s & data[7])); | 397 | 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])); | 398 | input_report_abs(dev, ABS_Y, !(s & data[4]) - !(s & data[5])); |
267 | } | ||
268 | 399 | ||
269 | if (s & gc->pads[GC_NES]) | ||
270 | for (j = 0; j < 4; j++) | 400 | for (j = 0; j < 4; j++) |
271 | input_report_key(dev, gc_snes_btn[j], s & data[gc_nes_bytes[j]]); | 401 | input_report_key(dev, gc_snes_btn[j], |
402 | s & data[gc_nes_bytes[j]]); | ||
403 | input_sync(dev); | ||
404 | break; | ||
405 | |||
406 | case GC_SNES: | ||
407 | |||
408 | input_report_abs(dev, ABS_X, !(s & data[6]) - !(s & data[7])); | ||
409 | input_report_abs(dev, ABS_Y, !(s & data[4]) - !(s & data[5])); | ||
272 | 410 | ||
273 | if (s & gc->pads[GC_SNES]) | ||
274 | for (j = 0; j < 8; j++) | 411 | for (j = 0; j < 8; j++) |
275 | input_report_key(dev, gc_snes_btn[j], s & data[gc_snes_bytes[j]]); | 412 | input_report_key(dev, gc_snes_btn[j], |
413 | s & data[gc_snes_bytes[j]]); | ||
414 | input_sync(dev); | ||
415 | break; | ||
276 | 416 | ||
277 | if (s & gc->pads[GC_SNESMOUSE]) { | 417 | case GC_SNESMOUSE: |
278 | /* | 418 | /* |
279 | * The 4 unused bits from SNES controllers appear to be ID bits | 419 | * The 4 unused bits from SNES controllers appear |
280 | * so use them to make sure iwe are dealing with a mouse. | 420 | * to be ID bits so use them to make sure we are |
421 | * dealing with a mouse. | ||
281 | * gamepad is connected. This is important since | 422 | * gamepad is connected. This is important since |
282 | * my SNES gamepad sends 1's for bits 16-31, which | 423 | * my SNES gamepad sends 1's for bits 16-31, which |
283 | * cause the mouse pointer to quickly move to the | 424 | * cause the mouse pointer to quickly move to the |
@@ -310,9 +451,14 @@ static void gc_nes_process_packet(struct gc *gc) | |||
310 | y_rel = -y_rel; | 451 | y_rel = -y_rel; |
311 | input_report_rel(dev, REL_Y, y_rel); | 452 | input_report_rel(dev, REL_Y, y_rel); |
312 | } | 453 | } |
454 | |||
455 | input_sync(dev); | ||
313 | } | 456 | } |
457 | break; | ||
458 | |||
459 | default: | ||
460 | break; | ||
314 | } | 461 | } |
315 | input_sync(dev); | ||
316 | } | 462 | } |
317 | } | 463 | } |
318 | 464 | ||
@@ -340,29 +486,35 @@ static void gc_multi_read_packet(struct gc *gc, int length, unsigned char *data) | |||
340 | static void gc_multi_process_packet(struct gc *gc) | 486 | static void gc_multi_process_packet(struct gc *gc) |
341 | { | 487 | { |
342 | unsigned char data[GC_MULTI2_LENGTH]; | 488 | unsigned char data[GC_MULTI2_LENGTH]; |
489 | int data_len = gc->pad_count[GC_MULTI2] ? GC_MULTI2_LENGTH : GC_MULTI_LENGTH; | ||
490 | struct gc_pad *pad; | ||
343 | struct input_dev *dev; | 491 | struct input_dev *dev; |
344 | int i, s; | 492 | int i, s; |
345 | 493 | ||
346 | gc_multi_read_packet(gc, gc->pads[GC_MULTI2] ? GC_MULTI2_LENGTH : GC_MULTI_LENGTH, data); | 494 | gc_multi_read_packet(gc, data_len, data); |
347 | 495 | ||
348 | for (i = 0; i < GC_MAX_DEVICES; i++) { | 496 | for (i = 0; i < GC_MAX_DEVICES; i++) { |
349 | 497 | pad = &gc->pads[i]; | |
350 | dev = gc->dev[i]; | 498 | dev = pad->dev; |
351 | if (!dev) | ||
352 | continue; | ||
353 | |||
354 | s = gc_status_bit[i]; | 499 | s = gc_status_bit[i]; |
355 | 500 | ||
356 | if (s & (gc->pads[GC_MULTI] | gc->pads[GC_MULTI2])) { | 501 | switch (pad->type) { |
357 | input_report_abs(dev, ABS_X, !(s & data[2]) - !(s & data[3])); | 502 | 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]); | 503 | input_report_key(dev, BTN_THUMB, s & data[5]); |
504 | /* fall through */ | ||
364 | 505 | ||
365 | input_sync(dev); | 506 | case GC_MULTI: |
507 | input_report_abs(dev, ABS_X, | ||
508 | !(s & data[2]) - !(s & data[3])); | ||
509 | input_report_abs(dev, ABS_Y, | ||
510 | !(s & data[0]) - !(s & data[1])); | ||
511 | input_report_key(dev, BTN_TRIGGER, s & data[4]); | ||
512 | input_sync(dev); | ||
513 | break; | ||
514 | |||
515 | default: | ||
516 | break; | ||
517 | } | ||
366 | } | 518 | } |
367 | } | 519 | } |
368 | 520 | ||
@@ -398,30 +550,41 @@ static int gc_psx_delay = GC_PSX_DELAY; | |||
398 | module_param_named(psx_delay, gc_psx_delay, uint, 0); | 550 | module_param_named(psx_delay, gc_psx_delay, uint, 0); |
399 | MODULE_PARM_DESC(psx_delay, "Delay when accessing Sony PSX controller (usecs)"); | 551 | MODULE_PARM_DESC(psx_delay, "Delay when accessing Sony PSX controller (usecs)"); |
400 | 552 | ||
401 | static short gc_psx_abs[] = { ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_HAT0X, ABS_HAT0Y }; | 553 | static const short gc_psx_abs[] = { |
402 | static short gc_psx_btn[] = { BTN_TL, BTN_TR, BTN_TL2, BTN_TR2, BTN_A, BTN_B, BTN_X, BTN_Y, | 554 | ABS_X, ABS_Y, ABS_RX, ABS_RY, ABS_HAT0X, ABS_HAT0Y |
403 | BTN_START, BTN_SELECT, BTN_THUMBL, BTN_THUMBR }; | 555 | }; |
404 | static short gc_psx_ddr_btn[] = { BTN_0, BTN_1, BTN_2, BTN_3 }; | 556 | static const short gc_psx_btn[] = { |
557 | BTN_TL, BTN_TR, BTN_TL2, BTN_TR2, BTN_A, BTN_B, BTN_X, BTN_Y, | ||
558 | BTN_START, BTN_SELECT, BTN_THUMBL, BTN_THUMBR | ||
559 | }; | ||
560 | static const short gc_psx_ddr_btn[] = { BTN_0, BTN_1, BTN_2, BTN_3 }; | ||
405 | 561 | ||
406 | /* | 562 | /* |
407 | * gc_psx_command() writes 8bit command and reads 8bit data from | 563 | * gc_psx_command() writes 8bit command and reads 8bit data from |
408 | * the psx pad. | 564 | * the psx pad. |
409 | */ | 565 | */ |
410 | 566 | ||
411 | static void gc_psx_command(struct gc *gc, int b, unsigned char data[GC_MAX_DEVICES]) | 567 | static void gc_psx_command(struct gc *gc, int b, unsigned char *data) |
412 | { | 568 | { |
569 | struct parport *port = gc->pd->port; | ||
413 | int i, j, cmd, read; | 570 | int i, j, cmd, read; |
414 | 571 | ||
415 | for (i = 0; i < GC_MAX_DEVICES; i++) | 572 | memset(data, 0, GC_MAX_DEVICES); |
416 | data[i] = 0; | ||
417 | 573 | ||
418 | for (i = 0; i < GC_PSX_LENGTH; i++, b >>= 1) { | 574 | for (i = 0; i < GC_PSX_LENGTH; i++, b >>= 1) { |
419 | cmd = (b & 1) ? GC_PSX_COMMAND : 0; | 575 | cmd = (b & 1) ? GC_PSX_COMMAND : 0; |
420 | parport_write_data(gc->pd->port, cmd | GC_PSX_POWER); | 576 | parport_write_data(port, cmd | GC_PSX_POWER); |
421 | udelay(gc_psx_delay); | 577 | udelay(gc_psx_delay); |
422 | read = parport_read_status(gc->pd->port) ^ 0x80; | 578 | |
423 | for (j = 0; j < GC_MAX_DEVICES; j++) | 579 | 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; | 580 | |
581 | for (j = 0; j < GC_MAX_DEVICES; j++) { | ||
582 | struct gc_pad *pad = &gc->pads[i]; | ||
583 | |||
584 | if (pad->type == GC_PSX || pad->type == GC_DDR) | ||
585 | data[j] |= (read & gc_status_bit[j]) ? (1 << i) : 0; | ||
586 | } | ||
587 | |||
425 | parport_write_data(gc->pd->port, cmd | GC_PSX_CLOCK | GC_PSX_POWER); | 588 | parport_write_data(gc->pd->port, cmd | GC_PSX_CLOCK | GC_PSX_POWER); |
426 | udelay(gc_psx_delay); | 589 | udelay(gc_psx_delay); |
427 | } | 590 | } |
@@ -432,31 +595,40 @@ static void gc_psx_command(struct gc *gc, int b, unsigned char data[GC_MAX_DEVIC | |||
432 | * device identifier code. | 595 | * device identifier code. |
433 | */ | 596 | */ |
434 | 597 | ||
435 | static void gc_psx_read_packet(struct gc *gc, unsigned char data[GC_MAX_DEVICES][GC_PSX_BYTES], | 598 | static void gc_psx_read_packet(struct gc *gc, |
599 | unsigned char data[GC_MAX_DEVICES][GC_PSX_BYTES], | ||
436 | unsigned char id[GC_MAX_DEVICES]) | 600 | unsigned char id[GC_MAX_DEVICES]) |
437 | { | 601 | { |
438 | int i, j, max_len = 0; | 602 | int i, j, max_len = 0; |
439 | unsigned long flags; | 603 | unsigned long flags; |
440 | unsigned char data2[GC_MAX_DEVICES]; | 604 | unsigned char data2[GC_MAX_DEVICES]; |
441 | 605 | ||
442 | parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER); /* Select pad */ | 606 | /* Select pad */ |
607 | parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER); | ||
443 | udelay(gc_psx_delay); | 608 | udelay(gc_psx_delay); |
444 | parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_POWER); /* Deselect, begin command */ | 609 | /* Deselect, begin command */ |
610 | parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_POWER); | ||
445 | udelay(gc_psx_delay); | 611 | udelay(gc_psx_delay); |
446 | 612 | ||
447 | local_irq_save(flags); | 613 | local_irq_save(flags); |
448 | 614 | ||
449 | gc_psx_command(gc, 0x01, data2); /* Access pad */ | 615 | gc_psx_command(gc, 0x01, data2); /* Access pad */ |
450 | gc_psx_command(gc, 0x42, id); /* Get device ids */ | 616 | gc_psx_command(gc, 0x42, id); /* Get device ids */ |
451 | gc_psx_command(gc, 0, data2); /* Dump status */ | 617 | gc_psx_command(gc, 0, data2); /* Dump status */ |
618 | |||
619 | /* Find the longest pad */ | ||
620 | for (i = 0; i < GC_MAX_DEVICES; i++) { | ||
621 | struct gc_pad *pad = &gc->pads[i]; | ||
452 | 622 | ||
453 | for (i =0; i < GC_MAX_DEVICES; i++) /* Find the longest pad */ | 623 | if ((pad->type == GC_PSX || pad->type == GC_DDR) && |
454 | if((gc_status_bit[i] & (gc->pads[GC_PSX] | gc->pads[GC_DDR])) | 624 | GC_PSX_LEN(id[i]) > max_len && |
455 | && (GC_PSX_LEN(id[i]) > max_len) | 625 | 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]); | 626 | max_len = GC_PSX_LEN(id[i]); |
627 | } | ||
628 | } | ||
458 | 629 | ||
459 | for (i = 0; i < max_len; i++) { /* Read in all the data */ | 630 | /* Read in all the data */ |
631 | for (i = 0; i < max_len; i++) { | ||
460 | gc_psx_command(gc, 0, data2); | 632 | gc_psx_command(gc, 0, data2); |
461 | for (j = 0; j < GC_MAX_DEVICES; j++) | 633 | for (j = 0; j < GC_MAX_DEVICES; j++) |
462 | data[j][i] = data2[j]; | 634 | data[j][i] = data2[j]; |
@@ -466,86 +638,104 @@ static void gc_psx_read_packet(struct gc *gc, unsigned char data[GC_MAX_DEVICES] | |||
466 | 638 | ||
467 | parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER); | 639 | parport_write_data(gc->pd->port, GC_PSX_CLOCK | GC_PSX_SELECT | GC_PSX_POWER); |
468 | 640 | ||
469 | for(i = 0; i < GC_MAX_DEVICES; i++) /* Set id's to the real value */ | 641 | /* Set id's to the real value */ |
642 | for (i = 0; i < GC_MAX_DEVICES; i++) | ||
470 | id[i] = GC_PSX_ID(id[i]); | 643 | id[i] = GC_PSX_ID(id[i]); |
471 | } | 644 | } |
472 | 645 | ||
473 | static void gc_psx_process_packet(struct gc *gc) | 646 | static void gc_psx_report_one(struct gc_pad *pad, unsigned char psx_type, |
647 | unsigned char *data) | ||
474 | { | 648 | { |
475 | unsigned char data[GC_MAX_DEVICES][GC_PSX_BYTES]; | 649 | struct input_dev *dev = pad->dev; |
476 | unsigned char id[GC_MAX_DEVICES]; | 650 | int i; |
477 | struct input_dev *dev; | ||
478 | int i, j; | ||
479 | 651 | ||
480 | gc_psx_read_packet(gc, data, id); | 652 | switch (psx_type) { |
481 | 653 | ||
482 | for (i = 0; i < GC_MAX_DEVICES; i++) { | 654 | case GC_PSX_RUMBLE: |
483 | 655 | ||
484 | dev = gc->dev[i]; | 656 | input_report_key(dev, BTN_THUMBL, ~data[0] & 0x04); |
485 | if (!dev) | 657 | input_report_key(dev, BTN_THUMBR, ~data[0] & 0x02); |
486 | continue; | ||
487 | 658 | ||
488 | switch (id[i]) { | 659 | case GC_PSX_NEGCON: |
660 | case GC_PSX_ANALOG: | ||
489 | 661 | ||
490 | case GC_PSX_RUMBLE: | 662 | if (pad->type == GC_DDR) { |
663 | for (i = 0; i < 4; i++) | ||
664 | input_report_key(dev, gc_psx_ddr_btn[i], | ||
665 | ~data[0] & (0x10 << i)); | ||
666 | } else { | ||
667 | for (i = 0; i < 4; i++) | ||
668 | input_report_abs(dev, gc_psx_abs[i + 2], | ||
669 | data[i + 2]); | ||
491 | 670 | ||
492 | input_report_key(dev, BTN_THUMBL, ~data[i][0] & 0x04); | 671 | input_report_abs(dev, ABS_X, |
493 | input_report_key(dev, BTN_THUMBR, ~data[i][0] & 0x02); | 672 | !!(data[0] & 0x80) * 128 + !(data[0] & 0x20) * 127); |
673 | input_report_abs(dev, ABS_Y, | ||
674 | !!(data[0] & 0x10) * 128 + !(data[0] & 0x40) * 127); | ||
675 | } | ||
494 | 676 | ||
495 | case GC_PSX_NEGCON: | 677 | for (i = 0; i < 8; i++) |
496 | case GC_PSX_ANALOG: | 678 | input_report_key(dev, gc_psx_btn[i], ~data[1] & (1 << i)); |
497 | 679 | ||
498 | if (gc->pads[GC_DDR] & gc_status_bit[i]) { | 680 | input_report_key(dev, BTN_START, ~data[0] & 0x08); |
499 | for(j = 0; j < 4; j++) | 681 | 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 | 682 | ||
505 | input_report_abs(dev, ABS_X, 128 + !(data[i][0] & 0x20) * 127 - !(data[i][0] & 0x80) * 128); | 683 | input_sync(dev); |
506 | input_report_abs(dev, ABS_Y, 128 + !(data[i][0] & 0x40) * 127 - !(data[i][0] & 0x10) * 128); | ||
507 | } | ||
508 | 684 | ||
509 | for (j = 0; j < 8; j++) | 685 | break; |
510 | input_report_key(dev, gc_psx_btn[j], ~data[i][1] & (1 << j)); | ||
511 | 686 | ||
512 | input_report_key(dev, BTN_START, ~data[i][0] & 0x08); | 687 | case GC_PSX_NORMAL: |
513 | input_report_key(dev, BTN_SELECT, ~data[i][0] & 0x01); | ||
514 | 688 | ||
515 | input_sync(dev); | 689 | if (pad->type == GC_DDR) { |
690 | for (i = 0; i < 4; i++) | ||
691 | input_report_key(dev, gc_psx_ddr_btn[i], | ||
692 | ~data[0] & (0x10 << i)); | ||
693 | } else { | ||
694 | input_report_abs(dev, ABS_X, | ||
695 | !!(data[0] & 0x80) * 128 + !(data[0] & 0x20) * 127); | ||
696 | input_report_abs(dev, ABS_Y, | ||
697 | !!(data[0] & 0x10) * 128 + !(data[0] & 0x40) * 127); | ||
516 | 698 | ||
517 | break; | 699 | /* |
518 | 700 | * For some reason if the extra axes are left unset | |
519 | case GC_PSX_NORMAL: | 701 | * they drift. |
520 | if (gc->pads[GC_DDR] & gc_status_bit[i]) { | 702 | * for (i = 0; i < 4; i++) |
521 | for(j = 0; j < 4; j++) | 703 | 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)); | 704 | * This needs to be debugged properly, |
523 | } else { | 705 | * 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); | 706 | * in input_sync() |
525 | input_report_abs(dev, ABS_Y, 128 + !(data[i][0] & 0x40) * 127 - !(data[i][0] & 0x10) * 128); | 707 | * --vojtech |
526 | 708 | */ | |
527 | /* for some reason if the extra axes are left unset they drift */ | 709 | } |
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 | 710 | ||
536 | for (j = 0; j < 8; j++) | 711 | for (i = 0; i < 8; i++) |
537 | input_report_key(dev, gc_psx_btn[j], ~data[i][1] & (1 << j)); | 712 | input_report_key(dev, gc_psx_btn[i], ~data[1] & (1 << i)); |
538 | 713 | ||
539 | input_report_key(dev, BTN_START, ~data[i][0] & 0x08); | 714 | input_report_key(dev, BTN_START, ~data[0] & 0x08); |
540 | input_report_key(dev, BTN_SELECT, ~data[i][0] & 0x01); | 715 | input_report_key(dev, BTN_SELECT, ~data[0] & 0x01); |
541 | 716 | ||
542 | input_sync(dev); | 717 | input_sync(dev); |
543 | 718 | ||
544 | break; | 719 | break; |
545 | 720 | ||
546 | case 0: /* not a pad, ignore */ | 721 | default: /* not a pad, ignore */ |
547 | break; | 722 | break; |
548 | } | 723 | } |
724 | } | ||
725 | |||
726 | static void gc_psx_process_packet(struct gc *gc) | ||
727 | { | ||
728 | unsigned char data[GC_MAX_DEVICES][GC_PSX_BYTES]; | ||
729 | unsigned char id[GC_MAX_DEVICES]; | ||
730 | struct gc_pad *pad; | ||
731 | int i; | ||
732 | |||
733 | gc_psx_read_packet(gc, data, id); | ||
734 | |||
735 | for (i = 0; i < GC_MAX_DEVICES; i++) { | ||
736 | pad = &gc->pads[i]; | ||
737 | if (pad->type == GC_PSX || pad->type == GC_DDR) | ||
738 | gc_psx_report_one(pad, id[i], data[i]); | ||
549 | } | 739 | } |
550 | } | 740 | } |
551 | 741 | ||
@@ -561,28 +751,31 @@ static void gc_timer(unsigned long private) | |||
561 | * N64 pads - must be read first, any read confuses them for 200 us | 751 | * N64 pads - must be read first, any read confuses them for 200 us |
562 | */ | 752 | */ |
563 | 753 | ||
564 | if (gc->pads[GC_N64]) | 754 | if (gc->pad_count[GC_N64]) |
565 | gc_n64_process_packet(gc); | 755 | gc_n64_process_packet(gc); |
566 | 756 | ||
567 | /* | 757 | /* |
568 | * NES and SNES pads or mouse | 758 | * NES and SNES pads or mouse |
569 | */ | 759 | */ |
570 | 760 | ||
571 | if (gc->pads[GC_NES] || gc->pads[GC_SNES] || gc->pads[GC_SNESMOUSE]) | 761 | if (gc->pad_count[GC_NES] || |
762 | gc->pad_count[GC_SNES] || | ||
763 | gc->pad_count[GC_SNESMOUSE]) { | ||
572 | gc_nes_process_packet(gc); | 764 | gc_nes_process_packet(gc); |
765 | } | ||
573 | 766 | ||
574 | /* | 767 | /* |
575 | * Multi and Multi2 joysticks | 768 | * Multi and Multi2 joysticks |
576 | */ | 769 | */ |
577 | 770 | ||
578 | if (gc->pads[GC_MULTI] || gc->pads[GC_MULTI2]) | 771 | if (gc->pad_count[GC_MULTI] || gc->pad_count[GC_MULTI2]) |
579 | gc_multi_process_packet(gc); | 772 | gc_multi_process_packet(gc); |
580 | 773 | ||
581 | /* | 774 | /* |
582 | * PSX controllers | 775 | * PSX controllers |
583 | */ | 776 | */ |
584 | 777 | ||
585 | if (gc->pads[GC_PSX] || gc->pads[GC_DDR]) | 778 | if (gc->pad_count[GC_PSX] || gc->pad_count[GC_DDR]) |
586 | gc_psx_process_packet(gc); | 779 | gc_psx_process_packet(gc); |
587 | 780 | ||
588 | mod_timer(&gc->timer, jiffies + GC_REFRESH_TIME); | 781 | mod_timer(&gc->timer, jiffies + GC_REFRESH_TIME); |
@@ -622,25 +815,29 @@ static void gc_close(struct input_dev *dev) | |||
622 | 815 | ||
623 | static int __init gc_setup_pad(struct gc *gc, int idx, int pad_type) | 816 | static int __init gc_setup_pad(struct gc *gc, int idx, int pad_type) |
624 | { | 817 | { |
818 | struct gc_pad *pad = &gc->pads[idx]; | ||
625 | struct input_dev *input_dev; | 819 | struct input_dev *input_dev; |
626 | int i; | 820 | int i; |
821 | int err; | ||
627 | 822 | ||
628 | if (!pad_type) | 823 | if (pad_type < 1 || pad_type >= GC_MAX) { |
629 | return 0; | 824 | pr_err("Pad type %d unknown\n", pad_type); |
630 | |||
631 | if (pad_type < 1 || pad_type > GC_MAX) { | ||
632 | printk(KERN_WARNING "gamecon.c: Pad type %d unknown\n", pad_type); | ||
633 | return -EINVAL; | 825 | return -EINVAL; |
634 | } | 826 | } |
635 | 827 | ||
636 | gc->dev[idx] = input_dev = input_allocate_device(); | 828 | pad->dev = input_dev = input_allocate_device(); |
637 | if (!input_dev) { | 829 | if (!input_dev) { |
638 | printk(KERN_ERR "gamecon.c: Not enough memory for input device\n"); | 830 | pr_err("Not enough memory for input device\n"); |
639 | return -ENOMEM; | 831 | return -ENOMEM; |
640 | } | 832 | } |
641 | 833 | ||
834 | pad->type = pad_type; | ||
835 | |||
836 | snprintf(pad->phys, sizeof(pad->phys), | ||
837 | "%s/input%d", gc->pd->port->name, idx); | ||
838 | |||
642 | input_dev->name = gc_names[pad_type]; | 839 | input_dev->name = gc_names[pad_type]; |
643 | input_dev->phys = gc->phys[idx]; | 840 | input_dev->phys = pad->phys; |
644 | input_dev->id.bustype = BUS_PARPORT; | 841 | input_dev->id.bustype = BUS_PARPORT; |
645 | input_dev->id.vendor = 0x0001; | 842 | input_dev->id.vendor = 0x0001; |
646 | input_dev->id.product = pad_type; | 843 | input_dev->id.product = pad_type; |
@@ -659,61 +856,76 @@ static int __init gc_setup_pad(struct gc *gc, int idx, int pad_type) | |||
659 | } else | 856 | } else |
660 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); | 857 | input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); |
661 | 858 | ||
662 | gc->pads[0] |= gc_status_bit[idx]; | 859 | gc->pad_count[pad_type]++; |
663 | gc->pads[pad_type] |= gc_status_bit[idx]; | ||
664 | 860 | ||
665 | switch (pad_type) { | 861 | switch (pad_type) { |
666 | 862 | ||
667 | case GC_N64: | 863 | case GC_N64: |
668 | for (i = 0; i < 10; i++) | 864 | for (i = 0; i < 10; i++) |
669 | set_bit(gc_n64_btn[i], input_dev->keybit); | 865 | __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 | 866 | ||
705 | break; | 867 | for (i = 0; i < 2; i++) { |
868 | input_set_abs_params(input_dev, ABS_X + i, -127, 126, 0, 2); | ||
869 | input_set_abs_params(input_dev, ABS_HAT0X + i, -1, 1, 0, 0); | ||
870 | } | ||
706 | 871 | ||
707 | case GC_DDR: | 872 | err = gc_n64_init_ff(input_dev, idx); |
708 | for (i = 0; i < 4; i++) | 873 | if (err) { |
709 | set_bit(gc_psx_ddr_btn[i], input_dev->keybit); | 874 | pr_warning("Failed to initiate rumble for N64 device %d\n", idx); |
710 | for (i = 0; i < 12; i++) | 875 | goto err_free_dev; |
711 | set_bit(gc_psx_btn[i], input_dev->keybit); | 876 | } |
712 | 877 | ||
713 | break; | 878 | break; |
879 | |||
880 | case GC_SNESMOUSE: | ||
881 | __set_bit(BTN_LEFT, input_dev->keybit); | ||
882 | __set_bit(BTN_RIGHT, input_dev->keybit); | ||
883 | __set_bit(REL_X, input_dev->relbit); | ||
884 | __set_bit(REL_Y, input_dev->relbit); | ||
885 | break; | ||
886 | |||
887 | case GC_SNES: | ||
888 | for (i = 4; i < 8; i++) | ||
889 | __set_bit(gc_snes_btn[i], input_dev->keybit); | ||
890 | case GC_NES: | ||
891 | for (i = 0; i < 4; i++) | ||
892 | __set_bit(gc_snes_btn[i], input_dev->keybit); | ||
893 | break; | ||
894 | |||
895 | case GC_MULTI2: | ||
896 | __set_bit(BTN_THUMB, input_dev->keybit); | ||
897 | case GC_MULTI: | ||
898 | __set_bit(BTN_TRIGGER, input_dev->keybit); | ||
899 | break; | ||
900 | |||
901 | case GC_PSX: | ||
902 | for (i = 0; i < 6; i++) | ||
903 | input_set_abs_params(input_dev, | ||
904 | gc_psx_abs[i], 4, 252, 0, 2); | ||
905 | for (i = 0; i < 12; i++) | ||
906 | __set_bit(gc_psx_btn[i], input_dev->keybit); | ||
907 | |||
908 | break; | ||
909 | |||
910 | case GC_DDR: | ||
911 | for (i = 0; i < 4; i++) | ||
912 | __set_bit(gc_psx_ddr_btn[i], input_dev->keybit); | ||
913 | for (i = 0; i < 12; i++) | ||
914 | __set_bit(gc_psx_btn[i], input_dev->keybit); | ||
915 | |||
916 | break; | ||
714 | } | 917 | } |
715 | 918 | ||
919 | err = input_register_device(pad->dev); | ||
920 | if (err) | ||
921 | goto err_free_dev; | ||
922 | |||
716 | return 0; | 923 | return 0; |
924 | |||
925 | err_free_dev: | ||
926 | input_free_device(pad->dev); | ||
927 | pad->dev = NULL; | ||
928 | return err; | ||
717 | } | 929 | } |
718 | 930 | ||
719 | static struct gc __init *gc_probe(int parport, int *pads, int n_pads) | 931 | static struct gc __init *gc_probe(int parport, int *pads, int n_pads) |
@@ -722,52 +934,47 @@ static struct gc __init *gc_probe(int parport, int *pads, int n_pads) | |||
722 | struct parport *pp; | 934 | struct parport *pp; |
723 | struct pardevice *pd; | 935 | struct pardevice *pd; |
724 | int i; | 936 | int i; |
937 | int count = 0; | ||
725 | int err; | 938 | int err; |
726 | 939 | ||
727 | pp = parport_find_number(parport); | 940 | pp = parport_find_number(parport); |
728 | if (!pp) { | 941 | if (!pp) { |
729 | printk(KERN_ERR "gamecon.c: no such parport\n"); | 942 | pr_err("no such parport %d\n", parport); |
730 | err = -EINVAL; | 943 | err = -EINVAL; |
731 | goto err_out; | 944 | goto err_out; |
732 | } | 945 | } |
733 | 946 | ||
734 | pd = parport_register_device(pp, "gamecon", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL); | 947 | pd = parport_register_device(pp, "gamecon", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL); |
735 | if (!pd) { | 948 | if (!pd) { |
736 | printk(KERN_ERR "gamecon.c: parport busy already - lp.o loaded?\n"); | 949 | pr_err("parport busy already - lp.o loaded?\n"); |
737 | err = -EBUSY; | 950 | err = -EBUSY; |
738 | goto err_put_pp; | 951 | goto err_put_pp; |
739 | } | 952 | } |
740 | 953 | ||
741 | gc = kzalloc(sizeof(struct gc), GFP_KERNEL); | 954 | gc = kzalloc(sizeof(struct gc), GFP_KERNEL); |
742 | if (!gc) { | 955 | if (!gc) { |
743 | printk(KERN_ERR "gamecon.c: Not enough memory\n"); | 956 | pr_err("Not enough memory\n"); |
744 | err = -ENOMEM; | 957 | err = -ENOMEM; |
745 | goto err_unreg_pardev; | 958 | goto err_unreg_pardev; |
746 | } | 959 | } |
747 | 960 | ||
748 | mutex_init(&gc->mutex); | 961 | mutex_init(&gc->mutex); |
749 | gc->pd = pd; | 962 | gc->pd = pd; |
750 | init_timer(&gc->timer); | 963 | setup_timer(&gc->timer, gc_timer, (long) gc); |
751 | gc->timer.data = (long) gc; | ||
752 | gc->timer.function = gc_timer; | ||
753 | 964 | ||
754 | for (i = 0; i < n_pads && i < GC_MAX_DEVICES; i++) { | 965 | for (i = 0; i < n_pads && i < GC_MAX_DEVICES; i++) { |
755 | if (!pads[i]) | 966 | if (!pads[i]) |
756 | continue; | 967 | continue; |
757 | 968 | ||
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]); | 969 | err = gc_setup_pad(gc, i, pads[i]); |
761 | if (err) | 970 | if (err) |
762 | goto err_unreg_devs; | 971 | goto err_unreg_devs; |
763 | 972 | ||
764 | err = input_register_device(gc->dev[i]); | 973 | count++; |
765 | if (err) | ||
766 | goto err_free_dev; | ||
767 | } | 974 | } |
768 | 975 | ||
769 | if (!gc->pads[0]) { | 976 | if (count == 0) { |
770 | printk(KERN_ERR "gamecon.c: No valid devices specified\n"); | 977 | pr_err("No valid devices specified\n"); |
771 | err = -EINVAL; | 978 | err = -EINVAL; |
772 | goto err_free_gc; | 979 | goto err_free_gc; |
773 | } | 980 | } |
@@ -775,12 +982,10 @@ static struct gc __init *gc_probe(int parport, int *pads, int n_pads) | |||
775 | parport_put_port(pp); | 982 | parport_put_port(pp); |
776 | return gc; | 983 | return gc; |
777 | 984 | ||
778 | err_free_dev: | ||
779 | input_free_device(gc->dev[i]); | ||
780 | err_unreg_devs: | 985 | err_unreg_devs: |
781 | while (--i >= 0) | 986 | while (--i >= 0) |
782 | if (gc->dev[i]) | 987 | if (gc->pads[i].dev) |
783 | input_unregister_device(gc->dev[i]); | 988 | input_unregister_device(gc->pads[i].dev); |
784 | err_free_gc: | 989 | err_free_gc: |
785 | kfree(gc); | 990 | kfree(gc); |
786 | err_unreg_pardev: | 991 | err_unreg_pardev: |
@@ -796,8 +1001,8 @@ static void gc_remove(struct gc *gc) | |||
796 | int i; | 1001 | int i; |
797 | 1002 | ||
798 | for (i = 0; i < GC_MAX_DEVICES; i++) | 1003 | for (i = 0; i < GC_MAX_DEVICES; i++) |
799 | if (gc->dev[i]) | 1004 | if (gc->pads[i].dev) |
800 | input_unregister_device(gc->dev[i]); | 1005 | input_unregister_device(gc->pads[i].dev); |
801 | parport_unregister_device(gc->pd); | 1006 | parport_unregister_device(gc->pd); |
802 | kfree(gc); | 1007 | kfree(gc); |
803 | } | 1008 | } |
@@ -813,7 +1018,7 @@ static int __init gc_init(void) | |||
813 | continue; | 1018 | continue; |
814 | 1019 | ||
815 | if (gc_cfg[i].nargs < 2) { | 1020 | if (gc_cfg[i].nargs < 2) { |
816 | printk(KERN_ERR "gamecon.c: at least one device must be specified\n"); | 1021 | pr_err("at least one device must be specified\n"); |
817 | err = -EINVAL; | 1022 | err = -EINVAL; |
818 | break; | 1023 | break; |
819 | } | 1024 | } |
diff --git a/drivers/input/joystick/gf2k.c b/drivers/input/joystick/gf2k.c index 67c207f5b1a1..45ac70eae0aa 100644 --- a/drivers/input/joystick/gf2k.c +++ b/drivers/input/joystick/gf2k.c | |||
@@ -277,7 +277,7 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv) | |||
277 | } | 277 | } |
278 | 278 | ||
279 | #ifdef RESET_WORKS | 279 | #ifdef RESET_WORKS |
280 | if ((gf2k->id != (GB(19,2,0) | GB(15,3,2) | GB(12,3,5))) || | 280 | if ((gf2k->id != (GB(19,2,0) | GB(15,3,2) | GB(12,3,5))) && |
281 | (gf2k->id != (GB(31,2,0) | GB(27,3,2) | GB(24,3,5)))) { | 281 | (gf2k->id != (GB(31,2,0) | GB(27,3,2) | GB(24,3,5)))) { |
282 | err = -ENODEV; | 282 | err = -ENODEV; |
283 | goto fail2; | 283 | goto fail2; |
diff --git a/drivers/input/joystick/iforce/iforce-main.c b/drivers/input/joystick/iforce/iforce-main.c index f6c688cae334..405febd94f24 100644 --- a/drivers/input/joystick/iforce/iforce-main.c +++ b/drivers/input/joystick/iforce/iforce-main.c | |||
@@ -54,6 +54,9 @@ static signed short btn_avb_wheel[] = | |||
54 | static signed short abs_joystick[] = | 54 | static signed short abs_joystick[] = |
55 | { ABS_X, ABS_Y, ABS_THROTTLE, ABS_HAT0X, ABS_HAT0Y, -1 }; | 55 | { ABS_X, ABS_Y, ABS_THROTTLE, ABS_HAT0X, ABS_HAT0Y, -1 }; |
56 | 56 | ||
57 | static signed short abs_joystick_rudder[] = | ||
58 | { ABS_X, ABS_Y, ABS_THROTTLE, ABS_RUDDER, ABS_HAT0X, ABS_HAT0Y, -1 }; | ||
59 | |||
57 | static signed short abs_avb_pegasus[] = | 60 | static signed short abs_avb_pegasus[] = |
58 | { ABS_X, ABS_Y, ABS_THROTTLE, ABS_RUDDER, ABS_HAT0X, ABS_HAT0Y, | 61 | { ABS_X, ABS_Y, ABS_THROTTLE, ABS_RUDDER, ABS_HAT0X, ABS_HAT0Y, |
59 | ABS_HAT1X, ABS_HAT1Y, -1 }; | 62 | ABS_HAT1X, ABS_HAT1Y, -1 }; |
@@ -76,8 +79,9 @@ static struct iforce_device iforce_device[] = { | |||
76 | { 0x061c, 0xc0a4, "ACT LABS Force RS", btn_wheel, abs_wheel, ff_iforce }, //? | 79 | { 0x061c, 0xc0a4, "ACT LABS Force RS", btn_wheel, abs_wheel, ff_iforce }, //? |
77 | { 0x061c, 0xc084, "ACT LABS Force RS", btn_wheel, abs_wheel, ff_iforce }, | 80 | { 0x061c, 0xc084, "ACT LABS Force RS", btn_wheel, abs_wheel, ff_iforce }, |
78 | { 0x06f8, 0x0001, "Guillemot Race Leader Force Feedback", btn_wheel, abs_wheel, ff_iforce }, //? | 81 | { 0x06f8, 0x0001, "Guillemot Race Leader Force Feedback", btn_wheel, abs_wheel, ff_iforce }, //? |
82 | { 0x06f8, 0x0001, "Guillemot Jet Leader Force Feedback", btn_joystick, abs_joystick_rudder, ff_iforce }, | ||
79 | { 0x06f8, 0x0004, "Guillemot Force Feedback Racing Wheel", btn_wheel, abs_wheel, ff_iforce }, //? | 83 | { 0x06f8, 0x0004, "Guillemot Force Feedback Racing Wheel", btn_wheel, abs_wheel, ff_iforce }, //? |
80 | { 0x06f8, 0x0004, "Gullemot Jet Leader 3D", btn_joystick, abs_joystick, ff_iforce }, //? | 84 | { 0x06f8, 0xa302, "Guillemot Jet Leader 3D", btn_joystick, abs_joystick, ff_iforce }, //? |
81 | { 0x06d6, 0x29bc, "Trust Force Feedback Race Master", btn_wheel, abs_wheel, ff_iforce }, | 85 | { 0x06d6, 0x29bc, "Trust Force Feedback Race Master", btn_wheel, abs_wheel, ff_iforce }, |
82 | { 0x0000, 0x0000, "Unknown I-Force Device [%04x:%04x]", btn_joystick, abs_joystick, ff_iforce } | 86 | { 0x0000, 0x0000, "Unknown I-Force Device [%04x:%04x]", btn_joystick, abs_joystick, ff_iforce } |
83 | }; | 87 | }; |
@@ -210,7 +214,7 @@ static int iforce_open(struct input_dev *dev) | |||
210 | return 0; | 214 | return 0; |
211 | } | 215 | } |
212 | 216 | ||
213 | static void iforce_release(struct input_dev *dev) | 217 | static void iforce_close(struct input_dev *dev) |
214 | { | 218 | { |
215 | struct iforce *iforce = input_get_drvdata(dev); | 219 | struct iforce *iforce = input_get_drvdata(dev); |
216 | int i; | 220 | int i; |
@@ -228,30 +232,17 @@ static void iforce_release(struct input_dev *dev) | |||
228 | 232 | ||
229 | /* Disable force feedback playback */ | 233 | /* Disable force feedback playback */ |
230 | iforce_send_packet(iforce, FF_CMD_ENABLE, "\001"); | 234 | iforce_send_packet(iforce, FF_CMD_ENABLE, "\001"); |
235 | /* Wait for the command to complete */ | ||
236 | wait_event_interruptible(iforce->wait, | ||
237 | !test_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags)); | ||
231 | } | 238 | } |
232 | 239 | ||
233 | switch (iforce->bus) { | 240 | switch (iforce->bus) { |
234 | #ifdef CONFIG_JOYSTICK_IFORCE_USB | 241 | #ifdef CONFIG_JOYSTICK_IFORCE_USB |
235 | case IFORCE_USB: | ||
236 | usb_kill_urb(iforce->irq); | ||
237 | |||
238 | /* The device was unplugged before the file | ||
239 | * was released */ | ||
240 | if (iforce->usbdev == NULL) { | ||
241 | iforce_delete_device(iforce); | ||
242 | kfree(iforce); | ||
243 | } | ||
244 | break; | ||
245 | #endif | ||
246 | } | ||
247 | } | ||
248 | |||
249 | void iforce_delete_device(struct iforce *iforce) | ||
250 | { | ||
251 | switch (iforce->bus) { | ||
252 | #ifdef CONFIG_JOYSTICK_IFORCE_USB | ||
253 | case IFORCE_USB: | 242 | case IFORCE_USB: |
254 | iforce_usb_delete(iforce); | 243 | usb_kill_urb(iforce->irq); |
244 | usb_kill_urb(iforce->out); | ||
245 | usb_kill_urb(iforce->ctrl); | ||
255 | break; | 246 | break; |
256 | #endif | 247 | #endif |
257 | #ifdef CONFIG_JOYSTICK_IFORCE_232 | 248 | #ifdef CONFIG_JOYSTICK_IFORCE_232 |
@@ -303,7 +294,7 @@ int iforce_init_device(struct iforce *iforce) | |||
303 | 294 | ||
304 | input_dev->name = "Unknown I-Force device"; | 295 | input_dev->name = "Unknown I-Force device"; |
305 | input_dev->open = iforce_open; | 296 | input_dev->open = iforce_open; |
306 | input_dev->close = iforce_release; | 297 | input_dev->close = iforce_close; |
307 | 298 | ||
308 | /* | 299 | /* |
309 | * On-device memory allocation. | 300 | * On-device memory allocation. |
diff --git a/drivers/input/joystick/iforce/iforce-usb.c b/drivers/input/joystick/iforce/iforce-usb.c index 9f289d8f52c6..6c96631ae5d9 100644 --- a/drivers/input/joystick/iforce/iforce-usb.c +++ b/drivers/input/joystick/iforce/iforce-usb.c | |||
@@ -109,6 +109,7 @@ static void iforce_usb_out(struct urb *urb) | |||
109 | struct iforce *iforce = urb->context; | 109 | struct iforce *iforce = urb->context; |
110 | 110 | ||
111 | if (urb->status) { | 111 | if (urb->status) { |
112 | clear_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags); | ||
112 | dbg("urb->status %d, exiting", urb->status); | 113 | dbg("urb->status %d, exiting", urb->status); |
113 | return; | 114 | return; |
114 | } | 115 | } |
@@ -186,33 +187,19 @@ fail: | |||
186 | return err; | 187 | return err; |
187 | } | 188 | } |
188 | 189 | ||
189 | /* Called by iforce_delete() */ | ||
190 | void iforce_usb_delete(struct iforce* iforce) | ||
191 | { | ||
192 | usb_kill_urb(iforce->irq); | ||
193 | usb_kill_urb(iforce->out); | ||
194 | usb_kill_urb(iforce->ctrl); | ||
195 | |||
196 | usb_free_urb(iforce->irq); | ||
197 | usb_free_urb(iforce->out); | ||
198 | usb_free_urb(iforce->ctrl); | ||
199 | } | ||
200 | |||
201 | static void iforce_usb_disconnect(struct usb_interface *intf) | 190 | static void iforce_usb_disconnect(struct usb_interface *intf) |
202 | { | 191 | { |
203 | struct iforce *iforce = usb_get_intfdata(intf); | 192 | struct iforce *iforce = usb_get_intfdata(intf); |
204 | int open = 0; /* FIXME! iforce->dev.handle->open; */ | ||
205 | 193 | ||
206 | usb_set_intfdata(intf, NULL); | 194 | usb_set_intfdata(intf, NULL); |
207 | if (iforce) { | ||
208 | iforce->usbdev = NULL; | ||
209 | input_unregister_device(iforce->dev); | ||
210 | 195 | ||
211 | if (!open) { | 196 | input_unregister_device(iforce->dev); |
212 | iforce_delete_device(iforce); | 197 | |
213 | kfree(iforce); | 198 | usb_free_urb(iforce->irq); |
214 | } | 199 | usb_free_urb(iforce->out); |
215 | } | 200 | usb_free_urb(iforce->ctrl); |
201 | |||
202 | kfree(iforce); | ||
216 | } | 203 | } |
217 | 204 | ||
218 | static struct usb_device_id iforce_usb_ids [] = { | 205 | static struct usb_device_id iforce_usb_ids [] = { |
@@ -225,6 +212,7 @@ static struct usb_device_id iforce_usb_ids [] = { | |||
225 | { USB_DEVICE(0x061c, 0xc0a4) }, /* ACT LABS Force RS */ | 212 | { USB_DEVICE(0x061c, 0xc0a4) }, /* ACT LABS Force RS */ |
226 | { USB_DEVICE(0x061c, 0xc084) }, /* ACT LABS Force RS */ | 213 | { USB_DEVICE(0x061c, 0xc084) }, /* ACT LABS Force RS */ |
227 | { USB_DEVICE(0x06f8, 0x0001) }, /* Guillemot Race Leader Force Feedback */ | 214 | { USB_DEVICE(0x06f8, 0x0001) }, /* Guillemot Race Leader Force Feedback */ |
215 | { USB_DEVICE(0x06f8, 0x0003) }, /* Guillemot Jet Leader Force Feedback */ | ||
228 | { USB_DEVICE(0x06f8, 0x0004) }, /* Guillemot Force Feedback Racing Wheel */ | 216 | { USB_DEVICE(0x06f8, 0x0004) }, /* Guillemot Force Feedback Racing Wheel */ |
229 | { USB_DEVICE(0x06f8, 0xa302) }, /* Guillemot Jet Leader 3D */ | 217 | { USB_DEVICE(0x06f8, 0xa302) }, /* Guillemot Jet Leader 3D */ |
230 | { } /* Terminating entry */ | 218 | { } /* Terminating entry */ |
diff --git a/drivers/input/joystick/iforce/iforce.h b/drivers/input/joystick/iforce/iforce.h index f2d91f4028ca..9f494b75848a 100644 --- a/drivers/input/joystick/iforce/iforce.h +++ b/drivers/input/joystick/iforce/iforce.h | |||
@@ -150,11 +150,9 @@ void iforce_serial_xmit(struct iforce *iforce); | |||
150 | 150 | ||
151 | /* iforce-usb.c */ | 151 | /* iforce-usb.c */ |
152 | void iforce_usb_xmit(struct iforce *iforce); | 152 | void iforce_usb_xmit(struct iforce *iforce); |
153 | void iforce_usb_delete(struct iforce *iforce); | ||
154 | 153 | ||
155 | /* iforce-main.c */ | 154 | /* iforce-main.c */ |
156 | int iforce_init_device(struct iforce *iforce); | 155 | int iforce_init_device(struct iforce *iforce); |
157 | void iforce_delete_device(struct iforce *iforce); | ||
158 | 156 | ||
159 | /* iforce-packets.c */ | 157 | /* iforce-packets.c */ |
160 | int iforce_control_playback(struct iforce*, u16 id, unsigned int); | 158 | int iforce_control_playback(struct iforce*, u16 id, unsigned int); |
diff --git a/drivers/input/joystick/turbografx.c b/drivers/input/joystick/turbografx.c index b6f859869540..d53b9e900234 100644 --- a/drivers/input/joystick/turbografx.c +++ b/drivers/input/joystick/turbografx.c | |||
@@ -35,6 +35,7 @@ | |||
35 | #include <linux/module.h> | 35 | #include <linux/module.h> |
36 | #include <linux/init.h> | 36 | #include <linux/init.h> |
37 | #include <linux/mutex.h> | 37 | #include <linux/mutex.h> |
38 | #include <linux/slab.h> | ||
38 | 39 | ||
39 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); | 40 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); |
40 | MODULE_DESCRIPTION("TurboGraFX parallel port interface driver"); | 41 | MODULE_DESCRIPTION("TurboGraFX parallel port interface driver"); |
diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c index 79e3edcced1a..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,55 +98,61 @@ static int dpad_to_buttons; | |||
99 | module_param(dpad_to_buttons, bool, S_IRUGO); | 98 | module_param(dpad_to_buttons, bool, S_IRUGO); |
100 | MODULE_PARM_DESC(dpad_to_buttons, "Map D-PAD to buttons rather than axes for unknown pads"); | 99 | MODULE_PARM_DESC(dpad_to_buttons, "Map D-PAD to buttons rather than axes for unknown pads"); |
101 | 100 | ||
101 | static int triggers_to_buttons; | ||
102 | module_param(triggers_to_buttons, bool, S_IRUGO); | ||
103 | MODULE_PARM_DESC(triggers_to_buttons, "Map triggers to buttons rather than axes for unknown pads"); | ||
104 | |||
102 | static const struct xpad_device { | 105 | static 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 }, |
131 | { 0x0738, 0x4738, "Mad Catz Wired Xbox 360 Controller (SFIV)", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, | ||
128 | { 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 }, |
129 | { 0x0c12, 0x8802, "Zeroplus Xbox Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, | 133 | { 0x0c12, 0x8802, "Zeroplus Xbox Controller", 0, XTYPE_XBOX }, |
130 | { 0x0c12, 0x880a, "Pelican Eclipse PL-2023", MAP_DPAD_TO_AXES, XTYPE_XBOX }, | 134 | { 0x0c12, 0x880a, "Pelican Eclipse PL-2023", 0, XTYPE_XBOX }, |
131 | { 0x0c12, 0x8810, "Zeroplus Xbox Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, | 135 | { 0x0c12, 0x8810, "Zeroplus Xbox Controller", 0, XTYPE_XBOX }, |
132 | { 0x0c12, 0x9902, "HAMA VibraX - *FAULTY HARDWARE*", MAP_DPAD_TO_AXES, XTYPE_XBOX }, | 136 | { 0x0c12, 0x9902, "HAMA VibraX - *FAULTY HARDWARE*", 0, XTYPE_XBOX }, |
133 | { 0x0e4c, 0x1097, "Radica Gamester Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, | 137 | { 0x0e4c, 0x1097, "Radica Gamester Controller", 0, XTYPE_XBOX }, |
134 | { 0x0e4c, 0x2390, "Radica Games Jtech Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, | 138 | { 0x0e4c, 0x2390, "Radica Games Jtech Controller", 0, XTYPE_XBOX }, |
135 | { 0x0e6f, 0x0003, "Logic3 Freebird wireless Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, | 139 | { 0x0e6f, 0x0003, "Logic3 Freebird wireless Controller", 0, XTYPE_XBOX }, |
136 | { 0x0e6f, 0x0005, "Eclipse wireless Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, | 140 | { 0x0e6f, 0x0005, "Eclipse wireless Controller", 0, XTYPE_XBOX }, |
137 | { 0x0e6f, 0x0006, "Edge wireless Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, | 141 | { 0x0e6f, 0x0006, "Edge wireless Controller", 0, XTYPE_XBOX }, |
138 | { 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 }, |
139 | { 0x0e8f, 0x0201, "SmartJoy Frag Xpad/PS2 adaptor", MAP_DPAD_TO_AXES, XTYPE_XBOX }, | 143 | { 0x0e8f, 0x0201, "SmartJoy Frag Xpad/PS2 adaptor", 0, XTYPE_XBOX }, |
140 | { 0x0f30, 0x0202, "Joytech Advanced Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, | 144 | { 0x0f30, 0x0202, "Joytech Advanced Controller", 0, XTYPE_XBOX }, |
141 | { 0x0f30, 0x8888, "BigBen XBMiniPad Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, | 145 | { 0x0f30, 0x8888, "BigBen XBMiniPad Controller", 0, XTYPE_XBOX }, |
142 | { 0x102c, 0xff0c, "Joytech Wireless Advanced Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, | 146 | { 0x102c, 0xff0c, "Joytech Wireless Advanced Controller", 0, XTYPE_XBOX }, |
143 | { 0x12ab, 0x8809, "Xbox DDR dancepad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX }, | 147 | { 0x12ab, 0x8809, "Xbox DDR dancepad", MAP_DPAD_TO_BUTTONS, XTYPE_XBOX }, |
144 | { 0x1430, 0x4748, "RedOctane Guitar Hero X-plorer", MAP_DPAD_TO_AXES, XTYPE_XBOX360 }, | 148 | { 0x1430, 0x4748, "RedOctane Guitar Hero X-plorer", 0, XTYPE_XBOX360 }, |
145 | { 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 }, |
146 | { 0x146b, 0x0601, "BigBen Interactive XBOX 360 Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX360 }, | 150 | { 0x146b, 0x0601, "BigBen Interactive XBOX 360 Controller", 0, XTYPE_XBOX360 }, |
147 | { 0x045e, 0x028e, "Microsoft X-Box 360 pad", MAP_DPAD_TO_AXES, XTYPE_XBOX360 }, | 151 | { 0x045e, 0x028e, "Microsoft X-Box 360 pad", 0, XTYPE_XBOX360 }, |
148 | { 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 }, |
149 | { 0xffff, 0xffff, "Chinese-made Xbox Controller", MAP_DPAD_TO_AXES, XTYPE_XBOX }, | 153 | { 0x0f0d, 0x0016, "Hori Real Arcade Pro.EX", MAP_TRIGGERS_TO_BUTTONS, XTYPE_XBOX360 }, |
150 | { 0x0000, 0x0000, "Generic X-Box pad", MAP_DPAD_UNKNOWN, XTYPE_UNKNOWN } | 154 | { 0xffff, 0xffff, "Chinese-made Xbox Controller", 0, XTYPE_XBOX }, |
155 | { 0x0000, 0x0000, "Generic X-Box pad", 0, XTYPE_UNKNOWN } | ||
151 | }; | 156 | }; |
152 | 157 | ||
153 | /* buttons shared with xbox and xbox360 */ | 158 | /* buttons shared with xbox and xbox360 */ |
@@ -163,13 +168,20 @@ static const signed short xpad_btn[] = { | |||
163 | -1 /* terminating entry */ | 168 | -1 /* terminating entry */ |
164 | }; | 169 | }; |
165 | 170 | ||
166 | /* only used if MAP_DPAD_TO_BUTTONS */ | 171 | /* used when dpad is mapped to nuttons */ |
167 | static const signed short xpad_btn_pad[] = { | 172 | static const signed short xpad_btn_pad[] = { |
168 | BTN_LEFT, BTN_RIGHT, /* d-pad left, right */ | 173 | BTN_LEFT, BTN_RIGHT, /* d-pad left, right */ |
169 | BTN_0, BTN_1, /* d-pad up, down (XXX names??) */ | 174 | BTN_0, BTN_1, /* d-pad up, down (XXX names??) */ |
170 | -1 /* terminating entry */ | 175 | -1 /* terminating entry */ |
171 | }; | 176 | }; |
172 | 177 | ||
178 | /* used when triggers are mapped to buttons */ | ||
179 | static const signed short xpad_btn_triggers[] = { | ||
180 | BTN_TL2, BTN_TR2, /* triggers left/right */ | ||
181 | -1 | ||
182 | }; | ||
183 | |||
184 | |||
173 | static const signed short xpad360_btn[] = { /* buttons for x360 controller */ | 185 | static const signed short xpad360_btn[] = { /* buttons for x360 controller */ |
174 | BTN_TL, BTN_TR, /* Button LB/RB */ | 186 | BTN_TL, BTN_TR, /* Button LB/RB */ |
175 | BTN_MODE, /* The big X button */ | 187 | BTN_MODE, /* The big X button */ |
@@ -179,16 +191,21 @@ static const signed short xpad360_btn[] = { /* buttons for x360 controller */ | |||
179 | static const signed short xpad_abs[] = { | 191 | static const signed short xpad_abs[] = { |
180 | ABS_X, ABS_Y, /* left stick */ | 192 | ABS_X, ABS_Y, /* left stick */ |
181 | ABS_RX, ABS_RY, /* right stick */ | 193 | ABS_RX, ABS_RY, /* right stick */ |
182 | ABS_Z, ABS_RZ, /* triggers left/right */ | ||
183 | -1 /* terminating entry */ | 194 | -1 /* terminating entry */ |
184 | }; | 195 | }; |
185 | 196 | ||
186 | /* only used if MAP_DPAD_TO_AXES */ | 197 | /* used when dpad is mapped to axes */ |
187 | static const signed short xpad_abs_pad[] = { | 198 | static const signed short xpad_abs_pad[] = { |
188 | ABS_HAT0X, ABS_HAT0Y, /* d-pad axes */ | 199 | ABS_HAT0X, ABS_HAT0Y, /* d-pad axes */ |
189 | -1 /* terminating entry */ | 200 | -1 /* terminating entry */ |
190 | }; | 201 | }; |
191 | 202 | ||
203 | /* used when triggers are mapped to axes */ | ||
204 | static const signed short xpad_abs_triggers[] = { | ||
205 | ABS_Z, ABS_RZ, /* triggers left/right */ | ||
206 | -1 | ||
207 | }; | ||
208 | |||
192 | /* 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 |
193 | * USB_INTERFACE_INFO (also specifically refused by USB subsystem), so we | 210 | * USB_INTERFACE_INFO (also specifically refused by USB subsystem), so we |
194 | * 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, |
@@ -212,6 +229,7 @@ static struct usb_device_id xpad_table [] = { | |||
212 | XPAD_XBOX360_VENDOR(0x1430), /* RedOctane X-Box 360 controllers */ | 229 | XPAD_XBOX360_VENDOR(0x1430), /* RedOctane X-Box 360 controllers */ |
213 | XPAD_XBOX360_VENDOR(0x146b), /* BigBen Interactive Controllers */ | 230 | XPAD_XBOX360_VENDOR(0x146b), /* BigBen Interactive Controllers */ |
214 | XPAD_XBOX360_VENDOR(0x1bad), /* Rock Band Drums */ | 231 | XPAD_XBOX360_VENDOR(0x1bad), /* Rock Band Drums */ |
232 | XPAD_XBOX360_VENDOR(0x0f0d), /* Hori Controllers */ | ||
215 | { } | 233 | { } |
216 | }; | 234 | }; |
217 | 235 | ||
@@ -243,7 +261,7 @@ struct usb_xpad { | |||
243 | 261 | ||
244 | char phys[64]; /* physical device path */ | 262 | char phys[64]; /* physical device path */ |
245 | 263 | ||
246 | int dpad_mapping; /* map d-pad to buttons or to axes */ | 264 | int mapping; /* map d-pad to buttons or to axes */ |
247 | int xtype; /* type of xbox device */ | 265 | int xtype; /* type of xbox device */ |
248 | }; | 266 | }; |
249 | 267 | ||
@@ -274,20 +292,25 @@ static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *d | |||
274 | ~(__s16) le16_to_cpup((__le16 *)(data + 18))); | 292 | ~(__s16) le16_to_cpup((__le16 *)(data + 18))); |
275 | 293 | ||
276 | /* triggers left/right */ | 294 | /* triggers left/right */ |
277 | input_report_abs(dev, ABS_Z, data[10]); | 295 | if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { |
278 | 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 | } | ||
279 | 302 | ||
280 | /* digital pad */ | 303 | /* digital pad */ |
281 | if (xpad->dpad_mapping == MAP_DPAD_TO_AXES) { | 304 | if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { |
282 | input_report_abs(dev, ABS_HAT0X, | ||
283 | !!(data[2] & 0x08) - !!(data[2] & 0x04)); | ||
284 | input_report_abs(dev, ABS_HAT0Y, | ||
285 | !!(data[2] & 0x02) - !!(data[2] & 0x01)); | ||
286 | } else /* xpad->dpad_mapping == MAP_DPAD_TO_BUTTONS */ { | ||
287 | input_report_key(dev, BTN_LEFT, data[2] & 0x04); | 305 | input_report_key(dev, BTN_LEFT, data[2] & 0x04); |
288 | input_report_key(dev, BTN_RIGHT, data[2] & 0x08); | 306 | input_report_key(dev, BTN_RIGHT, data[2] & 0x08); |
289 | input_report_key(dev, BTN_0, data[2] & 0x01); /* up */ | 307 | input_report_key(dev, BTN_0, data[2] & 0x01); /* up */ |
290 | 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)); | ||
291 | } | 314 | } |
292 | 315 | ||
293 | /* start/back buttons and stick press left/right */ | 316 | /* start/back buttons and stick press left/right */ |
@@ -325,17 +348,17 @@ static void xpad360_process_packet(struct usb_xpad *xpad, | |||
325 | struct input_dev *dev = xpad->dev; | 348 | struct input_dev *dev = xpad->dev; |
326 | 349 | ||
327 | /* digital pad */ | 350 | /* digital pad */ |
328 | if (xpad->dpad_mapping == MAP_DPAD_TO_AXES) { | 351 | if (xpad->mapping & MAP_DPAD_TO_BUTTONS) { |
329 | input_report_abs(dev, ABS_HAT0X, | ||
330 | !!(data[2] & 0x08) - !!(data[2] & 0x04)); | ||
331 | input_report_abs(dev, ABS_HAT0Y, | ||
332 | !!(data[2] & 0x02) - !!(data[2] & 0x01)); | ||
333 | } else if (xpad->dpad_mapping == MAP_DPAD_TO_BUTTONS) { | ||
334 | /* dpad as buttons (right, left, down, up) */ | 352 | /* dpad as buttons (right, left, down, up) */ |
335 | input_report_key(dev, BTN_LEFT, data[2] & 0x04); | 353 | input_report_key(dev, BTN_LEFT, data[2] & 0x04); |
336 | input_report_key(dev, BTN_RIGHT, data[2] & 0x08); | 354 | input_report_key(dev, BTN_RIGHT, data[2] & 0x08); |
337 | input_report_key(dev, BTN_0, data[2] & 0x01); /* up */ | 355 | input_report_key(dev, BTN_0, data[2] & 0x01); /* up */ |
338 | 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)); | ||
339 | } | 362 | } |
340 | 363 | ||
341 | /* start/back buttons */ | 364 | /* start/back buttons */ |
@@ -368,8 +391,13 @@ static void xpad360_process_packet(struct usb_xpad *xpad, | |||
368 | ~(__s16) le16_to_cpup((__le16 *)(data + 12))); | 391 | ~(__s16) le16_to_cpup((__le16 *)(data + 12))); |
369 | 392 | ||
370 | /* triggers left/right */ | 393 | /* triggers left/right */ |
371 | input_report_abs(dev, ABS_Z, data[4]); | 394 | if (xpad->mapping & MAP_TRIGGERS_TO_BUTTONS) { |
372 | 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 | } | ||
373 | 401 | ||
374 | input_sync(dev); | 402 | input_sync(dev); |
375 | } | 403 | } |
@@ -443,7 +471,7 @@ static void xpad_irq_in(struct urb *urb) | |||
443 | } | 471 | } |
444 | 472 | ||
445 | exit: | 473 | exit: |
446 | retval = usb_submit_urb (urb, GFP_ATOMIC); | 474 | retval = usb_submit_urb(urb, GFP_ATOMIC); |
447 | if (retval) | 475 | if (retval) |
448 | err ("%s - usb_submit_urb failed with result %d", | 476 | err ("%s - usb_submit_urb failed with result %d", |
449 | __func__, retval); | 477 | __func__, retval); |
@@ -502,7 +530,7 @@ static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad) | |||
502 | struct usb_endpoint_descriptor *ep_irq_out; | 530 | struct usb_endpoint_descriptor *ep_irq_out; |
503 | int error = -ENOMEM; | 531 | int error = -ENOMEM; |
504 | 532 | ||
505 | if (xpad->xtype != XTYPE_XBOX360) | 533 | if (xpad->xtype != XTYPE_XBOX360 && xpad->xtype != XTYPE_XBOX) |
506 | return 0; | 534 | return 0; |
507 | 535 | ||
508 | xpad->odata = usb_buffer_alloc(xpad->udev, XPAD_PKT_LEN, | 536 | xpad->odata = usb_buffer_alloc(xpad->udev, XPAD_PKT_LEN, |
@@ -532,13 +560,13 @@ static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad) | |||
532 | 560 | ||
533 | static void xpad_stop_output(struct usb_xpad *xpad) | 561 | static void xpad_stop_output(struct usb_xpad *xpad) |
534 | { | 562 | { |
535 | if (xpad->xtype == XTYPE_XBOX360) | 563 | if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype == XTYPE_XBOX) |
536 | usb_kill_urb(xpad->irq_out); | 564 | usb_kill_urb(xpad->irq_out); |
537 | } | 565 | } |
538 | 566 | ||
539 | static void xpad_deinit_output(struct usb_xpad *xpad) | 567 | static void xpad_deinit_output(struct usb_xpad *xpad) |
540 | { | 568 | { |
541 | if (xpad->xtype == XTYPE_XBOX360) { | 569 | if (xpad->xtype == XTYPE_XBOX360 || xpad->xtype == XTYPE_XBOX) { |
542 | usb_free_urb(xpad->irq_out); | 570 | usb_free_urb(xpad->irq_out); |
543 | usb_buffer_free(xpad->udev, XPAD_PKT_LEN, | 571 | usb_buffer_free(xpad->udev, XPAD_PKT_LEN, |
544 | xpad->odata, xpad->odata_dma); | 572 | xpad->odata, xpad->odata_dma); |
@@ -551,24 +579,45 @@ static void xpad_stop_output(struct usb_xpad *xpad) {} | |||
551 | #endif | 579 | #endif |
552 | 580 | ||
553 | #ifdef CONFIG_JOYSTICK_XPAD_FF | 581 | #ifdef CONFIG_JOYSTICK_XPAD_FF |
554 | static int xpad_play_effect(struct input_dev *dev, void *data, | 582 | static int xpad_play_effect(struct input_dev *dev, void *data, struct ff_effect *effect) |
555 | struct ff_effect *effect) | ||
556 | { | 583 | { |
557 | struct usb_xpad *xpad = input_get_drvdata(dev); | 584 | struct usb_xpad *xpad = input_get_drvdata(dev); |
558 | 585 | ||
559 | if (effect->type == FF_RUMBLE) { | 586 | if (effect->type == FF_RUMBLE) { |
560 | __u16 strong = effect->u.rumble.strong_magnitude; | 587 | __u16 strong = effect->u.rumble.strong_magnitude; |
561 | __u16 weak = effect->u.rumble.weak_magnitude; | 588 | __u16 weak = effect->u.rumble.weak_magnitude; |
562 | xpad->odata[0] = 0x00; | 589 | |
563 | xpad->odata[1] = 0x08; | 590 | switch (xpad->xtype) { |
564 | xpad->odata[2] = 0x00; | 591 | |
565 | xpad->odata[3] = strong / 256; | 592 | case XTYPE_XBOX: |
566 | xpad->odata[4] = weak / 256; | 593 | xpad->odata[0] = 0x00; |
567 | xpad->odata[5] = 0x00; | 594 | xpad->odata[1] = 0x06; |
568 | xpad->odata[6] = 0x00; | 595 | xpad->odata[2] = 0x00; |
569 | xpad->odata[7] = 0x00; | 596 | xpad->odata[3] = strong / 256; /* left actuator */ |
570 | xpad->irq_out->transfer_buffer_length = 8; | 597 | xpad->odata[4] = 0x00; |
571 | usb_submit_urb(xpad->irq_out, GFP_KERNEL); | 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 | } | ||
572 | } | 621 | } |
573 | 622 | ||
574 | return 0; | 623 | return 0; |
@@ -576,7 +625,7 @@ static int xpad_play_effect(struct input_dev *dev, void *data, | |||
576 | 625 | ||
577 | static int xpad_init_ff(struct usb_xpad *xpad) | 626 | static int xpad_init_ff(struct usb_xpad *xpad) |
578 | { | 627 | { |
579 | if (xpad->xtype != XTYPE_XBOX360) | 628 | if (xpad->xtype != XTYPE_XBOX360 && xpad->xtype != XTYPE_XBOX) |
580 | return 0; | 629 | return 0; |
581 | 630 | ||
582 | input_set_capability(xpad->dev, EV_FF, FF_RUMBLE); | 631 | input_set_capability(xpad->dev, EV_FF, FF_RUMBLE); |
@@ -709,11 +758,11 @@ static void xpad_set_up_abs(struct input_dev *input_dev, signed short abs) | |||
709 | input_set_abs_params(input_dev, abs, -32768, 32767, 16, 128); | 758 | input_set_abs_params(input_dev, abs, -32768, 32767, 16, 128); |
710 | break; | 759 | break; |
711 | case ABS_Z: | 760 | case ABS_Z: |
712 | case ABS_RZ: /* the triggers */ | 761 | case ABS_RZ: /* the triggers (if mapped to axes) */ |
713 | input_set_abs_params(input_dev, abs, 0, 255, 0, 0); | 762 | input_set_abs_params(input_dev, abs, 0, 255, 0, 0); |
714 | break; | 763 | break; |
715 | case ABS_HAT0X: | 764 | case ABS_HAT0X: |
716 | 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 */ |
717 | input_set_abs_params(input_dev, abs, -1, 1, 0, 0); | 766 | input_set_abs_params(input_dev, abs, -1, 1, 0, 0); |
718 | break; | 767 | break; |
719 | } | 768 | } |
@@ -749,10 +798,9 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id | |||
749 | goto fail2; | 798 | goto fail2; |
750 | 799 | ||
751 | xpad->udev = udev; | 800 | xpad->udev = udev; |
752 | xpad->dpad_mapping = xpad_device[i].dpad_mapping; | 801 | xpad->mapping = xpad_device[i].mapping; |
753 | xpad->xtype = xpad_device[i].xtype; | 802 | xpad->xtype = xpad_device[i].xtype; |
754 | if (xpad->dpad_mapping == MAP_DPAD_UNKNOWN) | 803 | |
755 | xpad->dpad_mapping = !dpad_to_buttons; | ||
756 | if (xpad->xtype == XTYPE_UNKNOWN) { | 804 | if (xpad->xtype == XTYPE_UNKNOWN) { |
757 | if (intf->cur_altsetting->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC) { | 805 | if (intf->cur_altsetting->desc.bInterfaceClass == USB_CLASS_VENDOR_SPEC) { |
758 | if (intf->cur_altsetting->desc.bInterfaceProtocol == 129) | 806 | if (intf->cur_altsetting->desc.bInterfaceProtocol == 129) |
@@ -761,7 +809,13 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id | |||
761 | xpad->xtype = XTYPE_XBOX360; | 809 | xpad->xtype = XTYPE_XBOX360; |
762 | } else | 810 | } else |
763 | 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; | ||
764 | } | 817 | } |
818 | |||
765 | xpad->dev = input_dev; | 819 | xpad->dev = input_dev; |
766 | usb_make_path(udev, xpad->phys, sizeof(xpad->phys)); | 820 | usb_make_path(udev, xpad->phys, sizeof(xpad->phys)); |
767 | strlcat(xpad->phys, "/input0", sizeof(xpad->phys)); | 821 | strlcat(xpad->phys, "/input0", sizeof(xpad->phys)); |
@@ -778,25 +832,37 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id | |||
778 | 832 | ||
779 | 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); |
780 | 834 | ||
781 | /* set up buttons */ | 835 | /* set up standard buttons and axes */ |
782 | for (i = 0; xpad_common_btn[i] >= 0; i++) | 836 | for (i = 0; xpad_common_btn[i] >= 0; i++) |
783 | set_bit(xpad_common_btn[i], input_dev->keybit); | 837 | __set_bit(xpad_common_btn[i], input_dev->keybit); |
784 | if ((xpad->xtype == XTYPE_XBOX360) || (xpad->xtype == XTYPE_XBOX360W)) | ||
785 | for (i = 0; xpad360_btn[i] >= 0; i++) | ||
786 | set_bit(xpad360_btn[i], input_dev->keybit); | ||
787 | else | ||
788 | for (i = 0; xpad_btn[i] >= 0; i++) | ||
789 | set_bit(xpad_btn[i], input_dev->keybit); | ||
790 | if (xpad->dpad_mapping == MAP_DPAD_TO_BUTTONS) | ||
791 | for (i = 0; xpad_btn_pad[i] >= 0; i++) | ||
792 | set_bit(xpad_btn_pad[i], input_dev->keybit); | ||
793 | 838 | ||
794 | /* set up axes */ | ||
795 | for (i = 0; xpad_abs[i] >= 0; i++) | 839 | for (i = 0; xpad_abs[i] >= 0; i++) |
796 | xpad_set_up_abs(input_dev, xpad_abs[i]); | 840 | xpad_set_up_abs(input_dev, xpad_abs[i]); |
797 | 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 { | ||
798 | for (i = 0; xpad_abs_pad[i] >= 0; i++) | 855 | for (i = 0; xpad_abs_pad[i] >= 0; i++) |
799 | 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 | } | ||
800 | 866 | ||
801 | error = xpad_init_output(intf, xpad); | 867 | error = xpad_init_output(intf, xpad); |
802 | if (error) | 868 | if (error) |