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 | |
| 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 | 6479f51 | 2012-04-29 08:11:13 +0000 | [diff] [blame] | 16 | #include <asm/arch/crm_regs.h> |
Eric Nelson | 54b3f3b | 2012-09-23 07:30:55 +0000 | [diff] [blame] | 17 | #include <ipu_pixfmt.h> |
Jason Liu | 83aa8fe | 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 | 026c986 | 2012-04-30 08:12:03 +0000 | [diff] [blame] | 23 | char *get_reset_cause(void) |
Jason Liu | 83aa8fe | 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 | 9af122b | 2012-03-13 07:26:48 +0000 | [diff] [blame] | 33 | case 0x00011: |
Jason Liu | 83aa8fe | 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 | b3aec6a | 2012-10-23 10:57:48 +0000 | [diff] [blame] | 52 | #if defined(CONFIG_MX53) || defined(CONFIG_MX6) |
| 53 | #if defined(CONFIG_MX53) |
Eric Nelson | c7d4612 | 2013-11-08 16:50:53 -0700 | [diff] [blame] | 54 | #define MEMCTL_BASE ESDCTL_BASE_ADDR |
Troy Kisky | b3aec6a | 2012-10-23 10:57:48 +0000 | [diff] [blame] | 55 | #else |
Eric Nelson | c7d4612 | 2013-11-08 16:50:53 -0700 | [diff] [blame] | 56 | #define MEMCTL_BASE MMDC_P0_BASE_ADDR |
Troy Kisky | b3aec6a | 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 | |
| 61 | struct esd_mmdc_regs { |
| 62 | uint32_t ctl; |
| 63 | uint32_t pdc; |
| 64 | uint32_t otc; |
| 65 | uint32_t cfg0; |
| 66 | uint32_t cfg1; |
| 67 | uint32_t cfg2; |
| 68 | uint32_t misc; |
| 69 | uint32_t scr; |
| 70 | uint32_t ref; |
| 71 | uint32_t rsvd1; |
| 72 | uint32_t rsvd2; |
| 73 | uint32_t rwd; |
| 74 | uint32_t or; |
| 75 | uint32_t mrr; |
| 76 | uint32_t cfg3lp; |
| 77 | uint32_t mr4; |
| 78 | }; |
| 79 | |
| 80 | #define ESD_MMDC_CTL_GET_ROW(mdctl) ((ctl >> 24) & 7) |
| 81 | #define ESD_MMDC_CTL_GET_COLUMN(mdctl) ((ctl >> 20) & 7) |
| 82 | #define ESD_MMDC_CTL_GET_WIDTH(mdctl) ((ctl >> 16) & 3) |
| 83 | #define ESD_MMDC_CTL_GET_CS1(mdctl) ((ctl >> 30) & 1) |
| 84 | #define ESD_MMDC_MISC_GET_BANK(mdmisc) ((misc >> 5) & 1) |
| 85 | |
| 86 | unsigned imx_ddr_size(void) |
| 87 | { |
| 88 | struct esd_mmdc_regs *mem = (struct esd_mmdc_regs *)MEMCTL_BASE; |
| 89 | unsigned ctl = readl(&mem->ctl); |
| 90 | unsigned misc = readl(&mem->misc); |
| 91 | int bits = 11 + 0 + 0 + 1; /* row + col + bank + width */ |
| 92 | |
| 93 | bits += ESD_MMDC_CTL_GET_ROW(ctl); |
| 94 | bits += col_lookup[ESD_MMDC_CTL_GET_COLUMN(ctl)]; |
| 95 | bits += bank_lookup[ESD_MMDC_MISC_GET_BANK(misc)]; |
| 96 | bits += ESD_MMDC_CTL_GET_WIDTH(ctl); |
| 97 | bits += ESD_MMDC_CTL_GET_CS1(ctl); |
| 98 | return 1 << bits; |
| 99 | } |
| 100 | #endif |
| 101 | |
Jason Liu | 83aa8fe | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 102 | #if defined(CONFIG_DISPLAY_CPUINFO) |
Fabio Estevam | 46e9733 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 103 | |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 104 | const char *get_imx_type(u32 imxtype) |
Fabio Estevam | 46e9733 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 105 | { |
| 106 | switch (imxtype) { |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 107 | case MXC_CPU_MX6Q: |
Fabio Estevam | 46e9733 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 108 | return "6Q"; /* Quad-core version of the mx6 */ |
Fabio Estevam | f3d5a2c | 2014-01-26 15:06:41 -0200 | [diff] [blame] | 109 | case MXC_CPU_MX6D: |
| 110 | return "6D"; /* Dual-core version of the mx6 */ |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 111 | case MXC_CPU_MX6DL: |
| 112 | return "6DL"; /* Dual Lite version of the mx6 */ |
| 113 | case MXC_CPU_MX6SOLO: |
| 114 | return "6SOLO"; /* Solo version of the mx6 */ |
| 115 | case MXC_CPU_MX6SL: |
Fabio Estevam | 46e9733 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 116 | return "6SL"; /* Solo-Lite version of the mx6 */ |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 117 | case MXC_CPU_MX51: |
Fabio Estevam | 46e9733 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 118 | return "51"; |
Troy Kisky | 5839493 | 2012-10-23 10:57:46 +0000 | [diff] [blame] | 119 | case MXC_CPU_MX53: |
Fabio Estevam | 46e9733 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 120 | return "53"; |
| 121 | default: |
Otavio Salvador | 8567d7d | 2012-06-30 05:07:32 +0000 | [diff] [blame] | 122 | return "??"; |
Fabio Estevam | 46e9733 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 123 | } |
| 124 | } |
| 125 | |
Jason Liu | 83aa8fe | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 126 | int print_cpuinfo(void) |
| 127 | { |
| 128 | u32 cpurev; |
| 129 | |
| 130 | cpurev = get_cpu_rev(); |
Fabio Estevam | 46e9733 | 2012-03-20 04:21:45 +0000 | [diff] [blame] | 131 | |
| 132 | printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n", |
| 133 | get_imx_type((cpurev & 0xFF000) >> 12), |
Jason Liu | 83aa8fe | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 134 | (cpurev & 0x000F0) >> 4, |
| 135 | (cpurev & 0x0000F) >> 0, |
| 136 | mxc_get_clock(MXC_ARM_CLK) / 1000000); |
| 137 | printf("Reset cause: %s\n", get_reset_cause()); |
| 138 | return 0; |
| 139 | } |
| 140 | #endif |
| 141 | |
| 142 | int cpu_eth_init(bd_t *bis) |
| 143 | { |
| 144 | int rc = -ENODEV; |
| 145 | |
| 146 | #if defined(CONFIG_FEC_MXC) |
| 147 | rc = fecmxc_initialize(bis); |
| 148 | #endif |
| 149 | |
| 150 | return rc; |
| 151 | } |
| 152 | |
Benoît Thébaudeau | 58d2232 | 2012-08-17 10:42:55 +0000 | [diff] [blame] | 153 | #ifdef CONFIG_FSL_ESDHC |
Jason Liu | 83aa8fe | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 154 | /* |
| 155 | * Initializes on-chip MMC controllers. |
| 156 | * to override, implement board_mmc_init() |
| 157 | */ |
| 158 | int cpu_mmc_init(bd_t *bis) |
| 159 | { |
Jason Liu | 83aa8fe | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 160 | return fsl_esdhc_mmc_init(bis); |
Jason Liu | 83aa8fe | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 161 | } |
Benoît Thébaudeau | 58d2232 | 2012-08-17 10:42:55 +0000 | [diff] [blame] | 162 | #endif |
Jason Liu | 83aa8fe | 2011-11-25 00:18:01 +0000 | [diff] [blame] | 163 | |
Fabio Estevam | 6479f51 | 2012-04-29 08:11:13 +0000 | [diff] [blame] | 164 | u32 get_ahb_clk(void) |
| 165 | { |
| 166 | struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR; |
| 167 | u32 reg, ahb_podf; |
| 168 | |
| 169 | reg = __raw_readl(&imx_ccm->cbcdr); |
| 170 | reg &= MXC_CCM_CBCDR_AHB_PODF_MASK; |
| 171 | ahb_podf = reg >> MXC_CCM_CBCDR_AHB_PODF_OFFSET; |
| 172 | |
| 173 | return get_periph_clk() / (ahb_podf + 1); |
| 174 | } |
Eric Nelson | 54b3f3b | 2012-09-23 07:30:55 +0000 | [diff] [blame] | 175 | |
| 176 | #if defined(CONFIG_VIDEO_IPUV3) |
| 177 | void arch_preboot_os(void) |
| 178 | { |
| 179 | /* disable video before launching O/S */ |
| 180 | ipuv3_fb_shutdown(); |
| 181 | } |
| 182 | #endif |