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-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  * TQC PS/2 Multiplexer driver
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  * Copyright (C) 2010 Dmitry Eremin-Solenikov
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  */
^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) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12) #include <linux/serio.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) MODULE_AUTHOR("Dmitry Eremin-Solenikov <dbaryshkov@gmail.com>");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) MODULE_DESCRIPTION("TQC PS/2 Multiplexer driver");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) MODULE_LICENSE("GPL");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #define PS2MULT_KB_SELECTOR		0xA0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #define PS2MULT_MS_SELECTOR		0xA1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #define PS2MULT_ESCAPE			0x7D
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #define PS2MULT_BSYNC			0x7E
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) #define PS2MULT_SESSION_START		0x55
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #define PS2MULT_SESSION_END		0x56
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) struct ps2mult_port {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 	struct serio *serio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) 	unsigned char sel;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	bool registered;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) #define PS2MULT_NUM_PORTS	2
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #define PS2MULT_KBD_PORT	0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) #define PS2MULT_MOUSE_PORT	1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) struct ps2mult {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) 	struct serio *mx_serio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) 	struct ps2mult_port ports[PS2MULT_NUM_PORTS];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) 	spinlock_t lock;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) 	struct ps2mult_port *in_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) 	struct ps2mult_port *out_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) 	bool escape;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) /* First MUST come PS2MULT_NUM_PORTS selectors */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) static const unsigned char ps2mult_controls[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 	PS2MULT_KB_SELECTOR, PS2MULT_MS_SELECTOR,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) 	PS2MULT_ESCAPE, PS2MULT_BSYNC,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 	PS2MULT_SESSION_START, PS2MULT_SESSION_END,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52) static const struct serio_device_id ps2mult_serio_ids[] = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53) 	{
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54) 		.type	= SERIO_RS232,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) 		.proto	= SERIO_PS2MULT,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) 		.id	= SERIO_ANY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 		.extra	= SERIO_ANY,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 	{ 0 }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) MODULE_DEVICE_TABLE(serio, ps2mult_serio_ids);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) static void ps2mult_select_port(struct ps2mult *psm, struct ps2mult_port *port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	struct serio *mx_serio = psm->mx_serio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	serio_write(mx_serio, port->sel);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	psm->out_port = port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	dev_dbg(&mx_serio->dev, "switched to sel %02x\n", port->sel);
^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) static int ps2mult_serio_write(struct serio *serio, unsigned char data)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 	struct serio *mx_port = serio->parent;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 	struct ps2mult *psm = serio_get_drvdata(mx_port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	struct ps2mult_port *port = serio->port_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 	bool need_escape;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 	spin_lock_irqsave(&psm->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83) 	if (psm->out_port != port)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84) 		ps2mult_select_port(psm, port);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86) 	need_escape = memchr(ps2mult_controls, data, sizeof(ps2mult_controls));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) 	dev_dbg(&serio->dev,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 		"write: %s%02x\n", need_escape ? "ESC " : "", data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	if (need_escape)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) 		serio_write(mx_port, PS2MULT_ESCAPE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 	serio_write(mx_port, data);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96) 	spin_unlock_irqrestore(&psm->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98) 	return 0;
^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) static int ps2mult_serio_start(struct serio *serio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) 	struct ps2mult *psm = serio_get_drvdata(serio->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) 	struct ps2mult_port *port = serio->port_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	spin_lock_irqsave(&psm->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	port->registered = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 	spin_unlock_irqrestore(&psm->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	return 0;
^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 ps2mult_serio_stop(struct serio *serio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 	struct ps2mult *psm = serio_get_drvdata(serio->parent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	struct ps2mult_port *port = serio->port_data;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	spin_lock_irqsave(&psm->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	port->registered = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 	spin_unlock_irqrestore(&psm->lock, flags);
^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 int ps2mult_create_port(struct ps2mult *psm, int i)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 	struct serio *mx_serio = psm->mx_serio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	struct serio *serio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	serio = kzalloc(sizeof(struct serio), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	if (!serio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) 	strlcpy(serio->name, "TQC PS/2 Multiplexer", sizeof(serio->name));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) 	snprintf(serio->phys, sizeof(serio->phys),
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 		 "%s/port%d", mx_serio->phys, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 	serio->id.type = SERIO_8042;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	serio->write = ps2mult_serio_write;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	serio->start = ps2mult_serio_start;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	serio->stop = ps2mult_serio_stop;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	serio->parent = psm->mx_serio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	serio->port_data = &psm->ports[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 	psm->ports[i].serio = serio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) static void ps2mult_reset(struct ps2mult *psm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) 	spin_lock_irqsave(&psm->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) 	serio_write(psm->mx_serio, PS2MULT_SESSION_END);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) 	serio_write(psm->mx_serio, PS2MULT_SESSION_START);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) 	ps2mult_select_port(psm, &psm->ports[PS2MULT_KBD_PORT]);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	spin_unlock_irqrestore(&psm->lock, flags);
^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) static int ps2mult_connect(struct serio *serio, struct serio_driver *drv)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	struct ps2mult *psm;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 	int i;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 	int error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 	if (!serio->write)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 		return -EINVAL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	psm = kzalloc(sizeof(*psm), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	if (!psm)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 		return -ENOMEM;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) 	spin_lock_init(&psm->lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 	psm->mx_serio = serio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) 	for (i = 0; i < PS2MULT_NUM_PORTS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) 		psm->ports[i].sel = ps2mult_controls[i];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) 		error = ps2mult_create_port(psm, i);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) 		if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) 			goto err_out;
^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) 	psm->in_port = psm->out_port = &psm->ports[PS2MULT_KBD_PORT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 	serio_set_drvdata(serio, psm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	error = serio_open(serio, drv);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	if (error)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		goto err_out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 	ps2mult_reset(psm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) 	for (i = 0; i <  PS2MULT_NUM_PORTS; i++) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 		struct serio *s = psm->ports[i].serio;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) 		dev_info(&serio->dev, "%s port at %s\n", s->name, serio->phys);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199) 		serio_register_port(s);
^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) 	return 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) err_out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205) 	while (--i >= 0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) 		kfree(psm->ports[i].serio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 	kfree(psm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) 	return error;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) static void ps2mult_disconnect(struct serio *serio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	struct ps2mult *psm = serio_get_drvdata(serio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 	/* Note that serio core already take care of children ports */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 	serio_write(serio, PS2MULT_SESSION_END);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 	serio_close(serio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 	kfree(psm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 	serio_set_drvdata(serio, NULL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) static int ps2mult_reconnect(struct serio *serio)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) 	struct ps2mult *psm = serio_get_drvdata(serio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) 	ps2mult_reset(psm);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) 	return 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) static irqreturn_t ps2mult_interrupt(struct serio *serio,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) 				     unsigned char data, unsigned int dfl)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) 	struct ps2mult *psm = serio_get_drvdata(serio);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	struct ps2mult_port *in_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	dev_dbg(&serio->dev, "Received %02x flags %02x\n", data, dfl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 	spin_lock_irqsave(&psm->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 	if (psm->escape) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 		psm->escape = false;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 		in_port = psm->in_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) 		if (in_port->registered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 			serio_interrupt(in_port->serio, data, dfl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) 		goto out;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) 	switch (data) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) 	case PS2MULT_ESCAPE:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) 		dev_dbg(&serio->dev, "ESCAPE\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) 		psm->escape = true;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) 	case PS2MULT_BSYNC:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) 		dev_dbg(&serio->dev, "BSYNC\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 		psm->in_port = psm->out_port;
^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) 	case PS2MULT_SESSION_START:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 		dev_dbg(&serio->dev, "SS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 	case PS2MULT_SESSION_END:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 		dev_dbg(&serio->dev, "SE\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	case PS2MULT_KB_SELECTOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 		dev_dbg(&serio->dev, "KB\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 		psm->in_port = &psm->ports[PS2MULT_KBD_PORT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 	case PS2MULT_MS_SELECTOR:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) 		dev_dbg(&serio->dev, "MS\n");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277) 		psm->in_port = &psm->ports[PS2MULT_MOUSE_PORT];
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280) 	default:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) 		in_port = psm->in_port;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) 		if (in_port->registered)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) 			serio_interrupt(in_port->serio, data, dfl);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) 		break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287)  out:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 	spin_unlock_irqrestore(&psm->lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	return IRQ_HANDLED;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) static struct serio_driver ps2mult_drv = {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 	.driver		= {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 		.name	= "ps2mult",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 	},
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 	.description	= "TQC PS/2 Multiplexer driver",
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	.id_table	= ps2mult_serio_ids,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	.interrupt	= ps2mult_interrupt,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 	.connect	= ps2mult_connect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	.disconnect	= ps2mult_disconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) 	.reconnect	= ps2mult_reconnect,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) module_serio_driver(ps2mult_drv);