5757#include <linux/spi/spi.h>
5858#include <linux/spi/spi-mem.h>
5959
60- /*
61- * The driver only uses one single LUT entry, that is updated on
62- * each call of exec_op(). Index 0 is preset at boot with a basic
63- * read operation, so let's use the last entry (31).
64- */
65- #define SEQID_LUT 31
66-
6760/* Registers used by the driver */
6861#define FSPI_MCR0 0x00
6962#define FSPI_MCR0_AHB_TIMEOUT (x ) ((x) << 24)
263256#define FSPI_TFDR 0x180
264257
265258#define FSPI_LUT_BASE 0x200
266- #define FSPI_LUT_OFFSET (SEQID_LUT * 4 * 4)
267- #define FSPI_LUT_REG (idx ) \
268- (FSPI_LUT_BASE + FSPI_LUT_OFFSET + (idx) * 4)
269259
270260/* register map end */
271261
@@ -341,6 +331,7 @@ struct nxp_fspi_devtype_data {
341331 unsigned int txfifo ;
342332 unsigned int ahb_buf_size ;
343333 unsigned int quirks ;
334+ unsigned int lut_num ;
344335 bool little_endian ;
345336};
346337
@@ -349,6 +340,7 @@ static struct nxp_fspi_devtype_data lx2160a_data = {
349340 .txfifo = SZ_1K , /* (128 * 64 bits) */
350341 .ahb_buf_size = SZ_2K , /* (256 * 64 bits) */
351342 .quirks = 0 ,
343+ .lut_num = 32 ,
352344 .little_endian = true, /* little-endian */
353345};
354346
@@ -357,6 +349,7 @@ static struct nxp_fspi_devtype_data imx8mm_data = {
357349 .txfifo = SZ_1K , /* (128 * 64 bits) */
358350 .ahb_buf_size = SZ_2K , /* (256 * 64 bits) */
359351 .quirks = 0 ,
352+ .lut_num = 32 ,
360353 .little_endian = true, /* little-endian */
361354};
362355
@@ -365,6 +358,7 @@ static struct nxp_fspi_devtype_data imx8qxp_data = {
365358 .txfifo = SZ_1K , /* (128 * 64 bits) */
366359 .ahb_buf_size = SZ_2K , /* (256 * 64 bits) */
367360 .quirks = 0 ,
361+ .lut_num = 32 ,
368362 .little_endian = true, /* little-endian */
369363};
370364
@@ -373,6 +367,7 @@ static struct nxp_fspi_devtype_data imx8dxl_data = {
373367 .txfifo = SZ_1K , /* (128 * 64 bits) */
374368 .ahb_buf_size = SZ_2K , /* (256 * 64 bits) */
375369 .quirks = FSPI_QUIRK_USE_IP_ONLY ,
370+ .lut_num = 32 ,
376371 .little_endian = true, /* little-endian */
377372};
378373
@@ -544,6 +539,8 @@ static void nxp_fspi_prepare_lut(struct nxp_fspi *f,
544539 void __iomem * base = f -> iobase ;
545540 u32 lutval [4 ] = {};
546541 int lutidx = 1 , i ;
542+ u32 lut_offset = (f -> devtype_data -> lut_num - 1 ) * 4 * 4 ;
543+ u32 target_lut_reg ;
547544
548545 /* cmd */
549546 lutval [0 ] |= LUT_DEF (0 , LUT_CMD , LUT_PAD (op -> cmd .buswidth ),
@@ -588,8 +585,10 @@ static void nxp_fspi_prepare_lut(struct nxp_fspi *f,
588585 fspi_writel (f , FSPI_LCKER_UNLOCK , f -> iobase + FSPI_LCKCR );
589586
590587 /* fill LUT */
591- for (i = 0 ; i < ARRAY_SIZE (lutval ); i ++ )
592- fspi_writel (f , lutval [i ], base + FSPI_LUT_REG (i ));
588+ for (i = 0 ; i < ARRAY_SIZE (lutval ); i ++ ) {
589+ target_lut_reg = FSPI_LUT_BASE + lut_offset + i * 4 ;
590+ fspi_writel (f , lutval [i ], base + target_lut_reg );
591+ }
593592
594593 dev_dbg (f -> dev , "CMD[%02x] lutval[0:%08x 1:%08x 2:%08x 3:%08x], size: 0x%08x\n" ,
595594 op -> cmd .opcode , lutval [0 ], lutval [1 ], lutval [2 ], lutval [3 ], op -> data .nbytes );
@@ -874,7 +873,7 @@ static int nxp_fspi_do_op(struct nxp_fspi *f, const struct spi_mem_op *op)
874873 void __iomem * base = f -> iobase ;
875874 int seqnum = 0 ;
876875 int err = 0 ;
877- u32 reg ;
876+ u32 reg , seqid_lut ;
878877
879878 reg = fspi_readl (f , base + FSPI_IPRXFCR );
880879 /* invalid RXFIFO first */
@@ -890,8 +889,9 @@ static int nxp_fspi_do_op(struct nxp_fspi *f, const struct spi_mem_op *op)
890889 * the LUT at each exec_op() call. And also specify the DATA
891890 * length, since it's has not been specified in the LUT.
892891 */
892+ seqid_lut = f -> devtype_data -> lut_num - 1 ;
893893 fspi_writel (f , op -> data .nbytes |
894- (SEQID_LUT << FSPI_IPCR1_SEQID_SHIFT ) |
894+ (seqid_lut << FSPI_IPCR1_SEQID_SHIFT ) |
895895 (seqnum << FSPI_IPCR1_SEQNUM_SHIFT ),
896896 base + FSPI_IPCR1 );
897897
@@ -1015,7 +1015,7 @@ static int nxp_fspi_default_setup(struct nxp_fspi *f)
10151015{
10161016 void __iomem * base = f -> iobase ;
10171017 int ret , i ;
1018- u32 reg ;
1018+ u32 reg , seqid_lut ;
10191019
10201020 /* disable and unprepare clock to avoid glitch pass to controller */
10211021 nxp_fspi_clk_disable_unprep (f );
@@ -1090,11 +1090,17 @@ static int nxp_fspi_default_setup(struct nxp_fspi *f)
10901090 fspi_writel (f , reg , base + FSPI_FLSHB1CR1 );
10911091 fspi_writel (f , reg , base + FSPI_FLSHB2CR1 );
10921092
1093+ /*
1094+ * The driver only uses one single LUT entry, that is updated on
1095+ * each call of exec_op(). Index 0 is preset at boot with a basic
1096+ * read operation, so let's use the last entry.
1097+ */
1098+ seqid_lut = f -> devtype_data -> lut_num - 1 ;
10931099 /* AHB Read - Set lut sequence ID for all CS. */
1094- fspi_writel (f , SEQID_LUT , base + FSPI_FLSHA1CR2 );
1095- fspi_writel (f , SEQID_LUT , base + FSPI_FLSHA2CR2 );
1096- fspi_writel (f , SEQID_LUT , base + FSPI_FLSHB1CR2 );
1097- fspi_writel (f , SEQID_LUT , base + FSPI_FLSHB2CR2 );
1100+ fspi_writel (f , seqid_lut , base + FSPI_FLSHA1CR2 );
1101+ fspi_writel (f , seqid_lut , base + FSPI_FLSHA2CR2 );
1102+ fspi_writel (f , seqid_lut , base + FSPI_FLSHB1CR2 );
1103+ fspi_writel (f , seqid_lut , base + FSPI_FLSHB2CR2 );
10981104
10991105 f -> selected = -1 ;
11001106
0 commit comments