clock_manager.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558
  1. /*
  2. * Copyright (C) 2013 Altera Corporation <www.altera.com>
  3. *
  4. * SPDX-License-Identifier: GPL-2.0+
  5. */
  6. #include <common.h>
  7. #include <asm/io.h>
  8. #include <asm/arch/clock_manager.h>
  9. DECLARE_GLOBAL_DATA_PTR;
  10. static const struct socfpga_clock_manager *clock_manager_base =
  11. (struct socfpga_clock_manager *)SOCFPGA_CLKMGR_ADDRESS;
  12. static void cm_wait_for_lock(uint32_t mask)
  13. {
  14. register uint32_t inter_val;
  15. uint32_t retry = 0;
  16. do {
  17. inter_val = readl(&clock_manager_base->inter) & mask;
  18. if (inter_val == mask)
  19. retry++;
  20. else
  21. retry = 0;
  22. if (retry >= 10)
  23. break;
  24. } while (1);
  25. }
  26. /* function to poll in the fsm busy bit */
  27. static void cm_wait_for_fsm(void)
  28. {
  29. while (readl(&clock_manager_base->stat) & CLKMGR_STAT_BUSY)
  30. ;
  31. }
  32. /*
  33. * function to write the bypass register which requires a poll of the
  34. * busy bit
  35. */
  36. static void cm_write_bypass(uint32_t val)
  37. {
  38. writel(val, &clock_manager_base->bypass);
  39. cm_wait_for_fsm();
  40. }
  41. /* function to write the ctrl register which requires a poll of the busy bit */
  42. static void cm_write_ctrl(uint32_t val)
  43. {
  44. writel(val, &clock_manager_base->ctrl);
  45. cm_wait_for_fsm();
  46. }
  47. /* function to write a clock register that has phase information */
  48. static void cm_write_with_phase(uint32_t value,
  49. uint32_t reg_address, uint32_t mask)
  50. {
  51. /* poll until phase is zero */
  52. while (readl(reg_address) & mask)
  53. ;
  54. writel(value, reg_address);
  55. while (readl(reg_address) & mask)
  56. ;
  57. }
  58. /*
  59. * Setup clocks while making no assumptions about previous state of the clocks.
  60. *
  61. * Start by being paranoid and gate all sw managed clocks
  62. * Put all plls in bypass
  63. * Put all plls VCO registers back to reset value (bandgap power down).
  64. * Put peripheral and main pll src to reset value to avoid glitch.
  65. * Delay 5 us.
  66. * Deassert bandgap power down and set numerator and denominator
  67. * Start 7 us timer.
  68. * set internal dividers
  69. * Wait for 7 us timer.
  70. * Enable plls
  71. * Set external dividers while plls are locking
  72. * Wait for pll lock
  73. * Assert/deassert outreset all.
  74. * Take all pll's out of bypass
  75. * Clear safe mode
  76. * set source main and peripheral clocks
  77. * Ungate clocks
  78. */
  79. void cm_basic_init(const struct cm_config * const cfg)
  80. {
  81. unsigned long end;
  82. /* Start by being paranoid and gate all sw managed clocks */
  83. /*
  84. * We need to disable nandclk
  85. * and then do another apb access before disabling
  86. * gatting off the rest of the periperal clocks.
  87. */
  88. writel(~CLKMGR_PERPLLGRP_EN_NANDCLK_MASK &
  89. readl(&clock_manager_base->per_pll.en),
  90. &clock_manager_base->per_pll.en);
  91. /* DO NOT GATE OFF DEBUG CLOCKS & BRIDGE CLOCKS */
  92. writel(CLKMGR_MAINPLLGRP_EN_DBGTIMERCLK_MASK |
  93. CLKMGR_MAINPLLGRP_EN_DBGTRACECLK_MASK |
  94. CLKMGR_MAINPLLGRP_EN_DBGCLK_MASK |
  95. CLKMGR_MAINPLLGRP_EN_DBGATCLK_MASK |
  96. CLKMGR_MAINPLLGRP_EN_S2FUSER0CLK_MASK |
  97. CLKMGR_MAINPLLGRP_EN_L4MPCLK_MASK,
  98. &clock_manager_base->main_pll.en);
  99. writel(0, &clock_manager_base->sdr_pll.en);
  100. /* now we can gate off the rest of the peripheral clocks */
  101. writel(0, &clock_manager_base->per_pll.en);
  102. /* Put all plls in bypass */
  103. cm_write_bypass(CLKMGR_BYPASS_PERPLL | CLKMGR_BYPASS_SDRPLL |
  104. CLKMGR_BYPASS_MAINPLL);
  105. /* Put all plls VCO registers back to reset value. */
  106. writel(CLKMGR_MAINPLLGRP_VCO_RESET_VALUE &
  107. ~CLKMGR_MAINPLLGRP_VCO_REGEXTSEL_MASK,
  108. &clock_manager_base->main_pll.vco);
  109. writel(CLKMGR_PERPLLGRP_VCO_RESET_VALUE &
  110. ~CLKMGR_PERPLLGRP_VCO_REGEXTSEL_MASK,
  111. &clock_manager_base->per_pll.vco);
  112. writel(CLKMGR_SDRPLLGRP_VCO_RESET_VALUE &
  113. ~CLKMGR_SDRPLLGRP_VCO_REGEXTSEL_MASK,
  114. &clock_manager_base->sdr_pll.vco);
  115. /*
  116. * The clocks to the flash devices and the L4_MAIN clocks can
  117. * glitch when coming out of safe mode if their source values
  118. * are different from their reset value. So the trick it to
  119. * put them back to their reset state, and change input
  120. * after exiting safe mode but before ungating the clocks.
  121. */
  122. writel(CLKMGR_PERPLLGRP_SRC_RESET_VALUE,
  123. &clock_manager_base->per_pll.src);
  124. writel(CLKMGR_MAINPLLGRP_L4SRC_RESET_VALUE,
  125. &clock_manager_base->main_pll.l4src);
  126. /* read back for the required 5 us delay. */
  127. readl(&clock_manager_base->main_pll.vco);
  128. readl(&clock_manager_base->per_pll.vco);
  129. readl(&clock_manager_base->sdr_pll.vco);
  130. /*
  131. * We made sure bgpwr down was assert for 5 us. Now deassert BG PWR DN
  132. * with numerator and denominator.
  133. */
  134. writel(cfg->main_vco_base, &clock_manager_base->main_pll.vco);
  135. writel(cfg->peri_vco_base, &clock_manager_base->per_pll.vco);
  136. writel(cfg->sdram_vco_base, &clock_manager_base->sdr_pll.vco);
  137. /*
  138. * Time starts here. Must wait 7 us from
  139. * BGPWRDN_SET(0) to VCO_ENABLE_SET(1).
  140. */
  141. end = timer_get_us() + 7;
  142. /* main mpu */
  143. writel(cfg->mpuclk, &clock_manager_base->main_pll.mpuclk);
  144. /* main main clock */
  145. writel(cfg->mainclk, &clock_manager_base->main_pll.mainclk);
  146. /* main for dbg */
  147. writel(cfg->dbgatclk, &clock_manager_base->main_pll.dbgatclk);
  148. /* main for cfgs2fuser0clk */
  149. writel(cfg->cfg2fuser0clk,
  150. &clock_manager_base->main_pll.cfgs2fuser0clk);
  151. /* Peri emac0 50 MHz default to RMII */
  152. writel(cfg->emac0clk, &clock_manager_base->per_pll.emac0clk);
  153. /* Peri emac1 50 MHz default to RMII */
  154. writel(cfg->emac1clk, &clock_manager_base->per_pll.emac1clk);
  155. /* Peri QSPI */
  156. writel(cfg->mainqspiclk, &clock_manager_base->main_pll.mainqspiclk);
  157. writel(cfg->perqspiclk, &clock_manager_base->per_pll.perqspiclk);
  158. /* Peri pernandsdmmcclk */
  159. writel(cfg->mainnandsdmmcclk,
  160. &clock_manager_base->main_pll.mainnandsdmmcclk);
  161. writel(cfg->pernandsdmmcclk,
  162. &clock_manager_base->per_pll.pernandsdmmcclk);
  163. /* Peri perbaseclk */
  164. writel(cfg->perbaseclk, &clock_manager_base->per_pll.perbaseclk);
  165. /* Peri s2fuser1clk */
  166. writel(cfg->s2fuser1clk, &clock_manager_base->per_pll.s2fuser1clk);
  167. /* 7 us must have elapsed before we can enable the VCO */
  168. while (timer_get_us() < end)
  169. ;
  170. /* Enable vco */
  171. /* main pll vco */
  172. writel(cfg->main_vco_base | CLKMGR_MAINPLLGRP_VCO_EN,
  173. &clock_manager_base->main_pll.vco);
  174. /* periferal pll */
  175. writel(cfg->peri_vco_base | CLKMGR_MAINPLLGRP_VCO_EN,
  176. &clock_manager_base->per_pll.vco);
  177. /* sdram pll vco */
  178. writel(cfg->sdram_vco_base | CLKMGR_MAINPLLGRP_VCO_EN,
  179. &clock_manager_base->sdr_pll.vco);
  180. /* L3 MP and L3 SP */
  181. writel(cfg->maindiv, &clock_manager_base->main_pll.maindiv);
  182. writel(cfg->dbgdiv, &clock_manager_base->main_pll.dbgdiv);
  183. writel(cfg->tracediv, &clock_manager_base->main_pll.tracediv);
  184. /* L4 MP, L4 SP, can0, and can1 */
  185. writel(cfg->perdiv, &clock_manager_base->per_pll.div);
  186. writel(cfg->gpiodiv, &clock_manager_base->per_pll.gpiodiv);
  187. #define LOCKED_MASK \
  188. (CLKMGR_INTER_SDRPLLLOCKED_MASK | \
  189. CLKMGR_INTER_PERPLLLOCKED_MASK | \
  190. CLKMGR_INTER_MAINPLLLOCKED_MASK)
  191. cm_wait_for_lock(LOCKED_MASK);
  192. /* write the sdram clock counters before toggling outreset all */
  193. writel(cfg->ddrdqsclk & CLKMGR_SDRPLLGRP_DDRDQSCLK_CNT_MASK,
  194. &clock_manager_base->sdr_pll.ddrdqsclk);
  195. writel(cfg->ddr2xdqsclk & CLKMGR_SDRPLLGRP_DDR2XDQSCLK_CNT_MASK,
  196. &clock_manager_base->sdr_pll.ddr2xdqsclk);
  197. writel(cfg->ddrdqclk & CLKMGR_SDRPLLGRP_DDRDQCLK_CNT_MASK,
  198. &clock_manager_base->sdr_pll.ddrdqclk);
  199. writel(cfg->s2fuser2clk & CLKMGR_SDRPLLGRP_S2FUSER2CLK_CNT_MASK,
  200. &clock_manager_base->sdr_pll.s2fuser2clk);
  201. /*
  202. * after locking, but before taking out of bypass
  203. * assert/deassert outresetall
  204. */
  205. uint32_t mainvco = readl(&clock_manager_base->main_pll.vco);
  206. /* assert main outresetall */
  207. writel(mainvco | CLKMGR_MAINPLLGRP_VCO_OUTRESETALL_MASK,
  208. &clock_manager_base->main_pll.vco);
  209. uint32_t periphvco = readl(&clock_manager_base->per_pll.vco);
  210. /* assert pheriph outresetall */
  211. writel(periphvco | CLKMGR_PERPLLGRP_VCO_OUTRESETALL_MASK,
  212. &clock_manager_base->per_pll.vco);
  213. /* assert sdram outresetall */
  214. writel(cfg->sdram_vco_base | CLKMGR_MAINPLLGRP_VCO_EN|
  215. CLKMGR_SDRPLLGRP_VCO_OUTRESETALL,
  216. &clock_manager_base->sdr_pll.vco);
  217. /* deassert main outresetall */
  218. writel(mainvco & ~CLKMGR_MAINPLLGRP_VCO_OUTRESETALL_MASK,
  219. &clock_manager_base->main_pll.vco);
  220. /* deassert pheriph outresetall */
  221. writel(periphvco & ~CLKMGR_PERPLLGRP_VCO_OUTRESETALL_MASK,
  222. &clock_manager_base->per_pll.vco);
  223. /* deassert sdram outresetall */
  224. writel(cfg->sdram_vco_base | CLKMGR_MAINPLLGRP_VCO_EN,
  225. &clock_manager_base->sdr_pll.vco);
  226. /*
  227. * now that we've toggled outreset all, all the clocks
  228. * are aligned nicely; so we can change any phase.
  229. */
  230. cm_write_with_phase(cfg->ddrdqsclk,
  231. (uint32_t)&clock_manager_base->sdr_pll.ddrdqsclk,
  232. CLKMGR_SDRPLLGRP_DDRDQSCLK_PHASE_MASK);
  233. /* SDRAM DDR2XDQSCLK */
  234. cm_write_with_phase(cfg->ddr2xdqsclk,
  235. (uint32_t)&clock_manager_base->sdr_pll.ddr2xdqsclk,
  236. CLKMGR_SDRPLLGRP_DDR2XDQSCLK_PHASE_MASK);
  237. cm_write_with_phase(cfg->ddrdqclk,
  238. (uint32_t)&clock_manager_base->sdr_pll.ddrdqclk,
  239. CLKMGR_SDRPLLGRP_DDRDQCLK_PHASE_MASK);
  240. cm_write_with_phase(cfg->s2fuser2clk,
  241. (uint32_t)&clock_manager_base->sdr_pll.s2fuser2clk,
  242. CLKMGR_SDRPLLGRP_S2FUSER2CLK_PHASE_MASK);
  243. /* Take all three PLLs out of bypass when safe mode is cleared. */
  244. cm_write_bypass(0);
  245. /* clear safe mode */
  246. cm_write_ctrl(readl(&clock_manager_base->ctrl) | CLKMGR_CTRL_SAFEMODE);
  247. /*
  248. * now that safe mode is clear with clocks gated
  249. * it safe to change the source mux for the flashes the the L4_MAIN
  250. */
  251. writel(cfg->persrc, &clock_manager_base->per_pll.src);
  252. writel(cfg->l4src, &clock_manager_base->main_pll.l4src);
  253. /* Now ungate non-hw-managed clocks */
  254. writel(~0, &clock_manager_base->main_pll.en);
  255. writel(~0, &clock_manager_base->per_pll.en);
  256. writel(~0, &clock_manager_base->sdr_pll.en);
  257. /* Clear the loss of lock bits (write 1 to clear) */
  258. writel(CLKMGR_INTER_SDRPLLLOST_MASK | CLKMGR_INTER_PERPLLLOST_MASK |
  259. CLKMGR_INTER_MAINPLLLOST_MASK,
  260. &clock_manager_base->inter);
  261. }
  262. static unsigned int cm_get_main_vco_clk_hz(void)
  263. {
  264. uint32_t reg, clock;
  265. /* get the main VCO clock */
  266. reg = readl(&clock_manager_base->main_pll.vco);
  267. clock = cm_get_osc_clk_hz(1);
  268. clock /= ((reg & CLKMGR_MAINPLLGRP_VCO_DENOM_MASK) >>
  269. CLKMGR_MAINPLLGRP_VCO_DENOM_OFFSET) + 1;
  270. clock *= ((reg & CLKMGR_MAINPLLGRP_VCO_NUMER_MASK) >>
  271. CLKMGR_MAINPLLGRP_VCO_NUMER_OFFSET) + 1;
  272. return clock;
  273. }
  274. static unsigned int cm_get_per_vco_clk_hz(void)
  275. {
  276. uint32_t reg, clock = 0;
  277. /* identify PER PLL clock source */
  278. reg = readl(&clock_manager_base->per_pll.vco);
  279. reg = (reg & CLKMGR_PERPLLGRP_VCO_SSRC_MASK) >>
  280. CLKMGR_PERPLLGRP_VCO_SSRC_OFFSET;
  281. if (reg == CLKMGR_VCO_SSRC_EOSC1)
  282. clock = cm_get_osc_clk_hz(1);
  283. else if (reg == CLKMGR_VCO_SSRC_EOSC2)
  284. clock = cm_get_osc_clk_hz(2);
  285. else if (reg == CLKMGR_VCO_SSRC_F2S)
  286. clock = cm_get_f2s_per_ref_clk_hz();
  287. /* get the PER VCO clock */
  288. reg = readl(&clock_manager_base->per_pll.vco);
  289. clock /= ((reg & CLKMGR_PERPLLGRP_VCO_DENOM_MASK) >>
  290. CLKMGR_PERPLLGRP_VCO_DENOM_OFFSET) + 1;
  291. clock *= ((reg & CLKMGR_PERPLLGRP_VCO_NUMER_MASK) >>
  292. CLKMGR_PERPLLGRP_VCO_NUMER_OFFSET) + 1;
  293. return clock;
  294. }
  295. unsigned long cm_get_mpu_clk_hz(void)
  296. {
  297. uint32_t reg, clock;
  298. clock = cm_get_main_vco_clk_hz();
  299. /* get the MPU clock */
  300. reg = readl(&clock_manager_base->altera.mpuclk);
  301. clock /= (reg + 1);
  302. reg = readl(&clock_manager_base->main_pll.mpuclk);
  303. clock /= (reg + 1);
  304. return clock;
  305. }
  306. unsigned long cm_get_sdram_clk_hz(void)
  307. {
  308. uint32_t reg, clock = 0;
  309. /* identify SDRAM PLL clock source */
  310. reg = readl(&clock_manager_base->sdr_pll.vco);
  311. reg = (reg & CLKMGR_SDRPLLGRP_VCO_SSRC_MASK) >>
  312. CLKMGR_SDRPLLGRP_VCO_SSRC_OFFSET;
  313. if (reg == CLKMGR_VCO_SSRC_EOSC1)
  314. clock = cm_get_osc_clk_hz(1);
  315. else if (reg == CLKMGR_VCO_SSRC_EOSC2)
  316. clock = cm_get_osc_clk_hz(2);
  317. else if (reg == CLKMGR_VCO_SSRC_F2S)
  318. clock = cm_get_f2s_sdr_ref_clk_hz();
  319. /* get the SDRAM VCO clock */
  320. reg = readl(&clock_manager_base->sdr_pll.vco);
  321. clock /= ((reg & CLKMGR_SDRPLLGRP_VCO_DENOM_MASK) >>
  322. CLKMGR_SDRPLLGRP_VCO_DENOM_OFFSET) + 1;
  323. clock *= ((reg & CLKMGR_SDRPLLGRP_VCO_NUMER_MASK) >>
  324. CLKMGR_SDRPLLGRP_VCO_NUMER_OFFSET) + 1;
  325. /* get the SDRAM (DDR_DQS) clock */
  326. reg = readl(&clock_manager_base->sdr_pll.ddrdqsclk);
  327. reg = (reg & CLKMGR_SDRPLLGRP_DDRDQSCLK_CNT_MASK) >>
  328. CLKMGR_SDRPLLGRP_DDRDQSCLK_CNT_OFFSET;
  329. clock /= (reg + 1);
  330. return clock;
  331. }
  332. unsigned int cm_get_l4_sp_clk_hz(void)
  333. {
  334. uint32_t reg, clock = 0;
  335. /* identify the source of L4 SP clock */
  336. reg = readl(&clock_manager_base->main_pll.l4src);
  337. reg = (reg & CLKMGR_MAINPLLGRP_L4SRC_L4SP) >>
  338. CLKMGR_MAINPLLGRP_L4SRC_L4SP_OFFSET;
  339. if (reg == CLKMGR_L4_SP_CLK_SRC_MAINPLL) {
  340. clock = cm_get_main_vco_clk_hz();
  341. /* get the clock prior L4 SP divider (main clk) */
  342. reg = readl(&clock_manager_base->altera.mainclk);
  343. clock /= (reg + 1);
  344. reg = readl(&clock_manager_base->main_pll.mainclk);
  345. clock /= (reg + 1);
  346. } else if (reg == CLKMGR_L4_SP_CLK_SRC_PERPLL) {
  347. clock = cm_get_per_vco_clk_hz();
  348. /* get the clock prior L4 SP divider (periph_base_clk) */
  349. reg = readl(&clock_manager_base->per_pll.perbaseclk);
  350. clock /= (reg + 1);
  351. }
  352. /* get the L4 SP clock which supplied to UART */
  353. reg = readl(&clock_manager_base->main_pll.maindiv);
  354. reg = (reg & CLKMGR_MAINPLLGRP_MAINDIV_L4SPCLK_MASK) >>
  355. CLKMGR_MAINPLLGRP_MAINDIV_L4SPCLK_OFFSET;
  356. clock = clock / (1 << reg);
  357. return clock;
  358. }
  359. unsigned int cm_get_mmc_controller_clk_hz(void)
  360. {
  361. uint32_t reg, clock = 0;
  362. /* identify the source of MMC clock */
  363. reg = readl(&clock_manager_base->per_pll.src);
  364. reg = (reg & CLKMGR_PERPLLGRP_SRC_SDMMC_MASK) >>
  365. CLKMGR_PERPLLGRP_SRC_SDMMC_OFFSET;
  366. if (reg == CLKMGR_SDMMC_CLK_SRC_F2S) {
  367. clock = cm_get_f2s_per_ref_clk_hz();
  368. } else if (reg == CLKMGR_SDMMC_CLK_SRC_MAIN) {
  369. clock = cm_get_main_vco_clk_hz();
  370. /* get the SDMMC clock */
  371. reg = readl(&clock_manager_base->main_pll.mainnandsdmmcclk);
  372. clock /= (reg + 1);
  373. } else if (reg == CLKMGR_SDMMC_CLK_SRC_PER) {
  374. clock = cm_get_per_vco_clk_hz();
  375. /* get the SDMMC clock */
  376. reg = readl(&clock_manager_base->per_pll.pernandsdmmcclk);
  377. clock /= (reg + 1);
  378. }
  379. /* further divide by 4 as we have fixed divider at wrapper */
  380. clock /= 4;
  381. return clock;
  382. }
  383. unsigned int cm_get_qspi_controller_clk_hz(void)
  384. {
  385. uint32_t reg, clock = 0;
  386. /* identify the source of QSPI clock */
  387. reg = readl(&clock_manager_base->per_pll.src);
  388. reg = (reg & CLKMGR_PERPLLGRP_SRC_QSPI_MASK) >>
  389. CLKMGR_PERPLLGRP_SRC_QSPI_OFFSET;
  390. if (reg == CLKMGR_QSPI_CLK_SRC_F2S) {
  391. clock = cm_get_f2s_per_ref_clk_hz();
  392. } else if (reg == CLKMGR_QSPI_CLK_SRC_MAIN) {
  393. clock = cm_get_main_vco_clk_hz();
  394. /* get the qspi clock */
  395. reg = readl(&clock_manager_base->main_pll.mainqspiclk);
  396. clock /= (reg + 1);
  397. } else if (reg == CLKMGR_QSPI_CLK_SRC_PER) {
  398. clock = cm_get_per_vco_clk_hz();
  399. /* get the qspi clock */
  400. reg = readl(&clock_manager_base->per_pll.perqspiclk);
  401. clock /= (reg + 1);
  402. }
  403. return clock;
  404. }
  405. unsigned int cm_get_spi_controller_clk_hz(void)
  406. {
  407. uint32_t reg, clock = 0;
  408. clock = cm_get_per_vco_clk_hz();
  409. /* get the clock prior L4 SP divider (periph_base_clk) */
  410. reg = readl(&clock_manager_base->per_pll.perbaseclk);
  411. clock /= (reg + 1);
  412. return clock;
  413. }
  414. static void cm_print_clock_quick_summary(void)
  415. {
  416. printf("MPU %10ld kHz\n", cm_get_mpu_clk_hz() / 1000);
  417. printf("DDR %10ld kHz\n", cm_get_sdram_clk_hz() / 1000);
  418. printf("EOSC1 %8d kHz\n", cm_get_osc_clk_hz(1) / 1000);
  419. printf("EOSC2 %8d kHz\n", cm_get_osc_clk_hz(2) / 1000);
  420. printf("F2S_SDR_REF %8d kHz\n", cm_get_f2s_sdr_ref_clk_hz() / 1000);
  421. printf("F2S_PER_REF %8d kHz\n", cm_get_f2s_per_ref_clk_hz() / 1000);
  422. printf("MMC %8d kHz\n", cm_get_mmc_controller_clk_hz() / 1000);
  423. printf("QSPI %8d kHz\n", cm_get_qspi_controller_clk_hz() / 1000);
  424. printf("UART %8d kHz\n", cm_get_l4_sp_clk_hz() / 1000);
  425. printf("SPI %8d kHz\n", cm_get_spi_controller_clk_hz() / 1000);
  426. }
  427. int set_cpu_clk_info(void)
  428. {
  429. /* Calculate the clock frequencies required for drivers */
  430. cm_get_l4_sp_clk_hz();
  431. cm_get_mmc_controller_clk_hz();
  432. gd->bd->bi_arm_freq = cm_get_mpu_clk_hz() / 1000000;
  433. gd->bd->bi_dsp_freq = 0;
  434. gd->bd->bi_ddr_freq = cm_get_sdram_clk_hz() / 1000000;
  435. return 0;
  436. }
  437. int do_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  438. {
  439. cm_print_clock_quick_summary();
  440. return 0;
  441. }
  442. U_BOOT_CMD(
  443. clocks, CONFIG_SYS_MAXARGS, 1, do_showclocks,
  444. "display clocks",
  445. ""
  446. );