cpu.c 5.5 KB

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