Merge tag 'u-boot-imx-20200210' of https://gitlab.denx.de/u-boot/custodians/u-boot-imx
[platform/kernel/u-boot.git] / board / liebherr / xea / xea.c
1 // 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
34 DECLARE_GLOBAL_DATA_PTR;
35
36 /*
37  * Functions
38  */
39
40 static 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
56 void board_init_f(ulong arg)
57 {
58         init_clocks();
59         preloader_console_init();
60 }
61
62 static int boot_tiva0, boot_tiva1;
63
64 /* Check if TIVAs request booting via U-Boot proper */
65 void spl_board_init(void)
66 {
67         struct gpio_desc btiva0, btiva1, en_3_3v;
68         int ret;
69
70         /*
71          * Setup GPIO0_0 (TIVA power enable pin) to be output high
72          * to allow TIVA startup.
73          */
74         ret = dm_gpio_lookup_name("GPIO0_0", &en_3_3v);
75         if (ret)
76                 printf("Cannot get GPIO0_0\n");
77
78         ret = dm_gpio_request(&en_3_3v, "pwr_3_3v");
79         if (ret)
80                 printf("Cannot request GPIO0_0\n");
81
82         /* Set GPIO0_0 to HIGH */
83         dm_gpio_set_dir_flags(&en_3_3v, GPIOD_IS_OUT | GPIOD_IS_OUT_ACTIVE);
84
85         ret = dm_gpio_lookup_name("GPIO0_23", &btiva0);
86         if (ret)
87                 printf("Cannot get GPIO0_23\n");
88
89         ret = dm_gpio_lookup_name("GPIO0_25", &btiva1);
90         if (ret)
91                 printf("Cannot get GPIO0_25\n");
92
93         ret = dm_gpio_request(&btiva0, "boot-tiva0");
94         if (ret)
95                 printf("Cannot request GPIO0_23\n");
96
97         ret = dm_gpio_request(&btiva1, "boot-tiva1");
98         if (ret)
99                 printf("Cannot request GPIO0_25\n");
100
101         dm_gpio_set_dir_flags(&btiva0, GPIOD_IS_IN);
102         dm_gpio_set_dir_flags(&btiva1, GPIOD_IS_IN);
103
104         udelay(1000);
105
106         boot_tiva0 = dm_gpio_get_value(&btiva0);
107         boot_tiva1 = dm_gpio_get_value(&btiva1);
108 }
109
110 void board_boot_order(u32 *spl_boot_list)
111 {
112         spl_boot_list[0] = BOOT_DEVICE_MMC1;
113         spl_boot_list[1] = BOOT_DEVICE_SPI;
114 }
115
116 int spl_start_uboot(void)
117 {
118         /* break into full u-boot on 'c' */
119         if (serial_tstc() && serial_getc() == 'c')
120                 return 1;
121
122         debug("%s: btiva0: %d btiva1: %d\n", __func__, boot_tiva0, boot_tiva1);
123         return !boot_tiva0 || !boot_tiva1;
124 }
125 #else
126
127 int board_early_init_f(void)
128 {
129         init_clocks();
130
131         return 0;
132 }
133
134 int board_init(void)
135 {
136         struct gpio_desc phy_rst;
137         int ret;
138
139         /* Address of boot parameters */
140         gd->bd->bi_boot_params = PHYS_SDRAM_1 + 0x100;
141
142         cpu_eth_init(NULL);
143
144         /* PHY INT#/PWDN# */
145         ret = dm_gpio_lookup_name("GPIO4_13", &phy_rst);
146         if (ret) {
147                 printf("Cannot get GPIO4_13\n");
148                 return ret;
149         }
150
151         ret = dm_gpio_request(&phy_rst, "phy-rst");
152         if (ret) {
153                 printf("Cannot request GPIO4_13\n");
154                 return ret;
155         }
156
157         dm_gpio_set_dir_flags(&phy_rst, GPIOD_IS_IN);
158         udelay(1000);
159
160         return 0;
161 }
162
163 int dram_init(void)
164 {
165         return mxs_dram_init();
166 }
167
168 #ifdef CONFIG_OF_BOARD_SETUP
169 static int fdt_fixup_l2switch(void *blob)
170 {
171         u8 ethaddr[6];
172         int ret;
173
174         if (eth_env_get_enetaddr("ethaddr", ethaddr)) {
175                 ret = fdt_find_and_setprop(blob,
176                                            "/ahb@80080000/switch@800f0000",
177                                            "local-mac-address", ethaddr, 6, 1);
178                 if (ret < 0)
179                         printf("%s: can't find usbether@1 node: %d\n",
180                                __func__, ret);
181         }
182
183         return 0;
184 }
185
186 int ft_board_setup(void *blob, bd_t *bd)
187 {
188         /*
189          * i.MX28 L2 switch needs manual update (fixup) of eth MAC address
190          * (in 'local-mac-address' property) as it uses "switch@800f0000"
191          * node, not set by default FIT image handling code in
192          * "ethernet@800f0000"
193          */
194         fdt_fixup_l2switch(blob);
195
196         return 0;
197 }
198 #endif
199
200 #endif  /* CONFIG_SPL_BUILD */