Lines Matching refs:chip
99 static int check_offs_len(struct nand_chip *chip, loff_t ofs, uint64_t len) in check_offs_len() argument
104 if (ofs & ((1ULL << chip->phys_erase_shift) - 1)) { in check_offs_len()
110 if (len & ((1ULL << chip->phys_erase_shift) - 1)) { in check_offs_len()
171 void nand_select_target(struct nand_chip *chip, unsigned int cs) in nand_select_target() argument
177 if (WARN_ON(cs > nanddev_ntargets(&chip->base))) in nand_select_target()
180 chip->cur_cs = cs; in nand_select_target()
182 if (chip->legacy.select_chip) in nand_select_target()
183 chip->legacy.select_chip(chip, cs); in nand_select_target()
194 void nand_deselect_target(struct nand_chip *chip) in nand_deselect_target() argument
196 if (chip->legacy.select_chip) in nand_deselect_target()
197 chip->legacy.select_chip(chip, -1); in nand_deselect_target()
199 chip->cur_cs = -1; in nand_deselect_target()
209 static void nand_release_device(struct nand_chip *chip) in nand_release_device() argument
212 mutex_unlock(&chip->controller->lock); in nand_release_device()
213 mutex_unlock(&chip->lock); in nand_release_device()
225 int nand_bbm_get_next_page(struct nand_chip *chip, int page) in nand_bbm_get_next_page() argument
227 struct mtd_info *mtd = nand_to_mtd(chip); in nand_bbm_get_next_page()
229 chip->page_shift) & chip->pagemask; in nand_bbm_get_next_page()
233 if (page == 0 && !(chip->options & bbm_flags)) in nand_bbm_get_next_page()
235 if (page == 0 && chip->options & NAND_BBM_FIRSTPAGE) in nand_bbm_get_next_page()
237 if (page <= 1 && chip->options & NAND_BBM_SECONDPAGE) in nand_bbm_get_next_page()
239 if (page <= last_page && chip->options & NAND_BBM_LASTPAGE) in nand_bbm_get_next_page()
252 static int nand_block_bad(struct nand_chip *chip, loff_t ofs) in nand_block_bad() argument
258 first_page = (int)(ofs >> chip->page_shift) & chip->pagemask; in nand_block_bad()
259 page_offset = nand_bbm_get_next_page(chip, 0); in nand_block_bad()
262 res = chip->ecc.read_oob(chip, first_page + page_offset); in nand_block_bad()
266 bad = chip->oob_poi[chip->badblockpos]; in nand_block_bad()
268 if (likely(chip->badblockbits == 8)) in nand_block_bad()
271 res = hweight8(bad) < chip->badblockbits; in nand_block_bad()
275 page_offset = nand_bbm_get_next_page(chip, page_offset + 1); in nand_block_bad()
281 static int nand_isbad_bbm(struct nand_chip *chip, loff_t ofs) in nand_isbad_bbm() argument
283 if (chip->options & NAND_NO_BBM_QUIRK) in nand_isbad_bbm()
286 if (chip->legacy.block_bad) in nand_isbad_bbm()
287 return chip->legacy.block_bad(chip, ofs); in nand_isbad_bbm()
289 return nand_block_bad(chip, ofs); in nand_isbad_bbm()
300 static void nand_get_device(struct nand_chip *chip) in nand_get_device() argument
304 mutex_lock(&chip->lock); in nand_get_device()
305 if (!chip->suspended) { in nand_get_device()
306 mutex_lock(&chip->controller->lock); in nand_get_device()
309 mutex_unlock(&chip->lock); in nand_get_device()
311 wait_event(chip->resume_wq, !chip->suspended); in nand_get_device()
322 static int nand_check_wp(struct nand_chip *chip) in nand_check_wp() argument
328 if (chip->options & NAND_BROKEN_XD) in nand_check_wp()
332 ret = nand_status_op(chip, &status); in nand_check_wp()
346 static uint8_t *nand_fill_oob(struct nand_chip *chip, uint8_t *oob, size_t len, in nand_fill_oob() argument
349 struct mtd_info *mtd = nand_to_mtd(chip); in nand_fill_oob()
356 memset(chip->oob_poi, 0xff, mtd->oobsize); in nand_fill_oob()
362 memcpy(chip->oob_poi + ops->ooboffs, oob, len); in nand_fill_oob()
366 ret = mtd_ooblayout_set_databytes(mtd, oob, chip->oob_poi, in nand_fill_oob()
385 static int nand_do_write_oob(struct nand_chip *chip, loff_t to, in nand_do_write_oob() argument
388 struct mtd_info *mtd = nand_to_mtd(chip); in nand_do_write_oob()
403 chipnr = (int)(to >> chip->chip_shift); in nand_do_write_oob()
411 ret = nand_reset(chip, chipnr); in nand_do_write_oob()
415 nand_select_target(chip, chipnr); in nand_do_write_oob()
418 page = (int)(to >> chip->page_shift); in nand_do_write_oob()
421 if (nand_check_wp(chip)) { in nand_do_write_oob()
422 nand_deselect_target(chip); in nand_do_write_oob()
427 if (page == chip->pagecache.page) in nand_do_write_oob()
428 chip->pagecache.page = -1; in nand_do_write_oob()
430 nand_fill_oob(chip, ops->oobbuf, ops->ooblen, ops); in nand_do_write_oob()
433 status = chip->ecc.write_oob_raw(chip, page & chip->pagemask); in nand_do_write_oob()
435 status = chip->ecc.write_oob(chip, page & chip->pagemask); in nand_do_write_oob()
437 nand_deselect_target(chip); in nand_do_write_oob()
456 static int nand_default_block_markbad(struct nand_chip *chip, loff_t ofs) in nand_default_block_markbad() argument
458 struct mtd_info *mtd = nand_to_mtd(chip); in nand_default_block_markbad()
465 ops.ooboffs = chip->badblockpos; in nand_default_block_markbad()
466 if (chip->options & NAND_BUSWIDTH_16) { in nand_default_block_markbad()
474 page_offset = nand_bbm_get_next_page(chip, 0); in nand_default_block_markbad()
477 res = nand_do_write_oob(chip, in nand_default_block_markbad()
484 page_offset = nand_bbm_get_next_page(chip, page_offset + 1); in nand_default_block_markbad()
495 int nand_markbad_bbm(struct nand_chip *chip, loff_t ofs) in nand_markbad_bbm() argument
497 if (chip->legacy.block_markbad) in nand_markbad_bbm()
498 return chip->legacy.block_markbad(chip, ofs); in nand_markbad_bbm()
500 return nand_default_block_markbad(chip, ofs); in nand_markbad_bbm()
522 static int nand_block_markbad_lowlevel(struct nand_chip *chip, loff_t ofs) in nand_block_markbad_lowlevel() argument
524 struct mtd_info *mtd = nand_to_mtd(chip); in nand_block_markbad_lowlevel()
527 if (!(chip->bbt_options & NAND_BBT_NO_OOB_BBM)) { in nand_block_markbad_lowlevel()
533 einfo.len = 1ULL << chip->phys_erase_shift; in nand_block_markbad_lowlevel()
534 nand_erase_nand(chip, &einfo, 0); in nand_block_markbad_lowlevel()
537 nand_get_device(chip); in nand_block_markbad_lowlevel()
539 ret = nand_markbad_bbm(chip, ofs); in nand_block_markbad_lowlevel()
540 nand_release_device(chip); in nand_block_markbad_lowlevel()
544 if (chip->bbt) { in nand_block_markbad_lowlevel()
545 res = nand_markbad_bbt(chip, ofs); in nand_block_markbad_lowlevel()
565 struct nand_chip *chip = mtd_to_nand(mtd); in nand_block_isreserved() local
567 if (!chip->bbt) in nand_block_isreserved()
570 return nand_isreserved_bbt(chip, ofs); in nand_block_isreserved()
582 static int nand_block_checkbad(struct nand_chip *chip, loff_t ofs, int allowbbt) in nand_block_checkbad() argument
585 if (chip->bbt) in nand_block_checkbad()
586 return nand_isbad_bbt(chip, ofs, allowbbt); in nand_block_checkbad()
588 return nand_isbad_bbm(chip, ofs); in nand_block_checkbad()
608 int nand_soft_waitrdy(struct nand_chip *chip, unsigned long timeout_ms) in nand_soft_waitrdy() argument
614 if (!nand_has_exec_op(chip)) in nand_soft_waitrdy()
618 timings = nand_get_sdr_timings(nand_get_interface_config(chip)); in nand_soft_waitrdy()
621 ret = nand_status_op(chip, NULL); in nand_soft_waitrdy()
632 ret = nand_read_data_op(chip, &status, sizeof(status), true, in nand_soft_waitrdy()
653 nand_exit_status_op(chip); in nand_soft_waitrdy()
676 int nand_gpio_waitrdy(struct nand_chip *chip, struct gpio_desc *gpiod, in nand_gpio_waitrdy() argument
707 void panic_nand_wait(struct nand_chip *chip, unsigned long timeo) in panic_nand_wait() argument
711 if (chip->legacy.dev_ready) { in panic_nand_wait()
712 if (chip->legacy.dev_ready(chip)) in panic_nand_wait()
718 ret = nand_read_data_op(chip, &status, sizeof(status), in panic_nand_wait()
730 static bool nand_supports_get_features(struct nand_chip *chip, int addr) in nand_supports_get_features() argument
732 return (chip->parameters.supports_set_get_features && in nand_supports_get_features()
733 test_bit(addr, chip->parameters.get_feature_list)); in nand_supports_get_features()
736 static bool nand_supports_set_features(struct nand_chip *chip, int addr) in nand_supports_set_features() argument
738 return (chip->parameters.supports_set_get_features && in nand_supports_set_features()
739 test_bit(addr, chip->parameters.set_feature_list)); in nand_supports_set_features()
751 static int nand_reset_interface(struct nand_chip *chip, int chipnr) in nand_reset_interface() argument
753 const struct nand_controller_ops *ops = chip->controller->ops; in nand_reset_interface()
756 if (!nand_controller_can_setup_interface(chip)) in nand_reset_interface()
773 chip->current_interface_config = nand_get_reset_interface_config(); in nand_reset_interface()
774 ret = ops->setup_interface(chip, chipnr, in nand_reset_interface()
775 chip->current_interface_config); in nand_reset_interface()
792 static int nand_setup_interface(struct nand_chip *chip, int chipnr) in nand_setup_interface() argument
794 const struct nand_controller_ops *ops = chip->controller->ops; in nand_setup_interface()
798 if (!nand_controller_can_setup_interface(chip)) in nand_setup_interface()
808 if (!chip->best_interface_config) in nand_setup_interface()
811 tmode_param[0] = chip->best_interface_config->timings.mode; in nand_setup_interface()
814 if (nand_supports_set_features(chip, ONFI_FEATURE_ADDR_TIMING_MODE)) { in nand_setup_interface()
815 nand_select_target(chip, chipnr); in nand_setup_interface()
816 ret = nand_set_features(chip, ONFI_FEATURE_ADDR_TIMING_MODE, in nand_setup_interface()
818 nand_deselect_target(chip); in nand_setup_interface()
824 ret = ops->setup_interface(chip, chipnr, chip->best_interface_config); in nand_setup_interface()
829 if (!nand_supports_get_features(chip, ONFI_FEATURE_ADDR_TIMING_MODE)) in nand_setup_interface()
833 nand_select_target(chip, chipnr); in nand_setup_interface()
834 ret = nand_get_features(chip, ONFI_FEATURE_ADDR_TIMING_MODE, in nand_setup_interface()
836 nand_deselect_target(chip); in nand_setup_interface()
840 if (tmode_param[0] != chip->best_interface_config->timings.mode) { in nand_setup_interface()
842 chip->best_interface_config->timings.mode); in nand_setup_interface()
847 chip->current_interface_config = chip->best_interface_config; in nand_setup_interface()
856 nand_reset_interface(chip, chipnr); in nand_setup_interface()
857 nand_select_target(chip, chipnr); in nand_setup_interface()
858 nand_reset_op(chip); in nand_setup_interface()
859 nand_deselect_target(chip); in nand_setup_interface()
874 int nand_choose_best_sdr_timings(struct nand_chip *chip, in nand_choose_best_sdr_timings() argument
878 const struct nand_controller_ops *ops = chip->controller->ops; in nand_choose_best_sdr_timings()
888 ret = ops->setup_interface(chip, NAND_DATA_IFACE_CHECK_ONLY, in nand_choose_best_sdr_timings()
891 chip->best_interface_config = iface; in nand_choose_best_sdr_timings()
897 } else if (chip->parameters.onfi) { in nand_choose_best_sdr_timings()
898 best_mode = fls(chip->parameters.onfi->async_timing_mode) - 1; in nand_choose_best_sdr_timings()
902 onfi_fill_interface_config(chip, iface, NAND_SDR_IFACE, mode); in nand_choose_best_sdr_timings()
904 ret = ops->setup_interface(chip, NAND_DATA_IFACE_CHECK_ONLY, in nand_choose_best_sdr_timings()
910 chip->best_interface_config = iface; in nand_choose_best_sdr_timings()
928 static int nand_choose_interface_config(struct nand_chip *chip) in nand_choose_interface_config() argument
933 if (!nand_controller_can_setup_interface(chip)) in nand_choose_interface_config()
940 if (chip->ops.choose_interface_config) in nand_choose_interface_config()
941 ret = chip->ops.choose_interface_config(chip, iface); in nand_choose_interface_config()
943 ret = nand_choose_best_sdr_timings(chip, iface, NULL); in nand_choose_interface_config()
963 static int nand_fill_column_cycles(struct nand_chip *chip, u8 *addrs, in nand_fill_column_cycles() argument
966 struct mtd_info *mtd = nand_to_mtd(chip); in nand_fill_column_cycles()
984 if (chip->options & NAND_BUSWIDTH_16) { in nand_fill_column_cycles()
1005 static int nand_sp_exec_read_page_op(struct nand_chip *chip, unsigned int page, in nand_sp_exec_read_page_op() argument
1010 nand_get_sdr_timings(nand_get_interface_config(chip)); in nand_sp_exec_read_page_op()
1011 struct mtd_info *mtd = nand_to_mtd(chip); in nand_sp_exec_read_page_op()
1020 struct nand_operation op = NAND_OPERATION(chip->cur_cs, instrs); in nand_sp_exec_read_page_op()
1030 !(chip->options & NAND_BUSWIDTH_16)) in nand_sp_exec_read_page_op()
1033 ret = nand_fill_column_cycles(chip, addrs, offset_in_page); in nand_sp_exec_read_page_op()
1040 if (chip->options & NAND_ROW_ADDR_3) { in nand_sp_exec_read_page_op()
1045 return nand_exec_op(chip, &op); in nand_sp_exec_read_page_op()
1048 static int nand_lp_exec_read_page_op(struct nand_chip *chip, unsigned int page, in nand_lp_exec_read_page_op() argument
1053 nand_get_sdr_timings(nand_get_interface_config(chip)); in nand_lp_exec_read_page_op()
1063 struct nand_operation op = NAND_OPERATION(chip->cur_cs, instrs); in nand_lp_exec_read_page_op()
1070 ret = nand_fill_column_cycles(chip, addrs, offset_in_page); in nand_lp_exec_read_page_op()
1077 if (chip->options & NAND_ROW_ADDR_3) { in nand_lp_exec_read_page_op()
1082 return nand_exec_op(chip, &op); in nand_lp_exec_read_page_op()
1098 int nand_read_page_op(struct nand_chip *chip, unsigned int page, in nand_read_page_op() argument
1101 struct mtd_info *mtd = nand_to_mtd(chip); in nand_read_page_op()
1109 if (nand_has_exec_op(chip)) { in nand_read_page_op()
1111 return nand_lp_exec_read_page_op(chip, page, in nand_read_page_op()
1115 return nand_sp_exec_read_page_op(chip, page, offset_in_page, in nand_read_page_op()
1119 chip->legacy.cmdfunc(chip, NAND_CMD_READ0, offset_in_page, page); in nand_read_page_op()
1121 chip->legacy.read_buf(chip, buf, len); in nand_read_page_op()
1139 int nand_read_param_page_op(struct nand_chip *chip, u8 page, void *buf, in nand_read_param_page_op() argument
1148 if (nand_has_exec_op(chip)) { in nand_read_param_page_op()
1150 nand_get_sdr_timings(nand_get_interface_config(chip)); in nand_read_param_page_op()
1158 struct nand_operation op = NAND_OPERATION(chip->cur_cs, instrs); in nand_read_param_page_op()
1164 return nand_exec_op(chip, &op); in nand_read_param_page_op()
1167 chip->legacy.cmdfunc(chip, NAND_CMD_PARAM, page, -1); in nand_read_param_page_op()
1169 p[i] = chip->legacy.read_byte(chip); in nand_read_param_page_op()
1187 int nand_change_read_column_op(struct nand_chip *chip, in nand_change_read_column_op() argument
1191 struct mtd_info *mtd = nand_to_mtd(chip); in nand_change_read_column_op()
1203 if (nand_has_exec_op(chip)) { in nand_change_read_column_op()
1205 nand_get_sdr_timings(nand_get_interface_config(chip)); in nand_change_read_column_op()
1214 struct nand_operation op = NAND_OPERATION(chip->cur_cs, instrs); in nand_change_read_column_op()
1217 ret = nand_fill_column_cycles(chip, addrs, offset_in_page); in nand_change_read_column_op()
1227 return nand_exec_op(chip, &op); in nand_change_read_column_op()
1230 chip->legacy.cmdfunc(chip, NAND_CMD_RNDOUT, offset_in_page, -1); in nand_change_read_column_op()
1232 chip->legacy.read_buf(chip, buf, len); in nand_change_read_column_op()
1251 int nand_read_oob_op(struct nand_chip *chip, unsigned int page, in nand_read_oob_op() argument
1254 struct mtd_info *mtd = nand_to_mtd(chip); in nand_read_oob_op()
1262 if (nand_has_exec_op(chip)) in nand_read_oob_op()
1263 return nand_read_page_op(chip, page, in nand_read_oob_op()
1267 chip->legacy.cmdfunc(chip, NAND_CMD_READOOB, offset_in_oob, page); in nand_read_oob_op()
1269 chip->legacy.read_buf(chip, buf, len); in nand_read_oob_op()
1275 static int nand_exec_prog_page_op(struct nand_chip *chip, unsigned int page, in nand_exec_prog_page_op() argument
1280 nand_get_sdr_timings(nand_get_interface_config(chip)); in nand_exec_prog_page_op()
1281 struct mtd_info *mtd = nand_to_mtd(chip); in nand_exec_prog_page_op()
1296 struct nand_operation op = NAND_OPERATION(chip->cur_cs, instrs); in nand_exec_prog_page_op()
1297 int naddrs = nand_fill_column_cycles(chip, addrs, offset_in_page); in nand_exec_prog_page_op()
1306 if (chip->options & NAND_ROW_ADDR_3) in nand_exec_prog_page_op()
1328 !(chip->options & NAND_BUSWIDTH_16)) in nand_exec_prog_page_op()
1339 ret = nand_exec_op(chip, &op); in nand_exec_prog_page_op()
1343 ret = nand_status_op(chip, &status); in nand_exec_prog_page_op()
1363 int nand_prog_page_begin_op(struct nand_chip *chip, unsigned int page, in nand_prog_page_begin_op() argument
1367 struct mtd_info *mtd = nand_to_mtd(chip); in nand_prog_page_begin_op()
1375 if (nand_has_exec_op(chip)) in nand_prog_page_begin_op()
1376 return nand_exec_prog_page_op(chip, page, offset_in_page, buf, in nand_prog_page_begin_op()
1379 chip->legacy.cmdfunc(chip, NAND_CMD_SEQIN, offset_in_page, page); in nand_prog_page_begin_op()
1382 chip->legacy.write_buf(chip, buf, len); in nand_prog_page_begin_op()
1397 int nand_prog_page_end_op(struct nand_chip *chip) in nand_prog_page_end_op() argument
1402 if (nand_has_exec_op(chip)) { in nand_prog_page_end_op()
1404 nand_get_sdr_timings(nand_get_interface_config(chip)); in nand_prog_page_end_op()
1410 struct nand_operation op = NAND_OPERATION(chip->cur_cs, instrs); in nand_prog_page_end_op()
1412 ret = nand_exec_op(chip, &op); in nand_prog_page_end_op()
1416 ret = nand_status_op(chip, &status); in nand_prog_page_end_op()
1420 chip->legacy.cmdfunc(chip, NAND_CMD_PAGEPROG, -1, -1); in nand_prog_page_end_op()
1421 ret = chip->legacy.waitfunc(chip); in nand_prog_page_end_op()
1448 int nand_prog_page_op(struct nand_chip *chip, unsigned int page, in nand_prog_page_op() argument
1452 struct mtd_info *mtd = nand_to_mtd(chip); in nand_prog_page_op()
1461 if (nand_has_exec_op(chip)) { in nand_prog_page_op()
1462 status = nand_exec_prog_page_op(chip, page, offset_in_page, buf, in nand_prog_page_op()
1465 chip->legacy.cmdfunc(chip, NAND_CMD_SEQIN, offset_in_page, in nand_prog_page_op()
1467 chip->legacy.write_buf(chip, buf, len); in nand_prog_page_op()
1468 chip->legacy.cmdfunc(chip, NAND_CMD_PAGEPROG, -1, -1); in nand_prog_page_op()
1469 status = chip->legacy.waitfunc(chip); in nand_prog_page_op()
1492 int nand_change_write_column_op(struct nand_chip *chip, in nand_change_write_column_op() argument
1497 struct mtd_info *mtd = nand_to_mtd(chip); in nand_change_write_column_op()
1509 if (nand_has_exec_op(chip)) { in nand_change_write_column_op()
1511 nand_get_sdr_timings(nand_get_interface_config(chip)); in nand_change_write_column_op()
1518 struct nand_operation op = NAND_OPERATION(chip->cur_cs, instrs); in nand_change_write_column_op()
1521 ret = nand_fill_column_cycles(chip, addrs, offset_in_page); in nand_change_write_column_op()
1531 return nand_exec_op(chip, &op); in nand_change_write_column_op()
1534 chip->legacy.cmdfunc(chip, NAND_CMD_RNDIN, offset_in_page, -1); in nand_change_write_column_op()
1536 chip->legacy.write_buf(chip, buf, len); in nand_change_write_column_op()
1555 int nand_readid_op(struct nand_chip *chip, u8 addr, void *buf, in nand_readid_op() argument
1564 if (nand_has_exec_op(chip)) { in nand_readid_op()
1566 nand_get_sdr_timings(nand_get_interface_config(chip)); in nand_readid_op()
1572 struct nand_operation op = NAND_OPERATION(chip->cur_cs, instrs); in nand_readid_op()
1578 return nand_exec_op(chip, &op); in nand_readid_op()
1581 chip->legacy.cmdfunc(chip, NAND_CMD_READID, addr, -1); in nand_readid_op()
1584 id[i] = chip->legacy.read_byte(chip); in nand_readid_op()
1601 int nand_status_op(struct nand_chip *chip, u8 *status) in nand_status_op() argument
1603 if (nand_has_exec_op(chip)) { in nand_status_op()
1605 nand_get_sdr_timings(nand_get_interface_config(chip)); in nand_status_op()
1611 struct nand_operation op = NAND_OPERATION(chip->cur_cs, instrs); in nand_status_op()
1616 return nand_exec_op(chip, &op); in nand_status_op()
1619 chip->legacy.cmdfunc(chip, NAND_CMD_STATUS, -1, -1); in nand_status_op()
1621 *status = chip->legacy.read_byte(chip); in nand_status_op()
1638 int nand_exit_status_op(struct nand_chip *chip) in nand_exit_status_op() argument
1640 if (nand_has_exec_op(chip)) { in nand_exit_status_op()
1644 struct nand_operation op = NAND_OPERATION(chip->cur_cs, instrs); in nand_exit_status_op()
1646 return nand_exec_op(chip, &op); in nand_exit_status_op()
1649 chip->legacy.cmdfunc(chip, NAND_CMD_READ0, -1, -1); in nand_exit_status_op()
1665 int nand_erase_op(struct nand_chip *chip, unsigned int eraseblock) in nand_erase_op() argument
1668 (chip->phys_erase_shift - chip->page_shift); in nand_erase_op()
1672 if (nand_has_exec_op(chip)) { in nand_erase_op()
1674 nand_get_sdr_timings(nand_get_interface_config(chip)); in nand_erase_op()
1683 struct nand_operation op = NAND_OPERATION(chip->cur_cs, instrs); in nand_erase_op()
1685 if (chip->options & NAND_ROW_ADDR_3) in nand_erase_op()
1688 ret = nand_exec_op(chip, &op); in nand_erase_op()
1692 ret = nand_status_op(chip, &status); in nand_erase_op()
1696 chip->legacy.cmdfunc(chip, NAND_CMD_ERASE1, -1, page); in nand_erase_op()
1697 chip->legacy.cmdfunc(chip, NAND_CMD_ERASE2, -1, -1); in nand_erase_op()
1699 ret = chip->legacy.waitfunc(chip); in nand_erase_op()
1725 static int nand_set_features_op(struct nand_chip *chip, u8 feature, in nand_set_features_op() argument
1731 if (nand_has_exec_op(chip)) { in nand_set_features_op()
1733 nand_get_sdr_timings(nand_get_interface_config(chip)); in nand_set_features_op()
1741 struct nand_operation op = NAND_OPERATION(chip->cur_cs, instrs); in nand_set_features_op()
1743 return nand_exec_op(chip, &op); in nand_set_features_op()
1746 chip->legacy.cmdfunc(chip, NAND_CMD_SET_FEATURES, feature, -1); in nand_set_features_op()
1748 chip->legacy.write_byte(chip, params[i]); in nand_set_features_op()
1750 ret = chip->legacy.waitfunc(chip); in nand_set_features_op()
1772 static int nand_get_features_op(struct nand_chip *chip, u8 feature, in nand_get_features_op() argument
1778 if (nand_has_exec_op(chip)) { in nand_get_features_op()
1780 nand_get_sdr_timings(nand_get_interface_config(chip)); in nand_get_features_op()
1789 struct nand_operation op = NAND_OPERATION(chip->cur_cs, instrs); in nand_get_features_op()
1791 return nand_exec_op(chip, &op); in nand_get_features_op()
1794 chip->legacy.cmdfunc(chip, NAND_CMD_GET_FEATURES, feature, -1); in nand_get_features_op()
1796 params[i] = chip->legacy.read_byte(chip); in nand_get_features_op()
1801 static int nand_wait_rdy_op(struct nand_chip *chip, unsigned int timeout_ms, in nand_wait_rdy_op() argument
1804 if (nand_has_exec_op(chip)) { in nand_wait_rdy_op()
1809 struct nand_operation op = NAND_OPERATION(chip->cur_cs, instrs); in nand_wait_rdy_op()
1811 return nand_exec_op(chip, &op); in nand_wait_rdy_op()
1815 if (!chip->legacy.dev_ready) in nand_wait_rdy_op()
1816 udelay(chip->legacy.chip_delay); in nand_wait_rdy_op()
1818 nand_wait_ready(chip); in nand_wait_rdy_op()
1833 int nand_reset_op(struct nand_chip *chip) in nand_reset_op() argument
1835 if (nand_has_exec_op(chip)) { in nand_reset_op()
1837 nand_get_sdr_timings(nand_get_interface_config(chip)); in nand_reset_op()
1842 struct nand_operation op = NAND_OPERATION(chip->cur_cs, instrs); in nand_reset_op()
1844 return nand_exec_op(chip, &op); in nand_reset_op()
1847 chip->legacy.cmdfunc(chip, NAND_CMD_RESET, -1, -1); in nand_reset_op()
1868 int nand_read_data_op(struct nand_chip *chip, void *buf, unsigned int len, in nand_read_data_op() argument
1874 if (nand_has_exec_op(chip)) { in nand_read_data_op()
1878 struct nand_operation op = NAND_OPERATION(chip->cur_cs, instrs); in nand_read_data_op()
1883 return nand_check_op(chip, &op); in nand_read_data_op()
1885 return nand_exec_op(chip, &op); in nand_read_data_op()
1896 p[i] = chip->legacy.read_byte(chip); in nand_read_data_op()
1898 chip->legacy.read_buf(chip, buf, len); in nand_read_data_op()
1918 int nand_write_data_op(struct nand_chip *chip, const void *buf, in nand_write_data_op() argument
1924 if (nand_has_exec_op(chip)) { in nand_write_data_op()
1928 struct nand_operation op = NAND_OPERATION(chip->cur_cs, instrs); in nand_write_data_op()
1932 return nand_exec_op(chip, &op); in nand_write_data_op()
1940 chip->legacy.write_byte(chip, p[i]); in nand_write_data_op()
1942 chip->legacy.write_buf(chip, buf, len); in nand_write_data_op()
2170 int nand_op_parser_exec_op(struct nand_chip *chip, in nand_op_parser_exec_op() argument
2212 ret = pattern->exec(chip, &ctx.subop); in nand_op_parser_exec_op()
2372 int nand_reset(struct nand_chip *chip, int chipnr) in nand_reset() argument
2376 ret = nand_reset_interface(chip, chipnr); in nand_reset()
2385 nand_select_target(chip, chipnr); in nand_reset()
2386 ret = nand_reset_op(chip); in nand_reset()
2387 nand_deselect_target(chip); in nand_reset()
2391 ret = nand_setup_interface(chip, chipnr); in nand_reset()
2408 int nand_get_features(struct nand_chip *chip, int addr, in nand_get_features() argument
2411 if (!nand_supports_get_features(chip, addr)) in nand_get_features()
2414 if (chip->legacy.get_features) in nand_get_features()
2415 return chip->legacy.get_features(chip, addr, subfeature_param); in nand_get_features()
2417 return nand_get_features_op(chip, addr, subfeature_param); in nand_get_features()
2429 int nand_set_features(struct nand_chip *chip, int addr, in nand_set_features() argument
2432 if (!nand_supports_set_features(chip, addr)) in nand_set_features()
2435 if (chip->legacy.set_features) in nand_set_features()
2436 return chip->legacy.set_features(chip, addr, subfeature_param); in nand_set_features()
2438 return nand_set_features_op(chip, addr, subfeature_param); in nand_set_features()
2581 int nand_read_page_raw_notsupp(struct nand_chip *chip, u8 *buf, in nand_read_page_raw_notsupp() argument
2596 int nand_read_page_raw(struct nand_chip *chip, uint8_t *buf, int oob_required, in nand_read_page_raw() argument
2599 struct mtd_info *mtd = nand_to_mtd(chip); in nand_read_page_raw()
2602 ret = nand_read_page_op(chip, page, 0, buf, mtd->writesize); in nand_read_page_raw()
2607 ret = nand_read_data_op(chip, chip->oob_poi, mtd->oobsize, in nand_read_page_raw()
2632 int nand_monolithic_read_page_raw(struct nand_chip *chip, u8 *buf, in nand_monolithic_read_page_raw() argument
2635 struct mtd_info *mtd = nand_to_mtd(chip); in nand_monolithic_read_page_raw()
2643 if (buf != chip->data_buf) in nand_monolithic_read_page_raw()
2644 read_buf = nand_get_data_buf(chip); in nand_monolithic_read_page_raw()
2647 ret = nand_read_page_op(chip, page, 0, read_buf, size); in nand_monolithic_read_page_raw()
2651 if (buf != chip->data_buf) in nand_monolithic_read_page_raw()
2667 static int nand_read_page_raw_syndrome(struct nand_chip *chip, uint8_t *buf, in nand_read_page_raw_syndrome() argument
2670 struct mtd_info *mtd = nand_to_mtd(chip); in nand_read_page_raw_syndrome()
2671 int eccsize = chip->ecc.size; in nand_read_page_raw_syndrome()
2672 int eccbytes = chip->ecc.bytes; in nand_read_page_raw_syndrome()
2673 uint8_t *oob = chip->oob_poi; in nand_read_page_raw_syndrome()
2676 ret = nand_read_page_op(chip, page, 0, NULL, 0); in nand_read_page_raw_syndrome()
2680 for (steps = chip->ecc.steps; steps > 0; steps--) { in nand_read_page_raw_syndrome()
2681 ret = nand_read_data_op(chip, buf, eccsize, false, false); in nand_read_page_raw_syndrome()
2687 if (chip->ecc.prepad) { in nand_read_page_raw_syndrome()
2688 ret = nand_read_data_op(chip, oob, chip->ecc.prepad, in nand_read_page_raw_syndrome()
2693 oob += chip->ecc.prepad; in nand_read_page_raw_syndrome()
2696 ret = nand_read_data_op(chip, oob, eccbytes, false, false); in nand_read_page_raw_syndrome()
2702 if (chip->ecc.postpad) { in nand_read_page_raw_syndrome()
2703 ret = nand_read_data_op(chip, oob, chip->ecc.postpad, in nand_read_page_raw_syndrome()
2708 oob += chip->ecc.postpad; in nand_read_page_raw_syndrome()
2712 size = mtd->oobsize - (oob - chip->oob_poi); in nand_read_page_raw_syndrome()
2714 ret = nand_read_data_op(chip, oob, size, false, false); in nand_read_page_raw_syndrome()
2729 static int nand_read_page_swecc(struct nand_chip *chip, uint8_t *buf, in nand_read_page_swecc() argument
2732 struct mtd_info *mtd = nand_to_mtd(chip); in nand_read_page_swecc()
2733 int i, eccsize = chip->ecc.size, ret; in nand_read_page_swecc()
2734 int eccbytes = chip->ecc.bytes; in nand_read_page_swecc()
2735 int eccsteps = chip->ecc.steps; in nand_read_page_swecc()
2737 uint8_t *ecc_calc = chip->ecc.calc_buf; in nand_read_page_swecc()
2738 uint8_t *ecc_code = chip->ecc.code_buf; in nand_read_page_swecc()
2741 chip->ecc.read_page_raw(chip, buf, 1, page); in nand_read_page_swecc()
2744 chip->ecc.calculate(chip, p, &ecc_calc[i]); in nand_read_page_swecc()
2746 ret = mtd_ooblayout_get_eccbytes(mtd, ecc_code, chip->oob_poi, 0, in nand_read_page_swecc()
2747 chip->ecc.total); in nand_read_page_swecc()
2751 eccsteps = chip->ecc.steps; in nand_read_page_swecc()
2757 stat = chip->ecc.correct(chip, p, &ecc_code[i], &ecc_calc[i]); in nand_read_page_swecc()
2776 static int nand_read_subpage(struct nand_chip *chip, uint32_t data_offs, in nand_read_subpage() argument
2779 struct mtd_info *mtd = nand_to_mtd(chip); in nand_read_subpage()
2784 int busw = (chip->options & NAND_BUSWIDTH_16) ? 2 : 1; in nand_read_subpage()
2790 start_step = data_offs / chip->ecc.size; in nand_read_subpage()
2791 end_step = (data_offs + readlen - 1) / chip->ecc.size; in nand_read_subpage()
2793 index = start_step * chip->ecc.bytes; in nand_read_subpage()
2796 datafrag_len = num_steps * chip->ecc.size; in nand_read_subpage()
2797 eccfrag_len = num_steps * chip->ecc.bytes; in nand_read_subpage()
2799 data_col_addr = start_step * chip->ecc.size; in nand_read_subpage()
2802 ret = nand_read_page_op(chip, page, data_col_addr, p, datafrag_len); in nand_read_subpage()
2807 for (i = 0; i < eccfrag_len ; i += chip->ecc.bytes, p += chip->ecc.size) in nand_read_subpage()
2808 chip->ecc.calculate(chip, p, &chip->ecc.calc_buf[i]); in nand_read_subpage()
2822 ret = nand_change_read_column_op(chip, mtd->writesize, in nand_read_subpage()
2823 chip->oob_poi, mtd->oobsize, in nand_read_subpage()
2836 if ((oobregion.offset + (num_steps * chip->ecc.bytes)) & in nand_read_subpage()
2840 ret = nand_change_read_column_op(chip, in nand_read_subpage()
2842 &chip->oob_poi[aligned_pos], in nand_read_subpage()
2848 ret = mtd_ooblayout_get_eccbytes(mtd, chip->ecc.code_buf, in nand_read_subpage()
2849 chip->oob_poi, index, eccfrag_len); in nand_read_subpage()
2854 for (i = 0; i < eccfrag_len ; i += chip->ecc.bytes, p += chip->ecc.size) { in nand_read_subpage()
2857 stat = chip->ecc.correct(chip, p, &chip->ecc.code_buf[i], in nand_read_subpage()
2858 &chip->ecc.calc_buf[i]); in nand_read_subpage()
2860 (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) { in nand_read_subpage()
2862 stat = nand_check_erased_ecc_chunk(p, chip->ecc.size, in nand_read_subpage()
2863 &chip->ecc.code_buf[i], in nand_read_subpage()
2864 chip->ecc.bytes, in nand_read_subpage()
2866 chip->ecc.strength); in nand_read_subpage()
2888 static int nand_read_page_hwecc(struct nand_chip *chip, uint8_t *buf, in nand_read_page_hwecc() argument
2891 struct mtd_info *mtd = nand_to_mtd(chip); in nand_read_page_hwecc()
2892 int i, eccsize = chip->ecc.size, ret; in nand_read_page_hwecc()
2893 int eccbytes = chip->ecc.bytes; in nand_read_page_hwecc()
2894 int eccsteps = chip->ecc.steps; in nand_read_page_hwecc()
2896 uint8_t *ecc_calc = chip->ecc.calc_buf; in nand_read_page_hwecc()
2897 uint8_t *ecc_code = chip->ecc.code_buf; in nand_read_page_hwecc()
2900 ret = nand_read_page_op(chip, page, 0, NULL, 0); in nand_read_page_hwecc()
2905 chip->ecc.hwctl(chip, NAND_ECC_READ); in nand_read_page_hwecc()
2907 ret = nand_read_data_op(chip, p, eccsize, false, false); in nand_read_page_hwecc()
2911 chip->ecc.calculate(chip, p, &ecc_calc[i]); in nand_read_page_hwecc()
2914 ret = nand_read_data_op(chip, chip->oob_poi, mtd->oobsize, false, in nand_read_page_hwecc()
2919 ret = mtd_ooblayout_get_eccbytes(mtd, ecc_code, chip->oob_poi, 0, in nand_read_page_hwecc()
2920 chip->ecc.total); in nand_read_page_hwecc()
2924 eccsteps = chip->ecc.steps; in nand_read_page_hwecc()
2930 stat = chip->ecc.correct(chip, p, &ecc_code[i], &ecc_calc[i]); in nand_read_page_hwecc()
2932 (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) { in nand_read_page_hwecc()
2937 chip->ecc.strength); in nand_read_page_hwecc()
2960 static int nand_read_page_syndrome(struct nand_chip *chip, uint8_t *buf, in nand_read_page_syndrome() argument
2963 struct mtd_info *mtd = nand_to_mtd(chip); in nand_read_page_syndrome()
2964 int ret, i, eccsize = chip->ecc.size; in nand_read_page_syndrome()
2965 int eccbytes = chip->ecc.bytes; in nand_read_page_syndrome()
2966 int eccsteps = chip->ecc.steps; in nand_read_page_syndrome()
2967 int eccpadbytes = eccbytes + chip->ecc.prepad + chip->ecc.postpad; in nand_read_page_syndrome()
2969 uint8_t *oob = chip->oob_poi; in nand_read_page_syndrome()
2972 ret = nand_read_page_op(chip, page, 0, NULL, 0); in nand_read_page_syndrome()
2979 chip->ecc.hwctl(chip, NAND_ECC_READ); in nand_read_page_syndrome()
2981 ret = nand_read_data_op(chip, p, eccsize, false, false); in nand_read_page_syndrome()
2985 if (chip->ecc.prepad) { in nand_read_page_syndrome()
2986 ret = nand_read_data_op(chip, oob, chip->ecc.prepad, in nand_read_page_syndrome()
2991 oob += chip->ecc.prepad; in nand_read_page_syndrome()
2994 chip->ecc.hwctl(chip, NAND_ECC_READSYN); in nand_read_page_syndrome()
2996 ret = nand_read_data_op(chip, oob, eccbytes, false, false); in nand_read_page_syndrome()
3000 stat = chip->ecc.correct(chip, p, oob, NULL); in nand_read_page_syndrome()
3004 if (chip->ecc.postpad) { in nand_read_page_syndrome()
3005 ret = nand_read_data_op(chip, oob, chip->ecc.postpad, in nand_read_page_syndrome()
3010 oob += chip->ecc.postpad; in nand_read_page_syndrome()
3014 (chip->ecc.options & NAND_ECC_GENERIC_ERASED_CHECK)) { in nand_read_page_syndrome()
3016 stat = nand_check_erased_ecc_chunk(p, chip->ecc.size, in nand_read_page_syndrome()
3020 chip->ecc.strength); in nand_read_page_syndrome()
3032 i = mtd->oobsize - (oob - chip->oob_poi); in nand_read_page_syndrome()
3034 ret = nand_read_data_op(chip, oob, i, false, false); in nand_read_page_syndrome()
3049 static uint8_t *nand_transfer_oob(struct nand_chip *chip, uint8_t *oob, in nand_transfer_oob() argument
3052 struct mtd_info *mtd = nand_to_mtd(chip); in nand_transfer_oob()
3059 memcpy(oob, chip->oob_poi + ops->ooboffs, len); in nand_transfer_oob()
3063 ret = mtd_ooblayout_get_databytes(mtd, oob, chip->oob_poi, in nand_transfer_oob()
3083 static int nand_setup_read_retry(struct nand_chip *chip, int retry_mode) in nand_setup_read_retry() argument
3087 if (retry_mode >= chip->read_retries) in nand_setup_read_retry()
3090 if (!chip->ops.setup_read_retry) in nand_setup_read_retry()
3093 return chip->ops.setup_read_retry(chip, retry_mode); in nand_setup_read_retry()
3096 static void nand_wait_readrdy(struct nand_chip *chip) in nand_wait_readrdy() argument
3100 if (!(chip->options & NAND_NEED_READRDY)) in nand_wait_readrdy()
3103 sdr = nand_get_sdr_timings(nand_get_interface_config(chip)); in nand_wait_readrdy()
3104 WARN_ON(nand_wait_rdy_op(chip, PSEC_TO_MSEC(sdr->tR_max), 0)); in nand_wait_readrdy()
3115 static int nand_do_read_ops(struct nand_chip *chip, loff_t from, in nand_do_read_ops() argument
3119 struct mtd_info *mtd = nand_to_mtd(chip); in nand_do_read_ops()
3131 chipnr = (int)(from >> chip->chip_shift); in nand_do_read_ops()
3132 nand_select_target(chip, chipnr); in nand_do_read_ops()
3134 realpage = (int)(from >> chip->page_shift); in nand_do_read_ops()
3135 page = realpage & chip->pagemask; in nand_do_read_ops()
3151 else if (chip->options & NAND_USES_DMA) in nand_do_read_ops()
3154 chip->buf_align); in nand_do_read_ops()
3159 if (realpage != chip->pagecache.page || oob) { in nand_do_read_ops()
3160 bufpoi = use_bounce_buf ? chip->data_buf : buf; in nand_do_read_ops()
3172 ret = chip->ecc.read_page_raw(chip, bufpoi, in nand_do_read_ops()
3175 else if (!aligned && NAND_HAS_SUBPAGE_READ(chip) && in nand_do_read_ops()
3177 ret = chip->ecc.read_subpage(chip, col, bytes, in nand_do_read_ops()
3180 ret = chip->ecc.read_page(chip, bufpoi, in nand_do_read_ops()
3185 chip->pagecache.page = -1; in nand_do_read_ops()
3194 if (!NAND_HAS_SUBPAGE_READ(chip) && !oob && in nand_do_read_ops()
3197 chip->pagecache.page = realpage; in nand_do_read_ops()
3198 chip->pagecache.bitflips = ret; in nand_do_read_ops()
3201 chip->pagecache.page = -1; in nand_do_read_ops()
3210 oob = nand_transfer_oob(chip, oob, ops, in nand_do_read_ops()
3216 nand_wait_readrdy(chip); in nand_do_read_ops()
3219 if (retry_mode + 1 < chip->read_retries) { in nand_do_read_ops()
3221 ret = nand_setup_read_retry(chip, in nand_do_read_ops()
3238 memcpy(buf, chip->data_buf + col, bytes); in nand_do_read_ops()
3241 chip->pagecache.bitflips); in nand_do_read_ops()
3248 ret = nand_setup_read_retry(chip, 0); in nand_do_read_ops()
3262 page = realpage & chip->pagemask; in nand_do_read_ops()
3266 nand_deselect_target(chip); in nand_do_read_ops()
3267 nand_select_target(chip, chipnr); in nand_do_read_ops()
3270 nand_deselect_target(chip); in nand_do_read_ops()
3290 int nand_read_oob_std(struct nand_chip *chip, int page) in nand_read_oob_std() argument
3292 struct mtd_info *mtd = nand_to_mtd(chip); in nand_read_oob_std()
3294 return nand_read_oob_op(chip, page, 0, chip->oob_poi, mtd->oobsize); in nand_read_oob_std()
3304 static int nand_read_oob_syndrome(struct nand_chip *chip, int page) in nand_read_oob_syndrome() argument
3306 struct mtd_info *mtd = nand_to_mtd(chip); in nand_read_oob_syndrome()
3308 int chunk = chip->ecc.bytes + chip->ecc.prepad + chip->ecc.postpad; in nand_read_oob_syndrome()
3309 int eccsize = chip->ecc.size; in nand_read_oob_syndrome()
3310 uint8_t *bufpoi = chip->oob_poi; in nand_read_oob_syndrome()
3313 ret = nand_read_page_op(chip, page, chip->ecc.size, NULL, 0); in nand_read_oob_syndrome()
3317 for (i = 0; i < chip->ecc.steps; i++) { in nand_read_oob_syndrome()
3323 ret = nand_change_read_column_op(chip, pos, in nand_read_oob_syndrome()
3327 ret = nand_read_page_op(chip, page, pos, NULL, in nand_read_oob_syndrome()
3336 ret = nand_read_data_op(chip, bufpoi, toread, false, false); in nand_read_oob_syndrome()
3344 ret = nand_read_data_op(chip, bufpoi, length, false, false); in nand_read_oob_syndrome()
3357 int nand_write_oob_std(struct nand_chip *chip, int page) in nand_write_oob_std() argument
3359 struct mtd_info *mtd = nand_to_mtd(chip); in nand_write_oob_std()
3361 return nand_prog_page_op(chip, page, mtd->writesize, chip->oob_poi, in nand_write_oob_std()
3372 static int nand_write_oob_syndrome(struct nand_chip *chip, int page) in nand_write_oob_syndrome() argument
3374 struct mtd_info *mtd = nand_to_mtd(chip); in nand_write_oob_syndrome()
3375 int chunk = chip->ecc.bytes + chip->ecc.prepad + chip->ecc.postpad; in nand_write_oob_syndrome()
3376 int eccsize = chip->ecc.size, length = mtd->oobsize; in nand_write_oob_syndrome()
3377 int ret, i, len, pos, sndcmd = 0, steps = chip->ecc.steps; in nand_write_oob_syndrome()
3378 const uint8_t *bufpoi = chip->oob_poi; in nand_write_oob_syndrome()
3385 if (!chip->ecc.prepad && !chip->ecc.postpad) { in nand_write_oob_syndrome()
3391 ret = nand_prog_page_begin_op(chip, page, pos, NULL, 0); in nand_write_oob_syndrome()
3404 ret = nand_write_data_op(chip, &fill, in nand_write_oob_syndrome()
3413 ret = nand_change_write_column_op(chip, pos, in nand_write_oob_syndrome()
3423 ret = nand_write_data_op(chip, bufpoi, len, false); in nand_write_oob_syndrome()
3431 ret = nand_write_data_op(chip, bufpoi, length, false); in nand_write_oob_syndrome()
3436 return nand_prog_page_end_op(chip); in nand_write_oob_syndrome()
3447 static int nand_do_read_oob(struct nand_chip *chip, loff_t from, in nand_do_read_oob() argument
3450 struct mtd_info *mtd = nand_to_mtd(chip); in nand_do_read_oob()
3466 chipnr = (int)(from >> chip->chip_shift); in nand_do_read_oob()
3467 nand_select_target(chip, chipnr); in nand_do_read_oob()
3470 realpage = (int)(from >> chip->page_shift); in nand_do_read_oob()
3471 page = realpage & chip->pagemask; in nand_do_read_oob()
3475 ret = chip->ecc.read_oob_raw(chip, page); in nand_do_read_oob()
3477 ret = chip->ecc.read_oob(chip, page); in nand_do_read_oob()
3483 buf = nand_transfer_oob(chip, buf, ops, len); in nand_do_read_oob()
3485 nand_wait_readrdy(chip); in nand_do_read_oob()
3496 page = realpage & chip->pagemask; in nand_do_read_oob()
3500 nand_deselect_target(chip); in nand_do_read_oob()
3501 nand_select_target(chip, chipnr); in nand_do_read_oob()
3504 nand_deselect_target(chip); in nand_do_read_oob()
3528 struct nand_chip *chip = mtd_to_nand(mtd); in nand_read_oob() local
3538 nand_get_device(chip); in nand_read_oob()
3541 ret = nand_do_read_oob(chip, from, ops); in nand_read_oob()
3543 ret = nand_do_read_ops(chip, from, ops); in nand_read_oob()
3545 nand_release_device(chip); in nand_read_oob()
3558 int nand_write_page_raw_notsupp(struct nand_chip *chip, const u8 *buf, in nand_write_page_raw_notsupp() argument
3573 int nand_write_page_raw(struct nand_chip *chip, const uint8_t *buf, in nand_write_page_raw() argument
3576 struct mtd_info *mtd = nand_to_mtd(chip); in nand_write_page_raw()
3579 ret = nand_prog_page_begin_op(chip, page, 0, buf, mtd->writesize); in nand_write_page_raw()
3584 ret = nand_write_data_op(chip, chip->oob_poi, mtd->oobsize, in nand_write_page_raw()
3590 return nand_prog_page_end_op(chip); in nand_write_page_raw()
3610 int nand_monolithic_write_page_raw(struct nand_chip *chip, const u8 *buf, in nand_monolithic_write_page_raw() argument
3613 struct mtd_info *mtd = nand_to_mtd(chip); in nand_monolithic_write_page_raw()
3620 if (buf != chip->data_buf) { in nand_monolithic_write_page_raw()
3621 write_buf = nand_get_data_buf(chip); in nand_monolithic_write_page_raw()
3626 return nand_prog_page_op(chip, page, 0, write_buf, size); in nand_monolithic_write_page_raw()
3639 static int nand_write_page_raw_syndrome(struct nand_chip *chip, in nand_write_page_raw_syndrome() argument
3643 struct mtd_info *mtd = nand_to_mtd(chip); in nand_write_page_raw_syndrome()
3644 int eccsize = chip->ecc.size; in nand_write_page_raw_syndrome()
3645 int eccbytes = chip->ecc.bytes; in nand_write_page_raw_syndrome()
3646 uint8_t *oob = chip->oob_poi; in nand_write_page_raw_syndrome()
3649 ret = nand_prog_page_begin_op(chip, page, 0, NULL, 0); in nand_write_page_raw_syndrome()
3653 for (steps = chip->ecc.steps; steps > 0; steps--) { in nand_write_page_raw_syndrome()
3654 ret = nand_write_data_op(chip, buf, eccsize, false); in nand_write_page_raw_syndrome()
3660 if (chip->ecc.prepad) { in nand_write_page_raw_syndrome()
3661 ret = nand_write_data_op(chip, oob, chip->ecc.prepad, in nand_write_page_raw_syndrome()
3666 oob += chip->ecc.prepad; in nand_write_page_raw_syndrome()
3669 ret = nand_write_data_op(chip, oob, eccbytes, false); in nand_write_page_raw_syndrome()
3675 if (chip->ecc.postpad) { in nand_write_page_raw_syndrome()
3676 ret = nand_write_data_op(chip, oob, chip->ecc.postpad, in nand_write_page_raw_syndrome()
3681 oob += chip->ecc.postpad; in nand_write_page_raw_syndrome()
3685 size = mtd->oobsize - (oob - chip->oob_poi); in nand_write_page_raw_syndrome()
3687 ret = nand_write_data_op(chip, oob, size, false); in nand_write_page_raw_syndrome()
3692 return nand_prog_page_end_op(chip); in nand_write_page_raw_syndrome()
3701 static int nand_write_page_swecc(struct nand_chip *chip, const uint8_t *buf, in nand_write_page_swecc() argument
3704 struct mtd_info *mtd = nand_to_mtd(chip); in nand_write_page_swecc()
3705 int i, eccsize = chip->ecc.size, ret; in nand_write_page_swecc()
3706 int eccbytes = chip->ecc.bytes; in nand_write_page_swecc()
3707 int eccsteps = chip->ecc.steps; in nand_write_page_swecc()
3708 uint8_t *ecc_calc = chip->ecc.calc_buf; in nand_write_page_swecc()
3713 chip->ecc.calculate(chip, p, &ecc_calc[i]); in nand_write_page_swecc()
3715 ret = mtd_ooblayout_set_eccbytes(mtd, ecc_calc, chip->oob_poi, 0, in nand_write_page_swecc()
3716 chip->ecc.total); in nand_write_page_swecc()
3720 return chip->ecc.write_page_raw(chip, buf, 1, page); in nand_write_page_swecc()
3730 static int nand_write_page_hwecc(struct nand_chip *chip, const uint8_t *buf, in nand_write_page_hwecc() argument
3733 struct mtd_info *mtd = nand_to_mtd(chip); in nand_write_page_hwecc()
3734 int i, eccsize = chip->ecc.size, ret; in nand_write_page_hwecc()
3735 int eccbytes = chip->ecc.bytes; in nand_write_page_hwecc()
3736 int eccsteps = chip->ecc.steps; in nand_write_page_hwecc()
3737 uint8_t *ecc_calc = chip->ecc.calc_buf; in nand_write_page_hwecc()
3740 ret = nand_prog_page_begin_op(chip, page, 0, NULL, 0); in nand_write_page_hwecc()
3745 chip->ecc.hwctl(chip, NAND_ECC_WRITE); in nand_write_page_hwecc()
3747 ret = nand_write_data_op(chip, p, eccsize, false); in nand_write_page_hwecc()
3751 chip->ecc.calculate(chip, p, &ecc_calc[i]); in nand_write_page_hwecc()
3754 ret = mtd_ooblayout_set_eccbytes(mtd, ecc_calc, chip->oob_poi, 0, in nand_write_page_hwecc()
3755 chip->ecc.total); in nand_write_page_hwecc()
3759 ret = nand_write_data_op(chip, chip->oob_poi, mtd->oobsize, false); in nand_write_page_hwecc()
3763 return nand_prog_page_end_op(chip); in nand_write_page_hwecc()
3776 static int nand_write_subpage_hwecc(struct nand_chip *chip, uint32_t offset, in nand_write_subpage_hwecc() argument
3780 struct mtd_info *mtd = nand_to_mtd(chip); in nand_write_subpage_hwecc()
3781 uint8_t *oob_buf = chip->oob_poi; in nand_write_subpage_hwecc()
3782 uint8_t *ecc_calc = chip->ecc.calc_buf; in nand_write_subpage_hwecc()
3783 int ecc_size = chip->ecc.size; in nand_write_subpage_hwecc()
3784 int ecc_bytes = chip->ecc.bytes; in nand_write_subpage_hwecc()
3785 int ecc_steps = chip->ecc.steps; in nand_write_subpage_hwecc()
3791 ret = nand_prog_page_begin_op(chip, page, 0, NULL, 0); in nand_write_subpage_hwecc()
3797 chip->ecc.hwctl(chip, NAND_ECC_WRITE); in nand_write_subpage_hwecc()
3800 ret = nand_write_data_op(chip, buf, ecc_size, false); in nand_write_subpage_hwecc()
3808 chip->ecc.calculate(chip, buf, ecc_calc); in nand_write_subpage_hwecc()
3822 ecc_calc = chip->ecc.calc_buf; in nand_write_subpage_hwecc()
3823 ret = mtd_ooblayout_set_eccbytes(mtd, ecc_calc, chip->oob_poi, 0, in nand_write_subpage_hwecc()
3824 chip->ecc.total); in nand_write_subpage_hwecc()
3829 ret = nand_write_data_op(chip, chip->oob_poi, mtd->oobsize, false); in nand_write_subpage_hwecc()
3833 return nand_prog_page_end_op(chip); in nand_write_subpage_hwecc()
3847 static int nand_write_page_syndrome(struct nand_chip *chip, const uint8_t *buf, in nand_write_page_syndrome() argument
3850 struct mtd_info *mtd = nand_to_mtd(chip); in nand_write_page_syndrome()
3851 int i, eccsize = chip->ecc.size; in nand_write_page_syndrome()
3852 int eccbytes = chip->ecc.bytes; in nand_write_page_syndrome()
3853 int eccsteps = chip->ecc.steps; in nand_write_page_syndrome()
3855 uint8_t *oob = chip->oob_poi; in nand_write_page_syndrome()
3858 ret = nand_prog_page_begin_op(chip, page, 0, NULL, 0); in nand_write_page_syndrome()
3863 chip->ecc.hwctl(chip, NAND_ECC_WRITE); in nand_write_page_syndrome()
3865 ret = nand_write_data_op(chip, p, eccsize, false); in nand_write_page_syndrome()
3869 if (chip->ecc.prepad) { in nand_write_page_syndrome()
3870 ret = nand_write_data_op(chip, oob, chip->ecc.prepad, in nand_write_page_syndrome()
3875 oob += chip->ecc.prepad; in nand_write_page_syndrome()
3878 chip->ecc.calculate(chip, p, oob); in nand_write_page_syndrome()
3880 ret = nand_write_data_op(chip, oob, eccbytes, false); in nand_write_page_syndrome()
3886 if (chip->ecc.postpad) { in nand_write_page_syndrome()
3887 ret = nand_write_data_op(chip, oob, chip->ecc.postpad, in nand_write_page_syndrome()
3892 oob += chip->ecc.postpad; in nand_write_page_syndrome()
3897 i = mtd->oobsize - (oob - chip->oob_poi); in nand_write_page_syndrome()
3899 ret = nand_write_data_op(chip, oob, i, false); in nand_write_page_syndrome()
3904 return nand_prog_page_end_op(chip); in nand_write_page_syndrome()
3917 static int nand_write_page(struct nand_chip *chip, uint32_t offset, in nand_write_page() argument
3921 struct mtd_info *mtd = nand_to_mtd(chip); in nand_write_page()
3924 if (!(chip->options & NAND_NO_SUBPAGE_WRITE) && in nand_write_page()
3925 chip->ecc.write_subpage) in nand_write_page()
3931 status = chip->ecc.write_page_raw(chip, buf, oob_required, in nand_write_page()
3934 status = chip->ecc.write_subpage(chip, offset, data_len, buf, in nand_write_page()
3937 status = chip->ecc.write_page(chip, buf, oob_required, page); in nand_write_page()
3945 #define NOTALIGNED(x) ((x & (chip->subpagesize - 1)) != 0)
3955 static int nand_do_write_ops(struct nand_chip *chip, loff_t to, in nand_do_write_ops() argument
3958 struct mtd_info *mtd = nand_to_mtd(chip); in nand_do_write_ops()
3983 chipnr = (int)(to >> chip->chip_shift); in nand_do_write_ops()
3984 nand_select_target(chip, chipnr); in nand_do_write_ops()
3987 if (nand_check_wp(chip)) { in nand_do_write_ops()
3992 realpage = (int)(to >> chip->page_shift); in nand_do_write_ops()
3993 page = realpage & chip->pagemask; in nand_do_write_ops()
3996 if (to <= ((loff_t)chip->pagecache.page << chip->page_shift) && in nand_do_write_ops()
3997 ((loff_t)chip->pagecache.page << chip->page_shift) < (to + ops->len)) in nand_do_write_ops()
3998 chip->pagecache.page = -1; in nand_do_write_ops()
4014 else if (chip->options & NAND_USES_DMA) in nand_do_write_ops()
4017 chip->buf_align); in nand_do_write_ops()
4030 wbuf = nand_get_data_buf(chip); in nand_do_write_ops()
4037 oob = nand_fill_oob(chip, oob, len, ops); in nand_do_write_ops()
4041 memset(chip->oob_poi, 0xff, mtd->oobsize); in nand_do_write_ops()
4044 ret = nand_write_page(chip, column, bytes, wbuf, in nand_do_write_ops()
4058 page = realpage & chip->pagemask; in nand_do_write_ops()
4062 nand_deselect_target(chip); in nand_do_write_ops()
4063 nand_select_target(chip, chipnr); in nand_do_write_ops()
4072 nand_deselect_target(chip); in nand_do_write_ops()
4090 struct nand_chip *chip = mtd_to_nand(mtd); in panic_nand_write() local
4091 int chipnr = (int)(to >> chip->chip_shift); in panic_nand_write()
4095 nand_select_target(chip, chipnr); in panic_nand_write()
4098 panic_nand_wait(chip, 400); in panic_nand_write()
4105 ret = nand_do_write_ops(chip, to, &ops); in panic_nand_write()
4120 struct nand_chip *chip = mtd_to_nand(mtd); in nand_write_oob() local
4125 nand_get_device(chip); in nand_write_oob()
4138 ret = nand_do_write_oob(chip, to, ops); in nand_write_oob()
4140 ret = nand_do_write_ops(chip, to, ops); in nand_write_oob()
4143 nand_release_device(chip); in nand_write_oob()
4167 int nand_erase_nand(struct nand_chip *chip, struct erase_info *instr, in nand_erase_nand() argument
4177 if (check_offs_len(chip, instr->addr, instr->len)) in nand_erase_nand()
4181 nand_get_device(chip); in nand_erase_nand()
4184 page = (int)(instr->addr >> chip->page_shift); in nand_erase_nand()
4185 chipnr = (int)(instr->addr >> chip->chip_shift); in nand_erase_nand()
4188 pages_per_block = 1 << (chip->phys_erase_shift - chip->page_shift); in nand_erase_nand()
4191 nand_select_target(chip, chipnr); in nand_erase_nand()
4194 if (nand_check_wp(chip)) { in nand_erase_nand()
4206 if (nand_block_checkbad(chip, ((loff_t) page) << in nand_erase_nand()
4207 chip->page_shift, allowbbt)) { in nand_erase_nand()
4218 if (page <= chip->pagecache.page && chip->pagecache.page < in nand_erase_nand()
4220 chip->pagecache.page = -1; in nand_erase_nand()
4222 ret = nand_erase_op(chip, (page & chip->pagemask) >> in nand_erase_nand()
4223 (chip->phys_erase_shift - chip->page_shift)); in nand_erase_nand()
4228 ((loff_t)page << chip->page_shift); in nand_erase_nand()
4233 len -= (1ULL << chip->phys_erase_shift); in nand_erase_nand()
4237 if (len && !(page & chip->pagemask)) { in nand_erase_nand()
4239 nand_deselect_target(chip); in nand_erase_nand()
4240 nand_select_target(chip, chipnr); in nand_erase_nand()
4248 nand_deselect_target(chip); in nand_erase_nand()
4249 nand_release_device(chip); in nand_erase_nand()
4263 struct nand_chip *chip = mtd_to_nand(mtd); in nand_sync() local
4268 nand_get_device(chip); in nand_sync()
4270 nand_release_device(chip); in nand_sync()
4280 struct nand_chip *chip = mtd_to_nand(mtd); in nand_block_isbad() local
4281 int chipnr = (int)(offs >> chip->chip_shift); in nand_block_isbad()
4285 nand_get_device(chip); in nand_block_isbad()
4287 nand_select_target(chip, chipnr); in nand_block_isbad()
4289 ret = nand_block_checkbad(chip, offs, 0); in nand_block_isbad()
4291 nand_deselect_target(chip); in nand_block_isbad()
4292 nand_release_device(chip); in nand_block_isbad()
4325 struct nand_chip *chip = mtd_to_nand(mtd); in nand_suspend() local
4328 mutex_lock(&chip->lock); in nand_suspend()
4329 if (chip->ops.suspend) in nand_suspend()
4330 ret = chip->ops.suspend(chip); in nand_suspend()
4332 chip->suspended = 1; in nand_suspend()
4333 mutex_unlock(&chip->lock); in nand_suspend()
4344 struct nand_chip *chip = mtd_to_nand(mtd); in nand_resume() local
4346 mutex_lock(&chip->lock); in nand_resume()
4347 if (chip->suspended) { in nand_resume()
4348 if (chip->ops.resume) in nand_resume()
4349 chip->ops.resume(chip); in nand_resume()
4350 chip->suspended = 0; in nand_resume()
4355 mutex_unlock(&chip->lock); in nand_resume()
4357 wake_up_all(&chip->resume_wq); in nand_resume()
4378 struct nand_chip *chip = mtd_to_nand(mtd); in nand_lock() local
4380 if (!chip->ops.lock_area) in nand_lock()
4383 return chip->ops.lock_area(chip, ofs, len); in nand_lock()
4394 struct nand_chip *chip = mtd_to_nand(mtd); in nand_unlock() local
4396 if (!chip->ops.unlock_area) in nand_unlock()
4399 return chip->ops.unlock_area(chip, ofs, len); in nand_unlock()
4403 static void nand_set_defaults(struct nand_chip *chip) in nand_set_defaults() argument
4406 if (!chip->controller) { in nand_set_defaults()
4407 chip->controller = &chip->legacy.dummy_controller; in nand_set_defaults()
4408 nand_controller_init(chip->controller); in nand_set_defaults()
4411 nand_legacy_set_defaults(chip); in nand_set_defaults()
4413 if (!chip->buf_align) in nand_set_defaults()
4414 chip->buf_align = 1; in nand_set_defaults()
4509 void nand_decode_ext_id(struct nand_chip *chip) in nand_decode_ext_id() argument
4512 struct mtd_info *mtd = nand_to_mtd(chip); in nand_decode_ext_id()
4514 u8 *id_data = chip->id.data; in nand_decode_ext_id()
4516 memorg = nanddev_get_memorg(&chip->base); in nand_decode_ext_id()
4538 chip->options |= NAND_BUSWIDTH_16; in nand_decode_ext_id()
4547 static void nand_decode_id(struct nand_chip *chip, struct nand_flash_dev *type) in nand_decode_id() argument
4549 struct mtd_info *mtd = nand_to_mtd(chip); in nand_decode_id()
4552 memorg = nanddev_get_memorg(&chip->base); in nand_decode_id()
4570 static void nand_decode_bbm_options(struct nand_chip *chip) in nand_decode_bbm_options() argument
4572 struct mtd_info *mtd = nand_to_mtd(chip); in nand_decode_bbm_options()
4575 if (mtd->writesize > 512 || (chip->options & NAND_BUSWIDTH_16)) in nand_decode_bbm_options()
4576 chip->badblockpos = NAND_BBM_POS_LARGE; in nand_decode_bbm_options()
4578 chip->badblockpos = NAND_BBM_POS_SMALL; in nand_decode_bbm_options()
4586 static bool find_full_id_nand(struct nand_chip *chip, in find_full_id_nand() argument
4589 struct nand_device *base = &chip->base; in find_full_id_nand()
4591 struct mtd_info *mtd = nand_to_mtd(chip); in find_full_id_nand()
4593 u8 *id_data = chip->id.data; in find_full_id_nand()
4595 memorg = nanddev_get_memorg(&chip->base); in find_full_id_nand()
4611 chip->options |= type->options; in find_full_id_nand()
4616 chip->parameters.model = kstrdup(type->name, GFP_KERNEL); in find_full_id_nand()
4617 if (!chip->parameters.model) in find_full_id_nand()
4630 static void nand_manufacturer_detect(struct nand_chip *chip) in nand_manufacturer_detect() argument
4636 if (chip->manufacturer.desc && chip->manufacturer.desc->ops && in nand_manufacturer_detect()
4637 chip->manufacturer.desc->ops->detect) { in nand_manufacturer_detect()
4640 memorg = nanddev_get_memorg(&chip->base); in nand_manufacturer_detect()
4643 memorg->bits_per_cell = nand_get_bits_per_cell(chip->id.data[2]); in nand_manufacturer_detect()
4644 chip->manufacturer.desc->ops->detect(chip); in nand_manufacturer_detect()
4646 nand_decode_ext_id(chip); in nand_manufacturer_detect()
4656 static int nand_manufacturer_init(struct nand_chip *chip) in nand_manufacturer_init() argument
4658 if (!chip->manufacturer.desc || !chip->manufacturer.desc->ops || in nand_manufacturer_init()
4659 !chip->manufacturer.desc->ops->init) in nand_manufacturer_init()
4662 return chip->manufacturer.desc->ops->init(chip); in nand_manufacturer_init()
4671 static void nand_manufacturer_cleanup(struct nand_chip *chip) in nand_manufacturer_cleanup() argument
4674 if (chip->manufacturer.desc && chip->manufacturer.desc->ops && in nand_manufacturer_cleanup()
4675 chip->manufacturer.desc->ops->cleanup) in nand_manufacturer_cleanup()
4676 chip->manufacturer.desc->ops->cleanup(chip); in nand_manufacturer_cleanup()
4688 static int nand_detect(struct nand_chip *chip, struct nand_flash_dev *type) in nand_detect() argument
4691 struct mtd_info *mtd = nand_to_mtd(chip); in nand_detect()
4694 u8 *id_data = chip->id.data; in nand_detect()
4702 memorg = nanddev_get_memorg(&chip->base); in nand_detect()
4710 ret = nand_reset(chip, 0); in nand_detect()
4715 nand_select_target(chip, 0); in nand_detect()
4718 ret = nand_readid_op(chip, 0, id_data, 2); in nand_detect()
4734 ret = nand_readid_op(chip, 0, id_data, sizeof(chip->id.data)); in nand_detect()
4744 chip->id.len = nand_id_len(id_data, ARRAY_SIZE(chip->id.data)); in nand_detect()
4748 chip->manufacturer.desc = manufacturer_desc; in nand_detect()
4760 busw = chip->options & NAND_BUSWIDTH_16; in nand_detect()
4766 chip->options &= ~NAND_BUSWIDTH_16; in nand_detect()
4770 if (find_full_id_nand(chip, type)) in nand_detect()
4779 ret = nand_onfi_detect(chip); in nand_detect()
4786 ret = nand_jedec_detect(chip); in nand_detect()
4796 chip->parameters.model = kstrdup(type->name, GFP_KERNEL); in nand_detect()
4797 if (!chip->parameters.model) in nand_detect()
4801 nand_manufacturer_detect(chip); in nand_detect()
4803 nand_decode_id(chip, type); in nand_detect()
4806 chip->options |= type->options; in nand_detect()
4815 mtd->name = chip->parameters.model; in nand_detect()
4817 if (chip->options & NAND_BUSWIDTH_AUTO) { in nand_detect()
4819 nand_set_defaults(chip); in nand_detect()
4820 } else if (busw != (chip->options & NAND_BUSWIDTH_16)) { in nand_detect()
4830 (chip->options & NAND_BUSWIDTH_16) ? 16 : 8); in nand_detect()
4836 nand_decode_bbm_options(chip); in nand_detect()
4839 chip->page_shift = ffs(mtd->writesize) - 1; in nand_detect()
4841 targetsize = nanddev_target_size(&chip->base); in nand_detect()
4842 chip->pagemask = (targetsize >> chip->page_shift) - 1; in nand_detect()
4844 chip->bbt_erase_shift = chip->phys_erase_shift = in nand_detect()
4847 chip->chip_shift = ffs((unsigned)targetsize) - 1; in nand_detect()
4849 chip->chip_shift = ffs((unsigned)(targetsize >> 32)); in nand_detect()
4850 chip->chip_shift += 32 - 1; in nand_detect()
4853 if (chip->chip_shift - chip->page_shift > 16) in nand_detect()
4854 chip->options |= NAND_ROW_ADDR_3; in nand_detect()
4856 chip->badblockbits = 8; in nand_detect()
4858 nand_legacy_adjust_cmdfunc(chip); in nand_detect()
4863 chip->parameters.model); in nand_detect()
4865 (int)(targetsize >> 20), nand_is_slc(chip) ? "SLC" : "MLC", in nand_detect()
4870 kfree(chip->parameters.model); in nand_detect()
4957 static void of_get_nand_ecc_legacy_user_config(struct nand_chip *chip) in of_get_nand_ecc_legacy_user_config() argument
4959 struct device_node *dn = nand_get_flash_node(chip); in of_get_nand_ecc_legacy_user_config()
4960 struct nand_ecc_props *user_conf = &chip->base.ecc.user_conf; in of_get_nand_ecc_legacy_user_config()
4993 static int rawnand_dt_init(struct nand_chip *chip) in rawnand_dt_init() argument
4995 struct nand_device *nand = mtd_to_nanddev(nand_to_mtd(chip)); in rawnand_dt_init()
4996 struct device_node *dn = nand_get_flash_node(chip); in rawnand_dt_init()
5002 chip->options |= NAND_BUSWIDTH_16; in rawnand_dt_init()
5005 chip->options |= NAND_IS_BOOT_MEDIUM; in rawnand_dt_init()
5008 chip->bbt_options |= NAND_BBT_USE_FLASH; in rawnand_dt_init()
5011 of_get_nand_ecc_legacy_user_config(chip); in rawnand_dt_init()
5025 chip->ecc.engine_type = nand->ecc.user_conf.engine_type; in rawnand_dt_init()
5026 if (chip->ecc.engine_type == NAND_ECC_ENGINE_TYPE_INVALID) in rawnand_dt_init()
5027 chip->ecc.engine_type = nand->ecc.defaults.engine_type; in rawnand_dt_init()
5029 chip->ecc.placement = nand->ecc.user_conf.placement; in rawnand_dt_init()
5030 chip->ecc.algo = nand->ecc.user_conf.algo; in rawnand_dt_init()
5031 chip->ecc.strength = nand->ecc.user_conf.strength; in rawnand_dt_init()
5032 chip->ecc.size = nand->ecc.user_conf.step_size; in rawnand_dt_init()
5051 static int nand_scan_ident(struct nand_chip *chip, unsigned int maxchips, in nand_scan_ident() argument
5054 struct mtd_info *mtd = nand_to_mtd(chip); in nand_scan_ident()
5060 memorg = nanddev_get_memorg(&chip->base); in nand_scan_ident()
5063 chip->cur_cs = -1; in nand_scan_ident()
5065 mutex_init(&chip->lock); in nand_scan_ident()
5066 init_waitqueue_head(&chip->resume_wq); in nand_scan_ident()
5069 chip->current_interface_config = nand_get_reset_interface_config(); in nand_scan_ident()
5071 ret = rawnand_dt_init(chip); in nand_scan_ident()
5079 nand_set_defaults(chip); in nand_scan_ident()
5081 ret = nand_legacy_check_hooks(chip); in nand_scan_ident()
5088 ret = nand_detect(chip, table); in nand_scan_ident()
5090 if (!(chip->options & NAND_SCAN_SILENT_NODEV)) in nand_scan_ident()
5092 nand_deselect_target(chip); in nand_scan_ident()
5096 nand_maf_id = chip->id.data[0]; in nand_scan_ident()
5097 nand_dev_id = chip->id.data[1]; in nand_scan_ident()
5099 nand_deselect_target(chip); in nand_scan_ident()
5106 ret = nand_reset(chip, i); in nand_scan_ident()
5110 nand_select_target(chip, i); in nand_scan_ident()
5112 ret = nand_readid_op(chip, 0, id, sizeof(id)); in nand_scan_ident()
5117 nand_deselect_target(chip); in nand_scan_ident()
5120 nand_deselect_target(chip); in nand_scan_ident()
5127 mtd->size = i * nanddev_target_size(&chip->base); in nand_scan_ident()
5132 static void nand_scan_ident_cleanup(struct nand_chip *chip) in nand_scan_ident_cleanup() argument
5134 kfree(chip->parameters.model); in nand_scan_ident_cleanup()
5135 kfree(chip->parameters.onfi); in nand_scan_ident_cleanup()
5138 static int nand_set_ecc_on_host_ops(struct nand_chip *chip) in nand_set_ecc_on_host_ops() argument
5140 struct nand_ecc_ctrl *ecc = &chip->ecc; in nand_set_ecc_on_host_ops()
5197 static int nand_set_ecc_soft_ops(struct nand_chip *chip) in nand_set_ecc_soft_ops() argument
5199 struct mtd_info *mtd = nand_to_mtd(chip); in nand_set_ecc_soft_ops()
5201 struct nand_ecc_ctrl *ecc = &chip->ecc; in nand_set_ecc_soft_ops()
5313 nand_check_ecc_caps(struct nand_chip *chip, in nand_check_ecc_caps() argument
5316 struct mtd_info *mtd = nand_to_mtd(chip); in nand_check_ecc_caps()
5318 int preset_step = chip->ecc.size; in nand_check_ecc_caps()
5319 int preset_strength = chip->ecc.strength; in nand_check_ecc_caps()
5344 chip->ecc.bytes = ecc_bytes; in nand_check_ecc_caps()
5367 nand_match_ecc_req(struct nand_chip *chip, in nand_match_ecc_req() argument
5371 nanddev_get_ecc_requirements(&chip->base); in nand_match_ecc_req()
5372 struct mtd_info *mtd = nand_to_mtd(chip); in nand_match_ecc_req()
5433 chip->ecc.size = best_step; in nand_match_ecc_req()
5434 chip->ecc.strength = best_strength; in nand_match_ecc_req()
5435 chip->ecc.bytes = best_ecc_bytes; in nand_match_ecc_req()
5450 nand_maximize_ecc(struct nand_chip *chip, in nand_maximize_ecc() argument
5453 struct mtd_info *mtd = nand_to_mtd(chip); in nand_maximize_ecc()
5466 if (chip->ecc.size && step_size != chip->ecc.size) in nand_maximize_ecc()
5503 chip->ecc.size = best_step; in nand_maximize_ecc()
5504 chip->ecc.strength = best_strength; in nand_maximize_ecc()
5505 chip->ecc.bytes = best_ecc_bytes; in nand_maximize_ecc()
5528 int nand_ecc_choose_conf(struct nand_chip *chip, in nand_ecc_choose_conf() argument
5531 struct mtd_info *mtd = nand_to_mtd(chip); in nand_ecc_choose_conf()
5537 if (chip->ecc.size && chip->ecc.strength) in nand_ecc_choose_conf()
5538 return nand_check_ecc_caps(chip, caps, oobavail); in nand_ecc_choose_conf()
5541 return nand_maximize_ecc(chip, caps, oobavail); in nand_ecc_choose_conf()
5543 if (!nand_match_ecc_req(chip, caps, oobavail)) in nand_ecc_choose_conf()
5546 return nand_maximize_ecc(chip, caps, oobavail); in nand_ecc_choose_conf()
5552 struct nand_chip *chip = container_of(nand, struct nand_chip, in rawnand_erase() local
5559 nand_select_target(chip, pos->target); in rawnand_erase()
5560 ret = nand_erase_op(chip, eb); in rawnand_erase()
5561 nand_deselect_target(chip); in rawnand_erase()
5569 struct nand_chip *chip = container_of(nand, struct nand_chip, in rawnand_markbad() local
5572 return nand_markbad_bbm(chip, nanddev_pos_to_offs(nand, pos)); in rawnand_markbad()
5577 struct nand_chip *chip = container_of(nand, struct nand_chip, in rawnand_isbad() local
5581 nand_select_target(chip, pos->target); in rawnand_isbad()
5582 ret = nand_isbad_bbm(chip, nanddev_pos_to_offs(nand, pos)); in rawnand_isbad()
5583 nand_deselect_target(chip); in rawnand_isbad()
5602 static int nand_scan_tail(struct nand_chip *chip) in nand_scan_tail() argument
5604 struct mtd_info *mtd = nand_to_mtd(chip); in nand_scan_tail()
5605 struct nand_ecc_ctrl *ecc = &chip->ecc; in nand_scan_tail()
5609 if (WARN_ON((chip->bbt_options & NAND_BBT_NO_OOB_BBM) && in nand_scan_tail()
5610 !(chip->bbt_options & NAND_BBT_USE_FLASH))) { in nand_scan_tail()
5614 chip->data_buf = kmalloc(mtd->writesize + mtd->oobsize, GFP_KERNEL); in nand_scan_tail()
5615 if (!chip->data_buf) in nand_scan_tail()
5624 nand_select_target(chip, 0); in nand_scan_tail()
5625 ret = nand_manufacturer_init(chip); in nand_scan_tail()
5626 nand_deselect_target(chip); in nand_scan_tail()
5631 chip->oob_poi = chip->data_buf + mtd->writesize; in nand_scan_tail()
5677 ret = nand_set_ecc_on_host_ops(chip); in nand_scan_tail()
5696 ret = nand_set_ecc_soft_ops(chip); in nand_scan_tail()
5763 chip->base.ecc.ctx.total = ecc->total; in nand_scan_tail()
5782 if (!nand_ecc_is_strong_enough(&chip->base)) in nand_scan_tail()
5784 mtd->name, chip->ecc.strength, chip->ecc.size, in nand_scan_tail()
5785 nanddev_get_ecc_requirements(&chip->base)->strength, in nand_scan_tail()
5786 nanddev_get_ecc_requirements(&chip->base)->step_size); in nand_scan_tail()
5789 if (!(chip->options & NAND_NO_SUBPAGE_WRITE) && nand_is_slc(chip)) { in nand_scan_tail()
5801 chip->subpagesize = mtd->writesize >> mtd->subpage_sft; in nand_scan_tail()
5804 chip->pagecache.page = -1; in nand_scan_tail()
5809 if (chip->page_shift > 9) in nand_scan_tail()
5810 chip->options |= NAND_SUBPAGE_READ; in nand_scan_tail()
5817 ret = nanddev_init(&chip->base, &rawnand_ops, mtd->owner); in nand_scan_tail()
5822 if (chip->options & NAND_ROM) in nand_scan_tail()
5852 ret = nand_choose_interface_config(chip); in nand_scan_tail()
5857 for (i = 0; i < nanddev_ntargets(&chip->base); i++) { in nand_scan_tail()
5858 ret = nand_setup_interface(chip, i); in nand_scan_tail()
5864 if (chip->options & NAND_SKIP_BBTSCAN) in nand_scan_tail()
5868 ret = nand_create_bbt(chip); in nand_scan_tail()
5875 kfree(chip->best_interface_config); in nand_scan_tail()
5878 nanddev_cleanup(&chip->base); in nand_scan_tail()
5881 nand_manufacturer_cleanup(chip); in nand_scan_tail()
5884 kfree(chip->data_buf); in nand_scan_tail()
5891 static int nand_attach(struct nand_chip *chip) in nand_attach() argument
5893 if (chip->controller->ops && chip->controller->ops->attach_chip) in nand_attach()
5894 return chip->controller->ops->attach_chip(chip); in nand_attach()
5899 static void nand_detach(struct nand_chip *chip) in nand_detach() argument
5901 if (chip->controller->ops && chip->controller->ops->detach_chip) in nand_detach()
5902 chip->controller->ops->detach_chip(chip); in nand_detach()
5915 int nand_scan_with_ids(struct nand_chip *chip, unsigned int maxchips, in nand_scan_with_ids() argument
5923 ret = nand_scan_ident(chip, maxchips, ids); in nand_scan_with_ids()
5927 ret = nand_attach(chip); in nand_scan_with_ids()
5931 ret = nand_scan_tail(chip); in nand_scan_with_ids()
5938 nand_detach(chip); in nand_scan_with_ids()
5940 nand_scan_ident_cleanup(chip); in nand_scan_with_ids()
5950 void nand_cleanup(struct nand_chip *chip) in nand_cleanup() argument
5952 if (chip->ecc.engine_type == NAND_ECC_ENGINE_TYPE_SOFT && in nand_cleanup()
5953 chip->ecc.algo == NAND_ECC_ALGO_BCH) in nand_cleanup()
5954 nand_bch_free((struct nand_bch_control *)chip->ecc.priv); in nand_cleanup()
5956 nanddev_cleanup(&chip->base); in nand_cleanup()
5959 kfree(chip->bbt); in nand_cleanup()
5960 kfree(chip->data_buf); in nand_cleanup()
5961 kfree(chip->ecc.code_buf); in nand_cleanup()
5962 kfree(chip->ecc.calc_buf); in nand_cleanup()
5965 if (chip->badblock_pattern && chip->badblock_pattern->options in nand_cleanup()
5967 kfree(chip->badblock_pattern); in nand_cleanup()
5970 kfree(chip->best_interface_config); in nand_cleanup()
5973 nand_manufacturer_cleanup(chip); in nand_cleanup()
5976 nand_detach(chip); in nand_cleanup()
5979 nand_scan_ident_cleanup(chip); in nand_cleanup()