aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/joystick/xpad.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/joystick/xpad.c')
-rw-r--r--drivers/input/joystick/xpad.c254
1 files changed, 160 insertions, 94 deletions
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;
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 },
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 */
167static const signed short xpad_btn_pad[] = { 172static 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 */
179static const signed short xpad_btn_triggers[] = {
180 BTN_TL2, BTN_TR2, /* triggers left/right */
181 -1
182};
183
184
173static const signed short xpad360_btn[] = { /* buttons for x360 controller */ 185static 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 */
179static const signed short xpad_abs[] = { 191static 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 */
187static const signed short xpad_abs_pad[] = { 198static 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 */
204static 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
445exit: 473exit:
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
533static void xpad_stop_output(struct usb_xpad *xpad) 561static 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
539static void xpad_deinit_output(struct usb_xpad *xpad) 567static 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
554static 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)
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
577static int xpad_init_ff(struct usb_xpad *xpad) 626static 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)