blob: aacfc854a2f873ddc8c5bc3ce6bcc5e361b9d0da [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Jason Liu23608e22011-11-25 00:18:02 +00002/*
3 * (C) Copyright 2007
4 * Sascha Hauer, Pengutronix
5 *
6 * (C) Copyright 2009 Freescale Semiconductor, Inc.
Jason Liu23608e22011-11-25 00:18:02 +00007 */
8
9#include <common.h>
Sean Anderson1ce6e102021-02-04 16:44:22 -050010#include <env.h>
Simon Glass52559322019-11-14 12:57:46 -070011#include <init.h>
Simon Glassc05ed002020-05-10 11:40:11 -060012#include <linux/delay.h>
Masahiro Yamada1221ce42016-09-21 11:28:55 +090013#include <linux/errno.h>
Jason Liu23608e22011-11-25 00:18:02 +000014#include <asm/io.h>
15#include <asm/arch/imx-regs.h>
16#include <asm/arch/clock.h>
17#include <asm/arch/sys_proto.h>
Diego Dortac49fa342017-09-27 13:12:37 -030018#include <asm/bootm.h>
Stefano Babic552a8482017-06-29 10:16:06 +020019#include <asm/mach-imx/boot_mode.h>
20#include <asm/mach-imx/dma.h>
21#include <asm/mach-imx/hab.h>
Fabio Estevam76c91e62013-02-07 06:45:23 +000022#include <stdbool.h>
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -050023#include <asm/arch/mxc_hdmi.h>
24#include <asm/arch/crm_regs.h>
Ye.Li7a264162014-11-20 21:14:14 +080025#include <dm.h>
Heinrich Schuchardt90865612020-06-26 19:57:55 +020026#include <fsl_sec.h>
Ye.Li7a264162014-11-20 21:14:14 +080027#include <imx_thermal.h>
Soeren Moch1a43dc12016-02-04 14:41:15 +010028#include <mmc.h>
Jason Liu23608e22011-11-25 00:18:02 +000029
Jorge Ramirez-Ortiz74a03942020-10-23 21:18:41 +020030#define has_err007805() \
31 (is_mx6sl() || is_mx6dl() || is_mx6solo() || is_mx6ull())
32
Troy Kisky20332a02012-10-23 10:57:46 +000033struct scu_regs {
34 u32 ctrl;
35 u32 config;
36 u32 status;
37 u32 invalidate;
38 u32 fpga_rev;
39};
40
Simon Glass4e28a252020-10-29 11:08:25 -060041#if !defined(CONFIG_SPL_BUILD) && defined(CONFIG_IMX_THERMAL)
Ye.Li7a264162014-11-20 21:14:14 +080042static const struct imx_thermal_plat imx6_thermal_plat = {
43 .regs = (void *)ANATOP_BASE_ADDR,
44 .fuse_bank = 1,
45 .fuse_word = 6,
46};
47
Simon Glass20e442a2020-12-28 20:34:54 -070048U_BOOT_DRVINFO(imx6_thermal) = {
Ye.Li7a264162014-11-20 21:14:14 +080049 .name = "imx_thermal",
Simon Glasscaa4daa2020-12-03 16:55:18 -070050 .plat = &imx6_thermal_plat,
Ye.Li7a264162014-11-20 21:14:14 +080051};
52#endif
53
Stefano Babicd714a752019-09-20 08:47:53 +020054#if defined(CONFIG_IMX_HAB)
Adrian Alonso6b50bfe2015-10-12 13:48:12 -050055struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
56 .bank = 0,
57 .word = 6,
58};
59#endif
60
Gabriel Huaua76df702014-07-26 11:35:43 -070061u32 get_nr_cpus(void)
62{
63 struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
64 return readl(&scu->config) & 3;
65}
66
Jason Liu23608e22011-11-25 00:18:02 +000067u32 get_cpu_rev(void)
68{
Fabio Estevama7683862012-03-20 04:21:45 +000069 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Troy Kisky20332a02012-10-23 10:57:46 +000070 u32 reg = readl(&anatop->digprog_sololite);
71 u32 type = ((reg >> 16) & 0xff);
Peng Fand0acd992015-07-11 11:38:42 +080072 u32 major, cfg = 0;
Fabio Estevama7683862012-03-20 04:21:45 +000073
Troy Kisky20332a02012-10-23 10:57:46 +000074 if (type != MXC_CPU_MX6SL) {
75 reg = readl(&anatop->digprog);
Fabio Estevam94db6652014-01-26 15:06:41 -020076 struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
Peng Fand0acd992015-07-11 11:38:42 +080077 cfg = readl(&scu->config) & 3;
Troy Kisky20332a02012-10-23 10:57:46 +000078 type = ((reg >> 16) & 0xff);
79 if (type == MXC_CPU_MX6DL) {
Troy Kisky20332a02012-10-23 10:57:46 +000080 if (!cfg)
81 type = MXC_CPU_MX6SOLO;
82 }
Fabio Estevam94db6652014-01-26 15:06:41 -020083
84 if (type == MXC_CPU_MX6Q) {
85 if (cfg == 1)
86 type = MXC_CPU_MX6D;
87 }
88
Peng Fan81ae46c2019-08-08 09:55:52 +000089 if (type == MXC_CPU_MX6ULL) {
90 if (readl(SRC_BASE_ADDR + 0x1c) & (1 << 6))
91 type = MXC_CPU_MX6ULZ;
92 }
Troy Kisky20332a02012-10-23 10:57:46 +000093 }
Peng Fandfd48612015-06-11 18:30:36 +080094 major = ((reg >> 8) & 0xff);
Peng Fand0acd992015-07-11 11:38:42 +080095 if ((major >= 1) &&
96 ((type == MXC_CPU_MX6Q) || (type == MXC_CPU_MX6D))) {
97 major--;
98 type = MXC_CPU_MX6QP;
99 if (cfg == 1)
100 type = MXC_CPU_MX6DP;
101 }
Troy Kisky20332a02012-10-23 10:57:46 +0000102 reg &= 0xff; /* mx6 silicon revision */
Ye Li5fdef6c2019-07-10 10:38:37 +0000103
104 /* For 6DQ, the value 0x00630005 is Silicon revision 1.3*/
105 if (((type == MXC_CPU_MX6Q) || (type == MXC_CPU_MX6D)) && (reg == 0x5))
106 reg = 0x3;
107
Peng Fandfd48612015-06-11 18:30:36 +0800108 return (type << 12) | (reg + (0x10 * (major + 1)));
Jason Liu23608e22011-11-25 00:18:02 +0000109}
110
Tim Harvey9b9449c2015-05-18 07:02:24 -0700111/*
112 * OCOTP_CFG3[17:16] (see Fusemap Description Table offset 0x440)
113 * defines a 2-bit SPEED_GRADING
114 */
115#define OCOTP_CFG3_SPEED_SHIFT 16
116#define OCOTP_CFG3_SPEED_800MHZ 0
117#define OCOTP_CFG3_SPEED_850MHZ 1
118#define OCOTP_CFG3_SPEED_1GHZ 2
119#define OCOTP_CFG3_SPEED_1P2GHZ 3
120
Peng Fand15a2442016-05-03 11:13:04 +0800121/*
122 * For i.MX6UL
123 */
124#define OCOTP_CFG3_SPEED_528MHZ 1
125#define OCOTP_CFG3_SPEED_696MHZ 2
126
Sébastien Szymanski0c7c6fb2017-08-02 17:05:27 +0200127/*
128 * For i.MX6ULL
129 */
130#define OCOTP_CFG3_SPEED_792MHZ 2
131#define OCOTP_CFG3_SPEED_900MHZ 3
132
Tim Harvey9b9449c2015-05-18 07:02:24 -0700133u32 get_cpu_speed_grade_hz(void)
134{
135 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
136 struct fuse_bank *bank = &ocotp->bank[0];
137 struct fuse_bank0_regs *fuse =
138 (struct fuse_bank0_regs *)bank->fuse_regs;
139 uint32_t val;
140
141 val = readl(&fuse->cfg3);
142 val >>= OCOTP_CFG3_SPEED_SHIFT;
143 val &= 0x3;
144
Sébastien Szymanski0c7c6fb2017-08-02 17:05:27 +0200145 if (is_mx6ul()) {
Peng Fand15a2442016-05-03 11:13:04 +0800146 if (val == OCOTP_CFG3_SPEED_528MHZ)
147 return 528000000;
148 else if (val == OCOTP_CFG3_SPEED_696MHZ)
Sébastien Szymanski44e67052017-08-02 17:05:26 +0200149 return 696000000;
Peng Fand15a2442016-05-03 11:13:04 +0800150 else
151 return 0;
152 }
153
Sébastien Szymanski0c7c6fb2017-08-02 17:05:27 +0200154 if (is_mx6ull()) {
155 if (val == OCOTP_CFG3_SPEED_528MHZ)
156 return 528000000;
157 else if (val == OCOTP_CFG3_SPEED_792MHZ)
158 return 792000000;
159 else if (val == OCOTP_CFG3_SPEED_900MHZ)
160 return 900000000;
161 else
162 return 0;
163 }
164
Tim Harvey9b9449c2015-05-18 07:02:24 -0700165 switch (val) {
166 /* Valid for IMX6DQ */
167 case OCOTP_CFG3_SPEED_1P2GHZ:
Peng Fan04cb3c02016-05-23 18:35:58 +0800168 if (is_mx6dq() || is_mx6dqp())
Tim Harvey9b9449c2015-05-18 07:02:24 -0700169 return 1200000000;
170 /* Valid for IMX6SX/IMX6SDL/IMX6DQ */
171 case OCOTP_CFG3_SPEED_1GHZ:
172 return 996000000;
173 /* Valid for IMX6DQ */
174 case OCOTP_CFG3_SPEED_850MHZ:
Peng Fan04cb3c02016-05-23 18:35:58 +0800175 if (is_mx6dq() || is_mx6dqp())
Tim Harvey9b9449c2015-05-18 07:02:24 -0700176 return 852000000;
177 /* Valid for IMX6SX/IMX6SDL/IMX6DQ */
178 case OCOTP_CFG3_SPEED_800MHZ:
179 return 792000000;
180 }
181 return 0;
182}
183
Tim Harveyf0e8e892015-05-18 06:56:45 -0700184/*
185 * OCOTP_MEM0[7:6] (see Fusemap Description Table offset 0x480)
186 * defines a 2-bit Temperature Grade
187 *
Fabio Estevam65496a32017-06-22 10:50:05 -0300188 * return temperature grade and min/max temperature in Celsius
Tim Harveyf0e8e892015-05-18 06:56:45 -0700189 */
190#define OCOTP_MEM0_TEMP_SHIFT 6
191
192u32 get_cpu_temp_grade(int *minc, int *maxc)
193{
194 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
195 struct fuse_bank *bank = &ocotp->bank[1];
196 struct fuse_bank1_regs *fuse =
197 (struct fuse_bank1_regs *)bank->fuse_regs;
198 uint32_t val;
199
200 val = readl(&fuse->mem0);
201 val >>= OCOTP_MEM0_TEMP_SHIFT;
202 val &= 0x3;
203
204 if (minc && maxc) {
205 if (val == TEMP_AUTOMOTIVE) {
206 *minc = -40;
207 *maxc = 125;
208 } else if (val == TEMP_INDUSTRIAL) {
209 *minc = -40;
210 *maxc = 105;
211 } else if (val == TEMP_EXTCOMMERCIAL) {
212 *minc = -20;
213 *maxc = 105;
214 } else {
215 *minc = 0;
216 *maxc = 95;
217 }
218 }
219 return val;
220}
221
Fabio Estevam38e70072013-03-27 07:36:55 +0000222#ifdef CONFIG_REVISION_TAG
223u32 __weak get_board_rev(void)
224{
225 u32 cpurev = get_cpu_rev();
226 u32 type = ((cpurev >> 12) & 0xff);
227 if (type == MXC_CPU_MX6SOLO)
228 cpurev = (MXC_CPU_MX6DL) << 12 | (cpurev & 0xFFF);
229
Fabio Estevam94db6652014-01-26 15:06:41 -0200230 if (type == MXC_CPU_MX6D)
231 cpurev = (MXC_CPU_MX6Q) << 12 | (cpurev & 0xFFF);
232
Fabio Estevam38e70072013-03-27 07:36:55 +0000233 return cpurev;
234}
235#endif
236
Fabio Estevame113fd12013-12-26 14:51:31 -0200237static void clear_ldo_ramp(void)
238{
239 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
240 int reg;
241
242 /* ROM may modify LDO ramp up time according to fuse setting, so in
243 * order to be in the safe side we neeed to reset these settings to
244 * match the reset value: 0'b00
245 */
246 reg = readl(&anatop->ana_misc2);
247 reg &= ~(0x3f << 24);
248 writel(reg, &anatop->ana_misc2);
249}
250
Dirk Behmecac833a2012-05-02 02:12:17 +0000251/*
Fabio Estevam157f45d2014-06-13 01:42:37 -0300252 * Set the PMU_REG_CORE register
Dirk Behmecac833a2012-05-02 02:12:17 +0000253 *
Fabio Estevam157f45d2014-06-13 01:42:37 -0300254 * Set LDO_SOC/PU/ARM regulators to the specified millivolt level.
Dirk Behmecac833a2012-05-02 02:12:17 +0000255 * Possible values are from 0.725V to 1.450V in steps of
256 * 0.025V (25mV).
257 */
Marek Vasutdf1b7212019-11-26 09:35:32 +0100258int set_ldo_voltage(enum ldo_reg ldo, u32 mv)
Dirk Behmecac833a2012-05-02 02:12:17 +0000259{
260 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Fabio Estevam39f0ac92013-12-26 14:51:34 -0200261 u32 val, step, old, reg = readl(&anatop->reg_core);
Fabio Estevam3d622b72013-12-26 14:51:33 -0200262 u8 shift;
Dirk Behmecac833a2012-05-02 02:12:17 +0000263
Peng Fan79a57b52017-08-08 16:21:35 +0800264 /* No LDO_SOC/PU/ARM */
265 if (is_mx6sll())
266 return 0;
267
Dirk Behmecac833a2012-05-02 02:12:17 +0000268 if (mv < 725)
269 val = 0x00; /* Power gated off */
270 else if (mv > 1450)
271 val = 0x1F; /* Power FET switched full on. No regulation */
272 else
273 val = (mv - 700) / 25;
274
Fabio Estevame113fd12013-12-26 14:51:31 -0200275 clear_ldo_ramp();
276
Fabio Estevam3d622b72013-12-26 14:51:33 -0200277 switch (ldo) {
278 case LDO_SOC:
279 shift = 18;
280 break;
281 case LDO_PU:
282 shift = 9;
283 break;
284 case LDO_ARM:
285 shift = 0;
286 break;
287 default:
288 return -EINVAL;
289 }
290
Fabio Estevam39f0ac92013-12-26 14:51:34 -0200291 old = (reg & (0x1F << shift)) >> shift;
292 step = abs(val - old);
293 if (step == 0)
294 return 0;
295
Fabio Estevam3d622b72013-12-26 14:51:33 -0200296 reg = (reg & ~(0x1F << shift)) | (val << shift);
Dirk Behmecac833a2012-05-02 02:12:17 +0000297 writel(reg, &anatop->reg_core);
Fabio Estevam3d622b72013-12-26 14:51:33 -0200298
Fabio Estevam39f0ac92013-12-26 14:51:34 -0200299 /*
300 * The LDO ramp-up is based on 64 clock cycles of 24 MHz = 2.6 us per
301 * step
302 */
303 udelay(3 * step);
304
Fabio Estevam3d622b72013-12-26 14:51:33 -0200305 return 0;
Dirk Behmecac833a2012-05-02 02:12:17 +0000306}
307
Anson Huang5c92edc2014-01-23 14:00:18 +0800308static void set_ahb_rate(u32 val)
309{
310 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
311 u32 reg, div;
312
313 div = get_periph_clk() / val - 1;
314 reg = readl(&mxc_ccm->cbcdr);
315
316 writel((reg & (~MXC_CCM_CBCDR_AHB_PODF_MASK)) |
317 (div << MXC_CCM_CBCDR_AHB_PODF_OFFSET), &mxc_ccm->cbcdr);
318}
319
Anson Huang16197bb2014-01-23 14:00:19 +0800320static void clear_mmdc_ch_mask(void)
321{
322 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Peng Fane1c2d682015-07-11 11:38:43 +0800323 u32 reg;
324 reg = readl(&mxc_ccm->ccdr);
Anson Huang16197bb2014-01-23 14:00:19 +0800325
326 /* Clear MMDC channel mask */
Peng Fan79a57b52017-08-08 16:21:35 +0800327 if (is_mx6sx() || is_mx6ul() || is_mx6ull() || is_mx6sl() || is_mx6sll())
Ye Lib7777892016-03-09 16:13:48 +0800328 reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK);
329 else
330 reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK | MXC_CCM_CCDR_MMDC_CH0_HS_MASK);
Peng Fane1c2d682015-07-11 11:38:43 +0800331 writel(reg, &mxc_ccm->ccdr);
Anson Huang16197bb2014-01-23 14:00:19 +0800332}
333
Peng Fan97c16dc2016-10-08 17:03:00 +0800334#define OCOTP_MEM0_REFTOP_TRIM_SHIFT 8
335
Peng Fan1f516fa2015-01-15 14:22:32 +0800336static void init_bandgap(void)
337{
338 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Peng Fan97c16dc2016-10-08 17:03:00 +0800339 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
340 struct fuse_bank *bank = &ocotp->bank[1];
341 struct fuse_bank1_regs *fuse =
342 (struct fuse_bank1_regs *)bank->fuse_regs;
343 uint32_t val;
344
Peng Fan1f516fa2015-01-15 14:22:32 +0800345 /*
346 * Ensure the bandgap has stabilized.
347 */
348 while (!(readl(&anatop->ana_misc0) & 0x80))
349 ;
350 /*
351 * For best noise performance of the analog blocks using the
352 * outputs of the bandgap, the reftop_selfbiasoff bit should
353 * be set.
354 */
355 writel(BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF, &anatop->ana_misc0_set);
Peng Fan5b664822016-08-11 14:02:50 +0800356 /*
Peng Fan97c16dc2016-10-08 17:03:00 +0800357 * On i.MX6ULL,we need to set VBGADJ bits according to the
358 * REFTOP_TRIM[3:0] in fuse table
359 * 000 - set REFTOP_VBGADJ[2:0] to 3b'110,
360 * 110 - set REFTOP_VBGADJ[2:0] to 3b'000,
361 * 001 - set REFTOP_VBGADJ[2:0] to 3b'001,
362 * 010 - set REFTOP_VBGADJ[2:0] to 3b'010,
363 * 011 - set REFTOP_VBGADJ[2:0] to 3b'011,
364 * 100 - set REFTOP_VBGADJ[2:0] to 3b'100,
365 * 101 - set REFTOP_VBGADJ[2:0] to 3b'101,
366 * 111 - set REFTOP_VBGADJ[2:0] to 3b'111,
Peng Fan5b664822016-08-11 14:02:50 +0800367 */
Peng Fan97c16dc2016-10-08 17:03:00 +0800368 if (is_mx6ull()) {
369 val = readl(&fuse->mem0);
370 val >>= OCOTP_MEM0_REFTOP_TRIM_SHIFT;
371 val &= 0x7;
Peng Fan1f516fa2015-01-15 14:22:32 +0800372
Peng Fan97c16dc2016-10-08 17:03:00 +0800373 writel(val << BM_ANADIG_ANA_MISC0_REFTOP_VBGADJ_SHIFT,
374 &anatop->ana_misc0_set);
375 }
376}
Peng Fan1f516fa2015-01-15 14:22:32 +0800377
Fabio Estevamd396f132019-11-04 09:44:34 -0300378#if defined(CONFIG_MX6Q) || defined(CONFIG_MX6QDL)
379static void noc_setup(void)
380{
381 enable_ipu_clock();
382
383 writel(0x80000201, 0xbb0608);
384 /* Bypass IPU1 QoS generator */
385 writel(0x00000002, 0x00bb048c);
386 /* Bypass IPU2 QoS generator */
387 writel(0x00000002, 0x00bb050c);
388 /* Bandwidth THR for of PRE0 */
389 writel(0x00000200, 0x00bb0690);
390 /* Bandwidth THR for of PRE1 */
391 writel(0x00000200, 0x00bb0710);
392 /* Bandwidth THR for of PRE2 */
393 writel(0x00000200, 0x00bb0790);
394 /* Bandwidth THR for of PRE3 */
395 writel(0x00000200, 0x00bb0810);
396 /* Saturation THR for of PRE0 */
397 writel(0x00000010, 0x00bb0694);
398 /* Saturation THR for of PRE1 */
399 writel(0x00000010, 0x00bb0714);
400 /* Saturation THR for of PRE2 */
401 writel(0x00000010, 0x00bb0794);
402 /* Saturation THR for of PRE */
403 writel(0x00000010, 0x00bb0814);
404
405 disable_ipu_clock();
406}
407#endif
408
Jason Liu23608e22011-11-25 00:18:02 +0000409int arch_cpu_init(void)
410{
Peng Fan72362972017-08-08 16:21:38 +0800411 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
412
Jason Liu23608e22011-11-25 00:18:02 +0000413 init_aips();
414
Anson Huang16197bb2014-01-23 14:00:19 +0800415 /* Need to clear MMDC_CHx_MASK to make warm reset work. */
416 clear_mmdc_ch_mask();
417
Anson Huang5c92edc2014-01-23 14:00:18 +0800418 /*
Peng Fan1f516fa2015-01-15 14:22:32 +0800419 * Disable self-bias circuit in the analog bandap.
420 * The self-bias circuit is used by the bandgap during startup.
421 * This bit should be set after the bandgap has initialized.
422 */
423 init_bandgap();
424
Peng Fancdf33c92016-08-11 14:02:43 +0800425 if (!is_mx6ul() && !is_mx6ull()) {
Peng Fane4dc3fc2016-03-09 16:44:36 +0800426 /*
427 * When low freq boot is enabled, ROM will not set AHB
428 * freq, so we need to ensure AHB freq is 132MHz in such
429 * scenario.
430 *
431 * To i.MX6UL, when power up, default ARM core and
432 * AHB rate is 396M and 132M.
433 */
434 if (mxc_get_clock(MXC_ARM_CLK) == 396000000)
435 set_ahb_rate(132000000);
436 }
Anson Huang5c92edc2014-01-23 14:00:18 +0800437
Peng Fanf15ece32016-09-28 09:40:27 +0800438 if (is_mx6ul()) {
439 if (is_soc_rev(CHIP_REV_1_0) == 0) {
440 /*
441 * According to the design team's requirement on
442 * i.MX6UL,the PMIC_STBY_REQ PAD should be configured
443 * as open drain 100K (0x0000b8a0).
444 * Only exists on TO1.0
445 */
446 writel(0x0000b8a0, IOMUXC_BASE_ADDR + 0x29c);
447 } else {
448 /*
449 * From TO1.1, SNVS adds internal pull up control
450 * for POR_B, the register filed is GPBIT[1:0],
451 * after system boot up, it can be set to 2b'01
452 * to disable internal pull up.It can save about
453 * 30uA power in SNVS mode.
454 */
455 writel((readl(MX6UL_SNVS_LP_BASE_ADDR + 0x10) &
456 (~0x1400)) | 0x400,
457 MX6UL_SNVS_LP_BASE_ADDR + 0x10);
458 }
Peng Fan7082d872016-03-09 16:44:37 +0800459 }
460
Peng Fanb4714612016-08-11 14:02:46 +0800461 if (is_mx6ull()) {
462 /*
463 * GPBIT[1:0] is suggested to set to 2'b11:
464 * 2'b00 : always PUP100K
465 * 2'b01 : PUP100K when PMIC_ON_REQ or SOC_NOT_FAIL
466 * 2'b10 : always disable PUP100K
467 * 2'b11 : PDN100K when SOC_FAIL, PUP100K when SOC_NOT_FAIL
468 * register offset is different from i.MX6UL, since
469 * i.MX6UL is fixed by ECO.
470 */
471 writel(readl(MX6UL_SNVS_LP_BASE_ADDR) |
472 0x3, MX6UL_SNVS_LP_BASE_ADDR);
473 }
474
Peng Fan7082d872016-03-09 16:44:37 +0800475 /* Set perclk to source from OSC 24MHz */
Jorge Ramirez-Ortiz74a03942020-10-23 21:18:41 +0200476 if (has_err007805())
Peng Fan9402caf2017-08-08 16:21:39 +0800477 setbits_le32(&ccm->cscmr1, MXC_CCM_CSCMR1_PER_CLK_SEL_MASK);
Ye.Li0f8ec142014-10-30 18:20:58 +0800478
Fabio Estevame2162d72017-11-23 10:55:33 -0200479 imx_wdog_disable_powerdown(); /* Disable PDE bit of WMCR register */
Stefan Roeseae695b12013-04-15 21:14:12 +0000480
Peng Fan72362972017-08-08 16:21:38 +0800481 if (is_mx6sx())
482 setbits_le32(&ccm->cscdr1, MXC_CCM_CSCDR1_UART_CLK_SEL);
483
Dirk Behme9d16c522015-03-09 14:48:48 +0100484 init_src();
485
Fabio Estevamd396f132019-11-04 09:44:34 -0300486#if defined(CONFIG_MX6Q) || defined(CONFIG_MX6QDL)
487 if (is_mx6dqp())
488 noc_setup();
489#endif
Jason Liu23608e22011-11-25 00:18:02 +0000490 return 0;
491}
Jason Liu23608e22011-11-25 00:18:02 +0000492
Peng Fan216d2862016-01-28 16:51:26 +0800493#ifdef CONFIG_ENV_IS_IN_MMC
494__weak int board_mmc_get_env_dev(int devno)
495{
496 return CONFIG_SYS_MMC_ENV_DEV;
497}
498
Soeren Moch1a43dc12016-02-04 14:41:15 +0100499static int mmc_get_boot_dev(void)
Peng Fan216d2862016-01-28 16:51:26 +0800500{
501 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
502 u32 soc_sbmr = readl(&src_regs->sbmr1);
503 u32 bootsel;
504 int devno;
505
506 /*
507 * Refer to
508 * "i.MX 6Dual/6Quad Applications Processor Reference Manual"
509 * Chapter "8.5.3.1 Expansion Device eFUSE Configuration"
510 * i.MX6SL/SX/UL has same layout.
511 */
512 bootsel = (soc_sbmr & 0x000000FF) >> 6;
513
Soeren Moch1a43dc12016-02-04 14:41:15 +0100514 /* No boot from sd/mmc */
Peng Fan216d2862016-01-28 16:51:26 +0800515 if (bootsel != 1)
Soeren Moch1a43dc12016-02-04 14:41:15 +0100516 return -1;
Peng Fan216d2862016-01-28 16:51:26 +0800517
518 /* BOOT_CFG2[3] and BOOT_CFG2[4] */
519 devno = (soc_sbmr & 0x00001800) >> 11;
520
Soeren Moch1a43dc12016-02-04 14:41:15 +0100521 return devno;
522}
523
524int mmc_get_env_dev(void)
525{
526 int devno = mmc_get_boot_dev();
527
528 /* If not boot from sd/mmc, use default value */
529 if (devno < 0)
530 return CONFIG_SYS_MMC_ENV_DEV;
531
Peng Fan216d2862016-01-28 16:51:26 +0800532 return board_mmc_get_env_dev(devno);
533}
Soeren Moch1a43dc12016-02-04 14:41:15 +0100534
535#ifdef CONFIG_SYS_MMC_ENV_PART
536__weak int board_mmc_get_env_part(int devno)
537{
538 return CONFIG_SYS_MMC_ENV_PART;
539}
540
541uint mmc_get_env_part(struct mmc *mmc)
542{
543 int devno = mmc_get_boot_dev();
544
545 /* If not boot from sd/mmc, use default value */
546 if (devno < 0)
547 return CONFIG_SYS_MMC_ENV_PART;
548
549 return board_mmc_get_env_part(devno);
550}
551#endif
Peng Fan216d2862016-01-28 16:51:26 +0800552#endif
553
Fabio Estevam39f0ac92013-12-26 14:51:34 -0200554int board_postclk_init(void)
555{
Peng Fan79a57b52017-08-08 16:21:35 +0800556 /* NO LDO SOC on i.MX6SLL */
557 if (is_mx6sll())
558 return 0;
559
Fabio Estevam39f0ac92013-12-26 14:51:34 -0200560 set_ldo_voltage(LDO_SOC, 1175); /* Set VDDSOC to 1.175V */
561
562 return 0;
563}
564
Anatolij Gustschinffc36f52017-08-28 17:51:33 +0200565#ifndef CONFIG_SPL_BUILD
Troy Kisky124a06d2012-08-15 10:31:20 +0000566/*
567 * cfg_val will be used for
568 * Boot_cfg4[7:0]:Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
Nikita Kiryanovf2863ff2014-10-29 19:28:33 +0200569 * After reset, if GPR10[28] is 1, ROM will use GPR9[25:0]
570 * instead of SBMR1 to determine the boot device.
Troy Kisky124a06d2012-08-15 10:31:20 +0000571 */
572const struct boot_mode soc_boot_modes[] = {
573 {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)},
574 /* reserved value should start rom usb */
Stefan Agner3fd95792017-06-09 13:13:12 -0700575#if defined(CONFIG_MX6UL) || defined(CONFIG_MX6ULL)
576 {"usb", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
577#else
Stefan Agner81c4ecc2016-09-15 15:04:39 -0700578 {"usb", MAKE_CFGVAL(0x10, 0x00, 0x00, 0x00)},
Stefan Agner3fd95792017-06-09 13:13:12 -0700579#endif
Troy Kisky124a06d2012-08-15 10:31:20 +0000580 {"sata", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
Nikolay Dimitrov2d59e3e2014-08-10 20:03:07 +0300581 {"ecspi1:0", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x08)},
582 {"ecspi1:1", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x18)},
583 {"ecspi1:2", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x28)},
584 {"ecspi1:3", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x38)},
Troy Kisky124a06d2012-08-15 10:31:20 +0000585 /* 4 bit bus width */
586 {"esdhc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
587 {"esdhc2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
588 {"esdhc3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
589 {"esdhc4", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
590 {NULL, 0},
591};
Anatolij Gustschinffc36f52017-08-28 17:51:33 +0200592#endif
Stephen Warren8f393772013-02-26 12:28:29 +0000593
Peng Faneb111bb2015-10-29 15:54:50 +0800594void reset_misc(void)
595{
Michael Trimarchi92362692018-06-20 23:27:54 +0200596#ifndef CONFIG_SPL_BUILD
Igor Opaniuk9de5eb22019-06-19 11:47:08 +0300597#if defined(CONFIG_VIDEO_MXS) && !defined(CONFIG_DM_VIDEO)
Peng Faneb111bb2015-10-29 15:54:50 +0800598 lcdif_power_down();
599#endif
Michael Trimarchi92362692018-06-20 23:27:54 +0200600#endif
Peng Faneb111bb2015-10-29 15:54:50 +0800601}
602
Stephen Warren8f393772013-02-26 12:28:29 +0000603void s_init(void)
604{
Eric Nelson8467fae2013-08-29 12:41:46 -0700605 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Ye.Li9293d7f2014-09-09 10:17:00 +0800606 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Eric Nelson8467fae2013-08-29 12:41:46 -0700607 u32 mask480;
608 u32 mask528;
Ye.Li9293d7f2014-09-09 10:17:00 +0800609 u32 reg, periph1, periph2;
Fabio Estevama3df99b2014-07-09 16:13:29 -0300610
Peng Fan79a57b52017-08-08 16:21:35 +0800611 if (is_mx6sx() || is_mx6ul() || is_mx6ull() || is_mx6sll())
Fabio Estevama3df99b2014-07-09 16:13:29 -0300612 return;
613
Eric Nelson8467fae2013-08-29 12:41:46 -0700614 /* Due to hardware limitation, on MX6Q we need to gate/ungate all PFDs
615 * to make sure PFD is working right, otherwise, PFDs may
616 * not output clock after reset, MX6DL and MX6SL have added 396M pfd
617 * workaround in ROM code, as bus clock need it
618 */
619
620 mask480 = ANATOP_PFD_CLKGATE_MASK(0) |
621 ANATOP_PFD_CLKGATE_MASK(1) |
622 ANATOP_PFD_CLKGATE_MASK(2) |
623 ANATOP_PFD_CLKGATE_MASK(3);
Ye.Li9293d7f2014-09-09 10:17:00 +0800624 mask528 = ANATOP_PFD_CLKGATE_MASK(1) |
Eric Nelson8467fae2013-08-29 12:41:46 -0700625 ANATOP_PFD_CLKGATE_MASK(3);
626
Ye.Li9293d7f2014-09-09 10:17:00 +0800627 reg = readl(&ccm->cbcmr);
628 periph2 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_MASK)
629 >> MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_OFFSET);
630 periph1 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK)
631 >> MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_OFFSET);
632
633 /* Checking if PLL2 PFD0 or PLL2 PFD2 is using for periph clock */
634 if ((periph2 != 0x2) && (periph1 != 0x2))
635 mask528 |= ANATOP_PFD_CLKGATE_MASK(0);
636
637 if ((periph2 != 0x1) && (periph1 != 0x1) &&
638 (periph2 != 0x3) && (periph1 != 0x3))
Eric Nelson8467fae2013-08-29 12:41:46 -0700639 mask528 |= ANATOP_PFD_CLKGATE_MASK(2);
Ye.Li9293d7f2014-09-09 10:17:00 +0800640
Eric Nelson8467fae2013-08-29 12:41:46 -0700641 writel(mask480, &anatop->pfd_480_set);
642 writel(mask528, &anatop->pfd_528_set);
643 writel(mask480, &anatop->pfd_480_clr);
644 writel(mask528, &anatop->pfd_528_clr);
Stephen Warren8f393772013-02-26 12:28:29 +0000645}
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500646
647#ifdef CONFIG_IMX_HDMI
648void imx_enable_hdmi_phy(void)
649{
650 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
651 u8 reg;
652 reg = readb(&hdmi->phy_conf0);
653 reg |= HDMI_PHY_CONF0_PDZ_MASK;
654 writeb(reg, &hdmi->phy_conf0);
655 udelay(3000);
656 reg |= HDMI_PHY_CONF0_ENTMDS_MASK;
657 writeb(reg, &hdmi->phy_conf0);
658 udelay(3000);
659 reg |= HDMI_PHY_CONF0_GEN2_TXPWRON_MASK;
660 writeb(reg, &hdmi->phy_conf0);
661 writeb(HDMI_MC_PHYRSTZ_ASSERT, &hdmi->mc_phyrstz);
662}
663
664void imx_setup_hdmi(void)
665{
666 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
667 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
Peng Fan00b1d2d2016-03-09 16:07:23 +0800668 int reg, count;
669 u8 val;
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500670
671 /* Turn on HDMI PHY clock */
672 reg = readl(&mxc_ccm->CCGR2);
673 reg |= MXC_CCM_CCGR2_HDMI_TX_IAHBCLK_MASK|
674 MXC_CCM_CCGR2_HDMI_TX_ISFRCLK_MASK;
675 writel(reg, &mxc_ccm->CCGR2);
676 writeb(HDMI_MC_PHYRSTZ_DEASSERT, &hdmi->mc_phyrstz);
677 reg = readl(&mxc_ccm->chsccdr);
678 reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK|
679 MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK|
680 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK);
681 reg |= (CHSCCDR_PODF_DIVIDE_BY_3
682 << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET)
683 |(CHSCCDR_IPU_PRE_CLK_540M_PFD
684 << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET);
685 writel(reg, &mxc_ccm->chsccdr);
Peng Fan00b1d2d2016-03-09 16:07:23 +0800686
687 /* Clear the overflow condition */
688 if (readb(&hdmi->ih_fc_stat2) & HDMI_IH_FC_STAT2_OVERFLOW_MASK) {
689 /* TMDS software reset */
690 writeb((u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, &hdmi->mc_swrstz);
691 val = readb(&hdmi->fc_invidconf);
692 /* Need minimum 3 times to write to clear the register */
693 for (count = 0 ; count < 5 ; count++)
694 writeb(val, &hdmi->fc_invidconf);
695 }
Pardeep Kumar Singla5ea7f0e2013-07-25 12:12:13 -0500696}
697#endif
Peng Fan0623d372016-01-28 16:55:05 +0800698
Heinrich Schuchardt90865612020-06-26 19:57:55 +0200699#ifdef CONFIG_ARCH_MISC_INIT
Sean Anderson1ce6e102021-02-04 16:44:22 -0500700/*
701 * UNIQUE_ID describes a unique ID based on silicon wafer
702 * and die X/Y position
703 *
704 * UNIQUE_ID offset 0x410
705 * 31:0 fuse 0
706 * FSL-wide unique, encoded LOT ID STD II/SJC CHALLENGE/ Unique ID
707 *
708 * UNIQUE_ID offset 0x420
709 * 31:24 fuse 1
710 * The X-coordinate of the die location on the wafer/SJC CHALLENGE/ Unique ID
711 * 23:16 fuse 1
712 * The Y-coordinate of the die location on the wafer/SJC CHALLENGE/ Unique ID
713 * 15:11 fuse 1
714 * The wafer number of the wafer on which the device was fabricated/SJC
715 * CHALLENGE/ Unique ID
716 * 10:0 fuse 1
717 * FSL-wide unique, encoded LOT ID STD II/SJC CHALLENGE/ Unique ID
718 */
719static void setup_serial_number(void)
720{
721 char serial_string[17];
722 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
723 struct fuse_bank *bank = &ocotp->bank[0];
724 struct fuse_bank0_regs *fuse =
725 (struct fuse_bank0_regs *)bank->fuse_regs;
726
727 if (env_get("serial#"))
728 return;
729
730 snprintf(serial_string, sizeof(serial_string), "%08x%08x",
731 fuse->uid_low, fuse->uid_high);
732 env_set("serial#", serial_string);
733}
734
Heinrich Schuchardt90865612020-06-26 19:57:55 +0200735int arch_misc_init(void)
736{
737#ifdef CONFIG_FSL_CAAM
738 sec_init();
739#endif
Sean Anderson1ce6e102021-02-04 16:44:22 -0500740 setup_serial_number();
Heinrich Schuchardt90865612020-06-26 19:57:55 +0200741 return 0;
742}
743#endif
Michael Trimarchi4a72abc2018-06-23 16:10:06 +0200744
745/*
746 * gpr_init() function is common for boards using MX6S, MX6DL, MX6D,
747 * MX6Q and MX6QP processors
748 */
Breno Lima3aa4b702017-08-24 10:00:16 -0300749void gpr_init(void)
750{
751 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
752
Christoph Niedermaier19bbd092018-10-19 17:40:54 +0200753 /*
754 * If this function is used in a common MX6 spl implementation
755 * we have to ensure that it is only called for suitable cpu types,
756 * otherwise it breaks hardware parts like enet1, can1, can2, etc.
757 */
758 if (!is_mx6dqp() && !is_mx6dq() && !is_mx6sdl())
759 return;
760
Breno Lima3aa4b702017-08-24 10:00:16 -0300761 /* enable AXI cache for VDOA/VPU/IPU */
762 writel(0xF00000CF, &iomux->gpr[4]);
763 if (is_mx6dqp()) {
764 /* set IPU AXI-id1 Qos=0x1 AXI-id0/2/3 Qos=0x7 */
765 writel(0x77177717, &iomux->gpr[6]);
766 writel(0x77177717, &iomux->gpr[7]);
767 } else {
768 /* set IPU AXI-id0 Qos=0xf(bypass) AXI-id1 Qos=0x7 */
769 writel(0x007F007F, &iomux->gpr[6]);
770 writel(0x007F007F, &iomux->gpr[7]);
771 }
772}