Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jagan Teki | ac880e7 | 2017-05-07 02:43:14 +0530 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 Amarula Solutions B.V. |
| 4 | * Copyright (C) 2016 Engicam S.r.l. |
| 5 | * Author: Jagan Teki <jagan@amarulasolutions.com> |
Jagan Teki | ac880e7 | 2017-05-07 02:43:14 +0530 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | 288b29e | 2019-11-14 12:57:43 -0700 | [diff] [blame] | 9 | #include <command.h> |
Simon Glass | 168068f | 2019-08-01 09:46:47 -0600 | [diff] [blame] | 10 | #include <env.h> |
Simon Glass | db41d65 | 2019-12-28 10:45:07 -0700 | [diff] [blame] | 11 | #include <hang.h> |
Simon Glass | 5255932 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 12 | #include <init.h> |
Simon Glass | f7ae49f | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Jagan Teki | ac880e7 | 2017-05-07 02:43:14 +0530 | [diff] [blame] | 14 | #include <mmc.h> |
Michael Trimarchi | 90d4665 | 2019-12-30 17:34:03 +0530 | [diff] [blame] | 15 | #include <asm/arch/clock.h> |
| 16 | #include <asm/arch/imx-regs.h> |
Jagan Teki | ac880e7 | 2017-05-07 02:43:14 +0530 | [diff] [blame] | 17 | #include <asm/arch/sys_proto.h> |
Shyam Saini | 74bf932 | 2019-02-06 13:23:35 +0530 | [diff] [blame] | 18 | #include <watchdog.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 19 | #include <asm/global_data.h> |
Jagan Teki | ac880e7 | 2017-05-07 02:43:14 +0530 | [diff] [blame] | 20 | |
| 21 | #include "board.h" |
| 22 | |
| 23 | DECLARE_GLOBAL_DATA_PTR; |
| 24 | |
| 25 | #ifdef CONFIG_ENV_IS_IN_MMC |
Jagan Teki | f924756 | 2017-05-07 02:43:15 +0530 | [diff] [blame] | 26 | static void mmc_late_init(void) |
Jagan Teki | ac880e7 | 2017-05-07 02:43:14 +0530 | [diff] [blame] | 27 | { |
| 28 | char cmd[32]; |
| 29 | char mmcblk[32]; |
| 30 | u32 dev_no = mmc_get_env_dev(); |
| 31 | |
Simon Glass | 018f530 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 32 | env_set_ulong("mmcdev", dev_no); |
Jagan Teki | ac880e7 | 2017-05-07 02:43:14 +0530 | [diff] [blame] | 33 | |
| 34 | /* Set mmcblk env */ |
| 35 | sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw", dev_no); |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 36 | env_set("mmcroot", mmcblk); |
Jagan Teki | ac880e7 | 2017-05-07 02:43:14 +0530 | [diff] [blame] | 37 | |
| 38 | sprintf(cmd, "mmc dev %d", dev_no); |
| 39 | run_command(cmd, 0); |
| 40 | } |
| 41 | #endif |
| 42 | |
Michael Trimarchi | 8811c4d | 2019-12-30 17:34:02 +0530 | [diff] [blame] | 43 | enum 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 | |
| 56 | static 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 | |
| 68 | static 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 | |
| 80 | static enum engicam_boards engicam_board_detect(void) |
Jagan Teki | 409b16d | 2017-11-21 00:02:10 +0530 | [diff] [blame] | 81 | { |
| 82 | const char *cmp_dtb = CONFIG_DEFAULT_DEVICE_TREE; |
| 83 | |
| 84 | if (!strcmp(cmp_dtb, "imx6q-icore")) { |
| 85 | if (is_mx6dq()) |
Michael Trimarchi | 8811c4d | 2019-12-30 17:34:02 +0530 | [diff] [blame] | 86 | return IMX6Q_ICORE; |
Jagan Teki | 04c28a7 | 2018-01-06 00:02:04 +0530 | [diff] [blame] | 87 | else if (is_mx6dl() || is_mx6solo()) |
Michael Trimarchi | 8811c4d | 2019-12-30 17:34:02 +0530 | [diff] [blame] | 88 | return IMX6DL_ICORE; |
Jagan Teki | 04c28a7 | 2018-01-06 00:02:04 +0530 | [diff] [blame] | 89 | } else if (!strcmp(cmp_dtb, "imx6q-icore-mipi")) { |
| 90 | if (is_mx6dq()) |
Michael Trimarchi | 8811c4d | 2019-12-30 17:34:02 +0530 | [diff] [blame] | 91 | return IMX6Q_ICORE_MIPI; |
Jagan Teki | 04c28a7 | 2018-01-06 00:02:04 +0530 | [diff] [blame] | 92 | else if (is_mx6dl() || is_mx6solo()) |
Michael Trimarchi | 8811c4d | 2019-12-30 17:34:02 +0530 | [diff] [blame] | 93 | return IMX6DL_ICORE_MIPI; |
Jagan Teki | 409b16d | 2017-11-21 00:02:10 +0530 | [diff] [blame] | 94 | } else if (!strcmp(cmp_dtb, "imx6q-icore-rqs")) { |
| 95 | if (is_mx6dq()) |
Michael Trimarchi | 8811c4d | 2019-12-30 17:34:02 +0530 | [diff] [blame] | 96 | return IMX6Q_ICORE_RQS; |
Jagan Teki | 04c28a7 | 2018-01-06 00:02:04 +0530 | [diff] [blame] | 97 | else if (is_mx6dl() || is_mx6solo()) |
Michael Trimarchi | 8811c4d | 2019-12-30 17:34:02 +0530 | [diff] [blame] | 98 | return IMX6DL_ICORE_RQS; |
Jagan Teki | 18053a8 | 2018-06-18 11:12:19 +0530 | [diff] [blame] | 99 | } else if (!strcmp(cmp_dtb, "imx6ul-geam")) |
Michael Trimarchi | 8811c4d | 2019-12-30 17:34:02 +0530 | [diff] [blame] | 100 | return IMX6UL_GEAM; |
Jagan Teki | 409b16d | 2017-11-21 00:02:10 +0530 | [diff] [blame] | 101 | else if (!strcmp(cmp_dtb, "imx6ul-isiot-emmc")) |
Michael Trimarchi | 8811c4d | 2019-12-30 17:34:02 +0530 | [diff] [blame] | 102 | return IMX6UL_ISIOT_EMMC; |
Jagan Teki | 409b16d | 2017-11-21 00:02:10 +0530 | [diff] [blame] | 103 | else if (!strcmp(cmp_dtb, "imx6ul-isiot-nand")) |
Michael Trimarchi | 8811c4d | 2019-12-30 17:34:02 +0530 | [diff] [blame] | 104 | return IMX6UL_ISIOT_NAND; |
| 105 | |
| 106 | return -EINVAL; |
Jagan Teki | 409b16d | 2017-11-21 00:02:10 +0530 | [diff] [blame] | 107 | } |
| 108 | |
Michael Trimarchi | 90d4665 | 2019-12-30 17:34:03 +0530 | [diff] [blame] | 109 | static 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 Teki | f924756 | 2017-05-07 02:43:15 +0530 | [diff] [blame] | 135 | int board_late_init(void) |
| 136 | { |
Michael Trimarchi | 8811c4d | 2019-12-30 17:34:02 +0530 | [diff] [blame] | 137 | enum engicam_boards board_detected = IMX6Q_ICORE; |
| 138 | |
Jagan Teki | f924756 | 2017-05-07 02:43:15 +0530 | [diff] [blame] | 139 | 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 Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 148 | env_set("modeboot", "mmcboot"); |
Jagan Teki | f924756 | 2017-05-07 02:43:15 +0530 | [diff] [blame] | 149 | break; |
Eran Matityahu | af104ae | 2017-12-14 20:20:02 +0200 | [diff] [blame] | 150 | case IMX6_BMODE_NAND_MIN ... IMX6_BMODE_NAND_MAX: |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 151 | env_set("modeboot", "nandboot"); |
Jagan Teki | f924756 | 2017-05-07 02:43:15 +0530 | [diff] [blame] | 152 | break; |
| 153 | default: |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 154 | env_set("modeboot", ""); |
Jagan Teki | f924756 | 2017-05-07 02:43:15 +0530 | [diff] [blame] | 155 | break; |
| 156 | } |
| 157 | |
Jagan Teki | 46f9c83 | 2017-05-12 17:18:26 +0530 | [diff] [blame] | 158 | if (is_mx6ul()) |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 159 | env_set("console", "ttymxc0"); |
Jagan Teki | 46f9c83 | 2017-05-12 17:18:26 +0530 | [diff] [blame] | 160 | else |
Simon Glass | 382bee5 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 161 | env_set("console", "ttymxc3"); |
Jagan Teki | 46f9c83 | 2017-05-12 17:18:26 +0530 | [diff] [blame] | 162 | |
Michael Trimarchi | 8811c4d | 2019-12-30 17:34:02 +0530 | [diff] [blame] | 163 | board_detected = engicam_board_detect(); |
| 164 | if (board_detected < 0) |
| 165 | hang(); |
| 166 | |
Michael Trimarchi | 90d4665 | 2019-12-30 17:34:03 +0530 | [diff] [blame] | 167 | fixup_enet_clock(board_detected); |
Michael Trimarchi | 8811c4d | 2019-12-30 17:34:02 +0530 | [diff] [blame] | 168 | setenv_fdt_file(board_detected); |
Jagan Teki | f924756 | 2017-05-07 02:43:15 +0530 | [diff] [blame] | 169 | |
Shyam Saini | 74bf932 | 2019-02-06 13:23:35 +0530 | [diff] [blame] | 170 | #ifdef CONFIG_HW_WATCHDOG |
| 171 | hw_watchdog_init(); |
| 172 | #endif |
| 173 | |
Jagan Teki | f924756 | 2017-05-07 02:43:15 +0530 | [diff] [blame] | 174 | return 0; |
| 175 | } |
| 176 | |
Jagan Teki | ac880e7 | 2017-05-07 02:43:14 +0530 | [diff] [blame] | 177 | int 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 | |
| 193 | int dram_init(void) |
| 194 | { |
| 195 | gd->ram_size = imx_ddr_size(); |
| 196 | |
| 197 | return 0; |
| 198 | } |