Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ OR BSD-3-Clause |
| 2 | /* |
| 3 | * Copyright (C) 2018, STMicroelectronics - All Rights Reserved |
| 4 | */ |
| 5 | |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 6 | #include <adc.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 7 | #include <log.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 8 | #include <net.h> |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 9 | #include <asm/arch/stm32.h> |
| 10 | #include <asm/arch/sys_proto.h> |
| 11 | #include <asm/gpio.h> |
| 12 | #include <asm/io.h> |
| 13 | #include <bootm.h> |
| 14 | #include <clk.h> |
| 15 | #include <config.h> |
| 16 | #include <dm.h> |
| 17 | #include <dm/device.h> |
| 18 | #include <dm/uclass.h> |
| 19 | #include <env.h> |
| 20 | #include <env_internal.h> |
| 21 | #include <g_dnl.h> |
| 22 | #include <generic-phy.h> |
| 23 | #include <hang.h> |
| 24 | #include <i2c.h> |
| 25 | #include <i2c_eeprom.h> |
| 26 | #include <init.h> |
| 27 | #include <led.h> |
| 28 | #include <memalign.h> |
| 29 | #include <misc.h> |
| 30 | #include <mtd.h> |
| 31 | #include <mtd_node.h> |
| 32 | #include <netdev.h> |
| 33 | #include <phy.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 34 | #include <linux/bitops.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 35 | #include <linux/delay.h> |
Simon Glass | bdd5f81 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 36 | #include <linux/printk.h> |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 37 | #include <power/regulator.h> |
| 38 | #include <remoteproc.h> |
| 39 | #include <reset.h> |
Marek Vasut | 3551654 | 2024-06-06 15:01:48 +0200 | [diff] [blame] | 40 | #include <spl.h> |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 41 | #include <syscon.h> |
| 42 | #include <usb.h> |
| 43 | #include <usb/dwc2_udc.h> |
| 44 | #include <watchdog.h> |
Simon Glass | 0034d96 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 45 | #include <dm/ofnode.h> |
Philip Oberfichtner | 78fa6b9 | 2022-07-26 15:04:53 +0200 | [diff] [blame] | 46 | #include "../common/dh_common.h" |
Patrick Delaunay | f2f25c3 | 2020-05-25 12:19:46 +0200 | [diff] [blame] | 47 | #include "../../st/common/stpmic1.h" |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 48 | |
| 49 | /* SYSCFG registers */ |
| 50 | #define SYSCFG_BOOTR 0x00 |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 51 | #define SYSCFG_IOCTRLSETR 0x18 |
| 52 | #define SYSCFG_ICNR 0x1C |
| 53 | #define SYSCFG_CMPCR 0x20 |
| 54 | #define SYSCFG_CMPENSETR 0x24 |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 55 | |
| 56 | #define SYSCFG_BOOTR_BOOT_MASK GENMASK(2, 0) |
| 57 | #define SYSCFG_BOOTR_BOOTPD_SHIFT 4 |
| 58 | |
| 59 | #define SYSCFG_IOCTRLSETR_HSLVEN_TRACE BIT(0) |
| 60 | #define SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI BIT(1) |
| 61 | #define SYSCFG_IOCTRLSETR_HSLVEN_ETH BIT(2) |
| 62 | #define SYSCFG_IOCTRLSETR_HSLVEN_SDMMC BIT(3) |
| 63 | #define SYSCFG_IOCTRLSETR_HSLVEN_SPI BIT(4) |
| 64 | |
| 65 | #define SYSCFG_CMPCR_SW_CTRL BIT(1) |
| 66 | #define SYSCFG_CMPCR_READY BIT(8) |
| 67 | |
| 68 | #define SYSCFG_CMPENSETR_MPU_EN BIT(0) |
| 69 | |
Marek Vasut | 145a876 | 2020-10-08 15:14:58 +0200 | [diff] [blame] | 70 | #define KS_CCR 0x08 |
| 71 | #define KS_CCR_EEPROM BIT(9) |
| 72 | #define KS_BE0 BIT(12) |
| 73 | #define KS_BE1 BIT(13) |
Marek Vasut | b2b31c1 | 2021-05-03 13:31:39 +0200 | [diff] [blame] | 74 | #define KS_CIDER 0xC0 |
| 75 | #define CIDER_ID 0x8870 |
Marek Vasut | 145a876 | 2020-10-08 15:14:58 +0200 | [diff] [blame] | 76 | |
Philip Oberfichtner | 78fa6b9 | 2022-07-26 15:04:53 +0200 | [diff] [blame] | 77 | static bool dh_stm32_mac_is_in_ks8851(void) |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 78 | { |
Patrick Delaunay | 280949c | 2022-06-06 16:04:15 +0200 | [diff] [blame] | 79 | ofnode node; |
Philip Oberfichtner | 78fa6b9 | 2022-07-26 15:04:53 +0200 | [diff] [blame] | 80 | u32 reg, cider, ccr; |
Marek Vasut | b0a2a49 | 2020-07-31 01:34:50 +0200 | [diff] [blame] | 81 | |
Patrick Delaunay | 280949c | 2022-06-06 16:04:15 +0200 | [diff] [blame] | 82 | node = ofnode_path("ethernet1"); |
Philip Oberfichtner | 78fa6b9 | 2022-07-26 15:04:53 +0200 | [diff] [blame] | 83 | if (!ofnode_valid(node)) |
| 84 | return false; |
Marek Vasut | 145a876 | 2020-10-08 15:14:58 +0200 | [diff] [blame] | 85 | |
Philip Oberfichtner | 78fa6b9 | 2022-07-26 15:04:53 +0200 | [diff] [blame] | 86 | if (ofnode_device_is_compatible(node, "micrel,ks8851-mll")) |
| 87 | return false; |
Marek Vasut | 145a876 | 2020-10-08 15:14:58 +0200 | [diff] [blame] | 88 | |
| 89 | /* |
| 90 | * KS8851 with EEPROM may use custom MAC from EEPROM, read |
| 91 | * out the KS8851 CCR register to determine whether EEPROM |
| 92 | * is present. If EEPROM is present, it must contain valid |
| 93 | * MAC address. |
| 94 | */ |
Patrick Delaunay | 280949c | 2022-06-06 16:04:15 +0200 | [diff] [blame] | 95 | reg = ofnode_get_addr(node); |
Marek Vasut | 145a876 | 2020-10-08 15:14:58 +0200 | [diff] [blame] | 96 | if (!reg) |
Philip Oberfichtner | 78fa6b9 | 2022-07-26 15:04:53 +0200 | [diff] [blame] | 97 | return false; |
Marek Vasut | 145a876 | 2020-10-08 15:14:58 +0200 | [diff] [blame] | 98 | |
Marek Vasut | b2b31c1 | 2021-05-03 13:31:39 +0200 | [diff] [blame] | 99 | writew(KS_BE0 | KS_BE1 | KS_CIDER, reg + 2); |
| 100 | cider = readw(reg); |
Philip Oberfichtner | 78fa6b9 | 2022-07-26 15:04:53 +0200 | [diff] [blame] | 101 | if ((cider & 0xfff0) != CIDER_ID) |
| 102 | return true; |
Marek Vasut | b2b31c1 | 2021-05-03 13:31:39 +0200 | [diff] [blame] | 103 | |
Marek Vasut | 145a876 | 2020-10-08 15:14:58 +0200 | [diff] [blame] | 104 | writew(KS_BE0 | KS_BE1 | KS_CCR, reg + 2); |
| 105 | ccr = readw(reg); |
Philip Oberfichtner | 78fa6b9 | 2022-07-26 15:04:53 +0200 | [diff] [blame] | 106 | if (ccr & KS_CCR_EEPROM) |
| 107 | return true; |
| 108 | |
| 109 | return false; |
| 110 | } |
Marek Vasut | b0a2a49 | 2020-07-31 01:34:50 +0200 | [diff] [blame] | 111 | |
Philip Oberfichtner | 78fa6b9 | 2022-07-26 15:04:53 +0200 | [diff] [blame] | 112 | static int dh_stm32_setup_ethaddr(void) |
| 113 | { |
| 114 | unsigned char enetaddr[6]; |
| 115 | |
| 116 | if (dh_mac_is_in_env("ethaddr")) |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 117 | return 0; |
| 118 | |
Marek Vasut | 29ab1a9 | 2024-03-12 22:15:58 +0100 | [diff] [blame] | 119 | if (dh_get_mac_is_enabled("ethernet0")) |
| 120 | return 0; |
| 121 | |
Philip Oberfichtner | 78fa6b9 | 2022-07-26 15:04:53 +0200 | [diff] [blame] | 122 | if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0")) |
| 123 | return eth_env_set_enetaddr("ethaddr", enetaddr); |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 124 | |
Philip Oberfichtner | 78fa6b9 | 2022-07-26 15:04:53 +0200 | [diff] [blame] | 125 | return -ENXIO; |
| 126 | } |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 127 | |
Philip Oberfichtner | 78fa6b9 | 2022-07-26 15:04:53 +0200 | [diff] [blame] | 128 | static int dh_stm32_setup_eth1addr(void) |
| 129 | { |
| 130 | unsigned char enetaddr[6]; |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 131 | |
Philip Oberfichtner | 78fa6b9 | 2022-07-26 15:04:53 +0200 | [diff] [blame] | 132 | if (dh_mac_is_in_env("eth1addr")) |
| 133 | return 0; |
Marek Vasut | b0a2a49 | 2020-07-31 01:34:50 +0200 | [diff] [blame] | 134 | |
Marek Vasut | 29ab1a9 | 2024-03-12 22:15:58 +0100 | [diff] [blame] | 135 | if (dh_get_mac_is_enabled("ethernet1")) |
| 136 | return 0; |
| 137 | |
Philip Oberfichtner | 78fa6b9 | 2022-07-26 15:04:53 +0200 | [diff] [blame] | 138 | if (dh_stm32_mac_is_in_ks8851()) |
| 139 | return 0; |
| 140 | |
| 141 | if (!dh_get_mac_from_eeprom(enetaddr, "eeprom0")) { |
Marek Vasut | b0a2a49 | 2020-07-31 01:34:50 +0200 | [diff] [blame] | 142 | enetaddr[5]++; |
Philip Oberfichtner | 78fa6b9 | 2022-07-26 15:04:53 +0200 | [diff] [blame] | 143 | return eth_env_set_enetaddr("eth1addr", enetaddr); |
Marek Vasut | b0a2a49 | 2020-07-31 01:34:50 +0200 | [diff] [blame] | 144 | } |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 145 | |
Philip Oberfichtner | 78fa6b9 | 2022-07-26 15:04:53 +0200 | [diff] [blame] | 146 | return -ENXIO; |
| 147 | } |
| 148 | |
| 149 | int setup_mac_address(void) |
| 150 | { |
| 151 | if (dh_stm32_setup_ethaddr()) |
| 152 | log_err("%s: Unable to setup ethaddr!\n", __func__); |
| 153 | |
| 154 | if (dh_stm32_setup_eth1addr()) |
| 155 | log_err("%s: Unable to setup eth1addr!\n", __func__); |
| 156 | |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 157 | return 0; |
| 158 | } |
| 159 | |
| 160 | int checkboard(void) |
| 161 | { |
| 162 | char *mode; |
| 163 | const char *fdt_compat; |
| 164 | int fdt_compat_len; |
| 165 | |
Patrick Delaunay | 472407a | 2020-03-18 09:22:49 +0100 | [diff] [blame] | 166 | if (IS_ENABLED(CONFIG_TFABOOT)) |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 167 | mode = "trusted"; |
| 168 | else |
| 169 | mode = "basic"; |
| 170 | |
| 171 | printf("Board: stm32mp1 in %s mode", mode); |
Patrick Delaunay | 280949c | 2022-06-06 16:04:15 +0200 | [diff] [blame] | 172 | fdt_compat = ofnode_get_property(ofnode_root(), "compatible", |
| 173 | &fdt_compat_len); |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 174 | if (fdt_compat && fdt_compat_len) |
| 175 | printf(" (%s)", fdt_compat); |
| 176 | puts("\n"); |
| 177 | |
| 178 | return 0; |
| 179 | } |
| 180 | |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 181 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
Marek Vasut | e5905ee | 2023-05-04 21:52:08 +0200 | [diff] [blame] | 182 | static u8 brdcode __section(".data"); |
| 183 | static u8 ddr3code __section(".data"); |
| 184 | static u8 somcode __section(".data"); |
Patrick Delaunay | 08c891a | 2020-05-25 12:19:47 +0200 | [diff] [blame] | 185 | static u32 opp_voltage_mv __section(".data"); |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 186 | |
| 187 | static void board_get_coding_straps(void) |
| 188 | { |
| 189 | struct gpio_desc gpio[4]; |
| 190 | ofnode node; |
| 191 | int i, ret; |
| 192 | |
Marek Vasut | 4bd7a5a | 2021-11-13 03:26:39 +0100 | [diff] [blame] | 193 | brdcode = 0; |
| 194 | ddr3code = 0; |
| 195 | somcode = 0; |
| 196 | |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 197 | node = ofnode_path("/config"); |
| 198 | if (!ofnode_valid(node)) { |
| 199 | printf("%s: no /config node?\n", __func__); |
| 200 | return; |
| 201 | } |
| 202 | |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 203 | ret = gpio_request_list_by_name_nodev(node, "dh,som-coding-gpios", |
| 204 | gpio, ARRAY_SIZE(gpio), |
| 205 | GPIOD_IS_IN); |
| 206 | for (i = 0; i < ret; i++) |
| 207 | somcode |= !!dm_gpio_get_value(&(gpio[i])) << i; |
| 208 | |
Marek Vasut | 4bd7a5a | 2021-11-13 03:26:39 +0100 | [diff] [blame] | 209 | gpio_free_list_nodev(gpio, ret); |
| 210 | |
Marek Vasut | 39221b5 | 2020-04-22 13:18:14 +0200 | [diff] [blame] | 211 | ret = gpio_request_list_by_name_nodev(node, "dh,ddr3-coding-gpios", |
| 212 | gpio, ARRAY_SIZE(gpio), |
| 213 | GPIOD_IS_IN); |
| 214 | for (i = 0; i < ret; i++) |
| 215 | ddr3code |= !!dm_gpio_get_value(&(gpio[i])) << i; |
| 216 | |
Marek Vasut | 4bd7a5a | 2021-11-13 03:26:39 +0100 | [diff] [blame] | 217 | gpio_free_list_nodev(gpio, ret); |
| 218 | |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 219 | ret = gpio_request_list_by_name_nodev(node, "dh,board-coding-gpios", |
| 220 | gpio, ARRAY_SIZE(gpio), |
| 221 | GPIOD_IS_IN); |
| 222 | for (i = 0; i < ret; i++) |
| 223 | brdcode |= !!dm_gpio_get_value(&(gpio[i])) << i; |
| 224 | |
Marek Vasut | 4bd7a5a | 2021-11-13 03:26:39 +0100 | [diff] [blame] | 225 | gpio_free_list_nodev(gpio, ret); |
| 226 | |
Harald Seiler | 1768f5d | 2023-09-27 14:46:25 +0200 | [diff] [blame] | 227 | if (CONFIG_IS_ENABLED(DISPLAY_PRINT)) |
| 228 | printf("Code: SoM:rev=%d,ddr3=%d Board:rev=%d\n", |
| 229 | somcode, ddr3code, brdcode); |
Marek Vasut | 39221b5 | 2020-04-22 13:18:14 +0200 | [diff] [blame] | 230 | } |
| 231 | |
| 232 | int board_stm32mp1_ddr_config_name_match(struct udevice *dev, |
| 233 | const char *name) |
| 234 | { |
Marek Vasut | 272198e | 2020-04-29 15:08:38 +0200 | [diff] [blame] | 235 | if (ddr3code == 1 && |
| 236 | !strcmp(name, "st,ddr3l-dhsom-1066-888-bin-g-2x1gb-533mhz")) |
| 237 | return 0; |
| 238 | |
Marek Vasut | 39221b5 | 2020-04-22 13:18:14 +0200 | [diff] [blame] | 239 | if (ddr3code == 2 && |
Marek Vasut | 272198e | 2020-04-29 15:08:38 +0200 | [diff] [blame] | 240 | !strcmp(name, "st,ddr3l-dhsom-1066-888-bin-g-2x2gb-533mhz")) |
Marek Vasut | 39221b5 | 2020-04-22 13:18:14 +0200 | [diff] [blame] | 241 | return 0; |
| 242 | |
| 243 | if (ddr3code == 3 && |
Marek Vasut | 272198e | 2020-04-29 15:08:38 +0200 | [diff] [blame] | 244 | !strcmp(name, "st,ddr3l-dhsom-1066-888-bin-g-2x4gb-533mhz")) |
Marek Vasut | 39221b5 | 2020-04-22 13:18:14 +0200 | [diff] [blame] | 245 | return 0; |
| 246 | |
| 247 | return -EINVAL; |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 248 | } |
| 249 | |
Patrick Delaunay | 08c891a | 2020-05-25 12:19:47 +0200 | [diff] [blame] | 250 | void board_vddcore_init(u32 voltage_mv) |
| 251 | { |
| 252 | if (IS_ENABLED(CONFIG_SPL_BUILD)) |
| 253 | opp_voltage_mv = voltage_mv; |
| 254 | } |
| 255 | |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 256 | int board_early_init_f(void) |
| 257 | { |
Patrick Delaunay | f2f25c3 | 2020-05-25 12:19:46 +0200 | [diff] [blame] | 258 | if (IS_ENABLED(CONFIG_SPL_BUILD)) |
Patrick Delaunay | 08c891a | 2020-05-25 12:19:47 +0200 | [diff] [blame] | 259 | stpmic1_init(opp_voltage_mv); |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 260 | board_get_coding_straps(); |
| 261 | |
| 262 | return 0; |
| 263 | } |
| 264 | |
| 265 | #ifdef CONFIG_SPL_LOAD_FIT |
| 266 | int board_fit_config_name_match(const char *name) |
| 267 | { |
Marek Vasut | 060cb12 | 2020-07-31 01:35:33 +0200 | [diff] [blame] | 268 | const char *compat; |
| 269 | char test[128]; |
| 270 | |
Patrick Delaunay | 280949c | 2022-06-06 16:04:15 +0200 | [diff] [blame] | 271 | compat = ofnode_get_property(ofnode_root(), "compatible", NULL); |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 272 | |
Marek Vasut | 060cb12 | 2020-07-31 01:35:33 +0200 | [diff] [blame] | 273 | snprintf(test, sizeof(test), "%s_somrev%d_boardrev%d", |
| 274 | compat, somcode, brdcode); |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 275 | |
| 276 | if (!strcmp(name, test)) |
| 277 | return 0; |
| 278 | |
| 279 | return -EINVAL; |
| 280 | } |
| 281 | #endif |
| 282 | #endif |
| 283 | |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 284 | static void board_key_check(void) |
| 285 | { |
| 286 | #if defined(CONFIG_FASTBOOT) || defined(CONFIG_CMD_STM32PROG) |
| 287 | ofnode node; |
| 288 | struct gpio_desc gpio; |
| 289 | enum forced_boot_mode boot_mode = BOOT_NORMAL; |
| 290 | |
| 291 | node = ofnode_path("/config"); |
| 292 | if (!ofnode_valid(node)) { |
| 293 | debug("%s: no /config node?\n", __func__); |
| 294 | return; |
| 295 | } |
| 296 | #ifdef CONFIG_FASTBOOT |
| 297 | if (gpio_request_by_name_nodev(node, "st,fastboot-gpios", 0, |
| 298 | &gpio, GPIOD_IS_IN)) { |
| 299 | debug("%s: could not find a /config/st,fastboot-gpios\n", |
| 300 | __func__); |
| 301 | } else { |
| 302 | if (dm_gpio_get_value(&gpio)) { |
| 303 | puts("Fastboot key pressed, "); |
| 304 | boot_mode = BOOT_FASTBOOT; |
| 305 | } |
| 306 | |
| 307 | dm_gpio_free(NULL, &gpio); |
| 308 | } |
| 309 | #endif |
| 310 | #ifdef CONFIG_CMD_STM32PROG |
| 311 | if (gpio_request_by_name_nodev(node, "st,stm32prog-gpios", 0, |
| 312 | &gpio, GPIOD_IS_IN)) { |
| 313 | debug("%s: could not find a /config/st,stm32prog-gpios\n", |
| 314 | __func__); |
| 315 | } else { |
| 316 | if (dm_gpio_get_value(&gpio)) { |
| 317 | puts("STM32Programmer key pressed, "); |
| 318 | boot_mode = BOOT_STM32PROG; |
| 319 | } |
| 320 | dm_gpio_free(NULL, &gpio); |
| 321 | } |
| 322 | #endif |
| 323 | |
| 324 | if (boot_mode != BOOT_NORMAL) { |
| 325 | puts("entering download mode...\n"); |
| 326 | clrsetbits_le32(TAMP_BOOT_CONTEXT, |
| 327 | TAMP_BOOT_FORCED_MASK, |
| 328 | boot_mode); |
| 329 | } |
| 330 | #endif |
| 331 | } |
| 332 | |
| 333 | #if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG) |
| 334 | |
| 335 | #include <usb/dwc2_udc.h> |
| 336 | int g_dnl_board_usb_cable_connected(void) |
| 337 | { |
| 338 | struct udevice *dwc2_udc_otg; |
| 339 | int ret; |
| 340 | |
| 341 | ret = uclass_get_device_by_driver(UCLASS_USB_GADGET_GENERIC, |
Simon Glass | 65130cd | 2020-12-28 20:34:56 -0700 | [diff] [blame] | 342 | DM_DRIVER_GET(dwc2_udc_otg), |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 343 | &dwc2_udc_otg); |
| 344 | if (!ret) |
| 345 | debug("dwc2_udc_otg init failed\n"); |
| 346 | |
| 347 | return dwc2_udc_B_session_valid(dwc2_udc_otg); |
| 348 | } |
| 349 | |
| 350 | #define STM32MP1_G_DNL_DFU_PRODUCT_NUM 0xdf11 |
| 351 | #define STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM 0x0afb |
| 352 | |
| 353 | int g_dnl_bind_fixup(struct usb_device_descriptor *dev, const char *name) |
| 354 | { |
| 355 | if (!strcmp(name, "usb_dnl_dfu")) |
| 356 | put_unaligned(STM32MP1_G_DNL_DFU_PRODUCT_NUM, &dev->idProduct); |
| 357 | else if (!strcmp(name, "usb_dnl_fastboot")) |
| 358 | put_unaligned(STM32MP1_G_DNL_FASTBOOT_PRODUCT_NUM, |
| 359 | &dev->idProduct); |
| 360 | else |
| 361 | put_unaligned(CONFIG_USB_GADGET_PRODUCT_NUM, &dev->idProduct); |
| 362 | |
| 363 | return 0; |
| 364 | } |
| 365 | |
| 366 | #endif /* CONFIG_USB_GADGET */ |
| 367 | |
| 368 | #ifdef CONFIG_LED |
| 369 | static int get_led(struct udevice **dev, char *led_string) |
| 370 | { |
Simon Glass | 0034d96 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 371 | const char *led_name; |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 372 | int ret; |
| 373 | |
Simon Glass | 0034d96 | 2021-08-07 07:24:01 -0600 | [diff] [blame] | 374 | led_name = ofnode_conf_read_str(led_string); |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 375 | if (!led_name) { |
| 376 | pr_debug("%s: could not find %s config string\n", |
| 377 | __func__, led_string); |
| 378 | return -ENOENT; |
| 379 | } |
| 380 | ret = led_get_by_label(led_name, dev); |
| 381 | if (ret) { |
| 382 | debug("%s: get=%d\n", __func__, ret); |
| 383 | return ret; |
| 384 | } |
| 385 | |
| 386 | return 0; |
| 387 | } |
| 388 | |
| 389 | static int setup_led(enum led_state_t cmd) |
| 390 | { |
| 391 | struct udevice *dev; |
| 392 | int ret; |
| 393 | |
| 394 | ret = get_led(&dev, "u-boot,boot-led"); |
| 395 | if (ret) |
| 396 | return ret; |
| 397 | |
| 398 | ret = led_set_state(dev, cmd); |
| 399 | return ret; |
| 400 | } |
| 401 | #endif |
| 402 | |
| 403 | static void __maybe_unused led_error_blink(u32 nb_blink) |
| 404 | { |
| 405 | #ifdef CONFIG_LED |
| 406 | int ret; |
| 407 | struct udevice *led; |
| 408 | u32 i; |
| 409 | #endif |
| 410 | |
| 411 | if (!nb_blink) |
| 412 | return; |
| 413 | |
| 414 | #ifdef CONFIG_LED |
| 415 | ret = get_led(&led, "u-boot,error-led"); |
| 416 | if (!ret) { |
| 417 | /* make u-boot,error-led blinking */ |
| 418 | /* if U32_MAX and 125ms interval, for 17.02 years */ |
| 419 | for (i = 0; i < 2 * nb_blink; i++) { |
| 420 | led_set_state(led, LEDST_TOGGLE); |
| 421 | mdelay(125); |
Stefan Roese | 80877fa | 2022-09-02 14:10:46 +0200 | [diff] [blame] | 422 | schedule(); |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 423 | } |
| 424 | } |
| 425 | #endif |
| 426 | |
| 427 | /* infinite: the boot process must be stopped */ |
| 428 | if (nb_blink == U32_MAX) |
| 429 | hang(); |
| 430 | } |
| 431 | |
| 432 | static void sysconf_init(void) |
| 433 | { |
Patrick Delaunay | f8fe21d | 2020-04-01 09:07:33 +0200 | [diff] [blame] | 434 | #ifndef CONFIG_TFABOOT |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 435 | u8 *syscfg; |
| 436 | #ifdef CONFIG_DM_REGULATOR |
| 437 | struct udevice *pwr_dev; |
| 438 | struct udevice *pwr_reg; |
| 439 | struct udevice *dev; |
| 440 | int ret; |
| 441 | u32 otp = 0; |
| 442 | #endif |
| 443 | u32 bootr; |
| 444 | |
| 445 | syscfg = (u8 *)syscon_get_first_range(STM32MP_SYSCON_SYSCFG); |
| 446 | |
| 447 | /* interconnect update : select master using the port 1 */ |
| 448 | /* LTDC = AXI_M9 */ |
| 449 | /* GPU = AXI_M8 */ |
| 450 | /* today information is hardcoded in U-Boot */ |
| 451 | writel(BIT(9), syscfg + SYSCFG_ICNR); |
| 452 | |
| 453 | /* disable Pull-Down for boot pin connected to VDD */ |
| 454 | bootr = readl(syscfg + SYSCFG_BOOTR); |
| 455 | bootr &= ~(SYSCFG_BOOTR_BOOT_MASK << SYSCFG_BOOTR_BOOTPD_SHIFT); |
| 456 | bootr |= (bootr & SYSCFG_BOOTR_BOOT_MASK) << SYSCFG_BOOTR_BOOTPD_SHIFT; |
| 457 | writel(bootr, syscfg + SYSCFG_BOOTR); |
| 458 | |
| 459 | #ifdef CONFIG_DM_REGULATOR |
| 460 | /* High Speed Low Voltage Pad mode Enable for SPI, SDMMC, ETH, QSPI |
| 461 | * and TRACE. Needed above ~50MHz and conditioned by AFMUX selection. |
| 462 | * The customer will have to disable this for low frequencies |
| 463 | * or if AFMUX is selected but the function not used, typically for |
| 464 | * TRACE. Otherwise, impact on power consumption. |
| 465 | * |
| 466 | * WARNING: |
| 467 | * enabling High Speed mode while VDD>2.7V |
| 468 | * with the OTP product_below_2v5 (OTP 18, BIT 13) |
| 469 | * erroneously set to 1 can damage the IC! |
| 470 | * => U-Boot set the register only if VDD < 2.7V (in DT) |
| 471 | * but this value need to be consistent with board design |
| 472 | */ |
| 473 | ret = uclass_get_device_by_driver(UCLASS_PMIC, |
Simon Glass | 65130cd | 2020-12-28 20:34:56 -0700 | [diff] [blame] | 474 | DM_DRIVER_GET(stm32mp_pwr_pmic), |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 475 | &pwr_dev); |
| 476 | if (!ret) { |
| 477 | ret = uclass_get_device_by_driver(UCLASS_MISC, |
Simon Glass | 65130cd | 2020-12-28 20:34:56 -0700 | [diff] [blame] | 478 | DM_DRIVER_GET(stm32mp_bsec), |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 479 | &dev); |
| 480 | if (ret) { |
| 481 | pr_err("Can't find stm32mp_bsec driver\n"); |
| 482 | return; |
| 483 | } |
| 484 | |
| 485 | ret = misc_read(dev, STM32_BSEC_SHADOW(18), &otp, 4); |
| 486 | if (ret > 0) |
| 487 | otp = otp & BIT(13); |
| 488 | |
| 489 | /* get VDD = vdd-supply */ |
| 490 | ret = device_get_supply_regulator(pwr_dev, "vdd-supply", |
| 491 | &pwr_reg); |
| 492 | |
| 493 | /* check if VDD is Low Voltage */ |
| 494 | if (!ret) { |
| 495 | if (regulator_get_value(pwr_reg) < 2700000) { |
| 496 | writel(SYSCFG_IOCTRLSETR_HSLVEN_TRACE | |
| 497 | SYSCFG_IOCTRLSETR_HSLVEN_QUADSPI | |
| 498 | SYSCFG_IOCTRLSETR_HSLVEN_ETH | |
| 499 | SYSCFG_IOCTRLSETR_HSLVEN_SDMMC | |
| 500 | SYSCFG_IOCTRLSETR_HSLVEN_SPI, |
| 501 | syscfg + SYSCFG_IOCTRLSETR); |
| 502 | |
| 503 | if (!otp) |
| 504 | pr_err("product_below_2v5=0: HSLVEN protected by HW\n"); |
| 505 | } else { |
| 506 | if (otp) |
| 507 | pr_err("product_below_2v5=1: HSLVEN update is destructive, no update as VDD>2.7V\n"); |
| 508 | } |
| 509 | } else { |
| 510 | debug("VDD unknown"); |
| 511 | } |
| 512 | } |
| 513 | #endif |
| 514 | |
| 515 | /* activate automatic I/O compensation |
| 516 | * warning: need to ensure CSI enabled and ready in clock driver |
| 517 | */ |
| 518 | writel(SYSCFG_CMPENSETR_MPU_EN, syscfg + SYSCFG_CMPENSETR); |
| 519 | |
| 520 | while (!(readl(syscfg + SYSCFG_CMPCR) & SYSCFG_CMPCR_READY)) |
| 521 | ; |
| 522 | clrbits_le32(syscfg + SYSCFG_CMPCR, SYSCFG_CMPCR_SW_CTRL); |
| 523 | #endif |
| 524 | } |
| 525 | |
Marek Vasut | 7f809fe | 2022-05-11 23:09:33 +0200 | [diff] [blame] | 526 | #ifdef CONFIG_DM_REGULATOR |
| 527 | #define STPMIC_NVM_BUCKS_VOUT_SHR 0xfc |
| 528 | #define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_1V2 0 |
| 529 | #define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_1V8 1 |
| 530 | #define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_3V0 2 |
| 531 | #define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_3V3 3 |
| 532 | #define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_MASK GENMASK(1, 0) |
| 533 | #define STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_OFFSET(n) ((((n) - 1) & 3) * 2) |
| 534 | static int board_get_regulator_buck3_nvm_uv_av96(int *uv) |
| 535 | { |
Marek Vasut | 7f809fe | 2022-05-11 23:09:33 +0200 | [diff] [blame] | 536 | struct udevice *dev; |
| 537 | u8 bucks_vout = 0; |
| 538 | const char *prop; |
| 539 | int len, ret; |
| 540 | |
| 541 | /* Check whether this is Avenger96 board. */ |
Patrick Delaunay | 280949c | 2022-06-06 16:04:15 +0200 | [diff] [blame] | 542 | prop = ofnode_get_property(ofnode_root(), "compatible", &len); |
Marek Vasut | 7f809fe | 2022-05-11 23:09:33 +0200 | [diff] [blame] | 543 | if (!prop || !len) |
| 544 | return -ENODEV; |
| 545 | |
Marek Vasut | 5278494 | 2022-09-26 18:50:00 +0200 | [diff] [blame] | 546 | if (!strstr(prop, "avenger96") && !strstr(prop, "dhcor-testbench")) |
Marek Vasut | 7f809fe | 2022-05-11 23:09:33 +0200 | [diff] [blame] | 547 | return -EINVAL; |
| 548 | |
| 549 | /* Read out STPMIC1 NVM and determine default Buck3 voltage. */ |
| 550 | ret = uclass_get_device_by_driver(UCLASS_MISC, |
| 551 | DM_DRIVER_GET(stpmic1_nvm), |
| 552 | &dev); |
| 553 | if (ret) |
| 554 | return ret; |
| 555 | |
| 556 | ret = misc_read(dev, STPMIC_NVM_BUCKS_VOUT_SHR, &bucks_vout, 1); |
| 557 | if (ret != 1) |
| 558 | return -EINVAL; |
| 559 | |
| 560 | bucks_vout >>= STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_OFFSET(3); |
| 561 | bucks_vout &= STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_MASK; |
| 562 | |
Marek Vasut | 5278494 | 2022-09-26 18:50:00 +0200 | [diff] [blame] | 563 | if (strstr(prop, "avenger96")) { |
| 564 | /* |
| 565 | * Avenger96 board comes in multiple regulator configurations: |
| 566 | * - rev.100 or rev.200 have Buck3 preconfigured to |
| 567 | * 3V3 operation on boot and contains extra Enpirion |
| 568 | * EP53A8LQI DCDC converter which supplies the IO. |
| 569 | * Reduce Buck3 voltage to 2V9 to not waste power. |
| 570 | * - rev.200L have Buck3 preconfigured to 1V8 operation |
| 571 | * and have no Enpirion EP53A8LQI DCDC anymore, the |
| 572 | * IO is supplied from Buck3. |
| 573 | */ |
| 574 | if (bucks_vout == STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_3V3) |
| 575 | *uv = 2900000; |
| 576 | else |
| 577 | *uv = 1800000; |
| 578 | } else { |
| 579 | /* Testbench always respects Buck3 NVM settings */ |
| 580 | if (bucks_vout == STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_3V3) |
| 581 | *uv = 3300000; |
| 582 | else if (bucks_vout == STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_3V0) |
| 583 | *uv = 3000000; |
| 584 | else if (bucks_vout == STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_1V8) |
| 585 | *uv = 1800000; |
| 586 | else /* STPMIC_NVM_BUCKS_VOUT_SHR_BUCK_1V2 */ |
| 587 | *uv = 1200000; |
| 588 | } |
Marek Vasut | 7f809fe | 2022-05-11 23:09:33 +0200 | [diff] [blame] | 589 | |
| 590 | return 0; |
| 591 | } |
| 592 | |
| 593 | static void board_init_regulator_av96(void) |
| 594 | { |
| 595 | struct udevice *rdev; |
| 596 | int ret, uv; |
| 597 | |
| 598 | ret = board_get_regulator_buck3_nvm_uv_av96(&uv); |
| 599 | if (ret) /* Not Avenger96 board. */ |
| 600 | return; |
| 601 | |
| 602 | ret = regulator_get_by_devname("buck3", &rdev); |
| 603 | if (ret) |
| 604 | return; |
| 605 | |
| 606 | /* Adjust Buck3 per preconfigured PMIC voltage from NVM. */ |
| 607 | regulator_set_value(rdev, uv); |
Marek Vasut | 69e8995 | 2022-09-23 03:31:22 +0200 | [diff] [blame] | 608 | regulator_set_enable(rdev, true); |
Marek Vasut | 7f809fe | 2022-05-11 23:09:33 +0200 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | static void board_init_regulator(void) |
| 612 | { |
| 613 | board_init_regulator_av96(); |
| 614 | |
| 615 | regulators_enable_boot_on(_DEBUG); |
| 616 | } |
| 617 | #else |
| 618 | static inline int board_get_regulator_buck3_nvm_uv_av96(int *uv) |
| 619 | { |
| 620 | return -EINVAL; |
| 621 | } |
| 622 | |
| 623 | static inline void board_init_regulator(void) {} |
| 624 | #endif |
| 625 | |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 626 | /* board dependent setup after realloc */ |
| 627 | int board_init(void) |
| 628 | { |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 629 | board_key_check(); |
| 630 | |
Marek Vasut | 7f809fe | 2022-05-11 23:09:33 +0200 | [diff] [blame] | 631 | board_init_regulator(); |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 632 | |
| 633 | sysconf_init(); |
| 634 | |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 635 | return 0; |
| 636 | } |
| 637 | |
| 638 | int board_late_init(void) |
| 639 | { |
| 640 | char *boot_device; |
| 641 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
| 642 | const void *fdt_compat; |
| 643 | int fdt_compat_len; |
| 644 | |
Patrick Delaunay | 280949c | 2022-06-06 16:04:15 +0200 | [diff] [blame] | 645 | fdt_compat = ofnode_get_property(ofnode_root(), "compatible", |
| 646 | &fdt_compat_len); |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 647 | if (fdt_compat && fdt_compat_len) { |
| 648 | if (strncmp(fdt_compat, "st,", 3) != 0) |
| 649 | env_set("board_name", fdt_compat); |
| 650 | else |
| 651 | env_set("board_name", fdt_compat + 3); |
| 652 | } |
| 653 | #endif |
| 654 | |
| 655 | /* Check the boot-source to disable bootdelay */ |
| 656 | boot_device = env_get("boot_device"); |
| 657 | if (!strcmp(boot_device, "serial") || !strcmp(boot_device, "usb")) |
| 658 | env_set("bootdelay", "0"); |
| 659 | |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 660 | #ifdef CONFIG_BOARD_EARLY_INIT_F |
| 661 | env_set_ulong("dh_som_rev", somcode); |
| 662 | env_set_ulong("dh_board_rev", brdcode); |
Marek Vasut | 39221b5 | 2020-04-22 13:18:14 +0200 | [diff] [blame] | 663 | env_set_ulong("dh_ddr3_code", ddr3code); |
Marek Vasut | 47b98ba | 2020-04-22 13:18:11 +0200 | [diff] [blame] | 664 | #endif |
| 665 | |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 666 | return 0; |
| 667 | } |
| 668 | |
| 669 | void board_quiesce_devices(void) |
| 670 | { |
| 671 | #ifdef CONFIG_LED |
| 672 | setup_led(LEDST_OFF); |
| 673 | #endif |
| 674 | } |
| 675 | |
Marek Vasut | 3551654 | 2024-06-06 15:01:48 +0200 | [diff] [blame] | 676 | static void dh_stm32_ks8851_fixup(void *blob) |
| 677 | { |
| 678 | struct gpio_desc ks8851intrn; |
| 679 | bool compatible = false; |
| 680 | int ks8851intrn_value; |
| 681 | const char *prop; |
| 682 | ofnode node; |
| 683 | int idx = 0; |
| 684 | int offset; |
| 685 | int ret; |
| 686 | |
| 687 | /* Do nothing if not STM32MP15xx DHCOM SoM */ |
| 688 | while ((prop = fdt_stringlist_get(blob, 0, "compatible", idx++, NULL))) { |
| 689 | if (!strstr(prop, "dhcom-som")) |
| 690 | continue; |
| 691 | compatible = true; |
| 692 | break; |
| 693 | } |
| 694 | |
| 695 | if (!compatible) |
| 696 | return; |
| 697 | |
| 698 | /* |
| 699 | * Read state of INTRN pull up resistor, if this pull up is populated, |
| 700 | * KS8851-16MLL is populated as well and should be enabled, otherwise |
| 701 | * it should be disabled. |
| 702 | */ |
| 703 | node = ofnode_path("/config"); |
| 704 | if (!ofnode_valid(node)) |
| 705 | return; |
| 706 | |
| 707 | ret = gpio_request_by_name_nodev(node, "dh,mac-coding-gpios", 0, |
| 708 | &ks8851intrn, GPIOD_IS_IN); |
| 709 | if (ret) |
| 710 | return; |
| 711 | |
| 712 | ks8851intrn_value = dm_gpio_get_value(&ks8851intrn); |
| 713 | |
| 714 | dm_gpio_free(NULL, &ks8851intrn); |
| 715 | |
| 716 | /* Set the 'status' property into KS8851-16MLL DT node. */ |
| 717 | offset = fdt_path_offset(blob, "ethernet1"); |
| 718 | ret = fdt_node_check_compatible(blob, offset, "micrel,ks8851-mll"); |
| 719 | if (ret) /* Not compatible */ |
| 720 | return; |
| 721 | |
| 722 | /* Add a bit of extra space for new 'status' property */ |
| 723 | ret = fdt_shrink_to_minimum(blob, 4096); |
| 724 | if (!ret) |
| 725 | return; |
| 726 | |
| 727 | fdt_setprop_string(blob, offset, "status", |
| 728 | ks8851intrn_value ? "okay" : "disabled"); |
| 729 | } |
| 730 | |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 731 | #if defined(CONFIG_OF_BOARD_SETUP) |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 732 | int ft_board_setup(void *blob, struct bd_info *bd) |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 733 | { |
Marek Vasut | 7f809fe | 2022-05-11 23:09:33 +0200 | [diff] [blame] | 734 | const char *buck3path = "/soc/i2c@5c002000/stpmic@33/regulators/buck3"; |
| 735 | int buck3off, ret, uv; |
| 736 | |
Marek Vasut | 3551654 | 2024-06-06 15:01:48 +0200 | [diff] [blame] | 737 | dh_stm32_ks8851_fixup(blob); |
| 738 | |
Marek Vasut | 7f809fe | 2022-05-11 23:09:33 +0200 | [diff] [blame] | 739 | ret = board_get_regulator_buck3_nvm_uv_av96(&uv); |
| 740 | if (ret) /* Not Avenger96 board, do not patch Buck3 in DT. */ |
| 741 | return 0; |
| 742 | |
| 743 | buck3off = fdt_path_offset(blob, buck3path); |
| 744 | if (buck3off < 0) /* No Buck3 regulator found. */ |
| 745 | return 0; |
| 746 | |
| 747 | ret = fdt_setprop_u32(blob, buck3off, "regulator-min-microvolt", uv); |
| 748 | if (ret < 0) |
| 749 | return ret; |
| 750 | |
| 751 | ret = fdt_setprop_u32(blob, buck3off, "regulator-max-microvolt", uv); |
| 752 | if (ret < 0) |
| 753 | return ret; |
| 754 | |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 755 | return 0; |
| 756 | } |
| 757 | #endif |
| 758 | |
Marek Vasut | 3551654 | 2024-06-06 15:01:48 +0200 | [diff] [blame] | 759 | #if defined(CONFIG_SPL_BUILD) |
| 760 | void spl_perform_fixups(struct spl_image_info *spl_image) |
| 761 | { |
| 762 | dh_stm32_ks8851_fixup(spl_image_fdt_addr(spl_image)); |
| 763 | } |
| 764 | #endif |
| 765 | |
Marek Vasut | 5ff0529 | 2020-01-24 18:39:16 +0100 | [diff] [blame] | 766 | static void board_copro_image_process(ulong fw_image, size_t fw_size) |
| 767 | { |
| 768 | int ret, id = 0; /* Copro id fixed to 0 as only one coproc on mp1 */ |
| 769 | |
| 770 | if (!rproc_is_initialized()) |
| 771 | if (rproc_init()) { |
| 772 | printf("Remote Processor %d initialization failed\n", |
| 773 | id); |
| 774 | return; |
| 775 | } |
| 776 | |
| 777 | ret = rproc_load(id, fw_image, fw_size); |
| 778 | printf("Load Remote Processor %d with data@addr=0x%08lx %u bytes:%s\n", |
| 779 | id, fw_image, fw_size, ret ? " Failed!" : " Success!"); |
| 780 | |
| 781 | if (!ret) { |
| 782 | rproc_start(id); |
| 783 | env_set("copro_state", "booted"); |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | U_BOOT_FIT_LOADABLE_HANDLER(IH_TYPE_COPRO, board_copro_image_process); |