1/*
2 * $Id: emu10k1-gp.c,v 1.1.1.1 2007/08/03 18:52:32 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/init.h>
36#include <linux/gameport.h>
37#include <linux/slab.h>
38#include <linux/pci.h>
39
40MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
41MODULE_DESCRIPTION("EMU10k1 gameport driver");
42MODULE_LICENSE("GPL");
43
44struct emu {
45	struct pci_dev *dev;
46	struct gameport *gameport;
47	int io;
48	int size;
49};
50
51static struct pci_device_id emu_tbl[] = {
52
53	{ 0x1102, 0x7002, PCI_ANY_ID, PCI_ANY_ID }, /* SB Live gameport */
54	{ 0x1102, 0x7003, PCI_ANY_ID, PCI_ANY_ID }, /* Audigy gameport */
55	{ 0x1102, 0x7004, PCI_ANY_ID, PCI_ANY_ID }, /* Dell SB Live */
56	{ 0x1102, 0x7005, PCI_ANY_ID, PCI_ANY_ID }, /* Audigy LS gameport */
57	{ 0, }
58};
59
60MODULE_DEVICE_TABLE(pci, emu_tbl);
61
62static int __devinit emu_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
63{
64	int ioport, iolen;
65	struct emu *emu;
66	struct gameport *port;
67
68	if (pci_enable_device(pdev))
69		return -EBUSY;
70
71	ioport = pci_resource_start(pdev, 0);
72	iolen = pci_resource_len(pdev, 0);
73
74	if (!request_region(ioport, iolen, "emu10k1-gp"))
75		return -EBUSY;
76
77	emu = kzalloc(sizeof(struct emu), GFP_KERNEL);
78	port = gameport_allocate_port();
79	if (!emu || !port) {
80		printk(KERN_ERR "emu10k1-gp: Memory allocation failed\n");
81		release_region(ioport, iolen);
82		kfree(emu);
83		gameport_free_port(port);
84		return -ENOMEM;
85	}
86
87	emu->io = ioport;
88	emu->size = iolen;
89	emu->dev = pdev;
90	emu->gameport = port;
91
92	gameport_set_name(port, "EMU10K1");
93	gameport_set_phys(port, "pci%s/gameport0", pci_name(pdev));
94	port->dev.parent = &pdev->dev;
95	port->io = ioport;
96
97	pci_set_drvdata(pdev, emu);
98
99	gameport_register_port(port);
100
101	return 0;
102}
103
104static void __devexit emu_remove(struct pci_dev *pdev)
105{
106	struct emu *emu = pci_get_drvdata(pdev);
107
108	gameport_unregister_port(emu->gameport);
109	release_region(emu->io, emu->size);
110	kfree(emu);
111}
112
113static struct pci_driver emu_driver = {
114        .name =         "Emu10k1_gameport",
115        .id_table =     emu_tbl,
116        .probe =        emu_probe,
117        .remove =       __devexit_p(emu_remove),
118};
119
120static int __init emu_init(void)
121{
122	return pci_register_driver(&emu_driver);
123}
124
125static void __exit emu_exit(void)
126{
127	pci_unregister_driver(&emu_driver);
128}
129
130module_init(emu_init);
131module_exit(emu_exit);
132