1 // SPDX-License-Identifier: GPL-2.0+
4 * Freescale QuadSPI driver.
6 * Copyright (C) 2013 Freescale Semiconductor, Inc.
7 * Copyright (C) 2018 Bootlin
8 * Copyright (C) 2018 exceet electronics GmbH
9 * Copyright (C) 2018 Kontron Electronics GmbH
10 * Copyright 2019-2020 NXP
12 * This driver is a ported version of Linux Freescale QSPI driver taken from
13 * v5.5-rc1 tag having following information.
15 * Transition to SPI MEM interface:
17 * Boris Brezillon <bbrezillon@kernel.org>
18 * Frieder Schrempf <frieder.schrempf@kontron.de>
19 * Yogesh Gaur <yogeshnarayan.gaur@nxp.com>
20 * Suresh Gupta <suresh.gupta@nxp.com>
22 * Based on the original fsl-quadspi.c spi-nor driver.
23 * Transition to spi-mem in spi-fsl-qspi.c
28 #include <linux/libfdt.h>
29 #include <linux/sizes.h>
30 #include <linux/iopoll.h>
32 #include <linux/iopoll.h>
33 #include <linux/sizes.h>
34 #include <linux/err.h>
38 DECLARE_GLOBAL_DATA_PTR;
41 * The driver only uses one single LUT entry, that is updated on
42 * each call of exec_op(). Index 0 is preset at boot with a basic
43 * read operation, so let's use the last entry (15).
47 /* Registers used by the driver */
48 #define QUADSPI_MCR 0x00
49 #define QUADSPI_MCR_RESERVED_MASK GENMASK(19, 16)
50 #define QUADSPI_MCR_MDIS_MASK BIT(14)
51 #define QUADSPI_MCR_CLR_TXF_MASK BIT(11)
52 #define QUADSPI_MCR_CLR_RXF_MASK BIT(10)
53 #define QUADSPI_MCR_DDR_EN_MASK BIT(7)
54 #define QUADSPI_MCR_END_CFG_MASK GENMASK(3, 2)
55 #define QUADSPI_MCR_SWRSTHD_MASK BIT(1)
56 #define QUADSPI_MCR_SWRSTSD_MASK BIT(0)
58 #define QUADSPI_IPCR 0x08
59 #define QUADSPI_IPCR_SEQID(x) ((x) << 24)
60 #define QUADSPI_FLSHCR 0x0c
61 #define QUADSPI_FLSHCR_TCSS_MASK GENMASK(3, 0)
62 #define QUADSPI_FLSHCR_TCSH_MASK GENMASK(11, 8)
63 #define QUADSPI_FLSHCR_TDH_MASK GENMASK(17, 16)
65 #define QUADSPI_BUF3CR 0x1c
66 #define QUADSPI_BUF3CR_ALLMST_MASK BIT(31)
67 #define QUADSPI_BUF3CR_ADATSZ(x) ((x) << 8)
68 #define QUADSPI_BUF3CR_ADATSZ_MASK GENMASK(15, 8)
70 #define QUADSPI_BFGENCR 0x20
71 #define QUADSPI_BFGENCR_SEQID(x) ((x) << 12)
73 #define QUADSPI_BUF0IND 0x30
74 #define QUADSPI_BUF1IND 0x34
75 #define QUADSPI_BUF2IND 0x38
76 #define QUADSPI_SFAR 0x100
78 #define QUADSPI_SMPR 0x108
79 #define QUADSPI_SMPR_DDRSMP_MASK GENMASK(18, 16)
80 #define QUADSPI_SMPR_FSDLY_MASK BIT(6)
81 #define QUADSPI_SMPR_FSPHS_MASK BIT(5)
82 #define QUADSPI_SMPR_HSENA_MASK BIT(0)
84 #define QUADSPI_RBCT 0x110
85 #define QUADSPI_RBCT_WMRK_MASK GENMASK(4, 0)
86 #define QUADSPI_RBCT_RXBRD_USEIPS BIT(8)
88 #define QUADSPI_TBDR 0x154
90 #define QUADSPI_SR 0x15c
91 #define QUADSPI_SR_IP_ACC_MASK BIT(1)
92 #define QUADSPI_SR_AHB_ACC_MASK BIT(2)
94 #define QUADSPI_FR 0x160
95 #define QUADSPI_FR_TFF_MASK BIT(0)
97 #define QUADSPI_RSER 0x164
98 #define QUADSPI_RSER_TFIE BIT(0)
100 #define QUADSPI_SPTRCLR 0x16c
101 #define QUADSPI_SPTRCLR_IPPTRC BIT(8)
102 #define QUADSPI_SPTRCLR_BFPTRC BIT(0)
104 #define QUADSPI_SFA1AD 0x180
105 #define QUADSPI_SFA2AD 0x184
106 #define QUADSPI_SFB1AD 0x188
107 #define QUADSPI_SFB2AD 0x18c
108 #define QUADSPI_RBDR(x) (0x200 + ((x) * 4))
110 #define QUADSPI_LUTKEY 0x300
111 #define QUADSPI_LUTKEY_VALUE 0x5AF05AF0
113 #define QUADSPI_LCKCR 0x304
114 #define QUADSPI_LCKER_LOCK BIT(0)
115 #define QUADSPI_LCKER_UNLOCK BIT(1)
117 #define QUADSPI_LUT_BASE 0x310
118 #define QUADSPI_LUT_OFFSET (SEQID_LUT * 4 * 4)
119 #define QUADSPI_LUT_REG(idx) \
120 (QUADSPI_LUT_BASE + QUADSPI_LUT_OFFSET + (idx) * 4)
122 /* Instruction set for the LUT register */
130 #define LUT_FSL_READ 7
131 #define LUT_FSL_WRITE 8
132 #define LUT_JMP_ON_CS 9
133 #define LUT_ADDR_DDR 10
134 #define LUT_MODE_DDR 11
135 #define LUT_MODE2_DDR 12
136 #define LUT_MODE4_DDR 13
137 #define LUT_FSL_READ_DDR 14
138 #define LUT_FSL_WRITE_DDR 15
139 #define LUT_DATA_LEARN 16
142 * The PAD definitions for LUT register.
144 * The pad stands for the number of IO lines [0:3].
145 * For example, the quad read needs four IO lines,
146 * so you should use LUT_PAD(4).
148 #define LUT_PAD(x) (fls(x) - 1)
151 * Macro for constructing the LUT entries with the following
154 * ---------------------------------------------------
155 * | INSTR1 | PAD1 | OPRND1 | INSTR0 | PAD0 | OPRND0 |
156 * ---------------------------------------------------
158 #define LUT_DEF(idx, ins, pad, opr) \
159 ((((ins) << 10) | ((pad) << 8) | (opr)) << (((idx) % 2) * 16))
161 /* Controller needs driver to swap endianness */
162 #define QUADSPI_QUIRK_SWAP_ENDIAN BIT(0)
164 /* Controller needs 4x internal clock */
165 #define QUADSPI_QUIRK_4X_INT_CLK BIT(1)
168 * TKT253890, the controller needs the driver to fill the txfifo with
169 * 16 bytes at least to trigger a data transfer, even though the extra
170 * data won't be transferred.
172 #define QUADSPI_QUIRK_TKT253890 BIT(2)
174 /* TKT245618, the controller cannot wake up from wait mode */
175 #define QUADSPI_QUIRK_TKT245618 BIT(3)
178 * Controller adds QSPI_AMBA_BASE (base address of the mapped memory)
179 * internally. No need to add it when setting SFXXAD and SFAR registers
181 #define QUADSPI_QUIRK_BASE_INTERNAL BIT(4)
184 * Controller uses TDH bits in register QUADSPI_FLSHCR.
185 * They need to be set in accordance with the DDR/SDR mode.
187 #define QUADSPI_QUIRK_USE_TDH_SETTING BIT(5)
189 struct fsl_qspi_devtype_data {
192 unsigned int ahb_buf_size;
197 static const struct fsl_qspi_devtype_data vybrid_data = {
200 .ahb_buf_size = SZ_1K,
201 .quirks = QUADSPI_QUIRK_SWAP_ENDIAN,
202 .little_endian = true,
205 static const struct fsl_qspi_devtype_data imx6sx_data = {
208 .ahb_buf_size = SZ_1K,
209 .quirks = QUADSPI_QUIRK_4X_INT_CLK | QUADSPI_QUIRK_TKT245618,
210 .little_endian = true,
213 static const struct fsl_qspi_devtype_data imx7d_data = {
216 .ahb_buf_size = SZ_1K,
217 .quirks = QUADSPI_QUIRK_TKT253890 | QUADSPI_QUIRK_4X_INT_CLK |
218 QUADSPI_QUIRK_USE_TDH_SETTING,
219 .little_endian = true,
222 static const struct fsl_qspi_devtype_data imx6ul_data = {
225 .ahb_buf_size = SZ_1K,
226 .quirks = QUADSPI_QUIRK_TKT253890 | QUADSPI_QUIRK_4X_INT_CLK |
227 QUADSPI_QUIRK_USE_TDH_SETTING,
228 .little_endian = true,
231 static const struct fsl_qspi_devtype_data ls1021a_data = {
234 .ahb_buf_size = SZ_1K,
236 .little_endian = false,
239 static const struct fsl_qspi_devtype_data ls1088a_data = {
242 .ahb_buf_size = SZ_1K,
243 .quirks = QUADSPI_QUIRK_TKT253890,
244 .little_endian = true,
247 static const struct fsl_qspi_devtype_data ls2080a_data = {
250 .ahb_buf_size = SZ_1K,
251 .quirks = QUADSPI_QUIRK_TKT253890 | QUADSPI_QUIRK_BASE_INTERNAL,
252 .little_endian = true,
257 void __iomem *iobase;
258 void __iomem *ahb_addr;
260 const struct fsl_qspi_devtype_data *devtype_data;
264 static inline int needs_swap_endian(struct fsl_qspi *q)
266 return q->devtype_data->quirks & QUADSPI_QUIRK_SWAP_ENDIAN;
269 static inline int needs_4x_clock(struct fsl_qspi *q)
271 return q->devtype_data->quirks & QUADSPI_QUIRK_4X_INT_CLK;
274 static inline int needs_fill_txfifo(struct fsl_qspi *q)
276 return q->devtype_data->quirks & QUADSPI_QUIRK_TKT253890;
279 static inline int needs_wakeup_wait_mode(struct fsl_qspi *q)
281 return q->devtype_data->quirks & QUADSPI_QUIRK_TKT245618;
284 static inline int needs_amba_base_offset(struct fsl_qspi *q)
286 return !(q->devtype_data->quirks & QUADSPI_QUIRK_BASE_INTERNAL);
289 static inline int needs_tdh_setting(struct fsl_qspi *q)
291 return q->devtype_data->quirks & QUADSPI_QUIRK_USE_TDH_SETTING;
295 * An IC bug makes it necessary to rearrange the 32-bit data.
296 * Later chips, such as IMX6SLX, have fixed this bug.
298 static inline u32 fsl_qspi_endian_xchg(struct fsl_qspi *q, u32 a)
300 return needs_swap_endian(q) ? __swab32(a) : a;
304 * R/W functions for big- or little-endian registers:
305 * The QSPI controller's endianness is independent of
306 * the CPU core's endianness. So far, although the CPU
307 * core is little-endian the QSPI controller can use
308 * big-endian or little-endian.
310 static void qspi_writel(struct fsl_qspi *q, u32 val, void __iomem *addr)
312 if (q->devtype_data->little_endian)
318 static u32 qspi_readl(struct fsl_qspi *q, void __iomem *addr)
320 if (q->devtype_data->little_endian)
321 return in_le32(addr);
323 return in_be32(addr);
326 static int fsl_qspi_check_buswidth(struct fsl_qspi *q, u8 width)
338 static bool fsl_qspi_supports_op(struct spi_slave *slave,
339 const struct spi_mem_op *op)
341 struct fsl_qspi *q = dev_get_priv(slave->dev->parent);
344 ret = fsl_qspi_check_buswidth(q, op->cmd.buswidth);
347 ret |= fsl_qspi_check_buswidth(q, op->addr.buswidth);
349 if (op->dummy.nbytes)
350 ret |= fsl_qspi_check_buswidth(q, op->dummy.buswidth);
353 ret |= fsl_qspi_check_buswidth(q, op->data.buswidth);
359 * The number of instructions needed for the op, needs
360 * to fit into a single LUT entry.
362 if (op->addr.nbytes +
363 (op->dummy.nbytes ? 1 : 0) +
364 (op->data.nbytes ? 1 : 0) > 6)
367 /* Max 64 dummy clock cycles supported */
368 if (op->dummy.nbytes &&
369 (op->dummy.nbytes * 8 / op->dummy.buswidth > 64))
372 /* Max data length, check controller limits and alignment */
373 if (op->data.dir == SPI_MEM_DATA_IN &&
374 (op->data.nbytes > q->devtype_data->ahb_buf_size ||
375 (op->data.nbytes > q->devtype_data->rxfifo - 4 &&
376 !IS_ALIGNED(op->data.nbytes, 8))))
379 if (op->data.dir == SPI_MEM_DATA_OUT &&
380 op->data.nbytes > q->devtype_data->txfifo)
386 static void fsl_qspi_prepare_lut(struct fsl_qspi *q,
387 const struct spi_mem_op *op)
389 void __iomem *base = q->iobase;
393 lutval[0] |= LUT_DEF(0, LUT_CMD, LUT_PAD(op->cmd.buswidth),
397 * For some unknown reason, using LUT_ADDR doesn't work in some
398 * cases (at least with only one byte long addresses), so
399 * let's use LUT_MODE to write the address bytes one by one
401 for (i = 0; i < op->addr.nbytes; i++) {
402 u8 addrbyte = op->addr.val >> (8 * (op->addr.nbytes - i - 1));
404 lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_MODE,
405 LUT_PAD(op->addr.buswidth),
410 if (op->dummy.nbytes) {
411 lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_DUMMY,
412 LUT_PAD(op->dummy.buswidth),
413 op->dummy.nbytes * 8 /
418 if (op->data.nbytes) {
419 lutval[lutidx / 2] |= LUT_DEF(lutidx,
420 op->data.dir == SPI_MEM_DATA_IN ?
421 LUT_FSL_READ : LUT_FSL_WRITE,
422 LUT_PAD(op->data.buswidth),
427 lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_STOP, 0, 0);
430 qspi_writel(q, QUADSPI_LUTKEY_VALUE, q->iobase + QUADSPI_LUTKEY);
431 qspi_writel(q, QUADSPI_LCKER_UNLOCK, q->iobase + QUADSPI_LCKCR);
433 dev_dbg(q->dev, "CMD[%x] lutval[0:%x \t 1:%x \t 2:%x \t 3:%x]\n",
434 op->cmd.opcode, lutval[0], lutval[1], lutval[2], lutval[3]);
437 for (i = 0; i < ARRAY_SIZE(lutval); i++)
438 qspi_writel(q, lutval[i], base + QUADSPI_LUT_REG(i));
441 qspi_writel(q, QUADSPI_LUTKEY_VALUE, q->iobase + QUADSPI_LUTKEY);
442 qspi_writel(q, QUADSPI_LCKER_LOCK, q->iobase + QUADSPI_LCKCR);
446 * If we have changed the content of the flash by writing or erasing, or if we
447 * read from flash with a different offset into the page buffer, we need to
448 * invalidate the AHB buffer. If we do not do so, we may read out the wrong
449 * data. The spec tells us reset the AHB domain and Serial Flash domain at
452 static void fsl_qspi_invalidate(struct fsl_qspi *q)
456 reg = qspi_readl(q, q->iobase + QUADSPI_MCR);
457 reg |= QUADSPI_MCR_SWRSTHD_MASK | QUADSPI_MCR_SWRSTSD_MASK;
458 qspi_writel(q, reg, q->iobase + QUADSPI_MCR);
461 * The minimum delay : 1 AHB + 2 SFCK clocks.
462 * Delay 1 us is enough.
466 reg &= ~(QUADSPI_MCR_SWRSTHD_MASK | QUADSPI_MCR_SWRSTSD_MASK);
467 qspi_writel(q, reg, q->iobase + QUADSPI_MCR);
470 static void fsl_qspi_select_mem(struct fsl_qspi *q, struct spi_slave *slave)
472 struct dm_spi_slave_platdata *plat =
473 dev_get_parent_platdata(slave->dev);
475 if (q->selected == plat->cs)
478 q->selected = plat->cs;
479 fsl_qspi_invalidate(q);
482 static void fsl_qspi_read_ahb(struct fsl_qspi *q, const struct spi_mem_op *op)
484 memcpy_fromio(op->data.buf.in,
485 q->ahb_addr + q->selected * q->devtype_data->ahb_buf_size,
489 static void fsl_qspi_fill_txfifo(struct fsl_qspi *q,
490 const struct spi_mem_op *op)
492 void __iomem *base = q->iobase;
496 for (i = 0; i < ALIGN_DOWN(op->data.nbytes, 4); i += 4) {
497 memcpy(&val, op->data.buf.out + i, 4);
498 val = fsl_qspi_endian_xchg(q, val);
499 qspi_writel(q, val, base + QUADSPI_TBDR);
502 if (i < op->data.nbytes) {
503 memcpy(&val, op->data.buf.out + i, op->data.nbytes - i);
504 val = fsl_qspi_endian_xchg(q, val);
505 qspi_writel(q, val, base + QUADSPI_TBDR);
508 if (needs_fill_txfifo(q)) {
509 for (i = op->data.nbytes; i < 16; i += 4)
510 qspi_writel(q, 0, base + QUADSPI_TBDR);
514 static void fsl_qspi_read_rxfifo(struct fsl_qspi *q,
515 const struct spi_mem_op *op)
517 void __iomem *base = q->iobase;
519 u8 *buf = op->data.buf.in;
522 for (i = 0; i < ALIGN_DOWN(op->data.nbytes, 4); i += 4) {
523 val = qspi_readl(q, base + QUADSPI_RBDR(i / 4));
524 val = fsl_qspi_endian_xchg(q, val);
525 memcpy(buf + i, &val, 4);
528 if (i < op->data.nbytes) {
529 val = qspi_readl(q, base + QUADSPI_RBDR(i / 4));
530 val = fsl_qspi_endian_xchg(q, val);
531 memcpy(buf + i, &val, op->data.nbytes - i);
535 static int fsl_qspi_readl_poll_tout(struct fsl_qspi *q, void __iomem *base,
536 u32 mask, u32 delay_us, u32 timeout_us)
540 if (!q->devtype_data->little_endian)
541 mask = (u32)cpu_to_be32(mask);
543 return readl_poll_timeout(base, reg, !(reg & mask), timeout_us);
546 static int fsl_qspi_do_op(struct fsl_qspi *q, const struct spi_mem_op *op)
548 void __iomem *base = q->iobase;
552 * Always start the sequence at the same index since we update
553 * the LUT at each exec_op() call. And also specify the DATA
554 * length, since it's has not been specified in the LUT.
556 qspi_writel(q, op->data.nbytes | QUADSPI_IPCR_SEQID(SEQID_LUT),
557 base + QUADSPI_IPCR);
559 /* wait for the controller being ready */
560 err = fsl_qspi_readl_poll_tout(q, base + QUADSPI_SR,
561 (QUADSPI_SR_IP_ACC_MASK |
562 QUADSPI_SR_AHB_ACC_MASK),
565 if (!err && op->data.nbytes && op->data.dir == SPI_MEM_DATA_IN)
566 fsl_qspi_read_rxfifo(q, op);
571 static int fsl_qspi_exec_op(struct spi_slave *slave,
572 const struct spi_mem_op *op)
574 struct fsl_qspi *q = dev_get_priv(slave->dev->parent);
575 void __iomem *base = q->iobase;
579 /* wait for the controller being ready */
580 fsl_qspi_readl_poll_tout(q, base + QUADSPI_SR, (QUADSPI_SR_IP_ACC_MASK |
581 QUADSPI_SR_AHB_ACC_MASK), 10, 1000);
583 fsl_qspi_select_mem(q, slave);
585 if (needs_amba_base_offset(q))
586 addr_offset = q->memmap_phy;
589 q->selected * q->devtype_data->ahb_buf_size + addr_offset,
590 base + QUADSPI_SFAR);
592 qspi_writel(q, qspi_readl(q, base + QUADSPI_MCR) |
593 QUADSPI_MCR_CLR_RXF_MASK | QUADSPI_MCR_CLR_TXF_MASK,
596 qspi_writel(q, QUADSPI_SPTRCLR_BFPTRC | QUADSPI_SPTRCLR_IPPTRC,
597 base + QUADSPI_SPTRCLR);
599 fsl_qspi_prepare_lut(q, op);
602 * If we have large chunks of data, we read them through the AHB bus
603 * by accessing the mapped memory. In all other cases we use
604 * IP commands to access the flash.
606 if (op->data.nbytes > (q->devtype_data->rxfifo - 4) &&
607 op->data.dir == SPI_MEM_DATA_IN) {
608 fsl_qspi_read_ahb(q, op);
610 qspi_writel(q, QUADSPI_RBCT_WMRK_MASK |
611 QUADSPI_RBCT_RXBRD_USEIPS, base + QUADSPI_RBCT);
613 if (op->data.nbytes && op->data.dir == SPI_MEM_DATA_OUT)
614 fsl_qspi_fill_txfifo(q, op);
616 err = fsl_qspi_do_op(q, op);
619 /* Invalidate the data in the AHB buffer. */
620 fsl_qspi_invalidate(q);
625 static int fsl_qspi_adjust_op_size(struct spi_slave *slave,
626 struct spi_mem_op *op)
628 struct fsl_qspi *q = dev_get_priv(slave->dev->parent);
630 if (op->data.dir == SPI_MEM_DATA_OUT) {
631 if (op->data.nbytes > q->devtype_data->txfifo)
632 op->data.nbytes = q->devtype_data->txfifo;
634 if (op->data.nbytes > q->devtype_data->ahb_buf_size)
635 op->data.nbytes = q->devtype_data->ahb_buf_size;
636 else if (op->data.nbytes > (q->devtype_data->rxfifo - 4))
637 op->data.nbytes = ALIGN_DOWN(op->data.nbytes, 8);
643 static int fsl_qspi_default_setup(struct fsl_qspi *q)
645 void __iomem *base = q->iobase;
646 u32 reg, addr_offset = 0;
648 /* Reset the module */
649 qspi_writel(q, QUADSPI_MCR_SWRSTSD_MASK | QUADSPI_MCR_SWRSTHD_MASK,
653 /* Disable the module */
654 qspi_writel(q, QUADSPI_MCR_MDIS_MASK | QUADSPI_MCR_RESERVED_MASK,
658 * Previous boot stages (BootROM, bootloader) might have used DDR
659 * mode and did not clear the TDH bits. As we currently use SDR mode
660 * only, clear the TDH bits if necessary.
662 if (needs_tdh_setting(q))
663 qspi_writel(q, qspi_readl(q, base + QUADSPI_FLSHCR) &
664 ~QUADSPI_FLSHCR_TDH_MASK,
665 base + QUADSPI_FLSHCR);
667 reg = qspi_readl(q, base + QUADSPI_SMPR);
668 qspi_writel(q, reg & ~(QUADSPI_SMPR_FSDLY_MASK
669 | QUADSPI_SMPR_FSPHS_MASK
670 | QUADSPI_SMPR_HSENA_MASK
671 | QUADSPI_SMPR_DDRSMP_MASK), base + QUADSPI_SMPR);
673 /* We only use the buffer3 for AHB read */
674 qspi_writel(q, 0, base + QUADSPI_BUF0IND);
675 qspi_writel(q, 0, base + QUADSPI_BUF1IND);
676 qspi_writel(q, 0, base + QUADSPI_BUF2IND);
678 qspi_writel(q, QUADSPI_BFGENCR_SEQID(SEQID_LUT),
679 q->iobase + QUADSPI_BFGENCR);
680 qspi_writel(q, QUADSPI_RBCT_WMRK_MASK, base + QUADSPI_RBCT);
681 qspi_writel(q, QUADSPI_BUF3CR_ALLMST_MASK |
682 QUADSPI_BUF3CR_ADATSZ(q->devtype_data->ahb_buf_size / 8),
683 base + QUADSPI_BUF3CR);
685 if (needs_amba_base_offset(q))
686 addr_offset = q->memmap_phy;
689 * In HW there can be a maximum of four chips on two buses with
690 * two chip selects on each bus. We use four chip selects in SW
691 * to differentiate between the four chips.
692 * We use ahb_buf_size for each chip and set SFA1AD, SFA2AD, SFB1AD,
693 * SFB2AD accordingly.
695 qspi_writel(q, q->devtype_data->ahb_buf_size + addr_offset,
696 base + QUADSPI_SFA1AD);
697 qspi_writel(q, q->devtype_data->ahb_buf_size * 2 + addr_offset,
698 base + QUADSPI_SFA2AD);
699 qspi_writel(q, q->devtype_data->ahb_buf_size * 3 + addr_offset,
700 base + QUADSPI_SFB1AD);
701 qspi_writel(q, q->devtype_data->ahb_buf_size * 4 + addr_offset,
702 base + QUADSPI_SFB2AD);
706 /* Enable the module */
707 qspi_writel(q, QUADSPI_MCR_RESERVED_MASK | QUADSPI_MCR_END_CFG_MASK,
712 static const struct spi_controller_mem_ops fsl_qspi_mem_ops = {
713 .adjust_op_size = fsl_qspi_adjust_op_size,
714 .supports_op = fsl_qspi_supports_op,
715 .exec_op = fsl_qspi_exec_op,
718 static int fsl_qspi_probe(struct udevice *bus)
720 struct dm_spi_bus *dm_bus = bus->uclass_priv;
721 struct fsl_qspi *q = dev_get_priv(bus);
722 const void *blob = gd->fdt_blob;
723 int node = dev_of_offset(bus);
724 struct fdt_resource res;
728 q->devtype_data = (struct fsl_qspi_devtype_data *)
729 dev_get_driver_data(bus);
731 /* find the resources */
732 ret = fdt_get_named_resource(blob, node, "reg", "reg-names", "QuadSPI",
735 dev_err(bus, "Can't get regs base addresses(ret = %d)!\n", ret);
739 q->iobase = map_physmem(res.start, res.end - res.start, MAP_NOCACHE);
741 ret = fdt_get_named_resource(blob, node, "reg", "reg-names",
742 "QuadSPI-memory", &res);
744 dev_err(bus, "Can't get AMBA base addresses(ret = %d)!\n", ret);
748 q->ahb_addr = map_physmem(res.start, res.end - res.start, MAP_NOCACHE);
749 q->memmap_phy = res.start;
751 dm_bus->max_hz = fdtdec_get_int(blob, node, "spi-max-frequency",
754 fsl_qspi_default_setup(q);
759 static int fsl_qspi_xfer(struct udevice *dev, unsigned int bitlen,
760 const void *dout, void *din, unsigned long flags)
765 static int fsl_qspi_claim_bus(struct udevice *dev)
770 static int fsl_qspi_release_bus(struct udevice *dev)
775 static int fsl_qspi_set_speed(struct udevice *bus, uint speed)
780 static int fsl_qspi_set_mode(struct udevice *bus, uint mode)
785 static const struct dm_spi_ops fsl_qspi_ops = {
786 .claim_bus = fsl_qspi_claim_bus,
787 .release_bus = fsl_qspi_release_bus,
788 .xfer = fsl_qspi_xfer,
789 .set_speed = fsl_qspi_set_speed,
790 .set_mode = fsl_qspi_set_mode,
791 .mem_ops = &fsl_qspi_mem_ops,
794 static const struct udevice_id fsl_qspi_ids[] = {
795 { .compatible = "fsl,vf610-qspi", .data = (ulong)&vybrid_data, },
796 { .compatible = "fsl,imx6sx-qspi", .data = (ulong)&imx6sx_data, },
797 { .compatible = "fsl,imx6ul-qspi", .data = (ulong)&imx6ul_data, },
798 { .compatible = "fsl,imx7d-qspi", .data = (ulong)&imx7d_data, },
799 { .compatible = "fsl,ls1021a-qspi", .data = (ulong)&ls1021a_data, },
800 { .compatible = "fsl,ls1088a-qspi", .data = (ulong)&ls1088a_data, },
801 { .compatible = "fsl,ls2080a-qspi", .data = (ulong)&ls2080a_data, },
805 U_BOOT_DRIVER(fsl_qspi) = {
808 .of_match = fsl_qspi_ids,
809 .ops = &fsl_qspi_ops,
810 .priv_auto_alloc_size = sizeof(struct fsl_qspi),
811 .probe = fsl_qspi_probe,