soc.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668
  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. #include <common.h>
  10. #include <linux/errno.h>
  11. #include <asm/io.h>
  12. #include <asm/arch/imx-regs.h>
  13. #include <asm/arch/clock.h>
  14. #include <asm/arch/sys_proto.h>
  15. #include <asm/bootm.h>
  16. #include <asm/mach-imx/boot_mode.h>
  17. #include <asm/mach-imx/dma.h>
  18. #include <asm/mach-imx/hab.h>
  19. #include <stdbool.h>
  20. #include <asm/arch/mxc_hdmi.h>
  21. #include <asm/arch/crm_regs.h>
  22. #include <dm.h>
  23. #include <imx_thermal.h>
  24. #include <mmc.h>
  25. enum ldo_reg {
  26. LDO_ARM,
  27. LDO_SOC,
  28. LDO_PU,
  29. };
  30. struct scu_regs {
  31. u32 ctrl;
  32. u32 config;
  33. u32 status;
  34. u32 invalidate;
  35. u32 fpga_rev;
  36. };
  37. #if defined(CONFIG_IMX_THERMAL)
  38. static const struct imx_thermal_plat imx6_thermal_plat = {
  39. .regs = (void *)ANATOP_BASE_ADDR,
  40. .fuse_bank = 1,
  41. .fuse_word = 6,
  42. };
  43. U_BOOT_DEVICE(imx6_thermal) = {
  44. .name = "imx_thermal",
  45. .platdata = &imx6_thermal_plat,
  46. };
  47. #endif
  48. #if defined(CONFIG_SECURE_BOOT)
  49. struct imx_sec_config_fuse_t const imx_sec_config_fuse = {
  50. .bank = 0,
  51. .word = 6,
  52. };
  53. #endif
  54. u32 get_nr_cpus(void)
  55. {
  56. struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
  57. return readl(&scu->config) & 3;
  58. }
  59. u32 get_cpu_rev(void)
  60. {
  61. struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
  62. u32 reg = readl(&anatop->digprog_sololite);
  63. u32 type = ((reg >> 16) & 0xff);
  64. u32 major, cfg = 0;
  65. if (type != MXC_CPU_MX6SL) {
  66. reg = readl(&anatop->digprog);
  67. struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
  68. cfg = readl(&scu->config) & 3;
  69. type = ((reg >> 16) & 0xff);
  70. if (type == MXC_CPU_MX6DL) {
  71. if (!cfg)
  72. type = MXC_CPU_MX6SOLO;
  73. }
  74. if (type == MXC_CPU_MX6Q) {
  75. if (cfg == 1)
  76. type = MXC_CPU_MX6D;
  77. }
  78. }
  79. major = ((reg >> 8) & 0xff);
  80. if ((major >= 1) &&
  81. ((type == MXC_CPU_MX6Q) || (type == MXC_CPU_MX6D))) {
  82. major--;
  83. type = MXC_CPU_MX6QP;
  84. if (cfg == 1)
  85. type = MXC_CPU_MX6DP;
  86. }
  87. reg &= 0xff; /* mx6 silicon revision */
  88. return (type << 12) | (reg + (0x10 * (major + 1)));
  89. }
  90. /*
  91. * OCOTP_CFG3[17:16] (see Fusemap Description Table offset 0x440)
  92. * defines a 2-bit SPEED_GRADING
  93. */
  94. #define OCOTP_CFG3_SPEED_SHIFT 16
  95. #define OCOTP_CFG3_SPEED_800MHZ 0
  96. #define OCOTP_CFG3_SPEED_850MHZ 1
  97. #define OCOTP_CFG3_SPEED_1GHZ 2
  98. #define OCOTP_CFG3_SPEED_1P2GHZ 3
  99. /*
  100. * For i.MX6UL
  101. */
  102. #define OCOTP_CFG3_SPEED_528MHZ 1
  103. #define OCOTP_CFG3_SPEED_696MHZ 2
  104. /*
  105. * For i.MX6ULL
  106. */
  107. #define OCOTP_CFG3_SPEED_792MHZ 2
  108. #define OCOTP_CFG3_SPEED_900MHZ 3
  109. u32 get_cpu_speed_grade_hz(void)
  110. {
  111. struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
  112. struct fuse_bank *bank = &ocotp->bank[0];
  113. struct fuse_bank0_regs *fuse =
  114. (struct fuse_bank0_regs *)bank->fuse_regs;
  115. uint32_t val;
  116. val = readl(&fuse->cfg3);
  117. val >>= OCOTP_CFG3_SPEED_SHIFT;
  118. val &= 0x3;
  119. if (is_mx6ul()) {
  120. if (val == OCOTP_CFG3_SPEED_528MHZ)
  121. return 528000000;
  122. else if (val == OCOTP_CFG3_SPEED_696MHZ)
  123. return 696000000;
  124. else
  125. return 0;
  126. }
  127. if (is_mx6ull()) {
  128. if (val == OCOTP_CFG3_SPEED_528MHZ)
  129. return 528000000;
  130. else if (val == OCOTP_CFG3_SPEED_792MHZ)
  131. return 792000000;
  132. else if (val == OCOTP_CFG3_SPEED_900MHZ)
  133. return 900000000;
  134. else
  135. return 0;
  136. }
  137. switch (val) {
  138. /* Valid for IMX6DQ */
  139. case OCOTP_CFG3_SPEED_1P2GHZ:
  140. if (is_mx6dq() || is_mx6dqp())
  141. return 1200000000;
  142. /* Valid for IMX6SX/IMX6SDL/IMX6DQ */
  143. case OCOTP_CFG3_SPEED_1GHZ:
  144. return 996000000;
  145. /* Valid for IMX6DQ */
  146. case OCOTP_CFG3_SPEED_850MHZ:
  147. if (is_mx6dq() || is_mx6dqp())
  148. return 852000000;
  149. /* Valid for IMX6SX/IMX6SDL/IMX6DQ */
  150. case OCOTP_CFG3_SPEED_800MHZ:
  151. return 792000000;
  152. }
  153. return 0;
  154. }
  155. /*
  156. * OCOTP_MEM0[7:6] (see Fusemap Description Table offset 0x480)
  157. * defines a 2-bit Temperature Grade
  158. *
  159. * return temperature grade and min/max temperature in Celsius
  160. */
  161. #define OCOTP_MEM0_TEMP_SHIFT 6
  162. u32 get_cpu_temp_grade(int *minc, int *maxc)
  163. {
  164. struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
  165. struct fuse_bank *bank = &ocotp->bank[1];
  166. struct fuse_bank1_regs *fuse =
  167. (struct fuse_bank1_regs *)bank->fuse_regs;
  168. uint32_t val;
  169. val = readl(&fuse->mem0);
  170. val >>= OCOTP_MEM0_TEMP_SHIFT;
  171. val &= 0x3;
  172. if (minc && maxc) {
  173. if (val == TEMP_AUTOMOTIVE) {
  174. *minc = -40;
  175. *maxc = 125;
  176. } else if (val == TEMP_INDUSTRIAL) {
  177. *minc = -40;
  178. *maxc = 105;
  179. } else if (val == TEMP_EXTCOMMERCIAL) {
  180. *minc = -20;
  181. *maxc = 105;
  182. } else {
  183. *minc = 0;
  184. *maxc = 95;
  185. }
  186. }
  187. return val;
  188. }
  189. #ifdef CONFIG_REVISION_TAG
  190. u32 __weak get_board_rev(void)
  191. {
  192. u32 cpurev = get_cpu_rev();
  193. u32 type = ((cpurev >> 12) & 0xff);
  194. if (type == MXC_CPU_MX6SOLO)
  195. cpurev = (MXC_CPU_MX6DL) << 12 | (cpurev & 0xFFF);
  196. if (type == MXC_CPU_MX6D)
  197. cpurev = (MXC_CPU_MX6Q) << 12 | (cpurev & 0xFFF);
  198. return cpurev;
  199. }
  200. #endif
  201. static void clear_ldo_ramp(void)
  202. {
  203. struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
  204. int reg;
  205. /* ROM may modify LDO ramp up time according to fuse setting, so in
  206. * order to be in the safe side we neeed to reset these settings to
  207. * match the reset value: 0'b00
  208. */
  209. reg = readl(&anatop->ana_misc2);
  210. reg &= ~(0x3f << 24);
  211. writel(reg, &anatop->ana_misc2);
  212. }
  213. /*
  214. * Set the PMU_REG_CORE register
  215. *
  216. * Set LDO_SOC/PU/ARM regulators to the specified millivolt level.
  217. * Possible values are from 0.725V to 1.450V in steps of
  218. * 0.025V (25mV).
  219. */
  220. static int set_ldo_voltage(enum ldo_reg ldo, u32 mv)
  221. {
  222. struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
  223. u32 val, step, old, reg = readl(&anatop->reg_core);
  224. u8 shift;
  225. /* No LDO_SOC/PU/ARM */
  226. if (is_mx6sll())
  227. return 0;
  228. if (mv < 725)
  229. val = 0x00; /* Power gated off */
  230. else if (mv > 1450)
  231. val = 0x1F; /* Power FET switched full on. No regulation */
  232. else
  233. val = (mv - 700) / 25;
  234. clear_ldo_ramp();
  235. switch (ldo) {
  236. case LDO_SOC:
  237. shift = 18;
  238. break;
  239. case LDO_PU:
  240. shift = 9;
  241. break;
  242. case LDO_ARM:
  243. shift = 0;
  244. break;
  245. default:
  246. return -EINVAL;
  247. }
  248. old = (reg & (0x1F << shift)) >> shift;
  249. step = abs(val - old);
  250. if (step == 0)
  251. return 0;
  252. reg = (reg & ~(0x1F << shift)) | (val << shift);
  253. writel(reg, &anatop->reg_core);
  254. /*
  255. * The LDO ramp-up is based on 64 clock cycles of 24 MHz = 2.6 us per
  256. * step
  257. */
  258. udelay(3 * step);
  259. return 0;
  260. }
  261. static void set_ahb_rate(u32 val)
  262. {
  263. struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
  264. u32 reg, div;
  265. div = get_periph_clk() / val - 1;
  266. reg = readl(&mxc_ccm->cbcdr);
  267. writel((reg & (~MXC_CCM_CBCDR_AHB_PODF_MASK)) |
  268. (div << MXC_CCM_CBCDR_AHB_PODF_OFFSET), &mxc_ccm->cbcdr);
  269. }
  270. static void clear_mmdc_ch_mask(void)
  271. {
  272. struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
  273. u32 reg;
  274. reg = readl(&mxc_ccm->ccdr);
  275. /* Clear MMDC channel mask */
  276. if (is_mx6sx() || is_mx6ul() || is_mx6ull() || is_mx6sl() || is_mx6sll())
  277. reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK);
  278. else
  279. reg &= ~(MXC_CCM_CCDR_MMDC_CH1_HS_MASK | MXC_CCM_CCDR_MMDC_CH0_HS_MASK);
  280. writel(reg, &mxc_ccm->ccdr);
  281. }
  282. #define OCOTP_MEM0_REFTOP_TRIM_SHIFT 8
  283. static void init_bandgap(void)
  284. {
  285. struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
  286. struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
  287. struct fuse_bank *bank = &ocotp->bank[1];
  288. struct fuse_bank1_regs *fuse =
  289. (struct fuse_bank1_regs *)bank->fuse_regs;
  290. uint32_t val;
  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. * On i.MX6ULL,we need to set VBGADJ bits according to the
  304. * REFTOP_TRIM[3:0] in fuse table
  305. * 000 - set REFTOP_VBGADJ[2:0] to 3b'110,
  306. * 110 - set REFTOP_VBGADJ[2:0] to 3b'000,
  307. * 001 - set REFTOP_VBGADJ[2:0] to 3b'001,
  308. * 010 - set REFTOP_VBGADJ[2:0] to 3b'010,
  309. * 011 - set REFTOP_VBGADJ[2:0] to 3b'011,
  310. * 100 - set REFTOP_VBGADJ[2:0] to 3b'100,
  311. * 101 - set REFTOP_VBGADJ[2:0] to 3b'101,
  312. * 111 - set REFTOP_VBGADJ[2:0] to 3b'111,
  313. */
  314. if (is_mx6ull()) {
  315. val = readl(&fuse->mem0);
  316. val >>= OCOTP_MEM0_REFTOP_TRIM_SHIFT;
  317. val &= 0x7;
  318. writel(val << BM_ANADIG_ANA_MISC0_REFTOP_VBGADJ_SHIFT,
  319. &anatop->ana_misc0_set);
  320. }
  321. }
  322. int arch_cpu_init(void)
  323. {
  324. struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
  325. init_aips();
  326. /* Need to clear MMDC_CHx_MASK to make warm reset work. */
  327. clear_mmdc_ch_mask();
  328. /*
  329. * Disable self-bias circuit in the analog bandap.
  330. * The self-bias circuit is used by the bandgap during startup.
  331. * This bit should be set after the bandgap has initialized.
  332. */
  333. init_bandgap();
  334. if (!is_mx6ul() && !is_mx6ull()) {
  335. /*
  336. * When low freq boot is enabled, ROM will not set AHB
  337. * freq, so we need to ensure AHB freq is 132MHz in such
  338. * scenario.
  339. *
  340. * To i.MX6UL, when power up, default ARM core and
  341. * AHB rate is 396M and 132M.
  342. */
  343. if (mxc_get_clock(MXC_ARM_CLK) == 396000000)
  344. set_ahb_rate(132000000);
  345. }
  346. if (is_mx6ul()) {
  347. if (is_soc_rev(CHIP_REV_1_0) == 0) {
  348. /*
  349. * According to the design team's requirement on
  350. * i.MX6UL,the PMIC_STBY_REQ PAD should be configured
  351. * as open drain 100K (0x0000b8a0).
  352. * Only exists on TO1.0
  353. */
  354. writel(0x0000b8a0, IOMUXC_BASE_ADDR + 0x29c);
  355. } else {
  356. /*
  357. * From TO1.1, SNVS adds internal pull up control
  358. * for POR_B, the register filed is GPBIT[1:0],
  359. * after system boot up, it can be set to 2b'01
  360. * to disable internal pull up.It can save about
  361. * 30uA power in SNVS mode.
  362. */
  363. writel((readl(MX6UL_SNVS_LP_BASE_ADDR + 0x10) &
  364. (~0x1400)) | 0x400,
  365. MX6UL_SNVS_LP_BASE_ADDR + 0x10);
  366. }
  367. }
  368. if (is_mx6ull()) {
  369. /*
  370. * GPBIT[1:0] is suggested to set to 2'b11:
  371. * 2'b00 : always PUP100K
  372. * 2'b01 : PUP100K when PMIC_ON_REQ or SOC_NOT_FAIL
  373. * 2'b10 : always disable PUP100K
  374. * 2'b11 : PDN100K when SOC_FAIL, PUP100K when SOC_NOT_FAIL
  375. * register offset is different from i.MX6UL, since
  376. * i.MX6UL is fixed by ECO.
  377. */
  378. writel(readl(MX6UL_SNVS_LP_BASE_ADDR) |
  379. 0x3, MX6UL_SNVS_LP_BASE_ADDR);
  380. }
  381. /* Set perclk to source from OSC 24MHz */
  382. if (is_mx6sl())
  383. setbits_le32(&ccm->cscmr1, MXC_CCM_CSCMR1_PER_CLK_SEL_MASK);
  384. imx_wdog_disable_powerdown(); /* Disable PDE bit of WMCR register */
  385. if (is_mx6sx())
  386. setbits_le32(&ccm->cscdr1, MXC_CCM_CSCDR1_UART_CLK_SEL);
  387. init_src();
  388. return 0;
  389. }
  390. #ifdef CONFIG_ENV_IS_IN_MMC
  391. __weak int board_mmc_get_env_dev(int devno)
  392. {
  393. return CONFIG_SYS_MMC_ENV_DEV;
  394. }
  395. static int mmc_get_boot_dev(void)
  396. {
  397. struct src *src_regs = (struct src *)SRC_BASE_ADDR;
  398. u32 soc_sbmr = readl(&src_regs->sbmr1);
  399. u32 bootsel;
  400. int devno;
  401. /*
  402. * Refer to
  403. * "i.MX 6Dual/6Quad Applications Processor Reference Manual"
  404. * Chapter "8.5.3.1 Expansion Device eFUSE Configuration"
  405. * i.MX6SL/SX/UL has same layout.
  406. */
  407. bootsel = (soc_sbmr & 0x000000FF) >> 6;
  408. /* No boot from sd/mmc */
  409. if (bootsel != 1)
  410. return -1;
  411. /* BOOT_CFG2[3] and BOOT_CFG2[4] */
  412. devno = (soc_sbmr & 0x00001800) >> 11;
  413. return devno;
  414. }
  415. int mmc_get_env_dev(void)
  416. {
  417. int devno = mmc_get_boot_dev();
  418. /* If not boot from sd/mmc, use default value */
  419. if (devno < 0)
  420. return CONFIG_SYS_MMC_ENV_DEV;
  421. return board_mmc_get_env_dev(devno);
  422. }
  423. #ifdef CONFIG_SYS_MMC_ENV_PART
  424. __weak int board_mmc_get_env_part(int devno)
  425. {
  426. return CONFIG_SYS_MMC_ENV_PART;
  427. }
  428. uint mmc_get_env_part(struct mmc *mmc)
  429. {
  430. int devno = mmc_get_boot_dev();
  431. /* If not boot from sd/mmc, use default value */
  432. if (devno < 0)
  433. return CONFIG_SYS_MMC_ENV_PART;
  434. return board_mmc_get_env_part(devno);
  435. }
  436. #endif
  437. #endif
  438. int board_postclk_init(void)
  439. {
  440. /* NO LDO SOC on i.MX6SLL */
  441. if (is_mx6sll())
  442. return 0;
  443. set_ldo_voltage(LDO_SOC, 1175); /* Set VDDSOC to 1.175V */
  444. return 0;
  445. }
  446. #ifndef CONFIG_SPL_BUILD
  447. /*
  448. * cfg_val will be used for
  449. * Boot_cfg4[7:0]:Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
  450. * After reset, if GPR10[28] is 1, ROM will use GPR9[25:0]
  451. * instead of SBMR1 to determine the boot device.
  452. */
  453. const struct boot_mode soc_boot_modes[] = {
  454. {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)},
  455. /* reserved value should start rom usb */
  456. #if defined(CONFIG_MX6UL) || defined(CONFIG_MX6ULL)
  457. {"usb", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
  458. #else
  459. {"usb", MAKE_CFGVAL(0x10, 0x00, 0x00, 0x00)},
  460. #endif
  461. {"sata", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
  462. {"ecspi1:0", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x08)},
  463. {"ecspi1:1", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x18)},
  464. {"ecspi1:2", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x28)},
  465. {"ecspi1:3", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x38)},
  466. /* 4 bit bus width */
  467. {"esdhc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
  468. {"esdhc2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
  469. {"esdhc3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
  470. {"esdhc4", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
  471. {NULL, 0},
  472. };
  473. #endif
  474. void reset_misc(void)
  475. {
  476. #ifdef CONFIG_VIDEO_MXS
  477. lcdif_power_down();
  478. #endif
  479. }
  480. void s_init(void)
  481. {
  482. struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
  483. struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
  484. u32 mask480;
  485. u32 mask528;
  486. u32 reg, periph1, periph2;
  487. if (is_mx6sx() || is_mx6ul() || is_mx6ull() || is_mx6sll())
  488. return;
  489. /* Due to hardware limitation, on MX6Q we need to gate/ungate all PFDs
  490. * to make sure PFD is working right, otherwise, PFDs may
  491. * not output clock after reset, MX6DL and MX6SL have added 396M pfd
  492. * workaround in ROM code, as bus clock need it
  493. */
  494. mask480 = ANATOP_PFD_CLKGATE_MASK(0) |
  495. ANATOP_PFD_CLKGATE_MASK(1) |
  496. ANATOP_PFD_CLKGATE_MASK(2) |
  497. ANATOP_PFD_CLKGATE_MASK(3);
  498. mask528 = ANATOP_PFD_CLKGATE_MASK(1) |
  499. ANATOP_PFD_CLKGATE_MASK(3);
  500. reg = readl(&ccm->cbcmr);
  501. periph2 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_MASK)
  502. >> MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_OFFSET);
  503. periph1 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK)
  504. >> MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_OFFSET);
  505. /* Checking if PLL2 PFD0 or PLL2 PFD2 is using for periph clock */
  506. if ((periph2 != 0x2) && (periph1 != 0x2))
  507. mask528 |= ANATOP_PFD_CLKGATE_MASK(0);
  508. if ((periph2 != 0x1) && (periph1 != 0x1) &&
  509. (periph2 != 0x3) && (periph1 != 0x3))
  510. mask528 |= ANATOP_PFD_CLKGATE_MASK(2);
  511. writel(mask480, &anatop->pfd_480_set);
  512. writel(mask528, &anatop->pfd_528_set);
  513. writel(mask480, &anatop->pfd_480_clr);
  514. writel(mask528, &anatop->pfd_528_clr);
  515. }
  516. #ifdef CONFIG_IMX_HDMI
  517. void imx_enable_hdmi_phy(void)
  518. {
  519. struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
  520. u8 reg;
  521. reg = readb(&hdmi->phy_conf0);
  522. reg |= HDMI_PHY_CONF0_PDZ_MASK;
  523. writeb(reg, &hdmi->phy_conf0);
  524. udelay(3000);
  525. reg |= HDMI_PHY_CONF0_ENTMDS_MASK;
  526. writeb(reg, &hdmi->phy_conf0);
  527. udelay(3000);
  528. reg |= HDMI_PHY_CONF0_GEN2_TXPWRON_MASK;
  529. writeb(reg, &hdmi->phy_conf0);
  530. writeb(HDMI_MC_PHYRSTZ_ASSERT, &hdmi->mc_phyrstz);
  531. }
  532. void imx_setup_hdmi(void)
  533. {
  534. struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
  535. struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
  536. int reg, count;
  537. u8 val;
  538. /* Turn on HDMI PHY clock */
  539. reg = readl(&mxc_ccm->CCGR2);
  540. reg |= MXC_CCM_CCGR2_HDMI_TX_IAHBCLK_MASK|
  541. MXC_CCM_CCGR2_HDMI_TX_ISFRCLK_MASK;
  542. writel(reg, &mxc_ccm->CCGR2);
  543. writeb(HDMI_MC_PHYRSTZ_DEASSERT, &hdmi->mc_phyrstz);
  544. reg = readl(&mxc_ccm->chsccdr);
  545. reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK|
  546. MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK|
  547. MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK);
  548. reg |= (CHSCCDR_PODF_DIVIDE_BY_3
  549. << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET)
  550. |(CHSCCDR_IPU_PRE_CLK_540M_PFD
  551. << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET);
  552. writel(reg, &mxc_ccm->chsccdr);
  553. /* Clear the overflow condition */
  554. if (readb(&hdmi->ih_fc_stat2) & HDMI_IH_FC_STAT2_OVERFLOW_MASK) {
  555. /* TMDS software reset */
  556. writeb((u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, &hdmi->mc_swrstz);
  557. val = readb(&hdmi->fc_invidconf);
  558. /* Need minimum 3 times to write to clear the register */
  559. for (count = 0 ; count < 5 ; count++)
  560. writeb(val, &hdmi->fc_invidconf);
  561. }
  562. }
  563. #endif
  564. void gpr_init(void)
  565. {
  566. struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
  567. /* enable AXI cache for VDOA/VPU/IPU */
  568. writel(0xF00000CF, &iomux->gpr[4]);
  569. if (is_mx6dqp()) {
  570. /* set IPU AXI-id1 Qos=0x1 AXI-id0/2/3 Qos=0x7 */
  571. writel(0x77177717, &iomux->gpr[6]);
  572. writel(0x77177717, &iomux->gpr[7]);
  573. } else {
  574. /* set IPU AXI-id0 Qos=0xf(bypass) AXI-id1 Qos=0x7 */
  575. writel(0x007F007F, &iomux->gpr[6]);
  576. writel(0x007F007F, &iomux->gpr[7]);
  577. }
  578. }