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. DECLARE_GLOBAL_DATA_PTR;
  31. /* ------------------------------------------------------------------------- */
  32. /* NOTE: This describes the proper use of this file.
  33. *
  34. * CONFIG_SYS_CLK_FREQ should be defined as the input frequency on
  35. * PCI_SYNC_IN .
  36. *
  37. * CONFIG_PLL_PCI_TO_MEM_MULTIPLIER is only required on MPC8240
  38. * boards. It should be defined as the PCI to Memory Multiplier as
  39. * documented in the MPC8240 Hardware Specs.
  40. *
  41. * Other mpc824x boards don't need CONFIG_PLL_PCI_TO_MEM_MULTIPLIER
  42. * because they can determine it from the PCR.
  43. *
  44. * Gary Milliorn <gary.milliorn@motorola.com> (who should know since
  45. * he designed the Sandpoint) told us that the PCR is not in all revs
  46. * of the MPC8240 CPU, so it's not guaranteeable and we cannot do
  47. * away with CONFIG_PLL_PCI_TO_MEM_MULTIPLIER altogether.
  48. */
  49. /* ------------------------------------------------------------------------- */
  50. /* This gives the PCI to Memory multiplier times 10 */
  51. /* The index is the value of PLL_CFG[0:4] */
  52. /* This is documented in the MPC8240/5 Hardware Specs */
  53. short pll_pci_to_mem_multiplier[] = {
  54. #if defined(CONFIG_MPC8240)
  55. 30, 30, 10, 10, 20, 10, 0, 10,
  56. 10, 0, 20, 0, 20, 0, 20, 0,
  57. 30, 0, 15, 0, 20, 0, 20, 0,
  58. 25, 0, 10, 0, 15, 15, 0, 0,
  59. #elif defined(CONFIG_MPC8245)
  60. 30, 30, 10, 10, 20, 10, 10, 10,
  61. 10, 20, 20, 15, 20, 15, 20, 30,
  62. 30, 40, 15, 40, 20, 25, 20, 40,
  63. 25, 20, 10, 20, 15, 15, 15, 0,
  64. #else
  65. #error Specific type of MPC824x must be defined (i.e. CONFIG_MPC8240)
  66. #endif
  67. };
  68. #define CU824_PLL_STATE_REG 0xFE80002F
  69. #define PCR 0x800000E2
  70. /* ------------------------------------------------------------------------- */
  71. /* compute the memory bus clock frequency */
  72. ulong get_bus_freq (ulong dummy)
  73. {
  74. unsigned char pll_cfg;
  75. #if defined(CONFIG_MPC8240) && !defined(CONFIG_CU824)
  76. return (CONFIG_SYS_CLK_FREQ) * (CONFIG_PLL_PCI_TO_MEM_MULTIPLIER);
  77. #elif defined(CONFIG_CU824)
  78. pll_cfg = *(volatile unsigned char *) (CU824_PLL_STATE_REG);
  79. pll_cfg &= 0x1f;
  80. #else
  81. CONFIG_READ_BYTE(PCR, pll_cfg);
  82. pll_cfg = (pll_cfg >> 3) & 0x1f;
  83. #endif
  84. return ((CONFIG_SYS_CLK_FREQ) * pll_pci_to_mem_multiplier[pll_cfg] + 5) / 10;
  85. }
  86. /* ------------------------------------------------------------------------- */
  87. /* This gives the Memory to CPU Core multiplier times 10 */
  88. /* The index is the value of PLLRATIO in HID1 */
  89. /* This is documented in the MPC8240 Hardware Specs */
  90. /* This is not documented for MPC8245 ? FIXME */
  91. short pllratio_to_factor[] = {
  92. 0, 0, 0, 10, 20, 20, 25, 45,
  93. 30, 0, 0, 0, 0, 0, 0, 0,
  94. 0, 0, 0, 10, 0, 0, 0, 45,
  95. 30, 0, 40, 0, 0, 0, 35, 0,
  96. };
  97. /* compute the CPU and memory bus clock frequencies */
  98. int get_clocks (void)
  99. {
  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. }