
Alternative solution for supporting 16 bit NAND detection for the i.MX27 and i.MX31 SoCs. This moves the SoC specific code to the SoC header file leaving mxc_nand.c free from #ifdef's (in this respect).
Question: Is this approach acceptable/preferred over having #ifdef's for different SoCs in mxc_nand.c? --- drivers/mtd/nand/mxc_nand.c | 12 ++---------- include/asm-arm/arch-mx27/imx-regs.h | 13 +++++++++++++ include/asm-arm/arch-mx31/mx31-regs.h | 13 +++++++++++++ 3 files changed, 28 insertions(+), 10 deletions(-)
diff --git a/drivers/mtd/nand/mxc_nand.c b/drivers/mtd/nand/mxc_nand.c index 3e4254a..45d0024 100644 --- a/drivers/mtd/nand/mxc_nand.c +++ b/drivers/mtd/nand/mxc_nand.c @@ -808,8 +808,6 @@ static void mxc_nand_command(struct mtd_info *mtd, unsigned command,
int board_nand_init(struct nand_chip *this) { - struct system_control_regs *sc_regs = - (struct system_control_regs *)IMX_SYSTEM_CTL_BASE; struct mtd_info *mtd; uint16_t tmp; int err = 0; @@ -871,15 +869,9 @@ int board_nand_init(struct nand_chip *this) writew(0x4, &host->regs->nfc_wrprot);
/* NAND bus width determines access funtions used by upper layer */ -#ifdef CONFIG_MX27 - if (readl(&sc_regs->fmcr) & NF_16BIT_SEL) - this->options |= NAND_BUSWIDTH_16; -#elif defined(CONFIG_MX31) - if (readl(&sc_regs->rcsr) & CCM_RCSR_NF16B) + if (mxc_nand_is_16bit()) this->options |= NAND_BUSWIDTH_16; -#else -#warning "No autodetection of 8/16 bit NAND" -#endif + host->pagesize_2k = 0;
return err; diff --git a/include/asm-arm/arch-mx27/imx-regs.h b/include/asm-arm/arch-mx27/imx-regs.h index d36a6da..b88fe51 100644 --- a/include/asm-arm/arch-mx27/imx-regs.h +++ b/include/asm-arm/arch-mx27/imx-regs.h @@ -516,4 +516,17 @@ struct iim_regs { #define IIM0_SCC_KEY 11 #define IIM1_SUID 1
+#ifndef __ASSEMBLY__ +static inline int mxc_nand_is_16bit(void) +{ + struct system_control_regs *sc_regs = + (struct system_control_regs *)IMX_SYSTEM_CTL_BASE; + + if (readl(&sc_regs->rcsr) & CCM_RCSR_NF16B) + return 1; + else + return 0; +} +#endif + #endif /* _IMX_REGS_H */ diff --git a/include/asm-arm/arch-mx31/mx31-regs.h b/include/asm-arm/arch-mx31/mx31-regs.h index 86c9975..613c632 100644 --- a/include/asm-arm/arch-mx31/mx31-regs.h +++ b/include/asm-arm/arch-mx31/mx31-regs.h @@ -63,6 +63,19 @@ struct system_control_regs { #define CCM_RCSR_NF16B (1 << 31) #define CCM_RCSR_NFMS (1 << 30)
+#include <asm/io.h> + +static inline int mxc_nand_is_16bit(void) +{ + struct system_control_regs *sc_regs = + (struct system_control_regs *)IMX_SYSTEM_CTL_BASE; + + if (readl(&sc_regs->rcsr) & CCM_RCSR_NF16B) + return 1; + else + return 0; +} + #endif
#define __REG(x) (*((volatile u32 *)(x)))