blob: 7aca75503846f485df8bf18f9419dce0d6fd7578 [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 Harveya6614bb2022-08-11 11:55:38 -07006#include <fdt_support.h>
Tim Harvey256dba02021-03-02 14:00:21 -08007#include <init.h>
8#include <led.h>
Tim Harvey256dba02021-03-02 14:00:21 -08009#include <miiphy.h>
Tim Harvey0de4f2c2023-05-02 17:05:54 -070010#include <mmc.h>
Tim Harvey0f5717f2022-04-13 11:31:09 -070011#include <asm/arch/clock.h>
Tim Harvey256dba02021-03-02 14:00:21 -080012#include <asm/arch/sys_proto.h>
Tim Harvey256dba02021-03-02 14:00:21 -080013
Tim Harveyd4daeaa2022-04-13 08:56:40 -070014#include "eeprom.h"
Tim Harvey256dba02021-03-02 14:00:21 -080015
16int board_phys_sdram_size(phys_size_t *size)
17{
Tim Harvey56c5e312022-03-30 13:39:02 -070018 if (!size)
Tim Harvey195a1612021-07-27 15:19:37 -070019 return -EINVAL;
Tim Harvey256dba02021-03-02 14:00:21 -080020
Tim Harvey56c5e312022-03-30 13:39:02 -070021 *size = get_ram_size((void *)PHYS_SDRAM, PHYS_SDRAM_SIZE);
Tim Harvey256dba02021-03-02 14:00:21 -080022
23 return 0;
24}
25
26int board_fit_config_name_match(const char *name)
27{
28 int i = 0;
29 const char *dtb;
Tim Harvey637b8b12021-06-30 17:07:40 -070030 static char init;
Tim Harvey256dba02021-03-02 14:00:21 -080031 char buf[32];
32
33 do {
Tim Harveyd4daeaa2022-04-13 08:56:40 -070034 dtb = eeprom_get_dtb_name(i++, buf, sizeof(buf));
Tim Harvey637b8b12021-06-30 17:07:40 -070035 if (!strcmp(dtb, name)) {
36 if (!init++)
37 printf("DTB : %s\n", name);
Tim Harvey256dba02021-03-02 14:00:21 -080038 return 0;
Tim Harvey637b8b12021-06-30 17:07:40 -070039 }
Tim Harvey256dba02021-03-02 14:00:21 -080040 } while (dtb);
41
42 return -1;
43}
44
Simon Glassa2d42102023-02-22 09:34:24 -070045static int __maybe_unused setup_fec(void)
Tim Harvey256dba02021-03-02 14:00:21 -080046{
47 struct iomuxc_gpr_base_regs *gpr =
48 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
49
Tim Harvey0f5717f2022-04-13 11:31:09 -070050#ifndef CONFIG_IMX8MP
Tim Harvey256dba02021-03-02 14:00:21 -080051 /* Use 125M anatop REF_CLK1 for ENET1, not from external */
52 clrsetbits_le32(&gpr->gpr[1], 0x2000, 0);
Tim Harvey0f5717f2022-04-13 11:31:09 -070053#else
54 /* Enable RGMII TX clk output */
55 setbits_le32(&gpr->gpr[1], BIT(22));
56#endif
Tim Harvey256dba02021-03-02 14:00:21 -080057
58 return 0;
59}
60
Simon Glassa2d42102023-02-22 09:34:24 -070061#if (IS_ENABLED(CONFIG_NET))
Tim Harvey256dba02021-03-02 14:00:21 -080062int board_phy_config(struct phy_device *phydev)
63{
64 unsigned short val;
65
66 switch (phydev->phy_id) {
67 case 0x2000a231: /* TI DP83867 GbE PHY */
68 puts("DP83867 ");
69 /* LED configuration */
70 val = 0;
71 val |= 0x5 << 4; /* LED1(Amber;Speed) : 1000BT link */
72 val |= 0xb << 8; /* LED2(Green;Link/Act): blink for TX/RX act */
73 phy_write(phydev, MDIO_DEVAD_NONE, 24, val);
74 break;
75 }
76
77 if (phydev->drv->config)
78 phydev->drv->config(phydev);
79
80 return 0;
81}
Tim Harvey0f5717f2022-04-13 11:31:09 -070082#endif // IS_ENABLED(CONFIG_NET)
Tim Harvey256dba02021-03-02 14:00:21 -080083
84int board_init(void)
85{
Tim Harvey1fec1822022-08-11 12:04:01 -070086 venice_eeprom_init(1);
Tim Harvey256dba02021-03-02 14:00:21 -080087
88 if (IS_ENABLED(CONFIG_FEC_MXC))
89 setup_fec();
90
Tim Harvey256dba02021-03-02 14:00:21 -080091 return 0;
92}
93
94int board_late_init(void)
95{
Tim Harvey68901572021-06-30 17:07:41 -070096 const char *str;
Tim Harvey256dba02021-03-02 14:00:21 -080097 char env[32];
98 int ret, i;
99 u8 enetaddr[6];
Tim Harvey68901572021-06-30 17:07:41 -0700100 char fdt[64];
Tim Harvey256dba02021-03-02 14:00:21 -0800101
Tim Harvey78b8e072021-07-27 15:19:39 -0700102 /* Set board serial/model */
Tim Harvey62a13192021-08-18 15:24:28 -0700103 if (!env_get("serial#"))
Tim Harveyd4daeaa2022-04-13 08:56:40 -0700104 env_set_ulong("serial#", eeprom_get_serial());
105 env_set("model", eeprom_get_model());
Tim Harvey78b8e072021-07-27 15:19:39 -0700106
Tim Harvey68901572021-06-30 17:07:41 -0700107 /* Set fdt_file vars */
108 i = 0;
109 do {
Tim Harveyd4daeaa2022-04-13 08:56:40 -0700110 str = eeprom_get_dtb_name(i, fdt, sizeof(fdt));
Tim Harvey68901572021-06-30 17:07:41 -0700111 if (str) {
112 sprintf(env, "fdt_file%d", i + 1);
113 strcat(fdt, ".dtb");
114 env_set(env, fdt);
115 }
116 i++;
117 } while (str);
118
Tim Harvey256dba02021-03-02 14:00:21 -0800119 /* Set mac addrs */
120 i = 0;
121 do {
122 if (i)
123 sprintf(env, "eth%daddr", i);
124 else
125 sprintf(env, "ethaddr");
Tim Harvey68901572021-06-30 17:07:41 -0700126 str = env_get(env);
127 if (!str) {
Tim Harveyd4daeaa2022-04-13 08:56:40 -0700128 ret = eeprom_getmac(i, enetaddr);
Tim Harvey256dba02021-03-02 14:00:21 -0800129 if (!ret)
130 eth_env_set_enetaddr(env, enetaddr);
131 }
132 i++;
133 } while (!ret);
134
135 return 0;
136}
137
138int board_mmc_get_env_dev(int devno)
139{
140 return devno;
141}
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700142
Tim Harvey0de4f2c2023-05-02 17:05:54 -0700143uint mmc_get_env_part(struct mmc *mmc)
144{
145 if (!IS_SD(mmc)) {
146 switch (EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config)) {
147 case 1:
148 return 1;
149 case 2:
150 return 2;
151 }
152 }
153
154 return 0;
155}
156
Tim Harveya6614bb2022-08-11 11:55:38 -0700157int ft_board_setup(void *fdt, struct bd_info *bd)
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700158{
Tim Harveya6614bb2022-08-11 11:55:38 -0700159 const char *base_model = eeprom_get_baseboard_model();
160 char pcbrev;
Tim Harvey547f6aa2021-08-18 15:24:30 -0700161 int off;
162
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700163 /* set board model dt prop */
Tim Harveya6614bb2022-08-11 11:55:38 -0700164 fdt_setprop_string(fdt, 0, "board", eeprom_get_model());
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700165
Tim Harveya6614bb2022-08-11 11:55:38 -0700166 if (!strncmp(base_model, "GW73", 4)) {
167 pcbrev = get_pcb_rev(base_model);
168
169 if (pcbrev > 'B') {
170 printf("adjusting dt for %s\n", base_model);
171
172 /*
173 * revC replaced PCIe 5-port switch with 4-port
174 * which changed ethernet1 PCIe GbE
175 * from: pcie@0,0/pcie@1,0/pcie@2,4/pcie@6.0
176 * to: pcie@0,0/pcie@1,0/pcie@2,3/pcie@5.0
177 */
178 off = fdt_path_offset(fdt, "ethernet1");
179 if (off > 0) {
180 u32 reg[5];
181
182 fdt_set_name(fdt, off, "pcie@5,0");
183 off = fdt_parent_offset(fdt, off);
184 fdt_set_name(fdt, off, "pcie@2,3");
185 memset(reg, 0, sizeof(reg));
186 reg[0] = cpu_to_fdt32(PCI_DEVFN(3, 0));
187 fdt_setprop(fdt, off, "reg", reg, sizeof(reg));
188 }
Tim Harvey547f6aa2021-08-18 15:24:30 -0700189 }
190 }
191
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700192 return 0;
193}