ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-2.6.6.tar.bz2
[linux-2.6.git] / sound / pci / au88x0 / au88x0_game.c
1 /*
2  * $Id: au88x0_game.c,v 1.9 2003/09/22 03:51:28 mjander Exp $
3  *
4  *  Manuel Jander.
5  *
6  *  Based on the work of:
7  *  Vojtech Pavlik
8  *  Raymond Ingles
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@suse.cz>, or by paper mail:
26  * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic
27  *
28  * Based 90% on Vojtech Pavlik pcigame driver.
29  * Merged and modified by Manuel Jander, for the OpenVortex
30  * driver. (email: mjander@embedded.cl).
31  */
32
33 #include <sound/driver.h>
34 #include <linux/time.h>
35 #include <linux/init.h>
36 #include <sound/core.h>
37 #include "au88x0.h"
38 #include <linux/gameport.h>
39
40 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
41
42 #define VORTEX_GAME_DWAIT       20      /* 20 ms */
43
44 static struct gameport gameport;
45
46 static unsigned char vortex_game_read(struct gameport *gameport)
47 {
48         vortex_t *vortex = gameport->driver;
49         return hwread(vortex->mmio, VORTEX_GAME_LEGACY);
50 }
51
52 static void vortex_game_trigger(struct gameport *gameport)
53 {
54         vortex_t *vortex = gameport->driver;
55         hwwrite(vortex->mmio, VORTEX_GAME_LEGACY, 0xff);
56 }
57
58 static int
59 vortex_game_cooked_read(struct gameport *gameport, int *axes, int *buttons)
60 {
61         vortex_t *vortex = gameport->driver;
62         int i;
63
64         *buttons = (~hwread(vortex->mmio, VORTEX_GAME_LEGACY) >> 4) & 0xf;
65
66         for (i = 0; i < 4; i++) {
67                 axes[i] =
68                     hwread(vortex->mmio, VORTEX_GAME_AXIS + (i * AXIS_SIZE));
69                 if (axes[i] == AXIS_RANGE)
70                         axes[i] = -1;
71         }
72         return 0;
73 }
74
75 static int vortex_game_open(struct gameport *gameport, int mode)
76 {
77         vortex_t *vortex = gameport->driver;
78
79         switch (mode) {
80         case GAMEPORT_MODE_COOKED:
81                 hwwrite(vortex->mmio, VORTEX_CTRL2,
82                         hwread(vortex->mmio,
83                                VORTEX_CTRL2) | CTRL2_GAME_ADCMODE);
84                 wait_ms(VORTEX_GAME_DWAIT);
85                 return 0;
86         case GAMEPORT_MODE_RAW:
87                 hwwrite(vortex->mmio, VORTEX_CTRL2,
88                         hwread(vortex->mmio,
89                                VORTEX_CTRL2) & ~CTRL2_GAME_ADCMODE);
90                 return 0;
91         default:
92                 return -1;
93         }
94
95         return 0;
96 }
97
98 static int vortex_gameport_register(vortex_t * vortex)
99 {
100         vortex->gameport = &gameport;
101
102         vortex->gameport->driver = vortex;
103         vortex->gameport->fuzz = 64;
104
105         vortex->gameport->read = vortex_game_read;
106         vortex->gameport->trigger = vortex_game_trigger;
107         vortex->gameport->cooked_read = vortex_game_cooked_read;
108         vortex->gameport->open = vortex_game_open;
109
110         gameport_register_port((struct gameport *)vortex->gameport);
111
112 /*      printk(KERN_INFO "gameport%d: %s at speed %d kHz\n",
113                 vortex->gameport->number, vortex->pci_dev->name, vortex->gameport->speed);
114 */
115         return 0;
116 }
117
118 static int vortex_gameport_unregister(vortex_t * vortex)
119 {
120         if (vortex->gameport != NULL)
121                 gameport_unregister_port(vortex->gameport);
122         return 0;
123 }
124
125 #else
126
127 static inline int vortex_gameport_register(vortex_t * vortex) { return 0; }
128 static inline int vortex_gameport_unregister(vortex_t * vortex) { return 0; }
129
130 #endif