From d2eee4b7f000365b9d74a9229fb4622c90d867ad Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 28 Nov 2013 12:21:33 -0600 Subject: [PATCH] SAMA5 NAND: Still debugging --- arch/arm/src/sama5/sam_gf1024.c | 4 ++-- arch/arm/src/sama5/sam_gf512.c | 4 ++-- arch/arm/src/sama5/sam_nand.c | 14 ++++++++------ arch/arm/src/sama5/sam_nand.h | 4 +++- arch/arm/src/sama5/sam_pmecc.c | 8 ++++++++ 5 files changed, 23 insertions(+), 11 deletions(-) diff --git a/arch/arm/src/sama5/sam_gf1024.c b/arch/arm/src/sama5/sam_gf1024.c index cc3d3c2d70..f904870f0b 100644 --- a/arch/arm/src/sama5/sam_gf1024.c +++ b/arch/arm/src/sama5/sam_gf1024.c @@ -48,7 +48,7 @@ #include "sam_pmecc.h" -#ifndef CONFIG_SAMA5_PMECC_GALOIS_ROMTABLES +#if defined(CONFIG_SAMA5_HAVE_PMECC) && !defined(CONFIG_SAMA5_PMECC_GALOIS_ROMTABLES) /********************************************************************************************************************************** * Public Data @@ -2116,4 +2116,4 @@ const uint16_t pmecc_gf_1024[2][PMECC_GF_SIZEOF_1024] = } }; -#endif /* CONFIG_SAMA5_PMECC_GALOIS_ROMTABLES */ +#endif /* CONFIG_SAMA5_HAVE_PMECC && !CONFIG_SAMA5_PMECC_GALOIS_ROMTABLES */ diff --git a/arch/arm/src/sama5/sam_gf512.c b/arch/arm/src/sama5/sam_gf512.c index becda081fc..b279f28020 100644 --- a/arch/arm/src/sama5/sam_gf512.c +++ b/arch/arm/src/sama5/sam_gf512.c @@ -48,7 +48,7 @@ #include "sam_pmecc.h" -#ifndef CONFIG_SAMA5_PMECC_GALOIS_ROMTABLES +#if defined(CONFIG_SAMA5_HAVE_PMECC) && !defined(CONFIG_SAMA5_PMECC_GALOIS_ROMTABLES) /********************************************************************************************************************************** * Public Data @@ -1092,4 +1092,4 @@ const uint16_t pmecc_gf512[2][PMECC_GF_SIZEOF_512] = } }; -#endif /* CONFIG_SAMA5_PMECC_GALOIS_ROMTABLES */ +#endif /* CONFIG_SAMA5_HAVE_PMECC && !CONFIG_SAMA5_PMECC_GALOIS_ROMTABLES */ diff --git a/arch/arm/src/sama5/sam_nand.c b/arch/arm/src/sama5/sam_nand.c index 0bae7291a2..42f3741283 100644 --- a/arch/arm/src/sama5/sam_nand.c +++ b/arch/arm/src/sama5/sam_nand.c @@ -1420,7 +1420,7 @@ static int nand_read_pmecc(struct sam_nandcs_s *priv, off_t block, regval = nand_getreg(SAM_HSMC_PMECCTRL); regval |= HSMC_PMECCTRL_DATA; - nand_putreg(SAM_HSMC_PMECCFG, regval); + nand_putreg(SAM_HSMC_PMECCTRL, regval); regval = nand_getreg(SAM_HSMC_PMECCEADDR); ret = nand_read(priv, true, (uint8_t *)data, pagesize + (regval + 1)); @@ -2612,7 +2612,9 @@ struct mtd_dev_s *sam_nand_initialize(int cs) { /* Initialize the global nand state structure */ +#if NAND_NBANKS > 1 sem_init(&g_nand.exclsem, 0, 1); +#endif sem_init(&g_nand.waitsem, 0, 0); /* Enable the NAND FLASH Controller (The NFC is always used) */ @@ -2627,9 +2629,9 @@ struct mtd_dev_s *sam_nand_initialize(int cs) #else /* Disable the PMECC if it is not being used */ - nand_putreg(SAM_SMC_PMECCTRL, HSMC_PMECCTRL_RST); - nand_putreg(SAM_SMC_PMECCTRL, HSMC_PMECCTRL_DISABLE); - nand_putreg(SAM_SMC_PMECCFG, 0); + nand_putreg(SAM_HSMC_PMECCTRL, HSMC_PMECCTRL_RST); + nand_putreg(SAM_HSMC_PMECCTRL, HSMC_PMECCTRL_DISABLE); + nand_putreg(SAM_HSMC_PMECCFG, 0); #endif /* Attach the CAN interrupt handler */ @@ -2743,8 +2745,8 @@ bool nand_checkreg(bool wr, uintptr_t regaddr, uint32_t regval) /* Save information about the new access */ - g_nand.wr = wr; - g_nand.regval = regval; + g_nand.wr = wr; + g_nand.regval = regval; g_nand.regadddr = regaddr; g_nand.ntimes = 0; } diff --git a/arch/arm/src/sama5/sam_nand.h b/arch/arm/src/sama5/sam_nand.h index a22adad85c..2f6fa73134 100644 --- a/arch/arm/src/sama5/sam_nand.h +++ b/arch/arm/src/sama5/sam_nand.h @@ -268,11 +268,13 @@ struct sam_nandcs_s struct sam_nand_s { bool initialized; /* True: One time initialization is complete */ +#if NAND_NBANKS > 1 sem_t exclsem; /* Enforce exclusive access to the SMC hardware */ +#endif /* Dynamic state */ - volatile bool cmddone; /* True: NFC commnad has completed */ + volatile bool cmddone; /* True: NFC command has completed */ volatile bool xfrdone; /* True: Transfer has completed */ volatile bool rbedge; /* True: Ready/busy edge detected */ sem_t waitsem; /* Used to wait for one of the above states */ diff --git a/arch/arm/src/sama5/sam_pmecc.c b/arch/arm/src/sama5/sam_pmecc.c index b5a5f35b36..ed2a2c9329 100644 --- a/arch/arm/src/sama5/sam_pmecc.c +++ b/arch/arm/src/sama5/sam_pmecc.c @@ -60,6 +60,12 @@ #include "sam_pmecc.h" #include "sam_nand.h" +/* Compile this logic only if there is at least one CS configure for NAND + * and with PMECC support enabled. + */ + +#ifdef CONFIG_SAMA5_HAVE_PMECC + /**************************************************************************** * Pre-processor Definitions ****************************************************************************/ @@ -1411,3 +1417,5 @@ void pmecc_buildgf(uint32_t mm, int16_t* indexof, int16_t* alphato) indexof[0] = -1; } #endif /* CONFIG_SAMA5_PMECC_GALOIS_CUSTOM */ + +#endif /* CONFIG_SAMA5_HAVE_PMECC */