speed.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /*
  2. * (C) Copyright 2000-2002
  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 <74xx_7xx.h>
  25. #include <asm/processor.h>
  26. #ifdef CONFIG_AMIGAONEG3SE
  27. #include "../board/MAI/AmigaOneG3SE/via686.h"
  28. #endif
  29. DECLARE_GLOBAL_DATA_PTR;
  30. extern unsigned long get_board_bus_clk (void);
  31. static const int hid1_multipliers_x_10[] = {
  32. 25, /* 0000 - 2.5x */
  33. 75, /* 0001 - 7.5x */
  34. 70, /* 0010 - 7x */
  35. 10, /* 0011 - bypass */
  36. 20, /* 0100 - 2x */
  37. 65, /* 0101 - 6.5x */
  38. 100, /* 0110 - 10x */
  39. 45, /* 0111 - 4.5x */
  40. 30, /* 1000 - 3x */
  41. 55, /* 1001 - 5.5x */
  42. 40, /* 1010 - 4x */
  43. 50, /* 1011 - 5x */
  44. 80, /* 1100 - 8x */
  45. 60, /* 1101 - 6x */
  46. 35, /* 1110 - 3.5x */
  47. 0 /* 1111 - off */
  48. };
  49. /* PLL_CFG[0:4] table for cpu 7448/7447A/7455/7457 */
  50. static const int hid1_74xx_multipliers_x_10[] = {
  51. 115, /* 00000 - 11.5x */
  52. 170, /* 00001 - 17x */
  53. 75, /* 00010 - 7.5x */
  54. 150, /* 00011 - 15x */
  55. 70, /* 00100 - 7x */
  56. 180, /* 00101 - 18x */
  57. 10, /* 00110 - bypass */
  58. 200, /* 00111 - 20x */
  59. 20, /* 01000 - 2x */
  60. 210, /* 01001 - 21x */
  61. 65, /* 01010 - 6.5x */
  62. 130, /* 01011 - 13x */
  63. 85, /* 01100 - 8.5x */
  64. 240, /* 01101 - 24x */
  65. 95, /* 01110 - 9.5x */
  66. 90, /* 01111 - 9x */
  67. 30, /* 10000 - 3x */
  68. 105, /* 10001 - 10.5x */
  69. 55, /* 10010 - 5.5x */
  70. 110, /* 10011 - 11x */
  71. 40, /* 10100 - 4x */
  72. 100, /* 10101 - 10x */
  73. 50, /* 10110 - 5x */
  74. 120, /* 10111 - 12x */
  75. 80, /* 11000 - 8x */
  76. 140, /* 11001 - 14x */
  77. 60, /* 11010 - 6x */
  78. 160, /* 11011 - 16x */
  79. 135, /* 11100 - 13.5x */
  80. 280, /* 11101 - 28x */
  81. 0, /* 11110 - off */
  82. 125 /* 11111 - 12.5x */
  83. };
  84. static const int hid1_fx_multipliers_x_10[] = {
  85. 00, /* 0000 - off */
  86. 00, /* 0001 - off */
  87. 10, /* 0010 - bypass */
  88. 10, /* 0011 - bypass */
  89. 20, /* 0100 - 2x */
  90. 25, /* 0101 - 2.5x */
  91. 30, /* 0110 - 3x */
  92. 35, /* 0111 - 3.5x */
  93. 40, /* 1000 - 4x */
  94. 45, /* 1001 - 4.5x */
  95. 50, /* 1010 - 5x */
  96. 55, /* 1011 - 5.5x */
  97. 60, /* 1100 - 6x */
  98. 65, /* 1101 - 6.5x */
  99. 70, /* 1110 - 7x */
  100. 75, /* 1111 - 7.5 */
  101. 80, /* 10000 - 8x */
  102. 85, /* 10001 - 8.5x */
  103. 90, /* 10010 - 9x */
  104. 95, /* 10011 - 9.5x */
  105. 100, /* 10100 - 10x */
  106. 110, /* 10101 - 11x */
  107. 120, /* 10110 - 12x */
  108. };
  109. /* ------------------------------------------------------------------------- */
  110. /*
  111. * Measure CPU clock speed (core clock GCLK1, GCLK2)
  112. *
  113. * (Approx. GCLK frequency in Hz)
  114. */
  115. int get_clocks (void)
  116. {
  117. ulong clock = 0;
  118. #ifdef CONFIG_SYS_BUS_CLK
  119. gd->bus_clk = CONFIG_SYS_BUS_CLK; /* bus clock is a fixed frequency */
  120. #else
  121. gd->bus_clk = get_board_bus_clk (); /* bus clock is configurable */
  122. #endif
  123. /* calculate the clock frequency based upon the CPU type */
  124. switch (get_cpu_type()) {
  125. case CPU_7447A:
  126. case CPU_7448:
  127. case CPU_7455:
  128. case CPU_7457:
  129. /*
  130. * Make sure division is done before multiplication to prevent 32-bit
  131. * arithmetic overflows which will cause a negative number
  132. */
  133. clock = (gd->bus_clk / 10) *
  134. hid1_74xx_multipliers_x_10[(get_hid1 () >> 12) & 0x1F];
  135. break;
  136. case CPU_750GX:
  137. case CPU_750FX:
  138. clock = (gd->bus_clk / 10) *
  139. hid1_fx_multipliers_x_10[get_hid1 () >> 27];
  140. break;
  141. case CPU_7450:
  142. case CPU_740:
  143. case CPU_740P:
  144. case CPU_745:
  145. case CPU_750CX:
  146. case CPU_750:
  147. case CPU_750P:
  148. case CPU_755:
  149. case CPU_7400:
  150. case CPU_7410:
  151. /*
  152. * Make sure division is done before multiplication to prevent 32-bit
  153. * arithmetic overflows which will cause a negative number
  154. */
  155. clock = (gd->bus_clk / 10) *
  156. hid1_multipliers_x_10[get_hid1 () >> 28];
  157. break;
  158. case CPU_UNKNOWN:
  159. printf ("get_gclk_freq(): unknown CPU type\n");
  160. clock = 0;
  161. return (1);
  162. }
  163. gd->cpu_clk = clock;
  164. return (0);
  165. }
  166. /* ------------------------------------------------------------------------- */