speed.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. /*
  2. * (C) Copyright 2001
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * (C) Copyright 2002
  6. * Gregory E. Allen, gallen@arlut.utexas.edu
  7. * Applied Research Laboratories, The University of Texas at Austin
  8. *
  9. * See file CREDITS for list of people who contributed to this
  10. * project.
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License as
  14. * published by the Free Software Foundation; either version 2 of
  15. * the License, or (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program; if not, write to the Free Software
  24. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  25. * MA 02111-1307 USA
  26. */
  27. #include <common.h>
  28. #include <mpc824x.h>
  29. #include <asm/processor.h>
  30. /* ------------------------------------------------------------------------- */
  31. /* NOTE: This describes the proper use of this file.
  32. *
  33. * CONFIG_SYS_CLK_FREQ should be defined as the input frequency on
  34. * PCI_SYNC_IN .
  35. *
  36. * CONFIG_PLL_PCI_TO_MEM_MULTIPLIER is only required on MPC8240
  37. * boards. It should be defined as the PCI to Memory Multiplier as
  38. * documented in the MPC8240 Hardware Specs.
  39. *
  40. * Other mpc824x boards don't need CONFIG_PLL_PCI_TO_MEM_MULTIPLIER
  41. * because they can determine it from the PCR.
  42. *
  43. * Gary Milliorn <gary.milliorn@motorola.com> (who should know since
  44. * he designed the Sandpoint) told us that the PCR is not in all revs
  45. * of the MPC8240 CPU, so it's not guaranteeable and we cannot do
  46. * away with CONFIG_PLL_PCI_TO_MEM_MULTIPLIER altogether.
  47. */
  48. /* ------------------------------------------------------------------------- */
  49. /* This gives the PCI to Memory multiplier times 10 */
  50. /* The index is the value of PLL_CFG[0:4] */
  51. /* This is documented in the MPC8240/5 Hardware Specs */
  52. short pll_pci_to_mem_multiplier[] = {
  53. #if defined(CONFIG_MPC8240)
  54. 30, 30, 10, 10, 20, 10, 0, 10,
  55. 10, 0, 20, 0, 20, 0, 20, 0,
  56. 30, 0, 15, 0, 20, 0, 20, 0,
  57. 25, 0, 10, 0, 15, 15, 0, 0,
  58. #elif defined(CONFIG_MPC8245)
  59. 30, 30, 10, 10, 20, 10, 10, 10,
  60. 10, 20, 20, 15, 20, 15, 20, 30,
  61. 30, 40, 15, 40, 20, 25, 20, 40,
  62. 25, 20, 10, 20, 15, 15, 15, 0,
  63. #else
  64. #error Specific type of MPC824x must be defined (i.e. CONFIG_MPC8240)
  65. #endif
  66. };
  67. #define CU824_PLL_STATE_REG 0xFE80002F
  68. #define PCR 0x800000E2
  69. /* ------------------------------------------------------------------------- */
  70. /* compute the memory bus clock frequency */
  71. ulong get_bus_freq (ulong dummy)
  72. {
  73. unsigned char pll_cfg;
  74. #if defined(CONFIG_MPC8240) && !defined(CONFIG_CU824)
  75. return (CONFIG_SYS_CLK_FREQ) * (CONFIG_PLL_PCI_TO_MEM_MULTIPLIER);
  76. #elif defined(CONFIG_CU824)
  77. pll_cfg = *(volatile unsigned char *) (CU824_PLL_STATE_REG);
  78. pll_cfg &= 0x1f;
  79. #else
  80. CONFIG_READ_BYTE(PCR, pll_cfg);
  81. pll_cfg = (pll_cfg >> 3) & 0x1f;
  82. #endif
  83. return ((CONFIG_SYS_CLK_FREQ) * pll_pci_to_mem_multiplier[pll_cfg] + 5) / 10;
  84. }
  85. /* ------------------------------------------------------------------------- */
  86. /* This gives the Memory to CPU Core multiplier times 10 */
  87. /* The index is the value of PLLRATIO in HID1 */
  88. /* This is documented in the MPC8240 Hardware Specs */
  89. /* This is not documented for MPC8245 ? FIXME */
  90. short pllratio_to_factor[] = {
  91. 0, 0, 0, 10, 20, 20, 25, 45,
  92. 30, 0, 0, 0, 0, 0, 0, 0,
  93. 0, 0, 0, 10, 0, 0, 0, 45,
  94. 30, 0, 40, 0, 0, 0, 35, 0,
  95. };
  96. /* compute the CPU and memory bus clock frequencies */
  97. int get_clocks (void)
  98. {
  99. DECLARE_GLOBAL_DATA_PTR;
  100. uint hid1 = mfspr(HID1);
  101. hid1 = (hid1 >> (32-5)) & 0x1f;
  102. gd->cpu_clk = (pllratio_to_factor[hid1] * get_bus_freq(0) + 5)
  103. / 10;
  104. gd->bus_clk = get_bus_freq(0);
  105. return (0);
  106. }