blob: 09fc22760d0c6e973359f121f92c63feed26793d [file] [log] [blame]
Jason Liu18936ee2011-11-25 00:18:01 +00001/*
2 * (C) Copyright 2007
3 * Sascha Hauer, Pengutronix
4 *
5 * (C) Copyright 2009 Freescale Semiconductor, Inc.
6 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Jason Liu18936ee2011-11-25 00:18:01 +00008 */
9
Jeroen Hofstee5624c6b2014-10-08 22:57:52 +020010#include <bootm.h>
Jason Liu18936ee2011-11-25 00:18:01 +000011#include <common.h>
Jeroen Hofstee5624c6b2014-10-08 22:57:52 +020012#include <netdev.h>
Jason Liu18936ee2011-11-25 00:18:01 +000013#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 Estevam6a376042012-04-29 08:11:13 +000018#include <asm/arch/crm_regs.h>
Eric Nelsone1eb75b2012-09-23 07:30:55 +000019#include <ipu_pixfmt.h>
Jason Liu18936ee2011-11-25 00:18:01 +000020
21#ifdef CONFIG_FSL_ESDHC
22#include <fsl_esdhc.h>
23#endif
24
Fabio Estevam1fc56f12012-04-30 08:12:03 +000025char *get_reset_cause(void)
Jason Liu18936ee2011-11-25 00:18:01 +000026{
27 u32 cause;
28 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
29
30 cause = readl(&src_regs->srsr);
31 writel(cause, &src_regs->srsr);
32
33 switch (cause) {
34 case 0x00001:
Fabio Estevamcece2622012-03-13 07:26:48 +000035 case 0x00011:
Jason Liu18936ee2011-11-25 00:18:01 +000036 return "POR";
37 case 0x00004:
38 return "CSU";
39 case 0x00008:
40 return "IPP USER";
41 case 0x00010:
42 return "WDOG";
43 case 0x00020:
44 return "JTAG HIGH-Z";
45 case 0x00040:
46 return "JTAG SW";
47 case 0x10000:
48 return "WARM BOOT";
49 default:
50 return "unknown reset";
51 }
52}
53
Troy Kiskyeb0344d2012-10-23 10:57:48 +000054#if defined(CONFIG_MX53) || defined(CONFIG_MX6)
55#if defined(CONFIG_MX53)
Eric Nelson3e9cbbb2013-11-08 16:50:53 -070056#define MEMCTL_BASE ESDCTL_BASE_ADDR
Troy Kiskyeb0344d2012-10-23 10:57:48 +000057#else
Eric Nelson3e9cbbb2013-11-08 16:50:53 -070058#define MEMCTL_BASE MMDC_P0_BASE_ADDR
Troy Kiskyeb0344d2012-10-23 10:57:48 +000059#endif
60static const unsigned char col_lookup[] = {9, 10, 11, 8, 12, 9, 9, 9};
61static const unsigned char bank_lookup[] = {3, 2};
62
Tim Harveyb07161c2014-06-02 16:13:21 -070063/* these MMDC registers are common to the IMX53 and IMX6 */
Troy Kiskyeb0344d2012-10-23 10:57:48 +000064struct esd_mmdc_regs {
65 uint32_t ctl;
66 uint32_t pdc;
67 uint32_t otc;
68 uint32_t cfg0;
69 uint32_t cfg1;
70 uint32_t cfg2;
71 uint32_t misc;
Troy Kiskyeb0344d2012-10-23 10:57:48 +000072};
73
74#define ESD_MMDC_CTL_GET_ROW(mdctl) ((ctl >> 24) & 7)
75#define ESD_MMDC_CTL_GET_COLUMN(mdctl) ((ctl >> 20) & 7)
76#define ESD_MMDC_CTL_GET_WIDTH(mdctl) ((ctl >> 16) & 3)
77#define ESD_MMDC_CTL_GET_CS1(mdctl) ((ctl >> 30) & 1)
78#define ESD_MMDC_MISC_GET_BANK(mdmisc) ((misc >> 5) & 1)
79
Tim Harveyb07161c2014-06-02 16:13:21 -070080/*
81 * imx_ddr_size - return size in bytes of DRAM according MMDC config
82 * The MMDC MDCTL register holds the number of bits for row, col, and data
83 * width and the MMDC MDMISC register holds the number of banks. Combine
84 * all these bits to determine the meme size the MMDC has been configured for
85 */
Troy Kiskyeb0344d2012-10-23 10:57:48 +000086unsigned 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);
Marek Vasutfcfdfdd2014-08-04 01:47:09 +020098
99 /* The MX6 can do only 3840 MiB of DRAM */
100 if (bits == 32)
101 return 0xf0000000;
102
Troy Kiskyeb0344d2012-10-23 10:57:48 +0000103 return 1 << bits;
104}
105#endif
106
Jason Liu18936ee2011-11-25 00:18:01 +0000107#if defined(CONFIG_DISPLAY_CPUINFO)
Fabio Estevama7683862012-03-20 04:21:45 +0000108
Troy Kisky20332a02012-10-23 10:57:46 +0000109const char *get_imx_type(u32 imxtype)
Fabio Estevama7683862012-03-20 04:21:45 +0000110{
111 switch (imxtype) {
Troy Kisky20332a02012-10-23 10:57:46 +0000112 case MXC_CPU_MX6Q:
Fabio Estevama7683862012-03-20 04:21:45 +0000113 return "6Q"; /* Quad-core version of the mx6 */
Fabio Estevam94db6652014-01-26 15:06:41 -0200114 case MXC_CPU_MX6D:
115 return "6D"; /* Dual-core version of the mx6 */
Troy Kisky20332a02012-10-23 10:57:46 +0000116 case MXC_CPU_MX6DL:
117 return "6DL"; /* Dual Lite version of the mx6 */
118 case MXC_CPU_MX6SOLO:
119 return "6SOLO"; /* Solo version of the mx6 */
120 case MXC_CPU_MX6SL:
Fabio Estevama7683862012-03-20 04:21:45 +0000121 return "6SL"; /* Solo-Lite version of the mx6 */
Fabio Estevam05d54b82014-06-24 17:40:58 -0300122 case MXC_CPU_MX6SX:
123 return "6SX"; /* SoloX version of the mx6 */
Troy Kisky20332a02012-10-23 10:57:46 +0000124 case MXC_CPU_MX51:
Fabio Estevama7683862012-03-20 04:21:45 +0000125 return "51";
Troy Kisky20332a02012-10-23 10:57:46 +0000126 case MXC_CPU_MX53:
Fabio Estevama7683862012-03-20 04:21:45 +0000127 return "53";
128 default:
Otavio Salvadore972d722012-06-30 05:07:32 +0000129 return "??";
Fabio Estevama7683862012-03-20 04:21:45 +0000130 }
131}
132
Jason Liu18936ee2011-11-25 00:18:01 +0000133int print_cpuinfo(void)
134{
135 u32 cpurev;
136
137 cpurev = get_cpu_rev();
Fabio Estevama7683862012-03-20 04:21:45 +0000138
139 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
140 get_imx_type((cpurev & 0xFF000) >> 12),
Jason Liu18936ee2011-11-25 00:18:01 +0000141 (cpurev & 0x000F0) >> 4,
142 (cpurev & 0x0000F) >> 0,
143 mxc_get_clock(MXC_ARM_CLK) / 1000000);
144 printf("Reset cause: %s\n", get_reset_cause());
145 return 0;
146}
147#endif
148
149int cpu_eth_init(bd_t *bis)
150{
151 int rc = -ENODEV;
152
153#if defined(CONFIG_FEC_MXC)
154 rc = fecmxc_initialize(bis);
155#endif
156
157 return rc;
158}
159
Benoît Thébaudeauecb0f312012-08-17 10:42:55 +0000160#ifdef CONFIG_FSL_ESDHC
Jason Liu18936ee2011-11-25 00:18:01 +0000161/*
162 * Initializes on-chip MMC controllers.
163 * to override, implement board_mmc_init()
164 */
165int cpu_mmc_init(bd_t *bis)
166{
Jason Liu18936ee2011-11-25 00:18:01 +0000167 return fsl_esdhc_mmc_init(bis);
Jason Liu18936ee2011-11-25 00:18:01 +0000168}
Benoît Thébaudeauecb0f312012-08-17 10:42:55 +0000169#endif
Jason Liu18936ee2011-11-25 00:18:01 +0000170
Fabio Estevam6a376042012-04-29 08:11:13 +0000171u32 get_ahb_clk(void)
172{
173 struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
174 u32 reg, ahb_podf;
175
176 reg = __raw_readl(&imx_ccm->cbcdr);
177 reg &= MXC_CCM_CBCDR_AHB_PODF_MASK;
178 ahb_podf = reg >> MXC_CCM_CBCDR_AHB_PODF_OFFSET;
179
180 return get_periph_clk() / (ahb_podf + 1);
181}
Eric Nelsone1eb75b2012-09-23 07:30:55 +0000182
183#if defined(CONFIG_VIDEO_IPUV3)
184void arch_preboot_os(void)
185{
186 /* disable video before launching O/S */
187 ipuv3_fb_shutdown();
188}
189#endif