clock.c 3.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include <common.h>
  2. #include <asm/arch/sysctl.h>
  3. #include <asm/arch/cpu.h>
  4. #include <asm/arch/clock.h>
  5. typedef struct {
  6. unsigned short mhz;
  7. unsigned char refdiv;
  8. unsigned char outdiv;
  9. unsigned int fbdiv;
  10. unsigned short bwadj;
  11. unsigned short sfreq;
  12. unsigned int sslope;
  13. } PLL_CONFIG;
  14. const PLL_CONFIG C_PLL_CONFIG[] = {
  15. { 500, 1, 2, 3932160, 119, 208, 189 }, // 500 MHz
  16. { 525, 2, 1, 4128768, 125, 139, 297 }, // 525 MHz
  17. { 550, 2, 1, 4325376, 131, 139, 311 }, // 550 MHz
  18. { 575, 2, 1, 4521984, 137, 139, 326 }, // 575 MHz
  19. { 600, 2, 1, 4718592, 143, 138, 339 }, // 600 MHz
  20. { 625, 1, 1, 3276800, 99, 208, 157 }, // 625 MHz
  21. { 650, 1, 1, 3407872, 103, 208, 164 }, // 650 MHz
  22. { 675, 1, 1, 3538944, 107, 208, 170 }, // 675 MHz
  23. { 700, 0, 0, 917504, 27, 416, 22 }, // 700 MHz
  24. { 725, 1, 1, 3801088, 115, 208, 182 }, // 725 MHz
  25. { 750, 0, 0, 983040, 29, 416, 23 }, // 750 MHz
  26. { 775, 3, 0, 4063232, 123, 104, 390 }, // 775 MHz
  27. { 800, 3, 0, 4194304, 127, 104, 403 }, // 800 MHz
  28. { 825, 3, 0, 4325376, 131, 104, 415 }, // 825 MHz
  29. { 850, 2, 0, 3342336, 101, 139, 241 }, // 850 MHz
  30. { 875, 2, 0, 3440640, 104, 139, 248 }, // 875 MHz
  31. { 900, 2, 0, 3538944, 107, 139, 255 }, // 900 MHz
  32. { 925, 2, 0, 3637248, 110, 139, 262 }, // 925 MHz
  33. { 950, 2, 0, 3735552, 113, 139, 269 }, // 950 MHz
  34. { 975, 2, 0, 3833856, 116, 139, 276 }, // 975 MHz
  35. { 1000, 2, 0, 3932160, 119, 139, 283 }, // 1000 MHz
  36. };
  37. #define PLL_BYPASS (1<<1)
  38. #define SAT_ENABLE (1<<3)
  39. #define PLL_OUTDIV_SHIFT 4
  40. #define PLL_REFDIV_SHIFT 8
  41. #define PLL_BWADJ_SHIFT 16
  42. #define PLL_LOW_FREQ 500
  43. #define PLL_FREQ_STEP 25
  44. static void plla_configure(int outdiv, int refdiv, int fbdiv, int bwadj,
  45. int sfreq, int sslope)
  46. {
  47. setbits_le32(SYS_CTRL_PLLA_CTRL0, PLL_BYPASS);
  48. udelay(10);
  49. reset_block(SYS_CTRL_RST_PLLA, 1);
  50. udelay(10);
  51. writel((refdiv << PLL_REFDIV_SHIFT) | (outdiv << PLL_OUTDIV_SHIFT) |
  52. SAT_ENABLE | PLL_BYPASS,
  53. SYS_CTRL_PLLA_CTRL0);
  54. writel(fbdiv, SYS_CTRL_PLLA_CTRL1);
  55. writel((bwadj << PLL_BWADJ_SHIFT) | sfreq, SYS_CTRL_PLLA_CTRL2);
  56. writel(sslope, SYS_CTRL_PLLA_CTRL3);
  57. udelay(10); // 5us delay required (from TCI datasheet), use 10us
  58. reset_block(SYS_CTRL_RST_PLLA, 0);
  59. udelay(100); // Delay for PLL to lock
  60. printf(" plla_ctrl0 : %08x\n", readl(SYS_CTRL_PLLA_CTRL0));
  61. printf(" plla_ctrl1 : %08x\n", readl(SYS_CTRL_PLLA_CTRL1));
  62. printf(" plla_ctrl2 : %08x\n", readl(SYS_CTRL_PLLA_CTRL2));
  63. printf(" plla_ctrl3 : %08x\n", readl(SYS_CTRL_PLLA_CTRL3));
  64. clrbits_le32(SYS_CTRL_PLLA_CTRL0, PLL_BYPASS); // Take PLL out of bypass
  65. puts("\nPLLA Set\n");
  66. }
  67. int plla_set_config(int mhz)
  68. {
  69. int index = (mhz - PLL_LOW_FREQ) / PLL_FREQ_STEP;
  70. const PLL_CONFIG *cfg;
  71. if (index < 0 || index > ARRAY_SIZE(C_PLL_CONFIG)) {
  72. debug("Freq %d MHz out of range, default to lowest\n", mhz);
  73. index = 0;
  74. }
  75. cfg = &C_PLL_CONFIG[index];
  76. printf("Attempting to set PLLA to %d MHz ...\n", (unsigned) cfg->mhz);
  77. plla_configure(cfg->outdiv, cfg->refdiv, cfg->fbdiv, cfg->bwadj,
  78. cfg->sfreq, cfg->sslope);
  79. return cfg->mhz;
  80. }