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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
|
#ifndef _LINUX_JOYSTICK_H
#define _LINUX_JOYSTICK_H
/*
* /usr/include/linux/joystick.h Version 1.2
*
* Copyright (C) 1996-1998 Vojtech Pavlik
*/
/*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Should you need to contact me, the author, you can do so either by
* e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
* Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic
*/
#include <asm/types.h>
#include <linux/module.h>
/*
* Version
*/
#define JS_VERSION 0x01020d
/*
* Types and constants for reading from /dev/js
*/
#define JS_EVENT_BUTTON 0x01 /* button pressed/released */
#define JS_EVENT_AXIS 0x02 /* joystick moved */
#define JS_EVENT_INIT 0x80 /* initial state of device */
struct js_event {
__u32 time; /* event timestamp in miliseconds */
__s16 value; /* value */
__u8 type; /* event type */
__u8 number; /* axis/button number */
};
/*
* IOCTL commands for joystick driver
*/
#define JSIOCGVERSION _IOR('j', 0x01, __u32) /* get driver version */
#define JSIOCGAXES _IOR('j', 0x11, __u8) /* get number of axes */
#define JSIOCGBUTTONS _IOR('j', 0x12, __u8) /* get number of buttons */
#define JSIOCGNAME(len) _IOC(_IOC_READ, 'j', 0x13, len) /* get identifier string */
#define JSIOCSCORR _IOW('j', 0x21, struct js_corr) /* set correction values */
#define JSIOCGCORR _IOR('j', 0x22, struct js_corr) /* get correction values */
/*
* Types and constants for get/set correction
*/
#define JS_CORR_NONE 0x00 /* returns raw values */
#define JS_CORR_BROKEN 0x01 /* broken line */
struct js_corr {
__s32 coef[8];
__s16 prec;
__u16 type;
};
/*
* v0.x compatibility definitions
*/
#define JS_RETURN sizeof(struct JS_DATA_TYPE)
#define JS_TRUE 1
#define JS_FALSE 0
#define JS_X_0 0x01
#define JS_Y_0 0x02
#define JS_X_1 0x04
#define JS_Y_1 0x08
#define JS_MAX 2
#define JS_DEF_TIMEOUT 0x1300
#define JS_DEF_CORR 0
#define JS_DEF_TIMELIMIT 10L
#define JS_SET_CAL 1
#define JS_GET_CAL 2
#define JS_SET_TIMEOUT 3
#define JS_GET_TIMEOUT 4
#define JS_SET_TIMELIMIT 5
#define JS_GET_TIMELIMIT 6
#define JS_GET_ALL 7
#define JS_SET_ALL 8
struct JS_DATA_TYPE {
int buttons;
int x;
int y;
};
struct JS_DATA_SAVE_TYPE {
int JS_TIMEOUT;
int BUSY;
long JS_EXPIRETIME;
long JS_TIMELIMIT;
struct JS_DATA_TYPE JS_SAVE;
struct JS_DATA_TYPE JS_CORR;
};
/*
* Internal definitions
*/
#ifdef __KERNEL__
#define JS_BUFF_SIZE 64 /* output buffer size */
#include <linux/version.h>
#ifndef KERNEL_VERSION
#define KERNEL_VERSION(a,b,c) (((a) << 16) + ((b) << 8) + (c))
#endif
#ifndef LINUX_VERSION_CODE
#error "You need to use at least 2.0 Linux kernel."
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,0,0)
#error "You need to use at least 2.0 Linux kernel."
#endif
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
#define JS_HAS_RDTSC (current_cpu_data.x86_capability & 0x10)
#include <linux/init.h>
#else
#ifdef MODULE
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,0,35)
#define JS_HAS_RDTSC (x86_capability & 0x10)
#else
#define JS_HAS_RDTSC 0
#endif
#else
#define JS_HAS_RDTSC (x86_capability & 0x10)
#endif
#define __initdata
#define __init
#define __cli cli
#define __save_flags(flags) save_flags(flags)
#define __restore_flags(flags) restore_flags(flags)
#define spin_lock_irqsave(x, flags) do { save_flags(flags); cli(); } while (0)
#define spin_unlock_irqrestore(x, flags) restore_flags(flags)
#define spin_lock_init(x) do { } while (0)
typedef struct { int something; } spinlock_t;
#define SPIN_LOCK_UNLOCKED { 0 }
#define MODULE_AUTHOR(x)
#define MODULE_PARM(x,y)
#define MODULE_SUPPORTED_DEVICE(x)
#define signal_pending(x) (((x)->signal) & ~((x)->blocked))
#endif
/*
* Parport stuff
*/
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,1,0)
#define USE_PARPORT
#endif
#ifdef USE_PARPORT
#include <linux/parport.h>
#define JS_PAR_DATA_IN(y) parport_read_data(y->port)
#define JS_PAR_DATA_OUT(x,y) parport_write_data(y->port, x)
#define JS_PAR_STATUS(y) parport_read_status(y->port)
#define JS_PAR_CTRL_IN(y) parport_read_control(y->port)
#define JS_PAR_CTRL_OUT(x,y) parport_write_control(y->port, x)
#define JS_PAR_ECTRL_OUT(x,y) parport_write_econtrol(y->port, x)
#else
#define JS_PAR_DATA_IN(y) inb(y)
#define JS_PAR_DATA_OUT(x,y) outb(x,y)
#define JS_PAR_STATUS(y) inb(y+1)
#define JS_PAR_CTRL_IN(y) inb(y+2)
#define JS_PAR_CTRL_OUT(x,y) outb(x,y+2)
#define JS_PAR_ECTRL_OUT(x,y) outb(x,y+0x402)
#endif
#define JS_PAR_STATUS_INVERT (0x80)
#define JS_PAR_CTRL_INVERT (0x04)
/*
* Internal types
*/
struct js_dev;
typedef int (*js_read_func)(void *info, int **axes, int **buttons);
typedef unsigned int (*js_time_func)(void);
typedef int (*js_delta_func)(unsigned int x, unsigned int y);
typedef int (*js_ops_func)(struct js_dev *dev);
struct js_data {
int *axes;
int *buttons;
};
struct js_dev {
struct js_dev *next;
struct js_list *list;
struct js_port *port;
struct wait_queue *wait;
struct js_data cur;
struct js_data new;
struct js_corr *corr;
struct js_event buff[JS_BUFF_SIZE];
js_ops_func open;
js_ops_func close;
int ahead;
int bhead;
int tail;
int num_axes;
int num_buttons;
char *name;
};
struct js_list {
struct js_list *next;
struct js_dev *dev;
int tail;
int startup;
};
struct js_port {
struct js_port *next;
struct js_port *prev;
js_read_func read;
struct js_dev **devs;
int **axes;
int **buttons;
struct js_corr **corr;
void *info;
int ndevs;
};
/*
* Sub-module interface
*/
extern unsigned int js_time_speed;
extern js_time_func js_get_time;
extern js_delta_func js_delta;
extern unsigned int js_time_speed_a;
extern js_time_func js_get_time_a;
extern js_delta_func js_delta_a;
extern struct js_port *js_register_port(struct js_port *port, void *info,
int devs, int infos, js_read_func read);
extern struct js_port *js_unregister_port(struct js_port *port);
extern int js_register_device(struct js_port *port, int number, int axes,
int buttons, char *name, js_ops_func open, js_ops_func close);
extern void js_unregister_device(struct js_dev *dev);
/*
* Kernel interface
*/
extern int js_init(void);
extern int js_am_init(void);
extern int js_an_init(void);
extern int js_as_init(void);
extern int js_console_init(void);
extern int js_db9_init(void);
extern int js_gr_init(void);
extern int js_l4_init(void);
extern int js_lt_init(void);
extern int js_sw_init(void);
extern int js_tm_init(void);
extern void js_am_setup(char *str, int *ints);
extern void js_an_setup(char *str, int *ints);
extern void js_as_setup(char *str, int *ints);
extern void js_console_setup(char *str, int *ints);
extern void js_db9_setup(char *str, int *ints);
extern void js_l4_setup(char *str, int *ints);
#endif /* __KERNEL__ */
#endif /* _LINUX_JOYSTICK_H */
|