initial commit with v2.6.9
[linux-2.6.9-moxart.git] / drivers / input / gameport / fm801-gp.c
blob93849a6cc98d9ce4cd18c6ccbc0ec8dfd4ae593d
1 /*
2 * FM801 gameport driver for Linux
4 * Copyright (c) by Takashi Iwai <tiwai@suse.de>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <asm/io.h>
24 #include <linux/delay.h>
25 #include <linux/errno.h>
26 #include <linux/ioport.h>
27 #include <linux/kernel.h>
28 #include <linux/module.h>
29 #include <linux/pci.h>
30 #include <linux/init.h>
31 #include <linux/slab.h>
32 #include <linux/gameport.h>
34 #define PCI_VENDOR_ID_FORTEMEDIA 0x1319
35 #define PCI_DEVICE_ID_FM801_GP 0x0802
37 #define HAVE_COOKED
39 struct fm801_gp {
40 struct gameport gameport;
41 struct resource *res_port;
42 char phys[32];
43 char name[32];
46 #ifdef HAVE_COOKED
47 static int fm801_gp_cooked_read(struct gameport *gameport, int *axes, int *buttons)
49 unsigned short w;
51 w = inw(gameport->io + 2);
52 *buttons = (~w >> 14) & 0x03;
53 axes[0] = (w == 0xffff) ? -1 : ((w & 0x1fff) << 5);
54 w = inw(gameport->io + 4);
55 axes[1] = (w == 0xffff) ? -1 : ((w & 0x1fff) << 5);
56 w = inw(gameport->io + 6);
57 *buttons |= ((~w >> 14) & 0x03) << 2;
58 axes[2] = (w == 0xffff) ? -1 : ((w & 0x1fff) << 5);
59 w = inw(gameport->io + 8);
60 axes[3] = (w == 0xffff) ? -1 : ((w & 0x1fff) << 5);
61 outw(0xff, gameport->io); /* reset */
63 return 0;
65 #endif
67 static int fm801_gp_open(struct gameport *gameport, int mode)
69 switch (mode) {
70 #ifdef HAVE_COOKED
71 case GAMEPORT_MODE_COOKED:
72 return 0;
73 #endif
74 case GAMEPORT_MODE_RAW:
75 return 0;
76 default:
77 return -1;
80 return 0;
83 static int __devinit fm801_gp_probe(struct pci_dev *pci, const struct pci_device_id *id)
85 struct fm801_gp *gp;
87 if (! (gp = kmalloc(sizeof(*gp), GFP_KERNEL))) {
88 printk("cannot malloc for fm801-gp\n");
89 return -1;
91 memset(gp, 0, sizeof(*gp));
93 gp->gameport.open = fm801_gp_open;
94 #ifdef HAVE_COOKED
95 gp->gameport.cooked_read = fm801_gp_cooked_read;
96 #endif
98 pci_enable_device(pci);
99 gp->gameport.io = pci_resource_start(pci, 0);
100 if ((gp->res_port = request_region(gp->gameport.io, 0x10, "FM801 GP")) == NULL) {
101 kfree(gp);
102 printk("unable to grab region 0x%x-0x%x\n", gp->gameport.io, gp->gameport.io + 0x0f);
103 return -1;
106 gp->gameport.phys = gp->phys;
107 gp->gameport.name = gp->name;
108 gp->gameport.id.bustype = BUS_PCI;
109 gp->gameport.id.vendor = pci->vendor;
110 gp->gameport.id.product = pci->device;
112 pci_set_drvdata(pci, gp);
114 outb(0x60, gp->gameport.io + 0x0d); /* enable joystick 1 and 2 */
116 gameport_register_port(&gp->gameport);
118 printk(KERN_INFO "gameport: at pci%s speed %d kHz\n",
119 pci_name(pci), gp->gameport.speed);
121 return 0;
124 static void __devexit fm801_gp_remove(struct pci_dev *pci)
126 struct fm801_gp *gp = pci_get_drvdata(pci);
127 if (gp) {
128 gameport_unregister_port(&gp->gameport);
129 release_resource(gp->res_port);
130 kfree(gp);
134 static struct pci_device_id fm801_gp_id_table[] = {
135 { PCI_VENDOR_ID_FORTEMEDIA, PCI_DEVICE_ID_FM801_GP, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 0 },
136 { 0 }
139 static struct pci_driver fm801_gp_driver = {
140 .name = "FM801_gameport",
141 .id_table = fm801_gp_id_table,
142 .probe = fm801_gp_probe,
143 .remove = __devexit_p(fm801_gp_remove),
146 int __init fm801_gp_init(void)
148 return pci_module_init(&fm801_gp_driver);
151 void __exit fm801_gp_exit(void)
153 pci_unregister_driver(&fm801_gp_driver);
156 module_init(fm801_gp_init);
157 module_exit(fm801_gp_exit);
159 MODULE_DEVICE_TABLE(pci, fm801_gp_id_table);
161 MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
162 MODULE_LICENSE("GPL");