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

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 1996-2001 Vojtech Pavlik
69 #define ANALOG_MAX_TIME 3 /* 3 ms */
121 struct input_dev *dev = analog->dev; in analog_decode()
124 if (analog->mask & ANALOG_HAT_FCS) in analog_decode()
126 if (axes[3] < ((initial[3] * ((i << 1) + 1)) >> 3)) { in analog_decode()
132 if (analog->mask & (0x10 << i)) in analog_decode()
133 input_report_key(dev, analog->buttons[j++], (buttons >> i) & 1); in analog_decode()
135 if (analog->mask & ANALOG_HBTN_CHF) in analog_decode()
137 input_report_key(dev, analog->buttons[j++], (buttons >> (i + 10)) & 1); in analog_decode()
139 if (analog->mask & ANALOG_BTN_TL) in analog_decode()
141 if (analog->mask & ANALOG_BTN_TR) in analog_decode()
142 input_report_key(dev, analog_pads[1], axes[3] < (initial[3] >> 1)); in analog_decode()
143 if (analog->mask & ANALOG_BTN_TL2) in analog_decode()
145 if (analog->mask & ANALOG_BTN_TR2) in analog_decode()
146 input_report_key(dev, analog_pads[3], axes[3] > (initial[3] + (initial[3] >> 1))); in analog_decode()
149 if (analog->mask & (1 << i)) in analog_decode()
152 for (i = j = 0; i < 3; i++) in analog_decode()
153 if (analog->mask & analog_exts[i]) { in analog_decode()
155 ((buttons >> ((i << 2) + 7)) & 1) - ((buttons >> ((i << 2) + 9)) & 1)); in analog_decode()
157 ((buttons >> ((i << 2) + 8)) & 1) - ((buttons >> ((i << 2) + 6)) & 1)); in analog_decode()
167 static int analog_cooked_read(struct analog_port *port) in analog_cooked_read() argument
169 struct gameport *gameport = port->gameport; in analog_cooked_read()
176 loopout = (ANALOG_LOOP_TIME * port->loop) / 1000; in analog_cooked_read()
185 this = port->mask; in analog_cooked_read()
193 this = gameport_read(gameport) & port->mask; in analog_cooked_read()
207 for (--i; i >= 0; i--) { in analog_cooked_read()
211 port->axes[j] = ((u32)ktime_sub(time[i], start) << ANALOG_FUZZ_BITS) / port->loop; in analog_cooked_read()
214 return -(this != port->mask); in analog_cooked_read()
217 static int analog_button_read(struct analog_port *port, char saitek, char chf) in analog_button_read() argument
221 int strobe = gameport_time(port->gameport, ANALOG_SAITEK_TIME); in analog_button_read()
223 u = gameport_read(port->gameport); in analog_button_read()
226 port->buttons = (~u >> 4) & 0xf; in analog_button_read()
230 port->buttons = 0; in analog_button_read()
233 port->buttons |= 1 << analog_chf[(~u >> 4) & 0xf]; in analog_button_read()
237 gameport_trigger(port->gameport); in analog_button_read()
238 while (((u = gameport_read(port->gameport)) & port->mask) && t) t--; in analog_button_read()
242 return -(!t || (i == 16)); in analog_button_read()
251 struct analog_port *port = gameport_get_drvdata(gameport); in analog_poll() local
254 char saitek = !!(port->analog[0].mask & ANALOG_SAITEK); in analog_poll()
255 char chf = !!(port->analog[0].mask & ANALOG_ANY_CHF); in analog_poll()
257 if (port->cooked) { in analog_poll()
258 port->bads -= gameport_cooked_read(port->gameport, port->axes, &port->buttons); in analog_poll()
260 port->buttons = port->buttons ? (1 << analog_chf[port->buttons]) : 0; in analog_poll()
261 port->reads++; in analog_poll()
263 if (!port->axtime--) { in analog_poll()
264 port->bads -= analog_cooked_read(port); in analog_poll()
265 port->bads -= analog_button_read(port, saitek, chf); in analog_poll()
266 port->reads++; in analog_poll()
267 port->axtime = ANALOG_AXIS_TIME - 1; in analog_poll()
270 analog_button_read(port, saitek, chf); in analog_poll()
275 if (port->analog[i].mask) in analog_poll()
276 analog_decode(port->analog + i, port->axes, port->initial, port->buttons); in analog_poll()
285 struct analog_port *port = input_get_drvdata(dev); in analog_open() local
287 gameport_start_polling(port->gameport); in analog_open()
297 struct analog_port *port = input_get_drvdata(dev); in analog_close() local
299 gameport_stop_polling(port->gameport); in analog_close()
304 * and timeout values for a joystick port.
307 static void analog_calibrate_timer(struct analog_port *port) in analog_calibrate_timer() argument
309 struct gameport *gameport = port->gameport; in analog_calibrate_timer()
326 t = ktime_sub(t2, t1) - ktime_sub(t3, t2); in analog_calibrate_timer()
330 port->loop = tx / 50; in analog_calibrate_timer()
341 seq_buf_init(&s, analog->name, sizeof(analog->name)); in analog_name()
342 seq_buf_printf(&s, "Analog %d-axis %d-button", in analog_name()
343 hweight8(analog->mask & ANALOG_AXES_STD), in analog_name()
344 hweight8(analog->mask & ANALOG_BTNS_STD) + !!(analog->mask & ANALOG_BTNS_CHF) * 2 + in analog_name()
345 hweight16(analog->mask & ANALOG_BTNS_GAMEPAD) + !!(analog->mask & ANALOG_HBTN_CHF) * 4); in analog_name()
347 if (analog->mask & ANALOG_HATS_ALL) in analog_name()
348 seq_buf_printf(&s, " %d-hat", in analog_name()
349 hweight16(analog->mask & ANALOG_HATS_ALL)); in analog_name()
351 if (analog->mask & ANALOG_HAT_FCS) in analog_name()
353 if (analog->mask & ANALOG_ANY_CHF) in analog_name()
354 seq_buf_printf(&s, (analog->mask & ANALOG_SAITEK) ? " Saitek" : " CHF"); in analog_name()
356 seq_buf_printf(&s, (analog->mask & ANALOG_GAMEPAD) ? " gamepad" : " joystick"); in analog_name()
363 static int analog_init_device(struct analog_port *port, struct analog *analog, int index) in analog_init_device() argument
370 snprintf(analog->phys, sizeof(analog->phys), in analog_init_device()
371 "%s/input%d", port->gameport->phys, index); in analog_init_device()
372 analog->buttons = (analog->mask & ANALOG_GAMEPAD) ? analog_pad_btn : analog_joy_btn; in analog_init_device()
374 analog->dev = input_dev = input_allocate_device(); in analog_init_device()
376 return -ENOMEM; in analog_init_device()
378 input_dev->name = analog->name; in analog_init_device()
379 input_dev->phys = analog->phys; in analog_init_device()
380 input_dev->id.bustype = BUS_GAMEPORT; in analog_init_device()
381 input_dev->id.vendor = GAMEPORT_ID_VENDOR_ANALOG; in analog_init_device()
382 input_dev->id.product = analog->mask >> 4; in analog_init_device()
383 input_dev->id.version = 0x0100; in analog_init_device()
384 input_dev->dev.parent = &port->gameport->dev; in analog_init_device()
386 input_set_drvdata(input_dev, port); in analog_init_device()
388 input_dev->open = analog_open; in analog_init_device()
389 input_dev->close = analog_close; in analog_init_device()
391 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); in analog_init_device()
394 if (analog->mask & (1 << i)) { in analog_init_device()
397 x = port->axes[i]; in analog_init_device()
398 y = (port->axes[0] + port->axes[1]) >> 1; in analog_init_device()
399 z = y - port->axes[i]; in analog_init_device()
400 z = z > 0 ? z : -z; in analog_init_device()
401 v = (x >> 3); in analog_init_device()
402 w = (x >> 3); in analog_init_device()
404 if ((i == 2 || i == 3) && (j == 2 || j == 3) && (z > (y >> 3))) in analog_init_device()
407 if (analog->mask & ANALOG_SAITEK) { in analog_init_device()
408 if (i == 2) x = port->axes[i]; in analog_init_device()
409 v = x - (x >> 2); in analog_init_device()
413 input_set_abs_params(input_dev, t, v, (x << 1) - v, port->fuzz, w); in analog_init_device()
417 for (i = j = 0; i < 3; i++) in analog_init_device()
418 if (analog->mask & analog_exts[i]) in analog_init_device()
421 input_set_abs_params(input_dev, t, -1, 1, 0, 0); in analog_init_device()
425 if (analog->mask & (0x10 << i)) in analog_init_device()
426 set_bit(analog->buttons[j++], input_dev->keybit); in analog_init_device()
428 if (analog->mask & ANALOG_BTNS_CHF) in analog_init_device()
430 set_bit(analog->buttons[j++], input_dev->keybit); in analog_init_device()
432 if (analog->mask & ANALOG_HBTN_CHF) in analog_init_device()
434 set_bit(analog->buttons[j++], input_dev->keybit); in analog_init_device()
437 if (analog->mask & (ANALOG_BTN_TL << i)) in analog_init_device()
438 set_bit(analog_pads[i], input_dev->keybit); in analog_init_device()
440 analog_decode(analog, port->axes, port->initial, port->buttons); in analog_init_device()
442 error = input_register_device(analog->dev); in analog_init_device()
444 input_free_device(analog->dev); in analog_init_device()
452 * analog_init_devices() sets up device-specific values and registers the input devices.
455 static int analog_init_masks(struct analog_port *port) in analog_init_masks() argument
458 struct analog *analog = port->analog; in analog_init_masks()
461 if (!port->mask) in analog_init_masks()
462 return -1; in analog_init_masks()
464 if ((port->mask & 3) != 3 && port->mask != 0xc) { in analog_init_masks()
467 port->mask, port->gameport->phys); in analog_init_masks()
468 return -1; in analog_init_masks()
472 i = analog_options[0]; /* FIXME !!! - need to specify options for different ports */ in analog_init_masks()
477 | port->mask | ((port->mask << 8) & ANALOG_HAT_FCS) in analog_init_masks()
478 | ((port->mask << 10) & ANALOG_BTNS_TLR) | ((port->mask << 12) & ANALOG_BTNS_TLR2); in analog_init_masks()
495 : (((ANALOG_BTNS_STD | port->mask) & ~analog[0].mask) | ANALOG_GAMEPAD); in analog_init_masks()
497 if (port->cooked) { in analog_init_masks()
499 for (i = 0; i < 4; i++) max[i] = port->axes[i] << 1; in analog_init_masks()
502 if ((analog[0].mask & 0xb) == 0xb) max[3] = (max[0] + max[1]) >> 1; in analog_init_masks()
504 if ((analog[0].mask & ANALOG_BTN_TR) && !(analog[0].mask & ANALOG_BTN_TR2)) max[3] >>= 1; in analog_init_masks()
505 if ((analog[0].mask & ANALOG_HAT_FCS)) max[3] >>= 1; in analog_init_masks()
507 gameport_calibrate(port->gameport, port->axes, max); in analog_init_masks()
511 port->initial[i] = port->axes[i]; in analog_init_masks()
513 return -!(analog[0].mask || analog[1].mask); in analog_init_masks()
516 … analog_init_port(struct gameport *gameport, struct gameport_driver *drv, struct analog_port *port) in analog_init_port() argument
520 port->gameport = gameport; in analog_init_port()
522 gameport_set_drvdata(gameport, port); in analog_init_port()
526 analog_calibrate_timer(port); in analog_init_port()
531 port->mask = (gameport_read(gameport) ^ t) & t & 0xf; in analog_init_port()
532 port->fuzz = (NSEC_PER_MSEC * ANALOG_FUZZ_MAGIC) / port->loop / 1000 + ANALOG_FUZZ_BITS; in analog_init_port()
535 if (!analog_cooked_read(port)) in analog_init_port()
545 while ((gameport_read(port->gameport) & port->mask) && (u < t)) in analog_init_port()
550 while ((gameport_read(port->gameport) & port->mask) && (v < t)) in analog_init_port()
553 if (v < (u >> 1)) { /* FIXME - more than one port */ in analog_init_port()
554 analog_options[0] |= /* FIXME - more than one port */ in analog_init_port()
565 if (!gameport_cooked_read(gameport, port->axes, &port->buttons)) in analog_init_port()
568 if (port->axes[i] != -1) in analog_init_port()
569 port->mask |= 1 << i; in analog_init_port()
571 port->fuzz = gameport->fuzz; in analog_init_port()
572 port->cooked = 1; in analog_init_port()
581 struct analog_port *port; in analog_connect() local
585 port = kzalloc(sizeof(*port), GFP_KERNEL); in analog_connect()
586 if (!port) in analog_connect()
587 return -ENOMEM; in analog_connect()
589 err = analog_init_port(gameport, drv, port); in analog_connect()
593 err = analog_init_masks(port); in analog_connect()
601 if (port->analog[i].mask) { in analog_connect()
602 err = analog_init_device(port, port->analog + i, i); in analog_connect()
609 fail3: while (--i >= 0) in analog_connect()
610 if (port->analog[i].mask) in analog_connect()
611 input_unregister_device(port->analog[i].dev); in analog_connect()
614 kfree(port); in analog_connect()
620 struct analog_port *port = gameport_get_drvdata(gameport); in analog_disconnect() local
624 if (port->analog[i].mask) in analog_disconnect()
625 input_unregister_device(port->analog[i].dev); in analog_disconnect()
629 port->bads, port->reads, port->reads ? (port->bads * 100 / port->reads) : 0, in analog_disconnect()
630 port->gameport->phys); in analog_disconnect()
631 kfree(port); in analog_disconnect()
643 { "y-joy", 0x0cc00033 },
644 { "y-pad", 0x8cc80033 },
673 printk(KERN_WARNING "analog.c: Bad config for port %d - \"%s\"\n", i, js[i]); in analog_parse_options()