speed.c 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217
  1. /*
  2. *
  3. * Copyright (C) 2004-2007 Freescale Semiconductor, Inc.
  4. * TsiChung Liew (Tsi-Chung.Liew@freescale.com)
  5. *
  6. * See file CREDITS for list of people who contributed to this
  7. * project.
  8. *
  9. * This program is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU General Public License as
  11. * published by the Free Software Foundation; either version 2 of
  12. * the License, or (at your option) any later version.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU General Public License
  20. * along with this program; if not, write to the Free Software
  21. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  22. * MA 02111-1307 USA
  23. */
  24. #include <common.h>
  25. #include <asm/processor.h>
  26. #include <asm/immap.h>
  27. DECLARE_GLOBAL_DATA_PTR;
  28. /*
  29. * Low Power Divider specifications
  30. */
  31. #define CLOCK_LPD_MIN (1 << 0) /* Divider (decoded) */
  32. #define CLOCK_LPD_MAX (1 << 15) /* Divider (decoded) */
  33. #define CLOCK_PLL_FVCO_MAX 540000000
  34. #define CLOCK_PLL_FVCO_MIN 300000000
  35. #define CLOCK_PLL_FSYS_MAX 266666666
  36. #define CLOCK_PLL_FSYS_MIN 100000000
  37. #define MHZ 1000000
  38. void clock_enter_limp(int lpdiv)
  39. {
  40. volatile ccm_t *ccm = (volatile ccm_t *)MMAP_CCM;
  41. int i, j;
  42. /* Check bounds of divider */
  43. if (lpdiv < CLOCK_LPD_MIN)
  44. lpdiv = CLOCK_LPD_MIN;
  45. if (lpdiv > CLOCK_LPD_MAX)
  46. lpdiv = CLOCK_LPD_MAX;
  47. /* Round divider down to nearest power of two */
  48. for (i = 0, j = lpdiv; j != 1; j >>= 1, i++) ;
  49. /* Apply the divider to the system clock */
  50. ccm->cdr = (ccm->cdr & 0xF0FF) | CCM_CDR_LPDIV(i);
  51. /* Enable Limp Mode */
  52. ccm->misccr |= CCM_MISCCR_LIMP;
  53. }
  54. /*
  55. * brief Exit Limp mode
  56. * warning The PLL should be set and locked prior to exiting Limp mode
  57. */
  58. void clock_exit_limp(void)
  59. {
  60. volatile ccm_t *ccm = (volatile ccm_t *)MMAP_CCM;
  61. volatile pll_t *pll = (volatile pll_t *)MMAP_PLL;
  62. /* Exit Limp mode */
  63. ccm->misccr &= ~CCM_MISCCR_LIMP;
  64. /* Wait for the PLL to lock */
  65. while (!(pll->psr & PLL_PSR_LOCK)) ;
  66. }
  67. /*
  68. * get_clocks() fills in gd->cpu_clock and gd->bus_clk
  69. */
  70. int get_clocks(void)
  71. {
  72. volatile ccm_t *ccm = (volatile ccm_t *)MMAP_CCM;
  73. volatile pll_t *pll = (volatile pll_t *)MMAP_PLL;
  74. int pllmult_nopci[] = { 20, 10, 24, 18, 12, 6, 16, 8 };
  75. int pllmult_pci[] = { 12, 6, 16, 8 };
  76. int vco = 0, bPci, temp, fbtemp, pcrvalue;
  77. int *pPllmult = NULL;
  78. u16 fbpll_mask;
  79. #ifdef CONFIG_M54455EVB
  80. volatile u8 *cpld = (volatile u8 *)(CFG_CS2_BASE + 3);
  81. #endif
  82. u8 bootmode;
  83. /* To determine PCI is present or not */
  84. if (((ccm->ccr & CCM_CCR_360_FBCONFIG_MASK) == 0x00e0) ||
  85. ((ccm->ccr & CCM_CCR_360_FBCONFIG_MASK) == 0x0060)) {
  86. pPllmult = &pllmult_pci[0];
  87. fbpll_mask = 3; /* 11b */
  88. bPci = 1;
  89. } else {
  90. pPllmult = &pllmult_nopci[0];
  91. fbpll_mask = 7; /* 111b */
  92. #ifdef CONFIG_PCI
  93. gd->pci_clk = 0;
  94. #endif
  95. bPci = 0;
  96. }
  97. #ifdef CONFIG_M54455EVB
  98. bootmode = (*cpld & 0x03);
  99. if (bootmode != 3) {
  100. /* Temporary read from CCR- fixed fb issue, must be the same clock
  101. as pci or input clock, causing cpld/fpga read inconsistancy */
  102. fbtemp = pPllmult[ccm->ccr & fbpll_mask];
  103. /* Break down into small pieces, code still in flex bus */
  104. pcrvalue = pll->pcr & 0xFFFFF0FF;
  105. temp = fbtemp - 1;
  106. pcrvalue |= PLL_PCR_OUTDIV3(temp);
  107. pll->pcr = pcrvalue;
  108. }
  109. #endif
  110. #ifdef CONFIG_M54451EVB
  111. /* No external logic to read the bootmode, hard coded from built */
  112. #ifdef CONFIG_CF_SBF
  113. bootmode = 3;
  114. #else
  115. bootmode = 2;
  116. /* default value is 16 mul, set to 20 mul */
  117. pcrvalue = (pll->pcr & 0x00FFFFFF) | 0x14000000;
  118. pll->pcr = pcrvalue;
  119. while ((pll->psr & PLL_PSR_LOCK) != PLL_PSR_LOCK);
  120. #endif
  121. #endif
  122. if (bootmode == 0) {
  123. /* RCON mode */
  124. vco = pPllmult[ccm->rcon & fbpll_mask] * CFG_INPUT_CLKSRC;
  125. if ((vco < CLOCK_PLL_FVCO_MIN) || (vco > CLOCK_PLL_FVCO_MAX)) {
  126. /* invaild range, re-set in PCR */
  127. int temp = ((pll->pcr & PLL_PCR_OUTDIV2_MASK) >> 4) + 1;
  128. int i, j, bus;
  129. j = (pll->pcr & 0xFF000000) >> 24;
  130. for (i = j; i < 0xFF; i++) {
  131. vco = i * CFG_INPUT_CLKSRC;
  132. if (vco >= CLOCK_PLL_FVCO_MIN) {
  133. bus = vco / temp;
  134. if (bus <= CLOCK_PLL_FSYS_MIN - MHZ)
  135. continue;
  136. else
  137. break;
  138. }
  139. }
  140. pcrvalue = pll->pcr & 0x00FF00FF;
  141. fbtemp = ((i - 1) << 8) | ((i - 1) << 12);
  142. pcrvalue |= ((i << 24) | fbtemp);
  143. pll->pcr = pcrvalue;
  144. }
  145. gd->vco_clk = vco; /* Vco clock */
  146. } else if (bootmode == 2) {
  147. /* Normal mode */
  148. vco = ((pll->pcr & 0xFF000000) >> 24) * CFG_INPUT_CLKSRC;
  149. if ((vco < CLOCK_PLL_FVCO_MIN) || (vco > CLOCK_PLL_FVCO_MAX)) {
  150. /* Default value */
  151. pcrvalue = (pll->pcr & 0x00FFFFFF);
  152. pcrvalue |= pPllmult[ccm->ccr & fbpll_mask] << 24;
  153. pll->pcr = pcrvalue;
  154. vco = ((pll->pcr & 0xFF000000) >> 24) * CFG_INPUT_CLKSRC;
  155. }
  156. gd->vco_clk = vco; /* Vco clock */
  157. } else if (bootmode == 3) {
  158. /* serial mode */
  159. vco = ((pll->pcr & 0xFF000000) >> 24) * CFG_INPUT_CLKSRC;
  160. gd->vco_clk = vco; /* Vco clock */
  161. }
  162. if ((ccm->ccr & CCM_MISCCR_LIMP) == CCM_MISCCR_LIMP) {
  163. /* Limp mode */
  164. } else {
  165. gd->inp_clk = CFG_INPUT_CLKSRC; /* Input clock */
  166. temp = (pll->pcr & PLL_PCR_OUTDIV1_MASK) + 1;
  167. gd->cpu_clk = vco / temp; /* cpu clock */
  168. temp = ((pll->pcr & PLL_PCR_OUTDIV2_MASK) >> 4) + 1;
  169. gd->bus_clk = vco / temp; /* bus clock */
  170. temp = ((pll->pcr & PLL_PCR_OUTDIV3_MASK) >> 8) + 1;
  171. gd->flb_clk = vco / temp; /* FlexBus clock */
  172. #ifdef CONFIG_PCI
  173. if (bPci) {
  174. temp = ((pll->pcr & PLL_PCR_OUTDIV4_MASK) >> 12) + 1;
  175. gd->pci_clk = vco / temp; /* PCI clock */
  176. }
  177. #endif
  178. }
  179. #ifdef CONFIG_FSL_I2C
  180. gd->i2c1_clk = gd->bus_clk;
  181. #endif
  182. return (0);
  183. }