blob: 0a6fd7f1437e2e665e9b9521132f9b7d957f9204 [file] [log] [blame]
Lukasz Majewskif3adb662019-12-08 22:06:56 +01001// SPDX-License-Identifier: GPL-2.0+
2/*
3 * XEA iMX28 board
4 *
5 * Copyright (C) 2019 DENX Software Engineering
6 * Lukasz Majewski, DENX Software Engineering, lukma@denx.de
7 *
8 * Copyright (C) 2018 DENX Software Engineering
9 * Måns Rullgård, DENX Software Engineering, mans@mansr.com
10 *
11 * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
12 * on behalf of DENX Software Engineering GmbH
13 *
14 */
15
16#include <common.h>
Simon Glass2dc9c342020-05-10 11:40:01 -060017#include <fdt_support.h>
Simon Glass97589732020-05-10 11:40:02 -060018#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060019#include <log.h>
Simon Glass274e0b02020-05-10 11:39:56 -060020#include <net.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060021#include <asm/global_data.h>
Lukasz Majewskif3adb662019-12-08 22:06:56 +010022#include <asm/gpio.h>
23#include <asm/io.h>
24#include <asm/arch/imx-regs.h>
25#include <asm/arch/iomux-mx28.h>
26#include <asm/arch/clock.h>
27#include <asm/arch/sys_proto.h>
Simon Glassdbd79542020-05-10 11:40:11 -060028#include <linux/delay.h>
Lukasz Majewskif3adb662019-12-08 22:06:56 +010029#include <linux/mii.h>
30#include <miiphy.h>
31#include <netdev.h>
32#include <errno.h>
33#include <usb.h>
34#include <serial.h>
Anatolij Gustschin6322fc12024-01-15 14:51:30 +010035#include <u-boot/crc.h>
36#include "boot_img_scr.h"
37
38#include <spi.h>
39#include <spi_flash.h>
Lukasz Majewskif3adb662019-12-08 22:06:56 +010040
41#ifdef CONFIG_SPL_BUILD
42#include <spl.h>
43#endif
44
45DECLARE_GLOBAL_DATA_PTR;
46
47/*
48 * Functions
49 */
50
51static void init_clocks(void)
52{
53 /* IO0 clock at 480MHz */
54 mxs_set_ioclk(MXC_IOCLK0, 480000);
55 /* IO1 clock at 480MHz */
56 mxs_set_ioclk(MXC_IOCLK1, 480000);
57
58 /* SSP0 clock at 96MHz */
59 mxs_set_sspclk(MXC_SSPCLK0, 96000, 0);
60 /* SSP2 clock at 160MHz */
61 mxs_set_sspclk(MXC_SSPCLK2, 160000, 0);
62 /* SSP3 clock at 96MHz */
63 mxs_set_sspclk(MXC_SSPCLK3, 96000, 0);
64}
65
Lukasz Majewski09207162021-12-27 11:38:21 +010066#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_FRAMEWORK)
Lukasz Majewskif3adb662019-12-08 22:06:56 +010067void board_init_f(ulong arg)
68{
69 init_clocks();
Lukasz Majewskibc6026d2023-05-19 12:43:55 +020070 spl_early_init();
Lukasz Majewskif3adb662019-12-08 22:06:56 +010071 preloader_console_init();
72}
73
Anatolij Gustschin6322fc12024-01-15 14:51:30 +010074static struct boot_img_src img_src[2];
75static int spi_load_boot_info(void)
76{
77 struct spi_flash *flash;
78 int err;
79
80 flash = spi_flash_probe(CONFIG_SF_DEFAULT_BUS,
81 CONFIG_SF_DEFAULT_CS,
82 CONFIG_SF_DEFAULT_SPEED,
83 CONFIG_SF_DEFAULT_MODE);
84 if (!flash) {
85 printf("%s: SPI probe err\n", __func__);
86 return -ENODEV;
87 }
88
89 /*
90 * Load both boot info structs from SPI flash
91 */
92 err = spi_flash_read(flash, SPI_FLASH_BOOT_SRC_OFFS,
93 sizeof(img_src[0]),
94 (void *)&img_src[0]);
95 if (err) {
96 debug("%s: First boot info NOR sector read error %d\n",
97 __func__, err);
98 return err;
99 }
100
101 err = spi_flash_read(flash,
102 SPI_FLASH_BOOT_SRC_OFFS + SPI_FLASH_SECTOR_SIZE,
103 sizeof(img_src[0]),
104 (void *)&img_src[1]);
105 if (err) {
106 debug("%s: First boot info NOR sector read error %d\n",
107 __func__, err);
108 return err;
109 }
110
111 debug("%s: BI0 0x%x 0x%x 0x%x\n", __func__,
112 img_src[0].magic, img_src[0].flags, img_src[0].crc8);
113
114 debug("%s: BI1 0x%x 0x%x 0x%x\n", __func__,
115 img_src[1].magic, img_src[1].flags, img_src[1].crc8);
116
117 return 0;
118}
119
Lukasz Majewskif3adb662019-12-08 22:06:56 +0100120static int boot_tiva0, boot_tiva1;
121
122/* Check if TIVAs request booting via U-Boot proper */
123void spl_board_init(void)
124{
Lukasz Majewski07adfb12020-01-25 09:01:39 +0100125 struct gpio_desc btiva0, btiva1, en_3_3v;
Lukasz Majewskif3adb662019-12-08 22:06:56 +0100126 int ret;
127
Lukasz Majewski07adfb12020-01-25 09:01:39 +0100128 /*
129 * Setup GPIO0_0 (TIVA power enable pin) to be output high
130 * to allow TIVA startup.
131 */
132 ret = dm_gpio_lookup_name("GPIO0_0", &en_3_3v);
133 if (ret)
134 printf("Cannot get GPIO0_0\n");
135
136 ret = dm_gpio_request(&en_3_3v, "pwr_3_3v");
137 if (ret)
138 printf("Cannot request GPIO0_0\n");
139
140 /* Set GPIO0_0 to HIGH */
141 dm_gpio_set_dir_flags(&en_3_3v, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
142
Lukasz Majewskif3adb662019-12-08 22:06:56 +0100143 ret = dm_gpio_lookup_name("GPIO0_23", &btiva0);
144 if (ret)
145 printf("Cannot get GPIO0_23\n");
146
147 ret = dm_gpio_lookup_name("GPIO0_25", &btiva1);
148 if (ret)
149 printf("Cannot get GPIO0_25\n");
150
151 ret = dm_gpio_request(&btiva0, "boot-tiva0");
152 if (ret)
153 printf("Cannot request GPIO0_23\n");
154
155 ret = dm_gpio_request(&btiva1, "boot-tiva1");
156 if (ret)
157 printf("Cannot request GPIO0_25\n");
158
159 dm_gpio_set_dir_flags(&btiva0, GPIOD_IS_IN);
160 dm_gpio_set_dir_flags(&btiva1, GPIOD_IS_IN);
161
162 udelay(1000);
163
164 boot_tiva0 = dm_gpio_get_value(&btiva0);
165 boot_tiva1 = dm_gpio_get_value(&btiva1);
166}
167
Anatolij Gustschin6322fc12024-01-15 14:51:30 +0100168int spl_mmc_emmc_boot_partition(struct mmc *mmc)
169{
170 int i, src_idx = -1, ret;
171
172 ret = spi_load_boot_info();
173 if (ret) {
174 printf("%s: Cannot read XEA boot info! [%d]\n", __func__, ret);
175 /* To avoid bricking board - by default boot from boot0 eMMC */
176 return 1;
177 }
178
179 for (i = 0; i < 2; i++) {
180 if (img_src[i].magic == 'B' &&
181 img_src[i].crc8 == crc8(0, &img_src[i].magic, 2)) {
182 src_idx = i;
183 break;
184 }
185 }
186
187 debug("%s: src idx: %d\n", __func__, src_idx);
188
189 if (src_idx < 0)
190 /*
191 * Always use eMMC (mmcblkX) boot0 if no
192 * valid image source description found
193 */
194 return 1;
195
196 if (img_src[src_idx].flags & BOOT_SRC_PART1)
197 return 2;
198
199 return 1;
200}
201
Lukasz Majewskif3adb662019-12-08 22:06:56 +0100202void board_boot_order(u32 *spl_boot_list)
203{
204 spl_boot_list[0] = BOOT_DEVICE_MMC1;
205 spl_boot_list[1] = BOOT_DEVICE_SPI;
Lukasz Majewski27458d22020-07-10 09:49:32 +0200206 spl_boot_list[2] = BOOT_DEVICE_UART;
Lukasz Majewskif3adb662019-12-08 22:06:56 +0100207}
208
209int spl_start_uboot(void)
210{
211 /* break into full u-boot on 'c' */
212 if (serial_tstc() && serial_getc() == 'c')
213 return 1;
214
215 debug("%s: btiva0: %d btiva1: %d\n", __func__, boot_tiva0, boot_tiva1);
216 return !boot_tiva0 || !boot_tiva1;
217}
218#else
Lukasz Majewski80361a12024-03-29 12:18:08 +0100219/*
220 * Reading the HW ID number for XEA SoM module
221 *
222 * GPIOs from Port 1 (GPIO1_15, GPIO1_16, GPIO1_17 and GPIO1_18)
223 * are used to store HW revision information.
224 * Reading of GPIOs values is performed before the Device Model is
225 * bring up as the proper DTB needs to be chosen first.
226 *
227 * Moreover, this approach is required as "single binary" configuration
228 * of U-Boot (imx28_xea_sb_defconfig) is NOT using SPL framework, so
229 * only minimal subset of functionality is provided when ID is read.
230 *
231 * Hence, the direct registers' access.
232 */
233#define XEA_SOM_HW_ID_GPIO_PORT (MXS_PINCTRL_BASE + (0x0900 + ((1) * 0x10)))
234#define XEA_SOM_REV_MASK GENMASK(18, 15)
235#define XEA_SOM_REV_SHIFT 15
236
237static u8 get_som_rev(void)
238{
239 struct mxs_register_32 *reg =
240 (struct mxs_register_32 *)XEA_SOM_HW_ID_GPIO_PORT;
241
242 u32 tmp = ~readl(&reg->reg);
243 u8 id = (tmp & XEA_SOM_REV_MASK) >> XEA_SOM_REV_SHIFT;
244
245 return id;
246}
Lukasz Majewskif3adb662019-12-08 22:06:56 +0100247
248int board_early_init_f(void)
249{
250 init_clocks();
251
252 return 0;
253}
254
255int board_init(void)
256{
257 struct gpio_desc phy_rst;
258 int ret;
259
260 /* Address of boot parameters */
261 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
262
263 cpu_eth_init(NULL);
264
265 /* PHY INT#/PWDN# */
266 ret = dm_gpio_lookup_name("GPIO4_13", &phy_rst);
267 if (ret) {
268 printf("Cannot get GPIO4_13\n");
269 return ret;
270 }
271
272 ret = dm_gpio_request(&phy_rst, "phy-rst");
273 if (ret) {
274 printf("Cannot request GPIO4_13\n");
275 return ret;
276 }
277
278 dm_gpio_set_dir_flags(&phy_rst, GPIOD_IS_IN);
279 udelay(1000);
280
281 return 0;
282}
Lukasz Majewski80361a12024-03-29 12:18:08 +0100283
284#if defined(CONFIG_BOARD_LATE_INIT)
285int board_late_init(void)
286{
287 int ret = env_set_ulong("board_som_rev", get_som_rev());
288
289 if (ret)
290 printf("Cannot set XEA's SoM revision env variable!\n");
291
292 return 0;
293}
294#endif
295
296#if defined(CONFIG_DISPLAY_BOARDINFO)
297int checkboard(void)
298{
299 printf("Board: LWE XEA SoM HW rev %d\n", get_som_rev());
300
301 return 0;
302}
303#endif
Lukasz Majewskif3adb662019-12-08 22:06:56 +0100304
305int dram_init(void)
306{
307 return mxs_dram_init();
308}
309
Lukasz Majewski363cd972020-01-25 09:01:37 +0100310#ifdef CONFIG_OF_BOARD_SETUP
311static int fdt_fixup_l2switch(void *blob)
312{
313 u8 ethaddr[6];
314 int ret;
315
316 if (eth_env_get_enetaddr("ethaddr", ethaddr)) {
317 ret = fdt_find_and_setprop(blob,
318 "/ahb@80080000/switch@800f0000",
319 "local-mac-address", ethaddr, 6, 1);
320 if (ret < 0)
321 printf("%s: can't find usbether@1 node: %d\n",
322 __func__, ret);
323 }
324
325 return 0;
326}
327
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900328int ft_board_setup(void *blob, struct bd_info *bd)
Lukasz Majewski363cd972020-01-25 09:01:37 +0100329{
330 /*
331 * i.MX28 L2 switch needs manual update (fixup) of eth MAC address
332 * (in 'local-mac-address' property) as it uses "switch@800f0000"
333 * node, not set by default FIT image handling code in
334 * "ethernet@800f0000"
335 */
336 fdt_fixup_l2switch(blob);
337
338 return 0;
339}
340#endif
Lukasz Majewskid70cd282023-05-19 12:43:46 +0200341/*
342 * NOTE:
343 *
344 * IMX28 clock "stub" DM driver!
345 *
346 * Only used for SPL stage, which is NOT using DM; serial and
347 * eMMC configuration.
348 */
349static const struct udevice_id imx28_clk_ids[] = {
350 { .compatible = "fsl,imx28-clkctrl", },
351 { }
352};
Lukasz Majewski363cd972020-01-25 09:01:37 +0100353
Lukasz Majewskid70cd282023-05-19 12:43:46 +0200354U_BOOT_DRIVER(fsl_imx28_clkctrl) = {
355 .name = "fsl_imx28_clkctrl",
356 .id = UCLASS_CLK,
357 .of_match = imx28_clk_ids,
358};
Lukasz Majewskif3adb662019-12-08 22:06:56 +0100359#endif /* CONFIG_SPL_BUILD */