2 * $Id: db9.c,v 1.13 2002/04/07 20:13:37 vojtech Exp $
4 * Copyright (c) 1999-2001 Vojtech Pavlik
6 * Based on the work of:
7 * Andree Borrmann Mats Sjövall
11 * Atari, Amstrad, Commodore, Amiga, Sega, etc. joystick driver for Linux
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program; if not, write to the Free Software
27 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
29 * Should you need to contact me, the author, you can do so either by
30 * e-mail - mail your message to <vojtech@ucw.cz>, or by paper mail:
31 * Vojtech Pavlik, Simunkova 1594, Prague 8, 182 00 Czech Republic
34 #include <linux/kernel.h>
35 #include <linux/module.h>
36 #include <linux/moduleparam.h>
37 #include <linux/delay.h>
38 #include <linux/init.h>
39 #include <linux/parport.h>
40 #include <linux/input.h>
42 MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
43 MODULE_DESCRIPTION("Atari, Amstrad, Commodore, Amiga, Sega, etc. joystick driver");
44 MODULE_LICENSE("GPL");
46 static int db9
[] __initdata
= { -1, 0 };
47 static int db9_nargs __initdata
= 0;
48 module_param_array_named(dev
, db9
, int, &db9_nargs
, 0);
49 MODULE_PARM_DESC(dev
, "Describes first attached device (<parport#>,<type>)");
51 static int db9_2
[] __initdata
= { -1, 0 };
52 static int db9_nargs_2 __initdata
= 0;
53 module_param_array_named(dev2
, db9_2
, int, &db9_nargs_2
, 0);
54 MODULE_PARM_DESC(dev2
, "Describes second attached device (<parport#>,<type>)");
56 static int db9_3
[] __initdata
= { -1, 0 };
57 static int db9_nargs_3 __initdata
= 0;
58 module_param_array_named(dev3
, db9_3
, int, &db9_nargs_3
, 0);
59 MODULE_PARM_DESC(dev3
, "Describes third attached device (<parport#>,<type>)");
61 __obsolete_setup("db9=");
62 __obsolete_setup("db9_2=");
63 __obsolete_setup("db9_3=");
65 #define DB9_MULTI_STICK 0x01
66 #define DB9_MULTI2_STICK 0x02
67 #define DB9_GENESIS_PAD 0x03
68 #define DB9_GENESIS5_PAD 0x05
69 #define DB9_GENESIS6_PAD 0x06
70 #define DB9_SATURN_PAD 0x07
71 #define DB9_MULTI_0802 0x08
72 #define DB9_MULTI_0802_2 0x09
73 #define DB9_CD32_PAD 0x0A
74 #define DB9_SATURN_DPP 0x0B
75 #define DB9_SATURN_DPP_2 0x0C
76 #define DB9_MAX_PAD 0x0D
81 #define DB9_RIGHT 0x08
82 #define DB9_FIRE1 0x10
83 #define DB9_FIRE2 0x20
84 #define DB9_FIRE3 0x40
85 #define DB9_FIRE4 0x80
87 #define DB9_NORMAL 0x0a
88 #define DB9_NOSELECT 0x08
90 #define DB9_MAX_DEVICES 2
92 #define DB9_GENESIS6_DELAY 14
93 #define DB9_REFRESH_TIME HZ/100
96 struct input_dev dev
[DB9_MAX_DEVICES
];
97 struct timer_list timer
;
104 static struct db9
*db9_base
[3];
106 static short db9_multi_btn
[] = { BTN_TRIGGER
, BTN_THUMB
};
107 static short db9_genesis_btn
[] = { BTN_START
, BTN_A
, BTN_B
, BTN_C
, BTN_X
, BTN_Y
, BTN_Z
, BTN_MODE
};
108 static short db9_cd32_btn
[] = { BTN_A
, BTN_B
, BTN_C
, BTN_X
, BTN_Y
, BTN_Z
, BTN_TL
, BTN_TR
, BTN_START
};
110 static char db9_buttons
[DB9_MAX_PAD
] = { 0, 1, 2, 4, 0, 6, 8, 9, 1, 1, 7, 9, 9 };
111 static short *db9_btn
[DB9_MAX_PAD
] = { NULL
, db9_multi_btn
, db9_multi_btn
, db9_genesis_btn
, NULL
, db9_genesis_btn
,
112 db9_genesis_btn
, db9_cd32_btn
, db9_multi_btn
, db9_multi_btn
, db9_cd32_btn
,
113 db9_cd32_btn
, db9_cd32_btn
};
114 static char *db9_name
[DB9_MAX_PAD
] = { NULL
, "Multisystem joystick", "Multisystem joystick (2 fire)", "Genesis pad",
115 NULL
, "Genesis 5 pad", "Genesis 6 pad", "Saturn pad", "Multisystem (0.8.0.2) joystick",
116 "Multisystem (0.8.0.2-dual) joystick", "Amiga CD-32 pad", "Saturn dpp", "Saturn dpp dual" };
118 static const int db9_max_pads
[DB9_MAX_PAD
] = { 0, 1, 1, 1, 0, 1, 1, 6, 1, 2, 1, 6, 12 };
119 static const int db9_num_axis
[DB9_MAX_PAD
] = { 0, 2, 2, 2, 0, 2, 2, 7, 2, 2, 2 ,7, 7 };
120 static const short db9_abs
[] = { ABS_X
, ABS_Y
, ABS_RX
, ABS_RY
, ABS_RZ
, ABS_Z
, ABS_HAT0X
, ABS_HAT0Y
, ABS_HAT1X
, ABS_HAT1Y
};
121 static const int db9_bidirectional
[DB9_MAX_PAD
] = { 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0 };
122 static const int db9_reverse
[DB9_MAX_PAD
] = { 0, 1, 1, 1, 0, 1, 1, 1, 1, 1, 1, 0, 0 };
127 #define DB9_SATURN_DELAY 300
128 static const int db9_saturn_byte
[] = { 1, 1, 1, 2, 2, 2, 2, 2, 1 };
129 static const unsigned char db9_saturn_mask
[] = { 0x04, 0x01, 0x02, 0x40, 0x20, 0x10, 0x08, 0x80, 0x08 };
132 * db9_saturn_write_sub() writes 2 bit data.
134 static void db9_saturn_write_sub(struct parport
*port
, int type
, unsigned char data
, int powered
, int pwr_sub
)
140 c
= 0x80 | 0x30 | (powered
? 0x08 : 0) | (pwr_sub
? 0x04 : 0) | data
;
141 parport_write_data(port
, c
);
144 c
= 0x40 | data
<< 4 | (powered
? 0x08 : 0) | (pwr_sub
? 0x04 : 0) | 0x03;
145 parport_write_data(port
, c
);
148 c
= ((((data
& 2) ? 2 : 0) | ((data
& 1) ? 4 : 0)) ^ 0x02) | !powered
;
149 parport_write_control(port
, c
);
155 * gc_saturn_read_sub() reads 4 bit data.
157 static unsigned char db9_saturn_read_sub(struct parport
*port
, int type
)
163 data
= parport_read_status(port
) ^ 0x80;
164 return (data
& 0x80 ? 1 : 0) | (data
& 0x40 ? 2 : 0)
165 | (data
& 0x20 ? 4 : 0) | (data
& 0x10 ? 8 : 0);
168 data
= parport_read_data(port
) & 0x0f;
169 return (data
& 0x8 ? 1 : 0) | (data
& 0x4 ? 2 : 0)
170 | (data
& 0x2 ? 4 : 0) | (data
& 0x1 ? 8 : 0);
175 * db9_saturn_read_analog() sends clock and reads 8 bit data.
177 static unsigned char db9_saturn_read_analog(struct parport
*port
, int type
, int powered
)
181 db9_saturn_write_sub(port
, type
, 0, powered
, 0);
182 udelay(DB9_SATURN_DELAY
);
183 data
= db9_saturn_read_sub(port
, type
) << 4;
184 db9_saturn_write_sub(port
, type
, 2, powered
, 0);
185 udelay(DB9_SATURN_DELAY
);
186 data
|= db9_saturn_read_sub(port
, type
);
191 * db9_saturn_read_packet() reads whole saturn packet at connector
192 * and returns device identifier code.
194 static unsigned char db9_saturn_read_packet(struct parport
*port
, unsigned char *data
, int type
, int powered
)
199 db9_saturn_write_sub(port
, type
, 3, powered
, 0);
200 data
[0] = db9_saturn_read_sub(port
, type
);
201 switch (data
[0] & 0x0f) {
204 return data
[0] = 0xff;
205 case 0x4: case 0x4 | 0x8:
206 /* ?100 : digital controller */
207 db9_saturn_write_sub(port
, type
, 0, powered
, 1);
208 data
[2] = db9_saturn_read_sub(port
, type
) << 4;
209 db9_saturn_write_sub(port
, type
, 2, powered
, 1);
210 data
[1] = db9_saturn_read_sub(port
, type
) << 4;
211 db9_saturn_write_sub(port
, type
, 1, powered
, 1);
212 data
[1] |= db9_saturn_read_sub(port
, type
);
213 db9_saturn_write_sub(port
, type
, 3, powered
, 1);
214 /* data[2] |= db9_saturn_read_sub(port, type); */
216 return data
[0] = 0x02;
218 /* 0001 : analog controller or multitap */
219 db9_saturn_write_sub(port
, type
, 2, powered
, 0);
220 udelay(DB9_SATURN_DELAY
);
221 data
[0] = db9_saturn_read_analog(port
, type
, powered
);
222 if (data
[0] != 0x41) {
223 /* read analog controller */
224 for (i
= 0; i
< (data
[0] & 0x0f); i
++)
225 data
[i
+ 1] = db9_saturn_read_analog(port
, type
, powered
);
226 db9_saturn_write_sub(port
, type
, 3, powered
, 0);
230 if (db9_saturn_read_analog(port
, type
, powered
) != 0x60)
231 return data
[0] = 0xff;
232 for (i
= 0; i
< 60; i
+= 10) {
233 data
[i
] = db9_saturn_read_analog(port
, type
, powered
);
236 for (j
= 0; j
< (data
[i
] & 0x0f); j
++)
237 data
[i
+ j
+ 1] = db9_saturn_read_analog(port
, type
, powered
);
239 db9_saturn_write_sub(port
, type
, 3, powered
, 0);
244 db9_saturn_write_sub(port
, type
, 2, powered
, 0);
245 udelay(DB9_SATURN_DELAY
);
246 tmp
= db9_saturn_read_analog(port
, type
, powered
);
248 for (i
= 0; i
< 3; i
++)
249 data
[i
+ 1] = db9_saturn_read_analog(port
, type
, powered
);
250 db9_saturn_write_sub(port
, type
, 3, powered
, 0);
251 return data
[0] = 0xe3;
259 * db9_saturn_report() analyzes packet and reports.
261 static int db9_saturn_report(unsigned char id
, unsigned char data
[60], struct input_dev
*dev
, int n
, int max_pads
)
265 tmp
= (id
== 0x41) ? 60 : 10;
266 for (j
= 0; (j
< tmp
) && (n
< max_pads
); j
+= 10, n
++) {
268 case 0x16: /* multi controller (analog 4 axis) */
269 input_report_abs(dev
+ n
, db9_abs
[5], data
[j
+ 6]);
270 case 0x15: /* mission stick (analog 3 axis) */
271 input_report_abs(dev
+ n
, db9_abs
[3], data
[j
+ 4]);
272 input_report_abs(dev
+ n
, db9_abs
[4], data
[j
+ 5]);
273 case 0x13: /* racing controller (analog 1 axis) */
274 input_report_abs(dev
+ n
, db9_abs
[2], data
[j
+ 3]);
275 case 0x34: /* saturn keyboard (udlr ZXC ASD QE Esc) */
276 case 0x02: /* digital pad (digital 2 axis + buttons) */
277 input_report_abs(dev
+ n
, db9_abs
[0], !(data
[j
+ 1] & 128) - !(data
[j
+ 1] & 64));
278 input_report_abs(dev
+ n
, db9_abs
[1], !(data
[j
+ 1] & 32) - !(data
[j
+ 1] & 16));
279 for (i
= 0; i
< 9; i
++)
280 input_report_key(dev
+ n
, db9_cd32_btn
[i
], ~data
[j
+ db9_saturn_byte
[i
]] & db9_saturn_mask
[i
]);
282 case 0x19: /* mission stick x2 (analog 6 axis + buttons) */
283 input_report_abs(dev
+ n
, db9_abs
[0], !(data
[j
+ 1] & 128) - !(data
[j
+ 1] & 64));
284 input_report_abs(dev
+ n
, db9_abs
[1], !(data
[j
+ 1] & 32) - !(data
[j
+ 1] & 16));
285 for (i
= 0; i
< 9; i
++)
286 input_report_key(dev
+ n
, db9_cd32_btn
[i
], ~data
[j
+ db9_saturn_byte
[i
]] & db9_saturn_mask
[i
]);
287 input_report_abs(dev
+ n
, db9_abs
[2], data
[j
+ 3]);
288 input_report_abs(dev
+ n
, db9_abs
[3], data
[j
+ 4]);
289 input_report_abs(dev
+ n
, db9_abs
[4], data
[j
+ 5]);
291 input_report_abs(dev + n, db9_abs[8], (data[j + 6] & 128 ? 0 : 1) - (data[j + 6] & 64 ? 0 : 1));
292 input_report_abs(dev + n, db9_abs[9], (data[j + 6] & 32 ? 0 : 1) - (data[j + 6] & 16 ? 0 : 1));
294 input_report_abs(dev
+ n
, db9_abs
[6], data
[j
+ 7]);
295 input_report_abs(dev
+ n
, db9_abs
[7], data
[j
+ 8]);
296 input_report_abs(dev
+ n
, db9_abs
[5], data
[j
+ 9]);
298 case 0xd3: /* sankyo ff (analog 1 axis + stop btn) */
299 input_report_key(dev
+ n
, BTN_A
, data
[j
+ 3] & 0x80);
300 input_report_abs(dev
+ n
, db9_abs
[2], data
[j
+ 3] & 0x7f);
302 case 0xe3: /* shuttle mouse (analog 2 axis + buttons. signed value) */
303 input_report_key(dev
+ n
, BTN_START
, data
[j
+ 1] & 0x08);
304 input_report_key(dev
+ n
, BTN_A
, data
[j
+ 1] & 0x04);
305 input_report_key(dev
+ n
, BTN_C
, data
[j
+ 1] & 0x02);
306 input_report_key(dev
+ n
, BTN_B
, data
[j
+ 1] & 0x01);
307 input_report_abs(dev
+ n
, db9_abs
[2], data
[j
+ 2] ^ 0x80);
308 input_report_abs(dev
+ n
, db9_abs
[3], (0xff-(data
[j
+ 3] ^ 0x80))+1); /* */
311 default: /* no pad */
312 input_report_abs(dev
+ n
, db9_abs
[0], 0);
313 input_report_abs(dev
+ n
, db9_abs
[1], 0);
314 for (i
= 0; i
< 9; i
++)
315 input_report_key(dev
+ n
, db9_cd32_btn
[i
], 0);
322 static int db9_saturn(int mode
, struct parport
*port
, struct input_dev
*dev
)
324 unsigned char id
, data
[60];
325 int type
, n
, max_pads
;
337 case DB9_SATURN_DPP_2
:
344 max_pads
= min(db9_max_pads
[mode
], DB9_MAX_DEVICES
);
345 for (tmp
= 0, i
= 0; i
< n
; i
++) {
346 id
= db9_saturn_read_packet(port
, data
, type
+ i
, 1);
347 tmp
= db9_saturn_report(id
, data
, dev
, tmp
, max_pads
);
352 static void db9_timer(unsigned long private)
354 struct db9
*db9
= (void *) private;
355 struct parport
*port
= db9
->pd
->port
;
356 struct input_dev
*dev
= db9
->dev
;
360 case DB9_MULTI_0802_2
:
362 data
= parport_read_data(port
) >> 3;
364 input_report_abs(dev
+ 1, ABS_X
, (data
& DB9_RIGHT
? 0 : 1) - (data
& DB9_LEFT
? 0 : 1));
365 input_report_abs(dev
+ 1, ABS_Y
, (data
& DB9_DOWN
? 0 : 1) - (data
& DB9_UP
? 0 : 1));
366 input_report_key(dev
+ 1, BTN_TRIGGER
, ~data
& DB9_FIRE1
);
370 data
= parport_read_status(port
) >> 3;
372 input_report_abs(dev
, ABS_X
, (data
& DB9_RIGHT
? 0 : 1) - (data
& DB9_LEFT
? 0 : 1));
373 input_report_abs(dev
, ABS_Y
, (data
& DB9_DOWN
? 0 : 1) - (data
& DB9_UP
? 0 : 1));
374 input_report_key(dev
, BTN_TRIGGER
, data
& DB9_FIRE1
);
377 case DB9_MULTI_STICK
:
379 data
= parport_read_data(port
);
381 input_report_abs(dev
, ABS_X
, (data
& DB9_RIGHT
? 0 : 1) - (data
& DB9_LEFT
? 0 : 1));
382 input_report_abs(dev
, ABS_Y
, (data
& DB9_DOWN
? 0 : 1) - (data
& DB9_UP
? 0 : 1));
383 input_report_key(dev
, BTN_TRIGGER
, ~data
& DB9_FIRE1
);
386 case DB9_MULTI2_STICK
:
388 data
= parport_read_data(port
);
390 input_report_abs(dev
, ABS_X
, (data
& DB9_RIGHT
? 0 : 1) - (data
& DB9_LEFT
? 0 : 1));
391 input_report_abs(dev
, ABS_Y
, (data
& DB9_DOWN
? 0 : 1) - (data
& DB9_UP
? 0 : 1));
392 input_report_key(dev
, BTN_TRIGGER
, ~data
& DB9_FIRE1
);
393 input_report_key(dev
, BTN_THUMB
, ~data
& DB9_FIRE2
);
396 case DB9_GENESIS_PAD
:
398 parport_write_control(port
, DB9_NOSELECT
);
399 data
= parport_read_data(port
);
401 input_report_abs(dev
, ABS_X
, (data
& DB9_RIGHT
? 0 : 1) - (data
& DB9_LEFT
? 0 : 1));
402 input_report_abs(dev
, ABS_Y
, (data
& DB9_DOWN
? 0 : 1) - (data
& DB9_UP
? 0 : 1));
403 input_report_key(dev
, BTN_B
, ~data
& DB9_FIRE1
);
404 input_report_key(dev
, BTN_C
, ~data
& DB9_FIRE2
);
406 parport_write_control(port
, DB9_NORMAL
);
407 data
=parport_read_data(port
);
409 input_report_key(dev
, BTN_A
, ~data
& DB9_FIRE1
);
410 input_report_key(dev
, BTN_START
, ~data
& DB9_FIRE2
);
413 case DB9_GENESIS5_PAD
:
415 parport_write_control(port
, DB9_NOSELECT
);
416 data
=parport_read_data(port
);
418 input_report_abs(dev
, ABS_X
, (data
& DB9_RIGHT
? 0 : 1) - (data
& DB9_LEFT
? 0 : 1));
419 input_report_abs(dev
, ABS_Y
, (data
& DB9_DOWN
? 0 : 1) - (data
& DB9_UP
? 0 : 1));
420 input_report_key(dev
, BTN_B
, ~data
& DB9_FIRE1
);
421 input_report_key(dev
, BTN_C
, ~data
& DB9_FIRE2
);
423 parport_write_control(port
, DB9_NORMAL
);
424 data
=parport_read_data(port
);
426 input_report_key(dev
, BTN_A
, ~data
& DB9_FIRE1
);
427 input_report_key(dev
, BTN_X
, ~data
& DB9_FIRE2
);
428 input_report_key(dev
, BTN_Y
, ~data
& DB9_LEFT
);
429 input_report_key(dev
, BTN_START
, ~data
& DB9_RIGHT
);
432 case DB9_GENESIS6_PAD
:
434 parport_write_control(port
, DB9_NOSELECT
); /* 1 */
435 udelay(DB9_GENESIS6_DELAY
);
436 data
=parport_read_data(port
);
438 input_report_abs(dev
, ABS_X
, (data
& DB9_RIGHT
? 0 : 1) - (data
& DB9_LEFT
? 0 : 1));
439 input_report_abs(dev
, ABS_Y
, (data
& DB9_DOWN
? 0 : 1) - (data
& DB9_UP
? 0 : 1));
440 input_report_key(dev
, BTN_B
, ~data
& DB9_FIRE1
);
441 input_report_key(dev
, BTN_C
, ~data
& DB9_FIRE2
);
443 parport_write_control(port
, DB9_NORMAL
);
444 udelay(DB9_GENESIS6_DELAY
);
445 data
=parport_read_data(port
);
447 input_report_key(dev
, BTN_A
, ~data
& DB9_FIRE1
);
448 input_report_key(dev
, BTN_START
, ~data
& DB9_FIRE2
);
450 parport_write_control(port
, DB9_NOSELECT
); /* 2 */
451 udelay(DB9_GENESIS6_DELAY
);
452 parport_write_control(port
, DB9_NORMAL
);
453 udelay(DB9_GENESIS6_DELAY
);
454 parport_write_control(port
, DB9_NOSELECT
); /* 3 */
455 udelay(DB9_GENESIS6_DELAY
);
456 data
=parport_read_data(port
);
458 input_report_key(dev
, BTN_X
, ~data
& DB9_LEFT
);
459 input_report_key(dev
, BTN_Y
, ~data
& DB9_DOWN
);
460 input_report_key(dev
, BTN_Z
, ~data
& DB9_UP
);
461 input_report_key(dev
, BTN_MODE
, ~data
& DB9_RIGHT
);
463 parport_write_control(port
, DB9_NORMAL
);
464 udelay(DB9_GENESIS6_DELAY
);
465 parport_write_control(port
, DB9_NOSELECT
); /* 4 */
466 udelay(DB9_GENESIS6_DELAY
);
467 parport_write_control(port
, DB9_NORMAL
);
472 case DB9_SATURN_DPP_2
:
474 db9_saturn(db9
->mode
, port
, dev
);
479 data
=parport_read_data(port
);
481 input_report_abs(dev
, ABS_X
, (data
& DB9_RIGHT
? 0 : 1) - (data
& DB9_LEFT
? 0 : 1));
482 input_report_abs(dev
, ABS_Y
, (data
& DB9_DOWN
? 0 : 1) - (data
& DB9_UP
? 0 : 1));
484 parport_write_control(port
, 0x0a);
486 for (i
= 0; i
< 7; i
++) {
487 data
= parport_read_data(port
);
488 parport_write_control(port
, 0x02);
489 parport_write_control(port
, 0x0a);
490 input_report_key(dev
, db9_cd32_btn
[i
], ~data
& DB9_FIRE2
);
493 parport_write_control(port
, 0x00);
499 mod_timer(&db9
->timer
, jiffies
+ DB9_REFRESH_TIME
);
502 static int db9_open(struct input_dev
*dev
)
504 struct db9
*db9
= dev
->private;
505 struct parport
*port
= db9
->pd
->port
;
508 parport_claim(db9
->pd
);
509 parport_write_data(port
, 0xff);
510 if (db9_reverse
[db9
->mode
]) {
511 parport_data_reverse(port
);
512 parport_write_control(port
, DB9_NORMAL
);
514 mod_timer(&db9
->timer
, jiffies
+ DB9_REFRESH_TIME
);
520 static void db9_close(struct input_dev
*dev
)
522 struct db9
*db9
= dev
->private;
523 struct parport
*port
= db9
->pd
->port
;
526 del_timer(&db9
->timer
);
527 parport_write_control(port
, 0x00);
528 parport_data_forward(port
);
529 parport_release(db9
->pd
);
533 static struct db9 __init
*db9_probe(int *config
, int nargs
)
543 printk(KERN_ERR
"db9.c: Device type must be specified.\n");
547 if (config
[1] < 1 || config
[1] >= DB9_MAX_PAD
|| !db9_buttons
[config
[1]]) {
548 printk(KERN_ERR
"db9.c: bad config\n");
552 pp
= parport_find_number(config
[0]);
554 printk(KERN_ERR
"db9.c: no such parport\n");
558 if (db9_bidirectional
[config
[1]]) {
559 if (!(pp
->modes
& PARPORT_MODE_TRISTATE
)) {
560 printk(KERN_ERR
"db9.c: specified parport is not bidirectional\n");
561 parport_put_port(pp
);
566 if (!(db9
= kmalloc(sizeof(struct db9
), GFP_KERNEL
))) {
567 parport_put_port(pp
);
570 memset(db9
, 0, sizeof(struct db9
));
572 db9
->mode
= config
[1];
573 init_timer(&db9
->timer
);
574 db9
->timer
.data
= (long) db9
;
575 db9
->timer
.function
= db9_timer
;
577 db9
->pd
= parport_register_device(pp
, "db9", NULL
, NULL
, NULL
, PARPORT_DEV_EXCL
, NULL
);
578 parport_put_port(pp
);
581 printk(KERN_ERR
"db9.c: parport busy already - lp.o loaded?\n");
586 for (i
= 0; i
< (min(db9_max_pads
[db9
->mode
], DB9_MAX_DEVICES
)); i
++) {
588 sprintf(db9
->phys
[i
], "%s/input%d", db9
->pd
->port
->name
, i
);
590 db9
->dev
[i
].private = db9
;
591 db9
->dev
[i
].open
= db9_open
;
592 db9
->dev
[i
].close
= db9_close
;
594 db9
->dev
[i
].name
= db9_name
[db9
->mode
];
595 db9
->dev
[i
].phys
= db9
->phys
[i
];
596 db9
->dev
[i
].id
.bustype
= BUS_PARPORT
;
597 db9
->dev
[i
].id
.vendor
= 0x0002;
598 db9
->dev
[i
].id
.product
= config
[1];
599 db9
->dev
[i
].id
.version
= 0x0100;
601 db9
->dev
[i
].evbit
[0] = BIT(EV_KEY
) | BIT(EV_ABS
);
602 for (j
= 0; j
< db9_buttons
[db9
->mode
]; j
++)
603 set_bit(db9_btn
[db9
->mode
][j
], db9
->dev
[i
].keybit
);
604 for (j
= 0; j
< db9_num_axis
[db9
->mode
]; j
++) {
605 set_bit(db9_abs
[j
], db9
->dev
[i
].absbit
);
607 db9
->dev
[i
].absmin
[db9_abs
[j
]] = -1;
608 db9
->dev
[i
].absmax
[db9_abs
[j
]] = 1;
610 db9
->dev
[i
].absmin
[db9_abs
[j
]] = 1;
611 db9
->dev
[i
].absmax
[db9_abs
[j
]] = 255;
612 db9
->dev
[i
].absflat
[db9_abs
[j
]] = 0;
615 input_register_device(db9
->dev
+ i
);
616 printk(KERN_INFO
"input: %s on %s\n", db9
->dev
[i
].name
, db9
->pd
->port
->name
);
622 static int __init
db9_init(void)
624 db9_base
[0] = db9_probe(db9
, db9_nargs
);
625 db9_base
[1] = db9_probe(db9_2
, db9_nargs_2
);
626 db9_base
[2] = db9_probe(db9_3
, db9_nargs_3
);
628 if (db9_base
[0] || db9_base
[1] || db9_base
[2])
634 static void __exit
db9_exit(void)
638 for (i
= 0; i
< 3; i
++)
640 for (j
= 0; j
< min(db9_max_pads
[db9_base
[i
]->mode
], DB9_MAX_DEVICES
); j
++)
641 input_unregister_device(db9_base
[i
]->dev
+ j
);
642 parport_unregister_device(db9_base
[i
]->pd
);
646 module_init(db9_init
);
647 module_exit(db9_exit
);