Lines Matching full:sfc
159 /* The SFC can transfer max 16KB - 1 at one time
187 static int rockchip_sfc_reset(struct rockchip_sfc *sfc) in rockchip_sfc_reset() argument
192 writel_relaxed(SFC_RCVR_RESET, sfc->regbase + SFC_RCVR); in rockchip_sfc_reset()
194 err = readl_poll_timeout(sfc->regbase + SFC_RCVR, status, in rockchip_sfc_reset()
198 dev_err(sfc->dev, "SFC reset never finished\n"); in rockchip_sfc_reset()
201 writel_relaxed(0xFFFFFFFF, sfc->regbase + SFC_ICLR); in rockchip_sfc_reset()
203 dev_dbg(sfc->dev, "reset\n"); in rockchip_sfc_reset()
208 static u16 rockchip_sfc_get_version(struct rockchip_sfc *sfc) in rockchip_sfc_get_version() argument
210 return (u16)(readl(sfc->regbase + SFC_VER) & 0xffff); in rockchip_sfc_get_version()
213 static u32 rockchip_sfc_get_max_iosize(struct rockchip_sfc *sfc) in rockchip_sfc_get_max_iosize() argument
218 static void rockchip_sfc_irq_unmask(struct rockchip_sfc *sfc, u32 mask) in rockchip_sfc_irq_unmask() argument
223 reg = readl(sfc->regbase + SFC_IMR); in rockchip_sfc_irq_unmask()
225 writel(reg, sfc->regbase + SFC_IMR); in rockchip_sfc_irq_unmask()
228 static void rockchip_sfc_irq_mask(struct rockchip_sfc *sfc, u32 mask) in rockchip_sfc_irq_mask() argument
233 reg = readl(sfc->regbase + SFC_IMR); in rockchip_sfc_irq_mask()
235 writel(reg, sfc->regbase + SFC_IMR); in rockchip_sfc_irq_mask()
238 static int rockchip_sfc_init(struct rockchip_sfc *sfc) in rockchip_sfc_init() argument
240 writel(0, sfc->regbase + SFC_CTRL); in rockchip_sfc_init()
241 writel(0xFFFFFFFF, sfc->regbase + SFC_ICLR); in rockchip_sfc_init()
242 rockchip_sfc_irq_mask(sfc, 0xFFFFFFFF); in rockchip_sfc_init()
243 if (rockchip_sfc_get_version(sfc) >= SFC_VER_4) in rockchip_sfc_init()
244 writel(SFC_LEN_CTRL_TRB_SEL, sfc->regbase + SFC_LEN_CTRL); in rockchip_sfc_init()
249 static int rockchip_sfc_wait_txfifo_ready(struct rockchip_sfc *sfc, u32 timeout_us) in rockchip_sfc_wait_txfifo_ready() argument
254 ret = readl_poll_timeout(sfc->regbase + SFC_FSR, status, in rockchip_sfc_wait_txfifo_ready()
258 dev_dbg(sfc->dev, "sfc wait tx fifo timeout\n"); in rockchip_sfc_wait_txfifo_ready()
266 static int rockchip_sfc_wait_rxfifo_ready(struct rockchip_sfc *sfc, u32 timeout_us) in rockchip_sfc_wait_rxfifo_ready() argument
271 ret = readl_poll_timeout(sfc->regbase + SFC_FSR, status, in rockchip_sfc_wait_rxfifo_ready()
275 dev_dbg(sfc->dev, "sfc wait rx fifo timeout\n"); in rockchip_sfc_wait_rxfifo_ready()
287 * SFC not support output DUMMY cycles right after CMD cycles, so in rockchip_sfc_adjust_op_work()
298 static int rockchip_sfc_xfer_setup(struct rockchip_sfc *sfc, in rockchip_sfc_xfer_setup() argument
317 writel(op->addr.nbytes * 8 - 1, sfc->regbase + SFC_ABIT); in rockchip_sfc_xfer_setup()
334 if (sfc->version >= SFC_VER_4) /* Clear it if no data to transfer */ in rockchip_sfc_xfer_setup()
335 writel(len, sfc->regbase + SFC_LEN_EXT); in rockchip_sfc_xfer_setup()
351 dev_dbg(sfc->dev, "sfc addr.nbytes=%x(x%d) dummy.nbytes=%x(x%d)\n", in rockchip_sfc_xfer_setup()
354 dev_dbg(sfc->dev, "sfc ctrl=%x cmd=%x addr=%llx len=%x\n", in rockchip_sfc_xfer_setup()
357 writel(ctrl, sfc->regbase + SFC_CTRL); in rockchip_sfc_xfer_setup()
358 writel(cmd, sfc->regbase + SFC_CMD); in rockchip_sfc_xfer_setup()
360 writel(op->addr.val, sfc->regbase + SFC_ADDR); in rockchip_sfc_xfer_setup()
365 static int rockchip_sfc_write_fifo(struct rockchip_sfc *sfc, const u8 *buf, int len) in rockchip_sfc_write_fifo() argument
375 tx_level = rockchip_sfc_wait_txfifo_ready(sfc, 1000); in rockchip_sfc_write_fifo()
379 iowrite32_rep(sfc->regbase + SFC_DATA, buf, write_words); in rockchip_sfc_write_fifo()
386 tx_level = rockchip_sfc_wait_txfifo_ready(sfc, 1000); in rockchip_sfc_write_fifo()
390 writel(tmp, sfc->regbase + SFC_DATA); in rockchip_sfc_write_fifo()
396 static int rockchip_sfc_read_fifo(struct rockchip_sfc *sfc, u8 *buf, int len) in rockchip_sfc_read_fifo() argument
407 rx_level = rockchip_sfc_wait_rxfifo_ready(sfc, 1000); in rockchip_sfc_read_fifo()
411 ioread32_rep(sfc->regbase + SFC_DATA, buf, read_words); in rockchip_sfc_read_fifo()
418 rx_level = rockchip_sfc_wait_rxfifo_ready(sfc, 1000); in rockchip_sfc_read_fifo()
421 tmp = readl(sfc->regbase + SFC_DATA); in rockchip_sfc_read_fifo()
428 static int rockchip_sfc_fifo_transfer_dma(struct rockchip_sfc *sfc, dma_addr_t dma_buf, size_t len) in rockchip_sfc_fifo_transfer_dma() argument
430 writel(0xFFFFFFFF, sfc->regbase + SFC_ICLR); in rockchip_sfc_fifo_transfer_dma()
431 writel((u32)dma_buf, sfc->regbase + SFC_DMA_ADDR); in rockchip_sfc_fifo_transfer_dma()
432 writel(SFC_DMA_TRIGGER_START, sfc->regbase + SFC_DMA_TRIGGER); in rockchip_sfc_fifo_transfer_dma()
437 static int rockchip_sfc_xfer_data_poll(struct rockchip_sfc *sfc, in rockchip_sfc_xfer_data_poll() argument
440 dev_dbg(sfc->dev, "sfc xfer_poll len=%x\n", len); in rockchip_sfc_xfer_data_poll()
443 return rockchip_sfc_write_fifo(sfc, op->data.buf.out, len); in rockchip_sfc_xfer_data_poll()
445 return rockchip_sfc_read_fifo(sfc, op->data.buf.in, len); in rockchip_sfc_xfer_data_poll()
448 static int rockchip_sfc_xfer_data_dma(struct rockchip_sfc *sfc, in rockchip_sfc_xfer_data_dma() argument
453 dev_dbg(sfc->dev, "sfc xfer_dma len=%x\n", len); in rockchip_sfc_xfer_data_dma()
456 memcpy(sfc->buffer, op->data.buf.out, len); in rockchip_sfc_xfer_data_dma()
458 ret = rockchip_sfc_fifo_transfer_dma(sfc, sfc->dma_buffer, len); in rockchip_sfc_xfer_data_dma()
459 if (!wait_for_completion_timeout(&sfc->cp, msecs_to_jiffies(2000))) { in rockchip_sfc_xfer_data_dma()
460 dev_err(sfc->dev, "DMA wait for transfer finish timeout\n"); in rockchip_sfc_xfer_data_dma()
463 rockchip_sfc_irq_mask(sfc, SFC_IMR_DMA); in rockchip_sfc_xfer_data_dma()
465 memcpy(op->data.buf.in, sfc->buffer, len); in rockchip_sfc_xfer_data_dma()
470 static int rockchip_sfc_xfer_done(struct rockchip_sfc *sfc, u32 timeout_us) in rockchip_sfc_xfer_done() argument
475 ret = readl_poll_timeout(sfc->regbase + SFC_SR, status, in rockchip_sfc_xfer_done()
479 dev_err(sfc->dev, "wait sfc idle timeout\n"); in rockchip_sfc_xfer_done()
480 rockchip_sfc_reset(sfc); in rockchip_sfc_xfer_done()
490 struct rockchip_sfc *sfc = spi_controller_get_devdata(mem->spi->controller); in rockchip_sfc_exec_mem_op() local
494 if (unlikely(mem->spi->max_speed_hz != sfc->frequency)) { in rockchip_sfc_exec_mem_op()
495 ret = clk_set_rate(sfc->clk, mem->spi->max_speed_hz); in rockchip_sfc_exec_mem_op()
498 sfc->frequency = mem->spi->max_speed_hz; in rockchip_sfc_exec_mem_op()
499 dev_dbg(sfc->dev, "set_freq=%dHz real_freq=%ldHz\n", in rockchip_sfc_exec_mem_op()
500 sfc->frequency, clk_get_rate(sfc->clk)); in rockchip_sfc_exec_mem_op()
504 rockchip_sfc_xfer_setup(sfc, mem, op, len); in rockchip_sfc_exec_mem_op()
506 if (likely(sfc->use_dma) && len >= SFC_DMA_TRANS_THRETHOLD) { in rockchip_sfc_exec_mem_op()
507 init_completion(&sfc->cp); in rockchip_sfc_exec_mem_op()
508 rockchip_sfc_irq_unmask(sfc, SFC_IMR_DMA); in rockchip_sfc_exec_mem_op()
509 ret = rockchip_sfc_xfer_data_dma(sfc, op, len); in rockchip_sfc_exec_mem_op()
511 ret = rockchip_sfc_xfer_data_poll(sfc, op, len); in rockchip_sfc_exec_mem_op()
515 dev_err(sfc->dev, "xfer data failed ret %d dir %d\n", ret, op->data.dir); in rockchip_sfc_exec_mem_op()
521 return rockchip_sfc_xfer_done(sfc, 100000); in rockchip_sfc_exec_mem_op()
526 struct rockchip_sfc *sfc = spi_controller_get_devdata(mem->spi->controller); in rockchip_sfc_adjust_op_size() local
528 op->data.nbytes = min(op->data.nbytes, sfc->max_iosize); in rockchip_sfc_adjust_op_size()
540 struct rockchip_sfc *sfc = dev_id; in rockchip_sfc_irq_handler() local
543 reg = readl(sfc->regbase + SFC_RISR); in rockchip_sfc_irq_handler()
546 writel_relaxed(reg, sfc->regbase + SFC_ICLR); in rockchip_sfc_irq_handler()
549 complete(&sfc->cp); in rockchip_sfc_irq_handler()
561 struct rockchip_sfc *sfc; in rockchip_sfc_probe() local
564 host = devm_spi_alloc_host(&pdev->dev, sizeof(*sfc)); in rockchip_sfc_probe()
575 sfc = spi_controller_get_devdata(host); in rockchip_sfc_probe()
576 sfc->dev = dev; in rockchip_sfc_probe()
578 sfc->regbase = devm_platform_ioremap_resource(pdev, 0); in rockchip_sfc_probe()
579 if (IS_ERR(sfc->regbase)) in rockchip_sfc_probe()
580 return PTR_ERR(sfc->regbase); in rockchip_sfc_probe()
582 sfc->clk = devm_clk_get(&pdev->dev, "clk_sfc"); in rockchip_sfc_probe()
583 if (IS_ERR(sfc->clk)) { in rockchip_sfc_probe()
584 dev_err(&pdev->dev, "Failed to get sfc interface clk\n"); in rockchip_sfc_probe()
585 return PTR_ERR(sfc->clk); in rockchip_sfc_probe()
588 sfc->hclk = devm_clk_get(&pdev->dev, "hclk_sfc"); in rockchip_sfc_probe()
589 if (IS_ERR(sfc->hclk)) { in rockchip_sfc_probe()
590 dev_err(&pdev->dev, "Failed to get sfc ahb clk\n"); in rockchip_sfc_probe()
591 return PTR_ERR(sfc->hclk); in rockchip_sfc_probe()
594 sfc->use_dma = !of_property_read_bool(sfc->dev->of_node, in rockchip_sfc_probe()
595 "rockchip,sfc-no-dma"); in rockchip_sfc_probe()
597 if (sfc->use_dma) { in rockchip_sfc_probe()
604 sfc->buffer = dmam_alloc_coherent(dev, SFC_MAX_IOSIZE_VER3, in rockchip_sfc_probe()
605 &sfc->dma_buffer, in rockchip_sfc_probe()
607 if (!sfc->buffer) in rockchip_sfc_probe()
611 ret = clk_prepare_enable(sfc->hclk); in rockchip_sfc_probe()
617 ret = clk_prepare_enable(sfc->clk); in rockchip_sfc_probe()
629 0, pdev->name, sfc); in rockchip_sfc_probe()
636 ret = rockchip_sfc_init(sfc); in rockchip_sfc_probe()
640 sfc->max_iosize = rockchip_sfc_get_max_iosize(sfc); in rockchip_sfc_probe()
641 sfc->version = rockchip_sfc_get_version(sfc); in rockchip_sfc_probe()
650 clk_disable_unprepare(sfc->clk); in rockchip_sfc_probe()
652 clk_disable_unprepare(sfc->hclk); in rockchip_sfc_probe()
660 struct rockchip_sfc *sfc = platform_get_drvdata(pdev); in rockchip_sfc_remove() local
664 clk_disable_unprepare(sfc->clk); in rockchip_sfc_remove()
665 clk_disable_unprepare(sfc->hclk); in rockchip_sfc_remove()
669 { .compatible = "rockchip,sfc"},
676 .name = "rockchip-sfc",