Lines Matching refs:hw

61 	struct tiny_spi *hw = tiny_spi_to_hw(spi);  in tiny_spi_baud()  local
63 return min(DIV_ROUND_UP(hw->freq, hz * 2), (1U << hw->baudwidth)) - 1; in tiny_spi_baud()
69 struct tiny_spi *hw = tiny_spi_to_hw(spi); in tiny_spi_setup_transfer() local
70 unsigned int baud = hw->baud; in tiny_spi_setup_transfer()
73 if (t->speed_hz && t->speed_hz != hw->speed_hz) in tiny_spi_setup_transfer()
76 writel(baud, hw->base + TINY_SPI_BAUD); in tiny_spi_setup_transfer()
77 writel(hw->mode, hw->base + TINY_SPI_CONTROL); in tiny_spi_setup_transfer()
83 struct tiny_spi *hw = tiny_spi_to_hw(spi); in tiny_spi_setup() local
85 if (spi->max_speed_hz != hw->speed_hz) { in tiny_spi_setup()
86 hw->speed_hz = spi->max_speed_hz; in tiny_spi_setup()
87 hw->baud = tiny_spi_baud(spi, hw->speed_hz); in tiny_spi_setup()
89 hw->mode = spi->mode & SPI_MODE_X_MASK; in tiny_spi_setup()
93 static inline void tiny_spi_wait_txr(struct tiny_spi *hw) in tiny_spi_wait_txr() argument
95 while (!(readb(hw->base + TINY_SPI_STATUS) & in tiny_spi_wait_txr()
100 static inline void tiny_spi_wait_txe(struct tiny_spi *hw) in tiny_spi_wait_txe() argument
102 while (!(readb(hw->base + TINY_SPI_STATUS) & in tiny_spi_wait_txe()
109 struct tiny_spi *hw = tiny_spi_to_hw(spi); in tiny_spi_txrx_bufs() local
114 if (hw->irq >= 0) { in tiny_spi_txrx_bufs()
116 hw->len = t->len; in tiny_spi_txrx_bufs()
117 hw->txp = t->tx_buf; in tiny_spi_txrx_bufs()
118 hw->rxp = t->rx_buf; in tiny_spi_txrx_bufs()
119 hw->txc = 0; in tiny_spi_txrx_bufs()
120 hw->rxc = 0; in tiny_spi_txrx_bufs()
124 writeb(hw->txp ? *hw->txp++ : 0, in tiny_spi_txrx_bufs()
125 hw->base + TINY_SPI_TXDATA); in tiny_spi_txrx_bufs()
126 hw->txc++; in tiny_spi_txrx_bufs()
127 writeb(hw->txp ? *hw->txp++ : 0, in tiny_spi_txrx_bufs()
128 hw->base + TINY_SPI_TXDATA); in tiny_spi_txrx_bufs()
129 hw->txc++; in tiny_spi_txrx_bufs()
130 writeb(TINY_SPI_STATUS_TXR, hw->base + TINY_SPI_STATUS); in tiny_spi_txrx_bufs()
132 writeb(hw->txp ? *hw->txp++ : 0, in tiny_spi_txrx_bufs()
133 hw->base + TINY_SPI_TXDATA); in tiny_spi_txrx_bufs()
134 hw->txc++; in tiny_spi_txrx_bufs()
135 writeb(TINY_SPI_STATUS_TXE, hw->base + TINY_SPI_STATUS); in tiny_spi_txrx_bufs()
138 wait_for_completion(&hw->done); in tiny_spi_txrx_bufs()
141 writeb(txp ? *txp++ : 0, hw->base + TINY_SPI_TXDATA); in tiny_spi_txrx_bufs()
143 writeb(txp ? *txp++ : 0, hw->base + TINY_SPI_TXDATA); in tiny_spi_txrx_bufs()
146 tiny_spi_wait_txr(hw); in tiny_spi_txrx_bufs()
148 *rxp++ = readb(hw->base + TINY_SPI_TXDATA); in tiny_spi_txrx_bufs()
150 tiny_spi_wait_txe(hw); in tiny_spi_txrx_bufs()
152 *rxp++ = readb(hw->base + TINY_SPI_RXDATA); in tiny_spi_txrx_bufs()
160 struct tiny_spi *hw = dev; in tiny_spi_irq() local
162 writeb(0, hw->base + TINY_SPI_STATUS); in tiny_spi_irq()
163 if (hw->rxc + 1 == hw->len) { in tiny_spi_irq()
164 if (hw->rxp) in tiny_spi_irq()
165 *hw->rxp++ = readb(hw->base + TINY_SPI_RXDATA); in tiny_spi_irq()
166 hw->rxc++; in tiny_spi_irq()
167 complete(&hw->done); in tiny_spi_irq()
169 if (hw->rxp) in tiny_spi_irq()
170 *hw->rxp++ = readb(hw->base + TINY_SPI_TXDATA); in tiny_spi_irq()
171 hw->rxc++; in tiny_spi_irq()
172 if (hw->txc < hw->len) { in tiny_spi_irq()
173 writeb(hw->txp ? *hw->txp++ : 0, in tiny_spi_irq()
174 hw->base + TINY_SPI_TXDATA); in tiny_spi_irq()
175 hw->txc++; in tiny_spi_irq()
177 hw->base + TINY_SPI_STATUS); in tiny_spi_irq()
180 hw->base + TINY_SPI_STATUS); in tiny_spi_irq()
191 struct tiny_spi *hw = platform_get_drvdata(pdev); in tiny_spi_of_probe() local
197 hw->bitbang.master->dev.of_node = pdev->dev.of_node; in tiny_spi_of_probe()
199 hw->freq = val; in tiny_spi_of_probe()
201 hw->baudwidth = val; in tiny_spi_of_probe()
214 struct tiny_spi *hw; in tiny_spi_probe() local
228 hw = spi_master_get_devdata(master); in tiny_spi_probe()
229 platform_set_drvdata(pdev, hw); in tiny_spi_probe()
232 hw->bitbang.master = master; in tiny_spi_probe()
233 hw->bitbang.setup_transfer = tiny_spi_setup_transfer; in tiny_spi_probe()
234 hw->bitbang.txrx_bufs = tiny_spi_txrx_bufs; in tiny_spi_probe()
237 hw->base = devm_platform_ioremap_resource(pdev, 0); in tiny_spi_probe()
238 if (IS_ERR(hw->base)) { in tiny_spi_probe()
239 err = PTR_ERR(hw->base); in tiny_spi_probe()
243 hw->irq = platform_get_irq(pdev, 0); in tiny_spi_probe()
244 if (hw->irq >= 0) { in tiny_spi_probe()
245 init_completion(&hw->done); in tiny_spi_probe()
246 err = devm_request_irq(&pdev->dev, hw->irq, tiny_spi_irq, 0, in tiny_spi_probe()
247 pdev->name, hw); in tiny_spi_probe()
253 hw->freq = platp->freq; in tiny_spi_probe()
254 hw->baudwidth = platp->baudwidth; in tiny_spi_probe()
262 err = spi_bitbang_start(&hw->bitbang); in tiny_spi_probe()
265 dev_info(&pdev->dev, "base %p, irq %d\n", hw->base, hw->irq); in tiny_spi_probe()
276 struct tiny_spi *hw = platform_get_drvdata(pdev); in tiny_spi_remove() local
277 struct spi_master *master = hw->bitbang.master; in tiny_spi_remove()
279 spi_bitbang_stop(&hw->bitbang); in tiny_spi_remove()