Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2007 |
| 4 | * Sascha Hauer, Pengutronix |
| 5 | * |
| 6 | * (C) Copyright 2009 Freescale Semiconductor, Inc. |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 7 | */ |
| 8 | |
Jeroen Hofstee | 5624c6b | 2014-10-08 22:57:52 +0200 | [diff] [blame] | 9 | #include <bootm.h> |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 10 | #include <common.h> |
Jeroen Hofstee | 5624c6b | 2014-10-08 22:57:52 +0200 | [diff] [blame] | 11 | #include <netdev.h> |
Masahiro Yamada | 1221ce4 | 2016-09-21 11:28:55 +0900 | [diff] [blame] | 12 | #include <linux/errno.h> |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 13 | #include <asm/io.h> |
| 14 | #include <asm/arch/imx-regs.h> |
| 15 | #include <asm/arch/clock.h> |
| 16 | #include <asm/arch/sys_proto.h> |
Fabio Estevam | 6a37604 | 2012-04-29 08:11:13 +0000 | [diff] [blame] | 17 | #include <asm/arch/crm_regs.h> |
Peng Fan | 770611f | 2018-01-10 13:20:34 +0800 | [diff] [blame] | 18 | #include <asm/mach-imx/boot_mode.h> |
Tim Harvey | 70caa8e | 2015-05-18 06:56:46 -0700 | [diff] [blame] | 19 | #include <imx_thermal.h> |
Eric Nelson | e1eb75b | 2012-09-23 07:30:55 +0000 | [diff] [blame] | 20 | #include <ipu_pixfmt.h> |
Ye.Li | 7a26416 | 2014-11-20 21:14:14 +0800 | [diff] [blame] | 21 | #include <thermal.h> |
Nikita Kiryanov | 44b9841 | 2014-11-21 12:47:26 +0200 | [diff] [blame] | 22 | #include <sata.h> |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 23 | |
Yangbo Lu | e37ac71 | 2019-06-21 11:42:28 +0800 | [diff] [blame] | 24 | #ifdef CONFIG_FSL_ESDHC_IMX |
| 25 | #include <fsl_esdhc_imx.h> |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 26 | #endif |
| 27 | |
Eric Nelson | 11c2e50 | 2015-02-15 14:37:21 -0700 | [diff] [blame] | 28 | static u32 reset_cause = -1; |
| 29 | |
Max Krummenacher | 6ed4d26 | 2019-02-01 16:04:51 +0100 | [diff] [blame] | 30 | u32 get_imx_reset_cause(void) |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 31 | { |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 32 | struct src *src_regs = (struct src *)SRC_BASE_ADDR; |
| 33 | |
Max Krummenacher | 6ed4d26 | 2019-02-01 16:04:51 +0100 | [diff] [blame] | 34 | if (reset_cause == -1) { |
| 35 | reset_cause = readl(&src_regs->srsr); |
| 36 | /* preserve the value for U-Boot proper */ |
| 37 | #if !defined(CONFIG_SPL_BUILD) |
| 38 | writel(reset_cause, &src_regs->srsr); |
| 39 | #endif |
| 40 | } |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 41 | |
Max Krummenacher | 6ed4d26 | 2019-02-01 16:04:51 +0100 | [diff] [blame] | 42 | return reset_cause; |
| 43 | } |
| 44 | |
| 45 | #if defined(CONFIG_DISPLAY_CPUINFO) && !defined(CONFIG_SPL_BUILD) |
| 46 | static char *get_reset_cause(void) |
| 47 | { |
| 48 | switch (get_imx_reset_cause()) { |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 49 | case 0x00001: |
Fabio Estevam | cece262 | 2012-03-13 07:26:48 +0000 | [diff] [blame] | 50 | case 0x00011: |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 51 | return "POR"; |
| 52 | case 0x00004: |
| 53 | return "CSU"; |
| 54 | case 0x00008: |
| 55 | return "IPP USER"; |
| 56 | case 0x00010: |
Adrian Alonso | cd562c8 | 2015-09-02 13:54:23 -0500 | [diff] [blame] | 57 | #ifdef CONFIG_MX7 |
| 58 | return "WDOG1"; |
| 59 | #else |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 60 | return "WDOG"; |
Adrian Alonso | cd562c8 | 2015-09-02 13:54:23 -0500 | [diff] [blame] | 61 | #endif |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 62 | case 0x00020: |
| 63 | return "JTAG HIGH-Z"; |
| 64 | case 0x00040: |
| 65 | return "JTAG SW"; |
Adrian Alonso | cd562c8 | 2015-09-02 13:54:23 -0500 | [diff] [blame] | 66 | case 0x00080: |
| 67 | return "WDOG3"; |
| 68 | #ifdef CONFIG_MX7 |
| 69 | case 0x00100: |
| 70 | return "WDOG4"; |
| 71 | case 0x00200: |
| 72 | return "TEMPSENSE"; |
Peng Fan | cd357ad | 2018-11-20 10:19:25 +0000 | [diff] [blame] | 73 | #elif defined(CONFIG_IMX8M) |
Peng Fan | 7537e93 | 2018-01-10 13:20:25 +0800 | [diff] [blame] | 74 | case 0x00100: |
| 75 | return "WDOG2"; |
| 76 | case 0x00200: |
| 77 | return "TEMPSENSE"; |
Adrian Alonso | cd562c8 | 2015-09-02 13:54:23 -0500 | [diff] [blame] | 78 | #else |
| 79 | case 0x00100: |
| 80 | return "TEMPSENSE"; |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 81 | case 0x10000: |
| 82 | return "WARM BOOT"; |
Adrian Alonso | cd562c8 | 2015-09-02 13:54:23 -0500 | [diff] [blame] | 83 | #endif |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 84 | default: |
| 85 | return "unknown reset"; |
| 86 | } |
| 87 | } |
Prabhakar Kushwaha | 28420e7 | 2015-05-18 17:13:52 +0530 | [diff] [blame] | 88 | #endif |
Eric Nelson | 11c2e50 | 2015-02-15 14:37:21 -0700 | [diff] [blame] | 89 | |
Troy Kisky | eb0344d | 2012-10-23 10:57:48 +0000 | [diff] [blame] | 90 | #if defined(CONFIG_MX53) || defined(CONFIG_MX6) |
| 91 | #if defined(CONFIG_MX53) |
Eric Nelson | 3e9cbbb | 2013-11-08 16:50:53 -0700 | [diff] [blame] | 92 | #define MEMCTL_BASE ESDCTL_BASE_ADDR |
Troy Kisky | eb0344d | 2012-10-23 10:57:48 +0000 | [diff] [blame] | 93 | #else |
Eric Nelson | 3e9cbbb | 2013-11-08 16:50:53 -0700 | [diff] [blame] | 94 | #define MEMCTL_BASE MMDC_P0_BASE_ADDR |
Troy Kisky | eb0344d | 2012-10-23 10:57:48 +0000 | [diff] [blame] | 95 | #endif |
| 96 | static const unsigned char col_lookup[] = {9, 10, 11, 8, 12, 9, 9, 9}; |
| 97 | static const unsigned char bank_lookup[] = {3, 2}; |
| 98 | |
Tim Harvey | b07161c | 2014-06-02 16:13:21 -0700 | [diff] [blame] | 99 | /* these MMDC registers are common to the IMX53 and IMX6 */ |
Troy Kisky | eb0344d | 2012-10-23 10:57:48 +0000 | [diff] [blame] | 100 | struct esd_mmdc_regs { |
| 101 | uint32_t ctl; |
| 102 | uint32_t pdc; |
| 103 | uint32_t otc; |
| 104 | uint32_t cfg0; |
| 105 | uint32_t cfg1; |
| 106 | uint32_t cfg2; |
| 107 | uint32_t misc; |
Troy Kisky | eb0344d | 2012-10-23 10:57:48 +0000 | [diff] [blame] | 108 | }; |
| 109 | |
| 110 | #define ESD_MMDC_CTL_GET_ROW(mdctl) ((ctl >> 24) & 7) |
| 111 | #define ESD_MMDC_CTL_GET_COLUMN(mdctl) ((ctl >> 20) & 7) |
| 112 | #define ESD_MMDC_CTL_GET_WIDTH(mdctl) ((ctl >> 16) & 3) |
| 113 | #define ESD_MMDC_CTL_GET_CS1(mdctl) ((ctl >> 30) & 1) |
| 114 | #define ESD_MMDC_MISC_GET_BANK(mdmisc) ((misc >> 5) & 1) |
| 115 | |
Tim Harvey | b07161c | 2014-06-02 16:13:21 -0700 | [diff] [blame] | 116 | /* |
| 117 | * imx_ddr_size - return size in bytes of DRAM according MMDC config |
| 118 | * The MMDC MDCTL register holds the number of bits for row, col, and data |
| 119 | * width and the MMDC MDMISC register holds the number of banks. Combine |
| 120 | * all these bits to determine the meme size the MMDC has been configured for |
| 121 | */ |
Troy Kisky | eb0344d | 2012-10-23 10:57:48 +0000 | [diff] [blame] | 122 | unsigned imx_ddr_size(void) |
| 123 | { |
| 124 | struct esd_mmdc_regs *mem = (struct esd_mmdc_regs *)MEMCTL_BASE; |
| 125 | unsigned ctl = readl(&mem->ctl); |
| 126 | unsigned misc = readl(&mem->misc); |
| 127 | int bits = 11 + 0 + 0 + 1; /* row + col + bank + width */ |
| 128 | |
| 129 | bits += ESD_MMDC_CTL_GET_ROW(ctl); |
| 130 | bits += col_lookup[ESD_MMDC_CTL_GET_COLUMN(ctl)]; |
| 131 | bits += bank_lookup[ESD_MMDC_MISC_GET_BANK(misc)]; |
| 132 | bits += ESD_MMDC_CTL_GET_WIDTH(ctl); |
| 133 | bits += ESD_MMDC_CTL_GET_CS1(ctl); |
Marek Vasut | fcfdfdd | 2014-08-04 01:47:09 +0200 | [diff] [blame] | 134 | |
| 135 | /* The MX6 can do only 3840 MiB of DRAM */ |
| 136 | if (bits == 32) |
| 137 | return 0xf0000000; |
| 138 | |
Troy Kisky | eb0344d | 2012-10-23 10:57:48 +0000 | [diff] [blame] | 139 | return 1 << bits; |
| 140 | } |
| 141 | #endif |
| 142 | |
Anatolij Gustschin | 38df370 | 2017-08-28 21:46:26 +0200 | [diff] [blame] | 143 | #if defined(CONFIG_DISPLAY_CPUINFO) && !defined(CONFIG_SPL_BUILD) |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 144 | |
Troy Kisky | 20332a0 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 145 | const char *get_imx_type(u32 imxtype) |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 146 | { |
| 147 | switch (imxtype) { |
Peng Fan | cd357ad | 2018-11-20 10:19:25 +0000 | [diff] [blame] | 148 | case MXC_CPU_IMX8MQ: |
| 149 | return "8MQ"; /* Quad-core version of the imx8m */ |
Fabio Estevam | e25a065 | 2016-02-28 12:33:17 -0300 | [diff] [blame] | 150 | case MXC_CPU_MX7S: |
Stefan Agner | 249092f | 2016-05-06 11:21:50 -0700 | [diff] [blame] | 151 | return "7S"; /* Single-core version of the mx7 */ |
Adrian Alonso | cd562c8 | 2015-09-02 13:54:23 -0500 | [diff] [blame] | 152 | case MXC_CPU_MX7D: |
| 153 | return "7D"; /* Dual-core version of the mx7 */ |
Peng Fan | d0acd99 | 2015-07-11 11:38:42 +0800 | [diff] [blame] | 154 | case MXC_CPU_MX6QP: |
| 155 | return "6QP"; /* Quad-Plus version of the mx6 */ |
| 156 | case MXC_CPU_MX6DP: |
| 157 | return "6DP"; /* Dual-Plus version of the mx6 */ |
Troy Kisky | 20332a0 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 158 | case MXC_CPU_MX6Q: |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 159 | return "6Q"; /* Quad-core version of the mx6 */ |
Fabio Estevam | 94db665 | 2014-01-26 15:06:41 -0200 | [diff] [blame] | 160 | case MXC_CPU_MX6D: |
| 161 | return "6D"; /* Dual-core version of the mx6 */ |
Troy Kisky | 20332a0 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 162 | case MXC_CPU_MX6DL: |
| 163 | return "6DL"; /* Dual Lite version of the mx6 */ |
| 164 | case MXC_CPU_MX6SOLO: |
| 165 | return "6SOLO"; /* Solo version of the mx6 */ |
| 166 | case MXC_CPU_MX6SL: |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 167 | return "6SL"; /* Solo-Lite version of the mx6 */ |
Peng Fan | 7ce6d3c | 2016-12-11 19:24:20 +0800 | [diff] [blame] | 168 | case MXC_CPU_MX6SLL: |
| 169 | return "6SLL"; /* SLL version of the mx6 */ |
Fabio Estevam | 05d54b8 | 2014-06-24 17:40:58 -0300 | [diff] [blame] | 170 | case MXC_CPU_MX6SX: |
| 171 | return "6SX"; /* SoloX version of the mx6 */ |
Peng Fan | 8631c06 | 2015-07-20 19:28:21 +0800 | [diff] [blame] | 172 | case MXC_CPU_MX6UL: |
| 173 | return "6UL"; /* Ultra-Lite version of the mx6 */ |
Peng Fan | 65ce54b | 2016-08-11 14:02:38 +0800 | [diff] [blame] | 174 | case MXC_CPU_MX6ULL: |
| 175 | return "6ULL"; /* ULL version of the mx6 */ |
Troy Kisky | 20332a0 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 176 | case MXC_CPU_MX51: |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 177 | return "51"; |
Troy Kisky | 20332a0 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 178 | case MXC_CPU_MX53: |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 179 | return "53"; |
| 180 | default: |
Otavio Salvador | e972d72 | 2012-06-30 05:07:32 +0000 | [diff] [blame] | 181 | return "??"; |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 182 | } |
| 183 | } |
| 184 | |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 185 | int print_cpuinfo(void) |
| 186 | { |
Stefano Babic | 943a3f2 | 2015-05-26 19:53:41 +0200 | [diff] [blame] | 187 | u32 cpurev; |
| 188 | __maybe_unused u32 max_freq; |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 189 | |
| 190 | cpurev = get_cpu_rev(); |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 191 | |
Adrian Alonso | 1368f99 | 2015-09-02 13:54:13 -0500 | [diff] [blame] | 192 | #if defined(CONFIG_IMX_THERMAL) |
| 193 | struct udevice *thermal_dev; |
| 194 | int cpu_tmp, minc, maxc, ret; |
| 195 | |
Tim Harvey | b83ddac | 2015-05-18 07:02:25 -0700 | [diff] [blame] | 196 | printf("CPU: Freescale i.MX%s rev%d.%d", |
| 197 | get_imx_type((cpurev & 0xFF000) >> 12), |
| 198 | (cpurev & 0x000F0) >> 4, |
| 199 | (cpurev & 0x0000F) >> 0); |
| 200 | max_freq = get_cpu_speed_grade_hz(); |
| 201 | if (!max_freq || max_freq == mxc_get_clock(MXC_ARM_CLK)) { |
| 202 | printf(" at %dMHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000); |
| 203 | } else { |
| 204 | printf(" %d MHz (running at %d MHz)\n", max_freq / 1000000, |
| 205 | mxc_get_clock(MXC_ARM_CLK) / 1000000); |
| 206 | } |
| 207 | #else |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 208 | printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n", |
| 209 | get_imx_type((cpurev & 0xFF000) >> 12), |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 210 | (cpurev & 0x000F0) >> 4, |
| 211 | (cpurev & 0x0000F) >> 0, |
| 212 | mxc_get_clock(MXC_ARM_CLK) / 1000000); |
Tim Harvey | b83ddac | 2015-05-18 07:02:25 -0700 | [diff] [blame] | 213 | #endif |
Ye.Li | 7a26416 | 2014-11-20 21:14:14 +0800 | [diff] [blame] | 214 | |
Adrian Alonso | 1368f99 | 2015-09-02 13:54:13 -0500 | [diff] [blame] | 215 | #if defined(CONFIG_IMX_THERMAL) |
Tim Harvey | 70caa8e | 2015-05-18 06:56:46 -0700 | [diff] [blame] | 216 | puts("CPU: "); |
| 217 | switch (get_cpu_temp_grade(&minc, &maxc)) { |
| 218 | case TEMP_AUTOMOTIVE: |
| 219 | puts("Automotive temperature grade "); |
| 220 | break; |
| 221 | case TEMP_INDUSTRIAL: |
| 222 | puts("Industrial temperature grade "); |
| 223 | break; |
| 224 | case TEMP_EXTCOMMERCIAL: |
| 225 | puts("Extended Commercial temperature grade "); |
| 226 | break; |
| 227 | default: |
| 228 | puts("Commercial temperature grade "); |
| 229 | break; |
| 230 | } |
| 231 | printf("(%dC to %dC)", minc, maxc); |
Ye.Li | 7a26416 | 2014-11-20 21:14:14 +0800 | [diff] [blame] | 232 | ret = uclass_get_device(UCLASS_THERMAL, 0, &thermal_dev); |
| 233 | if (!ret) { |
| 234 | ret = thermal_get_temp(thermal_dev, &cpu_tmp); |
| 235 | |
| 236 | if (!ret) |
Tim Harvey | 70caa8e | 2015-05-18 06:56:46 -0700 | [diff] [blame] | 237 | printf(" at %dC\n", cpu_tmp); |
Ye.Li | 7a26416 | 2014-11-20 21:14:14 +0800 | [diff] [blame] | 238 | else |
Fabio Estevam | 3a384b4 | 2015-09-08 14:43:10 -0300 | [diff] [blame] | 239 | debug(" - invalid sensor data\n"); |
Ye.Li | 7a26416 | 2014-11-20 21:14:14 +0800 | [diff] [blame] | 240 | } else { |
Fabio Estevam | 3a384b4 | 2015-09-08 14:43:10 -0300 | [diff] [blame] | 241 | debug(" - invalid sensor device\n"); |
Ye.Li | 7a26416 | 2014-11-20 21:14:14 +0800 | [diff] [blame] | 242 | } |
| 243 | #endif |
| 244 | |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 245 | printf("Reset cause: %s\n", get_reset_cause()); |
| 246 | return 0; |
| 247 | } |
| 248 | #endif |
| 249 | |
| 250 | int cpu_eth_init(bd_t *bis) |
| 251 | { |
| 252 | int rc = -ENODEV; |
| 253 | |
| 254 | #if defined(CONFIG_FEC_MXC) |
| 255 | rc = fecmxc_initialize(bis); |
| 256 | #endif |
| 257 | |
| 258 | return rc; |
| 259 | } |
| 260 | |
Yangbo Lu | e37ac71 | 2019-06-21 11:42:28 +0800 | [diff] [blame] | 261 | #ifdef CONFIG_FSL_ESDHC_IMX |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 262 | /* |
| 263 | * Initializes on-chip MMC controllers. |
| 264 | * to override, implement board_mmc_init() |
| 265 | */ |
| 266 | int cpu_mmc_init(bd_t *bis) |
| 267 | { |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 268 | return fsl_esdhc_mmc_init(bis); |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 269 | } |
Benoît Thébaudeau | ecb0f31 | 2012-08-17 10:42:55 +0000 | [diff] [blame] | 270 | #endif |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 271 | |
Peng Fan | cd357ad | 2018-11-20 10:19:25 +0000 | [diff] [blame] | 272 | #if !(defined(CONFIG_MX7) || defined(CONFIG_IMX8M)) |
Fabio Estevam | 6a37604 | 2012-04-29 08:11:13 +0000 | [diff] [blame] | 273 | u32 get_ahb_clk(void) |
| 274 | { |
| 275 | struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 276 | u32 reg, ahb_podf; |
| 277 | |
| 278 | reg = __raw_readl(&imx_ccm->cbcdr); |
| 279 | reg &= MXC_CCM_CBCDR_AHB_PODF_MASK; |
| 280 | ahb_podf = reg >> MXC_CCM_CBCDR_AHB_PODF_OFFSET; |
| 281 | |
| 282 | return get_periph_clk() / (ahb_podf + 1); |
| 283 | } |
Adrian Alonso | cd562c8 | 2015-09-02 13:54:23 -0500 | [diff] [blame] | 284 | #endif |
Eric Nelson | e1eb75b | 2012-09-23 07:30:55 +0000 | [diff] [blame] | 285 | |
Eric Nelson | e1eb75b | 2012-09-23 07:30:55 +0000 | [diff] [blame] | 286 | void arch_preboot_os(void) |
| 287 | { |
Marek Vasut | 42dc123 | 2019-06-09 03:50:51 +0200 | [diff] [blame] | 288 | #if defined(CONFIG_PCIE_IMX) && !CONFIG_IS_ENABLED(DM_PCI) |
Tim Harvey | 6ecbe13 | 2017-05-12 12:58:41 -0700 | [diff] [blame] | 289 | imx_pcie_remove(); |
| 290 | #endif |
Simon Glass | 10e40d5 | 2017-06-14 21:28:25 -0600 | [diff] [blame] | 291 | #if defined(CONFIG_SATA) |
Ludwig Zenz | 86e5953 | 2019-07-02 15:10:52 +0200 | [diff] [blame] | 292 | if (!is_mx6sdl()) { |
| 293 | sata_remove(0); |
Soeren Moch | dd1c8f1 | 2014-11-27 10:11:41 +0100 | [diff] [blame] | 294 | #if defined(CONFIG_MX6) |
Ludwig Zenz | 86e5953 | 2019-07-02 15:10:52 +0200 | [diff] [blame] | 295 | disable_sata_clock(); |
Soeren Moch | dd1c8f1 | 2014-11-27 10:11:41 +0100 | [diff] [blame] | 296 | #endif |
Ludwig Zenz | 86e5953 | 2019-07-02 15:10:52 +0200 | [diff] [blame] | 297 | } |
Nikita Kiryanov | 44b9841 | 2014-11-21 12:47:26 +0200 | [diff] [blame] | 298 | #endif |
| 299 | #if defined(CONFIG_VIDEO_IPUV3) |
Eric Nelson | e1eb75b | 2012-09-23 07:30:55 +0000 | [diff] [blame] | 300 | /* disable video before launching O/S */ |
| 301 | ipuv3_fb_shutdown(); |
Eric Nelson | e1eb75b | 2012-09-23 07:30:55 +0000 | [diff] [blame] | 302 | #endif |
Igor Opaniuk | 8c1df09 | 2019-06-04 00:05:59 +0300 | [diff] [blame] | 303 | #if defined(CONFIG_VIDEO_MXS) && !defined(CONFIG_DM_VIDEO) |
Peng Fan | 623787f | 2015-10-29 15:54:51 +0800 | [diff] [blame] | 304 | lcdif_power_down(); |
| 305 | #endif |
Nikita Kiryanov | 44b9841 | 2014-11-21 12:47:26 +0200 | [diff] [blame] | 306 | } |
Fabio Estevam | 32c81ea | 2014-11-14 11:27:21 -0200 | [diff] [blame] | 307 | |
Peng Fan | cd357ad | 2018-11-20 10:19:25 +0000 | [diff] [blame] | 308 | #ifndef CONFIG_IMX8M |
Fabio Estevam | 32c81ea | 2014-11-14 11:27:21 -0200 | [diff] [blame] | 309 | void set_chipselect_size(int const cs_size) |
| 310 | { |
| 311 | unsigned int reg; |
| 312 | struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR; |
| 313 | reg = readl(&iomuxc_regs->gpr[1]); |
| 314 | |
| 315 | switch (cs_size) { |
| 316 | case CS0_128: |
| 317 | reg &= ~0x7; /* CS0=128MB, CS1=0, CS2=0, CS3=0 */ |
| 318 | reg |= 0x5; |
| 319 | break; |
| 320 | case CS0_64M_CS1_64M: |
| 321 | reg &= ~0x3F; /* CS0=64MB, CS1=64MB, CS2=0, CS3=0 */ |
| 322 | reg |= 0x1B; |
| 323 | break; |
| 324 | case CS0_64M_CS1_32M_CS2_32M: |
| 325 | reg &= ~0x1FF; /* CS0=64MB, CS1=32MB, CS2=32MB, CS3=0 */ |
| 326 | reg |= 0x4B; |
| 327 | break; |
| 328 | case CS0_32M_CS1_32M_CS2_32M_CS3_32M: |
| 329 | reg &= ~0xFFF; /* CS0=32MB, CS1=32MB, CS2=32MB, CS3=32MB */ |
| 330 | reg |= 0x249; |
| 331 | break; |
| 332 | default: |
| 333 | printf("Unknown chip select size: %d\n", cs_size); |
| 334 | break; |
| 335 | } |
| 336 | |
| 337 | writel(reg, &iomuxc_regs->gpr[1]); |
| 338 | } |
Peng Fan | 7537e93 | 2018-01-10 13:20:25 +0800 | [diff] [blame] | 339 | #endif |
Fabio Estevam | 4555c26 | 2017-11-27 10:25:09 -0200 | [diff] [blame] | 340 | |
Peng Fan | cd357ad | 2018-11-20 10:19:25 +0000 | [diff] [blame] | 341 | #if defined(CONFIG_MX7) || defined(CONFIG_IMX8M) |
Peng Fan | 423e84b | 2018-01-10 13:20:29 +0800 | [diff] [blame] | 342 | /* |
| 343 | * OCOTP_TESTER3[9:8] (see Fusemap Description Table offset 0x440) |
| 344 | * defines a 2-bit SPEED_GRADING |
| 345 | */ |
| 346 | #define OCOTP_TESTER3_SPEED_SHIFT 8 |
Peng Fan | e56d9d7 | 2018-01-10 13:20:30 +0800 | [diff] [blame] | 347 | enum cpu_speed { |
| 348 | OCOTP_TESTER3_SPEED_GRADE0, |
| 349 | OCOTP_TESTER3_SPEED_GRADE1, |
| 350 | OCOTP_TESTER3_SPEED_GRADE2, |
| 351 | OCOTP_TESTER3_SPEED_GRADE3, |
| 352 | }; |
Peng Fan | 423e84b | 2018-01-10 13:20:29 +0800 | [diff] [blame] | 353 | |
| 354 | u32 get_cpu_speed_grade_hz(void) |
| 355 | { |
| 356 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 357 | struct fuse_bank *bank = &ocotp->bank[1]; |
| 358 | struct fuse_bank1_regs *fuse = |
| 359 | (struct fuse_bank1_regs *)bank->fuse_regs; |
| 360 | uint32_t val; |
| 361 | |
| 362 | val = readl(&fuse->tester3); |
| 363 | val >>= OCOTP_TESTER3_SPEED_SHIFT; |
| 364 | val &= 0x3; |
| 365 | |
| 366 | switch(val) { |
Peng Fan | e56d9d7 | 2018-01-10 13:20:30 +0800 | [diff] [blame] | 367 | case OCOTP_TESTER3_SPEED_GRADE0: |
Peng Fan | 423e84b | 2018-01-10 13:20:29 +0800 | [diff] [blame] | 368 | return 800000000; |
Peng Fan | e56d9d7 | 2018-01-10 13:20:30 +0800 | [diff] [blame] | 369 | case OCOTP_TESTER3_SPEED_GRADE1: |
| 370 | return is_mx7() ? 500000000 : 1000000000; |
| 371 | case OCOTP_TESTER3_SPEED_GRADE2: |
| 372 | return is_mx7() ? 1000000000 : 1300000000; |
| 373 | case OCOTP_TESTER3_SPEED_GRADE3: |
| 374 | return is_mx7() ? 1200000000 : 1500000000; |
Peng Fan | 423e84b | 2018-01-10 13:20:29 +0800 | [diff] [blame] | 375 | } |
Peng Fan | e56d9d7 | 2018-01-10 13:20:30 +0800 | [diff] [blame] | 376 | |
Peng Fan | 423e84b | 2018-01-10 13:20:29 +0800 | [diff] [blame] | 377 | return 0; |
| 378 | } |
| 379 | |
| 380 | /* |
| 381 | * OCOTP_TESTER3[7:6] (see Fusemap Description Table offset 0x440) |
| 382 | * defines a 2-bit SPEED_GRADING |
| 383 | */ |
| 384 | #define OCOTP_TESTER3_TEMP_SHIFT 6 |
| 385 | |
| 386 | u32 get_cpu_temp_grade(int *minc, int *maxc) |
| 387 | { |
| 388 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 389 | struct fuse_bank *bank = &ocotp->bank[1]; |
| 390 | struct fuse_bank1_regs *fuse = |
| 391 | (struct fuse_bank1_regs *)bank->fuse_regs; |
| 392 | uint32_t val; |
| 393 | |
| 394 | val = readl(&fuse->tester3); |
| 395 | val >>= OCOTP_TESTER3_TEMP_SHIFT; |
| 396 | val &= 0x3; |
| 397 | |
| 398 | if (minc && maxc) { |
| 399 | if (val == TEMP_AUTOMOTIVE) { |
| 400 | *minc = -40; |
| 401 | *maxc = 125; |
| 402 | } else if (val == TEMP_INDUSTRIAL) { |
| 403 | *minc = -40; |
| 404 | *maxc = 105; |
| 405 | } else if (val == TEMP_EXTCOMMERCIAL) { |
| 406 | *minc = -20; |
| 407 | *maxc = 105; |
| 408 | } else { |
| 409 | *minc = 0; |
| 410 | *maxc = 95; |
| 411 | } |
| 412 | } |
| 413 | return val; |
| 414 | } |
| 415 | #endif |
| 416 | |
Peng Fan | cd357ad | 2018-11-20 10:19:25 +0000 | [diff] [blame] | 417 | #if defined(CONFIG_MX7) || defined(CONFIG_IMX8M) |
Peng Fan | 770611f | 2018-01-10 13:20:34 +0800 | [diff] [blame] | 418 | enum boot_device get_boot_device(void) |
| 419 | { |
| 420 | struct bootrom_sw_info **p = |
| 421 | (struct bootrom_sw_info **)(ulong)ROM_SW_INFO_ADDR; |
| 422 | |
| 423 | enum boot_device boot_dev = SD1_BOOT; |
| 424 | u8 boot_type = (*p)->boot_dev_type; |
| 425 | u8 boot_instance = (*p)->boot_dev_instance; |
| 426 | |
| 427 | switch (boot_type) { |
| 428 | case BOOT_TYPE_SD: |
| 429 | boot_dev = boot_instance + SD1_BOOT; |
| 430 | break; |
| 431 | case BOOT_TYPE_MMC: |
| 432 | boot_dev = boot_instance + MMC1_BOOT; |
| 433 | break; |
| 434 | case BOOT_TYPE_NAND: |
| 435 | boot_dev = NAND_BOOT; |
| 436 | break; |
| 437 | case BOOT_TYPE_QSPI: |
| 438 | boot_dev = QSPI_BOOT; |
| 439 | break; |
| 440 | case BOOT_TYPE_WEIM: |
| 441 | boot_dev = WEIM_NOR_BOOT; |
| 442 | break; |
| 443 | case BOOT_TYPE_SPINOR: |
| 444 | boot_dev = SPI_NOR_BOOT; |
| 445 | break; |
Peng Fan | cd357ad | 2018-11-20 10:19:25 +0000 | [diff] [blame] | 446 | #ifdef CONFIG_IMX8M |
Peng Fan | 80ebf86 | 2018-01-10 13:20:35 +0800 | [diff] [blame] | 447 | case BOOT_TYPE_USB: |
| 448 | boot_dev = USB_BOOT; |
| 449 | break; |
| 450 | #endif |
Peng Fan | 770611f | 2018-01-10 13:20:34 +0800 | [diff] [blame] | 451 | default: |
| 452 | break; |
| 453 | } |
| 454 | |
| 455 | return boot_dev; |
| 456 | } |
| 457 | #endif |
| 458 | |
Fabio Estevam | 4555c26 | 2017-11-27 10:25:09 -0200 | [diff] [blame] | 459 | #ifdef CONFIG_NXP_BOARD_REVISION |
| 460 | int nxp_board_rev(void) |
| 461 | { |
| 462 | /* |
| 463 | * Get Board ID information from OCOTP_GP1[15:8] |
| 464 | * RevA: 0x1 |
| 465 | * RevB: 0x2 |
| 466 | * RevC: 0x3 |
| 467 | */ |
| 468 | struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR; |
| 469 | struct fuse_bank *bank = &ocotp->bank[4]; |
| 470 | struct fuse_bank4_regs *fuse = |
| 471 | (struct fuse_bank4_regs *)bank->fuse_regs; |
| 472 | |
| 473 | return (readl(&fuse->gp1) >> 8 & 0x0F); |
| 474 | } |
| 475 | |
| 476 | char nxp_board_rev_string(void) |
| 477 | { |
| 478 | const char *rev = "A"; |
| 479 | |
| 480 | return (*rev + nxp_board_rev() - 1); |
| 481 | } |
| 482 | #endif |