Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jagan Teki | c5d8681 | 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 | c5d8681 | 2017-05-07 02:43:14 +0530 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
Simon Glass | adaaa48 | 2019-11-14 12:57:43 -0700 | [diff] [blame] | 9 | #include <command.h> |
Simon Glass | 07dc93c | 2019-08-01 09:46:47 -0600 | [diff] [blame] | 10 | #include <env.h> |
Simon Glass | a7b5130 | 2019-11-14 12:57:46 -0700 | [diff] [blame] | 11 | #include <init.h> |
Jagan Teki | c5d8681 | 2017-05-07 02:43:14 +0530 | [diff] [blame] | 12 | #include <mmc.h> |
| 13 | #include <asm/arch/sys_proto.h> |
Shyam Saini | 8e0fe1d | 2019-02-06 13:23:35 +0530 | [diff] [blame] | 14 | #include <watchdog.h> |
Jagan Teki | c5d8681 | 2017-05-07 02:43:14 +0530 | [diff] [blame] | 15 | |
| 16 | #include "board.h" |
| 17 | |
| 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
| 20 | #ifdef CONFIG_ENV_IS_IN_MMC |
Jagan Teki | 3ff7b93 | 2017-05-07 02:43:15 +0530 | [diff] [blame] | 21 | static void mmc_late_init(void) |
Jagan Teki | c5d8681 | 2017-05-07 02:43:14 +0530 | [diff] [blame] | 22 | { |
| 23 | char cmd[32]; |
| 24 | char mmcblk[32]; |
| 25 | u32 dev_no = mmc_get_env_dev(); |
| 26 | |
Simon Glass | 4d949a2 | 2017-08-03 12:22:10 -0600 | [diff] [blame] | 27 | env_set_ulong("mmcdev", dev_no); |
Jagan Teki | c5d8681 | 2017-05-07 02:43:14 +0530 | [diff] [blame] | 28 | |
| 29 | /* Set mmcblk env */ |
| 30 | sprintf(mmcblk, "/dev/mmcblk%dp2 rootwait rw", dev_no); |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 31 | env_set("mmcroot", mmcblk); |
Jagan Teki | c5d8681 | 2017-05-07 02:43:14 +0530 | [diff] [blame] | 32 | |
| 33 | sprintf(cmd, "mmc dev %d", dev_no); |
| 34 | run_command(cmd, 0); |
| 35 | } |
| 36 | #endif |
| 37 | |
Michael Trimarchi | 5b1b2a3 | 2019-12-30 17:34:02 +0530 | [diff] [blame^] | 38 | enum engicam_boards { |
| 39 | IMX6Q_ICORE, |
| 40 | IMX6DL_ICORE, |
| 41 | IMX6Q_ICORE_MIPI, |
| 42 | IMX6DL_ICORE_MIPI, |
| 43 | IMX6Q_ICORE_RQS, |
| 44 | IMX6DL_ICORE_RQS, |
| 45 | IMX6UL_GEAM, |
| 46 | IMX6UL_ISIOT_EMMC, |
| 47 | IMX6UL_ISIOT_NAND, |
| 48 | ENGICAM_BOARDS, |
| 49 | }; |
| 50 | |
| 51 | static const char * const board_fdt_file[ENGICAM_BOARDS] = { |
| 52 | [IMX6Q_ICORE] = "imx6q-icore.dtb", |
| 53 | [IMX6DL_ICORE] = "imx6dl-icore.dtb", |
| 54 | [IMX6Q_ICORE_MIPI] = "imx6q-icore-mipi.dtb", |
| 55 | [IMX6DL_ICORE_MIPI] = "imx6dl-icore-mipi.dtb", |
| 56 | [IMX6Q_ICORE_RQS] = "imx6q-icore-rqs.dtb", |
| 57 | [IMX6DL_ICORE_RQS] = "imx6dl-icore-rqs.dtb", |
| 58 | [IMX6UL_GEAM] = "imx6ul-geam.dtb", |
| 59 | [IMX6UL_ISIOT_EMMC] = "imx6ul-isiot-emmc.dtb", |
| 60 | [IMX6UL_ISIOT_NAND] = "imx6ul-isiot-nand.dtb", |
| 61 | }; |
| 62 | |
| 63 | static int setenv_fdt_file(int board_detected) |
| 64 | { |
| 65 | if (board_detected < 0 || board_detected >= ENGICAM_BOARDS) |
| 66 | return -EINVAL; |
| 67 | |
| 68 | if (!board_fdt_file[board_detected]) |
| 69 | return -ENODEV; |
| 70 | |
| 71 | env_set("fdt_file", board_fdt_file[board_detected]); |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | static enum engicam_boards engicam_board_detect(void) |
Jagan Teki | 5479da6 | 2017-11-21 00:02:10 +0530 | [diff] [blame] | 76 | { |
| 77 | const char *cmp_dtb = CONFIG_DEFAULT_DEVICE_TREE; |
| 78 | |
| 79 | if (!strcmp(cmp_dtb, "imx6q-icore")) { |
| 80 | if (is_mx6dq()) |
Michael Trimarchi | 5b1b2a3 | 2019-12-30 17:34:02 +0530 | [diff] [blame^] | 81 | return IMX6Q_ICORE; |
Jagan Teki | 6e4572f | 2018-01-06 00:02:04 +0530 | [diff] [blame] | 82 | else if (is_mx6dl() || is_mx6solo()) |
Michael Trimarchi | 5b1b2a3 | 2019-12-30 17:34:02 +0530 | [diff] [blame^] | 83 | return IMX6DL_ICORE; |
Jagan Teki | 6e4572f | 2018-01-06 00:02:04 +0530 | [diff] [blame] | 84 | } else if (!strcmp(cmp_dtb, "imx6q-icore-mipi")) { |
| 85 | if (is_mx6dq()) |
Michael Trimarchi | 5b1b2a3 | 2019-12-30 17:34:02 +0530 | [diff] [blame^] | 86 | return IMX6Q_ICORE_MIPI; |
Jagan Teki | 6e4572f | 2018-01-06 00:02:04 +0530 | [diff] [blame] | 87 | else if (is_mx6dl() || is_mx6solo()) |
Michael Trimarchi | 5b1b2a3 | 2019-12-30 17:34:02 +0530 | [diff] [blame^] | 88 | return IMX6DL_ICORE_MIPI; |
Jagan Teki | 5479da6 | 2017-11-21 00:02:10 +0530 | [diff] [blame] | 89 | } else if (!strcmp(cmp_dtb, "imx6q-icore-rqs")) { |
| 90 | if (is_mx6dq()) |
Michael Trimarchi | 5b1b2a3 | 2019-12-30 17:34:02 +0530 | [diff] [blame^] | 91 | return IMX6Q_ICORE_RQS; |
Jagan Teki | 6e4572f | 2018-01-06 00:02:04 +0530 | [diff] [blame] | 92 | else if (is_mx6dl() || is_mx6solo()) |
Michael Trimarchi | 5b1b2a3 | 2019-12-30 17:34:02 +0530 | [diff] [blame^] | 93 | return IMX6DL_ICORE_RQS; |
Jagan Teki | b10b3b5 | 2018-06-18 11:12:19 +0530 | [diff] [blame] | 94 | } else if (!strcmp(cmp_dtb, "imx6ul-geam")) |
Michael Trimarchi | 5b1b2a3 | 2019-12-30 17:34:02 +0530 | [diff] [blame^] | 95 | return IMX6UL_GEAM; |
Jagan Teki | 5479da6 | 2017-11-21 00:02:10 +0530 | [diff] [blame] | 96 | else if (!strcmp(cmp_dtb, "imx6ul-isiot-emmc")) |
Michael Trimarchi | 5b1b2a3 | 2019-12-30 17:34:02 +0530 | [diff] [blame^] | 97 | return IMX6UL_ISIOT_EMMC; |
Jagan Teki | 5479da6 | 2017-11-21 00:02:10 +0530 | [diff] [blame] | 98 | else if (!strcmp(cmp_dtb, "imx6ul-isiot-nand")) |
Michael Trimarchi | 5b1b2a3 | 2019-12-30 17:34:02 +0530 | [diff] [blame^] | 99 | return IMX6UL_ISIOT_NAND; |
| 100 | |
| 101 | return -EINVAL; |
Jagan Teki | 5479da6 | 2017-11-21 00:02:10 +0530 | [diff] [blame] | 102 | } |
| 103 | |
Jagan Teki | 3ff7b93 | 2017-05-07 02:43:15 +0530 | [diff] [blame] | 104 | int board_late_init(void) |
| 105 | { |
Michael Trimarchi | 5b1b2a3 | 2019-12-30 17:34:02 +0530 | [diff] [blame^] | 106 | enum engicam_boards board_detected = IMX6Q_ICORE; |
| 107 | |
Jagan Teki | 3ff7b93 | 2017-05-07 02:43:15 +0530 | [diff] [blame] | 108 | switch ((imx6_src_get_boot_mode() & IMX6_BMODE_MASK) >> |
| 109 | IMX6_BMODE_SHIFT) { |
| 110 | case IMX6_BMODE_SD: |
| 111 | case IMX6_BMODE_ESD: |
| 112 | case IMX6_BMODE_MMC: |
| 113 | case IMX6_BMODE_EMMC: |
| 114 | #ifdef CONFIG_ENV_IS_IN_MMC |
| 115 | mmc_late_init(); |
| 116 | #endif |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 117 | env_set("modeboot", "mmcboot"); |
Jagan Teki | 3ff7b93 | 2017-05-07 02:43:15 +0530 | [diff] [blame] | 118 | break; |
Eran Matityahu | 5fa7ca6 | 2017-12-14 20:20:02 +0200 | [diff] [blame] | 119 | case IMX6_BMODE_NAND_MIN ... IMX6_BMODE_NAND_MAX: |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 120 | env_set("modeboot", "nandboot"); |
Jagan Teki | 3ff7b93 | 2017-05-07 02:43:15 +0530 | [diff] [blame] | 121 | break; |
| 122 | default: |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 123 | env_set("modeboot", ""); |
Jagan Teki | 3ff7b93 | 2017-05-07 02:43:15 +0530 | [diff] [blame] | 124 | break; |
| 125 | } |
| 126 | |
Jagan Teki | 388a904 | 2017-05-12 17:18:26 +0530 | [diff] [blame] | 127 | if (is_mx6ul()) |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 128 | env_set("console", "ttymxc0"); |
Jagan Teki | 388a904 | 2017-05-12 17:18:26 +0530 | [diff] [blame] | 129 | else |
Simon Glass | 6a38e41 | 2017-08-03 12:22:09 -0600 | [diff] [blame] | 130 | env_set("console", "ttymxc3"); |
Jagan Teki | 388a904 | 2017-05-12 17:18:26 +0530 | [diff] [blame] | 131 | |
Michael Trimarchi | 5b1b2a3 | 2019-12-30 17:34:02 +0530 | [diff] [blame^] | 132 | board_detected = engicam_board_detect(); |
| 133 | if (board_detected < 0) |
| 134 | hang(); |
| 135 | |
| 136 | setenv_fdt_file(board_detected); |
Jagan Teki | 3ff7b93 | 2017-05-07 02:43:15 +0530 | [diff] [blame] | 137 | |
Shyam Saini | 8e0fe1d | 2019-02-06 13:23:35 +0530 | [diff] [blame] | 138 | #ifdef CONFIG_HW_WATCHDOG |
| 139 | hw_watchdog_init(); |
| 140 | #endif |
| 141 | |
Jagan Teki | 3ff7b93 | 2017-05-07 02:43:15 +0530 | [diff] [blame] | 142 | return 0; |
| 143 | } |
| 144 | |
Jagan Teki | c5d8681 | 2017-05-07 02:43:14 +0530 | [diff] [blame] | 145 | int board_init(void) |
| 146 | { |
| 147 | /* Address of boot parameters */ |
| 148 | gd->bd->bi_boot_params = PHYS_SDRAM + 0x100; |
| 149 | |
| 150 | #ifdef CONFIG_NAND_MXS |
| 151 | setup_gpmi_nand(); |
| 152 | #endif |
| 153 | |
| 154 | #ifdef CONFIG_VIDEO_IPUV3 |
| 155 | setup_display(); |
| 156 | #endif |
| 157 | |
| 158 | return 0; |
| 159 | } |
| 160 | |
| 161 | int dram_init(void) |
| 162 | { |
| 163 | gd->ram_size = imx_ddr_size(); |
| 164 | |
| 165 | return 0; |
| 166 | } |