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