soc.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497
  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 <asm/armv7.h>
  11. #include <asm/bootm.h>
  12. #include <asm/pl310.h>
  13. #include <asm/errno.h>
  14. #include <asm/io.h>
  15. #include <asm/arch/imx-regs.h>
  16. #include <asm/arch/clock.h>
  17. #include <asm/arch/sys_proto.h>
  18. #include <asm/imx-common/boot_mode.h>
  19. #include <asm/imx-common/dma.h>
  20. #include <stdbool.h>
  21. #include <asm/arch/mxc_hdmi.h>
  22. #include <asm/arch/crm_regs.h>
  23. enum ldo_reg {
  24. LDO_ARM,
  25. LDO_SOC,
  26. LDO_PU,
  27. };
  28. struct scu_regs {
  29. u32 ctrl;
  30. u32 config;
  31. u32 status;
  32. u32 invalidate;
  33. u32 fpga_rev;
  34. };
  35. u32 get_nr_cpus(void)
  36. {
  37. struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
  38. return readl(&scu->config) & 3;
  39. }
  40. u32 get_cpu_rev(void)
  41. {
  42. struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
  43. u32 reg = readl(&anatop->digprog_sololite);
  44. u32 type = ((reg >> 16) & 0xff);
  45. if (type != MXC_CPU_MX6SL) {
  46. reg = readl(&anatop->digprog);
  47. struct scu_regs *scu = (struct scu_regs *)SCU_BASE_ADDR;
  48. u32 cfg = readl(&scu->config) & 3;
  49. type = ((reg >> 16) & 0xff);
  50. if (type == MXC_CPU_MX6DL) {
  51. if (!cfg)
  52. type = MXC_CPU_MX6SOLO;
  53. }
  54. if (type == MXC_CPU_MX6Q) {
  55. if (cfg == 1)
  56. type = MXC_CPU_MX6D;
  57. }
  58. }
  59. reg &= 0xff; /* mx6 silicon revision */
  60. return (type << 12) | (reg + 0x10);
  61. }
  62. #ifdef CONFIG_REVISION_TAG
  63. u32 __weak get_board_rev(void)
  64. {
  65. u32 cpurev = get_cpu_rev();
  66. u32 type = ((cpurev >> 12) & 0xff);
  67. if (type == MXC_CPU_MX6SOLO)
  68. cpurev = (MXC_CPU_MX6DL) << 12 | (cpurev & 0xFFF);
  69. if (type == MXC_CPU_MX6D)
  70. cpurev = (MXC_CPU_MX6Q) << 12 | (cpurev & 0xFFF);
  71. return cpurev;
  72. }
  73. #endif
  74. void init_aips(void)
  75. {
  76. struct aipstz_regs *aips1, *aips2;
  77. #ifdef CONFIG_MX6SX
  78. struct aipstz_regs *aips3;
  79. #endif
  80. aips1 = (struct aipstz_regs *)AIPS1_BASE_ADDR;
  81. aips2 = (struct aipstz_regs *)AIPS2_BASE_ADDR;
  82. #ifdef CONFIG_MX6SX
  83. aips3 = (struct aipstz_regs *)AIPS3_BASE_ADDR;
  84. #endif
  85. /*
  86. * Set all MPROTx to be non-bufferable, trusted for R/W,
  87. * not forced to user-mode.
  88. */
  89. writel(0x77777777, &aips1->mprot0);
  90. writel(0x77777777, &aips1->mprot1);
  91. writel(0x77777777, &aips2->mprot0);
  92. writel(0x77777777, &aips2->mprot1);
  93. /*
  94. * Set all OPACRx to be non-bufferable, not require
  95. * supervisor privilege level for access,allow for
  96. * write access and untrusted master access.
  97. */
  98. writel(0x00000000, &aips1->opacr0);
  99. writel(0x00000000, &aips1->opacr1);
  100. writel(0x00000000, &aips1->opacr2);
  101. writel(0x00000000, &aips1->opacr3);
  102. writel(0x00000000, &aips1->opacr4);
  103. writel(0x00000000, &aips2->opacr0);
  104. writel(0x00000000, &aips2->opacr1);
  105. writel(0x00000000, &aips2->opacr2);
  106. writel(0x00000000, &aips2->opacr3);
  107. writel(0x00000000, &aips2->opacr4);
  108. #ifdef CONFIG_MX6SX
  109. /*
  110. * Set all MPROTx to be non-bufferable, trusted for R/W,
  111. * not forced to user-mode.
  112. */
  113. writel(0x77777777, &aips3->mprot0);
  114. writel(0x77777777, &aips3->mprot1);
  115. /*
  116. * Set all OPACRx to be non-bufferable, not require
  117. * supervisor privilege level for access,allow for
  118. * write access and untrusted master access.
  119. */
  120. writel(0x00000000, &aips3->opacr0);
  121. writel(0x00000000, &aips3->opacr1);
  122. writel(0x00000000, &aips3->opacr2);
  123. writel(0x00000000, &aips3->opacr3);
  124. writel(0x00000000, &aips3->opacr4);
  125. #endif
  126. }
  127. static void clear_ldo_ramp(void)
  128. {
  129. struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
  130. int reg;
  131. /* ROM may modify LDO ramp up time according to fuse setting, so in
  132. * order to be in the safe side we neeed to reset these settings to
  133. * match the reset value: 0'b00
  134. */
  135. reg = readl(&anatop->ana_misc2);
  136. reg &= ~(0x3f << 24);
  137. writel(reg, &anatop->ana_misc2);
  138. }
  139. /*
  140. * Set the PMU_REG_CORE register
  141. *
  142. * Set LDO_SOC/PU/ARM regulators to the specified millivolt level.
  143. * Possible values are from 0.725V to 1.450V in steps of
  144. * 0.025V (25mV).
  145. */
  146. static int set_ldo_voltage(enum ldo_reg ldo, u32 mv)
  147. {
  148. struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
  149. u32 val, step, old, reg = readl(&anatop->reg_core);
  150. u8 shift;
  151. if (mv < 725)
  152. val = 0x00; /* Power gated off */
  153. else if (mv > 1450)
  154. val = 0x1F; /* Power FET switched full on. No regulation */
  155. else
  156. val = (mv - 700) / 25;
  157. clear_ldo_ramp();
  158. switch (ldo) {
  159. case LDO_SOC:
  160. shift = 18;
  161. break;
  162. case LDO_PU:
  163. shift = 9;
  164. break;
  165. case LDO_ARM:
  166. shift = 0;
  167. break;
  168. default:
  169. return -EINVAL;
  170. }
  171. old = (reg & (0x1F << shift)) >> shift;
  172. step = abs(val - old);
  173. if (step == 0)
  174. return 0;
  175. reg = (reg & ~(0x1F << shift)) | (val << shift);
  176. writel(reg, &anatop->reg_core);
  177. /*
  178. * The LDO ramp-up is based on 64 clock cycles of 24 MHz = 2.6 us per
  179. * step
  180. */
  181. udelay(3 * step);
  182. return 0;
  183. }
  184. static void imx_set_wdog_powerdown(bool enable)
  185. {
  186. struct wdog_regs *wdog1 = (struct wdog_regs *)WDOG1_BASE_ADDR;
  187. struct wdog_regs *wdog2 = (struct wdog_regs *)WDOG2_BASE_ADDR;
  188. /* Write to the PDE (Power Down Enable) bit */
  189. writew(enable, &wdog1->wmcr);
  190. writew(enable, &wdog2->wmcr);
  191. }
  192. static void set_ahb_rate(u32 val)
  193. {
  194. struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
  195. u32 reg, div;
  196. div = get_periph_clk() / val - 1;
  197. reg = readl(&mxc_ccm->cbcdr);
  198. writel((reg & (~MXC_CCM_CBCDR_AHB_PODF_MASK)) |
  199. (div << MXC_CCM_CBCDR_AHB_PODF_OFFSET), &mxc_ccm->cbcdr);
  200. }
  201. static void clear_mmdc_ch_mask(void)
  202. {
  203. struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
  204. /* Clear MMDC channel mask */
  205. writel(0, &mxc_ccm->ccdr);
  206. }
  207. int arch_cpu_init(void)
  208. {
  209. init_aips();
  210. /* Need to clear MMDC_CHx_MASK to make warm reset work. */
  211. clear_mmdc_ch_mask();
  212. /*
  213. * When low freq boot is enabled, ROM will not set AHB
  214. * freq, so we need to ensure AHB freq is 132MHz in such
  215. * scenario.
  216. */
  217. if (mxc_get_clock(MXC_ARM_CLK) == 396000000)
  218. set_ahb_rate(132000000);
  219. imx_set_wdog_powerdown(false); /* Disable PDE bit of WMCR register */
  220. #ifdef CONFIG_APBH_DMA
  221. /* Start APBH DMA */
  222. mxs_dma_init();
  223. #endif
  224. return 0;
  225. }
  226. int board_postclk_init(void)
  227. {
  228. set_ldo_voltage(LDO_SOC, 1175); /* Set VDDSOC to 1.175V */
  229. return 0;
  230. }
  231. #ifndef CONFIG_SYS_DCACHE_OFF
  232. void enable_caches(void)
  233. {
  234. #if defined(CONFIG_SYS_ARM_CACHE_WRITETHROUGH)
  235. enum dcache_option option = DCACHE_WRITETHROUGH;
  236. #else
  237. enum dcache_option option = DCACHE_WRITEBACK;
  238. #endif
  239. /* Avoid random hang when download by usb */
  240. invalidate_dcache_all();
  241. /* Enable D-cache. I-cache is already enabled in start.S */
  242. dcache_enable();
  243. /* Enable caching on OCRAM and ROM */
  244. mmu_set_region_dcache_behaviour(ROMCP_ARB_BASE_ADDR,
  245. ROMCP_ARB_END_ADDR,
  246. option);
  247. mmu_set_region_dcache_behaviour(IRAM_BASE_ADDR,
  248. IRAM_SIZE,
  249. option);
  250. }
  251. #endif
  252. #if defined(CONFIG_FEC_MXC)
  253. void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
  254. {
  255. struct ocotp_regs *ocotp = (struct ocotp_regs *)OCOTP_BASE_ADDR;
  256. struct fuse_bank *bank = &ocotp->bank[4];
  257. struct fuse_bank4_regs *fuse =
  258. (struct fuse_bank4_regs *)bank->fuse_regs;
  259. u32 value = readl(&fuse->mac_addr_high);
  260. mac[0] = (value >> 8);
  261. mac[1] = value ;
  262. value = readl(&fuse->mac_addr_low);
  263. mac[2] = value >> 24 ;
  264. mac[3] = value >> 16 ;
  265. mac[4] = value >> 8 ;
  266. mac[5] = value ;
  267. }
  268. #endif
  269. void boot_mode_apply(unsigned cfg_val)
  270. {
  271. unsigned reg;
  272. struct src *psrc = (struct src *)SRC_BASE_ADDR;
  273. writel(cfg_val, &psrc->gpr9);
  274. reg = readl(&psrc->gpr10);
  275. if (cfg_val)
  276. reg |= 1 << 28;
  277. else
  278. reg &= ~(1 << 28);
  279. writel(reg, &psrc->gpr10);
  280. }
  281. /*
  282. * cfg_val will be used for
  283. * Boot_cfg4[7:0]:Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
  284. * After reset, if GPR10[28] is 1, ROM will copy GPR9[25:0]
  285. * to SBMR1, which will determine the boot device.
  286. */
  287. const struct boot_mode soc_boot_modes[] = {
  288. {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)},
  289. /* reserved value should start rom usb */
  290. {"usb", MAKE_CFGVAL(0x01, 0x00, 0x00, 0x00)},
  291. {"sata", MAKE_CFGVAL(0x20, 0x00, 0x00, 0x00)},
  292. {"ecspi1:0", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x08)},
  293. {"ecspi1:1", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x18)},
  294. {"ecspi1:2", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x28)},
  295. {"ecspi1:3", MAKE_CFGVAL(0x30, 0x00, 0x00, 0x38)},
  296. /* 4 bit bus width */
  297. {"esdhc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x00)},
  298. {"esdhc2", MAKE_CFGVAL(0x40, 0x28, 0x00, 0x00)},
  299. {"esdhc3", MAKE_CFGVAL(0x40, 0x30, 0x00, 0x00)},
  300. {"esdhc4", MAKE_CFGVAL(0x40, 0x38, 0x00, 0x00)},
  301. {NULL, 0},
  302. };
  303. void s_init(void)
  304. {
  305. struct anatop_regs *anatop = (struct anatop_regs *)ANATOP_BASE_ADDR;
  306. struct mxc_ccm_reg *ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
  307. u32 mask480;
  308. u32 mask528;
  309. u32 reg, periph1, periph2;
  310. if (is_cpu_type(MXC_CPU_MX6SX))
  311. return;
  312. /* Due to hardware limitation, on MX6Q we need to gate/ungate all PFDs
  313. * to make sure PFD is working right, otherwise, PFDs may
  314. * not output clock after reset, MX6DL and MX6SL have added 396M pfd
  315. * workaround in ROM code, as bus clock need it
  316. */
  317. mask480 = ANATOP_PFD_CLKGATE_MASK(0) |
  318. ANATOP_PFD_CLKGATE_MASK(1) |
  319. ANATOP_PFD_CLKGATE_MASK(2) |
  320. ANATOP_PFD_CLKGATE_MASK(3);
  321. mask528 = ANATOP_PFD_CLKGATE_MASK(1) |
  322. ANATOP_PFD_CLKGATE_MASK(3);
  323. reg = readl(&ccm->cbcmr);
  324. periph2 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_MASK)
  325. >> MXC_CCM_CBCMR_PRE_PERIPH2_CLK_SEL_OFFSET);
  326. periph1 = ((reg & MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_MASK)
  327. >> MXC_CCM_CBCMR_PRE_PERIPH_CLK_SEL_OFFSET);
  328. /* Checking if PLL2 PFD0 or PLL2 PFD2 is using for periph clock */
  329. if ((periph2 != 0x2) && (periph1 != 0x2))
  330. mask528 |= ANATOP_PFD_CLKGATE_MASK(0);
  331. if ((periph2 != 0x1) && (periph1 != 0x1) &&
  332. (periph2 != 0x3) && (periph1 != 0x3))
  333. mask528 |= ANATOP_PFD_CLKGATE_MASK(2);
  334. writel(mask480, &anatop->pfd_480_set);
  335. writel(mask528, &anatop->pfd_528_set);
  336. writel(mask480, &anatop->pfd_480_clr);
  337. writel(mask528, &anatop->pfd_528_clr);
  338. }
  339. #ifdef CONFIG_IMX_HDMI
  340. void imx_enable_hdmi_phy(void)
  341. {
  342. struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
  343. u8 reg;
  344. reg = readb(&hdmi->phy_conf0);
  345. reg |= HDMI_PHY_CONF0_PDZ_MASK;
  346. writeb(reg, &hdmi->phy_conf0);
  347. udelay(3000);
  348. reg |= HDMI_PHY_CONF0_ENTMDS_MASK;
  349. writeb(reg, &hdmi->phy_conf0);
  350. udelay(3000);
  351. reg |= HDMI_PHY_CONF0_GEN2_TXPWRON_MASK;
  352. writeb(reg, &hdmi->phy_conf0);
  353. writeb(HDMI_MC_PHYRSTZ_ASSERT, &hdmi->mc_phyrstz);
  354. }
  355. void imx_setup_hdmi(void)
  356. {
  357. struct mxc_ccm_reg *mxc_ccm = (struct mxc_ccm_reg *)CCM_BASE_ADDR;
  358. struct hdmi_regs *hdmi = (struct hdmi_regs *)HDMI_ARB_BASE_ADDR;
  359. int reg;
  360. /* Turn on HDMI PHY clock */
  361. reg = readl(&mxc_ccm->CCGR2);
  362. reg |= MXC_CCM_CCGR2_HDMI_TX_IAHBCLK_MASK|
  363. MXC_CCM_CCGR2_HDMI_TX_ISFRCLK_MASK;
  364. writel(reg, &mxc_ccm->CCGR2);
  365. writeb(HDMI_MC_PHYRSTZ_DEASSERT, &hdmi->mc_phyrstz);
  366. reg = readl(&mxc_ccm->chsccdr);
  367. reg &= ~(MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_MASK|
  368. MXC_CCM_CHSCCDR_IPU1_DI0_PODF_MASK|
  369. MXC_CCM_CHSCCDR_IPU1_DI0_CLK_SEL_MASK);
  370. reg |= (CHSCCDR_PODF_DIVIDE_BY_3
  371. << MXC_CCM_CHSCCDR_IPU1_DI0_PODF_OFFSET)
  372. |(CHSCCDR_IPU_PRE_CLK_540M_PFD
  373. << MXC_CCM_CHSCCDR_IPU1_DI0_PRE_CLK_SEL_OFFSET);
  374. writel(reg, &mxc_ccm->chsccdr);
  375. }
  376. #endif
  377. #ifndef CONFIG_SYS_L2CACHE_OFF
  378. #define IOMUXC_GPR11_L2CACHE_AS_OCRAM 0x00000002
  379. void v7_outer_cache_enable(void)
  380. {
  381. struct pl310_regs *const pl310 = (struct pl310_regs *)L2_PL310_BASE;
  382. unsigned int val;
  383. #if defined CONFIG_MX6SL
  384. struct iomuxc *iomux = (struct iomuxc *)IOMUXC_BASE_ADDR;
  385. val = readl(&iomux->gpr[11]);
  386. if (val & IOMUXC_GPR11_L2CACHE_AS_OCRAM) {
  387. /* L2 cache configured as OCRAM, reset it */
  388. val &= ~IOMUXC_GPR11_L2CACHE_AS_OCRAM;
  389. writel(val, &iomux->gpr[11]);
  390. }
  391. #endif
  392. /* Must disable the L2 before changing the latency parameters */
  393. clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
  394. writel(0x132, &pl310->pl310_tag_latency_ctrl);
  395. writel(0x132, &pl310->pl310_data_latency_ctrl);
  396. val = readl(&pl310->pl310_prefetch_ctrl);
  397. /* Turn on the L2 I/D prefetch */
  398. val |= 0x30000000;
  399. /*
  400. * The L2 cache controller(PL310) version on the i.MX6D/Q is r3p1-50rel0
  401. * The L2 cache controller(PL310) version on the i.MX6DL/SOLO/SL is r3p2
  402. * But according to ARM PL310 errata: 752271
  403. * ID: 752271: Double linefill feature can cause data corruption
  404. * Fault Status: Present in: r3p0, r3p1, r3p1-50rel0. Fixed in r3p2
  405. * Workaround: The only workaround to this erratum is to disable the
  406. * double linefill feature. This is the default behavior.
  407. */
  408. #ifndef CONFIG_MX6Q
  409. val |= 0x40800000;
  410. #endif
  411. writel(val, &pl310->pl310_prefetch_ctrl);
  412. val = readl(&pl310->pl310_power_ctrl);
  413. val |= L2X0_DYNAMIC_CLK_GATING_EN;
  414. val |= L2X0_STNDBY_MODE_EN;
  415. writel(val, &pl310->pl310_power_ctrl);
  416. setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
  417. }
  418. void v7_outer_cache_disable(void)
  419. {
  420. struct pl310_regs *const pl310 = (struct pl310_regs *)L2_PL310_BASE;
  421. clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
  422. }
  423. #endif /* !CONFIG_SYS_L2CACHE_OFF */