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