Lines Matching refs:nfc

259 	struct sunxi_nfc *nfc = dev_id;  in sunxi_nfc_interrupt()  local
260 u32 st = readl(nfc->regs + NFC_REG_ST); in sunxi_nfc_interrupt()
261 u32 ien = readl(nfc->regs + NFC_REG_INT); in sunxi_nfc_interrupt()
267 complete(&nfc->complete); in sunxi_nfc_interrupt()
269 writel(st & NFC_INT_MASK, nfc->regs + NFC_REG_ST); in sunxi_nfc_interrupt()
270 writel(~st & ien & NFC_INT_MASK, nfc->regs + NFC_REG_INT); in sunxi_nfc_interrupt()
275 static int sunxi_nfc_wait_events(struct sunxi_nfc *nfc, u32 events, in sunxi_nfc_wait_events() argument
287 init_completion(&nfc->complete); in sunxi_nfc_wait_events()
289 writel(events, nfc->regs + NFC_REG_INT); in sunxi_nfc_wait_events()
291 ret = wait_for_completion_timeout(&nfc->complete, in sunxi_nfc_wait_events()
298 writel(0, nfc->regs + NFC_REG_INT); in sunxi_nfc_wait_events()
302 ret = readl_poll_timeout(nfc->regs + NFC_REG_ST, status, in sunxi_nfc_wait_events()
307 writel(events & NFC_INT_MASK, nfc->regs + NFC_REG_ST); in sunxi_nfc_wait_events()
310 dev_err(nfc->dev, "wait interrupt timedout\n"); in sunxi_nfc_wait_events()
315 static int sunxi_nfc_wait_cmd_fifo_empty(struct sunxi_nfc *nfc) in sunxi_nfc_wait_cmd_fifo_empty() argument
320 ret = readl_poll_timeout(nfc->regs + NFC_REG_ST, status, in sunxi_nfc_wait_cmd_fifo_empty()
324 dev_err(nfc->dev, "wait for empty cmd FIFO timedout\n"); in sunxi_nfc_wait_cmd_fifo_empty()
329 static int sunxi_nfc_rst(struct sunxi_nfc *nfc) in sunxi_nfc_rst() argument
334 writel(0, nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_rst()
335 writel(NFC_RESET, nfc->regs + NFC_REG_CTL); in sunxi_nfc_rst()
337 ret = readl_poll_timeout(nfc->regs + NFC_REG_CTL, ctl, in sunxi_nfc_rst()
341 dev_err(nfc->dev, "wait for NAND controller reset timedout\n"); in sunxi_nfc_rst()
346 static int sunxi_nfc_dma_op_prepare(struct sunxi_nfc *nfc, const void *buf, in sunxi_nfc_dma_op_prepare() argument
362 ret = dma_map_sg(nfc->dev, sg, 1, ddir); in sunxi_nfc_dma_op_prepare()
366 dmad = dmaengine_prep_slave_sg(nfc->dmac, sg, 1, tdir, DMA_CTRL_ACK); in sunxi_nfc_dma_op_prepare()
372 writel(readl(nfc->regs + NFC_REG_CTL) | NFC_RAM_METHOD, in sunxi_nfc_dma_op_prepare()
373 nfc->regs + NFC_REG_CTL); in sunxi_nfc_dma_op_prepare()
374 writel(nchunks, nfc->regs + NFC_REG_SECTOR_NUM); in sunxi_nfc_dma_op_prepare()
375 writel(chunksize, nfc->regs + NFC_REG_CNT); in sunxi_nfc_dma_op_prepare()
376 if (nfc->caps->extra_mbus_conf) in sunxi_nfc_dma_op_prepare()
377 writel(chunksize * nchunks, nfc->regs + NFC_REG_MDMA_CNT); in sunxi_nfc_dma_op_prepare()
388 writel(readl(nfc->regs + NFC_REG_CTL) & ~NFC_RAM_METHOD, in sunxi_nfc_dma_op_prepare()
389 nfc->regs + NFC_REG_CTL); in sunxi_nfc_dma_op_prepare()
392 dma_unmap_sg(nfc->dev, sg, 1, ddir); in sunxi_nfc_dma_op_prepare()
396 static void sunxi_nfc_dma_op_cleanup(struct sunxi_nfc *nfc, in sunxi_nfc_dma_op_cleanup() argument
400 dma_unmap_sg(nfc->dev, sg, 1, ddir); in sunxi_nfc_dma_op_cleanup()
401 writel(readl(nfc->regs + NFC_REG_CTL) & ~NFC_RAM_METHOD, in sunxi_nfc_dma_op_cleanup()
402 nfc->regs + NFC_REG_CTL); in sunxi_nfc_dma_op_cleanup()
409 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); in sunxi_nfc_select_chip() local
416 ctl = readl(nfc->regs + NFC_REG_CTL) & in sunxi_nfc_select_chip()
424 writel(mtd->writesize, nfc->regs + NFC_REG_SPARE_AREA); in sunxi_nfc_select_chip()
426 if (nfc->clk_rate != sunxi_nand->clk_rate) { in sunxi_nfc_select_chip()
427 clk_set_rate(nfc->mod_clk, sunxi_nand->clk_rate); in sunxi_nfc_select_chip()
428 nfc->clk_rate = sunxi_nand->clk_rate; in sunxi_nfc_select_chip()
431 writel(sunxi_nand->timing_ctl, nfc->regs + NFC_REG_TIMING_CTL); in sunxi_nfc_select_chip()
432 writel(sunxi_nand->timing_cfg, nfc->regs + NFC_REG_TIMING_CFG); in sunxi_nfc_select_chip()
433 writel(ctl, nfc->regs + NFC_REG_CTL); in sunxi_nfc_select_chip()
439 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); in sunxi_nfc_read_buf() local
450 ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); in sunxi_nfc_read_buf()
454 writel(cnt, nfc->regs + NFC_REG_CNT); in sunxi_nfc_read_buf()
456 writel(tmp, nfc->regs + NFC_REG_CMD); in sunxi_nfc_read_buf()
462 ret = sunxi_nfc_wait_events(nfc, NFC_CMD_INT_FLAG, poll, 0); in sunxi_nfc_read_buf()
467 memcpy_fromio(buf + offs, nfc->regs + NFC_RAM0_BASE, in sunxi_nfc_read_buf()
477 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); in sunxi_nfc_write_buf() local
488 ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); in sunxi_nfc_write_buf()
492 writel(cnt, nfc->regs + NFC_REG_CNT); in sunxi_nfc_write_buf()
493 memcpy_toio(nfc->regs + NFC_RAM0_BASE, buf + offs, cnt); in sunxi_nfc_write_buf()
496 writel(tmp, nfc->regs + NFC_REG_CMD); in sunxi_nfc_write_buf()
502 ret = sunxi_nfc_wait_events(nfc, NFC_CMD_INT_FLAG, poll, 0); in sunxi_nfc_write_buf()
615 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); in sunxi_nfc_randomizer_config() local
616 u32 ecc_ctl = readl(nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_randomizer_config()
622 ecc_ctl = readl(nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_randomizer_config()
624 ecc_ctl = readl(nfc->regs + NFC_REG_ECC_CTL) & ~NFC_RANDOM_SEED_MSK; in sunxi_nfc_randomizer_config()
625 writel(ecc_ctl | NFC_RANDOM_SEED(state), nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_randomizer_config()
630 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); in sunxi_nfc_randomizer_enable() local
635 writel(readl(nfc->regs + NFC_REG_ECC_CTL) | NFC_RANDOM_EN, in sunxi_nfc_randomizer_enable()
636 nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_randomizer_enable()
641 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); in sunxi_nfc_randomizer_disable() local
646 writel(readl(nfc->regs + NFC_REG_ECC_CTL) & ~NFC_RANDOM_EN, in sunxi_nfc_randomizer_disable()
647 nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_randomizer_disable()
679 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); in sunxi_nfc_hw_ecc_enable() local
683 ecc_ctl = readl(nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_hw_ecc_enable()
692 writel(ecc_ctl, nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_hw_ecc_enable()
697 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); in sunxi_nfc_hw_ecc_disable() local
699 writel(readl(nfc->regs + NFC_REG_ECC_CTL) & ~NFC_ECC_EN, in sunxi_nfc_hw_ecc_disable()
700 nfc->regs + NFC_REG_ECC_CTL); in sunxi_nfc_hw_ecc_disable()
719 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); in sunxi_nfc_hw_ecc_get_prot_oob_bytes() local
721 sunxi_nfc_user_data_to_buf(readl(nfc->regs + NFC_REG_USER_DATA(step)), in sunxi_nfc_hw_ecc_get_prot_oob_bytes()
733 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); in sunxi_nfc_hw_ecc_set_prot_oob_bytes() local
744 nfc->regs + NFC_REG_USER_DATA(step)); in sunxi_nfc_hw_ecc_set_prot_oob_bytes()
763 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); in sunxi_nfc_hw_ecc_correct() local
775 if (unlikely(!(readl(nfc->regs + NFC_REG_PAT_ID) & 0x1))) { in sunxi_nfc_hw_ecc_correct()
791 tmp = readl(nfc->regs + NFC_REG_ECC_ERR_CNT(step)); in sunxi_nfc_hw_ecc_correct()
803 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); in sunxi_nfc_hw_ecc_read_chunk() local
817 ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); in sunxi_nfc_hw_ecc_read_chunk()
823 nfc->regs + NFC_REG_CMD); in sunxi_nfc_hw_ecc_read_chunk()
825 ret = sunxi_nfc_wait_events(nfc, NFC_CMD_INT_FLAG, false, 0); in sunxi_nfc_hw_ecc_read_chunk()
833 readl(nfc->regs + NFC_REG_ECC_ST), in sunxi_nfc_hw_ecc_read_chunk()
847 memcpy_fromio(data, nfc->regs + NFC_RAM0_BASE, in sunxi_nfc_hw_ecc_read_chunk()
859 memcpy_fromio(data, nfc->regs + NFC_RAM0_BASE, ecc->size); in sunxi_nfc_hw_ecc_read_chunk()
908 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); in sunxi_nfc_hw_ecc_read_chunks_dma() local
916 ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); in sunxi_nfc_hw_ecc_read_chunks_dma()
920 ret = sunxi_nfc_dma_op_prepare(nfc, buf, ecc->size, nchunks, in sunxi_nfc_hw_ecc_read_chunks_dma()
930 NAND_CMD_READSTART, nfc->regs + NFC_REG_RCMD_SET); in sunxi_nfc_hw_ecc_read_chunks_dma()
932 dma_async_issue_pending(nfc->dmac); in sunxi_nfc_hw_ecc_read_chunks_dma()
935 nfc->regs + NFC_REG_CMD); in sunxi_nfc_hw_ecc_read_chunks_dma()
937 ret = sunxi_nfc_wait_events(nfc, NFC_CMD_INT_FLAG, false, 0); in sunxi_nfc_hw_ecc_read_chunks_dma()
939 dmaengine_terminate_all(nfc->dmac); in sunxi_nfc_hw_ecc_read_chunks_dma()
944 sunxi_nfc_dma_op_cleanup(nfc, DMA_FROM_DEVICE, &sg); in sunxi_nfc_hw_ecc_read_chunks_dma()
949 status = readl(nfc->regs + NFC_REG_ECC_ST); in sunxi_nfc_hw_ecc_read_chunks_dma()
1032 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); in sunxi_nfc_hw_ecc_write_chunk() local
1044 ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); in sunxi_nfc_hw_ecc_write_chunk()
1053 nfc->regs + NFC_REG_CMD); in sunxi_nfc_hw_ecc_write_chunk()
1055 ret = sunxi_nfc_wait_events(nfc, NFC_CMD_INT_FLAG, false, 0); in sunxi_nfc_hw_ecc_write_chunk()
1276 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); in sunxi_nfc_hw_ecc_write_page_dma() local
1283 ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); in sunxi_nfc_hw_ecc_write_page_dma()
1287 ret = sunxi_nfc_dma_op_prepare(nfc, buf, ecc->size, ecc->steps, in sunxi_nfc_hw_ecc_write_page_dma()
1305 nfc->regs + NFC_REG_WCMD_SET); in sunxi_nfc_hw_ecc_write_page_dma()
1307 dma_async_issue_pending(nfc->dmac); in sunxi_nfc_hw_ecc_write_page_dma()
1311 nfc->regs + NFC_REG_CMD); in sunxi_nfc_hw_ecc_write_page_dma()
1313 ret = sunxi_nfc_wait_events(nfc, NFC_CMD_INT_FLAG, false, 0); in sunxi_nfc_hw_ecc_write_page_dma()
1315 dmaengine_terminate_all(nfc->dmac); in sunxi_nfc_hw_ecc_write_page_dma()
1320 sunxi_nfc_dma_op_cleanup(nfc, DMA_TO_DEVICE, &sg); in sunxi_nfc_hw_ecc_write_page_dma()
1383 struct sunxi_nfc *nfc = to_sunxi_nfc(sunxi_nand->nand.controller); in sunxi_nfc_setup_interface() local
1483 dev_err(nfc->dev, "unsupported tWB\n"); in sunxi_nfc_setup_interface()
1489 dev_err(nfc->dev, "unsupported tADL\n"); in sunxi_nfc_setup_interface()
1495 dev_err(nfc->dev, "unsupported tWHR\n"); in sunxi_nfc_setup_interface()
1502 dev_err(nfc->dev, "unsupported tRHW\n"); in sunxi_nfc_setup_interface()
1528 real_clk_rate = clk_round_rate(nfc->mod_clk, sunxi_nand->clk_rate); in sunxi_nfc_setup_interface()
1530 dev_err(nfc->dev, "Unable to round clk %lu\n", in sunxi_nfc_setup_interface()
1610 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); in sunxi_nand_hw_ecc_ctrl_init() local
1673 dev_err(nfc->dev, "unsupported strength\n"); in sunxi_nand_hw_ecc_ctrl_init()
1698 if (nfc->dmac) { in sunxi_nand_hw_ecc_ctrl_init()
1777 struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller); in sunxi_nfc_exec_subop() local
1823 memcpy_toio(nfc->regs + NFC_RAM0_BASE, in sunxi_nfc_exec_subop()
1838 ret = sunxi_nfc_wait_cmd_fifo_empty(nfc); in sunxi_nfc_exec_subop()
1843 writel(addrs[0], nfc->regs + NFC_REG_ADDR_LOW); in sunxi_nfc_exec_subop()
1844 writel(addrs[1], nfc->regs + NFC_REG_ADDR_HIGH); in sunxi_nfc_exec_subop()
1849 nfc->regs + in sunxi_nfc_exec_subop()
1854 writel(cnt, nfc->regs + NFC_REG_CNT); in sunxi_nfc_exec_subop()
1856 writel(cmd, nfc->regs + NFC_REG_CMD); in sunxi_nfc_exec_subop()
1858 ret = sunxi_nfc_wait_events(nfc, NFC_CMD_INT_FLAG, in sunxi_nfc_exec_subop()
1865 memcpy_fromio(inbuf, nfc->regs + NFC_RAM0_BASE, cnt); in sunxi_nfc_exec_subop()
1930 static int sunxi_nand_chip_init(struct device *dev, struct sunxi_nfc *nfc, in sunxi_nand_chip_init() argument
1974 if (test_and_set_bit(tmp, &nfc->assigned_cs)) { in sunxi_nand_chip_init()
1990 nand->controller = &nfc->controller; in sunxi_nand_chip_init()
2014 list_add_tail(&sunxi_nand->node, &nfc->chips); in sunxi_nand_chip_init()
2019 static int sunxi_nand_chips_init(struct device *dev, struct sunxi_nfc *nfc) in sunxi_nand_chips_init() argument
2032 ret = sunxi_nand_chip_init(dev, nfc, nand_np); in sunxi_nand_chips_init()
2042 static void sunxi_nand_chips_cleanup(struct sunxi_nfc *nfc) in sunxi_nand_chips_cleanup() argument
2048 while (!list_empty(&nfc->chips)) { in sunxi_nand_chips_cleanup()
2049 sunxi_nand = list_first_entry(&nfc->chips, in sunxi_nand_chips_cleanup()
2065 struct sunxi_nfc *nfc; in sunxi_nfc_probe() local
2069 nfc = devm_kzalloc(dev, sizeof(*nfc), GFP_KERNEL); in sunxi_nfc_probe()
2070 if (!nfc) in sunxi_nfc_probe()
2073 nfc->dev = dev; in sunxi_nfc_probe()
2074 nand_controller_init(&nfc->controller); in sunxi_nfc_probe()
2075 INIT_LIST_HEAD(&nfc->chips); in sunxi_nfc_probe()
2078 nfc->regs = devm_ioremap_resource(dev, r); in sunxi_nfc_probe()
2079 if (IS_ERR(nfc->regs)) in sunxi_nfc_probe()
2080 return PTR_ERR(nfc->regs); in sunxi_nfc_probe()
2086 nfc->ahb_clk = devm_clk_get(dev, "ahb"); in sunxi_nfc_probe()
2087 if (IS_ERR(nfc->ahb_clk)) { in sunxi_nfc_probe()
2089 return PTR_ERR(nfc->ahb_clk); in sunxi_nfc_probe()
2092 ret = clk_prepare_enable(nfc->ahb_clk); in sunxi_nfc_probe()
2096 nfc->mod_clk = devm_clk_get(dev, "mod"); in sunxi_nfc_probe()
2097 if (IS_ERR(nfc->mod_clk)) { in sunxi_nfc_probe()
2099 ret = PTR_ERR(nfc->mod_clk); in sunxi_nfc_probe()
2103 ret = clk_prepare_enable(nfc->mod_clk); in sunxi_nfc_probe()
2107 nfc->reset = devm_reset_control_get_optional_exclusive(dev, "ahb"); in sunxi_nfc_probe()
2108 if (IS_ERR(nfc->reset)) { in sunxi_nfc_probe()
2109 ret = PTR_ERR(nfc->reset); in sunxi_nfc_probe()
2113 ret = reset_control_deassert(nfc->reset); in sunxi_nfc_probe()
2119 nfc->caps = of_device_get_match_data(&pdev->dev); in sunxi_nfc_probe()
2120 if (!nfc->caps) { in sunxi_nfc_probe()
2125 ret = sunxi_nfc_rst(nfc); in sunxi_nfc_probe()
2129 writel(0, nfc->regs + NFC_REG_INT); in sunxi_nfc_probe()
2131 0, "sunxi-nand", nfc); in sunxi_nfc_probe()
2135 nfc->dmac = dma_request_chan(dev, "rxtx"); in sunxi_nfc_probe()
2136 if (IS_ERR(nfc->dmac)) { in sunxi_nfc_probe()
2137 ret = PTR_ERR(nfc->dmac); in sunxi_nfc_probe()
2143 nfc->dmac = NULL; in sunxi_nfc_probe()
2147 dmac_cfg.src_addr = r->start + nfc->caps->reg_io_data; in sunxi_nfc_probe()
2151 dmac_cfg.src_maxburst = nfc->caps->dma_maxburst; in sunxi_nfc_probe()
2152 dmac_cfg.dst_maxburst = nfc->caps->dma_maxburst; in sunxi_nfc_probe()
2153 dmaengine_slave_config(nfc->dmac, &dmac_cfg); in sunxi_nfc_probe()
2155 if (nfc->caps->extra_mbus_conf) in sunxi_nfc_probe()
2156 writel(readl(nfc->regs + NFC_REG_CTL) | in sunxi_nfc_probe()
2157 NFC_DMA_TYPE_NORMAL, nfc->regs + NFC_REG_CTL); in sunxi_nfc_probe()
2160 platform_set_drvdata(pdev, nfc); in sunxi_nfc_probe()
2162 ret = sunxi_nand_chips_init(dev, nfc); in sunxi_nfc_probe()
2171 if (nfc->dmac) in sunxi_nfc_probe()
2172 dma_release_channel(nfc->dmac); in sunxi_nfc_probe()
2174 reset_control_assert(nfc->reset); in sunxi_nfc_probe()
2176 clk_disable_unprepare(nfc->mod_clk); in sunxi_nfc_probe()
2178 clk_disable_unprepare(nfc->ahb_clk); in sunxi_nfc_probe()
2185 struct sunxi_nfc *nfc = platform_get_drvdata(pdev); in sunxi_nfc_remove() local
2187 sunxi_nand_chips_cleanup(nfc); in sunxi_nfc_remove()
2189 reset_control_assert(nfc->reset); in sunxi_nfc_remove()
2191 if (nfc->dmac) in sunxi_nfc_remove()
2192 dma_release_channel(nfc->dmac); in sunxi_nfc_remove()
2193 clk_disable_unprepare(nfc->mod_clk); in sunxi_nfc_remove()
2194 clk_disable_unprepare(nfc->ahb_clk); in sunxi_nfc_remove()