]> git.ipfire.org Git - people/ms/u-boot.git/blame - arch/arm/cpu/armv7/mx6/soc.c
imx: mx6ull: fix USB bmode for i.MX 6UL and 6ULL
[people/ms/u-boot.git] / arch / arm / cpu / armv7 / mx6 / soc.c
CommitLineData
23608e23
JL
1/*
2 * (C) Copyright 2007
3 * Sascha Hauer, Pengutronix
4 *
5 * (C) Copyright 2009 Freescale Semiconductor, Inc.
6 *
1a459660 7 * SPDX-License-Identifier: GPL-2.0+
23608e23
JL
8 */
9
10#include <common.h>
1221ce45 11#include <linux/errno.h>
23608e23
JL
12#include <asm/io.h>
13#include <asm/arch/imx-regs.h>
14#include <asm/arch/clock.h>
15#include <asm/arch/sys_proto.h>
124a06d7 16#include <asm/imx-common/boot_mode.h>
ae695b18 17#include <asm/imx-common/dma.h>
6b50bfe5 18#include <asm/imx-common/hab.h>
76c91e66 19#include <stdbool.h>
5ea7f0e3
PKS
20#include <asm/arch/mxc_hdmi.h>
21#include <asm/arch/crm_regs.h>
7a264168
YL
22#include <dm.h>
23#include <imx_thermal.h>
1a43dc11 24#include <mmc.h>
23608e23 25
3d622b78
FE
26enum ldo_reg {
27 LDO_ARM,
28 LDO_SOC,
29 LDO_PU,
30};
31
20332a06
TK
32struct scu_regs {
33 u32 ctrl;
34 u32 config;
35 u32 status;
36 u32 invalidate;
37 u32 fpga_rev;
38};
39
1368f993 40#if defined(CONFIG_IMX_THERMAL)
7a264168
YL
41static 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
6b50bfe5
AA
53#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
a76df709
GH
60u32 get_nr_cpus(void)
61{
62 struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
63 return readl(&scu->config) & 3;
64}
65
23608e23
JL
66u32 get_cpu_rev(void)
67{
a7683867 68 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
20332a06
TK
69 u32 reg = readl(&anatop->digprog_sololite);
70 u32 type = ((reg >> 16) & 0xff);
d0acd993 71 u32 major, cfg = 0;
a7683867 72
20332a06
TK
73 if (type != MXC_CPU_MX6SL) {
74 reg = readl(&anatop->digprog);
94db6655 75 struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
d0acd993 76 cfg = readl(&scu->config) & 3;
20332a06
TK
77 type = ((reg >> 16) & 0xff);
78 if (type == MXC_CPU_MX6DL) {
20332a06
TK
79 if (!cfg)
80 type = MXC_CPU_MX6SOLO;
81 }
94db6655
FE
82
83 if (type == MXC_CPU_MX6Q) {
84 if (cfg == 1)
85 type = MXC_CPU_MX6D;
86 }
87
20332a06 88 }
dfd4861c 89 major = ((reg >> 8) & 0xff);
d0acd993
PF
90 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 }
20332a06 97 reg &= 0xff; /* mx6 silicon revision */
dfd4861c 98 return (type << 12) | (reg + (0x10 * (major + 1)));
23608e23
JL
99}
100
9b9449c3
TH
101/*
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
d15a244b
PF
111/*
112 * For i.MX6UL
113 */
114#define OCOTP_CFG3_SPEED_528MHZ 1
115#define OCOTP_CFG3_SPEED_696MHZ 2
116
9b9449c3
TH
117u32 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
6615da4d 129 if (is_mx6ul() || is_mx6ull()) {
d15a244b
PF
130 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
9b9449c3
TH
138 switch (val) {
139 /* Valid for IMX6DQ */
140 case OCOTP_CFG3_SPEED_1P2GHZ:
04cb3c0b 141 if (is_mx6dq() || is_mx6dqp())
9b9449c3
TH
142 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:
04cb3c0b 148 if (is_mx6dq() || is_mx6dqp())
9b9449c3
TH
149 return 852000000;
150 /* Valid for IMX6SX/IMX6SDL/IMX6DQ */
151 case OCOTP_CFG3_SPEED_800MHZ:
152 return 792000000;
153 }
154 return 0;
155}
156
f0e8e894
TH
157/*
158 * OCOTP_MEM0[7:6] (see Fusemap Description Table offset 0x480)
159 * defines a 2-bit Temperature Grade
160 *
65496a34 161 * return temperature grade and min/max temperature in Celsius
f0e8e894
TH
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
38e70077
FE
195#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
94db6655
FE
203 if (type == MXC_CPU_MX6D)
204 cpurev = (MXC_CPU_MX6Q) << 12 | (cpurev & 0xFFF);
205
38e70077
FE
206 return cpurev;
207}
208#endif
209
e113fd19
FE
210static 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
cac833a9 224/*
157f45da 225 * Set the PMU_REG_CORE register
cac833a9 226 *
157f45da 227 * Set LDO_SOC/PU/ARM regulators to the specified millivolt level.
cac833a9
DB
228 * Possible values are from 0.725V to 1.450V in steps of
229 * 0.025V (25mV).
230 */
3d622b78 231static int set_ldo_voltage(enum ldo_reg ldo, u32 mv)
cac833a9
DB
232{
233 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
39f0ac93 234 u32 val, step, old, reg = readl(&anatop->reg_core);
3d622b78 235 u8 shift;
cac833a9
DB
236
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
e113fd19
FE
244 clear_ldo_ramp();
245
3d622b78
FE
246 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
39f0ac93
FE
260 old = (reg & (0x1F << shift)) >> shift;
261 step = abs(val - old);
262 if (step == 0)
263 return 0;
264
3d622b78 265 reg = (reg & ~(0x1F << shift)) | (val << shift);
cac833a9 266 writel(reg, &anatop->reg_core);
3d622b78 267
39f0ac93
FE
268 /*
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
3d622b78 274 return 0;
cac833a9
DB
275}
276
5c92edc2
AH
277static 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
16197bb8
AH
289static void clear_mmdc_ch_mask(void)
290{
291 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
e1c2d68b
PF
292 u32 reg;
293 reg = readl(&mxc_ccm->ccdr);
16197bb8
AH
294
295 /* Clear MMDC channel mask */
6615da4d 296 if (is_mx6sx() || is_mx6ul() || is_mx6ull() || is_mx6sl())
b777789e
YL
297 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);
e1c2d68b 300 writel(reg, &mxc_ccm->ccdr);
16197bb8
AH
301}
302
97c16dc8
PF
303#define OCOTP_MEM0_REFTOP_TRIM_SHIFT 8
304
1f516faa
PF
305static void init_bandgap(void)
306{
307 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
97c16dc8
PF
308 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
309 struct fuse_bank *bank = &ocotp->bank[1];
310 struct fuse_bank1_regs *fuse =
311 (struct fuse_bank1_regs *)bank->fuse_regs;
312 uint32_t val;
313
1f516faa
PF
314 /*
315 * Ensure the bandgap has stabilized.
316 */
317 while (!(readl(&anatop->ana_misc0) & 0x80))
318 ;
319 /*
320 * For best noise performance of the analog blocks using the
321 * outputs of the bandgap, the reftop_selfbiasoff bit should
322 * be set.
323 */
324 writel(BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF, &anatop->ana_misc0_set);
5b66482d 325 /*
97c16dc8
PF
326 * On i.MX6ULL,we need to set VBGADJ bits according to the
327 * REFTOP_TRIM[3:0] in fuse table
328 * 000 - set REFTOP_VBGADJ[2:0] to 3b'110,
329 * 110 - set REFTOP_VBGADJ[2:0] to 3b'000,
330 * 001 - set REFTOP_VBGADJ[2:0] to 3b'001,
331 * 010 - set REFTOP_VBGADJ[2:0] to 3b'010,
332 * 011 - set REFTOP_VBGADJ[2:0] to 3b'011,
333 * 100 - set REFTOP_VBGADJ[2:0] to 3b'100,
334 * 101 - set REFTOP_VBGADJ[2:0] to 3b'101,
335 * 111 - set REFTOP_VBGADJ[2:0] to 3b'111,
5b66482d 336 */
97c16dc8
PF
337 if (is_mx6ull()) {
338 val = readl(&fuse->mem0);
339 val >>= OCOTP_MEM0_REFTOP_TRIM_SHIFT;
340 val &= 0x7;
1f516faa 341
97c16dc8
PF
342 writel(val << BM_ANADIG_ANA_MISC0_REFTOP_VBGADJ_SHIFT,
343 &anatop->ana_misc0_set);
344 }
345}
1f516faa 346
0f8ec145
YL
347#ifdef CONFIG_MX6SL
348static void set_preclk_from_osc(void)
349{
350 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
351 u32 reg;
352
353 reg = readl(&mxc_ccm->cscmr1);
354 reg |= MXC_CCM_CSCMR1_PER_CLK_SEL_MASK;
355 writel(reg, &mxc_ccm->cscmr1);
356}
357#endif
358
23608e23
JL
359int arch_cpu_init(void)
360{
361 init_aips();
362
16197bb8
AH
363 /* Need to clear MMDC_CHx_MASK to make warm reset work. */
364 clear_mmdc_ch_mask();
365
1f516faa
PF
366 /*
367 * Disable self-bias circuit in the analog bandap.
368 * The self-bias circuit is used by the bandgap during startup.
369 * This bit should be set after the bandgap has initialized.
370 */
371 init_bandgap();
372
cdf33c94 373 if (!is_mx6ul() && !is_mx6ull()) {
e4dc3fc0
PF
374 /*
375 * When low freq boot is enabled, ROM will not set AHB
376 * freq, so we need to ensure AHB freq is 132MHz in such
377 * scenario.
378 *
379 * To i.MX6UL, when power up, default ARM core and
380 * AHB rate is 396M and 132M.
381 */
382 if (mxc_get_clock(MXC_ARM_CLK) == 396000000)
383 set_ahb_rate(132000000);
384 }
5c92edc2 385
f15ece38
PF
386 if (is_mx6ul()) {
387 if (is_soc_rev(CHIP_REV_1_0) == 0) {
388 /*
389 * According to the design team's requirement on
390 * i.MX6UL,the PMIC_STBY_REQ PAD should be configured
391 * as open drain 100K (0x0000b8a0).
392 * Only exists on TO1.0
393 */
394 writel(0x0000b8a0, IOMUXC_BASE_ADDR + 0x29c);
395 } else {
396 /*
397 * From TO1.1, SNVS adds internal pull up control
398 * for POR_B, the register filed is GPBIT[1:0],
399 * after system boot up, it can be set to 2b'01
400 * to disable internal pull up.It can save about
401 * 30uA power in SNVS mode.
402 */
403 writel((readl(MX6UL_SNVS_LP_BASE_ADDR + 0x10) &
404 (~0x1400)) | 0x400,
405 MX6UL_SNVS_LP_BASE_ADDR + 0x10);
406 }
7082d879
PF
407 }
408
b4714616
PF
409 if (is_mx6ull()) {
410 /*
411 * GPBIT[1:0] is suggested to set to 2'b11:
412 * 2'b00 : always PUP100K
413 * 2'b01 : PUP100K when PMIC_ON_REQ or SOC_NOT_FAIL
414 * 2'b10 : always disable PUP100K
415 * 2'b11 : PDN100K when SOC_FAIL, PUP100K when SOC_NOT_FAIL
416 * register offset is different from i.MX6UL, since
417 * i.MX6UL is fixed by ECO.
418 */
419 writel(readl(MX6UL_SNVS_LP_BASE_ADDR) |
420 0x3, MX6UL_SNVS_LP_BASE_ADDR);
421 }
422
7082d879 423 /* Set perclk to source from OSC 24MHz */
0f8ec145
YL
424#if defined(CONFIG_MX6SL)
425 set_preclk_from_osc();
426#endif
427
76c91e66 428 imx_set_wdog_powerdown(false); /* Disable PDE bit of WMCR register */
ae695b18
SR
429
430#ifdef CONFIG_APBH_DMA
431 /* Start APBH DMA */
432 mxs_dma_init();
433#endif
434
9d16c52f
DB
435 init_src();
436
23608e23
JL
437 return 0;
438}
23608e23 439
216d286c
PF
440#ifdef CONFIG_ENV_IS_IN_MMC
441__weak int board_mmc_get_env_dev(int devno)
442{
443 return CONFIG_SYS_MMC_ENV_DEV;
444}
445
1a43dc11 446static int mmc_get_boot_dev(void)
216d286c
PF
447{
448 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
449 u32 soc_sbmr = readl(&src_regs->sbmr1);
450 u32 bootsel;
451 int devno;
452
453 /*
454 * Refer to
455 * "i.MX 6Dual/6Quad Applications Processor Reference Manual"
456 * Chapter "8.5.3.1 Expansion Device eFUSE Configuration"
457 * i.MX6SL/SX/UL has same layout.
458 */
459 bootsel = (soc_sbmr & 0x000000FF) >> 6;
460
1a43dc11 461 /* No boot from sd/mmc */
216d286c 462 if (bootsel != 1)
1a43dc11 463 return -1;
216d286c
PF
464
465 /* BOOT_CFG2[3] and BOOT_CFG2[4] */
466 devno = (soc_sbmr & 0x00001800) >> 11;
467
1a43dc11
SM
468 return devno;
469}
470
471int mmc_get_env_dev(void)
472{
473 int devno = mmc_get_boot_dev();
474
475 /* If not boot from sd/mmc, use default value */
476 if (devno < 0)
477 return CONFIG_SYS_MMC_ENV_DEV;
478
216d286c
PF
479 return board_mmc_get_env_dev(devno);
480}
1a43dc11
SM
481
482#ifdef CONFIG_SYS_MMC_ENV_PART
483__weak int board_mmc_get_env_part(int devno)
484{
485 return CONFIG_SYS_MMC_ENV_PART;
486}
487
488uint mmc_get_env_part(struct mmc *mmc)
489{
490 int devno = mmc_get_boot_dev();
491
492 /* If not boot from sd/mmc, use default value */
493 if (devno < 0)
494 return CONFIG_SYS_MMC_ENV_PART;
495
496 return board_mmc_get_env_part(devno);
497}
498#endif
216d286c
PF
499#endif
500
39f0ac93
FE
501int board_postclk_init(void)
502{
503 set_ldo_voltage(LDO_SOC, 1175); /* Set VDDSOC to 1.175V */
504
505 return 0;
506}
507
23608e23 508#if defined(CONFIG_FEC_MXC)
be252b65 509void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
23608e23 510{
8f3ff11c
BT
511 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
512 struct fuse_bank *bank = &ocotp->bank[4];
23608e23
JL
513 struct fuse_bank4_regs *fuse =
514 (struct fuse_bank4_regs *)bank->fuse_regs;
515
6615da4d 516 if ((is_mx6sx() || is_mx6ul() || is_mx6ull()) && dev_id == 1) {
d4d1dd67
YL
517 u32 value = readl(&fuse->mac_addr2);
518 mac[0] = value >> 24 ;
519 mac[1] = value >> 16 ;
520 mac[2] = value >> 8 ;
521 mac[3] = value ;
522
523 value = readl(&fuse->mac_addr1);
524 mac[4] = value >> 24 ;
525 mac[5] = value >> 16 ;
526
527 } else {
528 u32 value = readl(&fuse->mac_addr1);
529 mac[0] = (value >> 8);
530 mac[1] = value ;
531
532 value = readl(&fuse->mac_addr0);
533 mac[2] = value >> 24 ;
534 mac[3] = value >> 16 ;
535 mac[4] = value >> 8 ;
536 mac[5] = value ;
537 }
23608e23
JL
538
539}
540#endif
124a06d7 541
124a06d7
TK
542/*
543 * cfg_val will be used for
544 * Boot_cfg4[7:0]:Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
f2863ff3
NK
545 * After reset, if GPR10[28] is 1, ROM will use GPR9[25:0]
546 * instead of SBMR1 to determine the boot device.
124a06d7
TK
547 */
548const struct boot_mode soc_boot_modes[] = {
549 {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)},
550 /* reserved value should start rom usb */
3fd95790
SA
551#if defined(CONFIG_MX6UL) || defined(CONFIG_MX6ULL)
552 {"usb", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
553#else
81c4eccb 554 {"usb", MAKE_CFGVAL(0x10, 0x00, 0x00, 0x00)},
3fd95790 555#endif
124a06d7 556 {"sata", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
2d59e3ec
ND
557 {"ecspi1:0", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x08)},
558 {"ecspi1:1", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x18)},
559 {"ecspi1:2", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x28)},
560 {"ecspi1:3", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x38)},
124a06d7
TK
561 /* 4 bit bus width */
562 {"esdhc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
563 {"esdhc2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
564 {"esdhc3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
565 {"esdhc4", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
566 {NULL, 0},
567};
8f393776 568
eb111bb3
PF
569void reset_misc(void)
570{
571#ifdef CONFIG_VIDEO_MXS
572 lcdif_power_down();
573#endif
574}
575
8f393776
SW
576void s_init(void)
577{
8467faef 578 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
9293d7fd 579 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
8467faef
EN
580 u32 mask480;
581 u32 mask528;
9293d7fd 582 u32 reg, periph1, periph2;
a3df99b5 583
6615da4d 584 if (is_mx6sx() || is_mx6ul() || is_mx6ull())
a3df99b5
FE
585 return;
586
8467faef
EN
587 /* Due to hardware limitation, on MX6Q we need to gate/ungate all PFDs
588 * to make sure PFD is working right, otherwise, PFDs may
589 * not output clock after reset, MX6DL and MX6SL have added 396M pfd
590 * workaround in ROM code, as bus clock need it
591 */
592
593 mask480 = ANATOP_PFD_CLKGATE_MASK(0) |
594 ANATOP_PFD_CLKGATE_MASK(1) |
595 ANATOP_PFD_CLKGATE_MASK(2) |
596 ANATOP_PFD_CLKGATE_MASK(3);
9293d7fd 597 mask528 = ANATOP_PFD_CLKGATE_MASK(1) |
8467faef
EN
598 ANATOP_PFD_CLKGATE_MASK(3);
599
9293d7fd
YL
600 reg = readl(&ccm->cbcmr);
601 periph2 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_MASK)
602 >> MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_OFFSET);
603 periph1 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK)
604 >> MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_OFFSET);
605
606 /* Checking if PLL2 PFD0 or PLL2 PFD2 is using for periph clock */
607 if ((periph2 != 0x2) && (periph1 != 0x2))
608 mask528 |= ANATOP_PFD_CLKGATE_MASK(0);
609
610 if ((periph2 != 0x1) && (periph1 != 0x1) &&
611 (periph2 != 0x3) && (periph1 != 0x3))
8467faef 612 mask528 |= ANATOP_PFD_CLKGATE_MASK(2);
9293d7fd 613
8467faef
EN
614 writel(mask480, &anatop->pfd_480_set);
615 writel(mask528, &anatop->pfd_528_set);
616 writel(mask480, &anatop->pfd_480_clr);
617 writel(mask528, &anatop->pfd_528_clr);
8f393776 618}
5ea7f0e3
PKS
619
620#ifdef CONFIG_IMX_HDMI
621void imx_enable_hdmi_phy(void)
622{
623 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
624 u8 reg;
625 reg = readb(&hdmi->phy_conf0);
626 reg |= HDMI_PHY_CONF0_PDZ_MASK;
627 writeb(reg, &hdmi->phy_conf0);
628 udelay(3000);
629 reg |= HDMI_PHY_CONF0_ENTMDS_MASK;
630 writeb(reg, &hdmi->phy_conf0);
631 udelay(3000);
632 reg |= HDMI_PHY_CONF0_GEN2_TXPWRON_MASK;
633 writeb(reg, &hdmi->phy_conf0);
634 writeb(HDMI_MC_PHYRSTZ_ASSERT, &hdmi->mc_phyrstz);
635}
636
637void imx_setup_hdmi(void)
638{
639 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
640 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
00b1d2d3
PF
641 int reg, count;
642 u8 val;
5ea7f0e3
PKS
643
644 /* Turn on HDMI PHY clock */
645 reg = readl(&mxc_ccm->CCGR2);
646 reg |= MXC_CCM_CCGR2_HDMI_TX_IAHBCLK_MASK|
647 MXC_CCM_CCGR2_HDMI_TX_ISFRCLK_MASK;
648 writel(reg, &mxc_ccm->CCGR2);
649 writeb(HDMI_MC_PHYRSTZ_DEASSERT, &hdmi->mc_phyrstz);
650 reg = readl(&mxc_ccm->chsccdr);
651 reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK|
652 MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK|
653 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK);
654 reg |= (CHSCCDR_PODF_DIVIDE_BY_3
655 << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET)
656 |(CHSCCDR_IPU_PRE_CLK_540M_PFD
657 << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET);
658 writel(reg, &mxc_ccm->chsccdr);
00b1d2d3
PF
659
660 /* Clear the overflow condition */
661 if (readb(&hdmi->ih_fc_stat2) & HDMI_IH_FC_STAT2_OVERFLOW_MASK) {
662 /* TMDS software reset */
663 writeb((u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, &hdmi->mc_swrstz);
664 val = readb(&hdmi->fc_invidconf);
665 /* Need minimum 3 times to write to clear the register */
666 for (count = 0 ; count < 5 ; count++)
667 writeb(val, &hdmi->fc_invidconf);
668 }
5ea7f0e3
PKS
669}
670#endif
0623d375
PF
671
672#ifdef CONFIG_IMX_BOOTAUX
673int arch_auxiliary_core_up(u32 core_id, u32 boot_private_data)
674{
675 struct src *src_reg;
676 u32 stack, pc;
677
678 if (!boot_private_data)
679 return -EINVAL;
680
681 stack = *(u32 *)boot_private_data;
682 pc = *(u32 *)(boot_private_data + 4);
683
684 /* Set the stack and pc to M4 bootROM */
685 writel(stack, M4_BOOTROM_BASE_ADDR);
686 writel(pc, M4_BOOTROM_BASE_ADDR + 4);
687
688 /* Enable M4 */
689 src_reg = (struct src *)SRC_BASE_ADDR;
690 clrsetbits_le32(&src_reg->scr, SRC_SCR_M4C_NON_SCLR_RST_MASK,
691 SRC_SCR_M4_ENABLE_MASK);
692
693 return 0;
694}
695
696int arch_auxiliary_core_check_up(u32 core_id)
697{
698 struct src *src_reg = (struct src *)SRC_BASE_ADDR;
699 unsigned val;
700
701 val = readl(&src_reg->scr);
702
703 if (val & SRC_SCR_M4C_NON_SCLR_RST_MASK)
704 return 0; /* assert in reset */
705
706 return 1;
707}
708#endif