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) 2001 Vojtech Pavlik
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Based on the work of:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *	Toby Deshane
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  */
^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)  * InterAct digital gamepad/joystick driver for Linux
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/delay.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/gameport.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/input.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/jiffies.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) #define DRIVER_DESC	"InterAct digital joystick driver"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) MODULE_DESCRIPTION(DRIVER_DESC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #define INTERACT_MAX_START	600	/* 400 us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define INTERACT_MAX_STROBE	60	/* 40 us */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define INTERACT_MAX_LENGTH	32	/* 32 bits */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) #define INTERACT_TYPE_HHFX	0	/* HammerHead/FX */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #define INTERACT_TYPE_PP8D	1	/* ProPad 8 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) struct interact {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 	struct gameport *gameport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	struct input_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	int bads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	int reads;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	unsigned char type;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) 	unsigned char length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 	char phys[32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) static short interact_abs_hhfx[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	{ ABS_RX, ABS_RY, ABS_X, ABS_Y, ABS_HAT0X, ABS_HAT0Y, -1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) static short interact_abs_pp8d[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) 	{ ABS_X, ABS_Y, -1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static short interact_btn_hhfx[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	{ BTN_TR, BTN_X, BTN_Y, BTN_Z, BTN_A, BTN_B, BTN_C, BTN_TL, BTN_TL2, BTN_TR2, BTN_MODE, BTN_SELECT, -1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) static short interact_btn_pp8d[] =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 	{ BTN_C, BTN_TL, BTN_TR, BTN_A, BTN_B, BTN_Y, BTN_Z, BTN_X, -1 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) struct interact_type {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	int id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	short *abs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	short *btn;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	char *name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	unsigned char length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	unsigned char b8;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) static struct interact_type interact_type[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	{ 0x6202, interact_abs_hhfx, interact_btn_hhfx, "InterAct HammerHead/FX",    32, 4 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	{ 0x53f8, interact_abs_pp8d, interact_btn_pp8d, "InterAct ProPad 8 Digital", 16, 0 },
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	{ 0 }};
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72)  * interact_read_packet() reads and InterAct joystick data.
^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) static int interact_read_packet(struct gameport *gameport, int length, u32 *data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	unsigned char u, v;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	unsigned int t, s;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	i = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	data[0] = data[1] = data[2] = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 	t = gameport_time(gameport, INTERACT_MAX_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 	s = gameport_time(gameport, INTERACT_MAX_STROBE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 	local_irq_save(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	gameport_trigger(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	v = gameport_read(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	while (t > 0 && i < length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		t--;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 		u = v; v = gameport_read(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 		if (v & ~u & 0x40) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			data[0] = (data[0] << 1) | ((v >> 4) & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			data[1] = (data[1] << 1) | ((v >> 5) & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			data[2] = (data[2] << 1) | ((v >> 7) & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			i++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 			t = s;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	local_irq_restore(flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	return i;
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109)  * interact_poll() reads and analyzes InterAct joystick data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) static void interact_poll(struct gameport *gameport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	struct interact *interact = gameport_get_drvdata(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	struct input_dev *dev = interact->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	u32 data[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	interact->reads++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	if (interact_read_packet(interact->gameport, interact->length, data) < interact->length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 		interact->bads++;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	} else {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 		for (i = 0; i < 3; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 			data[i] <<= INTERACT_MAX_LENGTH - interact->length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 		switch (interact->type) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 			case INTERACT_TYPE_HHFX:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 				for (i = 0; i < 4; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 					input_report_abs(dev, interact_abs_hhfx[i], (data[i & 1] >> ((i >> 1) << 3)) & 0xff);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 				for (i = 0; i < 2; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 					input_report_abs(dev, ABS_HAT0Y - i,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 						((data[1] >> ((i << 1) + 17)) & 1)  - ((data[1] >> ((i << 1) + 16)) & 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 				for (i = 0; i < 8; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 					input_report_key(dev, interact_btn_hhfx[i], (data[0] >> (i + 16)) & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 				for (i = 0; i < 4; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 					input_report_key(dev, interact_btn_hhfx[i + 8], (data[1] >> (i + 20)) & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 				break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 			case INTERACT_TYPE_PP8D:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 				for (i = 0; i < 2; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 					input_report_abs(dev, interact_abs_pp8d[i],
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 						((data[0] >> ((i << 1) + 20)) & 1)  - ((data[0] >> ((i << 1) + 21)) & 1));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 				for (i = 0; i < 8; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 					input_report_key(dev, interact_btn_pp8d[i], (data[1] >> (i + 16)) & 1);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 				break;
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	input_sync(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164)  * interact_open() is a callback from the input open routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) static int interact_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	struct interact *interact = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	gameport_start_polling(interact->gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	return 0;
^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)  * interact_close() is a callback from the input close routine.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) static void interact_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 	struct interact *interact = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 	gameport_stop_polling(interact->gameport);
^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) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187)  * interact_connect() probes for InterAct joysticks.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) static int interact_connect(struct gameport *gameport, struct gameport_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	struct interact *interact;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	__u32 data[3];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	int i, t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 	interact = kzalloc(sizeof(struct interact), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 	input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 	if (!interact || !input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 		err = -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	interact->gameport = gameport;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 	interact->dev = input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	gameport_set_drvdata(gameport, interact);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	err = gameport_open(gameport, drv, GAMEPORT_MODE_RAW);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		goto fail1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	i = interact_read_packet(gameport, INTERACT_MAX_LENGTH * 2, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	if (i != 32 || (data[0] >> 24) != 0x0c || (data[1] >> 24) != 0x02) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 		goto fail2;
^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) 	for (i = 0; interact_type[i].length; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 		if (interact_type[i].id == (data[2] >> 16))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	if (!interact_type[i].length) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		printk(KERN_WARNING "interact.c: Unknown joystick on %s. [len %d d0 %08x d1 %08x i2 %08x]\n",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			gameport->phys, i, data[0], data[1], data[2]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 		err = -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		goto fail2;
^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) 	gameport_set_poll_handler(gameport, interact_poll);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 	gameport_set_poll_interval(gameport, 20);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	snprintf(interact->phys, sizeof(interact->phys), "%s/input0", gameport->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	interact->type = i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 	interact->length = interact_type[i].length;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	input_dev->name = interact_type[i].name;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	input_dev->phys = interact->phys;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	input_dev->id.bustype = BUS_GAMEPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	input_dev->id.vendor = GAMEPORT_ID_VENDOR_INTERACT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	input_dev->id.product = interact_type[i].id;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	input_dev->id.version = 0x0100;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 	input_dev->dev.parent = &gameport->dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	input_set_drvdata(input_dev, interact);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	input_dev->open = interact_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	input_dev->close = interact_close;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 	input_dev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	for (i = 0; (t = interact_type[interact->type].abs[i]) >= 0; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 		if (i < interact_type[interact->type].b8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 			input_set_abs_params(input_dev, t, 0, 255, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 			input_set_abs_params(input_dev, t, -1, 1, 0, 0);
^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) 	for (i = 0; (t = interact_type[interact->type].btn[i]) >= 0; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		__set_bit(t, input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 	err = input_register_device(interact->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		goto fail2;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) fail2:	gameport_close(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) fail1:  gameport_set_drvdata(gameport, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	input_free_device(input_dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 	kfree(interact);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	return err;
^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) static void interact_disconnect(struct gameport *gameport)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	struct interact *interact = gameport_get_drvdata(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 	input_unregister_device(interact->dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 	gameport_close(gameport);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 	gameport_set_drvdata(gameport, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	kfree(interact);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) static struct gameport_driver interact_drv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 		.name	= "interact",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 	.description	= DRIVER_DESC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	.connect	= interact_connect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 	.disconnect	= interact_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) module_gameport_driver(interact_drv);