1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#include <common.h>
17#include <fdt_support.h>
18#include <init.h>
19#include <log.h>
20#include <net.h>
21#include <asm/global_data.h>
22#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>
28#include <linux/delay.h>
29#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
44
45
46static void init_clocks(void)
47{
48
49 mxs_set_ioclk(MXC_IOCLK0, 480000);
50
51 mxs_set_ioclk(MXC_IOCLK1, 480000);
52
53
54 mxs_set_sspclk(MXC_SSPCLK0, 96000, 0);
55
56 mxs_set_sspclk(MXC_SSPCLK2, 160000, 0);
57
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
71void spl_board_init(void)
72{
73 struct gpio_desc btiva0, btiva1, en_3_3v;
74 int ret;
75
76
77
78
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
89 dm_gpio_set_dir_flags(&en_3_3v, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
90
91 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;
120 spl_boot_list[2] = BOOT_DEVICE_UART;
121}
122
123int spl_start_uboot(void)
124{
125
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
147 gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
148
149 cpu_eth_init(NULL);
150
151
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
175#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
193int ft_board_setup(void *blob, struct bd_info *bd)
194{
195
196
197
198
199
200
201 fdt_fixup_l2switch(blob);
202
203 return 0;
204}
205#endif
206
207#endif
208