soc.c 17 KB

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