Lines Matching refs:xspi
129 static inline u32 cdns_spi_read(struct cdns_spi *xspi, u32 offset) in cdns_spi_read() argument
131 return readl_relaxed(xspi->regs + offset); in cdns_spi_read()
134 static inline void cdns_spi_write(struct cdns_spi *xspi, u32 offset, u32 val) in cdns_spi_write() argument
136 writel_relaxed(val, xspi->regs + offset); in cdns_spi_write()
150 static void cdns_spi_init_hw(struct cdns_spi *xspi) in cdns_spi_init_hw() argument
154 if (xspi->is_decoded_cs) in cdns_spi_init_hw()
157 cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE); in cdns_spi_init_hw()
158 cdns_spi_write(xspi, CDNS_SPI_IDR, CDNS_SPI_IXR_ALL); in cdns_spi_init_hw()
161 while (cdns_spi_read(xspi, CDNS_SPI_ISR) & CDNS_SPI_IXR_RXNEMTY) in cdns_spi_init_hw()
162 cdns_spi_read(xspi, CDNS_SPI_RXD); in cdns_spi_init_hw()
164 cdns_spi_write(xspi, CDNS_SPI_ISR, CDNS_SPI_IXR_ALL); in cdns_spi_init_hw()
165 cdns_spi_write(xspi, CDNS_SPI_CR, ctrl_reg); in cdns_spi_init_hw()
166 cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_ENABLE); in cdns_spi_init_hw()
176 struct cdns_spi *xspi = spi_master_get_devdata(spi->master); in cdns_spi_chipselect() local
179 ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR); in cdns_spi_chipselect()
187 if (!(xspi->is_decoded_cs)) in cdns_spi_chipselect()
196 cdns_spi_write(xspi, CDNS_SPI_CR, ctrl_reg); in cdns_spi_chipselect()
207 struct cdns_spi *xspi = spi_master_get_devdata(spi->master); in cdns_spi_config_clock_mode() local
210 new_ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR); in cdns_spi_config_clock_mode()
227 cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE); in cdns_spi_config_clock_mode()
228 cdns_spi_write(xspi, CDNS_SPI_CR, new_ctrl_reg); in cdns_spi_config_clock_mode()
229 cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_ENABLE); in cdns_spi_config_clock_mode()
250 struct cdns_spi *xspi = spi_master_get_devdata(spi->master); in cdns_spi_config_clock_freq() local
254 frequency = xspi->clk_rate; in cdns_spi_config_clock_freq()
256 ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR); in cdns_spi_config_clock_freq()
259 if (xspi->speed_hz != transfer->speed_hz) { in cdns_spi_config_clock_freq()
269 xspi->speed_hz = frequency / (2 << baud_rate_val); in cdns_spi_config_clock_freq()
271 cdns_spi_write(xspi, CDNS_SPI_CR, ctrl_reg); in cdns_spi_config_clock_freq()
288 struct cdns_spi *xspi = spi_master_get_devdata(spi->master); in cdns_spi_setup_transfer() local
294 xspi->speed_hz); in cdns_spi_setup_transfer()
303 static void cdns_spi_fill_tx_fifo(struct cdns_spi *xspi) in cdns_spi_fill_tx_fifo() argument
307 while ((trans_cnt < xspi->tx_fifo_depth) && in cdns_spi_fill_tx_fifo()
308 (xspi->tx_bytes > 0)) { in cdns_spi_fill_tx_fifo()
313 if (cdns_spi_read(xspi, CDNS_SPI_ISR) & in cdns_spi_fill_tx_fifo()
317 if (xspi->txbuf) in cdns_spi_fill_tx_fifo()
318 cdns_spi_write(xspi, CDNS_SPI_TXD, *xspi->txbuf++); in cdns_spi_fill_tx_fifo()
320 cdns_spi_write(xspi, CDNS_SPI_TXD, 0); in cdns_spi_fill_tx_fifo()
322 xspi->tx_bytes--; in cdns_spi_fill_tx_fifo()
344 struct cdns_spi *xspi = spi_master_get_devdata(master); in cdns_spi_irq() local
349 intr_status = cdns_spi_read(xspi, CDNS_SPI_ISR); in cdns_spi_irq()
350 cdns_spi_write(xspi, CDNS_SPI_ISR, intr_status); in cdns_spi_irq()
357 cdns_spi_write(xspi, CDNS_SPI_IDR, CDNS_SPI_IXR_DEFAULT); in cdns_spi_irq()
363 trans_cnt = xspi->rx_bytes - xspi->tx_bytes; in cdns_spi_irq()
369 data = cdns_spi_read(xspi, CDNS_SPI_RXD); in cdns_spi_irq()
370 if (xspi->rxbuf) in cdns_spi_irq()
371 *xspi->rxbuf++ = data; in cdns_spi_irq()
373 xspi->rx_bytes--; in cdns_spi_irq()
377 if (xspi->tx_bytes) { in cdns_spi_irq()
379 cdns_spi_fill_tx_fifo(xspi); in cdns_spi_irq()
382 cdns_spi_write(xspi, CDNS_SPI_IDR, in cdns_spi_irq()
415 struct cdns_spi *xspi = spi_master_get_devdata(master); in cdns_transfer_one() local
417 xspi->txbuf = transfer->tx_buf; in cdns_transfer_one()
418 xspi->rxbuf = transfer->rx_buf; in cdns_transfer_one()
419 xspi->tx_bytes = transfer->len; in cdns_transfer_one()
420 xspi->rx_bytes = transfer->len; in cdns_transfer_one()
423 cdns_spi_fill_tx_fifo(xspi); in cdns_transfer_one()
426 cdns_spi_write(xspi, CDNS_SPI_IER, CDNS_SPI_IXR_DEFAULT); in cdns_transfer_one()
441 struct cdns_spi *xspi = spi_master_get_devdata(master); in cdns_prepare_transfer_hardware() local
443 cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_ENABLE); in cdns_prepare_transfer_hardware()
459 struct cdns_spi *xspi = spi_master_get_devdata(master); in cdns_unprepare_transfer_hardware() local
463 ctrl_reg = cdns_spi_read(xspi, CDNS_SPI_CR); in cdns_unprepare_transfer_hardware()
466 cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE); in cdns_unprepare_transfer_hardware()
479 static void cdns_spi_detect_fifo_depth(struct cdns_spi *xspi) in cdns_spi_detect_fifo_depth() argument
482 cdns_spi_write(xspi, CDNS_SPI_THLD, 0xffff); in cdns_spi_detect_fifo_depth()
483 xspi->tx_fifo_depth = cdns_spi_read(xspi, CDNS_SPI_THLD) + 1; in cdns_spi_detect_fifo_depth()
486 cdns_spi_write(xspi, CDNS_SPI_THLD, 0x1); in cdns_spi_detect_fifo_depth()
501 struct cdns_spi *xspi; in cdns_spi_probe() local
504 master = spi_alloc_master(&pdev->dev, sizeof(*xspi)); in cdns_spi_probe()
508 xspi = spi_master_get_devdata(master); in cdns_spi_probe()
512 xspi->regs = devm_platform_ioremap_resource(pdev, 0); in cdns_spi_probe()
513 if (IS_ERR(xspi->regs)) { in cdns_spi_probe()
514 ret = PTR_ERR(xspi->regs); in cdns_spi_probe()
518 xspi->pclk = devm_clk_get(&pdev->dev, "pclk"); in cdns_spi_probe()
519 if (IS_ERR(xspi->pclk)) { in cdns_spi_probe()
521 ret = PTR_ERR(xspi->pclk); in cdns_spi_probe()
525 xspi->ref_clk = devm_clk_get(&pdev->dev, "ref_clk"); in cdns_spi_probe()
526 if (IS_ERR(xspi->ref_clk)) { in cdns_spi_probe()
528 ret = PTR_ERR(xspi->ref_clk); in cdns_spi_probe()
532 ret = clk_prepare_enable(xspi->pclk); in cdns_spi_probe()
538 ret = clk_prepare_enable(xspi->ref_clk); in cdns_spi_probe()
557 &xspi->is_decoded_cs); in cdns_spi_probe()
559 xspi->is_decoded_cs = 0; in cdns_spi_probe()
561 cdns_spi_detect_fifo_depth(xspi); in cdns_spi_probe()
564 cdns_spi_init_hw(xspi); in cdns_spi_probe()
589 xspi->clk_rate = clk_get_rate(xspi->ref_clk); in cdns_spi_probe()
591 master->max_speed_hz = xspi->clk_rate / 4; in cdns_spi_probe()
592 xspi->speed_hz = master->max_speed_hz; in cdns_spi_probe()
610 clk_disable_unprepare(xspi->ref_clk); in cdns_spi_probe()
612 clk_disable_unprepare(xspi->pclk); in cdns_spi_probe()
631 struct cdns_spi *xspi = spi_master_get_devdata(master); in cdns_spi_remove() local
633 cdns_spi_write(xspi, CDNS_SPI_ER, CDNS_SPI_ER_DISABLE); in cdns_spi_remove()
635 clk_disable_unprepare(xspi->ref_clk); in cdns_spi_remove()
636 clk_disable_unprepare(xspi->pclk); in cdns_spi_remove()
672 struct cdns_spi *xspi = spi_master_get_devdata(master); in cdns_spi_resume() local
674 cdns_spi_init_hw(xspi); in cdns_spi_resume()
689 struct cdns_spi *xspi = spi_master_get_devdata(master); in cdns_spi_runtime_resume() local
692 ret = clk_prepare_enable(xspi->pclk); in cdns_spi_runtime_resume()
698 ret = clk_prepare_enable(xspi->ref_clk); in cdns_spi_runtime_resume()
701 clk_disable_unprepare(xspi->pclk); in cdns_spi_runtime_resume()
718 struct cdns_spi *xspi = spi_master_get_devdata(master); in cdns_spi_runtime_suspend() local
720 clk_disable_unprepare(xspi->ref_clk); in cdns_spi_runtime_suspend()
721 clk_disable_unprepare(xspi->pclk); in cdns_spi_runtime_suspend()