2 * $Id: vortex.c,v 1.5 2002/07/01 15:39:30 vojtech Exp $
4 * Copyright (c) 2000-2001 Vojtech Pavlik
6 * Based on the work of:
11 * Trident 4DWave and Aureal Vortex gameport driver for Linux
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 * Should you need to contact me, the author, you can do so either by
30 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
31 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
35 #include <linux/delay.h>
36 #include <linux/errno.h>
37 #include <linux/ioport.h>
38 #include <linux/kernel.h>
39 #include <linux/module.h>
40 #include <linux/pci.h>
41 #include <linux/init.h>
42 #include <linux/slab.h>
43 #include <linux/delay.h>
44 #include <linux/gameport.h>
46 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
47 MODULE_DESCRIPTION("Aureal Vortex and Vortex2 gameport driver");
48 MODULE_LICENSE("GPL");
50 #define VORTEX_GCR 0x0c /* Gameport control register */
51 #define VORTEX_LEG 0x08 /* Legacy port location */
52 #define VORTEX_AXD 0x10 /* Axes start */
53 #define VORTEX_DATA_WAIT 20 /* 20 ms */
56 struct gameport gameport;
63 static unsigned char vortex_read(struct gameport *gameport)
65 struct vortex *vortex = gameport->driver;
66 return readb(vortex->io + VORTEX_LEG);
69 static void vortex_trigger(struct gameport *gameport)
71 struct vortex *vortex = gameport->driver;
72 writeb(0xff, vortex->io + VORTEX_LEG);
75 static int vortex_cooked_read(struct gameport *gameport, int *axes, int *buttons)
77 struct vortex *vortex = gameport->driver;
80 *buttons = (~readb(vortex->base + VORTEX_LEG) >> 4) & 0xf;
82 for (i = 0; i < 4; i++) {
83 axes[i] = readw(vortex->io + VORTEX_AXD + i * sizeof(u32));
84 if (axes[i] == 0x1fff) axes[i] = -1;
90 static int vortex_open(struct gameport *gameport, int mode)
92 struct vortex *vortex = gameport->driver;
95 case GAMEPORT_MODE_COOKED:
96 writeb(0x40, vortex->io + VORTEX_GCR);
97 msleep(VORTEX_DATA_WAIT);
99 case GAMEPORT_MODE_RAW:
100 writeb(0x00, vortex->io + VORTEX_GCR);
109 static int __devinit vortex_probe(struct pci_dev *dev, const struct pci_device_id *id)
111 struct vortex *vortex;
114 if (!(vortex = kmalloc(sizeof(struct vortex), GFP_KERNEL)))
116 memset(vortex, 0, sizeof(struct vortex));
119 sprintf(vortex->phys, "pci%s/gameport0", pci_name(dev));
121 pci_set_drvdata(dev, vortex);
123 vortex->gameport.driver = vortex;
124 vortex->gameport.fuzz = 64;
126 vortex->gameport.read = vortex_read;
127 vortex->gameport.trigger = vortex_trigger;
128 vortex->gameport.cooked_read = vortex_cooked_read;
129 vortex->gameport.open = vortex_open;
131 vortex->gameport.name = pci_name(dev);
132 vortex->gameport.phys = vortex->phys;
133 vortex->gameport.id.bustype = BUS_PCI;
134 vortex->gameport.id.vendor = dev->vendor;
135 vortex->gameport.id.product = dev->device;
137 for (i = 0; i < 6; i++)
138 if (~pci_resource_flags(dev, i) & IORESOURCE_IO)
141 pci_enable_device(dev);
143 vortex->base = ioremap(pci_resource_start(vortex->dev, i),
144 pci_resource_len(vortex->dev, i));
145 vortex->io = vortex->base + id->driver_data;
147 gameport_register_port(&vortex->gameport);
149 printk(KERN_INFO "gameport at pci%s speed %d kHz\n",
150 pci_name(dev), vortex->gameport.speed);
155 static void __devexit vortex_remove(struct pci_dev *dev)
157 struct vortex *vortex = pci_get_drvdata(dev);
158 gameport_unregister_port(&vortex->gameport);
159 iounmap(vortex->base);
163 static struct pci_device_id vortex_id_table[] =
164 {{ 0x12eb, 0x0001, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0x11000 },
165 { 0x12eb, 0x0002, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0x28800 },
168 static struct pci_driver vortex_driver = {
170 .id_table = vortex_id_table,
171 .probe = vortex_probe,
172 .remove = __devexit_p(vortex_remove),
175 int __init vortex_init(void)
177 return pci_module_init(&vortex_driver);
180 void __exit vortex_exit(void)
182 pci_unregister_driver(&vortex_driver);
185 module_init(vortex_init);
186 module_exit(vortex_exit);