aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/joystick/gf2k.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/joystick/gf2k.c')
-rw-r--r--drivers/input/joystick/gf2k.c70
1 files changed, 38 insertions, 32 deletions
diff --git a/drivers/input/joystick/gf2k.c b/drivers/input/joystick/gf2k.c
index 8e4f92b115e6..8a3ad455eb38 100644
--- a/drivers/input/joystick/gf2k.c
+++ b/drivers/input/joystick/gf2k.c
@@ -35,6 +35,7 @@
35#include <linux/init.h> 35#include <linux/init.h>
36#include <linux/input.h> 36#include <linux/input.h>
37#include <linux/gameport.h> 37#include <linux/gameport.h>
38#include <linux/jiffies.h>
38 39
39#define DRIVER_DESC "Genius Flight 2000 joystick driver" 40#define DRIVER_DESC "Genius Flight 2000 joystick driver"
40 41
@@ -81,7 +82,7 @@ static short gf2k_seq_digital[] = { 590, 320, 860, 0 };
81 82
82struct gf2k { 83struct gf2k {
83 struct gameport *gameport; 84 struct gameport *gameport;
84 struct input_dev dev; 85 struct input_dev *dev;
85 int reads; 86 int reads;
86 int bads; 87 int bads;
87 unsigned char id; 88 unsigned char id;
@@ -175,7 +176,7 @@ static int gf2k_get_bits(unsigned char *buf, int pos, int num, int shift)
175 176
176static void gf2k_read(struct gf2k *gf2k, unsigned char *data) 177static void gf2k_read(struct gf2k *gf2k, unsigned char *data)
177{ 178{
178 struct input_dev *dev = &gf2k->dev; 179 struct input_dev *dev = gf2k->dev;
179 int i, t; 180 int i, t;
180 181
181 for (i = 0; i < 4 && i < gf2k_axes[gf2k->id]; i++) 182 for (i = 0; i < 4 && i < gf2k_axes[gf2k->id]; i++)
@@ -239,13 +240,19 @@ static void gf2k_close(struct input_dev *dev)
239static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv) 240static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
240{ 241{
241 struct gf2k *gf2k; 242 struct gf2k *gf2k;
243 struct input_dev *input_dev;
242 unsigned char data[GF2K_LENGTH]; 244 unsigned char data[GF2K_LENGTH];
243 int i, err; 245 int i, err;
244 246
245 if (!(gf2k = kzalloc(sizeof(struct gf2k), GFP_KERNEL))) 247 gf2k = kzalloc(sizeof(struct gf2k), GFP_KERNEL);
246 return -ENOMEM; 248 input_dev = input_allocate_device();
249 if (!gf2k || !input_dev) {
250 err = -ENOMEM;
251 goto fail1;
252 }
247 253
248 gf2k->gameport = gameport; 254 gf2k->gameport = gameport;
255 gf2k->dev = input_dev;
249 256
250 gameport_set_drvdata(gameport, gf2k); 257 gameport_set_drvdata(gameport, gf2k);
251 258
@@ -295,53 +302,52 @@ static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
295 302
296 gf2k->length = gf2k_lens[gf2k->id]; 303 gf2k->length = gf2k_lens[gf2k->id];
297 304
298 init_input_dev(&gf2k->dev); 305 input_dev->name = gf2k_names[gf2k->id];
299 306 input_dev->phys = gf2k->phys;
300 gf2k->dev.private = gf2k; 307 input_dev->id.bustype = BUS_GAMEPORT;
301 gf2k->dev.open = gf2k_open; 308 input_dev->id.vendor = GAMEPORT_ID_VENDOR_GENIUS;
302 gf2k->dev.close = gf2k_close; 309 input_dev->id.product = gf2k->id;
303 gf2k->dev.evbit[0] = BIT(EV_KEY) | BIT(EV_ABS); 310 input_dev->id.version = 0x0100;
311 input_dev->cdev.dev = &gameport->dev;
312 input_dev->private = gf2k;
304 313
305 gf2k->dev.name = gf2k_names[gf2k->id]; 314 input_dev->open = gf2k_open;
306 gf2k->dev.phys = gf2k->phys; 315 input_dev->close = gf2k_close;
307 gf2k->dev.id.bustype = BUS_GAMEPORT; 316 input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
308 gf2k->dev.id.vendor = GAMEPORT_ID_VENDOR_GENIUS;
309 gf2k->dev.id.product = gf2k->id;
310 gf2k->dev.id.version = 0x0100;
311 317
312 for (i = 0; i < gf2k_axes[gf2k->id]; i++) 318 for (i = 0; i < gf2k_axes[gf2k->id]; i++)
313 set_bit(gf2k_abs[i], gf2k->dev.absbit); 319 set_bit(gf2k_abs[i], input_dev->absbit);
314 320
315 for (i = 0; i < gf2k_hats[gf2k->id]; i++) { 321 for (i = 0; i < gf2k_hats[gf2k->id]; i++) {
316 set_bit(ABS_HAT0X + i, gf2k->dev.absbit); 322 set_bit(ABS_HAT0X + i, input_dev->absbit);
317 gf2k->dev.absmin[ABS_HAT0X + i] = -1; 323 input_dev->absmin[ABS_HAT0X + i] = -1;
318 gf2k->dev.absmax[ABS_HAT0X + i] = 1; 324 input_dev->absmax[ABS_HAT0X + i] = 1;
319 } 325 }
320 326
321 for (i = 0; i < gf2k_joys[gf2k->id]; i++) 327 for (i = 0; i < gf2k_joys[gf2k->id]; i++)
322 set_bit(gf2k_btn_joy[i], gf2k->dev.keybit); 328 set_bit(gf2k_btn_joy[i], input_dev->keybit);
323 329
324 for (i = 0; i < gf2k_pads[gf2k->id]; i++) 330 for (i = 0; i < gf2k_pads[gf2k->id]; i++)
325 set_bit(gf2k_btn_pad[i], gf2k->dev.keybit); 331 set_bit(gf2k_btn_pad[i], input_dev->keybit);
326 332
327 gf2k_read_packet(gameport, gf2k->length, data); 333 gf2k_read_packet(gameport, gf2k->length, data);
328 gf2k_read(gf2k, data); 334 gf2k_read(gf2k, data);
329 335
330 for (i = 0; i < gf2k_axes[gf2k->id]; i++) { 336 for (i = 0; i < gf2k_axes[gf2k->id]; i++) {
331 gf2k->dev.absmax[gf2k_abs[i]] = (i < 2) ? gf2k->dev.abs[gf2k_abs[i]] * 2 - 32 : 337 input_dev->absmax[gf2k_abs[i]] = (i < 2) ? input_dev->abs[gf2k_abs[i]] * 2 - 32 :
332 gf2k->dev.abs[gf2k_abs[0]] + gf2k->dev.abs[gf2k_abs[1]] - 32; 338 input_dev->abs[gf2k_abs[0]] + input_dev->abs[gf2k_abs[1]] - 32;
333 gf2k->dev.absmin[gf2k_abs[i]] = 32; 339 input_dev->absmin[gf2k_abs[i]] = 32;
334 gf2k->dev.absfuzz[gf2k_abs[i]] = 8; 340 input_dev->absfuzz[gf2k_abs[i]] = 8;
335 gf2k->dev.absflat[gf2k_abs[i]] = (i < 2) ? 24 : 0; 341 input_dev->absflat[gf2k_abs[i]] = (i < 2) ? 24 : 0;
336 } 342 }
337 343
338 input_register_device(&gf2k->dev); 344 input_register_device(gf2k->dev);
339 printk(KERN_INFO "input: %s on %s\n", gf2k_names[gf2k->id], gameport->phys);
340 345
341 return 0; 346 return 0;
342 347
343fail2: gameport_close(gameport); 348 fail2: gameport_close(gameport);
344fail1: gameport_set_drvdata(gameport, NULL); 349 fail1: gameport_set_drvdata(gameport, NULL);
350 input_free_device(input_dev);
345 kfree(gf2k); 351 kfree(gf2k);
346 return err; 352 return err;
347} 353}
@@ -350,7 +356,7 @@ static void gf2k_disconnect(struct gameport *gameport)
350{ 356{
351 struct gf2k *gf2k = gameport_get_drvdata(gameport); 357 struct gf2k *gf2k = gameport_get_drvdata(gameport);
352 358
353 input_unregister_device(&gf2k->dev); 359 input_unregister_device(gf2k->dev);
354 gameport_close(gameport); 360 gameport_close(gameport);
355 gameport_set_drvdata(gameport, NULL); 361 gameport_set_drvdata(gameport, NULL);
356 kfree(gf2k); 362 kfree(gf2k);