<div class="gmail_quote">Hi Hubert,<br><br><div class="gmail_quote"><div class="im">2011/6/24 Hubert Feurstein <span dir="ltr"><<a href="mailto:h.feurstein@gmail.com" target="_blank">h.feurstein@gmail.com</a>></span><br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Franck,<br>
<br>
2011/6/23 Franck JULLIEN <<a href="mailto:franck.jullien@gmail.com" target="_blank">franck.jullien@gmail.com</a>>:<br>
<div>> Hello, I have a question regarding the SPI spi_write_then_read function.<br>
><br>
</div>[snip]<br>
<div>>> +int spi_write_then_read(struct spi_device *spi,<br>
>> + const void *txbuf, unsigned n_tx,<br>
><br>
> Could you explain me why const is used here ?<br>
</div>Because this function will *not* write to the data of txbuf. With the<br>
const here, this is<br>
ensured at least at syntax level.<br></blockquote><div><br></div></div><div>OK.</div><div class="im"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
[snip]<br>
<div>><br>
> Then we call spi_sync then master->transfer. In this last function we have:<br>
> list_for_each_entry (t, &mesg->transfers, transfer_list) {<br>
> const u32 *txbuf = t->tx_buf; <--- point to zero when x[1] right ?????<br>
> u32 *rxbuf = t->rx_buf; <--- point to zero when x[0] right ?????<br>
> int i = 0;<br>
> while(i < t->len >> 2) {<br>
> rxbuf[i] = imx->xchg_single(imx, txbuf[i]);<br>
> i++;<br>
> }<br>
> }<br>
> What am I missing ???<br>
</div>Your transfer function has to handle this correctly:<br>
<div>while(i < t->len >> 2) {<br>
</div> u32 txval = txbuf ? txbuf[i] : 0<br>
u32 rxval = imx->xchg_single(imx, txval);<br>
if (rxbuf)<br>
rxbuf[i] = rxval;<br>
i++;<br>
}<br></blockquote><div><br></div></div><div>That's what I was thinking about. The code above is from imx_spi.c. I am currently</div><div>writing an Altera spi driver that's why I was looking at this...</div><div class="im">
<div><br></div>
<div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
If no txbuf is available then simply transfer 0, if no rxbuf is<br>
available then throw away the result.<br>
BTW, I'm not sure if the above transfer-handler is able to handle 8bit<br>
transfers correctly (because of len >> 2).<br>
<br></blockquote><div><br></div></div><div>I agree.</div><div class="im"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hope this helps.<br>
<br>
Best Regards<br>
<font color="#888888">Hubert<br>
</font></blockquote></div></div><br><div>Thanks,</div><div>Franck.</div>
</div><br>