2021-03-02 22:00:21 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright 2021 Gateworks Corporation
|
|
|
|
*/
|
|
|
|
|
2022-08-11 18:55:38 +00:00
|
|
|
#include <fdt_support.h>
|
2021-03-02 22:00:21 +00:00
|
|
|
#include <init.h>
|
|
|
|
#include <led.h>
|
2023-05-03 00:05:55 +00:00
|
|
|
#include <mmc.h>
|
2021-03-02 22:00:21 +00:00
|
|
|
#include <miiphy.h>
|
2023-05-03 00:05:54 +00:00
|
|
|
#include <mmc.h>
|
2022-04-13 18:31:09 +00:00
|
|
|
#include <asm/arch/clock.h>
|
2021-03-02 22:00:21 +00:00
|
|
|
#include <asm/arch/sys_proto.h>
|
2023-05-03 00:05:55 +00:00
|
|
|
#include <asm/mach-imx/boot_mode.h>
|
2021-03-02 22:00:21 +00:00
|
|
|
|
2022-04-13 15:56:40 +00:00
|
|
|
#include "eeprom.h"
|
2021-03-02 22:00:21 +00:00
|
|
|
|
|
|
|
int board_phys_sdram_size(phys_size_t *size)
|
|
|
|
{
|
2022-03-30 20:39:02 +00:00
|
|
|
if (!size)
|
2021-07-27 22:19:37 +00:00
|
|
|
return -EINVAL;
|
|
|
|
|
2023-06-23 16:44:17 +00:00
|
|
|
*size = get_ram_size((void *)PHYS_SDRAM, (long)PHYS_SDRAM_SIZE + (long)PHYS_SDRAM_2_SIZE);
|
2021-03-02 22:00:21 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int board_fit_config_name_match(const char *name)
|
|
|
|
{
|
|
|
|
int i = 0;
|
|
|
|
const char *dtb;
|
2021-07-01 00:07:40 +00:00
|
|
|
static char init;
|
2021-03-02 22:00:21 +00:00
|
|
|
char buf[32];
|
|
|
|
|
|
|
|
do {
|
2022-04-13 15:56:40 +00:00
|
|
|
dtb = eeprom_get_dtb_name(i++, buf, sizeof(buf));
|
2021-07-01 00:07:40 +00:00
|
|
|
if (!strcmp(dtb, name)) {
|
|
|
|
if (!init++)
|
|
|
|
printf("DTB : %s\n", name);
|
2021-03-02 22:00:21 +00:00
|
|
|
return 0;
|
2021-07-01 00:07:40 +00:00
|
|
|
}
|
2021-03-02 22:00:21 +00:00
|
|
|
} while (dtb);
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2023-02-22 16:34:24 +00:00
|
|
|
static int __maybe_unused setup_fec(void)
|
2021-03-02 22:00:21 +00:00
|
|
|
{
|
|
|
|
struct iomuxc_gpr_base_regs *gpr =
|
|
|
|
(struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
|
|
|
|
|
2022-04-13 18:31:09 +00:00
|
|
|
#ifndef CONFIG_IMX8MP
|
2021-03-02 22:00:21 +00:00
|
|
|
/* Use 125M anatop REF_CLK1 for ENET1, not from external */
|
|
|
|
clrsetbits_le32(&gpr->gpr[1], 0x2000, 0);
|
2022-04-13 18:31:09 +00:00
|
|
|
#else
|
|
|
|
/* Enable RGMII TX clk output */
|
|
|
|
setbits_le32(&gpr->gpr[1], BIT(22));
|
|
|
|
#endif
|
2021-03-02 22:00:21 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-02-22 16:34:24 +00:00
|
|
|
#if (IS_ENABLED(CONFIG_NET))
|
2021-03-02 22:00:21 +00:00
|
|
|
int board_phy_config(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
unsigned short val;
|
|
|
|
|
|
|
|
switch (phydev->phy_id) {
|
|
|
|
case 0x2000a231: /* TI DP83867 GbE PHY */
|
|
|
|
puts("DP83867 ");
|
|
|
|
/* LED configuration */
|
|
|
|
val = 0;
|
|
|
|
val |= 0x5 << 4; /* LED1(Amber;Speed) : 1000BT link */
|
|
|
|
val |= 0xb << 8; /* LED2(Green;Link/Act): blink for TX/RX act */
|
|
|
|
phy_write(phydev, MDIO_DEVAD_NONE, 24, val);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (phydev->drv->config)
|
|
|
|
phydev->drv->config(phydev);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2022-04-13 18:31:09 +00:00
|
|
|
#endif // IS_ENABLED(CONFIG_NET)
|
2021-03-02 22:00:21 +00:00
|
|
|
|
|
|
|
int board_init(void)
|
|
|
|
{
|
2022-08-11 19:04:01 +00:00
|
|
|
venice_eeprom_init(1);
|
2021-03-02 22:00:21 +00:00
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_FEC_MXC))
|
|
|
|
setup_fec();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int board_late_init(void)
|
|
|
|
{
|
2021-07-01 00:07:41 +00:00
|
|
|
const char *str;
|
2023-05-03 00:05:55 +00:00
|
|
|
struct mmc *mmc = NULL;
|
2021-03-02 22:00:21 +00:00
|
|
|
char env[32];
|
|
|
|
int ret, i;
|
|
|
|
u8 enetaddr[6];
|
2021-07-01 00:07:41 +00:00
|
|
|
char fdt[64];
|
2023-05-03 00:05:55 +00:00
|
|
|
int bootdev;
|
2021-03-02 22:00:21 +00:00
|
|
|
|
2021-07-27 22:19:39 +00:00
|
|
|
/* Set board serial/model */
|
2021-08-18 22:24:28 +00:00
|
|
|
if (!env_get("serial#"))
|
2022-04-13 15:56:40 +00:00
|
|
|
env_set_ulong("serial#", eeprom_get_serial());
|
|
|
|
env_set("model", eeprom_get_model());
|
2021-07-27 22:19:39 +00:00
|
|
|
|
2021-07-01 00:07:41 +00:00
|
|
|
/* Set fdt_file vars */
|
|
|
|
i = 0;
|
|
|
|
do {
|
2022-04-13 15:56:40 +00:00
|
|
|
str = eeprom_get_dtb_name(i, fdt, sizeof(fdt));
|
2021-07-01 00:07:41 +00:00
|
|
|
if (str) {
|
|
|
|
sprintf(env, "fdt_file%d", i + 1);
|
|
|
|
strcat(fdt, ".dtb");
|
|
|
|
env_set(env, fdt);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
} while (str);
|
|
|
|
|
2021-03-02 22:00:21 +00:00
|
|
|
/* Set mac addrs */
|
|
|
|
i = 0;
|
|
|
|
do {
|
|
|
|
if (i)
|
|
|
|
sprintf(env, "eth%daddr", i);
|
|
|
|
else
|
|
|
|
sprintf(env, "ethaddr");
|
2021-07-01 00:07:41 +00:00
|
|
|
str = env_get(env);
|
|
|
|
if (!str) {
|
2022-04-13 15:56:40 +00:00
|
|
|
ret = eeprom_getmac(i, enetaddr);
|
2021-03-02 22:00:21 +00:00
|
|
|
if (!ret)
|
|
|
|
eth_env_set_enetaddr(env, enetaddr);
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
} while (!ret);
|
|
|
|
|
2023-05-03 00:05:55 +00:00
|
|
|
/*
|
|
|
|
* set bootdev/bootblk/bootpart (used in firmware_update script)
|
|
|
|
* dynamically depending on boot device and SoC
|
|
|
|
*/
|
|
|
|
bootdev = -1;
|
|
|
|
switch (get_boot_device()) {
|
|
|
|
case SD1_BOOT:
|
|
|
|
case MMC1_BOOT: /* SDHC1 */
|
|
|
|
bootdev = 0;
|
|
|
|
break;
|
|
|
|
case SD2_BOOT:
|
|
|
|
case MMC2_BOOT: /* SDHC2 */
|
|
|
|
bootdev = 1;
|
|
|
|
break;
|
|
|
|
case SD3_BOOT:
|
|
|
|
case MMC3_BOOT: /* SDHC3 */
|
|
|
|
bootdev = 2;
|
|
|
|
break;
|
|
|
|
default:
|
2023-06-09 16:51:46 +00:00
|
|
|
bootdev = 2; /* assume SDHC3 (eMMC) if booting over SDP */
|
2023-05-03 00:05:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (bootdev != -1)
|
|
|
|
mmc = find_mmc_device(bootdev);
|
|
|
|
if (mmc) {
|
|
|
|
int bootblk;
|
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_IMX8MN) || IS_ENABLED(CONFIG_IMX8MP))
|
|
|
|
bootblk = 32 * SZ_1K / 512;
|
|
|
|
else
|
|
|
|
bootblk = 33 * SZ_1K / 512;
|
|
|
|
mmc_init(mmc);
|
|
|
|
if (!IS_SD(mmc)) {
|
|
|
|
int bootpart;
|
|
|
|
|
|
|
|
switch (EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config)) {
|
|
|
|
case 1: /* boot0 */
|
|
|
|
bootpart = 1;
|
|
|
|
break;
|
|
|
|
case 2: /* boot1 */
|
|
|
|
bootpart = 2;
|
|
|
|
break;
|
|
|
|
case 7: /* user */
|
|
|
|
default:
|
|
|
|
bootpart = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* IMX8MP/IMX8MN BOOTROM v2 uses offset=0 for boot parts */
|
|
|
|
if ((IS_ENABLED(CONFIG_IMX8MN) || IS_ENABLED(CONFIG_IMX8MP)) &&
|
|
|
|
(bootpart == 1 || bootpart == 2))
|
|
|
|
bootblk = 0;
|
|
|
|
env_set_hex("bootpart", bootpart);
|
|
|
|
env_set_hex("bootblk", bootblk);
|
|
|
|
} else { /* SD */
|
|
|
|
env_set("bootpart", "");
|
|
|
|
env_set_hex("bootblk", bootblk);
|
|
|
|
}
|
|
|
|
env_set_hex("dev", bootdev);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* override soc=imx8m to provide a more specific soc name */
|
|
|
|
if (IS_ENABLED(CONFIG_IMX8MN))
|
|
|
|
env_set("soc", "imx8mn");
|
|
|
|
else if (IS_ENABLED(CONFIG_IMX8MP))
|
|
|
|
env_set("soc", "imx8mp");
|
|
|
|
else if (IS_ENABLED(CONFIG_IMX8MM))
|
|
|
|
env_set("soc", "imx8mm");
|
|
|
|
|
2021-03-02 22:00:21 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int board_mmc_get_env_dev(int devno)
|
|
|
|
{
|
|
|
|
return devno;
|
|
|
|
}
|
2021-07-27 22:19:40 +00:00
|
|
|
|
2023-05-03 00:05:54 +00:00
|
|
|
uint mmc_get_env_part(struct mmc *mmc)
|
|
|
|
{
|
|
|
|
if (!IS_SD(mmc)) {
|
|
|
|
switch (EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config)) {
|
|
|
|
case 1:
|
|
|
|
return 1;
|
|
|
|
case 2:
|
|
|
|
return 2;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2022-08-11 18:55:38 +00:00
|
|
|
int ft_board_setup(void *fdt, struct bd_info *bd)
|
2021-07-27 22:19:40 +00:00
|
|
|
{
|
2022-08-11 18:55:38 +00:00
|
|
|
const char *base_model = eeprom_get_baseboard_model();
|
|
|
|
char pcbrev;
|
2021-08-18 22:24:30 +00:00
|
|
|
int off;
|
|
|
|
|
2021-07-27 22:19:40 +00:00
|
|
|
/* set board model dt prop */
|
2022-08-11 18:55:38 +00:00
|
|
|
fdt_setprop_string(fdt, 0, "board", eeprom_get_model());
|
2021-07-27 22:19:40 +00:00
|
|
|
|
2022-08-11 18:55:38 +00:00
|
|
|
if (!strncmp(base_model, "GW73", 4)) {
|
|
|
|
pcbrev = get_pcb_rev(base_model);
|
|
|
|
|
|
|
|
if (pcbrev > 'B') {
|
|
|
|
printf("adjusting dt for %s\n", base_model);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* revC replaced PCIe 5-port switch with 4-port
|
|
|
|
* which changed ethernet1 PCIe GbE
|
|
|
|
* from: pcie@0,0/pcie@1,0/pcie@2,4/pcie@6.0
|
|
|
|
* to: pcie@0,0/pcie@1,0/pcie@2,3/pcie@5.0
|
|
|
|
*/
|
|
|
|
off = fdt_path_offset(fdt, "ethernet1");
|
|
|
|
if (off > 0) {
|
|
|
|
u32 reg[5];
|
|
|
|
|
|
|
|
fdt_set_name(fdt, off, "pcie@5,0");
|
|
|
|
off = fdt_parent_offset(fdt, off);
|
|
|
|
fdt_set_name(fdt, off, "pcie@2,3");
|
|
|
|
memset(reg, 0, sizeof(reg));
|
|
|
|
reg[0] = cpu_to_fdt32(PCI_DEVFN(3, 0));
|
|
|
|
fdt_setprop(fdt, off, "reg", reg, sizeof(reg));
|
|
|
|
}
|
2021-08-18 22:24:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-27 22:19:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|