pq2.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * PowerQUICC II support functions
  3. *
  4. * Author: Scott Wood <scottwood@freescale.com>
  5. *
  6. * Copyright (c) 2007 Freescale Semiconductor, Inc.
  7. *
  8. * This program is free software; you can redistribute it and/or modify it
  9. * under the terms of the GNU General Public License version 2 as published
  10. * by the Free Software Foundation.
  11. */
  12. #include "ops.h"
  13. #include "types.h"
  14. #include "fsl-soc.h"
  15. #include "pq2.h"
  16. #include "stdio.h"
  17. #include "io.h"
  18. #define PQ2_SCCR (0x10c80/4) /* System Clock Configuration Register */
  19. #define PQ2_SCMR (0x10c88/4) /* System Clock Mode Register */
  20. static int pq2_corecnf_map[] = {
  21. 3, 2, 2, 2, 4, 4, 5, 9, 6, 11, 8, 10, 3, 12, 7, -1,
  22. 6, 5, 13, 2, 14, 4, 15, 9, 0, 11, 8, 10, 16, 12, 7, -1
  23. };
  24. /* Get various clocks from crystal frequency.
  25. * Returns zero on failure and non-zero on success.
  26. */
  27. int pq2_get_clocks(u32 crystal, u32 *sysfreq, u32 *corefreq,
  28. u32 *timebase, u32 *brgfreq)
  29. {
  30. u32 *immr;
  31. u32 sccr, scmr, mainclk, busclk;
  32. int corecnf, busdf, plldf, pllmf, dfbrg;
  33. immr = fsl_get_immr();
  34. if (!immr) {
  35. printf("pq2_get_clocks: Couldn't get IMMR base.\r\n");
  36. return 0;
  37. }
  38. sccr = in_be32(&immr[PQ2_SCCR]);
  39. scmr = in_be32(&immr[PQ2_SCMR]);
  40. dfbrg = sccr & 3;
  41. corecnf = (scmr >> 24) & 0x1f;
  42. busdf = (scmr >> 20) & 0xf;
  43. plldf = (scmr >> 12) & 1;
  44. pllmf = scmr & 0xfff;
  45. mainclk = crystal * (pllmf + 1) / (plldf + 1);
  46. busclk = mainclk / (busdf + 1);
  47. if (sysfreq)
  48. *sysfreq = mainclk / 2;
  49. if (timebase)
  50. *timebase = busclk / 4;
  51. if (brgfreq)
  52. *brgfreq = mainclk / (1 << ((dfbrg + 1) * 2));
  53. if (corefreq) {
  54. int coremult = pq2_corecnf_map[corecnf];
  55. if (coremult < 0)
  56. *corefreq = mainclk / 2;
  57. else if (coremult == 0)
  58. return 0;
  59. else
  60. *corefreq = busclk * coremult / 2;
  61. }
  62. return 1;
  63. }
  64. /* Set common device tree fields based on the given clock frequencies. */
  65. void pq2_set_clocks(u32 sysfreq, u32 corefreq, u32 timebase, u32 brgfreq)
  66. {
  67. void *node;
  68. dt_fixup_cpu_clocks(corefreq, timebase, sysfreq);
  69. node = finddevice("/soc/cpm");
  70. if (node)
  71. setprop(node, "clock-frequency", &sysfreq, 4);
  72. node = finddevice("/soc/cpm/brg");
  73. if (node)
  74. setprop(node, "clock-frequency", &brgfreq, 4);
  75. }
  76. int pq2_fixup_clocks(u32 crystal)
  77. {
  78. u32 sysfreq, corefreq, timebase, brgfreq;
  79. if (!pq2_get_clocks(crystal, &sysfreq, &corefreq, &timebase, &brgfreq))
  80. return 0;
  81. pq2_set_clocks(sysfreq, corefreq, timebase, brgfreq);
  82. return 1;
  83. }