blob: cd15410978ef9ec055f70d1b24b99bcc5007b2ca [file] [log] [blame]
Ying-Chun Liu (PaulLiu)a97107f2021-04-22 04:50:31 +08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2018 NXP
4 * Copyright 2020 Linaro
5 */
6
7#include <common.h>
8#include <env.h>
Ying-Chun Liu (PaulLiu)20dc0ba2021-08-24 17:44:19 +08009#include <hang.h>
Ying-Chun Liu (PaulLiu)a97107f2021-04-22 04:50:31 +080010#include <init.h>
11#include <miiphy.h>
12#include <netdev.h>
13
14#include <asm/arch/clock.h>
15#include <asm/arch/sys_proto.h>
16#include <asm/io.h>
17
Ying-Chun Liu (PaulLiu)20dc0ba2021-08-24 17:44:19 +080018#include "ddr/ddr.h"
19
Ying-Chun Liu (PaulLiu)a97107f2021-04-22 04:50:31 +080020DECLARE_GLOBAL_DATA_PTR;
21
Ying-Chun Liu (PaulLiu)20dc0ba2021-08-24 17:44:19 +080022int board_phys_sdram_size(phys_size_t *size)
23{
24 struct lpddr4_tcm_desc *lpddr4_tcm_desc =
25 (struct lpddr4_tcm_desc *)TCM_DATA_CFG;
26
27 switch (lpddr4_tcm_desc->size) {
28 case 4096:
29 case 2048:
30 case 1024:
31 *size = (1L << 20) * lpddr4_tcm_desc->size;
32 break;
33 default:
34 printf("%s: DRAM size %uM is not supported\n",
35 __func__,
36 lpddr4_tcm_desc->size);
37 hang();
38 break;
39 };
40
41 return 0;
42}
43
Ying-Chun Liu (PaulLiu)a97107f2021-04-22 04:50:31 +080044static int setup_fec(void)
45{
46 if (IS_ENABLED(CONFIG_FEC_MXC)) {
47 struct iomuxc_gpr_base_regs *gpr =
48 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
49
50 /* Use 125M anatop REF_CLK1 for ENET1, not from external */
51 clrsetbits_le32(&gpr->gpr[1], 0x2000, 0);
52 }
53
54 return 0;
55}
56
57int board_phy_config(struct phy_device *phydev)
58{
59 if (IS_ENABLED(CONFIG_FEC_MXC)) {
60 /* enable rgmii rxc skew and phy mode select to RGMII copper */
61 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x1f);
62 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x8);
63
64 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x00);
65 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x82ee);
66 phy_write(phydev, MDIO_DEVAD_NONE, 0x1d, 0x05);
67 phy_write(phydev, MDIO_DEVAD_NONE, 0x1e, 0x100);
68
69 if (phydev->drv->config)
70 phydev->drv->config(phydev);
71 }
72 return 0;
73}
74
75int board_init(void)
76{
77 if (IS_ENABLED(CONFIG_FEC_MXC))
78 setup_fec();
79
80 return 0;
81}
82
83int board_mmc_get_env_dev(int devno)
84{
85 return devno;
86}
87
88int board_late_init(void)
89{
90 if (IS_ENABLED(CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG)) {
91 env_set("board_name", "IOT-GATE-IMX8");
92 env_set("board_rev", "SBC-IOTMX8");
93 }
94
95 return 0;
96}