Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 |
| 3 | * Sascha Hauer, Pengutronix |
| 4 | * |
| 5 | * (C) Copyright 2009 Freescale Semiconductor, Inc. |
| 6 | * |
Wolfgang Denk | 1a45966 | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 8 | */ |
| 9 | |
Jeroen Hofstee | 5624c6b | 2014-10-08 22:57:52 +0200 | [diff] [blame] | 10 | #include <bootm.h> |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 11 | #include <common.h> |
Jeroen Hofstee | 5624c6b | 2014-10-08 22:57:52 +0200 | [diff] [blame] | 12 | #include <netdev.h> |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 13 | #include <asm/errno.h> |
| 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> |
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 | |
| 24 | #ifdef CONFIG_FSL_ESDHC |
| 25 | #include <fsl_esdhc.h> |
| 26 | #endif |
| 27 | |
Prabhakar Kushwaha | 28420e7 | 2015-05-18 17:13:52 +0530 | [diff] [blame] | 28 | #if defined(CONFIG_DISPLAY_CPUINFO) |
Eric Nelson | 11c2e50 | 2015-02-15 14:37:21 -0700 | [diff] [blame] | 29 | static u32 reset_cause = -1; |
| 30 | |
| 31 | static char *get_reset_cause(void) |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 32 | { |
| 33 | u32 cause; |
| 34 | struct src *src_regs = (struct src *)SRC_BASE_ADDR; |
| 35 | |
| 36 | cause = readl(&src_regs->srsr); |
| 37 | writel(cause, &src_regs->srsr); |
Eric Nelson | 11c2e50 | 2015-02-15 14:37:21 -0700 | [diff] [blame] | 38 | reset_cause = cause; |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 39 | |
| 40 | switch (cause) { |
| 41 | case 0x00001: |
Fabio Estevam | cece262 | 2012-03-13 07:26:48 +0000 | [diff] [blame] | 42 | case 0x00011: |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 43 | return "POR"; |
| 44 | case 0x00004: |
| 45 | return "CSU"; |
| 46 | case 0x00008: |
| 47 | return "IPP USER"; |
| 48 | case 0x00010: |
| 49 | return "WDOG"; |
| 50 | case 0x00020: |
| 51 | return "JTAG HIGH-Z"; |
| 52 | case 0x00040: |
| 53 | return "JTAG SW"; |
| 54 | case 0x10000: |
| 55 | return "WARM BOOT"; |
| 56 | default: |
| 57 | return "unknown reset"; |
| 58 | } |
| 59 | } |
| 60 | |
Eric Nelson | 11c2e50 | 2015-02-15 14:37:21 -0700 | [diff] [blame] | 61 | u32 get_imx_reset_cause(void) |
| 62 | { |
| 63 | return reset_cause; |
| 64 | } |
Prabhakar Kushwaha | 28420e7 | 2015-05-18 17:13:52 +0530 | [diff] [blame] | 65 | #endif |
Eric Nelson | 11c2e50 | 2015-02-15 14:37:21 -0700 | [diff] [blame] | 66 | |
Troy Kisky | eb0344d | 2012-10-23 10:57:48 +0000 | [diff] [blame] | 67 | #if defined(CONFIG_MX53) || defined(CONFIG_MX6) |
| 68 | #if defined(CONFIG_MX53) |
Eric Nelson | 3e9cbbb | 2013-11-08 16:50:53 -0700 | [diff] [blame] | 69 | #define MEMCTL_BASE ESDCTL_BASE_ADDR |
Troy Kisky | eb0344d | 2012-10-23 10:57:48 +0000 | [diff] [blame] | 70 | #else |
Eric Nelson | 3e9cbbb | 2013-11-08 16:50:53 -0700 | [diff] [blame] | 71 | #define MEMCTL_BASE MMDC_P0_BASE_ADDR |
Troy Kisky | eb0344d | 2012-10-23 10:57:48 +0000 | [diff] [blame] | 72 | #endif |
| 73 | static const unsigned char col_lookup[] = {9, 10, 11, 8, 12, 9, 9, 9}; |
| 74 | static const unsigned char bank_lookup[] = {3, 2}; |
| 75 | |
Tim Harvey | b07161c | 2014-06-02 16:13:21 -0700 | [diff] [blame] | 76 | /* these MMDC registers are common to the IMX53 and IMX6 */ |
Troy Kisky | eb0344d | 2012-10-23 10:57:48 +0000 | [diff] [blame] | 77 | struct esd_mmdc_regs { |
| 78 | uint32_t ctl; |
| 79 | uint32_t pdc; |
| 80 | uint32_t otc; |
| 81 | uint32_t cfg0; |
| 82 | uint32_t cfg1; |
| 83 | uint32_t cfg2; |
| 84 | uint32_t misc; |
Troy Kisky | eb0344d | 2012-10-23 10:57:48 +0000 | [diff] [blame] | 85 | }; |
| 86 | |
| 87 | #define ESD_MMDC_CTL_GET_ROW(mdctl) ((ctl >> 24) & 7) |
| 88 | #define ESD_MMDC_CTL_GET_COLUMN(mdctl) ((ctl >> 20) & 7) |
| 89 | #define ESD_MMDC_CTL_GET_WIDTH(mdctl) ((ctl >> 16) & 3) |
| 90 | #define ESD_MMDC_CTL_GET_CS1(mdctl) ((ctl >> 30) & 1) |
| 91 | #define ESD_MMDC_MISC_GET_BANK(mdmisc) ((misc >> 5) & 1) |
| 92 | |
Tim Harvey | b07161c | 2014-06-02 16:13:21 -0700 | [diff] [blame] | 93 | /* |
| 94 | * imx_ddr_size - return size in bytes of DRAM according MMDC config |
| 95 | * The MMDC MDCTL register holds the number of bits for row, col, and data |
| 96 | * width and the MMDC MDMISC register holds the number of banks. Combine |
| 97 | * all these bits to determine the meme size the MMDC has been configured for |
| 98 | */ |
Troy Kisky | eb0344d | 2012-10-23 10:57:48 +0000 | [diff] [blame] | 99 | unsigned imx_ddr_size(void) |
| 100 | { |
| 101 | struct esd_mmdc_regs *mem = (struct esd_mmdc_regs *)MEMCTL_BASE; |
| 102 | unsigned ctl = readl(&mem->ctl); |
| 103 | unsigned misc = readl(&mem->misc); |
| 104 | int bits = 11 + 0 + 0 + 1; /* row + col + bank + width */ |
| 105 | |
| 106 | bits += ESD_MMDC_CTL_GET_ROW(ctl); |
| 107 | bits += col_lookup[ESD_MMDC_CTL_GET_COLUMN(ctl)]; |
| 108 | bits += bank_lookup[ESD_MMDC_MISC_GET_BANK(misc)]; |
| 109 | bits += ESD_MMDC_CTL_GET_WIDTH(ctl); |
| 110 | bits += ESD_MMDC_CTL_GET_CS1(ctl); |
Marek Vasut | fcfdfdd | 2014-08-04 01:47:09 +0200 | [diff] [blame] | 111 | |
| 112 | /* The MX6 can do only 3840 MiB of DRAM */ |
| 113 | if (bits == 32) |
| 114 | return 0xf0000000; |
| 115 | |
Troy Kisky | eb0344d | 2012-10-23 10:57:48 +0000 | [diff] [blame] | 116 | return 1 << bits; |
| 117 | } |
| 118 | #endif |
| 119 | |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 120 | #if defined(CONFIG_DISPLAY_CPUINFO) |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 121 | |
Troy Kisky | 20332a0 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 122 | const char *get_imx_type(u32 imxtype) |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 123 | { |
| 124 | switch (imxtype) { |
Peng Fan | d0acd99 | 2015-07-11 11:38:42 +0800 | [diff] [blame] | 125 | case MXC_CPU_MX6QP: |
| 126 | return "6QP"; /* Quad-Plus version of the mx6 */ |
| 127 | case MXC_CPU_MX6DP: |
| 128 | return "6DP"; /* Dual-Plus version of the mx6 */ |
Troy Kisky | 20332a0 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 129 | case MXC_CPU_MX6Q: |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 130 | return "6Q"; /* Quad-core version of the mx6 */ |
Fabio Estevam | 94db665 | 2014-01-26 15:06:41 -0200 | [diff] [blame] | 131 | case MXC_CPU_MX6D: |
| 132 | return "6D"; /* Dual-core version of the mx6 */ |
Troy Kisky | 20332a0 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 133 | case MXC_CPU_MX6DL: |
| 134 | return "6DL"; /* Dual Lite version of the mx6 */ |
| 135 | case MXC_CPU_MX6SOLO: |
| 136 | return "6SOLO"; /* Solo version of the mx6 */ |
| 137 | case MXC_CPU_MX6SL: |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 138 | return "6SL"; /* Solo-Lite version of the mx6 */ |
Fabio Estevam | 05d54b8 | 2014-06-24 17:40:58 -0300 | [diff] [blame] | 139 | case MXC_CPU_MX6SX: |
| 140 | return "6SX"; /* SoloX version of the mx6 */ |
Peng Fan | 8631c06 | 2015-07-20 19:28:21 +0800 | [diff] [blame] | 141 | case MXC_CPU_MX6UL: |
| 142 | return "6UL"; /* Ultra-Lite version of the mx6 */ |
Troy Kisky | 20332a0 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 143 | case MXC_CPU_MX51: |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 144 | return "51"; |
Troy Kisky | 20332a0 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 145 | case MXC_CPU_MX53: |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 146 | return "53"; |
| 147 | default: |
Otavio Salvador | e972d72 | 2012-06-30 05:07:32 +0000 | [diff] [blame] | 148 | return "??"; |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 149 | } |
| 150 | } |
| 151 | |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 152 | int print_cpuinfo(void) |
| 153 | { |
Stefano Babic | 943a3f2 | 2015-05-26 19:53:41 +0200 | [diff] [blame] | 154 | u32 cpurev; |
| 155 | __maybe_unused u32 max_freq; |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 156 | |
Ye.Li | 7a26416 | 2014-11-20 21:14:14 +0800 | [diff] [blame] | 157 | #if defined(CONFIG_MX6) && defined(CONFIG_IMX6_THERMAL) |
| 158 | struct udevice *thermal_dev; |
Tim Harvey | 70caa8e | 2015-05-18 06:56:46 -0700 | [diff] [blame] | 159 | int cpu_tmp, minc, maxc, ret; |
Ye.Li | 7a26416 | 2014-11-20 21:14:14 +0800 | [diff] [blame] | 160 | #endif |
| 161 | |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 162 | cpurev = get_cpu_rev(); |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 163 | |
Tim Harvey | b83ddac | 2015-05-18 07:02:25 -0700 | [diff] [blame] | 164 | #if defined(CONFIG_MX6) |
| 165 | printf("CPU: Freescale i.MX%s rev%d.%d", |
| 166 | get_imx_type((cpurev & 0xFF000) >> 12), |
| 167 | (cpurev & 0x000F0) >> 4, |
| 168 | (cpurev & 0x0000F) >> 0); |
| 169 | max_freq = get_cpu_speed_grade_hz(); |
| 170 | if (!max_freq || max_freq == mxc_get_clock(MXC_ARM_CLK)) { |
| 171 | printf(" at %dMHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000); |
| 172 | } else { |
| 173 | printf(" %d MHz (running at %d MHz)\n", max_freq / 1000000, |
| 174 | mxc_get_clock(MXC_ARM_CLK) / 1000000); |
| 175 | } |
| 176 | #else |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 177 | printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n", |
| 178 | get_imx_type((cpurev & 0xFF000) >> 12), |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 179 | (cpurev & 0x000F0) >> 4, |
| 180 | (cpurev & 0x0000F) >> 0, |
| 181 | mxc_get_clock(MXC_ARM_CLK) / 1000000); |
Tim Harvey | b83ddac | 2015-05-18 07:02:25 -0700 | [diff] [blame] | 182 | #endif |
Ye.Li | 7a26416 | 2014-11-20 21:14:14 +0800 | [diff] [blame] | 183 | |
| 184 | #if defined(CONFIG_MX6) && defined(CONFIG_IMX6_THERMAL) |
Tim Harvey | 70caa8e | 2015-05-18 06:56:46 -0700 | [diff] [blame] | 185 | puts("CPU: "); |
| 186 | switch (get_cpu_temp_grade(&minc, &maxc)) { |
| 187 | case TEMP_AUTOMOTIVE: |
| 188 | puts("Automotive temperature grade "); |
| 189 | break; |
| 190 | case TEMP_INDUSTRIAL: |
| 191 | puts("Industrial temperature grade "); |
| 192 | break; |
| 193 | case TEMP_EXTCOMMERCIAL: |
| 194 | puts("Extended Commercial temperature grade "); |
| 195 | break; |
| 196 | default: |
| 197 | puts("Commercial temperature grade "); |
| 198 | break; |
| 199 | } |
| 200 | printf("(%dC to %dC)", minc, maxc); |
Ye.Li | 7a26416 | 2014-11-20 21:14:14 +0800 | [diff] [blame] | 201 | ret = uclass_get_device(UCLASS_THERMAL, 0, &thermal_dev); |
| 202 | if (!ret) { |
| 203 | ret = thermal_get_temp(thermal_dev, &cpu_tmp); |
| 204 | |
| 205 | if (!ret) |
Tim Harvey | 70caa8e | 2015-05-18 06:56:46 -0700 | [diff] [blame] | 206 | printf(" at %dC\n", cpu_tmp); |
Ye.Li | 7a26416 | 2014-11-20 21:14:14 +0800 | [diff] [blame] | 207 | else |
Tim Harvey | 70caa8e | 2015-05-18 06:56:46 -0700 | [diff] [blame] | 208 | puts(" - invalid sensor data\n"); |
Ye.Li | 7a26416 | 2014-11-20 21:14:14 +0800 | [diff] [blame] | 209 | } else { |
Tim Harvey | 70caa8e | 2015-05-18 06:56:46 -0700 | [diff] [blame] | 210 | puts(" - invalid sensor device\n"); |
Ye.Li | 7a26416 | 2014-11-20 21:14:14 +0800 | [diff] [blame] | 211 | } |
| 212 | #endif |
| 213 | |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 214 | printf("Reset cause: %s\n", get_reset_cause()); |
| 215 | return 0; |
| 216 | } |
| 217 | #endif |
| 218 | |
| 219 | int cpu_eth_init(bd_t *bis) |
| 220 | { |
| 221 | int rc = -ENODEV; |
| 222 | |
| 223 | #if defined(CONFIG_FEC_MXC) |
| 224 | rc = fecmxc_initialize(bis); |
| 225 | #endif |
| 226 | |
| 227 | return rc; |
| 228 | } |
| 229 | |
Benoît Thébaudeau | ecb0f31 | 2012-08-17 10:42:55 +0000 | [diff] [blame] | 230 | #ifdef CONFIG_FSL_ESDHC |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 231 | /* |
| 232 | * Initializes on-chip MMC controllers. |
| 233 | * to override, implement board_mmc_init() |
| 234 | */ |
| 235 | int cpu_mmc_init(bd_t *bis) |
| 236 | { |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 237 | return fsl_esdhc_mmc_init(bis); |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 238 | } |
Benoît Thébaudeau | ecb0f31 | 2012-08-17 10:42:55 +0000 | [diff] [blame] | 239 | #endif |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 240 | |
Fabio Estevam | 6a37604 | 2012-04-29 08:11:13 +0000 | [diff] [blame] | 241 | u32 get_ahb_clk(void) |
| 242 | { |
| 243 | struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 244 | u32 reg, ahb_podf; |
| 245 | |
| 246 | reg = __raw_readl(&imx_ccm->cbcdr); |
| 247 | reg &= MXC_CCM_CBCDR_AHB_PODF_MASK; |
| 248 | ahb_podf = reg >> MXC_CCM_CBCDR_AHB_PODF_OFFSET; |
| 249 | |
| 250 | return get_periph_clk() / (ahb_podf + 1); |
| 251 | } |
Eric Nelson | e1eb75b | 2012-09-23 07:30:55 +0000 | [diff] [blame] | 252 | |
Eric Nelson | e1eb75b | 2012-09-23 07:30:55 +0000 | [diff] [blame] | 253 | void arch_preboot_os(void) |
| 254 | { |
Nikita Kiryanov | 44b9841 | 2014-11-21 12:47:26 +0200 | [diff] [blame] | 255 | #if defined(CONFIG_CMD_SATA) |
| 256 | sata_stop(); |
Soeren Moch | dd1c8f1 | 2014-11-27 10:11:41 +0100 | [diff] [blame] | 257 | #if defined(CONFIG_MX6) |
| 258 | disable_sata_clock(); |
| 259 | #endif |
Nikita Kiryanov | 44b9841 | 2014-11-21 12:47:26 +0200 | [diff] [blame] | 260 | #endif |
| 261 | #if defined(CONFIG_VIDEO_IPUV3) |
Eric Nelson | e1eb75b | 2012-09-23 07:30:55 +0000 | [diff] [blame] | 262 | /* disable video before launching O/S */ |
| 263 | ipuv3_fb_shutdown(); |
Eric Nelson | e1eb75b | 2012-09-23 07:30:55 +0000 | [diff] [blame] | 264 | #endif |
Nikita Kiryanov | 44b9841 | 2014-11-21 12:47:26 +0200 | [diff] [blame] | 265 | } |
Fabio Estevam | 32c81ea | 2014-11-14 11:27:21 -0200 | [diff] [blame] | 266 | |
| 267 | void set_chipselect_size(int const cs_size) |
| 268 | { |
| 269 | unsigned int reg; |
| 270 | struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR; |
| 271 | reg = readl(&iomuxc_regs->gpr[1]); |
| 272 | |
| 273 | switch (cs_size) { |
| 274 | case CS0_128: |
| 275 | reg &= ~0x7; /* CS0=128MB, CS1=0, CS2=0, CS3=0 */ |
| 276 | reg |= 0x5; |
| 277 | break; |
| 278 | case CS0_64M_CS1_64M: |
| 279 | reg &= ~0x3F; /* CS0=64MB, CS1=64MB, CS2=0, CS3=0 */ |
| 280 | reg |= 0x1B; |
| 281 | break; |
| 282 | case CS0_64M_CS1_32M_CS2_32M: |
| 283 | reg &= ~0x1FF; /* CS0=64MB, CS1=32MB, CS2=32MB, CS3=0 */ |
| 284 | reg |= 0x4B; |
| 285 | break; |
| 286 | case CS0_32M_CS1_32M_CS2_32M_CS3_32M: |
| 287 | reg &= ~0xFFF; /* CS0=32MB, CS1=32MB, CS2=32MB, CS3=32MB */ |
| 288 | reg |= 0x249; |
| 289 | break; |
| 290 | default: |
| 291 | printf("Unknown chip select size: %d\n", cs_size); |
| 292 | break; |
| 293 | } |
| 294 | |
| 295 | writel(reg, &iomuxc_regs->gpr[1]); |
| 296 | } |