Skip to contentSkip to conversation

Add big endian and ONFI support to iProc NAND

PATCH Applied Ray Jui 4 participants 10 messages Jul 20, 2016 – Oct 18, 2016

Subsystems (4)
lore
Share & tools
lore

Ray Jui

author
#0 lore raw

v2 cover Add big endian and ONFI support to iProc NAND

This patch series adds big endian and ONFI support to iProc based NAND wrapper that utilizes the BRCMSTB NAND core driver. It also adds missing NAND DT properties for NS2 SVK

This patch series is based off v4.7-rc1 and is available on GIHUB:
repo: https://github.com/Broadcom/arm64-linux.git
branch: iproc-nand-be-v2

Changes from v1:
- Fixed minor format by adding braces around the 'else'

Ray Jui (2):
mtd: brcmnand: iProc big endian and ONFI support
arm64: dts: Updated NAND DT properties for NS2 SVK

 arch/arm64/boot/dts/broadcom/ns2-svk.dts |  2 ++
 drivers/mtd/nand/brcmnand/brcmnand.c     | 12 ++++++------
 drivers/mtd/nand/brcmnand/brcmnand.h     | 13 ++++++++-----
 drivers/mtd/nand/brcmnand/iproc_nand.c   | 18 ++++++++++++++----
 4 files changed, 30 insertions(+), 15 deletions(-)
Signature · 1 line
2.1.4
author
#1 lore raw

PATCH v2 1/2 mtd: brcmnand: iProc big endian and ONFI support

This patch adds big endian and ONFI support for various iProc based SoCs that use the core brcmstb NAND controller

This patch was originally implemented by Prafulla Kota <[email protected]> and fully tested on iProc based NS2 SVK

---
 drivers/mtd/nand/brcmnand/brcmnand.c   | 12 ++++++------
 drivers/mtd/nand/brcmnand/brcmnand.h   | 13 ++++++++-----
 drivers/mtd/nand/brcmnand/iproc_nand.c | 18 ++++++++++++++----
 3 files changed, 28 insertions(+), 15 deletions(-)
drivers/mtd/nand/brcmnand/brcmnand.c +6 -6
index b76ad7c..12a1585 100644
@@ -1279,7 +1279,7 @@ static void brcmnand_cmdfunc(struct mtd_info *mtd, unsigned command,
 		u32 *flash_cache = (u32 *)ctrl->flash_cache;
 		int i;
 
-		brcmnand_soc_data_bus_prepare(ctrl->soc);
+		brcmnand_soc_data_bus_prepare(ctrl->soc, true);
 
 		/*
 		 * Must cache the FLASH_CACHE now, since changes in
@@ -1292,7 +1292,7 @@ static void brcmnand_cmdfunc(struct mtd_info *mtd, unsigned command,
 			 */
 			flash_cache[i] = be32_to_cpu(brcmnand_read_fc(ctrl, i));
 
-		brcmnand_soc_data_bus_unprepare(ctrl->soc);
+		brcmnand_soc_data_bus_unprepare(ctrl->soc, true);
 
 		/* Cleanup from HW quirk: restore SECTOR_SIZE_1K */
 		if (host->hwcfg.sector_size_1k)
@@ -1508,12 +1508,12 @@ static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip,
 		brcmnand_waitfunc(mtd, chip);
 
 		if (likely(buf)) {
-			brcmnand_soc_data_bus_prepare(ctrl->soc);
+			brcmnand_soc_data_bus_prepare(ctrl->soc, false);
 
 			for (j = 0; j < FC_WORDS; j++, buf++)
 				*buf = brcmnand_read_fc(ctrl, j);
 
-			brcmnand_soc_data_bus_unprepare(ctrl->soc);
+			brcmnand_soc_data_bus_unprepare(ctrl->soc, false);
 		}
 
 		if (oob)
@@ -1678,12 +1678,12 @@ static int brcmnand_write(struct mtd_info *mtd, struct nand_chip *chip,
 		(void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS);
 
 		if (buf) {
-			brcmnand_soc_data_bus_prepare(ctrl->soc);
+			brcmnand_soc_data_bus_prepare(ctrl->soc, false);
 
 			for (j = 0; j < FC_WORDS; j++, buf++)
 				brcmnand_write_fc(ctrl, j, *buf);
 
-			brcmnand_soc_data_bus_unprepare(ctrl->soc);
+			brcmnand_soc_data_bus_unprepare(ctrl->soc, false);
 		} else if (oob) {
 			for (j = 0; j < FC_WORDS; j++)
 				brcmnand_write_fc(ctrl, j, 0xffffffff);
drivers/mtd/nand/brcmnand/brcmnand.h +8 -5
index ef5eabb..5c44cd4 100644
@@ -23,19 +23,22 @@ struct dev_pm_ops;
 struct brcmnand_soc {
 	bool (*ctlrdy_ack)(struct brcmnand_soc *soc);
 	void (*ctlrdy_set_enabled)(struct brcmnand_soc *soc, bool en);
-	void (*prepare_data_bus)(struct brcmnand_soc *soc, bool prepare);
+	void (*prepare_data_bus)(struct brcmnand_soc *soc, bool prepare,
+				 bool is_param);
 };
 
-static inline void brcmnand_soc_data_bus_prepare(struct brcmnand_soc *soc)
+static inline void brcmnand_soc_data_bus_prepare(struct brcmnand_soc *soc,
+						 bool is_param)
 {
 	if (soc && soc->prepare_data_bus)
-		soc->prepare_data_bus(soc, true);
+		soc->prepare_data_bus(soc, true, is_param);
 }
 
-static inline void brcmnand_soc_data_bus_unprepare(struct brcmnand_soc *soc)
+static inline void brcmnand_soc_data_bus_unprepare(struct brcmnand_soc *soc,
+						   bool is_param)
 {
 	if (soc && soc->prepare_data_bus)
-		soc->prepare_data_bus(soc, false);
+		soc->prepare_data_bus(soc, false, is_param);
 }
 
 static inline u32 brcmnand_readl(void __iomem *addr)
drivers/mtd/nand/brcmnand/iproc_nand.c +14 -4
index 585596c..4c6ae11 100644
@@ -74,7 +74,8 @@ static void iproc_nand_intc_set(struct brcmnand_soc *soc, bool en)
 	spin_unlock_irqrestore(&priv->idm_lock, flags);
 }
 
-static void iproc_nand_apb_access(struct brcmnand_soc *soc, bool prepare)
+static void iproc_nand_apb_access(struct brcmnand_soc *soc, bool prepare,
+				  bool is_param)
 {
 	struct iproc_nand_soc *priv =
 			container_of(soc, struct iproc_nand_soc, soc);
@@ -86,10 +87,19 @@ static void iproc_nand_apb_access(struct brcmnand_soc *soc, bool prepare)
 
 	val = brcmnand_readl(mmio);
 
-	if (prepare)
-		val |= IPROC_NAND_APB_LE_MODE;
-	else
+	/*
+	 * In the case of BE or when dealing with NAND data, alway configure
+	 * the APB bus to LE mode before accessing the FIFO and back to BE mode
+	 * after the access is done
+	 */
+	if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) || !is_param) {
+		if (prepare)
+			val |= IPROC_NAND_APB_LE_MODE;
+		else
+			val &= ~IPROC_NAND_APB_LE_MODE;
+	} else { /* when in LE accessing the parameter page, keep APB in BE */
 		val &= ~IPROC_NAND_APB_LE_MODE;
+	}
 
 	brcmnand_writel(val, mmio);
 
Signature · 1 line
2.1.4
author
#7 lore raw

PATCH v2 2/2 arm64: dts: Updated NAND DT properties for NS2 SVK

In reply to Ray Jui

This patch adds NAND DT properties for NS2 SVK to configure the bus width width and OOB sector size

---
 arch/arm64/boot/dts/broadcom/ns2-svk.dts | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/boot/dts/broadcom/ns2-svk.dts +2 -0
index 54ca40c..5ef0407 100644
@@ -128,6 +128,8 @@
 		nand-ecc-mode = "hw";
 		nand-ecc-strength = <8>;
 		nand-ecc-step-size = <512>;
+		nand-bus-width = <16>;
+		brcm,nand-oob-sector-size = <16>;
 		#address-cells = <1>;
 		#size-cells = <1>;
 	};
Signature · 1 line
2.1.4
#2 lore raw

Re: [PATCH v2 1/2] mtd: brcmnand: iProc big endian and ONFI support

In reply to Ray Jui
Quoted 2 lines · On Wed, 20 Jul 2016 14:53:50 -0700 Ray Jui <[email protected]> wrote:

This patch adds big endian and ONFI support for various iProc based SoCs that use the core brcmstb NAND controller

Brian, Kamal, can you review this patch?

Quoted 133 lines

This patch was originally implemented by Prafulla Kota <[email protected]> and fully tested on iProc based NS2 SVK

---
 drivers/mtd/nand/brcmnand/brcmnand.c   | 12 ++++++------
 drivers/mtd/nand/brcmnand/brcmnand.h   | 13 ++++++++-----
 drivers/mtd/nand/brcmnand/iproc_nand.c | 18 ++++++++++++++----
 3 files changed, 28 insertions(+), 15 deletions(-)
drivers/mtd/nand/brcmnand/brcmnand.c +6 -6
index b76ad7c..12a1585 100644
@@ -1279,7 +1279,7 @@ static void brcmnand_cmdfunc(struct mtd_info *mtd, unsigned command,
 		u32 *flash_cache = (u32 *)ctrl->flash_cache;
 		int i;
 
-		brcmnand_soc_data_bus_prepare(ctrl->soc);
+		brcmnand_soc_data_bus_prepare(ctrl->soc, true);
 
 		/*
 		 * Must cache the FLASH_CACHE now, since changes in
@@ -1292,7 +1292,7 @@ static void brcmnand_cmdfunc(struct mtd_info *mtd, unsigned command,
 			 */
 			flash_cache[i] = be32_to_cpu(brcmnand_read_fc(ctrl, i));
 
-		brcmnand_soc_data_bus_unprepare(ctrl->soc);
+		brcmnand_soc_data_bus_unprepare(ctrl->soc, true);
 
 		/* Cleanup from HW quirk: restore SECTOR_SIZE_1K */
 		if (host->hwcfg.sector_size_1k)
@@ -1508,12 +1508,12 @@ static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip,
 		brcmnand_waitfunc(mtd, chip);
 
 		if (likely(buf)) {
-			brcmnand_soc_data_bus_prepare(ctrl->soc);
+			brcmnand_soc_data_bus_prepare(ctrl->soc, false);
 
 			for (j = 0; j < FC_WORDS; j++, buf++)
 				*buf = brcmnand_read_fc(ctrl, j);
 
-			brcmnand_soc_data_bus_unprepare(ctrl->soc);
+			brcmnand_soc_data_bus_unprepare(ctrl->soc, false);
 		}
 
 		if (oob)
@@ -1678,12 +1678,12 @@ static int brcmnand_write(struct mtd_info *mtd, struct nand_chip *chip,
 		(void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS);
 
 		if (buf) {
-			brcmnand_soc_data_bus_prepare(ctrl->soc);
+			brcmnand_soc_data_bus_prepare(ctrl->soc, false);
 
 			for (j = 0; j < FC_WORDS; j++, buf++)
 				brcmnand_write_fc(ctrl, j, *buf);
 
-			brcmnand_soc_data_bus_unprepare(ctrl->soc);
+			brcmnand_soc_data_bus_unprepare(ctrl->soc, false);
 		} else if (oob) {
 			for (j = 0; j < FC_WORDS; j++)
 				brcmnand_write_fc(ctrl, j, 0xffffffff);
drivers/mtd/nand/brcmnand/brcmnand.h +8 -5
index ef5eabb..5c44cd4 100644
@@ -23,19 +23,22 @@ struct dev_pm_ops;
 struct brcmnand_soc {
 	bool (*ctlrdy_ack)(struct brcmnand_soc *soc);
 	void (*ctlrdy_set_enabled)(struct brcmnand_soc *soc, bool en);
-	void (*prepare_data_bus)(struct brcmnand_soc *soc, bool prepare);
+	void (*prepare_data_bus)(struct brcmnand_soc *soc, bool prepare,
+				 bool is_param);
 };
 
-static inline void brcmnand_soc_data_bus_prepare(struct brcmnand_soc *soc)
+static inline void brcmnand_soc_data_bus_prepare(struct brcmnand_soc *soc,
+						 bool is_param)
 {
 	if (soc && soc->prepare_data_bus)
-		soc->prepare_data_bus(soc, true);
+		soc->prepare_data_bus(soc, true, is_param);
 }
 
-static inline void brcmnand_soc_data_bus_unprepare(struct brcmnand_soc *soc)
+static inline void brcmnand_soc_data_bus_unprepare(struct brcmnand_soc *soc,
+						   bool is_param)
 {
 	if (soc && soc->prepare_data_bus)
-		soc->prepare_data_bus(soc, false);
+		soc->prepare_data_bus(soc, false, is_param);
 }
 
 static inline u32 brcmnand_readl(void __iomem *addr)
drivers/mtd/nand/brcmnand/iproc_nand.c +14 -4
index 585596c..4c6ae11 100644
@@ -74,7 +74,8 @@ static void iproc_nand_intc_set(struct brcmnand_soc *soc, bool en)
 	spin_unlock_irqrestore(&priv->idm_lock, flags);
 }
 
-static void iproc_nand_apb_access(struct brcmnand_soc *soc, bool prepare)
+static void iproc_nand_apb_access(struct brcmnand_soc *soc, bool prepare,
+				  bool is_param)
 {
 	struct iproc_nand_soc *priv =
 			container_of(soc, struct iproc_nand_soc, soc);
@@ -86,10 +87,19 @@ static void iproc_nand_apb_access(struct brcmnand_soc *soc, bool prepare)
 
 	val = brcmnand_readl(mmio);
 
-	if (prepare)
-		val |= IPROC_NAND_APB_LE_MODE;
-	else
+	/*
+	 * In the case of BE or when dealing with NAND data, alway configure
+	 * the APB bus to LE mode before accessing the FIFO and back to BE mode
+	 * after the access is done
+	 */
+	if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) || !is_param) {
+		if (prepare)
+			val |= IPROC_NAND_APB_LE_MODE;
+		else
+			val &= ~IPROC_NAND_APB_LE_MODE;
+	} else { /* when in LE accessing the parameter page, keep APB in BE */
 		val &= ~IPROC_NAND_APB_LE_MODE;
+	}
 
 	brcmnand_writel(val, mmio);
 
Reviewed-by
#3 lore raw

Re: [PATCH v2 1/2] mtd: brcmnand: iProc big endian and ONFI support

Boris

This change looks good to me.

Quoted 14 lines · Boris Brezillon
Quoted 2 lines · On Wed, 20 Jul 2016 14:53:50 -0700 Ray Jui <[email protected]> wrote:

This patch adds big endian and ONFI support for various iProc based SoCs that use the core brcmstb NAND controller

Brian, Kamal, can you review this patch?

Quoted 6 lines

This patch was originally implemented by Prafulla Kota <[email protected]> and fully tested on iProc based NS2 SVK

Quoted 128 lines
Quoted 127 lines
---
 drivers/mtd/nand/brcmnand/brcmnand.c   | 12 ++++++------
 drivers/mtd/nand/brcmnand/brcmnand.h   | 13 ++++++++-----
 drivers/mtd/nand/brcmnand/iproc_nand.c | 18 ++++++++++++++----
 3 files changed, 28 insertions(+), 15 deletions(-)
drivers/mtd/nand/brcmnand/brcmnand.c +6 -6
index b76ad7c..12a1585 100644
@@ -1279,7 +1279,7 @@ static void brcmnand_cmdfunc(struct mtd_info *mtd, unsigned command,
              u32 *flash_cache = (u32 *)ctrl->flash_cache;
              int i;
 
-             brcmnand_soc_data_bus_prepare(ctrl->soc);
+             brcmnand_soc_data_bus_prepare(ctrl->soc, true);
 
              /*
               * Must cache the FLASH_CACHE now, since changes in
@@ -1292,7 +1292,7 @@ static void brcmnand_cmdfunc(struct mtd_info *mtd, unsigned command,
                       */
                      flash_cache[i] = be32_to_cpu(brcmnand_read_fc(ctrl, i));
 
-             brcmnand_soc_data_bus_unprepare(ctrl->soc);
+             brcmnand_soc_data_bus_unprepare(ctrl->soc, true);
 
              /* Cleanup from HW quirk: restore SECTOR_SIZE_1K */
              if (host->hwcfg.sector_size_1k)
@@ -1508,12 +1508,12 @@ static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip,
              brcmnand_waitfunc(mtd, chip);
 
              if (likely(buf)) {
-                     brcmnand_soc_data_bus_prepare(ctrl->soc);
+                     brcmnand_soc_data_bus_prepare(ctrl->soc, false);
 
                      for (j = 0; j < FC_WORDS; j++, buf++)
                              *buf = brcmnand_read_fc(ctrl, j);
 
-                     brcmnand_soc_data_bus_unprepare(ctrl->soc);
+                     brcmnand_soc_data_bus_unprepare(ctrl->soc, false);
              }
 
              if (oob)
@@ -1678,12 +1678,12 @@ static int brcmnand_write(struct mtd_info *mtd, struct nand_chip *chip,
              (void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS);
 
              if (buf) {
-                     brcmnand_soc_data_bus_prepare(ctrl->soc);
+                     brcmnand_soc_data_bus_prepare(ctrl->soc, false);
 
                      for (j = 0; j < FC_WORDS; j++, buf++)
                              brcmnand_write_fc(ctrl, j, *buf);
 
-                     brcmnand_soc_data_bus_unprepare(ctrl->soc);
+                     brcmnand_soc_data_bus_unprepare(ctrl->soc, false);
              } else if (oob) {
                      for (j = 0; j < FC_WORDS; j++)
                              brcmnand_write_fc(ctrl, j, 0xffffffff);
drivers/mtd/nand/brcmnand/brcmnand.h +8 -5
index ef5eabb..5c44cd4 100644
@@ -23,19 +23,22 @@ struct dev_pm_ops;
 struct brcmnand_soc {
      bool (*ctlrdy_ack)(struct brcmnand_soc *soc);
      void (*ctlrdy_set_enabled)(struct brcmnand_soc *soc, bool en);
-     void (*prepare_data_bus)(struct brcmnand_soc *soc, bool prepare);
+     void (*prepare_data_bus)(struct brcmnand_soc *soc, bool prepare,
+                              bool is_param);
 };
 
-static inline void brcmnand_soc_data_bus_prepare(struct brcmnand_soc *soc)
+static inline void brcmnand_soc_data_bus_prepare(struct brcmnand_soc *soc,
+                                              bool is_param)
 {
      if (soc && soc->prepare_data_bus)
-             soc->prepare_data_bus(soc, true);
+             soc->prepare_data_bus(soc, true, is_param);
 }
 
-static inline void brcmnand_soc_data_bus_unprepare(struct brcmnand_soc *soc)
+static inline void brcmnand_soc_data_bus_unprepare(struct brcmnand_soc *soc,
+                                                bool is_param)
 {
      if (soc && soc->prepare_data_bus)
-             soc->prepare_data_bus(soc, false);
+             soc->prepare_data_bus(soc, false, is_param);
 }
 
 static inline u32 brcmnand_readl(void __iomem *addr)
drivers/mtd/nand/brcmnand/iproc_nand.c +14 -4
index 585596c..4c6ae11 100644
@@ -74,7 +74,8 @@ static void iproc_nand_intc_set(struct brcmnand_soc *soc, bool en)
      spin_unlock_irqrestore(&priv->idm_lock, flags);
 }
 
-static void iproc_nand_apb_access(struct brcmnand_soc *soc, bool prepare)
+static void iproc_nand_apb_access(struct brcmnand_soc *soc, bool prepare,
+                               bool is_param)
 {
      struct iproc_nand_soc *priv =
                      container_of(soc, struct iproc_nand_soc, soc);
@@ -86,10 +87,19 @@ static void iproc_nand_apb_access(struct brcmnand_soc *soc, bool prepare)
 
      val = brcmnand_readl(mmio);
 
-     if (prepare)
-             val |= IPROC_NAND_APB_LE_MODE;
-     else
+     /*
+      * In the case of BE or when dealing with NAND data, alway configure
+      * the APB bus to LE mode before accessing the FIFO and back to BE mode
+      * after the access is done
+      */
+     if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) || !is_param) {
+             if (prepare)
+                     val |= IPROC_NAND_APB_LE_MODE;
+             else
+                     val &= ~IPROC_NAND_APB_LE_MODE;
+     } else { /* when in LE accessing the parameter page, keep APB in BE */
              val &= ~IPROC_NAND_APB_LE_MODE;
+     }
 
      brcmnand_writel(val, mmio);
 
#4 lore raw

Re: [PATCH v2 1/2] mtd: brcmnand: iProc big endian and ONFI support

Quoted 3 lines · On Fri, 19 Aug 2016 11:14:17 -0400 Kamal Dasu <[email protected]> wrote:

Boris

This change looks good to me.

Is this an Acked-by or a Reviewed-by? :)

Quoted 153 lines
Quoted 14 lines · Boris Brezillon
Quoted 2 lines · On Wed, 20 Jul 2016 14:53:50 -0700 Ray Jui <[email protected]> wrote:

This patch adds big endian and ONFI support for various iProc based SoCs that use the core brcmstb NAND controller

Brian, Kamal, can you review this patch?

Quoted 6 lines

This patch was originally implemented by Prafulla Kota <[email protected]> and fully tested on iProc based NS2 SVK

Quoted 125 lines
Quoted 125 lines
---
 drivers/mtd/nand/brcmnand/brcmnand.c   | 12 ++++++------
 drivers/mtd/nand/brcmnand/brcmnand.h   | 13 ++++++++-----
 drivers/mtd/nand/brcmnand/iproc_nand.c | 18 ++++++++++++++----
 3 files changed, 28 insertions(+), 15 deletions(-)
drivers/mtd/nand/brcmnand/brcmnand.c +6 -6
index b76ad7c..12a1585 100644
@@ -1279,7 +1279,7 @@ static void brcmnand_cmdfunc(struct mtd_info *mtd, unsigned command,
              u32 *flash_cache = (u32 *)ctrl->flash_cache;
              int i;
 
-             brcmnand_soc_data_bus_prepare(ctrl->soc);
+             brcmnand_soc_data_bus_prepare(ctrl->soc, true);
 
              /*
               * Must cache the FLASH_CACHE now, since changes in
@@ -1292,7 +1292,7 @@ static void brcmnand_cmdfunc(struct mtd_info *mtd, unsigned command,
                       */
                      flash_cache[i] = be32_to_cpu(brcmnand_read_fc(ctrl, i));
 
-             brcmnand_soc_data_bus_unprepare(ctrl->soc);
+             brcmnand_soc_data_bus_unprepare(ctrl->soc, true);
 
              /* Cleanup from HW quirk: restore SECTOR_SIZE_1K */
              if (host->hwcfg.sector_size_1k)
@@ -1508,12 +1508,12 @@ static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip,
              brcmnand_waitfunc(mtd, chip);
 
              if (likely(buf)) {
-                     brcmnand_soc_data_bus_prepare(ctrl->soc);
+                     brcmnand_soc_data_bus_prepare(ctrl->soc, false);
 
                      for (j = 0; j < FC_WORDS; j++, buf++)
                              *buf = brcmnand_read_fc(ctrl, j);
 
-                     brcmnand_soc_data_bus_unprepare(ctrl->soc);
+                     brcmnand_soc_data_bus_unprepare(ctrl->soc, false);
              }
 
              if (oob)
@@ -1678,12 +1678,12 @@ static int brcmnand_write(struct mtd_info *mtd, struct nand_chip *chip,
              (void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS);
 
              if (buf) {
-                     brcmnand_soc_data_bus_prepare(ctrl->soc);
+                     brcmnand_soc_data_bus_prepare(ctrl->soc, false);
 
                      for (j = 0; j < FC_WORDS; j++, buf++)
                              brcmnand_write_fc(ctrl, j, *buf);
 
-                     brcmnand_soc_data_bus_unprepare(ctrl->soc);
+                     brcmnand_soc_data_bus_unprepare(ctrl->soc, false);
              } else if (oob) {
                      for (j = 0; j < FC_WORDS; j++)
                              brcmnand_write_fc(ctrl, j, 0xffffffff);
drivers/mtd/nand/brcmnand/brcmnand.h +8 -5
index ef5eabb..5c44cd4 100644
@@ -23,19 +23,22 @@ struct dev_pm_ops;
 struct brcmnand_soc {
      bool (*ctlrdy_ack)(struct brcmnand_soc *soc);
      void (*ctlrdy_set_enabled)(struct brcmnand_soc *soc, bool en);
-     void (*prepare_data_bus)(struct brcmnand_soc *soc, bool prepare);
+     void (*prepare_data_bus)(struct brcmnand_soc *soc, bool prepare,
+                              bool is_param);
 };
 
-static inline void brcmnand_soc_data_bus_prepare(struct brcmnand_soc *soc)
+static inline void brcmnand_soc_data_bus_prepare(struct brcmnand_soc *soc,
+                                              bool is_param)
 {
      if (soc && soc->prepare_data_bus)
-             soc->prepare_data_bus(soc, true);
+             soc->prepare_data_bus(soc, true, is_param);
 }
 
-static inline void brcmnand_soc_data_bus_unprepare(struct brcmnand_soc *soc)
+static inline void brcmnand_soc_data_bus_unprepare(struct brcmnand_soc *soc,
+                                                bool is_param)
 {
      if (soc && soc->prepare_data_bus)
-             soc->prepare_data_bus(soc, false);
+             soc->prepare_data_bus(soc, false, is_param);
 }
 
 static inline u32 brcmnand_readl(void __iomem *addr)
drivers/mtd/nand/brcmnand/iproc_nand.c +14 -4
index 585596c..4c6ae11 100644
@@ -74,7 +74,8 @@ static void iproc_nand_intc_set(struct brcmnand_soc *soc, bool en)
      spin_unlock_irqrestore(&priv->idm_lock, flags);
 }
 
-static void iproc_nand_apb_access(struct brcmnand_soc *soc, bool prepare)
+static void iproc_nand_apb_access(struct brcmnand_soc *soc, bool prepare,
+                               bool is_param)
 {
      struct iproc_nand_soc *priv =
                      container_of(soc, struct iproc_nand_soc, soc);
@@ -86,10 +87,19 @@ static void iproc_nand_apb_access(struct brcmnand_soc *soc, bool prepare)
 
      val = brcmnand_readl(mmio);
 
-     if (prepare)
-             val |= IPROC_NAND_APB_LE_MODE;
-     else
+     /*
+      * In the case of BE or when dealing with NAND data, alway configure
+      * the APB bus to LE mode before accessing the FIFO and back to BE mode
+      * after the access is done
+      */
+     if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) || !is_param) {
+             if (prepare)
+                     val |= IPROC_NAND_APB_LE_MODE;
+             else
+                     val &= ~IPROC_NAND_APB_LE_MODE;
+     } else { /* when in LE accessing the parameter page, keep APB in BE */
              val &= ~IPROC_NAND_APB_LE_MODE;
+     }
 
Quoted 3 lines

drivers/mtd/nand/brcmnand/iproc_nand.c static void iproc_nand_apb_access(struct brcmnand_soc *soc, bool prepare) · line 105

Quoted 2 lines
drivers/mtd/nand/brcmnand/iproc_nand.c +0 -0
      brcmnand_writel(val, mmio);
 

______________________________________________________
Linux MTD discussion mailing list
http://lists.infradead.org/mailman/listinfo/linux-mtd/

Acked-by
#5 lore raw

Re: [PATCH v2 1/2] mtd: brcmnand: iProc big endian and ONFI support

In reply to Boris Brezillon
Quoted 14 lines · Boris Brezillon
Quoted 2 lines · On Wed, 20 Jul 2016 14:53:50 -0700 Ray Jui <[email protected]> wrote:

This patch adds big endian and ONFI support for various iProc based SoCs that use the core brcmstb NAND controller

Brian, Kamal, can you review this patch?

Quoted 6 lines

This patch was originally implemented by Prafulla Kota <[email protected]> and fully tested on iProc based NS2 SVK

Quoted 128 lines
Quoted 127 lines
---
 drivers/mtd/nand/brcmnand/brcmnand.c   | 12 ++++++------
 drivers/mtd/nand/brcmnand/brcmnand.h   | 13 ++++++++-----
 drivers/mtd/nand/brcmnand/iproc_nand.c | 18 ++++++++++++++----
 3 files changed, 28 insertions(+), 15 deletions(-)
drivers/mtd/nand/brcmnand/brcmnand.c +6 -6
index b76ad7c..12a1585 100644
@@ -1279,7 +1279,7 @@ static void brcmnand_cmdfunc(struct mtd_info *mtd, unsigned command,
              u32 *flash_cache = (u32 *)ctrl->flash_cache;
              int i;
 
-             brcmnand_soc_data_bus_prepare(ctrl->soc);
+             brcmnand_soc_data_bus_prepare(ctrl->soc, true);
 
              /*
               * Must cache the FLASH_CACHE now, since changes in
@@ -1292,7 +1292,7 @@ static void brcmnand_cmdfunc(struct mtd_info *mtd, unsigned command,
                       */
                      flash_cache[i] = be32_to_cpu(brcmnand_read_fc(ctrl, i));
 
-             brcmnand_soc_data_bus_unprepare(ctrl->soc);
+             brcmnand_soc_data_bus_unprepare(ctrl->soc, true);
 
              /* Cleanup from HW quirk: restore SECTOR_SIZE_1K */
              if (host->hwcfg.sector_size_1k)
@@ -1508,12 +1508,12 @@ static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip,
              brcmnand_waitfunc(mtd, chip);
 
              if (likely(buf)) {
-                     brcmnand_soc_data_bus_prepare(ctrl->soc);
+                     brcmnand_soc_data_bus_prepare(ctrl->soc, false);
 
                      for (j = 0; j < FC_WORDS; j++, buf++)
                              *buf = brcmnand_read_fc(ctrl, j);
 
-                     brcmnand_soc_data_bus_unprepare(ctrl->soc);
+                     brcmnand_soc_data_bus_unprepare(ctrl->soc, false);
              }
 
              if (oob)
@@ -1678,12 +1678,12 @@ static int brcmnand_write(struct mtd_info *mtd, struct nand_chip *chip,
              (void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS);
 
              if (buf) {
-                     brcmnand_soc_data_bus_prepare(ctrl->soc);
+                     brcmnand_soc_data_bus_prepare(ctrl->soc, false);
 
                      for (j = 0; j < FC_WORDS; j++, buf++)
                              brcmnand_write_fc(ctrl, j, *buf);
 
-                     brcmnand_soc_data_bus_unprepare(ctrl->soc);
+                     brcmnand_soc_data_bus_unprepare(ctrl->soc, false);
              } else if (oob) {
                      for (j = 0; j < FC_WORDS; j++)
                              brcmnand_write_fc(ctrl, j, 0xffffffff);
drivers/mtd/nand/brcmnand/brcmnand.h +8 -5
index ef5eabb..5c44cd4 100644
@@ -23,19 +23,22 @@ struct dev_pm_ops;
 struct brcmnand_soc {
      bool (*ctlrdy_ack)(struct brcmnand_soc *soc);
      void (*ctlrdy_set_enabled)(struct brcmnand_soc *soc, bool en);
-     void (*prepare_data_bus)(struct brcmnand_soc *soc, bool prepare);
+     void (*prepare_data_bus)(struct brcmnand_soc *soc, bool prepare,
+                              bool is_param);
 };
 
-static inline void brcmnand_soc_data_bus_prepare(struct brcmnand_soc *soc)
+static inline void brcmnand_soc_data_bus_prepare(struct brcmnand_soc *soc,
+                                              bool is_param)
 {
      if (soc && soc->prepare_data_bus)
-             soc->prepare_data_bus(soc, true);
+             soc->prepare_data_bus(soc, true, is_param);
 }
 
-static inline void brcmnand_soc_data_bus_unprepare(struct brcmnand_soc *soc)
+static inline void brcmnand_soc_data_bus_unprepare(struct brcmnand_soc *soc,
+                                                bool is_param)
 {
      if (soc && soc->prepare_data_bus)
-             soc->prepare_data_bus(soc, false);
+             soc->prepare_data_bus(soc, false, is_param);
 }
 
 static inline u32 brcmnand_readl(void __iomem *addr)
drivers/mtd/nand/brcmnand/iproc_nand.c +14 -4
index 585596c..4c6ae11 100644
@@ -74,7 +74,8 @@ static void iproc_nand_intc_set(struct brcmnand_soc *soc, bool en)
      spin_unlock_irqrestore(&priv->idm_lock, flags);
 }
 
-static void iproc_nand_apb_access(struct brcmnand_soc *soc, bool prepare)
+static void iproc_nand_apb_access(struct brcmnand_soc *soc, bool prepare,
+                               bool is_param)
 {
      struct iproc_nand_soc *priv =
                      container_of(soc, struct iproc_nand_soc, soc);
@@ -86,10 +87,19 @@ static void iproc_nand_apb_access(struct brcmnand_soc *soc, bool prepare)
 
      val = brcmnand_readl(mmio);
 
-     if (prepare)
-             val |= IPROC_NAND_APB_LE_MODE;
-     else
+     /*
+      * In the case of BE or when dealing with NAND data, alway configure
+      * the APB bus to LE mode before accessing the FIFO and back to BE mode
+      * after the access is done
+      */
+     if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) || !is_param) {
+             if (prepare)
+                     val |= IPROC_NAND_APB_LE_MODE;
+             else
+                     val &= ~IPROC_NAND_APB_LE_MODE;
+     } else { /* when in LE accessing the parameter page, keep APB in BE */
              val &= ~IPROC_NAND_APB_LE_MODE;
+     }
 
      brcmnand_writel(val, mmio);
 
#6 lore raw

Re: [PATCH v2 1/2] mtd: brcmnand: iProc big endian and ONFI support

In reply to Ray Jui
Quoted 8 lines · On Wed, 20 Jul 2016 14:53:50 -0700 Ray Jui <[email protected]> wrote:

This patch adds big endian and ONFI support for various iProc based SoCs that use the core brcmstb NAND controller

This patch was originally implemented by Prafulla Kota <[email protected]> and fully tested on iProc based NS2 SVK

Applied.

Thanks,

Boris

Quoted 127 lines
---
 drivers/mtd/nand/brcmnand/brcmnand.c   | 12 ++++++------
 drivers/mtd/nand/brcmnand/brcmnand.h   | 13 ++++++++-----
 drivers/mtd/nand/brcmnand/iproc_nand.c | 18 ++++++++++++++----
 3 files changed, 28 insertions(+), 15 deletions(-)
drivers/mtd/nand/brcmnand/brcmnand.c +6 -6
index b76ad7c..12a1585 100644
@@ -1279,7 +1279,7 @@ static void brcmnand_cmdfunc(struct mtd_info *mtd, unsigned command,
 		u32 *flash_cache = (u32 *)ctrl->flash_cache;
 		int i;
 
-		brcmnand_soc_data_bus_prepare(ctrl->soc);
+		brcmnand_soc_data_bus_prepare(ctrl->soc, true);
 
 		/*
 		 * Must cache the FLASH_CACHE now, since changes in
@@ -1292,7 +1292,7 @@ static void brcmnand_cmdfunc(struct mtd_info *mtd, unsigned command,
 			 */
 			flash_cache[i] = be32_to_cpu(brcmnand_read_fc(ctrl, i));
 
-		brcmnand_soc_data_bus_unprepare(ctrl->soc);
+		brcmnand_soc_data_bus_unprepare(ctrl->soc, true);
 
 		/* Cleanup from HW quirk: restore SECTOR_SIZE_1K */
 		if (host->hwcfg.sector_size_1k)
@@ -1508,12 +1508,12 @@ static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip,
 		brcmnand_waitfunc(mtd, chip);
 
 		if (likely(buf)) {
-			brcmnand_soc_data_bus_prepare(ctrl->soc);
+			brcmnand_soc_data_bus_prepare(ctrl->soc, false);
 
 			for (j = 0; j < FC_WORDS; j++, buf++)
 				*buf = brcmnand_read_fc(ctrl, j);
 
-			brcmnand_soc_data_bus_unprepare(ctrl->soc);
+			brcmnand_soc_data_bus_unprepare(ctrl->soc, false);
 		}
 
 		if (oob)
@@ -1678,12 +1678,12 @@ static int brcmnand_write(struct mtd_info *mtd, struct nand_chip *chip,
 		(void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS);
 
 		if (buf) {
-			brcmnand_soc_data_bus_prepare(ctrl->soc);
+			brcmnand_soc_data_bus_prepare(ctrl->soc, false);
 
 			for (j = 0; j < FC_WORDS; j++, buf++)
 				brcmnand_write_fc(ctrl, j, *buf);
 
-			brcmnand_soc_data_bus_unprepare(ctrl->soc);
+			brcmnand_soc_data_bus_unprepare(ctrl->soc, false);
 		} else if (oob) {
 			for (j = 0; j < FC_WORDS; j++)
 				brcmnand_write_fc(ctrl, j, 0xffffffff);
drivers/mtd/nand/brcmnand/brcmnand.h +8 -5
index ef5eabb..5c44cd4 100644
@@ -23,19 +23,22 @@ struct dev_pm_ops;
 struct brcmnand_soc {
 	bool (*ctlrdy_ack)(struct brcmnand_soc *soc);
 	void (*ctlrdy_set_enabled)(struct brcmnand_soc *soc, bool en);
-	void (*prepare_data_bus)(struct brcmnand_soc *soc, bool prepare);
+	void (*prepare_data_bus)(struct brcmnand_soc *soc, bool prepare,
+				 bool is_param);
 };
 
-static inline void brcmnand_soc_data_bus_prepare(struct brcmnand_soc *soc)
+static inline void brcmnand_soc_data_bus_prepare(struct brcmnand_soc *soc,
+						 bool is_param)
 {
 	if (soc && soc->prepare_data_bus)
-		soc->prepare_data_bus(soc, true);
+		soc->prepare_data_bus(soc, true, is_param);
 }
 
-static inline void brcmnand_soc_data_bus_unprepare(struct brcmnand_soc *soc)
+static inline void brcmnand_soc_data_bus_unprepare(struct brcmnand_soc *soc,
+						   bool is_param)
 {
 	if (soc && soc->prepare_data_bus)
-		soc->prepare_data_bus(soc, false);
+		soc->prepare_data_bus(soc, false, is_param);
 }
 
 static inline u32 brcmnand_readl(void __iomem *addr)
drivers/mtd/nand/brcmnand/iproc_nand.c +14 -4
index 585596c..4c6ae11 100644
@@ -74,7 +74,8 @@ static void iproc_nand_intc_set(struct brcmnand_soc *soc, bool en)
 	spin_unlock_irqrestore(&priv->idm_lock, flags);
 }
 
-static void iproc_nand_apb_access(struct brcmnand_soc *soc, bool prepare)
+static void iproc_nand_apb_access(struct brcmnand_soc *soc, bool prepare,
+				  bool is_param)
 {
 	struct iproc_nand_soc *priv =
 			container_of(soc, struct iproc_nand_soc, soc);
@@ -86,10 +87,19 @@ static void iproc_nand_apb_access(struct brcmnand_soc *soc, bool prepare)
 
 	val = brcmnand_readl(mmio);
 
-	if (prepare)
-		val |= IPROC_NAND_APB_LE_MODE;
-	else
+	/*
+	 * In the case of BE or when dealing with NAND data, alway configure
+	 * the APB bus to LE mode before accessing the FIFO and back to BE mode
+	 * after the access is done
+	 */
+	if (IS_ENABLED(CONFIG_CPU_BIG_ENDIAN) || !is_param) {
+		if (prepare)
+			val |= IPROC_NAND_APB_LE_MODE;
+		else
+			val &= ~IPROC_NAND_APB_LE_MODE;
+	} else { /* when in LE accessing the parameter page, keep APB in BE */
 		val &= ~IPROC_NAND_APB_LE_MODE;
+	}
 
 	brcmnand_writel(val, mmio);
 
author
#8 lore raw

Re: [PATCH v2 2/2] arm64: dts: Updated NAND DT properties for NS2 SVK

In reply to Ray Jui

Hi Florian,

Would you be able to help to queue the following patch for v4.10? Sorry I did not include you in the "To" field of the original email.

Thanks,

Ray

Quoted 23 lines · Ray Jui

This patch adds NAND DT properties for NS2 SVK to configure the bus width width and OOB sector size

---
 arch/arm64/boot/dts/broadcom/ns2-svk.dts | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/boot/dts/broadcom/ns2-svk.dts +2 -0
index 54ca40c..5ef0407 100644
@@ -128,6 +128,8 @@
 		nand-ecc-mode = "hw";
 		nand-ecc-strength = <8>;
 		nand-ecc-step-size = <512>;
+		nand-bus-width = <16>;
+		brcm,nand-oob-sector-size = <16>;
 		#address-cells = <1>;
 		#size-cells = <1>;
 	};
#9 lore raw

Re: [PATCH v2 2/2] arm64: dts: Updated NAND DT properties for NS2 SVK

Quoted 4 lines · Ray Jui

Hi Florian,

Would you be able to help to queue the following patch for v4.10? Sorry I did not include you in the "To" field of the original email.

Applied, thanks!

Signature · 1 line
Florian