blob: 8b2dfca6116d498e00a08047df96c0ce5781f2ab [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>
Ye.Li7a264162014-11-20 21:14:14 +080020#include <thermal.h>
Jason Liu18936ee2011-11-25 00:18:01 +000021
22#ifdef CONFIG_FSL_ESDHC
23#include <fsl_esdhc.h>
24#endif
25
Fabio Estevam1fc56f12012-04-30 08:12:03 +000026char *get_reset_cause(void)
Jason Liu18936ee2011-11-25 00:18:01 +000027{
28 u32 cause;
29 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
30
31 cause = readl(&src_regs->srsr);
32 writel(cause, &src_regs->srsr);
33
34 switch (cause) {
35 case 0x00001:
Fabio Estevamcece2622012-03-13 07:26:48 +000036 case 0x00011:
Jason Liu18936ee2011-11-25 00:18:01 +000037 return "POR";
38 case 0x00004:
39 return "CSU";
40 case 0x00008:
41 return "IPP USER";
42 case 0x00010:
43 return "WDOG";
44 case 0x00020:
45 return "JTAG HIGH-Z";
46 case 0x00040:
47 return "JTAG SW";
48 case 0x10000:
49 return "WARM BOOT";
50 default:
51 return "unknown reset";
52 }
53}
54
Troy Kiskyeb0344d2012-10-23 10:57:48 +000055#if defined(CONFIG_MX53) || defined(CONFIG_MX6)
56#if defined(CONFIG_MX53)
Eric Nelson3e9cbbb2013-11-08 16:50:53 -070057#define MEMCTL_BASE ESDCTL_BASE_ADDR
Troy Kiskyeb0344d2012-10-23 10:57:48 +000058#else
Eric Nelson3e9cbbb2013-11-08 16:50:53 -070059#define MEMCTL_BASE MMDC_P0_BASE_ADDR
Troy Kiskyeb0344d2012-10-23 10:57:48 +000060#endif
61static const unsigned char col_lookup[] = {9, 10, 11, 8, 12, 9, 9, 9};
62static const unsigned char bank_lookup[] = {3, 2};
63
Tim Harveyb07161c2014-06-02 16:13:21 -070064/* these MMDC registers are common to the IMX53 and IMX6 */
Troy Kiskyeb0344d2012-10-23 10:57:48 +000065struct esd_mmdc_regs {
66 uint32_t ctl;
67 uint32_t pdc;
68 uint32_t otc;
69 uint32_t cfg0;
70 uint32_t cfg1;
71 uint32_t cfg2;
72 uint32_t misc;
Troy Kiskyeb0344d2012-10-23 10:57:48 +000073};
74
75#define ESD_MMDC_CTL_GET_ROW(mdctl) ((ctl >> 24) & 7)
76#define ESD_MMDC_CTL_GET_COLUMN(mdctl) ((ctl >> 20) & 7)
77#define ESD_MMDC_CTL_GET_WIDTH(mdctl) ((ctl >> 16) & 3)
78#define ESD_MMDC_CTL_GET_CS1(mdctl) ((ctl >> 30) & 1)
79#define ESD_MMDC_MISC_GET_BANK(mdmisc) ((misc >> 5) & 1)
80
Tim Harveyb07161c2014-06-02 16:13:21 -070081/*
82 * imx_ddr_size - return size in bytes of DRAM according MMDC config
83 * The MMDC MDCTL register holds the number of bits for row, col, and data
84 * width and the MMDC MDMISC register holds the number of banks. Combine
85 * all these bits to determine the meme size the MMDC has been configured for
86 */
Troy Kiskyeb0344d2012-10-23 10:57:48 +000087unsigned imx_ddr_size(void)
88{
89 struct esd_mmdc_regs *mem = (struct esd_mmdc_regs *)MEMCTL_BASE;
90 unsigned ctl = readl(&mem->ctl);
91 unsigned misc = readl(&mem->misc);
92 int bits = 11 + 0 + 0 + 1; /* row + col + bank + width */
93
94 bits += ESD_MMDC_CTL_GET_ROW(ctl);
95 bits += col_lookup[ESD_MMDC_CTL_GET_COLUMN(ctl)];
96 bits += bank_lookup[ESD_MMDC_MISC_GET_BANK(misc)];
97 bits += ESD_MMDC_CTL_GET_WIDTH(ctl);
98 bits += ESD_MMDC_CTL_GET_CS1(ctl);
Marek Vasutfcfdfdd2014-08-04 01:47:09 +020099
100 /* The MX6 can do only 3840 MiB of DRAM */
101 if (bits == 32)
102 return 0xf0000000;
103
Troy Kiskyeb0344d2012-10-23 10:57:48 +0000104 return 1 << bits;
105}
106#endif
107
Jason Liu18936ee2011-11-25 00:18:01 +0000108#if defined(CONFIG_DISPLAY_CPUINFO)
Fabio Estevama7683862012-03-20 04:21:45 +0000109
Troy Kisky20332a02012-10-23 10:57:46 +0000110const char *get_imx_type(u32 imxtype)
Fabio Estevama7683862012-03-20 04:21:45 +0000111{
112 switch (imxtype) {
Troy Kisky20332a02012-10-23 10:57:46 +0000113 case MXC_CPU_MX6Q:
Fabio Estevama7683862012-03-20 04:21:45 +0000114 return "6Q"; /* Quad-core version of the mx6 */
Fabio Estevam94db6652014-01-26 15:06:41 -0200115 case MXC_CPU_MX6D:
116 return "6D"; /* Dual-core version of the mx6 */
Troy Kisky20332a02012-10-23 10:57:46 +0000117 case MXC_CPU_MX6DL:
118 return "6DL"; /* Dual Lite version of the mx6 */
119 case MXC_CPU_MX6SOLO:
120 return "6SOLO"; /* Solo version of the mx6 */
121 case MXC_CPU_MX6SL:
Fabio Estevama7683862012-03-20 04:21:45 +0000122 return "6SL"; /* Solo-Lite version of the mx6 */
Fabio Estevam05d54b82014-06-24 17:40:58 -0300123 case MXC_CPU_MX6SX:
124 return "6SX"; /* SoloX version of the mx6 */
Troy Kisky20332a02012-10-23 10:57:46 +0000125 case MXC_CPU_MX51:
Fabio Estevama7683862012-03-20 04:21:45 +0000126 return "51";
Troy Kisky20332a02012-10-23 10:57:46 +0000127 case MXC_CPU_MX53:
Fabio Estevama7683862012-03-20 04:21:45 +0000128 return "53";
129 default:
Otavio Salvadore972d722012-06-30 05:07:32 +0000130 return "??";
Fabio Estevama7683862012-03-20 04:21:45 +0000131 }
132}
133
Jason Liu18936ee2011-11-25 00:18:01 +0000134int print_cpuinfo(void)
135{
136 u32 cpurev;
137
Ye.Li7a264162014-11-20 21:14:14 +0800138#if defined(CONFIG_MX6) && defined(CONFIG_IMX6_THERMAL)
139 struct udevice *thermal_dev;
140 int cpu_tmp, ret;
141#endif
142
Jason Liu18936ee2011-11-25 00:18:01 +0000143 cpurev = get_cpu_rev();
Fabio Estevama7683862012-03-20 04:21:45 +0000144
145 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
146 get_imx_type((cpurev & 0xFF000) >> 12),
Jason Liu18936ee2011-11-25 00:18:01 +0000147 (cpurev & 0x000F0) >> 4,
148 (cpurev & 0x0000F) >> 0,
149 mxc_get_clock(MXC_ARM_CLK) / 1000000);
Ye.Li7a264162014-11-20 21:14:14 +0800150
151#if defined(CONFIG_MX6) && defined(CONFIG_IMX6_THERMAL)
152 ret = uclass_get_device(UCLASS_THERMAL, 0, &thermal_dev);
153 if (!ret) {
154 ret = thermal_get_temp(thermal_dev, &cpu_tmp);
155
156 if (!ret)
157 printf("CPU: Temperature %d C\n", cpu_tmp);
158 else
159 printf("CPU: Temperature: invalid sensor data\n");
160 } else {
161 printf("CPU: Temperature: Can't find sensor device\n");
162 }
163#endif
164
Jason Liu18936ee2011-11-25 00:18:01 +0000165 printf("Reset cause: %s\n", get_reset_cause());
166 return 0;
167}
168#endif
169
170int cpu_eth_init(bd_t *bis)
171{
172 int rc = -ENODEV;
173
174#if defined(CONFIG_FEC_MXC)
175 rc = fecmxc_initialize(bis);
176#endif
177
178 return rc;
179}
180
Benoît Thébaudeauecb0f312012-08-17 10:42:55 +0000181#ifdef CONFIG_FSL_ESDHC
Jason Liu18936ee2011-11-25 00:18:01 +0000182/*
183 * Initializes on-chip MMC controllers.
184 * to override, implement board_mmc_init()
185 */
186int cpu_mmc_init(bd_t *bis)
187{
Jason Liu18936ee2011-11-25 00:18:01 +0000188 return fsl_esdhc_mmc_init(bis);
Jason Liu18936ee2011-11-25 00:18:01 +0000189}
Benoît Thébaudeauecb0f312012-08-17 10:42:55 +0000190#endif
Jason Liu18936ee2011-11-25 00:18:01 +0000191
Fabio Estevam6a376042012-04-29 08:11:13 +0000192u32 get_ahb_clk(void)
193{
194 struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
195 u32 reg, ahb_podf;
196
197 reg = __raw_readl(&imx_ccm->cbcdr);
198 reg &= MXC_CCM_CBCDR_AHB_PODF_MASK;
199 ahb_podf = reg >> MXC_CCM_CBCDR_AHB_PODF_OFFSET;
200
201 return get_periph_clk() / (ahb_podf + 1);
202}
Eric Nelsone1eb75b2012-09-23 07:30:55 +0000203
204#if defined(CONFIG_VIDEO_IPUV3)
205void arch_preboot_os(void)
206{
207 /* disable video before launching O/S */
208 ipuv3_fb_shutdown();
209}
210#endif
Fabio Estevam32c81ea2014-11-14 11:27:21 -0200211
212void set_chipselect_size(int const cs_size)
213{
214 unsigned int reg;
215 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
216 reg = readl(&iomuxc_regs->gpr[1]);
217
218 switch (cs_size) {
219 case CS0_128:
220 reg &= ~0x7; /* CS0=128MB, CS1=0, CS2=0, CS3=0 */
221 reg |= 0x5;
222 break;
223 case CS0_64M_CS1_64M:
224 reg &= ~0x3F; /* CS0=64MB, CS1=64MB, CS2=0, CS3=0 */
225 reg |= 0x1B;
226 break;
227 case CS0_64M_CS1_32M_CS2_32M:
228 reg &= ~0x1FF; /* CS0=64MB, CS1=32MB, CS2=32MB, CS3=0 */
229 reg |= 0x4B;
230 break;
231 case CS0_32M_CS1_32M_CS2_32M_CS3_32M:
232 reg &= ~0xFFF; /* CS0=32MB, CS1=32MB, CS2=32MB, CS3=32MB */
233 reg |= 0x249;
234 break;
235 default:
236 printf("Unknown chip select size: %d\n", cs_size);
237 break;
238 }
239
240 writel(reg, &iomuxc_regs->gpr[1]);
241}