From: Heiner Kallweit <hkallweit1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
Brian Norris
<computersforpeace-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
Cc: "linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org"
<linux-spi-u79uwXL29TY76Z2rM5mHXA@public.gmane.org>,
MTD Maling List
<linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org>
Subject: [PATCH v2 3/3] spi: fsl-espi: eliminate spi nor flash read loop
Date: Wed, 17 Aug 2016 21:11:01 +0200 [thread overview]
Message-ID: <b66e4ae5-3528-5141-e1fe-90c19ffcb7ac@gmail.com> (raw)
In-Reply-To: <20160816164204.GV9347-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
The fsl-espi driver contains a read loop that implicitely assumes that
the device to read from is a m25p80 SPI NOR flash (bytes 2 - 4 of the
first write transfer are interpreted as 3 byte flash address).
Now that we have such a read loop in the spi-nor driver and are able
to correctly indicate the message size limit of the controller,
the read loop can be removed from the fsl-espi driver.
Signed-off-by: Heiner Kallweit <hkallweit1-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
v2:
- set the new hook max_message_size in spi_master
---
drivers/spi/spi-fsl-espi.c | 91 +++++++++++-----------------------------------
1 file changed, 21 insertions(+), 70 deletions(-)
diff --git a/drivers/spi/spi-fsl-espi.c b/drivers/spi/spi-fsl-espi.c
index 8d85a3c..96a2442 100644
--- a/drivers/spi/spi-fsl-espi.c
+++ b/drivers/spi/spi-fsl-espi.c
@@ -258,23 +258,6 @@ static int fsl_espi_bufs(struct spi_device *spi, struct spi_transfer *t)
return mpc8xxx_spi->count;
}
-static inline void fsl_espi_addr2cmd(unsigned int addr, u8 *cmd)
-{
- if (cmd) {
- cmd[1] = (u8)(addr >> 16);
- cmd[2] = (u8)(addr >> 8);
- cmd[3] = (u8)(addr >> 0);
- }
-}
-
-static inline unsigned int fsl_espi_cmd2addr(u8 *cmd)
-{
- if (cmd)
- return cmd[1] << 16 | cmd[2] << 8 | cmd[3] << 0;
-
- return 0;
-}
-
static void fsl_espi_do_trans(struct spi_message *m,
struct fsl_espi_transfer *tr)
{
@@ -366,68 +349,36 @@ static void fsl_espi_cmd_trans(struct spi_message *m,
static void fsl_espi_rw_trans(struct spi_message *m,
struct fsl_espi_transfer *trans, u8 *rx_buff)
{
- struct fsl_espi_transfer *espi_trans = trans;
- unsigned int total_len = espi_trans->len;
struct spi_transfer *t;
u8 *local_buf;
- u8 *rx_buf = rx_buff;
- unsigned int trans_len;
- unsigned int addr;
- unsigned int tx_only;
- unsigned int rx_pos = 0;
- unsigned int pos;
- int i, loop;
+ unsigned int tx_only = 0;
+ int i = 0;
local_buf = kzalloc(SPCOM_TRANLEN_MAX, GFP_KERNEL);
if (!local_buf) {
- espi_trans->status = -ENOMEM;
+ trans->status = -ENOMEM;
return;
}
- for (pos = 0, loop = 0; pos < total_len; pos += trans_len, loop++) {
- trans_len = total_len - pos;
-
- i = 0;
- tx_only = 0;
- list_for_each_entry(t, &m->transfers, transfer_list) {
- if (t->tx_buf) {
- memcpy(local_buf + i, t->tx_buf, t->len);
- i += t->len;
- if (!t->rx_buf)
- tx_only += t->len;
- }
- }
-
- /* Add additional TX bytes to compensate SPCOM_TRANLEN_MAX */
- if (loop > 0)
- trans_len += tx_only;
-
- if (trans_len > SPCOM_TRANLEN_MAX)
- trans_len = SPCOM_TRANLEN_MAX;
-
- /* Update device offset */
- if (pos > 0) {
- addr = fsl_espi_cmd2addr(local_buf);
- addr += rx_pos;
- fsl_espi_addr2cmd(addr, local_buf);
+ list_for_each_entry(t, &m->transfers, transfer_list) {
+ if (t->tx_buf) {
+ memcpy(local_buf + i, t->tx_buf, t->len);
+ i += t->len;
+ if (!t->rx_buf)
+ tx_only += t->len;
}
+ }
- espi_trans->len = trans_len;
- espi_trans->tx_buf = local_buf;
- espi_trans->rx_buf = local_buf;
- fsl_espi_do_trans(m, espi_trans);
-
- /* If there is at least one RX byte then copy it to rx_buf */
- if (tx_only < SPCOM_TRANLEN_MAX)
- memcpy(rx_buf + rx_pos, espi_trans->rx_buf + tx_only,
- trans_len - tx_only);
-
- rx_pos += trans_len - tx_only;
+ trans->tx_buf = local_buf;
+ trans->rx_buf = local_buf;
+ fsl_espi_do_trans(m, trans);
- if (loop > 0)
- espi_trans->actual_length += espi_trans->len - tx_only;
- else
- espi_trans->actual_length += espi_trans->len;
+ if (!trans->status) {
+ /* If there is at least one RX byte then copy it to rx_buff */
+ if (trans->len > tx_only)
+ memcpy(rx_buff, trans->rx_buf + tx_only,
+ trans->len - tx_only);
+ trans->actual_length += trans->len;
}
kfree(local_buf);
@@ -663,7 +614,7 @@ static int fsl_espi_runtime_resume(struct device *dev)
}
#endif
-static size_t fsl_espi_max_transfer_size(struct spi_device *spi)
+static size_t fsl_espi_max_message_size(struct spi_device *spi)
{
return SPCOM_TRANLEN_MAX;
}
@@ -695,7 +646,7 @@ static struct spi_master * fsl_espi_probe(struct device *dev,
master->cleanup = fsl_espi_cleanup;
master->transfer_one_message = fsl_espi_do_one_msg;
master->auto_runtime_pm = true;
- master->max_transfer_size = fsl_espi_max_transfer_size;
+ master->max_message_size = fsl_espi_max_message_size;
mpc8xxx_spi = spi_master_get_devdata(master);
--
2.9.2
--
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-08-17 19:11 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-08-07 19:47 [PATCH 1/3] spi: introduce max message size flag in spi_master Heiner Kallweit
[not found] ` <6c95366c-7fcc-ef4c-033a-f9f6e152a669-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-08-16 16:42 ` Mark Brown
[not found] ` <20160816164204.GV9347-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2016-08-17 18:51 ` Heiner Kallweit
2016-08-17 19:08 ` [PATCH v2 1/3] spi: introduce max_message_size hook " Heiner Kallweit
[not found] ` <69c4ce26-7b41-222e-07b2-92818cedd05f-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-08-18 10:17 ` Mark Brown
2016-08-18 10:17 ` Applied "spi: introduce max_message_size hook in spi_master" to the spi tree Mark Brown
2016-08-17 19:09 ` [PATCH v2 2/3] mtd: m25p80: consider max message size in m25p80_read Heiner Kallweit
[not found] ` <b65240ff-7e28-5ecb-0670-abfca871246b-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-09-16 19:13 ` Heiner Kallweit
[not found] ` <a5aad691-fb3b-39a5-943e-43068df74c44-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-10-27 21:23 ` [PATCH RESEND] " Heiner Kallweit
[not found] ` <e2e4ecfe-b888-f335-57f6-634f5c818252-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-10-28 5:48 ` Heiner Kallweit
2016-10-28 5:58 ` [PATCH v2] " Heiner Kallweit
[not found] ` <0e38d1ed-af5c-160f-e02a-f1433c507d23-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-10-29 17:59 ` Marek Vasut
[not found] ` <6f1aed1e-9467-aa94-56cb-5e9435b21ae4-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-10-29 18:09 ` Mark Brown
2016-11-29 6:29 ` Heiner Kallweit
2016-12-23 15:15 ` [PATCH v2 2/3] " Cyrille Pitchen
2016-12-23 15:33 ` Cyrille Pitchen
[not found] ` <2e31fbe7-bbc7-8fed-ccbf-dd9ae4d220e1-AIFe0yeh4nAAvxtiuMwx3w@public.gmane.org>
2016-12-23 18:53 ` Marek Vasut
[not found] ` <e7513817-c6d1-948d-19ff-617debfa1399-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-12-23 21:04 ` Michal Suchanek
[not found] ` <CAOMqctTaPoMR=_dEF_j-WU178_i2tOp2sTfZJSDWWkohVxZn8A-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2016-12-24 10:20 ` Marek Vasut
[not found] ` <1bd5f31a-a32e-12ce-10af-1a17955f5ab6-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-12-24 23:47 ` Heiner Kallweit
2016-08-17 19:11 ` Heiner Kallweit [this message]
[not found] ` <b66e4ae5-3528-5141-e1fe-90c19ffcb7ac-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-08-18 10:17 ` Applied "spi: fsl-espi: eliminate spi nor flash read loop" to the spi tree Mark Brown
2016-10-13 18:50 ` [PATCH v2 RESEND 2/3] mtd: m25p80: consider max message size in m25p80_read 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=b66e4ae5-3528-5141-e1fe-90c19ffcb7ac@gmail.com \
--to=hkallweit1-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
--cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
--cc=computersforpeace-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
--cc=linux-mtd-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@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).