cpu.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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 <asm/arch/hardware.h>
  24. /* offsets from PLL controller base */
  25. #define PLLC_PLLCTL 0x100
  26. #define PLLC_PLLM 0x110
  27. #define PLLC_PREDIV 0x114
  28. #define PLLC_PLLDIV1 0x118
  29. #define PLLC_PLLDIV2 0x11c
  30. #define PLLC_PLLDIV3 0x120
  31. #define PLLC_POSTDIV 0x128
  32. #define PLLC_BPDIV 0x12c
  33. #define PLLC_PLLDIV4 0x160
  34. #define PLLC_PLLDIV5 0x164
  35. #define PLLC_PLLDIV6 0x168
  36. #define PLLC_PLLDIV8 0x170
  37. #define PLLC_PLLDIV9 0x174
  38. #define BIT(x) (1 << (x))
  39. /* SOC-specific pll info */
  40. #ifdef CONFIG_SOC_DM355
  41. #define ARM_PLLDIV PLLC_PLLDIV1
  42. #define DDR_PLLDIV PLLC_PLLDIV1
  43. #endif
  44. #ifdef CONFIG_SOC_DM644X
  45. #define ARM_PLLDIV PLLC_PLLDIV2
  46. #define DSP_PLLDIV PLLC_PLLDIV1
  47. #define DDR_PLLDIV PLLC_PLLDIV2
  48. #endif
  49. #ifdef CONFIG_SOC_DM6447
  50. #define ARM_PLLDIV PLLC_PLLDIV2
  51. #define DSP_PLLDIV PLLC_PLLDIV1
  52. #define DDR_PLLDIV PLLC_PLLDIV1
  53. #endif
  54. #ifdef CONFIG_DISPLAY_CPUINFO
  55. static unsigned pll_div(volatile void *pllbase, unsigned offset)
  56. {
  57. u32 div;
  58. div = REG(pllbase + offset);
  59. return (div & BIT(15)) ? (1 + (div & 0x1f)) : 1;
  60. }
  61. static inline unsigned pll_prediv(volatile void *pllbase)
  62. {
  63. #ifdef CONFIG_SOC_DM355
  64. /* this register read seems to fail on pll0 */
  65. if (pllbase == (volatile void *)DAVINCI_PLL_CNTRL0_BASE)
  66. return 8;
  67. else
  68. return pll_div(pllbase, PLLC_PREDIV);
  69. #endif
  70. return 1;
  71. }
  72. static inline unsigned pll_postdiv(volatile void *pllbase)
  73. {
  74. #ifdef CONFIG_SOC_DM355
  75. return pll_div(pllbase, PLLC_POSTDIV);
  76. #elif defined(CONFIG_SOC_DM6446)
  77. if (pllbase == (volatile void *)DAVINCI_PLL_CNTRL0_BASE)
  78. return pll_div(pllbase, PLLC_POSTDIV);
  79. #endif
  80. return 1;
  81. }
  82. static unsigned pll_sysclk_mhz(unsigned pll_addr, unsigned div)
  83. {
  84. volatile void *pllbase = (volatile void *) pll_addr;
  85. unsigned base = CONFIG_SYS_HZ_CLOCK / 1000;
  86. /* the PLL might be bypassed */
  87. if (REG(pllbase + PLLC_PLLCTL) & BIT(0)) {
  88. base /= pll_prediv(pllbase);
  89. base *= 1 + (REG(pllbase + PLLC_PLLM) & 0x0ff);
  90. base /= pll_postdiv(pllbase);
  91. }
  92. return DIV_ROUND_UP(base, 1000 * pll_div(pllbase, div));
  93. }
  94. int print_cpuinfo(void)
  95. {
  96. /* REVISIT fetch and display CPU ID and revision information
  97. * too ... that will matter as more revisions appear.
  98. */
  99. printf("Cores: ARM %d MHz",
  100. pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, ARM_PLLDIV));
  101. #ifdef DSP_PLLDIV
  102. printf(", DSP %d MHz",
  103. pll_sysclk_mhz(DAVINCI_PLL_CNTRL0_BASE, DSP_PLLDIV));
  104. #endif
  105. printf("\nDDR: %d MHz\n",
  106. /* DDR PHY uses an x2 input clock */
  107. pll_sysclk_mhz(DAVINCI_PLL_CNTRL1_BASE, DDR_PLLDIV)
  108. / 2);
  109. return 0;
  110. }
  111. #endif