cpr.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195
  1. /*
  2. * (C) Copyright 2007
  3. * Stefan Roese, DENX Software Engineering, sr@denx.de.
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <asm/processor.h>
  25. #include <ppc405.h>
  26. /* test-only: move into cpu directory!!! */
  27. #if defined(PLLMR0_200_133_66)
  28. void board_pll_init_f(void)
  29. {
  30. /*
  31. * set PLL clocks based on input sysclk is 33M
  32. *
  33. * ----------------------------------
  34. * | CLK | FREQ (MHz) | DIV RATIO |
  35. * ----------------------------------
  36. * | CPU | 200.0 | 4 (0x02)|
  37. * | PLB | 133.3 | 6 (0x06)|
  38. * | OPB | 66.6 | 12 (0x0C)|
  39. * | EBC | 66.6 | 12 (0x0C)|
  40. * | SPI | 66.6 | 12 (0x0C)|
  41. * | UART0 | 10.0 | 40 (0x28)|
  42. * | UART1 | 10.0 | 40 (0x28)|
  43. * | DAC | 2.0 | 200 (0xC8)|
  44. * | ADC | 2.0 | 200 (0xC8)|
  45. * | PWM | 100.0 | 4 (0x04)|
  46. * | EMAC | 25.0 | 16 (0x10)|
  47. * -----------------------------------
  48. */
  49. /* Initialize PLL */
  50. mtcpr(cprpllc, 0x0000033c);
  51. mtcpr(cprplld, 0x0c010200);
  52. mtcpr(cprprimad, 0x04060c0c);
  53. mtcpr(cprperd0, 0x000c0000); /* SPI clk div. eq. OPB clk div. */
  54. mtcpr(cprclkupd, 0x40000000);
  55. }
  56. #elif defined(PLLMR0_266_160_80)
  57. void board_pll_init_f(void)
  58. {
  59. /*
  60. * set PLL clocks based on input sysclk is 33M
  61. *
  62. * ----------------------------------
  63. * | CLK | FREQ (MHz) | DIV RATIO |
  64. * ----------------------------------
  65. * | CPU | 266.64 | 3 |
  66. * | PLB | 159.98 | 5 (0x05)|
  67. * | OPB | 79.99 | 10 (0x0A)|
  68. * | EBC | 79.99 | 10 (0x0A)|
  69. * | SPI | 79.99 | 10 (0x0A)|
  70. * | UART0 | 28.57 | 7 (0x07)|
  71. * | UART1 | 28.57 | 7 (0x07)|
  72. * | DAC | 28.57 | 7 (0xA7)|
  73. * | ADC | 4 | 50 (0x32)|
  74. * | PWM | 28.57 | 7 (0x07)|
  75. * | EMAC | 4 | 50 (0x32)|
  76. * -----------------------------------
  77. */
  78. /* Initialize PLL */
  79. mtcpr(cprpllc, 0x20000238);
  80. mtcpr(cprplld, 0x03010400);
  81. mtcpr(cprprimad, 0x03050a0a);
  82. mtcpr(cprperc0, 0x00000000);
  83. mtcpr(cprperd0, 0x070a0707); /* SPI clk div. eq. OPB clk div. */
  84. mtcpr(cprperd1, 0x07323200);
  85. mtcpr(cprclkupd, 0x40000000);
  86. }
  87. #elif defined(PLLMR0_333_166_83)
  88. void board_pll_init_f(void)
  89. {
  90. /*
  91. * set PLL clocks based on input sysclk is 33M
  92. *
  93. * ----------------------------------
  94. * | CLK | FREQ (MHz) | DIV RATIO |
  95. * ----------------------------------
  96. * | CPU | 333.33 | 2 |
  97. * | PLB | 166.66 | 4 (0x04)|
  98. * | OPB | 83.33 | 8 (0x08)|
  99. * | EBC | 83.33 | 8 (0x08)|
  100. * | SPI | 83.33 | 8 (0x08)|
  101. * | UART0 | 16.66 | 5 (0x05)|
  102. * | UART1 | 16.66 | 5 (0x05)|
  103. * | DAC | ???? | 166 (0xA6)|
  104. * | ADC | ???? | 166 (0xA6)|
  105. * | PWM | 41.66 | 3 (0x03)|
  106. * | EMAC | ???? | 3 (0x03)|
  107. * -----------------------------------
  108. */
  109. /* Initialize PLL */
  110. mtcpr(cprpllc, 0x0000033C);
  111. mtcpr(cprplld, 0x0a010000);
  112. mtcpr(cprprimad, 0x02040808);
  113. mtcpr(cprperd0, 0x02080505); /* SPI clk div. eq. OPB clk div. */
  114. mtcpr(cprperd1, 0xA6A60300);
  115. mtcpr(cprclkupd, 0x40000000);
  116. }
  117. #elif defined(PLLMR0_100_100_12)
  118. void board_pll_init_f(void)
  119. {
  120. /*
  121. * set PLL clocks based on input sysclk is 33M
  122. *
  123. * ----------------------
  124. * | CLK | FREQ (MHz) |
  125. * ----------------------
  126. * | CPU | 100.00 |
  127. * | PLB | 100.00 |
  128. * | OPB | 12.00 |
  129. * | EBC | 49.00 |
  130. * ----------------------
  131. */
  132. /* Initialize PLL */
  133. mtcpr(cprpllc, 0x000003BC);
  134. mtcpr(cprplld, 0x06060600);
  135. mtcpr(cprprimad, 0x02020004);
  136. mtcpr(cprperd0, 0x04002828); /* SPI clk div. eq. OPB clk div. */
  137. mtcpr(cprperd1, 0xC8C81600);
  138. mtcpr(cprclkupd, 0x40000000);
  139. }
  140. #endif /* CPU_<speed>_405EZ */
  141. #if defined(CONFIG_NAND_SPL) || defined(CONFIG_SPI_SPL)
  142. /*
  143. * Get timebase clock frequency
  144. */
  145. unsigned long get_tbclk(void)
  146. {
  147. unsigned long cpr_plld;
  148. unsigned long cpr_primad;
  149. unsigned long primad_cpudv;
  150. unsigned long pllFbkDiv;
  151. unsigned long freqProcessor;
  152. /*
  153. * Read PLL Mode registers
  154. */
  155. mfcpr(cprplld, cpr_plld);
  156. /*
  157. * Read CPR_PRIMAD register
  158. */
  159. mfcpr(cprprimad, cpr_primad);
  160. /*
  161. * Determine CPU clock frequency
  162. */
  163. primad_cpudv = ((cpr_primad & PRIMAD_CPUDV_MASK) >> 24);
  164. if (primad_cpudv == 0)
  165. primad_cpudv = 16;
  166. /*
  167. * Determine FBK_DIV.
  168. */
  169. pllFbkDiv = ((cpr_plld & PLLD_FBDV_MASK) >> 24);
  170. if (pllFbkDiv == 0)
  171. pllFbkDiv = 256;
  172. freqProcessor = (CONFIG_SYS_CLK_FREQ * pllFbkDiv) / primad_cpudv;
  173. return (freqProcessor);
  174. }
  175. #endif /* defined(CONFIG_NAND_SPL) || defined(CONFIG_SPI_SPL) */