speed.c 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * (C) Copyright 2003
  3. * Martin Winistoerfer, martinwinistoerfer@gmx.ch.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation,
  21. */
  22. /*
  23. * File: speed.c
  24. *
  25. * Discription: Provides cpu speed calculation
  26. *
  27. */
  28. #include <common.h>
  29. #include <mpc5xx.h>
  30. #include <asm/processor.h>
  31. DECLARE_GLOBAL_DATA_PTR;
  32. /*
  33. * Get cpu and bus clock
  34. */
  35. int get_clocks (void)
  36. {
  37. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  38. #ifndef CONFIG_5xx_GCLK_FREQ
  39. uint divf = (immr->im_clkrst.car_plprcr & PLPRCR_DIVF_MSK);
  40. uint mf = ((immr->im_clkrst.car_plprcr & PLPRCR_MF_MSK) >> PLPRCR_MF_SHIFT);
  41. ulong vcoout;
  42. vcoout = (CONFIG_SYS_OSC_CLK / (divf + 1)) * (mf + 1) * 2;
  43. if(immr->im_clkrst.car_plprcr & PLPRCR_CSRC_MSK) {
  44. gd->cpu_clk = vcoout / (2^(((immr->im_clkrst.car_sccr & SCCR_DFNL_MSK) >> SCCR_DFNL_SHIFT) + 1));
  45. } else {
  46. gd->cpu_clk = vcoout / (2^(immr->im_clkrst.car_sccr & SCCR_DFNH_MSK));
  47. }
  48. #else /* CONFIG_5xx_GCLK_FREQ */
  49. gd->bus_clk = CONFIG_5xx_GCLK_FREQ;
  50. #endif /* CONFIG_5xx_GCLK_FREQ */
  51. if ((immr->im_clkrst.car_sccr & SCCR_EBDF11) == 0) {
  52. /* No Bus Divider active */
  53. gd->bus_clk = gd->cpu_clk;
  54. } else {
  55. /* CLKOUT is GCLK / 2 */
  56. gd->bus_clk = gd->cpu_clk / 2;
  57. }
  58. return (0);
  59. }