blob: b21bd03a8aac99a50bbdf9b2be6f3b2fda4b9d60 [file] [log] [blame]
Jason Liudec11122011-11-25 00:18:02 +00001/*
2 * (C) Copyright 2007
3 * Sascha Hauer, Pengutronix
4 *
5 * (C) Copyright 2009 Freescale Semiconductor, Inc.
6 *
Wolfgang Denkd79de1d2013-07-08 09:37:19 +02007 * SPDX-License-Identifier: GPL-2.0+
Jason Liudec11122011-11-25 00:18:02 +00008 */
9
10#include <common.h>
Fabio Estevam13409292014-01-29 17:39:49 -020011#include <asm/armv7.h>
Jeroen Hofstee1abf3a12014-10-08 22:57:52 +020012#include <asm/bootm.h>
Fabio Estevam13409292014-01-29 17:39:49 -020013#include <asm/pl310.h>
Jason Liudec11122011-11-25 00:18:02 +000014#include <asm/errno.h>
15#include <asm/io.h>
16#include <asm/arch/imx-regs.h>
17#include <asm/arch/clock.h>
18#include <asm/arch/sys_proto.h>
Troy Kisky0ca618c2012-08-15 10:31:20 +000019#include <asm/imx-common/boot_mode.h>
Stefan Roese8338d1d2013-04-15 21:14:12 +000020#include <asm/imx-common/dma.h>
Fabio Estevam48e65b02013-02-07 06:45:23 +000021#include <stdbool.h>
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -050022#include <asm/arch/mxc_hdmi.h>
23#include <asm/arch/crm_regs.h>
Ye.Lif19692c2014-11-20 21:14:14 +080024#include <dm.h>
25#include <imx_thermal.h>
Jason Liudec11122011-11-25 00:18:02 +000026
Fabio Estevama47ec522013-12-26 14:51:33 -020027enum ldo_reg {
28 LDO_ARM,
29 LDO_SOC,
30 LDO_PU,
31};
32
Troy Kisky58394932012-10-23 10:57:46 +000033struct scu_regs {
34 u32 ctrl;
35 u32 config;
36 u32 status;
37 u32 invalidate;
38 u32 fpga_rev;
39};
40
Ye.Lif19692c2014-11-20 21:14:14 +080041#if defined(CONFIG_IMX6_THERMAL)
42static const struct imx_thermal_plat imx6_thermal_plat = {
43 .regs = (void *)ANATOP_BASE_ADDR,
44 .fuse_bank = 1,
45 .fuse_word = 6,
46};
47
48U_BOOT_DEVICE(imx6_thermal) = {
49 .name = "imx_thermal",
50 .platdata = &imx6_thermal_plat,
51};
52#endif
53
Gabriel Huau170ceaf2014-07-26 11:35:43 -070054u32 get_nr_cpus(void)
55{
56 struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
57 return readl(&scu->config) & 3;
58}
59
Jason Liudec11122011-11-25 00:18:02 +000060u32 get_cpu_rev(void)
61{
Fabio Estevam46e97332012-03-20 04:21:45 +000062 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Troy Kisky58394932012-10-23 10:57:46 +000063 u32 reg = readl(&anatop->digprog_sololite);
64 u32 type = ((reg >> 16) & 0xff);
Fabio Estevam46e97332012-03-20 04:21:45 +000065
Troy Kisky58394932012-10-23 10:57:46 +000066 if (type != MXC_CPU_MX6SL) {
67 reg = readl(&anatop->digprog);
Fabio Estevamf3d5a2c2014-01-26 15:06:41 -020068 struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
69 u32 cfg = readl(&scu->config) & 3;
Troy Kisky58394932012-10-23 10:57:46 +000070 type = ((reg >> 16) & 0xff);
71 if (type == MXC_CPU_MX6DL) {
Troy Kisky58394932012-10-23 10:57:46 +000072 if (!cfg)
73 type = MXC_CPU_MX6SOLO;
74 }
Fabio Estevamf3d5a2c2014-01-26 15:06:41 -020075
76 if (type == MXC_CPU_MX6Q) {
77 if (cfg == 1)
78 type = MXC_CPU_MX6D;
79 }
80
Troy Kisky58394932012-10-23 10:57:46 +000081 }
82 reg &= 0xff; /* mx6 silicon revision */
83 return (type << 12) | (reg + 0x10);
Jason Liudec11122011-11-25 00:18:02 +000084}
85
Tim Harvey258d0462015-05-18 07:02:24 -070086/*
87 * OCOTP_CFG3[17:16] (see Fusemap Description Table offset 0x440)
88 * defines a 2-bit SPEED_GRADING
89 */
90#define OCOTP_CFG3_SPEED_SHIFT 16
91#define OCOTP_CFG3_SPEED_800MHZ 0
92#define OCOTP_CFG3_SPEED_850MHZ 1
93#define OCOTP_CFG3_SPEED_1GHZ 2
94#define OCOTP_CFG3_SPEED_1P2GHZ 3
95
96u32 get_cpu_speed_grade_hz(void)
97{
98 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
99 struct fuse_bank *bank = &ocotp->bank[0];
100 struct fuse_bank0_regs *fuse =
101 (struct fuse_bank0_regs *)bank->fuse_regs;
102 uint32_t val;
103
104 val = readl(&fuse->cfg3);
105 val >>= OCOTP_CFG3_SPEED_SHIFT;
106 val &= 0x3;
107
108 switch (val) {
109 /* Valid for IMX6DQ */
110 case OCOTP_CFG3_SPEED_1P2GHZ:
111 if (is_cpu_type(MXC_CPU_MX6Q) || is_cpu_type(MXC_CPU_MX6D))
112 return 1200000000;
113 /* Valid for IMX6SX/IMX6SDL/IMX6DQ */
114 case OCOTP_CFG3_SPEED_1GHZ:
115 return 996000000;
116 /* Valid for IMX6DQ */
117 case OCOTP_CFG3_SPEED_850MHZ:
118 if (is_cpu_type(MXC_CPU_MX6Q) || is_cpu_type(MXC_CPU_MX6D))
119 return 852000000;
120 /* Valid for IMX6SX/IMX6SDL/IMX6DQ */
121 case OCOTP_CFG3_SPEED_800MHZ:
122 return 792000000;
123 }
124 return 0;
125}
126
Tim Harvey5e0e1932015-05-18 06:56:45 -0700127/*
128 * OCOTP_MEM0[7:6] (see Fusemap Description Table offset 0x480)
129 * defines a 2-bit Temperature Grade
130 *
131 * return temperature grade and min/max temperature in celcius
132 */
133#define OCOTP_MEM0_TEMP_SHIFT 6
134
135u32 get_cpu_temp_grade(int *minc, int *maxc)
136{
137 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
138 struct fuse_bank *bank = &ocotp->bank[1];
139 struct fuse_bank1_regs *fuse =
140 (struct fuse_bank1_regs *)bank->fuse_regs;
141 uint32_t val;
142
143 val = readl(&fuse->mem0);
144 val >>= OCOTP_MEM0_TEMP_SHIFT;
145 val &= 0x3;
146
147 if (minc && maxc) {
148 if (val == TEMP_AUTOMOTIVE) {
149 *minc = -40;
150 *maxc = 125;
151 } else if (val == TEMP_INDUSTRIAL) {
152 *minc = -40;
153 *maxc = 105;
154 } else if (val == TEMP_EXTCOMMERCIAL) {
155 *minc = -20;
156 *maxc = 105;
157 } else {
158 *minc = 0;
159 *maxc = 95;
160 }
161 }
162 return val;
163}
164
Fabio Estevam435998b2013-03-27 07:36:55 +0000165#ifdef CONFIG_REVISION_TAG
166u32 __weak get_board_rev(void)
167{
168 u32 cpurev = get_cpu_rev();
169 u32 type = ((cpurev >> 12) & 0xff);
170 if (type == MXC_CPU_MX6SOLO)
171 cpurev = (MXC_CPU_MX6DL) << 12 | (cpurev & 0xFFF);
172
Fabio Estevamf3d5a2c2014-01-26 15:06:41 -0200173 if (type == MXC_CPU_MX6D)
174 cpurev = (MXC_CPU_MX6Q) << 12 | (cpurev & 0xFFF);
175
Fabio Estevam435998b2013-03-27 07:36:55 +0000176 return cpurev;
177}
178#endif
179
Jason Liudec11122011-11-25 00:18:02 +0000180void init_aips(void)
181{
Jason Liubb25e072012-01-10 00:52:59 +0000182 struct aipstz_regs *aips1, *aips2;
Fabio Estevam712ab882014-06-24 17:40:58 -0300183#ifdef CONFIG_MX6SX
184 struct aipstz_regs *aips3;
185#endif
Jason Liubb25e072012-01-10 00:52:59 +0000186
187 aips1 = (struct aipstz_regs *)AIPS1_BASE_ADDR;
188 aips2 = (struct aipstz_regs *)AIPS2_BASE_ADDR;
Fabio Estevam712ab882014-06-24 17:40:58 -0300189#ifdef CONFIG_MX6SX
Ye.Li00cce362015-01-14 17:18:12 +0800190 aips3 = (struct aipstz_regs *)AIPS3_CONFIG_BASE_ADDR;
Fabio Estevam712ab882014-06-24 17:40:58 -0300191#endif
Jason Liudec11122011-11-25 00:18:02 +0000192
193 /*
194 * Set all MPROTx to be non-bufferable, trusted for R/W,
195 * not forced to user-mode.
196 */
Jason Liubb25e072012-01-10 00:52:59 +0000197 writel(0x77777777, &aips1->mprot0);
198 writel(0x77777777, &aips1->mprot1);
199 writel(0x77777777, &aips2->mprot0);
200 writel(0x77777777, &aips2->mprot1);
Jason Liudec11122011-11-25 00:18:02 +0000201
Jason Liubb25e072012-01-10 00:52:59 +0000202 /*
203 * Set all OPACRx to be non-bufferable, not require
204 * supervisor privilege level for access,allow for
205 * write access and untrusted master access.
206 */
207 writel(0x00000000, &aips1->opacr0);
208 writel(0x00000000, &aips1->opacr1);
209 writel(0x00000000, &aips1->opacr2);
210 writel(0x00000000, &aips1->opacr3);
211 writel(0x00000000, &aips1->opacr4);
212 writel(0x00000000, &aips2->opacr0);
213 writel(0x00000000, &aips2->opacr1);
214 writel(0x00000000, &aips2->opacr2);
215 writel(0x00000000, &aips2->opacr3);
216 writel(0x00000000, &aips2->opacr4);
Fabio Estevam712ab882014-06-24 17:40:58 -0300217
218#ifdef CONFIG_MX6SX
219 /*
220 * Set all MPROTx to be non-bufferable, trusted for R/W,
221 * not forced to user-mode.
222 */
223 writel(0x77777777, &aips3->mprot0);
224 writel(0x77777777, &aips3->mprot1);
225
226 /*
227 * Set all OPACRx to be non-bufferable, not require
228 * supervisor privilege level for access,allow for
229 * write access and untrusted master access.
230 */
231 writel(0x00000000, &aips3->opacr0);
232 writel(0x00000000, &aips3->opacr1);
233 writel(0x00000000, &aips3->opacr2);
234 writel(0x00000000, &aips3->opacr3);
235 writel(0x00000000, &aips3->opacr4);
236#endif
Jason Liudec11122011-11-25 00:18:02 +0000237}
238
Fabio Estevamcf621ff2013-12-26 14:51:31 -0200239static void clear_ldo_ramp(void)
240{
241 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
242 int reg;
243
244 /* ROM may modify LDO ramp up time according to fuse setting, so in
245 * order to be in the safe side we neeed to reset these settings to
246 * match the reset value: 0'b00
247 */
248 reg = readl(&anatop->ana_misc2);
249 reg &= ~(0x3f << 24);
250 writel(reg, &anatop->ana_misc2);
251}
252
Dirk Behme8c465942012-05-02 02:12:17 +0000253/*
Fabio Estevam2e95fe12014-06-13 01:42:37 -0300254 * Set the PMU_REG_CORE register
Dirk Behme8c465942012-05-02 02:12:17 +0000255 *
Fabio Estevam2e95fe12014-06-13 01:42:37 -0300256 * Set LDO_SOC/PU/ARM regulators to the specified millivolt level.
Dirk Behme8c465942012-05-02 02:12:17 +0000257 * Possible values are from 0.725V to 1.450V in steps of
258 * 0.025V (25mV).
259 */
Fabio Estevama47ec522013-12-26 14:51:33 -0200260static int set_ldo_voltage(enum ldo_reg ldo, u32 mv)
Dirk Behme8c465942012-05-02 02:12:17 +0000261{
262 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Fabio Estevam99b370b2013-12-26 14:51:34 -0200263 u32 val, step, old, reg = readl(&anatop->reg_core);
Fabio Estevama47ec522013-12-26 14:51:33 -0200264 u8 shift;
Dirk Behme8c465942012-05-02 02:12:17 +0000265
266 if (mv < 725)
267 val = 0x00; /* Power gated off */
268 else if (mv > 1450)
269 val = 0x1F; /* Power FET switched full on. No regulation */
270 else
271 val = (mv - 700) / 25;
272
Fabio Estevamcf621ff2013-12-26 14:51:31 -0200273 clear_ldo_ramp();
274
Fabio Estevama47ec522013-12-26 14:51:33 -0200275 switch (ldo) {
276 case LDO_SOC:
277 shift = 18;
278 break;
279 case LDO_PU:
280 shift = 9;
281 break;
282 case LDO_ARM:
283 shift = 0;
284 break;
285 default:
286 return -EINVAL;
287 }
288
Fabio Estevam99b370b2013-12-26 14:51:34 -0200289 old = (reg & (0x1F << shift)) >> shift;
290 step = abs(val - old);
291 if (step == 0)
292 return 0;
293
Fabio Estevama47ec522013-12-26 14:51:33 -0200294 reg = (reg & ~(0x1F << shift)) | (val << shift);
Dirk Behme8c465942012-05-02 02:12:17 +0000295 writel(reg, &anatop->reg_core);
Fabio Estevama47ec522013-12-26 14:51:33 -0200296
Fabio Estevam99b370b2013-12-26 14:51:34 -0200297 /*
298 * The LDO ramp-up is based on 64 clock cycles of 24 MHz = 2.6 us per
299 * step
300 */
301 udelay(3 * step);
302
Fabio Estevama47ec522013-12-26 14:51:33 -0200303 return 0;
Dirk Behme8c465942012-05-02 02:12:17 +0000304}
305
Fabio Estevam48e65b02013-02-07 06:45:23 +0000306static void imx_set_wdog_powerdown(bool enable)
307{
308 struct wdog_regs *wdog1 = (struct wdog_regs *)WDOG1_BASE_ADDR;
309 struct wdog_regs *wdog2 = (struct wdog_regs *)WDOG2_BASE_ADDR;
310
Peng Fancc844dc2015-01-15 14:22:33 +0800311#ifdef CONFIG_MX6SX
312 struct wdog_regs *wdog3 = (struct wdog_regs *)WDOG3_BASE_ADDR;
313 writew(enable, &wdog3->wmcr);
314#endif
315
Fabio Estevam48e65b02013-02-07 06:45:23 +0000316 /* Write to the PDE (Power Down Enable) bit */
317 writew(enable, &wdog1->wmcr);
318 writew(enable, &wdog2->wmcr);
319}
320
Anson Huang05a464f2014-01-23 14:00:18 +0800321static void set_ahb_rate(u32 val)
322{
323 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
324 u32 reg, div;
325
326 div = get_periph_clk() / val - 1;
327 reg = readl(&mxc_ccm->cbcdr);
328
329 writel((reg & (~MXC_CCM_CBCDR_AHB_PODF_MASK)) |
330 (div << MXC_CCM_CBCDR_AHB_PODF_OFFSET), &mxc_ccm->cbcdr);
331}
332
Anson Huang9a149bc2014-01-23 14:00:19 +0800333static void clear_mmdc_ch_mask(void)
334{
335 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
336
337 /* Clear MMDC channel mask */
338 writel(0, &mxc_ccm->ccdr);
339}
340
Peng Fanc0e0ebf2015-01-15 14:22:32 +0800341static void init_bandgap(void)
342{
343 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
344 /*
345 * Ensure the bandgap has stabilized.
346 */
347 while (!(readl(&anatop->ana_misc0) & 0x80))
348 ;
349 /*
350 * For best noise performance of the analog blocks using the
351 * outputs of the bandgap, the reftop_selfbiasoff bit should
352 * be set.
353 */
354 writel(BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF, &anatop->ana_misc0_set);
355}
356
357
Ye.Li622dfbd2014-10-30 18:20:58 +0800358#ifdef CONFIG_MX6SL
359static void set_preclk_from_osc(void)
360{
361 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
362 u32 reg;
363
364 reg = readl(&mxc_ccm->cscmr1);
365 reg |= MXC_CCM_CSCMR1_PER_CLK_SEL_MASK;
366 writel(reg, &mxc_ccm->cscmr1);
367}
368#endif
369
Dirk Behme0adb2152015-03-09 14:48:48 +0100370#define SRC_SCR_WARM_RESET_ENABLE 0
371
372static void init_src(void)
373{
374 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
375 u32 val;
376
377 /*
378 * force warm reset sources to generate cold reset
379 * for a more reliable restart
380 */
381 val = readl(&src_regs->scr);
382 val &= ~(1 << SRC_SCR_WARM_RESET_ENABLE);
383 writel(val, &src_regs->scr);
384}
385
Jason Liudec11122011-11-25 00:18:02 +0000386int arch_cpu_init(void)
387{
388 init_aips();
389
Anson Huang9a149bc2014-01-23 14:00:19 +0800390 /* Need to clear MMDC_CHx_MASK to make warm reset work. */
391 clear_mmdc_ch_mask();
392
Anson Huang05a464f2014-01-23 14:00:18 +0800393 /*
Peng Fanc0e0ebf2015-01-15 14:22:32 +0800394 * Disable self-bias circuit in the analog bandap.
395 * The self-bias circuit is used by the bandgap during startup.
396 * This bit should be set after the bandgap has initialized.
397 */
398 init_bandgap();
399
400 /*
Anson Huang05a464f2014-01-23 14:00:18 +0800401 * When low freq boot is enabled, ROM will not set AHB
402 * freq, so we need to ensure AHB freq is 132MHz in such
403 * scenario.
404 */
405 if (mxc_get_clock(MXC_ARM_CLK) == 396000000)
406 set_ahb_rate(132000000);
407
Ye.Li622dfbd2014-10-30 18:20:58 +0800408 /* Set perclk to source from OSC 24MHz */
409#if defined(CONFIG_MX6SL)
410 set_preclk_from_osc();
411#endif
412
Fabio Estevam48e65b02013-02-07 06:45:23 +0000413 imx_set_wdog_powerdown(false); /* Disable PDE bit of WMCR register */
Stefan Roese8338d1d2013-04-15 21:14:12 +0000414
415#ifdef CONFIG_APBH_DMA
416 /* Start APBH DMA */
417 mxs_dma_init();
418#endif
419
Dirk Behme0adb2152015-03-09 14:48:48 +0100420 init_src();
421
Jason Liudec11122011-11-25 00:18:02 +0000422 return 0;
423}
Jason Liudec11122011-11-25 00:18:02 +0000424
Fabio Estevam99b370b2013-12-26 14:51:34 -0200425int board_postclk_init(void)
426{
427 set_ldo_voltage(LDO_SOC, 1175); /* Set VDDSOC to 1.175V */
428
429 return 0;
430}
431
Eric Nelsonc94ce4a2012-03-04 11:47:38 +0000432#ifndef CONFIG_SYS_DCACHE_OFF
433void enable_caches(void)
434{
Nitin Gargb1ce7012014-09-16 13:33:25 -0500435#if defined(CONFIG_SYS_ARM_CACHE_WRITETHROUGH)
436 enum dcache_option option = DCACHE_WRITETHROUGH;
437#else
438 enum dcache_option option = DCACHE_WRITEBACK;
439#endif
440
Frank Li40c41002013-11-14 00:58:46 +0800441 /* Avoid random hang when download by usb */
442 invalidate_dcache_all();
Nitin Gargb1ce7012014-09-16 13:33:25 -0500443
Eric Nelsonc94ce4a2012-03-04 11:47:38 +0000444 /* Enable D-cache. I-cache is already enabled in start.S */
445 dcache_enable();
Nitin Gargb1ce7012014-09-16 13:33:25 -0500446
447 /* Enable caching on OCRAM and ROM */
448 mmu_set_region_dcache_behaviour(ROMCP_ARB_BASE_ADDR,
449 ROMCP_ARB_END_ADDR,
450 option);
451 mmu_set_region_dcache_behaviour(IRAM_BASE_ADDR,
452 IRAM_SIZE,
453 option);
Eric Nelsonc94ce4a2012-03-04 11:47:38 +0000454}
455#endif
456
Jason Liudec11122011-11-25 00:18:02 +0000457#if defined(CONFIG_FEC_MXC)
Fabio Estevam04fc1282011-12-20 05:46:31 +0000458void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
Jason Liudec11122011-11-25 00:18:02 +0000459{
Benoît Thébaudeaufa7e3952013-04-23 10:17:38 +0000460 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
461 struct fuse_bank *bank = &ocotp->bank[4];
Jason Liudec11122011-11-25 00:18:02 +0000462 struct fuse_bank4_regs *fuse =
463 (struct fuse_bank4_regs *)bank->fuse_regs;
464
Jason Liubf651aa2011-12-19 02:38:13 +0000465 u32 value = readl(&fuse->mac_addr_high);
466 mac[0] = (value >> 8);
467 mac[1] = value ;
Jason Liudec11122011-11-25 00:18:02 +0000468
Jason Liubf651aa2011-12-19 02:38:13 +0000469 value = readl(&fuse->mac_addr_low);
470 mac[2] = value >> 24 ;
471 mac[3] = value >> 16 ;
472 mac[4] = value >> 8 ;
473 mac[5] = value ;
Jason Liudec11122011-11-25 00:18:02 +0000474
475}
476#endif
Troy Kisky0ca618c2012-08-15 10:31:20 +0000477
478void boot_mode_apply(unsigned cfg_val)
479{
480 unsigned reg;
Eric Nelson7b8731a2012-09-18 15:26:32 +0000481 struct src *psrc = (struct src *)SRC_BASE_ADDR;
Troy Kisky0ca618c2012-08-15 10:31:20 +0000482 writel(cfg_val, &psrc->gpr9);
483 reg = readl(&psrc->gpr10);
484 if (cfg_val)
485 reg |= 1 << 28;
486 else
487 reg &= ~(1 << 28);
488 writel(reg, &psrc->gpr10);
489}
490/*
491 * cfg_val will be used for
492 * Boot_cfg4[7:0]:Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
Nikita Kiryanov9fba8422014-10-29 19:28:33 +0200493 * After reset, if GPR10[28] is 1, ROM will use GPR9[25:0]
494 * instead of SBMR1 to determine the boot device.
Troy Kisky0ca618c2012-08-15 10:31:20 +0000495 */
496const struct boot_mode soc_boot_modes[] = {
497 {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)},
498 /* reserved value should start rom usb */
499 {"usb", MAKE_CFGVAL(0x01, 0x00, 0x00, 0x00)},
500 {"sata", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
Nikolay Dimitrov284d9012014-08-10 20:03:07 +0300501 {"ecspi1:0", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x08)},
502 {"ecspi1:1", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x18)},
503 {"ecspi1:2", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x28)},
504 {"ecspi1:3", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x38)},
Troy Kisky0ca618c2012-08-15 10:31:20 +0000505 /* 4 bit bus width */
506 {"esdhc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
507 {"esdhc2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
508 {"esdhc3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
509 {"esdhc4", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
510 {NULL, 0},
511};
Stephen Warren57ab23f2013-02-26 12:28:29 +0000512
513void s_init(void)
514{
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700515 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Ye.Li29876872014-09-09 10:17:00 +0800516 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700517 u32 mask480;
518 u32 mask528;
Ye.Li29876872014-09-09 10:17:00 +0800519 u32 reg, periph1, periph2;
Fabio Estevam6633e3f2014-07-09 16:13:29 -0300520
521 if (is_cpu_type(MXC_CPU_MX6SX))
522 return;
523
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700524 /* Due to hardware limitation, on MX6Q we need to gate/ungate all PFDs
525 * to make sure PFD is working right, otherwise, PFDs may
526 * not output clock after reset, MX6DL and MX6SL have added 396M pfd
527 * workaround in ROM code, as bus clock need it
528 */
529
530 mask480 = ANATOP_PFD_CLKGATE_MASK(0) |
531 ANATOP_PFD_CLKGATE_MASK(1) |
532 ANATOP_PFD_CLKGATE_MASK(2) |
533 ANATOP_PFD_CLKGATE_MASK(3);
Ye.Li29876872014-09-09 10:17:00 +0800534 mask528 = ANATOP_PFD_CLKGATE_MASK(1) |
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700535 ANATOP_PFD_CLKGATE_MASK(3);
536
Ye.Li29876872014-09-09 10:17:00 +0800537 reg = readl(&ccm->cbcmr);
538 periph2 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_MASK)
539 >> MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_OFFSET);
540 periph1 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK)
541 >> MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_OFFSET);
542
543 /* Checking if PLL2 PFD0 or PLL2 PFD2 is using for periph clock */
544 if ((periph2 != 0x2) && (periph1 != 0x2))
545 mask528 |= ANATOP_PFD_CLKGATE_MASK(0);
546
547 if ((periph2 != 0x1) && (periph1 != 0x1) &&
548 (periph2 != 0x3) && (periph1 != 0x3))
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700549 mask528 |= ANATOP_PFD_CLKGATE_MASK(2);
Ye.Li29876872014-09-09 10:17:00 +0800550
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700551 writel(mask480, &anatop->pfd_480_set);
552 writel(mask528, &anatop->pfd_528_set);
553 writel(mask480, &anatop->pfd_480_clr);
554 writel(mask528, &anatop->pfd_528_clr);
Stephen Warren57ab23f2013-02-26 12:28:29 +0000555}
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -0500556
557#ifdef CONFIG_IMX_HDMI
558void imx_enable_hdmi_phy(void)
559{
560 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
561 u8 reg;
562 reg = readb(&hdmi->phy_conf0);
563 reg |= HDMI_PHY_CONF0_PDZ_MASK;
564 writeb(reg, &hdmi->phy_conf0);
565 udelay(3000);
566 reg |= HDMI_PHY_CONF0_ENTMDS_MASK;
567 writeb(reg, &hdmi->phy_conf0);
568 udelay(3000);
569 reg |= HDMI_PHY_CONF0_GEN2_TXPWRON_MASK;
570 writeb(reg, &hdmi->phy_conf0);
571 writeb(HDMI_MC_PHYRSTZ_ASSERT, &hdmi->mc_phyrstz);
572}
573
574void imx_setup_hdmi(void)
575{
576 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
577 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
578 int reg;
579
580 /* Turn on HDMI PHY clock */
581 reg = readl(&mxc_ccm->CCGR2);
582 reg |= MXC_CCM_CCGR2_HDMI_TX_IAHBCLK_MASK|
583 MXC_CCM_CCGR2_HDMI_TX_ISFRCLK_MASK;
584 writel(reg, &mxc_ccm->CCGR2);
585 writeb(HDMI_MC_PHYRSTZ_DEASSERT, &hdmi->mc_phyrstz);
586 reg = readl(&mxc_ccm->chsccdr);
587 reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK|
588 MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK|
589 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK);
590 reg |= (CHSCCDR_PODF_DIVIDE_BY_3
591 << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET)
592 |(CHSCCDR_IPU_PRE_CLK_540M_PFD
593 << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET);
594 writel(reg, &mxc_ccm->chsccdr);
595}
596#endif
Fabio Estevam13409292014-01-29 17:39:49 -0200597
598#ifndef CONFIG_SYS_L2CACHE_OFF
599#define IOMUXC_GPR11_L2CACHE_AS_OCRAM 0x00000002
600void v7_outer_cache_enable(void)
601{
602 struct pl310_regs *const pl310 = (struct pl310_regs *)L2_PL310_BASE;
603 unsigned int val;
604
Fabio Estevam761da0f2015-03-11 17:12:12 -0300605
606 /*
607 * Set bit 22 in the auxiliary control register. If this bit
608 * is cleared, PL310 treats Normal Shared Non-cacheable
609 * accesses as Cacheable no-allocate.
610 */
611 setbits_le32(&pl310->pl310_aux_ctrl, L310_SHARED_ATT_OVERRIDE_ENABLE);
612
Fabio Estevam13409292014-01-29 17:39:49 -0200613#if defined CONFIG_MX6SL
614 struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
615 val = readl(&iomux->gpr[11]);
616 if (val & IOMUXC_GPR11_L2CACHE_AS_OCRAM) {
617 /* L2 cache configured as OCRAM, reset it */
618 val &= ~IOMUXC_GPR11_L2CACHE_AS_OCRAM;
619 writel(val, &iomux->gpr[11]);
620 }
621#endif
622
Ye.Lia3e539a2014-08-20 17:18:24 +0800623 /* Must disable the L2 before changing the latency parameters */
624 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
625
Fabio Estevam13409292014-01-29 17:39:49 -0200626 writel(0x132, &pl310->pl310_tag_latency_ctrl);
627 writel(0x132, &pl310->pl310_data_latency_ctrl);
628
629 val = readl(&pl310->pl310_prefetch_ctrl);
630
631 /* Turn on the L2 I/D prefetch */
632 val |= 0x30000000;
633
634 /*
635 * The L2 cache controller(PL310) version on the i.MX6D/Q is r3p1-50rel0
636 * The L2 cache controller(PL310) version on the i.MX6DL/SOLO/SL is r3p2
637 * But according to ARM PL310 errata: 752271
638 * ID: 752271: Double linefill feature can cause data corruption
639 * Fault Status: Present in: r3p0, r3p1, r3p1-50rel0. Fixed in r3p2
640 * Workaround: The only workaround to this erratum is to disable the
641 * double linefill feature. This is the default behavior.
642 */
643
644#ifndef CONFIG_MX6Q
645 val |= 0x40800000;
646#endif
647 writel(val, &pl310->pl310_prefetch_ctrl);
648
649 val = readl(&pl310->pl310_power_ctrl);
650 val |= L2X0_DYNAMIC_CLK_GATING_EN;
651 val |= L2X0_STNDBY_MODE_EN;
652 writel(val, &pl310->pl310_power_ctrl);
653
654 setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
655}
656
657void v7_outer_cache_disable(void)
658{
659 struct pl310_regs *const pl310 = (struct pl310_regs *)L2_PL310_BASE;
660
661 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
662}
663#endif /* !CONFIG_SYS_L2CACHE_OFF */