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()
506 * @mtd: MTD device structure
511 static int nand_block_isreserved(struct mtd_info *mtd, loff_t ofs) in nand_block_isreserved() argument
513 struct nand_chip *chip = mtd_to_nand(mtd); in nand_block_isreserved()
518 return nand_isreserved_bbt(mtd, ofs); in nand_block_isreserved()
523 * @mtd: MTD device structure
530 static int nand_block_checkbad(struct mtd_info *mtd, loff_t ofs, int allowbbt) in nand_block_checkbad() argument
532 struct nand_chip *chip = mtd_to_nand(mtd); in nand_block_checkbad()
537 chip->scan_bbt(mtd); in nand_block_checkbad()
541 return chip->block_bad(mtd, ofs); in nand_block_checkbad()
544 return nand_isbad_bbt(mtd, ofs, allowbbt); in nand_block_checkbad()
549 * @mtd: MTD device structure
553 void nand_wait_ready(struct mtd_info *mtd) in nand_wait_ready() argument
555 struct nand_chip *chip = mtd_to_nand(mtd); in nand_wait_ready()
563 if (chip->dev_ready(mtd)) in nand_wait_ready()
567 if (!chip->dev_ready(mtd)) in nand_wait_ready()
574 * @mtd: MTD device structure
579 static void nand_wait_status_ready(struct mtd_info *mtd, unsigned long timeo) in nand_wait_status_ready() argument
581 register struct nand_chip *chip = mtd_to_nand(mtd); in nand_wait_status_ready()
602 * @mtd: MTD device structure
610 static void nand_command(struct mtd_info *mtd, unsigned int command, in nand_command() argument
613 register struct nand_chip *chip = mtd_to_nand(mtd); in nand_command()
620 if (column >= mtd->writesize) { in nand_command()
622 column -= mtd->writesize; in nand_command()
631 chip->cmd_ctrl(mtd, readcmd, ctrl); in nand_command()
634 chip->cmd_ctrl(mtd, command, ctrl); in nand_command()
644 chip->cmd_ctrl(mtd, column, ctrl); in nand_command()
648 chip->cmd_ctrl(mtd, page_addr, ctrl); in nand_command()
650 chip->cmd_ctrl(mtd, page_addr >> 8, ctrl); in nand_command()
652 chip->cmd_ctrl(mtd, page_addr >> 16, ctrl); in nand_command()
654 chip->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE); in nand_command()
675 chip->cmd_ctrl(mtd, NAND_CMD_STATUS, in nand_command()
677 chip->cmd_ctrl(mtd, in nand_command()
680 nand_wait_status_ready(mtd, 250); in nand_command()
700 nand_wait_ready(mtd); in nand_command()
705 * @mtd: MTD device structure
714 static void nand_command_lp(struct mtd_info *mtd, unsigned int command, in nand_command_lp() argument
717 register struct nand_chip *chip = mtd_to_nand(mtd); in nand_command_lp()
721 column += mtd->writesize; in nand_command_lp()
726 chip->cmd_ctrl(mtd, command, NAND_NCE | NAND_CLE | NAND_CTRL_CHANGE); in nand_command_lp()
737 chip->cmd_ctrl(mtd, column, ctrl); in nand_command_lp()
739 chip->cmd_ctrl(mtd, column >> 8, ctrl); in nand_command_lp()
742 chip->cmd_ctrl(mtd, page_addr, ctrl); in nand_command_lp()
743 chip->cmd_ctrl(mtd, page_addr >> 8, in nand_command_lp()
746 chip->cmd_ctrl(mtd, page_addr >> 16, in nand_command_lp()
750 chip->cmd_ctrl(mtd, NAND_CMD_NONE, NAND_NCE | NAND_CTRL_CHANGE); in nand_command_lp()
773 chip->cmd_ctrl(mtd, NAND_CMD_STATUS, in nand_command_lp()
775 chip->cmd_ctrl(mtd, NAND_CMD_NONE, in nand_command_lp()
778 nand_wait_status_ready(mtd, 250); in nand_command_lp()
783 chip->cmd_ctrl(mtd, NAND_CMD_RNDOUTSTART, in nand_command_lp()
785 chip->cmd_ctrl(mtd, NAND_CMD_NONE, in nand_command_lp()
790 chip->cmd_ctrl(mtd, NAND_CMD_READSTART, in nand_command_lp()
792 chip->cmd_ctrl(mtd, NAND_CMD_NONE, in nand_command_lp()
813 nand_wait_ready(mtd); in nand_command_lp()
819 * @mtd: MTD device structure
825 struct mtd_info *mtd, int new_state) in panic_nand_get_device() argument
834 * @mtd: MTD device structure
840 nand_get_device(struct mtd_info *mtd, int new_state) in nand_get_device() argument
842 struct nand_chip *chip = mtd_to_nand(mtd); in nand_get_device()
849 * @mtd: MTD device structure
857 static void panic_nand_wait(struct mtd_info *mtd, struct nand_chip *chip, in panic_nand_wait() argument
863 if (chip->dev_ready(mtd)) in panic_nand_wait()
883 * @mtd: MTD device structure
888 static int nand_wait(struct mtd_info *mtd, struct nand_chip *chip) in nand_wait() argument
912 if (chip->dev_ready(mtd)) in nand_wait()
946 struct mtd_info *mtd = nand_to_mtd(chip); in nand_reset_data_interface() local
968 ret = chip->setup_data_interface(mtd, chipnr, conf); in nand_reset_data_interface()
990 struct mtd_info *mtd = nand_to_mtd(chip); in nand_setup_data_interface() local
1005 ret = chip->onfi_set_features(mtd, chip, in nand_setup_data_interface()
1012 ret = chip->setup_data_interface(mtd, chipnr, chip->data_interface); in nand_setup_data_interface()
1033 struct mtd_info *mtd = nand_to_mtd(chip); in nand_init_data_interface() local
1064 ret = chip->setup_data_interface(mtd, in nand_init_data_interface()
1097 struct mtd_info *mtd = nand_to_mtd(chip); in nand_read_page_op() local
1102 if (offset_in_page + len > mtd->writesize + mtd->oobsize) in nand_read_page_op()
1105 chip->cmdfunc(mtd, NAND_CMD_READ0, offset_in_page, page); in nand_read_page_op()
1107 chip->read_buf(mtd, buf, len); in nand_read_page_op()
1128 struct mtd_info *mtd = nand_to_mtd(chip); in nand_read_param_page_op() local
1135 chip->cmdfunc(mtd, NAND_CMD_PARAM, page, -1); in nand_read_param_page_op()
1137 p[i] = chip->read_byte(mtd); in nand_read_param_page_op()
1159 struct mtd_info *mtd = nand_to_mtd(chip); in nand_change_read_column_op() local
1164 if (offset_in_page + len > mtd->writesize + mtd->oobsize) in nand_change_read_column_op()
1167 chip->cmdfunc(mtd, NAND_CMD_RNDOUT, offset_in_page, -1); in nand_change_read_column_op()
1169 chip->read_buf(mtd, buf, len); in nand_change_read_column_op()
1191 struct mtd_info *mtd = nand_to_mtd(chip); in nand_read_oob_op() local
1196 if (offset_in_oob + len > mtd->oobsize) in nand_read_oob_op()
1199 chip->cmdfunc(mtd, NAND_CMD_READOOB, offset_in_oob, page); in nand_read_oob_op()
1201 chip->read_buf(mtd, buf, len); in nand_read_oob_op()
1224 struct mtd_info *mtd = nand_to_mtd(chip); in nand_prog_page_begin_op() local
1229 if (offset_in_page + len > mtd->writesize + mtd->oobsize) in nand_prog_page_begin_op()
1232 chip->cmdfunc(mtd, NAND_CMD_SEQIN, offset_in_page, page); in nand_prog_page_begin_op()
1235 chip->write_buf(mtd, buf, len); in nand_prog_page_begin_op()
1252 struct mtd_info *mtd = nand_to_mtd(chip); in nand_prog_page_end_op() local
1255 chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1); in nand_prog_page_end_op()
1257 status = chip->waitfunc(mtd, chip); in nand_prog_page_end_op()
1282 struct mtd_info *mtd = nand_to_mtd(chip); in nand_prog_page_op() local
1288 if (offset_in_page + len > mtd->writesize + mtd->oobsize) in nand_prog_page_op()
1291 chip->cmdfunc(mtd, NAND_CMD_SEQIN, offset_in_page, page); in nand_prog_page_op()
1292 chip->write_buf(mtd, buf, len); in nand_prog_page_op()
1293 chip->cmdfunc(mtd, NAND_CMD_PAGEPROG, -1, -1); in nand_prog_page_op()
1295 status = chip->waitfunc(mtd, chip); in nand_prog_page_op()
1321 struct mtd_info *mtd = nand_to_mtd(chip); in nand_change_write_column_op() local
1326 if (offset_in_page + len > mtd->writesize + mtd->oobsize) in nand_change_write_column_op()
1329 chip->cmdfunc(mtd, NAND_CMD_RNDIN, offset_in_page, -1); in nand_change_write_column_op()
1331 chip->write_buf(mtd, buf, len); in nand_change_write_column_op()
1353 struct mtd_info *mtd = nand_to_mtd(chip); in nand_readid_op() local
1360 chip->cmdfunc(mtd, NAND_CMD_READID, addr, -1); in nand_readid_op()
1363 id[i] = chip->read_byte(mtd); in nand_readid_op()
1382 struct mtd_info *mtd = nand_to_mtd(chip); in nand_status_op() local
1384 chip->cmdfunc(mtd, NAND_CMD_STATUS, -1, -1); in nand_status_op()
1386 *status = chip->read_byte(mtd); in nand_status_op()
1405 struct mtd_info *mtd = nand_to_mtd(chip); in nand_exit_status_op() local
1407 chip->cmdfunc(mtd, NAND_CMD_READ0, -1, -1); in nand_exit_status_op()
1426 struct mtd_info *mtd = nand_to_mtd(chip); in nand_erase_op() local
1431 chip->cmdfunc(mtd, NAND_CMD_ERASE1, -1, page); in nand_erase_op()
1432 chip->cmdfunc(mtd, NAND_CMD_ERASE2, -1, -1); in nand_erase_op()
1434 status = chip->waitfunc(mtd, chip); in nand_erase_op()
1460 struct mtd_info *mtd = nand_to_mtd(chip); in nand_set_features_op() local
1464 chip->cmdfunc(mtd, NAND_CMD_SET_FEATURES, feature, -1); in nand_set_features_op()
1466 chip->write_byte(mtd, params[i]); in nand_set_features_op()
1468 status = chip->waitfunc(mtd, chip); in nand_set_features_op()
1490 struct mtd_info *mtd = nand_to_mtd(chip); in nand_get_features_op() local
1494 chip->cmdfunc(mtd, NAND_CMD_GET_FEATURES, feature, -1); in nand_get_features_op()
1496 params[i] = chip->read_byte(mtd); in nand_get_features_op()
1513 struct mtd_info *mtd = nand_to_mtd(chip); in nand_reset_op() local
1515 chip->cmdfunc(mtd, NAND_CMD_RESET, -1, -1); in nand_reset_op()
1537 struct mtd_info *mtd = nand_to_mtd(chip); in nand_read_data_op() local
1547 p[i] = chip->read_byte(mtd); in nand_read_data_op()
1549 chip->read_buf(mtd, buf, len); in nand_read_data_op()
1572 struct mtd_info *mtd = nand_to_mtd(chip); in nand_write_data_op() local
1582 chip->write_byte(mtd, p[i]); in nand_write_data_op()
1584 chip->write_buf(mtd, buf, len); in nand_write_data_op()
1600 struct mtd_info *mtd = nand_to_mtd(chip); in nand_reset() local
1611 chip->select_chip(mtd, chipnr); in nand_reset()
1613 chip->select_chip(mtd, -1); in nand_reset()
1617 chip->select_chip(mtd, chipnr); in nand_reset()
1619 chip->select_chip(mtd, -1); in nand_reset()
1755 * @mtd: mtd info structure
1763 static int nand_read_page_raw(struct mtd_info *mtd, struct nand_chip *chip, in nand_read_page_raw() argument
1768 ret = nand_read_data_op(chip, buf, mtd->writesize, false); in nand_read_page_raw()
1773 ret = nand_read_data_op(chip, chip->oob_poi, mtd->oobsize, in nand_read_page_raw()
1784 * @mtd: mtd info structure
1792 static int nand_read_page_raw_syndrome(struct mtd_info *mtd, in nand_read_page_raw_syndrome() argument
1833 size = mtd->oobsize - (oob - chip->oob_poi); in nand_read_page_raw_syndrome()
1845 * @mtd: mtd info structure
1851 static int nand_read_page_swecc(struct mtd_info *mtd, struct nand_chip *chip, in nand_read_page_swecc() argument
1863 chip->ecc.read_page_raw(mtd, chip, buf, 1, page); in nand_read_page_swecc()
1866 chip->ecc.calculate(mtd, p, &ecc_calc[i]); in nand_read_page_swecc()
1877 stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]); in nand_read_page_swecc()
1879 mtd->ecc_stats.failed++; in nand_read_page_swecc()
1881 mtd->ecc_stats.corrected += stat; in nand_read_page_swecc()
1890 * @mtd: mtd info structure
1897 static int nand_read_subpage(struct mtd_info *mtd, struct nand_chip *chip, in nand_read_subpage() argument
1924 chip->cmdfunc(mtd, NAND_CMD_RNDOUT, data_col_addr, -1); in nand_read_subpage()
1933 chip->ecc.calculate(mtd, p, &chip->buffers->ecccalc[i]); in nand_read_subpage()
1946 ret = nand_change_read_column_op(chip, mtd->writesize, in nand_read_subpage()
1947 chip->oob_poi, mtd->oobsize, in nand_read_subpage()
1964 mtd->writesize + aligned_pos, in nand_read_subpage()
1978 stat = chip->ecc.correct(mtd, p, in nand_read_subpage()
1991 mtd->ecc_stats.failed++; in nand_read_subpage()
1993 mtd->ecc_stats.corrected += stat; in nand_read_subpage()
2002 * @mtd: mtd info structure
2010 static int nand_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, in nand_read_page_hwecc() argument
2024 chip->ecc.hwctl(mtd, NAND_ECC_READ); in nand_read_page_hwecc()
2030 chip->ecc.calculate(mtd, p, &ecc_calc[i]); in nand_read_page_hwecc()
2033 ret = nand_read_data_op(chip, chip->oob_poi, mtd->oobsize, false); in nand_read_page_hwecc()
2046 stat = chip->ecc.correct(mtd, p, &ecc_code[i], &ecc_calc[i]); in nand_read_page_hwecc()
2057 mtd->ecc_stats.failed++; in nand_read_page_hwecc()
2059 mtd->ecc_stats.corrected += stat; in nand_read_page_hwecc()
2068 * @mtd: mtd info structure
2080 static int nand_read_page_hwecc_oob_first(struct mtd_info *mtd, in nand_read_page_hwecc_oob_first() argument
2094 ret = nand_read_oob_op(chip, page, 0, chip->oob_poi, mtd->oobsize); in nand_read_page_hwecc_oob_first()
2108 chip->ecc.hwctl(mtd, NAND_ECC_READ); in nand_read_page_hwecc_oob_first()
2114 chip->ecc.calculate(mtd, p, &ecc_calc[i]); in nand_read_page_hwecc_oob_first()
2116 stat = chip->ecc.correct(mtd, p, &ecc_code[i], NULL); in nand_read_page_hwecc_oob_first()
2127 mtd->ecc_stats.failed++; in nand_read_page_hwecc_oob_first()
2129 mtd->ecc_stats.corrected += stat; in nand_read_page_hwecc_oob_first()
2138 * @mtd: mtd info structure
2147 static int nand_read_page_syndrome(struct mtd_info *mtd, struct nand_chip *chip, in nand_read_page_syndrome() argument
2161 chip->ecc.hwctl(mtd, NAND_ECC_READ); in nand_read_page_syndrome()
2176 chip->ecc.hwctl(mtd, NAND_ECC_READSYN); in nand_read_page_syndrome()
2182 stat = chip->ecc.correct(mtd, p, oob, NULL); in nand_read_page_syndrome()
2206 mtd->ecc_stats.failed++; in nand_read_page_syndrome()
2208 mtd->ecc_stats.corrected += stat; in nand_read_page_syndrome()
2214 i = mtd->oobsize - (oob - chip->oob_poi); in nand_read_page_syndrome()
2274 * @mtd: MTD device structure
2281 static int nand_setup_read_retry(struct mtd_info *mtd, int retry_mode) in nand_setup_read_retry() argument
2283 struct nand_chip *chip = mtd_to_nand(mtd); in nand_setup_read_retry()
2293 return chip->setup_read_retry(mtd, retry_mode); in nand_setup_read_retry()
2298 * @mtd: MTD device structure
2304 static int nand_do_read_ops(struct mtd_info *mtd, loff_t from, in nand_do_read_ops() argument
2308 struct nand_chip *chip = mtd_to_nand(mtd); in nand_do_read_ops()
2312 uint32_t max_oobsize = mtd_oobavail(mtd, ops); in nand_do_read_ops()
2321 chip->select_chip(mtd, chipnr); in nand_do_read_ops()
2326 col = (int)(from & (mtd->writesize - 1)); in nand_do_read_ops()
2333 unsigned int ecc_failures = mtd->ecc_stats.failed; in nand_do_read_ops()
2336 bytes = min(mtd->writesize - col, readlen); in nand_do_read_ops()
2337 aligned = (bytes == mtd->writesize); in nand_do_read_ops()
2367 ret = chip->ecc.read_page_raw(mtd, chip, bufpoi, in nand_do_read_ops()
2372 ret = chip->ecc.read_subpage(mtd, chip, in nand_do_read_ops()
2376 ret = chip->ecc.read_page(mtd, chip, bufpoi, in nand_do_read_ops()
2390 !(mtd->ecc_stats.failed - ecc_failures) && in nand_do_read_ops()
2416 nand_wait_ready(mtd); in nand_do_read_ops()
2419 if (mtd->ecc_stats.failed - ecc_failures) { in nand_do_read_ops()
2422 ret = nand_setup_read_retry(mtd, in nand_do_read_ops()
2428 mtd->ecc_stats.failed = ecc_failures; in nand_do_read_ops()
2448 ret = nand_setup_read_retry(mtd, 0); in nand_do_read_ops()
2466 chip->select_chip(mtd, -1); in nand_do_read_ops()
2467 chip->select_chip(mtd, chipnr); in nand_do_read_ops()
2470 chip->select_chip(mtd, -1); in nand_do_read_ops()
2487 * @mtd: mtd info structure
2491 static int nand_read_oob_std(struct mtd_info *mtd, struct nand_chip *chip, in nand_read_oob_std() argument
2494 return nand_read_oob_op(chip, page, 0, chip->oob_poi, mtd->oobsize); in nand_read_oob_std()
2500 * @mtd: mtd info structure
2504 static int nand_read_oob_syndrome(struct mtd_info *mtd, struct nand_chip *chip, in nand_read_oob_syndrome() argument
2507 int length = mtd->oobsize; in nand_read_oob_syndrome()
2522 if (mtd->writesize > 512) in nand_read_oob_syndrome()
2554 * @mtd: mtd info structure
2558 static int nand_write_oob_std(struct mtd_info *mtd, struct nand_chip *chip, in nand_write_oob_std() argument
2561 return nand_prog_page_op(chip, page, mtd->writesize, chip->oob_poi, in nand_write_oob_std()
2562 mtd->oobsize); in nand_write_oob_std()
2568 * @mtd: mtd info structure
2572 static int nand_write_oob_syndrome(struct mtd_info *mtd, in nand_write_oob_syndrome() argument
2576 int eccsize = chip->ecc.size, length = mtd->oobsize; in nand_write_oob_syndrome()
2597 if (mtd->writesize <= 512) { in nand_write_oob_syndrome()
2641 * @mtd: MTD device structure
2647 static int nand_do_read_oob(struct mtd_info *mtd, loff_t from, in nand_do_read_oob() argument
2651 struct nand_chip *chip = mtd_to_nand(mtd); in nand_do_read_oob()
2661 stats = mtd->ecc_stats; in nand_do_read_oob()
2663 len = mtd_oobavail(mtd, ops); in nand_do_read_oob()
2672 if (unlikely(from >= mtd->size || in nand_do_read_oob()
2673 ops->ooboffs + readlen > ((mtd->size >> chip->page_shift) - in nand_do_read_oob()
2681 chip->select_chip(mtd, chipnr); in nand_do_read_oob()
2691 ret = chip->ecc.read_oob_raw(mtd, chip, page); in nand_do_read_oob()
2693 ret = chip->ecc.read_oob(mtd, chip, page); in nand_do_read_oob()
2706 nand_wait_ready(mtd); in nand_do_read_oob()
2720 chip->select_chip(mtd, -1); in nand_do_read_oob()
2721 chip->select_chip(mtd, chipnr); in nand_do_read_oob()
2724 chip->select_chip(mtd, -1); in nand_do_read_oob()
2731 if (mtd->ecc_stats.failed - stats.failed) in nand_do_read_oob()
2734 return mtd->ecc_stats.corrected - stats.corrected ? -EUCLEAN : 0; in nand_do_read_oob()
2738 * nand_read_oob - [MTD Interface] NAND read data and/or out-of-band
2739 * @mtd: MTD device structure
2745 static int nand_read_oob(struct mtd_info *mtd, loff_t from, in nand_read_oob() argument
2753 if (ops->datbuf && (from + ops->len) > mtd->size) { in nand_read_oob()
2759 nand_get_device(mtd, FL_READING); in nand_read_oob()
2772 ret = nand_do_read_oob(mtd, from, ops); in nand_read_oob()
2774 ret = nand_do_read_ops(mtd, from, ops); in nand_read_oob()
2777 nand_release_device(mtd); in nand_read_oob()
2784 * @mtd: mtd info structure
2792 static int nand_write_page_raw(struct mtd_info *mtd, struct nand_chip *chip, in nand_write_page_raw() argument
2797 ret = nand_write_data_op(chip, buf, mtd->writesize, false); in nand_write_page_raw()
2802 ret = nand_write_data_op(chip, chip->oob_poi, mtd->oobsize, in nand_write_page_raw()
2813 * @mtd: mtd info structure
2821 static int nand_write_page_raw_syndrome(struct mtd_info *mtd, in nand_write_page_raw_syndrome() argument
2863 size = mtd->oobsize - (oob - chip->oob_poi); in nand_write_page_raw_syndrome()
2874 * @mtd: mtd info structure
2880 static int nand_write_page_swecc(struct mtd_info *mtd, struct nand_chip *chip, in nand_write_page_swecc() argument
2893 chip->ecc.calculate(mtd, p, &ecc_calc[i]); in nand_write_page_swecc()
2898 return chip->ecc.write_page_raw(mtd, chip, buf, 1, page); in nand_write_page_swecc()
2903 * @mtd: mtd info structure
2909 static int nand_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip, in nand_write_page_hwecc() argument
2922 chip->ecc.hwctl(mtd, NAND_ECC_WRITE); in nand_write_page_hwecc()
2928 chip->ecc.calculate(mtd, p, &ecc_calc[i]); in nand_write_page_hwecc()
2934 ret = nand_write_data_op(chip, chip->oob_poi, mtd->oobsize, false); in nand_write_page_hwecc()
2944 * @mtd: mtd info structure
2952 static int nand_write_subpage_hwecc(struct mtd_info *mtd, in nand_write_subpage_hwecc() argument
2965 int oob_bytes = mtd->oobsize / ecc_steps; in nand_write_subpage_hwecc()
2971 chip->ecc.hwctl(mtd, NAND_ECC_WRITE); in nand_write_subpage_hwecc()
2982 chip->ecc.calculate(mtd, buf, ecc_calc); in nand_write_subpage_hwecc()
3001 ret = nand_write_data_op(chip, chip->oob_poi, mtd->oobsize, false); in nand_write_subpage_hwecc()
3011 * @mtd: mtd info structure
3020 static int nand_write_page_syndrome(struct mtd_info *mtd, in nand_write_page_syndrome() argument
3033 chip->ecc.hwctl(mtd, NAND_ECC_WRITE); in nand_write_page_syndrome()
3048 chip->ecc.calculate(mtd, p, oob); in nand_write_page_syndrome()
3067 i = mtd->oobsize - (oob - chip->oob_poi); in nand_write_page_syndrome()
3079 * @mtd: MTD device structure
3088 static int nand_write_page(struct mtd_info *mtd, struct nand_chip *chip, in nand_write_page() argument
3096 subpage = offset || (data_len < mtd->writesize); in nand_write_page()
3107 status = chip->ecc.write_page_raw(mtd, chip, buf, in nand_write_page()
3110 status = chip->ecc.write_subpage(mtd, chip, offset, data_len, in nand_write_page()
3113 status = chip->ecc.write_page(mtd, chip, buf, oob_required, in nand_write_page()
3127 * @mtd: MTD device structure
3132 static uint8_t *nand_fill_oob(struct mtd_info *mtd, uint8_t *oob, size_t len, in nand_fill_oob() argument
3135 struct nand_chip *chip = mtd_to_nand(mtd); in nand_fill_oob()
3141 memset(chip->oob_poi, 0xff, mtd->oobsize); in nand_fill_oob()
3185 * @mtd: MTD device structure
3191 static int nand_do_write_ops(struct mtd_info *mtd, loff_t to, in nand_do_write_ops() argument
3195 struct nand_chip *chip = mtd_to_nand(mtd); in nand_do_write_ops()
3199 uint32_t oobmaxlen = mtd_oobavail(mtd, ops); in nand_do_write_ops()
3217 column = to & (mtd->writesize - 1); in nand_do_write_ops()
3220 chip->select_chip(mtd, chipnr); in nand_do_write_ops()
3223 if (nand_check_wp(mtd)) { in nand_do_write_ops()
3243 int bytes = mtd->writesize; in nand_do_write_ops()
3246 int part_pagewr = (column || writelen < mtd->writesize); in nand_do_write_ops()
3264 memset(chip->buffers->databuf, 0xff, mtd->writesize); in nand_do_write_ops()
3271 oob = nand_fill_oob(mtd, oob, len, ops); in nand_do_write_ops()
3275 memset(chip->oob_poi, 0xff, mtd->oobsize); in nand_do_write_ops()
3277 ret = chip->write_page(mtd, chip, column, bytes, wbuf, in nand_do_write_ops()
3295 chip->select_chip(mtd, -1); in nand_do_write_ops()
3296 chip->select_chip(mtd, chipnr); in nand_do_write_ops()
3305 chip->select_chip(mtd, -1); in nand_do_write_ops()
3310 * panic_nand_write - [MTD Interface] NAND write with ECC
3311 * @mtd: MTD device structure
3320 static int panic_nand_write(struct mtd_info *mtd, loff_t to, size_t len, in panic_nand_write() argument
3323 struct nand_chip *chip = mtd_to_nand(mtd); in panic_nand_write()
3328 panic_nand_wait(mtd, chip, 400); in panic_nand_write()
3331 panic_nand_get_device(chip, mtd, FL_WRITING); in panic_nand_write()
3338 ret = nand_do_write_ops(mtd, to, &ops); in panic_nand_write()
3345 * nand_do_write_oob - [MTD Interface] NAND write out-of-band
3346 * @mtd: MTD device structure
3352 static int nand_do_write_oob(struct mtd_info *mtd, loff_t to, in nand_do_write_oob() argument
3356 struct nand_chip *chip = mtd_to_nand(mtd); in nand_do_write_oob()
3361 len = mtd_oobavail(mtd, ops); in nand_do_write_oob()
3377 if (unlikely(to >= mtd->size || in nand_do_write_oob()
3379 ((mtd->size >> chip->page_shift) - in nand_do_write_oob()
3396 chip->select_chip(mtd, chipnr); in nand_do_write_oob()
3402 if (nand_check_wp(mtd)) { in nand_do_write_oob()
3403 chip->select_chip(mtd, -1); in nand_do_write_oob()
3411 nand_fill_oob(mtd, ops->oobbuf, ops->ooblen, ops); in nand_do_write_oob()
3414 status = chip->ecc.write_oob_raw(mtd, chip, page & chip->pagemask); in nand_do_write_oob()
3416 status = chip->ecc.write_oob(mtd, chip, page & chip->pagemask); in nand_do_write_oob()
3418 chip->select_chip(mtd, -1); in nand_do_write_oob()
3429 * nand_write_oob - [MTD Interface] NAND write data and/or out-of-band
3430 * @mtd: MTD device structure
3434 static int nand_write_oob(struct mtd_info *mtd, loff_t to, in nand_write_oob() argument
3442 if (ops->datbuf && (to + ops->len) > mtd->size) { in nand_write_oob()
3448 nand_get_device(mtd, FL_WRITING); in nand_write_oob()
3461 ret = nand_do_write_oob(mtd, to, ops); in nand_write_oob()
3463 ret = nand_do_write_ops(mtd, to, ops); in nand_write_oob()
3466 nand_release_device(mtd); in nand_write_oob()
3472 * @mtd: MTD device structure
3477 static int single_erase(struct mtd_info *mtd, int page) in single_erase() argument
3479 struct nand_chip *chip = mtd_to_nand(mtd); in single_erase()
3489 * nand_erase - [MTD Interface] erase block(s)
3490 * @mtd: MTD device structure
3495 static int nand_erase(struct mtd_info *mtd, struct erase_info *instr) in nand_erase() argument
3497 return nand_erase_nand(mtd, instr, 0); in nand_erase()
3502 * @mtd: MTD device structure
3508 int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr, in nand_erase_nand() argument
3512 struct nand_chip *chip = mtd_to_nand(mtd); in nand_erase_nand()
3519 if (check_offs_len(mtd, instr->addr, instr->len)) in nand_erase_nand()
3523 nand_get_device(mtd, FL_ERASING); in nand_erase_nand()
3533 chip->select_chip(mtd, chipnr); in nand_erase_nand()
3536 if (nand_check_wp(mtd)) { in nand_erase_nand()
3552 if (!instr->scrub && nand_block_checkbad(mtd, ((loff_t) page) << in nand_erase_nand()
3568 status = chip->erase(mtd, page & chip->pagemask); in nand_erase_nand()
3587 chip->select_chip(mtd, -1); in nand_erase_nand()
3588 chip->select_chip(mtd, chipnr); in nand_erase_nand()
3598 chip->select_chip(mtd, -1); in nand_erase_nand()
3599 nand_release_device(mtd); in nand_erase_nand()
3610 * nand_sync - [MTD Interface] sync
3611 * @mtd: MTD device structure
3615 static void nand_sync(struct mtd_info *mtd) in nand_sync() argument
3620 nand_get_device(mtd, FL_SYNCING); in nand_sync()
3622 nand_release_device(mtd); in nand_sync()
3626 * nand_block_isbad - [MTD Interface] Check if block at offset is bad
3627 * @mtd: MTD device structure
3628 * @offs: offset relative to mtd start
3630 static int nand_block_isbad(struct mtd_info *mtd, loff_t offs) in nand_block_isbad() argument
3632 struct nand_chip *chip = mtd_to_nand(mtd); in nand_block_isbad()
3637 nand_get_device(mtd, FL_READING); in nand_block_isbad()
3638 chip->select_chip(mtd, chipnr); in nand_block_isbad()
3640 ret = nand_block_checkbad(mtd, offs, 0); in nand_block_isbad()
3642 chip->select_chip(mtd, -1); in nand_block_isbad()
3643 nand_release_device(mtd); in nand_block_isbad()
3649 * nand_block_markbad - [MTD Interface] Mark block at the given offset as bad
3650 * @mtd: MTD device structure
3651 * @ofs: offset relative to mtd start
3653 static int nand_block_markbad(struct mtd_info *mtd, loff_t ofs) in nand_block_markbad() argument
3657 ret = nand_block_isbad(mtd, ofs); in nand_block_markbad()
3665 return nand_block_markbad_lowlevel(mtd, ofs); in nand_block_markbad()
3670 * @mtd: MTD device structure
3675 static int nand_onfi_set_features(struct mtd_info *mtd, struct nand_chip *chip, in nand_onfi_set_features() argument
3690 * @mtd: MTD device structure
3695 static int nand_onfi_get_features(struct mtd_info *mtd, struct nand_chip *chip, in nand_onfi_get_features() argument
3792 static int nand_flash_detect_ext_param_page(struct mtd_info *mtd, in nand_flash_detect_ext_param_page() argument
3866 static int nand_setup_read_retry_micron(struct mtd_info *mtd, int retry_mode) in nand_setup_read_retry_micron() argument
3868 struct nand_chip *chip = mtd_to_nand(mtd); in nand_setup_read_retry_micron()
3871 return chip->onfi_set_features(mtd, chip, ONFI_FEATURE_ADDR_READ_RETRY, in nand_setup_read_retry_micron()
3893 static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, in nand_flash_detect_onfi() argument
3945 if (!mtd->name) in nand_flash_detect_onfi()
3946 mtd->name = p->model; in nand_flash_detect_onfi()
3948 mtd->writesize = le32_to_cpu(p->byte_per_page); in nand_flash_detect_onfi()
3952 * (don't ask me who thought of this...). MTD assumes that these in nand_flash_detect_onfi()
3955 mtd->erasesize = 1 << (fls(le32_to_cpu(p->pages_per_block)) - 1); in nand_flash_detect_onfi()
3956 mtd->erasesize *= mtd->writesize; in nand_flash_detect_onfi()
3958 mtd->oobsize = le16_to_cpu(p->spare_bytes_per_page); in nand_flash_detect_onfi()
3962 chip->chipsize *= (uint64_t)mtd->erasesize * p->lun_count; in nand_flash_detect_onfi()
3982 if (mtd->writesize > 512 && chip->cmdfunc == nand_command) in nand_flash_detect_onfi()
3986 if (nand_flash_detect_ext_param_page(mtd, chip, p)) in nand_flash_detect_onfi()
3998 static int nand_flash_detect_onfi(struct mtd_info *mtd, struct nand_chip *chip, in nand_flash_detect_onfi() argument
4008 static int nand_flash_detect_jedec(struct mtd_info *mtd, struct nand_chip *chip, in nand_flash_detect_jedec() argument
4054 if (!mtd->name) in nand_flash_detect_jedec()
4055 mtd->name = p->model; in nand_flash_detect_jedec()
4057 mtd->writesize = le32_to_cpu(p->byte_per_page); in nand_flash_detect_jedec()
4060 mtd->erasesize = 1 << (fls(le32_to_cpu(p->pages_per_block)) - 1); in nand_flash_detect_jedec()
4061 mtd->erasesize *= mtd->writesize; in nand_flash_detect_jedec()
4063 mtd->oobsize = le16_to_cpu(p->spare_bytes_per_page); in nand_flash_detect_jedec()
4067 chip->chipsize *= (uint64_t)mtd->erasesize * p->lun_count; in nand_flash_detect_jedec()
4162 static void nand_decode_ext_id(struct mtd_info *mtd, struct nand_chip *chip, in nand_decode_ext_id() argument
4185 mtd->writesize = 2048 << (extid & 0x03); in nand_decode_ext_id()
4190 mtd->oobsize = 128; in nand_decode_ext_id()
4193 mtd->oobsize = 218; in nand_decode_ext_id()
4196 mtd->oobsize = 400; in nand_decode_ext_id()
4199 mtd->oobsize = 436; in nand_decode_ext_id()
4202 mtd->oobsize = 512; in nand_decode_ext_id()
4205 mtd->oobsize = 640; in nand_decode_ext_id()
4209 mtd->oobsize = 1024; in nand_decode_ext_id()
4214 mtd->erasesize = (128 * 1024) << in nand_decode_ext_id()
4222 mtd->writesize = 2048 << (extid & 0x03); in nand_decode_ext_id()
4227 mtd->oobsize = 128; in nand_decode_ext_id()
4230 mtd->oobsize = 224; in nand_decode_ext_id()
4233 mtd->oobsize = 448; in nand_decode_ext_id()
4236 mtd->oobsize = 64; in nand_decode_ext_id()
4239 mtd->oobsize = 32; in nand_decode_ext_id()
4242 mtd->oobsize = 16; in nand_decode_ext_id()
4245 mtd->oobsize = 640; in nand_decode_ext_id()
4252 mtd->erasesize = (128 * 1024) << tmp; in nand_decode_ext_id()
4254 mtd->erasesize = 768 * 1024; in nand_decode_ext_id()
4256 mtd->erasesize = (64 * 1024) << tmp; in nand_decode_ext_id()
4260 mtd->writesize = 1024 << (extid & 0x03); in nand_decode_ext_id()
4263 mtd->oobsize = (8 << (extid & 0x01)) * in nand_decode_ext_id()
4264 (mtd->writesize >> 9); in nand_decode_ext_id()
4267 mtd->erasesize = (64 * 1024) << (extid & 0x03); in nand_decode_ext_id()
4284 mtd->oobsize = 32 * mtd->writesize >> 9; in nand_decode_ext_id()
4292 * decodes a matching ID table entry and assigns the MTD size parameters for
4295 static void nand_decode_id(struct mtd_info *mtd, struct nand_chip *chip, in nand_decode_id() argument
4301 mtd->erasesize = type->erasesize; in nand_decode_id()
4302 mtd->writesize = type->pagesize; in nand_decode_id()
4303 mtd->oobsize = mtd->writesize / 32; in nand_decode_id()
4317 && mtd->writesize == 512) { in nand_decode_id()
4318 mtd->erasesize = 128 * 1024; in nand_decode_id()
4319 mtd->erasesize <<= ((id_data[3] & 0x03) << 1); in nand_decode_id()
4328 static void nand_decode_bbm_options(struct mtd_info *mtd, in nand_decode_bbm_options() argument
4334 if (mtd->writesize > 512 || (chip->options & NAND_BUSWIDTH_16)) in nand_decode_bbm_options()
4355 (mtd->writesize == 2048 && in nand_decode_bbm_options()
4365 static bool find_full_id_nand(struct mtd_info *mtd, struct nand_chip *chip, in find_full_id_nand() argument
4369 mtd->writesize = type->pagesize; in find_full_id_nand()
4370 mtd->erasesize = type->erasesize; in find_full_id_nand()
4371 mtd->oobsize = type->oobsize; in find_full_id_nand()
4383 if (!mtd->name) in find_full_id_nand()
4384 mtd->name = type->name; in find_full_id_nand()
4394 struct nand_flash_dev *nand_get_flash_type(struct mtd_info *mtd, in nand_get_flash_type() argument
4412 chip->select_chip(mtd, 0); in nand_get_flash_type()
4446 if (find_full_id_nand(mtd, chip, type, id_data, &busw)) in nand_get_flash_type()
4456 if (nand_flash_detect_onfi(mtd, chip, &busw)) in nand_get_flash_type()
4460 if (nand_flash_detect_jedec(mtd, chip, &busw)) in nand_get_flash_type()
4467 if (!mtd->name) in nand_get_flash_type()
4468 mtd->name = type->name; in nand_get_flash_type()
4474 nand_decode_ext_id(mtd, chip, id_data, &busw); in nand_get_flash_type()
4476 nand_decode_id(mtd, chip, type, id_data, &busw); in nand_get_flash_type()
4506 pr_info("%s %s\n", nand_manuf_ids[maf_idx].name, mtd->name); in nand_get_flash_type()
4513 nand_decode_bbm_options(mtd, chip, id_data); in nand_get_flash_type()
4516 chip->page_shift = ffs(mtd->writesize) - 1; in nand_get_flash_type()
4521 ffs(mtd->erasesize) - 1; in nand_get_flash_type()
4536 if (mtd->writesize > 512 && chip->cmdfunc == nand_command) in nand_get_flash_type()
4566 mtd->erasesize >> 10, mtd->writesize, mtd->oobsize); in nand_get_flash_type()
4574 static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, int node) in nand_dt_init() argument
4628 static int nand_dt_init(struct mtd_info *mtd, struct nand_chip *chip, int node) in nand_dt_init() argument
4636 * @mtd: MTD device structure
4641 * flash ID and sets up MTD fields accordingly.
4644 int nand_scan_ident(struct mtd_info *mtd, int maxchips, in nand_scan_ident() argument
4648 struct nand_chip *chip = mtd_to_nand(mtd); in nand_scan_ident()
4653 ret = nand_dt_init(mtd, chip, chip->flash_node); in nand_scan_ident()
4662 type = nand_get_flash_type(mtd, chip, &nand_maf_id, in nand_scan_ident()
4668 chip->select_chip(mtd, -1); in nand_scan_ident()
4689 chip->select_chip(mtd, -1); in nand_scan_ident()
4698 chip->select_chip(mtd, i); in nand_scan_ident()
4704 chip->select_chip(mtd, -1); in nand_scan_ident()
4707 chip->select_chip(mtd, -1); in nand_scan_ident()
4715 /* Store the number of chips and calc total size for mtd */ in nand_scan_ident()
4717 mtd->size = i * chip->chipsize; in nand_scan_ident()
4736 struct mtd_info *mtd = nand_to_mtd(chip); in nand_check_ecc_caps() local
4749 nsteps = mtd->writesize / preset_step; in nand_check_ecc_caps()
4798 struct mtd_info *mtd = nand_to_mtd(chip); in nand_match_ecc_req() local
4815 req_corr = mtd->writesize / req_step * req_strength; in nand_match_ecc_req()
4832 if (mtd->writesize % step_size) in nand_match_ecc_req()
4835 nsteps = mtd->writesize / step_size; in nand_match_ecc_req()
4882 struct mtd_info *mtd = nand_to_mtd(chip); in nand_maximize_ecc() local
4904 if (mtd->writesize % step_size) in nand_maximize_ecc()
4907 nsteps = mtd->writesize / step_size; in nand_maximize_ecc()
4957 static bool nand_ecc_strength_good(struct mtd_info *mtd) in nand_ecc_strength_good() argument
4959 struct nand_chip *chip = mtd_to_nand(mtd); in nand_ecc_strength_good()
4971 corr = (mtd->writesize * ecc->strength) / ecc->size; in nand_ecc_strength_good()
4972 ds_corr = (mtd->writesize * chip->ecc_strength_ds) / chip->ecc_step_ds; in nand_ecc_strength_good()
4999 * @mtd: MTD device structure
5005 int nand_scan_tail(struct mtd_info *mtd) in nand_scan_tail() argument
5008 struct nand_chip *chip = mtd_to_nand(mtd); in nand_scan_tail()
5030 chip->oob_poi = chip->buffers->databuf + mtd->writesize; in nand_scan_tail()
5036 switch (mtd->oobsize) { in nand_scan_tail()
5053 mtd->oobsize); in nand_scan_tail()
5118 if (mtd->writesize >= ecc->size) { in nand_scan_tail()
5126 ecc->size, mtd->writesize); in nand_scan_tail()
5164 if (!ecc->size && (mtd->oobsize >= 64)) { in nand_scan_tail()
5171 ecc->priv = nand_bch_init(mtd); in nand_scan_tail()
5186 ecc->size = mtd->writesize; in nand_scan_tail()
5206 mtd->oobavail = 0; in nand_scan_tail()
5209 mtd->oobavail += ecc->layout->oobfree[i].length; in nand_scan_tail()
5213 if (!nand_ecc_strength_good(mtd)) in nand_scan_tail()
5215 mtd->name); in nand_scan_tail()
5221 ecc->steps = mtd->writesize / ecc->size; in nand_scan_tail()
5222 if (ecc->steps * ecc->size != mtd->writesize) { in nand_scan_tail()
5232 mtd->subpage_sft = 1; in nand_scan_tail()
5237 mtd->subpage_sft = 2; in nand_scan_tail()
5241 chip->subpagesize = mtd->writesize >> mtd->subpage_sft; in nand_scan_tail()
5261 /* Fill in remaining MTD driver data */ in nand_scan_tail()
5262 mtd->type = nand_is_slc(chip) ? MTD_NANDFLASH : MTD_MLCNANDFLASH; in nand_scan_tail()
5263 mtd->flags = (chip->options & NAND_ROM) ? MTD_CAP_ROM : in nand_scan_tail()
5265 mtd->_erase = nand_erase; in nand_scan_tail()
5266 mtd->_panic_write = panic_nand_write; in nand_scan_tail()
5267 mtd->_read_oob = nand_read_oob; in nand_scan_tail()
5268 mtd->_write_oob = nand_write_oob; in nand_scan_tail()
5269 mtd->_sync = nand_sync; in nand_scan_tail()
5270 mtd->_lock = NULL; in nand_scan_tail()
5271 mtd->_unlock = NULL; in nand_scan_tail()
5272 mtd->_block_isreserved = nand_block_isreserved; in nand_scan_tail()
5273 mtd->_block_isbad = nand_block_isbad; in nand_scan_tail()
5274 mtd->_block_markbad = nand_block_markbad; in nand_scan_tail()
5275 mtd->writebufsize = mtd->writesize; in nand_scan_tail()
5278 mtd->ecclayout = ecc->layout; in nand_scan_tail()
5279 mtd->ecc_strength = ecc->strength; in nand_scan_tail()
5280 mtd->ecc_step_size = ecc->size; in nand_scan_tail()
5286 if (!mtd->bitflip_threshold) in nand_scan_tail()
5287 mtd->bitflip_threshold = DIV_ROUND_UP(mtd->ecc_strength * 3, 4); in nand_scan_tail()
5295 * @mtd: MTD device structure
5299 * The flash ID is read and the mtd/chip structures are filled with the
5302 int nand_scan(struct mtd_info *mtd, int maxchips) in nand_scan() argument
5306 ret = nand_scan_ident(mtd, maxchips, NULL); in nand_scan()
5308 ret = nand_scan_tail(mtd); in nand_scan()