blob: 8e0477c7a6e47b53e3f758572209a2726dca28e7 [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
Simon Glassadaaa482019-11-14 12:57:43 -07008#include <command.h>
Simon Glass07dc93c2019-08-01 09:46:47 -06009#include <env.h>
Simon Glassf11478f2019-12-28 10:45:07 -070010#include <hang.h>
Simon Glassa7b51302019-11-14 12:57:46 -070011#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Jagan Tekic5d86812017-05-07 02:43:14 +053013#include <mmc.h>
Michael Trimarchia81849f2019-12-30 17:34:03 +053014#include <asm/arch/clock.h>
15#include <asm/arch/imx-regs.h>
Jagan Tekic5d86812017-05-07 02:43:14 +053016#include <asm/arch/sys_proto.h>
Shyam Saini8e0fe1d2019-02-06 13:23:35 +053017#include <watchdog.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060018#include <asm/global_data.h>
Jagan Tekic5d86812017-05-07 02:43:14 +053019
20#include "board.h"
21
22DECLARE_GLOBAL_DATA_PTR;
23
24#ifdef CONFIG_ENV_IS_IN_MMC
Jagan Teki3ff7b932017-05-07 02:43:15 +053025static void mmc_late_init(void)
Jagan Tekic5d86812017-05-07 02:43:14 +053026{
27 char cmd[32];
28 char mmcblk[32];
29 u32 dev_no = mmc_get_env_dev();
30
Simon Glass4d949a22017-08-03 12:22:10 -060031 env_set_ulong("mmcdev", dev_no);
Jagan Tekic5d86812017-05-07 02:43:14 +053032
33 /* Set mmcblk env */
34 sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw", dev_no);
Simon Glass6a38e412017-08-03 12:22:09 -060035 env_set("mmcroot", mmcblk);
Jagan Tekic5d86812017-05-07 02:43:14 +053036
37 sprintf(cmd, "mmc dev %d", dev_no);
38 run_command(cmd, 0);
39}
40#endif
41
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053042enum engicam_boards {
43 IMX6Q_ICORE,
44 IMX6DL_ICORE,
45 IMX6Q_ICORE_MIPI,
46 IMX6DL_ICORE_MIPI,
47 IMX6Q_ICORE_RQS,
48 IMX6DL_ICORE_RQS,
49 IMX6UL_GEAM,
50 IMX6UL_ISIOT_EMMC,
51 IMX6UL_ISIOT_NAND,
52 ENGICAM_BOARDS,
53};
54
55static const char * const board_fdt_file[ENGICAM_BOARDS] = {
56 [IMX6Q_ICORE] = "imx6q-icore.dtb",
57 [IMX6DL_ICORE] = "imx6dl-icore.dtb",
58 [IMX6Q_ICORE_MIPI] = "imx6q-icore-mipi.dtb",
59 [IMX6DL_ICORE_MIPI] = "imx6dl-icore-mipi.dtb",
60 [IMX6Q_ICORE_RQS] = "imx6q-icore-rqs.dtb",
61 [IMX6DL_ICORE_RQS] = "imx6dl-icore-rqs.dtb",
62 [IMX6UL_GEAM] = "imx6ul-geam.dtb",
63 [IMX6UL_ISIOT_EMMC] = "imx6ul-isiot-emmc.dtb",
64 [IMX6UL_ISIOT_NAND] = "imx6ul-isiot-nand.dtb",
65};
66
67static int setenv_fdt_file(int board_detected)
68{
69 if (board_detected < 0 || board_detected >= ENGICAM_BOARDS)
70 return -EINVAL;
71
72 if (!board_fdt_file[board_detected])
73 return -ENODEV;
74
75 env_set("fdt_file", board_fdt_file[board_detected]);
76 return 0;
77}
78
79static enum engicam_boards engicam_board_detect(void)
Jagan Teki5479da62017-11-21 00:02:10 +053080{
81 const char *cmp_dtb = CONFIG_DEFAULT_DEVICE_TREE;
82
83 if (!strcmp(cmp_dtb, "imx6q-icore")) {
84 if (is_mx6dq())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053085 return IMX6Q_ICORE;
Jagan Teki6e4572f2018-01-06 00:02:04 +053086 else if (is_mx6dl() || is_mx6solo())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053087 return IMX6DL_ICORE;
Jagan Teki6e4572f2018-01-06 00:02:04 +053088 } else if (!strcmp(cmp_dtb, "imx6q-icore-mipi")) {
89 if (is_mx6dq())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053090 return IMX6Q_ICORE_MIPI;
Jagan Teki6e4572f2018-01-06 00:02:04 +053091 else if (is_mx6dl() || is_mx6solo())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053092 return IMX6DL_ICORE_MIPI;
Jagan Teki5479da62017-11-21 00:02:10 +053093 } else if (!strcmp(cmp_dtb, "imx6q-icore-rqs")) {
94 if (is_mx6dq())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053095 return IMX6Q_ICORE_RQS;
Jagan Teki6e4572f2018-01-06 00:02:04 +053096 else if (is_mx6dl() || is_mx6solo())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053097 return IMX6DL_ICORE_RQS;
Jagan Tekib10b3b52018-06-18 11:12:19 +053098 } else if (!strcmp(cmp_dtb, "imx6ul-geam"))
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053099 return IMX6UL_GEAM;
Jagan Teki5479da62017-11-21 00:02:10 +0530100 else if (!strcmp(cmp_dtb, "imx6ul-isiot-emmc"))
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +0530101 return IMX6UL_ISIOT_EMMC;
Jagan Teki5479da62017-11-21 00:02:10 +0530102 else if (!strcmp(cmp_dtb, "imx6ul-isiot-nand"))
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +0530103 return IMX6UL_ISIOT_NAND;
104
105 return -EINVAL;
Jagan Teki5479da62017-11-21 00:02:10 +0530106}
107
Michael Trimarchia81849f2019-12-30 17:34:03 +0530108static int fixup_enet_clock(enum engicam_boards board_detected)
109{
110 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
111 int clk_internal = 0;
112
113 switch (board_detected) {
114 case IMX6Q_ICORE_MIPI:
115 case IMX6DL_ICORE_MIPI:
116 clk_internal = 1;
117 break;
118 default:
119 break;
120 }
121
122 /* set gpr1[21] to select anatop clock */
123 debug("fixup_enet_clock %d\n", clk_internal);
124 clrsetbits_le32(&iomuxc_regs->gpr[1], 0x1 << 21, clk_internal << 21);
125
126 if (!clk_internal) {
127 /* clock is external */
128 return 0;
129 }
130
131 return enable_fec_anatop_clock(0, ENET_50MHZ);
132}
133
Jagan Teki3ff7b932017-05-07 02:43:15 +0530134int board_late_init(void)
135{
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +0530136 enum engicam_boards board_detected = IMX6Q_ICORE;
137
Jagan Teki3ff7b932017-05-07 02:43:15 +0530138 switch ((imx6_src_get_boot_mode() & IMX6_BMODE_MASK) >>
139 IMX6_BMODE_SHIFT) {
140 case IMX6_BMODE_SD:
141 case IMX6_BMODE_ESD:
142 case IMX6_BMODE_MMC:
143 case IMX6_BMODE_EMMC:
144#ifdef CONFIG_ENV_IS_IN_MMC
145 mmc_late_init();
146#endif
Simon Glass6a38e412017-08-03 12:22:09 -0600147 env_set("modeboot", "mmcboot");
Jagan Teki3ff7b932017-05-07 02:43:15 +0530148 break;
Eran Matityahu5fa7ca62017-12-14 20:20:02 +0200149 case IMX6_BMODE_NAND_MIN ... IMX6_BMODE_NAND_MAX:
Simon Glass6a38e412017-08-03 12:22:09 -0600150 env_set("modeboot", "nandboot");
Jagan Teki3ff7b932017-05-07 02:43:15 +0530151 break;
152 default:
Simon Glass6a38e412017-08-03 12:22:09 -0600153 env_set("modeboot", "");
Jagan Teki3ff7b932017-05-07 02:43:15 +0530154 break;
155 }
156
Jagan Teki388a9042017-05-12 17:18:26 +0530157 if (is_mx6ul())
Simon Glass6a38e412017-08-03 12:22:09 -0600158 env_set("console", "ttymxc0");
Jagan Teki388a9042017-05-12 17:18:26 +0530159 else
Simon Glass6a38e412017-08-03 12:22:09 -0600160 env_set("console", "ttymxc3");
Jagan Teki388a9042017-05-12 17:18:26 +0530161
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +0530162 board_detected = engicam_board_detect();
163 if (board_detected < 0)
164 hang();
165
Michael Trimarchia81849f2019-12-30 17:34:03 +0530166 fixup_enet_clock(board_detected);
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +0530167 setenv_fdt_file(board_detected);
Jagan Teki3ff7b932017-05-07 02:43:15 +0530168
Shyam Saini8e0fe1d2019-02-06 13:23:35 +0530169#ifdef CONFIG_HW_WATCHDOG
170 hw_watchdog_init();
171#endif
172
Jagan Teki3ff7b932017-05-07 02:43:15 +0530173 return 0;
174}
175
Jagan Tekic5d86812017-05-07 02:43:14 +0530176int board_init(void)
177{
178 /* Address of boot parameters */
179 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
180
181#ifdef CONFIG_NAND_MXS
182 setup_gpmi_nand();
183#endif
184
185#ifdef CONFIG_VIDEO_IPUV3
186 setup_display();
187#endif
188
189 return 0;
190}
191
192int dram_init(void)
193{
194 gd->ram_size = imx_ddr_size();
195
196 return 0;
197}