[U-Boot] [PATCH v5] Corrupted NAND Flash access on KARO TX25 modules.

The mxc_nand driver uses the symmetric mode to access the NAND Flash, but the devices populated on the KARO TX25 only support ann asymmetic mode (MX25: bit 8 within NAND_FLAHS_CONFIG1 register cleared).
This patch enables to selected the NAND Flash access mode with the configuration flag CONFIG_SYS_NAND_MXC_NFC_TWO_CYCLES.
Signed-off-by: Daniel Gachet daniel.gachet@hefr.ch --- drivers/mtd/nand/mxc_nand.c | 13 +++++++++++++ include/configs/tx25.h | 1 + 2 files changed, 14 insertions(+)
diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c index 936186f..08fbb12 100644 --- a/drivers/mtd/nand/mxc_nand.c +++ b/drivers/mtd/nand/mxc_nand.c @@ -48,6 +48,17 @@ * Reading or writing a 2K or 4K page requires only 1 FDI/FDO cycle. * Also some of registers are moved and/or changed meaning as seen below. */ +/* + * NAND Flash access mode on MX25 + * + * The MX25 NAND Flash Controller supports two modes to access the Flash: + * a) symmetric mode (one Flash clock cycle per access) or + * b) asymmetric mode (two Flash clock cycles per access) + * + * By default the NAND Flash Controller is configured in the symmetric mode. + * To select the asymmetric mode, the configuration option + * CONFIG_SYS_NAND_MXC_NFC_TWO_CYCLES has to be selected. + */ #if defined(CONFIG_MX31) || defined(CONFIG_MX27) #define MXC_NFC_V1 #elif defined(CONFIG_MX25) || defined(CONFIG_MX35) @@ -1290,7 +1301,9 @@ static void mxc_setup_config1(void) uint16_t tmp;
tmp = readw(&host->regs->nfc_config1); +#ifndef CONFIG_SYS_NAND_MXC_NFC_TWO_CYCLES tmp |= NFC_ONE_CYCLE; +#endif tmp |= NFC_4_8N_ECC; writew(tmp, &host->regs->nfc_config1); if (host->pagesize_2k) diff --git a/include/configs/tx25.h b/include/configs/tx25.h index 6821528..8fa51cb 100644 --- a/include/configs/tx25.h +++ b/include/configs/tx25.h @@ -109,6 +109,7 @@ /* NAND */ #define CONFIG_NAND_MXC #define CONFIG_NAND_MXC_V1_1 +#define CONFIG_SYS_NAND_MXC_NFC_TWO_CYCLES /* 2 cycles to access NAND Flash */ #define CONFIG_MXC_NAND_REGS_BASE (0xBB000000) #define CONFIG_SYS_MAX_NAND_DEVICE 1 #define CONFIG_SYS_NAND_BASE (0xBB000000)

Dear Daniel,
On Thu, Aug 2, 2012 at 01:17:07 PM, Daniel Gachet wrote:
The mxc_nand driver uses the symmetric mode to access the NAND Flash, but the devices populated on the KARO TX25 only support ann asymmetic mode (MX25: bit 8 within NAND_FLAHS_CONFIG1 register cleared).
This patch enables to selected the NAND Flash access mode with the configuration flag CONFIG_SYS_NAND_MXC_NFC_TWO_CYCLES.
Signed-off-by: Daniel Gachet daniel.gachet@hefr.ch
drivers/mtd/nand/mxc_nand.c | 13 +++++++++++++ include/configs/tx25.h | 1 + 2 files changed, 14 insertions(+)
diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c index 936186f..08fbb12 100644 --- a/drivers/mtd/nand/mxc_nand.c +++ b/drivers/mtd/nand/mxc_nand.c @@ -48,6 +48,17 @@
- Reading or writing a 2K or 4K page requires only 1 FDI/FDO
cycle.
Also some of registers are moved and/or changed meaning as
seen below. */ +/*
- NAND Flash access mode on MX25
- The MX25 NAND Flash Controller supports two modes to access the
Flash:
- a) symmetric mode (one Flash clock cycle per access) or
- b) asymmetric mode (two Flash clock cycles per access)
- By default the NAND Flash Controller is configured in the
symmetric mode.
- To select the asymmetric mode, the configuration option
- CONFIG_SYS_NAND_MXC_NFC_TWO_CYCLES has to be selected.
- */
#if defined(CONFIG_MX31) || defined(CONFIG_MX27) #define MXC_NFC_V1 #elif defined(CONFIG_MX25) || defined(CONFIG_MX35) @@ -1290,7 +1301,9 @@ static void mxc_setup_config1(void) uint16_t tmp;
tmp = readw(&host->regs->nfc_config1); +#ifndef CONFIG_SYS_NAND_MXC_NFC_TWO_CYCLES tmp |= NFC_ONE_CYCLE; +#endif tmp |= NFC_4_8N_ECC; writew(tmp, &host->regs->nfc_config1); if (host->pagesize_2k) diff --git a/include/configs/tx25.h b/include/configs/tx25.h index 6821528..8fa51cb 100644 --- a/include/configs/tx25.h +++ b/include/configs/tx25.h @@ -109,6 +109,7 @@ /* NAND */ #define CONFIG_NAND_MXC #define CONFIG_NAND_MXC_V1_1 +#define CONFIG_SYS_NAND_MXC_NFC_TWO_CYCLES /* 2 cycles to access NAND Flash */ #define CONFIG_MXC_NAND_REGS_BASE (0xBB000000) #define CONFIG_SYS_MAX_NAND_DEVICE 1
#define CONFIG_SYS_NAND_BASE (0xBB000000)
1.7.9.5
U-Boot mailing list U-Boot@lists.denx.de http://lists.denx.de/mailman/listinfo/u-boot
Why don't you simply add a factor of two to the CCM NFC divider in lowlevel_init.S?
Best regards, Benoît

Dear Daniel, Scott,
On Thu, Aug 2, 2012 at 01:28:08 PM, Benoît Thébaudeau wrote:
On Thu, Aug 2, 2012 at 01:17:07 PM, Daniel Gachet wrote:
The mxc_nand driver uses the symmetric mode to access the NAND Flash, but the devices populated on the KARO TX25 only support ann asymmetic mode (MX25: bit 8 within NAND_FLAHS_CONFIG1 register cleared).
This patch enables to selected the NAND Flash access mode with the configuration flag CONFIG_SYS_NAND_MXC_NFC_TWO_CYCLES.
[snip]
Why don't you simply add a factor of two to the CCM NFC divider in lowlevel_init.S?
To be more specific, I also have hardware based on the i.MX25 that does not use the NAND Flash from the reference design. It works fine with the symmetric mode as long as the NFC prescaler is set up appropriately in the MMC. I don't think that it is possible that a NAND Flash device does not support symmetric mode. So there should not be any need for a CONFIG_SYS_NAND_MXC_NFC_TWO_CYCLES config option.
All you have to do is to set the appropriate value in PER8 DIV in PCDR2 (address 0x53f80020). This can easily be added as a single line to the init_clocks macro in board/karo/tx25/lowlevel_init.S. Since the TX25 board does not set this register, it is left at its reset value, which is 0x01010101, so the line to add would be (dividing the NFC clock twice more): write32 0x53f80020, 0x01010103
This patch is interfering with a patch series that I'd like to post today or tomorrow, so please make a quick decision about this, so that I can know if I should take this patch into account for my series or if I should ignore it.
Best regards, Benoît

Dear Daniel, Scott,
On Thu, Aug 2, 2012 at 03:55:51 PM, Benoît Thébaudeau wrote:
On Thu, Aug 2, 2012 at 01:28:08 PM, Benoît Thébaudeau wrote:
On Thu, Aug 2, 2012 at 01:17:07 PM, Daniel Gachet wrote:
The mxc_nand driver uses the symmetric mode to access the NAND Flash, but the devices populated on the KARO TX25 only support ann asymmetic mode (MX25: bit 8 within NAND_FLAHS_CONFIG1 register cleared).
This patch enables to selected the NAND Flash access mode with the configuration flag CONFIG_SYS_NAND_MXC_NFC_TWO_CYCLES.
[snip]
Why don't you simply add a factor of two to the CCM NFC divider in lowlevel_init.S?
To be more specific, I also have hardware based on the i.MX25 that does not use the NAND Flash from the reference design. It works fine with the symmetric mode as long as the NFC prescaler is set up appropriately in the MMC. I don't think that it is possible that a NAND Flash device does not support symmetric mode. So there should not be any need for a CONFIG_SYS_NAND_MXC_NFC_TWO_CYCLES config option.
All you have to do is to set the appropriate value in PER8 DIV in PCDR2 (address 0x53f80020). This can easily be added as a single line to the init_clocks macro in board/karo/tx25/lowlevel_init.S. Since the TX25 board does not set this register, it is left at its reset value, which is 0x01010101, so the line to add would be (dividing the NFC clock twice more): write32 0x53f80020, 0x01010103
This patch is interfering with a patch series that I'd like to post today or tomorrow, so please make a quick decision about this, so that I can know if I should take this patch into account for my series or if I should ignore it.
Did you have a chance to test my suggestion on Karo TX25? Do you want me to send a patch for it?
Except if adding this config option to the driver adds a real benefit compared to my suggestion, it is probably better to tune the board files first.
Best regards, Benoît

The NAND Flash of the KARO TX25 board is a Samsung K9F1G08U0B with 25-ns R/W cycle times. However, the NFC clock for this board was set to 66.5 MHz, so using the NFC driver in symmetric mode (i.e. 1 NFC clock cycle = 1 NF R/W cycle) resulted in NF R/W cycle times of 15 ns, hence corrupted NF accesses.
This patch fixes this issue by setting the NFC clock to the highest frequency complying to the 25-ns NF R/W cycle times specification, i.e. 33.25 MHz.
Signed-off-by: Benoît Thébaudeau benoit.thebaudeau@advansee.com Cc: John Rigby jcrigby@gmail.com Cc: Scott Wood scottwood@freescale.com Cc: Stefano Babic sbabic@denx.de Cc: Daniel Gachet Daniel.Gachet@hefr.ch --- This patch is a replacement solution that I suggest instead of http://patchwork.ozlabs.org/patch/174735/ since there is no need for a CONFIG_SYS_NAND_MXC_NFC_TWO_CYCLES config option in the NFC driver.
It still has to be tested by someone having this board, but I'm very confident that it works since I have another PCB design based on the i.MX25 with a NAND Flash with the same timings that works fine using these clock settings.
.../board/karo/tx25/lowlevel_init.S | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git u-boot-2012.07.orig/board/karo/tx25/lowlevel_init.S u-boot-2012.07/board/karo/tx25/lowlevel_init.S index 823df10..eb3f187 100644 --- u-boot-2012.07.orig/board/karo/tx25/lowlevel_init.S +++ u-boot-2012.07/board/karo/tx25/lowlevel_init.S @@ -67,6 +67,14 @@ write32 0x53f80008, 0x20034000
/* + * PCDR2: NFC = 33.25 MHz + * This is required for the NAND Flash of this board, which is a Samsung + * K9F1G08U0B with 25-ns R/W cycle times, in order to make it work with + * the NFC driver in symmetric (i.e. one-cycle) mode. + */ + write32 0x53f80020, 0x01010103 + + /* * enable all implemented clocks in all three * clock control registers */

On 08/08/2012 15:55, Benoît Thébaudeau wrote:
The NAND Flash of the KARO TX25 board is a Samsung K9F1G08U0B with 25-ns R/W cycle times. However, the NFC clock for this board was set to 66.5 MHz, so using the NFC driver in symmetric mode (i.e. 1 NFC clock cycle = 1 NF R/W cycle) resulted in NF R/W cycle times of 15 ns, hence corrupted NF accesses.
This patch fixes this issue by setting the NFC clock to the highest frequency complying to the 25-ns NF R/W cycle times specification, i.e. 33.25 MHz.
Signed-off-by: Benoît Thébaudeau benoit.thebaudeau@advansee.com Cc: John Rigby jcrigby@gmail.com Cc: Scott Wood scottwood@freescale.com Cc: Stefano Babic sbabic@denx.de Cc: Daniel Gachet Daniel.Gachet@hefr.ch
This patch is a replacement solution that I suggest instead of http://patchwork.ozlabs.org/patch/174735/ since there is no need for a CONFIG_SYS_NAND_MXC_NFC_TWO_CYCLES config option in the NFC driver.
It still has to be tested by someone having this board, but I'm very confident that it works since I have another PCB design based on the i.MX25 with a NAND Flash with the same timings that works fine using these clock settings.
.../board/karo/tx25/lowlevel_init.S | 8 ++++++++ 1 file changed, 8 insertions(+)
diff --git u-boot-2012.07.orig/board/karo/tx25/lowlevel_init.S u-boot-2012.07/board/karo/tx25/lowlevel_init.S index 823df10..eb3f187 100644 --- u-boot-2012.07.orig/board/karo/tx25/lowlevel_init.S +++ u-boot-2012.07/board/karo/tx25/lowlevel_init.S @@ -67,6 +67,14 @@ write32 0x53f80008, 0x20034000
/*
* PCDR2: NFC = 33.25 MHz
* This is required for the NAND Flash of this board, which is a Samsung
* K9F1G08U0B with 25-ns R/W cycle times, in order to make it work with
* the NFC driver in symmetric (i.e. one-cycle) mode.
*/
- write32 0x53f80020, 0x01010103
- /*
This is a very local change, only for the Karo-TX25. I see no problem with it.
Acked-by: Stefano Babic sbabic@denx.de
Best regards, Stefano Babic

On 08/08/2012 15:55, Benoît Thébaudeau wrote:
The NAND Flash of the KARO TX25 board is a Samsung K9F1G08U0B with 25-ns R/W cycle times. However, the NFC clock for this board was set to 66.5 MHz, so using the NFC driver in symmetric mode (i.e. 1 NFC clock cycle = 1 NF R/W cycle) resulted in NF R/W cycle times of 15 ns, hence corrupted NF accesses.
This patch fixes this issue by setting the NFC clock to the highest frequency complying to the 25-ns NF R/W cycle times specification, i.e. 33.25 MHz.
Applied to u-boot-imx(fix), thanks.
Best regards, Stefano Babic
participants (3)
-
Benoît Thébaudeau
-
Daniel Gachet
-
Stefano Babic