Skip to content

Commit 760951d

Browse files
committed
spi: spi-nxp-fspi: few fix for flexspi
Merge series from Haibo Chen <haibo.chen@nxp.com>: PATCH 1: different operations maybe require different max frequency, so add flexspi to handle such case, re-config the clock rate when new coming operation require new clock frequency. Patch 2: add workaround for erratum ERR050272. Since only add 4us dealy in nxp_fspi_dll_calibration(), so do not distinguish different platforms. Patch 3: add max frequency limitation for different sample clock source selection. Datasheet give max 66MHz for mode 0 and 166MHz for mode 3. And IC suggest to add this limitation on all SoCs for safety and stability.
2 parents 6b6e031 + f43579e commit 760951d

1 file changed

Lines changed: 27 additions & 5 deletions

File tree

drivers/spi/spi-nxp-fspi.c

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,10 @@ struct nxp_fspi {
404404
#define FSPI_NEED_INIT BIT(0)
405405
#define FSPI_DTR_MODE BIT(1)
406406
int flags;
407+
/* save the previous operation clock rate */
408+
unsigned long pre_op_rate;
409+
/* the max clock rate fspi output to device */
410+
unsigned long max_rate;
407411
};
408412

409413
static inline int needs_ip_only(struct nxp_fspi *f)
@@ -685,10 +689,13 @@ static void nxp_fspi_select_rx_sample_clk_source(struct nxp_fspi *f,
685689
* change the mode back to mode 0.
686690
*/
687691
reg = fspi_readl(f, f->iobase + FSPI_MCR0);
688-
if (op_is_dtr)
692+
if (op_is_dtr) {
689693
reg |= FSPI_MCR0_RXCLKSRC(3);
690-
else /*select mode 0 */
694+
f->max_rate = 166000000;
695+
} else { /*select mode 0 */
691696
reg &= ~FSPI_MCR0_RXCLKSRC(3);
697+
f->max_rate = 66000000;
698+
}
692699
fspi_writel(f, reg, f->iobase + FSPI_MCR0);
693700
}
694701

@@ -719,6 +726,12 @@ static void nxp_fspi_dll_calibration(struct nxp_fspi *f)
719726
0, POLL_TOUT, true);
720727
if (ret)
721728
dev_warn(f->dev, "DLL lock failed, please fix it!\n");
729+
730+
/*
731+
* For ERR050272, DLL lock status bit is not accurate,
732+
* wait for 4us more as a workaround.
733+
*/
734+
udelay(4);
722735
}
723736

724737
/*
@@ -780,11 +793,17 @@ static void nxp_fspi_select_mem(struct nxp_fspi *f, struct spi_device *spi,
780793
uint64_t size_kb;
781794

782795
/*
783-
* Return, if previously selected target device is same as current
784-
* requested target device. Also the DTR or STR mode do not change.
796+
* Return when following condition all meet,
797+
* 1, if previously selected target device is same as current
798+
* requested target device.
799+
* 2, the DTR or STR mode do not change.
800+
* 3, previous operation max rate equals current one.
801+
*
802+
* For other case, need to re-config.
785803
*/
786804
if ((f->selected == spi_get_chipselect(spi, 0)) &&
787-
(!!(f->flags & FSPI_DTR_MODE) == op_is_dtr))
805+
(!!(f->flags & FSPI_DTR_MODE) == op_is_dtr) &&
806+
(f->pre_op_rate == op->max_freq))
788807
return;
789808

790809
/* Reset FLSHxxCR0 registers */
@@ -802,6 +821,7 @@ static void nxp_fspi_select_mem(struct nxp_fspi *f, struct spi_device *spi,
802821
dev_dbg(f->dev, "Target device [CS:%x] selected\n", spi_get_chipselect(spi, 0));
803822

804823
nxp_fspi_select_rx_sample_clk_source(f, op_is_dtr);
824+
rate = min(f->max_rate, op->max_freq);
805825

806826
if (op_is_dtr) {
807827
f->flags |= FSPI_DTR_MODE;
@@ -832,6 +852,8 @@ static void nxp_fspi_select_mem(struct nxp_fspi *f, struct spi_device *spi,
832852
else
833853
nxp_fspi_dll_override(f);
834854

855+
f->pre_op_rate = op->max_freq;
856+
835857
f->selected = spi_get_chipselect(spi, 0);
836858
}
837859

0 commit comments

Comments
 (0)