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.
13 #include <linux/list.h>
14 #include <linux/device.h>
18 void *port_data
; /* Private pointer for gameport drivers */
26 void (*trigger
)(struct gameport
*);
27 unsigned char (*read
)(struct gameport
*);
28 int (*cooked_read
)(struct gameport
*, int *, int *);
29 int (*calibrate
)(struct gameport
*, int *, int *);
30 int (*open
)(struct gameport
*, int);
31 void (*close
)(struct gameport
*);
33 struct timer_list poll_timer
;
34 unsigned int poll_interval
; /* in msecs */
35 spinlock_t timer_lock
;
36 unsigned int poll_cnt
;
37 void (*poll_handler
)(struct gameport
*);
39 struct gameport
*parent
, *child
;
41 struct gameport_driver
*drv
;
42 struct semaphore drv_sem
; /* protects serio->drv so attributes can pin driver */
45 unsigned int registered
; /* port has been fully registered with driver core */
47 struct list_head node
;
49 #define to_gameport_port(d) container_of(d, struct gameport, dev)
51 struct gameport_driver
{
56 int (*connect
)(struct gameport
*, struct gameport_driver
*drv
);
57 int (*reconnect
)(struct gameport
*);
58 void (*disconnect
)(struct gameport
*);
60 struct device_driver driver
;
64 #define to_gameport_driver(d) container_of(d, struct gameport_driver, driver)
66 int gameport_open(struct gameport
*gameport
, struct gameport_driver
*drv
, int mode
);
67 void gameport_close(struct gameport
*gameport
);
68 void gameport_rescan(struct gameport
*gameport
);
70 #if defined(CONFIG_GAMEPORT) || (defined(MODULE) && defined(CONFIG_GAMEPORT_MODULE))
72 void __gameport_register_port(struct gameport
*gameport
, struct module
*owner
);
73 static inline void gameport_register_port(struct gameport
*gameport
)
75 __gameport_register_port(gameport
, THIS_MODULE
);
78 void gameport_unregister_port(struct gameport
*gameport
);
80 void gameport_set_phys(struct gameport
*gameport
, const char *fmt
, ...)
81 __attribute__ ((format (printf
, 2, 3)));
85 static inline void gameport_register_port(struct gameport
*gameport
)
90 static inline void gameport_unregister_port(struct gameport
*gameport
)
95 static inline void gameport_set_phys(struct gameport
*gameport
,
103 static inline struct gameport
*gameport_allocate_port(void)
105 struct gameport
*gameport
= kcalloc(1, sizeof(struct gameport
), GFP_KERNEL
);
110 static inline void gameport_free_port(struct gameport
*gameport
)
115 static inline void gameport_set_name(struct gameport
*gameport
, const char *name
)
117 strlcpy(gameport
->name
, name
, sizeof(gameport
->name
));
121 * Use the following fucntions to manipulate gameport's per-port
122 * driver-specific data.
124 static inline void *gameport_get_drvdata(struct gameport
*gameport
)
126 return dev_get_drvdata(&gameport
->dev
);
129 static inline void gameport_set_drvdata(struct gameport
*gameport
, void *data
)
131 dev_set_drvdata(&gameport
->dev
, data
);
135 * Use the following fucntions to pin gameport's driver in process context
137 static inline int gameport_pin_driver(struct gameport
*gameport
)
139 return down_interruptible(&gameport
->drv_sem
);
142 static inline void gameport_unpin_driver(struct gameport
*gameport
)
144 up(&gameport
->drv_sem
);
147 void __gameport_register_driver(struct gameport_driver
*drv
, struct module
*owner
);
148 static inline void gameport_register_driver(struct gameport_driver
*drv
)
150 __gameport_register_driver(drv
, THIS_MODULE
);
153 void gameport_unregister_driver(struct gameport_driver
*drv
);
155 #define GAMEPORT_MODE_DISABLED 0
156 #define GAMEPORT_MODE_RAW 1
157 #define GAMEPORT_MODE_COOKED 2
159 #define GAMEPORT_ID_VENDOR_ANALOG 0x0001
160 #define GAMEPORT_ID_VENDOR_MADCATZ 0x0002
161 #define GAMEPORT_ID_VENDOR_LOGITECH 0x0003
162 #define GAMEPORT_ID_VENDOR_CREATIVE 0x0004
163 #define GAMEPORT_ID_VENDOR_GENIUS 0x0005
164 #define GAMEPORT_ID_VENDOR_INTERACT 0x0006
165 #define GAMEPORT_ID_VENDOR_MICROSOFT 0x0007
166 #define GAMEPORT_ID_VENDOR_THRUSTMASTER 0x0008
167 #define GAMEPORT_ID_VENDOR_GRAVIS 0x0009
168 #define GAMEPORT_ID_VENDOR_GUILLEMOT 0x000a
170 static inline void gameport_trigger(struct gameport
*gameport
)
172 if (gameport
->trigger
)
173 gameport
->trigger(gameport
);
175 outb(0xff, gameport
->io
);
178 static inline unsigned char gameport_read(struct gameport
*gameport
)
181 return gameport
->read(gameport
);
183 return inb(gameport
->io
);
186 static inline int gameport_cooked_read(struct gameport
*gameport
, int *axes
, int *buttons
)
188 if (gameport
->cooked_read
)
189 return gameport
->cooked_read(gameport
, axes
, buttons
);
194 static inline int gameport_calibrate(struct gameport
*gameport
, int *axes
, int *max
)
196 if (gameport
->calibrate
)
197 return gameport
->calibrate(gameport
, axes
, max
);
202 static inline int gameport_time(struct gameport
*gameport
, int time
)
204 return (time
* gameport
->speed
) / 1000;
207 static inline void gameport_set_poll_handler(struct gameport
*gameport
, void (*handler
)(struct gameport
*))
209 gameport
->poll_handler
= handler
;
212 static inline void gameport_set_poll_interval(struct gameport
*gameport
, unsigned int msecs
)
214 gameport
->poll_interval
= msecs
;
217 void gameport_start_polling(struct gameport
*gameport
);
218 void gameport_stop_polling(struct gameport
*gameport
);