1#ifndef _GAMEPORT_H
2#define _GAMEPORT_H
3
4
5
6
7
8
9
10
11
12#ifdef __KERNEL__
13#include <asm/io.h>
14#include <linux/types.h>
15#include <linux/list.h>
16#include <linux/mutex.h>
17#include <linux/device.h>
18#include <linux/timer.h>
19#include <linux/slab.h>
20
21struct gameport {
22
23 void *port_data;
24 char name[32];
25 char phys[32];
26
27 int io;
28 int speed;
29 int fuzz;
30
31 void (*trigger)(struct gameport *);
32 unsigned char (*read)(struct gameport *);
33 int (*cooked_read)(struct gameport *, int *, int *);
34 int (*calibrate)(struct gameport *, int *, int *);
35 int (*open)(struct gameport *, int);
36 void (*close)(struct gameport *);
37
38 struct timer_list poll_timer;
39 unsigned int poll_interval;
40 spinlock_t timer_lock;
41 unsigned int poll_cnt;
42 void (*poll_handler)(struct gameport *);
43
44 struct gameport *parent, *child;
45
46 struct gameport_driver *drv;
47 struct mutex drv_mutex;
48
49 struct device dev;
50
51 struct list_head node;
52};
53#define to_gameport_port(d) container_of(d, struct gameport, dev)
54
55struct gameport_driver {
56 const char *description;
57
58 int (*connect)(struct gameport *, struct gameport_driver *drv);
59 int (*reconnect)(struct gameport *);
60 void (*disconnect)(struct gameport *);
61
62 struct device_driver driver;
63
64 bool ignore;
65};
66#define to_gameport_driver(d) container_of(d, struct gameport_driver, driver)
67
68int gameport_open(struct gameport *gameport, struct gameport_driver *drv, int mode);
69void gameport_close(struct gameport *gameport);
70
71#if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
72
73void __gameport_register_port(struct gameport *gameport, struct module *owner);
74static inline void gameport_register_port(struct gameport *gameport)
75{
76 __gameport_register_port(gameport, THIS_MODULE);
77}
78
79void gameport_unregister_port(struct gameport *gameport);
80
81void gameport_set_phys(struct gameport *gameport, const char *fmt, ...)
82 __attribute__ ((format (printf, 2, 3)));
83
84#else
85
86static inline void gameport_register_port(struct gameport *gameport)
87{
88 return;
89}
90
91static inline void gameport_unregister_port(struct gameport *gameport)
92{
93 return;
94}
95
96static inline void gameport_set_phys(struct gameport *gameport,
97 const char *fmt, ...)
98{
99 return;
100}
101
102#endif
103
104static inline struct gameport *gameport_allocate_port(void)
105{
106 struct gameport *gameport = kzalloc(sizeof(struct gameport), GFP_KERNEL);
107
108 return gameport;
109}
110
111static inline void gameport_free_port(struct gameport *gameport)
112{
113 kfree(gameport);
114}
115
116static inline void gameport_set_name(struct gameport *gameport, const char *name)
117{
118 strlcpy(gameport->name, name, sizeof(gameport->name));
119}
120
121
122
123
124
125static inline void *gameport_get_drvdata(struct gameport *gameport)
126{
127 return dev_get_drvdata(&gameport->dev);
128}
129
130static inline void gameport_set_drvdata(struct gameport *gameport, void *data)
131{
132 dev_set_drvdata(&gameport->dev, data);
133}
134
135
136
137
138static inline int gameport_pin_driver(struct gameport *gameport)
139{
140 return mutex_lock_interruptible(&gameport->drv_mutex);
141}
142
143static inline void gameport_unpin_driver(struct gameport *gameport)
144{
145 mutex_unlock(&gameport->drv_mutex);
146}
147
148int __gameport_register_driver(struct gameport_driver *drv,
149 struct module *owner, const char *mod_name);
150static inline int __must_check gameport_register_driver(struct gameport_driver *drv)
151{
152 return __gameport_register_driver(drv, THIS_MODULE, KBUILD_MODNAME);
153}
154
155void gameport_unregister_driver(struct gameport_driver *drv);
156
157#endif
158
159#define GAMEPORT_MODE_DISABLED 0
160#define GAMEPORT_MODE_RAW 1
161#define GAMEPORT_MODE_COOKED 2
162
163#define GAMEPORT_ID_VENDOR_ANALOG 0x0001
164#define GAMEPORT_ID_VENDOR_MADCATZ 0x0002
165#define GAMEPORT_ID_VENDOR_LOGITECH 0x0003
166#define GAMEPORT_ID_VENDOR_CREATIVE 0x0004
167#define GAMEPORT_ID_VENDOR_GENIUS 0x0005
168#define GAMEPORT_ID_VENDOR_INTERACT 0x0006
169#define GAMEPORT_ID_VENDOR_MICROSOFT 0x0007
170#define GAMEPORT_ID_VENDOR_THRUSTMASTER 0x0008
171#define GAMEPORT_ID_VENDOR_GRAVIS 0x0009
172#define GAMEPORT_ID_VENDOR_GUILLEMOT 0x000a
173
174#ifdef __KERNEL__
175
176static inline void gameport_trigger(struct gameport *gameport)
177{
178 if (gameport->trigger)
179 gameport->trigger(gameport);
180 else
181 outb(0xff, gameport->io);
182}
183
184static inline unsigned char gameport_read(struct gameport *gameport)
185{
186 if (gameport->read)
187 return gameport->read(gameport);
188 else
189 return inb(gameport->io);
190}
191
192static inline int gameport_cooked_read(struct gameport *gameport, int *axes, int *buttons)
193{
194 if (gameport->cooked_read)
195 return gameport->cooked_read(gameport, axes, buttons);
196 else
197 return -1;
198}
199
200static inline int gameport_calibrate(struct gameport *gameport, int *axes, int *max)
201{
202 if (gameport->calibrate)
203 return gameport->calibrate(gameport, axes, max);
204 else
205 return -1;
206}
207
208static inline int gameport_time(struct gameport *gameport, int time)
209{
210 return (time * gameport->speed) / 1000;
211}
212
213static inline void gameport_set_poll_handler(struct gameport *gameport, void (*handler)(struct gameport *))
214{
215 gameport->poll_handler = handler;
216}
217
218static inline void gameport_set_poll_interval(struct gameport *gameport, unsigned int msecs)
219{
220 gameport->poll_interval = msecs;
221}
222
223void gameport_start_polling(struct gameport *gameport);
224void gameport_stop_polling(struct gameport *gameport);
225
226#endif
227#endif
228