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