All of lore.kernel.org
 help / color / mirror / Atom feed
From: Michal Suchanek <hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
To: linux-sunxi-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org,
	stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Pawel Moll <pawel.moll-5wv7dgnIgG8@public.gmane.org>,
	Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org>,
	Ian Campbell
	<ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg@public.gmane.org>,
	Kumar Gala <galak-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>,
	Maxime Ripard
	<maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org>,
	Chen-Yu Tsai <wens-jdAy2FN1RRM@public.gmane.org>,
	Russell King <linux-I+IVW8TIWO2tmTQ+vhA3Yw@public.gmane.org>,
	Mark Brown <broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Michal Suchanek
	<hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Arnd Bergmann <arnd-r2nGTMty4D4@public.gmane.org>,
	Olof Johansson <olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org>,
	Krzysztof Kozlowski
	<k.kozlowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>,
	Javier Martinez Canillas
	<javier-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org>,
	Simon Horman
	<horms+renesas-/R6kz+dDXgpPR4JQBCEnsQ@public.gmane.org>,
	Sjoerd Simons
	<sjoerd.simons-ZGY8ohtN/8pPYcu2f3hruQ@public.gmane.org>,
	Thierry Reding <treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org>,
	Alison Wang <b18965-KZfg59tc24xl57MIdRCFDg@public.gmane.org>,
	Timo Sigurdsson
	<public_timo.s-fWgRPtSzPNU3WX+qO2AYSQ@public.gmane.org>,
	Jonathan Liu <net147-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Gerhard Bertelsmann <info@gerh>
Subject: [PATCH v3 02/13] spi: sunxi: fix transfer timeout
Date: 13 Jun 2016 17:46:49 -0000	[thread overview]
Message-ID: <064955d033503f129c3e138b0563817d1fffab27.1465490774.git.hramrach@gmail.com> (raw)
In-Reply-To: <cover.1465490774.git.hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>

The trasfer timeout is fixed at 1000 ms. Reading a 4Mbyte flash over
1MHz SPI bus takes way longer than that. Calculate the timeout from the
actual time the transfer is supposed to take and multiply by 2 for good
measure.

Signed-off-by: Michal Suchanek <hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---

v2:
- fix build error
- use unsigned instead of int in max_t
- use tfr->speed_hz instead of sspi->max_speed_hz
  - commit 47284e3e0f3c427c93f8583549b6c938e8a18015 changes the driver
    to use tfr->speed_hz
v3:
- avoid max_t by using unsigned constant
---
 drivers/spi/spi-sun4i.c | 10 +++++++++-
 drivers/spi/spi-sun6i.c | 10 +++++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-sun4i.c b/drivers/spi/spi-sun4i.c
index 4213508..0c2216a 100644
--- a/drivers/spi/spi-sun4i.c
+++ b/drivers/spi/spi-sun4i.c
@@ -173,6 +173,7 @@ static int sun4i_spi_transfer_one(struct spi_master *master,
 {
 	struct sun4i_spi *sspi = spi_master_get_devdata(master);
 	unsigned int mclk_rate, div, timeout;
+	unsigned int start, end, tx_time;
 	unsigned int tx_len = 0;
 	int ret = 0;
 	u32 reg;
@@ -279,9 +280,16 @@ static int sun4i_spi_transfer_one(struct spi_master *master,
 	reg = sun4i_spi_read(sspi, SUN4I_CTL_REG);
 	sun4i_spi_write(sspi, SUN4I_CTL_REG, reg | SUN4I_CTL_XCH);
 
+	tx_time = max(tfr->len * 8 * 2 / (tfr->speed_hz / 1000), 100U);
+	start = jiffies;
 	timeout = wait_for_completion_timeout(&sspi->done,
-					      msecs_to_jiffies(1000));
+					      msecs_to_jiffies(tx_time));
+	end = jiffies;
 	if (!timeout) {
+		dev_warn(&master->dev,
+			 "%s: timeout transferring %u bytes@%iHz for %i(%i)ms",
+			 dev_name(&spi->dev), tfr->len, tfr->speed_hz,
+			 jiffies_to_msecs(end - start), tx_time);
 		ret = -ETIMEDOUT;
 		goto out;
 	}
diff --git a/drivers/spi/spi-sun6i.c b/drivers/spi/spi-sun6i.c
index fe70695..8f6be86 100644
--- a/drivers/spi/spi-sun6i.c
+++ b/drivers/spi/spi-sun6i.c
@@ -160,6 +160,7 @@ static int sun6i_spi_transfer_one(struct spi_master *master,
 {
 	struct sun6i_spi *sspi = spi_master_get_devdata(master);
 	unsigned int mclk_rate, div, timeout;
+	unsigned int start, end, tx_time;
 	unsigned int tx_len = 0;
 	int ret = 0;
 	u32 reg;
@@ -269,9 +270,16 @@ static int sun6i_spi_transfer_one(struct spi_master *master,
 	reg = sun6i_spi_read(sspi, SUN6I_TFR_CTL_REG);
 	sun6i_spi_write(sspi, SUN6I_TFR_CTL_REG, reg | SUN6I_TFR_CTL_XCH);
 
+	tx_time = max(tfr->len * 8 * 2 / (tfr->speed_hz / 1000), 100U);
+	start = jiffies;
 	timeout = wait_for_completion_timeout(&sspi->done,
-					      msecs_to_jiffies(1000));
+					      msecs_to_jiffies(tx_time));
+	end = jiffies;
 	if (!timeout) {
+		dev_warn(&master->dev,
+			 "%s: timeout transferring %u bytes@%iHz for %i(%i)ms",
+			 dev_name(&spi->dev), tfr->len, tfr->speed_hz,
+			 jiffies_to_msecs(end - start), tx_time);
 		ret = -ETIMEDOUT;
 		goto out;
 	}
-- 
2.8.1

WARNING: multiple messages have this Message-ID (diff)
From: hramrach@gmail.com (Michal Suchanek)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v3 02/13] spi: sunxi: fix transfer timeout
Date: 13 Jun 2016 17:46:49 -0000	[thread overview]
Message-ID: <064955d033503f129c3e138b0563817d1fffab27.1465490774.git.hramrach@gmail.com> (raw)
In-Reply-To: <cover.1465490774.git.hramrach@gmail.com>

The trasfer timeout is fixed at 1000 ms. Reading a 4Mbyte flash over
1MHz SPI bus takes way longer than that. Calculate the timeout from the
actual time the transfer is supposed to take and multiply by 2 for good
measure.

Signed-off-by: Michal Suchanek <hramrach@gmail.com>
---

v2:
- fix build error
- use unsigned instead of int in max_t
- use tfr->speed_hz instead of sspi->max_speed_hz
  - commit 47284e3e0f3c427c93f8583549b6c938e8a18015 changes the driver
    to use tfr->speed_hz
v3:
- avoid max_t by using unsigned constant
---
 drivers/spi/spi-sun4i.c | 10 +++++++++-
 drivers/spi/spi-sun6i.c | 10 +++++++++-
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/drivers/spi/spi-sun4i.c b/drivers/spi/spi-sun4i.c
index 4213508..0c2216a 100644
--- a/drivers/spi/spi-sun4i.c
+++ b/drivers/spi/spi-sun4i.c
@@ -173,6 +173,7 @@ static int sun4i_spi_transfer_one(struct spi_master *master,
 {
 	struct sun4i_spi *sspi = spi_master_get_devdata(master);
 	unsigned int mclk_rate, div, timeout;
+	unsigned int start, end, tx_time;
 	unsigned int tx_len = 0;
 	int ret = 0;
 	u32 reg;
@@ -279,9 +280,16 @@ static int sun4i_spi_transfer_one(struct spi_master *master,
 	reg = sun4i_spi_read(sspi, SUN4I_CTL_REG);
 	sun4i_spi_write(sspi, SUN4I_CTL_REG, reg | SUN4I_CTL_XCH);
 
+	tx_time = max(tfr->len * 8 * 2 / (tfr->speed_hz / 1000), 100U);
+	start = jiffies;
 	timeout = wait_for_completion_timeout(&sspi->done,
-					      msecs_to_jiffies(1000));
+					      msecs_to_jiffies(tx_time));
+	end = jiffies;
 	if (!timeout) {
+		dev_warn(&master->dev,
+			 "%s: timeout transferring %u bytes@%iHz for %i(%i)ms",
+			 dev_name(&spi->dev), tfr->len, tfr->speed_hz,
+			 jiffies_to_msecs(end - start), tx_time);
 		ret = -ETIMEDOUT;
 		goto out;
 	}
diff --git a/drivers/spi/spi-sun6i.c b/drivers/spi/spi-sun6i.c
index fe70695..8f6be86 100644
--- a/drivers/spi/spi-sun6i.c
+++ b/drivers/spi/spi-sun6i.c
@@ -160,6 +160,7 @@ static int sun6i_spi_transfer_one(struct spi_master *master,
 {
 	struct sun6i_spi *sspi = spi_master_get_devdata(master);
 	unsigned int mclk_rate, div, timeout;
+	unsigned int start, end, tx_time;
 	unsigned int tx_len = 0;
 	int ret = 0;
 	u32 reg;
@@ -269,9 +270,16 @@ static int sun6i_spi_transfer_one(struct spi_master *master,
 	reg = sun6i_spi_read(sspi, SUN6I_TFR_CTL_REG);
 	sun6i_spi_write(sspi, SUN6I_TFR_CTL_REG, reg | SUN6I_TFR_CTL_XCH);
 
+	tx_time = max(tfr->len * 8 * 2 / (tfr->speed_hz / 1000), 100U);
+	start = jiffies;
 	timeout = wait_for_completion_timeout(&sspi->done,
-					      msecs_to_jiffies(1000));
+					      msecs_to_jiffies(tx_time));
+	end = jiffies;
 	if (!timeout) {
+		dev_warn(&master->dev,
+			 "%s: timeout transferring %u bytes@%iHz for %i(%i)ms",
+			 dev_name(&spi->dev), tfr->len, tfr->speed_hz,
+			 jiffies_to_msecs(end - start), tx_time);
 		ret = -ETIMEDOUT;
 		goto out;
 	}
-- 
2.8.1

  parent reply	other threads:[~2016-06-13 17:46 UTC|newest]

Thread overview: 121+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-13 17:46 [PATCH v3 00/13] sunxi spi fixes Michal Suchanek
2016-06-13 17:46 ` Michal Suchanek
2016-06-13 17:46 ` [PATCH v3 01/13] spi: sunxi: set maximum and minimum speed of SPI master Michal Suchanek
2016-06-13 17:46   ` Michal Suchanek
2016-06-13 19:55   ` Maxime Ripard
2016-06-13 19:55     ` Maxime Ripard
2016-06-13 19:55     ` Maxime Ripard
2016-06-13 17:46 ` [PATCH v3 04/13] spi: sunxi: expose maximum transfer size limit Michal Suchanek
2016-06-13 17:46   ` Michal Suchanek
2016-06-13 19:56   ` Maxime Ripard
2016-06-13 19:56     ` Maxime Ripard
2016-06-13 19:56     ` Maxime Ripard
     [not found] ` <cover.1465490774.git.hramrach-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
2016-06-13 17:46   ` [PATCH v3 03/13] spi: sun4i: fix FIFO limit Michal Suchanek
2016-06-13 17:46     ` Michal Suchanek
2016-06-13 19:56     ` Maxime Ripard
2016-06-13 19:56       ` Maxime Ripard
2016-06-13 19:56       ` Maxime Ripard
2016-06-13 17:46   ` Michal Suchanek [this message]
2016-06-13 17:46     ` [PATCH v3 02/13] spi: sunxi: fix transfer timeout Michal Suchanek
2016-06-13 19:55     ` Maxime Ripard
2016-06-13 19:55       ` Maxime Ripard
2016-06-13 19:55       ` Maxime Ripard
2016-06-13 17:46   ` [PATCH v3 06/13] spi: sunxi: rename sun4i,sun6i -> sunxi Michal Suchanek
2016-06-13 17:46     ` Michal Suchanek
2016-06-13 17:46   ` [PATCH v3 05/13] spi: sun6i: update CS handling from spi-sun4i Michal Suchanek
2016-06-13 17:46     ` Michal Suchanek
2016-06-13 17:46   ` [PATCH v3 08/13] spi: sunxi: synchronize whitespace, comments, struct Michal Suchanek
2016-06-13 17:46     ` Michal Suchanek
2016-06-13 17:46   ` [PATCH v3 09/13] spi: sunxi: use register map Michal Suchanek
2016-06-13 17:46     ` Michal Suchanek
2016-06-13 17:46   ` [PATCH v3 07/13] spi: sunxi: rename constants to match between sun4i and sun6i Michal Suchanek
2016-06-13 17:46     ` Michal Suchanek
2016-06-13 23:31     ` [linux-sunxi] " Julian Calaby
2016-06-13 23:31       ` Julian Calaby
2016-06-13 23:31       ` Julian Calaby
2016-06-13 23:31       ` Julian Calaby
2016-06-14  4:43       ` [linux-sunxi] " Michal Suchanek
2016-06-14  4:43         ` Michal Suchanek
2016-06-14  4:43         ` Michal Suchanek
2016-06-14  4:43         ` Michal Suchanek
2016-06-13 17:46   ` [PATCH v3 11/13] dt: spi: sun4i: merge sun4i and sun6i binding doc Michal Suchanek
2016-06-13 17:46     ` Michal Suchanek
2016-06-13 23:45     ` [linux-sunxi] " Julian Calaby
2016-06-13 23:45       ` Julian Calaby
2016-06-13 23:45       ` Julian Calaby
2016-06-13 23:45       ` Julian Calaby
2016-06-14  4:40       ` [linux-sunxi] " Michal Suchanek
2016-06-14  4:40         ` Michal Suchanek
2016-06-14  4:40         ` Michal Suchanek
2016-06-14  4:40         ` Michal Suchanek
2016-06-14  4:48         ` [linux-sunxi] " Julian Calaby
2016-06-14  4:48           ` Julian Calaby
2016-06-14  4:48           ` Julian Calaby
2016-06-14  4:48           ` Julian Calaby
2016-06-13 17:46   ` [PATCH v3 10/13] spi: sunxi: merge sun4i and sun6i SPI driver Michal Suchanek
2016-06-13 17:46     ` Michal Suchanek
2016-06-13 23:43     ` [linux-sunxi] " Julian Calaby
2016-06-13 23:43       ` Julian Calaby
2016-06-13 23:43       ` Julian Calaby
2016-06-13 23:43       ` Julian Calaby
2016-06-14  4:34       ` [linux-sunxi] " Michal Suchanek
2016-06-14  4:34         ` Michal Suchanek
2016-06-14  4:34         ` Michal Suchanek
2016-06-14  4:34         ` Michal Suchanek
2016-06-14  4:47         ` [linux-sunxi] " Julian Calaby
2016-06-14  4:47           ` Julian Calaby
2016-06-14  4:47           ` Julian Calaby
2016-06-14  4:47           ` Julian Calaby
2016-06-14  5:28           ` [linux-sunxi] " Michal Suchanek
2016-06-14  5:28             ` Michal Suchanek
2016-06-14  5:28             ` Michal Suchanek
2016-06-14  5:28             ` Michal Suchanek
2016-06-14  5:45             ` [linux-sunxi] " Julian Calaby
2016-06-14  5:45               ` Julian Calaby
2016-06-14  5:45               ` Julian Calaby
2016-06-14  5:45               ` Julian Calaby
2016-06-14  6:35               ` Michal Suchanek
2016-06-14  6:35                 ` Michal Suchanek
2016-06-14  6:35                 ` Michal Suchanek
2016-06-14  6:35                 ` Michal Suchanek
2016-06-14 11:20                 ` [linux-sunxi] " Julian Calaby
2016-06-14 11:20                   ` Julian Calaby
2016-06-14 11:20                   ` Julian Calaby
2016-06-14 11:20                   ` Julian Calaby
2016-06-13 17:46   ` [PATCH v3 13/13] spi: sun4i: add DMA support Michal
2016-06-13 17:46     ` Michal
2016-06-13 17:46   ` [PATCH v3 12/13] spi: sunxi: remove CONFIG_SPI_SUN6I Michal Suchanek
2016-06-13 17:46     ` Michal Suchanek
2016-06-13 19:57 ` [PATCH v3 00/13] sunxi spi fixes Maxime Ripard
2016-06-13 19:57   ` Maxime Ripard
2016-06-13 19:57   ` Maxime Ripard
2016-06-14  4:50   ` Michal Suchanek
2016-06-14  4:50     ` Michal Suchanek
2016-06-14  4:50     ` Michal Suchanek
2016-06-14  4:50     ` Michal Suchanek
2016-06-14  4:50     ` Michal Suchanek
2016-06-17 10:34   ` Michal Suchanek
2016-06-17 10:34     ` Michal Suchanek
2016-06-17 10:34     ` Michal Suchanek
2016-06-17 10:34     ` Michal Suchanek
2016-06-17 10:34     ` Michal Suchanek
2016-07-25  7:32     ` Maxime Ripard
2016-07-25  7:32       ` Maxime Ripard
2016-07-25  7:32       ` Maxime Ripard
2016-07-25  7:32       ` Maxime Ripard
2016-07-25  7:32       ` Maxime Ripard
2016-07-25  8:03       ` Michal Suchanek
2016-07-25  8:03         ` Michal Suchanek
2016-07-25  8:03         ` Michal Suchanek
2016-07-25  8:03         ` Michal Suchanek
2016-07-25  8:03         ` Michal Suchanek
2016-07-29 20:22         ` Maxime Ripard
2016-07-29 20:22           ` Maxime Ripard
2016-07-29 20:22           ` Maxime Ripard
2016-07-29 20:22           ` Maxime Ripard
2016-07-29 20:22           ` Maxime Ripard
2016-07-30 17:32           ` Michal Suchanek
2016-07-30 17:32             ` Michal Suchanek
2016-07-30 17:32             ` Michal Suchanek
2016-07-30 17:32             ` Michal Suchanek
2016-07-30 17:32             ` Michal Suchanek

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=064955d033503f129c3e138b0563817d1fffab27.1465490774.git.hramrach@gmail.com \
    --to=hramrach-re5jqeeqqe8avxtiumwx3w@public.gmane.org \
    --cc=arnd-r2nGTMty4D4@public.gmane.org \
    --cc=b18965-KZfg59tc24xl57MIdRCFDg@public.gmane.org \
    --cc=broonie-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=galak-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
    --cc=horms+renesas-/R6kz+dDXgpPR4JQBCEnsQ@public.gmane.org \
    --cc=ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg@public.gmane.org \
    --cc=info@gerh \
    --cc=javier-JPH+aEBZ4P+UEJcrhfAQsw@public.gmane.org \
    --cc=k.kozlowski-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org \
    --cc=linux-I+IVW8TIWO2tmTQ+vhA3Yw@public.gmane.org \
    --cc=linux-sunxi-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org \
    --cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
    --cc=maxime.ripard-wi1+55ScJUtKEb57/3fJTNBPR1lH4CV8@public.gmane.org \
    --cc=net147-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=olof-nZhT3qVonbNeoWH0uzbU5w@public.gmane.org \
    --cc=pawel.moll-5wv7dgnIgG8@public.gmane.org \
    --cc=public_timo.s-fWgRPtSzPNU3WX+qO2AYSQ@public.gmane.org \
    --cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=sjoerd.simons-ZGY8ohtN/8pPYcu2f3hruQ@public.gmane.org \
    --cc=stable-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=treding-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org \
    --cc=wens-jdAy2FN1RRM@public.gmane.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.