speed.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  1. /*
  2. * Copyright 2004, 2007-2009 Freescale Semiconductor Inc.
  3. * (C) Copyright 2003 Motorola Inc.
  4. * Xianghua Xiao, (X.Xiao@motorola.com)
  5. *
  6. * (C) Copyright 2000
  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 <ppc_asm.tmpl>
  29. #include <asm/processor.h>
  30. #include <asm/io.h>
  31. DECLARE_GLOBAL_DATA_PTR;
  32. /* --------------------------------------------------------------- */
  33. void get_sys_info (sys_info_t * sysInfo)
  34. {
  35. volatile ccsr_gur_t *gur = (void *)(CONFIG_SYS_MPC85xx_GUTS_ADDR);
  36. uint plat_ratio,e500_ratio,half_freqSystemBus;
  37. uint lcrr_div;
  38. int i;
  39. #ifdef CONFIG_QE
  40. u32 qe_ratio;
  41. #endif
  42. plat_ratio = (gur->porpllsr) & 0x0000003e;
  43. plat_ratio >>= 1;
  44. sysInfo->freqSystemBus = plat_ratio * CONFIG_SYS_CLK_FREQ;
  45. /* Divide before multiply to avoid integer
  46. * overflow for processor speeds above 2GHz */
  47. half_freqSystemBus = sysInfo->freqSystemBus/2;
  48. for (i = 0; i < CONFIG_NUM_CPUS; i++) {
  49. e500_ratio = ((gur->porpllsr) >> (i * 8 + 16)) & 0x3f;
  50. sysInfo->freqProcessor[i] = e500_ratio * half_freqSystemBus;
  51. }
  52. /* Note: freqDDRBus is the MCLK frequency, not the data rate. */
  53. sysInfo->freqDDRBus = sysInfo->freqSystemBus;
  54. #ifdef CONFIG_DDR_CLK_FREQ
  55. {
  56. u32 ddr_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_DDR_RATIO)
  57. >> MPC85xx_PORPLLSR_DDR_RATIO_SHIFT;
  58. if (ddr_ratio != 0x7)
  59. sysInfo->freqDDRBus = ddr_ratio * CONFIG_DDR_CLK_FREQ;
  60. }
  61. #endif
  62. #ifdef CONFIG_QE
  63. qe_ratio = ((gur->porpllsr) & MPC85xx_PORPLLSR_QE_RATIO)
  64. >> MPC85xx_PORPLLSR_QE_RATIO_SHIFT;
  65. sysInfo->freqQE = qe_ratio * CONFIG_SYS_CLK_FREQ;
  66. #endif
  67. #if defined(CONFIG_SYS_LBC_LCRR)
  68. /* We will program LCRR to this value later */
  69. lcrr_div = CONFIG_SYS_LBC_LCRR & LCRR_CLKDIV;
  70. #else
  71. {
  72. volatile ccsr_lbc_t *lbc = (void *)(CONFIG_SYS_MPC85xx_LBC_ADDR);
  73. lcrr_div = in_be32(&lbc->lcrr) & LCRR_CLKDIV;
  74. }
  75. #endif
  76. if (lcrr_div == 2 || lcrr_div == 4 || lcrr_div == 8) {
  77. #if !defined(CONFIG_MPC8540) && !defined(CONFIG_MPC8541) && \
  78. !defined(CONFIG_MPC8555) && !defined(CONFIG_MPC8560)
  79. /*
  80. * Yes, the entire PQ38 family use the same
  81. * bit-representation for twice the clock divider values.
  82. */
  83. lcrr_div *= 2;
  84. #endif
  85. sysInfo->freqLocalBus = sysInfo->freqSystemBus / lcrr_div;
  86. } else {
  87. /* In case anyone cares what the unknown value is */
  88. sysInfo->freqLocalBus = lcrr_div;
  89. }
  90. }
  91. int get_clocks (void)
  92. {
  93. sys_info_t sys_info;
  94. #ifdef CONFIG_MPC8544
  95. volatile ccsr_gur_t *gur = (void *) CONFIG_SYS_MPC85xx_GUTS_ADDR;
  96. #endif
  97. #if defined(CONFIG_CPM2)
  98. volatile ccsr_cpm_t *cpm = (ccsr_cpm_t *)CONFIG_SYS_MPC85xx_CPM_ADDR;
  99. uint sccr, dfbrg;
  100. /* set VCO = 4 * BRG */
  101. cpm->im_cpm_intctl.sccr &= 0xfffffffc;
  102. sccr = cpm->im_cpm_intctl.sccr;
  103. dfbrg = (sccr & SCCR_DFBRG_MSK) >> SCCR_DFBRG_SHIFT;
  104. #endif
  105. get_sys_info (&sys_info);
  106. gd->cpu_clk = sys_info.freqProcessor[0];
  107. gd->bus_clk = sys_info.freqSystemBus;
  108. gd->mem_clk = sys_info.freqDDRBus;
  109. gd->lbc_clk = sys_info.freqLocalBus;
  110. #ifdef CONFIG_QE
  111. gd->qe_clk = sys_info.freqQE;
  112. gd->brg_clk = gd->qe_clk / 2;
  113. #endif
  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. #if defined(CONFIG_MPC8540) || defined(CONFIG_MPC8541) || \
  122. defined(CONFIG_MPC8560) || defined(CONFIG_MPC8555)
  123. gd->i2c1_clk = sys_info.freqSystemBus;
  124. #elif defined(CONFIG_MPC8544)
  125. /*
  126. * On the 8544, the I2C clock is the same as the SEC clock. This can be
  127. * either CCB/2 or CCB/3, depending on the value of cfg_sec_freq. See
  128. * 4.4.3.3 of the 8544 RM. Note that this might actually work for all
  129. * 85xx, but only the 8544 has cfg_sec_freq, so it's unknown if the
  130. * PORDEVSR2_SEC_CFG bit is 0 on all 85xx boards that are not an 8544.
  131. */
  132. if (gur->pordevsr2 & MPC85xx_PORDEVSR2_SEC_CFG)
  133. gd->i2c1_clk = sys_info.freqSystemBus / 3;
  134. else
  135. gd->i2c1_clk = sys_info.freqSystemBus / 2;
  136. #else
  137. /* Most 85xx SOCs use CCB/2, so this is the default behavior. */
  138. gd->i2c1_clk = sys_info.freqSystemBus / 2;
  139. #endif
  140. gd->i2c2_clk = gd->i2c1_clk;
  141. #if defined(CONFIG_MPC8536)
  142. gd->sdhc_clk = gd->bus_clk / 2;
  143. #endif
  144. #if defined(CONFIG_CPM2)
  145. gd->vco_out = 2*sys_info.freqSystemBus;
  146. gd->cpm_clk = gd->vco_out / 2;
  147. gd->scc_clk = gd->vco_out / 4;
  148. gd->brg_clk = gd->vco_out / (1 << (2 * (dfbrg + 1)));
  149. #endif
  150. if(gd->cpu_clk != 0) return (0);
  151. else 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. return gd->bus_clk;
  160. }
  161. /********************************************
  162. * get_ddr_freq
  163. * return ddr bus freq in Hz
  164. *********************************************/
  165. ulong get_ddr_freq (ulong dummy)
  166. {
  167. return gd->mem_clk;
  168. }