]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/armv7/mx6/soc.c
karo: fdt: fix panel-dpi support
[karo-tx-uboot.git] / arch / arm / cpu / armv7 / mx6 / soc.c
1 /*
2  * (C) Copyright 2007
3  * Sascha Hauer, Pengutronix
4  *
5  * (C) Copyright 2009 Freescale Semiconductor, Inc.
6  *
7  * SPDX-License-Identifier:     GPL-2.0+
8  */
9
10 #include <common.h>
11 #include <div64.h>
12 #include <ipu.h>
13 #include <fuse.h>
14 #include <thermal.h>
15 #include <asm/armv7.h>
16 #include <asm/bootm.h>
17 #include <asm/pl310.h>
18 #include <asm/errno.h>
19 #include <asm/io.h>
20 #include <asm/arch/imx-regs.h>
21 #include <asm/arch/clock.h>
22 #include <asm/arch/regs-ocotp.h>
23 #include <asm/arch/sys_proto.h>
24 #include <asm/imx-common/boot_mode.h>
25 #include <asm/imx-common/dma.h>
26 #include <stdbool.h>
27 #include <asm/arch/mxc_hdmi.h>
28 #include <asm/arch/crm_regs.h>
29 #include <dm.h>
30 #include <imx_thermal.h>
31
32 DECLARE_GLOBAL_DATA_PTR;
33
34 #define __data __attribute__((section(".data")))
35
36 #ifdef CONFIG_MX6_TEMPERATURE_MIN
37 #define TEMPERATURE_MIN                 CONFIG_MX6_TEMPERATURE_MIN
38 #else
39 #define TEMPERATURE_MIN                 (-40)
40 #endif
41 #ifdef CONFIG_MX6_TEMPERATURE_HOT
42 #define TEMPERATURE_HOT                 CONFIG_MX6_TEMPERATURE_HOT
43 #else
44 #define TEMPERATURE_HOT                 80
45 #endif
46 #ifdef CONFIG_MX6_TEMPERATURE_MAX
47 #define TEMPERATURE_MAX                 CONFIG_MX6_TEMPERATURE_MAX
48 #else
49 #define TEMPERATURE_MAX                 125
50 #endif
51 #define TEMP_AVG_COUNT                  5
52 #define TEMP_WARN_THRESHOLD             5
53
54 enum ldo_reg {
55         LDO_ARM,
56         LDO_SOC,
57         LDO_PU,
58 };
59
60 struct scu_regs {
61         u32     ctrl;
62         u32     config;
63         u32     status;
64         u32     invalidate;
65         u32     fpga_rev;
66 };
67
68 #if defined(CONFIG_IMX6_THERMAL)
69 static const struct imx_thermal_plat imx6_thermal_plat = {
70         .regs = (void *)ANATOP_BASE_ADDR,
71         .fuse_bank = 1,
72         .fuse_word = 6,
73 };
74
75 U_BOOT_DEVICE(imx6_thermal) = {
76         .name = "imx_thermal",
77         .platdata = &imx6_thermal_plat,
78 };
79 #endif
80
81 u32 get_nr_cpus(void)
82 {
83         struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
84         return readl(&scu->config) & 3;
85 }
86
87 u32 get_cpu_rev(void)
88 {
89         struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
90         u32 reg = readl(&anatop->digprog_sololite);
91         u32 type = ((reg >> 16) & 0xff);
92         u32 major, cfg = 0;
93
94         if (type != MXC_CPU_MX6SL) {
95                 reg = readl(&anatop->digprog);
96                 struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
97                 cfg = readl(&scu->config) & 3;
98                 type = ((reg >> 16) & 0xff);
99                 if (type == MXC_CPU_MX6DL) {
100                         if (!cfg)
101                                 type = MXC_CPU_MX6SOLO;
102                 }
103
104                 if (type == MXC_CPU_MX6Q) {
105                         if (cfg == 1)
106                                 type = MXC_CPU_MX6D;
107                 }
108
109         }
110         major = ((reg >> 8) & 0xff);
111         if ((major >= 1) &&
112             ((type == MXC_CPU_MX6Q) || (type == MXC_CPU_MX6D))) {
113                 major--;
114                 type = MXC_CPU_MX6QP;
115                 if (cfg == 1)
116                         type = MXC_CPU_MX6DP;
117         }
118         reg &= 0xff;            /* mx6 silicon revision */
119         if (type == MXC_CPU_MX6Q) {
120                 switch (reg) {
121                 case 0x02:
122                         break;
123                 case 0x05:
124                         reg = 0x03;
125                         break;
126                 case 0x06:
127                         reg = 0x06;
128                         break;
129                 default:
130                         printf("Unknown CPU Rev.: 0x%02x\n", reg);
131                 }
132         }
133         return (type << 12) | (reg + (0x10 * (major + 1)));
134 }
135
136 /*
137  * OCOTP_CFG3[17:16] (see Fusemap Description Table offset 0x440)
138  * defines a 2-bit SPEED_GRADING
139  */
140 #define OCOTP_CFG3_SPEED_SHIFT  16
141 #define OCOTP_CFG3_SPEED_800MHZ 0
142 #define OCOTP_CFG3_SPEED_850MHZ 1
143 #define OCOTP_CFG3_SPEED_1GHZ   2
144 #define OCOTP_CFG3_SPEED_1P2GHZ 3
145
146 u32 get_cpu_speed_grade_hz(void)
147 {
148         uint32_t val;
149
150         if (fuse_read(0, 3, &val)) {
151                 printf("Failed to read speed_grade fuse\n");
152                 return 0;
153         }
154         val >>= OCOTP_CFG3_SPEED_SHIFT;
155         val &= 0x3;
156
157         switch (val) {
158         /* Valid for IMX6DQ */
159         case OCOTP_CFG3_SPEED_1P2GHZ:
160                 if (is_cpu_type(MXC_CPU_MX6Q) || is_cpu_type(MXC_CPU_MX6D))
161                         return 1200000000;
162         /* Valid for IMX6SX/IMX6SDL/IMX6DQ */
163         case OCOTP_CFG3_SPEED_1GHZ:
164                 return 996000000;
165         /* Valid for IMX6DQ */
166         case OCOTP_CFG3_SPEED_850MHZ:
167                 if (is_cpu_type(MXC_CPU_MX6Q) || is_cpu_type(MXC_CPU_MX6D))
168                         return 852000000;
169         /* Valid for IMX6SX/IMX6SDL/IMX6DQ/IMX6ULL */
170         case OCOTP_CFG3_SPEED_800MHZ:
171                 return 792000000;
172         }
173         return 0;
174 }
175
176 /*
177  * OCOTP_MEM0[7:6] (see Fusemap Description Table offset 0x480)
178  * defines a 2-bit Temperature Grade
179  *
180  * return temperature grade and min/max temperature in celcius
181  */
182 #define OCOTP_MEM0_TEMP_SHIFT          6
183
184 u32 get_cpu_temp_grade(int *minc, int *maxc)
185 {
186         uint32_t val;
187
188         if (fuse_read(1, 0, &val)) {
189                 printf("Failed to read temp_grade fuse\n");
190                 val = 0;
191         }
192         val >>= OCOTP_MEM0_TEMP_SHIFT;
193         val &= 0x3;
194
195         if (minc && maxc) {
196                 if (val == TEMP_AUTOMOTIVE) {
197                         *minc = -40;
198                         *maxc = 125;
199                 } else if (val == TEMP_INDUSTRIAL) {
200                         *minc = -40;
201                         *maxc = 105;
202                 } else if (val == TEMP_EXTCOMMERCIAL) {
203                         *minc = -20;
204                         *maxc = 105;
205                 } else {
206                         *minc = 0;
207                         *maxc = 95;
208                 }
209         }
210         return val;
211 }
212
213 #ifdef CONFIG_REVISION_TAG
214 u32 __weak get_board_rev(void)
215 {
216         u32 cpurev = get_cpu_rev();
217         u32 type = ((cpurev >> 12) & 0xff);
218         if (type == MXC_CPU_MX6SOLO)
219                 cpurev = (MXC_CPU_MX6DL) << 12 | (cpurev & 0xFFF);
220
221         if (type == MXC_CPU_MX6D)
222                 cpurev = (MXC_CPU_MX6Q) << 12 | (cpurev & 0xFFF);
223
224         return cpurev;
225 }
226 #endif
227
228 void init_aips(void)
229 {
230         struct aipstz_regs *aips1, *aips2;
231 #ifdef AIPS3_CONFIG_BASE_ADDR
232         struct aipstz_regs *aips3;
233 #endif
234         aips1 = (struct aipstz_regs *)AIPS1_BASE_ADDR;
235         aips2 = (struct aipstz_regs *)AIPS2_BASE_ADDR;
236 #ifdef AIPS3_CONFIG_BASE_ADDR
237         aips3 = (struct aipstz_regs *)AIPS3_CONFIG_BASE_ADDR;
238 #endif
239
240         /*
241          * Set all MPROTx to be non-bufferable, trusted for R/W,
242          * not forced to user-mode.
243          */
244         writel(0x77777777, &aips1->mprot0);
245         writel(0x77777777, &aips1->mprot1);
246         writel(0x77777777, &aips2->mprot0);
247         writel(0x77777777, &aips2->mprot1);
248
249         /*
250          * Set all OPACRx to be non-bufferable, not require
251          * supervisor privilege level for access,allow for
252          * write access and untrusted master access.
253          */
254         writel(0x00000000, &aips1->opacr0);
255         writel(0x00000000, &aips1->opacr1);
256         writel(0x00000000, &aips1->opacr2);
257         writel(0x00000000, &aips1->opacr3);
258         writel(0x00000000, &aips1->opacr4);
259         writel(0x00000000, &aips2->opacr0);
260         writel(0x00000000, &aips2->opacr1);
261         writel(0x00000000, &aips2->opacr2);
262         writel(0x00000000, &aips2->opacr3);
263         writel(0x00000000, &aips2->opacr4);
264
265 #ifdef AIPS3_CONFIG_BASE_ADDR
266         /*
267          * Set all MPROTx to be non-bufferable, trusted for R/W,
268          * not forced to user-mode.
269          */
270         writel(0x77777777, &aips3->mprot0);
271         writel(0x77777777, &aips3->mprot1);
272
273         /*
274          * Set all OPACRx to be non-bufferable, not require
275          * supervisor privilege level for access,allow for
276          * write access and untrusted master access.
277          */
278         writel(0x00000000, &aips3->opacr0);
279         writel(0x00000000, &aips3->opacr1);
280         writel(0x00000000, &aips3->opacr2);
281         writel(0x00000000, &aips3->opacr3);
282         writel(0x00000000, &aips3->opacr4);
283 #endif
284 }
285
286 static void clear_ldo_ramp(void)
287 {
288         struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
289         int reg;
290
291         /* ROM may modify LDO ramp up time according to fuse setting, so in
292          * order to be in the safe side we neeed to reset these settings to
293          * match the reset value: 0'b00
294          */
295         reg = readl(&anatop->ana_misc2);
296         reg &= ~(0x3f << 24);
297         writel(reg, &anatop->ana_misc2);
298 }
299
300 /*
301  * Set the PMU_REG_CORE register
302  *
303  * Set LDO_SOC/PU/ARM regulators to the specified millivolt level.
304  * Possible values are from 0.725V to 1.450V in steps of
305  * 0.025V (25mV).
306  */
307 static int set_ldo_voltage(enum ldo_reg ldo, u32 mv)
308 {
309         struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
310         u32 val, step, old, reg = readl(&anatop->reg_core);
311         u8 shift;
312
313         if (mv < 725)
314                 val = 0x00;     /* Power gated off */
315         else if (mv > 1450)
316                 val = 0x1F;     /* Power FET switched full on. No regulation */
317         else
318                 val = (mv - 700) / 25;
319
320         clear_ldo_ramp();
321
322         switch (ldo) {
323         case LDO_SOC:
324                 shift = 18;
325                 break;
326         case LDO_PU:
327                 shift = 9;
328                 break;
329         case LDO_ARM:
330                 shift = 0;
331                 break;
332         default:
333                 return -EINVAL;
334         }
335
336         old = (reg & (0x1F << shift)) >> shift;
337         step = abs(val - old);
338         if (step == 0)
339                 return 0;
340
341         reg = (reg & ~(0x1F << shift)) | (val << shift);
342         writel(reg, &anatop->reg_core);
343
344         /*
345          * The LDO ramp-up is based on 64 clock cycles of 24 MHz = 2.6 us per
346          * step
347          */
348         udelay(3 * step);
349
350         return 0;
351 }
352
353 int check_cpu_temperature(int boot)
354 {
355         int ret;
356         static int __data max_temp;
357         int boot_limit = getenv_ulong("max_boot_temp", 10, TEMPERATURE_HOT);
358         int tmp;
359         struct udevice *dev;
360         bool first = true;
361
362         if (uclass_get_device_by_name(UCLASS_THERMAL, "imx_thermal", &dev)) {
363                 if (first) {
364                         printf("No thermal device found; cannot read CPU temperature\n");
365                         first = false;
366                 }
367                 return 0;
368         }
369
370         ret = thermal_get_temp(dev, &tmp);
371         if (ret) {
372                 printf("Failed to read temperature: %d\n", ret);
373                 return TEMPERATURE_MAX;
374         }
375         if (tmp < TEMPERATURE_MIN || tmp > TEMPERATURE_MAX) {
376                 printf("Temperature:   can't get valid data!\n");
377                 return tmp;
378         }
379
380         if (!boot) {
381                 if (tmp > boot_limit) {
382                         printf("CPU is %d C; too hot, resetting...\n", tmp);
383                         udelay(100000);
384                         reset_cpu(0);
385                 }
386                 if (tmp > max_temp) {
387                         if (tmp > boot_limit - TEMP_WARN_THRESHOLD)
388                                 printf("WARNING: CPU temperature %d C\n", tmp);
389                         max_temp = tmp;
390                 }
391         } else {
392                 while (tmp >= boot_limit) {
393                         if (first) {
394                                 printf("CPU is %d C; too hot to boot, waiting...\n",
395                                         tmp);
396                                 first = false;
397                         }
398                         if (ctrlc())
399                                 break;
400                         udelay(50000);
401                         ret = thermal_get_temp(dev, &tmp);
402                         if (ret < 0) {
403                                 printf("Failed to read temperature: %d\n", ret);
404                                 return TEMPERATURE_MAX;
405                         }
406                         if (tmp > boot_limit - TEMP_WARN_THRESHOLD && tmp != max_temp)
407                                 printf("WARNING: CPU temperature %d C\n", tmp);
408                         max_temp = tmp;
409                 }
410         }
411         return tmp;
412 }
413
414 static void imx_set_wdog_powerdown(bool enable)
415 {
416         struct wdog_regs *wdog1 = (struct wdog_regs *)WDOG1_BASE_ADDR;
417         struct wdog_regs *wdog2 = (struct wdog_regs *)WDOG2_BASE_ADDR;
418         struct wdog_regs *wdog3 = (struct wdog_regs *)WDOG3_BASE_ADDR;
419
420         if (is_cpu_type(MXC_CPU_MX6SX) || is_cpu_type(MXC_CPU_MX6UL) ||
421             is_cpu_type(MXC_CPU_MX6ULL))
422                 writew(enable, &wdog3->wmcr);
423
424         /* Write to the PDE (Power Down Enable) bit */
425         writew(enable, &wdog1->wmcr);
426         writew(enable, &wdog2->wmcr);
427 }
428
429 static void set_ahb_rate(u32 val)
430 {
431         struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
432         u32 reg, div;
433
434         div = get_periph_clk() / val - 1;
435         reg = readl(&mxc_ccm->cbcdr);
436
437         writel((reg & (~MXC_CCM_CBCDR_AHB_PODF_MASK)) |
438                 (div << MXC_CCM_CBCDR_AHB_PODF_OFFSET), &mxc_ccm->cbcdr);
439 }
440
441 static void clear_mmdc_ch_mask(void)
442 {
443         struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
444         u32 reg;
445         reg = readl(&mxc_ccm->ccdr);
446
447         /* Clear MMDC channel mask */
448         reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK | MXC_CCM_CCDR_MMDC_CH0_HS_MASK);
449         writel(reg, &mxc_ccm->ccdr);
450 }
451
452 static void init_bandgap(void)
453 {
454         struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
455         /*
456          * Ensure the bandgap has stabilized.
457          */
458         while (!(readl(&anatop->ana_misc0) & 0x80))
459                 ;
460         /*
461          * For best noise performance of the analog blocks using the
462          * outputs of the bandgap, the reftop_selfbiasoff bit should
463          * be set.
464          */
465         writel(BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF, &anatop->ana_misc0_set);
466 }
467
468 #ifdef CONFIG_SOC_MX6SL
469 static void set_preclk_from_osc(void)
470 {
471         struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
472         u32 reg;
473
474         reg = readl(&mxc_ccm->cscmr1);
475         reg |= MXC_CCM_CSCMR1_PER_CLK_SEL_MASK;
476         writel(reg, &mxc_ccm->cscmr1);
477 }
478 #endif
479
480 #define SRC_SCR_WARM_RESET_ENABLE       0
481
482 static void init_src(void)
483 {
484         struct src *src_regs = (struct src *)SRC_BASE_ADDR;
485         u32 val;
486
487         /*
488          * force warm reset sources to generate cold reset
489          * for a more reliable restart
490          */
491         val = readl(&src_regs->scr);
492         val &= ~(1 << SRC_SCR_WARM_RESET_ENABLE);
493         writel(val, &src_regs->scr);
494 }
495
496 int arch_cpu_init(void)
497 {
498         init_aips();
499
500         /* Need to clear MMDC_CHx_MASK to make warm reset work. */
501         clear_mmdc_ch_mask();
502
503         /*
504          * Disable self-bias circuit in the analog bandap.
505          * The self-bias circuit is used by the bandgap during startup.
506          * This bit should be set after the bandgap has initialized.
507          */
508         init_bandgap();
509
510         /*
511          * When low freq boot is enabled, ROM will not set AHB
512          * freq, so we need to ensure AHB freq is 132MHz in such
513          * scenario.
514          */
515         if (mxc_get_clock(MXC_ARM_CLK) == 396000000)
516                 set_ahb_rate(132000000);
517
518                 /* Set perclk to source from OSC 24MHz */
519 #if defined(CONFIG_SOC_MX6SL)
520         set_preclk_from_osc();
521 #endif
522
523         imx_set_wdog_powerdown(false); /* Disable PDE bit of WMCR register */
524
525 #ifdef CONFIG_VIDEO_IPUV3
526         gd->arch.ipu_hw_rev = IPUV3_HW_REV_IPUV3H;
527 #endif
528 #ifdef  CONFIG_APBH_DMA
529         /* Timer is required for Initializing APBH DMA */
530         timer_init();
531         mxs_dma_init();
532 #endif
533
534         init_src();
535
536         return 0;
537 }
538
539 int board_postclk_init(void)
540 {
541         set_ldo_voltage(LDO_SOC, 1175); /* Set VDDSOC to 1.175V */
542
543         return 0;
544 }
545
546 #ifndef CONFIG_SYS_DCACHE_OFF
547 void enable_caches(void)
548 {
549 #if defined(CONFIG_SYS_ARM_CACHE_WRITETHROUGH)
550         enum dcache_option option = DCACHE_WRITETHROUGH;
551 #else
552         enum dcache_option option = DCACHE_WRITEBACK;
553 #endif
554
555         /* Avoid random hang when download by usb */
556         invalidate_dcache_all();
557
558         /* Enable D-cache. I-cache is already enabled in start.S */
559         dcache_enable();
560
561         /* Enable caching on OCRAM and ROM */
562         mmu_set_region_dcache_behaviour(ROMCP_ARB_BASE_ADDR,
563                                         ROMCP_ARB_END_ADDR,
564                                         option);
565         mmu_set_region_dcache_behaviour(IRAM_BASE_ADDR,
566                                         IRAM_SIZE,
567                                         option);
568 }
569 #endif
570
571 #if defined(CONFIG_FEC_MXC)
572 __weak void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
573 {
574         unsigned int mac0, mac1;
575
576         memset(mac, 0, 6);
577         if (dev_id < 0 || dev_id > 2)
578                 return;
579
580         if (fuse_read(4, 2, &mac0)) {
581                 printf("Failed to read MAC0 fuse\n");
582                 return;
583         }
584         if (fuse_read(4, 3, &mac1)) {
585                 printf("Failed to read MAC1 fuse\n");
586                 return;
587         }
588         mac[0] = mac1 >> 8;
589         mac[1] = mac1;
590         mac[2] = mac0 >> 24;
591         mac[3] = mac0 >> 16;
592         if (dev_id == 0) {
593                 mac[4] = mac0 >> 8;
594                 mac[5] = mac0;
595         } else {
596                 mac[4] = mac1 >> 24;
597                 mac[5] = mac1 >> 16;
598         }
599 }
600 #endif
601
602 void boot_mode_apply(unsigned cfg_val)
603 {
604         unsigned reg;
605         struct src *psrc = (struct src *)SRC_BASE_ADDR;
606         writel(cfg_val, &psrc->gpr9);
607         reg = readl(&psrc->gpr10);
608         if (cfg_val)
609                 reg |= 1 << 28;
610         else
611                 reg &= ~(1 << 28);
612         writel(reg, &psrc->gpr10);
613 }
614 /*
615  * cfg_val will be used for
616  * Boot_cfg4[7:0]:Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
617  * After reset, if GPR10[28] is 1, ROM will use GPR9[25:0]
618  * instead of SBMR1 to determine the boot device.
619  */
620 const struct boot_mode soc_boot_modes[] = {
621         {"normal",      MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)},
622         /* reserved value should start rom usb */
623         {"usb",         MAKE_CFGVAL(0x01, 0x00, 0x00, 0x00)},
624         {"sata",        MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
625         {"ecspi1:0",    MAKE_CFGVAL(0x30, 0x00, 0x00, 0x08)},
626         {"ecspi1:1",    MAKE_CFGVAL(0x30, 0x00, 0x00, 0x18)},
627         {"ecspi1:2",    MAKE_CFGVAL(0x30, 0x00, 0x00, 0x28)},
628         {"ecspi1:3",    MAKE_CFGVAL(0x30, 0x00, 0x00, 0x38)},
629         /* 4 bit bus width */
630         {"esdhc1",      MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
631         {"esdhc2",      MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
632         {"esdhc3",      MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
633         {"esdhc4",      MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
634         {NULL,          0},
635 };
636
637 void s_init(void)
638 {
639         struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
640         struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
641         u32 mask480;
642         u32 mask528;
643         u32 reg, periph1, periph2;
644
645         if (is_cpu_type(MXC_CPU_MX6SX) || is_cpu_type(MXC_CPU_MX6UL) ||
646             is_cpu_type(MXC_CPU_MX6ULL))
647                 return;
648
649         /* Due to hardware limitation, on MX6Q we need to gate/ungate all PFDs
650          * to make sure PFD is working right, otherwise, PFDs may
651          * not output clock after reset, MX6DL and MX6SL have added 396M pfd
652          * workaround in ROM code, as bus clock need it
653          */
654
655         mask480 = ANATOP_PFD_CLKGATE_MASK(0) |
656                 ANATOP_PFD_CLKGATE_MASK(1) |
657                 ANATOP_PFD_CLKGATE_MASK(2) |
658                 ANATOP_PFD_CLKGATE_MASK(3);
659         mask528 = ANATOP_PFD_CLKGATE_MASK(1) |
660                 ANATOP_PFD_CLKGATE_MASK(3);
661
662         reg = readl(&ccm->cbcmr);
663         periph2 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_MASK)
664                 >> MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_OFFSET);
665         periph1 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK)
666                 >> MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_OFFSET);
667
668         /* Checking if PLL2 PFD0 or PLL2 PFD2 is using for periph clock */
669         if ((periph2 != 0x2) && (periph1 != 0x2))
670                 mask528 |= ANATOP_PFD_CLKGATE_MASK(0);
671
672         if ((periph2 != 0x1) && (periph1 != 0x1) &&
673                 (periph2 != 0x3) && (periph1 != 0x3))
674                 mask528 |= ANATOP_PFD_CLKGATE_MASK(2);
675
676         writel(mask480, &anatop->pfd_480_set);
677         writel(mask528, &anatop->pfd_528_set);
678         writel(mask480, &anatop->pfd_480_clr);
679         writel(mask528, &anatop->pfd_528_clr);
680 }
681
682 #ifdef CONFIG_IMX_HDMI
683 void imx_enable_hdmi_phy(void)
684 {
685         struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
686         u8 reg;
687         reg = readb(&hdmi->phy_conf0);
688         reg |= HDMI_PHY_CONF0_PDZ_MASK;
689         writeb(reg, &hdmi->phy_conf0);
690         udelay(3000);
691         reg |= HDMI_PHY_CONF0_ENTMDS_MASK;
692         writeb(reg, &hdmi->phy_conf0);
693         udelay(3000);
694         reg |= HDMI_PHY_CONF0_GEN2_TXPWRON_MASK;
695         writeb(reg, &hdmi->phy_conf0);
696         writeb(HDMI_MC_PHYRSTZ_ASSERT, &hdmi->mc_phyrstz);
697 }
698
699 void imx_setup_hdmi(void)
700 {
701         struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
702         struct hdmi_regs *hdmi  = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
703         int reg;
704
705         /* Turn on HDMI PHY clock */
706         reg = readl(&mxc_ccm->CCGR2);
707         reg |=  MXC_CCM_CCGR2_HDMI_TX_IAHBCLK_MASK|
708                  MXC_CCM_CCGR2_HDMI_TX_ISFRCLK_MASK;
709         writel(reg, &mxc_ccm->CCGR2);
710         writeb(HDMI_MC_PHYRSTZ_DEASSERT, &hdmi->mc_phyrstz);
711         reg = readl(&mxc_ccm->chsccdr);
712         reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK|
713                  MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK|
714                  MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK);
715         reg |= (CHSCCDR_PODF_DIVIDE_BY_3
716                  << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET)
717                  |(CHSCCDR_IPU_PRE_CLK_540M_PFD
718                  << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET);
719         writel(reg, &mxc_ccm->chsccdr);
720 }
721 #endif
722
723 #ifndef CONFIG_SYS_L2CACHE_OFF
724 #define IOMUXC_GPR11_L2CACHE_AS_OCRAM 0x00000002
725 void v7_outer_cache_enable(void)
726 {
727         struct pl310_regs *const pl310 = (struct pl310_regs *)L2_PL310_BASE;
728         unsigned int val;
729
730
731         /*
732          * Set bit 22 in the auxiliary control register. If this bit
733          * is cleared, PL310 treats Normal Shared Non-cacheable
734          * accesses as Cacheable no-allocate.
735          */
736         setbits_le32(&pl310->pl310_aux_ctrl, L310_SHARED_ATT_OVERRIDE_ENABLE);
737
738 #if defined CONFIG_SOC_MX6SL
739         struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
740         val = readl(&iomux->gpr[11]);
741         if (val & IOMUXC_GPR11_L2CACHE_AS_OCRAM) {
742                 /* L2 cache configured as OCRAM, reset it */
743                 val &= ~IOMUXC_GPR11_L2CACHE_AS_OCRAM;
744                 writel(val, &iomux->gpr[11]);
745         }
746 #endif
747
748         /* Must disable the L2 before changing the latency parameters */
749         clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
750
751         writel(0x132, &pl310->pl310_tag_latency_ctrl);
752         writel(0x132, &pl310->pl310_data_latency_ctrl);
753
754         val = readl(&pl310->pl310_prefetch_ctrl);
755
756         /* Turn on the L2 I/D prefetch */
757         val |= 0x30000000;
758
759         /*
760          * The L2 cache controller(PL310) version on the i.MX6D/Q is r3p1-50rel0
761          * The L2 cache controller(PL310) version on the i.MX6DL/SOLO/SL is r3p2
762          * But according to ARM PL310 errata: 752271
763          * ID: 752271: Double linefill feature can cause data corruption
764          * Fault Status: Present in: r3p0, r3p1, r3p1-50rel0. Fixed in r3p2
765          * Workaround: The only workaround to this erratum is to disable the
766          * double linefill feature. This is the default behavior.
767          */
768
769 #ifndef CONFIG_SOC_MX6Q
770         val |= 0x40800000;
771 #endif
772         writel(val, &pl310->pl310_prefetch_ctrl);
773
774         val = readl(&pl310->pl310_power_ctrl);
775         val |= L2X0_DYNAMIC_CLK_GATING_EN;
776         val |= L2X0_STNDBY_MODE_EN;
777         writel(val, &pl310->pl310_power_ctrl);
778
779         setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
780 }
781
782 void v7_outer_cache_disable(void)
783 {
784         struct pl310_regs *const pl310 = (struct pl310_regs *)L2_PL310_BASE;
785
786         clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
787 }
788 #endif /* !CONFIG_SYS_L2CACHE_OFF */