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