speed.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. * (C) Copyright 2003
  3. * Martin Winistoerfer, martinwinistoerfer@gmx.ch.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. /*
  8. * File: speed.c
  9. *
  10. * Discription: Provides cpu speed calculation
  11. *
  12. */
  13. #include <common.h>
  14. #include <mpc5xx.h>
  15. #include <asm/processor.h>
  16. DECLARE_GLOBAL_DATA_PTR;
  17. /*
  18. * Get cpu and bus clock
  19. */
  20. int get_clocks (void)
  21. {
  22. volatile immap_t *immr = (immap_t *) CONFIG_SYS_IMMR;
  23. #ifndef CONFIG_5xx_GCLK_FREQ
  24. uint divf = (immr->im_clkrst.car_plprcr & PLPRCR_DIVF_MSK);
  25. uint mf = ((immr->im_clkrst.car_plprcr & PLPRCR_MF_MSK) >> PLPRCR_MF_SHIFT);
  26. ulong vcoout;
  27. vcoout = (CONFIG_SYS_OSC_CLK / (divf + 1)) * (mf + 1) * 2;
  28. if(immr->im_clkrst.car_plprcr & PLPRCR_CSRC_MSK) {
  29. gd->cpu_clk = vcoout / (2^(((immr->im_clkrst.car_sccr & SCCR_DFNL_MSK) >> SCCR_DFNL_SHIFT) + 1));
  30. } else {
  31. gd->cpu_clk = vcoout / (2^(immr->im_clkrst.car_sccr & SCCR_DFNH_MSK));
  32. }
  33. #else /* CONFIG_5xx_GCLK_FREQ */
  34. gd->bus_clk = CONFIG_5xx_GCLK_FREQ;
  35. #endif /* CONFIG_5xx_GCLK_FREQ */
  36. if ((immr->im_clkrst.car_sccr & SCCR_EBDF11) == 0) {
  37. /* No Bus Divider active */
  38. gd->bus_clk = gd->cpu_clk;
  39. } else {
  40. /* CLKOUT is GCLK / 2 */
  41. gd->bus_clk = gd->cpu_clk / 2;
  42. }
  43. return (0);
  44. }