speed.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * (C) Copyright 2003
  4. * Josef Baumgartner <josef.baumgartner@telex.de>
  5. *
  6. * Copyright (C) 2004-2007, 2012 Freescale Semiconductor, Inc.
  7. * Hayden Fraser (Hayden.Fraser@freescale.com)
  8. */
  9. #include <common.h>
  10. #include <asm/processor.h>
  11. #include <asm/immap.h>
  12. #include <asm/io.h>
  13. DECLARE_GLOBAL_DATA_PTR;
  14. /* get_clocks() fills in gd->cpu_clock and gd->bus_clk */
  15. int get_clocks (void)
  16. {
  17. #if defined(CONFIG_M5208)
  18. pll_t *pll = (pll_t *) MMAP_PLL;
  19. out_8(&pll->odr, CONFIG_SYS_PLL_ODR);
  20. out_8(&pll->fdr, CONFIG_SYS_PLL_FDR);
  21. #endif
  22. #if defined(CONFIG_M5249) || defined(CONFIG_M5253)
  23. volatile unsigned long cpll = mbar2_readLong(MCFSIM_PLLCR);
  24. unsigned long pllcr;
  25. #ifndef CONFIG_SYS_PLL_BYPASS
  26. #ifdef CONFIG_M5249
  27. /* Setup the PLL to run at the specified speed */
  28. #ifdef CONFIG_SYS_FAST_CLK
  29. pllcr = 0x925a3100; /* ~140MHz clock (PLL bypass = 0) */
  30. #else
  31. pllcr = 0x135a4140; /* ~72MHz clock (PLL bypass = 0) */
  32. #endif
  33. #endif /* CONFIG_M5249 */
  34. #ifdef CONFIG_M5253
  35. pllcr = CONFIG_SYS_PLLCR;
  36. #endif /* CONFIG_M5253 */
  37. cpll = cpll & 0xfffffffe; /* Set PLL bypass mode = 0 (PSTCLK = crystal) */
  38. mbar2_writeLong(MCFSIM_PLLCR, cpll); /* Set the PLL to bypass mode (PSTCLK = crystal) */
  39. mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* set the clock speed */
  40. pllcr ^= 0x00000001; /* Set pll bypass to 1 */
  41. mbar2_writeLong(MCFSIM_PLLCR, pllcr); /* Start locking (pll bypass = 1) */
  42. udelay(0x20); /* Wait for a lock ... */
  43. #endif /* #ifndef CONFIG_SYS_PLL_BYPASS */
  44. #endif /* CONFIG_M5249 || CONFIG_M5253 */
  45. #if defined(CONFIG_M5275)
  46. pll_t *pll = (pll_t *)(MMAP_PLL);
  47. /* Setup PLL */
  48. out_be32(&pll->syncr, 0x01080000);
  49. while (!(in_be32(&pll->synsr) & FMPLL_SYNSR_LOCK))
  50. ;
  51. out_be32(&pll->syncr, 0x01000000);
  52. while (!(in_be32(&pll->synsr) & FMPLL_SYNSR_LOCK))
  53. ;
  54. #endif
  55. gd->cpu_clk = CONFIG_SYS_CLK;
  56. #if defined(CONFIG_M5208) || defined(CONFIG_M5249) || defined(CONFIG_M5253) || \
  57. defined(CONFIG_M5271) || defined(CONFIG_M5275)
  58. gd->bus_clk = gd->cpu_clk / 2;
  59. #else
  60. gd->bus_clk = gd->cpu_clk;
  61. #endif
  62. #ifdef CONFIG_SYS_I2C_FSL
  63. gd->arch.i2c1_clk = gd->bus_clk;
  64. #ifdef CONFIG_SYS_I2C2_FSL_OFFSET
  65. gd->arch.i2c2_clk = gd->bus_clk;
  66. #endif
  67. #endif
  68. return (0);
  69. }