^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) // SPDX-License-Identifier: GPL-2.0-or-later
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 1998-2001 Vojtech Pavlik
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * FP-Gaming Assassin 3D joystick driver for Linux
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/gameport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) #define DRIVER_DESC "FP-Gaming Assassin 3D joystick driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define A3D_MAX_START 600 /* 600 us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define A3D_MAX_STROBE 80 /* 80 us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define A3D_MAX_LENGTH 40 /* 40*3 bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) #define A3D_MODE_A3D 1 /* Assassin 3D */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define A3D_MODE_PAN 2 /* Panther */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) #define A3D_MODE_OEM 3 /* Panther OEM version */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) #define A3D_MODE_PXL 4 /* Panther XL */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) static char *a3d_names[] = { NULL, "FP-Gaming Assassin 3D", "MadCatz Panther", "OEM Panther",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) "MadCatz Panther XL", "MadCatz Panther XL w/ rudder" };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) struct a3d {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) struct gameport *gameport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) struct gameport *adc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) struct input_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) int axes[4];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) int buttons;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) int mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) int length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) int reads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) int bads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) char phys[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) * a3d_read_packet() reads an Assassin 3D packet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) static int a3d_read_packet(struct gameport *gameport, int length, char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) unsigned char u, v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) unsigned int t, s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) t = gameport_time(gameport, A3D_MAX_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) s = gameport_time(gameport, A3D_MAX_STROBE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) gameport_trigger(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) v = gameport_read(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) while (t > 0 && i < length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) t--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) u = v; v = gameport_read(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) if (~v & u & 0x10) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) data[i++] = v >> 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) t = s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) * a3d_csum() computes checksum of triplet packet
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) static int a3d_csum(char *data, int count)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) int i, csum = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) for (i = 0; i < count - 2; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) csum += data[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) return (csum & 0x3f) != ((data[count - 2] << 3) | data[count - 1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) static void a3d_read(struct a3d *a3d, unsigned char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) struct input_dev *dev = a3d->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) switch (a3d->mode) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) case A3D_MODE_A3D:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) case A3D_MODE_OEM:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) case A3D_MODE_PAN:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) input_report_rel(dev, REL_X, ((data[5] << 6) | (data[6] << 3) | data[ 7]) - ((data[5] & 4) << 7));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) input_report_rel(dev, REL_Y, ((data[8] << 6) | (data[9] << 3) | data[10]) - ((data[8] & 4) << 7));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) input_report_key(dev, BTN_RIGHT, data[2] & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) input_report_key(dev, BTN_LEFT, data[3] & 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) input_report_key(dev, BTN_MIDDLE, data[3] & 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) a3d->axes[0] = ((signed char)((data[11] << 6) | (data[12] << 3) | (data[13]))) + 128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) a3d->axes[1] = ((signed char)((data[14] << 6) | (data[15] << 3) | (data[16]))) + 128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) a3d->axes[2] = ((signed char)((data[17] << 6) | (data[18] << 3) | (data[19]))) + 128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) a3d->axes[3] = ((signed char)((data[20] << 6) | (data[21] << 3) | (data[22]))) + 128;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) a3d->buttons = ((data[3] << 3) | data[4]) & 0xf;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) case A3D_MODE_PXL:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) input_report_rel(dev, REL_X, ((data[ 9] << 6) | (data[10] << 3) | data[11]) - ((data[ 9] & 4) << 7));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) input_report_rel(dev, REL_Y, ((data[12] << 6) | (data[13] << 3) | data[14]) - ((data[12] & 4) << 7));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) input_report_key(dev, BTN_RIGHT, data[2] & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) input_report_key(dev, BTN_LEFT, data[3] & 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) input_report_key(dev, BTN_MIDDLE, data[3] & 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) input_report_key(dev, BTN_SIDE, data[7] & 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) input_report_key(dev, BTN_EXTRA, data[7] & 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) input_report_abs(dev, ABS_X, ((signed char)((data[15] << 6) | (data[16] << 3) | (data[17]))) + 128);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) input_report_abs(dev, ABS_Y, ((signed char)((data[18] << 6) | (data[19] << 3) | (data[20]))) + 128);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) input_report_abs(dev, ABS_RUDDER, ((signed char)((data[21] << 6) | (data[22] << 3) | (data[23]))) + 128);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) input_report_abs(dev, ABS_THROTTLE, ((signed char)((data[24] << 6) | (data[25] << 3) | (data[26]))) + 128);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) input_report_abs(dev, ABS_HAT0X, ( data[5] & 1) - ((data[5] >> 2) & 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) input_report_abs(dev, ABS_HAT0Y, ((data[5] >> 1) & 1) - ((data[6] >> 2) & 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) input_report_abs(dev, ABS_HAT1X, ((data[4] >> 1) & 1) - ( data[3] & 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) input_report_abs(dev, ABS_HAT1Y, ((data[4] >> 2) & 1) - ( data[4] & 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) input_report_key(dev, BTN_TRIGGER, data[8] & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) input_report_key(dev, BTN_THUMB, data[8] & 2);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) input_report_key(dev, BTN_TOP, data[8] & 4);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) input_report_key(dev, BTN_PINKIE, data[7] & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) * a3d_poll() reads and analyzes A3D joystick data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) static void a3d_poll(struct gameport *gameport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct a3d *a3d = gameport_get_drvdata(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) unsigned char data[A3D_MAX_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) a3d->reads++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (a3d_read_packet(a3d->gameport, a3d->length, data) != a3d->length ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) data[0] != a3d->mode || a3d_csum(data, a3d->length))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) a3d->bads++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) a3d_read(a3d, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) * a3d_adc_cooked_read() copies the acis and button data to the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) * callers arrays. It could do the read itself, but the caller could
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) * call this more than 50 times a second, which would use too much CPU.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) static int a3d_adc_cooked_read(struct gameport *gameport, int *axes, int *buttons)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) struct a3d *a3d = gameport->port_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) for (i = 0; i < 4; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) axes[i] = (a3d->axes[i] < 254) ? a3d->axes[i] : -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) *buttons = a3d->buttons;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) * a3d_adc_open() is the gameport open routine. It refuses to serve
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) * any but cooked data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) static int a3d_adc_open(struct gameport *gameport, int mode)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) struct a3d *a3d = gameport->port_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) if (mode != GAMEPORT_MODE_COOKED)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) return -1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) gameport_start_polling(a3d->gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) * a3d_adc_close() is a callback from the input close routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) static void a3d_adc_close(struct gameport *gameport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) struct a3d *a3d = gameport->port_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) gameport_stop_polling(a3d->gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) * a3d_open() is a callback from the input open routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static int a3d_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) struct a3d *a3d = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) gameport_start_polling(a3d->gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) * a3d_close() is a callback from the input close routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) static void a3d_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) struct a3d *a3d = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) gameport_stop_polling(a3d->gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) * a3d_connect() probes for A3D joysticks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) static int a3d_connect(struct gameport *gameport, struct gameport_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) struct a3d *a3d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) struct gameport *adc;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) unsigned char data[A3D_MAX_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) a3d = kzalloc(sizeof(struct a3d), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) if (!a3d || !input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) a3d->dev = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) a3d->gameport = gameport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) gameport_set_drvdata(gameport, a3d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) i = a3d_read_packet(gameport, A3D_MAX_LENGTH, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) if (!i || a3d_csum(data, i)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) a3d->mode = data[0];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) if (!a3d->mode || a3d->mode > 5) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) printk(KERN_WARNING "a3d.c: Unknown A3D device detected "
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) "(%s, id=%d), contact <vojtech@ucw.cz>\n", gameport->phys, a3d->mode);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) gameport_set_poll_handler(gameport, a3d_poll);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) gameport_set_poll_interval(gameport, 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) snprintf(a3d->phys, sizeof(a3d->phys), "%s/input0", gameport->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) input_dev->name = a3d_names[a3d->mode];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) input_dev->phys = a3d->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) input_dev->id.bustype = BUS_GAMEPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) input_dev->id.vendor = GAMEPORT_ID_VENDOR_MADCATZ;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) input_dev->id.product = a3d->mode;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) input_dev->id.version = 0x0100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) input_dev->dev.parent = &gameport->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) input_dev->open = a3d_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) input_dev->close = a3d_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) input_set_drvdata(input_dev, a3d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) if (a3d->mode == A3D_MODE_PXL) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) int axes[] = { ABS_X, ABS_Y, ABS_THROTTLE, ABS_RUDDER };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) a3d->length = 33;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) input_dev->evbit[0] |= BIT_MASK(EV_ABS) | BIT_MASK(EV_KEY) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) BIT_MASK(EV_REL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) input_dev->relbit[0] |= BIT_MASK(REL_X) | BIT_MASK(REL_Y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) input_dev->absbit[0] |= BIT_MASK(ABS_X) | BIT_MASK(ABS_Y) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) BIT_MASK(ABS_THROTTLE) | BIT_MASK(ABS_RUDDER) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) BIT_MASK(ABS_HAT0X) | BIT_MASK(ABS_HAT0Y) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) BIT_MASK(ABS_HAT1X) | BIT_MASK(ABS_HAT1Y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) input_dev->keybit[BIT_WORD(BTN_MOUSE)] |= BIT_MASK(BTN_RIGHT) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) BIT_MASK(BTN_SIDE) | BIT_MASK(BTN_EXTRA);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) input_dev->keybit[BIT_WORD(BTN_JOYSTICK)] |=
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) BIT_MASK(BTN_TRIGGER) | BIT_MASK(BTN_THUMB) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) BIT_MASK(BTN_TOP) | BIT_MASK(BTN_PINKIE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) a3d_read(a3d, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) for (i = 0; i < 4; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) if (i < 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) input_set_abs_params(input_dev, axes[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 48, input_abs_get_val(input_dev, axes[i]) * 2 - 48, 0, 8);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) input_set_abs_params(input_dev, axes[i], 2, 253, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) input_set_abs_params(input_dev, ABS_HAT0X + i, -1, 1, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) a3d->length = 29;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) input_dev->evbit[0] |= BIT_MASK(EV_KEY) | BIT_MASK(EV_REL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) input_dev->relbit[0] |= BIT_MASK(REL_X) | BIT_MASK(REL_Y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) input_dev->keybit[BIT_WORD(BTN_MOUSE)] |= BIT_MASK(BTN_RIGHT) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_MIDDLE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) a3d_read(a3d, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) if (!(a3d->adc = adc = gameport_allocate_port()))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) printk(KERN_ERR "a3d: Not enough memory for ADC port\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) adc->port_data = a3d;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) adc->open = a3d_adc_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) adc->close = a3d_adc_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) adc->cooked_read = a3d_adc_cooked_read;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) adc->fuzz = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) gameport_set_name(adc, a3d_names[a3d->mode]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) gameport_set_phys(adc, "%s/gameport0", gameport->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) adc->dev.parent = &gameport->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) gameport_register_port(adc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) err = input_register_device(a3d->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) goto fail3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) fail3: if (a3d->adc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) gameport_unregister_port(a3d->adc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) fail2: gameport_close(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) fail1: gameport_set_drvdata(gameport, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372) input_free_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) kfree(a3d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) static void a3d_disconnect(struct gameport *gameport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) struct a3d *a3d = gameport_get_drvdata(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) input_unregister_device(a3d->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) if (a3d->adc)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) gameport_unregister_port(a3d->adc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) gameport_close(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) gameport_set_drvdata(gameport, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) kfree(a3d);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) static struct gameport_driver a3d_drv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) .name = "adc",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392) .owner = THIS_MODULE,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) .description = DRIVER_DESC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) .connect = a3d_connect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) .disconnect = a3d_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) module_gameport_driver(a3d_drv);