From 3f00e5f1190840d61592f53b8cb0b041d6e59ec1 Mon Sep 17 00:00:00 2001 From: Pratyush Yadav Date: Mon, 5 Oct 2020 23:36:11 +0530 Subject: [PATCH] spi: spi-cadence-quadspi: Search for rxlow at incrementing TX values commit 44a68f7b5931677bd0a99cf7d6683ce7ca05331f from git://git.ti.com/ti-linux-kernel/ti-linux-kernel.git Sometimes TX = 16 might fall outside the range of valid TX values. In that case, the tuning algorithm would be unable to find rxlow or rxhigh, and give up. If TX = 16 is on the border of the valid range, then on some runs it would succeed and on some others it would fail. So if rxlow is not found at the initial TX value of 16, do not give up. Instead, increment the TX and look for it again. This process is repeated until the TX crosses a threshold, after which an error is returned. A similar process is followed for the upper TX boundary as well. Signed-off-by: Pratyush Yadav Signed-off-by: Xulin Sun --- drivers/spi/spi-cadence-quadspi.c | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi-cadence-quadspi.c b/drivers/spi/spi-cadence-quadspi.c index fc888237988d..ea4857b98a92 100644 --- a/drivers/spi/spi-cadence-quadspi.c +++ b/drivers/spi/spi-cadence-quadspi.c @@ -277,6 +277,8 @@ struct cqspi_driver_platdata { #define CQSPI_PHY_HIGH_RX_BOUND 25 #define CQSPI_PHY_LOW_TX_BOUND 32 #define CQSPI_PHY_HIGH_TX_BOUND 48 +#define CQSPI_PHY_TX_LOOKUP_LOW_BOUND 24 +#define CQSPI_PHY_TX_LOOKUP_HIGH_BOUND 38 #define CQSPI_PHY_DEFAULT_TEMP 45 #define CQSPI_PHY_MIN_TEMP -45 @@ -575,15 +577,19 @@ static int cqspi_phy_calibrate(struct cqspi_flash_pdata *f_pdata, /* Look for RX boundaries at TX = 16. */ rxlow.tx = 16; - rxhigh.tx = 16; - rxlow.read_delay = CQSPI_PHY_INIT_RD; - ret = cqspi_find_rx_low(f_pdata, mem, &rxlow); + do { + dev_dbg(dev, "Searching for rxlow on TX = %d\n", rxlow.tx); + rxlow.read_delay = CQSPI_PHY_INIT_RD; + ret = cqspi_find_rx_low(f_pdata, mem, &rxlow); + } while (ret && ++rxlow.tx <= CQSPI_PHY_TX_LOOKUP_LOW_BOUND); + if (ret) goto out; dev_dbg(dev, "rxlow: RX: %d TX: %d RD: %d\n", rxlow.rx, rxlow.tx, rxlow.read_delay); + rxhigh.tx = rxlow.tx; rxhigh.read_delay = rxlow.read_delay; cqspi_find_rx_high(f_pdata, mem, &rxhigh); if (ret) @@ -601,9 +607,14 @@ static int cqspi_phy_calibrate(struct cqspi_flash_pdata *f_pdata, /* Look for RX boundaries at TX = 48. */ temp.tx = 48; - temp.read_delay = CQSPI_PHY_INIT_RD; - ret = cqspi_find_rx_low(f_pdata, mem, &temp); + do { + dev_dbg(dev, "Searching for rxlow on TX = %d\n", + temp.tx); + temp.read_delay = CQSPI_PHY_INIT_RD; + ret = cqspi_find_rx_low(f_pdata, mem, &temp); + } while (ret && --temp.tx >= CQSPI_PHY_TX_LOOKUP_HIGH_BOUND); + if (ret) goto out; dev_dbg(dev, "rxlow: RX: %d TX: %d RD: %d\n", temp.rx, temp.tx,