blob: d4c22121497bebabb952df35525b1d822e6e13fc [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 Harveya32dd712023-05-02 17:05:55 -07009#include <mmc.h>
Tim Harvey256dba02021-03-02 14:00:21 -080010#include <miiphy.h>
Tim Harvey0de4f2c2023-05-02 17:05:54 -070011#include <mmc.h>
Tim Harvey0f5717f2022-04-13 11:31:09 -070012#include <asm/arch/clock.h>
Tim Harvey256dba02021-03-02 14:00:21 -080013#include <asm/arch/sys_proto.h>
Tim Harveya32dd712023-05-02 17:05:55 -070014#include <asm/mach-imx/boot_mode.h>
Tim Harvey256dba02021-03-02 14:00:21 -080015
Tim Harveyd4daeaa2022-04-13 08:56:40 -070016#include "eeprom.h"
Tim Harvey256dba02021-03-02 14:00:21 -080017
18int board_phys_sdram_size(phys_size_t *size)
19{
Tim Harvey56c5e312022-03-30 13:39:02 -070020 if (!size)
Tim Harvey195a1612021-07-27 15:19:37 -070021 return -EINVAL;
Tim Harvey256dba02021-03-02 14:00:21 -080022
Tim Harvey55475292023-06-23 09:44:17 -070023 *size = get_ram_size((void *)PHYS_SDRAM, (long)PHYS_SDRAM_SIZE + (long)PHYS_SDRAM_2_SIZE);
Tim Harvey256dba02021-03-02 14:00:21 -080024
25 return 0;
26}
27
Tim Harveyb326d462024-03-12 12:05:43 -070028int board_fit_config_name_match(const char *path)
Tim Harvey256dba02021-03-02 14:00:21 -080029{
Tim Harveyb326d462024-03-12 12:05:43 -070030 const char *name = path + strlen("freescale/");
Tim Harvey637b8b12021-06-30 17:07:40 -070031 static char init;
Tim Harveyb326d462024-03-12 12:05:43 -070032 const char *dtb;
Tim Harvey256dba02021-03-02 14:00:21 -080033 char buf[32];
Tim Harveyb326d462024-03-12 12:05:43 -070034 int i = 0;
Tim Harvey256dba02021-03-02 14:00:21 -080035
36 do {
Tim Harveyd4daeaa2022-04-13 08:56:40 -070037 dtb = eeprom_get_dtb_name(i++, buf, sizeof(buf));
Tim Harvey637b8b12021-06-30 17:07:40 -070038 if (!strcmp(dtb, name)) {
39 if (!init++)
40 printf("DTB : %s\n", name);
Tim Harvey256dba02021-03-02 14:00:21 -080041 return 0;
Tim Harvey637b8b12021-06-30 17:07:40 -070042 }
Tim Harvey256dba02021-03-02 14:00:21 -080043 } while (dtb);
44
45 return -1;
46}
47
Simon Glassa2d42102023-02-22 09:34:24 -070048#if (IS_ENABLED(CONFIG_NET))
Tim Harvey256dba02021-03-02 14:00:21 -080049int board_phy_config(struct phy_device *phydev)
50{
51 unsigned short val;
52
53 switch (phydev->phy_id) {
54 case 0x2000a231: /* TI DP83867 GbE PHY */
55 puts("DP83867 ");
56 /* LED configuration */
57 val = 0;
58 val |= 0x5 << 4; /* LED1(Amber;Speed) : 1000BT link */
59 val |= 0xb << 8; /* LED2(Green;Link/Act): blink for TX/RX act */
60 phy_write(phydev, MDIO_DEVAD_NONE, 24, val);
61 break;
Tim Harveyfc80be62024-06-19 14:13:39 -070062 case 0xd565a401: /* MaxLinear GPY111 */
63 puts("GPY111 ");
64 break;
Tim Harvey256dba02021-03-02 14:00:21 -080065 }
66
67 if (phydev->drv->config)
68 phydev->drv->config(phydev);
69
70 return 0;
71}
Tim Harvey0f5717f2022-04-13 11:31:09 -070072#endif // IS_ENABLED(CONFIG_NET)
Tim Harvey256dba02021-03-02 14:00:21 -080073
74int board_init(void)
75{
Tim Harvey1fec1822022-08-11 12:04:01 -070076 venice_eeprom_init(1);
Tim Harvey256dba02021-03-02 14:00:21 -080077
Tim Harvey256dba02021-03-02 14:00:21 -080078 return 0;
79}
80
81int board_late_init(void)
82{
Tim Harvey68901572021-06-30 17:07:41 -070083 const char *str;
Tim Harveya32dd712023-05-02 17:05:55 -070084 struct mmc *mmc = NULL;
Tim Harvey256dba02021-03-02 14:00:21 -080085 char env[32];
86 int ret, i;
87 u8 enetaddr[6];
Tim Harvey68901572021-06-30 17:07:41 -070088 char fdt[64];
Tim Harveya32dd712023-05-02 17:05:55 -070089 int bootdev;
Tim Harvey256dba02021-03-02 14:00:21 -080090
Tim Harvey78b8e072021-07-27 15:19:39 -070091 /* Set board serial/model */
Tim Harvey62a13192021-08-18 15:24:28 -070092 if (!env_get("serial#"))
Tim Harveyd4daeaa2022-04-13 08:56:40 -070093 env_set_ulong("serial#", eeprom_get_serial());
94 env_set("model", eeprom_get_model());
Tim Harvey78b8e072021-07-27 15:19:39 -070095
Tim Harvey68901572021-06-30 17:07:41 -070096 /* Set fdt_file vars */
97 i = 0;
98 do {
Tim Harveyd4daeaa2022-04-13 08:56:40 -070099 str = eeprom_get_dtb_name(i, fdt, sizeof(fdt));
Tim Harvey68901572021-06-30 17:07:41 -0700100 if (str) {
101 sprintf(env, "fdt_file%d", i + 1);
102 strcat(fdt, ".dtb");
103 env_set(env, fdt);
104 }
105 i++;
106 } while (str);
107
Tim Harvey256dba02021-03-02 14:00:21 -0800108 /* Set mac addrs */
109 i = 0;
110 do {
111 if (i)
112 sprintf(env, "eth%daddr", i);
113 else
114 sprintf(env, "ethaddr");
Tim Harvey68901572021-06-30 17:07:41 -0700115 str = env_get(env);
116 if (!str) {
Tim Harveyd4daeaa2022-04-13 08:56:40 -0700117 ret = eeprom_getmac(i, enetaddr);
Tim Harvey256dba02021-03-02 14:00:21 -0800118 if (!ret)
119 eth_env_set_enetaddr(env, enetaddr);
120 }
121 i++;
122 } while (!ret);
123
Tim Harveya32dd712023-05-02 17:05:55 -0700124 /*
125 * set bootdev/bootblk/bootpart (used in firmware_update script)
126 * dynamically depending on boot device and SoC
127 */
128 bootdev = -1;
129 switch (get_boot_device()) {
130 case SD1_BOOT:
131 case MMC1_BOOT: /* SDHC1 */
132 bootdev = 0;
133 break;
134 case SD2_BOOT:
135 case MMC2_BOOT: /* SDHC2 */
136 bootdev = 1;
137 break;
138 case SD3_BOOT:
139 case MMC3_BOOT: /* SDHC3 */
140 bootdev = 2;
141 break;
142 default:
Tim Harvey8bdb05d2023-06-09 09:51:46 -0700143 bootdev = 2; /* assume SDHC3 (eMMC) if booting over SDP */
Tim Harveya32dd712023-05-02 17:05:55 -0700144 break;
145 }
146 if (bootdev != -1)
147 mmc = find_mmc_device(bootdev);
148 if (mmc) {
149 int bootblk;
150
151 if (IS_ENABLED(CONFIG_IMX8MN) || IS_ENABLED(CONFIG_IMX8MP))
152 bootblk = 32 * SZ_1K / 512;
153 else
154 bootblk = 33 * SZ_1K / 512;
155 mmc_init(mmc);
156 if (!IS_SD(mmc)) {
157 int bootpart;
158
159 switch (EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config)) {
160 case 1: /* boot0 */
161 bootpart = 1;
162 break;
163 case 2: /* boot1 */
164 bootpart = 2;
165 break;
166 case 7: /* user */
167 default:
168 bootpart = 0;
169 break;
170 }
171 /* IMX8MP/IMX8MN BOOTROM v2 uses offset=0 for boot parts */
172 if ((IS_ENABLED(CONFIG_IMX8MN) || IS_ENABLED(CONFIG_IMX8MP)) &&
173 (bootpart == 1 || bootpart == 2))
174 bootblk = 0;
175 env_set_hex("bootpart", bootpart);
176 env_set_hex("bootblk", bootblk);
177 } else { /* SD */
178 env_set("bootpart", "");
179 env_set_hex("bootblk", bootblk);
180 }
181 env_set_hex("dev", bootdev);
182 }
183
184 /* override soc=imx8m to provide a more specific soc name */
185 if (IS_ENABLED(CONFIG_IMX8MN))
186 env_set("soc", "imx8mn");
187 else if (IS_ENABLED(CONFIG_IMX8MP))
188 env_set("soc", "imx8mp");
189 else if (IS_ENABLED(CONFIG_IMX8MM))
190 env_set("soc", "imx8mm");
191
Tim Harvey256dba02021-03-02 14:00:21 -0800192 return 0;
193}
194
195int board_mmc_get_env_dev(int devno)
196{
197 return devno;
198}
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700199
Tim Harvey0de4f2c2023-05-02 17:05:54 -0700200uint mmc_get_env_part(struct mmc *mmc)
201{
202 if (!IS_SD(mmc)) {
203 switch (EXT_CSD_EXTRACT_BOOT_PART(mmc->part_config)) {
204 case 1:
205 return 1;
206 case 2:
207 return 2;
208 }
209 }
210
211 return 0;
212}
213
Tim Harveya6614bb2022-08-11 11:55:38 -0700214int ft_board_setup(void *fdt, struct bd_info *bd)
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700215{
Tim Harveya6614bb2022-08-11 11:55:38 -0700216 const char *base_model = eeprom_get_baseboard_model();
Tim Harvey9fbf12b2024-04-17 13:01:53 -0700217 const char *path;
Tim Harveya6614bb2022-08-11 11:55:38 -0700218 char pcbrev;
Tim Harvey547f6aa2021-08-18 15:24:30 -0700219 int off;
220
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700221 /* set board model dt prop */
Tim Harveya6614bb2022-08-11 11:55:38 -0700222 fdt_setprop_string(fdt, 0, "board", eeprom_get_model());
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700223
Tim Harveya6614bb2022-08-11 11:55:38 -0700224 if (!strncmp(base_model, "GW73", 4)) {
225 pcbrev = get_pcb_rev(base_model);
Tim Harvey9fbf12b2024-04-17 13:01:53 -0700226 path = fdt_get_alias(fdt, "ethernet1");
Tim Harveya6614bb2022-08-11 11:55:38 -0700227
Tim Harvey9fbf12b2024-04-17 13:01:53 -0700228 if (pcbrev > 'B' && pcbrev < 'E' && path && !strncmp(path, "/soc@0/pcie@", 12)) {
229 printf("adjusting %s pcie\n", base_model);
Tim Harveya6614bb2022-08-11 11:55:38 -0700230 /*
Tim Harvey3dfc10b2023-10-18 11:33:06 -0700231 * revC/D/E has PCIe 4-port switch which changes
232 * ethernet1 PCIe GbE:
Tim Harveya6614bb2022-08-11 11:55:38 -0700233 * from: pcie@0,0/pcie@1,0/pcie@2,4/pcie@6.0
234 * to: pcie@0,0/pcie@1,0/pcie@2,3/pcie@5.0
235 */
236 off = fdt_path_offset(fdt, "ethernet1");
237 if (off > 0) {
238 u32 reg[5];
239
240 fdt_set_name(fdt, off, "pcie@5,0");
241 off = fdt_parent_offset(fdt, off);
242 fdt_set_name(fdt, off, "pcie@2,3");
243 memset(reg, 0, sizeof(reg));
244 reg[0] = cpu_to_fdt32(PCI_DEVFN(3, 0));
245 fdt_setprop(fdt, off, "reg", reg, sizeof(reg));
246 }
Tim Harvey547f6aa2021-08-18 15:24:30 -0700247 }
248 }
249
Tim Harvey60c1bfd2021-07-27 15:19:40 -0700250 return 0;
251}