From: "Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>
To: barebox@lists.infradead.org
Subject: [PATCH 2/2] spi: imx: add timeout to xchg_single
Date: Wed, 2 Aug 2017 21:39:07 +0200 [thread overview]
Message-ID: <20170802193907.4317-3-u.kleine-koenig@pengutronix.de> (raw)
In-Reply-To: <20170802193907.4317-1-u.kleine-koenig@pengutronix.de>
If there is a problem STAT_RR might never be set which results in an endless loop.
Break out after 10 µs with -ETIMEOUT instead.
Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de>
---
drivers/spi/imx_spi.c | 28 ++++++++++++++++++++++++----
1 file changed, 24 insertions(+), 4 deletions(-)
diff --git a/drivers/spi/imx_spi.c b/drivers/spi/imx_spi.c
index 97a2091969dd..78198798a57e 100644
--- a/drivers/spi/imx_spi.c
+++ b/drivers/spi/imx_spi.c
@@ -32,6 +32,9 @@
#include <linux/err.h>
#include <clock.h>
+/* time to wait for STAT_RR getting set */
+#define IMX_SPI_RR_TIMEOUT 10000 /* ns */
+
struct imx_spi {
struct spi_master master;
int *cs_array;
@@ -89,6 +92,7 @@ static unsigned int imx_spi_maybe_reverse_bits(struct spi_device *spi, unsigned
static int cspi_0_0_xchg_single(struct imx_spi *imx, u32 txdata, u32 *rxdata)
{
void __iomem *base = imx->regs;
+ int ret;
unsigned int cfg_reg = readl(base + CSPI_0_0_CTRL);
@@ -98,7 +102,12 @@ static int cspi_0_0_xchg_single(struct imx_spi *imx, u32 txdata, u32 *rxdata)
writel(cfg_reg, base + CSPI_0_0_CTRL);
- while (!(readl(base + CSPI_0_0_INT) & CSPI_0_0_STAT_RR));
+ ret = wait_on_timeout(IMX_SPI_RR_TIMEOUT,
+ readl(base + CSPI_0_0_INT) & CSPI_0_0_STAT_RR);
+ if (ret) {
+ dev_err(imx->master.dev, "Timeout waiting for received data\n");
+ return ret;
+ }
*rxdata = readl(base + CSPI_0_0_RXDATA);
@@ -157,6 +166,7 @@ static void cspi_0_0_init(struct imx_spi *imx)
static int cspi_0_7_xchg_single(struct imx_spi *imx, u32 txdata, u32 *rxdata)
{
void __iomem *base = imx->regs;
+ int ret;
unsigned int cfg_reg = readl(base + CSPI_0_7_CTRL);
@@ -166,8 +176,12 @@ static int cspi_0_7_xchg_single(struct imx_spi *imx, u32 txdata, u32 *rxdata)
writel(cfg_reg, base + CSPI_0_7_CTRL);
- while (!(readl(base + CSPI_0_7_STAT) & CSPI_0_7_STAT_RR))
- ;
+ ret = wait_on_timeout(IMX_SPI_RR_TIMEOUT,
+ readl(base + CSPI_0_7_STAT) & CSPI_0_7_STAT_RR);
+ if (ret) {
+ dev_err(imx->master.dev, "Timeout waiting for received data\n");
+ return ret;
+ }
*rxdata = readl(base + CSPI_0_7_RXDATA);
return 0;
@@ -248,10 +262,16 @@ static void cspi_0_7_init(struct imx_spi *imx)
static int cspi_2_3_xchg_single(struct imx_spi *imx, u32 txdata, u32 *rxdata)
{
void __iomem *base = imx->regs;
+ int ret;
writel(txdata, base + CSPI_2_3_TXDATA);
- while (!(readl(base + CSPI_2_3_STAT) & CSPI_2_3_STAT_RR));
+ ret = wait_on_timeout(IMX_SPI_RR_TIMEOUT,
+ readl(base + CSPI_2_3_STAT) & CSPI_2_3_STAT_RR);
+ if (ret) {
+ dev_err(imx->master.dev, "Timeout waiting for received data\n");
+ return ret;
+ }
*rxdata = readl(base + CSPI_2_3_RXDATA);
--
2.11.0
_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox
next prev parent reply other threads:[~2017-08-02 19:39 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-02 19:39 [PATCH 0/2] spi: imx: don't loop endlessly Uwe Kleine-König
2017-08-02 19:39 ` [PATCH 1/2] spi: imx: add error checking Uwe Kleine-König
2017-08-02 19:39 ` Uwe Kleine-König [this message]
2017-08-02 19:54 ` [PATCH 0/2] spi: imx: don't loop endlessly Sam Ravnborg
2017-08-02 20:19 ` Uwe Kleine-König
2017-08-02 20:32 ` Sam Ravnborg
2017-08-03 9:07 ` Uwe Kleine-König
2017-08-03 10:43 ` Sam Ravnborg
2017-08-03 18:41 ` Uwe Kleine-König
2017-09-29 18:08 ` Alexander Kurz
2017-10-02 5:31 ` Uwe Kleine-König
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20170802193907.4317-3-u.kleine-koenig@pengutronix.de \
--to=u.kleine-koenig@pengutronix.de \
--cc=barebox@lists.infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox