diff options
author | Dominic Cerquetti <binary1230@yahoo.com> | 2006-10-10 17:42:48 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2006-10-17 17:46:33 -0400 |
commit | deb8ee43a23d48116cb23eb8dd1de2348efb1e80 (patch) | |
tree | c30cede8edd09cc7aff7c01ea6fbcb7b0d900e5d | |
parent | 4550718f6c75c9abe8b987fa4c625fd041aa95a2 (diff) |
USB: xpad: dance pad support
Adds support for dance pads to the xpad driver. Dance pads require the
d-pad to be mapped to four buttons instead of two axes, so that
combinations of up/down and left/right can be hit simultaneously.
Known dance pads are detected, and there is a module parameter added
to default unknown xpad devices to map the d-pad to buttons if this is
desired. (dpad_to_buttons). Minor modifications were made to port the
changes in the original patch to a newer kernel version.
This patch was originally from Dominic Cerquetti originally written
for kernel 2.6.11.4, with minor modifications (API changes for USB,
spelling fixes to the documentation added in the original patch) made
to apply to the current kernel. I have modified Dominic's original
patch per some suggestions from Dmitry Torokhov. (There was nothing
in the patch format description about multiple From: lines, so I
haven't added myself.)
[akpm@osdl.org: cleanups]
Signed-off-by: Adam Buchbinder <adam.buchbinder@gmail.com>
Acked-by: Dmitry Torokhov <dtor@mail.ru>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
-rw-r--r-- | Documentation/input/xpad.txt | 115 | ||||
-rw-r--r-- | drivers/usb/input/xpad.c | 139 |
2 files changed, 186 insertions, 68 deletions
diff --git a/Documentation/input/xpad.txt b/Documentation/input/xpad.txt index b9111a703ce0..5427bdf225ed 100644 --- a/Documentation/input/xpad.txt +++ b/Documentation/input/xpad.txt | |||
@@ -3,20 +3,37 @@ xpad - Linux USB driver for X-Box gamepads | |||
3 | This is the very first release of a driver for X-Box gamepads. | 3 | This is the very first release of a driver for X-Box gamepads. |
4 | Basically, this was hacked away in just a few hours, so don't expect | 4 | Basically, this was hacked away in just a few hours, so don't expect |
5 | miracles. | 5 | miracles. |
6 | |||
6 | In particular, there is currently NO support for the rumble pack. | 7 | In particular, there is currently NO support for the rumble pack. |
7 | You won't find many ff-aware linux applications anyway. | 8 | You won't find many ff-aware linux applications anyway. |
8 | 9 | ||
9 | 10 | ||
10 | 0. Status | 11 | 0. Notes |
11 | --------- | 12 | -------- |
13 | |||
14 | Driver updated for kernel 2.6.17.11. (Based on a patch for 2.6.11.4.) | ||
12 | 15 | ||
13 | For now, this driver has only been tested on just one Linux-Box. | 16 | The number of buttons/axes reported varies based on 3 things: |
14 | This one is running a 2.4.18 kernel with usb-uhci on an amd athlon 600. | 17 | - if you are using a known controller |
18 | - if you are using a known dance pad | ||
19 | - if using an unknown device (one not listed below), what you set in the | ||
20 | module configuration for "Map D-PAD to buttons rather than axes for unknown | ||
21 | pads" (module option dpad_to_buttons) | ||
15 | 22 | ||
16 | The jstest-program from joystick-1.2.15 (jstest-version 2.1.0) reports | 23 | If you set dpad_to_buttons to 0 and you are using an unknown device (one |
17 | 8 axes and 10 buttons. | 24 | not listed below), the driver will map the directional pad to axes (X/Y), |
25 | if you said N it will map the d-pad to buttons, which is needed for dance | ||
26 | style games to function correctly. The default is Y. | ||
27 | |||
28 | dpad_to_buttons has no effect for known pads. | ||
29 | |||
30 | 0.1 Normal Controllers | ||
31 | ---------------------- | ||
32 | With a normal controller, the directional pad is mapped to its own X/Y axes. | ||
33 | The jstest-program from joystick-1.2.15 (jstest-version 2.1.0) will report 8 | ||
34 | axes and 10 buttons. | ||
18 | 35 | ||
19 | Alls 8 axes work, though they all have the same range (-32768..32767) | 36 | All 8 axes work, though they all have the same range (-32768..32767) |
20 | and the zero-setting is not correct for the triggers (I don't know if that | 37 | and the zero-setting is not correct for the triggers (I don't know if that |
21 | is some limitation of jstest, since the input device setup should be fine. I | 38 | is some limitation of jstest, since the input device setup should be fine. I |
22 | didn't have a look at jstest itself yet). | 39 | didn't have a look at jstest itself yet). |
@@ -30,16 +47,50 @@ in game functionality were OK. However, I find it rather difficult to | |||
30 | play first person shooters with a pad. Your mileage may vary. | 47 | play first person shooters with a pad. Your mileage may vary. |
31 | 48 | ||
32 | 49 | ||
50 | 0.2 Xbox Dance Pads | ||
51 | ------------------- | ||
52 | When using a known dance pad, jstest will report 6 axes and 14 buttons. | ||
53 | |||
54 | For dance style pads (like the redoctane pad) several changes | ||
55 | have been made. The old driver would map the d-pad to axes, resulting | ||
56 | in the driver being unable to report when the user was pressing both | ||
57 | left+right or up+down, making DDR style games unplayable. | ||
58 | |||
59 | Known dance pads automatically map the d-pad to buttons and will work | ||
60 | correctly out of the box. | ||
61 | |||
62 | If your dance pad is recognized by the driver but is using axes instead | ||
63 | of buttons, see section 0.3 - Unknown Controllers | ||
64 | |||
65 | I've tested this with Stepmania, and it works quite well. | ||
66 | |||
67 | |||
68 | 0.3 Unkown Controllers | ||
69 | ---------------------- | ||
70 | If you have an unkown xbox controller, it should work just fine with | ||
71 | the default settings. | ||
72 | |||
73 | HOWEVER if you have an unknown dance pad not listed below, it will not | ||
74 | work UNLESS you set "dpad_to_buttons" to 1 in the module configuration. | ||
75 | |||
76 | PLEASE if you have an unkown controller, email Dom <binary1230@yahoo.com> with | ||
77 | a dump from /proc/bus/usb and a description of the pad (manufacturer, country, | ||
78 | whether it is a dance pad or normal controller) so that we can add your pad | ||
79 | to the list of supported devices, ensuring that it will work out of the | ||
80 | box in the future. | ||
81 | |||
82 | |||
33 | 1. USB adapter | 83 | 1. USB adapter |
34 | -------------- | 84 | -------------- |
35 | 85 | ||
36 | Before you can actually use the driver, you need to get yourself an | 86 | Before you can actually use the driver, you need to get yourself an |
37 | adapter cable to connect the X-Box controller to your Linux-Box. | 87 | adapter cable to connect the X-Box controller to your Linux-Box. You |
88 | can buy these online fairly cheap, or build your own. | ||
38 | 89 | ||
39 | Such a cable is pretty easy to build. The Controller itself is a USB compound | 90 | Such a cable is pretty easy to build. The Controller itself is a USB |
40 | device (a hub with three ports for two expansion slots and the controller | 91 | compound device (a hub with three ports for two expansion slots and |
41 | device) with the only difference in a nonstandard connector (5 pins vs. 4 on | 92 | the controller device) with the only difference in a nonstandard connector |
42 | standard USB connector). | 93 | (5 pins vs. 4 on standard USB connector). |
43 | 94 | ||
44 | You just need to solder a USB connector onto the cable and keep the | 95 | You just need to solder a USB connector onto the cable and keep the |
45 | yellow wire unconnected. The other pins have the same order on both | 96 | yellow wire unconnected. The other pins have the same order on both |
@@ -51,36 +102,36 @@ original one. You can buy an extension cable and cut that instead. That way, | |||
51 | you can still use the controller with your X-Box, if you have one ;) | 102 | you can still use the controller with your X-Box, if you have one ;) |
52 | 103 | ||
53 | 104 | ||
54 | 2. driver installation | 105 | 2. Driver Installation |
55 | ---------------------- | 106 | ---------------------- |
56 | 107 | ||
57 | Once you have the adapter cable and the controller is connected, you need | 108 | Once you have the adapter cable and the controller is connected, you need |
58 | to load your USB subsystem and should cat /proc/bus/usb/devices. | 109 | to load your USB subsystem and should cat /proc/bus/usb/devices. |
59 | There should be an entry like the one at the end [4]. | 110 | There should be an entry like the one at the end [4]. |
60 | 111 | ||
61 | Currently (as of version 0.0.4), the following three devices are included: | 112 | Currently (as of version 0.0.6), the following devices are included: |
62 | original Microsoft XBOX controller (US), vendor=0x045e, product=0x0202 | 113 | original Microsoft XBOX controller (US), vendor=0x045e, product=0x0202 |
114 | smaller Microsoft XBOX controller (US), vendor=0x045e, product=0x0289 | ||
63 | original Microsoft XBOX controller (Japan), vendor=0x045e, product=0x0285 | 115 | original Microsoft XBOX controller (Japan), vendor=0x045e, product=0x0285 |
64 | InterAct PowerPad Pro (Germany), vendor=0x05fd, product=0x107a | 116 | InterAct PowerPad Pro (Germany), vendor=0x05fd, product=0x107a |
117 | RedOctane Xbox Dance Pad (US), vendor=0x0c12, product=0x8809 | ||
65 | 118 | ||
66 | If you have another controller that is not listed above and is not recognized | 119 | The driver should work with xbox pads not listed above as well, however |
67 | by the driver, please drop me a line with the appropriate info (that is, include | 120 | you will need to do something extra for dance pads to work. |
68 | the name, vendor and product ID, as well as the country where you bought it; | ||
69 | sending the whole dump out of /proc/bus/usb/devices along would be even better). | ||
70 | 121 | ||
71 | In theory, the driver should work with other controllers than mine | 122 | If you have a controller not listed above, see 0.3 - Unknown Controllers |
72 | (InterAct PowerPad pro, bought in Germany) just fine, but I cannot test this | ||
73 | for I only have this one controller. | ||
74 | 123 | ||
75 | If you compiled and installed the driver, test the functionality: | 124 | If you compiled and installed the driver, test the functionality: |
76 | > modprobe xpad | 125 | > modprobe xpad |
77 | > modprobe joydev | 126 | > modprobe joydev |
78 | > jstest /dev/js0 | 127 | > jstest /dev/js0 |
79 | 128 | ||
80 | There should be a single line showing 18 inputs (8 axes, 10 buttons), and | 129 | If you're using a normal controller, there should be a single line showing |
81 | it's values should change if you move the sticks and push the buttons. | 130 | 18 inputs (8 axes, 10 buttons), and its values should change if you move |
131 | the sticks and push the buttons. If you're using a dance pad, it should | ||
132 | show 20 inputs (6 axes, 14 buttons). | ||
82 | 133 | ||
83 | It works? Voila, your done ;) | 134 | It works? Voila, you're done ;) |
84 | 135 | ||
85 | 136 | ||
86 | 3. Thanks | 137 | 3. Thanks |
@@ -111,6 +162,22 @@ I: If#= 0 Alt= 0 #EPs= 2 Cls=58(unk. ) Sub=42 Prot=00 Driver=(none) | |||
111 | E: Ad=81(I) Atr=03(Int.) MxPS= 32 Ivl= 10ms | 162 | E: Ad=81(I) Atr=03(Int.) MxPS= 32 Ivl= 10ms |
112 | E: Ad=02(O) Atr=03(Int.) MxPS= 32 Ivl= 10ms | 163 | E: Ad=02(O) Atr=03(Int.) MxPS= 32 Ivl= 10ms |
113 | 164 | ||
165 | 5. /proc/bus/usb/devices - dump from Redoctane Xbox Dance Pad (US): | ||
166 | |||
167 | T: Bus=01 Lev=02 Prnt=09 Port=00 Cnt=01 Dev#= 10 Spd=12 MxCh= 0 | ||
168 | D: Ver= 1.10 Cls=00(>ifc ) Sub=00 Prot=00 MxPS= 8 #Cfgs= 1 | ||
169 | P: Vendor=0c12 ProdID=8809 Rev= 0.01 | ||
170 | S: Product=XBOX DDR | ||
171 | C:* #Ifs= 1 Cfg#= 1 Atr=80 MxPwr=100mA | ||
172 | I: If#= 0 Alt= 0 #EPs= 2 Cls=58(unk. ) Sub=42 Prot=00 Driver=xpad | ||
173 | E: Ad=82(I) Atr=03(Int.) MxPS= 32 Ivl=4ms | ||
174 | E: Ad=02(O) Atr=03(Int.) MxPS= 32 Ivl=4ms | ||
175 | |||
114 | -- | 176 | -- |
115 | Marko Friedemann <mfr@bmx-chemnitz.de> | 177 | Marko Friedemann <mfr@bmx-chemnitz.de> |
116 | 2002-07-16 | 178 | 2002-07-16 |
179 | - original doc | ||
180 | |||
181 | Dominic Cerquetti <binary1230@yahoo.com> | ||
182 | 2005-03-19 | ||
183 | - added stuff for dance pads, new d-pad->axes mappings | ||
diff --git a/drivers/usb/input/xpad.c b/drivers/usb/input/xpad.c index cebb6c463bfb..6a12a943b938 100644 --- a/drivers/usb/input/xpad.c +++ b/drivers/usb/input/xpad.c | |||
@@ -1,8 +1,9 @@ | |||
1 | /* | 1 | /* |
2 | * X-Box gamepad - v0.0.5 | 2 | * X-Box gamepad - v0.0.6 |
3 | * | 3 | * |
4 | * Copyright (c) 2002 Marko Friedemann <mfr@bmx-chemnitz.de> | 4 | * Copyright (c) 2002 Marko Friedemann <mfr@bmx-chemnitz.de> |
5 | * | 5 | * 2005 Dominic Cerquetti <binary1230@yahoo.com> |
6 | * 2006 Adam Buchbinder <adam.buchbinder@gmail.com> | ||
6 | * | 7 | * |
7 | * This program is free software; you can redistribute it and/or | 8 | * This program is free software; you can redistribute it and/or |
8 | * modify it under the terms of the GNU General Public License as | 9 | * modify it under the terms of the GNU General Public License as |
@@ -30,9 +31,10 @@ | |||
30 | * - Greg Kroah-Hartman - usb-skeleton driver | 31 | * - Greg Kroah-Hartman - usb-skeleton driver |
31 | * | 32 | * |
32 | * TODO: | 33 | * TODO: |
33 | * - fine tune axes | 34 | * - fine tune axes (especially trigger axes) |
34 | * - fix "analog" buttons (reported as digital now) | 35 | * - fix "analog" buttons (reported as digital now) |
35 | * - get rumble working | 36 | * - get rumble working |
37 | * - need USB IDs for other dance pads | ||
36 | * | 38 | * |
37 | * History: | 39 | * History: |
38 | * | 40 | * |
@@ -57,25 +59,40 @@ | |||
57 | #include <linux/kernel.h> | 59 | #include <linux/kernel.h> |
58 | #include <linux/init.h> | 60 | #include <linux/init.h> |
59 | #include <linux/slab.h> | 61 | #include <linux/slab.h> |
62 | #include <linux/stat.h> | ||
60 | #include <linux/module.h> | 63 | #include <linux/module.h> |
64 | #include <linux/moduleparam.h> | ||
61 | #include <linux/smp_lock.h> | 65 | #include <linux/smp_lock.h> |
62 | #include <linux/usb/input.h> | 66 | #include <linux/usb/input.h> |
63 | 67 | ||
64 | #define DRIVER_VERSION "v0.0.5" | 68 | #define DRIVER_VERSION "v0.0.6" |
65 | #define DRIVER_AUTHOR "Marko Friedemann <mfr@bmx-chemnitz.de>" | 69 | #define DRIVER_AUTHOR "Marko Friedemann <mfr@bmx-chemnitz.de>" |
66 | #define DRIVER_DESC "X-Box pad driver" | 70 | #define DRIVER_DESC "X-Box pad driver" |
67 | 71 | ||
68 | #define XPAD_PKT_LEN 32 | 72 | #define XPAD_PKT_LEN 32 |
69 | 73 | ||
74 | /* xbox d-pads should map to buttons, as is required for DDR pads | ||
75 | but we map them to axes when possible to simplify things */ | ||
76 | #define MAP_DPAD_TO_BUTTONS 0 | ||
77 | #define MAP_DPAD_TO_AXES 1 | ||
78 | #define MAP_DPAD_UNKNOWN -1 | ||
79 | |||
80 | static int dpad_to_buttons; | ||
81 | module_param(dpad_to_buttons, bool, S_IRUGO); | ||
82 | MODULE_PARM_DESC(dpad_to_buttons, "Map D-PAD to buttons rather than axes for unknown pads"); | ||
83 | |||
70 | static const struct xpad_device { | 84 | static const struct xpad_device { |
71 | u16 idVendor; | 85 | u16 idVendor; |
72 | u16 idProduct; | 86 | u16 idProduct; |
73 | char *name; | 87 | char *name; |
88 | u8 dpad_mapping; | ||
74 | } xpad_device[] = { | 89 | } xpad_device[] = { |
75 | { 0x045e, 0x0202, "Microsoft X-Box pad (US)" }, | 90 | { 0x045e, 0x0202, "Microsoft X-Box pad v1 (US)", MAP_DPAD_TO_AXES }, |
76 | { 0x045e, 0x0285, "Microsoft X-Box pad (Japan)" }, | 91 | { 0x045e, 0x0289, "Microsoft X-Box pad v2 (US)", MAP_DPAD_TO_AXES }, |
77 | { 0x05fd, 0x107a, "InterAct 'PowerPad Pro' X-Box pad (Germany)" }, | 92 | { 0x045e, 0x0285, "Microsoft X-Box pad (Japan)", MAP_DPAD_TO_AXES }, |
78 | { 0x0000, 0x0000, "X-Box pad" } | 93 | { 0x05fd, 0x107a, "InterAct 'PowerPad Pro' X-Box pad (Germany)", MAP_DPAD_TO_AXES }, |
94 | { 0x0c12, 0x8809, "RedOctane Xbox Dance Pad", MAP_DPAD_TO_BUTTONS }, | ||
95 | { 0x0000, 0x0000, "Generic X-Box pad", MAP_DPAD_UNKNOWN } | ||
79 | }; | 96 | }; |
80 | 97 | ||
81 | static const signed short xpad_btn[] = { | 98 | static const signed short xpad_btn[] = { |
@@ -84,11 +101,23 @@ static const signed short xpad_btn[] = { | |||
84 | -1 /* terminating entry */ | 101 | -1 /* terminating entry */ |
85 | }; | 102 | }; |
86 | 103 | ||
104 | /* only used if MAP_DPAD_TO_BUTTONS */ | ||
105 | static const signed short xpad_btn_pad[] = { | ||
106 | BTN_LEFT, BTN_RIGHT, /* d-pad left, right */ | ||
107 | BTN_0, BTN_1, /* d-pad up, down (XXX names??) */ | ||
108 | -1 /* terminating entry */ | ||
109 | }; | ||
110 | |||
87 | static const signed short xpad_abs[] = { | 111 | static const signed short xpad_abs[] = { |
88 | ABS_X, ABS_Y, /* left stick */ | 112 | ABS_X, ABS_Y, /* left stick */ |
89 | ABS_RX, ABS_RY, /* right stick */ | 113 | ABS_RX, ABS_RY, /* right stick */ |
90 | ABS_Z, ABS_RZ, /* triggers left/right */ | 114 | ABS_Z, ABS_RZ, /* triggers left/right */ |
91 | ABS_HAT0X, ABS_HAT0Y, /* digital pad */ | 115 | -1 /* terminating entry */ |
116 | }; | ||
117 | |||
118 | /* only used if MAP_DPAD_TO_AXES */ | ||
119 | static const signed short xpad_abs_pad[] = { | ||
120 | ABS_HAT0X, ABS_HAT0Y, /* d-pad axes */ | ||
92 | -1 /* terminating entry */ | 121 | -1 /* terminating entry */ |
93 | }; | 122 | }; |
94 | 123 | ||
@@ -100,14 +129,16 @@ static struct usb_device_id xpad_table [] = { | |||
100 | MODULE_DEVICE_TABLE (usb, xpad_table); | 129 | MODULE_DEVICE_TABLE (usb, xpad_table); |
101 | 130 | ||
102 | struct usb_xpad { | 131 | struct usb_xpad { |
103 | struct input_dev *dev; /* input device interface */ | 132 | struct input_dev *dev; /* input device interface */ |
104 | struct usb_device *udev; /* usb device */ | 133 | struct usb_device *udev; /* usb device */ |
105 | 134 | ||
106 | struct urb *irq_in; /* urb for interrupt in report */ | 135 | struct urb *irq_in; /* urb for interrupt in report */ |
107 | unsigned char *idata; /* input data */ | 136 | unsigned char *idata; /* input data */ |
108 | dma_addr_t idata_dma; | 137 | dma_addr_t idata_dma; |
109 | 138 | ||
110 | char phys[65]; /* physical device path */ | 139 | char phys[65]; /* physical device path */ |
140 | |||
141 | int dpad_mapping; /* map d-pad to buttons or to axes */ | ||
111 | }; | 142 | }; |
112 | 143 | ||
113 | /* | 144 | /* |
@@ -137,14 +168,21 @@ static void xpad_process_packet(struct usb_xpad *xpad, u16 cmd, unsigned char *d | |||
137 | input_report_abs(dev, ABS_RZ, data[11]); | 168 | input_report_abs(dev, ABS_RZ, data[11]); |
138 | 169 | ||
139 | /* digital pad */ | 170 | /* digital pad */ |
140 | input_report_abs(dev, ABS_HAT0X, !!(data[2] & 0x08) - !!(data[2] & 0x04)); | 171 | if (xpad->dpad_mapping == MAP_DPAD_TO_AXES) { |
141 | input_report_abs(dev, ABS_HAT0Y, !!(data[2] & 0x02) - !!(data[2] & 0x01)); | 172 | input_report_abs(dev, ABS_HAT0X, !!(data[2] & 0x08) - !!(data[2] & 0x04)); |
173 | input_report_abs(dev, ABS_HAT0Y, !!(data[2] & 0x02) - !!(data[2] & 0x01)); | ||
174 | } else /* xpad->dpad_mapping == MAP_DPAD_TO_BUTTONS */ { | ||
175 | input_report_key(dev, BTN_LEFT, data[2] & 0x04); | ||
176 | input_report_key(dev, BTN_RIGHT, data[2] & 0x08); | ||
177 | input_report_key(dev, BTN_0, data[2] & 0x01); // up | ||
178 | input_report_key(dev, BTN_1, data[2] & 0x02); // down | ||
179 | } | ||
142 | 180 | ||
143 | /* start/back buttons and stick press left/right */ | 181 | /* start/back buttons and stick press left/right */ |
144 | input_report_key(dev, BTN_START, (data[2] & 0x10) >> 4); | 182 | input_report_key(dev, BTN_START, data[2] & 0x10); |
145 | input_report_key(dev, BTN_BACK, (data[2] & 0x20) >> 5); | 183 | input_report_key(dev, BTN_BACK, data[2] & 0x20); |
146 | input_report_key(dev, BTN_THUMBL, (data[2] & 0x40) >> 6); | 184 | input_report_key(dev, BTN_THUMBL, data[2] & 0x40); |
147 | input_report_key(dev, BTN_THUMBR, data[2] >> 7); | 185 | input_report_key(dev, BTN_THUMBR, data[2] & 0x80); |
148 | 186 | ||
149 | /* "analog" buttons A, B, X, Y */ | 187 | /* "analog" buttons A, B, X, Y */ |
150 | input_report_key(dev, BTN_A, data[4]); | 188 | input_report_key(dev, BTN_A, data[4]); |
@@ -206,6 +244,28 @@ static void xpad_close (struct input_dev *dev) | |||
206 | usb_kill_urb(xpad->irq_in); | 244 | usb_kill_urb(xpad->irq_in); |
207 | } | 245 | } |
208 | 246 | ||
247 | static void xpad_set_up_abs(struct input_dev *input_dev, signed short abs) | ||
248 | { | ||
249 | set_bit(abs, input_dev->absbit); | ||
250 | |||
251 | switch (abs) { | ||
252 | case ABS_X: | ||
253 | case ABS_Y: | ||
254 | case ABS_RX: | ||
255 | case ABS_RY: /* the two sticks */ | ||
256 | input_set_abs_params(input_dev, abs, -32768, 32767, 16, 128); | ||
257 | break; | ||
258 | case ABS_Z: | ||
259 | case ABS_RZ: /* the triggers */ | ||
260 | input_set_abs_params(input_dev, abs, 0, 255, 0, 0); | ||
261 | break; | ||
262 | case ABS_HAT0X: | ||
263 | case ABS_HAT0Y: /* the d-pad (only if MAP_DPAD_TO_AXES) */ | ||
264 | input_set_abs_params(input_dev, abs, -1, 1, 0, 0); | ||
265 | break; | ||
266 | } | ||
267 | } | ||
268 | |||
209 | static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id) | 269 | static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id) |
210 | { | 270 | { |
211 | struct usb_device *udev = interface_to_usbdev (intf); | 271 | struct usb_device *udev = interface_to_usbdev (intf); |
@@ -235,6 +295,9 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id | |||
235 | goto fail2; | 295 | goto fail2; |
236 | 296 | ||
237 | xpad->udev = udev; | 297 | xpad->udev = udev; |
298 | xpad->dpad_mapping = xpad_device[i].dpad_mapping; | ||
299 | if (xpad->dpad_mapping == MAP_DPAD_UNKNOWN) | ||
300 | xpad->dpad_mapping = dpad_to_buttons; | ||
238 | xpad->dev = input_dev; | 301 | xpad->dev = input_dev; |
239 | usb_make_path(udev, xpad->phys, sizeof(xpad->phys)); | 302 | usb_make_path(udev, xpad->phys, sizeof(xpad->phys)); |
240 | strlcat(xpad->phys, "/input0", sizeof(xpad->phys)); | 303 | strlcat(xpad->phys, "/input0", sizeof(xpad->phys)); |
@@ -249,32 +312,19 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id | |||
249 | 312 | ||
250 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); | 313 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); |
251 | 314 | ||
315 | /* set up buttons */ | ||
252 | for (i = 0; xpad_btn[i] >= 0; i++) | 316 | for (i = 0; xpad_btn[i] >= 0; i++) |
253 | set_bit(xpad_btn[i], input_dev->keybit); | 317 | set_bit(xpad_btn[i], input_dev->keybit); |
318 | if (xpad->dpad_mapping == MAP_DPAD_TO_BUTTONS) | ||
319 | for (i = 0; xpad_btn_pad[i] >= 0; i++) | ||
320 | set_bit(xpad_btn_pad[i], input_dev->keybit); | ||
254 | 321 | ||
255 | for (i = 0; xpad_abs[i] >= 0; i++) { | 322 | /* set up axes */ |
256 | 323 | for (i = 0; xpad_abs[i] >= 0; i++) | |
257 | signed short t = xpad_abs[i]; | 324 | xpad_set_up_abs(input_dev, xpad_abs[i]); |
258 | 325 | if (xpad->dpad_mapping == MAP_DPAD_TO_AXES) | |
259 | set_bit(t, input_dev->absbit); | 326 | for (i = 0; xpad_abs_pad[i] >= 0; i++) |
260 | 327 | xpad_set_up_abs(input_dev, xpad_abs_pad[i]); | |
261 | switch (t) { | ||
262 | case ABS_X: | ||
263 | case ABS_Y: | ||
264 | case ABS_RX: | ||
265 | case ABS_RY: /* the two sticks */ | ||
266 | input_set_abs_params(input_dev, t, -32768, 32767, 16, 128); | ||
267 | break; | ||
268 | case ABS_Z: | ||
269 | case ABS_RZ: /* the triggers */ | ||
270 | input_set_abs_params(input_dev, t, 0, 255, 0, 0); | ||
271 | break; | ||
272 | case ABS_HAT0X: | ||
273 | case ABS_HAT0Y: /* the d-pad */ | ||
274 | input_set_abs_params(input_dev, t, -1, 1, 0, 0); | ||
275 | break; | ||
276 | } | ||
277 | } | ||
278 | 328 | ||
279 | ep_irq_in = &intf->cur_altsetting->endpoint[0].desc; | 329 | ep_irq_in = &intf->cur_altsetting->endpoint[0].desc; |
280 | usb_fill_int_urb(xpad->irq_in, udev, | 330 | usb_fill_int_urb(xpad->irq_in, udev, |
@@ -305,7 +355,8 @@ static void xpad_disconnect(struct usb_interface *intf) | |||
305 | usb_kill_urb(xpad->irq_in); | 355 | usb_kill_urb(xpad->irq_in); |
306 | input_unregister_device(xpad->dev); | 356 | input_unregister_device(xpad->dev); |
307 | usb_free_urb(xpad->irq_in); | 357 | usb_free_urb(xpad->irq_in); |
308 | usb_buffer_free(interface_to_usbdev(intf), XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); | 358 | usb_buffer_free(interface_to_usbdev(intf), XPAD_PKT_LEN, |
359 | xpad->idata, xpad->idata_dma); | ||
309 | kfree(xpad); | 360 | kfree(xpad); |
310 | } | 361 | } |
311 | } | 362 | } |