blob: 4290a69807719003550a39c1a6e596de25a58572 [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
131 led_default_state();
132
Tim Harvey78b8e072021-07-27 15:19:39 -0700133 /* Set board serial/model */
Tim Harvey62a13192021-08-18 15:24:28 -0700134 if (!env_get("serial#"))
Tim Harveyd4daeaa2022-04-13 08:56:40 -0700135 env_set_ulong("serial#", eeprom_get_serial());
136 env_set("model", eeprom_get_model());
Tim Harvey78b8e072021-07-27 15:19:39 -0700137
Tim Harvey68901572021-06-30 17:07:41 -0700138 /* Set fdt_file vars */
139 i = 0;
140 do {
Tim Harveyd4daeaa2022-04-13 08:56:40 -0700141 str = eeprom_get_dtb_name(i, fdt, sizeof(fdt));
Tim Harvey68901572021-06-30 17:07:41 -0700142 if (str) {
143 sprintf(env, "fdt_file%d", i + 1);
144 strcat(fdt, ".dtb");
145 env_set(env, fdt);
146 }
147 i++;
148 } while (str);
149
Tim Harvey256dba02021-03-02 14:00:21 -0800150 /* Set mac addrs */
151 i = 0;
152 do {
153 if (i)
154 sprintf(env, "eth%daddr", i);
155 else
156 sprintf(env, "ethaddr");
Tim Harvey68901572021-06-30 17:07:41 -0700157 str = env_get(env);
158 if (!str) {
Tim Harveyd4daeaa2022-04-13 08:56:40 -0700159 ret = eeprom_getmac(i, enetaddr);
Tim Harvey256dba02021-03-02 14:00:21 -0800160 if (!ret)
161 eth_env_set_enetaddr(env, enetaddr);
162 }
163 i++;
164 } while (!ret);
165
166 return 0;
167}
168
169int board_mmc_get_env_dev(int devno)
170{
171 return devno;
172}
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700173
174int ft_board_setup(void *blob, struct bd_info *bd)
175{
Tim Harvey547f6aa2021-08-18 15:24:30 -0700176 int off;
177
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700178 /* set board model dt prop */
Tim Harveyd4daeaa2022-04-13 08:56:40 -0700179 fdt_setprop_string(blob, 0, "board", eeprom_get_model());
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700180
Tim Harvey547f6aa2021-08-18 15:24:30 -0700181 /* update temp thresholds */
182 off = fdt_path_offset(blob, "/thermal-zones/cpu-thermal/trips");
183 if (off >= 0) {
184 int minc, maxc, prop;
185
186 get_cpu_temp_grade(&minc, &maxc);
187 fdt_for_each_subnode(prop, blob, off) {
188 const char *type = fdt_getprop(blob, prop, "type", NULL);
189
190 if (type && (!strcmp("critical", type)))
191 fdt_setprop_u32(blob, prop, "temperature", maxc * 1000);
192 else if (type && (!strcmp("passive", type)))
193 fdt_setprop_u32(blob, prop, "temperature", (maxc - 10) * 1000);
194 }
195 }
196
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700197 return 0;
198}