[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <36b04940-83a6-93a7-f7e1-d0acc8c135d9@pengutronix.de>
Date: Wed, 15 Nov 2017 13:40:04 +0100
From: Marc Kleine-Budde <mkl@...gutronix.de>
To: Jan Glauber <jan.glauber@...iumnetworks.com>
Cc: Mark Brown <broonie@...nel.org>,
Tim Harvey <tharvey@...eworks.com>, linux-spi@...r.kernel.org,
"linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
Wolfgang Grandegger <wg@...ndegger.com>,
linux-can <linux-can@...r.kernel.org>
Subject: Re: MCP251x SPI CAN controller on Cavium ThunderX
On 11/15/2017 01:07 PM, Jan Glauber wrote:
> On Wed, Nov 15, 2017 at 11:54:20AM +0100, Marc Kleine-Budde wrote:
>> On 11/14/2017 01:02 PM, Mark Brown wrote:
>>> On Mon, Nov 13, 2017 at 01:17:42PM -0800, Tim Harvey wrote:
>>>
>>>> When a register is read from the mcp251x driver the
>>>> octeon_spi_do_transfer() gets a spi_message with a single spi_xfer of
>>>> len=3, a tx_buf, and an rx_buf which I believe is supposed to shift
>>>> out 3 bytes out MOSI and shift in 3 bytes from MISO where the last
>>>> byte shifted in would be the response.
>>>
>>> No, that will simultaneously transmit and recieve three bytes.
>>
>> That's what the driver supposed to do.
>>
>>> If you want to transmit two bytes and then recieve one byte you need
>>> two xfers, one with a len of 2 and a tx_buf, the other with a len of
>>> 1 and a rx_buf.
>> To read a register (mcp251x_read_reg()) the mcp251x does a 3 byte full
>> duplex transfer. The first byte send is the command (read register) the
>> second byte the register number the third byte is a dummy. The first 2
>> bytes received are ignored the 3rd byte is the register contents.
>
> To support this full duplex transfer the Cavium SPI controller needs
> to know the receive lenght before setting up the transaction.
>
> spi_transfer only includes the total length, so I don't see how this
> should work.
It's a standard 3 byte full duplex transfer. Three bytes are send while
three bytes are received.
> static int mcp251x_spi_trans(struct spi_device *spi, int len)
> {
> struct mcp251x_priv *priv = spi_get_drvdata(spi);
> struct spi_transfer t = {
> .tx_buf = priv->spi_tx_buf,
> .rx_buf = priv->spi_rx_buf,
> .len = len,
> .cs_change = 0,
> };
> struct spi_message m;
> int ret;
>
> spi_message_init(&m);
>
> if (mcp251x_enable_dma) {
> t.tx_dma = priv->spi_tx_dma;
> t.rx_dma = priv->spi_rx_dma;
> m.is_dma_mapped = 1;
> }
>
> spi_message_add_tail(&t, &m);
>
> ret = spi_sync(spi, &m);
> if (ret)
> dev_err(&spi->dev, "spi transfer failed: ret = %d\n", ret);
> return ret;
> }
mcp251x_spi_trans() is called with len=3,
priv->spi_tx_buf and priv->spi_rx_buf point to previously allocared memory
priv->spi_tx_buf has been filled before calling mcp251x_spi_trans().
Marc
--
Pengutronix e.K. | Marc Kleine-Budde |
Industrial Linux Solutions | Phone: +49-231-2826-924 |
Vertretung West/Dortmund | Fax: +49-5121-206917-5555 |
Amtsgericht Hildesheim, HRA 2686 | http://www.pengutronix.de |
Download attachment "signature.asc" of type "application/pgp-signature" (489 bytes)
Powered by blists - more mailing lists