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