source: svn/trunk/newcon3bcm2_21bu/toolchain/mips-linux-uclibc/include/linux/gameport.h

Last change on this file was 2, checked in by jglee, 11 years ago

first commit

  • Property svn:executable set to *
File size: 5.4 KB
Line 
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/device.h>
14
15struct gameport {
16
17        void *port_data;        /* Private pointer for gameport drivers */
18        char name[32];
19        char phys[32];
20
21        int io;
22        int speed;
23        int fuzz;
24
25        void (*trigger)(struct gameport *);
26        unsigned char (*read)(struct gameport *);
27        int (*cooked_read)(struct gameport *, int *, int *);
28        int (*calibrate)(struct gameport *, int *, int *);
29        int (*open)(struct gameport *, int);
30        void (*close)(struct gameport *);
31
32        struct timer_list poll_timer;
33        unsigned int poll_interval;     /* in msecs */
34        spinlock_t timer_lock;
35        unsigned int poll_cnt;
36        void (*poll_handler)(struct gameport *);
37
38        struct gameport *parent, *child;
39
40        struct gameport_driver *drv;
41        struct semaphore drv_sem;       /* protects serio->drv so attributes can pin driver */
42
43        struct device dev;
44        unsigned int registered;        /* port has been fully registered with driver core */
45
46        struct list_head node;
47};
48#define to_gameport_port(d)     container_of(d, struct gameport, dev)
49
50struct gameport_driver {
51
52        void *private;
53        char *description;
54
55        int (*connect)(struct gameport *, struct gameport_driver *drv);
56        int (*reconnect)(struct gameport *);
57        void (*disconnect)(struct gameport *);
58
59        struct device_driver driver;
60
61        unsigned int ignore;
62};
63#define to_gameport_driver(d)   container_of(d, struct gameport_driver, driver)
64
65int gameport_open(struct gameport *gameport, struct gameport_driver *drv, int mode);
66void gameport_close(struct gameport *gameport);
67void gameport_rescan(struct gameport *gameport);
68
69#if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
70
71void __gameport_register_port(struct gameport *gameport, struct module *owner);
72static inline void gameport_register_port(struct gameport *gameport)
73{
74        __gameport_register_port(gameport, THIS_MODULE);
75}
76
77void gameport_unregister_port(struct gameport *gameport);
78
79void gameport_set_phys(struct gameport *gameport, const char *fmt, ...)
80        __attribute__ ((format (printf, 2, 3)));
81
82#else
83
84static inline void gameport_register_port(struct gameport *gameport)
85{
86        return;
87}
88
89static inline void gameport_unregister_port(struct gameport *gameport)
90{
91        return;
92}
93
94static inline void gameport_set_phys(struct gameport *gameport,
95                                     const char *fmt, ...)
96{
97        return;
98}
99
100#endif
101
102static inline struct gameport *gameport_allocate_port(void)
103{
104        struct gameport *gameport = kcalloc(1, sizeof(struct gameport), GFP_KERNEL);
105
106        return gameport;
107}
108
109static inline void gameport_free_port(struct gameport *gameport)
110{
111        kfree(gameport);
112}
113
114static inline void gameport_set_name(struct gameport *gameport, const char *name)
115{
116        strlcpy(gameport->name, name, sizeof(gameport->name));
117}
118
119/*
120 * Use the following fucntions to manipulate gameport's per-port
121 * driver-specific data.
122 */
123static inline void *gameport_get_drvdata(struct gameport *gameport)
124{
125        return dev_get_drvdata(&gameport->dev);
126}
127
128static inline void gameport_set_drvdata(struct gameport *gameport, void *data)
129{
130        dev_set_drvdata(&gameport->dev, data);
131}
132
133/*
134 * Use the following fucntions to pin gameport's driver in process context
135 */
136static inline int gameport_pin_driver(struct gameport *gameport)
137{
138        return down_interruptible(&gameport->drv_sem);
139}
140
141static inline void gameport_unpin_driver(struct gameport *gameport)
142{
143        up(&gameport->drv_sem);
144}
145
146void __gameport_register_driver(struct gameport_driver *drv, struct module *owner);
147static inline void gameport_register_driver(struct gameport_driver *drv)
148{
149        __gameport_register_driver(drv, THIS_MODULE);
150}
151
152void gameport_unregister_driver(struct gameport_driver *drv);
153
154#define GAMEPORT_MODE_DISABLED          0
155#define GAMEPORT_MODE_RAW               1
156#define GAMEPORT_MODE_COOKED            2
157
158#define GAMEPORT_ID_VENDOR_ANALOG       0x0001
159#define GAMEPORT_ID_VENDOR_MADCATZ      0x0002
160#define GAMEPORT_ID_VENDOR_LOGITECH     0x0003
161#define GAMEPORT_ID_VENDOR_CREATIVE     0x0004
162#define GAMEPORT_ID_VENDOR_GENIUS       0x0005
163#define GAMEPORT_ID_VENDOR_INTERACT     0x0006
164#define GAMEPORT_ID_VENDOR_MICROSOFT    0x0007
165#define GAMEPORT_ID_VENDOR_THRUSTMASTER 0x0008
166#define GAMEPORT_ID_VENDOR_GRAVIS       0x0009
167#define GAMEPORT_ID_VENDOR_GUILLEMOT    0x000a
168
169static inline void gameport_trigger(struct gameport *gameport)
170{
171        if (gameport->trigger)
172                gameport->trigger(gameport);
173        else
174                outb(0xff, gameport->io);
175}
176
177static inline unsigned char gameport_read(struct gameport *gameport)
178{
179        if (gameport->read)
180                return gameport->read(gameport);
181        else
182                return inb(gameport->io);
183}
184
185static inline int gameport_cooked_read(struct gameport *gameport, int *axes, int *buttons)
186{
187        if (gameport->cooked_read)
188                return gameport->cooked_read(gameport, axes, buttons);
189        else
190                return -1;
191}
192
193static inline int gameport_calibrate(struct gameport *gameport, int *axes, int *max)
194{
195        if (gameport->calibrate)
196                return gameport->calibrate(gameport, axes, max);
197        else
198                return -1;
199}
200
201static inline int gameport_time(struct gameport *gameport, int time)
202{
203        return (time * gameport->speed) / 1000;
204}
205
206static inline void gameport_set_poll_handler(struct gameport *gameport, void (*handler)(struct gameport *))
207{
208        gameport->poll_handler = handler;
209}
210
211static inline void gameport_set_poll_interval(struct gameport *gameport, unsigned int msecs)
212{
213        gameport->poll_interval = msecs;
214}
215
216void gameport_start_polling(struct gameport *gameport);
217void gameport_stop_polling(struct gameport *gameport);
218
219#endif
Note: See TracBrowser for help on using the repository browser.