patch-2_6_7-vs1_9_1_12
[linux-2.6.git] / drivers / input / gameport / emu10k1-gp.c
1 /*
2  * $Id: emu10k1-gp.c,v 1.8 2002/01/22 20:40:46 vojtech Exp $
3  *
4  *  Copyright (c) 2001 Vojtech Pavlik
5  */
6
7 /*
8  * EMU10k1 - SB Live / Audigy - gameport driver for Linux
9  */
10
11 /*
12  * This program is free software; you can redistribute it and/or modify
13  * it under the terms of the GNU General Public License as published by
14  * the Free Software Foundation; either version 2 of the License, or
15  * (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25  *
26  * Should you need to contact me, the author, you can do so either by
27  * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
28  * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
29  */
30
31 #include <asm/io.h>
32
33 #include <linux/module.h>
34 #include <linux/ioport.h>
35 #include <linux/config.h>
36 #include <linux/init.h>
37 #include <linux/gameport.h>
38 #include <linux/slab.h>
39 #include <linux/pci.h>
40
41 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
42 MODULE_DESCRIPTION("EMU10k1 gameport driver");
43 MODULE_LICENSE("GPL");
44
45 struct emu {
46         struct pci_dev *dev;
47         struct gameport gameport;
48         int size;
49         char phys[32];
50 };
51
52 static struct pci_device_id emu_tbl[] = {
53         { 0x1102, 0x7002, PCI_ANY_ID, PCI_ANY_ID }, /* SB Live gameport */
54         { 0x1102, 0x7003, PCI_ANY_ID, PCI_ANY_ID }, /* Audigy gameport */
55         { 0, }
56 };
57
58 MODULE_DEVICE_TABLE(pci, emu_tbl);
59
60 static int __devinit emu_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
61 {
62         int ioport, iolen;
63         struct emu *emu;
64
65         if (pci_enable_device(pdev))
66                 return -EBUSY;
67
68         ioport = pci_resource_start(pdev, 0);
69         iolen = pci_resource_len(pdev, 0);
70
71         if (!request_region(ioport, iolen, "emu10k1-gp"))
72                 return -EBUSY;
73
74         if (!(emu = kmalloc(sizeof(struct emu), GFP_KERNEL))) {
75                 printk(KERN_ERR "emu10k1-gp: Memory allocation failed.\n");
76                 release_region(ioport, iolen);
77                 return -ENOMEM;
78         }
79         memset(emu, 0, sizeof(struct emu));
80
81         sprintf(emu->phys, "pci%s/gameport0", pci_name(pdev));
82
83         emu->size = iolen;
84         emu->dev = pdev;
85
86         emu->gameport.io = ioport;
87         emu->gameport.name = pci_name(pdev);
88         emu->gameport.phys = emu->phys;
89         emu->gameport.id.bustype = BUS_PCI;
90         emu->gameport.id.vendor = pdev->vendor;
91         emu->gameport.id.product = pdev->device;
92
93         pci_set_drvdata(pdev, emu);
94
95         gameport_register_port(&emu->gameport);
96
97         printk(KERN_INFO "gameport: pci%s speed %d kHz\n",
98                 pci_name(pdev), emu->gameport.speed);
99
100         return 0;
101 }
102
103 static void __devexit emu_remove(struct pci_dev *pdev)
104 {
105         struct emu *emu = pci_get_drvdata(pdev);
106         gameport_unregister_port(&emu->gameport);
107         release_region(emu->gameport.io, emu->size);
108         kfree(emu);
109 }
110
111 static struct pci_driver emu_driver = {
112         .name =         "Emu10k1 Gameport",
113         .id_table =     emu_tbl,
114         .probe =        emu_probe,
115         .remove =       __devexit_p(emu_remove),
116 };
117
118 int __init emu_init(void)
119 {
120         return pci_module_init(&emu_driver);
121 }
122
123 void __exit emu_exit(void)
124 {
125         pci_unregister_driver(&emu_driver);
126 }
127
128 module_init(emu_init);
129 module_exit(emu_exit);