32 #include <linux/kernel.h>
33 #include <linux/parport.h>
34 #include <linux/input.h>
35 #include <linux/module.h>
38 #include <linux/slab.h>
44 #define TGFX_MAX_PORTS 3
45 #define TGFX_MAX_DEVICES 7
61 #define TGFX_REFRESH_TIME HZ/100
63 #define TGFX_TRIGGER 0x08
65 #define TGFX_DOWN 0x20
66 #define TGFX_LEFT 0x40
67 #define TGFX_RIGHT 0x80
69 #define TGFX_THUMB 0x02
70 #define TGFX_THUMB2 0x04
72 #define TGFX_TOP2 0x08
91 static void tgfx_timer(
unsigned long private)
93 struct tgfx *tgfx = (
void *)
private;
94 struct input_dev *
dev;
97 for (i = 0; i < 7; i++)
98 if (tgfx->sticks & (1 << i)) {
121 static int tgfx_open(
struct input_dev *dev)
123 struct tgfx *tgfx = input_get_drvdata(dev);
140 static void tgfx_close(
struct input_dev *dev)
142 struct tgfx *tgfx = input_get_drvdata(dev);
159 static struct tgfx
__init *tgfx_probe(
int parport,
int *n_buttons,
int n_devs)
162 struct input_dev *input_dev;
177 printk(
KERN_ERR "turbografx.c: parport busy already - lp.o loaded?\n");
182 tgfx = kzalloc(
sizeof(
struct tgfx),
GFP_KERNEL);
186 goto err_unreg_pardev;
192 tgfx->timer.data = (
long) tgfx;
193 tgfx->timer.function = tgfx_timer;
195 for (i = 0; i < n_devs; i++) {
196 if (n_buttons[i] < 1)
199 if (n_buttons[i] > 6) {
200 printk(
KERN_ERR "turbografx.c: Invalid number of buttons %d\n", n_buttons[i]);
205 tgfx->dev[
i] = input_dev = input_allocate_device();
207 printk(
KERN_ERR "turbografx.c: Not enough memory for input device\n");
212 tgfx->sticks |= (1 <<
i);
213 snprintf(tgfx->name[i],
sizeof(tgfx->name[i]),
214 "TurboGraFX %d-button Multisystem joystick", n_buttons[i]);
215 snprintf(tgfx->phys[i],
sizeof(tgfx->phys[i]),
216 "%s/input%d", tgfx->pd->port->name, i);
218 input_dev->name = tgfx->name[
i];
219 input_dev->phys = tgfx->phys[
i];
221 input_dev->id.vendor = 0x0003;
222 input_dev->id.product = n_buttons[
i];
223 input_dev->id.version = 0x0100;
225 input_set_drvdata(input_dev, tgfx);
227 input_dev->open = tgfx_open;
228 input_dev->close = tgfx_close;
231 input_set_abs_params(input_dev,
ABS_X, -1, 1, 0, 0);
232 input_set_abs_params(input_dev,
ABS_Y, -1, 1, 0, 0);
234 for (j = 0; j < n_buttons[
i]; j++)
235 set_bit(tgfx_buttons[j], input_dev->keybit);
237 err = input_register_device(tgfx->dev[i]);
252 input_free_device(tgfx->dev[i]);
256 input_unregister_device(tgfx->dev[i]);
267 static void tgfx_remove(
struct tgfx *tgfx)
273 input_unregister_device(tgfx->dev[i]);
278 static int __init tgfx_init(
void)
285 if (tgfx_cfg[i].nargs == 0 || tgfx_cfg[i].args[0] < 0)
288 if (tgfx_cfg[i].nargs < 2) {
289 printk(
KERN_ERR "turbografx.c: at least one joystick must be specified\n");
294 tgfx_base[
i] = tgfx_probe(tgfx_cfg[i].args[0],
295 tgfx_cfg[i].args + 1,
296 tgfx_cfg[i].nargs - 1);
297 if (IS_ERR(tgfx_base[i])) {
298 err = PTR_ERR(tgfx_base[i]);
308 tgfx_remove(tgfx_base[i]);
312 return have_dev ? 0 : -
ENODEV;
315 static void __exit tgfx_exit(
void)
321 tgfx_remove(tgfx_base[i]);