blob: d4b22ad7f315072c8df91be9c3b214c15879eeb7 [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>
11#include <asm/errno.h>
12#include <asm/io.h>
13#include <asm/arch/imx-regs.h>
14#include <asm/arch/clock.h>
15#include <asm/arch/sys_proto.h>
Troy Kisky0ca618c2012-08-15 10:31:20 +000016#include <asm/imx-common/boot_mode.h>
Stefan Roese8338d1d2013-04-15 21:14:12 +000017#include <asm/imx-common/dma.h>
Adrian Alonso6ec8d842015-10-12 13:48:12 -050018#include <asm/imx-common/hab.h>
Fabio Estevam48e65b02013-02-07 06:45:23 +000019#include <stdbool.h>
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -050020#include <asm/arch/mxc_hdmi.h>
21#include <asm/arch/crm_regs.h>
Ye.Lif19692c2014-11-20 21:14:14 +080022#include <dm.h>
23#include <imx_thermal.h>
Soeren Mochbc177f12016-02-04 14:41:15 +010024#include <mmc.h>
Jason Liudec11122011-11-25 00:18:02 +000025
Fabio Estevama47ec522013-12-26 14:51:33 -020026enum ldo_reg {
27 LDO_ARM,
28 LDO_SOC,
29 LDO_PU,
30};
31
Troy Kisky58394932012-10-23 10:57:46 +000032struct scu_regs {
33 u32 ctrl;
34 u32 config;
35 u32 status;
36 u32 invalidate;
37 u32 fpga_rev;
38};
39
Adrian Alonsoce08c362015-09-02 13:54:13 -050040#if defined(CONFIG_IMX_THERMAL)
Ye.Lif19692c2014-11-20 21:14:14 +080041static const struct imx_thermal_plat imx6_thermal_plat = {
42 .regs = (void *)ANATOP_BASE_ADDR,
43 .fuse_bank = 1,
44 .fuse_word = 6,
45};
46
47U_BOOT_DEVICE(imx6_thermal) = {
48 .name = "imx_thermal",
49 .platdata = &imx6_thermal_plat,
50};
51#endif
52
Adrian Alonso6ec8d842015-10-12 13:48:12 -050053#if defined(CONFIG_SECURE_BOOT)
54struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
55 .bank = 0,
56 .word = 6,
57};
58#endif
59
Gabriel Huau170ceaf2014-07-26 11:35:43 -070060u32 get_nr_cpus(void)
61{
62 struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
63 return readl(&scu->config) & 3;
64}
65
Jason Liudec11122011-11-25 00:18:02 +000066u32 get_cpu_rev(void)
67{
Fabio Estevam46e97332012-03-20 04:21:45 +000068 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Troy Kisky58394932012-10-23 10:57:46 +000069 u32 reg = readl(&anatop->digprog_sololite);
70 u32 type = ((reg >> 16) & 0xff);
Peng Fan5f247922015-07-11 11:38:42 +080071 u32 major, cfg = 0;
Fabio Estevam46e97332012-03-20 04:21:45 +000072
Troy Kisky58394932012-10-23 10:57:46 +000073 if (type != MXC_CPU_MX6SL) {
74 reg = readl(&anatop->digprog);
Fabio Estevamf3d5a2c2014-01-26 15:06:41 -020075 struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
Peng Fan5f247922015-07-11 11:38:42 +080076 cfg = readl(&scu->config) & 3;
Troy Kisky58394932012-10-23 10:57:46 +000077 type = ((reg >> 16) & 0xff);
78 if (type == MXC_CPU_MX6DL) {
Troy Kisky58394932012-10-23 10:57:46 +000079 if (!cfg)
80 type = MXC_CPU_MX6SOLO;
81 }
Fabio Estevamf3d5a2c2014-01-26 15:06:41 -020082
83 if (type == MXC_CPU_MX6Q) {
84 if (cfg == 1)
85 type = MXC_CPU_MX6D;
86 }
87
Troy Kisky58394932012-10-23 10:57:46 +000088 }
Peng Fan88383232015-06-11 18:30:36 +080089 major = ((reg >> 8) & 0xff);
Peng Fan5f247922015-07-11 11:38:42 +080090 if ((major >= 1) &&
91 ((type == MXC_CPU_MX6Q) || (type == MXC_CPU_MX6D))) {
92 major--;
93 type = MXC_CPU_MX6QP;
94 if (cfg == 1)
95 type = MXC_CPU_MX6DP;
96 }
Troy Kisky58394932012-10-23 10:57:46 +000097 reg &= 0xff; /* mx6 silicon revision */
Peng Fan88383232015-06-11 18:30:36 +080098 return (type << 12) | (reg + (0x10 * (major + 1)));
Jason Liudec11122011-11-25 00:18:02 +000099}
100
Tim Harvey258d0462015-05-18 07:02:24 -0700101/*
102 * OCOTP_CFG3[17:16] (see Fusemap Description Table offset 0x440)
103 * defines a 2-bit SPEED_GRADING
104 */
105#define OCOTP_CFG3_SPEED_SHIFT 16
106#define OCOTP_CFG3_SPEED_800MHZ 0
107#define OCOTP_CFG3_SPEED_850MHZ 1
108#define OCOTP_CFG3_SPEED_1GHZ 2
109#define OCOTP_CFG3_SPEED_1P2GHZ 3
110
111u32 get_cpu_speed_grade_hz(void)
112{
113 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
114 struct fuse_bank *bank = &ocotp->bank[0];
115 struct fuse_bank0_regs *fuse =
116 (struct fuse_bank0_regs *)bank->fuse_regs;
117 uint32_t val;
118
119 val = readl(&fuse->cfg3);
120 val >>= OCOTP_CFG3_SPEED_SHIFT;
121 val &= 0x3;
122
123 switch (val) {
124 /* Valid for IMX6DQ */
125 case OCOTP_CFG3_SPEED_1P2GHZ:
126 if (is_cpu_type(MXC_CPU_MX6Q) || is_cpu_type(MXC_CPU_MX6D))
127 return 1200000000;
128 /* Valid for IMX6SX/IMX6SDL/IMX6DQ */
129 case OCOTP_CFG3_SPEED_1GHZ:
130 return 996000000;
131 /* Valid for IMX6DQ */
132 case OCOTP_CFG3_SPEED_850MHZ:
133 if (is_cpu_type(MXC_CPU_MX6Q) || is_cpu_type(MXC_CPU_MX6D))
134 return 852000000;
135 /* Valid for IMX6SX/IMX6SDL/IMX6DQ */
136 case OCOTP_CFG3_SPEED_800MHZ:
137 return 792000000;
138 }
139 return 0;
140}
141
Tim Harvey5e0e1932015-05-18 06:56:45 -0700142/*
143 * OCOTP_MEM0[7:6] (see Fusemap Description Table offset 0x480)
144 * defines a 2-bit Temperature Grade
145 *
146 * return temperature grade and min/max temperature in celcius
147 */
148#define OCOTP_MEM0_TEMP_SHIFT 6
149
150u32 get_cpu_temp_grade(int *minc, int *maxc)
151{
152 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
153 struct fuse_bank *bank = &ocotp->bank[1];
154 struct fuse_bank1_regs *fuse =
155 (struct fuse_bank1_regs *)bank->fuse_regs;
156 uint32_t val;
157
158 val = readl(&fuse->mem0);
159 val >>= OCOTP_MEM0_TEMP_SHIFT;
160 val &= 0x3;
161
162 if (minc && maxc) {
163 if (val == TEMP_AUTOMOTIVE) {
164 *minc = -40;
165 *maxc = 125;
166 } else if (val == TEMP_INDUSTRIAL) {
167 *minc = -40;
168 *maxc = 105;
169 } else if (val == TEMP_EXTCOMMERCIAL) {
170 *minc = -20;
171 *maxc = 105;
172 } else {
173 *minc = 0;
174 *maxc = 95;
175 }
176 }
177 return val;
178}
179
Fabio Estevam435998b2013-03-27 07:36:55 +0000180#ifdef CONFIG_REVISION_TAG
181u32 __weak get_board_rev(void)
182{
183 u32 cpurev = get_cpu_rev();
184 u32 type = ((cpurev >> 12) & 0xff);
185 if (type == MXC_CPU_MX6SOLO)
186 cpurev = (MXC_CPU_MX6DL) << 12 | (cpurev & 0xFFF);
187
Fabio Estevamf3d5a2c2014-01-26 15:06:41 -0200188 if (type == MXC_CPU_MX6D)
189 cpurev = (MXC_CPU_MX6Q) << 12 | (cpurev & 0xFFF);
190
Fabio Estevam435998b2013-03-27 07:36:55 +0000191 return cpurev;
192}
193#endif
194
Fabio Estevamcf621ff2013-12-26 14:51:31 -0200195static void clear_ldo_ramp(void)
196{
197 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
198 int reg;
199
200 /* ROM may modify LDO ramp up time according to fuse setting, so in
201 * order to be in the safe side we neeed to reset these settings to
202 * match the reset value: 0'b00
203 */
204 reg = readl(&anatop->ana_misc2);
205 reg &= ~(0x3f << 24);
206 writel(reg, &anatop->ana_misc2);
207}
208
Dirk Behme8c465942012-05-02 02:12:17 +0000209/*
Fabio Estevam2e95fe12014-06-13 01:42:37 -0300210 * Set the PMU_REG_CORE register
Dirk Behme8c465942012-05-02 02:12:17 +0000211 *
Fabio Estevam2e95fe12014-06-13 01:42:37 -0300212 * Set LDO_SOC/PU/ARM regulators to the specified millivolt level.
Dirk Behme8c465942012-05-02 02:12:17 +0000213 * Possible values are from 0.725V to 1.450V in steps of
214 * 0.025V (25mV).
215 */
Fabio Estevama47ec522013-12-26 14:51:33 -0200216static int set_ldo_voltage(enum ldo_reg ldo, u32 mv)
Dirk Behme8c465942012-05-02 02:12:17 +0000217{
218 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Fabio Estevam99b370b2013-12-26 14:51:34 -0200219 u32 val, step, old, reg = readl(&anatop->reg_core);
Fabio Estevama47ec522013-12-26 14:51:33 -0200220 u8 shift;
Dirk Behme8c465942012-05-02 02:12:17 +0000221
222 if (mv < 725)
223 val = 0x00; /* Power gated off */
224 else if (mv > 1450)
225 val = 0x1F; /* Power FET switched full on. No regulation */
226 else
227 val = (mv - 700) / 25;
228
Fabio Estevamcf621ff2013-12-26 14:51:31 -0200229 clear_ldo_ramp();
230
Fabio Estevama47ec522013-12-26 14:51:33 -0200231 switch (ldo) {
232 case LDO_SOC:
233 shift = 18;
234 break;
235 case LDO_PU:
236 shift = 9;
237 break;
238 case LDO_ARM:
239 shift = 0;
240 break;
241 default:
242 return -EINVAL;
243 }
244
Fabio Estevam99b370b2013-12-26 14:51:34 -0200245 old = (reg & (0x1F << shift)) >> shift;
246 step = abs(val - old);
247 if (step == 0)
248 return 0;
249
Fabio Estevama47ec522013-12-26 14:51:33 -0200250 reg = (reg & ~(0x1F << shift)) | (val << shift);
Dirk Behme8c465942012-05-02 02:12:17 +0000251 writel(reg, &anatop->reg_core);
Fabio Estevama47ec522013-12-26 14:51:33 -0200252
Fabio Estevam99b370b2013-12-26 14:51:34 -0200253 /*
254 * The LDO ramp-up is based on 64 clock cycles of 24 MHz = 2.6 us per
255 * step
256 */
257 udelay(3 * step);
258
Fabio Estevama47ec522013-12-26 14:51:33 -0200259 return 0;
Dirk Behme8c465942012-05-02 02:12:17 +0000260}
261
Anson Huang05a464f2014-01-23 14:00:18 +0800262static void set_ahb_rate(u32 val)
263{
264 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
265 u32 reg, div;
266
267 div = get_periph_clk() / val - 1;
268 reg = readl(&mxc_ccm->cbcdr);
269
270 writel((reg & (~MXC_CCM_CBCDR_AHB_PODF_MASK)) |
271 (div << MXC_CCM_CBCDR_AHB_PODF_OFFSET), &mxc_ccm->cbcdr);
272}
273
Anson Huang9a149bc2014-01-23 14:00:19 +0800274static void clear_mmdc_ch_mask(void)
275{
276 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Peng Fan53f3c9e2015-07-11 11:38:43 +0800277 u32 reg;
278 reg = readl(&mxc_ccm->ccdr);
Anson Huang9a149bc2014-01-23 14:00:19 +0800279
280 /* Clear MMDC channel mask */
Ye Li64cef442016-03-09 16:13:48 +0800281 if (is_cpu_type(MXC_CPU_MX6SX) || is_cpu_type(MXC_CPU_MX6UL) || is_cpu_type(MXC_CPU_MX6SL))
282 reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK);
283 else
284 reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK | MXC_CCM_CCDR_MMDC_CH0_HS_MASK);
Peng Fan53f3c9e2015-07-11 11:38:43 +0800285 writel(reg, &mxc_ccm->ccdr);
Anson Huang9a149bc2014-01-23 14:00:19 +0800286}
287
Peng Fanc0e0ebf2015-01-15 14:22:32 +0800288static void init_bandgap(void)
289{
290 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
291 /*
292 * Ensure the bandgap has stabilized.
293 */
294 while (!(readl(&anatop->ana_misc0) & 0x80))
295 ;
296 /*
297 * For best noise performance of the analog blocks using the
298 * outputs of the bandgap, the reftop_selfbiasoff bit should
299 * be set.
300 */
301 writel(BM_ANADIG_ANA_MISC0_REFTOP_SELBIASOFF, &anatop->ana_misc0_set);
302}
303
304
Ye.Li622dfbd2014-10-30 18:20:58 +0800305#ifdef CONFIG_MX6SL
306static void set_preclk_from_osc(void)
307{
308 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
309 u32 reg;
310
311 reg = readl(&mxc_ccm->cscmr1);
312 reg |= MXC_CCM_CSCMR1_PER_CLK_SEL_MASK;
313 writel(reg, &mxc_ccm->cscmr1);
314}
315#endif
316
Jason Liudec11122011-11-25 00:18:02 +0000317int arch_cpu_init(void)
318{
319 init_aips();
320
Anson Huang9a149bc2014-01-23 14:00:19 +0800321 /* Need to clear MMDC_CHx_MASK to make warm reset work. */
322 clear_mmdc_ch_mask();
323
Anson Huang05a464f2014-01-23 14:00:18 +0800324 /*
Peng Fanc0e0ebf2015-01-15 14:22:32 +0800325 * Disable self-bias circuit in the analog bandap.
326 * The self-bias circuit is used by the bandgap during startup.
327 * This bit should be set after the bandgap has initialized.
328 */
329 init_bandgap();
330
Peng Fanf60137e2016-03-09 16:44:36 +0800331 if (!IS_ENABLED(CONFIG_MX6UL)) {
332 /*
333 * When low freq boot is enabled, ROM will not set AHB
334 * freq, so we need to ensure AHB freq is 132MHz in such
335 * scenario.
336 *
337 * To i.MX6UL, when power up, default ARM core and
338 * AHB rate is 396M and 132M.
339 */
340 if (mxc_get_clock(MXC_ARM_CLK) == 396000000)
341 set_ahb_rate(132000000);
342 }
Anson Huang05a464f2014-01-23 14:00:18 +0800343
Peng Fana2cba652016-03-09 16:44:37 +0800344 if (IS_ENABLED(CONFIG_MX6UL) && is_soc_rev(CHIP_REV_1_0) == 0) {
345 /*
346 * According to the design team's requirement on i.MX6UL,
347 * the PMIC_STBY_REQ PAD should be configured as open
348 * drain 100K (0x0000b8a0).
349 * Only exists on TO1.0
350 */
351 writel(0x0000b8a0, IOMUXC_BASE_ADDR + 0x29c);
352 }
353
354 /* Set perclk to source from OSC 24MHz */
Ye.Li622dfbd2014-10-30 18:20:58 +0800355#if defined(CONFIG_MX6SL)
356 set_preclk_from_osc();
357#endif
358
Fabio Estevam48e65b02013-02-07 06:45:23 +0000359 imx_set_wdog_powerdown(false); /* Disable PDE bit of WMCR register */
Stefan Roese8338d1d2013-04-15 21:14:12 +0000360
361#ifdef CONFIG_APBH_DMA
362 /* Start APBH DMA */
363 mxs_dma_init();
364#endif
365
Dirk Behme0adb2152015-03-09 14:48:48 +0100366 init_src();
367
Jason Liudec11122011-11-25 00:18:02 +0000368 return 0;
369}
Jason Liudec11122011-11-25 00:18:02 +0000370
Peng Fan850dbca2016-01-28 16:51:26 +0800371#ifdef CONFIG_ENV_IS_IN_MMC
372__weak int board_mmc_get_env_dev(int devno)
373{
374 return CONFIG_SYS_MMC_ENV_DEV;
375}
376
Soeren Mochbc177f12016-02-04 14:41:15 +0100377static int mmc_get_boot_dev(void)
Peng Fan850dbca2016-01-28 16:51:26 +0800378{
379 struct src *src_regs = (struct src *)SRC_BASE_ADDR;
380 u32 soc_sbmr = readl(&src_regs->sbmr1);
381 u32 bootsel;
382 int devno;
383
384 /*
385 * Refer to
386 * "i.MX 6Dual/6Quad Applications Processor Reference Manual"
387 * Chapter "8.5.3.1 Expansion Device eFUSE Configuration"
388 * i.MX6SL/SX/UL has same layout.
389 */
390 bootsel = (soc_sbmr & 0x000000FF) >> 6;
391
Soeren Mochbc177f12016-02-04 14:41:15 +0100392 /* No boot from sd/mmc */
Peng Fan850dbca2016-01-28 16:51:26 +0800393 if (bootsel != 1)
Soeren Mochbc177f12016-02-04 14:41:15 +0100394 return -1;
Peng Fan850dbca2016-01-28 16:51:26 +0800395
396 /* BOOT_CFG2[3] and BOOT_CFG2[4] */
397 devno = (soc_sbmr & 0x00001800) >> 11;
398
Soeren Mochbc177f12016-02-04 14:41:15 +0100399 return devno;
400}
401
402int mmc_get_env_dev(void)
403{
404 int devno = mmc_get_boot_dev();
405
406 /* If not boot from sd/mmc, use default value */
407 if (devno < 0)
408 return CONFIG_SYS_MMC_ENV_DEV;
409
Peng Fan850dbca2016-01-28 16:51:26 +0800410 return board_mmc_get_env_dev(devno);
411}
Soeren Mochbc177f12016-02-04 14:41:15 +0100412
413#ifdef CONFIG_SYS_MMC_ENV_PART
414__weak int board_mmc_get_env_part(int devno)
415{
416 return CONFIG_SYS_MMC_ENV_PART;
417}
418
419uint mmc_get_env_part(struct mmc *mmc)
420{
421 int devno = mmc_get_boot_dev();
422
423 /* If not boot from sd/mmc, use default value */
424 if (devno < 0)
425 return CONFIG_SYS_MMC_ENV_PART;
426
427 return board_mmc_get_env_part(devno);
428}
429#endif
Peng Fan850dbca2016-01-28 16:51:26 +0800430#endif
431
Fabio Estevam99b370b2013-12-26 14:51:34 -0200432int board_postclk_init(void)
433{
434 set_ldo_voltage(LDO_SOC, 1175); /* Set VDDSOC to 1.175V */
435
436 return 0;
437}
438
Jason Liudec11122011-11-25 00:18:02 +0000439#if defined(CONFIG_FEC_MXC)
Fabio Estevam04fc1282011-12-20 05:46:31 +0000440void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
Jason Liudec11122011-11-25 00:18:02 +0000441{
Benoît Thébaudeaufa7e3952013-04-23 10:17:38 +0000442 struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
443 struct fuse_bank *bank = &ocotp->bank[4];
Jason Liudec11122011-11-25 00:18:02 +0000444 struct fuse_bank4_regs *fuse =
445 (struct fuse_bank4_regs *)bank->fuse_regs;
446
Ye Lid5d8bf72016-02-01 10:41:31 +0800447 if ((is_cpu_type(MXC_CPU_MX6SX) || is_cpu_type(MXC_CPU_MX6UL)) &&
448 dev_id == 1) {
449 u32 value = readl(&fuse->mac_addr2);
450 mac[0] = value >> 24 ;
451 mac[1] = value >> 16 ;
452 mac[2] = value >> 8 ;
453 mac[3] = value ;
454
455 value = readl(&fuse->mac_addr1);
456 mac[4] = value >> 24 ;
457 mac[5] = value >> 16 ;
458
459 } else {
460 u32 value = readl(&fuse->mac_addr1);
461 mac[0] = (value >> 8);
462 mac[1] = value ;
Jason Liudec11122011-11-25 00:18:02 +0000463
Ye Lid5d8bf72016-02-01 10:41:31 +0800464 value = readl(&fuse->mac_addr0);
465 mac[2] = value >> 24 ;
466 mac[3] = value >> 16 ;
467 mac[4] = value >> 8 ;
468 mac[5] = value ;
469 }
Jason Liudec11122011-11-25 00:18:02 +0000470
471}
472#endif
Troy Kisky0ca618c2012-08-15 10:31:20 +0000473
Troy Kisky0ca618c2012-08-15 10:31:20 +0000474/*
475 * cfg_val will be used for
476 * Boot_cfg4[7:0]:Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
Nikita Kiryanov9fba8422014-10-29 19:28:33 +0200477 * After reset, if GPR10[28] is 1, ROM will use GPR9[25:0]
478 * instead of SBMR1 to determine the boot device.
Troy Kisky0ca618c2012-08-15 10:31:20 +0000479 */
480const struct boot_mode soc_boot_modes[] = {
481 {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)},
482 /* reserved value should start rom usb */
483 {"usb", MAKE_CFGVAL(0x01, 0x00, 0x00, 0x00)},
484 {"sata", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
Nikolay Dimitrov284d9012014-08-10 20:03:07 +0300485 {"ecspi1:0", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x08)},
486 {"ecspi1:1", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x18)},
487 {"ecspi1:2", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x28)},
488 {"ecspi1:3", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x38)},
Troy Kisky0ca618c2012-08-15 10:31:20 +0000489 /* 4 bit bus width */
490 {"esdhc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
491 {"esdhc2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
492 {"esdhc3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
493 {"esdhc4", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
494 {NULL, 0},
495};
Stephen Warren57ab23f2013-02-26 12:28:29 +0000496
Peng Fan92683e62015-10-29 15:54:50 +0800497void reset_misc(void)
498{
499#ifdef CONFIG_VIDEO_MXS
500 lcdif_power_down();
501#endif
502}
503
Stephen Warren57ab23f2013-02-26 12:28:29 +0000504void s_init(void)
505{
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700506 struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
Ye.Li29876872014-09-09 10:17:00 +0800507 struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700508 u32 mask480;
509 u32 mask528;
Ye.Li29876872014-09-09 10:17:00 +0800510 u32 reg, periph1, periph2;
Fabio Estevam6633e3f2014-07-09 16:13:29 -0300511
Peng Fancf333da2015-07-20 19:28:29 +0800512 if (is_cpu_type(MXC_CPU_MX6SX) || is_cpu_type(MXC_CPU_MX6UL))
Fabio Estevam6633e3f2014-07-09 16:13:29 -0300513 return;
514
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700515 /* Due to hardware limitation, on MX6Q we need to gate/ungate all PFDs
516 * to make sure PFD is working right, otherwise, PFDs may
517 * not output clock after reset, MX6DL and MX6SL have added 396M pfd
518 * workaround in ROM code, as bus clock need it
519 */
520
521 mask480 = ANATOP_PFD_CLKGATE_MASK(0) |
522 ANATOP_PFD_CLKGATE_MASK(1) |
523 ANATOP_PFD_CLKGATE_MASK(2) |
524 ANATOP_PFD_CLKGATE_MASK(3);
Ye.Li29876872014-09-09 10:17:00 +0800525 mask528 = ANATOP_PFD_CLKGATE_MASK(1) |
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700526 ANATOP_PFD_CLKGATE_MASK(3);
527
Ye.Li29876872014-09-09 10:17:00 +0800528 reg = readl(&ccm->cbcmr);
529 periph2 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_MASK)
530 >> MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_OFFSET);
531 periph1 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK)
532 >> MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_OFFSET);
533
534 /* Checking if PLL2 PFD0 or PLL2 PFD2 is using for periph clock */
535 if ((periph2 != 0x2) && (periph1 != 0x2))
536 mask528 |= ANATOP_PFD_CLKGATE_MASK(0);
537
538 if ((periph2 != 0x1) && (periph1 != 0x1) &&
539 (periph2 != 0x3) && (periph1 != 0x3))
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700540 mask528 |= ANATOP_PFD_CLKGATE_MASK(2);
Ye.Li29876872014-09-09 10:17:00 +0800541
Eric Nelson2c37d3b2013-08-29 12:41:46 -0700542 writel(mask480, &anatop->pfd_480_set);
543 writel(mask528, &anatop->pfd_528_set);
544 writel(mask480, &anatop->pfd_480_clr);
545 writel(mask528, &anatop->pfd_528_clr);
Stephen Warren57ab23f2013-02-26 12:28:29 +0000546}
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -0500547
548#ifdef CONFIG_IMX_HDMI
549void imx_enable_hdmi_phy(void)
550{
551 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
552 u8 reg;
553 reg = readb(&hdmi->phy_conf0);
554 reg |= HDMI_PHY_CONF0_PDZ_MASK;
555 writeb(reg, &hdmi->phy_conf0);
556 udelay(3000);
557 reg |= HDMI_PHY_CONF0_ENTMDS_MASK;
558 writeb(reg, &hdmi->phy_conf0);
559 udelay(3000);
560 reg |= HDMI_PHY_CONF0_GEN2_TXPWRON_MASK;
561 writeb(reg, &hdmi->phy_conf0);
562 writeb(HDMI_MC_PHYRSTZ_ASSERT, &hdmi->mc_phyrstz);
563}
564
565void imx_setup_hdmi(void)
566{
567 struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
568 struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
Peng Fan95ae6122016-03-09 16:07:23 +0800569 int reg, count;
570 u8 val;
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -0500571
572 /* Turn on HDMI PHY clock */
573 reg = readl(&mxc_ccm->CCGR2);
574 reg |= MXC_CCM_CCGR2_HDMI_TX_IAHBCLK_MASK|
575 MXC_CCM_CCGR2_HDMI_TX_ISFRCLK_MASK;
576 writel(reg, &mxc_ccm->CCGR2);
577 writeb(HDMI_MC_PHYRSTZ_DEASSERT, &hdmi->mc_phyrstz);
578 reg = readl(&mxc_ccm->chsccdr);
579 reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK|
580 MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK|
581 MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK);
582 reg |= (CHSCCDR_PODF_DIVIDE_BY_3
583 << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET)
584 |(CHSCCDR_IPU_PRE_CLK_540M_PFD
585 << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET);
586 writel(reg, &mxc_ccm->chsccdr);
Peng Fan95ae6122016-03-09 16:07:23 +0800587
588 /* Clear the overflow condition */
589 if (readb(&hdmi->ih_fc_stat2) & HDMI_IH_FC_STAT2_OVERFLOW_MASK) {
590 /* TMDS software reset */
591 writeb((u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, &hdmi->mc_swrstz);
592 val = readb(&hdmi->fc_invidconf);
593 /* Need minimum 3 times to write to clear the register */
594 for (count = 0 ; count < 5 ; count++)
595 writeb(val, &hdmi->fc_invidconf);
596 }
Pardeep Kumar Singlac1fa1302013-07-25 12:12:13 -0500597}
598#endif
Peng Fanfb3a3b72016-01-28 16:55:05 +0800599
600#ifdef CONFIG_IMX_BOOTAUX
601int arch_auxiliary_core_up(u32 core_id, u32 boot_private_data)
602{
603 struct src *src_reg;
604 u32 stack, pc;
605
606 if (!boot_private_data)
607 return -EINVAL;
608
609 stack = *(u32 *)boot_private_data;
610 pc = *(u32 *)(boot_private_data + 4);
611
612 /* Set the stack and pc to M4 bootROM */
613 writel(stack, M4_BOOTROM_BASE_ADDR);
614 writel(pc, M4_BOOTROM_BASE_ADDR + 4);
615
616 /* Enable M4 */
617 src_reg = (struct src *)SRC_BASE_ADDR;
618 clrsetbits_le32(&src_reg->scr, SRC_SCR_M4C_NON_SCLR_RST_MASK,
619 SRC_SCR_M4_ENABLE_MASK);
620
621 return 0;
622}
623
624int arch_auxiliary_core_check_up(u32 core_id)
625{
626 struct src *src_reg = (struct src *)SRC_BASE_ADDR;
627 unsigned val;
628
629 val = readl(&src_reg->scr);
630
631 if (val & SRC_SCR_M4C_NON_SCLR_RST_MASK)
632 return 0; /* assert in reset */
633
634 return 1;
635}
636#endif