Add FlexSPI support for i.MX RT1170
Subsystems (6)
A message that is not in the archive (sent off-list or not yet received): [email protected]
v2 cover Add FlexSPI support for i.MX RT1170
The nxp_fspi driver is missing some per-device quirks that are needed for imxrt1170 support.
Fortunately, linux (where the driver originated) has since added support for these qirks.
This series cherry-picks the linux commit, then adds the imxrt1170 usage of the quirks.
I believe Jesse Taube is also working on this problem for the i.mxrt1050, however the patches I saw were quite a bit different, thus this RFC.
Changes in v2:
- Rebased to latest master
- Seperated devicetree and binds to their own patch
- Included imxrt1170-evk_defconfig changes missing in v1
Jonathan Currier (5):
spi: fspi: involve lut_num for struct nxp_fspi_devtype_data
spi: fspi: Add imxrt1170 device data
ARM: dts: imx: Add flexspi (fspi) to imxrt1170 and it's evk.
spi: fspi: dev_dbg() call assumes fdt_addr_t always a long long
configs: imxrt1170-evk_defconfig: include FlexSPI driver and flash
chip support
arch/arm/dts/imxrt1170-evk.dts | 28 +++++++++++ arch/arm/dts/imxrt1170.dtsi | 13 +++++ configs/imxrt1170-evk_defconfig | 15 ++++++ drivers/clk/imx/clk-imxrt1170.c | 9 ++++ drivers/spi/nxp_fspi.c | 55 +++++++++++++-------- include/dt-bindings/clock/imxrt1170-clock.h | 4 +- 6 files changed, 103 insertions(+), 21 deletions(-)
Signature · 1 line
2.45.3
RFC PATCH v2 1/5 spi: fspi: involve lut_num for struct nxp_fspi_devtype_data
The flexspi on different SoCs may have different number of LUTs. So involve lut_num in nxp_fspi_devtype_data to make distinguish. This patch prepare for the adding of imx8ulp.
(Picked from linux 190b7e2efb1ed8435fc7431d9c7a2447d05d5066)
--- drivers/spi/nxp_fspi.c | 42 +++++++++++++++++++++++------------------- 1 file changed, 23 insertions(+), 19 deletions(-)
drivers/spi/nxp_fspi.c +23 -19
@@ -52,13 +52,6 @@#include <linux/bug.h> #include <linux/err.h> -/* -* The driver only uses one single LUT entry, that is updated on -* each call of exec_op(). Index 0 is preset at boot with a basic -* read operation, so let's use the last entry (31). -*/ -#define SEQID_LUT 31 -/* Registers used by the driver */ #define FSPI_MCR0 0x00#define FSPI_MCR0_AHB_TIMEOUT (x) ((x) << 24)
@@ -242,9 +235,6 @@#define FSPI_TFDR 0x180#define FSPI_LUT_BASE 0x200 -#define FSPI_LUT_OFFSET (SEQID_LUT * 4 * 4) -#define FSPI_LUT_REG (idx) \ - (FSPI_LUT_BASE + FSPI_LUT_OFFSET + (idx) * 4)/* register map end */
@@ -316,6 +306,7 @@ struct nxp_fspi_devtype_data {unsigned int txfifo;unsigned int ahb_buf_size;unsigned int quirks; +unsigned int lut_num;bool little_endian; };
@@ -324,6 +315,7 @@ static struct nxp_fspi_devtype_data lx2160a_data = { .txfifo = SZ_1K, /* (128 * 64 bits) */ .ahb_buf_size = SZ_2K, /* (256 * 64 bits) */ .quirks = 0, + .lut_num = 32, .little_endian = true, /* little-endian */ };
@@ -332,6 +324,7 @@ static struct nxp_fspi_devtype_data imx8mm_data = { .txfifo = SZ_1K, /* (128 * 64 bits) */ .ahb_buf_size = SZ_2K, /* (256 * 64 bits) */ .quirks = 0, + .lut_num = 32, .little_endian = true, /* little-endian */ };
@@ -486,6 +479,8 @@ static void nxp_fspi_prepare_lut(struct nxp_fspi *f,void __iomem *base = f->iobase;u32 lutval[4 ] = {};int lutidx =1 , i; +u32 lut_offset = (f->devtype_data->lut_num -1 ) *4 *4 ; +u32 target_lut_reg;/* cmd */ lutval[0] |= LUT_DEF(0, LUT_CMD, LUT_PAD(op->cmd.buswidth),
@@ -530,8 +525,10 @@ static void nxp_fspi_prepare_lut(struct nxp_fspi *f,fspi_writel (f,FSPI_LCKER_UNLOCK , f->iobase +FSPI_LCKCR );/* fill LUT */ -for (i =0 ; i <ARRAY_SIZE (lutval); i++) -fspi_writel (f, lutval[i], base +FSPI_LUT_REG (i)); +for (i =0 ; i <ARRAY_SIZE (lutval); i++) { + target_lut_reg =FSPI_LUT_BASE + lut_offset + i *4 ; +fspi_writel (f, lutval[i], base + target_lut_reg); + }dev_dbg (f->dev,"CMD[%x] lutval[0:%x \t 1:%x \t 2:%x \t 3:%x], size: 0x%08x\n" , op->cmd.opcode, lutval[0 ], lutval[1 ], lutval[2 ], lutval[3 ], op->data.nbytes);
@@ -731,7 +728,7 @@ static int nxp_fspi_do_op(struct nxp_fspi *f, const struct spi_mem_op *op)void __iomem *base = f->iobase;int seqnum =0 ;int err =0 ; -u32 reg; +u32 reg, seqid_lut; reg =fspi_readl (f, base +FSPI_IPRXFCR );/* invalid RXFIFO first */
@@ -745,8 +742,9 @@ static int nxp_fspi_do_op(struct nxp_fspi *f, const struct spi_mem_op *op)* the LUT at each exec_op() call. And also specify the DATA * length, since it's has not been specified in the LUT. */ + seqid_lut = f->devtype_data->lut_num -1 ;fspi_writel (f, op->data.nbytes | - (SEQID_LUT <<FSPI_IPCR1_SEQID_SHIFT ) | + (seqid_lut <<FSPI_IPCR1_SEQID_SHIFT ) | (seqnum <<FSPI_IPCR1_SEQNUM_SHIFT ), base +FSPI_IPCR1 );
@@ -862,7 +860,7 @@ static int nxp_fspi_default_setup(struct nxp_fspi *f) {void __iomem *base = f->iobase;int ret, i; -u32 reg; +u32 reg, seqid_lut;#if CONFIG_IS_ENABLED (CLK )/* the default frequency, we will change it later if necessary. */
@@ -933,11 +931,17 @@ static int nxp_fspi_default_setup(struct nxp_fspi *f)fspi_writel (f, reg, base +FSPI_FLSHB1CR1 );fspi_writel (f, reg, base +FSPI_FLSHB2CR1 ); +/* +* The driver only uses one single LUT entry, that is updated on +* each call of exec_op(). Index 0 is preset at boot with a basic +* read operation, so let's use the last entry. +*/ + seqid_lut = f->devtype_data->lut_num -1 ;/* AHB Read - Set lut sequence ID for all CS. */ -fspi_writel (f,SEQID_LUT , base +FSPI_FLSHA1CR2 ); -fspi_writel (f,SEQID_LUT , base +FSPI_FLSHA2CR2 ); -fspi_writel (f,SEQID_LUT , base +FSPI_FLSHB1CR2 ); -fspi_writel (f,SEQID_LUT , base +FSPI_FLSHB2CR2 ); +fspi_writel (f, seqid_lut, base +FSPI_FLSHA1CR2 ); +fspi_writel (f, seqid_lut, base +FSPI_FLSHA2CR2 ); +fspi_writel (f, seqid_lut, base +FSPI_FLSHB1CR2 ); +fspi_writel (f, seqid_lut, base +FSPI_FLSHB2CR2 );return 0 ; }
Signature · 1 line
2.45.3
RFC PATCH v2 2/5 spi: fspi: Add imxrt1170 device data
In reply to Jonathan CurrierAdd the device specific driver data, and the clock configuration.
--- drivers/clk/imx/clk-imxrt1170.c | 9 +++++++++ drivers/spi/nxp_fspi.c | 10 ++++++++++ 2 files changed, 19 insertions(+)
drivers/clk/imx/clk-imxrt1170.c +9 -0
@@ -105,6 +105,8 @@ static const char * const usdhc1_sels[] = {"rcosc48M_div2", "osc", "rcosc400M", "pll2_pfd2", "pll2_pfd0", "pll1_div5", "pll_arm"};static const char *const semc_sels[] = {"rcosc48M_div2" ,"osc" ,"rcosc400M" ,"rcosc16M" ,"pll1_div5" ,"pll2_sys" ,"pll2_pfd2" ,"pll3_pfd0" }; +static const char *const flexspi1_sels[] = {"rcosc48M_div2" ,"osc" ,"rcosc400M" ,"rcosc16M" , +"pll3_pdf0" ,"pll2_clk" ,"pll2_pfd2" ,"pll3_clk" };static int imxrt1170_clk_probe (struct udevice *dev) {
@@ -163,6 +165,13 @@ static int imxrt1170_clk_probe(struct udevice *dev)imx_clk_divider (dev,"lpuart1" ,"lpuart1_sel" , base + (25 * 0x80), 0, 8)); +clk_dm (IMXRT1170_CLK_FLEXSPI1_SEL , +imx_clk_mux (dev,"flexspi1_sel" , base + (20 *0x80 ),8 ,3 , + flexspi1_sels,ARRAY_SIZE (flexspi1_sels))); +clk_dm (IMXRT1170_CLK_FLEXSPI1 , +imx_clk_divider (dev,"flexspi1" ,"flexspi1_sel" , + base + (20 *0x80 ),0 ,8 )); +clk_dm (IMXRT1170_CLK_USDHC1_SEL ,imx_clk_mux (dev,"usdhc1_sel" , base + (58 *0x80 ),8 ,3 , usdhc1_sels,ARRAY_SIZE (usdhc1_sels)));
drivers/spi/nxp_fspi.c +10 -0
@@ -328,6 +328,15 @@ static struct nxp_fspi_devtype_data imx8mm_data = { .little_endian = true, /* little-endian */ }; +static struct nxp_fspi_devtype_data imxrt1170_data = { + .rxfifo =SZ_256 , + .txfifo =SZ_256 , + .ahb_buf_size =SZ_4K , + .quirks =0 , + .lut_num =16 , + .little_endian = true, +}; +struct nxp_fspi {struct udevice *dev;void __iomem *iobase;
@@ -1061,6 +1070,7 @@ static const struct udevice_id nxp_fspi_ids[] = { { .compatible = "nxp,lx2160a-fspi", .data = (ulong)&lx2160a_data, }, { .compatible = "nxp,imx8mm-fspi", .data = (ulong)&imx8mm_data, }, { .compatible = "nxp,imx8mp-fspi", .data = (ulong)&imx8mm_data, }, + { .compatible = "nxp,imxrt1170-fspi", .data = (ulong)&imxrt1170_data, }, { } };
Signature · 1 line
2.45.3
RFC PATCH v2 3/5 ARM: dts: imx: Add flexspi (fspi) to imxrt1170 and it's evk.
In reply to Jonathan Currier--- arch/arm/dts/imxrt1170-evk.dts | 28 +++++++++++++++++++++ arch/arm/dts/imxrt1170.dtsi | 13 ++++++++++ include/dt-bindings/clock/imxrt1170-clock.h | 4 ++- 3 files changed, 44 insertions(+), 1 deletion(-)
arch/arm/dts/imxrt1170-evk.dts +28 -0
@@ -234,6 +234,34 @@ (IMX_PAD_SION | 8) /* SEMC_DQS */ >; }; + + pinctrl_flexspi1: flexspi1grp { + fsl,pins = < + IOMUXC_GPIO_SD_B2_05_FLEXSPI1_A_DQS 0xa + IOMUXC_GPIO_SD_B2_06_FLEXSPI1_A_SS0_B 0xa + IOMUXC_GPIO_SD_B2_07_FLEXSPI1_A_SCLK 0xa + IOMUXC_GPIO_SD_B2_08_FLEXSPI1_A_DATA00 0xa + IOMUXC_GPIO_SD_B2_09_FLEXSPI1_A_DATA01 0xa + IOMUXC_GPIO_SD_B2_10_FLEXSPI1_A_DATA02 0xa + IOMUXC_GPIO_SD_B2_11_FLEXSPI1_A_DATA03 0xa + >; + }; + }; +}; + +&flexspi1 { + pinctrl-names = "default"; + pinctrl-0 = <&pinctrl_flexspi1>; + status = "okay"; + + flash@0 { + compatible = "jedec,spi-nor"; + reg = <0>; + #address-cells = <1>; + #size-cells = <1>; + spi-max-frequency = <250000000>; + spi-tx-bus-width = <4>; + spi-rx-bus-width = <4>; }; };
arch/arm/dts/imxrt1170.dtsi +13 -0
@@ -246,6 +246,19 @@ #interrupt-cells = <2>; }; + flexspi1: spi@400cc000 { + compatible = "nxp,imxrt1170-fspi"; + reg = <0x400cc000 0x800>, <0x30000000 0x10000000>; + reg-names = "fspi_base", "fspi_mmap"; + #address-cells = <1>; + #size-cells = <0>; + interrupts = <130>; + clocks = <&clks IMXRT1170_CLK_DUMMY>, + <&clks IMXRT1170_CLK_FLEXSPI1>; + clock-names = "fspi_en", "fspi"; + status = "disabled"; + }; + gpt1: gpt1@400ec000 { compatible = "fsl,imxrt-gpt"; reg = <0x400ec000 0x4000>;
include/dt-bindings/clock/imxrt1170-clock.h +3 -1
@@ -43,6 +43,8 @@#define IMXRT1170_CLK_GPT1 33#define IMXRT1170_CLK_SEMC_SEL 34#define IMXRT1170_CLK_SEMC 35 -#define IMXRT1170_CLK_END 36 +#define IMXRT1170_CLK_FLEXSPI1_SEL 36 +#define IMXRT1170_CLK_FLEXSPI1 37 +#define IMXRT1170_CLK_END 38#endif /* __DT_BINDINGS_CLOCK_IMXRT1170_H */
Signature · 1 line
2.45.3
RFC PATCH v2 4/5 spi: fspi: dev_dbg() call assumes fdt_addr_t always a long long
In reply to Jonathan CurrierOn 32-bit systems, e.g. i.mxrt-1170 fdt_addr_t may only be 32-bit. Cast to a "long long" for garbage avoidance.
--- drivers/spi/nxp_fspi.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/spi/nxp_fspi.c +2 -1
@@ -1048,7 +1048,8 @@ static int nxp_fspi_of_to_plat(struct udevice *bus) }#endif -dev_dbg (bus,"iobase=<0x%llx>, ahb_addr=<0x%llx>\n" , iobase, ahb_addr); +dev_dbg (bus,"iobase=<0x%llx>, ahb_addr=<0x%llx>\n" , + (long long )iobase, (long long )ahb_addr);return 0 ; }
Signature · 1 line
2.45.3
RFC PATCH v2 5/5 configs: imxrt1170-evk_defconfig: include FlexSPI driver and flash chip support
In reply to Jonathan Currier--- configs/imxrt1170-evk_defconfig | 15 +++++++++++++++ 1 file changed, 15 insertions(+)
configs/imxrt1170-evk_defconfig +15 -0
@@ -37,6 +37,8 @@ CONFIG_SYS_MMCSD_RAW_MODE_U_BOOT_SECTOR=0x100 # CONFIG_BOOTM_PLAN9 is not set # CONFIG_BOOTM_RTEMS is not set # CONFIG_BOOTM_VXWORKS is not set +CONFIG_CMD_MTD=y +CONFIG_CMD_SPI=y # CONFIG_CMD_MII is not set # CONFIG_SPL_DOS_PARTITION is not set # CONFIG_ISO_PARTITION is not set
@@ -58,6 +60,15 @@ CONFIG_CLK_IMXRT1170=y CONFIG_MXC_GPIO=y # CONFIG_INPUT is not set CONFIG_FSL_USDHC=y +CONFIG_MTD=y +CONFIG_DM_MTD=y +CONFIG_MTD_BLOCK=y +CONFIG_CFI_FLASH=y +CONFIG_FLASH_CFI_MTD=y +CONFIG_DM_SPI_FLASH=y +CONFIG_SPI_FLASH_SOFT_RESET=y +CONFIG_SPI_FLASH_ISSI=y +CONFIG_SPI_FLASH_MTD=y CONFIG_PINCTRL=y CONFIG_SPL_PINCTRL=y CONFIG_PINCTRL_IMXRT=y
@@ -65,6 +76,10 @@ CONFIG_RAM=y CONFIG_SPL_RAM=y CONFIG_IMXRT_SDRAM=y CONFIG_FSL_LPUART=y +CONFIG_SPI=y +CONFIG_DM_SPI=y +CONFIG_SPI_DIRMAP=y +CONFIG_NXP_FSPI=y CONFIG_TIMER=y CONFIG_SPL_TIMER=y CONFIG_IMX_GPT_TIMER=y
Signature · 1 line
2.45.3
Quoted 15 lines · Jonathan Currier
The
nxp_fspidriver is missing some per-device quirks that are needed for imxrt1170 support.Fortunately, linux (where the driver originated) has since added support for these qirks.
This series cherry-picks the linux commit, then adds the imxrt1170 usage of the quirks.
I believe Jesse Taube is also working on this problem for the i.mxrt1050, however the patches I saw were quite a bit different, thus this RFC.
Quoted 4 lines
Changes in v2:
- Rebased to latest master
- Seperated devicetree and binds to their own patch
- Included imxrt1170-evk_defconfig changes missing in v1
Applied all, thanks.