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