* Building a software serial driver @ 2014-06-23 18:15 Torrie Fischer 2014-06-24 8:12 ` Pranay Srivastava 0 siblings, 1 reply; 6+ messages in thread From: Torrie Fischer @ 2014-06-23 18:15 UTC (permalink / raw) To: kernelnewbies 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 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. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part. Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140623/f42481d0/attachment.bin ^ permalink raw reply [flat|nested] 6+ messages in thread
* Building a software serial driver 2014-06-23 18:15 Building a software serial driver Torrie Fischer @ 2014-06-24 8:12 ` Pranay Srivastava 2014-06-24 12:56 ` Torrie Fischer 0 siblings, 1 reply; 6+ messages in thread From: Pranay Srivastava @ 2014-06-24 8:12 UTC (permalink / raw) To: kernelnewbies Hi Torrie On Mon, Jun 23, 2014 at 11:45 PM, Torrie Fischer <tdfischer@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 ^ permalink raw reply [flat|nested] 6+ messages in thread
* Building a software serial driver 2014-06-24 8:12 ` Pranay Srivastava @ 2014-06-24 12:56 ` Torrie Fischer 2014-06-24 15:57 ` Pranay Srivastava 0 siblings, 1 reply; 6+ messages in thread From: Torrie Fischer @ 2014-06-24 12:56 UTC (permalink / raw) To: kernelnewbies Hi, Pranay. Thanks for having a look. On Tuesday, June 24, 2014 13:42:35 Pranay Srivastava wrote: > > I looked at uart_register code, it seems there's no read callback so > that's why you are getting that -EIO. >From what I understand, I'm supposed to set up the interrupts needed in the startup function which is called when the device is opened. This never happens though, as adding a printk results in no output. > 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 suspect that start_tx is not getting called since adding a printk in my start_tx function doesn't result in any output. > > I don't have much idea how will you read from it though. I'm able to read from it by waiting for a rising edge interrupt and then bit- banging the GPIO line in userspace, though at a slow baud that is unusable. I need 9600 to read from my device :) -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part. Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140624/8352ed4f/attachment.bin ^ permalink raw reply [flat|nested] 6+ messages in thread
* Building a software serial driver 2014-06-24 12:56 ` Torrie Fischer @ 2014-06-24 15:57 ` Pranay Srivastava 2014-06-24 18:19 ` Torrie Fischer 0 siblings, 1 reply; 6+ messages in thread From: Pranay Srivastava @ 2014-06-24 15:57 UTC (permalink / raw) To: kernelnewbies Hi Torrie, On Tue, Jun 24, 2014 at 6:26 PM, Torrie Fischer <tdfischer@hackerbots.net> wrote: > Hi, Pranay. > > Thanks for having a look. > > On Tuesday, June 24, 2014 13:42:35 Pranay Srivastava wrote: >> >> I looked at uart_register code, it seems there's no read callback so >> that's why you are getting that -EIO. > > From what I understand, I'm supposed to set up the interrupts needed in the > startup function which is called when the device is opened. This never happens > though, as adding a printk results in no output. I think this might be causing it, if you see tty_open then it has a call to , tty_open_current_tty , this seems to be the only one which I think is not making the driver being looked up and hence no uport->open so in case there's an already a tty attached to current then i think it isn't opening a new one. Maybe you need to detach this tty? Not so sure I'll look again what can be done. > >> 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 suspect that start_tx is not getting called since adding a printk in my > start_tx function doesn't result in any output. > >> >> I don't have much idea how will you read from it though. > > I'm able to read from it by waiting for a rising edge interrupt and then bit- > banging the GPIO line in userspace, though at a slow baud that is unusable. I > need 9600 to read from my device :) Ok good!. I don't have much idea about GPIO. While searching I found there's a GPIO library for Raspi. I don't know how much help that would be but i guess you don't want to use it. -- ---P.K.S ^ permalink raw reply [flat|nested] 6+ messages in thread
* Building a software serial driver 2014-06-24 15:57 ` Pranay Srivastava @ 2014-06-24 18:19 ` Torrie Fischer 2014-06-25 5:56 ` Pranay Srivastava 0 siblings, 1 reply; 6+ messages in thread From: Torrie Fischer @ 2014-06-24 18:19 UTC (permalink / raw) To: kernelnewbies Apparently all I had to do was set the type attribute on the uart_port structure to anything that isn't PORT_UNKNOWN. Here's a functional driver that takes a GPIO pin and creates a read-only serial TTY: https://github.com/tdfischer/gpio_serial/blob/master/gpiotty.c :) On Tuesday, June 24, 2014 21:27:46 Pranay Srivastava wrote: > Hi Torrie, > > On Tue, Jun 24, 2014 at 6:26 PM, Torrie Fischer > > <tdfischer@hackerbots.net> wrote: > > Hi, Pranay. > > > > Thanks for having a look. > > > > On Tuesday, June 24, 2014 13:42:35 Pranay Srivastava wrote: > >> I looked at uart_register code, it seems there's no read callback so > >> that's why you are getting that -EIO. > > > > From what I understand, I'm supposed to set up the interrupts needed in > > the > > startup function which is called when the device is opened. This never > > happens though, as adding a printk results in no output. > > I think this might be causing it, if you see tty_open then it has a call to > , > > tty_open_current_tty , this seems to be the only one which I think is > not making the driver being looked up and hence no uport->open > > so in case there's an already a tty attached to current then i think > it isn't opening > a new one. Maybe you need to detach this tty? Not so sure I'll look > again what can be done. > > >> 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 suspect that start_tx is not getting called since adding a printk in my > > start_tx function doesn't result in any output. > > > >> I don't have much idea how will you read from it though. > > > > I'm able to read from it by waiting for a rising edge interrupt and then > > bit- banging the GPIO line in userspace, though at a slow baud that is > > unusable. I need 9600 to read from my device :) > > Ok good!. I don't have much idea about GPIO. While searching I found > there's a GPIO library for Raspi. I don't know how much help that > would be but i > guess you don't want to use it. -------------- next part -------------- A non-text attachment was scrubbed... Name: not available Type: application/pgp-signature Size: 198 bytes Desc: This is a digitally signed message part. Url : http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20140624/855dadf3/attachment.bin ^ permalink raw reply [flat|nested] 6+ messages in thread
* Building a software serial driver 2014-06-24 18:19 ` Torrie Fischer @ 2014-06-25 5:56 ` Pranay Srivastava 0 siblings, 0 replies; 6+ messages in thread From: Pranay Srivastava @ 2014-06-25 5:56 UTC (permalink / raw) To: kernelnewbies On Tue, Jun 24, 2014 at 11:49 PM, Torrie Fischer <tdfischer@hackerbots.net> wrote: > Apparently all I had to do was set the type attribute on the uart_port > structure to anything that isn't PORT_UNKNOWN. > Arhh.. I see. I overlooked that since tty->type was being set. Good to know you got it working. > Here's a functional driver that takes a GPIO pin and creates a read-only > serial TTY: So multiple open don't harm? The startup routine is called only once is that right? > > https://github.com/tdfischer/gpio_serial/blob/master/gpiotty.c > > :) > > On Tuesday, June 24, 2014 21:27:46 Pranay Srivastava wrote: >> Hi Torrie, >> >> On Tue, Jun 24, 2014 at 6:26 PM, Torrie Fischer >> >> <tdfischer@hackerbots.net> wrote: >> > Hi, Pranay. >> > >> > Thanks for having a look. >> > >> > On Tuesday, June 24, 2014 13:42:35 Pranay Srivastava wrote: >> >> I looked at uart_register code, it seems there's no read callback so >> >> that's why you are getting that -EIO. >> > >> > From what I understand, I'm supposed to set up the interrupts needed in >> > the >> > startup function which is called when the device is opened. This never >> > happens though, as adding a printk results in no output. >> >> I think this might be causing it, if you see tty_open then it has a call to >> , >> >> tty_open_current_tty , this seems to be the only one which I think is >> not making the driver being looked up and hence no uport->open >> >> so in case there's an already a tty attached to current then i think >> it isn't opening >> a new one. Maybe you need to detach this tty? Not so sure I'll look >> again what can be done. >> >> >> 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 suspect that start_tx is not getting called since adding a printk in my >> > start_tx function doesn't result in any output. >> > >> >> I don't have much idea how will you read from it though. >> > >> > I'm able to read from it by waiting for a rising edge interrupt and then >> > bit- banging the GPIO line in userspace, though at a slow baud that is >> > unusable. I need 9600 to read from my device :) >> >> Ok good!. I don't have much idea about GPIO. While searching I found >> there's a GPIO library for Raspi. I don't know how much help that >> would be but i >> guess you don't want to use it. -- ---P.K.S ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2014-06-25 5:56 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-06-23 18:15 Building a software serial driver Torrie Fischer 2014-06-24 8:12 ` Pranay Srivastava 2014-06-24 12:56 ` Torrie Fischer 2014-06-24 15:57 ` Pranay Srivastava 2014-06-24 18:19 ` Torrie Fischer 2014-06-25 5:56 ` Pranay Srivastava
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.