cpu.c 4.8 KB

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