speed.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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 <clock_legacy.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. plat_ratio = (gur->porpllsr) & 0x0000003e;
  24. plat_ratio >>= 1;
  25. switch (plat_ratio) {
  26. case 0x0:
  27. sys_info->freq_systembus = 16 * CONFIG_SYS_CLK_FREQ;
  28. break;
  29. case 0x02:
  30. case 0x03:
  31. case 0x04:
  32. case 0x05:
  33. case 0x06:
  34. case 0x08:
  35. case 0x09:
  36. case 0x0a:
  37. case 0x0c:
  38. case 0x10:
  39. sys_info->freq_systembus = plat_ratio * CONFIG_SYS_CLK_FREQ;
  40. break;
  41. default:
  42. sys_info->freq_systembus = 0;
  43. break;
  44. }
  45. e600_ratio = (gur->porpllsr) & 0x003f0000;
  46. e600_ratio >>= 16;
  47. switch (e600_ratio) {
  48. case 0x10:
  49. sys_info->freq_processor = 2 * sys_info->freq_systembus;
  50. break;
  51. case 0x19:
  52. sys_info->freq_processor = 5 * sys_info->freq_systembus / 2;
  53. break;
  54. case 0x20:
  55. sys_info->freq_processor = 3 * sys_info->freq_systembus;
  56. break;
  57. case 0x39:
  58. sys_info->freq_processor = 7 * sys_info->freq_systembus / 2;
  59. break;
  60. case 0x28:
  61. sys_info->freq_processor = 4 * sys_info->freq_systembus;
  62. break;
  63. case 0x1d:
  64. sys_info->freq_processor = 9 * sys_info->freq_systembus / 2;
  65. break;
  66. default:
  67. sys_info->freq_processor = e600_ratio +
  68. sys_info->freq_systembus;
  69. break;
  70. }
  71. sys_info->freq_localbus = sys_info->freq_systembus;
  72. }
  73. /*
  74. * Measure CPU clock speed (core clock GCLK1, GCLK2)
  75. * (Approx. GCLK frequency in Hz)
  76. */
  77. int get_clocks(void)
  78. {
  79. sys_info_t sys_info;
  80. get_sys_info(&sys_info);
  81. gd->cpu_clk = sys_info.freq_processor;
  82. gd->bus_clk = sys_info.freq_systembus;
  83. gd->arch.lbc_clk = sys_info.freq_localbus;
  84. /*
  85. * The base clock for I2C depends on the actual SOC. Unfortunately,
  86. * there is no pattern that can be used to determine the frequency, so
  87. * the only choice is to look up the actual SOC number and use the value
  88. * for that SOC. This information is taken from application note
  89. * AN2919.
  90. */
  91. #ifdef CONFIG_ARCH_MPC8610
  92. gd->arch.i2c1_clk = sys_info.freq_systembus;
  93. #else
  94. gd->arch.i2c1_clk = sys_info.freq_systembus / 2;
  95. #endif
  96. gd->arch.i2c2_clk = gd->arch.i2c1_clk;
  97. if (gd->cpu_clk != 0)
  98. return 0;
  99. else
  100. return 1;
  101. }
  102. /*
  103. * get_bus_freq
  104. * Return system bus freq in Hz
  105. */
  106. ulong get_bus_freq(ulong dummy)
  107. {
  108. ulong val;
  109. sys_info_t sys_info;
  110. get_sys_info(&sys_info);
  111. val = sys_info.freq_systembus;
  112. return val;
  113. }