Lines Matching refs:sw
114 struct sw { struct
215 #define GB(pos,num) sw_get_bits(buf, pos, num, sw->bits)
301 static int sw_parse(unsigned char *buf, struct sw *sw) in sw_parse() argument
306 switch (sw->type) { in sw_parse()
313 dev = sw->dev[0]; in sw_parse()
335 for (i = 0; i < sw->number; i ++) { in sw_parse()
340 input_report_abs(sw->dev[i], ABS_X, GB(i*15+3,1) - GB(i*15+2,1)); in sw_parse()
341 input_report_abs(sw->dev[i], ABS_Y, GB(i*15+0,1) - GB(i*15+1,1)); in sw_parse()
344 input_report_key(sw->dev[i], sw_btn[SW_ID_GP][j], !GB(i*15+j+4,1)); in sw_parse()
346 input_sync(sw->dev[i]); in sw_parse()
357 dev = sw->dev[0]; in sw_parse()
378 dev = sw->dev[0]; in sw_parse()
403 dev = sw->dev[0]; in sw_parse()
425 static int sw_read(struct sw *sw) in sw_read() argument
430 i = sw_read_packet(sw->gameport, buf, sw->length, 0); in sw_read()
432 if (sw->type == SW_ID_3DP && sw->length == 66 && i != 66) { /* Broken packet, try to fix */ in sw_read()
436 " - going to reinitialize.\n", sw->gameport->phys); in sw_read()
437 sw->fail = SW_FAIL; /* Reinitialize */ in sw_read()
453 if (i == sw->length && !sw_parse(buf, sw)) { /* Parse data */ in sw_read()
455 sw->fail = 0; in sw_read()
456 sw->ok++; in sw_read()
458 if (sw->type == SW_ID_3DP && sw->length == 66 /* Many packets OK */ in sw_read()
459 && sw->ok > SW_OK) { in sw_read()
462 " - enabling optimization again.\n", sw->gameport->phys); in sw_read()
463 sw->length = 22; in sw_read()
469 sw->ok = 0; in sw_read()
470 sw->fail++; in sw_read()
472 if (sw->type == SW_ID_3DP && sw->length == 22 && sw->fail > SW_BAD) { /* Consecutive bad packets */ in sw_read()
475 " - disabling optimization.\n", sw->gameport->phys); in sw_read()
476 sw->length = 66; in sw_read()
479 if (sw->fail < SW_FAIL) in sw_read()
483 " - reinitializing joystick.\n", sw->gameport->phys); in sw_read()
485 if (!i && sw->type == SW_ID_3DP) { /* 3D Pro can be in analog mode */ in sw_read()
487 sw_init_digital(sw->gameport); in sw_read()
491 i = sw_read_packet(sw->gameport, buf, SW_LENGTH, 0); /* Read normal data packet */ in sw_read()
493 sw_read_packet(sw->gameport, buf, SW_LENGTH, i); /* Read ID packet, this initializes the stick */ in sw_read()
495 sw->fail = SW_FAIL; in sw_read()
502 struct sw *sw = gameport_get_drvdata(gameport); in sw_poll() local
504 sw->reads++; in sw_poll()
505 if (sw_read(sw)) in sw_poll()
506 sw->bads++; in sw_poll()
511 struct sw *sw = input_get_drvdata(dev); in sw_open() local
513 gameport_start_polling(sw->gameport); in sw_open()
519 struct sw *sw = input_get_drvdata(dev); in sw_close() local
521 gameport_stop_polling(sw->gameport); in sw_close()
588 struct sw *sw; in sw_connect() local
599 sw = kzalloc(sizeof(struct sw), GFP_KERNEL); in sw_connect()
602 if (!sw || !buf || !idbuf) { in sw_connect()
607 sw->gameport = gameport; in sw_connect()
609 gameport_set_drvdata(gameport, sw); in sw_connect()
652 sw->type = -1; in sw_connect()
666 sw->number = 1; in sw_connect()
667 sw->gameport = gameport; in sw_connect()
668 sw->length = i; in sw_connect()
669 sw->bits = m; in sw_connect()
675 sw->number++; in sw_connect()
679 sw->type = SW_ID_FSP; in sw_connect()
682 sw->number++; in sw_connect()
684 sw->number++; in sw_connect()
686 sw->type = SW_ID_GP; in sw_connect()
690 sw->type = SW_ID_FFW; in sw_connect()
694 sw->type = SW_ID_FFP; in sw_connect()
697 sw->type = SW_ID_PP; in sw_connect()
700 sw->bits = 3; in sw_connect()
702 sw->length = 22; in sw_connect()
704 sw->type = SW_ID_3DP; in sw_connect()
711 } while (k && sw->type == -1); in sw_connect()
713 if (sw->type == -1) { in sw_connect()
733 for (i = 0; i < sw->number; i++) { in sw_connect()
736 snprintf(sw->name, sizeof(sw->name), in sw_connect()
737 "Microsoft SideWinder %s", sw_name[sw->type]); in sw_connect()
738 snprintf(sw->phys[i], sizeof(sw->phys[i]), in sw_connect()
741 sw->dev[i] = input_dev = input_allocate_device(); in sw_connect()
747 input_dev->name = sw->name; in sw_connect()
748 input_dev->phys = sw->phys[i]; in sw_connect()
751 input_dev->id.product = sw->type; in sw_connect()
755 input_set_drvdata(input_dev, sw); in sw_connect()
762 for (j = 0; (bits = sw_bit[sw->type][j]); j++) { in sw_connect()
765 code = sw_abs[sw->type][j]; in sw_connect()
776 for (j = 0; (code = sw_btn[sw->type][j]); j++) in sw_connect()
779 dbg("%s%s [%d-bit id %d data %d]\n", sw->name, comment, m, l, k); in sw_connect()
781 err = input_register_device(sw->dev[i]); in sw_connect()
791 fail4: input_free_device(sw->dev[i]); in sw_connect()
793 input_unregister_device(sw->dev[i]); in sw_connect()
796 kfree(sw); in sw_connect()
802 struct sw *sw = gameport_get_drvdata(gameport); in sw_disconnect() local
805 for (i = 0; i < sw->number; i++) in sw_disconnect()
806 input_unregister_device(sw->dev[i]); in sw_disconnect()
809 kfree(sw); in sw_disconnect()