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