Lines Matching refs:nand

119 	struct nand_chip nand;  member
251 static struct meson_nfc_nand_chip *to_meson_nand(struct nand_chip *nand) in to_meson_nand() argument
253 return container_of(nand, struct meson_nfc_nand_chip, nand); in to_meson_nand()
256 static void meson_nfc_select_chip(struct nand_chip *nand, int chip) in meson_nfc_select_chip() argument
258 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_select_chip()
259 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_select_chip()
299 static void meson_nfc_cmd_access(struct nand_chip *nand, int raw, bool dir, in meson_nfc_cmd_access() argument
302 struct mtd_info *mtd = nand_to_mtd(nand); in meson_nfc_cmd_access()
304 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_cmd_access()
308 pagesize = nand->ecc.size; in meson_nfc_cmd_access()
317 pages = len / nand->ecc.size; in meson_nfc_cmd_access()
365 static u8 *meson_nfc_oob_ptr(struct nand_chip *nand, int i) in meson_nfc_oob_ptr() argument
367 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_oob_ptr()
370 len = nand->ecc.size * (i + 1) + (nand->ecc.bytes + 2) * i; in meson_nfc_oob_ptr()
375 static u8 *meson_nfc_data_ptr(struct nand_chip *nand, int i) in meson_nfc_data_ptr() argument
377 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_data_ptr()
380 temp = nand->ecc.size + nand->ecc.bytes; in meson_nfc_data_ptr()
386 static void meson_nfc_get_data_oob(struct nand_chip *nand, in meson_nfc_get_data_oob() argument
392 oob_len = nand->ecc.bytes + 2; in meson_nfc_get_data_oob()
393 for (i = 0; i < nand->ecc.steps; i++) { in meson_nfc_get_data_oob()
395 dsrc = meson_nfc_data_ptr(nand, i); in meson_nfc_get_data_oob()
396 memcpy(buf, dsrc, nand->ecc.size); in meson_nfc_get_data_oob()
397 buf += nand->ecc.size; in meson_nfc_get_data_oob()
399 osrc = meson_nfc_oob_ptr(nand, i); in meson_nfc_get_data_oob()
405 static void meson_nfc_set_data_oob(struct nand_chip *nand, in meson_nfc_set_data_oob() argument
411 oob_len = nand->ecc.bytes + 2; in meson_nfc_set_data_oob()
412 for (i = 0; i < nand->ecc.steps; i++) { in meson_nfc_set_data_oob()
414 dsrc = meson_nfc_data_ptr(nand, i); in meson_nfc_set_data_oob()
415 memcpy(dsrc, buf, nand->ecc.size); in meson_nfc_set_data_oob()
416 buf += nand->ecc.size; in meson_nfc_set_data_oob()
418 osrc = meson_nfc_oob_ptr(nand, i); in meson_nfc_set_data_oob()
424 static int meson_nfc_wait_no_rb_pin(struct nand_chip *nand, int timeout_ms, in meson_nfc_wait_no_rb_pin() argument
427 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_wait_no_rb_pin()
439 nand_status_op(nand, NULL); in meson_nfc_wait_no_rb_pin()
450 nand_exit_status_op(nand); in meson_nfc_wait_no_rb_pin()
483 static int meson_nfc_queue_rb(struct nand_chip *nand, int timeout_ms, in meson_nfc_queue_rb() argument
486 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_queue_rb()
499 return meson_nfc_wait_no_rb_pin(nand, timeout_ms, in meson_nfc_queue_rb()
506 static void meson_nfc_set_user_byte(struct nand_chip *nand, u8 *oob_buf) in meson_nfc_set_user_byte() argument
508 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_set_user_byte()
512 for (i = 0, count = 0; i < nand->ecc.steps; i++, count += 2) { in meson_nfc_set_user_byte()
519 static void meson_nfc_get_user_byte(struct nand_chip *nand, u8 *oob_buf) in meson_nfc_get_user_byte() argument
521 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_get_user_byte()
525 for (i = 0, count = 0; i < nand->ecc.steps; i++, count += 2) { in meson_nfc_get_user_byte()
532 static int meson_nfc_ecc_correct(struct nand_chip *nand, u32 *bitflips, in meson_nfc_ecc_correct() argument
535 struct mtd_info *mtd = nand_to_mtd(nand); in meson_nfc_ecc_correct()
536 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_ecc_correct()
540 for (i = 0; i < nand->ecc.steps; i++) { in meson_nfc_ecc_correct()
548 if ((nand->options & NAND_NEED_SCRAMBLING) && in meson_nfc_ecc_correct()
549 ECC_ZERO_CNT(*info) < nand->ecc.strength) { in meson_nfc_ecc_correct()
561 static int meson_nfc_dma_buffer_setup(struct nand_chip *nand, void *databuf, in meson_nfc_dma_buffer_setup() argument
565 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_dma_buffer_setup()
601 static void meson_nfc_dma_buffer_release(struct nand_chip *nand, in meson_nfc_dma_buffer_release() argument
605 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_dma_buffer_release()
614 static int meson_nfc_read_buf(struct nand_chip *nand, u8 *buf, int len) in meson_nfc_read_buf() argument
616 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_read_buf()
625 ret = meson_nfc_dma_buffer_setup(nand, buf, len, info, in meson_nfc_read_buf()
635 meson_nfc_dma_buffer_release(nand, len, PER_INFO_BYTE, DMA_FROM_DEVICE); in meson_nfc_read_buf()
643 static int meson_nfc_write_buf(struct nand_chip *nand, u8 *buf, int len) in meson_nfc_write_buf() argument
645 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_write_buf()
649 ret = meson_nfc_dma_buffer_setup(nand, buf, len, NULL, in meson_nfc_write_buf()
659 meson_nfc_dma_buffer_release(nand, len, 0, DMA_TO_DEVICE); in meson_nfc_write_buf()
664 static int meson_nfc_rw_cmd_prepare_and_execute(struct nand_chip *nand, in meson_nfc_rw_cmd_prepare_and_execute() argument
668 nand_get_sdr_timings(nand_get_interface_config(nand)); in meson_nfc_rw_cmd_prepare_and_execute()
669 struct mtd_info *mtd = nand_to_mtd(nand); in meson_nfc_rw_cmd_prepare_and_execute()
670 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_rw_cmd_prepare_and_execute()
693 if (nand->options & NAND_ROW_ADDR_3) in meson_nfc_rw_cmd_prepare_and_execute()
709 meson_nfc_queue_rb(nand, PSEC_TO_MSEC(sdr->tR_max), true); in meson_nfc_rw_cmd_prepare_and_execute()
717 static int meson_nfc_write_page_sub(struct nand_chip *nand, in meson_nfc_write_page_sub() argument
721 nand_get_sdr_timings(nand_get_interface_config(nand)); in meson_nfc_write_page_sub()
722 struct mtd_info *mtd = nand_to_mtd(nand); in meson_nfc_write_page_sub()
723 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_write_page_sub()
724 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_write_page_sub()
729 meson_nfc_select_chip(nand, nand->cur_cs); in meson_nfc_write_page_sub()
732 info_len = nand->ecc.steps * PER_INFO_BYTE; in meson_nfc_write_page_sub()
734 ret = meson_nfc_rw_cmd_prepare_and_execute(nand, page, DIRWRITE); in meson_nfc_write_page_sub()
738 ret = meson_nfc_dma_buffer_setup(nand, meson_chip->data_buf, in meson_nfc_write_page_sub()
744 if (nand->options & NAND_NEED_SCRAMBLING) { in meson_nfc_write_page_sub()
746 meson_nfc_cmd_access(nand, raw, DIRWRITE, in meson_nfc_write_page_sub()
749 meson_nfc_cmd_access(nand, raw, DIRWRITE, in meson_nfc_write_page_sub()
755 meson_nfc_queue_rb(nand, PSEC_TO_MSEC(sdr->tPROG_max), false); in meson_nfc_write_page_sub()
757 meson_nfc_dma_buffer_release(nand, data_len, info_len, DMA_TO_DEVICE); in meson_nfc_write_page_sub()
762 static int meson_nfc_write_page_raw(struct nand_chip *nand, const u8 *buf, in meson_nfc_write_page_raw() argument
765 u8 *oob_buf = nand->oob_poi; in meson_nfc_write_page_raw()
767 meson_nfc_set_data_oob(nand, buf, oob_buf); in meson_nfc_write_page_raw()
769 return meson_nfc_write_page_sub(nand, page, 1); in meson_nfc_write_page_raw()
772 static int meson_nfc_write_page_hwecc(struct nand_chip *nand, in meson_nfc_write_page_hwecc() argument
775 struct mtd_info *mtd = nand_to_mtd(nand); in meson_nfc_write_page_hwecc()
776 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_write_page_hwecc()
777 u8 *oob_buf = nand->oob_poi; in meson_nfc_write_page_hwecc()
780 memset(meson_chip->info_buf, 0, nand->ecc.steps * PER_INFO_BYTE); in meson_nfc_write_page_hwecc()
781 meson_nfc_set_user_byte(nand, oob_buf); in meson_nfc_write_page_hwecc()
783 return meson_nfc_write_page_sub(nand, page, 0); in meson_nfc_write_page_hwecc()
787 struct nand_chip *nand, int raw) in meson_nfc_check_ecc_pages_valid() argument
789 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_check_ecc_pages_valid()
794 neccpages = raw ? 1 : nand->ecc.steps; in meson_nfc_check_ecc_pages_valid()
806 static int meson_nfc_read_page_sub(struct nand_chip *nand, in meson_nfc_read_page_sub() argument
809 struct mtd_info *mtd = nand_to_mtd(nand); in meson_nfc_read_page_sub()
810 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_read_page_sub()
811 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_read_page_sub()
815 meson_nfc_select_chip(nand, nand->cur_cs); in meson_nfc_read_page_sub()
818 info_len = nand->ecc.steps * PER_INFO_BYTE; in meson_nfc_read_page_sub()
820 ret = meson_nfc_rw_cmd_prepare_and_execute(nand, page, DIRREAD); in meson_nfc_read_page_sub()
824 ret = meson_nfc_dma_buffer_setup(nand, meson_chip->data_buf, in meson_nfc_read_page_sub()
830 if (nand->options & NAND_NEED_SCRAMBLING) { in meson_nfc_read_page_sub()
832 meson_nfc_cmd_access(nand, raw, DIRREAD, in meson_nfc_read_page_sub()
835 meson_nfc_cmd_access(nand, raw, DIRREAD, in meson_nfc_read_page_sub()
840 meson_nfc_check_ecc_pages_valid(nfc, nand, raw); in meson_nfc_read_page_sub()
842 meson_nfc_dma_buffer_release(nand, data_len, info_len, DMA_FROM_DEVICE); in meson_nfc_read_page_sub()
847 static int meson_nfc_read_page_raw(struct nand_chip *nand, u8 *buf, in meson_nfc_read_page_raw() argument
850 u8 *oob_buf = nand->oob_poi; in meson_nfc_read_page_raw()
853 ret = meson_nfc_read_page_sub(nand, page, 1); in meson_nfc_read_page_raw()
857 meson_nfc_get_data_oob(nand, buf, oob_buf); in meson_nfc_read_page_raw()
862 static int meson_nfc_read_page_hwecc(struct nand_chip *nand, u8 *buf, in meson_nfc_read_page_hwecc() argument
865 struct mtd_info *mtd = nand_to_mtd(nand); in meson_nfc_read_page_hwecc()
866 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_read_page_hwecc()
867 struct nand_ecc_ctrl *ecc = &nand->ecc; in meson_nfc_read_page_hwecc()
870 u8 *oob_buf = nand->oob_poi; in meson_nfc_read_page_hwecc()
873 ret = meson_nfc_read_page_sub(nand, page, 0); in meson_nfc_read_page_hwecc()
877 meson_nfc_get_user_byte(nand, oob_buf); in meson_nfc_read_page_hwecc()
878 ret = meson_nfc_ecc_correct(nand, &bitflips, &correct_bitmap); in meson_nfc_read_page_hwecc()
884 if ((nand->options & NAND_NEED_SCRAMBLING) || !buf) { in meson_nfc_read_page_hwecc()
888 ret = meson_nfc_read_page_raw(nand, buf, 0, page); in meson_nfc_read_page_hwecc()
892 for (i = 0; i < nand->ecc.steps ; i++) { in meson_nfc_read_page_hwecc()
894 u8 *oob = nand->oob_poi + i * (ecc->bytes + 2); in meson_nfc_read_page_hwecc()
916 static int meson_nfc_read_oob_raw(struct nand_chip *nand, int page) in meson_nfc_read_oob_raw() argument
918 return meson_nfc_read_page_raw(nand, NULL, 1, page); in meson_nfc_read_oob_raw()
921 static int meson_nfc_read_oob(struct nand_chip *nand, int page) in meson_nfc_read_oob() argument
923 return meson_nfc_read_page_hwecc(nand, NULL, 1, page); in meson_nfc_read_oob()
1013 static int meson_nfc_exec_op(struct nand_chip *nand, in meson_nfc_exec_op() argument
1016 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_exec_op()
1017 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_exec_op()
1024 err = meson_nfc_check_op(nand, op); in meson_nfc_exec_op()
1031 meson_nfc_select_chip(nand, op->cs); in meson_nfc_exec_op()
1058 meson_nfc_read_buf(nand, buf, instr->ctx.data.len); in meson_nfc_exec_op()
1066 meson_nfc_write_buf(nand, buf, instr->ctx.data.len); in meson_nfc_exec_op()
1071 meson_nfc_queue_rb(nand, instr->ctx.waitrdy.timeout_ms, in meson_nfc_exec_op()
1085 struct nand_chip *nand = mtd_to_nand(mtd); in meson_ooblayout_ecc() local
1087 if (section >= nand->ecc.steps) in meson_ooblayout_ecc()
1090 oobregion->offset = 2 + (section * (2 + nand->ecc.bytes)); in meson_ooblayout_ecc()
1091 oobregion->length = nand->ecc.bytes; in meson_ooblayout_ecc()
1099 struct nand_chip *nand = mtd_to_nand(mtd); in meson_ooblayout_free() local
1101 if (section >= nand->ecc.steps) in meson_ooblayout_free()
1104 oobregion->offset = section * (2 + nand->ecc.bytes); in meson_ooblayout_free()
1200 static void meson_nfc_free_buffer(struct nand_chip *nand) in meson_nfc_free_buffer() argument
1202 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_free_buffer()
1208 static int meson_chip_buffer_init(struct nand_chip *nand) in meson_chip_buffer_init() argument
1210 struct mtd_info *mtd = nand_to_mtd(nand); in meson_chip_buffer_init()
1211 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_chip_buffer_init()
1214 nsectors = mtd->writesize / nand->ecc.size; in meson_chip_buffer_init()
1233 int meson_nfc_setup_interface(struct nand_chip *nand, int csline, in meson_nfc_setup_interface() argument
1236 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nfc_setup_interface()
1275 static int meson_nand_bch_mode(struct nand_chip *nand) in meson_nand_bch_mode() argument
1277 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nand_bch_mode()
1280 if (nand->ecc.strength > 60 || nand->ecc.strength < 8) in meson_nand_bch_mode()
1284 if (meson_ecc[i].strength == nand->ecc.strength && in meson_nand_bch_mode()
1285 meson_ecc[i].size == nand->ecc.size) { in meson_nand_bch_mode()
1294 static void meson_nand_detach_chip(struct nand_chip *nand) in meson_nand_detach_chip() argument
1296 meson_nfc_free_buffer(nand); in meson_nand_detach_chip()
1299 static int meson_nand_attach_chip(struct nand_chip *nand) in meson_nand_attach_chip() argument
1301 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nand_attach_chip()
1302 struct meson_nfc_nand_chip *meson_chip = to_meson_nand(nand); in meson_nand_attach_chip()
1303 struct mtd_info *mtd = nand_to_mtd(nand); in meson_nand_attach_chip()
1323 if (nand->bbt_options & NAND_BBT_USE_FLASH) in meson_nand_attach_chip()
1324 nand->bbt_options |= NAND_BBT_NO_OOB; in meson_nand_attach_chip()
1326 nand->options |= NAND_NO_SUBPAGE_WRITE; in meson_nand_attach_chip()
1328 ret = nand_ecc_choose_conf(nand, nfc->data->ecc_caps, in meson_nand_attach_chip()
1337 ret = meson_nand_bch_mode(nand); in meson_nand_attach_chip()
1341 nand->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST; in meson_nand_attach_chip()
1342 nand->ecc.write_page_raw = meson_nfc_write_page_raw; in meson_nand_attach_chip()
1343 nand->ecc.write_page = meson_nfc_write_page_hwecc; in meson_nand_attach_chip()
1344 nand->ecc.write_oob_raw = nand_write_oob_std; in meson_nand_attach_chip()
1345 nand->ecc.write_oob = nand_write_oob_std; in meson_nand_attach_chip()
1347 nand->ecc.read_page_raw = meson_nfc_read_page_raw; in meson_nand_attach_chip()
1348 nand->ecc.read_page = meson_nfc_read_page_hwecc; in meson_nand_attach_chip()
1349 nand->ecc.read_oob_raw = meson_nfc_read_oob_raw; in meson_nand_attach_chip()
1350 nand->ecc.read_oob = meson_nfc_read_oob; in meson_nand_attach_chip()
1352 if (nand->options & NAND_BUSWIDTH_16) { in meson_nand_attach_chip()
1356 ret = meson_chip_buffer_init(nand); in meson_nand_attach_chip()
1375 struct nand_chip *nand; in meson_nfc_nand_chip_init() local
1408 nand = &meson_chip->nand; in meson_nfc_nand_chip_init()
1409 nand->controller = &nfc->controller; in meson_nfc_nand_chip_init()
1410 nand->controller->ops = &meson_nand_controller_ops; in meson_nfc_nand_chip_init()
1411 nand_set_flash_node(nand, np); in meson_nfc_nand_chip_init()
1412 nand_set_controller_data(nand, nfc); in meson_nfc_nand_chip_init()
1414 nand->options |= NAND_USES_DMA; in meson_nfc_nand_chip_init()
1415 mtd = nand_to_mtd(nand); in meson_nfc_nand_chip_init()
1428 ret = nand_scan(nand, nsels); in meson_nfc_nand_chip_init()
1435 nand_cleanup(nand); in meson_nfc_nand_chip_init()
1452 mtd = nand_to_mtd(&meson_chip->nand); in meson_nfc_nand_chip_cleanup()
1455 nand_cleanup(&meson_chip->nand); in meson_nfc_nand_chip_cleanup()