blob: 992d209cbd0a3db2b2895e36c6747175a9e99b77 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jagan Tekic5d86812017-05-07 02:43:14 +05302/*
3 * Copyright (C) 2016 Amarula Solutions B.V.
4 * Copyright (C) 2016 Engicam S.r.l.
5 * Author: Jagan Teki <jagan@amarulasolutions.com>
Jagan Tekic5d86812017-05-07 02:43:14 +05306 */
7
8#include <common.h>
Simon Glassadaaa482019-11-14 12:57:43 -07009#include <command.h>
Simon Glass07dc93c2019-08-01 09:46:47 -060010#include <env.h>
Simon Glassa7b51302019-11-14 12:57:46 -070011#include <init.h>
Jagan Tekic5d86812017-05-07 02:43:14 +053012#include <mmc.h>
13#include <asm/arch/sys_proto.h>
Shyam Saini8e0fe1d2019-02-06 13:23:35 +053014#include <watchdog.h>
Jagan Tekic5d86812017-05-07 02:43:14 +053015
16#include "board.h"
17
18DECLARE_GLOBAL_DATA_PTR;
19
20#ifdef CONFIG_ENV_IS_IN_MMC
Jagan Teki3ff7b932017-05-07 02:43:15 +053021static void mmc_late_init(void)
Jagan Tekic5d86812017-05-07 02:43:14 +053022{
23 char cmd[32];
24 char mmcblk[32];
25 u32 dev_no = mmc_get_env_dev();
26
Simon Glass4d949a22017-08-03 12:22:10 -060027 env_set_ulong("mmcdev", dev_no);
Jagan Tekic5d86812017-05-07 02:43:14 +053028
29 /* Set mmcblk env */
30 sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw", dev_no);
Simon Glass6a38e412017-08-03 12:22:09 -060031 env_set("mmcroot", mmcblk);
Jagan Tekic5d86812017-05-07 02:43:14 +053032
33 sprintf(cmd, "mmc dev %d", dev_no);
34 run_command(cmd, 0);
35}
36#endif
37
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053038enum engicam_boards {
39 IMX6Q_ICORE,
40 IMX6DL_ICORE,
41 IMX6Q_ICORE_MIPI,
42 IMX6DL_ICORE_MIPI,
43 IMX6Q_ICORE_RQS,
44 IMX6DL_ICORE_RQS,
45 IMX6UL_GEAM,
46 IMX6UL_ISIOT_EMMC,
47 IMX6UL_ISIOT_NAND,
48 ENGICAM_BOARDS,
49};
50
51static const char * const board_fdt_file[ENGICAM_BOARDS] = {
52 [IMX6Q_ICORE] = "imx6q-icore.dtb",
53 [IMX6DL_ICORE] = "imx6dl-icore.dtb",
54 [IMX6Q_ICORE_MIPI] = "imx6q-icore-mipi.dtb",
55 [IMX6DL_ICORE_MIPI] = "imx6dl-icore-mipi.dtb",
56 [IMX6Q_ICORE_RQS] = "imx6q-icore-rqs.dtb",
57 [IMX6DL_ICORE_RQS] = "imx6dl-icore-rqs.dtb",
58 [IMX6UL_GEAM] = "imx6ul-geam.dtb",
59 [IMX6UL_ISIOT_EMMC] = "imx6ul-isiot-emmc.dtb",
60 [IMX6UL_ISIOT_NAND] = "imx6ul-isiot-nand.dtb",
61};
62
63static int setenv_fdt_file(int board_detected)
64{
65 if (board_detected < 0 || board_detected >= ENGICAM_BOARDS)
66 return -EINVAL;
67
68 if (!board_fdt_file[board_detected])
69 return -ENODEV;
70
71 env_set("fdt_file", board_fdt_file[board_detected]);
72 return 0;
73}
74
75static enum engicam_boards engicam_board_detect(void)
Jagan Teki5479da62017-11-21 00:02:10 +053076{
77 const char *cmp_dtb = CONFIG_DEFAULT_DEVICE_TREE;
78
79 if (!strcmp(cmp_dtb, "imx6q-icore")) {
80 if (is_mx6dq())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053081 return IMX6Q_ICORE;
Jagan Teki6e4572f2018-01-06 00:02:04 +053082 else if (is_mx6dl() || is_mx6solo())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053083 return IMX6DL_ICORE;
Jagan Teki6e4572f2018-01-06 00:02:04 +053084 } else if (!strcmp(cmp_dtb, "imx6q-icore-mipi")) {
85 if (is_mx6dq())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053086 return IMX6Q_ICORE_MIPI;
Jagan Teki6e4572f2018-01-06 00:02:04 +053087 else if (is_mx6dl() || is_mx6solo())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053088 return IMX6DL_ICORE_MIPI;
Jagan Teki5479da62017-11-21 00:02:10 +053089 } else if (!strcmp(cmp_dtb, "imx6q-icore-rqs")) {
90 if (is_mx6dq())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053091 return IMX6Q_ICORE_RQS;
Jagan Teki6e4572f2018-01-06 00:02:04 +053092 else if (is_mx6dl() || is_mx6solo())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053093 return IMX6DL_ICORE_RQS;
Jagan Tekib10b3b52018-06-18 11:12:19 +053094 } else if (!strcmp(cmp_dtb, "imx6ul-geam"))
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053095 return IMX6UL_GEAM;
Jagan Teki5479da62017-11-21 00:02:10 +053096 else if (!strcmp(cmp_dtb, "imx6ul-isiot-emmc"))
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053097 return IMX6UL_ISIOT_EMMC;
Jagan Teki5479da62017-11-21 00:02:10 +053098 else if (!strcmp(cmp_dtb, "imx6ul-isiot-nand"))
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053099 return IMX6UL_ISIOT_NAND;
100
101 return -EINVAL;
Jagan Teki5479da62017-11-21 00:02:10 +0530102}
103
Jagan Teki3ff7b932017-05-07 02:43:15 +0530104int board_late_init(void)
105{
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +0530106 enum engicam_boards board_detected = IMX6Q_ICORE;
107
Jagan Teki3ff7b932017-05-07 02:43:15 +0530108 switch ((imx6_src_get_boot_mode() & IMX6_BMODE_MASK) >>
109 IMX6_BMODE_SHIFT) {
110 case IMX6_BMODE_SD:
111 case IMX6_BMODE_ESD:
112 case IMX6_BMODE_MMC:
113 case IMX6_BMODE_EMMC:
114#ifdef CONFIG_ENV_IS_IN_MMC
115 mmc_late_init();
116#endif
Simon Glass6a38e412017-08-03 12:22:09 -0600117 env_set("modeboot", "mmcboot");
Jagan Teki3ff7b932017-05-07 02:43:15 +0530118 break;
Eran Matityahu5fa7ca62017-12-14 20:20:02 +0200119 case IMX6_BMODE_NAND_MIN ... IMX6_BMODE_NAND_MAX:
Simon Glass6a38e412017-08-03 12:22:09 -0600120 env_set("modeboot", "nandboot");
Jagan Teki3ff7b932017-05-07 02:43:15 +0530121 break;
122 default:
Simon Glass6a38e412017-08-03 12:22:09 -0600123 env_set("modeboot", "");
Jagan Teki3ff7b932017-05-07 02:43:15 +0530124 break;
125 }
126
Jagan Teki388a9042017-05-12 17:18:26 +0530127 if (is_mx6ul())
Simon Glass6a38e412017-08-03 12:22:09 -0600128 env_set("console", "ttymxc0");
Jagan Teki388a9042017-05-12 17:18:26 +0530129 else
Simon Glass6a38e412017-08-03 12:22:09 -0600130 env_set("console", "ttymxc3");
Jagan Teki388a9042017-05-12 17:18:26 +0530131
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +0530132 board_detected = engicam_board_detect();
133 if (board_detected < 0)
134 hang();
135
136 setenv_fdt_file(board_detected);
Jagan Teki3ff7b932017-05-07 02:43:15 +0530137
Shyam Saini8e0fe1d2019-02-06 13:23:35 +0530138#ifdef CONFIG_HW_WATCHDOG
139 hw_watchdog_init();
140#endif
141
Jagan Teki3ff7b932017-05-07 02:43:15 +0530142 return 0;
143}
144
Jagan Tekic5d86812017-05-07 02:43:14 +0530145int board_init(void)
146{
147 /* Address of boot parameters */
148 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
149
150#ifdef CONFIG_NAND_MXS
151 setup_gpmi_nand();
152#endif
153
154#ifdef CONFIG_VIDEO_IPUV3
155 setup_display();
156#endif
157
158 return 0;
159}
160
161int dram_init(void)
162{
163 gd->ram_size = imx_ddr_size();
164
165 return 0;
166}