From: Vignesh R <vigneshr@ti.com>
To: Mark Brown <broonie@kernel.org>,
David Woodhouse <dwmw2@infradead.org>,
Brian Norris <computersforpeace@gmail.com>,
Tony Lindgren <tony@atomide.com>,
Russell King <linux@arm.linux.org.uk>
Cc: Huang Shijie <b32955@freescale.com>, Vignesh R <vigneshr@ti.com>,
linux-omap@vger.kernel.org, devicetree@vger.kernel.org,
linux-arm-kernel@lists.infradead.org,
linux-kernel@vger.kernel.org, linux-mtd@lists.infradead.org,
linux-spi@vger.kernel.org
Subject: [RFC PATCH 2/5] spi: spi-ti-qspi: Add memory mapped read support
Date: Tue, 28 Jul 2015 14:11:13 +0530 [thread overview]
Message-ID: <1438072876-16338-3-git-send-email-vigneshr@ti.com> (raw)
In-Reply-To: <1438072876-16338-1-git-send-email-vigneshr@ti.com>
TI QSPI controller has memory mapped port through which SPI flash
memories can be read using memcpy call. This patch adds support for
memory mapped read based on use_mmap_read flag.
When use_mmap_read flag is set, the controller is switched to memory
mapped interface by writing to QSPI_SPI_SWITCH_REG. The read_opcode,
read mode, dummy bytes are configured in QSPI_SPI_SETUPx_REG, then
memcpy is called to copy the requested data from flash to the rx_buf.
With this patch, the read speed increased from ~100kB/s to ~2.5MB/s on
DRA74 EVM.
Signed-off-by: Vignesh R <vigneshr@ti.com>
---
drivers/spi/spi-ti-qspi.c | 129 ++++++++++++++++++++++++++++++++++++++++++++--
1 file changed, 125 insertions(+), 4 deletions(-)
diff --git a/drivers/spi/spi-ti-qspi.c b/drivers/spi/spi-ti-qspi.c
index 5c0616870358..45844a227c5e 100644
--- a/drivers/spi/spi-ti-qspi.c
+++ b/drivers/spi/spi-ti-qspi.c
@@ -71,11 +71,8 @@ struct ti_qspi {
#define QSPI_SPI_CMD_REG (0x48)
#define QSPI_SPI_STATUS_REG (0x4c)
#define QSPI_SPI_DATA_REG (0x50)
-#define QSPI_SPI_SETUP0_REG (0x54)
+#define QSPI_SPI_SETUP_REG(n) (0x54 + 4 * n)
#define QSPI_SPI_SWITCH_REG (0x64)
-#define QSPI_SPI_SETUP1_REG (0x58)
-#define QSPI_SPI_SETUP2_REG (0x5c)
-#define QSPI_SPI_SETUP3_REG (0x60)
#define QSPI_SPI_DATA_REG_1 (0x68)
#define QSPI_SPI_DATA_REG_2 (0x6c)
#define QSPI_SPI_DATA_REG_3 (0x70)
@@ -118,6 +115,16 @@ struct ti_qspi {
#define QSPI_AUTOSUSPEND_TIMEOUT 2000
+#define MEM_CS_EN(n) ((n + 1) << 8)
+
+#define MM_SWITCH 0x1
+
+#define QSPI_SETUP_RD_NORMAL (0x0 << 12)
+#define QSPI_SETUP_RD_DUAL (0x1 << 12)
+#define QSPI_SETUP_RD_QUAD (0x3 << 12)
+#define QSPI_SETUP_ADDR_SHIFT 8
+#define QSPI_SETUP_DUMMY_SHIFT 10
+
static inline unsigned long ti_qspi_read(struct ti_qspi *qspi,
unsigned long reg)
{
@@ -335,6 +342,117 @@ static int qspi_transfer_msg(struct ti_qspi *qspi, struct spi_transfer *t)
return 0;
}
+static void ti_qspi_enable_memory_map(struct spi_device *spi)
+{
+ struct ti_qspi *qspi = spi_master_get_devdata(spi->master);
+ u32 val;
+
+ ti_qspi_write(qspi, MM_SWITCH, QSPI_SPI_SWITCH_REG);
+ if (qspi->ctrl_mod) {
+ val = readl(qspi->ctrl_base);
+ val |= MEM_CS_EN(spi->chip_select);
+ writel(val, qspi->ctrl_base);
+ }
+}
+
+static void ti_qspi_disable_memory_map(struct spi_device *spi)
+{
+ struct ti_qspi *qspi = spi_master_get_devdata(spi->master);
+ u32 val;
+
+ ti_qspi_write(qspi, 0, QSPI_SPI_SWITCH_REG);
+ if (qspi->ctrl_mod) {
+ val = readl(qspi->ctrl_base);
+ val &= ~MEM_CS_EN(spi->chip_select);
+ writel(val, qspi->ctrl_base);
+ }
+}
+
+static void ti_qspi_setup_mmap_read(struct spi_device *spi, u8
+ read_opcode, u8 addr_width,
+ u8 dummy_bytes)
+{
+ struct ti_qspi *qspi = spi_master_get_devdata(spi->master);
+ u32 mode = spi->mode & (SPI_RX_DUAL | SPI_RX_QUAD);
+ u32 memval = read_opcode;
+
+ switch (mode) {
+ case SPI_RX_QUAD:
+ memval |= QSPI_SETUP_RD_QUAD;
+ break;
+ case SPI_RX_DUAL:
+ memval |= QSPI_SETUP_RD_DUAL;
+ break;
+ default:
+ memval |= QSPI_SETUP_RD_NORMAL;
+ break;
+ }
+ memval |= ((addr_width - 1) << QSPI_SETUP_ADDR_SHIFT |
+ dummy_bytes << QSPI_SETUP_DUMMY_SHIFT);
+ ti_qspi_write(qspi, memval,
+ QSPI_SPI_SETUP_REG(spi->chip_select));
+}
+
+static unsigned int ti_qspi_cmd2addr(u8 *cmd, u8 addr_width)
+{
+ u32 addr;
+
+ /* cmd[0] is read opcode */
+ addr = cmd[1] << ((addr_width - 1) * 8);
+ addr |= cmd[2] << ((addr_width - 2) * 8);
+ addr |= cmd[3] << ((addr_width - 3) * 8);
+ addr |= cmd[4] << ((addr_width - 4) * 8);
+
+ return addr;
+}
+
+static int ti_qspi_mmap_read(struct spi_master *master,
+ struct spi_message *m)
+{
+ struct ti_qspi *qspi = spi_master_get_devdata(master);
+ struct spi_device *spi = m->spi;
+ struct spi_transfer *t;
+ u8 read_opcode = 0x3; /* Default normal read */
+ void *to = NULL;
+ u8 addr_width = 4, dummy_bytes = 0;
+ unsigned int len = 0, from = 0;
+ int status = 0;
+
+ mutex_lock(&qspi->list_lock);
+
+ /* disable WC interrupt during memcpy */
+ ti_qspi_write(qspi, QSPI_WC_INT_DISABLE, QSPI_INTR_ENABLE_CLEAR_REG);
+ ti_qspi_enable_memory_map(spi);
+ list_for_each_entry(t, &m->transfers, transfer_list) {
+ if (t->tx_buf) {
+ read_opcode = *((u8 *)t->tx_buf);
+ dummy_bytes = t->len - (addr_width + 1);
+ from = ti_qspi_cmd2addr((u8 *)t->tx_buf, addr_width);
+ }
+ if (t->rx_buf) {
+ to = ((void *)t->rx_buf);
+ len = t->len;
+ }
+ m->actual_length += t->len;
+ }
+ ti_qspi_setup_mmap_read(spi, read_opcode, addr_width,
+ dummy_bytes);
+
+ if (qspi_is_busy(qspi)) {
+ status = -EBUSY;
+ goto err;
+ }
+ memcpy(to, qspi->mmap_base + from, len);
+
+err:
+ ti_qspi_disable_memory_map(spi);
+ mutex_unlock(&qspi->list_lock);
+ m->status = status;
+ spi_finalize_current_message(master);
+
+ return status;
+}
+
static int ti_qspi_start_transfer_one(struct spi_master *master,
struct spi_message *m)
{
@@ -344,6 +462,9 @@ static int ti_qspi_start_transfer_one(struct spi_master *master,
int status = 0, ret;
int frame_length;
+ if (m->use_mmap_mode)
+ return ti_qspi_mmap_read(master, m);
+
/* setup device control reg */
qspi->dc = 0;
--
2.4.6
next prev parent reply other threads:[~2015-07-28 8:41 UTC|newest]
Thread overview: 44+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-28 8:41 [RFC PATCH 0/5] Add memory mapped read support for TI QSPI Vignesh R
2015-07-28 8:41 ` [RFC PATCH 1/5] spi: introduce flag for memory mapped read Vignesh R
2015-07-31 18:17 ` Mark Brown
2015-08-03 4:57 ` Vignesh R
2015-08-04 15:51 ` Mark Brown
[not found] ` <20150804155148.GR20873-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-08-04 17:59 ` R, Vignesh
[not found] ` <55C0FD98.1090107-l0cyMroinI0@public.gmane.org>
2015-08-05 5:21 ` Michal Suchanek
2015-08-05 5:35 ` Vignesh R
[not found] ` <55C1A095.8000509-l0cyMroinI0@public.gmane.org>
2015-08-05 5:57 ` Michal Suchanek
2015-08-05 11:50 ` Mark Brown
[not found] ` <20150805115013.GJ20873-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-08-05 12:40 ` Michal Suchanek
[not found] ` <CAOMqctQXwcHyiWBwtugSDSE_k65qrNfrwnhjQMDJkLoJMmGzUw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-08-05 12:44 ` Mark Brown
2015-08-05 12:56 ` Michal Suchanek
2015-08-06 9:02 ` Mark Brown
2015-08-06 10:01 ` Michal Suchanek
[not found] ` <CAOMqctQZRZ4zG_yYy=CeX3DX4NVNWN1COP4Q-2YvMun9xYOA7g-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-08-06 10:22 ` Russell King - ARM Linux
2015-08-06 11:00 ` Mark Brown
[not found] ` <20150806102225.GI7576-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2015-08-06 11:02 ` Michal Suchanek
2015-08-06 12:25 ` Vignesh R
2015-08-06 13:51 ` Russell King - ARM Linux
[not found] ` <20150806135129.GJ7576-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2015-08-06 16:14 ` Geert Uytterhoeven
[not found] ` <CAMuHMdWWDwZ=ziGQXFCnOX8pErXpsEi533J73_Hh=sEqq4hR6Q-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-08-06 18:20 ` Michal Suchanek
2015-08-06 21:33 ` Russell King - ARM Linux
[not found] ` <20150806213340.GK7576-l+eeeJia6m9vn6HldHNs0ANdhmdF6hFW@public.gmane.org>
2015-08-07 7:38 ` Michal Suchanek
2015-08-07 8:35 ` Vignesh R
2015-08-07 8:25 ` Martin Sperl
2015-08-07 10:16 ` Michal Suchanek
[not found] ` <CAOMqctScUybdoZPgqH185qzDxB=TyutDMARextHx0XwC7L3Xmw-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2015-08-12 9:27 ` Vignesh R
2015-08-06 16:46 ` Mark Brown
2015-08-06 18:20 ` Mark Brown
2015-08-06 11:23 ` Mark Brown
2015-08-06 11:42 ` Michal Suchanek
2015-08-06 16:03 ` Mark Brown
2015-07-28 8:41 ` Vignesh R [this message]
2015-07-28 8:41 ` [RFC PATCH 3/5] mtd: devices: m25p80: set flag to request " Vignesh R
2015-07-28 8:41 ` [RFC PATCH 4/5] ARM: dts: DRA7: Add memory map region entries for qspi Vignesh R
2015-07-31 13:48 ` Sekhar Nori
[not found] ` <55BB7CA4.1020300-l0cyMroinI0@public.gmane.org>
2015-08-03 5:09 ` Vignesh R
2015-07-31 18:19 ` Mark Brown
[not found] ` <20150731181903.GN20873-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2015-08-03 5:02 ` Vignesh R
[not found] ` <55BEF5D1.1050608-l0cyMroinI0@public.gmane.org>
2015-08-04 15:52 ` Mark Brown
2015-07-31 21:28 ` Brian Norris
[not found] ` <20150731212847.GH10676-hpIqsD4AKlfQT0dZR+AlfA@public.gmane.org>
2015-08-03 5:06 ` Vignesh R
2015-07-28 8:41 ` [RFC PATCH 5/5] ARM: dts: AM4372: " Vignesh R
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=1438072876-16338-3-git-send-email-vigneshr@ti.com \
--to=vigneshr@ti.com \
--cc=b32955@freescale.com \
--cc=broonie@kernel.org \
--cc=computersforpeace@gmail.com \
--cc=devicetree@vger.kernel.org \
--cc=dwmw2@infradead.org \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mtd@lists.infradead.org \
--cc=linux-omap@vger.kernel.org \
--cc=linux-spi@vger.kernel.org \
--cc=linux@arm.linux.org.uk \
--cc=tony@atomide.com \
/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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).