Lines Matching defs: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_enable(nand);
825 sunxi_nfc_randomizer_disable(nand);
831 ret = sunxi_nfc_hw_ecc_correct(nand, data, oob_required ? oob : NULL, 0,
842 if (nand->options & NAND_NEED_SCRAMBLING)
843 nand_change_read_column_op(nand, data_off, data,
849 nand_change_read_column_op(nand, oob_off, oob, ecc->bytes + 4,
861 nand_change_read_column_op(nand, oob_off, NULL, 0,
863 sunxi_nfc_randomizer_read_buf(nand, oob, ecc->bytes + 4,
866 sunxi_nfc_hw_ecc_get_prot_oob_bytes(nand, oob, 0,
871 sunxi_nfc_hw_ecc_update_stats(nand, max_bitflips, ret);
876 static void sunxi_nfc_hw_ecc_read_extra_oob(struct nand_chip *nand,
880 struct mtd_info *mtd = nand_to_mtd(nand);
881 struct nand_ecc_ctrl *ecc = &nand->ecc;
889 nand_change_read_column_op(nand, mtd->writesize, NULL, 0,
893 sunxi_nfc_read_buf(nand, oob + offset, len);
895 sunxi_nfc_randomizer_read_buf(nand, oob + offset, len,
902 static int sunxi_nfc_hw_ecc_read_chunks_dma(struct nand_chip *nand, uint8_t *buf,
906 bool randomized = nand->options & NAND_NEED_SCRAMBLING;
907 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
908 struct mtd_info *mtd = nand_to_mtd(nand);
909 struct nand_ecc_ctrl *ecc = &nand->ecc;
924 sunxi_nfc_hw_ecc_enable(nand);
925 sunxi_nfc_randomizer_config(nand, page, false);
926 sunxi_nfc_randomizer_enable(nand);
945 sunxi_nfc_randomizer_disable(nand);
946 sunxi_nfc_hw_ecc_disable(nand);
959 u8 *oob = nand->oob_poi + oob_off;
962 ret = sunxi_nfc_hw_ecc_correct(nand, randomized ? data : NULL,
972 nand_change_read_column_op(nand,
976 sunxi_nfc_hw_ecc_get_prot_oob_bytes(nand, oob, i,
983 sunxi_nfc_hw_ecc_update_stats(nand, &max_bitflips, ret);
991 u8 *oob = nand->oob_poi + oob_off;
1002 nand_change_read_column_op(nand, data_off,
1007 nand_change_read_column_op(nand,
1018 sunxi_nfc_hw_ecc_update_stats(nand, &max_bitflips, ret);
1023 sunxi_nfc_hw_ecc_read_extra_oob(nand, nand->oob_poi,
1030 static int sunxi_nfc_hw_ecc_write_chunk(struct nand_chip *nand,
1036 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
1037 struct nand_ecc_ctrl *ecc = &nand->ecc;
1041 nand_change_write_column_op(nand, data_off, NULL, 0, false);
1043 sunxi_nfc_randomizer_write_buf(nand, data, ecc->size, false, page);
1046 nand_change_write_column_op(nand, oob_off, NULL, 0, false);
1052 sunxi_nfc_randomizer_enable(nand);
1053 sunxi_nfc_hw_ecc_set_prot_oob_bytes(nand, oob, 0, bbm, page);
1060 sunxi_nfc_randomizer_disable(nand);
1069 static void sunxi_nfc_hw_ecc_write_extra_oob(struct nand_chip *nand,
1073 struct mtd_info *mtd = nand_to_mtd(nand);
1074 struct nand_ecc_ctrl *ecc = &nand->ecc;
1082 nand_change_write_column_op(nand, offset + mtd->writesize,
1085 sunxi_nfc_randomizer_write_buf(nand, oob + offset, len, false, page);
1091 static int sunxi_nfc_hw_ecc_read_page(struct nand_chip *nand, uint8_t *buf,
1094 struct mtd_info *mtd = nand_to_mtd(nand);
1095 struct nand_ecc_ctrl *ecc = &nand->ecc;
1100 sunxi_nfc_select_chip(nand, nand->cur_cs);
1102 nand_read_page_op(nand, page, 0, NULL, 0);
1104 sunxi_nfc_hw_ecc_enable(nand);
1110 u8 *oob = nand->oob_poi + oob_off;
1112 ret = sunxi_nfc_hw_ecc_read_chunk(nand, data, data_off, oob,
1123 sunxi_nfc_hw_ecc_read_extra_oob(nand, nand->oob_poi, &cur_off,
1126 sunxi_nfc_hw_ecc_disable(nand);
1131 static int sunxi_nfc_hw_ecc_read_page_dma(struct nand_chip *nand, u8 *buf,
1136 sunxi_nfc_select_chip(nand, nand->cur_cs);
1138 nand_read_page_op(nand, page, 0, NULL, 0);
1140 ret = sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, oob_required, page,
1141 nand->ecc.steps);
1146 return sunxi_nfc_hw_ecc_read_page(nand, buf, oob_required, page);
1149 static int sunxi_nfc_hw_ecc_read_subpage(struct nand_chip *nand,
1153 struct mtd_info *mtd = nand_to_mtd(nand);
1154 struct nand_ecc_ctrl *ecc = &nand->ecc;
1158 sunxi_nfc_select_chip(nand, nand->cur_cs);
1160 nand_read_page_op(nand, page, 0, NULL, 0);
1162 sunxi_nfc_hw_ecc_enable(nand);
1169 u8 *oob = nand->oob_poi + oob_off;
1171 ret = sunxi_nfc_hw_ecc_read_chunk(nand, data, data_off,
1180 sunxi_nfc_hw_ecc_disable(nand);
1185 static int sunxi_nfc_hw_ecc_read_subpage_dma(struct nand_chip *nand,
1189 int nchunks = DIV_ROUND_UP(data_offs + readlen, nand->ecc.size);
1192 sunxi_nfc_select_chip(nand, nand->cur_cs);
1194 nand_read_page_op(nand, page, 0, NULL, 0);
1196 ret = sunxi_nfc_hw_ecc_read_chunks_dma(nand, buf, false, page, nchunks);
1201 return sunxi_nfc_hw_ecc_read_subpage(nand, data_offs, readlen,
1205 static int sunxi_nfc_hw_ecc_write_page(struct nand_chip *nand,
1209 struct mtd_info *mtd = nand_to_mtd(nand);
1210 struct nand_ecc_ctrl *ecc = &nand->ecc;
1213 sunxi_nfc_select_chip(nand, nand->cur_cs);
1215 nand_prog_page_begin_op(nand, page, 0, NULL, 0);
1217 sunxi_nfc_hw_ecc_enable(nand);
1223 const u8 *oob = nand->oob_poi + oob_off;
1225 ret = sunxi_nfc_hw_ecc_write_chunk(nand, data, data_off, oob,
1232 if (oob_required || (nand->options & NAND_NEED_SCRAMBLING))
1233 sunxi_nfc_hw_ecc_write_extra_oob(nand, nand->oob_poi,
1236 sunxi_nfc_hw_ecc_disable(nand);
1238 return nand_prog_page_end_op(nand);
1241 static int sunxi_nfc_hw_ecc_write_subpage(struct nand_chip *nand,
1246 struct mtd_info *mtd = nand_to_mtd(nand);
1247 struct nand_ecc_ctrl *ecc = &nand->ecc;
1250 sunxi_nfc_select_chip(nand, nand->cur_cs);
1252 nand_prog_page_begin_op(nand, page, 0, NULL, 0);
1254 sunxi_nfc_hw_ecc_enable(nand);
1261 const u8 *oob = nand->oob_poi + oob_off;
1263 ret = sunxi_nfc_hw_ecc_write_chunk(nand, data, data_off, oob,
1270 sunxi_nfc_hw_ecc_disable(nand);
1272 return nand_prog_page_end_op(nand);
1275 static int sunxi_nfc_hw_ecc_write_page_dma(struct nand_chip *nand,
1280 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
1281 struct nand_ecc_ctrl *ecc = &nand->ecc;
1286 sunxi_nfc_select_chip(nand, nand->cur_cs);
1298 const u8 *oob = nand->oob_poi + (i * (ecc->bytes + 4));
1300 sunxi_nfc_hw_ecc_set_prot_oob_bytes(nand, oob, i, !i, page);
1303 nand_prog_page_begin_op(nand, page, 0, NULL, 0);
1305 sunxi_nfc_hw_ecc_enable(nand);
1306 sunxi_nfc_randomizer_config(nand, page, false);
1307 sunxi_nfc_randomizer_enable(nand);
1327 sunxi_nfc_randomizer_disable(nand);
1328 sunxi_nfc_hw_ecc_disable(nand);
1335 if (oob_required || (nand->options & NAND_NEED_SCRAMBLING))
1337 sunxi_nfc_hw_ecc_write_extra_oob(nand, nand->oob_poi,
1340 return nand_prog_page_end_op(nand);
1343 return sunxi_nfc_hw_ecc_write_page(nand, buf, oob_required, page);
1346 static int sunxi_nfc_hw_ecc_read_oob(struct nand_chip *nand, int page)
1348 u8 *buf = nand_get_data_buf(nand);
1350 return nand->ecc.read_page(nand, buf, 1, page);
1353 static int sunxi_nfc_hw_ecc_write_oob(struct nand_chip *nand, int page)
1355 struct mtd_info *mtd = nand_to_mtd(nand);
1356 u8 *buf = nand_get_data_buf(nand);
1360 ret = nand->ecc.write_page(nand, buf, 1, page);
1365 return nand_prog_page_end_op(nand);
1389 static int sunxi_nfc_setup_interface(struct nand_chip *nand, int csline,
1392 struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
1393 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller);
1562 struct nand_chip *nand = mtd_to_nand(mtd);
1563 struct nand_ecc_ctrl *ecc = &nand->ecc;
1577 struct nand_chip *nand = mtd_to_nand(mtd);
1578 struct nand_ecc_ctrl *ecc = &nand->ecc;
1617 static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand,
1622 struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
1623 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
1624 struct mtd_info *mtd = nand_to_mtd(nand);
1703 nand->options |= NAND_USES_DMA;
1724 static int sunxi_nand_attach_chip(struct nand_chip *nand)
1727 nanddev_get_ecc_requirements(&nand->base);
1728 struct nand_ecc_ctrl *ecc = &nand->ecc;
1729 struct device_node *np = nand_get_flash_node(nand);
1732 if (nand->bbt_options & NAND_BBT_USE_FLASH)
1733 nand->bbt_options |= NAND_BBT_NO_OOB;
1735 if (nand->options & NAND_NEED_SCRAMBLING)
1736 nand->options |= NAND_NO_SUBPAGE_WRITE;
1738 nand->options |= NAND_SUBPAGE_READ;
1750 ret = sunxi_nand_hw_ecc_ctrl_init(nand, ecc, np);
1764 static int sunxi_nfc_exec_subop(struct nand_chip *nand,
1767 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
1860 static int sunxi_nfc_soft_waitrdy(struct nand_chip *nand,
1863 return nand_soft_waitrdy(nand,
1897 static int sunxi_nfc_exec_op(struct nand_chip *nand,
1900 struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
1904 sunxi_nfc_select_chip(nand, op->cs);
1911 return nand_op_parser_exec_op(nand, parser, op, check_only);
1930 chip = &sunxi_nand->nand;
1943 struct nand_chip *nand;
1994 nand = &sunxi_nand->nand;
1996 nand->controller = &nfc->controller;
1997 nand->controller->ops = &sunxi_nand_controller_ops;
2003 nand->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
2004 nand_set_flash_node(nand, np);
2006 mtd = nand_to_mtd(nand);
2009 ret = nand_scan(nand, nsels);
2016 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",