Lines Matching refs:nand
184 * @nand: base NAND chip structure
194 struct nand_chip nand;
203 static inline struct sunxi_nand_chip *to_sunxi_nand(struct nand_chip *nand)
205 return container_of(nand, struct sunxi_nand_chip, nand);
415 static void sunxi_nfc_select_chip(struct nand_chip *nand, unsigned int cs)
417 struct mtd_info *mtd = nand_to_mtd(nand);
418 struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
419 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller);
430 ctl |= NFC_CE_SEL(sel->cs) | NFC_EN | NFC_PAGE_SHIFT(nand->page_shift);
446 static void sunxi_nfc_read_buf(struct nand_chip *nand, uint8_t *buf, int len)
448 struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
449 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller);
483 static void sunxi_nfc_write_buf(struct nand_chip *nand, const uint8_t *buf,
486 struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
487 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller);
602 static u16 sunxi_nfc_randomizer_state(struct nand_chip *nand, int page,
605 struct mtd_info *mtd = nand_to_mtd(nand);
622 static void sunxi_nfc_randomizer_config(struct nand_chip *nand, int page,
625 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
629 if (!(nand->options & NAND_NEED_SCRAMBLING))
633 state = sunxi_nfc_randomizer_state(nand, page, ecc);
638 static void sunxi_nfc_randomizer_enable(struct nand_chip *nand)
640 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
642 if (!(nand->options & NAND_NEED_SCRAMBLING))
649 static void sunxi_nfc_randomizer_disable(struct nand_chip *nand)
651 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
653 if (!(nand->options & NAND_NEED_SCRAMBLING))
660 static void sunxi_nfc_randomize_bbm(struct nand_chip *nand, int page, u8 *bbm)
662 u16 state = sunxi_nfc_randomizer_state(nand, page, true);
668 static void sunxi_nfc_randomizer_write_buf(struct nand_chip *nand,
672 sunxi_nfc_randomizer_config(nand, page, ecc);
673 sunxi_nfc_randomizer_enable(nand);
674 sunxi_nfc_write_buf(nand, buf, len);
675 sunxi_nfc_randomizer_disable(nand);
678 static void sunxi_nfc_randomizer_read_buf(struct nand_chip *nand, uint8_t *buf,
681 sunxi_nfc_randomizer_config(nand, page, ecc);
682 sunxi_nfc_randomizer_enable(nand);
683 sunxi_nfc_read_buf(nand, buf, len);
684 sunxi_nfc_randomizer_disable(nand);
687 static void sunxi_nfc_hw_ecc_enable(struct nand_chip *nand)
689 struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
690 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
695 static void sunxi_nfc_hw_ecc_disable(struct nand_chip *nand)
697 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
715 static void sunxi_nfc_hw_ecc_get_prot_oob_bytes(struct nand_chip *nand, u8 *oob,
718 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
724 if (bbm && (nand->options & NAND_NEED_SCRAMBLING))
725 sunxi_nfc_randomize_bbm(nand, page, oob);
728 static void sunxi_nfc_hw_ecc_set_prot_oob_bytes(struct nand_chip *nand,
732 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
736 if (bbm && (nand->options & NAND_NEED_SCRAMBLING)) {
738 sunxi_nfc_randomize_bbm(nand, page, user_data);
746 static void sunxi_nfc_hw_ecc_update_stats(struct nand_chip *nand,
749 struct mtd_info *mtd = nand_to_mtd(nand);
759 static int sunxi_nfc_hw_ecc_correct(struct nand_chip *nand, u8 *data, u8 *oob,
762 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
763 struct nand_ecc_ctrl *ecc = &nand->ecc;
795 static int sunxi_nfc_hw_ecc_read_chunk(struct nand_chip *nand,
802 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
803 struct nand_ecc_ctrl *ecc = &nand->ecc;
809 nand_change_read_column_op(nand, data_off, NULL, 0, false);
811 sunxi_nfc_randomizer_read_buf(nand, NULL, ecc->size, false, page);
814 nand_change_read_column_op(nand, oob_off, NULL, 0, false);
820 sunxi_nfc_randomizer_config(nand, page, false);
821 sunxi_nfc_randomizer_enable(nand);
826 sunxi_nfc_randomizer_disable(nand);
832 ret = sunxi_nfc_hw_ecc_correct(nand, data, oob_required ? oob : NULL, 0,
843 if (nand->options & NAND_NEED_SCRAMBLING)
844 nand_change_read_column_op(nand, data_off, data,
850 nand_change_read_column_op(nand, oob_off, oob, ecc->bytes + 4,
862 nand_change_read_column_op(nand, oob_off, NULL, 0,
864 sunxi_nfc_randomizer_read_buf(nand, oob, ecc->bytes + 4,
867 sunxi_nfc_hw_ecc_get_prot_oob_bytes(nand, oob, 0,
872 sunxi_nfc_hw_ecc_update_stats(nand, max_bitflips, ret);
877 static void sunxi_nfc_hw_ecc_read_extra_oob(struct nand_chip *nand,
881 struct mtd_info *mtd = nand_to_mtd(nand);
882 struct nand_ecc_ctrl *ecc = &nand->ecc;
890 nand_change_read_column_op(nand, mtd->writesize, NULL, 0,
894 sunxi_nfc_read_buf(nand, oob + offset, len);
896 sunxi_nfc_randomizer_read_buf(nand, oob + offset, len,
903 static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nand_chip *nand, uint8_t *buf,
907 bool randomized = nand->options & NAND_NEED_SCRAMBLING;
908 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
909 struct mtd_info *mtd = nand_to_mtd(nand);
910 struct nand_ecc_ctrl *ecc = &nand->ecc;
925 sunxi_nfc_hw_ecc_enable(nand);
926 sunxi_nfc_randomizer_config(nand, page, false);
927 sunxi_nfc_randomizer_enable(nand);
946 sunxi_nfc_randomizer_disable(nand);
947 sunxi_nfc_hw_ecc_disable(nand);
960 u8 *oob = nand->oob_poi + oob_off;
963 ret = sunxi_nfc_hw_ecc_correct(nand, randomized ? data : NULL,
973 nand_change_read_column_op(nand,
977 sunxi_nfc_hw_ecc_get_prot_oob_bytes(nand, oob, i,
984 sunxi_nfc_hw_ecc_update_stats(nand, &max_bitflips, ret);
992 u8 *oob = nand->oob_poi + oob_off;
1003 nand_change_read_column_op(nand, data_off,
1008 nand_change_read_column_op(nand,
1019 sunxi_nfc_hw_ecc_update_stats(nand, &max_bitflips, ret);
1024 sunxi_nfc_hw_ecc_read_extra_oob(nand, nand->oob_poi,
1031 static int sunxi_nfc_hw_ecc_write_chunk(struct nand_chip *nand,
1037 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
1038 struct nand_ecc_ctrl *ecc = &nand->ecc;
1042 nand_change_write_column_op(nand, data_off, NULL, 0, false);
1044 sunxi_nfc_randomizer_write_buf(nand, data, ecc->size, false, page);
1047 nand_change_write_column_op(nand, oob_off, NULL, 0, false);
1053 sunxi_nfc_randomizer_config(nand, page, false);
1054 sunxi_nfc_randomizer_enable(nand);
1055 sunxi_nfc_hw_ecc_set_prot_oob_bytes(nand, oob, 0, bbm, page);
1062 sunxi_nfc_randomizer_disable(nand);
1071 static void sunxi_nfc_hw_ecc_write_extra_oob(struct nand_chip *nand,
1075 struct mtd_info *mtd = nand_to_mtd(nand);
1076 struct nand_ecc_ctrl *ecc = &nand->ecc;
1084 nand_change_write_column_op(nand, offset + mtd->writesize,
1087 sunxi_nfc_randomizer_write_buf(nand, oob + offset, len, false, page);
1093 static int sunxi_nfc_hw_ecc_read_page(struct nand_chip *nand, uint8_t *buf,
1096 struct mtd_info *mtd = nand_to_mtd(nand);
1097 struct nand_ecc_ctrl *ecc = &nand->ecc;
1102 sunxi_nfc_select_chip(nand, nand->cur_cs);
1104 nand_read_page_op(nand, page, 0, NULL, 0);
1106 sunxi_nfc_hw_ecc_enable(nand);
1112 u8 *oob = nand->oob_poi + oob_off;
1114 ret = sunxi_nfc_hw_ecc_read_chunk(nand, data, data_off, oob,
1125 sunxi_nfc_hw_ecc_read_extra_oob(nand, nand->oob_poi, &cur_off,
1128 sunxi_nfc_hw_ecc_disable(nand);
1133 static int sunxi_nfc_hw_ecc_read_page_dma(struct nand_chip *nand, u8 *buf,
1138 sunxi_nfc_select_chip(nand, nand->cur_cs);
1140 nand_read_page_op(nand, page, 0, NULL, 0);
1142 ret = sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, oob_required, page,
1143 nand->ecc.steps);
1148 return sunxi_nfc_hw_ecc_read_page(nand, buf, oob_required, page);
1151 static int sunxi_nfc_hw_ecc_read_subpage(struct nand_chip *nand,
1155 struct mtd_info *mtd = nand_to_mtd(nand);
1156 struct nand_ecc_ctrl *ecc = &nand->ecc;
1160 sunxi_nfc_select_chip(nand, nand->cur_cs);
1162 nand_read_page_op(nand, page, 0, NULL, 0);
1164 sunxi_nfc_hw_ecc_enable(nand);
1171 u8 *oob = nand->oob_poi + oob_off;
1173 ret = sunxi_nfc_hw_ecc_read_chunk(nand, data, data_off,
1182 sunxi_nfc_hw_ecc_disable(nand);
1187 static int sunxi_nfc_hw_ecc_read_subpage_dma(struct nand_chip *nand,
1191 int nchunks = DIV_ROUND_UP(data_offs + readlen, nand->ecc.size);
1194 sunxi_nfc_select_chip(nand, nand->cur_cs);
1196 nand_read_page_op(nand, page, 0, NULL, 0);
1198 ret = sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, false, page, nchunks);
1203 return sunxi_nfc_hw_ecc_read_subpage(nand, data_offs, readlen,
1207 static int sunxi_nfc_hw_ecc_write_page(struct nand_chip *nand,
1211 struct mtd_info *mtd = nand_to_mtd(nand);
1212 struct nand_ecc_ctrl *ecc = &nand->ecc;
1215 sunxi_nfc_select_chip(nand, nand->cur_cs);
1217 nand_prog_page_begin_op(nand, page, 0, NULL, 0);
1219 sunxi_nfc_hw_ecc_enable(nand);
1225 const u8 *oob = nand->oob_poi + oob_off;
1227 ret = sunxi_nfc_hw_ecc_write_chunk(nand, data, data_off, oob,
1234 if (oob_required || (nand->options & NAND_NEED_SCRAMBLING))
1235 sunxi_nfc_hw_ecc_write_extra_oob(nand, nand->oob_poi,
1238 sunxi_nfc_hw_ecc_disable(nand);
1240 return nand_prog_page_end_op(nand);
1243 static int sunxi_nfc_hw_ecc_write_subpage(struct nand_chip *nand,
1248 struct mtd_info *mtd = nand_to_mtd(nand);
1249 struct nand_ecc_ctrl *ecc = &nand->ecc;
1252 sunxi_nfc_select_chip(nand, nand->cur_cs);
1254 nand_prog_page_begin_op(nand, page, 0, NULL, 0);
1256 sunxi_nfc_hw_ecc_enable(nand);
1263 const u8 *oob = nand->oob_poi + oob_off;
1265 ret = sunxi_nfc_hw_ecc_write_chunk(nand, data, data_off, oob,
1272 sunxi_nfc_hw_ecc_disable(nand);
1274 return nand_prog_page_end_op(nand);
1277 static int sunxi_nfc_hw_ecc_write_page_dma(struct nand_chip *nand,
1282 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
1283 struct nand_ecc_ctrl *ecc = &nand->ecc;
1288 sunxi_nfc_select_chip(nand, nand->cur_cs);
1300 const u8 *oob = nand->oob_poi + (i * (ecc->bytes + 4));
1302 sunxi_nfc_hw_ecc_set_prot_oob_bytes(nand, oob, i, !i, page);
1305 nand_prog_page_begin_op(nand, page, 0, NULL, 0);
1307 sunxi_nfc_hw_ecc_enable(nand);
1308 sunxi_nfc_randomizer_config(nand, page, false);
1309 sunxi_nfc_randomizer_enable(nand);
1329 sunxi_nfc_randomizer_disable(nand);
1330 sunxi_nfc_hw_ecc_disable(nand);
1337 if (oob_required || (nand->options & NAND_NEED_SCRAMBLING))
1339 sunxi_nfc_hw_ecc_write_extra_oob(nand, nand->oob_poi,
1342 return nand_prog_page_end_op(nand);
1345 return sunxi_nfc_hw_ecc_write_page(nand, buf, oob_required, page);
1348 static int sunxi_nfc_hw_ecc_read_oob(struct nand_chip *nand, int page)
1350 u8 *buf = nand_get_data_buf(nand);
1352 return nand->ecc.read_page(nand, buf, 1, page);
1355 static int sunxi_nfc_hw_ecc_write_oob(struct nand_chip *nand, int page)
1357 struct mtd_info *mtd = nand_to_mtd(nand);
1358 u8 *buf = nand_get_data_buf(nand);
1362 ret = nand->ecc.write_page(nand, buf, 1, page);
1367 return nand_prog_page_end_op(nand);
1391 static int sunxi_nfc_setup_interface(struct nand_chip *nand, int csline,
1394 struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
1395 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller);
1564 struct nand_chip *nand = mtd_to_nand(mtd);
1565 struct nand_ecc_ctrl *ecc = &nand->ecc;
1579 struct nand_chip *nand = mtd_to_nand(mtd);
1580 struct nand_ecc_ctrl *ecc = &nand->ecc;
1619 static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand,
1624 struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
1625 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
1626 struct mtd_info *mtd = nand_to_mtd(nand);
1705 nand->options |= NAND_USES_DMA;
1726 static int sunxi_nand_attach_chip(struct nand_chip *nand)
1729 nanddev_get_ecc_requirements(&nand->base);
1730 struct nand_ecc_ctrl *ecc = &nand->ecc;
1731 struct device_node *np = nand_get_flash_node(nand);
1734 if (nand->bbt_options & NAND_BBT_USE_FLASH)
1735 nand->bbt_options |= NAND_BBT_NO_OOB;
1737 if (nand->options & NAND_NEED_SCRAMBLING)
1738 nand->options |= NAND_NO_SUBPAGE_WRITE;
1740 nand->options |= NAND_SUBPAGE_READ;
1752 ret = sunxi_nand_hw_ecc_ctrl_init(nand, ecc, np);
1766 static int sunxi_nfc_exec_subop(struct nand_chip *nand,
1769 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
1862 static int sunxi_nfc_soft_waitrdy(struct nand_chip *nand,
1865 return nand_soft_waitrdy(nand,
1899 static int sunxi_nfc_exec_op(struct nand_chip *nand,
1902 struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
1906 sunxi_nfc_select_chip(nand, op->cs);
1913 return nand_op_parser_exec_op(nand, parser, op, check_only);
1932 chip = &sunxi_nand->nand;
1945 struct nand_chip *nand;
1996 nand = &sunxi_nand->nand;
1998 nand->controller = &nfc->controller;
1999 nand->controller->ops = &sunxi_nand_controller_ops;
2005 nand->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
2006 nand_set_flash_node(nand, np);
2008 mtd = nand_to_mtd(nand);
2011 ret = nand_scan(nand, nsels);
2018 nand_cleanup(nand);
2131 0, "sunxi-nand", nfc);
2144 dev_err(dev, "failed to init nand chips\n");
2184 .compatible = "allwinner,sun4i-a10-nand",
2188 .compatible = "allwinner,sun8i-a23-nand-controller",