speed.c 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  1. /*
  2. * Copyright 2004 Freescale Semiconductor.
  3. * Jeff Brown
  4. * Srikanth Srinivasan (srikanth.srinivasan@freescale.com)
  5. *
  6. * (C) Copyright 2000-2002
  7. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  8. *
  9. * SPDX-License-Identifier: GPL-2.0+
  10. */
  11. #include <common.h>
  12. #include <mpc86xx.h>
  13. #include <asm/processor.h>
  14. #include <asm/io.h>
  15. DECLARE_GLOBAL_DATA_PTR;
  16. /* used in some defintiions of CONFIG_SYS_CLK_FREQ */
  17. extern unsigned long get_board_sys_clk(unsigned long dummy);
  18. void get_sys_info(sys_info_t *sys_info)
  19. {
  20. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  21. volatile ccsr_gur_t *gur = &immap->im_gur;
  22. uint plat_ratio, e600_ratio;
  23. uint lcrr_div;
  24. plat_ratio = (gur->porpllsr) & 0x0000003e;
  25. plat_ratio >>= 1;
  26. switch (plat_ratio) {
  27. case 0x0:
  28. sys_info->freq_systembus = 16 * CONFIG_SYS_CLK_FREQ;
  29. break;
  30. case 0x02:
  31. case 0x03:
  32. case 0x04:
  33. case 0x05:
  34. case 0x06:
  35. case 0x08:
  36. case 0x09:
  37. case 0x0a:
  38. case 0x0c:
  39. case 0x10:
  40. sys_info->freq_systembus = plat_ratio * CONFIG_SYS_CLK_FREQ;
  41. break;
  42. default:
  43. sys_info->freq_systembus = 0;
  44. break;
  45. }
  46. e600_ratio = (gur->porpllsr) & 0x003f0000;
  47. e600_ratio >>= 16;
  48. switch (e600_ratio) {
  49. case 0x10:
  50. sys_info->freq_processor = 2 * sys_info->freq_systembus;
  51. break;
  52. case 0x19:
  53. sys_info->freq_processor = 5 * sys_info->freq_systembus / 2;
  54. break;
  55. case 0x20:
  56. sys_info->freq_processor = 3 * sys_info->freq_systembus;
  57. break;
  58. case 0x39:
  59. sys_info->freq_processor = 7 * sys_info->freq_systembus / 2;
  60. break;
  61. case 0x28:
  62. sys_info->freq_processor = 4 * sys_info->freq_systembus;
  63. break;
  64. case 0x1d:
  65. sys_info->freq_processor = 9 * sys_info->freq_systembus / 2;
  66. break;
  67. default:
  68. sys_info->freq_processor = e600_ratio +
  69. sys_info->freq_systembus;
  70. break;
  71. }
  72. #if defined(CONFIG_SYS_LBC_LCRR)
  73. /* We will program LCRR to this value later */
  74. lcrr_div = CONFIG_SYS_LBC_LCRR & LCRR_CLKDIV;
  75. #else
  76. lcrr_div = in_be32(&immap->im_lbc.lcrr) & LCRR_CLKDIV;
  77. #endif
  78. if (lcrr_div == 2 || lcrr_div == 4 || lcrr_div == 8) {
  79. sys_info->freq_localbus = sys_info->freq_systembus
  80. / (lcrr_div * 2);
  81. } else {
  82. /* In case anyone cares what the unknown value is */
  83. sys_info->freq_localbus = lcrr_div;
  84. }
  85. }
  86. /*
  87. * Measure CPU clock speed (core clock GCLK1, GCLK2)
  88. * (Approx. GCLK frequency in Hz)
  89. */
  90. int get_clocks(void)
  91. {
  92. sys_info_t sys_info;
  93. get_sys_info(&sys_info);
  94. gd->cpu_clk = sys_info.freq_processor;
  95. gd->bus_clk = sys_info.freq_systembus;
  96. gd->arch.lbc_clk = sys_info.freq_localbus;
  97. /*
  98. * The base clock for I2C depends on the actual SOC. Unfortunately,
  99. * there is no pattern that can be used to determine the frequency, so
  100. * the only choice is to look up the actual SOC number and use the value
  101. * for that SOC. This information is taken from application note
  102. * AN2919.
  103. */
  104. #ifdef CONFIG_MPC8610
  105. gd->arch.i2c1_clk = sys_info.freq_systembus;
  106. #else
  107. gd->arch.i2c1_clk = sys_info.freq_systembus / 2;
  108. #endif
  109. gd->arch.i2c2_clk = gd->arch.i2c1_clk;
  110. if (gd->cpu_clk != 0)
  111. return 0;
  112. else
  113. return 1;
  114. }
  115. /*
  116. * get_bus_freq
  117. * Return system bus freq in Hz
  118. */
  119. ulong get_bus_freq(ulong dummy)
  120. {
  121. ulong val;
  122. sys_info_t sys_info;
  123. get_sys_info(&sys_info);
  124. val = sys_info.freq_systembus;
  125. return val;
  126. }