]> icculus.org git repositories - btb/d2x.git/blob - input/linux/include/joystick.h
This commit was generated by cvs2svn to compensate for changes in r2,
[btb/d2x.git] / input / linux / include / joystick.h
1 #ifndef _LINUX_JOYSTICK_H
2 #define _LINUX_JOYSTICK_H
3
4 /*
5  *  /usr/include/linux/joystick.h  Version 1.2
6  *
7  *  Copyright (C) 1996-1998 Vojtech Pavlik
8  */
9
10 #include <asm/types.h>
11 #include <linux/module.h>
12
13 /*
14  * Version
15  */
16
17 #define JS_VERSION              0x01020a
18
19 /*
20  * Types and constants for reading from /dev/js
21  */
22
23 #define JS_EVENT_BUTTON         0x01    /* button pressed/released */
24 #define JS_EVENT_AXIS           0x02    /* joystick moved */
25 #define JS_EVENT_INIT           0x80    /* initial state of device */
26
27 struct js_event {
28         __u32 time;     /* event timestamp in miliseconds */
29         __s16 value;    /* value */
30         __u8 type;      /* event type */
31         __u8 number;    /* axis/button number */
32 };
33
34 /*
35  * IOCTL commands for joystick driver
36  */
37
38 #define JSIOCGVERSION           _IOR('j', 0x01, __u32)                  /* get driver version */
39
40 #define JSIOCGAXES              _IOR('j', 0x11, __u8)                   /* get number of axes */
41 #define JSIOCGBUTTONS           _IOR('j', 0x12, __u8)                   /* get number of buttons */
42 #define JSIOCGNAME(len)         _IOC(_IOC_READ, 'j', 0x13, len)         /* get identifier string */
43
44 #define JSIOCSCORR              _IOW('j', 0x21, struct js_corr)         /* set correction values */
45 #define JSIOCGCORR              _IOR('j', 0x22, struct js_corr)         /* get correction values */
46
47 /*
48  * Types and constants for get/set correction
49  */
50
51 #define JS_CORR_NONE            0x00    /* returns raw values */
52 #define JS_CORR_BROKEN          0x01    /* broken line */
53
54 struct js_corr {
55         __s32 coef[8];
56         __s16 prec;
57         __u16 type;
58 };
59
60 /*
61  * v0.x compatibility definitions
62  */
63
64 #define JS_RETURN               sizeof(struct JS_DATA_TYPE)
65 #define JS_TRUE                 1
66 #define JS_FALSE                0
67 #define JS_X_0                  0x01
68 #define JS_Y_0                  0x02
69 #define JS_X_1                  0x04
70 #define JS_Y_1                  0x08
71 #define JS_MAX                  2
72
73 #define JS_DEF_TIMEOUT          0x1300
74 #define JS_DEF_CORR             0
75 #define JS_DEF_TIMELIMIT        10L
76
77 #define JS_SET_CAL              1
78 #define JS_GET_CAL              2
79 #define JS_SET_TIMEOUT          3
80 #define JS_GET_TIMEOUT          4
81 #define JS_SET_TIMELIMIT        5
82 #define JS_GET_TIMELIMIT        6
83 #define JS_GET_ALL              7
84 #define JS_SET_ALL              8
85
86 struct JS_DATA_TYPE {
87         int buttons;
88         int x;
89         int y;
90 };
91
92 struct JS_DATA_SAVE_TYPE {
93         int JS_TIMEOUT;
94         int BUSY;
95         long JS_EXPIRETIME;
96         long JS_TIMELIMIT;
97         struct JS_DATA_TYPE JS_SAVE;
98         struct JS_DATA_TYPE JS_CORR;
99 };
100
101 /*
102  * Internal definitions
103  */
104
105 #ifdef __KERNEL__
106
107 #define JS_BUFF_SIZE            64              /* output buffer size */
108
109 #include <linux/version.h>
110
111 #ifndef KERNEL_VERSION
112 #define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
113 #endif
114
115 #ifndef LINUX_VERSION_CODE
116 #error "You need to use at least 2.0 Linux kernel."
117 #endif
118
119 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,0,0)
120 #error "You need to use at least 2.0 Linux kernel."
121 #endif
122
123 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
124 #define JS_HAS_RDTSC    (current_cpu_data.x86_capability & 0x10)
125 #include <linux/init.h>
126 #else
127 #ifdef MODULE
128 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,0,35)
129 #define JS_HAS_RDTSC    (x86_capability & 0x10)
130 #else
131 #define JS_HAS_RDTSC    0
132 #endif
133 #else
134 #define JS_HAS_RDTSC    (x86_capability & 0x10)
135 #endif
136 #define __initdata
137 #define __init
138 #define MODULE_AUTHOR(x)
139 #define MODULE_PARM(x,y)
140 #define MODULE_SUPPORTED_DEVICE(x)
141 #define signal_pending(x) (((x)->signal) & ~((x)->blocked))
142 #endif
143
144 /*
145  * Parport stuff
146  */
147
148 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
149 #define USE_PARPORT
150 #endif
151
152 #ifdef USE_PARPORT
153 #include <linux/parport.h>
154 #define JS_PAR_STATUS(y)        parport_read_status(y->port)
155 #define JS_PAR_DATA_IN(y)       parport_read_data(y->port)
156 #define JS_PAR_DATA_OUT(x,y)    parport_write_data(y->port, x)
157 #define JS_PAR_CTRL_OUT(x,y)    parport_write_control(y->port, x)
158 #else
159 #define JS_PAR_STATUS(y)        inb(y+1)
160 #define JS_PAR_DATA_IN(y)       inb(y)
161 #define JS_PAR_DATA_OUT(x,y)    outb(x,y)
162 #define JS_PAR_CTRL_OUT(x,y)    outb(x,y+2)
163 #endif
164
165 #define JS_PAR_STATUS_INVERT    (0x80)
166
167 /*
168  * Internal types
169  */
170
171 struct js_dev;
172
173 typedef int (*js_read_func)(void *info, int **axes, int **buttons);
174 typedef unsigned int (*js_time_func)(void);
175 typedef int (*js_delta_func)(unsigned int x, unsigned int y);
176 typedef int (*js_ops_func)(struct js_dev *dev);
177
178 struct js_data {
179         int *axes;
180         int *buttons;
181 };
182
183 struct js_dev {
184         struct js_dev *next;
185         struct js_list *list;
186         struct js_port *port;
187         struct wait_queue *wait;
188         struct js_data cur;
189         struct js_data new;
190         struct js_corr *corr;
191         struct js_event buff[JS_BUFF_SIZE];
192         js_ops_func open;
193         js_ops_func close;
194         int ahead;
195         int bhead;
196         int tail;
197         int num_axes;
198         int num_buttons;
199         char *name;
200 };
201
202 struct js_list {
203         struct js_list *next;
204         struct js_dev *dev;
205         int tail;
206         int startup;
207 };
208
209 struct js_port {
210         struct js_port *next;
211         struct js_port *prev;
212         js_read_func read;
213         struct js_dev **devs;
214         int **axes;
215         int **buttons;
216         struct js_corr **corr;
217         void *info;
218         int ndevs;
219 };
220
221 /*
222  * Sub-module interface
223  */
224
225 extern unsigned int js_time_speed;
226 extern js_time_func js_get_time;
227 extern js_delta_func js_delta;
228
229 extern unsigned int js_time_speed_a;
230 extern js_time_func js_get_time_a;
231 extern js_delta_func js_delta_a;
232
233 extern struct js_port *js_register_port(struct js_port *port, void *info,
234         int devs, int infos, js_read_func read);
235 extern struct js_port *js_unregister_port(struct js_port *port);
236
237 extern int js_register_device(struct js_port *port, int number, int axes,
238         int buttons, char *name, js_ops_func open, js_ops_func close);
239 extern void js_unregister_device(struct js_dev *dev);
240
241 /*
242  * Kernel interface
243  */
244
245 extern int js_init(void);
246 extern int js_am_init(void);
247 extern int js_an_init(void);
248 extern int js_as_init(void);
249 extern int js_console_init(void);
250 extern int js_db9_init(void);
251 extern int js_gr_init(void);
252 extern int js_l4_init(void);
253 extern int js_lt_init(void);
254 extern int js_sw_init(void);
255 extern int js_tm_init(void);
256
257 extern void js_am_setup(char *str, int *ints);
258 extern void js_an_setup(char *str, int *ints);
259 extern void js_as_setup(char *str, int *ints);
260 extern void js_console_setup(char *str, int *ints);
261 extern void js_db9_setup(char *str, int *ints);
262 extern void js_l4_setup(char *str, int *ints);
263
264 #endif /* __KERNEL__ */
265
266 #endif /* _LINUX_JOYSTICK_H */