blob: 52dbafb50cec8b3e5bc7a123fe595cd9632a2b15 [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>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090013#include <linux/errno.h>
Jason Liu18936ee2011-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 Estevam6a376042012-04-29 08:11:13 +000018#include <asm/arch/crm_regs.h>
Tim Harvey70caa8e2015-05-18 06:56:46 -070019#include <imx_thermal.h>
Eric Nelsone1eb75b2012-09-23 07:30:55 +000020#include <ipu_pixfmt.h>
Ye.Li7a264162014-11-20 21:14:14 +080021#include <thermal.h>
Nikita Kiryanov44b98412014-11-21 12:47:26 +020022#include <sata.h>
Jason Liu18936ee2011-11-25 00:18:01 +000023
24#ifdef CONFIG_FSL_ESDHC
25#include <fsl_esdhc.h>
26#endif
27
Anatolij Gustschin38df3702017-08-28 21:46:26 +020028#if defined(CONFIG_DISPLAY_CPUINFO) && !defined(CONFIG_SPL_BUILD)
Eric Nelson11c2e502015-02-15 14:37:21 -070029static u32 reset_cause = -1;
30
31static char *get_reset_cause(void)
Jason Liu18936ee2011-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 Nelson11c2e502015-02-15 14:37:21 -070038 reset_cause = cause;
Jason Liu18936ee2011-11-25 00:18:01 +000039
40 switch (cause) {
41 case 0x00001:
Fabio Estevamcece2622012-03-13 07:26:48 +000042 case 0x00011:
Jason Liu18936ee2011-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 Alonsocd562c82015-09-02 13:54:23 -050049#ifdef CONFIG_MX7
50 return "WDOG1";
51#else
Jason Liu18936ee2011-11-25 00:18:01 +000052 return "WDOG";
Adrian Alonsocd562c82015-09-02 13:54:23 -050053#endif
Jason Liu18936ee2011-11-25 00:18:01 +000054 case 0x00020:
55 return "JTAG HIGH-Z";
56 case 0x00040:
57 return "JTAG SW";
Adrian Alonsocd562c82015-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 Fan7537e932018-01-10 13:20:25 +080065#elif defined(CONFIG_MX8M)
66 case 0x00100:
67 return "WDOG2";
68 case 0x00200:
69 return "TEMPSENSE";
Adrian Alonsocd562c82015-09-02 13:54:23 -050070#else
71 case 0x00100:
72 return "TEMPSENSE";
Jason Liu18936ee2011-11-25 00:18:01 +000073 case 0x10000:
74 return "WARM BOOT";
Adrian Alonsocd562c82015-09-02 13:54:23 -050075#endif
Jason Liu18936ee2011-11-25 00:18:01 +000076 default:
77 return "unknown reset";
78 }
79}
80
Eric Nelson11c2e502015-02-15 14:37:21 -070081u32 get_imx_reset_cause(void)
82{
83 return reset_cause;
84}
Prabhakar Kushwaha28420e72015-05-18 17:13:52 +053085#endif
Eric Nelson11c2e502015-02-15 14:37:21 -070086
Troy Kiskyeb0344d2012-10-23 10:57:48 +000087#if defined(CONFIG_MX53) || defined(CONFIG_MX6)
88#if defined(CONFIG_MX53)
Eric Nelson3e9cbbb2013-11-08 16:50:53 -070089#define MEMCTL_BASE ESDCTL_BASE_ADDR
Troy Kiskyeb0344d2012-10-23 10:57:48 +000090#else
Eric Nelson3e9cbbb2013-11-08 16:50:53 -070091#define MEMCTL_BASE MMDC_P0_BASE_ADDR
Troy Kiskyeb0344d2012-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 Harveyb07161c2014-06-02 16:13:21 -070096/* these MMDC registers are common to the IMX53 and IMX6 */
Troy Kiskyeb0344d2012-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 Kiskyeb0344d2012-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 Harveyb07161c2014-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 Kiskyeb0344d2012-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 Vasutfcfdfdd2014-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 Kiskyeb0344d2012-10-23 10:57:48 +0000136 return 1 << bits;
137}
138#endif
139
Anatolij Gustschin38df3702017-08-28 21:46:26 +0200140#if defined(CONFIG_DISPLAY_CPUINFO) && !defined(CONFIG_SPL_BUILD)
Fabio Estevama7683862012-03-20 04:21:45 +0000141
Troy Kisky20332a02012-10-23 10:57:46 +0000142const char *get_imx_type(u32 imxtype)
Fabio Estevama7683862012-03-20 04:21:45 +0000143{
144 switch (imxtype) {
Peng Fan7537e932018-01-10 13:20:25 +0800145 case MXC_CPU_MX8MQ:
146 return "8MQ"; /* Quad-core version of the mx8m */
Fabio Estevame25a0652016-02-28 12:33:17 -0300147 case MXC_CPU_MX7S:
Stefan Agner249092f2016-05-06 11:21:50 -0700148 return "7S"; /* Single-core version of the mx7 */
Adrian Alonsocd562c82015-09-02 13:54:23 -0500149 case MXC_CPU_MX7D:
150 return "7D"; /* Dual-core version of the mx7 */
Peng Fand0acd992015-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 Kisky20332a02012-10-23 10:57:46 +0000155 case MXC_CPU_MX6Q:
Fabio Estevama7683862012-03-20 04:21:45 +0000156 return "6Q"; /* Quad-core version of the mx6 */
Fabio Estevam94db6652014-01-26 15:06:41 -0200157 case MXC_CPU_MX6D:
158 return "6D"; /* Dual-core version of the mx6 */
Troy Kisky20332a02012-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 Estevama7683862012-03-20 04:21:45 +0000164 return "6SL"; /* Solo-Lite version of the mx6 */
Peng Fan7ce6d3c2016-12-11 19:24:20 +0800165 case MXC_CPU_MX6SLL:
166 return "6SLL"; /* SLL version of the mx6 */
Fabio Estevam05d54b82014-06-24 17:40:58 -0300167 case MXC_CPU_MX6SX:
168 return "6SX"; /* SoloX version of the mx6 */
Peng Fan8631c062015-07-20 19:28:21 +0800169 case MXC_CPU_MX6UL:
170 return "6UL"; /* Ultra-Lite version of the mx6 */
Peng Fan65ce54b2016-08-11 14:02:38 +0800171 case MXC_CPU_MX6ULL:
172 return "6ULL"; /* ULL version of the mx6 */
Troy Kisky20332a02012-10-23 10:57:46 +0000173 case MXC_CPU_MX51:
Fabio Estevama7683862012-03-20 04:21:45 +0000174 return "51";
Troy Kisky20332a02012-10-23 10:57:46 +0000175 case MXC_CPU_MX53:
Fabio Estevama7683862012-03-20 04:21:45 +0000176 return "53";
177 default:
Otavio Salvadore972d722012-06-30 05:07:32 +0000178 return "??";
Fabio Estevama7683862012-03-20 04:21:45 +0000179 }
180}
181
Jason Liu18936ee2011-11-25 00:18:01 +0000182int print_cpuinfo(void)
183{
Stefano Babic943a3f22015-05-26 19:53:41 +0200184 u32 cpurev;
185 __maybe_unused u32 max_freq;
Jason Liu18936ee2011-11-25 00:18:01 +0000186
187 cpurev = get_cpu_rev();
Fabio Estevama7683862012-03-20 04:21:45 +0000188
Adrian Alonso1368f992015-09-02 13:54:13 -0500189#if defined(CONFIG_IMX_THERMAL)
190 struct udevice *thermal_dev;
191 int cpu_tmp, minc, maxc, ret;
192
Tim Harveyb83ddac2015-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 Estevama7683862012-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 Liu18936ee2011-11-25 00:18:01 +0000207 (cpurev & 0x000F0) >> 4,
208 (cpurev & 0x0000F) >> 0,
209 mxc_get_clock(MXC_ARM_CLK) / 1000000);
Tim Harveyb83ddac2015-05-18 07:02:25 -0700210#endif
Ye.Li7a264162014-11-20 21:14:14 +0800211
Adrian Alonso1368f992015-09-02 13:54:13 -0500212#if defined(CONFIG_IMX_THERMAL)
Tim Harvey70caa8e2015-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.Li7a264162014-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 Harvey70caa8e2015-05-18 06:56:46 -0700234 printf(" at %dC\n", cpu_tmp);
Ye.Li7a264162014-11-20 21:14:14 +0800235 else
Fabio Estevam3a384b42015-09-08 14:43:10 -0300236 debug(" - invalid sensor data\n");
Ye.Li7a264162014-11-20 21:14:14 +0800237 } else {
Fabio Estevam3a384b42015-09-08 14:43:10 -0300238 debug(" - invalid sensor device\n");
Ye.Li7a264162014-11-20 21:14:14 +0800239 }
240#endif
241
Jason Liu18936ee2011-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ébaudeauecb0f312012-08-17 10:42:55 +0000258#ifdef CONFIG_FSL_ESDHC
Jason Liu18936ee2011-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 Liu18936ee2011-11-25 00:18:01 +0000265 return fsl_esdhc_mmc_init(bis);
Jason Liu18936ee2011-11-25 00:18:01 +0000266}
Benoît Thébaudeauecb0f312012-08-17 10:42:55 +0000267#endif
Jason Liu18936ee2011-11-25 00:18:01 +0000268
Peng Fan7537e932018-01-10 13:20:25 +0800269#if !(defined(CONFIG_MX7) || defined(CONFIG_MX8M))
Fabio Estevam6a376042012-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 Alonsocd562c82015-09-02 13:54:23 -0500281#endif
Eric Nelsone1eb75b2012-09-23 07:30:55 +0000282
Eric Nelsone1eb75b2012-09-23 07:30:55 +0000283void arch_preboot_os(void)
284{
Tim Harvey6ecbe132017-05-12 12:58:41 -0700285#if defined(CONFIG_PCIE_IMX)
286 imx_pcie_remove();
287#endif
Simon Glass10e40d52017-06-14 21:28:25 -0600288#if defined(CONFIG_SATA)
Simon Glass7e0712b2017-07-29 11:35:14 -0600289 sata_remove(0);
Soeren Mochdd1c8f12014-11-27 10:11:41 +0100290#if defined(CONFIG_MX6)
291 disable_sata_clock();
292#endif
Nikita Kiryanov44b98412014-11-21 12:47:26 +0200293#endif
294#if defined(CONFIG_VIDEO_IPUV3)
Eric Nelsone1eb75b2012-09-23 07:30:55 +0000295 /* disable video before launching O/S */
296 ipuv3_fb_shutdown();
Eric Nelsone1eb75b2012-09-23 07:30:55 +0000297#endif
Peng Fan623787f2015-10-29 15:54:51 +0800298#if defined(CONFIG_VIDEO_MXS)
299 lcdif_power_down();
300#endif
Nikita Kiryanov44b98412014-11-21 12:47:26 +0200301}
Fabio Estevam32c81ea2014-11-14 11:27:21 -0200302
Peng Fan7537e932018-01-10 13:20:25 +0800303#ifndef CONFIG_MX8M
Fabio Estevam32c81ea2014-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 Fan7537e932018-01-10 13:20:25 +0800334#endif
Fabio Estevam4555c262017-11-27 10:25:09 -0200335
Peng Fan423e84b2018-01-10 13:20:29 +0800336#if defined(CONFIG_MX7)
337/*
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
342#define OCOTP_TESTER3_SPEED_800MHZ 0
343#define OCOTP_TESTER3_SPEED_500MHZ 1
344#define OCOTP_TESTER3_SPEED_1GHZ 2
345#define OCOTP_TESTER3_SPEED_1P2GHZ 3
346
347u32 get_cpu_speed_grade_hz(void)
348{
349 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
350 struct fuse_bank *bank = &ocotp->bank[1];
351 struct fuse_bank1_regs *fuse =
352 (struct fuse_bank1_regs *)bank->fuse_regs;
353 uint32_t val;
354
355 val = readl(&fuse->tester3);
356 val >>= OCOTP_TESTER3_SPEED_SHIFT;
357 val &= 0x3;
358
359 switch(val) {
360 case OCOTP_TESTER3_SPEED_800MHZ:
361 return 800000000;
362 case OCOTP_TESTER3_SPEED_500MHZ:
363 return 500000000;
364 case OCOTP_TESTER3_SPEED_1GHZ:
365 return 1000000000;
366 case OCOTP_TESTER3_SPEED_1P2GHZ:
367 return 1200000000;
368 }
369 return 0;
370}
371
372/*
373 * OCOTP_TESTER3[7:6] (see Fusemap Description Table offset 0x440)
374 * defines a 2-bit SPEED_GRADING
375 */
376#define OCOTP_TESTER3_TEMP_SHIFT 6
377
378u32 get_cpu_temp_grade(int *minc, int *maxc)
379{
380 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
381 struct fuse_bank *bank = &ocotp->bank[1];
382 struct fuse_bank1_regs *fuse =
383 (struct fuse_bank1_regs *)bank->fuse_regs;
384 uint32_t val;
385
386 val = readl(&fuse->tester3);
387 val >>= OCOTP_TESTER3_TEMP_SHIFT;
388 val &= 0x3;
389
390 if (minc && maxc) {
391 if (val == TEMP_AUTOMOTIVE) {
392 *minc = -40;
393 *maxc = 125;
394 } else if (val == TEMP_INDUSTRIAL) {
395 *minc = -40;
396 *maxc = 105;
397 } else if (val == TEMP_EXTCOMMERCIAL) {
398 *minc = -20;
399 *maxc = 105;
400 } else {
401 *minc = 0;
402 *maxc = 95;
403 }
404 }
405 return val;
406}
407#endif
408
Fabio Estevam4555c262017-11-27 10:25:09 -0200409#ifdef CONFIG_NXP_BOARD_REVISION
410int nxp_board_rev(void)
411{
412 /*
413 * Get Board ID information from OCOTP_GP1[15:8]
414 * RevA: 0x1
415 * RevB: 0x2
416 * RevC: 0x3
417 */
418 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
419 struct fuse_bank *bank = &ocotp->bank[4];
420 struct fuse_bank4_regs *fuse =
421 (struct fuse_bank4_regs *)bank->fuse_regs;
422
423 return (readl(&fuse->gp1) >> 8 & 0x0F);
424}
425
426char nxp_board_rev_string(void)
427{
428 const char *rev = "A";
429
430 return (*rev + nxp_board_rev() - 1);
431}
432#endif