Lines Matching refs:nfc

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