Thread (11 messages) 11 messages, 3 authors, 2020-05-13

Re: [PATCH 2/3] input: serio: allow more than one byte to be sent at once

From: Sean Young <sean@mess.org>
Date: 2020-05-12 09:07:31
Also in: linux-media, lkml

On Mon, May 11, 2020 at 08:51:18AM +0200, Greg KH wrote:
On Thu, May 07, 2020 at 09:59:18PM +0100, Sean Young wrote:
quoted
On Thu, May 07, 2020 at 01:25:46PM -0700, Dmitry Torokhov wrote:
quoted
On Thu, May 07, 2020 at 02:53:36PM +0100, Sean Young wrote:
quoted
serio drivers can only send one byte at a time. If the underlying tty
is a usb serial port, then each byte will be put into separate usb
urbs, which is not efficient.

Additionally, the Infrared Toy device refuses to transmit IR if the
IR data is sent one byte at a time. IR data is formatted in u16 values,
and the firmware expects complete u16 values in the packet.

https://github.com/DangerousPrototypes/USB_IR_Toy/blob/master/Firmware-main/IRs.c#L240
Ummm, serial protocol data size is at most 9 bits so I have no earthly
idea how they expect to get 16.
serio is a layer on top several serial protocols, including ttys. ttys allow
more than one byte to be written at a time, see struct tty_operations:

        int  (*write)(struct tty_struct * tty,
                      const unsigned char *buf, int count);

ttys would be very inefficient if you could only write one byte at a time,
and they are very serial.

This patch exposes the underlying tty write() functionality to serio. When
the underlying tty is a usb serial port this makes for far fewer usb packets
being used to send the same data, and fixes my driver problem, and it
would reduce the number of calls in a few other cases too.

I'm happy to rework the patch if there are comments on the style or
approach.
Why not just use the ir-usb.c driver for this device instead?
So this device is the infrared kind which rc-core (in drivers/media/rc/)
supports, remotes and such things (not for serial IR). So by using a 
rc-core driver, it can use kernel IR decoding, BPF decoding, lirc chardev
and rc keymaps, etc.

This device is a PIC18F2550 type device, which is a usb serial port
microcontroller type with some firmware and IR diodes:
	http://dangerousprototypes.com/docs/USB_IR_Toy_v2

serio supports a whole bunch of usb serial devices which can be attached
via inputattach(1). Not all of these are input devices, for example there
are two cec devices too.

Now, in many of these drivers, multiple bytes need to be written to the
device in order to send it a command, for example in
drivers/input/touchscreen/elo.c:

        for (i = 0; i < ELO10_PACKET_LEN; i++) {
                csum += packet[i];
                if (serio_write(elo->serio, packet[i]))
                        goto out;
        }

So if serio had an interface for sending a buffer, that would be less
call overhead. In fact, if the underlying serio is a serial usb port,
that would much more efficient on the usb layer too (one usb roundtrips in
stead of ELO10_PACKET_LEN roundtrips), like so:

	serio_write_buf(elo->serio, packet, ELO10_PACKET_LEN);

So what I'm suggesting is extending the serio interface to allow sending
a buffer of bytes. Of course serio isn't just usb serial ports. There quite
a few instances of serio_register_port() in the kernel. Many of them
can be extended to support sending a buffer rather than a single byte,
if this makes sense. For example the ps2 serio port takes a mutex for every
byte, so this could be more efficient by reducing it to one mutex lock
per buffer.

Now it would be nice to have a discussion about this rather than being
dismissed with:
quoted
quoted
Ummm, serial protocol data size is at most 9 bits so I have no earthly
idea how they expect to get 16.
Which is just a tad insulting.


Sean
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help