Marcel Ziswiler | 99d768b | 2019-05-31 18:56:39 +0300 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright 2019 Toradex |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | afb0215 | 2019-12-28 10:45:01 -0700 | [diff] [blame] | 7 | #include <cpu_func.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 8 | #include <init.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 9 | #include <asm/global_data.h> |
Marcel Ziswiler | 99d768b | 2019-05-31 18:56:39 +0300 | [diff] [blame] | 10 | |
| 11 | #include <asm/arch/clock.h> |
| 12 | #include <asm/arch/imx8-pins.h> |
| 13 | #include <asm/arch/iomux.h> |
Peng Fan | 2e0644a | 2023-04-28 12:08:09 +0800 | [diff] [blame] | 14 | #include <firmware/imx/sci/sci.h> |
Andrejs Cainikovs | 4a5a9e9 | 2023-04-03 13:14:26 +0200 | [diff] [blame] | 15 | #include <asm/arch/snvs_security_sc.h> |
Marcel Ziswiler | 99d768b | 2019-05-31 18:56:39 +0300 | [diff] [blame] | 16 | #include <asm/arch/sys_proto.h> |
| 17 | #include <asm/gpio.h> |
| 18 | #include <asm/io.h> |
Simon Glass | 5e6201b | 2019-08-01 09:46:51 -0600 | [diff] [blame] | 19 | #include <env.h> |
Marcel Ziswiler | 99d768b | 2019-05-31 18:56:39 +0300 | [diff] [blame] | 20 | #include <errno.h> |
| 21 | #include <linux/libfdt.h> |
| 22 | |
| 23 | #include "../common/tdx-cfg-block.h" |
| 24 | |
| 25 | DECLARE_GLOBAL_DATA_PTR; |
| 26 | |
| 27 | #define UART_PAD_CTRL ((SC_PAD_CONFIG_OUT_IN << PADRING_CONFIG_SHIFT) | \ |
| 28 | (SC_PAD_ISO_OFF << PADRING_LPCONFIG_SHIFT) | \ |
| 29 | (SC_PAD_28FDSOI_DSE_DV_HIGH << PADRING_DSE_SHIFT) | \ |
| 30 | (SC_PAD_28FDSOI_PS_PU << PADRING_PULL_SHIFT)) |
| 31 | |
| 32 | static iomux_cfg_t uart3_pads[] = { |
| 33 | SC_P_FLEXCAN2_RX | MUX_MODE_ALT(2) | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 34 | SC_P_FLEXCAN2_TX | MUX_MODE_ALT(2) | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 35 | /* Transceiver FORCEOFF# signal, mux to use pull-up */ |
| 36 | SC_P_QSPI0B_DQS | MUX_MODE_ALT(4) | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 37 | }; |
| 38 | |
| 39 | static void setup_iomux_uart(void) |
| 40 | { |
| 41 | imx8_iomux_setup_multiple_pads(uart3_pads, ARRAY_SIZE(uart3_pads)); |
| 42 | } |
| 43 | |
Max Krummenacher | 88c7071 | 2023-03-03 14:26:32 +0100 | [diff] [blame] | 44 | static int is_imx8dx(void) |
Igor Opaniuk | dcc63c1 | 2020-10-22 11:21:43 +0300 | [diff] [blame] | 45 | { |
Max Krummenacher | 88c7071 | 2023-03-03 14:26:32 +0100 | [diff] [blame] | 46 | u32 val = 0; |
Peng Fan | bffd4dc | 2023-06-15 18:09:00 +0800 | [diff] [blame] | 47 | int sc_err = sc_misc_otp_fuse_read(-1, 6, &val); |
Igor Opaniuk | dcc63c1 | 2020-10-22 11:21:43 +0300 | [diff] [blame] | 48 | |
Peng Fan | bffd4dc | 2023-06-15 18:09:00 +0800 | [diff] [blame] | 49 | if (sc_err) { |
Igor Opaniuk | dcc63c1 | 2020-10-22 11:21:43 +0300 | [diff] [blame] | 50 | /* DX has two A35 cores disabled */ |
Max Krummenacher | 88c7071 | 2023-03-03 14:26:32 +0100 | [diff] [blame] | 51 | return (val & 0xf) != 0x0; |
Igor Opaniuk | dcc63c1 | 2020-10-22 11:21:43 +0300 | [diff] [blame] | 52 | } |
Max Krummenacher | 88c7071 | 2023-03-03 14:26:32 +0100 | [diff] [blame] | 53 | return false; |
| 54 | } |
Igor Opaniuk | dcc63c1 | 2020-10-22 11:21:43 +0300 | [diff] [blame] | 55 | |
Max Krummenacher | 88c7071 | 2023-03-03 14:26:32 +0100 | [diff] [blame] | 56 | void board_mem_get_layout(u64 *phys_sdram_1_start, |
| 57 | u64 *phys_sdram_1_size, |
| 58 | u64 *phys_sdram_2_start, |
| 59 | u64 *phys_sdram_2_size) |
| 60 | { |
Igor Opaniuk | dcc63c1 | 2020-10-22 11:21:43 +0300 | [diff] [blame] | 61 | *phys_sdram_1_start = PHYS_SDRAM_1; |
Max Krummenacher | 88c7071 | 2023-03-03 14:26:32 +0100 | [diff] [blame] | 62 | if (is_imx8dx()) |
Igor Opaniuk | dcc63c1 | 2020-10-22 11:21:43 +0300 | [diff] [blame] | 63 | /* Our DX based SKUs only have 1 GB RAM */ |
| 64 | *phys_sdram_1_size = SZ_1G; |
| 65 | else |
| 66 | *phys_sdram_1_size = PHYS_SDRAM_1_SIZE; |
| 67 | *phys_sdram_2_start = PHYS_SDRAM_2; |
| 68 | *phys_sdram_2_size = PHYS_SDRAM_2_SIZE; |
| 69 | } |
| 70 | |
Marcel Ziswiler | 99d768b | 2019-05-31 18:56:39 +0300 | [diff] [blame] | 71 | int board_early_init_f(void) |
| 72 | { |
| 73 | sc_pm_clock_rate_t rate; |
Peng Fan | bffd4dc | 2023-06-15 18:09:00 +0800 | [diff] [blame] | 74 | int err; |
Marcel Ziswiler | 99d768b | 2019-05-31 18:56:39 +0300 | [diff] [blame] | 75 | |
| 76 | /* |
| 77 | * This works around that having only UART3 up the baudrate is 1.2M |
| 78 | * instead of 115.2k. Set UART0 clock root to 80 MHz |
| 79 | */ |
| 80 | rate = 80000000; |
| 81 | err = sc_pm_set_clock_rate(-1, SC_R_UART_0, SC_PM_CLK_PER, &rate); |
Peng Fan | bffd4dc | 2023-06-15 18:09:00 +0800 | [diff] [blame] | 82 | if (err) |
Marcel Ziswiler | 99d768b | 2019-05-31 18:56:39 +0300 | [diff] [blame] | 83 | return 0; |
| 84 | |
Anatolij Gustschin | ef156d2 | 2019-06-12 13:35:25 +0200 | [diff] [blame] | 85 | /* Set UART3 clock root to 80 MHz and enable it */ |
| 86 | rate = SC_80MHZ; |
| 87 | err = sc_pm_setup_uart(SC_R_UART_3, rate); |
Peng Fan | bffd4dc | 2023-06-15 18:09:00 +0800 | [diff] [blame] | 88 | if (err) |
Marcel Ziswiler | 99d768b | 2019-05-31 18:56:39 +0300 | [diff] [blame] | 89 | return 0; |
| 90 | |
| 91 | setup_iomux_uart(); |
| 92 | |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | #if IS_ENABLED(CONFIG_DM_GPIO) |
| 97 | static void board_gpio_init(void) |
| 98 | { |
| 99 | /* TODO */ |
| 100 | } |
| 101 | #else |
| 102 | static inline void board_gpio_init(void) {} |
| 103 | #endif |
| 104 | |
| 105 | #if IS_ENABLED(CONFIG_FEC_MXC) |
| 106 | #include <miiphy.h> |
| 107 | |
| 108 | int board_phy_config(struct phy_device *phydev) |
| 109 | { |
| 110 | if (phydev->drv->config) |
| 111 | phydev->drv->config(phydev); |
| 112 | |
| 113 | return 0; |
| 114 | } |
| 115 | #endif |
| 116 | |
Marcel Ziswiler | 99d768b | 2019-05-31 18:56:39 +0300 | [diff] [blame] | 117 | int checkboard(void) |
| 118 | { |
| 119 | puts("Model: Toradex Colibri iMX8X\n"); |
| 120 | |
| 121 | build_info(); |
| 122 | print_bootinfo(); |
| 123 | |
| 124 | return 0; |
| 125 | } |
| 126 | |
Andrejs Cainikovs | a4d8154 | 2023-03-03 14:26:33 +0100 | [diff] [blame] | 127 | static void select_dt_from_module_version(void) |
| 128 | { |
| 129 | /* |
| 130 | * The dtb filename is constructed from ${soc}-colibri-${fdt_board}.dtb. |
| 131 | * Set soc depending on the used SoC. |
| 132 | */ |
| 133 | if (is_imx8dx()) |
| 134 | env_set("soc", "imx8dx"); |
| 135 | else |
| 136 | env_set("soc", "imx8qxp"); |
| 137 | } |
| 138 | |
Marcel Ziswiler | 99d768b | 2019-05-31 18:56:39 +0300 | [diff] [blame] | 139 | int board_init(void) |
| 140 | { |
| 141 | board_gpio_init(); |
| 142 | |
Andrejs Cainikovs | 4a5a9e9 | 2023-04-03 13:14:26 +0200 | [diff] [blame] | 143 | if (IS_ENABLED(CONFIG_IMX_SNVS_SEC_SC_AUTO)) { |
| 144 | int ret = snvs_security_sc_init(); |
| 145 | |
| 146 | if (ret) |
| 147 | return ret; |
| 148 | } |
| 149 | |
Marcel Ziswiler | 99d768b | 2019-05-31 18:56:39 +0300 | [diff] [blame] | 150 | return 0; |
| 151 | } |
| 152 | |
Marcel Ziswiler | 99d768b | 2019-05-31 18:56:39 +0300 | [diff] [blame] | 153 | /* |
| 154 | * Board specific reset that is system reset. |
| 155 | */ |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 156 | void reset_cpu(void) |
Marcel Ziswiler | 99d768b | 2019-05-31 18:56:39 +0300 | [diff] [blame] | 157 | { |
| 158 | /* TODO */ |
| 159 | } |
| 160 | |
| 161 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 162 | int ft_board_setup(void *blob, struct bd_info *bd) |
Marcel Ziswiler | 99d768b | 2019-05-31 18:56:39 +0300 | [diff] [blame] | 163 | { |
| 164 | return ft_common_board_setup(blob, bd); |
| 165 | } |
| 166 | #endif |
| 167 | |
| 168 | int board_mmc_get_env_dev(int devno) |
| 169 | { |
| 170 | return devno; |
| 171 | } |
| 172 | |
| 173 | int board_late_init(void) |
| 174 | { |
| 175 | #ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG |
| 176 | /* TODO move to common */ |
| 177 | env_set("board_name", "Colibri iMX8QXP"); |
| 178 | env_set("board_rev", "v1.0"); |
| 179 | #endif |
| 180 | |
Andrejs Cainikovs | aa390ed | 2023-04-03 13:14:25 +0200 | [diff] [blame] | 181 | build_info(); |
| 182 | |
Andrejs Cainikovs | a4d8154 | 2023-03-03 14:26:33 +0100 | [diff] [blame] | 183 | select_dt_from_module_version(); |
| 184 | |
Marcel Ziswiler | 99d768b | 2019-05-31 18:56:39 +0300 | [diff] [blame] | 185 | return 0; |
| 186 | } |