20 #include <linux/errno.h>
21 #include <linux/module.h>
30 #define DRV_NAME "spi_oc_tiny"
32 #define TINY_SPI_RXDATA 0
33 #define TINY_SPI_TXDATA 4
34 #define TINY_SPI_STATUS 8
35 #define TINY_SPI_CONTROL 12
36 #define TINY_SPI_BAUD 16
38 #define TINY_SPI_STATUS_TXE 0x1
39 #define TINY_SPI_STATUS_TXR 0x2
63 return spi_master_get_devdata(sdev->
master);
66 static unsigned int tiny_spi_baud(
struct spi_device *
spi,
unsigned int hz)
75 struct tiny_spi *hw = tiny_spi_to_hw(spi);
83 static int tiny_spi_setup_transfer(
struct spi_device *spi,
86 struct tiny_spi *hw = tiny_spi_to_hw(spi);
91 baud = tiny_spi_baud(spi, t->
speed_hz);
98 static int tiny_spi_setup(
struct spi_device *spi)
100 struct tiny_spi *hw = tiny_spi_to_hw(spi);
110 static inline void tiny_spi_wait_txr(
struct tiny_spi *hw)
117 static inline void tiny_spi_wait_txe(
struct tiny_spi *hw)
126 struct tiny_spi *hw = tiny_spi_to_hw(spi);
156 }
else if (txp && rxp) {
161 for (i = 2; i < t->
len; i++) {
163 tiny_spi_wait_txr(hw);
168 tiny_spi_wait_txr(hw);
171 tiny_spi_wait_txe(hw);
178 for (i = 2; i < t->
len; i++) {
180 tiny_spi_wait_txr(hw);
185 tiny_spi_wait_txr(hw);
188 tiny_spi_wait_txe(hw);
194 for (i = 2; i < t->
len; i++) {
196 tiny_spi_wait_txr(hw);
200 tiny_spi_wait_txe(hw);
205 for (i = 2; i < t->
len; i++) {
206 tiny_spi_wait_txr(hw);
210 tiny_spi_wait_txe(hw);
220 if (hw->
rxc + 1 == hw->
len) {
248 struct tiny_spi *hw = platform_get_drvdata(pdev);
269 hw->
bitbang.master->dev.of_node = pdev->
dev.of_node;
271 "clock-frequency", &len);
272 if (val && len >=
sizeof(
__be32))
275 if (val && len >=
sizeof(
__be32))
303 master->
setup = tiny_spi_setup;
305 hw = spi_master_get_devdata(master);
306 platform_set_drvdata(pdev, hw);
309 hw->
bitbang.master = spi_master_get(master);
312 hw->
bitbang.setup_transfer = tiny_spi_setup_transfer;
313 hw->
bitbang.chipselect = tiny_spi_chipselect;
314 hw->
bitbang.txrx_bufs = tiny_spi_txrx_bufs;
330 init_completion(&hw->
done);
331 err = devm_request_irq(&pdev->
dev, hw->
irq, tiny_spi_irq, 0,
345 err = tiny_spi_of_probe(pdev);
371 platform_set_drvdata(pdev,
NULL);
372 spi_master_put(master);
378 struct tiny_spi *hw = platform_get_drvdata(pdev);
385 platform_set_drvdata(pdev,
NULL);
386 spi_master_put(master);
392 { .compatible =
"opencores,tiny-spi-rtlsvn2", },
397 #define tiny_spi_match NULL
401 .probe = tiny_spi_probe,