提交 f75e5097 编写于 作者: T Thomas Gleixner

[MTD] NAND modularize write function

Modularize the write function and reorganaize the internal buffer
management. Remove obsolete chip options and fixup all affected
users.
Signed-off-by: NThomas Gleixner <tglx@linutronix.de>
上级 e4d222ff
...@@ -1666,7 +1666,7 @@ static int __init doc_probe(unsigned long physadr) ...@@ -1666,7 +1666,7 @@ static int __init doc_probe(unsigned long physadr)
nand->ecc.mode = NAND_ECC_HW_SYNDROME; nand->ecc.mode = NAND_ECC_HW_SYNDROME;
nand->ecc.size = 512; nand->ecc.size = 512;
nand->ecc.bytes = 6; nand->ecc.bytes = 6;
nand->options = NAND_USE_FLASH_BBT | NAND_HWECC_SYNDROME; nand->options = NAND_USE_FLASH_BBT;
doc->physadr = physadr; doc->physadr = physadr;
doc->virtadr = virtadr; doc->virtadr = virtadr;
......
...@@ -198,9 +198,6 @@ static void __exit ep7312_cleanup(void) ...@@ -198,9 +198,6 @@ static void __exit ep7312_cleanup(void)
/* Release resources, unregister device */ /* Release resources, unregister device */
nand_release(ap7312_mtd); nand_release(ap7312_mtd);
/* Free internal data buffer */
kfree(this->data_buf);
/* Free the MTD device structure */ /* Free the MTD device structure */
kfree(ep7312_mtd); kfree(ep7312_mtd);
} }
......
此差异已折叠。
...@@ -666,7 +666,7 @@ static inline int nand_memory_bbt(struct mtd_info *mtd, struct nand_bbt_descr *b ...@@ -666,7 +666,7 @@ static inline int nand_memory_bbt(struct mtd_info *mtd, struct nand_bbt_descr *b
struct nand_chip *this = mtd->priv; struct nand_chip *this = mtd->priv;
bd->options &= ~NAND_BBT_SCANEMPTY; bd->options &= ~NAND_BBT_SCANEMPTY;
return create_bbt(mtd, this->data_buf, bd, -1); return create_bbt(mtd, this->buffers.databuf, bd, -1);
} }
/** /**
......
...@@ -571,7 +571,6 @@ static int __init rtc_from4_init(void) ...@@ -571,7 +571,6 @@ static int __init rtc_from4_init(void)
this->ecc.mode = NAND_ECC_HW_SYNDROME; this->ecc.mode = NAND_ECC_HW_SYNDROME;
this->ecc.size = 512; this->ecc.size = 512;
this->ecc.bytes = 8; this->ecc.bytes = 8;
this->options |= NAND_HWECC_SYNDROME;
/* return the status of extra status and ECC checks */ /* return the status of extra status and ECC checks */
this->errstat = rtc_from4_errstat; this->errstat = rtc_from4_errstat;
/* set the nand_oobinfo to support FPGA H/W error detection */ /* set the nand_oobinfo to support FPGA H/W error detection */
......
...@@ -175,8 +175,6 @@ static int __init toto_init(void) ...@@ -175,8 +175,6 @@ static int __init toto_init(void)
goto out; goto out;
out_buf:
kfree(this->data_buf);
out_mtd: out_mtd:
kfree(toto_mtd); kfree(toto_mtd);
out: out:
......
...@@ -37,7 +37,7 @@ extern int nand_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t from, ...@@ -37,7 +37,7 @@ extern int nand_read_raw (struct mtd_info *mtd, uint8_t *buf, loff_t from,
extern int nand_write_raw(struct mtd_info *mtd, loff_t to, size_t len, extern int nand_write_raw(struct mtd_info *mtd, loff_t to, size_t len,
size_t *retlen, uint8_t *buf, uint8_t *oob); size_t *retlen, const uint8_t *buf, uint8_t *oob);
/* The maximum number of NAND chips in an array */ /* The maximum number of NAND chips in an array */
#define NAND_MAX_CHIPS 8 #define NAND_MAX_CHIPS 8
...@@ -47,6 +47,7 @@ extern int nand_write_raw(struct mtd_info *mtd, loff_t to, size_t len, ...@@ -47,6 +47,7 @@ extern int nand_write_raw(struct mtd_info *mtd, loff_t to, size_t len,
* adjust this accordingly. * adjust this accordingly.
*/ */
#define NAND_MAX_OOBSIZE 64 #define NAND_MAX_OOBSIZE 64
#define NAND_MAX_PAGESIZE 2048
/* /*
* Constants for hardware specific CLE/ALE/NCE function * Constants for hardware specific CLE/ALE/NCE function
...@@ -181,20 +182,12 @@ typedef enum { ...@@ -181,20 +182,12 @@ typedef enum {
/* Use a flash based bad block table. This option is passed to the /* Use a flash based bad block table. This option is passed to the
* default bad block table function. */ * default bad block table function. */
#define NAND_USE_FLASH_BBT 0x00010000 #define NAND_USE_FLASH_BBT 0x00010000
/* The hw ecc generator provides a syndrome instead a ecc value on read
* This can only work if we have the ecc bytes directly behind the
* data bytes. Applies for DOC and AG-AND Renesas HW Reed Solomon generators */
#define NAND_HWECC_SYNDROME 0x00020000
/* This option skips the bbt scan during initialization. */ /* This option skips the bbt scan during initialization. */
#define NAND_SKIP_BBTSCAN 0x00040000 #define NAND_SKIP_BBTSCAN 0x00020000
/* Options set by nand scan */ /* Options set by nand scan */
/* Nand scan has allocated controller struct */ /* Nand scan has allocated controller struct */
#define NAND_CONTROLLER_ALLOC 0x20000000 #define NAND_CONTROLLER_ALLOC 0x80000000
/* Nand scan has allocated oob_buf */
#define NAND_OOBBUF_ALLOC 0x40000000
/* Nand scan has allocated data_buf */
#define NAND_DATABUF_ALLOC 0x80000000
/* /*
...@@ -240,6 +233,7 @@ struct nand_hw_control { ...@@ -240,6 +233,7 @@ struct nand_hw_control {
* be provided if an hardware ECC is available * be provided if an hardware ECC is available
* @calculate: function for ecc calculation or readback from ecc hardware * @calculate: function for ecc calculation or readback from ecc hardware
* @correct: function for ecc correction, matching to ecc generator (sw/hw) * @correct: function for ecc correction, matching to ecc generator (sw/hw)
* @read_page: function to read a page according to the ecc generator requirements
* @write_page: function to write a page according to the ecc generator requirements * @write_page: function to write a page according to the ecc generator requirements
*/ */
struct nand_ecc_ctrl { struct nand_ecc_ctrl {
...@@ -260,9 +254,28 @@ struct nand_ecc_ctrl { ...@@ -260,9 +254,28 @@ struct nand_ecc_ctrl {
int (*read_page)(struct mtd_info *mtd, int (*read_page)(struct mtd_info *mtd,
struct nand_chip *chip, struct nand_chip *chip,
uint8_t *buf); uint8_t *buf);
int (*write_page)(struct mtd_info *mtd, void (*write_page)(struct mtd_info *mtd,
struct nand_chip *chip, struct nand_chip *chip,
uint8_t *buf, int cached); const uint8_t *buf);
};
/**
* struct nand_buffers - buffer structure for read/write
* @ecccalc: buffer for calculated ecc
* @ecccode: buffer for ecc read from flash
* @oobwbuf: buffer for write oob data
* @databuf: buffer for data - dynamically sized
* @oobrbuf: buffer to read oob data
*
* Do not change the order of buffers. databuf and oobrbuf must be in
* consecutive order.
*/
struct nand_buffers {
uint8_t ecccalc[NAND_MAX_OOBSIZE];
uint8_t ecccode[NAND_MAX_OOBSIZE];
uint8_t oobwbuf[NAND_MAX_OOBSIZE];
uint8_t databuf[NAND_MAX_PAGESIZE];
uint8_t oobrbuf[NAND_MAX_OOBSIZE];
}; };
/** /**
...@@ -294,8 +307,8 @@ struct nand_ecc_ctrl { ...@@ -294,8 +307,8 @@ struct nand_ecc_ctrl {
* @phys_erase_shift: [INTERN] number of address bits in a physical eraseblock * @phys_erase_shift: [INTERN] number of address bits in a physical eraseblock
* @bbt_erase_shift: [INTERN] number of address bits in a bbt entry * @bbt_erase_shift: [INTERN] number of address bits in a bbt entry
* @chip_shift: [INTERN] number of address bits in one chip * @chip_shift: [INTERN] number of address bits in one chip
* @data_buf: [INTERN] internal buffer for one page + oob * @datbuf: [INTERN] internal buffer for one page + oob
* @oob_buf: [INTERN] oob buffer for one eraseblock * @oobbuf: [INTERN] oob buffer for one eraseblock
* @oobdirty: [INTERN] indicates that oob_buf must be reinitialized * @oobdirty: [INTERN] indicates that oob_buf must be reinitialized
* @data_poi: [INTERN] pointer to a data buffer * @data_poi: [INTERN] pointer to a data buffer
* @options: [BOARDSPECIFIC] various chip options. They can partly be set to inform nand_scan about * @options: [BOARDSPECIFIC] various chip options. They can partly be set to inform nand_scan about
...@@ -336,32 +349,38 @@ struct nand_chip { ...@@ -336,32 +349,38 @@ struct nand_chip {
int (*waitfunc)(struct mtd_info *mtd, struct nand_chip *this, int state); int (*waitfunc)(struct mtd_info *mtd, struct nand_chip *this, int state);
void (*erase_cmd)(struct mtd_info *mtd, int page); void (*erase_cmd)(struct mtd_info *mtd, int page);
int (*scan_bbt)(struct mtd_info *mtd); int (*scan_bbt)(struct mtd_info *mtd);
struct nand_ecc_ctrl ecc; int (*errstat)(struct mtd_info *mtd, struct nand_chip *this, int state, int status, int page);
int chip_delay; int chip_delay;
wait_queue_head_t wq; unsigned int options;
nand_state_t state;
int page_shift; int page_shift;
int phys_erase_shift; int phys_erase_shift;
int bbt_erase_shift; int bbt_erase_shift;
int chip_shift; int chip_shift;
uint8_t *data_buf;
uint8_t *oob_buf;
int oobdirty;
uint8_t *data_poi;
unsigned int options;
int badblockpos;
int numchips; int numchips;
unsigned long chipsize; unsigned long chipsize;
int pagemask; int pagemask;
int pagebuf; int pagebuf;
int badblockpos;
nand_state_t state;
uint8_t *oob_poi;
struct nand_hw_control *controller;
struct nand_oobinfo *autooob; struct nand_oobinfo *autooob;
struct nand_ecc_ctrl ecc;
struct nand_buffers buffers;
struct nand_hw_control hwcontrol;
uint8_t *bbt; uint8_t *bbt;
struct nand_bbt_descr *bbt_td; struct nand_bbt_descr *bbt_td;
struct nand_bbt_descr *bbt_md; struct nand_bbt_descr *bbt_md;
struct nand_bbt_descr *badblock_pattern; struct nand_bbt_descr *badblock_pattern;
struct nand_hw_control *controller;
void *priv; void *priv;
int (*errstat)(struct mtd_info *mtd, struct nand_chip *this, int state, int status, int page);
}; };
/* /*
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册