speed.c 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /*
  2. * (C) Copyright 2003
  3. * Josef Baumgartner <josef.baumgartner@telex.de>
  4. *
  5. * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
  6. * Hayden Fraser (Hayden.Fraser@freescale.com)
  7. *
  8. * See file CREDITS for list of people who contributed to this
  9. * project.
  10. *
  11. * This program is free software; you can redistribute it and/or
  12. * modify it under the terms of the GNU General Public License as
  13. * published by the Free Software Foundation; either version 2 of
  14. * the License, or (at your option) any later version.
  15. *
  16. * This program is distributed in the hope that it will be useful,
  17. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  19. * GNU General Public License for more details.
  20. *
  21. * You should have received a copy of the GNU General Public License
  22. * along with this program; if not, write to the Free Software
  23. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  24. * MA 02111-1307 USA
  25. */
  26. #include <common.h>
  27. #include <asm/processor.h>
  28. #include <asm/immap.h>
  29. #include <asm/io.h>
  30. DECLARE_GLOBAL_DATA_PTR;
  31. /* get_clocks() fills in gd->cpu_clock and gd->bus_clk */
  32. int get_clocks (void)
  33. {
  34. #if defined(CONFIG_M5208)
  35. pll_t *pll = (pll_t *) MMAP_PLL;
  36. out_8(&pll->odr, CONFIG_SYS_PLL_ODR);
  37. out_8(&pll->fdr, CONFIG_SYS_PLL_FDR);
  38. #endif
  39. #if defined(CONFIG_M5249) || defined(CONFIG_M5253)
  40. volatile unsigned long cpll = mbar2_readLong(MCFSIM_PLLCR);
  41. unsigned long pllcr;
  42. #ifndef CONFIG_SYS_PLL_BYPASS
  43. #ifdef CONFIG_M5249
  44. /* Setup the PLL to run at the specified speed */
  45. #ifdef CONFIG_SYS_FAST_CLK
  46. pllcr = 0x925a3100; /* ~140MHz clock (PLL bypass = 0) */
  47. #else
  48. pllcr = 0x135a4140; /* ~72MHz clock (PLL bypass = 0) */
  49. #endif
  50. #endif /* CONFIG_M5249 */
  51. #ifdef CONFIG_M5253
  52. pllcr = CONFIG_SYS_PLLCR;
  53. #endif /* CONFIG_M5253 */
  54. cpll = cpll & 0xfffffffe; /* Set PLL bypass mode = 0 (PSTCLK = crystal) */
  55. mbar2_writeLong(MCFSIM_PLLCR, cpll); /* Set the PLL to bypass mode (PSTCLK = crystal) */
  56. mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* set the clock speed */
  57. pllcr ^= 0x00000001; /* Set pll bypass to 1 */
  58. mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* Start locking (pll bypass = 1) */
  59. udelay(0x20); /* Wait for a lock ... */
  60. #endif /* #ifndef CONFIG_SYS_PLL_BYPASS */
  61. #endif /* CONFIG_M5249 || CONFIG_M5253 */
  62. #if defined(CONFIG_M5275)
  63. pll_t *pll = (pll_t *)(MMAP_PLL);
  64. /* Setup PLL */
  65. out_be32(&pll->syncr, 0x01080000);
  66. while (!(in_be32(&pll->synsr) & FMPLL_SYNSR_LOCK))
  67. ;
  68. out_be32(&pll->syncr, 0x01000000);
  69. while (!(in_be32(&pll->synsr) & FMPLL_SYNSR_LOCK))
  70. ;
  71. #endif
  72. gd->cpu_clk = CONFIG_SYS_CLK;
  73. #if defined(CONFIG_M5208) || defined(CONFIG_M5249) || defined(CONFIG_M5253) || \
  74. defined(CONFIG_M5271) || defined(CONFIG_M5275)
  75. gd->bus_clk = gd->cpu_clk / 2;
  76. #else
  77. gd->bus_clk = gd->cpu_clk;
  78. #endif
  79. #ifdef CONFIG_FSL_I2C
  80. gd->i2c1_clk = gd->bus_clk;
  81. #ifdef CONFIG_SYS_I2C2_OFFSET
  82. gd->i2c2_clk = gd->bus_clk;
  83. #endif
  84. #endif
  85. return (0);
  86. }