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