public inbox for linux-arm-kernel@lists.infradead.org
 help / color / mirror / Atom feed
* [PATCH v2] spi: spi-imx: Fix spi_bus_clk if requested clock is higher than input clock
@ 2022-11-15 16:26 Frieder Schrempf
  2022-11-15 16:54 ` Marc Kleine-Budde
  2022-11-15 17:24 ` Fabio Estevam
  0 siblings, 2 replies; 5+ messages in thread
From: Frieder Schrempf @ 2022-11-15 16:26 UTC (permalink / raw)
  To: David Jander, linux-arm-kernel, linux-kernel, linux-spi,
	Marc Kleine-Budde, Mark Brown, Sascha Hauer, Shawn Guo
  Cc: Frieder Schrempf, Fabio Estevam, Marek Vasut, stable,
	Baruch Siach, Minghao Chi, NXP Linux Team,
	Pengutronix Kernel Team

From: Frieder Schrempf <frieder.schrempf@kontron.de>

In case the requested bus clock is higher than the input clock, the correct
dividers (pre = 0, post = 0) are returned from mx51_ecspi_clkdiv(), but
*fres is left uninitialized and therefore contains an arbitrary value.

This causes trouble for the recently introduced PIO polling feature as the
value in spi_imx->spi_bus_clk is used there to calculate for which
transfers to enable PIO polling.

Fix this by setting *fres even if no clock dividers are in use.

This issue was observed on Kontron BL i.MX8MM with an SPI peripheral clock set
to 50 MHz by default and a requested SPI bus clock of 80 MHz for the SPI NOR
flash.

With the fix applied the debug message from mx51_ecspi_clkdiv() now prints the
following:

spi_imx 30820000.spi: mx51_ecspi_clkdiv: fin: 50000000, fspi: 50000000,
post: 0, pre: 0

Fixes: 07e759387788 ("spi: spi-imx: add PIO polling support")
Cc: Marc Kleine-Budde <mkl@pengutronix.de>
Cc: David Jander <david@protonic.nl>
Cc: Fabio Estevam <festevam@gmail.com>
Cc: Mark Brown <broonie@kernel.org>
Cc: Marek Vasut <marex@denx.de>
Cc: stable@vger.kernel.org
Signed-off-by: Frieder Schrempf <frieder.schrempf@kontron.de>
---

Changes for v2:

* Remove the reference and the Fixes tag for commit 6fd8b8503a0d as it is
  incorrect.
---
 drivers/spi/spi-imx.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/spi/spi-imx.c b/drivers/spi/spi-imx.c
index 30d82cc7300b..468ce0a2b282 100644
--- a/drivers/spi/spi-imx.c
+++ b/drivers/spi/spi-imx.c
@@ -444,8 +444,7 @@ static unsigned int mx51_ecspi_clkdiv(struct spi_imx_data *spi_imx,
 	unsigned int pre, post;
 	unsigned int fin = spi_imx->spi_clk;
 
-	if (unlikely(fspi > fin))
-		return 0;
+	fspi = min(fspi, fin);
 
 	post = fls(fin) - fls(fspi);
 	if (fin > fspi << post)
-- 
2.38.1


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

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] spi: spi-imx: Fix spi_bus_clk if requested clock is higher than input clock
  2022-11-15 16:26 [PATCH v2] spi: spi-imx: Fix spi_bus_clk if requested clock is higher than input clock Frieder Schrempf
@ 2022-11-15 16:54 ` Marc Kleine-Budde
  2022-11-15 17:14   ` Frieder Schrempf
  2022-11-15 17:24 ` Fabio Estevam
  1 sibling, 1 reply; 5+ messages in thread
From: Marc Kleine-Budde @ 2022-11-15 16:54 UTC (permalink / raw)
  To: Frieder Schrempf
  Cc: David Jander, linux-arm-kernel, linux-kernel, linux-spi,
	Mark Brown, Sascha Hauer, Shawn Guo, Marek Vasut, NXP Linux Team,
	stable, Frieder Schrempf, Pengutronix Kernel Team, Baruch Siach,
	Fabio Estevam, Minghao Chi


[-- Attachment #1.1: Type: text/plain, Size: 1570 bytes --]

On 15.11.2022 17:26:53, Frieder Schrempf wrote:
> From: Frieder Schrempf <frieder.schrempf@kontron.de>
> 
> In case the requested bus clock is higher than the input clock, the correct
> dividers (pre = 0, post = 0) are returned from mx51_ecspi_clkdiv(), but
> *fres is left uninitialized and therefore contains an arbitrary value.
> 
> This causes trouble for the recently introduced PIO polling feature as the
> value in spi_imx->spi_bus_clk is used there to calculate for which
> transfers to enable PIO polling.
> 
> Fix this by setting *fres even if no clock dividers are in use.
> 
> This issue was observed on Kontron BL i.MX8MM with an SPI peripheral clock set
> to 50 MHz by default and a requested SPI bus clock of 80 MHz for the SPI NOR
> flash.
> 
> With the fix applied the debug message from mx51_ecspi_clkdiv() now prints the
> following:
> 
> spi_imx 30820000.spi: mx51_ecspi_clkdiv: fin: 50000000, fspi: 50000000,
> post: 0, pre: 0
> 
> Fixes: 07e759387788 ("spi: spi-imx: add PIO polling support")

The *fres parameter was introduced in:

| Fixes: 6fd8b8503a0d ("spi: spi-imx: Fix out-of-order CS/SCLK operation at low speeds")

The exiting code:

|	if (unlikely(fspi > fin))
|		return 0;

was not sufficient any more and should be fixed.

Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] spi: spi-imx: Fix spi_bus_clk if requested clock is higher than input clock
  2022-11-15 16:54 ` Marc Kleine-Budde
@ 2022-11-15 17:14   ` Frieder Schrempf
  2022-11-15 17:58     ` Marc Kleine-Budde
  0 siblings, 1 reply; 5+ messages in thread
From: Frieder Schrempf @ 2022-11-15 17:14 UTC (permalink / raw)
  To: Marc Kleine-Budde, Frieder Schrempf
  Cc: David Jander, linux-arm-kernel, linux-kernel, linux-spi,
	Mark Brown, Sascha Hauer, Shawn Guo, Marek Vasut, NXP Linux Team,
	stable, Pengutronix Kernel Team, Baruch Siach, Fabio Estevam,
	Minghao Chi

On 15.11.22 17:54, Marc Kleine-Budde wrote:
> On 15.11.2022 17:26:53, Frieder Schrempf wrote:
>> From: Frieder Schrempf <frieder.schrempf@kontron.de>
>>
>> In case the requested bus clock is higher than the input clock, the correct
>> dividers (pre = 0, post = 0) are returned from mx51_ecspi_clkdiv(), but
>> *fres is left uninitialized and therefore contains an arbitrary value.
>>
>> This causes trouble for the recently introduced PIO polling feature as the
>> value in spi_imx->spi_bus_clk is used there to calculate for which
>> transfers to enable PIO polling.
>>
>> Fix this by setting *fres even if no clock dividers are in use.
>>
>> This issue was observed on Kontron BL i.MX8MM with an SPI peripheral clock set
>> to 50 MHz by default and a requested SPI bus clock of 80 MHz for the SPI NOR
>> flash.
>>
>> With the fix applied the debug message from mx51_ecspi_clkdiv() now prints the
>> following:
>>
>> spi_imx 30820000.spi: mx51_ecspi_clkdiv: fin: 50000000, fspi: 50000000,
>> post: 0, pre: 0
>>
>> Fixes: 07e759387788 ("spi: spi-imx: add PIO polling support")

You want me to remove this tag?

> The *fres parameter was introduced in:
> 
> | Fixes: 6fd8b8503a0d ("spi: spi-imx: Fix out-of-order CS/SCLK operation at low speeds")

and instead add back this tag? I wasn't really sure about that.

> 
> The exiting code:
> 
> |	if (unlikely(fspi > fin))
> |		return 0;
> 
> was not sufficient any more and should be fixed.

You want me to add this in the description? Or is this just the
explanation for why 6fd8b8503a0d should be in the Fixes tag?

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] spi: spi-imx: Fix spi_bus_clk if requested clock is higher than input clock
  2022-11-15 16:26 [PATCH v2] spi: spi-imx: Fix spi_bus_clk if requested clock is higher than input clock Frieder Schrempf
  2022-11-15 16:54 ` Marc Kleine-Budde
@ 2022-11-15 17:24 ` Fabio Estevam
  1 sibling, 0 replies; 5+ messages in thread
From: Fabio Estevam @ 2022-11-15 17:24 UTC (permalink / raw)
  To: Frieder Schrempf
  Cc: David Jander, linux-arm-kernel, linux-kernel, linux-spi,
	Marc Kleine-Budde, Mark Brown, Sascha Hauer, Shawn Guo,
	Frieder Schrempf, Marek Vasut, stable, Baruch Siach, Minghao Chi,
	NXP Linux Team, Pengutronix Kernel Team

On Tue, Nov 15, 2022 at 1:27 PM Frieder Schrempf <frieder@fris.de> wrote:
>
> From: Frieder Schrempf <frieder.schrempf@kontron.de>
>
> In case the requested bus clock is higher than the input clock, the correct
> dividers (pre = 0, post = 0) are returned from mx51_ecspi_clkdiv(), but
> *fres is left uninitialized and therefore contains an arbitrary value.
>
> This causes trouble for the recently introduced PIO polling feature as the
> value in spi_imx->spi_bus_clk is used there to calculate for which
> transfers to enable PIO polling.
>
> Fix this by setting *fres even if no clock dividers are in use.
>
> This issue was observed on Kontron BL i.MX8MM with an SPI peripheral clock set
> to 50 MHz by default and a requested SPI bus clock of 80 MHz for the SPI NOR
> flash.
>
> With the fix applied the debug message from mx51_ecspi_clkdiv() now prints the
> following:
>
> spi_imx 30820000.spi: mx51_ecspi_clkdiv: fin: 50000000, fspi: 50000000,
> post: 0, pre: 0
>
> Fixes: 07e759387788 ("spi: spi-imx: add PIO polling support")
> Cc: Marc Kleine-Budde <mkl@pengutronix.de>
> Cc: David Jander <david@protonic.nl>
> Cc: Fabio Estevam <festevam@gmail.com>
> Cc: Mark Brown <broonie@kernel.org>
> Cc: Marek Vasut <marex@denx.de>
> Cc: stable@vger.kernel.org
> Signed-off-by: Frieder Schrempf <frieder.schrempf@kontron.de>

Thanks for the fix:

Tested-by: Fabio Estevam <festevam@gmail.com>

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v2] spi: spi-imx: Fix spi_bus_clk if requested clock is higher than input clock
  2022-11-15 17:14   ` Frieder Schrempf
@ 2022-11-15 17:58     ` Marc Kleine-Budde
  0 siblings, 0 replies; 5+ messages in thread
From: Marc Kleine-Budde @ 2022-11-15 17:58 UTC (permalink / raw)
  To: Frieder Schrempf
  Cc: Frieder Schrempf, David Jander, linux-arm-kernel, linux-kernel,
	linux-spi, Mark Brown, Sascha Hauer, Shawn Guo, Marek Vasut,
	NXP Linux Team, stable, Pengutronix Kernel Team, Baruch Siach,
	Fabio Estevam, Minghao Chi


[-- Attachment #1.1: Type: text/plain, Size: 2083 bytes --]

On 15.11.2022 18:14:38, Frieder Schrempf wrote:
> On 15.11.22 17:54, Marc Kleine-Budde wrote:
> > On 15.11.2022 17:26:53, Frieder Schrempf wrote:
> >> From: Frieder Schrempf <frieder.schrempf@kontron.de>
> >>
> >> In case the requested bus clock is higher than the input clock, the correct
> >> dividers (pre = 0, post = 0) are returned from mx51_ecspi_clkdiv(), but
> >> *fres is left uninitialized and therefore contains an arbitrary value.
> >>
> >> This causes trouble for the recently introduced PIO polling feature as the
> >> value in spi_imx->spi_bus_clk is used there to calculate for which
> >> transfers to enable PIO polling.
> >>
> >> Fix this by setting *fres even if no clock dividers are in use.
> >>
> >> This issue was observed on Kontron BL i.MX8MM with an SPI peripheral clock set
> >> to 50 MHz by default and a requested SPI bus clock of 80 MHz for the SPI NOR
> >> flash.
> >>
> >> With the fix applied the debug message from mx51_ecspi_clkdiv() now prints the
> >> following:
> >>
> >> spi_imx 30820000.spi: mx51_ecspi_clkdiv: fin: 50000000, fspi: 50000000,
> >> post: 0, pre: 0
> >>
> >> Fixes: 07e759387788 ("spi: spi-imx: add PIO polling support")
> 
> You want me to remove this tag?
> 
> > The *fres parameter was introduced in:
> > 
> > | Fixes: 6fd8b8503a0d ("spi: spi-imx: Fix out-of-order CS/SCLK operation at low speeds")
> 
> and instead add back this tag? I wasn't really sure about that.

Keep both.

> > 
> > The exiting code:
> > 
> > |	if (unlikely(fspi > fin))
> > |		return 0;
> > 
> > was not sufficient any more and should be fixed.
> 
> You want me to add this in the description? Or is this just the
> explanation for why 6fd8b8503a0d should be in the Fixes tag?

No need to add the explanation to the patch.

Marc

-- 
Pengutronix e.K.                 | Marc Kleine-Budde           |
Embedded Linux                   | https://www.pengutronix.de  |
Vertretung West/Dortmund         | Phone: +49-231-2826-924     |
Amtsgericht Hildesheim, HRA 2686 | Fax:   +49-5121-206917-5555 |

[-- Attachment #1.2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

[-- Attachment #2: Type: text/plain, Size: 176 bytes --]

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-11-15 17:59 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-11-15 16:26 [PATCH v2] spi: spi-imx: Fix spi_bus_clk if requested clock is higher than input clock Frieder Schrempf
2022-11-15 16:54 ` Marc Kleine-Budde
2022-11-15 17:14   ` Frieder Schrempf
2022-11-15 17:58     ` Marc Kleine-Budde
2022-11-15 17:24 ` Fabio Estevam

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox