speed.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  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. #include <asm/io.h>
  31. DECLARE_GLOBAL_DATA_PTR;
  32. /* used in some defintiions of CONFIG_SYS_CLK_FREQ */
  33. extern unsigned long get_board_sys_clk(unsigned long dummy);
  34. void get_sys_info(sys_info_t *sysInfo)
  35. {
  36. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  37. volatile ccsr_gur_t *gur = &immap->im_gur;
  38. uint plat_ratio, e600_ratio;
  39. uint lcrr_div;
  40. plat_ratio = (gur->porpllsr) & 0x0000003e;
  41. plat_ratio >>= 1;
  42. switch (plat_ratio) {
  43. case 0x0:
  44. sysInfo->freqSystemBus = 16 * CONFIG_SYS_CLK_FREQ;
  45. break;
  46. case 0x02:
  47. case 0x03:
  48. case 0x04:
  49. case 0x05:
  50. case 0x06:
  51. case 0x08:
  52. case 0x09:
  53. case 0x0a:
  54. case 0x0c:
  55. case 0x10:
  56. sysInfo->freqSystemBus = plat_ratio * CONFIG_SYS_CLK_FREQ;
  57. break;
  58. default:
  59. sysInfo->freqSystemBus = 0;
  60. break;
  61. }
  62. e600_ratio = (gur->porpllsr) & 0x003f0000;
  63. e600_ratio >>= 16;
  64. switch (e600_ratio) {
  65. case 0x10:
  66. sysInfo->freqProcessor = 2 * sysInfo->freqSystemBus;
  67. break;
  68. case 0x19:
  69. sysInfo->freqProcessor = 5 * sysInfo->freqSystemBus / 2;
  70. break;
  71. case 0x20:
  72. sysInfo->freqProcessor = 3 * sysInfo->freqSystemBus;
  73. break;
  74. case 0x39:
  75. sysInfo->freqProcessor = 7 * sysInfo->freqSystemBus / 2;
  76. break;
  77. case 0x28:
  78. sysInfo->freqProcessor = 4 * sysInfo->freqSystemBus;
  79. break;
  80. case 0x1d:
  81. sysInfo->freqProcessor = 9 * sysInfo->freqSystemBus / 2;
  82. break;
  83. default:
  84. sysInfo->freqProcessor = e600_ratio + sysInfo->freqSystemBus;
  85. break;
  86. }
  87. #if defined(CONFIG_SYS_LBC_LCRR)
  88. /* We will program LCRR to this value later */
  89. lcrr_div = CONFIG_SYS_LBC_LCRR & LCRR_CLKDIV;
  90. #else
  91. {
  92. volatile ccsr_lbc_t *lbc = &immap->im_lbc;
  93. lcrr_div = in_be32(&lbc->lcrr) & LCRR_CLKDIV;
  94. }
  95. #endif
  96. if (lcrr_div == 2 || lcrr_div == 4 || lcrr_div == 8) {
  97. sysInfo->freqLocalBus = sysInfo->freqSystemBus / (lcrr_div * 2);
  98. } else {
  99. /* In case anyone cares what the unknown value is */
  100. sysInfo->freqLocalBus = lcrr_div;
  101. }
  102. }
  103. /*
  104. * Measure CPU clock speed (core clock GCLK1, GCLK2)
  105. * (Approx. GCLK frequency in Hz)
  106. */
  107. int get_clocks(void)
  108. {
  109. sys_info_t sys_info;
  110. get_sys_info(&sys_info);
  111. gd->cpu_clk = sys_info.freqProcessor;
  112. gd->bus_clk = sys_info.freqSystemBus;
  113. gd->lbc_clk = sys_info.freqLocalBus;
  114. /*
  115. * The base clock for I2C depends on the actual SOC. Unfortunately,
  116. * there is no pattern that can be used to determine the frequency, so
  117. * the only choice is to look up the actual SOC number and use the value
  118. * for that SOC. This information is taken from application note
  119. * AN2919.
  120. */
  121. #ifdef CONFIG_MPC8610
  122. gd->i2c1_clk = sys_info.freqSystemBus;
  123. #else
  124. gd->i2c1_clk = sys_info.freqSystemBus / 2;
  125. #endif
  126. gd->i2c2_clk = gd->i2c1_clk;
  127. if (gd->cpu_clk != 0)
  128. return 0;
  129. else
  130. return 1;
  131. }
  132. /*
  133. * get_bus_freq
  134. * Return system bus freq in Hz
  135. */
  136. ulong get_bus_freq(ulong dummy)
  137. {
  138. ulong val;
  139. sys_info_t sys_info;
  140. get_sys_info(&sys_info);
  141. val = sys_info.freqSystemBus;
  142. return val;
  143. }