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