Lines Matching +full:3 +full:- +full:port

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 1996-2001 Vojtech Pavlik
75 #define ANALOG_MAX_TIME 3 /* 3 ms */
131 #define DELTA(x,y) (boot_cpu_has(X86_FEATURE_TSC) ? ((y) - (x)) : ((x) - (y) + ((x) < (y) ? PIT_TIC…
148 #define DELTA(x,y) ((y)-(x))
152 #define DELTA(x,y) ((y)-(x))
158 #define DELTA(x,y) ((y)-(x))
177 return y - x; in delta()
188 struct input_dev *dev = analog->dev; in analog_decode()
191 if (analog->mask & ANALOG_HAT_FCS) in analog_decode()
193 if (axes[3] < ((initial[3] * ((i << 1) + 1)) >> 3)) { in analog_decode()
199 if (analog->mask & (0x10 << i)) in analog_decode()
200 input_report_key(dev, analog->buttons[j++], (buttons >> i) & 1); in analog_decode()
202 if (analog->mask & ANALOG_HBTN_CHF) in analog_decode()
204 input_report_key(dev, analog->buttons[j++], (buttons >> (i + 10)) & 1); in analog_decode()
206 if (analog->mask & ANALOG_BTN_TL) in analog_decode()
208 if (analog->mask & ANALOG_BTN_TR) in analog_decode()
209 input_report_key(dev, analog_pads[1], axes[3] < (initial[3] >> 1)); in analog_decode()
210 if (analog->mask & ANALOG_BTN_TL2) in analog_decode()
212 if (analog->mask & ANALOG_BTN_TR2) in analog_decode()
213 input_report_key(dev, analog_pads[3], axes[3] > (initial[3] + (initial[3] >> 1))); in analog_decode()
216 if (analog->mask & (1 << i)) in analog_decode()
219 for (i = j = 0; i < 3; i++) in analog_decode()
220 if (analog->mask & analog_exts[i]) { in analog_decode()
222 ((buttons >> ((i << 2) + 7)) & 1) - ((buttons >> ((i << 2) + 9)) & 1)); in analog_decode()
224 ((buttons >> ((i << 2) + 8)) & 1) - ((buttons >> ((i << 2) + 6)) & 1)); in analog_decode()
234 static int analog_cooked_read(struct analog_port *port) in analog_cooked_read() argument
236 struct gameport *gameport = port->gameport; in analog_cooked_read()
243 loopout = (ANALOG_LOOP_TIME * port->loop) / 1000; in analog_cooked_read()
244 timeout = ANALOG_MAX_TIME * port->speed; in analog_cooked_read()
252 this = port->mask; in analog_cooked_read()
260 this = gameport_read(gameport) & port->mask; in analog_cooked_read()
274 for (--i; i >= 0; i--) { in analog_cooked_read()
278 port->axes[j] = (delta(start, time[i]) << ANALOG_FUZZ_BITS) / port->loop; in analog_cooked_read()
281 return -(this != port->mask); in analog_cooked_read()
284 static int analog_button_read(struct analog_port *port, char saitek, char chf) in analog_button_read() argument
288 int strobe = gameport_time(port->gameport, ANALOG_SAITEK_TIME); in analog_button_read()
290 u = gameport_read(port->gameport); in analog_button_read()
293 port->buttons = (~u >> 4) & 0xf; in analog_button_read()
297 port->buttons = 0; in analog_button_read()
300 port->buttons |= 1 << analog_chf[(~u >> 4) & 0xf]; in analog_button_read()
304 gameport_trigger(port->gameport); in analog_button_read()
305 while (((u = gameport_read(port->gameport)) & port->mask) && t) t--; in analog_button_read()
309 return -(!t || (i == 16)); in analog_button_read()
318 struct analog_port *port = gameport_get_drvdata(gameport); in analog_poll() local
321 char saitek = !!(port->analog[0].mask & ANALOG_SAITEK); in analog_poll()
322 char chf = !!(port->analog[0].mask & ANALOG_ANY_CHF); in analog_poll()
324 if (port->cooked) { in analog_poll()
325 port->bads -= gameport_cooked_read(port->gameport, port->axes, &port->buttons); in analog_poll()
327 port->buttons = port->buttons ? (1 << analog_chf[port->buttons]) : 0; in analog_poll()
328 port->reads++; in analog_poll()
330 if (!port->axtime--) { in analog_poll()
331 port->bads -= analog_cooked_read(port); in analog_poll()
332 port->bads -= analog_button_read(port, saitek, chf); in analog_poll()
333 port->reads++; in analog_poll()
334 port->axtime = ANALOG_AXIS_TIME - 1; in analog_poll()
337 analog_button_read(port, saitek, chf); in analog_poll()
342 if (port->analog[i].mask) in analog_poll()
343 analog_decode(port->analog + i, port->axes, port->initial, port->buttons); in analog_poll()
352 struct analog_port *port = input_get_drvdata(dev); in analog_open() local
354 gameport_start_polling(port->gameport); in analog_open()
364 struct analog_port *port = input_get_drvdata(dev); in analog_close() local
366 gameport_stop_polling(port->gameport); in analog_close()
371 * and timeout values for a joystick port.
374 static void analog_calibrate_timer(struct analog_port *port) in analog_calibrate_timer() argument
376 struct gameport *gameport = port->gameport; in analog_calibrate_timer()
382 port->speed = 1000000; in analog_calibrate_timer()
394 port->speed = delta(t1, t2) - delta(t2, t3); in analog_calibrate_timer()
409 t = delta(t1, t2) - delta(t2, t3); in analog_calibrate_timer()
413 port->loop = tx / 50; in analog_calibrate_timer()
422 snprintf(analog->name, sizeof(analog->name), "Analog %d-axis %d-button", in analog_name()
423 hweight8(analog->mask & ANALOG_AXES_STD), in analog_name()
424 hweight8(analog->mask & ANALOG_BTNS_STD) + !!(analog->mask & ANALOG_BTNS_CHF) * 2 + in analog_name()
425 hweight16(analog->mask & ANALOG_BTNS_GAMEPAD) + !!(analog->mask & ANALOG_HBTN_CHF) * 4); in analog_name()
427 if (analog->mask & ANALOG_HATS_ALL) in analog_name()
428 snprintf(analog->name, sizeof(analog->name), "%s %d-hat", in analog_name()
429 analog->name, hweight16(analog->mask & ANALOG_HATS_ALL)); in analog_name()
431 if (analog->mask & ANALOG_HAT_FCS) in analog_name()
432 strlcat(analog->name, " FCS", sizeof(analog->name)); in analog_name()
433 if (analog->mask & ANALOG_ANY_CHF) in analog_name()
434 strlcat(analog->name, (analog->mask & ANALOG_SAITEK) ? " Saitek" : " CHF", in analog_name()
435 sizeof(analog->name)); in analog_name()
437 strlcat(analog->name, (analog->mask & ANALOG_GAMEPAD) ? " gamepad": " joystick", in analog_name()
438 sizeof(analog->name)); in analog_name()
445 static int analog_init_device(struct analog_port *port, struct analog *analog, int index) in analog_init_device() argument
452 snprintf(analog->phys, sizeof(analog->phys), in analog_init_device()
453 "%s/input%d", port->gameport->phys, index); in analog_init_device()
454 analog->buttons = (analog->mask & ANALOG_GAMEPAD) ? analog_pad_btn : analog_joy_btn; in analog_init_device()
456 analog->dev = input_dev = input_allocate_device(); in analog_init_device()
458 return -ENOMEM; in analog_init_device()
460 input_dev->name = analog->name; in analog_init_device()
461 input_dev->phys = analog->phys; in analog_init_device()
462 input_dev->id.bustype = BUS_GAMEPORT; in analog_init_device()
463 input_dev->id.vendor = GAMEPORT_ID_VENDOR_ANALOG; in analog_init_device()
464 input_dev->id.product = analog->mask >> 4; in analog_init_device()
465 input_dev->id.version = 0x0100; in analog_init_device()
466 input_dev->dev.parent = &port->gameport->dev; in analog_init_device()
468 input_set_drvdata(input_dev, port); in analog_init_device()
470 input_dev->open = analog_open; in analog_init_device()
471 input_dev->close = analog_close; in analog_init_device()
473 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); in analog_init_device()
476 if (analog->mask & (1 << i)) { in analog_init_device()
479 x = port->axes[i]; in analog_init_device()
480 y = (port->axes[0] + port->axes[1]) >> 1; in analog_init_device()
481 z = y - port->axes[i]; in analog_init_device()
482 z = z > 0 ? z : -z; in analog_init_device()
483 v = (x >> 3); in analog_init_device()
484 w = (x >> 3); in analog_init_device()
486 if ((i == 2 || i == 3) && (j == 2 || j == 3) && (z > (y >> 3))) in analog_init_device()
489 if (analog->mask & ANALOG_SAITEK) { in analog_init_device()
490 if (i == 2) x = port->axes[i]; in analog_init_device()
491 v = x - (x >> 2); in analog_init_device()
495 input_set_abs_params(input_dev, t, v, (x << 1) - v, port->fuzz, w); in analog_init_device()
499 for (i = j = 0; i < 3; i++) in analog_init_device()
500 if (analog->mask & analog_exts[i]) in analog_init_device()
503 input_set_abs_params(input_dev, t, -1, 1, 0, 0); in analog_init_device()
507 if (analog->mask & (0x10 << i)) in analog_init_device()
508 set_bit(analog->buttons[j++], input_dev->keybit); in analog_init_device()
510 if (analog->mask & ANALOG_BTNS_CHF) in analog_init_device()
512 set_bit(analog->buttons[j++], input_dev->keybit); in analog_init_device()
514 if (analog->mask & ANALOG_HBTN_CHF) in analog_init_device()
516 set_bit(analog->buttons[j++], input_dev->keybit); in analog_init_device()
519 if (analog->mask & (ANALOG_BTN_TL << i)) in analog_init_device()
520 set_bit(analog_pads[i], input_dev->keybit); in analog_init_device()
522 analog_decode(analog, port->axes, port->initial, port->buttons); in analog_init_device()
524 error = input_register_device(analog->dev); in analog_init_device()
526 input_free_device(analog->dev); in analog_init_device()
534 * analog_init_devices() sets up device-specific values and registers the input devices.
537 static int analog_init_masks(struct analog_port *port) in analog_init_masks() argument
540 struct analog *analog = port->analog; in analog_init_masks()
543 if (!port->mask) in analog_init_masks()
544 return -1; in analog_init_masks()
546 if ((port->mask & 3) != 3 && port->mask != 0xc) { in analog_init_masks()
549 port->mask, port->gameport->phys); in analog_init_masks()
550 return -1; in analog_init_masks()
554 i = analog_options[0]; /* FIXME !!! - need to specify options for different ports */ in analog_init_masks()
559 | port->mask | ((port->mask << 8) & ANALOG_HAT_FCS) in analog_init_masks()
560 | ((port->mask << 10) & ANALOG_BTNS_TLR) | ((port->mask << 12) & ANALOG_BTNS_TLR2); in analog_init_masks()
577 : (((ANALOG_BTNS_STD | port->mask) & ~analog[0].mask) | ANALOG_GAMEPAD); in analog_init_masks()
579 if (port->cooked) { in analog_init_masks()
581 for (i = 0; i < 4; i++) max[i] = port->axes[i] << 1; in analog_init_masks()
584 if ((analog[0].mask & 0xb) == 0xb) max[3] = (max[0] + max[1]) >> 1; in analog_init_masks()
586 if ((analog[0].mask & ANALOG_BTN_TR) && !(analog[0].mask & ANALOG_BTN_TR2)) max[3] >>= 1; in analog_init_masks()
587 if ((analog[0].mask & ANALOG_HAT_FCS)) max[3] >>= 1; in analog_init_masks()
589 gameport_calibrate(port->gameport, port->axes, max); in analog_init_masks()
593 port->initial[i] = port->axes[i]; in analog_init_masks()
595 return -!(analog[0].mask || analog[1].mask); in analog_init_masks()
598 … analog_init_port(struct gameport *gameport, struct gameport_driver *drv, struct analog_port *port) in analog_init_port() argument
602 port->gameport = gameport; in analog_init_port()
604 gameport_set_drvdata(gameport, port); in analog_init_port()
608 analog_calibrate_timer(port); in analog_init_port()
613 port->mask = (gameport_read(gameport) ^ t) & t & 0xf; in analog_init_port()
614 port->fuzz = (port->speed * ANALOG_FUZZ_MAGIC) / port->loop / 1000 + ANALOG_FUZZ_BITS; in analog_init_port()
617 if (!analog_cooked_read(port)) in analog_init_port()
627 while ((gameport_read(port->gameport) & port->mask) && (u < t)) in analog_init_port()
632 while ((gameport_read(port->gameport) & port->mask) && (v < t)) in analog_init_port()
635 if (v < (u >> 1)) { /* FIXME - more than one port */ in analog_init_port()
636 analog_options[0] |= /* FIXME - more than one port */ in analog_init_port()
647 if (!gameport_cooked_read(gameport, port->axes, &port->buttons)) in analog_init_port()
650 if (port->axes[i] != -1) in analog_init_port()
651 port->mask |= 1 << i; in analog_init_port()
653 port->fuzz = gameport->fuzz; in analog_init_port()
654 port->cooked = 1; in analog_init_port()
663 struct analog_port *port; in analog_connect() local
667 if (!(port = kzalloc(sizeof(struct analog_port), GFP_KERNEL))) in analog_connect()
668 return - ENOMEM; in analog_connect()
670 err = analog_init_port(gameport, drv, port); in analog_connect()
674 err = analog_init_masks(port); in analog_connect()
682 if (port->analog[i].mask) { in analog_connect()
683 err = analog_init_device(port, port->analog + i, i); in analog_connect()
690 fail3: while (--i >= 0) in analog_connect()
691 if (port->analog[i].mask) in analog_connect()
692 input_unregister_device(port->analog[i].dev); in analog_connect()
695 kfree(port); in analog_connect()
701 struct analog_port *port = gameport_get_drvdata(gameport); in analog_disconnect() local
705 if (port->analog[i].mask) in analog_disconnect()
706 input_unregister_device(port->analog[i].dev); in analog_disconnect()
710 port->bads, port->reads, port->reads ? (port->bads * 100 / port->reads) : 0, in analog_disconnect()
711 port->gameport->phys); in analog_disconnect()
712 kfree(port); in analog_disconnect()
724 { "y-joy", 0x0cc00033 },
725 { "y-pad", 0x8cc80033 },
754 printk(KERN_WARNING "analog.c: Bad config for port %d - \"%s\"\n", i, js[i]); in analog_parse_options()