vserver 2.0 rc7
[linux-2.6.git] / drivers / input / gameport / fm801-gp.c
index ab0a151..57615bc 100644 (file)
 #define HAVE_COOKED
 
 struct fm801_gp {
-       struct gameport gameport;
+       struct gameport *gameport;
        struct resource *res_port;
-       char phys[32];
-       char name[32];
 };
 
 #ifdef HAVE_COOKED
@@ -83,40 +81,42 @@ static int fm801_gp_open(struct gameport *gameport, int mode)
 static int __devinit fm801_gp_probe(struct pci_dev *pci, const struct pci_device_id *id)
 {
        struct fm801_gp *gp;
+       struct gameport *port;
 
-       if (! (gp = kmalloc(sizeof(*gp), GFP_KERNEL))) {
-               printk("cannot malloc for fm801-gp\n");
-               return -1;
+       gp = kcalloc(1, sizeof(struct fm801_gp), GFP_KERNEL);
+       port = gameport_allocate_port();
+       if (!gp || !port) {
+               printk(KERN_ERR "fm801-gp: Memory allocation failed\n");
+               kfree(gp);
+               gameport_free_port(port);
+               return -ENOMEM;
        }
-       memset(gp, 0, sizeof(*gp));
 
-       gp->gameport.open = fm801_gp_open;
+       pci_enable_device(pci);
+
+       port->open = fm801_gp_open;
 #ifdef HAVE_COOKED
-       gp->gameport.cooked_read = fm801_gp_cooked_read;
+       port->cooked_read = fm801_gp_cooked_read;
 #endif
-
-       pci_enable_device(pci);
-       gp->gameport.io = pci_resource_start(pci, 0);
-       if ((gp->res_port = request_region(gp->gameport.io, 0x10, "FM801 GP")) == NULL) {
-               printk("unable to grab region 0x%x-0x%x\n", gp->gameport.io, gp->gameport.io + 0x0f);
+       gameport_set_name(port, "FM801");
+       gameport_set_phys(port, "pci%s/gameport0", pci_name(pci));
+       port->dev.parent = &pci->dev;
+       port->io = pci_resource_start(pci, 0);
+
+       gp->gameport = port;
+       gp->res_port = request_region(port->io, 0x10, "FM801 GP");
+       if (!gp->res_port) {
                kfree(gp);
-               return -1;
+               gameport_free_port(port);
+               printk(KERN_DEBUG "fm801-gp: unable to grab region 0x%x-0x%x\n",
+                       port->io, port->io + 0x0f);
+               return -EBUSY;
        }
 
-       gp->gameport.phys = gp->phys;
-       gp->gameport.name = gp->name;
-       gp->gameport.id.bustype = BUS_PCI;
-       gp->gameport.id.vendor = pci->vendor;
-       gp->gameport.id.product = pci->device;
-
        pci_set_drvdata(pci, gp);
 
-       outb(0x60, gp->gameport.io + 0x0d); /* enable joystick 1 and 2 */
-
-       gameport_register_port(&gp->gameport);
-
-       printk(KERN_INFO "gameport: at pci%s speed %d kHz\n",
-               pci_name(pci), gp->gameport.speed);
+       outb(0x60, port->io + 0x0d); /* enable joystick 1 and 2 */
+       gameport_register_port(port);
 
        return 0;
 }
@@ -124,8 +124,9 @@ static int __devinit fm801_gp_probe(struct pci_dev *pci, const struct pci_device
 static void __devexit fm801_gp_remove(struct pci_dev *pci)
 {
        struct fm801_gp *gp = pci_get_drvdata(pci);
+
        if (gp) {
-               gameport_unregister_port(&gp->gameport);
+               gameport_unregister_port(gp->gameport);
                release_resource(gp->res_port);
                kfree(gp);
        }
@@ -143,12 +144,12 @@ static struct pci_driver fm801_gp_driver = {
        .remove =       __devexit_p(fm801_gp_remove),
 };
 
-int __init fm801_gp_init(void)
+static int __init fm801_gp_init(void)
 {
-       return pci_module_init(&fm801_gp_driver);
+       return pci_register_driver(&fm801_gp_driver);
 }
 
-void __exit fm801_gp_exit(void)
+static void __exit fm801_gp_exit(void)
 {
        pci_unregister_driver(&fm801_gp_driver);
 }