Marcel Ziswiler | 315deb3 | 2023-08-04 12:08:08 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | /* |
| 3 | * Board specific initialization for Verdin AM62 SoM |
| 4 | * |
| 5 | * Copyright 2023 Toradex - https://www.toradex.com/ |
| 6 | * |
| 7 | */ |
| 8 | |
Tom Rini | b7f7046 | 2023-12-14 13:16:45 -0500 | [diff] [blame] | 9 | #include <config.h> |
Marcel Ziswiler | 315deb3 | 2023-08-04 12:08:08 +0200 | [diff] [blame] | 10 | #include <asm/arch/hardware.h> |
| 11 | #include <asm/io.h> |
| 12 | #include <dm/uclass.h> |
| 13 | #include <env.h> |
| 14 | #include <fdt_support.h> |
| 15 | #include <init.h> |
| 16 | #include <k3-ddrss.h> |
Max Krummenacher | 0fd5b07 | 2024-01-17 11:16:49 +0100 | [diff] [blame] | 17 | #include <power/regulator.h> |
Marcel Ziswiler | 315deb3 | 2023-08-04 12:08:08 +0200 | [diff] [blame] | 18 | #include <spl.h> |
| 19 | |
| 20 | #include "../common/tdx-cfg-block.h" |
| 21 | |
Max Krummenacher | 0fd5b07 | 2024-01-17 11:16:49 +0100 | [diff] [blame] | 22 | #define VDD_CORE_REG "buck1" |
| 23 | |
Marcel Ziswiler | 315deb3 | 2023-08-04 12:08:08 +0200 | [diff] [blame] | 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
| 26 | int board_init(void) |
| 27 | { |
| 28 | return 0; |
| 29 | } |
| 30 | |
| 31 | int dram_init(void) |
| 32 | { |
| 33 | gd->ram_size = get_ram_size((long *)CFG_SYS_SDRAM_BASE, CFG_SYS_SDRAM_SIZE); |
| 34 | |
Emanuele Ghidoli | 478eaf2 | 2023-08-24 10:08:50 +0200 | [diff] [blame] | 35 | if (gd->ram_size < SZ_512M) |
| 36 | puts("## WARNING: Less than 512MB RAM detected\n"); |
Marcel Ziswiler | 315deb3 | 2023-08-04 12:08:08 +0200 | [diff] [blame] | 37 | |
| 38 | return 0; |
| 39 | } |
| 40 | |
| 41 | /* |
| 42 | * Avoid relocated U-Boot clash with Linux reserved-memory on 512 MB SoM |
| 43 | */ |
Heinrich Schuchardt | 51a9aac | 2023-08-12 20:16:58 +0200 | [diff] [blame] | 44 | phys_addr_t board_get_usable_ram_top(phys_size_t total_size) |
Marcel Ziswiler | 315deb3 | 2023-08-04 12:08:08 +0200 | [diff] [blame] | 45 | { |
| 46 | return 0x9C000000; |
| 47 | } |
| 48 | |
| 49 | #if defined(CONFIG_SPL_LOAD_FIT) |
| 50 | int board_fit_config_name_match(const char *name) |
| 51 | { |
| 52 | return 0; |
| 53 | } |
| 54 | #endif |
| 55 | |
Max Krummenacher | 0fd5b07 | 2024-01-17 11:16:49 +0100 | [diff] [blame] | 56 | static u32 get_vdd_core_nominal(void) |
| 57 | { |
| 58 | int core_uvolt; |
| 59 | |
| 60 | switch (k3_get_speed_grade()) { |
| 61 | case 'G': |
| 62 | case 'K': |
| 63 | case 'S': |
| 64 | core_uvolt = 750000; |
| 65 | break; |
| 66 | case 'T': |
| 67 | default: |
| 68 | core_uvolt = 850000; |
| 69 | break; |
| 70 | } |
| 71 | return core_uvolt; |
| 72 | } |
| 73 | |
Marcel Ziswiler | 315deb3 | 2023-08-04 12:08:08 +0200 | [diff] [blame] | 74 | #if IS_ENABLED(CONFIG_OF_LIBFDT) && IS_ENABLED(CONFIG_OF_BOARD_SETUP) |
| 75 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 76 | { |
Max Krummenacher | 0fd5b07 | 2024-01-17 11:16:49 +0100 | [diff] [blame] | 77 | int core_uvolt; |
| 78 | |
| 79 | core_uvolt = get_vdd_core_nominal(); |
| 80 | if (core_uvolt != 850000) { |
| 81 | do_fixup_by_path_u32(blob, "/bus@f0000/i2c@20000000/pmic@30/regulators/buck1", |
| 82 | "regulator-max-microvolt", core_uvolt, 0); |
| 83 | do_fixup_by_path_u32(blob, "/bus@f0000/i2c@20000000/pmic@30/regulators/buck1", |
| 84 | "regulator-min-microvolt", core_uvolt, 0); |
| 85 | } |
| 86 | |
Marcel Ziswiler | 315deb3 | 2023-08-04 12:08:08 +0200 | [diff] [blame] | 87 | return ft_common_board_setup(blob, bd); |
| 88 | } |
| 89 | #endif |
| 90 | |
| 91 | static void select_dt_from_module_version(void) |
| 92 | { |
| 93 | char variant[32]; |
| 94 | char *env_variant = env_get("variant"); |
| 95 | int is_wifi = 0; |
| 96 | |
| 97 | if (IS_ENABLED(CONFIG_TDX_CFG_BLOCK)) { |
| 98 | /* |
| 99 | * If we have a valid config block and it says we are a module with |
| 100 | * Wi-Fi/Bluetooth make sure we use the -wifi device tree. |
| 101 | */ |
| 102 | is_wifi = (tdx_hw_tag.prodid == VERDIN_AM62Q_WIFI_BT_IT) || |
| 103 | (tdx_hw_tag.prodid == VERDIN_AM62S_512MB_WIFI_BT_IT) || |
| 104 | (tdx_hw_tag.prodid == VERDIN_AM62D_1G_WIFI_BT_IT) || |
| 105 | (tdx_hw_tag.prodid == VERDIN_AM62Q_2G_WIFI_BT_IT); |
| 106 | } |
| 107 | |
| 108 | if (is_wifi) |
| 109 | strlcpy(&variant[0], "wifi", sizeof(variant)); |
| 110 | else |
| 111 | strlcpy(&variant[0], "nonwifi", sizeof(variant)); |
| 112 | |
| 113 | if (strcmp(variant, env_variant)) { |
| 114 | printf("Setting variant to %s\n", variant); |
| 115 | env_set("variant", variant); |
| 116 | } |
| 117 | } |
| 118 | |
| 119 | int board_late_init(void) |
| 120 | { |
Max Krummenacher | 0fd5b07 | 2024-01-17 11:16:49 +0100 | [diff] [blame] | 121 | int ret; |
| 122 | int core_uvolt; |
| 123 | struct udevice *dev = NULL; |
| 124 | |
| 125 | core_uvolt = get_vdd_core_nominal(); |
| 126 | if (core_uvolt != 850000) { |
| 127 | /* Set CPU core voltage to 0.75V for slower speed grades */ |
| 128 | ret = regulator_get_by_devname(VDD_CORE_REG, &dev); |
| 129 | if (ret) |
| 130 | pr_err("VDD CORE Regulator get error: %d\n", ret); |
| 131 | |
| 132 | ret = regulator_set_value_force(dev, core_uvolt); |
| 133 | if (ret) |
| 134 | pr_err("VDD CORE Regulator value setting error: %d\n", ret); |
| 135 | } |
| 136 | |
Marcel Ziswiler | 315deb3 | 2023-08-04 12:08:08 +0200 | [diff] [blame] | 137 | select_dt_from_module_version(); |
| 138 | |
| 139 | return 0; |
| 140 | } |
| 141 | |
| 142 | #define CTRLMMR_USB0_PHY_CTRL 0x43004008 |
| 143 | #define CTRLMMR_USB1_PHY_CTRL 0x43004018 |
| 144 | #define CORE_VOLTAGE 0x80000000 |
| 145 | #define MCU_CTRL_LFXOSC_32K_BYPASS_VAL BIT(4) |
| 146 | |
| 147 | #ifdef CONFIG_SPL_BOARD_INIT |
| 148 | void spl_board_init(void) |
| 149 | { |
| 150 | u32 val; |
| 151 | |
Max Krummenacher | 88f9862 | 2024-01-17 11:16:46 +0100 | [diff] [blame] | 152 | /* Clear USB0_PHY_CTRL_CORE_VOLTAGE */ |
| 153 | /* TI recommends to clear the bit independent of VDDA_CORE_USB */ |
Marcel Ziswiler | 315deb3 | 2023-08-04 12:08:08 +0200 | [diff] [blame] | 154 | val = readl(CTRLMMR_USB0_PHY_CTRL); |
| 155 | val &= ~(CORE_VOLTAGE); |
| 156 | writel(val, CTRLMMR_USB0_PHY_CTRL); |
| 157 | |
Max Krummenacher | 88f9862 | 2024-01-17 11:16:46 +0100 | [diff] [blame] | 158 | /* Clear USB1_PHY_CTRL_CORE_VOLTAGE */ |
Marcel Ziswiler | 315deb3 | 2023-08-04 12:08:08 +0200 | [diff] [blame] | 159 | val = readl(CTRLMMR_USB1_PHY_CTRL); |
| 160 | val &= ~(CORE_VOLTAGE); |
| 161 | writel(val, CTRLMMR_USB1_PHY_CTRL); |
| 162 | |
| 163 | /* We use the 32k FOUT from the Epson RX8130CE RTC chip */ |
| 164 | /* In WKUP_LFOSC0 clear the power down bit and set the bypass bit |
| 165 | * The bypass bit is required as we provide a CMOS clock signal and |
| 166 | * the power down seems to be required also in the bypass case |
| 167 | * despite of the datasheet stating otherwise |
| 168 | */ |
| 169 | /* Compare with the AM62 datasheet, |
| 170 | * Table 7-21. LFXOSC Modes of Operation |
| 171 | */ |
| 172 | val = readl(MCU_CTRL_LFXOSC_CTRL); |
| 173 | val &= ~MCU_CTRL_LFXOSC_32K_DISABLE_VAL; |
| 174 | val |= MCU_CTRL_LFXOSC_32K_BYPASS_VAL; |
| 175 | writel(val, MCU_CTRL_LFXOSC_CTRL); |
| 176 | /* Make sure to mux up to take the SoC 32k from the LFOSC input */ |
| 177 | writel(MCU_CTRL_DEVICE_CLKOUT_LFOSC_SELECT_VAL, |
| 178 | MCU_CTRL_DEVICE_CLKOUT_32K_CTRL); |
| 179 | } |
| 180 | #endif |