blob: 8eb05c8dd67795ebc0e656b0f122e5475eb535ef [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jason Liu18936ee2011-11-25 00:18:01 +00002/*
3 * (C) Copyright 2007
4 * Sascha Hauer, Pengutronix
5 *
6 * (C) Copyright 2009 Freescale Semiconductor, Inc.
Jason Liu18936ee2011-11-25 00:18:01 +00007 */
8
Jeroen Hofstee5624c6b2014-10-08 22:57:52 +02009#include <bootm.h>
Jason Liu18936ee2011-11-25 00:18:01 +000010#include <common.h>
Simon Glass055efe52020-07-19 10:15:41 -060011#include <dm.h>
Simon Glass691d7192020-05-10 11:40:02 -060012#include <init.h>
Simon Glassf7ae49f2020-05-10 11:40:05 -060013#include <log.h>
Simon Glass90526e92020-05-10 11:39:56 -060014#include <net.h>
Jeroen Hofstee5624c6b2014-10-08 22:57:52 +020015#include <netdev.h>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090016#include <linux/errno.h>
Jason Liu18936ee2011-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 Estevam6a376042012-04-29 08:11:13 +000021#include <asm/arch/crm_regs.h>
Peng Fan770611f2018-01-10 13:20:34 +080022#include <asm/mach-imx/boot_mode.h>
Tim Harvey70caa8e2015-05-18 06:56:46 -070023#include <imx_thermal.h>
Eric Nelsone1eb75b2012-09-23 07:30:55 +000024#include <ipu_pixfmt.h>
Ye.Li7a264162014-11-20 21:14:14 +080025#include <thermal.h>
Nikita Kiryanov44b98412014-11-21 12:47:26 +020026#include <sata.h>
Ye Liacc403c2019-07-22 20:51:25 -070027#include <dm/device-internal.h>
28#include <dm/uclass-internal.h>
Jason Liu18936ee2011-11-25 00:18:01 +000029
Yangbo Lue37ac712019-06-21 11:42:28 +080030#ifdef CONFIG_FSL_ESDHC_IMX
31#include <fsl_esdhc_imx.h>
Jason Liu18936ee2011-11-25 00:18:01 +000032#endif
33
Eric Nelson11c2e502015-02-15 14:37:21 -070034static u32 reset_cause = -1;
35
Max Krummenacher6ed4d262019-02-01 16:04:51 +010036u32 get_imx_reset_cause(void)
Jason Liu18936ee2011-11-25 00:18:01 +000037{
Jason Liu18936ee2011-11-25 00:18:01 +000038 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
39
Max Krummenacher6ed4d262019-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 }
Jason Liu18936ee2011-11-25 00:18:01 +000047
Max Krummenacher6ed4d262019-02-01 16:04:51 +010048 return reset_cause;
49}
50
51#if defined(CONFIG_DISPLAY_CPUINFO) && !defined(CONFIG_SPL_BUILD)
52static char *get_reset_cause(void)
53{
54 switch (get_imx_reset_cause()) {
Jason Liu18936ee2011-11-25 00:18:01 +000055 case 0x00001:
Fabio Estevamcece2622012-03-13 07:26:48 +000056 case 0x00011:
Jason Liu18936ee2011-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 Alonsocd562c82015-09-02 13:54:23 -050063#ifdef CONFIG_MX7
64 return "WDOG1";
65#else
Jason Liu18936ee2011-11-25 00:18:01 +000066 return "WDOG";
Adrian Alonsocd562c82015-09-02 13:54:23 -050067#endif
Jason Liu18936ee2011-11-25 00:18:01 +000068 case 0x00020:
69 return "JTAG HIGH-Z";
70 case 0x00040:
71 return "JTAG SW";
Adrian Alonsocd562c82015-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 Fancd357ad2018-11-20 10:19:25 +000079#elif defined(CONFIG_IMX8M)
Peng Fan7537e932018-01-10 13:20:25 +080080 case 0x00100:
81 return "WDOG2";
82 case 0x00200:
83 return "TEMPSENSE";
Adrian Alonsocd562c82015-09-02 13:54:23 -050084#else
85 case 0x00100:
86 return "TEMPSENSE";
Jason Liu18936ee2011-11-25 00:18:01 +000087 case 0x10000:
88 return "WARM BOOT";
Adrian Alonsocd562c82015-09-02 13:54:23 -050089#endif
Jason Liu18936ee2011-11-25 00:18:01 +000090 default:
91 return "unknown reset";
92 }
93}
Prabhakar Kushwaha28420e72015-05-18 17:13:52 +053094#endif
Eric Nelson11c2e502015-02-15 14:37:21 -070095
Anatolij Gustschin38df3702017-08-28 21:46:26 +020096#if defined(CONFIG_DISPLAY_CPUINFO) && !defined(CONFIG_SPL_BUILD)
Fabio Estevama7683862012-03-20 04:21:45 +000097
Troy Kisky20332a02012-10-23 10:57:46 +000098const char *get_imx_type(u32 imxtype)
Fabio Estevama7683862012-03-20 04:21:45 +000099{
100 switch (imxtype) {
Peng Fan625b03d2019-12-27 10:14:02 +0800101 case MXC_CPU_IMX8MP:
Ye Lid1eee7e2020-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 Lid1eee7e2020-04-20 20:12:54 -0700107 case MXC_CPU_IMX8MP6:
108 return "8MP[6]"; /* Quad-core version of the imx8mp, NPU fused */
Peng Fan24341312019-06-27 17:23:49 +0800109 case MXC_CPU_IMX8MN:
Peng Fanc9154032020-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:
Ye Lic4f78cb2021-03-19 15:57:11 +0800120 return "8MNano SoloLite";/* Single-core Lite version of the imx8mn */
121 case MXC_CPU_IMX8MNUQ:
122 return "8MNano UltraLite Quad";/* Quad-core UltraLite version of the imx8mn */
123 case MXC_CPU_IMX8MNUD:
124 return "8MNano UltraLite Dual";/* Dual-core UltraLite version of the imx8mn */
125 case MXC_CPU_IMX8MNUS:
126 return "8MNano UltraLite Solo";/* Single-core UltraLite version of the imx8mn */
Peng Fan65a6c502019-08-27 06:25:04 +0000127 case MXC_CPU_IMX8MM:
128 return "8MMQ"; /* Quad-core version of the imx8mm */
129 case MXC_CPU_IMX8MML:
130 return "8MMQL"; /* Quad-core Lite version of the imx8mm */
131 case MXC_CPU_IMX8MMD:
132 return "8MMD"; /* Dual-core version of the imx8mm */
133 case MXC_CPU_IMX8MMDL:
134 return "8MMDL"; /* Dual-core Lite version of the imx8mm */
135 case MXC_CPU_IMX8MMS:
136 return "8MMS"; /* Single-core version of the imx8mm */
137 case MXC_CPU_IMX8MMSL:
138 return "8MMSL"; /* Single-core Lite version of the imx8mm */
Peng Fancd357ad2018-11-20 10:19:25 +0000139 case MXC_CPU_IMX8MQ:
Peng Fancb1a1de2020-02-05 17:34:54 +0800140 return "8MQ"; /* Quad-core version of the imx8mq */
141 case MXC_CPU_IMX8MQL:
142 return "8MQLite"; /* Quad-core Lite version of the imx8mq */
143 case MXC_CPU_IMX8MD:
144 return "8MD"; /* Dual-core version of the imx8mq */
Fabio Estevame25a0652016-02-28 12:33:17 -0300145 case MXC_CPU_MX7S:
Stefan Agner249092f2016-05-06 11:21:50 -0700146 return "7S"; /* Single-core version of the mx7 */
Adrian Alonsocd562c82015-09-02 13:54:23 -0500147 case MXC_CPU_MX7D:
148 return "7D"; /* Dual-core version of the mx7 */
Peng Fand0acd992015-07-11 11:38:42 +0800149 case MXC_CPU_MX6QP:
150 return "6QP"; /* Quad-Plus version of the mx6 */
151 case MXC_CPU_MX6DP:
152 return "6DP"; /* Dual-Plus version of the mx6 */
Troy Kisky20332a02012-10-23 10:57:46 +0000153 case MXC_CPU_MX6Q:
Fabio Estevama7683862012-03-20 04:21:45 +0000154 return "6Q"; /* Quad-core version of the mx6 */
Fabio Estevam94db6652014-01-26 15:06:41 -0200155 case MXC_CPU_MX6D:
156 return "6D"; /* Dual-core version of the mx6 */
Troy Kisky20332a02012-10-23 10:57:46 +0000157 case MXC_CPU_MX6DL:
158 return "6DL"; /* Dual Lite version of the mx6 */
159 case MXC_CPU_MX6SOLO:
160 return "6SOLO"; /* Solo version of the mx6 */
161 case MXC_CPU_MX6SL:
Fabio Estevama7683862012-03-20 04:21:45 +0000162 return "6SL"; /* Solo-Lite version of the mx6 */
Peng Fan7ce6d3c2016-12-11 19:24:20 +0800163 case MXC_CPU_MX6SLL:
164 return "6SLL"; /* SLL version of the mx6 */
Fabio Estevam05d54b82014-06-24 17:40:58 -0300165 case MXC_CPU_MX6SX:
166 return "6SX"; /* SoloX version of the mx6 */
Peng Fan8631c062015-07-20 19:28:21 +0800167 case MXC_CPU_MX6UL:
168 return "6UL"; /* Ultra-Lite version of the mx6 */
Peng Fan65ce54b2016-08-11 14:02:38 +0800169 case MXC_CPU_MX6ULL:
170 return "6ULL"; /* ULL version of the mx6 */
Peng Fan81ae46c2019-08-08 09:55:52 +0000171 case MXC_CPU_MX6ULZ:
172 return "6ULZ"; /* ULZ 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
Peng Fandc597d12020-05-03 22:19:57 +0800189#if defined(CONFIG_IMX_THERMAL) || defined(CONFIG_IMX_TMU)
Adrian Alonso1368f992015-09-02 13:54:13 -0500190 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",
Peng Fan13868ea2019-12-30 17:57:10 +0800194 get_imx_type((cpurev & 0x1FF000) >> 12),
Tim Harveyb83ddac2015-05-18 07:02:25 -0700195 (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",
Peng Fan13868ea2019-12-30 17:57:10 +0800206 get_imx_type((cpurev & 0x1FF000) >> 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
Peng Fandc597d12020-05-03 22:19:57 +0800212#if defined(CONFIG_IMX_THERMAL) || defined(CONFIG_IMX_TMU)
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 Harvey9d416282020-10-12 12:26:41 -0700234 printf(" at %dC", 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 }
Tim Harvey9d416282020-10-12 12:26:41 -0700240 puts("\n");
Ye.Li7a264162014-11-20 21:14:14 +0800241#endif
242
Jason Liu18936ee2011-11-25 00:18:01 +0000243 printf("Reset cause: %s\n", get_reset_cause());
244 return 0;
245}
246#endif
247
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900248int cpu_eth_init(struct bd_info *bis)
Jason Liu18936ee2011-11-25 00:18:01 +0000249{
250 int rc = -ENODEV;
251
252#if defined(CONFIG_FEC_MXC)
253 rc = fecmxc_initialize(bis);
254#endif
255
256 return rc;
257}
258
Yangbo Lue37ac712019-06-21 11:42:28 +0800259#ifdef CONFIG_FSL_ESDHC_IMX
Jason Liu18936ee2011-11-25 00:18:01 +0000260/*
261 * Initializes on-chip MMC controllers.
262 * to override, implement board_mmc_init()
263 */
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900264int cpu_mmc_init(struct bd_info *bis)
Jason Liu18936ee2011-11-25 00:18:01 +0000265{
Jason Liu18936ee2011-11-25 00:18:01 +0000266 return fsl_esdhc_mmc_init(bis);
Jason Liu18936ee2011-11-25 00:18:01 +0000267}
Benoît Thébaudeauecb0f312012-08-17 10:42:55 +0000268#endif
Jason Liu18936ee2011-11-25 00:18:01 +0000269
Peng Fancd357ad2018-11-20 10:19:25 +0000270#if !(defined(CONFIG_MX7) || defined(CONFIG_IMX8M))
Fabio Estevam6a376042012-04-29 08:11:13 +0000271u32 get_ahb_clk(void)
272{
273 struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
274 u32 reg, ahb_podf;
275
276 reg = __raw_readl(&imx_ccm->cbcdr);
277 reg &= MXC_CCM_CBCDR_AHB_PODF_MASK;
278 ahb_podf = reg >> MXC_CCM_CBCDR_AHB_PODF_OFFSET;
279
280 return get_periph_clk() / (ahb_podf + 1);
281}
Adrian Alonsocd562c82015-09-02 13:54:23 -0500282#endif
Eric Nelsone1eb75b2012-09-23 07:30:55 +0000283
Eric Nelsone1eb75b2012-09-23 07:30:55 +0000284void arch_preboot_os(void)
285{
Ye Liacc403c2019-07-22 20:51:25 -0700286#if defined(CONFIG_IMX_AHCI)
287 struct udevice *dev;
288 int rc;
289
290 rc = uclass_find_device(UCLASS_AHCI, 0, &dev);
291 if (!rc && dev) {
292 rc = device_remove(dev, DM_REMOVE_NORMAL);
293 if (rc)
294 printf("Cannot remove SATA device '%s' (err=%d)\n",
295 dev->name, rc);
296 }
297#endif
298
Simon Glass10e40d52017-06-14 21:28:25 -0600299#if defined(CONFIG_SATA)
Ludwig Zenz86e59532019-07-02 15:10:52 +0200300 if (!is_mx6sdl()) {
301 sata_remove(0);
Soeren Mochdd1c8f12014-11-27 10:11:41 +0100302#if defined(CONFIG_MX6)
Ludwig Zenz86e59532019-07-02 15:10:52 +0200303 disable_sata_clock();
Soeren Mochdd1c8f12014-11-27 10:11:41 +0100304#endif
Ludwig Zenz86e59532019-07-02 15:10:52 +0200305 }
Nikita Kiryanov44b98412014-11-21 12:47:26 +0200306#endif
307#if defined(CONFIG_VIDEO_IPUV3)
Eric Nelsone1eb75b2012-09-23 07:30:55 +0000308 /* disable video before launching O/S */
309 ipuv3_fb_shutdown();
Eric Nelsone1eb75b2012-09-23 07:30:55 +0000310#endif
Igor Opaniuk8c1df092019-06-04 00:05:59 +0300311#if defined(CONFIG_VIDEO_MXS) && !defined(CONFIG_DM_VIDEO)
Peng Fan623787f2015-10-29 15:54:51 +0800312 lcdif_power_down();
313#endif
Nikita Kiryanov44b98412014-11-21 12:47:26 +0200314}
Fabio Estevam32c81ea2014-11-14 11:27:21 -0200315
Peng Fancd357ad2018-11-20 10:19:25 +0000316#ifndef CONFIG_IMX8M
Fabio Estevam32c81ea2014-11-14 11:27:21 -0200317void set_chipselect_size(int const cs_size)
318{
319 unsigned int reg;
320 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
321 reg = readl(&iomuxc_regs->gpr[1]);
322
323 switch (cs_size) {
324 case CS0_128:
325 reg &= ~0x7; /* CS0=128MB, CS1=0, CS2=0, CS3=0 */
326 reg |= 0x5;
327 break;
328 case CS0_64M_CS1_64M:
329 reg &= ~0x3F; /* CS0=64MB, CS1=64MB, CS2=0, CS3=0 */
330 reg |= 0x1B;
331 break;
332 case CS0_64M_CS1_32M_CS2_32M:
333 reg &= ~0x1FF; /* CS0=64MB, CS1=32MB, CS2=32MB, CS3=0 */
334 reg |= 0x4B;
335 break;
336 case CS0_32M_CS1_32M_CS2_32M_CS3_32M:
337 reg &= ~0xFFF; /* CS0=32MB, CS1=32MB, CS2=32MB, CS3=32MB */
338 reg |= 0x249;
339 break;
340 default:
341 printf("Unknown chip select size: %d\n", cs_size);
342 break;
343 }
344
345 writel(reg, &iomuxc_regs->gpr[1]);
346}
Peng Fan7537e932018-01-10 13:20:25 +0800347#endif
Fabio Estevam4555c262017-11-27 10:25:09 -0200348
Peng Fancd357ad2018-11-20 10:19:25 +0000349#if defined(CONFIG_MX7) || defined(CONFIG_IMX8M)
Peng Fan423e84b2018-01-10 13:20:29 +0800350/*
351 * OCOTP_TESTER3[9:8] (see Fusemap Description Table offset 0x440)
352 * defines a 2-bit SPEED_GRADING
353 */
354#define OCOTP_TESTER3_SPEED_SHIFT 8
Peng Fane56d9d72018-01-10 13:20:30 +0800355enum cpu_speed {
356 OCOTP_TESTER3_SPEED_GRADE0,
357 OCOTP_TESTER3_SPEED_GRADE1,
358 OCOTP_TESTER3_SPEED_GRADE2,
359 OCOTP_TESTER3_SPEED_GRADE3,
Peng Fan47586a42018-12-12 02:47:58 -0800360 OCOTP_TESTER3_SPEED_GRADE4,
Peng Fane56d9d72018-01-10 13:20:30 +0800361};
Peng Fan423e84b2018-01-10 13:20:29 +0800362
363u32 get_cpu_speed_grade_hz(void)
364{
365 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
366 struct fuse_bank *bank = &ocotp->bank[1];
367 struct fuse_bank1_regs *fuse =
368 (struct fuse_bank1_regs *)bank->fuse_regs;
369 uint32_t val;
370
371 val = readl(&fuse->tester3);
372 val >>= OCOTP_TESTER3_SPEED_SHIFT;
Peng Fan47586a42018-12-12 02:47:58 -0800373
Peng Fan354dcce2020-01-17 16:11:29 +0800374 if (is_imx8mn() || is_imx8mp()) {
Peng Fan47586a42018-12-12 02:47:58 -0800375 val &= 0xf;
376 return 2300000000 - val * 100000000;
377 }
378
379 if (is_imx8mm())
380 val &= 0x7;
381 else
382 val &= 0x3;
Peng Fan423e84b2018-01-10 13:20:29 +0800383
384 switch(val) {
Peng Fane56d9d72018-01-10 13:20:30 +0800385 case OCOTP_TESTER3_SPEED_GRADE0:
Peng Fan423e84b2018-01-10 13:20:29 +0800386 return 800000000;
Peng Fane56d9d72018-01-10 13:20:30 +0800387 case OCOTP_TESTER3_SPEED_GRADE1:
Ye Lic9a1a242018-10-16 23:12:37 -0700388 return (is_mx7() ? 500000000 : (is_imx8mq() ? 1000000000 : 1200000000));
Peng Fane56d9d72018-01-10 13:20:30 +0800389 case OCOTP_TESTER3_SPEED_GRADE2:
Ye Lic9a1a242018-10-16 23:12:37 -0700390 return (is_mx7() ? 1000000000 : (is_imx8mq() ? 1300000000 : 1600000000));
Peng Fane56d9d72018-01-10 13:20:30 +0800391 case OCOTP_TESTER3_SPEED_GRADE3:
Ye Lic9a1a242018-10-16 23:12:37 -0700392 return (is_mx7() ? 1200000000 : (is_imx8mq() ? 1500000000 : 1800000000));
Peng Fan47586a42018-12-12 02:47:58 -0800393 case OCOTP_TESTER3_SPEED_GRADE4:
394 return 2000000000;
Peng Fan423e84b2018-01-10 13:20:29 +0800395 }
Peng Fane56d9d72018-01-10 13:20:30 +0800396
Peng Fan423e84b2018-01-10 13:20:29 +0800397 return 0;
398}
399
400/*
401 * OCOTP_TESTER3[7:6] (see Fusemap Description Table offset 0x440)
402 * defines a 2-bit SPEED_GRADING
403 */
404#define OCOTP_TESTER3_TEMP_SHIFT 6
405
Ye Li79e02172020-03-09 23:11:54 -0700406/* iMX8MP uses OCOTP_TESTER3[6:5] for Market segment */
407#define IMX8MP_OCOTP_TESTER3_TEMP_SHIFT 5
408
Peng Fan423e84b2018-01-10 13:20:29 +0800409u32 get_cpu_temp_grade(int *minc, int *maxc)
410{
411 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
412 struct fuse_bank *bank = &ocotp->bank[1];
413 struct fuse_bank1_regs *fuse =
414 (struct fuse_bank1_regs *)bank->fuse_regs;
415 uint32_t val;
416
417 val = readl(&fuse->tester3);
Ye Li79e02172020-03-09 23:11:54 -0700418 if (is_imx8mp())
419 val >>= IMX8MP_OCOTP_TESTER3_TEMP_SHIFT;
420 else
421 val >>= OCOTP_TESTER3_TEMP_SHIFT;
Peng Fan423e84b2018-01-10 13:20:29 +0800422 val &= 0x3;
423
424 if (minc && maxc) {
425 if (val == TEMP_AUTOMOTIVE) {
426 *minc = -40;
427 *maxc = 125;
428 } else if (val == TEMP_INDUSTRIAL) {
429 *minc = -40;
430 *maxc = 105;
431 } else if (val == TEMP_EXTCOMMERCIAL) {
432 *minc = -20;
433 *maxc = 105;
434 } else {
435 *minc = 0;
436 *maxc = 95;
437 }
438 }
439 return val;
440}
441#endif
442
Peng Fanb890c4a2019-09-16 03:09:34 +0000443#if defined(CONFIG_MX7) || defined(CONFIG_IMX8MQ) || defined(CONFIG_IMX8MM)
Peng Fan770611f2018-01-10 13:20:34 +0800444enum boot_device get_boot_device(void)
445{
446 struct bootrom_sw_info **p =
447 (struct bootrom_sw_info **)(ulong)ROM_SW_INFO_ADDR;
448
449 enum boot_device boot_dev = SD1_BOOT;
450 u8 boot_type = (*p)->boot_dev_type;
451 u8 boot_instance = (*p)->boot_dev_instance;
452
453 switch (boot_type) {
454 case BOOT_TYPE_SD:
455 boot_dev = boot_instance + SD1_BOOT;
456 break;
457 case BOOT_TYPE_MMC:
458 boot_dev = boot_instance + MMC1_BOOT;
459 break;
460 case BOOT_TYPE_NAND:
461 boot_dev = NAND_BOOT;
462 break;
463 case BOOT_TYPE_QSPI:
464 boot_dev = QSPI_BOOT;
465 break;
466 case BOOT_TYPE_WEIM:
467 boot_dev = WEIM_NOR_BOOT;
468 break;
469 case BOOT_TYPE_SPINOR:
470 boot_dev = SPI_NOR_BOOT;
471 break;
Peng Fan80ebf862018-01-10 13:20:35 +0800472 case BOOT_TYPE_USB:
473 boot_dev = USB_BOOT;
474 break;
Peng Fan770611f2018-01-10 13:20:34 +0800475 default:
Peng Fand4e84f22018-05-17 15:15:59 +0800476#ifdef CONFIG_IMX8M
477 if (((readl(SRC_BASE_ADDR + 0x58) & 0x00007FFF) >> 12) == 0x4)
478 boot_dev = QSPI_BOOT;
479#endif
Peng Fan770611f2018-01-10 13:20:34 +0800480 break;
481 }
482
483 return boot_dev;
484}
485#endif
486
Fabio Estevam4555c262017-11-27 10:25:09 -0200487#ifdef CONFIG_NXP_BOARD_REVISION
488int nxp_board_rev(void)
489{
490 /*
491 * Get Board ID information from OCOTP_GP1[15:8]
492 * RevA: 0x1
493 * RevB: 0x2
494 * RevC: 0x3
495 */
496 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
497 struct fuse_bank *bank = &ocotp->bank[4];
498 struct fuse_bank4_regs *fuse =
499 (struct fuse_bank4_regs *)bank->fuse_regs;
500
501 return (readl(&fuse->gp1) >> 8 & 0x0F);
502}
503
504char nxp_board_rev_string(void)
505{
506 const char *rev = "A";
507
508 return (*rev + nxp_board_rev() - 1);
509}
510#endif