Skip to content

Commit b21ff82

Browse files
masahir0yBoris Brezillon
authored andcommitted
mtd: nand: denali: set NAND_ECC_CUSTOM_PAGE_ACCESS
The denali_cmdfunc() actually does nothing valuable for NAND_CMD_{PAGEPROG,READ0,SEQIN}. For NAND_CMD_{READ0,SEQIN}, it copies "page" to "denali->page", then denali_read_page(_raw) compares them just for the sanity check. (Inconsistently, this check is missing from denali_write_page(_raw).) The Denali controller is equipped with high level read/write interface, so let's skip unneeded call of cmdfunc(). If NAND_ECC_CUSTOM_PAGE_ACCESS is set, nand_write_page() will not call ->waitfunc hook. So, ->write_page(_raw) hooks should directly return -EIO on failure. The error handling of page writes will be much simpler. Signed-off-by: Masahiro Yamada <[email protected]> Signed-off-by: Boris Brezillon <[email protected]>
1 parent d690694 commit b21ff82

File tree

2 files changed

+12
-30
lines changed

2 files changed

+12
-30
lines changed

drivers/mtd/nand/denali.c

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -998,13 +998,16 @@ static void denali_setup_dma(struct denali_nand_info *denali, int op)
998998
* configuration details.
999999
*/
10001000
static int write_page(struct mtd_info *mtd, struct nand_chip *chip,
1001-
const uint8_t *buf, bool raw_xfer)
1001+
const uint8_t *buf, int page, bool raw_xfer)
10021002
{
10031003
struct denali_nand_info *denali = mtd_to_denali(mtd);
10041004
dma_addr_t addr = denali->buf.dma_buf;
10051005
size_t size = mtd->writesize + mtd->oobsize;
10061006
uint32_t irq_status;
10071007
uint32_t irq_mask = INTR__DMA_CMD_COMP | INTR__PROGRAM_FAIL;
1008+
int ret = 0;
1009+
1010+
denali->page = page;
10081011

10091012
/*
10101013
* if it is a raw xfer, we want to disable ecc and send the spare area.
@@ -1036,13 +1039,13 @@ static int write_page(struct mtd_info *mtd, struct nand_chip *chip,
10361039
if (irq_status == 0) {
10371040
dev_err(denali->dev, "timeout on write_page (type = %d)\n",
10381041
raw_xfer);
1039-
denali->status = NAND_STATUS_FAIL;
1042+
ret = -EIO;
10401043
}
10411044

10421045
denali_enable_dma(denali, false);
10431046
dma_sync_single_for_cpu(denali->dev, addr, size, DMA_TO_DEVICE);
10441047

1045-
return 0;
1048+
return ret;
10461049
}
10471050

10481051
/* NAND core entry points */
@@ -1059,7 +1062,7 @@ static int denali_write_page(struct mtd_info *mtd, struct nand_chip *chip,
10591062
* for regular page writes, we let HW handle all the ECC
10601063
* data written to the device.
10611064
*/
1062-
return write_page(mtd, chip, buf, false);
1065+
return write_page(mtd, chip, buf, page, false);
10631066
}
10641067

10651068
/*
@@ -1075,7 +1078,7 @@ static int denali_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
10751078
* for raw page writes, we want to disable ECC and simply write
10761079
* whatever data is in the buffer.
10771080
*/
1078-
return write_page(mtd, chip, buf, true);
1081+
return write_page(mtd, chip, buf, page, true);
10791082
}
10801083

10811084
static int denali_write_oob(struct mtd_info *mtd, struct nand_chip *chip,
@@ -1105,12 +1108,7 @@ static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip,
11051108
unsigned long uncor_ecc_flags = 0;
11061109
int stat = 0;
11071110

1108-
if (page != denali->page) {
1109-
dev_err(denali->dev,
1110-
"IN %s: page %d is not equal to denali->page %d",
1111-
__func__, page, denali->page);
1112-
BUG();
1113-
}
1111+
denali->page = page;
11141112

11151113
setup_ecc_for_xfer(denali, true, false);
11161114

@@ -1154,12 +1152,7 @@ static int denali_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
11541152
size_t size = mtd->writesize + mtd->oobsize;
11551153
uint32_t irq_mask = INTR__DMA_CMD_COMP;
11561154

1157-
if (page != denali->page) {
1158-
dev_err(denali->dev,
1159-
"IN %s: page %d is not equal to denali->page %d",
1160-
__func__, page, denali->page);
1161-
BUG();
1162-
}
1155+
denali->page = page;
11631156

11641157
setup_ecc_for_xfer(denali, false, true);
11651158
denali_enable_dma(denali, true);
@@ -1204,12 +1197,7 @@ static void denali_select_chip(struct mtd_info *mtd, int chip)
12041197

12051198
static int denali_waitfunc(struct mtd_info *mtd, struct nand_chip *chip)
12061199
{
1207-
struct denali_nand_info *denali = mtd_to_denali(mtd);
1208-
int status = denali->status;
1209-
1210-
denali->status = 0;
1211-
1212-
return status;
1200+
return 0;
12131201
}
12141202

12151203
static int denali_erase(struct mtd_info *mtd, int page)
@@ -1238,8 +1226,6 @@ static void denali_cmdfunc(struct mtd_info *mtd, unsigned int cmd, int col,
12381226
int i;
12391227

12401228
switch (cmd) {
1241-
case NAND_CMD_PAGEPROG:
1242-
break;
12431229
case NAND_CMD_STATUS:
12441230
read_status(denali);
12451231
break;
@@ -1259,10 +1245,6 @@ static void denali_cmdfunc(struct mtd_info *mtd, unsigned int cmd, int col,
12591245
write_byte_to_buf(denali, id);
12601246
}
12611247
break;
1262-
case NAND_CMD_READ0:
1263-
case NAND_CMD_SEQIN:
1264-
denali->page = page;
1265-
break;
12661248
case NAND_CMD_RESET:
12671249
reset_bank(denali);
12681250
break;
@@ -1605,6 +1587,7 @@ int denali_init(struct denali_nand_info *denali)
16051587

16061588
mtd_set_ooblayout(mtd, &denali_ooblayout_ops);
16071589

1590+
chip->ecc.options |= NAND_ECC_CUSTOM_PAGE_ACCESS;
16081591
chip->ecc.read_page = denali_read_page;
16091592
chip->ecc.read_page_raw = denali_read_page_raw;
16101593
chip->ecc.write_page = denali_write_page;

drivers/mtd/nand/denali.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -323,7 +323,6 @@ struct nand_buf {
323323
struct denali_nand_info {
324324
struct nand_chip nand;
325325
int flash_bank; /* currently selected chip */
326-
int status;
327326
int platform;
328327
struct nand_buf buf;
329328
struct device *dev;

0 commit comments

Comments
 (0)