Commit 35301c99 authored by Geert Uytterhoeven's avatar Geert Uytterhoeven Committed by Mark Brown

spi: rspi: Add rspi_data_{out,in,out_in}() helpers

Add helpers rspi_data_{out,in,out_in}() to write, read, or write and
read data to/from the Data Register, taking care of waiting until data
or space is available in the buffers.
Signed-off-by: default avatarGeert Uytterhoeven <geert+renesas@linux-m68k.org>
Signed-off-by: default avatarMark Brown <broonie@linaro.org>
parent 74da7686
...@@ -356,22 +356,51 @@ static int rspi_wait_for_interrupt(struct rspi_data *rspi, u8 wait_mask, ...@@ -356,22 +356,51 @@ static int rspi_wait_for_interrupt(struct rspi_data *rspi, u8 wait_mask,
return 0; return 0;
} }
static int rspi_data_out(struct rspi_data *rspi, u8 data)
{
if (rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE) < 0) {
dev_err(&rspi->master->dev, "transmit timeout\n");
return -ETIMEDOUT;
}
rspi_write_data(rspi, data);
return 0;
}
static int rspi_data_in(struct rspi_data *rspi)
{
u8 data;
if (rspi_wait_for_interrupt(rspi, SPSR_SPRF, SPCR_SPRIE) < 0) {
dev_err(&rspi->master->dev, "receive timeout\n");
return -ETIMEDOUT;
}
data = rspi_read_data(rspi);
return data;
}
static int rspi_data_out_in(struct rspi_data *rspi, u8 data)
{
int ret;
ret = rspi_data_out(rspi, data);
if (ret < 0)
return ret;
return rspi_data_in(rspi);
}
static int rspi_send_pio(struct rspi_data *rspi, struct spi_transfer *t) static int rspi_send_pio(struct rspi_data *rspi, struct spi_transfer *t)
{ {
int remain = t->len; int remain = t->len, ret;
const u8 *data = t->tx_buf; const u8 *data = t->tx_buf;
while (remain > 0) { while (remain > 0) {
rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) | SPCR_TXMD, rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) | SPCR_TXMD,
RSPI_SPCR); RSPI_SPCR);
if (rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE) < 0) { ret = rspi_data_out(rspi, *data++);
dev_err(&rspi->master->dev, if (ret < 0)
"%s: tx empty timeout\n", __func__); return ret;
return -ETIMEDOUT;
}
rspi_write_data(rspi, *data);
data++;
remain--; remain--;
} }
...@@ -383,28 +412,17 @@ static int rspi_send_pio(struct rspi_data *rspi, struct spi_transfer *t) ...@@ -383,28 +412,17 @@ static int rspi_send_pio(struct rspi_data *rspi, struct spi_transfer *t)
static int qspi_send_pio(struct rspi_data *rspi, struct spi_transfer *t) static int qspi_send_pio(struct rspi_data *rspi, struct spi_transfer *t)
{ {
int remain = t->len; int remain = t->len, ret;
const u8 *data = t->tx_buf; const u8 *data = t->tx_buf;
rspi_write8(rspi, SPBFCR_TXRST, QSPI_SPBFCR); rspi_write8(rspi, SPBFCR_TXRST, QSPI_SPBFCR);
rspi_write8(rspi, 0x00, QSPI_SPBFCR); rspi_write8(rspi, 0x00, QSPI_SPBFCR);
while (remain > 0) { while (remain > 0) {
/* dummy read */
if (rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE) < 0) { ret = rspi_data_out_in(rspi, *data++);
dev_err(&rspi->master->dev, if (ret < 0)
"%s: tx empty timeout\n", __func__); return ret;
return -ETIMEDOUT;
}
rspi_write_data(rspi, *data++);
if (rspi_wait_for_interrupt(rspi, SPSR_SPRF, SPCR_SPRIE) < 0) {
dev_err(&rspi->master->dev,
"%s: receive timeout\n", __func__);
return -ETIMEDOUT;
}
rspi_read_data(rspi);
remain--; remain--;
} }
...@@ -549,32 +567,20 @@ static void rspi_receive_init(const struct rspi_data *rspi) ...@@ -549,32 +567,20 @@ static void rspi_receive_init(const struct rspi_data *rspi)
static int rspi_receive_pio(struct rspi_data *rspi, struct spi_transfer *t) static int rspi_receive_pio(struct rspi_data *rspi, struct spi_transfer *t)
{ {
int remain = t->len; int remain = t->len, ret;
u8 *data; u8 *data = t->rx_buf;
rspi_receive_init(rspi); rspi_receive_init(rspi);
data = t->rx_buf;
while (remain > 0) { while (remain > 0) {
rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) & ~SPCR_TXMD, rspi_write8(rspi, rspi_read8(rspi, RSPI_SPCR) & ~SPCR_TXMD,
RSPI_SPCR); RSPI_SPCR);
if (rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE) < 0) { /* dummy write data for generate clock */
dev_err(&rspi->master->dev, ret = rspi_data_out_in(rspi, DUMMY_DATA);
"%s: tx empty timeout\n", __func__); if (ret < 0)
return -ETIMEDOUT; return ret;
} *data++ = ret;
/* dummy write for generate clock */
rspi_write_data(rspi, DUMMY_DATA);
if (rspi_wait_for_interrupt(rspi, SPSR_SPRF, SPCR_SPRIE) < 0) {
dev_err(&rspi->master->dev,
"%s: receive timeout\n", __func__);
return -ETIMEDOUT;
}
*data = rspi_read_data(rspi);
data++;
remain--; remain--;
} }
...@@ -594,28 +600,17 @@ static void qspi_receive_init(const struct rspi_data *rspi) ...@@ -594,28 +600,17 @@ static void qspi_receive_init(const struct rspi_data *rspi)
static int qspi_receive_pio(struct rspi_data *rspi, struct spi_transfer *t) static int qspi_receive_pio(struct rspi_data *rspi, struct spi_transfer *t)
{ {
int remain = t->len; int remain = t->len, ret;
u8 *data; u8 *data = t->rx_buf;
qspi_receive_init(rspi); qspi_receive_init(rspi);
data = t->rx_buf;
while (remain > 0) { while (remain > 0) {
if (rspi_wait_for_interrupt(rspi, SPSR_SPTEF, SPCR_SPTIE) < 0) {
dev_err(&rspi->master->dev,
"%s: tx empty timeout\n", __func__);
return -ETIMEDOUT;
}
/* dummy write for generate clock */ /* dummy write for generate clock */
rspi_write_data(rspi, DUMMY_DATA); ret = rspi_data_out_in(rspi, DUMMY_DATA);
if (ret < 0)
if (rspi_wait_for_interrupt(rspi, SPSR_SPRF, SPCR_SPRIE) < 0) { return ret;
dev_err(&rspi->master->dev, *data++ = ret;
"%s: receive timeout\n", __func__);
return -ETIMEDOUT;
}
*data++ = rspi_read_data(rspi);
remain--; remain--;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment