blob: 59e8b1dca1d74bbb2cff6cca0ab657af0c6ab7f7 [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/*
3 * Copyright (C) 2015 Freescale Semiconductor, Inc.
4 *
5 * Author: Fabio Estevam <fabio.estevam@freescale.com>
6 *
7 * Copyright (C) 2013 Jon Nettleton <jon.nettleton@gmail.com>
8 *
9 * Based on SPL code from Solidrun tree, which is:
10 * Author: Tungyi Lin <tungyilin1127@gmail.com>
11 *
12 * Derived from EDM_CF_IMX6 code by TechNexion,Inc
13 * Ported to SolidRun microSOM by Rabeeh Khoury <rabeeh@solid-run.com>
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -030014 */
15
Simon Glassc3dc39a2020-05-10 11:39:55 -060016#include <common.h>
Simon Glass4d72caa2020-05-10 11:40:01 -060017#include <image.h>
Simon Glass52559322019-11-14 12:57:46 -070018#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060019#include <log.h>
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -030020#include <asm/arch/clock.h>
21#include <asm/arch/imx-regs.h>
22#include <asm/arch/iomux.h>
23#include <asm/arch/mx6-pins.h>
Fabio Estevamf68a9c62015-04-29 22:28:09 -030024#include <asm/arch/mxc_hdmi.h>
Simon Glass9fb625c2019-08-01 09:46:51 -060025#include <env.h>
Simon Glassc05ed002020-05-10 11:40:11 -060026#include <linux/delay.h>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090027#include <linux/errno.h>
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -030028#include <asm/gpio.h>
Stefano Babic552a8482017-06-29 10:16:06 +020029#include <asm/mach-imx/iomux-v3.h>
30#include <asm/mach-imx/sata.h>
31#include <asm/mach-imx/video.h>
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -030032#include <mmc.h>
Yangbo Lue37ac712019-06-21 11:42:28 +080033#include <fsl_esdhc_imx.h>
Fabio Estevam712be3e2015-05-04 11:22:55 -030034#include <malloc.h>
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -030035#include <asm/arch/crm_regs.h>
36#include <asm/io.h>
37#include <asm/arch/sys_proto.h>
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -030038#include <spl.h>
Fabio Estevame1d74372015-04-29 22:28:10 -030039#include <usb.h>
Mateusz Kulikowskie162c6b2016-03-31 23:12:23 +020040#include <usb/ehci-ci.h>
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -030041
42DECLARE_GLOBAL_DATA_PTR;
43
44#define UART_PAD_CTRL (PAD_CTL_PUS_100K_UP | \
45 PAD_CTL_SPEED_MED | PAD_CTL_DSE_40ohm | \
46 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
47
48#define USDHC_PAD_CTRL (PAD_CTL_PUS_47K_UP | \
49 PAD_CTL_SPEED_LOW | PAD_CTL_DSE_80ohm | \
50 PAD_CTL_SRE_FAST | PAD_CTL_HYS)
51
Fabio Estevame1d74372015-04-29 22:28:10 -030052#define USB_H1_VBUS IMX_GPIO_NR(1, 0)
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -030053
Jon Nettleton73708202018-06-07 16:17:36 +030054enum board_type {
55 CUBOXI = 0x00,
56 HUMMINGBOARD = 0x01,
57 HUMMINGBOARD2 = 0x02,
58 UNKNOWN = 0x03,
59};
60
Baruch Siacheb9124f2019-11-10 14:38:07 +020061static struct gpio_desc board_detect_desc[5];
62
Jon Nettleton51f957a2018-06-07 16:17:37 +030063#define MEM_STRIDE 0x4000000
64static u32 get_ram_size_stride_test(u32 *base, u32 maxsize)
65{
66 volatile u32 *addr;
67 u32 save[64];
68 u32 cnt;
69 u32 size;
70 int i = 0;
71
72 /* First save the data */
73 for (cnt = 0; cnt < maxsize; cnt += MEM_STRIDE) {
74 addr = (volatile u32 *)((u32)base + cnt); /* pointer arith! */
75 sync ();
76 save[i++] = *addr;
77 sync ();
78 }
79
80 /* First write a signature */
81 * (volatile u32 *)base = 0x12345678;
82 for (size = MEM_STRIDE; size < maxsize; size += MEM_STRIDE) {
83 * (volatile u32 *)((u32)base + size) = size;
84 sync ();
85 if (* (volatile u32 *)((u32)base) == size) { /* We reached the overlapping address */
86 break;
87 }
88 }
89
90 /* Restore the data */
91 for (cnt = (maxsize - MEM_STRIDE); i > 0; cnt -= MEM_STRIDE) {
92 addr = (volatile u32 *)((u32)base + cnt); /* pointer arith! */
93 sync ();
94 *addr = save[i--];
95 sync ();
96 }
97
98 return (size);
99}
100
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300101int dram_init(void)
102{
Jon Nettleton51f957a2018-06-07 16:17:37 +0300103 u32 max_size = imx_ddr_size();
104
105 gd->ram_size = get_ram_size_stride_test((u32 *) CONFIG_SYS_SDRAM_BASE,
106 (u32)max_size);
107
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300108 return 0;
109}
110
111static iomux_v3_cfg_t const uart1_pads[] = {
Fabio Estevamcfdcc5f2015-04-25 18:47:17 -0300112 IOMUX_PADS(PAD_CSI0_DAT10__UART1_TX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
113 IOMUX_PADS(PAD_CSI0_DAT11__UART1_RX_DATA | MUX_PAD_CTRL(UART_PAD_CTRL)),
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300114};
115
116static iomux_v3_cfg_t const usdhc2_pads[] = {
Fabio Estevamcfdcc5f2015-04-25 18:47:17 -0300117 IOMUX_PADS(PAD_SD2_CLK__SD2_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
118 IOMUX_PADS(PAD_SD2_CMD__SD2_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
119 IOMUX_PADS(PAD_SD2_DAT0__SD2_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
120 IOMUX_PADS(PAD_SD2_DAT1__SD2_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
121 IOMUX_PADS(PAD_SD2_DAT2__SD2_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
122 IOMUX_PADS(PAD_SD2_DAT3__SD2_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300123};
124
Jon Nettleton86e5a7f2018-06-11 15:26:20 +0300125static iomux_v3_cfg_t const usdhc3_pads[] = {
126 IOMUX_PADS(PAD_SD3_CLK__SD3_CLK | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
127 IOMUX_PADS(PAD_SD3_CMD__SD3_CMD | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
128 IOMUX_PADS(PAD_SD3_DAT0__SD3_DATA0 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
129 IOMUX_PADS(PAD_SD3_DAT1__SD3_DATA1 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
130 IOMUX_PADS(PAD_SD3_DAT2__SD3_DATA2 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
131 IOMUX_PADS(PAD_SD3_DAT3__SD3_DATA3 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
132 IOMUX_PADS(PAD_SD3_DAT4__SD3_DATA4 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
133 IOMUX_PADS(PAD_SD3_DAT5__SD3_DATA5 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
134 IOMUX_PADS(PAD_SD3_DAT6__SD3_DATA6 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
135 IOMUX_PADS(PAD_SD3_DAT7__SD3_DATA7 | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
136 IOMUX_PADS(PAD_SD3_RST__SD3_RESET | MUX_PAD_CTRL(USDHC_PAD_CTRL)),
137};
138
Jon Nettleton73708202018-06-07 16:17:36 +0300139static iomux_v3_cfg_t const board_detect[] = {
Fabio Estevamfeb6cc52015-04-25 18:47:19 -0300140 /* These pins are for sensing if it is a CuBox-i or a HummingBoard */
141 IOMUX_PADS(PAD_KEY_ROW1__GPIO4_IO09 | MUX_PAD_CTRL(UART_PAD_CTRL)),
142 IOMUX_PADS(PAD_EIM_DA4__GPIO3_IO04 | MUX_PAD_CTRL(UART_PAD_CTRL)),
Jon Nettleton73708202018-06-07 16:17:36 +0300143 IOMUX_PADS(PAD_SD4_DAT0__GPIO2_IO08 | MUX_PAD_CTRL(UART_PAD_CTRL)),
144};
145
146static iomux_v3_cfg_t const som_rev_detect[] = {
147 /* These pins are for sensing if it is a CuBox-i or a HummingBoard */
148 IOMUX_PADS(PAD_CSI0_DAT14__GPIO6_IO00 | MUX_PAD_CTRL(UART_PAD_CTRL)),
149 IOMUX_PADS(PAD_CSI0_DAT18__GPIO6_IO04 | MUX_PAD_CTRL(UART_PAD_CTRL)),
Fabio Estevamfeb6cc52015-04-25 18:47:19 -0300150};
151
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300152static void setup_iomux_uart(void)
153{
Fabio Estevamcfdcc5f2015-04-25 18:47:17 -0300154 SETUP_IOMUX_PADS(uart1_pads);
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300155}
156
Jon Nettleton86e5a7f2018-06-11 15:26:20 +0300157static struct fsl_esdhc_cfg usdhc_cfg = {
158 .esdhc_base = USDHC2_BASE_ADDR,
159 .max_bus_width = 4,
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300160};
161
Jon Nettleton86e5a7f2018-06-11 15:26:20 +0300162static struct fsl_esdhc_cfg emmc_cfg = {
163 .esdhc_base = USDHC3_BASE_ADDR,
164 .max_bus_width = 8,
165};
166
167int board_mmc_get_env_dev(int devno)
168{
Baruch Siacheb9124f2019-11-10 14:38:07 +0200169 return devno;
Jon Nettleton86e5a7f2018-06-11 15:26:20 +0300170}
171
172#define USDHC2_CD_GPIO IMX_GPIO_NR(1, 4)
173
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300174int board_mmc_getcd(struct mmc *mmc)
175{
Jon Nettleton86e5a7f2018-06-11 15:26:20 +0300176 struct fsl_esdhc_cfg *cfg = mmc->priv;
177 int ret = 0;
178
179 switch (cfg->esdhc_base) {
180 case USDHC2_BASE_ADDR:
181 ret = !gpio_get_value(USDHC2_CD_GPIO);
182 break;
183 case USDHC3_BASE_ADDR:
Jon Nettleton19ed6062018-06-11 15:26:22 +0300184 ret = (mmc_get_op_cond(mmc) < 0) ? 0 : 1; /* eMMC/uSDHC3 has no CD GPIO */
Jon Nettleton86e5a7f2018-06-11 15:26:20 +0300185 break;
186 }
187
188 return ret;
189}
190
Jon Nettleton86e5a7f2018-06-11 15:26:20 +0300191static int mmc_init_spl(bd_t *bis)
192{
193 struct src *psrc = (struct src *)SRC_BASE_ADDR;
194 unsigned reg = readl(&psrc->sbmr1) >> 11;
195
196 /*
197 * Upon reading BOOT_CFG register the following map is done:
198 * Bit 11 and 12 of BOOT_CFG register can determine the current
199 * mmc port
200 * 0x1 SD2
201 * 0x2 SD3
202 */
203 switch (reg & 0x3) {
204 case 0x1:
205 SETUP_IOMUX_PADS(usdhc2_pads);
206 usdhc_cfg.sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
207 gd->arch.sdhc_clk = usdhc_cfg.sdhc_clk;
208 return fsl_esdhc_initialize(bis, &usdhc_cfg);
209 case 0x2:
210 SETUP_IOMUX_PADS(usdhc3_pads);
211 emmc_cfg.sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
212 gd->arch.sdhc_clk = emmc_cfg.sdhc_clk;
213 return fsl_esdhc_initialize(bis, &emmc_cfg);
214 }
215
216 return -ENODEV;
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300217}
218
219int board_mmc_init(bd_t *bis)
220{
Jon Nettleton86e5a7f2018-06-11 15:26:20 +0300221 if (IS_ENABLED(CONFIG_SPL_BUILD))
222 return mmc_init_spl(bis);
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300223
Baruch Siacheb9124f2019-11-10 14:38:07 +0200224 return 0;
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300225}
226
Fabio Estevamf68a9c62015-04-29 22:28:09 -0300227#ifdef CONFIG_VIDEO_IPUV3
228static void do_enable_hdmi(struct display_info_t const *dev)
229{
230 imx_enable_hdmi_phy();
231}
232
233struct display_info_t const displays[] = {
234 {
235 .bus = -1,
236 .addr = 0,
237 .pixfmt = IPU_PIX_FMT_RGB24,
238 .detect = detect_hdmi,
239 .enable = do_enable_hdmi,
240 .mode = {
241 .name = "HDMI",
242 /* 1024x768@60Hz (VESA)*/
243 .refresh = 60,
244 .xres = 1024,
245 .yres = 768,
246 .pixclock = 15384,
247 .left_margin = 160,
248 .right_margin = 24,
249 .upper_margin = 29,
250 .lower_margin = 3,
251 .hsync_len = 136,
252 .vsync_len = 6,
253 .sync = FB_SYNC_EXT,
254 .vmode = FB_VMODE_NONINTERLACED
255 }
256 }
257};
258
259size_t display_count = ARRAY_SIZE(displays);
260
261static int setup_display(void)
262{
263 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
264 int reg;
265 int timeout = 100000;
266
267 enable_ipu_clock();
268 imx_setup_hdmi();
269
270 /* set video pll to 455MHz (24MHz * (37+11/12) / 2) */
271 setbits_le32(&ccm->analog_pll_video, BM_ANADIG_PLL_VIDEO_POWERDOWN);
272
273 reg = readl(&ccm->analog_pll_video);
274 reg &= ~BM_ANADIG_PLL_VIDEO_DIV_SELECT;
275 reg |= BF_ANADIG_PLL_VIDEO_DIV_SELECT(37);
276 reg &= ~BM_ANADIG_PLL_VIDEO_POST_DIV_SELECT;
277 reg |= BF_ANADIG_PLL_VIDEO_POST_DIV_SELECT(1);
278 writel(reg, &ccm->analog_pll_video);
279
280 writel(BF_ANADIG_PLL_VIDEO_NUM_A(11), &ccm->analog_pll_video_num);
281 writel(BF_ANADIG_PLL_VIDEO_DENOM_B(12), &ccm->analog_pll_video_denom);
282
283 reg &= ~BM_ANADIG_PLL_VIDEO_POWERDOWN;
284 writel(reg, &ccm->analog_pll_video);
285
286 while (timeout--)
287 if (readl(&ccm->analog_pll_video) & BM_ANADIG_PLL_VIDEO_LOCK)
288 break;
289 if (timeout < 0) {
290 printf("Warning: video pll lock timeout!\n");
291 return -ETIMEDOUT;
292 }
293
294 reg = readl(&ccm->analog_pll_video);
295 reg |= BM_ANADIG_PLL_VIDEO_ENABLE;
296 reg &= ~BM_ANADIG_PLL_VIDEO_BYPASS;
297 writel(reg, &ccm->analog_pll_video);
298
299 /* gate ipu1_di0_clk */
300 clrbits_le32(&ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK);
301
302 /* select video_pll clock / 7 for ipu1_di0_clk -> 65MHz pixclock */
303 reg = readl(&ccm->chsccdr);
304 reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK |
305 MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK |
306 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK);
307 reg |= (2 << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET) |
308 (6 << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET) |
309 (0 << MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_OFFSET);
310 writel(reg, &ccm->chsccdr);
311
312 /* enable ipu1_di0_clk */
313 setbits_le32(&ccm->CCGR3, MXC_CCM_CCGR3_LDB_DI0_MASK);
314
315 return 0;
316}
317#endif /* CONFIG_VIDEO_IPUV3 */
318
Fabio Estevamd8da22c2020-06-18 20:21:20 -0300319static int setup_fec(void)
320{
321 struct iomuxc *const iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
322 int ret;
323
324 ret = enable_fec_anatop_clock(0, ENET_25MHZ);
325 if (ret)
326 return ret;
327
328 /* set gpr1[ENET_CLK_SEL] */
329 setbits_le32(&iomuxc_regs->gpr[1], IOMUXC_GPR1_ENET_CLK_SEL_MASK);
330
331 return 0;
332}
333
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300334int board_early_init_f(void)
335{
336 setup_iomux_uart();
Fabio Estevamf68a9c62015-04-29 22:28:09 -0300337
Peter Robinsonff181562017-07-01 18:44:03 +0100338#ifdef CONFIG_CMD_SATA
339 setup_sata();
340#endif
Fabio Estevamd8da22c2020-06-18 20:21:20 -0300341 setup_fec();
342
Fabio Estevamae40e822017-09-22 23:45:31 -0300343 return 0;
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300344}
345
346int board_init(void)
347{
Fabio Estevamae40e822017-09-22 23:45:31 -0300348 int ret = 0;
349
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300350 /* address of boot parameters */
351 gd->bd->bi_boot_params = CONFIG_SYS_SDRAM_BASE + 0x100;
352
Fabio Estevamae40e822017-09-22 23:45:31 -0300353#ifdef CONFIG_VIDEO_IPUV3
354 ret = setup_display();
355#endif
356
357 return ret;
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300358}
359
Baruch Siacheb9124f2019-11-10 14:38:07 +0200360static int request_detect_gpios(void)
361{
362 int node;
363 int ret;
364
365 node = fdt_node_offset_by_compatible(gd->fdt_blob, 0,
366 "solidrun,hummingboard-detect");
367 if (node < 0)
368 return -ENODEV;
369
370 ret = gpio_request_list_by_name_nodev(offset_to_ofnode(node),
371 "detect-gpios", board_detect_desc,
372 ARRAY_SIZE(board_detect_desc), GPIOD_IS_IN);
373
374 return ret;
375}
376
377static int free_detect_gpios(void)
378{
379 return gpio_free_list_nodev(board_detect_desc,
380 ARRAY_SIZE(board_detect_desc));
381}
382
Jon Nettleton73708202018-06-07 16:17:36 +0300383static enum board_type board_type(void)
Fabio Estevamfeb6cc52015-04-25 18:47:19 -0300384{
Jon Nettleton73708202018-06-07 16:17:36 +0300385 int val1, val2, val3;
Fabio Estevamfeb6cc52015-04-25 18:47:19 -0300386
Jon Nettleton73708202018-06-07 16:17:36 +0300387 SETUP_IOMUX_PADS(board_detect);
Fabio Estevamfeb6cc52015-04-25 18:47:19 -0300388
389 /*
390 * Machine selection -
Jon Nettleton73708202018-06-07 16:17:36 +0300391 * Machine val1, val2, val3
392 * ----------------------------
393 * HB2 x x 0
394 * HB rev 3.x x 0 x
395 * CBi 0 1 x
396 * HB 1 1 x
Fabio Estevamfeb6cc52015-04-25 18:47:19 -0300397 */
398
Dennis Gilmoreb1e85122017-08-24 10:49:43 -0500399 gpio_direction_input(IMX_GPIO_NR(2, 8));
Jon Nettleton73708202018-06-07 16:17:36 +0300400 val3 = gpio_get_value(IMX_GPIO_NR(2, 8));
Dennis Gilmoreb1e85122017-08-24 10:49:43 -0500401
Jon Nettleton73708202018-06-07 16:17:36 +0300402 if (val3 == 0)
403 return HUMMINGBOARD2;
Dennis Gilmoreb1e85122017-08-24 10:49:43 -0500404
Jon Nettleton73708202018-06-07 16:17:36 +0300405 gpio_direction_input(IMX_GPIO_NR(3, 4));
406 val2 = gpio_get_value(IMX_GPIO_NR(3, 4));
Dennis Gilmoreb1e85122017-08-24 10:49:43 -0500407
Jon Nettleton73708202018-06-07 16:17:36 +0300408 if (val2 == 0)
409 return HUMMINGBOARD;
410
411 gpio_direction_input(IMX_GPIO_NR(4, 9));
412 val1 = gpio_get_value(IMX_GPIO_NR(4, 9));
413
414 if (val1 == 0) {
415 return CUBOXI;
416 } else {
417 return HUMMINGBOARD;
418 }
419}
420
421static bool is_rev_15_som(void)
422{
423 int val1, val2;
424 SETUP_IOMUX_PADS(som_rev_detect);
425
426 val1 = gpio_get_value(IMX_GPIO_NR(6, 0));
427 val2 = gpio_get_value(IMX_GPIO_NR(6, 4));
428
429 if (val1 == 1 && val2 == 0)
Dennis Gilmoreb1e85122017-08-24 10:49:43 -0500430 return true;
Jon Nettleton73708202018-06-07 16:17:36 +0300431
432 return false;
Dennis Gilmoreb1e85122017-08-24 10:49:43 -0500433}
434
Jon Nettleton19ed6062018-06-11 15:26:22 +0300435static bool has_emmc(void)
436{
437 struct mmc *mmc;
Baruch Siacheb9124f2019-11-10 14:38:07 +0200438 mmc = find_mmc_device(2);
Jon Nettleton19ed6062018-06-11 15:26:22 +0300439 if (!mmc)
440 return 0;
441 return (mmc_get_op_cond(mmc) < 0) ? 0 : 1;
442}
443
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300444int checkboard(void)
445{
Baruch Siacheb9124f2019-11-10 14:38:07 +0200446 request_detect_gpios();
447
Jon Nettleton73708202018-06-07 16:17:36 +0300448 switch (board_type()) {
449 case CUBOXI:
450 puts("Board: MX6 Cubox-i");
451 break;
452 case HUMMINGBOARD:
453 puts("Board: MX6 HummingBoard");
454 break;
455 case HUMMINGBOARD2:
456 puts("Board: MX6 HummingBoard2");
457 break;
458 case UNKNOWN:
459 default:
460 puts("Board: Unknown\n");
461 goto out;
462 }
Fabio Estevamfeb6cc52015-04-25 18:47:19 -0300463
Jon Nettleton73708202018-06-07 16:17:36 +0300464 if (is_rev_15_som())
465 puts(" (som rev 1.5)\n");
466 else
467 puts("\n");
468
Baruch Siacheb9124f2019-11-10 14:38:07 +0200469 free_detect_gpios();
Jon Nettleton73708202018-06-07 16:17:36 +0300470out:
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300471 return 0;
472}
473
Baruch Siacheb9124f2019-11-10 14:38:07 +0200474/* Override the default implementation, DT model is not accurate */
475int show_board_info(void)
476{
477 return checkboard();
478}
479
Fabio Estevam205d5862015-04-25 18:47:21 -0300480int board_late_init(void)
481{
482#ifdef CONFIG_ENV_VARS_UBOOT_RUNTIME_CONFIG
Baruch Siacheb9124f2019-11-10 14:38:07 +0200483 request_detect_gpios();
484
Jon Nettleton73708202018-06-07 16:17:36 +0300485 switch (board_type()) {
486 case CUBOXI:
Simon Glass382bee52017-08-03 12:22:09 -0600487 env_set("board_name", "CUBOXI");
Jon Nettleton73708202018-06-07 16:17:36 +0300488 break;
489 case HUMMINGBOARD:
490 env_set("board_name", "HUMMINGBOARD");
491 break;
492 case HUMMINGBOARD2:
493 env_set("board_name", "HUMMINGBOARD2");
494 break;
495 case UNKNOWN:
496 default:
497 env_set("board_name", "CUBOXI");
498 }
Fabio Estevam205d5862015-04-25 18:47:21 -0300499
Breno Lima4a2f9012016-07-22 09:11:30 -0300500 if (is_mx6dq())
Simon Glass382bee52017-08-03 12:22:09 -0600501 env_set("board_rev", "MX6Q");
Fabio Estevam205d5862015-04-25 18:47:21 -0300502 else
Simon Glass382bee52017-08-03 12:22:09 -0600503 env_set("board_rev", "MX6DL");
Jon Nettleton73708202018-06-07 16:17:36 +0300504
505 if (is_rev_15_som())
506 env_set("som_rev", "V15");
Jon Nettleton19ed6062018-06-11 15:26:22 +0300507
508 if (has_emmc())
509 env_set("has_emmc", "yes");
510
Baruch Siacheb9124f2019-11-10 14:38:07 +0200511 free_detect_gpios();
Fabio Estevam205d5862015-04-25 18:47:21 -0300512#endif
513
514 return 0;
515}
516
Baruch Siacheb9124f2019-11-10 14:38:07 +0200517/*
518 * This is not a perfect match. Avoid dependency on the DM GPIO driver needed
519 * for accurate board detection. Hummingboard2 DT is good enough for U-Boot on
520 * all Hummingboard/Cubox-i platforms.
521 */
522int board_fit_config_name_match(const char *name)
523{
524 char tmp_name[36];
525
526 snprintf(tmp_name, sizeof(tmp_name), "%s-hummingboard2-emmc-som-v15",
527 is_mx6dq() ? "imx6q" : "imx6dl");
528
529 return strcmp(name, tmp_name);
530}
531
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300532#ifdef CONFIG_SPL_BUILD
Fabio Estevamcfdcc5f2015-04-25 18:47:17 -0300533#include <asm/arch/mx6-ddr.h>
Fabio Estevam8cb68172015-04-25 18:47:18 -0300534static const struct mx6dq_iomux_ddr_regs mx6q_ddr_ioregs = {
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300535 .dram_sdclk_0 = 0x00020030,
536 .dram_sdclk_1 = 0x00020030,
537 .dram_cas = 0x00020030,
538 .dram_ras = 0x00020030,
Jon Nettletonb4e9bdc2018-04-10 17:05:35 -0300539 .dram_reset = 0x000c0030,
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300540 .dram_sdcke0 = 0x00003000,
541 .dram_sdcke1 = 0x00003000,
542 .dram_sdba2 = 0x00000000,
543 .dram_sdodt0 = 0x00003030,
544 .dram_sdodt1 = 0x00003030,
545 .dram_sdqs0 = 0x00000030,
546 .dram_sdqs1 = 0x00000030,
547 .dram_sdqs2 = 0x00000030,
548 .dram_sdqs3 = 0x00000030,
549 .dram_sdqs4 = 0x00000030,
550 .dram_sdqs5 = 0x00000030,
551 .dram_sdqs6 = 0x00000030,
552 .dram_sdqs7 = 0x00000030,
553 .dram_dqm0 = 0x00020030,
554 .dram_dqm1 = 0x00020030,
555 .dram_dqm2 = 0x00020030,
556 .dram_dqm3 = 0x00020030,
557 .dram_dqm4 = 0x00020030,
558 .dram_dqm5 = 0x00020030,
559 .dram_dqm6 = 0x00020030,
560 .dram_dqm7 = 0x00020030,
561};
562
Fabio Estevam8cb68172015-04-25 18:47:18 -0300563static const struct mx6sdl_iomux_ddr_regs mx6dl_ddr_ioregs = {
564 .dram_sdclk_0 = 0x00000028,
565 .dram_sdclk_1 = 0x00000028,
566 .dram_cas = 0x00000028,
567 .dram_ras = 0x00000028,
568 .dram_reset = 0x000c0028,
569 .dram_sdcke0 = 0x00003000,
570 .dram_sdcke1 = 0x00003000,
571 .dram_sdba2 = 0x00000000,
572 .dram_sdodt0 = 0x00003030,
573 .dram_sdodt1 = 0x00003030,
574 .dram_sdqs0 = 0x00000028,
575 .dram_sdqs1 = 0x00000028,
576 .dram_sdqs2 = 0x00000028,
577 .dram_sdqs3 = 0x00000028,
578 .dram_sdqs4 = 0x00000028,
579 .dram_sdqs5 = 0x00000028,
580 .dram_sdqs6 = 0x00000028,
581 .dram_sdqs7 = 0x00000028,
582 .dram_dqm0 = 0x00000028,
583 .dram_dqm1 = 0x00000028,
584 .dram_dqm2 = 0x00000028,
585 .dram_dqm3 = 0x00000028,
586 .dram_dqm4 = 0x00000028,
587 .dram_dqm5 = 0x00000028,
588 .dram_dqm6 = 0x00000028,
589 .dram_dqm7 = 0x00000028,
590};
591
592static const struct mx6dq_iomux_grp_regs mx6q_grp_ioregs = {
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300593 .grp_ddr_type = 0x000C0000,
594 .grp_ddrmode_ctl = 0x00020000,
595 .grp_ddrpke = 0x00000000,
596 .grp_addds = 0x00000030,
597 .grp_ctlds = 0x00000030,
598 .grp_ddrmode = 0x00020000,
599 .grp_b0ds = 0x00000030,
600 .grp_b1ds = 0x00000030,
601 .grp_b2ds = 0x00000030,
602 .grp_b3ds = 0x00000030,
603 .grp_b4ds = 0x00000030,
604 .grp_b5ds = 0x00000030,
605 .grp_b6ds = 0x00000030,
606 .grp_b7ds = 0x00000030,
607};
608
Fabio Estevam8cb68172015-04-25 18:47:18 -0300609static const struct mx6sdl_iomux_grp_regs mx6sdl_grp_ioregs = {
610 .grp_ddr_type = 0x000c0000,
611 .grp_ddrmode_ctl = 0x00020000,
612 .grp_ddrpke = 0x00000000,
613 .grp_addds = 0x00000028,
614 .grp_ctlds = 0x00000028,
615 .grp_ddrmode = 0x00020000,
616 .grp_b0ds = 0x00000028,
617 .grp_b1ds = 0x00000028,
618 .grp_b2ds = 0x00000028,
619 .grp_b3ds = 0x00000028,
620 .grp_b4ds = 0x00000028,
621 .grp_b5ds = 0x00000028,
622 .grp_b6ds = 0x00000028,
623 .grp_b7ds = 0x00000028,
624};
625
626/* microSOM with Dual processor and 1GB memory */
627static const struct mx6_mmdc_calibration mx6q_1g_mmcd_calib = {
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300628 .p0_mpwldectrl0 = 0x00000000,
629 .p0_mpwldectrl1 = 0x00000000,
630 .p1_mpwldectrl0 = 0x00000000,
631 .p1_mpwldectrl1 = 0x00000000,
632 .p0_mpdgctrl0 = 0x0314031c,
633 .p0_mpdgctrl1 = 0x023e0304,
634 .p1_mpdgctrl0 = 0x03240330,
635 .p1_mpdgctrl1 = 0x03180260,
636 .p0_mprddlctl = 0x3630323c,
637 .p1_mprddlctl = 0x3436283a,
638 .p0_mpwrdlctl = 0x36344038,
639 .p1_mpwrdlctl = 0x422a423c,
640};
641
Fabio Estevam8cb68172015-04-25 18:47:18 -0300642/* microSOM with Quad processor and 2GB memory */
643static const struct mx6_mmdc_calibration mx6q_2g_mmcd_calib = {
644 .p0_mpwldectrl0 = 0x00000000,
645 .p0_mpwldectrl1 = 0x00000000,
646 .p1_mpwldectrl0 = 0x00000000,
647 .p1_mpwldectrl1 = 0x00000000,
648 .p0_mpdgctrl0 = 0x0314031c,
649 .p0_mpdgctrl1 = 0x023e0304,
650 .p1_mpdgctrl0 = 0x03240330,
651 .p1_mpdgctrl1 = 0x03180260,
652 .p0_mprddlctl = 0x3630323c,
653 .p1_mprddlctl = 0x3436283a,
654 .p0_mpwrdlctl = 0x36344038,
655 .p1_mpwrdlctl = 0x422a423c,
656};
657
658/* microSOM with Solo processor and 512MB memory */
659static const struct mx6_mmdc_calibration mx6dl_512m_mmcd_calib = {
660 .p0_mpwldectrl0 = 0x0045004D,
661 .p0_mpwldectrl1 = 0x003A0047,
662 .p0_mpdgctrl0 = 0x023C0224,
663 .p0_mpdgctrl1 = 0x02000220,
664 .p0_mprddlctl = 0x44444846,
665 .p0_mpwrdlctl = 0x32343032,
666};
667
668/* microSOM with Dual lite processor and 1GB memory */
669static const struct mx6_mmdc_calibration mx6dl_1g_mmcd_calib = {
670 .p0_mpwldectrl0 = 0x0045004D,
671 .p0_mpwldectrl1 = 0x003A0047,
672 .p1_mpwldectrl0 = 0x001F001F,
673 .p1_mpwldectrl1 = 0x00210035,
674 .p0_mpdgctrl0 = 0x023C0224,
675 .p0_mpdgctrl1 = 0x02000220,
676 .p1_mpdgctrl0 = 0x02200220,
Fabio Estevamdbab8b82015-05-29 13:00:36 -0300677 .p1_mpdgctrl1 = 0x02040208,
Fabio Estevam8cb68172015-04-25 18:47:18 -0300678 .p0_mprddlctl = 0x44444846,
679 .p1_mprddlctl = 0x4042463C,
680 .p0_mpwrdlctl = 0x32343032,
681 .p1_mpwrdlctl = 0x36363430,
682};
683
684static struct mx6_ddr3_cfg mem_ddr_2g = {
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300685 .mem_speed = 1600,
686 .density = 2,
687 .width = 16,
688 .banks = 8,
689 .rowaddr = 14,
690 .coladdr = 10,
691 .pagesz = 2,
692 .trcd = 1375,
693 .trcmin = 4875,
694 .trasmin = 3500,
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300695};
696
Fabio Estevam8cb68172015-04-25 18:47:18 -0300697static struct mx6_ddr3_cfg mem_ddr_4g = {
698 .mem_speed = 1600,
699 .density = 4,
700 .width = 16,
701 .banks = 8,
Jon Nettleton51f957a2018-06-07 16:17:37 +0300702 .rowaddr = 16,
Fabio Estevam8cb68172015-04-25 18:47:18 -0300703 .coladdr = 10,
704 .pagesz = 2,
705 .trcd = 1375,
706 .trcmin = 4875,
707 .trasmin = 3500,
708};
709
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300710static void ccgr_init(void)
711{
712 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
713
714 writel(0x00C03F3F, &ccm->CCGR0);
715 writel(0x0030FC03, &ccm->CCGR1);
716 writel(0x0FFFC000, &ccm->CCGR2);
717 writel(0x3FF00000, &ccm->CCGR3);
718 writel(0x00FFF300, &ccm->CCGR4);
719 writel(0x0F0000C3, &ccm->CCGR5);
720 writel(0x000003FF, &ccm->CCGR6);
721}
722
Fabio Estevam8cb68172015-04-25 18:47:18 -0300723static void spl_dram_init(int width)
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300724{
725 struct mx6_ddr_sysinfo sysinfo = {
726 /* width of data bus: 0=16, 1=32, 2=64 */
Fabio Estevam8cb68172015-04-25 18:47:18 -0300727 .dsize = width / 32,
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300728 /* config for full 4GB range so that get_mem_size() works */
729 .cs_density = 32, /* 32Gb per CS */
730 .ncs = 1, /* single chip select */
731 .cs1_mirror = 0,
732 .rtt_wr = 1 /*DDR3_RTT_60_OHM*/, /* RTT_Wr = RZQ/4 */
733 .rtt_nom = 1 /*DDR3_RTT_60_OHM*/, /* RTT_Nom = RZQ/4 */
734 .walat = 1, /* Write additional latency */
735 .ralat = 5, /* Read additional latency */
736 .mif3_mode = 3, /* Command prediction working mode */
737 .bi_on = 1, /* Bank interleaving enabled */
738 .sde_to_rst = 0x10, /* 14 cycles, 200us (JEDEC default) */
739 .rst_to_cke = 0x23, /* 33 cycles, 500us (JEDEC default) */
Peng Fanf2ff8342015-08-17 16:11:03 +0800740 .ddr_type = DDR_TYPE_DDR3,
Fabio Estevamedf00932016-08-29 20:37:15 -0300741 .refsel = 1, /* Refresh cycles at 32KHz */
742 .refr = 7, /* 8 refresh commands per refresh cycle */
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300743 };
744
Breno Lima4a2f9012016-07-22 09:11:30 -0300745 if (is_mx6dq())
Fabio Estevam8cb68172015-04-25 18:47:18 -0300746 mx6dq_dram_iocfg(width, &mx6q_ddr_ioregs, &mx6q_grp_ioregs);
747 else
748 mx6sdl_dram_iocfg(width, &mx6dl_ddr_ioregs, &mx6sdl_grp_ioregs);
749
750 if (is_cpu_type(MXC_CPU_MX6D))
751 mx6_dram_cfg(&sysinfo, &mx6q_1g_mmcd_calib, &mem_ddr_2g);
752 else if (is_cpu_type(MXC_CPU_MX6Q))
753 mx6_dram_cfg(&sysinfo, &mx6q_2g_mmcd_calib, &mem_ddr_4g);
754 else if (is_cpu_type(MXC_CPU_MX6DL))
Fabio Estevamdbab8b82015-05-29 13:00:36 -0300755 mx6_dram_cfg(&sysinfo, &mx6dl_1g_mmcd_calib, &mem_ddr_2g);
Fabio Estevam8cb68172015-04-25 18:47:18 -0300756 else if (is_cpu_type(MXC_CPU_MX6SOLO))
757 mx6_dram_cfg(&sysinfo, &mx6dl_512m_mmcd_calib, &mem_ddr_2g);
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300758}
759
760void board_init_f(ulong dummy)
761{
762 /* setup AIPS and disable watchdog */
763 arch_cpu_init();
764
765 ccgr_init();
766 gpr_init();
767
768 /* iomux and setup of i2c */
769 board_early_init_f();
770
771 /* setup GP timer */
772 timer_init();
773
774 /* UART clocks enabled and gd valid - init serial console */
775 preloader_console_init();
776
777 /* DDR initialization */
Fabio Estevam8cb68172015-04-25 18:47:18 -0300778 if (is_cpu_type(MXC_CPU_MX6SOLO))
779 spl_dram_init(32);
780 else
781 spl_dram_init(64);
Fabio Estevamb8ce6fe2015-04-20 14:48:57 -0300782
783 /* Clear the BSS. */
784 memset(__bss_start, 0, __bss_end - __bss_start);
785
786 /* load/boot image from boot device */
787 board_init_r(NULL, 0);
788}
789#endif