blob: 42aa5cb63ca3f733e9b99139bfdce1e19c522b6b [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -03002/*
Josua Mayer741ce302022-05-19 12:31:59 +03003 * Copyright (C) 2022 Josua Mayer <josua@solid-run.com>
4 *
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -03005 * Copyright (C) 2015 Freescale Semiconductor, Inc.
6 *
7 * Author: Fabio Estevam <fabio.estevam@freescale.com>
8 *
9 * Copyright (C) 2013 Jon Nettleton <jon.nettleton@gmail.com>
10 *
11 * Based on SPL code from Solidrun tree, which is:
12 * Author: Tungyi Lin <tungyilin1127@gmail.com>
13 *
14 * Derived from EDM_CF_IMX6 code by TechNexion,Inc
15 * Ported to SolidRun microSOM by Rabeeh Khoury <rabeeh@solid-run.com>
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -030016 */
17
Simon Glassc3dc39a2020-05-10 11:39:55 -060018#include <common.h>
Simon Glass4d72caa2020-05-10 11:40:01 -060019#include <image.h>
Simon Glass52559322019-11-14 12:57:46 -070020#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060021#include <log.h>
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -030022#include <asm/arch/clock.h>
23#include <asm/arch/imx-regs.h>
24#include <asm/arch/iomux.h>
25#include <asm/arch/mx6-pins.h>
Fabio Estevamf68a9c62015-04-29 22:28:09 -030026#include <asm/arch/mxc_hdmi.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060027#include <env.h>
Simon Glass401d1c42020-10-30 21:38:53 -060028#include <asm/global_data.h>
Simon Glassc05ed002020-05-10 11:40:11 -060029#include <linux/delay.h>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090030#include <linux/errno.h>
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -030031#include <asm/gpio.h>
Stefano Babic552a8482017-06-29 10:16:06 +020032#include <asm/mach-imx/iomux-v3.h>
33#include <asm/mach-imx/sata.h>
34#include <asm/mach-imx/video.h>
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -030035#include <mmc.h>
Yangbo Lue37ac712019-06-21 11:42:28 +080036#include <fsl_esdhc_imx.h>
Fabio Estevam712be3e2015-05-04 11:22:55 -030037#include <malloc.h>
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -030038#include <asm/arch/crm_regs.h>
39#include <asm/io.h>
40#include <asm/arch/sys_proto.h>
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -030041#include <spl.h>
Fabio Estevame1d74372015-04-29 22:28:10 -030042#include <usb.h>
Mateusz Kulikowskie162c6b2016-03-31 23:12:23 +020043#include <usb/ehci-ci.h>
Josua Mayer741ce302022-05-19 12:31:59 +030044#include <netdev.h>
45#include <phy.h>
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -030046
47DECLARE_GLOBAL_DATA_PTR;
48
49#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
50 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
51 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
52
53#define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \
54 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
55 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
56
Fabio Estevame1d74372015-04-29 22:28:10 -030057#define USB_H1_VBUS IMX_GPIO_NR(1, 0)
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -030058
Jon Nettleton73708202018-06-07 16:17:36 +030059enum board_type {
60 CUBOXI = 0x00,
61 HUMMINGBOARD = 0x01,
62 HUMMINGBOARD2 = 0x02,
63 UNKNOWN = 0x03,
64};
65
Baruch Siacheb9124f2019-11-10 14:38:07 +020066static struct gpio_desc board_detect_desc[5];
67
Jon Nettleton51f957a2018-06-07 16:17:37 +030068#define MEM_STRIDE 0x4000000
69static u32 get_ram_size_stride_test(u32 *base, u32 maxsize)
70{
71 volatile u32 *addr;
72 u32 save[64];
73 u32 cnt;
74 u32 size;
75 int i = 0;
76
77 /* First save the data */
78 for (cnt = 0; cnt < maxsize; cnt += MEM_STRIDE) {
79 addr = (volatile u32 *)((u32)base + cnt); /* pointer arith! */
80 sync ();
81 save[i++] = *addr;
82 sync ();
83 }
84
85 /* First write a signature */
86 * (volatile u32 *)base = 0x12345678;
87 for (size = MEM_STRIDE; size < maxsize; size += MEM_STRIDE) {
88 * (volatile u32 *)((u32)base + size) = size;
89 sync ();
90 if (* (volatile u32 *)((u32)base) == size) { /* We reached the overlapping address */
91 break;
92 }
93 }
94
95 /* Restore the data */
96 for (cnt = (maxsize - MEM_STRIDE); i > 0; cnt -= MEM_STRIDE) {
97 addr = (volatile u32 *)((u32)base + cnt); /* pointer arith! */
98 sync ();
99 *addr = save[i--];
100 sync ();
101 }
102
103 return (size);
104}
105
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300106int dram_init(void)
107{
Jon Nettleton51f957a2018-06-07 16:17:37 +0300108 u32 max_size = imx_ddr_size();
109
110 gd->ram_size = get_ram_size_stride_test((u32 *) CONFIG_SYS_SDRAM_BASE,
111 (u32)max_size);
112
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300113 return 0;
114}
115
116static iomux_v3_cfg_t const uart1_pads[] = {
Fabio Estevamcfdcc5f2015-04-25 18:47:17 -0300117 IOMUX_PADS(PAD_CSI0_DAT10__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
118 IOMUX_PADS(PAD_CSI0_DAT11__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300119};
120
121static iomux_v3_cfg_t const usdhc2_pads[] = {
Fabio Estevamcfdcc5f2015-04-25 18:47:17 -0300122 IOMUX_PADS(PAD_SD2_CLK__SD2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
123 IOMUX_PADS(PAD_SD2_CMD__SD2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
124 IOMUX_PADS(PAD_SD2_DAT0__SD2_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
125 IOMUX_PADS(PAD_SD2_DAT1__SD2_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
126 IOMUX_PADS(PAD_SD2_DAT2__SD2_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
127 IOMUX_PADS(PAD_SD2_DAT3__SD2_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300128};
129
Jon Nettleton86e5a7f2018-06-11 15:26:20 +0300130static iomux_v3_cfg_t const usdhc3_pads[] = {
131 IOMUX_PADS(PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
132 IOMUX_PADS(PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
133 IOMUX_PADS(PAD_SD3_DAT0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
134 IOMUX_PADS(PAD_SD3_DAT1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
135 IOMUX_PADS(PAD_SD3_DAT2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
136 IOMUX_PADS(PAD_SD3_DAT3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
137 IOMUX_PADS(PAD_SD3_DAT4__SD3_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
138 IOMUX_PADS(PAD_SD3_DAT5__SD3_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
139 IOMUX_PADS(PAD_SD3_DAT6__SD3_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
140 IOMUX_PADS(PAD_SD3_DAT7__SD3_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
141 IOMUX_PADS(PAD_SD3_RST__SD3_RESET | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
142};
143
Jon Nettleton73708202018-06-07 16:17:36 +0300144static iomux_v3_cfg_t const board_detect[] = {
Fabio Estevamfeb6cc52015-04-25 18:47:19 -0300145 /* These pins are for sensing if it is a CuBox-i or a HummingBoard */
146 IOMUX_PADS(PAD_KEY_ROW1__GPIO4_IO09 | MUX_PAD_CTRL(UART_PAD_CTRL)),
147 IOMUX_PADS(PAD_EIM_DA4__GPIO3_IO04 | MUX_PAD_CTRL(UART_PAD_CTRL)),
Jon Nettleton73708202018-06-07 16:17:36 +0300148 IOMUX_PADS(PAD_SD4_DAT0__GPIO2_IO08 | MUX_PAD_CTRL(UART_PAD_CTRL)),
149};
150
151static iomux_v3_cfg_t const som_rev_detect[] = {
152 /* These pins are for sensing if it is a CuBox-i or a HummingBoard */
153 IOMUX_PADS(PAD_CSI0_DAT14__GPIO6_IO00 | MUX_PAD_CTRL(UART_PAD_CTRL)),
154 IOMUX_PADS(PAD_CSI0_DAT18__GPIO6_IO04 | MUX_PAD_CTRL(UART_PAD_CTRL)),
Fabio Estevamfeb6cc52015-04-25 18:47:19 -0300155};
156
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300157static void setup_iomux_uart(void)
158{
Fabio Estevamcfdcc5f2015-04-25 18:47:17 -0300159 SETUP_IOMUX_PADS(uart1_pads);
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300160}
161
Jon Nettleton86e5a7f2018-06-11 15:26:20 +0300162int board_mmc_get_env_dev(int devno)
163{
Baruch Siacheb9124f2019-11-10 14:38:07 +0200164 return devno;
Jon Nettleton86e5a7f2018-06-11 15:26:20 +0300165}
166
Fabio Estevamf68a9c62015-04-29 22:28:09 -0300167#ifdef CONFIG_VIDEO_IPUV3
168static void do_enable_hdmi(struct display_info_t const *dev)
169{
170 imx_enable_hdmi_phy();
171}
172
173struct display_info_t const displays[] = {
174 {
175 .bus = -1,
176 .addr = 0,
177 .pixfmt = IPU_PIX_FMT_RGB24,
178 .detect = detect_hdmi,
179 .enable = do_enable_hdmi,
180 .mode = {
181 .name = "HDMI",
182 /* 1024x768@60Hz (VESA)*/
183 .refresh = 60,
184 .xres = 1024,
185 .yres = 768,
186 .pixclock = 15384,
187 .left_margin = 160,
188 .right_margin = 24,
189 .upper_margin = 29,
190 .lower_margin = 3,
191 .hsync_len = 136,
192 .vsync_len = 6,
193 .sync = FB_SYNC_EXT,
194 .vmode = FB_VMODE_NONINTERLACED
195 }
196 }
197};
198
199size_t display_count = ARRAY_SIZE(displays);
200
201static int setup_display(void)
202{
203 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
204 int reg;
205 int timeout = 100000;
206
207 enable_ipu_clock();
208 imx_setup_hdmi();
209
210 /* set video pll to 455MHz (24MHz * (37+11/12) / 2) */
211 setbits_le32(&ccm->analog_pll_video, BM_ANADIG_PLL_VIDEO_POWERDOWN);
212
213 reg = readl(&ccm->analog_pll_video);
214 reg &= ~BM_ANADIG_PLL_VIDEO_DIV_SELECT;
215 reg |= BF_ANADIG_PLL_VIDEO_DIV_SELECT(37);
216 reg &= ~BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT;
217 reg |= BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(1);
218 writel(reg, &ccm->analog_pll_video);
219
220 writel(BF_ANADIG_PLL_VIDEO_NUM_A(11), &ccm->analog_pll_video_num);
221 writel(BF_ANADIG_PLL_VIDEO_DENOM_B(12), &ccm->analog_pll_video_denom);
222
223 reg &= ~BM_ANADIG_PLL_VIDEO_POWERDOWN;
224 writel(reg, &ccm->analog_pll_video);
225
226 while (timeout--)
227 if (readl(&ccm->analog_pll_video) & BM_ANADIG_PLL_VIDEO_LOCK)
228 break;
229 if (timeout < 0) {
230 printf("Warning: video pll lock timeout!\n");
231 return -ETIMEDOUT;
232 }
233
234 reg = readl(&ccm->analog_pll_video);
235 reg |= BM_ANADIG_PLL_VIDEO_ENABLE;
236 reg &= ~BM_ANADIG_PLL_VIDEO_BYPASS;
237 writel(reg, &ccm->analog_pll_video);
238
239 /* gate ipu1_di0_clk */
240 clrbits_le32(&ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK);
241
242 /* select video_pll clock / 7 for ipu1_di0_clk -> 65MHz pixclock */
243 reg = readl(&ccm->chsccdr);
244 reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK |
245 MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK |
246 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK);
247 reg |= (2 << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET) |
248 (6 << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET) |
249 (0 << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
250 writel(reg, &ccm->chsccdr);
251
252 /* enable ipu1_di0_clk */
253 setbits_le32(&ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK);
254
255 return 0;
256}
257#endif /* CONFIG_VIDEO_IPUV3 */
258
Fabio Estevamd8da22c2020-06-18 20:21:20 -0300259static int setup_fec(void)
260{
261 struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
262 int ret;
263
264 ret = enable_fec_anatop_clock(0, ENET_25MHZ);
265 if (ret)
266 return ret;
267
268 /* set gpr1[ENET_CLK_SEL] */
269 setbits_le32(&iomuxc_regs->gpr[1], IOMUXC_GPR1_ENET_CLK_SEL_MASK);
270
271 return 0;
272}
273
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300274int board_early_init_f(void)
275{
276 setup_iomux_uart();
Fabio Estevamf68a9c62015-04-29 22:28:09 -0300277
Peter Robinsonff181562017-07-01 18:44:03 +0100278#ifdef CONFIG_CMD_SATA
279 setup_sata();
280#endif
Fabio Estevamd8da22c2020-06-18 20:21:20 -0300281 setup_fec();
282
Fabio Estevamae40e822017-09-22 23:45:31 -0300283 return 0;
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300284}
285
286int board_init(void)
287{
Fabio Estevamae40e822017-09-22 23:45:31 -0300288 int ret = 0;
289
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300290 /* address of boot parameters */
291 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
292
Fabio Estevamae40e822017-09-22 23:45:31 -0300293#ifdef CONFIG_VIDEO_IPUV3
294 ret = setup_display();
295#endif
296
297 return ret;
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300298}
299
Baruch Siacheb9124f2019-11-10 14:38:07 +0200300static int request_detect_gpios(void)
301{
302 int node;
303 int ret;
304
305 node = fdt_node_offset_by_compatible(gd->fdt_blob, 0,
306 "solidrun,hummingboard-detect");
307 if (node < 0)
308 return -ENODEV;
309
310 ret = gpio_request_list_by_name_nodev(offset_to_ofnode(node),
311 "detect-gpios", board_detect_desc,
312 ARRAY_SIZE(board_detect_desc), GPIOD_IS_IN);
313
314 return ret;
315}
316
317static int free_detect_gpios(void)
318{
319 return gpio_free_list_nodev(board_detect_desc,
320 ARRAY_SIZE(board_detect_desc));
321}
322
Jon Nettleton73708202018-06-07 16:17:36 +0300323static enum board_type board_type(void)
Fabio Estevamfeb6cc52015-04-25 18:47:19 -0300324{
Jon Nettleton73708202018-06-07 16:17:36 +0300325 int val1, val2, val3;
Fabio Estevamfeb6cc52015-04-25 18:47:19 -0300326
Jon Nettleton73708202018-06-07 16:17:36 +0300327 SETUP_IOMUX_PADS(board_detect);
Fabio Estevamfeb6cc52015-04-25 18:47:19 -0300328
329 /*
330 * Machine selection -
Jon Nettleton73708202018-06-07 16:17:36 +0300331 * Machine val1, val2, val3
332 * ----------------------------
333 * HB2 x x 0
334 * HB rev 3.x x 0 x
335 * CBi 0 1 x
336 * HB 1 1 x
Fabio Estevamfeb6cc52015-04-25 18:47:19 -0300337 */
338
Dennis Gilmoreb1e85122017-08-24 10:49:43 -0500339 gpio_direction_input(IMX_GPIO_NR(2, 8));
Jon Nettleton73708202018-06-07 16:17:36 +0300340 val3 = gpio_get_value(IMX_GPIO_NR(2, 8));
Dennis Gilmoreb1e85122017-08-24 10:49:43 -0500341
Jon Nettleton73708202018-06-07 16:17:36 +0300342 if (val3 == 0)
343 return HUMMINGBOARD2;
Dennis Gilmoreb1e85122017-08-24 10:49:43 -0500344
Jon Nettleton73708202018-06-07 16:17:36 +0300345 gpio_direction_input(IMX_GPIO_NR(3, 4));
346 val2 = gpio_get_value(IMX_GPIO_NR(3, 4));
Dennis Gilmoreb1e85122017-08-24 10:49:43 -0500347
Jon Nettleton73708202018-06-07 16:17:36 +0300348 if (val2 == 0)
349 return HUMMINGBOARD;
350
351 gpio_direction_input(IMX_GPIO_NR(4, 9));
352 val1 = gpio_get_value(IMX_GPIO_NR(4, 9));
353
354 if (val1 == 0) {
355 return CUBOXI;
356 } else {
357 return HUMMINGBOARD;
358 }
359}
360
361static bool is_rev_15_som(void)
362{
363 int val1, val2;
364 SETUP_IOMUX_PADS(som_rev_detect);
365
366 val1 = gpio_get_value(IMX_GPIO_NR(6, 0));
367 val2 = gpio_get_value(IMX_GPIO_NR(6, 4));
368
369 if (val1 == 1 && val2 == 0)
Dennis Gilmoreb1e85122017-08-24 10:49:43 -0500370 return true;
Jon Nettleton73708202018-06-07 16:17:36 +0300371
372 return false;
Dennis Gilmoreb1e85122017-08-24 10:49:43 -0500373}
374
Jon Nettleton19ed6062018-06-11 15:26:22 +0300375static bool has_emmc(void)
376{
377 struct mmc *mmc;
Baruch Siacheb9124f2019-11-10 14:38:07 +0200378 mmc = find_mmc_device(2);
Jon Nettleton19ed6062018-06-11 15:26:22 +0300379 if (!mmc)
380 return 0;
Pali Rohára4c577f2021-07-14 16:37:29 +0200381 return (mmc_get_op_cond(mmc, true) < 0) ? 0 : 1;
Jon Nettleton19ed6062018-06-11 15:26:22 +0300382}
383
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300384int checkboard(void)
385{
Baruch Siacheb9124f2019-11-10 14:38:07 +0200386 request_detect_gpios();
387
Jon Nettleton73708202018-06-07 16:17:36 +0300388 switch (board_type()) {
389 case CUBOXI:
390 puts("Board: MX6 Cubox-i");
391 break;
392 case HUMMINGBOARD:
393 puts("Board: MX6 HummingBoard");
394 break;
395 case HUMMINGBOARD2:
396 puts("Board: MX6 HummingBoard2");
397 break;
398 case UNKNOWN:
399 default:
400 puts("Board: Unknown\n");
401 goto out;
402 }
Fabio Estevamfeb6cc52015-04-25 18:47:19 -0300403
Jon Nettleton73708202018-06-07 16:17:36 +0300404 if (is_rev_15_som())
405 puts(" (som rev 1.5)\n");
406 else
407 puts("\n");
408
Baruch Siacheb9124f2019-11-10 14:38:07 +0200409 free_detect_gpios();
Jon Nettleton73708202018-06-07 16:17:36 +0300410out:
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300411 return 0;
412}
413
Josua Mayer741ce302022-05-19 12:31:59 +0300414static int find_ethernet_phy(void)
415{
416 struct mii_dev *bus = NULL;
417 struct phy_device *phydev = NULL;
418 int phy_addr = -ENOENT;
419
420#ifdef CONFIG_FEC_MXC
421 bus = fec_get_miibus(ENET_BASE_ADDR, -1);
422 if (!bus)
423 return -ENOENT;
424
425 // scan address 0, 1, 4
426 phydev = phy_find_by_mask(bus, 0b00010011);
427 if (!phydev) {
428 free(bus);
429 return -ENOENT;
430 }
431 pr_debug("%s: detected ethernet phy at address %d\n", __func__, phydev->addr);
432 phy_addr = phydev->addr;
433
434 free(phydev);
435#endif
436
437 return phy_addr;
438}
439
440#if defined(CONFIG_OF_LIBFDT) && defined(CONFIG_OF_BOARD_SETUP)
441/*
442 * Configure the correct ethernet PHYs nodes in device-tree:
443 * - AR8035 at addresses 0 or 4: Cubox
444 * - AR8035 at address 0: HummingBoard, HummingBoard 2
445 * - ADIN1300 at address 1: since SoM rev 1.9
446 */
447int ft_board_setup(void *fdt, struct bd_info *bd)
448{
449 int node_phy0, node_phy1, node_phy4;
450 int ret, phy;
451 bool enable_phy0 = false, enable_phy1 = false, enable_phy4 = false;
452
453 // detect phy
454 phy = find_ethernet_phy();
455 if (phy == 0 || phy == 4) {
456 enable_phy0 = true;
457 switch (board_type()) {
458 case CUBOXI:
459 case UNKNOWN:
460 default:
461 enable_phy4 = true;
462 }
463 } else if (phy == 1) {
464 enable_phy1 = true;
465 } else {
466 pr_err("%s: couldn't detect ethernet phy, not patching dtb!\n", __func__);
467 return 0;
468 }
469
470 // update all phy nodes status
471 node_phy0 = fdt_path_offset(fdt, "/soc/bus@2100000/ethernet@2188000/mdio/ethernet-phy@0");
472 ret = fdt_setprop_string(fdt, node_phy0, "status", enable_phy0 ? "okay" : "disabled");
473 if (ret < 0 && enable_phy0)
474 pr_err("%s: failed to enable ethernet phy at address 0 in dtb!\n", __func__);
475 node_phy1 = fdt_path_offset(fdt, "/soc/bus@2100000/ethernet@2188000/mdio/ethernet-phy@1");
476 ret = fdt_setprop_string(fdt, node_phy1, "status", enable_phy1 ? "okay" : "disabled");
477 if (ret < 0 && enable_phy1)
478 pr_err("%s: failed to enable ethernet phy at address 1 in dtb!\n", __func__);
479 node_phy4 = fdt_path_offset(fdt, "/soc/bus@2100000/ethernet@2188000/mdio/ethernet-phy@4");
480 ret = fdt_setprop_string(fdt, node_phy4, "status", enable_phy4 ? "okay" : "disabled");
481 if (ret < 0 && enable_phy4)
482 pr_err("%s: failed to enable ethernet phy at address 4 in dtb!\n", __func__);
483
484 return 0;
485}
486#endif
487
Baruch Siacheb9124f2019-11-10 14:38:07 +0200488/* Override the default implementation, DT model is not accurate */
489int show_board_info(void)
490{
491 return checkboard();
492}
493
Fabio Estevam205d5862015-04-25 18:47:21 -0300494int board_late_init(void)
495{
496#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Baruch Siacheb9124f2019-11-10 14:38:07 +0200497 request_detect_gpios();
498
Jon Nettleton73708202018-06-07 16:17:36 +0300499 switch (board_type()) {
500 case CUBOXI:
Simon Glass382bee52017-08-03 12:22:09 -0600501 env_set("board_name", "CUBOXI");
Jon Nettleton73708202018-06-07 16:17:36 +0300502 break;
503 case HUMMINGBOARD:
504 env_set("board_name", "HUMMINGBOARD");
505 break;
506 case HUMMINGBOARD2:
507 env_set("board_name", "HUMMINGBOARD2");
508 break;
509 case UNKNOWN:
510 default:
511 env_set("board_name", "CUBOXI");
512 }
Fabio Estevam205d5862015-04-25 18:47:21 -0300513
Breno Lima4a2f9012016-07-22 09:11:30 -0300514 if (is_mx6dq())
Simon Glass382bee52017-08-03 12:22:09 -0600515 env_set("board_rev", "MX6Q");
Fabio Estevam205d5862015-04-25 18:47:21 -0300516 else
Simon Glass382bee52017-08-03 12:22:09 -0600517 env_set("board_rev", "MX6DL");
Jon Nettleton73708202018-06-07 16:17:36 +0300518
519 if (is_rev_15_som())
520 env_set("som_rev", "V15");
Jon Nettleton19ed6062018-06-11 15:26:22 +0300521
522 if (has_emmc())
523 env_set("has_emmc", "yes");
524
Baruch Siacheb9124f2019-11-10 14:38:07 +0200525 free_detect_gpios();
Fabio Estevam205d5862015-04-25 18:47:21 -0300526#endif
527
528 return 0;
529}
530
Baruch Siacheb9124f2019-11-10 14:38:07 +0200531/*
532 * This is not a perfect match. Avoid dependency on the DM GPIO driver needed
533 * for accurate board detection. Hummingboard2 DT is good enough for U-Boot on
534 * all Hummingboard/Cubox-i platforms.
535 */
536int board_fit_config_name_match(const char *name)
537{
538 char tmp_name[36];
539
540 snprintf(tmp_name, sizeof(tmp_name), "%s-hummingboard2-emmc-som-v15",
541 is_mx6dq() ? "imx6q" : "imx6dl");
542
543 return strcmp(name, tmp_name);
544}
545
Walter Lozano6c3fbf32020-05-19 15:24:22 -0300546void board_boot_order(u32 *spl_boot_list)
547{
548 struct src *psrc = (struct src *)SRC_BASE_ADDR;
549 unsigned int reg = readl(&psrc->sbmr1) >> 11;
550 u32 boot_mode = imx6_src_get_boot_mode() & IMX6_BMODE_MASK;
551 unsigned int bmode = readl(&src_base->sbmr2);
552
553 /* If bmode is serial or USB phy is active, return serial */
554 if (((bmode >> 24) & 0x03) == 0x01 || is_usbotg_phy_active()) {
555 spl_boot_list[0] = BOOT_DEVICE_BOARD;
556 return;
557 }
558
559 switch (boot_mode >> IMX6_BMODE_SHIFT) {
560 case IMX6_BMODE_SD:
561 case IMX6_BMODE_ESD:
562 case IMX6_BMODE_MMC:
563 case IMX6_BMODE_EMMC:
564 /*
565 * Upon reading BOOT_CFG register the following map is done:
566 * Bit 11 and 12 of BOOT_CFG register can determine the current
567 * mmc port
568 * 0x1 SD2
569 * 0x2 SD3
570 */
571
572 reg &= 0x3; /* Only care about bottom 2 bits */
573 switch (reg) {
574 case 1:
575 SETUP_IOMUX_PADS(usdhc2_pads);
576 spl_boot_list[0] = BOOT_DEVICE_MMC1;
577 break;
578 case 2:
579 SETUP_IOMUX_PADS(usdhc3_pads);
580 spl_boot_list[0] = BOOT_DEVICE_MMC2;
581 break;
582 }
583 break;
584 default:
585 /* By default use USB downloader */
586 spl_boot_list[0] = BOOT_DEVICE_BOARD;
587 break;
588 }
589
590 /* As a last resort, use serial downloader */
591 spl_boot_list[1] = BOOT_DEVICE_BOARD;
592}
593
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300594#ifdef CONFIG_SPL_BUILD
Fabio Estevamcfdcc5f2015-04-25 18:47:17 -0300595#include <asm/arch/mx6-ddr.h>
Fabio Estevam8cb68172015-04-25 18:47:18 -0300596static const struct mx6dq_iomux_ddr_regs mx6q_ddr_ioregs = {
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300597 .dram_sdclk_0 = 0x00020030,
598 .dram_sdclk_1 = 0x00020030,
599 .dram_cas = 0x00020030,
600 .dram_ras = 0x00020030,
Jon Nettletonb4e9bdc2018-04-10 17:05:35 -0300601 .dram_reset = 0x000c0030,
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300602 .dram_sdcke0 = 0x00003000,
603 .dram_sdcke1 = 0x00003000,
604 .dram_sdba2 = 0x00000000,
605 .dram_sdodt0 = 0x00003030,
606 .dram_sdodt1 = 0x00003030,
607 .dram_sdqs0 = 0x00000030,
608 .dram_sdqs1 = 0x00000030,
609 .dram_sdqs2 = 0x00000030,
610 .dram_sdqs3 = 0x00000030,
611 .dram_sdqs4 = 0x00000030,
612 .dram_sdqs5 = 0x00000030,
613 .dram_sdqs6 = 0x00000030,
614 .dram_sdqs7 = 0x00000030,
615 .dram_dqm0 = 0x00020030,
616 .dram_dqm1 = 0x00020030,
617 .dram_dqm2 = 0x00020030,
618 .dram_dqm3 = 0x00020030,
619 .dram_dqm4 = 0x00020030,
620 .dram_dqm5 = 0x00020030,
621 .dram_dqm6 = 0x00020030,
622 .dram_dqm7 = 0x00020030,
623};
624
Fabio Estevam8cb68172015-04-25 18:47:18 -0300625static const struct mx6sdl_iomux_ddr_regs mx6dl_ddr_ioregs = {
626 .dram_sdclk_0 = 0x00000028,
627 .dram_sdclk_1 = 0x00000028,
628 .dram_cas = 0x00000028,
629 .dram_ras = 0x00000028,
630 .dram_reset = 0x000c0028,
631 .dram_sdcke0 = 0x00003000,
632 .dram_sdcke1 = 0x00003000,
633 .dram_sdba2 = 0x00000000,
634 .dram_sdodt0 = 0x00003030,
635 .dram_sdodt1 = 0x00003030,
636 .dram_sdqs0 = 0x00000028,
637 .dram_sdqs1 = 0x00000028,
638 .dram_sdqs2 = 0x00000028,
639 .dram_sdqs3 = 0x00000028,
640 .dram_sdqs4 = 0x00000028,
641 .dram_sdqs5 = 0x00000028,
642 .dram_sdqs6 = 0x00000028,
643 .dram_sdqs7 = 0x00000028,
644 .dram_dqm0 = 0x00000028,
645 .dram_dqm1 = 0x00000028,
646 .dram_dqm2 = 0x00000028,
647 .dram_dqm3 = 0x00000028,
648 .dram_dqm4 = 0x00000028,
649 .dram_dqm5 = 0x00000028,
650 .dram_dqm6 = 0x00000028,
651 .dram_dqm7 = 0x00000028,
652};
653
654static const struct mx6dq_iomux_grp_regs mx6q_grp_ioregs = {
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300655 .grp_ddr_type = 0x000C0000,
656 .grp_ddrmode_ctl = 0x00020000,
657 .grp_ddrpke = 0x00000000,
658 .grp_addds = 0x00000030,
659 .grp_ctlds = 0x00000030,
660 .grp_ddrmode = 0x00020000,
661 .grp_b0ds = 0x00000030,
662 .grp_b1ds = 0x00000030,
663 .grp_b2ds = 0x00000030,
664 .grp_b3ds = 0x00000030,
665 .grp_b4ds = 0x00000030,
666 .grp_b5ds = 0x00000030,
667 .grp_b6ds = 0x00000030,
668 .grp_b7ds = 0x00000030,
669};
670
Fabio Estevam8cb68172015-04-25 18:47:18 -0300671static const struct mx6sdl_iomux_grp_regs mx6sdl_grp_ioregs = {
672 .grp_ddr_type = 0x000c0000,
673 .grp_ddrmode_ctl = 0x00020000,
674 .grp_ddrpke = 0x00000000,
675 .grp_addds = 0x00000028,
676 .grp_ctlds = 0x00000028,
677 .grp_ddrmode = 0x00020000,
678 .grp_b0ds = 0x00000028,
679 .grp_b1ds = 0x00000028,
680 .grp_b2ds = 0x00000028,
681 .grp_b3ds = 0x00000028,
682 .grp_b4ds = 0x00000028,
683 .grp_b5ds = 0x00000028,
684 .grp_b6ds = 0x00000028,
685 .grp_b7ds = 0x00000028,
686};
687
688/* microSOM with Dual processor and 1GB memory */
689static const struct mx6_mmdc_calibration mx6q_1g_mmcd_calib = {
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300690 .p0_mpwldectrl0 = 0x00000000,
691 .p0_mpwldectrl1 = 0x00000000,
692 .p1_mpwldectrl0 = 0x00000000,
693 .p1_mpwldectrl1 = 0x00000000,
694 .p0_mpdgctrl0 = 0x0314031c,
695 .p0_mpdgctrl1 = 0x023e0304,
696 .p1_mpdgctrl0 = 0x03240330,
697 .p1_mpdgctrl1 = 0x03180260,
698 .p0_mprddlctl = 0x3630323c,
699 .p1_mprddlctl = 0x3436283a,
700 .p0_mpwrdlctl = 0x36344038,
701 .p1_mpwrdlctl = 0x422a423c,
702};
703
Fabio Estevam8cb68172015-04-25 18:47:18 -0300704/* microSOM with Quad processor and 2GB memory */
705static const struct mx6_mmdc_calibration mx6q_2g_mmcd_calib = {
706 .p0_mpwldectrl0 = 0x00000000,
707 .p0_mpwldectrl1 = 0x00000000,
708 .p1_mpwldectrl0 = 0x00000000,
709 .p1_mpwldectrl1 = 0x00000000,
710 .p0_mpdgctrl0 = 0x0314031c,
711 .p0_mpdgctrl1 = 0x023e0304,
712 .p1_mpdgctrl0 = 0x03240330,
713 .p1_mpdgctrl1 = 0x03180260,
714 .p0_mprddlctl = 0x3630323c,
715 .p1_mprddlctl = 0x3436283a,
716 .p0_mpwrdlctl = 0x36344038,
717 .p1_mpwrdlctl = 0x422a423c,
718};
719
720/* microSOM with Solo processor and 512MB memory */
721static const struct mx6_mmdc_calibration mx6dl_512m_mmcd_calib = {
722 .p0_mpwldectrl0 = 0x0045004D,
723 .p0_mpwldectrl1 = 0x003A0047,
724 .p0_mpdgctrl0 = 0x023C0224,
725 .p0_mpdgctrl1 = 0x02000220,
726 .p0_mprddlctl = 0x44444846,
727 .p0_mpwrdlctl = 0x32343032,
728};
729
730/* microSOM with Dual lite processor and 1GB memory */
731static const struct mx6_mmdc_calibration mx6dl_1g_mmcd_calib = {
732 .p0_mpwldectrl0 = 0x0045004D,
733 .p0_mpwldectrl1 = 0x003A0047,
734 .p1_mpwldectrl0 = 0x001F001F,
735 .p1_mpwldectrl1 = 0x00210035,
736 .p0_mpdgctrl0 = 0x023C0224,
737 .p0_mpdgctrl1 = 0x02000220,
738 .p1_mpdgctrl0 = 0x02200220,
Fabio Estevamdbab8b82015-05-29 13:00:36 -0300739 .p1_mpdgctrl1 = 0x02040208,
Fabio Estevam8cb68172015-04-25 18:47:18 -0300740 .p0_mprddlctl = 0x44444846,
741 .p1_mprddlctl = 0x4042463C,
742 .p0_mpwrdlctl = 0x32343032,
743 .p1_mpwrdlctl = 0x36363430,
744};
745
746static struct mx6_ddr3_cfg mem_ddr_2g = {
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300747 .mem_speed = 1600,
748 .density = 2,
749 .width = 16,
750 .banks = 8,
751 .rowaddr = 14,
752 .coladdr = 10,
753 .pagesz = 2,
754 .trcd = 1375,
755 .trcmin = 4875,
756 .trasmin = 3500,
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300757};
758
Fabio Estevam8cb68172015-04-25 18:47:18 -0300759static struct mx6_ddr3_cfg mem_ddr_4g = {
760 .mem_speed = 1600,
761 .density = 4,
762 .width = 16,
763 .banks = 8,
Jon Nettleton51f957a2018-06-07 16:17:37 +0300764 .rowaddr = 16,
Fabio Estevam8cb68172015-04-25 18:47:18 -0300765 .coladdr = 10,
766 .pagesz = 2,
767 .trcd = 1375,
768 .trcmin = 4875,
769 .trasmin = 3500,
770};
771
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300772static void ccgr_init(void)
773{
774 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
775
776 writel(0x00C03F3F, &ccm->CCGR0);
777 writel(0x0030FC03, &ccm->CCGR1);
778 writel(0x0FFFC000, &ccm->CCGR2);
779 writel(0x3FF00000, &ccm->CCGR3);
780 writel(0x00FFF300, &ccm->CCGR4);
781 writel(0x0F0000C3, &ccm->CCGR5);
782 writel(0x000003FF, &ccm->CCGR6);
783}
784
Fabio Estevam8cb68172015-04-25 18:47:18 -0300785static void spl_dram_init(int width)
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300786{
787 struct mx6_ddr_sysinfo sysinfo = {
788 /* width of data bus: 0=16, 1=32, 2=64 */
Fabio Estevam8cb68172015-04-25 18:47:18 -0300789 .dsize = width / 32,
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300790 /* config for full 4GB range so that get_mem_size() works */
791 .cs_density = 32, /* 32Gb per CS */
792 .ncs = 1, /* single chip select */
793 .cs1_mirror = 0,
794 .rtt_wr = 1 /*DDR3_RTT_60_OHM*/, /* RTT_Wr = RZQ/4 */
795 .rtt_nom = 1 /*DDR3_RTT_60_OHM*/, /* RTT_Nom = RZQ/4 */
796 .walat = 1, /* Write additional latency */
797 .ralat = 5, /* Read additional latency */
798 .mif3_mode = 3, /* Command prediction working mode */
799 .bi_on = 1, /* Bank interleaving enabled */
800 .sde_to_rst = 0x10, /* 14 cycles, 200us (JEDEC default) */
801 .rst_to_cke = 0x23, /* 33 cycles, 500us (JEDEC default) */
Peng Fanf2ff8342015-08-17 16:11:03 +0800802 .ddr_type = DDR_TYPE_DDR3,
Fabio Estevamedf00932016-08-29 20:37:15 -0300803 .refsel = 1, /* Refresh cycles at 32KHz */
804 .refr = 7, /* 8 refresh commands per refresh cycle */
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300805 };
806
Breno Lima4a2f9012016-07-22 09:11:30 -0300807 if (is_mx6dq())
Fabio Estevam8cb68172015-04-25 18:47:18 -0300808 mx6dq_dram_iocfg(width, &mx6q_ddr_ioregs, &mx6q_grp_ioregs);
809 else
810 mx6sdl_dram_iocfg(width, &mx6dl_ddr_ioregs, &mx6sdl_grp_ioregs);
811
812 if (is_cpu_type(MXC_CPU_MX6D))
813 mx6_dram_cfg(&sysinfo, &mx6q_1g_mmcd_calib, &mem_ddr_2g);
814 else if (is_cpu_type(MXC_CPU_MX6Q))
815 mx6_dram_cfg(&sysinfo, &mx6q_2g_mmcd_calib, &mem_ddr_4g);
816 else if (is_cpu_type(MXC_CPU_MX6DL))
Fabio Estevamdbab8b82015-05-29 13:00:36 -0300817 mx6_dram_cfg(&sysinfo, &mx6dl_1g_mmcd_calib, &mem_ddr_2g);
Fabio Estevam8cb68172015-04-25 18:47:18 -0300818 else if (is_cpu_type(MXC_CPU_MX6SOLO))
819 mx6_dram_cfg(&sysinfo, &mx6dl_512m_mmcd_calib, &mem_ddr_2g);
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300820}
821
822void board_init_f(ulong dummy)
823{
824 /* setup AIPS and disable watchdog */
825 arch_cpu_init();
826
827 ccgr_init();
828 gpr_init();
829
830 /* iomux and setup of i2c */
831 board_early_init_f();
832
833 /* setup GP timer */
834 timer_init();
835
836 /* UART clocks enabled and gd valid - init serial console */
837 preloader_console_init();
838
839 /* DDR initialization */
Fabio Estevam8cb68172015-04-25 18:47:18 -0300840 if (is_cpu_type(MXC_CPU_MX6SOLO))
841 spl_dram_init(32);
842 else
843 spl_dram_init(64);
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300844
845 /* Clear the BSS. */
846 memset(__bss_start, 0, __bss_end - __bss_start);
847
848 /* load/boot image from boot device */
849 board_init_r(NULL, 0);
850}
851#endif