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