blob: 38b87ed5c39a9daf0251c7f52d3d68addd297087 [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>
Ye Li3525e3c2019-07-22 20:51:25 -070027#include <dm/device-internal.h>
28#include <dm/uclass-internal.h>
Jason Liu83aa8fe2011-11-25 00:18:01 +000029
Yangbo Lu73340382019-06-21 11:42:28 +080030#ifdef CONFIG_FSL_ESDHC_IMX
31#include <fsl_esdhc_imx.h>
Jason Liu83aa8fe2011-11-25 00:18:01 +000032#endif
33
Eric Nelson25e02302015-02-15 14:37:21 -070034static u32 reset_cause = -1;
35
Max Krummenachercb2c8fd2019-02-01 16:04:51 +010036u32 get_imx_reset_cause(void)
Jason Liu83aa8fe2011-11-25 00:18:01 +000037{
Jason Liu83aa8fe2011-11-25 00:18:01 +000038 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
39
Max Krummenachercb2c8fd2019-02-01 16:04:51 +010040 if (reset_cause == -1) {
41 reset_cause = readl(&src_regs->srsr);
42/* preserve the value for U-Boot proper */
43#if !defined(CONFIG_SPL_BUILD)
44 writel(reset_cause, &src_regs->srsr);
45#endif
46 }
47
48 return reset_cause;
49}
Jason Liu83aa8fe2011-11-25 00:18:01 +000050
Max Krummenachercb2c8fd2019-02-01 16:04:51 +010051#if defined(CONFIG_DISPLAY_CPUINFO) && !defined(CONFIG_SPL_BUILD)
52static char *get_reset_cause(void)
53{
54 switch (get_imx_reset_cause()) {
Jason Liu83aa8fe2011-11-25 00:18:01 +000055 case 0x00001:
Fabio Estevam9af122b2012-03-13 07:26:48 +000056 case 0x00011:
Jason Liu83aa8fe2011-11-25 00:18:01 +000057 return "POR";
58 case 0x00004:
59 return "CSU";
60 case 0x00008:
61 return "IPP USER";
62 case 0x00010:
Adrian Alonso9f883e02015-09-02 13:54:23 -050063#ifdef CONFIG_MX7
64 return "WDOG1";
65#else
Jason Liu83aa8fe2011-11-25 00:18:01 +000066 return "WDOG";
Adrian Alonso9f883e02015-09-02 13:54:23 -050067#endif
Jason Liu83aa8fe2011-11-25 00:18:01 +000068 case 0x00020:
69 return "JTAG HIGH-Z";
70 case 0x00040:
71 return "JTAG SW";
Adrian Alonso9f883e02015-09-02 13:54:23 -050072 case 0x00080:
73 return "WDOG3";
74#ifdef CONFIG_MX7
75 case 0x00100:
76 return "WDOG4";
77 case 0x00200:
78 return "TEMPSENSE";
Peng Fan39945c12018-11-20 10:19:25 +000079#elif defined(CONFIG_IMX8M)
Peng Fana78e0ac2018-01-10 13:20:25 +080080 case 0x00100:
81 return "WDOG2";
82 case 0x00200:
83 return "TEMPSENSE";
Adrian Alonso9f883e02015-09-02 13:54:23 -050084#else
85 case 0x00100:
86 return "TEMPSENSE";
Jason Liu83aa8fe2011-11-25 00:18:01 +000087 case 0x10000:
88 return "WARM BOOT";
Adrian Alonso9f883e02015-09-02 13:54:23 -050089#endif
Jason Liu83aa8fe2011-11-25 00:18:01 +000090 default:
91 return "unknown reset";
92 }
93}
Prabhakar Kushwahaf2c19de2015-05-18 17:13:52 +053094#endif
Eric Nelson25e02302015-02-15 14:37:21 -070095
Anatolij Gustschin03dd9862017-08-28 21:46:26 +020096#if defined(CONFIG_DISPLAY_CPUINFO) && !defined(CONFIG_SPL_BUILD)
Fabio Estevam46e97332012-03-20 04:21:45 +000097
Troy Kisky58394932012-10-23 10:57:46 +000098const char *get_imx_type(u32 imxtype)
Fabio Estevam46e97332012-03-20 04:21:45 +000099{
100 switch (imxtype) {
Peng Fan69cec072019-12-27 10:14:02 +0800101 case MXC_CPU_IMX8MP:
Ye Lid2d754f2020-04-20 20:12:54 -0700102 return "8MP[8]"; /* Quad-core version of the imx8mp */
103 case MXC_CPU_IMX8MPD:
104 return "8MP Dual[3]"; /* Dual-core version of the imx8mp */
105 case MXC_CPU_IMX8MPL:
106 return "8MP Lite[4]"; /* Quad-core Lite version of the imx8mp */
Ye Lid2d754f2020-04-20 20:12:54 -0700107 case MXC_CPU_IMX8MP6:
108 return "8MP[6]"; /* Quad-core version of the imx8mp, NPU fused */
Peng Fan5d2f2062019-06-27 17:23:49 +0800109 case MXC_CPU_IMX8MN:
Peng Fan1a07d912020-02-05 17:39:27 +0800110 return "8MNano Quad"; /* Quad-core version */
111 case MXC_CPU_IMX8MND:
112 return "8MNano Dual"; /* Dual-core version */
113 case MXC_CPU_IMX8MNS:
114 return "8MNano Solo"; /* Single-core version */
115 case MXC_CPU_IMX8MNL:
116 return "8MNano QuadLite"; /* Quad-core Lite version */
117 case MXC_CPU_IMX8MNDL:
118 return "8MNano DualLite"; /* Dual-core Lite version */
119 case MXC_CPU_IMX8MNSL:
120 return "8MNano SoloLite"; /* Single-core Lite version */
Peng Fan2d22a992019-08-27 06:25:04 +0000121 case MXC_CPU_IMX8MM:
122 return "8MMQ"; /* Quad-core version of the imx8mm */
123 case MXC_CPU_IMX8MML:
124 return "8MMQL"; /* Quad-core Lite version of the imx8mm */
125 case MXC_CPU_IMX8MMD:
126 return "8MMD"; /* Dual-core version of the imx8mm */
127 case MXC_CPU_IMX8MMDL:
128 return "8MMDL"; /* Dual-core Lite version of the imx8mm */
129 case MXC_CPU_IMX8MMS:
130 return "8MMS"; /* Single-core version of the imx8mm */
131 case MXC_CPU_IMX8MMSL:
132 return "8MMSL"; /* Single-core Lite version of the imx8mm */
Peng Fan39945c12018-11-20 10:19:25 +0000133 case MXC_CPU_IMX8MQ:
Peng Fan67815082020-02-05 17:34:54 +0800134 return "8MQ"; /* Quad-core version of the imx8mq */
135 case MXC_CPU_IMX8MQL:
136 return "8MQLite"; /* Quad-core Lite version of the imx8mq */
137 case MXC_CPU_IMX8MD:
138 return "8MD"; /* Dual-core version of the imx8mq */
Fabio Estevamf6ced1b2016-02-28 12:33:17 -0300139 case MXC_CPU_MX7S:
Stefan Agnerf19a8e42016-05-06 11:21:50 -0700140 return "7S"; /* Single-core version of the mx7 */
Adrian Alonso9f883e02015-09-02 13:54:23 -0500141 case MXC_CPU_MX7D:
142 return "7D"; /* Dual-core version of the mx7 */
Peng Fan5f247922015-07-11 11:38:42 +0800143 case MXC_CPU_MX6QP:
144 return "6QP"; /* Quad-Plus version of the mx6 */
145 case MXC_CPU_MX6DP:
146 return "6DP"; /* Dual-Plus version of the mx6 */
Troy Kisky58394932012-10-23 10:57:46 +0000147 case MXC_CPU_MX6Q:
Fabio Estevam46e97332012-03-20 04:21:45 +0000148 return "6Q"; /* Quad-core version of the mx6 */
Fabio Estevamf3d5a2c2014-01-26 15:06:41 -0200149 case MXC_CPU_MX6D:
150 return "6D"; /* Dual-core version of the mx6 */
Troy Kisky58394932012-10-23 10:57:46 +0000151 case MXC_CPU_MX6DL:
152 return "6DL"; /* Dual Lite version of the mx6 */
153 case MXC_CPU_MX6SOLO:
154 return "6SOLO"; /* Solo version of the mx6 */
155 case MXC_CPU_MX6SL:
Fabio Estevam46e97332012-03-20 04:21:45 +0000156 return "6SL"; /* Solo-Lite version of the mx6 */
Peng Fan4cfd7972016-12-11 19:24:20 +0800157 case MXC_CPU_MX6SLL:
158 return "6SLL"; /* SLL version of the mx6 */
Fabio Estevam712ab882014-06-24 17:40:58 -0300159 case MXC_CPU_MX6SX:
160 return "6SX"; /* SoloX version of the mx6 */
Peng Faneaa53a12015-07-20 19:28:21 +0800161 case MXC_CPU_MX6UL:
162 return "6UL"; /* Ultra-Lite version of the mx6 */
Peng Fan3b33e3f2016-08-11 14:02:38 +0800163 case MXC_CPU_MX6ULL:
164 return "6ULL"; /* ULL version of the mx6 */
Peng Fanc53d0c92019-08-08 09:55:52 +0000165 case MXC_CPU_MX6ULZ:
166 return "6ULZ"; /* ULZ version of the mx6 */
Troy Kisky58394932012-10-23 10:57:46 +0000167 case MXC_CPU_MX51:
Fabio Estevam46e97332012-03-20 04:21:45 +0000168 return "51";
Troy Kisky58394932012-10-23 10:57:46 +0000169 case MXC_CPU_MX53:
Fabio Estevam46e97332012-03-20 04:21:45 +0000170 return "53";
171 default:
Otavio Salvador8567d7d2012-06-30 05:07:32 +0000172 return "??";
Fabio Estevam46e97332012-03-20 04:21:45 +0000173 }
174}
175
Jason Liu83aa8fe2011-11-25 00:18:01 +0000176int print_cpuinfo(void)
177{
Stefano Babic40adacc2015-05-26 19:53:41 +0200178 u32 cpurev;
179 __maybe_unused u32 max_freq;
Jason Liu83aa8fe2011-11-25 00:18:01 +0000180
Adrian Alonsoce08c362015-09-02 13:54:13 -0500181 cpurev = get_cpu_rev();
182
Peng Fan0df2e032020-05-03 22:19:57 +0800183#if defined(CONFIG_IMX_THERMAL) || defined(CONFIG_IMX_TMU)
Ye.Lif19692c2014-11-20 21:14:14 +0800184 struct udevice *thermal_dev;
Tim Harvey27f90592015-05-18 06:56:46 -0700185 int cpu_tmp, minc, maxc, ret;
Ye.Lif19692c2014-11-20 21:14:14 +0800186
Tim Harveyd792ede2015-05-18 07:02:25 -0700187 printf("CPU: Freescale i.MX%s rev%d.%d",
Peng Fan41b517212019-12-30 17:57:10 +0800188 get_imx_type((cpurev & 0x1FF000) >> 12),
Tim Harveyd792ede2015-05-18 07:02:25 -0700189 (cpurev & 0x000F0) >> 4,
190 (cpurev & 0x0000F) >> 0);
191 max_freq = get_cpu_speed_grade_hz();
192 if (!max_freq || max_freq == mxc_get_clock(MXC_ARM_CLK)) {
193 printf(" at %dMHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
194 } else {
195 printf(" %d MHz (running at %d MHz)\n", max_freq / 1000000,
196 mxc_get_clock(MXC_ARM_CLK) / 1000000);
197 }
198#else
Fabio Estevam46e97332012-03-20 04:21:45 +0000199 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
Peng Fan41b517212019-12-30 17:57:10 +0800200 get_imx_type((cpurev & 0x1FF000) >> 12),
Jason Liu83aa8fe2011-11-25 00:18:01 +0000201 (cpurev & 0x000F0) >> 4,
202 (cpurev & 0x0000F) >> 0,
203 mxc_get_clock(MXC_ARM_CLK) / 1000000);
Tim Harveyd792ede2015-05-18 07:02:25 -0700204#endif
Ye.Lif19692c2014-11-20 21:14:14 +0800205
Peng Fan0df2e032020-05-03 22:19:57 +0800206#if defined(CONFIG_IMX_THERMAL) || defined(CONFIG_IMX_TMU)
Tim Harvey27f90592015-05-18 06:56:46 -0700207 puts("CPU: ");
208 switch (get_cpu_temp_grade(&minc, &maxc)) {
209 case TEMP_AUTOMOTIVE:
210 puts("Automotive temperature grade ");
211 break;
212 case TEMP_INDUSTRIAL:
213 puts("Industrial temperature grade ");
214 break;
215 case TEMP_EXTCOMMERCIAL:
216 puts("Extended Commercial temperature grade ");
217 break;
218 default:
219 puts("Commercial temperature grade ");
220 break;
221 }
222 printf("(%dC to %dC)", minc, maxc);
Ye.Lif19692c2014-11-20 21:14:14 +0800223 ret = uclass_get_device(UCLASS_THERMAL, 0, &thermal_dev);
224 if (!ret) {
225 ret = thermal_get_temp(thermal_dev, &cpu_tmp);
226
227 if (!ret)
Tim Harveycea7d882020-10-12 12:26:41 -0700228 printf(" at %dC", cpu_tmp);
Ye.Lif19692c2014-11-20 21:14:14 +0800229 else
Fabio Estevamf62604d2015-09-08 14:43:10 -0300230 debug(" - invalid sensor data\n");
Ye.Lif19692c2014-11-20 21:14:14 +0800231 } else {
Fabio Estevamf62604d2015-09-08 14:43:10 -0300232 debug(" - invalid sensor device\n");
Ye.Lif19692c2014-11-20 21:14:14 +0800233 }
Tim Harveycea7d882020-10-12 12:26:41 -0700234 puts("\n");
Ye.Lif19692c2014-11-20 21:14:14 +0800235#endif
236
Jason Liu83aa8fe2011-11-25 00:18:01 +0000237 printf("Reset cause: %s\n", get_reset_cause());
238 return 0;
239}
240#endif
241
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900242int cpu_eth_init(struct bd_info *bis)
Jason Liu83aa8fe2011-11-25 00:18:01 +0000243{
244 int rc = -ENODEV;
245
246#if defined(CONFIG_FEC_MXC)
247 rc = fecmxc_initialize(bis);
248#endif
249
250 return rc;
251}
252
Yangbo Lu73340382019-06-21 11:42:28 +0800253#ifdef CONFIG_FSL_ESDHC_IMX
Jason Liu83aa8fe2011-11-25 00:18:01 +0000254/*
255 * Initializes on-chip MMC controllers.
256 * to override, implement board_mmc_init()
257 */
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900258int cpu_mmc_init(struct bd_info *bis)
Jason Liu83aa8fe2011-11-25 00:18:01 +0000259{
Jason Liu83aa8fe2011-11-25 00:18:01 +0000260 return fsl_esdhc_mmc_init(bis);
Jason Liu83aa8fe2011-11-25 00:18:01 +0000261}
Benoît Thébaudeau58d22322012-08-17 10:42:55 +0000262#endif
Jason Liu83aa8fe2011-11-25 00:18:01 +0000263
Peng Fan39945c12018-11-20 10:19:25 +0000264#if !(defined(CONFIG_MX7) || defined(CONFIG_IMX8M))
Fabio Estevam6479f512012-04-29 08:11:13 +0000265u32 get_ahb_clk(void)
266{
267 struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
268 u32 reg, ahb_podf;
269
270 reg = __raw_readl(&imx_ccm->cbcdr);
271 reg &= MXC_CCM_CBCDR_AHB_PODF_MASK;
272 ahb_podf = reg >> MXC_CCM_CBCDR_AHB_PODF_OFFSET;
273
274 return get_periph_clk() / (ahb_podf + 1);
275}
Adrian Alonso9f883e02015-09-02 13:54:23 -0500276#endif
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000277
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000278void arch_preboot_os(void)
279{
Marek Vasut81647a32019-06-09 03:50:51 +0200280#if defined(CONFIG_PCIE_IMX) && !CONFIG_IS_ENABLED(DM_PCI)
Tim Harveyc22f2ea2017-05-12 12:58:41 -0700281 imx_pcie_remove();
282#endif
Ye Li3525e3c2019-07-22 20:51:25 -0700283
284#if defined(CONFIG_IMX_AHCI)
285 struct udevice *dev;
286 int rc;
287
288 rc = uclass_find_device(UCLASS_AHCI, 0, &dev);
289 if (!rc && dev) {
290 rc = device_remove(dev, DM_REMOVE_NORMAL);
291 if (rc)
292 printf("Cannot remove SATA device '%s' (err=%d)\n",
293 dev->name, rc);
294 }
295#endif
296
Simon Glassab3055a2017-06-14 21:28:25 -0600297#if defined(CONFIG_SATA)
Ludwig Zenzeb15ce22019-07-02 15:10:52 +0200298 if (!is_mx6sdl()) {
299 sata_remove(0);
Soeren Mocha517d022014-11-27 10:11:41 +0100300#if defined(CONFIG_MX6)
Ludwig Zenzeb15ce22019-07-02 15:10:52 +0200301 disable_sata_clock();
Soeren Mocha517d022014-11-27 10:11:41 +0100302#endif
Ludwig Zenzeb15ce22019-07-02 15:10:52 +0200303 }
Nikita Kiryanovb5c9ed32014-11-21 12:47:26 +0200304#endif
305#if defined(CONFIG_VIDEO_IPUV3)
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000306 /* disable video before launching O/S */
307 ipuv3_fb_shutdown();
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000308#endif
Igor Opaniukf5abe402019-06-04 00:05:59 +0300309#if defined(CONFIG_VIDEO_MXS) && !defined(CONFIG_DM_VIDEO)
Peng Fanf2c39922015-10-29 15:54:51 +0800310 lcdif_power_down();
311#endif
Nikita Kiryanovb5c9ed32014-11-21 12:47:26 +0200312}
Fabio Estevam16e65f62014-11-14 11:27:21 -0200313
Peng Fan39945c12018-11-20 10:19:25 +0000314#ifndef CONFIG_IMX8M
Fabio Estevam16e65f62014-11-14 11:27:21 -0200315void set_chipselect_size(int const cs_size)
316{
317 unsigned int reg;
318 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
319 reg = readl(&iomuxc_regs->gpr[1]);
320
321 switch (cs_size) {
322 case CS0_128:
323 reg &= ~0x7; /* CS0=128MB, CS1=0, CS2=0, CS3=0 */
324 reg |= 0x5;
325 break;
326 case CS0_64M_CS1_64M:
327 reg &= ~0x3F; /* CS0=64MB, CS1=64MB, CS2=0, CS3=0 */
328 reg |= 0x1B;
329 break;
330 case CS0_64M_CS1_32M_CS2_32M:
331 reg &= ~0x1FF; /* CS0=64MB, CS1=32MB, CS2=32MB, CS3=0 */
332 reg |= 0x4B;
333 break;
334 case CS0_32M_CS1_32M_CS2_32M_CS3_32M:
335 reg &= ~0xFFF; /* CS0=32MB, CS1=32MB, CS2=32MB, CS3=32MB */
336 reg |= 0x249;
337 break;
338 default:
339 printf("Unknown chip select size: %d\n", cs_size);
340 break;
341 }
342
343 writel(reg, &iomuxc_regs->gpr[1]);
344}
Peng Fana78e0ac2018-01-10 13:20:25 +0800345#endif
Fabio Estevam49bcdd72017-11-27 10:25:09 -0200346
Peng Fan39945c12018-11-20 10:19:25 +0000347#if defined(CONFIG_MX7) || defined(CONFIG_IMX8M)
Peng Fan7753bc72018-01-10 13:20:29 +0800348/*
349 * OCOTP_TESTER3[9:8] (see Fusemap Description Table offset 0x440)
350 * defines a 2-bit SPEED_GRADING
351 */
352#define OCOTP_TESTER3_SPEED_SHIFT 8
Peng Fana12bf3c2018-01-10 13:20:30 +0800353enum cpu_speed {
354 OCOTP_TESTER3_SPEED_GRADE0,
355 OCOTP_TESTER3_SPEED_GRADE1,
356 OCOTP_TESTER3_SPEED_GRADE2,
357 OCOTP_TESTER3_SPEED_GRADE3,
Peng Fan6a5f9c92018-12-12 02:47:58 -0800358 OCOTP_TESTER3_SPEED_GRADE4,
Peng Fana12bf3c2018-01-10 13:20:30 +0800359};
Peng Fan7753bc72018-01-10 13:20:29 +0800360
361u32 get_cpu_speed_grade_hz(void)
362{
363 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
364 struct fuse_bank *bank = &ocotp->bank[1];
365 struct fuse_bank1_regs *fuse =
366 (struct fuse_bank1_regs *)bank->fuse_regs;
367 uint32_t val;
368
369 val = readl(&fuse->tester3);
370 val >>= OCOTP_TESTER3_SPEED_SHIFT;
Peng Fan6a5f9c92018-12-12 02:47:58 -0800371
Peng Fan0599e5e2020-01-17 16:11:29 +0800372 if (is_imx8mn() || is_imx8mp()) {
Peng Fan6a5f9c92018-12-12 02:47:58 -0800373 val &= 0xf;
374 return 2300000000 - val * 100000000;
375 }
376
377 if (is_imx8mm())
378 val &= 0x7;
379 else
380 val &= 0x3;
Peng Fan7753bc72018-01-10 13:20:29 +0800381
382 switch(val) {
Peng Fana12bf3c2018-01-10 13:20:30 +0800383 case OCOTP_TESTER3_SPEED_GRADE0:
Peng Fan7753bc72018-01-10 13:20:29 +0800384 return 800000000;
Peng Fana12bf3c2018-01-10 13:20:30 +0800385 case OCOTP_TESTER3_SPEED_GRADE1:
Ye Lic9c1f9c2018-10-16 23:12:37 -0700386 return (is_mx7() ? 500000000 : (is_imx8mq() ? 1000000000 : 1200000000));
Peng Fana12bf3c2018-01-10 13:20:30 +0800387 case OCOTP_TESTER3_SPEED_GRADE2:
Ye Lic9c1f9c2018-10-16 23:12:37 -0700388 return (is_mx7() ? 1000000000 : (is_imx8mq() ? 1300000000 : 1600000000));
Peng Fana12bf3c2018-01-10 13:20:30 +0800389 case OCOTP_TESTER3_SPEED_GRADE3:
Ye Lic9c1f9c2018-10-16 23:12:37 -0700390 return (is_mx7() ? 1200000000 : (is_imx8mq() ? 1500000000 : 1800000000));
Peng Fan6a5f9c92018-12-12 02:47:58 -0800391 case OCOTP_TESTER3_SPEED_GRADE4:
392 return 2000000000;
Peng Fan7753bc72018-01-10 13:20:29 +0800393 }
Peng Fana12bf3c2018-01-10 13:20:30 +0800394
Peng Fan7753bc72018-01-10 13:20:29 +0800395 return 0;
396}
397
398/*
399 * OCOTP_TESTER3[7:6] (see Fusemap Description Table offset 0x440)
400 * defines a 2-bit SPEED_GRADING
401 */
402#define OCOTP_TESTER3_TEMP_SHIFT 6
403
Ye Lia31f1962020-03-09 23:11:54 -0700404/* iMX8MP uses OCOTP_TESTER3[6:5] for Market segment */
405#define IMX8MP_OCOTP_TESTER3_TEMP_SHIFT 5
406
Peng Fan7753bc72018-01-10 13:20:29 +0800407u32 get_cpu_temp_grade(int *minc, int *maxc)
408{
409 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
410 struct fuse_bank *bank = &ocotp->bank[1];
411 struct fuse_bank1_regs *fuse =
412 (struct fuse_bank1_regs *)bank->fuse_regs;
413 uint32_t val;
414
415 val = readl(&fuse->tester3);
Ye Lia31f1962020-03-09 23:11:54 -0700416 if (is_imx8mp())
417 val >>= IMX8MP_OCOTP_TESTER3_TEMP_SHIFT;
418 else
419 val >>= OCOTP_TESTER3_TEMP_SHIFT;
Peng Fan7753bc72018-01-10 13:20:29 +0800420 val &= 0x3;
421
422 if (minc && maxc) {
423 if (val == TEMP_AUTOMOTIVE) {
424 *minc = -40;
425 *maxc = 125;
426 } else if (val == TEMP_INDUSTRIAL) {
427 *minc = -40;
428 *maxc = 105;
429 } else if (val == TEMP_EXTCOMMERCIAL) {
430 *minc = -20;
431 *maxc = 105;
432 } else {
433 *minc = 0;
434 *maxc = 95;
435 }
436 }
437 return val;
438}
439#endif
440
Peng Fan88c41fd2019-09-16 03:09:34 +0000441#if defined(CONFIG_MX7) || defined(CONFIG_IMX8MQ) || defined(CONFIG_IMX8MM)
Peng Fand64a3c52018-01-10 13:20:34 +0800442enum boot_device get_boot_device(void)
443{
444 struct bootrom_sw_info **p =
445 (struct bootrom_sw_info **)(ulong)ROM_SW_INFO_ADDR;
446
447 enum boot_device boot_dev = SD1_BOOT;
448 u8 boot_type = (*p)->boot_dev_type;
449 u8 boot_instance = (*p)->boot_dev_instance;
450
451 switch (boot_type) {
452 case BOOT_TYPE_SD:
453 boot_dev = boot_instance + SD1_BOOT;
454 break;
455 case BOOT_TYPE_MMC:
456 boot_dev = boot_instance + MMC1_BOOT;
457 break;
458 case BOOT_TYPE_NAND:
459 boot_dev = NAND_BOOT;
460 break;
461 case BOOT_TYPE_QSPI:
462 boot_dev = QSPI_BOOT;
463 break;
464 case BOOT_TYPE_WEIM:
465 boot_dev = WEIM_NOR_BOOT;
466 break;
467 case BOOT_TYPE_SPINOR:
468 boot_dev = SPI_NOR_BOOT;
469 break;
Peng Fan24d3fbc2018-01-10 13:20:35 +0800470 case BOOT_TYPE_USB:
471 boot_dev = USB_BOOT;
472 break;
Peng Fand64a3c52018-01-10 13:20:34 +0800473 default:
Peng Fan037f91c2018-05-17 15:15:59 +0800474#ifdef CONFIG_IMX8M
475 if (((readl(SRC_BASE_ADDR + 0x58) & 0x00007FFF) >> 12) == 0x4)
476 boot_dev = QSPI_BOOT;
477#endif
Peng Fand64a3c52018-01-10 13:20:34 +0800478 break;
479 }
480
481 return boot_dev;
482}
483#endif
484
Fabio Estevam49bcdd72017-11-27 10:25:09 -0200485#ifdef CONFIG_NXP_BOARD_REVISION
486int nxp_board_rev(void)
487{
488 /*
489 * Get Board ID information from OCOTP_GP1[15:8]
490 * RevA: 0x1
491 * RevB: 0x2
492 * RevC: 0x3
493 */
494 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
495 struct fuse_bank *bank = &ocotp->bank[4];
496 struct fuse_bank4_regs *fuse =
497 (struct fuse_bank4_regs *)bank->fuse_regs;
498
499 return (readl(&fuse->gp1) >> 8 & 0x0F);
500}
501
502char nxp_board_rev_string(void)
503{
504 const char *rev = "A";
505
506 return (*rev + nxp_board_rev() - 1);
507}
508#endif