speed.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. /*
  2. * (C) Copyright 2001-2004
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * (C) Copyright 2002
  6. * David Mueller, ELSOFT AG, d.mueller@elsoft.ch
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. /*
  27. * This code should work for both the S3C2400 and the S3C2410
  28. * as they seem to have the same PLL and clock machinery inside.
  29. * The different address mapping is handled by the s3c24xx.h files below.
  30. */
  31. #include <common.h>
  32. #include <s3c6400.h>
  33. #define APLL 0
  34. #define MPLL 1
  35. #define EPLL 2
  36. /* ------------------------------------------------------------------------- */
  37. /*
  38. * NOTE: This describes the proper use of this file.
  39. *
  40. * CONFIG_SYS_CLK_FREQ should be defined as the input frequency of the PLL.
  41. *
  42. * get_FCLK(), get_HCLK(), get_PCLK() and get_UCLK() return the clock of
  43. * the specified bus in HZ.
  44. */
  45. /* ------------------------------------------------------------------------- */
  46. static ulong get_PLLCLK(int pllreg)
  47. {
  48. ulong r, m, p, s;
  49. switch (pllreg) {
  50. case APLL:
  51. r = APLL_CON_REG;
  52. break;
  53. case MPLL:
  54. r = MPLL_CON_REG;
  55. break;
  56. case EPLL:
  57. r = EPLL_CON0_REG;
  58. break;
  59. default:
  60. hang();
  61. }
  62. m = (r >> 16) & 0x3ff;
  63. p = (r >> 8) & 0x3f;
  64. s = r & 0x7;
  65. return m * (CONFIG_SYS_CLK_FREQ / (p * (1 << s)));
  66. }
  67. /* return ARMCORE frequency */
  68. ulong get_ARMCLK(void)
  69. {
  70. ulong div;
  71. div = CLK_DIV0_REG;
  72. return get_PLLCLK(APLL) / ((div & 0x7) + 1);
  73. }
  74. /* return FCLK frequency */
  75. ulong get_FCLK(void)
  76. {
  77. return get_PLLCLK(APLL);
  78. }
  79. /* return HCLK frequency */
  80. ulong get_HCLK(void)
  81. {
  82. ulong fclk;
  83. uint hclkx2_div = ((CLK_DIV0_REG >> 9) & 0x7) + 1;
  84. uint hclk_div = ((CLK_DIV0_REG >> 8) & 0x1) + 1;
  85. /*
  86. * Bit 7 exists on s3c6410, and not on s3c6400, it is reserved on
  87. * s3c6400 and is always 0, and it is indeed running in ASYNC mode
  88. */
  89. if (OTHERS_REG & 0x80)
  90. fclk = get_FCLK(); /* SYNC Mode */
  91. else
  92. fclk = get_PLLCLK(MPLL); /* ASYNC Mode */
  93. return fclk / (hclk_div * hclkx2_div);
  94. }
  95. /* return PCLK frequency */
  96. ulong get_PCLK(void)
  97. {
  98. ulong fclk;
  99. uint hclkx2_div = ((CLK_DIV0_REG >> 9) & 0x7) + 1;
  100. uint pre_div = ((CLK_DIV0_REG >> 12) & 0xf) + 1;
  101. if (OTHERS_REG & 0x80)
  102. fclk = get_FCLK(); /* SYNC Mode */
  103. else
  104. fclk = get_PLLCLK(MPLL); /* ASYNC Mode */
  105. return fclk / (hclkx2_div * pre_div);
  106. }
  107. /* return UCLK frequency */
  108. ulong get_UCLK(void)
  109. {
  110. return get_PLLCLK(EPLL);
  111. }
  112. int print_cpuinfo(void)
  113. {
  114. printf("\nCPU: S3C6400@%luMHz\n", get_ARMCLK() / 1000000);
  115. printf(" Fclk = %luMHz, Hclk = %luMHz, Pclk = %luMHz ",
  116. get_FCLK() / 1000000, get_HCLK() / 1000000,
  117. get_PCLK() / 1000000);
  118. if (OTHERS_REG & 0x80)
  119. printf("(SYNC Mode) \n");
  120. else
  121. printf("(ASYNC Mode) \n");
  122. return 0;
  123. }