speed.c 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297
  1. /*
  2. *
  3. * Copyright (C) 2004-2007, 2012 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. #include <asm/io.h>
  28. DECLARE_GLOBAL_DATA_PTR;
  29. /*
  30. * Low Power Divider specifications
  31. */
  32. #define CLOCK_LPD_MIN (1 << 0) /* Divider (decoded) */
  33. #define CLOCK_LPD_MAX (1 << 15) /* Divider (decoded) */
  34. #define CLOCK_PLL_FVCO_MAX 540000000
  35. #define CLOCK_PLL_FVCO_MIN 300000000
  36. #define CLOCK_PLL_FSYS_MAX 266666666
  37. #define CLOCK_PLL_FSYS_MIN 100000000
  38. #define MHZ 1000000
  39. void clock_enter_limp(int lpdiv)
  40. {
  41. ccm_t *ccm = (ccm_t *)MMAP_CCM;
  42. int i, j;
  43. /* Check bounds of divider */
  44. if (lpdiv < CLOCK_LPD_MIN)
  45. lpdiv = CLOCK_LPD_MIN;
  46. if (lpdiv > CLOCK_LPD_MAX)
  47. lpdiv = CLOCK_LPD_MAX;
  48. /* Round divider down to nearest power of two */
  49. for (i = 0, j = lpdiv; j != 1; j >>= 1, i++) ;
  50. #ifdef CONFIG_MCF5445x
  51. /* Apply the divider to the system clock */
  52. clrsetbits_be16(&ccm->cdr, 0x0f00, CCM_CDR_LPDIV(i));
  53. #endif
  54. /* Enable Limp Mode */
  55. setbits_be16(&ccm->misccr, CCM_MISCCR_LIMP);
  56. }
  57. /*
  58. * brief Exit Limp mode
  59. * warning The PLL should be set and locked prior to exiting Limp mode
  60. */
  61. void clock_exit_limp(void)
  62. {
  63. ccm_t *ccm = (ccm_t *)MMAP_CCM;
  64. pll_t *pll = (pll_t *)MMAP_PLL;
  65. /* Exit Limp mode */
  66. clrbits_be16(&ccm->misccr, CCM_MISCCR_LIMP);
  67. /* Wait for the PLL to lock */
  68. while (!(in_be32(&pll->psr) & PLL_PSR_LOCK))
  69. ;
  70. }
  71. #ifdef CONFIG_MCF5441x
  72. void setup_5441x_clocks(void)
  73. {
  74. ccm_t *ccm = (ccm_t *)MMAP_CCM;
  75. pll_t *pll = (pll_t *)MMAP_PLL;
  76. int temp, vco = 0, bootmod_ccr, pdr;
  77. bootmod_ccr = (in_be16(&ccm->ccr) & CCM_CCR_BOOTMOD) >> 14;
  78. switch (bootmod_ccr) {
  79. case 0:
  80. out_be32(&pll->pcr, 0x00000013);
  81. out_be32(&pll->pdr, 0x00e70c61);
  82. clock_exit_limp();
  83. break;
  84. case 2:
  85. break;
  86. case 3:
  87. break;
  88. }
  89. /*Change frequency for Modelo SER1 USB host*/
  90. #ifdef CONFIG_LOW_MCFCLK
  91. temp = in_be32(&pll->pcr);
  92. temp &= ~0x3f;
  93. temp |= 5;
  94. out_be32(&pll->pcr, temp);
  95. temp = in_be32(&pll->pdr);
  96. temp &= ~0x001f0000;
  97. temp |= 0x00040000;
  98. out_be32(&pll->pdr, temp);
  99. __asm__("tpf");
  100. #endif
  101. setbits_be16(&ccm->misccr2, 0x02);
  102. vco = ((in_be32(&pll->pcr) & PLL_CR_FBKDIV_BITS) + 1) *
  103. CONFIG_SYS_INPUT_CLKSRC;
  104. gd->vco_clk = vco;
  105. gd->inp_clk = CONFIG_SYS_INPUT_CLKSRC; /* Input clock */
  106. pdr = in_be32(&pll->pdr);
  107. temp = (pdr & PLL_DR_OUTDIV1_BITS) + 1;
  108. gd->cpu_clk = vco / temp; /* cpu clock */
  109. gd->flb_clk = vco / temp; /* FlexBus clock */
  110. gd->flb_clk >>= 1;
  111. if (in_be16(ccm->misccr2) & 2) /* fsys/4 */
  112. gd->flb_clk >>= 1;
  113. temp = ((pdr & PLL_DR_OUTDIV2_BITS) >> 5) + 1;
  114. gd->bus_clk = vco / temp; /* bus clock */
  115. }
  116. #endif
  117. #ifdef CONFIG_MCF5445x
  118. void setup_5445x_clocks(void)
  119. {
  120. ccm_t *ccm = (ccm_t *)MMAP_CCM;
  121. pll_t *pll = (pll_t *)MMAP_PLL;
  122. int pllmult_nopci[] = { 20, 10, 24, 18, 12, 6, 16, 8 };
  123. int pllmult_pci[] = { 12, 6, 16, 8 };
  124. int vco = 0, temp, fbtemp, pcrvalue;
  125. int *pPllmult = NULL;
  126. u16 fbpll_mask;
  127. #ifdef CONFIG_PCI
  128. int bPci;
  129. #endif
  130. #ifdef CONFIG_M54455EVB
  131. u8 *cpld = (u8 *)(CONFIG_SYS_CS2_BASE + 3);
  132. #endif
  133. u8 bootmode;
  134. /* To determine PCI is present or not */
  135. if (((in_be16(&ccm->ccr) & CCM_CCR_360_FBCONFIG_MASK) == 0x00e0) ||
  136. ((in_be16(&ccm->ccr) & CCM_CCR_360_FBCONFIG_MASK) == 0x0060)) {
  137. pPllmult = &pllmult_pci[0];
  138. fbpll_mask = 3; /* 11b */
  139. #ifdef CONFIG_PCI
  140. bPci = 1;
  141. #endif
  142. } else {
  143. pPllmult = &pllmult_nopci[0];
  144. fbpll_mask = 7; /* 111b */
  145. #ifdef CONFIG_PCI
  146. gd->pci_clk = 0;
  147. bPci = 0;
  148. #endif
  149. }
  150. #ifdef CONFIG_M54455EVB
  151. bootmode = (in_8(cpld) & 0x03);
  152. if (bootmode != 3) {
  153. /* Temporary read from CCR- fixed fb issue, must be the same clock
  154. as pci or input clock, causing cpld/fpga read inconsistancy */
  155. fbtemp = pPllmult[ccm->ccr & fbpll_mask];
  156. /* Break down into small pieces, code still in flex bus */
  157. pcrvalue = in_be32(&pll->pcr) & 0xFFFFF0FF;
  158. temp = fbtemp - 1;
  159. pcrvalue |= PLL_PCR_OUTDIV3(temp);
  160. out_be32(&pll->pcr, pcrvalue);
  161. }
  162. #endif
  163. #ifdef CONFIG_M54451EVB
  164. /* No external logic to read the bootmode, hard coded from built */
  165. #ifdef CONFIG_CF_SBF
  166. bootmode = 3;
  167. #else
  168. bootmode = 2;
  169. /* default value is 16 mul, set to 20 mul */
  170. pcrvalue = (in_be32(&pll->pcr) & 0x00FFFFFF) | 0x14000000;
  171. out_be32(&pll->pcr, pcrvalue);
  172. while ((in_be32(&pll->psr) & PLL_PSR_LOCK) != PLL_PSR_LOCK)
  173. ;
  174. #endif
  175. #endif
  176. if (bootmode == 0) {
  177. /* RCON mode */
  178. vco = pPllmult[ccm->rcon & fbpll_mask] * CONFIG_SYS_INPUT_CLKSRC;
  179. if ((vco < CLOCK_PLL_FVCO_MIN) || (vco > CLOCK_PLL_FVCO_MAX)) {
  180. /* invaild range, re-set in PCR */
  181. int temp = ((in_be32(&pll->pcr) & PLL_PCR_OUTDIV2_MASK) >> 4) + 1;
  182. int i, j, bus;
  183. j = (in_be32(&pll->pcr) & 0xFF000000) >> 24;
  184. for (i = j; i < 0xFF; i++) {
  185. vco = i * CONFIG_SYS_INPUT_CLKSRC;
  186. if (vco >= CLOCK_PLL_FVCO_MIN) {
  187. bus = vco / temp;
  188. if (bus <= CLOCK_PLL_FSYS_MIN - MHZ)
  189. continue;
  190. else
  191. break;
  192. }
  193. }
  194. pcrvalue = in_be32(&pll->pcr) & 0x00FF00FF;
  195. fbtemp = ((i - 1) << 8) | ((i - 1) << 12);
  196. pcrvalue |= ((i << 24) | fbtemp);
  197. out_be32(&pll->pcr, pcrvalue);
  198. }
  199. gd->vco_clk = vco; /* Vco clock */
  200. } else if (bootmode == 2) {
  201. /* Normal mode */
  202. vco = ((in_be32(&pll->pcr) & 0xFF000000) >> 24) * CONFIG_SYS_INPUT_CLKSRC;
  203. if ((vco < CLOCK_PLL_FVCO_MIN) || (vco > CLOCK_PLL_FVCO_MAX)) {
  204. /* Default value */
  205. pcrvalue = (in_be32(&pll->pcr) & 0x00FFFFFF);
  206. pcrvalue |= pPllmult[in_be16(&ccm->ccr) & fbpll_mask] << 24;
  207. out_be32(&pll->pcr, pcrvalue);
  208. vco = ((in_be32(&pll->pcr) & 0xFF000000) >> 24) * CONFIG_SYS_INPUT_CLKSRC;
  209. }
  210. gd->vco_clk = vco; /* Vco clock */
  211. } else if (bootmode == 3) {
  212. /* serial mode */
  213. vco = ((in_be32(&pll->pcr) & 0xFF000000) >> 24) * CONFIG_SYS_INPUT_CLKSRC;
  214. gd->vco_clk = vco; /* Vco clock */
  215. }
  216. if ((in_be16(&ccm->ccr) & CCM_MISCCR_LIMP) == CCM_MISCCR_LIMP) {
  217. /* Limp mode */
  218. } else {
  219. gd->inp_clk = CONFIG_SYS_INPUT_CLKSRC; /* Input clock */
  220. temp = (in_be32(&pll->pcr) & PLL_PCR_OUTDIV1_MASK) + 1;
  221. gd->cpu_clk = vco / temp; /* cpu clock */
  222. temp = ((in_be32(&pll->pcr) & PLL_PCR_OUTDIV2_MASK) >> 4) + 1;
  223. gd->bus_clk = vco / temp; /* bus clock */
  224. temp = ((in_be32(&pll->pcr) & PLL_PCR_OUTDIV3_MASK) >> 8) + 1;
  225. gd->flb_clk = vco / temp; /* FlexBus clock */
  226. #ifdef CONFIG_PCI
  227. if (bPci) {
  228. temp = ((in_be32(&pll->pcr) & PLL_PCR_OUTDIV4_MASK) >> 12) + 1;
  229. gd->pci_clk = vco / temp; /* PCI clock */
  230. }
  231. #endif
  232. }
  233. #ifdef CONFIG_FSL_I2C
  234. gd->arch.i2c1_clk = gd->bus_clk;
  235. #endif
  236. }
  237. #endif
  238. /* get_clocks() fills in gd->cpu_clock and gd->bus_clk */
  239. int get_clocks(void)
  240. {
  241. #ifdef CONFIG_MCF5441x
  242. setup_5441x_clocks();
  243. #endif
  244. #ifdef CONFIG_MCF5445x
  245. setup_5445x_clocks();
  246. #endif
  247. #ifdef CONFIG_FSL_I2C
  248. gd->arch.i2c1_clk = gd->bus_clk;
  249. #endif
  250. return (0);
  251. }