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