Skip to content

Commit 97d90da

Browse files
author
Boris Brezillon
committed
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. Signed-off-by: Boris Brezillon <[email protected]> [[email protected]: rebased and fixed some conflicts] Signed-off-by: Miquel Raynal <[email protected]> Acked-by: Masahiro Yamada <[email protected]>
1 parent eb94555 commit 97d90da

24 files changed

+1131
-431
lines changed

drivers/mtd/nand/atmel/nand-controller.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1000,7 +1000,7 @@ static int atmel_hsmc_nand_pmecc_read_pg(struct nand_chip *chip, u8 *buf,
10001000
* to the non-optimized one.
10011001
*/
10021002
if (nand->activecs->rb.type != ATMEL_NAND_NATIVE_RB) {
1003-
chip->cmdfunc(mtd, NAND_CMD_READ0, 0x00, page);
1003+
nand_read_page_op(chip, page, 0, NULL, 0);
10041004

10051005
return atmel_nand_pmecc_read_pg(chip, buf, oob_required, page,
10061006
raw);

drivers/mtd/nand/brcmnand/brcmnand.c

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1071,7 +1071,7 @@ static void brcmnand_wp(struct mtd_info *mtd, int wp)
10711071
return;
10721072

10731073
brcmnand_set_wp(ctrl, wp);
1074-
chip->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1);
1074+
nand_status_op(chip, NULL);
10751075
/* NAND_STATUS_WP 0x00 = protected, 0x80 = not protected */
10761076
ret = bcmnand_ctrl_poll_status(ctrl,
10771077
NAND_CTRL_RDY |
@@ -1453,7 +1453,7 @@ static uint8_t brcmnand_read_byte(struct mtd_info *mtd)
14531453

14541454
/* At FC_BYTES boundary, switch to next column */
14551455
if (host->last_byte > 0 && offs == 0)
1456-
chip->cmdfunc(mtd, NAND_CMD_RNDOUT, addr, -1);
1456+
nand_change_read_column_op(chip, addr, NULL, 0, false);
14571457

14581458
ret = ctrl->flash_cache[offs];
14591459
break;
@@ -1689,7 +1689,7 @@ static int brcmstb_nand_verify_erased_page(struct mtd_info *mtd,
16891689
sas = mtd->oobsize / chip->ecc.steps;
16901690

16911691
/* read without ecc for verification */
1692-
chip->cmdfunc(mtd, NAND_CMD_READ0, 0x00, page);
1692+
nand_read_page_op(chip, page, 0, NULL, 0);
16931693
ret = chip->ecc.read_page_raw(mtd, chip, buf, true, page);
16941694
if (ret)
16951695
return ret;
@@ -2369,12 +2369,11 @@ static int brcmnand_resume(struct device *dev)
23692369

23702370
list_for_each_entry(host, &ctrl->host_list, node) {
23712371
struct nand_chip *chip = &host->chip;
2372-
struct mtd_info *mtd = nand_to_mtd(chip);
23732372

23742373
brcmnand_save_restore_cs_config(host, 1);
23752374

23762375
/* Reset the chip, required by some chips after power-up */
2377-
chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
2376+
nand_reset_op(chip);
23782377
}
23792378

23802379
return 0;

drivers/mtd/nand/cafe_nand.c

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -353,23 +353,15 @@ static void cafe_nand_bug(struct mtd_info *mtd)
353353
static int cafe_nand_write_oob(struct mtd_info *mtd,
354354
struct nand_chip *chip, int page)
355355
{
356-
int status = 0;
357-
358-
chip->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->writesize, page);
359-
chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
360-
chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
361-
status = chip->waitfunc(mtd, chip);
362-
363-
return status & NAND_STATUS_FAIL ? -EIO : 0;
356+
return nand_prog_page_op(chip, page, mtd->writesize, chip->oob_poi,
357+
mtd->oobsize);
364358
}
365359

366360
/* Don't use -- use nand_read_oob_std for now */
367361
static int cafe_nand_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
368362
int page)
369363
{
370-
chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page);
371-
chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
372-
return 0;
364+
return nand_read_oob_op(chip, page, 0, chip->oob_poi, mtd->oobsize);
373365
}
374366
/**
375367
* cafe_nand_read_page_syndrome - [REPLACEABLE] hardware ecc syndrome based page read

drivers/mtd/nand/denali.c

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -645,8 +645,6 @@ static void denali_oob_xfer(struct mtd_info *mtd, struct nand_chip *chip,
645645
int page, int write)
646646
{
647647
struct denali_nand_info *denali = mtd_to_denali(mtd);
648-
unsigned int start_cmd = write ? NAND_CMD_SEQIN : NAND_CMD_READ0;
649-
unsigned int rnd_cmd = write ? NAND_CMD_RNDIN : NAND_CMD_RNDOUT;
650648
int writesize = mtd->writesize;
651649
int oobsize = mtd->oobsize;
652650
uint8_t *bufpoi = chip->oob_poi;
@@ -658,11 +656,11 @@ static void denali_oob_xfer(struct mtd_info *mtd, struct nand_chip *chip,
658656
int i, pos, len;
659657

660658
/* BBM at the beginning of the OOB area */
661-
chip->cmdfunc(mtd, start_cmd, writesize, page);
662659
if (write)
663-
chip->write_buf(mtd, bufpoi, oob_skip);
660+
nand_prog_page_begin_op(chip, page, writesize, bufpoi,
661+
oob_skip);
664662
else
665-
chip->read_buf(mtd, bufpoi, oob_skip);
663+
nand_read_page_op(chip, page, writesize, bufpoi, oob_skip);
666664
bufpoi += oob_skip;
667665

668666
/* OOB ECC */
@@ -675,30 +673,35 @@ static void denali_oob_xfer(struct mtd_info *mtd, struct nand_chip *chip,
675673
else if (pos + len > writesize)
676674
len = writesize - pos;
677675

678-
chip->cmdfunc(mtd, rnd_cmd, pos, -1);
679676
if (write)
680-
chip->write_buf(mtd, bufpoi, len);
677+
nand_change_write_column_op(chip, pos, bufpoi, len,
678+
false);
681679
else
682-
chip->read_buf(mtd, bufpoi, len);
680+
nand_change_read_column_op(chip, pos, bufpoi, len,
681+
false);
683682
bufpoi += len;
684683
if (len < ecc_bytes) {
685684
len = ecc_bytes - len;
686-
chip->cmdfunc(mtd, rnd_cmd, writesize + oob_skip, -1);
687685
if (write)
688-
chip->write_buf(mtd, bufpoi, len);
686+
nand_change_write_column_op(chip, writesize +
687+
oob_skip, bufpoi,
688+
len, false);
689689
else
690-
chip->read_buf(mtd, bufpoi, len);
690+
nand_change_read_column_op(chip, writesize +
691+
oob_skip, bufpoi,
692+
len, false);
691693
bufpoi += len;
692694
}
693695
}
694696

695697
/* OOB free */
696698
len = oobsize - (bufpoi - chip->oob_poi);
697-
chip->cmdfunc(mtd, rnd_cmd, size - len, -1);
698699
if (write)
699-
chip->write_buf(mtd, bufpoi, len);
700+
nand_change_write_column_op(chip, size - len, bufpoi, len,
701+
false);
700702
else
701-
chip->read_buf(mtd, bufpoi, len);
703+
nand_change_read_column_op(chip, size - len, bufpoi, len,
704+
false);
702705
}
703706

704707
static int denali_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip,
@@ -788,16 +791,12 @@ static int denali_write_oob(struct mtd_info *mtd, struct nand_chip *chip,
788791
int page)
789792
{
790793
struct denali_nand_info *denali = mtd_to_denali(mtd);
791-
int status;
792794

793795
denali_reset_irq(denali);
794796

795797
denali_oob_xfer(mtd, chip, page, 1);
796798

797-
chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
798-
status = chip->waitfunc(mtd, chip);
799-
800-
return status & NAND_STATUS_FAIL ? -EIO : 0;
799+
return nand_prog_page_end_op(chip);
801800
}
802801

803802
static int denali_read_page(struct mtd_info *mtd, struct nand_chip *chip,

drivers/mtd/nand/diskonchip.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ static int doc200x_wait(struct mtd_info *mtd, struct nand_chip *this)
448448
int status;
449449

450450
DoC_WaitReady(doc);
451-
this->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1);
451+
nand_status_op(this, NULL);
452452
DoC_WaitReady(doc);
453453
status = (int)this->read_byte(mtd);
454454

@@ -595,7 +595,7 @@ static void doc2001plus_select_chip(struct mtd_info *mtd, int chip)
595595

596596
/* Assert ChipEnable and deassert WriteProtect */
597597
WriteDOC((DOC_FLASH_CE), docptr, Mplus_FlashSelect);
598-
this->cmdfunc(mtd, NAND_CMD_RESET, -1, -1);
598+
nand_reset_op(this);
599599

600600
doc->curchip = chip;
601601
doc->curfloor = floor;

drivers/mtd/nand/docg4.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -864,7 +864,7 @@ static int docg4_read_oob(struct mtd_info *mtd, struct nand_chip *nand,
864864

865865
dev_dbg(doc->dev, "%s: page %x\n", __func__, page);
866866

867-
docg4_command(mtd, NAND_CMD_READ0, nand->ecc.size, page);
867+
nand_read_page_op(nand, page, nand->ecc.size, NULL, 0);
868868

869869
writew(DOC_ECCCONF0_READ_MODE | DOCG4_OOB_SIZE, docptr + DOC_ECCCONF0);
870870
write_nop(docptr);

drivers/mtd/nand/fsmc_nand.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
697697
unsigned int max_bitflips = 0;
698698

699699
for (i = 0, s = 0; s < eccsteps; s++, i += eccbytes, p += eccsize) {
700-
chip->cmdfunc(mtd, NAND_CMD_READ0, s * eccsize, page);
700+
nand_read_page_op(chip, page, s * eccsize, NULL, 0);
701701
chip->ecc.hwctl(mtd, NAND_ECC_READ);
702702
chip->read_buf(mtd, p, eccsize);
703703

@@ -720,8 +720,7 @@ static int fsmc_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
720720
if (chip->options & NAND_BUSWIDTH_16)
721721
len = roundup(len, 2);
722722

723-
chip->cmdfunc(mtd, NAND_CMD_READOOB, off, page);
724-
chip->read_buf(mtd, oob + j, len);
723+
nand_read_oob_op(chip, page, off, oob + j, len);
725724
j += len;
726725
}
727726

drivers/mtd/nand/gpmi-nand/gpmi-nand.c

Lines changed: 19 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1097,8 +1097,8 @@ static int gpmi_ecc_read_page(struct mtd_info *mtd, struct nand_chip *chip,
10971097
eccbytes = DIV_ROUND_UP(offset + eccbits, 8);
10981098
offset /= 8;
10991099
eccbytes -= offset;
1100-
chip->cmdfunc(mtd, NAND_CMD_RNDOUT, offset, -1);
1101-
chip->read_buf(mtd, eccbuf, eccbytes);
1100+
nand_change_read_column_op(chip, offset, eccbuf,
1101+
eccbytes, false);
11021102

11031103
/*
11041104
* ECC data are not byte aligned and we may have
@@ -1220,7 +1220,7 @@ static int gpmi_ecc_read_subpage(struct mtd_info *mtd, struct nand_chip *chip,
12201220
meta = geo->metadata_size;
12211221
if (first) {
12221222
col = meta + (size + ecc_parity_size) * first;
1223-
chip->cmdfunc(mtd, NAND_CMD_RNDOUT, col, -1);
1223+
nand_change_read_column_op(chip, col, NULL, 0, false);
12241224

12251225
meta = 0;
12261226
buf = buf + first * size;
@@ -1411,7 +1411,7 @@ static int gpmi_ecc_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
14111411
memset(chip->oob_poi, ~0, mtd->oobsize);
14121412

14131413
/* Read out the conventional OOB. */
1414-
chip->cmdfunc(mtd, NAND_CMD_READ0, mtd->writesize, page);
1414+
nand_read_page_op(chip, page, mtd->writesize, NULL, 0);
14151415
chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
14161416

14171417
/*
@@ -1421,7 +1421,7 @@ static int gpmi_ecc_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
14211421
*/
14221422
if (GPMI_IS_MX23(this)) {
14231423
/* Read the block mark into the first byte of the OOB buffer. */
1424-
chip->cmdfunc(mtd, NAND_CMD_READ0, 0, page);
1424+
nand_read_page_op(chip, page, 0, NULL, 0);
14251425
chip->oob_poi[0] = chip->read_byte(mtd);
14261426
}
14271427

@@ -1432,7 +1432,6 @@ static int
14321432
gpmi_ecc_write_oob(struct mtd_info *mtd, struct nand_chip *chip, int page)
14331433
{
14341434
struct mtd_oob_region of = { };
1435-
int status = 0;
14361435

14371436
/* Do we have available oob area? */
14381437
mtd_ooblayout_free(mtd, 0, &of);
@@ -1442,12 +1441,8 @@ gpmi_ecc_write_oob(struct mtd_info *mtd, struct nand_chip *chip, int page)
14421441
if (!nand_is_slc(chip))
14431442
return -EPERM;
14441443

1445-
chip->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->writesize + of.offset, page);
1446-
chip->write_buf(mtd, chip->oob_poi + of.offset, of.length);
1447-
chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
1448-
1449-
status = chip->waitfunc(mtd, chip);
1450-
return status & NAND_STATUS_FAIL ? -EIO : 0;
1444+
return nand_prog_page_op(chip, page, mtd->writesize + of.offset,
1445+
chip->oob_poi + of.offset, of.length);
14511446
}
14521447

14531448
/*
@@ -1622,15 +1617,15 @@ static int gpmi_ecc_write_page_raw(struct mtd_info *mtd,
16221617
static int gpmi_ecc_read_oob_raw(struct mtd_info *mtd, struct nand_chip *chip,
16231618
int page)
16241619
{
1625-
chip->cmdfunc(mtd, NAND_CMD_READ0, 0, page);
1620+
nand_read_page_op(chip, page, 0, NULL, 0);
16261621

16271622
return gpmi_ecc_read_page_raw(mtd, chip, NULL, 1, page);
16281623
}
16291624

16301625
static int gpmi_ecc_write_oob_raw(struct mtd_info *mtd, struct nand_chip *chip,
16311626
int page)
16321627
{
1633-
chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0, page);
1628+
nand_prog_page_begin_op(chip, page, 0, NULL, 0);
16341629

16351630
return gpmi_ecc_write_page_raw(mtd, chip, NULL, 1, page);
16361631
}
@@ -1641,7 +1636,7 @@ static int gpmi_block_markbad(struct mtd_info *mtd, loff_t ofs)
16411636
struct gpmi_nand_data *this = nand_get_controller_data(chip);
16421637
int ret = 0;
16431638
uint8_t *block_mark;
1644-
int column, page, status, chipnr;
1639+
int column, page, chipnr;
16451640

16461641
chipnr = (int)(ofs >> chip->chip_shift);
16471642
chip->select_chip(mtd, chipnr);
@@ -1655,13 +1650,7 @@ static int gpmi_block_markbad(struct mtd_info *mtd, loff_t ofs)
16551650
/* Shift to get page */
16561651
page = (int)(ofs >> chip->page_shift);
16571652

1658-
chip->cmdfunc(mtd, NAND_CMD_SEQIN, column, page);
1659-
chip->write_buf(mtd, block_mark, 1);
1660-
chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
1661-
1662-
status = chip->waitfunc(mtd, chip);
1663-
if (status & NAND_STATUS_FAIL)
1664-
ret = -EIO;
1653+
ret = nand_prog_page_op(chip, page, column, block_mark, 1);
16651654

16661655
chip->select_chip(mtd, -1);
16671656

@@ -1729,7 +1718,7 @@ static int mx23_check_transcription_stamp(struct gpmi_nand_data *this)
17291718
* Read the NCB fingerprint. The fingerprint is four bytes long
17301719
* and starts in the 12th byte of the page.
17311720
*/
1732-
chip->cmdfunc(mtd, NAND_CMD_READ0, 12, page);
1721+
nand_read_page_op(chip, page, 12, NULL, 0);
17331722
chip->read_buf(mtd, buffer, strlen(fingerprint));
17341723

17351724
/* Look for the fingerprint. */
@@ -1789,17 +1778,10 @@ static int mx23_write_transcription_stamp(struct gpmi_nand_data *this)
17891778
dev_dbg(dev, "Erasing the search area...\n");
17901779

17911780
for (block = 0; block < search_area_size_in_blocks; block++) {
1792-
/* Compute the page address. */
1793-
page = block * block_size_in_pages;
1794-
17951781
/* Erase this block. */
17961782
dev_dbg(dev, "\tErasing block 0x%x\n", block);
1797-
chip->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page);
1798-
chip->cmdfunc(mtd, NAND_CMD_ERASE2, -1, -1);
1799-
1800-
/* Wait for the erase to finish. */
1801-
status = chip->waitfunc(mtd, chip);
1802-
if (status & NAND_STATUS_FAIL)
1783+
status = nand_erase_op(chip, block);
1784+
if (status)
18031785
dev_err(dev, "[%s] Erase failed.\n", __func__);
18041786
}
18051787

@@ -1815,13 +1797,11 @@ static int mx23_write_transcription_stamp(struct gpmi_nand_data *this)
18151797

18161798
/* Write the first page of the current stride. */
18171799
dev_dbg(dev, "Writing an NCB fingerprint in page 0x%x\n", page);
1818-
chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page);
1819-
chip->ecc.write_page_raw(mtd, chip, buffer, 0, page);
1820-
chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1);
18211800

1822-
/* Wait for the write to finish. */
1823-
status = chip->waitfunc(mtd, chip);
1824-
if (status & NAND_STATUS_FAIL)
1801+
nand_prog_page_begin_op(chip, page, 0, NULL, 0);
1802+
chip->ecc.write_page_raw(mtd, chip, buffer, 0, page);
1803+
status = nand_prog_page_end_op(chip);
1804+
if (status)
18251805
dev_err(dev, "[%s] Write failed.\n", __func__);
18261806
}
18271807

@@ -1876,7 +1856,7 @@ static int mx23_boot_init(struct gpmi_nand_data *this)
18761856

18771857
/* Send the command to read the conventional block mark. */
18781858
chip->select_chip(mtd, chipnr);
1879-
chip->cmdfunc(mtd, NAND_CMD_READ0, mtd->writesize, page);
1859+
nand_read_page_op(chip, page, mtd->writesize, NULL, 0);
18801860
block_mark = chip->read_byte(mtd);
18811861
chip->select_chip(mtd, -1);
18821862

drivers/mtd/nand/hisi504_nand.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -574,8 +574,7 @@ static int hisi_nand_read_oob(struct mtd_info *mtd, struct nand_chip *chip,
574574
{
575575
struct hinfc_host *host = nand_get_controller_data(chip);
576576

577-
chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page);
578-
chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
577+
nand_read_oob_op(chip, page, 0, chip->oob_poi, mtd->oobsize);
579578

580579
if (host->irq_status & HINFC504_INTS_UE) {
581580
host->irq_status = 0;

0 commit comments

Comments
 (0)