blob: b8aaf3ef0159006c73b01759b2342923890d0c19 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jason Liudec11122011-11-25 00:18:02 +00002/*
3 * (C) Copyright 2007
4 * Sascha Hauer, Pengutronix
5 *
6 * (C) Copyright 2009 Freescale Semiconductor, Inc.
Jason Liudec11122011-11-25 00:18:02 +00007 */
8
9#include <common.h>
Simon Glassa7b51302019-11-14 12:57:46 -070010#include <init.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090011#include <linux/errno.h>
Jason Liudec11122011-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>
Diego Dorta3a5bf532017-09-27 13:12:37 -030016#include <asm/bootm.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020017#include <asm/mach-imx/boot_mode.h>
18#include <asm/mach-imx/dma.h>
19#include <asm/mach-imx/hab.h>
Fabio Estevam48e65b02013-02-07 06:45:23 +000020#include <stdbool.h>
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -050021#include <asm/arch/mxc_hdmi.h>
22#include <asm/arch/crm_regs.h>
Ye.Lif19692c2014-11-20 21:14:14 +080023#include <dm.h>
24#include <imx_thermal.h>
Soeren Mochbc177f12016-02-04 14:41:15 +010025#include <mmc.h>
Jason Liudec11122011-11-25 00:18:02 +000026
Troy Kisky58394932012-10-23 10:57:46 +000027struct scu_regs {
28 u32 ctrl;
29 u32 config;
30 u32 status;
31 u32 invalidate;
32 u32 fpga_rev;
33};
34
Adrian Alonsoce08c362015-09-02 13:54:13 -050035#if defined(CONFIG_IMX_THERMAL)
Ye.Lif19692c2014-11-20 21:14:14 +080036static const struct imx_thermal_plat imx6_thermal_plat = {
37 .regs = (void *)ANATOP_BASE_ADDR,
38 .fuse_bank = 1,
39 .fuse_word = 6,
40};
41
42U_BOOT_DEVICE(imx6_thermal) = {
43 .name = "imx_thermal",
44 .platdata = &imx6_thermal_plat,
45};
46#endif
47
Stefano Babicf8b509b2019-09-20 08:47:53 +020048#if defined(CONFIG_IMX_HAB)
Adrian Alonso6ec8d842015-10-12 13:48:12 -050049struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
50 .bank = 0,
51 .word = 6,
52};
53#endif
54
Gabriel Huau170ceaf2014-07-26 11:35:43 -070055u32 get_nr_cpus(void)
56{
57 struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
58 return readl(&scu->config) & 3;
59}
60
Jason Liudec11122011-11-25 00:18:02 +000061u32 get_cpu_rev(void)
62{
Fabio Estevam46e97332012-03-20 04:21:45 +000063 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Troy Kisky58394932012-10-23 10:57:46 +000064 u32 reg = readl(&anatop->digprog_sololite);
65 u32 type = ((reg >> 16) & 0xff);
Peng Fan5f247922015-07-11 11:38:42 +080066 u32 major, cfg = 0;
Fabio Estevam46e97332012-03-20 04:21:45 +000067
Troy Kisky58394932012-10-23 10:57:46 +000068 if (type != MXC_CPU_MX6SL) {
69 reg = readl(&anatop->digprog);
Fabio Estevamf3d5a2c2014-01-26 15:06:41 -020070 struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
Peng Fan5f247922015-07-11 11:38:42 +080071 cfg = readl(&scu->config) & 3;
Troy Kisky58394932012-10-23 10:57:46 +000072 type = ((reg >> 16) & 0xff);
73 if (type == MXC_CPU_MX6DL) {
Troy Kisky58394932012-10-23 10:57:46 +000074 if (!cfg)
75 type = MXC_CPU_MX6SOLO;
76 }
Fabio Estevamf3d5a2c2014-01-26 15:06:41 -020077
78 if (type == MXC_CPU_MX6Q) {
79 if (cfg == 1)
80 type = MXC_CPU_MX6D;
81 }
82
Peng Fanc53d0c92019-08-08 09:55:52 +000083 if (type == MXC_CPU_MX6ULL) {
84 if (readl(SRC_BASE_ADDR + 0x1c) & (1 << 6))
85 type = MXC_CPU_MX6ULZ;
86 }
Troy Kisky58394932012-10-23 10:57:46 +000087 }
Peng Fan88383232015-06-11 18:30:36 +080088 major = ((reg >> 8) & 0xff);
Peng Fan5f247922015-07-11 11:38:42 +080089 if ((major >= 1) &&
90 ((type == MXC_CPU_MX6Q) || (type == MXC_CPU_MX6D))) {
91 major--;
92 type = MXC_CPU_MX6QP;
93 if (cfg == 1)
94 type = MXC_CPU_MX6DP;
95 }
Troy Kisky58394932012-10-23 10:57:46 +000096 reg &= 0xff; /* mx6 silicon revision */
Ye Li10f19c72019-07-10 10:38:37 +000097
98 /* For 6DQ, the value 0x00630005 is Silicon revision 1.3*/
99 if (((type == MXC_CPU_MX6Q) || (type == MXC_CPU_MX6D)) && (reg == 0x5))
100 reg = 0x3;
101
Peng Fan88383232015-06-11 18:30:36 +0800102 return (type << 12) | (reg + (0x10 * (major + 1)));
Jason Liudec11122011-11-25 00:18:02 +0000103}
104
Tim Harvey258d0462015-05-18 07:02:24 -0700105/*
106 * OCOTP_CFG3[17:16] (see Fusemap Description Table offset 0x440)
107 * defines a 2-bit SPEED_GRADING
108 */
109#define OCOTP_CFG3_SPEED_SHIFT 16
110#define OCOTP_CFG3_SPEED_800MHZ 0
111#define OCOTP_CFG3_SPEED_850MHZ 1
112#define OCOTP_CFG3_SPEED_1GHZ 2
113#define OCOTP_CFG3_SPEED_1P2GHZ 3
114
Peng Fan441e9052016-05-03 11:13:04 +0800115/*
116 * For i.MX6UL
117 */
118#define OCOTP_CFG3_SPEED_528MHZ 1
119#define OCOTP_CFG3_SPEED_696MHZ 2
120
Sébastien Szymanskib130c8a2017-08-02 17:05:27 +0200121/*
122 * For i.MX6ULL
123 */
124#define OCOTP_CFG3_SPEED_792MHZ 2
125#define OCOTP_CFG3_SPEED_900MHZ 3
126
Tim Harvey258d0462015-05-18 07:02:24 -0700127u32 get_cpu_speed_grade_hz(void)
128{
129 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
130 struct fuse_bank *bank = &ocotp->bank[0];
131 struct fuse_bank0_regs *fuse =
132 (struct fuse_bank0_regs *)bank->fuse_regs;
133 uint32_t val;
134
135 val = readl(&fuse->cfg3);
136 val >>= OCOTP_CFG3_SPEED_SHIFT;
137 val &= 0x3;
138
Sébastien Szymanskib130c8a2017-08-02 17:05:27 +0200139 if (is_mx6ul()) {
Peng Fan441e9052016-05-03 11:13:04 +0800140 if (val == OCOTP_CFG3_SPEED_528MHZ)
141 return 528000000;
142 else if (val == OCOTP_CFG3_SPEED_696MHZ)
Sébastien Szymanski415c7ce2017-08-02 17:05:26 +0200143 return 696000000;
Peng Fan441e9052016-05-03 11:13:04 +0800144 else
145 return 0;
146 }
147
Sébastien Szymanskib130c8a2017-08-02 17:05:27 +0200148 if (is_mx6ull()) {
149 if (val == OCOTP_CFG3_SPEED_528MHZ)
150 return 528000000;
151 else if (val == OCOTP_CFG3_SPEED_792MHZ)
152 return 792000000;
153 else if (val == OCOTP_CFG3_SPEED_900MHZ)
154 return 900000000;
155 else
156 return 0;
157 }
158
Tim Harvey258d0462015-05-18 07:02:24 -0700159 switch (val) {
160 /* Valid for IMX6DQ */
161 case OCOTP_CFG3_SPEED_1P2GHZ:
Peng Fan6c4f76f2016-05-23 18:35:58 +0800162 if (is_mx6dq() || is_mx6dqp())
Tim Harvey258d0462015-05-18 07:02:24 -0700163 return 1200000000;
164 /* Valid for IMX6SX/IMX6SDL/IMX6DQ */
165 case OCOTP_CFG3_SPEED_1GHZ:
166 return 996000000;
167 /* Valid for IMX6DQ */
168 case OCOTP_CFG3_SPEED_850MHZ:
Peng Fan6c4f76f2016-05-23 18:35:58 +0800169 if (is_mx6dq() || is_mx6dqp())
Tim Harvey258d0462015-05-18 07:02:24 -0700170 return 852000000;
171 /* Valid for IMX6SX/IMX6SDL/IMX6DQ */
172 case OCOTP_CFG3_SPEED_800MHZ:
173 return 792000000;
174 }
175 return 0;
176}
177
Tim Harvey5e0e1932015-05-18 06:56:45 -0700178/*
179 * OCOTP_MEM0[7:6] (see Fusemap Description Table offset 0x480)
180 * defines a 2-bit Temperature Grade
181 *
Fabio Estevama24859c2017-06-22 10:50:05 -0300182 * return temperature grade and min/max temperature in Celsius
Tim Harvey5e0e1932015-05-18 06:56:45 -0700183 */
184#define OCOTP_MEM0_TEMP_SHIFT 6
185
186u32 get_cpu_temp_grade(int *minc, int *maxc)
187{
188 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
189 struct fuse_bank *bank = &ocotp->bank[1];
190 struct fuse_bank1_regs *fuse =
191 (struct fuse_bank1_regs *)bank->fuse_regs;
192 uint32_t val;
193
194 val = readl(&fuse->mem0);
195 val >>= OCOTP_MEM0_TEMP_SHIFT;
196 val &= 0x3;
197
198 if (minc && maxc) {
199 if (val == TEMP_AUTOMOTIVE) {
200 *minc = -40;
201 *maxc = 125;
202 } else if (val == TEMP_INDUSTRIAL) {
203 *minc = -40;
204 *maxc = 105;
205 } else if (val == TEMP_EXTCOMMERCIAL) {
206 *minc = -20;
207 *maxc = 105;
208 } else {
209 *minc = 0;
210 *maxc = 95;
211 }
212 }
213 return val;
214}
215
Fabio Estevam435998b2013-03-27 07:36:55 +0000216#ifdef CONFIG_REVISION_TAG
217u32 __weak get_board_rev(void)
218{
219 u32 cpurev = get_cpu_rev();
220 u32 type = ((cpurev >> 12) & 0xff);
221 if (type == MXC_CPU_MX6SOLO)
222 cpurev = (MXC_CPU_MX6DL) << 12 | (cpurev & 0xFFF);
223
Fabio Estevamf3d5a2c2014-01-26 15:06:41 -0200224 if (type == MXC_CPU_MX6D)
225 cpurev = (MXC_CPU_MX6Q) << 12 | (cpurev & 0xFFF);
226
Fabio Estevam435998b2013-03-27 07:36:55 +0000227 return cpurev;
228}
229#endif
230
Fabio Estevamcf621ff2013-12-26 14:51:31 -0200231static void clear_ldo_ramp(void)
232{
233 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
234 int reg;
235
236 /* ROM may modify LDO ramp up time according to fuse setting, so in
237 * order to be in the safe side we neeed to reset these settings to
238 * match the reset value: 0'b00
239 */
240 reg = readl(&anatop->ana_misc2);
241 reg &= ~(0x3f << 24);
242 writel(reg, &anatop->ana_misc2);
243}
244
Dirk Behme8c465942012-05-02 02:12:17 +0000245/*
Fabio Estevam2e95fe12014-06-13 01:42:37 -0300246 * Set the PMU_REG_CORE register
Dirk Behme8c465942012-05-02 02:12:17 +0000247 *
Fabio Estevam2e95fe12014-06-13 01:42:37 -0300248 * Set LDO_SOC/PU/ARM regulators to the specified millivolt level.
Dirk Behme8c465942012-05-02 02:12:17 +0000249 * Possible values are from 0.725V to 1.450V in steps of
250 * 0.025V (25mV).
251 */
Marek Vasut02fec412019-11-26 09:35:32 +0100252int set_ldo_voltage(enum ldo_reg ldo, u32 mv)
Dirk Behme8c465942012-05-02 02:12:17 +0000253{
254 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Fabio Estevam99b370b2013-12-26 14:51:34 -0200255 u32 val, step, old, reg = readl(&anatop->reg_core);
Fabio Estevama47ec522013-12-26 14:51:33 -0200256 u8 shift;
Dirk Behme8c465942012-05-02 02:12:17 +0000257
Peng Fan81224c42017-08-08 16:21:35 +0800258 /* No LDO_SOC/PU/ARM */
259 if (is_mx6sll())
260 return 0;
261
Dirk Behme8c465942012-05-02 02:12:17 +0000262 if (mv < 725)
263 val = 0x00; /* Power gated off */
264 else if (mv > 1450)
265 val = 0x1F; /* Power FET switched full on. No regulation */
266 else
267 val = (mv - 700) / 25;
268
Fabio Estevamcf621ff2013-12-26 14:51:31 -0200269 clear_ldo_ramp();
270
Fabio Estevama47ec522013-12-26 14:51:33 -0200271 switch (ldo) {
272 case LDO_SOC:
273 shift = 18;
274 break;
275 case LDO_PU:
276 shift = 9;
277 break;
278 case LDO_ARM:
279 shift = 0;
280 break;
281 default:
282 return -EINVAL;
283 }
284
Fabio Estevam99b370b2013-12-26 14:51:34 -0200285 old = (reg & (0x1F << shift)) >> shift;
286 step = abs(val - old);
287 if (step == 0)
288 return 0;
289
Fabio Estevama47ec522013-12-26 14:51:33 -0200290 reg = (reg & ~(0x1F << shift)) | (val << shift);
Dirk Behme8c465942012-05-02 02:12:17 +0000291 writel(reg, &anatop->reg_core);
Fabio Estevama47ec522013-12-26 14:51:33 -0200292
Fabio Estevam99b370b2013-12-26 14:51:34 -0200293 /*
294 * The LDO ramp-up is based on 64 clock cycles of 24 MHz = 2.6 us per
295 * step
296 */
297 udelay(3 * step);
298
Fabio Estevama47ec522013-12-26 14:51:33 -0200299 return 0;
Dirk Behme8c465942012-05-02 02:12:17 +0000300}
301
Anson Huang05a464f2014-01-23 14:00:18 +0800302static void set_ahb_rate(u32 val)
303{
304 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
305 u32 reg, div;
306
307 div = get_periph_clk() / val - 1;
308 reg = readl(&mxc_ccm->cbcdr);
309
310 writel((reg & (~MXC_CCM_CBCDR_AHB_PODF_MASK)) |
311 (div << MXC_CCM_CBCDR_AHB_PODF_OFFSET), &mxc_ccm->cbcdr);
312}
313
Anson Huang9a149bc2014-01-23 14:00:19 +0800314static void clear_mmdc_ch_mask(void)
315{
316 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Peng Fan53f3c9e2015-07-11 11:38:43 +0800317 u32 reg;
318 reg = readl(&mxc_ccm->ccdr);
Anson Huang9a149bc2014-01-23 14:00:19 +0800319
320 /* Clear MMDC channel mask */
Peng Fan81224c42017-08-08 16:21:35 +0800321 if (is_mx6sx() || is_mx6ul() || is_mx6ull() || is_mx6sl() || is_mx6sll())
Ye Li64cef442016-03-09 16:13:48 +0800322 reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK);
323 else
324 reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK | MXC_CCM_CCDR_MMDC_CH0_HS_MASK);
Peng Fan53f3c9e2015-07-11 11:38:43 +0800325 writel(reg, &mxc_ccm->ccdr);
Anson Huang9a149bc2014-01-23 14:00:19 +0800326}
327
Peng Fan656d2332016-10-08 17:03:00 +0800328#define OCOTP_MEM0_REFTOP_TRIM_SHIFT 8
329
Peng Fanc0e0ebf2015-01-15 14:22:32 +0800330static void init_bandgap(void)
331{
332 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Peng Fan656d2332016-10-08 17:03:00 +0800333 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
334 struct fuse_bank *bank = &ocotp->bank[1];
335 struct fuse_bank1_regs *fuse =
336 (struct fuse_bank1_regs *)bank->fuse_regs;
337 uint32_t val;
338
Peng Fanc0e0ebf2015-01-15 14:22:32 +0800339 /*
340 * Ensure the bandgap has stabilized.
341 */
342 while (!(readl(&anatop->ana_misc0) & 0x80))
343 ;
344 /*
345 * For best noise performance of the analog blocks using the
346 * outputs of the bandgap, the reftop_selfbiasoff bit should
347 * be set.
348 */
349 writel(BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF, &anatop->ana_misc0_set);
Peng Fan6b989352016-08-11 14:02:50 +0800350 /*
Peng Fan656d2332016-10-08 17:03:00 +0800351 * On i.MX6ULL,we need to set VBGADJ bits according to the
352 * REFTOP_TRIM[3:0] in fuse table
353 * 000 - set REFTOP_VBGADJ[2:0] to 3b'110,
354 * 110 - set REFTOP_VBGADJ[2:0] to 3b'000,
355 * 001 - set REFTOP_VBGADJ[2:0] to 3b'001,
356 * 010 - set REFTOP_VBGADJ[2:0] to 3b'010,
357 * 011 - set REFTOP_VBGADJ[2:0] to 3b'011,
358 * 100 - set REFTOP_VBGADJ[2:0] to 3b'100,
359 * 101 - set REFTOP_VBGADJ[2:0] to 3b'101,
360 * 111 - set REFTOP_VBGADJ[2:0] to 3b'111,
Peng Fan6b989352016-08-11 14:02:50 +0800361 */
Peng Fan656d2332016-10-08 17:03:00 +0800362 if (is_mx6ull()) {
363 val = readl(&fuse->mem0);
364 val >>= OCOTP_MEM0_REFTOP_TRIM_SHIFT;
365 val &= 0x7;
Peng Fanc0e0ebf2015-01-15 14:22:32 +0800366
Peng Fan656d2332016-10-08 17:03:00 +0800367 writel(val << BM_ANADIG_ANA_MISC0_REFTOP_VBGADJ_SHIFT,
368 &anatop->ana_misc0_set);
369 }
370}
Peng Fanc0e0ebf2015-01-15 14:22:32 +0800371
Fabio Estevam3e59fa92019-11-04 09:44:34 -0300372#if defined(CONFIG_MX6Q) || defined(CONFIG_MX6QDL)
373static void noc_setup(void)
374{
375 enable_ipu_clock();
376
377 writel(0x80000201, 0xbb0608);
378 /* Bypass IPU1 QoS generator */
379 writel(0x00000002, 0x00bb048c);
380 /* Bypass IPU2 QoS generator */
381 writel(0x00000002, 0x00bb050c);
382 /* Bandwidth THR for of PRE0 */
383 writel(0x00000200, 0x00bb0690);
384 /* Bandwidth THR for of PRE1 */
385 writel(0x00000200, 0x00bb0710);
386 /* Bandwidth THR for of PRE2 */
387 writel(0x00000200, 0x00bb0790);
388 /* Bandwidth THR for of PRE3 */
389 writel(0x00000200, 0x00bb0810);
390 /* Saturation THR for of PRE0 */
391 writel(0x00000010, 0x00bb0694);
392 /* Saturation THR for of PRE1 */
393 writel(0x00000010, 0x00bb0714);
394 /* Saturation THR for of PRE2 */
395 writel(0x00000010, 0x00bb0794);
396 /* Saturation THR for of PRE */
397 writel(0x00000010, 0x00bb0814);
398
399 disable_ipu_clock();
400}
401#endif
402
Jason Liudec11122011-11-25 00:18:02 +0000403int arch_cpu_init(void)
404{
Peng Fan946333d2017-08-08 16:21:38 +0800405 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
406
Jason Liudec11122011-11-25 00:18:02 +0000407 init_aips();
408
Anson Huang9a149bc2014-01-23 14:00:19 +0800409 /* Need to clear MMDC_CHx_MASK to make warm reset work. */
410 clear_mmdc_ch_mask();
411
Anson Huang05a464f2014-01-23 14:00:18 +0800412 /*
Peng Fanc0e0ebf2015-01-15 14:22:32 +0800413 * Disable self-bias circuit in the analog bandap.
414 * The self-bias circuit is used by the bandgap during startup.
415 * This bit should be set after the bandgap has initialized.
416 */
417 init_bandgap();
418
Peng Fanae86e3f2016-08-11 14:02:43 +0800419 if (!is_mx6ul() && !is_mx6ull()) {
Peng Fanf60137e2016-03-09 16:44:36 +0800420 /*
421 * When low freq boot is enabled, ROM will not set AHB
422 * freq, so we need to ensure AHB freq is 132MHz in such
423 * scenario.
424 *
425 * To i.MX6UL, when power up, default ARM core and
426 * AHB rate is 396M and 132M.
427 */
428 if (mxc_get_clock(MXC_ARM_CLK) == 396000000)
429 set_ahb_rate(132000000);
430 }
Anson Huang05a464f2014-01-23 14:00:18 +0800431
Peng Fan2b990ea2016-09-28 09:40:27 +0800432 if (is_mx6ul()) {
433 if (is_soc_rev(CHIP_REV_1_0) == 0) {
434 /*
435 * According to the design team's requirement on
436 * i.MX6UL,the PMIC_STBY_REQ PAD should be configured
437 * as open drain 100K (0x0000b8a0).
438 * Only exists on TO1.0
439 */
440 writel(0x0000b8a0, IOMUXC_BASE_ADDR + 0x29c);
441 } else {
442 /*
443 * From TO1.1, SNVS adds internal pull up control
444 * for POR_B, the register filed is GPBIT[1:0],
445 * after system boot up, it can be set to 2b'01
446 * to disable internal pull up.It can save about
447 * 30uA power in SNVS mode.
448 */
449 writel((readl(MX6UL_SNVS_LP_BASE_ADDR + 0x10) &
450 (~0x1400)) | 0x400,
451 MX6UL_SNVS_LP_BASE_ADDR + 0x10);
452 }
Peng Fana2cba652016-03-09 16:44:37 +0800453 }
454
Peng Fanb64bf0b2016-08-11 14:02:46 +0800455 if (is_mx6ull()) {
456 /*
457 * GPBIT[1:0] is suggested to set to 2'b11:
458 * 2'b00 : always PUP100K
459 * 2'b01 : PUP100K when PMIC_ON_REQ or SOC_NOT_FAIL
460 * 2'b10 : always disable PUP100K
461 * 2'b11 : PDN100K when SOC_FAIL, PUP100K when SOC_NOT_FAIL
462 * register offset is different from i.MX6UL, since
463 * i.MX6UL is fixed by ECO.
464 */
465 writel(readl(MX6UL_SNVS_LP_BASE_ADDR) |
466 0x3, MX6UL_SNVS_LP_BASE_ADDR);
467 }
468
Peng Fana2cba652016-03-09 16:44:37 +0800469 /* Set perclk to source from OSC 24MHz */
Peng Fanfe7052a2017-08-08 16:21:39 +0800470 if (is_mx6sl())
471 setbits_le32(&ccm->cscmr1, MXC_CCM_CSCMR1_PER_CLK_SEL_MASK);
Ye.Li622dfbd2014-10-30 18:20:58 +0800472
Fabio Estevam5f79d462017-11-23 10:55:33 -0200473 imx_wdog_disable_powerdown(); /* Disable PDE bit of WMCR register */
Stefan Roese8338d1d2013-04-15 21:14:12 +0000474
Peng Fan946333d2017-08-08 16:21:38 +0800475 if (is_mx6sx())
476 setbits_le32(&ccm->cscdr1, MXC_CCM_CSCDR1_UART_CLK_SEL);
477
Dirk Behme0adb2152015-03-09 14:48:48 +0100478 init_src();
479
Fabio Estevam3e59fa92019-11-04 09:44:34 -0300480#if defined(CONFIG_MX6Q) || defined(CONFIG_MX6QDL)
481 if (is_mx6dqp())
482 noc_setup();
483#endif
Jason Liudec11122011-11-25 00:18:02 +0000484 return 0;
485}
Jason Liudec11122011-11-25 00:18:02 +0000486
Peng Fan850dbca2016-01-28 16:51:26 +0800487#ifdef CONFIG_ENV_IS_IN_MMC
488__weak int board_mmc_get_env_dev(int devno)
489{
490 return CONFIG_SYS_MMC_ENV_DEV;
491}
492
Soeren Mochbc177f12016-02-04 14:41:15 +0100493static int mmc_get_boot_dev(void)
Peng Fan850dbca2016-01-28 16:51:26 +0800494{
495 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
496 u32 soc_sbmr = readl(&src_regs->sbmr1);
497 u32 bootsel;
498 int devno;
499
500 /*
501 * Refer to
502 * "i.MX 6Dual/6Quad Applications Processor Reference Manual"
503 * Chapter "8.5.3.1 Expansion Device eFUSE Configuration"
504 * i.MX6SL/SX/UL has same layout.
505 */
506 bootsel = (soc_sbmr & 0x000000FF) >> 6;
507
Soeren Mochbc177f12016-02-04 14:41:15 +0100508 /* No boot from sd/mmc */
Peng Fan850dbca2016-01-28 16:51:26 +0800509 if (bootsel != 1)
Soeren Mochbc177f12016-02-04 14:41:15 +0100510 return -1;
Peng Fan850dbca2016-01-28 16:51:26 +0800511
512 /* BOOT_CFG2[3] and BOOT_CFG2[4] */
513 devno = (soc_sbmr & 0x00001800) >> 11;
514
Soeren Mochbc177f12016-02-04 14:41:15 +0100515 return devno;
516}
517
518int mmc_get_env_dev(void)
519{
520 int devno = mmc_get_boot_dev();
521
522 /* If not boot from sd/mmc, use default value */
523 if (devno < 0)
524 return CONFIG_SYS_MMC_ENV_DEV;
525
Peng Fan850dbca2016-01-28 16:51:26 +0800526 return board_mmc_get_env_dev(devno);
527}
Soeren Mochbc177f12016-02-04 14:41:15 +0100528
529#ifdef CONFIG_SYS_MMC_ENV_PART
530__weak int board_mmc_get_env_part(int devno)
531{
532 return CONFIG_SYS_MMC_ENV_PART;
533}
534
535uint mmc_get_env_part(struct mmc *mmc)
536{
537 int devno = mmc_get_boot_dev();
538
539 /* If not boot from sd/mmc, use default value */
540 if (devno < 0)
541 return CONFIG_SYS_MMC_ENV_PART;
542
543 return board_mmc_get_env_part(devno);
544}
545#endif
Peng Fan850dbca2016-01-28 16:51:26 +0800546#endif
547
Fabio Estevam99b370b2013-12-26 14:51:34 -0200548int board_postclk_init(void)
549{
Peng Fan81224c42017-08-08 16:21:35 +0800550 /* NO LDO SOC on i.MX6SLL */
551 if (is_mx6sll())
552 return 0;
553
Fabio Estevam99b370b2013-12-26 14:51:34 -0200554 set_ldo_voltage(LDO_SOC, 1175); /* Set VDDSOC to 1.175V */
555
556 return 0;
557}
558
Anatolij Gustschin938734e2017-08-28 17:51:33 +0200559#ifndef CONFIG_SPL_BUILD
Troy Kisky0ca618c2012-08-15 10:31:20 +0000560/*
561 * cfg_val will be used for
562 * Boot_cfg4[7:0]:Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
Nikita Kiryanov9fba8422014-10-29 19:28:33 +0200563 * After reset, if GPR10[28] is 1, ROM will use GPR9[25:0]
564 * instead of SBMR1 to determine the boot device.
Troy Kisky0ca618c2012-08-15 10:31:20 +0000565 */
566const struct boot_mode soc_boot_modes[] = {
567 {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)},
568 /* reserved value should start rom usb */
Stefan Agner6b46c462017-06-09 13:13:12 -0700569#if defined(CONFIG_MX6UL) || defined(CONFIG_MX6ULL)
570 {"usb", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
571#else
Stefan Agnereb4b62b2016-09-15 15:04:39 -0700572 {"usb", MAKE_CFGVAL(0x10, 0x00, 0x00, 0x00)},
Stefan Agner6b46c462017-06-09 13:13:12 -0700573#endif
Troy Kisky0ca618c2012-08-15 10:31:20 +0000574 {"sata", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
Nikolay Dimitrov284d9012014-08-10 20:03:07 +0300575 {"ecspi1:0", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x08)},
576 {"ecspi1:1", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x18)},
577 {"ecspi1:2", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x28)},
578 {"ecspi1:3", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x38)},
Troy Kisky0ca618c2012-08-15 10:31:20 +0000579 /* 4 bit bus width */
580 {"esdhc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
581 {"esdhc2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
582 {"esdhc3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
583 {"esdhc4", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
584 {NULL, 0},
585};
Anatolij Gustschin938734e2017-08-28 17:51:33 +0200586#endif
Stephen Warren57ab23f2013-02-26 12:28:29 +0000587
Peng Fan92683e62015-10-29 15:54:50 +0800588void reset_misc(void)
589{
Michael Trimarchic41042a2018-06-20 23:27:54 +0200590#ifndef CONFIG_SPL_BUILD
Igor Opaniuka2ac2aa2019-06-19 11:47:08 +0300591#if defined(CONFIG_VIDEO_MXS) && !defined(CONFIG_DM_VIDEO)
Peng Fan92683e62015-10-29 15:54:50 +0800592 lcdif_power_down();
593#endif
Michael Trimarchic41042a2018-06-20 23:27:54 +0200594#endif
Peng Fan92683e62015-10-29 15:54:50 +0800595}
596
Stephen Warren57ab23f2013-02-26 12:28:29 +0000597void s_init(void)
598{
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700599 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Ye.Li29876872014-09-09 10:17:00 +0800600 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700601 u32 mask480;
602 u32 mask528;
Ye.Li29876872014-09-09 10:17:00 +0800603 u32 reg, periph1, periph2;
Fabio Estevam6633e3f2014-07-09 16:13:29 -0300604
Peng Fan81224c42017-08-08 16:21:35 +0800605 if (is_mx6sx() || is_mx6ul() || is_mx6ull() || is_mx6sll())
Fabio Estevam6633e3f2014-07-09 16:13:29 -0300606 return;
607
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700608 /* Due to hardware limitation, on MX6Q we need to gate/ungate all PFDs
609 * to make sure PFD is working right, otherwise, PFDs may
610 * not output clock after reset, MX6DL and MX6SL have added 396M pfd
611 * workaround in ROM code, as bus clock need it
612 */
613
614 mask480 = ANATOP_PFD_CLKGATE_MASK(0) |
615 ANATOP_PFD_CLKGATE_MASK(1) |
616 ANATOP_PFD_CLKGATE_MASK(2) |
617 ANATOP_PFD_CLKGATE_MASK(3);
Ye.Li29876872014-09-09 10:17:00 +0800618 mask528 = ANATOP_PFD_CLKGATE_MASK(1) |
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700619 ANATOP_PFD_CLKGATE_MASK(3);
620
Ye.Li29876872014-09-09 10:17:00 +0800621 reg = readl(&ccm->cbcmr);
622 periph2 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_MASK)
623 >> MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_OFFSET);
624 periph1 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK)
625 >> MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_OFFSET);
626
627 /* Checking if PLL2 PFD0 or PLL2 PFD2 is using for periph clock */
628 if ((periph2 != 0x2) && (periph1 != 0x2))
629 mask528 |= ANATOP_PFD_CLKGATE_MASK(0);
630
631 if ((periph2 != 0x1) && (periph1 != 0x1) &&
632 (periph2 != 0x3) && (periph1 != 0x3))
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700633 mask528 |= ANATOP_PFD_CLKGATE_MASK(2);
Ye.Li29876872014-09-09 10:17:00 +0800634
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700635 writel(mask480, &anatop->pfd_480_set);
636 writel(mask528, &anatop->pfd_528_set);
637 writel(mask480, &anatop->pfd_480_clr);
638 writel(mask528, &anatop->pfd_528_clr);
Stephen Warren57ab23f2013-02-26 12:28:29 +0000639}
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -0500640
641#ifdef CONFIG_IMX_HDMI
642void imx_enable_hdmi_phy(void)
643{
644 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
645 u8 reg;
646 reg = readb(&hdmi->phy_conf0);
647 reg |= HDMI_PHY_CONF0_PDZ_MASK;
648 writeb(reg, &hdmi->phy_conf0);
649 udelay(3000);
650 reg |= HDMI_PHY_CONF0_ENTMDS_MASK;
651 writeb(reg, &hdmi->phy_conf0);
652 udelay(3000);
653 reg |= HDMI_PHY_CONF0_GEN2_TXPWRON_MASK;
654 writeb(reg, &hdmi->phy_conf0);
655 writeb(HDMI_MC_PHYRSTZ_ASSERT, &hdmi->mc_phyrstz);
656}
657
658void imx_setup_hdmi(void)
659{
660 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
661 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
Peng Fan95ae6122016-03-09 16:07:23 +0800662 int reg, count;
663 u8 val;
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -0500664
665 /* Turn on HDMI PHY clock */
666 reg = readl(&mxc_ccm->CCGR2);
667 reg |= MXC_CCM_CCGR2_HDMI_TX_IAHBCLK_MASK|
668 MXC_CCM_CCGR2_HDMI_TX_ISFRCLK_MASK;
669 writel(reg, &mxc_ccm->CCGR2);
670 writeb(HDMI_MC_PHYRSTZ_DEASSERT, &hdmi->mc_phyrstz);
671 reg = readl(&mxc_ccm->chsccdr);
672 reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK|
673 MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK|
674 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK);
675 reg |= (CHSCCDR_PODF_DIVIDE_BY_3
676 << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET)
677 |(CHSCCDR_IPU_PRE_CLK_540M_PFD
678 << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET);
679 writel(reg, &mxc_ccm->chsccdr);
Peng Fan95ae6122016-03-09 16:07:23 +0800680
681 /* Clear the overflow condition */
682 if (readb(&hdmi->ih_fc_stat2) & HDMI_IH_FC_STAT2_OVERFLOW_MASK) {
683 /* TMDS software reset */
684 writeb((u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, &hdmi->mc_swrstz);
685 val = readb(&hdmi->fc_invidconf);
686 /* Need minimum 3 times to write to clear the register */
687 for (count = 0 ; count < 5 ; count++)
688 writeb(val, &hdmi->fc_invidconf);
689 }
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -0500690}
691#endif
Peng Fanfb3a3b72016-01-28 16:55:05 +0800692
Michael Trimarchid9de3f82018-06-23 16:10:06 +0200693
694/*
695 * gpr_init() function is common for boards using MX6S, MX6DL, MX6D,
696 * MX6Q and MX6QP processors
697 */
Breno Limaf22b1092017-08-24 10:00:16 -0300698void gpr_init(void)
699{
700 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
701
Christoph Niedermaier2082ebf2018-10-19 17:40:54 +0200702 /*
703 * If this function is used in a common MX6 spl implementation
704 * we have to ensure that it is only called for suitable cpu types,
705 * otherwise it breaks hardware parts like enet1, can1, can2, etc.
706 */
707 if (!is_mx6dqp() && !is_mx6dq() && !is_mx6sdl())
708 return;
709
Breno Limaf22b1092017-08-24 10:00:16 -0300710 /* enable AXI cache for VDOA/VPU/IPU */
711 writel(0xF00000CF, &iomux->gpr[4]);
712 if (is_mx6dqp()) {
713 /* set IPU AXI-id1 Qos=0x1 AXI-id0/2/3 Qos=0x7 */
714 writel(0x77177717, &iomux->gpr[6]);
715 writel(0x77177717, &iomux->gpr[7]);
716 } else {
717 /* set IPU AXI-id0 Qos=0xf(bypass) AXI-id1 Qos=0x7 */
718 writel(0x007F007F, &iomux->gpr[6]);
719 writel(0x007F007F, &iomux->gpr[7]);
720 }
721}