From mboxrd@z Thu Jan 1 00:00:00 1970 Return-path: Received: from mail-iy0-f177.google.com ([209.85.210.177]) by canuck.infradead.org with esmtps (Exim 4.76 #1 (Red Hat Linux)) id 1Qa6f9-0005R3-L3 for barebox@lists.infradead.org; Fri, 24 Jun 2011 13:43:12 +0000 Received: by iyn15 with SMTP id 15so2891824iyn.36 for ; Fri, 24 Jun 2011 06:43:03 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <1308606394-7510-1-git-send-email-h.feurstein@gmail.com> <1308606394-7510-2-git-send-email-h.feurstein@gmail.com> Date: Fri, 24 Jun 2011 15:43:02 +0200 Message-ID: From: Franck JULLIEN List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: multipart/mixed; boundary="===============0950614275==" Sender: barebox-bounces@lists.infradead.org Errors-To: barebox-bounces+u.kleine-koenig=pengutronix.de@lists.infradead.org Subject: Fwd: [RFC PATCH 2/3] spi: add more spi transfer functions To: barebox --===============0950614275== Content-Type: multipart/alternative; boundary=00151773e360643ef104a67561cf --00151773e360643ef104a67561cf Content-Type: text/plain; charset=ISO-8859-1 Hi Hubert, 2011/6/24 Hubert Feurstein > Hi Franck, > > 2011/6/23 Franck JULLIEN : > > Hello, I have a question regarding the SPI spi_write_then_read function. > > > [snip] > >> +int spi_write_then_read(struct spi_device *spi, > >> + const void *txbuf, unsigned n_tx, > > > > Could you explain me why const is used here ? > Because this function will *not* write to the data of txbuf. With the > const here, this is > ensured at least at syntax level. > OK. > > [snip] > > > > Then we call spi_sync then master->transfer. In this last function we > have: > > list_for_each_entry (t, &mesg->transfers, transfer_list) { > > const u32 *txbuf = t->tx_buf; <--- point to zero when x[1] right ????? > > u32 *rxbuf = t->rx_buf; <--- point to zero when x[0] right ????? > > int i = 0; > > while(i < t->len >> 2) { > > rxbuf[i] = imx->xchg_single(imx, txbuf[i]); > > i++; > > } > > } > > What am I missing ??? > Your transfer function has to handle this correctly: > while(i < t->len >> 2) { > u32 txval = txbuf ? txbuf[i] : 0 > u32 rxval = imx->xchg_single(imx, txval); > if (rxbuf) > rxbuf[i] = rxval; > i++; > } > That's what I was thinking about. The code above is from imx_spi.c. I am currently writing an Altera spi driver that's why I was looking at this... > If no txbuf is available then simply transfer 0, if no rxbuf is > available then throw away the result. > BTW, I'm not sure if the above transfer-handler is able to handle 8bit > transfers correctly (because of len >> 2). > > I agree. > Hope this helps. > > Best Regards > Hubert > Thanks, Franck. --00151773e360643ef104a67561cf Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
Hi Hubert,

2011/6/24 Hubert Feurstein <h.feurstein@gmail.com&g= t;
Hi Franck,

2011/6/23 Franck JULLIEN <franck.jullien@gmail.com>:
> Hello, I have a question regarding the SPI=A0spi_write_then_read = function.
>
[snip]
>> +int spi_write_then_read(struct spi_device *spi,
>> + =A0 =A0 =A0 =A0 =A0 =A0 =A0 const void *txbuf, unsigned n_tx, >
> Could you explain me why const is used here ?
Because this function will *not* write to the data of txbuf. With the=
const here, this is
ensured at least at syntax level.

OK.
=A0

[snip]
>
> Then we call spi_sync then=A0master->transfer. In this last functio= n we have:
> list_for_each_entry (t, &mesg->transfers, transfer_list) {
> const u32 *txbuf =3D t->tx_buf; =A0<--- point to zero=A0when x[1= ]=A0right ?????
> u32 *rxbuf =3D t->rx_buf; =A0 =A0 =A0 =A0<---=A0point to zero wh= en=A0x[0]=A0right ?????
> int i =3D 0;
> while(i < t->len >> 2) {
> rxbuf[i] =3D imx->xchg_single(imx, txbuf[i]);
> i++;
> }
> }
> What am I missing ???
Your =A0transfer function has to handle this correctly:
while(i < t->len >> 2) {
=A0u32 txval =3D txbuf ? txbuf[i] : 0
=A0u32 rxval =3D imx->xchg_single(imx, txval);
=A0if (rxbuf)
=A0 =A0rxbuf[i] =3D rxval;
=A0i++;
}

That's what I was thinking = about. The code above is from imx_spi.c. I am currently
writing a= n Altera spi driver that's why I was looking at this...

=A0
If no txbuf is available then simply transfer 0, if no rxbuf is
available then throw away the result.
BTW, I'm not sure if the above transfer-handler is able to handle 8bit<= br> transfers correctly (because of len >> 2).


I agree.
=
=A0
Hope this helps.

Best Regards
Hubert

Thanks,
Franck.

--00151773e360643ef104a67561cf-- --===============0950614275== Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox --===============0950614275==--