Skip to contentSkip to conversation

Add drivers necessary to support PS/2 port on TQM85xx boards

PATCH Superseded Dmitry Eremin-Solenikov 2 participants 8 messages Aug 12, 2010 – Aug 14, 2010

Subsystems (2)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Add drivers necessary to support PS/2 port on TQM85xx boards

On tqm85xx boards PS/2 keyboard and mouse are connected to the CPU via special PIC controller multiplexing two PS/2 streams into single UART.

To support this I'm using already existing serport UART->serio ldisc, on top of which runs protcol multiplexer serio->2 serio ports driver, which provides serio ports for atkbd and psmouse drivers.

Signature · 2 lines
With best wishes
Dmitry
#1 lore raw

PATCH 1/4 serio: support multiple child devices per single parent

Some (rare) serio devices need to have multiple serio children. One of the examples is PS/2 multiplexer present on several TQC STKxxx boards, which connect PS/2 keyboard and mouse to single tty port.

---
 drivers/input/mouse/psmouse-base.c |    2 +-
 drivers/input/mouse/synaptics.c    |   11 +++-
 drivers/input/serio/serio.c        |   90 ++++++++++++++++--------------------
 include/linux/serio.h              |    4 +-
 4 files changed, 52 insertions(+), 55 deletions(-)
drivers/input/mouse/psmouse-base.c +1 -1
index 979c502..0eeed6c 100644
@@ -1582,7 +1582,7 @@ static ssize_t psmouse_attr_set_protocol(struct psmouse *psmouse, void *data, co
 	if (!new_dev)
 		return -ENOMEM;
 
-	while (serio->child) {
+	while (!list_empty(&serio->children)) {
 		if (++retry > 3) {
 			printk(KERN_WARNING
 				"psmouse: failed to destroy child port, "
drivers/input/mouse/synaptics.c +8 -3
index 705589d..9295ad0 100644
@@ -315,7 +315,9 @@ static void synaptics_pass_pt_packet(struct serio *ptport, unsigned char *packet
 
 static void synaptics_pt_activate(struct psmouse *psmouse)
 {
-	struct serio *ptport = psmouse->ps2dev.serio->child;
+	struct serio *ptport =
+		list_first_entry(&psmouse->ps2dev.serio->children,
+				struct serio, child_list);
 	struct psmouse *child = serio_get_drvdata(ptport);
 	struct synaptics_data *priv = psmouse->private;
 
@@ -577,8 +579,11 @@ static psmouse_ret_t synaptics_process_byte(struct psmouse *psmouse)
 			priv->pkt_type = synaptics_detect_pkt_type(psmouse);
 
 		if (SYN_CAP_PASS_THROUGH(priv->capabilities) && synaptics_is_pt_packet(psmouse->packet)) {
-			if (psmouse->ps2dev.serio->child)
-				synaptics_pass_pt_packet(psmouse->ps2dev.serio->child, psmouse->packet);
+			if (!list_empty(&psmouse->ps2dev.serio->children))
+				synaptics_pass_pt_packet(
+						list_first_entry(&psmouse->ps2dev.serio->children,
+							struct serio, child_list),
+						psmouse->packet);
 		} else
 			synaptics_process_packet(psmouse);
 
drivers/input/serio/serio.c +43 -53

176 lines not on this page · raw message

include/linux/serio.h +3 -1
index b555256..d2ae60d 100644
@@ -41,7 +41,9 @@ struct serio {
 	int (*start)(struct serio *);
 	void (*stop)(struct serio *);
 
-	struct serio *parent, *child;
+	struct serio *parent;
+	struct list_head child_list;
+	struct list_head children;
 	unsigned int depth;		/* level of nesting in serio hierarchy */
 
 	struct serio_driver *drv;	/* accessed from interrupt, must be protected by serio->lock and serio->sem */
Signature · 1 line
1.7.1
maintainer
#2 lore raw

Re: [PATCH 1/4] serio: support multiple child devices per single parent

Hi Dmitry,

Quoted 4 lines · Dmitry Eremin-Solenikov

Some (rare) serio devices need to have multiple serio children. One of the examples is PS/2 multiplexer present on several TQC STKxxx boards, which connect PS/2 keyboard and mouse to single tty port.

I like idea of the patch, however I'd prefer if we kept recurstion out of the serio core and instead stick to iterative algorithms. Any chance you could rework the part that travels the [sub]trees?

Thanks.

Signature · 1 line
Dmitry
#3 lore raw

Re: [PATCH 1/4] serio: support multiple child devices per single parent

Hi Dmitry,

Quoted 11 lines · Dmitry Torokhov

Hi Dmitry,

Quoted 4 lines · Dmitry Eremin-Solenikov

Some (rare) serio devices need to have multiple serio children. One of the examples is PS/2 multiplexer present on several TQC STKxxx boards, which connect PS/2 keyboard and mouse to single tty port.

I like idea of the patch, however I'd prefer if we kept recurstion out of the serio core and instead stick to iterative algorithms. Any chance you could rework the part that travels the [sub]trees?

Would you mind another list_head embedded into struct strio? If it's suitable solution, I've refactored recursion out.

Signature · 2 lines
With best wishes
Dmitry
#4 lore raw

PATCH 2/4 serio: add support for PS2Mult multiplexer protocol

In reply to Dmitry Eremin-Solenikov

PS2Mult is a simple serial protocol used for multiplexing several PS/2 streams into one serial data stream. It's used e.g. on TQM85xx serie of boards.

---
 drivers/input/serio/Kconfig   |    8 ++
 drivers/input/serio/Makefile  |    1 +
 drivers/input/serio/ps2mult.c |  264 +++++++++++++++++++++++++++++++++++++++++
 include/linux/serio.h         |    2 +
 4 files changed, 275 insertions(+), 0 deletions(-)
 create mode 100644 drivers/input/serio/ps2mult.c
drivers/input/serio/Kconfig +8 -0
index 3bfe8fa..63f4658 100644
@@ -226,4 +226,12 @@ config SERIO_AMS_DELTA
 	  To compile this driver as a module, choose M here;
 	  the module will be called ams_delta_serio.
 
+config SERIO_PS2MULT
+	tristate "TQC PS/2 multiplexer"
+	help
+	  Say Y here if you have the PS/2 line multiplexer like present on TQC boads
+
+	  To compile this driver as a module, choose M here: the
+	  module will be called ps2mult.
+
 endif
drivers/input/serio/Makefile +1 -0
index 84c80bf..26714c5 100644
@@ -24,3 +24,4 @@ obj-$(CONFIG_SERIO_RAW)		+= serio_raw.o
 obj-$(CONFIG_SERIO_AMS_DELTA)	+= ams_delta_serio.o
 obj-$(CONFIG_SERIO_XILINX_XPS_PS2)	+= xilinx_ps2.o
 obj-$(CONFIG_SERIO_ALTERA_PS2)	+= altera_ps2.o
+obj-$(CONFIG_SERIO_PS2MULT)	+= ps2mult.o
drivers/input/serio/ps2mult.c new file +264 -0

264 lines not on this page · raw message

include/linux/serio.h +2 -0
index d2ae60d..1cf47e5 100644
@@ -155,6 +155,7 @@ static inline void serio_continue_rx(struct serio *serio)
 #define SERIO_HIL_MLC	0x03
 #define SERIO_PS_PSTHRU	0x05
 #define SERIO_8042_XL	0x06
+#define SERIO_PS2MULT_T	0x07
 
 /*
  * Serio protocols
@@ -199,5 +200,6 @@ static inline void serio_continue_rx(struct serio *serio)
 #define SERIO_W8001	0x39
 #define SERIO_DYNAPRO	0x3a
 #define SERIO_HAMPSHIRE	0x3b
+#define SERIO_PS2MULT	0x3c
 
 #endif
Signature · 1 line
1.7.1
maintainer
#5 lore raw

Re: [PATCH 2/4] serio: add support for PS2Mult multiplexer protocol

drivers/input/serio/ps2mult.c line 68

Quoted 8 lines · Dmitry Eremin-Solenikov
drivers/input/serio/ps2mult.c new file +8 -0
+
+static int ps2mult_serio_write(struct serio *serio, unsigned char data)
+{
+	struct ps2mult *psm = serio_get_drvdata(serio->parent);
+	struct ps2mult_port *psmp = serio->port_data;
+	int need_escape = 0;
+
+	mutex_lock(&psm->lock);

serio->write() is allowed to be called from interrupt contexts so you should not be using mutex but a spinlock.

BTW, if anyone has time to annotate serio code with kerneldoc markups that would be great.

drivers/input/serio/ps2mult.c line 79

Quoted 11 lines
drivers/input/serio/ps2mult.c new file +11 -0
+	if (psm->cur_out_port != psmp->port) {
+		psm->serio->write(psm->serio, psmp->sel);
+		psm->cur_out_port = psmp->port;
+		dev_dbg(&serio->dev, "switched to sel %02x\n", psmp->sel);
+	}
+	if (data == PS2MULT_ESCAPE
+	 || data == PS2MULT_BSYNC
+	 || data == PS2MULT_SESSION_START
+	 || data == PS2MULT_SESSION_END
+	 || memchr(ps2mult_selectors, data, PS2MULT_NUM_PORTS))
+		need_escape = 1;

Use bool/true/false please. I'd also probably write

	need_escape = data == PS2MULT_ESCAPE ||
		      data == ...
Quoted 10 lines
drivers/input/serio/ps2mult.c new file +10 -0
+
+static int ps2mult_connect(struct serio *serio, struct serio_driver *drv)
+{
+	struct ps2mult *psm;
+	int i;
+	int rc;
+
+	if (!serio->write)
+		return -EINVAL;
+

drivers/input/serio/ps2mult.c line 164

Quoted 10 lines
drivers/input/serio/ps2mult.c new file +10 -0
+	psm = kzalloc(sizeof(*psm), GFP_KERNEL);
+	if (!psm)
+		return -ENOMEM;
+
+	mutex_init(&psm->lock);
+	psm->serio = serio;
+
+	serio_set_drvdata(serio, psm);
+	serio_open(serio, drv);
+

Here serio port is allowed to start sending the data. I do not believe you are ready to receive it though. I think you need to create ports first and then use start() to mark ports that have been regstered by serio core as 'ready'. Probably i8042 could give you some ideas.

include/linux/serio.h static inline void serio_continue_rx(struct serio *serio) · line 158

Quoted 8 lines

index d2ae60d..1cf47e5 100644

include/linux/serio.h +1 -0
@@ -155,6 +155,7 @@ static inline void serio_continue_rx(struct serio *serio)
 #define SERIO_HIL_MLC	0x03
 #define SERIO_PS_PSTHRU	0x05
 #define SERIO_8042_XL	0x06
+#define SERIO_PS2MULT_T	0x07

Why do you need new serio type? I'd stick with SERIO_I8042 so that you do not need to patch atkbd/psmouse.

Thanks.

Signature · 1 line
Dmitry
#6 lore raw

PATCH 3/4 atkbd: support binding to ps2mult devices

In reply to Dmitry Eremin-Solenikov
---
 drivers/input/keyboard/atkbd.c |    7 +++++++
 1 files changed, 7 insertions(+), 0 deletions(-)
drivers/input/keyboard/atkbd.c +7 -0
index d358ef8..156fe54 100644
@@ -1113,6 +1113,7 @@ static int atkbd_connect(struct serio *serio, struct serio_driver *drv)
 		/* Fall through */
 
 	case SERIO_8042:
+	case SERIO_PS2MULT_T:
 		if (serio->write)
 			atkbd->write = true;
 		break;
@@ -1240,6 +1241,12 @@ static struct serio_device_id atkbd_serio_ids[] = {
 		.id	= SERIO_ANY,
 		.extra	= SERIO_ANY,
 	},
+	{
+		.type	= SERIO_PS2MULT_T,
+		.proto	= SERIO_ANY,
+		.id	= SERIO_ANY,
+		.extra	= SERIO_ANY,
+	},
 	{ 0 }
 };
 
Signature · 1 line
1.7.1
#7 lore raw

PATCH 4/4 psmouse: support binding to ps2mult devices

In reply to Dmitry Eremin-Solenikov
---
 drivers/input/mouse/psmouse-base.c |    6 ++++++
 1 files changed, 6 insertions(+), 0 deletions(-)
drivers/input/mouse/psmouse-base.c +6 -0
index 0eeed6c..1e9fdd7 100644
@@ -1460,6 +1460,12 @@ static struct serio_device_id psmouse_serio_ids[] = {
 		.id	= SERIO_ANY,
 		.extra	= SERIO_ANY,
 	},
+	{
+		.type	= SERIO_PS2MULT_T,
+		.proto	= SERIO_ANY,
+		.id	= SERIO_ANY,
+		.extra	= SERIO_ANY,
+	},
 	{ 0 }
 };
 
Signature · 1 line
1.7.1