speed.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. #if defined(CONFIG_S3C2400) || defined (CONFIG_S3C2410) || defined (CONFIG_TRAB)
  32. #if defined(CONFIG_S3C2400)
  33. #include <s3c2400.h>
  34. #elif defined(CONFIG_S3C2410)
  35. #include <s3c2410.h>
  36. #endif
  37. #define MPLL 0
  38. #define UPLL 1
  39. /* ------------------------------------------------------------------------- */
  40. /* NOTE: This describes the proper use of this file.
  41. *
  42. * CONFIG_SYS_CLK_FREQ should be defined as the input frequency of the PLL.
  43. *
  44. * get_FCLK(), get_HCLK(), get_PCLK() and get_UCLK() return the clock of
  45. * the specified bus in HZ.
  46. */
  47. /* ------------------------------------------------------------------------- */
  48. static ulong get_PLLCLK(int pllreg)
  49. {
  50. S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER();
  51. ulong r, m, p, s;
  52. if (pllreg == MPLL)
  53. r = clk_power->MPLLCON;
  54. else if (pllreg == UPLL)
  55. r = clk_power->UPLLCON;
  56. else
  57. hang();
  58. m = ((r & 0xFF000) >> 12) + 8;
  59. p = ((r & 0x003F0) >> 4) + 2;
  60. s = r & 0x3;
  61. return((CONFIG_SYS_CLK_FREQ * m) / (p << s));
  62. }
  63. /* return FCLK frequency */
  64. ulong get_FCLK(void)
  65. {
  66. return(get_PLLCLK(MPLL));
  67. }
  68. /* return HCLK frequency */
  69. ulong get_HCLK(void)
  70. {
  71. S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER();
  72. return((clk_power->CLKDIVN & 0x2) ? get_FCLK()/2 : get_FCLK());
  73. }
  74. /* return PCLK frequency */
  75. ulong get_PCLK(void)
  76. {
  77. S3C24X0_CLOCK_POWER * const clk_power = S3C24X0_GetBase_CLOCK_POWER();
  78. return((clk_power->CLKDIVN & 0x1) ? get_HCLK()/2 : get_HCLK());
  79. }
  80. /* return UCLK frequency */
  81. ulong get_UCLK(void)
  82. {
  83. return(get_PLLCLK(UPLL));
  84. }
  85. #endif /* defined(CONFIG_S3C2400) || defined (CONFIG_S3C2410) || defined (CONFIG_TRAB) */