generic.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215
  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. #include <asm/arch/sys_proto.h>
  28. static u32 mx31_decode_pll(u32 reg, u32 infreq)
  29. {
  30. u32 mfi = GET_PLL_MFI(reg);
  31. u32 mfn = GET_PLL_MFN(reg);
  32. u32 mfd = GET_PLL_MFD(reg);
  33. u32 pd = GET_PLL_PD(reg);
  34. mfi = mfi <= 5 ? 5 : mfi;
  35. mfd += 1;
  36. pd += 1;
  37. return ((2 * (infreq >> 10) * (mfi * mfd + mfn)) /
  38. (mfd * pd)) << 10;
  39. }
  40. static u32 mx31_get_mpl_dpdgck_clk(void)
  41. {
  42. u32 infreq;
  43. if ((readl(CCM_CCMR) & CCMR_PRCS_MASK) == CCMR_FPM)
  44. infreq = CONFIG_MX31_CLK32 * 1024;
  45. else
  46. infreq = CONFIG_MX31_HCLK_FREQ;
  47. return mx31_decode_pll(readl(CCM_MPCTL), infreq);
  48. }
  49. static u32 mx31_get_mcu_main_clk(void)
  50. {
  51. /* For now we assume mpl_dpdgck_clk == mcu_main_clk
  52. * which should be correct for most boards
  53. */
  54. return mx31_get_mpl_dpdgck_clk();
  55. }
  56. static u32 mx31_get_ipg_clk(void)
  57. {
  58. u32 freq = mx31_get_mcu_main_clk();
  59. u32 pdr0 = readl(CCM_PDR0);
  60. freq /= GET_PDR0_MAX_PODF(pdr0) + 1;
  61. freq /= GET_PDR0_IPG_PODF(pdr0) + 1;
  62. return freq;
  63. }
  64. /* hsp is the clock for the ipu */
  65. static u32 mx31_get_hsp_clk(void)
  66. {
  67. u32 freq = mx31_get_mcu_main_clk();
  68. u32 pdr0 = readl(CCM_PDR0);
  69. freq /= GET_PDR0_HSP_PODF(pdr0) + 1;
  70. return freq;
  71. }
  72. void mx31_dump_clocks(void)
  73. {
  74. u32 cpufreq = mx31_get_mcu_main_clk();
  75. printf("mx31 cpu clock: %dMHz\n",cpufreq / 1000000);
  76. printf("ipg clock : %dHz\n", mx31_get_ipg_clk());
  77. printf("hsp clock : %dHz\n", mx31_get_hsp_clk());
  78. }
  79. unsigned int mxc_get_clock(enum mxc_clock clk)
  80. {
  81. switch (clk) {
  82. case MXC_ARM_CLK:
  83. return mx31_get_mcu_main_clk();
  84. case MXC_IPG_CLK:
  85. case MXC_IPG_PERCLK:
  86. case MXC_CSPI_CLK:
  87. case MXC_UART_CLK:
  88. return mx31_get_ipg_clk();
  89. case MXC_IPU_CLK:
  90. return mx31_get_hsp_clk();
  91. }
  92. return -1;
  93. }
  94. u32 imx_get_uartclk(void)
  95. {
  96. return mxc_get_clock(MXC_UART_CLK);
  97. }
  98. void mx31_gpio_mux(unsigned long mode)
  99. {
  100. unsigned long reg, shift, tmp;
  101. reg = IOMUXC_BASE + (mode & 0x1fc);
  102. shift = (~mode & 0x3) * 8;
  103. tmp = readl(reg);
  104. tmp &= ~(0xff << shift);
  105. tmp |= ((mode >> IOMUX_MODE_POS) & 0xff) << shift;
  106. writel(tmp, reg);
  107. }
  108. void mx31_set_pad(enum iomux_pins pin, u32 config)
  109. {
  110. u32 field, l, reg;
  111. pin &= IOMUX_PADNUM_MASK;
  112. reg = (IOMUXC_BASE + 0x154) + (pin + 2) / 3 * 4;
  113. field = (pin + 2) % 3;
  114. l = readl(reg);
  115. l &= ~(0x1ff << (field * 10));
  116. l |= config << (field * 10);
  117. writel(l, reg);
  118. }
  119. void mxc_setup_weimcs(int cs, const struct mxc_weimcs *weimcs)
  120. {
  121. struct mx31_weim *weim = (struct mx31_weim *) WEIM_BASE;
  122. struct mx31_weim_cscr *cscr = &weim->cscr[cs];
  123. writel(weimcs->upper, &cscr->upper);
  124. writel(weimcs->lower, &cscr->lower);
  125. writel(weimcs->additional, &cscr->additional);
  126. }
  127. struct mx3_cpu_type mx31_cpu_type[] = {
  128. { .srev = 0x00, .v = 0x10 },
  129. { .srev = 0x10, .v = 0x11 },
  130. { .srev = 0x11, .v = 0x11 },
  131. { .srev = 0x12, .v = 0x1F },
  132. { .srev = 0x13, .v = 0x1F },
  133. { .srev = 0x14, .v = 0x12 },
  134. { .srev = 0x15, .v = 0x12 },
  135. { .srev = 0x28, .v = 0x20 },
  136. { .srev = 0x29, .v = 0x20 },
  137. };
  138. u32 get_cpu_rev(void)
  139. {
  140. u32 i, srev;
  141. /* read SREV register from IIM module */
  142. struct iim_regs *iim = (struct iim_regs *)MX31_IIM_BASE_ADDR;
  143. srev = readl(&iim->iim_srev);
  144. for (i = 0; i < ARRAY_SIZE(mx31_cpu_type); i++)
  145. if (srev == mx31_cpu_type[i].srev)
  146. return mx31_cpu_type[i].v;
  147. return srev | 0x8000;
  148. }
  149. static char *get_reset_cause(void)
  150. {
  151. /* read RCSR register from CCM module */
  152. struct clock_control_regs *ccm =
  153. (struct clock_control_regs *)CCM_BASE;
  154. u32 cause = readl(&ccm->rcsr) & 0x07;
  155. switch (cause) {
  156. case 0x0000:
  157. return "POR";
  158. case 0x0001:
  159. return "RST";
  160. case 0x0002:
  161. return "WDOG";
  162. case 0x0006:
  163. return "JTAG";
  164. default:
  165. return "unknown reset";
  166. }
  167. }
  168. #if defined(CONFIG_DISPLAY_CPUINFO)
  169. int print_cpuinfo (void)
  170. {
  171. u32 srev = get_cpu_rev();
  172. printf("CPU: Freescale i.MX31 rev %d.%d%s at %d MHz.\n",
  173. (srev & 0xF0) >> 4, (srev & 0x0F),
  174. ((srev & 0x8000) ? " unknown" : ""),
  175. mx31_get_mcu_main_clk() / 1000000);
  176. printf("Reset cause: %s\n", get_reset_cause());
  177. return 0;
  178. }
  179. #endif