Lines Matching full:nand

3  * Amlogic Meson Nand Flash Controller Driver
91 /* nand flash controller delay 3 ns */
109 struct nand_chip nand; member
217 static struct meson_nfc_nand_chip *to_meson_nand(struct nand_chip *nand) in to_meson_nand() argument
219 return container_of(nand, struct meson_nfc_nand_chip, nand); in to_meson_nand()
222 static void meson_nfc_select_chip(struct nand_chip *nand, int chip) in meson_nfc_select_chip() argument
224 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_select_chip()
225 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_select_chip()
265 static void meson_nfc_cmd_access(struct nand_chip *nand, int raw, bool dir, in meson_nfc_cmd_access() argument
268 struct mtd_info *mtd = nand_to_mtd(nand); in meson_nfc_cmd_access()
270 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_cmd_access()
274 pagesize = nand->ecc.size; in meson_nfc_cmd_access()
283 pages = len / nand->ecc.size; in meson_nfc_cmd_access()
296 * The Nand flash controller is designed as two stages pipleline - in meson_nfc_drain_cmd()
299 * but the Nand flash controller still has two commands buffered, in meson_nfc_drain_cmd()
331 static u8 *meson_nfc_oob_ptr(struct nand_chip *nand, int i) in meson_nfc_oob_ptr() argument
333 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_oob_ptr()
336 len = nand->ecc.size * (i + 1) + (nand->ecc.bytes + 2) * i; in meson_nfc_oob_ptr()
341 static u8 *meson_nfc_data_ptr(struct nand_chip *nand, int i) in meson_nfc_data_ptr() argument
343 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_data_ptr()
346 temp = nand->ecc.size + nand->ecc.bytes; in meson_nfc_data_ptr()
352 static void meson_nfc_get_data_oob(struct nand_chip *nand, in meson_nfc_get_data_oob() argument
358 oob_len = nand->ecc.bytes + 2; in meson_nfc_get_data_oob()
359 for (i = 0; i < nand->ecc.steps; i++) { in meson_nfc_get_data_oob()
361 dsrc = meson_nfc_data_ptr(nand, i); in meson_nfc_get_data_oob()
362 memcpy(buf, dsrc, nand->ecc.size); in meson_nfc_get_data_oob()
363 buf += nand->ecc.size; in meson_nfc_get_data_oob()
365 osrc = meson_nfc_oob_ptr(nand, i); in meson_nfc_get_data_oob()
371 static void meson_nfc_set_data_oob(struct nand_chip *nand, in meson_nfc_set_data_oob() argument
377 oob_len = nand->ecc.bytes + 2; in meson_nfc_set_data_oob()
378 for (i = 0; i < nand->ecc.steps; i++) { in meson_nfc_set_data_oob()
380 dsrc = meson_nfc_data_ptr(nand, i); in meson_nfc_set_data_oob()
381 memcpy(dsrc, buf, nand->ecc.size); in meson_nfc_set_data_oob()
382 buf += nand->ecc.size; in meson_nfc_set_data_oob()
384 osrc = meson_nfc_oob_ptr(nand, i); in meson_nfc_set_data_oob()
418 static void meson_nfc_set_user_byte(struct nand_chip *nand, u8 *oob_buf) in meson_nfc_set_user_byte() argument
420 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_set_user_byte()
424 for (i = 0, count = 0; i < nand->ecc.steps; i++, count += 2) { in meson_nfc_set_user_byte()
431 static void meson_nfc_get_user_byte(struct nand_chip *nand, u8 *oob_buf) in meson_nfc_get_user_byte() argument
433 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_get_user_byte()
437 for (i = 0, count = 0; i < nand->ecc.steps; i++, count += 2) { in meson_nfc_get_user_byte()
444 static int meson_nfc_ecc_correct(struct nand_chip *nand, u32 *bitflips, in meson_nfc_ecc_correct() argument
447 struct mtd_info *mtd = nand_to_mtd(nand); in meson_nfc_ecc_correct()
448 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_ecc_correct()
452 for (i = 0; i < nand->ecc.steps; i++) { in meson_nfc_ecc_correct()
460 if ((nand->options & NAND_NEED_SCRAMBLING) && in meson_nfc_ecc_correct()
461 ECC_ZERO_CNT(*info) < nand->ecc.strength) { in meson_nfc_ecc_correct()
473 static int meson_nfc_dma_buffer_setup(struct nand_chip *nand, void *databuf, in meson_nfc_dma_buffer_setup() argument
477 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_dma_buffer_setup()
512 static void meson_nfc_dma_buffer_release(struct nand_chip *nand, in meson_nfc_dma_buffer_release() argument
516 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_dma_buffer_release()
523 static int meson_nfc_read_buf(struct nand_chip *nand, u8 *buf, int len) in meson_nfc_read_buf() argument
525 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_read_buf()
534 ret = meson_nfc_dma_buffer_setup(nand, buf, len, info, in meson_nfc_read_buf()
544 meson_nfc_dma_buffer_release(nand, len, PER_INFO_BYTE, DMA_FROM_DEVICE); in meson_nfc_read_buf()
552 static int meson_nfc_write_buf(struct nand_chip *nand, u8 *buf, int len) in meson_nfc_write_buf() argument
554 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_write_buf()
558 ret = meson_nfc_dma_buffer_setup(nand, buf, len, NULL, in meson_nfc_write_buf()
568 meson_nfc_dma_buffer_release(nand, len, 0, DMA_TO_DEVICE); in meson_nfc_write_buf()
573 static int meson_nfc_rw_cmd_prepare_and_execute(struct nand_chip *nand, in meson_nfc_rw_cmd_prepare_and_execute() argument
577 nand_get_sdr_timings(nand_get_interface_config(nand)); in meson_nfc_rw_cmd_prepare_and_execute()
578 struct mtd_info *mtd = nand_to_mtd(nand); in meson_nfc_rw_cmd_prepare_and_execute()
579 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_rw_cmd_prepare_and_execute()
602 if (nand->options & NAND_ROW_ADDR_3) in meson_nfc_rw_cmd_prepare_and_execute()
626 static int meson_nfc_write_page_sub(struct nand_chip *nand, in meson_nfc_write_page_sub() argument
630 nand_get_sdr_timings(nand_get_interface_config(nand)); in meson_nfc_write_page_sub()
631 struct mtd_info *mtd = nand_to_mtd(nand); in meson_nfc_write_page_sub()
632 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_write_page_sub()
633 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_write_page_sub()
638 meson_nfc_select_chip(nand, nand->cur_cs); in meson_nfc_write_page_sub()
641 info_len = nand->ecc.steps * PER_INFO_BYTE; in meson_nfc_write_page_sub()
643 ret = meson_nfc_rw_cmd_prepare_and_execute(nand, page, DIRWRITE); in meson_nfc_write_page_sub()
647 ret = meson_nfc_dma_buffer_setup(nand, meson_chip->data_buf, in meson_nfc_write_page_sub()
653 if (nand->options & NAND_NEED_SCRAMBLING) { in meson_nfc_write_page_sub()
655 meson_nfc_cmd_access(nand, raw, DIRWRITE, in meson_nfc_write_page_sub()
658 meson_nfc_cmd_access(nand, raw, DIRWRITE, in meson_nfc_write_page_sub()
666 meson_nfc_dma_buffer_release(nand, data_len, info_len, DMA_TO_DEVICE); in meson_nfc_write_page_sub()
671 static int meson_nfc_write_page_raw(struct nand_chip *nand, const u8 *buf, in meson_nfc_write_page_raw() argument
674 u8 *oob_buf = nand->oob_poi; in meson_nfc_write_page_raw()
676 meson_nfc_set_data_oob(nand, buf, oob_buf); in meson_nfc_write_page_raw()
678 return meson_nfc_write_page_sub(nand, page, 1); in meson_nfc_write_page_raw()
681 static int meson_nfc_write_page_hwecc(struct nand_chip *nand, in meson_nfc_write_page_hwecc() argument
684 struct mtd_info *mtd = nand_to_mtd(nand); in meson_nfc_write_page_hwecc()
685 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_write_page_hwecc()
686 u8 *oob_buf = nand->oob_poi; in meson_nfc_write_page_hwecc()
689 memset(meson_chip->info_buf, 0, nand->ecc.steps * PER_INFO_BYTE); in meson_nfc_write_page_hwecc()
690 meson_nfc_set_user_byte(nand, oob_buf); in meson_nfc_write_page_hwecc()
692 return meson_nfc_write_page_sub(nand, page, 0); in meson_nfc_write_page_hwecc()
696 struct nand_chip *nand, int raw) in meson_nfc_check_ecc_pages_valid() argument
698 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_check_ecc_pages_valid()
703 neccpages = raw ? 1 : nand->ecc.steps; in meson_nfc_check_ecc_pages_valid()
713 static int meson_nfc_read_page_sub(struct nand_chip *nand, in meson_nfc_read_page_sub() argument
716 struct mtd_info *mtd = nand_to_mtd(nand); in meson_nfc_read_page_sub()
717 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_read_page_sub()
718 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_read_page_sub()
722 meson_nfc_select_chip(nand, nand->cur_cs); in meson_nfc_read_page_sub()
725 info_len = nand->ecc.steps * PER_INFO_BYTE; in meson_nfc_read_page_sub()
727 ret = meson_nfc_rw_cmd_prepare_and_execute(nand, page, DIRREAD); in meson_nfc_read_page_sub()
731 ret = meson_nfc_dma_buffer_setup(nand, meson_chip->data_buf, in meson_nfc_read_page_sub()
737 if (nand->options & NAND_NEED_SCRAMBLING) { in meson_nfc_read_page_sub()
739 meson_nfc_cmd_access(nand, raw, DIRREAD, in meson_nfc_read_page_sub()
742 meson_nfc_cmd_access(nand, raw, DIRREAD, in meson_nfc_read_page_sub()
747 meson_nfc_check_ecc_pages_valid(nfc, nand, raw); in meson_nfc_read_page_sub()
749 meson_nfc_dma_buffer_release(nand, data_len, info_len, DMA_FROM_DEVICE); in meson_nfc_read_page_sub()
754 static int meson_nfc_read_page_raw(struct nand_chip *nand, u8 *buf, in meson_nfc_read_page_raw() argument
757 u8 *oob_buf = nand->oob_poi; in meson_nfc_read_page_raw()
760 ret = meson_nfc_read_page_sub(nand, page, 1); in meson_nfc_read_page_raw()
764 meson_nfc_get_data_oob(nand, buf, oob_buf); in meson_nfc_read_page_raw()
769 static int meson_nfc_read_page_hwecc(struct nand_chip *nand, u8 *buf, in meson_nfc_read_page_hwecc() argument
772 struct mtd_info *mtd = nand_to_mtd(nand); in meson_nfc_read_page_hwecc()
773 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_read_page_hwecc()
774 struct nand_ecc_ctrl *ecc = &nand->ecc; in meson_nfc_read_page_hwecc()
777 u8 *oob_buf = nand->oob_poi; in meson_nfc_read_page_hwecc()
780 ret = meson_nfc_read_page_sub(nand, page, 0); in meson_nfc_read_page_hwecc()
784 meson_nfc_get_user_byte(nand, oob_buf); in meson_nfc_read_page_hwecc()
785 ret = meson_nfc_ecc_correct(nand, &bitflips, &correct_bitmap); in meson_nfc_read_page_hwecc()
791 if ((nand->options & NAND_NEED_SCRAMBLING) || !buf) { in meson_nfc_read_page_hwecc()
795 ret = meson_nfc_read_page_raw(nand, buf, 0, page); in meson_nfc_read_page_hwecc()
799 for (i = 0; i < nand->ecc.steps ; i++) { in meson_nfc_read_page_hwecc()
801 u8 *oob = nand->oob_poi + i * (ecc->bytes + 2); in meson_nfc_read_page_hwecc()
823 static int meson_nfc_read_oob_raw(struct nand_chip *nand, int page) in meson_nfc_read_oob_raw() argument
825 return meson_nfc_read_page_raw(nand, NULL, 1, page); in meson_nfc_read_oob_raw()
828 static int meson_nfc_read_oob(struct nand_chip *nand, int page) in meson_nfc_read_oob() argument
830 return meson_nfc_read_page_hwecc(nand, NULL, 1, page); in meson_nfc_read_oob()
892 static int meson_nfc_exec_op(struct nand_chip *nand, in meson_nfc_exec_op() argument
895 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_exec_op()
896 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_exec_op()
905 meson_nfc_select_chip(nand, op->cs); in meson_nfc_exec_op()
932 meson_nfc_read_buf(nand, buf, instr->ctx.data.len); in meson_nfc_exec_op()
940 meson_nfc_write_buf(nand, buf, instr->ctx.data.len); in meson_nfc_exec_op()
958 struct nand_chip *nand = mtd_to_nand(mtd); in meson_ooblayout_ecc() local
960 if (section >= nand->ecc.steps) in meson_ooblayout_ecc()
963 oobregion->offset = 2 + (section * (2 + nand->ecc.bytes)); in meson_ooblayout_ecc()
964 oobregion->length = nand->ecc.bytes; in meson_ooblayout_ecc()
972 struct nand_chip *nand = mtd_to_nand(mtd); in meson_ooblayout_free() local
974 if (section >= nand->ecc.steps) in meson_ooblayout_free()
977 oobregion->offset = section * (2 + nand->ecc.bytes); in meson_ooblayout_free()
1067 static void meson_nfc_free_buffer(struct nand_chip *nand) in meson_nfc_free_buffer() argument
1069 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_free_buffer()
1075 static int meson_chip_buffer_init(struct nand_chip *nand) in meson_chip_buffer_init() argument
1077 struct mtd_info *mtd = nand_to_mtd(nand); in meson_chip_buffer_init()
1078 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_chip_buffer_init()
1081 nsectors = mtd->writesize / nand->ecc.size; in meson_chip_buffer_init()
1100 int meson_nfc_setup_interface(struct nand_chip *nand, int csline, in meson_nfc_setup_interface() argument
1103 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_setup_interface()
1142 static int meson_nand_bch_mode(struct nand_chip *nand) in meson_nand_bch_mode() argument
1144 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nand_bch_mode()
1147 if (nand->ecc.strength > 60 || nand->ecc.strength < 8) in meson_nand_bch_mode()
1151 if (meson_ecc[i].strength == nand->ecc.strength) { in meson_nand_bch_mode()
1160 static void meson_nand_detach_chip(struct nand_chip *nand) in meson_nand_detach_chip() argument
1162 meson_nfc_free_buffer(nand); in meson_nand_detach_chip()
1165 static int meson_nand_attach_chip(struct nand_chip *nand) in meson_nand_attach_chip() argument
1167 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nand_attach_chip()
1168 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nand_attach_chip()
1169 struct mtd_info *mtd = nand_to_mtd(nand); in meson_nand_attach_chip()
1175 "%s:nand%d", in meson_nand_attach_chip()
1182 if (nand->bbt_options & NAND_BBT_USE_FLASH) in meson_nand_attach_chip()
1183 nand->bbt_options |= NAND_BBT_NO_OOB; in meson_nand_attach_chip()
1185 nand->options |= NAND_NO_SUBPAGE_WRITE; in meson_nand_attach_chip()
1187 ret = nand_ecc_choose_conf(nand, nfc->data->ecc_caps, in meson_nand_attach_chip()
1196 ret = meson_nand_bch_mode(nand); in meson_nand_attach_chip()
1200 nand->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST; in meson_nand_attach_chip()
1201 nand->ecc.write_page_raw = meson_nfc_write_page_raw; in meson_nand_attach_chip()
1202 nand->ecc.write_page = meson_nfc_write_page_hwecc; in meson_nand_attach_chip()
1203 nand->ecc.write_oob_raw = nand_write_oob_std; in meson_nand_attach_chip()
1204 nand->ecc.write_oob = nand_write_oob_std; in meson_nand_attach_chip()
1206 nand->ecc.read_page_raw = meson_nfc_read_page_raw; in meson_nand_attach_chip()
1207 nand->ecc.read_page = meson_nfc_read_page_hwecc; in meson_nand_attach_chip()
1208 nand->ecc.read_oob_raw = meson_nfc_read_oob_raw; in meson_nand_attach_chip()
1209 nand->ecc.read_oob = meson_nfc_read_oob; in meson_nand_attach_chip()
1211 if (nand->options & NAND_BUSWIDTH_16) { in meson_nand_attach_chip()
1215 ret = meson_chip_buffer_init(nand); in meson_nand_attach_chip()
1234 struct nand_chip *nand; in meson_nfc_nand_chip_init() local
1266 nand = &meson_chip->nand; in meson_nfc_nand_chip_init()
1267 nand->controller = &nfc->controller; in meson_nfc_nand_chip_init()
1268 nand->controller->ops = &meson_nand_controller_ops; in meson_nfc_nand_chip_init()
1269 nand_set_flash_node(nand, np); in meson_nfc_nand_chip_init()
1270 nand_set_controller_data(nand, nfc); in meson_nfc_nand_chip_init()
1272 nand->options |= NAND_USES_DMA; in meson_nfc_nand_chip_init()
1273 mtd = nand_to_mtd(nand); in meson_nfc_nand_chip_init()
1277 ret = nand_scan(nand, nsels); in meson_nfc_nand_chip_init()
1284 nand_cleanup(nand); in meson_nfc_nand_chip_init()
1302 mtd = nand_to_mtd(&meson_chip->nand); in meson_nfc_nand_chip_cleanup()
1307 meson_nfc_free_buffer(&meson_chip->nand); in meson_nfc_nand_chip_cleanup()
1308 nand_cleanup(&meson_chip->nand); in meson_nfc_nand_chip_cleanup()
1410 dev_err(dev, "failed to initialize NAND clock\n"); in meson_nfc_probe()
1432 dev_err(dev, "failed to init NAND chips\n"); in meson_nfc_probe()
1462 .name = "meson-nand",
1470 MODULE_DESCRIPTION("Amlogic's Meson NAND Flash Controller driver");