blob: a636107410eec82a5a6b7b8b19a0b52de435e6cc [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>
Simon Glassdbd79542020-05-10 11:40:11 -060011#include <linux/delay.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090012#include <linux/errno.h>
Jason Liudec11122011-11-25 00:18:02 +000013#include <asm/io.h>
14#include <asm/arch/imx-regs.h>
15#include <asm/arch/clock.h>
16#include <asm/arch/sys_proto.h>
Diego Dorta3a5bf532017-09-27 13:12:37 -030017#include <asm/bootm.h>
Stefano Babic33731bc2017-06-29 10:16:06 +020018#include <asm/mach-imx/boot_mode.h>
19#include <asm/mach-imx/dma.h>
20#include <asm/mach-imx/hab.h>
Fabio Estevam48e65b02013-02-07 06:45:23 +000021#include <stdbool.h>
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -050022#include <asm/arch/mxc_hdmi.h>
23#include <asm/arch/crm_regs.h>
Ye.Lif19692c2014-11-20 21:14:14 +080024#include <dm.h>
Heinrich Schuchardtcdd0c852020-06-26 19:57:55 +020025#include <fsl_sec.h>
Ye.Lif19692c2014-11-20 21:14:14 +080026#include <imx_thermal.h>
Soeren Mochbc177f12016-02-04 14:41:15 +010027#include <mmc.h>
Jason Liudec11122011-11-25 00:18:02 +000028
Troy Kisky58394932012-10-23 10:57:46 +000029struct scu_regs {
30 u32 ctrl;
31 u32 config;
32 u32 status;
33 u32 invalidate;
34 u32 fpga_rev;
35};
36
Simon Glass8c19f7b2020-10-29 11:08:25 -060037#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_IMX_THERMAL)
Ye.Lif19692c2014-11-20 21:14:14 +080038static const struct imx_thermal_plat imx6_thermal_plat = {
39 .regs = (void *)ANATOP_BASE_ADDR,
40 .fuse_bank = 1,
41 .fuse_word = 6,
42};
43
44U_BOOT_DEVICE(imx6_thermal) = {
45 .name = "imx_thermal",
46 .platdata = &imx6_thermal_plat,
47};
48#endif
49
Stefano Babicf8b509b2019-09-20 08:47:53 +020050#if defined(CONFIG_IMX_HAB)
Adrian Alonso6ec8d842015-10-12 13:48:12 -050051struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
52 .bank = 0,
53 .word = 6,
54};
55#endif
56
Gabriel Huau170ceaf2014-07-26 11:35:43 -070057u32 get_nr_cpus(void)
58{
59 struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
60 return readl(&scu->config) & 3;
61}
62
Jason Liudec11122011-11-25 00:18:02 +000063u32 get_cpu_rev(void)
64{
Fabio Estevam46e97332012-03-20 04:21:45 +000065 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Troy Kisky58394932012-10-23 10:57:46 +000066 u32 reg = readl(&anatop->digprog_sololite);
67 u32 type = ((reg >> 16) & 0xff);
Peng Fan5f247922015-07-11 11:38:42 +080068 u32 major, cfg = 0;
Fabio Estevam46e97332012-03-20 04:21:45 +000069
Troy Kisky58394932012-10-23 10:57:46 +000070 if (type != MXC_CPU_MX6SL) {
71 reg = readl(&anatop->digprog);
Fabio Estevamf3d5a2c2014-01-26 15:06:41 -020072 struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
Peng Fan5f247922015-07-11 11:38:42 +080073 cfg = readl(&scu->config) & 3;
Troy Kisky58394932012-10-23 10:57:46 +000074 type = ((reg >> 16) & 0xff);
75 if (type == MXC_CPU_MX6DL) {
Troy Kisky58394932012-10-23 10:57:46 +000076 if (!cfg)
77 type = MXC_CPU_MX6SOLO;
78 }
Fabio Estevamf3d5a2c2014-01-26 15:06:41 -020079
80 if (type == MXC_CPU_MX6Q) {
81 if (cfg == 1)
82 type = MXC_CPU_MX6D;
83 }
84
Peng Fanc53d0c92019-08-08 09:55:52 +000085 if (type == MXC_CPU_MX6ULL) {
86 if (readl(SRC_BASE_ADDR + 0x1c) & (1 << 6))
87 type = MXC_CPU_MX6ULZ;
88 }
Troy Kisky58394932012-10-23 10:57:46 +000089 }
Peng Fan88383232015-06-11 18:30:36 +080090 major = ((reg >> 8) & 0xff);
Peng Fan5f247922015-07-11 11:38:42 +080091 if ((major >= 1) &&
92 ((type == MXC_CPU_MX6Q) || (type == MXC_CPU_MX6D))) {
93 major--;
94 type = MXC_CPU_MX6QP;
95 if (cfg == 1)
96 type = MXC_CPU_MX6DP;
97 }
Troy Kisky58394932012-10-23 10:57:46 +000098 reg &= 0xff; /* mx6 silicon revision */
Ye Li10f19c72019-07-10 10:38:37 +000099
100 /* For 6DQ, the value 0x00630005 is Silicon revision 1.3*/
101 if (((type == MXC_CPU_MX6Q) || (type == MXC_CPU_MX6D)) && (reg == 0x5))
102 reg = 0x3;
103
Peng Fan88383232015-06-11 18:30:36 +0800104 return (type << 12) | (reg + (0x10 * (major + 1)));
Jason Liudec11122011-11-25 00:18:02 +0000105}
106
Tim Harvey258d0462015-05-18 07:02:24 -0700107/*
108 * OCOTP_CFG3[17:16] (see Fusemap Description Table offset 0x440)
109 * defines a 2-bit SPEED_GRADING
110 */
111#define OCOTP_CFG3_SPEED_SHIFT 16
112#define OCOTP_CFG3_SPEED_800MHZ 0
113#define OCOTP_CFG3_SPEED_850MHZ 1
114#define OCOTP_CFG3_SPEED_1GHZ 2
115#define OCOTP_CFG3_SPEED_1P2GHZ 3
116
Peng Fan441e9052016-05-03 11:13:04 +0800117/*
118 * For i.MX6UL
119 */
120#define OCOTP_CFG3_SPEED_528MHZ 1
121#define OCOTP_CFG3_SPEED_696MHZ 2
122
Sébastien Szymanskib130c8a2017-08-02 17:05:27 +0200123/*
124 * For i.MX6ULL
125 */
126#define OCOTP_CFG3_SPEED_792MHZ 2
127#define OCOTP_CFG3_SPEED_900MHZ 3
128
Tim Harvey258d0462015-05-18 07:02:24 -0700129u32 get_cpu_speed_grade_hz(void)
130{
131 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
132 struct fuse_bank *bank = &ocotp->bank[0];
133 struct fuse_bank0_regs *fuse =
134 (struct fuse_bank0_regs *)bank->fuse_regs;
135 uint32_t val;
136
137 val = readl(&fuse->cfg3);
138 val >>= OCOTP_CFG3_SPEED_SHIFT;
139 val &= 0x3;
140
Sébastien Szymanskib130c8a2017-08-02 17:05:27 +0200141 if (is_mx6ul()) {
Peng Fan441e9052016-05-03 11:13:04 +0800142 if (val == OCOTP_CFG3_SPEED_528MHZ)
143 return 528000000;
144 else if (val == OCOTP_CFG3_SPEED_696MHZ)
Sébastien Szymanski415c7ce2017-08-02 17:05:26 +0200145 return 696000000;
Peng Fan441e9052016-05-03 11:13:04 +0800146 else
147 return 0;
148 }
149
Sébastien Szymanskib130c8a2017-08-02 17:05:27 +0200150 if (is_mx6ull()) {
151 if (val == OCOTP_CFG3_SPEED_528MHZ)
152 return 528000000;
153 else if (val == OCOTP_CFG3_SPEED_792MHZ)
154 return 792000000;
155 else if (val == OCOTP_CFG3_SPEED_900MHZ)
156 return 900000000;
157 else
158 return 0;
159 }
160
Tim Harvey258d0462015-05-18 07:02:24 -0700161 switch (val) {
162 /* Valid for IMX6DQ */
163 case OCOTP_CFG3_SPEED_1P2GHZ:
Peng Fan6c4f76f2016-05-23 18:35:58 +0800164 if (is_mx6dq() || is_mx6dqp())
Tim Harvey258d0462015-05-18 07:02:24 -0700165 return 1200000000;
166 /* Valid for IMX6SX/IMX6SDL/IMX6DQ */
167 case OCOTP_CFG3_SPEED_1GHZ:
168 return 996000000;
169 /* Valid for IMX6DQ */
170 case OCOTP_CFG3_SPEED_850MHZ:
Peng Fan6c4f76f2016-05-23 18:35:58 +0800171 if (is_mx6dq() || is_mx6dqp())
Tim Harvey258d0462015-05-18 07:02:24 -0700172 return 852000000;
173 /* Valid for IMX6SX/IMX6SDL/IMX6DQ */
174 case OCOTP_CFG3_SPEED_800MHZ:
175 return 792000000;
176 }
177 return 0;
178}
179
Tim Harvey5e0e1932015-05-18 06:56:45 -0700180/*
181 * OCOTP_MEM0[7:6] (see Fusemap Description Table offset 0x480)
182 * defines a 2-bit Temperature Grade
183 *
Fabio Estevama24859c2017-06-22 10:50:05 -0300184 * return temperature grade and min/max temperature in Celsius
Tim Harvey5e0e1932015-05-18 06:56:45 -0700185 */
186#define OCOTP_MEM0_TEMP_SHIFT 6
187
188u32 get_cpu_temp_grade(int *minc, int *maxc)
189{
190 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
191 struct fuse_bank *bank = &ocotp->bank[1];
192 struct fuse_bank1_regs *fuse =
193 (struct fuse_bank1_regs *)bank->fuse_regs;
194 uint32_t val;
195
196 val = readl(&fuse->mem0);
197 val >>= OCOTP_MEM0_TEMP_SHIFT;
198 val &= 0x3;
199
200 if (minc && maxc) {
201 if (val == TEMP_AUTOMOTIVE) {
202 *minc = -40;
203 *maxc = 125;
204 } else if (val == TEMP_INDUSTRIAL) {
205 *minc = -40;
206 *maxc = 105;
207 } else if (val == TEMP_EXTCOMMERCIAL) {
208 *minc = -20;
209 *maxc = 105;
210 } else {
211 *minc = 0;
212 *maxc = 95;
213 }
214 }
215 return val;
216}
217
Fabio Estevam435998b2013-03-27 07:36:55 +0000218#ifdef CONFIG_REVISION_TAG
219u32 __weak get_board_rev(void)
220{
221 u32 cpurev = get_cpu_rev();
222 u32 type = ((cpurev >> 12) & 0xff);
223 if (type == MXC_CPU_MX6SOLO)
224 cpurev = (MXC_CPU_MX6DL) << 12 | (cpurev & 0xFFF);
225
Fabio Estevamf3d5a2c2014-01-26 15:06:41 -0200226 if (type == MXC_CPU_MX6D)
227 cpurev = (MXC_CPU_MX6Q) << 12 | (cpurev & 0xFFF);
228
Fabio Estevam435998b2013-03-27 07:36:55 +0000229 return cpurev;
230}
231#endif
232
Fabio Estevamcf621ff2013-12-26 14:51:31 -0200233static void clear_ldo_ramp(void)
234{
235 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
236 int reg;
237
238 /* ROM may modify LDO ramp up time according to fuse setting, so in
239 * order to be in the safe side we neeed to reset these settings to
240 * match the reset value: 0'b00
241 */
242 reg = readl(&anatop->ana_misc2);
243 reg &= ~(0x3f << 24);
244 writel(reg, &anatop->ana_misc2);
245}
246
Dirk Behme8c465942012-05-02 02:12:17 +0000247/*
Fabio Estevam2e95fe12014-06-13 01:42:37 -0300248 * Set the PMU_REG_CORE register
Dirk Behme8c465942012-05-02 02:12:17 +0000249 *
Fabio Estevam2e95fe12014-06-13 01:42:37 -0300250 * Set LDO_SOC/PU/ARM regulators to the specified millivolt level.
Dirk Behme8c465942012-05-02 02:12:17 +0000251 * Possible values are from 0.725V to 1.450V in steps of
252 * 0.025V (25mV).
253 */
Marek Vasut02fec412019-11-26 09:35:32 +0100254int set_ldo_voltage(enum ldo_reg ldo, u32 mv)
Dirk Behme8c465942012-05-02 02:12:17 +0000255{
256 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Fabio Estevam99b370b2013-12-26 14:51:34 -0200257 u32 val, step, old, reg = readl(&anatop->reg_core);
Fabio Estevama47ec522013-12-26 14:51:33 -0200258 u8 shift;
Dirk Behme8c465942012-05-02 02:12:17 +0000259
Peng Fan81224c42017-08-08 16:21:35 +0800260 /* No LDO_SOC/PU/ARM */
261 if (is_mx6sll())
262 return 0;
263
Dirk Behme8c465942012-05-02 02:12:17 +0000264 if (mv < 725)
265 val = 0x00; /* Power gated off */
266 else if (mv > 1450)
267 val = 0x1F; /* Power FET switched full on. No regulation */
268 else
269 val = (mv - 700) / 25;
270
Fabio Estevamcf621ff2013-12-26 14:51:31 -0200271 clear_ldo_ramp();
272
Fabio Estevama47ec522013-12-26 14:51:33 -0200273 switch (ldo) {
274 case LDO_SOC:
275 shift = 18;
276 break;
277 case LDO_PU:
278 shift = 9;
279 break;
280 case LDO_ARM:
281 shift = 0;
282 break;
283 default:
284 return -EINVAL;
285 }
286
Fabio Estevam99b370b2013-12-26 14:51:34 -0200287 old = (reg & (0x1F << shift)) >> shift;
288 step = abs(val - old);
289 if (step == 0)
290 return 0;
291
Fabio Estevama47ec522013-12-26 14:51:33 -0200292 reg = (reg & ~(0x1F << shift)) | (val << shift);
Dirk Behme8c465942012-05-02 02:12:17 +0000293 writel(reg, &anatop->reg_core);
Fabio Estevama47ec522013-12-26 14:51:33 -0200294
Fabio Estevam99b370b2013-12-26 14:51:34 -0200295 /*
296 * The LDO ramp-up is based on 64 clock cycles of 24 MHz = 2.6 us per
297 * step
298 */
299 udelay(3 * step);
300
Fabio Estevama47ec522013-12-26 14:51:33 -0200301 return 0;
Dirk Behme8c465942012-05-02 02:12:17 +0000302}
303
Anson Huang05a464f2014-01-23 14:00:18 +0800304static void set_ahb_rate(u32 val)
305{
306 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
307 u32 reg, div;
308
309 div = get_periph_clk() / val - 1;
310 reg = readl(&mxc_ccm->cbcdr);
311
312 writel((reg & (~MXC_CCM_CBCDR_AHB_PODF_MASK)) |
313 (div << MXC_CCM_CBCDR_AHB_PODF_OFFSET), &mxc_ccm->cbcdr);
314}
315
Anson Huang9a149bc2014-01-23 14:00:19 +0800316static void clear_mmdc_ch_mask(void)
317{
318 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Peng Fan53f3c9e2015-07-11 11:38:43 +0800319 u32 reg;
320 reg = readl(&mxc_ccm->ccdr);
Anson Huang9a149bc2014-01-23 14:00:19 +0800321
322 /* Clear MMDC channel mask */
Peng Fan81224c42017-08-08 16:21:35 +0800323 if (is_mx6sx() || is_mx6ul() || is_mx6ull() || is_mx6sl() || is_mx6sll())
Ye Li64cef442016-03-09 16:13:48 +0800324 reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK);
325 else
326 reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK | MXC_CCM_CCDR_MMDC_CH0_HS_MASK);
Peng Fan53f3c9e2015-07-11 11:38:43 +0800327 writel(reg, &mxc_ccm->ccdr);
Anson Huang9a149bc2014-01-23 14:00:19 +0800328}
329
Peng Fan656d2332016-10-08 17:03:00 +0800330#define OCOTP_MEM0_REFTOP_TRIM_SHIFT 8
331
Peng Fanc0e0ebf2015-01-15 14:22:32 +0800332static void init_bandgap(void)
333{
334 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Peng Fan656d2332016-10-08 17:03:00 +0800335 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
336 struct fuse_bank *bank = &ocotp->bank[1];
337 struct fuse_bank1_regs *fuse =
338 (struct fuse_bank1_regs *)bank->fuse_regs;
339 uint32_t val;
340
Peng Fanc0e0ebf2015-01-15 14:22:32 +0800341 /*
342 * Ensure the bandgap has stabilized.
343 */
344 while (!(readl(&anatop->ana_misc0) & 0x80))
345 ;
346 /*
347 * For best noise performance of the analog blocks using the
348 * outputs of the bandgap, the reftop_selfbiasoff bit should
349 * be set.
350 */
351 writel(BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF, &anatop->ana_misc0_set);
Peng Fan6b989352016-08-11 14:02:50 +0800352 /*
Peng Fan656d2332016-10-08 17:03:00 +0800353 * On i.MX6ULL,we need to set VBGADJ bits according to the
354 * REFTOP_TRIM[3:0] in fuse table
355 * 000 - set REFTOP_VBGADJ[2:0] to 3b'110,
356 * 110 - set REFTOP_VBGADJ[2:0] to 3b'000,
357 * 001 - set REFTOP_VBGADJ[2:0] to 3b'001,
358 * 010 - set REFTOP_VBGADJ[2:0] to 3b'010,
359 * 011 - set REFTOP_VBGADJ[2:0] to 3b'011,
360 * 100 - set REFTOP_VBGADJ[2:0] to 3b'100,
361 * 101 - set REFTOP_VBGADJ[2:0] to 3b'101,
362 * 111 - set REFTOP_VBGADJ[2:0] to 3b'111,
Peng Fan6b989352016-08-11 14:02:50 +0800363 */
Peng Fan656d2332016-10-08 17:03:00 +0800364 if (is_mx6ull()) {
365 val = readl(&fuse->mem0);
366 val >>= OCOTP_MEM0_REFTOP_TRIM_SHIFT;
367 val &= 0x7;
Peng Fanc0e0ebf2015-01-15 14:22:32 +0800368
Peng Fan656d2332016-10-08 17:03:00 +0800369 writel(val << BM_ANADIG_ANA_MISC0_REFTOP_VBGADJ_SHIFT,
370 &anatop->ana_misc0_set);
371 }
372}
Peng Fanc0e0ebf2015-01-15 14:22:32 +0800373
Fabio Estevam3e59fa92019-11-04 09:44:34 -0300374#if defined(CONFIG_MX6Q) || defined(CONFIG_MX6QDL)
375static void noc_setup(void)
376{
377 enable_ipu_clock();
378
379 writel(0x80000201, 0xbb0608);
380 /* Bypass IPU1 QoS generator */
381 writel(0x00000002, 0x00bb048c);
382 /* Bypass IPU2 QoS generator */
383 writel(0x00000002, 0x00bb050c);
384 /* Bandwidth THR for of PRE0 */
385 writel(0x00000200, 0x00bb0690);
386 /* Bandwidth THR for of PRE1 */
387 writel(0x00000200, 0x00bb0710);
388 /* Bandwidth THR for of PRE2 */
389 writel(0x00000200, 0x00bb0790);
390 /* Bandwidth THR for of PRE3 */
391 writel(0x00000200, 0x00bb0810);
392 /* Saturation THR for of PRE0 */
393 writel(0x00000010, 0x00bb0694);
394 /* Saturation THR for of PRE1 */
395 writel(0x00000010, 0x00bb0714);
396 /* Saturation THR for of PRE2 */
397 writel(0x00000010, 0x00bb0794);
398 /* Saturation THR for of PRE */
399 writel(0x00000010, 0x00bb0814);
400
401 disable_ipu_clock();
402}
403#endif
404
Jason Liudec11122011-11-25 00:18:02 +0000405int arch_cpu_init(void)
406{
Peng Fan946333d2017-08-08 16:21:38 +0800407 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
408
Jason Liudec11122011-11-25 00:18:02 +0000409 init_aips();
410
Anson Huang9a149bc2014-01-23 14:00:19 +0800411 /* Need to clear MMDC_CHx_MASK to make warm reset work. */
412 clear_mmdc_ch_mask();
413
Anson Huang05a464f2014-01-23 14:00:18 +0800414 /*
Peng Fanc0e0ebf2015-01-15 14:22:32 +0800415 * Disable self-bias circuit in the analog bandap.
416 * The self-bias circuit is used by the bandgap during startup.
417 * This bit should be set after the bandgap has initialized.
418 */
419 init_bandgap();
420
Peng Fanae86e3f2016-08-11 14:02:43 +0800421 if (!is_mx6ul() && !is_mx6ull()) {
Peng Fanf60137e2016-03-09 16:44:36 +0800422 /*
423 * When low freq boot is enabled, ROM will not set AHB
424 * freq, so we need to ensure AHB freq is 132MHz in such
425 * scenario.
426 *
427 * To i.MX6UL, when power up, default ARM core and
428 * AHB rate is 396M and 132M.
429 */
430 if (mxc_get_clock(MXC_ARM_CLK) == 396000000)
431 set_ahb_rate(132000000);
432 }
Anson Huang05a464f2014-01-23 14:00:18 +0800433
Peng Fan2b990ea2016-09-28 09:40:27 +0800434 if (is_mx6ul()) {
435 if (is_soc_rev(CHIP_REV_1_0) == 0) {
436 /*
437 * According to the design team's requirement on
438 * i.MX6UL,the PMIC_STBY_REQ PAD should be configured
439 * as open drain 100K (0x0000b8a0).
440 * Only exists on TO1.0
441 */
442 writel(0x0000b8a0, IOMUXC_BASE_ADDR + 0x29c);
443 } else {
444 /*
445 * From TO1.1, SNVS adds internal pull up control
446 * for POR_B, the register filed is GPBIT[1:0],
447 * after system boot up, it can be set to 2b'01
448 * to disable internal pull up.It can save about
449 * 30uA power in SNVS mode.
450 */
451 writel((readl(MX6UL_SNVS_LP_BASE_ADDR + 0x10) &
452 (~0x1400)) | 0x400,
453 MX6UL_SNVS_LP_BASE_ADDR + 0x10);
454 }
Peng Fana2cba652016-03-09 16:44:37 +0800455 }
456
Peng Fanb64bf0b2016-08-11 14:02:46 +0800457 if (is_mx6ull()) {
458 /*
459 * GPBIT[1:0] is suggested to set to 2'b11:
460 * 2'b00 : always PUP100K
461 * 2'b01 : PUP100K when PMIC_ON_REQ or SOC_NOT_FAIL
462 * 2'b10 : always disable PUP100K
463 * 2'b11 : PDN100K when SOC_FAIL, PUP100K when SOC_NOT_FAIL
464 * register offset is different from i.MX6UL, since
465 * i.MX6UL is fixed by ECO.
466 */
467 writel(readl(MX6UL_SNVS_LP_BASE_ADDR) |
468 0x3, MX6UL_SNVS_LP_BASE_ADDR);
469 }
470
Peng Fana2cba652016-03-09 16:44:37 +0800471 /* Set perclk to source from OSC 24MHz */
Peng Fanfe7052a2017-08-08 16:21:39 +0800472 if (is_mx6sl())
473 setbits_le32(&ccm->cscmr1, MXC_CCM_CSCMR1_PER_CLK_SEL_MASK);
Ye.Li622dfbd2014-10-30 18:20:58 +0800474
Fabio Estevam5f79d462017-11-23 10:55:33 -0200475 imx_wdog_disable_powerdown(); /* Disable PDE bit of WMCR register */
Stefan Roese8338d1d2013-04-15 21:14:12 +0000476
Peng Fan946333d2017-08-08 16:21:38 +0800477 if (is_mx6sx())
478 setbits_le32(&ccm->cscdr1, MXC_CCM_CSCDR1_UART_CLK_SEL);
479
Dirk Behme0adb2152015-03-09 14:48:48 +0100480 init_src();
481
Fabio Estevam3e59fa92019-11-04 09:44:34 -0300482#if defined(CONFIG_MX6Q) || defined(CONFIG_MX6QDL)
483 if (is_mx6dqp())
484 noc_setup();
485#endif
Jason Liudec11122011-11-25 00:18:02 +0000486 return 0;
487}
Jason Liudec11122011-11-25 00:18:02 +0000488
Peng Fan850dbca2016-01-28 16:51:26 +0800489#ifdef CONFIG_ENV_IS_IN_MMC
490__weak int board_mmc_get_env_dev(int devno)
491{
492 return CONFIG_SYS_MMC_ENV_DEV;
493}
494
Soeren Mochbc177f12016-02-04 14:41:15 +0100495static int mmc_get_boot_dev(void)
Peng Fan850dbca2016-01-28 16:51:26 +0800496{
497 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
498 u32 soc_sbmr = readl(&src_regs->sbmr1);
499 u32 bootsel;
500 int devno;
501
502 /*
503 * Refer to
504 * "i.MX 6Dual/6Quad Applications Processor Reference Manual"
505 * Chapter "8.5.3.1 Expansion Device eFUSE Configuration"
506 * i.MX6SL/SX/UL has same layout.
507 */
508 bootsel = (soc_sbmr & 0x000000FF) >> 6;
509
Soeren Mochbc177f12016-02-04 14:41:15 +0100510 /* No boot from sd/mmc */
Peng Fan850dbca2016-01-28 16:51:26 +0800511 if (bootsel != 1)
Soeren Mochbc177f12016-02-04 14:41:15 +0100512 return -1;
Peng Fan850dbca2016-01-28 16:51:26 +0800513
514 /* BOOT_CFG2[3] and BOOT_CFG2[4] */
515 devno = (soc_sbmr & 0x00001800) >> 11;
516
Soeren Mochbc177f12016-02-04 14:41:15 +0100517 return devno;
518}
519
520int mmc_get_env_dev(void)
521{
522 int devno = mmc_get_boot_dev();
523
524 /* If not boot from sd/mmc, use default value */
525 if (devno < 0)
526 return CONFIG_SYS_MMC_ENV_DEV;
527
Peng Fan850dbca2016-01-28 16:51:26 +0800528 return board_mmc_get_env_dev(devno);
529}
Soeren Mochbc177f12016-02-04 14:41:15 +0100530
531#ifdef CONFIG_SYS_MMC_ENV_PART
532__weak int board_mmc_get_env_part(int devno)
533{
534 return CONFIG_SYS_MMC_ENV_PART;
535}
536
537uint mmc_get_env_part(struct mmc *mmc)
538{
539 int devno = mmc_get_boot_dev();
540
541 /* If not boot from sd/mmc, use default value */
542 if (devno < 0)
543 return CONFIG_SYS_MMC_ENV_PART;
544
545 return board_mmc_get_env_part(devno);
546}
547#endif
Peng Fan850dbca2016-01-28 16:51:26 +0800548#endif
549
Fabio Estevam99b370b2013-12-26 14:51:34 -0200550int board_postclk_init(void)
551{
Peng Fan81224c42017-08-08 16:21:35 +0800552 /* NO LDO SOC on i.MX6SLL */
553 if (is_mx6sll())
554 return 0;
555
Fabio Estevam99b370b2013-12-26 14:51:34 -0200556 set_ldo_voltage(LDO_SOC, 1175); /* Set VDDSOC to 1.175V */
557
558 return 0;
559}
560
Anatolij Gustschin938734e2017-08-28 17:51:33 +0200561#ifndef CONFIG_SPL_BUILD
Troy Kisky0ca618c2012-08-15 10:31:20 +0000562/*
563 * cfg_val will be used for
564 * Boot_cfg4[7:0]:Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
Nikita Kiryanov9fba8422014-10-29 19:28:33 +0200565 * After reset, if GPR10[28] is 1, ROM will use GPR9[25:0]
566 * instead of SBMR1 to determine the boot device.
Troy Kisky0ca618c2012-08-15 10:31:20 +0000567 */
568const struct boot_mode soc_boot_modes[] = {
569 {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)},
570 /* reserved value should start rom usb */
Stefan Agner6b46c462017-06-09 13:13:12 -0700571#if defined(CONFIG_MX6UL) || defined(CONFIG_MX6ULL)
572 {"usb", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
573#else
Stefan Agnereb4b62b2016-09-15 15:04:39 -0700574 {"usb", MAKE_CFGVAL(0x10, 0x00, 0x00, 0x00)},
Stefan Agner6b46c462017-06-09 13:13:12 -0700575#endif
Troy Kisky0ca618c2012-08-15 10:31:20 +0000576 {"sata", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
Nikolay Dimitrov284d9012014-08-10 20:03:07 +0300577 {"ecspi1:0", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x08)},
578 {"ecspi1:1", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x18)},
579 {"ecspi1:2", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x28)},
580 {"ecspi1:3", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x38)},
Troy Kisky0ca618c2012-08-15 10:31:20 +0000581 /* 4 bit bus width */
582 {"esdhc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
583 {"esdhc2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
584 {"esdhc3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
585 {"esdhc4", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
586 {NULL, 0},
587};
Anatolij Gustschin938734e2017-08-28 17:51:33 +0200588#endif
Stephen Warren57ab23f2013-02-26 12:28:29 +0000589
Peng Fan92683e62015-10-29 15:54:50 +0800590void reset_misc(void)
591{
Michael Trimarchic41042a2018-06-20 23:27:54 +0200592#ifndef CONFIG_SPL_BUILD
Igor Opaniuka2ac2aa2019-06-19 11:47:08 +0300593#if defined(CONFIG_VIDEO_MXS) && !defined(CONFIG_DM_VIDEO)
Peng Fan92683e62015-10-29 15:54:50 +0800594 lcdif_power_down();
595#endif
Michael Trimarchic41042a2018-06-20 23:27:54 +0200596#endif
Peng Fan92683e62015-10-29 15:54:50 +0800597}
598
Stephen Warren57ab23f2013-02-26 12:28:29 +0000599void s_init(void)
600{
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700601 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Ye.Li29876872014-09-09 10:17:00 +0800602 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700603 u32 mask480;
604 u32 mask528;
Ye.Li29876872014-09-09 10:17:00 +0800605 u32 reg, periph1, periph2;
Fabio Estevam6633e3f2014-07-09 16:13:29 -0300606
Peng Fan81224c42017-08-08 16:21:35 +0800607 if (is_mx6sx() || is_mx6ul() || is_mx6ull() || is_mx6sll())
Fabio Estevam6633e3f2014-07-09 16:13:29 -0300608 return;
609
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700610 /* Due to hardware limitation, on MX6Q we need to gate/ungate all PFDs
611 * to make sure PFD is working right, otherwise, PFDs may
612 * not output clock after reset, MX6DL and MX6SL have added 396M pfd
613 * workaround in ROM code, as bus clock need it
614 */
615
616 mask480 = ANATOP_PFD_CLKGATE_MASK(0) |
617 ANATOP_PFD_CLKGATE_MASK(1) |
618 ANATOP_PFD_CLKGATE_MASK(2) |
619 ANATOP_PFD_CLKGATE_MASK(3);
Ye.Li29876872014-09-09 10:17:00 +0800620 mask528 = ANATOP_PFD_CLKGATE_MASK(1) |
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700621 ANATOP_PFD_CLKGATE_MASK(3);
622
Ye.Li29876872014-09-09 10:17:00 +0800623 reg = readl(&ccm->cbcmr);
624 periph2 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_MASK)
625 >> MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_OFFSET);
626 periph1 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK)
627 >> MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_OFFSET);
628
629 /* Checking if PLL2 PFD0 or PLL2 PFD2 is using for periph clock */
630 if ((periph2 != 0x2) && (periph1 != 0x2))
631 mask528 |= ANATOP_PFD_CLKGATE_MASK(0);
632
633 if ((periph2 != 0x1) && (periph1 != 0x1) &&
634 (periph2 != 0x3) && (periph1 != 0x3))
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700635 mask528 |= ANATOP_PFD_CLKGATE_MASK(2);
Ye.Li29876872014-09-09 10:17:00 +0800636
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700637 writel(mask480, &anatop->pfd_480_set);
638 writel(mask528, &anatop->pfd_528_set);
639 writel(mask480, &anatop->pfd_480_clr);
640 writel(mask528, &anatop->pfd_528_clr);
Stephen Warren57ab23f2013-02-26 12:28:29 +0000641}
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -0500642
643#ifdef CONFIG_IMX_HDMI
644void imx_enable_hdmi_phy(void)
645{
646 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
647 u8 reg;
648 reg = readb(&hdmi->phy_conf0);
649 reg |= HDMI_PHY_CONF0_PDZ_MASK;
650 writeb(reg, &hdmi->phy_conf0);
651 udelay(3000);
652 reg |= HDMI_PHY_CONF0_ENTMDS_MASK;
653 writeb(reg, &hdmi->phy_conf0);
654 udelay(3000);
655 reg |= HDMI_PHY_CONF0_GEN2_TXPWRON_MASK;
656 writeb(reg, &hdmi->phy_conf0);
657 writeb(HDMI_MC_PHYRSTZ_ASSERT, &hdmi->mc_phyrstz);
658}
659
660void imx_setup_hdmi(void)
661{
662 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
663 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
Peng Fan95ae6122016-03-09 16:07:23 +0800664 int reg, count;
665 u8 val;
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -0500666
667 /* Turn on HDMI PHY clock */
668 reg = readl(&mxc_ccm->CCGR2);
669 reg |= MXC_CCM_CCGR2_HDMI_TX_IAHBCLK_MASK|
670 MXC_CCM_CCGR2_HDMI_TX_ISFRCLK_MASK;
671 writel(reg, &mxc_ccm->CCGR2);
672 writeb(HDMI_MC_PHYRSTZ_DEASSERT, &hdmi->mc_phyrstz);
673 reg = readl(&mxc_ccm->chsccdr);
674 reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK|
675 MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK|
676 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK);
677 reg |= (CHSCCDR_PODF_DIVIDE_BY_3
678 << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET)
679 |(CHSCCDR_IPU_PRE_CLK_540M_PFD
680 << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET);
681 writel(reg, &mxc_ccm->chsccdr);
Peng Fan95ae6122016-03-09 16:07:23 +0800682
683 /* Clear the overflow condition */
684 if (readb(&hdmi->ih_fc_stat2) & HDMI_IH_FC_STAT2_OVERFLOW_MASK) {
685 /* TMDS software reset */
686 writeb((u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, &hdmi->mc_swrstz);
687 val = readb(&hdmi->fc_invidconf);
688 /* Need minimum 3 times to write to clear the register */
689 for (count = 0 ; count < 5 ; count++)
690 writeb(val, &hdmi->fc_invidconf);
691 }
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -0500692}
693#endif
Peng Fanfb3a3b72016-01-28 16:55:05 +0800694
Heinrich Schuchardtcdd0c852020-06-26 19:57:55 +0200695#ifdef CONFIG_ARCH_MISC_INIT
696int arch_misc_init(void)
697{
698#ifdef CONFIG_FSL_CAAM
699 sec_init();
700#endif
701 return 0;
702}
703#endif
Michael Trimarchid9de3f82018-06-23 16:10:06 +0200704
705/*
706 * gpr_init() function is common for boards using MX6S, MX6DL, MX6D,
707 * MX6Q and MX6QP processors
708 */
Breno Limaf22b1092017-08-24 10:00:16 -0300709void gpr_init(void)
710{
711 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
712
Christoph Niedermaier2082ebf2018-10-19 17:40:54 +0200713 /*
714 * If this function is used in a common MX6 spl implementation
715 * we have to ensure that it is only called for suitable cpu types,
716 * otherwise it breaks hardware parts like enet1, can1, can2, etc.
717 */
718 if (!is_mx6dqp() && !is_mx6dq() && !is_mx6sdl())
719 return;
720
Breno Limaf22b1092017-08-24 10:00:16 -0300721 /* enable AXI cache for VDOA/VPU/IPU */
722 writel(0xF00000CF, &iomux->gpr[4]);
723 if (is_mx6dqp()) {
724 /* set IPU AXI-id1 Qos=0x1 AXI-id0/2/3 Qos=0x7 */
725 writel(0x77177717, &iomux->gpr[6]);
726 writel(0x77177717, &iomux->gpr[7]);
727 } else {
728 /* set IPU AXI-id0 Qos=0xf(bypass) AXI-id1 Qos=0x7 */
729 writel(0x007F007F, &iomux->gpr[6]);
730 writel(0x007F007F, &iomux->gpr[7]);
731 }
732}