Commit eb94b74c authored by Marc Kleine-Budde's avatar Marc Kleine-Budde

can: mcp251xfd: simplify UINC handling

In the patches:

| 1f652bb6 can: mcp25xxfd: rx-path: reduce number of SPI core requests to set UINC bit
| 68c0c1c7 can: mcp251xfd: tef-path: reduce number of SPI core requests to set UINC bit

the setting of the UINC bit in the TEF and RX FIFO was batched into a
single SPI message consisting of several transfers. All transfers but
the last need to have the cs_change set to 1.

In the original patches the array of prepared transfers is send from
the beginning with the length depending on the number of read TEF/RX
objects. The cs_change of the last transfer is temporarily set to
0 during send.

This patch removes the modification of cs_change by preparing the last
transfer with cs_change to 0 and all other to 1. When sending the SPI
message the driver now starts with an offset into the array, so that
it always ends on the last entry in the array, which has the cs_change
set to 0.

Link: https://lore.kernel.org/r/20210304160328.2752293-3-mkl@pengutronix.deSigned-off-by: default avatarMarc Kleine-Budde <mkl@pengutronix.de>
parent e0ab3dd5
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// //
// mcp251xfd - Microchip MCP251xFD Family CAN controller driver // mcp251xfd - Microchip MCP251xFD Family CAN controller driver
// //
// Copyright (c) 2019, 2020 Pengutronix, // Copyright (c) 2019, 2020, 2021 Pengutronix,
// Marc Kleine-Budde <kernel@pengutronix.de> // Marc Kleine-Budde <kernel@pengutronix.de>
// //
// Based on: // Based on:
...@@ -330,6 +330,7 @@ static void mcp251xfd_ring_init(struct mcp251xfd_priv *priv) ...@@ -330,6 +330,7 @@ static void mcp251xfd_ring_init(struct mcp251xfd_priv *priv)
struct mcp251xfd_tx_ring *tx_ring; struct mcp251xfd_tx_ring *tx_ring;
struct mcp251xfd_rx_ring *rx_ring, *prev_rx_ring = NULL; struct mcp251xfd_rx_ring *rx_ring, *prev_rx_ring = NULL;
struct mcp251xfd_tx_obj *tx_obj; struct mcp251xfd_tx_obj *tx_obj;
struct spi_transfer *xfer;
u32 val; u32 val;
u16 addr; u16 addr;
u8 len; u8 len;
...@@ -347,8 +348,6 @@ static void mcp251xfd_ring_init(struct mcp251xfd_priv *priv) ...@@ -347,8 +348,6 @@ static void mcp251xfd_ring_init(struct mcp251xfd_priv *priv)
addr, val, val); addr, val, val);
for (j = 0; j < ARRAY_SIZE(tef_ring->uinc_xfer); j++) { for (j = 0; j < ARRAY_SIZE(tef_ring->uinc_xfer); j++) {
struct spi_transfer *xfer;
xfer = &tef_ring->uinc_xfer[j]; xfer = &tef_ring->uinc_xfer[j];
xfer->tx_buf = &tef_ring->uinc_buf; xfer->tx_buf = &tef_ring->uinc_buf;
xfer->len = len; xfer->len = len;
...@@ -357,6 +356,15 @@ static void mcp251xfd_ring_init(struct mcp251xfd_priv *priv) ...@@ -357,6 +356,15 @@ static void mcp251xfd_ring_init(struct mcp251xfd_priv *priv)
xfer->cs_change_delay.unit = SPI_DELAY_UNIT_NSECS; xfer->cs_change_delay.unit = SPI_DELAY_UNIT_NSECS;
} }
/* "cs_change == 1" on the last transfer results in an active
* chip select after the complete SPI message. This causes the
* controller to interpret the next register access as
* data. Set "cs_change" of the last transfer to "0" to
* properly deactivate the chip select at the end of the
* message.
*/
xfer->cs_change = 0;
/* TX */ /* TX */
tx_ring = priv->tx; tx_ring = priv->tx;
tx_ring->head = 0; tx_ring->head = 0;
...@@ -397,8 +405,6 @@ static void mcp251xfd_ring_init(struct mcp251xfd_priv *priv) ...@@ -397,8 +405,6 @@ static void mcp251xfd_ring_init(struct mcp251xfd_priv *priv)
addr, val, val); addr, val, val);
for (j = 0; j < ARRAY_SIZE(rx_ring->uinc_xfer); j++) { for (j = 0; j < ARRAY_SIZE(rx_ring->uinc_xfer); j++) {
struct spi_transfer *xfer;
xfer = &rx_ring->uinc_xfer[j]; xfer = &rx_ring->uinc_xfer[j];
xfer->tx_buf = &rx_ring->uinc_buf; xfer->tx_buf = &rx_ring->uinc_buf;
xfer->len = len; xfer->len = len;
...@@ -406,6 +412,15 @@ static void mcp251xfd_ring_init(struct mcp251xfd_priv *priv) ...@@ -406,6 +412,15 @@ static void mcp251xfd_ring_init(struct mcp251xfd_priv *priv)
xfer->cs_change_delay.value = 0; xfer->cs_change_delay.value = 0;
xfer->cs_change_delay.unit = SPI_DELAY_UNIT_NSECS; xfer->cs_change_delay.unit = SPI_DELAY_UNIT_NSECS;
} }
/* "cs_change == 1" on the last transfer results in an
* active chip select after the complete SPI
* message. This causes the controller to interpret
* the next register access as data. Set "cs_change"
* of the last transfer to "0" to properly deactivate
* the chip select at the end of the message.
*/
xfer->cs_change = 0;
} }
} }
...@@ -1366,25 +1381,20 @@ static int mcp251xfd_handle_tefif(struct mcp251xfd_priv *priv) ...@@ -1366,25 +1381,20 @@ static int mcp251xfd_handle_tefif(struct mcp251xfd_priv *priv)
if (len) { if (len) {
struct mcp251xfd_tef_ring *ring = priv->tef; struct mcp251xfd_tef_ring *ring = priv->tef;
struct mcp251xfd_tx_ring *tx_ring = priv->tx; struct mcp251xfd_tx_ring *tx_ring = priv->tx;
struct spi_transfer *last_xfer; int offset;
/* Increment the TEF FIFO tail pointer 'len' times in /* Increment the TEF FIFO tail pointer 'len' times in
* a single SPI message. * a single SPI message.
* *
* Note: * Note:
* * Calculate offset, so that the SPI transfer ends on
* "cs_change == 1" on the last transfer results in an * the last message of the uinc_xfer array, which has
* active chip select after the complete SPI * "cs_change == 0", to properly deactivate the chip
* message. This causes the controller to interpret * select.
* the next register access as data. Temporary set
* "cs_change" of the last transfer to "0" to properly
* deactivate the chip select at the end of the
* message.
*/ */
last_xfer = &ring->uinc_xfer[len - 1]; offset = ARRAY_SIZE(ring->uinc_xfer) - len;
last_xfer->cs_change = 0; err = spi_sync_transfer(priv->spi,
err = spi_sync_transfer(priv->spi, ring->uinc_xfer, len); ring->uinc_xfer + offset, len);
last_xfer->cs_change = 1;
if (err) if (err)
return err; return err;
...@@ -1536,7 +1546,7 @@ mcp251xfd_handle_rxif_ring(struct mcp251xfd_priv *priv, ...@@ -1536,7 +1546,7 @@ mcp251xfd_handle_rxif_ring(struct mcp251xfd_priv *priv,
return err; return err;
while ((len = mcp251xfd_get_rx_linear_len(ring))) { while ((len = mcp251xfd_get_rx_linear_len(ring))) {
struct spi_transfer *last_xfer; int offset;
rx_tail = mcp251xfd_get_rx_tail(ring); rx_tail = mcp251xfd_get_rx_tail(ring);
...@@ -1557,19 +1567,14 @@ mcp251xfd_handle_rxif_ring(struct mcp251xfd_priv *priv, ...@@ -1557,19 +1567,14 @@ mcp251xfd_handle_rxif_ring(struct mcp251xfd_priv *priv,
* single SPI message. * single SPI message.
* *
* Note: * Note:
* * Calculate offset, so that the SPI transfer ends on
* "cs_change == 1" on the last transfer results in an * the last message of the uinc_xfer array, which has
* active chip select after the complete SPI * "cs_change == 0", to properly deactivate the chip
* message. This causes the controller to interpret * select.
* the next register access as data. Temporary set
* "cs_change" of the last transfer to "0" to properly
* deactivate the chip select at the end of the
* message.
*/ */
last_xfer = &ring->uinc_xfer[len - 1]; offset = ARRAY_SIZE(ring->uinc_xfer) - len;
last_xfer->cs_change = 0; err = spi_sync_transfer(priv->spi,
err = spi_sync_transfer(priv->spi, ring->uinc_xfer, len); ring->uinc_xfer + offset, len);
last_xfer->cs_change = 1;
if (err) if (err)
return err; return err;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment