2021-03-02 22:00:21 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright 2021 Gateworks Corporation
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <init.h>
|
|
|
|
#include <led.h>
|
|
|
|
#include <miiphy.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>
|
|
|
|
|
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;
|
|
|
|
|
2022-03-30 20:39:02 +00:00
|
|
|
*size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_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;
|
|
|
|
}
|
|
|
|
|
2022-04-13 18:31:09 +00:00
|
|
|
#if (IS_ENABLED(CONFIG_NET))
|
2021-03-02 22:00:21 +00:00
|
|
|
static int setup_fec(void)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-04-13 18:31:09 +00:00
|
|
|
static int setup_eqos(void)
|
|
|
|
{
|
|
|
|
struct iomuxc_gpr_base_regs *gpr =
|
|
|
|
(struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
|
|
|
|
|
|
|
|
/* set INTF as RGMII, enable RGMII TXC clock */
|
|
|
|
clrsetbits_le32(&gpr->gpr[1],
|
|
|
|
IOMUXC_GPR_GPR1_GPR_ENET_QOS_INTF_SEL_MASK, BIT(16));
|
|
|
|
setbits_le32(&gpr->gpr[1], BIT(19) | BIT(21));
|
|
|
|
|
|
|
|
return set_clk_eqos(ENET_125MHZ);
|
|
|
|
}
|
|
|
|
|
2021-03-02 22:00:21 +00:00
|
|
|
int board_phy_config(struct phy_device *phydev)
|
|
|
|
{
|
|
|
|
unsigned short val;
|
2022-03-08 18:47:44 +00:00
|
|
|
ofnode node;
|
2021-03-02 22:00:21 +00:00
|
|
|
|
|
|
|
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;
|
2022-03-08 18:47:44 +00:00
|
|
|
case 0xd565a401: /* MaxLinear GPY111 */
|
|
|
|
puts("GPY111 ");
|
|
|
|
node = phy_get_ofnode(phydev);
|
|
|
|
if (ofnode_valid(node)) {
|
|
|
|
u32 rx_delay, tx_delay;
|
|
|
|
|
|
|
|
rx_delay = ofnode_read_u32_default(node, "rx-internal-delay-ps", 2000);
|
|
|
|
tx_delay = ofnode_read_u32_default(node, "tx-internal-delay-ps", 2000);
|
|
|
|
val = phy_read(phydev, MDIO_DEVAD_NONE, 0x17);
|
|
|
|
val &= ~((0x7 << 12) | (0x7 << 8));
|
|
|
|
val |= (rx_delay / 500) << 12;
|
|
|
|
val |= (tx_delay / 500) << 8;
|
|
|
|
phy_write(phydev, MDIO_DEVAD_NONE, 0x17, val);
|
|
|
|
}
|
|
|
|
break;
|
2021-03-02 22:00:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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-04-13 15:56:40 +00:00
|
|
|
eeprom_init(1);
|
2021-03-02 22:00:21 +00:00
|
|
|
|
|
|
|
if (IS_ENABLED(CONFIG_FEC_MXC))
|
|
|
|
setup_fec();
|
2022-04-13 18:31:09 +00:00
|
|
|
if (IS_ENABLED(CONFIG_DWC_ETH_QOS))
|
|
|
|
setup_eqos();
|
2021-03-02 22:00:21 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int board_late_init(void)
|
|
|
|
{
|
2021-07-01 00:07:41 +00:00
|
|
|
const char *str;
|
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];
|
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);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int board_mmc_get_env_dev(int devno)
|
|
|
|
{
|
|
|
|
return devno;
|
|
|
|
}
|
2021-07-27 22:19:40 +00:00
|
|
|
|
|
|
|
int ft_board_setup(void *blob, struct bd_info *bd)
|
|
|
|
{
|
2021-08-18 22:24:30 +00:00
|
|
|
int off;
|
|
|
|
|
2021-07-27 22:19:40 +00:00
|
|
|
/* set board model dt prop */
|
2022-04-13 15:56:40 +00:00
|
|
|
fdt_setprop_string(blob, 0, "board", eeprom_get_model());
|
2021-07-27 22:19:40 +00:00
|
|
|
|
2021-08-18 22:24:30 +00:00
|
|
|
/* update temp thresholds */
|
|
|
|
off = fdt_path_offset(blob, "/thermal-zones/cpu-thermal/trips");
|
|
|
|
if (off >= 0) {
|
|
|
|
int minc, maxc, prop;
|
|
|
|
|
|
|
|
get_cpu_temp_grade(&minc, &maxc);
|
|
|
|
fdt_for_each_subnode(prop, blob, off) {
|
|
|
|
const char *type = fdt_getprop(blob, prop, "type", NULL);
|
|
|
|
|
|
|
|
if (type && (!strcmp("critical", type)))
|
|
|
|
fdt_setprop_u32(blob, prop, "temperature", maxc * 1000);
|
|
|
|
else if (type && (!strcmp("passive", type)))
|
|
|
|
fdt_setprop_u32(blob, prop, "temperature", (maxc - 10) * 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-27 22:19:40 +00:00
|
|
|
return 0;
|
|
|
|
}
|