blob: 55c02653da6864398c2d3f25777ad0d014d298b1 [file] [log] [blame]
Igor Opaniuk309e65b2020-01-28 14:42:25 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
Marcel Ziswilerd7f9a202021-10-09 22:41:09 +02003 * Copyright 2020-2021 Toradex
Igor Opaniuk309e65b2020-01-28 14:42:25 +01004 */
5
6#include <common.h>
Simon Glass97589732020-05-10 11:40:02 -06007#include <init.h>
Igor Opaniuk309e65b2020-01-28 14:42:25 +01008#include <asm/arch/clock.h>
Igor Opaniukd1b4d0d2020-03-27 12:28:18 +02009#include <asm/arch/sys_proto.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060010#include <asm/global_data.h>
Igor Opaniuk309e65b2020-01-28 14:42:25 +010011#include <asm/io.h>
Max Krummenacher34515ca2021-10-09 22:41:10 +020012#include <hang.h>
Max Krummenacher4b13b562020-10-28 11:58:13 +020013#include <i2c.h>
Marcel Ziswilerd7f9a202021-10-09 22:41:09 +020014#include <micrel.h>
Igor Opaniuk309e65b2020-01-28 14:42:25 +010015#include <miiphy.h>
16#include <netdev.h>
17
Max Krummenacher4b13b562020-10-28 11:58:13 +020018#include "../common/tdx-cfg-block.h"
19
Igor Opaniuk309e65b2020-01-28 14:42:25 +010020DECLARE_GLOBAL_DATA_PTR;
21
Max Krummenacher4b13b562020-10-28 11:58:13 +020022#define I2C_PMIC 0
23
24enum pcb_rev_t {
25 PCB_VERSION_1_0,
26 PCB_VERSION_1_1
27};
28
Igor Opaniuk309e65b2020-01-28 14:42:25 +010029#if IS_ENABLED(CONFIG_FEC_MXC)
30static 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 Opaniuk309e65b2020-01-28 14:42:25 +010040#endif
41
42int board_init(void)
43{
44 if (IS_ENABLED(CONFIG_FEC_MXC))
45 setup_fec();
46
47 return 0;
48}
49
50int board_mmc_get_env_dev(int devno)
51{
52 return devno;
53}
54
Max Krummenacher4b13b562020-10-28 11:58:13 +020055static 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
73static 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 Schenker75b85e12022-07-21 15:17:31 +020086 (tdx_hw_tag.prodid == VERDIN_IMX8MMDL_WIFI_BT_IT) ||
87 (tdx_hw_tag.prodid == VERDIN_IMX8MMQ_WIFI_BT_IT_NO_CAN);
Max Krummenacher4b13b562020-10-28 11:58:13 +020088 }
89
90 switch (get_pcb_revision()) {
91 case PCB_VERSION_1_0:
Max Krummenacher34515ca2021-10-09 22:41:10 +020092 printf("Detected a V1.0 module which is no longer supported in this BSP version\n");
93 hang();
Max Krummenacher4b13b562020-10-28 11:58:13 +020094 default:
95 if (is_wifi)
Max Krummenacher34515ca2021-10-09 22:41:10 +020096 strlcpy(&variant[0], "wifi", sizeof(variant));
Max Krummenacher4b13b562020-10-28 11:58:13 +020097 else
Max Krummenacher34515ca2021-10-09 22:41:10 +020098 strlcpy(&variant[0], "nonwifi", sizeof(variant));
Max Krummenacher4b13b562020-10-28 11:58:13 +020099 break;
100 }
101
102 if (strcmp(variant, env_variant)) {
103 printf("Setting variant to %s\n", variant);
104 env_set("variant", variant);
Max Krummenacher4b13b562020-10-28 11:58:13 +0200105 }
106}
107
Igor Opaniuk309e65b2020-01-28 14:42:25 +0100108int board_late_init(void)
109{
Max Krummenacher4b13b562020-10-28 11:58:13 +0200110 select_dt_from_module_version();
111
Igor Opaniuk309e65b2020-01-28 14:42:25 +0100112 return 0;
113}
114
Marcel Ziswiler6b17fd12020-10-28 11:58:16 +0200115int board_phys_sdram_size(phys_size_t *size)
116{
117 if (!size)
118 return -EINVAL;
119
120 *size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE);
121
122 return 0;
123}
124
Igor Opaniuk309e65b2020-01-28 14:42:25 +0100125#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900126int ft_board_setup(void *blob, struct bd_info *bd)
Igor Opaniuk309e65b2020-01-28 14:42:25 +0100127{
Philippe Schenker93eb8502022-08-29 19:59:52 +0200128 return ft_common_board_setup(blob, bd);
Igor Opaniuk309e65b2020-01-28 14:42:25 +0100129}
130#endif