blob: b72466808c0023aab2692abd554a0078299d41b3 [file] [log] [blame]
Jason Liu23608e22011-11-25 00:18:02 +00001/*
2 * (C) Copyright 2007
3 * Sascha Hauer, Pengutronix
4 *
5 * (C) Copyright 2009 Freescale Semiconductor, Inc.
6 *
Wolfgang Denk1a459662013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Jason Liu23608e22011-11-25 00:18:02 +00008 */
9
10#include <common.h>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090011#include <linux/errno.h>
Jason Liu23608e22011-11-25 00:18:02 +000012#include <asm/io.h>
13#include <asm/arch/imx-regs.h>
14#include <asm/arch/clock.h>
15#include <asm/arch/sys_proto.h>
Stefano Babic552a8482017-06-29 10:16:06 +020016#include <asm/mach-imx/boot_mode.h>
17#include <asm/mach-imx/dma.h>
18#include <asm/mach-imx/hab.h>
Fabio Estevam76c91e62013-02-07 06:45:23 +000019#include <stdbool.h>
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -050020#include <asm/arch/mxc_hdmi.h>
21#include <asm/arch/crm_regs.h>
Ye.Li7a264162014-11-20 21:14:14 +080022#include <dm.h>
23#include <imx_thermal.h>
Soeren Moch1a43dc12016-02-04 14:41:15 +010024#include <mmc.h>
Jason Liu23608e22011-11-25 00:18:02 +000025
Fabio Estevam3d622b72013-12-26 14:51:33 -020026enum ldo_reg {
27 LDO_ARM,
28 LDO_SOC,
29 LDO_PU,
30};
31
Troy Kisky20332a02012-10-23 10:57:46 +000032struct scu_regs {
33 u32 ctrl;
34 u32 config;
35 u32 status;
36 u32 invalidate;
37 u32 fpga_rev;
38};
39
Adrian Alonso1368f992015-09-02 13:54:13 -050040#if defined(CONFIG_IMX_THERMAL)
Ye.Li7a264162014-11-20 21:14:14 +080041static const struct imx_thermal_plat imx6_thermal_plat = {
42 .regs = (void *)ANATOP_BASE_ADDR,
43 .fuse_bank = 1,
44 .fuse_word = 6,
45};
46
47U_BOOT_DEVICE(imx6_thermal) = {
48 .name = "imx_thermal",
49 .platdata = &imx6_thermal_plat,
50};
51#endif
52
Adrian Alonso6b50bfe2015-10-12 13:48:12 -050053#if defined(CONFIG_SECURE_BOOT)
54struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
55 .bank = 0,
56 .word = 6,
57};
58#endif
59
Gabriel Huaua76df702014-07-26 11:35:43 -070060u32 get_nr_cpus(void)
61{
62 struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
63 return readl(&scu->config) & 3;
64}
65
Jason Liu23608e22011-11-25 00:18:02 +000066u32 get_cpu_rev(void)
67{
Fabio Estevama7683862012-03-20 04:21:45 +000068 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Troy Kisky20332a02012-10-23 10:57:46 +000069 u32 reg = readl(&anatop->digprog_sololite);
70 u32 type = ((reg >> 16) & 0xff);
Peng Fand0acd992015-07-11 11:38:42 +080071 u32 major, cfg = 0;
Fabio Estevama7683862012-03-20 04:21:45 +000072
Troy Kisky20332a02012-10-23 10:57:46 +000073 if (type != MXC_CPU_MX6SL) {
74 reg = readl(&anatop->digprog);
Fabio Estevam94db6652014-01-26 15:06:41 -020075 struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
Peng Fand0acd992015-07-11 11:38:42 +080076 cfg = readl(&scu->config) & 3;
Troy Kisky20332a02012-10-23 10:57:46 +000077 type = ((reg >> 16) & 0xff);
78 if (type == MXC_CPU_MX6DL) {
Troy Kisky20332a02012-10-23 10:57:46 +000079 if (!cfg)
80 type = MXC_CPU_MX6SOLO;
81 }
Fabio Estevam94db6652014-01-26 15:06:41 -020082
83 if (type == MXC_CPU_MX6Q) {
84 if (cfg == 1)
85 type = MXC_CPU_MX6D;
86 }
87
Troy Kisky20332a02012-10-23 10:57:46 +000088 }
Peng Fandfd48612015-06-11 18:30:36 +080089 major = ((reg >> 8) & 0xff);
Peng Fand0acd992015-07-11 11:38:42 +080090 if ((major >= 1) &&
91 ((type == MXC_CPU_MX6Q) || (type == MXC_CPU_MX6D))) {
92 major--;
93 type = MXC_CPU_MX6QP;
94 if (cfg == 1)
95 type = MXC_CPU_MX6DP;
96 }
Troy Kisky20332a02012-10-23 10:57:46 +000097 reg &= 0xff; /* mx6 silicon revision */
Peng Fandfd48612015-06-11 18:30:36 +080098 return (type << 12) | (reg + (0x10 * (major + 1)));
Jason Liu23608e22011-11-25 00:18:02 +000099}
100
Tim Harvey9b9449c2015-05-18 07:02:24 -0700101/*
102 * OCOTP_CFG3[17:16] (see Fusemap Description Table offset 0x440)
103 * defines a 2-bit SPEED_GRADING
104 */
105#define OCOTP_CFG3_SPEED_SHIFT 16
106#define OCOTP_CFG3_SPEED_800MHZ 0
107#define OCOTP_CFG3_SPEED_850MHZ 1
108#define OCOTP_CFG3_SPEED_1GHZ 2
109#define OCOTP_CFG3_SPEED_1P2GHZ 3
110
Peng Fand15a2442016-05-03 11:13:04 +0800111/*
112 * For i.MX6UL
113 */
114#define OCOTP_CFG3_SPEED_528MHZ 1
115#define OCOTP_CFG3_SPEED_696MHZ 2
116
Sébastien Szymanski0c7c6fb2017-08-02 17:05:27 +0200117/*
118 * For i.MX6ULL
119 */
120#define OCOTP_CFG3_SPEED_792MHZ 2
121#define OCOTP_CFG3_SPEED_900MHZ 3
122
Tim Harvey9b9449c2015-05-18 07:02:24 -0700123u32 get_cpu_speed_grade_hz(void)
124{
125 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
126 struct fuse_bank *bank = &ocotp->bank[0];
127 struct fuse_bank0_regs *fuse =
128 (struct fuse_bank0_regs *)bank->fuse_regs;
129 uint32_t val;
130
131 val = readl(&fuse->cfg3);
132 val >>= OCOTP_CFG3_SPEED_SHIFT;
133 val &= 0x3;
134
Sébastien Szymanski0c7c6fb2017-08-02 17:05:27 +0200135 if (is_mx6ul()) {
Peng Fand15a2442016-05-03 11:13:04 +0800136 if (val == OCOTP_CFG3_SPEED_528MHZ)
137 return 528000000;
138 else if (val == OCOTP_CFG3_SPEED_696MHZ)
Sébastien Szymanski44e67052017-08-02 17:05:26 +0200139 return 696000000;
Peng Fand15a2442016-05-03 11:13:04 +0800140 else
141 return 0;
142 }
143
Sébastien Szymanski0c7c6fb2017-08-02 17:05:27 +0200144 if (is_mx6ull()) {
145 if (val == OCOTP_CFG3_SPEED_528MHZ)
146 return 528000000;
147 else if (val == OCOTP_CFG3_SPEED_792MHZ)
148 return 792000000;
149 else if (val == OCOTP_CFG3_SPEED_900MHZ)
150 return 900000000;
151 else
152 return 0;
153 }
154
Tim Harvey9b9449c2015-05-18 07:02:24 -0700155 switch (val) {
156 /* Valid for IMX6DQ */
157 case OCOTP_CFG3_SPEED_1P2GHZ:
Peng Fan04cb3c02016-05-23 18:35:58 +0800158 if (is_mx6dq() || is_mx6dqp())
Tim Harvey9b9449c2015-05-18 07:02:24 -0700159 return 1200000000;
160 /* Valid for IMX6SX/IMX6SDL/IMX6DQ */
161 case OCOTP_CFG3_SPEED_1GHZ:
162 return 996000000;
163 /* Valid for IMX6DQ */
164 case OCOTP_CFG3_SPEED_850MHZ:
Peng Fan04cb3c02016-05-23 18:35:58 +0800165 if (is_mx6dq() || is_mx6dqp())
Tim Harvey9b9449c2015-05-18 07:02:24 -0700166 return 852000000;
167 /* Valid for IMX6SX/IMX6SDL/IMX6DQ */
168 case OCOTP_CFG3_SPEED_800MHZ:
169 return 792000000;
170 }
171 return 0;
172}
173
Tim Harveyf0e8e892015-05-18 06:56:45 -0700174/*
175 * OCOTP_MEM0[7:6] (see Fusemap Description Table offset 0x480)
176 * defines a 2-bit Temperature Grade
177 *
Fabio Estevam65496a32017-06-22 10:50:05 -0300178 * return temperature grade and min/max temperature in Celsius
Tim Harveyf0e8e892015-05-18 06:56:45 -0700179 */
180#define OCOTP_MEM0_TEMP_SHIFT 6
181
182u32 get_cpu_temp_grade(int *minc, int *maxc)
183{
184 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
185 struct fuse_bank *bank = &ocotp->bank[1];
186 struct fuse_bank1_regs *fuse =
187 (struct fuse_bank1_regs *)bank->fuse_regs;
188 uint32_t val;
189
190 val = readl(&fuse->mem0);
191 val >>= OCOTP_MEM0_TEMP_SHIFT;
192 val &= 0x3;
193
194 if (minc && maxc) {
195 if (val == TEMP_AUTOMOTIVE) {
196 *minc = -40;
197 *maxc = 125;
198 } else if (val == TEMP_INDUSTRIAL) {
199 *minc = -40;
200 *maxc = 105;
201 } else if (val == TEMP_EXTCOMMERCIAL) {
202 *minc = -20;
203 *maxc = 105;
204 } else {
205 *minc = 0;
206 *maxc = 95;
207 }
208 }
209 return val;
210}
211
Fabio Estevam38e70072013-03-27 07:36:55 +0000212#ifdef CONFIG_REVISION_TAG
213u32 __weak get_board_rev(void)
214{
215 u32 cpurev = get_cpu_rev();
216 u32 type = ((cpurev >> 12) & 0xff);
217 if (type == MXC_CPU_MX6SOLO)
218 cpurev = (MXC_CPU_MX6DL) << 12 | (cpurev & 0xFFF);
219
Fabio Estevam94db6652014-01-26 15:06:41 -0200220 if (type == MXC_CPU_MX6D)
221 cpurev = (MXC_CPU_MX6Q) << 12 | (cpurev & 0xFFF);
222
Fabio Estevam38e70072013-03-27 07:36:55 +0000223 return cpurev;
224}
225#endif
226
Fabio Estevame113fd12013-12-26 14:51:31 -0200227static void clear_ldo_ramp(void)
228{
229 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
230 int reg;
231
232 /* ROM may modify LDO ramp up time according to fuse setting, so in
233 * order to be in the safe side we neeed to reset these settings to
234 * match the reset value: 0'b00
235 */
236 reg = readl(&anatop->ana_misc2);
237 reg &= ~(0x3f << 24);
238 writel(reg, &anatop->ana_misc2);
239}
240
Dirk Behmecac833a2012-05-02 02:12:17 +0000241/*
Fabio Estevam157f45d2014-06-13 01:42:37 -0300242 * Set the PMU_REG_CORE register
Dirk Behmecac833a2012-05-02 02:12:17 +0000243 *
Fabio Estevam157f45d2014-06-13 01:42:37 -0300244 * Set LDO_SOC/PU/ARM regulators to the specified millivolt level.
Dirk Behmecac833a2012-05-02 02:12:17 +0000245 * Possible values are from 0.725V to 1.450V in steps of
246 * 0.025V (25mV).
247 */
Fabio Estevam3d622b72013-12-26 14:51:33 -0200248static int set_ldo_voltage(enum ldo_reg ldo, u32 mv)
Dirk Behmecac833a2012-05-02 02:12:17 +0000249{
250 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Fabio Estevam39f0ac92013-12-26 14:51:34 -0200251 u32 val, step, old, reg = readl(&anatop->reg_core);
Fabio Estevam3d622b72013-12-26 14:51:33 -0200252 u8 shift;
Dirk Behmecac833a2012-05-02 02:12:17 +0000253
Peng Fan79a57b52017-08-08 16:21:35 +0800254 /* No LDO_SOC/PU/ARM */
255 if (is_mx6sll())
256 return 0;
257
Dirk Behmecac833a2012-05-02 02:12:17 +0000258 if (mv < 725)
259 val = 0x00; /* Power gated off */
260 else if (mv > 1450)
261 val = 0x1F; /* Power FET switched full on. No regulation */
262 else
263 val = (mv - 700) / 25;
264
Fabio Estevame113fd12013-12-26 14:51:31 -0200265 clear_ldo_ramp();
266
Fabio Estevam3d622b72013-12-26 14:51:33 -0200267 switch (ldo) {
268 case LDO_SOC:
269 shift = 18;
270 break;
271 case LDO_PU:
272 shift = 9;
273 break;
274 case LDO_ARM:
275 shift = 0;
276 break;
277 default:
278 return -EINVAL;
279 }
280
Fabio Estevam39f0ac92013-12-26 14:51:34 -0200281 old = (reg & (0x1F << shift)) >> shift;
282 step = abs(val - old);
283 if (step == 0)
284 return 0;
285
Fabio Estevam3d622b72013-12-26 14:51:33 -0200286 reg = (reg & ~(0x1F << shift)) | (val << shift);
Dirk Behmecac833a2012-05-02 02:12:17 +0000287 writel(reg, &anatop->reg_core);
Fabio Estevam3d622b72013-12-26 14:51:33 -0200288
Fabio Estevam39f0ac92013-12-26 14:51:34 -0200289 /*
290 * The LDO ramp-up is based on 64 clock cycles of 24 MHz = 2.6 us per
291 * step
292 */
293 udelay(3 * step);
294
Fabio Estevam3d622b72013-12-26 14:51:33 -0200295 return 0;
Dirk Behmecac833a2012-05-02 02:12:17 +0000296}
297
Anson Huang5c92edc2014-01-23 14:00:18 +0800298static void set_ahb_rate(u32 val)
299{
300 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
301 u32 reg, div;
302
303 div = get_periph_clk() / val - 1;
304 reg = readl(&mxc_ccm->cbcdr);
305
306 writel((reg & (~MXC_CCM_CBCDR_AHB_PODF_MASK)) |
307 (div << MXC_CCM_CBCDR_AHB_PODF_OFFSET), &mxc_ccm->cbcdr);
308}
309
Anson Huang16197bb2014-01-23 14:00:19 +0800310static void clear_mmdc_ch_mask(void)
311{
312 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Peng Fane1c2d682015-07-11 11:38:43 +0800313 u32 reg;
314 reg = readl(&mxc_ccm->ccdr);
Anson Huang16197bb2014-01-23 14:00:19 +0800315
316 /* Clear MMDC channel mask */
Peng Fan79a57b52017-08-08 16:21:35 +0800317 if (is_mx6sx() || is_mx6ul() || is_mx6ull() || is_mx6sl() || is_mx6sll())
Ye Lib7777892016-03-09 16:13:48 +0800318 reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK);
319 else
320 reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK | MXC_CCM_CCDR_MMDC_CH0_HS_MASK);
Peng Fane1c2d682015-07-11 11:38:43 +0800321 writel(reg, &mxc_ccm->ccdr);
Anson Huang16197bb2014-01-23 14:00:19 +0800322}
323
Peng Fan97c16dc2016-10-08 17:03:00 +0800324#define OCOTP_MEM0_REFTOP_TRIM_SHIFT 8
325
Peng Fan1f516fa2015-01-15 14:22:32 +0800326static void init_bandgap(void)
327{
328 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Peng Fan97c16dc2016-10-08 17:03:00 +0800329 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
330 struct fuse_bank *bank = &ocotp->bank[1];
331 struct fuse_bank1_regs *fuse =
332 (struct fuse_bank1_regs *)bank->fuse_regs;
333 uint32_t val;
334
Peng Fan1f516fa2015-01-15 14:22:32 +0800335 /*
336 * Ensure the bandgap has stabilized.
337 */
338 while (!(readl(&anatop->ana_misc0) & 0x80))
339 ;
340 /*
341 * For best noise performance of the analog blocks using the
342 * outputs of the bandgap, the reftop_selfbiasoff bit should
343 * be set.
344 */
345 writel(BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF, &anatop->ana_misc0_set);
Peng Fan5b664822016-08-11 14:02:50 +0800346 /*
Peng Fan97c16dc2016-10-08 17:03:00 +0800347 * On i.MX6ULL,we need to set VBGADJ bits according to the
348 * REFTOP_TRIM[3:0] in fuse table
349 * 000 - set REFTOP_VBGADJ[2:0] to 3b'110,
350 * 110 - set REFTOP_VBGADJ[2:0] to 3b'000,
351 * 001 - set REFTOP_VBGADJ[2:0] to 3b'001,
352 * 010 - set REFTOP_VBGADJ[2:0] to 3b'010,
353 * 011 - set REFTOP_VBGADJ[2:0] to 3b'011,
354 * 100 - set REFTOP_VBGADJ[2:0] to 3b'100,
355 * 101 - set REFTOP_VBGADJ[2:0] to 3b'101,
356 * 111 - set REFTOP_VBGADJ[2:0] to 3b'111,
Peng Fan5b664822016-08-11 14:02:50 +0800357 */
Peng Fan97c16dc2016-10-08 17:03:00 +0800358 if (is_mx6ull()) {
359 val = readl(&fuse->mem0);
360 val >>= OCOTP_MEM0_REFTOP_TRIM_SHIFT;
361 val &= 0x7;
Peng Fan1f516fa2015-01-15 14:22:32 +0800362
Peng Fan97c16dc2016-10-08 17:03:00 +0800363 writel(val << BM_ANADIG_ANA_MISC0_REFTOP_VBGADJ_SHIFT,
364 &anatop->ana_misc0_set);
365 }
366}
Peng Fan1f516fa2015-01-15 14:22:32 +0800367
Jason Liu23608e22011-11-25 00:18:02 +0000368int arch_cpu_init(void)
369{
Peng Fan72362972017-08-08 16:21:38 +0800370 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
371
Jason Liu23608e22011-11-25 00:18:02 +0000372 init_aips();
373
Anson Huang16197bb2014-01-23 14:00:19 +0800374 /* Need to clear MMDC_CHx_MASK to make warm reset work. */
375 clear_mmdc_ch_mask();
376
Anson Huang5c92edc2014-01-23 14:00:18 +0800377 /*
Peng Fan1f516fa2015-01-15 14:22:32 +0800378 * Disable self-bias circuit in the analog bandap.
379 * The self-bias circuit is used by the bandgap during startup.
380 * This bit should be set after the bandgap has initialized.
381 */
382 init_bandgap();
383
Peng Fancdf33c92016-08-11 14:02:43 +0800384 if (!is_mx6ul() && !is_mx6ull()) {
Peng Fane4dc3fc2016-03-09 16:44:36 +0800385 /*
386 * When low freq boot is enabled, ROM will not set AHB
387 * freq, so we need to ensure AHB freq is 132MHz in such
388 * scenario.
389 *
390 * To i.MX6UL, when power up, default ARM core and
391 * AHB rate is 396M and 132M.
392 */
393 if (mxc_get_clock(MXC_ARM_CLK) == 396000000)
394 set_ahb_rate(132000000);
395 }
Anson Huang5c92edc2014-01-23 14:00:18 +0800396
Peng Fanf15ece32016-09-28 09:40:27 +0800397 if (is_mx6ul()) {
398 if (is_soc_rev(CHIP_REV_1_0) == 0) {
399 /*
400 * According to the design team's requirement on
401 * i.MX6UL,the PMIC_STBY_REQ PAD should be configured
402 * as open drain 100K (0x0000b8a0).
403 * Only exists on TO1.0
404 */
405 writel(0x0000b8a0, IOMUXC_BASE_ADDR + 0x29c);
406 } else {
407 /*
408 * From TO1.1, SNVS adds internal pull up control
409 * for POR_B, the register filed is GPBIT[1:0],
410 * after system boot up, it can be set to 2b'01
411 * to disable internal pull up.It can save about
412 * 30uA power in SNVS mode.
413 */
414 writel((readl(MX6UL_SNVS_LP_BASE_ADDR + 0x10) &
415 (~0x1400)) | 0x400,
416 MX6UL_SNVS_LP_BASE_ADDR + 0x10);
417 }
Peng Fan7082d872016-03-09 16:44:37 +0800418 }
419
Peng Fanb4714612016-08-11 14:02:46 +0800420 if (is_mx6ull()) {
421 /*
422 * GPBIT[1:0] is suggested to set to 2'b11:
423 * 2'b00 : always PUP100K
424 * 2'b01 : PUP100K when PMIC_ON_REQ or SOC_NOT_FAIL
425 * 2'b10 : always disable PUP100K
426 * 2'b11 : PDN100K when SOC_FAIL, PUP100K when SOC_NOT_FAIL
427 * register offset is different from i.MX6UL, since
428 * i.MX6UL is fixed by ECO.
429 */
430 writel(readl(MX6UL_SNVS_LP_BASE_ADDR) |
431 0x3, MX6UL_SNVS_LP_BASE_ADDR);
432 }
433
Peng Fan7082d872016-03-09 16:44:37 +0800434 /* Set perclk to source from OSC 24MHz */
Peng Fan9402caf2017-08-08 16:21:39 +0800435 if (is_mx6sl())
436 setbits_le32(&ccm->cscmr1, MXC_CCM_CSCMR1_PER_CLK_SEL_MASK);
Ye.Li0f8ec142014-10-30 18:20:58 +0800437
Fabio Estevam76c91e62013-02-07 06:45:23 +0000438 imx_set_wdog_powerdown(false); /* Disable PDE bit of WMCR register */
Stefan Roeseae695b12013-04-15 21:14:12 +0000439
Peng Fan72362972017-08-08 16:21:38 +0800440 if (is_mx6sx())
441 setbits_le32(&ccm->cscdr1, MXC_CCM_CSCDR1_UART_CLK_SEL);
442
Dirk Behme9d16c522015-03-09 14:48:48 +0100443 init_src();
444
Jason Liu23608e22011-11-25 00:18:02 +0000445 return 0;
446}
Jason Liu23608e22011-11-25 00:18:02 +0000447
Peng Fan216d2862016-01-28 16:51:26 +0800448#ifdef CONFIG_ENV_IS_IN_MMC
449__weak int board_mmc_get_env_dev(int devno)
450{
451 return CONFIG_SYS_MMC_ENV_DEV;
452}
453
Soeren Moch1a43dc12016-02-04 14:41:15 +0100454static int mmc_get_boot_dev(void)
Peng Fan216d2862016-01-28 16:51:26 +0800455{
456 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
457 u32 soc_sbmr = readl(&src_regs->sbmr1);
458 u32 bootsel;
459 int devno;
460
461 /*
462 * Refer to
463 * "i.MX 6Dual/6Quad Applications Processor Reference Manual"
464 * Chapter "8.5.3.1 Expansion Device eFUSE Configuration"
465 * i.MX6SL/SX/UL has same layout.
466 */
467 bootsel = (soc_sbmr & 0x000000FF) >> 6;
468
Soeren Moch1a43dc12016-02-04 14:41:15 +0100469 /* No boot from sd/mmc */
Peng Fan216d2862016-01-28 16:51:26 +0800470 if (bootsel != 1)
Soeren Moch1a43dc12016-02-04 14:41:15 +0100471 return -1;
Peng Fan216d2862016-01-28 16:51:26 +0800472
473 /* BOOT_CFG2[3] and BOOT_CFG2[4] */
474 devno = (soc_sbmr & 0x00001800) >> 11;
475
Soeren Moch1a43dc12016-02-04 14:41:15 +0100476 return devno;
477}
478
479int mmc_get_env_dev(void)
480{
481 int devno = mmc_get_boot_dev();
482
483 /* If not boot from sd/mmc, use default value */
484 if (devno < 0)
485 return CONFIG_SYS_MMC_ENV_DEV;
486
Peng Fan216d2862016-01-28 16:51:26 +0800487 return board_mmc_get_env_dev(devno);
488}
Soeren Moch1a43dc12016-02-04 14:41:15 +0100489
490#ifdef CONFIG_SYS_MMC_ENV_PART
491__weak int board_mmc_get_env_part(int devno)
492{
493 return CONFIG_SYS_MMC_ENV_PART;
494}
495
496uint mmc_get_env_part(struct mmc *mmc)
497{
498 int devno = mmc_get_boot_dev();
499
500 /* If not boot from sd/mmc, use default value */
501 if (devno < 0)
502 return CONFIG_SYS_MMC_ENV_PART;
503
504 return board_mmc_get_env_part(devno);
505}
506#endif
Peng Fan216d2862016-01-28 16:51:26 +0800507#endif
508
Fabio Estevam39f0ac92013-12-26 14:51:34 -0200509int board_postclk_init(void)
510{
Peng Fan79a57b52017-08-08 16:21:35 +0800511 /* NO LDO SOC on i.MX6SLL */
512 if (is_mx6sll())
513 return 0;
514
Fabio Estevam39f0ac92013-12-26 14:51:34 -0200515 set_ldo_voltage(LDO_SOC, 1175); /* Set VDDSOC to 1.175V */
516
517 return 0;
518}
519
Jason Liu23608e22011-11-25 00:18:02 +0000520#if defined(CONFIG_FEC_MXC)
Fabio Estevambe252b62011-12-20 05:46:31 +0000521void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
Jason Liu23608e22011-11-25 00:18:02 +0000522{
Benoît Thébaudeau8f3ff112013-04-23 10:17:38 +0000523 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
524 struct fuse_bank *bank = &ocotp->bank[4];
Jason Liu23608e22011-11-25 00:18:02 +0000525 struct fuse_bank4_regs *fuse =
526 (struct fuse_bank4_regs *)bank->fuse_regs;
527
Peng Fan6615da42016-08-11 14:02:45 +0800528 if ((is_mx6sx() || is_mx6ul() || is_mx6ull()) && dev_id == 1) {
Ye Lid4d1dd62016-02-01 10:41:31 +0800529 u32 value = readl(&fuse->mac_addr2);
530 mac[0] = value >> 24 ;
531 mac[1] = value >> 16 ;
532 mac[2] = value >> 8 ;
533 mac[3] = value ;
Jason Liu23608e22011-11-25 00:18:02 +0000534
Ye Lid4d1dd62016-02-01 10:41:31 +0800535 value = readl(&fuse->mac_addr1);
536 mac[4] = value >> 24 ;
537 mac[5] = value >> 16 ;
538
539 } else {
540 u32 value = readl(&fuse->mac_addr1);
541 mac[0] = (value >> 8);
542 mac[1] = value ;
543
544 value = readl(&fuse->mac_addr0);
545 mac[2] = value >> 24 ;
546 mac[3] = value >> 16 ;
547 mac[4] = value >> 8 ;
548 mac[5] = value ;
549 }
Jason Liu23608e22011-11-25 00:18:02 +0000550
551}
552#endif
Troy Kisky124a06d2012-08-15 10:31:20 +0000553
Anatolij Gustschinffc36f52017-08-28 17:51:33 +0200554#ifndef CONFIG_SPL_BUILD
Troy Kisky124a06d2012-08-15 10:31:20 +0000555/*
556 * cfg_val will be used for
557 * Boot_cfg4[7:0]:Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
Nikita Kiryanovf2863ff2014-10-29 19:28:33 +0200558 * After reset, if GPR10[28] is 1, ROM will use GPR9[25:0]
559 * instead of SBMR1 to determine the boot device.
Troy Kisky124a06d2012-08-15 10:31:20 +0000560 */
561const struct boot_mode soc_boot_modes[] = {
562 {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)},
563 /* reserved value should start rom usb */
Stefan Agner3fd95792017-06-09 13:13:12 -0700564#if defined(CONFIG_MX6UL) || defined(CONFIG_MX6ULL)
565 {"usb", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
566#else
Stefan Agner81c4ecc2016-09-15 15:04:39 -0700567 {"usb", MAKE_CFGVAL(0x10, 0x00, 0x00, 0x00)},
Stefan Agner3fd95792017-06-09 13:13:12 -0700568#endif
Troy Kisky124a06d2012-08-15 10:31:20 +0000569 {"sata", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
Nikolay Dimitrov2d59e3e2014-08-10 20:03:07 +0300570 {"ecspi1:0", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x08)},
571 {"ecspi1:1", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x18)},
572 {"ecspi1:2", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x28)},
573 {"ecspi1:3", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x38)},
Troy Kisky124a06d2012-08-15 10:31:20 +0000574 /* 4 bit bus width */
575 {"esdhc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
576 {"esdhc2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
577 {"esdhc3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
578 {"esdhc4", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
579 {NULL, 0},
580};
Anatolij Gustschinffc36f52017-08-28 17:51:33 +0200581#endif
Stephen Warren8f393772013-02-26 12:28:29 +0000582
Peng Faneb111bb2015-10-29 15:54:50 +0800583void reset_misc(void)
584{
585#ifdef CONFIG_VIDEO_MXS
586 lcdif_power_down();
587#endif
588}
589
Stephen Warren8f393772013-02-26 12:28:29 +0000590void s_init(void)
591{
Eric Nelson8467fae2013-08-29 12:41:46 -0700592 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Ye.Li9293d7f2014-09-09 10:17:00 +0800593 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Eric Nelson8467fae2013-08-29 12:41:46 -0700594 u32 mask480;
595 u32 mask528;
Ye.Li9293d7f2014-09-09 10:17:00 +0800596 u32 reg, periph1, periph2;
Fabio Estevama3df99b2014-07-09 16:13:29 -0300597
Peng Fan79a57b52017-08-08 16:21:35 +0800598 if (is_mx6sx() || is_mx6ul() || is_mx6ull() || is_mx6sll())
Fabio Estevama3df99b2014-07-09 16:13:29 -0300599 return;
600
Eric Nelson8467fae2013-08-29 12:41:46 -0700601 /* Due to hardware limitation, on MX6Q we need to gate/ungate all PFDs
602 * to make sure PFD is working right, otherwise, PFDs may
603 * not output clock after reset, MX6DL and MX6SL have added 396M pfd
604 * workaround in ROM code, as bus clock need it
605 */
606
607 mask480 = ANATOP_PFD_CLKGATE_MASK(0) |
608 ANATOP_PFD_CLKGATE_MASK(1) |
609 ANATOP_PFD_CLKGATE_MASK(2) |
610 ANATOP_PFD_CLKGATE_MASK(3);
Ye.Li9293d7f2014-09-09 10:17:00 +0800611 mask528 = ANATOP_PFD_CLKGATE_MASK(1) |
Eric Nelson8467fae2013-08-29 12:41:46 -0700612 ANATOP_PFD_CLKGATE_MASK(3);
613
Ye.Li9293d7f2014-09-09 10:17:00 +0800614 reg = readl(&ccm->cbcmr);
615 periph2 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_MASK)
616 >> MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_OFFSET);
617 periph1 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK)
618 >> MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_OFFSET);
619
620 /* Checking if PLL2 PFD0 or PLL2 PFD2 is using for periph clock */
621 if ((periph2 != 0x2) && (periph1 != 0x2))
622 mask528 |= ANATOP_PFD_CLKGATE_MASK(0);
623
624 if ((periph2 != 0x1) && (periph1 != 0x1) &&
625 (periph2 != 0x3) && (periph1 != 0x3))
Eric Nelson8467fae2013-08-29 12:41:46 -0700626 mask528 |= ANATOP_PFD_CLKGATE_MASK(2);
Ye.Li9293d7f2014-09-09 10:17:00 +0800627
Eric Nelson8467fae2013-08-29 12:41:46 -0700628 writel(mask480, &anatop->pfd_480_set);
629 writel(mask528, &anatop->pfd_528_set);
630 writel(mask480, &anatop->pfd_480_clr);
631 writel(mask528, &anatop->pfd_528_clr);
Stephen Warren8f393772013-02-26 12:28:29 +0000632}
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500633
634#ifdef CONFIG_IMX_HDMI
635void imx_enable_hdmi_phy(void)
636{
637 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
638 u8 reg;
639 reg = readb(&hdmi->phy_conf0);
640 reg |= HDMI_PHY_CONF0_PDZ_MASK;
641 writeb(reg, &hdmi->phy_conf0);
642 udelay(3000);
643 reg |= HDMI_PHY_CONF0_ENTMDS_MASK;
644 writeb(reg, &hdmi->phy_conf0);
645 udelay(3000);
646 reg |= HDMI_PHY_CONF0_GEN2_TXPWRON_MASK;
647 writeb(reg, &hdmi->phy_conf0);
648 writeb(HDMI_MC_PHYRSTZ_ASSERT, &hdmi->mc_phyrstz);
649}
650
651void imx_setup_hdmi(void)
652{
653 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
654 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
Peng Fan00b1d2d2016-03-09 16:07:23 +0800655 int reg, count;
656 u8 val;
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500657
658 /* Turn on HDMI PHY clock */
659 reg = readl(&mxc_ccm->CCGR2);
660 reg |= MXC_CCM_CCGR2_HDMI_TX_IAHBCLK_MASK|
661 MXC_CCM_CCGR2_HDMI_TX_ISFRCLK_MASK;
662 writel(reg, &mxc_ccm->CCGR2);
663 writeb(HDMI_MC_PHYRSTZ_DEASSERT, &hdmi->mc_phyrstz);
664 reg = readl(&mxc_ccm->chsccdr);
665 reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK|
666 MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK|
667 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK);
668 reg |= (CHSCCDR_PODF_DIVIDE_BY_3
669 << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET)
670 |(CHSCCDR_IPU_PRE_CLK_540M_PFD
671 << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET);
672 writel(reg, &mxc_ccm->chsccdr);
Peng Fan00b1d2d2016-03-09 16:07:23 +0800673
674 /* Clear the overflow condition */
675 if (readb(&hdmi->ih_fc_stat2) & HDMI_IH_FC_STAT2_OVERFLOW_MASK) {
676 /* TMDS software reset */
677 writeb((u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, &hdmi->mc_swrstz);
678 val = readb(&hdmi->fc_invidconf);
679 /* Need minimum 3 times to write to clear the register */
680 for (count = 0 ; count < 5 ; count++)
681 writeb(val, &hdmi->fc_invidconf);
682 }
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500683}
684#endif
Peng Fan0623d372016-01-28 16:55:05 +0800685
Breno Lima3aa4b702017-08-24 10:00:16 -0300686void gpr_init(void)
687{
688 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
689
690 /* enable AXI cache for VDOA/VPU/IPU */
691 writel(0xF00000CF, &iomux->gpr[4]);
692 if (is_mx6dqp()) {
693 /* set IPU AXI-id1 Qos=0x1 AXI-id0/2/3 Qos=0x7 */
694 writel(0x77177717, &iomux->gpr[6]);
695 writel(0x77177717, &iomux->gpr[7]);
696 } else {
697 /* set IPU AXI-id0 Qos=0xf(bypass) AXI-id1 Qos=0x7 */
698 writel(0x007F007F, &iomux->gpr[6]);
699 writel(0x007F007F, &iomux->gpr[7]);
700 }
701}
702
Peng Fan0623d372016-01-28 16:55:05 +0800703#ifdef CONFIG_IMX_BOOTAUX
704int arch_auxiliary_core_up(u32 core_id, u32 boot_private_data)
705{
706 struct src *src_reg;
707 u32 stack, pc;
708
709 if (!boot_private_data)
710 return -EINVAL;
711
712 stack = *(u32 *)boot_private_data;
713 pc = *(u32 *)(boot_private_data + 4);
714
715 /* Set the stack and pc to M4 bootROM */
716 writel(stack, M4_BOOTROM_BASE_ADDR);
717 writel(pc, M4_BOOTROM_BASE_ADDR + 4);
718
719 /* Enable M4 */
720 src_reg = (struct src *)SRC_BASE_ADDR;
721 clrsetbits_le32(&src_reg->scr, SRC_SCR_M4C_NON_SCLR_RST_MASK,
722 SRC_SCR_M4_ENABLE_MASK);
723
724 return 0;
725}
726
727int arch_auxiliary_core_check_up(u32 core_id)
728{
729 struct src *src_reg = (struct src *)SRC_BASE_ADDR;
730 unsigned val;
731
732 val = readl(&src_reg->scr);
733
734 if (val & SRC_SCR_M4C_NON_SCLR_RST_MASK)
735 return 0; /* assert in reset */
736
737 return 1;
738}
739#endif