* [PATCH] spi: ti-qspi: Simplify qspi_write_msg and qspi_read_msg implementation
@ 2014-01-12 6:40 Axel Lin
2014-01-12 8:26 ` sourav
2014-01-13 10:15 ` Mark Brown
0 siblings, 2 replies; 3+ messages in thread
From: Axel Lin @ 2014-01-12 6:40 UTC (permalink / raw)
To: Mark Brown; +Cc: Sourav Poddar, linux-spi-u79uwXL29TY76Z2rM5mHXA
Make the unit of wlen to be byte, and simplify the code to avoid duplicate
code for different wlen cases.
Signed-off-by: Axel Lin <axel.lin-8E1dMatC8ynQT0dZR+AlfA@public.gmane.org>
---
drivers/spi/spi-ti-qspi.c | 61 ++++++++++++++++-------------------------------
1 file changed, 20 insertions(+), 41 deletions(-)
diff --git a/drivers/spi/spi-ti-qspi.c b/drivers/spi/spi-ti-qspi.c
index 4b413e9..2a1ab49 100644
--- a/drivers/spi/spi-ti-qspi.c
+++ b/drivers/spi/spi-ti-qspi.c
@@ -208,53 +208,36 @@ static int qspi_write_msg(struct ti_qspi *qspi, struct spi_transfer *t)
txbuf = t->tx_buf;
cmd = qspi->cmd | QSPI_WR_SNGL;
count = t->len;
- wlen = t->bits_per_word;
+ wlen = t->bits_per_word >> 3; /* in bytes */
while (count) {
switch (wlen) {
- case 8:
+ case 1:
dev_dbg(qspi->dev, "tx cmd %08x dc %08x data %02x\n",
cmd, qspi->dc, *txbuf);
writeb(*txbuf, qspi->base + QSPI_SPI_DATA_REG);
- ti_qspi_write(qspi, cmd, QSPI_SPI_CMD_REG);
- ret = wait_for_completion_timeout(&qspi->transfer_complete,
- QSPI_COMPLETION_TIMEOUT);
- if (ret == 0) {
- dev_err(qspi->dev, "write timed out\n");
- return -ETIMEDOUT;
- }
- txbuf += 1;
- count -= 1;
break;
- case 16:
+ case 2:
dev_dbg(qspi->dev, "tx cmd %08x dc %08x data %04x\n",
cmd, qspi->dc, *txbuf);
writew(*((u16 *)txbuf), qspi->base + QSPI_SPI_DATA_REG);
- ti_qspi_write(qspi, cmd, QSPI_SPI_CMD_REG);
- ret = wait_for_completion_timeout(&qspi->transfer_complete,
- QSPI_COMPLETION_TIMEOUT);
- if (ret == 0) {
- dev_err(qspi->dev, "write timed out\n");
- return -ETIMEDOUT;
- }
- txbuf += 2;
- count -= 2;
break;
- case 32:
+ case 4:
dev_dbg(qspi->dev, "tx cmd %08x dc %08x data %08x\n",
cmd, qspi->dc, *txbuf);
writel(*((u32 *)txbuf), qspi->base + QSPI_SPI_DATA_REG);
- ti_qspi_write(qspi, cmd, QSPI_SPI_CMD_REG);
- ret = wait_for_completion_timeout(&qspi->transfer_complete,
- QSPI_COMPLETION_TIMEOUT);
- if (ret == 0) {
- dev_err(qspi->dev, "write timed out\n");
- return -ETIMEDOUT;
- }
- txbuf += 4;
- count -= 4;
break;
}
+
+ ti_qspi_write(qspi, cmd, QSPI_SPI_CMD_REG);
+ ret = wait_for_completion_timeout(&qspi->transfer_complete,
+ QSPI_COMPLETION_TIMEOUT);
+ if (ret == 0) {
+ dev_err(qspi->dev, "write timed out\n");
+ return -ETIMEDOUT;
+ }
+ txbuf += wlen;
+ count -= wlen;
}
return 0;
@@ -280,7 +263,7 @@ static int qspi_read_msg(struct ti_qspi *qspi, struct spi_transfer *t)
break;
}
count = t->len;
- wlen = t->bits_per_word;
+ wlen = t->bits_per_word >> 3; /* in bytes */
while (count) {
dev_dbg(qspi->dev, "rx cmd %08x dc %08x\n", cmd, qspi->dc);
@@ -292,22 +275,18 @@ static int qspi_read_msg(struct ti_qspi *qspi, struct spi_transfer *t)
return -ETIMEDOUT;
}
switch (wlen) {
- case 8:
+ case 1:
*rxbuf = readb(qspi->base + QSPI_SPI_DATA_REG);
- rxbuf += 1;
- count -= 1;
break;
- case 16:
+ case 2:
*((u16 *)rxbuf) = readw(qspi->base + QSPI_SPI_DATA_REG);
- rxbuf += 2;
- count -= 2;
break;
- case 32:
+ case 4:
*((u32 *)rxbuf) = readl(qspi->base + QSPI_SPI_DATA_REG);
- rxbuf += 4;
- count -= 4;
break;
}
+ rxbuf += wlen;
+ count -= wlen;
}
return 0;
--
1.8.1.2
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] spi: ti-qspi: Simplify qspi_write_msg and qspi_read_msg implementation
2014-01-12 6:40 [PATCH] spi: ti-qspi: Simplify qspi_write_msg and qspi_read_msg implementation Axel Lin
@ 2014-01-12 8:26 ` sourav
2014-01-13 10:15 ` Mark Brown
1 sibling, 0 replies; 3+ messages in thread
From: sourav @ 2014-01-12 8:26 UTC (permalink / raw)
To: Axel Lin; +Cc: Mark Brown, linux-spi-u79uwXL29TY76Z2rM5mHXA
On Sunday 12 January 2014 12:10 PM, Axel Lin wrote:
> Make the unit of wlen to be byte, and simplify the code to avoid duplicate
> code for different wlen cases.
>
> Signed-off-by: Axel Lin<axel.lin-8E1dMatC8ynQT0dZR+AlfA@public.gmane.org>
> ---
> drivers/spi/spi-ti-qspi.c | 61 ++++++++++++++++-------------------------------
> 1 file changed, 20 insertions(+), 41 deletions(-)
>
> diff --git a/drivers/spi/spi-ti-qspi.c b/drivers/spi/spi-ti-qspi.c
> index 4b413e9..2a1ab49 100644
> --- a/drivers/spi/spi-ti-qspi.c
> +++ b/drivers/spi/spi-ti-qspi.c
> @@ -208,53 +208,36 @@ static int qspi_write_msg(struct ti_qspi *qspi, struct spi_transfer *t)
> txbuf = t->tx_buf;
> cmd = qspi->cmd | QSPI_WR_SNGL;
> count = t->len;
> - wlen = t->bits_per_word;
> + wlen = t->bits_per_word>> 3; /* in bytes */
>
> while (count) {
> switch (wlen) {
> - case 8:
> + case 1:
> dev_dbg(qspi->dev, "tx cmd %08x dc %08x data %02x\n",
> cmd, qspi->dc, *txbuf);
> writeb(*txbuf, qspi->base + QSPI_SPI_DATA_REG);
> - ti_qspi_write(qspi, cmd, QSPI_SPI_CMD_REG);
> - ret = wait_for_completion_timeout(&qspi->transfer_complete,
> - QSPI_COMPLETION_TIMEOUT);
> - if (ret == 0) {
> - dev_err(qspi->dev, "write timed out\n");
> - return -ETIMEDOUT;
> - }
> - txbuf += 1;
> - count -= 1;
> break;
> - case 16:
> + case 2:
> dev_dbg(qspi->dev, "tx cmd %08x dc %08x data %04x\n",
> cmd, qspi->dc, *txbuf);
> writew(*((u16 *)txbuf), qspi->base + QSPI_SPI_DATA_REG);
> - ti_qspi_write(qspi, cmd, QSPI_SPI_CMD_REG);
> - ret = wait_for_completion_timeout(&qspi->transfer_complete,
> - QSPI_COMPLETION_TIMEOUT);
> - if (ret == 0) {
> - dev_err(qspi->dev, "write timed out\n");
> - return -ETIMEDOUT;
> - }
> - txbuf += 2;
> - count -= 2;
> break;
> - case 32:
> + case 4:
> dev_dbg(qspi->dev, "tx cmd %08x dc %08x data %08x\n",
> cmd, qspi->dc, *txbuf);
> writel(*((u32 *)txbuf), qspi->base + QSPI_SPI_DATA_REG);
> - ti_qspi_write(qspi, cmd, QSPI_SPI_CMD_REG);
> - ret = wait_for_completion_timeout(&qspi->transfer_complete,
> - QSPI_COMPLETION_TIMEOUT);
> - if (ret == 0) {
> - dev_err(qspi->dev, "write timed out\n");
> - return -ETIMEDOUT;
> - }
> - txbuf += 4;
> - count -= 4;
> break;
> }
> +
> + ti_qspi_write(qspi, cmd, QSPI_SPI_CMD_REG);
> + ret = wait_for_completion_timeout(&qspi->transfer_complete,
> + QSPI_COMPLETION_TIMEOUT);
> + if (ret == 0) {
> + dev_err(qspi->dev, "write timed out\n");
> + return -ETIMEDOUT;
> + }
> + txbuf += wlen;
> + count -= wlen;
> }
>
> return 0;
> @@ -280,7 +263,7 @@ static int qspi_read_msg(struct ti_qspi *qspi, struct spi_transfer *t)
> break;
> }
> count = t->len;
> - wlen = t->bits_per_word;
> + wlen = t->bits_per_word>> 3; /* in bytes */
>
> while (count) {
> dev_dbg(qspi->dev, "rx cmd %08x dc %08x\n", cmd, qspi->dc);
> @@ -292,22 +275,18 @@ static int qspi_read_msg(struct ti_qspi *qspi, struct spi_transfer *t)
> return -ETIMEDOUT;
> }
> switch (wlen) {
> - case 8:
> + case 1:
> *rxbuf = readb(qspi->base + QSPI_SPI_DATA_REG);
> - rxbuf += 1;
> - count -= 1;
> break;
> - case 16:
> + case 2:
> *((u16 *)rxbuf) = readw(qspi->base + QSPI_SPI_DATA_REG);
> - rxbuf += 2;
> - count -= 2;
> break;
> - case 32:
> + case 4:
> *((u32 *)rxbuf) = readl(qspi->base + QSPI_SPI_DATA_REG);
> - rxbuf += 4;
> - count -= 4;
> break;
> }
> + rxbuf += wlen;
> + count -= wlen;
> }
>
> return 0;
Acked-by: Sourav Poddar <sourav.poddar-l0cyMroinI0@public.gmane.org>
--
To unsubscribe from this list: send the line "unsubscribe linux-spi" in
the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] spi: ti-qspi: Simplify qspi_write_msg and qspi_read_msg implementation
2014-01-12 6:40 [PATCH] spi: ti-qspi: Simplify qspi_write_msg and qspi_read_msg implementation Axel Lin
2014-01-12 8:26 ` sourav
@ 2014-01-13 10:15 ` Mark Brown
1 sibling, 0 replies; 3+ messages in thread
From: Mark Brown @ 2014-01-13 10:15 UTC (permalink / raw)
To: Axel Lin; +Cc: Sourav Poddar, linux-spi-u79uwXL29TY76Z2rM5mHXA
[-- Attachment #1: Type: text/plain, Size: 186 bytes --]
On Sun, Jan 12, 2014 at 02:40:22PM +0800, Axel Lin wrote:
> Make the unit of wlen to be byte, and simplify the code to avoid duplicate
> code for different wlen cases.
Applied, thanks.
[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2014-01-13 10:15 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-12 6:40 [PATCH] spi: ti-qspi: Simplify qspi_write_msg and qspi_read_msg implementation Axel Lin
2014-01-12 8:26 ` sourav
2014-01-13 10:15 ` Mark Brown
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).