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/imx-regs.h>
26 #include <asm/arch/clock.h>
29 static u32
mx31_decode_pll(u32 reg
, u32 infreq
)
31 u32 mfi
= GET_PLL_MFI(reg
);
32 u32 mfn
= GET_PLL_MFN(reg
);
33 u32 mfd
= GET_PLL_MFD(reg
);
34 u32 pd
= GET_PLL_PD(reg
);
36 mfi
= mfi
<= 5 ? 5 : mfi
;
40 return ((2 * (infreq
>> 10) * (mfi
* mfd
+ mfn
)) /
44 static u32
mx31_get_mpl_dpdgck_clk(void)
48 if ((readl(CCM_CCMR
) & CCMR_PRCS_MASK
) == CCMR_FPM
)
49 infreq
= CONFIG_MX31_CLK32
* 1024;
51 infreq
= CONFIG_MX31_HCLK_FREQ
;
53 return mx31_decode_pll(readl(CCM_MPCTL
), infreq
);
56 static u32
mx31_get_mcu_main_clk(void)
58 /* For now we assume mpl_dpdgck_clk == mcu_main_clk
59 * which should be correct for most boards
61 return mx31_get_mpl_dpdgck_clk();
64 static u32
mx31_get_ipg_clk(void)
66 u32 freq
= mx31_get_mcu_main_clk();
67 u32 pdr0
= readl(CCM_PDR0
);
69 freq
/= GET_PDR0_MAX_PODF(pdr0
) + 1;
70 freq
/= GET_PDR0_IPG_PODF(pdr0
) + 1;
75 /* hsp is the clock for the ipu */
76 static u32
mx31_get_hsp_clk(void)
78 u32 freq
= mx31_get_mcu_main_clk();
79 u32 pdr0
= readl(CCM_PDR0
);
81 freq
/= GET_PDR0_HSP_PODF(pdr0
) + 1;
86 void mx31_dump_clocks(void)
88 u32 cpufreq
= mx31_get_mcu_main_clk();
89 printf("mx31 cpu clock: %dMHz\n",cpufreq
/ 1000000);
90 printf("ipg clock : %dHz\n", mx31_get_ipg_clk());
91 printf("hsp clock : %dHz\n", mx31_get_hsp_clk());
94 unsigned int mxc_get_clock(enum mxc_clock clk
)
98 return mx31_get_mcu_main_clk();
103 return mx31_get_ipg_clk();
105 return mx31_get_hsp_clk();
110 u32
imx_get_uartclk(void)
112 return mxc_get_clock(MXC_UART_CLK
);
115 void mx31_gpio_mux(unsigned long mode
)
117 unsigned long reg
, shift
, tmp
;
119 reg
= IOMUXC_BASE
+ (mode
& 0x1fc);
120 shift
= (~mode
& 0x3) * 8;
123 tmp
&= ~(0xff << shift
);
124 tmp
|= ((mode
>> IOMUX_MODE_POS
) & 0xff) << shift
;
128 void mx31_set_pad(enum iomux_pins pin
, u32 config
)
132 pin
&= IOMUX_PADNUM_MASK
;
133 reg
= (IOMUXC_BASE
+ 0x154) + (pin
+ 2) / 3 * 4;
134 field
= (pin
+ 2) % 3;
137 l
&= ~(0x1ff << (field
* 10));
138 l
|= config
<< (field
* 10);
143 struct mx3_cpu_type mx31_cpu_type
[] = {
144 { .srev
= 0x00, .v
= 0x10 },
145 { .srev
= 0x10, .v
= 0x11 },
146 { .srev
= 0x11, .v
= 0x11 },
147 { .srev
= 0x12, .v
= 0x1F },
148 { .srev
= 0x13, .v
= 0x1F },
149 { .srev
= 0x14, .v
= 0x12 },
150 { .srev
= 0x15, .v
= 0x12 },
151 { .srev
= 0x28, .v
= 0x20 },
152 { .srev
= 0x29, .v
= 0x20 },
155 u32
get_cpu_rev(void)
159 /* read SREV register from IIM module */
160 struct iim_regs
*iim
= (struct iim_regs
*)MX31_IIM_BASE_ADDR
;
161 srev
= readl(&iim
->iim_srev
);
163 for (i
= 0; i
< ARRAY_SIZE(mx31_cpu_type
); i
++)
164 if (srev
== mx31_cpu_type
[i
].srev
)
165 return mx31_cpu_type
[i
].v
;
167 return srev
| 0x8000;
170 static char *get_reset_cause(void)
172 /* read RCSR register from CCM module */
173 struct clock_control_regs
*ccm
=
174 (struct clock_control_regs
*)CCM_BASE
;
176 u32 cause
= readl(&ccm
->rcsr
) & 0x07;
188 return "unknown reset";
192 #if defined(CONFIG_DISPLAY_CPUINFO)
193 int print_cpuinfo (void)
195 u32 srev
= get_cpu_rev();
197 printf("CPU: Freescale i.MX31 rev %d.%d%s at %d MHz.\n",
198 (srev
& 0xF0) >> 4, (srev
& 0x0F),
199 ((srev
& 0x8000) ? " unknown" : ""),
200 mx31_get_mcu_main_clk() / 1000000);
201 printf("Reset cause: %s\n", get_reset_cause());