Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 2 | |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 3 | /* |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 4 | * Freescale QuadSPI driver. |
| 5 | * |
| 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 |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 11 | * |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 12 | * This driver is a ported version of Linux Freescale QSPI driver taken from |
| 13 | * v5.5-rc1 tag having following information. |
| 14 | * |
| 15 | * Transition to SPI MEM interface: |
| 16 | * Authors: |
| 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> |
| 21 | * |
| 22 | * Based on the original fsl-quadspi.c spi-nor driver. |
| 23 | * Transition to spi-mem in spi-fsl-qspi.c |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 24 | */ |
| 25 | |
| 26 | #include <common.h> |
Sean Anderson | a89b943 | 2020-10-04 21:39:50 -0400 | [diff] [blame] | 27 | #include <dm.h> |
| 28 | #include <dm/device_compat.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 29 | #include <log.h> |
Sean Anderson | a89b943 | 2020-10-04 21:39:50 -0400 | [diff] [blame] | 30 | #include <spi.h> |
| 31 | #include <spi-mem.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 32 | #include <linux/bitops.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 33 | #include <linux/delay.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 34 | #include <linux/libfdt.h> |
| 35 | #include <linux/sizes.h> |
| 36 | #include <linux/iopoll.h> |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 37 | #include <linux/iopoll.h> |
| 38 | #include <linux/sizes.h> |
| 39 | #include <linux/err.h> |
Sean Anderson | a89b943 | 2020-10-04 21:39:50 -0400 | [diff] [blame] | 40 | #include <asm/io.h> |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 41 | |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 42 | DECLARE_GLOBAL_DATA_PTR; |
| 43 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 44 | /* |
| 45 | * The driver only uses one single LUT entry, that is updated on |
| 46 | * each call of exec_op(). Index 0 is preset at boot with a basic |
| 47 | * read operation, so let's use the last entry (15). |
| 48 | */ |
| 49 | #define SEQID_LUT 15 |
Ye Li | d7e3c9a | 2020-06-09 00:59:06 -0700 | [diff] [blame] | 50 | #define SEQID_LUT_AHB 14 |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 51 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 52 | /* Registers used by the driver */ |
| 53 | #define QUADSPI_MCR 0x00 |
| 54 | #define QUADSPI_MCR_RESERVED_MASK GENMASK(19, 16) |
| 55 | #define QUADSPI_MCR_MDIS_MASK BIT(14) |
| 56 | #define QUADSPI_MCR_CLR_TXF_MASK BIT(11) |
| 57 | #define QUADSPI_MCR_CLR_RXF_MASK BIT(10) |
| 58 | #define QUADSPI_MCR_DDR_EN_MASK BIT(7) |
| 59 | #define QUADSPI_MCR_END_CFG_MASK GENMASK(3, 2) |
| 60 | #define QUADSPI_MCR_SWRSTHD_MASK BIT(1) |
| 61 | #define QUADSPI_MCR_SWRSTSD_MASK BIT(0) |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 62 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 63 | #define QUADSPI_IPCR 0x08 |
| 64 | #define QUADSPI_IPCR_SEQID(x) ((x) << 24) |
| 65 | #define QUADSPI_FLSHCR 0x0c |
| 66 | #define QUADSPI_FLSHCR_TCSS_MASK GENMASK(3, 0) |
| 67 | #define QUADSPI_FLSHCR_TCSH_MASK GENMASK(11, 8) |
| 68 | #define QUADSPI_FLSHCR_TDH_MASK GENMASK(17, 16) |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 69 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 70 | #define QUADSPI_BUF3CR 0x1c |
| 71 | #define QUADSPI_BUF3CR_ALLMST_MASK BIT(31) |
| 72 | #define QUADSPI_BUF3CR_ADATSZ(x) ((x) << 8) |
| 73 | #define QUADSPI_BUF3CR_ADATSZ_MASK GENMASK(15, 8) |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 74 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 75 | #define QUADSPI_BFGENCR 0x20 |
| 76 | #define QUADSPI_BFGENCR_SEQID(x) ((x) << 12) |
Peng Fan | 3a34448 | 2015-01-04 17:07:14 +0800 | [diff] [blame] | 77 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 78 | #define QUADSPI_BUF0IND 0x30 |
| 79 | #define QUADSPI_BUF1IND 0x34 |
| 80 | #define QUADSPI_BUF2IND 0x38 |
| 81 | #define QUADSPI_SFAR 0x100 |
Peng Fan | 3a34448 | 2015-01-04 17:07:14 +0800 | [diff] [blame] | 82 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 83 | #define QUADSPI_SMPR 0x108 |
| 84 | #define QUADSPI_SMPR_DDRSMP_MASK GENMASK(18, 16) |
| 85 | #define QUADSPI_SMPR_FSDLY_MASK BIT(6) |
| 86 | #define QUADSPI_SMPR_FSPHS_MASK BIT(5) |
| 87 | #define QUADSPI_SMPR_HSENA_MASK BIT(0) |
Yuan Yao | d719326 | 2016-03-15 14:36:42 +0800 | [diff] [blame] | 88 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 89 | #define QUADSPI_RBCT 0x110 |
| 90 | #define QUADSPI_RBCT_WMRK_MASK GENMASK(4, 0) |
| 91 | #define QUADSPI_RBCT_RXBRD_USEIPS BIT(8) |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 92 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 93 | #define QUADSPI_TBDR 0x154 |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 94 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 95 | #define QUADSPI_SR 0x15c |
| 96 | #define QUADSPI_SR_IP_ACC_MASK BIT(1) |
| 97 | #define QUADSPI_SR_AHB_ACC_MASK BIT(2) |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 98 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 99 | #define QUADSPI_FR 0x160 |
| 100 | #define QUADSPI_FR_TFF_MASK BIT(0) |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 101 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 102 | #define QUADSPI_RSER 0x164 |
| 103 | #define QUADSPI_RSER_TFIE BIT(0) |
Ye Li | 007b604 | 2019-08-14 11:31:36 +0000 | [diff] [blame] | 104 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 105 | #define QUADSPI_SPTRCLR 0x16c |
| 106 | #define QUADSPI_SPTRCLR_IPPTRC BIT(8) |
| 107 | #define QUADSPI_SPTRCLR_BFPTRC BIT(0) |
Ye Li | 007b604 | 2019-08-14 11:31:36 +0000 | [diff] [blame] | 108 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 109 | #define QUADSPI_SFA1AD 0x180 |
| 110 | #define QUADSPI_SFA2AD 0x184 |
| 111 | #define QUADSPI_SFB1AD 0x188 |
| 112 | #define QUADSPI_SFB2AD 0x18c |
| 113 | #define QUADSPI_RBDR(x) (0x200 + ((x) * 4)) |
Ye Li | 007b604 | 2019-08-14 11:31:36 +0000 | [diff] [blame] | 114 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 115 | #define QUADSPI_LUTKEY 0x300 |
| 116 | #define QUADSPI_LUTKEY_VALUE 0x5AF05AF0 |
| 117 | |
| 118 | #define QUADSPI_LCKCR 0x304 |
| 119 | #define QUADSPI_LCKER_LOCK BIT(0) |
| 120 | #define QUADSPI_LCKER_UNLOCK BIT(1) |
| 121 | |
| 122 | #define QUADSPI_LUT_BASE 0x310 |
| 123 | #define QUADSPI_LUT_OFFSET (SEQID_LUT * 4 * 4) |
| 124 | #define QUADSPI_LUT_REG(idx) \ |
| 125 | (QUADSPI_LUT_BASE + QUADSPI_LUT_OFFSET + (idx) * 4) |
| 126 | |
Ye Li | d7e3c9a | 2020-06-09 00:59:06 -0700 | [diff] [blame] | 127 | #define QUADSPI_AHB_LUT_OFFSET (SEQID_LUT_AHB * 4 * 4) |
| 128 | #define QUADSPI_AHB_LUT_REG(idx) \ |
| 129 | (QUADSPI_LUT_BASE + QUADSPI_AHB_LUT_OFFSET + (idx) * 4) |
| 130 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 131 | /* Instruction set for the LUT register */ |
| 132 | #define LUT_STOP 0 |
| 133 | #define LUT_CMD 1 |
| 134 | #define LUT_ADDR 2 |
| 135 | #define LUT_DUMMY 3 |
| 136 | #define LUT_MODE 4 |
| 137 | #define LUT_MODE2 5 |
| 138 | #define LUT_MODE4 6 |
| 139 | #define LUT_FSL_READ 7 |
| 140 | #define LUT_FSL_WRITE 8 |
| 141 | #define LUT_JMP_ON_CS 9 |
| 142 | #define LUT_ADDR_DDR 10 |
| 143 | #define LUT_MODE_DDR 11 |
| 144 | #define LUT_MODE2_DDR 12 |
| 145 | #define LUT_MODE4_DDR 13 |
| 146 | #define LUT_FSL_READ_DDR 14 |
| 147 | #define LUT_FSL_WRITE_DDR 15 |
| 148 | #define LUT_DATA_LEARN 16 |
| 149 | |
| 150 | /* |
| 151 | * The PAD definitions for LUT register. |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 152 | * |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 153 | * The pad stands for the number of IO lines [0:3]. |
| 154 | * For example, the quad read needs four IO lines, |
| 155 | * so you should use LUT_PAD(4). |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 156 | */ |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 157 | #define LUT_PAD(x) (fls(x) - 1) |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 158 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 159 | /* |
| 160 | * Macro for constructing the LUT entries with the following |
| 161 | * register layout: |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 162 | * |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 163 | * --------------------------------------------------- |
| 164 | * | INSTR1 | PAD1 | OPRND1 | INSTR0 | PAD0 | OPRND0 | |
| 165 | * --------------------------------------------------- |
| 166 | */ |
| 167 | #define LUT_DEF(idx, ins, pad, opr) \ |
| 168 | ((((ins) << 10) | ((pad) << 8) | (opr)) << (((idx) % 2) * 16)) |
| 169 | |
| 170 | /* Controller needs driver to swap endianness */ |
| 171 | #define QUADSPI_QUIRK_SWAP_ENDIAN BIT(0) |
| 172 | |
| 173 | /* Controller needs 4x internal clock */ |
| 174 | #define QUADSPI_QUIRK_4X_INT_CLK BIT(1) |
| 175 | |
| 176 | /* |
| 177 | * TKT253890, the controller needs the driver to fill the txfifo with |
| 178 | * 16 bytes at least to trigger a data transfer, even though the extra |
| 179 | * data won't be transferred. |
| 180 | */ |
| 181 | #define QUADSPI_QUIRK_TKT253890 BIT(2) |
| 182 | |
| 183 | /* TKT245618, the controller cannot wake up from wait mode */ |
| 184 | #define QUADSPI_QUIRK_TKT245618 BIT(3) |
| 185 | |
| 186 | /* |
| 187 | * Controller adds QSPI_AMBA_BASE (base address of the mapped memory) |
| 188 | * internally. No need to add it when setting SFXXAD and SFAR registers |
| 189 | */ |
| 190 | #define QUADSPI_QUIRK_BASE_INTERNAL BIT(4) |
| 191 | |
| 192 | /* |
| 193 | * Controller uses TDH bits in register QUADSPI_FLSHCR. |
| 194 | * They need to be set in accordance with the DDR/SDR mode. |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 195 | */ |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 196 | #define QUADSPI_QUIRK_USE_TDH_SETTING BIT(5) |
| 197 | |
Ye Li | d7e3c9a | 2020-06-09 00:59:06 -0700 | [diff] [blame] | 198 | /* |
| 199 | * Controller only has Two CS on flash A, no flash B port |
| 200 | */ |
| 201 | #define QUADSPI_QUIRK_SINGLE_BUS BIT(6) |
| 202 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 203 | struct fsl_qspi_devtype_data { |
| 204 | unsigned int rxfifo; |
| 205 | unsigned int txfifo; |
| 206 | unsigned int ahb_buf_size; |
| 207 | unsigned int quirks; |
| 208 | bool little_endian; |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 209 | }; |
| 210 | |
Ye Li | 007b604 | 2019-08-14 11:31:36 +0000 | [diff] [blame] | 211 | static const struct fsl_qspi_devtype_data vybrid_data = { |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 212 | .rxfifo = SZ_128, |
| 213 | .txfifo = SZ_64, |
| 214 | .ahb_buf_size = SZ_1K, |
| 215 | .quirks = QUADSPI_QUIRK_SWAP_ENDIAN, |
| 216 | .little_endian = true, |
Ye Li | 007b604 | 2019-08-14 11:31:36 +0000 | [diff] [blame] | 217 | }; |
| 218 | |
| 219 | static const struct fsl_qspi_devtype_data imx6sx_data = { |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 220 | .rxfifo = SZ_128, |
| 221 | .txfifo = SZ_512, |
| 222 | .ahb_buf_size = SZ_1K, |
| 223 | .quirks = QUADSPI_QUIRK_4X_INT_CLK | QUADSPI_QUIRK_TKT245618, |
| 224 | .little_endian = true, |
Ye Li | 007b604 | 2019-08-14 11:31:36 +0000 | [diff] [blame] | 225 | }; |
| 226 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 227 | static const struct fsl_qspi_devtype_data imx7d_data = { |
| 228 | .rxfifo = SZ_128, |
| 229 | .txfifo = SZ_512, |
| 230 | .ahb_buf_size = SZ_1K, |
| 231 | .quirks = QUADSPI_QUIRK_TKT253890 | QUADSPI_QUIRK_4X_INT_CLK | |
| 232 | QUADSPI_QUIRK_USE_TDH_SETTING, |
| 233 | .little_endian = true, |
Ye Li | 007b604 | 2019-08-14 11:31:36 +0000 | [diff] [blame] | 234 | }; |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 235 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 236 | static const struct fsl_qspi_devtype_data imx6ul_data = { |
| 237 | .rxfifo = SZ_128, |
| 238 | .txfifo = SZ_512, |
| 239 | .ahb_buf_size = SZ_1K, |
| 240 | .quirks = QUADSPI_QUIRK_TKT253890 | QUADSPI_QUIRK_4X_INT_CLK | |
| 241 | QUADSPI_QUIRK_USE_TDH_SETTING, |
| 242 | .little_endian = true, |
Ye Li | 57f6775 | 2019-08-14 11:31:40 +0000 | [diff] [blame] | 243 | }; |
| 244 | |
Ye Li | e4d39a0 | 2020-06-09 00:59:05 -0700 | [diff] [blame] | 245 | static const struct fsl_qspi_devtype_data imx7ulp_data = { |
| 246 | .rxfifo = SZ_64, |
| 247 | .txfifo = SZ_64, |
| 248 | .ahb_buf_size = SZ_128, |
| 249 | .quirks = QUADSPI_QUIRK_TKT253890 | QUADSPI_QUIRK_4X_INT_CLK | |
Ye Li | d7e3c9a | 2020-06-09 00:59:06 -0700 | [diff] [blame] | 250 | QUADSPI_QUIRK_USE_TDH_SETTING | QUADSPI_QUIRK_SINGLE_BUS, |
Ye Li | e4d39a0 | 2020-06-09 00:59:05 -0700 | [diff] [blame] | 251 | .little_endian = true, |
| 252 | }; |
| 253 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 254 | static const struct fsl_qspi_devtype_data ls1021a_data = { |
| 255 | .rxfifo = SZ_128, |
| 256 | .txfifo = SZ_64, |
| 257 | .ahb_buf_size = SZ_1K, |
| 258 | .quirks = 0, |
| 259 | .little_endian = false, |
| 260 | }; |
| 261 | |
| 262 | static const struct fsl_qspi_devtype_data ls1088a_data = { |
| 263 | .rxfifo = SZ_128, |
| 264 | .txfifo = SZ_128, |
| 265 | .ahb_buf_size = SZ_1K, |
| 266 | .quirks = QUADSPI_QUIRK_TKT253890, |
| 267 | .little_endian = true, |
| 268 | }; |
| 269 | |
| 270 | static const struct fsl_qspi_devtype_data ls2080a_data = { |
| 271 | .rxfifo = SZ_128, |
| 272 | .txfifo = SZ_64, |
| 273 | .ahb_buf_size = SZ_1K, |
| 274 | .quirks = QUADSPI_QUIRK_TKT253890 | QUADSPI_QUIRK_BASE_INTERNAL, |
| 275 | .little_endian = true, |
| 276 | }; |
| 277 | |
| 278 | struct fsl_qspi { |
| 279 | struct udevice *dev; |
| 280 | void __iomem *iobase; |
| 281 | void __iomem *ahb_addr; |
| 282 | u32 memmap_phy; |
Ye Li | d7e3c9a | 2020-06-09 00:59:06 -0700 | [diff] [blame] | 283 | u32 memmap_size; |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 284 | const struct fsl_qspi_devtype_data *devtype_data; |
| 285 | int selected; |
| 286 | }; |
| 287 | |
| 288 | static inline int needs_swap_endian(struct fsl_qspi *q) |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 289 | { |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 290 | return q->devtype_data->quirks & QUADSPI_QUIRK_SWAP_ENDIAN; |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 291 | } |
| 292 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 293 | static inline int needs_4x_clock(struct fsl_qspi *q) |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 294 | { |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 295 | return q->devtype_data->quirks & QUADSPI_QUIRK_4X_INT_CLK; |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 296 | } |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 297 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 298 | static inline int needs_fill_txfifo(struct fsl_qspi *q) |
Rajat Srivastava | 234daec | 2018-03-22 13:30:55 +0530 | [diff] [blame] | 299 | { |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 300 | return q->devtype_data->quirks & QUADSPI_QUIRK_TKT253890; |
Rajat Srivastava | 234daec | 2018-03-22 13:30:55 +0530 | [diff] [blame] | 301 | } |
| 302 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 303 | static inline int needs_wakeup_wait_mode(struct fsl_qspi *q) |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 304 | { |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 305 | return q->devtype_data->quirks & QUADSPI_QUIRK_TKT245618; |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 306 | } |
| 307 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 308 | static inline int needs_amba_base_offset(struct fsl_qspi *q) |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 309 | { |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 310 | return !(q->devtype_data->quirks & QUADSPI_QUIRK_BASE_INTERNAL); |
| 311 | } |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 312 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 313 | static inline int needs_tdh_setting(struct fsl_qspi *q) |
| 314 | { |
| 315 | return q->devtype_data->quirks & QUADSPI_QUIRK_USE_TDH_SETTING; |
| 316 | } |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 317 | |
Ye Li | d7e3c9a | 2020-06-09 00:59:06 -0700 | [diff] [blame] | 318 | static inline int needs_single_bus(struct fsl_qspi *q) |
| 319 | { |
| 320 | return q->devtype_data->quirks & QUADSPI_QUIRK_SINGLE_BUS; |
| 321 | } |
| 322 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 323 | /* |
| 324 | * An IC bug makes it necessary to rearrange the 32-bit data. |
| 325 | * Later chips, such as IMX6SLX, have fixed this bug. |
| 326 | */ |
| 327 | static inline u32 fsl_qspi_endian_xchg(struct fsl_qspi *q, u32 a) |
| 328 | { |
| 329 | return needs_swap_endian(q) ? __swab32(a) : a; |
| 330 | } |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 331 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 332 | /* |
| 333 | * R/W functions for big- or little-endian registers: |
| 334 | * The QSPI controller's endianness is independent of |
| 335 | * the CPU core's endianness. So far, although the CPU |
| 336 | * core is little-endian the QSPI controller can use |
| 337 | * big-endian or little-endian. |
| 338 | */ |
| 339 | static void qspi_writel(struct fsl_qspi *q, u32 val, void __iomem *addr) |
| 340 | { |
| 341 | if (q->devtype_data->little_endian) |
| 342 | out_le32(addr, val); |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 343 | else |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 344 | out_be32(addr, val); |
| 345 | } |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 346 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 347 | static u32 qspi_readl(struct fsl_qspi *q, void __iomem *addr) |
| 348 | { |
| 349 | if (q->devtype_data->little_endian) |
| 350 | return in_le32(addr); |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 351 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 352 | return in_be32(addr); |
| 353 | } |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 354 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 355 | static int fsl_qspi_check_buswidth(struct fsl_qspi *q, u8 width) |
| 356 | { |
| 357 | switch (width) { |
| 358 | case 1: |
| 359 | case 2: |
| 360 | case 4: |
| 361 | return 0; |
| 362 | } |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 363 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 364 | return -ENOTSUPP; |
| 365 | } |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 366 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 367 | static bool fsl_qspi_supports_op(struct spi_slave *slave, |
| 368 | const struct spi_mem_op *op) |
| 369 | { |
| 370 | struct fsl_qspi *q = dev_get_priv(slave->dev->parent); |
| 371 | int ret; |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 372 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 373 | ret = fsl_qspi_check_buswidth(q, op->cmd.buswidth); |
Peng Fan | 3642a87 | 2014-12-31 11:01:39 +0800 | [diff] [blame] | 374 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 375 | if (op->addr.nbytes) |
| 376 | ret |= fsl_qspi_check_buswidth(q, op->addr.buswidth); |
Peng Fan | 3a34448 | 2015-01-04 17:07:14 +0800 | [diff] [blame] | 377 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 378 | if (op->dummy.nbytes) |
| 379 | ret |= fsl_qspi_check_buswidth(q, op->dummy.buswidth); |
Peng Fan | 3a34448 | 2015-01-04 17:07:14 +0800 | [diff] [blame] | 380 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 381 | if (op->data.nbytes) |
| 382 | ret |= fsl_qspi_check_buswidth(q, op->data.buswidth); |
Peng Fan | 3a34448 | 2015-01-04 17:07:14 +0800 | [diff] [blame] | 383 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 384 | if (ret) |
| 385 | return false; |
Yuan Yao | d719326 | 2016-03-15 14:36:42 +0800 | [diff] [blame] | 386 | |
| 387 | /* |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 388 | * The number of instructions needed for the op, needs |
| 389 | * to fit into a single LUT entry. |
Yuan Yao | d719326 | 2016-03-15 14:36:42 +0800 | [diff] [blame] | 390 | */ |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 391 | if (op->addr.nbytes + |
| 392 | (op->dummy.nbytes ? 1 : 0) + |
| 393 | (op->data.nbytes ? 1 : 0) > 6) |
| 394 | return false; |
Yuan Yao | d719326 | 2016-03-15 14:36:42 +0800 | [diff] [blame] | 395 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 396 | /* Max 64 dummy clock cycles supported */ |
| 397 | if (op->dummy.nbytes && |
| 398 | (op->dummy.nbytes * 8 / op->dummy.buswidth > 64)) |
| 399 | return false; |
Yuan Yao | d719326 | 2016-03-15 14:36:42 +0800 | [diff] [blame] | 400 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 401 | /* Max data length, check controller limits and alignment */ |
| 402 | if (op->data.dir == SPI_MEM_DATA_IN && |
| 403 | (op->data.nbytes > q->devtype_data->ahb_buf_size || |
| 404 | (op->data.nbytes > q->devtype_data->rxfifo - 4 && |
| 405 | !IS_ALIGNED(op->data.nbytes, 8)))) |
| 406 | return false; |
| 407 | |
| 408 | if (op->data.dir == SPI_MEM_DATA_OUT && |
| 409 | op->data.nbytes > q->devtype_data->txfifo) |
| 410 | return false; |
| 411 | |
| 412 | return true; |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 413 | } |
| 414 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 415 | static void fsl_qspi_prepare_lut(struct fsl_qspi *q, |
| 416 | const struct spi_mem_op *op) |
Peng Fan | 1c5f966 | 2015-01-08 10:40:20 +0800 | [diff] [blame] | 417 | { |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 418 | void __iomem *base = q->iobase; |
| 419 | u32 lutval[4] = {}; |
| 420 | int lutidx = 1, i; |
Peng Fan | 1c5f966 | 2015-01-08 10:40:20 +0800 | [diff] [blame] | 421 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 422 | lutval[0] |= LUT_DEF(0, LUT_CMD, LUT_PAD(op->cmd.buswidth), |
| 423 | op->cmd.opcode); |
Peng Fan | 1c5f966 | 2015-01-08 10:40:20 +0800 | [diff] [blame] | 424 | |
Ye Li | d7e3c9a | 2020-06-09 00:59:06 -0700 | [diff] [blame] | 425 | if (IS_ENABLED(CONFIG_FSL_QSPI_AHB_FULL_MAP)) { |
| 426 | if (op->addr.nbytes) { |
| 427 | lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_ADDR, |
| 428 | LUT_PAD(op->addr.buswidth), |
| 429 | (op->addr.nbytes == 4) ? 0x20 : 0x18); |
| 430 | lutidx++; |
| 431 | } |
| 432 | } else { |
| 433 | /* |
| 434 | * For some unknown reason, using LUT_ADDR doesn't work in some |
| 435 | * cases (at least with only one byte long addresses), so |
| 436 | * let's use LUT_MODE to write the address bytes one by one |
| 437 | */ |
| 438 | for (i = 0; i < op->addr.nbytes; i++) { |
| 439 | u8 addrbyte = op->addr.val >> (8 * (op->addr.nbytes - i - 1)); |
Peng Fan | 1c5f966 | 2015-01-08 10:40:20 +0800 | [diff] [blame] | 440 | |
Ye Li | d7e3c9a | 2020-06-09 00:59:06 -0700 | [diff] [blame] | 441 | lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_MODE, |
| 442 | LUT_PAD(op->addr.buswidth), |
| 443 | addrbyte); |
| 444 | lutidx++; |
| 445 | } |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 446 | } |
Peng Fan | 1c5f966 | 2015-01-08 10:40:20 +0800 | [diff] [blame] | 447 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 448 | if (op->dummy.nbytes) { |
| 449 | lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_DUMMY, |
| 450 | LUT_PAD(op->dummy.buswidth), |
| 451 | op->dummy.nbytes * 8 / |
| 452 | op->dummy.buswidth); |
| 453 | lutidx++; |
| 454 | } |
Peng Fan | 1c5f966 | 2015-01-08 10:40:20 +0800 | [diff] [blame] | 455 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 456 | if (op->data.nbytes) { |
| 457 | lutval[lutidx / 2] |= LUT_DEF(lutidx, |
| 458 | op->data.dir == SPI_MEM_DATA_IN ? |
| 459 | LUT_FSL_READ : LUT_FSL_WRITE, |
| 460 | LUT_PAD(op->data.buswidth), |
| 461 | 0); |
| 462 | lutidx++; |
| 463 | } |
Peng Fan | 1c5f966 | 2015-01-08 10:40:20 +0800 | [diff] [blame] | 464 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 465 | lutval[lutidx / 2] |= LUT_DEF(lutidx, LUT_STOP, 0, 0); |
Peng Fan | 1c5f966 | 2015-01-08 10:40:20 +0800 | [diff] [blame] | 466 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 467 | /* unlock LUT */ |
| 468 | qspi_writel(q, QUADSPI_LUTKEY_VALUE, q->iobase + QUADSPI_LUTKEY); |
| 469 | qspi_writel(q, QUADSPI_LCKER_UNLOCK, q->iobase + QUADSPI_LCKCR); |
Peng Fan | 1c5f966 | 2015-01-08 10:40:20 +0800 | [diff] [blame] | 470 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 471 | dev_dbg(q->dev, "CMD[%x] lutval[0:%x \t 1:%x \t 2:%x \t 3:%x]\n", |
| 472 | op->cmd.opcode, lutval[0], lutval[1], lutval[2], lutval[3]); |
Peng Fan | 1c5f966 | 2015-01-08 10:40:20 +0800 | [diff] [blame] | 473 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 474 | /* fill LUT */ |
| 475 | for (i = 0; i < ARRAY_SIZE(lutval); i++) |
| 476 | qspi_writel(q, lutval[i], base + QUADSPI_LUT_REG(i)); |
Ye Li | 416d2ec | 2019-08-14 11:31:27 +0000 | [diff] [blame] | 477 | |
Ye Li | d7e3c9a | 2020-06-09 00:59:06 -0700 | [diff] [blame] | 478 | if (IS_ENABLED(CONFIG_FSL_QSPI_AHB_FULL_MAP)) { |
| 479 | if (op->data.nbytes && op->data.dir == SPI_MEM_DATA_IN && |
| 480 | op->addr.nbytes) { |
| 481 | for (i = 0; i < ARRAY_SIZE(lutval); i++) |
| 482 | qspi_writel(q, lutval[i], base + QUADSPI_AHB_LUT_REG(i)); |
| 483 | } |
| 484 | } |
| 485 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 486 | /* lock LUT */ |
| 487 | qspi_writel(q, QUADSPI_LUTKEY_VALUE, q->iobase + QUADSPI_LUTKEY); |
| 488 | qspi_writel(q, QUADSPI_LCKER_LOCK, q->iobase + QUADSPI_LCKCR); |
Peng Fan | 1c5f966 | 2015-01-08 10:40:20 +0800 | [diff] [blame] | 489 | } |
| 490 | |
| 491 | /* |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 492 | * If we have changed the content of the flash by writing or erasing, or if we |
| 493 | * read from flash with a different offset into the page buffer, we need to |
| 494 | * invalidate the AHB buffer. If we do not do so, we may read out the wrong |
| 495 | * data. The spec tells us reset the AHB domain and Serial Flash domain at |
| 496 | * the same time. |
Peng Fan | 1c5f966 | 2015-01-08 10:40:20 +0800 | [diff] [blame] | 497 | */ |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 498 | static void fsl_qspi_invalidate(struct fsl_qspi *q) |
Peng Fan | 1c5f966 | 2015-01-08 10:40:20 +0800 | [diff] [blame] | 499 | { |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 500 | u32 reg; |
Peng Fan | 1c5f966 | 2015-01-08 10:40:20 +0800 | [diff] [blame] | 501 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 502 | reg = qspi_readl(q, q->iobase + QUADSPI_MCR); |
| 503 | reg |= QUADSPI_MCR_SWRSTHD_MASK | QUADSPI_MCR_SWRSTSD_MASK; |
| 504 | qspi_writel(q, reg, q->iobase + QUADSPI_MCR); |
Peng Fan | 1c5f966 | 2015-01-08 10:40:20 +0800 | [diff] [blame] | 505 | |
| 506 | /* |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 507 | * The minimum delay : 1 AHB + 2 SFCK clocks. |
| 508 | * Delay 1 us is enough. |
Peng Fan | 1c5f966 | 2015-01-08 10:40:20 +0800 | [diff] [blame] | 509 | */ |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 510 | udelay(1); |
Peng Fan | 1c5f966 | 2015-01-08 10:40:20 +0800 | [diff] [blame] | 511 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 512 | reg &= ~(QUADSPI_MCR_SWRSTHD_MASK | QUADSPI_MCR_SWRSTSD_MASK); |
| 513 | qspi_writel(q, reg, q->iobase + QUADSPI_MCR); |
Peng Fan | 1c5f966 | 2015-01-08 10:40:20 +0800 | [diff] [blame] | 514 | } |
Peng Fan | 1c5f966 | 2015-01-08 10:40:20 +0800 | [diff] [blame] | 515 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 516 | static void fsl_qspi_select_mem(struct fsl_qspi *q, struct spi_slave *slave) |
Peng Fan | 3a34448 | 2015-01-04 17:07:14 +0800 | [diff] [blame] | 517 | { |
Simon Glass | b75b15b | 2020-12-03 16:55:23 -0700 | [diff] [blame] | 518 | struct dm_spi_slave_plat *plat = |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 519 | dev_get_parent_plat(slave->dev); |
Peng Fan | 3a34448 | 2015-01-04 17:07:14 +0800 | [diff] [blame] | 520 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 521 | if (q->selected == plat->cs) |
| 522 | return; |
Alexander Stein | 283eb4a | 2017-06-01 09:32:19 +0200 | [diff] [blame] | 523 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 524 | q->selected = plat->cs; |
| 525 | fsl_qspi_invalidate(q); |
Peng Fan | 3a34448 | 2015-01-04 17:07:14 +0800 | [diff] [blame] | 526 | } |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 527 | |
Ye Li | d7e3c9a | 2020-06-09 00:59:06 -0700 | [diff] [blame] | 528 | static u32 fsl_qspi_memsize_per_cs(struct fsl_qspi *q) |
| 529 | { |
| 530 | if (IS_ENABLED(CONFIG_FSL_QSPI_AHB_FULL_MAP)) { |
| 531 | if (needs_single_bus(q)) |
| 532 | return q->memmap_size / 2; |
| 533 | else |
| 534 | return q->memmap_size / 4; |
| 535 | } else { |
| 536 | return ALIGN(q->devtype_data->ahb_buf_size, 0x400); |
| 537 | } |
| 538 | } |
| 539 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 540 | static void fsl_qspi_read_ahb(struct fsl_qspi *q, const struct spi_mem_op *op) |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 541 | { |
Ye Li | d7e3c9a | 2020-06-09 00:59:06 -0700 | [diff] [blame] | 542 | void __iomem *ahb_read_addr = q->ahb_addr; |
| 543 | |
| 544 | if (IS_ENABLED(CONFIG_FSL_QSPI_AHB_FULL_MAP)) { |
| 545 | if (op->addr.nbytes) |
| 546 | ahb_read_addr += op->addr.val; |
| 547 | } |
| 548 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 549 | memcpy_fromio(op->data.buf.in, |
Ye Li | d7e3c9a | 2020-06-09 00:59:06 -0700 | [diff] [blame] | 550 | ahb_read_addr + q->selected * fsl_qspi_memsize_per_cs(q), |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 551 | op->data.nbytes); |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 552 | } |
| 553 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 554 | static void fsl_qspi_fill_txfifo(struct fsl_qspi *q, |
| 555 | const struct spi_mem_op *op) |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 556 | { |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 557 | void __iomem *base = q->iobase; |
| 558 | int i; |
| 559 | u32 val; |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 560 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 561 | for (i = 0; i < ALIGN_DOWN(op->data.nbytes, 4); i += 4) { |
| 562 | memcpy(&val, op->data.buf.out + i, 4); |
| 563 | val = fsl_qspi_endian_xchg(q, val); |
| 564 | qspi_writel(q, val, base + QUADSPI_TBDR); |
| 565 | } |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 566 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 567 | if (i < op->data.nbytes) { |
| 568 | memcpy(&val, op->data.buf.out + i, op->data.nbytes - i); |
| 569 | val = fsl_qspi_endian_xchg(q, val); |
| 570 | qspi_writel(q, val, base + QUADSPI_TBDR); |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 571 | } |
| 572 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 573 | if (needs_fill_txfifo(q)) { |
| 574 | for (i = op->data.nbytes; i < 16; i += 4) |
| 575 | qspi_writel(q, 0, base + QUADSPI_TBDR); |
| 576 | } |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 577 | } |
| 578 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 579 | static void fsl_qspi_read_rxfifo(struct fsl_qspi *q, |
| 580 | const struct spi_mem_op *op) |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 581 | { |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 582 | void __iomem *base = q->iobase; |
| 583 | int i; |
| 584 | u8 *buf = op->data.buf.in; |
| 585 | u32 val; |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 586 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 587 | for (i = 0; i < ALIGN_DOWN(op->data.nbytes, 4); i += 4) { |
| 588 | val = qspi_readl(q, base + QUADSPI_RBDR(i / 4)); |
| 589 | val = fsl_qspi_endian_xchg(q, val); |
| 590 | memcpy(buf + i, &val, 4); |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 591 | } |
| 592 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 593 | if (i < op->data.nbytes) { |
| 594 | val = qspi_readl(q, base + QUADSPI_RBDR(i / 4)); |
| 595 | val = fsl_qspi_endian_xchg(q, val); |
| 596 | memcpy(buf + i, &val, op->data.nbytes - i); |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 597 | } |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 598 | } |
| 599 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 600 | static int fsl_qspi_readl_poll_tout(struct fsl_qspi *q, void __iomem *base, |
| 601 | u32 mask, u32 delay_us, u32 timeout_us) |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 602 | { |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 603 | u32 reg; |
Alexander Stein | 283eb4a | 2017-06-01 09:32:19 +0200 | [diff] [blame] | 604 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 605 | if (!q->devtype_data->little_endian) |
| 606 | mask = (u32)cpu_to_be32(mask); |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 607 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 608 | return readl_poll_timeout(base, reg, !(reg & mask), timeout_us); |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 609 | } |
| 610 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 611 | static int fsl_qspi_do_op(struct fsl_qspi *q, const struct spi_mem_op *op) |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 612 | { |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 613 | void __iomem *base = q->iobase; |
| 614 | int err = 0; |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 615 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 616 | /* |
| 617 | * Always start the sequence at the same index since we update |
| 618 | * the LUT at each exec_op() call. And also specify the DATA |
| 619 | * length, since it's has not been specified in the LUT. |
| 620 | */ |
| 621 | qspi_writel(q, op->data.nbytes | QUADSPI_IPCR_SEQID(SEQID_LUT), |
| 622 | base + QUADSPI_IPCR); |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 623 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 624 | /* wait for the controller being ready */ |
| 625 | err = fsl_qspi_readl_poll_tout(q, base + QUADSPI_SR, |
| 626 | (QUADSPI_SR_IP_ACC_MASK | |
| 627 | QUADSPI_SR_AHB_ACC_MASK), |
| 628 | 10, 1000); |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 629 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 630 | if (!err && op->data.nbytes && op->data.dir == SPI_MEM_DATA_IN) |
| 631 | fsl_qspi_read_rxfifo(q, op); |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 632 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 633 | return err; |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 634 | } |
| 635 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 636 | static int fsl_qspi_exec_op(struct spi_slave *slave, |
| 637 | const struct spi_mem_op *op) |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 638 | { |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 639 | struct fsl_qspi *q = dev_get_priv(slave->dev->parent); |
| 640 | void __iomem *base = q->iobase; |
| 641 | u32 addr_offset = 0; |
| 642 | int err = 0; |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 643 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 644 | /* wait for the controller being ready */ |
| 645 | fsl_qspi_readl_poll_tout(q, base + QUADSPI_SR, (QUADSPI_SR_IP_ACC_MASK | |
| 646 | QUADSPI_SR_AHB_ACC_MASK), 10, 1000); |
Alexander Stein | 283eb4a | 2017-06-01 09:32:19 +0200 | [diff] [blame] | 647 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 648 | fsl_qspi_select_mem(q, slave); |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 649 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 650 | if (needs_amba_base_offset(q)) |
| 651 | addr_offset = q->memmap_phy; |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 652 | |
Ye Li | d7e3c9a | 2020-06-09 00:59:06 -0700 | [diff] [blame] | 653 | if (IS_ENABLED(CONFIG_FSL_QSPI_AHB_FULL_MAP)) { |
| 654 | if (op->addr.nbytes) |
| 655 | addr_offset += op->addr.val; |
| 656 | } |
| 657 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 658 | qspi_writel(q, |
Ye Li | d7e3c9a | 2020-06-09 00:59:06 -0700 | [diff] [blame] | 659 | q->selected * fsl_qspi_memsize_per_cs(q) + addr_offset, |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 660 | base + QUADSPI_SFAR); |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 661 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 662 | qspi_writel(q, qspi_readl(q, base + QUADSPI_MCR) | |
| 663 | QUADSPI_MCR_CLR_RXF_MASK | QUADSPI_MCR_CLR_TXF_MASK, |
| 664 | base + QUADSPI_MCR); |
Alison Wang | c7410e3 | 2014-05-06 09:13:01 +0800 | [diff] [blame] | 665 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 666 | qspi_writel(q, QUADSPI_SPTRCLR_BFPTRC | QUADSPI_SPTRCLR_IPPTRC, |
| 667 | base + QUADSPI_SPTRCLR); |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 668 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 669 | fsl_qspi_prepare_lut(q, op); |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 670 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 671 | /* |
| 672 | * If we have large chunks of data, we read them through the AHB bus |
| 673 | * by accessing the mapped memory. In all other cases we use |
| 674 | * IP commands to access the flash. |
| 675 | */ |
| 676 | if (op->data.nbytes > (q->devtype_data->rxfifo - 4) && |
| 677 | op->data.dir == SPI_MEM_DATA_IN) { |
| 678 | fsl_qspi_read_ahb(q, op); |
| 679 | } else { |
| 680 | qspi_writel(q, QUADSPI_RBCT_WMRK_MASK | |
| 681 | QUADSPI_RBCT_RXBRD_USEIPS, base + QUADSPI_RBCT); |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 682 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 683 | if (op->data.nbytes && op->data.dir == SPI_MEM_DATA_OUT) |
| 684 | fsl_qspi_fill_txfifo(q, op); |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 685 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 686 | err = fsl_qspi_do_op(q, op); |
| 687 | } |
| 688 | |
| 689 | /* Invalidate the data in the AHB buffer. */ |
| 690 | fsl_qspi_invalidate(q); |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 691 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 692 | return err; |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 693 | } |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 694 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 695 | static int fsl_qspi_adjust_op_size(struct spi_slave *slave, |
| 696 | struct spi_mem_op *op) |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 697 | { |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 698 | struct fsl_qspi *q = dev_get_priv(slave->dev->parent); |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 699 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 700 | if (op->data.dir == SPI_MEM_DATA_OUT) { |
| 701 | if (op->data.nbytes > q->devtype_data->txfifo) |
| 702 | op->data.nbytes = q->devtype_data->txfifo; |
| 703 | } else { |
| 704 | if (op->data.nbytes > q->devtype_data->ahb_buf_size) |
| 705 | op->data.nbytes = q->devtype_data->ahb_buf_size; |
| 706 | else if (op->data.nbytes > (q->devtype_data->rxfifo - 4)) |
| 707 | op->data.nbytes = ALIGN_DOWN(op->data.nbytes, 8); |
| 708 | } |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 709 | |
| 710 | return 0; |
| 711 | } |
| 712 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 713 | static int fsl_qspi_default_setup(struct fsl_qspi *q) |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 714 | { |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 715 | void __iomem *base = q->iobase; |
Ye Li | d7e3c9a | 2020-06-09 00:59:06 -0700 | [diff] [blame] | 716 | u32 reg, addr_offset = 0, memsize_cs; |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 717 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 718 | /* Reset the module */ |
| 719 | qspi_writel(q, QUADSPI_MCR_SWRSTSD_MASK | QUADSPI_MCR_SWRSTHD_MASK, |
| 720 | base + QUADSPI_MCR); |
| 721 | udelay(1); |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 722 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 723 | /* Disable the module */ |
| 724 | qspi_writel(q, QUADSPI_MCR_MDIS_MASK | QUADSPI_MCR_RESERVED_MASK, |
| 725 | base + QUADSPI_MCR); |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 726 | |
Yuan Yao | ae41239 | 2016-03-15 14:36:40 +0800 | [diff] [blame] | 727 | /* |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 728 | * Previous boot stages (BootROM, bootloader) might have used DDR |
| 729 | * mode and did not clear the TDH bits. As we currently use SDR mode |
| 730 | * only, clear the TDH bits if necessary. |
Yuan Yao | ae41239 | 2016-03-15 14:36:40 +0800 | [diff] [blame] | 731 | */ |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 732 | if (needs_tdh_setting(q)) |
| 733 | qspi_writel(q, qspi_readl(q, base + QUADSPI_FLSHCR) & |
| 734 | ~QUADSPI_FLSHCR_TDH_MASK, |
| 735 | base + QUADSPI_FLSHCR); |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 736 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 737 | reg = qspi_readl(q, base + QUADSPI_SMPR); |
| 738 | qspi_writel(q, reg & ~(QUADSPI_SMPR_FSDLY_MASK |
| 739 | | QUADSPI_SMPR_FSPHS_MASK |
| 740 | | QUADSPI_SMPR_HSENA_MASK |
| 741 | | QUADSPI_SMPR_DDRSMP_MASK), base + QUADSPI_SMPR); |
Ye Li | 007b604 | 2019-08-14 11:31:36 +0000 | [diff] [blame] | 742 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 743 | /* We only use the buffer3 for AHB read */ |
| 744 | qspi_writel(q, 0, base + QUADSPI_BUF0IND); |
| 745 | qspi_writel(q, 0, base + QUADSPI_BUF1IND); |
| 746 | qspi_writel(q, 0, base + QUADSPI_BUF2IND); |
Suresh Gupta | 4945b87 | 2017-08-30 20:06:33 +0530 | [diff] [blame] | 747 | |
Ye Li | d7e3c9a | 2020-06-09 00:59:06 -0700 | [diff] [blame] | 748 | if (IS_ENABLED(CONFIG_FSL_QSPI_AHB_FULL_MAP)) |
| 749 | qspi_writel(q, QUADSPI_BFGENCR_SEQID(SEQID_LUT_AHB), |
| 750 | q->iobase + QUADSPI_BFGENCR); |
| 751 | else |
| 752 | qspi_writel(q, QUADSPI_BFGENCR_SEQID(SEQID_LUT), |
| 753 | q->iobase + QUADSPI_BFGENCR); |
| 754 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 755 | qspi_writel(q, QUADSPI_RBCT_WMRK_MASK, base + QUADSPI_RBCT); |
| 756 | qspi_writel(q, QUADSPI_BUF3CR_ALLMST_MASK | |
| 757 | QUADSPI_BUF3CR_ADATSZ(q->devtype_data->ahb_buf_size / 8), |
| 758 | base + QUADSPI_BUF3CR); |
Suresh Gupta | 4945b87 | 2017-08-30 20:06:33 +0530 | [diff] [blame] | 759 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 760 | if (needs_amba_base_offset(q)) |
| 761 | addr_offset = q->memmap_phy; |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 762 | |
Yuan Yao | b4bfe10 | 2016-03-15 14:36:41 +0800 | [diff] [blame] | 763 | /* |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 764 | * In HW there can be a maximum of four chips on two buses with |
| 765 | * two chip selects on each bus. We use four chip selects in SW |
| 766 | * to differentiate between the four chips. |
| 767 | * We use ahb_buf_size for each chip and set SFA1AD, SFA2AD, SFB1AD, |
| 768 | * SFB2AD accordingly. |
Yuan Yao | b4bfe10 | 2016-03-15 14:36:41 +0800 | [diff] [blame] | 769 | */ |
Ye Li | d7e3c9a | 2020-06-09 00:59:06 -0700 | [diff] [blame] | 770 | memsize_cs = fsl_qspi_memsize_per_cs(q); |
| 771 | qspi_writel(q, memsize_cs + addr_offset, |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 772 | base + QUADSPI_SFA1AD); |
Ye Li | d7e3c9a | 2020-06-09 00:59:06 -0700 | [diff] [blame] | 773 | qspi_writel(q, memsize_cs * 2 + addr_offset, |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 774 | base + QUADSPI_SFA2AD); |
Ye Li | d7e3c9a | 2020-06-09 00:59:06 -0700 | [diff] [blame] | 775 | if (!needs_single_bus(q)) { |
| 776 | qspi_writel(q, memsize_cs * 3 + addr_offset, |
| 777 | base + QUADSPI_SFB1AD); |
| 778 | qspi_writel(q, memsize_cs * 4 + addr_offset, |
| 779 | base + QUADSPI_SFB2AD); |
| 780 | } |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 781 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 782 | q->selected = -1; |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 783 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 784 | /* Enable the module */ |
| 785 | qspi_writel(q, QUADSPI_MCR_RESERVED_MASK | QUADSPI_MCR_END_CFG_MASK, |
| 786 | base + QUADSPI_MCR); |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 787 | return 0; |
| 788 | } |
| 789 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 790 | static const struct spi_controller_mem_ops fsl_qspi_mem_ops = { |
| 791 | .adjust_op_size = fsl_qspi_adjust_op_size, |
| 792 | .supports_op = fsl_qspi_supports_op, |
| 793 | .exec_op = fsl_qspi_exec_op, |
| 794 | }; |
| 795 | |
| 796 | static int fsl_qspi_probe(struct udevice *bus) |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 797 | { |
Simon Glass | 9558862 | 2020-12-22 19:30:28 -0700 | [diff] [blame] | 798 | struct dm_spi_bus *dm_bus = dev_get_uclass_priv(bus); |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 799 | struct fsl_qspi *q = dev_get_priv(bus); |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 800 | const void *blob = gd->fdt_blob; |
Simon Glass | dd79d6e | 2017-01-17 16:52:55 -0700 | [diff] [blame] | 801 | int node = dev_of_offset(bus); |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 802 | struct fdt_resource res; |
| 803 | int ret; |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 804 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 805 | q->dev = bus; |
| 806 | q->devtype_data = (struct fsl_qspi_devtype_data *) |
| 807 | dev_get_driver_data(bus); |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 808 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 809 | /* find the resources */ |
| 810 | ret = fdt_get_named_resource(blob, node, "reg", "reg-names", "QuadSPI", |
| 811 | &res); |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 812 | if (ret) { |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 813 | dev_err(bus, "Can't get regs base addresses(ret = %d)!\n", ret); |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 814 | return -ENOMEM; |
| 815 | } |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 816 | |
| 817 | q->iobase = map_physmem(res.start, res.end - res.start, MAP_NOCACHE); |
| 818 | |
Yuan Yao | ae41239 | 2016-03-15 14:36:40 +0800 | [diff] [blame] | 819 | ret = fdt_get_named_resource(blob, node, "reg", "reg-names", |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 820 | "QuadSPI-memory", &res); |
Yuan Yao | ae41239 | 2016-03-15 14:36:40 +0800 | [diff] [blame] | 821 | if (ret) { |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 822 | dev_err(bus, "Can't get AMBA base addresses(ret = %d)!\n", ret); |
Yuan Yao | ae41239 | 2016-03-15 14:36:40 +0800 | [diff] [blame] | 823 | return -ENOMEM; |
| 824 | } |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 825 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 826 | q->ahb_addr = map_physmem(res.start, res.end - res.start, MAP_NOCACHE); |
| 827 | q->memmap_phy = res.start; |
Ye Li | d7e3c9a | 2020-06-09 00:59:06 -0700 | [diff] [blame] | 828 | q->memmap_size = res.end - res.start; |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 829 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 830 | dm_bus->max_hz = fdtdec_get_int(blob, node, "spi-max-frequency", |
| 831 | 66000000); |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 832 | |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 833 | fsl_qspi_default_setup(q); |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 834 | |
| 835 | return 0; |
| 836 | } |
| 837 | |
| 838 | static int fsl_qspi_xfer(struct udevice *dev, unsigned int bitlen, |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 839 | const void *dout, void *din, unsigned long flags) |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 840 | { |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 841 | return 0; |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 842 | } |
| 843 | |
| 844 | static int fsl_qspi_claim_bus(struct udevice *dev) |
| 845 | { |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 846 | return 0; |
| 847 | } |
| 848 | |
| 849 | static int fsl_qspi_release_bus(struct udevice *dev) |
| 850 | { |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 851 | return 0; |
| 852 | } |
| 853 | |
| 854 | static int fsl_qspi_set_speed(struct udevice *bus, uint speed) |
| 855 | { |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 856 | return 0; |
| 857 | } |
| 858 | |
| 859 | static int fsl_qspi_set_mode(struct udevice *bus, uint mode) |
| 860 | { |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 861 | return 0; |
| 862 | } |
| 863 | |
| 864 | static const struct dm_spi_ops fsl_qspi_ops = { |
| 865 | .claim_bus = fsl_qspi_claim_bus, |
| 866 | .release_bus = fsl_qspi_release_bus, |
| 867 | .xfer = fsl_qspi_xfer, |
| 868 | .set_speed = fsl_qspi_set_speed, |
| 869 | .set_mode = fsl_qspi_set_mode, |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 870 | .mem_ops = &fsl_qspi_mem_ops, |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 871 | }; |
| 872 | |
| 873 | static const struct udevice_id fsl_qspi_ids[] = { |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 874 | { .compatible = "fsl,vf610-qspi", .data = (ulong)&vybrid_data, }, |
| 875 | { .compatible = "fsl,imx6sx-qspi", .data = (ulong)&imx6sx_data, }, |
| 876 | { .compatible = "fsl,imx6ul-qspi", .data = (ulong)&imx6ul_data, }, |
| 877 | { .compatible = "fsl,imx7d-qspi", .data = (ulong)&imx7d_data, }, |
Ye Li | e4d39a0 | 2020-06-09 00:59:05 -0700 | [diff] [blame] | 878 | { .compatible = "fsl,imx7ulp-qspi", .data = (ulong)&imx7ulp_data, }, |
Kuldeep Singh | d8429a1 | 2020-02-20 22:57:52 +0530 | [diff] [blame] | 879 | { .compatible = "fsl,ls1021a-qspi", .data = (ulong)&ls1021a_data, }, |
| 880 | { .compatible = "fsl,ls1088a-qspi", .data = (ulong)&ls1088a_data, }, |
| 881 | { .compatible = "fsl,ls2080a-qspi", .data = (ulong)&ls2080a_data, }, |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 882 | { } |
| 883 | }; |
| 884 | |
| 885 | U_BOOT_DRIVER(fsl_qspi) = { |
| 886 | .name = "fsl_qspi", |
| 887 | .id = UCLASS_SPI, |
| 888 | .of_match = fsl_qspi_ids, |
| 889 | .ops = &fsl_qspi_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 890 | .priv_auto = sizeof(struct fsl_qspi), |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 891 | .probe = fsl_qspi_probe, |
Haikun.Wang@freescale.com | 221f2e1 | 2015-04-01 11:10:40 +0800 | [diff] [blame] | 892 | }; |