blob: fd6d08c533c8d014ceae0e645aba9e7b11e71ae9 [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>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090013#include <linux/errno.h>
Jason Liu83aa8fe2011-11-25 00:18:01 +000014#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
Anatolij Gustschin03dd9862017-08-28 21:46:26 +020028#if defined(CONFIG_DISPLAY_CPUINFO) && !defined(CONFIG_SPL_BUILD)
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";
Peng Fana78e0ac2018-01-10 13:20:25 +080065#elif defined(CONFIG_MX8M)
66 case 0x00100:
67 return "WDOG2";
68 case 0x00200:
69 return "TEMPSENSE";
Adrian Alonso9f883e02015-09-02 13:54:23 -050070#else
71 case 0x00100:
72 return "TEMPSENSE";
Jason Liu83aa8fe2011-11-25 00:18:01 +000073 case 0x10000:
74 return "WARM BOOT";
Adrian Alonso9f883e02015-09-02 13:54:23 -050075#endif
Jason Liu83aa8fe2011-11-25 00:18:01 +000076 default:
77 return "unknown reset";
78 }
79}
80
Eric Nelson25e02302015-02-15 14:37:21 -070081u32 get_imx_reset_cause(void)
82{
83 return reset_cause;
84}
Prabhakar Kushwahaf2c19de2015-05-18 17:13:52 +053085#endif
Eric Nelson25e02302015-02-15 14:37:21 -070086
Troy Kiskyb3aec6a2012-10-23 10:57:48 +000087#if defined(CONFIG_MX53) || defined(CONFIG_MX6)
88#if defined(CONFIG_MX53)
Eric Nelsonc7d46122013-11-08 16:50:53 -070089#define MEMCTL_BASE ESDCTL_BASE_ADDR
Troy Kiskyb3aec6a2012-10-23 10:57:48 +000090#else
Eric Nelsonc7d46122013-11-08 16:50:53 -070091#define MEMCTL_BASE MMDC_P0_BASE_ADDR
Troy Kiskyb3aec6a2012-10-23 10:57:48 +000092#endif
93static const unsigned char col_lookup[] = {9, 10, 11, 8, 12, 9, 9, 9};
94static const unsigned char bank_lookup[] = {3, 2};
95
Tim Harvey066fbad2014-06-02 16:13:21 -070096/* these MMDC registers are common to the IMX53 and IMX6 */
Troy Kiskyb3aec6a2012-10-23 10:57:48 +000097struct esd_mmdc_regs {
98 uint32_t ctl;
99 uint32_t pdc;
100 uint32_t otc;
101 uint32_t cfg0;
102 uint32_t cfg1;
103 uint32_t cfg2;
104 uint32_t misc;
Troy Kiskyb3aec6a2012-10-23 10:57:48 +0000105};
106
107#define ESD_MMDC_CTL_GET_ROW(mdctl) ((ctl >> 24) & 7)
108#define ESD_MMDC_CTL_GET_COLUMN(mdctl) ((ctl >> 20) & 7)
109#define ESD_MMDC_CTL_GET_WIDTH(mdctl) ((ctl >> 16) & 3)
110#define ESD_MMDC_CTL_GET_CS1(mdctl) ((ctl >> 30) & 1)
111#define ESD_MMDC_MISC_GET_BANK(mdmisc) ((misc >> 5) & 1)
112
Tim Harvey066fbad2014-06-02 16:13:21 -0700113/*
114 * imx_ddr_size - return size in bytes of DRAM according MMDC config
115 * The MMDC MDCTL register holds the number of bits for row, col, and data
116 * width and the MMDC MDMISC register holds the number of banks. Combine
117 * all these bits to determine the meme size the MMDC has been configured for
118 */
Troy Kiskyb3aec6a2012-10-23 10:57:48 +0000119unsigned imx_ddr_size(void)
120{
121 struct esd_mmdc_regs *mem = (struct esd_mmdc_regs *)MEMCTL_BASE;
122 unsigned ctl = readl(&mem->ctl);
123 unsigned misc = readl(&mem->misc);
124 int bits = 11 + 0 + 0 + 1; /* row + col + bank + width */
125
126 bits += ESD_MMDC_CTL_GET_ROW(ctl);
127 bits += col_lookup[ESD_MMDC_CTL_GET_COLUMN(ctl)];
128 bits += bank_lookup[ESD_MMDC_MISC_GET_BANK(misc)];
129 bits += ESD_MMDC_CTL_GET_WIDTH(ctl);
130 bits += ESD_MMDC_CTL_GET_CS1(ctl);
Marek Vasut005a4d12014-08-04 01:47:09 +0200131
132 /* The MX6 can do only 3840 MiB of DRAM */
133 if (bits == 32)
134 return 0xf0000000;
135
Troy Kiskyb3aec6a2012-10-23 10:57:48 +0000136 return 1 << bits;
137}
138#endif
139
Anatolij Gustschin03dd9862017-08-28 21:46:26 +0200140#if defined(CONFIG_DISPLAY_CPUINFO) && !defined(CONFIG_SPL_BUILD)
Fabio Estevam46e97332012-03-20 04:21:45 +0000141
Troy Kisky58394932012-10-23 10:57:46 +0000142const char *get_imx_type(u32 imxtype)
Fabio Estevam46e97332012-03-20 04:21:45 +0000143{
144 switch (imxtype) {
Peng Fana78e0ac2018-01-10 13:20:25 +0800145 case MXC_CPU_MX8MQ:
146 return "8MQ"; /* Quad-core version of the mx8m */
Fabio Estevamf6ced1b2016-02-28 12:33:17 -0300147 case MXC_CPU_MX7S:
Stefan Agnerf19a8e42016-05-06 11:21:50 -0700148 return "7S"; /* Single-core version of the mx7 */
Adrian Alonso9f883e02015-09-02 13:54:23 -0500149 case MXC_CPU_MX7D:
150 return "7D"; /* Dual-core version of the mx7 */
Peng Fan5f247922015-07-11 11:38:42 +0800151 case MXC_CPU_MX6QP:
152 return "6QP"; /* Quad-Plus version of the mx6 */
153 case MXC_CPU_MX6DP:
154 return "6DP"; /* Dual-Plus version of the mx6 */
Troy Kisky58394932012-10-23 10:57:46 +0000155 case MXC_CPU_MX6Q:
Fabio Estevam46e97332012-03-20 04:21:45 +0000156 return "6Q"; /* Quad-core version of the mx6 */
Fabio Estevamf3d5a2c2014-01-26 15:06:41 -0200157 case MXC_CPU_MX6D:
158 return "6D"; /* Dual-core version of the mx6 */
Troy Kisky58394932012-10-23 10:57:46 +0000159 case MXC_CPU_MX6DL:
160 return "6DL"; /* Dual Lite version of the mx6 */
161 case MXC_CPU_MX6SOLO:
162 return "6SOLO"; /* Solo version of the mx6 */
163 case MXC_CPU_MX6SL:
Fabio Estevam46e97332012-03-20 04:21:45 +0000164 return "6SL"; /* Solo-Lite version of the mx6 */
Peng Fan4cfd7972016-12-11 19:24:20 +0800165 case MXC_CPU_MX6SLL:
166 return "6SLL"; /* SLL version of the mx6 */
Fabio Estevam712ab882014-06-24 17:40:58 -0300167 case MXC_CPU_MX6SX:
168 return "6SX"; /* SoloX version of the mx6 */
Peng Faneaa53a12015-07-20 19:28:21 +0800169 case MXC_CPU_MX6UL:
170 return "6UL"; /* Ultra-Lite version of the mx6 */
Peng Fan3b33e3f2016-08-11 14:02:38 +0800171 case MXC_CPU_MX6ULL:
172 return "6ULL"; /* ULL version of the mx6 */
Troy Kisky58394932012-10-23 10:57:46 +0000173 case MXC_CPU_MX51:
Fabio Estevam46e97332012-03-20 04:21:45 +0000174 return "51";
Troy Kisky58394932012-10-23 10:57:46 +0000175 case MXC_CPU_MX53:
Fabio Estevam46e97332012-03-20 04:21:45 +0000176 return "53";
177 default:
Otavio Salvador8567d7d2012-06-30 05:07:32 +0000178 return "??";
Fabio Estevam46e97332012-03-20 04:21:45 +0000179 }
180}
181
Jason Liu83aa8fe2011-11-25 00:18:01 +0000182int print_cpuinfo(void)
183{
Stefano Babic40adacc2015-05-26 19:53:41 +0200184 u32 cpurev;
185 __maybe_unused u32 max_freq;
Jason Liu83aa8fe2011-11-25 00:18:01 +0000186
Adrian Alonsoce08c362015-09-02 13:54:13 -0500187 cpurev = get_cpu_rev();
188
189#if defined(CONFIG_IMX_THERMAL)
Ye.Lif19692c2014-11-20 21:14:14 +0800190 struct udevice *thermal_dev;
Tim Harvey27f90592015-05-18 06:56:46 -0700191 int cpu_tmp, minc, maxc, ret;
Ye.Lif19692c2014-11-20 21:14:14 +0800192
Tim Harveyd792ede2015-05-18 07:02:25 -0700193 printf("CPU: Freescale i.MX%s rev%d.%d",
194 get_imx_type((cpurev & 0xFF000) >> 12),
195 (cpurev & 0x000F0) >> 4,
196 (cpurev & 0x0000F) >> 0);
197 max_freq = get_cpu_speed_grade_hz();
198 if (!max_freq || max_freq == mxc_get_clock(MXC_ARM_CLK)) {
199 printf(" at %dMHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
200 } else {
201 printf(" %d MHz (running at %d MHz)\n", max_freq / 1000000,
202 mxc_get_clock(MXC_ARM_CLK) / 1000000);
203 }
204#else
Fabio Estevam46e97332012-03-20 04:21:45 +0000205 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
206 get_imx_type((cpurev & 0xFF000) >> 12),
Jason Liu83aa8fe2011-11-25 00:18:01 +0000207 (cpurev & 0x000F0) >> 4,
208 (cpurev & 0x0000F) >> 0,
209 mxc_get_clock(MXC_ARM_CLK) / 1000000);
Tim Harveyd792ede2015-05-18 07:02:25 -0700210#endif
Ye.Lif19692c2014-11-20 21:14:14 +0800211
Adrian Alonsoce08c362015-09-02 13:54:13 -0500212#if defined(CONFIG_IMX_THERMAL)
Tim Harvey27f90592015-05-18 06:56:46 -0700213 puts("CPU: ");
214 switch (get_cpu_temp_grade(&minc, &maxc)) {
215 case TEMP_AUTOMOTIVE:
216 puts("Automotive temperature grade ");
217 break;
218 case TEMP_INDUSTRIAL:
219 puts("Industrial temperature grade ");
220 break;
221 case TEMP_EXTCOMMERCIAL:
222 puts("Extended Commercial temperature grade ");
223 break;
224 default:
225 puts("Commercial temperature grade ");
226 break;
227 }
228 printf("(%dC to %dC)", minc, maxc);
Ye.Lif19692c2014-11-20 21:14:14 +0800229 ret = uclass_get_device(UCLASS_THERMAL, 0, &thermal_dev);
230 if (!ret) {
231 ret = thermal_get_temp(thermal_dev, &cpu_tmp);
232
233 if (!ret)
Tim Harvey27f90592015-05-18 06:56:46 -0700234 printf(" at %dC\n", cpu_tmp);
Ye.Lif19692c2014-11-20 21:14:14 +0800235 else
Fabio Estevamf62604d2015-09-08 14:43:10 -0300236 debug(" - invalid sensor data\n");
Ye.Lif19692c2014-11-20 21:14:14 +0800237 } else {
Fabio Estevamf62604d2015-09-08 14:43:10 -0300238 debug(" - invalid sensor device\n");
Ye.Lif19692c2014-11-20 21:14:14 +0800239 }
240#endif
241
Jason Liu83aa8fe2011-11-25 00:18:01 +0000242 printf("Reset cause: %s\n", get_reset_cause());
243 return 0;
244}
245#endif
246
247int cpu_eth_init(bd_t *bis)
248{
249 int rc = -ENODEV;
250
251#if defined(CONFIG_FEC_MXC)
252 rc = fecmxc_initialize(bis);
253#endif
254
255 return rc;
256}
257
Benoît Thébaudeau58d22322012-08-17 10:42:55 +0000258#ifdef CONFIG_FSL_ESDHC
Jason Liu83aa8fe2011-11-25 00:18:01 +0000259/*
260 * Initializes on-chip MMC controllers.
261 * to override, implement board_mmc_init()
262 */
263int cpu_mmc_init(bd_t *bis)
264{
Jason Liu83aa8fe2011-11-25 00:18:01 +0000265 return fsl_esdhc_mmc_init(bis);
Jason Liu83aa8fe2011-11-25 00:18:01 +0000266}
Benoît Thébaudeau58d22322012-08-17 10:42:55 +0000267#endif
Jason Liu83aa8fe2011-11-25 00:18:01 +0000268
Peng Fana78e0ac2018-01-10 13:20:25 +0800269#if !(defined(CONFIG_MX7) || defined(CONFIG_MX8M))
Fabio Estevam6479f512012-04-29 08:11:13 +0000270u32 get_ahb_clk(void)
271{
272 struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
273 u32 reg, ahb_podf;
274
275 reg = __raw_readl(&imx_ccm->cbcdr);
276 reg &= MXC_CCM_CBCDR_AHB_PODF_MASK;
277 ahb_podf = reg >> MXC_CCM_CBCDR_AHB_PODF_OFFSET;
278
279 return get_periph_clk() / (ahb_podf + 1);
280}
Adrian Alonso9f883e02015-09-02 13:54:23 -0500281#endif
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000282
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000283void arch_preboot_os(void)
284{
Tim Harveyc22f2ea2017-05-12 12:58:41 -0700285#if defined(CONFIG_PCIE_IMX)
286 imx_pcie_remove();
287#endif
Simon Glassab3055a2017-06-14 21:28:25 -0600288#if defined(CONFIG_SATA)
Simon Glass23dba642017-07-29 11:35:14 -0600289 sata_remove(0);
Soeren Mocha517d022014-11-27 10:11:41 +0100290#if defined(CONFIG_MX6)
291 disable_sata_clock();
292#endif
Nikita Kiryanovb5c9ed32014-11-21 12:47:26 +0200293#endif
294#if defined(CONFIG_VIDEO_IPUV3)
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000295 /* disable video before launching O/S */
296 ipuv3_fb_shutdown();
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000297#endif
Peng Fanf2c39922015-10-29 15:54:51 +0800298#if defined(CONFIG_VIDEO_MXS)
299 lcdif_power_down();
300#endif
Nikita Kiryanovb5c9ed32014-11-21 12:47:26 +0200301}
Fabio Estevam16e65f62014-11-14 11:27:21 -0200302
Peng Fana78e0ac2018-01-10 13:20:25 +0800303#ifndef CONFIG_MX8M
Fabio Estevam16e65f62014-11-14 11:27:21 -0200304void set_chipselect_size(int const cs_size)
305{
306 unsigned int reg;
307 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
308 reg = readl(&iomuxc_regs->gpr[1]);
309
310 switch (cs_size) {
311 case CS0_128:
312 reg &= ~0x7; /* CS0=128MB, CS1=0, CS2=0, CS3=0 */
313 reg |= 0x5;
314 break;
315 case CS0_64M_CS1_64M:
316 reg &= ~0x3F; /* CS0=64MB, CS1=64MB, CS2=0, CS3=0 */
317 reg |= 0x1B;
318 break;
319 case CS0_64M_CS1_32M_CS2_32M:
320 reg &= ~0x1FF; /* CS0=64MB, CS1=32MB, CS2=32MB, CS3=0 */
321 reg |= 0x4B;
322 break;
323 case CS0_32M_CS1_32M_CS2_32M_CS3_32M:
324 reg &= ~0xFFF; /* CS0=32MB, CS1=32MB, CS2=32MB, CS3=32MB */
325 reg |= 0x249;
326 break;
327 default:
328 printf("Unknown chip select size: %d\n", cs_size);
329 break;
330 }
331
332 writel(reg, &iomuxc_regs->gpr[1]);
333}
Peng Fana78e0ac2018-01-10 13:20:25 +0800334#endif
Fabio Estevam49bcdd72017-11-27 10:25:09 -0200335
Peng Fana12bf3c2018-01-10 13:20:30 +0800336#if defined(CONFIG_MX7) || defined(CONFIG_MX8M)
Peng Fan7753bc72018-01-10 13:20:29 +0800337/*
338 * OCOTP_TESTER3[9:8] (see Fusemap Description Table offset 0x440)
339 * defines a 2-bit SPEED_GRADING
340 */
341#define OCOTP_TESTER3_SPEED_SHIFT 8
Peng Fana12bf3c2018-01-10 13:20:30 +0800342enum cpu_speed {
343 OCOTP_TESTER3_SPEED_GRADE0,
344 OCOTP_TESTER3_SPEED_GRADE1,
345 OCOTP_TESTER3_SPEED_GRADE2,
346 OCOTP_TESTER3_SPEED_GRADE3,
347};
Peng Fan7753bc72018-01-10 13:20:29 +0800348
349u32 get_cpu_speed_grade_hz(void)
350{
351 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
352 struct fuse_bank *bank = &ocotp->bank[1];
353 struct fuse_bank1_regs *fuse =
354 (struct fuse_bank1_regs *)bank->fuse_regs;
355 uint32_t val;
356
357 val = readl(&fuse->tester3);
358 val >>= OCOTP_TESTER3_SPEED_SHIFT;
359 val &= 0x3;
360
361 switch(val) {
Peng Fana12bf3c2018-01-10 13:20:30 +0800362 case OCOTP_TESTER3_SPEED_GRADE0:
Peng Fan7753bc72018-01-10 13:20:29 +0800363 return 800000000;
Peng Fana12bf3c2018-01-10 13:20:30 +0800364 case OCOTP_TESTER3_SPEED_GRADE1:
365 return is_mx7() ? 500000000 : 1000000000;
366 case OCOTP_TESTER3_SPEED_GRADE2:
367 return is_mx7() ? 1000000000 : 1300000000;
368 case OCOTP_TESTER3_SPEED_GRADE3:
369 return is_mx7() ? 1200000000 : 1500000000;
Peng Fan7753bc72018-01-10 13:20:29 +0800370 }
Peng Fana12bf3c2018-01-10 13:20:30 +0800371
Peng Fan7753bc72018-01-10 13:20:29 +0800372 return 0;
373}
374
375/*
376 * OCOTP_TESTER3[7:6] (see Fusemap Description Table offset 0x440)
377 * defines a 2-bit SPEED_GRADING
378 */
379#define OCOTP_TESTER3_TEMP_SHIFT 6
380
381u32 get_cpu_temp_grade(int *minc, int *maxc)
382{
383 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
384 struct fuse_bank *bank = &ocotp->bank[1];
385 struct fuse_bank1_regs *fuse =
386 (struct fuse_bank1_regs *)bank->fuse_regs;
387 uint32_t val;
388
389 val = readl(&fuse->tester3);
390 val >>= OCOTP_TESTER3_TEMP_SHIFT;
391 val &= 0x3;
392
393 if (minc && maxc) {
394 if (val == TEMP_AUTOMOTIVE) {
395 *minc = -40;
396 *maxc = 125;
397 } else if (val == TEMP_INDUSTRIAL) {
398 *minc = -40;
399 *maxc = 105;
400 } else if (val == TEMP_EXTCOMMERCIAL) {
401 *minc = -20;
402 *maxc = 105;
403 } else {
404 *minc = 0;
405 *maxc = 95;
406 }
407 }
408 return val;
409}
410#endif
411
Fabio Estevam49bcdd72017-11-27 10:25:09 -0200412#ifdef CONFIG_NXP_BOARD_REVISION
413int nxp_board_rev(void)
414{
415 /*
416 * Get Board ID information from OCOTP_GP1[15:8]
417 * RevA: 0x1
418 * RevB: 0x2
419 * RevC: 0x3
420 */
421 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
422 struct fuse_bank *bank = &ocotp->bank[4];
423 struct fuse_bank4_regs *fuse =
424 (struct fuse_bank4_regs *)bank->fuse_regs;
425
426 return (readl(&fuse->gp1) >> 8 & 0x0F);
427}
428
429char nxp_board_rev_string(void)
430{
431 const char *rev = "A";
432
433 return (*rev + nxp_board_rev() - 1);
434}
435#endif