speed.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. /* This code should work for both the S3C2400 and the S3C2410
  27. * as they seem to have the same PLL and clock machinery inside.
  28. * The different address mapping is handled by the s3c24xx.h files below.
  29. */
  30. #include <common.h>
  31. #ifdef CONFIG_S3C24X0
  32. #include <asm/io.h>
  33. #include <asm/arch/s3c24x0_cpu.h>
  34. #define MPLL 0
  35. #define UPLL 1
  36. /* ------------------------------------------------------------------------- */
  37. /* NOTE: This describes the proper use of this file.
  38. *
  39. * CONFIG_SYS_CLK_FREQ should be defined as the input frequency of the PLL.
  40. *
  41. * get_FCLK(), get_HCLK(), get_PCLK() and get_UCLK() return the clock of
  42. * the specified bus in HZ.
  43. */
  44. /* ------------------------------------------------------------------------- */
  45. static ulong get_PLLCLK(int pllreg)
  46. {
  47. struct s3c24x0_clock_power *clk_power = s3c24x0_get_base_clock_power();
  48. ulong r, m, p, s;
  49. if (pllreg == MPLL)
  50. r = readl(&clk_power->mpllcon);
  51. else if (pllreg == UPLL)
  52. r = readl(&clk_power->upllcon);
  53. else
  54. hang();
  55. m = ((r & 0xFF000) >> 12) + 8;
  56. p = ((r & 0x003F0) >> 4) + 2;
  57. s = r & 0x3;
  58. #if defined(CONFIG_S3C2440)
  59. if (pllreg == MPLL)
  60. return 2 * m * (CONFIG_SYS_CLK_FREQ / (p << s));
  61. #endif
  62. return (CONFIG_SYS_CLK_FREQ * m) / (p << s);
  63. }
  64. /* return FCLK frequency */
  65. ulong get_FCLK(void)
  66. {
  67. return get_PLLCLK(MPLL);
  68. }
  69. /* return HCLK frequency */
  70. ulong get_HCLK(void)
  71. {
  72. struct s3c24x0_clock_power *clk_power = s3c24x0_get_base_clock_power();
  73. #ifdef CONFIG_S3C2440
  74. switch (readl(&clk_power->clkdivn) & 0x6) {
  75. default:
  76. case 0:
  77. return get_FCLK();
  78. case 2:
  79. return get_FCLK() / 2;
  80. case 4:
  81. return (readl(&clk_power->camdivn) & (1 << 9)) ?
  82. get_FCLK() / 8 : get_FCLK() / 4;
  83. case 6:
  84. return (readl(&clk_power->camdivn) & (1 << 8)) ?
  85. get_FCLK() / 6 : get_FCLK() / 3;
  86. }
  87. #else
  88. return (readl(&clk_power->clkdivn) & 2) ? get_FCLK() / 2 : get_FCLK();
  89. #endif
  90. }
  91. /* return PCLK frequency */
  92. ulong get_PCLK(void)
  93. {
  94. struct s3c24x0_clock_power *clk_power = s3c24x0_get_base_clock_power();
  95. return (readl(&clk_power->clkdivn) & 1) ? get_HCLK() / 2 : get_HCLK();
  96. }
  97. /* return UCLK frequency */
  98. ulong get_UCLK(void)
  99. {
  100. return get_PLLCLK(UPLL);
  101. }
  102. #endif /* CONFIG_S3C24X0 */