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 | 8eb3b1e | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2018, STMicroelectronics - All Rights Reserved |
Patrick Delaunay | 8eb3b1e | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 4 | */ |
Patrice Chotard | 879cde5 | 2019-02-12 16:50:40 +0100 | [diff] [blame] | 5 | #include <common.h> |
| 6 | #include <adc.h> |
Patrick Delaunay | 500401f | 2019-06-21 15:26:40 +0200 | [diff] [blame] | 7 | #include <bootm.h> |
Patrice Chotard | 204079b | 2018-08-10 17:12:14 +0200 | [diff] [blame] | 8 | #include <clk.h> |
Patrick Delaunay | 266bf10 | 2019-07-30 19:16:44 +0200 | [diff] [blame] | 9 | #include <config.h> |
Patrice Chotard | 204079b | 2018-08-10 17:12:14 +0200 | [diff] [blame] | 10 | #include <dm.h> |
Simon Glass | db22961 | 2019-08-01 09:46:42 -0600 | [diff] [blame] | 11 | #include <env.h> |
Simon Glass | 9d1f619 | 2019-08-02 09:44:25 -0600 | [diff] [blame] | 12 | #include <env_internal.h> |
Simon Glass | 2dc9c34 | 2020-05-10 11:40:01 -0600 | [diff] [blame] | 13 | #include <fdt_support.h> |
Patrick Delaunay | 58bc0cd | 2019-03-29 15:42:23 +0100 | [diff] [blame] | 14 | #include <g_dnl.h> |
Patrice Chotard | 204079b | 2018-08-10 17:12:14 +0200 | [diff] [blame] | 15 | #include <generic-phy.h> |
Simon Glass | f11478f | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 16 | #include <hang.h> |
Patrick Delaunay | 7f3384d | 2019-03-29 15:42:24 +0100 | [diff] [blame] | 17 | #include <i2c.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 18 | #include <init.h> |
Patrick Delaunay | 92dc102 | 2019-02-12 11:44:41 +0100 | [diff] [blame] | 19 | #include <led.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 20 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 21 | #include <malloc.h> |
Patrick Delaunay | 92dc102 | 2019-02-12 11:44:41 +0100 | [diff] [blame] | 22 | #include <misc.h> |
Patrick Delaunay | de98cbf | 2019-07-02 13:26:07 +0200 | [diff] [blame] | 23 | #include <mtd_node.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 24 | #include <net.h> |
Patrick Delaunay | bff66f9 | 2019-08-01 11:29:03 +0200 | [diff] [blame] | 25 | #include <netdev.h> |
Patrice Chotard | 204079b | 2018-08-10 17:12:14 +0200 | [diff] [blame] | 26 | #include <phy.h> |
Patrick Delaunay | c17d725 | 2019-08-02 15:07:20 +0200 | [diff] [blame] | 27 | #include <remoteproc.h> |
Patrice Chotard | 204079b | 2018-08-10 17:12:14 +0200 | [diff] [blame] | 28 | #include <reset.h> |
Patrick Delaunay | 4ace1d1 | 2019-02-27 17:01:24 +0100 | [diff] [blame] | 29 | #include <syscon.h> |
Patrick Delaunay | 7f3384d | 2019-03-29 15:42:24 +0100 | [diff] [blame] | 30 | #include <usb.h> |
Patrick Delaunay | ae0931d0 | 2019-07-30 19:16:39 +0200 | [diff] [blame] | 31 | #include <watchdog.h> |
Patrice Chotard | 204079b | 2018-08-10 17:12:14 +0200 | [diff] [blame] | 32 | #include <asm/io.h> |
Patrick Delaunay | f2a7b87 | 2019-02-27 17:01:18 +0100 | [diff] [blame] | 33 | #include <asm/gpio.h> |
Patrick Delaunay | 4ace1d1 | 2019-02-27 17:01:24 +0100 | [diff] [blame] | 34 | #include <asm/arch/stm32.h> |
Patrice Chotard | dad97bf | 2019-05-02 18:36:01 +0200 | [diff] [blame] | 35 | #include <asm/arch/sys_proto.h> |
Patrick Delaunay | de98cbf | 2019-07-02 13:26:07 +0200 | [diff] [blame] | 36 | #include <jffs2/load_kernel.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 37 | #include <linux/bitops.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 38 | #include <linux/delay.h> |
Simon Glass | d66c5f7 | 2020-02-03 07:36:15 -0700 | [diff] [blame] | 39 | #include <linux/err.h> |
Patrick Delaunay | 181298e | 2020-04-22 14:29:16 +0200 | [diff] [blame] | 40 | #include <linux/iopoll.h> |
Patrice Chotard | 204079b | 2018-08-10 17:12:14 +0200 | [diff] [blame] | 41 | #include <power/regulator.h> |
Patrick Delaunay | 7f3384d | 2019-03-29 15:42:24 +0100 | [diff] [blame] | 42 | #include <usb/dwc2_udc.h> |
Patrick Delaunay | 8eb3b1e | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 43 | |
Patrick Delaunay | 4ace1d1 | 2019-02-27 17:01:24 +0100 | [diff] [blame] | 44 | /* SYSCFG registers */ |
| 45 | #define SYSCFG_BOOTR 0x00 |
| 46 | #define SYSCFG_PMCSETR 0x04 |
| 47 | #define SYSCFG_IOCTRLSETR 0x18 |
| 48 | #define SYSCFG_ICNR 0x1C |
| 49 | #define SYSCFG_CMPCR 0x20 |
| 50 | #define SYSCFG_CMPENSETR 0x24 |
| 51 | #define SYSCFG_PMCCLRR 0x44 |
| 52 | |
| 53 | #define SYSCFG_BOOTR_BOOT_MASK GENMASK(2, 0) |
| 54 | #define SYSCFG_BOOTR_BOOTPD_SHIFT 4 |
| 55 | |
| 56 | #define SYSCFG_IOCTRLSETR_HSLVEN_TRACE BIT(0) |
| 57 | #define SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI BIT(1) |
| 58 | #define SYSCFG_IOCTRLSETR_HSLVEN_ETH BIT(2) |
| 59 | #define SYSCFG_IOCTRLSETR_HSLVEN_SDMMC BIT(3) |
| 60 | #define SYSCFG_IOCTRLSETR_HSLVEN_SPI BIT(4) |
| 61 | |
| 62 | #define SYSCFG_CMPCR_SW_CTRL BIT(1) |
| 63 | #define SYSCFG_CMPCR_READY BIT(8) |
| 64 | |
| 65 | #define SYSCFG_CMPENSETR_MPU_EN BIT(0) |
| 66 | |
| 67 | #define SYSCFG_PMCSETR_ETH_CLK_SEL BIT(16) |
| 68 | #define SYSCFG_PMCSETR_ETH_REF_CLK_SEL BIT(17) |
| 69 | |
| 70 | #define SYSCFG_PMCSETR_ETH_SELMII BIT(20) |
| 71 | |
| 72 | #define SYSCFG_PMCSETR_ETH_SEL_MASK GENMASK(23, 21) |
Christophe Roullier | 69ac3f5 | 2019-05-17 15:08:43 +0200 | [diff] [blame] | 73 | #define SYSCFG_PMCSETR_ETH_SEL_GMII_MII 0 |
| 74 | #define SYSCFG_PMCSETR_ETH_SEL_RGMII BIT(21) |
| 75 | #define SYSCFG_PMCSETR_ETH_SEL_RMII BIT(23) |
Patrick Delaunay | 4ace1d1 | 2019-02-27 17:01:24 +0100 | [diff] [blame] | 76 | |
Patrick Delaunay | 8eb3b1e | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 77 | /* |
| 78 | * Get a global data pointer |
| 79 | */ |
| 80 | DECLARE_GLOBAL_DATA_PTR; |
| 81 | |
Patrice Chotard | cded32f | 2019-04-30 18:09:38 +0200 | [diff] [blame] | 82 | #define USB_LOW_THRESHOLD_UV 200000 |
Patrice Chotard | 879cde5 | 2019-02-12 16:50:40 +0100 | [diff] [blame] | 83 | #define USB_WARNING_LOW_THRESHOLD_UV 660000 |
| 84 | #define USB_START_LOW_THRESHOLD_UV 1230000 |
Patrice Chotard | cded32f | 2019-04-30 18:09:38 +0200 | [diff] [blame] | 85 | #define USB_START_HIGH_THRESHOLD_UV 2150000 |
Patrice Chotard | 879cde5 | 2019-02-12 16:50:40 +0100 | [diff] [blame] | 86 | |
Patrick Delaunay | 92dc102 | 2019-02-12 11:44:41 +0100 | [diff] [blame] | 87 | int checkboard(void) |
| 88 | { |
| 89 | int ret; |
| 90 | char *mode; |
| 91 | u32 otp; |
| 92 | struct udevice *dev; |
| 93 | const char *fdt_compat; |
| 94 | int fdt_compat_len; |
| 95 | |
Patrick Delaunay | 472407a | 2020-03-18 09:22:49 +0100 | [diff] [blame] | 96 | if (IS_ENABLED(CONFIG_TFABOOT)) |
Patrick Delaunay | 92dc102 | 2019-02-12 11:44:41 +0100 | [diff] [blame] | 97 | mode = "trusted"; |
| 98 | else |
| 99 | mode = "basic"; |
| 100 | |
| 101 | printf("Board: stm32mp1 in %s mode", mode); |
| 102 | fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible", |
| 103 | &fdt_compat_len); |
| 104 | if (fdt_compat && fdt_compat_len) |
| 105 | printf(" (%s)", fdt_compat); |
| 106 | puts("\n"); |
| 107 | |
Patrick Delaunay | 52163d9 | 2020-03-24 09:05:00 +0100 | [diff] [blame] | 108 | /* display the STMicroelectronics board identification */ |
Patrick Delaunay | 0885c23 | 2020-02-12 19:37:42 +0100 | [diff] [blame] | 109 | if (CONFIG_IS_ENABLED(CMD_STBOARD)) { |
| 110 | ret = uclass_get_device_by_driver(UCLASS_MISC, |
| 111 | DM_GET_DRIVER(stm32mp_bsec), |
| 112 | &dev); |
| 113 | if (!ret) |
| 114 | ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD), |
| 115 | &otp, sizeof(otp)); |
| 116 | if (ret > 0 && otp) |
| 117 | printf("Board: MB%04x Var%d.%d Rev.%c-%02d\n", |
| 118 | otp >> 16, |
| 119 | (otp >> 12) & 0xF, |
| 120 | (otp >> 4) & 0xF, |
| 121 | ((otp >> 8) & 0xF) - 1 + 'A', |
| 122 | otp & 0xF); |
Patrick Delaunay | 92dc102 | 2019-02-12 11:44:41 +0100 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | return 0; |
| 126 | } |
| 127 | |
Patrick Delaunay | 008d3c3 | 2019-02-27 17:01:20 +0100 | [diff] [blame] | 128 | static void board_key_check(void) |
| 129 | { |
| 130 | #if defined(CONFIG_FASTBOOT) || defined(CONFIG_CMD_STM32PROG) |
| 131 | ofnode node; |
| 132 | struct gpio_desc gpio; |
| 133 | enum forced_boot_mode boot_mode = BOOT_NORMAL; |
| 134 | |
| 135 | node = ofnode_path("/config"); |
| 136 | if (!ofnode_valid(node)) { |
| 137 | debug("%s: no /config node?\n", __func__); |
| 138 | return; |
| 139 | } |
| 140 | #ifdef CONFIG_FASTBOOT |
| 141 | if (gpio_request_by_name_nodev(node, "st,fastboot-gpios", 0, |
| 142 | &gpio, GPIOD_IS_IN)) { |
| 143 | debug("%s: could not find a /config/st,fastboot-gpios\n", |
| 144 | __func__); |
| 145 | } else { |
| 146 | if (dm_gpio_get_value(&gpio)) { |
| 147 | puts("Fastboot key pressed, "); |
| 148 | boot_mode = BOOT_FASTBOOT; |
| 149 | } |
| 150 | |
| 151 | dm_gpio_free(NULL, &gpio); |
| 152 | } |
| 153 | #endif |
| 154 | #ifdef CONFIG_CMD_STM32PROG |
| 155 | if (gpio_request_by_name_nodev(node, "st,stm32prog-gpios", 0, |
| 156 | &gpio, GPIOD_IS_IN)) { |
| 157 | debug("%s: could not find a /config/st,stm32prog-gpios\n", |
| 158 | __func__); |
| 159 | } else { |
| 160 | if (dm_gpio_get_value(&gpio)) { |
| 161 | puts("STM32Programmer key pressed, "); |
| 162 | boot_mode = BOOT_STM32PROG; |
| 163 | } |
| 164 | dm_gpio_free(NULL, &gpio); |
| 165 | } |
| 166 | #endif |
| 167 | |
| 168 | if (boot_mode != BOOT_NORMAL) { |
| 169 | puts("entering download mode...\n"); |
| 170 | clrsetbits_le32(TAMP_BOOT_CONTEXT, |
| 171 | TAMP_BOOT_FORCED_MASK, |
| 172 | boot_mode); |
| 173 | } |
| 174 | #endif |
| 175 | } |
| 176 | |
Patrick Delaunay | 58bc0cd | 2019-03-29 15:42:23 +0100 | [diff] [blame] | 177 | #if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG) |
Patrice Chotard | 204079b | 2018-08-10 17:12:14 +0200 | [diff] [blame] | 178 | |
Patrick Delaunay | 7f3384d | 2019-03-29 15:42:24 +0100 | [diff] [blame] | 179 | /* STMicroelectronics STUSB1600 Type-C controller */ |
| 180 | #define STUSB1600_CC_CONNECTION_STATUS 0x0E |
| 181 | |
| 182 | /* STUSB1600_CC_CONNECTION_STATUS bitfields */ |
| 183 | #define STUSB1600_CC_ATTACH BIT(0) |
| 184 | |
| 185 | static int stusb1600_init(struct udevice **dev_stusb1600) |
| 186 | { |
| 187 | ofnode node; |
| 188 | struct udevice *dev, *bus; |
| 189 | int ret; |
| 190 | u32 chip_addr; |
| 191 | |
| 192 | *dev_stusb1600 = NULL; |
| 193 | |
| 194 | /* if node stusb1600 is present, means DK1 or DK2 board */ |
| 195 | node = ofnode_by_compatible(ofnode_null(), "st,stusb1600"); |
| 196 | if (!ofnode_valid(node)) |
| 197 | return -ENODEV; |
| 198 | |
| 199 | ret = ofnode_read_u32(node, "reg", &chip_addr); |
| 200 | if (ret) |
| 201 | return -EINVAL; |
| 202 | |
| 203 | ret = uclass_get_device_by_ofnode(UCLASS_I2C, ofnode_get_parent(node), |
| 204 | &bus); |
| 205 | if (ret) { |
| 206 | printf("bus for stusb1600 not found\n"); |
| 207 | return -ENODEV; |
| 208 | } |
| 209 | |
| 210 | ret = dm_i2c_probe(bus, chip_addr, 0, &dev); |
| 211 | if (!ret) |
| 212 | *dev_stusb1600 = dev; |
| 213 | |
| 214 | return ret; |
| 215 | } |
| 216 | |
| 217 | static int stusb1600_cable_connected(struct udevice *dev) |
| 218 | { |
| 219 | u8 status; |
| 220 | |
| 221 | if (dm_i2c_read(dev, STUSB1600_CC_CONNECTION_STATUS, &status, 1)) |
| 222 | return 0; |
| 223 | |
| 224 | return status & STUSB1600_CC_ATTACH; |
| 225 | } |
| 226 | |
| 227 | #include <usb/dwc2_udc.h> |
Patrick Delaunay | 58bc0cd | 2019-03-29 15:42:23 +0100 | [diff] [blame] | 228 | int g_dnl_board_usb_cable_connected(void) |
Patrice Chotard | 204079b | 2018-08-10 17:12:14 +0200 | [diff] [blame] | 229 | { |
Patrick Delaunay | 7f3384d | 2019-03-29 15:42:24 +0100 | [diff] [blame] | 230 | struct udevice *stusb1600; |
Patrick Delaunay | 58bc0cd | 2019-03-29 15:42:23 +0100 | [diff] [blame] | 231 | struct udevice *dwc2_udc_otg; |
Patrice Chotard | 204079b | 2018-08-10 17:12:14 +0200 | [diff] [blame] | 232 | int ret; |
| 233 | |
Patrick Delaunay | 7f3384d | 2019-03-29 15:42:24 +0100 | [diff] [blame] | 234 | if (!stusb1600_init(&stusb1600)) |
| 235 | return stusb1600_cable_connected(stusb1600); |
| 236 | |
Patrick Delaunay | 58bc0cd | 2019-03-29 15:42:23 +0100 | [diff] [blame] | 237 | ret = uclass_get_device_by_driver(UCLASS_USB_GADGET_GENERIC, |
| 238 | DM_GET_DRIVER(dwc2_udc_otg), |
| 239 | &dwc2_udc_otg); |
| 240 | if (!ret) |
| 241 | debug("dwc2_udc_otg init failed\n"); |
Patrice Chotard | 204079b | 2018-08-10 17:12:14 +0200 | [diff] [blame] | 242 | |
Patrick Delaunay | 58bc0cd | 2019-03-29 15:42:23 +0100 | [diff] [blame] | 243 | return dwc2_udc_B_session_valid(dwc2_udc_otg); |
Patrice Chotard | 879cde5 | 2019-02-12 16:50:40 +0100 | [diff] [blame] | 244 | } |
Patrick Delaunay | 0aafce6 | 2019-09-13 15:24:17 +0200 | [diff] [blame] | 245 | |
| 246 | #define STM32MP1_G_DNL_DFU_PRODUCT_NUM 0xdf11 |
| 247 | #define STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM 0x0afb |
| 248 | |
| 249 | int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name) |
| 250 | { |
| 251 | if (!strcmp(name, "usb_dnl_dfu")) |
| 252 | put_unaligned(STM32MP1_G_DNL_DFU_PRODUCT_NUM, &dev->idProduct); |
| 253 | else if (!strcmp(name, "usb_dnl_fastboot")) |
| 254 | put_unaligned(STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM, |
| 255 | &dev->idProduct); |
| 256 | else |
| 257 | put_unaligned(CONFIG_USB_GADGET_PRODUCT_NUM, &dev->idProduct); |
| 258 | |
| 259 | return 0; |
| 260 | } |
| 261 | |
Patrick Delaunay | 58bc0cd | 2019-03-29 15:42:23 +0100 | [diff] [blame] | 262 | #endif /* CONFIG_USB_GADGET */ |
Patrice Chotard | 879cde5 | 2019-02-12 16:50:40 +0100 | [diff] [blame] | 263 | |
| 264 | static int get_led(struct udevice **dev, char *led_string) |
| 265 | { |
| 266 | char *led_name; |
| 267 | int ret; |
| 268 | |
| 269 | led_name = fdtdec_get_config_string(gd->fdt_blob, led_string); |
| 270 | if (!led_name) { |
| 271 | pr_debug("%s: could not find %s config string\n", |
| 272 | __func__, led_string); |
| 273 | return -ENOENT; |
| 274 | } |
| 275 | ret = led_get_by_label(led_name, dev); |
| 276 | if (ret) { |
| 277 | debug("%s: get=%d\n", __func__, ret); |
| 278 | return ret; |
| 279 | } |
| 280 | |
| 281 | return 0; |
| 282 | } |
| 283 | |
| 284 | static int setup_led(enum led_state_t cmd) |
| 285 | { |
| 286 | struct udevice *dev; |
| 287 | int ret; |
| 288 | |
Patrick Delaunay | 8ae05cf | 2020-04-22 14:29:12 +0200 | [diff] [blame] | 289 | if (!CONFIG_IS_ENABLED(LED)) |
| 290 | return 0; |
| 291 | |
Patrice Chotard | 879cde5 | 2019-02-12 16:50:40 +0100 | [diff] [blame] | 292 | ret = get_led(&dev, "u-boot,boot-led"); |
| 293 | if (ret) |
| 294 | return ret; |
| 295 | |
| 296 | ret = led_set_state(dev, cmd); |
Patrice Chotard | 204079b | 2018-08-10 17:12:14 +0200 | [diff] [blame] | 297 | return ret; |
| 298 | } |
Patrick Delaunay | ae0931d0 | 2019-07-30 19:16:39 +0200 | [diff] [blame] | 299 | |
| 300 | static void __maybe_unused led_error_blink(u32 nb_blink) |
| 301 | { |
Patrick Delaunay | ae0931d0 | 2019-07-30 19:16:39 +0200 | [diff] [blame] | 302 | int ret; |
| 303 | struct udevice *led; |
| 304 | u32 i; |
Patrick Delaunay | ae0931d0 | 2019-07-30 19:16:39 +0200 | [diff] [blame] | 305 | |
| 306 | if (!nb_blink) |
| 307 | return; |
| 308 | |
Patrick Delaunay | 8ae05cf | 2020-04-22 14:29:12 +0200 | [diff] [blame] | 309 | if (CONFIG_IS_ENABLED(LED)) { |
| 310 | ret = get_led(&led, "u-boot,error-led"); |
| 311 | if (!ret) { |
| 312 | /* make u-boot,error-led blinking */ |
| 313 | /* if U32_MAX and 125ms interval, for 17.02 years */ |
| 314 | for (i = 0; i < 2 * nb_blink; i++) { |
| 315 | led_set_state(led, LEDST_TOGGLE); |
| 316 | mdelay(125); |
| 317 | WATCHDOG_RESET(); |
| 318 | } |
| 319 | led_set_state(led, LEDST_ON); |
Patrick Delaunay | ae0931d0 | 2019-07-30 19:16:39 +0200 | [diff] [blame] | 320 | } |
| 321 | } |
Patrick Delaunay | ae0931d0 | 2019-07-30 19:16:39 +0200 | [diff] [blame] | 322 | |
| 323 | /* infinite: the boot process must be stopped */ |
| 324 | if (nb_blink == U32_MAX) |
| 325 | hang(); |
| 326 | } |
Patrice Chotard | 204079b | 2018-08-10 17:12:14 +0200 | [diff] [blame] | 327 | |
Patrick Delaunay | f6626e7 | 2019-07-30 19:16:43 +0200 | [diff] [blame] | 328 | #ifdef CONFIG_ADC |
Patrice Chotard | 879cde5 | 2019-02-12 16:50:40 +0100 | [diff] [blame] | 329 | static int board_check_usb_power(void) |
| 330 | { |
| 331 | struct ofnode_phandle_args adc_args; |
| 332 | struct udevice *adc; |
Patrice Chotard | 879cde5 | 2019-02-12 16:50:40 +0100 | [diff] [blame] | 333 | ofnode node; |
| 334 | unsigned int raw; |
| 335 | int max_uV = 0; |
Patrice Chotard | cded32f | 2019-04-30 18:09:38 +0200 | [diff] [blame] | 336 | int min_uV = USB_START_HIGH_THRESHOLD_UV; |
Patrice Chotard | 879cde5 | 2019-02-12 16:50:40 +0100 | [diff] [blame] | 337 | int ret, uV, adc_count; |
Patrice Chotard | cded32f | 2019-04-30 18:09:38 +0200 | [diff] [blame] | 338 | u32 nb_blink; |
| 339 | u8 i; |
Patrice Chotard | 879cde5 | 2019-02-12 16:50:40 +0100 | [diff] [blame] | 340 | node = ofnode_path("/config"); |
| 341 | if (!ofnode_valid(node)) { |
| 342 | debug("%s: no /config node?\n", __func__); |
| 343 | return -ENOENT; |
| 344 | } |
| 345 | |
| 346 | /* |
| 347 | * Retrieve the ADC channels devices and get measurement |
| 348 | * for each of them |
| 349 | */ |
| 350 | adc_count = ofnode_count_phandle_with_args(node, "st,adc_usb_pd", |
| 351 | "#io-channel-cells"); |
| 352 | if (adc_count < 0) { |
| 353 | if (adc_count == -ENOENT) |
| 354 | return 0; |
| 355 | |
| 356 | pr_err("%s: can't find adc channel (%d)\n", __func__, |
| 357 | adc_count); |
| 358 | |
| 359 | return adc_count; |
| 360 | } |
| 361 | |
| 362 | for (i = 0; i < adc_count; i++) { |
| 363 | if (ofnode_parse_phandle_with_args(node, "st,adc_usb_pd", |
| 364 | "#io-channel-cells", 0, i, |
| 365 | &adc_args)) { |
| 366 | pr_debug("%s: can't find /config/st,adc_usb_pd\n", |
| 367 | __func__); |
| 368 | return 0; |
| 369 | } |
| 370 | |
| 371 | ret = uclass_get_device_by_ofnode(UCLASS_ADC, adc_args.node, |
| 372 | &adc); |
| 373 | |
| 374 | if (ret) { |
| 375 | pr_err("%s: Can't get adc device(%d)\n", __func__, |
| 376 | ret); |
| 377 | return ret; |
| 378 | } |
| 379 | |
| 380 | ret = adc_channel_single_shot(adc->name, adc_args.args[0], |
| 381 | &raw); |
| 382 | if (ret) { |
| 383 | pr_err("%s: single shot failed for %s[%d]!\n", |
| 384 | __func__, adc->name, adc_args.args[0]); |
| 385 | return ret; |
| 386 | } |
| 387 | /* Convert to uV */ |
| 388 | if (!adc_raw_to_uV(adc, raw, &uV)) { |
| 389 | if (uV > max_uV) |
| 390 | max_uV = uV; |
Patrice Chotard | cded32f | 2019-04-30 18:09:38 +0200 | [diff] [blame] | 391 | if (uV < min_uV) |
| 392 | min_uV = uV; |
Patrice Chotard | 879cde5 | 2019-02-12 16:50:40 +0100 | [diff] [blame] | 393 | pr_debug("%s: %s[%02d] = %u, %d uV\n", __func__, |
| 394 | adc->name, adc_args.args[0], raw, uV); |
| 395 | } else { |
| 396 | pr_err("%s: Can't get uV value for %s[%d]\n", |
| 397 | __func__, adc->name, adc_args.args[0]); |
| 398 | } |
| 399 | } |
| 400 | |
| 401 | /* |
| 402 | * If highest value is inside 1.23 Volts and 2.10 Volts, that means |
| 403 | * board is plugged on an USB-C 3A power supply and boot process can |
| 404 | * continue. |
| 405 | */ |
| 406 | if (max_uV > USB_START_LOW_THRESHOLD_UV && |
Patrice Chotard | cded32f | 2019-04-30 18:09:38 +0200 | [diff] [blame] | 407 | max_uV <= USB_START_HIGH_THRESHOLD_UV && |
| 408 | min_uV <= USB_LOW_THRESHOLD_UV) |
Patrice Chotard | 879cde5 | 2019-02-12 16:50:40 +0100 | [diff] [blame] | 409 | return 0; |
| 410 | |
Patrice Chotard | cded32f | 2019-04-30 18:09:38 +0200 | [diff] [blame] | 411 | pr_err("****************************************************\n"); |
| 412 | |
| 413 | /* |
| 414 | * If highest and lowest value are either both below |
| 415 | * USB_LOW_THRESHOLD_UV or both above USB_LOW_THRESHOLD_UV, that |
| 416 | * means USB TYPE-C is in unattached mode, this is an issue, make |
| 417 | * u-boot,error-led blinking and stop boot process. |
| 418 | */ |
| 419 | if ((max_uV > USB_LOW_THRESHOLD_UV && |
| 420 | min_uV > USB_LOW_THRESHOLD_UV) || |
| 421 | (max_uV <= USB_LOW_THRESHOLD_UV && |
| 422 | min_uV <= USB_LOW_THRESHOLD_UV)) { |
| 423 | pr_err("* ERROR USB TYPE-C connection in unattached mode *\n"); |
| 424 | pr_err("* Check that USB TYPE-C cable is correctly plugged *\n"); |
| 425 | /* with 125ms interval, led will blink for 17.02 years ....*/ |
| 426 | nb_blink = U32_MAX; |
| 427 | } |
Patrice Chotard | 879cde5 | 2019-02-12 16:50:40 +0100 | [diff] [blame] | 428 | |
Patrice Chotard | cded32f | 2019-04-30 18:09:38 +0200 | [diff] [blame] | 429 | if (max_uV > USB_LOW_THRESHOLD_UV && |
| 430 | max_uV <= USB_WARNING_LOW_THRESHOLD_UV && |
| 431 | min_uV <= USB_LOW_THRESHOLD_UV) { |
| 432 | pr_err("* WARNING 500mA power supply detected *\n"); |
Patrice Chotard | 879cde5 | 2019-02-12 16:50:40 +0100 | [diff] [blame] | 433 | nb_blink = 2; |
Patrice Chotard | cded32f | 2019-04-30 18:09:38 +0200 | [diff] [blame] | 434 | } |
| 435 | |
| 436 | if (max_uV > USB_WARNING_LOW_THRESHOLD_UV && |
| 437 | max_uV <= USB_START_LOW_THRESHOLD_UV && |
| 438 | min_uV <= USB_LOW_THRESHOLD_UV) { |
Patrice Chotard | 2d583f9 | 2020-04-30 18:41:05 +0200 | [diff] [blame] | 439 | pr_err("* WARNING 1.5A power supply detected *\n"); |
Patrice Chotard | 879cde5 | 2019-02-12 16:50:40 +0100 | [diff] [blame] | 440 | nb_blink = 3; |
| 441 | } |
| 442 | |
Patrice Chotard | cded32f | 2019-04-30 18:09:38 +0200 | [diff] [blame] | 443 | /* |
| 444 | * If highest value is above 2.15 Volts that means that the USB TypeC |
| 445 | * supplies more than 3 Amp, this is not compliant with TypeC specification |
| 446 | */ |
| 447 | if (max_uV > USB_START_HIGH_THRESHOLD_UV) { |
| 448 | pr_err("* USB TYPE-C charger not compliant with *\n"); |
| 449 | pr_err("* specification *\n"); |
| 450 | pr_err("****************************************************\n\n"); |
| 451 | /* with 125ms interval, led will blink for 17.02 years ....*/ |
| 452 | nb_blink = U32_MAX; |
| 453 | } else { |
| 454 | pr_err("* Current too low, use a 3A power supply! *\n"); |
| 455 | pr_err("****************************************************\n\n"); |
| 456 | } |
Patrice Chotard | 879cde5 | 2019-02-12 16:50:40 +0100 | [diff] [blame] | 457 | |
Patrick Delaunay | ae0931d0 | 2019-07-30 19:16:39 +0200 | [diff] [blame] | 458 | led_error_blink(nb_blink); |
Patrice Chotard | 879cde5 | 2019-02-12 16:50:40 +0100 | [diff] [blame] | 459 | |
| 460 | return 0; |
| 461 | } |
Patrick Delaunay | f6626e7 | 2019-07-30 19:16:43 +0200 | [diff] [blame] | 462 | #endif /* CONFIG_ADC */ |
Patrice Chotard | 879cde5 | 2019-02-12 16:50:40 +0100 | [diff] [blame] | 463 | |
Patrick Delaunay | 4ace1d1 | 2019-02-27 17:01:24 +0100 | [diff] [blame] | 464 | static void sysconf_init(void) |
| 465 | { |
Patrick Delaunay | f8fe21d | 2020-04-01 09:07:33 +0200 | [diff] [blame] | 466 | #ifndef CONFIG_TFABOOT |
Patrick Delaunay | 4ace1d1 | 2019-02-27 17:01:24 +0100 | [diff] [blame] | 467 | u8 *syscfg; |
| 468 | #ifdef CONFIG_DM_REGULATOR |
| 469 | struct udevice *pwr_dev; |
| 470 | struct udevice *pwr_reg; |
| 471 | struct udevice *dev; |
Patrick Delaunay | 4ace1d1 | 2019-02-27 17:01:24 +0100 | [diff] [blame] | 472 | u32 otp = 0; |
| 473 | #endif |
Patrick Delaunay | 181298e | 2020-04-22 14:29:16 +0200 | [diff] [blame] | 474 | int ret; |
| 475 | u32 bootr, val; |
Patrick Delaunay | 4ace1d1 | 2019-02-27 17:01:24 +0100 | [diff] [blame] | 476 | |
| 477 | syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG); |
| 478 | |
| 479 | /* interconnect update : select master using the port 1 */ |
| 480 | /* LTDC = AXI_M9 */ |
| 481 | /* GPU = AXI_M8 */ |
| 482 | /* today information is hardcoded in U-Boot */ |
| 483 | writel(BIT(9), syscfg + SYSCFG_ICNR); |
| 484 | |
| 485 | /* disable Pull-Down for boot pin connected to VDD */ |
| 486 | bootr = readl(syscfg + SYSCFG_BOOTR); |
| 487 | bootr &= ~(SYSCFG_BOOTR_BOOT_MASK << SYSCFG_BOOTR_BOOTPD_SHIFT); |
| 488 | bootr |= (bootr & SYSCFG_BOOTR_BOOT_MASK) << SYSCFG_BOOTR_BOOTPD_SHIFT; |
| 489 | writel(bootr, syscfg + SYSCFG_BOOTR); |
| 490 | |
| 491 | #ifdef CONFIG_DM_REGULATOR |
| 492 | /* High Speed Low Voltage Pad mode Enable for SPI, SDMMC, ETH, QSPI |
| 493 | * and TRACE. Needed above ~50MHz and conditioned by AFMUX selection. |
| 494 | * The customer will have to disable this for low frequencies |
| 495 | * or if AFMUX is selected but the function not used, typically for |
| 496 | * TRACE. Otherwise, impact on power consumption. |
| 497 | * |
| 498 | * WARNING: |
| 499 | * enabling High Speed mode while VDD>2.7V |
| 500 | * with the OTP product_below_2v5 (OTP 18, BIT 13) |
| 501 | * erroneously set to 1 can damage the IC! |
| 502 | * => U-Boot set the register only if VDD < 2.7V (in DT) |
| 503 | * but this value need to be consistent with board design |
| 504 | */ |
Patrick Delaunay | 6b2baa0 | 2019-07-30 19:16:42 +0200 | [diff] [blame] | 505 | ret = uclass_get_device_by_driver(UCLASS_PMIC, |
| 506 | DM_GET_DRIVER(stm32mp_pwr_pmic), |
| 507 | &pwr_dev); |
Patrick Delaunay | 4ace1d1 | 2019-02-27 17:01:24 +0100 | [diff] [blame] | 508 | if (!ret) { |
| 509 | ret = uclass_get_device_by_driver(UCLASS_MISC, |
| 510 | DM_GET_DRIVER(stm32mp_bsec), |
| 511 | &dev); |
| 512 | if (ret) { |
| 513 | pr_err("Can't find stm32mp_bsec driver\n"); |
| 514 | return; |
| 515 | } |
| 516 | |
| 517 | ret = misc_read(dev, STM32_BSEC_SHADOW(18), &otp, 4); |
Patrick Delaunay | ceb82e3 | 2019-08-02 13:08:06 +0200 | [diff] [blame] | 518 | if (ret > 0) |
Patrick Delaunay | 4ace1d1 | 2019-02-27 17:01:24 +0100 | [diff] [blame] | 519 | otp = otp & BIT(13); |
| 520 | |
Patrick Delaunay | 6b2baa0 | 2019-07-30 19:16:42 +0200 | [diff] [blame] | 521 | /* get VDD = vdd-supply */ |
| 522 | ret = device_get_supply_regulator(pwr_dev, "vdd-supply", |
Patrick Delaunay | 4ace1d1 | 2019-02-27 17:01:24 +0100 | [diff] [blame] | 523 | &pwr_reg); |
| 524 | |
| 525 | /* check if VDD is Low Voltage */ |
| 526 | if (!ret) { |
| 527 | if (regulator_get_value(pwr_reg) < 2700000) { |
| 528 | writel(SYSCFG_IOCTRLSETR_HSLVEN_TRACE | |
| 529 | SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI | |
| 530 | SYSCFG_IOCTRLSETR_HSLVEN_ETH | |
| 531 | SYSCFG_IOCTRLSETR_HSLVEN_SDMMC | |
| 532 | SYSCFG_IOCTRLSETR_HSLVEN_SPI, |
| 533 | syscfg + SYSCFG_IOCTRLSETR); |
| 534 | |
| 535 | if (!otp) |
| 536 | pr_err("product_below_2v5=0: HSLVEN protected by HW\n"); |
| 537 | } else { |
| 538 | if (otp) |
| 539 | pr_err("product_below_2v5=1: HSLVEN update is destructive, no update as VDD>2.7V\n"); |
| 540 | } |
| 541 | } else { |
| 542 | debug("VDD unknown"); |
| 543 | } |
| 544 | } |
| 545 | #endif |
| 546 | |
| 547 | /* activate automatic I/O compensation |
| 548 | * warning: need to ensure CSI enabled and ready in clock driver |
| 549 | */ |
| 550 | writel(SYSCFG_CMPENSETR_MPU_EN, syscfg + SYSCFG_CMPENSETR); |
| 551 | |
Patrick Delaunay | 181298e | 2020-04-22 14:29:16 +0200 | [diff] [blame] | 552 | /* poll until ready (1s timeout) */ |
| 553 | ret = readl_poll_timeout(syscfg + SYSCFG_CMPCR, val, |
| 554 | val & SYSCFG_CMPCR_READY, |
| 555 | 1000000); |
| 556 | if (ret) { |
| 557 | pr_err("SYSCFG: I/O compensation failed, timeout.\n"); |
| 558 | led_error_blink(10); |
| 559 | } |
| 560 | |
Patrick Delaunay | 4ace1d1 | 2019-02-27 17:01:24 +0100 | [diff] [blame] | 561 | clrbits_le32(syscfg + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL); |
| 562 | #endif |
| 563 | } |
| 564 | |
Patrick Delaunay | 9f76fdf | 2019-07-30 19:16:38 +0200 | [diff] [blame] | 565 | #ifdef CONFIG_DM_REGULATOR |
| 566 | /* Fix to make I2C1 usable on DK2 for touchscreen usage in kernel */ |
| 567 | static int dk2_i2c1_fix(void) |
| 568 | { |
| 569 | ofnode node; |
| 570 | struct gpio_desc hdmi, audio; |
| 571 | int ret = 0; |
| 572 | |
| 573 | node = ofnode_path("/soc/i2c@40012000/hdmi-transmitter@39"); |
| 574 | if (!ofnode_valid(node)) { |
| 575 | pr_debug("%s: no hdmi-transmitter@39 ?\n", __func__); |
| 576 | return -ENOENT; |
| 577 | } |
| 578 | |
| 579 | if (gpio_request_by_name_nodev(node, "reset-gpios", 0, |
| 580 | &hdmi, GPIOD_IS_OUT)) { |
| 581 | pr_debug("%s: could not find reset-gpios\n", |
| 582 | __func__); |
| 583 | return -ENOENT; |
| 584 | } |
| 585 | |
| 586 | node = ofnode_path("/soc/i2c@40012000/cs42l51@4a"); |
| 587 | if (!ofnode_valid(node)) { |
| 588 | pr_debug("%s: no cs42l51@4a ?\n", __func__); |
| 589 | return -ENOENT; |
| 590 | } |
| 591 | |
| 592 | if (gpio_request_by_name_nodev(node, "reset-gpios", 0, |
| 593 | &audio, GPIOD_IS_OUT)) { |
| 594 | pr_debug("%s: could not find reset-gpios\n", |
| 595 | __func__); |
| 596 | return -ENOENT; |
| 597 | } |
| 598 | |
| 599 | /* before power up, insure that HDMI and AUDIO IC is under reset */ |
| 600 | ret = dm_gpio_set_value(&hdmi, 1); |
| 601 | if (ret) { |
| 602 | pr_err("%s: can't set_value for hdmi_nrst gpio", __func__); |
| 603 | goto error; |
| 604 | } |
| 605 | ret = dm_gpio_set_value(&audio, 1); |
| 606 | if (ret) { |
| 607 | pr_err("%s: can't set_value for audio_nrst gpio", __func__); |
| 608 | goto error; |
| 609 | } |
| 610 | |
| 611 | /* power-up audio IC */ |
| 612 | regulator_autoset_by_name("v1v8_audio", NULL); |
| 613 | |
| 614 | /* power-up HDMI IC */ |
| 615 | regulator_autoset_by_name("v1v2_hdmi", NULL); |
| 616 | regulator_autoset_by_name("v3v3_hdmi", NULL); |
| 617 | |
| 618 | error: |
| 619 | return ret; |
| 620 | } |
| 621 | |
| 622 | static bool board_is_dk2(void) |
| 623 | { |
Patrick Delaunay | 310aa8a | 2020-01-13 15:17:42 +0100 | [diff] [blame] | 624 | if (CONFIG_IS_ENABLED(TARGET_ST_STM32MP15x) && |
Patrick Delaunay | 9f76fdf | 2019-07-30 19:16:38 +0200 | [diff] [blame] | 625 | of_machine_is_compatible("st,stm32mp157c-dk2")) |
| 626 | return true; |
| 627 | |
| 628 | return false; |
| 629 | } |
| 630 | #endif |
| 631 | |
Patrick Delaunay | 486ae96 | 2020-04-22 14:29:13 +0200 | [diff] [blame] | 632 | static bool board_is_ev1(void) |
| 633 | { |
| 634 | if (CONFIG_IS_ENABLED(TARGET_ST_STM32MP15x) && |
| 635 | (of_machine_is_compatible("st,stm32mp157a-ev1") || |
| 636 | of_machine_is_compatible("st,stm32mp157c-ev1") || |
| 637 | of_machine_is_compatible("st,stm32mp157d-ev1") || |
| 638 | of_machine_is_compatible("st,stm32mp157f-ev1"))) |
| 639 | return true; |
| 640 | |
| 641 | return false; |
| 642 | } |
| 643 | |
| 644 | /* touchscreen driver: only used for pincontrol configuration */ |
| 645 | static const struct udevice_id goodix_ids[] = { |
| 646 | { .compatible = "goodix,gt9147", }, |
| 647 | { } |
| 648 | }; |
| 649 | |
| 650 | U_BOOT_DRIVER(goodix) = { |
| 651 | .name = "goodix", |
| 652 | .id = UCLASS_NOP, |
| 653 | .of_match = goodix_ids, |
| 654 | }; |
| 655 | |
| 656 | static void board_ev1_init(void) |
| 657 | { |
| 658 | struct udevice *dev; |
| 659 | |
| 660 | /* configure IRQ line on EV1 for touchscreen before LCD reset */ |
| 661 | uclass_get_device_by_driver(UCLASS_NOP, DM_GET_DRIVER(goodix), &dev); |
| 662 | } |
| 663 | |
Patrick Delaunay | 8eb3b1e | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 664 | /* board dependent setup after realloc */ |
| 665 | int board_init(void) |
| 666 | { |
Patrice Chotard | 972723a | 2019-03-11 11:13:17 +0100 | [diff] [blame] | 667 | struct udevice *dev; |
| 668 | |
Patrick Delaunay | 8eb3b1e | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 669 | /* address of boot parameters */ |
| 670 | gd->bd->bi_boot_params = STM32_DDR_BASE + 0x100; |
| 671 | |
Patrice Chotard | 972723a | 2019-03-11 11:13:17 +0100 | [diff] [blame] | 672 | /* probe all PINCTRL for hog */ |
| 673 | for (uclass_first_device(UCLASS_PINCTRL, &dev); |
| 674 | dev; |
| 675 | uclass_next_device(&dev)) { |
| 676 | pr_debug("probe pincontrol = %s\n", dev->name); |
| 677 | } |
| 678 | |
Patrick Delaunay | 008d3c3 | 2019-02-27 17:01:20 +0100 | [diff] [blame] | 679 | board_key_check(); |
| 680 | |
Patrick Delaunay | 486ae96 | 2020-04-22 14:29:13 +0200 | [diff] [blame] | 681 | if (board_is_ev1()) |
| 682 | board_ev1_init(); |
| 683 | |
Patrick Delaunay | 6519e44 | 2019-07-05 17:20:09 +0200 | [diff] [blame] | 684 | #ifdef CONFIG_DM_REGULATOR |
Patrick Delaunay | 9f76fdf | 2019-07-30 19:16:38 +0200 | [diff] [blame] | 685 | if (board_is_dk2()) |
| 686 | dk2_i2c1_fix(); |
| 687 | |
Patrick Delaunay | 6519e44 | 2019-07-05 17:20:09 +0200 | [diff] [blame] | 688 | regulators_enable_boot_on(_DEBUG); |
| 689 | #endif |
| 690 | |
Patrick Delaunay | 4ace1d1 | 2019-02-27 17:01:24 +0100 | [diff] [blame] | 691 | sysconf_init(); |
| 692 | |
Patrick Delaunay | 78f68f2 | 2020-04-10 19:14:01 +0200 | [diff] [blame] | 693 | if (CONFIG_IS_ENABLED(LED)) |
Patrick Delaunay | 36e3d11 | 2018-07-27 16:37:08 +0200 | [diff] [blame] | 694 | led_default_state(); |
| 695 | |
Patrick Delaunay | 8ae05cf | 2020-04-22 14:29:12 +0200 | [diff] [blame] | 696 | setup_led(LEDST_ON); |
| 697 | |
Patrick Delaunay | 8eb3b1e | 2018-03-12 10:46:18 +0100 | [diff] [blame] | 698 | return 0; |
| 699 | } |
Patrick Delaunay | d70e3f8 | 2019-02-27 17:01:11 +0100 | [diff] [blame] | 700 | |
| 701 | int board_late_init(void) |
| 702 | { |
| 703 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
| 704 | const void *fdt_compat; |
| 705 | int fdt_compat_len; |
Patrick Delaunay | e8566ec | 2019-07-30 19:16:37 +0200 | [diff] [blame] | 706 | int ret; |
| 707 | u32 otp; |
| 708 | struct udevice *dev; |
| 709 | char buf[10]; |
Patrick Delaunay | d70e3f8 | 2019-02-27 17:01:11 +0100 | [diff] [blame] | 710 | |
| 711 | fdt_compat = fdt_getprop(gd->fdt_blob, 0, "compatible", |
| 712 | &fdt_compat_len); |
| 713 | if (fdt_compat && fdt_compat_len) { |
Patrick Delaunay | 4533a2c | 2020-04-22 14:29:14 +0200 | [diff] [blame] | 714 | if (strncmp(fdt_compat, "st,", 3) != 0) { |
Patrick Delaunay | d70e3f8 | 2019-02-27 17:01:11 +0100 | [diff] [blame] | 715 | env_set("board_name", fdt_compat); |
Patrick Delaunay | 4533a2c | 2020-04-22 14:29:14 +0200 | [diff] [blame] | 716 | } else { |
| 717 | char dtb_name[256]; |
| 718 | int buf_len = sizeof(dtb_name); |
| 719 | |
Patrick Delaunay | d70e3f8 | 2019-02-27 17:01:11 +0100 | [diff] [blame] | 720 | env_set("board_name", fdt_compat + 3); |
Patrick Delaunay | 4533a2c | 2020-04-22 14:29:14 +0200 | [diff] [blame] | 721 | |
| 722 | strncpy(dtb_name, fdt_compat + 3, buf_len); |
| 723 | buf_len -= strlen(fdt_compat + 3); |
| 724 | strncat(dtb_name, ".dtb", buf_len); |
| 725 | env_set("fdtfile", dtb_name); |
| 726 | } |
Patrick Delaunay | d70e3f8 | 2019-02-27 17:01:11 +0100 | [diff] [blame] | 727 | } |
Patrick Delaunay | e8566ec | 2019-07-30 19:16:37 +0200 | [diff] [blame] | 728 | ret = uclass_get_device_by_driver(UCLASS_MISC, |
| 729 | DM_GET_DRIVER(stm32mp_bsec), |
| 730 | &dev); |
| 731 | |
| 732 | if (!ret) |
| 733 | ret = misc_read(dev, STM32_BSEC_SHADOW(BSEC_OTP_BOARD), |
| 734 | &otp, sizeof(otp)); |
| 735 | if (!ret && otp) { |
| 736 | snprintf(buf, sizeof(buf), "0x%04x", otp >> 16); |
| 737 | env_set("board_id", buf); |
| 738 | |
| 739 | snprintf(buf, sizeof(buf), "0x%04x", |
| 740 | ((otp >> 8) & 0xF) - 1 + 0xA); |
| 741 | env_set("board_rev", buf); |
| 742 | } |
Patrick Delaunay | d70e3f8 | 2019-02-27 17:01:11 +0100 | [diff] [blame] | 743 | #endif |
| 744 | |
Patrick Delaunay | f6626e7 | 2019-07-30 19:16:43 +0200 | [diff] [blame] | 745 | #ifdef CONFIG_ADC |
Patrice Chotard | 879cde5 | 2019-02-12 16:50:40 +0100 | [diff] [blame] | 746 | /* for DK1/DK2 boards */ |
| 747 | board_check_usb_power(); |
Patrick Delaunay | f6626e7 | 2019-07-30 19:16:43 +0200 | [diff] [blame] | 748 | #endif /* CONFIG_ADC */ |
Patrice Chotard | 879cde5 | 2019-02-12 16:50:40 +0100 | [diff] [blame] | 749 | |
Patrick Delaunay | d70e3f8 | 2019-02-27 17:01:11 +0100 | [diff] [blame] | 750 | return 0; |
| 751 | } |
Patrice Chotard | 879cde5 | 2019-02-12 16:50:40 +0100 | [diff] [blame] | 752 | |
| 753 | void board_quiesce_devices(void) |
| 754 | { |
| 755 | setup_led(LEDST_OFF); |
| 756 | } |
Patrice Chotard | 41443cf | 2019-05-02 18:07:14 +0200 | [diff] [blame] | 757 | |
Patrick Delaunay | bff66f9 | 2019-08-01 11:29:03 +0200 | [diff] [blame] | 758 | /* eth init function : weak called in eqos driver */ |
| 759 | int board_interface_eth_init(struct udevice *dev, |
| 760 | phy_interface_t interface_type) |
Christophe Roullier | 69ac3f5 | 2019-05-17 15:08:43 +0200 | [diff] [blame] | 761 | { |
| 762 | u8 *syscfg; |
| 763 | u32 value; |
Patrick Delaunay | bff66f9 | 2019-08-01 11:29:03 +0200 | [diff] [blame] | 764 | bool eth_clk_sel_reg = false; |
| 765 | bool eth_ref_clk_sel_reg = false; |
| 766 | |
| 767 | /* Gigabit Ethernet 125MHz clock selection. */ |
| 768 | eth_clk_sel_reg = dev_read_bool(dev, "st,eth_clk_sel"); |
| 769 | |
| 770 | /* Ethernet 50Mhz RMII clock selection */ |
| 771 | eth_ref_clk_sel_reg = |
| 772 | dev_read_bool(dev, "st,eth_ref_clk_sel"); |
Christophe Roullier | 69ac3f5 | 2019-05-17 15:08:43 +0200 | [diff] [blame] | 773 | |
| 774 | syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG); |
| 775 | |
| 776 | if (!syscfg) |
| 777 | return -ENODEV; |
| 778 | |
| 779 | switch (interface_type) { |
| 780 | case PHY_INTERFACE_MODE_MII: |
| 781 | value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII | |
| 782 | SYSCFG_PMCSETR_ETH_REF_CLK_SEL; |
| 783 | debug("%s: PHY_INTERFACE_MODE_MII\n", __func__); |
| 784 | break; |
| 785 | case PHY_INTERFACE_MODE_GMII: |
| 786 | if (eth_clk_sel_reg) |
| 787 | value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII | |
| 788 | SYSCFG_PMCSETR_ETH_CLK_SEL; |
| 789 | else |
| 790 | value = SYSCFG_PMCSETR_ETH_SEL_GMII_MII; |
| 791 | debug("%s: PHY_INTERFACE_MODE_GMII\n", __func__); |
| 792 | break; |
| 793 | case PHY_INTERFACE_MODE_RMII: |
| 794 | if (eth_ref_clk_sel_reg) |
| 795 | value = SYSCFG_PMCSETR_ETH_SEL_RMII | |
| 796 | SYSCFG_PMCSETR_ETH_REF_CLK_SEL; |
| 797 | else |
| 798 | value = SYSCFG_PMCSETR_ETH_SEL_RMII; |
| 799 | debug("%s: PHY_INTERFACE_MODE_RMII\n", __func__); |
| 800 | break; |
| 801 | case PHY_INTERFACE_MODE_RGMII: |
| 802 | case PHY_INTERFACE_MODE_RGMII_ID: |
| 803 | case PHY_INTERFACE_MODE_RGMII_RXID: |
| 804 | case PHY_INTERFACE_MODE_RGMII_TXID: |
| 805 | if (eth_clk_sel_reg) |
| 806 | value = SYSCFG_PMCSETR_ETH_SEL_RGMII | |
| 807 | SYSCFG_PMCSETR_ETH_CLK_SEL; |
| 808 | else |
| 809 | value = SYSCFG_PMCSETR_ETH_SEL_RGMII; |
| 810 | debug("%s: PHY_INTERFACE_MODE_RGMII\n", __func__); |
| 811 | break; |
| 812 | default: |
| 813 | debug("%s: Do not manage %d interface\n", |
| 814 | __func__, interface_type); |
| 815 | /* Do not manage others interfaces */ |
| 816 | return -EINVAL; |
| 817 | } |
| 818 | |
| 819 | /* clear and set ETH configuration bits */ |
| 820 | writel(SYSCFG_PMCSETR_ETH_SEL_MASK | SYSCFG_PMCSETR_ETH_SELMII | |
| 821 | SYSCFG_PMCSETR_ETH_REF_CLK_SEL | SYSCFG_PMCSETR_ETH_CLK_SEL, |
| 822 | syscfg + SYSCFG_PMCCLRR); |
| 823 | writel(value, syscfg + SYSCFG_PMCSETR); |
| 824 | |
| 825 | return 0; |
| 826 | } |
| 827 | |
Patrice Chotard | 3432037 | 2019-05-02 18:28:05 +0200 | [diff] [blame] | 828 | enum env_location env_get_location(enum env_operation op, int prio) |
| 829 | { |
| 830 | u32 bootmode = get_bootmode(); |
| 831 | |
| 832 | if (prio) |
| 833 | return ENVL_UNKNOWN; |
| 834 | |
| 835 | switch (bootmode & TAMP_BOOT_DEVICE_MASK) { |
| 836 | #ifdef CONFIG_ENV_IS_IN_EXT4 |
| 837 | case BOOT_FLASH_SD: |
| 838 | case BOOT_FLASH_EMMC: |
| 839 | return ENVL_EXT4; |
| 840 | #endif |
| 841 | #ifdef CONFIG_ENV_IS_IN_UBI |
| 842 | case BOOT_FLASH_NAND: |
Patrick Delaunay | b5a7ca2 | 2020-03-18 09:22:52 +0100 | [diff] [blame] | 843 | case BOOT_FLASH_SPINAND: |
Patrice Chotard | 3432037 | 2019-05-02 18:28:05 +0200 | [diff] [blame] | 844 | return ENVL_UBI; |
| 845 | #endif |
Patrice Chotard | 2c461ec | 2019-05-09 14:25:36 +0200 | [diff] [blame] | 846 | #ifdef CONFIG_ENV_IS_IN_SPI_FLASH |
| 847 | case BOOT_FLASH_NOR: |
| 848 | return ENVL_SPI_FLASH; |
| 849 | #endif |
Patrice Chotard | 3432037 | 2019-05-02 18:28:05 +0200 | [diff] [blame] | 850 | default: |
| 851 | return ENVL_NOWHERE; |
| 852 | } |
| 853 | } |
| 854 | |
Patrice Chotard | dad97bf | 2019-05-02 18:36:01 +0200 | [diff] [blame] | 855 | #if defined(CONFIG_ENV_IS_IN_EXT4) |
| 856 | const char *env_ext4_get_intf(void) |
| 857 | { |
| 858 | u32 bootmode = get_bootmode(); |
| 859 | |
| 860 | switch (bootmode & TAMP_BOOT_DEVICE_MASK) { |
| 861 | case BOOT_FLASH_SD: |
| 862 | case BOOT_FLASH_EMMC: |
| 863 | return "mmc"; |
| 864 | default: |
| 865 | return ""; |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | const char *env_ext4_get_dev_part(void) |
| 870 | { |
| 871 | static char *const dev_part[] = {"0:auto", "1:auto", "2:auto"}; |
| 872 | u32 bootmode = get_bootmode(); |
| 873 | |
| 874 | return dev_part[(bootmode & TAMP_BOOT_INSTANCE_MASK) - 1]; |
| 875 | } |
| 876 | #endif |
| 877 | |
Patrick Delaunay | de98cbf | 2019-07-02 13:26:07 +0200 | [diff] [blame] | 878 | #if defined(CONFIG_OF_BOARD_SETUP) |
| 879 | int ft_board_setup(void *blob, bd_t *bd) |
| 880 | { |
| 881 | #ifdef CONFIG_FDT_FIXUP_PARTITIONS |
| 882 | struct node_info nodes[] = { |
| 883 | { "st,stm32f469-qspi", MTD_DEV_TYPE_NOR, }, |
Patrick Delaunay | b5a7ca2 | 2020-03-18 09:22:52 +0100 | [diff] [blame] | 884 | { "st,stm32f469-qspi", MTD_DEV_TYPE_SPINAND}, |
Patrick Delaunay | de98cbf | 2019-07-02 13:26:07 +0200 | [diff] [blame] | 885 | { "st,stm32mp15-fmc2", MTD_DEV_TYPE_NAND, }, |
| 886 | }; |
| 887 | fdt_fixup_mtdparts(blob, nodes, ARRAY_SIZE(nodes)); |
| 888 | #endif |
| 889 | |
| 890 | return 0; |
| 891 | } |
| 892 | #endif |
Patrick Delaunay | c17d725 | 2019-08-02 15:07:20 +0200 | [diff] [blame] | 893 | |
| 894 | static void board_copro_image_process(ulong fw_image, size_t fw_size) |
| 895 | { |
| 896 | int ret, id = 0; /* Copro id fixed to 0 as only one coproc on mp1 */ |
| 897 | |
| 898 | if (!rproc_is_initialized()) |
| 899 | if (rproc_init()) { |
| 900 | printf("Remote Processor %d initialization failed\n", |
| 901 | id); |
| 902 | return; |
| 903 | } |
| 904 | |
| 905 | ret = rproc_load(id, fw_image, fw_size); |
| 906 | printf("Load Remote Processor %d with data@addr=0x%08lx %u bytes:%s\n", |
| 907 | id, fw_image, fw_size, ret ? " Failed!" : " Success!"); |
| 908 | |
Fabien Dessenne | ad6cc94 | 2019-10-30 14:38:32 +0100 | [diff] [blame] | 909 | if (!ret) |
Patrick Delaunay | c17d725 | 2019-08-02 15:07:20 +0200 | [diff] [blame] | 910 | rproc_start(id); |
Patrick Delaunay | c17d725 | 2019-08-02 15:07:20 +0200 | [diff] [blame] | 911 | } |
| 912 | |
| 913 | U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_COPRO, board_copro_image_process); |