Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Driver for Atmel QSPI Controller |
| 4 | * |
| 5 | * Copyright (C) 2015 Atmel Corporation |
| 6 | * Copyright (C) 2018 Cryptera A/S |
| 7 | * |
| 8 | * Author: Cyrille Pitchen <cyrille.pitchen@atmel.com> |
| 9 | * Author: Piotr Bugalski <bugalski.piotr@gmail.com> |
| 10 | */ |
| 11 | |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 12 | #include <malloc.h> |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 13 | #include <asm/io.h> |
| 14 | #include <clk.h> |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 15 | #include <dm.h> |
| 16 | #include <errno.h> |
| 17 | #include <fdtdec.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 18 | #include <dm/device_compat.h> |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 19 | #include <linux/bitfield.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 20 | #include <linux/bitops.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 21 | #include <linux/err.h> |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 22 | #include <linux/io.h> |
| 23 | #include <linux/iopoll.h> |
| 24 | #include <linux/ioport.h> |
| 25 | #include <mach/clk.h> |
| 26 | #include <spi.h> |
| 27 | #include <spi-mem.h> |
| 28 | |
| 29 | /* QSPI register offsets */ |
| 30 | #define QSPI_CR 0x0000 /* Control Register */ |
| 31 | #define QSPI_MR 0x0004 /* Mode Register */ |
| 32 | #define QSPI_RD 0x0008 /* Receive Data Register */ |
| 33 | #define QSPI_TD 0x000c /* Transmit Data Register */ |
| 34 | #define QSPI_SR 0x0010 /* Status Register */ |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 35 | #define QSPI_SR2 0x0024 /* SAMA7G5 Status Register */ |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 36 | #define QSPI_IER 0x0014 /* Interrupt Enable Register */ |
| 37 | #define QSPI_IDR 0x0018 /* Interrupt Disable Register */ |
| 38 | #define QSPI_IMR 0x001c /* Interrupt Mask Register */ |
| 39 | #define QSPI_SCR 0x0020 /* Serial Clock Register */ |
| 40 | |
| 41 | #define QSPI_IAR 0x0030 /* Instruction Address Register */ |
| 42 | #define QSPI_ICR 0x0034 /* Instruction Code Register */ |
| 43 | #define QSPI_WICR 0x0034 /* Write Instruction Code Register */ |
| 44 | #define QSPI_IFR 0x0038 /* Instruction Frame Register */ |
| 45 | #define QSPI_RICR 0x003C /* Read Instruction Code Register */ |
| 46 | |
| 47 | #define QSPI_SMR 0x0040 /* Scrambling Mode Register */ |
| 48 | #define QSPI_SKR 0x0044 /* Scrambling Key Register */ |
| 49 | |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 50 | #define QSPI_REFRESH 0x0050 /* Refresh Register */ |
| 51 | #define QSPI_WRACNT 0x0054 /* Write Access Counter Register */ |
| 52 | #define QSPI_DLLCFG 0x0058 /* DLL Configuration Register */ |
| 53 | #define QSPI_PCALCFG 0x005C /* Pad Calibration Configuration Register */ |
| 54 | #define QSPI_PCALBP 0x0060 /* Pad Calibration Bypass Register */ |
| 55 | #define QSPI_TOUT 0x0064 /* Timeout Register */ |
| 56 | |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 57 | #define QSPI_WPMR 0x00E4 /* Write Protection Mode Register */ |
| 58 | #define QSPI_WPSR 0x00E8 /* Write Protection Status Register */ |
| 59 | |
| 60 | #define QSPI_VERSION 0x00FC /* Version Register */ |
| 61 | |
| 62 | /* Bitfields in QSPI_CR (Control Register) */ |
| 63 | #define QSPI_CR_QSPIEN BIT(0) |
| 64 | #define QSPI_CR_QSPIDIS BIT(1) |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 65 | #define QSPI_CR_DLLON BIT(2) |
| 66 | #define QSPI_CR_DLLOFF BIT(3) |
| 67 | #define QSPI_CR_STPCAL BIT(4) |
| 68 | #define QSPI_CR_SRFRSH BIT(5) |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 69 | #define QSPI_CR_SWRST BIT(7) |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 70 | #define QSPI_CR_UPDCFG BIT(8) |
| 71 | #define QSPI_CR_STTFR BIT(9) |
| 72 | #define QSPI_CR_RTOUT BIT(10) |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 73 | #define QSPI_CR_LASTXFER BIT(24) |
| 74 | |
| 75 | /* Bitfields in QSPI_MR (Mode Register) */ |
| 76 | #define QSPI_MR_SMM BIT(0) |
| 77 | #define QSPI_MR_LLB BIT(1) |
| 78 | #define QSPI_MR_WDRBT BIT(2) |
| 79 | #define QSPI_MR_SMRM BIT(3) |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 80 | #define QSPI_MR_DQSDLYEN BIT(3) |
| 81 | |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 82 | #define QSPI_MR_CSMODE_MASK GENMASK(5, 4) |
| 83 | #define QSPI_MR_CSMODE_NOT_RELOADED (0 << 4) |
| 84 | #define QSPI_MR_CSMODE_LASTXFER (1 << 4) |
| 85 | #define QSPI_MR_CSMODE_SYSTEMATICALLY (2 << 4) |
| 86 | #define QSPI_MR_NBBITS_MASK GENMASK(11, 8) |
| 87 | #define QSPI_MR_NBBITS(n) ((((n) - 8) << 8) & QSPI_MR_NBBITS_MASK) |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 88 | #define QSPI_MR_OENSD BIT(15) |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 89 | #define QSPI_MR_DLYBCT_MASK GENMASK(23, 16) |
| 90 | #define QSPI_MR_DLYBCT(n) (((n) << 16) & QSPI_MR_DLYBCT_MASK) |
| 91 | #define QSPI_MR_DLYCS_MASK GENMASK(31, 24) |
| 92 | #define QSPI_MR_DLYCS(n) (((n) << 24) & QSPI_MR_DLYCS_MASK) |
| 93 | |
| 94 | /* Bitfields in QSPI_SR/QSPI_IER/QSPI_IDR/QSPI_IMR */ |
| 95 | #define QSPI_SR_RDRF BIT(0) |
| 96 | #define QSPI_SR_TDRE BIT(1) |
| 97 | #define QSPI_SR_TXEMPTY BIT(2) |
| 98 | #define QSPI_SR_OVRES BIT(3) |
| 99 | #define QSPI_SR_CSR BIT(8) |
| 100 | #define QSPI_SR_CSS BIT(9) |
| 101 | #define QSPI_SR_INSTRE BIT(10) |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 102 | #define QSPI_SR_LWRA BIT(11) |
| 103 | #define QSPI_SR_QITF BIT(12) |
| 104 | #define QSPI_SR_QITR BIT(13) |
| 105 | #define QSPI_SR_CSFA BIT(14) |
| 106 | #define QSPI_SR_CSRA BIT(15) |
| 107 | #define QSPI_SR_RFRSHD BIT(16) |
| 108 | #define QSPI_SR_TOUT BIT(17) |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 109 | #define QSPI_SR_QSPIENS BIT(24) |
| 110 | |
| 111 | #define QSPI_SR_CMD_COMPLETED (QSPI_SR_INSTRE | QSPI_SR_CSR) |
| 112 | |
| 113 | /* Bitfields in QSPI_SCR (Serial Clock Register) */ |
| 114 | #define QSPI_SCR_CPOL BIT(0) |
| 115 | #define QSPI_SCR_CPHA BIT(1) |
| 116 | #define QSPI_SCR_SCBR_MASK GENMASK(15, 8) |
| 117 | #define QSPI_SCR_SCBR(n) (((n) << 8) & QSPI_SCR_SCBR_MASK) |
| 118 | #define QSPI_SCR_DLYBS_MASK GENMASK(23, 16) |
| 119 | #define QSPI_SCR_DLYBS(n) (((n) << 16) & QSPI_SCR_DLYBS_MASK) |
| 120 | |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 121 | /* Bitfields in QSPI_SR2 (SAMA7G5 Status Register) */ |
| 122 | #define QSPI_SR2_SYNCBSY BIT(0) |
| 123 | #define QSPI_SR2_QSPIENS BIT(1) |
| 124 | #define QSPI_SR2_CSS BIT(2) |
| 125 | #define QSPI_SR2_RBUSY BIT(3) |
| 126 | #define QSPI_SR2_HIDLE BIT(4) |
| 127 | #define QSPI_SR2_DLOCK BIT(5) |
| 128 | #define QSPI_SR2_CALBSY BIT(6) |
| 129 | |
| 130 | /* Bitfields in QSPI_IAR (Instruction Address Register) */ |
| 131 | #define QSPI_IAR_ADDR GENMASK(31, 0) |
| 132 | |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 133 | /* Bitfields in QSPI_ICR (Read/Write Instruction Code Register) */ |
| 134 | #define QSPI_ICR_INST_MASK GENMASK(7, 0) |
| 135 | #define QSPI_ICR_INST(inst) (((inst) << 0) & QSPI_ICR_INST_MASK) |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 136 | #define QSPI_ICR_INST_MASK_SAMA7G5 GENMASK(15, 0) |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 137 | #define QSPI_ICR_OPT_MASK GENMASK(23, 16) |
| 138 | #define QSPI_ICR_OPT(opt) (((opt) << 16) & QSPI_ICR_OPT_MASK) |
| 139 | |
| 140 | /* Bitfields in QSPI_IFR (Instruction Frame Register) */ |
| 141 | #define QSPI_IFR_WIDTH_MASK GENMASK(2, 0) |
| 142 | #define QSPI_IFR_WIDTH_SINGLE_BIT_SPI (0 << 0) |
| 143 | #define QSPI_IFR_WIDTH_DUAL_OUTPUT (1 << 0) |
| 144 | #define QSPI_IFR_WIDTH_QUAD_OUTPUT (2 << 0) |
| 145 | #define QSPI_IFR_WIDTH_DUAL_IO (3 << 0) |
| 146 | #define QSPI_IFR_WIDTH_QUAD_IO (4 << 0) |
| 147 | #define QSPI_IFR_WIDTH_DUAL_CMD (5 << 0) |
| 148 | #define QSPI_IFR_WIDTH_QUAD_CMD (6 << 0) |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 149 | #define QSPI_IFR_WIDTH_OCT_OUTPUT (7 << 0) |
| 150 | #define QSPI_IFR_WIDTH_OCT_IO (8 << 0) |
| 151 | #define QSPI_IFR_WIDTH_OCT_CMD (9 << 0) |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 152 | #define QSPI_IFR_INSTEN BIT(4) |
| 153 | #define QSPI_IFR_ADDREN BIT(5) |
| 154 | #define QSPI_IFR_OPTEN BIT(6) |
| 155 | #define QSPI_IFR_DATAEN BIT(7) |
| 156 | #define QSPI_IFR_OPTL_MASK GENMASK(9, 8) |
| 157 | #define QSPI_IFR_OPTL_1BIT (0 << 8) |
| 158 | #define QSPI_IFR_OPTL_2BIT (1 << 8) |
| 159 | #define QSPI_IFR_OPTL_4BIT (2 << 8) |
| 160 | #define QSPI_IFR_OPTL_8BIT (3 << 8) |
| 161 | #define QSPI_IFR_ADDRL BIT(10) |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 162 | #define QSPI_IFR_ADDRL_SAMA7G5 GENMASK(11, 10) |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 163 | #define QSPI_IFR_TFRTYP_MEM BIT(12) |
| 164 | #define QSPI_IFR_SAMA5D2_WRITE_TRSFR BIT(13) |
| 165 | #define QSPI_IFR_CRM BIT(14) |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 166 | #define QSPI_IFR_DDREN BIT(15) |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 167 | #define QSPI_IFR_NBDUM_MASK GENMASK(20, 16) |
| 168 | #define QSPI_IFR_NBDUM(n) (((n) << 16) & QSPI_IFR_NBDUM_MASK) |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 169 | #define QSPI_IFR_END BIT(22) |
| 170 | #define QSPI_IFR_SMRM BIT(23) |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 171 | #define QSPI_IFR_APBTFRTYP_READ BIT(24) /* Defined in SAM9X60 */ |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 172 | #define QSPI_IFR_DQSEN BIT(25) |
| 173 | #define QSPI_IFR_DDRCMDEN BIT(26) |
| 174 | #define QSPI_IFR_HFWBEN BIT(27) |
| 175 | #define QSPI_IFR_PROTTYP GENMASK(29, 28) |
| 176 | #define QSPI_IFR_PROTTYP_STD_SPI 0 |
| 177 | #define QSPI_IFR_PROTTYP_TWIN_QUAD 1 |
| 178 | #define QSPI_IFR_PROTTYP_OCTAFLASH 2 |
| 179 | #define QSPI_IFR_PROTTYP_HYPERFLASH 3 |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 180 | |
| 181 | /* Bitfields in QSPI_SMR (Scrambling Mode Register) */ |
| 182 | #define QSPI_SMR_SCREN BIT(0) |
| 183 | #define QSPI_SMR_RVDIS BIT(1) |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 184 | #define QSPI_SMR_SCRKL BIT(2) |
| 185 | |
| 186 | /* Bitfields in QSPI_REFRESH (Refresh Register) */ |
| 187 | #define QSPI_REFRESH_DELAY_COUNTER GENMASK(31, 0) |
| 188 | |
| 189 | /* Bitfields in QSPI_WRACNT (Write Access Counter Register) */ |
| 190 | #define QSPI_WRACNT_NBWRA GENMASK(31, 0) |
| 191 | |
| 192 | /* Bitfields in QSPI_DLLCFG (DLL Configuration Register) */ |
| 193 | #define QSPI_DLLCFG_RANGE BIT(0) |
| 194 | |
| 195 | /* Bitfields in QSPI_PCALCFG (DLL Pad Calibration Configuration Register) */ |
| 196 | #define QSPI_PCALCFG_AAON BIT(0) |
| 197 | #define QSPI_PCALCFG_DAPCAL BIT(1) |
| 198 | #define QSPI_PCALCFG_DIFFPM BIT(2) |
| 199 | #define QSPI_PCALCFG_CLKDIV GENMASK(6, 4) |
| 200 | #define QSPI_PCALCFG_CALCNT GENMASK(16, 8) |
| 201 | #define QSPI_PCALCFG_CALP GENMASK(27, 24) |
| 202 | #define QSPI_PCALCFG_CALN GENMASK(31, 28) |
| 203 | |
| 204 | /* Bitfields in QSPI_PCALBP (DLL Pad Calibration Bypass Register) */ |
| 205 | #define QSPI_PCALBP_BPEN BIT(0) |
| 206 | #define QSPI_PCALBP_CALPBP GENMASK(11, 8) |
| 207 | #define QSPI_PCALBP_CALNBP GENMASK(19, 16) |
| 208 | |
| 209 | /* Bitfields in QSPI_TOUT (Timeout Register) */ |
| 210 | #define QSPI_TOUT_TCNTM GENMASK(15, 0) |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 211 | |
| 212 | /* Bitfields in QSPI_WPMR (Write Protection Mode Register) */ |
| 213 | #define QSPI_WPMR_WPEN BIT(0) |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 214 | #define QSPI_WPMR_WPITEN BIT(1) |
| 215 | #define QSPI_WPMR_WPCREN BIT(2) |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 216 | #define QSPI_WPMR_WPKEY_MASK GENMASK(31, 8) |
| 217 | #define QSPI_WPMR_WPKEY(wpkey) (((wpkey) << 8) & QSPI_WPMR_WPKEY_MASK) |
| 218 | |
| 219 | /* Bitfields in QSPI_WPSR (Write Protection Status Register) */ |
| 220 | #define QSPI_WPSR_WPVS BIT(0) |
| 221 | #define QSPI_WPSR_WPVSRC_MASK GENMASK(15, 8) |
| 222 | #define QSPI_WPSR_WPVSRC(src) (((src) << 8) & QSPI_WPSR_WPVSRC) |
| 223 | |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 224 | #define ATMEL_QSPI_TIMEOUT 1000000 /* us */ |
| 225 | #define ATMEL_QSPI_SYNC_TIMEOUT 300000 /* us */ |
| 226 | #define QSPI_DLLCFG_THRESHOLD_FREQ 90000000U |
| 227 | #define QSPI_TOUT_MAX 0xffff |
| 228 | |
| 229 | /** |
| 230 | * struct atmel_qspi_pcal - Pad Calibration Clock Division |
| 231 | * @pclk_rate: peripheral clock rate. |
| 232 | * @pclkdiv: calibration clock division. The clock applied to the calibration |
| 233 | * cell is divided by pclkdiv + 1. |
| 234 | */ |
| 235 | struct atmel_qspi_pcal { |
| 236 | u32 pclk_rate; |
| 237 | u8 pclk_div; |
| 238 | }; |
| 239 | |
| 240 | #define ATMEL_QSPI_PCAL_ARRAY_SIZE 8 |
| 241 | static const struct atmel_qspi_pcal pcal[ATMEL_QSPI_PCAL_ARRAY_SIZE] = { |
| 242 | {25000000, 0}, |
| 243 | {50000000, 1}, |
| 244 | {75000000, 2}, |
| 245 | {100000000, 3}, |
| 246 | {125000000, 4}, |
| 247 | {150000000, 5}, |
| 248 | {175000000, 6}, |
| 249 | {200000000, 7}, |
| 250 | }; |
| 251 | |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 252 | struct atmel_qspi_caps { |
| 253 | bool has_qspick; |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 254 | bool has_gclk; |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 255 | bool has_ricr; |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 256 | bool octal; |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 257 | }; |
| 258 | |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 259 | struct atmel_qspi_priv_ops; |
| 260 | |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 261 | struct atmel_qspi { |
| 262 | void __iomem *regs; |
| 263 | void __iomem *mem; |
Tudor Ambarus | 678b893 | 2020-03-20 09:37:59 +0000 | [diff] [blame] | 264 | resource_size_t mmap_size; |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 265 | const struct atmel_qspi_caps *caps; |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 266 | const struct atmel_qspi_priv_ops *ops; |
Tudor Ambarus | f44d2e0 | 2020-03-20 09:37:59 +0000 | [diff] [blame] | 267 | struct udevice *dev; |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 268 | ulong bus_clk_rate; |
| 269 | u32 mr; |
| 270 | }; |
| 271 | |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 272 | struct atmel_qspi_priv_ops { |
| 273 | int (*set_cfg)(struct atmel_qspi *aq, const struct spi_mem_op *op, |
| 274 | u32 *offset); |
| 275 | int (*transfer)(struct atmel_qspi *aq, const struct spi_mem_op *op, |
| 276 | u32 offset); |
| 277 | }; |
| 278 | |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 279 | struct atmel_qspi_mode { |
| 280 | u8 cmd_buswidth; |
| 281 | u8 addr_buswidth; |
| 282 | u8 data_buswidth; |
| 283 | u32 config; |
| 284 | }; |
| 285 | |
| 286 | static const struct atmel_qspi_mode atmel_qspi_modes[] = { |
| 287 | { 1, 1, 1, QSPI_IFR_WIDTH_SINGLE_BIT_SPI }, |
| 288 | { 1, 1, 2, QSPI_IFR_WIDTH_DUAL_OUTPUT }, |
| 289 | { 1, 1, 4, QSPI_IFR_WIDTH_QUAD_OUTPUT }, |
| 290 | { 1, 2, 2, QSPI_IFR_WIDTH_DUAL_IO }, |
| 291 | { 1, 4, 4, QSPI_IFR_WIDTH_QUAD_IO }, |
| 292 | { 2, 2, 2, QSPI_IFR_WIDTH_DUAL_CMD }, |
| 293 | { 4, 4, 4, QSPI_IFR_WIDTH_QUAD_CMD }, |
| 294 | }; |
| 295 | |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 296 | static const struct atmel_qspi_mode atmel_qspi_sama7g5_modes[] = { |
| 297 | { 1, 1, 1, QSPI_IFR_WIDTH_SINGLE_BIT_SPI }, |
| 298 | { 1, 1, 2, QSPI_IFR_WIDTH_DUAL_OUTPUT }, |
| 299 | { 1, 1, 4, QSPI_IFR_WIDTH_QUAD_OUTPUT }, |
| 300 | { 1, 2, 2, QSPI_IFR_WIDTH_DUAL_IO }, |
| 301 | { 1, 4, 4, QSPI_IFR_WIDTH_QUAD_IO }, |
| 302 | { 2, 2, 2, QSPI_IFR_WIDTH_DUAL_CMD }, |
| 303 | { 4, 4, 4, QSPI_IFR_WIDTH_QUAD_CMD }, |
| 304 | { 1, 1, 8, QSPI_IFR_WIDTH_OCT_OUTPUT }, |
| 305 | { 1, 8, 8, QSPI_IFR_WIDTH_OCT_IO }, |
| 306 | { 8, 8, 8, QSPI_IFR_WIDTH_OCT_CMD }, |
| 307 | }; |
| 308 | |
Tudor Ambarus | f44d2e0 | 2020-03-20 09:37:59 +0000 | [diff] [blame] | 309 | #ifdef VERBOSE_DEBUG |
| 310 | static const char *atmel_qspi_reg_name(u32 offset, char *tmp, size_t sz) |
| 311 | { |
| 312 | switch (offset) { |
| 313 | case QSPI_CR: |
| 314 | return "CR"; |
| 315 | case QSPI_MR: |
| 316 | return "MR"; |
| 317 | case QSPI_RD: |
Tudor Ambarus | 7e02233 | 2021-11-03 18:45:42 +0200 | [diff] [blame] | 318 | return "RD"; |
Tudor Ambarus | f44d2e0 | 2020-03-20 09:37:59 +0000 | [diff] [blame] | 319 | case QSPI_TD: |
| 320 | return "TD"; |
| 321 | case QSPI_SR: |
| 322 | return "SR"; |
| 323 | case QSPI_IER: |
| 324 | return "IER"; |
| 325 | case QSPI_IDR: |
| 326 | return "IDR"; |
| 327 | case QSPI_IMR: |
| 328 | return "IMR"; |
| 329 | case QSPI_SCR: |
| 330 | return "SCR"; |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 331 | case QSPI_SR2: |
| 332 | return "SR2"; |
Tudor Ambarus | f44d2e0 | 2020-03-20 09:37:59 +0000 | [diff] [blame] | 333 | case QSPI_IAR: |
| 334 | return "IAR"; |
| 335 | case QSPI_ICR: |
| 336 | return "ICR/WICR"; |
| 337 | case QSPI_IFR: |
| 338 | return "IFR"; |
| 339 | case QSPI_RICR: |
| 340 | return "RICR"; |
| 341 | case QSPI_SMR: |
| 342 | return "SMR"; |
| 343 | case QSPI_SKR: |
| 344 | return "SKR"; |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 345 | case QSPI_REFRESH: |
| 346 | return "REFRESH"; |
| 347 | case QSPI_WRACNT: |
| 348 | return "WRACNT"; |
| 349 | case QSPI_DLLCFG: |
| 350 | return "DLLCFG"; |
| 351 | case QSPI_PCALCFG: |
| 352 | return "PCALCFG"; |
| 353 | case QSPI_PCALBP: |
| 354 | return "PCALBP"; |
| 355 | case QSPI_TOUT: |
| 356 | return "TOUT"; |
Tudor Ambarus | f44d2e0 | 2020-03-20 09:37:59 +0000 | [diff] [blame] | 357 | case QSPI_WPMR: |
| 358 | return "WPMR"; |
| 359 | case QSPI_WPSR: |
| 360 | return "WPSR"; |
| 361 | case QSPI_VERSION: |
| 362 | return "VERSION"; |
| 363 | default: |
| 364 | snprintf(tmp, sz, "0x%02x", offset); |
| 365 | break; |
| 366 | } |
| 367 | |
| 368 | return tmp; |
| 369 | } |
| 370 | #endif /* VERBOSE_DEBUG */ |
| 371 | |
| 372 | static u32 atmel_qspi_read(struct atmel_qspi *aq, u32 offset) |
| 373 | { |
| 374 | u32 value = readl(aq->regs + offset); |
| 375 | |
| 376 | #ifdef VERBOSE_DEBUG |
| 377 | char tmp[16]; |
| 378 | |
| 379 | dev_vdbg(aq->dev, "read 0x%08x from %s\n", value, |
| 380 | atmel_qspi_reg_name(offset, tmp, sizeof(tmp))); |
| 381 | #endif /* VERBOSE_DEBUG */ |
| 382 | |
| 383 | return value; |
| 384 | } |
| 385 | |
| 386 | static void atmel_qspi_write(u32 value, struct atmel_qspi *aq, u32 offset) |
| 387 | { |
| 388 | #ifdef VERBOSE_DEBUG |
| 389 | char tmp[16]; |
| 390 | |
| 391 | dev_vdbg(aq->dev, "write 0x%08x into %s\n", value, |
| 392 | atmel_qspi_reg_name(offset, tmp, sizeof(tmp))); |
| 393 | #endif /* VERBOSE_DEBUG */ |
| 394 | |
| 395 | writel(value, aq->regs + offset); |
| 396 | } |
| 397 | |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 398 | static inline bool atmel_qspi_is_compatible(const struct spi_mem_op *op, |
| 399 | const struct atmel_qspi_mode *mode) |
| 400 | { |
| 401 | if (op->cmd.buswidth != mode->cmd_buswidth) |
| 402 | return false; |
| 403 | |
| 404 | if (op->addr.nbytes && op->addr.buswidth != mode->addr_buswidth) |
| 405 | return false; |
| 406 | |
| 407 | if (op->data.nbytes && op->data.buswidth != mode->data_buswidth) |
| 408 | return false; |
| 409 | |
| 410 | return true; |
| 411 | } |
| 412 | |
| 413 | static int atmel_qspi_find_mode(const struct spi_mem_op *op) |
| 414 | { |
| 415 | u32 i; |
| 416 | |
| 417 | for (i = 0; i < ARRAY_SIZE(atmel_qspi_modes); i++) |
| 418 | if (atmel_qspi_is_compatible(op, &atmel_qspi_modes[i])) |
| 419 | return i; |
| 420 | |
| 421 | return -ENOTSUPP; |
| 422 | } |
| 423 | |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 424 | static int atmel_qspi_sama7g5_find_mode(const struct spi_mem_op *op) |
| 425 | { |
| 426 | u32 i; |
| 427 | |
| 428 | for (i = 0; i < ARRAY_SIZE(atmel_qspi_sama7g5_modes); i++) |
| 429 | if (atmel_qspi_is_compatible(op, &atmel_qspi_sama7g5_modes[i])) |
| 430 | return i; |
| 431 | |
| 432 | return -EOPNOTSUPP; |
| 433 | } |
| 434 | |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 435 | static bool atmel_qspi_supports_op(struct spi_slave *slave, |
| 436 | const struct spi_mem_op *op) |
| 437 | { |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 438 | struct atmel_qspi *aq = dev_get_priv(slave->dev->parent); |
| 439 | |
Tudor Ambarus | 938a6c9 | 2022-04-08 11:40:26 +0300 | [diff] [blame] | 440 | if (!spi_mem_default_supports_op(slave, op)) |
| 441 | return false; |
| 442 | |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 443 | if (aq->caps->octal) { |
| 444 | if (atmel_qspi_sama7g5_find_mode(op) < 0) |
| 445 | return false; |
| 446 | else |
| 447 | return true; |
| 448 | } |
| 449 | |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 450 | if (atmel_qspi_find_mode(op) < 0) |
| 451 | return false; |
| 452 | |
| 453 | /* special case not supported by hardware */ |
| 454 | if (op->addr.nbytes == 2 && op->cmd.buswidth != op->addr.buswidth && |
| 455 | op->dummy.nbytes == 0) |
| 456 | return false; |
| 457 | |
| 458 | return true; |
| 459 | } |
| 460 | |
| 461 | static int atmel_qspi_set_cfg(struct atmel_qspi *aq, |
| 462 | const struct spi_mem_op *op, u32 *offset) |
| 463 | { |
| 464 | u32 iar, icr, ifr; |
| 465 | u32 dummy_cycles = 0; |
| 466 | int mode; |
| 467 | |
| 468 | iar = 0; |
| 469 | icr = QSPI_ICR_INST(op->cmd.opcode); |
| 470 | ifr = QSPI_IFR_INSTEN; |
| 471 | |
| 472 | mode = atmel_qspi_find_mode(op); |
| 473 | if (mode < 0) |
| 474 | return mode; |
| 475 | ifr |= atmel_qspi_modes[mode].config; |
| 476 | |
| 477 | if (op->dummy.buswidth && op->dummy.nbytes) |
| 478 | dummy_cycles = op->dummy.nbytes * 8 / op->dummy.buswidth; |
| 479 | |
| 480 | /* |
| 481 | * The controller allows 24 and 32-bit addressing while NAND-flash |
| 482 | * requires 16-bit long. Handling 8-bit long addresses is done using |
| 483 | * the option field. For the 16-bit addresses, the workaround depends |
| 484 | * of the number of requested dummy bits. If there are 8 or more dummy |
| 485 | * cycles, the address is shifted and sent with the first dummy byte. |
| 486 | * Otherwise opcode is disabled and the first byte of the address |
| 487 | * contains the command opcode (works only if the opcode and address |
| 488 | * use the same buswidth). The limitation is when the 16-bit address is |
| 489 | * used without enough dummy cycles and the opcode is using a different |
| 490 | * buswidth than the address. |
| 491 | */ |
| 492 | if (op->addr.buswidth) { |
| 493 | switch (op->addr.nbytes) { |
| 494 | case 0: |
| 495 | break; |
| 496 | case 1: |
| 497 | ifr |= QSPI_IFR_OPTEN | QSPI_IFR_OPTL_8BIT; |
| 498 | icr |= QSPI_ICR_OPT(op->addr.val & 0xff); |
| 499 | break; |
| 500 | case 2: |
| 501 | if (dummy_cycles < 8 / op->addr.buswidth) { |
| 502 | ifr &= ~QSPI_IFR_INSTEN; |
| 503 | ifr |= QSPI_IFR_ADDREN; |
| 504 | iar = (op->cmd.opcode << 16) | |
| 505 | (op->addr.val & 0xffff); |
| 506 | } else { |
| 507 | ifr |= QSPI_IFR_ADDREN; |
| 508 | iar = (op->addr.val << 8) & 0xffffff; |
| 509 | dummy_cycles -= 8 / op->addr.buswidth; |
| 510 | } |
| 511 | break; |
| 512 | case 3: |
| 513 | ifr |= QSPI_IFR_ADDREN; |
| 514 | iar = op->addr.val & 0xffffff; |
| 515 | break; |
| 516 | case 4: |
| 517 | ifr |= QSPI_IFR_ADDREN | QSPI_IFR_ADDRL; |
| 518 | iar = op->addr.val & 0x7ffffff; |
| 519 | break; |
| 520 | default: |
| 521 | return -ENOTSUPP; |
| 522 | } |
| 523 | } |
| 524 | |
| 525 | /* offset of the data access in the QSPI memory space */ |
| 526 | *offset = iar; |
| 527 | |
| 528 | /* Set number of dummy cycles */ |
| 529 | if (dummy_cycles) |
| 530 | ifr |= QSPI_IFR_NBDUM(dummy_cycles); |
| 531 | |
| 532 | /* Set data enable */ |
| 533 | if (op->data.nbytes) |
| 534 | ifr |= QSPI_IFR_DATAEN; |
| 535 | |
| 536 | /* |
| 537 | * If the QSPI controller is set in regular SPI mode, set it in |
| 538 | * Serial Memory Mode (SMM). |
| 539 | */ |
| 540 | if (aq->mr != QSPI_MR_SMM) { |
Tudor Ambarus | f44d2e0 | 2020-03-20 09:37:59 +0000 | [diff] [blame] | 541 | atmel_qspi_write(QSPI_MR_SMM, aq, QSPI_MR); |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 542 | aq->mr = QSPI_MR_SMM; |
| 543 | } |
| 544 | |
| 545 | /* Clear pending interrupts */ |
Tudor Ambarus | f44d2e0 | 2020-03-20 09:37:59 +0000 | [diff] [blame] | 546 | (void)atmel_qspi_read(aq, QSPI_SR); |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 547 | |
| 548 | if (aq->caps->has_ricr) { |
| 549 | if (!op->addr.nbytes && op->data.dir == SPI_MEM_DATA_IN) |
| 550 | ifr |= QSPI_IFR_APBTFRTYP_READ; |
| 551 | |
| 552 | /* Set QSPI Instruction Frame registers */ |
Tudor Ambarus | f44d2e0 | 2020-03-20 09:37:59 +0000 | [diff] [blame] | 553 | atmel_qspi_write(iar, aq, QSPI_IAR); |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 554 | if (op->data.dir == SPI_MEM_DATA_IN) |
Tudor Ambarus | f44d2e0 | 2020-03-20 09:37:59 +0000 | [diff] [blame] | 555 | atmel_qspi_write(icr, aq, QSPI_RICR); |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 556 | else |
Tudor Ambarus | f44d2e0 | 2020-03-20 09:37:59 +0000 | [diff] [blame] | 557 | atmel_qspi_write(icr, aq, QSPI_WICR); |
| 558 | atmel_qspi_write(ifr, aq, QSPI_IFR); |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 559 | } else { |
| 560 | if (op->data.dir == SPI_MEM_DATA_OUT) |
| 561 | ifr |= QSPI_IFR_SAMA5D2_WRITE_TRSFR; |
| 562 | |
| 563 | /* Set QSPI Instruction Frame registers */ |
Tudor Ambarus | f44d2e0 | 2020-03-20 09:37:59 +0000 | [diff] [blame] | 564 | atmel_qspi_write(iar, aq, QSPI_IAR); |
| 565 | atmel_qspi_write(icr, aq, QSPI_ICR); |
| 566 | atmel_qspi_write(ifr, aq, QSPI_IFR); |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 567 | } |
| 568 | |
| 569 | return 0; |
| 570 | } |
| 571 | |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 572 | static int atmel_qspi_transfer(struct atmel_qspi *aq, |
| 573 | const struct spi_mem_op *op, u32 offset) |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 574 | { |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 575 | u32 sr, imr; |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 576 | |
| 577 | /* Skip to the final steps if there is no data */ |
| 578 | if (op->data.nbytes) { |
| 579 | /* Dummy read of QSPI_IFR to synchronize APB and AHB accesses */ |
Tudor Ambarus | f44d2e0 | 2020-03-20 09:37:59 +0000 | [diff] [blame] | 580 | (void)atmel_qspi_read(aq, QSPI_IFR); |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 581 | |
| 582 | /* Send/Receive data */ |
| 583 | if (op->data.dir == SPI_MEM_DATA_IN) |
| 584 | memcpy_fromio(op->data.buf.in, aq->mem + offset, |
| 585 | op->data.nbytes); |
| 586 | else |
| 587 | memcpy_toio(aq->mem + offset, op->data.buf.out, |
| 588 | op->data.nbytes); |
| 589 | |
| 590 | /* Release the chip-select */ |
Tudor Ambarus | f44d2e0 | 2020-03-20 09:37:59 +0000 | [diff] [blame] | 591 | atmel_qspi_write(QSPI_CR_LASTXFER, aq, QSPI_CR); |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 592 | } |
| 593 | |
| 594 | /* Poll INSTruction End and Chip Select Rise flags. */ |
| 595 | imr = QSPI_SR_INSTRE | QSPI_SR_CSR; |
| 596 | return readl_poll_timeout(aq->regs + QSPI_SR, sr, (sr & imr) == imr, |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 597 | ATMEL_QSPI_TIMEOUT); |
| 598 | } |
| 599 | |
| 600 | static int atmel_qspi_reg_sync(struct atmel_qspi *aq) |
| 601 | { |
| 602 | u32 val; |
| 603 | |
| 604 | return readl_poll_timeout(aq->regs + QSPI_SR2, val, |
| 605 | !(val & QSPI_SR2_SYNCBSY), |
| 606 | ATMEL_QSPI_SYNC_TIMEOUT); |
| 607 | } |
| 608 | |
| 609 | static int atmel_qspi_update_config(struct atmel_qspi *aq) |
| 610 | { |
| 611 | int ret; |
| 612 | |
| 613 | ret = atmel_qspi_reg_sync(aq); |
| 614 | if (ret) |
| 615 | return ret; |
| 616 | atmel_qspi_write(QSPI_CR_UPDCFG, aq, QSPI_CR); |
| 617 | return atmel_qspi_reg_sync(aq); |
| 618 | } |
| 619 | |
| 620 | static int atmel_qspi_sama7g5_set_cfg(struct atmel_qspi *aq, |
| 621 | const struct spi_mem_op *op, u32 *offset) |
| 622 | { |
| 623 | u32 iar, icr, ifr; |
| 624 | int mode, ret; |
| 625 | |
| 626 | iar = 0; |
| 627 | icr = FIELD_PREP(QSPI_ICR_INST_MASK_SAMA7G5, op->cmd.opcode); |
| 628 | ifr = QSPI_IFR_INSTEN; |
| 629 | |
| 630 | mode = atmel_qspi_sama7g5_find_mode(op); |
| 631 | if (mode < 0) |
| 632 | return mode; |
| 633 | ifr |= atmel_qspi_sama7g5_modes[mode].config; |
| 634 | |
| 635 | if (op->dummy.buswidth && op->dummy.nbytes) { |
| 636 | if (op->addr.dtr && op->dummy.dtr && op->data.dtr) |
| 637 | ifr |= QSPI_IFR_NBDUM(op->dummy.nbytes * 8 / |
| 638 | (2 * op->dummy.buswidth)); |
| 639 | else |
| 640 | ifr |= QSPI_IFR_NBDUM(op->dummy.nbytes * 8 / |
| 641 | op->dummy.buswidth); |
| 642 | } |
| 643 | |
| 644 | if (op->addr.buswidth && op->addr.nbytes) { |
| 645 | ifr |= FIELD_PREP(QSPI_IFR_ADDRL_SAMA7G5, op->addr.nbytes - 1) | |
| 646 | QSPI_IFR_ADDREN; |
| 647 | iar = FIELD_PREP(QSPI_IAR_ADDR, op->addr.val); |
| 648 | } |
| 649 | |
| 650 | if (op->addr.dtr && op->dummy.dtr && op->data.dtr) { |
| 651 | ifr |= QSPI_IFR_DDREN; |
| 652 | if (op->cmd.dtr) |
| 653 | ifr |= QSPI_IFR_DDRCMDEN; |
| 654 | ifr |= QSPI_IFR_DQSEN; |
| 655 | } |
| 656 | |
| 657 | if (op->cmd.buswidth == 8 || op->addr.buswidth == 8 || |
| 658 | op->data.buswidth == 8) |
| 659 | ifr |= FIELD_PREP(QSPI_IFR_PROTTYP, QSPI_IFR_PROTTYP_OCTAFLASH); |
| 660 | |
| 661 | /* offset of the data access in the QSPI memory space */ |
| 662 | *offset = iar; |
| 663 | |
| 664 | /* Set data enable */ |
| 665 | if (op->data.nbytes) { |
| 666 | ifr |= QSPI_IFR_DATAEN; |
| 667 | if (op->addr.nbytes) |
| 668 | ifr |= QSPI_IFR_TFRTYP_MEM; |
| 669 | } |
| 670 | |
| 671 | /* |
| 672 | * If the QSPI controller is set in regular SPI mode, set it in |
| 673 | * Serial Memory Mode (SMM). |
| 674 | */ |
| 675 | if (aq->mr != QSPI_MR_SMM) { |
| 676 | atmel_qspi_write(QSPI_MR_SMM | QSPI_MR_DQSDLYEN, aq, QSPI_MR); |
| 677 | ret = atmel_qspi_update_config(aq); |
| 678 | if (ret) |
| 679 | return ret; |
| 680 | aq->mr = QSPI_MR_SMM; |
| 681 | } |
| 682 | |
| 683 | /* Clear pending interrupts */ |
| 684 | (void)atmel_qspi_read(aq, QSPI_SR); |
| 685 | |
| 686 | /* Set QSPI Instruction Frame registers */ |
| 687 | if (op->addr.nbytes && !op->data.nbytes) |
| 688 | atmel_qspi_write(iar, aq, QSPI_IAR); |
| 689 | |
| 690 | if (op->data.dir == SPI_MEM_DATA_IN) { |
| 691 | atmel_qspi_write(icr, aq, QSPI_RICR); |
| 692 | } else { |
| 693 | atmel_qspi_write(icr, aq, QSPI_WICR); |
| 694 | if (op->data.nbytes) |
| 695 | atmel_qspi_write(FIELD_PREP(QSPI_WRACNT_NBWRA, |
| 696 | op->data.nbytes), |
| 697 | aq, QSPI_WRACNT); |
| 698 | } |
| 699 | |
| 700 | atmel_qspi_write(ifr, aq, QSPI_IFR); |
| 701 | |
| 702 | return atmel_qspi_update_config(aq); |
| 703 | } |
| 704 | |
| 705 | static int atmel_qspi_sama7g5_transfer(struct atmel_qspi *aq, |
| 706 | const struct spi_mem_op *op, u32 offset) |
| 707 | { |
| 708 | int err; |
| 709 | u32 val; |
| 710 | |
| 711 | if (!op->data.nbytes) { |
| 712 | /* Start the transfer. */ |
| 713 | err = atmel_qspi_reg_sync(aq); |
| 714 | if (err) |
| 715 | return err; |
| 716 | atmel_qspi_write(QSPI_CR_STTFR, aq, QSPI_CR); |
| 717 | |
| 718 | return readl_poll_timeout(aq->regs + QSPI_SR, val, |
| 719 | val & QSPI_SR_CSRA, |
| 720 | ATMEL_QSPI_TIMEOUT); |
| 721 | } |
| 722 | |
| 723 | /* Send/Receive data. */ |
| 724 | if (op->data.dir == SPI_MEM_DATA_IN) { |
| 725 | memcpy_fromio(op->data.buf.in, aq->mem + offset, |
| 726 | op->data.nbytes); |
| 727 | |
| 728 | if (op->addr.nbytes) { |
| 729 | err = readl_poll_timeout(aq->regs + QSPI_SR2, val, |
| 730 | !(val & QSPI_SR2_RBUSY), |
| 731 | ATMEL_QSPI_SYNC_TIMEOUT); |
| 732 | if (err) |
| 733 | return err; |
| 734 | } |
| 735 | } else { |
| 736 | memcpy_toio(aq->mem + offset, op->data.buf.out, |
| 737 | op->data.nbytes); |
| 738 | |
| 739 | err = readl_poll_timeout(aq->regs + QSPI_SR, val, |
| 740 | val & QSPI_SR_LWRA, |
| 741 | ATMEL_QSPI_TIMEOUT); |
| 742 | if (err) |
| 743 | return err; |
| 744 | } |
| 745 | |
| 746 | /* Release the chip-select. */ |
| 747 | err = atmel_qspi_reg_sync(aq); |
| 748 | if (err) |
| 749 | return err; |
| 750 | atmel_qspi_write(QSPI_CR_LASTXFER, aq, QSPI_CR); |
| 751 | |
| 752 | return readl_poll_timeout(aq->regs + QSPI_SR, val, val & QSPI_SR_CSRA, |
| 753 | ATMEL_QSPI_TIMEOUT); |
| 754 | } |
| 755 | |
| 756 | static int atmel_qspi_exec_op(struct spi_slave *slave, |
| 757 | const struct spi_mem_op *op) |
| 758 | { |
| 759 | struct atmel_qspi *aq = dev_get_priv(slave->dev->parent); |
| 760 | u32 offset; |
| 761 | int err; |
| 762 | |
| 763 | /* |
| 764 | * Check if the address exceeds the MMIO window size. An improvement |
| 765 | * would be to add support for regular SPI mode and fall back to it |
| 766 | * when the flash memories overrun the controller's memory space. |
| 767 | */ |
| 768 | if (op->addr.val + op->data.nbytes > aq->mmap_size) |
| 769 | return -ENOTSUPP; |
| 770 | |
| 771 | if (op->addr.nbytes > 4) |
| 772 | return -EOPNOTSUPP; |
| 773 | |
| 774 | err = aq->ops->set_cfg(aq, op, &offset); |
| 775 | if (err) |
| 776 | return err; |
| 777 | |
| 778 | return aq->ops->transfer(aq, op, offset); |
| 779 | } |
| 780 | |
| 781 | static int atmel_qspi_set_pad_calibration(struct udevice *bus, uint hz) |
| 782 | { |
| 783 | struct atmel_qspi *aq = dev_get_priv(bus); |
| 784 | u32 status, val; |
| 785 | int i, ret; |
| 786 | u8 pclk_div = 0; |
| 787 | |
| 788 | for (i = 0; i < ATMEL_QSPI_PCAL_ARRAY_SIZE; i++) { |
| 789 | if (aq->bus_clk_rate <= pcal[i].pclk_rate) { |
| 790 | pclk_div = pcal[i].pclk_div; |
| 791 | break; |
| 792 | } |
| 793 | } |
| 794 | |
| 795 | /* |
| 796 | * Use the biggest divider in case the peripheral clock exceeds |
| 797 | * 200MHZ. |
| 798 | */ |
| 799 | if (aq->bus_clk_rate > pcal[ATMEL_QSPI_PCAL_ARRAY_SIZE - 1].pclk_rate) |
| 800 | pclk_div = pcal[ATMEL_QSPI_PCAL_ARRAY_SIZE - 1].pclk_div; |
| 801 | |
| 802 | /* Disable QSPI while configuring the pad calibration. */ |
| 803 | status = atmel_qspi_read(aq, QSPI_SR2); |
| 804 | if (status & QSPI_SR2_QSPIENS) { |
| 805 | ret = atmel_qspi_reg_sync(aq); |
| 806 | if (ret) |
| 807 | return ret; |
| 808 | atmel_qspi_write(QSPI_CR_QSPIDIS, aq, QSPI_CR); |
| 809 | } |
| 810 | |
| 811 | /* |
| 812 | * The analog circuitry is not shut down at the end of the calibration |
| 813 | * and the start-up time is only required for the first calibration |
| 814 | * sequence, thus increasing performance. Set the delay between the Pad |
| 815 | * calibration analog circuitry and the calibration request to 2us. |
| 816 | */ |
| 817 | atmel_qspi_write(QSPI_PCALCFG_AAON | |
| 818 | FIELD_PREP(QSPI_PCALCFG_CLKDIV, pclk_div) | |
| 819 | FIELD_PREP(QSPI_PCALCFG_CALCNT, |
| 820 | 2 * (aq->bus_clk_rate / 1000000)), |
| 821 | aq, QSPI_PCALCFG); |
| 822 | |
| 823 | /* DLL On + start calibration. */ |
| 824 | atmel_qspi_write(QSPI_CR_DLLON | QSPI_CR_STPCAL, aq, QSPI_CR); |
| 825 | ret = readl_poll_timeout(aq->regs + QSPI_SR2, val, |
| 826 | (val & QSPI_SR2_DLOCK) && |
| 827 | !(val & QSPI_SR2_CALBSY), |
| 828 | ATMEL_QSPI_TIMEOUT); |
| 829 | |
| 830 | /* Refresh analogic blocks every 1 ms.*/ |
| 831 | atmel_qspi_write(FIELD_PREP(QSPI_REFRESH_DELAY_COUNTER, hz / 1000), |
| 832 | aq, QSPI_REFRESH); |
| 833 | |
| 834 | return ret; |
| 835 | } |
| 836 | |
| 837 | static int atmel_qspi_set_gclk(struct udevice *bus, uint hz) |
| 838 | { |
| 839 | struct atmel_qspi *aq = dev_get_priv(bus); |
| 840 | struct clk gclk; |
| 841 | u32 status, val; |
| 842 | int ret; |
| 843 | |
| 844 | /* Disable DLL before setting GCLK */ |
| 845 | status = atmel_qspi_read(aq, QSPI_SR2); |
| 846 | if (status & QSPI_SR2_DLOCK) { |
| 847 | atmel_qspi_write(QSPI_CR_DLLOFF, aq, QSPI_CR); |
| 848 | ret = readl_poll_timeout(aq->regs + QSPI_SR2, val, |
| 849 | !(val & QSPI_SR2_DLOCK), |
| 850 | ATMEL_QSPI_TIMEOUT); |
| 851 | if (ret) |
| 852 | return ret; |
| 853 | } |
| 854 | |
| 855 | if (hz > QSPI_DLLCFG_THRESHOLD_FREQ) |
| 856 | atmel_qspi_write(QSPI_DLLCFG_RANGE, aq, QSPI_DLLCFG); |
| 857 | else |
| 858 | atmel_qspi_write(0, aq, QSPI_DLLCFG); |
| 859 | |
| 860 | ret = clk_get_by_name(bus, "gclk", &gclk); |
| 861 | if (ret) { |
| 862 | dev_err(bus, "Missing QSPI generic clock\n"); |
| 863 | return ret; |
| 864 | } |
| 865 | |
| 866 | ret = clk_disable(&gclk); |
| 867 | if (ret) |
| 868 | dev_err(bus, "Failed to disable QSPI generic clock\n"); |
| 869 | |
| 870 | ret = clk_set_rate(&gclk, hz); |
| 871 | if (ret < 0) { |
| 872 | dev_err(bus, "Failed to set generic clock rate.\n"); |
| 873 | return ret; |
| 874 | } |
| 875 | |
| 876 | ret = clk_enable(&gclk); |
| 877 | if (ret) |
| 878 | dev_err(bus, "Failed to enable QSPI generic clock\n"); |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 879 | |
| 880 | return ret; |
| 881 | } |
| 882 | |
| 883 | static int atmel_qspi_sama7g5_set_speed(struct udevice *bus, uint hz) |
| 884 | { |
| 885 | struct atmel_qspi *aq = dev_get_priv(bus); |
| 886 | u32 val; |
| 887 | int ret; |
| 888 | |
| 889 | ret = atmel_qspi_set_gclk(bus, hz); |
| 890 | if (ret) |
| 891 | return ret; |
| 892 | |
| 893 | if (aq->caps->octal) { |
| 894 | ret = atmel_qspi_set_pad_calibration(bus, hz); |
| 895 | if (ret) |
| 896 | return ret; |
| 897 | } else { |
| 898 | atmel_qspi_write(QSPI_CR_DLLON, aq, QSPI_CR); |
| 899 | ret = readl_poll_timeout(aq->regs + QSPI_SR2, val, |
| 900 | val & QSPI_SR2_DLOCK, |
| 901 | ATMEL_QSPI_TIMEOUT); |
| 902 | } |
| 903 | |
| 904 | /* Set the QSPI controller by default in Serial Memory Mode */ |
| 905 | atmel_qspi_write(QSPI_MR_SMM | QSPI_MR_DQSDLYEN, aq, QSPI_MR); |
| 906 | ret = atmel_qspi_update_config(aq); |
| 907 | if (ret) |
| 908 | return ret; |
| 909 | aq->mr = QSPI_MR_SMM; |
| 910 | |
| 911 | /* Enable the QSPI controller. */ |
| 912 | ret = atmel_qspi_reg_sync(aq); |
| 913 | if (ret) |
| 914 | return ret; |
| 915 | atmel_qspi_write(QSPI_CR_QSPIEN, aq, QSPI_CR); |
| 916 | ret = readl_poll_timeout(aq->regs + QSPI_SR2, val, |
| 917 | val & QSPI_SR2_QSPIENS, |
| 918 | ATMEL_QSPI_SYNC_TIMEOUT); |
| 919 | if (ret) |
| 920 | return ret; |
| 921 | |
| 922 | if (aq->caps->octal) |
| 923 | ret = readl_poll_timeout(aq->regs + QSPI_SR, val, |
| 924 | val & QSPI_SR_RFRSHD, |
| 925 | ATMEL_QSPI_TIMEOUT); |
| 926 | |
| 927 | atmel_qspi_write(FIELD_PREP(QSPI_TOUT_TCNTM, QSPI_TOUT_MAX), |
| 928 | aq, QSPI_TOUT); |
| 929 | |
| 930 | return ret; |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 931 | } |
| 932 | |
| 933 | static int atmel_qspi_set_speed(struct udevice *bus, uint hz) |
| 934 | { |
| 935 | struct atmel_qspi *aq = dev_get_priv(bus); |
| 936 | u32 scr, scbr, mask, new_value; |
| 937 | |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 938 | if (aq->caps->has_gclk) |
| 939 | return atmel_qspi_sama7g5_set_speed(bus, hz); |
| 940 | |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 941 | /* Compute the QSPI baudrate */ |
| 942 | scbr = DIV_ROUND_UP(aq->bus_clk_rate, hz); |
| 943 | if (scbr > 0) |
| 944 | scbr--; |
| 945 | |
| 946 | new_value = QSPI_SCR_SCBR(scbr); |
| 947 | mask = QSPI_SCR_SCBR_MASK; |
| 948 | |
Tudor Ambarus | f44d2e0 | 2020-03-20 09:37:59 +0000 | [diff] [blame] | 949 | scr = atmel_qspi_read(aq, QSPI_SCR); |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 950 | if ((scr & mask) == new_value) |
| 951 | return 0; |
| 952 | |
| 953 | scr = (scr & ~mask) | new_value; |
Tudor Ambarus | f44d2e0 | 2020-03-20 09:37:59 +0000 | [diff] [blame] | 954 | atmel_qspi_write(scr, aq, QSPI_SCR); |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 955 | |
| 956 | return 0; |
| 957 | } |
| 958 | |
| 959 | static int atmel_qspi_set_mode(struct udevice *bus, uint mode) |
| 960 | { |
| 961 | struct atmel_qspi *aq = dev_get_priv(bus); |
| 962 | u32 scr, mask, new_value = 0; |
| 963 | |
| 964 | if (mode & SPI_CPOL) |
| 965 | new_value = QSPI_SCR_CPOL; |
| 966 | if (mode & SPI_CPHA) |
| 967 | new_value = QSPI_SCR_CPHA; |
| 968 | |
| 969 | mask = QSPI_SCR_CPOL | QSPI_SCR_CPHA; |
| 970 | |
Tudor Ambarus | f44d2e0 | 2020-03-20 09:37:59 +0000 | [diff] [blame] | 971 | scr = atmel_qspi_read(aq, QSPI_SCR); |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 972 | if ((scr & mask) == new_value) |
| 973 | return 0; |
| 974 | |
| 975 | scr = (scr & ~mask) | new_value; |
Tudor Ambarus | f44d2e0 | 2020-03-20 09:37:59 +0000 | [diff] [blame] | 976 | atmel_qspi_write(scr, aq, QSPI_SCR); |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 977 | if (aq->caps->has_gclk) |
| 978 | return atmel_qspi_update_config(aq); |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 979 | |
| 980 | return 0; |
| 981 | } |
| 982 | |
| 983 | static int atmel_qspi_enable_clk(struct udevice *dev) |
| 984 | { |
| 985 | struct atmel_qspi *aq = dev_get_priv(dev); |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 986 | struct clk pclk, qspick, gclk; |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 987 | int ret; |
| 988 | |
| 989 | ret = clk_get_by_name(dev, "pclk", &pclk); |
| 990 | if (ret) |
| 991 | ret = clk_get_by_index(dev, 0, &pclk); |
| 992 | |
| 993 | if (ret) { |
| 994 | dev_err(dev, "Missing QSPI peripheral clock\n"); |
| 995 | return ret; |
| 996 | } |
| 997 | |
| 998 | ret = clk_enable(&pclk); |
| 999 | if (ret) { |
| 1000 | dev_err(dev, "Failed to enable QSPI peripheral clock\n"); |
Sean Anderson | d318eb3 | 2023-12-16 14:38:42 -0500 | [diff] [blame] | 1001 | return ret; |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 1002 | } |
| 1003 | |
| 1004 | if (aq->caps->has_qspick) { |
| 1005 | /* Get the QSPI system clock */ |
| 1006 | ret = clk_get_by_name(dev, "qspick", &qspick); |
| 1007 | if (ret) { |
| 1008 | dev_err(dev, "Missing QSPI peripheral clock\n"); |
Sean Anderson | d318eb3 | 2023-12-16 14:38:42 -0500 | [diff] [blame] | 1009 | return ret; |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 1010 | } |
| 1011 | |
| 1012 | ret = clk_enable(&qspick); |
| 1013 | if (ret) |
| 1014 | dev_err(dev, "Failed to enable QSPI system clock\n"); |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 1015 | } else if (aq->caps->has_gclk) { |
| 1016 | ret = clk_get_by_name(dev, "gclk", &gclk); |
| 1017 | if (ret) { |
| 1018 | dev_err(dev, "Missing QSPI generic clock\n"); |
Sean Anderson | d318eb3 | 2023-12-16 14:38:42 -0500 | [diff] [blame] | 1019 | return ret; |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 1020 | } |
| 1021 | |
| 1022 | ret = clk_enable(&gclk); |
| 1023 | if (ret) |
| 1024 | dev_err(dev, "Failed to enable QSPI system clock\n"); |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | aq->bus_clk_rate = clk_get_rate(&pclk); |
| 1028 | if (!aq->bus_clk_rate) |
Sean Anderson | d318eb3 | 2023-12-16 14:38:42 -0500 | [diff] [blame] | 1029 | return -EINVAL; |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 1030 | |
| 1031 | return ret; |
| 1032 | } |
| 1033 | |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 1034 | static int atmel_qspi_init(struct atmel_qspi *aq) |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 1035 | { |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 1036 | int ret; |
| 1037 | |
| 1038 | if (aq->caps->has_gclk) { |
| 1039 | ret = atmel_qspi_reg_sync(aq); |
| 1040 | if (ret) |
| 1041 | return ret; |
| 1042 | atmel_qspi_write(QSPI_CR_SWRST, aq, QSPI_CR); |
| 1043 | return 0; |
| 1044 | } |
| 1045 | |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 1046 | /* Reset the QSPI controller */ |
Tudor Ambarus | f44d2e0 | 2020-03-20 09:37:59 +0000 | [diff] [blame] | 1047 | atmel_qspi_write(QSPI_CR_SWRST, aq, QSPI_CR); |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 1048 | |
| 1049 | /* Set the QSPI controller by default in Serial Memory Mode */ |
Tudor Ambarus | f44d2e0 | 2020-03-20 09:37:59 +0000 | [diff] [blame] | 1050 | atmel_qspi_write(QSPI_MR_SMM, aq, QSPI_MR); |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 1051 | aq->mr = QSPI_MR_SMM; |
| 1052 | |
| 1053 | /* Enable the QSPI controller */ |
Tudor Ambarus | f44d2e0 | 2020-03-20 09:37:59 +0000 | [diff] [blame] | 1054 | atmel_qspi_write(QSPI_CR_QSPIEN, aq, QSPI_CR); |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 1055 | |
| 1056 | return 0; |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 1057 | } |
| 1058 | |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 1059 | static const struct atmel_qspi_priv_ops atmel_qspi_priv_ops = { |
| 1060 | .set_cfg = atmel_qspi_set_cfg, |
| 1061 | .transfer = atmel_qspi_transfer, |
| 1062 | }; |
| 1063 | |
| 1064 | static const struct atmel_qspi_priv_ops atmel_qspi_sama7g5_priv_ops = { |
| 1065 | .set_cfg = atmel_qspi_sama7g5_set_cfg, |
| 1066 | .transfer = atmel_qspi_sama7g5_transfer, |
| 1067 | }; |
| 1068 | |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 1069 | static int atmel_qspi_probe(struct udevice *dev) |
| 1070 | { |
| 1071 | struct atmel_qspi *aq = dev_get_priv(dev); |
| 1072 | struct resource res; |
| 1073 | int ret; |
| 1074 | |
| 1075 | aq->caps = (struct atmel_qspi_caps *)dev_get_driver_data(dev); |
| 1076 | if (!aq->caps) { |
| 1077 | dev_err(dev, "Could not retrieve QSPI caps\n"); |
| 1078 | return -EINVAL; |
| 1079 | }; |
| 1080 | |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 1081 | if (aq->caps->has_gclk) |
| 1082 | aq->ops = &atmel_qspi_sama7g5_priv_ops; |
| 1083 | else |
| 1084 | aq->ops = &atmel_qspi_priv_ops; |
| 1085 | |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 1086 | /* Map the registers */ |
| 1087 | ret = dev_read_resource_byname(dev, "qspi_base", &res); |
| 1088 | if (ret) { |
| 1089 | dev_err(dev, "missing registers\n"); |
| 1090 | return ret; |
| 1091 | } |
| 1092 | |
| 1093 | aq->regs = devm_ioremap(dev, res.start, resource_size(&res)); |
| 1094 | if (IS_ERR(aq->regs)) |
| 1095 | return PTR_ERR(aq->regs); |
| 1096 | |
| 1097 | /* Map the AHB memory */ |
| 1098 | ret = dev_read_resource_byname(dev, "qspi_mmap", &res); |
| 1099 | if (ret) { |
| 1100 | dev_err(dev, "missing AHB memory\n"); |
| 1101 | return ret; |
| 1102 | } |
| 1103 | |
| 1104 | aq->mem = devm_ioremap(dev, res.start, resource_size(&res)); |
| 1105 | if (IS_ERR(aq->mem)) |
| 1106 | return PTR_ERR(aq->mem); |
| 1107 | |
Tudor Ambarus | 678b893 | 2020-03-20 09:37:59 +0000 | [diff] [blame] | 1108 | aq->mmap_size = resource_size(&res); |
| 1109 | |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 1110 | ret = atmel_qspi_enable_clk(dev); |
| 1111 | if (ret) |
| 1112 | return ret; |
| 1113 | |
Tudor Ambarus | f44d2e0 | 2020-03-20 09:37:59 +0000 | [diff] [blame] | 1114 | aq->dev = dev; |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 1115 | return atmel_qspi_init(aq); |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 1116 | } |
| 1117 | |
| 1118 | static const struct spi_controller_mem_ops atmel_qspi_mem_ops = { |
| 1119 | .supports_op = atmel_qspi_supports_op, |
| 1120 | .exec_op = atmel_qspi_exec_op, |
| 1121 | }; |
| 1122 | |
| 1123 | static const struct dm_spi_ops atmel_qspi_ops = { |
| 1124 | .set_speed = atmel_qspi_set_speed, |
| 1125 | .set_mode = atmel_qspi_set_mode, |
| 1126 | .mem_ops = &atmel_qspi_mem_ops, |
| 1127 | }; |
| 1128 | |
| 1129 | static const struct atmel_qspi_caps atmel_sama5d2_qspi_caps = {}; |
| 1130 | |
| 1131 | static const struct atmel_qspi_caps atmel_sam9x60_qspi_caps = { |
| 1132 | .has_qspick = true, |
| 1133 | .has_ricr = true, |
| 1134 | }; |
| 1135 | |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 1136 | static const struct atmel_qspi_caps atmel_sama7g5_ospi_caps = { |
| 1137 | .has_gclk = true, |
| 1138 | .octal = true, |
| 1139 | }; |
| 1140 | |
| 1141 | static const struct atmel_qspi_caps atmel_sama7g5_qspi_caps = { |
| 1142 | .has_gclk = true, |
| 1143 | }; |
| 1144 | |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 1145 | static const struct udevice_id atmel_qspi_ids[] = { |
| 1146 | { |
| 1147 | .compatible = "atmel,sama5d2-qspi", |
| 1148 | .data = (ulong)&atmel_sama5d2_qspi_caps, |
| 1149 | }, |
| 1150 | { |
| 1151 | .compatible = "microchip,sam9x60-qspi", |
| 1152 | .data = (ulong)&atmel_sam9x60_qspi_caps, |
| 1153 | }, |
Tudor Ambarus | 8e4f44b | 2021-11-03 18:47:10 +0200 | [diff] [blame] | 1154 | { |
| 1155 | .compatible = "microchip,sama7g5-ospi", |
| 1156 | .data = (ulong)&atmel_sama7g5_ospi_caps, |
| 1157 | }, |
| 1158 | { |
| 1159 | .compatible = "microchip,sama7g5-qspi", |
| 1160 | .data = (ulong)&atmel_sama7g5_qspi_caps, |
| 1161 | }, |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 1162 | { /* sentinel */ } |
| 1163 | }; |
| 1164 | |
| 1165 | U_BOOT_DRIVER(atmel_qspi) = { |
| 1166 | .name = "atmel_qspi", |
| 1167 | .id = UCLASS_SPI, |
| 1168 | .of_match = atmel_qspi_ids, |
| 1169 | .ops = &atmel_qspi_ops, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 1170 | .priv_auto = sizeof(struct atmel_qspi), |
Tudor Ambarus | 88151bb | 2019-06-18 08:51:50 +0000 | [diff] [blame] | 1171 | .probe = atmel_qspi_probe, |
| 1172 | }; |