incaip_clock.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /*
  2. * (C) Copyright 2003
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  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
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (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., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <asm/inca-ip.h>
  25. /*******************************************************************************
  26. *
  27. * get_cpuclk - returns the frequency of the CPU.
  28. *
  29. * Gets the value directly from the INCA-IP hardware.
  30. *
  31. * RETURNS:
  32. * 150.000.000 for 150 MHz
  33. * 133.333.333 for 133 Mhz (= 400MHz/3)
  34. * 100.000.000 for 100 Mhz (= 400MHz/4)
  35. * NOTE:
  36. * This functions should be used by the hardware driver to get the correct
  37. * frequency of the CPU. Don't use the macros, which are set to init the CPU
  38. * frequency in the ROM code.
  39. */
  40. uint incaip_get_cpuclk (void)
  41. {
  42. /*-------------------------------------------------------------------------*/
  43. /* CPU Clock Input Multiplexer (MUX I) */
  44. /* Multiplexer MUX I selects the maximum input clock to the CPU. */
  45. /*-------------------------------------------------------------------------*/
  46. if (*((volatile ulong *) INCA_IP_CGU_CGU_MUXCR) &
  47. INCA_IP_CGU_CGU_MUXCR_MUXI) {
  48. /* MUX I set to 150 MHz clock */
  49. return 150000000;
  50. } else {
  51. /* MUX I set to 100/133 MHz clock */
  52. if (*((volatile ulong *) INCA_IP_CGU_CGU_DIVCR) & 0x40) {
  53. /* Division value is 1/3, maximum CPU operating */
  54. /* frequency is 133.3 MHz */
  55. return 133333333;
  56. } else {
  57. /* Division value is 1/4, maximum CPU operating */
  58. /* frequency is 100 MHz */
  59. return 100000000;
  60. }
  61. }
  62. }
  63. /*******************************************************************************
  64. *
  65. * get_fpiclk - returns the frequency of the FPI bus.
  66. *
  67. * Gets the value directly from the INCA-IP hardware.
  68. *
  69. * RETURNS: Frquency in Hz
  70. *
  71. * NOTE:
  72. * This functions should be used by the hardware driver to get the correct
  73. * frequency of the CPU. Don't use the macros, which are set to init the CPU
  74. * frequency in the ROM code.
  75. * The calculation for the
  76. */
  77. uint incaip_get_fpiclk (void)
  78. {
  79. uint clkCPU;
  80. clkCPU = incaip_get_cpuclk ();
  81. switch (*((volatile ulong *) INCA_IP_CGU_CGU_DIVCR) & 0xC) {
  82. case 0x4:
  83. return clkCPU >> 1; /* devided by 2 */
  84. break;
  85. case 0x8:
  86. return clkCPU >> 2; /* devided by 4 */
  87. break;
  88. default:
  89. return clkCPU;
  90. break;
  91. }
  92. }
  93. int incaip_set_cpuclk (void)
  94. {
  95. extern void ebu_init(long);
  96. extern void cgu_init(long);
  97. extern void sdram_init(long);
  98. char tmp[64];
  99. ulong cpuclk;
  100. if (getenv_r ("cpuclk", tmp, sizeof (tmp)) > 0) {
  101. cpuclk = simple_strtoul (tmp, NULL, 10) * 1000000;
  102. cgu_init (cpuclk);
  103. ebu_init (cpuclk);
  104. sdram_init (cpuclk);
  105. }
  106. return 0;
  107. }