blob: f1efabb203d7e8a876a5dfda69b71797edba22a5 [file] [log] [blame]
Tim Harvey256dba02021-03-02 14:00:21 -08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2021 Gateworks Corporation
4 */
5
Tim Harvey256dba02021-03-02 14:00:21 -08006#include <init.h>
7#include <led.h>
Tim Harvey256dba02021-03-02 14:00:21 -08008#include <miiphy.h>
Tim Harvey0f5717f2022-04-13 11:31:09 -07009#include <asm/arch/clock.h>
Tim Harvey256dba02021-03-02 14:00:21 -080010#include <asm/arch/sys_proto.h>
Tim Harvey256dba02021-03-02 14:00:21 -080011
Tim Harveyd4daeaa2022-04-13 08:56:40 -070012#include "eeprom.h"
Tim Harvey256dba02021-03-02 14:00:21 -080013
14int board_phys_sdram_size(phys_size_t *size)
15{
Tim Harvey56c5e312022-03-30 13:39:02 -070016 if (!size)
Tim Harvey195a1612021-07-27 15:19:37 -070017 return -EINVAL;
Tim Harvey256dba02021-03-02 14:00:21 -080018
Tim Harvey56c5e312022-03-30 13:39:02 -070019 *size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE);
Tim Harvey256dba02021-03-02 14:00:21 -080020
21 return 0;
22}
23
24int board_fit_config_name_match(const char *name)
25{
26 int i = 0;
27 const char *dtb;
Tim Harvey637b8b12021-06-30 17:07:40 -070028 static char init;
Tim Harvey256dba02021-03-02 14:00:21 -080029 char buf[32];
30
31 do {
Tim Harveyd4daeaa2022-04-13 08:56:40 -070032 dtb = eeprom_get_dtb_name(i++, buf, sizeof(buf));
Tim Harvey637b8b12021-06-30 17:07:40 -070033 if (!strcmp(dtb, name)) {
34 if (!init++)
35 printf("DTB : %s\n", name);
Tim Harvey256dba02021-03-02 14:00:21 -080036 return 0;
Tim Harvey637b8b12021-06-30 17:07:40 -070037 }
Tim Harvey256dba02021-03-02 14:00:21 -080038 } while (dtb);
39
40 return -1;
41}
42
Tim Harvey0f5717f2022-04-13 11:31:09 -070043#if (IS_ENABLED(CONFIG_NET))
Tim Harvey256dba02021-03-02 14:00:21 -080044static int setup_fec(void)
45{
46 struct iomuxc_gpr_base_regs *gpr =
47 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
48
Tim Harvey0f5717f2022-04-13 11:31:09 -070049#ifndef CONFIG_IMX8MP
Tim Harvey256dba02021-03-02 14:00:21 -080050 /* Use 125M anatop REF_CLK1 for ENET1, not from external */
51 clrsetbits_le32(&gpr->gpr[1], 0x2000, 0);
Tim Harvey0f5717f2022-04-13 11:31:09 -070052#else
53 /* Enable RGMII TX clk output */
54 setbits_le32(&gpr->gpr[1], BIT(22));
55#endif
Tim Harvey256dba02021-03-02 14:00:21 -080056
57 return 0;
58}
59
Tim Harvey0f5717f2022-04-13 11:31:09 -070060static int setup_eqos(void)
61{
62 struct iomuxc_gpr_base_regs *gpr =
63 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
64
65 /* set INTF as RGMII, enable RGMII TXC clock */
66 clrsetbits_le32(&gpr->gpr[1],
67 IOMUXC_GPR_GPR1_GPR_ENET_QOS_INTF_SEL_MASK, BIT(16));
68 setbits_le32(&gpr->gpr[1], BIT(19) | BIT(21));
69
70 return set_clk_eqos(ENET_125MHZ);
71}
72
Tim Harvey256dba02021-03-02 14:00:21 -080073int board_phy_config(struct phy_device *phydev)
74{
75 unsigned short val;
Tim Harveya82c8ff2022-03-08 10:47:44 -080076 ofnode node;
Tim Harvey256dba02021-03-02 14:00:21 -080077
78 switch (phydev->phy_id) {
79 case 0x2000a231: /* TI DP83867 GbE PHY */
80 puts("DP83867 ");
81 /* LED configuration */
82 val = 0;
83 val |= 0x5 << 4; /* LED1(Amber;Speed) : 1000BT link */
84 val |= 0xb << 8; /* LED2(Green;Link/Act): blink for TX/RX act */
85 phy_write(phydev, MDIO_DEVAD_NONE, 24, val);
86 break;
Tim Harveya82c8ff2022-03-08 10:47:44 -080087 case 0xd565a401: /* MaxLinear GPY111 */
88 puts("GPY111 ");
89 node = phy_get_ofnode(phydev);
90 if (ofnode_valid(node)) {
91 u32 rx_delay, tx_delay;
92
93 rx_delay = ofnode_read_u32_default(node, "rx-internal-delay-ps", 2000);
94 tx_delay = ofnode_read_u32_default(node, "tx-internal-delay-ps", 2000);
95 val = phy_read(phydev, MDIO_DEVAD_NONE, 0x17);
96 val &= ~((0x7 << 12) | (0x7 << 8));
97 val |= (rx_delay / 500) << 12;
98 val |= (tx_delay / 500) << 8;
99 phy_write(phydev, MDIO_DEVAD_NONE, 0x17, val);
100 }
101 break;
Tim Harvey256dba02021-03-02 14:00:21 -0800102 }
103
104 if (phydev->drv->config)
105 phydev->drv->config(phydev);
106
107 return 0;
108}
Tim Harvey0f5717f2022-04-13 11:31:09 -0700109#endif // IS_ENABLED(CONFIG_NET)
Tim Harvey256dba02021-03-02 14:00:21 -0800110
111int board_init(void)
112{
Tim Harveyd4daeaa2022-04-13 08:56:40 -0700113 eeprom_init(1);
Tim Harvey256dba02021-03-02 14:00:21 -0800114
115 if (IS_ENABLED(CONFIG_FEC_MXC))
116 setup_fec();
Tim Harvey0f5717f2022-04-13 11:31:09 -0700117 if (IS_ENABLED(CONFIG_DWC_ETH_QOS))
118 setup_eqos();
Tim Harvey256dba02021-03-02 14:00:21 -0800119
Tim Harvey256dba02021-03-02 14:00:21 -0800120 return 0;
121}
122
123int board_late_init(void)
124{
Tim Harvey68901572021-06-30 17:07:41 -0700125 const char *str;
Tim Harvey256dba02021-03-02 14:00:21 -0800126 char env[32];
127 int ret, i;
128 u8 enetaddr[6];
Tim Harvey68901572021-06-30 17:07:41 -0700129 char fdt[64];
Tim Harvey256dba02021-03-02 14:00:21 -0800130
Tim Harvey78b8e072021-07-27 15:19:39 -0700131 /* Set board serial/model */
Tim Harvey62a13192021-08-18 15:24:28 -0700132 if (!env_get("serial#"))
Tim Harveyd4daeaa2022-04-13 08:56:40 -0700133 env_set_ulong("serial#", eeprom_get_serial());
134 env_set("model", eeprom_get_model());
Tim Harvey78b8e072021-07-27 15:19:39 -0700135
Tim Harvey68901572021-06-30 17:07:41 -0700136 /* Set fdt_file vars */
137 i = 0;
138 do {
Tim Harveyd4daeaa2022-04-13 08:56:40 -0700139 str = eeprom_get_dtb_name(i, fdt, sizeof(fdt));
Tim Harvey68901572021-06-30 17:07:41 -0700140 if (str) {
141 sprintf(env, "fdt_file%d", i + 1);
142 strcat(fdt, ".dtb");
143 env_set(env, fdt);
144 }
145 i++;
146 } while (str);
147
Tim Harvey256dba02021-03-02 14:00:21 -0800148 /* Set mac addrs */
149 i = 0;
150 do {
151 if (i)
152 sprintf(env, "eth%daddr", i);
153 else
154 sprintf(env, "ethaddr");
Tim Harvey68901572021-06-30 17:07:41 -0700155 str = env_get(env);
156 if (!str) {
Tim Harveyd4daeaa2022-04-13 08:56:40 -0700157 ret = eeprom_getmac(i, enetaddr);
Tim Harvey256dba02021-03-02 14:00:21 -0800158 if (!ret)
159 eth_env_set_enetaddr(env, enetaddr);
160 }
161 i++;
162 } while (!ret);
163
164 return 0;
165}
166
167int board_mmc_get_env_dev(int devno)
168{
169 return devno;
170}
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700171
172int ft_board_setup(void *blob, struct bd_info *bd)
173{
Tim Harvey547f6aa2021-08-18 15:24:30 -0700174 int off;
175
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700176 /* set board model dt prop */
Tim Harveyd4daeaa2022-04-13 08:56:40 -0700177 fdt_setprop_string(blob, 0, "board", eeprom_get_model());
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700178
Tim Harvey547f6aa2021-08-18 15:24:30 -0700179 /* update temp thresholds */
180 off = fdt_path_offset(blob, "/thermal-zones/cpu-thermal/trips");
181 if (off >= 0) {
182 int minc, maxc, prop;
183
184 get_cpu_temp_grade(&minc, &maxc);
185 fdt_for_each_subnode(prop, blob, off) {
186 const char *type = fdt_getprop(blob, prop, "type", NULL);
187
188 if (type && (!strcmp("critical", type)))
189 fdt_setprop_u32(blob, prop, "temperature", maxc * 1000);
190 else if (type && (!strcmp("passive", type)))
191 fdt_setprop_u32(blob, prop, "temperature", (maxc - 10) * 1000);
192 }
193 }
194
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700195 return 0;
196}