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