blob: c8ac526cb47f0af992567b644bab68e45333f733 [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
219
220int board_early_init_f(void)
221{
222 init_clocks();
223
224 return 0;
225}
226
227int board_init(void)
228{
229 struct gpio_desc phy_rst;
230 int ret;
231
232 /* Address of boot parameters */
233 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
234
235 cpu_eth_init(NULL);
236
237 /* PHY INT#/PWDN# */
238 ret = dm_gpio_lookup_name("GPIO4_13", &phy_rst);
239 if (ret) {
240 printf("Cannot get GPIO4_13\n");
241 return ret;
242 }
243
244 ret = dm_gpio_request(&phy_rst, "phy-rst");
245 if (ret) {
246 printf("Cannot request GPIO4_13\n");
247 return ret;
248 }
249
250 dm_gpio_set_dir_flags(&phy_rst, GPIOD_IS_IN);
251 udelay(1000);
252
253 return 0;
254}
255
256int dram_init(void)
257{
258 return mxs_dram_init();
259}
260
Lukasz Majewski363cd972020-01-25 09:01:37 +0100261#ifdef CONFIG_OF_BOARD_SETUP
262static int fdt_fixup_l2switch(void *blob)
263{
264 u8 ethaddr[6];
265 int ret;
266
267 if (eth_env_get_enetaddr("ethaddr", ethaddr)) {
268 ret = fdt_find_and_setprop(blob,
269 "/ahb@80080000/switch@800f0000",
270 "local-mac-address", ethaddr, 6, 1);
271 if (ret < 0)
272 printf("%s: can't find usbether@1 node: %d\n",
273 __func__, ret);
274 }
275
276 return 0;
277}
278
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900279int ft_board_setup(void *blob, struct bd_info *bd)
Lukasz Majewski363cd972020-01-25 09:01:37 +0100280{
281 /*
282 * i.MX28 L2 switch needs manual update (fixup) of eth MAC address
283 * (in 'local-mac-address' property) as it uses "switch@800f0000"
284 * node, not set by default FIT image handling code in
285 * "ethernet@800f0000"
286 */
287 fdt_fixup_l2switch(blob);
288
289 return 0;
290}
291#endif
Lukasz Majewskid70cd282023-05-19 12:43:46 +0200292/*
293 * NOTE:
294 *
295 * IMX28 clock "stub" DM driver!
296 *
297 * Only used for SPL stage, which is NOT using DM; serial and
298 * eMMC configuration.
299 */
300static const struct udevice_id imx28_clk_ids[] = {
301 { .compatible = "fsl,imx28-clkctrl", },
302 { }
303};
Lukasz Majewski363cd972020-01-25 09:01:37 +0100304
Lukasz Majewskid70cd282023-05-19 12:43:46 +0200305U_BOOT_DRIVER(fsl_imx28_clkctrl) = {
306 .name = "fsl_imx28_clkctrl",
307 .id = UCLASS_CLK,
308 .of_match = imx28_clk_ids,
309};
Lukasz Majewskif3adb662019-12-08 22:06:56 +0100310#endif /* CONFIG_SPL_BUILD */