speed.c 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. /*
  2. * (C) Copyright 2000-2009
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * Copyright (C) 2004-2006 Freescale Semiconductor, Inc.
  6. *
  7. * SPDX-License-Identifier: GPL-2.0+
  8. *
  9. * Based on the MPC83xx code.
  10. */
  11. #include <common.h>
  12. #include <command.h>
  13. #include <asm/io.h>
  14. #include <asm/processor.h>
  15. DECLARE_GLOBAL_DATA_PTR;
  16. static int spmf_mult[] = {
  17. 68, 1, 12, 16,
  18. 20, 24, 28, 32,
  19. 36, 40, 44, 48,
  20. 52, 56, 60, 64
  21. };
  22. static int cpmf_mult[][2] = {
  23. {0, 1}, {0, 1}, /* 0 and 1 are not valid */
  24. {1, 1}, {3, 2},
  25. {2, 1}, {5, 2},
  26. {3, 1}, {7, 2},
  27. {0, 1}, {0, 1}, /* and all above 7 are not valid too */
  28. {0, 1}, {0, 1},
  29. {0, 1}, {0, 1},
  30. {0, 1}, {0, 1}
  31. };
  32. static int sys_dividors[][2] = {
  33. {2, 1}, {5, 2}, {3, 1}, {7, 2}, {4, 1},
  34. {9, 2}, {5, 1}, {7, 1}, {6, 1}, {8, 1},
  35. {9, 1}, {11, 1}, {10, 1}, {12, 1}, {13, 1},
  36. {15, 1}, {14, 1}, {16, 1}, {17, 1}, {19, 1},
  37. {18, 1}, {20, 1}, {21, 1}, {23, 1}, {22, 1},
  38. {24, 1}, {25, 1}, {27, 1}, {26, 1}, {28, 1},
  39. {29, 1}, {31, 1}, {30, 1}, {32, 1}, {33, 1}
  40. };
  41. int get_clocks (void)
  42. {
  43. volatile immap_t *im = (immap_t *) CONFIG_SYS_IMMR;
  44. u8 spmf;
  45. u8 cpmf;
  46. u8 sys_div;
  47. u8 ips_div;
  48. u8 pci_div;
  49. u32 ref_clk = CONFIG_SYS_MPC512X_CLKIN;
  50. u32 spll;
  51. u32 sys_clk;
  52. u32 core_clk;
  53. u32 csb_clk;
  54. u32 ips_clk;
  55. u32 pci_clk;
  56. u32 reg;
  57. reg = in_be32(&im->sysconf.immrbar);
  58. if ((reg & IMMRBAR_BASE_ADDR) != (u32) im)
  59. return -1;
  60. reg = in_be32(&im->clk.spmr);
  61. spmf = (reg & SPMR_SPMF) >> SPMR_SPMF_SHIFT;
  62. spll = ref_clk * spmf_mult[spmf];
  63. reg = in_be32(&im->clk.scfr[1]);
  64. sys_div = (reg & SCFR2_SYS_DIV) >> SCFR2_SYS_DIV_SHIFT;
  65. sys_clk = (spll * sys_dividors[sys_div][1]) / sys_dividors[sys_div][0];
  66. csb_clk = sys_clk / 2;
  67. reg = in_be32(&im->clk.spmr);
  68. cpmf = (reg & SPMR_CPMF) >> SPMR_CPMF_SHIFT;
  69. core_clk = (csb_clk * cpmf_mult[cpmf][0]) / cpmf_mult[cpmf][1];
  70. reg = in_be32(&im->clk.scfr[0]);
  71. ips_div = (reg & SCFR1_IPS_DIV_MASK) >> SCFR1_IPS_DIV_SHIFT;
  72. if (ips_div != 0) {
  73. ips_clk = csb_clk / ips_div;
  74. } else {
  75. /* in case we cannot get a sane IPS divisor, fail gracefully */
  76. ips_clk = 0;
  77. }
  78. reg = in_be32(&im->clk.scfr[0]);
  79. pci_div = (reg & SCFR1_PCI_DIV_MASK) >> SCFR1_PCI_DIV_SHIFT;
  80. if (pci_div != 0) {
  81. pci_clk = csb_clk / pci_div;
  82. } else {
  83. /* in case we cannot get a sane IPS divisor, fail gracefully */
  84. pci_clk = 333333;
  85. }
  86. gd->arch.ips_clk = ips_clk;
  87. gd->pci_clk = pci_clk;
  88. gd->arch.csb_clk = csb_clk;
  89. gd->cpu_clk = core_clk;
  90. gd->bus_clk = csb_clk;
  91. return 0;
  92. }
  93. /********************************************
  94. * get_bus_freq
  95. * return system bus freq in Hz
  96. *********************************************/
  97. ulong get_bus_freq (ulong dummy)
  98. {
  99. return gd->arch.csb_clk;
  100. }
  101. int do_clocks (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
  102. {
  103. char buf[32];
  104. printf("Clock configuration:\n");
  105. printf(" CPU: %-4s MHz\n", strmhz(buf, gd->cpu_clk));
  106. printf(" Coherent System Bus: %-4s MHz\n",
  107. strmhz(buf, gd->arch.csb_clk));
  108. printf(" IPS Bus: %-4s MHz\n",
  109. strmhz(buf, gd->arch.ips_clk));
  110. printf(" PCI: %-4s MHz\n", strmhz(buf, gd->pci_clk));
  111. printf(" DDR: %-4s MHz\n",
  112. strmhz(buf, 2 * gd->arch.csb_clk));
  113. return 0;
  114. }
  115. U_BOOT_CMD(clocks, 1, 0, do_clocks,
  116. "print clock configuration",
  117. " clocks"
  118. );