Lines Matching full:mtd

3  *   This is the generic MTD driver for NAND flash devices. It should be
7 * http://www.linux-mtd.infradead.org/doc/nand.html
20 * Check, if mtd->ecctype should be set to MTD_ECC_HW
39 #include <linux/mtd/mtd.h>
40 #include <linux/mtd/rawnand.h>
41 #include <linux/mtd/nand_ecc.h>
42 #include <linux/mtd/nand_bch.h>
44 #include <linux/mtd/partitions.h>
95 static int nand_get_device(struct mtd_info *mtd, int new_state);
97 static int nand_do_write_oob(struct mtd_info *mtd, loff_t to,
106 static int check_offs_len(struct mtd_info *mtd, in check_offs_len() argument
109 struct nand_chip *chip = mtd_to_nand(mtd); in check_offs_len()
129 * @mtd: MTD device structure
133 static void nand_release_device(struct mtd_info *mtd) in nand_release_device() argument
135 struct nand_chip *chip = mtd_to_nand(mtd); in nand_release_device()
138 chip->select_chip(mtd, -1); in nand_release_device()
143 * @mtd: MTD device structure
147 uint8_t nand_read_byte(struct mtd_info *mtd) in nand_read_byte() argument
149 struct nand_chip *chip = mtd_to_nand(mtd); in nand_read_byte()
155 * @mtd: MTD device structure
160 static uint8_t nand_read_byte16(struct mtd_info *mtd) in nand_read_byte16() argument
162 struct nand_chip *chip = mtd_to_nand(mtd); in nand_read_byte16()
168 * @mtd: MTD device structure
172 static u16 nand_read_word(struct mtd_info *mtd) in nand_read_word() argument
174 struct nand_chip *chip = mtd_to_nand(mtd); in nand_read_word()
180 * @mtd: MTD device structure
185 static void nand_select_chip(struct mtd_info *mtd, int chipnr) in nand_select_chip() argument
187 struct nand_chip *chip = mtd_to_nand(mtd); in nand_select_chip()
191 chip->cmd_ctrl(mtd, NAND_CMD_NONE, 0 | NAND_CTRL_CHANGE); in nand_select_chip()
203 * @mtd: MTD device structure
208 static void nand_write_byte(struct mtd_info *mtd, uint8_t byte) in nand_write_byte() argument
210 struct nand_chip *chip = mtd_to_nand(mtd); in nand_write_byte()
212 chip->write_buf(mtd, &byte, 1); in nand_write_byte()
217 * @mtd: MTD device structure
222 static void nand_write_byte16(struct mtd_info *mtd, uint8_t byte) in nand_write_byte16() argument
224 struct nand_chip *chip = mtd_to_nand(mtd); in nand_write_byte16()
243 chip->write_buf(mtd, (uint8_t *)&word, 2); in nand_write_byte16()
281 * @mtd: MTD device structure
287 void nand_write_buf(struct mtd_info *mtd, const uint8_t *buf, int len) in nand_write_buf() argument
289 struct nand_chip *chip = mtd_to_nand(mtd); in nand_write_buf()
296 * @mtd: MTD device structure
302 void nand_read_buf(struct mtd_info *mtd, uint8_t *buf, int len) in nand_read_buf() argument
304 struct nand_chip *chip = mtd_to_nand(mtd); in nand_read_buf()
311 * @mtd: MTD device structure
317 void nand_write_buf16(struct mtd_info *mtd, const uint8_t *buf, int len) in nand_write_buf16() argument
319 struct nand_chip *chip = mtd_to_nand(mtd); in nand_write_buf16()
327 * @mtd: MTD device structure
333 void nand_read_buf16(struct mtd_info *mtd, uint8_t *buf, int len) in nand_read_buf16() argument
335 struct nand_chip *chip = mtd_to_nand(mtd); in nand_read_buf16()
343 * @mtd: MTD device structure
348 static int nand_block_bad(struct mtd_info *mtd, loff_t ofs) in nand_block_bad() argument
351 struct nand_chip *chip = mtd_to_nand(mtd); in nand_block_bad()
355 ofs += mtd->erasesize - mtd->writesize; in nand_block_bad()
361 chip->cmdfunc(mtd, NAND_CMD_READOOB, in nand_block_bad()
363 bad = cpu_to_le16(chip->read_word(mtd)); in nand_block_bad()
369 chip->cmdfunc(mtd, NAND_CMD_READOOB, chip->badblockpos, in nand_block_bad()
371 bad = chip->read_byte(mtd); in nand_block_bad()
378 ofs += mtd->writesize; in nand_block_bad()
388 * @mtd: MTD device structure
395 static int nand_default_block_markbad(struct mtd_info *mtd, loff_t ofs) in nand_default_block_markbad() argument
397 struct nand_chip *chip = mtd_to_nand(mtd); in nand_default_block_markbad()
415 ofs += mtd->erasesize - mtd->writesize; in nand_default_block_markbad()
417 res = nand_do_write_oob(mtd, ofs, &ops); in nand_default_block_markbad()
422 ofs += mtd->writesize; in nand_default_block_markbad()
430 * @mtd: MTD device structure
445 static int nand_block_markbad_lowlevel(struct mtd_info *mtd, loff_t ofs) in nand_block_markbad_lowlevel() argument
447 struct nand_chip *chip = mtd_to_nand(mtd); in nand_block_markbad_lowlevel()
455 einfo.mtd = mtd; in nand_block_markbad_lowlevel()
458 nand_erase_nand(mtd, &einfo, 0); in nand_block_markbad_lowlevel()
461 nand_get_device(mtd, FL_WRITING); in nand_block_markbad_lowlevel()
462 ret = chip->block_markbad(mtd, ofs); in nand_block_markbad_lowlevel()
463 nand_release_device(mtd); in nand_block_markbad_lowlevel()
468 res = nand_markbad_bbt(mtd, ofs); in nand_block_markbad_lowlevel()
474 mtd->ecc_stats.badblocks++; in nand_block_markbad_lowlevel()
481 * @mtd: MTD device structure
486 static int nand_check_wp(struct mtd_info *mtd) in nand_check_wp() argument
488 struct nand_chip *chip = mtd_to_nand(mtd); in nand_check_wp()
495 chip->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1); in nand_check_wp()
496 return (chip->read_byte(mtd) & NAND_STATUS_WP) ? 0 : 1; in nand_check_wp()
501 * @mtd: MTD device structure
506 static int nand_block_isreserved(struct mtd_info *mtd, loff_t ofs) in nand_block_isreserved() argument
508 struct nand_chip *chip = mtd_to_nand(mtd); in nand_block_isreserved()
513 return nand_isreserved_bbt(mtd, ofs); in nand_block_isreserved()
518 * @mtd: MTD device structure
525 static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int allowbbt) in nand_block_checkbad() argument
527 struct nand_chip *chip = mtd_to_nand(mtd); in nand_block_checkbad()
532 chip->scan_bbt(mtd); in nand_block_checkbad()
536 return chip->block_bad(mtd, ofs); in nand_block_checkbad()
539 return nand_isbad_bbt(mtd, ofs, allowbbt); in nand_block_checkbad()
544 * @mtd: MTD device structure
548 void nand_wait_ready(struct mtd_info *mtd) in nand_wait_ready() argument
550 struct nand_chip *chip = mtd_to_nand(mtd); in nand_wait_ready()
558 if (chip->dev_ready(mtd)) in nand_wait_ready()
562 if (!chip->dev_ready(mtd)) in nand_wait_ready()
569 * @mtd: MTD device structure
574 static void nand_wait_status_ready(struct mtd_info *mtd, unsigned long timeo) in nand_wait_status_ready() argument
576 register struct nand_chip *chip = mtd_to_nand(mtd); in nand_wait_status_ready()
582 if ((chip->read_byte(mtd) & NAND_STATUS_READY)) in nand_wait_status_ready()
590 * @mtd: MTD device structure
598 static void nand_command(struct mtd_info *mtd, unsigned int command, in nand_command() argument
601 register struct nand_chip *chip = mtd_to_nand(mtd); in nand_command()
608 if (column >= mtd->writesize) { in nand_command()
610 column -= mtd->writesize; in nand_command()
619 chip->cmd_ctrl(mtd, readcmd, ctrl); in nand_command()
622 chip->cmd_ctrl(mtd, command, ctrl); in nand_command()
632 chip->cmd_ctrl(mtd, column, ctrl); in nand_command()
636 chip->cmd_ctrl(mtd, page_addr, ctrl); in nand_command()
638 chip->cmd_ctrl(mtd, page_addr >> 8, ctrl); in nand_command()
640 chip->cmd_ctrl(mtd, page_addr >> 16, ctrl); in nand_command()
642 chip->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE); in nand_command()
663 chip->cmd_ctrl(mtd, NAND_CMD_STATUS, in nand_command()
665 chip->cmd_ctrl(mtd, in nand_command()
668 nand_wait_status_ready(mtd, 250); in nand_command()
688 nand_wait_ready(mtd); in nand_command()
693 * @mtd: MTD device structure
702 static void nand_command_lp(struct mtd_info *mtd, unsigned int command, in nand_command_lp() argument
705 register struct nand_chip *chip = mtd_to_nand(mtd); in nand_command_lp()
709 column += mtd->writesize; in nand_command_lp()
714 chip->cmd_ctrl(mtd, command, NAND_NCE | NAND_CLE | NAND_CTRL_CHANGE); in nand_command_lp()
725 chip->cmd_ctrl(mtd, column, ctrl); in nand_command_lp()
727 chip->cmd_ctrl(mtd, column >> 8, ctrl); in nand_command_lp()
730 chip->cmd_ctrl(mtd, page_addr, ctrl); in nand_command_lp()
731 chip->cmd_ctrl(mtd, page_addr >> 8, in nand_command_lp()
734 chip->cmd_ctrl(mtd, page_addr >> 16, in nand_command_lp()
738 chip->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE); in nand_command_lp()
761 chip->cmd_ctrl(mtd, NAND_CMD_STATUS, in nand_command_lp()
763 chip->cmd_ctrl(mtd, NAND_CMD_NONE, in nand_command_lp()
766 nand_wait_status_ready(mtd, 250); in nand_command_lp()
771 chip->cmd_ctrl(mtd, NAND_CMD_RNDOUTSTART, in nand_command_lp()
773 chip->cmd_ctrl(mtd, NAND_CMD_NONE, in nand_command_lp()
778 chip->cmd_ctrl(mtd, NAND_CMD_READSTART, in nand_command_lp()
780 chip->cmd_ctrl(mtd, NAND_CMD_NONE, in nand_command_lp()
801 nand_wait_ready(mtd); in nand_command_lp()
807 * @mtd: MTD device structure
813 struct mtd_info *mtd, int new_state) in panic_nand_get_device() argument
822 * @mtd: MTD device structure
828 nand_get_device(struct mtd_info *mtd, int new_state) in nand_get_device() argument
830 struct nand_chip *chip = mtd_to_nand(mtd); in nand_get_device()
837 * @mtd: MTD device structure
845 static void panic_nand_wait(struct mtd_info *mtd, struct nand_chip *chip, in panic_nand_wait() argument
851 if (chip->dev_ready(mtd)) in panic_nand_wait()
854 if (chip->read_byte(mtd) & NAND_STATUS_READY) in panic_nand_wait()
863 * @mtd: MTD device structure
868 static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip) in nand_wait() argument
881 chip->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1); in nand_wait()
889 if (chip->dev_ready(mtd)) in nand_wait()
892 if (chip->read_byte(mtd) & NAND_STATUS_READY) in nand_wait()
898 status = (int)chip->read_byte(mtd); in nand_wait()
915 struct mtd_info *mtd = nand_to_mtd(chip); in nand_reset_data_interface() local
937 ret = chip->setup_data_interface(mtd, chipnr, conf); in nand_reset_data_interface()
959 struct mtd_info *mtd = nand_to_mtd(chip); in nand_setup_data_interface() local
974 ret = chip->onfi_set_features(mtd, chip, in nand_setup_data_interface()
981 ret = chip->setup_data_interface(mtd, chipnr, chip->data_interface); in nand_setup_data_interface()
1002 struct mtd_info *mtd = nand_to_mtd(chip); in nand_init_data_interface() local
1033 ret = chip->setup_data_interface(mtd, in nand_init_data_interface()
1059 struct mtd_info *mtd = nand_to_mtd(chip); in nand_reset() local
1070 chip->select_chip(mtd, chipnr); in nand_reset()
1071 chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); in nand_reset()
1072 chip->select_chip(mtd, -1); in nand_reset()
1074 chip->select_chip(mtd, chipnr); in nand_reset()
1076 chip->select_chip(mtd, -1); in nand_reset()
1212 * @mtd: mtd info structure
1220 static int nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip, in nand_read_page_raw() argument
1223 chip->read_buf(mtd, buf, mtd->writesize); in nand_read_page_raw()
1225 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize); in nand_read_page_raw()
1231 * @mtd: mtd info structure
1239 static int nand_read_page_raw_syndrome(struct mtd_info *mtd, in nand_read_page_raw_syndrome() argument
1249 chip->read_buf(mtd, buf, eccsize); in nand_read_page_raw_syndrome()
1253 chip->read_buf(mtd, oob, chip->ecc.prepad); in nand_read_page_raw_syndrome()
1257 chip->read_buf(mtd, oob, eccbytes); in nand_read_page_raw_syndrome()
1261 chip->read_buf(mtd, oob, chip->ecc.postpad); in nand_read_page_raw_syndrome()
1266 size = mtd->oobsize - (oob - chip->oob_poi); in nand_read_page_raw_syndrome()
1268 chip->read_buf(mtd, oob, size); in nand_read_page_raw_syndrome()
1275 * @mtd: mtd info structure
1281 static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip, in nand_read_page_swecc() argument
1293 chip->ecc.read_page_raw(mtd, chip, buf, 1, page); in nand_read_page_swecc()
1296 chip->ecc.calculate(mtd, p, &ecc_calc[i]); in nand_read_page_swecc()
1307 stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]); in nand_read_page_swecc()
1309 mtd->ecc_stats.failed++; in nand_read_page_swecc()
1311 mtd->ecc_stats.corrected += stat; in nand_read_page_swecc()
1320 * @mtd: mtd info structure
1327 static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip, in nand_read_subpage() argument
1353 chip->cmdfunc(mtd, NAND_CMD_RNDOUT, data_col_addr, -1); in nand_read_subpage()
1356 chip->read_buf(mtd, p, datafrag_len); in nand_read_subpage()
1360 chip->ecc.calculate(mtd, p, &chip->buffers->ecccalc[i]); in nand_read_subpage()
1373 chip->cmdfunc(mtd, NAND_CMD_RNDOUT, mtd->writesize, -1); in nand_read_subpage()
1374 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize); in nand_read_subpage()
1387 chip->cmdfunc(mtd, NAND_CMD_RNDOUT, in nand_read_subpage()
1388 mtd->writesize + aligned_pos, -1); in nand_read_subpage()
1389 chip->read_buf(mtd, &chip->oob_poi[aligned_pos], aligned_len); in nand_read_subpage()
1399 stat = chip->ecc.correct(mtd, p, in nand_read_subpage()
1412 mtd->ecc_stats.failed++; in nand_read_subpage()
1414 mtd->ecc_stats.corrected += stat; in nand_read_subpage()
1423 * @mtd: mtd info structure
1431 static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, in nand_read_page_hwecc() argument
1444 chip->ecc.hwctl(mtd, NAND_ECC_READ); in nand_read_page_hwecc()
1445 chip->read_buf(mtd, p, eccsize); in nand_read_page_hwecc()
1446 chip->ecc.calculate(mtd, p, &ecc_calc[i]); in nand_read_page_hwecc()
1448 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize); in nand_read_page_hwecc()
1459 stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]); in nand_read_page_hwecc()
1470 mtd->ecc_stats.failed++; in nand_read_page_hwecc()
1472 mtd->ecc_stats.corrected += stat; in nand_read_page_hwecc()
1481 * @mtd: mtd info structure
1493 static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd, in nand_read_page_hwecc_oob_first() argument
1506 chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page); in nand_read_page_hwecc_oob_first()
1507 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize); in nand_read_page_hwecc_oob_first()
1508 chip->cmdfunc(mtd, NAND_CMD_READ0, 0, page); in nand_read_page_hwecc_oob_first()
1516 chip->ecc.hwctl(mtd, NAND_ECC_READ); in nand_read_page_hwecc_oob_first()
1517 chip->read_buf(mtd, p, eccsize); in nand_read_page_hwecc_oob_first()
1518 chip->ecc.calculate(mtd, p, &ecc_calc[i]); in nand_read_page_hwecc_oob_first()
1520 stat = chip->ecc.correct(mtd, p, &ecc_code[i], NULL); in nand_read_page_hwecc_oob_first()
1531 mtd->ecc_stats.failed++; in nand_read_page_hwecc_oob_first()
1533 mtd->ecc_stats.corrected += stat; in nand_read_page_hwecc_oob_first()
1542 * @mtd: mtd info structure
1551 static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip, in nand_read_page_syndrome() argument
1565 chip->ecc.hwctl(mtd, NAND_ECC_READ); in nand_read_page_syndrome()
1566 chip->read_buf(mtd, p, eccsize); in nand_read_page_syndrome()
1569 chip->read_buf(mtd, oob, chip->ecc.prepad); in nand_read_page_syndrome()
1573 chip->ecc.hwctl(mtd, NAND_ECC_READSYN); in nand_read_page_syndrome()
1574 chip->read_buf(mtd, oob, eccbytes); in nand_read_page_syndrome()
1575 stat = chip->ecc.correct(mtd, p, oob, NULL); in nand_read_page_syndrome()
1580 chip->read_buf(mtd, oob, chip->ecc.postpad); in nand_read_page_syndrome()
1595 mtd->ecc_stats.failed++; in nand_read_page_syndrome()
1597 mtd->ecc_stats.corrected += stat; in nand_read_page_syndrome()
1603 i = mtd->oobsize - (oob - chip->oob_poi); in nand_read_page_syndrome()
1605 chip->read_buf(mtd, oob, i); in nand_read_page_syndrome()
1660 * @mtd: MTD device structure
1667 static int nand_setup_read_retry(struct mtd_info *mtd, int retry_mode) in nand_setup_read_retry() argument
1669 struct nand_chip *chip = mtd_to_nand(mtd); in nand_setup_read_retry()
1679 return chip->setup_read_retry(mtd, retry_mode); in nand_setup_read_retry()
1684 * @mtd: MTD device structure
1690 static int nand_do_read_ops(struct mtd_info *mtd, loff_t from, in nand_do_read_ops() argument
1694 struct nand_chip *chip = mtd_to_nand(mtd); in nand_do_read_ops()
1698 uint32_t max_oobsize = mtd_oobavail(mtd, ops); in nand_do_read_ops()
1707 chip->select_chip(mtd, chipnr); in nand_do_read_ops()
1712 col = (int)(from & (mtd->writesize - 1)); in nand_do_read_ops()
1719 unsigned int ecc_failures = mtd->ecc_stats.failed; in nand_do_read_ops()
1722 bytes = min(mtd->writesize - col, readlen); in nand_do_read_ops()
1723 aligned = (bytes == mtd->writesize); in nand_do_read_ops()
1743 chip->cmdfunc(mtd, NAND_CMD_READ0, 0x00, page); in nand_do_read_ops()
1750 ret = chip->ecc.read_page_raw(mtd, chip, bufpoi, in nand_do_read_ops()
1755 ret = chip->ecc.read_subpage(mtd, chip, in nand_do_read_ops()
1759 ret = chip->ecc.read_page(mtd, chip, bufpoi, in nand_do_read_ops()
1773 !(mtd->ecc_stats.failed - ecc_failures) && in nand_do_read_ops()
1799 nand_wait_ready(mtd); in nand_do_read_ops()
1802 if (mtd->ecc_stats.failed - ecc_failures) { in nand_do_read_ops()
1805 ret = nand_setup_read_retry(mtd, in nand_do_read_ops()
1811 mtd->ecc_stats.failed = ecc_failures; in nand_do_read_ops()
1831 ret = nand_setup_read_retry(mtd, 0); in nand_do_read_ops()
1849 chip->select_chip(mtd, -1); in nand_do_read_ops()
1850 chip->select_chip(mtd, chipnr); in nand_do_read_ops()
1853 chip->select_chip(mtd, -1); in nand_do_read_ops()
1870 * @mtd: mtd info structure
1874 static int nand_read_oob_std(struct mtd_info *mtd, struct nand_chip *chip, in nand_read_oob_std() argument
1877 chip->cmdfunc(mtd, NAND_CMD_READOOB, 0, page); in nand_read_oob_std()
1878 chip->read_buf(mtd, chip->oob_poi, mtd->oobsize); in nand_read_oob_std()
1885 * @mtd: mtd info structure
1889 static int nand_read_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip, in nand_read_oob_syndrome() argument
1892 int length = mtd->oobsize; in nand_read_oob_syndrome()
1898 chip->cmdfunc(mtd, NAND_CMD_READ0, chip->ecc.size, page); in nand_read_oob_syndrome()
1902 if (mtd->writesize > 512) in nand_read_oob_syndrome()
1903 chip->cmdfunc(mtd, NAND_CMD_RNDOUT, pos, -1); in nand_read_oob_syndrome()
1905 chip->cmdfunc(mtd, NAND_CMD_READ0, pos, page); in nand_read_oob_syndrome()
1909 chip->read_buf(mtd, bufpoi, toread); in nand_read_oob_syndrome()
1914 chip->read_buf(mtd, bufpoi, length); in nand_read_oob_syndrome()
1921 * @mtd: mtd info structure
1925 static int nand_write_oob_std(struct mtd_info *mtd, struct nand_chip *chip, in nand_write_oob_std() argument
1930 int length = mtd->oobsize; in nand_write_oob_std()
1932 chip->cmdfunc(mtd, NAND_CMD_SEQIN, mtd->writesize, page); in nand_write_oob_std()
1933 chip->write_buf(mtd, buf, length); in nand_write_oob_std()
1935 chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1); in nand_write_oob_std()
1937 status = chip->waitfunc(mtd, chip); in nand_write_oob_std()
1945 * @mtd: mtd info structure
1949 static int nand_write_oob_syndrome(struct mtd_info *mtd, in nand_write_oob_syndrome() argument
1953 int eccsize = chip->ecc.size, length = mtd->oobsize; in nand_write_oob_syndrome()
1968 chip->cmdfunc(mtd, NAND_CMD_SEQIN, pos, page); in nand_write_oob_syndrome()
1971 if (mtd->writesize <= 512) { in nand_write_oob_syndrome()
1977 chip->write_buf(mtd, (uint8_t *)&fill, in nand_write_oob_syndrome()
1983 chip->cmdfunc(mtd, NAND_CMD_RNDIN, pos, -1); in nand_write_oob_syndrome()
1988 chip->write_buf(mtd, bufpoi, len); in nand_write_oob_syndrome()
1993 chip->write_buf(mtd, bufpoi, length); in nand_write_oob_syndrome()
1995 chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1); in nand_write_oob_syndrome()
1996 status = chip->waitfunc(mtd, chip); in nand_write_oob_syndrome()
2003 * @mtd: MTD device structure
2009 static int nand_do_read_oob(struct mtd_info *mtd, loff_t from, in nand_do_read_oob() argument
2013 struct nand_chip *chip = mtd_to_nand(mtd); in nand_do_read_oob()
2023 stats = mtd->ecc_stats; in nand_do_read_oob()
2025 len = mtd_oobavail(mtd, ops); in nand_do_read_oob()
2034 if (unlikely(from >= mtd->size || in nand_do_read_oob()
2035 ops->ooboffs + readlen > ((mtd->size >> chip->page_shift) - in nand_do_read_oob()
2043 chip->select_chip(mtd, chipnr); in nand_do_read_oob()
2053 ret = chip->ecc.read_oob_raw(mtd, chip, page); in nand_do_read_oob()
2055 ret = chip->ecc.read_oob(mtd, chip, page); in nand_do_read_oob()
2068 nand_wait_ready(mtd); in nand_do_read_oob()
2082 chip->select_chip(mtd, -1); in nand_do_read_oob()
2083 chip->select_chip(mtd, chipnr); in nand_do_read_oob()
2086 chip->select_chip(mtd, -1); in nand_do_read_oob()
2093 if (mtd->ecc_stats.failed - stats.failed) in nand_do_read_oob()
2096 return mtd->ecc_stats.corrected - stats.corrected ? -EUCLEAN : 0; in nand_do_read_oob()
2100 * nand_read_oob - [MTD Interface] NAND read data and/or out-of-band
2101 * @mtd: MTD device structure
2107 static int nand_read_oob(struct mtd_info *mtd, loff_t from, in nand_read_oob() argument
2115 if (ops->datbuf && (from + ops->len) > mtd->size) { in nand_read_oob()
2121 nand_get_device(mtd, FL_READING); in nand_read_oob()
2134 ret = nand_do_read_oob(mtd, from, ops); in nand_read_oob()
2136 ret = nand_do_read_ops(mtd, from, ops); in nand_read_oob()
2139 nand_release_device(mtd); in nand_read_oob()
2146 * @mtd: mtd info structure
2154 static int nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip, in nand_write_page_raw() argument
2157 chip->write_buf(mtd, buf, mtd->writesize); in nand_write_page_raw()
2159 chip->write_buf(mtd, chip->oob_poi, mtd->oobsize); in nand_write_page_raw()
2166 * @mtd: mtd info structure
2174 static int nand_write_page_raw_syndrome(struct mtd_info *mtd, in nand_write_page_raw_syndrome() argument
2185 chip->write_buf(mtd, buf, eccsize); in nand_write_page_raw_syndrome()
2189 chip->write_buf(mtd, oob, chip->ecc.prepad); in nand_write_page_raw_syndrome()
2193 chip->write_buf(mtd, oob, eccbytes); in nand_write_page_raw_syndrome()
2197 chip->write_buf(mtd, oob, chip->ecc.postpad); in nand_write_page_raw_syndrome()
2202 size = mtd->oobsize - (oob - chip->oob_poi); in nand_write_page_raw_syndrome()
2204 chip->write_buf(mtd, oob, size); in nand_write_page_raw_syndrome()
2210 * @mtd: mtd info structure
2216 static int nand_write_page_swecc(struct mtd_info *mtd, struct nand_chip *chip, in nand_write_page_swecc() argument
2229 chip->ecc.calculate(mtd, p, &ecc_calc[i]); in nand_write_page_swecc()
2234 return chip->ecc.write_page_raw(mtd, chip, buf, 1, page); in nand_write_page_swecc()
2239 * @mtd: mtd info structure
2245 static int nand_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, in nand_write_page_hwecc() argument
2257 chip->ecc.hwctl(mtd, NAND_ECC_WRITE); in nand_write_page_hwecc()
2258 chip->write_buf(mtd, p, eccsize); in nand_write_page_hwecc()
2259 chip->ecc.calculate(mtd, p, &ecc_calc[i]); in nand_write_page_hwecc()
2265 chip->write_buf(mtd, chip->oob_poi, mtd->oobsize); in nand_write_page_hwecc()
2273 * @mtd: mtd info structure
2281 static int nand_write_subpage_hwecc(struct mtd_info *mtd, in nand_write_subpage_hwecc() argument
2294 int oob_bytes = mtd->oobsize / ecc_steps; in nand_write_subpage_hwecc()
2299 chip->ecc.hwctl(mtd, NAND_ECC_WRITE); in nand_write_subpage_hwecc()
2302 chip->write_buf(mtd, buf, ecc_size); in nand_write_subpage_hwecc()
2308 chip->ecc.calculate(mtd, buf, ecc_calc); in nand_write_subpage_hwecc()
2327 chip->write_buf(mtd, chip->oob_poi, mtd->oobsize); in nand_write_subpage_hwecc()
2335 * @mtd: mtd info structure
2344 static int nand_write_page_syndrome(struct mtd_info *mtd, in nand_write_page_syndrome() argument
2357 chip->ecc.hwctl(mtd, NAND_ECC_WRITE); in nand_write_page_syndrome()
2358 chip->write_buf(mtd, p, eccsize); in nand_write_page_syndrome()
2361 chip->write_buf(mtd, oob, chip->ecc.prepad); in nand_write_page_syndrome()
2365 chip->ecc.calculate(mtd, p, oob); in nand_write_page_syndrome()
2366 chip->write_buf(mtd, oob, eccbytes); in nand_write_page_syndrome()
2370 chip->write_buf(mtd, oob, chip->ecc.postpad); in nand_write_page_syndrome()
2376 i = mtd->oobsize - (oob - chip->oob_poi); in nand_write_page_syndrome()
2378 chip->write_buf(mtd, oob, i); in nand_write_page_syndrome()
2385 * @mtd: MTD device structure
2394 static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip, in nand_write_page() argument
2402 subpage = offset || (data_len < mtd->writesize); in nand_write_page()
2407 chip->cmdfunc(mtd, NAND_CMD_SEQIN, 0x00, page); in nand_write_page()
2410 status = chip->ecc.write_page_raw(mtd, chip, buf, in nand_write_page()
2413 status = chip->ecc.write_subpage(mtd, chip, offset, data_len, in nand_write_page()
2416 status = chip->ecc.write_page(mtd, chip, buf, oob_required, in nand_write_page()
2423 chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1); in nand_write_page()
2425 status = chip->waitfunc(mtd, chip); in nand_write_page()
2435 * @mtd: MTD device structure
2440 static uint8_t *nand_fill_oob(struct mtd_info *mtd, uint8_t *oob, size_t len, in nand_fill_oob() argument
2443 struct nand_chip *chip = mtd_to_nand(mtd); in nand_fill_oob()
2449 memset(chip->oob_poi, 0xff, mtd->oobsize); in nand_fill_oob()
2493 * @mtd: MTD device structure
2499 static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, in nand_do_write_ops() argument
2503 struct nand_chip *chip = mtd_to_nand(mtd); in nand_do_write_ops()
2507 uint32_t oobmaxlen = mtd_oobavail(mtd, ops); in nand_do_write_ops()
2525 column = to & (mtd->writesize - 1); in nand_do_write_ops()
2528 chip->select_chip(mtd, chipnr); in nand_do_write_ops()
2531 if (nand_check_wp(mtd)) { in nand_do_write_ops()
2551 int bytes = mtd->writesize; in nand_do_write_ops()
2554 int part_pagewr = (column || writelen < mtd->writesize); in nand_do_write_ops()
2572 memset(chip->buffers->databuf, 0xff, mtd->writesize); in nand_do_write_ops()
2579 oob = nand_fill_oob(mtd, oob, len, ops); in nand_do_write_ops()
2583 memset(chip->oob_poi, 0xff, mtd->oobsize); in nand_do_write_ops()
2585 ret = chip->write_page(mtd, chip, column, bytes, wbuf, in nand_do_write_ops()
2603 chip->select_chip(mtd, -1); in nand_do_write_ops()
2604 chip->select_chip(mtd, chipnr); in nand_do_write_ops()
2613 chip->select_chip(mtd, -1); in nand_do_write_ops()
2618 * panic_nand_write - [MTD Interface] NAND write with ECC
2619 * @mtd: MTD device structure
2628 static int panic_nand_write(struct mtd_info *mtd, loff_t to, size_t len, in panic_nand_write() argument
2631 struct nand_chip *chip = mtd_to_nand(mtd); in panic_nand_write()
2636 panic_nand_wait(mtd, chip, 400); in panic_nand_write()
2639 panic_nand_get_device(chip, mtd, FL_WRITING); in panic_nand_write()
2646 ret = nand_do_write_ops(mtd, to, &ops); in panic_nand_write()
2653 * nand_do_write_oob - [MTD Interface] NAND write out-of-band
2654 * @mtd: MTD device structure
2660 static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, in nand_do_write_oob() argument
2664 struct nand_chip *chip = mtd_to_nand(mtd); in nand_do_write_oob()
2669 len = mtd_oobavail(mtd, ops); in nand_do_write_oob()
2685 if (unlikely(to >= mtd->size || in nand_do_write_oob()
2687 ((mtd->size >> chip->page_shift) - in nand_do_write_oob()
2704 chip->select_chip(mtd, chipnr); in nand_do_write_oob()
2710 if (nand_check_wp(mtd)) { in nand_do_write_oob()
2711 chip->select_chip(mtd, -1); in nand_do_write_oob()
2719 nand_fill_oob(mtd, ops->oobbuf, ops->ooblen, ops); in nand_do_write_oob()
2722 status = chip->ecc.write_oob_raw(mtd, chip, page & chip->pagemask); in nand_do_write_oob()
2724 status = chip->ecc.write_oob(mtd, chip, page & chip->pagemask); in nand_do_write_oob()
2726 chip->select_chip(mtd, -1); in nand_do_write_oob()
2737 * nand_write_oob - [MTD Interface] NAND write data and/or out-of-band
2738 * @mtd: MTD device structure
2742 static int nand_write_oob(struct mtd_info *mtd, loff_t to, in nand_write_oob() argument
2750 if (ops->datbuf && (to + ops->len) > mtd->size) { in nand_write_oob()
2756 nand_get_device(mtd, FL_WRITING); in nand_write_oob()
2769 ret = nand_do_write_oob(mtd, to, ops); in nand_write_oob()
2771 ret = nand_do_write_ops(mtd, to, ops); in nand_write_oob()
2774 nand_release_device(mtd); in nand_write_oob()
2780 * @mtd: MTD device structure
2785 static int single_erase(struct mtd_info *mtd, int page) in single_erase() argument
2787 struct nand_chip *chip = mtd_to_nand(mtd); in single_erase()
2789 chip->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page); in single_erase()
2790 chip->cmdfunc(mtd, NAND_CMD_ERASE2, -1, -1); in single_erase()
2792 return chip->waitfunc(mtd, chip); in single_erase()
2796 * nand_erase - [MTD Interface] erase block(s)
2797 * @mtd: MTD device structure
2802 static int nand_erase(struct mtd_info *mtd, struct erase_info *instr) in nand_erase() argument
2804 return nand_erase_nand(mtd, instr, 0); in nand_erase()
2809 * @mtd: MTD device structure
2815 int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, in nand_erase_nand() argument
2819 struct nand_chip *chip = mtd_to_nand(mtd); in nand_erase_nand()
2826 if (check_offs_len(mtd, instr->addr, instr->len)) in nand_erase_nand()
2830 nand_get_device(mtd, FL_ERASING); in nand_erase_nand()
2840 chip->select_chip(mtd, chipnr); in nand_erase_nand()
2843 if (nand_check_wp(mtd)) { in nand_erase_nand()
2859 if (!instr->scrub && nand_block_checkbad(mtd, ((loff_t) page) << in nand_erase_nand()
2875 status = chip->erase(mtd, page & chip->pagemask); in nand_erase_nand()
2894 chip->select_chip(mtd, -1); in nand_erase_nand()
2895 chip->select_chip(mtd, chipnr); in nand_erase_nand()
2905 chip->select_chip(mtd, -1); in nand_erase_nand()
2906 nand_release_device(mtd); in nand_erase_nand()
2917 * nand_sync - [MTD Interface] sync
2918 * @mtd: MTD device structure
2922 static void nand_sync(struct mtd_info *mtd) in nand_sync() argument
2927 nand_get_device(mtd, FL_SYNCING); in nand_sync()
2929 nand_release_device(mtd); in nand_sync()
2933 * nand_block_isbad - [MTD Interface] Check if block at offset is bad
2934 * @mtd: MTD device structure
2935 * @offs: offset relative to mtd start
2937 static int nand_block_isbad(struct mtd_info *mtd, loff_t offs) in nand_block_isbad() argument
2939 struct nand_chip *chip = mtd_to_nand(mtd); in nand_block_isbad()
2944 nand_get_device(mtd, FL_READING); in nand_block_isbad()
2945 chip->select_chip(mtd, chipnr); in nand_block_isbad()
2947 ret = nand_block_checkbad(mtd, offs, 0); in nand_block_isbad()
2949 chip->select_chip(mtd, -1); in nand_block_isbad()
2950 nand_release_device(mtd); in nand_block_isbad()
2956 * nand_block_markbad - [MTD Interface] Mark block at the given offset as bad
2957 * @mtd: MTD device structure
2958 * @ofs: offset relative to mtd start
2960 static int nand_block_markbad(struct mtd_info *mtd, loff_t ofs) in nand_block_markbad() argument
2964 ret = nand_block_isbad(mtd, ofs); in nand_block_markbad()
2972 return nand_block_markbad_lowlevel(mtd, ofs); in nand_block_markbad()
2977 * @mtd: MTD device structure
2982 static int nand_onfi_set_features(struct mtd_info *mtd, struct nand_chip *chip, in nand_onfi_set_features() argument
2995 chip->cmdfunc(mtd, NAND_CMD_SET_FEATURES, addr, -1); in nand_onfi_set_features()
2997 chip->write_byte(mtd, subfeature_param[i]); in nand_onfi_set_features()
2999 status = chip->waitfunc(mtd, chip); in nand_onfi_set_features()
3007 * @mtd: MTD device structure
3012 static int nand_onfi_get_features(struct mtd_info *mtd, struct nand_chip *chip, in nand_onfi_get_features() argument
3024 chip->cmdfunc(mtd, NAND_CMD_GET_FEATURES, addr, -1); in nand_onfi_get_features()
3026 *subfeature_param++ = chip->read_byte(mtd); in nand_onfi_get_features()
3114 static int nand_flash_detect_ext_param_page(struct mtd_info *mtd, in nand_flash_detect_ext_param_page() argument
3131 chip->cmdfunc(mtd, NAND_CMD_PARAM, 0, -1); in nand_flash_detect_ext_param_page()
3134 chip->cmdfunc(mtd, NAND_CMD_RNDOUT, in nand_flash_detect_ext_param_page()
3138 chip->read_buf(mtd, (uint8_t *)ep, len); in nand_flash_detect_ext_param_page()
3184 static int nand_setup_read_retry_micron(struct mtd_info *mtd, int retry_mode) in nand_setup_read_retry_micron() argument
3186 struct nand_chip *chip = mtd_to_nand(mtd); in nand_setup_read_retry_micron()
3189 return chip->onfi_set_features(mtd, chip, ONFI_FEATURE_ADDR_READ_RETRY, in nand_setup_read_retry_micron()
3211 static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, in nand_flash_detect_onfi() argument
3219 chip->cmdfunc(mtd, NAND_CMD_READID, 0x20, -1); in nand_flash_detect_onfi()
3220 if (chip->read_byte(mtd) != 'O' || chip->read_byte(mtd) != 'N' || in nand_flash_detect_onfi()
3221 chip->read_byte(mtd) != 'F' || chip->read_byte(mtd) != 'I') in nand_flash_detect_onfi()
3224 chip->cmdfunc(mtd, NAND_CMD_PARAM, 0, -1); in nand_flash_detect_onfi()
3227 ((uint8_t *)p)[j] = chip->read_byte(mtd); in nand_flash_detect_onfi()
3259 if (!mtd->name) in nand_flash_detect_onfi()
3260 mtd->name = p->model; in nand_flash_detect_onfi()
3262 mtd->writesize = le32_to_cpu(p->byte_per_page); in nand_flash_detect_onfi()
3266 * (don't ask me who thought of this...). MTD assumes that these in nand_flash_detect_onfi()
3269 mtd->erasesize = 1 << (fls(le32_to_cpu(p->pages_per_block)) - 1); in nand_flash_detect_onfi()
3270 mtd->erasesize *= mtd->writesize; in nand_flash_detect_onfi()
3272 mtd->oobsize = le16_to_cpu(p->spare_bytes_per_page); in nand_flash_detect_onfi()
3276 chip->chipsize *= (uint64_t)mtd->erasesize * p->lun_count; in nand_flash_detect_onfi()
3296 if (mtd->writesize > 512 && chip->cmdfunc == nand_command) in nand_flash_detect_onfi()
3300 if (nand_flash_detect_ext_param_page(mtd, chip, p)) in nand_flash_detect_onfi()
3312 static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, in nand_flash_detect_onfi() argument
3322 static int nand_flash_detect_jedec(struct mtd_info *mtd, struct nand_chip *chip, in nand_flash_detect_jedec() argument
3331 chip->cmdfunc(mtd, NAND_CMD_READID, 0x40, -1); in nand_flash_detect_jedec()
3332 if (chip->read_byte(mtd) != 'J' || chip->read_byte(mtd) != 'E' || in nand_flash_detect_jedec()
3333 chip->read_byte(mtd) != 'D' || chip->read_byte(mtd) != 'E' || in nand_flash_detect_jedec()
3334 chip->read_byte(mtd) != 'C') in nand_flash_detect_jedec()
3337 chip->cmdfunc(mtd, NAND_CMD_PARAM, 0x40, -1); in nand_flash_detect_jedec()
3340 ((uint8_t *)p)[j] = chip->read_byte(mtd); in nand_flash_detect_jedec()
3366 if (!mtd->name) in nand_flash_detect_jedec()
3367 mtd->name = p->model; in nand_flash_detect_jedec()
3369 mtd->writesize = le32_to_cpu(p->byte_per_page); in nand_flash_detect_jedec()
3372 mtd->erasesize = 1 << (fls(le32_to_cpu(p->pages_per_block)) - 1); in nand_flash_detect_jedec()
3373 mtd->erasesize *= mtd->writesize; in nand_flash_detect_jedec()
3375 mtd->oobsize = le16_to_cpu(p->spare_bytes_per_page); in nand_flash_detect_jedec()
3379 chip->chipsize *= (uint64_t)mtd->erasesize * p->lun_count; in nand_flash_detect_jedec()
3474 static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, in nand_decode_ext_id() argument
3497 mtd->writesize = 2048 << (extid & 0x03); in nand_decode_ext_id()
3502 mtd->oobsize = 128; in nand_decode_ext_id()
3505 mtd->oobsize = 218; in nand_decode_ext_id()
3508 mtd->oobsize = 400; in nand_decode_ext_id()
3511 mtd->oobsize = 436; in nand_decode_ext_id()
3514 mtd->oobsize = 512; in nand_decode_ext_id()
3517 mtd->oobsize = 640; in nand_decode_ext_id()
3521 mtd->oobsize = 1024; in nand_decode_ext_id()
3526 mtd->erasesize = (128 * 1024) << in nand_decode_ext_id()
3534 mtd->writesize = 2048 << (extid & 0x03); in nand_decode_ext_id()
3539 mtd->oobsize = 128; in nand_decode_ext_id()
3542 mtd->oobsize = 224; in nand_decode_ext_id()
3545 mtd->oobsize = 448; in nand_decode_ext_id()
3548 mtd->oobsize = 64; in nand_decode_ext_id()
3551 mtd->oobsize = 32; in nand_decode_ext_id()
3554 mtd->oobsize = 16; in nand_decode_ext_id()
3557 mtd->oobsize = 640; in nand_decode_ext_id()
3564 mtd->erasesize = (128 * 1024) << tmp; in nand_decode_ext_id()
3566 mtd->erasesize = 768 * 1024; in nand_decode_ext_id()
3568 mtd->erasesize = (64 * 1024) << tmp; in nand_decode_ext_id()
3572 mtd->writesize = 1024 << (extid & 0x03); in nand_decode_ext_id()
3575 mtd->oobsize = (8 << (extid & 0x01)) * in nand_decode_ext_id()
3576 (mtd->writesize >> 9); in nand_decode_ext_id()
3579 mtd->erasesize = (64 * 1024) << (extid & 0x03); in nand_decode_ext_id()
3596 mtd->oobsize = 32 * mtd->writesize >> 9; in nand_decode_ext_id()
3604 * decodes a matching ID table entry and assigns the MTD size parameters for
3607 static void nand_decode_id(struct mtd_info *mtd, struct nand_chip *chip, in nand_decode_id() argument
3613 mtd->erasesize = type->erasesize; in nand_decode_id()
3614 mtd->writesize = type->pagesize; in nand_decode_id()
3615 mtd->oobsize = mtd->writesize / 32; in nand_decode_id()
3629 && mtd->writesize == 512) { in nand_decode_id()
3630 mtd->erasesize = 128 * 1024; in nand_decode_id()
3631 mtd->erasesize <<= ((id_data[3] & 0x03) << 1); in nand_decode_id()
3640 static void nand_decode_bbm_options(struct mtd_info *mtd, in nand_decode_bbm_options() argument
3646 if (mtd->writesize > 512 || (chip->options & NAND_BUSWIDTH_16)) in nand_decode_bbm_options()
3667 (mtd->writesize == 2048 && in nand_decode_bbm_options()
3677 static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip, in find_full_id_nand() argument
3681 mtd->writesize = type->pagesize; in find_full_id_nand()
3682 mtd->erasesize = type->erasesize; in find_full_id_nand()
3683 mtd->oobsize = type->oobsize; in find_full_id_nand()
3695 if (!mtd->name) in find_full_id_nand()
3696 mtd->name = type->name; in find_full_id_nand()
3706 struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, in nand_get_flash_type() argument
3722 chip->select_chip(mtd, 0); in nand_get_flash_type()
3725 chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1); in nand_get_flash_type()
3728 *maf_id = chip->read_byte(mtd); in nand_get_flash_type()
3729 *dev_id = chip->read_byte(mtd); in nand_get_flash_type()
3738 chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1); in nand_get_flash_type()
3742 id_data[i] = chip->read_byte(mtd); in nand_get_flash_type()
3755 if (find_full_id_nand(mtd, chip, type, id_data, &busw)) in nand_get_flash_type()
3765 if (nand_flash_detect_onfi(mtd, chip, &busw)) in nand_get_flash_type()
3769 if (nand_flash_detect_jedec(mtd, chip, &busw)) in nand_get_flash_type()
3776 if (!mtd->name) in nand_get_flash_type()
3777 mtd->name = type->name; in nand_get_flash_type()
3783 nand_decode_ext_id(mtd, chip, id_data, &busw); in nand_get_flash_type()
3785 nand_decode_id(mtd, chip, type, id_data, &busw); in nand_get_flash_type()
3815 pr_info("%s %s\n", nand_manuf_ids[maf_idx].name, mtd->name); in nand_get_flash_type()
3822 nand_decode_bbm_options(mtd, chip, id_data); in nand_get_flash_type()
3825 chip->page_shift = ffs(mtd->writesize) - 1; in nand_get_flash_type()
3830 ffs(mtd->erasesize) - 1; in nand_get_flash_type()
3845 if (mtd->writesize > 512 && chip->cmdfunc == nand_command) in nand_get_flash_type()
3875 mtd->erasesize >> 10, mtd->writesize, mtd->oobsize); in nand_get_flash_type()
3883 static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, int node) in nand_dt_init() argument
3937 static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, int node) in nand_dt_init() argument
3945 * @mtd: MTD device structure
3950 * flash ID and sets up MTD fields accordingly.
3953 int nand_scan_ident(struct mtd_info *mtd, int maxchips, in nand_scan_ident() argument
3957 struct nand_chip *chip = mtd_to_nand(mtd); in nand_scan_ident()
3962 ret = nand_dt_init(mtd, chip, chip->flash_node); in nand_scan_ident()
3971 type = nand_get_flash_type(mtd, chip, &nand_maf_id, in nand_scan_ident()
3977 chip->select_chip(mtd, -1); in nand_scan_ident()
3998 chip->select_chip(mtd, -1); in nand_scan_ident()
4005 chip->select_chip(mtd, i); in nand_scan_ident()
4007 chip->cmdfunc(mtd, NAND_CMD_READID, 0x00, -1); in nand_scan_ident()
4009 if (nand_maf_id != chip->read_byte(mtd) || in nand_scan_ident()
4010 nand_dev_id != chip->read_byte(mtd)) { in nand_scan_ident()
4011 chip->select_chip(mtd, -1); in nand_scan_ident()
4014 chip->select_chip(mtd, -1); in nand_scan_ident()
4022 /* Store the number of chips and calc total size for mtd */ in nand_scan_ident()
4024 mtd->size = i * chip->chipsize; in nand_scan_ident()
4043 struct mtd_info *mtd = nand_to_mtd(chip); in nand_check_ecc_caps() local
4056 nsteps = mtd->writesize / preset_step; in nand_check_ecc_caps()
4105 struct mtd_info *mtd = nand_to_mtd(chip); in nand_match_ecc_req() local
4122 req_corr = mtd->writesize / req_step * req_strength; in nand_match_ecc_req()
4139 if (mtd->writesize % step_size) in nand_match_ecc_req()
4142 nsteps = mtd->writesize / step_size; in nand_match_ecc_req()
4189 struct mtd_info *mtd = nand_to_mtd(chip); in nand_maximize_ecc() local
4211 if (mtd->writesize % step_size) in nand_maximize_ecc()
4214 nsteps = mtd->writesize / step_size; in nand_maximize_ecc()
4264 static bool nand_ecc_strength_good(struct mtd_info *mtd) in nand_ecc_strength_good() argument
4266 struct nand_chip *chip = mtd_to_nand(mtd); in nand_ecc_strength_good()
4278 corr = (mtd->writesize * ecc->strength) / ecc->size; in nand_ecc_strength_good()
4279 ds_corr = (mtd->writesize * chip->ecc_strength_ds) / chip->ecc_step_ds; in nand_ecc_strength_good()
4306 * @mtd: MTD device structure
4312 int nand_scan_tail(struct mtd_info *mtd) in nand_scan_tail() argument
4315 struct nand_chip *chip = mtd_to_nand(mtd); in nand_scan_tail()
4337 chip->oob_poi = chip->buffers->databuf + mtd->writesize; in nand_scan_tail()
4343 switch (mtd->oobsize) { in nand_scan_tail()
4360 mtd->oobsize); in nand_scan_tail()
4425 if (mtd->writesize >= ecc->size) { in nand_scan_tail()
4433 ecc->size, mtd->writesize); in nand_scan_tail()
4471 if (!ecc->size && (mtd->oobsize >= 64)) { in nand_scan_tail()
4478 ecc->priv = nand_bch_init(mtd); in nand_scan_tail()
4493 ecc->size = mtd->writesize; in nand_scan_tail()
4513 mtd->oobavail = 0; in nand_scan_tail()
4516 mtd->oobavail += ecc->layout->oobfree[i].length; in nand_scan_tail()
4520 if (!nand_ecc_strength_good(mtd)) in nand_scan_tail()
4522 mtd->name); in nand_scan_tail()
4528 ecc->steps = mtd->writesize / ecc->size; in nand_scan_tail()
4529 if (ecc->steps * ecc->size != mtd->writesize) { in nand_scan_tail()
4539 mtd->subpage_sft = 1; in nand_scan_tail()
4544 mtd->subpage_sft = 2; in nand_scan_tail()
4548 chip->subpagesize = mtd->writesize >> mtd->subpage_sft; in nand_scan_tail()
4568 /* Fill in remaining MTD driver data */ in nand_scan_tail()
4569 mtd->type = nand_is_slc(chip) ? MTD_NANDFLASH : MTD_MLCNANDFLASH; in nand_scan_tail()
4570 mtd->flags = (chip->options & NAND_ROM) ? MTD_CAP_ROM : in nand_scan_tail()
4572 mtd->_erase = nand_erase; in nand_scan_tail()
4573 mtd->_panic_write = panic_nand_write; in nand_scan_tail()
4574 mtd->_read_oob = nand_read_oob; in nand_scan_tail()
4575 mtd->_write_oob = nand_write_oob; in nand_scan_tail()
4576 mtd->_sync = nand_sync; in nand_scan_tail()
4577 mtd->_lock = NULL; in nand_scan_tail()
4578 mtd->_unlock = NULL; in nand_scan_tail()
4579 mtd->_block_isreserved = nand_block_isreserved; in nand_scan_tail()
4580 mtd->_block_isbad = nand_block_isbad; in nand_scan_tail()
4581 mtd->_block_markbad = nand_block_markbad; in nand_scan_tail()
4582 mtd->writebufsize = mtd->writesize; in nand_scan_tail()
4585 mtd->ecclayout = ecc->layout; in nand_scan_tail()
4586 mtd->ecc_strength = ecc->strength; in nand_scan_tail()
4587 mtd->ecc_step_size = ecc->size; in nand_scan_tail()
4593 if (!mtd->bitflip_threshold) in nand_scan_tail()
4594 mtd->bitflip_threshold = DIV_ROUND_UP(mtd->ecc_strength * 3, 4); in nand_scan_tail()
4602 * @mtd: MTD device structure
4606 * The flash ID is read and the mtd/chip structures are filled with the
4609 int nand_scan(struct mtd_info *mtd, int maxchips) in nand_scan() argument
4613 ret = nand_scan_ident(mtd, maxchips, NULL); in nand_scan()
4615 ret = nand_scan_tail(mtd); in nand_scan()