Building a software serial driver

Pranay Srivastava pranjas at gmail.com
Tue Jun 24 04:12:35 EDT 2014


Hi Torrie

On Mon, Jun 23, 2014 at 11:45 PM, Torrie Fischer
<tdfischer at hackerbots.net> wrote:
> Greetings fellow newbies.
>
> I'm toying around with a Raspberry PI and trying to create a driver that takes
> a single GPIO pin and turns it into a read-only TTY device because using the
> userspace GPIO sysfs API is too slow for me.
>
> Here's my current code:
>
> https://github.com/tdfischer/gpio_serial
>
> It is based off of the tiny_serial example driver in the LDD3 repo:
>
> https://github.com/martinezjavier/ldd3/blob/master/tty/tiny_serial.c
>

I looked at uart_register code, it seems there's no read callback so
that's why you are getting that -EIO.
I don't think you've to change a lot of code but I looked up and found

tty_flip_buffer_push

For the above you can get the tty from the uart_driver->tty_driver. It
uses the tty_port as an argument which you can get with your line as
index into the uart_driver->tty_driver->ports[line_number].

Your data would be going into a circular buffer for this uart so I
think all you need to do is push this. See the uart_ops structure you
can see there which ones are being called.

The buffer you would be writing to seems to be a page and is circular
buffer. So you'll need to check when you are about to write the last
byte then you'll need to flush it. You just need to provide the
flushing part in start_xmit since that is taken care of by uart_write
as I see.

I think you can put this call in your start_tx since uart_start is
calling port->start_tx at the end so i guess you should be good there.

I don't have much idea how will you read from it though.

> It builds and loads just fine, and even creates a /dev/ttyGPIO0 device.
> However, reading from it returns -EIO. Running strace on cat shows that it
> opens up the device successfully, but fails on the first call to read().
>
> Any idea what I'm missing here? I'm fairly certain it is something obvious.
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>



-- 
        ---P.K.S



More information about the Kernelnewbies mailing list