blob: ca62f0be6d25b833b7557a113d0a1d4f354d9944 [file] [log] [blame]
Tim Harvey03bf8432021-03-02 14:00:21 -08001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * Copyright 2021 Gateworks Corporation
4 */
5
Tim Harvey77f6dab2022-08-11 11:55:38 -07006#include <fdt_support.h>
Tim Harvey03bf8432021-03-02 14:00:21 -08007#include <init.h>
8#include <led.h>
Tim Harvey03bf8432021-03-02 14:00:21 -08009#include <miiphy.h>
Tim Harvey23956252022-04-13 11:31:09 -070010#include <asm/arch/clock.h>
Tim Harvey03bf8432021-03-02 14:00:21 -080011#include <asm/arch/sys_proto.h>
Tim Harvey03bf8432021-03-02 14:00:21 -080012
Tim Harveyfb9ec332022-04-13 08:56:40 -070013#include "eeprom.h"
Tim Harvey03bf8432021-03-02 14:00:21 -080014
15int board_phys_sdram_size(phys_size_t *size)
16{
Tim Harvey52ae8d62022-03-30 13:39:02 -070017 if (!size)
Tim Harvey692c25e2021-07-27 15:19:37 -070018 return -EINVAL;
19
Tim Harvey52ae8d62022-03-30 13:39:02 -070020 *size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE);
Tim Harvey03bf8432021-03-02 14:00:21 -080021
22 return 0;
23}
24
25int board_fit_config_name_match(const char *name)
26{
27 int i = 0;
28 const char *dtb;
Tim Harvey9d2e6392021-06-30 17:07:40 -070029 static char init;
Tim Harvey03bf8432021-03-02 14:00:21 -080030 char buf[32];
31
32 do {
Tim Harveyfb9ec332022-04-13 08:56:40 -070033 dtb = eeprom_get_dtb_name(i++, buf, sizeof(buf));
Tim Harvey9d2e6392021-06-30 17:07:40 -070034 if (!strcmp(dtb, name)) {
35 if (!init++)
36 printf("DTB : %s\n", name);
Tim Harvey03bf8432021-03-02 14:00:21 -080037 return 0;
Tim Harvey9d2e6392021-06-30 17:07:40 -070038 }
Tim Harvey03bf8432021-03-02 14:00:21 -080039 } while (dtb);
40
41 return -1;
42}
43
Simon Glass9c097f82023-02-22 09:34:24 -070044static int __maybe_unused setup_fec(void)
Tim Harvey03bf8432021-03-02 14:00:21 -080045{
46 struct iomuxc_gpr_base_regs *gpr =
47 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
48
Tim Harvey23956252022-04-13 11:31:09 -070049#ifndef CONFIG_IMX8MP
Tim Harvey03bf8432021-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 Harvey23956252022-04-13 11:31:09 -070052#else
53 /* Enable RGMII TX clk output */
54 setbits_le32(&gpr->gpr[1], BIT(22));
55#endif
Tim Harvey03bf8432021-03-02 14:00:21 -080056
57 return 0;
58}
59
Simon Glass9c097f82023-02-22 09:34:24 -070060#if (IS_ENABLED(CONFIG_NET))
Tim Harvey03bf8432021-03-02 14:00:21 -080061int board_phy_config(struct phy_device *phydev)
62{
63 unsigned short val;
64
65 switch (phydev->phy_id) {
66 case 0x2000a231: /* TI DP83867 GbE PHY */
67 puts("DP83867 ");
68 /* LED configuration */
69 val = 0;
70 val |= 0x5 << 4; /* LED1(Amber;Speed) : 1000BT link */
71 val |= 0xb << 8; /* LED2(Green;Link/Act): blink for TX/RX act */
72 phy_write(phydev, MDIO_DEVAD_NONE, 24, val);
73 break;
74 }
75
76 if (phydev->drv->config)
77 phydev->drv->config(phydev);
78
79 return 0;
80}
Tim Harvey23956252022-04-13 11:31:09 -070081#endif // IS_ENABLED(CONFIG_NET)
Tim Harvey03bf8432021-03-02 14:00:21 -080082
83int board_init(void)
84{
Tim Harvey37d5bf42022-08-11 12:04:01 -070085 venice_eeprom_init(1);
Tim Harvey03bf8432021-03-02 14:00:21 -080086
87 if (IS_ENABLED(CONFIG_FEC_MXC))
88 setup_fec();
89
Tim Harvey03bf8432021-03-02 14:00:21 -080090 return 0;
91}
92
93int board_late_init(void)
94{
Tim Harvey0f3f6e62021-06-30 17:07:41 -070095 const char *str;
Tim Harvey03bf8432021-03-02 14:00:21 -080096 char env[32];
97 int ret, i;
98 u8 enetaddr[6];
Tim Harvey0f3f6e62021-06-30 17:07:41 -070099 char fdt[64];
Tim Harvey03bf8432021-03-02 14:00:21 -0800100
Tim Harvey57d27aa2021-07-27 15:19:39 -0700101 /* Set board serial/model */
Tim Harvey45e82c32021-08-18 15:24:28 -0700102 if (!env_get("serial#"))
Tim Harveyfb9ec332022-04-13 08:56:40 -0700103 env_set_ulong("serial#", eeprom_get_serial());
104 env_set("model", eeprom_get_model());
Tim Harvey57d27aa2021-07-27 15:19:39 -0700105
Tim Harvey0f3f6e62021-06-30 17:07:41 -0700106 /* Set fdt_file vars */
107 i = 0;
108 do {
Tim Harveyfb9ec332022-04-13 08:56:40 -0700109 str = eeprom_get_dtb_name(i, fdt, sizeof(fdt));
Tim Harvey0f3f6e62021-06-30 17:07:41 -0700110 if (str) {
111 sprintf(env, "fdt_file%d", i + 1);
112 strcat(fdt, ".dtb");
113 env_set(env, fdt);
114 }
115 i++;
116 } while (str);
117
Tim Harvey03bf8432021-03-02 14:00:21 -0800118 /* Set mac addrs */
119 i = 0;
120 do {
121 if (i)
122 sprintf(env, "eth%daddr", i);
123 else
124 sprintf(env, "ethaddr");
Tim Harvey0f3f6e62021-06-30 17:07:41 -0700125 str = env_get(env);
126 if (!str) {
Tim Harveyfb9ec332022-04-13 08:56:40 -0700127 ret = eeprom_getmac(i, enetaddr);
Tim Harvey03bf8432021-03-02 14:00:21 -0800128 if (!ret)
129 eth_env_set_enetaddr(env, enetaddr);
130 }
131 i++;
132 } while (!ret);
133
134 return 0;
135}
136
137int board_mmc_get_env_dev(int devno)
138{
139 return devno;
140}
Tim Harvey2eb85642021-07-27 15:19:40 -0700141
Tim Harvey77f6dab2022-08-11 11:55:38 -0700142int ft_board_setup(void *fdt, struct bd_info *bd)
Tim Harvey2eb85642021-07-27 15:19:40 -0700143{
Tim Harvey77f6dab2022-08-11 11:55:38 -0700144 const char *base_model = eeprom_get_baseboard_model();
145 char pcbrev;
Tim Harveyf8a792e2021-08-18 15:24:30 -0700146 int off;
147
Tim Harvey2eb85642021-07-27 15:19:40 -0700148 /* set board model dt prop */
Tim Harvey77f6dab2022-08-11 11:55:38 -0700149 fdt_setprop_string(fdt, 0, "board", eeprom_get_model());
Tim Harvey2eb85642021-07-27 15:19:40 -0700150
Tim Harvey77f6dab2022-08-11 11:55:38 -0700151 if (!strncmp(base_model, "GW73", 4)) {
152 pcbrev = get_pcb_rev(base_model);
153
154 if (pcbrev > 'B') {
155 printf("adjusting dt for %s\n", base_model);
156
157 /*
158 * revC replaced PCIe 5-port switch with 4-port
159 * which changed ethernet1 PCIe GbE
160 * from: pcie@0,0/pcie@1,0/pcie@2,4/pcie@6.0
161 * to: pcie@0,0/pcie@1,0/pcie@2,3/pcie@5.0
162 */
163 off = fdt_path_offset(fdt, "ethernet1");
164 if (off > 0) {
165 u32 reg[5];
166
167 fdt_set_name(fdt, off, "pcie@5,0");
168 off = fdt_parent_offset(fdt, off);
169 fdt_set_name(fdt, off, "pcie@2,3");
170 memset(reg, 0, sizeof(reg));
171 reg[0] = cpu_to_fdt32(PCI_DEVFN(3, 0));
172 fdt_setprop(fdt, off, "reg", reg, sizeof(reg));
173 }
Tim Harveyf8a792e2021-08-18 15:24:30 -0700174 }
175 }
176
Tim Harvey2eb85642021-07-27 15:19:40 -0700177 return 0;
178}