blob: cd11b0ada77c2417c7b3c2ab567fb691347aae0d [file] [log] [blame]
Lukasz Majewski010e58d2019-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 Glass4d72caa2020-05-10 11:40:01 -060017#include <fdt_support.h>
Simon Glass691d7192020-05-10 11:40:02 -060018#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060019#include <log.h>
Simon Glass90526e92020-05-10 11:39:56 -060020#include <net.h>
Simon Glass401d1c42020-10-30 21:38:53 -060021#include <asm/global_data.h>
Lukasz Majewski010e58d2019-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 Glassc05ed002020-05-10 11:40:11 -060028#include <linux/delay.h>
Lukasz Majewski010e58d2019-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
61#ifdef CONFIG_SPL_BUILD
62void board_init_f(ulong arg)
63{
64 init_clocks();
65 preloader_console_init();
66}
67
68static int boot_tiva0, boot_tiva1;
69
70/* Check if TIVAs request booting via U-Boot proper */
71void spl_board_init(void)
72{
Lukasz Majewskieceb4e02020-01-25 09:01:39 +010073 struct gpio_desc btiva0, btiva1, en_3_3v;
Lukasz Majewski010e58d2019-12-08 22:06:56 +010074 int ret;
75
Lukasz Majewskieceb4e02020-01-25 09:01:39 +010076 /*
77 * Setup GPIO0_0 (TIVA power enable pin) to be output high
78 * to allow TIVA startup.
79 */
80 ret = dm_gpio_lookup_name("GPIO0_0", &en_3_3v);
81 if (ret)
82 printf("Cannot get GPIO0_0\n");
83
84 ret = dm_gpio_request(&en_3_3v, "pwr_3_3v");
85 if (ret)
86 printf("Cannot request GPIO0_0\n");
87
88 /* Set GPIO0_0 to HIGH */
89 dm_gpio_set_dir_flags(&en_3_3v, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
90
Lukasz Majewski010e58d2019-12-08 22:06:56 +010091 ret = dm_gpio_lookup_name("GPIO0_23", &btiva0);
92 if (ret)
93 printf("Cannot get GPIO0_23\n");
94
95 ret = dm_gpio_lookup_name("GPIO0_25", &btiva1);
96 if (ret)
97 printf("Cannot get GPIO0_25\n");
98
99 ret = dm_gpio_request(&btiva0, "boot-tiva0");
100 if (ret)
101 printf("Cannot request GPIO0_23\n");
102
103 ret = dm_gpio_request(&btiva1, "boot-tiva1");
104 if (ret)
105 printf("Cannot request GPIO0_25\n");
106
107 dm_gpio_set_dir_flags(&btiva0, GPIOD_IS_IN);
108 dm_gpio_set_dir_flags(&btiva1, GPIOD_IS_IN);
109
110 udelay(1000);
111
112 boot_tiva0 = dm_gpio_get_value(&btiva0);
113 boot_tiva1 = dm_gpio_get_value(&btiva1);
114}
115
116void board_boot_order(u32 *spl_boot_list)
117{
118 spl_boot_list[0] = BOOT_DEVICE_MMC1;
119 spl_boot_list[1] = BOOT_DEVICE_SPI;
Lukasz Majewski949feef2020-07-10 09:49:32 +0200120 spl_boot_list[2] = BOOT_DEVICE_UART;
Lukasz Majewski010e58d2019-12-08 22:06:56 +0100121}
122
123int spl_start_uboot(void)
124{
125 /* break into full u-boot on 'c' */
126 if (serial_tstc() && serial_getc() == 'c')
127 return 1;
128
129 debug("%s: btiva0: %d btiva1: %d\n", __func__, boot_tiva0, boot_tiva1);
130 return !boot_tiva0 || !boot_tiva1;
131}
132#else
133
134int board_early_init_f(void)
135{
136 init_clocks();
137
138 return 0;
139}
140
141int board_init(void)
142{
143 struct gpio_desc phy_rst;
144 int ret;
145
146 /* Address of boot parameters */
147 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
148
149 cpu_eth_init(NULL);
150
151 /* PHY INT#/PWDN# */
152 ret = dm_gpio_lookup_name("GPIO4_13", &phy_rst);
153 if (ret) {
154 printf("Cannot get GPIO4_13\n");
155 return ret;
156 }
157
158 ret = dm_gpio_request(&phy_rst, "phy-rst");
159 if (ret) {
160 printf("Cannot request GPIO4_13\n");
161 return ret;
162 }
163
164 dm_gpio_set_dir_flags(&phy_rst, GPIOD_IS_IN);
165 udelay(1000);
166
167 return 0;
168}
169
170int dram_init(void)
171{
172 return mxs_dram_init();
173}
174
Lukasz Majewskibcd7f892020-01-25 09:01:37 +0100175#ifdef CONFIG_OF_BOARD_SETUP
176static int fdt_fixup_l2switch(void *blob)
177{
178 u8 ethaddr[6];
179 int ret;
180
181 if (eth_env_get_enetaddr("ethaddr", ethaddr)) {
182 ret = fdt_find_and_setprop(blob,
183 "/ahb@80080000/switch@800f0000",
184 "local-mac-address", ethaddr, 6, 1);
185 if (ret < 0)
186 printf("%s: can't find usbether@1 node: %d\n",
187 __func__, ret);
188 }
189
190 return 0;
191}
192
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900193int ft_board_setup(void *blob, struct bd_info *bd)
Lukasz Majewskibcd7f892020-01-25 09:01:37 +0100194{
195 /*
196 * i.MX28 L2 switch needs manual update (fixup) of eth MAC address
197 * (in 'local-mac-address' property) as it uses "switch@800f0000"
198 * node, not set by default FIT image handling code in
199 * "ethernet@800f0000"
200 */
201 fdt_fixup_l2switch(blob);
202
203 return 0;
204}
205#endif
206
Lukasz Majewski010e58d2019-12-08 22:06:56 +0100207#endif /* CONFIG_SPL_BUILD */