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/list.h>
15 #include <linux/mutex.h>
16 #include <linux/device.h>
17 #include <linux/timer.h>
21 void *port_data
; /* Private pointer for gameport drivers */
29 void (*trigger
)(struct gameport
*);
30 unsigned char (*read
)(struct gameport
*);
31 int (*cooked_read
)(struct gameport
*, int *, int *);
32 int (*calibrate
)(struct gameport
*, int *, int *);
33 int (*open
)(struct gameport
*, int);
34 void (*close
)(struct gameport
*);
36 struct timer_list poll_timer
;
37 unsigned int poll_interval
; /* in msecs */
38 spinlock_t timer_lock
;
39 unsigned int poll_cnt
;
40 void (*poll_handler
)(struct gameport
*);
42 struct gameport
*parent
, *child
;
44 struct gameport_driver
*drv
;
45 struct mutex drv_mutex
; /* protects serio->drv so attributes can pin driver */
48 unsigned int registered
; /* port has been fully registered with driver core */
50 struct list_head node
;
52 #define to_gameport_port(d) container_of(d, struct gameport, dev)
54 struct gameport_driver
{
59 int (*connect
)(struct gameport
*, struct gameport_driver
*drv
);
60 int (*reconnect
)(struct gameport
*);
61 void (*disconnect
)(struct gameport
*);
63 struct device_driver driver
;
67 #define to_gameport_driver(d) container_of(d, struct gameport_driver, driver)
69 int gameport_open(struct gameport
*gameport
, struct gameport_driver
*drv
, int mode
);
70 void gameport_close(struct gameport
*gameport
);
72 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
74 void __gameport_register_port(struct gameport
*gameport
, struct module
*owner
);
75 static inline void gameport_register_port(struct gameport
*gameport
)
77 __gameport_register_port(gameport
, THIS_MODULE
);
80 void gameport_unregister_port(struct gameport
*gameport
);
82 void gameport_set_phys(struct gameport
*gameport
, const char *fmt
, ...)
83 __attribute__ ((format (printf
, 2, 3)));
87 static inline void gameport_register_port(struct gameport
*gameport
)
92 static inline void gameport_unregister_port(struct gameport
*gameport
)
97 static inline void gameport_set_phys(struct gameport
*gameport
,
105 static inline struct gameport
*gameport_allocate_port(void)
107 struct gameport
*gameport
= kzalloc(sizeof(struct gameport
), GFP_KERNEL
);
112 static inline void gameport_free_port(struct gameport
*gameport
)
117 static inline void gameport_set_name(struct gameport
*gameport
, const char *name
)
119 strlcpy(gameport
->name
, name
, sizeof(gameport
->name
));
123 * Use the following functions to manipulate gameport's per-port
124 * driver-specific data.
126 static inline void *gameport_get_drvdata(struct gameport
*gameport
)
128 return dev_get_drvdata(&gameport
->dev
);
131 static inline void gameport_set_drvdata(struct gameport
*gameport
, void *data
)
133 dev_set_drvdata(&gameport
->dev
, data
);
137 * Use the following functions to pin gameport's driver in process context
139 static inline int gameport_pin_driver(struct gameport
*gameport
)
141 return mutex_lock_interruptible(&gameport
->drv_mutex
);
144 static inline void gameport_unpin_driver(struct gameport
*gameport
)
146 mutex_unlock(&gameport
->drv_mutex
);
149 void __gameport_register_driver(struct gameport_driver
*drv
, struct module
*owner
);
150 static inline void gameport_register_driver(struct gameport_driver
*drv
)
152 __gameport_register_driver(drv
, THIS_MODULE
);
155 void gameport_unregister_driver(struct gameport_driver
*drv
);
157 #endif /* __KERNEL__ */
159 #define GAMEPORT_MODE_DISABLED 0
160 #define GAMEPORT_MODE_RAW 1
161 #define GAMEPORT_MODE_COOKED 2
163 #define GAMEPORT_ID_VENDOR_ANALOG 0x0001
164 #define GAMEPORT_ID_VENDOR_MADCATZ 0x0002
165 #define GAMEPORT_ID_VENDOR_LOGITECH 0x0003
166 #define GAMEPORT_ID_VENDOR_CREATIVE 0x0004
167 #define GAMEPORT_ID_VENDOR_GENIUS 0x0005
168 #define GAMEPORT_ID_VENDOR_INTERACT 0x0006
169 #define GAMEPORT_ID_VENDOR_MICROSOFT 0x0007
170 #define GAMEPORT_ID_VENDOR_THRUSTMASTER 0x0008
171 #define GAMEPORT_ID_VENDOR_GRAVIS 0x0009
172 #define GAMEPORT_ID_VENDOR_GUILLEMOT 0x000a
176 static inline void gameport_trigger(struct gameport
*gameport
)
178 if (gameport
->trigger
)
179 gameport
->trigger(gameport
);
181 outb(0xff, gameport
->io
);
184 static inline unsigned char gameport_read(struct gameport
*gameport
)
187 return gameport
->read(gameport
);
189 return inb(gameport
->io
);
192 static inline int gameport_cooked_read(struct gameport
*gameport
, int *axes
, int *buttons
)
194 if (gameport
->cooked_read
)
195 return gameport
->cooked_read(gameport
, axes
, buttons
);
200 static inline int gameport_calibrate(struct gameport
*gameport
, int *axes
, int *max
)
202 if (gameport
->calibrate
)
203 return gameport
->calibrate(gameport
, axes
, max
);
208 static inline int gameport_time(struct gameport
*gameport
, int time
)
210 return (time
* gameport
->speed
) / 1000;
213 static inline void gameport_set_poll_handler(struct gameport
*gameport
, void (*handler
)(struct gameport
*))
215 gameport
->poll_handler
= handler
;
218 static inline void gameport_set_poll_interval(struct gameport
*gameport
, unsigned int msecs
)
220 gameport
->poll_interval
= msecs
;
223 void gameport_start_polling(struct gameport
*gameport
);
224 void gameport_stop_polling(struct gameport
*gameport
);
226 #endif /* __KERNEL__ */