blob: efd8fc614a641f7abb1cc61dd213b7dfc278d73a [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>
Jeroen Hofstee1abf3a12014-10-08 22:57:52 +020011#include <netdev.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090012#include <linux/errno.h>
Jason Liu83aa8fe2011-11-25 00:18:01 +000013#include <asm/io.h>
14#include <asm/arch/imx-regs.h>
15#include <asm/arch/clock.h>
16#include <asm/arch/sys_proto.h>
Fabio Estevam6479f512012-04-29 08:11:13 +000017#include <asm/arch/crm_regs.h>
Peng Fand64a3c52018-01-10 13:20:34 +080018#include <asm/mach-imx/boot_mode.h>
Tim Harvey27f90592015-05-18 06:56:46 -070019#include <imx_thermal.h>
Eric Nelson54b3f3b2012-09-23 07:30:55 +000020#include <ipu_pixfmt.h>
Ye.Lif19692c2014-11-20 21:14:14 +080021#include <thermal.h>
Nikita Kiryanovb5c9ed32014-11-21 12:47:26 +020022#include <sata.h>
Jason Liu83aa8fe2011-11-25 00:18:01 +000023
Yangbo Lu73340382019-06-21 11:42:28 +080024#ifdef CONFIG_FSL_ESDHC_IMX
25#include <fsl_esdhc_imx.h>
Jason Liu83aa8fe2011-11-25 00:18:01 +000026#endif
27
Eric Nelson25e02302015-02-15 14:37:21 -070028static u32 reset_cause = -1;
29
Max Krummenachercb2c8fd2019-02-01 16:04:51 +010030u32 get_imx_reset_cause(void)
Jason Liu83aa8fe2011-11-25 00:18:01 +000031{
Jason Liu83aa8fe2011-11-25 00:18:01 +000032 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
33
Max Krummenachercb2c8fd2019-02-01 16:04:51 +010034 if (reset_cause == -1) {
35 reset_cause = readl(&src_regs->srsr);
36/* preserve the value for U-Boot proper */
37#if !defined(CONFIG_SPL_BUILD)
38 writel(reset_cause, &src_regs->srsr);
39#endif
40 }
41
42 return reset_cause;
43}
Jason Liu83aa8fe2011-11-25 00:18:01 +000044
Max Krummenachercb2c8fd2019-02-01 16:04:51 +010045#if defined(CONFIG_DISPLAY_CPUINFO) && !defined(CONFIG_SPL_BUILD)
46static char *get_reset_cause(void)
47{
48 switch (get_imx_reset_cause()) {
Jason Liu83aa8fe2011-11-25 00:18:01 +000049 case 0x00001:
Fabio Estevam9af122b2012-03-13 07:26:48 +000050 case 0x00011:
Jason Liu83aa8fe2011-11-25 00:18:01 +000051 return "POR";
52 case 0x00004:
53 return "CSU";
54 case 0x00008:
55 return "IPP USER";
56 case 0x00010:
Adrian Alonso9f883e02015-09-02 13:54:23 -050057#ifdef CONFIG_MX7
58 return "WDOG1";
59#else
Jason Liu83aa8fe2011-11-25 00:18:01 +000060 return "WDOG";
Adrian Alonso9f883e02015-09-02 13:54:23 -050061#endif
Jason Liu83aa8fe2011-11-25 00:18:01 +000062 case 0x00020:
63 return "JTAG HIGH-Z";
64 case 0x00040:
65 return "JTAG SW";
Adrian Alonso9f883e02015-09-02 13:54:23 -050066 case 0x00080:
67 return "WDOG3";
68#ifdef CONFIG_MX7
69 case 0x00100:
70 return "WDOG4";
71 case 0x00200:
72 return "TEMPSENSE";
Peng Fan39945c12018-11-20 10:19:25 +000073#elif defined(CONFIG_IMX8M)
Peng Fana78e0ac2018-01-10 13:20:25 +080074 case 0x00100:
75 return "WDOG2";
76 case 0x00200:
77 return "TEMPSENSE";
Adrian Alonso9f883e02015-09-02 13:54:23 -050078#else
79 case 0x00100:
80 return "TEMPSENSE";
Jason Liu83aa8fe2011-11-25 00:18:01 +000081 case 0x10000:
82 return "WARM BOOT";
Adrian Alonso9f883e02015-09-02 13:54:23 -050083#endif
Jason Liu83aa8fe2011-11-25 00:18:01 +000084 default:
85 return "unknown reset";
86 }
87}
Prabhakar Kushwahaf2c19de2015-05-18 17:13:52 +053088#endif
Eric Nelson25e02302015-02-15 14:37:21 -070089
Troy Kiskyb3aec6a2012-10-23 10:57:48 +000090#if defined(CONFIG_MX53) || defined(CONFIG_MX6)
91#if defined(CONFIG_MX53)
Eric Nelsonc7d46122013-11-08 16:50:53 -070092#define MEMCTL_BASE ESDCTL_BASE_ADDR
Troy Kiskyb3aec6a2012-10-23 10:57:48 +000093#else
Eric Nelsonc7d46122013-11-08 16:50:53 -070094#define MEMCTL_BASE MMDC_P0_BASE_ADDR
Troy Kiskyb3aec6a2012-10-23 10:57:48 +000095#endif
96static const unsigned char col_lookup[] = {9, 10, 11, 8, 12, 9, 9, 9};
97static const unsigned char bank_lookup[] = {3, 2};
98
Tim Harvey066fbad2014-06-02 16:13:21 -070099/* these MMDC registers are common to the IMX53 and IMX6 */
Troy Kiskyb3aec6a2012-10-23 10:57:48 +0000100struct esd_mmdc_regs {
101 uint32_t ctl;
102 uint32_t pdc;
103 uint32_t otc;
104 uint32_t cfg0;
105 uint32_t cfg1;
106 uint32_t cfg2;
107 uint32_t misc;
Troy Kiskyb3aec6a2012-10-23 10:57:48 +0000108};
109
110#define ESD_MMDC_CTL_GET_ROW(mdctl) ((ctl >> 24) & 7)
111#define ESD_MMDC_CTL_GET_COLUMN(mdctl) ((ctl >> 20) & 7)
112#define ESD_MMDC_CTL_GET_WIDTH(mdctl) ((ctl >> 16) & 3)
113#define ESD_MMDC_CTL_GET_CS1(mdctl) ((ctl >> 30) & 1)
114#define ESD_MMDC_MISC_GET_BANK(mdmisc) ((misc >> 5) & 1)
115
Tim Harvey066fbad2014-06-02 16:13:21 -0700116/*
117 * imx_ddr_size - return size in bytes of DRAM according MMDC config
118 * The MMDC MDCTL register holds the number of bits for row, col, and data
119 * width and the MMDC MDMISC register holds the number of banks. Combine
120 * all these bits to determine the meme size the MMDC has been configured for
121 */
Troy Kiskyb3aec6a2012-10-23 10:57:48 +0000122unsigned imx_ddr_size(void)
123{
124 struct esd_mmdc_regs *mem = (struct esd_mmdc_regs *)MEMCTL_BASE;
125 unsigned ctl = readl(&mem->ctl);
126 unsigned misc = readl(&mem->misc);
127 int bits = 11 + 0 + 0 + 1; /* row + col + bank + width */
128
129 bits += ESD_MMDC_CTL_GET_ROW(ctl);
130 bits += col_lookup[ESD_MMDC_CTL_GET_COLUMN(ctl)];
131 bits += bank_lookup[ESD_MMDC_MISC_GET_BANK(misc)];
132 bits += ESD_MMDC_CTL_GET_WIDTH(ctl);
133 bits += ESD_MMDC_CTL_GET_CS1(ctl);
Marek Vasut005a4d12014-08-04 01:47:09 +0200134
135 /* The MX6 can do only 3840 MiB of DRAM */
136 if (bits == 32)
137 return 0xf0000000;
138
Troy Kiskyb3aec6a2012-10-23 10:57:48 +0000139 return 1 << bits;
140}
141#endif
142
Anatolij Gustschin03dd9862017-08-28 21:46:26 +0200143#if defined(CONFIG_DISPLAY_CPUINFO) && !defined(CONFIG_SPL_BUILD)
Fabio Estevam46e97332012-03-20 04:21:45 +0000144
Troy Kisky58394932012-10-23 10:57:46 +0000145const char *get_imx_type(u32 imxtype)
Fabio Estevam46e97332012-03-20 04:21:45 +0000146{
147 switch (imxtype) {
Peng Fan2d22a992019-08-27 06:25:04 +0000148 case MXC_CPU_IMX8MM:
149 return "8MMQ"; /* Quad-core version of the imx8mm */
150 case MXC_CPU_IMX8MML:
151 return "8MMQL"; /* Quad-core Lite version of the imx8mm */
152 case MXC_CPU_IMX8MMD:
153 return "8MMD"; /* Dual-core version of the imx8mm */
154 case MXC_CPU_IMX8MMDL:
155 return "8MMDL"; /* Dual-core Lite version of the imx8mm */
156 case MXC_CPU_IMX8MMS:
157 return "8MMS"; /* Single-core version of the imx8mm */
158 case MXC_CPU_IMX8MMSL:
159 return "8MMSL"; /* Single-core Lite version of the imx8mm */
Peng Fan39945c12018-11-20 10:19:25 +0000160 case MXC_CPU_IMX8MQ:
161 return "8MQ"; /* Quad-core version of the imx8m */
Fabio Estevamf6ced1b2016-02-28 12:33:17 -0300162 case MXC_CPU_MX7S:
Stefan Agnerf19a8e42016-05-06 11:21:50 -0700163 return "7S"; /* Single-core version of the mx7 */
Adrian Alonso9f883e02015-09-02 13:54:23 -0500164 case MXC_CPU_MX7D:
165 return "7D"; /* Dual-core version of the mx7 */
Peng Fan5f247922015-07-11 11:38:42 +0800166 case MXC_CPU_MX6QP:
167 return "6QP"; /* Quad-Plus version of the mx6 */
168 case MXC_CPU_MX6DP:
169 return "6DP"; /* Dual-Plus version of the mx6 */
Troy Kisky58394932012-10-23 10:57:46 +0000170 case MXC_CPU_MX6Q:
Fabio Estevam46e97332012-03-20 04:21:45 +0000171 return "6Q"; /* Quad-core version of the mx6 */
Fabio Estevamf3d5a2c2014-01-26 15:06:41 -0200172 case MXC_CPU_MX6D:
173 return "6D"; /* Dual-core version of the mx6 */
Troy Kisky58394932012-10-23 10:57:46 +0000174 case MXC_CPU_MX6DL:
175 return "6DL"; /* Dual Lite version of the mx6 */
176 case MXC_CPU_MX6SOLO:
177 return "6SOLO"; /* Solo version of the mx6 */
178 case MXC_CPU_MX6SL:
Fabio Estevam46e97332012-03-20 04:21:45 +0000179 return "6SL"; /* Solo-Lite version of the mx6 */
Peng Fan4cfd7972016-12-11 19:24:20 +0800180 case MXC_CPU_MX6SLL:
181 return "6SLL"; /* SLL version of the mx6 */
Fabio Estevam712ab882014-06-24 17:40:58 -0300182 case MXC_CPU_MX6SX:
183 return "6SX"; /* SoloX version of the mx6 */
Peng Faneaa53a12015-07-20 19:28:21 +0800184 case MXC_CPU_MX6UL:
185 return "6UL"; /* Ultra-Lite version of the mx6 */
Peng Fan3b33e3f2016-08-11 14:02:38 +0800186 case MXC_CPU_MX6ULL:
187 return "6ULL"; /* ULL version of the mx6 */
Peng Fanc53d0c92019-08-08 09:55:52 +0000188 case MXC_CPU_MX6ULZ:
189 return "6ULZ"; /* ULZ version of the mx6 */
Troy Kisky58394932012-10-23 10:57:46 +0000190 case MXC_CPU_MX51:
Fabio Estevam46e97332012-03-20 04:21:45 +0000191 return "51";
Troy Kisky58394932012-10-23 10:57:46 +0000192 case MXC_CPU_MX53:
Fabio Estevam46e97332012-03-20 04:21:45 +0000193 return "53";
194 default:
Otavio Salvador8567d7d2012-06-30 05:07:32 +0000195 return "??";
Fabio Estevam46e97332012-03-20 04:21:45 +0000196 }
197}
198
Jason Liu83aa8fe2011-11-25 00:18:01 +0000199int print_cpuinfo(void)
200{
Stefano Babic40adacc2015-05-26 19:53:41 +0200201 u32 cpurev;
202 __maybe_unused u32 max_freq;
Jason Liu83aa8fe2011-11-25 00:18:01 +0000203
Adrian Alonsoce08c362015-09-02 13:54:13 -0500204 cpurev = get_cpu_rev();
205
206#if defined(CONFIG_IMX_THERMAL)
Ye.Lif19692c2014-11-20 21:14:14 +0800207 struct udevice *thermal_dev;
Tim Harvey27f90592015-05-18 06:56:46 -0700208 int cpu_tmp, minc, maxc, ret;
Ye.Lif19692c2014-11-20 21:14:14 +0800209
Tim Harveyd792ede2015-05-18 07:02:25 -0700210 printf("CPU: Freescale i.MX%s rev%d.%d",
211 get_imx_type((cpurev & 0xFF000) >> 12),
212 (cpurev & 0x000F0) >> 4,
213 (cpurev & 0x0000F) >> 0);
214 max_freq = get_cpu_speed_grade_hz();
215 if (!max_freq || max_freq == mxc_get_clock(MXC_ARM_CLK)) {
216 printf(" at %dMHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
217 } else {
218 printf(" %d MHz (running at %d MHz)\n", max_freq / 1000000,
219 mxc_get_clock(MXC_ARM_CLK) / 1000000);
220 }
221#else
Fabio Estevam46e97332012-03-20 04:21:45 +0000222 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
223 get_imx_type((cpurev & 0xFF000) >> 12),
Jason Liu83aa8fe2011-11-25 00:18:01 +0000224 (cpurev & 0x000F0) >> 4,
225 (cpurev & 0x0000F) >> 0,
226 mxc_get_clock(MXC_ARM_CLK) / 1000000);
Tim Harveyd792ede2015-05-18 07:02:25 -0700227#endif
Ye.Lif19692c2014-11-20 21:14:14 +0800228
Adrian Alonsoce08c362015-09-02 13:54:13 -0500229#if defined(CONFIG_IMX_THERMAL)
Tim Harvey27f90592015-05-18 06:56:46 -0700230 puts("CPU: ");
231 switch (get_cpu_temp_grade(&minc, &maxc)) {
232 case TEMP_AUTOMOTIVE:
233 puts("Automotive temperature grade ");
234 break;
235 case TEMP_INDUSTRIAL:
236 puts("Industrial temperature grade ");
237 break;
238 case TEMP_EXTCOMMERCIAL:
239 puts("Extended Commercial temperature grade ");
240 break;
241 default:
242 puts("Commercial temperature grade ");
243 break;
244 }
245 printf("(%dC to %dC)", minc, maxc);
Ye.Lif19692c2014-11-20 21:14:14 +0800246 ret = uclass_get_device(UCLASS_THERMAL, 0, &thermal_dev);
247 if (!ret) {
248 ret = thermal_get_temp(thermal_dev, &cpu_tmp);
249
250 if (!ret)
Tim Harvey27f90592015-05-18 06:56:46 -0700251 printf(" at %dC\n", cpu_tmp);
Ye.Lif19692c2014-11-20 21:14:14 +0800252 else
Fabio Estevamf62604d2015-09-08 14:43:10 -0300253 debug(" - invalid sensor data\n");
Ye.Lif19692c2014-11-20 21:14:14 +0800254 } else {
Fabio Estevamf62604d2015-09-08 14:43:10 -0300255 debug(" - invalid sensor device\n");
Ye.Lif19692c2014-11-20 21:14:14 +0800256 }
257#endif
258
Jason Liu83aa8fe2011-11-25 00:18:01 +0000259 printf("Reset cause: %s\n", get_reset_cause());
260 return 0;
261}
262#endif
263
264int cpu_eth_init(bd_t *bis)
265{
266 int rc = -ENODEV;
267
268#if defined(CONFIG_FEC_MXC)
269 rc = fecmxc_initialize(bis);
270#endif
271
272 return rc;
273}
274
Yangbo Lu73340382019-06-21 11:42:28 +0800275#ifdef CONFIG_FSL_ESDHC_IMX
Jason Liu83aa8fe2011-11-25 00:18:01 +0000276/*
277 * Initializes on-chip MMC controllers.
278 * to override, implement board_mmc_init()
279 */
280int cpu_mmc_init(bd_t *bis)
281{
Jason Liu83aa8fe2011-11-25 00:18:01 +0000282 return fsl_esdhc_mmc_init(bis);
Jason Liu83aa8fe2011-11-25 00:18:01 +0000283}
Benoît Thébaudeau58d22322012-08-17 10:42:55 +0000284#endif
Jason Liu83aa8fe2011-11-25 00:18:01 +0000285
Peng Fan39945c12018-11-20 10:19:25 +0000286#if !(defined(CONFIG_MX7) || defined(CONFIG_IMX8M))
Fabio Estevam6479f512012-04-29 08:11:13 +0000287u32 get_ahb_clk(void)
288{
289 struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
290 u32 reg, ahb_podf;
291
292 reg = __raw_readl(&imx_ccm->cbcdr);
293 reg &= MXC_CCM_CBCDR_AHB_PODF_MASK;
294 ahb_podf = reg >> MXC_CCM_CBCDR_AHB_PODF_OFFSET;
295
296 return get_periph_clk() / (ahb_podf + 1);
297}
Adrian Alonso9f883e02015-09-02 13:54:23 -0500298#endif
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000299
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000300void arch_preboot_os(void)
301{
Marek Vasut81647a32019-06-09 03:50:51 +0200302#if defined(CONFIG_PCIE_IMX) && !CONFIG_IS_ENABLED(DM_PCI)
Tim Harveyc22f2ea2017-05-12 12:58:41 -0700303 imx_pcie_remove();
304#endif
Simon Glassab3055a2017-06-14 21:28:25 -0600305#if defined(CONFIG_SATA)
Ludwig Zenzeb15ce22019-07-02 15:10:52 +0200306 if (!is_mx6sdl()) {
307 sata_remove(0);
Soeren Mocha517d022014-11-27 10:11:41 +0100308#if defined(CONFIG_MX6)
Ludwig Zenzeb15ce22019-07-02 15:10:52 +0200309 disable_sata_clock();
Soeren Mocha517d022014-11-27 10:11:41 +0100310#endif
Ludwig Zenzeb15ce22019-07-02 15:10:52 +0200311 }
Nikita Kiryanovb5c9ed32014-11-21 12:47:26 +0200312#endif
313#if defined(CONFIG_VIDEO_IPUV3)
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000314 /* disable video before launching O/S */
315 ipuv3_fb_shutdown();
Eric Nelson54b3f3b2012-09-23 07:30:55 +0000316#endif
Igor Opaniukf5abe402019-06-04 00:05:59 +0300317#if defined(CONFIG_VIDEO_MXS) && !defined(CONFIG_DM_VIDEO)
Peng Fanf2c39922015-10-29 15:54:51 +0800318 lcdif_power_down();
319#endif
Nikita Kiryanovb5c9ed32014-11-21 12:47:26 +0200320}
Fabio Estevam16e65f62014-11-14 11:27:21 -0200321
Peng Fan39945c12018-11-20 10:19:25 +0000322#ifndef CONFIG_IMX8M
Fabio Estevam16e65f62014-11-14 11:27:21 -0200323void set_chipselect_size(int const cs_size)
324{
325 unsigned int reg;
326 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
327 reg = readl(&iomuxc_regs->gpr[1]);
328
329 switch (cs_size) {
330 case CS0_128:
331 reg &= ~0x7; /* CS0=128MB, CS1=0, CS2=0, CS3=0 */
332 reg |= 0x5;
333 break;
334 case CS0_64M_CS1_64M:
335 reg &= ~0x3F; /* CS0=64MB, CS1=64MB, CS2=0, CS3=0 */
336 reg |= 0x1B;
337 break;
338 case CS0_64M_CS1_32M_CS2_32M:
339 reg &= ~0x1FF; /* CS0=64MB, CS1=32MB, CS2=32MB, CS3=0 */
340 reg |= 0x4B;
341 break;
342 case CS0_32M_CS1_32M_CS2_32M_CS3_32M:
343 reg &= ~0xFFF; /* CS0=32MB, CS1=32MB, CS2=32MB, CS3=32MB */
344 reg |= 0x249;
345 break;
346 default:
347 printf("Unknown chip select size: %d\n", cs_size);
348 break;
349 }
350
351 writel(reg, &iomuxc_regs->gpr[1]);
352}
Peng Fana78e0ac2018-01-10 13:20:25 +0800353#endif
Fabio Estevam49bcdd72017-11-27 10:25:09 -0200354
Peng Fan39945c12018-11-20 10:19:25 +0000355#if defined(CONFIG_MX7) || defined(CONFIG_IMX8M)
Peng Fan7753bc72018-01-10 13:20:29 +0800356/*
357 * OCOTP_TESTER3[9:8] (see Fusemap Description Table offset 0x440)
358 * defines a 2-bit SPEED_GRADING
359 */
360#define OCOTP_TESTER3_SPEED_SHIFT 8
Peng Fana12bf3c2018-01-10 13:20:30 +0800361enum cpu_speed {
362 OCOTP_TESTER3_SPEED_GRADE0,
363 OCOTP_TESTER3_SPEED_GRADE1,
364 OCOTP_TESTER3_SPEED_GRADE2,
365 OCOTP_TESTER3_SPEED_GRADE3,
366};
Peng Fan7753bc72018-01-10 13:20:29 +0800367
368u32 get_cpu_speed_grade_hz(void)
369{
370 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
371 struct fuse_bank *bank = &ocotp->bank[1];
372 struct fuse_bank1_regs *fuse =
373 (struct fuse_bank1_regs *)bank->fuse_regs;
374 uint32_t val;
375
376 val = readl(&fuse->tester3);
377 val >>= OCOTP_TESTER3_SPEED_SHIFT;
378 val &= 0x3;
379
380 switch(val) {
Peng Fana12bf3c2018-01-10 13:20:30 +0800381 case OCOTP_TESTER3_SPEED_GRADE0:
Peng Fan7753bc72018-01-10 13:20:29 +0800382 return 800000000;
Peng Fana12bf3c2018-01-10 13:20:30 +0800383 case OCOTP_TESTER3_SPEED_GRADE1:
384 return is_mx7() ? 500000000 : 1000000000;
385 case OCOTP_TESTER3_SPEED_GRADE2:
386 return is_mx7() ? 1000000000 : 1300000000;
387 case OCOTP_TESTER3_SPEED_GRADE3:
388 return is_mx7() ? 1200000000 : 1500000000;
Peng Fan7753bc72018-01-10 13:20:29 +0800389 }
Peng Fana12bf3c2018-01-10 13:20:30 +0800390
Peng Fan7753bc72018-01-10 13:20:29 +0800391 return 0;
392}
393
394/*
395 * OCOTP_TESTER3[7:6] (see Fusemap Description Table offset 0x440)
396 * defines a 2-bit SPEED_GRADING
397 */
398#define OCOTP_TESTER3_TEMP_SHIFT 6
399
400u32 get_cpu_temp_grade(int *minc, int *maxc)
401{
402 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
403 struct fuse_bank *bank = &ocotp->bank[1];
404 struct fuse_bank1_regs *fuse =
405 (struct fuse_bank1_regs *)bank->fuse_regs;
406 uint32_t val;
407
408 val = readl(&fuse->tester3);
409 val >>= OCOTP_TESTER3_TEMP_SHIFT;
410 val &= 0x3;
411
412 if (minc && maxc) {
413 if (val == TEMP_AUTOMOTIVE) {
414 *minc = -40;
415 *maxc = 125;
416 } else if (val == TEMP_INDUSTRIAL) {
417 *minc = -40;
418 *maxc = 105;
419 } else if (val == TEMP_EXTCOMMERCIAL) {
420 *minc = -20;
421 *maxc = 105;
422 } else {
423 *minc = 0;
424 *maxc = 95;
425 }
426 }
427 return val;
428}
429#endif
430
Peng Fan39945c12018-11-20 10:19:25 +0000431#if defined(CONFIG_MX7) || defined(CONFIG_IMX8M)
Peng Fand64a3c52018-01-10 13:20:34 +0800432enum boot_device get_boot_device(void)
433{
434 struct bootrom_sw_info **p =
435 (struct bootrom_sw_info **)(ulong)ROM_SW_INFO_ADDR;
436
437 enum boot_device boot_dev = SD1_BOOT;
438 u8 boot_type = (*p)->boot_dev_type;
439 u8 boot_instance = (*p)->boot_dev_instance;
440
441 switch (boot_type) {
442 case BOOT_TYPE_SD:
443 boot_dev = boot_instance + SD1_BOOT;
444 break;
445 case BOOT_TYPE_MMC:
446 boot_dev = boot_instance + MMC1_BOOT;
447 break;
448 case BOOT_TYPE_NAND:
449 boot_dev = NAND_BOOT;
450 break;
451 case BOOT_TYPE_QSPI:
452 boot_dev = QSPI_BOOT;
453 break;
454 case BOOT_TYPE_WEIM:
455 boot_dev = WEIM_NOR_BOOT;
456 break;
457 case BOOT_TYPE_SPINOR:
458 boot_dev = SPI_NOR_BOOT;
459 break;
Peng Fan39945c12018-11-20 10:19:25 +0000460#ifdef CONFIG_IMX8M
Peng Fan24d3fbc2018-01-10 13:20:35 +0800461 case BOOT_TYPE_USB:
462 boot_dev = USB_BOOT;
463 break;
464#endif
Peng Fand64a3c52018-01-10 13:20:34 +0800465 default:
466 break;
467 }
468
469 return boot_dev;
470}
471#endif
472
Fabio Estevam49bcdd72017-11-27 10:25:09 -0200473#ifdef CONFIG_NXP_BOARD_REVISION
474int nxp_board_rev(void)
475{
476 /*
477 * Get Board ID information from OCOTP_GP1[15:8]
478 * RevA: 0x1
479 * RevB: 0x2
480 * RevC: 0x3
481 */
482 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
483 struct fuse_bank *bank = &ocotp->bank[4];
484 struct fuse_bank4_regs *fuse =
485 (struct fuse_bank4_regs *)bank->fuse_regs;
486
487 return (readl(&fuse->gp1) >> 8 & 0x0F);
488}
489
490char nxp_board_rev_string(void)
491{
492 const char *rev = "A";
493
494 return (*rev + nxp_board_rev() - 1);
495}
496#endif