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