blob: 7b53bfdeb40cd7d32615aafa97e8cf1038817318 [file] [log] [blame]
Jason Liudec11122011-11-25 00:18:02 +00001/*
2 * (C) Copyright 2007
3 * Sascha Hauer, Pengutronix
4 *
5 * (C) Copyright 2009 Freescale Semiconductor, Inc.
6 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Jason Liudec11122011-11-25 00:18:02 +00008 */
9
10#include <common.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>
Troy Kisky0ca618c2012-08-15 10:31:20 +000016#include <asm/imx-common/boot_mode.h>
Stefan Roese8338d1d2013-04-15 21:14:12 +000017#include <asm/imx-common/dma.h>
Adrian Alonso6ec8d842015-10-12 13:48:12 -050018#include <asm/imx-common/hab.h>
Fabio Estevam48e65b02013-02-07 06:45:23 +000019#include <stdbool.h>
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -050020#include <asm/arch/mxc_hdmi.h>
21#include <asm/arch/crm_regs.h>
Ye.Lif19692c2014-11-20 21:14:14 +080022#include <dm.h>
23#include <imx_thermal.h>
Soeren Mochbc177f12016-02-04 14:41:15 +010024#include <mmc.h>
Jason Liudec11122011-11-25 00:18:02 +000025
Fabio Estevama47ec522013-12-26 14:51:33 -020026enum ldo_reg {
27 LDO_ARM,
28 LDO_SOC,
29 LDO_PU,
30};
31
Troy Kisky58394932012-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 Alonsoce08c362015-09-02 13:54:13 -050040#if defined(CONFIG_IMX_THERMAL)
Ye.Lif19692c2014-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 Alonso6ec8d842015-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 Huau170ceaf2014-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 Liudec11122011-11-25 00:18:02 +000066u32 get_cpu_rev(void)
67{
Fabio Estevam46e97332012-03-20 04:21:45 +000068 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Troy Kisky58394932012-10-23 10:57:46 +000069 u32 reg = readl(&anatop->digprog_sololite);
70 u32 type = ((reg >> 16) & 0xff);
Peng Fan5f247922015-07-11 11:38:42 +080071 u32 major, cfg = 0;
Fabio Estevam46e97332012-03-20 04:21:45 +000072
Troy Kisky58394932012-10-23 10:57:46 +000073 if (type != MXC_CPU_MX6SL) {
74 reg = readl(&anatop->digprog);
Fabio Estevamf3d5a2c2014-01-26 15:06:41 -020075 struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
Peng Fan5f247922015-07-11 11:38:42 +080076 cfg = readl(&scu->config) & 3;
Troy Kisky58394932012-10-23 10:57:46 +000077 type = ((reg >> 16) & 0xff);
78 if (type == MXC_CPU_MX6DL) {
Troy Kisky58394932012-10-23 10:57:46 +000079 if (!cfg)
80 type = MXC_CPU_MX6SOLO;
81 }
Fabio Estevamf3d5a2c2014-01-26 15:06:41 -020082
83 if (type == MXC_CPU_MX6Q) {
84 if (cfg == 1)
85 type = MXC_CPU_MX6D;
86 }
87
Troy Kisky58394932012-10-23 10:57:46 +000088 }
Peng Fan88383232015-06-11 18:30:36 +080089 major = ((reg >> 8) & 0xff);
Peng Fan5f247922015-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 Kisky58394932012-10-23 10:57:46 +000097 reg &= 0xff; /* mx6 silicon revision */
Peng Fan88383232015-06-11 18:30:36 +080098 return (type << 12) | (reg + (0x10 * (major + 1)));
Jason Liudec11122011-11-25 00:18:02 +000099}
100
Tim Harvey258d0462015-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 Fan441e9052016-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
Tim Harvey258d0462015-05-18 07:02:24 -0700117u32 get_cpu_speed_grade_hz(void)
118{
119 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
120 struct fuse_bank *bank = &ocotp->bank[0];
121 struct fuse_bank0_regs *fuse =
122 (struct fuse_bank0_regs *)bank->fuse_regs;
123 uint32_t val;
124
125 val = readl(&fuse->cfg3);
126 val >>= OCOTP_CFG3_SPEED_SHIFT;
127 val &= 0x3;
128
Peng Fane146c5c2016-08-11 14:02:45 +0800129 if (is_mx6ul() || is_mx6ull()) {
Peng Fan441e9052016-05-03 11:13:04 +0800130 if (val == OCOTP_CFG3_SPEED_528MHZ)
131 return 528000000;
132 else if (val == OCOTP_CFG3_SPEED_696MHZ)
133 return 69600000;
134 else
135 return 0;
136 }
137
Tim Harvey258d0462015-05-18 07:02:24 -0700138 switch (val) {
139 /* Valid for IMX6DQ */
140 case OCOTP_CFG3_SPEED_1P2GHZ:
Peng Fan6c4f76f2016-05-23 18:35:58 +0800141 if (is_mx6dq() || is_mx6dqp())
Tim Harvey258d0462015-05-18 07:02:24 -0700142 return 1200000000;
143 /* Valid for IMX6SX/IMX6SDL/IMX6DQ */
144 case OCOTP_CFG3_SPEED_1GHZ:
145 return 996000000;
146 /* Valid for IMX6DQ */
147 case OCOTP_CFG3_SPEED_850MHZ:
Peng Fan6c4f76f2016-05-23 18:35:58 +0800148 if (is_mx6dq() || is_mx6dqp())
Tim Harvey258d0462015-05-18 07:02:24 -0700149 return 852000000;
150 /* Valid for IMX6SX/IMX6SDL/IMX6DQ */
151 case OCOTP_CFG3_SPEED_800MHZ:
152 return 792000000;
153 }
154 return 0;
155}
156
Tim Harvey5e0e1932015-05-18 06:56:45 -0700157/*
158 * OCOTP_MEM0[7:6] (see Fusemap Description Table offset 0x480)
159 * defines a 2-bit Temperature Grade
160 *
161 * return temperature grade and min/max temperature in celcius
162 */
163#define OCOTP_MEM0_TEMP_SHIFT 6
164
165u32 get_cpu_temp_grade(int *minc, int *maxc)
166{
167 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
168 struct fuse_bank *bank = &ocotp->bank[1];
169 struct fuse_bank1_regs *fuse =
170 (struct fuse_bank1_regs *)bank->fuse_regs;
171 uint32_t val;
172
173 val = readl(&fuse->mem0);
174 val >>= OCOTP_MEM0_TEMP_SHIFT;
175 val &= 0x3;
176
177 if (minc && maxc) {
178 if (val == TEMP_AUTOMOTIVE) {
179 *minc = -40;
180 *maxc = 125;
181 } else if (val == TEMP_INDUSTRIAL) {
182 *minc = -40;
183 *maxc = 105;
184 } else if (val == TEMP_EXTCOMMERCIAL) {
185 *minc = -20;
186 *maxc = 105;
187 } else {
188 *minc = 0;
189 *maxc = 95;
190 }
191 }
192 return val;
193}
194
Fabio Estevam435998b2013-03-27 07:36:55 +0000195#ifdef CONFIG_REVISION_TAG
196u32 __weak get_board_rev(void)
197{
198 u32 cpurev = get_cpu_rev();
199 u32 type = ((cpurev >> 12) & 0xff);
200 if (type == MXC_CPU_MX6SOLO)
201 cpurev = (MXC_CPU_MX6DL) << 12 | (cpurev & 0xFFF);
202
Fabio Estevamf3d5a2c2014-01-26 15:06:41 -0200203 if (type == MXC_CPU_MX6D)
204 cpurev = (MXC_CPU_MX6Q) << 12 | (cpurev & 0xFFF);
205
Fabio Estevam435998b2013-03-27 07:36:55 +0000206 return cpurev;
207}
208#endif
209
Fabio Estevamcf621ff2013-12-26 14:51:31 -0200210static void clear_ldo_ramp(void)
211{
212 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
213 int reg;
214
215 /* ROM may modify LDO ramp up time according to fuse setting, so in
216 * order to be in the safe side we neeed to reset these settings to
217 * match the reset value: 0'b00
218 */
219 reg = readl(&anatop->ana_misc2);
220 reg &= ~(0x3f << 24);
221 writel(reg, &anatop->ana_misc2);
222}
223
Dirk Behme8c465942012-05-02 02:12:17 +0000224/*
Fabio Estevam2e95fe12014-06-13 01:42:37 -0300225 * Set the PMU_REG_CORE register
Dirk Behme8c465942012-05-02 02:12:17 +0000226 *
Fabio Estevam2e95fe12014-06-13 01:42:37 -0300227 * Set LDO_SOC/PU/ARM regulators to the specified millivolt level.
Dirk Behme8c465942012-05-02 02:12:17 +0000228 * Possible values are from 0.725V to 1.450V in steps of
229 * 0.025V (25mV).
230 */
Fabio Estevama47ec522013-12-26 14:51:33 -0200231static int set_ldo_voltage(enum ldo_reg ldo, u32 mv)
Dirk Behme8c465942012-05-02 02:12:17 +0000232{
233 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Fabio Estevam99b370b2013-12-26 14:51:34 -0200234 u32 val, step, old, reg = readl(&anatop->reg_core);
Fabio Estevama47ec522013-12-26 14:51:33 -0200235 u8 shift;
Dirk Behme8c465942012-05-02 02:12:17 +0000236
237 if (mv < 725)
238 val = 0x00; /* Power gated off */
239 else if (mv > 1450)
240 val = 0x1F; /* Power FET switched full on. No regulation */
241 else
242 val = (mv - 700) / 25;
243
Fabio Estevamcf621ff2013-12-26 14:51:31 -0200244 clear_ldo_ramp();
245
Fabio Estevama47ec522013-12-26 14:51:33 -0200246 switch (ldo) {
247 case LDO_SOC:
248 shift = 18;
249 break;
250 case LDO_PU:
251 shift = 9;
252 break;
253 case LDO_ARM:
254 shift = 0;
255 break;
256 default:
257 return -EINVAL;
258 }
259
Fabio Estevam99b370b2013-12-26 14:51:34 -0200260 old = (reg & (0x1F << shift)) >> shift;
261 step = abs(val - old);
262 if (step == 0)
263 return 0;
264
Fabio Estevama47ec522013-12-26 14:51:33 -0200265 reg = (reg & ~(0x1F << shift)) | (val << shift);
Dirk Behme8c465942012-05-02 02:12:17 +0000266 writel(reg, &anatop->reg_core);
Fabio Estevama47ec522013-12-26 14:51:33 -0200267
Fabio Estevam99b370b2013-12-26 14:51:34 -0200268 /*
269 * The LDO ramp-up is based on 64 clock cycles of 24 MHz = 2.6 us per
270 * step
271 */
272 udelay(3 * step);
273
Fabio Estevama47ec522013-12-26 14:51:33 -0200274 return 0;
Dirk Behme8c465942012-05-02 02:12:17 +0000275}
276
Anson Huang05a464f2014-01-23 14:00:18 +0800277static void set_ahb_rate(u32 val)
278{
279 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
280 u32 reg, div;
281
282 div = get_periph_clk() / val - 1;
283 reg = readl(&mxc_ccm->cbcdr);
284
285 writel((reg & (~MXC_CCM_CBCDR_AHB_PODF_MASK)) |
286 (div << MXC_CCM_CBCDR_AHB_PODF_OFFSET), &mxc_ccm->cbcdr);
287}
288
Anson Huang9a149bc2014-01-23 14:00:19 +0800289static void clear_mmdc_ch_mask(void)
290{
291 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Peng Fan53f3c9e2015-07-11 11:38:43 +0800292 u32 reg;
293 reg = readl(&mxc_ccm->ccdr);
Anson Huang9a149bc2014-01-23 14:00:19 +0800294
295 /* Clear MMDC channel mask */
Peng Fane146c5c2016-08-11 14:02:45 +0800296 if (is_mx6sx() || is_mx6ul() || is_mx6ull() || is_mx6sl())
Ye Li64cef442016-03-09 16:13:48 +0800297 reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK);
298 else
299 reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK | MXC_CCM_CCDR_MMDC_CH0_HS_MASK);
Peng Fan53f3c9e2015-07-11 11:38:43 +0800300 writel(reg, &mxc_ccm->ccdr);
Anson Huang9a149bc2014-01-23 14:00:19 +0800301}
302
Peng Fanc0e0ebf2015-01-15 14:22:32 +0800303static void init_bandgap(void)
304{
305 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
306 /*
307 * Ensure the bandgap has stabilized.
308 */
309 while (!(readl(&anatop->ana_misc0) & 0x80))
310 ;
311 /*
312 * For best noise performance of the analog blocks using the
313 * outputs of the bandgap, the reftop_selfbiasoff bit should
314 * be set.
315 */
316 writel(BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF, &anatop->ana_misc0_set);
Peng Fan6b989352016-08-11 14:02:50 +0800317 /*
318 * On i.MX6ULL, the LDO 1.2V bandgap voltage is 30mV higher. so set
319 * VBGADJ bits to 2b'110 to adjust it.
320 */
321 if (is_mx6ull())
322 writel(BM_ANADIG_ANA_MISC0_REFTOP_VBGADJ, &anatop->ana_misc0_set);
Peng Fanc0e0ebf2015-01-15 14:22:32 +0800323}
324
325
Ye.Li622dfbd2014-10-30 18:20:58 +0800326#ifdef CONFIG_MX6SL
327static void set_preclk_from_osc(void)
328{
329 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
330 u32 reg;
331
332 reg = readl(&mxc_ccm->cscmr1);
333 reg |= MXC_CCM_CSCMR1_PER_CLK_SEL_MASK;
334 writel(reg, &mxc_ccm->cscmr1);
335}
336#endif
337
Jason Liudec11122011-11-25 00:18:02 +0000338int arch_cpu_init(void)
339{
340 init_aips();
341
Anson Huang9a149bc2014-01-23 14:00:19 +0800342 /* Need to clear MMDC_CHx_MASK to make warm reset work. */
343 clear_mmdc_ch_mask();
344
Anson Huang05a464f2014-01-23 14:00:18 +0800345 /*
Peng Fanc0e0ebf2015-01-15 14:22:32 +0800346 * Disable self-bias circuit in the analog bandap.
347 * The self-bias circuit is used by the bandgap during startup.
348 * This bit should be set after the bandgap has initialized.
349 */
350 init_bandgap();
351
Peng Fanae86e3f2016-08-11 14:02:43 +0800352 if (!is_mx6ul() && !is_mx6ull()) {
Peng Fanf60137e2016-03-09 16:44:36 +0800353 /*
354 * When low freq boot is enabled, ROM will not set AHB
355 * freq, so we need to ensure AHB freq is 132MHz in such
356 * scenario.
357 *
358 * To i.MX6UL, when power up, default ARM core and
359 * AHB rate is 396M and 132M.
360 */
361 if (mxc_get_clock(MXC_ARM_CLK) == 396000000)
362 set_ahb_rate(132000000);
363 }
Anson Huang05a464f2014-01-23 14:00:18 +0800364
Peng Fan2b990ea2016-09-28 09:40:27 +0800365 if (is_mx6ul()) {
366 if (is_soc_rev(CHIP_REV_1_0) == 0) {
367 /*
368 * According to the design team's requirement on
369 * i.MX6UL,the PMIC_STBY_REQ PAD should be configured
370 * as open drain 100K (0x0000b8a0).
371 * Only exists on TO1.0
372 */
373 writel(0x0000b8a0, IOMUXC_BASE_ADDR + 0x29c);
374 } else {
375 /*
376 * From TO1.1, SNVS adds internal pull up control
377 * for POR_B, the register filed is GPBIT[1:0],
378 * after system boot up, it can be set to 2b'01
379 * to disable internal pull up.It can save about
380 * 30uA power in SNVS mode.
381 */
382 writel((readl(MX6UL_SNVS_LP_BASE_ADDR + 0x10) &
383 (~0x1400)) | 0x400,
384 MX6UL_SNVS_LP_BASE_ADDR + 0x10);
385 }
Peng Fana2cba652016-03-09 16:44:37 +0800386 }
387
Peng Fanb64bf0b2016-08-11 14:02:46 +0800388 if (is_mx6ull()) {
389 /*
390 * GPBIT[1:0] is suggested to set to 2'b11:
391 * 2'b00 : always PUP100K
392 * 2'b01 : PUP100K when PMIC_ON_REQ or SOC_NOT_FAIL
393 * 2'b10 : always disable PUP100K
394 * 2'b11 : PDN100K when SOC_FAIL, PUP100K when SOC_NOT_FAIL
395 * register offset is different from i.MX6UL, since
396 * i.MX6UL is fixed by ECO.
397 */
398 writel(readl(MX6UL_SNVS_LP_BASE_ADDR) |
399 0x3, MX6UL_SNVS_LP_BASE_ADDR);
400 }
401
Peng Fana2cba652016-03-09 16:44:37 +0800402 /* Set perclk to source from OSC 24MHz */
Ye.Li622dfbd2014-10-30 18:20:58 +0800403#if defined(CONFIG_MX6SL)
404 set_preclk_from_osc();
405#endif
406
Fabio Estevam48e65b02013-02-07 06:45:23 +0000407 imx_set_wdog_powerdown(false); /* Disable PDE bit of WMCR register */
Stefan Roese8338d1d2013-04-15 21:14:12 +0000408
409#ifdef CONFIG_APBH_DMA
410 /* Start APBH DMA */
411 mxs_dma_init();
412#endif
413
Dirk Behme0adb2152015-03-09 14:48:48 +0100414 init_src();
415
Jason Liudec11122011-11-25 00:18:02 +0000416 return 0;
417}
Jason Liudec11122011-11-25 00:18:02 +0000418
Peng Fan850dbca2016-01-28 16:51:26 +0800419#ifdef CONFIG_ENV_IS_IN_MMC
420__weak int board_mmc_get_env_dev(int devno)
421{
422 return CONFIG_SYS_MMC_ENV_DEV;
423}
424
Soeren Mochbc177f12016-02-04 14:41:15 +0100425static int mmc_get_boot_dev(void)
Peng Fan850dbca2016-01-28 16:51:26 +0800426{
427 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
428 u32 soc_sbmr = readl(&src_regs->sbmr1);
429 u32 bootsel;
430 int devno;
431
432 /*
433 * Refer to
434 * "i.MX 6Dual/6Quad Applications Processor Reference Manual"
435 * Chapter "8.5.3.1 Expansion Device eFUSE Configuration"
436 * i.MX6SL/SX/UL has same layout.
437 */
438 bootsel = (soc_sbmr & 0x000000FF) >> 6;
439
Soeren Mochbc177f12016-02-04 14:41:15 +0100440 /* No boot from sd/mmc */
Peng Fan850dbca2016-01-28 16:51:26 +0800441 if (bootsel != 1)
Soeren Mochbc177f12016-02-04 14:41:15 +0100442 return -1;
Peng Fan850dbca2016-01-28 16:51:26 +0800443
444 /* BOOT_CFG2[3] and BOOT_CFG2[4] */
445 devno = (soc_sbmr & 0x00001800) >> 11;
446
Soeren Mochbc177f12016-02-04 14:41:15 +0100447 return devno;
448}
449
450int mmc_get_env_dev(void)
451{
452 int devno = mmc_get_boot_dev();
453
454 /* If not boot from sd/mmc, use default value */
455 if (devno < 0)
456 return CONFIG_SYS_MMC_ENV_DEV;
457
Peng Fan850dbca2016-01-28 16:51:26 +0800458 return board_mmc_get_env_dev(devno);
459}
Soeren Mochbc177f12016-02-04 14:41:15 +0100460
461#ifdef CONFIG_SYS_MMC_ENV_PART
462__weak int board_mmc_get_env_part(int devno)
463{
464 return CONFIG_SYS_MMC_ENV_PART;
465}
466
467uint mmc_get_env_part(struct mmc *mmc)
468{
469 int devno = mmc_get_boot_dev();
470
471 /* If not boot from sd/mmc, use default value */
472 if (devno < 0)
473 return CONFIG_SYS_MMC_ENV_PART;
474
475 return board_mmc_get_env_part(devno);
476}
477#endif
Peng Fan850dbca2016-01-28 16:51:26 +0800478#endif
479
Fabio Estevam99b370b2013-12-26 14:51:34 -0200480int board_postclk_init(void)
481{
482 set_ldo_voltage(LDO_SOC, 1175); /* Set VDDSOC to 1.175V */
483
484 return 0;
485}
486
Jason Liudec11122011-11-25 00:18:02 +0000487#if defined(CONFIG_FEC_MXC)
Fabio Estevam04fc1282011-12-20 05:46:31 +0000488void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
Jason Liudec11122011-11-25 00:18:02 +0000489{
Benoît Thébaudeaufa7e3952013-04-23 10:17:38 +0000490 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
491 struct fuse_bank *bank = &ocotp->bank[4];
Jason Liudec11122011-11-25 00:18:02 +0000492 struct fuse_bank4_regs *fuse =
493 (struct fuse_bank4_regs *)bank->fuse_regs;
494
Peng Fane146c5c2016-08-11 14:02:45 +0800495 if ((is_mx6sx() || is_mx6ul() || is_mx6ull()) && dev_id == 1) {
Ye Lid5d8bf72016-02-01 10:41:31 +0800496 u32 value = readl(&fuse->mac_addr2);
497 mac[0] = value >> 24 ;
498 mac[1] = value >> 16 ;
499 mac[2] = value >> 8 ;
500 mac[3] = value ;
501
502 value = readl(&fuse->mac_addr1);
503 mac[4] = value >> 24 ;
504 mac[5] = value >> 16 ;
505
506 } else {
507 u32 value = readl(&fuse->mac_addr1);
508 mac[0] = (value >> 8);
509 mac[1] = value ;
Jason Liudec11122011-11-25 00:18:02 +0000510
Ye Lid5d8bf72016-02-01 10:41:31 +0800511 value = readl(&fuse->mac_addr0);
512 mac[2] = value >> 24 ;
513 mac[3] = value >> 16 ;
514 mac[4] = value >> 8 ;
515 mac[5] = value ;
516 }
Jason Liudec11122011-11-25 00:18:02 +0000517
518}
519#endif
Troy Kisky0ca618c2012-08-15 10:31:20 +0000520
Troy Kisky0ca618c2012-08-15 10:31:20 +0000521/*
522 * cfg_val will be used for
523 * Boot_cfg4[7:0]:Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
Nikita Kiryanov9fba8422014-10-29 19:28:33 +0200524 * After reset, if GPR10[28] is 1, ROM will use GPR9[25:0]
525 * instead of SBMR1 to determine the boot device.
Troy Kisky0ca618c2012-08-15 10:31:20 +0000526 */
527const struct boot_mode soc_boot_modes[] = {
528 {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)},
529 /* reserved value should start rom usb */
Stefan Agnereb4b62b2016-09-15 15:04:39 -0700530 {"usb", MAKE_CFGVAL(0x10, 0x00, 0x00, 0x00)},
Troy Kisky0ca618c2012-08-15 10:31:20 +0000531 {"sata", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
Nikolay Dimitrov284d9012014-08-10 20:03:07 +0300532 {"ecspi1:0", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x08)},
533 {"ecspi1:1", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x18)},
534 {"ecspi1:2", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x28)},
535 {"ecspi1:3", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x38)},
Troy Kisky0ca618c2012-08-15 10:31:20 +0000536 /* 4 bit bus width */
537 {"esdhc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
538 {"esdhc2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
539 {"esdhc3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
540 {"esdhc4", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
541 {NULL, 0},
542};
Stephen Warren57ab23f2013-02-26 12:28:29 +0000543
Peng Fan92683e62015-10-29 15:54:50 +0800544void reset_misc(void)
545{
546#ifdef CONFIG_VIDEO_MXS
547 lcdif_power_down();
548#endif
549}
550
Stephen Warren57ab23f2013-02-26 12:28:29 +0000551void s_init(void)
552{
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700553 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Ye.Li29876872014-09-09 10:17:00 +0800554 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700555 u32 mask480;
556 u32 mask528;
Ye.Li29876872014-09-09 10:17:00 +0800557 u32 reg, periph1, periph2;
Fabio Estevam6633e3f2014-07-09 16:13:29 -0300558
Peng Fane146c5c2016-08-11 14:02:45 +0800559 if (is_mx6sx() || is_mx6ul() || is_mx6ull())
Fabio Estevam6633e3f2014-07-09 16:13:29 -0300560 return;
561
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700562 /* Due to hardware limitation, on MX6Q we need to gate/ungate all PFDs
563 * to make sure PFD is working right, otherwise, PFDs may
564 * not output clock after reset, MX6DL and MX6SL have added 396M pfd
565 * workaround in ROM code, as bus clock need it
566 */
567
568 mask480 = ANATOP_PFD_CLKGATE_MASK(0) |
569 ANATOP_PFD_CLKGATE_MASK(1) |
570 ANATOP_PFD_CLKGATE_MASK(2) |
571 ANATOP_PFD_CLKGATE_MASK(3);
Ye.Li29876872014-09-09 10:17:00 +0800572 mask528 = ANATOP_PFD_CLKGATE_MASK(1) |
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700573 ANATOP_PFD_CLKGATE_MASK(3);
574
Ye.Li29876872014-09-09 10:17:00 +0800575 reg = readl(&ccm->cbcmr);
576 periph2 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_MASK)
577 >> MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_OFFSET);
578 periph1 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK)
579 >> MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_OFFSET);
580
581 /* Checking if PLL2 PFD0 or PLL2 PFD2 is using for periph clock */
582 if ((periph2 != 0x2) && (periph1 != 0x2))
583 mask528 |= ANATOP_PFD_CLKGATE_MASK(0);
584
585 if ((periph2 != 0x1) && (periph1 != 0x1) &&
586 (periph2 != 0x3) && (periph1 != 0x3))
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700587 mask528 |= ANATOP_PFD_CLKGATE_MASK(2);
Ye.Li29876872014-09-09 10:17:00 +0800588
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700589 writel(mask480, &anatop->pfd_480_set);
590 writel(mask528, &anatop->pfd_528_set);
591 writel(mask480, &anatop->pfd_480_clr);
592 writel(mask528, &anatop->pfd_528_clr);
Stephen Warren57ab23f2013-02-26 12:28:29 +0000593}
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -0500594
595#ifdef CONFIG_IMX_HDMI
596void imx_enable_hdmi_phy(void)
597{
598 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
599 u8 reg;
600 reg = readb(&hdmi->phy_conf0);
601 reg |= HDMI_PHY_CONF0_PDZ_MASK;
602 writeb(reg, &hdmi->phy_conf0);
603 udelay(3000);
604 reg |= HDMI_PHY_CONF0_ENTMDS_MASK;
605 writeb(reg, &hdmi->phy_conf0);
606 udelay(3000);
607 reg |= HDMI_PHY_CONF0_GEN2_TXPWRON_MASK;
608 writeb(reg, &hdmi->phy_conf0);
609 writeb(HDMI_MC_PHYRSTZ_ASSERT, &hdmi->mc_phyrstz);
610}
611
612void imx_setup_hdmi(void)
613{
614 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
615 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
Peng Fan95ae6122016-03-09 16:07:23 +0800616 int reg, count;
617 u8 val;
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -0500618
619 /* Turn on HDMI PHY clock */
620 reg = readl(&mxc_ccm->CCGR2);
621 reg |= MXC_CCM_CCGR2_HDMI_TX_IAHBCLK_MASK|
622 MXC_CCM_CCGR2_HDMI_TX_ISFRCLK_MASK;
623 writel(reg, &mxc_ccm->CCGR2);
624 writeb(HDMI_MC_PHYRSTZ_DEASSERT, &hdmi->mc_phyrstz);
625 reg = readl(&mxc_ccm->chsccdr);
626 reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK|
627 MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK|
628 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK);
629 reg |= (CHSCCDR_PODF_DIVIDE_BY_3
630 << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET)
631 |(CHSCCDR_IPU_PRE_CLK_540M_PFD
632 << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET);
633 writel(reg, &mxc_ccm->chsccdr);
Peng Fan95ae6122016-03-09 16:07:23 +0800634
635 /* Clear the overflow condition */
636 if (readb(&hdmi->ih_fc_stat2) & HDMI_IH_FC_STAT2_OVERFLOW_MASK) {
637 /* TMDS software reset */
638 writeb((u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, &hdmi->mc_swrstz);
639 val = readb(&hdmi->fc_invidconf);
640 /* Need minimum 3 times to write to clear the register */
641 for (count = 0 ; count < 5 ; count++)
642 writeb(val, &hdmi->fc_invidconf);
643 }
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -0500644}
645#endif
Peng Fanfb3a3b72016-01-28 16:55:05 +0800646
647#ifdef CONFIG_IMX_BOOTAUX
648int arch_auxiliary_core_up(u32 core_id, u32 boot_private_data)
649{
650 struct src *src_reg;
651 u32 stack, pc;
652
653 if (!boot_private_data)
654 return -EINVAL;
655
656 stack = *(u32 *)boot_private_data;
657 pc = *(u32 *)(boot_private_data + 4);
658
659 /* Set the stack and pc to M4 bootROM */
660 writel(stack, M4_BOOTROM_BASE_ADDR);
661 writel(pc, M4_BOOTROM_BASE_ADDR + 4);
662
663 /* Enable M4 */
664 src_reg = (struct src *)SRC_BASE_ADDR;
665 clrsetbits_le32(&src_reg->scr, SRC_SCR_M4C_NON_SCLR_RST_MASK,
666 SRC_SCR_M4_ENABLE_MASK);
667
668 return 0;
669}
670
671int arch_auxiliary_core_check_up(u32 core_id)
672{
673 struct src *src_reg = (struct src *)SRC_BASE_ADDR;
674 unsigned val;
675
676 val = readl(&src_reg->scr);
677
678 if (val & SRC_SCR_M4C_NON_SCLR_RST_MASK)
679 return 0; /* assert in reset */
680
681 return 1;
682}
683#endif