Lines Matching full:nfc

225 	struct meson_nfc *nfc = nand_get_controller_data(nand);  in meson_nfc_select_chip()  local
231 nfc->param.chip_select = meson_chip->sels[chip] ? NAND_CE1 : NAND_CE0; in meson_nfc_select_chip()
232 nfc->param.rb_select = nfc->param.chip_select; in meson_nfc_select_chip()
233 nfc->timing.twb = meson_chip->twb; in meson_nfc_select_chip()
234 nfc->timing.tadl = meson_chip->tadl; in meson_nfc_select_chip()
235 nfc->timing.tbers_max = meson_chip->tbers_max; in meson_nfc_select_chip()
237 if (nfc->clk_rate != meson_chip->clk_rate) { in meson_nfc_select_chip()
238 ret = clk_set_rate(nfc->device_clk, meson_chip->clk_rate); in meson_nfc_select_chip()
240 dev_err(nfc->dev, "failed to set clock rate\n"); in meson_nfc_select_chip()
243 nfc->clk_rate = meson_chip->clk_rate; in meson_nfc_select_chip()
245 if (nfc->bus_timing != meson_chip->bus_timing) { in meson_nfc_select_chip()
247 writel(value, nfc->reg_base + NFC_REG_CFG); in meson_nfc_select_chip()
248 writel((1 << 31), nfc->reg_base + NFC_REG_CMD); in meson_nfc_select_chip()
249 nfc->bus_timing = meson_chip->bus_timing; in meson_nfc_select_chip()
253 static void meson_nfc_cmd_idle(struct meson_nfc *nfc, u32 time) in meson_nfc_cmd_idle() argument
255 writel(nfc->param.chip_select | NFC_CMD_IDLE | (time & 0x3ff), in meson_nfc_cmd_idle()
256 nfc->reg_base + NFC_REG_CMD); in meson_nfc_cmd_idle()
259 static void meson_nfc_cmd_seed(struct meson_nfc *nfc, u32 seed) in meson_nfc_cmd_seed() argument
262 nfc->reg_base + NFC_REG_CMD); in meson_nfc_cmd_seed()
269 struct meson_nfc *nfc = nand_get_controller_data(mtd_to_nand(mtd)); in meson_nfc_cmd_access() local
279 writel(cmd, nfc->reg_base + NFC_REG_CMD); in meson_nfc_cmd_access()
288 writel(cmd, nfc->reg_base + NFC_REG_CMD); in meson_nfc_cmd_access()
291 static void meson_nfc_drain_cmd(struct meson_nfc *nfc) in meson_nfc_drain_cmd() argument
300 * one is fetched into NFC request queue (ready to run), and another in meson_nfc_drain_cmd()
304 meson_nfc_cmd_idle(nfc, 0); in meson_nfc_drain_cmd()
305 meson_nfc_cmd_idle(nfc, 0); in meson_nfc_drain_cmd()
308 static int meson_nfc_wait_cmd_finish(struct meson_nfc *nfc, in meson_nfc_wait_cmd_finish() argument
315 ret = readl_relaxed_poll_timeout(nfc->reg_base + NFC_REG_CMD, cmd_size, in meson_nfc_wait_cmd_finish()
319 dev_err(nfc->dev, "wait for empty CMD FIFO time out\n"); in meson_nfc_wait_cmd_finish()
324 static int meson_nfc_wait_dma_finish(struct meson_nfc *nfc) in meson_nfc_wait_dma_finish() argument
326 meson_nfc_drain_cmd(nfc); in meson_nfc_wait_dma_finish()
328 return meson_nfc_wait_cmd_finish(nfc, DMA_BUSY_TIMEOUT); in meson_nfc_wait_dma_finish()
390 static int meson_nfc_queue_rb(struct meson_nfc *nfc, int timeout_ms) in meson_nfc_queue_rb() argument
395 meson_nfc_cmd_idle(nfc, nfc->timing.twb); in meson_nfc_queue_rb()
396 meson_nfc_drain_cmd(nfc); in meson_nfc_queue_rb()
397 meson_nfc_wait_cmd_finish(nfc, CMD_FIFO_EMPTY_TIMEOUT); in meson_nfc_queue_rb()
399 cfg = readl(nfc->reg_base + NFC_REG_CFG); in meson_nfc_queue_rb()
401 writel(cfg, nfc->reg_base + NFC_REG_CFG); in meson_nfc_queue_rb()
403 reinit_completion(&nfc->completion); in meson_nfc_queue_rb()
407 | nfc->param.chip_select | nfc->timing.tbers_max; in meson_nfc_queue_rb()
408 writel(cmd, nfc->reg_base + NFC_REG_CMD); in meson_nfc_queue_rb()
410 ret = wait_for_completion_timeout(&nfc->completion, in meson_nfc_queue_rb()
477 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_dma_buffer_setup() local
481 nfc->daddr = dma_map_single(nfc->dev, databuf, datalen, dir); in meson_nfc_dma_buffer_setup()
482 ret = dma_mapping_error(nfc->dev, nfc->daddr); in meson_nfc_dma_buffer_setup()
484 dev_err(nfc->dev, "DMA mapping error\n"); in meson_nfc_dma_buffer_setup()
487 cmd = GENCMDDADDRL(NFC_CMD_ADL, nfc->daddr); in meson_nfc_dma_buffer_setup()
488 writel(cmd, nfc->reg_base + NFC_REG_CMD); in meson_nfc_dma_buffer_setup()
490 cmd = GENCMDDADDRH(NFC_CMD_ADH, nfc->daddr); in meson_nfc_dma_buffer_setup()
491 writel(cmd, nfc->reg_base + NFC_REG_CMD); in meson_nfc_dma_buffer_setup()
494 nfc->iaddr = dma_map_single(nfc->dev, infobuf, infolen, dir); in meson_nfc_dma_buffer_setup()
495 ret = dma_mapping_error(nfc->dev, nfc->iaddr); in meson_nfc_dma_buffer_setup()
497 dev_err(nfc->dev, "DMA mapping error\n"); in meson_nfc_dma_buffer_setup()
498 dma_unmap_single(nfc->dev, in meson_nfc_dma_buffer_setup()
499 nfc->daddr, datalen, dir); in meson_nfc_dma_buffer_setup()
502 cmd = GENCMDIADDRL(NFC_CMD_AIL, nfc->iaddr); in meson_nfc_dma_buffer_setup()
503 writel(cmd, nfc->reg_base + NFC_REG_CMD); in meson_nfc_dma_buffer_setup()
505 cmd = GENCMDIADDRH(NFC_CMD_AIH, nfc->iaddr); in meson_nfc_dma_buffer_setup()
506 writel(cmd, nfc->reg_base + NFC_REG_CMD); in meson_nfc_dma_buffer_setup()
516 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_dma_buffer_release() local
518 dma_unmap_single(nfc->dev, nfc->daddr, datalen, dir); in meson_nfc_dma_buffer_release()
520 dma_unmap_single(nfc->dev, nfc->iaddr, infolen, dir); in meson_nfc_dma_buffer_release()
525 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_read_buf() local
540 writel(cmd, nfc->reg_base + NFC_REG_CMD); in meson_nfc_read_buf()
542 meson_nfc_drain_cmd(nfc); in meson_nfc_read_buf()
543 meson_nfc_wait_cmd_finish(nfc, 1000); in meson_nfc_read_buf()
554 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_write_buf() local
564 writel(cmd, nfc->reg_base + NFC_REG_CMD); in meson_nfc_write_buf()
566 meson_nfc_drain_cmd(nfc); in meson_nfc_write_buf()
567 meson_nfc_wait_cmd_finish(nfc, 1000); in meson_nfc_write_buf()
579 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_rw_cmd_prepare_and_execute() local
580 u32 *addrs = nfc->cmdfifo.rw.addrs; in meson_nfc_rw_cmd_prepare_and_execute()
581 u32 cs = nfc->param.chip_select; in meson_nfc_rw_cmd_prepare_and_execute()
588 nfc->cmdfifo.rw.cmd0 = cs | NFC_CMD_CLE | cmd0; in meson_nfc_rw_cmd_prepare_and_execute()
612 writel_relaxed(nfc->cmdfifo.cmd[i], in meson_nfc_rw_cmd_prepare_and_execute()
613 nfc->reg_base + NFC_REG_CMD); in meson_nfc_rw_cmd_prepare_and_execute()
616 nfc->cmdfifo.rw.cmd1 = cs | NFC_CMD_CLE | NAND_CMD_READSTART; in meson_nfc_rw_cmd_prepare_and_execute()
617 writel(nfc->cmdfifo.rw.cmd1, nfc->reg_base + NFC_REG_CMD); in meson_nfc_rw_cmd_prepare_and_execute()
618 meson_nfc_queue_rb(nfc, PSEC_TO_MSEC(sdr->tR_max)); in meson_nfc_rw_cmd_prepare_and_execute()
620 meson_nfc_cmd_idle(nfc, nfc->timing.tadl); in meson_nfc_rw_cmd_prepare_and_execute()
633 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_write_page_sub() local
654 meson_nfc_cmd_seed(nfc, page); in meson_nfc_write_page_sub()
662 cmd = nfc->param.chip_select | NFC_CMD_CLE | NAND_CMD_PAGEPROG; in meson_nfc_write_page_sub()
663 writel(cmd, nfc->reg_base + NFC_REG_CMD); in meson_nfc_write_page_sub()
664 meson_nfc_queue_rb(nfc, PSEC_TO_MSEC(sdr->tPROG_max)); in meson_nfc_write_page_sub()
695 static void meson_nfc_check_ecc_pages_valid(struct meson_nfc *nfc, in meson_nfc_check_ecc_pages_valid() argument
707 /* info is updated by nfc dma engine*/ in meson_nfc_check_ecc_pages_valid()
717 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_read_page_sub() local
738 meson_nfc_cmd_seed(nfc, page); in meson_nfc_read_page_sub()
746 ret = meson_nfc_wait_dma_finish(nfc); in meson_nfc_read_page_sub()
747 meson_nfc_check_ecc_pages_valid(nfc, nand, raw); in meson_nfc_read_page_sub()
896 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nfc_exec_op() local
913 cmd = nfc->param.chip_select | NFC_CMD_CLE; in meson_nfc_exec_op()
915 writel(cmd, nfc->reg_base + NFC_REG_CMD); in meson_nfc_exec_op()
916 meson_nfc_cmd_idle(nfc, delay_idle); in meson_nfc_exec_op()
921 cmd = nfc->param.chip_select | NFC_CMD_ALE; in meson_nfc_exec_op()
923 writel(cmd, nfc->reg_base + NFC_REG_CMD); in meson_nfc_exec_op()
925 meson_nfc_cmd_idle(nfc, delay_idle); in meson_nfc_exec_op()
945 meson_nfc_queue_rb(nfc, instr->ctx.waitrdy.timeout_ms); in meson_nfc_exec_op()
947 meson_nfc_cmd_idle(nfc, delay_idle); in meson_nfc_exec_op()
951 meson_nfc_wait_cmd_finish(nfc, 1000); in meson_nfc_exec_op()
988 static int meson_nfc_clk_init(struct meson_nfc *nfc) in meson_nfc_clk_init() argument
993 nfc->core_clk = devm_clk_get(nfc->dev, "core"); in meson_nfc_clk_init()
994 if (IS_ERR(nfc->core_clk)) { in meson_nfc_clk_init()
995 dev_err(nfc->dev, "failed to get core clock\n"); in meson_nfc_clk_init()
996 return PTR_ERR(nfc->core_clk); in meson_nfc_clk_init()
999 nfc->device_clk = devm_clk_get(nfc->dev, "device"); in meson_nfc_clk_init()
1000 if (IS_ERR(nfc->device_clk)) { in meson_nfc_clk_init()
1001 dev_err(nfc->dev, "failed to get device clock\n"); in meson_nfc_clk_init()
1002 return PTR_ERR(nfc->device_clk); in meson_nfc_clk_init()
1005 nfc->phase_tx = devm_clk_get(nfc->dev, "tx"); in meson_nfc_clk_init()
1006 if (IS_ERR(nfc->phase_tx)) { in meson_nfc_clk_init()
1007 dev_err(nfc->dev, "failed to get TX clk\n"); in meson_nfc_clk_init()
1008 return PTR_ERR(nfc->phase_tx); in meson_nfc_clk_init()
1011 nfc->phase_rx = devm_clk_get(nfc->dev, "rx"); in meson_nfc_clk_init()
1012 if (IS_ERR(nfc->phase_rx)) { in meson_nfc_clk_init()
1013 dev_err(nfc->dev, "failed to get RX clk\n"); in meson_nfc_clk_init()
1014 return PTR_ERR(nfc->phase_rx); in meson_nfc_clk_init()
1018 regmap_update_bits(nfc->reg_clk, in meson_nfc_clk_init()
1021 ret = clk_prepare_enable(nfc->core_clk); in meson_nfc_clk_init()
1023 dev_err(nfc->dev, "failed to enable core clock\n"); in meson_nfc_clk_init()
1027 ret = clk_prepare_enable(nfc->device_clk); in meson_nfc_clk_init()
1029 dev_err(nfc->dev, "failed to enable device clock\n"); in meson_nfc_clk_init()
1033 ret = clk_prepare_enable(nfc->phase_tx); in meson_nfc_clk_init()
1035 dev_err(nfc->dev, "failed to enable TX clock\n"); in meson_nfc_clk_init()
1039 ret = clk_prepare_enable(nfc->phase_rx); in meson_nfc_clk_init()
1041 dev_err(nfc->dev, "failed to enable RX clock\n"); in meson_nfc_clk_init()
1045 ret = clk_set_rate(nfc->device_clk, 24000000); in meson_nfc_clk_init()
1051 clk_disable_unprepare(nfc->phase_tx); in meson_nfc_clk_init()
1053 clk_disable_unprepare(nfc->device_clk); in meson_nfc_clk_init()
1055 clk_disable_unprepare(nfc->core_clk); in meson_nfc_clk_init()
1059 static void meson_nfc_disable_clk(struct meson_nfc *nfc) in meson_nfc_disable_clk() argument
1061 clk_disable_unprepare(nfc->phase_rx); in meson_nfc_disable_clk()
1062 clk_disable_unprepare(nfc->phase_tx); in meson_nfc_disable_clk()
1063 clk_disable_unprepare(nfc->device_clk); in meson_nfc_disable_clk()
1064 clk_disable_unprepare(nfc->core_clk); in meson_nfc_disable_clk()
1167 struct meson_nfc *nfc = nand_get_controller_data(nand); in meson_nand_attach_chip() local
1174 mtd->name = devm_kasprintf(nfc->dev, GFP_KERNEL, in meson_nand_attach_chip()
1176 dev_name(nfc->dev), in meson_nand_attach_chip()
1187 ret = nand_ecc_choose_conf(nand, nfc->data->ecc_caps, in meson_nand_attach_chip()
1190 dev_err(nfc->dev, "failed to ECC init\n"); in meson_nand_attach_chip()
1212 dev_err(nfc->dev, "16bits bus width not supported"); in meson_nand_attach_chip()
1231 struct meson_nfc *nfc, struct device_node *np) in meson_nfc_nand_chip_init() argument
1260 if (test_and_set_bit(tmp, &nfc->assigned_cs)) { in meson_nfc_nand_chip_init()
1267 nand->controller = &nfc->controller; in meson_nfc_nand_chip_init()
1270 nand_set_controller_data(nand, nfc); in meson_nfc_nand_chip_init()
1288 list_add_tail(&meson_chip->node, &nfc->chips); in meson_nfc_nand_chip_init()
1293 static int meson_nfc_nand_chip_cleanup(struct meson_nfc *nfc) in meson_nfc_nand_chip_cleanup() argument
1299 while (!list_empty(&nfc->chips)) { in meson_nfc_nand_chip_cleanup()
1300 meson_chip = list_first_entry(&nfc->chips, in meson_nfc_nand_chip_cleanup()
1316 struct meson_nfc *nfc) in meson_nfc_nand_chips_init() argument
1323 ret = meson_nfc_nand_chip_init(dev, nfc, nand_np); in meson_nfc_nand_chips_init()
1325 meson_nfc_nand_chip_cleanup(nfc); in meson_nfc_nand_chips_init()
1336 struct meson_nfc *nfc = id; in meson_nfc_irq() local
1339 cfg = readl(nfc->reg_base + NFC_REG_CFG); in meson_nfc_irq()
1344 writel(cfg, nfc->reg_base + NFC_REG_CFG); in meson_nfc_irq()
1346 complete(&nfc->completion); in meson_nfc_irq()
1360 .compatible = "amlogic,meson-gxl-nfc",
1363 .compatible = "amlogic,meson-axg-nfc",
1373 struct meson_nfc *nfc; in meson_nfc_probe() local
1377 nfc = devm_kzalloc(dev, sizeof(*nfc), GFP_KERNEL); in meson_nfc_probe()
1378 if (!nfc) in meson_nfc_probe()
1381 nfc->data = of_device_get_match_data(&pdev->dev); in meson_nfc_probe()
1382 if (!nfc->data) in meson_nfc_probe()
1385 nand_controller_init(&nfc->controller); in meson_nfc_probe()
1386 INIT_LIST_HEAD(&nfc->chips); in meson_nfc_probe()
1387 init_completion(&nfc->completion); in meson_nfc_probe()
1389 nfc->dev = dev; in meson_nfc_probe()
1392 nfc->reg_base = devm_ioremap_resource(dev, res); in meson_nfc_probe()
1393 if (IS_ERR(nfc->reg_base)) in meson_nfc_probe()
1394 return PTR_ERR(nfc->reg_base); in meson_nfc_probe()
1396 nfc->reg_clk = in meson_nfc_probe()
1399 if (IS_ERR(nfc->reg_clk)) { in meson_nfc_probe()
1401 return PTR_ERR(nfc->reg_clk); in meson_nfc_probe()
1408 ret = meson_nfc_clk_init(nfc); in meson_nfc_probe()
1414 writel(0, nfc->reg_base + NFC_REG_CFG); in meson_nfc_probe()
1415 ret = devm_request_irq(dev, irq, meson_nfc_irq, 0, dev_name(dev), nfc); in meson_nfc_probe()
1417 dev_err(dev, "failed to request NFC IRQ\n"); in meson_nfc_probe()
1428 platform_set_drvdata(pdev, nfc); in meson_nfc_probe()
1430 ret = meson_nfc_nand_chips_init(dev, nfc); in meson_nfc_probe()
1438 meson_nfc_disable_clk(nfc); in meson_nfc_probe()
1444 struct meson_nfc *nfc = platform_get_drvdata(pdev); in meson_nfc_remove() local
1447 ret = meson_nfc_nand_chip_cleanup(nfc); in meson_nfc_remove()
1451 meson_nfc_disable_clk(nfc); in meson_nfc_remove()