2020-01-28 13:42:25 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
2021-10-09 20:41:09 +00:00
|
|
|
* Copyright 2020-2021 Toradex
|
2020-01-28 13:42:25 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2020-05-10 17:40:02 +00:00
|
|
|
#include <init.h>
|
2020-01-28 13:42:25 +00:00
|
|
|
#include <asm/arch/clock.h>
|
2020-03-27 10:28:18 +00:00
|
|
|
#include <asm/arch/sys_proto.h>
|
2020-10-31 03:38:53 +00:00
|
|
|
#include <asm/global_data.h>
|
2020-01-28 13:42:25 +00:00
|
|
|
#include <asm/io.h>
|
2021-10-09 20:41:10 +00:00
|
|
|
#include <hang.h>
|
2020-10-28 09:58:13 +00:00
|
|
|
#include <i2c.h>
|
2021-10-09 20:41:09 +00:00
|
|
|
#include <micrel.h>
|
2020-01-28 13:42:25 +00:00
|
|
|
#include <miiphy.h>
|
|
|
|
#include <netdev.h>
|
|
|
|
|
2020-10-28 09:58:13 +00:00
|
|
|
#include "../common/tdx-cfg-block.h"
|
|
|
|
|
2020-01-28 13:42:25 +00:00
|
|
|
DECLARE_GLOBAL_DATA_PTR;
|
|
|
|
|
2020-10-28 09:58:13 +00:00
|
|
|
#define I2C_PMIC 0
|
|
|
|
|
|
|
|
enum pcb_rev_t {
|
|
|
|
PCB_VERSION_1_0,
|
|
|
|
PCB_VERSION_1_1
|
|
|
|
};
|
|
|
|
|
2020-01-28 13:42:25 +00:00
|
|
|
#if IS_ENABLED(CONFIG_FEC_MXC)
|
|
|
|
static int setup_fec(void)
|
|
|
|
{
|
|
|
|
struct iomuxc_gpr_base_regs *gpr =
|
|
|
|
(struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
|
|
|
|
|
|
|
|
/* Use 125M anatop REF_CLK1 for ENET1, not from external */
|
|
|
|
clrsetbits_le32(&gpr->gpr[1], 0x2000, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int board_init(void)
|
|
|
|
{
|
|
|
|
if (IS_ENABLED(CONFIG_FEC_MXC))
|
|
|
|
setup_fec();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int board_mmc_get_env_dev(int devno)
|
|
|
|
{
|
|
|
|
return devno;
|
|
|
|
}
|
|
|
|
|
2020-10-28 09:58:13 +00:00
|
|
|
static enum pcb_rev_t get_pcb_revision(void)
|
|
|
|
{
|
|
|
|
struct udevice *bus;
|
|
|
|
struct udevice *i2c_dev = NULL;
|
|
|
|
int ret;
|
|
|
|
u8 is_bd71837 = 0;
|
|
|
|
|
|
|
|
ret = uclass_get_device_by_seq(UCLASS_I2C, I2C_PMIC, &bus);
|
|
|
|
if (!ret)
|
|
|
|
ret = dm_i2c_probe(bus, 0x4b, 0, &i2c_dev);
|
|
|
|
if (!ret)
|
|
|
|
ret = dm_i2c_read(i2c_dev, 0x0, &is_bd71837, 1);
|
|
|
|
|
|
|
|
/* BD71837_REV, High Nibble is major version, fix 1010 */
|
|
|
|
is_bd71837 = !ret && ((is_bd71837 & 0xf0) == 0xa0);
|
|
|
|
return is_bd71837 ? PCB_VERSION_1_0 : PCB_VERSION_1_1;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void select_dt_from_module_version(void)
|
|
|
|
{
|
|
|
|
char variant[32];
|
|
|
|
char *env_variant = env_get("variant");
|
|
|
|
int is_wifi = 0;
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_TDX_CFG_BLOCK)) {
|
|
|
|
/*
|
|
|
|
* If we have a valid config block and it says we are a
|
|
|
|
* module with Wi-Fi/Bluetooth make sure we use the -wifi
|
|
|
|
* device tree.
|
|
|
|
*/
|
|
|
|
is_wifi = (tdx_hw_tag.prodid == VERDIN_IMX8MMQ_WIFI_BT_IT) ||
|
2022-07-21 13:17:31 +00:00
|
|
|
(tdx_hw_tag.prodid == VERDIN_IMX8MMDL_WIFI_BT_IT) ||
|
|
|
|
(tdx_hw_tag.prodid == VERDIN_IMX8MMQ_WIFI_BT_IT_NO_CAN);
|
2020-10-28 09:58:13 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (get_pcb_revision()) {
|
|
|
|
case PCB_VERSION_1_0:
|
2021-10-09 20:41:10 +00:00
|
|
|
printf("Detected a V1.0 module which is no longer supported in this BSP version\n");
|
|
|
|
hang();
|
2020-10-28 09:58:13 +00:00
|
|
|
default:
|
|
|
|
if (is_wifi)
|
2021-10-09 20:41:10 +00:00
|
|
|
strlcpy(&variant[0], "wifi", sizeof(variant));
|
2020-10-28 09:58:13 +00:00
|
|
|
else
|
2021-10-09 20:41:10 +00:00
|
|
|
strlcpy(&variant[0], "nonwifi", sizeof(variant));
|
2020-10-28 09:58:13 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (strcmp(variant, env_variant)) {
|
|
|
|
printf("Setting variant to %s\n", variant);
|
|
|
|
env_set("variant", variant);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-01-28 13:42:25 +00:00
|
|
|
int board_late_init(void)
|
|
|
|
{
|
2020-10-28 09:58:13 +00:00
|
|
|
select_dt_from_module_version();
|
|
|
|
|
2020-01-28 13:42:25 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-10-28 09:58:16 +00:00
|
|
|
int board_phys_sdram_size(phys_size_t *size)
|
|
|
|
{
|
|
|
|
if (!size)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
*size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-01-28 13:42:25 +00:00
|
|
|
#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
|
2020-06-26 06:13:33 +00:00
|
|
|
int ft_board_setup(void *blob, struct bd_info *bd)
|
2020-01-28 13:42:25 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
#endif
|