generic.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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/mx31-regs.h>
  25. #include <asm/io.h>
  26. static u32 mx31_decode_pll(u32 reg, u32 infreq)
  27. {
  28. u32 mfi = (reg >> 10) & 0xf;
  29. u32 mfn = reg & 0x3ff;
  30. u32 mfd = (reg >> 16) & 0x3ff;
  31. u32 pd = (reg >> 26) & 0xf;
  32. mfi = mfi <= 5 ? 5 : mfi;
  33. mfd += 1;
  34. pd += 1;
  35. return ((2 * (infreq >> 10) * (mfi * mfd + mfn)) /
  36. (mfd * pd)) << 10;
  37. }
  38. static u32 mx31_get_mpl_dpdgck_clk(void)
  39. {
  40. u32 infreq;
  41. if ((__REG(CCM_CCMR) & CCMR_PRCS_MASK) == CCMR_FPM)
  42. infreq = CONFIG_MX31_CLK32 * 1024;
  43. else
  44. infreq = CONFIG_MX31_HCLK_FREQ;
  45. return mx31_decode_pll(__REG(CCM_MPCTL), infreq);
  46. }
  47. static u32 mx31_get_mcu_main_clk(void)
  48. {
  49. /* For now we assume mpl_dpdgck_clk == mcu_main_clk
  50. * which should be correct for most boards
  51. */
  52. return mx31_get_mpl_dpdgck_clk();
  53. }
  54. u32 mx31_get_ipg_clk(void)
  55. {
  56. u32 freq = mx31_get_mcu_main_clk();
  57. u32 pdr0 = __REG(CCM_PDR0);
  58. freq /= ((pdr0 >> 3) & 0x7) + 1;
  59. freq /= ((pdr0 >> 6) & 0x3) + 1;
  60. return freq;
  61. }
  62. void mx31_dump_clocks(void)
  63. {
  64. u32 cpufreq = mx31_get_mcu_main_clk();
  65. printf("mx31 cpu clock: %dMHz\n",cpufreq / 1000000);
  66. printf("ipg clock : %dHz\n", mx31_get_ipg_clk());
  67. }
  68. void mx31_gpio_mux(unsigned long mode)
  69. {
  70. unsigned long reg, shift, tmp;
  71. reg = IOMUXC_BASE + (mode & 0x1fc);
  72. shift = (~mode & 0x3) * 8;
  73. tmp = __REG(reg);
  74. tmp &= ~(0xff << shift);
  75. tmp |= ((mode >> IOMUX_MODE_POS) & 0xff) << shift;
  76. __REG(reg) = tmp;
  77. }
  78. void mx31_set_pad(enum iomux_pins pin, u32 config)
  79. {
  80. u32 field, l;
  81. void *reg;
  82. pin &= IOMUX_PADNUM_MASK;
  83. reg = (IOMUXC_BASE + 0x154) + (pin + 2) / 3 * 4;
  84. field = (pin + 2) % 3;
  85. l = __raw_readl(reg);
  86. l &= ~(0x1ff << (field * 10));
  87. l |= config << (field * 10);
  88. __raw_writel(l, reg);
  89. }
  90. #if defined(CONFIG_DISPLAY_CPUINFO)
  91. int print_cpuinfo (void)
  92. {
  93. printf("CPU: Freescale i.MX31 at %d MHz\n",
  94. mx31_get_mcu_main_clk() / 1000000);
  95. return 0;
  96. }
  97. #endif