speed.c 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /*
  2. * (C) Copyright 2003
  3. * Josef Baumgartner <josef.baumgartner@telex.de>
  4. *
  5. * Copyright (C) 2004-2007 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. DECLARE_GLOBAL_DATA_PTR;
  30. /*
  31. * get_clocks() fills in gd->cpu_clock and gd->bus_clk
  32. */
  33. int get_clocks (void)
  34. {
  35. #if defined(CONFIG_M5249) || defined(CONFIG_M5253)
  36. volatile unsigned long cpll = mbar2_readLong(MCFSIM_PLLCR);
  37. unsigned long pllcr;
  38. #ifndef CFG_PLL_BYPASS
  39. #ifdef CONFIG_M5249
  40. /* Setup the PLL to run at the specified speed */
  41. #ifdef CFG_FAST_CLK
  42. pllcr = 0x925a3100; /* ~140MHz clock (PLL bypass = 0) */
  43. #else
  44. pllcr = 0x135a4140; /* ~72MHz clock (PLL bypass = 0) */
  45. #endif
  46. #endif /* CONFIG_M5249 */
  47. #ifdef CONFIG_M5253
  48. pllcr = CFG_PLLCR;
  49. #endif /* CONFIG_M5253 */
  50. cpll = cpll & 0xfffffffe; /* Set PLL bypass mode = 0 (PSTCLK = crystal) */
  51. mbar2_writeLong(MCFSIM_PLLCR, cpll); /* Set the PLL to bypass mode (PSTCLK = crystal) */
  52. mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* set the clock speed */
  53. pllcr ^= 0x00000001; /* Set pll bypass to 1 */
  54. mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* Start locking (pll bypass = 1) */
  55. udelay(0x20); /* Wait for a lock ... */
  56. #endif /* #ifndef CFG_PLL_BYPASS */
  57. #endif /* CONFIG_M5249 || CONFIG_M5253 */
  58. #if defined(CONFIG_M5275)
  59. volatile pll_t *pll = (volatile pll_t *)(MMAP_PLL);
  60. /* Setup PLL */
  61. pll->syncr = 0x01080000;
  62. while (!(pll->synsr & FMPLL_SYNSR_LOCK)
  63. ;
  64. pll->syncr = 0x01000000;
  65. while (!(pll->synsr & FMPLL_SYNSR_LOCK))
  66. ;
  67. #endif
  68. gd->cpu_clk = CFG_CLK;
  69. #if defined(CONFIG_M5249) || defined(CONFIG_M5253) || defined(CONFIG_M5275)
  70. gd->bus_clk = gd->cpu_clk / 2;
  71. #else
  72. gd->bus_clk = gd->cpu_clk;
  73. #endif
  74. return (0);
  75. }