]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/armv7/mx6/soc.c
08f2cdbe7fcd6ef31e23556696deaff1d3d5ff4e
[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 */
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 CONFIG_SOC_MX6SX
218         struct aipstz_regs *aips3;
219 #endif
220
221         aips1 = (struct aipstz_regs *)AIPS1_ARB_BASE_ADDR;
222         aips2 = (struct aipstz_regs *)AIPS2_ARB_BASE_ADDR;
223 #ifdef CONFIG_SOC_MX6SX
224         aips3 = (struct aipstz_regs *)AIPS3_ARB_BASE_ADDR;
225 #endif
226
227         /*
228          * Set all MPROTx to be non-bufferable, trusted for R/W,
229          * not forced to user-mode.
230          */
231         writel(0x77777777, &aips1->mprot0);
232         writel(0x77777777, &aips1->mprot1);
233         writel(0x77777777, &aips2->mprot0);
234         writel(0x77777777, &aips2->mprot1);
235
236         /*
237          * Set all OPACRx to be non-bufferable, not require
238          * supervisor privilege level for access,allow for
239          * write access and untrusted master access.
240          */
241         writel(0x00000000, &aips1->opacr0);
242         writel(0x00000000, &aips1->opacr1);
243         writel(0x00000000, &aips1->opacr2);
244         writel(0x00000000, &aips1->opacr3);
245         writel(0x00000000, &aips1->opacr4);
246         writel(0x00000000, &aips2->opacr0);
247         writel(0x00000000, &aips2->opacr1);
248         writel(0x00000000, &aips2->opacr2);
249         writel(0x00000000, &aips2->opacr3);
250         writel(0x00000000, &aips2->opacr4);
251
252 #ifdef CONFIG_SOC_MX6SX
253         /*
254          * Set all MPROTx to be non-bufferable, trusted for R/W,
255          * not forced to user-mode.
256          */
257         writel(0x77777777, &aips3->mprot0);
258         writel(0x77777777, &aips3->mprot1);
259
260         /*
261          * Set all OPACRx to be non-bufferable, not require
262          * supervisor privilege level for access,allow for
263          * write access and untrusted master access.
264          */
265         writel(0x00000000, &aips3->opacr0);
266         writel(0x00000000, &aips3->opacr1);
267         writel(0x00000000, &aips3->opacr2);
268         writel(0x00000000, &aips3->opacr3);
269         writel(0x00000000, &aips3->opacr4);
270 #endif
271 }
272
273 static void clear_ldo_ramp(void)
274 {
275         struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
276         int reg;
277
278         /* ROM may modify LDO ramp up time according to fuse setting, so in
279          * order to be in the safe side we neeed to reset these settings to
280          * match the reset value: 0'b00
281          */
282         reg = readl(&anatop->ana_misc2);
283         reg &= ~(0x3f << 24);
284         writel(reg, &anatop->ana_misc2);
285 }
286
287 /*
288  * Set the PMU_REG_CORE register
289  *
290  * Set LDO_SOC/PU/ARM regulators to the specified millivolt level.
291  * Possible values are from 0.725V to 1.450V in steps of
292  * 0.025V (25mV).
293  */
294 static int set_ldo_voltage(enum ldo_reg ldo, u32 mv)
295 {
296         struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
297         u32 val, step, old, reg = readl(&anatop->reg_core);
298         u8 shift;
299
300         if (mv < 725)
301                 val = 0x00;     /* Power gated off */
302         else if (mv > 1450)
303                 val = 0x1F;     /* Power FET switched full on. No regulation */
304         else
305                 val = (mv - 700) / 25;
306
307         clear_ldo_ramp();
308
309         switch (ldo) {
310         case LDO_SOC:
311                 shift = 18;
312                 break;
313         case LDO_PU:
314                 shift = 9;
315                 break;
316         case LDO_ARM:
317                 shift = 0;
318                 break;
319         default:
320                 return -EINVAL;
321         }
322
323         old = (reg & (0x1F << shift)) >> shift;
324         step = abs(val - old);
325         if (step == 0)
326                 return 0;
327
328         reg = (reg & ~(0x1F << shift)) | (val << shift);
329         writel(reg, &anatop->reg_core);
330
331         /*
332          * The LDO ramp-up is based on 64 clock cycles of 24 MHz = 2.6 us per
333          * step
334          */
335         udelay(3 * step);
336
337         return 0;
338 }
339
340 int check_cpu_temperature(int boot)
341 {
342         int ret;
343         static int __data max_temp;
344         int boot_limit = getenv_ulong("max_boot_temp", 10, TEMPERATURE_HOT);
345         int tmp;
346         struct udevice *dev;
347         bool first = true;
348
349         if (uclass_get_device_by_name(UCLASS_THERMAL, "imx_thermal", &dev)) {
350                 if (first) {
351                         printf("No thermal device found; cannot read CPU temperature\n");
352                         first = false;
353                 }
354                 return 0;
355         }
356
357         ret = thermal_get_temp(dev, &tmp);
358         if (ret) {
359                 printf("Failed to read temperature: %d\n", ret);
360                 return TEMPERATURE_MAX;
361         }
362         if (tmp < TEMPERATURE_MIN || tmp > TEMPERATURE_MAX) {
363                 printf("Temperature:   can't get valid data!\n");
364                 return tmp;
365         }
366
367         if (!boot) {
368                 if (tmp > boot_limit) {
369                         printf("CPU is %d C; too hot, resetting...\n", tmp);
370                         udelay(100000);
371                         reset_cpu(0);
372                 }
373                 if (tmp > max_temp) {
374                         if (tmp > boot_limit - TEMP_WARN_THRESHOLD)
375                                 printf("WARNING: CPU temperature %d C\n", tmp);
376                         max_temp = tmp;
377                 }
378         } else {
379                 while (tmp >= boot_limit) {
380                         if (first) {
381                                 printf("CPU is %d C; too hot to boot, waiting...\n",
382                                         tmp);
383                                 first = false;
384                         }
385                         if (ctrlc())
386                                 break;
387                         udelay(50000);
388                         ret = thermal_get_temp(dev, &tmp);
389                         if (ret < 0) {
390                                 printf("Failed to read temperature: %d\n", ret);
391                                 return TEMPERATURE_MAX;
392                         }
393                         if (tmp > boot_limit - TEMP_WARN_THRESHOLD && tmp != max_temp)
394                                 printf("WARNING: CPU temperature %d C\n", tmp);
395                         max_temp = tmp;
396                 }
397         }
398         return tmp;
399 }
400
401 static void imx_set_wdog_powerdown(bool enable)
402 {
403         struct wdog_regs *wdog1 = (struct wdog_regs *)WDOG1_BASE_ADDR;
404         struct wdog_regs *wdog2 = (struct wdog_regs *)WDOG2_BASE_ADDR;
405         struct wdog_regs *wdog3 = (struct wdog_regs *)WDOG3_BASE_ADDR;
406
407         if (is_cpu_type(MXC_CPU_MX6SX) || is_cpu_type(MXC_CPU_MX6UL))
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 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 #endif
587
588 void boot_mode_apply(unsigned cfg_val)
589 {
590         unsigned reg;
591         struct src *psrc = (struct src *)SRC_BASE_ADDR;
592         writel(cfg_val, &psrc->gpr9);
593         reg = readl(&psrc->gpr10);
594         if (cfg_val)
595                 reg |= 1 << 28;
596         else
597                 reg &= ~(1 << 28);
598         writel(reg, &psrc->gpr10);
599 }
600 /*
601  * cfg_val will be used for
602  * Boot_cfg4[7:0]:Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
603  * After reset, if GPR10[28] is 1, ROM will use GPR9[25:0]
604  * instead of SBMR1 to determine the boot device.
605  */
606 const struct boot_mode soc_boot_modes[] = {
607         {"normal",      MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)},
608         /* reserved value should start rom usb */
609         {"usb",         MAKE_CFGVAL(0x01, 0x00, 0x00, 0x00)},
610         {"sata",        MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
611         {"ecspi1:0",    MAKE_CFGVAL(0x30, 0x00, 0x00, 0x08)},
612         {"ecspi1:1",    MAKE_CFGVAL(0x30, 0x00, 0x00, 0x18)},
613         {"ecspi1:2",    MAKE_CFGVAL(0x30, 0x00, 0x00, 0x28)},
614         {"ecspi1:3",    MAKE_CFGVAL(0x30, 0x00, 0x00, 0x38)},
615         /* 4 bit bus width */
616         {"esdhc1",      MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
617         {"esdhc2",      MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
618         {"esdhc3",      MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
619         {"esdhc4",      MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
620         {NULL,          0},
621 };
622
623 void s_init(void)
624 {
625         struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
626         struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
627         u32 mask480;
628         u32 mask528;
629         u32 reg, periph1, periph2;
630
631         if (is_cpu_type(MXC_CPU_MX6SX) || is_cpu_type(MXC_CPU_MX6UL))
632                 return;
633
634         /* Due to hardware limitation, on MX6Q we need to gate/ungate all PFDs
635          * to make sure PFD is working right, otherwise, PFDs may
636          * not output clock after reset, MX6DL and MX6SL have added 396M pfd
637          * workaround in ROM code, as bus clock need it
638          */
639
640         mask480 = ANATOP_PFD_CLKGATE_MASK(0) |
641                 ANATOP_PFD_CLKGATE_MASK(1) |
642                 ANATOP_PFD_CLKGATE_MASK(2) |
643                 ANATOP_PFD_CLKGATE_MASK(3);
644         mask528 = ANATOP_PFD_CLKGATE_MASK(1) |
645                 ANATOP_PFD_CLKGATE_MASK(3);
646
647         reg = readl(&ccm->cbcmr);
648         periph2 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_MASK)
649                 >> MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_OFFSET);
650         periph1 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK)
651                 >> MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_OFFSET);
652
653         /* Checking if PLL2 PFD0 or PLL2 PFD2 is using for periph clock */
654         if ((periph2 != 0x2) && (periph1 != 0x2))
655                 mask528 |= ANATOP_PFD_CLKGATE_MASK(0);
656
657         if ((periph2 != 0x1) && (periph1 != 0x1) &&
658                 (periph2 != 0x3) && (periph1 != 0x3))
659                 mask528 |= ANATOP_PFD_CLKGATE_MASK(2);
660
661         writel(mask480, &anatop->pfd_480_set);
662         writel(mask528, &anatop->pfd_528_set);
663         writel(mask480, &anatop->pfd_480_clr);
664         writel(mask528, &anatop->pfd_528_clr);
665 }
666
667 #ifdef CONFIG_IMX_HDMI
668 void imx_enable_hdmi_phy(void)
669 {
670         struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
671         u8 reg;
672         reg = readb(&hdmi->phy_conf0);
673         reg |= HDMI_PHY_CONF0_PDZ_MASK;
674         writeb(reg, &hdmi->phy_conf0);
675         udelay(3000);
676         reg |= HDMI_PHY_CONF0_ENTMDS_MASK;
677         writeb(reg, &hdmi->phy_conf0);
678         udelay(3000);
679         reg |= HDMI_PHY_CONF0_GEN2_TXPWRON_MASK;
680         writeb(reg, &hdmi->phy_conf0);
681         writeb(HDMI_MC_PHYRSTZ_ASSERT, &hdmi->mc_phyrstz);
682 }
683
684 void imx_setup_hdmi(void)
685 {
686         struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
687         struct hdmi_regs *hdmi  = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
688         int reg;
689
690         /* Turn on HDMI PHY clock */
691         reg = readl(&mxc_ccm->CCGR2);
692         reg |=  MXC_CCM_CCGR2_HDMI_TX_IAHBCLK_MASK|
693                  MXC_CCM_CCGR2_HDMI_TX_ISFRCLK_MASK;
694         writel(reg, &mxc_ccm->CCGR2);
695         writeb(HDMI_MC_PHYRSTZ_DEASSERT, &hdmi->mc_phyrstz);
696         reg = readl(&mxc_ccm->chsccdr);
697         reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK|
698                  MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK|
699                  MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK);
700         reg |= (CHSCCDR_PODF_DIVIDE_BY_3
701                  << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET)
702                  |(CHSCCDR_IPU_PRE_CLK_540M_PFD
703                  << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET);
704         writel(reg, &mxc_ccm->chsccdr);
705 }
706 #endif
707
708 #ifndef CONFIG_SYS_L2CACHE_OFF
709 #define IOMUXC_GPR11_L2CACHE_AS_OCRAM 0x00000002
710 void v7_outer_cache_enable(void)
711 {
712         struct pl310_regs *const pl310 = (struct pl310_regs *)L2_PL310_BASE;
713         unsigned int val;
714
715
716         /*
717          * Set bit 22 in the auxiliary control register. If this bit
718          * is cleared, PL310 treats Normal Shared Non-cacheable
719          * accesses as Cacheable no-allocate.
720          */
721         setbits_le32(&pl310->pl310_aux_ctrl, L310_SHARED_ATT_OVERRIDE_ENABLE);
722
723 #if defined CONFIG_SOC_MX6SL
724         struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
725         val = readl(&iomux->gpr[11]);
726         if (val & IOMUXC_GPR11_L2CACHE_AS_OCRAM) {
727                 /* L2 cache configured as OCRAM, reset it */
728                 val &= ~IOMUXC_GPR11_L2CACHE_AS_OCRAM;
729                 writel(val, &iomux->gpr[11]);
730         }
731 #endif
732
733         /* Must disable the L2 before changing the latency parameters */
734         clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
735
736         writel(0x132, &pl310->pl310_tag_latency_ctrl);
737         writel(0x132, &pl310->pl310_data_latency_ctrl);
738
739         val = readl(&pl310->pl310_prefetch_ctrl);
740
741         /* Turn on the L2 I/D prefetch */
742         val |= 0x30000000;
743
744         /*
745          * The L2 cache controller(PL310) version on the i.MX6D/Q is r3p1-50rel0
746          * The L2 cache controller(PL310) version on the i.MX6DL/SOLO/SL is r3p2
747          * But according to ARM PL310 errata: 752271
748          * ID: 752271: Double linefill feature can cause data corruption
749          * Fault Status: Present in: r3p0, r3p1, r3p1-50rel0. Fixed in r3p2
750          * Workaround: The only workaround to this erratum is to disable the
751          * double linefill feature. This is the default behavior.
752          */
753
754 #ifndef CONFIG_SOC_MX6Q
755         val |= 0x40800000;
756 #endif
757         writel(val, &pl310->pl310_prefetch_ctrl);
758
759         val = readl(&pl310->pl310_power_ctrl);
760         val |= L2X0_DYNAMIC_CLK_GATING_EN;
761         val |= L2X0_STNDBY_MODE_EN;
762         writel(val, &pl310->pl310_power_ctrl);
763
764         setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
765 }
766
767 void v7_outer_cache_disable(void)
768 {
769         struct pl310_regs *const pl310 = (struct pl310_regs *)L2_PL310_BASE;
770
771         clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
772 }
773 #endif /* !CONFIG_SYS_L2CACHE_OFF */