blob: df9149e0d6d857fa7276ec39d1868df60d7f1d56 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jagan Tekiac880e72017-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 Tekiac880e72017-05-07 02:43:14 +05306 */
7
8#include <common.h>
Simon Glass288b29e2019-11-14 12:57:43 -07009#include <command.h>
Simon Glass168068f2019-08-01 09:46:47 -060010#include <env.h>
Simon Glassdb41d652019-12-28 10:45:07 -070011#include <hang.h>
Simon Glass52559322019-11-14 12:57:46 -070012#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060013#include <log.h>
Jagan Tekiac880e72017-05-07 02:43:14 +053014#include <mmc.h>
Michael Trimarchi90d46652019-12-30 17:34:03 +053015#include <asm/arch/clock.h>
16#include <asm/arch/imx-regs.h>
Jagan Tekiac880e72017-05-07 02:43:14 +053017#include <asm/arch/sys_proto.h>
Shyam Saini74bf9322019-02-06 13:23:35 +053018#include <watchdog.h>
Simon Glass401d1c42020-10-30 21:38:53 -060019#include <asm/global_data.h>
Jagan Tekiac880e72017-05-07 02:43:14 +053020
21#include "board.h"
22
23DECLARE_GLOBAL_DATA_PTR;
24
25#ifdef CONFIG_ENV_IS_IN_MMC
Jagan Tekif9247562017-05-07 02:43:15 +053026static void mmc_late_init(void)
Jagan Tekiac880e72017-05-07 02:43:14 +053027{
28 char cmd[32];
29 char mmcblk[32];
30 u32 dev_no = mmc_get_env_dev();
31
Simon Glass018f5302017-08-03 12:22:10 -060032 env_set_ulong("mmcdev", dev_no);
Jagan Tekiac880e72017-05-07 02:43:14 +053033
34 /* Set mmcblk env */
35 sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw", dev_no);
Simon Glass382bee52017-08-03 12:22:09 -060036 env_set("mmcroot", mmcblk);
Jagan Tekiac880e72017-05-07 02:43:14 +053037
38 sprintf(cmd, "mmc dev %d", dev_no);
39 run_command(cmd, 0);
40}
41#endif
42
Michael Trimarchi8811c4d2019-12-30 17:34:02 +053043enum engicam_boards {
44 IMX6Q_ICORE,
45 IMX6DL_ICORE,
46 IMX6Q_ICORE_MIPI,
47 IMX6DL_ICORE_MIPI,
48 IMX6Q_ICORE_RQS,
49 IMX6DL_ICORE_RQS,
50 IMX6UL_GEAM,
51 IMX6UL_ISIOT_EMMC,
52 IMX6UL_ISIOT_NAND,
53 ENGICAM_BOARDS,
54};
55
56static const char * const board_fdt_file[ENGICAM_BOARDS] = {
57 [IMX6Q_ICORE] = "imx6q-icore.dtb",
58 [IMX6DL_ICORE] = "imx6dl-icore.dtb",
59 [IMX6Q_ICORE_MIPI] = "imx6q-icore-mipi.dtb",
60 [IMX6DL_ICORE_MIPI] = "imx6dl-icore-mipi.dtb",
61 [IMX6Q_ICORE_RQS] = "imx6q-icore-rqs.dtb",
62 [IMX6DL_ICORE_RQS] = "imx6dl-icore-rqs.dtb",
63 [IMX6UL_GEAM] = "imx6ul-geam.dtb",
64 [IMX6UL_ISIOT_EMMC] = "imx6ul-isiot-emmc.dtb",
65 [IMX6UL_ISIOT_NAND] = "imx6ul-isiot-nand.dtb",
66};
67
68static int setenv_fdt_file(int board_detected)
69{
70 if (board_detected < 0 || board_detected >= ENGICAM_BOARDS)
71 return -EINVAL;
72
73 if (!board_fdt_file[board_detected])
74 return -ENODEV;
75
76 env_set("fdt_file", board_fdt_file[board_detected]);
77 return 0;
78}
79
80static enum engicam_boards engicam_board_detect(void)
Jagan Teki409b16d2017-11-21 00:02:10 +053081{
82 const char *cmp_dtb = CONFIG_DEFAULT_DEVICE_TREE;
83
84 if (!strcmp(cmp_dtb, "imx6q-icore")) {
85 if (is_mx6dq())
Michael Trimarchi8811c4d2019-12-30 17:34:02 +053086 return IMX6Q_ICORE;
Jagan Teki04c28a72018-01-06 00:02:04 +053087 else if (is_mx6dl() || is_mx6solo())
Michael Trimarchi8811c4d2019-12-30 17:34:02 +053088 return IMX6DL_ICORE;
Jagan Teki04c28a72018-01-06 00:02:04 +053089 } else if (!strcmp(cmp_dtb, "imx6q-icore-mipi")) {
90 if (is_mx6dq())
Michael Trimarchi8811c4d2019-12-30 17:34:02 +053091 return IMX6Q_ICORE_MIPI;
Jagan Teki04c28a72018-01-06 00:02:04 +053092 else if (is_mx6dl() || is_mx6solo())
Michael Trimarchi8811c4d2019-12-30 17:34:02 +053093 return IMX6DL_ICORE_MIPI;
Jagan Teki409b16d2017-11-21 00:02:10 +053094 } else if (!strcmp(cmp_dtb, "imx6q-icore-rqs")) {
95 if (is_mx6dq())
Michael Trimarchi8811c4d2019-12-30 17:34:02 +053096 return IMX6Q_ICORE_RQS;
Jagan Teki04c28a72018-01-06 00:02:04 +053097 else if (is_mx6dl() || is_mx6solo())
Michael Trimarchi8811c4d2019-12-30 17:34:02 +053098 return IMX6DL_ICORE_RQS;
Jagan Teki18053a82018-06-18 11:12:19 +053099 } else if (!strcmp(cmp_dtb, "imx6ul-geam"))
Michael Trimarchi8811c4d2019-12-30 17:34:02 +0530100 return IMX6UL_GEAM;
Jagan Teki409b16d2017-11-21 00:02:10 +0530101 else if (!strcmp(cmp_dtb, "imx6ul-isiot-emmc"))
Michael Trimarchi8811c4d2019-12-30 17:34:02 +0530102 return IMX6UL_ISIOT_EMMC;
Jagan Teki409b16d2017-11-21 00:02:10 +0530103 else if (!strcmp(cmp_dtb, "imx6ul-isiot-nand"))
Michael Trimarchi8811c4d2019-12-30 17:34:02 +0530104 return IMX6UL_ISIOT_NAND;
105
106 return -EINVAL;
Jagan Teki409b16d2017-11-21 00:02:10 +0530107}
108
Michael Trimarchi90d46652019-12-30 17:34:03 +0530109static int fixup_enet_clock(enum engicam_boards board_detected)
110{
111 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
112 int clk_internal = 0;
113
114 switch (board_detected) {
115 case IMX6Q_ICORE_MIPI:
116 case IMX6DL_ICORE_MIPI:
117 clk_internal = 1;
118 break;
119 default:
120 break;
121 }
122
123 /* set gpr1[21] to select anatop clock */
124 debug("fixup_enet_clock %d\n", clk_internal);
125 clrsetbits_le32(&iomuxc_regs->gpr[1], 0x1 << 21, clk_internal << 21);
126
127 if (!clk_internal) {
128 /* clock is external */
129 return 0;
130 }
131
132 return enable_fec_anatop_clock(0, ENET_50MHZ);
133}
134
Jagan Tekif9247562017-05-07 02:43:15 +0530135int board_late_init(void)
136{
Michael Trimarchi8811c4d2019-12-30 17:34:02 +0530137 enum engicam_boards board_detected = IMX6Q_ICORE;
138
Jagan Tekif9247562017-05-07 02:43:15 +0530139 switch ((imx6_src_get_boot_mode() & IMX6_BMODE_MASK) >>
140 IMX6_BMODE_SHIFT) {
141 case IMX6_BMODE_SD:
142 case IMX6_BMODE_ESD:
143 case IMX6_BMODE_MMC:
144 case IMX6_BMODE_EMMC:
145#ifdef CONFIG_ENV_IS_IN_MMC
146 mmc_late_init();
147#endif
Simon Glass382bee52017-08-03 12:22:09 -0600148 env_set("modeboot", "mmcboot");
Jagan Tekif9247562017-05-07 02:43:15 +0530149 break;
Eran Matityahuaf104ae2017-12-14 20:20:02 +0200150 case IMX6_BMODE_NAND_MIN ... IMX6_BMODE_NAND_MAX:
Simon Glass382bee52017-08-03 12:22:09 -0600151 env_set("modeboot", "nandboot");
Jagan Tekif9247562017-05-07 02:43:15 +0530152 break;
153 default:
Simon Glass382bee52017-08-03 12:22:09 -0600154 env_set("modeboot", "");
Jagan Tekif9247562017-05-07 02:43:15 +0530155 break;
156 }
157
Jagan Teki46f9c832017-05-12 17:18:26 +0530158 if (is_mx6ul())
Simon Glass382bee52017-08-03 12:22:09 -0600159 env_set("console", "ttymxc0");
Jagan Teki46f9c832017-05-12 17:18:26 +0530160 else
Simon Glass382bee52017-08-03 12:22:09 -0600161 env_set("console", "ttymxc3");
Jagan Teki46f9c832017-05-12 17:18:26 +0530162
Michael Trimarchi8811c4d2019-12-30 17:34:02 +0530163 board_detected = engicam_board_detect();
164 if (board_detected < 0)
165 hang();
166
Michael Trimarchi90d46652019-12-30 17:34:03 +0530167 fixup_enet_clock(board_detected);
Michael Trimarchi8811c4d2019-12-30 17:34:02 +0530168 setenv_fdt_file(board_detected);
Jagan Tekif9247562017-05-07 02:43:15 +0530169
Shyam Saini74bf9322019-02-06 13:23:35 +0530170#ifdef CONFIG_HW_WATCHDOG
171 hw_watchdog_init();
172#endif
173
Jagan Tekif9247562017-05-07 02:43:15 +0530174 return 0;
175}
176
Jagan Tekiac880e72017-05-07 02:43:14 +0530177int board_init(void)
178{
179 /* Address of boot parameters */
180 gd->bd->bi_boot_params = PHYS_SDRAM + 0x100;
181
182#ifdef CONFIG_NAND_MXS
183 setup_gpmi_nand();
184#endif
185
186#ifdef CONFIG_VIDEO_IPUV3
187 setup_display();
188#endif
189
190 return 0;
191}
192
193int dram_init(void)
194{
195 gd->ram_size = imx_ddr_size();
196
197 return 0;
198}