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