Patchwork [U-Boot,1/4] Optimized nand_read_buf for kirkwood

login
register
mail settings
Submitter Phil Sutter
Date Nov. 21, 2012, 12:59 p.m.
Message ID <1353502761-12640-1-git-send-email-phil.sutter@viprinet.com>
Download mbox | patch
Permalink /patch/200770/
State Superseded
Delegated to: Prafulla Wadaskar
Headers show

Comments

Phil Sutter - Nov. 21, 2012, 12:59 p.m.
The basic idea is taken from the linux-kernel, but further optimized.

First align the buffer to 8 bytes, then use ldrd/strd to read and store
in 8 byte quantities, then do the final bytes.

Signed-off-by: Nico Erfurth <ne@erfurth.eu>
Cc: Prafulla Wadaskar <prafulla@marvell.com>
---
 drivers/mtd/nand/kirkwood_nand.c |   29 +++++++++++++++++++++++++++++
 1 files changed, 29 insertions(+), 0 deletions(-)
Prafulla Wadaskar - Nov. 26, 2012, 3:46 a.m.
> -----Original Message-----
> From: Phil Sutter [mailto:phil.sutter@viprinet.com]
> Sent: 21 November 2012 18:29
> To: u-boot@lists.denx.de
> Cc: Nico Erfurth; Prafulla Wadaskar
> Subject: [PATCH 1/4] Optimized nand_read_buf for kirkwood
> 
> The basic idea is taken from the linux-kernel, but further optimized.
> 
> First align the buffer to 8 bytes, then use ldrd/strd to read and
> store
> in 8 byte quantities, then do the final bytes.
> 
> Signed-off-by: Nico Erfurth <ne@erfurth.eu>
> Cc: Prafulla Wadaskar <prafulla@marvell.com>

Hi Phil,
Have you tested this patch? I don't see your signed-off or tested-by signature in this patch.

Regards...
Prafulla . . .
Phil Sutter - Nov. 26, 2012, 10:29 a.m.
Hello Prafulla,

On Sun, Nov 25, 2012 at 07:46:50PM -0800, Prafulla Wadaskar wrote:
> Have you tested this patch? I don't see your signed-off or tested-by signature in this patch.

Yes, I did. But just for functionality, no real spead measurement or so.
That's why I skipped the tested-by line. I just caught up on this,
please see the patch I send in reply to this mail.

Best wishes,

Phil Sutter
Software Engineer
Phil Sutter - Feb. 21, 2013, 5:21 p.m.
Respin of my patch series for review. Only changes in patches 2 and 3:

env_nand.c: support falling back to redundant env when writing:
  Print status message for each of the redundant copies when writing. So
  when writing, we see which image is being written to. Also, when the first
  attempt fails, a second message follows so the user sees that writing was
  eventually successful.

env_nand.c: clarify log messages when env reading fails:
  Print a warning if one of the two redundant copies could not be read and an
  error if both failed to read. Message text and formatting chosen with
  common/env_flash.c as example.
Phil Sutter - June 26, 2013, 6:25 p.m.
Respin of the remaining two of my patch series for review.  First patch
is identical but removed the versioning from the title as suggested.
Second patch cleaned up so checkpatch.pl does not complain anymore.
Kudos to Scott for pointing out the warnings and his further comments. 

Greetings, Phil

Patch

diff --git a/drivers/mtd/nand/kirkwood_nand.c b/drivers/mtd/nand/kirkwood_nand.c
index bdab5aa..e04a59f 100644
--- a/drivers/mtd/nand/kirkwood_nand.c
+++ b/drivers/mtd/nand/kirkwood_nand.c
@@ -38,6 +38,34 @@  struct kwnandf_registers {
 static struct kwnandf_registers *nf_reg =
 	(struct kwnandf_registers *)KW_NANDF_BASE;
 
+
+/* The basic idea is stolen from the linux kernel, but the inner loop is optimized a bit more */
+static void kw_nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len)
+{
+	struct nand_chip *chip = mtd->priv;
+
+	while (len && (unsigned long)buf & 7)
+	{
+		*buf++ = readb(chip->IO_ADDR_R);
+		len--;
+	};
+
+	asm volatile (
+		".LFlashLoop:\n"
+		"  subs\t%0, #8\n"
+		"  ldrpld\tr2, [%2]\n" // Read 2 words
+		"  strpld\tr2, [%1], #8\n" // Read 2 words
+		"  bpl\t.LFlashLoop\n" // This results in one additional loop if len%8 <> 0
+		"  addne\t%0, #8\n"
+		: "+&r" (len), "+&r" (buf)
+		: "r" (chip->IO_ADDR_R)
+		: "r2", "r3", "memory", "cc"
+	);
+
+	while (len--)
+		*buf++ = readb(chip->IO_ADDR_R);
+}
+
 /*
  * hardware specific access to control-lines/bits
  */
@@ -76,6 +104,7 @@  int board_nand_init(struct nand_chip *nand)
 	nand->options = NAND_COPYBACK | NAND_CACHEPRG | NAND_NO_PADDING;
 	nand->ecc.mode = NAND_ECC_SOFT;
 	nand->cmd_ctrl = kw_nand_hwcontrol;
+	nand->read_buf = kw_nand_read_buf;
 	nand->chip_delay = 40;
 	nand->select_chip = kw_nand_select_chip;
 	return 0;