Lines Matching full:nfc
53 /* Addresses for NFC MAIN RAM BUFFER areas */
76 /* NFC ECC mode define */
174 static inline u32 vf610_nfc_read(struct vf610_nfc *nfc, uint reg) in vf610_nfc_read() argument
176 return readl(nfc->regs + reg); in vf610_nfc_read()
179 static inline void vf610_nfc_write(struct vf610_nfc *nfc, uint reg, u32 val) in vf610_nfc_write() argument
181 writel(val, nfc->regs + reg); in vf610_nfc_write()
184 static inline void vf610_nfc_set(struct vf610_nfc *nfc, uint reg, u32 bits) in vf610_nfc_set() argument
186 vf610_nfc_write(nfc, reg, vf610_nfc_read(nfc, reg) | bits); in vf610_nfc_set()
189 static inline void vf610_nfc_clear(struct vf610_nfc *nfc, uint reg, u32 bits) in vf610_nfc_clear() argument
191 vf610_nfc_write(nfc, reg, vf610_nfc_read(nfc, reg) & ~bits); in vf610_nfc_clear()
194 static inline void vf610_nfc_set_field(struct vf610_nfc *nfc, u32 reg, in vf610_nfc_set_field() argument
197 vf610_nfc_write(nfc, reg, in vf610_nfc_set_field()
198 (vf610_nfc_read(nfc, reg) & (~mask)) | val << shift); in vf610_nfc_set_field()
282 static inline void vf610_nfc_clear_status(struct vf610_nfc *nfc) in vf610_nfc_clear_status() argument
284 u32 tmp = vf610_nfc_read(nfc, NFC_IRQ_STATUS); in vf610_nfc_clear_status()
287 vf610_nfc_write(nfc, NFC_IRQ_STATUS, tmp); in vf610_nfc_clear_status()
290 static void vf610_nfc_done(struct vf610_nfc *nfc) in vf610_nfc_done() argument
301 vf610_nfc_set(nfc, NFC_IRQ_STATUS, IDLE_EN_BIT); in vf610_nfc_done()
302 vf610_nfc_set(nfc, NFC_FLASH_CMD2, START_BIT); in vf610_nfc_done()
304 if (!wait_for_completion_timeout(&nfc->cmd_done, timeout)) in vf610_nfc_done()
305 dev_warn(nfc->dev, "Timeout while waiting for BUSY.\n"); in vf610_nfc_done()
307 vf610_nfc_clear_status(nfc); in vf610_nfc_done()
312 struct vf610_nfc *nfc = data; in vf610_nfc_irq() local
314 vf610_nfc_clear(nfc, NFC_IRQ_STATUS, IDLE_EN_BIT); in vf610_nfc_irq()
315 complete(&nfc->cmd_done); in vf610_nfc_irq()
320 static inline void vf610_nfc_ecc_mode(struct vf610_nfc *nfc, int ecc_mode) in vf610_nfc_ecc_mode() argument
322 vf610_nfc_set_field(nfc, NFC_FLASH_CONFIG, in vf610_nfc_ecc_mode()
327 static inline void vf610_nfc_run(struct vf610_nfc *nfc, u32 col, u32 row, in vf610_nfc_run() argument
330 vf610_nfc_set_field(nfc, NFC_COL_ADDR, COL_ADDR_MASK, in vf610_nfc_run()
333 vf610_nfc_set_field(nfc, NFC_ROW_ADDR, ROW_ADDR_MASK, in vf610_nfc_run()
336 vf610_nfc_write(nfc, NFC_SECTOR_SIZE, trfr_sz); in vf610_nfc_run()
337 vf610_nfc_write(nfc, NFC_FLASH_CMD1, cmd1); in vf610_nfc_run()
338 vf610_nfc_write(nfc, NFC_FLASH_CMD2, cmd2); in vf610_nfc_run()
340 dev_dbg(nfc->dev, in vf610_nfc_run()
344 vf610_nfc_done(nfc); in vf610_nfc_run()
362 struct vf610_nfc *nfc = chip_to_nfc(chip); in vf610_nfc_cmd() local
410 vf610_nfc_wr_to_sram(nfc->regs + NFC_MAIN_AREA(0) + offset, in vf610_nfc_cmd()
412 trfr_sz, !nfc->data_access); in vf610_nfc_cmd()
440 vf610_nfc_clear(nfc, NFC_FLASH_CONFIG, CONFIG_16BIT); in vf610_nfc_cmd()
444 vf610_nfc_run(nfc, col, row, cmd1, cmd2, trfr_sz); in vf610_nfc_cmd()
452 nfc->regs + NFC_MAIN_AREA(0) + offset, in vf610_nfc_cmd()
453 trfr_sz, !nfc->data_access); in vf610_nfc_cmd()
457 vf610_nfc_set(nfc, NFC_FLASH_CONFIG, CONFIG_16BIT); in vf610_nfc_cmd()
482 struct vf610_nfc *nfc = chip_to_nfc(chip); in vf610_nfc_select_target() local
486 if (nfc->variant != NFC_VFC610) in vf610_nfc_select_target()
489 tmp = vf610_nfc_read(nfc, NFC_ROW_ADDR); in vf610_nfc_select_target()
494 vf610_nfc_write(nfc, NFC_ROW_ADDR, tmp); in vf610_nfc_select_target()
511 struct vf610_nfc *nfc = chip_to_nfc(chip); in vf610_nfc_correct_data() local
516 int flips_threshold = nfc->chip.ecc.strength / 2; in vf610_nfc_correct_data()
518 ecc_status = vf610_nfc_read(nfc, ecc_status_off) & 0xff; in vf610_nfc_correct_data()
524 nfc->data_access = true; in vf610_nfc_correct_data()
525 nand_read_oob_op(&nfc->chip, page, 0, oob, mtd->oobsize); in vf610_nfc_correct_data()
526 nfc->data_access = false; in vf610_nfc_correct_data()
532 return nand_check_erased_ecc_chunk(dat, nfc->chip.ecc.size, oob, in vf610_nfc_correct_data()
552 struct vf610_nfc *nfc = chip_to_nfc(chip); in vf610_nfc_read_page() local
570 vf610_nfc_ecc_mode(nfc, nfc->ecc_mode); in vf610_nfc_read_page()
571 vf610_nfc_run(nfc, 0, row, cmd1, cmd2, trfr_sz); in vf610_nfc_read_page()
572 vf610_nfc_ecc_mode(nfc, ECC_BYPASS); in vf610_nfc_read_page()
578 vf610_nfc_rd_from_sram(buf, nfc->regs + NFC_MAIN_AREA(0), in vf610_nfc_read_page()
582 nfc->regs + NFC_MAIN_AREA(0) + in vf610_nfc_read_page()
600 struct vf610_nfc *nfc = chip_to_nfc(chip); in vf610_nfc_write_page() local
621 vf610_nfc_wr_to_sram(nfc->regs + NFC_MAIN_AREA(0), buf, in vf610_nfc_write_page()
627 vf610_nfc_ecc_mode(nfc, nfc->ecc_mode); in vf610_nfc_write_page()
628 vf610_nfc_run(nfc, 0, row, cmd1, cmd2, trfr_sz); in vf610_nfc_write_page()
629 vf610_nfc_ecc_mode(nfc, ECC_BYPASS); in vf610_nfc_write_page()
644 struct vf610_nfc *nfc = chip_to_nfc(chip); in vf610_nfc_read_page_raw() local
647 nfc->data_access = true; in vf610_nfc_read_page_raw()
649 nfc->data_access = false; in vf610_nfc_read_page_raw()
657 struct vf610_nfc *nfc = chip_to_nfc(chip); in vf610_nfc_write_page_raw() local
661 nfc->data_access = true; in vf610_nfc_write_page_raw()
666 nfc->data_access = false; in vf610_nfc_write_page_raw()
676 struct vf610_nfc *nfc = chip_to_nfc(chip); in vf610_nfc_read_oob() local
679 nfc->data_access = true; in vf610_nfc_read_oob()
681 nfc->data_access = false; in vf610_nfc_read_oob()
689 struct vf610_nfc *nfc = chip_to_nfc(chip); in vf610_nfc_write_oob() local
692 nfc->data_access = true; in vf610_nfc_write_oob()
695 nfc->data_access = false; in vf610_nfc_write_oob()
704 { .compatible = "fsl,vf610-nfc", .data = (void *)NFC_VFC610 },
709 static void vf610_nfc_preinit_controller(struct vf610_nfc *nfc) in vf610_nfc_preinit_controller() argument
711 vf610_nfc_clear(nfc, NFC_FLASH_CONFIG, CONFIG_16BIT); in vf610_nfc_preinit_controller()
712 vf610_nfc_clear(nfc, NFC_FLASH_CONFIG, CONFIG_ADDR_AUTO_INCR_BIT); in vf610_nfc_preinit_controller()
713 vf610_nfc_clear(nfc, NFC_FLASH_CONFIG, CONFIG_BUFNO_AUTO_INCR_BIT); in vf610_nfc_preinit_controller()
714 vf610_nfc_clear(nfc, NFC_FLASH_CONFIG, CONFIG_BOOT_MODE_BIT); in vf610_nfc_preinit_controller()
715 vf610_nfc_clear(nfc, NFC_FLASH_CONFIG, CONFIG_DMA_REQ_BIT); in vf610_nfc_preinit_controller()
716 vf610_nfc_set(nfc, NFC_FLASH_CONFIG, CONFIG_FAST_FLASH_BIT); in vf610_nfc_preinit_controller()
717 vf610_nfc_ecc_mode(nfc, ECC_BYPASS); in vf610_nfc_preinit_controller()
720 vf610_nfc_set_field(nfc, NFC_FLASH_CONFIG, CONFIG_PAGE_CNT_MASK, in vf610_nfc_preinit_controller()
724 static void vf610_nfc_init_controller(struct vf610_nfc *nfc) in vf610_nfc_init_controller() argument
726 if (nfc->chip.options & NAND_BUSWIDTH_16) in vf610_nfc_init_controller()
727 vf610_nfc_set(nfc, NFC_FLASH_CONFIG, CONFIG_16BIT); in vf610_nfc_init_controller()
729 vf610_nfc_clear(nfc, NFC_FLASH_CONFIG, CONFIG_16BIT); in vf610_nfc_init_controller()
731 if (nfc->chip.ecc.engine_type == NAND_ECC_ENGINE_TYPE_ON_HOST) { in vf610_nfc_init_controller()
733 vf610_nfc_set_field(nfc, NFC_FLASH_CONFIG, in vf610_nfc_init_controller()
739 vf610_nfc_set(nfc, NFC_FLASH_CONFIG, CONFIG_ECC_SRAM_REQ_BIT); in vf610_nfc_init_controller()
746 struct vf610_nfc *nfc = chip_to_nfc(chip); in vf610_nfc_attach_chip() local
748 vf610_nfc_init_controller(nfc); in vf610_nfc_attach_chip()
756 dev_err(nfc->dev, "Unsupported flash page size\n"); in vf610_nfc_attach_chip()
764 dev_err(nfc->dev, "Unsupported flash with hwecc\n"); in vf610_nfc_attach_chip()
769 dev_err(nfc->dev, "Step size needs to be page size\n"); in vf610_nfc_attach_chip()
780 nfc->ecc_mode = ECC_60_BYTE; in vf610_nfc_attach_chip()
783 nfc->ecc_mode = ECC_45_BYTE; in vf610_nfc_attach_chip()
786 dev_err(nfc->dev, "Unsupported ECC strength\n"); in vf610_nfc_attach_chip()
810 struct vf610_nfc *nfc; in vf610_nfc_probe() local
817 nfc = devm_kzalloc(&pdev->dev, sizeof(*nfc), GFP_KERNEL); in vf610_nfc_probe()
818 if (!nfc) in vf610_nfc_probe()
821 nfc->dev = &pdev->dev; in vf610_nfc_probe()
822 chip = &nfc->chip; in vf610_nfc_probe()
826 mtd->dev.parent = nfc->dev; in vf610_nfc_probe()
833 nfc->regs = devm_platform_ioremap_resource(pdev, 0); in vf610_nfc_probe()
834 if (IS_ERR(nfc->regs)) in vf610_nfc_probe()
835 return PTR_ERR(nfc->regs); in vf610_nfc_probe()
837 nfc->clk = devm_clk_get_enabled(&pdev->dev, NULL); in vf610_nfc_probe()
838 if (IS_ERR(nfc->clk)) { in vf610_nfc_probe()
839 dev_err(nfc->dev, "Unable to get and enable clock!\n"); in vf610_nfc_probe()
840 return PTR_ERR(nfc->clk); in vf610_nfc_probe()
843 nfc->variant = (enum vf610_nfc_variant)device_get_match_data(&pdev->dev); in vf610_nfc_probe()
844 if (!nfc->variant) in vf610_nfc_probe()
847 for_each_available_child_of_node(nfc->dev->of_node, child) { in vf610_nfc_probe()
848 if (of_device_is_compatible(child, "fsl,vf610-nfc-nandcs")) { in vf610_nfc_probe()
851 dev_err(nfc->dev, in vf610_nfc_probe()
862 dev_err(nfc->dev, "NAND chip sub-node missing!\n"); in vf610_nfc_probe()
868 init_completion(&nfc->cmd_done); in vf610_nfc_probe()
870 err = devm_request_irq(nfc->dev, irq, vf610_nfc_irq, 0, DRV_NAME, nfc); in vf610_nfc_probe()
872 dev_err(nfc->dev, "Error requesting IRQ!\n"); in vf610_nfc_probe()
876 vf610_nfc_preinit_controller(nfc); in vf610_nfc_probe()
878 nand_controller_init(&nfc->base); in vf610_nfc_probe()
879 nfc->base.ops = &vf610_nfc_controller_ops; in vf610_nfc_probe()
880 chip->controller = &nfc->base; in vf610_nfc_probe()
887 platform_set_drvdata(pdev, nfc); in vf610_nfc_probe()
902 struct vf610_nfc *nfc = platform_get_drvdata(pdev); in vf610_nfc_remove() local
903 struct nand_chip *chip = &nfc->chip; in vf610_nfc_remove()
914 struct vf610_nfc *nfc = dev_get_drvdata(dev); in vf610_nfc_suspend() local
916 clk_disable_unprepare(nfc->clk); in vf610_nfc_suspend()
922 struct vf610_nfc *nfc = dev_get_drvdata(dev); in vf610_nfc_resume() local
925 err = clk_prepare_enable(nfc->clk); in vf610_nfc_resume()
929 vf610_nfc_preinit_controller(nfc); in vf610_nfc_resume()
930 vf610_nfc_init_controller(nfc); in vf610_nfc_resume()
950 MODULE_DESCRIPTION("Freescale VF610/MPC5125 NFC MTD NAND driver");