3 * Sascha Hauer, Pengutronix
5 * See file CREDITS for list of people who contributed to this
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.
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.
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,
25 #include <asm/arch/mx31-regs.h>
28 static u32 mx31_decode_pll(u32 reg, u32 infreq)
30 u32 mfi = (reg >> 10) & 0xf;
31 u32 mfn = reg & 0x3ff;
32 u32 mfd = (reg >> 16) & 0x3ff;
33 u32 pd = (reg >> 26) & 0xf;
35 mfi = mfi <= 5 ? 5 : mfi;
39 return ((2 * (infreq >> 10) * (mfi * mfd + mfn)) /
43 static u32 mx31_get_mpl_dpdgck_clk(void)
47 if ((__REG(CCM_CCMR) & CCMR_PRCS_MASK) == CCMR_FPM)
48 infreq = CONFIG_MX31_CLK32 * 1024;
50 infreq = CONFIG_MX31_HCLK_FREQ;
52 return mx31_decode_pll(__REG(CCM_MPCTL), infreq);
55 static u32 mx31_get_mcu_main_clk(void)
57 /* For now we assume mpl_dpdgck_clk == mcu_main_clk
58 * which should be correct for most boards
60 return mx31_get_mpl_dpdgck_clk();
63 u32 mx31_get_ipg_clk(void)
65 u32 freq = mx31_get_mcu_main_clk();
66 u32 pdr0 = __REG(CCM_PDR0);
68 freq /= ((pdr0 >> 3) & 0x7) + 1;
69 freq /= ((pdr0 >> 6) & 0x3) + 1;
74 void mx31_dump_clocks(void)
76 u32 cpufreq = mx31_get_mcu_main_clk();
77 printf("mx31 cpu clock: %dMHz\n",cpufreq / 1000000);
78 printf("ipg clock : %dHz\n", mx31_get_ipg_clk());
81 void mx31_gpio_mux(unsigned long mode)
83 unsigned long reg, shift, tmp;
85 reg = IOMUXC_BASE + (mode & 0x1fc);
86 shift = (~mode & 0x3) * 8;
89 tmp &= ~(0xff << shift);
90 tmp |= ((mode >> IOMUX_MODE_POS) & 0xff) << shift;
94 void mx31_set_pad(enum iomux_pins pin, u32 config)
99 pin &= IOMUX_PADNUM_MASK;
100 reg = (IOMUXC_BASE + 0x154) + (pin + 2) / 3 * 4;
101 field = (pin + 2) % 3;
103 l = __raw_readl(reg);
104 l &= ~(0x1ff << (field * 10));
105 l |= config << (field * 10);
106 __raw_writel(l, reg);
110 #if defined(CONFIG_DISPLAY_CPUINFO)
111 int print_cpuinfo (void)
113 printf("CPU: Freescale i.MX31 at %d MHz\n",
114 mx31_get_mcu_main_clk() / 1000000);