<div dir="ltr"><div><div>I also found that we having problems with MCP supply, so this is it! Thanks anish for your reply!<br><br></div>Cheers,<br></div>- dhs<br><div><div><div><br><br><div><div class="gmail_extra"><div class="gmail_quote">2015-09-09 15:30 GMT-03:00 Daniel. <span dir="ltr"><<a href="mailto:danielhilst@gmail.com" target="_blank">danielhilst@gmail.com</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I've checked the iomux configuration, there was some pins miss<br>
configured. Anyway I'm still losing IRQs. But now I have some hints<br>
from kernel. Now I see that I'm hitting this line:<br>
<a href="https://gist.github.com/gkos/4cce494e90518077084a#file-gpio-mcp23s08-c-L380" rel="noreferrer" target="_blank">https://gist.github.com/gkos/4cce494e90518077084a#file-gpio-mcp23s08-c-L380</a><br>
which traces to:<br>
<br>
<br>
spi32766-72 [000] .... 1728.245798: mcp23s17_produce_complete:<br>
mcp23s08: Error on SPI transfer, -115<br>
<br>
>From errno.h 115 means "operation in progress":<br>
<a href="http://lxr.free-electrons.com/source/include/uapi/asm-generic/errno.h?v=3.10#L88" rel="noreferrer" target="_blank">http://lxr.free-electrons.com/source/include/uapi/asm-generic/errno.h?v=3.10#L88</a><br>
<br>
So I need to take a look from ecspi (imx6 spi controller) code/clock/rates etc.<br>
<br>
Cheers,<br>
- dhs<br>
<div class="HOEnZb"><div class="h5"><br>
2015-09-08 18:23 GMT-03:00 Daniel. <<a href="mailto:danielhilst@gmail.com">danielhilst@gmail.com</a>>:<br>
> Even spi_async sleeps? I thought that spi_async wouldn't sleep :/<br>
><br>
> I have a board with an MCP23S17 gpio expander that is used as an<br>
> digital input. I need to notify my application every time that any<br>
> input status changes. The MCP triggers an interrupt every time that an<br>
> input changes, but, the application may not be able to poll the MCP at<br>
> the same rate that the input changes, so I used a circular queue at<br>
> MCP driver. I need to add input changes (readed from INTCAP) as soon<br>
> as they came, to be free to get new input changes as soon as possible.<br>
> I'm looking for 1ms resolution here, so, summarizing, I want to be<br>
> able to enqueue input changes at each 1ms.<br>
><br>
> The MCP works like this.<br>
><br>
> 1 - Input changes (set IRQ flags)<br>
> 2 - Raise IRQ<br>
> 3 - IRS reads INTCAP (this clears IRQ flags)<br>
><br>
> Okay, ... I was enqueing on the threaded IRQ, but was losing events.<br>
> The "losing events" here means that I got two interrupts in a row,<br>
> with same INTCAP values, so I got input changes notification (IRS<br>
> called) with no input changes. I think that a new interrupt is being<br>
> raised before I read INTCAP so it got masked. The big question is: How<br>
> to read INTCAP as fast as possible?<br>
><br>
> This is why I tried spi_async in interrupt context. (mcp_hard_irq),<br>
> but I'm still losing events at 1ms resolution.<br>
><br>
> So, explaning the mess I did in the code :), first of all I've updated<br>
> the code, is still in the same link:<br>
> <a href="https://gist.github.com/gkos/4cce494e90518077084a" rel="noreferrer" target="_blank">https://gist.github.com/gkos/4cce494e90518077084a</a><br>
><br>
> I've decided to use a producing/consuming aproach, since application<br>
> will never be abble to poll input status at same rate that it changes<br>
> I need to enqueue it. To do this I've created a new function inside<br>
> this module. mcp_getlast() should take the last element in queue, or<br>
> wait for next event if is empty, is my consumer, here it is:<br>
> <a href="https://gist.github.com/gkos/4cce494e90518077084a#file-gpio-mcp23s08-c-L182" rel="noreferrer" target="_blank">https://gist.github.com/gkos/4cce494e90518077084a#file-gpio-mcp23s08-c-L182</a><br>
><br>
> The procucer is the mcp23s17_produce_complete handler, it should<br>
> enqueue INTCAP and return. This is it!<br>
> <a href="https://gist.github.com/gkos/4cce494e90518077084a#file-gpio-mcp23s08-c-L346" rel="noreferrer" target="_blank">https://gist.github.com/gkos/4cce494e90518077084a#file-gpio-mcp23s08-c-L346</a><br>
><br>
> I've enabled tracing on my kernel (3.10.53 running on an i.MX6 quad).<br>
> At the trace file I got this lines:<br>
> spi32766-72 [000] d... 2589.220910:<br>
> mcp23s17_produce_complete: mcp23s08: produced ffffff01<br>
> spi32766-72 [000] d... 2589.222973:<br>
> mcp23s17_produce_complete: mcp23s08: produced ffffff00<br>
> spi32766-72 [000] d... 2589.223235:<br>
> mcp23s17_produce_complete: mcp23s08: produced ffffff01<br>
> spi32766-72 [000] d... 2589.226119:<br>
> mcp23s17_produce_complete: mcp23s08: produced ffffff00<br>
> spi32766-72 [000] d... 2589.227631:<br>
> mcp23s17_produce_complete: mcp23s08: produced ffffff00<br>
> spi32766-72 [000] d... 2589.227898:<br>
> mcp23s17_produce_complete: mcp23s08: produced ffffff01<br>
><br>
> There is possible see that INTCAP repeated (..ff00). This my problem!<br>
><br>
> Well, thanks anybody that readed that long, any ideia would be helpful<br>
><br>
> Best regards,<br>
><br>
><br>
> 2015-09-08 16:30 GMT-03:00 anish singh <<a href="mailto:anish198519851985@gmail.com">anish198519851985@gmail.com</a>>:<br>
>><br>
>><br>
>> On Tue, Sep 8, 2015 at 10:19 AM, Daniel. <<a href="mailto:danielhilst@gmail.com">danielhilst@gmail.com</a>> wrote:<br>
>>><br>
>>> Hi all,<br>
>>><br>
>>> I'm dealing with a SPI driver and I have a doubt. I need to read and write<br>
>>> data to spi (registers and values) inside interrupt handler. I want to know<br>
>>> if this pattern is safe or if I'll face problems with it.<br>
>><br>
>><br>
>> AFAIK the spi calls sleep, so it is not safe.<br>
>>><br>
>>><br>
>>> This code is being added to gpio-mcp23s08.c driver to handle IRQ and save<br>
>>> INTCAP at interruption time. INTCAP register keeps the input port status at<br>
>>> interruption time. I want to capture this as fast as possible and put it at<br>
>>> a circular queue. I write this code inspired by spi_sync function, but using<br>
>>> spinlocks so it doesn't sleeps. But, these spin_(un)lock calls seems a bad<br>
>>> ideia to me. Any better idea or guidelines?<br>
>>><br>
>>> Here is the code.<br>
>>><br>
>>> <a href="https://gist.github.com/gkos/4cce494e90518077084a#file-gpio-mcp23s08-c-L440" rel="noreferrer" target="_blank">https://gist.github.com/gkos/4cce494e90518077084a#file-gpio-mcp23s08-c-L440</a><br>
>>><br>
>>> The functions are mcp23s17_read_irqsafe and mcp23s17_read_irqsafe_complete<br>
>>><br>
>>> PS: The code is a little messed up (because I've been trying to optimize<br>
>>> this INTCAP capturing by many means)<br>
>>><br>
>> What exactly you are trying to optimize you have not mentioned. I looked at<br>
>> the driver code<br>
>> you pointed out in your mail and looks like they are using threaded irq and<br>
>> I am sure that you<br>
>> understand that threaded irq can perform sleeping operations as it is<br>
>> basically a kthread.<br>
>><br>
>> <a href="http://lxr.free-electrons.com/source/drivers/gpio/gpio-mcp23s08.c#L494" rel="noreferrer" target="_blank">http://lxr.free-electrons.com/source/drivers/gpio/gpio-mcp23s08.c#L494</a> so<br>
>> you can easily use<br>
>> spinlock here. It is not interrupt context.<br>
>><br>
>> Generally if you are trying to optimize something in linux kernel you should<br>
>> be very clear about your goal.<br>
>><br>
>>> Cheers<br>
>>> - dhs<br>
>>><br>
>>> --<br>
>>> "Do or do not. There is no try"<br>
>>> Yoda Master<br>
>>><br>
>>> _______________________________________________<br>
>>> Kernelnewbies mailing list<br>
>>> <a href="mailto:Kernelnewbies@kernelnewbies.org">Kernelnewbies@kernelnewbies.org</a><br>
>>> <a href="http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies" rel="noreferrer" target="_blank">http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies</a><br>
>>><br>
>><br>
><br>
><br>
><br>
> --<br>
> "Do or do not. There is no try"<br>
> Yoda Master<br>
<br>
<br>
<br>
--<br>
"Do or do not. There is no try"<br>
Yoda Master<br>
</div></div></blockquote></div><br><br clear="all"><br>-- <br><div class="gmail_signature"><div style="text-align:right"><i>"Do or do not. There is no try"</i><br><i> </i><i><b>Yoda Master</b></i><br></div></div>
</div></div></div></div></div></div>