All of lore.kernel.org
 help / color / mirror / Atom feed
* [U-Boot]  [PATCH 2/2] EXYNOS: SPI: Support SPI_PREAMBLE mode
@ 2013-05-03  4:53 Vadim Bendebury
  2013-05-03  5:12 ` Vadim Bendebury
  0 siblings, 1 reply; 9+ messages in thread
From: Vadim Bendebury @ 2013-05-03  4:53 UTC (permalink / raw)
  To: u-boot

[the original patch removed]

So, I spent some more time debugging a system which requires this
patch: a system, where on a SPI interface a response to a command
could come way later then the command data transmission completes.

The original patch was trying to address many corner cases, but come
to think of it, in this situation the slave does not care about extra
data sent on the transmit interface, as otherwise there is no clock
and no data could be transferred from the slave.

Then, for this SPI interface we do not need to set the counter of
clocks, and do not need to keep adding more clocks if the data has not
been received yet, the clocks could be just free running. And then the
patch becomes much simpler, what do you think:

diff --git a/drivers/spi/exynos_spi.c b/drivers/spi/exynos_spi.c
index c697db8..fff8310 100644
--- a/drivers/spi/exynos_spi.c
+++ b/drivers/spi/exynos_spi.c
@@ -211,10 +211,10 @@ static void spi_get_fifo_levels(struct exynos_spi *regs,
  */
 static void spi_request_bytes(struct exynos_spi *regs, int count)
 {
-       assert(count && count < (1 << 16));
        setbits_le32(&regs->ch_cfg, SPI_CH_RST);
        clrbits_le32(&regs->ch_cfg, SPI_CH_RST);
-       writel(count | SPI_PACKET_CNT_EN, &regs->pkt_cnt);
+       if (count)
+               writel(count | SPI_PACKET_CNT_EN, &regs->pkt_cnt);
 }

 static void spi_rx_tx(struct exynos_spi_slave *spi_slave, int todo,
@@ -225,14 +225,20 @@ static void spi_rx_tx(struct exynos_spi_slave
*spi_slave, int todo,
        const uchar *txp = *doutp;
        int rx_lvl, tx_lvl;
        uint out_bytes, in_bytes;
-
+       int hunting;
+
+       if (spi_slave->free_running_mode) {
+               spi_request_bytes(regs, 0);
+               hunting = 1;
+       } else {
+               hunting = 0;
+               spi_request_bytes(regs, todo);
+       }
        out_bytes = in_bytes = todo;

-       /*
-        * If there's something to send, do a software reset and set a
-        * transaction size.
-        */
-       spi_request_bytes(regs, todo);
+       /* Software reset the channel. */
+       setbits_le32(&regs->ch_cfg, SPI_CH_RST);
+       clrbits_le32(&regs->ch_cfg, SPI_CH_RST);

        /*
         * Bytes are transmitted/received in pairs. Wait to receive all the
@@ -243,13 +249,23 @@ static void spi_rx_tx(struct exynos_spi_slave
*spi_slave, int todo,

                /* Keep the fifos full/empty. */
                spi_get_fifo_levels(regs, &rx_lvl, &tx_lvl);
-               if (tx_lvl < spi_slave->fifo_size && out_bytes) {
-                       temp = txp ? *txp++ : 0xff;
+               if (tx_lvl < spi_slave->fifo_size) {
+                       if (txp && out_bytes) {
+                               temp = *txp++;
+                               out_bytes--;
+                       } else {
+                               temp = 0xff;
+                       }
                        writel(temp, &regs->tx_data);
-                       out_bytes--;
                }
                if (rx_lvl > 0 && in_bytes) {
                        temp = readl(&regs->rx_data);
+                       if (hunting) {
+                               if ((temp & 0xff) != PREAMBLE_VALUE)
+                                       continue;
+                               else
+                                       hunting = 0;
+                       }
                        if (rxp)
                                *rxp++ = temp;
                        in_bytes--;

^ permalink raw reply related	[flat|nested] 9+ messages in thread
* [U-Boot] [PATCH 0/2] SPI: Enable SPI_PREAMBLE Mode
@ 2013-03-22  6:29 Rajeshwari Shinde
  2013-03-22  6:29 ` [U-Boot] [PATCH 2/2] EXYNOS: SPI: Support SPI_PREAMBLE mode Rajeshwari Shinde
  0 siblings, 1 reply; 9+ messages in thread
From: Rajeshwari Shinde @ 2013-03-22  6:29 UTC (permalink / raw)
  To: u-boot

This patch set enables PREAMBLE Mode for EXYNOS SPI.
 
Rajeshwari Shinde (2):
  SPI: Add support for preamble bytes
  EXYNOS: SPI: Support SPI_PREAMBLE mode

 drivers/spi/exynos_spi.c |   62 ++++++++++++++++++++++++++++++++++++++++------
 include/spi.h            |    5 +++
 2 files changed, 59 insertions(+), 8 deletions(-)

-- 
1.7.4.4

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2013-05-11 21:38 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-03  4:53 [U-Boot] [PATCH 2/2] EXYNOS: SPI: Support SPI_PREAMBLE mode Vadim Bendebury
2013-05-03  5:12 ` Vadim Bendebury
2013-05-06 14:37   ` Simon Glass
2013-05-06 16:01     ` Vadim Bendebury
2013-05-11 21:38       ` Simon Glass
  -- strict thread matches above, loose matches on Subject: below --
2013-03-22  6:29 [U-Boot] [PATCH 0/2] SPI: Enable SPI_PREAMBLE Mode Rajeshwari Shinde
2013-03-22  6:29 ` [U-Boot] [PATCH 2/2] EXYNOS: SPI: Support SPI_PREAMBLE mode Rajeshwari Shinde
2013-05-03  1:28   ` Vadim Bendebury
2013-05-06 12:06     ` Simon Glass
2013-05-11 14:41     ` Simon Glass

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.