generic.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. /*
  2. * (C) Copyright 2007
  3. * Sascha Hauer, Pengutronix
  4. *
  5. * See file CREDITS for list of people who contributed to this
  6. * project.
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. */
  23. #include <common.h>
  24. #include <asm/arch/imx-regs.h>
  25. #include <asm/arch/clock.h>
  26. #include <asm/io.h>
  27. static u32 mx31_decode_pll(u32 reg, u32 infreq)
  28. {
  29. u32 mfi = (reg >> 10) & 0xf;
  30. u32 mfn = reg & 0x3ff;
  31. u32 mfd = (reg >> 16) & 0x3ff;
  32. u32 pd = (reg >> 26) & 0xf;
  33. mfi = mfi <= 5 ? 5 : mfi;
  34. mfd += 1;
  35. pd += 1;
  36. return ((2 * (infreq >> 10) * (mfi * mfd + mfn)) /
  37. (mfd * pd)) << 10;
  38. }
  39. static u32 mx31_get_mpl_dpdgck_clk(void)
  40. {
  41. u32 infreq;
  42. if ((__REG(CCM_CCMR) & CCMR_PRCS_MASK) == CCMR_FPM)
  43. infreq = CONFIG_MX31_CLK32 * 1024;
  44. else
  45. infreq = CONFIG_MX31_HCLK_FREQ;
  46. return mx31_decode_pll(__REG(CCM_MPCTL), infreq);
  47. }
  48. static u32 mx31_get_mcu_main_clk(void)
  49. {
  50. /* For now we assume mpl_dpdgck_clk == mcu_main_clk
  51. * which should be correct for most boards
  52. */
  53. return mx31_get_mpl_dpdgck_clk();
  54. }
  55. static u32 mx31_get_ipg_clk(void)
  56. {
  57. u32 freq = mx31_get_mcu_main_clk();
  58. u32 pdr0 = __REG(CCM_PDR0);
  59. freq /= ((pdr0 >> 3) & 0x7) + 1;
  60. freq /= ((pdr0 >> 6) & 0x3) + 1;
  61. return freq;
  62. }
  63. void mx31_dump_clocks(void)
  64. {
  65. u32 cpufreq = mx31_get_mcu_main_clk();
  66. printf("mx31 cpu clock: %dMHz\n",cpufreq / 1000000);
  67. printf("ipg clock : %dHz\n", mx31_get_ipg_clk());
  68. }
  69. unsigned int mxc_get_clock(enum mxc_clock clk)
  70. {
  71. switch (clk) {
  72. case MXC_ARM_CLK:
  73. return mx31_get_mcu_main_clk();
  74. case MXC_IPG_CLK:
  75. case MXC_CSPI_CLK:
  76. case MXC_UART_CLK:
  77. return mx31_get_ipg_clk();
  78. }
  79. return -1;
  80. }
  81. u32 imx_get_uartclk(void)
  82. {
  83. return mxc_get_clock(MXC_UART_CLK);
  84. }
  85. void mx31_gpio_mux(unsigned long mode)
  86. {
  87. unsigned long reg, shift, tmp;
  88. reg = IOMUXC_BASE + (mode & 0x1fc);
  89. shift = (~mode & 0x3) * 8;
  90. tmp = __REG(reg);
  91. tmp &= ~(0xff << shift);
  92. tmp |= ((mode >> IOMUX_MODE_POS) & 0xff) << shift;
  93. __REG(reg) = tmp;
  94. }
  95. void mx31_set_pad(enum iomux_pins pin, u32 config)
  96. {
  97. u32 field, l, reg;
  98. pin &= IOMUX_PADNUM_MASK;
  99. reg = (IOMUXC_BASE + 0x154) + (pin + 2) / 3 * 4;
  100. field = (pin + 2) % 3;
  101. l = __REG(reg);
  102. l &= ~(0x1ff << (field * 10));
  103. l |= config << (field * 10);
  104. __REG(reg) = l;
  105. }
  106. struct mx3_cpu_type mx31_cpu_type[] = {
  107. { .srev = 0x00, .v = 0x10 },
  108. { .srev = 0x10, .v = 0x11 },
  109. { .srev = 0x11, .v = 0x11 },
  110. { .srev = 0x12, .v = 0x1F },
  111. { .srev = 0x13, .v = 0x1F },
  112. { .srev = 0x14, .v = 0x12 },
  113. { .srev = 0x15, .v = 0x12 },
  114. { .srev = 0x28, .v = 0x20 },
  115. { .srev = 0x29, .v = 0x20 },
  116. };
  117. u32 get_cpu_rev(void)
  118. {
  119. u32 i, srev;
  120. /* read SREV register from IIM module */
  121. struct iim_regs *iim = (struct iim_regs *)MX31_IIM_BASE_ADDR;
  122. srev = readl(&iim->iim_srev);
  123. for (i = 0; i < ARRAY_SIZE(mx31_cpu_type); i++)
  124. if (srev == mx31_cpu_type[i].srev)
  125. return mx31_cpu_type[i].v;
  126. return srev | 0x8000;
  127. }
  128. static char *get_reset_cause(void)
  129. {
  130. /* read RCSR register from CCM module */
  131. struct clock_control_regs *ccm =
  132. (struct clock_control_regs *)CCM_BASE;
  133. u32 cause = readl(&ccm->rcsr) & 0x07;
  134. switch (cause) {
  135. case 0x0000:
  136. return "POR";
  137. case 0x0001:
  138. return "RST";
  139. case 0x0002:
  140. return "WDOG";
  141. case 0x0006:
  142. return "JTAG";
  143. default:
  144. return "unknown reset";
  145. }
  146. }
  147. #if defined(CONFIG_DISPLAY_CPUINFO)
  148. int print_cpuinfo (void)
  149. {
  150. u32 srev = get_cpu_rev();
  151. printf("CPU: Freescale i.MX31 rev %d.%d%s at %d MHz.",
  152. (srev & 0xF0) >> 4, (srev & 0x0F),
  153. ((srev & 0x8000) ? " unknown" : ""),
  154. mx31_get_mcu_main_clk() / 1000000);
  155. printf("Reset cause: %s\n", get_reset_cause());
  156. return 0;
  157. }
  158. #endif