Lines Matching refs:sspi
90 static inline u32 sun4i_spi_read(struct sun4i_spi *sspi, u32 reg) in sun4i_spi_read() argument
92 return readl(sspi->base_addr + reg); in sun4i_spi_read()
95 static inline void sun4i_spi_write(struct sun4i_spi *sspi, u32 reg, u32 value) in sun4i_spi_write() argument
97 writel(value, sspi->base_addr + reg); in sun4i_spi_write()
100 static inline u32 sun4i_spi_get_tx_fifo_count(struct sun4i_spi *sspi) in sun4i_spi_get_tx_fifo_count() argument
102 u32 reg = sun4i_spi_read(sspi, SUN4I_FIFO_STA_REG); in sun4i_spi_get_tx_fifo_count()
109 static inline void sun4i_spi_enable_interrupt(struct sun4i_spi *sspi, u32 mask) in sun4i_spi_enable_interrupt() argument
111 u32 reg = sun4i_spi_read(sspi, SUN4I_INT_CTL_REG); in sun4i_spi_enable_interrupt()
114 sun4i_spi_write(sspi, SUN4I_INT_CTL_REG, reg); in sun4i_spi_enable_interrupt()
117 static inline void sun4i_spi_disable_interrupt(struct sun4i_spi *sspi, u32 mask) in sun4i_spi_disable_interrupt() argument
119 u32 reg = sun4i_spi_read(sspi, SUN4I_INT_CTL_REG); in sun4i_spi_disable_interrupt()
122 sun4i_spi_write(sspi, SUN4I_INT_CTL_REG, reg); in sun4i_spi_disable_interrupt()
125 static inline void sun4i_spi_drain_fifo(struct sun4i_spi *sspi, int len) in sun4i_spi_drain_fifo() argument
131 reg = sun4i_spi_read(sspi, SUN4I_FIFO_STA_REG); in sun4i_spi_drain_fifo()
139 byte = readb(sspi->base_addr + SUN4I_RXDATA_REG); in sun4i_spi_drain_fifo()
140 if (sspi->rx_buf) in sun4i_spi_drain_fifo()
141 *sspi->rx_buf++ = byte; in sun4i_spi_drain_fifo()
145 static inline void sun4i_spi_fill_fifo(struct sun4i_spi *sspi, int len) in sun4i_spi_fill_fifo() argument
151 cnt = SUN4I_FIFO_DEPTH - sun4i_spi_get_tx_fifo_count(sspi); in sun4i_spi_fill_fifo()
153 len = min3(len, (int)cnt, sspi->len); in sun4i_spi_fill_fifo()
156 byte = sspi->tx_buf ? *sspi->tx_buf++ : 0; in sun4i_spi_fill_fifo()
157 writeb(byte, sspi->base_addr + SUN4I_TXDATA_REG); in sun4i_spi_fill_fifo()
158 sspi->len--; in sun4i_spi_fill_fifo()
164 struct sun4i_spi *sspi = spi_master_get_devdata(spi->master); in sun4i_spi_set_cs() local
167 reg = sun4i_spi_read(sspi, SUN4I_CTL_REG); in sun4i_spi_set_cs()
196 sun4i_spi_write(sspi, SUN4I_CTL_REG, reg); in sun4i_spi_set_cs()
208 struct sun4i_spi *sspi = spi_master_get_devdata(master); in sun4i_spi_transfer_one() local
222 reinit_completion(&sspi->done); in sun4i_spi_transfer_one()
223 sspi->tx_buf = tfr->tx_buf; in sun4i_spi_transfer_one()
224 sspi->rx_buf = tfr->rx_buf; in sun4i_spi_transfer_one()
225 sspi->len = tfr->len; in sun4i_spi_transfer_one()
228 sun4i_spi_write(sspi, SUN4I_INT_STA_REG, ~0); in sun4i_spi_transfer_one()
231 reg = sun4i_spi_read(sspi, SUN4I_CTL_REG); in sun4i_spi_transfer_one()
234 sun4i_spi_write(sspi, SUN4I_CTL_REG, in sun4i_spi_transfer_one()
261 if (sspi->rx_buf) in sun4i_spi_transfer_one()
266 sun4i_spi_write(sspi, SUN4I_CTL_REG, reg); in sun4i_spi_transfer_one()
269 mclk_rate = clk_get_rate(sspi->mclk); in sun4i_spi_transfer_one()
271 clk_set_rate(sspi->mclk, 2 * tfr->speed_hz); in sun4i_spi_transfer_one()
272 mclk_rate = clk_get_rate(sspi->mclk); in sun4i_spi_transfer_one()
300 sun4i_spi_write(sspi, SUN4I_CLK_CTL_REG, reg); in sun4i_spi_transfer_one()
303 if (sspi->tx_buf) in sun4i_spi_transfer_one()
307 sun4i_spi_write(sspi, SUN4I_BURST_CNT_REG, SUN4I_BURST_CNT(tfr->len)); in sun4i_spi_transfer_one()
308 sun4i_spi_write(sspi, SUN4I_XMIT_CNT_REG, SUN4I_XMIT_CNT(tx_len)); in sun4i_spi_transfer_one()
315 sun4i_spi_fill_fifo(sspi, SUN4I_FIFO_DEPTH - 1); in sun4i_spi_transfer_one()
318 sun4i_spi_enable_interrupt(sspi, SUN4I_INT_CTL_TC | in sun4i_spi_transfer_one()
322 sun4i_spi_enable_interrupt(sspi, SUN4I_INT_CTL_TF_E34); in sun4i_spi_transfer_one()
325 reg = sun4i_spi_read(sspi, SUN4I_CTL_REG); in sun4i_spi_transfer_one()
326 sun4i_spi_write(sspi, SUN4I_CTL_REG, reg | SUN4I_CTL_XCH); in sun4i_spi_transfer_one()
330 timeout = wait_for_completion_timeout(&sspi->done, in sun4i_spi_transfer_one()
344 sun4i_spi_write(sspi, SUN4I_INT_CTL_REG, 0); in sun4i_spi_transfer_one()
351 struct sun4i_spi *sspi = dev_id; in sun4i_spi_handler() local
352 u32 status = sun4i_spi_read(sspi, SUN4I_INT_STA_REG); in sun4i_spi_handler()
356 sun4i_spi_write(sspi, SUN4I_INT_STA_REG, SUN4I_INT_CTL_TC); in sun4i_spi_handler()
357 sun4i_spi_drain_fifo(sspi, SUN4I_FIFO_DEPTH); in sun4i_spi_handler()
358 complete(&sspi->done); in sun4i_spi_handler()
364 sun4i_spi_drain_fifo(sspi, SUN4I_FIFO_DEPTH); in sun4i_spi_handler()
366 sun4i_spi_write(sspi, SUN4I_INT_STA_REG, SUN4I_INT_CTL_RF_F34); in sun4i_spi_handler()
372 sun4i_spi_fill_fifo(sspi, SUN4I_FIFO_DEPTH); in sun4i_spi_handler()
374 if (!sspi->len) in sun4i_spi_handler()
376 sun4i_spi_disable_interrupt(sspi, SUN4I_INT_CTL_TF_E34); in sun4i_spi_handler()
379 sun4i_spi_write(sspi, SUN4I_INT_STA_REG, SUN4I_INT_CTL_TF_E34); in sun4i_spi_handler()
390 struct sun4i_spi *sspi = spi_master_get_devdata(master); in sun4i_spi_runtime_resume() local
393 ret = clk_prepare_enable(sspi->hclk); in sun4i_spi_runtime_resume()
399 ret = clk_prepare_enable(sspi->mclk); in sun4i_spi_runtime_resume()
405 sun4i_spi_write(sspi, SUN4I_CTL_REG, in sun4i_spi_runtime_resume()
411 clk_disable_unprepare(sspi->hclk); in sun4i_spi_runtime_resume()
419 struct sun4i_spi *sspi = spi_master_get_devdata(master); in sun4i_spi_runtime_suspend() local
421 clk_disable_unprepare(sspi->mclk); in sun4i_spi_runtime_suspend()
422 clk_disable_unprepare(sspi->hclk); in sun4i_spi_runtime_suspend()
430 struct sun4i_spi *sspi; in sun4i_spi_probe() local
440 sspi = spi_master_get_devdata(master); in sun4i_spi_probe()
442 sspi->base_addr = devm_platform_ioremap_resource(pdev, 0); in sun4i_spi_probe()
443 if (IS_ERR(sspi->base_addr)) { in sun4i_spi_probe()
444 ret = PTR_ERR(sspi->base_addr); in sun4i_spi_probe()
455 0, "sun4i-spi", sspi); in sun4i_spi_probe()
461 sspi->master = master; in sun4i_spi_probe()
473 sspi->hclk = devm_clk_get(&pdev->dev, "ahb"); in sun4i_spi_probe()
474 if (IS_ERR(sspi->hclk)) { in sun4i_spi_probe()
476 ret = PTR_ERR(sspi->hclk); in sun4i_spi_probe()
480 sspi->mclk = devm_clk_get(&pdev->dev, "mod"); in sun4i_spi_probe()
481 if (IS_ERR(sspi->mclk)) { in sun4i_spi_probe()
483 ret = PTR_ERR(sspi->mclk); in sun4i_spi_probe()
487 init_completion(&sspi->done); in sun4i_spi_probe()