Lines Matching full:xspi

134 static inline u32 cdns_spi_read(struct cdns_spi *xspi, u32 offset)  in cdns_spi_read()  argument
136 return readl_relaxed(xspi->regs + offset); in cdns_spi_read()
139 static inline void cdns_spi_write(struct cdns_spi *xspi, u32 offset, u32 val) in cdns_spi_write() argument
141 writel_relaxed(val, xspi->regs + offset); in cdns_spi_write()
146 * @xspi: Pointer to the cdns_spi structure
156 static void cdns_spi_init_hw(struct cdns_spi *xspi, bool is_target) in cdns_spi_init_hw() argument
163 if (xspi->is_decoded_cs) in cdns_spi_init_hw()
166 cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE); in cdns_spi_init_hw()
167 cdns_spi_write(xspi, CDNS_SPI_IDR, CDNS_SPI_IXR_ALL); in cdns_spi_init_hw()
170 while (cdns_spi_read(xspi, CDNS_SPI_ISR) & CDNS_SPI_IXR_RXNEMTY) in cdns_spi_init_hw()
171 cdns_spi_read(xspi, CDNS_SPI_RXD); in cdns_spi_init_hw()
173 cdns_spi_write(xspi, CDNS_SPI_ISR, CDNS_SPI_IXR_ALL); in cdns_spi_init_hw()
174 cdns_spi_write(xspi, CDNS_SPI_CR, ctrl_reg); in cdns_spi_init_hw()
175 cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_ENABLE); in cdns_spi_init_hw()
185 struct cdns_spi *xspi = spi_controller_get_devdata(spi->controller); in cdns_spi_chipselect() local
188 ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR); in cdns_spi_chipselect()
196 if (!(xspi->is_decoded_cs)) in cdns_spi_chipselect()
205 cdns_spi_write(xspi, CDNS_SPI_CR, ctrl_reg); in cdns_spi_chipselect()
216 struct cdns_spi *xspi = spi_controller_get_devdata(spi->controller); in cdns_spi_config_clock_mode() local
219 new_ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR); in cdns_spi_config_clock_mode()
236 cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE); in cdns_spi_config_clock_mode()
237 cdns_spi_write(xspi, CDNS_SPI_CR, new_ctrl_reg); in cdns_spi_config_clock_mode()
238 cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_ENABLE); in cdns_spi_config_clock_mode()
259 struct cdns_spi *xspi = spi_controller_get_devdata(spi->controller); in cdns_spi_config_clock_freq() local
263 frequency = xspi->clk_rate; in cdns_spi_config_clock_freq()
265 ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR); in cdns_spi_config_clock_freq()
268 if (xspi->speed_hz != transfer->speed_hz) { in cdns_spi_config_clock_freq()
278 xspi->speed_hz = frequency / (2 << baud_rate_val); in cdns_spi_config_clock_freq()
280 cdns_spi_write(xspi, CDNS_SPI_CR, ctrl_reg); in cdns_spi_config_clock_freq()
297 struct cdns_spi *xspi = spi_controller_get_devdata(spi->controller); in cdns_spi_setup_transfer() local
303 xspi->speed_hz); in cdns_spi_setup_transfer()
310 * @xspi: Pointer to the cdns_spi structure
314 static void cdns_spi_process_fifo(struct cdns_spi *xspi, int ntx, int nrx) in cdns_spi_process_fifo() argument
316 ntx = clamp(ntx, 0, xspi->tx_bytes); in cdns_spi_process_fifo()
317 nrx = clamp(nrx, 0, xspi->rx_bytes); in cdns_spi_process_fifo()
319 xspi->tx_bytes -= ntx; in cdns_spi_process_fifo()
320 xspi->rx_bytes -= nrx; in cdns_spi_process_fifo()
324 u8 data = cdns_spi_read(xspi, CDNS_SPI_RXD); in cdns_spi_process_fifo()
326 if (xspi->rxbuf) in cdns_spi_process_fifo()
327 *xspi->rxbuf++ = data; in cdns_spi_process_fifo()
333 if (xspi->txbuf) in cdns_spi_process_fifo()
334 cdns_spi_write(xspi, CDNS_SPI_TXD, *xspi->txbuf++); in cdns_spi_process_fifo()
336 cdns_spi_write(xspi, CDNS_SPI_TXD, 0); in cdns_spi_process_fifo()
347 * @dev_id: Pointer to the xspi structure
361 struct cdns_spi *xspi = spi_controller_get_devdata(ctlr); in cdns_spi_irq() local
366 intr_status = cdns_spi_read(xspi, CDNS_SPI_ISR); in cdns_spi_irq()
367 cdns_spi_write(xspi, CDNS_SPI_ISR, intr_status); in cdns_spi_irq()
374 cdns_spi_write(xspi, CDNS_SPI_IDR, CDNS_SPI_IXR_DEFAULT); in cdns_spi_irq()
378 int threshold = cdns_spi_read(xspi, CDNS_SPI_THLD); in cdns_spi_irq()
379 int trans_cnt = xspi->rx_bytes - xspi->tx_bytes; in cdns_spi_irq()
387 if (xspi->tx_bytes < xspi->tx_fifo_depth >> 1) in cdns_spi_irq()
388 cdns_spi_write(xspi, CDNS_SPI_THLD, 1); in cdns_spi_irq()
390 if (xspi->tx_bytes) { in cdns_spi_irq()
391 cdns_spi_process_fifo(xspi, trans_cnt, trans_cnt); in cdns_spi_irq()
398 cdns_spi_process_fifo(xspi, 0, trans_cnt); in cdns_spi_irq()
399 cdns_spi_write(xspi, CDNS_SPI_IDR, in cdns_spi_irq()
434 struct cdns_spi *xspi = spi_controller_get_devdata(ctlr); in cdns_transfer_one() local
436 xspi->txbuf = transfer->tx_buf; in cdns_transfer_one()
437 xspi->rxbuf = transfer->rx_buf; in cdns_transfer_one()
438 xspi->tx_bytes = transfer->len; in cdns_transfer_one()
439 xspi->rx_bytes = transfer->len; in cdns_transfer_one()
447 if (xspi->tx_bytes > xspi->tx_fifo_depth) in cdns_transfer_one()
448 cdns_spi_write(xspi, CDNS_SPI_THLD, xspi->tx_fifo_depth >> 1); in cdns_transfer_one()
451 /* When xspi in busy condition, bytes may send failed, in cdns_transfer_one()
454 if (cdns_spi_read(xspi, CDNS_SPI_ISR) & CDNS_SPI_IXR_TXFULL) in cdns_transfer_one()
457 cdns_spi_process_fifo(xspi, xspi->tx_fifo_depth, 0); in cdns_transfer_one()
459 cdns_spi_write(xspi, CDNS_SPI_IER, CDNS_SPI_IXR_DEFAULT); in cdns_transfer_one()
474 struct cdns_spi *xspi = spi_controller_get_devdata(ctlr); in cdns_prepare_transfer_hardware() local
476 cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_ENABLE); in cdns_prepare_transfer_hardware()
493 struct cdns_spi *xspi = spi_controller_get_devdata(ctlr); in cdns_unprepare_transfer_hardware() local
495 unsigned int cnt = xspi->tx_fifo_depth; in cdns_unprepare_transfer_hardware()
499 cdns_spi_read(xspi, CDNS_SPI_RXD); in cdns_unprepare_transfer_hardware()
503 ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR); in cdns_unprepare_transfer_hardware()
506 cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE); in cdns_unprepare_transfer_hardware()
509 cdns_spi_write(xspi, CDNS_SPI_THLD, 0x1); in cdns_unprepare_transfer_hardware()
515 * @xspi: Pointer to the cdns_spi structure
521 static void cdns_spi_detect_fifo_depth(struct cdns_spi *xspi) in cdns_spi_detect_fifo_depth() argument
524 cdns_spi_write(xspi, CDNS_SPI_THLD, 0xffff); in cdns_spi_detect_fifo_depth()
525 xspi->tx_fifo_depth = cdns_spi_read(xspi, CDNS_SPI_THLD) + 1; in cdns_spi_detect_fifo_depth()
528 cdns_spi_write(xspi, CDNS_SPI_THLD, 0x1); in cdns_spi_detect_fifo_depth()
541 struct cdns_spi *xspi = spi_controller_get_devdata(ctlr); in cdns_target_abort() local
544 intr_status = cdns_spi_read(xspi, CDNS_SPI_ISR); in cdns_target_abort()
545 cdns_spi_write(xspi, CDNS_SPI_ISR, intr_status); in cdns_target_abort()
546 cdns_spi_write(xspi, CDNS_SPI_IDR, (CDNS_SPI_IXR_MODF | CDNS_SPI_IXR_RXNEMTY)); in cdns_target_abort()
564 struct cdns_spi *xspi; in cdns_spi_probe() local
570 ctlr = spi_alloc_target(&pdev->dev, sizeof(*xspi)); in cdns_spi_probe()
572 ctlr = spi_alloc_host(&pdev->dev, sizeof(*xspi)); in cdns_spi_probe()
577 xspi = spi_controller_get_devdata(ctlr); in cdns_spi_probe()
581 xspi->regs = devm_platform_ioremap_resource(pdev, 0); in cdns_spi_probe()
582 if (IS_ERR(xspi->regs)) { in cdns_spi_probe()
583 ret = PTR_ERR(xspi->regs); in cdns_spi_probe()
587 xspi->pclk = devm_clk_get_enabled(&pdev->dev, "pclk"); in cdns_spi_probe()
588 if (IS_ERR(xspi->pclk)) { in cdns_spi_probe()
590 ret = PTR_ERR(xspi->pclk); in cdns_spi_probe()
594 xspi->rstc = devm_reset_control_get_optional_exclusive(&pdev->dev, "spi"); in cdns_spi_probe()
595 if (IS_ERR(xspi->rstc)) { in cdns_spi_probe()
596 ret = dev_err_probe(&pdev->dev, PTR_ERR(xspi->rstc), in cdns_spi_probe()
601 reset_control_assert(xspi->rstc); in cdns_spi_probe()
602 reset_control_deassert(xspi->rstc); in cdns_spi_probe()
604 xspi->ref_clk = devm_clk_get_enabled(&pdev->dev, "ref_clk"); in cdns_spi_probe()
605 if (IS_ERR(xspi->ref_clk)) { in cdns_spi_probe()
607 ret = PTR_ERR(xspi->ref_clk); in cdns_spi_probe()
625 &xspi->is_decoded_cs); in cdns_spi_probe()
627 xspi->is_decoded_cs = 0; in cdns_spi_probe()
630 cdns_spi_detect_fifo_depth(xspi); in cdns_spi_probe()
633 cdns_spi_init_hw(xspi, spi_controller_is_target(ctlr)); in cdns_spi_probe()
661 xspi->clk_rate = clk_get_rate(xspi->ref_clk); in cdns_spi_probe()
663 ctlr->max_speed_hz = xspi->clk_rate / 4; in cdns_spi_probe()
664 xspi->speed_hz = ctlr->max_speed_hz; in cdns_spi_probe()
700 struct cdns_spi *xspi = spi_controller_get_devdata(ctlr); in cdns_spi_remove() local
702 cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE); in cdns_spi_remove()
739 struct cdns_spi *xspi = spi_controller_get_devdata(ctlr); in cdns_spi_resume() local
741 cdns_spi_init_hw(xspi, spi_controller_is_target(ctlr)); in cdns_spi_resume()
756 struct cdns_spi *xspi = spi_controller_get_devdata(ctlr); in cdns_spi_runtime_resume() local
759 ret = clk_prepare_enable(xspi->pclk); in cdns_spi_runtime_resume()
765 ret = clk_prepare_enable(xspi->ref_clk); in cdns_spi_runtime_resume()
768 clk_disable_unprepare(xspi->pclk); in cdns_spi_runtime_resume()
785 struct cdns_spi *xspi = spi_controller_get_devdata(ctlr); in cdns_spi_runtime_suspend() local
787 clk_disable_unprepare(xspi->ref_clk); in cdns_spi_runtime_suspend()
788 clk_disable_unprepare(xspi->pclk); in cdns_spi_runtime_suspend()