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