blob: 42231872611caddf50b165fd55e066e67009141a [file] [log] [blame]
Jason Liu83aa8fe2011-11-25 00:18:01 +00001/*
2 * (C) Copyright 2007
3 * Sascha Hauer, Pengutronix
4 *
5 * (C) Copyright 2009 Freescale Semiconductor, Inc.
6 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Jason Liu83aa8fe2011-11-25 00:18:01 +00008 */
9
Jeroen Hofstee1abf3a12014-10-08 22:57:52 +020010#include <bootm.h>
Jason Liu83aa8fe2011-11-25 00:18:01 +000011#include <common.h>
Jeroen Hofstee1abf3a12014-10-08 22:57:52 +020012#include <netdev.h>
Jason Liu83aa8fe2011-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 Estevam6479f512012-04-29 08:11:13 +000018#include <asm/arch/crm_regs.h>
Tim Harvey27f90592015-05-18 06:56:46 -070019#include <imx_thermal.h>
Eric Nelson54b3f3b2012-09-23 07:30:55 +000020#include <ipu_pixfmt.h>
Ye.Lif19692c2014-11-20 21:14:14 +080021#include <thermal.h>
Nikita Kiryanovb5c9ed32014-11-21 12:47:26 +020022#include <sata.h>
Jason Liu83aa8fe2011-11-25 00:18:01 +000023
24#ifdef CONFIG_FSL_ESDHC
25#include <fsl_esdhc.h>
26#endif
27
Prabhakar Kushwahaf2c19de2015-05-18 17:13:52 +053028#if defined(CONFIG_DISPLAY_CPUINFO)
Eric Nelson25e02302015-02-15 14:37:21 -070029static u32 reset_cause = -1;
30
31static char *get_reset_cause(void)
Jason Liu83aa8fe2011-11-25 00:18:01 +000032{
33 u32 cause;
34 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
35
36 cause = readl(&src_regs->srsr);
37 writel(cause, &src_regs->srsr);
Eric Nelson25e02302015-02-15 14:37:21 -070038 reset_cause = cause;
Jason Liu83aa8fe2011-11-25 00:18:01 +000039
40 switch (cause) {
41 case 0x00001:
Fabio Estevam9af122b2012-03-13 07:26:48 +000042 case 0x00011:
Jason Liu83aa8fe2011-11-25 00:18:01 +000043 return "POR";
44 case 0x00004:
45 return "CSU";
46 case 0x00008:
47 return "IPP USER";
48 case 0x00010:
Adrian Alonso9f883e02015-09-02 13:54:23 -050049#ifdef CONFIG_MX7
50 return "WDOG1";
51#else
Jason Liu83aa8fe2011-11-25 00:18:01 +000052 return "WDOG";
Adrian Alonso9f883e02015-09-02 13:54:23 -050053#endif
Jason Liu83aa8fe2011-11-25 00:18:01 +000054 case 0x00020:
55 return "JTAG HIGH-Z";
56 case 0x00040:
57 return "JTAG SW";
Adrian Alonso9f883e02015-09-02 13:54:23 -050058 case 0x00080:
59 return "WDOG3";
60#ifdef CONFIG_MX7
61 case 0x00100:
62 return "WDOG4";
63 case 0x00200:
64 return "TEMPSENSE";
65#else
66 case 0x00100:
67 return "TEMPSENSE";
Jason Liu83aa8fe2011-11-25 00:18:01 +000068 case 0x10000:
69 return "WARM BOOT";
Adrian Alonso9f883e02015-09-02 13:54:23 -050070#endif
Jason Liu83aa8fe2011-11-25 00:18:01 +000071 default:
72 return "unknown reset";
73 }
74}
75
Eric Nelson25e02302015-02-15 14:37:21 -070076u32 get_imx_reset_cause(void)
77{
78 return reset_cause;
79}
Prabhakar Kushwahaf2c19de2015-05-18 17:13:52 +053080#endif
Eric Nelson25e02302015-02-15 14:37:21 -070081
Troy Kiskyb3aec6a2012-10-23 10:57:48 +000082#if defined(CONFIG_MX53) || defined(CONFIG_MX6)
83#if defined(CONFIG_MX53)
Eric Nelsonc7d46122013-11-08 16:50:53 -070084#define MEMCTL_BASE ESDCTL_BASE_ADDR
Troy Kiskyb3aec6a2012-10-23 10:57:48 +000085#else
Eric Nelsonc7d46122013-11-08 16:50:53 -070086#define MEMCTL_BASE MMDC_P0_BASE_ADDR
Troy Kiskyb3aec6a2012-10-23 10:57:48 +000087#endif
88static const unsigned char col_lookup[] = {9, 10, 11, 8, 12, 9, 9, 9};
89static const unsigned char bank_lookup[] = {3, 2};
90
Tim Harvey066fbad2014-06-02 16:13:21 -070091/* these MMDC registers are common to the IMX53 and IMX6 */
Troy Kiskyb3aec6a2012-10-23 10:57:48 +000092struct esd_mmdc_regs {
93 uint32_t ctl;
94 uint32_t pdc;
95 uint32_t otc;
96 uint32_t cfg0;
97 uint32_t cfg1;
98 uint32_t cfg2;
99 uint32_t misc;
Troy Kiskyb3aec6a2012-10-23 10:57:48 +0000100};
101
102#define ESD_MMDC_CTL_GET_ROW(mdctl) ((ctl >> 24) & 7)
103#define ESD_MMDC_CTL_GET_COLUMN(mdctl) ((ctl >> 20) & 7)
104#define ESD_MMDC_CTL_GET_WIDTH(mdctl) ((ctl >> 16) & 3)
105#define ESD_MMDC_CTL_GET_CS1(mdctl) ((ctl >> 30) & 1)
106#define ESD_MMDC_MISC_GET_BANK(mdmisc) ((misc >> 5) & 1)
107
Tim Harvey066fbad2014-06-02 16:13:21 -0700108/*
109 * imx_ddr_size - return size in bytes of DRAM according MMDC config
110 * The MMDC MDCTL register holds the number of bits for row, col, and data
111 * width and the MMDC MDMISC register holds the number of banks. Combine
112 * all these bits to determine the meme size the MMDC has been configured for
113 */
Troy Kiskyb3aec6a2012-10-23 10:57:48 +0000114unsigned imx_ddr_size(void)
115{
116 struct esd_mmdc_regs *mem = (struct esd_mmdc_regs *)MEMCTL_BASE;
117 unsigned ctl = readl(&mem->ctl);
118 unsigned misc = readl(&mem->misc);
119 int bits = 11 + 0 + 0 + 1; /* row + col + bank + width */
120
121 bits += ESD_MMDC_CTL_GET_ROW(ctl);
122 bits += col_lookup[ESD_MMDC_CTL_GET_COLUMN(ctl)];
123 bits += bank_lookup[ESD_MMDC_MISC_GET_BANK(misc)];
124 bits += ESD_MMDC_CTL_GET_WIDTH(ctl);
125 bits += ESD_MMDC_CTL_GET_CS1(ctl);
Marek Vasut005a4d12014-08-04 01:47:09 +0200126
127 /* The MX6 can do only 3840 MiB of DRAM */
128 if (bits == 32)
129 return 0xf0000000;
130
Troy Kiskyb3aec6a2012-10-23 10:57:48 +0000131 return 1 << bits;
132}
133#endif
134
Jason Liu83aa8fe2011-11-25 00:18:01 +0000135#if defined(CONFIG_DISPLAY_CPUINFO)
Fabio Estevam46e97332012-03-20 04:21:45 +0000136
Troy Kisky58394932012-10-23 10:57:46 +0000137const char *get_imx_type(u32 imxtype)
Fabio Estevam46e97332012-03-20 04:21:45 +0000138{
139 switch (imxtype) {
Fabio Estevamf6ced1b2016-02-28 12:33:17 -0300140 case MXC_CPU_MX7S:
Stefan Agnerf19a8e42016-05-06 11:21:50 -0700141 return "7S"; /* Single-core version of the mx7 */
Adrian Alonso9f883e02015-09-02 13:54:23 -0500142 case MXC_CPU_MX7D:
143 return "7D"; /* Dual-core version of the mx7 */
Peng Fan5f247922015-07-11 11:38:42 +0800144 case MXC_CPU_MX6QP:
145 return "6QP"; /* Quad-Plus version of the mx6 */
146 case MXC_CPU_MX6DP:
147 return "6DP"; /* Dual-Plus version of the mx6 */
Troy Kisky58394932012-10-23 10:57:46 +0000148 case MXC_CPU_MX6Q:
Fabio Estevam46e97332012-03-20 04:21:45 +0000149 return "6Q"; /* Quad-core version of the mx6 */
Fabio Estevamf3d5a2c2014-01-26 15:06:41 -0200150 case MXC_CPU_MX6D:
151 return "6D"; /* Dual-core version of the mx6 */
Troy Kisky58394932012-10-23 10:57:46 +0000152 case MXC_CPU_MX6DL:
153 return "6DL"; /* Dual Lite version of the mx6 */
154 case MXC_CPU_MX6SOLO:
155 return "6SOLO"; /* Solo version of the mx6 */
156 case MXC_CPU_MX6SL:
Fabio Estevam46e97332012-03-20 04:21:45 +0000157 return "6SL"; /* Solo-Lite version of the mx6 */
Fabio Estevam712ab882014-06-24 17:40:58 -0300158 case MXC_CPU_MX6SX:
159 return "6SX"; /* SoloX version of the mx6 */
Peng Faneaa53a12015-07-20 19:28:21 +0800160 case MXC_CPU_MX6UL:
161 return "6UL"; /* Ultra-Lite version of the mx6 */
Troy Kisky58394932012-10-23 10:57:46 +0000162 case MXC_CPU_MX51:
Fabio Estevam46e97332012-03-20 04:21:45 +0000163 return "51";
Troy Kisky58394932012-10-23 10:57:46 +0000164 case MXC_CPU_MX53:
Fabio Estevam46e97332012-03-20 04:21:45 +0000165 return "53";
166 default:
Otavio Salvador8567d7d2012-06-30 05:07:32 +0000167 return "??";
Fabio Estevam46e97332012-03-20 04:21:45 +0000168 }
169}
170
Jason Liu83aa8fe2011-11-25 00:18:01 +0000171int print_cpuinfo(void)
172{
Stefano Babic40adacc2015-05-26 19:53:41 +0200173 u32 cpurev;
174 __maybe_unused u32 max_freq;
Jason Liu83aa8fe2011-11-25 00:18:01 +0000175
Adrian Alonsoce08c362015-09-02 13:54:13 -0500176 cpurev = get_cpu_rev();
177
178#if defined(CONFIG_IMX_THERMAL)
Ye.Lif19692c2014-11-20 21:14:14 +0800179 struct udevice *thermal_dev;
Tim Harvey27f90592015-05-18 06:56:46 -0700180 int cpu_tmp, minc, maxc, ret;
Ye.Lif19692c2014-11-20 21:14:14 +0800181
Tim Harveyd792ede2015-05-18 07:02:25 -0700182 printf("CPU: Freescale i.MX%s rev%d.%d",
183 get_imx_type((cpurev & 0xFF000) >> 12),
184 (cpurev & 0x000F0) >> 4,
185 (cpurev & 0x0000F) >> 0);
186 max_freq = get_cpu_speed_grade_hz();
187 if (!max_freq || max_freq == mxc_get_clock(MXC_ARM_CLK)) {
188 printf(" at %dMHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
189 } else {
190 printf(" %d MHz (running at %d MHz)\n", max_freq / 1000000,
191 mxc_get_clock(MXC_ARM_CLK) / 1000000);
192 }
193#else
Fabio Estevam46e97332012-03-20 04:21:45 +0000194 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
195 get_imx_type((cpurev & 0xFF000) >> 12),
Jason Liu83aa8fe2011-11-25 00:18:01 +0000196 (cpurev & 0x000F0) >> 4,
197 (cpurev & 0x0000F) >> 0,
198 mxc_get_clock(MXC_ARM_CLK) / 1000000);
Tim Harveyd792ede2015-05-18 07:02:25 -0700199#endif
Ye.Lif19692c2014-11-20 21:14:14 +0800200
Adrian Alonsoce08c362015-09-02 13:54:13 -0500201#if defined(CONFIG_IMX_THERMAL)
Tim Harvey27f90592015-05-18 06:56:46 -0700202 puts("CPU: ");
203 switch (get_cpu_temp_grade(&minc, &maxc)) {
204 case TEMP_AUTOMOTIVE:
205 puts("Automotive temperature grade ");
206 break;
207 case TEMP_INDUSTRIAL:
208 puts("Industrial temperature grade ");
209 break;
210 case TEMP_EXTCOMMERCIAL:
211 puts("Extended Commercial temperature grade ");
212 break;
213 default:
214 puts("Commercial temperature grade ");
215 break;
216 }
217 printf("(%dC to %dC)", minc, maxc);
Ye.Lif19692c2014-11-20 21:14:14 +0800218 ret = uclass_get_device(UCLASS_THERMAL, 0, &thermal_dev);
219 if (!ret) {
220 ret = thermal_get_temp(thermal_dev, &cpu_tmp);
221
222 if (!ret)
Tim Harvey27f90592015-05-18 06:56:46 -0700223 printf(" at %dC\n", cpu_tmp);
Ye.Lif19692c2014-11-20 21:14:14 +0800224 else
Fabio Estevamf62604d2015-09-08 14:43:10 -0300225 debug(" - invalid sensor data\n");
Ye.Lif19692c2014-11-20 21:14:14 +0800226 } else {
Fabio Estevamf62604d2015-09-08 14:43:10 -0300227 debug(" - invalid sensor device\n");
Ye.Lif19692c2014-11-20 21:14:14 +0800228 }
229#endif
230
Jason Liu83aa8fe2011-11-25 00:18:01 +0000231 printf("Reset cause: %s\n", get_reset_cause());
232 return 0;
233}
234#endif
235
236int cpu_eth_init(bd_t *bis)
237{
238 int rc = -ENODEV;
239
240#if defined(CONFIG_FEC_MXC)
241 rc = fecmxc_initialize(bis);
242#endif
243
244 return rc;
245}
246
Benoît Thébaudeau58d22322012-08-17 10:42:55 +0000247#ifdef CONFIG_FSL_ESDHC
Jason Liu83aa8fe2011-11-25 00:18:01 +0000248/*
249 * Initializes on-chip MMC controllers.
250 * to override, implement board_mmc_init()
251 */
252int cpu_mmc_init(bd_t *bis)
253{
Jason Liu83aa8fe2011-11-25 00:18:01 +0000254 return fsl_esdhc_mmc_init(bis);
Jason Liu83aa8fe2011-11-25 00:18:01 +0000255}
Benoît Thébaudeau58d22322012-08-17 10:42:55 +0000256#endif
Jason Liu83aa8fe2011-11-25 00:18:01 +0000257
Adrian Alonso9f883e02015-09-02 13:54:23 -0500258#ifndef CONFIG_MX7
Fabio Estevam6479f512012-04-29 08:11:13 +0000259u32 get_ahb_clk(void)
260{
261 struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
262 u32 reg, ahb_podf;
263
264 reg = __raw_readl(&imx_ccm->cbcdr);
265 reg &= MXC_CCM_CBCDR_AHB_PODF_MASK;
266 ahb_podf = reg >> MXC_CCM_CBCDR_AHB_PODF_OFFSET;
267
268 return get_periph_clk() / (ahb_podf + 1);
269}
Adrian Alonso9f883e02015-09-02 13:54:23 -0500270#endif
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000271
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000272void arch_preboot_os(void)
273{
Nikita Kiryanovb5c9ed32014-11-21 12:47:26 +0200274#if defined(CONFIG_CMD_SATA)
275 sata_stop();
Soeren Mocha517d022014-11-27 10:11:41 +0100276#if defined(CONFIG_MX6)
277 disable_sata_clock();
278#endif
Nikita Kiryanovb5c9ed32014-11-21 12:47:26 +0200279#endif
280#if defined(CONFIG_VIDEO_IPUV3)
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000281 /* disable video before launching O/S */
282 ipuv3_fb_shutdown();
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000283#endif
Peng Fanf2c39922015-10-29 15:54:51 +0800284#if defined(CONFIG_VIDEO_MXS)
285 lcdif_power_down();
286#endif
Nikita Kiryanovb5c9ed32014-11-21 12:47:26 +0200287}
Fabio Estevam16e65f62014-11-14 11:27:21 -0200288
289void set_chipselect_size(int const cs_size)
290{
291 unsigned int reg;
292 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
293 reg = readl(&iomuxc_regs->gpr[1]);
294
295 switch (cs_size) {
296 case CS0_128:
297 reg &= ~0x7; /* CS0=128MB, CS1=0, CS2=0, CS3=0 */
298 reg |= 0x5;
299 break;
300 case CS0_64M_CS1_64M:
301 reg &= ~0x3F; /* CS0=64MB, CS1=64MB, CS2=0, CS3=0 */
302 reg |= 0x1B;
303 break;
304 case CS0_64M_CS1_32M_CS2_32M:
305 reg &= ~0x1FF; /* CS0=64MB, CS1=32MB, CS2=32MB, CS3=0 */
306 reg |= 0x4B;
307 break;
308 case CS0_32M_CS1_32M_CS2_32M_CS3_32M:
309 reg &= ~0xFFF; /* CS0=32MB, CS1=32MB, CS2=32MB, CS3=32MB */
310 reg |= 0x249;
311 break;
312 default:
313 printf("Unknown chip select size: %d\n", cs_size);
314 break;
315 }
316
317 writel(reg, &iomuxc_regs->gpr[1]);
318}