Initial support of driver brcmnand (from kernel 4.18)
Subsystems (6)
cover Initial support of driver brcmnand (from kernel 4.18)
This serie is a port the support of driver brcmnand from kernel 4.18 to u-boot. I've tried to stay as close as possible to the kernel. In this first port, I haven't ported the support of DMA, it's not mandatory in the first step and it could be added later.
This code has been tested on bcm6838 (mips), bcm63158 (arm) and bcm6858 (arm64).
In the code, I've used "#ifndef __UBOOT__" to show the difference between the kernel code.
I've also added a file brcmnand_compat.[hc] to compat function with the kernel (for example devm_clk_get).
Changes in v1:
- define less function in brcmnand_compat.c/h and add more #ifndef __UBOOT__
- port completion.h (function stubbed) from kernel 4.18
- define devm_ioremap for everybody
- remove duplicate SoB
- update text commit
- add support of bcm63158
Boris Brezillon (1):
mtd: nand: provide several helpers to do common NAND operations
Brian Norris (1):
mtd: add get/set of_node/flash_node helpers
Marc Gonzalez (1):
mtd: nand: import nand_hw_control_init()
Philippe Reynes (15):
arm: asm: io.h: define readX_relaxed and writeX_relaxed
include: linux: io: define devm_ioremap on board with ioremap compat linux: import completion from linux 4.18
drivers: nand: brcmnand: add initial support
drivers: nand: brcmnand: add parameter parameter-page-big-endian
drivers: nand: brcmnand: add an option to read the write-protect from
device tree
dt: bcm6838: add nand controller
dt: bcm968380gerg: enable nand controller
bcm968380gerg: add nand support
dt: bcm6858: add nand controller
dt: bcm968580xref: enable nand controller
bcm968580xref: add nand support
dt: bcm63158: add nand controller
dt: bcm963158: enable nand controller
bcm963158: add nand support
arch/arm/dts/bcm63158.dtsi | 13 + arch/arm/dts/bcm6858.dtsi | 13 + arch/arm/dts/bcm963158.dts | 15 + arch/arm/dts/bcm968580xref.dts | 15 + arch/arm/include/asm/io.h | 21 + arch/mips/dts/brcm,bcm6838.dtsi | 13 + arch/mips/dts/brcm,bcm968380gerg.dts | 12 + configs/bcm963158_ram_defconfig | 6 + configs/bcm968380gerg_ram_defconfig | 7 + configs/bcm968580xref_ram_defconfig | 7 + drivers/mtd/nand/raw/Kconfig | 25 + drivers/mtd/nand/raw/Makefile | 1 + drivers/mtd/nand/raw/brcmnand/Makefile | 7 + drivers/mtd/nand/raw/brcmnand/bcm63158_nand.c | 123 + drivers/mtd/nand/raw/brcmnand/bcm6838_nand.c | 122 + drivers/mtd/nand/raw/brcmnand/bcm6858_nand.c | 123 + drivers/mtd/nand/raw/brcmnand/brcmnand.c | 2805 +++++++++++++++++++++++ drivers/mtd/nand/raw/brcmnand/brcmnand.h | 63 + drivers/mtd/nand/raw/brcmnand/brcmnand_compat.c | 66 + drivers/mtd/nand/raw/brcmnand/brcmnand_compat.h | 15 + drivers/mtd/nand/raw/nand_base.c | 1013 ++++++-- include/configs/broadcom_bcm963158.h | 7 + include/configs/broadcom_bcm968380gerg.h | 7 + include/configs/broadcom_bcm968580xref.h | 7 + include/linux/completion.h | 173 ++ include/linux/io.h | 2 +- include/linux/mtd/rawnand.h | 49 + 27 files changed, 4569 insertions(+), 161 deletions(-) create mode 100644 drivers/mtd/nand/raw/brcmnand/Makefile create mode 100644 drivers/mtd/nand/raw/brcmnand/bcm63158_nand.c create mode 100644 drivers/mtd/nand/raw/brcmnand/bcm6838_nand.c create mode 100644 drivers/mtd/nand/raw/brcmnand/bcm6858_nand.c create mode 100644 drivers/mtd/nand/raw/brcmnand/brcmnand.c create mode 100644 drivers/mtd/nand/raw/brcmnand/brcmnand.h create mode 100644 drivers/mtd/nand/raw/brcmnand/brcmnand_compat.c create mode 100644 drivers/mtd/nand/raw/brcmnand/brcmnand_compat.h create mode 100644 include/linux/completion.h
Signature · 1 line
2.7.4
PATCH 1/18 mtd: add get/set of_node/flash_node helpers
From: Brian Norris <[email protected]>
Linux commit 28b8b26b308 ("mtd: add get/set of_node/flash_node helpers")
We are going to begin using the mtd->dev.of_node field for MTD device nodes, so let's add helpers for it. Also, we'll be making some conversions on spi_nor (and nand_chip eventually) too, so get that ready with their own helpers.
[Philippe Reynes: only add function nand_set_flash_node and nand_get_flash_node because others were already backported]
--- include/linux/mtd/rawnand.h | 12 ++++++++++++ 1 file changed, 12 insertions(+)
include/linux/mtd/rawnand.h +12 -0
@@ -15,6 +15,7 @@#include <config.h> +#include <dm/device.h> #include <linux/compat.h> #include <linux/mtd/mtd.h> #include <linux/mtd/flashchip.h>
@@ -961,6 +962,17 @@ struct nand_chip {void *priv; }; +static inline void nand_set_flash_node (struct nand_chip *chip, +ofnode node) +{ + chip->flash_node =ofnode_to_offset (node); +} + +static inline ofnode nand_get_flash_node (struct nand_chip *chip) +{ +return offset_to_ofnode (chip->flash_node); +} +static inline struct nand_chip *mtd_to_nand (struct mtd_info *mtd) { return container_of(mtd, struct nand_chip, mtd);
Signature · 1 line
2.7.4
PATCH 1/18 mtd: add get/set of_node/flash_node helpers
Quoted 9 lines · Philippe Reynes
From: Brian Norris <[email protected]>
Linux commit
28b8b26b308("mtd: add get/set of_node/flash_node helpers")We are going to begin using the
mtd->dev.of_nodefield for MTD device nodes, so let's add helpers for it. Also, we'll be making some conversions onspi_nor(andnand_chipeventually) too, so get that ready with their own helpers.
Quoted 6 lines
Signed-off-by Brian Norris <[email protected]>Reviewed-by Boris Brezillon <[email protected]>[Philippe Reynes: only add function
nand_set_flash_nodeandnand_get_flash_nodebecause others were already backported]Signed-off-by Philippe Reynes <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190424/186d89e7/attachment.sig>
PATCH 2/18 mtd: nand: import nand_hw_control_init()
In reply to Philippe ReynesFrom: Marc Gonzalez <[email protected]>
Linux commit d45bc58dd3b ("mtd: nand: import nand_hw_control_init()")
The code to initialize a struct nand_hw_control is duplicated across several drivers. Factorize it using an inline function.
--- include/linux/mtd/rawnand.h | 7 +++++++ 1 file changed, 7 insertions(+)
include/linux/mtd/rawnand.h +7 -0
@@ -499,6 +499,13 @@ struct nand_hw_control {struct nand_chip *active; }; +static inline void nand_hw_control_init (struct nand_hw_control *nfc) +{ + nfc->active =NULL ; +spin_lock_init (&nfc->lock); +init_waitqueue_head (&nfc->wq); +} +/** * struct nand_ecc_step_info - ECC step information of ECC engine * @stepsize: data bytes per ECC step
Signature · 1 line
2.7.4
PATCH 2/18 mtd: nand: import nand_hw_control_init()
Quoted 4 lines · Philippe Reynes
From: Marc Gonzalez <[email protected]>
Linux commit
d45bc58dd3b("mtd: nand: importnand_hw_control_init()")
Quoted 8 lines
The code to initialize a struct
nand_hw_controlis duplicated across several drivers. Factorize it using an inline function.Signed-off-by Marc Gonzalez <[email protected]>Signed-off-by Boris Brezillon <[email protected]>[Philippe Reynes: adapt code to u-boot and only keep new function]Signed-off-by Philippe Reynes <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190424/54fd4f96/attachment.sig>
PATCH 3/18 mtd: nand: provide several helpers to do common NAND operations
In reply to Philippe ReynesFrom: Boris Brezillon <[email protected]>
Linux commit 97d90da8a88 ("mtd: nand: provide several helpers to do common NAND operations")
This is part of the process of removing direct calls to ->cmdfunc() outside of the core in order to introduce a better interface to execute NAND operations.
Here we provide several helpers and make use of them to remove all direct calls to ->cmdfunc(). This way, we can easily modify those helpers to make use of the new ->exec_op() interface when available.
--- drivers/mtd/nand/raw/nand_base.c | 1013 ++++++++++++++++++++++++++++++++------ include/linux/mtd/rawnand.h | 30 ++ 2 files changed, 883 insertions(+), 160 deletions(-)
drivers/mtd/nand/raw/nand_base.c +853 -160
@@ -486,14 +486,19 @@ static int nand_block_markbad_lowlevel(struct mtd_info *mtd, loff_t ofs)static int nand_check_wp (struct mtd_info *mtd) {struct nand_chip *chip =mtd_to_nand (mtd); +u8 status; +int ret;/* Broken xD cards report WP despite being writable */ if (chip->options &NAND_BROKEN_XD )return 0 ;/* Check the WP bit */ - chip->cmdfunc (mtd,NAND_CMD_STATUS ,-1 ,-1 ); -return (chip->read_byte (mtd) &NAND_STATUS_WP ) ?0 :1 ; + ret =nand_status_op (chip, &status); +if (ret) +return ret; + +return status &NAND_STATUS_WP ?0 :1 ; }/**
@@ -575,11 +580,18 @@ static void nand_wait_status_ready(struct mtd_info *mtd, unsigned long timeo) { registerstruct nand_chip *chip =mtd_to_nand (mtd);u32 time_start; +int ret; timeo = (CONFIG_SYS_HZ * timeo) /1000 ; time_start =get_timer (0 );while (get_timer (time_start) < timeo) { -if ((chip->read_byte (mtd) &NAND_STATUS_READY )) +u8 status; + + ret =nand_read_data_op (chip, &status,sizeof (status), true); +if (ret) +return ; + +if (status &NAND_STATUS_READY )break ;WATCHDOG_RESET (); }
@@ -851,7 +863,15 @@ static void panic_nand_wait(struct mtd_info *mtd, struct nand_chip *chip,if (chip->dev_ready (mtd))break ; }else { -if (chip->read_byte (mtd) &NAND_STATUS_READY ) +int ret; +u8 status; + + ret =nand_read_data_op (chip, &status,sizeof (status), + true); +if (ret) +return ; + +if (status &NAND_STATUS_READY )break ; }mdelay (1 );
@@ -867,8 +887,9 @@ static void panic_nand_wait(struct mtd_info *mtd, struct nand_chip *chip,*/ static int nand_wait (struct mtd_info *mtd,struct nand_chip *chip) { -int status;unsigned long timeo =400 ; +u8 status; +int ret;led_trigger_event (nand_led_trigger,LED_FULL );
@@ -878,7 +899,9 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)*/ ndelay (100 ); - chip->cmdfunc (mtd,NAND_CMD_STATUS ,-1 ,-1 ); + ret =nand_status_op (chip,NULL ); +if (ret) +return ret;u32 timer = (CONFIG_SYS_HZ * timeo) /1000 ;u32 time_start;
@@ -889,13 +912,21 @@ static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip)if (chip->dev_ready (mtd))break ; }else { -if (chip->read_byte (mtd) &NAND_STATUS_READY ) + ret =nand_read_data_op (chip, &status, +sizeof (status), true); +if (ret) +return ret; + +if (status &NAND_STATUS_READY )break ; } }led_trigger_event (nand_led_trigger,LED_OFF ); - status = (int )chip->read_byte (mtd); + ret =nand_read_data_op (chip, &status,sizeof (status), true); +if (ret) +return ret; +/* This can happen if in case of timeout or buggy dev_ready */ WARN_ON (!(status &NAND_STATUS_READY ));return status;
@@ -1048,6 +1079,516 @@ static void __maybe_unused nand_release_data_interface(struct nand_chip *chip) }/** +* nand_read_page_op - Do a READ PAGE operation +* @chip: The NAND chip +* @page: page to read +* @offset_in_page: offset within the page +* @buf: buffer used to store the data +* @len: length of the buffer +* +* This function issues a READ PAGE operation. +* This function does not select/unselect the CS line. +* +* Returns 0 on success, a negative error code otherwise. +*/ +int nand_read_page_op (struct nand_chip *chip,unsigned int page, +unsigned int offset_in_page,void *buf,unsigned int len) +{ +struct mtd_info *mtd =nand_to_mtd (chip); + +if (len && !buf) +return -EINVAL ; + +if (offset_in_page + len > mtd->writesize + mtd->oobsize) +return -EINVAL ; + + chip->cmdfunc (mtd,NAND_CMD_READ0 , offset_in_page, page); +if (len) + chip->read_buf (mtd, buf, len); + +return 0 ; +} +EXPORT_SYMBOL_GPL (nand_read_page_op); + +/** +* nand_read_param_page_op - Do a READ PARAMETER PAGE operation +* @chip: The NAND chip +* @page: parameter page to read +* @buf: buffer used to store the data +* @len: length of the buffer +* +* This function issues a READ PARAMETER PAGE operation. +* This function does not select/unselect the CS line. +* +* Returns 0 on success, a negative error code otherwise. +*/ +static int nand_read_param_page_op (struct nand_chip *chip,u8 page,void *buf, +unsigned int len) +{ +struct mtd_info *mtd =nand_to_mtd (chip); +unsigned int i; +u8 *p = buf; + +if (len && !buf) +return -EINVAL ; + + chip->cmdfunc (mtd,NAND_CMD_PARAM , page,-1 ); +for (i =0 ; i < len; i++) + p[i] = chip->read_byte (mtd); + +return 0 ; +} + +/** +* nand_change_read_column_op - Do a CHANGE READ COLUMN operation +* @chip: The NAND chip +* @offset_in_page: offset within the page +* @buf: buffer used to store the data +* @len: length of the buffer +* @force_8bit: force 8-bit bus access +* +* This function issues a CHANGE READ COLUMN operation. +* This function does not select/unselect the CS line. +* +* Returns 0 on success, a negative error code otherwise. +*/ +int nand_change_read_column_op (struct nand_chip *chip, +unsigned int offset_in_page,void *buf, +unsigned int len,bool force_8bit) +{ +struct mtd_info *mtd =nand_to_mtd (chip); + +if (len && !buf) +return -EINVAL ; + +if (offset_in_page + len > mtd->writesize + mtd->oobsize) +return -EINVAL ; + + chip->cmdfunc (mtd,NAND_CMD_RNDOUT , offset_in_page,-1 ); +if (len) + chip->read_buf (mtd, buf, len); + +return 0 ; +} +EXPORT_SYMBOL_GPL (nand_change_read_column_op); + +/** +* nand_read_oob_op - Do a READ OOB operation +* @chip: The NAND chip +* @page: page to read +* @offset_in_oob: offset within the OOB area +* @buf: buffer used to store the data +* @len: length of the buffer +* +* This function issues a READ OOB operation. +* This function does not select/unselect the CS line. +* +* Returns 0 on success, a negative error code otherwise. +*/ +int nand_read_oob_op (struct nand_chip *chip,unsigned int page, +unsigned int offset_in_oob,void *buf,unsigned int len) +{ +struct mtd_info *mtd =nand_to_mtd (chip); + +if (len && !buf) +return -EINVAL ; + +if (offset_in_oob + len > mtd->oobsize) +return -EINVAL ; + + chip->cmdfunc (mtd,NAND_CMD_READOOB , offset_in_oob, page); +if (len) + chip->read_buf (mtd, buf, len); + +return 0 ; +} +EXPORT_SYMBOL_GPL (nand_read_oob_op); + +/** +* nand_prog_page_begin_op - starts a PROG PAGE operation +* @chip: The NAND chip +* @page: page to write +* @offset_in_page: offset within the page +* @buf: buffer containing the data to write to the page +* @len: length of the buffer +* +* This function issues the first half of a PROG PAGE operation. +* This function does not select/unselect the CS line. +* +* Returns 0 on success, a negative error code otherwise. +*/ +int nand_prog_page_begin_op (struct nand_chip *chip,unsigned int page, +unsigned int offset_in_page,const void *buf, +unsigned int len) +{ +struct mtd_info *mtd =nand_to_mtd (chip); + +if (len && !buf) +return -EINVAL ; + +if (offset_in_page + len > mtd->writesize + mtd->oobsize) +return -EINVAL ; + + chip->cmdfunc (mtd,NAND_CMD_SEQIN , offset_in_page, page); + +if (buf) + chip->write_buf (mtd, buf, len); + +return 0 ; +} +EXPORT_SYMBOL_GPL (nand_prog_page_begin_op); + +/** +* nand_prog_page_end_op - ends a PROG PAGE operation +* @chip: The NAND chip +* +* This function issues the second half of a PROG PAGE operation. +* This function does not select/unselect the CS line. +* +* Returns 0 on success, a negative error code otherwise. +*/ +int nand_prog_page_end_op (struct nand_chip *chip) +{ +struct mtd_info *mtd =nand_to_mtd (chip); +int status; + + chip->cmdfunc (mtd,NAND_CMD_PAGEPROG ,-1 ,-1 ); + + status = chip->waitfunc (mtd, chip); +if (status &NAND_STATUS_FAIL ) +return -EIO ; + +return 0 ; +} +EXPORT_SYMBOL_GPL (nand_prog_page_end_op); + +/** +* nand_prog_page_op - Do a full PROG PAGE operation +* @chip: The NAND chip +* @page: page to write +* @offset_in_page: offset within the page +* @buf: buffer containing the data to write to the page +* @len: length of the buffer +* +* This function issues a full PROG PAGE operation. +* This function does not select/unselect the CS line. +* +* Returns 0 on success, a negative error code otherwise. +*/ +int nand_prog_page_op (struct nand_chip *chip,unsigned int page, +unsigned int offset_in_page,const void *buf, +unsigned int len) +{ +struct mtd_info *mtd =nand_to_mtd (chip); +int status; + +if (!len || !buf) +return -EINVAL ; + +if (offset_in_page + len > mtd->writesize + mtd->oobsize) +return -EINVAL ; + + chip->cmdfunc (mtd,NAND_CMD_SEQIN , offset_in_page, page); + chip->write_buf (mtd, buf, len); + chip->cmdfunc (mtd,NAND_CMD_PAGEPROG ,-1 ,-1 ); + + status = chip->waitfunc (mtd, chip); +if (status &NAND_STATUS_FAIL ) +return -EIO ; + +return 0 ; +} +EXPORT_SYMBOL_GPL (nand_prog_page_op); + +/** +* nand_change_write_column_op - Do a CHANGE WRITE COLUMN operation +* @chip: The NAND chip +* @offset_in_page: offset within the page +* @buf: buffer containing the data to send to the NAND +* @len: length of the buffer +* @force_8bit: force 8-bit bus access +* +* This function issues a CHANGE WRITE COLUMN operation. +* This function does not select/unselect the CS line. +* +* Returns 0 on success, a negative error code otherwise. +*/ +int nand_change_write_column_op (struct nand_chip *chip, +unsigned int offset_in_page, +const void *buf,unsigned int len, +bool force_8bit) +{ +struct mtd_info *mtd =nand_to_mtd (chip); + +if (len && !buf) +return -EINVAL ; + +if (offset_in_page + len > mtd->writesize + mtd->oobsize) +return -EINVAL ; + + chip->cmdfunc (mtd,NAND_CMD_RNDIN , offset_in_page,-1 ); +if (len) + chip->write_buf (mtd, buf, len); + +return 0 ; +} +EXPORT_SYMBOL_GPL (nand_change_write_column_op); + +/** +* nand_readid_op - Do a READID operation +* @chip: The NAND chip +* @addr: address cycle to pass after the READID command +* @buf: buffer used to store the ID +* @len: length of the buffer +* +* This function sends a READID command and reads back the ID returned by the +* NAND. +* This function does not select/unselect the CS line. +* +* Returns 0 on success, a negative error code otherwise. +*/ +int nand_readid_op (struct nand_chip *chip,u8 addr,void *buf, +unsigned int len) +{ +struct mtd_info *mtd =nand_to_mtd (chip); +unsigned int i; +u8 *id = buf; + +if (len && !buf) +return -EINVAL ; + + chip->cmdfunc (mtd,NAND_CMD_READID , addr,-1 ); + +for (i =0 ; i < len; i++) + id[i] = chip->read_byte (mtd); + +return 0 ; +} +EXPORT_SYMBOL_GPL (nand_readid_op); + +/** +* nand_status_op - Do a STATUS operation +* @chip: The NAND chip +* @status: out variable to store the NAND status +* +* This function sends a STATUS command and reads back the status returned by +* the NAND. +* This function does not select/unselect the CS line. +* +* Returns 0 on success, a negative error code otherwise. +*/ +int nand_status_op (struct nand_chip *chip,u8 *status) +{ +struct mtd_info *mtd =nand_to_mtd (chip); + + chip->cmdfunc (mtd,NAND_CMD_STATUS ,-1 ,-1 ); +if (status) + *status = chip->read_byte (mtd); + +return 0 ; +} +EXPORT_SYMBOL_GPL (nand_status_op); + +/** +* nand_exit_status_op - Exit a STATUS operation +* @chip: The NAND chip +* +* This function sends a READ0 command to cancel the effect of the STATUS +* command to avoid reading only the status until a new read command is sent. +* +* This function does not select/unselect the CS line. +* +* Returns 0 on success, a negative error code otherwise. +*/ +int nand_exit_status_op (struct nand_chip *chip) +{ +struct mtd_info *mtd =nand_to_mtd (chip); + + chip->cmdfunc (mtd,NAND_CMD_READ0 ,-1 ,-1 ); + +return 0 ; +} +EXPORT_SYMBOL_GPL (nand_exit_status_op); + +/** +* nand_erase_op - Do an erase operation +* @chip: The NAND chip +* @eraseblock: block to erase +* +* This function sends an ERASE command and waits for the NAND to be ready +* before returning. +* This function does not select/unselect the CS line. +* +* Returns 0 on success, a negative error code otherwise. +*/ +int nand_erase_op (struct nand_chip *chip,unsigned int eraseblock) +{ +struct mtd_info *mtd =nand_to_mtd (chip); +unsigned int page = eraseblock << + (chip->phys_erase_shift - chip->page_shift); +int status; + + chip->cmdfunc (mtd,NAND_CMD_ERASE1 ,-1 , page); + chip->cmdfunc (mtd,NAND_CMD_ERASE2 ,-1 ,-1 ); + + status = chip->waitfunc (mtd, chip); +if (status <0 ) +return status; + +if (status &NAND_STATUS_FAIL ) +return -EIO ; + +return 0 ; +} +EXPORT_SYMBOL_GPL (nand_erase_op); + +/** +* nand_set_features_op - Do a SET FEATURES operation +* @chip: The NAND chip +* @feature: feature id +* @data: 4 bytes of data +* +* This function sends a SET FEATURES command and waits for the NAND to be +* ready before returning. +* This function does not select/unselect the CS line. +* +* Returns 0 on success, a negative error code otherwise. +*/ +static int nand_set_features_op (struct nand_chip *chip,u8 feature, +const void *data) +{ +struct mtd_info *mtd =nand_to_mtd (chip); +const u8 *params = data; +int i, status; + + chip->cmdfunc (mtd,NAND_CMD_SET_FEATURES , feature,-1 ); +for (i =0 ; i <ONFI_SUBFEATURE_PARAM_LEN ; ++i) + chip->write_byte (mtd, params[i]); + + status = chip->waitfunc (mtd, chip); +if (status &NAND_STATUS_FAIL ) +return -EIO ; + +return 0 ; +} + +/** +* nand_get_features_op - Do a GET FEATURES operation +* @chip: The NAND chip +* @feature: feature id +* @data: 4 bytes of data +* +* This function sends a GET FEATURES command and waits for the NAND to be +* ready before returning. +* This function does not select/unselect the CS line. +* +* Returns 0 on success, a negative error code otherwise. +*/ +static int nand_get_features_op (struct nand_chip *chip,u8 feature, +void *data) +{ +struct mtd_info *mtd =nand_to_mtd (chip); +u8 *params = data; +int i; + + chip->cmdfunc (mtd,NAND_CMD_GET_FEATURES , feature,-1 ); +for (i =0 ; i <ONFI_SUBFEATURE_PARAM_LEN ; ++i) + params[i] = chip->read_byte (mtd); + +return 0 ; +} + +/** +* nand_reset_op - Do a reset operation +* @chip: The NAND chip +* +* This function sends a RESET command and waits for the NAND to be ready +* before returning. +* This function does not select/unselect the CS line. +* +* Returns 0 on success, a negative error code otherwise. +*/ +int nand_reset_op (struct nand_chip *chip) +{ +struct mtd_info *mtd =nand_to_mtd (chip); + + chip->cmdfunc (mtd,NAND_CMD_RESET ,-1 ,-1 ); + +return 0 ; +} +EXPORT_SYMBOL_GPL (nand_reset_op); + +/** +* nand_read_data_op - Read data from the NAND +* @chip: The NAND chip +* @buf: buffer used to store the data +* @len: length of the buffer +* @force_8bit: force 8-bit bus access +* +* This function does a raw data read on the bus. Usually used after launching +* another NAND operation like nand_read_page_op(). +* This function does not select/unselect the CS line. +* +* Returns 0 on success, a negative error code otherwise. +*/ +int nand_read_data_op (struct nand_chip *chip,void *buf,unsigned int len, +bool force_8bit) +{ +struct mtd_info *mtd =nand_to_mtd (chip); + +if (!len || !buf) +return -EINVAL ; + +if (force_8bit) { +u8 *p = buf; +unsigned int i; + +for (i =0 ; i < len; i++) + p[i] = chip->read_byte (mtd); + }else { + chip->read_buf (mtd, buf, len); + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (nand_read_data_op); + +/** +* nand_write_data_op - Write data from the NAND +* @chip: The NAND chip +* @buf: buffer containing the data to send on the bus +* @len: length of the buffer +* @force_8bit: force 8-bit bus access +* +* This function does a raw data write on the bus. Usually used after launching +* another NAND operation like nand_write_page_begin_op(). +* This function does not select/unselect the CS line. +* +* Returns 0 on success, a negative error code otherwise. +*/ +int nand_write_data_op (struct nand_chip *chip,const void *buf, +unsigned int len,bool force_8bit) +{ +struct mtd_info *mtd =nand_to_mtd (chip); + +if (!len || !buf) +return -EINVAL ; + +if (force_8bit) { +const u8 *p = buf; +unsigned int i; + +for (i =0 ; i < len; i++) + chip->write_byte (mtd, p[i]); + }else { + chip->write_buf (mtd, buf, len); + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (nand_write_data_op); + +/** * nand_reset - Reset and initialize a NAND device * @chip: The NAND chip * @chipnr: Internal die id
@@ -1068,8 +1609,10 @@ int nand_reset(struct nand_chip *chip, int chipnr)* interface settings, hence this weird ->select_chip() dance. */ chip->select_chip (mtd, chipnr); - chip->cmdfunc (mtd,NAND_CMD_RESET ,-1 ,-1 ); + ret =nand_reset_op (chip); chip->select_chip (mtd,-1 ); +if (ret) +return ret; chip->select_chip (mtd, chipnr); ret =nand_setup_data_interface (chip, chipnr);
@@ -1220,9 +1763,19 @@ EXPORT_SYMBOL(nand_check_erased_ecc_chunk);static int nand_read_page_raw (struct mtd_info *mtd,struct nand_chip *chip,uint8_t *buf,int oob_required,int page) { - chip->read_buf (mtd, buf, mtd->writesize); -if (oob_required) - chip->read_buf (mtd, chip->oob_poi, mtd->oobsize); +int ret; + + ret =nand_read_data_op (chip, buf, mtd->writesize, false); +if (ret) +return ret; + +if (oob_required) { + ret =nand_read_data_op (chip, chip->oob_poi, mtd->oobsize, + false); +if (ret) +return ret; + } +return 0 ; }
@@ -1243,29 +1796,46 @@ static int nand_read_page_raw_syndrome(struct mtd_info *mtd,int eccsize = chip->ecc.size;int eccbytes = chip->ecc.bytes;uint8_t *oob = chip->oob_poi; -int steps, size; +int steps, size, ret;for (steps = chip->ecc.steps; steps >0 ; steps--) { - chip->read_buf (mtd, buf, eccsize); + ret =nand_read_data_op (chip, buf, eccsize, false); +if (ret) +return ret; + buf += eccsize;if (chip->ecc.prepad) { - chip->read_buf (mtd, oob, chip->ecc.prepad); + ret =nand_read_data_op (chip, oob, chip->ecc.prepad, + false); +if (ret) +return ret; + oob += chip->ecc.prepad; } - chip->read_buf (mtd, oob, eccbytes); + ret =nand_read_data_op (chip, oob, eccbytes, false); +if (ret) +return ret; + oob += eccbytes;if (chip->ecc.postpad) { - chip->read_buf (mtd, oob, chip->ecc.postpad); + ret =nand_read_data_op (chip, oob, chip->ecc.postpad, + false); +if (ret) +return ret; + oob += chip->ecc.postpad; } } size = mtd->oobsize - (oob - chip->oob_poi); -if (size) - chip->read_buf (mtd, oob, size); +if (size) { + ret =nand_read_data_op (chip, oob, size, false); +if (ret) +return ret; + }return 0 ; }
@@ -1336,6 +1906,7 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,int busw = (chip->options &NAND_BUSWIDTH_16 ) ?2 :1 ;int index;unsigned int max_bitflips =0 ; +int ret;/* Column address within the page aligned to ECC size (256bytes) */ start_step = data_offs / chip->ecc.size;
@@ -1353,7 +1924,9 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip, chip->cmdfunc (mtd,NAND_CMD_RNDOUT , data_col_addr,-1 ); p = bufpoi + data_col_addr; - chip->read_buf (mtd, p, datafrag_len); + ret =nand_read_data_op (chip, p, datafrag_len, false); +if (ret) +return ret;/* Calculate ECC */ for (i =0 ; i < eccfrag_len ; i += chip->ecc.bytes, p += chip->ecc.size)
@@ -1370,8 +1943,11 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip, } }if (gaps) { - chip->cmdfunc (mtd,NAND_CMD_RNDOUT , mtd->writesize,-1 ); - chip->read_buf (mtd, chip->oob_poi, mtd->oobsize); + ret =nand_change_read_column_op (chip, mtd->writesize, + chip->oob_poi, mtd->oobsize, + false); +if (ret) +return ret; }else {/* * Send the command to read the particular ECC bytes take care
@@ -1384,9 +1960,12 @@ static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,if (eccpos[index + (num_steps * chip->ecc.bytes)] & (busw -1 )) aligned_len++; - chip->cmdfunc (mtd,NAND_CMD_RNDOUT , - mtd->writesize + aligned_pos,-1 ); - chip->read_buf (mtd, &chip->oob_poi[aligned_pos], aligned_len); + ret =nand_change_read_column_op (chip, + mtd->writesize + aligned_pos, + &chip->oob_poi[aligned_pos], + aligned_len, false); +if (ret) +return ret; }for (i =0 ; i < eccfrag_len; i++)
@@ -1439,13 +2018,21 @@ static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,uint8_t *ecc_code = chip->buffers->ecccode;uint32_t *eccpos = chip->ecc.layout->eccpos;unsigned int max_bitflips =0 ; +int ret;for (i =0 ; eccsteps; eccsteps--, i += eccbytes, p += eccsize) { chip->ecc.hwctl (mtd,NAND_ECC_READ ); - chip->read_buf (mtd, p, eccsize); + + ret =nand_read_data_op (chip, p, eccsize, false); +if (ret) +return ret; + chip->ecc.calculate (mtd, p, &ecc_calc[i]); } - chip->read_buf (mtd, chip->oob_poi, mtd->oobsize); + + ret =nand_read_data_op (chip, chip->oob_poi, mtd->oobsize, false); +if (ret) +return ret;for (i =0 ; i < chip->ecc.total; i++) ecc_code[i] = chip->oob_poi[eccpos[i]];
@@ -1501,11 +2088,16 @@ static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd,uint32_t *eccpos = chip->ecc.layout->eccpos;uint8_t *ecc_calc = chip->buffers->ecccalc;unsigned int max_bitflips =0 ; +int ret;/* Read the OOB area first */ - chip->cmdfunc (mtd,NAND_CMD_READOOB ,0 , page); - chip->read_buf (mtd, chip->oob_poi, mtd->oobsize); - chip->cmdfunc (mtd,NAND_CMD_READ0 ,0 , page); + ret =nand_read_oob_op (chip, page,0 , chip->oob_poi, mtd->oobsize); +if (ret) +return ret; + + ret =nand_read_page_op (chip, page,0 ,NULL ,0 ); +if (ret) +return ret;for (i =0 ; i < chip->ecc.total; i++) ecc_code[i] = chip->oob_poi[eccpos[i]];
@@ -1514,7 +2106,11 @@ static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd,int stat; chip->ecc.hwctl (mtd,NAND_ECC_READ ); - chip->read_buf (mtd, p, eccsize); + + ret =nand_read_data_op (chip, p, eccsize, false); +if (ret) +return ret; + chip->ecc.calculate (mtd, p, &ecc_calc[i]); stat = chip->ecc.correct (mtd, p, &ecc_code[i],NULL );
@@ -1551,7 +2147,7 @@ static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd,static int nand_read_page_syndrome (struct mtd_info *mtd,struct nand_chip *chip,uint8_t *buf,int oob_required,int page) { -int i, eccsize = chip->ecc.size; +int ret, i, eccsize = chip->ecc.size;int eccbytes = chip->ecc.bytes;int eccsteps = chip->ecc.steps;int eccpadbytes = eccbytes + chip->ecc.prepad + chip->ecc.postpad;
@@ -1563,21 +2159,36 @@ static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip,int stat; chip->ecc.hwctl (mtd,NAND_ECC_READ ); - chip->read_buf (mtd, p, eccsize); + + ret =nand_read_data_op (chip, p, eccsize, false); +if (ret) +return ret;if (chip->ecc.prepad) { - chip->read_buf (mtd, oob, chip->ecc.prepad); + ret =nand_read_data_op (chip, oob, chip->ecc.prepad, + false); +if (ret) +return ret; + oob += chip->ecc.prepad; } chip->ecc.hwctl (mtd,NAND_ECC_READSYN ); - chip->read_buf (mtd, oob, eccbytes); + + ret =nand_read_data_op (chip, oob, eccbytes, false); +if (ret) +return ret; + stat = chip->ecc.correct (mtd, p, oob,NULL ); oob += eccbytes;if (chip->ecc.postpad) { - chip->read_buf (mtd, oob, chip->ecc.postpad); + ret =nand_read_data_op (chip, oob, chip->ecc.postpad, + false); +if (ret) +return ret; + oob += chip->ecc.postpad; }
@@ -1601,8 +2212,11 @@ static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip,/* Calculate remaining oob bytes */ i = mtd->oobsize - (oob - chip->oob_poi); -if (i) - chip->read_buf (mtd, oob, i); +if (i) { + ret =nand_read_data_op (chip, oob, i, false); +if (ret) +return ret; + }return max_bitflips; }
@@ -1739,8 +2353,11 @@ static int nand_do_read_ops(struct mtd_info *mtd, loff_t from, __func__, buf); read_retry: -if (nand_standard_page_accessors (&chip->ecc)) - chip->cmdfunc (mtd,NAND_CMD_READ0 ,0x00 , page); +if (nand_standard_page_accessors (&chip->ecc)) { + ret =nand_read_page_op (chip, page,0 ,NULL ,0 ); +if (ret) +break ; + }/* * Now read the page into the buffer. Absent an error,
@@ -1874,9 +2491,7 @@ read_retry:static int nand_read_oob_std (struct mtd_info *mtd,struct nand_chip *chip,int page) { - chip->cmdfunc (mtd,NAND_CMD_READOOB ,0 , page); - chip->read_buf (mtd, chip->oob_poi, mtd->oobsize); -return 0 ; +return nand_read_oob_op (chip, page,0 , chip->oob_poi, mtd->oobsize); }/**
@@ -1893,25 +2508,43 @@ static int nand_read_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip,int chunk = chip->ecc.bytes + chip->ecc.prepad + chip->ecc.postpad;int eccsize = chip->ecc.size;uint8_t *bufpoi = chip->oob_poi; -int i, toread, sndrnd =0 , pos; +int i, toread, sndrnd =0 , pos, ret; + + ret =nand_read_page_op (chip, page, chip->ecc.size,NULL ,0 ); +if (ret) +return ret; - chip->cmdfunc (mtd,NAND_CMD_READ0 , chip->ecc.size, page);for (i =0 ; i < chip->ecc.steps; i++) {if (sndrnd) { +int ret; + pos = eccsize + i * (eccsize + chunk);if (mtd->writesize >512 ) - chip->cmdfunc (mtd,NAND_CMD_RNDOUT , pos,-1 ); + ret =nand_change_read_column_op (chip, pos, +NULL ,0 , + false);else - chip->cmdfunc (mtd,NAND_CMD_READ0 , pos, page); + ret =nand_read_page_op (chip, page, pos,NULL , +0 ); + +if (ret) +return ret; }else sndrnd =1 ; toread =min_t (int, length, chunk); - chip->read_buf (mtd, bufpoi, toread); + + ret =nand_read_data_op (chip, bufpoi, toread, false); +if (ret) +return ret; + bufpoi += toread; length -= toread; } -if (length >0 ) - chip->read_buf (mtd, bufpoi, length); +if (length >0 ) { + ret =nand_read_data_op (chip, bufpoi, length, false); +if (ret) +return ret; + }return 0 ; }
@@ -1925,18 +2558,8 @@ static int nand_read_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip,static int nand_write_oob_std (struct mtd_info *mtd,struct nand_chip *chip,int page) { -int status =0 ; -const uint8_t *buf = chip->oob_poi; -int length = mtd->oobsize; - - chip->cmdfunc (mtd,NAND_CMD_SEQIN , mtd->writesize, page); - chip->write_buf (mtd, buf, length); -/* Send command to program the OOB data */ - chip->cmdfunc (mtd,NAND_CMD_PAGEPROG ,-1 ,-1 ); - - status = chip->waitfunc (mtd, chip); - -return status &NAND_STATUS_FAIL ? -EIO :0 ; +return nand_prog_page_op (chip, page, mtd->writesize, chip->oob_poi, + mtd->oobsize); }/**
@@ -1951,7 +2574,7 @@ static int nand_write_oob_syndrome(struct mtd_info *mtd, {int chunk = chip->ecc.bytes + chip->ecc.prepad + chip->ecc.postpad;int eccsize = chip->ecc.size, length = mtd->oobsize; -int i, len, pos, status =0 , sndcmd =0 , steps = chip->ecc.steps; +int ret, i, len, pos, sndcmd =0 , steps = chip->ecc.steps;const uint8_t *bufpoi = chip->oob_poi;/*
@@ -1965,7 +2588,10 @@ static int nand_write_oob_syndrome(struct mtd_info *mtd, }else pos = eccsize; - chip->cmdfunc (mtd,NAND_CMD_SEQIN , pos, page); + ret =nand_prog_page_begin_op (chip, page, pos,NULL ,0 ); +if (ret) +return ret; +for (i =0 ; i < steps; i++) {if (sndcmd) {if (mtd->writesize <=512 ) {
@@ -1974,28 +2600,40 @@ static int nand_write_oob_syndrome(struct mtd_info *mtd, len = eccsize;while (len >0 ) {int num =min_t (int, len,4 ); - chip->write_buf (mtd, (uint8_t *)&fill, - num); + + ret =nand_write_data_op (chip, &fill, + num, false); +if (ret) +return ret; + len -= num; } }else { pos = eccsize + i * (eccsize + chunk); - chip->cmdfunc (mtd,NAND_CMD_RNDIN , pos,-1 ); + ret =nand_change_write_column_op (chip, pos, +NULL ,0 , + false); +if (ret) +return ret; } }else sndcmd =1 ; len =min_t (int, length, chunk); - chip->write_buf (mtd, bufpoi, len); + + ret =nand_write_data_op (chip, bufpoi, len, false); +if (ret) +return ret; + bufpoi += len; length -= len; } -if (length >0 ) - chip->write_buf (mtd, bufpoi, length); - - chip->cmdfunc (mtd,NAND_CMD_PAGEPROG ,-1 ,-1 ); - status = chip->waitfunc (mtd, chip); +if (length >0 ) { + ret =nand_write_data_op (chip, bufpoi, length, false); +if (ret) +return ret; + } -return status &NAND_STATUS_FAIL ? -EIO :0 ; +return nand_prog_page_end_op (chip); }/**
@@ -2154,9 +2792,18 @@ out:static int nand_write_page_raw (struct mtd_info *mtd,struct nand_chip *chip,const uint8_t *buf,int oob_required,int page) { - chip->write_buf (mtd, buf, mtd->writesize); -if (oob_required) - chip->write_buf (mtd, chip->oob_poi, mtd->oobsize); +int ret; + + ret =nand_write_data_op (chip, buf, mtd->writesize, false); +if (ret) +return ret; + +if (oob_required) { + ret =nand_write_data_op (chip, chip->oob_poi, mtd->oobsize, + false); +if (ret) +return ret; + }return 0 ; }
@@ -2179,29 +2826,46 @@ static int nand_write_page_raw_syndrome(struct mtd_info *mtd,int eccsize = chip->ecc.size;int eccbytes = chip->ecc.bytes;uint8_t *oob = chip->oob_poi; -int steps, size; +int steps, size, ret;for (steps = chip->ecc.steps; steps >0 ; steps--) { - chip->write_buf (mtd, buf, eccsize); + ret =nand_write_data_op (chip, buf, eccsize, false); +if (ret) +return ret; + buf += eccsize;if (chip->ecc.prepad) { - chip->write_buf (mtd, oob, chip->ecc.prepad); + ret =nand_write_data_op (chip, oob, chip->ecc.prepad, + false); +if (ret) +return ret; + oob += chip->ecc.prepad; } - chip->write_buf (mtd, oob, eccbytes); + ret =nand_write_data_op (chip, oob, eccbytes, false); +if (ret) +return ret; + oob += eccbytes;if (chip->ecc.postpad) { - chip->write_buf (mtd, oob, chip->ecc.postpad); + ret =nand_write_data_op (chip, oob, chip->ecc.postpad, + false); +if (ret) +return ret; + oob += chip->ecc.postpad; } } size = mtd->oobsize - (oob - chip->oob_poi); -if (size) - chip->write_buf (mtd, oob, size); +if (size) { + ret =nand_write_data_op (chip, oob, size, false); +if (ret) +return ret; + }return 0 ; }
@@ -2252,17 +2916,24 @@ static int nand_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,uint8_t *ecc_calc = chip->buffers->ecccalc;const uint8_t *p = buf;uint32_t *eccpos = chip->ecc.layout->eccpos; +int ret;for (i =0 ; eccsteps; eccsteps--, i += eccbytes, p += eccsize) { chip->ecc.hwctl (mtd,NAND_ECC_WRITE ); - chip->write_buf (mtd, p, eccsize); + + ret =nand_write_data_op (chip, p, eccsize, false); +if (ret) +return ret; + chip->ecc.calculate (mtd, p, &ecc_calc[i]); }for (i =0 ; i < chip->ecc.total; i++) chip->oob_poi[eccpos[i]] = ecc_calc[i]; - chip->write_buf (mtd, chip->oob_poi, mtd->oobsize); + ret =nand_write_data_op (chip, chip->oob_poi, mtd->oobsize, false); +if (ret) +return ret;return 0 ; }
@@ -2293,13 +2964,16 @@ static int nand_write_subpage_hwecc(struct mtd_info *mtd,uint32_t end_step = (offset + data_len -1 ) / ecc_size;int oob_bytes = mtd->oobsize / ecc_steps;int step, i; +int ret;for (step =0 ; step < ecc_steps; step++) {/* configure controller for WRITE access */ chip->ecc.hwctl (mtd,NAND_ECC_WRITE );/* write data (untouched subpages already masked by 0xFF) */ - chip->write_buf (mtd, buf, ecc_size); + ret =nand_write_data_op (chip, buf, ecc_size, false); +if (ret) +return ret;/* mask ECC of un-touched subpages by padding 0xFF */ if ((step < start_step) || (step > end_step))
@@ -2324,7 +2998,9 @@ static int nand_write_subpage_hwecc(struct mtd_info *mtd, chip->oob_poi[eccpos[i]] = ecc_calc[i];/* write OOB buffer to NAND device */ - chip->write_buf (mtd, chip->oob_poi, mtd->oobsize); + ret =nand_write_data_op (chip, chip->oob_poi, mtd->oobsize, false); +if (ret) +return ret;return 0 ; }
@@ -2351,31 +3027,49 @@ static int nand_write_page_syndrome(struct mtd_info *mtd,int eccsteps = chip->ecc.steps;const uint8_t *p = buf;uint8_t *oob = chip->oob_poi; +int ret;for (i =0 ; eccsteps; eccsteps--, i += eccbytes, p += eccsize) { - chip->ecc.hwctl (mtd,NAND_ECC_WRITE ); - chip->write_buf (mtd, p, eccsize); + + ret =nand_write_data_op (chip, p, eccsize, false); +if (ret) +return ret;if (chip->ecc.prepad) { - chip->write_buf (mtd, oob, chip->ecc.prepad); + ret =nand_write_data_op (chip, oob, chip->ecc.prepad, + false); +if (ret) +return ret; + oob += chip->ecc.prepad; } chip->ecc.calculate (mtd, p, oob); - chip->write_buf (mtd, oob, eccbytes); + + ret =nand_write_data_op (chip, oob, eccbytes, false); +if (ret) +return ret; + oob += eccbytes;if (chip->ecc.postpad) { - chip->write_buf (mtd, oob, chip->ecc.postpad); + ret =nand_write_data_op (chip, oob, chip->ecc.postpad, + false); +if (ret) +return ret; + oob += chip->ecc.postpad; } }/* Calculate remaining oob bytes */ i = mtd->oobsize - (oob - chip->oob_poi); -if (i) - chip->write_buf (mtd, oob, i); +if (i) { + ret =nand_write_data_op (chip, oob, i, false); +if (ret) +return ret; + }return 0 ; }
@@ -2403,8 +3097,11 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,else subpage =0 ; -if (nand_standard_page_accessors (&chip->ecc)) - chip->cmdfunc (mtd,NAND_CMD_SEQIN ,0x00 , page); +if (nand_standard_page_accessors (&chip->ecc)) { + status =nand_prog_page_begin_op (chip, page,0 ,NULL ,0 ); +if (status) +return status; + }if (unlikely (raw)) status = chip->ecc.write_page_raw(mtd, chip, buf,
@@ -2419,13 +3116,8 @@ static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip,if (status <0 )return status; -if (nand_standard_page_accessors (&chip->ecc)) { - chip->cmdfunc (mtd,NAND_CMD_PAGEPROG ,-1 ,-1 ); - - status = chip->waitfunc (mtd, chip); -if (status &NAND_STATUS_FAIL ) -return -EIO ; - } +if (nand_standard_page_accessors (&chip->ecc)) +return nand_prog_page_end_op (chip);return 0 ; }
@@ -2785,11 +3477,12 @@ out:static int single_erase (struct mtd_info *mtd,int page) {struct nand_chip *chip =mtd_to_nand (mtd); +unsigned int eraseblock; +/* Send commands to erase a block */ - chip->cmdfunc (mtd,NAND_CMD_ERASE1 ,-1 , page); - chip->cmdfunc (mtd,NAND_CMD_ERASE2 ,-1 ,-1 ); + eraseblock = page >> (chip->phys_erase_shift - chip->page_shift); -return chip->waitfunc (mtd, chip); +return nand_erase_op (chip, eraseblock); }/**
@@ -2982,9 +3675,6 @@ static int nand_block_markbad(struct mtd_info *mtd, loff_t ofs)static int nand_onfi_set_features (struct mtd_info *mtd,struct nand_chip *chip,int addr,uint8_t *subfeature_param) { -int status; -int i; -#ifdef CONFIG_SYS_NAND_ONFI_DETECTION if (!chip->onfi_version || !(le16_to_cpu(chip->onfi_params.opt_cmd)
@@ -2992,14 +3682,7 @@ static int nand_onfi_set_features(struct mtd_info *mtd, struct nand_chip *chip,return -ENOTSUPP ;#endif - chip->cmdfunc (mtd,NAND_CMD_SET_FEATURES , addr,-1 ); -for (i =0 ; i <ONFI_SUBFEATURE_PARAM_LEN ; ++i) - chip->write_byte (mtd, subfeature_param[i]); - - status = chip->waitfunc (mtd, chip); -if (status &NAND_STATUS_FAIL ) -return -EIO ; -return 0 ; +return nand_set_features_op (chip, addr, subfeature_param); }/**
@@ -3012,8 +3695,6 @@ static int nand_onfi_set_features(struct mtd_info *mtd, struct nand_chip *chip,static int nand_onfi_get_features (struct mtd_info *mtd,struct nand_chip *chip,int addr,uint8_t *subfeature_param) { -int i; -#ifdef CONFIG_SYS_NAND_ONFI_DETECTION if (!chip->onfi_version || !(le16_to_cpu(chip->onfi_params.opt_cmd)
@@ -3021,10 +3702,7 @@ static int nand_onfi_get_features(struct mtd_info *mtd, struct nand_chip *chip,return -ENOTSUPP ;#endif - chip->cmdfunc (mtd,NAND_CMD_GET_FEATURES , addr,-1 ); -for (i =0 ; i <ONFI_SUBFEATURE_PARAM_LEN ; ++i) - *subfeature_param++ = chip->read_byte (mtd); -return 0 ; +return nand_get_features_op (chip, addr, subfeature_param); }/* Set default functions */
@@ -3118,7 +3796,7 @@ static int nand_flash_detect_ext_param_page(struct mtd_info *mtd,struct onfi_ext_section *s;struct onfi_ext_ecc_info *ecc;uint8_t *cursor; -int ret = -EINVAL ; +int ret;int len;int i;
@@ -3128,14 +3806,18 @@ static int nand_flash_detect_ext_param_page(struct mtd_info *mtd,return -ENOMEM ;/* Send our own NAND_CMD_PARAM. */ - chip->cmdfunc (mtd,NAND_CMD_PARAM ,0 ,-1 ); + ret =nand_read_param_page_op (chip,0 ,NULL ,0 ); +if (ret) + goto ext_out;/* Use the Change Read Column command to skip the ONFI param pages. */ - chip->cmdfunc (mtd,NAND_CMD_RNDOUT , -sizeof (*p) * p->num_of_param_pages ,-1 ); + ret =nand_change_read_column_op (chip, +sizeof (*p) * p->num_of_param_pages, + ep, len, true); +if (ret) + goto ext_out; -/* Read out the Extended Parameter Page. */ - chip->read_buf (mtd, (uint8_t *)ep, len); + ret = -EINVAL ;if ((onfi_crc16 (ONFI_CRC_BASE , ((uint8_t *)ep) +2 , len -2 ) !=le16_to_cpu (ep->crc))) {pr_debug ("fail in the CRC.\n" );
@@ -3212,19 +3894,23 @@ static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, int *busw) {struct nand_onfi_params *p = &chip->onfi_params; -int i, j; -int val; +char id[4 ]; +int i, ret, val;/* Try ONFI for unknown chip or LP */ - chip->cmdfunc (mtd,NAND_CMD_READID ,0x20 ,-1 ); -if (chip->read_byte (mtd) !='O' || chip->read_byte (mtd) !='N' || - chip->read_byte (mtd) !='F' || chip->read_byte (mtd) !='I' ) + ret =nand_readid_op (chip,0x20 , id,sizeof (id)); +if (ret ||strncmp (id,"ONFI" ,4 )) +return 0 ; + + ret =nand_read_param_page_op (chip,0 ,NULL ,0 ); +if (ret)return 0 ; - chip->cmdfunc (mtd,NAND_CMD_PARAM ,0 ,-1 );for (i =0 ; i <3 ; i++) { -for (j =0 ; j <sizeof (*p); j++) - ((uint8_t *)p)[j] = chip->read_byte (mtd); + ret =nand_read_data_op (chip, p,sizeof (*p), true); +if (ret) +return 0 ; +if (onfi_crc16 (ONFI_CRC_BASE , (uint8_t *)p,254 ) ==le16_to_cpu (p->crc)) {break ;
@@ -3324,20 +4010,22 @@ static int nand_flash_detect_jedec(struct mtd_info *mtd, struct nand_chip *chip, {struct nand_jedec_params *p = &chip->jedec_params;struct jedec_ecc_info *ecc; -int val; -int i, j; +char id[5 ]; +int i, val, ret;/* Try JEDEC for unknown chip or LP */ - chip->cmdfunc (mtd,NAND_CMD_READID ,0x40 ,-1 ); -if (chip->read_byte (mtd) !='J' || chip->read_byte (mtd) !='E' || - chip->read_byte (mtd) !='D' || chip->read_byte (mtd) !='E' || - chip->read_byte (mtd) !='C' ) + ret =nand_readid_op (chip,0x40 , id,sizeof (id)); +if (ret ||strncmp (id,"JEDEC" ,sizeof (id))) +return 0 ; + + ret =nand_read_param_page_op (chip,0x40 ,NULL ,0 ); +if (ret)return 0 ; - chip->cmdfunc (mtd,NAND_CMD_PARAM ,0x40 ,-1 );for (i =0 ; i <3 ; i++) { -for (j =0 ; j <sizeof (*p); j++) - ((uint8_t *)p)[j] = chip->read_byte (mtd); + ret =nand_read_data_op (chip, p,sizeof (*p), true); +if (ret) +return 0 ;if (onfi_crc16 (ONFI_CRC_BASE , (uint8_t *)p,510 ) ==le16_to_cpu (p->crc))
@@ -3708,25 +4396,29 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, int *maf_id, int *dev_id, struct nand_flash_dev *type) { - int busw; -int i, maf_idx; + int busw, ret; +int maf_idx;u8 id_data[8 ];/* * Reset the chip, required by some chips (e.g. Micron MT29FxGxxxxx) * after power-up. */ -nand_reset (chip,0 ); + ret =nand_reset (chip,0 ); +if (ret) +return ERR_PTR (ret);/* Select the device */ chip->select_chip (mtd,0 );/* Send the command for reading device ID */ - chip->cmdfunc (mtd,NAND_CMD_READID ,0x00 ,-1 ); + ret =nand_readid_op (chip,0 , id_data,2 ); +if (ret) +return ERR_PTR (ret);/* Read manufacturer and device IDs */ - *maf_id = chip->read_byte (mtd); - *dev_id = chip->read_byte (mtd); + *maf_id = id_data[0 ]; + *dev_id = id_data[1 ];/* * Try again to make sure, as some systems the bus-hold or other
@@ -3735,11 +4427,10 @@ struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd,* not match, ignore the device completely. */ - chip->cmdfunc (mtd,NAND_CMD_READID ,0x00 ,-1 ); -/* Read entire ID string */ -for (i =0 ; i <8 ; i++) - id_data[i] = chip->read_byte (mtd); + ret =nand_readid_op (chip,0 , id_data,8 ); +if (ret) +return ERR_PTR (ret);if (id_data[0 ] != *maf_id || id_data[1 ] != *dev_id) { pr_info("second ID read did not match %02x,%02x against %02x,%02x\n",
@@ -3999,15 +4690,17 @@ int nand_scan_ident(struct mtd_info *mtd, int maxchips,/* Check for a chip array */ for (i =1 ; i < maxchips; i++) { +u8 id[2 ]; +/* See comment in nand_get_flash_type for reset */ nand_reset (chip, i); chip->select_chip (mtd, i);/* Send the command for reading device ID */ - chip->cmdfunc (mtd,NAND_CMD_READID ,0x00 ,-1 ); +nand_readid_op (chip,0 , id,sizeof (id)); +/* Read manufacturer and device IDs */ -if (nand_maf_id != chip->read_byte (mtd) || - nand_dev_id != chip->read_byte (mtd)) { +if (nand_maf_id != id[0 ] || nand_dev_id != id[1 ]) { chip->select_chip (mtd,-1 );break ; }
include/linux/mtd/rawnand.h +30 -0
@@ -1299,4 +1299,34 @@ int nand_maximize_ecc(struct nand_chip *chip,/* Reset and initialize a NAND device */ int nand_reset (struct nand_chip *chip,int chipnr); + +/* NAND operation helpers */ +int nand_reset_op (struct nand_chip *chip); +int nand_readid_op (struct nand_chip *chip,u8 addr,void *buf, +unsigned int len); +int nand_status_op (struct nand_chip *chip,u8 *status); +int nand_exit_status_op (struct nand_chip *chip); +int nand_erase_op (struct nand_chip *chip,unsigned int eraseblock); +int nand_read_page_op (struct nand_chip *chip,unsigned int page, +unsigned int offset_in_page,void *buf,unsigned int len); +int nand_change_read_column_op (struct nand_chip *chip, +unsigned int offset_in_page,void *buf, +unsigned int len,bool force_8bit); +int nand_read_oob_op (struct nand_chip *chip,unsigned int page, +unsigned int offset_in_page,void *buf,unsigned int len); +int nand_prog_page_begin_op (struct nand_chip *chip,unsigned int page, +unsigned int offset_in_page,const void *buf, +unsigned int len); +int nand_prog_page_end_op (struct nand_chip *chip); +int nand_prog_page_op (struct nand_chip *chip,unsigned int page, +unsigned int offset_in_page,const void *buf, +unsigned int len); +int nand_change_write_column_op (struct nand_chip *chip, +unsigned int offset_in_page,const void *buf, +unsigned int len,bool force_8bit); +int nand_read_data_op (struct nand_chip *chip,void *buf,unsigned int len, +bool force_8bit); +int nand_write_data_op (struct nand_chip *chip,const void *buf, +unsigned int len,bool force_8bit); +#endif /* __LINUX_MTD_RAWNAND_H */
Signature · 1 line
2.7.4
PATCH 3/18 mtd: nand: provide several helpers to do common NAND operations
Quoted 13 lines · Philippe Reynes
From: Boris Brezillon <[email protected]>
Linux commit
97d90da8a88("mtd: nand: provide several helpers to do common NAND operations")This is part of the process of removing direct calls to ->cmdfunc() outside of the core in order to introduce a better interface to execute NAND operations.
Here we provide several helpers and make use of them to remove all direct calls to ->cmdfunc(). This way, we can easily modify those helpers to make use of the new ->exec_op() interface when available.
Quoted 7 lines
Signed-off-by Boris Brezillon <[email protected]>[miquel.raynal at free-electrons.com: rebased and fixed some conflicts]Signed-off-by Miquel Raynal <[email protected]>Acked-by Masahiro Yamada <[email protected]>[Philippe Reynes: adapt code to u-boot and only keep new function]Signed-off-by Philippe Reynes <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190424/04e5955f/attachment.sig>
PATCH 4/18 arm: asm: io.h: define readX_relaxed and writeX_relaxed
In reply to Philippe ReynesThis patch port the function readX_relaxed andwriteX_relaxed from kernel 4.18.
--- arch/arm/include/asm/io.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+)
arch/arm/include/asm/io.h +21 -0
@@ -123,6 +123,27 @@ static inline void __raw_readsl(unsigned long addr, void *data, int longlen)#define readq (c) ({ u64 __v = __arch_getq(c); __iormb(); __v; })/* +* Relaxed I/O memory access primitives. These follow the Device memory +* ordering rules but do not guarantee any ordering relative to Normal memory +* accesses. +*/ +#define readb_relaxed (c) ({ u8 __r = __raw_readb(c); __r; }) +#define readw_relaxed (c) ({ u16 __r = le16_to_cpu((__force __le16) \ + __raw_readw(c)); __r; }) +#define readl_relaxed (c) ({ u32 __r = le32_to_cpu((__force __le32) \ + __raw_readl(c)); __r; }) +#define readq_relaxed (c) ({ u64 __r = le64_to_cpu((__force __le64) \ + __raw_readq(c)); __r; }) + +#define writeb_relaxed (v, c) ((void)__raw_writeb((v), (c))) +#define writew_relaxed (v, c) ((void)__raw_writew((__force u16) \ + cpu_to_le16(v), (c))) +#define writel_relaxed (v, c) ((void)__raw_writel((__force u32) \ + cpu_to_le32(v), (c))) +#define writeq_relaxed (v, c) ((void)__raw_writeq((__force u64) \ + cpu_to_le64(v), (c))) + +/* * The compiler seems to be incapable of optimising constants * properly. Spell it out to the compiler in some cases. * These are only valid for small values of "off" (< 1<<12)
Signature · 1 line
2.7.4
PATCH 4/18 arm: asm: io.h: define readX_relaxed and writeX_relaxed
Quoted 4 lines · Philippe Reynes
This patch port the function
readX_relaxedandwriteX_relaxedfrom kernel 4.18.Signed-off-by Philippe Reynes <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190424/93168662/attachment.sig>
PATCH 5/18 include: linux: io: define devm_ioremap on board with ioremap
In reply to Philippe ReynesThe macro devm_ioremap is only defined for configuration that doesn't have ioremap. But this macro may also be defined on configuration with ioremap.
This patch remove the condition for the macro devm_ioremap, so it's always defined.
--- include/linux/io.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
include/linux/io.h +1 -1
@@ -65,8 +65,8 @@ static inline void __iomem *ioremap(resource_size_t offset,static inline void iounmap (void __iomem *addr) { } +#endif #define devm_ioremap (dev, offset, size) ioremap(offset, size) -#endif #endif /* _LINUX_IO_H */
Signature · 1 line
2.7.4
PATCH 5/18 include: linux: io: define devm_ioremap on board with ioremap
Quoted 7 lines · Philippe Reynes
The macro
devm_ioremapis only defined for configuration that doesn't have ioremap. But this macro may also be defined on configuration with ioremap.
This patch remove the condition for the macrodevm_ioremap, so it's always defined.Signed-off-by Philippe Reynes <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190424/c5147965/attachment.sig>
PATCH 6/18 compat linux: import completion from linux 4.18
In reply to Philippe ReynesThis patch port the file include/linux/completion.h from linux 4.18 to u-boot. It define the structure but all the function are stubbed.
--- include/linux/completion.h | 173 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 173 insertions(+) create mode 100644 include/linux/completion.h
include/linux/completion.h new file +173 -0
@@ -0,0 +1,173 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +#ifndef __LINUX_COMPLETION_H +#define __LINUX_COMPLETION_H + +/* +* (C) Copyright 2001 Linus Torvalds +* +* Atomic wait-for-completion handler data structures. +* See kernel/sched/completion.c for details. +*/ +#ifndef __UBOOT__ +#include <linux/wait.h> +#endif /* __UBOOT__ */ + +/* +* struct completion - structure used to maintain state for a "completion" +* +* This is the opaque structure used to maintain the state for a "completion". +* Completions currently use a FIFO to queue threads that have to wait for +* the "completion" event. +* +* See also: complete(), wait_for_completion() (and friends _timeout, +* _interruptible, _interruptible_timeout, and _killable), init_completion(), +* reinit_completion(), and macros DECLARE_COMPLETION(), +* DECLARE_COMPLETION_ONSTACK(). +*/ +struct completion { +unsigned int done; +#ifndef __UBOOT__ +wait_queue_head_t wait; +#endif /* __UBOOT__ */ +}; + +#define init_completion_map (x, m) __init_completion(x) +#define init_completion (x) __init_completion(x) +static inline void complete_acquire (struct completion *x) {} +static inline void complete_release (struct completion *x) {} + +#define COMPLETION_INITIALIZER (work) \ + { 0, __WAIT_QUEUE_HEAD_INITIALIZER((work).wait) } + +#define COMPLETION_INITIALIZER_ONSTACK_MAP (work, map) \ + (*({ init_completion_map(&(work), &(map)); &(work); })) + +#define COMPLETION_INITIALIZER_ONSTACK (work) \ + (*({ init_completion(&work); &work; })) + +/** +* DECLARE_COMPLETION - declare and initialize a completion structure +* @work: identifier for the completion structure +* +* This macro declares and initializes a completion structure. Generally used +* for static declarations. You should use the _ONSTACK variant for automatic +* variables. +*/ +#define DECLARE_COMPLETION (work) \ + struct completion work = COMPLETION_INITIALIZER(work) + +/* +* Lockdep needs to run a non-constant initializer for on-stack +* completions - so we use the _ONSTACK() variant for those that +* are on the kernel stack: +*/ +/** +* DECLARE_COMPLETION_ONSTACK - declare and initialize a completion structure +* @work: identifier for the completion structure +* +* This macro declares and initializes a completion structure on the kernel +* stack. +*/ +#ifdef CONFIG_LOCKDEP +# define DECLARE_COMPLETION_ONSTACK (work) \ + struct completion work = COMPLETION_INITIALIZER_ONSTACK(work) +# define DECLARE_COMPLETION_ONSTACK_MAP (work, map) \ + struct completion work = COMPLETION_INITIALIZER_ONSTACK_MAP(work, map) +#else +# define DECLARE_COMPLETION_ONSTACK (work) DECLARE_COMPLETION(work) +# define DECLARE_COMPLETION_ONSTACK_MAP (work, map) DECLARE_COMPLETION(work) +#endif + +/** +* init_completion - Initialize a dynamically allocated completion +* @x: pointer to completion structure that is to be initialized +* +* This inline function will initialize a dynamically created completion +* structure. +*/ +static inline void __init_completion (struct completion *x) +{ + x->done =0 ; +#ifndef __UBOOT__ +init_waitqueue_head (&x->wait); +#endif /* __UBOOT__ */ +} + +/** +* reinit_completion - reinitialize a completion structure +* @x: pointer to completion structure that is to be reinitialized +* +* This inline function should be used to reinitialize a completion structure so it can +* be reused. This is especially important after complete_all() is used. +*/ +static inline void reinit_completion (struct completion *x) +{ + x->done =0 ; +} + +#ifndef __UBOOT__ +extern void wait_for_completion (struct completion *); +extern void wait_for_completion_io (struct completion *); +extern int wait_for_completion_interruptible (struct completion *x); +extern int wait_for_completion_killable (struct completion *x); +extern unsigned long wait_for_completion_timeout (struct completion *x, +unsigned long timeout); +extern unsigned long wait_for_completion_io_timeout (struct completion *x, +unsigned long timeout); +extern long wait_for_completion_interruptible_timeout ( +struct completion *x,unsigned long timeout); +extern long wait_for_completion_killable_timeout ( +struct completion *x,unsigned long timeout); +extern bool try_wait_for_completion (struct completion *x); +extern bool completion_done (struct completion *x); + +extern void complete (struct completion *); +extern void complete_all (struct completion *); + +#else /* __UBOOT __ */ + +#define wait_for_completion (x) do {} while (0) +#define wait_for_completion_io (x) do {} while (0) + +inline int wait_for_completion_interruptible (struct completion *x) +{ +return 1 ; +} +inline int wait_for_completion_killable (struct completion *x) +{ +return 1 ; +} +inline unsigned long wait_for_completion_timeout (struct completion *x, +unsigned long timeout) +{ +return 1 ; +} +inline unsigned long wait_for_completion_io_timeout (struct completion *x, +unsigned long timeout) +{ +return 1 ; +} +inline long wait_for_completion_interruptible_timeout (struct completion *x, +unsigned long timeout) +{ +return 1 ; +} +inline long wait_for_completion_killable_timeout (struct completion *x, +unsigned long timeout) +{ +return 1 ; +} +inline bool try_wait_for_completion (struct completion *x) +{ +return 1 ; +} +inline bool completion_done (struct completion *x) +{ +return 1 ; +} + +#define complete (x) do {} while (0) +#define complete_all (x) do {} while (0) +#endif /* __UBOOT__ */ + +#endif
Signature · 1 line
2.7.4
PATCH 6/18 compat linux: import completion from linux 4.18
Quoted 5 lines · Philippe Reynes
This patch port the file
include/linux/completion.hfrom linux 4.18 to u-boot. It define the structure but all the function are stubbed.Signed-off-by Philippe Reynes <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190424/5b79fba7/attachment.sig>
PATCH 7/18 drivers: nand: brcmnand: add initial support
In reply to Philippe ReynesThe driver brcmnand come from linux kernel 4.18.
Only SoC bcm6838 and bcm6858 are supported.
--- drivers/mtd/nand/raw/Kconfig | 25 + drivers/mtd/nand/raw/Makefile | 1 + drivers/mtd/nand/raw/brcmnand/Makefile | 7 + drivers/mtd/nand/raw/brcmnand/bcm63158_nand.c | 123 + drivers/mtd/nand/raw/brcmnand/bcm6838_nand.c | 122 + drivers/mtd/nand/raw/brcmnand/bcm6858_nand.c | 123 + drivers/mtd/nand/raw/brcmnand/brcmnand.c | 2789 +++++++++++++++++++++++ drivers/mtd/nand/raw/brcmnand/brcmnand.h | 63 + drivers/mtd/nand/raw/brcmnand/brcmnand_compat.c | 66 + drivers/mtd/nand/raw/brcmnand/brcmnand_compat.h | 15 + 10 files changed, 3334 insertions(+) create mode 100644 drivers/mtd/nand/raw/brcmnand/Makefile create mode 100644 drivers/mtd/nand/raw/brcmnand/bcm63158_nand.c create mode 100644 drivers/mtd/nand/raw/brcmnand/bcm6838_nand.c create mode 100644 drivers/mtd/nand/raw/brcmnand/bcm6858_nand.c create mode 100644 drivers/mtd/nand/raw/brcmnand/brcmnand.c create mode 100644 drivers/mtd/nand/raw/brcmnand/brcmnand.h create mode 100644 drivers/mtd/nand/raw/brcmnand/brcmnand_compat.c create mode 100644 drivers/mtd/nand/raw/brcmnand/brcmnand_compat.h
drivers/mtd/nand/raw/Kconfig +25 -0
@@ -60,6 +60,31 @@ config SPL_GENERATE_ATMEL_PMECC_HEADER endif +config NAND_BRCMNAND + bool "Support Broadcom NAND controller" + depends on OF_CONTROL && DM && MTD + help + Enable the driver for NAND flash on platforms using a Broadcom NAND + controller. + +config NAND_BRCMNAND_6838 + bool "Support Broadcom NAND controller on bcm6838" + depends on NAND_BRCMNAND && ARCH_BMIPS && SOC_BMIPS_BCM6838 + help + Enable support for broadcom nand driver on bcm6838. + +config NAND_BRCMNAND_6858 + bool "Support Broadcom NAND controller on bcm6858" + depends on NAND_BRCMNAND && ARCH_BCM6858 + help + Enable support for broadcom nand driver on bcm6858. + +config NAND_BRCMNAND_63158 + bool "Support Broadcom NAND controller on bcm63158" + depends on NAND_BRCMNAND && ARCH_BCM63158 + help + Enable support for broadcom nand driver on bcm63158. + config NAND_DAVINCI bool "Support TI Davinci NAND controller" help
drivers/mtd/nand/raw/Makefile +1 -0
@@ -41,6 +41,7 @@ obj-$(CONFIG_NAND_ECC_BCH) += nand_bch.o obj-$(CONFIG_NAND_ATMEL) += atmel_nand.o obj-$(CONFIG_NAND_ARASAN) += arasan_nfc.o +obj-$(CONFIG_NAND_BRCMNAND) += brcmnand/ obj-$(CONFIG_NAND_DAVINCI) += davinci_nand.o obj-$(CONFIG_NAND_DENALI) += denali.o obj-$(CONFIG_NAND_DENALI_DT) += denali_dt.o
drivers/mtd/nand/raw/brcmnand/Makefile new file +7 -0
@@ -0,0 +1,7 @@ +# SPDX-License-Identifier: GPL-2.0+ + +obj-$(CONFIG_NAND_BRCMNAND_63158) += bcm63158_nand.o +obj-$(CONFIG_NAND_BRCMNAND_6838) += bcm6838_nand.o +obj-$(CONFIG_NAND_BRCMNAND_6858) += bcm6858_nand.o +obj-$(CONFIG_NAND_BRCMNAND) += brcmnand.o +obj-$(CONFIG_NAND_BRCMNAND) += brcmnand_compat.o
drivers/mtd/nand/raw/brcmnand/bcm63158_nand.c new file +123 -0
123 lines not on this page · raw message
drivers/mtd/nand/raw/brcmnand/bcm6838_nand.c new file +122 -0
122 lines not on this page · raw message
drivers/mtd/nand/raw/brcmnand/bcm6858_nand.c new file +123 -0
123 lines not on this page · raw message
drivers/mtd/nand/raw/brcmnand/brcmnand.c new file +2789 -0
2,587 lines not on this page · raw message
drivers/mtd/nand/raw/brcmnand/brcmnand.h new file +63 -0
63 lines not on this page · raw message
drivers/mtd/nand/raw/brcmnand/brcmnand_compat.c new file +66 -0
66 lines not on this page · raw message
drivers/mtd/nand/raw/brcmnand/brcmnand_compat.h new file +15 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.7.4
Part of the diff is not shown here. View the raw message.
PATCH 7/18 drivers: nand: brcmnand: add initial support
Quoted 4 lines · Philippe Reynes
The driver brcmnand come from linux kernel 4.18.
Only SoC bcm6838 and bcm6858 are supported.Signed-off-by Philippe Reynes <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190424/41b98765/attachment.sig>
PATCH 8/18 drivers: nand: brcmnand: add parameter parameter-page-big-endian
In reply to Philippe ReynesThe parameter page isn't always in big endian, so we add an option to choose the endiannes of the parameter page.
--- drivers/mtd/nand/raw/brcmnand/brcmnand.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-)
drivers/mtd/nand/raw/brcmnand/brcmnand.c +15 -2
@@ -113,6 +113,7 @@ struct brcmnand_controller {unsigned int irq;unsigned int dma_irq;int nand_version; +int parameter_page_big_endian;/* Some SoCs provide custom interrupt status register(s) */ struct brcmnand_soc *soc;
@@ -1439,12 +1440,20 @@ static void brcmnand_cmdfunc(struct mtd_info *mtd, unsigned command,* Must cache the FLASH_CACHE now, since changes in * SECTOR_SIZE_1K may invalidate it */ -for (i =0 ; i <FC_WORDS ; i++) +for (i =0 ; i <FC_WORDS ; i++) { +u32 fc; + + fc =brcmnand_read_fc (ctrl, i); +/* * Flash cache is big endian for parameter pages, at * least on STB SoCs */ - flash_cache[i] =be32_to_cpu (brcmnand_read_fc (ctrl, i)); +if (ctrl->parameter_page_big_endian) + flash_cache[i] =be32_to_cpu (fc); +else + flash_cache[i] =le32_to_cpu (fc); + }brcmnand_soc_data_bus_unprepare (ctrl->soc, true);
@@ -2550,6 +2559,10 @@ int brcmnand_probe(struct udevice *dev, struct brcmnand_soc *soc)nand_hw_control_init (&ctrl->controller);INIT_LIST_HEAD (&ctrl->host_list); +/* Is parameter page in big endian ? */ + ctrl->parameter_page_big_endian = +dev_read_u32_default (dev,"parameter-page-big-endian" ,1 ); +/* NAND register range */ #ifndef __UBOOT__ res =platform_get_resource (pdev,IORESOURCE_MEM ,0 );
Signature · 1 line
2.7.4
PATCH 8/18 drivers: nand: brcmnand: add parameter parameter-page-big-endian
Quoted 4 lines · Philippe Reynes
The parameter page isn't always in big endian, so we add an option to choose the endiannes of the parameter page.
Signed-off-by Philippe Reynes <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190424/2c739a79/attachment.sig>
PATCH 9/18 drivers: nand: brcmnand: add an option to read the write-protect from device tree
In reply to Philippe ReynesThe option write-protect may only change on the kernel command line, we add a property in the device tree to be more flexible.
--- drivers/mtd/nand/raw/brcmnand/brcmnand.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/mtd/nand/raw/brcmnand/brcmnand.c +3 -0
@@ -2671,6 +2671,9 @@ int brcmnand_probe(struct udevice *dev, struct brcmnand_soc *soc)/* Disable XOR addressing */ brcmnand_rmw_reg (ctrl,BRCMNAND_CS_XOR ,0xff ,0 ,0 ); +/* Read the write-protect configuration in the device tree */ + wp_on =dev_read_u32_default (dev,"write-protect" , wp_on); +if (ctrl->features &BRCMNAND_HAS_WP ) {/* Permanently disable write protection */ if (wp_on ==2 )
Signature · 1 line
2.7.4
PATCH 9/18 drivers: nand: brcmnand: add an option to read the write-protect from device tree
Quoted 4 lines · Philippe Reynes
The option write-protect may only change on the kernel command line, we add a property in the device tree to be more flexible.
Signed-off-by Philippe Reynes <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190424/39f6654e/attachment.sig>
PATCH 10/18 dt: bcm6838: add nand controller
In reply to Philippe ReynesAdd the nand controller in the bcm6838 device tree.
--- arch/mips/dts/brcm,bcm6838.dtsi | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/mips/dts/brcm,bcm6838.dtsi +13 -0
@@ -98,5 +98,18 @@ status = "disabled"; }; + + nand: nand-controller at 14e02200 { + #address-cells = <1>; + #size-cells = <0>; + compatible = "brcm,nand-bcm6838", + "brcm,brcmnand-v5.0", + "brcm,brcmnand"; + reg-names = "nand", "nand-int-base", "nand-cache"; + reg = <0x14e02200 0x180>, + <0x14e000f0 0x10>, + <0x14e02600 0x180>; + status = "disabled"; + }; }; };
Signature · 1 line
2.7.4
PATCH 10/18 dt: bcm6838: add nand controller
Quoted 3 lines · Philippe Reynes
Add the nand controller in the bcm6838 device tree.
Signed-off-by Philippe Reynes <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190424/b15c8536/attachment.sig>
PATCH 11/18 dt: bcm968380gerg: enable nand controller
In reply to Philippe ReynesEnable the nand controller in the device tree
of the board bcm96838gerg.
--- arch/mips/dts/brcm,bcm968380gerg.dts | 12 ++++++++++++ 1 file changed, 12 insertions(+)
arch/mips/dts/brcm,bcm968380gerg.dts +12 -0
@@ -38,3 +38,15 @@ label = "bcm968380gerg:green:usb"; }; }; + +&nand { + status = "okay"; + + nandcs at 0 { + compatible = "brcm,nandcs"; + reg = <0>; + nand-ecc-strength = <4>; + nand-ecc-step-size = <512>; + brcm,nand-oob-sector-size = <16>; + }; +};
Signature · 1 line
2.7.4
PATCH 11/18 dt: bcm968380gerg: enable nand controller
Quoted 4 lines · Philippe Reynes
Enable the nand controller in the device tree
of the board bcm96838gerg.Signed-off-by Philippe Reynes <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190424/c7659476/attachment.sig>
PATCH 12/18 bcm968380gerg: add nand support
In reply to Philippe ReynesEnable the nand support (driver and command)
in the configuration of the board bcm96838gerg.
--- configs/bcm968380gerg_ram_defconfig | 7 +++++++ include/configs/broadcom_bcm968380gerg.h | 7 +++++++ 2 files changed, 14 insertions(+)
configs/bcm968380gerg_ram_defconfig +7 -0
@@ -25,6 +25,7 @@ CONFIG_CMD_LICENSE=y CONFIG_CMD_MEMINFO=y # CONFIG_CMD_FLASH is not set # CONFIG_CMD_LOADS is not set +CONFIG_CMD_NAND=y # CONFIG_CMD_MISC is not set CONFIG_DEFAULT_DEVICE_TREE="brcm,bcm968380gerg" # CONFIG_NET is not set
@@ -34,6 +35,12 @@ CONFIG_DM_GPIO=y CONFIG_LED=y CONFIG_LED_BCM6328=y CONFIG_LED_BLINK=y +CONFIG_MTD=y +CONFIG_NAND=y +CONFIG_NAND_BRCMNAND=y +CONFIG_NAND_BRCMNAND_6838=y +CONFIG_SPI_FLASH=y +# CONFIG_SPI_FLASH_USE_4K_SECTORS is not set CONFIG_PHY=y CONFIG_BCM6368_USBH_PHY=y CONFIG_PINCTRL=y
include/configs/broadcom_bcm968380gerg.h +7 -0
@@ -7,3 +7,10 @@#include <configs/bmips_bcm6838.h> #define CONFIG_ENV_SIZE (8 * 1024) + +#ifdef CONFIG_NAND +#define CONFIG_SYS_MAX_NAND_DEVICE 1 +#define CONFIG_SYS_NAND_SELF_INIT +#define CONFIG_SYS_NAND_ONFI_DETECTION +#define CONFIG_SYS_NAND_DRIVER_ECC_LAYOUT +#endif /* CONFIG_NAND */
Signature · 1 line
2.7.4
PATCH 12/18 bcm968380gerg: add nand support
Quoted 4 lines · Philippe Reynes
Enable the nand support (driver and command)
in the configuration of the board bcm96838gerg.Signed-off-by Philippe Reynes <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190424/6006a461/attachment.sig>
PATCH 13/18 dt: bcm6858: add nand controller
In reply to Philippe ReynesAdd the nand controller in the bcm6858 device tree.
--- arch/arm/dts/bcm6858.dtsi | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/arm/dts/bcm6858.dtsi +13 -0
@@ -98,5 +98,18 @@ compatible = "wdt-reboot"; wdt = <&wdt1>; }; + + nand: nand-controller at ff801800 { + compatible = "brcm,nand-bcm6858", + "brcm,brcmnand-v5.0", + "brcm,brcmnand"; + reg-names = "nand", "nand-int-base", "nand-cache"; + reg = <0x0 0xff801800 0x0 0x180>, + <0x0 0xff802000 0x0 0x10>, + <0x0 0xff801c00 0x0 0x200>; + parameter-page-big-endian = <0>; + + status = "disabled"; + }; }; };
Signature · 1 line
2.7.4
PATCH 13/18 dt: bcm6858: add nand controller
Quoted 3 lines · Philippe Reynes
Add the nand controller in the bcm6858 device tree.
Signed-off-by Philippe Reynes <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190424/16ee48d9/attachment.sig>
PATCH 14/18 dt: bcm968580xref: enable nand controller
In reply to Philippe ReynesEnable the nand controller in the device tree
of the board bcm968580xref.
--- arch/arm/dts/bcm968580xref.dts | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
arch/arm/dts/bcm968580xref.dts +15 -0
@@ -29,3 +29,18 @@ u-boot,dm-pre-reloc; status = "okay"; }; + +&nand { + status = "okay"; + write-protect = <0>; + #address-cells = <1>; + #size-cells = <0>; + + nandcs at 0 { + compatible = "brcm,nandcs"; + reg = <0>; + nand-ecc-strength = <4>; + nand-ecc-step-size = <512>; + brcm,nand-oob-sector-size = <16>; + }; +};
Signature · 1 line
2.7.4
PATCH 14/18 dt: bcm968580xref: enable nand controller
Quoted 4 lines · Philippe Reynes
Enable the nand controller in the device tree
of the board bcm968580xref.Signed-off-by Philippe Reynes <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190424/174d05d7/attachment.sig>
PATCH 15/18 bcm968580xref: add nand support
In reply to Philippe ReynesEnable the nand support (driver and command)
in the configuration of the board bcm968580xref.
--- configs/bcm968580xref_ram_defconfig | 7 +++++++ include/configs/broadcom_bcm968580xref.h | 7 +++++++ 2 files changed, 14 insertions(+)
configs/bcm968580xref_ram_defconfig +7 -0
@@ -15,6 +15,9 @@ CONFIG_SUPPORT_RAW_INITRD=y CONFIG_DISPLAY_BOARDINFO_LATE=y CONFIG_HUSH_PARSER=y CONFIG_CMD_BOOTEFI_SELFTEST=y +CONFIG_CMD_MTD=y +CONFIG_CMD_NAND=y +CONFIG_CMD_PART=y CONFIG_DOS_PARTITION=y CONFIG_ISO_PARTITION=y CONFIG_EFI_PARTITION=y
@@ -23,6 +26,10 @@ CONFIG_DEFAULT_DEVICE_TREE="bcm968580xref" CONFIG_BLK=y CONFIG_CLK=y # CONFIG_MMC is not set +CONFIG_MTD=y +CONFIG_NAND=y +CONFIG_NAND_BRCMNAND=y +CONFIG_NAND_BRCMNAND_6858=y CONFIG_SPECIFY_CONSOLE_INDEX=y # CONFIG_SPL_SERIAL_PRESENT is not set CONFIG_CONS_INDEX=0
include/configs/broadcom_bcm968580xref.h +7 -0
@@ -29,6 +29,13 @@#define CONFIG_SKIP_LOWLEVEL_INIT +#ifdef CONFIG_NAND +#define CONFIG_SYS_MAX_NAND_DEVICE 1 +#define CONFIG_SYS_NAND_SELF_INIT +#define CONFIG_SYS_NAND_ONFI_DETECTION +#define CONFIG_SYS_NAND_DRIVER_ECC_LAYOUT +#endif /* CONFIG_NAND */ +/* * 968580xref */
Signature · 1 line
2.7.4
PATCH 15/18 bcm968580xref: add nand support
Quoted 4 lines · Philippe Reynes
Enable the nand support (driver and command)
in the configuration of the board bcm968580xref.Signed-off-by Philippe Reynes <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190424/95c3fc98/attachment.sig>
PATCH 16/18 dt: bcm63158: add nand controller
In reply to Philippe ReynesAdd the nand controller in the bcm63158 device tree.
--- arch/arm/dts/bcm63158.dtsi | 13 +++++++++++++ 1 file changed, 13 insertions(+)
arch/arm/dts/bcm63158.dtsi +13 -0
@@ -98,5 +98,18 @@ compatible = "wdt-reboot"; wdt = <&wdt1>; }; + + nand: nand-controller at ff801800 { + compatible = "brcm,nand-bcm63158", + "brcm,brcmnand-v5.0", + "brcm,brcmnand"; + reg-names = "nand", "nand-int-base", "nand-cache"; + reg = <0x0 0xff801800 0x0 0x180>, + <0x0 0xff802000 0x0 0x10>, + <0x0 0xff801c00 0x0 0x200>; + parameter-page-big-endian = <0>; + + status = "disabled"; + }; }; };
Signature · 1 line
2.7.4
PATCH 16/18 dt: bcm63158: add nand controller
Quoted 3 lines · Philippe Reynes
Add the nand controller in the bcm63158 device tree.
Signed-off-by Philippe Reynes <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190424/bf4d5fdb/attachment.sig>
PATCH 17/18 dt: bcm963158: enable nand controller
In reply to Philippe ReynesEnable the nand controller in the device tree
of the board bcm963158.
--- arch/arm/dts/bcm963158.dts | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
arch/arm/dts/bcm963158.dts +15 -0
@@ -29,3 +29,18 @@ u-boot,dm-pre-reloc; status = "okay"; }; + +&nand { + status = "okay"; + write-protect = <0>; + #address-cells = <1>; + #size-cells = <0>; + + nandcs at 0 { + compatible = "brcm,nandcs"; + reg = <0>; + nand-ecc-strength = <4>; + nand-ecc-step-size = <512>; + brcm,nand-oob-sector-size = <16>; + }; +};
Signature · 1 line
2.7.4
PATCH 17/18 dt: bcm963158: enable nand controller
Quoted 4 lines · Philippe Reynes
Enable the nand controller in the device tree
of the board bcm963158.Signed-off-by Philippe Reynes <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190424/e1e81c9e/attachment.sig>
PATCH 18/18 bcm963158: add nand support
In reply to Philippe ReynesEnable the nand support (driver and command)
in the configuration of the board bcm963158.
--- configs/bcm963158_ram_defconfig | 6 ++++++ include/configs/broadcom_bcm963158.h | 7 +++++++ 2 files changed, 13 insertions(+)
configs/bcm963158_ram_defconfig +6 -0
@@ -20,6 +20,8 @@ CONFIG_CMD_BOOTEFI_SELFTEST=y # CONFIG_CMD_LZMADEC is not set # CONFIG_CMD_UNZIP is not set # CONFIG_CMD_FLASH is not set +CONFIG_CMD_MTD=y +CONFIG_CMD_NAND=y CONFIG_CMD_CACHE=y CONFIG_DOS_PARTITION=y CONFIG_ISO_PARTITION=y
@@ -29,6 +31,10 @@ CONFIG_DEFAULT_DEVICE_TREE="bcm963158" CONFIG_BLK=y CONFIG_CLK=y # CONFIG_MMC is not set +CONFIG_MTD=y +CONFIG_NAND=y +CONFIG_NAND_BRCMNAND=y +CONFIG_NAND_BRCMNAND_63158=y CONFIG_SPECIFY_CONSOLE_INDEX=y # CONFIG_SPL_SERIAL_PRESENT is not set CONFIG_CONS_INDEX=0
include/configs/broadcom_bcm963158.h +7 -0
@@ -30,6 +30,13 @@#define CONFIG_SKIP_LOWLEVEL_INIT +#ifdef CONFIG_NAND +#define CONFIG_SYS_MAX_NAND_DEVICE 1 +#define CONFIG_SYS_NAND_SELF_INIT +#define CONFIG_SYS_NAND_ONFI_DETECTION +#define CONFIG_SYS_NAND_DRIVER_ECC_LAYOUT +#endif /* CONFIG_NAND */ +/* * bcm963158 */
Signature · 1 line
2.7.4
PATCH 18/18 bcm963158: add nand support
Quoted 4 lines · Philippe Reynes
Enable the nand support (driver and command)
in the configuration of the board bcm963158.Signed-off-by Philippe Reynes <[email protected]>
Applied to u-boot/master, thanks!
Signature · 8 lines
Tom -------------- next part -------------- A non-text attachment was scrubbed... Name: signature.asc Type: application/pgp-signature Size: 819 bytes Desc: not available URL: <http://lists.denx.de/pipermail/u-boot/attachments/20190424/2ced81b1/attachment.sig>