[PATCH 24/39] mtd: nand: denali: add NEW_N_BANKS_FORMAT capability

Masahiro Yamada yamada.masahiro at socionext.com
Sat Nov 26 10:06:10 PST 2016


Commit 271707b1d817 ("mtd: nand: denali: max_banks calculation
changed in revision 5.1") added a revision check to support the
new max_banks encoding.  Its git-log states "The encoding of
max_banks changed in Denali revision 5.1" but I doubt it.

The revision register on some UniPhier SoCs says the IP is 5.0
but the max_banks is encoded in the new format.  The revision of
this IP is often useless.

In order to provide a way to calculate correct max_banks without
relying on the revision register, add DENALI_CAPS_NEW_N_BANKS_FORMAT
capability (quirk).

Signed-off-by: Masahiro Yamada <yamada.masahiro at socionext.com>
---

 drivers/mtd/nand/denali.c | 24 +++++++++++++++++-------
 drivers/mtd/nand/denali.h |  1 +
 2 files changed, 18 insertions(+), 7 deletions(-)

diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
index 752ad98..614b4a5 100644
--- a/drivers/mtd/nand/denali.c
+++ b/drivers/mtd/nand/denali.c
@@ -448,17 +448,27 @@ static void find_valid_banks(struct denali_nand_info *denali)
 static void detect_max_banks(struct denali_nand_info *denali)
 {
 	u32 features = ioread32(denali->flash_reg + FEATURES);
+	bool old_format;
+
 	/*
-	 * Read the revision register, so we can calculate the max_banks
-	 * properly: the encoding changed from rev 5.0 to 5.1
+	 * There are some IP versions with different n_banks encoding.
+	 * Some people say the change happened from rev 5.0 to 5.1, while
+	 * there exist variants with revision older than 5.1 but new encoding.
+	 * The option flag is available in case the revision is useless.
 	 */
-	u32 revision = MAKE_COMPARABLE_REVISION(
+	if (denali->caps & DENALI_CAPS_NEW_N_BANKS_FORMAT)
+		old_format = false;
+	else {
+		u32 revision = MAKE_COMPARABLE_REVISION(
 				ioread32(denali->flash_reg + REVISION));
 
-	if (revision < REVISION_5_1)
-		denali->max_banks = 2 << (features & FEATURES__N_BANKS);
-	else
-		denali->max_banks = 1 << (features & FEATURES__N_BANKS);
+		old_format = revision < REVISION_5_1;
+	}
+
+	denali->max_banks = 1 << (features & FEATURES__N_BANKS);
+
+	if (old_format)
+		denali->max_banks <<= 1;
 }
 
 static u16 denali_nand_timing_set(struct denali_nand_info *denali)
diff --git a/drivers/mtd/nand/denali.h b/drivers/mtd/nand/denali.h
index 9bdf037..e3fe3bc 100644
--- a/drivers/mtd/nand/denali.h
+++ b/drivers/mtd/nand/denali.h
@@ -436,6 +436,7 @@ struct denali_nand_info {
 	unsigned int caps;
 #define DENALI_CAPS_HW_ECC_FIXUP		BIT(0)
 #define DENALI_CAPS_DMA_64BIT			BIT(1)
+#define DENALI_CAPS_NEW_N_BANKS_FORMAT		BIT(2)
 };
 
 extern int denali_init(struct denali_nand_info *denali);
-- 
2.7.4




More information about the linux-mtd mailing list