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_controller_get_devdata(spi->controller); 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_controller_get_devdata(host); in sun4i_spi_transfer_one() local
223 reinit_completion(&sspi->done); in sun4i_spi_transfer_one()
224 sspi->tx_buf = tfr->tx_buf; in sun4i_spi_transfer_one()
225 sspi->rx_buf = tfr->rx_buf; in sun4i_spi_transfer_one()
226 sspi->len = tfr->len; in sun4i_spi_transfer_one()
229 sun4i_spi_write(sspi, SUN4I_INT_STA_REG, ~0); in sun4i_spi_transfer_one()
232 reg = sun4i_spi_read(sspi, SUN4I_CTL_REG); in sun4i_spi_transfer_one()
235 sun4i_spi_write(sspi, SUN4I_CTL_REG, in sun4i_spi_transfer_one()
262 if (sspi->rx_buf) in sun4i_spi_transfer_one()
267 sun4i_spi_write(sspi, SUN4I_CTL_REG, reg); in sun4i_spi_transfer_one()
270 mclk_rate = clk_get_rate(sspi->mclk); in sun4i_spi_transfer_one()
272 clk_set_rate(sspi->mclk, 2 * tfr->speed_hz); in sun4i_spi_transfer_one()
273 mclk_rate = clk_get_rate(sspi->mclk); in sun4i_spi_transfer_one()
301 sun4i_spi_write(sspi, SUN4I_CLK_CTL_REG, reg); in sun4i_spi_transfer_one()
304 if (sspi->tx_buf) in sun4i_spi_transfer_one()
308 sun4i_spi_write(sspi, SUN4I_BURST_CNT_REG, SUN4I_BURST_CNT(tfr->len)); in sun4i_spi_transfer_one()
309 sun4i_spi_write(sspi, SUN4I_XMIT_CNT_REG, SUN4I_XMIT_CNT(tx_len)); in sun4i_spi_transfer_one()
316 sun4i_spi_fill_fifo(sspi, SUN4I_FIFO_DEPTH - 1); in sun4i_spi_transfer_one()
319 sun4i_spi_enable_interrupt(sspi, SUN4I_INT_CTL_TC | in sun4i_spi_transfer_one()
323 sun4i_spi_enable_interrupt(sspi, SUN4I_INT_CTL_TF_E34); in sun4i_spi_transfer_one()
326 reg = sun4i_spi_read(sspi, SUN4I_CTL_REG); in sun4i_spi_transfer_one()
327 sun4i_spi_write(sspi, SUN4I_CTL_REG, reg | SUN4I_CTL_XCH); in sun4i_spi_transfer_one()
331 time_left = wait_for_completion_timeout(&sspi->done, in sun4i_spi_transfer_one()
345 sun4i_spi_write(sspi, SUN4I_INT_CTL_REG, 0); in sun4i_spi_transfer_one()
352 struct sun4i_spi *sspi = dev_id; in sun4i_spi_handler() local
353 u32 status = sun4i_spi_read(sspi, SUN4I_INT_STA_REG); in sun4i_spi_handler()
357 sun4i_spi_write(sspi, SUN4I_INT_STA_REG, SUN4I_INT_CTL_TC); in sun4i_spi_handler()
358 sun4i_spi_drain_fifo(sspi, SUN4I_FIFO_DEPTH); in sun4i_spi_handler()
359 complete(&sspi->done); in sun4i_spi_handler()
365 sun4i_spi_drain_fifo(sspi, SUN4I_FIFO_DEPTH); in sun4i_spi_handler()
367 sun4i_spi_write(sspi, SUN4I_INT_STA_REG, SUN4I_INT_CTL_RF_F34); in sun4i_spi_handler()
373 sun4i_spi_fill_fifo(sspi, SUN4I_FIFO_DEPTH); in sun4i_spi_handler()
375 if (!sspi->len) in sun4i_spi_handler()
377 sun4i_spi_disable_interrupt(sspi, SUN4I_INT_CTL_TF_E34); in sun4i_spi_handler()
380 sun4i_spi_write(sspi, SUN4I_INT_STA_REG, SUN4I_INT_CTL_TF_E34); in sun4i_spi_handler()
391 struct sun4i_spi *sspi = spi_controller_get_devdata(host); in sun4i_spi_runtime_resume() local
394 ret = clk_prepare_enable(sspi->hclk); in sun4i_spi_runtime_resume()
400 ret = clk_prepare_enable(sspi->mclk); in sun4i_spi_runtime_resume()
406 sun4i_spi_write(sspi, SUN4I_CTL_REG, in sun4i_spi_runtime_resume()
412 clk_disable_unprepare(sspi->hclk); in sun4i_spi_runtime_resume()
420 struct sun4i_spi *sspi = spi_controller_get_devdata(host); in sun4i_spi_runtime_suspend() local
422 clk_disable_unprepare(sspi->mclk); in sun4i_spi_runtime_suspend()
423 clk_disable_unprepare(sspi->hclk); in sun4i_spi_runtime_suspend()
431 struct sun4i_spi *sspi; in sun4i_spi_probe() local
441 sspi = spi_controller_get_devdata(host); in sun4i_spi_probe()
443 sspi->base_addr = devm_platform_ioremap_resource(pdev, 0); in sun4i_spi_probe()
444 if (IS_ERR(sspi->base_addr)) { in sun4i_spi_probe()
445 ret = PTR_ERR(sspi->base_addr); in sun4i_spi_probe()
456 0, "sun4i-spi", sspi); in sun4i_spi_probe()
462 sspi->host = host; in sun4i_spi_probe()
474 sspi->hclk = devm_clk_get(&pdev->dev, "ahb"); in sun4i_spi_probe()
475 if (IS_ERR(sspi->hclk)) { in sun4i_spi_probe()
477 ret = PTR_ERR(sspi->hclk); in sun4i_spi_probe()
481 sspi->mclk = devm_clk_get(&pdev->dev, "mod"); in sun4i_spi_probe()
482 if (IS_ERR(sspi->mclk)) { in sun4i_spi_probe()
484 ret = PTR_ERR(sspi->mclk); in sun4i_spi_probe()
488 init_completion(&sspi->done); in sun4i_spi_probe()