5 * Copyright (c) 1999-2002 Vojtech Pavlik
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.
14 #include <linux/types.h>
15 #include <linux/list.h>
16 #include <linux/mutex.h>
17 #include <linux/device.h>
18 #include <linux/timer.h>
19 #include <linux/slab.h>
23 void *port_data
; /* Private pointer for gameport drivers */
31 void (*trigger
)(struct gameport
*);
32 unsigned char (*read
)(struct gameport
*);
33 int (*cooked_read
)(struct gameport
*, int *, int *);
34 int (*calibrate
)(struct gameport
*, int *, int *);
35 int (*open
)(struct gameport
*, int);
36 void (*close
)(struct gameport
*);
38 struct timer_list poll_timer
;
39 unsigned int poll_interval
; /* in msecs */
40 spinlock_t timer_lock
;
41 unsigned int poll_cnt
;
42 void (*poll_handler
)(struct gameport
*);
44 struct gameport
*parent
, *child
;
46 struct gameport_driver
*drv
;
47 struct mutex drv_mutex
; /* protects serio->drv so attributes can pin driver */
51 struct list_head node
;
53 #define to_gameport_port(d) container_of(d, struct gameport, dev)
55 struct gameport_driver
{
60 int (*connect
)(struct gameport
*, struct gameport_driver
*drv
);
61 int (*reconnect
)(struct gameport
*);
62 void (*disconnect
)(struct gameport
*);
64 struct device_driver driver
;
68 #define to_gameport_driver(d) container_of(d, struct gameport_driver, driver)
70 int gameport_open(struct gameport
*gameport
, struct gameport_driver
*drv
, int mode
);
71 void gameport_close(struct gameport
*gameport
);
73 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
75 void __gameport_register_port(struct gameport
*gameport
, struct module
*owner
);
76 static inline void gameport_register_port(struct gameport
*gameport
)
78 __gameport_register_port(gameport
, THIS_MODULE
);
81 void gameport_unregister_port(struct gameport
*gameport
);
83 void gameport_set_phys(struct gameport
*gameport
, const char *fmt
, ...)
84 __attribute__ ((format (printf
, 2, 3)));
88 static inline void gameport_register_port(struct gameport
*gameport
)
93 static inline void gameport_unregister_port(struct gameport
*gameport
)
98 static inline void gameport_set_phys(struct gameport
*gameport
,
106 static inline struct gameport
*gameport_allocate_port(void)
108 struct gameport
*gameport
= kzalloc(sizeof(struct gameport
), GFP_KERNEL
);
113 static inline void gameport_free_port(struct gameport
*gameport
)
118 static inline void gameport_set_name(struct gameport
*gameport
, const char *name
)
120 strlcpy(gameport
->name
, name
, sizeof(gameport
->name
));
124 * Use the following functions to manipulate gameport's per-port
125 * driver-specific data.
127 static inline void *gameport_get_drvdata(struct gameport
*gameport
)
129 return dev_get_drvdata(&gameport
->dev
);
132 static inline void gameport_set_drvdata(struct gameport
*gameport
, void *data
)
134 dev_set_drvdata(&gameport
->dev
, data
);
138 * Use the following functions to pin gameport's driver in process context
140 static inline int gameport_pin_driver(struct gameport
*gameport
)
142 return mutex_lock_interruptible(&gameport
->drv_mutex
);
145 static inline void gameport_unpin_driver(struct gameport
*gameport
)
147 mutex_unlock(&gameport
->drv_mutex
);
150 int __gameport_register_driver(struct gameport_driver
*drv
,
151 struct module
*owner
, const char *mod_name
);
152 static inline int __must_check
gameport_register_driver(struct gameport_driver
*drv
)
154 return __gameport_register_driver(drv
, THIS_MODULE
, KBUILD_MODNAME
);
157 void gameport_unregister_driver(struct gameport_driver
*drv
);
159 #endif /* __KERNEL__ */
161 #define GAMEPORT_MODE_DISABLED 0
162 #define GAMEPORT_MODE_RAW 1
163 #define GAMEPORT_MODE_COOKED 2
165 #define GAMEPORT_ID_VENDOR_ANALOG 0x0001
166 #define GAMEPORT_ID_VENDOR_MADCATZ 0x0002
167 #define GAMEPORT_ID_VENDOR_LOGITECH 0x0003
168 #define GAMEPORT_ID_VENDOR_CREATIVE 0x0004
169 #define GAMEPORT_ID_VENDOR_GENIUS 0x0005
170 #define GAMEPORT_ID_VENDOR_INTERACT 0x0006
171 #define GAMEPORT_ID_VENDOR_MICROSOFT 0x0007
172 #define GAMEPORT_ID_VENDOR_THRUSTMASTER 0x0008
173 #define GAMEPORT_ID_VENDOR_GRAVIS 0x0009
174 #define GAMEPORT_ID_VENDOR_GUILLEMOT 0x000a
178 static inline void gameport_trigger(struct gameport
*gameport
)
180 if (gameport
->trigger
)
181 gameport
->trigger(gameport
);
183 outb(0xff, gameport
->io
);
186 static inline unsigned char gameport_read(struct gameport
*gameport
)
189 return gameport
->read(gameport
);
191 return inb(gameport
->io
);
194 static inline int gameport_cooked_read(struct gameport
*gameport
, int *axes
, int *buttons
)
196 if (gameport
->cooked_read
)
197 return gameport
->cooked_read(gameport
, axes
, buttons
);
202 static inline int gameport_calibrate(struct gameport
*gameport
, int *axes
, int *max
)
204 if (gameport
->calibrate
)
205 return gameport
->calibrate(gameport
, axes
, max
);
210 static inline int gameport_time(struct gameport
*gameport
, int time
)
212 return (time
* gameport
->speed
) / 1000;
215 static inline void gameport_set_poll_handler(struct gameport
*gameport
, void (*handler
)(struct gameport
*))
217 gameport
->poll_handler
= handler
;
220 static inline void gameport_set_poll_interval(struct gameport
*gameport
, unsigned int msecs
)
222 gameport
->poll_interval
= msecs
;
225 void gameport_start_polling(struct gameport
*gameport
);
226 void gameport_stop_polling(struct gameport
*gameport
);
228 #endif /* __KERNEL__ */
This page took 0.035676 seconds and 5 git commands to generate.