blob: 9483516ca0dbaedfa51a7642426b8964fe4b93f3 [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 Glassf11478f2019-12-28 10:45:07 -070011#include <hang.h>
Simon Glassa7b51302019-11-14 12:57:46 -070012#include <init.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>
Jagan Tekic5d86812017-05-07 02:43:14 +053018
19#include "board.h"
20
21DECLARE_GLOBAL_DATA_PTR;
22
23#ifdef CONFIG_ENV_IS_IN_MMC
Jagan Teki3ff7b932017-05-07 02:43:15 +053024static void mmc_late_init(void)
Jagan Tekic5d86812017-05-07 02:43:14 +053025{
26 char cmd[32];
27 char mmcblk[32];
28 u32 dev_no = mmc_get_env_dev();
29
Simon Glass4d949a22017-08-03 12:22:10 -060030 env_set_ulong("mmcdev", dev_no);
Jagan Tekic5d86812017-05-07 02:43:14 +053031
32 /* Set mmcblk env */
33 sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw", dev_no);
Simon Glass6a38e412017-08-03 12:22:09 -060034 env_set("mmcroot", mmcblk);
Jagan Tekic5d86812017-05-07 02:43:14 +053035
36 sprintf(cmd, "mmc dev %d", dev_no);
37 run_command(cmd, 0);
38}
39#endif
40
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053041enum engicam_boards {
42 IMX6Q_ICORE,
43 IMX6DL_ICORE,
44 IMX6Q_ICORE_MIPI,
45 IMX6DL_ICORE_MIPI,
46 IMX6Q_ICORE_RQS,
47 IMX6DL_ICORE_RQS,
48 IMX6UL_GEAM,
49 IMX6UL_ISIOT_EMMC,
50 IMX6UL_ISIOT_NAND,
51 ENGICAM_BOARDS,
52};
53
54static const char * const board_fdt_file[ENGICAM_BOARDS] = {
55 [IMX6Q_ICORE] = "imx6q-icore.dtb",
56 [IMX6DL_ICORE] = "imx6dl-icore.dtb",
57 [IMX6Q_ICORE_MIPI] = "imx6q-icore-mipi.dtb",
58 [IMX6DL_ICORE_MIPI] = "imx6dl-icore-mipi.dtb",
59 [IMX6Q_ICORE_RQS] = "imx6q-icore-rqs.dtb",
60 [IMX6DL_ICORE_RQS] = "imx6dl-icore-rqs.dtb",
61 [IMX6UL_GEAM] = "imx6ul-geam.dtb",
62 [IMX6UL_ISIOT_EMMC] = "imx6ul-isiot-emmc.dtb",
63 [IMX6UL_ISIOT_NAND] = "imx6ul-isiot-nand.dtb",
64};
65
66static int setenv_fdt_file(int board_detected)
67{
68 if (board_detected < 0 || board_detected >= ENGICAM_BOARDS)
69 return -EINVAL;
70
71 if (!board_fdt_file[board_detected])
72 return -ENODEV;
73
74 env_set("fdt_file", board_fdt_file[board_detected]);
75 return 0;
76}
77
78static enum engicam_boards engicam_board_detect(void)
Jagan Teki5479da62017-11-21 00:02:10 +053079{
80 const char *cmp_dtb = CONFIG_DEFAULT_DEVICE_TREE;
81
82 if (!strcmp(cmp_dtb, "imx6q-icore")) {
83 if (is_mx6dq())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053084 return IMX6Q_ICORE;
Jagan Teki6e4572f2018-01-06 00:02:04 +053085 else if (is_mx6dl() || is_mx6solo())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053086 return IMX6DL_ICORE;
Jagan Teki6e4572f2018-01-06 00:02:04 +053087 } else if (!strcmp(cmp_dtb, "imx6q-icore-mipi")) {
88 if (is_mx6dq())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053089 return IMX6Q_ICORE_MIPI;
Jagan Teki6e4572f2018-01-06 00:02:04 +053090 else if (is_mx6dl() || is_mx6solo())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053091 return IMX6DL_ICORE_MIPI;
Jagan Teki5479da62017-11-21 00:02:10 +053092 } else if (!strcmp(cmp_dtb, "imx6q-icore-rqs")) {
93 if (is_mx6dq())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053094 return IMX6Q_ICORE_RQS;
Jagan Teki6e4572f2018-01-06 00:02:04 +053095 else if (is_mx6dl() || is_mx6solo())
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053096 return IMX6DL_ICORE_RQS;
Jagan Tekib10b3b52018-06-18 11:12:19 +053097 } else if (!strcmp(cmp_dtb, "imx6ul-geam"))
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +053098 return IMX6UL_GEAM;
Jagan Teki5479da62017-11-21 00:02:10 +053099 else if (!strcmp(cmp_dtb, "imx6ul-isiot-emmc"))
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +0530100 return IMX6UL_ISIOT_EMMC;
Jagan Teki5479da62017-11-21 00:02:10 +0530101 else if (!strcmp(cmp_dtb, "imx6ul-isiot-nand"))
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +0530102 return IMX6UL_ISIOT_NAND;
103
104 return -EINVAL;
Jagan Teki5479da62017-11-21 00:02:10 +0530105}
106
Michael Trimarchia81849f2019-12-30 17:34:03 +0530107static int fixup_enet_clock(enum engicam_boards board_detected)
108{
109 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
110 int clk_internal = 0;
111
112 switch (board_detected) {
113 case IMX6Q_ICORE_MIPI:
114 case IMX6DL_ICORE_MIPI:
115 clk_internal = 1;
116 break;
117 default:
118 break;
119 }
120
121 /* set gpr1[21] to select anatop clock */
122 debug("fixup_enet_clock %d\n", clk_internal);
123 clrsetbits_le32(&iomuxc_regs->gpr[1], 0x1 << 21, clk_internal << 21);
124
125 if (!clk_internal) {
126 /* clock is external */
127 return 0;
128 }
129
130 return enable_fec_anatop_clock(0, ENET_50MHZ);
131}
132
Jagan Teki3ff7b932017-05-07 02:43:15 +0530133int board_late_init(void)
134{
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +0530135 enum engicam_boards board_detected = IMX6Q_ICORE;
136
Jagan Teki3ff7b932017-05-07 02:43:15 +0530137 switch ((imx6_src_get_boot_mode() & IMX6_BMODE_MASK) >>
138 IMX6_BMODE_SHIFT) {
139 case IMX6_BMODE_SD:
140 case IMX6_BMODE_ESD:
141 case IMX6_BMODE_MMC:
142 case IMX6_BMODE_EMMC:
143#ifdef CONFIG_ENV_IS_IN_MMC
144 mmc_late_init();
145#endif
Simon Glass6a38e412017-08-03 12:22:09 -0600146 env_set("modeboot", "mmcboot");
Jagan Teki3ff7b932017-05-07 02:43:15 +0530147 break;
Eran Matityahu5fa7ca62017-12-14 20:20:02 +0200148 case IMX6_BMODE_NAND_MIN ... IMX6_BMODE_NAND_MAX:
Simon Glass6a38e412017-08-03 12:22:09 -0600149 env_set("modeboot", "nandboot");
Jagan Teki3ff7b932017-05-07 02:43:15 +0530150 break;
151 default:
Simon Glass6a38e412017-08-03 12:22:09 -0600152 env_set("modeboot", "");
Jagan Teki3ff7b932017-05-07 02:43:15 +0530153 break;
154 }
155
Jagan Teki388a9042017-05-12 17:18:26 +0530156 if (is_mx6ul())
Simon Glass6a38e412017-08-03 12:22:09 -0600157 env_set("console", "ttymxc0");
Jagan Teki388a9042017-05-12 17:18:26 +0530158 else
Simon Glass6a38e412017-08-03 12:22:09 -0600159 env_set("console", "ttymxc3");
Jagan Teki388a9042017-05-12 17:18:26 +0530160
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +0530161 board_detected = engicam_board_detect();
162 if (board_detected < 0)
163 hang();
164
Michael Trimarchia81849f2019-12-30 17:34:03 +0530165 fixup_enet_clock(board_detected);
Michael Trimarchi5b1b2a32019-12-30 17:34:02 +0530166 setenv_fdt_file(board_detected);
Jagan Teki3ff7b932017-05-07 02:43:15 +0530167
Shyam Saini8e0fe1d2019-02-06 13:23:35 +0530168#ifdef CONFIG_HW_WATCHDOG
169 hw_watchdog_init();
170#endif
171
Jagan Teki3ff7b932017-05-07 02:43:15 +0530172 return 0;
173}
174
Jagan Tekic5d86812017-05-07 02:43:14 +0530175int board_init(void)
176{
177 /* Address of boot parameters */
178 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
179
180#ifdef CONFIG_NAND_MXS
181 setup_gpmi_nand();
182#endif
183
184#ifdef CONFIG_VIDEO_IPUV3
185 setup_display();
186#endif
187
188 return 0;
189}
190
191int dram_init(void)
192{
193 gd->ram_size = imx_ddr_size();
194
195 return 0;
196}