cpu.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2004 Texas Instruments.
  4. * Copyright (C) 2009 David Brownell
  5. */
  6. #include <common.h>
  7. #include <clock_legacy.h>
  8. #include <init.h>
  9. #include <asm/arch/hardware.h>
  10. #include <asm/global_data.h>
  11. #include <asm/io.h>
  12. DECLARE_GLOBAL_DATA_PTR;
  13. /* offsets from PLL controller base */
  14. #define PLLC_PLLCTL 0x100
  15. #define PLLC_PLLM 0x110
  16. #define PLLC_PREDIV 0x114
  17. #define PLLC_PLLDIV1 0x118
  18. #define PLLC_PLLDIV2 0x11c
  19. #define PLLC_PLLDIV3 0x120
  20. #define PLLC_POSTDIV 0x128
  21. #define PLLC_BPDIV 0x12c
  22. #define PLLC_PLLDIV4 0x160
  23. #define PLLC_PLLDIV5 0x164
  24. #define PLLC_PLLDIV6 0x168
  25. #define PLLC_PLLDIV7 0x16c
  26. #define PLLC_PLLDIV8 0x170
  27. #define PLLC_PLLDIV9 0x174
  28. unsigned int sysdiv[9] = {
  29. PLLC_PLLDIV1, PLLC_PLLDIV2, PLLC_PLLDIV3, PLLC_PLLDIV4, PLLC_PLLDIV5,
  30. PLLC_PLLDIV6, PLLC_PLLDIV7, PLLC_PLLDIV8, PLLC_PLLDIV9
  31. };
  32. int clk_get(enum davinci_clk_ids id)
  33. {
  34. int pre_div;
  35. int pllm;
  36. int post_div;
  37. int pll_out;
  38. unsigned int pll_base;
  39. pll_out = CFG_SYS_OSCIN_FREQ;
  40. if (id == DAVINCI_AUXCLK_CLKID)
  41. goto out;
  42. if ((id >> 16) == 1)
  43. pll_base = (unsigned int)davinci_pllc1_regs;
  44. else
  45. pll_base = (unsigned int)davinci_pllc0_regs;
  46. id &= 0xFFFF;
  47. /*
  48. * Lets keep this simple. Combining operations can result in
  49. * unexpected approximations
  50. */
  51. pre_div = (readl(pll_base + PLLC_PREDIV) &
  52. DAVINCI_PLLC_DIV_MASK) + 1;
  53. pllm = readl(pll_base + PLLC_PLLM) + 1;
  54. pll_out /= pre_div;
  55. pll_out *= pllm;
  56. if (id == DAVINCI_PLLM_CLKID)
  57. goto out;
  58. post_div = (readl(pll_base + PLLC_POSTDIV) &
  59. DAVINCI_PLLC_DIV_MASK) + 1;
  60. pll_out /= post_div;
  61. if (id == DAVINCI_PLLC_CLKID)
  62. goto out;
  63. pll_out /= (readl(pll_base + sysdiv[id - 1]) &
  64. DAVINCI_PLLC_DIV_MASK) + 1;
  65. out:
  66. return pll_out;
  67. }
  68. int set_cpu_clk_info(void)
  69. {
  70. gd->bd->bi_arm_freq = clk_get(DAVINCI_ARM_CLKID) / 1000000;
  71. /* DDR PHY uses an x2 input clock */
  72. gd->bd->bi_ddr_freq = cpu_is_da830() ? 0 :
  73. (clk_get(DAVINCI_DDR_CLKID) / 1000000);
  74. gd->bd->bi_dsp_freq = 0;
  75. return 0;
  76. }
  77. unsigned long get_board_sys_clk(void)
  78. {
  79. return clk_get(DAVINCI_ARM_CLKID);
  80. }