cpu.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244
  1. /*
  2. * Copyright (C) 2004 Texas Instruments.
  3. * Copyright (C) 2009 David Brownell
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  21. */
  22. #include <common.h>
  23. #include <netdev.h>
  24. #include <asm/arch/hardware.h>
  25. #include <asm/io.h>
  26. /* offsets from PLL controller base */
  27. #define PLLC_PLLCTL 0x100
  28. #define PLLC_PLLM 0x110
  29. #define PLLC_PREDIV 0x114
  30. #define PLLC_PLLDIV1 0x118
  31. #define PLLC_PLLDIV2 0x11c
  32. #define PLLC_PLLDIV3 0x120
  33. #define PLLC_POSTDIV 0x128
  34. #define PLLC_BPDIV 0x12c
  35. #define PLLC_PLLDIV4 0x160
  36. #define PLLC_PLLDIV5 0x164
  37. #define PLLC_PLLDIV6 0x168
  38. #define PLLC_PLLDIV7 0x16c
  39. #define PLLC_PLLDIV8 0x170
  40. #define PLLC_PLLDIV9 0x174
  41. #define BIT(x) (1 << (x))
  42. /* SOC-specific pll info */
  43. #ifdef CONFIG_SOC_DM355
  44. #define ARM_PLLDIV PLLC_PLLDIV1
  45. #define DDR_PLLDIV PLLC_PLLDIV1
  46. #endif
  47. #ifdef CONFIG_SOC_DM644X
  48. #define ARM_PLLDIV PLLC_PLLDIV2
  49. #define DSP_PLLDIV PLLC_PLLDIV1
  50. #define DDR_PLLDIV PLLC_PLLDIV2
  51. #endif
  52. #ifdef CONFIG_SOC_DM646X
  53. #define DSP_PLLDIV PLLC_PLLDIV1
  54. #define ARM_PLLDIV PLLC_PLLDIV2
  55. #define DDR_PLLDIV PLLC_PLLDIV1
  56. #endif
  57. #ifdef CONFIG_SOC_DA8XX
  58. unsigned int sysdiv[9] = {
  59. PLLC_PLLDIV1, PLLC_PLLDIV2, PLLC_PLLDIV3, PLLC_PLLDIV4, PLLC_PLLDIV5,
  60. PLLC_PLLDIV6, PLLC_PLLDIV7, PLLC_PLLDIV8, PLLC_PLLDIV9
  61. };
  62. int clk_get(enum davinci_clk_ids id)
  63. {
  64. int pre_div;
  65. int pllm;
  66. int post_div;
  67. int pll_out;
  68. unsigned int pll_base;
  69. pll_out = CONFIG_SYS_OSCIN_FREQ;
  70. if (id == DAVINCI_AUXCLK_CLKID)
  71. goto out;
  72. if ((id >> 16) == 1)
  73. pll_base = (unsigned int)davinci_pllc1_regs;
  74. else
  75. pll_base = (unsigned int)davinci_pllc0_regs;
  76. id &= 0xFFFF;
  77. /*
  78. * Lets keep this simple. Combining operations can result in
  79. * unexpected approximations
  80. */
  81. pre_div = (readl(pll_base + PLLC_PREDIV) &
  82. DAVINCI_PLLC_DIV_MASK) + 1;
  83. pllm = readl(pll_base + PLLC_PLLM) + 1;
  84. pll_out /= pre_div;
  85. pll_out *= pllm;
  86. if (id == DAVINCI_PLLM_CLKID)
  87. goto out;
  88. post_div = (readl(pll_base + PLLC_POSTDIV) &
  89. DAVINCI_PLLC_DIV_MASK) + 1;
  90. pll_out /= post_div;
  91. if (id == DAVINCI_PLLC_CLKID)
  92. goto out;
  93. pll_out /= (readl(pll_base + sysdiv[id - 1]) &
  94. DAVINCI_PLLC_DIV_MASK) + 1;
  95. out:
  96. return pll_out;
  97. }
  98. #ifdef CONFIG_DISPLAY_CPUINFO
  99. int print_cpuinfo(void)
  100. {
  101. printf("Cores: ARM %d MHz",
  102. clk_get(DAVINCI_ARM_CLKID) / 1000000);
  103. printf("\nDDR: %d MHz\n",
  104. /* DDR PHY uses an x2 input clock */
  105. clk_get(0x10001) / 1000000);
  106. return 0;
  107. }
  108. #endif
  109. #else /* CONFIG_SOC_DA8XX */
  110. #ifdef CONFIG_DISPLAY_CPUINFO
  111. static unsigned pll_div(volatile void *pllbase, unsigned offset)
  112. {
  113. u32 div;
  114. div = REG(pllbase + offset);
  115. return (div & BIT(15)) ? (1 + (div & 0x1f)) : 1;
  116. }
  117. static inline unsigned pll_prediv(volatile void *pllbase)
  118. {
  119. #ifdef CONFIG_SOC_DM355
  120. /* this register read seems to fail on pll0 */
  121. if (pllbase == (volatile void *)DAVINCI_PLL_CNTRL0_BASE)
  122. return 8;
  123. else
  124. return pll_div(pllbase, PLLC_PREDIV);
  125. #elif defined(CONFIG_SOC_DM365)
  126. return pll_div(pllbase, PLLC_PREDIV);
  127. #endif
  128. return 1;
  129. }
  130. static inline unsigned pll_postdiv(volatile void *pllbase)
  131. {
  132. #if defined(CONFIG_SOC_DM355) || defined(CONFIG_SOC_DM365)
  133. return pll_div(pllbase, PLLC_POSTDIV);
  134. #elif defined(CONFIG_SOC_DM6446)
  135. if (pllbase == (volatile void *)DAVINCI_PLL_CNTRL0_BASE)
  136. return pll_div(pllbase, PLLC_POSTDIV);
  137. #endif
  138. return 1;
  139. }
  140. static unsigned pll_sysclk_mhz(unsigned pll_addr, unsigned div)
  141. {
  142. volatile void *pllbase = (volatile void *) pll_addr;
  143. #ifdef CONFIG_SOC_DM646X
  144. unsigned base = CFG_REFCLK_FREQ / 1000;
  145. #else
  146. unsigned base = CONFIG_SYS_HZ_CLOCK / 1000;
  147. #endif
  148. /* the PLL might be bypassed */
  149. if (readl(pllbase + PLLC_PLLCTL) & BIT(0)) {
  150. base /= pll_prediv(pllbase);
  151. #if defined(CONFIG_SOC_DM365)
  152. base *= 2 * (readl(pllbase + PLLC_PLLM) & 0x0ff);
  153. #else
  154. base *= 1 + (REG(pllbase + PLLC_PLLM) & 0x0ff);
  155. #endif
  156. base /= pll_postdiv(pllbase);
  157. }
  158. return DIV_ROUND_UP(base, 1000 * pll_div(pllbase, div));
  159. }
  160. int print_cpuinfo(void)
  161. {
  162. /* REVISIT fetch and display CPU ID and revision information
  163. * too ... that will matter as more revisions appear.
  164. */
  165. #if defined(CONFIG_SOC_DM365)
  166. printf("Cores: ARM %d MHz",
  167. pll_sysclk_mhz(DAVINCI_PLL_CNTRL1_BASE, ARM_PLLDIV));
  168. #else
  169. printf("Cores: ARM %d MHz",
  170. pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, ARM_PLLDIV));
  171. #endif
  172. #ifdef DSP_PLLDIV
  173. printf(", DSP %d MHz",
  174. pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, DSP_PLLDIV));
  175. #endif
  176. printf("\nDDR: %d MHz\n",
  177. /* DDR PHY uses an x2 input clock */
  178. #if defined(CONFIG_SOC_DM365)
  179. pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, DDR_PLLDIV)
  180. / 2);
  181. #else
  182. pll_sysclk_mhz(DAVINCI_PLL_CNTRL1_BASE, DDR_PLLDIV)
  183. / 2);
  184. #endif
  185. return 0;
  186. }
  187. #ifdef DAVINCI_DM6467EVM
  188. unsigned int davinci_arm_clk_get()
  189. {
  190. return pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, ARM_PLLDIV) * 1000000;
  191. }
  192. #endif
  193. #if defined(CONFIG_SOC_DM365)
  194. unsigned int davinci_clk_get(unsigned int div)
  195. {
  196. return pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, div) * 1000000;
  197. }
  198. #endif
  199. #endif /* CONFIG_DISPLAY_CPUINFO */
  200. #endif /* !CONFIG_SOC_DA8XX */
  201. /*
  202. * Initializes on-chip ethernet controllers.
  203. * to override, implement board_eth_init()
  204. */
  205. int cpu_eth_init(bd_t *bis)
  206. {
  207. #if defined(CONFIG_DRIVER_TI_EMAC)
  208. davinci_emac_initialize();
  209. #endif
  210. return 0;
  211. }