Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause |
| 2 | /* |
| 3 | * Copyright (C) 2018, STMicroelectronics - All Rights Reserved |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <adc.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 8 | #include <log.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 9 | #include <net.h> |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 10 | #include <asm/arch/stm32.h> |
| 11 | #include <asm/arch/sys_proto.h> |
| 12 | #include <asm/gpio.h> |
| 13 | #include <asm/io.h> |
| 14 | #include <bootm.h> |
| 15 | #include <clk.h> |
| 16 | #include <config.h> |
| 17 | #include <dm.h> |
| 18 | #include <dm/device.h> |
| 19 | #include <dm/uclass.h> |
| 20 | #include <env.h> |
| 21 | #include <env_internal.h> |
| 22 | #include <g_dnl.h> |
| 23 | #include <generic-phy.h> |
| 24 | #include <hang.h> |
| 25 | #include <i2c.h> |
| 26 | #include <i2c_eeprom.h> |
| 27 | #include <init.h> |
| 28 | #include <led.h> |
| 29 | #include <memalign.h> |
| 30 | #include <misc.h> |
| 31 | #include <mtd.h> |
| 32 | #include <mtd_node.h> |
| 33 | #include <netdev.h> |
| 34 | #include <phy.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 35 | #include <linux/bitops.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 36 | #include <linux/delay.h> |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 37 | #include <power/regulator.h> |
| 38 | #include <remoteproc.h> |
| 39 | #include <reset.h> |
| 40 | #include <syscon.h> |
| 41 | #include <usb.h> |
| 42 | #include <usb/dwc2_udc.h> |
| 43 | #include <watchdog.h> |
Patrick Delaunay | f2f25c3 | 2020-05-25 12:19:46 +0200 | [diff] [blame] | 44 | #include "../../st/common/stpmic1.h" |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 45 | |
| 46 | /* SYSCFG registers */ |
| 47 | #define SYSCFG_BOOTR 0x00 |
| 48 | #define SYSCFG_PMCSETR 0x04 |
| 49 | #define SYSCFG_IOCTRLSETR 0x18 |
| 50 | #define SYSCFG_ICNR 0x1C |
| 51 | #define SYSCFG_CMPCR 0x20 |
| 52 | #define SYSCFG_CMPENSETR 0x24 |
| 53 | #define SYSCFG_PMCCLRR 0x44 |
| 54 | |
| 55 | #define SYSCFG_BOOTR_BOOT_MASK GENMASK(2, 0) |
| 56 | #define SYSCFG_BOOTR_BOOTPD_SHIFT 4 |
| 57 | |
| 58 | #define SYSCFG_IOCTRLSETR_HSLVEN_TRACE BIT(0) |
| 59 | #define SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI BIT(1) |
| 60 | #define SYSCFG_IOCTRLSETR_HSLVEN_ETH BIT(2) |
| 61 | #define SYSCFG_IOCTRLSETR_HSLVEN_SDMMC BIT(3) |
| 62 | #define SYSCFG_IOCTRLSETR_HSLVEN_SPI BIT(4) |
| 63 | |
| 64 | #define SYSCFG_CMPCR_SW_CTRL BIT(1) |
| 65 | #define SYSCFG_CMPCR_READY BIT(8) |
| 66 | |
| 67 | #define SYSCFG_CMPENSETR_MPU_EN BIT(0) |
| 68 | |
| 69 | #define SYSCFG_PMCSETR_ETH_CLK_SEL BIT(16) |
| 70 | #define SYSCFG_PMCSETR_ETH_REF_CLK_SEL BIT(17) |
| 71 | |
| 72 | #define SYSCFG_PMCSETR_ETH_SELMII BIT(20) |
| 73 | |
| 74 | #define SYSCFG_PMCSETR_ETH_SEL_MASK GENMASK(23, 21) |
| 75 | #define SYSCFG_PMCSETR_ETH_SEL_GMII_MII 0 |
| 76 | #define SYSCFG_PMCSETR_ETH_SEL_RGMII BIT(21) |
| 77 | #define SYSCFG_PMCSETR_ETH_SEL_RMII BIT(23) |
| 78 | |
| 79 | /* |
| 80 | * Get a global data pointer |
| 81 | */ |
| 82 | DECLARE_GLOBAL_DATA_PTR; |
| 83 | |
Marek Vasut | 145a876 | 2020-10-08 15:14:58 +0200 | [diff] [blame] | 84 | #define KS_CCR 0x08 |
| 85 | #define KS_CCR_EEPROM BIT(9) |
| 86 | #define KS_BE0 BIT(12) |
| 87 | #define KS_BE1 BIT(13) |
| 88 | |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 89 | int setup_mac_address(void) |
| 90 | { |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 91 | unsigned char enetaddr[6]; |
Marek Vasut | b0a2a49 | 2020-07-31 01:34:50 +0200 | [diff] [blame] | 92 | bool skip_eth0 = false; |
| 93 | bool skip_eth1 = false; |
Marek Vasut | 2ab7a2a | 2020-03-31 19:51:29 +0200 | [diff] [blame] | 94 | struct udevice *dev; |
| 95 | int off, ret; |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 96 | |
| 97 | ret = eth_env_get_enetaddr("ethaddr", enetaddr); |
| 98 | if (ret) /* ethaddr is already set */ |
Marek Vasut | b0a2a49 | 2020-07-31 01:34:50 +0200 | [diff] [blame] | 99 | skip_eth0 = true; |
| 100 | |
| 101 | off = fdt_path_offset(gd->fdt_blob, "ethernet1"); |
| 102 | if (off < 0) { |
| 103 | /* ethernet1 is not present in the system */ |
| 104 | skip_eth1 = true; |
Marek Vasut | 145a876 | 2020-10-08 15:14:58 +0200 | [diff] [blame] | 105 | goto out_set_ethaddr; |
| 106 | } |
| 107 | |
| 108 | ret = eth_env_get_enetaddr("eth1addr", enetaddr); |
| 109 | if (ret) { |
| 110 | /* eth1addr is already set */ |
| 111 | skip_eth1 = true; |
| 112 | goto out_set_ethaddr; |
| 113 | } |
| 114 | |
| 115 | ret = fdt_node_check_compatible(gd->fdt_blob, off, "micrel,ks8851-mll"); |
| 116 | if (ret) |
| 117 | goto out_set_ethaddr; |
| 118 | |
| 119 | /* |
| 120 | * KS8851 with EEPROM may use custom MAC from EEPROM, read |
| 121 | * out the KS8851 CCR register to determine whether EEPROM |
| 122 | * is present. If EEPROM is present, it must contain valid |
| 123 | * MAC address. |
| 124 | */ |
| 125 | u32 reg, ccr; |
| 126 | reg = fdt_get_base_address(gd->fdt_blob, off); |
| 127 | if (!reg) |
| 128 | goto out_set_ethaddr; |
| 129 | |
| 130 | writew(KS_BE0 | KS_BE1 | KS_CCR, reg + 2); |
| 131 | ccr = readw(reg); |
| 132 | if (ccr & KS_CCR_EEPROM) { |
| 133 | skip_eth1 = true; |
| 134 | goto out_set_ethaddr; |
Marek Vasut | b0a2a49 | 2020-07-31 01:34:50 +0200 | [diff] [blame] | 135 | } |
| 136 | |
Marek Vasut | 145a876 | 2020-10-08 15:14:58 +0200 | [diff] [blame] | 137 | out_set_ethaddr: |
Marek Vasut | b0a2a49 | 2020-07-31 01:34:50 +0200 | [diff] [blame] | 138 | if (skip_eth0 && skip_eth1) |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 139 | return 0; |
| 140 | |
Marek Vasut | 2ab7a2a | 2020-03-31 19:51:29 +0200 | [diff] [blame] | 141 | off = fdt_path_offset(gd->fdt_blob, "eeprom0"); |
| 142 | if (off < 0) { |
| 143 | printf("%s: No eeprom0 path offset\n", __func__); |
| 144 | return off; |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 145 | } |
| 146 | |
Marek Vasut | 2ab7a2a | 2020-03-31 19:51:29 +0200 | [diff] [blame] | 147 | ret = uclass_get_device_by_of_offset(UCLASS_I2C_EEPROM, off, &dev); |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 148 | if (ret) { |
| 149 | printf("Cannot find EEPROM!\n"); |
| 150 | return ret; |
| 151 | } |
| 152 | |
| 153 | ret = i2c_eeprom_read(dev, 0xfa, enetaddr, 0x6); |
| 154 | if (ret) { |
| 155 | printf("Error reading configuration EEPROM!\n"); |
| 156 | return ret; |
| 157 | } |
| 158 | |
Marek Vasut | b0a2a49 | 2020-07-31 01:34:50 +0200 | [diff] [blame] | 159 | if (is_valid_ethaddr(enetaddr)) { |
| 160 | if (!skip_eth0) |
| 161 | eth_env_set_enetaddr("ethaddr", enetaddr); |
| 162 | |
| 163 | enetaddr[5]++; |
| 164 | if (!skip_eth1) |
| 165 | eth_env_set_enetaddr("eth1addr", enetaddr); |
| 166 | } |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 167 | |
| 168 | return 0; |
| 169 | } |
| 170 | |
| 171 | int checkboard(void) |
| 172 | { |
| 173 | char *mode; |
| 174 | const char *fdt_compat; |
| 175 | int fdt_compat_len; |
| 176 | |
Patrick Delaunay | 472407a | 2020-03-18 09:22:49 +0100 | [diff] [blame] | 177 | if (IS_ENABLED(CONFIG_TFABOOT)) |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 178 | mode = "trusted"; |
| 179 | else |
| 180 | mode = "basic"; |
| 181 | |
| 182 | printf("Board: stm32mp1 in %s mode", mode); |
| 183 | fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible", |
| 184 | &fdt_compat_len); |
| 185 | if (fdt_compat && fdt_compat_len) |
| 186 | printf(" (%s)", fdt_compat); |
| 187 | puts("\n"); |
| 188 | |
| 189 | return 0; |
| 190 | } |
| 191 | |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 192 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
| 193 | static u8 brdcode __section("data"); |
Marek Vasut | 39221b5 | 2020-04-22 13:18:14 +0200 | [diff] [blame] | 194 | static u8 ddr3code __section("data"); |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 195 | static u8 somcode __section("data"); |
Patrick Delaunay | 08c891a | 2020-05-25 12:19:47 +0200 | [diff] [blame] | 196 | static u32 opp_voltage_mv __section(".data"); |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 197 | |
| 198 | static void board_get_coding_straps(void) |
| 199 | { |
| 200 | struct gpio_desc gpio[4]; |
| 201 | ofnode node; |
| 202 | int i, ret; |
| 203 | |
| 204 | node = ofnode_path("/config"); |
| 205 | if (!ofnode_valid(node)) { |
| 206 | printf("%s: no /config node?\n", __func__); |
| 207 | return; |
| 208 | } |
| 209 | |
| 210 | brdcode = 0; |
Marek Vasut | 39221b5 | 2020-04-22 13:18:14 +0200 | [diff] [blame] | 211 | ddr3code = 0; |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 212 | somcode = 0; |
| 213 | |
| 214 | ret = gpio_request_list_by_name_nodev(node, "dh,som-coding-gpios", |
| 215 | gpio, ARRAY_SIZE(gpio), |
| 216 | GPIOD_IS_IN); |
| 217 | for (i = 0; i < ret; i++) |
| 218 | somcode |= !!dm_gpio_get_value(&(gpio[i])) << i; |
| 219 | |
Marek Vasut | 39221b5 | 2020-04-22 13:18:14 +0200 | [diff] [blame] | 220 | ret = gpio_request_list_by_name_nodev(node, "dh,ddr3-coding-gpios", |
| 221 | gpio, ARRAY_SIZE(gpio), |
| 222 | GPIOD_IS_IN); |
| 223 | for (i = 0; i < ret; i++) |
| 224 | ddr3code |= !!dm_gpio_get_value(&(gpio[i])) << i; |
| 225 | |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 226 | ret = gpio_request_list_by_name_nodev(node, "dh,board-coding-gpios", |
| 227 | gpio, ARRAY_SIZE(gpio), |
| 228 | GPIOD_IS_IN); |
| 229 | for (i = 0; i < ret; i++) |
| 230 | brdcode |= !!dm_gpio_get_value(&(gpio[i])) << i; |
| 231 | |
Marek Vasut | 39221b5 | 2020-04-22 13:18:14 +0200 | [diff] [blame] | 232 | printf("Code: SoM:rev=%d,ddr3=%d Board:rev=%d\n", |
| 233 | somcode, ddr3code, brdcode); |
| 234 | } |
| 235 | |
| 236 | int board_stm32mp1_ddr_config_name_match(struct udevice *dev, |
| 237 | const char *name) |
| 238 | { |
Marek Vasut | 272198e | 2020-04-29 15:08:38 +0200 | [diff] [blame] | 239 | if (ddr3code == 1 && |
| 240 | !strcmp(name, "st,ddr3l-dhsom-1066-888-bin-g-2x1gb-533mhz")) |
| 241 | return 0; |
| 242 | |
Marek Vasut | 39221b5 | 2020-04-22 13:18:14 +0200 | [diff] [blame] | 243 | if (ddr3code == 2 && |
Marek Vasut | 272198e | 2020-04-29 15:08:38 +0200 | [diff] [blame] | 244 | !strcmp(name, "st,ddr3l-dhsom-1066-888-bin-g-2x2gb-533mhz")) |
Marek Vasut | 39221b5 | 2020-04-22 13:18:14 +0200 | [diff] [blame] | 245 | return 0; |
| 246 | |
| 247 | if (ddr3code == 3 && |
Marek Vasut | 272198e | 2020-04-29 15:08:38 +0200 | [diff] [blame] | 248 | !strcmp(name, "st,ddr3l-dhsom-1066-888-bin-g-2x4gb-533mhz")) |
Marek Vasut | 39221b5 | 2020-04-22 13:18:14 +0200 | [diff] [blame] | 249 | return 0; |
| 250 | |
| 251 | return -EINVAL; |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 252 | } |
| 253 | |
Patrick Delaunay | 08c891a | 2020-05-25 12:19:47 +0200 | [diff] [blame] | 254 | void board_vddcore_init(u32 voltage_mv) |
| 255 | { |
| 256 | if (IS_ENABLED(CONFIG_SPL_BUILD)) |
| 257 | opp_voltage_mv = voltage_mv; |
| 258 | } |
| 259 | |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 260 | int board_early_init_f(void) |
| 261 | { |
Patrick Delaunay | f2f25c3 | 2020-05-25 12:19:46 +0200 | [diff] [blame] | 262 | if (IS_ENABLED(CONFIG_SPL_BUILD)) |
Patrick Delaunay | 08c891a | 2020-05-25 12:19:47 +0200 | [diff] [blame] | 263 | stpmic1_init(opp_voltage_mv); |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 264 | board_get_coding_straps(); |
| 265 | |
| 266 | return 0; |
| 267 | } |
| 268 | |
| 269 | #ifdef CONFIG_SPL_LOAD_FIT |
| 270 | int board_fit_config_name_match(const char *name) |
| 271 | { |
Marek Vasut | 060cb12 | 2020-07-31 01:35:33 +0200 | [diff] [blame] | 272 | const char *compat; |
| 273 | char test[128]; |
| 274 | |
| 275 | compat = fdt_getprop(gd->fdt_blob, 0, "compatible", NULL); |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 276 | |
Marek Vasut | 060cb12 | 2020-07-31 01:35:33 +0200 | [diff] [blame] | 277 | snprintf(test, sizeof(test), "%s_somrev%d_boardrev%d", |
| 278 | compat, somcode, brdcode); |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 279 | |
| 280 | if (!strcmp(name, test)) |
| 281 | return 0; |
| 282 | |
| 283 | return -EINVAL; |
| 284 | } |
| 285 | #endif |
| 286 | #endif |
| 287 | |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 288 | static void board_key_check(void) |
| 289 | { |
| 290 | #if defined(CONFIG_FASTBOOT) || defined(CONFIG_CMD_STM32PROG) |
| 291 | ofnode node; |
| 292 | struct gpio_desc gpio; |
| 293 | enum forced_boot_mode boot_mode = BOOT_NORMAL; |
| 294 | |
| 295 | node = ofnode_path("/config"); |
| 296 | if (!ofnode_valid(node)) { |
| 297 | debug("%s: no /config node?\n", __func__); |
| 298 | return; |
| 299 | } |
| 300 | #ifdef CONFIG_FASTBOOT |
| 301 | if (gpio_request_by_name_nodev(node, "st,fastboot-gpios", 0, |
| 302 | &gpio, GPIOD_IS_IN)) { |
| 303 | debug("%s: could not find a /config/st,fastboot-gpios\n", |
| 304 | __func__); |
| 305 | } else { |
| 306 | if (dm_gpio_get_value(&gpio)) { |
| 307 | puts("Fastboot key pressed, "); |
| 308 | boot_mode = BOOT_FASTBOOT; |
| 309 | } |
| 310 | |
| 311 | dm_gpio_free(NULL, &gpio); |
| 312 | } |
| 313 | #endif |
| 314 | #ifdef CONFIG_CMD_STM32PROG |
| 315 | if (gpio_request_by_name_nodev(node, "st,stm32prog-gpios", 0, |
| 316 | &gpio, GPIOD_IS_IN)) { |
| 317 | debug("%s: could not find a /config/st,stm32prog-gpios\n", |
| 318 | __func__); |
| 319 | } else { |
| 320 | if (dm_gpio_get_value(&gpio)) { |
| 321 | puts("STM32Programmer key pressed, "); |
| 322 | boot_mode = BOOT_STM32PROG; |
| 323 | } |
| 324 | dm_gpio_free(NULL, &gpio); |
| 325 | } |
| 326 | #endif |
| 327 | |
| 328 | if (boot_mode != BOOT_NORMAL) { |
| 329 | puts("entering download mode...\n"); |
| 330 | clrsetbits_le32(TAMP_BOOT_CONTEXT, |
| 331 | TAMP_BOOT_FORCED_MASK, |
| 332 | boot_mode); |
| 333 | } |
| 334 | #endif |
| 335 | } |
| 336 | |
| 337 | #if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG) |
| 338 | |
| 339 | #include <usb/dwc2_udc.h> |
| 340 | int g_dnl_board_usb_cable_connected(void) |
| 341 | { |
| 342 | struct udevice *dwc2_udc_otg; |
| 343 | int ret; |
| 344 | |
| 345 | ret = uclass_get_device_by_driver(UCLASS_USB_GADGET_GENERIC, |
| 346 | DM_GET_DRIVER(dwc2_udc_otg), |
| 347 | &dwc2_udc_otg); |
| 348 | if (!ret) |
| 349 | debug("dwc2_udc_otg init failed\n"); |
| 350 | |
| 351 | return dwc2_udc_B_session_valid(dwc2_udc_otg); |
| 352 | } |
| 353 | |
| 354 | #define STM32MP1_G_DNL_DFU_PRODUCT_NUM 0xdf11 |
| 355 | #define STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM 0x0afb |
| 356 | |
| 357 | int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name) |
| 358 | { |
| 359 | if (!strcmp(name, "usb_dnl_dfu")) |
| 360 | put_unaligned(STM32MP1_G_DNL_DFU_PRODUCT_NUM, &dev->idProduct); |
| 361 | else if (!strcmp(name, "usb_dnl_fastboot")) |
| 362 | put_unaligned(STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM, |
| 363 | &dev->idProduct); |
| 364 | else |
| 365 | put_unaligned(CONFIG_USB_GADGET_PRODUCT_NUM, &dev->idProduct); |
| 366 | |
| 367 | return 0; |
| 368 | } |
| 369 | |
| 370 | #endif /* CONFIG_USB_GADGET */ |
| 371 | |
| 372 | #ifdef CONFIG_LED |
| 373 | static int get_led(struct udevice **dev, char *led_string) |
| 374 | { |
| 375 | char *led_name; |
| 376 | int ret; |
| 377 | |
| 378 | led_name = fdtdec_get_config_string(gd->fdt_blob, led_string); |
| 379 | if (!led_name) { |
| 380 | pr_debug("%s: could not find %s config string\n", |
| 381 | __func__, led_string); |
| 382 | return -ENOENT; |
| 383 | } |
| 384 | ret = led_get_by_label(led_name, dev); |
| 385 | if (ret) { |
| 386 | debug("%s: get=%d\n", __func__, ret); |
| 387 | return ret; |
| 388 | } |
| 389 | |
| 390 | return 0; |
| 391 | } |
| 392 | |
| 393 | static int setup_led(enum led_state_t cmd) |
| 394 | { |
| 395 | struct udevice *dev; |
| 396 | int ret; |
| 397 | |
| 398 | ret = get_led(&dev, "u-boot,boot-led"); |
| 399 | if (ret) |
| 400 | return ret; |
| 401 | |
| 402 | ret = led_set_state(dev, cmd); |
| 403 | return ret; |
| 404 | } |
| 405 | #endif |
| 406 | |
| 407 | static void __maybe_unused led_error_blink(u32 nb_blink) |
| 408 | { |
| 409 | #ifdef CONFIG_LED |
| 410 | int ret; |
| 411 | struct udevice *led; |
| 412 | u32 i; |
| 413 | #endif |
| 414 | |
| 415 | if (!nb_blink) |
| 416 | return; |
| 417 | |
| 418 | #ifdef CONFIG_LED |
| 419 | ret = get_led(&led, "u-boot,error-led"); |
| 420 | if (!ret) { |
| 421 | /* make u-boot,error-led blinking */ |
| 422 | /* if U32_MAX and 125ms interval, for 17.02 years */ |
| 423 | for (i = 0; i < 2 * nb_blink; i++) { |
| 424 | led_set_state(led, LEDST_TOGGLE); |
| 425 | mdelay(125); |
| 426 | WATCHDOG_RESET(); |
| 427 | } |
| 428 | } |
| 429 | #endif |
| 430 | |
| 431 | /* infinite: the boot process must be stopped */ |
| 432 | if (nb_blink == U32_MAX) |
| 433 | hang(); |
| 434 | } |
| 435 | |
| 436 | static void sysconf_init(void) |
| 437 | { |
Patrick Delaunay | f8fe21d | 2020-04-01 09:07:33 +0200 | [diff] [blame] | 438 | #ifndef CONFIG_TFABOOT |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 439 | u8 *syscfg; |
| 440 | #ifdef CONFIG_DM_REGULATOR |
| 441 | struct udevice *pwr_dev; |
| 442 | struct udevice *pwr_reg; |
| 443 | struct udevice *dev; |
| 444 | int ret; |
| 445 | u32 otp = 0; |
| 446 | #endif |
| 447 | u32 bootr; |
| 448 | |
| 449 | syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG); |
| 450 | |
| 451 | /* interconnect update : select master using the port 1 */ |
| 452 | /* LTDC = AXI_M9 */ |
| 453 | /* GPU = AXI_M8 */ |
| 454 | /* today information is hardcoded in U-Boot */ |
| 455 | writel(BIT(9), syscfg + SYSCFG_ICNR); |
| 456 | |
| 457 | /* disable Pull-Down for boot pin connected to VDD */ |
| 458 | bootr = readl(syscfg + SYSCFG_BOOTR); |
| 459 | bootr &= ~(SYSCFG_BOOTR_BOOT_MASK << SYSCFG_BOOTR_BOOTPD_SHIFT); |
| 460 | bootr |= (bootr & SYSCFG_BOOTR_BOOT_MASK) << SYSCFG_BOOTR_BOOTPD_SHIFT; |
| 461 | writel(bootr, syscfg + SYSCFG_BOOTR); |
| 462 | |
| 463 | #ifdef CONFIG_DM_REGULATOR |
| 464 | /* High Speed Low Voltage Pad mode Enable for SPI, SDMMC, ETH, QSPI |
| 465 | * and TRACE. Needed above ~50MHz and conditioned by AFMUX selection. |
| 466 | * The customer will have to disable this for low frequencies |
| 467 | * or if AFMUX is selected but the function not used, typically for |
| 468 | * TRACE. Otherwise, impact on power consumption. |
| 469 | * |
| 470 | * WARNING: |
| 471 | * enabling High Speed mode while VDD>2.7V |
| 472 | * with the OTP product_below_2v5 (OTP 18, BIT 13) |
| 473 | * erroneously set to 1 can damage the IC! |
| 474 | * => U-Boot set the register only if VDD < 2.7V (in DT) |
| 475 | * but this value need to be consistent with board design |
| 476 | */ |
| 477 | ret = uclass_get_device_by_driver(UCLASS_PMIC, |
| 478 | DM_GET_DRIVER(stm32mp_pwr_pmic), |
| 479 | &pwr_dev); |
| 480 | if (!ret) { |
| 481 | ret = uclass_get_device_by_driver(UCLASS_MISC, |
| 482 | DM_GET_DRIVER(stm32mp_bsec), |
| 483 | &dev); |
| 484 | if (ret) { |
| 485 | pr_err("Can't find stm32mp_bsec driver\n"); |
| 486 | return; |
| 487 | } |
| 488 | |
| 489 | ret = misc_read(dev, STM32_BSEC_SHADOW(18), &otp, 4); |
| 490 | if (ret > 0) |
| 491 | otp = otp & BIT(13); |
| 492 | |
| 493 | /* get VDD = vdd-supply */ |
| 494 | ret = device_get_supply_regulator(pwr_dev, "vdd-supply", |
| 495 | &pwr_reg); |
| 496 | |
| 497 | /* check if VDD is Low Voltage */ |
| 498 | if (!ret) { |
| 499 | if (regulator_get_value(pwr_reg) < 2700000) { |
| 500 | writel(SYSCFG_IOCTRLSETR_HSLVEN_TRACE | |
| 501 | SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI | |
| 502 | SYSCFG_IOCTRLSETR_HSLVEN_ETH | |
| 503 | SYSCFG_IOCTRLSETR_HSLVEN_SDMMC | |
| 504 | SYSCFG_IOCTRLSETR_HSLVEN_SPI, |
| 505 | syscfg + SYSCFG_IOCTRLSETR); |
| 506 | |
| 507 | if (!otp) |
| 508 | pr_err("product_below_2v5=0: HSLVEN protected by HW\n"); |
| 509 | } else { |
| 510 | if (otp) |
| 511 | pr_err("product_below_2v5=1: HSLVEN update is destructive, no update as VDD>2.7V\n"); |
| 512 | } |
| 513 | } else { |
| 514 | debug("VDD unknown"); |
| 515 | } |
| 516 | } |
| 517 | #endif |
| 518 | |
| 519 | /* activate automatic I/O compensation |
| 520 | * warning: need to ensure CSI enabled and ready in clock driver |
| 521 | */ |
| 522 | writel(SYSCFG_CMPENSETR_MPU_EN, syscfg + SYSCFG_CMPENSETR); |
| 523 | |
| 524 | while (!(readl(syscfg + SYSCFG_CMPCR) & SYSCFG_CMPCR_READY)) |
| 525 | ; |
| 526 | clrbits_le32(syscfg + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL); |
| 527 | #endif |
| 528 | } |
| 529 | |
Marek Vasut | 0839ea9 | 2020-03-28 02:01:58 +0100 | [diff] [blame] | 530 | static void board_init_fmc2(void) |
| 531 | { |
| 532 | #define STM32_FMC2_BCR1 0x0 |
| 533 | #define STM32_FMC2_BTR1 0x4 |
| 534 | #define STM32_FMC2_BWTR1 0x104 |
| 535 | #define STM32_FMC2_BCR(x) ((x) * 0x8 + STM32_FMC2_BCR1) |
| 536 | #define STM32_FMC2_BCRx_FMCEN BIT(31) |
| 537 | #define STM32_FMC2_BCRx_WREN BIT(12) |
| 538 | #define STM32_FMC2_BCRx_RSVD BIT(7) |
| 539 | #define STM32_FMC2_BCRx_FACCEN BIT(6) |
| 540 | #define STM32_FMC2_BCRx_MWID(n) ((n) << 4) |
| 541 | #define STM32_FMC2_BCRx_MTYP(n) ((n) << 2) |
| 542 | #define STM32_FMC2_BCRx_MUXEN BIT(1) |
| 543 | #define STM32_FMC2_BCRx_MBKEN BIT(0) |
| 544 | #define STM32_FMC2_BTR(x) ((x) * 0x8 + STM32_FMC2_BTR1) |
| 545 | #define STM32_FMC2_BTRx_DATAHLD(n) ((n) << 30) |
| 546 | #define STM32_FMC2_BTRx_BUSTURN(n) ((n) << 16) |
| 547 | #define STM32_FMC2_BTRx_DATAST(n) ((n) << 8) |
| 548 | #define STM32_FMC2_BTRx_ADDHLD(n) ((n) << 4) |
| 549 | #define STM32_FMC2_BTRx_ADDSET(n) ((n) << 0) |
| 550 | |
| 551 | #define RCC_MP_AHB6RSTCLRR 0x218 |
| 552 | #define RCC_MP_AHB6RSTCLRR_FMCRST BIT(12) |
| 553 | #define RCC_MP_AHB6ENSETR 0x19c |
| 554 | #define RCC_MP_AHB6ENSETR_FMCEN BIT(12) |
| 555 | |
| 556 | const u32 bcr = STM32_FMC2_BCRx_WREN |STM32_FMC2_BCRx_RSVD | |
| 557 | STM32_FMC2_BCRx_FACCEN | STM32_FMC2_BCRx_MWID(1) | |
| 558 | STM32_FMC2_BCRx_MTYP(2) | STM32_FMC2_BCRx_MUXEN | |
| 559 | STM32_FMC2_BCRx_MBKEN; |
| 560 | const u32 btr = STM32_FMC2_BTRx_DATAHLD(3) | |
| 561 | STM32_FMC2_BTRx_BUSTURN(2) | |
| 562 | STM32_FMC2_BTRx_DATAST(0x22) | |
| 563 | STM32_FMC2_BTRx_ADDHLD(2) | |
| 564 | STM32_FMC2_BTRx_ADDSET(2); |
| 565 | |
| 566 | /* Set up FMC2 bus for KS8851-16MLL and X11 SRAM */ |
| 567 | writel(RCC_MP_AHB6RSTCLRR_FMCRST, STM32_RCC_BASE + RCC_MP_AHB6RSTCLRR); |
| 568 | writel(RCC_MP_AHB6ENSETR_FMCEN, STM32_RCC_BASE + RCC_MP_AHB6ENSETR); |
| 569 | |
| 570 | /* KS8851-16MLL -- Muxed mode */ |
| 571 | writel(bcr, STM32_FMC2_BASE + STM32_FMC2_BCR(1)); |
| 572 | writel(btr, STM32_FMC2_BASE + STM32_FMC2_BTR(1)); |
| 573 | /* AS7C34098 SRAM on X11 -- Muxed mode */ |
| 574 | writel(bcr, STM32_FMC2_BASE + STM32_FMC2_BCR(3)); |
| 575 | writel(btr, STM32_FMC2_BASE + STM32_FMC2_BTR(3)); |
| 576 | |
| 577 | setbits_le32(STM32_FMC2_BASE + STM32_FMC2_BCR1, STM32_FMC2_BCRx_FMCEN); |
| 578 | } |
| 579 | |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 580 | /* board dependent setup after realloc */ |
| 581 | int board_init(void) |
| 582 | { |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 583 | /* address of boot parameters */ |
| 584 | gd->bd->bi_boot_params = STM32_DDR_BASE + 0x100; |
| 585 | |
Patrick Delaunay | 48bd3c9 | 2020-07-02 15:20:47 +0200 | [diff] [blame] | 586 | if (CONFIG_IS_ENABLED(DM_GPIO_HOG)) |
| 587 | gpio_hog_probe_all(); |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 588 | |
| 589 | board_key_check(); |
| 590 | |
| 591 | #ifdef CONFIG_DM_REGULATOR |
| 592 | regulators_enable_boot_on(_DEBUG); |
| 593 | #endif |
| 594 | |
| 595 | sysconf_init(); |
| 596 | |
Marek Vasut | 0839ea9 | 2020-03-28 02:01:58 +0100 | [diff] [blame] | 597 | board_init_fmc2(); |
| 598 | |
Patrick Delaunay | 78f68f2 | 2020-04-10 19:14:01 +0200 | [diff] [blame] | 599 | if (CONFIG_IS_ENABLED(LED)) |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 600 | led_default_state(); |
| 601 | |
| 602 | return 0; |
| 603 | } |
| 604 | |
| 605 | int board_late_init(void) |
| 606 | { |
| 607 | char *boot_device; |
| 608 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
| 609 | const void *fdt_compat; |
| 610 | int fdt_compat_len; |
| 611 | |
| 612 | fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible", |
| 613 | &fdt_compat_len); |
| 614 | if (fdt_compat && fdt_compat_len) { |
| 615 | if (strncmp(fdt_compat, "st,", 3) != 0) |
| 616 | env_set("board_name", fdt_compat); |
| 617 | else |
| 618 | env_set("board_name", fdt_compat + 3); |
| 619 | } |
| 620 | #endif |
| 621 | |
| 622 | /* Check the boot-source to disable bootdelay */ |
| 623 | boot_device = env_get("boot_device"); |
| 624 | if (!strcmp(boot_device, "serial") || !strcmp(boot_device, "usb")) |
| 625 | env_set("bootdelay", "0"); |
| 626 | |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 627 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
| 628 | env_set_ulong("dh_som_rev", somcode); |
| 629 | env_set_ulong("dh_board_rev", brdcode); |
Marek Vasut | 39221b5 | 2020-04-22 13:18:14 +0200 | [diff] [blame] | 630 | env_set_ulong("dh_ddr3_code", ddr3code); |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 631 | #endif |
| 632 | |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 633 | return 0; |
| 634 | } |
| 635 | |
| 636 | void board_quiesce_devices(void) |
| 637 | { |
| 638 | #ifdef CONFIG_LED |
| 639 | setup_led(LEDST_OFF); |
| 640 | #endif |
| 641 | } |
| 642 | |
| 643 | /* eth init function : weak called in eqos driver */ |
| 644 | int board_interface_eth_init(struct udevice *dev, |
| 645 | phy_interface_t interface_type) |
| 646 | { |
| 647 | u8 *syscfg; |
| 648 | u32 value; |
| 649 | bool eth_clk_sel_reg = false; |
| 650 | bool eth_ref_clk_sel_reg = false; |
| 651 | |
| 652 | /* Gigabit Ethernet 125MHz clock selection. */ |
| 653 | eth_clk_sel_reg = dev_read_bool(dev, "st,eth_clk_sel"); |
| 654 | |
| 655 | /* Ethernet 50Mhz RMII clock selection */ |
| 656 | eth_ref_clk_sel_reg = |
| 657 | dev_read_bool(dev, "st,eth_ref_clk_sel"); |
| 658 | |
| 659 | syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG); |
| 660 | |
| 661 | if (!syscfg) |
| 662 | return -ENODEV; |
| 663 | |
| 664 | switch (interface_type) { |
| 665 | case PHY_INTERFACE_MODE_MII: |
| 666 | value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII | |
| 667 | SYSCFG_PMCSETR_ETH_REF_CLK_SEL; |
| 668 | debug("%s: PHY_INTERFACE_MODE_MII\n", __func__); |
| 669 | break; |
| 670 | case PHY_INTERFACE_MODE_GMII: |
| 671 | if (eth_clk_sel_reg) |
| 672 | value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII | |
| 673 | SYSCFG_PMCSETR_ETH_CLK_SEL; |
| 674 | else |
| 675 | value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII; |
| 676 | debug("%s: PHY_INTERFACE_MODE_GMII\n", __func__); |
| 677 | break; |
| 678 | case PHY_INTERFACE_MODE_RMII: |
| 679 | if (eth_ref_clk_sel_reg) |
| 680 | value = SYSCFG_PMCSETR_ETH_SEL_RMII | |
| 681 | SYSCFG_PMCSETR_ETH_REF_CLK_SEL; |
| 682 | else |
| 683 | value = SYSCFG_PMCSETR_ETH_SEL_RMII; |
| 684 | debug("%s: PHY_INTERFACE_MODE_RMII\n", __func__); |
| 685 | break; |
| 686 | case PHY_INTERFACE_MODE_RGMII: |
| 687 | case PHY_INTERFACE_MODE_RGMII_ID: |
| 688 | case PHY_INTERFACE_MODE_RGMII_RXID: |
| 689 | case PHY_INTERFACE_MODE_RGMII_TXID: |
| 690 | if (eth_clk_sel_reg) |
| 691 | value = SYSCFG_PMCSETR_ETH_SEL_RGMII | |
| 692 | SYSCFG_PMCSETR_ETH_CLK_SEL; |
| 693 | else |
| 694 | value = SYSCFG_PMCSETR_ETH_SEL_RGMII; |
| 695 | debug("%s: PHY_INTERFACE_MODE_RGMII\n", __func__); |
| 696 | break; |
| 697 | default: |
| 698 | debug("%s: Do not manage %d interface\n", |
| 699 | __func__, interface_type); |
| 700 | /* Do not manage others interfaces */ |
| 701 | return -EINVAL; |
| 702 | } |
| 703 | |
| 704 | /* clear and set ETH configuration bits */ |
| 705 | writel(SYSCFG_PMCSETR_ETH_SEL_MASK | SYSCFG_PMCSETR_ETH_SELMII | |
| 706 | SYSCFG_PMCSETR_ETH_REF_CLK_SEL | SYSCFG_PMCSETR_ETH_CLK_SEL, |
| 707 | syscfg + SYSCFG_PMCCLRR); |
| 708 | writel(value, syscfg + SYSCFG_PMCSETR); |
| 709 | |
| 710 | return 0; |
| 711 | } |
| 712 | |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 713 | #if defined(CONFIG_OF_BOARD_SETUP) |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 714 | int ft_board_setup(void *blob, struct bd_info *bd) |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 715 | { |
| 716 | return 0; |
| 717 | } |
| 718 | #endif |
| 719 | |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 720 | static void board_copro_image_process(ulong fw_image, size_t fw_size) |
| 721 | { |
| 722 | int ret, id = 0; /* Copro id fixed to 0 as only one coproc on mp1 */ |
| 723 | |
| 724 | if (!rproc_is_initialized()) |
| 725 | if (rproc_init()) { |
| 726 | printf("Remote Processor %d initialization failed\n", |
| 727 | id); |
| 728 | return; |
| 729 | } |
| 730 | |
| 731 | ret = rproc_load(id, fw_image, fw_size); |
| 732 | printf("Load Remote Processor %d with data@addr=0x%08lx %u bytes:%s\n", |
| 733 | id, fw_image, fw_size, ret ? " Failed!" : " Success!"); |
| 734 | |
| 735 | if (!ret) { |
| 736 | rproc_start(id); |
| 737 | env_set("copro_state", "booted"); |
| 738 | } |
| 739 | } |
| 740 | |
| 741 | U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_COPRO, board_copro_image_process); |