blob: 30665ea992425db46a2e0a483e56da27083c265c [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>
Lukasz Majewski010e58d2019-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>
27#include <linux/mii.h>
28#include <miiphy.h>
29#include <netdev.h>
30#include <errno.h>
31#include <usb.h>
32#include <serial.h>
33
34#ifdef CONFIG_SPL_BUILD
35#include <spl.h>
36#endif
37
38DECLARE_GLOBAL_DATA_PTR;
39
40/*
41 * Functions
42 */
43
44static void init_clocks(void)
45{
46 /* IO0 clock at 480MHz */
47 mxs_set_ioclk(MXC_IOCLK0, 480000);
48 /* IO1 clock at 480MHz */
49 mxs_set_ioclk(MXC_IOCLK1, 480000);
50
51 /* SSP0 clock at 96MHz */
52 mxs_set_sspclk(MXC_SSPCLK0, 96000, 0);
53 /* SSP2 clock at 160MHz */
54 mxs_set_sspclk(MXC_SSPCLK2, 160000, 0);
55 /* SSP3 clock at 96MHz */
56 mxs_set_sspclk(MXC_SSPCLK3, 96000, 0);
57}
58
59#ifdef CONFIG_SPL_BUILD
60void board_init_f(ulong arg)
61{
62 init_clocks();
63 preloader_console_init();
64}
65
66static int boot_tiva0, boot_tiva1;
67
68/* Check if TIVAs request booting via U-Boot proper */
69void spl_board_init(void)
70{
Lukasz Majewskieceb4e02020-01-25 09:01:39 +010071 struct gpio_desc btiva0, btiva1, en_3_3v;
Lukasz Majewski010e58d2019-12-08 22:06:56 +010072 int ret;
73
Lukasz Majewskieceb4e02020-01-25 09:01:39 +010074 /*
75 * Setup GPIO0_0 (TIVA power enable pin) to be output high
76 * to allow TIVA startup.
77 */
78 ret = dm_gpio_lookup_name("GPIO0_0", &en_3_3v);
79 if (ret)
80 printf("Cannot get GPIO0_0\n");
81
82 ret = dm_gpio_request(&en_3_3v, "pwr_3_3v");
83 if (ret)
84 printf("Cannot request GPIO0_0\n");
85
86 /* Set GPIO0_0 to HIGH */
87 dm_gpio_set_dir_flags(&en_3_3v, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
88
Lukasz Majewski010e58d2019-12-08 22:06:56 +010089 ret = dm_gpio_lookup_name("GPIO0_23", &btiva0);
90 if (ret)
91 printf("Cannot get GPIO0_23\n");
92
93 ret = dm_gpio_lookup_name("GPIO0_25", &btiva1);
94 if (ret)
95 printf("Cannot get GPIO0_25\n");
96
97 ret = dm_gpio_request(&btiva0, "boot-tiva0");
98 if (ret)
99 printf("Cannot request GPIO0_23\n");
100
101 ret = dm_gpio_request(&btiva1, "boot-tiva1");
102 if (ret)
103 printf("Cannot request GPIO0_25\n");
104
105 dm_gpio_set_dir_flags(&btiva0, GPIOD_IS_IN);
106 dm_gpio_set_dir_flags(&btiva1, GPIOD_IS_IN);
107
108 udelay(1000);
109
110 boot_tiva0 = dm_gpio_get_value(&btiva0);
111 boot_tiva1 = dm_gpio_get_value(&btiva1);
112}
113
114void board_boot_order(u32 *spl_boot_list)
115{
116 spl_boot_list[0] = BOOT_DEVICE_MMC1;
117 spl_boot_list[1] = BOOT_DEVICE_SPI;
118}
119
120int spl_start_uboot(void)
121{
122 /* break into full u-boot on 'c' */
123 if (serial_tstc() && serial_getc() == 'c')
124 return 1;
125
126 debug("%s: btiva0: %d btiva1: %d\n", __func__, boot_tiva0, boot_tiva1);
127 return !boot_tiva0 || !boot_tiva1;
128}
129#else
130
131int board_early_init_f(void)
132{
133 init_clocks();
134
135 return 0;
136}
137
138int board_init(void)
139{
140 struct gpio_desc phy_rst;
141 int ret;
142
143 /* Address of boot parameters */
144 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
145
146 cpu_eth_init(NULL);
147
148 /* PHY INT#/PWDN# */
149 ret = dm_gpio_lookup_name("GPIO4_13", &phy_rst);
150 if (ret) {
151 printf("Cannot get GPIO4_13\n");
152 return ret;
153 }
154
155 ret = dm_gpio_request(&phy_rst, "phy-rst");
156 if (ret) {
157 printf("Cannot request GPIO4_13\n");
158 return ret;
159 }
160
161 dm_gpio_set_dir_flags(&phy_rst, GPIOD_IS_IN);
162 udelay(1000);
163
164 return 0;
165}
166
167int dram_init(void)
168{
169 return mxs_dram_init();
170}
171
Lukasz Majewskibcd7f892020-01-25 09:01:37 +0100172#ifdef CONFIG_OF_BOARD_SETUP
173static int fdt_fixup_l2switch(void *blob)
174{
175 u8 ethaddr[6];
176 int ret;
177
178 if (eth_env_get_enetaddr("ethaddr", ethaddr)) {
179 ret = fdt_find_and_setprop(blob,
180 "/ahb@80080000/switch@800f0000",
181 "local-mac-address", ethaddr, 6, 1);
182 if (ret < 0)
183 printf("%s: can't find usbether@1 node: %d\n",
184 __func__, ret);
185 }
186
187 return 0;
188}
189
190int ft_board_setup(void *blob, bd_t *bd)
191{
192 /*
193 * i.MX28 L2 switch needs manual update (fixup) of eth MAC address
194 * (in 'local-mac-address' property) as it uses "switch@800f0000"
195 * node, not set by default FIT image handling code in
196 * "ethernet@800f0000"
197 */
198 fdt_fixup_l2switch(blob);
199
200 return 0;
201}
202#endif
203
Lukasz Majewski010e58d2019-12-08 22:06:56 +0100204#endif /* CONFIG_SPL_BUILD */