Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
| 2 | /* |
| 3 | * Copyright 2022 Toradex |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <asm/arch/clock.h> |
| 8 | #include <asm/arch/imx8mp_pins.h> |
| 9 | #include <asm/arch/sys_proto.h> |
| 10 | #include <asm-generic/gpio.h> |
| 11 | #include <asm/global_data.h> |
| 12 | #include <asm/mach-imx/gpio.h> |
| 13 | #include <asm/mach-imx/iomux-v3.h> |
| 14 | #include <errno.h> |
| 15 | #include <env.h> |
| 16 | #include <init.h> |
| 17 | #include <linux/delay.h> |
| 18 | #include <micrel.h> |
| 19 | #include <miiphy.h> |
| 20 | #include <netdev.h> |
| 21 | |
| 22 | #include "../common/tdx-cfg-block.h" |
| 23 | |
| 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
| 26 | #define UART_PAD_CTRL (PAD_CTL_DSE6 | PAD_CTL_FSEL1) |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 27 | |
| 28 | /* Verdin UART_3, Console/Debug UART */ |
| 29 | static const iomux_v3_cfg_t uart_pads[] = { |
| 30 | MX8MP_PAD_UART3_RXD__UART3_DCE_RX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 31 | MX8MP_PAD_UART3_TXD__UART3_DCE_TX | MUX_PAD_CTRL(UART_PAD_CTRL), |
| 32 | }; |
| 33 | |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 34 | int board_early_init_f(void) |
| 35 | { |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 36 | imx_iomux_v3_setup_multiple_pads(uart_pads, ARRAY_SIZE(uart_pads)); |
| 37 | |
| 38 | init_uart_clk(2); |
| 39 | |
| 40 | return 0; |
| 41 | } |
| 42 | |
| 43 | static void setup_fec(void) |
| 44 | { |
| 45 | struct iomuxc_gpr_base_regs *gpr = |
| 46 | (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR; |
| 47 | |
| 48 | /* Enable RGMII TX clk output */ |
| 49 | setbits_le32(&gpr->gpr[1], BIT(22)); |
| 50 | } |
| 51 | |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 52 | #if IS_ENABLED(CONFIG_NET) |
| 53 | int board_phy_config(struct phy_device *phydev) |
| 54 | { |
| 55 | if (phydev->drv->config) |
| 56 | phydev->drv->config(phydev); |
| 57 | return 0; |
| 58 | } |
| 59 | #endif |
| 60 | |
| 61 | int board_init(void) |
| 62 | { |
| 63 | int ret = 0; |
| 64 | |
| 65 | if (IS_ENABLED(CONFIG_FEC_MXC)) |
| 66 | setup_fec(); |
| 67 | |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 68 | return ret; |
| 69 | } |
| 70 | |
| 71 | static void select_dt_from_module_version(void) |
| 72 | { |
| 73 | char variant[32]; |
| 74 | char *env_variant = env_get("variant"); |
| 75 | int is_wifi = 0; |
| 76 | |
| 77 | if (IS_ENABLED(CONFIG_TDX_CFG_BLOCK)) { |
| 78 | /* |
| 79 | * If we have a valid config block and it says we are a module with |
| 80 | * Wi-Fi/Bluetooth make sure we use the -wifi device tree. |
| 81 | */ |
| 82 | is_wifi = (tdx_hw_tag.prodid == VERDIN_IMX8MPQ_WIFI_BT_IT) || |
| 83 | (tdx_hw_tag.prodid == VERDIN_IMX8MPQ_2GB_WIFI_BT_IT) || |
| 84 | (tdx_hw_tag.prodid == VERDIN_IMX8MPQ_8GB_WIFI_BT); |
| 85 | } |
| 86 | |
| 87 | if (is_wifi) |
| 88 | strlcpy(&variant[0], "wifi", sizeof(variant)); |
| 89 | else |
| 90 | strlcpy(&variant[0], "nonwifi", sizeof(variant)); |
| 91 | |
| 92 | if (strcmp(variant, env_variant)) { |
| 93 | printf("Setting variant to %s\n", variant); |
| 94 | env_set("variant", variant); |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 95 | } |
| 96 | } |
| 97 | |
| 98 | int board_late_init(void) |
| 99 | { |
| 100 | select_dt_from_module_version(); |
| 101 | |
| 102 | return 0; |
| 103 | } |
| 104 | |
Francesco Dolcini | 48ed57d | 2022-09-07 11:51:05 +0200 | [diff] [blame] | 105 | int board_phys_sdram_size(phys_size_t *size) |
| 106 | { |
| 107 | if (!size) |
| 108 | return -EINVAL; |
| 109 | |
| 110 | *size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE + PHYS_SDRAM_2_SIZE); |
| 111 | |
| 112 | return 0; |
| 113 | } |
| 114 | |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 115 | #if IS_ENABLED(CONFIG_OF_LIBFDT) && IS_ENABLED(CONFIG_OF_BOARD_SETUP) |
| 116 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 117 | { |
Philippe Schenker | 1396e84 | 2022-08-29 19:59:53 +0200 | [diff] [blame] | 118 | return ft_common_board_setup(blob, bd); |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 119 | } |
| 120 | #endif |