public inbox for linux-mtd@lists.infradead.org
 help / color / mirror / Atom feed
From: "Rafał Miłecki" <zajec5@gmail.com>
To: linux-mtd@lists.infradead.org, Artem Bityutskiy <dedekind1@gmail.com>
Cc: "Rafał Miłecki" <zajec5@gmail.com>
Subject: [RFC][PATCH] bcm47xxnflash: use small delay between polling
Date: Fri, 23 Nov 2012 16:43:38 +0100	[thread overview]
Message-ID: <1353685418-30623-1-git-send-email-zajec5@gmail.com> (raw)

---
I think it's a good idea to add some delays between polling the
hardware. I'm not sure however what delays should be used.

In the proposed patch I put "ndelay(1)" which is extermely low delay,
but even with that it's common for the loop to make only 0-3 iterations.
For that reason I don't want to put delays like "ndelay(10)" or bigger.
This could mean waiting 10ns while the hardware is ready after 1ns.

What do you think about this?
---
 drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c |   16 +++++++++++-----
 1 files changed, 11 insertions(+), 5 deletions(-)

diff --git a/drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c b/drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c
index ece343c..1026100 100644
--- a/drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c
+++ b/drivers/mtd/nand/bcm47xxnflash/ops_bcm4706.c
@@ -16,9 +16,13 @@
 
 #include "bcm47xxnflash.h"
 
-/* Broadcom uses 1'000'000 but it seems to be too many. Tests on WNDR4500 has
- * shown 164 retries as maxiumum. */
-#define NFLASH_READY_RETRIES		1000
+/* Broadcom uses 1'000'000 for both without any delay.
+ * Tests on WNDR4500 have shown that in can take:
+ * 1) 0-5 retries for ctl_cmd with ndelay(1)
+ * 2) 0-800 retries for poll with ndelay(1)
+ */
+#define NFLASH_CTL_CMD_RETRIES		100
+#define NFLASH_POLL_RETRIES		10000
 
 #define NFLASH_SECTOR_SIZE		512
 
@@ -45,11 +49,12 @@ static int bcm47xxnflash_ops_bcm4706_ctl_cmd(struct bcma_drv_cc *cc, u32 code)
 	int i = 0;
 
 	bcma_cc_write32(cc, BCMA_CC_NFLASH_CTL, NCTL_START | code);
-	for (i = 0; i < NFLASH_READY_RETRIES; i++) {
+	for (i = 0; i < NFLASH_CTL_CMD_RETRIES; i++) {
 		if (!(bcma_cc_read32(cc, BCMA_CC_NFLASH_CTL) & NCTL_START)) {
 			i = 0;
 			break;
 		}
+		ndelay(1);
 	}
 	if (i) {
 		pr_err("NFLASH control command not ready!\n");
@@ -62,7 +67,7 @@ static int bcm47xxnflash_ops_bcm4706_poll(struct bcma_drv_cc *cc)
 {
 	int i;
 
-	for (i = 0; i < NFLASH_READY_RETRIES; i++) {
+	for (i = 0; i < NFLASH_POLL_RETRIES; i++) {
 		if (bcma_cc_read32(cc, BCMA_CC_NFLASH_CTL) & NCTL_READY) {
 			if (bcma_cc_read32(cc, BCMA_CC_NFLASH_CTL) &
 			    BCMA_CC_NFLASH_CTL_ERR) {
@@ -72,6 +77,7 @@ static int bcm47xxnflash_ops_bcm4706_poll(struct bcma_drv_cc *cc)
 				return 0;
 			}
 		}
+		ndelay(1);
 	}
 
 	pr_err("Polling timeout!\n");
-- 
1.7.7

             reply	other threads:[~2012-11-23 15:43 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-23 15:43 Rafał Miłecki [this message]
2012-11-23 16:38 ` [RFC][PATCH] bcm47xxnflash: use small delay between polling Kevin Cernekee

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=1353685418-30623-1-git-send-email-zajec5@gmail.com \
    --to=zajec5@gmail.com \
    --cc=dedekind1@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