Skip to contentSkip to conversation

NAND: Allow nand_scan to be replaced by user

PATCH New Marek Vasut 2 participants 3 messages Dec 5, 2011

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 NAND: Allow nand_scan to be replaced by user

This patch allows user to supply nand_scan() call replacement via the usual method. This will be beneficial for PXA3XX NAND driver, which does further init of the chip at this stage.

---
 drivers/mtd/nand/nand_base.c |   12 +++++++++---
 include/linux/mtd/nand.h     |    2 ++
 2 files changed, 11 insertions(+), 3 deletions(-)
drivers/mtd/nand/nand_base.c +9 -3
index 27f6c77..baf7622 100644
@@ -2974,10 +2974,16 @@ int nand_scan_tail(struct mtd_info *mtd)
 int nand_scan(struct mtd_info *mtd, int maxchips)
 {
 	int ret;
+	struct nand_chip *nand = mtd->priv;
+
+	if (nand->scan) {
+		ret = nand->scan(mtd);
+	} else {
+		ret = nand_scan_ident(mtd, maxchips, NULL);
+		if (!ret)
+			ret = nand_scan_tail(mtd);
+	}
 
-	ret = nand_scan_ident(mtd, maxchips, NULL);
-	if (!ret)
-		ret = nand_scan_tail(mtd);
 	return ret;
 }
 
include/linux/mtd/nand.h +2 -0
index 1cdc7ae..698208c 100644
@@ -432,6 +432,7 @@ struct nand_buffers {
  * @errstat:		[OPTIONAL] hardware specific function to perform additional error status checks
  *			(determine if errors are correctable)
  * @write_page:		[REPLACEABLE] High-level page write function
+ * @scan:		[REPLACEABLE] Fill in the chip size and other parameters
  */
 
 struct nand_chip {
@@ -456,6 +457,7 @@ struct nand_chip {
 	int		(*errstat)(struct mtd_info *mtd, struct nand_chip *this, int state, int status, int page);
 	int		(*write_page)(struct mtd_info *mtd, struct nand_chip *chip,
 				      const uint8_t *buf, int page, int cached, int raw);
+	int		(*scan)(struct mtd_info *mtd);
 
 	int		chip_delay;
 	unsigned int	options;
Signature · 1 line
1.7.7.1
#1 lore raw

PATCH 1/1 NAND: Allow nand_scan to be replaced by user

Quoted 24 lines · Marek Vasut

This patch allows user to supply nand_scan() call replacement via the usual method. This will be beneficial for PXA3XX NAND driver, which does further init of the chip at this stage.

---
 drivers/mtd/nand/nand_base.c |   12 +++++++++---
 include/linux/mtd/nand.h     |    2 ++
 2 files changed, 11 insertions(+), 3 deletions(-)
drivers/mtd/nand/nand_base.c +5 -0
index 27f6c77..baf7622 100644
@@ -2974,10 +2974,16 @@ int nand_scan_tail(struct mtd_info *mtd)
 int nand_scan(struct mtd_info *mtd, int maxchips)
 {
 	int ret;
+	struct nand_chip *nand = mtd->priv;
+
+	if (nand->scan) {
+		ret = nand->scan(mtd);
+	} else {

drivers/mtd/nand/nand_base.c int nand_scan_tail(struct mtd_info *mtd) · line 2988

Quoted 10 lines
drivers/mtd/nand/nand_base.c +4 -3
+		ret = nand_scan_ident(mtd, maxchips, NULL);
+		if (!ret)
+			ret = nand_scan_tail(mtd);
+	}
 
-	ret = nand_scan_ident(mtd, maxchips, NULL);
-	if (!ret)
-		ret = nand_scan_tail(mtd);
 	return ret;
 }

There is no need to change this code. Instead, we should stop calling nand_scan in the first place if we want to insert code between ident and tail.

Does the approach in the following patch work for you?
http://patchwork.ozlabs.org/patch/128816/

-Scott

#2 lore raw

PATCH 1/1 NAND: Allow nand_scan to be replaced by user

Quoted 40 lines · Marek Vasut
Quoted 39 lines

This patch allows user to supply nand_scan() call replacement via the usual method. This will be beneficial for PXA3XX NAND driver, which does further init of the chip at this stage.

---

 drivers/mtd/nand/nand_base.c |   12 +++++++++---
 include/linux/mtd/nand.h     |    2 ++
 2 files changed, 11 insertions(+), 3 deletions(-)
drivers/mtd/nand/nand_base.c +9 -3
index 27f6c77..baf7622 100644
@@ -2974,10 +2974,16 @@ int nand_scan_tail(struct mtd_info *mtd)
 
 int nand_scan(struct mtd_info *mtd, int maxchips)
 {
 
 	int ret;
 
+	struct nand_chip *nand = mtd->priv;
+
+	if (nand->scan) {
+		ret = nand->scan(mtd);
+	} else {
+		ret = nand_scan_ident(mtd, maxchips, NULL);
+		if (!ret)
+			ret = nand_scan_tail(mtd);
+	}
 
-	ret = nand_scan_ident(mtd, maxchips, NULL);
-	if (!ret)
-		ret = nand_scan_tail(mtd);

return ret;

Quoted 8 lines
Quoted 1 line

}

There is no need to change this code. Instead, we should stop calling nand_scan in the first place if we want to insert code between ident and tail.

Does the approach in the following patch work for you?
http://patchwork.ozlabs.org/patch/128816/

No, why use weak-aliased function if you can pass it like I do? If V2 passed the function pointer like I do, I'll be OK with it. Though I tried very hard to keep the pxa3xx driver as much unchanged as possible and this slightly breaks my effort. Anyway, when do you expect to see this (in some modified version, without the weak-aliased fn) mainline?

Quoted 2 lines

-Scott