^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) 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) * Guillemot Digital Interface Protocol 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/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #include <linux/gameport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) #define DRIVER_DESC "Guillemot Digital joystick driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define GUILLEMOT_MAX_START 600 /* 600 us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define GUILLEMOT_MAX_STROBE 60 /* 60 us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define GUILLEMOT_MAX_LENGTH 17 /* 17 bytes */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) static short guillemot_abs_pad[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) { ABS_X, ABS_Y, ABS_THROTTLE, ABS_RUDDER, -1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) static short guillemot_btn_pad[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_MODE, BTN_SELECT, -1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) static struct {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) int x;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) int y;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) } guillemot_hat_to_axis[16] = {{ 0,-1}, { 1,-1}, { 1, 0}, { 1, 1}, { 0, 1}, {-1, 1}, {-1, 0}, {-1,-1}};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) struct guillemot_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) unsigned char id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) short *abs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) short *btn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) int hat;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) struct guillemot {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) struct gameport *gameport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) struct input_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) int bads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) int reads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) struct guillemot_type *type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) unsigned char length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) char phys[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) static struct guillemot_type guillemot_type[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) { 0x00, guillemot_abs_pad, guillemot_btn_pad, 1, "Guillemot Pad" },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) { 0 }};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) * guillemot_read_packet() reads Guillemot joystick data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) static int guillemot_read_packet(struct gameport *gameport, u8 *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) unsigned char u, v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) unsigned int t, s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) for (i = 0; i < GUILLEMOT_MAX_LENGTH; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) data[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) t = gameport_time(gameport, GUILLEMOT_MAX_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) s = gameport_time(gameport, GUILLEMOT_MAX_STROBE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) gameport_trigger(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) v = gameport_read(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) while (t > 0 && i < GUILLEMOT_MAX_LENGTH * 8) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) t--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) u = v; v = gameport_read(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) if (v & ~u & 0x10) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) data[i >> 3] |= ((v >> 5) & 1) << (i & 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) t = s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) * guillemot_poll() reads and analyzes Guillemot joystick data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) static void guillemot_poll(struct gameport *gameport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) struct guillemot *guillemot = gameport_get_drvdata(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) struct input_dev *dev = guillemot->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) u8 data[GUILLEMOT_MAX_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) guillemot->reads++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) if (guillemot_read_packet(guillemot->gameport, data) != GUILLEMOT_MAX_LENGTH * 8 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) data[0] != 0x55 || data[16] != 0xaa) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) guillemot->bads++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) } else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) for (i = 0; i < 6 && guillemot->type->abs[i] >= 0; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) input_report_abs(dev, guillemot->type->abs[i], data[i + 5]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) if (guillemot->type->hat) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) input_report_abs(dev, ABS_HAT0X, guillemot_hat_to_axis[data[4] >> 4].x);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) input_report_abs(dev, ABS_HAT0Y, guillemot_hat_to_axis[data[4] >> 4].y);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) for (i = 0; i < 16 && guillemot->type->btn[i] >= 0; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) input_report_key(dev, guillemot->type->btn[i], (data[2 + (i >> 3)] >> (i & 7)) & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * guillemot_open() is a callback from the input open routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) static int guillemot_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) struct guillemot *guillemot = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) gameport_start_polling(guillemot->gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) * guillemot_close() is a callback from the input close routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) static void guillemot_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) struct guillemot *guillemot = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) gameport_stop_polling(guillemot->gameport);
^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) * guillemot_connect() probes for Guillemot joysticks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) static int guillemot_connect(struct gameport *gameport, struct gameport_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) struct guillemot *guillemot;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) u8 data[GUILLEMOT_MAX_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) int i, t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) guillemot = kzalloc(sizeof(struct guillemot), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) if (!guillemot || !input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) goto fail1;
^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) guillemot->gameport = gameport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) guillemot->dev = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) gameport_set_drvdata(gameport, guillemot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) i = guillemot_read_packet(gameport, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) if (i != GUILLEMOT_MAX_LENGTH * 8 || data[0] != 0x55 || data[16] != 0xaa) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) goto fail2;
^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) for (i = 0; guillemot_type[i].name; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) if (guillemot_type[i].id == data[11])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) if (!guillemot_type[i].name) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) printk(KERN_WARNING "guillemot.c: Unknown joystick on %s. [ %02x%02x:%04x, ver %d.%02d ]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) gameport->phys, data[12], data[13], data[11], data[14], data[15]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) gameport_set_poll_handler(gameport, guillemot_poll);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) gameport_set_poll_interval(gameport, 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) snprintf(guillemot->phys, sizeof(guillemot->phys), "%s/input0", gameport->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) guillemot->type = guillemot_type + i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) input_dev->name = guillemot_type[i].name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) input_dev->phys = guillemot->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) input_dev->id.bustype = BUS_GAMEPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) input_dev->id.vendor = GAMEPORT_ID_VENDOR_GUILLEMOT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) input_dev->id.product = guillemot_type[i].id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) input_dev->id.version = (int)data[14] << 8 | data[15];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) input_dev->dev.parent = &gameport->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) input_set_drvdata(input_dev, guillemot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) input_dev->open = guillemot_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) input_dev->close = guillemot_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) for (i = 0; (t = guillemot->type->abs[i]) >= 0; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) input_set_abs_params(input_dev, t, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) if (guillemot->type->hat) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) input_set_abs_params(input_dev, ABS_HAT0X, -1, 1, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) input_set_abs_params(input_dev, ABS_HAT0Y, -1, 1, 0, 0);
^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) for (i = 0; (t = guillemot->type->btn[i]) >= 0; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) set_bit(t, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) err = input_register_device(guillemot->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) fail2: gameport_close(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) fail1: gameport_set_drvdata(gameport, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) input_free_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) kfree(guillemot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) static void guillemot_disconnect(struct gameport *gameport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) struct guillemot *guillemot = gameport_get_drvdata(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) printk(KERN_INFO "guillemot.c: Failed %d reads out of %d on %s\n", guillemot->reads, guillemot->bads, guillemot->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) input_unregister_device(guillemot->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) gameport_close(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) kfree(guillemot);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) static struct gameport_driver guillemot_drv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) .name = "guillemot",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) .description = DRIVER_DESC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) .connect = guillemot_connect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) .disconnect = guillemot_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) module_gameport_driver(guillemot_drv);