Lines Matching full:nfc
23 * NFC Page Data Layout:
112 * @type: NFC version
227 struct rk_nfc *nfc = nand_get_controller_data(chip); in rk_nfc_data_ptr() local
229 return nfc->page_buf + i * rk_nfc_data_len(chip); in rk_nfc_data_ptr()
234 struct rk_nfc *nfc = nand_get_controller_data(chip); in rk_nfc_oob_ptr() local
236 return nfc->page_buf + i * rk_nfc_data_len(chip) + chip->ecc.size; in rk_nfc_oob_ptr()
241 struct rk_nfc *nfc = nand_get_controller_data(chip); in rk_nfc_hw_ecc_setup() local
245 if (strength == nfc->cfg->ecc_strengths[i]) { in rk_nfc_hw_ecc_setup()
246 reg = nfc->cfg->ecc_cfgs[i]; in rk_nfc_hw_ecc_setup()
254 writel(reg, nfc->regs + nfc->cfg->bchctl_off); in rk_nfc_hw_ecc_setup()
257 nfc->cur_ecc = strength; in rk_nfc_hw_ecc_setup()
264 struct rk_nfc *nfc = nand_get_controller_data(chip); in rk_nfc_select_chip() local
270 nfc->selected_bank = -1; in rk_nfc_select_chip()
272 val = readl_relaxed(nfc->regs + NFC_FMCTL); in rk_nfc_select_chip()
274 writel(val, nfc->regs + NFC_FMCTL); in rk_nfc_select_chip()
278 nfc->selected_bank = rknand->sels[cs]; in rk_nfc_select_chip()
279 nfc->band_offset = NFC_BANK + nfc->selected_bank * NFC_BANK_STEP; in rk_nfc_select_chip()
281 val = readl_relaxed(nfc->regs + NFC_FMCTL); in rk_nfc_select_chip()
283 val |= FMCTL_CE_SEL(nfc->selected_bank); in rk_nfc_select_chip()
285 writel(val, nfc->regs + NFC_FMCTL); in rk_nfc_select_chip()
291 if (nfc->cur_timing != rknand->timing) { in rk_nfc_select_chip()
292 writel(rknand->timing, nfc->regs + NFC_FMWAIT); in rk_nfc_select_chip()
293 nfc->cur_timing = rknand->timing; in rk_nfc_select_chip()
300 if (nfc->cur_ecc != ecc->strength) in rk_nfc_select_chip()
304 static inline int rk_nfc_wait_ioready(struct rk_nfc *nfc) in rk_nfc_wait_ioready() argument
309 rc = readl_relaxed_poll_timeout(nfc->regs + NFC_FMCTL, val, in rk_nfc_wait_ioready()
315 static void rk_nfc_read_buf(struct rk_nfc *nfc, u8 *buf, int len) in rk_nfc_read_buf() argument
320 buf[i] = readb_relaxed(nfc->regs + nfc->band_offset + in rk_nfc_read_buf()
324 static void rk_nfc_write_buf(struct rk_nfc *nfc, const u8 *buf, int len) in rk_nfc_write_buf() argument
329 writeb(buf[i], nfc->regs + nfc->band_offset + BANK_DATA); in rk_nfc_write_buf()
335 struct rk_nfc *nfc = nand_get_controller_data(chip); in rk_nfc_cmd() local
337 int reg_offset = nfc->band_offset; in rk_nfc_cmd()
349 nfc->regs + reg_offset + BANK_CMD); in rk_nfc_cmd()
358 nfc->regs + reg_offset + BANK_ADDR); in rk_nfc_cmd()
368 rk_nfc_write_buf(nfc, outbuf, cnt); in rk_nfc_cmd()
371 rk_nfc_read_buf(nfc, inbuf, cnt); in rk_nfc_cmd()
376 if (rk_nfc_wait_ioready(nfc) < 0) { in rk_nfc_cmd()
378 dev_err(nfc->dev, "IO not ready\n"); in rk_nfc_cmd()
419 struct rk_nfc *nfc = nand_get_controller_data(chip); in rk_nfc_setup_interface() local
431 if (IS_ERR(nfc->nfc_clk)) in rk_nfc_setup_interface()
432 rate = clk_get_rate(nfc->ahb_clk); in rk_nfc_setup_interface()
434 rate = clk_get_rate(nfc->nfc_clk); in rk_nfc_setup_interface()
469 static void rk_nfc_xfer_start(struct rk_nfc *nfc, u8 rw, u8 n_KB, in rk_nfc_xfer_start() argument
480 if (nfc->cfg->type == NFC_V6 || nfc->cfg->type == NFC_V8) { in rk_nfc_xfer_start()
481 bch_reg = readl_relaxed(nfc->regs + nfc->cfg->bchctl_off); in rk_nfc_xfer_start()
483 (nfc->selected_bank << BCHCTL_BANK); in rk_nfc_xfer_start()
484 writel(bch_reg, nfc->regs + nfc->cfg->bchctl_off); in rk_nfc_xfer_start()
487 writel(dma_reg, nfc->regs + nfc->cfg->dma_cfg_off); in rk_nfc_xfer_start()
488 writel((u32)dma_data, nfc->regs + nfc->cfg->dma_data_buf_off); in rk_nfc_xfer_start()
489 writel((u32)dma_oob, nfc->regs + nfc->cfg->dma_oob_buf_off); in rk_nfc_xfer_start()
490 writel(fl_reg, nfc->regs + nfc->cfg->flctl_off); in rk_nfc_xfer_start()
492 writel(fl_reg, nfc->regs + nfc->cfg->flctl_off); in rk_nfc_xfer_start()
495 static int rk_nfc_wait_for_xfer_done(struct rk_nfc *nfc) in rk_nfc_wait_for_xfer_done() argument
500 ptr = nfc->regs + nfc->cfg->flctl_off; in rk_nfc_wait_for_xfer_done()
511 struct rk_nfc *nfc = nand_get_controller_data(chip); in rk_nfc_write_page_raw() local
528 memset(nfc->page_buf, 0xff, mtd->writesize + mtd->oobsize); in rk_nfc_write_page_raw()
531 /* Copy data to the NFC buffer. */ in rk_nfc_write_page_raw()
549 * The OOB data layout on the NFC is: in rk_nfc_write_page_raw()
577 /* Copy ECC data to the NFC buffer. */ in rk_nfc_write_page_raw()
584 rk_nfc_write_buf(nfc, buf, mtd->writesize + mtd->oobsize); in rk_nfc_write_page_raw()
592 struct rk_nfc *nfc = nand_get_controller_data(chip); in rk_nfc_write_page_hwecc() local
606 memcpy(nfc->page_buf, buf, mtd->writesize); in rk_nfc_write_page_hwecc()
608 memset(nfc->page_buf, 0xFF, mtd->writesize); in rk_nfc_write_page_hwecc()
648 if (nfc->cfg->type == NFC_V9) in rk_nfc_write_page_hwecc()
649 nfc->oob_buf[i] = reg; in rk_nfc_write_page_hwecc()
651 nfc->oob_buf[i * (oob_step / 4)] = reg; in rk_nfc_write_page_hwecc()
654 dma_data = dma_map_single(nfc->dev, (void *)nfc->page_buf, in rk_nfc_write_page_hwecc()
656 dma_oob = dma_map_single(nfc->dev, nfc->oob_buf, in rk_nfc_write_page_hwecc()
660 reinit_completion(&nfc->done); in rk_nfc_write_page_hwecc()
661 writel(INT_DMA, nfc->regs + nfc->cfg->int_en_off); in rk_nfc_write_page_hwecc()
663 rk_nfc_xfer_start(nfc, NFC_WRITE, ecc->steps, dma_data, in rk_nfc_write_page_hwecc()
665 ret = wait_for_completion_timeout(&nfc->done, in rk_nfc_write_page_hwecc()
668 dev_warn(nfc->dev, "write: wait dma done timeout.\n"); in rk_nfc_write_page_hwecc()
671 * needs to check the NFC`s status register to see if the data in rk_nfc_write_page_hwecc()
674 ret = rk_nfc_wait_for_xfer_done(nfc); in rk_nfc_write_page_hwecc()
676 dma_unmap_single(nfc->dev, dma_data, mtd->writesize, in rk_nfc_write_page_hwecc()
678 dma_unmap_single(nfc->dev, dma_oob, ecc->steps * oob_step, in rk_nfc_write_page_hwecc()
685 dev_err(nfc->dev, "write: wait transfer done timeout.\n"); in rk_nfc_write_page_hwecc()
701 struct rk_nfc *nfc = nand_get_controller_data(chip); in rk_nfc_read_page_raw() local
718 rk_nfc_read_buf(nfc, nfc->page_buf, mtd->writesize + mtd->oobsize); in rk_nfc_read_page_raw()
736 /* Copy ECC data from the NFC buffer. */ in rk_nfc_read_page_raw()
741 /* Copy data from the NFC buffer. */ in rk_nfc_read_page_raw()
755 struct rk_nfc *nfc = nand_get_controller_data(chip); in rk_nfc_read_page_hwecc() local
769 dma_data = dma_map_single(nfc->dev, nfc->page_buf, in rk_nfc_read_page_hwecc()
772 dma_oob = dma_map_single(nfc->dev, nfc->oob_buf, in rk_nfc_read_page_hwecc()
788 reinit_completion(&nfc->done); in rk_nfc_read_page_hwecc()
789 writel(INT_DMA, nfc->regs + nfc->cfg->int_en_off); in rk_nfc_read_page_hwecc()
790 rk_nfc_xfer_start(nfc, NFC_READ, ecc->steps, dma_data, in rk_nfc_read_page_hwecc()
792 ret = wait_for_completion_timeout(&nfc->done, in rk_nfc_read_page_hwecc()
795 dev_warn(nfc->dev, "read: wait dma done timeout.\n"); in rk_nfc_read_page_hwecc()
798 * needs to check the NFC`s status register to see if the data in rk_nfc_read_page_hwecc()
801 ret = rk_nfc_wait_for_xfer_done(nfc); in rk_nfc_read_page_hwecc()
803 dma_unmap_single(nfc->dev, dma_data, mtd->writesize, in rk_nfc_read_page_hwecc()
805 dma_unmap_single(nfc->dev, dma_oob, ecc->steps * oob_step, in rk_nfc_read_page_hwecc()
810 dev_err(nfc->dev, "read: wait transfer done timeout.\n"); in rk_nfc_read_page_hwecc()
816 if (nfc->cfg->type == NFC_V9) in rk_nfc_read_page_hwecc()
817 tmp = nfc->oob_buf[i]; in rk_nfc_read_page_hwecc()
819 tmp = nfc->oob_buf[i * (oob_step / 4)]; in rk_nfc_read_page_hwecc()
827 bch_st = readl_relaxed(nfc->regs + in rk_nfc_read_page_hwecc()
828 nfc->cfg->bch_st_off + i * 4); in rk_nfc_read_page_hwecc()
829 if (bch_st & BIT(nfc->cfg->ecc0.err_flag_bit) || in rk_nfc_read_page_hwecc()
830 bch_st & BIT(nfc->cfg->ecc1.err_flag_bit)) { in rk_nfc_read_page_hwecc()
834 cnt = ECC_ERR_CNT(bch_st, nfc->cfg->ecc0); in rk_nfc_read_page_hwecc()
838 cnt = ECC_ERR_CNT(bch_st, nfc->cfg->ecc1); in rk_nfc_read_page_hwecc()
845 memcpy(buf, nfc->page_buf, mtd->writesize); in rk_nfc_read_page_hwecc()
855 dev_err(nfc->dev, "read page: %x ecc error!\n", page); in rk_nfc_read_page_hwecc()
867 static inline void rk_nfc_hw_init(struct rk_nfc *nfc) in rk_nfc_hw_init() argument
870 writel(FMCTL_WP, nfc->regs + NFC_FMCTL); in rk_nfc_hw_init()
871 /* Config default timing 40ns at 150 Mhz NFC clock. */ in rk_nfc_hw_init()
872 writel(0x1081, nfc->regs + NFC_FMWAIT); in rk_nfc_hw_init()
873 nfc->cur_timing = 0x1081; in rk_nfc_hw_init()
875 writel(0, nfc->regs + nfc->cfg->randmz_off); in rk_nfc_hw_init()
876 writel(0, nfc->regs + nfc->cfg->dma_cfg_off); in rk_nfc_hw_init()
877 writel(FLCTL_RST, nfc->regs + nfc->cfg->flctl_off); in rk_nfc_hw_init()
882 struct rk_nfc *nfc = id; in rk_nfc_irq() local
885 sta = readl_relaxed(nfc->regs + nfc->cfg->int_st_off); in rk_nfc_irq()
886 ien = readl_relaxed(nfc->regs + nfc->cfg->int_en_off); in rk_nfc_irq()
891 writel(sta, nfc->regs + nfc->cfg->int_clr_off); in rk_nfc_irq()
892 writel(~sta & ien, nfc->regs + nfc->cfg->int_en_off); in rk_nfc_irq()
894 complete(&nfc->done); in rk_nfc_irq()
899 static int rk_nfc_enable_clks(struct device *dev, struct rk_nfc *nfc) in rk_nfc_enable_clks() argument
903 if (!IS_ERR(nfc->nfc_clk)) { in rk_nfc_enable_clks()
904 ret = clk_prepare_enable(nfc->nfc_clk); in rk_nfc_enable_clks()
906 dev_err(dev, "failed to enable NFC clk\n"); in rk_nfc_enable_clks()
911 ret = clk_prepare_enable(nfc->ahb_clk); in rk_nfc_enable_clks()
914 clk_disable_unprepare(nfc->nfc_clk); in rk_nfc_enable_clks()
921 static void rk_nfc_disable_clks(struct rk_nfc *nfc) in rk_nfc_disable_clks() argument
923 clk_disable_unprepare(nfc->nfc_clk); in rk_nfc_disable_clks()
924 clk_disable_unprepare(nfc->ahb_clk); in rk_nfc_disable_clks()
937 * The beginning of the OOB area stores the reserved data for the NFC, in rk_nfc_ooblayout_free()
969 struct rk_nfc *nfc = nand_get_controller_data(chip); in rk_nfc_ecc_init() local
971 const u8 *strengths = nfc->cfg->ecc_strengths; in rk_nfc_ecc_init()
975 nfc_max_strength = nfc->cfg->ecc_strengths[0]; in rk_nfc_ecc_init()
997 dev_err(nfc->dev, "unsupported ECC strength\n"); in rk_nfc_ecc_init()
1013 struct rk_nfc *nfc = nand_get_controller_data(chip); in rk_nfc_attach_chip() local
1043 if (nfc->page_buf && new_page_len > nfc->page_buf_size) { in rk_nfc_attach_chip()
1044 buf = krealloc(nfc->page_buf, new_page_len, in rk_nfc_attach_chip()
1048 nfc->page_buf = buf; in rk_nfc_attach_chip()
1049 nfc->page_buf_size = new_page_len; in rk_nfc_attach_chip()
1053 if (nfc->oob_buf && new_oob_len > nfc->oob_buf_size) { in rk_nfc_attach_chip()
1054 buf = krealloc(nfc->oob_buf, new_oob_len, in rk_nfc_attach_chip()
1057 kfree(nfc->page_buf); in rk_nfc_attach_chip()
1058 nfc->page_buf = NULL; in rk_nfc_attach_chip()
1061 nfc->oob_buf = buf; in rk_nfc_attach_chip()
1062 nfc->oob_buf_size = new_oob_len; in rk_nfc_attach_chip()
1065 if (!nfc->page_buf) { in rk_nfc_attach_chip()
1066 nfc->page_buf = kzalloc(new_page_len, GFP_KERNEL | GFP_DMA); in rk_nfc_attach_chip()
1067 if (!nfc->page_buf) in rk_nfc_attach_chip()
1069 nfc->page_buf_size = new_page_len; in rk_nfc_attach_chip()
1072 if (!nfc->oob_buf) { in rk_nfc_attach_chip()
1073 nfc->oob_buf = kzalloc(new_oob_len, GFP_KERNEL | GFP_DMA); in rk_nfc_attach_chip()
1074 if (!nfc->oob_buf) { in rk_nfc_attach_chip()
1075 kfree(nfc->page_buf); in rk_nfc_attach_chip()
1076 nfc->page_buf = NULL; in rk_nfc_attach_chip()
1079 nfc->oob_buf_size = new_oob_len; in rk_nfc_attach_chip()
1099 static int rk_nfc_nand_chip_init(struct device *dev, struct rk_nfc *nfc, in rk_nfc_nand_chip_init() argument
1136 if (test_and_set_bit(tmp, &nfc->assigned_cs)) { in rk_nfc_nand_chip_init()
1145 chip->controller = &nfc->controller; in rk_nfc_nand_chip_init()
1149 nand_set_controller_data(chip, nfc); in rk_nfc_nand_chip_init()
1162 dev_err(nfc->dev, "NAND label property is mandatory\n"); in rk_nfc_nand_chip_init()
1167 rk_nfc_hw_init(nfc); in rk_nfc_nand_chip_init()
1188 list_add_tail(&rknand->node, &nfc->chips); in rk_nfc_nand_chip_init()
1193 static void rk_nfc_chips_cleanup(struct rk_nfc *nfc) in rk_nfc_chips_cleanup() argument
1199 list_for_each_entry_safe(rknand, tmp, &nfc->chips, node) { in rk_nfc_chips_cleanup()
1208 static int rk_nfc_nand_chips_init(struct device *dev, struct rk_nfc *nfc) in rk_nfc_nand_chips_init() argument
1215 dev_err(nfc->dev, "incorrect number of NAND chips (%d)\n", in rk_nfc_nand_chips_init()
1221 ret = rk_nfc_nand_chip_init(dev, nfc, nand_np); in rk_nfc_nand_chips_init()
1224 rk_nfc_chips_cleanup(nfc); in rk_nfc_nand_chips_init()
1345 .compatible = "rockchip,px30-nfc",
1349 .compatible = "rockchip,rk2928-nfc",
1353 .compatible = "rockchip,rv1108-nfc",
1363 struct rk_nfc *nfc; in rk_nfc_probe() local
1366 nfc = devm_kzalloc(dev, sizeof(*nfc), GFP_KERNEL); in rk_nfc_probe()
1367 if (!nfc) in rk_nfc_probe()
1370 nand_controller_init(&nfc->controller); in rk_nfc_probe()
1371 INIT_LIST_HEAD(&nfc->chips); in rk_nfc_probe()
1372 nfc->controller.ops = &rk_nfc_controller_ops; in rk_nfc_probe()
1374 nfc->cfg = of_device_get_match_data(dev); in rk_nfc_probe()
1375 nfc->dev = dev; in rk_nfc_probe()
1377 init_completion(&nfc->done); in rk_nfc_probe()
1379 nfc->regs = devm_platform_ioremap_resource(pdev, 0); in rk_nfc_probe()
1380 if (IS_ERR(nfc->regs)) { in rk_nfc_probe()
1381 ret = PTR_ERR(nfc->regs); in rk_nfc_probe()
1385 nfc->nfc_clk = devm_clk_get(dev, "nfc"); in rk_nfc_probe()
1386 if (IS_ERR(nfc->nfc_clk)) { in rk_nfc_probe()
1387 dev_dbg(dev, "no NFC clk\n"); in rk_nfc_probe()
1388 /* Some earlier models, such as rk3066, have no NFC clk. */ in rk_nfc_probe()
1391 nfc->ahb_clk = devm_clk_get(dev, "ahb"); in rk_nfc_probe()
1392 if (IS_ERR(nfc->ahb_clk)) { in rk_nfc_probe()
1394 ret = PTR_ERR(nfc->ahb_clk); in rk_nfc_probe()
1398 ret = rk_nfc_enable_clks(dev, nfc); in rk_nfc_probe()
1408 writel(0, nfc->regs + nfc->cfg->int_en_off); in rk_nfc_probe()
1409 ret = devm_request_irq(dev, irq, rk_nfc_irq, 0x0, "rk-nand", nfc); in rk_nfc_probe()
1411 dev_err(dev, "failed to request NFC irq\n"); in rk_nfc_probe()
1415 platform_set_drvdata(pdev, nfc); in rk_nfc_probe()
1417 ret = rk_nfc_nand_chips_init(dev, nfc); in rk_nfc_probe()
1425 rk_nfc_disable_clks(nfc); in rk_nfc_probe()
1432 struct rk_nfc *nfc = platform_get_drvdata(pdev); in rk_nfc_remove() local
1434 kfree(nfc->page_buf); in rk_nfc_remove()
1435 kfree(nfc->oob_buf); in rk_nfc_remove()
1436 rk_nfc_chips_cleanup(nfc); in rk_nfc_remove()
1437 rk_nfc_disable_clks(nfc); in rk_nfc_remove()
1444 struct rk_nfc *nfc = dev_get_drvdata(dev); in rk_nfc_suspend() local
1446 rk_nfc_disable_clks(nfc); in rk_nfc_suspend()
1453 struct rk_nfc *nfc = dev_get_drvdata(dev); in rk_nfc_resume() local
1459 ret = rk_nfc_enable_clks(dev, nfc); in rk_nfc_resume()
1464 list_for_each_entry(rknand, &nfc->chips, node) { in rk_nfc_resume()
1481 .name = "rockchip-nfc",