blob: 18572b9d37eff80fc9a16da7606a55d8e429ad27 [file] [log] [blame]
Sascha Hauer1a7676f2008-03-26 20:40:42 +01001/*
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
24#include <common.h>
Stefano Babic78129d92011-03-14 15:43:56 +010025#include <asm/arch/imx-regs.h>
Stefano Babic6272c7e2010-10-06 08:59:26 +020026#include <asm/io.h>
Sascha Hauer1a7676f2008-03-26 20:40:42 +010027
28static u32 mx31_decode_pll(u32 reg, u32 infreq)
29{
30 u32 mfi = (reg >> 10) & 0xf;
Jens Gehrlein23602162008-07-04 16:50:05 +020031 u32 mfn = reg & 0x3ff;
32 u32 mfd = (reg >> 16) & 0x3ff;
Sascha Hauer1a7676f2008-03-26 20:40:42 +010033 u32 pd = (reg >> 26) & 0xf;
34
35 mfi = mfi <= 5 ? 5 : mfi;
36 mfd += 1;
37 pd += 1;
38
39 return ((2 * (infreq >> 10) * (mfi * mfd + mfn)) /
40 (mfd * pd)) << 10;
41}
42
Guennadi Liakhovetski08601a62008-05-08 10:09:27 +020043static u32 mx31_get_mpl_dpdgck_clk(void)
Sascha Hauer1a7676f2008-03-26 20:40:42 +010044{
45 u32 infreq;
46
47 if ((__REG(CCM_CCMR) & CCMR_PRCS_MASK) == CCMR_FPM)
48 infreq = CONFIG_MX31_CLK32 * 1024;
49 else
50 infreq = CONFIG_MX31_HCLK_FREQ;
51
52 return mx31_decode_pll(__REG(CCM_MPCTL), infreq);
53}
54
Guennadi Liakhovetski08601a62008-05-08 10:09:27 +020055static u32 mx31_get_mcu_main_clk(void)
Sascha Hauer1a7676f2008-03-26 20:40:42 +010056{
57 /* For now we assume mpl_dpdgck_clk == mcu_main_clk
58 * which should be correct for most boards
59 */
60 return mx31_get_mpl_dpdgck_clk();
61}
62
63u32 mx31_get_ipg_clk(void)
64{
65 u32 freq = mx31_get_mcu_main_clk();
66 u32 pdr0 = __REG(CCM_PDR0);
67
68 freq /= ((pdr0 >> 3) & 0x7) + 1;
69 freq /= ((pdr0 >> 6) & 0x3) + 1;
70
71 return freq;
72}
73
74void mx31_dump_clocks(void)
75{
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());
79}
80
81void mx31_gpio_mux(unsigned long mode)
82{
83 unsigned long reg, shift, tmp;
84
Magnus Lilja532c1582008-08-03 21:44:10 +020085 reg = IOMUXC_BASE + (mode & 0x1fc);
Sascha Hauer1a7676f2008-03-26 20:40:42 +010086 shift = (~mode & 0x3) * 8;
87
88 tmp = __REG(reg);
89 tmp &= ~(0xff << shift);
Magnus Lilja532c1582008-08-03 21:44:10 +020090 tmp |= ((mode >> IOMUX_MODE_POS) & 0xff) << shift;
Sascha Hauer1a7676f2008-03-26 20:40:42 +010091 __REG(reg) = tmp;
92}
93
Stefano Babic6272c7e2010-10-06 08:59:26 +020094void mx31_set_pad(enum iomux_pins pin, u32 config)
95{
Stefano Babic5f09b922010-10-19 20:19:13 +020096 u32 field, l, reg;
Stefano Babic6272c7e2010-10-06 08:59:26 +020097
98 pin &= IOMUX_PADNUM_MASK;
99 reg = (IOMUXC_BASE + 0x154) + (pin + 2) / 3 * 4;
100 field = (pin + 2) % 3;
101
Stefano Babic5f09b922010-10-19 20:19:13 +0200102 l = __REG(reg);
Stefano Babic6272c7e2010-10-06 08:59:26 +0200103 l &= ~(0x1ff << (field * 10));
104 l |= config << (field * 10);
Stefano Babic5f09b922010-10-19 20:19:13 +0200105 __REG(reg) = l;
Stefano Babic6272c7e2010-10-06 08:59:26 +0200106
107}
108
Fabio Estevam939b9782011-04-11 16:18:12 +0000109struct mx3_cpu_type mx31_cpu_type[] = {
110 { .srev = 0x00, .v = "1.0" },
111 { .srev = 0x10, .v = "1.1" },
112 { .srev = 0x11, .v = "1.1" },
113 { .srev = 0x12, .v = "1.15" },
114 { .srev = 0x13, .v = "1.15" },
115 { .srev = 0x14, .v = "1.2" },
116 { .srev = 0x15, .v = "1.2" },
117 { .srev = 0x28, .v = "2.0" },
118 { .srev = 0x29, .v = "2.0" },
119};
120
121char *get_cpu_rev(void)
122{
123 u32 i, srev;
124
125 /* read SREV register from IIM module */
126 struct iim_regs *iim = (struct iim_regs *)MX31_IIM_BASE_ADDR;
127 srev = readl(&iim->iim_srev);
128
129 for (i = 0; i < ARRAY_SIZE(mx31_cpu_type); i++)
130 if (srev == mx31_cpu_type[i].srev)
131 return mx31_cpu_type[i].v;
132 return "unknown";
133}
134
Fabio Estevam2b0fa452011-04-18 07:38:11 +0000135char *get_reset_cause(void)
136{
137 /* read RCSR register from CCM module */
138 struct clock_control_regs *ccm =
139 (struct clock_control_regs *)CCM_BASE;
140
141 u32 cause = readl(&ccm->rcsr) & 0x07;
142
143 switch (cause) {
144 case 0x0000:
145 return "POR";
146 break;
147 case 0x0001:
148 return "RST";
149 break;
150 case 0x0002:
151 return "WDOG";
152 break;
153 case 0x0006:
154 return "JTAG";
155 break;
156 default:
157 return "unknown reset";
158 }
159}
160
Sascha Hauer1a7676f2008-03-26 20:40:42 +0100161#if defined(CONFIG_DISPLAY_CPUINFO)
162int print_cpuinfo (void)
163{
Fabio Estevam2b0fa452011-04-18 07:38:11 +0000164 printf("CPU: Freescale i.MX31 rev %s at %d MHz.",
Fabio Estevam939b9782011-04-11 16:18:12 +0000165 get_cpu_rev(), mx31_get_mcu_main_clk() / 1000000);
Fabio Estevam2b0fa452011-04-18 07:38:11 +0000166 printf("Reset cause: %s\n", get_reset_cause());
Sascha Hauer1a7676f2008-03-26 20:40:42 +0100167 return 0;
168}
169#endif