Lines Matching refs:sspi

105 static inline u32 sun6i_spi_read(struct sun6i_spi *sspi, u32 reg)  in sun6i_spi_read()  argument
107 return readl(sspi->base_addr + reg); in sun6i_spi_read()
110 static inline void sun6i_spi_write(struct sun6i_spi *sspi, u32 reg, u32 value) in sun6i_spi_write() argument
112 writel(value, sspi->base_addr + reg); in sun6i_spi_write()
115 static inline u32 sun6i_spi_get_rx_fifo_count(struct sun6i_spi *sspi) in sun6i_spi_get_rx_fifo_count() argument
117 u32 reg = sun6i_spi_read(sspi, SUN6I_FIFO_STA_REG); in sun6i_spi_get_rx_fifo_count()
122 static inline u32 sun6i_spi_get_tx_fifo_count(struct sun6i_spi *sspi) in sun6i_spi_get_tx_fifo_count() argument
124 u32 reg = sun6i_spi_read(sspi, SUN6I_FIFO_STA_REG); in sun6i_spi_get_tx_fifo_count()
129 static inline void sun6i_spi_disable_interrupt(struct sun6i_spi *sspi, u32 mask) in sun6i_spi_disable_interrupt() argument
131 u32 reg = sun6i_spi_read(sspi, SUN6I_INT_CTL_REG); in sun6i_spi_disable_interrupt()
134 sun6i_spi_write(sspi, SUN6I_INT_CTL_REG, reg); in sun6i_spi_disable_interrupt()
137 static inline void sun6i_spi_drain_fifo(struct sun6i_spi *sspi) in sun6i_spi_drain_fifo() argument
143 len = sun6i_spi_get_rx_fifo_count(sspi); in sun6i_spi_drain_fifo()
146 byte = readb(sspi->base_addr + SUN6I_RXDATA_REG); in sun6i_spi_drain_fifo()
147 if (sspi->rx_buf) in sun6i_spi_drain_fifo()
148 *sspi->rx_buf++ = byte; in sun6i_spi_drain_fifo()
152 static inline void sun6i_spi_fill_fifo(struct sun6i_spi *sspi) in sun6i_spi_fill_fifo() argument
159 cnt = sspi->fifo_depth - sun6i_spi_get_tx_fifo_count(sspi); in sun6i_spi_fill_fifo()
161 len = min((int)cnt, sspi->len); in sun6i_spi_fill_fifo()
164 byte = sspi->tx_buf ? *sspi->tx_buf++ : 0; in sun6i_spi_fill_fifo()
165 writeb(byte, sspi->base_addr + SUN6I_TXDATA_REG); in sun6i_spi_fill_fifo()
166 sspi->len--; in sun6i_spi_fill_fifo()
172 struct sun6i_spi *sspi = spi_master_get_devdata(spi->master); in sun6i_spi_set_cs() local
175 reg = sun6i_spi_read(sspi, SUN6I_TFR_CTL_REG); in sun6i_spi_set_cs()
184 sun6i_spi_write(sspi, SUN6I_TFR_CTL_REG, reg); in sun6i_spi_set_cs()
192 static int sun6i_spi_prepare_dma(struct sun6i_spi *sspi, in sun6i_spi_prepare_dma() argument
196 struct spi_master *master = sspi->master; in sun6i_spi_prepare_dma()
202 .src_addr = sspi->dma_addr_rx, in sun6i_spi_prepare_dma()
222 .dst_addr = sspi->dma_addr_tx, in sun6i_spi_prepare_dma()
258 struct sun6i_spi *sspi = spi_master_get_devdata(master); in sun6i_spi_transfer_one() local
270 reinit_completion(&sspi->done); in sun6i_spi_transfer_one()
271 sspi->tx_buf = tfr->tx_buf; in sun6i_spi_transfer_one()
272 sspi->rx_buf = tfr->rx_buf; in sun6i_spi_transfer_one()
273 sspi->len = tfr->len; in sun6i_spi_transfer_one()
277 sun6i_spi_write(sspi, SUN6I_INT_STA_REG, ~0); in sun6i_spi_transfer_one()
280 sun6i_spi_write(sspi, SUN6I_FIFO_CTL_REG, in sun6i_spi_transfer_one()
292 trig_level = sspi->fifo_depth / 4 * 3; in sun6i_spi_transfer_one()
299 trig_level = sspi->fifo_depth / 2; in sun6i_spi_transfer_one()
310 sun6i_spi_write(sspi, SUN6I_FIFO_CTL_REG, reg); in sun6i_spi_transfer_one()
316 reg = sun6i_spi_read(sspi, SUN6I_TFR_CTL_REG); in sun6i_spi_transfer_one()
337 if (sspi->rx_buf) { in sun6i_spi_transfer_one()
347 sun6i_spi_write(sspi, SUN6I_TFR_CTL_REG, reg); in sun6i_spi_transfer_one()
350 mclk_rate = clk_get_rate(sspi->mclk); in sun6i_spi_transfer_one()
352 clk_set_rate(sspi->mclk, 2 * tfr->speed_hz); in sun6i_spi_transfer_one()
353 mclk_rate = clk_get_rate(sspi->mclk); in sun6i_spi_transfer_one()
381 sun6i_spi_write(sspi, SUN6I_CLK_CTL_REG, reg); in sun6i_spi_transfer_one()
383 reg = sun6i_spi_read(sspi, SUN6I_GBL_CTL_REG); in sun6i_spi_transfer_one()
385 sun6i_spi_write(sspi, SUN6I_GBL_CTL_REG, reg); in sun6i_spi_transfer_one()
388 if (sspi->tx_buf) in sun6i_spi_transfer_one()
392 sun6i_spi_write(sspi, SUN6I_BURST_CNT_REG, tfr->len); in sun6i_spi_transfer_one()
393 sun6i_spi_write(sspi, SUN6I_XMIT_CNT_REG, tx_len); in sun6i_spi_transfer_one()
394 sun6i_spi_write(sspi, SUN6I_BURST_CTL_CNT_REG, tx_len); in sun6i_spi_transfer_one()
398 sun6i_spi_fill_fifo(sspi); in sun6i_spi_transfer_one()
400 ret = sun6i_spi_prepare_dma(sspi, tfr); in sun6i_spi_transfer_one()
413 if (rx_len > sspi->fifo_depth) in sun6i_spi_transfer_one()
415 if (tx_len > sspi->fifo_depth) in sun6i_spi_transfer_one()
419 sun6i_spi_write(sspi, SUN6I_INT_CTL_REG, reg); in sun6i_spi_transfer_one()
422 reg = sun6i_spi_read(sspi, SUN6I_TFR_CTL_REG); in sun6i_spi_transfer_one()
423 sun6i_spi_write(sspi, SUN6I_TFR_CTL_REG, reg | SUN6I_TFR_CTL_XCH); in sun6i_spi_transfer_one()
427 timeout = wait_for_completion_timeout(&sspi->done, in sun6i_spi_transfer_one()
438 sun6i_spi_write(sspi, SUN6I_INT_CTL_REG, 0); in sun6i_spi_transfer_one()
450 struct sun6i_spi *sspi = dev_id; in sun6i_spi_handler() local
451 u32 status = sun6i_spi_read(sspi, SUN6I_INT_STA_REG); in sun6i_spi_handler()
455 sun6i_spi_write(sspi, SUN6I_INT_STA_REG, SUN6I_INT_CTL_TC); in sun6i_spi_handler()
456 sun6i_spi_drain_fifo(sspi); in sun6i_spi_handler()
457 complete(&sspi->done); in sun6i_spi_handler()
463 sun6i_spi_drain_fifo(sspi); in sun6i_spi_handler()
465 sun6i_spi_write(sspi, SUN6I_INT_STA_REG, SUN6I_INT_CTL_RF_RDY); in sun6i_spi_handler()
471 sun6i_spi_fill_fifo(sspi); in sun6i_spi_handler()
473 if (!sspi->len) in sun6i_spi_handler()
475 sun6i_spi_disable_interrupt(sspi, SUN6I_INT_CTL_TF_ERQ); in sun6i_spi_handler()
478 sun6i_spi_write(sspi, SUN6I_INT_STA_REG, SUN6I_INT_CTL_TF_ERQ); in sun6i_spi_handler()
489 struct sun6i_spi *sspi = spi_master_get_devdata(master); in sun6i_spi_runtime_resume() local
492 ret = clk_prepare_enable(sspi->hclk); in sun6i_spi_runtime_resume()
498 ret = clk_prepare_enable(sspi->mclk); in sun6i_spi_runtime_resume()
504 ret = reset_control_deassert(sspi->rstc); in sun6i_spi_runtime_resume()
510 sun6i_spi_write(sspi, SUN6I_GBL_CTL_REG, in sun6i_spi_runtime_resume()
516 clk_disable_unprepare(sspi->mclk); in sun6i_spi_runtime_resume()
518 clk_disable_unprepare(sspi->hclk); in sun6i_spi_runtime_resume()
526 struct sun6i_spi *sspi = spi_master_get_devdata(master); in sun6i_spi_runtime_suspend() local
528 reset_control_assert(sspi->rstc); in sun6i_spi_runtime_suspend()
529 clk_disable_unprepare(sspi->mclk); in sun6i_spi_runtime_suspend()
530 clk_disable_unprepare(sspi->hclk); in sun6i_spi_runtime_suspend()
539 struct sun6i_spi *sspi = spi_master_get_devdata(master); in sun6i_spi_can_dma() local
546 return xfer->len > sspi->fifo_depth; in sun6i_spi_can_dma()
552 struct sun6i_spi *sspi; in sun6i_spi_probe() local
563 sspi = spi_master_get_devdata(master); in sun6i_spi_probe()
565 sspi->base_addr = devm_platform_get_and_ioremap_resource(pdev, 0, &mem); in sun6i_spi_probe()
566 if (IS_ERR(sspi->base_addr)) { in sun6i_spi_probe()
567 ret = PTR_ERR(sspi->base_addr); in sun6i_spi_probe()
578 0, "sun6i-spi", sspi); in sun6i_spi_probe()
584 sspi->master = master; in sun6i_spi_probe()
585 sspi->fifo_depth = (unsigned long)of_device_get_match_data(&pdev->dev); in sun6i_spi_probe()
599 sspi->hclk = devm_clk_get(&pdev->dev, "ahb"); in sun6i_spi_probe()
600 if (IS_ERR(sspi->hclk)) { in sun6i_spi_probe()
602 ret = PTR_ERR(sspi->hclk); in sun6i_spi_probe()
606 sspi->mclk = devm_clk_get(&pdev->dev, "mod"); in sun6i_spi_probe()
607 if (IS_ERR(sspi->mclk)) { in sun6i_spi_probe()
609 ret = PTR_ERR(sspi->mclk); in sun6i_spi_probe()
613 init_completion(&sspi->done); in sun6i_spi_probe()
615 sspi->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL); in sun6i_spi_probe()
616 if (IS_ERR(sspi->rstc)) { in sun6i_spi_probe()
618 ret = PTR_ERR(sspi->rstc); in sun6i_spi_probe()
644 sspi->dma_addr_tx = mem->start + SUN6I_TXDATA_REG; in sun6i_spi_probe()
645 sspi->dma_addr_rx = mem->start + SUN6I_RXDATA_REG; in sun6i_spi_probe()