cpu.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220
  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 <netdev.h>
  8. #include <asm/arch/hardware.h>
  9. #include <asm/io.h>
  10. DECLARE_GLOBAL_DATA_PTR;
  11. /* offsets from PLL controller base */
  12. #define PLLC_PLLCTL 0x100
  13. #define PLLC_PLLM 0x110
  14. #define PLLC_PREDIV 0x114
  15. #define PLLC_PLLDIV1 0x118
  16. #define PLLC_PLLDIV2 0x11c
  17. #define PLLC_PLLDIV3 0x120
  18. #define PLLC_POSTDIV 0x128
  19. #define PLLC_BPDIV 0x12c
  20. #define PLLC_PLLDIV4 0x160
  21. #define PLLC_PLLDIV5 0x164
  22. #define PLLC_PLLDIV6 0x168
  23. #define PLLC_PLLDIV7 0x16c
  24. #define PLLC_PLLDIV8 0x170
  25. #define PLLC_PLLDIV9 0x174
  26. /* SOC-specific pll info */
  27. #ifdef CONFIG_SOC_DM355
  28. #define ARM_PLLDIV PLLC_PLLDIV1
  29. #define DDR_PLLDIV PLLC_PLLDIV1
  30. #endif
  31. #ifdef CONFIG_SOC_DM644X
  32. #define ARM_PLLDIV PLLC_PLLDIV2
  33. #define DSP_PLLDIV PLLC_PLLDIV1
  34. #define DDR_PLLDIV PLLC_PLLDIV2
  35. #endif
  36. #ifdef CONFIG_SOC_DM646X
  37. #define DSP_PLLDIV PLLC_PLLDIV1
  38. #define ARM_PLLDIV PLLC_PLLDIV2
  39. #define DDR_PLLDIV PLLC_PLLDIV1
  40. #endif
  41. #ifdef CONFIG_SOC_DA8XX
  42. unsigned int sysdiv[9] = {
  43. PLLC_PLLDIV1, PLLC_PLLDIV2, PLLC_PLLDIV3, PLLC_PLLDIV4, PLLC_PLLDIV5,
  44. PLLC_PLLDIV6, PLLC_PLLDIV7, PLLC_PLLDIV8, PLLC_PLLDIV9
  45. };
  46. int clk_get(enum davinci_clk_ids id)
  47. {
  48. int pre_div;
  49. int pllm;
  50. int post_div;
  51. int pll_out;
  52. unsigned int pll_base;
  53. pll_out = CONFIG_SYS_OSCIN_FREQ;
  54. if (id == DAVINCI_AUXCLK_CLKID)
  55. goto out;
  56. if ((id >> 16) == 1)
  57. pll_base = (unsigned int)davinci_pllc1_regs;
  58. else
  59. pll_base = (unsigned int)davinci_pllc0_regs;
  60. id &= 0xFFFF;
  61. /*
  62. * Lets keep this simple. Combining operations can result in
  63. * unexpected approximations
  64. */
  65. pre_div = (readl(pll_base + PLLC_PREDIV) &
  66. DAVINCI_PLLC_DIV_MASK) + 1;
  67. pllm = readl(pll_base + PLLC_PLLM) + 1;
  68. pll_out /= pre_div;
  69. pll_out *= pllm;
  70. if (id == DAVINCI_PLLM_CLKID)
  71. goto out;
  72. post_div = (readl(pll_base + PLLC_POSTDIV) &
  73. DAVINCI_PLLC_DIV_MASK) + 1;
  74. pll_out /= post_div;
  75. if (id == DAVINCI_PLLC_CLKID)
  76. goto out;
  77. pll_out /= (readl(pll_base + sysdiv[id - 1]) &
  78. DAVINCI_PLLC_DIV_MASK) + 1;
  79. out:
  80. return pll_out;
  81. }
  82. int set_cpu_clk_info(void)
  83. {
  84. gd->bd->bi_arm_freq = clk_get(DAVINCI_ARM_CLKID) / 1000000;
  85. /* DDR PHY uses an x2 input clock */
  86. gd->bd->bi_ddr_freq = cpu_is_da830() ? 0 :
  87. (clk_get(DAVINCI_DDR_CLKID) / 1000000);
  88. gd->bd->bi_dsp_freq = 0;
  89. return 0;
  90. }
  91. #else /* CONFIG_SOC_DA8XX */
  92. static unsigned pll_div(volatile void *pllbase, unsigned offset)
  93. {
  94. u32 div;
  95. div = REG(pllbase + offset);
  96. return (div & BIT(15)) ? (1 + (div & 0x1f)) : 1;
  97. }
  98. static inline unsigned pll_prediv(volatile void *pllbase)
  99. {
  100. #ifdef CONFIG_SOC_DM355
  101. /* this register read seems to fail on pll0 */
  102. if (pllbase == (volatile void *)DAVINCI_PLL_CNTRL0_BASE)
  103. return 8;
  104. else
  105. return pll_div(pllbase, PLLC_PREDIV);
  106. #elif defined(CONFIG_SOC_DM365)
  107. return pll_div(pllbase, PLLC_PREDIV);
  108. #endif
  109. return 1;
  110. }
  111. static inline unsigned pll_postdiv(volatile void *pllbase)
  112. {
  113. #if defined(CONFIG_SOC_DM355) || defined(CONFIG_SOC_DM365)
  114. return pll_div(pllbase, PLLC_POSTDIV);
  115. #elif defined(CONFIG_SOC_DM6446)
  116. if (pllbase == (volatile void *)DAVINCI_PLL_CNTRL0_BASE)
  117. return pll_div(pllbase, PLLC_POSTDIV);
  118. #endif
  119. return 1;
  120. }
  121. static unsigned pll_sysclk_mhz(unsigned pll_addr, unsigned div)
  122. {
  123. volatile void *pllbase = (volatile void *) pll_addr;
  124. #ifdef CONFIG_SOC_DM646X
  125. unsigned base = CONFIG_REFCLK_FREQ / 1000;
  126. #else
  127. unsigned base = CONFIG_SYS_HZ_CLOCK / 1000;
  128. #endif
  129. /* the PLL might be bypassed */
  130. if (readl(pllbase + PLLC_PLLCTL) & BIT(0)) {
  131. base /= pll_prediv(pllbase);
  132. #if defined(CONFIG_SOC_DM365)
  133. base *= 2 * (readl(pllbase + PLLC_PLLM) & 0x0ff);
  134. #else
  135. base *= 1 + (REG(pllbase + PLLC_PLLM) & 0x0ff);
  136. #endif
  137. base /= pll_postdiv(pllbase);
  138. }
  139. return DIV_ROUND_UP(base, 1000 * pll_div(pllbase, div));
  140. }
  141. #ifdef DAVINCI_DM6467EVM
  142. unsigned int davinci_arm_clk_get()
  143. {
  144. return pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, ARM_PLLDIV) * 1000000;
  145. }
  146. #endif
  147. #if defined(CONFIG_SOC_DM365)
  148. unsigned int davinci_clk_get(unsigned int div)
  149. {
  150. return pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, div) * 1000000;
  151. }
  152. #endif
  153. int set_cpu_clk_info(void)
  154. {
  155. unsigned int pllbase = DAVINCI_PLL_CNTRL0_BASE;
  156. #if defined(CONFIG_SOC_DM365)
  157. pllbase = DAVINCI_PLL_CNTRL1_BASE;
  158. #endif
  159. gd->bd->bi_arm_freq = pll_sysclk_mhz(pllbase, ARM_PLLDIV);
  160. #ifdef DSP_PLLDIV
  161. gd->bd->bi_dsp_freq =
  162. pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, DSP_PLLDIV);
  163. #else
  164. gd->bd->bi_dsp_freq = 0;
  165. #endif
  166. pllbase = DAVINCI_PLL_CNTRL1_BASE;
  167. #if defined(CONFIG_SOC_DM365)
  168. pllbase = DAVINCI_PLL_CNTRL0_BASE;
  169. #endif
  170. gd->bd->bi_ddr_freq = pll_sysclk_mhz(pllbase, DDR_PLLDIV) / 2;
  171. return 0;
  172. }
  173. #endif /* !CONFIG_SOC_DA8XX */
  174. /*
  175. * Initializes on-chip ethernet controllers.
  176. * to override, implement board_eth_init()
  177. */
  178. int cpu_eth_init(bd_t *bis)
  179. {
  180. #if defined(CONFIG_DRIVER_TI_EMAC)
  181. davinci_emac_initialize();
  182. #endif
  183. return 0;
  184. }