speed.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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. #ifdef MPC8641HPCN
  31. /*
  32. * get_board_sys_clk
  33. * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
  34. */
  35. unsigned long get_board_sys_clk(ulong dummy)
  36. {
  37. u8 i, go_bit, rd_clks;
  38. ulong val = 0;
  39. go_bit = in8(PIXIS_BASE + PIXIS_VCTL);
  40. go_bit &= 0x01;
  41. rd_clks = in8(PIXIS_BASE + PIXIS_VCFGEN0);
  42. rd_clks &= 0x1C;
  43. /*
  44. * Only if both go bit and the SCLK bit in VCFGEN0 are set
  45. * should we be using the AUX register. Remember, we also set the
  46. * GO bit to boot from the alternate bank on the on-board flash
  47. */
  48. if (go_bit) {
  49. if (rd_clks == 0x1c)
  50. i = in8(PIXIS_BASE + PIXIS_AUX);
  51. else
  52. i = in8(PIXIS_BASE + PIXIS_SPD);
  53. } else {
  54. i = in8(PIXIS_BASE + PIXIS_SPD);
  55. }
  56. i &= 0x07;
  57. switch (i) {
  58. case 0:
  59. val = 33000000;
  60. break;
  61. case 1:
  62. val = 40000000;
  63. break;
  64. case 2:
  65. val = 50000000;
  66. break;
  67. case 3:
  68. val = 66000000;
  69. break;
  70. case 4:
  71. val = 83000000;
  72. break;
  73. case 5:
  74. val = 100000000;
  75. break;
  76. case 6:
  77. val = 134000000;
  78. break;
  79. case 7:
  80. val = 166000000;
  81. break;
  82. }
  83. return val;
  84. }
  85. #endif
  86. void get_sys_info (sys_info_t *sysInfo)
  87. {
  88. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  89. volatile ccsr_gur_t *gur = &immap->im_gur;
  90. uint plat_ratio, e600_ratio;
  91. plat_ratio = (gur->porpllsr) & 0x0000003e;
  92. plat_ratio >>= 1;
  93. switch(plat_ratio) {
  94. case 0x0:
  95. sysInfo->freqSystemBus = 16 * CONFIG_SYS_CLK_FREQ;
  96. break;
  97. case 0x02:
  98. case 0x03:
  99. case 0x04:
  100. case 0x05:
  101. case 0x06:
  102. case 0x08:
  103. case 0x09:
  104. case 0x0a:
  105. case 0x0c:
  106. case 0x10:
  107. sysInfo->freqSystemBus = plat_ratio * CONFIG_SYS_CLK_FREQ;
  108. break;
  109. default:
  110. sysInfo->freqSystemBus = 0;
  111. break;
  112. }
  113. e600_ratio = (gur->porpllsr) & 0x003f0000;
  114. e600_ratio >>= 16;
  115. switch (e600_ratio) {
  116. case 0x10:
  117. sysInfo->freqProcessor = 2 * sysInfo->freqSystemBus;
  118. break;
  119. case 0x19:
  120. sysInfo->freqProcessor = 5 * sysInfo->freqSystemBus/2;
  121. break;
  122. case 0x20:
  123. sysInfo->freqProcessor = 3 * sysInfo->freqSystemBus;
  124. break;
  125. case 0x39:
  126. sysInfo->freqProcessor = 7 * sysInfo->freqSystemBus/2;
  127. break;
  128. case 0x28:
  129. sysInfo->freqProcessor = 4 * sysInfo->freqSystemBus;
  130. break;
  131. case 0x1d:
  132. sysInfo->freqProcessor = 9 * sysInfo->freqSystemBus/2;
  133. break;
  134. default:
  135. sysInfo->freqProcessor = e600_ratio + sysInfo->freqSystemBus;
  136. break;
  137. }
  138. }
  139. /*
  140. * Measure CPU clock speed (core clock GCLK1, GCLK2)
  141. * (Approx. GCLK frequency in Hz)
  142. */
  143. int get_clocks(void)
  144. {
  145. DECLARE_GLOBAL_DATA_PTR;
  146. sys_info_t sys_info;
  147. get_sys_info(&sys_info);
  148. gd->cpu_clk = sys_info.freqProcessor;
  149. gd->bus_clk = sys_info.freqSystemBus;
  150. if (gd->cpu_clk != 0)
  151. return 0;
  152. else
  153. return 1;
  154. }
  155. /*
  156. * get_bus_freq
  157. * Return system bus freq in Hz
  158. */
  159. ulong get_bus_freq(ulong dummy)
  160. {
  161. ulong val;
  162. sys_info_t sys_info;
  163. get_sys_info(&sys_info);
  164. val = sys_info.freqSystemBus;
  165. return val;
  166. }