Lines Matching refs:sw

98 struct sw {
199 #define GB(pos,num) sw_get_bits(buf, pos, num, sw->bits)
285 static int sw_parse(unsigned char *buf, struct sw *sw)
290 switch (sw->type) {
297 dev = sw->dev[0];
319 for (i = 0; i < sw->number; i ++) {
324 input_report_abs(sw->dev[i], ABS_X, GB(i*15+3,1) - GB(i*15+2,1));
325 input_report_abs(sw->dev[i], ABS_Y, GB(i*15+0,1) - GB(i*15+1,1));
328 input_report_key(sw->dev[i], sw_btn[SW_ID_GP][j], !GB(i*15+j+4,1));
330 input_sync(sw->dev[i]);
341 dev = sw->dev[0];
362 dev = sw->dev[0];
387 dev = sw->dev[0];
409 static int sw_read(struct sw *sw)
414 i = sw_read_packet(sw->gameport, buf, sw->length, 0);
416 if (sw->type == SW_ID_3DP && sw->length == 66 && i != 66) { /* Broken packet, try to fix */
420 " - going to reinitialize.\n", sw->gameport->phys);
421 sw->fail = SW_FAIL; /* Reinitialize */
437 if (i == sw->length && !sw_parse(buf, sw)) { /* Parse data */
439 sw->fail = 0;
440 sw->ok++;
442 if (sw->type == SW_ID_3DP && sw->length == 66 /* Many packets OK */
443 && sw->ok > SW_OK) {
446 " - enabling optimization again.\n", sw->gameport->phys);
447 sw->length = 22;
453 sw->ok = 0;
454 sw->fail++;
456 if (sw->type == SW_ID_3DP && sw->length == 22 && sw->fail > SW_BAD) { /* Consecutive bad packets */
459 " - disabling optimization.\n", sw->gameport->phys);
460 sw->length = 66;
463 if (sw->fail < SW_FAIL)
467 " - reinitializing joystick.\n", sw->gameport->phys);
469 if (!i && sw->type == SW_ID_3DP) { /* 3D Pro can be in analog mode */
471 sw_init_digital(sw->gameport);
475 i = sw_read_packet(sw->gameport, buf, SW_LENGTH, 0); /* Read normal data packet */
477 sw_read_packet(sw->gameport, buf, SW_LENGTH, i); /* Read ID packet, this initializes the stick */
479 sw->fail = SW_FAIL;
486 struct sw *sw = gameport_get_drvdata(gameport);
488 sw->reads++;
489 if (sw_read(sw))
490 sw->bads++;
495 struct sw *sw = input_get_drvdata(dev);
497 gameport_start_polling(sw->gameport);
503 struct sw *sw = input_get_drvdata(dev);
505 gameport_stop_polling(sw->gameport);
572 struct sw *sw;
583 sw = kzalloc(sizeof(struct sw), GFP_KERNEL);
586 if (!sw || !buf || !idbuf) {
591 sw->gameport = gameport;
593 gameport_set_drvdata(gameport, sw);
636 sw->type = -1;
650 sw->number = 1;
651 sw->gameport = gameport;
652 sw->length = i;
653 sw->bits = m;
659 sw->number++;
664 sw->type = SW_ID_FSP;
667 sw->number++;
670 sw->number++;
673 sw->type = SW_ID_GP;
677 sw->type = SW_ID_FFW;
681 sw->type = SW_ID_FFP;
684 sw->type = SW_ID_PP;
687 sw->bits = 3;
690 sw->length = 22;
693 sw->type = SW_ID_3DP;
700 } while (k && sw->type == -1);
702 if (sw->type == -1) {
722 for (i = 0; i < sw->number; i++) {
725 snprintf(sw->name, sizeof(sw->name),
726 "Microsoft SideWinder %s", sw_name[sw->type]);
727 snprintf(sw->phys[i], sizeof(sw->phys[i]),
730 sw->dev[i] = input_dev = input_allocate_device();
736 input_dev->name = sw->name;
737 input_dev->phys = sw->phys[i];
740 input_dev->id.product = sw->type;
744 input_set_drvdata(input_dev, sw);
751 for (j = 0; (bits = sw_bit[sw->type][j]); j++) {
754 code = sw_abs[sw->type][j];
765 for (j = 0; (code = sw_btn[sw->type][j]); j++)
768 dbg("%s%s [%d-bit id %d data %d]\n", sw->name, comment, m, l, k);
770 err = input_register_device(sw->dev[i]);
780 fail4: input_free_device(sw->dev[i]);
782 input_unregister_device(sw->dev[i]);
785 kfree(sw);
791 struct sw *sw = gameport_get_drvdata(gameport);
794 for (i = 0; i < sw->number; i++)
795 input_unregister_device(sw->dev[i]);
798 kfree(sw);