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