SPI operations on interrupt context!?
anish singh
anish198519851985 at gmail.com
Tue Sep 8 15:30:01 EDT 2015
On Tue, Sep 8, 2015 at 10:19 AM, Daniel. <danielhilst at gmail.com> wrote:
> Hi all,
>
> I'm dealing with a SPI driver and I have a doubt. I need to read and write
> data to spi (registers and values) inside interrupt handler. I want to know
> if this pattern is safe or if I'll face problems with it.
>
AFAIK the spi calls sleep, so it is not safe.
>
> This code is being added to gpio-mcp23s08.c driver to handle IRQ and save
> INTCAP at interruption time. INTCAP register keeps the input port status at
> interruption time. I want to capture this as fast as possible and put it at
> a circular queue. I write this code inspired by spi_sync function, but
> using spinlocks so it doesn't sleeps. But, these spin_(un)lock calls seems
> a bad ideia to me. Any better idea or guidelines?
>
> Here is the code.
> https://gist.github.com/gkos/4cce494e90518077084a#file-gpio-mcp23s08-c-L440
>
> The functions are mcp23s17_read_irqsafe and mcp23s17_read_irqsafe_complete
>
> PS: The code is a little messed up (because I've been trying to optimize
> this INTCAP capturing by many means)
>
> What exactly you are trying to optimize you have not mentioned. I looked
at the driver code
you pointed out in your mail and looks like they are using threaded irq and
I am sure that you
understand that threaded irq can perform sleeping operations as it is
basically a kthread.
http://lxr.free-electrons.com/source/drivers/gpio/gpio-mcp23s08.c#L494 so
you can easily use
spinlock here. It is not interrupt context.
Generally if you are trying to optimize something in linux kernel you
should be very clear about your goal.
Cheers
> - dhs
>
> --
> *"Do or do not. There is no try"*
> *Yoda Master*
>
> _______________________________________________
> Kernelnewbies mailing list
> Kernelnewbies at kernelnewbies.org
> http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.kernelnewbies.org/pipermail/kernelnewbies/attachments/20150908/0d571a92/attachment.html
More information about the Kernelnewbies
mailing list