Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
Marcel Ziswiler | d7f9a20 | 2021-10-09 22:41:09 +0200 | [diff] [blame] | 3 | * Copyright 2020-2021 Toradex |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 4 | */ |
| 5 | |
Tom Rini | dec7ea0 | 2024-05-20 13:35:03 -0600 | [diff] [blame] | 6 | #include <config.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 7 | #include <init.h> |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 8 | #include <asm/arch/clock.h> |
Igor Opaniuk | d1b4d0d | 2020-03-27 12:28:18 +0200 | [diff] [blame] | 9 | #include <asm/arch/sys_proto.h> |
Simon Glass | 3ba929a | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 10 | #include <asm/global_data.h> |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 11 | #include <asm/io.h> |
Max Krummenacher | 34515ca | 2021-10-09 22:41:10 +0200 | [diff] [blame] | 12 | #include <hang.h> |
Max Krummenacher | 4b13b56 | 2020-10-28 11:58:13 +0200 | [diff] [blame] | 13 | #include <i2c.h> |
Marcel Ziswiler | d7f9a20 | 2021-10-09 22:41:09 +0200 | [diff] [blame] | 14 | #include <micrel.h> |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 15 | #include <miiphy.h> |
| 16 | #include <netdev.h> |
| 17 | |
Max Krummenacher | 4b13b56 | 2020-10-28 11:58:13 +0200 | [diff] [blame] | 18 | #include "../common/tdx-cfg-block.h" |
| 19 | |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 20 | DECLARE_GLOBAL_DATA_PTR; |
| 21 | |
Max Krummenacher | 4b13b56 | 2020-10-28 11:58:13 +0200 | [diff] [blame] | 22 | #define I2C_PMIC 0 |
| 23 | |
| 24 | enum pcb_rev_t { |
| 25 | PCB_VERSION_1_0, |
| 26 | PCB_VERSION_1_1 |
| 27 | }; |
| 28 | |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 29 | #if IS_ENABLED(CONFIG_FEC_MXC) |
| 30 | static int setup_fec(void) |
| 31 | { |
| 32 | struct iomuxc_gpr_base_regs *gpr = |
| 33 | (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR; |
| 34 | |
| 35 | /* Use 125M anatop REF_CLK1 for ENET1, not from external */ |
| 36 | clrsetbits_le32(&gpr->gpr[1], 0x2000, 0); |
| 37 | |
| 38 | return 0; |
| 39 | } |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 40 | #endif |
| 41 | |
| 42 | int board_init(void) |
| 43 | { |
| 44 | if (IS_ENABLED(CONFIG_FEC_MXC)) |
| 45 | setup_fec(); |
| 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |
| 50 | int board_mmc_get_env_dev(int devno) |
| 51 | { |
| 52 | return devno; |
| 53 | } |
| 54 | |
Max Krummenacher | 4b13b56 | 2020-10-28 11:58:13 +0200 | [diff] [blame] | 55 | static enum pcb_rev_t get_pcb_revision(void) |
| 56 | { |
| 57 | struct udevice *bus; |
| 58 | struct udevice *i2c_dev = NULL; |
| 59 | int ret; |
| 60 | u8 is_bd71837 = 0; |
| 61 | |
| 62 | ret = uclass_get_device_by_seq(UCLASS_I2C, I2C_PMIC, &bus); |
| 63 | if (!ret) |
| 64 | ret = dm_i2c_probe(bus, 0x4b, 0, &i2c_dev); |
| 65 | if (!ret) |
| 66 | ret = dm_i2c_read(i2c_dev, 0x0, &is_bd71837, 1); |
| 67 | |
| 68 | /* BD71837_REV, High Nibble is major version, fix 1010 */ |
| 69 | is_bd71837 = !ret && ((is_bd71837 & 0xf0) == 0xa0); |
| 70 | return is_bd71837 ? PCB_VERSION_1_0 : PCB_VERSION_1_1; |
| 71 | } |
| 72 | |
| 73 | static void select_dt_from_module_version(void) |
| 74 | { |
| 75 | char variant[32]; |
| 76 | char *env_variant = env_get("variant"); |
| 77 | int is_wifi = 0; |
| 78 | |
| 79 | if (IS_ENABLED(CONFIG_TDX_CFG_BLOCK)) { |
| 80 | /* |
| 81 | * If we have a valid config block and it says we are a |
| 82 | * module with Wi-Fi/Bluetooth make sure we use the -wifi |
| 83 | * device tree. |
| 84 | */ |
| 85 | is_wifi = (tdx_hw_tag.prodid == VERDIN_IMX8MMQ_WIFI_BT_IT) || |
Philippe Schenker | 75b85e1 | 2022-07-21 15:17:31 +0200 | [diff] [blame] | 86 | (tdx_hw_tag.prodid == VERDIN_IMX8MMDL_WIFI_BT_IT) || |
Emanuele Ghidoli | d7c9b8a | 2024-05-28 11:59:41 +0200 | [diff] [blame] | 87 | (tdx_hw_tag.prodid == VERDIN_IMX8MMQ_WIFI_BT_IT_NO_CAN) || |
| 88 | (tdx_hw_tag.prodid == VERDIN_IMX8MMQ_4G_WIFI_BT_ET); |
Max Krummenacher | 4b13b56 | 2020-10-28 11:58:13 +0200 | [diff] [blame] | 89 | } |
| 90 | |
| 91 | switch (get_pcb_revision()) { |
| 92 | case PCB_VERSION_1_0: |
Max Krummenacher | 34515ca | 2021-10-09 22:41:10 +0200 | [diff] [blame] | 93 | printf("Detected a V1.0 module which is no longer supported in this BSP version\n"); |
| 94 | hang(); |
Max Krummenacher | 4b13b56 | 2020-10-28 11:58:13 +0200 | [diff] [blame] | 95 | default: |
| 96 | if (is_wifi) |
Max Krummenacher | 34515ca | 2021-10-09 22:41:10 +0200 | [diff] [blame] | 97 | strlcpy(&variant[0], "wifi", sizeof(variant)); |
Max Krummenacher | 4b13b56 | 2020-10-28 11:58:13 +0200 | [diff] [blame] | 98 | else |
Max Krummenacher | 34515ca | 2021-10-09 22:41:10 +0200 | [diff] [blame] | 99 | strlcpy(&variant[0], "nonwifi", sizeof(variant)); |
Max Krummenacher | 4b13b56 | 2020-10-28 11:58:13 +0200 | [diff] [blame] | 100 | break; |
| 101 | } |
| 102 | |
| 103 | if (strcmp(variant, env_variant)) { |
| 104 | printf("Setting variant to %s\n", variant); |
| 105 | env_set("variant", variant); |
Max Krummenacher | 4b13b56 | 2020-10-28 11:58:13 +0200 | [diff] [blame] | 106 | } |
| 107 | } |
| 108 | |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 109 | int board_late_init(void) |
| 110 | { |
Max Krummenacher | 4b13b56 | 2020-10-28 11:58:13 +0200 | [diff] [blame] | 111 | select_dt_from_module_version(); |
| 112 | |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 113 | return 0; |
| 114 | } |
| 115 | |
Marcel Ziswiler | 6b17fd1 | 2020-10-28 11:58:16 +0200 | [diff] [blame] | 116 | int board_phys_sdram_size(phys_size_t *size) |
| 117 | { |
| 118 | if (!size) |
| 119 | return -EINVAL; |
| 120 | |
Emanuele Ghidoli | 1356bdc | 2024-05-28 11:59:38 +0200 | [diff] [blame] | 121 | *size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE + PHYS_SDRAM_2_SIZE); |
Marcel Ziswiler | 6b17fd1 | 2020-10-28 11:58:16 +0200 | [diff] [blame] | 122 | |
| 123 | return 0; |
| 124 | } |
| 125 | |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 126 | #if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP) |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 127 | int ft_board_setup(void *blob, struct bd_info *bd) |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 128 | { |
Marek Vasut | 173f642 | 2024-06-25 10:26:15 +0200 | [diff] [blame] | 129 | const char *canoscpath = "/oscillator"; |
| 130 | int freq = 40000000; /* 40 MHz is used on most variants */ |
| 131 | int canoscoff, ret; |
| 132 | |
| 133 | canoscoff = fdt_path_offset(blob, canoscpath); |
| 134 | if (canoscoff < 0) /* No CAN oscillator found. */ |
| 135 | goto exit; |
| 136 | |
| 137 | /* |
| 138 | * The following "prodid" (PID4 in Toradex naming) use |
| 139 | * a 20MHz CAN oscillator: |
| 140 | * - 0055, V1.1A, V1.1B, V1.1C and V1.1D |
| 141 | * - 0059, V1.1A and V1.1B |
| 142 | */ |
| 143 | if ((tdx_hw_tag.ver_major == 1 && tdx_hw_tag.ver_minor == 1) && |
| 144 | ((tdx_hw_tag.prodid == VERDIN_IMX8MMQ_IT && |
| 145 | tdx_hw_tag.ver_assembly <= 1) || /* 0059 rev. A or B */ |
| 146 | (tdx_hw_tag.prodid == VERDIN_IMX8MMQ_WIFI_BT_IT && |
| 147 | tdx_hw_tag.ver_assembly <= 3))) { /* 0055 rev. A/B/C/D */ |
| 148 | freq = 20000000; |
| 149 | } |
| 150 | |
| 151 | ret = fdt_setprop_u32(blob, canoscoff, "clock-frequency", freq); |
| 152 | if (ret < 0) { |
| 153 | printf("Failed to set CAN oscillator clock-frequency, ret=%d\n", |
| 154 | ret); |
| 155 | } |
| 156 | |
| 157 | exit: |
Philippe Schenker | 93eb850 | 2022-08-29 19:59:52 +0200 | [diff] [blame] | 158 | return ft_common_board_setup(blob, bd); |
Igor Opaniuk | 309e65b | 2020-01-28 14:42:25 +0100 | [diff] [blame] | 159 | } |
| 160 | #endif |