diff options
Diffstat (limited to 'drivers/input/joystick')
-rw-r--r-- | drivers/input/joystick/Kconfig | 10 | ||||
-rw-r--r-- | drivers/input/joystick/Makefile | 1 | ||||
-rw-r--r-- | drivers/input/joystick/a3d.c | 4 | ||||
-rw-r--r-- | drivers/input/joystick/as5011.c | 367 | ||||
-rw-r--r-- | drivers/input/joystick/gamecon.c | 3 | ||||
-rw-r--r-- | drivers/input/joystick/iforce/Makefile | 15 | ||||
-rw-r--r-- | drivers/input/joystick/turbografx.c | 1 | ||||
-rw-r--r-- | drivers/input/joystick/xpad.c | 123 |
8 files changed, 456 insertions, 68 deletions
diff --git a/drivers/input/joystick/Kconfig b/drivers/input/joystick/Kconfig index 5b596165b571..56eb471b5576 100644 --- a/drivers/input/joystick/Kconfig +++ b/drivers/input/joystick/Kconfig | |||
@@ -255,6 +255,16 @@ config JOYSTICK_AMIGA | |||
255 | To compile this driver as a module, choose M here: the | 255 | To compile this driver as a module, choose M here: the |
256 | module will be called amijoy. | 256 | module will be called amijoy. |
257 | 257 | ||
258 | config JOYSTICK_AS5011 | ||
259 | tristate "Austria Microsystem AS5011 joystick" | ||
260 | depends on I2C | ||
261 | help | ||
262 | Say Y here if you have an AS5011 digital joystick connected to your | ||
263 | system. | ||
264 | |||
265 | To compile this driver as a module, choose M here: the | ||
266 | module will be called as5011. | ||
267 | |||
258 | config JOYSTICK_JOYDUMP | 268 | config JOYSTICK_JOYDUMP |
259 | tristate "Gameport data dumper" | 269 | tristate "Gameport data dumper" |
260 | select GAMEPORT | 270 | select GAMEPORT |
diff --git a/drivers/input/joystick/Makefile b/drivers/input/joystick/Makefile index f3a8cbe2abb6..92dc0de9dfed 100644 --- a/drivers/input/joystick/Makefile +++ b/drivers/input/joystick/Makefile | |||
@@ -7,6 +7,7 @@ | |||
7 | obj-$(CONFIG_JOYSTICK_A3D) += a3d.o | 7 | obj-$(CONFIG_JOYSTICK_A3D) += a3d.o |
8 | obj-$(CONFIG_JOYSTICK_ADI) += adi.o | 8 | obj-$(CONFIG_JOYSTICK_ADI) += adi.o |
9 | obj-$(CONFIG_JOYSTICK_AMIGA) += amijoy.o | 9 | obj-$(CONFIG_JOYSTICK_AMIGA) += amijoy.o |
10 | obj-$(CONFIG_JOYSTICK_AS5011) += as5011.o | ||
10 | obj-$(CONFIG_JOYSTICK_ANALOG) += analog.o | 11 | obj-$(CONFIG_JOYSTICK_ANALOG) += analog.o |
11 | obj-$(CONFIG_JOYSTICK_COBRA) += cobra.o | 12 | obj-$(CONFIG_JOYSTICK_COBRA) += cobra.o |
12 | obj-$(CONFIG_JOYSTICK_DB9) += db9.o | 13 | obj-$(CONFIG_JOYSTICK_DB9) += db9.o |
diff --git a/drivers/input/joystick/a3d.c b/drivers/input/joystick/a3d.c index d259b41354b8..1639ab2b94b7 100644 --- a/drivers/input/joystick/a3d.c +++ b/drivers/input/joystick/a3d.c | |||
@@ -3,7 +3,7 @@ | |||
3 | */ | 3 | */ |
4 | 4 | ||
5 | /* | 5 | /* |
6 | * FP-Gaming Assasin 3D joystick driver for Linux | 6 | * FP-Gaming Assassin 3D joystick driver for Linux |
7 | */ | 7 | */ |
8 | 8 | ||
9 | /* | 9 | /* |
@@ -34,7 +34,7 @@ | |||
34 | #include <linux/input.h> | 34 | #include <linux/input.h> |
35 | #include <linux/jiffies.h> | 35 | #include <linux/jiffies.h> |
36 | 36 | ||
37 | #define DRIVER_DESC "FP-Gaming Assasin 3D joystick driver" | 37 | #define DRIVER_DESC "FP-Gaming Assassin 3D joystick driver" |
38 | 38 | ||
39 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); | 39 | MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>"); |
40 | MODULE_DESCRIPTION(DRIVER_DESC); | 40 | MODULE_DESCRIPTION(DRIVER_DESC); |
diff --git a/drivers/input/joystick/as5011.c b/drivers/input/joystick/as5011.c new file mode 100644 index 000000000000..f6732b57ca07 --- /dev/null +++ b/drivers/input/joystick/as5011.c | |||
@@ -0,0 +1,367 @@ | |||
1 | /* | ||
2 | * Copyright (c) 2010, 2011 Fabien Marteau <fabien.marteau@armadeus.com> | ||
3 | * Sponsored by ARMadeus Systems | ||
4 | * | ||
5 | * This program is free software; you can redistribute it and/or modify | ||
6 | * it under the terms of the GNU General Public License as published by | ||
7 | * the Free Software Foundation; either version 2 of the License, or | ||
8 | * (at your option) any later version. | ||
9 | * | ||
10 | * This program is distributed in the hope that it will be useful, | ||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
13 | * GNU General Public License for more details. | ||
14 | * | ||
15 | * You should have received a copy of the GNU General Public License | ||
16 | * along with this program; if not, write to the Free Software | ||
17 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
18 | * | ||
19 | * Driver for Austria Microsystems joysticks AS5011 | ||
20 | * | ||
21 | * TODO: | ||
22 | * - Power on the chip when open() and power down when close() | ||
23 | * - Manage power mode | ||
24 | */ | ||
25 | |||
26 | #include <linux/i2c.h> | ||
27 | #include <linux/interrupt.h> | ||
28 | #include <linux/input.h> | ||
29 | #include <linux/gpio.h> | ||
30 | #include <linux/delay.h> | ||
31 | #include <linux/input/as5011.h> | ||
32 | #include <linux/slab.h> | ||
33 | |||
34 | #define DRIVER_DESC "Driver for Austria Microsystems AS5011 joystick" | ||
35 | #define MODULE_DEVICE_ALIAS "as5011" | ||
36 | |||
37 | MODULE_AUTHOR("Fabien Marteau <fabien.marteau@armadeus.com>"); | ||
38 | MODULE_DESCRIPTION(DRIVER_DESC); | ||
39 | MODULE_LICENSE("GPL"); | ||
40 | |||
41 | /* registers */ | ||
42 | #define AS5011_CTRL1 0x76 | ||
43 | #define AS5011_CTRL2 0x75 | ||
44 | #define AS5011_XP 0x43 | ||
45 | #define AS5011_XN 0x44 | ||
46 | #define AS5011_YP 0x53 | ||
47 | #define AS5011_YN 0x54 | ||
48 | #define AS5011_X_REG 0x41 | ||
49 | #define AS5011_Y_REG 0x42 | ||
50 | #define AS5011_X_RES_INT 0x51 | ||
51 | #define AS5011_Y_RES_INT 0x52 | ||
52 | |||
53 | /* CTRL1 bits */ | ||
54 | #define AS5011_CTRL1_LP_PULSED 0x80 | ||
55 | #define AS5011_CTRL1_LP_ACTIVE 0x40 | ||
56 | #define AS5011_CTRL1_LP_CONTINUE 0x20 | ||
57 | #define AS5011_CTRL1_INT_WUP_EN 0x10 | ||
58 | #define AS5011_CTRL1_INT_ACT_EN 0x08 | ||
59 | #define AS5011_CTRL1_EXT_CLK_EN 0x04 | ||
60 | #define AS5011_CTRL1_SOFT_RST 0x02 | ||
61 | #define AS5011_CTRL1_DATA_VALID 0x01 | ||
62 | |||
63 | /* CTRL2 bits */ | ||
64 | #define AS5011_CTRL2_EXT_SAMPLE_EN 0x08 | ||
65 | #define AS5011_CTRL2_RC_BIAS_ON 0x04 | ||
66 | #define AS5011_CTRL2_INV_SPINNING 0x02 | ||
67 | |||
68 | #define AS5011_MAX_AXIS 80 | ||
69 | #define AS5011_MIN_AXIS (-80) | ||
70 | #define AS5011_FUZZ 8 | ||
71 | #define AS5011_FLAT 40 | ||
72 | |||
73 | struct as5011_device { | ||
74 | struct input_dev *input_dev; | ||
75 | struct i2c_client *i2c_client; | ||
76 | unsigned int button_gpio; | ||
77 | unsigned int button_irq; | ||
78 | unsigned int axis_irq; | ||
79 | }; | ||
80 | |||
81 | static int as5011_i2c_write(struct i2c_client *client, | ||
82 | uint8_t aregaddr, | ||
83 | uint8_t avalue) | ||
84 | { | ||
85 | uint8_t data[2] = { aregaddr, avalue }; | ||
86 | struct i2c_msg msg = { | ||
87 | client->addr, I2C_M_IGNORE_NAK, 2, (uint8_t *)data | ||
88 | }; | ||
89 | int error; | ||
90 | |||
91 | error = i2c_transfer(client->adapter, &msg, 1); | ||
92 | return error < 0 ? error : 0; | ||
93 | } | ||
94 | |||
95 | static int as5011_i2c_read(struct i2c_client *client, | ||
96 | uint8_t aregaddr, signed char *value) | ||
97 | { | ||
98 | uint8_t data[2] = { aregaddr }; | ||
99 | struct i2c_msg msg_set[2] = { | ||
100 | { client->addr, I2C_M_REV_DIR_ADDR, 1, (uint8_t *)data }, | ||
101 | { client->addr, I2C_M_RD | I2C_M_NOSTART, 1, (uint8_t *)data } | ||
102 | }; | ||
103 | int error; | ||
104 | |||
105 | error = i2c_transfer(client->adapter, msg_set, 2); | ||
106 | if (error < 0) | ||
107 | return error; | ||
108 | |||
109 | *value = data[0] & 0x80 ? -1 * (1 + ~data[0]) : data[0]; | ||
110 | return 0; | ||
111 | } | ||
112 | |||
113 | static irqreturn_t as5011_button_interrupt(int irq, void *dev_id) | ||
114 | { | ||
115 | struct as5011_device *as5011 = dev_id; | ||
116 | int val = gpio_get_value_cansleep(as5011->button_gpio); | ||
117 | |||
118 | input_report_key(as5011->input_dev, BTN_JOYSTICK, !val); | ||
119 | input_sync(as5011->input_dev); | ||
120 | |||
121 | return IRQ_HANDLED; | ||
122 | } | ||
123 | |||
124 | static irqreturn_t as5011_axis_interrupt(int irq, void *dev_id) | ||
125 | { | ||
126 | struct as5011_device *as5011 = dev_id; | ||
127 | int error; | ||
128 | signed char x, y; | ||
129 | |||
130 | error = as5011_i2c_read(as5011->i2c_client, AS5011_X_RES_INT, &x); | ||
131 | if (error < 0) | ||
132 | goto out; | ||
133 | |||
134 | error = as5011_i2c_read(as5011->i2c_client, AS5011_Y_RES_INT, &y); | ||
135 | if (error < 0) | ||
136 | goto out; | ||
137 | |||
138 | input_report_abs(as5011->input_dev, ABS_X, x); | ||
139 | input_report_abs(as5011->input_dev, ABS_Y, y); | ||
140 | input_sync(as5011->input_dev); | ||
141 | |||
142 | out: | ||
143 | return IRQ_HANDLED; | ||
144 | } | ||
145 | |||
146 | static int __devinit as5011_configure_chip(struct as5011_device *as5011, | ||
147 | const struct as5011_platform_data *plat_dat) | ||
148 | { | ||
149 | struct i2c_client *client = as5011->i2c_client; | ||
150 | int error; | ||
151 | signed char value; | ||
152 | |||
153 | /* chip soft reset */ | ||
154 | error = as5011_i2c_write(client, AS5011_CTRL1, | ||
155 | AS5011_CTRL1_SOFT_RST); | ||
156 | if (error < 0) { | ||
157 | dev_err(&client->dev, "Soft reset failed\n"); | ||
158 | return error; | ||
159 | } | ||
160 | |||
161 | mdelay(10); | ||
162 | |||
163 | error = as5011_i2c_write(client, AS5011_CTRL1, | ||
164 | AS5011_CTRL1_LP_PULSED | | ||
165 | AS5011_CTRL1_LP_ACTIVE | | ||
166 | AS5011_CTRL1_INT_ACT_EN); | ||
167 | if (error < 0) { | ||
168 | dev_err(&client->dev, "Power config failed\n"); | ||
169 | return error; | ||
170 | } | ||
171 | |||
172 | error = as5011_i2c_write(client, AS5011_CTRL2, | ||
173 | AS5011_CTRL2_INV_SPINNING); | ||
174 | if (error < 0) { | ||
175 | dev_err(&client->dev, "Can't invert spinning\n"); | ||
176 | return error; | ||
177 | } | ||
178 | |||
179 | /* write threshold */ | ||
180 | error = as5011_i2c_write(client, AS5011_XP, plat_dat->xp); | ||
181 | if (error < 0) { | ||
182 | dev_err(&client->dev, "Can't write threshold\n"); | ||
183 | return error; | ||
184 | } | ||
185 | |||
186 | error = as5011_i2c_write(client, AS5011_XN, plat_dat->xn); | ||
187 | if (error < 0) { | ||
188 | dev_err(&client->dev, "Can't write threshold\n"); | ||
189 | return error; | ||
190 | } | ||
191 | |||
192 | error = as5011_i2c_write(client, AS5011_YP, plat_dat->yp); | ||
193 | if (error < 0) { | ||
194 | dev_err(&client->dev, "Can't write threshold\n"); | ||
195 | return error; | ||
196 | } | ||
197 | |||
198 | error = as5011_i2c_write(client, AS5011_YN, plat_dat->yn); | ||
199 | if (error < 0) { | ||
200 | dev_err(&client->dev, "Can't write threshold\n"); | ||
201 | return error; | ||
202 | } | ||
203 | |||
204 | /* to free irq gpio in chip */ | ||
205 | error = as5011_i2c_read(client, AS5011_X_RES_INT, &value); | ||
206 | if (error < 0) { | ||
207 | dev_err(&client->dev, "Can't read i2c X resolution value\n"); | ||
208 | return error; | ||
209 | } | ||
210 | |||
211 | return 0; | ||
212 | } | ||
213 | |||
214 | static int __devinit as5011_probe(struct i2c_client *client, | ||
215 | const struct i2c_device_id *id) | ||
216 | { | ||
217 | const struct as5011_platform_data *plat_data; | ||
218 | struct as5011_device *as5011; | ||
219 | struct input_dev *input_dev; | ||
220 | int irq; | ||
221 | int error; | ||
222 | |||
223 | plat_data = client->dev.platform_data; | ||
224 | if (!plat_data) | ||
225 | return -EINVAL; | ||
226 | |||
227 | if (!plat_data->axis_irq) { | ||
228 | dev_err(&client->dev, "No axis IRQ?\n"); | ||
229 | return -EINVAL; | ||
230 | } | ||
231 | |||
232 | if (!i2c_check_functionality(client->adapter, | ||
233 | I2C_FUNC_PROTOCOL_MANGLING)) { | ||
234 | dev_err(&client->dev, | ||
235 | "need i2c bus that supports protocol mangling\n"); | ||
236 | return -ENODEV; | ||
237 | } | ||
238 | |||
239 | as5011 = kmalloc(sizeof(struct as5011_device), GFP_KERNEL); | ||
240 | input_dev = input_allocate_device(); | ||
241 | if (!as5011 || !input_dev) { | ||
242 | dev_err(&client->dev, | ||
243 | "Can't allocate memory for device structure\n"); | ||
244 | error = -ENOMEM; | ||
245 | goto err_free_mem; | ||
246 | } | ||
247 | |||
248 | as5011->i2c_client = client; | ||
249 | as5011->input_dev = input_dev; | ||
250 | as5011->button_gpio = plat_data->button_gpio; | ||
251 | as5011->axis_irq = plat_data->axis_irq; | ||
252 | |||
253 | input_dev->name = "Austria Microsystem as5011 joystick"; | ||
254 | input_dev->id.bustype = BUS_I2C; | ||
255 | input_dev->dev.parent = &client->dev; | ||
256 | |||
257 | __set_bit(EV_KEY, input_dev->evbit); | ||
258 | __set_bit(EV_ABS, input_dev->evbit); | ||
259 | __set_bit(BTN_JOYSTICK, input_dev->keybit); | ||
260 | |||
261 | input_set_abs_params(input_dev, ABS_X, | ||
262 | AS5011_MIN_AXIS, AS5011_MAX_AXIS, AS5011_FUZZ, AS5011_FLAT); | ||
263 | input_set_abs_params(as5011->input_dev, ABS_Y, | ||
264 | AS5011_MIN_AXIS, AS5011_MAX_AXIS, AS5011_FUZZ, AS5011_FLAT); | ||
265 | |||
266 | error = gpio_request(as5011->button_gpio, "AS5011 button"); | ||
267 | if (error < 0) { | ||
268 | dev_err(&client->dev, "Failed to request button gpio\n"); | ||
269 | goto err_free_mem; | ||
270 | } | ||
271 | |||
272 | irq = gpio_to_irq(as5011->button_gpio); | ||
273 | if (irq < 0) { | ||
274 | dev_err(&client->dev, | ||
275 | "Failed to get irq number for button gpio\n"); | ||
276 | goto err_free_button_gpio; | ||
277 | } | ||
278 | |||
279 | as5011->button_irq = irq; | ||
280 | |||
281 | error = request_threaded_irq(as5011->button_irq, | ||
282 | NULL, as5011_button_interrupt, | ||
283 | IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING, | ||
284 | "as5011_button", as5011); | ||
285 | if (error < 0) { | ||
286 | dev_err(&client->dev, | ||
287 | "Can't allocate button irq %d\n", as5011->button_irq); | ||
288 | goto err_free_button_gpio; | ||
289 | } | ||
290 | |||
291 | error = as5011_configure_chip(as5011, plat_data); | ||
292 | if (error) | ||
293 | goto err_free_button_irq; | ||
294 | |||
295 | error = request_threaded_irq(as5011->axis_irq, NULL, | ||
296 | as5011_axis_interrupt, | ||
297 | plat_data->axis_irqflags, | ||
298 | "as5011_joystick", as5011); | ||
299 | if (error) { | ||
300 | dev_err(&client->dev, | ||
301 | "Can't allocate axis irq %d\n", plat_data->axis_irq); | ||
302 | goto err_free_button_irq; | ||
303 | } | ||
304 | |||
305 | error = input_register_device(as5011->input_dev); | ||
306 | if (error) { | ||
307 | dev_err(&client->dev, "Failed to register input device\n"); | ||
308 | goto err_free_axis_irq; | ||
309 | } | ||
310 | |||
311 | i2c_set_clientdata(client, as5011); | ||
312 | |||
313 | return 0; | ||
314 | |||
315 | err_free_axis_irq: | ||
316 | free_irq(as5011->axis_irq, as5011); | ||
317 | err_free_button_irq: | ||
318 | free_irq(as5011->button_irq, as5011); | ||
319 | err_free_button_gpio: | ||
320 | gpio_free(as5011->button_gpio); | ||
321 | err_free_mem: | ||
322 | input_free_device(input_dev); | ||
323 | kfree(as5011); | ||
324 | |||
325 | return error; | ||
326 | } | ||
327 | |||
328 | static int __devexit as5011_remove(struct i2c_client *client) | ||
329 | { | ||
330 | struct as5011_device *as5011 = i2c_get_clientdata(client); | ||
331 | |||
332 | free_irq(as5011->axis_irq, as5011); | ||
333 | free_irq(as5011->button_irq, as5011); | ||
334 | gpio_free(as5011->button_gpio); | ||
335 | |||
336 | input_unregister_device(as5011->input_dev); | ||
337 | kfree(as5011); | ||
338 | |||
339 | return 0; | ||
340 | } | ||
341 | |||
342 | static const struct i2c_device_id as5011_id[] = { | ||
343 | { MODULE_DEVICE_ALIAS, 0 }, | ||
344 | { } | ||
345 | }; | ||
346 | MODULE_DEVICE_TABLE(i2c, as5011_id); | ||
347 | |||
348 | static struct i2c_driver as5011_driver = { | ||
349 | .driver = { | ||
350 | .name = "as5011", | ||
351 | }, | ||
352 | .probe = as5011_probe, | ||
353 | .remove = __devexit_p(as5011_remove), | ||
354 | .id_table = as5011_id, | ||
355 | }; | ||
356 | |||
357 | static int __init as5011_init(void) | ||
358 | { | ||
359 | return i2c_add_driver(&as5011_driver); | ||
360 | } | ||
361 | module_init(as5011_init); | ||
362 | |||
363 | static void __exit as5011_exit(void) | ||
364 | { | ||
365 | i2c_del_driver(&as5011_driver); | ||
366 | } | ||
367 | module_exit(as5011_exit); | ||
diff --git a/drivers/input/joystick/gamecon.c b/drivers/input/joystick/gamecon.c index 0ffaf2c77a19..e68e49786483 100644 --- a/drivers/input/joystick/gamecon.c +++ b/drivers/input/joystick/gamecon.c | |||
@@ -521,9 +521,8 @@ static void gc_multi_process_packet(struct gc *gc) | |||
521 | * PSX support | 521 | * PSX support |
522 | * | 522 | * |
523 | * See documentation at: | 523 | * See documentation at: |
524 | * http://www.dim.com/~mackys/psxmemcard/ps-eng2.txt | 524 | * http://www.geocities.co.jp/Playtown/2004/psx/ps_eng.txt |
525 | * http://www.gamesx.com/controldata/psxcont/psxcont.htm | 525 | * http://www.gamesx.com/controldata/psxcont/psxcont.htm |
526 | * ftp://milano.usal.es/pablo/ | ||
527 | * | 526 | * |
528 | */ | 527 | */ |
529 | 528 | ||
diff --git a/drivers/input/joystick/iforce/Makefile b/drivers/input/joystick/iforce/Makefile index 74daff49ab6e..bc5bda22f15e 100644 --- a/drivers/input/joystick/iforce/Makefile +++ b/drivers/input/joystick/iforce/Makefile | |||
@@ -4,17 +4,8 @@ | |||
4 | # By Johann Deneux <johann.deneux@gmail.com> | 4 | # By Johann Deneux <johann.deneux@gmail.com> |
5 | # | 5 | # |
6 | 6 | ||
7 | # Goal definition | ||
8 | iforce-objs := iforce-ff.o iforce-main.o iforce-packets.o | ||
9 | |||
10 | obj-$(CONFIG_JOYSTICK_IFORCE) += iforce.o | 7 | obj-$(CONFIG_JOYSTICK_IFORCE) += iforce.o |
11 | 8 | ||
12 | ifeq ($(CONFIG_JOYSTICK_IFORCE_232),y) | 9 | iforce-y := iforce-ff.o iforce-main.o iforce-packets.o |
13 | iforce-objs += iforce-serio.o | 10 | iforce-$(CONFIG_JOYSTICK_IFORCE_232) += iforce-serio.o |
14 | endif | 11 | iforce-$(CONFIG_JOYSTICK_IFORCE_USB) += iforce-usb.o |
15 | |||
16 | ifeq ($(CONFIG_JOYSTICK_IFORCE_USB),y) | ||
17 | iforce-objs += iforce-usb.o | ||
18 | endif | ||
19 | |||
20 | EXTRA_CFLAGS = -Werror-implicit-function-declaration | ||
diff --git a/drivers/input/joystick/turbografx.c b/drivers/input/joystick/turbografx.c index d53b9e900234..27b6a3ce18ca 100644 --- a/drivers/input/joystick/turbografx.c +++ b/drivers/input/joystick/turbografx.c | |||
@@ -245,6 +245,7 @@ static struct tgfx __init *tgfx_probe(int parport, int *n_buttons, int n_devs) | |||
245 | goto err_free_tgfx; | 245 | goto err_free_tgfx; |
246 | } | 246 | } |
247 | 247 | ||
248 | parport_put_port(pp); | ||
248 | return tgfx; | 249 | return tgfx; |
249 | 250 | ||
250 | err_free_dev: | 251 | err_free_dev: |
diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c index f9fb7fa10af3..56abf3d0e911 100644 --- a/drivers/input/joystick/xpad.c +++ b/drivers/input/joystick/xpad.c | |||
@@ -543,21 +543,25 @@ exit: | |||
543 | static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad) | 543 | static int xpad_init_output(struct usb_interface *intf, struct usb_xpad *xpad) |
544 | { | 544 | { |
545 | struct usb_endpoint_descriptor *ep_irq_out; | 545 | struct usb_endpoint_descriptor *ep_irq_out; |
546 | int error = -ENOMEM; | 546 | int error; |
547 | 547 | ||
548 | if (xpad->xtype != XTYPE_XBOX360 && xpad->xtype != XTYPE_XBOX) | 548 | if (xpad->xtype != XTYPE_XBOX360 && xpad->xtype != XTYPE_XBOX) |
549 | return 0; | 549 | return 0; |
550 | 550 | ||
551 | xpad->odata = usb_alloc_coherent(xpad->udev, XPAD_PKT_LEN, | 551 | xpad->odata = usb_alloc_coherent(xpad->udev, XPAD_PKT_LEN, |
552 | GFP_KERNEL, &xpad->odata_dma); | 552 | GFP_KERNEL, &xpad->odata_dma); |
553 | if (!xpad->odata) | 553 | if (!xpad->odata) { |
554 | error = -ENOMEM; | ||
554 | goto fail1; | 555 | goto fail1; |
556 | } | ||
555 | 557 | ||
556 | mutex_init(&xpad->odata_mutex); | 558 | mutex_init(&xpad->odata_mutex); |
557 | 559 | ||
558 | xpad->irq_out = usb_alloc_urb(0, GFP_KERNEL); | 560 | xpad->irq_out = usb_alloc_urb(0, GFP_KERNEL); |
559 | if (!xpad->irq_out) | 561 | if (!xpad->irq_out) { |
562 | error = -ENOMEM; | ||
560 | goto fail2; | 563 | goto fail2; |
564 | } | ||
561 | 565 | ||
562 | ep_irq_out = &intf->cur_altsetting->endpoint[1].desc; | 566 | ep_irq_out = &intf->cur_altsetting->endpoint[1].desc; |
563 | usb_fill_int_urb(xpad->irq_out, xpad->udev, | 567 | usb_fill_int_urb(xpad->irq_out, xpad->udev, |
@@ -728,7 +732,7 @@ static void xpad_led_disconnect(struct usb_xpad *xpad) | |||
728 | 732 | ||
729 | if (xpad_led) { | 733 | if (xpad_led) { |
730 | led_classdev_unregister(&xpad_led->led_cdev); | 734 | led_classdev_unregister(&xpad_led->led_cdev); |
731 | kfree(xpad_led->name); | 735 | kfree(xpad_led); |
732 | } | 736 | } |
733 | } | 737 | } |
734 | #else | 738 | #else |
@@ -756,8 +760,9 @@ static void xpad_close(struct input_dev *dev) | |||
756 | { | 760 | { |
757 | struct usb_xpad *xpad = input_get_drvdata(dev); | 761 | struct usb_xpad *xpad = input_get_drvdata(dev); |
758 | 762 | ||
759 | if(xpad->xtype != XTYPE_XBOX360W) | 763 | if (xpad->xtype != XTYPE_XBOX360W) |
760 | usb_kill_urb(xpad->irq_in); | 764 | usb_kill_urb(xpad->irq_in); |
765 | |||
761 | xpad_stop_output(xpad); | 766 | xpad_stop_output(xpad); |
762 | } | 767 | } |
763 | 768 | ||
@@ -789,8 +794,7 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id | |||
789 | struct usb_xpad *xpad; | 794 | struct usb_xpad *xpad; |
790 | struct input_dev *input_dev; | 795 | struct input_dev *input_dev; |
791 | struct usb_endpoint_descriptor *ep_irq_in; | 796 | struct usb_endpoint_descriptor *ep_irq_in; |
792 | int i; | 797 | int i, error; |
793 | int error = -ENOMEM; | ||
794 | 798 | ||
795 | for (i = 0; xpad_device[i].idVendor; i++) { | 799 | for (i = 0; xpad_device[i].idVendor; i++) { |
796 | if ((le16_to_cpu(udev->descriptor.idVendor) == xpad_device[i].idVendor) && | 800 | if ((le16_to_cpu(udev->descriptor.idVendor) == xpad_device[i].idVendor) && |
@@ -800,17 +804,23 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id | |||
800 | 804 | ||
801 | xpad = kzalloc(sizeof(struct usb_xpad), GFP_KERNEL); | 805 | xpad = kzalloc(sizeof(struct usb_xpad), GFP_KERNEL); |
802 | input_dev = input_allocate_device(); | 806 | input_dev = input_allocate_device(); |
803 | if (!xpad || !input_dev) | 807 | if (!xpad || !input_dev) { |
808 | error = -ENOMEM; | ||
804 | goto fail1; | 809 | goto fail1; |
810 | } | ||
805 | 811 | ||
806 | xpad->idata = usb_alloc_coherent(udev, XPAD_PKT_LEN, | 812 | xpad->idata = usb_alloc_coherent(udev, XPAD_PKT_LEN, |
807 | GFP_KERNEL, &xpad->idata_dma); | 813 | GFP_KERNEL, &xpad->idata_dma); |
808 | if (!xpad->idata) | 814 | if (!xpad->idata) { |
815 | error = -ENOMEM; | ||
809 | goto fail1; | 816 | goto fail1; |
817 | } | ||
810 | 818 | ||
811 | xpad->irq_in = usb_alloc_urb(0, GFP_KERNEL); | 819 | xpad->irq_in = usb_alloc_urb(0, GFP_KERNEL); |
812 | if (!xpad->irq_in) | 820 | if (!xpad->irq_in) { |
821 | error = -ENOMEM; | ||
813 | goto fail2; | 822 | goto fail2; |
823 | } | ||
814 | 824 | ||
815 | xpad->udev = udev; | 825 | xpad->udev = udev; |
816 | xpad->mapping = xpad_device[i].mapping; | 826 | xpad->mapping = xpad_device[i].mapping; |
@@ -887,15 +897,15 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id | |||
887 | 897 | ||
888 | error = xpad_init_output(intf, xpad); | 898 | error = xpad_init_output(intf, xpad); |
889 | if (error) | 899 | if (error) |
890 | goto fail2; | 900 | goto fail3; |
891 | 901 | ||
892 | error = xpad_init_ff(xpad); | 902 | error = xpad_init_ff(xpad); |
893 | if (error) | 903 | if (error) |
894 | goto fail3; | 904 | goto fail4; |
895 | 905 | ||
896 | error = xpad_led_probe(xpad); | 906 | error = xpad_led_probe(xpad); |
897 | if (error) | 907 | if (error) |
898 | goto fail3; | 908 | goto fail5; |
899 | 909 | ||
900 | ep_irq_in = &intf->cur_altsetting->endpoint[0].desc; | 910 | ep_irq_in = &intf->cur_altsetting->endpoint[0].desc; |
901 | usb_fill_int_urb(xpad->irq_in, udev, | 911 | usb_fill_int_urb(xpad->irq_in, udev, |
@@ -907,34 +917,26 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id | |||
907 | 917 | ||
908 | error = input_register_device(xpad->dev); | 918 | error = input_register_device(xpad->dev); |
909 | if (error) | 919 | if (error) |
910 | goto fail4; | 920 | goto fail6; |
911 | 921 | ||
912 | usb_set_intfdata(intf, xpad); | 922 | usb_set_intfdata(intf, xpad); |
913 | 923 | ||
914 | /* | ||
915 | * Submit the int URB immediatly rather than waiting for open | ||
916 | * because we get status messages from the device whether | ||
917 | * or not any controllers are attached. In fact, it's | ||
918 | * exactly the message that a controller has arrived that | ||
919 | * we're waiting for. | ||
920 | */ | ||
921 | if (xpad->xtype == XTYPE_XBOX360W) { | 924 | if (xpad->xtype == XTYPE_XBOX360W) { |
922 | xpad->irq_in->dev = xpad->udev; | ||
923 | error = usb_submit_urb(xpad->irq_in, GFP_KERNEL); | ||
924 | if (error) | ||
925 | goto fail4; | ||
926 | |||
927 | /* | 925 | /* |
928 | * Setup the message to set the LEDs on the | 926 | * Setup the message to set the LEDs on the |
929 | * controller when it shows up | 927 | * controller when it shows up |
930 | */ | 928 | */ |
931 | xpad->bulk_out = usb_alloc_urb(0, GFP_KERNEL); | 929 | xpad->bulk_out = usb_alloc_urb(0, GFP_KERNEL); |
932 | if(!xpad->bulk_out) | 930 | if (!xpad->bulk_out) { |
933 | goto fail5; | 931 | error = -ENOMEM; |
932 | goto fail7; | ||
933 | } | ||
934 | 934 | ||
935 | xpad->bdata = kzalloc(XPAD_PKT_LEN, GFP_KERNEL); | 935 | xpad->bdata = kzalloc(XPAD_PKT_LEN, GFP_KERNEL); |
936 | if(!xpad->bdata) | 936 | if (!xpad->bdata) { |
937 | goto fail6; | 937 | error = -ENOMEM; |
938 | goto fail8; | ||
939 | } | ||
938 | 940 | ||
939 | xpad->bdata[2] = 0x08; | 941 | xpad->bdata[2] = 0x08; |
940 | switch (intf->cur_altsetting->desc.bInterfaceNumber) { | 942 | switch (intf->cur_altsetting->desc.bInterfaceNumber) { |
@@ -955,14 +957,31 @@ static int xpad_probe(struct usb_interface *intf, const struct usb_device_id *id | |||
955 | usb_fill_bulk_urb(xpad->bulk_out, udev, | 957 | usb_fill_bulk_urb(xpad->bulk_out, udev, |
956 | usb_sndbulkpipe(udev, ep_irq_in->bEndpointAddress), | 958 | usb_sndbulkpipe(udev, ep_irq_in->bEndpointAddress), |
957 | xpad->bdata, XPAD_PKT_LEN, xpad_bulk_out, xpad); | 959 | xpad->bdata, XPAD_PKT_LEN, xpad_bulk_out, xpad); |
960 | |||
961 | /* | ||
962 | * Submit the int URB immediately rather than waiting for open | ||
963 | * because we get status messages from the device whether | ||
964 | * or not any controllers are attached. In fact, it's | ||
965 | * exactly the message that a controller has arrived that | ||
966 | * we're waiting for. | ||
967 | */ | ||
968 | xpad->irq_in->dev = xpad->udev; | ||
969 | error = usb_submit_urb(xpad->irq_in, GFP_KERNEL); | ||
970 | if (error) | ||
971 | goto fail9; | ||
958 | } | 972 | } |
959 | 973 | ||
960 | return 0; | 974 | return 0; |
961 | 975 | ||
962 | fail6: usb_free_urb(xpad->bulk_out); | 976 | fail9: kfree(xpad->bdata); |
963 | fail5: usb_kill_urb(xpad->irq_in); | 977 | fail8: usb_free_urb(xpad->bulk_out); |
964 | fail4: usb_free_urb(xpad->irq_in); | 978 | fail7: input_unregister_device(input_dev); |
965 | fail3: xpad_deinit_output(xpad); | 979 | input_dev = NULL; |
980 | fail6: xpad_led_disconnect(xpad); | ||
981 | fail5: if (input_dev) | ||
982 | input_ff_destroy(input_dev); | ||
983 | fail4: xpad_deinit_output(xpad); | ||
984 | fail3: usb_free_urb(xpad->irq_in); | ||
966 | fail2: usb_free_coherent(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); | 985 | fail2: usb_free_coherent(udev, XPAD_PKT_LEN, xpad->idata, xpad->idata_dma); |
967 | fail1: input_free_device(input_dev); | 986 | fail1: input_free_device(input_dev); |
968 | kfree(xpad); | 987 | kfree(xpad); |
@@ -974,21 +993,24 @@ static void xpad_disconnect(struct usb_interface *intf) | |||
974 | { | 993 | { |
975 | struct usb_xpad *xpad = usb_get_intfdata (intf); | 994 | struct usb_xpad *xpad = usb_get_intfdata (intf); |
976 | 995 | ||
977 | usb_set_intfdata(intf, NULL); | 996 | xpad_led_disconnect(xpad); |
978 | if (xpad) { | 997 | input_unregister_device(xpad->dev); |
979 | xpad_led_disconnect(xpad); | 998 | xpad_deinit_output(xpad); |
980 | input_unregister_device(xpad->dev); | 999 | |
981 | xpad_deinit_output(xpad); | 1000 | if (xpad->xtype == XTYPE_XBOX360W) { |
982 | if (xpad->xtype == XTYPE_XBOX360W) { | 1001 | usb_kill_urb(xpad->bulk_out); |
983 | usb_kill_urb(xpad->bulk_out); | 1002 | usb_free_urb(xpad->bulk_out); |
984 | usb_free_urb(xpad->bulk_out); | 1003 | usb_kill_urb(xpad->irq_in); |
985 | usb_kill_urb(xpad->irq_in); | ||
986 | } | ||
987 | usb_free_urb(xpad->irq_in); | ||
988 | usb_free_coherent(xpad->udev, XPAD_PKT_LEN, | ||
989 | xpad->idata, xpad->idata_dma); | ||
990 | kfree(xpad); | ||
991 | } | 1004 | } |
1005 | |||
1006 | usb_free_urb(xpad->irq_in); | ||
1007 | usb_free_coherent(xpad->udev, XPAD_PKT_LEN, | ||
1008 | xpad->idata, xpad->idata_dma); | ||
1009 | |||
1010 | kfree(xpad->bdata); | ||
1011 | kfree(xpad); | ||
1012 | |||
1013 | usb_set_intfdata(intf, NULL); | ||
992 | } | 1014 | } |
993 | 1015 | ||
994 | static struct usb_driver xpad_driver = { | 1016 | static struct usb_driver xpad_driver = { |
@@ -1000,10 +1022,7 @@ static struct usb_driver xpad_driver = { | |||
1000 | 1022 | ||
1001 | static int __init usb_xpad_init(void) | 1023 | static int __init usb_xpad_init(void) |
1002 | { | 1024 | { |
1003 | int result = usb_register(&xpad_driver); | 1025 | return usb_register(&xpad_driver); |
1004 | if (result == 0) | ||
1005 | printk(KERN_INFO KBUILD_MODNAME ": " DRIVER_DESC "\n"); | ||
1006 | return result; | ||
1007 | } | 1026 | } |
1008 | 1027 | ||
1009 | static void __exit usb_xpad_exit(void) | 1028 | static void __exit usb_xpad_exit(void) |