Lines Matching full:nfc
52 /* Addresses for NFC MAIN RAM BUFFER areas */
75 /* NFC ECC mode define */
173 static inline u32 vf610_nfc_read(struct vf610_nfc *nfc, uint reg) in vf610_nfc_read() argument
175 return readl(nfc->regs + reg); in vf610_nfc_read()
178 static inline void vf610_nfc_write(struct vf610_nfc *nfc, uint reg, u32 val) in vf610_nfc_write() argument
180 writel(val, nfc->regs + reg); in vf610_nfc_write()
183 static inline void vf610_nfc_set(struct vf610_nfc *nfc, uint reg, u32 bits) in vf610_nfc_set() argument
185 vf610_nfc_write(nfc, reg, vf610_nfc_read(nfc, reg) | bits); in vf610_nfc_set()
188 static inline void vf610_nfc_clear(struct vf610_nfc *nfc, uint reg, u32 bits) in vf610_nfc_clear() argument
190 vf610_nfc_write(nfc, reg, vf610_nfc_read(nfc, reg) & ~bits); in vf610_nfc_clear()
193 static inline void vf610_nfc_set_field(struct vf610_nfc *nfc, u32 reg, in vf610_nfc_set_field() argument
196 vf610_nfc_write(nfc, reg, in vf610_nfc_set_field()
197 (vf610_nfc_read(nfc, reg) & (~mask)) | val << shift); in vf610_nfc_set_field()
281 static inline void vf610_nfc_clear_status(struct vf610_nfc *nfc) in vf610_nfc_clear_status() argument
283 u32 tmp = vf610_nfc_read(nfc, NFC_IRQ_STATUS); in vf610_nfc_clear_status()
286 vf610_nfc_write(nfc, NFC_IRQ_STATUS, tmp); in vf610_nfc_clear_status()
289 static void vf610_nfc_done(struct vf610_nfc *nfc) in vf610_nfc_done() argument
300 vf610_nfc_set(nfc, NFC_IRQ_STATUS, IDLE_EN_BIT); in vf610_nfc_done()
301 vf610_nfc_set(nfc, NFC_FLASH_CMD2, START_BIT); in vf610_nfc_done()
303 if (!wait_for_completion_timeout(&nfc->cmd_done, timeout)) in vf610_nfc_done()
304 dev_warn(nfc->dev, "Timeout while waiting for BUSY.\n"); in vf610_nfc_done()
306 vf610_nfc_clear_status(nfc); in vf610_nfc_done()
311 struct vf610_nfc *nfc = data; in vf610_nfc_irq() local
313 vf610_nfc_clear(nfc, NFC_IRQ_STATUS, IDLE_EN_BIT); in vf610_nfc_irq()
314 complete(&nfc->cmd_done); in vf610_nfc_irq()
319 static inline void vf610_nfc_ecc_mode(struct vf610_nfc *nfc, int ecc_mode) in vf610_nfc_ecc_mode() argument
321 vf610_nfc_set_field(nfc, NFC_FLASH_CONFIG, in vf610_nfc_ecc_mode()
326 static inline void vf610_nfc_run(struct vf610_nfc *nfc, u32 col, u32 row, in vf610_nfc_run() argument
329 vf610_nfc_set_field(nfc, NFC_COL_ADDR, COL_ADDR_MASK, in vf610_nfc_run()
332 vf610_nfc_set_field(nfc, NFC_ROW_ADDR, ROW_ADDR_MASK, in vf610_nfc_run()
335 vf610_nfc_write(nfc, NFC_SECTOR_SIZE, trfr_sz); in vf610_nfc_run()
336 vf610_nfc_write(nfc, NFC_FLASH_CMD1, cmd1); in vf610_nfc_run()
337 vf610_nfc_write(nfc, NFC_FLASH_CMD2, cmd2); in vf610_nfc_run()
339 dev_dbg(nfc->dev, in vf610_nfc_run()
343 vf610_nfc_done(nfc); in vf610_nfc_run()
361 struct vf610_nfc *nfc = chip_to_nfc(chip); in vf610_nfc_cmd() local
409 vf610_nfc_wr_to_sram(nfc->regs + NFC_MAIN_AREA(0) + offset, in vf610_nfc_cmd()
411 trfr_sz, !nfc->data_access); in vf610_nfc_cmd()
439 vf610_nfc_clear(nfc, NFC_FLASH_CONFIG, CONFIG_16BIT); in vf610_nfc_cmd()
443 vf610_nfc_run(nfc, col, row, cmd1, cmd2, trfr_sz); in vf610_nfc_cmd()
451 nfc->regs + NFC_MAIN_AREA(0) + offset, in vf610_nfc_cmd()
452 trfr_sz, !nfc->data_access); in vf610_nfc_cmd()
456 vf610_nfc_set(nfc, NFC_FLASH_CONFIG, CONFIG_16BIT); in vf610_nfc_cmd()
481 struct vf610_nfc *nfc = chip_to_nfc(chip); in vf610_nfc_select_target() local
485 if (nfc->variant != NFC_VFC610) in vf610_nfc_select_target()
488 tmp = vf610_nfc_read(nfc, NFC_ROW_ADDR); in vf610_nfc_select_target()
493 vf610_nfc_write(nfc, NFC_ROW_ADDR, tmp); in vf610_nfc_select_target()
510 struct vf610_nfc *nfc = chip_to_nfc(chip); in vf610_nfc_correct_data() local
515 int flips_threshold = nfc->chip.ecc.strength / 2; in vf610_nfc_correct_data()
517 ecc_status = vf610_nfc_read(nfc, ecc_status_off) & 0xff; in vf610_nfc_correct_data()
523 nfc->data_access = true; in vf610_nfc_correct_data()
524 nand_read_oob_op(&nfc->chip, page, 0, oob, mtd->oobsize); in vf610_nfc_correct_data()
525 nfc->data_access = false; in vf610_nfc_correct_data()
531 return nand_check_erased_ecc_chunk(dat, nfc->chip.ecc.size, oob, in vf610_nfc_correct_data()
551 struct vf610_nfc *nfc = chip_to_nfc(chip); in vf610_nfc_read_page() local
569 vf610_nfc_ecc_mode(nfc, nfc->ecc_mode); in vf610_nfc_read_page()
570 vf610_nfc_run(nfc, 0, row, cmd1, cmd2, trfr_sz); in vf610_nfc_read_page()
571 vf610_nfc_ecc_mode(nfc, ECC_BYPASS); in vf610_nfc_read_page()
577 vf610_nfc_rd_from_sram(buf, nfc->regs + NFC_MAIN_AREA(0), in vf610_nfc_read_page()
581 nfc->regs + NFC_MAIN_AREA(0) + in vf610_nfc_read_page()
599 struct vf610_nfc *nfc = chip_to_nfc(chip); in vf610_nfc_write_page() local
620 vf610_nfc_wr_to_sram(nfc->regs + NFC_MAIN_AREA(0), buf, in vf610_nfc_write_page()
626 vf610_nfc_ecc_mode(nfc, nfc->ecc_mode); in vf610_nfc_write_page()
627 vf610_nfc_run(nfc, 0, row, cmd1, cmd2, trfr_sz); in vf610_nfc_write_page()
628 vf610_nfc_ecc_mode(nfc, ECC_BYPASS); in vf610_nfc_write_page()
643 struct vf610_nfc *nfc = chip_to_nfc(chip); in vf610_nfc_read_page_raw() local
646 nfc->data_access = true; in vf610_nfc_read_page_raw()
648 nfc->data_access = false; in vf610_nfc_read_page_raw()
656 struct vf610_nfc *nfc = chip_to_nfc(chip); in vf610_nfc_write_page_raw() local
660 nfc->data_access = true; in vf610_nfc_write_page_raw()
665 nfc->data_access = false; in vf610_nfc_write_page_raw()
675 struct vf610_nfc *nfc = chip_to_nfc(chip); in vf610_nfc_read_oob() local
678 nfc->data_access = true; in vf610_nfc_read_oob()
680 nfc->data_access = false; in vf610_nfc_read_oob()
688 struct vf610_nfc *nfc = chip_to_nfc(chip); in vf610_nfc_write_oob() local
691 nfc->data_access = true; in vf610_nfc_write_oob()
694 nfc->data_access = false; in vf610_nfc_write_oob()
703 { .compatible = "fsl,vf610-nfc", .data = (void *)NFC_VFC610 },
708 static void vf610_nfc_preinit_controller(struct vf610_nfc *nfc) in vf610_nfc_preinit_controller() argument
710 vf610_nfc_clear(nfc, NFC_FLASH_CONFIG, CONFIG_16BIT); in vf610_nfc_preinit_controller()
711 vf610_nfc_clear(nfc, NFC_FLASH_CONFIG, CONFIG_ADDR_AUTO_INCR_BIT); in vf610_nfc_preinit_controller()
712 vf610_nfc_clear(nfc, NFC_FLASH_CONFIG, CONFIG_BUFNO_AUTO_INCR_BIT); in vf610_nfc_preinit_controller()
713 vf610_nfc_clear(nfc, NFC_FLASH_CONFIG, CONFIG_BOOT_MODE_BIT); in vf610_nfc_preinit_controller()
714 vf610_nfc_clear(nfc, NFC_FLASH_CONFIG, CONFIG_DMA_REQ_BIT); in vf610_nfc_preinit_controller()
715 vf610_nfc_set(nfc, NFC_FLASH_CONFIG, CONFIG_FAST_FLASH_BIT); in vf610_nfc_preinit_controller()
716 vf610_nfc_ecc_mode(nfc, ECC_BYPASS); in vf610_nfc_preinit_controller()
719 vf610_nfc_set_field(nfc, NFC_FLASH_CONFIG, CONFIG_PAGE_CNT_MASK, in vf610_nfc_preinit_controller()
723 static void vf610_nfc_init_controller(struct vf610_nfc *nfc) in vf610_nfc_init_controller() argument
725 if (nfc->chip.options & NAND_BUSWIDTH_16) in vf610_nfc_init_controller()
726 vf610_nfc_set(nfc, NFC_FLASH_CONFIG, CONFIG_16BIT); in vf610_nfc_init_controller()
728 vf610_nfc_clear(nfc, NFC_FLASH_CONFIG, CONFIG_16BIT); in vf610_nfc_init_controller()
730 if (nfc->chip.ecc.engine_type == NAND_ECC_ENGINE_TYPE_ON_HOST) { in vf610_nfc_init_controller()
732 vf610_nfc_set_field(nfc, NFC_FLASH_CONFIG, in vf610_nfc_init_controller()
738 vf610_nfc_set(nfc, NFC_FLASH_CONFIG, CONFIG_ECC_SRAM_REQ_BIT); in vf610_nfc_init_controller()
745 struct vf610_nfc *nfc = chip_to_nfc(chip); in vf610_nfc_attach_chip() local
747 vf610_nfc_init_controller(nfc); in vf610_nfc_attach_chip()
755 dev_err(nfc->dev, "Unsupported flash page size\n"); in vf610_nfc_attach_chip()
763 dev_err(nfc->dev, "Unsupported flash with hwecc\n"); in vf610_nfc_attach_chip()
768 dev_err(nfc->dev, "Step size needs to be page size\n"); in vf610_nfc_attach_chip()
779 nfc->ecc_mode = ECC_60_BYTE; in vf610_nfc_attach_chip()
782 nfc->ecc_mode = ECC_45_BYTE; in vf610_nfc_attach_chip()
785 dev_err(nfc->dev, "Unsupported ECC strength\n"); in vf610_nfc_attach_chip()
809 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()
847 nfc->variant = (uintptr_t)of_id->data; in vf610_nfc_probe()
849 for_each_available_child_of_node(nfc->dev->of_node, child) { in vf610_nfc_probe()
850 if (of_device_is_compatible(child, "fsl,vf610-nfc-nandcs")) { in vf610_nfc_probe()
853 dev_err(nfc->dev, in vf610_nfc_probe()
864 dev_err(nfc->dev, "NAND chip sub-node missing!\n"); in vf610_nfc_probe()
870 init_completion(&nfc->cmd_done); in vf610_nfc_probe()
872 err = devm_request_irq(nfc->dev, irq, vf610_nfc_irq, 0, DRV_NAME, nfc); in vf610_nfc_probe()
874 dev_err(nfc->dev, "Error requesting IRQ!\n"); in vf610_nfc_probe()
878 vf610_nfc_preinit_controller(nfc); in vf610_nfc_probe()
880 nand_controller_init(&nfc->base); in vf610_nfc_probe()
881 nfc->base.ops = &vf610_nfc_controller_ops; in vf610_nfc_probe()
882 chip->controller = &nfc->base; in vf610_nfc_probe()
889 platform_set_drvdata(pdev, nfc); in vf610_nfc_probe()
904 struct vf610_nfc *nfc = platform_get_drvdata(pdev); in vf610_nfc_remove() local
905 struct nand_chip *chip = &nfc->chip; in vf610_nfc_remove()
916 struct vf610_nfc *nfc = dev_get_drvdata(dev); in vf610_nfc_suspend() local
918 clk_disable_unprepare(nfc->clk); in vf610_nfc_suspend()
924 struct vf610_nfc *nfc = dev_get_drvdata(dev); in vf610_nfc_resume() local
927 err = clk_prepare_enable(nfc->clk); in vf610_nfc_resume()
931 vf610_nfc_preinit_controller(nfc); in vf610_nfc_resume()
932 vf610_nfc_init_controller(nfc); in vf610_nfc_resume()
952 MODULE_DESCRIPTION("Freescale VF610/MPC5125 NFC MTD NAND driver");