2 * $Id: turbografx.c,v 1.1.1.1 2005/04/11 02:50:21 jack Exp $
4 * Copyright (c) 1998-2000 Vojtech Pavlik
6 * Based on the work of:
13 * TurboGraFX parallel port interface driver for Linux.
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2 of the License, or
20 * (at your option) any later version.
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
27 * You should have received a copy of the GNU General Public License
28 * along with this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 * Should you need to contact me, the author, you can do so either by
32 * e-mail - mail your message to <vojtech@suse.cz>, or by paper mail:
33 * Vojtech Pavlik, Ucitelska 1576, Prague 8, 182 00 Czech Republic
36 #include <linux/kernel.h>
37 #include <linux/parport.h>
38 #include <linux/input.h>
39 #include <linux/module.h>
40 #include <linux/init.h>
42 MODULE_AUTHOR("Vojtech Pavlik <vojtech@suse.cz>");
43 MODULE_LICENSE("GPL");
44 MODULE_PARM(tgfx, "2-8i");
45 MODULE_PARM(tgfx_2, "2-8i");
46 MODULE_PARM(tgfx_3, "2-8i");
48 #define TGFX_REFRESH_TIME HZ/100 /* 10 ms */
50 #define TGFX_TRIGGER 0x08
52 #define TGFX_DOWN 0x20
53 #define TGFX_LEFT 0x40
54 #define TGFX_RIGHT 0x80
56 #define TGFX_THUMB 0x02
57 #define TGFX_THUMB2 0x04
59 #define TGFX_TOP2 0x08
61 static int tgfx[] __initdata = { -1, 0, 0, 0, 0, 0, 0, 0 };
62 static int tgfx_2[] __initdata = { -1, 0, 0, 0, 0, 0, 0, 0 };
63 static int tgfx_3[] __initdata = { -1, 0, 0, 0, 0, 0, 0, 0 };
65 static int tgfx_buttons[] = { BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2 };
66 static char *tgfx_name = "TurboGraFX Multisystem joystick";
70 struct timer_list timer;
71 struct input_dev dev[7];
77 * tgfx_timer() reads and analyzes TurboGraFX joystick data.
80 static void tgfx_timer(unsigned long private)
82 struct tgfx *tgfx = (void *) private;
83 struct input_dev *dev;
86 for (i = 0; i < 7; i++)
87 if (tgfx->sticks & (1 << i)) {
91 parport_write_data(tgfx->pd->port, ~(1 << i));
92 data1 = parport_read_status(tgfx->pd->port) ^ 0x7f;
93 data2 = parport_read_control(tgfx->pd->port) ^ 0x04; /* CAVEAT parport */
95 input_report_abs(dev, ABS_X, !!(data1 & TGFX_RIGHT) - !!(data1 & TGFX_LEFT));
96 input_report_abs(dev, ABS_Y, !!(data1 & TGFX_DOWN ) - !!(data1 & TGFX_UP ));
98 input_report_key(dev, BTN_TRIGGER, (data1 & TGFX_TRIGGER));
99 input_report_key(dev, BTN_THUMB, (data2 & TGFX_THUMB ));
100 input_report_key(dev, BTN_THUMB2, (data2 & TGFX_THUMB2 ));
101 input_report_key(dev, BTN_TOP, (data2 & TGFX_TOP ));
102 input_report_key(dev, BTN_TOP2, (data2 & TGFX_TOP2 ));
105 mod_timer(&tgfx->timer, jiffies + TGFX_REFRESH_TIME);
108 static int tgfx_open(struct input_dev *dev)
110 struct tgfx *tgfx = dev->private;
112 parport_claim(tgfx->pd);
113 parport_write_control(tgfx->pd->port, 0x04);
114 mod_timer(&tgfx->timer, jiffies + TGFX_REFRESH_TIME);
119 static void tgfx_close(struct input_dev *dev)
121 struct tgfx *tgfx = dev->private;
123 del_timer(&tgfx->timer);
124 parport_write_control(tgfx->pd->port, 0x00);
125 parport_release(tgfx->pd);
130 * tgfx_probe() probes for tg gamepads.
133 static struct tgfx __init *tgfx_probe(int *config)
142 for (pp = parport_enumerate(); pp && (config[0] > 0); pp = pp->next)
146 printk(KERN_ERR "turbografx.c: no such parport\n");
150 if (!(tgfx = kmalloc(sizeof(struct tgfx), GFP_KERNEL)))
152 memset(tgfx, 0, sizeof(struct tgfx));
154 tgfx->pd = parport_register_device(pp, "turbografx", NULL, NULL, NULL, PARPORT_DEV_EXCL, NULL);
157 printk(KERN_ERR "turbografx.c: parport busy already - lp.o loaded?\n");
162 init_timer(&tgfx->timer);
163 tgfx->timer.data = (long) tgfx;
164 tgfx->timer.function = tgfx_timer;
168 for (i = 0; i < 7; i++)
169 if (config[i+1] > 0 && config[i+1] < 6) {
171 tgfx->sticks |= (1 << i);
173 tgfx->dev[i].private = tgfx;
174 tgfx->dev[i].open = tgfx_open;
175 tgfx->dev[i].close = tgfx_close;
177 tgfx->dev[i].name = tgfx_name;
178 tgfx->dev[i].idbus = BUS_PARPORT;
179 tgfx->dev[i].idvendor = 0x0003;
180 tgfx->dev[i].idproduct = config[i+1];
181 tgfx->dev[i].idversion = 0x0100;
183 tgfx->dev[i].evbit[0] = BIT(EV_KEY) | BIT(EV_ABS);
184 tgfx->dev[i].absbit[0] = BIT(ABS_X) | BIT(ABS_Y);
186 for (j = 0; j < config[i+1]; j++)
187 set_bit(tgfx_buttons[j], tgfx->dev[i].keybit);
189 tgfx->dev[i].absmin[ABS_X] = -1; tgfx->dev[i].absmax[ABS_X] = 1;
190 tgfx->dev[i].absmin[ABS_Y] = -1; tgfx->dev[i].absmax[ABS_Y] = 1;
192 input_register_device(tgfx->dev + i);
193 printk(KERN_INFO "input%d: %d-button Multisystem joystick on %s\n",
194 tgfx->dev[i].number, config[i+1], tgfx->pd->port->name);
198 parport_unregister_device(tgfx->pd);
207 int __init tgfx_setup(char *str)
210 get_options(str, ARRAY_SIZE(ints), ints);
211 for (i = 0; i <= ints[0] && i < 8; i++) tgfx[i] = ints[i + 1];
214 int __init tgfx_setup_2(char *str)
217 get_options(str, ARRAY_SIZE(ints), ints);
218 for (i = 0; i <= ints[0] && i < 8; i++) tgfx_2[i] = ints[i + 1];
221 int __init tgfx_setup_3(char *str)
224 get_options(str, ARRAY_SIZE(ints), ints);
225 for (i = 0; i <= ints[0] && i < 8; i++) tgfx_3[i] = ints[i + 1];
228 __setup("tgfx=", tgfx_setup);
229 __setup("tgfx_2=", tgfx_setup_2);
230 __setup("tgfx_3=", tgfx_setup_3);
233 int __init tgfx_init(void)
235 tgfx_base[0] = tgfx_probe(tgfx);
236 tgfx_base[1] = tgfx_probe(tgfx_2);
237 tgfx_base[2] = tgfx_probe(tgfx_3);
239 if (tgfx_base[0] || tgfx_base[1] || tgfx_base[2])
245 void __exit tgfx_exit(void)
249 for (i = 0; i < 3; i++)
251 for (j = 0; j < 7; j++)
252 if (tgfx_base[i]->sticks & (1 << j))
253 input_unregister_device(tgfx_base[i]->dev + j);
254 parport_unregister_device(tgfx_base[i]->pd);
258 module_init(tgfx_init);
259 module_exit(tgfx_exit);