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