Lines Matching defs:nand

184  * @nand: base NAND chip structure
193 struct nand_chip nand;
201 static inline struct sunxi_nand_chip *to_sunxi_nand(struct nand_chip *nand)
203 return container_of(nand, struct sunxi_nand_chip, nand);
405 static void sunxi_nfc_select_chip(struct nand_chip *nand, unsigned int cs)
407 struct mtd_info *mtd = nand_to_mtd(nand);
408 struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
409 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller);
420 ctl |= NFC_CE_SEL(sel->cs) | NFC_EN | NFC_PAGE_SHIFT(nand->page_shift);
436 static void sunxi_nfc_read_buf(struct nand_chip *nand, uint8_t *buf, int len)
438 struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
439 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller);
473 static void sunxi_nfc_write_buf(struct nand_chip *nand, const uint8_t *buf,
476 struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
477 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller);
592 static u16 sunxi_nfc_randomizer_state(struct nand_chip *nand, int page,
595 struct mtd_info *mtd = nand_to_mtd(nand);
612 static void sunxi_nfc_randomizer_config(struct nand_chip *nand, int page,
615 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
619 if (!(nand->options & NAND_NEED_SCRAMBLING))
623 state = sunxi_nfc_randomizer_state(nand, page, ecc);
628 static void sunxi_nfc_randomizer_enable(struct nand_chip *nand)
630 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
632 if (!(nand->options & NAND_NEED_SCRAMBLING))
639 static void sunxi_nfc_randomizer_disable(struct nand_chip *nand)
641 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
643 if (!(nand->options & NAND_NEED_SCRAMBLING))
650 static void sunxi_nfc_randomize_bbm(struct nand_chip *nand, int page, u8 *bbm)
652 u16 state = sunxi_nfc_randomizer_state(nand, page, true);
658 static void sunxi_nfc_randomizer_write_buf(struct nand_chip *nand,
662 sunxi_nfc_randomizer_config(nand, page, ecc);
663 sunxi_nfc_randomizer_enable(nand);
664 sunxi_nfc_write_buf(nand, buf, len);
665 sunxi_nfc_randomizer_disable(nand);
668 static void sunxi_nfc_randomizer_read_buf(struct nand_chip *nand, uint8_t *buf,
671 sunxi_nfc_randomizer_config(nand, page, ecc);
672 sunxi_nfc_randomizer_enable(nand);
673 sunxi_nfc_read_buf(nand, buf, len);
674 sunxi_nfc_randomizer_disable(nand);
677 static void sunxi_nfc_hw_ecc_enable(struct nand_chip *nand)
679 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
680 struct sunxi_nand_hw_ecc *data = nand->ecc.priv;
689 if (nand->ecc.size == 512)
695 static void sunxi_nfc_hw_ecc_disable(struct nand_chip *nand)
697 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
716 static void sunxi_nfc_hw_ecc_get_prot_oob_bytes(struct nand_chip *nand, u8 *oob,
719 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
725 if (bbm && (nand->options & NAND_NEED_SCRAMBLING))
726 sunxi_nfc_randomize_bbm(nand, page, oob);
729 static void sunxi_nfc_hw_ecc_set_prot_oob_bytes(struct nand_chip *nand,
733 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
737 if (bbm && (nand->options & NAND_NEED_SCRAMBLING)) {
739 sunxi_nfc_randomize_bbm(nand, page, user_data);
747 static void sunxi_nfc_hw_ecc_update_stats(struct nand_chip *nand,
750 struct mtd_info *mtd = nand_to_mtd(nand);
760 static int sunxi_nfc_hw_ecc_correct(struct nand_chip *nand, u8 *data, u8 *oob,
763 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
764 struct nand_ecc_ctrl *ecc = &nand->ecc;
796 static int sunxi_nfc_hw_ecc_read_chunk(struct nand_chip *nand,
803 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
804 struct nand_ecc_ctrl *ecc = &nand->ecc;
810 nand_change_read_column_op(nand, data_off, NULL, 0, false);
812 sunxi_nfc_randomizer_read_buf(nand, NULL, ecc->size, false, page);
815 nand_change_read_column_op(nand, oob_off, NULL, 0, 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);
941 sunxi_nfc_randomizer_disable(nand);
942 sunxi_nfc_hw_ecc_disable(nand);
955 u8 *oob = nand->oob_poi + oob_off;
958 ret = sunxi_nfc_hw_ecc_correct(nand, randomized ? data : NULL,
968 nand_change_read_column_op(nand,
972 sunxi_nfc_hw_ecc_get_prot_oob_bytes(nand, oob, i,
979 sunxi_nfc_hw_ecc_update_stats(nand, &max_bitflips, ret);
987 u8 *oob = nand->oob_poi + oob_off;
998 nand_change_read_column_op(nand, data_off,
1003 nand_change_read_column_op(nand,
1014 sunxi_nfc_hw_ecc_update_stats(nand, &max_bitflips, ret);
1019 sunxi_nfc_hw_ecc_read_extra_oob(nand, nand->oob_poi,
1026 static int sunxi_nfc_hw_ecc_write_chunk(struct nand_chip *nand,
1032 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
1033 struct nand_ecc_ctrl *ecc = &nand->ecc;
1037 nand_change_write_column_op(nand, data_off, NULL, 0, false);
1039 sunxi_nfc_randomizer_write_buf(nand, data, ecc->size, false, page);
1042 nand_change_write_column_op(nand, oob_off, NULL, 0, false);
1048 sunxi_nfc_randomizer_enable(nand);
1049 sunxi_nfc_hw_ecc_set_prot_oob_bytes(nand, oob, 0, bbm, page);
1056 sunxi_nfc_randomizer_disable(nand);
1065 static void sunxi_nfc_hw_ecc_write_extra_oob(struct nand_chip *nand,
1069 struct mtd_info *mtd = nand_to_mtd(nand);
1070 struct nand_ecc_ctrl *ecc = &nand->ecc;
1078 nand_change_write_column_op(nand, offset + mtd->writesize,
1081 sunxi_nfc_randomizer_write_buf(nand, oob + offset, len, false, page);
1087 static int sunxi_nfc_hw_ecc_read_page(struct nand_chip *nand, uint8_t *buf,
1090 struct mtd_info *mtd = nand_to_mtd(nand);
1091 struct nand_ecc_ctrl *ecc = &nand->ecc;
1096 sunxi_nfc_select_chip(nand, nand->cur_cs);
1098 nand_read_page_op(nand, page, 0, NULL, 0);
1100 sunxi_nfc_hw_ecc_enable(nand);
1106 u8 *oob = nand->oob_poi + oob_off;
1108 ret = sunxi_nfc_hw_ecc_read_chunk(nand, data, data_off, oob,
1119 sunxi_nfc_hw_ecc_read_extra_oob(nand, nand->oob_poi, &cur_off,
1122 sunxi_nfc_hw_ecc_disable(nand);
1127 static int sunxi_nfc_hw_ecc_read_page_dma(struct nand_chip *nand, u8 *buf,
1132 sunxi_nfc_select_chip(nand, nand->cur_cs);
1134 nand_read_page_op(nand, page, 0, NULL, 0);
1136 ret = sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, oob_required, page,
1137 nand->ecc.steps);
1142 return sunxi_nfc_hw_ecc_read_page(nand, buf, oob_required, page);
1145 static int sunxi_nfc_hw_ecc_read_subpage(struct nand_chip *nand,
1149 struct mtd_info *mtd = nand_to_mtd(nand);
1150 struct nand_ecc_ctrl *ecc = &nand->ecc;
1154 sunxi_nfc_select_chip(nand, nand->cur_cs);
1156 nand_read_page_op(nand, page, 0, NULL, 0);
1158 sunxi_nfc_hw_ecc_enable(nand);
1165 u8 *oob = nand->oob_poi + oob_off;
1167 ret = sunxi_nfc_hw_ecc_read_chunk(nand, data, data_off,
1176 sunxi_nfc_hw_ecc_disable(nand);
1181 static int sunxi_nfc_hw_ecc_read_subpage_dma(struct nand_chip *nand,
1185 int nchunks = DIV_ROUND_UP(data_offs + readlen, nand->ecc.size);
1188 sunxi_nfc_select_chip(nand, nand->cur_cs);
1190 nand_read_page_op(nand, page, 0, NULL, 0);
1192 ret = sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, false, page, nchunks);
1197 return sunxi_nfc_hw_ecc_read_subpage(nand, data_offs, readlen,
1201 static int sunxi_nfc_hw_ecc_write_page(struct nand_chip *nand,
1205 struct mtd_info *mtd = nand_to_mtd(nand);
1206 struct nand_ecc_ctrl *ecc = &nand->ecc;
1209 sunxi_nfc_select_chip(nand, nand->cur_cs);
1211 nand_prog_page_begin_op(nand, page, 0, NULL, 0);
1213 sunxi_nfc_hw_ecc_enable(nand);
1219 const u8 *oob = nand->oob_poi + oob_off;
1221 ret = sunxi_nfc_hw_ecc_write_chunk(nand, data, data_off, oob,
1228 if (oob_required || (nand->options & NAND_NEED_SCRAMBLING))
1229 sunxi_nfc_hw_ecc_write_extra_oob(nand, nand->oob_poi,
1232 sunxi_nfc_hw_ecc_disable(nand);
1234 return nand_prog_page_end_op(nand);
1237 static int sunxi_nfc_hw_ecc_write_subpage(struct nand_chip *nand,
1242 struct mtd_info *mtd = nand_to_mtd(nand);
1243 struct nand_ecc_ctrl *ecc = &nand->ecc;
1246 sunxi_nfc_select_chip(nand, nand->cur_cs);
1248 nand_prog_page_begin_op(nand, page, 0, NULL, 0);
1250 sunxi_nfc_hw_ecc_enable(nand);
1257 const u8 *oob = nand->oob_poi + oob_off;
1259 ret = sunxi_nfc_hw_ecc_write_chunk(nand, data, data_off, oob,
1266 sunxi_nfc_hw_ecc_disable(nand);
1268 return nand_prog_page_end_op(nand);
1271 static int sunxi_nfc_hw_ecc_write_page_dma(struct nand_chip *nand,
1276 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
1277 struct nand_ecc_ctrl *ecc = &nand->ecc;
1281 sunxi_nfc_select_chip(nand, nand->cur_cs);
1293 const u8 *oob = nand->oob_poi + (i * (ecc->bytes + 4));
1295 sunxi_nfc_hw_ecc_set_prot_oob_bytes(nand, oob, i, !i, page);
1298 nand_prog_page_begin_op(nand, page, 0, NULL, 0);
1300 sunxi_nfc_hw_ecc_enable(nand);
1301 sunxi_nfc_randomizer_config(nand, page, false);
1302 sunxi_nfc_randomizer_enable(nand);
1317 sunxi_nfc_randomizer_disable(nand);
1318 sunxi_nfc_hw_ecc_disable(nand);
1325 if (oob_required || (nand->options & NAND_NEED_SCRAMBLING))
1327 sunxi_nfc_hw_ecc_write_extra_oob(nand, nand->oob_poi,
1330 return nand_prog_page_end_op(nand);
1333 return sunxi_nfc_hw_ecc_write_page(nand, buf, oob_required, page);
1336 static int sunxi_nfc_hw_ecc_read_oob(struct nand_chip *nand, int page)
1338 u8 *buf = nand_get_data_buf(nand);
1340 return nand->ecc.read_page(nand, buf, 1, page);
1343 static int sunxi_nfc_hw_ecc_write_oob(struct nand_chip *nand, int page)
1345 struct mtd_info *mtd = nand_to_mtd(nand);
1346 u8 *buf = nand_get_data_buf(nand);
1350 ret = nand->ecc.write_page(nand, buf, 1, page);
1355 return nand_prog_page_end_op(nand);
1379 static int sunxi_nfc_setup_interface(struct nand_chip *nand, int csline,
1382 struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
1383 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller);
1552 struct nand_chip *nand = mtd_to_nand(mtd);
1553 struct nand_ecc_ctrl *ecc = &nand->ecc;
1567 struct nand_chip *nand = mtd_to_nand(mtd);
1568 struct nand_ecc_ctrl *ecc = &nand->ecc;
1605 static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand,
1610 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
1611 struct mtd_info *mtd = nand_to_mtd(nand);
1702 nand->options |= NAND_USES_DMA;
1734 static int sunxi_nand_attach_chip(struct nand_chip *nand)
1737 nanddev_get_ecc_requirements(&nand->base);
1738 struct nand_ecc_ctrl *ecc = &nand->ecc;
1739 struct device_node *np = nand_get_flash_node(nand);
1742 if (nand->bbt_options & NAND_BBT_USE_FLASH)
1743 nand->bbt_options |= NAND_BBT_NO_OOB;
1745 if (nand->options & NAND_NEED_SCRAMBLING)
1746 nand->options |= NAND_NO_SUBPAGE_WRITE;
1748 nand->options |= NAND_SUBPAGE_READ;
1760 ret = sunxi_nand_hw_ecc_ctrl_init(nand, ecc, np);
1774 static int sunxi_nfc_exec_subop(struct nand_chip *nand,
1777 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
1870 static int sunxi_nfc_soft_waitrdy(struct nand_chip *nand,
1873 return nand_soft_waitrdy(nand,
1907 static int sunxi_nfc_exec_op(struct nand_chip *nand,
1910 struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
1914 sunxi_nfc_select_chip(nand, op->cs);
1921 return nand_op_parser_exec_op(nand, parser, op, check_only);
1935 struct nand_chip *nand;
1988 nand = &sunxi_nand->nand;
1990 nand->controller = &nfc->controller;
1991 nand->controller->ops = &sunxi_nand_controller_ops;
1997 nand->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
1998 nand_set_flash_node(nand, np);
2000 mtd = nand_to_mtd(nand);
2003 ret = nand_scan(nand, nsels);
2010 nand_cleanup(nand);
2052 chip = &sunxi_nand->nand;
2131 0, "sunxi-nand", nfc);
2164 dev_err(dev, "failed to init nand chips\n");
2212 .compatible = "allwinner,sun4i-a10-nand",
2216 .compatible = "allwinner,sun8i-a23-nand-controller",