speed.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240
  1. /*
  2. * Copyright 2004 Freescale Semiconductor.
  3. * Jeff Brown (jeffrey@freescale.com)
  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. unsigned long get_board_sys_clk(ulong dummy);
  31. unsigned long get_sysclk_from_px_regs(void);
  32. void get_sys_info (sys_info_t *sysInfo)
  33. {
  34. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  35. volatile ccsr_gur_t *gur = &immap->im_gur;
  36. uint plat_ratio, e600_ratio;
  37. plat_ratio = (gur->porpllsr) & 0x0000003e;
  38. plat_ratio >>= 1;
  39. switch(plat_ratio) {
  40. case 0x0:
  41. sysInfo->freqSystemBus = 16 * CONFIG_SYS_CLK_FREQ;
  42. break;
  43. case 0x02:
  44. case 0x03:
  45. case 0x04:
  46. case 0x05:
  47. case 0x06:
  48. case 0x08:
  49. case 0x09:
  50. case 0x0a:
  51. case 0x0c:
  52. case 0x10:
  53. sysInfo->freqSystemBus = plat_ratio * CONFIG_SYS_CLK_FREQ;
  54. break;
  55. default:
  56. sysInfo->freqSystemBus = 0;
  57. break;
  58. }
  59. #if 0
  60. printf("assigned system bus freq = %d for plat ratio 0x%08lx\n",
  61. sysInfo->freqSystemBus, plat_ratio);
  62. #endif
  63. e600_ratio = (gur->porpllsr) & 0x003f0000;
  64. e600_ratio >>= 16;
  65. switch (e600_ratio) {
  66. case 0x10:
  67. sysInfo->freqProcessor = 2 * sysInfo->freqSystemBus;
  68. break;
  69. case 0x19:
  70. sysInfo->freqProcessor = 5 * sysInfo->freqSystemBus/2;
  71. break;
  72. case 0x20:
  73. sysInfo->freqProcessor = 3 * sysInfo->freqSystemBus;
  74. break;
  75. case 0x39:
  76. sysInfo->freqProcessor = 7 * sysInfo->freqSystemBus/2;
  77. break;
  78. case 0x28:
  79. sysInfo->freqProcessor = 4 * sysInfo->freqSystemBus;
  80. break;
  81. case 0x1d:
  82. sysInfo->freqProcessor = 9 * sysInfo->freqSystemBus/2;
  83. break;
  84. default:
  85. /* JB - Emulator workaround until real cop is plugged in */
  86. /* sysInfo->freqProcessor = 3 * sysInfo->freqSystemBus; */
  87. sysInfo->freqProcessor = e600_ratio + sysInfo->freqSystemBus;
  88. break;
  89. }
  90. #if 0
  91. printf("assigned processor freq = %d for e600 ratio 0x%08lx\n",
  92. sysInfo->freqProcessor, e600_ratio);
  93. #endif
  94. }
  95. /*
  96. * Measure CPU clock speed (core clock GCLK1, GCLK2)
  97. * (Approx. GCLK frequency in Hz)
  98. */
  99. int get_clocks(void)
  100. {
  101. DECLARE_GLOBAL_DATA_PTR;
  102. sys_info_t sys_info;
  103. get_sys_info(&sys_info);
  104. gd->cpu_clk = sys_info.freqProcessor;
  105. gd->bus_clk = sys_info.freqSystemBus;
  106. if (gd->cpu_clk != 0)
  107. return 0;
  108. else
  109. return 1;
  110. }
  111. /*
  112. * get_bus_freq
  113. * Return system bus freq in Hz
  114. */
  115. ulong get_bus_freq(ulong dummy)
  116. {
  117. ulong val;
  118. sys_info_t sys_info;
  119. get_sys_info(&sys_info);
  120. val = sys_info.freqSystemBus;
  121. return val;
  122. }
  123. unsigned long get_sysclk_from_px_regs()
  124. {
  125. ulong val;
  126. u8 vclkh, vclkl;
  127. vclkh = in8(PIXIS_BASE + PIXIS_VCLKH);
  128. vclkl = in8(PIXIS_BASE + PIXIS_VCLKL);
  129. if ((vclkh == 0x84) && (vclkl == 0x07)) {
  130. val = 33000000;
  131. }
  132. if ((vclkh == 0x3F) && (vclkl == 0x20)) {
  133. val = 40000000;
  134. }
  135. if ((vclkh == 0x3F) && (vclkl == 0x2A)) {
  136. val = 50000000;
  137. }
  138. if ((vclkh == 0x24) && (vclkl == 0x04)) {
  139. val = 66000000;
  140. }
  141. if ((vclkh == 0x3F) && (vclkl == 0x4B)) {
  142. val = 83000000;
  143. }
  144. if ((vclkh == 0x3F) && (vclkl == 0x5C)) {
  145. val = 100000000;
  146. }
  147. if ((vclkh == 0xDF) && (vclkl == 0x3B)) {
  148. val = 134000000;
  149. }
  150. if ((vclkh == 0xDF) && (vclkl == 0x4B)) {
  151. val = 166000000;
  152. }
  153. return val;
  154. }
  155. /*
  156. * get_board_sys_clk
  157. * Reads the FPGA on board for CONFIG_SYS_CLK_FREQ
  158. */
  159. unsigned long get_board_sys_clk(ulong dummy)
  160. {
  161. u8 i, go_bit, rd_clks;
  162. ulong val;
  163. go_bit = in8(PIXIS_BASE + PIXIS_VCTL);
  164. go_bit &= 0x01;
  165. rd_clks = in8(PIXIS_BASE + PIXIS_VCFGEN0);
  166. rd_clks &= 0x1C;
  167. /*
  168. * Only if both go bit and the SCLK bit in VCFGEN0 are set
  169. * should we be using the AUX register. Remember, we also set the
  170. * GO bit to boot from the alternate bank on the on-board flash
  171. */
  172. if (go_bit) {
  173. if (rd_clks == 0x1c)
  174. i = in8(PIXIS_BASE + PIXIS_AUX);
  175. else
  176. i = in8(PIXIS_BASE + PIXIS_SPD);
  177. } else {
  178. i = in8(PIXIS_BASE + PIXIS_SPD);
  179. }
  180. i &= 0x07;
  181. switch (i) {
  182. case 0:
  183. val = 33000000;
  184. break;
  185. case 1:
  186. val = 40000000;
  187. break;
  188. case 2:
  189. val = 50000000;
  190. break;
  191. case 3:
  192. val = 66000000;
  193. break;
  194. case 4:
  195. val = 83000000;
  196. break;
  197. case 5:
  198. val = 100000000;
  199. break;
  200. case 6:
  201. val = 134000000;
  202. break;
  203. case 7:
  204. val = 166000000;
  205. break;
  206. }
  207. return val;
  208. }