Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Vikas Manocha | bf1ae44 | 2017-04-10 15:02:51 -0700 | [diff] [blame] | 2 | /* |
Patrice Chotard | 3bc599c | 2017-10-23 09:53:58 +0200 | [diff] [blame] | 3 | * Copyright (C) 2017, STMicroelectronics - All Rights Reserved |
| 4 | * Author(s): Vikas Manocha, <vikas.manocha@st.com> for STMicroelectronics. |
Vikas Manocha | bf1ae44 | 2017-04-10 15:02:51 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Vikas Manocha | d0b24c1 | 2017-04-10 15:02:55 -0700 | [diff] [blame] | 8 | #include <clk.h> |
Vikas Manocha | 910a52e | 2017-04-10 15:02:52 -0700 | [diff] [blame] | 9 | #include <dm.h> |
Simon Glass | 691d719 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 10 | #include <init.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Vikas Manocha | 910a52e | 2017-04-10 15:02:52 -0700 | [diff] [blame] | 12 | #include <ram.h> |
Vikas Manocha | bf1ae44 | 2017-04-10 15:02:51 -0700 | [diff] [blame] | 13 | #include <asm/io.h> |
Simon Glass | 336d461 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 14 | #include <dm/device_compat.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 15 | #include <linux/bitops.h> |
Simon Glass | c05ed00 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 16 | #include <linux/delay.h> |
Vikas Manocha | bf1ae44 | 2017-04-10 15:02:51 -0700 | [diff] [blame] | 17 | |
Patrice Chotard | 0b3f789 | 2017-12-12 09:49:41 +0100 | [diff] [blame] | 18 | #define MEM_MODE_MASK GENMASK(2, 0) |
Radoslaw Pietrzyk | 246a5e5 | 2018-05-16 17:27:11 +0200 | [diff] [blame] | 19 | #define SWP_FMC_OFFSET 10 |
| 20 | #define SWP_FMC_MASK GENMASK(SWP_FMC_OFFSET+1, SWP_FMC_OFFSET) |
Patrice Chotard | 0b3f789 | 2017-12-12 09:49:41 +0100 | [diff] [blame] | 21 | #define NOT_FOUND 0xff |
| 22 | |
Patrice Chotard | 9242ece | 2017-07-18 17:37:24 +0200 | [diff] [blame] | 23 | struct stm32_fmc_regs { |
Patrice Chotard | 1421e0a | 2017-07-18 17:37:25 +0200 | [diff] [blame] | 24 | /* 0x0 */ |
| 25 | u32 bcr1; /* NOR/PSRAM Chip select control register 1 */ |
| 26 | u32 btr1; /* SRAM/NOR-Flash Chip select timing register 1 */ |
| 27 | u32 bcr2; /* NOR/PSRAM Chip select Control register 2 */ |
| 28 | u32 btr2; /* SRAM/NOR-Flash Chip select timing register 2 */ |
| 29 | u32 bcr3; /* NOR/PSRAMChip select Control register 3 */ |
| 30 | u32 btr3; /* SRAM/NOR-Flash Chip select timing register 3 */ |
| 31 | u32 bcr4; /* NOR/PSRAM Chip select Control register 4 */ |
| 32 | u32 btr4; /* SRAM/NOR-Flash Chip select timing register 4 */ |
| 33 | u32 reserved1[24]; |
Patrice Chotard | 9242ece | 2017-07-18 17:37:24 +0200 | [diff] [blame] | 34 | |
Patrice Chotard | 1421e0a | 2017-07-18 17:37:25 +0200 | [diff] [blame] | 35 | /* 0x80 */ |
| 36 | u32 pcr; /* NAND Flash control register */ |
| 37 | u32 sr; /* FIFO status and interrupt register */ |
| 38 | u32 pmem; /* Common memory space timing register */ |
| 39 | u32 patt; /* Attribute memory space timing registers */ |
| 40 | u32 reserved2[1]; |
| 41 | u32 eccr; /* ECC result registers */ |
| 42 | u32 reserved3[27]; |
| 43 | |
| 44 | /* 0x104 */ |
| 45 | u32 bwtr1; /* SRAM/NOR-Flash write timing register 1 */ |
| 46 | u32 reserved4[1]; |
| 47 | u32 bwtr2; /* SRAM/NOR-Flash write timing register 2 */ |
| 48 | u32 reserved5[1]; |
| 49 | u32 bwtr3; /* SRAM/NOR-Flash write timing register 3 */ |
| 50 | u32 reserved6[1]; |
| 51 | u32 bwtr4; /* SRAM/NOR-Flash write timing register 4 */ |
| 52 | u32 reserved7[8]; |
| 53 | |
| 54 | /* 0x140 */ |
| 55 | u32 sdcr1; /* SDRAM Control register 1 */ |
| 56 | u32 sdcr2; /* SDRAM Control register 2 */ |
| 57 | u32 sdtr1; /* SDRAM Timing register 1 */ |
| 58 | u32 sdtr2; /* SDRAM Timing register 2 */ |
| 59 | u32 sdcmr; /* SDRAM Mode register */ |
| 60 | u32 sdrtr; /* SDRAM Refresh timing register */ |
| 61 | u32 sdsr; /* SDRAM Status register */ |
| 62 | }; |
Patrice Chotard | 9242ece | 2017-07-18 17:37:24 +0200 | [diff] [blame] | 63 | |
Patrice Chotard | 7016651 | 2017-07-18 17:37:29 +0200 | [diff] [blame] | 64 | /* |
| 65 | * NOR/PSRAM Control register BCR1 |
| 66 | * FMC controller Enable, only availabe for H7 |
| 67 | */ |
| 68 | #define FMC_BCR1_FMCEN BIT(31) |
| 69 | |
Patrice Chotard | 9242ece | 2017-07-18 17:37:24 +0200 | [diff] [blame] | 70 | /* Control register SDCR */ |
| 71 | #define FMC_SDCR_RPIPE_SHIFT 13 /* RPIPE bit shift */ |
| 72 | #define FMC_SDCR_RBURST_SHIFT 12 /* RBURST bit shift */ |
| 73 | #define FMC_SDCR_SDCLK_SHIFT 10 /* SDRAM clock divisor shift */ |
| 74 | #define FMC_SDCR_WP_SHIFT 9 /* Write protection shift */ |
| 75 | #define FMC_SDCR_CAS_SHIFT 7 /* CAS latency shift */ |
| 76 | #define FMC_SDCR_NB_SHIFT 6 /* Number of banks shift */ |
| 77 | #define FMC_SDCR_MWID_SHIFT 4 /* Memory width shift */ |
| 78 | #define FMC_SDCR_NR_SHIFT 2 /* Number of row address bits shift */ |
| 79 | #define FMC_SDCR_NC_SHIFT 0 /* Number of col address bits shift */ |
| 80 | |
| 81 | /* Timings register SDTR */ |
| 82 | #define FMC_SDTR_TMRD_SHIFT 0 /* Load mode register to active */ |
| 83 | #define FMC_SDTR_TXSR_SHIFT 4 /* Exit self-refresh time */ |
| 84 | #define FMC_SDTR_TRAS_SHIFT 8 /* Self-refresh time */ |
| 85 | #define FMC_SDTR_TRC_SHIFT 12 /* Row cycle delay */ |
| 86 | #define FMC_SDTR_TWR_SHIFT 16 /* Recovery delay */ |
| 87 | #define FMC_SDTR_TRP_SHIFT 20 /* Row precharge delay */ |
| 88 | #define FMC_SDTR_TRCD_SHIFT 24 /* Row-to-column delay */ |
| 89 | |
| 90 | #define FMC_SDCMR_NRFS_SHIFT 5 |
| 91 | |
| 92 | #define FMC_SDCMR_MODE_NORMAL 0 |
| 93 | #define FMC_SDCMR_MODE_START_CLOCK 1 |
| 94 | #define FMC_SDCMR_MODE_PRECHARGE 2 |
| 95 | #define FMC_SDCMR_MODE_AUTOREFRESH 3 |
| 96 | #define FMC_SDCMR_MODE_WRITE_MODE 4 |
| 97 | #define FMC_SDCMR_MODE_SELFREFRESH 5 |
| 98 | #define FMC_SDCMR_MODE_POWERDOWN 6 |
| 99 | |
| 100 | #define FMC_SDCMR_BANK_1 BIT(4) |
| 101 | #define FMC_SDCMR_BANK_2 BIT(3) |
| 102 | |
| 103 | #define FMC_SDCMR_MODE_REGISTER_SHIFT 9 |
| 104 | |
| 105 | #define FMC_SDSR_BUSY BIT(5) |
| 106 | |
Patrice Chotard | 1421e0a | 2017-07-18 17:37:25 +0200 | [diff] [blame] | 107 | #define FMC_BUSY_WAIT(regs) do { \ |
Patrice Chotard | 9242ece | 2017-07-18 17:37:24 +0200 | [diff] [blame] | 108 | __asm__ __volatile__ ("dsb" : : : "memory"); \ |
Patrice Chotard | 1421e0a | 2017-07-18 17:37:25 +0200 | [diff] [blame] | 109 | while (regs->sdsr & FMC_SDSR_BUSY) \ |
Patrice Chotard | 9242ece | 2017-07-18 17:37:24 +0200 | [diff] [blame] | 110 | ; \ |
| 111 | } while (0) |
| 112 | |
Vikas Manocha | 6c9a100 | 2017-04-10 15:02:56 -0700 | [diff] [blame] | 113 | struct stm32_sdram_control { |
| 114 | u8 no_columns; |
| 115 | u8 no_rows; |
| 116 | u8 memory_width; |
| 117 | u8 no_banks; |
| 118 | u8 cas_latency; |
Vikas Manocha | bfea69a | 2017-04-10 15:03:03 -0700 | [diff] [blame] | 119 | u8 sdclk; |
Vikas Manocha | 6c9a100 | 2017-04-10 15:02:56 -0700 | [diff] [blame] | 120 | u8 rd_burst; |
| 121 | u8 rd_pipe_delay; |
| 122 | }; |
| 123 | |
| 124 | struct stm32_sdram_timing { |
| 125 | u8 tmrd; |
| 126 | u8 txsr; |
| 127 | u8 tras; |
| 128 | u8 trc; |
| 129 | u8 trp; |
Vikas Manocha | bfea69a | 2017-04-10 15:03:03 -0700 | [diff] [blame] | 130 | u8 twr; |
Vikas Manocha | 6c9a100 | 2017-04-10 15:02:56 -0700 | [diff] [blame] | 131 | u8 trcd; |
| 132 | }; |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 133 | enum stm32_fmc_bank { |
| 134 | SDRAM_BANK1, |
| 135 | SDRAM_BANK2, |
| 136 | MAX_SDRAM_BANK, |
| 137 | }; |
| 138 | |
Patrice Chotard | 7016651 | 2017-07-18 17:37:29 +0200 | [diff] [blame] | 139 | enum stm32_fmc_family { |
| 140 | STM32F7_FMC, |
| 141 | STM32H7_FMC, |
| 142 | }; |
| 143 | |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 144 | struct bank_params { |
Patrice Chotard | f39b90d | 2017-07-18 17:37:26 +0200 | [diff] [blame] | 145 | struct stm32_sdram_control *sdram_control; |
| 146 | struct stm32_sdram_timing *sdram_timing; |
Vikas Manocha | bfea69a | 2017-04-10 15:03:03 -0700 | [diff] [blame] | 147 | u32 sdram_ref_count; |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 148 | enum stm32_fmc_bank target_bank; |
| 149 | }; |
| 150 | |
| 151 | struct stm32_sdram_params { |
| 152 | struct stm32_fmc_regs *base; |
| 153 | u8 no_sdram_banks; |
| 154 | struct bank_params bank_params[MAX_SDRAM_BANK]; |
Patrice Chotard | 7016651 | 2017-07-18 17:37:29 +0200 | [diff] [blame] | 155 | enum stm32_fmc_family family; |
Vikas Manocha | 6c9a100 | 2017-04-10 15:02:56 -0700 | [diff] [blame] | 156 | }; |
Vikas Manocha | bf1ae44 | 2017-04-10 15:02:51 -0700 | [diff] [blame] | 157 | |
| 158 | #define SDRAM_MODE_BL_SHIFT 0 |
| 159 | #define SDRAM_MODE_CAS_SHIFT 4 |
| 160 | #define SDRAM_MODE_BL 0 |
Vikas Manocha | 6c9a100 | 2017-04-10 15:02:56 -0700 | [diff] [blame] | 161 | |
| 162 | int stm32_sdram_init(struct udevice *dev) |
Vikas Manocha | bf1ae44 | 2017-04-10 15:02:51 -0700 | [diff] [blame] | 163 | { |
Vikas Manocha | 6c9a100 | 2017-04-10 15:02:56 -0700 | [diff] [blame] | 164 | struct stm32_sdram_params *params = dev_get_platdata(dev); |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 165 | struct stm32_sdram_control *control; |
| 166 | struct stm32_sdram_timing *timing; |
Patrice Chotard | 1421e0a | 2017-07-18 17:37:25 +0200 | [diff] [blame] | 167 | struct stm32_fmc_regs *regs = params->base; |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 168 | enum stm32_fmc_bank target_bank; |
| 169 | u32 ctb; /* SDCMR register: Command Target Bank */ |
| 170 | u32 ref_count; |
| 171 | u8 i; |
Vikas Manocha | bf1ae44 | 2017-04-10 15:02:51 -0700 | [diff] [blame] | 172 | |
Patrice Chotard | 7016651 | 2017-07-18 17:37:29 +0200 | [diff] [blame] | 173 | /* disable the FMC controller */ |
| 174 | if (params->family == STM32H7_FMC) |
| 175 | clrbits_le32(®s->bcr1, FMC_BCR1_FMCEN); |
| 176 | |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 177 | for (i = 0; i < params->no_sdram_banks; i++) { |
| 178 | control = params->bank_params[i].sdram_control; |
| 179 | timing = params->bank_params[i].sdram_timing; |
| 180 | target_bank = params->bank_params[i].target_bank; |
| 181 | ref_count = params->bank_params[i].sdram_ref_count; |
Vikas Manocha | bf1ae44 | 2017-04-10 15:02:51 -0700 | [diff] [blame] | 182 | |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 183 | writel(control->sdclk << FMC_SDCR_SDCLK_SHIFT |
| 184 | | control->cas_latency << FMC_SDCR_CAS_SHIFT |
| 185 | | control->no_banks << FMC_SDCR_NB_SHIFT |
| 186 | | control->memory_width << FMC_SDCR_MWID_SHIFT |
| 187 | | control->no_rows << FMC_SDCR_NR_SHIFT |
| 188 | | control->no_columns << FMC_SDCR_NC_SHIFT |
| 189 | | control->rd_pipe_delay << FMC_SDCR_RPIPE_SHIFT |
| 190 | | control->rd_burst << FMC_SDCR_RBURST_SHIFT, |
| 191 | ®s->sdcr1); |
Vikas Manocha | bf1ae44 | 2017-04-10 15:02:51 -0700 | [diff] [blame] | 192 | |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 193 | if (target_bank == SDRAM_BANK2) |
| 194 | writel(control->cas_latency << FMC_SDCR_CAS_SHIFT |
| 195 | | control->no_banks << FMC_SDCR_NB_SHIFT |
| 196 | | control->memory_width << FMC_SDCR_MWID_SHIFT |
| 197 | | control->no_rows << FMC_SDCR_NR_SHIFT |
| 198 | | control->no_columns << FMC_SDCR_NC_SHIFT, |
| 199 | ®s->sdcr2); |
Vikas Manocha | bf1ae44 | 2017-04-10 15:02:51 -0700 | [diff] [blame] | 200 | |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 201 | writel(timing->trcd << FMC_SDTR_TRCD_SHIFT |
| 202 | | timing->trp << FMC_SDTR_TRP_SHIFT |
| 203 | | timing->twr << FMC_SDTR_TWR_SHIFT |
| 204 | | timing->trc << FMC_SDTR_TRC_SHIFT |
| 205 | | timing->tras << FMC_SDTR_TRAS_SHIFT |
| 206 | | timing->txsr << FMC_SDTR_TXSR_SHIFT |
| 207 | | timing->tmrd << FMC_SDTR_TMRD_SHIFT, |
| 208 | ®s->sdtr1); |
Vikas Manocha | bf1ae44 | 2017-04-10 15:02:51 -0700 | [diff] [blame] | 209 | |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 210 | if (target_bank == SDRAM_BANK2) |
| 211 | writel(timing->trcd << FMC_SDTR_TRCD_SHIFT |
| 212 | | timing->trp << FMC_SDTR_TRP_SHIFT |
| 213 | | timing->twr << FMC_SDTR_TWR_SHIFT |
| 214 | | timing->trc << FMC_SDTR_TRC_SHIFT |
| 215 | | timing->tras << FMC_SDTR_TRAS_SHIFT |
| 216 | | timing->txsr << FMC_SDTR_TXSR_SHIFT |
| 217 | | timing->tmrd << FMC_SDTR_TMRD_SHIFT, |
| 218 | ®s->sdtr2); |
Patrice Chotard | 7016651 | 2017-07-18 17:37:29 +0200 | [diff] [blame] | 219 | |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 220 | if (target_bank == SDRAM_BANK1) |
| 221 | ctb = FMC_SDCMR_BANK_1; |
| 222 | else |
| 223 | ctb = FMC_SDCMR_BANK_2; |
Vikas Manocha | bf1ae44 | 2017-04-10 15:02:51 -0700 | [diff] [blame] | 224 | |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 225 | writel(ctb | FMC_SDCMR_MODE_START_CLOCK, ®s->sdcmr); |
| 226 | udelay(200); /* 200 us delay, page 10, "Power-Up" */ |
| 227 | FMC_BUSY_WAIT(regs); |
Vikas Manocha | bf1ae44 | 2017-04-10 15:02:51 -0700 | [diff] [blame] | 228 | |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 229 | writel(ctb | FMC_SDCMR_MODE_PRECHARGE, ®s->sdcmr); |
| 230 | udelay(100); |
| 231 | FMC_BUSY_WAIT(regs); |
Vikas Manocha | bf1ae44 | 2017-04-10 15:02:51 -0700 | [diff] [blame] | 232 | |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 233 | writel((ctb | FMC_SDCMR_MODE_AUTOREFRESH | 7 << FMC_SDCMR_NRFS_SHIFT), |
| 234 | ®s->sdcmr); |
| 235 | udelay(100); |
| 236 | FMC_BUSY_WAIT(regs); |
| 237 | |
| 238 | writel(ctb | (SDRAM_MODE_BL << SDRAM_MODE_BL_SHIFT |
| 239 | | control->cas_latency << SDRAM_MODE_CAS_SHIFT) |
| 240 | << FMC_SDCMR_MODE_REGISTER_SHIFT | FMC_SDCMR_MODE_WRITE_MODE, |
| 241 | ®s->sdcmr); |
| 242 | udelay(100); |
| 243 | FMC_BUSY_WAIT(regs); |
| 244 | |
| 245 | writel(ctb | FMC_SDCMR_MODE_NORMAL, ®s->sdcmr); |
| 246 | FMC_BUSY_WAIT(regs); |
| 247 | |
| 248 | /* Refresh timer */ |
| 249 | writel(ref_count << 1, ®s->sdrtr); |
| 250 | } |
Vikas Manocha | bf1ae44 | 2017-04-10 15:02:51 -0700 | [diff] [blame] | 251 | |
Patrice Chotard | 7016651 | 2017-07-18 17:37:29 +0200 | [diff] [blame] | 252 | /* enable the FMC controller */ |
| 253 | if (params->family == STM32H7_FMC) |
| 254 | setbits_le32(®s->bcr1, FMC_BCR1_FMCEN); |
| 255 | |
Vikas Manocha | bf1ae44 | 2017-04-10 15:02:51 -0700 | [diff] [blame] | 256 | return 0; |
| 257 | } |
Vikas Manocha | 910a52e | 2017-04-10 15:02:52 -0700 | [diff] [blame] | 258 | |
Vikas Manocha | 6c9a100 | 2017-04-10 15:02:56 -0700 | [diff] [blame] | 259 | static int stm32_fmc_ofdata_to_platdata(struct udevice *dev) |
| 260 | { |
Vikas Manocha | 6c9a100 | 2017-04-10 15:02:56 -0700 | [diff] [blame] | 261 | struct stm32_sdram_params *params = dev_get_platdata(dev); |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 262 | struct bank_params *bank_params; |
Patrice Chotard | 0b3f789 | 2017-12-12 09:49:41 +0100 | [diff] [blame] | 263 | struct ofnode_phandle_args args; |
| 264 | u32 *syscfg_base; |
| 265 | u32 mem_remap; |
Radoslaw Pietrzyk | 246a5e5 | 2018-05-16 17:27:11 +0200 | [diff] [blame] | 266 | u32 swp_fmc; |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 267 | ofnode bank_node; |
| 268 | char *bank_name; |
| 269 | u8 bank = 0; |
Patrice Chotard | 0b3f789 | 2017-12-12 09:49:41 +0100 | [diff] [blame] | 270 | int ret; |
| 271 | |
Radoslaw Pietrzyk | 246a5e5 | 2018-05-16 17:27:11 +0200 | [diff] [blame] | 272 | ret = dev_read_phandle_with_args(dev, "st,syscfg", NULL, 0, 0, |
Patrice Chotard | 0b3f789 | 2017-12-12 09:49:41 +0100 | [diff] [blame] | 273 | &args); |
Radoslaw Pietrzyk | 246a5e5 | 2018-05-16 17:27:11 +0200 | [diff] [blame] | 274 | if (ret) { |
| 275 | dev_dbg(dev, "%s: can't find syscon device (%d)\n", __func__, ret); |
| 276 | } else { |
Patrice Chotard | 0b3f789 | 2017-12-12 09:49:41 +0100 | [diff] [blame] | 277 | syscfg_base = (u32 *)ofnode_get_addr(args.node); |
| 278 | |
Radoslaw Pietrzyk | 246a5e5 | 2018-05-16 17:27:11 +0200 | [diff] [blame] | 279 | mem_remap = dev_read_u32_default(dev, "st,mem_remap", NOT_FOUND); |
| 280 | if (mem_remap != NOT_FOUND) { |
| 281 | /* set memory mapping selection */ |
| 282 | clrsetbits_le32(syscfg_base, MEM_MODE_MASK, mem_remap); |
| 283 | } else { |
| 284 | dev_dbg(dev, "%s: cannot find st,mem_remap property\n", __func__); |
| 285 | } |
| 286 | |
| 287 | swp_fmc = dev_read_u32_default(dev, "st,swp_fmc", NOT_FOUND); |
| 288 | if (swp_fmc != NOT_FOUND) { |
| 289 | /* set fmc swapping selection */ |
| 290 | clrsetbits_le32(syscfg_base, SWP_FMC_MASK, swp_fmc << SWP_FMC_OFFSET); |
| 291 | } else { |
| 292 | dev_dbg(dev, "%s: cannot find st,swp_fmc property\n", __func__); |
| 293 | } |
| 294 | |
| 295 | dev_dbg(dev, "syscfg %x = %x\n", (u32)syscfg_base, *syscfg_base); |
Patrice Chotard | 0b3f789 | 2017-12-12 09:49:41 +0100 | [diff] [blame] | 296 | } |
Vikas Manocha | 6c9a100 | 2017-04-10 15:02:56 -0700 | [diff] [blame] | 297 | |
Patrice Chotard | f39b90d | 2017-07-18 17:37:26 +0200 | [diff] [blame] | 298 | dev_for_each_subnode(bank_node, dev) { |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 299 | /* extract the bank index from DT */ |
| 300 | bank_name = (char *)ofnode_get_name(bank_node); |
| 301 | strsep(&bank_name, "@"); |
| 302 | if (!bank_name) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 303 | pr_err("missing sdram bank index"); |
Patrice Chotard | f39b90d | 2017-07-18 17:37:26 +0200 | [diff] [blame] | 304 | return -EINVAL; |
| 305 | } |
| 306 | |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 307 | bank_params = ¶ms->bank_params[bank]; |
| 308 | strict_strtoul(bank_name, 10, |
| 309 | (long unsigned int *)&bank_params->target_bank); |
Patrice Chotard | f39b90d | 2017-07-18 17:37:26 +0200 | [diff] [blame] | 310 | |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 311 | if (bank_params->target_bank >= MAX_SDRAM_BANK) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 312 | pr_err("Found bank %d , but only bank 0 and 1 are supported", |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 313 | bank_params->target_bank); |
Patrice Chotard | f39b90d | 2017-07-18 17:37:26 +0200 | [diff] [blame] | 314 | return -EINVAL; |
| 315 | } |
| 316 | |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 317 | debug("Find bank %s %u\n", bank_name, bank_params->target_bank); |
| 318 | |
| 319 | params->bank_params[bank].sdram_control = |
| 320 | (struct stm32_sdram_control *) |
| 321 | ofnode_read_u8_array_ptr(bank_node, |
| 322 | "st,sdram-control", |
| 323 | sizeof(struct stm32_sdram_control)); |
| 324 | |
| 325 | if (!params->bank_params[bank].sdram_control) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 326 | pr_err("st,sdram-control not found for %s", |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 327 | ofnode_get_name(bank_node)); |
| 328 | return -EINVAL; |
| 329 | } |
| 330 | |
| 331 | |
| 332 | params->bank_params[bank].sdram_timing = |
| 333 | (struct stm32_sdram_timing *) |
| 334 | ofnode_read_u8_array_ptr(bank_node, |
| 335 | "st,sdram-timing", |
| 336 | sizeof(struct stm32_sdram_timing)); |
| 337 | |
| 338 | if (!params->bank_params[bank].sdram_timing) { |
Masahiro Yamada | 9b643e3 | 2017-09-16 14:10:41 +0900 | [diff] [blame] | 339 | pr_err("st,sdram-timing not found for %s", |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 340 | ofnode_get_name(bank_node)); |
| 341 | return -EINVAL; |
| 342 | } |
| 343 | |
| 344 | |
| 345 | bank_params->sdram_ref_count = ofnode_read_u32_default(bank_node, |
Vikas Manocha | bfea69a | 2017-04-10 15:03:03 -0700 | [diff] [blame] | 346 | "st,sdram-refcount", 8196); |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 347 | bank++; |
Vikas Manocha | 6c9a100 | 2017-04-10 15:02:56 -0700 | [diff] [blame] | 348 | } |
| 349 | |
Patrice Chotard | f303aaf | 2017-07-18 17:37:27 +0200 | [diff] [blame] | 350 | params->no_sdram_banks = bank; |
| 351 | debug("%s, no of banks = %d\n", __func__, params->no_sdram_banks); |
| 352 | |
Vikas Manocha | 6c9a100 | 2017-04-10 15:02:56 -0700 | [diff] [blame] | 353 | return 0; |
| 354 | } |
| 355 | |
Vikas Manocha | 910a52e | 2017-04-10 15:02:52 -0700 | [diff] [blame] | 356 | static int stm32_fmc_probe(struct udevice *dev) |
| 357 | { |
Patrice Chotard | 1421e0a | 2017-07-18 17:37:25 +0200 | [diff] [blame] | 358 | struct stm32_sdram_params *params = dev_get_platdata(dev); |
Vikas Manocha | d0b24c1 | 2017-04-10 15:02:55 -0700 | [diff] [blame] | 359 | int ret; |
Patrice Chotard | 1421e0a | 2017-07-18 17:37:25 +0200 | [diff] [blame] | 360 | fdt_addr_t addr; |
| 361 | |
| 362 | addr = dev_read_addr(dev); |
| 363 | if (addr == FDT_ADDR_T_NONE) |
| 364 | return -EINVAL; |
| 365 | |
| 366 | params->base = (struct stm32_fmc_regs *)addr; |
Patrice Chotard | 7016651 | 2017-07-18 17:37:29 +0200 | [diff] [blame] | 367 | params->family = dev_get_driver_data(dev); |
Patrice Chotard | 1421e0a | 2017-07-18 17:37:25 +0200 | [diff] [blame] | 368 | |
Patrice Chotard | 14a50e3 | 2017-05-30 15:06:31 +0200 | [diff] [blame] | 369 | #ifdef CONFIG_CLK |
Vikas Manocha | d0b24c1 | 2017-04-10 15:02:55 -0700 | [diff] [blame] | 370 | struct clk clk; |
Vikas Manocha | 6c9a100 | 2017-04-10 15:02:56 -0700 | [diff] [blame] | 371 | |
Vikas Manocha | d0b24c1 | 2017-04-10 15:02:55 -0700 | [diff] [blame] | 372 | ret = clk_get_by_index(dev, 0, &clk); |
| 373 | if (ret < 0) |
| 374 | return ret; |
| 375 | |
| 376 | ret = clk_enable(&clk); |
| 377 | |
| 378 | if (ret) { |
| 379 | dev_err(dev, "failed to enable clock\n"); |
| 380 | return ret; |
| 381 | } |
| 382 | #endif |
Vikas Manocha | 6c9a100 | 2017-04-10 15:02:56 -0700 | [diff] [blame] | 383 | ret = stm32_sdram_init(dev); |
| 384 | if (ret) |
| 385 | return ret; |
| 386 | |
Vikas Manocha | 910a52e | 2017-04-10 15:02:52 -0700 | [diff] [blame] | 387 | return 0; |
| 388 | } |
| 389 | |
| 390 | static int stm32_fmc_get_info(struct udevice *dev, struct ram_info *info) |
| 391 | { |
Vikas Manocha | 910a52e | 2017-04-10 15:02:52 -0700 | [diff] [blame] | 392 | return 0; |
| 393 | } |
| 394 | |
| 395 | static struct ram_ops stm32_fmc_ops = { |
| 396 | .get_info = stm32_fmc_get_info, |
| 397 | }; |
| 398 | |
| 399 | static const struct udevice_id stm32_fmc_ids[] = { |
Patrice Chotard | 7016651 | 2017-07-18 17:37:29 +0200 | [diff] [blame] | 400 | { .compatible = "st,stm32-fmc", .data = STM32F7_FMC }, |
| 401 | { .compatible = "st,stm32h7-fmc", .data = STM32H7_FMC }, |
Vikas Manocha | 910a52e | 2017-04-10 15:02:52 -0700 | [diff] [blame] | 402 | { } |
| 403 | }; |
| 404 | |
| 405 | U_BOOT_DRIVER(stm32_fmc) = { |
| 406 | .name = "stm32_fmc", |
| 407 | .id = UCLASS_RAM, |
| 408 | .of_match = stm32_fmc_ids, |
| 409 | .ops = &stm32_fmc_ops, |
Vikas Manocha | 6c9a100 | 2017-04-10 15:02:56 -0700 | [diff] [blame] | 410 | .ofdata_to_platdata = stm32_fmc_ofdata_to_platdata, |
Vikas Manocha | 910a52e | 2017-04-10 15:02:52 -0700 | [diff] [blame] | 411 | .probe = stm32_fmc_probe, |
Simon Glass | caa4daa | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 412 | .plat_auto = sizeof(struct stm32_sdram_params), |
Vikas Manocha | 910a52e | 2017-04-10 15:02:52 -0700 | [diff] [blame] | 413 | }; |