Lines Matching +full:rx +full:- +full:clk +full:- +full:delay +full:- +full:ps
1 // SPDX-License-Identifier: GPL-2.0
9 #include <linux/clk.h>
15 #include <linux/mtd/nand-ecc-sw-hamming.h>
73 #define OP_CMD_BYTES(x) (((x) - 1) << 13)
174 struct clk *ps_clk;
175 struct clk *send_clk;
176 struct clk *send_dly_clk;
188 ret = clk_prepare_enable(nfc->ps_clk); in mxic_nfc_clk_enable()
192 ret = clk_prepare_enable(nfc->send_clk); in mxic_nfc_clk_enable()
196 ret = clk_prepare_enable(nfc->send_dly_clk); in mxic_nfc_clk_enable()
203 clk_disable_unprepare(nfc->send_clk); in mxic_nfc_clk_enable()
205 clk_disable_unprepare(nfc->ps_clk); in mxic_nfc_clk_enable()
212 clk_disable_unprepare(nfc->send_clk); in mxic_nfc_clk_disable()
213 clk_disable_unprepare(nfc->send_dly_clk); in mxic_nfc_clk_disable()
214 clk_disable_unprepare(nfc->ps_clk); in mxic_nfc_clk_disable()
223 nfc->regs + IDLY_CODE(0)); in mxic_nfc_set_input_delay()
228 nfc->regs + IDLY_CODE(1)); in mxic_nfc_set_input_delay()
235 ret = clk_set_rate(nfc->send_clk, freq); in mxic_nfc_clk_setup()
239 ret = clk_set_rate(nfc->send_dly_clk, freq); in mxic_nfc_clk_setup()
244 * A constant delay range from 0x0 ~ 0x1F for input delay, in mxic_nfc_clk_setup()
245 * the unit is 78 ps, the max input delay is 2.418 ns. in mxic_nfc_clk_setup()
250 * Phase degree = 360 * freq * output-delay in mxic_nfc_clk_setup()
251 * where output-delay is a constant value 1 ns in FPGA. in mxic_nfc_clk_setup()
257 ret = clk_set_phase(nfc->send_dly_clk, 9 * freq / 25000000); in mxic_nfc_clk_setup()
288 sts = readl(nfc->regs + INT_STS); in mxic_nfc_isr()
290 complete(&nfc->complete); in mxic_nfc_isr()
301 HC_CFG_IDLE_SIO_LVL(1), nfc->regs + HC_CFG); in mxic_nfc_hw_init()
302 writel(INT_STS_ALL, nfc->regs + INT_STS_EN); in mxic_nfc_hw_init()
303 writel(INT_RDY_PIN, nfc->regs + INT_SIG_EN); in mxic_nfc_hw_init()
304 writel(0x0, nfc->regs + ONFI_DIN_CNT(0)); in mxic_nfc_hw_init()
305 writel(0, nfc->regs + LRD_CFG); in mxic_nfc_hw_init()
306 writel(0, nfc->regs + LRD_CTRL); in mxic_nfc_hw_init()
307 writel(0x0, nfc->regs + HC_EN); in mxic_nfc_hw_init()
312 writel(readl(nfc->regs + HC_CFG) | HC_CFG_MAN_CS_EN, in mxic_nfc_cs_enable()
313 nfc->regs + HC_CFG); in mxic_nfc_cs_enable()
314 writel(HC_CFG_MAN_CS_ASSERT | readl(nfc->regs + HC_CFG), in mxic_nfc_cs_enable()
315 nfc->regs + HC_CFG); in mxic_nfc_cs_enable()
320 writel(~HC_CFG_MAN_CS_ASSERT & readl(nfc->regs + HC_CFG), in mxic_nfc_cs_disable()
321 nfc->regs + HC_CFG); in mxic_nfc_cs_disable()
329 ret = wait_for_completion_timeout(&nfc->complete, in mxic_nfc_wait_ready()
332 dev_err(nfc->dev, "nand device timeout\n"); in mxic_nfc_wait_ready()
333 return -ETIMEDOUT; in mxic_nfc_wait_ready()
345 unsigned int nbytes = len - pos; in mxic_nfc_data_xfer()
356 ret = readl_poll_timeout(nfc->regs + INT_STS, sts, in mxic_nfc_data_xfer()
361 writel(data, nfc->regs + TXD(nbytes % 4)); in mxic_nfc_data_xfer()
363 ret = readl_poll_timeout(nfc->regs + INT_STS, sts, in mxic_nfc_data_xfer()
368 ret = readl_poll_timeout(nfc->regs + INT_STS, sts, in mxic_nfc_data_xfer()
374 data = readl(nfc->regs + RXD); in mxic_nfc_data_xfer()
376 data >>= (8 * (4 - nbytes)); in mxic_nfc_data_xfer()
379 if (readl(nfc->regs + INT_STS) & INT_RX_NOT_EMPTY) in mxic_nfc_data_xfer()
380 dev_warn(nfc->dev, "RX FIFO not empty\n"); in mxic_nfc_data_xfer()
400 init_completion(&nfc->complete); in mxic_nfc_exec_op()
401 for (op_id = 0; op_id < op->ninstrs; op_id++) { in mxic_nfc_exec_op()
402 instr = &op->instrs[op_id]; in mxic_nfc_exec_op()
404 switch (instr->type) { in mxic_nfc_exec_op()
406 writel(0, nfc->regs + HC_EN); in mxic_nfc_exec_op()
407 writel(HC_EN_BIT, nfc->regs + HC_EN); in mxic_nfc_exec_op()
409 OP_CMD_BYTES(0), nfc->regs + SS_CTRL(0)); in mxic_nfc_exec_op()
412 &instr->ctx.cmd.opcode, in mxic_nfc_exec_op()
418 OP_ADDR_BYTES(instr->ctx.addr.naddrs), in mxic_nfc_exec_op()
419 nfc->regs + SS_CTRL(0)); in mxic_nfc_exec_op()
421 instr->ctx.addr.addrs, NULL, in mxic_nfc_exec_op()
422 instr->ctx.addr.naddrs); in mxic_nfc_exec_op()
426 writel(0x0, nfc->regs + ONFI_DIN_CNT(0)); in mxic_nfc_exec_op()
428 OP_READ, nfc->regs + SS_CTRL(0)); in mxic_nfc_exec_op()
430 instr->ctx.data.buf.in, in mxic_nfc_exec_op()
431 instr->ctx.data.len); in mxic_nfc_exec_op()
435 writel(instr->ctx.data.len, in mxic_nfc_exec_op()
436 nfc->regs + ONFI_DIN_CNT(0)); in mxic_nfc_exec_op()
438 nfc->regs + SS_CTRL(0)); in mxic_nfc_exec_op()
440 instr->ctx.data.buf.out, NULL, in mxic_nfc_exec_op()
441 instr->ctx.data.len); in mxic_nfc_exec_op()
469 freq = NSEC_PER_SEC / (sdr->tRC_min / 1000); in mxic_nfc_setup_interface()
473 dev_err(nfc->dev, "set freq:%ld failed\n", freq); in mxic_nfc_setup_interface()
475 if (sdr->tRC_min < 30000) in mxic_nfc_setup_interface()
476 writel(DATA_STROB_EDO_EN, nfc->regs + DATA_STROB); in mxic_nfc_setup_interface()
488 struct device_node *nand_np, *np = pdev->dev.of_node; in mxic_nfc_probe()
495 nfc = devm_kzalloc(&pdev->dev, sizeof(struct mxic_nand_ctlr), in mxic_nfc_probe()
498 return -ENOMEM; in mxic_nfc_probe()
500 nfc->ps_clk = devm_clk_get(&pdev->dev, "ps"); in mxic_nfc_probe()
501 if (IS_ERR(nfc->ps_clk)) in mxic_nfc_probe()
502 return PTR_ERR(nfc->ps_clk); in mxic_nfc_probe()
504 nfc->send_clk = devm_clk_get(&pdev->dev, "send"); in mxic_nfc_probe()
505 if (IS_ERR(nfc->send_clk)) in mxic_nfc_probe()
506 return PTR_ERR(nfc->send_clk); in mxic_nfc_probe()
508 nfc->send_dly_clk = devm_clk_get(&pdev->dev, "send_dly"); in mxic_nfc_probe()
509 if (IS_ERR(nfc->send_dly_clk)) in mxic_nfc_probe()
510 return PTR_ERR(nfc->send_dly_clk); in mxic_nfc_probe()
512 nfc->regs = devm_platform_ioremap_resource(pdev, 0); in mxic_nfc_probe()
513 if (IS_ERR(nfc->regs)) in mxic_nfc_probe()
514 return PTR_ERR(nfc->regs); in mxic_nfc_probe()
516 nand_chip = &nfc->chip; in mxic_nfc_probe()
518 mtd->dev.parent = &pdev->dev; in mxic_nfc_probe()
523 nand_chip->priv = nfc; in mxic_nfc_probe()
524 nfc->dev = &pdev->dev; in mxic_nfc_probe()
525 nfc->controller.ops = &mxic_nand_controller_ops; in mxic_nfc_probe()
526 nand_controller_init(&nfc->controller); in mxic_nfc_probe()
527 nand_chip->controller = &nfc->controller; in mxic_nfc_probe()
535 err = devm_request_irq(&pdev->dev, irq, mxic_nfc_isr, in mxic_nfc_probe()
536 0, "mxic-nfc", nfc); in mxic_nfc_probe()
559 struct nand_chip *chip = &nfc->chip; in mxic_nfc_remove()
570 { .compatible = "mxic,multi-itfc-v009-nand-controller", },
579 .name = "mxic-nfc",