cpu.c 4.8 KB

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