Lines Matching full:sfc
190 static int rockchip_sfc_reset(struct rockchip_sfc *sfc) in rockchip_sfc_reset() argument
195 writel_relaxed(SFC_RCVR_RESET, sfc->regbase + SFC_RCVR); in rockchip_sfc_reset()
197 err = readl_poll_timeout(sfc->regbase + SFC_RCVR, status, in rockchip_sfc_reset()
201 dev_err(sfc->dev, "SFC reset never finished\n"); in rockchip_sfc_reset()
204 writel_relaxed(0xFFFFFFFF, sfc->regbase + SFC_ICLR); in rockchip_sfc_reset()
206 dev_dbg(sfc->dev, "reset\n"); in rockchip_sfc_reset()
211 static u16 rockchip_sfc_get_version(struct rockchip_sfc *sfc) in rockchip_sfc_get_version() argument
213 return (u16)(readl(sfc->regbase + SFC_VER) & 0xffff); in rockchip_sfc_get_version()
216 static u32 rockchip_sfc_get_max_iosize(struct rockchip_sfc *sfc) in rockchip_sfc_get_max_iosize() argument
221 static int rockchip_sfc_clk_set_rate(struct rockchip_sfc *sfc, unsigned long speed) in rockchip_sfc_clk_set_rate() argument
223 if (sfc->version >= SFC_VER_8) in rockchip_sfc_clk_set_rate()
224 return clk_set_rate(sfc->clk, speed * 2); in rockchip_sfc_clk_set_rate()
226 return clk_set_rate(sfc->clk, speed); in rockchip_sfc_clk_set_rate()
229 static unsigned long rockchip_sfc_clk_get_rate(struct rockchip_sfc *sfc) in rockchip_sfc_clk_get_rate() argument
231 if (sfc->version >= SFC_VER_8) in rockchip_sfc_clk_get_rate()
232 return clk_get_rate(sfc->clk) / 2; in rockchip_sfc_clk_get_rate()
234 return clk_get_rate(sfc->clk); in rockchip_sfc_clk_get_rate()
237 static void rockchip_sfc_irq_unmask(struct rockchip_sfc *sfc, u32 mask) in rockchip_sfc_irq_unmask() argument
242 reg = readl(sfc->regbase + SFC_IMR); in rockchip_sfc_irq_unmask()
244 writel(reg, sfc->regbase + SFC_IMR); in rockchip_sfc_irq_unmask()
247 static void rockchip_sfc_irq_mask(struct rockchip_sfc *sfc, u32 mask) in rockchip_sfc_irq_mask() argument
252 reg = readl(sfc->regbase + SFC_IMR); in rockchip_sfc_irq_mask()
254 writel(reg, sfc->regbase + SFC_IMR); in rockchip_sfc_irq_mask()
257 static int rockchip_sfc_init(struct rockchip_sfc *sfc) in rockchip_sfc_init() argument
259 writel(0, sfc->regbase + SFC_CTRL); in rockchip_sfc_init()
260 writel(0xFFFFFFFF, sfc->regbase + SFC_ICLR); in rockchip_sfc_init()
261 rockchip_sfc_irq_mask(sfc, 0xFFFFFFFF); in rockchip_sfc_init()
262 if (rockchip_sfc_get_version(sfc) >= SFC_VER_4) in rockchip_sfc_init()
263 writel(SFC_LEN_CTRL_TRB_SEL, sfc->regbase + SFC_LEN_CTRL); in rockchip_sfc_init()
268 static int rockchip_sfc_wait_txfifo_ready(struct rockchip_sfc *sfc, u32 timeout_us) in rockchip_sfc_wait_txfifo_ready() argument
273 ret = readl_poll_timeout(sfc->regbase + SFC_FSR, status, in rockchip_sfc_wait_txfifo_ready()
277 dev_dbg(sfc->dev, "sfc wait tx fifo timeout\n"); in rockchip_sfc_wait_txfifo_ready()
285 static int rockchip_sfc_wait_rxfifo_ready(struct rockchip_sfc *sfc, u32 timeout_us) in rockchip_sfc_wait_rxfifo_ready() argument
290 ret = readl_poll_timeout(sfc->regbase + SFC_FSR, status, in rockchip_sfc_wait_rxfifo_ready()
294 dev_dbg(sfc->dev, "sfc wait rx fifo timeout\n"); in rockchip_sfc_wait_rxfifo_ready()
306 * SFC not support output DUMMY cycles right after CMD cycles, so in rockchip_sfc_adjust_op_work()
317 static int rockchip_sfc_xfer_setup(struct rockchip_sfc *sfc, in rockchip_sfc_xfer_setup() argument
338 sfc->regbase + cs * SFC_CS1_REG_OFFSET + SFC_ABIT); in rockchip_sfc_xfer_setup()
355 if (sfc->version >= SFC_VER_4) /* Clear it if no data to transfer */ in rockchip_sfc_xfer_setup()
356 writel(len, sfc->regbase + SFC_LEN_EXT); in rockchip_sfc_xfer_setup()
372 dev_dbg(sfc->dev, "sfc addr.nbytes=%x(x%d) dummy.nbytes=%x(x%d)\n", in rockchip_sfc_xfer_setup()
375 dev_dbg(sfc->dev, "sfc ctrl=%x cmd=%x addr=%llx len=%x\n", in rockchip_sfc_xfer_setup()
378 writel(ctrl, sfc->regbase + cs * SFC_CS1_REG_OFFSET + SFC_CTRL); in rockchip_sfc_xfer_setup()
379 writel(cmd, sfc->regbase + SFC_CMD); in rockchip_sfc_xfer_setup()
381 writel(op->addr.val, sfc->regbase + SFC_ADDR); in rockchip_sfc_xfer_setup()
386 static int rockchip_sfc_write_fifo(struct rockchip_sfc *sfc, const u8 *buf, int len) in rockchip_sfc_write_fifo() argument
396 tx_level = rockchip_sfc_wait_txfifo_ready(sfc, 1000); in rockchip_sfc_write_fifo()
400 iowrite32_rep(sfc->regbase + SFC_DATA, buf, write_words); in rockchip_sfc_write_fifo()
407 tx_level = rockchip_sfc_wait_txfifo_ready(sfc, 1000); in rockchip_sfc_write_fifo()
411 writel(tmp, sfc->regbase + SFC_DATA); in rockchip_sfc_write_fifo()
417 static int rockchip_sfc_read_fifo(struct rockchip_sfc *sfc, u8 *buf, int len) in rockchip_sfc_read_fifo() argument
428 rx_level = rockchip_sfc_wait_rxfifo_ready(sfc, 1000); in rockchip_sfc_read_fifo()
432 ioread32_rep(sfc->regbase + SFC_DATA, buf, read_words); in rockchip_sfc_read_fifo()
439 rx_level = rockchip_sfc_wait_rxfifo_ready(sfc, 1000); in rockchip_sfc_read_fifo()
442 tmp = readl(sfc->regbase + SFC_DATA); in rockchip_sfc_read_fifo()
449 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
451 writel(0xFFFFFFFF, sfc->regbase + SFC_ICLR); in rockchip_sfc_fifo_transfer_dma()
452 writel((u32)dma_buf, sfc->regbase + SFC_DMA_ADDR); in rockchip_sfc_fifo_transfer_dma()
453 writel(SFC_DMA_TRIGGER_START, sfc->regbase + SFC_DMA_TRIGGER); in rockchip_sfc_fifo_transfer_dma()
458 static int rockchip_sfc_xfer_data_poll(struct rockchip_sfc *sfc, in rockchip_sfc_xfer_data_poll() argument
461 dev_dbg(sfc->dev, "sfc xfer_poll len=%x\n", len); in rockchip_sfc_xfer_data_poll()
464 return rockchip_sfc_write_fifo(sfc, op->data.buf.out, len); in rockchip_sfc_xfer_data_poll()
466 return rockchip_sfc_read_fifo(sfc, op->data.buf.in, len); in rockchip_sfc_xfer_data_poll()
469 static int rockchip_sfc_xfer_data_dma(struct rockchip_sfc *sfc, in rockchip_sfc_xfer_data_dma() argument
474 dev_dbg(sfc->dev, "sfc xfer_dma len=%x\n", len); in rockchip_sfc_xfer_data_dma()
477 memcpy(sfc->buffer, op->data.buf.out, len); in rockchip_sfc_xfer_data_dma()
478 dma_sync_single_for_device(sfc->dev, sfc->dma_buffer, len, DMA_TO_DEVICE); in rockchip_sfc_xfer_data_dma()
481 ret = rockchip_sfc_fifo_transfer_dma(sfc, sfc->dma_buffer, len); in rockchip_sfc_xfer_data_dma()
482 if (!wait_for_completion_timeout(&sfc->cp, msecs_to_jiffies(2000))) { in rockchip_sfc_xfer_data_dma()
483 dev_err(sfc->dev, "DMA wait for transfer finish timeout\n"); in rockchip_sfc_xfer_data_dma()
486 rockchip_sfc_irq_mask(sfc, SFC_IMR_DMA); in rockchip_sfc_xfer_data_dma()
489 dma_sync_single_for_cpu(sfc->dev, sfc->dma_buffer, len, DMA_FROM_DEVICE); in rockchip_sfc_xfer_data_dma()
490 memcpy(op->data.buf.in, sfc->buffer, len); in rockchip_sfc_xfer_data_dma()
496 static int rockchip_sfc_xfer_done(struct rockchip_sfc *sfc, u32 timeout_us) in rockchip_sfc_xfer_done() argument
505 ret = readl_poll_timeout(sfc->regbase + SFC_SR, status, in rockchip_sfc_xfer_done()
511 ret = readl_poll_timeout(sfc->regbase + SFC_SR, status, in rockchip_sfc_xfer_done()
515 dev_err(sfc->dev, "wait sfc idle timeout\n"); in rockchip_sfc_xfer_done()
516 rockchip_sfc_reset(sfc); in rockchip_sfc_xfer_done()
526 struct rockchip_sfc *sfc = spi_controller_get_devdata(mem->spi->controller); in rockchip_sfc_exec_mem_op() local
531 ret = pm_runtime_get_sync(sfc->dev); in rockchip_sfc_exec_mem_op()
533 pm_runtime_put_noidle(sfc->dev); in rockchip_sfc_exec_mem_op()
537 if (unlikely(op->max_freq != sfc->speed[cs]) && in rockchip_sfc_exec_mem_op()
538 !has_acpi_companion(sfc->dev)) { in rockchip_sfc_exec_mem_op()
539 ret = rockchip_sfc_clk_set_rate(sfc, op->max_freq); in rockchip_sfc_exec_mem_op()
542 sfc->speed[cs] = op->max_freq; in rockchip_sfc_exec_mem_op()
543 dev_dbg(sfc->dev, "set_freq=%dHz real_freq=%ldHz\n", in rockchip_sfc_exec_mem_op()
544 sfc->speed[cs], rockchip_sfc_clk_get_rate(sfc)); in rockchip_sfc_exec_mem_op()
548 rockchip_sfc_xfer_setup(sfc, mem, op, len); in rockchip_sfc_exec_mem_op()
550 if (likely(sfc->use_dma) && len >= SFC_DMA_TRANS_THRETHOLD && !(len & 0x3)) { in rockchip_sfc_exec_mem_op()
551 init_completion(&sfc->cp); in rockchip_sfc_exec_mem_op()
552 rockchip_sfc_irq_unmask(sfc, SFC_IMR_DMA); in rockchip_sfc_exec_mem_op()
553 ret = rockchip_sfc_xfer_data_dma(sfc, op, len); in rockchip_sfc_exec_mem_op()
555 ret = rockchip_sfc_xfer_data_poll(sfc, op, len); in rockchip_sfc_exec_mem_op()
559 dev_err(sfc->dev, "xfer data failed ret %d dir %d\n", ret, op->data.dir); in rockchip_sfc_exec_mem_op()
566 ret = rockchip_sfc_xfer_done(sfc, 100000); in rockchip_sfc_exec_mem_op()
568 pm_runtime_mark_last_busy(sfc->dev); in rockchip_sfc_exec_mem_op()
569 pm_runtime_put_autosuspend(sfc->dev); in rockchip_sfc_exec_mem_op()
576 struct rockchip_sfc *sfc = spi_controller_get_devdata(mem->spi->controller); in rockchip_sfc_adjust_op_size() local
578 op->data.nbytes = min(op->data.nbytes, sfc->max_iosize); in rockchip_sfc_adjust_op_size()
594 struct rockchip_sfc *sfc = dev_id; in rockchip_sfc_irq_handler() local
597 reg = readl(sfc->regbase + SFC_RISR); in rockchip_sfc_irq_handler()
600 writel_relaxed(reg, sfc->regbase + SFC_ICLR); in rockchip_sfc_irq_handler()
603 complete(&sfc->cp); in rockchip_sfc_irq_handler()
615 struct rockchip_sfc *sfc; in rockchip_sfc_probe() local
619 host = devm_spi_alloc_host(&pdev->dev, sizeof(*sfc)); in rockchip_sfc_probe()
631 sfc = spi_controller_get_devdata(host); in rockchip_sfc_probe()
632 sfc->dev = dev; in rockchip_sfc_probe()
633 sfc->host = host; in rockchip_sfc_probe()
635 sfc->regbase = devm_platform_ioremap_resource(pdev, 0); in rockchip_sfc_probe()
636 if (IS_ERR(sfc->regbase)) in rockchip_sfc_probe()
637 return PTR_ERR(sfc->regbase); in rockchip_sfc_probe()
640 sfc->clk = devm_clk_get(&pdev->dev, "clk_sfc"); in rockchip_sfc_probe()
641 if (IS_ERR(sfc->clk)) in rockchip_sfc_probe()
642 return dev_err_probe(&pdev->dev, PTR_ERR(sfc->clk), in rockchip_sfc_probe()
643 "Failed to get sfc interface clk\n"); in rockchip_sfc_probe()
646 sfc->hclk = devm_clk_get(&pdev->dev, "hclk_sfc"); in rockchip_sfc_probe()
647 if (IS_ERR(sfc->hclk)) in rockchip_sfc_probe()
648 return dev_err_probe(&pdev->dev, PTR_ERR(sfc->hclk), in rockchip_sfc_probe()
649 "Failed to get sfc ahb clk\n"); in rockchip_sfc_probe()
657 sfc->speed[i] = val; in rockchip_sfc_probe()
660 sfc->use_dma = !of_property_read_bool(sfc->dev->of_node, "rockchip,sfc-no-dma"); in rockchip_sfc_probe()
662 ret = clk_prepare_enable(sfc->hclk); in rockchip_sfc_probe()
668 ret = clk_prepare_enable(sfc->clk); in rockchip_sfc_probe()
680 0, pdev->name, sfc); in rockchip_sfc_probe()
686 platform_set_drvdata(pdev, sfc); in rockchip_sfc_probe()
688 ret = rockchip_sfc_init(sfc); in rockchip_sfc_probe()
692 sfc->version = rockchip_sfc_get_version(sfc); in rockchip_sfc_probe()
693 sfc->max_iosize = rockchip_sfc_get_max_iosize(sfc); in rockchip_sfc_probe()
701 if (sfc->use_dma) { in rockchip_sfc_probe()
702 sfc->buffer = (u8 *)__get_free_pages(GFP_KERNEL | GFP_DMA32, in rockchip_sfc_probe()
703 get_order(sfc->max_iosize)); in rockchip_sfc_probe()
704 if (!sfc->buffer) { in rockchip_sfc_probe()
708 sfc->dma_buffer = virt_to_phys(sfc->buffer); in rockchip_sfc_probe()
720 free_pages((unsigned long)sfc->buffer, get_order(sfc->max_iosize)); in rockchip_sfc_probe()
728 clk_disable_unprepare(sfc->clk); in rockchip_sfc_probe()
730 clk_disable_unprepare(sfc->hclk); in rockchip_sfc_probe()
737 struct rockchip_sfc *sfc = platform_get_drvdata(pdev); in rockchip_sfc_remove() local
738 struct spi_controller *host = sfc->host; in rockchip_sfc_remove()
741 free_pages((unsigned long)sfc->buffer, get_order(sfc->max_iosize)); in rockchip_sfc_remove()
743 clk_disable_unprepare(sfc->clk); in rockchip_sfc_remove()
744 clk_disable_unprepare(sfc->hclk); in rockchip_sfc_remove()
750 struct rockchip_sfc *sfc = dev_get_drvdata(dev); in rockchip_sfc_runtime_suspend() local
752 clk_disable_unprepare(sfc->clk); in rockchip_sfc_runtime_suspend()
753 clk_disable_unprepare(sfc->hclk); in rockchip_sfc_runtime_suspend()
760 struct rockchip_sfc *sfc = dev_get_drvdata(dev); in rockchip_sfc_runtime_resume() local
763 ret = clk_prepare_enable(sfc->hclk); in rockchip_sfc_runtime_resume()
767 ret = clk_prepare_enable(sfc->clk); in rockchip_sfc_runtime_resume()
769 clk_disable_unprepare(sfc->hclk); in rockchip_sfc_runtime_resume()
785 struct rockchip_sfc *sfc = dev_get_drvdata(dev); in rockchip_sfc_resume() local
800 rockchip_sfc_init(sfc); in rockchip_sfc_resume()
816 { .compatible = "rockchip,sfc"},
823 .name = "rockchip-sfc",