All of lore.kernel.org
 help / color / mirror / Atom feed
From: Vadim Bendebury <vbendeb@chromium.org>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/2] EXYNOS: SPI: Support SPI_PREAMBLE mode
Date: Thu, 2 May 2013 22:12:33 -0700	[thread overview]
Message-ID: <CANy1buL7pxzB9DfDHMV8ZTwbMohF1ai6GcB=h69nUUpxNq4Mgw@mail.gmail.com> (raw)
In-Reply-To: <CANy1buKoxRRKBr7s2kg0uOZ4HRi2La=9HJagqQ+HZ+VMLBN=8A@mail.gmail.com>

[the original patch removed, re-sending from a registered address]

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--;

  reply	other threads:[~2013-05-03  5:12 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
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

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CANy1buL7pxzB9DfDHMV8ZTwbMohF1ai6GcB=h69nUUpxNq4Mgw@mail.gmail.com' \
    --to=vbendeb@chromium.org \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.