Lines Matching +full:strobe +full:- +full:pos

1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Copyright (c) 1998-2005 Vojtech Pavlik
93 } sw_hat_to_axis[] = {{ 0, 0}, { 0,-1}, { 1,-1}, { 1, 0}, { 1, 1}, { 0, 1}, {-1, 1}, {-1, 0}, {-1,-
119 int timeout, bitout, sched, i, kick, start, strobe; in sw_read_packet() local
122 i = -id; /* Don't care about data, only want ID */ in sw_read_packet()
126 strobe = gameport_time(gameport, SW_STROBE); in sw_read_packet()
137 bitout--; in sw_read_packet()
143 bitout = strobe; /* Extend time if not timed out */ in sw_read_packet()
147 timeout--; in sw_read_packet()
148 bitout--; /* Decrement timers */ in sw_read_packet()
149 sched--; in sw_read_packet()
154 if ((~u & v & 0x10) && (bitout > 0)) { /* Rising edge on clock - data bit */ in sw_read_packet()
158 bitout = strobe; /* Extend timeout for next bit */ in sw_read_packet()
167 if (pending && sched < 0 && (i > -SW_END)) { /* Second trigger time */ in sw_read_packet()
175 local_irq_restore(flags); /* Done - relax */ in sw_read_packet()
191 * Parameter 'pos' is bit number inside packet where to start at, 'num' is number
196 #define GB(pos,num) sw_get_bits(buf, pos, num, sw->bits) argument
198 static __u64 sw_get_bits(unsigned char *buf, int pos, int num, char bits) in sw_get_bits() argument
201 int tri = pos % bits; /* Start position */ in sw_get_bits()
202 int i = pos / bits; in sw_get_bits()
205 while (num--) { in sw_get_bits()
233 while ((gameport_read(gameport) & 1) && t) t--; /* Wait for axis to fall back to 0 */ in sw_init_digital()
267 return -1; in sw_check()
287 switch (sw->type) { in sw_parse()
292 return -1; in sw_parse()
294 dev = sw->dev[0]; in sw_parse()
316 for (i = 0; i < sw->number; i ++) { in sw_parse()
319 return -1; in sw_parse()
321 input_report_abs(sw->dev[i], ABS_X, GB(i*15+3,1) - GB(i*15+2,1)); in sw_parse()
322 input_report_abs(sw->dev[i], ABS_Y, GB(i*15+0,1) - GB(i*15+1,1)); in sw_parse()
325 input_report_key(sw->dev[i], sw_btn[SW_ID_GP][j], !GB(i*15+j+4,1)); in sw_parse()
327 input_sync(sw->dev[i]); in sw_parse()
336 return -1; in sw_parse()
338 dev = sw->dev[0]; in sw_parse()
357 return -1; in sw_parse()
359 dev = sw->dev[0]; in sw_parse()
382 return -1; in sw_parse()
384 dev = sw->dev[0]; in sw_parse()
397 return -1; in sw_parse()
411 i = sw_read_packet(sw->gameport, buf, sw->length, 0); in sw_read()
413 if (sw->type == SW_ID_3DP && sw->length == 66 && i != 66) { /* Broken packet, try to fix */ in sw_read()
417 " - going to reinitialize.\n", sw->gameport->phys); in sw_read()
418 sw->fail = SW_FAIL; /* Reinitialize */ in sw_read()
422 if (i < 66 && GB(0,64) == GB(i*3-66,64)) /* 1 == 3 */ in sw_read()
428 if (i < 66 && GB(i*3-132,64) == GB(i*3-66,64)) { /* 2 == 3 */ in sw_read()
429 memmove(buf, buf + i - 22, 22); /* Move data */ in sw_read()
434 if (i == sw->length && !sw_parse(buf, sw)) { /* Parse data */ in sw_read()
436 sw->fail = 0; in sw_read()
437 sw->ok++; in sw_read()
439 if (sw->type == SW_ID_3DP && sw->length == 66 /* Many packets OK */ in sw_read()
440 && sw->ok > SW_OK) { in sw_read()
443 " - enabling optimization again.\n", sw->gameport->phys); in sw_read()
444 sw->length = 22; in sw_read()
450 sw->ok = 0; in sw_read()
451 sw->fail++; in sw_read()
453 if (sw->type == SW_ID_3DP && sw->length == 22 && sw->fail > SW_BAD) { /* Consecutive bad packets */ in sw_read()
456 " - disabling optimization.\n", sw->gameport->phys); in sw_read()
457 sw->length = 66; in sw_read()
460 if (sw->fail < SW_FAIL) in sw_read()
461 return -1; /* Not enough, don't reinitialize yet */ in sw_read()
464 " - reinitializing joystick.\n", sw->gameport->phys); in sw_read()
466 if (!i && sw->type == SW_ID_3DP) { /* 3D Pro can be in analog mode */ in sw_read()
468 sw_init_digital(sw->gameport); in sw_read()
472 i = sw_read_packet(sw->gameport, buf, SW_LENGTH, 0); /* Read normal data packet */ in sw_read()
474 sw_read_packet(sw->gameport, buf, SW_LENGTH, i); /* Read ID packet, this initializes the stick */ in sw_read()
476 sw->fail = SW_FAIL; in sw_read()
478 return -1; in sw_read()
485 sw->reads++; in sw_poll()
487 sw->bads++; in sw_poll()
494 gameport_start_polling(sw->gameport); in sw_open()
502 gameport_stop_polling(sw->gameport); in sw_close()
514 for (i = (((length + 3) >> 2) - 1); i >= 0; i--) in sw_print_packet()
538 (int) ((sw_get_bits(buf, 8, 6, 1) << 6) | /* Two 6-bit values */ in sw_3dp_id()
546 * sw_guess_mode() checks the upper two button bits for toggling -
547 * indication of that the joystick is in 3-bit mode. This is documented
558 xor |= (buf[i - 1] ^ buf[i]) & 6; in sw_guess_mode()
584 err = -ENOMEM; in sw_connect()
588 sw->gameport = gameport; in sw_connect()
597 gameport->phys, gameport->io, gameport->speed); in sw_connect()
609 if (!i) { /* No data -> FAIL */ in sw_connect()
610 err = -ENODEV; in sw_connect()
619 if (j <= 0) { /* Read ID failed. Happens in 1-bit mode on PP */ in sw_connect()
625 err = -ENODEV; in sw_connect()
633 sw->type = -1; in sw_connect()
638 k--; in sw_connect()
647 sw->number = 1; in sw_connect()
648 sw->gameport = gameport; in sw_connect()
649 sw->length = i; in sw_connect()
650 sw->bits = m; in sw_connect()
656 sw->number++; in sw_connect()
659 if (j <= 40) { /* ID length less or eq 40 -> FSP */ in sw_connect()
662 sw->type = SW_ID_FSP; in sw_connect()
665 sw->number++; in sw_connect()
668 sw->number++; in sw_connect()
671 sw->type = SW_ID_GP; in sw_connect()
675 sw->type = SW_ID_FFW; in sw_connect()
678 if (j == 14) { /* ID length 14*3 -> FFP */ in sw_connect()
679 sw->type = SW_ID_FFP; in sw_connect()
682 sw->type = SW_ID_PP; in sw_connect()
685 sw->bits = 3; in sw_connect()
688 sw->length = 22; in sw_connect()
691 sw->type = SW_ID_3DP; in sw_connect()
698 } while (k && sw->type == -1); in sw_connect()
700 if (sw->type == -1) { in sw_connect()
702 "on %s, contact <vojtech@ucw.cz>\n", gameport->phys); in sw_connect()
705 err = -ENODEV; in sw_connect()
720 for (i = 0; i < sw->number; i++) { in sw_connect()
723 snprintf(sw->name, sizeof(sw->name), in sw_connect()
724 "Microsoft SideWinder %s", sw_name[sw->type]); in sw_connect()
725 snprintf(sw->phys[i], sizeof(sw->phys[i]), in sw_connect()
726 "%s/input%d", gameport->phys, i); in sw_connect()
728 sw->dev[i] = input_dev = input_allocate_device(); in sw_connect()
730 err = -ENOMEM; in sw_connect()
734 input_dev->name = sw->name; in sw_connect()
735 input_dev->phys = sw->phys[i]; in sw_connect()
736 input_dev->id.bustype = BUS_GAMEPORT; in sw_connect()
737 input_dev->id.vendor = GAMEPORT_ID_VENDOR_MICROSOFT; in sw_connect()
738 input_dev->id.product = sw->type; in sw_connect()
739 input_dev->id.version = 0x0100; in sw_connect()
740 input_dev->dev.parent = &gameport->dev; in sw_connect()
744 input_dev->open = sw_open; in sw_connect()
745 input_dev->close = sw_close; in sw_connect()
747 input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); in sw_connect()
749 for (j = 0; (bits = sw_bit[sw->type][j]); j++) { in sw_connect()
752 code = sw_abs[sw->type][j]; in sw_connect()
753 min = bits == 1 ? -1 : 0; in sw_connect()
754 max = (1 << bits) - 1; in sw_connect()
755 fuzz = (bits >> 1) >= 2 ? 1 << ((bits >> 1) - 2) : 0; in sw_connect()
757 0 : 1 << (bits - 5); in sw_connect()
763 for (j = 0; (code = sw_btn[sw->type][j]); j++) in sw_connect()
764 __set_bit(code, input_dev->keybit); in sw_connect()
766 dbg("%s%s [%d-bit id %d data %d]\n", sw->name, comment, m, l, k); in sw_connect()
768 err = input_register_device(sw->dev[i]); in sw_connect()
778 fail4: input_free_device(sw->dev[i]); in sw_connect()
779 fail3: while (--i >= 0) in sw_connect()
780 input_unregister_device(sw->dev[i]); in sw_connect()
792 for (i = 0; i < sw->number; i++) in sw_disconnect()
793 input_unregister_device(sw->dev[i]); in sw_disconnect()