blob: 6472d382c93581c471ef6b4214cb5fa0811b9287 [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>
Michael Trimarchia81849f2019-12-30 17:34:03 +053013#include <asm/arch/clock.h>
14#include <asm/arch/imx-regs.h>
Jagan Tekic5d86812017-05-07 02:43:14 +053015#include <asm/arch/sys_proto.h>
Shyam Saini8e0fe1d2019-02-06 13:23:35 +053016#include <watchdog.h>
Jagan Tekic5d86812017-05-07 02:43:14 +053017
18#include "board.h"
19
20DECLARE_GLOBAL_DATA_PTR;
21
22#ifdef CONFIG_ENV_IS_IN_MMC
Jagan Teki3ff7b932017-05-07 02:43:15 +053023static void mmc_late_init(void)
Jagan Tekic5d86812017-05-07 02:43:14 +053024{
25 char cmd[32];
26 char mmcblk[32];
27 u32 dev_no = mmc_get_env_dev();
28
Simon Glass4d949a22017-08-03 12:22:10 -060029 env_set_ulong("mmcdev", dev_no);
Jagan Tekic5d86812017-05-07 02:43:14 +053030
31 /* Set mmcblk env */
32 sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw", dev_no);
Simon Glass6a38e412017-08-03 12:22:09 -060033 env_set("mmcroot", mmcblk);
Jagan Tekic5d86812017-05-07 02:43:14 +053034
35 sprintf(cmd, "mmc dev %d", dev_no);
36 run_command(cmd, 0);
37}
38#endif
39
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053040enum engicam_boards {
41 IMX6Q_ICORE,
42 IMX6DL_ICORE,
43 IMX6Q_ICORE_MIPI,
44 IMX6DL_ICORE_MIPI,
45 IMX6Q_ICORE_RQS,
46 IMX6DL_ICORE_RQS,
47 IMX6UL_GEAM,
48 IMX6UL_ISIOT_EMMC,
49 IMX6UL_ISIOT_NAND,
50 ENGICAM_BOARDS,
51};
52
53static const char * const board_fdt_file[ENGICAM_BOARDS] = {
54 [IMX6Q_ICORE] = "imx6q-icore.dtb",
55 [IMX6DL_ICORE] = "imx6dl-icore.dtb",
56 [IMX6Q_ICORE_MIPI] = "imx6q-icore-mipi.dtb",
57 [IMX6DL_ICORE_MIPI] = "imx6dl-icore-mipi.dtb",
58 [IMX6Q_ICORE_RQS] = "imx6q-icore-rqs.dtb",
59 [IMX6DL_ICORE_RQS] = "imx6dl-icore-rqs.dtb",
60 [IMX6UL_GEAM] = "imx6ul-geam.dtb",
61 [IMX6UL_ISIOT_EMMC] = "imx6ul-isiot-emmc.dtb",
62 [IMX6UL_ISIOT_NAND] = "imx6ul-isiot-nand.dtb",
63};
64
65static int setenv_fdt_file(int board_detected)
66{
67 if (board_detected < 0 || board_detected >= ENGICAM_BOARDS)
68 return -EINVAL;
69
70 if (!board_fdt_file[board_detected])
71 return -ENODEV;
72
73 env_set("fdt_file", board_fdt_file[board_detected]);
74 return 0;
75}
76
77static enum engicam_boards engicam_board_detect(void)
Jagan Teki5479da62017-11-21 00:02:10 +053078{
79 const char *cmp_dtb = CONFIG_DEFAULT_DEVICE_TREE;
80
81 if (!strcmp(cmp_dtb, "imx6q-icore")) {
82 if (is_mx6dq())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053083 return IMX6Q_ICORE;
Jagan Teki6e4572f2018-01-06 00:02:04 +053084 else if (is_mx6dl() || is_mx6solo())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053085 return IMX6DL_ICORE;
Jagan Teki6e4572f2018-01-06 00:02:04 +053086 } else if (!strcmp(cmp_dtb, "imx6q-icore-mipi")) {
87 if (is_mx6dq())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053088 return IMX6Q_ICORE_MIPI;
Jagan Teki6e4572f2018-01-06 00:02:04 +053089 else if (is_mx6dl() || is_mx6solo())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053090 return IMX6DL_ICORE_MIPI;
Jagan Teki5479da62017-11-21 00:02:10 +053091 } else if (!strcmp(cmp_dtb, "imx6q-icore-rqs")) {
92 if (is_mx6dq())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053093 return IMX6Q_ICORE_RQS;
Jagan Teki6e4572f2018-01-06 00:02:04 +053094 else if (is_mx6dl() || is_mx6solo())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053095 return IMX6DL_ICORE_RQS;
Jagan Tekib10b3b52018-06-18 11:12:19 +053096 } else if (!strcmp(cmp_dtb, "imx6ul-geam"))
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053097 return IMX6UL_GEAM;
Jagan Teki5479da62017-11-21 00:02:10 +053098 else if (!strcmp(cmp_dtb, "imx6ul-isiot-emmc"))
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053099 return IMX6UL_ISIOT_EMMC;
Jagan Teki5479da62017-11-21 00:02:10 +0530100 else if (!strcmp(cmp_dtb, "imx6ul-isiot-nand"))
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +0530101 return IMX6UL_ISIOT_NAND;
102
103 return -EINVAL;
Jagan Teki5479da62017-11-21 00:02:10 +0530104}
105
Michael Trimarchia81849f2019-12-30 17:34:03 +0530106static int fixup_enet_clock(enum engicam_boards board_detected)
107{
108 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
109 int clk_internal = 0;
110
111 switch (board_detected) {
112 case IMX6Q_ICORE_MIPI:
113 case IMX6DL_ICORE_MIPI:
114 clk_internal = 1;
115 break;
116 default:
117 break;
118 }
119
120 /* set gpr1[21] to select anatop clock */
121 debug("fixup_enet_clock %d\n", clk_internal);
122 clrsetbits_le32(&iomuxc_regs->gpr[1], 0x1 << 21, clk_internal << 21);
123
124 if (!clk_internal) {
125 /* clock is external */
126 return 0;
127 }
128
129 return enable_fec_anatop_clock(0, ENET_50MHZ);
130}
131
Jagan Teki3ff7b932017-05-07 02:43:15 +0530132int board_late_init(void)
133{
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +0530134 enum engicam_boards board_detected = IMX6Q_ICORE;
135
Jagan Teki3ff7b932017-05-07 02:43:15 +0530136 switch ((imx6_src_get_boot_mode() & IMX6_BMODE_MASK) >>
137 IMX6_BMODE_SHIFT) {
138 case IMX6_BMODE_SD:
139 case IMX6_BMODE_ESD:
140 case IMX6_BMODE_MMC:
141 case IMX6_BMODE_EMMC:
142#ifdef CONFIG_ENV_IS_IN_MMC
143 mmc_late_init();
144#endif
Simon Glass6a38e412017-08-03 12:22:09 -0600145 env_set("modeboot", "mmcboot");
Jagan Teki3ff7b932017-05-07 02:43:15 +0530146 break;
Eran Matityahu5fa7ca62017-12-14 20:20:02 +0200147 case IMX6_BMODE_NAND_MIN ... IMX6_BMODE_NAND_MAX:
Simon Glass6a38e412017-08-03 12:22:09 -0600148 env_set("modeboot", "nandboot");
Jagan Teki3ff7b932017-05-07 02:43:15 +0530149 break;
150 default:
Simon Glass6a38e412017-08-03 12:22:09 -0600151 env_set("modeboot", "");
Jagan Teki3ff7b932017-05-07 02:43:15 +0530152 break;
153 }
154
Jagan Teki388a9042017-05-12 17:18:26 +0530155 if (is_mx6ul())
Simon Glass6a38e412017-08-03 12:22:09 -0600156 env_set("console", "ttymxc0");
Jagan Teki388a9042017-05-12 17:18:26 +0530157 else
Simon Glass6a38e412017-08-03 12:22:09 -0600158 env_set("console", "ttymxc3");
Jagan Teki388a9042017-05-12 17:18:26 +0530159
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +0530160 board_detected = engicam_board_detect();
161 if (board_detected < 0)
162 hang();
163
Michael Trimarchia81849f2019-12-30 17:34:03 +0530164 fixup_enet_clock(board_detected);
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +0530165 setenv_fdt_file(board_detected);
Jagan Teki3ff7b932017-05-07 02:43:15 +0530166
Shyam Saini8e0fe1d2019-02-06 13:23:35 +0530167#ifdef CONFIG_HW_WATCHDOG
168 hw_watchdog_init();
169#endif
170
Jagan Teki3ff7b932017-05-07 02:43:15 +0530171 return 0;
172}
173
Jagan Tekic5d86812017-05-07 02:43:14 +0530174int board_init(void)
175{
176 /* Address of boot parameters */
177 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
178
179#ifdef CONFIG_NAND_MXS
180 setup_gpmi_nand();
181#endif
182
183#ifdef CONFIG_VIDEO_IPUV3
184 setup_display();
185#endif
186
187 return 0;
188}
189
190int dram_init(void)
191{
192 gd->ram_size = imx_ddr_size();
193
194 return 0;
195}