Lines Matching refs:sw

95 struct sw {
196 #define GB(pos,num) sw_get_bits(buf, pos, num, sw->bits)
282 static int sw_parse(unsigned char *buf, struct sw *sw)
287 switch (sw->type) {
294 dev = sw->dev[0];
316 for (i = 0; i < sw->number; i ++) {
321 input_report_abs(sw->dev[i], ABS_X, GB(i*15+3,1) - GB(i*15+2,1));
322 input_report_abs(sw->dev[i], ABS_Y, GB(i*15+0,1) - GB(i*15+1,1));
325 input_report_key(sw->dev[i], sw_btn[SW_ID_GP][j], !GB(i*15+j+4,1));
327 input_sync(sw->dev[i]);
338 dev = sw->dev[0];
359 dev = sw->dev[0];
384 dev = sw->dev[0];
406 static int sw_read(struct sw *sw)
411 i = sw_read_packet(sw->gameport, buf, sw->length, 0);
413 if (sw->type == SW_ID_3DP && sw->length == 66 && i != 66) { /* Broken packet, try to fix */
417 " - going to reinitialize.\n", sw->gameport->phys);
418 sw->fail = SW_FAIL; /* Reinitialize */
434 if (i == sw->length && !sw_parse(buf, sw)) { /* Parse data */
436 sw->fail = 0;
437 sw->ok++;
439 if (sw->type == SW_ID_3DP && sw->length == 66 /* Many packets OK */
440 && sw->ok > SW_OK) {
443 " - enabling optimization again.\n", sw->gameport->phys);
444 sw->length = 22;
450 sw->ok = 0;
451 sw->fail++;
453 if (sw->type == SW_ID_3DP && sw->length == 22 && sw->fail > SW_BAD) { /* Consecutive bad packets */
456 " - disabling optimization.\n", sw->gameport->phys);
457 sw->length = 66;
460 if (sw->fail < SW_FAIL)
464 " - reinitializing joystick.\n", sw->gameport->phys);
466 if (!i && sw->type == SW_ID_3DP) { /* 3D Pro can be in analog mode */
468 sw_init_digital(sw->gameport);
472 i = sw_read_packet(sw->gameport, buf, SW_LENGTH, 0); /* Read normal data packet */
474 sw_read_packet(sw->gameport, buf, SW_LENGTH, i); /* Read ID packet, this initializes the stick */
476 sw->fail = SW_FAIL;
483 struct sw *sw = gameport_get_drvdata(gameport);
485 sw->reads++;
486 if (sw_read(sw))
487 sw->bads++;
492 struct sw *sw = input_get_drvdata(dev);
494 gameport_start_polling(sw->gameport);
500 struct sw *sw = input_get_drvdata(dev);
502 gameport_stop_polling(sw->gameport);
569 struct sw *sw;
580 sw = kzalloc(sizeof(struct sw), GFP_KERNEL);
583 if (!sw || !buf || !idbuf) {
588 sw->gameport = gameport;
590 gameport_set_drvdata(gameport, sw);
633 sw->type = -1;
647 sw->number = 1;
648 sw->gameport = gameport;
649 sw->length = i;
650 sw->bits = m;
656 sw->number++;
662 sw->type = SW_ID_FSP;
665 sw->number++;
668 sw->number++;
671 sw->type = SW_ID_GP;
675 sw->type = SW_ID_FFW;
679 sw->type = SW_ID_FFP;
682 sw->type = SW_ID_PP;
685 sw->bits = 3;
688 sw->length = 22;
691 sw->type = SW_ID_3DP;
698 } while (k && sw->type == -1);
700 if (sw->type == -1) {
720 for (i = 0; i < sw->number; i++) {
723 snprintf(sw->name, sizeof(sw->name),
724 "Microsoft SideWinder %s", sw_name[sw->type]);
725 snprintf(sw->phys[i], sizeof(sw->phys[i]),
728 sw->dev[i] = input_dev = input_allocate_device();
734 input_dev->name = sw->name;
735 input_dev->phys = sw->phys[i];
738 input_dev->id.product = sw->type;
742 input_set_drvdata(input_dev, sw);
749 for (j = 0; (bits = sw_bit[sw->type][j]); j++) {
752 code = sw_abs[sw->type][j];
763 for (j = 0; (code = sw_btn[sw->type][j]); j++)
766 dbg("%s%s [%d-bit id %d data %d]\n", sw->name, comment, m, l, k);
768 err = input_register_device(sw->dev[i]);
778 fail4: input_free_device(sw->dev[i]);
780 input_unregister_device(sw->dev[i]);
783 kfree(sw);
789 struct sw *sw = gameport_get_drvdata(gameport);
792 for (i = 0; i < sw->number; i++)
793 input_unregister_device(sw->dev[i]);
796 kfree(sw);