diff options
-rw-r--r-- | drivers/spi/spi-jcore-bitbang.c | 53 |
1 files changed, 32 insertions, 21 deletions
diff --git a/drivers/spi/spi-jcore-bitbang.c b/drivers/spi/spi-jcore-bitbang.c index 9f86d6acb3c6..03ecdbbe1289 100644 --- a/drivers/spi/spi-jcore-bitbang.c +++ b/drivers/spi/spi-jcore-bitbang.c @@ -50,15 +50,9 @@ struct sei_spi { struct spi_bitbang bitbang; void __iomem *base; - int len; - int count; volatile unsigned int ctrlReg; unsigned int csReg; unsigned int speedReg; - - /* data buffers */ - const unsigned char *tx; - unsigned char *rx; }; static void sei_spi_wait_till_ready(struct sei_spi *hw, int timeout) @@ -120,25 +114,42 @@ static int sei_spi_setup(struct spi_device *spi) static int sei_spi_txrx(struct spi_device *spi, struct spi_transfer *t) { struct sei_spi *hw = spi_master_get_devdata(spi->master); - unsigned char rxByte, txByte; + + void *ctrl = hw->base + CTRL_REG; + void *stat = hw->base + STAT_REG; + void *data = hw->base + DATA_REG; + int timeout; + int xmit = hw->csReg | hw->speedReg | SEI_SPI_CTRL_XMIT; + int status; + + /* data buffers */ + const unsigned char *tx; + unsigned char *rx; + int len; + int count; // pr_info("%s: TXRX cpu=%d\n", __func__, smp_processor_id()); - hw->tx = t->tx_buf; - hw->rx = t->rx_buf; - hw->len = t->len; - - for (hw->count = 0; hw->count < hw->len; hw->count++) { - if (hw->tx) - txByte = hw->tx[hw->count]; - else - txByte = 0; - hw_txbyte(hw, txByte); - rxByte = hw_rxbyte(hw); - if (hw->rx) - hw->rx[hw->count] = rxByte; + tx = t->tx_buf; + rx = t->rx_buf; + len = t->len; +// pr_info("txrx %d\n", len); + + for (count = 0; count < len; count++) { + timeout = SEI_SPI_WAIT_RDY_MAX_LOOP; + do status = readl(stat); + while ((status & SEI_SPI_STAT_BUSY) && timeout--); + + writel(tx ? *tx++ : 0, data); + writel(xmit, ctrl); + + timeout = SEI_SPI_WAIT_RDY_MAX_LOOP; + do status = readl(stat); + while ((status & SEI_SPI_STAT_BUSY) && timeout--); + + if (rx) *rx++ = readl(data); } - return hw->count; + return count; } static int sei_spi_probe(struct platform_device *pdev) |