Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mtd: nand: refactor erase_cmd() to return chip status

The nand_chip::erase_cmd callback previously served a dual purpose; for
one, it allowed a per-flash-chip override, so that AG-AND devices could
use a different erase command than other NAND. These AND devices were
dropped in commit 14c6578683367b1e7af0c3c09e872b45a45183a7 (mtd: nand:
remove AG-AND support). On the other hand, some drivers (denali and
doc-g4) need to use this sort of callback to implement
controller-specific erase operations.

To make the latter operation easier for some drivers (e.g., ST's new BCH
NAND driver), it helps if the command dispatch and wait functions can be
lumped together, rather than called separately.

This patch does two things:
1. Pull the call to chip->waitfunc() into chip->erase_cmd(), and return
the status from this callback
2. Rename erase_cmd() to just erase(), since this callback does a
little more than just send a command

Signed-off-by: Brian Norris <computersforpeace@gmail.com>
Tested-by: Lee Jones <lee.jones@linaro.org>

+16 -16
+3 -4
drivers/mtd/nand/denali.c
··· 1233 1233 return status; 1234 1234 } 1235 1235 1236 - static void denali_erase(struct mtd_info *mtd, int page) 1236 + static int denali_erase(struct mtd_info *mtd, int page) 1237 1237 { 1238 1238 struct denali_nand_info *denali = mtd_to_denali(mtd); 1239 1239 ··· 1250 1250 irq_status = wait_for_irq(denali, INTR_STATUS__ERASE_COMP | 1251 1251 INTR_STATUS__ERASE_FAIL); 1252 1252 1253 - denali->status = (irq_status & INTR_STATUS__ERASE_FAIL) ? 1254 - NAND_STATUS_FAIL : PASS; 1253 + return (irq_status & INTR_STATUS__ERASE_FAIL) ? NAND_STATUS_FAIL : PASS; 1255 1254 } 1256 1255 1257 1256 static void denali_cmdfunc(struct mtd_info *mtd, unsigned int cmd, int col, ··· 1583 1584 denali->nand.ecc.write_page_raw = denali_write_page_raw; 1584 1585 denali->nand.ecc.read_oob = denali_read_oob; 1585 1586 denali->nand.ecc.write_oob = denali_write_oob; 1586 - denali->nand.erase_cmd = denali_erase; 1587 + denali->nand.erase = denali_erase; 1587 1588 1588 1589 if (nand_scan_tail(&denali->mtd)) { 1589 1590 ret = -ENXIO;
+4 -2
drivers/mtd/nand/docg4.c
··· 872 872 return 0; 873 873 } 874 874 875 - static void docg4_erase_block(struct mtd_info *mtd, int page) 875 + static int docg4_erase_block(struct mtd_info *mtd, int page) 876 876 { 877 877 struct nand_chip *nand = mtd->priv; 878 878 struct docg4_priv *doc = nand->priv; ··· 916 916 write_nop(docptr); 917 917 poll_status(doc); 918 918 write_nop(docptr); 919 + 920 + return nand->waitfunc(mtd, nand); 919 921 } 920 922 921 923 static int write_page(struct mtd_info *mtd, struct nand_chip *nand, ··· 1238 1236 nand->block_markbad = docg4_block_markbad; 1239 1237 nand->read_buf = docg4_read_buf; 1240 1238 nand->write_buf = docg4_write_buf16; 1241 - nand->erase_cmd = docg4_erase_block; 1239 + nand->erase = docg4_erase_block; 1242 1240 nand->ecc.read_page = docg4_read_page; 1243 1241 nand->ecc.write_page = docg4_write_page; 1244 1242 nand->ecc.read_page_raw = docg4_read_page_raw;
+7 -7
drivers/mtd/nand/nand_base.c
··· 2617 2617 } 2618 2618 2619 2619 /** 2620 - * single_erase_cmd - [GENERIC] NAND standard block erase command function 2620 + * single_erase - [GENERIC] NAND standard block erase command function 2621 2621 * @mtd: MTD device structure 2622 2622 * @page: the page address of the block which will be erased 2623 2623 * 2624 - * Standard erase command for NAND chips. 2624 + * Standard erase command for NAND chips. Returns NAND status. 2625 2625 */ 2626 - static void single_erase_cmd(struct mtd_info *mtd, int page) 2626 + static int single_erase(struct mtd_info *mtd, int page) 2627 2627 { 2628 2628 struct nand_chip *chip = mtd->priv; 2629 2629 /* Send commands to erase a block */ 2630 2630 chip->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page); 2631 2631 chip->cmdfunc(mtd, NAND_CMD_ERASE2, -1, -1); 2632 + 2633 + return chip->waitfunc(mtd, chip); 2632 2634 } 2633 2635 2634 2636 /** ··· 2711 2709 (page + pages_per_block)) 2712 2710 chip->pagebuf = -1; 2713 2711 2714 - chip->erase_cmd(mtd, page & chip->pagemask); 2715 - 2716 - status = chip->waitfunc(mtd, chip); 2712 + status = chip->erase(mtd, page & chip->pagemask); 2717 2713 2718 2714 /* 2719 2715 * See if operation failed and additional status checks are ··· 3684 3684 } 3685 3685 3686 3686 chip->badblockbits = 8; 3687 - chip->erase_cmd = single_erase_cmd; 3687 + chip->erase = single_erase; 3688 3688 3689 3689 /* Do not replace user supplied command function! */ 3690 3690 if (mtd->writesize > 512 && chip->cmdfunc == nand_command)
+2 -3
include/linux/mtd/nand.h
··· 552 552 * @ecc: [BOARDSPECIFIC] ECC control structure 553 553 * @buffers: buffer structure for read/write 554 554 * @hwcontrol: platform-specific hardware control structure 555 - * @erase_cmd: [INTERN] erase command write function, selectable due 556 - * to AND support. 555 + * @erase: [REPLACEABLE] erase function 557 556 * @scan_bbt: [REPLACEABLE] function to scan bad block table 558 557 * @chip_delay: [BOARDSPECIFIC] chip dependent delay for transferring 559 558 * data from array to read regs (tR). ··· 636 637 void (*cmdfunc)(struct mtd_info *mtd, unsigned command, int column, 637 638 int page_addr); 638 639 int(*waitfunc)(struct mtd_info *mtd, struct nand_chip *this); 639 - void (*erase_cmd)(struct mtd_info *mtd, int page); 640 + int (*erase)(struct mtd_info *mtd, int page); 640 641 int (*scan_bbt)(struct mtd_info *mtd); 641 642 int (*errstat)(struct mtd_info *mtd, struct nand_chip *this, int state, 642 643 int status, int page);