Lines Matching full:sw
96 struct sw { struct
197 #define GB(pos,num) sw_get_bits(buf, pos, num, sw->bits)
283 static int sw_parse(unsigned char *buf, struct sw *sw) in sw_parse() argument
288 switch (sw->type) { in sw_parse()
295 dev = sw->dev[0]; in sw_parse()
317 for (i = 0; i < sw->number; i ++) { in sw_parse()
322 input_report_abs(sw->dev[i], ABS_X, GB(i*15+3,1) - GB(i*15+2,1)); in sw_parse()
323 input_report_abs(sw->dev[i], ABS_Y, GB(i*15+0,1) - GB(i*15+1,1)); in sw_parse()
326 input_report_key(sw->dev[i], sw_btn[SW_ID_GP][j], !GB(i*15+j+4,1)); in sw_parse()
328 input_sync(sw->dev[i]); in sw_parse()
339 dev = sw->dev[0]; in sw_parse()
360 dev = sw->dev[0]; in sw_parse()
385 dev = sw->dev[0]; in sw_parse()
407 static int sw_read(struct sw *sw) in sw_read() argument
412 i = sw_read_packet(sw->gameport, buf, sw->length, 0); in sw_read()
414 if (sw->type == SW_ID_3DP && sw->length == 66 && i != 66) { /* Broken packet, try to fix */ in sw_read()
418 " - going to reinitialize.\n", sw->gameport->phys); in sw_read()
419 sw->fail = SW_FAIL; /* Reinitialize */ in sw_read()
435 if (i == sw->length && !sw_parse(buf, sw)) { /* Parse data */ in sw_read()
437 sw->fail = 0; in sw_read()
438 sw->ok++; in sw_read()
440 if (sw->type == SW_ID_3DP && sw->length == 66 /* Many packets OK */ in sw_read()
441 && sw->ok > SW_OK) { in sw_read()
444 " - enabling optimization again.\n", sw->gameport->phys); in sw_read()
445 sw->length = 22; in sw_read()
451 sw->ok = 0; in sw_read()
452 sw->fail++; in sw_read()
454 if (sw->type == SW_ID_3DP && sw->length == 22 && sw->fail > SW_BAD) { /* Consecutive bad packets */ in sw_read()
457 " - disabling optimization.\n", sw->gameport->phys); in sw_read()
458 sw->length = 66; in sw_read()
461 if (sw->fail < SW_FAIL) in sw_read()
465 " - reinitializing joystick.\n", sw->gameport->phys); in sw_read()
467 if (!i && sw->type == SW_ID_3DP) { /* 3D Pro can be in analog mode */ in sw_read()
469 sw_init_digital(sw->gameport); in sw_read()
473 i = sw_read_packet(sw->gameport, buf, SW_LENGTH, 0); /* Read normal data packet */ in sw_read()
475 sw_read_packet(sw->gameport, buf, SW_LENGTH, i); /* Read ID packet, this initializes the stick */ in sw_read()
477 sw->fail = SW_FAIL; in sw_read()
484 struct sw *sw = gameport_get_drvdata(gameport); in sw_poll() local
486 sw->reads++; in sw_poll()
487 if (sw_read(sw)) in sw_poll()
488 sw->bads++; in sw_poll()
493 struct sw *sw = input_get_drvdata(dev); in sw_open() local
495 gameport_start_polling(sw->gameport); in sw_open()
501 struct sw *sw = input_get_drvdata(dev); in sw_close() local
503 gameport_stop_polling(sw->gameport); in sw_close()
522 * Unfortunately I don't know how to do this for the other SW types.
570 struct sw *sw; in sw_connect() local
581 sw = kzalloc(sizeof(*sw), GFP_KERNEL); in sw_connect()
584 if (!sw || !buf || !idbuf) { in sw_connect()
589 sw->gameport = gameport; in sw_connect()
591 gameport_set_drvdata(gameport, sw); in sw_connect()
634 sw->type = -1; in sw_connect()
648 sw->number = 1; in sw_connect()
649 sw->gameport = gameport; in sw_connect()
650 sw->length = i; in sw_connect()
651 sw->bits = m; in sw_connect()
657 sw->number++; in sw_connect()
663 sw->type = SW_ID_FSP; in sw_connect()
666 sw->number++; in sw_connect()
669 sw->number++; in sw_connect()
672 sw->type = SW_ID_GP; in sw_connect()
676 sw->type = SW_ID_FFW; in sw_connect()
680 sw->type = SW_ID_FFP; in sw_connect()
683 sw->type = SW_ID_PP; in sw_connect()
686 sw->bits = 3; in sw_connect()
689 sw->length = 22; in sw_connect()
692 sw->type = SW_ID_3DP; in sw_connect()
699 } while (k && sw->type == -1); in sw_connect()
701 if (sw->type == -1) { in sw_connect()
721 for (i = 0; i < sw->number; i++) { in sw_connect()
724 snprintf(sw->name, sizeof(sw->name), in sw_connect()
725 "Microsoft SideWinder %s", sw_name[sw->type]); in sw_connect()
726 snprintf(sw->phys[i], sizeof(sw->phys[i]), in sw_connect()
729 sw->dev[i] = input_dev = input_allocate_device(); in sw_connect()
735 input_dev->name = sw->name; in sw_connect()
736 input_dev->phys = sw->phys[i]; in sw_connect()
739 input_dev->id.product = sw->type; in sw_connect()
743 input_set_drvdata(input_dev, sw); in sw_connect()
750 for (j = 0; (bits = sw_bit[sw->type][j]); j++) { in sw_connect()
753 code = sw_abs[sw->type][j]; in sw_connect()
764 for (j = 0; (code = sw_btn[sw->type][j]); j++) in sw_connect()
767 dbg("%s%s [%d-bit id %d data %d]\n", sw->name, comment, m, l, k); in sw_connect()
769 err = input_register_device(sw->dev[i]); in sw_connect()
779 fail4: input_free_device(sw->dev[i]); in sw_connect()
781 input_unregister_device(sw->dev[i]); in sw_connect()
784 kfree(sw); in sw_connect()
790 struct sw *sw = gameport_get_drvdata(gameport); in sw_disconnect() local
793 for (i = 0; i < sw->number; i++) in sw_disconnect()
794 input_unregister_device(sw->dev[i]); in sw_disconnect()
797 kfree(sw); in sw_disconnect()