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