Tom Rini | 8b0c8a1 | 2018-05-06 18:27:01 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2018, STMicroelectronics - All Rights Reserved |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 4 | */ |
| 5 | |
Patrick Delaunay | 753f536 | 2020-11-06 19:01:36 +0100 | [diff] [blame] | 6 | #define LOG_CATEGORY UCLASS_RAM |
| 7 | |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 8 | #include <common.h> |
| 9 | #include <clk.h> |
| 10 | #include <dm.h> |
Simon Glass | 8e16b1e | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 11 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 13 | #include <ram.h> |
| 14 | #include <regmap.h> |
| 15 | #include <syscon.h> |
| 16 | #include <asm/io.h> |
Patrick Delaunay | 753f536 | 2020-11-06 19:01:36 +0100 | [diff] [blame] | 17 | #include <dm/device_compat.h> |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 18 | #include "stm32mp1_ddr.h" |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 19 | #include "stm32mp1_ddr_regs.h" |
| 20 | |
| 21 | /* DDR subsystem configuration */ |
| 22 | struct stm32mp1_ddr_cfg { |
| 23 | u8 nb_bytes; /* MEMC_DRAM_DATA_WIDTH */ |
| 24 | }; |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 25 | |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 26 | static const char *const clkname[] = { |
| 27 | "ddrc1", |
| 28 | "ddrc2", |
| 29 | "ddrcapb", |
| 30 | "ddrphycapb", |
| 31 | "ddrphyc" /* LAST clock => used for get_rate() */ |
| 32 | }; |
| 33 | |
Patrick Delaunay | 29e1a94 | 2019-04-10 14:09:23 +0200 | [diff] [blame] | 34 | int stm32mp1_ddr_clk_enable(struct ddr_info *priv, uint32_t mem_speed) |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 35 | { |
| 36 | unsigned long ddrphy_clk; |
| 37 | unsigned long ddr_clk; |
| 38 | struct clk clk; |
| 39 | int ret; |
Patrick Delaunay | 6abbd35 | 2019-06-21 15:26:51 +0200 | [diff] [blame] | 40 | unsigned int idx; |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 41 | |
| 42 | for (idx = 0; idx < ARRAY_SIZE(clkname); idx++) { |
| 43 | ret = clk_get_by_name(priv->dev, clkname[idx], &clk); |
| 44 | |
| 45 | if (!ret) |
| 46 | ret = clk_enable(&clk); |
| 47 | |
| 48 | if (ret) { |
Patrick Delaunay | 753f536 | 2020-11-06 19:01:36 +0100 | [diff] [blame] | 49 | log_err("error for %s : %d\n", clkname[idx], ret); |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 50 | return ret; |
| 51 | } |
| 52 | } |
| 53 | |
| 54 | priv->clk = clk; |
| 55 | ddrphy_clk = clk_get_rate(&priv->clk); |
| 56 | |
Patrick Delaunay | 753f536 | 2020-11-06 19:01:36 +0100 | [diff] [blame] | 57 | log_debug("DDR: mem_speed (%d kHz), RCC %d kHz\n", |
| 58 | mem_speed, (u32)(ddrphy_clk / 1000)); |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 59 | /* max 10% frequency delta */ |
Patrick Delaunay | 29e1a94 | 2019-04-10 14:09:23 +0200 | [diff] [blame] | 60 | ddr_clk = abs(ddrphy_clk - mem_speed * 1000); |
| 61 | if (ddr_clk > (mem_speed * 100)) { |
Patrick Delaunay | 753f536 | 2020-11-06 19:01:36 +0100 | [diff] [blame] | 62 | log_err("DDR expected freq %d kHz, current is %d kHz\n", |
| 63 | mem_speed, (u32)(ddrphy_clk / 1000)); |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 64 | return -EINVAL; |
| 65 | } |
| 66 | |
| 67 | return 0; |
| 68 | } |
| 69 | |
Marek Vasut | 697887a | 2020-04-22 13:18:12 +0200 | [diff] [blame] | 70 | __weak int board_stm32mp1_ddr_config_name_match(struct udevice *dev, |
| 71 | const char *name) |
| 72 | { |
| 73 | return 0; /* Always match */ |
| 74 | } |
| 75 | |
| 76 | static ofnode stm32mp1_ddr_get_ofnode(struct udevice *dev) |
| 77 | { |
| 78 | const char *name; |
| 79 | ofnode node; |
| 80 | |
| 81 | dev_for_each_subnode(node, dev) { |
| 82 | name = ofnode_get_property(node, "compatible", NULL); |
| 83 | |
| 84 | if (!board_stm32mp1_ddr_config_name_match(dev, name)) |
| 85 | return node; |
| 86 | } |
| 87 | |
| 88 | return dev_ofnode(dev); |
| 89 | } |
| 90 | |
Patrick Delaunay | 915bd1a | 2021-11-24 10:52:19 +0100 | [diff] [blame] | 91 | static int stm32mp1_ddr_setup(struct udevice *dev) |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 92 | { |
| 93 | struct ddr_info *priv = dev_get_priv(dev); |
Patrick Delaunay | 6abbd35 | 2019-06-21 15:26:51 +0200 | [diff] [blame] | 94 | int ret; |
| 95 | unsigned int idx; |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 96 | struct clk axidcg; |
| 97 | struct stm32mp1_ddr_config config; |
Marek Vasut | 697887a | 2020-04-22 13:18:12 +0200 | [diff] [blame] | 98 | ofnode node = stm32mp1_ddr_get_ofnode(dev); |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 99 | |
Patrick Delaunay | a68e2d6 | 2020-03-06 11:14:11 +0100 | [diff] [blame] | 100 | #define PARAM(x, y, z) \ |
| 101 | { .name = x, \ |
| 102 | .offset = offsetof(struct stm32mp1_ddr_config, y), \ |
| 103 | .size = sizeof(config.y) / sizeof(u32), \ |
Patrick Delaunay | a68e2d6 | 2020-03-06 11:14:11 +0100 | [diff] [blame] | 104 | } |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 105 | |
Patrick Delaunay | a68e2d6 | 2020-03-06 11:14:11 +0100 | [diff] [blame] | 106 | #define CTL_PARAM(x) PARAM("st,ctl-"#x, c_##x, NULL) |
| 107 | #define PHY_PARAM(x) PARAM("st,phy-"#x, p_##x, NULL) |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 108 | |
| 109 | const struct { |
| 110 | const char *name; /* name in DT */ |
| 111 | const u32 offset; /* offset in config struct */ |
| 112 | const u32 size; /* size of parameters */ |
| 113 | } param[] = { |
| 114 | CTL_PARAM(reg), |
| 115 | CTL_PARAM(timing), |
| 116 | CTL_PARAM(map), |
| 117 | CTL_PARAM(perf), |
| 118 | PHY_PARAM(reg), |
Patrick Delaunay | 9e2dd66 | 2021-11-15 15:32:29 +0100 | [diff] [blame] | 119 | PHY_PARAM(timing) |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 120 | }; |
| 121 | |
Marek Vasut | 697887a | 2020-04-22 13:18:12 +0200 | [diff] [blame] | 122 | config.info.speed = ofnode_read_u32_default(node, "st,mem-speed", 0); |
| 123 | config.info.size = ofnode_read_u32_default(node, "st,mem-size", 0); |
| 124 | config.info.name = ofnode_read_string(node, "st,mem-name"); |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 125 | if (!config.info.name) { |
Patrick Delaunay | 753f536 | 2020-11-06 19:01:36 +0100 | [diff] [blame] | 126 | dev_dbg(dev, "no st,mem-name\n"); |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 127 | return -EINVAL; |
| 128 | } |
| 129 | printf("RAM: %s\n", config.info.name); |
| 130 | |
| 131 | for (idx = 0; idx < ARRAY_SIZE(param); idx++) { |
Marek Vasut | 697887a | 2020-04-22 13:18:12 +0200 | [diff] [blame] | 132 | ret = ofnode_read_u32_array(node, param[idx].name, |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 133 | (void *)((u32)&config + |
| 134 | param[idx].offset), |
| 135 | param[idx].size); |
Patrick Delaunay | 753f536 | 2020-11-06 19:01:36 +0100 | [diff] [blame] | 136 | dev_dbg(dev, "%s: %s[0x%x] = %d\n", __func__, |
| 137 | param[idx].name, param[idx].size, ret); |
Patrick Delaunay | 9e2dd66 | 2021-11-15 15:32:29 +0100 | [diff] [blame] | 138 | if (ret) { |
Patrick Delaunay | 753f536 | 2020-11-06 19:01:36 +0100 | [diff] [blame] | 139 | dev_err(dev, "Cannot read %s, error=%d\n", |
| 140 | param[idx].name, ret); |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 141 | return -EINVAL; |
| 142 | } |
| 143 | } |
| 144 | |
| 145 | ret = clk_get_by_name(dev, "axidcg", &axidcg); |
| 146 | if (ret) { |
Patrick Delaunay | 753f536 | 2020-11-06 19:01:36 +0100 | [diff] [blame] | 147 | dev_dbg(dev, "%s: Cannot found axidcg\n", __func__); |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 148 | return -EINVAL; |
| 149 | } |
| 150 | clk_disable(&axidcg); /* disable clock gating during init */ |
| 151 | |
| 152 | stm32mp1_ddr_init(priv, &config); |
| 153 | |
| 154 | clk_enable(&axidcg); /* enable clock gating */ |
| 155 | |
| 156 | /* check size */ |
Patrick Delaunay | 753f536 | 2020-11-06 19:01:36 +0100 | [diff] [blame] | 157 | dev_dbg(dev, "get_ram_size(%x, %x)\n", |
| 158 | (u32)priv->info.base, (u32)STM32_DDR_SIZE); |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 159 | |
| 160 | priv->info.size = get_ram_size((long *)priv->info.base, |
| 161 | STM32_DDR_SIZE); |
| 162 | |
Patrick Delaunay | 753f536 | 2020-11-06 19:01:36 +0100 | [diff] [blame] | 163 | dev_dbg(dev, "info.size: %x\n", (u32)priv->info.size); |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 164 | |
| 165 | /* check memory access for all memory */ |
| 166 | if (config.info.size != priv->info.size) { |
| 167 | printf("DDR invalid size : 0x%x, expected 0x%x\n", |
| 168 | priv->info.size, config.info.size); |
| 169 | return -EINVAL; |
| 170 | } |
| 171 | return 0; |
| 172 | } |
| 173 | |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 174 | static u8 get_data_bus_width(struct stm32mp1_ddrctl *ctl) |
| 175 | { |
| 176 | u32 reg = readl(&ctl->mstr) & DDRCTRL_MSTR_DATA_BUS_WIDTH_MASK; |
| 177 | u8 data_bus_width = reg >> DDRCTRL_MSTR_DATA_BUS_WIDTH_SHIFT; |
| 178 | |
| 179 | return data_bus_width; |
| 180 | } |
| 181 | |
| 182 | static u8 get_nb_bank(struct stm32mp1_ddrctl *ctl) |
| 183 | { |
| 184 | /* Count bank address bits */ |
| 185 | u8 bits = 0; |
| 186 | u32 reg, val; |
| 187 | |
| 188 | reg = readl(&ctl->addrmap1); |
| 189 | /* addrmap1.addrmap_bank_b1 */ |
| 190 | val = (reg & GENMASK(5, 0)) >> 0; |
| 191 | if (val <= 31) |
| 192 | bits++; |
| 193 | /* addrmap1.addrmap_bank_b2 */ |
| 194 | val = (reg & GENMASK(13, 8)) >> 8; |
| 195 | if (val <= 31) |
| 196 | bits++; |
| 197 | /* addrmap1.addrmap_bank_b3 */ |
| 198 | val = (reg & GENMASK(21, 16)) >> 16; |
| 199 | if (val <= 31) |
| 200 | bits++; |
| 201 | |
| 202 | return bits; |
| 203 | } |
| 204 | |
| 205 | static u8 get_nb_col(struct stm32mp1_ddrctl *ctl, u8 data_bus_width) |
| 206 | { |
| 207 | u8 bits; |
| 208 | u32 reg, val; |
| 209 | |
| 210 | /* Count column address bits, start at 2 for b0 and b1 (fixed) */ |
| 211 | bits = 2; |
| 212 | |
| 213 | reg = readl(&ctl->addrmap2); |
| 214 | /* addrmap2.addrmap_col_b2 */ |
| 215 | val = (reg & GENMASK(3, 0)) >> 0; |
| 216 | if (val <= 7) |
| 217 | bits++; |
| 218 | /* addrmap2.addrmap_col_b3 */ |
| 219 | val = (reg & GENMASK(11, 8)) >> 8; |
| 220 | if (val <= 7) |
| 221 | bits++; |
| 222 | /* addrmap2.addrmap_col_b4 */ |
| 223 | val = (reg & GENMASK(19, 16)) >> 16; |
| 224 | if (val <= 7) |
| 225 | bits++; |
| 226 | /* addrmap2.addrmap_col_b5 */ |
| 227 | val = (reg & GENMASK(27, 24)) >> 24; |
| 228 | if (val <= 7) |
| 229 | bits++; |
| 230 | |
| 231 | reg = readl(&ctl->addrmap3); |
| 232 | /* addrmap3.addrmap_col_b6 */ |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 233 | val = (reg & GENMASK(4, 0)) >> 0; |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 234 | if (val <= 7) |
| 235 | bits++; |
| 236 | /* addrmap3.addrmap_col_b7 */ |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 237 | val = (reg & GENMASK(12, 8)) >> 8; |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 238 | if (val <= 7) |
| 239 | bits++; |
| 240 | /* addrmap3.addrmap_col_b8 */ |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 241 | val = (reg & GENMASK(20, 16)) >> 16; |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 242 | if (val <= 7) |
| 243 | bits++; |
| 244 | /* addrmap3.addrmap_col_b9 */ |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 245 | val = (reg & GENMASK(28, 24)) >> 24; |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 246 | if (val <= 7) |
| 247 | bits++; |
| 248 | |
| 249 | reg = readl(&ctl->addrmap4); |
| 250 | /* addrmap4.addrmap_col_b10 */ |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 251 | val = (reg & GENMASK(4, 0)) >> 0; |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 252 | if (val <= 7) |
| 253 | bits++; |
| 254 | /* addrmap4.addrmap_col_b11 */ |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 255 | val = (reg & GENMASK(12, 8)) >> 8; |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 256 | if (val <= 7) |
| 257 | bits++; |
| 258 | |
| 259 | /* |
| 260 | * column bits shift up: |
| 261 | * 1 when half the data bus is used (data_bus_width = 1) |
| 262 | * 2 when a quarter the data bus is used (data_bus_width = 2) |
| 263 | * nothing to do for full data bus (data_bus_width = 0) |
| 264 | */ |
| 265 | bits += data_bus_width; |
| 266 | |
| 267 | return bits; |
| 268 | } |
| 269 | |
| 270 | static u8 get_nb_row(struct stm32mp1_ddrctl *ctl) |
| 271 | { |
| 272 | /* Count row address bits */ |
| 273 | u8 bits = 0; |
| 274 | u32 reg, val; |
| 275 | |
| 276 | reg = readl(&ctl->addrmap5); |
| 277 | /* addrmap5.addrmap_row_b0 */ |
| 278 | val = (reg & GENMASK(3, 0)) >> 0; |
| 279 | if (val <= 11) |
| 280 | bits++; |
| 281 | /* addrmap5.addrmap_row_b1 */ |
| 282 | val = (reg & GENMASK(11, 8)) >> 8; |
| 283 | if (val <= 11) |
| 284 | bits++; |
| 285 | /* addrmap5.addrmap_row_b2_10 */ |
| 286 | val = (reg & GENMASK(19, 16)) >> 16; |
| 287 | if (val <= 11) |
| 288 | bits += 9; |
| 289 | else |
| 290 | printf("warning: addrmap5.addrmap_row_b2_10 not supported\n"); |
| 291 | /* addrmap5.addrmap_row_b11 */ |
| 292 | val = (reg & GENMASK(27, 24)) >> 24; |
| 293 | if (val <= 11) |
| 294 | bits++; |
| 295 | |
| 296 | reg = readl(&ctl->addrmap6); |
| 297 | /* addrmap6.addrmap_row_b12 */ |
| 298 | val = (reg & GENMASK(3, 0)) >> 0; |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 299 | if (val <= 11) |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 300 | bits++; |
| 301 | /* addrmap6.addrmap_row_b13 */ |
| 302 | val = (reg & GENMASK(11, 8)) >> 8; |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 303 | if (val <= 11) |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 304 | bits++; |
| 305 | /* addrmap6.addrmap_row_b14 */ |
| 306 | val = (reg & GENMASK(19, 16)) >> 16; |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 307 | if (val <= 11) |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 308 | bits++; |
| 309 | /* addrmap6.addrmap_row_b15 */ |
| 310 | val = (reg & GENMASK(27, 24)) >> 24; |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 311 | if (val <= 11) |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 312 | bits++; |
| 313 | |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 314 | if (reg & BIT(31)) |
| 315 | printf("warning: LPDDR3_6GB_12GB is not supported\n"); |
| 316 | |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 317 | return bits; |
| 318 | } |
| 319 | |
| 320 | /* |
| 321 | * stm32mp1_ddr_size |
| 322 | * |
| 323 | * Get the current DRAM size from the DDR CTL registers |
| 324 | * |
| 325 | * @return: DRAM size |
| 326 | */ |
| 327 | u32 stm32mp1_ddr_size(struct udevice *dev) |
| 328 | { |
| 329 | u8 nb_bit; |
| 330 | u32 ddr_size; |
| 331 | u8 data_bus_width; |
| 332 | struct ddr_info *priv = dev_get_priv(dev); |
| 333 | struct stm32mp1_ddrctl *ctl = priv->ctl; |
| 334 | struct stm32mp1_ddr_cfg *cfg = (struct stm32mp1_ddr_cfg *)dev_get_driver_data(dev); |
| 335 | const u8 nb_bytes = cfg->nb_bytes; |
| 336 | |
| 337 | data_bus_width = get_data_bus_width(ctl); |
| 338 | nb_bit = get_nb_bank(ctl) + get_nb_col(ctl, data_bus_width) + |
| 339 | get_nb_row(ctl); |
| 340 | if (nb_bit > 32) { |
| 341 | nb_bit = 32; |
| 342 | debug("invalid DDR configuration: %d bits\n", nb_bit); |
| 343 | } |
| 344 | |
| 345 | ddr_size = (nb_bytes >> data_bus_width) << nb_bit; |
| 346 | if (ddr_size > STM32_DDR_SIZE) { |
| 347 | ddr_size = STM32_DDR_SIZE; |
| 348 | debug("invalid DDR configuration: size = %x\n", ddr_size); |
| 349 | } |
| 350 | |
| 351 | return ddr_size; |
| 352 | } |
| 353 | |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 354 | static int stm32mp1_ddr_probe(struct udevice *dev) |
| 355 | { |
| 356 | struct ddr_info *priv = dev_get_priv(dev); |
| 357 | struct regmap *map; |
| 358 | int ret; |
| 359 | |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 360 | priv->dev = dev; |
| 361 | |
Masahiro Yamada | e4873e3 | 2018-04-19 12:14:03 +0900 | [diff] [blame] | 362 | ret = regmap_init_mem(dev_ofnode(dev), &map); |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 363 | if (ret) |
Patrick Delaunay | 753f536 | 2020-11-06 19:01:36 +0100 | [diff] [blame] | 364 | return log_ret(ret); |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 365 | |
| 366 | priv->ctl = regmap_get_range(map, 0); |
| 367 | priv->phy = regmap_get_range(map, 1); |
| 368 | |
| 369 | priv->rcc = STM32_RCC_BASE; |
| 370 | |
| 371 | priv->info.base = STM32_DDR_BASE; |
| 372 | |
Patrick Delaunay | 72a5762 | 2021-10-11 09:52:50 +0200 | [diff] [blame] | 373 | if (IS_ENABLED(CONFIG_SPL_BUILD)) { |
| 374 | priv->info.size = 0; |
| 375 | ret = stm32mp1_ddr_setup(dev); |
Patrick Delaunay | 753f536 | 2020-11-06 19:01:36 +0100 | [diff] [blame] | 376 | |
Patrick Delaunay | 72a5762 | 2021-10-11 09:52:50 +0200 | [diff] [blame] | 377 | return log_ret(ret); |
| 378 | } |
| 379 | |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 380 | priv->info.size = stm32mp1_ddr_size(dev); |
| 381 | |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 382 | return 0; |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 383 | } |
| 384 | |
| 385 | static int stm32mp1_ddr_get_info(struct udevice *dev, struct ram_info *info) |
| 386 | { |
| 387 | struct ddr_info *priv = dev_get_priv(dev); |
| 388 | |
| 389 | *info = priv->info; |
| 390 | |
| 391 | return 0; |
| 392 | } |
| 393 | |
| 394 | static struct ram_ops stm32mp1_ddr_ops = { |
| 395 | .get_info = stm32mp1_ddr_get_info, |
| 396 | }; |
| 397 | |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 398 | static const struct stm32mp1_ddr_cfg stm32mp13x_ddr_cfg = { |
| 399 | .nb_bytes = 2, |
| 400 | }; |
| 401 | |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 402 | static const struct stm32mp1_ddr_cfg stm32mp15x_ddr_cfg = { |
| 403 | .nb_bytes = 4, |
| 404 | }; |
| 405 | |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 406 | static const struct udevice_id stm32mp1_ddr_ids[] = { |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 407 | { .compatible = "st,stm32mp1-ddr", .data = (ulong)&stm32mp15x_ddr_cfg}, |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 408 | { .compatible = "st,stm32mp13-ddr", .data = (ulong)&stm32mp13x_ddr_cfg}, |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 409 | { } |
| 410 | }; |
| 411 | |
| 412 | U_BOOT_DRIVER(ddr_stm32mp1) = { |
| 413 | .name = "stm32mp1_ddr", |
| 414 | .id = UCLASS_RAM, |
| 415 | .of_match = stm32mp1_ddr_ids, |
| 416 | .ops = &stm32mp1_ddr_ops, |
| 417 | .probe = stm32mp1_ddr_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 418 | .priv_auto = sizeof(struct ddr_info), |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 419 | }; |