speed.c 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. /*
  2. * (C) Copyright 2000-2002
  3. * Wolfgang Denk, DENX Software Engineering, wd@denx.de.
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <mpc8260.h>
  9. #include <asm/processor.h>
  10. #if defined(CONFIG_BOARD_GET_CPU_CLK_F)
  11. extern unsigned long board_get_cpu_clk_f (void);
  12. #endif
  13. DECLARE_GLOBAL_DATA_PTR;
  14. /* ------------------------------------------------------------------------- */
  15. /* Bus-to-Core Multiplier */
  16. #define _1x 2
  17. #define _1_5x 3
  18. #define _2x 4
  19. #define _2_5x 5
  20. #define _3x 6
  21. #define _3_5x 7
  22. #define _4x 8
  23. #define _4_5x 9
  24. #define _5x 10
  25. #define _5_5x 11
  26. #define _6x 12
  27. #define _6_5x 13
  28. #define _7x 14
  29. #define _7_5x 15
  30. #define _8x 16
  31. #define _byp -1
  32. #define _off -2
  33. #define _unk -3
  34. typedef struct {
  35. int b2c_mult;
  36. int vco_div;
  37. char *freq_60x;
  38. char *freq_core;
  39. } corecnf_t;
  40. /*
  41. * this table based on "Errata to MPC8260 PowerQUICC II User's Manual",
  42. * Rev. 1, 8/2000, page 10.
  43. */
  44. corecnf_t corecnf_tab[] = {
  45. { _1_5x, 4, " 33-100", " 33-100" }, /* 0x00 */
  46. { _1x, 4, " 50-150", " 50-150" }, /* 0x01 */
  47. { _1x, 8, " 25-75 ", " 25-75 " }, /* 0x02 */
  48. { _byp, -1, " ?-? ", " ?-? " }, /* 0x03 */
  49. { _2x, 2, " 50-150", "100-300" }, /* 0x04 */
  50. { _2x, 4, " 25-75 ", " 50-150" }, /* 0x05 */
  51. { _2_5x, 2, " 40-120", "100-240" }, /* 0x06 */
  52. { _4_5x, 2, " 22-65 ", "100-300" }, /* 0x07 */
  53. { _3x, 2, " 33-100", "100-300" }, /* 0x08 */
  54. { _5_5x, 2, " 18-55 ", "100-300" }, /* 0x09 */
  55. { _4x, 2, " 25-75 ", "100-300" }, /* 0x0A */
  56. { _5x, 2, " 20-60 ", "100-300" }, /* 0x0B */
  57. { _1_5x, 8, " 16-50 ", " 16-50 " }, /* 0x0C */
  58. { _6x, 2, " 16-50 ", "100-300" }, /* 0x0D */
  59. { _3_5x, 2, " 30-85 ", "100-300" }, /* 0x0E */
  60. { _off, -1, " ?-? ", " ?-? " }, /* 0x0F */
  61. { _3x, 4, " 16-50 ", " 50-150" }, /* 0x10 */
  62. { _2_5x, 4, " 20-60 ", " 50-120" }, /* 0x11 */
  63. { _6_5x, 2, " 15-46 ", "100-300" }, /* 0x12 */
  64. { _byp, -1, " ?-? ", " ?-? " }, /* 0x13 */
  65. { _7x, 2, " 14-43 ", "100-300" }, /* 0x14 */
  66. { _2x, 4, " 25-75 ", " 50-150" }, /* 0x15 */
  67. { _7_5x, 2, " 13-40 ", "100-300" }, /* 0x16 */
  68. { _4_5x, 2, " 22-65 ", "100-300" }, /* 0x17 */
  69. { _unk, -1, " ?-? ", " ?-? " }, /* 0x18 */
  70. { _5_5x, 2, " 18-55 ", "100-300" }, /* 0x19 */
  71. { _4x, 2, " 25-75 ", "100-300" }, /* 0x1A */
  72. { _5x, 2, " 20-60 ", "100-300" }, /* 0x1B */
  73. { _8x, 2, " 12-38 ", "100-300" }, /* 0x1C */
  74. { _6x, 2, " 16-50 ", "100-300" }, /* 0x1D */
  75. { _3_5x, 2, " 30-85 ", "100-300" }, /* 0x1E */
  76. { _off, -1, " ?-? ", " ?-? " }, /* 0x1F */
  77. };
  78. /* ------------------------------------------------------------------------- */
  79. /*
  80. *
  81. */
  82. int get_clocks (void)
  83. {
  84. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  85. ulong clkin;
  86. ulong sccr, dfbrg;
  87. ulong scmr, corecnf, plldf, pllmf;
  88. corecnf_t *cp;
  89. #if !defined(CONFIG_8260_CLKIN)
  90. #error clock measuring not implemented yet - define CONFIG_8260_CLKIN
  91. #else
  92. #if defined(CONFIG_BOARD_GET_CPU_CLK_F)
  93. clkin = board_get_cpu_clk_f ();
  94. #else
  95. clkin = CONFIG_8260_CLKIN;
  96. #endif
  97. #endif
  98. sccr = immap->im_clkrst.car_sccr;
  99. dfbrg = (sccr & SCCR_DFBRG_MSK) >> SCCR_DFBRG_SHIFT;
  100. scmr = immap->im_clkrst.car_scmr;
  101. corecnf = (scmr & SCMR_CORECNF_MSK) >> SCMR_CORECNF_SHIFT;
  102. cp = &corecnf_tab[corecnf];
  103. /* HiP7, HiP7 Rev01, HiP7 RevA */
  104. if ((get_pvr () == PVR_8260_HIP7) ||
  105. (get_pvr () == PVR_8260_HIP7R1) ||
  106. (get_pvr () == PVR_8260_HIP7RA)) {
  107. pllmf = (scmr & SCMR_PLLMF_MSKH7) >> SCMR_PLLMF_SHIFT;
  108. gd->arch.vco_out = clkin * (pllmf + 1);
  109. } else { /* HiP3, HiP4 */
  110. pllmf = (scmr & SCMR_PLLMF_MSK) >> SCMR_PLLMF_SHIFT;
  111. plldf = (scmr & SCMR_PLLDF) ? 1 : 0;
  112. gd->arch.vco_out = (clkin * 2 * (pllmf + 1)) / (plldf + 1);
  113. }
  114. gd->arch.cpm_clk = gd->arch.vco_out / 2;
  115. gd->bus_clk = clkin;
  116. gd->arch.scc_clk = gd->arch.vco_out / 4;
  117. gd->arch.brg_clk = gd->arch.vco_out / (1 << (2 * (dfbrg + 1)));
  118. if (cp->b2c_mult > 0) {
  119. gd->cpu_clk = (clkin * cp->b2c_mult) / 2;
  120. } else {
  121. gd->cpu_clk = clkin;
  122. }
  123. #ifdef CONFIG_PCI
  124. gd->pci_clk = clkin;
  125. if (sccr & SCCR_PCI_MODE) {
  126. uint pci_div;
  127. uint pcidf = (sccr & SCCR_PCIDF_MSK) >> SCCR_PCIDF_SHIFT;
  128. if (sccr & SCCR_PCI_MODCK) {
  129. pci_div = 2;
  130. if (pcidf == 9) {
  131. pci_div *= 5;
  132. } else if (pcidf == 0xB) {
  133. pci_div *= 6;
  134. } else {
  135. pci_div *= (pcidf + 1);
  136. }
  137. } else {
  138. pci_div = pcidf + 1;
  139. }
  140. gd->pci_clk = (gd->arch.cpm_clk * 2) / pci_div;
  141. }
  142. #endif
  143. return (0);
  144. }
  145. int prt_8260_clks (void)
  146. {
  147. volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
  148. ulong sccr, dfbrg;
  149. ulong scmr, corecnf, busdf, cpmdf, plldf, pllmf, pcidf;
  150. corecnf_t *cp;
  151. sccr = immap->im_clkrst.car_sccr;
  152. dfbrg = (sccr & SCCR_DFBRG_MSK) >> SCCR_DFBRG_SHIFT;
  153. scmr = immap->im_clkrst.car_scmr;
  154. corecnf = (scmr & SCMR_CORECNF_MSK) >> SCMR_CORECNF_SHIFT;
  155. busdf = (scmr & SCMR_BUSDF_MSK) >> SCMR_BUSDF_SHIFT;
  156. cpmdf = (scmr & SCMR_CPMDF_MSK) >> SCMR_CPMDF_SHIFT;
  157. plldf = (scmr & SCMR_PLLDF) ? 1 : 0;
  158. pllmf = (scmr & SCMR_PLLMF_MSK) >> SCMR_PLLMF_SHIFT;
  159. pcidf = (sccr & SCCR_PCIDF_MSK) >> SCCR_PCIDF_SHIFT;
  160. cp = &corecnf_tab[corecnf];
  161. puts (CPU_ID_STR " Clock Configuration\n - Bus-to-Core Mult ");
  162. switch (cp->b2c_mult) {
  163. case _byp:
  164. puts ("BYPASS");
  165. break;
  166. case _off:
  167. puts ("OFF");
  168. break;
  169. case _unk:
  170. puts ("UNKNOWN");
  171. break;
  172. default:
  173. printf ("%d%sx",
  174. cp->b2c_mult / 2,
  175. (cp->b2c_mult % 2) ? ".5" : "");
  176. break;
  177. }
  178. printf (", VCO Div %d, 60x Bus Freq %s, Core Freq %s\n",
  179. cp->vco_div, cp->freq_60x, cp->freq_core);
  180. printf (" - dfbrg %ld, corecnf 0x%02lx, busdf %ld, cpmdf %ld, "
  181. "plldf %ld, pllmf %ld, pcidf %ld\n",
  182. dfbrg, corecnf, busdf, cpmdf,
  183. plldf, pllmf, pcidf);
  184. printf (" - vco_out %10ld, scc_clk %10ld, brg_clk %10ld\n",
  185. gd->arch.vco_out, gd->arch.scc_clk, gd->arch.brg_clk);
  186. printf (" - cpu_clk %10ld, cpm_clk %10ld, bus_clk %10ld\n",
  187. gd->cpu_clk, gd->arch.cpm_clk, gd->bus_clk);
  188. #ifdef CONFIG_PCI
  189. printf (" - pci_clk %10ld\n", gd->pci_clk);
  190. #endif
  191. putc ('\n');
  192. return (0);
  193. }