Lines Matching refs:sspi
98 static inline u32 sun6i_spi_read(struct sun6i_spi *sspi, u32 reg) in sun6i_spi_read() argument
100 return readl(sspi->base_addr + reg); in sun6i_spi_read()
103 static inline void sun6i_spi_write(struct sun6i_spi *sspi, u32 reg, u32 value) in sun6i_spi_write() argument
105 writel(value, sspi->base_addr + reg); in sun6i_spi_write()
108 static inline u32 sun6i_spi_get_rx_fifo_count(struct sun6i_spi *sspi) in sun6i_spi_get_rx_fifo_count() argument
110 u32 reg = sun6i_spi_read(sspi, SUN6I_FIFO_STA_REG); in sun6i_spi_get_rx_fifo_count()
115 static inline u32 sun6i_spi_get_tx_fifo_count(struct sun6i_spi *sspi) in sun6i_spi_get_tx_fifo_count() argument
117 u32 reg = sun6i_spi_read(sspi, SUN6I_FIFO_STA_REG); in sun6i_spi_get_tx_fifo_count()
122 static inline void sun6i_spi_disable_interrupt(struct sun6i_spi *sspi, u32 mask) in sun6i_spi_disable_interrupt() argument
124 u32 reg = sun6i_spi_read(sspi, SUN6I_INT_CTL_REG); in sun6i_spi_disable_interrupt()
127 sun6i_spi_write(sspi, SUN6I_INT_CTL_REG, reg); in sun6i_spi_disable_interrupt()
130 static inline void sun6i_spi_drain_fifo(struct sun6i_spi *sspi) in sun6i_spi_drain_fifo() argument
136 len = sun6i_spi_get_rx_fifo_count(sspi); in sun6i_spi_drain_fifo()
139 byte = readb(sspi->base_addr + SUN6I_RXDATA_REG); in sun6i_spi_drain_fifo()
140 if (sspi->rx_buf) in sun6i_spi_drain_fifo()
141 *sspi->rx_buf++ = byte; in sun6i_spi_drain_fifo()
145 static inline void sun6i_spi_fill_fifo(struct sun6i_spi *sspi) in sun6i_spi_fill_fifo() argument
152 cnt = sspi->fifo_depth - sun6i_spi_get_tx_fifo_count(sspi); in sun6i_spi_fill_fifo()
154 len = min((int)cnt, sspi->len); in sun6i_spi_fill_fifo()
157 byte = sspi->tx_buf ? *sspi->tx_buf++ : 0; in sun6i_spi_fill_fifo()
158 writeb(byte, sspi->base_addr + SUN6I_TXDATA_REG); in sun6i_spi_fill_fifo()
159 sspi->len--; in sun6i_spi_fill_fifo()
165 struct sun6i_spi *sspi = spi_master_get_devdata(spi->master); in sun6i_spi_set_cs() local
168 reg = sun6i_spi_read(sspi, SUN6I_TFR_CTL_REG); in sun6i_spi_set_cs()
177 sun6i_spi_write(sspi, SUN6I_TFR_CTL_REG, reg); in sun6i_spi_set_cs()
189 struct sun6i_spi *sspi = spi_master_get_devdata(master); in sun6i_spi_transfer_one() local
200 reinit_completion(&sspi->done); in sun6i_spi_transfer_one()
201 sspi->tx_buf = tfr->tx_buf; in sun6i_spi_transfer_one()
202 sspi->rx_buf = tfr->rx_buf; in sun6i_spi_transfer_one()
203 sspi->len = tfr->len; in sun6i_spi_transfer_one()
206 sun6i_spi_write(sspi, SUN6I_INT_STA_REG, ~0); in sun6i_spi_transfer_one()
209 sun6i_spi_write(sspi, SUN6I_FIFO_CTL_REG, in sun6i_spi_transfer_one()
218 trig_level = sspi->fifo_depth / 4 * 3; in sun6i_spi_transfer_one()
219 sun6i_spi_write(sspi, SUN6I_FIFO_CTL_REG, in sun6i_spi_transfer_one()
227 reg = sun6i_spi_read(sspi, SUN6I_TFR_CTL_REG); in sun6i_spi_transfer_one()
248 if (sspi->rx_buf) { in sun6i_spi_transfer_one()
258 sun6i_spi_write(sspi, SUN6I_TFR_CTL_REG, reg); in sun6i_spi_transfer_one()
261 mclk_rate = clk_get_rate(sspi->mclk); in sun6i_spi_transfer_one()
263 clk_set_rate(sspi->mclk, 2 * tfr->speed_hz); in sun6i_spi_transfer_one()
264 mclk_rate = clk_get_rate(sspi->mclk); in sun6i_spi_transfer_one()
292 sun6i_spi_write(sspi, SUN6I_CLK_CTL_REG, reg); in sun6i_spi_transfer_one()
295 if (sspi->tx_buf) in sun6i_spi_transfer_one()
299 sun6i_spi_write(sspi, SUN6I_BURST_CNT_REG, tfr->len); in sun6i_spi_transfer_one()
300 sun6i_spi_write(sspi, SUN6I_XMIT_CNT_REG, tx_len); in sun6i_spi_transfer_one()
301 sun6i_spi_write(sspi, SUN6I_BURST_CTL_CNT_REG, tx_len); in sun6i_spi_transfer_one()
304 sun6i_spi_fill_fifo(sspi); in sun6i_spi_transfer_one()
309 if (rx_len > sspi->fifo_depth) in sun6i_spi_transfer_one()
311 if (tx_len > sspi->fifo_depth) in sun6i_spi_transfer_one()
314 sun6i_spi_write(sspi, SUN6I_INT_CTL_REG, reg); in sun6i_spi_transfer_one()
317 reg = sun6i_spi_read(sspi, SUN6I_TFR_CTL_REG); in sun6i_spi_transfer_one()
318 sun6i_spi_write(sspi, SUN6I_TFR_CTL_REG, reg | SUN6I_TFR_CTL_XCH); in sun6i_spi_transfer_one()
322 timeout = wait_for_completion_timeout(&sspi->done, in sun6i_spi_transfer_one()
333 sun6i_spi_write(sspi, SUN6I_INT_CTL_REG, 0); in sun6i_spi_transfer_one()
340 struct sun6i_spi *sspi = dev_id; in sun6i_spi_handler() local
341 u32 status = sun6i_spi_read(sspi, SUN6I_INT_STA_REG); in sun6i_spi_handler()
345 sun6i_spi_write(sspi, SUN6I_INT_STA_REG, SUN6I_INT_CTL_TC); in sun6i_spi_handler()
346 sun6i_spi_drain_fifo(sspi); in sun6i_spi_handler()
347 complete(&sspi->done); in sun6i_spi_handler()
353 sun6i_spi_drain_fifo(sspi); in sun6i_spi_handler()
355 sun6i_spi_write(sspi, SUN6I_INT_STA_REG, SUN6I_INT_CTL_RF_RDY); in sun6i_spi_handler()
361 sun6i_spi_fill_fifo(sspi); in sun6i_spi_handler()
363 if (!sspi->len) in sun6i_spi_handler()
365 sun6i_spi_disable_interrupt(sspi, SUN6I_INT_CTL_TF_ERQ); in sun6i_spi_handler()
368 sun6i_spi_write(sspi, SUN6I_INT_STA_REG, SUN6I_INT_CTL_TF_ERQ); in sun6i_spi_handler()
379 struct sun6i_spi *sspi = spi_master_get_devdata(master); in sun6i_spi_runtime_resume() local
382 ret = clk_prepare_enable(sspi->hclk); in sun6i_spi_runtime_resume()
388 ret = clk_prepare_enable(sspi->mclk); in sun6i_spi_runtime_resume()
394 ret = reset_control_deassert(sspi->rstc); in sun6i_spi_runtime_resume()
400 sun6i_spi_write(sspi, SUN6I_GBL_CTL_REG, in sun6i_spi_runtime_resume()
406 clk_disable_unprepare(sspi->mclk); in sun6i_spi_runtime_resume()
408 clk_disable_unprepare(sspi->hclk); in sun6i_spi_runtime_resume()
416 struct sun6i_spi *sspi = spi_master_get_devdata(master); in sun6i_spi_runtime_suspend() local
418 reset_control_assert(sspi->rstc); in sun6i_spi_runtime_suspend()
419 clk_disable_unprepare(sspi->mclk); in sun6i_spi_runtime_suspend()
420 clk_disable_unprepare(sspi->hclk); in sun6i_spi_runtime_suspend()
428 struct sun6i_spi *sspi; in sun6i_spi_probe() local
438 sspi = spi_master_get_devdata(master); in sun6i_spi_probe()
440 sspi->base_addr = devm_platform_ioremap_resource(pdev, 0); in sun6i_spi_probe()
441 if (IS_ERR(sspi->base_addr)) { in sun6i_spi_probe()
442 ret = PTR_ERR(sspi->base_addr); in sun6i_spi_probe()
453 0, "sun6i-spi", sspi); in sun6i_spi_probe()
459 sspi->master = master; in sun6i_spi_probe()
460 sspi->fifo_depth = (unsigned long)of_device_get_match_data(&pdev->dev); in sun6i_spi_probe()
474 sspi->hclk = devm_clk_get(&pdev->dev, "ahb"); in sun6i_spi_probe()
475 if (IS_ERR(sspi->hclk)) { in sun6i_spi_probe()
477 ret = PTR_ERR(sspi->hclk); in sun6i_spi_probe()
481 sspi->mclk = devm_clk_get(&pdev->dev, "mod"); in sun6i_spi_probe()
482 if (IS_ERR(sspi->mclk)) { in sun6i_spi_probe()
484 ret = PTR_ERR(sspi->mclk); in sun6i_spi_probe()
488 init_completion(&sspi->done); in sun6i_spi_probe()
490 sspi->rstc = devm_reset_control_get_exclusive(&pdev->dev, NULL); in sun6i_spi_probe()
491 if (IS_ERR(sspi->rstc)) { in sun6i_spi_probe()
493 ret = PTR_ERR(sspi->rstc); in sun6i_spi_probe()