clock_manager.c 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2013-2017 Altera Corporation <www.altera.com>
  4. */
  5. #include <common.h>
  6. #include <wait_bit.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. void cm_wait_for_lock(u32 mask)
  13. {
  14. u32 inter_val;
  15. u32 retry = 0;
  16. do {
  17. #if defined(CONFIG_TARGET_SOCFPGA_GEN5)
  18. inter_val = readl(&clock_manager_base->inter) & mask;
  19. #else
  20. inter_val = readl(&clock_manager_base->stat) & mask;
  21. #endif
  22. /* Wait for stable lock */
  23. if (inter_val == mask)
  24. retry++;
  25. else
  26. retry = 0;
  27. if (retry >= 10)
  28. break;
  29. } while (1);
  30. }
  31. /* function to poll in the fsm busy bit */
  32. int cm_wait_for_fsm(void)
  33. {
  34. return wait_for_bit_le32(&clock_manager_base->stat,
  35. CLKMGR_STAT_BUSY, false, 20000, false);
  36. }
  37. int set_cpu_clk_info(void)
  38. {
  39. /* Calculate the clock frequencies required for drivers */
  40. cm_get_l4_sp_clk_hz();
  41. cm_get_mmc_controller_clk_hz();
  42. gd->bd->bi_arm_freq = cm_get_mpu_clk_hz() / 1000000;
  43. gd->bd->bi_dsp_freq = 0;
  44. #if defined(CONFIG_TARGET_SOCFPGA_GEN5)
  45. gd->bd->bi_ddr_freq = cm_get_sdram_clk_hz() / 1000000;
  46. #else
  47. gd->bd->bi_ddr_freq = 0;
  48. #endif
  49. return 0;
  50. }
  51. #ifndef CONFIG_SPL_BUILD
  52. static int do_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  53. {
  54. cm_print_clock_quick_summary();
  55. return 0;
  56. }
  57. U_BOOT_CMD(
  58. clocks, CONFIG_SYS_MAXARGS, 1, do_showclocks,
  59. "display clocks",
  60. ""
  61. );
  62. #endif