mtd: stm_nand_bch: Add new BCH NAND Flash driver
Subsystems (3)
PATCH 1/1 mtd: stm_nand_bch: Add new BCH NAND Flash driver
---
Hi MTD Gang,
I'd like to start an open discussion surrounding one of the NAND drivers utilised within the ST BSP. As with most internal kernels drivers some workarounds have been employed, which are unlikely to be welcomed in the Mainline kernel. I'd be very appreciative if some subject-matter experts could go through the current implementation with me to identify some of the difficulties and together I hope we can discover some solutions which I can subseqently implement.
Any help would be gratefully received.
Kind regards,
Lee
--- drivers/mtd/nand/Kconfig | 12 + drivers/mtd/nand/Makefile | 2 + drivers/mtd/nand/nand_base.c | 30 +- drivers/mtd/nand/nand_bbt.c | 26 + drivers/mtd/nand/nand_ecc.c | 5 + drivers/mtd/nand/nand_ids.c | 646 ++++++++ drivers/mtd/nand/stm_nand_bch.c | 3113 ++++++++++++++++++++++++++++++++++++++ drivers/mtd/nand/stm_nand_dt.c | 165 ++ drivers/mtd/nand/stm_nand_dt.h | 27 + drivers/mtd/nand/stm_nand_regs.h | 379 +++++ include/linux/mtd/bbm.h | 13 + include/linux/mtd/nand.h | 75 + include/linux/mtd/stm_nand.h | 176 +++ 13 files changed, 4657 insertions(+), 12 deletions(-) create mode 100644 drivers/mtd/nand/stm_nand_bch.c create mode 100644 drivers/mtd/nand/stm_nand_dt.c create mode 100644 drivers/mtd/nand/stm_nand_dt.h create mode 100644 drivers/mtd/nand/stm_nand_regs.h create mode 100644 include/linux/mtd/stm_nand.h
drivers/mtd/nand/Kconfig +12 -0
@@ -510,4 +510,16 @@ config MTD_NAND_XWAY Enables support for NAND Flash chips on Lantiq XWAY SoCs. NAND is attached to the External Bus Unit (EBU). +config MTD_NAND_STM_BCH + tristate "STMicroelectronics: NANDi BCH Controller" + help + Adds support for the STMicroelectronics NANDi BCH Controller. + +config STM_NAND_BCH_DEBUG + bool "NANDi BCH debug messages" + depends on MTD_NAND_STM_BCH + default n + help + Display debug messages on the console + endif # MTD_NAND
drivers/mtd/nand/Makefile +2 -0
@@ -46,6 +46,8 @@ obj-$(CONFIG_MTD_NAND_NUC900) += nuc900_nand.o obj-$(CONFIG_MTD_NAND_MPC5121_NFC) += mpc5121_nfc.o obj-$(CONFIG_MTD_NAND_RICOH) += r852.o obj-$(CONFIG_MTD_NAND_JZ4740) += jz4740_nand.o +obj-$(CONFIG_OF) += stm_nand_dt.o +obj-$(CONFIG_MTD_NAND_STM_BCH) += stm_nand_bch.o obj-$(CONFIG_MTD_NAND_GPMI_NAND) += gpmi-nand/ obj-$(CONFIG_MTD_NAND_XWAY) += xway_nand.o obj-$(CONFIG_MTD_NAND_BCM47XXNFLASH) += bcm47xxnflash/
drivers/mtd/nand/nand_base.c +18 -12
@@ -90,9 +90,9 @@ static struct nand_ecclayout nand_oob_128 = { .length = 78} } }; -static int nand_get_device (struct mtd_info *mtd,int new_state); +int nand_get_device (struct mtd_info *mtd,int new_state); -static int nand_do_write_oob (struct mtd_info *mtd,loff_t to, +int nand_do_write_oob (struct mtd_info *mtd,loff_t to,struct mtd_oob_ops *ops);/*
@@ -128,7 +128,7 @@ static int check_offs_len(struct mtd_info *mtd,* * Release chip lock and wake up anyone waiting on the device. */ -static void nand_release_device (struct mtd_info *mtd) +void nand_release_device (struct mtd_info *mtd) {struct nand_chip *chip = mtd->priv;
@@ -139,6 +139,7 @@ static void nand_release_device(struct mtd_info *mtd)wake_up (&chip->controller->wq);spin_unlock (&chip->controller->lock); } +EXPORT_SYMBOL_GPL (nand_release_device);/** * nand_read_byte - [DEFAULT] read one byte from the chip
@@ -423,7 +424,7 @@ static int nand_block_markbad_lowlevel(struct mtd_info *mtd, loff_t ofs)* Check, if the device is write protected. The function expects, that the * device is already selected. */ -static int nand_check_wp (struct mtd_info *mtd) +int nand_check_wp (struct mtd_info *mtd) {struct nand_chip *chip = mtd->priv;
@@ -435,6 +436,7 @@ static int nand_check_wp(struct mtd_info *mtd) chip->cmdfunc (mtd,NAND_CMD_STATUS ,-1 ,-1 );return (chip->read_byte (mtd) &NAND_STATUS_WP ) ?0 :1 ; } +EXPORT_SYMBOL_GPL (nand_check_wp);/** * nand_block_checkbad - [GENERIC] Check if a block is marked bad
@@ -736,8 +738,7 @@ static void panic_nand_get_device(struct nand_chip *chip,* * Get the device and lock it for exclusive access */ -static int -nand_get_device (struct mtd_info *mtd,int new_state) +int nand_get_device (struct mtd_info *mtd,int new_state) {struct nand_chip *chip = mtd->priv;spinlock_t *lock = &chip->controller->lock;
@@ -769,6 +770,7 @@ retry:remove_wait_queue (wq, &wait); goto retry; } +EXPORT_SYMBOL_GPL (nand_get_device);/** * panic_nand_wait - [GENERIC] wait until the command is done
@@ -1366,7 +1368,7 @@ static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip,* @ops: oob ops structure * @len: size of oob to transfer */ -static uint8_t *nand_transfer_oob (struct nand_chip *chip,uint8_t *oob, +uint8_t *nand_transfer_oob (struct nand_chip *chip,uint8_t *oob,struct mtd_oob_ops *ops,size_t len) {switch (ops->mode) {
@@ -1406,6 +1408,7 @@ static uint8_t *nand_transfer_oob(struct nand_chip *chip, uint8_t *oob, }return NULL ; } +EXPORT_SYMBOL_GPL (nand_transfer_oob);/** * nand_do_read_ops - [INTERN] Read data with ECC
@@ -2158,7 +2161,7 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,* @len: oob data write length * @ops: oob ops structure */ -static uint8_t *nand_fill_oob (struct mtd_info *mtd,uint8_t *oob,size_t len, +uint8_t *nand_fill_oob (struct mtd_info *mtd,uint8_t *oob,size_t len,struct mtd_oob_ops *ops) {struct nand_chip *chip = mtd->priv;
@@ -2206,6 +2209,7 @@ static uint8_t *nand_fill_oob(struct mtd_info *mtd, uint8_t *oob, size_t len, }return NULL ; } +EXPORT_SYMBOL_GPL (nand_fill_oob);#define NOTALIGNED (x) ((x & (chip->subpagesize - 1)) != 0)
@@ -2395,7 +2399,7 @@ static int nand_write(struct mtd_info *mtd, loff_t to, size_t len,* * NAND write out-of-band. */ -static int nand_do_write_oob (struct mtd_info *mtd,loff_t to, +int nand_do_write_oob (struct mtd_info *mtd,loff_t to,struct mtd_oob_ops *ops) {int chipnr, page, status, len;
@@ -2472,6 +2476,7 @@ static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,return 0 ; } +EXPORT_SYMBOL_GPL (nand_do_write_oob);/** * nand_write_oob - [MTD Interface] NAND write data and/or out-of-band
@@ -2665,7 +2670,7 @@ erase_exit:* * Sync is actually a wait for chip ready function. */ -static void nand_sync (struct mtd_info *mtd) +void nand_sync (struct mtd_info *mtd) {pr_debug ("%s: called\n" , __func__);
@@ -2674,6 +2679,7 @@ static void nand_sync(struct mtd_info *mtd)/* Release it and go back */ nand_release_device (mtd); } +EXPORT_SYMBOL_GPL (nand_sync);/** * nand_block_isbad - [MTD Interface] Check if block at offset is bad
@@ -2757,7 +2763,7 @@ static int nand_onfi_get_features(struct mtd_info *mtd, struct nand_chip *chip,* nand_suspend - [MTD Interface] Suspend the NAND flash * @mtd: MTD device structure */ -static int nand_suspend (struct mtd_info *mtd) +int nand_suspend (struct mtd_info *mtd) {return nand_get_device (mtd,FL_PM_SUSPENDED ); }
@@ -2766,7 +2772,7 @@ static int nand_suspend(struct mtd_info *mtd)* nand_resume - [MTD Interface] Resume the NAND flash * @mtd: MTD device structure */ -static void nand_resume (struct mtd_info *mtd) +void nand_resume (struct mtd_info *mtd) {struct nand_chip *chip = mtd->priv;
drivers/mtd/nand/nand_bbt.c +26 -0
@@ -1246,6 +1246,28 @@ static struct nand_bbt_descr bbt_mirror_no_oob_descr = { .pattern = mirror_pattern }; + +/* BBT descriptors for (Micron) 4-bit on-die ECC */ +static struct nand_bbt_descr bbt_main_descr_ode = { + .options =NAND_BBT_LASTBLOCK |NAND_BBT_CREATE |NAND_BBT_WRITE + |NAND_BBT_2BIT |NAND_BBT_VERSION |NAND_BBT_PERCHIP , + .offs =8 +8 ,/* need to shift by 8 due to on-die ECC */ + .len =4 , + .veroffs =12 +8 ,/* need to shift by 8 due to on-die ECC */ + .maxblocks =4 , + .pattern = bbt_pattern +}; + +static struct nand_bbt_descr bbt_mirror_descr_ode = { + .options =NAND_BBT_LASTBLOCK |NAND_BBT_CREATE |NAND_BBT_WRITE + |NAND_BBT_2BIT |NAND_BBT_VERSION |NAND_BBT_PERCHIP , + .offs =8 +8 ,/* need to shift by 8 due to on-die ECC */ + .len =4 , + .veroffs =12 +8 ,/* need to shift by 8 due to on-die ECC */ + .maxblocks =4 , + .pattern = mirror_pattern +}; +#define BADBLOCK_SCAN_MASK (~NAND_BBT_NO_OOB)/** * nand_create_badblock_pattern - [INTERN] Creates a BBT descriptor structure
@@ -1293,6 +1315,9 @@ int nand_default_bbt(struct mtd_info *mtd)if (this->bbt_options &NAND_BBT_NO_OOB ) { this->bbt_td = &bbt_main_no_oob_descr; this->bbt_md = &bbt_mirror_no_oob_descr; + }else if (this->ecc.mode ==NAND_ECC_4BITONDIE ) { + this->bbt_td = &bbt_main_descr_ode; + this->bbt_md = &bbt_mirror_descr_ode; }else { this->bbt_td = &bbt_main_descr; this->bbt_md = &bbt_mirror_descr;
@@ -1337,6 +1362,7 @@ int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt) }return 1 ; } +EXPORT_SYMBOL_GPL (nand_isbad_bbt);/** * nand_markbad_bbt - [NAND Interface] Mark a block bad in the BBT
drivers/mtd/nand/nand_ecc.c +5 -0
@@ -506,6 +506,11 @@ int __nand_correct_data(unsigned char *buf,if ((bitsperbyte[b0] + bitsperbyte[b1] + bitsperbyte[b2]) ==1 )return 1 ;/* error in ECC data; no action needed */ +if ((bitsperbyte[b0] + bitsperbyte[b1] + bitsperbyte[b2]) ==1 ) { + pr_debug"%s: ignoring error in ECC, data ok", __func__); +return 1 ;/* error in ecc data; no action needed */ + } +pr_err ("%s: uncorrectable ECC error" , __func__);return -1 ; }
drivers/mtd/nand/nand_ids.c +646 -0
652 lines not on this page · raw message
drivers/mtd/nand/stm_nand_bch.c new file +3113 -0
2,136 lines not on this page · raw message
drivers/mtd/nand/stm_nand_dt.c new file +165 -0
165 lines not on this page · raw message
drivers/mtd/nand/stm_nand_dt.h new file +27 -0
Lines of this file are not shown. View the raw message.
drivers/mtd/nand/stm_nand_regs.h new file +379 -0
379 lines not on this page · raw message
include/linux/mtd/nand.h +75 -0
75 lines not on this page · raw message
include/linux/mtd/stm_nand.h new file +176 -0
176 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
1.8.3.2
Part of the diff is not shown here. View the raw message.