blob: f2070c97143261541ea8e3382467b48e66d8c949 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jason Liu83aa8fe2011-11-25 00:18:01 +00002/*
3 * (C) Copyright 2007
4 * Sascha Hauer, Pengutronix
5 *
6 * (C) Copyright 2009 Freescale Semiconductor, Inc.
Jason Liu83aa8fe2011-11-25 00:18:01 +00007 */
8
Jeroen Hofstee1abf3a12014-10-08 22:57:52 +02009#include <bootm.h>
Jason Liu83aa8fe2011-11-25 00:18:01 +000010#include <common.h>
Simon Glass97589732020-05-10 11:40:02 -060011#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060012#include <log.h>
Simon Glass274e0b02020-05-10 11:39:56 -060013#include <net.h>
Jeroen Hofstee1abf3a12014-10-08 22:57:52 +020014#include <netdev.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090015#include <linux/errno.h>
Jason Liu83aa8fe2011-11-25 00:18:01 +000016#include <asm/io.h>
17#include <asm/arch/imx-regs.h>
18#include <asm/arch/clock.h>
19#include <asm/arch/sys_proto.h>
Fabio Estevam6479f512012-04-29 08:11:13 +000020#include <asm/arch/crm_regs.h>
Peng Fand64a3c52018-01-10 13:20:34 +080021#include <asm/mach-imx/boot_mode.h>
Tim Harvey27f90592015-05-18 06:56:46 -070022#include <imx_thermal.h>
Eric Nelson54b3f3b2012-09-23 07:30:55 +000023#include <ipu_pixfmt.h>
Ye.Lif19692c2014-11-20 21:14:14 +080024#include <thermal.h>
Nikita Kiryanovb5c9ed32014-11-21 12:47:26 +020025#include <sata.h>
Jason Liu83aa8fe2011-11-25 00:18:01 +000026
Yangbo Lu73340382019-06-21 11:42:28 +080027#ifdef CONFIG_FSL_ESDHC_IMX
28#include <fsl_esdhc_imx.h>
Jason Liu83aa8fe2011-11-25 00:18:01 +000029#endif
30
Eric Nelson25e02302015-02-15 14:37:21 -070031static u32 reset_cause = -1;
32
Max Krummenachercb2c8fd2019-02-01 16:04:51 +010033u32 get_imx_reset_cause(void)
Jason Liu83aa8fe2011-11-25 00:18:01 +000034{
Jason Liu83aa8fe2011-11-25 00:18:01 +000035 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
36
Max Krummenachercb2c8fd2019-02-01 16:04:51 +010037 if (reset_cause == -1) {
38 reset_cause = readl(&src_regs->srsr);
39/* preserve the value for U-Boot proper */
40#if !defined(CONFIG_SPL_BUILD)
41 writel(reset_cause, &src_regs->srsr);
42#endif
43 }
44
45 return reset_cause;
46}
Jason Liu83aa8fe2011-11-25 00:18:01 +000047
Max Krummenachercb2c8fd2019-02-01 16:04:51 +010048#if defined(CONFIG_DISPLAY_CPUINFO) && !defined(CONFIG_SPL_BUILD)
49static char *get_reset_cause(void)
50{
51 switch (get_imx_reset_cause()) {
Jason Liu83aa8fe2011-11-25 00:18:01 +000052 case 0x00001:
Fabio Estevam9af122b2012-03-13 07:26:48 +000053 case 0x00011:
Jason Liu83aa8fe2011-11-25 00:18:01 +000054 return "POR";
55 case 0x00004:
56 return "CSU";
57 case 0x00008:
58 return "IPP USER";
59 case 0x00010:
Adrian Alonso9f883e02015-09-02 13:54:23 -050060#ifdef CONFIG_MX7
61 return "WDOG1";
62#else
Jason Liu83aa8fe2011-11-25 00:18:01 +000063 return "WDOG";
Adrian Alonso9f883e02015-09-02 13:54:23 -050064#endif
Jason Liu83aa8fe2011-11-25 00:18:01 +000065 case 0x00020:
66 return "JTAG HIGH-Z";
67 case 0x00040:
68 return "JTAG SW";
Adrian Alonso9f883e02015-09-02 13:54:23 -050069 case 0x00080:
70 return "WDOG3";
71#ifdef CONFIG_MX7
72 case 0x00100:
73 return "WDOG4";
74 case 0x00200:
75 return "TEMPSENSE";
Peng Fan39945c12018-11-20 10:19:25 +000076#elif defined(CONFIG_IMX8M)
Peng Fana78e0ac2018-01-10 13:20:25 +080077 case 0x00100:
78 return "WDOG2";
79 case 0x00200:
80 return "TEMPSENSE";
Adrian Alonso9f883e02015-09-02 13:54:23 -050081#else
82 case 0x00100:
83 return "TEMPSENSE";
Jason Liu83aa8fe2011-11-25 00:18:01 +000084 case 0x10000:
85 return "WARM BOOT";
Adrian Alonso9f883e02015-09-02 13:54:23 -050086#endif
Jason Liu83aa8fe2011-11-25 00:18:01 +000087 default:
88 return "unknown reset";
89 }
90}
Prabhakar Kushwahaf2c19de2015-05-18 17:13:52 +053091#endif
Eric Nelson25e02302015-02-15 14:37:21 -070092
Anatolij Gustschin03dd9862017-08-28 21:46:26 +020093#if defined(CONFIG_DISPLAY_CPUINFO) && !defined(CONFIG_SPL_BUILD)
Fabio Estevam46e97332012-03-20 04:21:45 +000094
Troy Kisky58394932012-10-23 10:57:46 +000095const char *get_imx_type(u32 imxtype)
Fabio Estevam46e97332012-03-20 04:21:45 +000096{
97 switch (imxtype) {
Peng Fan69cec072019-12-27 10:14:02 +080098 case MXC_CPU_IMX8MP:
99 return "8MP"; /* Quad-core version of the imx8mp */
Peng Fan5d2f2062019-06-27 17:23:49 +0800100 case MXC_CPU_IMX8MN:
Peng Fan1a07d912020-02-05 17:39:27 +0800101 return "8MNano Quad"; /* Quad-core version */
102 case MXC_CPU_IMX8MND:
103 return "8MNano Dual"; /* Dual-core version */
104 case MXC_CPU_IMX8MNS:
105 return "8MNano Solo"; /* Single-core version */
106 case MXC_CPU_IMX8MNL:
107 return "8MNano QuadLite"; /* Quad-core Lite version */
108 case MXC_CPU_IMX8MNDL:
109 return "8MNano DualLite"; /* Dual-core Lite version */
110 case MXC_CPU_IMX8MNSL:
111 return "8MNano SoloLite"; /* Single-core Lite version */
Peng Fan2d22a992019-08-27 06:25:04 +0000112 case MXC_CPU_IMX8MM:
113 return "8MMQ"; /* Quad-core version of the imx8mm */
114 case MXC_CPU_IMX8MML:
115 return "8MMQL"; /* Quad-core Lite version of the imx8mm */
116 case MXC_CPU_IMX8MMD:
117 return "8MMD"; /* Dual-core version of the imx8mm */
118 case MXC_CPU_IMX8MMDL:
119 return "8MMDL"; /* Dual-core Lite version of the imx8mm */
120 case MXC_CPU_IMX8MMS:
121 return "8MMS"; /* Single-core version of the imx8mm */
122 case MXC_CPU_IMX8MMSL:
123 return "8MMSL"; /* Single-core Lite version of the imx8mm */
Peng Fan39945c12018-11-20 10:19:25 +0000124 case MXC_CPU_IMX8MQ:
Peng Fan67815082020-02-05 17:34:54 +0800125 return "8MQ"; /* Quad-core version of the imx8mq */
126 case MXC_CPU_IMX8MQL:
127 return "8MQLite"; /* Quad-core Lite version of the imx8mq */
128 case MXC_CPU_IMX8MD:
129 return "8MD"; /* Dual-core version of the imx8mq */
Fabio Estevamf6ced1b2016-02-28 12:33:17 -0300130 case MXC_CPU_MX7S:
Stefan Agnerf19a8e42016-05-06 11:21:50 -0700131 return "7S"; /* Single-core version of the mx7 */
Adrian Alonso9f883e02015-09-02 13:54:23 -0500132 case MXC_CPU_MX7D:
133 return "7D"; /* Dual-core version of the mx7 */
Peng Fan5f247922015-07-11 11:38:42 +0800134 case MXC_CPU_MX6QP:
135 return "6QP"; /* Quad-Plus version of the mx6 */
136 case MXC_CPU_MX6DP:
137 return "6DP"; /* Dual-Plus version of the mx6 */
Troy Kisky58394932012-10-23 10:57:46 +0000138 case MXC_CPU_MX6Q:
Fabio Estevam46e97332012-03-20 04:21:45 +0000139 return "6Q"; /* Quad-core version of the mx6 */
Fabio Estevamf3d5a2c2014-01-26 15:06:41 -0200140 case MXC_CPU_MX6D:
141 return "6D"; /* Dual-core version of the mx6 */
Troy Kisky58394932012-10-23 10:57:46 +0000142 case MXC_CPU_MX6DL:
143 return "6DL"; /* Dual Lite version of the mx6 */
144 case MXC_CPU_MX6SOLO:
145 return "6SOLO"; /* Solo version of the mx6 */
146 case MXC_CPU_MX6SL:
Fabio Estevam46e97332012-03-20 04:21:45 +0000147 return "6SL"; /* Solo-Lite version of the mx6 */
Peng Fan4cfd7972016-12-11 19:24:20 +0800148 case MXC_CPU_MX6SLL:
149 return "6SLL"; /* SLL version of the mx6 */
Fabio Estevam712ab882014-06-24 17:40:58 -0300150 case MXC_CPU_MX6SX:
151 return "6SX"; /* SoloX version of the mx6 */
Peng Faneaa53a12015-07-20 19:28:21 +0800152 case MXC_CPU_MX6UL:
153 return "6UL"; /* Ultra-Lite version of the mx6 */
Peng Fan3b33e3f2016-08-11 14:02:38 +0800154 case MXC_CPU_MX6ULL:
155 return "6ULL"; /* ULL version of the mx6 */
Peng Fanc53d0c92019-08-08 09:55:52 +0000156 case MXC_CPU_MX6ULZ:
157 return "6ULZ"; /* ULZ version of the mx6 */
Troy Kisky58394932012-10-23 10:57:46 +0000158 case MXC_CPU_MX51:
Fabio Estevam46e97332012-03-20 04:21:45 +0000159 return "51";
Troy Kisky58394932012-10-23 10:57:46 +0000160 case MXC_CPU_MX53:
Fabio Estevam46e97332012-03-20 04:21:45 +0000161 return "53";
162 default:
Otavio Salvador8567d7d2012-06-30 05:07:32 +0000163 return "??";
Fabio Estevam46e97332012-03-20 04:21:45 +0000164 }
165}
166
Jason Liu83aa8fe2011-11-25 00:18:01 +0000167int print_cpuinfo(void)
168{
Stefano Babic40adacc2015-05-26 19:53:41 +0200169 u32 cpurev;
170 __maybe_unused u32 max_freq;
Jason Liu83aa8fe2011-11-25 00:18:01 +0000171
Adrian Alonsoce08c362015-09-02 13:54:13 -0500172 cpurev = get_cpu_rev();
173
Peng Fan0df2e032020-05-03 22:19:57 +0800174#if defined(CONFIG_IMX_THERMAL) || defined(CONFIG_IMX_TMU)
Ye.Lif19692c2014-11-20 21:14:14 +0800175 struct udevice *thermal_dev;
Tim Harvey27f90592015-05-18 06:56:46 -0700176 int cpu_tmp, minc, maxc, ret;
Ye.Lif19692c2014-11-20 21:14:14 +0800177
Tim Harveyd792ede2015-05-18 07:02:25 -0700178 printf("CPU: Freescale i.MX%s rev%d.%d",
Peng Fan41b517212019-12-30 17:57:10 +0800179 get_imx_type((cpurev & 0x1FF000) >> 12),
Tim Harveyd792ede2015-05-18 07:02:25 -0700180 (cpurev & 0x000F0) >> 4,
181 (cpurev & 0x0000F) >> 0);
182 max_freq = get_cpu_speed_grade_hz();
183 if (!max_freq || max_freq == mxc_get_clock(MXC_ARM_CLK)) {
184 printf(" at %dMHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
185 } else {
186 printf(" %d MHz (running at %d MHz)\n", max_freq / 1000000,
187 mxc_get_clock(MXC_ARM_CLK) / 1000000);
188 }
189#else
Fabio Estevam46e97332012-03-20 04:21:45 +0000190 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
Peng Fan41b517212019-12-30 17:57:10 +0800191 get_imx_type((cpurev & 0x1FF000) >> 12),
Jason Liu83aa8fe2011-11-25 00:18:01 +0000192 (cpurev & 0x000F0) >> 4,
193 (cpurev & 0x0000F) >> 0,
194 mxc_get_clock(MXC_ARM_CLK) / 1000000);
Tim Harveyd792ede2015-05-18 07:02:25 -0700195#endif
Ye.Lif19692c2014-11-20 21:14:14 +0800196
Peng Fan0df2e032020-05-03 22:19:57 +0800197#if defined(CONFIG_IMX_THERMAL) || defined(CONFIG_IMX_TMU)
Tim Harvey27f90592015-05-18 06:56:46 -0700198 puts("CPU: ");
199 switch (get_cpu_temp_grade(&minc, &maxc)) {
200 case TEMP_AUTOMOTIVE:
201 puts("Automotive temperature grade ");
202 break;
203 case TEMP_INDUSTRIAL:
204 puts("Industrial temperature grade ");
205 break;
206 case TEMP_EXTCOMMERCIAL:
207 puts("Extended Commercial temperature grade ");
208 break;
209 default:
210 puts("Commercial temperature grade ");
211 break;
212 }
213 printf("(%dC to %dC)", minc, maxc);
Ye.Lif19692c2014-11-20 21:14:14 +0800214 ret = uclass_get_device(UCLASS_THERMAL, 0, &thermal_dev);
215 if (!ret) {
216 ret = thermal_get_temp(thermal_dev, &cpu_tmp);
217
218 if (!ret)
Tim Harvey27f90592015-05-18 06:56:46 -0700219 printf(" at %dC\n", cpu_tmp);
Ye.Lif19692c2014-11-20 21:14:14 +0800220 else
Fabio Estevamf62604d2015-09-08 14:43:10 -0300221 debug(" - invalid sensor data\n");
Ye.Lif19692c2014-11-20 21:14:14 +0800222 } else {
Fabio Estevamf62604d2015-09-08 14:43:10 -0300223 debug(" - invalid sensor device\n");
Ye.Lif19692c2014-11-20 21:14:14 +0800224 }
225#endif
226
Jason Liu83aa8fe2011-11-25 00:18:01 +0000227 printf("Reset cause: %s\n", get_reset_cause());
228 return 0;
229}
230#endif
231
232int cpu_eth_init(bd_t *bis)
233{
234 int rc = -ENODEV;
235
236#if defined(CONFIG_FEC_MXC)
237 rc = fecmxc_initialize(bis);
238#endif
239
240 return rc;
241}
242
Yangbo Lu73340382019-06-21 11:42:28 +0800243#ifdef CONFIG_FSL_ESDHC_IMX
Jason Liu83aa8fe2011-11-25 00:18:01 +0000244/*
245 * Initializes on-chip MMC controllers.
246 * to override, implement board_mmc_init()
247 */
248int cpu_mmc_init(bd_t *bis)
249{
Jason Liu83aa8fe2011-11-25 00:18:01 +0000250 return fsl_esdhc_mmc_init(bis);
Jason Liu83aa8fe2011-11-25 00:18:01 +0000251}
Benoît Thébaudeau58d22322012-08-17 10:42:55 +0000252#endif
Jason Liu83aa8fe2011-11-25 00:18:01 +0000253
Peng Fan39945c12018-11-20 10:19:25 +0000254#if !(defined(CONFIG_MX7) || defined(CONFIG_IMX8M))
Fabio Estevam6479f512012-04-29 08:11:13 +0000255u32 get_ahb_clk(void)
256{
257 struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
258 u32 reg, ahb_podf;
259
260 reg = __raw_readl(&imx_ccm->cbcdr);
261 reg &= MXC_CCM_CBCDR_AHB_PODF_MASK;
262 ahb_podf = reg >> MXC_CCM_CBCDR_AHB_PODF_OFFSET;
263
264 return get_periph_clk() / (ahb_podf + 1);
265}
Adrian Alonso9f883e02015-09-02 13:54:23 -0500266#endif
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000267
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000268void arch_preboot_os(void)
269{
Marek Vasut81647a32019-06-09 03:50:51 +0200270#if defined(CONFIG_PCIE_IMX) && !CONFIG_IS_ENABLED(DM_PCI)
Tim Harveyc22f2ea2017-05-12 12:58:41 -0700271 imx_pcie_remove();
272#endif
Simon Glassab3055a2017-06-14 21:28:25 -0600273#if defined(CONFIG_SATA)
Ludwig Zenzeb15ce22019-07-02 15:10:52 +0200274 if (!is_mx6sdl()) {
275 sata_remove(0);
Soeren Mocha517d022014-11-27 10:11:41 +0100276#if defined(CONFIG_MX6)
Ludwig Zenzeb15ce22019-07-02 15:10:52 +0200277 disable_sata_clock();
Soeren Mocha517d022014-11-27 10:11:41 +0100278#endif
Ludwig Zenzeb15ce22019-07-02 15:10:52 +0200279 }
Nikita Kiryanovb5c9ed32014-11-21 12:47:26 +0200280#endif
281#if defined(CONFIG_VIDEO_IPUV3)
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000282 /* disable video before launching O/S */
283 ipuv3_fb_shutdown();
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000284#endif
Igor Opaniukf5abe402019-06-04 00:05:59 +0300285#if defined(CONFIG_VIDEO_MXS) && !defined(CONFIG_DM_VIDEO)
Peng Fanf2c39922015-10-29 15:54:51 +0800286 lcdif_power_down();
287#endif
Nikita Kiryanovb5c9ed32014-11-21 12:47:26 +0200288}
Fabio Estevam16e65f62014-11-14 11:27:21 -0200289
Peng Fan39945c12018-11-20 10:19:25 +0000290#ifndef CONFIG_IMX8M
Fabio Estevam16e65f62014-11-14 11:27:21 -0200291void set_chipselect_size(int const cs_size)
292{
293 unsigned int reg;
294 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
295 reg = readl(&iomuxc_regs->gpr[1]);
296
297 switch (cs_size) {
298 case CS0_128:
299 reg &= ~0x7; /* CS0=128MB, CS1=0, CS2=0, CS3=0 */
300 reg |= 0x5;
301 break;
302 case CS0_64M_CS1_64M:
303 reg &= ~0x3F; /* CS0=64MB, CS1=64MB, CS2=0, CS3=0 */
304 reg |= 0x1B;
305 break;
306 case CS0_64M_CS1_32M_CS2_32M:
307 reg &= ~0x1FF; /* CS0=64MB, CS1=32MB, CS2=32MB, CS3=0 */
308 reg |= 0x4B;
309 break;
310 case CS0_32M_CS1_32M_CS2_32M_CS3_32M:
311 reg &= ~0xFFF; /* CS0=32MB, CS1=32MB, CS2=32MB, CS3=32MB */
312 reg |= 0x249;
313 break;
314 default:
315 printf("Unknown chip select size: %d\n", cs_size);
316 break;
317 }
318
319 writel(reg, &iomuxc_regs->gpr[1]);
320}
Peng Fana78e0ac2018-01-10 13:20:25 +0800321#endif
Fabio Estevam49bcdd72017-11-27 10:25:09 -0200322
Peng Fan39945c12018-11-20 10:19:25 +0000323#if defined(CONFIG_MX7) || defined(CONFIG_IMX8M)
Peng Fan7753bc72018-01-10 13:20:29 +0800324/*
325 * OCOTP_TESTER3[9:8] (see Fusemap Description Table offset 0x440)
326 * defines a 2-bit SPEED_GRADING
327 */
328#define OCOTP_TESTER3_SPEED_SHIFT 8
Peng Fana12bf3c2018-01-10 13:20:30 +0800329enum cpu_speed {
330 OCOTP_TESTER3_SPEED_GRADE0,
331 OCOTP_TESTER3_SPEED_GRADE1,
332 OCOTP_TESTER3_SPEED_GRADE2,
333 OCOTP_TESTER3_SPEED_GRADE3,
Peng Fan6a5f9c92018-12-12 02:47:58 -0800334 OCOTP_TESTER3_SPEED_GRADE4,
Peng Fana12bf3c2018-01-10 13:20:30 +0800335};
Peng Fan7753bc72018-01-10 13:20:29 +0800336
337u32 get_cpu_speed_grade_hz(void)
338{
339 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
340 struct fuse_bank *bank = &ocotp->bank[1];
341 struct fuse_bank1_regs *fuse =
342 (struct fuse_bank1_regs *)bank->fuse_regs;
343 uint32_t val;
344
345 val = readl(&fuse->tester3);
346 val >>= OCOTP_TESTER3_SPEED_SHIFT;
Peng Fan6a5f9c92018-12-12 02:47:58 -0800347
Peng Fan0599e5e2020-01-17 16:11:29 +0800348 if (is_imx8mn() || is_imx8mp()) {
Peng Fan6a5f9c92018-12-12 02:47:58 -0800349 val &= 0xf;
350 return 2300000000 - val * 100000000;
351 }
352
353 if (is_imx8mm())
354 val &= 0x7;
355 else
356 val &= 0x3;
Peng Fan7753bc72018-01-10 13:20:29 +0800357
358 switch(val) {
Peng Fana12bf3c2018-01-10 13:20:30 +0800359 case OCOTP_TESTER3_SPEED_GRADE0:
Peng Fan7753bc72018-01-10 13:20:29 +0800360 return 800000000;
Peng Fana12bf3c2018-01-10 13:20:30 +0800361 case OCOTP_TESTER3_SPEED_GRADE1:
Ye Lic9c1f9c2018-10-16 23:12:37 -0700362 return (is_mx7() ? 500000000 : (is_imx8mq() ? 1000000000 : 1200000000));
Peng Fana12bf3c2018-01-10 13:20:30 +0800363 case OCOTP_TESTER3_SPEED_GRADE2:
Ye Lic9c1f9c2018-10-16 23:12:37 -0700364 return (is_mx7() ? 1000000000 : (is_imx8mq() ? 1300000000 : 1600000000));
Peng Fana12bf3c2018-01-10 13:20:30 +0800365 case OCOTP_TESTER3_SPEED_GRADE3:
Ye Lic9c1f9c2018-10-16 23:12:37 -0700366 return (is_mx7() ? 1200000000 : (is_imx8mq() ? 1500000000 : 1800000000));
Peng Fan6a5f9c92018-12-12 02:47:58 -0800367 case OCOTP_TESTER3_SPEED_GRADE4:
368 return 2000000000;
Peng Fan7753bc72018-01-10 13:20:29 +0800369 }
Peng Fana12bf3c2018-01-10 13:20:30 +0800370
Peng Fan7753bc72018-01-10 13:20:29 +0800371 return 0;
372}
373
374/*
375 * OCOTP_TESTER3[7:6] (see Fusemap Description Table offset 0x440)
376 * defines a 2-bit SPEED_GRADING
377 */
378#define OCOTP_TESTER3_TEMP_SHIFT 6
379
380u32 get_cpu_temp_grade(int *minc, int *maxc)
381{
382 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
383 struct fuse_bank *bank = &ocotp->bank[1];
384 struct fuse_bank1_regs *fuse =
385 (struct fuse_bank1_regs *)bank->fuse_regs;
386 uint32_t val;
387
388 val = readl(&fuse->tester3);
389 val >>= OCOTP_TESTER3_TEMP_SHIFT;
390 val &= 0x3;
391
392 if (minc && maxc) {
393 if (val == TEMP_AUTOMOTIVE) {
394 *minc = -40;
395 *maxc = 125;
396 } else if (val == TEMP_INDUSTRIAL) {
397 *minc = -40;
398 *maxc = 105;
399 } else if (val == TEMP_EXTCOMMERCIAL) {
400 *minc = -20;
401 *maxc = 105;
402 } else {
403 *minc = 0;
404 *maxc = 95;
405 }
406 }
407 return val;
408}
409#endif
410
Peng Fan88c41fd2019-09-16 03:09:34 +0000411#if defined(CONFIG_MX7) || defined(CONFIG_IMX8MQ) || defined(CONFIG_IMX8MM)
Peng Fand64a3c52018-01-10 13:20:34 +0800412enum boot_device get_boot_device(void)
413{
414 struct bootrom_sw_info **p =
415 (struct bootrom_sw_info **)(ulong)ROM_SW_INFO_ADDR;
416
417 enum boot_device boot_dev = SD1_BOOT;
418 u8 boot_type = (*p)->boot_dev_type;
419 u8 boot_instance = (*p)->boot_dev_instance;
420
421 switch (boot_type) {
422 case BOOT_TYPE_SD:
423 boot_dev = boot_instance + SD1_BOOT;
424 break;
425 case BOOT_TYPE_MMC:
426 boot_dev = boot_instance + MMC1_BOOT;
427 break;
428 case BOOT_TYPE_NAND:
429 boot_dev = NAND_BOOT;
430 break;
431 case BOOT_TYPE_QSPI:
432 boot_dev = QSPI_BOOT;
433 break;
434 case BOOT_TYPE_WEIM:
435 boot_dev = WEIM_NOR_BOOT;
436 break;
437 case BOOT_TYPE_SPINOR:
438 boot_dev = SPI_NOR_BOOT;
439 break;
Peng Fan39945c12018-11-20 10:19:25 +0000440#ifdef CONFIG_IMX8M
Peng Fan24d3fbc2018-01-10 13:20:35 +0800441 case BOOT_TYPE_USB:
442 boot_dev = USB_BOOT;
443 break;
444#endif
Peng Fand64a3c52018-01-10 13:20:34 +0800445 default:
446 break;
447 }
448
449 return boot_dev;
450}
451#endif
452
Fabio Estevam49bcdd72017-11-27 10:25:09 -0200453#ifdef CONFIG_NXP_BOARD_REVISION
454int nxp_board_rev(void)
455{
456 /*
457 * Get Board ID information from OCOTP_GP1[15:8]
458 * RevA: 0x1
459 * RevB: 0x2
460 * RevC: 0x3
461 */
462 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
463 struct fuse_bank *bank = &ocotp->bank[4];
464 struct fuse_bank4_regs *fuse =
465 (struct fuse_bank4_regs *)bank->fuse_regs;
466
467 return (readl(&fuse->gp1) >> 8 & 0x0F);
468}
469
470char nxp_board_rev_string(void)
471{
472 const char *rev = "A";
473
474 return (*rev + nxp_board_rev() - 1);
475}
476#endif