blob: 4a175cb86f45fca9458c53fae8a2f990c67d0bec [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 Glassea8c0432020-07-19 10:15:41 -060011#include <dm.h>
Simon Glass97589732020-05-10 11:40:02 -060012#include <init.h>
Simon Glass0f2af882020-05-10 11:40:05 -060013#include <log.h>
Simon Glass274e0b02020-05-10 11:39:56 -060014#include <net.h>
Jeroen Hofstee1abf3a12014-10-08 22:57:52 +020015#include <netdev.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090016#include <linux/errno.h>
Jason Liu83aa8fe2011-11-25 00:18:01 +000017#include <asm/io.h>
18#include <asm/arch/imx-regs.h>
19#include <asm/arch/clock.h>
20#include <asm/arch/sys_proto.h>
Fabio Estevam6479f512012-04-29 08:11:13 +000021#include <asm/arch/crm_regs.h>
Peng Fand64a3c52018-01-10 13:20:34 +080022#include <asm/mach-imx/boot_mode.h>
Tim Harvey27f90592015-05-18 06:56:46 -070023#include <imx_thermal.h>
Eric Nelson54b3f3b2012-09-23 07:30:55 +000024#include <ipu_pixfmt.h>
Ye.Lif19692c2014-11-20 21:14:14 +080025#include <thermal.h>
Nikita Kiryanovb5c9ed32014-11-21 12:47:26 +020026#include <sata.h>
Jason Liu83aa8fe2011-11-25 00:18:01 +000027
Yangbo Lu73340382019-06-21 11:42:28 +080028#ifdef CONFIG_FSL_ESDHC_IMX
29#include <fsl_esdhc_imx.h>
Jason Liu83aa8fe2011-11-25 00:18:01 +000030#endif
31
Eric Nelson25e02302015-02-15 14:37:21 -070032static u32 reset_cause = -1;
33
Max Krummenachercb2c8fd2019-02-01 16:04:51 +010034u32 get_imx_reset_cause(void)
Jason Liu83aa8fe2011-11-25 00:18:01 +000035{
Jason Liu83aa8fe2011-11-25 00:18:01 +000036 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
37
Max Krummenachercb2c8fd2019-02-01 16:04:51 +010038 if (reset_cause == -1) {
39 reset_cause = readl(&src_regs->srsr);
40/* preserve the value for U-Boot proper */
41#if !defined(CONFIG_SPL_BUILD)
42 writel(reset_cause, &src_regs->srsr);
43#endif
44 }
45
46 return reset_cause;
47}
Jason Liu83aa8fe2011-11-25 00:18:01 +000048
Max Krummenachercb2c8fd2019-02-01 16:04:51 +010049#if defined(CONFIG_DISPLAY_CPUINFO) && !defined(CONFIG_SPL_BUILD)
50static char *get_reset_cause(void)
51{
52 switch (get_imx_reset_cause()) {
Jason Liu83aa8fe2011-11-25 00:18:01 +000053 case 0x00001:
Fabio Estevam9af122b2012-03-13 07:26:48 +000054 case 0x00011:
Jason Liu83aa8fe2011-11-25 00:18:01 +000055 return "POR";
56 case 0x00004:
57 return "CSU";
58 case 0x00008:
59 return "IPP USER";
60 case 0x00010:
Adrian Alonso9f883e02015-09-02 13:54:23 -050061#ifdef CONFIG_MX7
62 return "WDOG1";
63#else
Jason Liu83aa8fe2011-11-25 00:18:01 +000064 return "WDOG";
Adrian Alonso9f883e02015-09-02 13:54:23 -050065#endif
Jason Liu83aa8fe2011-11-25 00:18:01 +000066 case 0x00020:
67 return "JTAG HIGH-Z";
68 case 0x00040:
69 return "JTAG SW";
Adrian Alonso9f883e02015-09-02 13:54:23 -050070 case 0x00080:
71 return "WDOG3";
72#ifdef CONFIG_MX7
73 case 0x00100:
74 return "WDOG4";
75 case 0x00200:
76 return "TEMPSENSE";
Peng Fan39945c12018-11-20 10:19:25 +000077#elif defined(CONFIG_IMX8M)
Peng Fana78e0ac2018-01-10 13:20:25 +080078 case 0x00100:
79 return "WDOG2";
80 case 0x00200:
81 return "TEMPSENSE";
Adrian Alonso9f883e02015-09-02 13:54:23 -050082#else
83 case 0x00100:
84 return "TEMPSENSE";
Jason Liu83aa8fe2011-11-25 00:18:01 +000085 case 0x10000:
86 return "WARM BOOT";
Adrian Alonso9f883e02015-09-02 13:54:23 -050087#endif
Jason Liu83aa8fe2011-11-25 00:18:01 +000088 default:
89 return "unknown reset";
90 }
91}
Prabhakar Kushwahaf2c19de2015-05-18 17:13:52 +053092#endif
Eric Nelson25e02302015-02-15 14:37:21 -070093
Anatolij Gustschin03dd9862017-08-28 21:46:26 +020094#if defined(CONFIG_DISPLAY_CPUINFO) && !defined(CONFIG_SPL_BUILD)
Fabio Estevam46e97332012-03-20 04:21:45 +000095
Troy Kisky58394932012-10-23 10:57:46 +000096const char *get_imx_type(u32 imxtype)
Fabio Estevam46e97332012-03-20 04:21:45 +000097{
98 switch (imxtype) {
Peng Fan69cec072019-12-27 10:14:02 +080099 case MXC_CPU_IMX8MP:
Ye Lid2d754f2020-04-20 20:12:54 -0700100 return "8MP[8]"; /* Quad-core version of the imx8mp */
101 case MXC_CPU_IMX8MPD:
102 return "8MP Dual[3]"; /* Dual-core version of the imx8mp */
103 case MXC_CPU_IMX8MPL:
104 return "8MP Lite[4]"; /* Quad-core Lite version of the imx8mp */
Ye Lid2d754f2020-04-20 20:12:54 -0700105 case MXC_CPU_IMX8MP6:
106 return "8MP[6]"; /* Quad-core version of the imx8mp, NPU fused */
Peng Fan5d2f2062019-06-27 17:23:49 +0800107 case MXC_CPU_IMX8MN:
Peng Fan1a07d912020-02-05 17:39:27 +0800108 return "8MNano Quad"; /* Quad-core version */
109 case MXC_CPU_IMX8MND:
110 return "8MNano Dual"; /* Dual-core version */
111 case MXC_CPU_IMX8MNS:
112 return "8MNano Solo"; /* Single-core version */
113 case MXC_CPU_IMX8MNL:
114 return "8MNano QuadLite"; /* Quad-core Lite version */
115 case MXC_CPU_IMX8MNDL:
116 return "8MNano DualLite"; /* Dual-core Lite version */
117 case MXC_CPU_IMX8MNSL:
118 return "8MNano SoloLite"; /* Single-core Lite version */
Peng Fan2d22a992019-08-27 06:25:04 +0000119 case MXC_CPU_IMX8MM:
120 return "8MMQ"; /* Quad-core version of the imx8mm */
121 case MXC_CPU_IMX8MML:
122 return "8MMQL"; /* Quad-core Lite version of the imx8mm */
123 case MXC_CPU_IMX8MMD:
124 return "8MMD"; /* Dual-core version of the imx8mm */
125 case MXC_CPU_IMX8MMDL:
126 return "8MMDL"; /* Dual-core Lite version of the imx8mm */
127 case MXC_CPU_IMX8MMS:
128 return "8MMS"; /* Single-core version of the imx8mm */
129 case MXC_CPU_IMX8MMSL:
130 return "8MMSL"; /* Single-core Lite version of the imx8mm */
Peng Fan39945c12018-11-20 10:19:25 +0000131 case MXC_CPU_IMX8MQ:
Peng Fan67815082020-02-05 17:34:54 +0800132 return "8MQ"; /* Quad-core version of the imx8mq */
133 case MXC_CPU_IMX8MQL:
134 return "8MQLite"; /* Quad-core Lite version of the imx8mq */
135 case MXC_CPU_IMX8MD:
136 return "8MD"; /* Dual-core version of the imx8mq */
Fabio Estevamf6ced1b2016-02-28 12:33:17 -0300137 case MXC_CPU_MX7S:
Stefan Agnerf19a8e42016-05-06 11:21:50 -0700138 return "7S"; /* Single-core version of the mx7 */
Adrian Alonso9f883e02015-09-02 13:54:23 -0500139 case MXC_CPU_MX7D:
140 return "7D"; /* Dual-core version of the mx7 */
Peng Fan5f247922015-07-11 11:38:42 +0800141 case MXC_CPU_MX6QP:
142 return "6QP"; /* Quad-Plus version of the mx6 */
143 case MXC_CPU_MX6DP:
144 return "6DP"; /* Dual-Plus version of the mx6 */
Troy Kisky58394932012-10-23 10:57:46 +0000145 case MXC_CPU_MX6Q:
Fabio Estevam46e97332012-03-20 04:21:45 +0000146 return "6Q"; /* Quad-core version of the mx6 */
Fabio Estevamf3d5a2c2014-01-26 15:06:41 -0200147 case MXC_CPU_MX6D:
148 return "6D"; /* Dual-core version of the mx6 */
Troy Kisky58394932012-10-23 10:57:46 +0000149 case MXC_CPU_MX6DL:
150 return "6DL"; /* Dual Lite version of the mx6 */
151 case MXC_CPU_MX6SOLO:
152 return "6SOLO"; /* Solo version of the mx6 */
153 case MXC_CPU_MX6SL:
Fabio Estevam46e97332012-03-20 04:21:45 +0000154 return "6SL"; /* Solo-Lite version of the mx6 */
Peng Fan4cfd7972016-12-11 19:24:20 +0800155 case MXC_CPU_MX6SLL:
156 return "6SLL"; /* SLL version of the mx6 */
Fabio Estevam712ab882014-06-24 17:40:58 -0300157 case MXC_CPU_MX6SX:
158 return "6SX"; /* SoloX version of the mx6 */
Peng Faneaa53a12015-07-20 19:28:21 +0800159 case MXC_CPU_MX6UL:
160 return "6UL"; /* Ultra-Lite version of the mx6 */
Peng Fan3b33e3f2016-08-11 14:02:38 +0800161 case MXC_CPU_MX6ULL:
162 return "6ULL"; /* ULL version of the mx6 */
Peng Fanc53d0c92019-08-08 09:55:52 +0000163 case MXC_CPU_MX6ULZ:
164 return "6ULZ"; /* ULZ version of the mx6 */
Troy Kisky58394932012-10-23 10:57:46 +0000165 case MXC_CPU_MX51:
Fabio Estevam46e97332012-03-20 04:21:45 +0000166 return "51";
Troy Kisky58394932012-10-23 10:57:46 +0000167 case MXC_CPU_MX53:
Fabio Estevam46e97332012-03-20 04:21:45 +0000168 return "53";
169 default:
Otavio Salvador8567d7d2012-06-30 05:07:32 +0000170 return "??";
Fabio Estevam46e97332012-03-20 04:21:45 +0000171 }
172}
173
Jason Liu83aa8fe2011-11-25 00:18:01 +0000174int print_cpuinfo(void)
175{
Stefano Babic40adacc2015-05-26 19:53:41 +0200176 u32 cpurev;
177 __maybe_unused u32 max_freq;
Jason Liu83aa8fe2011-11-25 00:18:01 +0000178
Adrian Alonsoce08c362015-09-02 13:54:13 -0500179 cpurev = get_cpu_rev();
180
Peng Fan0df2e032020-05-03 22:19:57 +0800181#if defined(CONFIG_IMX_THERMAL) || defined(CONFIG_IMX_TMU)
Ye.Lif19692c2014-11-20 21:14:14 +0800182 struct udevice *thermal_dev;
Tim Harvey27f90592015-05-18 06:56:46 -0700183 int cpu_tmp, minc, maxc, ret;
Ye.Lif19692c2014-11-20 21:14:14 +0800184
Tim Harveyd792ede2015-05-18 07:02:25 -0700185 printf("CPU: Freescale i.MX%s rev%d.%d",
Peng Fan41b517212019-12-30 17:57:10 +0800186 get_imx_type((cpurev & 0x1FF000) >> 12),
Tim Harveyd792ede2015-05-18 07:02:25 -0700187 (cpurev & 0x000F0) >> 4,
188 (cpurev & 0x0000F) >> 0);
189 max_freq = get_cpu_speed_grade_hz();
190 if (!max_freq || max_freq == mxc_get_clock(MXC_ARM_CLK)) {
191 printf(" at %dMHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
192 } else {
193 printf(" %d MHz (running at %d MHz)\n", max_freq / 1000000,
194 mxc_get_clock(MXC_ARM_CLK) / 1000000);
195 }
196#else
Fabio Estevam46e97332012-03-20 04:21:45 +0000197 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
Peng Fan41b517212019-12-30 17:57:10 +0800198 get_imx_type((cpurev & 0x1FF000) >> 12),
Jason Liu83aa8fe2011-11-25 00:18:01 +0000199 (cpurev & 0x000F0) >> 4,
200 (cpurev & 0x0000F) >> 0,
201 mxc_get_clock(MXC_ARM_CLK) / 1000000);
Tim Harveyd792ede2015-05-18 07:02:25 -0700202#endif
Ye.Lif19692c2014-11-20 21:14:14 +0800203
Peng Fan0df2e032020-05-03 22:19:57 +0800204#if defined(CONFIG_IMX_THERMAL) || defined(CONFIG_IMX_TMU)
Tim Harvey27f90592015-05-18 06:56:46 -0700205 puts("CPU: ");
206 switch (get_cpu_temp_grade(&minc, &maxc)) {
207 case TEMP_AUTOMOTIVE:
208 puts("Automotive temperature grade ");
209 break;
210 case TEMP_INDUSTRIAL:
211 puts("Industrial temperature grade ");
212 break;
213 case TEMP_EXTCOMMERCIAL:
214 puts("Extended Commercial temperature grade ");
215 break;
216 default:
217 puts("Commercial temperature grade ");
218 break;
219 }
220 printf("(%dC to %dC)", minc, maxc);
Ye.Lif19692c2014-11-20 21:14:14 +0800221 ret = uclass_get_device(UCLASS_THERMAL, 0, &thermal_dev);
222 if (!ret) {
223 ret = thermal_get_temp(thermal_dev, &cpu_tmp);
224
225 if (!ret)
Tim Harvey27f90592015-05-18 06:56:46 -0700226 printf(" at %dC\n", cpu_tmp);
Ye.Lif19692c2014-11-20 21:14:14 +0800227 else
Fabio Estevamf62604d2015-09-08 14:43:10 -0300228 debug(" - invalid sensor data\n");
Ye.Lif19692c2014-11-20 21:14:14 +0800229 } else {
Fabio Estevamf62604d2015-09-08 14:43:10 -0300230 debug(" - invalid sensor device\n");
Ye.Lif19692c2014-11-20 21:14:14 +0800231 }
232#endif
233
Jason Liu83aa8fe2011-11-25 00:18:01 +0000234 printf("Reset cause: %s\n", get_reset_cause());
235 return 0;
236}
237#endif
238
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900239int cpu_eth_init(struct bd_info *bis)
Jason Liu83aa8fe2011-11-25 00:18:01 +0000240{
241 int rc = -ENODEV;
242
243#if defined(CONFIG_FEC_MXC)
244 rc = fecmxc_initialize(bis);
245#endif
246
247 return rc;
248}
249
Yangbo Lu73340382019-06-21 11:42:28 +0800250#ifdef CONFIG_FSL_ESDHC_IMX
Jason Liu83aa8fe2011-11-25 00:18:01 +0000251/*
252 * Initializes on-chip MMC controllers.
253 * to override, implement board_mmc_init()
254 */
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900255int cpu_mmc_init(struct bd_info *bis)
Jason Liu83aa8fe2011-11-25 00:18:01 +0000256{
Jason Liu83aa8fe2011-11-25 00:18:01 +0000257 return fsl_esdhc_mmc_init(bis);
Jason Liu83aa8fe2011-11-25 00:18:01 +0000258}
Benoît Thébaudeau58d22322012-08-17 10:42:55 +0000259#endif
Jason Liu83aa8fe2011-11-25 00:18:01 +0000260
Peng Fan39945c12018-11-20 10:19:25 +0000261#if !(defined(CONFIG_MX7) || defined(CONFIG_IMX8M))
Fabio Estevam6479f512012-04-29 08:11:13 +0000262u32 get_ahb_clk(void)
263{
264 struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
265 u32 reg, ahb_podf;
266
267 reg = __raw_readl(&imx_ccm->cbcdr);
268 reg &= MXC_CCM_CBCDR_AHB_PODF_MASK;
269 ahb_podf = reg >> MXC_CCM_CBCDR_AHB_PODF_OFFSET;
270
271 return get_periph_clk() / (ahb_podf + 1);
272}
Adrian Alonso9f883e02015-09-02 13:54:23 -0500273#endif
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000274
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000275void arch_preboot_os(void)
276{
Marek Vasut81647a32019-06-09 03:50:51 +0200277#if defined(CONFIG_PCIE_IMX) && !CONFIG_IS_ENABLED(DM_PCI)
Tim Harveyc22f2ea2017-05-12 12:58:41 -0700278 imx_pcie_remove();
279#endif
Simon Glassab3055a2017-06-14 21:28:25 -0600280#if defined(CONFIG_SATA)
Ludwig Zenzeb15ce22019-07-02 15:10:52 +0200281 if (!is_mx6sdl()) {
282 sata_remove(0);
Soeren Mocha517d022014-11-27 10:11:41 +0100283#if defined(CONFIG_MX6)
Ludwig Zenzeb15ce22019-07-02 15:10:52 +0200284 disable_sata_clock();
Soeren Mocha517d022014-11-27 10:11:41 +0100285#endif
Ludwig Zenzeb15ce22019-07-02 15:10:52 +0200286 }
Nikita Kiryanovb5c9ed32014-11-21 12:47:26 +0200287#endif
288#if defined(CONFIG_VIDEO_IPUV3)
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000289 /* disable video before launching O/S */
290 ipuv3_fb_shutdown();
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000291#endif
Igor Opaniukf5abe402019-06-04 00:05:59 +0300292#if defined(CONFIG_VIDEO_MXS) && !defined(CONFIG_DM_VIDEO)
Peng Fanf2c39922015-10-29 15:54:51 +0800293 lcdif_power_down();
294#endif
Nikita Kiryanovb5c9ed32014-11-21 12:47:26 +0200295}
Fabio Estevam16e65f62014-11-14 11:27:21 -0200296
Peng Fan39945c12018-11-20 10:19:25 +0000297#ifndef CONFIG_IMX8M
Fabio Estevam16e65f62014-11-14 11:27:21 -0200298void set_chipselect_size(int const cs_size)
299{
300 unsigned int reg;
301 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
302 reg = readl(&iomuxc_regs->gpr[1]);
303
304 switch (cs_size) {
305 case CS0_128:
306 reg &= ~0x7; /* CS0=128MB, CS1=0, CS2=0, CS3=0 */
307 reg |= 0x5;
308 break;
309 case CS0_64M_CS1_64M:
310 reg &= ~0x3F; /* CS0=64MB, CS1=64MB, CS2=0, CS3=0 */
311 reg |= 0x1B;
312 break;
313 case CS0_64M_CS1_32M_CS2_32M:
314 reg &= ~0x1FF; /* CS0=64MB, CS1=32MB, CS2=32MB, CS3=0 */
315 reg |= 0x4B;
316 break;
317 case CS0_32M_CS1_32M_CS2_32M_CS3_32M:
318 reg &= ~0xFFF; /* CS0=32MB, CS1=32MB, CS2=32MB, CS3=32MB */
319 reg |= 0x249;
320 break;
321 default:
322 printf("Unknown chip select size: %d\n", cs_size);
323 break;
324 }
325
326 writel(reg, &iomuxc_regs->gpr[1]);
327}
Peng Fana78e0ac2018-01-10 13:20:25 +0800328#endif
Fabio Estevam49bcdd72017-11-27 10:25:09 -0200329
Peng Fan39945c12018-11-20 10:19:25 +0000330#if defined(CONFIG_MX7) || defined(CONFIG_IMX8M)
Peng Fan7753bc72018-01-10 13:20:29 +0800331/*
332 * OCOTP_TESTER3[9:8] (see Fusemap Description Table offset 0x440)
333 * defines a 2-bit SPEED_GRADING
334 */
335#define OCOTP_TESTER3_SPEED_SHIFT 8
Peng Fana12bf3c2018-01-10 13:20:30 +0800336enum cpu_speed {
337 OCOTP_TESTER3_SPEED_GRADE0,
338 OCOTP_TESTER3_SPEED_GRADE1,
339 OCOTP_TESTER3_SPEED_GRADE2,
340 OCOTP_TESTER3_SPEED_GRADE3,
Peng Fan6a5f9c92018-12-12 02:47:58 -0800341 OCOTP_TESTER3_SPEED_GRADE4,
Peng Fana12bf3c2018-01-10 13:20:30 +0800342};
Peng Fan7753bc72018-01-10 13:20:29 +0800343
344u32 get_cpu_speed_grade_hz(void)
345{
346 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
347 struct fuse_bank *bank = &ocotp->bank[1];
348 struct fuse_bank1_regs *fuse =
349 (struct fuse_bank1_regs *)bank->fuse_regs;
350 uint32_t val;
351
352 val = readl(&fuse->tester3);
353 val >>= OCOTP_TESTER3_SPEED_SHIFT;
Peng Fan6a5f9c92018-12-12 02:47:58 -0800354
Peng Fan0599e5e2020-01-17 16:11:29 +0800355 if (is_imx8mn() || is_imx8mp()) {
Peng Fan6a5f9c92018-12-12 02:47:58 -0800356 val &= 0xf;
357 return 2300000000 - val * 100000000;
358 }
359
360 if (is_imx8mm())
361 val &= 0x7;
362 else
363 val &= 0x3;
Peng Fan7753bc72018-01-10 13:20:29 +0800364
365 switch(val) {
Peng Fana12bf3c2018-01-10 13:20:30 +0800366 case OCOTP_TESTER3_SPEED_GRADE0:
Peng Fan7753bc72018-01-10 13:20:29 +0800367 return 800000000;
Peng Fana12bf3c2018-01-10 13:20:30 +0800368 case OCOTP_TESTER3_SPEED_GRADE1:
Ye Lic9c1f9c2018-10-16 23:12:37 -0700369 return (is_mx7() ? 500000000 : (is_imx8mq() ? 1000000000 : 1200000000));
Peng Fana12bf3c2018-01-10 13:20:30 +0800370 case OCOTP_TESTER3_SPEED_GRADE2:
Ye Lic9c1f9c2018-10-16 23:12:37 -0700371 return (is_mx7() ? 1000000000 : (is_imx8mq() ? 1300000000 : 1600000000));
Peng Fana12bf3c2018-01-10 13:20:30 +0800372 case OCOTP_TESTER3_SPEED_GRADE3:
Ye Lic9c1f9c2018-10-16 23:12:37 -0700373 return (is_mx7() ? 1200000000 : (is_imx8mq() ? 1500000000 : 1800000000));
Peng Fan6a5f9c92018-12-12 02:47:58 -0800374 case OCOTP_TESTER3_SPEED_GRADE4:
375 return 2000000000;
Peng Fan7753bc72018-01-10 13:20:29 +0800376 }
Peng Fana12bf3c2018-01-10 13:20:30 +0800377
Peng Fan7753bc72018-01-10 13:20:29 +0800378 return 0;
379}
380
381/*
382 * OCOTP_TESTER3[7:6] (see Fusemap Description Table offset 0x440)
383 * defines a 2-bit SPEED_GRADING
384 */
385#define OCOTP_TESTER3_TEMP_SHIFT 6
386
387u32 get_cpu_temp_grade(int *minc, int *maxc)
388{
389 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
390 struct fuse_bank *bank = &ocotp->bank[1];
391 struct fuse_bank1_regs *fuse =
392 (struct fuse_bank1_regs *)bank->fuse_regs;
393 uint32_t val;
394
395 val = readl(&fuse->tester3);
396 val >>= OCOTP_TESTER3_TEMP_SHIFT;
397 val &= 0x3;
398
399 if (minc && maxc) {
400 if (val == TEMP_AUTOMOTIVE) {
401 *minc = -40;
402 *maxc = 125;
403 } else if (val == TEMP_INDUSTRIAL) {
404 *minc = -40;
405 *maxc = 105;
406 } else if (val == TEMP_EXTCOMMERCIAL) {
407 *minc = -20;
408 *maxc = 105;
409 } else {
410 *minc = 0;
411 *maxc = 95;
412 }
413 }
414 return val;
415}
416#endif
417
Peng Fan88c41fd2019-09-16 03:09:34 +0000418#if defined(CONFIG_MX7) || defined(CONFIG_IMX8MQ) || defined(CONFIG_IMX8MM)
Peng Fand64a3c52018-01-10 13:20:34 +0800419enum boot_device get_boot_device(void)
420{
421 struct bootrom_sw_info **p =
422 (struct bootrom_sw_info **)(ulong)ROM_SW_INFO_ADDR;
423
424 enum boot_device boot_dev = SD1_BOOT;
425 u8 boot_type = (*p)->boot_dev_type;
426 u8 boot_instance = (*p)->boot_dev_instance;
427
428 switch (boot_type) {
429 case BOOT_TYPE_SD:
430 boot_dev = boot_instance + SD1_BOOT;
431 break;
432 case BOOT_TYPE_MMC:
433 boot_dev = boot_instance + MMC1_BOOT;
434 break;
435 case BOOT_TYPE_NAND:
436 boot_dev = NAND_BOOT;
437 break;
438 case BOOT_TYPE_QSPI:
439 boot_dev = QSPI_BOOT;
440 break;
441 case BOOT_TYPE_WEIM:
442 boot_dev = WEIM_NOR_BOOT;
443 break;
444 case BOOT_TYPE_SPINOR:
445 boot_dev = SPI_NOR_BOOT;
446 break;
Peng Fan39945c12018-11-20 10:19:25 +0000447#ifdef CONFIG_IMX8M
Peng Fan24d3fbc2018-01-10 13:20:35 +0800448 case BOOT_TYPE_USB:
449 boot_dev = USB_BOOT;
450 break;
451#endif
Peng Fand64a3c52018-01-10 13:20:34 +0800452 default:
453 break;
454 }
455
456 return boot_dev;
457}
458#endif
459
Fabio Estevam49bcdd72017-11-27 10:25:09 -0200460#ifdef CONFIG_NXP_BOARD_REVISION
461int nxp_board_rev(void)
462{
463 /*
464 * Get Board ID information from OCOTP_GP1[15:8]
465 * RevA: 0x1
466 * RevB: 0x2
467 * RevC: 0x3
468 */
469 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
470 struct fuse_bank *bank = &ocotp->bank[4];
471 struct fuse_bank4_regs *fuse =
472 (struct fuse_bank4_regs *)bank->fuse_regs;
473
474 return (readl(&fuse->gp1) >> 8 & 0x0F);
475}
476
477char nxp_board_rev_string(void)
478{
479 const char *rev = "A";
480
481 return (*rev + nxp_board_rev() - 1);
482}
483#endif