speed.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * (C) Copyright 2003 Motorola Inc.
  3. * Xianghua Xiao, (X.Xiao@motorola.com)
  4. *
  5. * (C) Copyright 2000
  6. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <ppc_asm.tmpl>
  28. #include <asm/processor.h>
  29. /* --------------------------------------------------------------- */
  30. #define ONE_BILLION 1000000000
  31. void get_sys_info (sys_info_t * sysInfo)
  32. {
  33. volatile immap_t *immap = (immap_t *)CFG_IMMR;
  34. volatile ccsr_gur_t *gur = &immap->im_gur;
  35. uint plat_ratio,e500_ratio;
  36. plat_ratio = (gur->porpllsr) & 0x0000003e;
  37. plat_ratio >>= 1;
  38. switch(plat_ratio) {
  39. case 0x02:
  40. case 0x03:
  41. case 0x04:
  42. case 0x05:
  43. case 0x06:
  44. case 0x08:
  45. case 0x09:
  46. case 0x0a:
  47. case 0x0c:
  48. case 0x10:
  49. sysInfo->freqSystemBus = plat_ratio * CONFIG_SYS_CLK_FREQ;
  50. break;
  51. default:
  52. sysInfo->freqSystemBus = 0;
  53. break;
  54. }
  55. e500_ratio = (gur->porpllsr) & 0x003f0000;
  56. e500_ratio >>= 16;
  57. switch(e500_ratio) {
  58. case 0x04:
  59. sysInfo->freqProcessor = 2*sysInfo->freqSystemBus;
  60. break;
  61. case 0x05:
  62. sysInfo->freqProcessor = 5*sysInfo->freqSystemBus/2;
  63. break;
  64. case 0x06:
  65. sysInfo->freqProcessor = 3*sysInfo->freqSystemBus;
  66. break;
  67. case 0x07:
  68. sysInfo->freqProcessor = 7*sysInfo->freqSystemBus/2;
  69. break;
  70. default:
  71. sysInfo->freqProcessor = 0;
  72. break;
  73. }
  74. }
  75. int get_clocks (void)
  76. {
  77. DECLARE_GLOBAL_DATA_PTR;
  78. sys_info_t sys_info;
  79. #if defined(CONFIG_MPC8560)
  80. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  81. uint sccr, dfbrg;
  82. /* set VCO = 4 * BRG */
  83. immap->im_cpm.im_cpm_intctl.sccr &= 0xfffffffc;
  84. sccr = immap->im_cpm.im_cpm_intctl.sccr;
  85. dfbrg = (sccr & SCCR_DFBRG_MSK) >> SCCR_DFBRG_SHIFT;
  86. #endif
  87. get_sys_info (&sys_info);
  88. gd->cpu_clk = sys_info.freqProcessor;
  89. gd->bus_clk = sys_info.freqSystemBus;
  90. #if defined(CONFIG_MPC8560)
  91. gd->vco_out = 2*sys_info.freqSystemBus;
  92. gd->cpm_clk = gd->vco_out / 2;
  93. gd->scc_clk = gd->vco_out / 4;
  94. gd->brg_clk = gd->vco_out / (1 << (2 * (dfbrg + 1)));
  95. #endif
  96. if(gd->cpu_clk != 0) return (0);
  97. else return (1);
  98. }
  99. /********************************************
  100. * get_bus_freq
  101. * return system bus freq in Hz
  102. *********************************************/
  103. ulong get_bus_freq (ulong dummy)
  104. {
  105. ulong val;
  106. sys_info_t sys_info;
  107. get_sys_info (&sys_info);
  108. val = sys_info.freqSystemBus;
  109. return val;
  110. }