File: /usr/src/linux/include/linux/gameport.h
1 #ifndef _GAMEPORT_H
2 #define _GAMEPORT_H
3
4 /*
5 * $Id: gameport.h,v 1.11 2001/04/26 10:24:46 vojtech Exp $
6 *
7 * Copyright (c) 1999-2000 Vojtech Pavlik
8 *
9 * Sponsored by SuSE
10 */
11
12 /*
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
17 *
18 * This program is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU General Public License for more details.
22 *
23 * You should have received a copy of the GNU General Public License
24 * along with this program; if not, write to the Free Software
25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 *
27 * Should you need to contact me, the author, you can do so either by
28 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
29 * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic
30 */
31
32 #include <linux/sched.h>
33 #include <linux/delay.h>
34 #include <asm/io.h>
35
36 struct gameport;
37
38 struct gameport {
39
40 void *private;
41
42 int number;
43
44 int io;
45 int speed;
46 int fuzz;
47
48 void (*trigger)(struct gameport *);
49 unsigned char (*read)(struct gameport *);
50 int (*cooked_read)(struct gameport *, int *, int *);
51 int (*calibrate)(struct gameport *, int *, int *);
52 int (*open)(struct gameport *, int);
53 void (*close)(struct gameport *);
54
55 struct gameport_dev *dev;
56 struct gameport *next;
57 };
58
59 struct gameport_dev {
60
61 void *private;
62
63 void (*connect)(struct gameport *, struct gameport_dev *dev);
64 void (*disconnect)(struct gameport *);
65
66 struct gameport_dev *next;
67 };
68
69 int gameport_open(struct gameport *gameport, struct gameport_dev *dev, int mode);
70 void gameport_close(struct gameport *gameport);
71 void gameport_rescan(struct gameport *gameport);
72
73 #if defined(CONFIG_INPUT_GAMEPORT) || defined(CONFIG_INPUT_GAMEPORT_MODULE)
74 void gameport_register_port(struct gameport *gameport);
75 void gameport_unregister_port(struct gameport *gameport);
76 #else
77 void __inline__ gameport_register_port(struct gameport *gameport) { return; }
78 void __inline__ gameport_unregister_port(struct gameport *gameport) { return; }
79 #endif
80
81 void gameport_register_device(struct gameport_dev *dev);
82 void gameport_unregister_device(struct gameport_dev *dev);
83
84 #define GAMEPORT_MODE_DISABLED 0
85 #define GAMEPORT_MODE_RAW 1
86 #define GAMEPORT_MODE_COOKED 2
87
88 #define GAMEPORT_ID_VENDOR_ANALOG 0x0001
89 #define GAMEPORT_ID_VENDOR_MADCATZ 0x0002
90 #define GAMEPORT_ID_VENDOR_LOGITECH 0x0003
91 #define GAMEPORT_ID_VENDOR_CREATIVE 0x0004
92 #define GAMEPORT_ID_VENDOR_GENIUS 0x0005
93 #define GAMEPORT_ID_VENDOR_INTERACT 0x0006
94 #define GAMEPORT_ID_VENDOR_MICROSOFT 0x0007
95 #define GAMEPORT_ID_VENDOR_THRUSTMASTER 0x0008
96 #define GAMEPORT_ID_VENDOR_GRAVIS 0x0009
97
98 static __inline__ void gameport_trigger(struct gameport *gameport)
99 {
100 if (gameport->trigger)
101 gameport->trigger(gameport);
102 else
103 outb(0xff, gameport->io);
104 }
105
106 static __inline__ unsigned char gameport_read(struct gameport *gameport)
107 {
108 if (gameport->read)
109 return gameport->read(gameport);
110 else
111 return inb(gameport->io);
112 }
113
114 static __inline__ int gameport_cooked_read(struct gameport *gameport, int *axes, int *buttons)
115 {
116 if (gameport->cooked_read)
117 return gameport->cooked_read(gameport, axes, buttons);
118 else
119 return -1;
120 }
121
122 static __inline__ int gameport_calibrate(struct gameport *gameport, int *axes, int *max)
123 {
124 if (gameport->calibrate)
125 return gameport->calibrate(gameport, axes, max);
126 else
127 return -1;
128 }
129
130 static __inline__ int gameport_time(struct gameport *gameport, int time)
131 {
132 return (time * gameport->speed) / 1000;
133 }
134
135 static __inline__ void wait_ms(unsigned int ms)
136 {
137 current->state = TASK_UNINTERRUPTIBLE;
138 schedule_timeout(1 + ms * HZ / 1000);
139 }
140
141 #endif
142