Lines Matching +full:port +full:- +full:2
1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 1999-2001 Vojtech Pavlik
27 int args[2];
38 module_param_array_named(dev3, db9_cfg[2].args, int, &db9_cfg[2].nargs, 0);
72 #define DB9_MAX_DEVICES 2
104 { "Multisystem joystick", db9_multi_btn, 1, 1, 2, 1, 1 },
105 { "Multisystem joystick (2 fire)", db9_multi_btn, 2, 1, 2, 1, 1 },
106 { "Genesis pad", db9_genesis_btn, 4, 1, 2, 1, 1 },
108 { "Genesis 5 pad", db9_genesis_btn, 6, 1, 2, 1, 1 },
109 { "Genesis 6 pad", db9_genesis_btn, 8, 1, 2, 1, 1 },
111 { "Multisystem (0.8.0.2) joystick", db9_multi_btn, 1, 1, 2, 1, 1 },
112 { "Multisystem (0.8.0.2-dual) joystick", db9_multi_btn, 1, 2, 2, 1, 1 },
113 { "Amiga CD-32 pad", db9_cd32_btn, 7, 1, 2, 1, 1 },
122 static const int db9_saturn_byte[] = { 1, 1, 1, 2, 2, 2, 2, 2, 1 };
126 * db9_saturn_write_sub() writes 2 bit data.
128 static void db9_saturn_write_sub(struct parport *port, int type, unsigned char data, int powered, i… in db9_saturn_write_sub() argument
135 parport_write_data(port, c); in db9_saturn_write_sub()
137 case 2: /* DPP2 */ in db9_saturn_write_sub()
139 parport_write_data(port, c); in db9_saturn_write_sub()
142 c = ((((data & 2) ? 2 : 0) | ((data & 1) ? 4 : 0)) ^ 0x02) | !powered; in db9_saturn_write_sub()
143 parport_write_control(port, c); in db9_saturn_write_sub()
151 static unsigned char db9_saturn_read_sub(struct parport *port, int type) in db9_saturn_read_sub() argument
157 data = parport_read_status(port) ^ 0x80; in db9_saturn_read_sub()
158 return (data & 0x80 ? 1 : 0) | (data & 0x40 ? 2 : 0) in db9_saturn_read_sub()
162 data = parport_read_data(port) & 0x0f; in db9_saturn_read_sub()
163 return (data & 0x8 ? 1 : 0) | (data & 0x4 ? 2 : 0) in db9_saturn_read_sub()
171 static unsigned char db9_saturn_read_analog(struct parport *port, int type, int powered) in db9_saturn_read_analog() argument
175 db9_saturn_write_sub(port, type, 0, powered, 0); in db9_saturn_read_analog()
177 data = db9_saturn_read_sub(port, type) << 4; in db9_saturn_read_analog()
178 db9_saturn_write_sub(port, type, 2, powered, 0); in db9_saturn_read_analog()
180 data |= db9_saturn_read_sub(port, type); in db9_saturn_read_analog()
188 static unsigned char db9_saturn_read_packet(struct parport *port, unsigned char *data, int type, in… in db9_saturn_read_packet() argument
193 db9_saturn_write_sub(port, type, 3, powered, 0); in db9_saturn_read_packet()
194 data[0] = db9_saturn_read_sub(port, type); in db9_saturn_read_packet()
201 db9_saturn_write_sub(port, type, 0, powered, 1); in db9_saturn_read_packet()
202 data[2] = db9_saturn_read_sub(port, type) << 4; in db9_saturn_read_packet()
203 db9_saturn_write_sub(port, type, 2, powered, 1); in db9_saturn_read_packet()
204 data[1] = db9_saturn_read_sub(port, type) << 4; in db9_saturn_read_packet()
205 db9_saturn_write_sub(port, type, 1, powered, 1); in db9_saturn_read_packet()
206 data[1] |= db9_saturn_read_sub(port, type); in db9_saturn_read_packet()
207 db9_saturn_write_sub(port, type, 3, powered, 1); in db9_saturn_read_packet()
208 /* data[2] |= db9_saturn_read_sub(port, type); */ in db9_saturn_read_packet()
209 data[2] |= data[0]; in db9_saturn_read_packet()
213 db9_saturn_write_sub(port, type, 2, powered, 0); in db9_saturn_read_packet()
215 data[0] = db9_saturn_read_analog(port, type, powered); in db9_saturn_read_packet()
219 data[i + 1] = db9_saturn_read_analog(port, type, powered); in db9_saturn_read_packet()
220 db9_saturn_write_sub(port, type, 3, powered, 0); in db9_saturn_read_packet()
224 if (db9_saturn_read_analog(port, type, powered) != 0x60) in db9_saturn_read_packet()
227 data[i] = db9_saturn_read_analog(port, type, powered); in db9_saturn_read_packet()
231 data[i + j + 1] = db9_saturn_read_analog(port, type, powered); in db9_saturn_read_packet()
233 db9_saturn_write_sub(port, type, 3, powered, 0); in db9_saturn_read_packet()
238 db9_saturn_write_sub(port, type, 2, powered, 0); in db9_saturn_read_packet()
240 tmp = db9_saturn_read_analog(port, type, powered); in db9_saturn_read_packet()
243 data[i + 1] = db9_saturn_read_analog(port, type, powered); in db9_saturn_read_packet()
244 db9_saturn_write_sub(port, type, 3, powered, 0); in db9_saturn_read_packet()
273 input_report_abs(dev, db9_abs[2], data[j + 3]); in db9_saturn_report()
276 case 0x02: /* digital pad (digital 2 axis + buttons) */ in db9_saturn_report()
277 input_report_abs(dev, db9_abs[0], !(data[j + 1] & 128) - !(data[j + 1] & 64)); in db9_saturn_report()
278 input_report_abs(dev, db9_abs[1], !(data[j + 1] & 32) - !(data[j + 1] & 16)); in db9_saturn_report()
283 input_report_abs(dev, db9_abs[0], !(data[j + 1] & 128) - !(data[j + 1] & 64)); in db9_saturn_report()
284 input_report_abs(dev, db9_abs[1], !(data[j + 1] & 32) - !(data[j + 1] & 16)); in db9_saturn_report()
287 input_report_abs(dev, db9_abs[2], data[j + 3]); in db9_saturn_report()
291 input_report_abs(dev, db9_abs[8], (data[j + 6] & 128 ? 0 : 1) - (data[j + 6] & 64 ? 0 : 1)); in db9_saturn_report()
292 input_report_abs(dev, db9_abs[9], (data[j + 6] & 32 ? 0 : 1) - (data[j + 6] & 16 ? 0 : 1)); in db9_saturn_report()
300 input_report_abs(dev, db9_abs[2], data[j + 3] & 0x7f); in db9_saturn_report()
302 case 0xe3: /* shuttle mouse (analog 2 axis + buttons. signed value) */ in db9_saturn_report()
307 input_report_abs(dev, db9_abs[2], data[j + 2] ^ 0x80); in db9_saturn_report()
308 input_report_abs(dev, db9_abs[3], (0xff-(data[j + 3] ^ 0x80))+1); /* */ in db9_saturn_report()
322 static int db9_saturn(int mode, struct parport *port, struct input_dev *devs[]) in db9_saturn() argument
339 n = 2; in db9_saturn()
342 return -1; in db9_saturn()
346 id = db9_saturn_read_packet(port, data, type + i, 1); in db9_saturn()
355 struct parport *port = db9->pd->port; in db9_timer() local
356 struct input_dev *dev = db9->dev[0]; in db9_timer()
357 struct input_dev *dev2 = db9->dev[1]; in db9_timer()
360 switch (db9->mode) { in db9_timer()
363 data = parport_read_data(port) >> 3; in db9_timer()
365 input_report_abs(dev2, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); in db9_timer()
366 input_report_abs(dev2, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); in db9_timer()
372 data = parport_read_status(port) >> 3; in db9_timer()
374 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); in db9_timer()
375 input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); in db9_timer()
381 data = parport_read_data(port); in db9_timer()
383 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); in db9_timer()
384 input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); in db9_timer()
390 data = parport_read_data(port); in db9_timer()
392 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); in db9_timer()
393 input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); in db9_timer()
400 parport_write_control(port, DB9_NOSELECT); in db9_timer()
401 data = parport_read_data(port); in db9_timer()
403 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); in db9_timer()
404 input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); in db9_timer()
408 parport_write_control(port, DB9_NORMAL); in db9_timer()
409 data = parport_read_data(port); in db9_timer()
417 parport_write_control(port, DB9_NOSELECT); in db9_timer()
418 data = parport_read_data(port); in db9_timer()
420 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); in db9_timer()
421 input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); in db9_timer()
425 parport_write_control(port, DB9_NORMAL); in db9_timer()
426 data = parport_read_data(port); in db9_timer()
436 parport_write_control(port, DB9_NOSELECT); /* 1 */ in db9_timer()
438 data = parport_read_data(port); in db9_timer()
440 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); in db9_timer()
441 input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); in db9_timer()
445 parport_write_control(port, DB9_NORMAL); in db9_timer()
447 data = parport_read_data(port); in db9_timer()
452 parport_write_control(port, DB9_NOSELECT); /* 2 */ in db9_timer()
454 parport_write_control(port, DB9_NORMAL); in db9_timer()
456 parport_write_control(port, DB9_NOSELECT); /* 3 */ in db9_timer()
458 data=parport_read_data(port); in db9_timer()
465 parport_write_control(port, DB9_NORMAL); in db9_timer()
467 parport_write_control(port, DB9_NOSELECT); /* 4 */ in db9_timer()
469 parport_write_control(port, DB9_NORMAL); in db9_timer()
476 db9_saturn(db9->mode, port, db9->dev); in db9_timer()
481 data = parport_read_data(port); in db9_timer()
483 input_report_abs(dev, ABS_X, (data & DB9_RIGHT ? 0 : 1) - (data & DB9_LEFT ? 0 : 1)); in db9_timer()
484 input_report_abs(dev, ABS_Y, (data & DB9_DOWN ? 0 : 1) - (data & DB9_UP ? 0 : 1)); in db9_timer()
486 parport_write_control(port, 0x0a); in db9_timer()
489 data = parport_read_data(port); in db9_timer()
490 parport_write_control(port, 0x02); in db9_timer()
491 parport_write_control(port, 0x0a); in db9_timer()
495 parport_write_control(port, 0x00); in db9_timer()
501 mod_timer(&db9->timer, jiffies + DB9_REFRESH_TIME); in db9_timer()
507 struct parport *port = db9->pd->port; in db9_open() local
510 err = mutex_lock_interruptible(&db9->mutex); in db9_open()
514 if (!db9->used++) { in db9_open()
515 parport_claim(db9->pd); in db9_open()
516 parport_write_data(port, 0xff); in db9_open()
517 if (db9_modes[db9->mode].reverse) { in db9_open()
518 parport_data_reverse(port); in db9_open()
519 parport_write_control(port, DB9_NORMAL); in db9_open()
521 mod_timer(&db9->timer, jiffies + DB9_REFRESH_TIME); in db9_open()
524 mutex_unlock(&db9->mutex); in db9_open()
531 struct parport *port = db9->pd->port; in db9_close() local
533 mutex_lock(&db9->mutex); in db9_close()
534 if (!--db9->used) { in db9_close()
535 del_timer_sync(&db9->timer); in db9_close()
536 parport_write_control(port, 0x00); in db9_close()
537 parport_data_forward(port); in db9_close()
538 parport_release(db9->pd); in db9_close()
540 mutex_unlock(&db9->mutex); in db9_close()
558 if (db9_cfg[port_idx].args[DB9_ARG_PARPORT] == pp->number) in db9_attach()
563 pr_debug("Not using parport%d.\n", pp->number); in db9_attach()
576 if (db9_mode->bidirectional && !(pp->modes & PARPORT_MODE_TRISTATE)) { in db9_attach()
586 printk(KERN_ERR "db9.c: parport busy already - lp.o loaded?\n"); in db9_attach()
594 mutex_init(&db9->mutex); in db9_attach()
595 db9->pd = pd; in db9_attach()
596 db9->mode = mode; in db9_attach()
597 db9->parportno = pp->number; in db9_attach()
598 timer_setup(&db9->timer, db9_timer, 0); in db9_attach()
600 for (i = 0; i < (min(db9_mode->n_pads, DB9_MAX_DEVICES)); i++) { in db9_attach()
602 db9->dev[i] = input_dev = input_allocate_device(); in db9_attach()
608 snprintf(db9->phys[i], sizeof(db9->phys[i]), in db9_attach()
609 "%s/input%d", db9->pd->port->name, i); in db9_attach()
611 input_dev->name = db9_mode->name; in db9_attach()
612 input_dev->phys = db9->phys[i]; in db9_attach()
613 input_dev->id.bustype = BUS_PARPORT; in db9_attach()
614 input_dev->id.vendor = 0x0002; in db9_attach()
615 input_dev->id.product = mode; in db9_attach()
616 input_dev->id.version = 0x0100; in db9_attach()
620 input_dev->open = db9_open; in db9_attach()
621 input_dev->close = db9_close; in db9_attach()
623 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); in db9_attach()
624 for (j = 0; j < db9_mode->n_buttons; j++) in db9_attach()
625 set_bit(db9_mode->buttons[j], input_dev->keybit); in db9_attach()
626 for (j = 0; j < db9_mode->n_axis; j++) { in db9_attach()
627 if (j < 2) in db9_attach()
628 input_set_abs_params(input_dev, db9_abs[j], -1, 1, 0, 0); in db9_attach()
641 input_free_device(db9->dev[i]); in db9_attach()
643 while (--i >= 0) in db9_attach()
644 input_unregister_device(db9->dev[i]); in db9_attach()
650 static void db9_detach(struct parport *port) in db9_detach() argument
656 if (db9_base[i] && db9_base[i]->parportno == port->number) in db9_detach()
666 for (i = 0; i < min(db9_modes[db9->mode].n_pads, DB9_MAX_DEVICES); i++) in db9_detach()
667 input_unregister_device(db9->dev[i]); in db9_detach()
668 parport_unregister_device(db9->pd); in db9_detach()
687 if (db9_cfg[i].nargs < 2) { in db9_init()
689 return -EINVAL; in db9_init()
696 return -ENODEV; in db9_init()