Fedora kernel-2.6.17-1.2142_FC4 patched with stable patch-2.6.17.4-vs2.0.2-rc26.diff
[linux-2.6.git] / drivers / input / joystick / iforce / iforce-serio.c
index e17c2e8..64a78c5 100644 (file)
@@ -62,7 +62,7 @@ again:
                cs ^= iforce->xmit.buf[iforce->xmit.tail];
                XMIT_INC(iforce->xmit.tail, 1);
        }
-       
+
        serio_write(iforce->serio, cs);
 
        if (test_and_clear_bit(IFORCE_XMIT_AGAIN, iforce->xmit_flags))
@@ -75,13 +75,15 @@ again:
 
 static void iforce_serio_write_wakeup(struct serio *serio)
 {
-       iforce_serial_xmit((struct iforce *)serio->private);
+       struct iforce *iforce = serio_get_drvdata(serio);
+
+       iforce_serial_xmit(iforce);
 }
 
 static irqreturn_t iforce_serio_irq(struct serio *serio,
                unsigned char data, unsigned int flags, struct pt_regs *regs)
 {
-       struct iforce* iforce = serio->private;
+       struct iforce *iforce = serio_get_drvdata(serio);
 
        if (!iforce->pkt) {
                if (data == 0x2b)
@@ -124,43 +126,68 @@ out:
        return IRQ_HANDLED;
 }
 
-static void iforce_serio_connect(struct serio *serio, struct serio_dev *dev)
+static int iforce_serio_connect(struct serio *serio, struct serio_driver *drv)
 {
        struct iforce *iforce;
-       if (serio->type != (SERIO_RS232 | SERIO_IFORCE))
-               return;
+       int err;
 
-       if (!(iforce = kmalloc(sizeof(struct iforce), GFP_KERNEL))) return;
-       memset(iforce, 0, sizeof(struct iforce));
+       iforce = kzalloc(sizeof(struct iforce), GFP_KERNEL);
+       if (!iforce)
+               return -ENOMEM;
 
        iforce->bus = IFORCE_232;
        iforce->serio = serio;
-       serio->private = iforce;
 
-       if (serio_open(serio, dev)) {
+       serio_set_drvdata(serio, iforce);
+
+       err = serio_open(serio, drv);
+       if (err) {
+               serio_set_drvdata(serio, NULL);
                kfree(iforce);
-               return;
+               return err;
        }
 
-       if (iforce_init_device(iforce)) {
+       err = iforce_init_device(iforce);
+       if (err) {
                serio_close(serio);
+               serio_set_drvdata(serio, NULL);
                kfree(iforce);
-               return;
+               return -ENODEV;
        }
+
+       return 0;
 }
 
 static void iforce_serio_disconnect(struct serio *serio)
 {
-       struct iforce* iforce = serio->private;
+       struct iforce *iforce = serio_get_drvdata(serio);
 
-       input_unregister_device(&iforce->dev);
+       input_unregister_device(iforce->dev);
        serio_close(serio);
+       serio_set_drvdata(serio, NULL);
        kfree(iforce);
 }
 
-struct serio_dev iforce_serio_dev = {
-       .write_wakeup = iforce_serio_write_wakeup,
-       .interrupt =    iforce_serio_irq,
-       .connect =      iforce_serio_connect,
-       .disconnect =   iforce_serio_disconnect,
+static struct serio_device_id iforce_serio_ids[] = {
+       {
+               .type   = SERIO_RS232,
+               .proto  = SERIO_IFORCE,
+               .id     = SERIO_ANY,
+               .extra  = SERIO_ANY,
+       },
+       { 0 }
+};
+
+MODULE_DEVICE_TABLE(serio, iforce_serio_ids);
+
+struct serio_driver iforce_serio_drv = {
+       .driver         = {
+               .name   = "iforce",
+       },
+       .description    = "RS232 I-Force joysticks and wheels driver",
+       .id_table       = iforce_serio_ids,
+       .write_wakeup   = iforce_serio_write_wakeup,
+       .interrupt      = iforce_serio_irq,
+       .connect        = iforce_serio_connect,
+       .disconnect     = iforce_serio_disconnect,
 };