All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: "Mark Brown" <broonie@kernel.org>,
	"Cristian Ciocaltea" <cristian.ciocaltea@collabora.com>,
	"Yang Yingliang" <yangyingliang@huawei.com>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Amit Kumar Mahapatra via Alsa-devel"
	<alsa-devel@alsa-project.org>,
	"Neil Armstrong" <neil.armstrong@linaro.org>,
	"Tharun Kumar P" <tharunkumar.pasumarthi@microchip.com>,
	"Vijaya Krishna Nivarthi" <quic_vnivarth@quicinc.com>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-amlogic@lists.infradead.org,
	linux-mediatek@lists.infradead.org,
	linux-arm-msm@vger.kernel.org,
	linux-rockchip@lists.infradead.org,
	linux-riscv@lists.infradead.org,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org
Cc: Sanjay R Mehta <sanju.mehta@amd.com>,
	Radu Pirea <radu_nicolae.pirea@upb.ro>,
	Nicolas Ferre <nicolas.ferre@microchip.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Claudiu Beznea <claudiu.beznea@microchip.com>,
	Tudor Ambarus <tudor.ambarus@linaro.org>,
	Serge Semin <fancer.lancer@gmail.com>,
	Shawn Guo <shawnguo@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Fabio Estevam <festevam@gmail.com>,
	NXP Linux Team <linux-imx@nxp.com>,
	Kevin Hilman <khilman@baylibre.com>,
	Jerome Brunet <jbrunet@baylibre.com>,
	Martin Blumenstingl <martin.blumenstingl@googlemail.com>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	AngeloGioacchino Del Regno 
	<angelogioacchino.delregno@collabora.com>,
	Andy Gross <agross@kernel.org>,
	Bjorn Andersson <andersson@kernel.org>,
	Konrad Dybcio <konrad.dybcio@linaro.org>,
	Heiko Stuebner <heiko@sntech.de>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	Orson Zhai <orsonzhai@gmail.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Chunyan Zhang <zhang.lyra@gmail.com>,
	Alain Volmat <alain.volmat@foss.st.com>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	Max Filippov <jcmvbkbc@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Richard Cochran <richardcochran@gmail.com>
Subject: [PATCH v2 04/15] spi: Replace open coded spi_controller_xfer_timeout()
Date: Mon, 10 Jul 2023 18:49:21 +0300	[thread overview]
Message-ID: <20230710154932.68377-5-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20230710154932.68377-1-andriy.shevchenko@linux.intel.com>

Since the new spi_controller_xfer_timeout() helper appeared,
we may replace open coded variant in spi_transfer_wait().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/spi/spi.c       | 25 ++-----------------------
 include/linux/spi/spi.h |  6 +++++-
 2 files changed, 7 insertions(+), 24 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 125dea8fae00..c99ee4164f11 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1342,8 +1342,7 @@ static int spi_transfer_wait(struct spi_controller *ctlr,
 {
 	struct spi_statistics __percpu *statm = ctlr->pcpu_statistics;
 	struct spi_statistics __percpu *stats = msg->spi->pcpu_statistics;
-	u32 speed_hz = xfer->speed_hz;
-	unsigned long long ms;
+	unsigned long ms;
 
 	if (spi_controller_is_slave(ctlr)) {
 		if (wait_for_completion_interruptible(&ctlr->xfer_completion)) {
@@ -1351,29 +1350,9 @@ static int spi_transfer_wait(struct spi_controller *ctlr,
 			return -EINTR;
 		}
 	} else {
-		if (!speed_hz)
-			speed_hz = 100000;
-
-		/*
-		 * For each byte we wait for 8 cycles of the SPI clock.
-		 * Since speed is defined in Hz and we want milliseconds,
-		 * use respective multiplier, but before the division,
-		 * otherwise we may get 0 for short transfers.
-		 */
-		ms = 8LL * MSEC_PER_SEC * xfer->len;
-		do_div(ms, speed_hz);
-
-		/*
-		 * Increase it twice and add 200 ms tolerance, use
-		 * predefined maximum in case of overflow.
-		 */
-		ms += ms + 200;
-		if (ms > UINT_MAX)
-			ms = UINT_MAX;
-
+		ms = spi_controller_xfer_timeout(ctlr, xfer);
 		ms = wait_for_completion_timeout(&ctlr->xfer_completion,
 						 msecs_to_jiffies(ms));
-
 		if (ms == 0) {
 			SPI_STATISTICS_INCREMENT_FIELD(statm, timedout);
 			SPI_STATISTICS_INCREMENT_FIELD(stats, timedout);
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 32c94eae8926..0ce1cb18a076 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -1270,12 +1270,16 @@ static inline bool spi_is_bpw_supported(struct spi_device *spi, u32 bpw)
  * that it would take on a single data line and take twice this amount of time
  * with a minimum of 500ms to avoid false positives on loaded systems.
  *
+ * Assume speed to be 100 kHz if it's not defined at the time of invocation.
+ *
  * Returns: Transfer timeout value in milliseconds.
  */
 static inline unsigned int spi_controller_xfer_timeout(struct spi_controller *ctlr,
 						       struct spi_transfer *xfer)
 {
-	return max(xfer->len * 8 * 2 / (xfer->speed_hz / 1000), 500U);
+	u32 speed_hz = xfer->speed_hz ?: 100000;
+
+	return max(xfer->len * 8 * 2 / (speed_hz / 1000), 500U);
 }
 
 /*---------------------------------------------------------------------------*/
-- 
2.40.0.1.gaa8946217a0b


WARNING: multiple messages have this Message-ID (diff)
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: "Mark Brown" <broonie@kernel.org>,
	"Cristian Ciocaltea" <cristian.ciocaltea@collabora.com>,
	"Yang Yingliang" <yangyingliang@huawei.com>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Amit Kumar Mahapatra via Alsa-devel"
	<alsa-devel@alsa-project.org>,
	"Neil Armstrong" <neil.armstrong@linaro.org>,
	"Tharun Kumar P" <tharunkumar.pasumarthi@microchip.com>,
	"Vijaya Krishna Nivarthi" <quic_vnivarth@quicinc.com>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-amlogic@lists.infradead.org,
	linux-mediatek@lists.infradead.org,
	linux-arm-msm@vger.kernel.org,
	linux-rockchip@lists.infradead.org,
	linux-riscv@lists.infradead.org,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org
Cc: Sanjay R Mehta <sanju.mehta@amd.com>,
	Radu Pirea <radu_nicolae.pirea@upb.ro>,
	Nicolas Ferre <nicolas.ferre@microchip.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Claudiu Beznea <claudiu.beznea@microchip.com>,
	Tudor Ambarus <tudor.ambarus@linaro.org>,
	Serge Semin <fancer.lancer@gmail.com>,
	Shawn Guo <shawnguo@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Fabio Estevam <festevam@gmail.com>,
	NXP Linux Team <linux-imx@nxp.com>,
	Kevin Hilman <khilman@baylibre.com>,
	Jerome Brunet <jbrunet@baylibre.com>,
	Martin Blumenstingl <martin.blumenstingl@googlemail.com>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	Andy Gross <agross@kernel.org>,
	Bjorn Andersson <andersson@kernel.org>,
	Konrad Dybcio <konrad.dybcio@linaro.org>,
	Heiko Stuebner <heiko@sntech.de>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	Orson Zhai <orsonzhai@gmail.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Chunyan Zhang <zhang.lyra@gmail.com>,
	Alain Volmat <alain.volmat@foss.st.com>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	Max Filippov <jcmvbkbc@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Richard Cochran <richardcochran@gmail.com>
Subject: [PATCH v2 04/15] spi: Replace open coded spi_controller_xfer_timeout()
Date: Mon, 10 Jul 2023 18:49:21 +0300	[thread overview]
Message-ID: <20230710154932.68377-5-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20230710154932.68377-1-andriy.shevchenko@linux.intel.com>

Since the new spi_controller_xfer_timeout() helper appeared,
we may replace open coded variant in spi_transfer_wait().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/spi/spi.c       | 25 ++-----------------------
 include/linux/spi/spi.h |  6 +++++-
 2 files changed, 7 insertions(+), 24 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 125dea8fae00..c99ee4164f11 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1342,8 +1342,7 @@ static int spi_transfer_wait(struct spi_controller *ctlr,
 {
 	struct spi_statistics __percpu *statm = ctlr->pcpu_statistics;
 	struct spi_statistics __percpu *stats = msg->spi->pcpu_statistics;
-	u32 speed_hz = xfer->speed_hz;
-	unsigned long long ms;
+	unsigned long ms;
 
 	if (spi_controller_is_slave(ctlr)) {
 		if (wait_for_completion_interruptible(&ctlr->xfer_completion)) {
@@ -1351,29 +1350,9 @@ static int spi_transfer_wait(struct spi_controller *ctlr,
 			return -EINTR;
 		}
 	} else {
-		if (!speed_hz)
-			speed_hz = 100000;
-
-		/*
-		 * For each byte we wait for 8 cycles of the SPI clock.
-		 * Since speed is defined in Hz and we want milliseconds,
-		 * use respective multiplier, but before the division,
-		 * otherwise we may get 0 for short transfers.
-		 */
-		ms = 8LL * MSEC_PER_SEC * xfer->len;
-		do_div(ms, speed_hz);
-
-		/*
-		 * Increase it twice and add 200 ms tolerance, use
-		 * predefined maximum in case of overflow.
-		 */
-		ms += ms + 200;
-		if (ms > UINT_MAX)
-			ms = UINT_MAX;
-
+		ms = spi_controller_xfer_timeout(ctlr, xfer);
 		ms = wait_for_completion_timeout(&ctlr->xfer_completion,
 						 msecs_to_jiffies(ms));
-
 		if (ms == 0) {
 			SPI_STATISTICS_INCREMENT_FIELD(statm, timedout);
 			SPI_STATISTICS_INCREMENT_FIELD(stats, timedout);
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 32c94eae8926..0ce1cb18a076 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -1270,12 +1270,16 @@ static inline bool spi_is_bpw_supported(struct spi_device *spi, u32 bpw)
  * that it would take on a single data line and take twice this amount of time
  * with a minimum of 500ms to avoid false positives on loaded systems.
  *
+ * Assume speed to be 100 kHz if it's not defined at the time of invocation.
+ *
  * Returns: Transfer timeout value in milliseconds.
  */
 static inline unsigned int spi_controller_xfer_timeout(struct spi_controller *ctlr,
 						       struct spi_transfer *xfer)
 {
-	return max(xfer->len * 8 * 2 / (xfer->speed_hz / 1000), 500U);
+	u32 speed_hz = xfer->speed_hz ?: 100000;
+
+	return max(xfer->len * 8 * 2 / (speed_hz / 1000), 500U);
 }
 
 /*---------------------------------------------------------------------------*/
-- 
2.40.0.1.gaa8946217a0b


_______________________________________________
linux-riscv mailing list
linux-riscv@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-riscv

WARNING: multiple messages have this Message-ID (diff)
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: "Mark Brown" <broonie@kernel.org>,
	"Cristian Ciocaltea" <cristian.ciocaltea@collabora.com>,
	"Yang Yingliang" <yangyingliang@huawei.com>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Amit Kumar Mahapatra via Alsa-devel"
	<alsa-devel@alsa-project.org>,
	"Neil Armstrong" <neil.armstrong@linaro.org>,
	"Tharun Kumar P" <tharunkumar.pasumarthi@microchip.com>,
	"Vijaya Krishna Nivarthi" <quic_vnivarth@quicinc.com>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-amlogic@lists.infradead.org,
	linux-mediatek@lists.infradead.org,
	linux-arm-msm@vger.kernel.org,
	linux-rockchip@lists.infradead.org,
	linux-riscv@lists.infradead.org,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org
Cc: Sanjay R Mehta <sanju.mehta@amd.com>,
	Radu Pirea <radu_nicolae.pirea@upb.ro>,
	Nicolas Ferre <nicolas.ferre@microchip.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Claudiu Beznea <claudiu.beznea@microchip.com>,
	Tudor Ambarus <tudor.ambarus@linaro.org>,
	Serge Semin <fancer.lancer@gmail.com>,
	Shawn Guo <shawnguo@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Fabio Estevam <festevam@gmail.com>,
	NXP Linux Team <linux-imx@nxp.com>,
	Kevin Hilman <khilman@baylibre.com>,
	Jerome Brunet <jbrunet@baylibre.com>,
	Martin Blumenstingl <martin.blumenstingl@googlemail.com>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	Andy Gross <agross@kernel.org>,
	Bjorn Andersson <andersson@kernel.org>,
	Konrad Dybcio <konrad.dybcio@linaro.org>,
	Heiko Stuebner <heiko@sntech.de>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	Orson Zhai <orsonzhai@gmail.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Chunyan Zhang <zhang.lyra@gmail.com>,
	Alain Volmat <alain.volmat@foss.st.com>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	Max Filippov <jcmvbkbc@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Richard Cochran <richardcochran@gmail.com>
Subject: [PATCH v2 04/15] spi: Replace open coded spi_controller_xfer_timeout()
Date: Mon, 10 Jul 2023 18:49:21 +0300	[thread overview]
Message-ID: <20230710154932.68377-5-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20230710154932.68377-1-andriy.shevchenko@linux.intel.com>

Since the new spi_controller_xfer_timeout() helper appeared,
we may replace open coded variant in spi_transfer_wait().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/spi/spi.c       | 25 ++-----------------------
 include/linux/spi/spi.h |  6 +++++-
 2 files changed, 7 insertions(+), 24 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 125dea8fae00..c99ee4164f11 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1342,8 +1342,7 @@ static int spi_transfer_wait(struct spi_controller *ctlr,
 {
 	struct spi_statistics __percpu *statm = ctlr->pcpu_statistics;
 	struct spi_statistics __percpu *stats = msg->spi->pcpu_statistics;
-	u32 speed_hz = xfer->speed_hz;
-	unsigned long long ms;
+	unsigned long ms;
 
 	if (spi_controller_is_slave(ctlr)) {
 		if (wait_for_completion_interruptible(&ctlr->xfer_completion)) {
@@ -1351,29 +1350,9 @@ static int spi_transfer_wait(struct spi_controller *ctlr,
 			return -EINTR;
 		}
 	} else {
-		if (!speed_hz)
-			speed_hz = 100000;
-
-		/*
-		 * For each byte we wait for 8 cycles of the SPI clock.
-		 * Since speed is defined in Hz and we want milliseconds,
-		 * use respective multiplier, but before the division,
-		 * otherwise we may get 0 for short transfers.
-		 */
-		ms = 8LL * MSEC_PER_SEC * xfer->len;
-		do_div(ms, speed_hz);
-
-		/*
-		 * Increase it twice and add 200 ms tolerance, use
-		 * predefined maximum in case of overflow.
-		 */
-		ms += ms + 200;
-		if (ms > UINT_MAX)
-			ms = UINT_MAX;
-
+		ms = spi_controller_xfer_timeout(ctlr, xfer);
 		ms = wait_for_completion_timeout(&ctlr->xfer_completion,
 						 msecs_to_jiffies(ms));
-
 		if (ms == 0) {
 			SPI_STATISTICS_INCREMENT_FIELD(statm, timedout);
 			SPI_STATISTICS_INCREMENT_FIELD(stats, timedout);
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 32c94eae8926..0ce1cb18a076 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -1270,12 +1270,16 @@ static inline bool spi_is_bpw_supported(struct spi_device *spi, u32 bpw)
  * that it would take on a single data line and take twice this amount of time
  * with a minimum of 500ms to avoid false positives on loaded systems.
  *
+ * Assume speed to be 100 kHz if it's not defined at the time of invocation.
+ *
  * Returns: Transfer timeout value in milliseconds.
  */
 static inline unsigned int spi_controller_xfer_timeout(struct spi_controller *ctlr,
 						       struct spi_transfer *xfer)
 {
-	return max(xfer->len * 8 * 2 / (xfer->speed_hz / 1000), 500U);
+	u32 speed_hz = xfer->speed_hz ?: 100000;
+
+	return max(xfer->len * 8 * 2 / (speed_hz / 1000), 500U);
 }
 
 /*---------------------------------------------------------------------------*/
-- 
2.40.0.1.gaa8946217a0b


_______________________________________________
Linux-rockchip mailing list
Linux-rockchip@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-rockchip

WARNING: multiple messages have this Message-ID (diff)
From: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
To: "Mark Brown" <broonie@kernel.org>,
	"Cristian Ciocaltea" <cristian.ciocaltea@collabora.com>,
	"Yang Yingliang" <yangyingliang@huawei.com>,
	"Andy Shevchenko" <andriy.shevchenko@linux.intel.com>,
	"Amit Kumar Mahapatra via Alsa-devel"
	<alsa-devel@alsa-project.org>,
	"Neil Armstrong" <neil.armstrong@linaro.org>,
	"Tharun Kumar P" <tharunkumar.pasumarthi@microchip.com>,
	"Vijaya Krishna Nivarthi" <quic_vnivarth@quicinc.com>,
	"Uwe Kleine-König" <u.kleine-koenig@pengutronix.de>,
	linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-kernel@lists.infradead.org,
	linux-amlogic@lists.infradead.org,
	linux-mediatek@lists.infradead.org,
	linux-arm-msm@vger.kernel.org,
	linux-rockchip@lists.infradead.org,
	linux-riscv@lists.infradead.org,
	linux-stm32@st-md-mailman.stormreply.com,
	linux-trace-kernel@vger.kernel.org, netdev@vger.kernel.org
Cc: Sanjay R Mehta <sanju.mehta@amd.com>,
	Radu Pirea <radu_nicolae.pirea@upb.ro>,
	Nicolas Ferre <nicolas.ferre@microchip.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Claudiu Beznea <claudiu.beznea@microchip.com>,
	Tudor Ambarus <tudor.ambarus@linaro.org>,
	Serge Semin <fancer.lancer@gmail.com>,
	Shawn Guo <shawnguo@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Fabio Estevam <festevam@gmail.com>,
	NXP Linux Team <linux-imx@nxp.com>,
	Kevin Hilman <khilman@baylibre.com>,
	Jerome Brunet <jbrunet@baylibre.com>,
	Martin Blumenstingl <martin.blumenstingl@googlemail.com>,
	Matthias Brugger <matthias.bgg@gmail.com>,
	AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	Andy Gross <agross@kernel.org>,
	Bjorn Andersson <andersson@kernel.org>,
	Konrad Dybcio <konrad.dybcio@linaro.org>,
	Heiko Stuebner <heiko@sntech.de>,
	Palmer Dabbelt <palmer@dabbelt.com>,
	Paul Walmsley <paul.walmsley@sifive.com>,
	Orson Zhai <orsonzhai@gmail.com>,
	Baolin Wang <baolin.wang@linux.alibaba.com>,
	Chunyan Zhang <zhang.lyra@gmail.com>,
	Alain Volmat <alain.volmat@foss.st.com>,
	Maxime Coquelin <mcoquelin.stm32@gmail.com>,
	Alexandre Torgue <alexandre.torgue@foss.st.com>,
	Max Filippov <jcmvbkbc@gmail.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Richard Cochran <richardcochran@gmail.com>
Subject: [PATCH v2 04/15] spi: Replace open coded spi_controller_xfer_timeout()
Date: Mon, 10 Jul 2023 18:49:21 +0300	[thread overview]
Message-ID: <20230710154932.68377-5-andriy.shevchenko@linux.intel.com> (raw)
In-Reply-To: <20230710154932.68377-1-andriy.shevchenko@linux.intel.com>

Since the new spi_controller_xfer_timeout() helper appeared,
we may replace open coded variant in spi_transfer_wait().

Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
---
 drivers/spi/spi.c       | 25 ++-----------------------
 include/linux/spi/spi.h |  6 +++++-
 2 files changed, 7 insertions(+), 24 deletions(-)

diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
index 125dea8fae00..c99ee4164f11 100644
--- a/drivers/spi/spi.c
+++ b/drivers/spi/spi.c
@@ -1342,8 +1342,7 @@ static int spi_transfer_wait(struct spi_controller *ctlr,
 {
 	struct spi_statistics __percpu *statm = ctlr->pcpu_statistics;
 	struct spi_statistics __percpu *stats = msg->spi->pcpu_statistics;
-	u32 speed_hz = xfer->speed_hz;
-	unsigned long long ms;
+	unsigned long ms;
 
 	if (spi_controller_is_slave(ctlr)) {
 		if (wait_for_completion_interruptible(&ctlr->xfer_completion)) {
@@ -1351,29 +1350,9 @@ static int spi_transfer_wait(struct spi_controller *ctlr,
 			return -EINTR;
 		}
 	} else {
-		if (!speed_hz)
-			speed_hz = 100000;
-
-		/*
-		 * For each byte we wait for 8 cycles of the SPI clock.
-		 * Since speed is defined in Hz and we want milliseconds,
-		 * use respective multiplier, but before the division,
-		 * otherwise we may get 0 for short transfers.
-		 */
-		ms = 8LL * MSEC_PER_SEC * xfer->len;
-		do_div(ms, speed_hz);
-
-		/*
-		 * Increase it twice and add 200 ms tolerance, use
-		 * predefined maximum in case of overflow.
-		 */
-		ms += ms + 200;
-		if (ms > UINT_MAX)
-			ms = UINT_MAX;
-
+		ms = spi_controller_xfer_timeout(ctlr, xfer);
 		ms = wait_for_completion_timeout(&ctlr->xfer_completion,
 						 msecs_to_jiffies(ms));
-
 		if (ms == 0) {
 			SPI_STATISTICS_INCREMENT_FIELD(statm, timedout);
 			SPI_STATISTICS_INCREMENT_FIELD(stats, timedout);
diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h
index 32c94eae8926..0ce1cb18a076 100644
--- a/include/linux/spi/spi.h
+++ b/include/linux/spi/spi.h
@@ -1270,12 +1270,16 @@ static inline bool spi_is_bpw_supported(struct spi_device *spi, u32 bpw)
  * that it would take on a single data line and take twice this amount of time
  * with a minimum of 500ms to avoid false positives on loaded systems.
  *
+ * Assume speed to be 100 kHz if it's not defined at the time of invocation.
+ *
  * Returns: Transfer timeout value in milliseconds.
  */
 static inline unsigned int spi_controller_xfer_timeout(struct spi_controller *ctlr,
 						       struct spi_transfer *xfer)
 {
-	return max(xfer->len * 8 * 2 / (xfer->speed_hz / 1000), 500U);
+	u32 speed_hz = xfer->speed_hz ?: 100000;
+
+	return max(xfer->len * 8 * 2 / (speed_hz / 1000), 500U);
 }
 
 /*---------------------------------------------------------------------------*/
-- 
2.40.0.1.gaa8946217a0b


_______________________________________________
linux-amlogic mailing list
linux-amlogic@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-amlogic

  parent reply	other threads:[~2023-07-10 15:49 UTC|newest]

Thread overview: 192+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-10 15:49 [PATCH v2 00/15] spi: Header and core clean up and refactoring Andy Shevchenko
2023-07-10 15:49 ` Andy Shevchenko
2023-07-10 15:49 ` Andy Shevchenko
2023-07-10 15:49 ` Andy Shevchenko
2023-07-10 15:49 ` [PATCH v2 01/15] spi: Remove unneeded OF node NULL checks Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-11  8:12   ` AngeloGioacchino Del Regno
2023-07-11  8:12     ` AngeloGioacchino Del Regno
2023-07-11  8:12     ` AngeloGioacchino Del Regno
2023-07-11  8:12     ` AngeloGioacchino Del Regno
2023-07-11 12:51     ` Andy Shevchenko
2023-07-11 12:51       ` Andy Shevchenko
2023-07-11 12:51       ` Andy Shevchenko
2023-07-11 12:51       ` Andy Shevchenko
2023-07-10 15:49 ` [PATCH v2 02/15] spi: Drop duplicate IDR allocation code in spi_register_controller() Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 17:09   ` Mark Brown
2023-07-10 17:09     ` Mark Brown
2023-07-10 17:09     ` Mark Brown
2023-07-10 17:09     ` Mark Brown
2023-07-11 10:58     ` Andy Shevchenko
2023-07-11 10:58       ` Andy Shevchenko
2023-07-11 10:58       ` Andy Shevchenko
2023-07-11 10:58       ` Andy Shevchenko
2023-07-10 15:49 ` [PATCH v2 03/15] spi: Replace if-else-if by bitops and multiplications Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 16:56   ` Mark Brown
2023-07-10 16:56     ` Mark Brown
2023-07-10 16:56     ` Mark Brown
2023-07-10 16:56     ` Mark Brown
2023-07-11 10:58     ` Andy Shevchenko
2023-07-11 10:58       ` Andy Shevchenko
2023-07-11 10:58       ` Andy Shevchenko
2023-07-11 10:58       ` Andy Shevchenko
2023-07-10 15:49 ` Andy Shevchenko [this message]
2023-07-10 15:49   ` [PATCH v2 04/15] spi: Replace open coded spi_controller_xfer_timeout() Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 17:30   ` Mark Brown
2023-07-10 17:30     ` Mark Brown
2023-07-10 17:30     ` Mark Brown
2023-07-10 17:30     ` Mark Brown
2023-07-11 11:01     ` Andy Shevchenko
2023-07-11 11:01       ` Andy Shevchenko
2023-07-11 11:01       ` Andy Shevchenko
2023-07-11 11:01       ` Andy Shevchenko
2023-07-11 14:14       ` Mark Brown
2023-07-11 14:14         ` Mark Brown
2023-07-11 14:14         ` Mark Brown
2023-07-11 14:14         ` Mark Brown
2023-07-11 15:30         ` Andy Shevchenko
2023-07-11 15:30           ` Andy Shevchenko
2023-07-11 15:30           ` Andy Shevchenko
2023-07-11 15:30           ` Andy Shevchenko
2023-07-11 15:49           ` Mark Brown
2023-07-11 15:49             ` Mark Brown
2023-07-11 15:49             ` Mark Brown
2023-07-11 15:49             ` Mark Brown
2023-07-11  8:28   ` AngeloGioacchino Del Regno
2023-07-11  8:28     ` AngeloGioacchino Del Regno
2023-07-11  8:28     ` AngeloGioacchino Del Regno
2023-07-11  8:28     ` AngeloGioacchino Del Regno
2023-07-11 13:05     ` Mark Brown
2023-07-11 13:05       ` Mark Brown
2023-07-11 13:05       ` Mark Brown
2023-07-11 13:05       ` Mark Brown
2023-07-11 13:29       ` AngeloGioacchino Del Regno
2023-07-11 13:29         ` AngeloGioacchino Del Regno
2023-07-11 13:29         ` AngeloGioacchino Del Regno
2023-07-11 13:29         ` AngeloGioacchino Del Regno
2023-07-10 15:49 ` [PATCH v2 05/15] spi: Remove code duplication in spi_add_device_locked() Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 17:16   ` Mark Brown
2023-07-10 17:16     ` Mark Brown
2023-07-10 17:16     ` Mark Brown
2023-07-10 17:16     ` Mark Brown
2023-07-11 11:06     ` Andy Shevchenko
2023-07-11 11:06       ` Andy Shevchenko
2023-07-11 11:06       ` Andy Shevchenko
2023-07-11 11:06       ` Andy Shevchenko
2023-07-11 12:01       ` Sebastian Reichel
2023-07-11 12:01         ` Sebastian Reichel
2023-07-11 12:01         ` Sebastian Reichel
2023-07-11 12:01         ` Sebastian Reichel
2023-07-11 12:47         ` Andy Shevchenko
2023-07-11 12:47           ` Andy Shevchenko
2023-07-11 12:47           ` Andy Shevchenko
2023-07-11 12:47           ` Andy Shevchenko
2023-07-10 15:49 ` [PATCH v2 06/15] spi: Use sysfs_emit() to instead of s*printf() Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49 ` [PATCH v2 07/15] spi: Sort headers alphabetically Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49 ` [PATCH v2 08/15] spi: Clean up headers Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 17:21   ` Mark Brown
2023-07-10 17:21     ` Mark Brown
2023-07-10 17:21     ` Mark Brown
2023-07-10 17:21     ` Mark Brown
2023-07-11 11:10     ` Andy Shevchenko
2023-07-11 11:10       ` Andy Shevchenko
2023-07-11 11:10       ` Andy Shevchenko
2023-07-11 11:10       ` Andy Shevchenko
2023-07-11  8:26   ` Mark Brown
2023-07-11  8:26     ` Mark Brown
2023-07-11  8:26     ` Mark Brown
2023-07-11  8:26     ` Mark Brown
2023-07-11 11:10     ` Andy Shevchenko
2023-07-11 11:10       ` Andy Shevchenko
2023-07-11 11:10       ` Andy Shevchenko
2023-07-11 11:10       ` Andy Shevchenko
2023-07-10 15:49 ` [PATCH v2 09/15] spi: Use struct_size() helper Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:59   ` Marc Kleine-Budde
2023-07-10 15:59     ` Marc Kleine-Budde
2023-07-10 15:59     ` Marc Kleine-Budde
2023-07-10 15:59     ` Marc Kleine-Budde
2023-07-10 16:10     ` Andy Shevchenko
2023-07-10 16:10       ` Andy Shevchenko
2023-07-10 16:10       ` Andy Shevchenko
2023-07-10 16:10       ` Andy Shevchenko
2023-07-10 16:12       ` Andy Shevchenko
2023-07-10 16:12         ` Andy Shevchenko
2023-07-10 16:12         ` Andy Shevchenko
2023-07-10 16:12         ` Andy Shevchenko
2023-07-10 15:49 ` [PATCH v2 10/15] spi: Use predefined constants from bits.h and units.h Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49 ` [PATCH v2 11/15] spi: Get rid of old SPI_MASTER_NO_TX & SPI_MASTER_NO_RX Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49 ` [PATCH v2 12/15] spi: Get rid of old SPI_MASTER_MUST_TX & SPI_MASTER_MUST_RX Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49 ` [PATCH v2 13/15] spi: Rename SPI_MASTER_GPIO_SS to SPI_CONTROLLER_GPIO_SS Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-11 12:30   ` Serge Semin
2023-07-11 12:30     ` Serge Semin
2023-07-11 12:30     ` Serge Semin
2023-07-11 12:30     ` Serge Semin
2023-07-11 12:49     ` Andy Shevchenko
2023-07-11 12:49       ` Andy Shevchenko
2023-07-11 12:49       ` Andy Shevchenko
2023-07-11 12:49       ` Andy Shevchenko
2023-07-10 15:49 ` [PATCH v2 14/15] spi: Convert to SPI_CONTROLLER_HALF_DUPLEX Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49 ` [PATCH v2 15/15] spi: Fix spelling typos and acronyms capitalization Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 15:49   ` Andy Shevchenko
2023-07-10 17:31 ` [PATCH v2 00/15] spi: Header and core clean up and refactoring Mark Brown
2023-07-10 17:31   ` Mark Brown
2023-07-10 17:31   ` Mark Brown
2023-07-10 17:31   ` Mark Brown
2023-07-11 11:11   ` Andy Shevchenko
2023-07-11 11:11     ` Andy Shevchenko
2023-07-11 11:11     ` Andy Shevchenko
2023-07-11 11:11     ` Andy Shevchenko
2023-07-11 13:38     ` Mark Brown
2023-07-11 13:38       ` Mark Brown
2023-07-11 13:38       ` Mark Brown
2023-07-11 13:38       ` Mark Brown
2023-07-11 13:45       ` Andy Shevchenko
2023-07-11 13:45         ` Andy Shevchenko
2023-07-11 13:45         ` Andy Shevchenko
2023-07-11 13:45         ` Andy Shevchenko
2023-07-12 11:47 ` (subset) " Mark Brown
2023-07-12 11:47   ` Mark Brown
2023-07-12 11:47   ` Mark Brown
2023-07-12 11:47   ` Mark Brown

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=20230710154932.68377-5-andriy.shevchenko@linux.intel.com \
    --to=andriy.shevchenko@linux.intel.com \
    --cc=agross@kernel.org \
    --cc=alain.volmat@foss.st.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=alexandre.torgue@foss.st.com \
    --cc=alsa-devel@alsa-project.org \
    --cc=andersson@kernel.org \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=baolin.wang@linux.alibaba.com \
    --cc=broonie@kernel.org \
    --cc=claudiu.beznea@microchip.com \
    --cc=cristian.ciocaltea@collabora.com \
    --cc=fancer.lancer@gmail.com \
    --cc=festevam@gmail.com \
    --cc=heiko@sntech.de \
    --cc=jbrunet@baylibre.com \
    --cc=jcmvbkbc@gmail.com \
    --cc=kernel@pengutronix.de \
    --cc=khilman@baylibre.com \
    --cc=konrad.dybcio@linaro.org \
    --cc=linux-amlogic@lists.infradead.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-imx@nxp.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=linux-riscv@lists.infradead.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=linux-stm32@st-md-mailman.stormreply.com \
    --cc=linux-trace-kernel@vger.kernel.org \
    --cc=martin.blumenstingl@googlemail.com \
    --cc=matthias.bgg@gmail.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=mhiramat@kernel.org \
    --cc=neil.armstrong@linaro.org \
    --cc=netdev@vger.kernel.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=orsonzhai@gmail.com \
    --cc=palmer@dabbelt.com \
    --cc=paul.walmsley@sifive.com \
    --cc=quic_vnivarth@quicinc.com \
    --cc=radu_nicolae.pirea@upb.ro \
    --cc=richardcochran@gmail.com \
    --cc=rostedt@goodmis.org \
    --cc=s.hauer@pengutronix.de \
    --cc=sanju.mehta@amd.com \
    --cc=shawnguo@kernel.org \
    --cc=tharunkumar.pasumarthi@microchip.com \
    --cc=tudor.ambarus@linaro.org \
    --cc=u.kleine-koenig@pengutronix.de \
    --cc=yangyingliang@huawei.com \
    --cc=zhang.lyra@gmail.com \
    /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.