blob: a6ab551a4a74d9806894ff0c8b587eeb740cd1c8 [file] [log] [blame]
Adrian Alonsoc5752f72015-09-02 13:54:19 -05001/*
2 * Copyright (C) 2015 Freescale Semiconductor, Inc.
3 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <asm/io.h>
9#include <asm/arch/imx-regs.h>
10#include <asm/arch/clock.h>
11#include <asm/arch/sys_proto.h>
12#include <asm/imx-common/boot_mode.h>
13#include <asm/imx-common/dma.h>
Adrian Alonsobb955142015-10-12 13:48:13 -050014#include <asm/imx-common/hab.h>
Adrian Alonsoc5752f72015-09-02 13:54:19 -050015#include <asm/arch/crm_regs.h>
16#include <dm.h>
17#include <imx_thermal.h>
18
Adrian Alonsoc5752f72015-09-02 13:54:19 -050019#if defined(CONFIG_IMX_THERMAL)
20static const struct imx_thermal_plat imx7_thermal_plat = {
21 .regs = (void *)ANATOP_BASE_ADDR,
22 .fuse_bank = 3,
23 .fuse_word = 3,
24};
25
26U_BOOT_DEVICE(imx7_thermal) = {
27 .name = "imx_thermal",
28 .platdata = &imx7_thermal_plat,
29};
30#endif
31
Adrian Alonsobb955142015-10-12 13:48:13 -050032#if defined(CONFIG_SECURE_BOOT)
33struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
34 .bank = 1,
35 .word = 3,
36};
37#endif
38
Adrian Alonsoc5752f72015-09-02 13:54:19 -050039/*
40 * OCOTP_TESTER3[9:8] (see Fusemap Description Table offset 0x440)
41 * defines a 2-bit SPEED_GRADING
42 */
43#define OCOTP_TESTER3_SPEED_SHIFT 8
44#define OCOTP_TESTER3_SPEED_800MHZ 0
45#define OCOTP_TESTER3_SPEED_850MHZ 1
46#define OCOTP_TESTER3_SPEED_1GHZ 2
47
48u32 get_cpu_speed_grade_hz(void)
49{
50 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
51 struct fuse_bank *bank = &ocotp->bank[1];
52 struct fuse_bank1_regs *fuse =
53 (struct fuse_bank1_regs *)bank->fuse_regs;
54 uint32_t val;
55
56 val = readl(&fuse->tester3);
57 val >>= OCOTP_TESTER3_SPEED_SHIFT;
58 val &= 0x3;
59
60 switch(val) {
61 case OCOTP_TESTER3_SPEED_800MHZ:
62 return 792000000;
63 case OCOTP_TESTER3_SPEED_850MHZ:
64 return 852000000;
65 case OCOTP_TESTER3_SPEED_1GHZ:
66 return 996000000;
67 }
68 return 0;
69}
70
71/*
72 * OCOTP_TESTER3[7:6] (see Fusemap Description Table offset 0x440)
73 * defines a 2-bit SPEED_GRADING
74 */
75#define OCOTP_TESTER3_TEMP_SHIFT 6
76
77u32 get_cpu_temp_grade(int *minc, int *maxc)
78{
79 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
80 struct fuse_bank *bank = &ocotp->bank[1];
81 struct fuse_bank1_regs *fuse =
82 (struct fuse_bank1_regs *)bank->fuse_regs;
83 uint32_t val;
84
85 val = readl(&fuse->tester3);
86 val >>= OCOTP_TESTER3_TEMP_SHIFT;
87 val &= 0x3;
88
89 if (minc && maxc) {
Peng Fanf697c2a2015-09-15 14:05:08 +080090 if (val == TEMP_AUTOMOTIVE) {
Adrian Alonsoc5752f72015-09-02 13:54:19 -050091 *minc = -40;
92 *maxc = 125;
93 } else if (val == TEMP_INDUSTRIAL) {
94 *minc = -40;
95 *maxc = 105;
96 } else if (val == TEMP_EXTCOMMERCIAL) {
97 *minc = -20;
98 *maxc = 105;
99 } else {
100 *minc = 0;
101 *maxc = 95;
102 }
103 }
104 return val;
105}
106
107u32 get_cpu_rev(void)
108{
109 struct mxc_ccm_anatop_reg *ccm_anatop = (struct mxc_ccm_anatop_reg *)
110 ANATOP_BASE_ADDR;
111 u32 reg = readl(&ccm_anatop->digprog);
112 u32 type = (reg >> 16) & 0xff;
113
114 reg &= 0xff;
115 return (type << 12) | reg;
116}
117
118#ifdef CONFIG_REVISION_TAG
119u32 __weak get_board_rev(void)
120{
121 return get_cpu_rev();
122}
123#endif
124
Peng Fan7de47032015-10-23 10:13:04 +0800125/* enable all periherial can be accessed in nosec mode */
126static void init_csu(void)
127{
128 int i = 0;
129 for (i = 0; i < CSU_NUM_REGS; i++)
130 writel(CSU_INIT_SEC_LEVEL0, CSU_IPS_BASE_ADDR + i * 4);
131}
132
Peng Fand9699de2016-01-04 13:16:41 +0800133static void imx_enet_mdio_fixup(void)
134{
135 struct iomuxc_gpr_base_regs *gpr_regs =
136 (struct iomuxc_gpr_base_regs *)IOMUXC_GPR_BASE_ADDR;
137
138 /*
139 * The management data input/output (MDIO) requires open-drain,
140 * i.MX7D TO1.0 ENET MDIO pin has no open drain, but TO1.1 supports
141 * this feature. So to TO1.1, need to enable open drain by setting
142 * bits GPR0[8:7].
143 */
144
145 if (soc_rev() >= CHIP_REV_1_1) {
146 setbits_le32(&gpr_regs->gpr[0],
147 IOMUXC_GPR_GPR0_ENET_MDIO_OPEN_DRAIN_MASK);
148 }
149}
150
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500151int arch_cpu_init(void)
152{
153 init_aips();
154
Peng Fan7de47032015-10-23 10:13:04 +0800155 init_csu();
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500156 /* Disable PDE bit of WMCR register */
157 imx_set_wdog_powerdown(false);
158
Peng Fand9699de2016-01-04 13:16:41 +0800159 imx_enet_mdio_fixup();
160
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500161#ifdef CONFIG_APBH_DMA
162 /* Start APBH DMA */
163 mxs_dma_init();
164#endif
165
166 return 0;
167}
168
169#ifdef CONFIG_SERIAL_TAG
170void get_board_serial(struct tag_serialnr *serialnr)
171{
172 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
173 struct fuse_bank *bank = &ocotp->bank[0];
174 struct fuse_bank0_regs *fuse =
175 (struct fuse_bank0_regs *)bank->fuse_regs;
176
177 serialnr->low = fuse->tester0;
178 serialnr->high = fuse->tester1;
179}
180#endif
181
182#if defined(CONFIG_FEC_MXC)
183void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
184{
185 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
186 struct fuse_bank *bank = &ocotp->bank[9];
187 struct fuse_bank9_regs *fuse =
188 (struct fuse_bank9_regs *)bank->fuse_regs;
189
190 if (0 == dev_id) {
191 u32 value = readl(&fuse->mac_addr1);
192 mac[0] = (value >> 8);
193 mac[1] = value;
194
195 value = readl(&fuse->mac_addr0);
196 mac[2] = value >> 24;
197 mac[3] = value >> 16;
198 mac[4] = value >> 8;
199 mac[5] = value;
200 } else {
201 u32 value = readl(&fuse->mac_addr2);
202 mac[0] = value >> 24;
203 mac[1] = value >> 16;
204 mac[2] = value >> 8;
205 mac[3] = value;
206
207 value = readl(&fuse->mac_addr1);
208 mac[4] = value >> 24;
209 mac[5] = value >> 16;
210 }
211}
212#endif
213
214void set_wdog_reset(struct wdog_regs *wdog)
215{
216 u32 reg = readw(&wdog->wcr);
217 /*
218 * Output WDOG_B signal to reset external pmic or POR_B decided by
219 * the board desgin. Without external reset, the peripherals/DDR/
220 * PMIC are not reset, that may cause system working abnormal.
221 */
222 reg = readw(&wdog->wcr);
223 reg |= 1 << 3;
224 /*
225 * WDZST bit is write-once only bit. Align this bit in kernel,
226 * otherwise kernel code will have no chance to set this bit.
227 */
228 reg |= 1 << 0;
229 writew(reg, &wdog->wcr);
230}
231
232/*
233 * cfg_val will be used for
234 * Boot_cfg4[7:0]:Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
235 * After reset, if GPR10[28] is 1, ROM will copy GPR9[25:0]
236 * to SBMR1, which will determine the boot device.
237 */
238const struct boot_mode soc_boot_modes[] = {
239 {"ecspi1:0", MAKE_CFGVAL(0x00, 0x60, 0x00, 0x00)},
240 {"ecspi1:1", MAKE_CFGVAL(0x40, 0x62, 0x00, 0x00)},
241 {"ecspi1:2", MAKE_CFGVAL(0x80, 0x64, 0x00, 0x00)},
242 {"ecspi1:3", MAKE_CFGVAL(0xc0, 0x66, 0x00, 0x00)},
243
244 {"weim", MAKE_CFGVAL(0x00, 0x50, 0x00, 0x00)},
245 {"qspi1", MAKE_CFGVAL(0x10, 0x40, 0x00, 0x00)},
246 /* 4 bit bus width */
247 {"usdhc1", MAKE_CFGVAL(0x10, 0x10, 0x00, 0x00)},
248 {"usdhc2", MAKE_CFGVAL(0x10, 0x14, 0x00, 0x00)},
249 {"usdhc3", MAKE_CFGVAL(0x10, 0x18, 0x00, 0x00)},
250 {"mmc1", MAKE_CFGVAL(0x10, 0x20, 0x00, 0x00)},
251 {"mmc2", MAKE_CFGVAL(0x10, 0x24, 0x00, 0x00)},
252 {"mmc3", MAKE_CFGVAL(0x10, 0x28, 0x00, 0x00)},
253 {NULL, 0},
254};
255
256enum boot_device get_boot_device(void)
257{
258 struct bootrom_sw_info **p =
259 (struct bootrom_sw_info **)ROM_SW_INFO_ADDR;
260
261 enum boot_device boot_dev = SD1_BOOT;
262 u8 boot_type = (*p)->boot_dev_type;
263 u8 boot_instance = (*p)->boot_dev_instance;
264
265 switch (boot_type) {
266 case BOOT_TYPE_SD:
267 boot_dev = boot_instance + SD1_BOOT;
268 break;
269 case BOOT_TYPE_MMC:
270 boot_dev = boot_instance + MMC1_BOOT;
271 break;
272 case BOOT_TYPE_NAND:
273 boot_dev = NAND_BOOT;
274 break;
275 case BOOT_TYPE_QSPI:
276 boot_dev = QSPI_BOOT;
277 break;
278 case BOOT_TYPE_WEIM:
279 boot_dev = WEIM_NOR_BOOT;
280 break;
281 case BOOT_TYPE_SPINOR:
282 boot_dev = SPI_NOR_BOOT;
283 break;
284 default:
285 break;
286 }
287
288 return boot_dev;
289}
290
Peng Fan62d8cce2016-01-28 16:51:25 +0800291#ifdef CONFIG_ENV_IS_IN_MMC
292__weak int board_mmc_get_env_dev(int devno)
293{
294 return CONFIG_SYS_MMC_ENV_DEV;
295}
296
297int mmc_get_env_dev(void)
298{
299 struct bootrom_sw_info **p =
300 (struct bootrom_sw_info **)ROM_SW_INFO_ADDR;
301 int devno = (*p)->boot_dev_instance;
302 u8 boot_type = (*p)->boot_dev_type;
303
304 /* If not boot from sd/mmc, use default value */
305 if ((boot_type != BOOT_TYPE_SD) && (boot_type != BOOT_TYPE_MMC))
306 return CONFIG_SYS_MMC_ENV_DEV;
307
308 return board_mmc_get_env_dev(devno);
309}
310#endif
311
Adrian Alonsoc5752f72015-09-02 13:54:19 -0500312void s_init(void)
313{
314#if !defined CONFIG_SPL_BUILD
315 /* Enable SMP mode for CPU0, by setting bit 6 of Auxiliary Ctl reg */
316 asm volatile(
317 "mrc p15, 0, r0, c1, c0, 1\n"
318 "orr r0, r0, #1 << 6\n"
319 "mcr p15, 0, r0, c1, c0, 1\n");
320#endif
321 /* clock configuration. */
322 clock_init();
323
324 return;
325}