speed.c 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Copyright 2004 Freescale Semiconductor.
  3. * Jeff Brown
  4. * Srikanth Srinivasan (srikanth.srinivasan@freescale.com)
  5. *
  6. * (C) Copyright 2000-2002
  7. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <mpc86xx.h>
  29. #include <asm/processor.h>
  30. /*
  31. * get_board_sys_clk
  32. * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
  33. */
  34. unsigned long get_board_sys_clk(ulong dummy)
  35. {
  36. u8 i, go_bit, rd_clks;
  37. ulong val = 0;
  38. go_bit = in8(PIXIS_BASE + PIXIS_VCTL);
  39. go_bit &= 0x01;
  40. rd_clks = in8(PIXIS_BASE + PIXIS_VCFGEN0);
  41. rd_clks &= 0x1C;
  42. /*
  43. * Only if both go bit and the SCLK bit in VCFGEN0 are set
  44. * should we be using the AUX register. Remember, we also set the
  45. * GO bit to boot from the alternate bank on the on-board flash
  46. */
  47. if (go_bit) {
  48. if (rd_clks == 0x1c)
  49. i = in8(PIXIS_BASE + PIXIS_AUX);
  50. else
  51. i = in8(PIXIS_BASE + PIXIS_SPD);
  52. } else {
  53. i = in8(PIXIS_BASE + PIXIS_SPD);
  54. }
  55. i &= 0x07;
  56. switch (i) {
  57. case 0:
  58. val = 33000000;
  59. break;
  60. case 1:
  61. val = 40000000;
  62. break;
  63. case 2:
  64. val = 50000000;
  65. break;
  66. case 3:
  67. val = 66000000;
  68. break;
  69. case 4:
  70. val = 83000000;
  71. break;
  72. case 5:
  73. val = 100000000;
  74. break;
  75. case 6:
  76. val = 134000000;
  77. break;
  78. case 7:
  79. val = 166000000;
  80. break;
  81. }
  82. return val;
  83. }
  84. void get_sys_info (sys_info_t *sysInfo)
  85. {
  86. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  87. volatile ccsr_gur_t *gur = &immap->im_gur;
  88. uint plat_ratio, e600_ratio;
  89. plat_ratio = (gur->porpllsr) & 0x0000003e;
  90. plat_ratio >>= 1;
  91. switch(plat_ratio) {
  92. case 0x0:
  93. sysInfo->freqSystemBus = 16 * CONFIG_SYS_CLK_FREQ;
  94. break;
  95. case 0x02:
  96. case 0x03:
  97. case 0x04:
  98. case 0x05:
  99. case 0x06:
  100. case 0x08:
  101. case 0x09:
  102. case 0x0a:
  103. case 0x0c:
  104. case 0x10:
  105. sysInfo->freqSystemBus = plat_ratio * CONFIG_SYS_CLK_FREQ;
  106. break;
  107. default:
  108. sysInfo->freqSystemBus = 0;
  109. break;
  110. }
  111. e600_ratio = (gur->porpllsr) & 0x003f0000;
  112. e600_ratio >>= 16;
  113. switch (e600_ratio) {
  114. case 0x10:
  115. sysInfo->freqProcessor = 2 * sysInfo->freqSystemBus;
  116. break;
  117. case 0x19:
  118. sysInfo->freqProcessor = 5 * sysInfo->freqSystemBus/2;
  119. break;
  120. case 0x20:
  121. sysInfo->freqProcessor = 3 * sysInfo->freqSystemBus;
  122. break;
  123. case 0x39:
  124. sysInfo->freqProcessor = 7 * sysInfo->freqSystemBus/2;
  125. break;
  126. case 0x28:
  127. sysInfo->freqProcessor = 4 * sysInfo->freqSystemBus;
  128. break;
  129. case 0x1d:
  130. sysInfo->freqProcessor = 9 * sysInfo->freqSystemBus/2;
  131. break;
  132. default:
  133. sysInfo->freqProcessor = e600_ratio + sysInfo->freqSystemBus;
  134. break;
  135. }
  136. }
  137. /*
  138. * Measure CPU clock speed (core clock GCLK1, GCLK2)
  139. * (Approx. GCLK frequency in Hz)
  140. */
  141. int get_clocks(void)
  142. {
  143. DECLARE_GLOBAL_DATA_PTR;
  144. sys_info_t sys_info;
  145. get_sys_info(&sys_info);
  146. gd->cpu_clk = sys_info.freqProcessor;
  147. gd->bus_clk = sys_info.freqSystemBus;
  148. if (gd->cpu_clk != 0)
  149. return 0;
  150. else
  151. return 1;
  152. }
  153. /*
  154. * get_bus_freq
  155. * Return system bus freq in Hz
  156. */
  157. ulong get_bus_freq(ulong dummy)
  158. {
  159. ulong val;
  160. sys_info_t sys_info;
  161. get_sys_info(&sys_info);
  162. val = sys_info.freqSystemBus;
  163. return val;
  164. }