speed.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. /*
  2. * Copyright 2004 Freescale Semiconductor.
  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. DECLARE_GLOBAL_DATA_PTR;
  31. /* --------------------------------------------------------------- */
  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,e500_ratio,half_freqSystemBus;
  37. plat_ratio = (gur->porpllsr) & 0x0000003e;
  38. plat_ratio >>= 1;
  39. sysInfo->freqSystemBus = plat_ratio * CONFIG_SYS_CLK_FREQ;
  40. e500_ratio = (gur->porpllsr) & 0x003f0000;
  41. e500_ratio >>= 16;
  42. /* Divide before multiply to avoid integer
  43. * overflow for processor speeds above 2GHz */
  44. half_freqSystemBus = sysInfo->freqSystemBus/2;
  45. sysInfo->freqProcessor = e500_ratio*half_freqSystemBus;
  46. }
  47. int get_clocks (void)
  48. {
  49. sys_info_t sys_info;
  50. #if defined(CONFIG_CPM2)
  51. volatile immap_t *immap = (immap_t *) CFG_IMMR;
  52. uint sccr, dfbrg;
  53. /* set VCO = 4 * BRG */
  54. immap->im_cpm.im_cpm_intctl.sccr &= 0xfffffffc;
  55. sccr = immap->im_cpm.im_cpm_intctl.sccr;
  56. dfbrg = (sccr & SCCR_DFBRG_MSK) >> SCCR_DFBRG_SHIFT;
  57. #endif
  58. get_sys_info (&sys_info);
  59. gd->cpu_clk = sys_info.freqProcessor;
  60. gd->bus_clk = sys_info.freqSystemBus;
  61. #if defined(CONFIG_CPM2)
  62. gd->vco_out = 2*sys_info.freqSystemBus;
  63. gd->cpm_clk = gd->vco_out / 2;
  64. gd->scc_clk = gd->vco_out / 4;
  65. gd->brg_clk = gd->vco_out / (1 << (2 * (dfbrg + 1)));
  66. #endif
  67. if(gd->cpu_clk != 0) return (0);
  68. else return (1);
  69. }
  70. /********************************************
  71. * get_bus_freq
  72. * return system bus freq in Hz
  73. *********************************************/
  74. ulong get_bus_freq (ulong dummy)
  75. {
  76. ulong val;
  77. sys_info_t sys_info;
  78. get_sys_info (&sys_info);
  79. val = sys_info.freqSystemBus;
  80. return val;
  81. }