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