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