Skip to content

Commit 135cbd3

Browse files
Marek Vasutbroonie
authored andcommitted
spi: imx: mx51-ecspi: Reinstate low-speed CONFIGREG delay
Since 00b80ac ("spi: imx: mx51-ecspi: Move some initialisation to prepare_message hook."), the MX51_ECSPI_CONFIG write no longer happens in prepare_transfer hook, but rather in prepare_message hook, however the MX51_ECSPI_CONFIG delay is still left in prepare_transfer hook and thus has no effect. This leads to low bus frequency operation problems described in 6fd8b85 ("spi: spi-imx: Fix out-of-order CS/SCLK operation at low speeds") again. Move the MX51_ECSPI_CONFIG write delay into the prepare_message hook as well, thus reinstating the low bus frequency fix. Fixes: 00b80ac ("spi: imx: mx51-ecspi: Move some initialisation to prepare_message hook.") Signed-off-by: Marek Vasut <[email protected]> Cc: Uwe Kleine-König <[email protected]> Cc: Mark Brown <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Mark Brown <[email protected]>
1 parent e4a5c19 commit 135cbd3

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

drivers/spi/spi-imx.c

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -506,7 +506,7 @@ static int mx51_ecspi_prepare_message(struct spi_imx_data *spi_imx,
506506
{
507507
struct spi_device *spi = msg->spi;
508508
u32 ctrl = MX51_ECSPI_CTRL_ENABLE;
509-
u32 testreg;
509+
u32 testreg, delay;
510510
u32 cfg = readl(spi_imx->base + MX51_ECSPI_CONFIG);
511511

512512
/* set Master or Slave mode */
@@ -567,14 +567,31 @@ static int mx51_ecspi_prepare_message(struct spi_imx_data *spi_imx,
567567

568568
writel(cfg, spi_imx->base + MX51_ECSPI_CONFIG);
569569

570+
/*
571+
* Wait until the changes in the configuration register CONFIGREG
572+
* propagate into the hardware. It takes exactly one tick of the
573+
* SCLK clock, but we will wait two SCLK clock just to be sure. The
574+
* effect of the delay it takes for the hardware to apply changes
575+
* is noticable if the SCLK clock run very slow. In such a case, if
576+
* the polarity of SCLK should be inverted, the GPIO ChipSelect might
577+
* be asserted before the SCLK polarity changes, which would disrupt
578+
* the SPI communication as the device on the other end would consider
579+
* the change of SCLK polarity as a clock tick already.
580+
*/
581+
delay = (2 * 1000000) / spi_imx->spi_bus_clk;
582+
if (likely(delay < 10)) /* SCLK is faster than 100 kHz */
583+
udelay(delay);
584+
else /* SCLK is _very_ slow */
585+
usleep_range(delay, delay + 10);
586+
570587
return 0;
571588
}
572589

573590
static int mx51_ecspi_prepare_transfer(struct spi_imx_data *spi_imx,
574591
struct spi_device *spi)
575592
{
576593
u32 ctrl = readl(spi_imx->base + MX51_ECSPI_CTRL);
577-
u32 clk, delay;
594+
u32 clk;
578595

579596
/* Clear BL field and set the right value */
580597
ctrl &= ~MX51_ECSPI_CTRL_BL_MASK;
@@ -596,23 +613,6 @@ static int mx51_ecspi_prepare_transfer(struct spi_imx_data *spi_imx,
596613

597614
writel(ctrl, spi_imx->base + MX51_ECSPI_CTRL);
598615

599-
/*
600-
* Wait until the changes in the configuration register CONFIGREG
601-
* propagate into the hardware. It takes exactly one tick of the
602-
* SCLK clock, but we will wait two SCLK clock just to be sure. The
603-
* effect of the delay it takes for the hardware to apply changes
604-
* is noticable if the SCLK clock run very slow. In such a case, if
605-
* the polarity of SCLK should be inverted, the GPIO ChipSelect might
606-
* be asserted before the SCLK polarity changes, which would disrupt
607-
* the SPI communication as the device on the other end would consider
608-
* the change of SCLK polarity as a clock tick already.
609-
*/
610-
delay = (2 * 1000000) / clk;
611-
if (likely(delay < 10)) /* SCLK is faster than 100 kHz */
612-
udelay(delay);
613-
else /* SCLK is _very_ slow */
614-
usleep_range(delay, delay + 10);
615-
616616
return 0;
617617
}
618618

0 commit comments

Comments
 (0)