From: Heiner Kallweit <hkallweit1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
Cc: "linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>
Subject: [PATCH v2 08/09] spi: fsl-espi: add support for RXSKIP mode
Date: Thu, 27 Oct 2016 21:28:51 +0200 [thread overview]
Message-ID: <10553bf5-a1a7-5a5d-482b-8831f3ba859c@gmail.com> (raw)
In-Reply-To: <5b98be38-17a2-79a2-14da-fb2bb6f8820f-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
This patch adds support for ESPI RXSKIP mode. This mode is optimized
for flash reads:
- sends a number of bytes and then reads a number of bytes
- shifts out zeros automatically when reading
- optionally can be configured for dual read mode
Signed-off-by: Heiner Kallweit <hkallweit1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
v2:
- rebased
---
drivers/spi/spi-fsl-espi.c | 56 ++++++++++++++++++++++++++++++++++++++++++----
drivers/spi/spi-fsl-lib.h | 1 +
2 files changed, 53 insertions(+), 4 deletions(-)
diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c
index 2f95b19..e32dc30 100644
--- a/drivers/spi/spi-fsl-espi.c
+++ b/drivers/spi/spi-fsl-espi.c
@@ -150,7 +150,8 @@ static void fsl_espi_copy_to_buf(struct spi_message *m,
list_for_each_entry(t, &m->transfers, transfer_list) {
if (t->tx_buf)
fsl_espi_memcpy_swab(buf, t->tx_buf, m, t);
- else
+ /* In RXSKIP mode controller shifts zeros automatically */
+ else if (!mspi->rxskip)
memset(buf, 0, t->len);
buf += t->len;
}
@@ -203,6 +204,42 @@ static int fsl_espi_check_message(struct spi_message *m)
return 0;
}
+static void fsl_espi_check_rxskip_mode(struct spi_message *m,
+ struct mpc8xxx_spi *mspi)
+{
+ struct spi_transfer *t;
+ unsigned int i = 0, rxskip_len = 0;
+
+ mspi->rxskip = 0;
+
+ /*
+ * prerequisites for rxskip mode:
+ * - message has two transfers
+ * - first transfer is a write and second is a read
+ *
+ * In addition enable rxskip mode only if length of write transfer
+ * is <= FSL_ESPI_FIFO_SIZE. This allows to keep the current
+ * low-level transfer implementation.
+ * This constraint doesn't affect SPI NOR reads as typical use case
+ * for rxskip mode as the read command has only few bytes.
+ */
+ list_for_each_entry(t, &m->transfers, transfer_list) {
+ if (i == 0) {
+ if (!t->tx_buf || t->rx_buf ||
+ t->len > FSL_ESPI_FIFO_SIZE)
+ return;
+ rxskip_len = t->len;
+ } else if (i == 1) {
+ if (t->tx_buf || !t->rx_buf)
+ return;
+ }
+ i++;
+ }
+
+ if (i == 2)
+ mspi->rxskip = rxskip_len;
+}
+
static void fsl_espi_fill_tx_fifo(struct mpc8xxx_spi *mspi, u32 events)
{
u32 tx_fifo_avail;
@@ -282,7 +319,7 @@ static void fsl_espi_setup_transfer(struct spi_device *spi,
static int fsl_espi_bufs(struct spi_device *spi, struct spi_transfer *t)
{
struct mpc8xxx_spi *mpc8xxx_spi = spi_master_get_devdata(spi->master);
- u32 mask;
+ u32 mask, spcom;
int ret;
mpc8xxx_spi->rx_len = t->len;
@@ -294,8 +331,18 @@ static int fsl_espi_bufs(struct spi_device *spi, struct spi_transfer *t)
reinit_completion(&mpc8xxx_spi->done);
/* Set SPCOM[CS] and SPCOM[TRANLEN] field */
- fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPCOM,
- (SPCOM_CS(spi->chip_select) | SPCOM_TRANLEN(t->len - 1)));
+ spcom = SPCOM_CS(spi->chip_select);
+ spcom |= SPCOM_TRANLEN(t->len - 1);
+
+ /* configure RXSKIP mode */
+ if (mpc8xxx_spi->rxskip) {
+ spcom |= SPCOM_RXSKIP(mpc8xxx_spi->rxskip);
+ mpc8xxx_spi->tx_len = mpc8xxx_spi->rxskip;
+ mpc8xxx_spi->rx_len = t->len - mpc8xxx_spi->rxskip;
+ mpc8xxx_spi->rx = t->rx_buf + mpc8xxx_spi->rxskip;
+ }
+
+ fsl_espi_write_reg(mpc8xxx_spi, ESPI_SPCOM, spcom);
/* enable interrupts */
mask = SPIM_DON;
@@ -327,6 +374,7 @@ static int fsl_espi_trans(struct spi_message *m, struct spi_transfer *trans)
struct spi_device *spi = m->spi;
int ret;
+ fsl_espi_check_rxskip_mode(m, mspi);
fsl_espi_copy_to_buf(m, mspi);
fsl_espi_setup_transfer(spi, trans);
diff --git a/drivers/spi/spi-fsl-lib.h b/drivers/spi/spi-fsl-lib.h
index 35a7a17..8096fae 100644
--- a/drivers/spi/spi-fsl-lib.h
+++ b/drivers/spi/spi-fsl-lib.h
@@ -32,6 +32,7 @@ struct mpc8xxx_spi {
unsigned int rx_len;
unsigned int tx_len;
u8 *local_buf;
+ unsigned int rxskip;
spinlock_t lock;
#endif
--
2.10.1
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
next prev parent reply other threads:[~2016-10-27 19:28 UTC|newest]
Thread overview: 30+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <5b98be38-17a2-79a2-14da-fb2bb6f8820f@gmail.com>
[not found] ` <5b98be38-17a2-79a2-14da-fb2bb6f8820f-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-10-02 12:22 ` [PATCH 02/11] spi: fsl-espi: remove unneeded check for SPI_QE_CPU_MODE Heiner Kallweit
[not found] ` <20608368-44e6-21f8-d970-5ade9990ce59-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-10-06 15:45 ` Mark Brown
[not found] ` <20161006154543.rxlrc3sumejozpcg-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2016-10-06 18:36 ` Heiner Kallweit
[not found] ` <bbe77580-1ac2-4071-5d7d-f786c54ad177-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-10-26 17:07 ` Mark Brown
2016-10-02 12:22 ` [PATCH 03/11] spi: fsl-espi: fix handling of word sizes other than 8 bit Heiner Kallweit
2016-10-02 12:23 ` [PATCH 04/11] spi: fsl-espi: fix and improve writing to TX FIFO Heiner Kallweit
[not found] ` <c246dbf2-c59e-f029-afa1-8a5c6f6dd24b-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-10-28 18:53 ` Applied "spi: fsl-espi: fix and improve writing to TX FIFO" to the spi tree Mark Brown
2016-10-02 12:23 ` [PATCH 05/11] spi: fsl-espi: Rename len in struct mpc8xxx_spi to rx_len and make it unsigned Heiner Kallweit
2016-10-02 12:23 ` [PATCH 06/11] spi: fsl-espi: simplify and inline function fsl_espi_change_mode Heiner Kallweit
[not found] ` <0aeb49f0-dbfb-7acb-3829-cabafe4e7291-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-10-28 18:52 ` Applied "spi: fsl-espi: simplify and inline function fsl_espi_change_mode" to the spi tree Mark Brown
2016-10-02 12:23 ` [PATCH 07/11] spi: fsl-espi: fix and improve reading from RX FIFO Heiner Kallweit
2016-10-02 12:23 ` [PATCH 08/11] spi: fsl-espi: make better use of the " Heiner Kallweit
[not found] ` <144b73b1-dff2-a5b6-9df1-837238f20008-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-10-28 18:51 ` Applied "spi: fsl-espi: make better use of the RX FIFO" to the spi tree Mark Brown
2016-10-02 12:23 ` [PATCH 09/11] spi: fsl-espi: extend and improve transfer error handling Heiner Kallweit
[not found] ` <4ba19a7f-9f66-54c4-9119-e85671d608fb-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-10-28 18:52 ` Applied "spi: fsl-espi: extend and improve transfer error handling" to the spi tree Mark Brown
2016-10-02 12:23 ` [PATCH 10/11] spi: fsl-espi: add support for RXSKIP mode Heiner Kallweit
2016-10-02 12:23 ` [PATCH 11/11] spi: fsl-espi: add support for dual read mode Heiner Kallweit
2016-10-27 19:24 ` [PATCH v2 01/09] spi: fsl-espi: improve check for SPI_QE_CPU_MODE Heiner Kallweit
[not found] ` <0b5e7849-88d6-2af5-a428-eeb0de0f2af2-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-10-28 18:34 ` Mark Brown
2016-10-28 18:53 ` Applied "spi: fsl-espi: improve check for SPI_QE_CPU_MODE" to the spi tree Mark Brown
2016-10-27 19:25 ` [PATCH v2 02/09] spi: fsl-espi: fix and improve writing to TX FIFO Heiner Kallweit
2016-10-27 19:26 ` [PATCH v2 03/09] spi: fsl-espi: Rename len in struct mpc8xxx_spi to rx_len and make it unsigned Heiner Kallweit
[not found] ` <611500a3-d254-f04c-ce20-6905a649bcda-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-10-28 18:53 ` Applied "spi: fsl-espi: Rename len in struct mpc8xxx_spi to rx_len and make it unsigned" to the spi tree Mark Brown
2016-10-27 19:26 ` [PATCH v2 04/09] spi: fsl-espi: simplify and inline function fsl_espi_change_mode Heiner Kallweit
2016-10-27 19:27 ` [PATCH v2 05/09] spi: fsl-espi: fix and improve reading from RX FIFO Heiner Kallweit
[not found] ` <6ae20ab9-4068-9be7-654d-12424de35716-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-10-28 18:51 ` Applied "spi: fsl-espi: fix and improve reading from RX FIFO" to the spi tree Mark Brown
2016-10-27 19:27 ` [PATCH v2 06/09] spi: fsl-espi: make better use of the RX FIFO Heiner Kallweit
2016-10-27 19:28 ` [PATCH v2 07/09] spi: fsl-espi: extend and improve transfer error handling Heiner Kallweit
2016-10-27 19:28 ` Heiner Kallweit [this message]
2016-10-27 19:29 ` [PATCH v2 09/09] spi: fsl-espi: add support for dual read mode Heiner Kallweit
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=10553bf5-a1a7-5a5d-482b-8831f3ba859c@gmail.com \
--to=hkallweit1-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/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).