blob: 4df5f9c164169e2f8ecba358cc26c9fec9855342 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefano Babica521a772010-01-20 18:19:32 +01002/*
3 * (C) Copyright 2007
4 * Sascha Hauer, Pengutronix
5 *
6 * (C) Copyright 2009 Freescale Semiconductor, Inc.
Stefano Babica521a772010-01-20 18:19:32 +01007 */
8
Simon Glass1d91ba72019-11-14 12:57:37 -07009#include <cpu_func.h>
Stefano Babica521a772010-01-20 18:19:32 +010010#include <asm/arch/imx-regs.h>
Stefano Babicac41d4d2010-03-05 17:54:37 +010011#include <asm/arch/clock.h>
Fabio Estevamf231efb2011-10-13 05:34:59 +000012#include <asm/arch/sys_proto.h>
Simon Glass274e0b02020-05-10 11:39:56 -060013#include <asm/cache.h>
Fabio Estevamf231efb2011-10-13 05:34:59 +000014
Masahiro Yamada56a931c2016-09-21 11:28:55 +090015#include <linux/errno.h>
Stefano Babica521a772010-01-20 18:19:32 +010016#include <asm/io.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020017#include <asm/mach-imx/boot_mode.h>
Stefano Babica521a772010-01-20 18:19:32 +010018
Liu Hui-R64343baa2d782011-01-03 22:27:35 +000019#if !(defined(CONFIG_MX51) || defined(CONFIG_MX53))
Jason Liue7a7ed22010-10-18 11:09:26 +080020#error "CPU_TYPE not defined"
21#endif
22
Stefano Babica521a772010-01-20 18:19:32 +010023u32 get_cpu_rev(void)
24{
Liu Hui-R64343baa2d782011-01-03 22:27:35 +000025#ifdef CONFIG_MX51
26 int system_rev = 0x51000;
27#else
28 int system_rev = 0x53000;
29#endif
Jason Liue7a7ed22010-10-18 11:09:26 +080030 int reg = __raw_readl(ROM_SI_REV);
Stefano Babica521a772010-01-20 18:19:32 +010031
Liu Hui-R64343baa2d782011-01-03 22:27:35 +000032#if defined(CONFIG_MX51)
Stefano Babica521a772010-01-20 18:19:32 +010033 switch (reg) {
34 case 0x02:
Jason Liue7a7ed22010-10-18 11:09:26 +080035 system_rev |= CHIP_REV_1_1;
Stefano Babica521a772010-01-20 18:19:32 +010036 break;
37 case 0x10:
38 if ((__raw_readl(GPIO1_BASE_ADDR + 0x0) & (0x1 << 22)) == 0)
Jason Liue7a7ed22010-10-18 11:09:26 +080039 system_rev |= CHIP_REV_2_5;
Stefano Babica521a772010-01-20 18:19:32 +010040 else
Jason Liue7a7ed22010-10-18 11:09:26 +080041 system_rev |= CHIP_REV_2_0;
Stefano Babica521a772010-01-20 18:19:32 +010042 break;
43 case 0x20:
Jason Liue7a7ed22010-10-18 11:09:26 +080044 system_rev |= CHIP_REV_3_0;
Stefano Babica521a772010-01-20 18:19:32 +010045 break;
Liu Hui-R64343baa2d782011-01-03 22:27:35 +000046 default:
47 system_rev |= CHIP_REV_1_0;
48 break;
49 }
50#else
Fabio Estevam000f4d02011-04-26 10:50:15 +000051 if (reg < 0x20)
Jason Liue7a7ed22010-10-18 11:09:26 +080052 system_rev |= CHIP_REV_1_0;
Fabio Estevam000f4d02011-04-26 10:50:15 +000053 else
54 system_rev |= reg;
Liu Hui-R64343baa2d782011-01-03 22:27:35 +000055#endif
Stefano Babica521a772010-01-20 18:19:32 +010056 return system_rev;
57}
58
Fabio Estevame993b0d2013-04-24 14:44:25 +000059#ifdef CONFIG_REVISION_TAG
60u32 __weak get_board_rev(void)
61{
62 return get_cpu_rev();
63}
64#endif
65
Trevor Woerner43ec7e02019-05-03 09:41:00 -040066#if !CONFIG_IS_ENABLED(SYS_DCACHE_OFF)
Benoît Thébaudeaub8aaed32012-08-14 03:17:52 +000067void enable_caches(void)
68{
69 /* Enable D-cache. I-cache is already enabled in start.S */
70 dcache_enable();
71}
72#endif
73
Stefano Babica521a772010-01-20 18:19:32 +010074#if defined(CONFIG_FEC_MXC)
Jason Liuce0e55e2012-01-31 02:07:29 +000075void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
Liu Hui-R643434df66192010-11-18 23:45:55 +000076{
77 int i;
78 struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
79 struct fuse_bank *bank = &iim->bank[1];
80 struct fuse_bank1_regs *fuse =
81 (struct fuse_bank1_regs *)bank->fuse_regs;
82
83 for (i = 0; i < 6; i++)
84 mac[i] = readl(&fuse->mac_addr[i]) & 0xff;
85}
86#endif
Stefano Babica521a772010-01-20 18:19:32 +010087
Troy Kisky0ca618c2012-08-15 10:31:20 +000088#ifdef CONFIG_MX53
Marek Vasut96215c92020-09-05 00:53:01 +020089#define IMX53_SRTC_LPGR_PERSIST_SECONDARY_BOOT BIT(30)
90
Troy Kisky0ca618c2012-08-15 10:31:20 +000091void boot_mode_apply(unsigned cfg_val)
92{
Marek Vasut96215c92020-09-05 00:53:01 +020093 void *lpgr = &((struct srtc_regs *)SRTC_BASE_ADDR)->lpgr;
94
95 if (cfg_val == MAKE_CFGVAL_PRIMARY_BOOT)
96 clrbits_le32(lpgr, IMX53_SRTC_LPGR_PERSIST_SECONDARY_BOOT);
97 else if (cfg_val == MAKE_CFGVAL_SECONDARY_BOOT)
98 setbits_le32(lpgr, IMX53_SRTC_LPGR_PERSIST_SECONDARY_BOOT);
99 else
100 writel(cfg_val, lpgr);
Troy Kisky0ca618c2012-08-15 10:31:20 +0000101}
Marek Vasut96215c92020-09-05 00:53:01 +0200102
103int boot_mode_getprisec(void)
104{
105 void *lpgr = &((struct srtc_regs *)SRTC_BASE_ADDR)->lpgr;
106
107 return !!(readl(lpgr) & IMX53_SRTC_LPGR_PERSIST_SECONDARY_BOOT);
108}
109
Troy Kisky0ca618c2012-08-15 10:31:20 +0000110/*
111 * cfg_val will be used for
112 * Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
113 *
114 * If bit 28 of LPGR is set upon watchdog reset,
115 * bits[25:0] of LPGR will move to SBMR.
116 */
117const struct boot_mode soc_boot_modes[] = {
118 {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)},
119 /* usb or serial download */
120 {"usb", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x13)},
121 {"sata", MAKE_CFGVAL(0x28, 0x00, 0x00, 0x12)},
122 {"escpi1:0", MAKE_CFGVAL(0x38, 0x20, 0x00, 0x12)},
123 {"escpi1:1", MAKE_CFGVAL(0x38, 0x20, 0x04, 0x12)},
124 {"escpi1:2", MAKE_CFGVAL(0x38, 0x20, 0x08, 0x12)},
125 {"escpi1:3", MAKE_CFGVAL(0x38, 0x20, 0x0c, 0x12)},
126 /* 4 bit bus width */
127 {"esdhc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x12)},
128 {"esdhc2", MAKE_CFGVAL(0x40, 0x20, 0x08, 0x12)},
129 {"esdhc3", MAKE_CFGVAL(0x40, 0x20, 0x10, 0x12)},
130 {"esdhc4", MAKE_CFGVAL(0x40, 0x20, 0x18, 0x12)},
Marek Vasut96215c92020-09-05 00:53:01 +0200131 {"primary", MAKE_CFGVAL_PRIMARY_BOOT},
132 {"secondary", MAKE_CFGVAL_SECONDARY_BOOT},
Troy Kisky0ca618c2012-08-15 10:31:20 +0000133 {NULL, 0},
134};
135#endif