blob: b04930f7ea7da88e36e65a9c9faa9f188778de93 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Copyright (c) 2001 Vojtech Pavlik
3 */
4
5/*
6 * EMU10k1 - SB Live / Audigy - gameport driver for Linux
7 */
8
9/*
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 * Should you need to contact me, the author, you can do so either by
25 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
26 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
27 */
28
29#include <asm/io.h>
30
31#include <linux/module.h>
32#include <linux/ioport.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033#include <linux/init.h>
34#include <linux/gameport.h>
35#include <linux/slab.h>
36#include <linux/pci.h>
37
38MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
39MODULE_DESCRIPTION("EMU10k1 gameport driver");
40MODULE_LICENSE("GPL");
41
42struct emu {
43 struct pci_dev *dev;
44 struct gameport *gameport;
45 int io;
46 int size;
47};
48
49static struct pci_device_id emu_tbl[] = {
50
51 { 0x1102, 0x7002, PCI_ANY_ID, PCI_ANY_ID }, /* SB Live gameport */
52 { 0x1102, 0x7003, PCI_ANY_ID, PCI_ANY_ID }, /* Audigy gameport */
53 { 0x1102, 0x7004, PCI_ANY_ID, PCI_ANY_ID }, /* Dell SB Live */
54 { 0x1102, 0x7005, PCI_ANY_ID, PCI_ANY_ID }, /* Audigy LS gameport */
55 { 0, }
56};
57
58MODULE_DEVICE_TABLE(pci, emu_tbl);
59
60static int __devinit emu_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
61{
62 int ioport, iolen;
63 struct emu *emu;
64 struct gameport *port;
65
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
Pekka Enberga97e1482005-09-06 15:18:33 -070075 emu = kzalloc(sizeof(struct emu), GFP_KERNEL);
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 port = gameport_allocate_port();
77 if (!emu || !port) {
78 printk(KERN_ERR "emu10k1-gp: Memory allocation failed\n");
79 release_region(ioport, iolen);
80 kfree(emu);
81 gameport_free_port(port);
82 return -ENOMEM;
83 }
84
85 emu->io = ioport;
86 emu->size = iolen;
87 emu->dev = pdev;
88 emu->gameport = port;
89
90 gameport_set_name(port, "EMU10K1");
91 gameport_set_phys(port, "pci%s/gameport0", pci_name(pdev));
92 port->dev.parent = &pdev->dev;
93 port->io = ioport;
94
95 pci_set_drvdata(pdev, emu);
96
97 gameport_register_port(port);
98
99 return 0;
100}
101
102static void __devexit emu_remove(struct pci_dev *pdev)
103{
104 struct emu *emu = pci_get_drvdata(pdev);
105
106 gameport_unregister_port(emu->gameport);
107 release_region(emu->io, emu->size);
108 kfree(emu);
109}
110
111static 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
118static int __init emu_init(void)
119{
120 return pci_register_driver(&emu_driver);
121}
122
123static void __exit emu_exit(void)
124{
125 pci_unregister_driver(&emu_driver);
126}
127
128module_init(emu_init);
129module_exit(emu_exit);