blob: e4d2eb65cc4251c5da049f62425176483a7dd1bb [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>
35
36#ifdef CONFIG_SPL_BUILD
37#include <spl.h>
38#endif
39
40DECLARE_GLOBAL_DATA_PTR;
41
42/*
43 * Functions
44 */
45
46static void init_clocks(void)
47{
48 /* IO0 clock at 480MHz */
49 mxs_set_ioclk(MXC_IOCLK0, 480000);
50 /* IO1 clock at 480MHz */
51 mxs_set_ioclk(MXC_IOCLK1, 480000);
52
53 /* SSP0 clock at 96MHz */
54 mxs_set_sspclk(MXC_SSPCLK0, 96000, 0);
55 /* SSP2 clock at 160MHz */
56 mxs_set_sspclk(MXC_SSPCLK2, 160000, 0);
57 /* SSP3 clock at 96MHz */
58 mxs_set_sspclk(MXC_SSPCLK3, 96000, 0);
59}
60
Lukasz Majewski09207162021-12-27 11:38:21 +010061#if defined(CONFIG_SPL_BUILD) && defined(CONFIG_SPL_FRAMEWORK)
Lukasz Majewskif3adb662019-12-08 22:06:56 +010062void board_init_f(ulong arg)
63{
64 init_clocks();
Lukasz Majewskibc6026d2023-05-19 12:43:55 +020065 spl_early_init();
Lukasz Majewskif3adb662019-12-08 22:06:56 +010066 preloader_console_init();
67}
68
69static int boot_tiva0, boot_tiva1;
70
71/* Check if TIVAs request booting via U-Boot proper */
72void spl_board_init(void)
73{
Lukasz Majewski07adfb12020-01-25 09:01:39 +010074 struct gpio_desc btiva0, btiva1, en_3_3v;
Lukasz Majewskif3adb662019-12-08 22:06:56 +010075 int ret;
76
Lukasz Majewski07adfb12020-01-25 09:01:39 +010077 /*
78 * Setup GPIO0_0 (TIVA power enable pin) to be output high
79 * to allow TIVA startup.
80 */
81 ret = dm_gpio_lookup_name("GPIO0_0", &en_3_3v);
82 if (ret)
83 printf("Cannot get GPIO0_0\n");
84
85 ret = dm_gpio_request(&en_3_3v, "pwr_3_3v");
86 if (ret)
87 printf("Cannot request GPIO0_0\n");
88
89 /* Set GPIO0_0 to HIGH */
90 dm_gpio_set_dir_flags(&en_3_3v, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
91
Lukasz Majewskif3adb662019-12-08 22:06:56 +010092 ret = dm_gpio_lookup_name("GPIO0_23", &btiva0);
93 if (ret)
94 printf("Cannot get GPIO0_23\n");
95
96 ret = dm_gpio_lookup_name("GPIO0_25", &btiva1);
97 if (ret)
98 printf("Cannot get GPIO0_25\n");
99
100 ret = dm_gpio_request(&btiva0, "boot-tiva0");
101 if (ret)
102 printf("Cannot request GPIO0_23\n");
103
104 ret = dm_gpio_request(&btiva1, "boot-tiva1");
105 if (ret)
106 printf("Cannot request GPIO0_25\n");
107
108 dm_gpio_set_dir_flags(&btiva0, GPIOD_IS_IN);
109 dm_gpio_set_dir_flags(&btiva1, GPIOD_IS_IN);
110
111 udelay(1000);
112
113 boot_tiva0 = dm_gpio_get_value(&btiva0);
114 boot_tiva1 = dm_gpio_get_value(&btiva1);
115}
116
117void board_boot_order(u32 *spl_boot_list)
118{
119 spl_boot_list[0] = BOOT_DEVICE_MMC1;
120 spl_boot_list[1] = BOOT_DEVICE_SPI;
Lukasz Majewski27458d22020-07-10 09:49:32 +0200121 spl_boot_list[2] = BOOT_DEVICE_UART;
Lukasz Majewskif3adb662019-12-08 22:06:56 +0100122}
123
124int spl_start_uboot(void)
125{
126 /* break into full u-boot on 'c' */
127 if (serial_tstc() && serial_getc() == 'c')
128 return 1;
129
130 debug("%s: btiva0: %d btiva1: %d\n", __func__, boot_tiva0, boot_tiva1);
131 return !boot_tiva0 || !boot_tiva1;
132}
133#else
134
135int board_early_init_f(void)
136{
137 init_clocks();
138
139 return 0;
140}
141
142int board_init(void)
143{
144 struct gpio_desc phy_rst;
145 int ret;
146
147 /* Address of boot parameters */
148 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
149
150 cpu_eth_init(NULL);
151
152 /* PHY INT#/PWDN# */
153 ret = dm_gpio_lookup_name("GPIO4_13", &phy_rst);
154 if (ret) {
155 printf("Cannot get GPIO4_13\n");
156 return ret;
157 }
158
159 ret = dm_gpio_request(&phy_rst, "phy-rst");
160 if (ret) {
161 printf("Cannot request GPIO4_13\n");
162 return ret;
163 }
164
165 dm_gpio_set_dir_flags(&phy_rst, GPIOD_IS_IN);
166 udelay(1000);
167
168 return 0;
169}
170
171int dram_init(void)
172{
173 return mxs_dram_init();
174}
175
Lukasz Majewski363cd972020-01-25 09:01:37 +0100176#ifdef CONFIG_OF_BOARD_SETUP
177static int fdt_fixup_l2switch(void *blob)
178{
179 u8 ethaddr[6];
180 int ret;
181
182 if (eth_env_get_enetaddr("ethaddr", ethaddr)) {
183 ret = fdt_find_and_setprop(blob,
184 "/ahb@80080000/switch@800f0000",
185 "local-mac-address", ethaddr, 6, 1);
186 if (ret < 0)
187 printf("%s: can't find usbether@1 node: %d\n",
188 __func__, ret);
189 }
190
191 return 0;
192}
193
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900194int ft_board_setup(void *blob, struct bd_info *bd)
Lukasz Majewski363cd972020-01-25 09:01:37 +0100195{
196 /*
197 * i.MX28 L2 switch needs manual update (fixup) of eth MAC address
198 * (in 'local-mac-address' property) as it uses "switch@800f0000"
199 * node, not set by default FIT image handling code in
200 * "ethernet@800f0000"
201 */
202 fdt_fixup_l2switch(blob);
203
204 return 0;
205}
206#endif
Lukasz Majewskid70cd282023-05-19 12:43:46 +0200207/*
208 * NOTE:
209 *
210 * IMX28 clock "stub" DM driver!
211 *
212 * Only used for SPL stage, which is NOT using DM; serial and
213 * eMMC configuration.
214 */
215static const struct udevice_id imx28_clk_ids[] = {
216 { .compatible = "fsl,imx28-clkctrl", },
217 { }
218};
Lukasz Majewski363cd972020-01-25 09:01:37 +0100219
Lukasz Majewskid70cd282023-05-19 12:43:46 +0200220U_BOOT_DRIVER(fsl_imx28_clkctrl) = {
221 .name = "fsl_imx28_clkctrl",
222 .id = UCLASS_CLK,
223 .of_match = imx28_clk_ids,
224};
Lukasz Majewskif3adb662019-12-08 22:06:56 +0100225#endif /* CONFIG_SPL_BUILD */