linux-mtd.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: Heiner Kallweit <hkallweit1@gmail.com>
To: Brian Norris <computersforpeace@gmail.com>
Cc: MTD Maling List <linux-mtd@lists.infradead.org>
Subject: [PATCH 2/2] mtd: m25p80: consider max_transfer_size when reading
Date: Sat, 27 Feb 2016 23:50:11 +0100	[thread overview]
Message-ID: <56D22823.7090005@gmail.com> (raw)

Some controllers have transfer size limits. To allow to deal with this
max_transfer_size was introduced in the SPI core recently.
Use this new feature to read in chunks if needed.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/mtd/devices/m25p80.c | 30 +++++++++++++++++++++++++++++-
 1 file changed, 29 insertions(+), 1 deletion(-)

diff --git a/drivers/mtd/devices/m25p80.c b/drivers/mtd/devices/m25p80.c
index c2d1f65..69f3acf 100644
--- a/drivers/mtd/devices/m25p80.c
+++ b/drivers/mtd/devices/m25p80.c
@@ -119,7 +119,7 @@ static inline unsigned int m25p80_rx_nbits(struct spi_nor *nor)
  * Read an address range from the nor chip.  The address range
  * may be any size provided it is within the physical boundaries.
  */
-static int m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
+static int _m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
 			size_t *retlen, u_char *buf)
 {
 	struct m25p *flash = nor->priv;
@@ -153,6 +153,34 @@ static int m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
 	return ret;
 }
 
+/* Read in max_read_len chunks if len > max_read_len */
+static int m25p80_read(struct spi_nor *nor, loff_t from, size_t len,
+		       size_t *retlen, u_char *buf)
+{
+	struct m25p *flash = nor->priv;
+	/*
+	 * The controller transfer size limit refers to the overall transfer
+	 * including read command + actually read data. Therefore subtract
+	 * the command size when calculating the max read length.
+	 */
+	size_t max_read_len = spi_max_transfer_size(flash->spi) -
+			      (m25p_cmdsz(nor) + nor->read_dummy / 8);
+	size_t read_len;
+	int ret;
+
+	while (len > 0) {
+		read_len = min(len, max_read_len);
+		ret = _m25p80_read(nor, from, read_len, retlen, buf);
+		if (ret)
+			return ret;
+		from += read_len;
+		buf += read_len;
+		len -= read_len;
+	}
+
+	return 0;
+}
+
 /*
  * board specific setup should have ensured the SPI clock used here
  * matches what the READ command supports, at least until this driver
-- 
2.7.1

             reply	other threads:[~2016-02-27 22:50 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-02-27 22:50 Heiner Kallweit [this message]
2016-04-05 19:39 ` [PATCH 2/2] mtd: m25p80: consider max_transfer_size when reading Brian Norris
2016-04-05 20:08   ` Heiner Kallweit
2016-04-05 21:07     ` Brian Norris
2016-04-07 19:09       ` Heiner Kallweit
2016-05-05 23:57         ` Brian Norris
2016-05-06 12:14           ` Mark Brown
2016-06-03 22:22             ` Heiner Kallweit
2016-06-06 17:40               ` Mark Brown
2016-06-06 18:28                 ` Brian Norris
2016-06-06 18:34                   ` Mark Brown
2016-06-06 18:43                     ` Brian Norris
2016-06-06 18:48                       ` Mark Brown
2016-06-06 18:53                 ` Heiner Kallweit
2016-06-06 19:40                   ` Michal Suchanek
2016-06-06 21:02                     ` Heiner Kallweit
2016-06-06 19:46                   ` Geert Uytterhoeven
2016-06-06 21:20                     ` Heiner Kallweit
2016-06-06 22:28                       ` Marek Vasut
2016-06-07  4:52                         ` Heiner Kallweit
2016-06-06 23:07                   ` Mark Brown
2016-06-07  6:03                     ` Heiner Kallweit
2016-06-07  8:10                       ` Michal Suchanek
2016-06-07 20:42                         ` Heiner Kallweit
2016-06-08 19:51                       ` Heiner Kallweit
2016-06-09  7:12                         ` Michal Suchanek
2016-06-17 20:13                           ` Heiner Kallweit
2016-04-06 13:55   ` Cyrille Pitchen

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=56D22823.7090005@gmail.com \
    --to=hkallweit1@gmail.com \
    --cc=computersforpeace@gmail.com \
    --cc=linux-mtd@lists.infradead.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).