^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) 1999-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) * Creative Labs Blaster GamePad Cobra 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 "Creative Labs Blaster GamePad Cobra 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 COBRA_MAX_STROBE 45 /* 45 us max wait for first strobe */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define COBRA_LENGTH 36
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) static int cobra_btn[] = { BTN_START, BTN_SELECT, BTN_TL, BTN_TR, BTN_X, BTN_Y, BTN_Z, BTN_A, BTN_B, BTN_C, BTN_TL2, BTN_TR2, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) struct cobra {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) struct gameport *gameport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) struct input_dev *dev[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) int reads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) int bads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) unsigned char exists;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) char phys[2][32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) static unsigned char cobra_read_packet(struct gameport *gameport, unsigned int *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) unsigned char u, v, w;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44) __u64 buf[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) int r[2], t[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) int i, j, ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) int strobe = gameport_time(gameport, COBRA_MAX_STROBE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) r[i] = buf[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) t[i] = COBRA_MAX_STROBE;
^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) local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) u = gameport_read(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) t[0]--; t[1]--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) v = gameport_read(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) for (i = 0, w = u ^ v; i < 2 && w; i++, w >>= 2)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) if (w & 0x30) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) if ((w & 0x30) < 0x30 && r[i] < COBRA_LENGTH && t[i] > 0) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65) buf[i] |= (__u64)((w >> 5) & 1) << r[i]++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) t[i] = strobe;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) u = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) } else t[i] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70) } while (t[0] > 0 || t[1] > 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) if (r[i] != COBRA_LENGTH) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) for (j = 0; j < COBRA_LENGTH && (buf[i] & 0x04104107f) ^ 0x041041040; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) buf[i] = (buf[i] >> 1) | ((__u64)(buf[i] & 1) << (COBRA_LENGTH - 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) if (j < COBRA_LENGTH) ret |= (1 << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) data[i] = ((buf[i] >> 7) & 0x000001f) | ((buf[i] >> 8) & 0x00003e0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) | ((buf[i] >> 9) & 0x0007c00) | ((buf[i] >> 10) & 0x00f8000)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) | ((buf[i] >> 11) & 0x1f00000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) static void cobra_poll(struct gameport *gameport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) struct cobra *cobra = gameport_get_drvdata(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) struct input_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) unsigned int data[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) int i, j, r;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) cobra->reads++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) if ((r = cobra_read_packet(gameport, data)) != cobra->exists) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) cobra->bads++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) for (i = 0; i < 2; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) if (cobra->exists & r & (1 << i)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) dev = cobra->dev[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) input_report_abs(dev, ABS_X, ((data[i] >> 4) & 1) - ((data[i] >> 3) & 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) input_report_abs(dev, ABS_Y, ((data[i] >> 2) & 1) - ((data[i] >> 1) & 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) for (j = 0; cobra_btn[j]; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) input_report_key(dev, cobra_btn[j], data[i] & (0x20 << j));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) static int cobra_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) struct cobra *cobra = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) gameport_start_polling(cobra->gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) static void cobra_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) struct cobra *cobra = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) gameport_stop_polling(cobra->gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) static int cobra_connect(struct gameport *gameport, struct gameport_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) struct cobra *cobra;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) unsigned int data[2];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) int i, j;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) cobra = kzalloc(sizeof(struct cobra), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) if (!cobra)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) cobra->gameport = gameport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) gameport_set_drvdata(gameport, cobra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) cobra->exists = cobra_read_packet(gameport, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) for (i = 0; i < 2; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) if ((cobra->exists >> i) & data[i] & 1) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) printk(KERN_WARNING "cobra.c: Device %d on %s has the Ext bit set. ID is: %d"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) " Contact vojtech@ucw.cz\n", i, gameport->phys, (data[i] >> 2) & 7);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) cobra->exists &= ~(1 << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) if (!cobra->exists) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) gameport_set_poll_handler(gameport, cobra_poll);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) gameport_set_poll_interval(gameport, 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) for (i = 0; i < 2; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) if (~(cobra->exists >> i) & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) cobra->dev[i] = input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) if (!input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) goto fail3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) snprintf(cobra->phys[i], sizeof(cobra->phys[i]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) "%s/input%d", gameport->phys, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) input_dev->name = "Creative Labs Blaster GamePad Cobra";
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) input_dev->phys = cobra->phys[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) input_dev->id.bustype = BUS_GAMEPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) input_dev->id.vendor = GAMEPORT_ID_VENDOR_CREATIVE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) input_dev->id.product = 0x0008;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) input_dev->id.version = 0x0100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) input_dev->dev.parent = &gameport->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) input_set_drvdata(input_dev, cobra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) input_dev->open = cobra_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) input_dev->close = cobra_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) input_set_abs_params(input_dev, ABS_X, -1, 1, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) input_set_abs_params(input_dev, ABS_Y, -1, 1, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) for (j = 0; cobra_btn[j]; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) set_bit(cobra_btn[j], input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) err = input_register_device(cobra->dev[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) goto fail4;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) fail4: input_free_device(cobra->dev[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) fail3: while (--i >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) if (cobra->dev[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) input_unregister_device(cobra->dev[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) fail2: gameport_close(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) fail1: gameport_set_drvdata(gameport, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) kfree(cobra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) static void cobra_disconnect(struct gameport *gameport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) struct cobra *cobra = gameport_get_drvdata(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) for (i = 0; i < 2; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) if ((cobra->exists >> i) & 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) input_unregister_device(cobra->dev[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) gameport_close(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) gameport_set_drvdata(gameport, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) kfree(cobra);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) static struct gameport_driver cobra_drv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) .driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) .name = "cobra",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) .description = DRIVER_DESC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) .connect = cobra_connect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) .disconnect = cobra_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) module_gameport_driver(cobra_drv);