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 	void *driver;
42 
43 	int number;
44 
45 	int io;
46 	int speed;
47 	int fuzz;
48 
49 	void (*trigger)(struct gameport *);
50 	unsigned char (*read)(struct gameport *);
51 	int (*cooked_read)(struct gameport *, int *, int *);
52 	int (*calibrate)(struct gameport *, int *, int *);
53 	int (*open)(struct gameport *, int);
54 	void (*close)(struct gameport *);
55 
56 	struct gameport_dev *dev;
57 	struct gameport *next;
58 };
59 
60 struct gameport_dev {
61 
62 	void *private;
63 
64 	void (*connect)(struct gameport *, struct gameport_dev *dev);
65 	void (*disconnect)(struct gameport *);
66 
67 	struct gameport_dev *next;
68 };
69 
70 int gameport_open(struct gameport *gameport, struct gameport_dev *dev, int mode);
71 void gameport_close(struct gameport *gameport);
72 void gameport_rescan(struct gameport *gameport);
73 
74 #if defined(CONFIG_INPUT_GAMEPORT) || defined(CONFIG_INPUT_GAMEPORT_MODULE)
75 void gameport_register_port(struct gameport *gameport);
76 void gameport_unregister_port(struct gameport *gameport);
77 #else
gameport_register_port(struct gameport * gameport)78 static void __inline__ gameport_register_port(struct gameport *gameport) { return; }
gameport_unregister_port(struct gameport * gameport)79 static void __inline__ gameport_unregister_port(struct gameport *gameport) { return; }
80 #endif
81 
82 void gameport_register_device(struct gameport_dev *dev);
83 void gameport_unregister_device(struct gameport_dev *dev);
84 
85 #define GAMEPORT_MODE_DISABLED		0
86 #define GAMEPORT_MODE_RAW		1
87 #define GAMEPORT_MODE_COOKED		2
88 
89 #define GAMEPORT_ID_VENDOR_ANALOG	0x0001
90 #define GAMEPORT_ID_VENDOR_MADCATZ	0x0002
91 #define GAMEPORT_ID_VENDOR_LOGITECH	0x0003
92 #define GAMEPORT_ID_VENDOR_CREATIVE	0x0004
93 #define GAMEPORT_ID_VENDOR_GENIUS	0x0005
94 #define GAMEPORT_ID_VENDOR_INTERACT	0x0006
95 #define GAMEPORT_ID_VENDOR_MICROSOFT	0x0007
96 #define GAMEPORT_ID_VENDOR_THRUSTMASTER	0x0008
97 #define GAMEPORT_ID_VENDOR_GRAVIS	0x0009
98 
gameport_trigger(struct gameport * gameport)99 static __inline__ void gameport_trigger(struct gameport *gameport)
100 {
101 	if (gameport->trigger)
102 		gameport->trigger(gameport);
103 	else
104 		outb(0xff, gameport->io);
105 }
106 
gameport_read(struct gameport * gameport)107 static __inline__ unsigned char gameport_read(struct gameport *gameport)
108 {
109 	if (gameport->read)
110 		return gameport->read(gameport);
111 	else
112 		return inb(gameport->io);
113 }
114 
gameport_cooked_read(struct gameport * gameport,int * axes,int * buttons)115 static __inline__ int gameport_cooked_read(struct gameport *gameport, int *axes, int *buttons)
116 {
117 	if (gameport->cooked_read)
118 		return gameport->cooked_read(gameport, axes, buttons);
119 	else
120 		return -1;
121 }
122 
gameport_calibrate(struct gameport * gameport,int * axes,int * max)123 static __inline__ int gameport_calibrate(struct gameport *gameport, int *axes, int *max)
124 {
125 	if (gameport->calibrate)
126 		return gameport->calibrate(gameport, axes, max);
127 	else
128 		return -1;
129 }
130 
gameport_time(struct gameport * gameport,int time)131 static __inline__ int gameport_time(struct gameport *gameport, int time)
132 {
133 	return (time * gameport->speed) / 1000;
134 }
135 
wait_ms(unsigned int ms)136 static __inline__ void wait_ms(unsigned int ms)
137 {
138 	current->state = TASK_UNINTERRUPTIBLE;
139 	schedule_timeout(1 + ms * HZ / 1000);
140 }
141 
142 #endif
143