blob: ceee31eecd7923a0b31c43e25ffb56fc24b5972e [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>
Simon Glassea8c0432020-07-19 10:15:41 -060010#include <dm.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>
Ye Li3525e3c2019-07-22 20:51:25 -070026#include <dm/device-internal.h>
27#include <dm/uclass-internal.h>
Jason Liu83aa8fe2011-11-25 00:18:01 +000028
Yangbo Lu73340382019-06-21 11:42:28 +080029#ifdef CONFIG_FSL_ESDHC_IMX
30#include <fsl_esdhc_imx.h>
Jason Liu83aa8fe2011-11-25 00:18:01 +000031#endif
32
Eric Nelson25e02302015-02-15 14:37:21 -070033static u32 reset_cause = -1;
34
Max Krummenachercb2c8fd2019-02-01 16:04:51 +010035u32 get_imx_reset_cause(void)
Jason Liu83aa8fe2011-11-25 00:18:01 +000036{
Jason Liu83aa8fe2011-11-25 00:18:01 +000037 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
38
Max Krummenachercb2c8fd2019-02-01 16:04:51 +010039 if (reset_cause == -1) {
40 reset_cause = readl(&src_regs->srsr);
41/* preserve the value for U-Boot proper */
42#if !defined(CONFIG_SPL_BUILD)
43 writel(reset_cause, &src_regs->srsr);
44#endif
45 }
46
47 return reset_cause;
48}
Jason Liu83aa8fe2011-11-25 00:18:01 +000049
Max Krummenachercb2c8fd2019-02-01 16:04:51 +010050#if defined(CONFIG_DISPLAY_CPUINFO) && !defined(CONFIG_SPL_BUILD)
51static char *get_reset_cause(void)
52{
53 switch (get_imx_reset_cause()) {
Jason Liu83aa8fe2011-11-25 00:18:01 +000054 case 0x00001:
Fabio Estevam9af122b2012-03-13 07:26:48 +000055 case 0x00011:
Jason Liu83aa8fe2011-11-25 00:18:01 +000056 return "POR";
57 case 0x00004:
58 return "CSU";
59 case 0x00008:
60 return "IPP USER";
61 case 0x00010:
Adrian Alonso9f883e02015-09-02 13:54:23 -050062#ifdef CONFIG_MX7
63 return "WDOG1";
64#else
Jason Liu83aa8fe2011-11-25 00:18:01 +000065 return "WDOG";
Adrian Alonso9f883e02015-09-02 13:54:23 -050066#endif
Jason Liu83aa8fe2011-11-25 00:18:01 +000067 case 0x00020:
68 return "JTAG HIGH-Z";
69 case 0x00040:
70 return "JTAG SW";
Adrian Alonso9f883e02015-09-02 13:54:23 -050071 case 0x00080:
72 return "WDOG3";
73#ifdef CONFIG_MX7
74 case 0x00100:
75 return "WDOG4";
76 case 0x00200:
77 return "TEMPSENSE";
Peng Fan39945c12018-11-20 10:19:25 +000078#elif defined(CONFIG_IMX8M)
Peng Fana78e0ac2018-01-10 13:20:25 +080079 case 0x00100:
80 return "WDOG2";
81 case 0x00200:
82 return "TEMPSENSE";
Adrian Alonso9f883e02015-09-02 13:54:23 -050083#else
84 case 0x00100:
85 return "TEMPSENSE";
Jason Liu83aa8fe2011-11-25 00:18:01 +000086 case 0x10000:
87 return "WARM BOOT";
Adrian Alonso9f883e02015-09-02 13:54:23 -050088#endif
Jason Liu83aa8fe2011-11-25 00:18:01 +000089 default:
90 return "unknown reset";
91 }
92}
Prabhakar Kushwahaf2c19de2015-05-18 17:13:52 +053093#endif
Eric Nelson25e02302015-02-15 14:37:21 -070094
Anatolij Gustschin03dd9862017-08-28 21:46:26 +020095#if defined(CONFIG_DISPLAY_CPUINFO) && !defined(CONFIG_SPL_BUILD)
Fabio Estevam46e97332012-03-20 04:21:45 +000096
Troy Kisky58394932012-10-23 10:57:46 +000097const char *get_imx_type(u32 imxtype)
Fabio Estevam46e97332012-03-20 04:21:45 +000098{
99 switch (imxtype) {
Peng Fan69cec072019-12-27 10:14:02 +0800100 case MXC_CPU_IMX8MP:
Ye Lid2d754f2020-04-20 20:12:54 -0700101 return "8MP[8]"; /* Quad-core version of the imx8mp */
102 case MXC_CPU_IMX8MPD:
103 return "8MP Dual[3]"; /* Dual-core version of the imx8mp */
104 case MXC_CPU_IMX8MPL:
105 return "8MP Lite[4]"; /* Quad-core Lite version of the imx8mp */
Ye Lid2d754f2020-04-20 20:12:54 -0700106 case MXC_CPU_IMX8MP6:
107 return "8MP[6]"; /* Quad-core version of the imx8mp, NPU fused */
Peng Fan4d54f5b2022-04-07 15:55:51 +0800108 case MXC_CPU_IMX8MPUL:
109 return "8MP UltraLite"; /* Quad-core UltraLite version of the imx8mp */
Peng Fan5d2f2062019-06-27 17:23:49 +0800110 case MXC_CPU_IMX8MN:
Peng Fan1a07d912020-02-05 17:39:27 +0800111 return "8MNano Quad"; /* Quad-core version */
112 case MXC_CPU_IMX8MND:
113 return "8MNano Dual"; /* Dual-core version */
114 case MXC_CPU_IMX8MNS:
115 return "8MNano Solo"; /* Single-core version */
116 case MXC_CPU_IMX8MNL:
117 return "8MNano QuadLite"; /* Quad-core Lite version */
118 case MXC_CPU_IMX8MNDL:
119 return "8MNano DualLite"; /* Dual-core Lite version */
120 case MXC_CPU_IMX8MNSL:
Ye Li715180e2021-03-19 15:57:11 +0800121 return "8MNano SoloLite";/* Single-core Lite version of the imx8mn */
122 case MXC_CPU_IMX8MNUQ:
123 return "8MNano UltraLite Quad";/* Quad-core UltraLite version of the imx8mn */
124 case MXC_CPU_IMX8MNUD:
125 return "8MNano UltraLite Dual";/* Dual-core UltraLite version of the imx8mn */
126 case MXC_CPU_IMX8MNUS:
127 return "8MNano UltraLite Solo";/* Single-core UltraLite version of the imx8mn */
Peng Fan2d22a992019-08-27 06:25:04 +0000128 case MXC_CPU_IMX8MM:
129 return "8MMQ"; /* Quad-core version of the imx8mm */
130 case MXC_CPU_IMX8MML:
131 return "8MMQL"; /* Quad-core Lite version of the imx8mm */
132 case MXC_CPU_IMX8MMD:
133 return "8MMD"; /* Dual-core version of the imx8mm */
134 case MXC_CPU_IMX8MMDL:
135 return "8MMDL"; /* Dual-core Lite version of the imx8mm */
136 case MXC_CPU_IMX8MMS:
137 return "8MMS"; /* Single-core version of the imx8mm */
138 case MXC_CPU_IMX8MMSL:
139 return "8MMSL"; /* Single-core Lite version of the imx8mm */
Peng Fan39945c12018-11-20 10:19:25 +0000140 case MXC_CPU_IMX8MQ:
Peng Fan67815082020-02-05 17:34:54 +0800141 return "8MQ"; /* Quad-core version of the imx8mq */
142 case MXC_CPU_IMX8MQL:
143 return "8MQLite"; /* Quad-core Lite version of the imx8mq */
144 case MXC_CPU_IMX8MD:
145 return "8MD"; /* Dual-core version of the imx8mq */
Fabio Estevamf6ced1b2016-02-28 12:33:17 -0300146 case MXC_CPU_MX7S:
Stefan Agnerf19a8e42016-05-06 11:21:50 -0700147 return "7S"; /* Single-core version of the mx7 */
Adrian Alonso9f883e02015-09-02 13:54:23 -0500148 case MXC_CPU_MX7D:
149 return "7D"; /* Dual-core version of the mx7 */
Peng Fan5f247922015-07-11 11:38:42 +0800150 case MXC_CPU_MX6QP:
151 return "6QP"; /* Quad-Plus version of the mx6 */
152 case MXC_CPU_MX6DP:
153 return "6DP"; /* Dual-Plus version of the mx6 */
Troy Kisky58394932012-10-23 10:57:46 +0000154 case MXC_CPU_MX6Q:
Fabio Estevam46e97332012-03-20 04:21:45 +0000155 return "6Q"; /* Quad-core version of the mx6 */
Fabio Estevamf3d5a2c2014-01-26 15:06:41 -0200156 case MXC_CPU_MX6D:
157 return "6D"; /* Dual-core version of the mx6 */
Troy Kisky58394932012-10-23 10:57:46 +0000158 case MXC_CPU_MX6DL:
159 return "6DL"; /* Dual Lite version of the mx6 */
160 case MXC_CPU_MX6SOLO:
161 return "6SOLO"; /* Solo version of the mx6 */
162 case MXC_CPU_MX6SL:
Fabio Estevam46e97332012-03-20 04:21:45 +0000163 return "6SL"; /* Solo-Lite version of the mx6 */
Peng Fan4cfd7972016-12-11 19:24:20 +0800164 case MXC_CPU_MX6SLL:
165 return "6SLL"; /* SLL version of the mx6 */
Fabio Estevam712ab882014-06-24 17:40:58 -0300166 case MXC_CPU_MX6SX:
167 return "6SX"; /* SoloX version of the mx6 */
Peng Faneaa53a12015-07-20 19:28:21 +0800168 case MXC_CPU_MX6UL:
169 return "6UL"; /* Ultra-Lite version of the mx6 */
Peng Fan3b33e3f2016-08-11 14:02:38 +0800170 case MXC_CPU_MX6ULL:
171 return "6ULL"; /* ULL version of the mx6 */
Peng Fanc53d0c92019-08-08 09:55:52 +0000172 case MXC_CPU_MX6ULZ:
173 return "6ULZ"; /* ULZ version of the mx6 */
Troy Kisky58394932012-10-23 10:57:46 +0000174 case MXC_CPU_MX51:
Fabio Estevam46e97332012-03-20 04:21:45 +0000175 return "51";
Troy Kisky58394932012-10-23 10:57:46 +0000176 case MXC_CPU_MX53:
Fabio Estevam46e97332012-03-20 04:21:45 +0000177 return "53";
178 default:
Otavio Salvador8567d7d2012-06-30 05:07:32 +0000179 return "??";
Fabio Estevam46e97332012-03-20 04:21:45 +0000180 }
181}
182
Jason Liu83aa8fe2011-11-25 00:18:01 +0000183int print_cpuinfo(void)
184{
Stefano Babic40adacc2015-05-26 19:53:41 +0200185 u32 cpurev;
186 __maybe_unused u32 max_freq;
Jason Liu83aa8fe2011-11-25 00:18:01 +0000187
Adrian Alonsoce08c362015-09-02 13:54:13 -0500188 cpurev = get_cpu_rev();
189
Peng Fan0df2e032020-05-03 22:19:57 +0800190#if defined(CONFIG_IMX_THERMAL) || defined(CONFIG_IMX_TMU)
Ye.Lif19692c2014-11-20 21:14:14 +0800191 struct udevice *thermal_dev;
Tim Harvey27f90592015-05-18 06:56:46 -0700192 int cpu_tmp, minc, maxc, ret;
Ye.Lif19692c2014-11-20 21:14:14 +0800193
Tim Harveyd792ede2015-05-18 07:02:25 -0700194 printf("CPU: Freescale i.MX%s rev%d.%d",
Peng Fan41b517212019-12-30 17:57:10 +0800195 get_imx_type((cpurev & 0x1FF000) >> 12),
Tim Harveyd792ede2015-05-18 07:02:25 -0700196 (cpurev & 0x000F0) >> 4,
197 (cpurev & 0x0000F) >> 0);
198 max_freq = get_cpu_speed_grade_hz();
199 if (!max_freq || max_freq == mxc_get_clock(MXC_ARM_CLK)) {
200 printf(" at %dMHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
201 } else {
202 printf(" %d MHz (running at %d MHz)\n", max_freq / 1000000,
203 mxc_get_clock(MXC_ARM_CLK) / 1000000);
204 }
205#else
Fabio Estevam46e97332012-03-20 04:21:45 +0000206 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
Peng Fan41b517212019-12-30 17:57:10 +0800207 get_imx_type((cpurev & 0x1FF000) >> 12),
Jason Liu83aa8fe2011-11-25 00:18:01 +0000208 (cpurev & 0x000F0) >> 4,
209 (cpurev & 0x0000F) >> 0,
210 mxc_get_clock(MXC_ARM_CLK) / 1000000);
Tim Harveyd792ede2015-05-18 07:02:25 -0700211#endif
Ye.Lif19692c2014-11-20 21:14:14 +0800212
Peng Fan0df2e032020-05-03 22:19:57 +0800213#if defined(CONFIG_IMX_THERMAL) || defined(CONFIG_IMX_TMU)
Tim Harvey27f90592015-05-18 06:56:46 -0700214 puts("CPU: ");
215 switch (get_cpu_temp_grade(&minc, &maxc)) {
216 case TEMP_AUTOMOTIVE:
217 puts("Automotive temperature grade ");
218 break;
219 case TEMP_INDUSTRIAL:
220 puts("Industrial temperature grade ");
221 break;
222 case TEMP_EXTCOMMERCIAL:
223 puts("Extended Commercial temperature grade ");
224 break;
225 default:
226 puts("Commercial temperature grade ");
227 break;
228 }
229 printf("(%dC to %dC)", minc, maxc);
Ye.Lif19692c2014-11-20 21:14:14 +0800230 ret = uclass_get_device(UCLASS_THERMAL, 0, &thermal_dev);
231 if (!ret) {
232 ret = thermal_get_temp(thermal_dev, &cpu_tmp);
233
234 if (!ret)
Tim Harveycea7d882020-10-12 12:26:41 -0700235 printf(" at %dC", cpu_tmp);
Ye.Lif19692c2014-11-20 21:14:14 +0800236 else
Fabio Estevamf62604d2015-09-08 14:43:10 -0300237 debug(" - invalid sensor data\n");
Ye.Lif19692c2014-11-20 21:14:14 +0800238 } else {
Fabio Estevamf62604d2015-09-08 14:43:10 -0300239 debug(" - invalid sensor device\n");
Ye.Lif19692c2014-11-20 21:14:14 +0800240 }
Tim Harveycea7d882020-10-12 12:26:41 -0700241 puts("\n");
Ye.Lif19692c2014-11-20 21:14:14 +0800242#endif
243
Jason Liu83aa8fe2011-11-25 00:18:01 +0000244 printf("Reset cause: %s\n", get_reset_cause());
245 return 0;
246}
247#endif
248
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900249int cpu_eth_init(struct bd_info *bis)
Jason Liu83aa8fe2011-11-25 00:18:01 +0000250{
251 int rc = -ENODEV;
252
253#if defined(CONFIG_FEC_MXC)
254 rc = fecmxc_initialize(bis);
255#endif
256
257 return rc;
258}
259
Yangbo Lu73340382019-06-21 11:42:28 +0800260#ifdef CONFIG_FSL_ESDHC_IMX
Jason Liu83aa8fe2011-11-25 00:18:01 +0000261/*
262 * Initializes on-chip MMC controllers.
263 * to override, implement board_mmc_init()
264 */
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900265int cpu_mmc_init(struct bd_info *bis)
Jason Liu83aa8fe2011-11-25 00:18:01 +0000266{
Jason Liu83aa8fe2011-11-25 00:18:01 +0000267 return fsl_esdhc_mmc_init(bis);
Jason Liu83aa8fe2011-11-25 00:18:01 +0000268}
Benoît Thébaudeau58d22322012-08-17 10:42:55 +0000269#endif
Jason Liu83aa8fe2011-11-25 00:18:01 +0000270
Peng Fan39945c12018-11-20 10:19:25 +0000271#if !(defined(CONFIG_MX7) || defined(CONFIG_IMX8M))
Fabio Estevam6479f512012-04-29 08:11:13 +0000272u32 get_ahb_clk(void)
273{
274 struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
275 u32 reg, ahb_podf;
276
277 reg = __raw_readl(&imx_ccm->cbcdr);
278 reg &= MXC_CCM_CBCDR_AHB_PODF_MASK;
279 ahb_podf = reg >> MXC_CCM_CBCDR_AHB_PODF_OFFSET;
280
281 return get_periph_clk() / (ahb_podf + 1);
282}
Adrian Alonso9f883e02015-09-02 13:54:23 -0500283#endif
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000284
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000285void arch_preboot_os(void)
286{
Ye Li3525e3c2019-07-22 20:51:25 -0700287#if defined(CONFIG_IMX_AHCI)
288 struct udevice *dev;
289 int rc;
290
291 rc = uclass_find_device(UCLASS_AHCI, 0, &dev);
292 if (!rc && dev) {
293 rc = device_remove(dev, DM_REMOVE_NORMAL);
294 if (rc)
295 printf("Cannot remove SATA device '%s' (err=%d)\n",
296 dev->name, rc);
297 }
298#endif
299
Simon Glassab3055a2017-06-14 21:28:25 -0600300#if defined(CONFIG_SATA)
Ludwig Zenzeb15ce22019-07-02 15:10:52 +0200301 if (!is_mx6sdl()) {
302 sata_remove(0);
Soeren Mocha517d022014-11-27 10:11:41 +0100303#if defined(CONFIG_MX6)
Ludwig Zenzeb15ce22019-07-02 15:10:52 +0200304 disable_sata_clock();
Soeren Mocha517d022014-11-27 10:11:41 +0100305#endif
Ludwig Zenzeb15ce22019-07-02 15:10:52 +0200306 }
Nikita Kiryanovb5c9ed32014-11-21 12:47:26 +0200307#endif
308#if defined(CONFIG_VIDEO_IPUV3)
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000309 /* disable video before launching O/S */
310 ipuv3_fb_shutdown();
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000311#endif
Simon Glass52cb5042022-10-18 07:46:31 -0600312#if defined(CONFIG_VIDEO_MXS) && !defined(CONFIG_VIDEO)
Peng Fanf2c39922015-10-29 15:54:51 +0800313 lcdif_power_down();
314#endif
Nikita Kiryanovb5c9ed32014-11-21 12:47:26 +0200315}
Fabio Estevam16e65f62014-11-14 11:27:21 -0200316
Peng Fan39945c12018-11-20 10:19:25 +0000317#ifndef CONFIG_IMX8M
Fabio Estevam16e65f62014-11-14 11:27:21 -0200318void set_chipselect_size(int const cs_size)
319{
320 unsigned int reg;
321 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
322 reg = readl(&iomuxc_regs->gpr[1]);
323
324 switch (cs_size) {
325 case CS0_128:
326 reg &= ~0x7; /* CS0=128MB, CS1=0, CS2=0, CS3=0 */
327 reg |= 0x5;
328 break;
329 case CS0_64M_CS1_64M:
330 reg &= ~0x3F; /* CS0=64MB, CS1=64MB, CS2=0, CS3=0 */
331 reg |= 0x1B;
332 break;
333 case CS0_64M_CS1_32M_CS2_32M:
334 reg &= ~0x1FF; /* CS0=64MB, CS1=32MB, CS2=32MB, CS3=0 */
335 reg |= 0x4B;
336 break;
337 case CS0_32M_CS1_32M_CS2_32M_CS3_32M:
338 reg &= ~0xFFF; /* CS0=32MB, CS1=32MB, CS2=32MB, CS3=32MB */
339 reg |= 0x249;
340 break;
341 default:
342 printf("Unknown chip select size: %d\n", cs_size);
343 break;
344 }
345
346 writel(reg, &iomuxc_regs->gpr[1]);
347}
Peng Fana78e0ac2018-01-10 13:20:25 +0800348#endif
Fabio Estevam49bcdd72017-11-27 10:25:09 -0200349
Peng Fan39945c12018-11-20 10:19:25 +0000350#if defined(CONFIG_MX7) || defined(CONFIG_IMX8M)
Peng Fan7753bc72018-01-10 13:20:29 +0800351/*
352 * OCOTP_TESTER3[9:8] (see Fusemap Description Table offset 0x440)
353 * defines a 2-bit SPEED_GRADING
354 */
355#define OCOTP_TESTER3_SPEED_SHIFT 8
Peng Fana12bf3c2018-01-10 13:20:30 +0800356enum cpu_speed {
357 OCOTP_TESTER3_SPEED_GRADE0,
358 OCOTP_TESTER3_SPEED_GRADE1,
359 OCOTP_TESTER3_SPEED_GRADE2,
360 OCOTP_TESTER3_SPEED_GRADE3,
Peng Fan6a5f9c92018-12-12 02:47:58 -0800361 OCOTP_TESTER3_SPEED_GRADE4,
Peng Fana12bf3c2018-01-10 13:20:30 +0800362};
Peng Fan7753bc72018-01-10 13:20:29 +0800363
364u32 get_cpu_speed_grade_hz(void)
365{
366 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
367 struct fuse_bank *bank = &ocotp->bank[1];
368 struct fuse_bank1_regs *fuse =
369 (struct fuse_bank1_regs *)bank->fuse_regs;
370 uint32_t val;
371
372 val = readl(&fuse->tester3);
373 val >>= OCOTP_TESTER3_SPEED_SHIFT;
Peng Fan6a5f9c92018-12-12 02:47:58 -0800374
Peng Fan0599e5e2020-01-17 16:11:29 +0800375 if (is_imx8mn() || is_imx8mp()) {
Peng Fan6a5f9c92018-12-12 02:47:58 -0800376 val &= 0xf;
377 return 2300000000 - val * 100000000;
378 }
379
380 if (is_imx8mm())
381 val &= 0x7;
382 else
383 val &= 0x3;
Peng Fan7753bc72018-01-10 13:20:29 +0800384
385 switch(val) {
Peng Fana12bf3c2018-01-10 13:20:30 +0800386 case OCOTP_TESTER3_SPEED_GRADE0:
Peng Fan7753bc72018-01-10 13:20:29 +0800387 return 800000000;
Peng Fana12bf3c2018-01-10 13:20:30 +0800388 case OCOTP_TESTER3_SPEED_GRADE1:
Ye Lic9c1f9c2018-10-16 23:12:37 -0700389 return (is_mx7() ? 500000000 : (is_imx8mq() ? 1000000000 : 1200000000));
Peng Fana12bf3c2018-01-10 13:20:30 +0800390 case OCOTP_TESTER3_SPEED_GRADE2:
Ye Lic9c1f9c2018-10-16 23:12:37 -0700391 return (is_mx7() ? 1000000000 : (is_imx8mq() ? 1300000000 : 1600000000));
Peng Fana12bf3c2018-01-10 13:20:30 +0800392 case OCOTP_TESTER3_SPEED_GRADE3:
Ye Lic9c1f9c2018-10-16 23:12:37 -0700393 return (is_mx7() ? 1200000000 : (is_imx8mq() ? 1500000000 : 1800000000));
Peng Fan6a5f9c92018-12-12 02:47:58 -0800394 case OCOTP_TESTER3_SPEED_GRADE4:
395 return 2000000000;
Peng Fan7753bc72018-01-10 13:20:29 +0800396 }
Peng Fana12bf3c2018-01-10 13:20:30 +0800397
Peng Fan7753bc72018-01-10 13:20:29 +0800398 return 0;
399}
400
401/*
402 * OCOTP_TESTER3[7:6] (see Fusemap Description Table offset 0x440)
403 * defines a 2-bit SPEED_GRADING
404 */
405#define OCOTP_TESTER3_TEMP_SHIFT 6
406
Ye Lia31f1962020-03-09 23:11:54 -0700407/* iMX8MP uses OCOTP_TESTER3[6:5] for Market segment */
408#define IMX8MP_OCOTP_TESTER3_TEMP_SHIFT 5
409
Peng Fan7753bc72018-01-10 13:20:29 +0800410u32 get_cpu_temp_grade(int *minc, int *maxc)
411{
412 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
413 struct fuse_bank *bank = &ocotp->bank[1];
414 struct fuse_bank1_regs *fuse =
415 (struct fuse_bank1_regs *)bank->fuse_regs;
416 uint32_t val;
417
418 val = readl(&fuse->tester3);
Ye Lia31f1962020-03-09 23:11:54 -0700419 if (is_imx8mp())
420 val >>= IMX8MP_OCOTP_TESTER3_TEMP_SHIFT;
421 else
422 val >>= OCOTP_TESTER3_TEMP_SHIFT;
Peng Fan7753bc72018-01-10 13:20:29 +0800423 val &= 0x3;
424
425 if (minc && maxc) {
426 if (val == TEMP_AUTOMOTIVE) {
427 *minc = -40;
428 *maxc = 125;
429 } else if (val == TEMP_INDUSTRIAL) {
430 *minc = -40;
431 *maxc = 105;
432 } else if (val == TEMP_EXTCOMMERCIAL) {
433 *minc = -20;
434 *maxc = 105;
435 } else {
436 *minc = 0;
437 *maxc = 95;
438 }
439 }
440 return val;
441}
442#endif
443
Peng Fan88c41fd2019-09-16 03:09:34 +0000444#if defined(CONFIG_MX7) || defined(CONFIG_IMX8MQ) || defined(CONFIG_IMX8MM)
Peng Fand64a3c52018-01-10 13:20:34 +0800445enum boot_device get_boot_device(void)
446{
447 struct bootrom_sw_info **p =
448 (struct bootrom_sw_info **)(ulong)ROM_SW_INFO_ADDR;
449
450 enum boot_device boot_dev = SD1_BOOT;
451 u8 boot_type = (*p)->boot_dev_type;
452 u8 boot_instance = (*p)->boot_dev_instance;
453
454 switch (boot_type) {
455 case BOOT_TYPE_SD:
456 boot_dev = boot_instance + SD1_BOOT;
457 break;
458 case BOOT_TYPE_MMC:
459 boot_dev = boot_instance + MMC1_BOOT;
460 break;
461 case BOOT_TYPE_NAND:
462 boot_dev = NAND_BOOT;
463 break;
464 case BOOT_TYPE_QSPI:
465 boot_dev = QSPI_BOOT;
466 break;
467 case BOOT_TYPE_WEIM:
468 boot_dev = WEIM_NOR_BOOT;
469 break;
470 case BOOT_TYPE_SPINOR:
471 boot_dev = SPI_NOR_BOOT;
472 break;
Peng Fan24d3fbc2018-01-10 13:20:35 +0800473 case BOOT_TYPE_USB:
474 boot_dev = USB_BOOT;
475 break;
Peng Fand64a3c52018-01-10 13:20:34 +0800476 default:
Peng Fan037f91c2018-05-17 15:15:59 +0800477#ifdef CONFIG_IMX8M
478 if (((readl(SRC_BASE_ADDR + 0x58) & 0x00007FFF) >> 12) == 0x4)
479 boot_dev = QSPI_BOOT;
480#endif
Peng Fand64a3c52018-01-10 13:20:34 +0800481 break;
482 }
483
484 return boot_dev;
485}
486#endif
487
Fabio Estevam49bcdd72017-11-27 10:25:09 -0200488#ifdef CONFIG_NXP_BOARD_REVISION
489int nxp_board_rev(void)
490{
491 /*
492 * Get Board ID information from OCOTP_GP1[15:8]
493 * RevA: 0x1
494 * RevB: 0x2
495 * RevC: 0x3
496 */
497 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
498 struct fuse_bank *bank = &ocotp->bank[4];
499 struct fuse_bank4_regs *fuse =
500 (struct fuse_bank4_regs *)bank->fuse_regs;
501
502 return (readl(&fuse->gp1) >> 8 & 0x0F);
503}
504
505char nxp_board_rev_string(void)
506{
507 const char *rev = "A";
508
509 return (*rev + nxp_board_rev() - 1);
510}
511#endif
Marek Vasuteec84622023-06-23 21:56:27 +0200512
513__weak void reset_cpu(void)
514{
515}