aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/input/gameport/emu10k1-gp.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/input/gameport/emu10k1-gp.c')
-rw-r--r--drivers/input/gameport/emu10k1-gp.c44
1 files changed, 27 insertions, 17 deletions
diff --git a/drivers/input/gameport/emu10k1-gp.c b/drivers/input/gameport/emu10k1-gp.c
index 7392992da424..422aa0a6b77f 100644
--- a/drivers/input/gameport/emu10k1-gp.c
+++ b/drivers/input/gameport/emu10k1-gp.c
@@ -59,44 +59,52 @@ MODULE_DEVICE_TABLE(pci, emu_tbl);
59 59
60static int __devinit emu_probe(struct pci_dev *pdev, const struct pci_device_id *ent) 60static int __devinit emu_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
61{ 61{
62 int ioport, iolen;
63 struct emu *emu; 62 struct emu *emu;
64 struct gameport *port; 63 struct gameport *port;
65 64 int error;
66 if (pci_enable_device(pdev))
67 return -EBUSY;
68
69 ioport = pci_resource_start(pdev, 0);
70 iolen = pci_resource_len(pdev, 0);
71
72 if (!request_region(ioport, iolen, "emu10k1-gp"))
73 return -EBUSY;
74 65
75 emu = kzalloc(sizeof(struct emu), GFP_KERNEL); 66 emu = kzalloc(sizeof(struct emu), GFP_KERNEL);
76 port = gameport_allocate_port(); 67 port = gameport_allocate_port();
77 if (!emu || !port) { 68 if (!emu || !port) {
78 printk(KERN_ERR "emu10k1-gp: Memory allocation failed\n"); 69 printk(KERN_ERR "emu10k1-gp: Memory allocation failed\n");
79 release_region(ioport, iolen); 70 error = -ENOMEM;
80 kfree(emu); 71 goto err_out_free;
81 gameport_free_port(port);
82 return -ENOMEM;
83 } 72 }
84 73
85 emu->io = ioport; 74 error = pci_enable_device(pdev);
86 emu->size = iolen; 75 if (error)
76 goto err_out_free;
77
78 emu->io = pci_resource_start(pdev, 0);
79 emu->size = pci_resource_len(pdev, 0);
80
87 emu->dev = pdev; 81 emu->dev = pdev;
88 emu->gameport = port; 82 emu->gameport = port;
89 83
90 gameport_set_name(port, "EMU10K1"); 84 gameport_set_name(port, "EMU10K1");
91 gameport_set_phys(port, "pci%s/gameport0", pci_name(pdev)); 85 gameport_set_phys(port, "pci%s/gameport0", pci_name(pdev));
92 port->dev.parent = &pdev->dev; 86 port->dev.parent = &pdev->dev;
93 port->io = ioport; 87 port->io = emu->io;
88
89 if (!request_region(emu->io, emu->size, "emu10k1-gp")) {
90 printk(KERN_ERR "emu10k1-gp: unable to grab region 0x%x-0x%x\n",
91 emu->io, emu->io + emu->size - 1);
92 error = -EBUSY;
93 goto err_out_disable_dev;
94 }
94 95
95 pci_set_drvdata(pdev, emu); 96 pci_set_drvdata(pdev, emu);
96 97
97 gameport_register_port(port); 98 gameport_register_port(port);
98 99
99 return 0; 100 return 0;
101
102 err_out_disable_dev:
103 pci_disable_device(pdev);
104 err_out_free:
105 gameport_free_port(port);
106 kfree(emu);
107 return error;
100} 108}
101 109
102static void __devexit emu_remove(struct pci_dev *pdev) 110static void __devexit emu_remove(struct pci_dev *pdev)
@@ -106,6 +114,8 @@ static void __devexit emu_remove(struct pci_dev *pdev)
106 gameport_unregister_port(emu->gameport); 114 gameport_unregister_port(emu->gameport);
107 release_region(emu->io, emu->size); 115 release_region(emu->io, emu->size);
108 kfree(emu); 116 kfree(emu);
117
118 pci_disable_device(pdev);
109} 119}
110 120
111static struct pci_driver emu_driver = { 121static struct pci_driver emu_driver = {