Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags
^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)  * Genius Flight 2000 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/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/kernel.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/module.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/gameport.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	"Genius Flight 2000 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 GF2K_START		400	/* The time we wait for the first bit [400 us] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define GF2K_STROBE		40	/* The time we wait for the first bit [40 us] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define GF2K_TIMEOUT		4	/* Wait for everything to settle [4 ms] */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define GF2K_LENGTH		80	/* Max number of triplets in a packet */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33)  * Genius joystick ids ...
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define GF2K_ID_G09		1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define GF2K_ID_F30D		2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) #define GF2K_ID_F30		3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define GF2K_ID_F31D		4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define GF2K_ID_F305		5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #define GF2K_ID_F23P		6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define GF2K_ID_F31		7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define GF2K_ID_MAX		7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) static char gf2k_length[] = { 40, 40, 40, 40, 40, 40, 40, 40 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static char gf2k_hat_to_axis[][2] = {{ 0, 0}, { 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  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) static char *gf2k_names[] = {"", "Genius G-09D", "Genius F-30D", "Genius F-30", "Genius MaxFighter F-31D",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 				"Genius F-30-5", "Genius Flight2000 F-23", "Genius F-31"};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) static unsigned char gf2k_hats[] = { 0, 2, 0, 0, 2, 0, 2, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) static unsigned char gf2k_axes[] = { 0, 2, 0, 0, 4, 0, 4, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static unsigned char gf2k_joys[] = { 0, 0, 0, 0,10, 0, 8, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) static unsigned char gf2k_pads[] = { 0, 6, 0, 0, 0, 0, 0, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static unsigned char gf2k_lens[] = { 0,18, 0, 0,18, 0,18, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) static unsigned char gf2k_abs[] = { ABS_X, ABS_Y, ABS_THROTTLE, ABS_RUDDER, ABS_GAS, ABS_BRAKE };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) static short gf2k_btn_joy[] = { BTN_TRIGGER, BTN_THUMB, BTN_TOP, BTN_TOP2, BTN_BASE, BTN_BASE2, BTN_BASE3, BTN_BASE4 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static short gf2k_btn_pad[] = { BTN_A, BTN_B, BTN_C, BTN_X, BTN_Y, BTN_Z, BTN_TL, BTN_TR, BTN_TL2, BTN_TR2, BTN_START, BTN_SELECT };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) static short gf2k_seq_reset[] = { 240, 340, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) static short gf2k_seq_digital[] = { 590, 320, 860, 0 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) struct gf2k {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	struct gameport *gameport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct input_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	int reads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	int bads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	unsigned char id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	unsigned char length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	char phys[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75)  * gf2k_read_packet() reads a Genius Flight2000 packet.
^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) static int gf2k_read_packet(struct gameport *gameport, int length, char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	unsigned char u, v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	unsigned int t, p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	t = gameport_time(gameport, GF2K_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	p = gameport_time(gameport, GF2K_STROBE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 	local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 	gameport_trigger(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 	v = gameport_read(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 	while (t > 0 && i < length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 		t--; u = v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 		v = gameport_read(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 		if (v & ~u & 0x10) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			data[i++] = v >> 5;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			t = p;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	return i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  * gf2k_trigger_seq() initializes a Genius Flight2000 joystick
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111)  * into digital mode.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) static void gf2k_trigger_seq(struct gameport *gameport, short *seq)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	int i, t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120)         local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123)         do {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		gameport_trigger(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		t = gameport_time(gameport, GF2K_TIMEOUT * 1000);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		while ((gameport_read(gameport) & 1) && t) t--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127)                 udelay(seq[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128)         } while (seq[++i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	gameport_trigger(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 	local_irq_restore(flags);
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136)  * js_sw_get_bits() composes bits from the triplet buffer into a __u64.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137)  * Parameter 'pos' is bit number inside packet where to start at, 'num' is number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138)  * of bits to be read, 'shift' is offset in the resulting __u64 to start at, bits
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139)  * is number of bits per triplet.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) #define GB(p,n,s)	gf2k_get_bits(data, p, n, s)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static int gf2k_get_bits(unsigned char *buf, int pos, int num, int shift)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	__u64 data = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	for (i = 0; i < num / 3 + 2; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 		data |= buf[pos / 3 + i] << (i * 3);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	data >>= pos % 3;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 	data &= (1 << num) - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	data <<= shift;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	return data;
^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) static void gf2k_read(struct gf2k *gf2k, unsigned char *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	struct input_dev *dev = gf2k->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	int i, t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 	for (i = 0; i < 4 && i < gf2k_axes[gf2k->id]; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 		input_report_abs(dev, gf2k_abs[i], GB(i<<3,8,0) | GB(i+46,1,8) | GB(i+50,1,9));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	for (i = 0; i < 2 && i < gf2k_axes[gf2k->id] - 4; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		input_report_abs(dev, gf2k_abs[i], GB(i*9+60,8,0) | GB(i+54,1,9));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	t = GB(40,4,0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	for (i = 0; i < gf2k_hats[gf2k->id]; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 		input_report_abs(dev, ABS_HAT0X + i, gf2k_hat_to_axis[t][i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 	t = GB(44,2,0) | GB(32,8,2) | GB(78,2,10);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	for (i = 0; i < gf2k_joys[gf2k->id]; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 		input_report_key(dev, gf2k_btn_joy[i], (t >> i) & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	for (i = 0; i < gf2k_pads[gf2k->id]; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		input_report_key(dev, gf2k_btn_pad[i], (t >> i) & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) }
^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)  * gf2k_poll() reads and analyzes Genius joystick data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) static void gf2k_poll(struct gameport *gameport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 	struct gf2k *gf2k = gameport_get_drvdata(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	unsigned char data[GF2K_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	gf2k->reads++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	if (gf2k_read_packet(gf2k->gameport, gf2k_length[gf2k->id], data) < gf2k_length[gf2k->id])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 		gf2k->bads++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		gf2k_read(gf2k, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) static int gf2k_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 	struct gf2k *gf2k = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	gameport_start_polling(gf2k->gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) static void gf2k_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 	struct gf2k *gf2k = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	gameport_stop_polling(gf2k->gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218)  * gf2k_connect() probes for Genius id joysticks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) static int gf2k_connect(struct gameport *gameport, struct gameport_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 	struct gf2k *gf2k;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	unsigned char data[GF2K_LENGTH];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 	int i, err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 	gf2k = kzalloc(sizeof(struct gf2k), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 	if (!gf2k || !input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 		goto fail1;
^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) 	gf2k->gameport = gameport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	gf2k->dev = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	gameport_set_drvdata(gameport, gf2k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	gf2k_trigger_seq(gameport, gf2k_seq_reset);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	msleep(GF2K_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	gf2k_trigger_seq(gameport, gf2k_seq_digital);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	msleep(GF2K_TIMEOUT);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	if (gf2k_read_packet(gameport, GF2K_LENGTH, data) < 12) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	if (!(gf2k->id = GB(7,2,0) | GB(3,3,2) | GB(0,3,5))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		goto fail2;
^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) #ifdef RESET_WORKS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	if ((gf2k->id != (GB(19,2,0) | GB(15,3,2) | GB(12,3,5))) &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	    (gf2k->id != (GB(31,2,0) | GB(27,3,2) | GB(24,3,5)))) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	gf2k->id = 6;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	if (gf2k->id > GF2K_ID_MAX || !gf2k_axes[gf2k->id]) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		printk(KERN_WARNING "gf2k.c: Not yet supported joystick on %s. [id: %d type:%s]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 			gameport->phys, gf2k->id, gf2k->id > GF2K_ID_MAX ? "Unknown" : gf2k_names[gf2k->id]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 		err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	gameport_set_poll_handler(gameport, gf2k_poll);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	gameport_set_poll_interval(gameport, 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	snprintf(gf2k->phys, sizeof(gf2k->phys), "%s/input0", gameport->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	gf2k->length = gf2k_lens[gf2k->id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	input_dev->name = gf2k_names[gf2k->id];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	input_dev->phys = gf2k->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	input_dev->id.bustype = BUS_GAMEPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	input_dev->id.vendor = GAMEPORT_ID_VENDOR_GENIUS;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	input_dev->id.product = gf2k->id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	input_dev->id.version = 0x0100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	input_dev->dev.parent = &gameport->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	input_set_drvdata(input_dev, gf2k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	input_dev->open = gf2k_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	input_dev->close = gf2k_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	for (i = 0; i < gf2k_axes[gf2k->id]; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 		set_bit(gf2k_abs[i], input_dev->absbit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) 	for (i = 0; i < gf2k_hats[gf2k->id]; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 		input_set_abs_params(input_dev, ABS_HAT0X + i, -1, 1, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) 	for (i = 0; i < gf2k_joys[gf2k->id]; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 		set_bit(gf2k_btn_joy[i], input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 	for (i = 0; i < gf2k_pads[gf2k->id]; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) 		set_bit(gf2k_btn_pad[i], input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) 	gf2k_read_packet(gameport, gf2k->length, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) 	gf2k_read(gf2k, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) 	for (i = 0; i < gf2k_axes[gf2k->id]; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) 		int max = i < 2 ?
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) 			input_abs_get_val(input_dev, gf2k_abs[i]) * 2 :
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) 			input_abs_get_val(input_dev, gf2k_abs[0]) +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) 				input_abs_get_val(input_dev, gf2k_abs[1]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) 		int flat = i < 2 ? 24 : 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) 		input_set_abs_params(input_dev, gf2k_abs[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) 				     32, max - 32, 8, flat);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) 	err = input_register_device(gf2k->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) 		goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333)  fail2:	gameport_close(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334)  fail1:	gameport_set_drvdata(gameport, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) 	input_free_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) 	kfree(gf2k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337) 	return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) static void gf2k_disconnect(struct gameport *gameport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) 	struct gf2k *gf2k = gameport_get_drvdata(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) 	input_unregister_device(gf2k->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345) 	gameport_close(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) 	gameport_set_drvdata(gameport, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) 	kfree(gf2k);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) static struct gameport_driver gf2k_drv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352) 		.name	= "gf2k",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) 	.description	= DRIVER_DESC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) 	.connect	= gf2k_connect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) 	.disconnect	= gf2k_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) module_gameport_driver(gf2k_drv);