aboutsummaryrefslogtreecommitdiffstats
path: root/include/linux/gameport.h
diff options
context:
space:
mode:
Diffstat (limited to 'include/linux/gameport.h')
-rw-r--r--include/linux/gameport.h198
1 files changed, 198 insertions, 0 deletions
diff --git a/include/linux/gameport.h b/include/linux/gameport.h
new file mode 100644
index 000000000000..b1272f822cfa
--- /dev/null
+++ b/include/linux/gameport.h
@@ -0,0 +1,198 @@
1#ifndef _GAMEPORT_H
2#define _GAMEPORT_H
3
4/*
5 * Copyright (c) 1999-2002 Vojtech Pavlik
6 *
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
10 */
11
12#include <asm/io.h>
13#include <linux/list.h>
14#include <linux/device.h>
15
16struct gameport {
17
18 void *port_data; /* Private pointer for gameport drivers */
19 char name[32];
20 char phys[32];
21
22 int io;
23 int speed;
24 int fuzz;
25
26 void (*trigger)(struct gameport *);
27 unsigned char (*read)(struct gameport *);
28 int (*cooked_read)(struct gameport *, int *, int *);
29 int (*calibrate)(struct gameport *, int *, int *);
30 int (*open)(struct gameport *, int);
31 void (*close)(struct gameport *);
32
33 struct timer_list poll_timer;
34 unsigned int poll_interval; /* in msecs */
35 spinlock_t timer_lock;
36 unsigned int poll_cnt;
37 void (*poll_handler)(struct gameport *);
38
39 struct gameport *parent, *child;
40
41 struct gameport_driver *drv;
42 struct semaphore drv_sem; /* protects serio->drv so attributes can pin driver */
43
44 struct device dev;
45 unsigned int registered; /* port has been fully registered with driver core */
46
47 struct list_head node;
48};
49#define to_gameport_port(d) container_of(d, struct gameport, dev)
50
51struct gameport_driver {
52
53 void *private;
54 char *description;
55
56 int (*connect)(struct gameport *, struct gameport_driver *drv);
57 int (*reconnect)(struct gameport *);
58 void (*disconnect)(struct gameport *);
59
60 struct device_driver driver;
61
62 unsigned int ignore;
63};
64#define to_gameport_driver(d) container_of(d, struct gameport_driver, driver)
65
66int gameport_open(struct gameport *gameport, struct gameport_driver *drv, int mode);
67void gameport_close(struct gameport *gameport);
68void gameport_rescan(struct gameport *gameport);
69
70void __gameport_register_port(struct gameport *gameport, struct module *owner);
71static inline void gameport_register_port(struct gameport *gameport)
72{
73 __gameport_register_port(gameport, THIS_MODULE);
74}
75
76void gameport_unregister_port(struct gameport *gameport);
77
78static inline struct gameport *gameport_allocate_port(void)
79{
80 struct gameport *gameport = kcalloc(1, sizeof(struct gameport), GFP_KERNEL);
81
82 return gameport;
83}
84
85static inline void gameport_free_port(struct gameport *gameport)
86{
87 kfree(gameport);
88}
89
90static inline void gameport_set_name(struct gameport *gameport, const char *name)
91{
92 strlcpy(gameport->name, name, sizeof(gameport->name));
93}
94
95void gameport_set_phys(struct gameport *gameport, const char *fmt, ...)
96 __attribute__ ((format (printf, 2, 3)));
97
98/*
99 * Use the following fucntions to manipulate gameport's per-port
100 * driver-specific data.
101 */
102static inline void *gameport_get_drvdata(struct gameport *gameport)
103{
104 return dev_get_drvdata(&gameport->dev);
105}
106
107static inline void gameport_set_drvdata(struct gameport *gameport, void *data)
108{
109 dev_set_drvdata(&gameport->dev, data);
110}
111
112/*
113 * Use the following fucntions to pin gameport's driver in process context
114 */
115static inline int gameport_pin_driver(struct gameport *gameport)
116{
117 return down_interruptible(&gameport->drv_sem);
118}
119
120static inline void gameport_unpin_driver(struct gameport *gameport)
121{
122 up(&gameport->drv_sem);
123}
124
125void __gameport_register_driver(struct gameport_driver *drv, struct module *owner);
126static inline void gameport_register_driver(struct gameport_driver *drv)
127{
128 __gameport_register_driver(drv, THIS_MODULE);
129}
130
131void gameport_unregister_driver(struct gameport_driver *drv);
132
133#define GAMEPORT_MODE_DISABLED 0
134#define GAMEPORT_MODE_RAW 1
135#define GAMEPORT_MODE_COOKED 2
136
137#define GAMEPORT_ID_VENDOR_ANALOG 0x0001
138#define GAMEPORT_ID_VENDOR_MADCATZ 0x0002
139#define GAMEPORT_ID_VENDOR_LOGITECH 0x0003
140#define GAMEPORT_ID_VENDOR_CREATIVE 0x0004
141#define GAMEPORT_ID_VENDOR_GENIUS 0x0005
142#define GAMEPORT_ID_VENDOR_INTERACT 0x0006
143#define GAMEPORT_ID_VENDOR_MICROSOFT 0x0007
144#define GAMEPORT_ID_VENDOR_THRUSTMASTER 0x0008
145#define GAMEPORT_ID_VENDOR_GRAVIS 0x0009
146#define GAMEPORT_ID_VENDOR_GUILLEMOT 0x000a
147
148static inline void gameport_trigger(struct gameport *gameport)
149{
150 if (gameport->trigger)
151 gameport->trigger(gameport);
152 else
153 outb(0xff, gameport->io);
154}
155
156static inline unsigned char gameport_read(struct gameport *gameport)
157{
158 if (gameport->read)
159 return gameport->read(gameport);
160 else
161 return inb(gameport->io);
162}
163
164static inline int gameport_cooked_read(struct gameport *gameport, int *axes, int *buttons)
165{
166 if (gameport->cooked_read)
167 return gameport->cooked_read(gameport, axes, buttons);
168 else
169 return -1;
170}
171
172static inline int gameport_calibrate(struct gameport *gameport, int *axes, int *max)
173{
174 if (gameport->calibrate)
175 return gameport->calibrate(gameport, axes, max);
176 else
177 return -1;
178}
179
180static inline int gameport_time(struct gameport *gameport, int time)
181{
182 return (time * gameport->speed) / 1000;
183}
184
185static inline void gameport_set_poll_handler(struct gameport *gameport, void (*handler)(struct gameport *))
186{
187 gameport->poll_handler = handler;
188}
189
190static inline void gameport_set_poll_interval(struct gameport *gameport, unsigned int msecs)
191{
192 gameport->poll_interval = msecs;
193}
194
195void gameport_start_polling(struct gameport *gameport);
196void gameport_stop_polling(struct gameport *gameport);
197
198#endif