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 | |
| 10 | #include <common.h> |
| 11 | #include <asm/errno.h> |
| 12 | #include <asm/io.h> |
| 13 | #include <asm/arch/imx-regs.h> |
| 14 | #include <asm/arch/clock.h> |
| 15 | #include <asm/arch/sys_proto.h> |
Fabio Estevam | 6a37604 | 2012-04-29 08:11:13 +0000 | [diff] [blame] | 16 | #include <asm/arch/crm_regs.h> |
Eric Nelson | e1eb75b | 2012-09-23 07:30:55 +0000 | [diff] [blame] | 17 | #include <ipu_pixfmt.h> |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 18 | |
| 19 | #ifdef CONFIG_FSL_ESDHC |
| 20 | #include <fsl_esdhc.h> |
| 21 | #endif |
| 22 | |
Fabio Estevam | 1fc56f1 | 2012-04-30 08:12:03 +0000 | [diff] [blame] | 23 | char *get_reset_cause(void) |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 24 | { |
| 25 | u32 cause; |
| 26 | struct src *src_regs = (struct src *)SRC_BASE_ADDR; |
| 27 | |
| 28 | cause = readl(&src_regs->srsr); |
| 29 | writel(cause, &src_regs->srsr); |
| 30 | |
| 31 | switch (cause) { |
| 32 | case 0x00001: |
Fabio Estevam | cece262 | 2012-03-13 07:26:48 +0000 | [diff] [blame] | 33 | case 0x00011: |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 34 | return "POR"; |
| 35 | case 0x00004: |
| 36 | return "CSU"; |
| 37 | case 0x00008: |
| 38 | return "IPP USER"; |
| 39 | case 0x00010: |
| 40 | return "WDOG"; |
| 41 | case 0x00020: |
| 42 | return "JTAG HIGH-Z"; |
| 43 | case 0x00040: |
| 44 | return "JTAG SW"; |
| 45 | case 0x10000: |
| 46 | return "WARM BOOT"; |
| 47 | default: |
| 48 | return "unknown reset"; |
| 49 | } |
| 50 | } |
| 51 | |
Troy Kisky | eb0344d | 2012-10-23 10:57:48 +0000 | [diff] [blame] | 52 | #if defined(CONFIG_MX53) || defined(CONFIG_MX6) |
| 53 | #if defined(CONFIG_MX53) |
Eric Nelson | 3e9cbbb | 2013-11-08 16:50:53 -0700 | [diff] [blame] | 54 | #define MEMCTL_BASE ESDCTL_BASE_ADDR |
Troy Kisky | eb0344d | 2012-10-23 10:57:48 +0000 | [diff] [blame] | 55 | #else |
Eric Nelson | 3e9cbbb | 2013-11-08 16:50:53 -0700 | [diff] [blame] | 56 | #define MEMCTL_BASE MMDC_P0_BASE_ADDR |
Troy Kisky | eb0344d | 2012-10-23 10:57:48 +0000 | [diff] [blame] | 57 | #endif |
| 58 | static const unsigned char col_lookup[] = {9, 10, 11, 8, 12, 9, 9, 9}; |
| 59 | static const unsigned char bank_lookup[] = {3, 2}; |
| 60 | |
Tim Harvey | b07161c | 2014-06-02 16:13:21 -0700 | [diff] [blame] | 61 | /* these MMDC registers are common to the IMX53 and IMX6 */ |
Troy Kisky | eb0344d | 2012-10-23 10:57:48 +0000 | [diff] [blame] | 62 | struct esd_mmdc_regs { |
| 63 | uint32_t ctl; |
| 64 | uint32_t pdc; |
| 65 | uint32_t otc; |
| 66 | uint32_t cfg0; |
| 67 | uint32_t cfg1; |
| 68 | uint32_t cfg2; |
| 69 | uint32_t misc; |
Troy Kisky | eb0344d | 2012-10-23 10:57:48 +0000 | [diff] [blame] | 70 | }; |
| 71 | |
| 72 | #define ESD_MMDC_CTL_GET_ROW(mdctl) ((ctl >> 24) & 7) |
| 73 | #define ESD_MMDC_CTL_GET_COLUMN(mdctl) ((ctl >> 20) & 7) |
| 74 | #define ESD_MMDC_CTL_GET_WIDTH(mdctl) ((ctl >> 16) & 3) |
| 75 | #define ESD_MMDC_CTL_GET_CS1(mdctl) ((ctl >> 30) & 1) |
| 76 | #define ESD_MMDC_MISC_GET_BANK(mdmisc) ((misc >> 5) & 1) |
| 77 | |
Tim Harvey | b07161c | 2014-06-02 16:13:21 -0700 | [diff] [blame] | 78 | /* |
| 79 | * imx_ddr_size - return size in bytes of DRAM according MMDC config |
| 80 | * The MMDC MDCTL register holds the number of bits for row, col, and data |
| 81 | * width and the MMDC MDMISC register holds the number of banks. Combine |
| 82 | * all these bits to determine the meme size the MMDC has been configured for |
| 83 | */ |
Troy Kisky | eb0344d | 2012-10-23 10:57:48 +0000 | [diff] [blame] | 84 | unsigned imx_ddr_size(void) |
| 85 | { |
| 86 | struct esd_mmdc_regs *mem = (struct esd_mmdc_regs *)MEMCTL_BASE; |
| 87 | unsigned ctl = readl(&mem->ctl); |
| 88 | unsigned misc = readl(&mem->misc); |
| 89 | int bits = 11 + 0 + 0 + 1; /* row + col + bank + width */ |
| 90 | |
| 91 | bits += ESD_MMDC_CTL_GET_ROW(ctl); |
| 92 | bits += col_lookup[ESD_MMDC_CTL_GET_COLUMN(ctl)]; |
| 93 | bits += bank_lookup[ESD_MMDC_MISC_GET_BANK(misc)]; |
| 94 | bits += ESD_MMDC_CTL_GET_WIDTH(ctl); |
| 95 | bits += ESD_MMDC_CTL_GET_CS1(ctl); |
Marek Vasut | fcfdfdd | 2014-08-04 01:47:09 +0200 | [diff] [blame] | 96 | |
| 97 | /* The MX6 can do only 3840 MiB of DRAM */ |
| 98 | if (bits == 32) |
| 99 | return 0xf0000000; |
| 100 | |
Troy Kisky | eb0344d | 2012-10-23 10:57:48 +0000 | [diff] [blame] | 101 | return 1 << bits; |
| 102 | } |
| 103 | #endif |
| 104 | |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 105 | #if defined(CONFIG_DISPLAY_CPUINFO) |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 106 | |
Troy Kisky | 20332a0 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 107 | const char *get_imx_type(u32 imxtype) |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 108 | { |
| 109 | switch (imxtype) { |
Troy Kisky | 20332a0 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 110 | case MXC_CPU_MX6Q: |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 111 | return "6Q"; /* Quad-core version of the mx6 */ |
Fabio Estevam | 94db665 | 2014-01-26 15:06:41 -0200 | [diff] [blame] | 112 | case MXC_CPU_MX6D: |
| 113 | return "6D"; /* Dual-core version of the mx6 */ |
Troy Kisky | 20332a0 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 114 | case MXC_CPU_MX6DL: |
| 115 | return "6DL"; /* Dual Lite version of the mx6 */ |
| 116 | case MXC_CPU_MX6SOLO: |
| 117 | return "6SOLO"; /* Solo version of the mx6 */ |
| 118 | case MXC_CPU_MX6SL: |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 119 | return "6SL"; /* Solo-Lite version of the mx6 */ |
Fabio Estevam | 05d54b8 | 2014-06-24 17:40:58 -0300 | [diff] [blame] | 120 | case MXC_CPU_MX6SX: |
| 121 | return "6SX"; /* SoloX version of the mx6 */ |
Troy Kisky | 20332a0 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 122 | case MXC_CPU_MX51: |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 123 | return "51"; |
Troy Kisky | 20332a0 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 124 | case MXC_CPU_MX53: |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 125 | return "53"; |
| 126 | default: |
Otavio Salvador | e972d72 | 2012-06-30 05:07:32 +0000 | [diff] [blame] | 127 | return "??"; |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 128 | } |
| 129 | } |
| 130 | |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 131 | int print_cpuinfo(void) |
| 132 | { |
| 133 | u32 cpurev; |
| 134 | |
| 135 | cpurev = get_cpu_rev(); |
Fabio Estevam | a768386 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 136 | |
| 137 | printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n", |
| 138 | get_imx_type((cpurev & 0xFF000) >> 12), |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 139 | (cpurev & 0x000F0) >> 4, |
| 140 | (cpurev & 0x0000F) >> 0, |
| 141 | mxc_get_clock(MXC_ARM_CLK) / 1000000); |
| 142 | printf("Reset cause: %s\n", get_reset_cause()); |
| 143 | return 0; |
| 144 | } |
| 145 | #endif |
| 146 | |
| 147 | int cpu_eth_init(bd_t *bis) |
| 148 | { |
| 149 | int rc = -ENODEV; |
| 150 | |
| 151 | #if defined(CONFIG_FEC_MXC) |
| 152 | rc = fecmxc_initialize(bis); |
| 153 | #endif |
| 154 | |
| 155 | return rc; |
| 156 | } |
| 157 | |
Benoît Thébaudeau | ecb0f31 | 2012-08-17 10:42:55 +0000 | [diff] [blame] | 158 | #ifdef CONFIG_FSL_ESDHC |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 159 | /* |
| 160 | * Initializes on-chip MMC controllers. |
| 161 | * to override, implement board_mmc_init() |
| 162 | */ |
| 163 | int cpu_mmc_init(bd_t *bis) |
| 164 | { |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 165 | return fsl_esdhc_mmc_init(bis); |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 166 | } |
Benoît Thébaudeau | ecb0f31 | 2012-08-17 10:42:55 +0000 | [diff] [blame] | 167 | #endif |
Jason Liu | 18936ee | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 168 | |
Fabio Estevam | 6a37604 | 2012-04-29 08:11:13 +0000 | [diff] [blame] | 169 | u32 get_ahb_clk(void) |
| 170 | { |
| 171 | struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 172 | u32 reg, ahb_podf; |
| 173 | |
| 174 | reg = __raw_readl(&imx_ccm->cbcdr); |
| 175 | reg &= MXC_CCM_CBCDR_AHB_PODF_MASK; |
| 176 | ahb_podf = reg >> MXC_CCM_CBCDR_AHB_PODF_OFFSET; |
| 177 | |
| 178 | return get_periph_clk() / (ahb_podf + 1); |
| 179 | } |
Eric Nelson | e1eb75b | 2012-09-23 07:30:55 +0000 | [diff] [blame] | 180 | |
| 181 | #if defined(CONFIG_VIDEO_IPUV3) |
| 182 | void arch_preboot_os(void) |
| 183 | { |
| 184 | /* disable video before launching O/S */ |
| 185 | ipuv3_fb_shutdown(); |
| 186 | } |
| 187 | #endif |