cpu.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  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. int set_cpu_clk_info(void)
  100. {
  101. gd->bd->bi_arm_freq = clk_get(DAVINCI_ARM_CLKID) / 1000000;
  102. /* DDR PHY uses an x2 input clock */
  103. gd->bd->bi_ddr_freq = cpu_is_da830() ? 0 :
  104. (clk_get(DAVINCI_DDR_CLKID) / 1000000);
  105. gd->bd->bi_dsp_freq = 0;
  106. return 0;
  107. }
  108. #else /* CONFIG_SOC_DA8XX */
  109. static unsigned pll_div(volatile void *pllbase, unsigned offset)
  110. {
  111. u32 div;
  112. div = REG(pllbase + offset);
  113. return (div & BIT(15)) ? (1 + (div & 0x1f)) : 1;
  114. }
  115. static inline unsigned pll_prediv(volatile void *pllbase)
  116. {
  117. #ifdef CONFIG_SOC_DM355
  118. /* this register read seems to fail on pll0 */
  119. if (pllbase == (volatile void *)DAVINCI_PLL_CNTRL0_BASE)
  120. return 8;
  121. else
  122. return pll_div(pllbase, PLLC_PREDIV);
  123. #elif defined(CONFIG_SOC_DM365)
  124. return pll_div(pllbase, PLLC_PREDIV);
  125. #endif
  126. return 1;
  127. }
  128. static inline unsigned pll_postdiv(volatile void *pllbase)
  129. {
  130. #if defined(CONFIG_SOC_DM355) || defined(CONFIG_SOC_DM365)
  131. return pll_div(pllbase, PLLC_POSTDIV);
  132. #elif defined(CONFIG_SOC_DM6446)
  133. if (pllbase == (volatile void *)DAVINCI_PLL_CNTRL0_BASE)
  134. return pll_div(pllbase, PLLC_POSTDIV);
  135. #endif
  136. return 1;
  137. }
  138. static unsigned pll_sysclk_mhz(unsigned pll_addr, unsigned div)
  139. {
  140. volatile void *pllbase = (volatile void *) pll_addr;
  141. #ifdef CONFIG_SOC_DM646X
  142. unsigned base = CONFIG_REFCLK_FREQ / 1000;
  143. #else
  144. unsigned base = CONFIG_SYS_HZ_CLOCK / 1000;
  145. #endif
  146. /* the PLL might be bypassed */
  147. if (readl(pllbase + PLLC_PLLCTL) & BIT(0)) {
  148. base /= pll_prediv(pllbase);
  149. #if defined(CONFIG_SOC_DM365)
  150. base *= 2 * (readl(pllbase + PLLC_PLLM) & 0x0ff);
  151. #else
  152. base *= 1 + (REG(pllbase + PLLC_PLLM) & 0x0ff);
  153. #endif
  154. base /= pll_postdiv(pllbase);
  155. }
  156. return DIV_ROUND_UP(base, 1000 * pll_div(pllbase, div));
  157. }
  158. #ifdef DAVINCI_DM6467EVM
  159. unsigned int davinci_arm_clk_get()
  160. {
  161. return pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, ARM_PLLDIV) * 1000000;
  162. }
  163. #endif
  164. #if defined(CONFIG_SOC_DM365)
  165. unsigned int davinci_clk_get(unsigned int div)
  166. {
  167. return pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, div) * 1000000;
  168. }
  169. #endif
  170. int set_cpu_clk_info(void)
  171. {
  172. unsigned int pllbase = DAVINCI_PLL_CNTRL0_BASE;
  173. #if defined(CONFIG_SOC_DM365)
  174. pllbase = DAVINCI_PLL_CNTRL1_BASE;
  175. #endif
  176. gd->bd->bi_arm_freq = pll_sysclk_mhz(pllbase, ARM_PLLDIV);
  177. #ifdef DSP_PLLDIV
  178. gd->bd->bi_dsp_freq =
  179. pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, DSP_PLLDIV);
  180. #else
  181. gd->bd->bi_dsp_freq = 0;
  182. #endif
  183. pllbase = DAVINCI_PLL_CNTRL1_BASE;
  184. #if defined(CONFIG_SOC_DM365)
  185. pllbase = DAVINCI_PLL_CNTRL0_BASE;
  186. #endif
  187. gd->bd->bi_ddr_freq = pll_sysclk_mhz(pllbase, DDR_PLLDIV) / 2;
  188. return 0;
  189. }
  190. #endif /* !CONFIG_SOC_DA8XX */
  191. /*
  192. * Initializes on-chip ethernet controllers.
  193. * to override, implement board_eth_init()
  194. */
  195. int cpu_eth_init(bd_t *bis)
  196. {
  197. #if defined(CONFIG_DRIVER_TI_EMAC)
  198. davinci_emac_initialize();
  199. #endif
  200. return 0;
  201. }