speed.c 2.8 KB

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