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 | |
| 52 | static int setup_eqos(void) |
| 53 | { |
| 54 | struct iomuxc_gpr_base_regs *gpr = |
| 55 | (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR; |
| 56 | |
| 57 | /* set INTF as RGMII, enable RGMII TXC clock */ |
| 58 | clrsetbits_le32(&gpr->gpr[1], |
| 59 | IOMUXC_GPR_GPR1_GPR_ENET_QOS_INTF_SEL_MASK, BIT(16)); |
| 60 | setbits_le32(&gpr->gpr[1], BIT(19) | BIT(21)); |
| 61 | |
| 62 | return set_clk_eqos(ENET_125MHZ); |
| 63 | } |
| 64 | |
| 65 | #if IS_ENABLED(CONFIG_NET) |
| 66 | int board_phy_config(struct phy_device *phydev) |
| 67 | { |
| 68 | if (phydev->drv->config) |
| 69 | phydev->drv->config(phydev); |
| 70 | return 0; |
| 71 | } |
| 72 | #endif |
| 73 | |
| 74 | int board_init(void) |
| 75 | { |
| 76 | int ret = 0; |
| 77 | |
| 78 | if (IS_ENABLED(CONFIG_FEC_MXC)) |
| 79 | setup_fec(); |
| 80 | |
| 81 | if (IS_ENABLED(CONFIG_DWC_ETH_QOS)) |
| 82 | ret = setup_eqos(); |
| 83 | |
| 84 | return ret; |
| 85 | } |
| 86 | |
| 87 | static void select_dt_from_module_version(void) |
| 88 | { |
| 89 | char variant[32]; |
| 90 | char *env_variant = env_get("variant"); |
| 91 | int is_wifi = 0; |
| 92 | |
| 93 | if (IS_ENABLED(CONFIG_TDX_CFG_BLOCK)) { |
| 94 | /* |
| 95 | * If we have a valid config block and it says we are a module with |
| 96 | * Wi-Fi/Bluetooth make sure we use the -wifi device tree. |
| 97 | */ |
| 98 | is_wifi = (tdx_hw_tag.prodid == VERDIN_IMX8MPQ_WIFI_BT_IT) || |
| 99 | (tdx_hw_tag.prodid == VERDIN_IMX8MPQ_2GB_WIFI_BT_IT) || |
| 100 | (tdx_hw_tag.prodid == VERDIN_IMX8MPQ_8GB_WIFI_BT); |
| 101 | } |
| 102 | |
| 103 | if (is_wifi) |
| 104 | strlcpy(&variant[0], "wifi", sizeof(variant)); |
| 105 | else |
| 106 | strlcpy(&variant[0], "nonwifi", sizeof(variant)); |
| 107 | |
| 108 | if (strcmp(variant, env_variant)) { |
| 109 | printf("Setting variant to %s\n", variant); |
| 110 | env_set("variant", variant); |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 111 | } |
| 112 | } |
| 113 | |
| 114 | int board_late_init(void) |
| 115 | { |
| 116 | select_dt_from_module_version(); |
| 117 | |
| 118 | return 0; |
| 119 | } |
| 120 | |
Francesco Dolcini | 48ed57d | 2022-09-07 11:51:05 +0200 | [diff] [blame] | 121 | int board_phys_sdram_size(phys_size_t *size) |
| 122 | { |
| 123 | if (!size) |
| 124 | return -EINVAL; |
| 125 | |
| 126 | *size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE + PHYS_SDRAM_2_SIZE); |
| 127 | |
| 128 | return 0; |
| 129 | } |
| 130 | |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 131 | #if IS_ENABLED(CONFIG_OF_LIBFDT) && IS_ENABLED(CONFIG_OF_BOARD_SETUP) |
| 132 | int ft_board_setup(void *blob, struct bd_info *bd) |
| 133 | { |
Philippe Schenker | 1396e84 | 2022-08-29 19:59:53 +0200 | [diff] [blame] | 134 | return ft_common_board_setup(blob, bd); |
Marcel Ziswiler | 36a439d | 2022-02-07 11:54:13 +0100 | [diff] [blame] | 135 | } |
| 136 | #endif |