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)  *  Based on the work of:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *	Steffen Schwenke
^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)  * TurboGraFX parallel port interface 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/parport.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/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/mutex.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) MODULE_AUTHOR("Vojtech Pavlik <vojtech@ucw.cz>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) MODULE_DESCRIPTION("TurboGraFX parallel port interface driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) #define TGFX_MAX_PORTS		3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) #define TGFX_MAX_DEVICES	7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) struct tgfx_config {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) 	int args[TGFX_MAX_DEVICES + 1];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) 	unsigned int nargs;
^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) static struct tgfx_config tgfx_cfg[TGFX_MAX_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) module_param_array_named(map, tgfx_cfg[0].args, int, &tgfx_cfg[0].nargs, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) MODULE_PARM_DESC(map, "Describes first set of devices (<parport#>,<js1>,<js2>,..<js7>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) module_param_array_named(map2, tgfx_cfg[1].args, int, &tgfx_cfg[1].nargs, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) MODULE_PARM_DESC(map2, "Describes second set of devices");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) module_param_array_named(map3, tgfx_cfg[2].args, int, &tgfx_cfg[2].nargs, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) MODULE_PARM_DESC(map3, "Describes third set of devices");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) #define TGFX_REFRESH_TIME	HZ/100	/* 10 ms */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) #define TGFX_TRIGGER		0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define TGFX_UP			0x10
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) #define TGFX_DOWN		0x20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) #define TGFX_LEFT		0x40
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) #define TGFX_RIGHT		0x80
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) #define TGFX_THUMB		0x02
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) #define TGFX_THUMB2		0x04
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) #define TGFX_TOP		0x01
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) #define TGFX_TOP2		0x08
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) static int tgfx_buttons[] = { BTN_TRIGGER, BTN_THUMB, BTN_THUMB2, BTN_TOP, BTN_TOP2 };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) static struct tgfx {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	struct pardevice *pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	struct timer_list timer;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 	struct input_dev *dev[TGFX_MAX_DEVICES];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	char name[TGFX_MAX_DEVICES][64];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	char phys[TGFX_MAX_DEVICES][32];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	int sticks;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	int used;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	int parportno;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	struct mutex sem;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) } *tgfx_base[TGFX_MAX_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73)  * tgfx_timer() reads and analyzes TurboGraFX joystick data.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) static void tgfx_timer(struct timer_list *t)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	struct tgfx *tgfx = from_timer(tgfx, t, timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	struct input_dev *dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 	int data1, data2, i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 	for (i = 0; i < 7; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 		if (tgfx->sticks & (1 << i)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 			dev = tgfx->dev[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 			parport_write_data(tgfx->pd->port, ~(1 << i));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 			data1 = parport_read_status(tgfx->pd->port) ^ 0x7f;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 			data2 = parport_read_control(tgfx->pd->port) ^ 0x04;	/* CAVEAT parport */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 			input_report_abs(dev, ABS_X, !!(data1 & TGFX_RIGHT) - !!(data1 & TGFX_LEFT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 			input_report_abs(dev, ABS_Y, !!(data1 & TGFX_DOWN ) - !!(data1 & TGFX_UP  ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 			input_report_key(dev, BTN_TRIGGER, (data1 & TGFX_TRIGGER));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 			input_report_key(dev, BTN_THUMB,   (data2 & TGFX_THUMB  ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 			input_report_key(dev, BTN_THUMB2,  (data2 & TGFX_THUMB2 ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 			input_report_key(dev, BTN_TOP,     (data2 & TGFX_TOP    ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 			input_report_key(dev, BTN_TOP2,    (data2 & TGFX_TOP2   ));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) 			input_sync(dev);
^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) 	mod_timer(&tgfx->timer, jiffies + TGFX_REFRESH_TIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) static int tgfx_open(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	struct tgfx *tgfx = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	int err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	err = mutex_lock_interruptible(&tgfx->sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 	if (err)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 		return err;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	if (!tgfx->used++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 		parport_claim(tgfx->pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 		parport_write_control(tgfx->pd->port, 0x04);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 		mod_timer(&tgfx->timer, jiffies + TGFX_REFRESH_TIME);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	mutex_unlock(&tgfx->sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) static void tgfx_close(struct input_dev *dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	struct tgfx *tgfx = input_get_drvdata(dev);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 	mutex_lock(&tgfx->sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	if (!--tgfx->used) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 		del_timer_sync(&tgfx->timer);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		parport_write_control(tgfx->pd->port, 0x00);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 		parport_release(tgfx->pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	mutex_unlock(&tgfx->sem);
^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) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141)  * tgfx_probe() probes for tg gamepads.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) static void tgfx_attach(struct parport *pp)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	struct tgfx *tgfx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 	struct input_dev *input_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	struct pardevice *pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) 	int i, j, port_idx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 	int *n_buttons, n_devs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	struct pardev_cb tgfx_parport_cb;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	for (port_idx = 0; port_idx < TGFX_MAX_PORTS; port_idx++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 		if (tgfx_cfg[port_idx].nargs == 0 ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 		    tgfx_cfg[port_idx].args[0] < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 		if (tgfx_cfg[port_idx].args[0] == pp->number)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 			break;
^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) 	if (port_idx == TGFX_MAX_PORTS) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 		pr_debug("Not using parport%d.\n", pp->number);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	n_buttons = tgfx_cfg[port_idx].args + 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	n_devs = tgfx_cfg[port_idx].nargs - 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 	memset(&tgfx_parport_cb, 0, sizeof(tgfx_parport_cb));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	tgfx_parport_cb.flags = PARPORT_FLAG_EXCL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 	pd = parport_register_dev_model(pp, "turbografx", &tgfx_parport_cb,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 					port_idx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if (!pd) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		pr_err("parport busy already - lp.o loaded?\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 	tgfx = kzalloc(sizeof(struct tgfx), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	if (!tgfx) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		printk(KERN_ERR "turbografx.c: Not enough memory\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		goto err_unreg_pardev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) 	mutex_init(&tgfx->sem);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) 	tgfx->pd = pd;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	tgfx->parportno = pp->number;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	timer_setup(&tgfx->timer, tgfx_timer, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	for (i = 0; i < n_devs; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 		if (n_buttons[i] < 1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 		if (n_buttons[i] > ARRAY_SIZE(tgfx_buttons)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 			printk(KERN_ERR "turbografx.c: Invalid number of buttons %d\n", n_buttons[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 			goto err_unreg_devs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		tgfx->dev[i] = input_dev = input_allocate_device();
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		if (!input_dev) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) 			printk(KERN_ERR "turbografx.c: Not enough memory for input device\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) 			goto err_unreg_devs;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) 		tgfx->sticks |= (1 << i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 		snprintf(tgfx->name[i], sizeof(tgfx->name[i]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 			 "TurboGraFX %d-button Multisystem joystick", n_buttons[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 		snprintf(tgfx->phys[i], sizeof(tgfx->phys[i]),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 			 "%s/input%d", tgfx->pd->port->name, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 		input_dev->name = tgfx->name[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 		input_dev->phys = tgfx->phys[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 		input_dev->id.bustype = BUS_PARPORT;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 		input_dev->id.vendor = 0x0003;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 		input_dev->id.product = n_buttons[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		input_dev->id.version = 0x0100;
^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, tgfx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 		input_dev->open = tgfx_open;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		input_dev->close = tgfx_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) 		input_set_abs_params(input_dev, ABS_X, -1, 1, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 		input_set_abs_params(input_dev, ABS_Y, -1, 1, 0, 0);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 		for (j = 0; j < n_buttons[i]; j++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 			set_bit(tgfx_buttons[j], input_dev->keybit);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 		if (input_register_device(tgfx->dev[i]))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) 			goto err_free_dev;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)         if (!tgfx->sticks) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) 		printk(KERN_ERR "turbografx.c: No valid devices specified\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 		goto err_free_tgfx;
^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) 	tgfx_base[port_idx] = tgfx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241)  err_free_dev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 	input_free_device(tgfx->dev[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)  err_unreg_devs:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	while (--i >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		if (tgfx->dev[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 			input_unregister_device(tgfx->dev[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247)  err_free_tgfx:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 	kfree(tgfx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  err_unreg_pardev:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 	parport_unregister_device(pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) static void tgfx_detach(struct parport *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 	struct tgfx *tgfx;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 	for (i = 0; i < TGFX_MAX_PORTS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		if (tgfx_base[i] && tgfx_base[i]->parportno == port->number)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	if (i == TGFX_MAX_PORTS)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		return;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	tgfx = tgfx_base[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 	tgfx_base[i] = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 	for (i = 0; i < TGFX_MAX_DEVICES; i++)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 		if (tgfx->dev[i])
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 			input_unregister_device(tgfx->dev[i]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 	parport_unregister_device(tgfx->pd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	kfree(tgfx);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) static struct parport_driver tgfx_parport_driver = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 	.name = "turbografx",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 	.match_port = tgfx_attach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 	.detach = tgfx_detach,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	.devmodel = true,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) static int __init tgfx_init(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	int have_dev = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	for (i = 0; i < TGFX_MAX_PORTS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 		if (tgfx_cfg[i].nargs == 0 || tgfx_cfg[i].args[0] < 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 			continue;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		if (tgfx_cfg[i].nargs < 2) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 			printk(KERN_ERR "turbografx.c: at least one joystick must be specified\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			return -EINVAL;
^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) 		have_dev = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	if (!have_dev)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 		return -ENODEV;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 	return parport_register_driver(&tgfx_parport_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) static void __exit tgfx_exit(void)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) 	parport_unregister_driver(&tgfx_parport_driver);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) module_init(tgfx_init);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) module_exit(tgfx_exit);