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 | } |
Harald Seiler | f3e4b8b | 2023-09-27 14:44:40 +0200 | [diff] [blame] | 130 | if (CONFIG_IS_ENABLED(DISPLAY_PRINT)) |
| 131 | printf("RAM: %s\n", config.info.name); |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 132 | |
| 133 | for (idx = 0; idx < ARRAY_SIZE(param); idx++) { |
Marek Vasut | 697887a | 2020-04-22 13:18:12 +0200 | [diff] [blame] | 134 | ret = ofnode_read_u32_array(node, param[idx].name, |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 135 | (void *)((u32)&config + |
| 136 | param[idx].offset), |
| 137 | param[idx].size); |
Patrick Delaunay | 753f536 | 2020-11-06 19:01:36 +0100 | [diff] [blame] | 138 | dev_dbg(dev, "%s: %s[0x%x] = %d\n", __func__, |
| 139 | param[idx].name, param[idx].size, ret); |
Patrick Delaunay | 9e2dd66 | 2021-11-15 15:32:29 +0100 | [diff] [blame] | 140 | if (ret) { |
Patrick Delaunay | 753f536 | 2020-11-06 19:01:36 +0100 | [diff] [blame] | 141 | dev_err(dev, "Cannot read %s, error=%d\n", |
| 142 | param[idx].name, ret); |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 143 | return -EINVAL; |
| 144 | } |
| 145 | } |
| 146 | |
| 147 | ret = clk_get_by_name(dev, "axidcg", &axidcg); |
| 148 | if (ret) { |
Patrick Delaunay | 753f536 | 2020-11-06 19:01:36 +0100 | [diff] [blame] | 149 | dev_dbg(dev, "%s: Cannot found axidcg\n", __func__); |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 150 | return -EINVAL; |
| 151 | } |
| 152 | clk_disable(&axidcg); /* disable clock gating during init */ |
| 153 | |
| 154 | stm32mp1_ddr_init(priv, &config); |
| 155 | |
| 156 | clk_enable(&axidcg); /* enable clock gating */ |
| 157 | |
| 158 | /* check size */ |
Patrick Delaunay | 753f536 | 2020-11-06 19:01:36 +0100 | [diff] [blame] | 159 | dev_dbg(dev, "get_ram_size(%x, %x)\n", |
| 160 | (u32)priv->info.base, (u32)STM32_DDR_SIZE); |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 161 | |
| 162 | priv->info.size = get_ram_size((long *)priv->info.base, |
| 163 | STM32_DDR_SIZE); |
| 164 | |
Patrick Delaunay | 753f536 | 2020-11-06 19:01:36 +0100 | [diff] [blame] | 165 | dev_dbg(dev, "info.size: %x\n", (u32)priv->info.size); |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 166 | |
| 167 | /* check memory access for all memory */ |
| 168 | if (config.info.size != priv->info.size) { |
| 169 | printf("DDR invalid size : 0x%x, expected 0x%x\n", |
| 170 | priv->info.size, config.info.size); |
| 171 | return -EINVAL; |
| 172 | } |
| 173 | return 0; |
| 174 | } |
| 175 | |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 176 | static u8 get_data_bus_width(struct stm32mp1_ddrctl *ctl) |
| 177 | { |
| 178 | u32 reg = readl(&ctl->mstr) & DDRCTRL_MSTR_DATA_BUS_WIDTH_MASK; |
| 179 | u8 data_bus_width = reg >> DDRCTRL_MSTR_DATA_BUS_WIDTH_SHIFT; |
| 180 | |
| 181 | return data_bus_width; |
| 182 | } |
| 183 | |
| 184 | static u8 get_nb_bank(struct stm32mp1_ddrctl *ctl) |
| 185 | { |
| 186 | /* Count bank address bits */ |
| 187 | u8 bits = 0; |
| 188 | u32 reg, val; |
| 189 | |
| 190 | reg = readl(&ctl->addrmap1); |
| 191 | /* addrmap1.addrmap_bank_b1 */ |
| 192 | val = (reg & GENMASK(5, 0)) >> 0; |
| 193 | if (val <= 31) |
| 194 | bits++; |
| 195 | /* addrmap1.addrmap_bank_b2 */ |
| 196 | val = (reg & GENMASK(13, 8)) >> 8; |
| 197 | if (val <= 31) |
| 198 | bits++; |
| 199 | /* addrmap1.addrmap_bank_b3 */ |
| 200 | val = (reg & GENMASK(21, 16)) >> 16; |
| 201 | if (val <= 31) |
| 202 | bits++; |
| 203 | |
| 204 | return bits; |
| 205 | } |
| 206 | |
| 207 | static u8 get_nb_col(struct stm32mp1_ddrctl *ctl, u8 data_bus_width) |
| 208 | { |
| 209 | u8 bits; |
| 210 | u32 reg, val; |
| 211 | |
| 212 | /* Count column address bits, start at 2 for b0 and b1 (fixed) */ |
| 213 | bits = 2; |
| 214 | |
| 215 | reg = readl(&ctl->addrmap2); |
| 216 | /* addrmap2.addrmap_col_b2 */ |
| 217 | val = (reg & GENMASK(3, 0)) >> 0; |
| 218 | if (val <= 7) |
| 219 | bits++; |
| 220 | /* addrmap2.addrmap_col_b3 */ |
| 221 | val = (reg & GENMASK(11, 8)) >> 8; |
| 222 | if (val <= 7) |
| 223 | bits++; |
| 224 | /* addrmap2.addrmap_col_b4 */ |
| 225 | val = (reg & GENMASK(19, 16)) >> 16; |
| 226 | if (val <= 7) |
| 227 | bits++; |
| 228 | /* addrmap2.addrmap_col_b5 */ |
| 229 | val = (reg & GENMASK(27, 24)) >> 24; |
| 230 | if (val <= 7) |
| 231 | bits++; |
| 232 | |
| 233 | reg = readl(&ctl->addrmap3); |
| 234 | /* addrmap3.addrmap_col_b6 */ |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 235 | val = (reg & GENMASK(4, 0)) >> 0; |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 236 | if (val <= 7) |
| 237 | bits++; |
| 238 | /* addrmap3.addrmap_col_b7 */ |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 239 | val = (reg & GENMASK(12, 8)) >> 8; |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 240 | if (val <= 7) |
| 241 | bits++; |
| 242 | /* addrmap3.addrmap_col_b8 */ |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 243 | val = (reg & GENMASK(20, 16)) >> 16; |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 244 | if (val <= 7) |
| 245 | bits++; |
| 246 | /* addrmap3.addrmap_col_b9 */ |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 247 | val = (reg & GENMASK(28, 24)) >> 24; |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 248 | if (val <= 7) |
| 249 | bits++; |
| 250 | |
| 251 | reg = readl(&ctl->addrmap4); |
| 252 | /* addrmap4.addrmap_col_b10 */ |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 253 | val = (reg & GENMASK(4, 0)) >> 0; |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 254 | if (val <= 7) |
| 255 | bits++; |
| 256 | /* addrmap4.addrmap_col_b11 */ |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 257 | val = (reg & GENMASK(12, 8)) >> 8; |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 258 | if (val <= 7) |
| 259 | bits++; |
| 260 | |
| 261 | /* |
| 262 | * column bits shift up: |
| 263 | * 1 when half the data bus is used (data_bus_width = 1) |
| 264 | * 2 when a quarter the data bus is used (data_bus_width = 2) |
| 265 | * nothing to do for full data bus (data_bus_width = 0) |
| 266 | */ |
| 267 | bits += data_bus_width; |
| 268 | |
| 269 | return bits; |
| 270 | } |
| 271 | |
| 272 | static u8 get_nb_row(struct stm32mp1_ddrctl *ctl) |
| 273 | { |
| 274 | /* Count row address bits */ |
| 275 | u8 bits = 0; |
| 276 | u32 reg, val; |
| 277 | |
| 278 | reg = readl(&ctl->addrmap5); |
| 279 | /* addrmap5.addrmap_row_b0 */ |
| 280 | val = (reg & GENMASK(3, 0)) >> 0; |
| 281 | if (val <= 11) |
| 282 | bits++; |
| 283 | /* addrmap5.addrmap_row_b1 */ |
| 284 | val = (reg & GENMASK(11, 8)) >> 8; |
| 285 | if (val <= 11) |
| 286 | bits++; |
| 287 | /* addrmap5.addrmap_row_b2_10 */ |
| 288 | val = (reg & GENMASK(19, 16)) >> 16; |
| 289 | if (val <= 11) |
| 290 | bits += 9; |
| 291 | else |
| 292 | printf("warning: addrmap5.addrmap_row_b2_10 not supported\n"); |
| 293 | /* addrmap5.addrmap_row_b11 */ |
| 294 | val = (reg & GENMASK(27, 24)) >> 24; |
| 295 | if (val <= 11) |
| 296 | bits++; |
| 297 | |
| 298 | reg = readl(&ctl->addrmap6); |
| 299 | /* addrmap6.addrmap_row_b12 */ |
| 300 | val = (reg & GENMASK(3, 0)) >> 0; |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 301 | if (val <= 11) |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 302 | bits++; |
| 303 | /* addrmap6.addrmap_row_b13 */ |
| 304 | val = (reg & GENMASK(11, 8)) >> 8; |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 305 | if (val <= 11) |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 306 | bits++; |
| 307 | /* addrmap6.addrmap_row_b14 */ |
| 308 | val = (reg & GENMASK(19, 16)) >> 16; |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 309 | if (val <= 11) |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 310 | bits++; |
| 311 | /* addrmap6.addrmap_row_b15 */ |
| 312 | val = (reg & GENMASK(27, 24)) >> 24; |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 313 | if (val <= 11) |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 314 | bits++; |
| 315 | |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 316 | if (reg & BIT(31)) |
| 317 | printf("warning: LPDDR3_6GB_12GB is not supported\n"); |
| 318 | |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 319 | return bits; |
| 320 | } |
| 321 | |
| 322 | /* |
| 323 | * stm32mp1_ddr_size |
| 324 | * |
| 325 | * Get the current DRAM size from the DDR CTL registers |
| 326 | * |
| 327 | * @return: DRAM size |
| 328 | */ |
| 329 | u32 stm32mp1_ddr_size(struct udevice *dev) |
| 330 | { |
| 331 | u8 nb_bit; |
| 332 | u32 ddr_size; |
| 333 | u8 data_bus_width; |
| 334 | struct ddr_info *priv = dev_get_priv(dev); |
| 335 | struct stm32mp1_ddrctl *ctl = priv->ctl; |
| 336 | struct stm32mp1_ddr_cfg *cfg = (struct stm32mp1_ddr_cfg *)dev_get_driver_data(dev); |
| 337 | const u8 nb_bytes = cfg->nb_bytes; |
| 338 | |
| 339 | data_bus_width = get_data_bus_width(ctl); |
| 340 | nb_bit = get_nb_bank(ctl) + get_nb_col(ctl, data_bus_width) + |
| 341 | get_nb_row(ctl); |
| 342 | if (nb_bit > 32) { |
| 343 | nb_bit = 32; |
| 344 | debug("invalid DDR configuration: %d bits\n", nb_bit); |
| 345 | } |
| 346 | |
| 347 | ddr_size = (nb_bytes >> data_bus_width) << nb_bit; |
| 348 | if (ddr_size > STM32_DDR_SIZE) { |
| 349 | ddr_size = STM32_DDR_SIZE; |
| 350 | debug("invalid DDR configuration: size = %x\n", ddr_size); |
| 351 | } |
| 352 | |
| 353 | return ddr_size; |
| 354 | } |
| 355 | |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 356 | static int stm32mp1_ddr_probe(struct udevice *dev) |
| 357 | { |
| 358 | struct ddr_info *priv = dev_get_priv(dev); |
| 359 | struct regmap *map; |
| 360 | int ret; |
| 361 | |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 362 | priv->dev = dev; |
| 363 | |
Masahiro Yamada | e4873e3 | 2018-04-19 12:14:03 +0900 | [diff] [blame] | 364 | ret = regmap_init_mem(dev_ofnode(dev), &map); |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 365 | if (ret) |
Patrick Delaunay | 753f536 | 2020-11-06 19:01:36 +0100 | [diff] [blame] | 366 | return log_ret(ret); |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 367 | |
| 368 | priv->ctl = regmap_get_range(map, 0); |
| 369 | priv->phy = regmap_get_range(map, 1); |
| 370 | |
| 371 | priv->rcc = STM32_RCC_BASE; |
| 372 | |
| 373 | priv->info.base = STM32_DDR_BASE; |
| 374 | |
Patrick Delaunay | 72a5762 | 2021-10-11 09:52:50 +0200 | [diff] [blame] | 375 | if (IS_ENABLED(CONFIG_SPL_BUILD)) { |
| 376 | priv->info.size = 0; |
| 377 | ret = stm32mp1_ddr_setup(dev); |
Patrick Delaunay | 753f536 | 2020-11-06 19:01:36 +0100 | [diff] [blame] | 378 | |
Patrick Delaunay | 72a5762 | 2021-10-11 09:52:50 +0200 | [diff] [blame] | 379 | return log_ret(ret); |
| 380 | } |
| 381 | |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 382 | priv->info.size = stm32mp1_ddr_size(dev); |
| 383 | |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 384 | return 0; |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 385 | } |
| 386 | |
| 387 | static int stm32mp1_ddr_get_info(struct udevice *dev, struct ram_info *info) |
| 388 | { |
| 389 | struct ddr_info *priv = dev_get_priv(dev); |
| 390 | |
| 391 | *info = priv->info; |
| 392 | |
| 393 | return 0; |
| 394 | } |
| 395 | |
| 396 | static struct ram_ops stm32mp1_ddr_ops = { |
| 397 | .get_info = stm32mp1_ddr_get_info, |
| 398 | }; |
| 399 | |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 400 | static const struct stm32mp1_ddr_cfg stm32mp13x_ddr_cfg = { |
| 401 | .nb_bytes = 2, |
| 402 | }; |
| 403 | |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 404 | static const struct stm32mp1_ddr_cfg stm32mp15x_ddr_cfg = { |
| 405 | .nb_bytes = 4, |
| 406 | }; |
| 407 | |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 408 | static const struct udevice_id stm32mp1_ddr_ids[] = { |
Patrick Delaunay | df7fe21 | 2021-11-24 10:52:18 +0100 | [diff] [blame] | 409 | { .compatible = "st,stm32mp1-ddr", .data = (ulong)&stm32mp15x_ddr_cfg}, |
Patrick Delaunay | b5bb08d | 2022-05-20 18:24:50 +0200 | [diff] [blame] | 410 | { .compatible = "st,stm32mp13-ddr", .data = (ulong)&stm32mp13x_ddr_cfg}, |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 411 | { } |
| 412 | }; |
| 413 | |
| 414 | U_BOOT_DRIVER(ddr_stm32mp1) = { |
| 415 | .name = "stm32mp1_ddr", |
| 416 | .id = UCLASS_RAM, |
| 417 | .of_match = stm32mp1_ddr_ids, |
| 418 | .ops = &stm32mp1_ddr_ops, |
| 419 | .probe = stm32mp1_ddr_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 420 | .priv_auto = sizeof(struct ddr_info), |
Patrick Delaunay | 939d536 | 2018-03-12 10:46:11 +0100 | [diff] [blame] | 421 | }; |