diff options
author | Dmitry Torokhov <dtor_core@ameritech.net> | 2005-09-15 03:01:52 -0400 |
---|---|---|
committer | Greg Kroah-Hartman <gregkh@suse.de> | 2005-10-28 12:52:53 -0400 |
commit | 17dd3f0f7aa729a042af5d3318ff9b3e7781b45b (patch) | |
tree | 261580f0229e6365f044cd26925dfb2735e0754d /drivers/input/joystick/tmdc.c | |
parent | 0259567ad60df13a55583b84d2cddb5526705907 (diff) |
[PATCH] drivers/input/joystick: convert to dynamic input_dev allocation
Input: convert drivers/input/joystick to dynamic input_dev allocation
This is required for input_dev sysfs integration
Signed-off-by: Dmitry Torokhov <dtor@mail.ru>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
Diffstat (limited to 'drivers/input/joystick/tmdc.c')
-rw-r--r-- | drivers/input/joystick/tmdc.c | 324 |
1 files changed, 192 insertions, 132 deletions
diff --git a/drivers/input/joystick/tmdc.c b/drivers/input/joystick/tmdc.c index 7431efc4330e..3a7d1bb46472 100644 --- a/drivers/input/joystick/tmdc.c +++ b/drivers/input/joystick/tmdc.c | |||
@@ -63,37 +63,70 @@ MODULE_LICENSE("GPL"); | |||
63 | #define TMDC_ABS_HAT 4 | 63 | #define TMDC_ABS_HAT 4 |
64 | #define TMDC_BTN 16 | 64 | #define TMDC_BTN 16 |
65 | 65 | ||
66 | static unsigned char tmdc_byte_a[16] = { 0, 1, 3, 4, 6, 7 }; | 66 | static const unsigned char tmdc_byte_a[16] = { 0, 1, 3, 4, 6, 7 }; |
67 | static unsigned char tmdc_byte_d[16] = { 2, 5, 8, 9 }; | 67 | static const unsigned char tmdc_byte_d[16] = { 2, 5, 8, 9 }; |
68 | 68 | ||
69 | static signed char tmdc_abs[TMDC_ABS] = | 69 | static const signed char tmdc_abs[TMDC_ABS] = |
70 | { ABS_X, ABS_Y, ABS_RUDDER, ABS_THROTTLE, ABS_RX, ABS_RY, ABS_RZ }; | 70 | { ABS_X, ABS_Y, ABS_RUDDER, ABS_THROTTLE, ABS_RX, ABS_RY, ABS_RZ }; |
71 | static signed char tmdc_abs_hat[TMDC_ABS_HAT] = | 71 | static const signed char tmdc_abs_hat[TMDC_ABS_HAT] = |
72 | { ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y }; | 72 | { ABS_HAT0X, ABS_HAT0Y, ABS_HAT1X, ABS_HAT1Y }; |
73 | static signed char tmdc_abs_at[TMDC_ABS] = | 73 | static const signed char tmdc_abs_at[TMDC_ABS] = |
74 | { ABS_X, ABS_Y, ABS_RUDDER, -1, ABS_THROTTLE }; | 74 | { ABS_X, ABS_Y, ABS_RUDDER, -1, ABS_THROTTLE }; |
75 | static signed char tmdc_abs_fm[TMDC_ABS] = | 75 | static const signed char tmdc_abs_fm[TMDC_ABS] = |
76 | { ABS_RX, ABS_RY, ABS_X, ABS_Y }; | 76 | { ABS_RX, ABS_RY, ABS_X, ABS_Y }; |
77 | 77 | ||
78 | static short tmdc_btn_pad[TMDC_BTN] = | 78 | static const short tmdc_btn_pad[TMDC_BTN] = |
79 | { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_START, BTN_SELECT, BTN_TL, BTN_TR }; | 79 | { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_START, BTN_SELECT, BTN_TL, BTN_TR }; |
80 | static short tmdc_btn_joy[TMDC_BTN] = | 80 | static const short tmdc_btn_joy[TMDC_BTN] = |
81 | { BTN_TRIGGER, BTN_THUMB, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2, BTN_THUMB2, BTN_PINKIE, | 81 | { BTN_TRIGGER, BTN_THUMB, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2, BTN_THUMB2, BTN_PINKIE, |
82 | BTN_BASE3, BTN_BASE4, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z }; | 82 | BTN_BASE3, BTN_BASE4, BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z }; |
83 | static short tmdc_btn_fm[TMDC_BTN] = | 83 | static const short tmdc_btn_fm[TMDC_BTN] = |
84 | { BTN_TRIGGER, BTN_C, BTN_B, BTN_A, BTN_THUMB, BTN_X, BTN_Y, BTN_Z, BTN_TOP, BTN_TOP2 }; | 84 | { BTN_TRIGGER, BTN_C, BTN_B, BTN_A, BTN_THUMB, BTN_X, BTN_Y, BTN_Z, BTN_TOP, BTN_TOP2 }; |
85 | static short tmdc_btn_at[TMDC_BTN] = | 85 | static const short tmdc_btn_at[TMDC_BTN] = |
86 | { BTN_TRIGGER, BTN_THUMB2, BTN_PINKIE, BTN_THUMB, BTN_BASE6, BTN_BASE5, BTN_BASE4, | 86 | { BTN_TRIGGER, BTN_THUMB2, BTN_PINKIE, BTN_THUMB, BTN_BASE6, BTN_BASE5, BTN_BASE4, |
87 | BTN_BASE3, BTN_BASE2, BTN_BASE }; | 87 | BTN_BASE3, BTN_BASE2, BTN_BASE }; |
88 | 88 | ||
89 | static struct { | 89 | static const struct { |
90 | int x; | 90 | int x; |
91 | int y; | 91 | int y; |
92 | } tmdc_hat_to_axis[] = {{ 0, 0}, { 1, 0}, { 0,-1}, {-1, 0}, { 0, 1}}; | 92 | } tmdc_hat_to_axis[] = {{ 0, 0}, { 1, 0}, { 0,-1}, {-1, 0}, { 0, 1}}; |
93 | 93 | ||
94 | static const struct tmdc_model { | ||
95 | unsigned char id; | ||
96 | const char *name; | ||
97 | char abs; | ||
98 | char hats; | ||
99 | char btnc[4]; | ||
100 | char btno[4]; | ||
101 | const signed char *axes; | ||
102 | const short *buttons; | ||
103 | } tmdc_models[] = { | ||
104 | { 1, "ThrustMaster Millenium 3D Inceptor", 6, 2, { 4, 2 }, { 4, 6 }, tmdc_abs, tmdc_btn_joy }, | ||
105 | { 3, "ThrustMaster Rage 3D Gamepad", 2, 0, { 8, 2 }, { 0, 0 }, tmdc_abs, tmdc_btn_pad }, | ||
106 | { 4, "ThrustMaster Attack Throttle", 5, 2, { 4, 6 }, { 4, 2 }, tmdc_abs_at, tmdc_btn_at }, | ||
107 | { 8, "ThrustMaster FragMaster", 4, 0, { 8, 2 }, { 0, 0 }, tmdc_abs_fm, tmdc_btn_fm }, | ||
108 | { 163, "Thrustmaster Fusion GamePad", 2, 0, { 8, 2 }, { 0, 0 }, tmdc_abs, tmdc_btn_pad }, | ||
109 | { 0, "Unknown %d-axis, %d-button TM device %d", 0, 0, { 0, 0 }, { 0, 0 }, tmdc_abs, tmdc_btn_joy } | ||
110 | }; | ||
111 | |||
112 | |||
113 | struct tmdc_port { | ||
114 | struct input_dev *dev; | ||
115 | char name[64]; | ||
116 | char phys[32]; | ||
117 | int mode; | ||
118 | const signed char *abs; | ||
119 | const short *btn; | ||
120 | unsigned char absc; | ||
121 | unsigned char btnc[4]; | ||
122 | unsigned char btno[4]; | ||
123 | }; | ||
124 | |||
94 | struct tmdc { | 125 | struct tmdc { |
95 | struct gameport *gameport; | 126 | struct gameport *gameport; |
96 | struct input_dev dev[2]; | 127 | struct tmdc_port *port[2]; |
128 | #if 0 | ||
129 | struct input_dev *dev[2]; | ||
97 | char name[2][64]; | 130 | char name[2][64]; |
98 | char phys[2][32]; | 131 | char phys[2][32]; |
99 | int mode[2]; | 132 | int mode[2]; |
@@ -102,6 +135,7 @@ struct tmdc { | |||
102 | unsigned char absc[2]; | 135 | unsigned char absc[2]; |
103 | unsigned char btnc[2][4]; | 136 | unsigned char btnc[2][4]; |
104 | unsigned char btno[2][4]; | 137 | unsigned char btno[2][4]; |
138 | #endif | ||
105 | int reads; | 139 | int reads; |
106 | int bads; | 140 | int bads; |
107 | unsigned char exists; | 141 | unsigned char exists; |
@@ -156,6 +190,50 @@ static int tmdc_read_packet(struct gameport *gameport, unsigned char data[2][TMD | |||
156 | return (i[0] == TMDC_MAX_LENGTH) | ((i[1] == TMDC_MAX_LENGTH) << 1); | 190 | return (i[0] == TMDC_MAX_LENGTH) | ((i[1] == TMDC_MAX_LENGTH) << 1); |
157 | } | 191 | } |
158 | 192 | ||
193 | static int tmdc_parse_packet(struct tmdc_port *port, unsigned char *data) | ||
194 | { | ||
195 | int i, k, l; | ||
196 | |||
197 | if (data[TMDC_BYTE_ID] != port->mode) | ||
198 | return -1; | ||
199 | |||
200 | for (i = 0; i < port->absc; i++) { | ||
201 | if (port->abs[i] < 0) | ||
202 | return 0; | ||
203 | |||
204 | input_report_abs(port->dev, port->abs[i], data[tmdc_byte_a[i]]); | ||
205 | } | ||
206 | |||
207 | switch (port->mode) { | ||
208 | |||
209 | case TMDC_MODE_M3DI: | ||
210 | |||
211 | i = tmdc_byte_d[0]; | ||
212 | input_report_abs(port->dev, ABS_HAT0X, ((data[i] >> 3) & 1) - ((data[i] >> 1) & 1)); | ||
213 | input_report_abs(port->dev, ABS_HAT0Y, ((data[i] >> 2) & 1) - ( data[i] & 1)); | ||
214 | break; | ||
215 | |||
216 | case TMDC_MODE_AT: | ||
217 | |||
218 | i = tmdc_byte_a[3]; | ||
219 | input_report_abs(port->dev, ABS_HAT0X, tmdc_hat_to_axis[(data[i] - 141) / 25].x); | ||
220 | input_report_abs(port->dev, ABS_HAT0Y, tmdc_hat_to_axis[(data[i] - 141) / 25].y); | ||
221 | break; | ||
222 | |||
223 | } | ||
224 | |||
225 | for (k = l = 0; k < 4; k++) { | ||
226 | for (i = 0; i < port->btnc[k]; i++) | ||
227 | input_report_key(port->dev, port->btn[i + l], | ||
228 | ((data[tmdc_byte_d[k]] >> (i + port->btno[k])) & 1)); | ||
229 | l += port->btnc[k]; | ||
230 | } | ||
231 | |||
232 | input_sync(port->dev); | ||
233 | |||
234 | return 0; | ||
235 | } | ||
236 | |||
159 | /* | 237 | /* |
160 | * tmdc_poll() reads and analyzes ThrustMaster joystick data. | 238 | * tmdc_poll() reads and analyzes ThrustMaster joystick data. |
161 | */ | 239 | */ |
@@ -164,57 +242,21 @@ static void tmdc_poll(struct gameport *gameport) | |||
164 | { | 242 | { |
165 | unsigned char data[2][TMDC_MAX_LENGTH]; | 243 | unsigned char data[2][TMDC_MAX_LENGTH]; |
166 | struct tmdc *tmdc = gameport_get_drvdata(gameport); | 244 | struct tmdc *tmdc = gameport_get_drvdata(gameport); |
167 | struct input_dev *dev; | ||
168 | unsigned char r, bad = 0; | 245 | unsigned char r, bad = 0; |
169 | int i, j, k, l; | 246 | int i; |
170 | 247 | ||
171 | tmdc->reads++; | 248 | tmdc->reads++; |
172 | 249 | ||
173 | if ((r = tmdc_read_packet(tmdc->gameport, data)) != tmdc->exists) | 250 | if ((r = tmdc_read_packet(tmdc->gameport, data)) != tmdc->exists) |
174 | bad = 1; | 251 | bad = 1; |
175 | else | 252 | else { |
176 | 253 | for (i = 0; i < 2; i++) { | |
177 | for (j = 0; j < 2; j++) | 254 | if (r & (1 << i) & tmdc->exists) { |
178 | if (r & (1 << j) & tmdc->exists) { | ||
179 | |||
180 | if (data[j][TMDC_BYTE_ID] != tmdc->mode[j]) { | ||
181 | bad = 1; | ||
182 | continue; | ||
183 | } | ||
184 | |||
185 | dev = tmdc->dev + j; | ||
186 | |||
187 | for (i = 0; i < tmdc->absc[j]; i++) { | ||
188 | if (tmdc->abs[j][i] < 0) continue; | ||
189 | input_report_abs(dev, tmdc->abs[j][i], data[j][tmdc_byte_a[i]]); | ||
190 | } | ||
191 | |||
192 | switch (tmdc->mode[j]) { | ||
193 | 255 | ||
194 | case TMDC_MODE_M3DI: | 256 | if (tmdc_parse_packet(tmdc->port[i], data[i])) |
195 | 257 | bad = 1; | |
196 | i = tmdc_byte_d[0]; | ||
197 | input_report_abs(dev, ABS_HAT0X, ((data[j][i] >> 3) & 1) - ((data[j][i] >> 1) & 1)); | ||
198 | input_report_abs(dev, ABS_HAT0Y, ((data[j][i] >> 2) & 1) - ( data[j][i] & 1)); | ||
199 | break; | ||
200 | |||
201 | case TMDC_MODE_AT: | ||
202 | |||
203 | i = tmdc_byte_a[3]; | ||
204 | input_report_abs(dev, ABS_HAT0X, tmdc_hat_to_axis[(data[j][i] - 141) / 25].x); | ||
205 | input_report_abs(dev, ABS_HAT0Y, tmdc_hat_to_axis[(data[j][i] - 141) / 25].y); | ||
206 | break; | ||
207 | |||
208 | } | ||
209 | |||
210 | for (k = l = 0; k < 4; k++) { | ||
211 | for (i = 0; i < tmdc->btnc[j][k]; i++) | ||
212 | input_report_key(dev, tmdc->btn[j][i + l], | ||
213 | ((data[j][tmdc_byte_d[k]] >> (i + tmdc->btno[j][k])) & 1)); | ||
214 | l += tmdc->btnc[j][k]; | ||
215 | } | 258 | } |
216 | 259 | } | |
217 | input_sync(dev); | ||
218 | } | 260 | } |
219 | 261 | ||
220 | tmdc->bads += bad; | 262 | tmdc->bads += bad; |
@@ -235,31 +277,89 @@ static void tmdc_close(struct input_dev *dev) | |||
235 | gameport_stop_polling(tmdc->gameport); | 277 | gameport_stop_polling(tmdc->gameport); |
236 | } | 278 | } |
237 | 279 | ||
280 | static int tmdc_setup_port(struct tmdc *tmdc, int idx, unsigned char *data) | ||
281 | { | ||
282 | const struct tmdc_model *model; | ||
283 | struct tmdc_port *port; | ||
284 | struct input_dev *input_dev; | ||
285 | int i, j, b = 0; | ||
286 | |||
287 | tmdc->port[idx] = port = kzalloc(sizeof (struct tmdc_port), GFP_KERNEL); | ||
288 | input_dev = input_allocate_device(); | ||
289 | if (!port || !input_dev) { | ||
290 | kfree(port); | ||
291 | input_free_device(input_dev); | ||
292 | return -ENOMEM; | ||
293 | } | ||
294 | |||
295 | port->mode = data[TMDC_BYTE_ID]; | ||
296 | |||
297 | for (model = tmdc_models; model->id && model->id != port->mode; model++) | ||
298 | /* empty */; | ||
299 | |||
300 | port->abs = model->axes; | ||
301 | port->btn = model->buttons; | ||
302 | |||
303 | if (!model->id) { | ||
304 | port->absc = data[TMDC_BYTE_DEF] >> 4; | ||
305 | for (i = 0; i < 4; i++) | ||
306 | port->btnc[i] = i < (data[TMDC_BYTE_DEF] & 0xf) ? 8 : 0; | ||
307 | } else { | ||
308 | port->absc = model->abs; | ||
309 | for (i = 0; i < 4; i++) | ||
310 | port->btnc[i] = model->btnc[i]; | ||
311 | } | ||
312 | |||
313 | for (i = 0; i < 4; i++) | ||
314 | port->btno[i] = model->btno[i]; | ||
315 | |||
316 | snprintf(port->name, sizeof(port->name), model->name, | ||
317 | port->absc, (data[TMDC_BYTE_DEF] & 0xf) << 3, port->mode); | ||
318 | snprintf(port->phys, sizeof(port->phys), "%s/input%d", tmdc->gameport->phys, i); | ||
319 | |||
320 | port->dev = input_dev; | ||
321 | |||
322 | input_dev->name = port->name; | ||
323 | input_dev->phys = port->phys; | ||
324 | input_dev->id.bustype = BUS_GAMEPORT; | ||
325 | input_dev->id.vendor = GAMEPORT_ID_VENDOR_THRUSTMASTER; | ||
326 | input_dev->id.product = model->id; | ||
327 | input_dev->id.version = 0x0100; | ||
328 | input_dev->cdev.dev = &tmdc->gameport->dev; | ||
329 | input_dev->private = tmdc; | ||
330 | |||
331 | input_dev->open = tmdc_open; | ||
332 | input_dev->close = tmdc_close; | ||
333 | |||
334 | input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); | ||
335 | |||
336 | for (i = 0; i < port->absc && i < TMDC_ABS; i++) | ||
337 | if (port->abs[i] >= 0) | ||
338 | input_set_abs_params(input_dev, port->abs[i], 8, 248, 2, 4); | ||
339 | |||
340 | for (i = 0; i < model->hats && i < TMDC_ABS_HAT; i++) | ||
341 | input_set_abs_params(input_dev, tmdc_abs_hat[i], -1, 1, 0, 0); | ||
342 | |||
343 | for (i = 0; i < 4; i++) { | ||
344 | for (j = 0; j < port->btnc[i] && j < TMDC_BTN; j++) | ||
345 | set_bit(port->btn[j + b], input_dev->keybit); | ||
346 | b += port->btnc[i]; | ||
347 | } | ||
348 | |||
349 | input_register_device(port->dev); | ||
350 | |||
351 | return 0; | ||
352 | } | ||
353 | |||
238 | /* | 354 | /* |
239 | * tmdc_probe() probes for ThrustMaster type joysticks. | 355 | * tmdc_probe() probes for ThrustMaster type joysticks. |
240 | */ | 356 | */ |
241 | 357 | ||
242 | static int tmdc_connect(struct gameport *gameport, struct gameport_driver *drv) | 358 | static int tmdc_connect(struct gameport *gameport, struct gameport_driver *drv) |
243 | { | 359 | { |
244 | static struct models { | ||
245 | unsigned char id; | ||
246 | char *name; | ||
247 | char abs; | ||
248 | char hats; | ||
249 | char btnc[4]; | ||
250 | char btno[4]; | ||
251 | signed char *axes; | ||
252 | short *buttons; | ||
253 | } models[] = { { 1, "ThrustMaster Millenium 3D Inceptor", 6, 2, { 4, 2 }, { 4, 6 }, tmdc_abs, tmdc_btn_joy }, | ||
254 | { 3, "ThrustMaster Rage 3D Gamepad", 2, 0, { 8, 2 }, { 0, 0 }, tmdc_abs, tmdc_btn_pad }, | ||
255 | { 4, "ThrustMaster Attack Throttle", 5, 2, { 4, 6 }, { 4, 2 }, tmdc_abs_at, tmdc_btn_at }, | ||
256 | { 8, "ThrustMaster FragMaster", 4, 0, { 8, 2 }, { 0, 0 }, tmdc_abs_fm, tmdc_btn_fm }, | ||
257 | { 163, "Thrustmaster Fusion GamePad", 2, 0, { 8, 2 }, { 0, 0 }, tmdc_abs, tmdc_btn_pad }, | ||
258 | { 0, "Unknown %d-axis, %d-button TM device %d", 0, 0, { 0, 0 }, { 0, 0 }, tmdc_abs, tmdc_btn_joy }}; | ||
259 | |||
260 | unsigned char data[2][TMDC_MAX_LENGTH]; | 360 | unsigned char data[2][TMDC_MAX_LENGTH]; |
261 | struct tmdc *tmdc; | 361 | struct tmdc *tmdc; |
262 | int i, j, k, l, m; | 362 | int i; |
263 | int err; | 363 | int err; |
264 | 364 | ||
265 | if (!(tmdc = kzalloc(sizeof(struct tmdc), GFP_KERNEL))) | 365 | if (!(tmdc = kzalloc(sizeof(struct tmdc), GFP_KERNEL))) |
@@ -281,68 +381,25 @@ static int tmdc_connect(struct gameport *gameport, struct gameport_driver *drv) | |||
281 | gameport_set_poll_handler(gameport, tmdc_poll); | 381 | gameport_set_poll_handler(gameport, tmdc_poll); |
282 | gameport_set_poll_interval(gameport, 20); | 382 | gameport_set_poll_interval(gameport, 20); |
283 | 383 | ||
284 | for (j = 0; j < 2; j++) | 384 | for (i = 0; i < 2; i++) { |
285 | if (tmdc->exists & (1 << j)) { | 385 | if (tmdc->exists & (1 << i)) { |
286 | 386 | ||
287 | tmdc->mode[j] = data[j][TMDC_BYTE_ID]; | 387 | err = tmdc_setup_port(tmdc, i, data[i]); |
288 | 388 | if (err) | |
289 | for (m = 0; models[m].id && models[m].id != tmdc->mode[j]; m++); | 389 | goto fail3; |
290 | |||
291 | tmdc->abs[j] = models[m].axes; | ||
292 | tmdc->btn[j] = models[m].buttons; | ||
293 | |||
294 | if (!models[m].id) { | ||
295 | models[m].abs = data[j][TMDC_BYTE_DEF] >> 4; | ||
296 | for (k = 0; k < 4; k++) | ||
297 | models[m].btnc[k] = k < (data[j][TMDC_BYTE_DEF] & 0xf) ? 8 : 0; | ||
298 | } | ||
299 | |||
300 | tmdc->absc[j] = models[m].abs; | ||
301 | for (k = 0; k < 4; k++) { | ||
302 | tmdc->btnc[j][k] = models[m].btnc[k]; | ||
303 | tmdc->btno[j][k] = models[m].btno[k]; | ||
304 | } | ||
305 | |||
306 | sprintf(tmdc->name[j], models[m].name, models[m].abs, | ||
307 | (data[j][TMDC_BYTE_DEF] & 0xf) << 3, tmdc->mode[j]); | ||
308 | |||
309 | sprintf(tmdc->phys[j], "%s/input%d", gameport->phys, j); | ||
310 | |||
311 | tmdc->dev[j].private = tmdc; | ||
312 | tmdc->dev[j].open = tmdc_open; | ||
313 | tmdc->dev[j].close = tmdc_close; | ||
314 | |||
315 | tmdc->dev[j].name = tmdc->name[j]; | ||
316 | tmdc->dev[j].phys = tmdc->phys[j]; | ||
317 | tmdc->dev[j].id.bustype = BUS_GAMEPORT; | ||
318 | tmdc->dev[j].id.vendor = GAMEPORT_ID_VENDOR_THRUSTMASTER; | ||
319 | tmdc->dev[j].id.product = models[m].id; | ||
320 | tmdc->dev[j].id.version = 0x0100; | ||
321 | |||
322 | tmdc->dev[j].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); | ||
323 | |||
324 | for (i = 0; i < models[m].abs && i < TMDC_ABS; i++) | ||
325 | if (tmdc->abs[j][i] >= 0) | ||
326 | input_set_abs_params(&tmdc->dev[j], tmdc->abs[j][i], 8, 248, 2, 4); | ||
327 | |||
328 | for (i = 0; i < models[m].hats && i < TMDC_ABS_HAT; i++) | ||
329 | input_set_abs_params(&tmdc->dev[j], tmdc_abs_hat[i], -1, 1, 0, 0); | ||
330 | |||
331 | |||
332 | for (k = l = 0; k < 4; k++) { | ||
333 | for (i = 0; i < models[m].btnc[k] && i < TMDC_BTN; i++) | ||
334 | set_bit(tmdc->btn[j][i + l], tmdc->dev[j].keybit); | ||
335 | l += models[m].btnc[k]; | ||
336 | } | ||
337 | |||
338 | input_register_device(tmdc->dev + j); | ||
339 | printk(KERN_INFO "input: %s on %s\n", tmdc->name[j], gameport->phys); | ||
340 | } | 390 | } |
391 | } | ||
341 | 392 | ||
342 | return 0; | 393 | return 0; |
343 | 394 | ||
344 | fail2: gameport_close(gameport); | 395 | fail3: while (--i >= 0) { |
345 | fail1: gameport_set_drvdata(gameport, NULL); | 396 | if (tmdc->port[i]) { |
397 | input_unregister_device(tmdc->port[i]->dev); | ||
398 | kfree(tmdc->port[i]); | ||
399 | } | ||
400 | } | ||
401 | fail2: gameport_close(gameport); | ||
402 | fail1: gameport_set_drvdata(gameport, NULL); | ||
346 | kfree(tmdc); | 403 | kfree(tmdc); |
347 | return err; | 404 | return err; |
348 | } | 405 | } |
@@ -352,9 +409,12 @@ static void tmdc_disconnect(struct gameport *gameport) | |||
352 | struct tmdc *tmdc = gameport_get_drvdata(gameport); | 409 | struct tmdc *tmdc = gameport_get_drvdata(gameport); |
353 | int i; | 410 | int i; |
354 | 411 | ||
355 | for (i = 0; i < 2; i++) | 412 | for (i = 0; i < 2; i++) { |
356 | if (tmdc->exists & (1 << i)) | 413 | if (tmdc->port[i]) { |
357 | input_unregister_device(tmdc->dev + i); | 414 | input_unregister_device(tmdc->port[i]->dev); |
415 | kfree(tmdc->port[i]); | ||
416 | } | ||
417 | } | ||
358 | gameport_close(gameport); | 418 | gameport_close(gameport); |
359 | gameport_set_drvdata(gameport, NULL); | 419 | gameport_set_drvdata(gameport, NULL); |
360 | kfree(tmdc); | 420 | kfree(tmdc); |