1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31#include <linux/time.h>
32#include <linux/delay.h>
33#include <linux/init.h>
34#include <sound/core.h>
35#include "au88x0.h"
36#include <linux/gameport.h>
37#include <linux/export.h>
38
39#if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
40
41#define VORTEX_GAME_DWAIT 20
42
43static unsigned char vortex_game_read(struct gameport *gameport)
44{
45 vortex_t *vortex = gameport_get_port_data(gameport);
46 return hwread(vortex->mmio, VORTEX_GAME_LEGACY);
47}
48
49static void vortex_game_trigger(struct gameport *gameport)
50{
51 vortex_t *vortex = gameport_get_port_data(gameport);
52 hwwrite(vortex->mmio, VORTEX_GAME_LEGACY, 0xff);
53}
54
55static int
56vortex_game_cooked_read(struct gameport *gameport, int *axes, int *buttons)
57{
58 vortex_t *vortex = gameport_get_port_data(gameport);
59 int i;
60
61 *buttons = (~hwread(vortex->mmio, VORTEX_GAME_LEGACY) >> 4) & 0xf;
62
63 for (i = 0; i < 4; i++) {
64 axes[i] =
65 hwread(vortex->mmio, VORTEX_GAME_AXIS + (i * AXIS_SIZE));
66 if (axes[i] == AXIS_RANGE)
67 axes[i] = -1;
68 }
69 return 0;
70}
71
72static int vortex_game_open(struct gameport *gameport, int mode)
73{
74 vortex_t *vortex = gameport_get_port_data(gameport);
75
76 switch (mode) {
77 case GAMEPORT_MODE_COOKED:
78 hwwrite(vortex->mmio, VORTEX_CTRL2,
79 hwread(vortex->mmio,
80 VORTEX_CTRL2) | CTRL2_GAME_ADCMODE);
81 msleep(VORTEX_GAME_DWAIT);
82 return 0;
83 case GAMEPORT_MODE_RAW:
84 hwwrite(vortex->mmio, VORTEX_CTRL2,
85 hwread(vortex->mmio,
86 VORTEX_CTRL2) & ~CTRL2_GAME_ADCMODE);
87 return 0;
88 default:
89 return -1;
90 }
91
92 return 0;
93}
94
95static int __devinit vortex_gameport_register(vortex_t * vortex)
96{
97 struct gameport *gp;
98
99 vortex->gameport = gp = gameport_allocate_port();
100 if (!gp) {
101 printk(KERN_ERR "vortex: cannot allocate memory for gameport\n");
102 return -ENOMEM;
103 };
104
105 gameport_set_name(gp, "AU88x0 Gameport");
106 gameport_set_phys(gp, "pci%s/gameport0", pci_name(vortex->pci_dev));
107 gameport_set_dev_parent(gp, &vortex->pci_dev->dev);
108
109 gp->read = vortex_game_read;
110 gp->trigger = vortex_game_trigger;
111 gp->cooked_read = vortex_game_cooked_read;
112 gp->open = vortex_game_open;
113
114 gameport_set_port_data(gp, vortex);
115 gp->fuzz = 64;
116
117 gameport_register_port(gp);
118
119 return 0;
120}
121
122static void vortex_gameport_unregister(vortex_t * vortex)
123{
124 if (vortex->gameport) {
125 gameport_unregister_port(vortex->gameport);
126 vortex->gameport = NULL;
127 }
128}
129
130#else
131static inline int vortex_gameport_register(vortex_t * vortex) { return -ENOSYS; }
132static inline void vortex_gameport_unregister(vortex_t * vortex) { }
133#endif
134