1 // SPDX-License-Identifier: GPL-2.0+
4 * Sascha Hauer, Pengutronix
6 * (C) Copyright 2009 Freescale Semiconductor, Inc.
12 #include <linux/errno.h>
14 #include <asm/arch/imx-regs.h>
15 #include <asm/arch/clock.h>
16 #include <asm/arch/sys_proto.h>
17 #include <asm/arch/crm_regs.h>
18 #include <asm/mach-imx/boot_mode.h>
19 #include <imx_thermal.h>
20 #include <ipu_pixfmt.h>
24 #ifdef CONFIG_FSL_ESDHC_IMX
25 #include <fsl_esdhc_imx.h>
28 static u32 reset_cause = -1;
30 u32 get_imx_reset_cause(void)
32 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
34 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);
45 #if defined(CONFIG_DISPLAY_CPUINFO) && !defined(CONFIG_SPL_BUILD)
46 static char *get_reset_cause(void)
48 switch (get_imx_reset_cause()) {
73 #elif defined(CONFIG_IMX8M)
85 return "unknown reset";
90 #if defined(CONFIG_DISPLAY_CPUINFO) && !defined(CONFIG_SPL_BUILD)
92 const char *get_imx_type(u32 imxtype)
96 return "8MMQ"; /* Quad-core version of the imx8mm */
98 return "8MMQL"; /* Quad-core Lite version of the imx8mm */
100 return "8MMD"; /* Dual-core version of the imx8mm */
101 case MXC_CPU_IMX8MMDL:
102 return "8MMDL"; /* Dual-core Lite version of the imx8mm */
103 case MXC_CPU_IMX8MMS:
104 return "8MMS"; /* Single-core version of the imx8mm */
105 case MXC_CPU_IMX8MMSL:
106 return "8MMSL"; /* Single-core Lite version of the imx8mm */
108 return "8MQ"; /* Quad-core version of the imx8m */
110 return "7S"; /* Single-core version of the mx7 */
112 return "7D"; /* Dual-core version of the mx7 */
114 return "6QP"; /* Quad-Plus version of the mx6 */
116 return "6DP"; /* Dual-Plus version of the mx6 */
118 return "6Q"; /* Quad-core version of the mx6 */
120 return "6D"; /* Dual-core version of the mx6 */
122 return "6DL"; /* Dual Lite version of the mx6 */
123 case MXC_CPU_MX6SOLO:
124 return "6SOLO"; /* Solo version of the mx6 */
126 return "6SL"; /* Solo-Lite version of the mx6 */
128 return "6SLL"; /* SLL version of the mx6 */
130 return "6SX"; /* SoloX version of the mx6 */
132 return "6UL"; /* Ultra-Lite version of the mx6 */
134 return "6ULL"; /* ULL version of the mx6 */
136 return "6ULZ"; /* ULZ version of the mx6 */
146 int print_cpuinfo(void)
149 __maybe_unused u32 max_freq;
151 cpurev = get_cpu_rev();
153 #if defined(CONFIG_IMX_THERMAL)
154 struct udevice *thermal_dev;
155 int cpu_tmp, minc, maxc, ret;
157 printf("CPU: Freescale i.MX%s rev%d.%d",
158 get_imx_type((cpurev & 0xFF000) >> 12),
159 (cpurev & 0x000F0) >> 4,
160 (cpurev & 0x0000F) >> 0);
161 max_freq = get_cpu_speed_grade_hz();
162 if (!max_freq || max_freq == mxc_get_clock(MXC_ARM_CLK)) {
163 printf(" at %dMHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
165 printf(" %d MHz (running at %d MHz)\n", max_freq / 1000000,
166 mxc_get_clock(MXC_ARM_CLK) / 1000000);
169 printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n",
170 get_imx_type((cpurev & 0xFF000) >> 12),
171 (cpurev & 0x000F0) >> 4,
172 (cpurev & 0x0000F) >> 0,
173 mxc_get_clock(MXC_ARM_CLK) / 1000000);
176 #if defined(CONFIG_IMX_THERMAL)
178 switch (get_cpu_temp_grade(&minc, &maxc)) {
179 case TEMP_AUTOMOTIVE:
180 puts("Automotive temperature grade ");
182 case TEMP_INDUSTRIAL:
183 puts("Industrial temperature grade ");
185 case TEMP_EXTCOMMERCIAL:
186 puts("Extended Commercial temperature grade ");
189 puts("Commercial temperature grade ");
192 printf("(%dC to %dC)", minc, maxc);
193 ret = uclass_get_device(UCLASS_THERMAL, 0, &thermal_dev);
195 ret = thermal_get_temp(thermal_dev, &cpu_tmp);
198 printf(" at %dC\n", cpu_tmp);
200 debug(" - invalid sensor data\n");
202 debug(" - invalid sensor device\n");
206 printf("Reset cause: %s\n", get_reset_cause());
211 int cpu_eth_init(bd_t *bis)
215 #if defined(CONFIG_FEC_MXC)
216 rc = fecmxc_initialize(bis);
222 #ifdef CONFIG_FSL_ESDHC_IMX
224 * Initializes on-chip MMC controllers.
225 * to override, implement board_mmc_init()
227 int cpu_mmc_init(bd_t *bis)
229 return fsl_esdhc_mmc_init(bis);
233 #if !(defined(CONFIG_MX7) || defined(CONFIG_IMX8M))
234 u32 get_ahb_clk(void)
236 struct mxc_ccm_reg *imx_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
239 reg = __raw_readl(&imx_ccm->cbcdr);
240 reg &= MXC_CCM_CBCDR_AHB_PODF_MASK;
241 ahb_podf = reg >> MXC_CCM_CBCDR_AHB_PODF_OFFSET;
243 return get_periph_clk() / (ahb_podf + 1);
247 void arch_preboot_os(void)
249 #if defined(CONFIG_PCIE_IMX) && !CONFIG_IS_ENABLED(DM_PCI)
252 #if defined(CONFIG_SATA)
255 #if defined(CONFIG_MX6)
256 disable_sata_clock();
260 #if defined(CONFIG_VIDEO_IPUV3)
261 /* disable video before launching O/S */
264 #if defined(CONFIG_VIDEO_MXS) && !defined(CONFIG_DM_VIDEO)
270 void set_chipselect_size(int const cs_size)
273 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
274 reg = readl(&iomuxc_regs->gpr[1]);
278 reg &= ~0x7; /* CS0=128MB, CS1=0, CS2=0, CS3=0 */
281 case CS0_64M_CS1_64M:
282 reg &= ~0x3F; /* CS0=64MB, CS1=64MB, CS2=0, CS3=0 */
285 case CS0_64M_CS1_32M_CS2_32M:
286 reg &= ~0x1FF; /* CS0=64MB, CS1=32MB, CS2=32MB, CS3=0 */
289 case CS0_32M_CS1_32M_CS2_32M_CS3_32M:
290 reg &= ~0xFFF; /* CS0=32MB, CS1=32MB, CS2=32MB, CS3=32MB */
294 printf("Unknown chip select size: %d\n", cs_size);
298 writel(reg, &iomuxc_regs->gpr[1]);
302 #if defined(CONFIG_MX7) || defined(CONFIG_IMX8M)
304 * OCOTP_TESTER3[9:8] (see Fusemap Description Table offset 0x440)
305 * defines a 2-bit SPEED_GRADING
307 #define OCOTP_TESTER3_SPEED_SHIFT 8
309 OCOTP_TESTER3_SPEED_GRADE0,
310 OCOTP_TESTER3_SPEED_GRADE1,
311 OCOTP_TESTER3_SPEED_GRADE2,
312 OCOTP_TESTER3_SPEED_GRADE3,
315 u32 get_cpu_speed_grade_hz(void)
317 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
318 struct fuse_bank *bank = &ocotp->bank[1];
319 struct fuse_bank1_regs *fuse =
320 (struct fuse_bank1_regs *)bank->fuse_regs;
323 val = readl(&fuse->tester3);
324 val >>= OCOTP_TESTER3_SPEED_SHIFT;
328 case OCOTP_TESTER3_SPEED_GRADE0:
330 case OCOTP_TESTER3_SPEED_GRADE1:
331 return is_mx7() ? 500000000 : 1000000000;
332 case OCOTP_TESTER3_SPEED_GRADE2:
333 return is_mx7() ? 1000000000 : 1300000000;
334 case OCOTP_TESTER3_SPEED_GRADE3:
335 return is_mx7() ? 1200000000 : 1500000000;
342 * OCOTP_TESTER3[7:6] (see Fusemap Description Table offset 0x440)
343 * defines a 2-bit SPEED_GRADING
345 #define OCOTP_TESTER3_TEMP_SHIFT 6
347 u32 get_cpu_temp_grade(int *minc, int *maxc)
349 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
350 struct fuse_bank *bank = &ocotp->bank[1];
351 struct fuse_bank1_regs *fuse =
352 (struct fuse_bank1_regs *)bank->fuse_regs;
355 val = readl(&fuse->tester3);
356 val >>= OCOTP_TESTER3_TEMP_SHIFT;
360 if (val == TEMP_AUTOMOTIVE) {
363 } else if (val == TEMP_INDUSTRIAL) {
366 } else if (val == TEMP_EXTCOMMERCIAL) {
378 #if defined(CONFIG_MX7) || defined(CONFIG_IMX8M)
379 enum boot_device get_boot_device(void)
381 struct bootrom_sw_info **p =
382 (struct bootrom_sw_info **)(ulong)ROM_SW_INFO_ADDR;
384 enum boot_device boot_dev = SD1_BOOT;
385 u8 boot_type = (*p)->boot_dev_type;
386 u8 boot_instance = (*p)->boot_dev_instance;
390 boot_dev = boot_instance + SD1_BOOT;
393 boot_dev = boot_instance + MMC1_BOOT;
396 boot_dev = NAND_BOOT;
399 boot_dev = QSPI_BOOT;
402 boot_dev = WEIM_NOR_BOOT;
404 case BOOT_TYPE_SPINOR:
405 boot_dev = SPI_NOR_BOOT;
420 #ifdef CONFIG_NXP_BOARD_REVISION
421 int nxp_board_rev(void)
424 * Get Board ID information from OCOTP_GP1[15:8]
429 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
430 struct fuse_bank *bank = &ocotp->bank[4];
431 struct fuse_bank4_regs *fuse =
432 (struct fuse_bank4_regs *)bank->fuse_regs;
434 return (readl(&fuse->gp1) >> 8 & 0x0F);
437 char nxp_board_rev_string(void)
439 const char *rev = "A";
441 return (*rev + nxp_board_rev() - 1);