clock_manager.c 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  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. #if defined(CONFIG_TARGET_SOCFPGA_GEN5)
  40. /* Calculate the clock frequencies required for drivers */
  41. cm_get_l4_sp_clk_hz();
  42. cm_get_mmc_controller_clk_hz();
  43. #endif
  44. gd->bd->bi_arm_freq = cm_get_mpu_clk_hz() / 1000000;
  45. gd->bd->bi_dsp_freq = 0;
  46. #if defined(CONFIG_TARGET_SOCFPGA_GEN5)
  47. gd->bd->bi_ddr_freq = cm_get_sdram_clk_hz() / 1000000;
  48. #else
  49. gd->bd->bi_ddr_freq = 0;
  50. #endif
  51. return 0;
  52. }
  53. #ifndef CONFIG_SPL_BUILD
  54. static int do_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  55. {
  56. cm_print_clock_quick_summary();
  57. return 0;
  58. }
  59. U_BOOT_CMD(
  60. clocks, CONFIG_SYS_MAXARGS, 1, do_showclocks,
  61. "display clocks",
  62. ""
  63. );
  64. #endif