blob: 98aa4d15bccedaa1688a52e0eb3c122abbaebfc7 [file] [log] [blame]
Stefano Babic1c2b3ac2011-01-20 07:49:52 +00001/*
2 * (C) Copyright 2007
3 * Sascha Hauer, Pengutronix
4 *
5 * (C) Copyright 2008-2010 Freescale Semiconductor, Inc.
6 *
7 * See file CREDITS for list of people who contributed to this
8 * project.
9 *
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation; either version 2 of
13 * the License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23 * MA 02111-1307 USA
24 */
25
26#include <common.h>
Benoît Thébaudeaucd6173b2012-08-14 10:32:54 +000027#include <div64.h>
Stefano Babic1c2b3ac2011-01-20 07:49:52 +000028#include <asm/io.h>
29#include <asm/errno.h>
30#include <asm/arch/imx-regs.h>
31#include <asm/arch/crm_regs.h>
32#include <asm/arch/clock.h>
33#include <asm/arch/sys_proto.h>
Benoît Thébaudeau5baa2482012-08-17 10:43:48 +000034#ifdef CONFIG_FSL_ESDHC
35#include <fsl_esdhc.h>
36#endif
Stefano Babic1c2b3ac2011-01-20 07:49:52 +000037#include <netdev.h>
Stefano Babice9a05792012-10-10 21:11:43 +000038#include <spl.h>
Stefano Babic1c2b3ac2011-01-20 07:49:52 +000039
40#define CLK_CODE(arm, ahb, sel) (((arm) << 16) + ((ahb) << 8) + (sel))
41#define CLK_CODE_ARM(c) (((c) >> 16) & 0xFF)
42#define CLK_CODE_AHB(c) (((c) >> 8) & 0xFF)
43#define CLK_CODE_PATH(c) ((c) & 0xFF)
44
45#define CCM_GET_DIVIDER(x, m, o) (((x) & (m)) >> (o))
46
47#ifdef CONFIG_FSL_ESDHC
48DECLARE_GLOBAL_DATA_PTR;
49#endif
50
51static int g_clk_mux_auto[8] = {
52 CLK_CODE(1, 3, 0), CLK_CODE(1, 2, 1), CLK_CODE(2, 1, 1), -1,
53 CLK_CODE(1, 6, 0), CLK_CODE(1, 4, 1), CLK_CODE(2, 2, 1), -1,
54};
55
56static int g_clk_mux_consumer[16] = {
57 CLK_CODE(1, 4, 0), CLK_CODE(1, 3, 1), CLK_CODE(1, 3, 1), -1,
58 -1, -1, CLK_CODE(4, 1, 0), CLK_CODE(1, 5, 0),
59 CLK_CODE(1, 8, 1), CLK_CODE(1, 6, 1), CLK_CODE(2, 4, 0), -1,
60 -1, -1, CLK_CODE(4, 2, 0), -1,
61};
62
63static int hsp_div_table[3][16] = {
64 {4, 3, 2, -1, -1, -1, 1, 5, 4, 3, 2, -1, -1, -1, 1, -1},
65 {-1, -1, -1, -1, -1, -1, -1, -1, 8, 6, 4, -1, -1, -1, 2, -1},
66 {3, -1, -1, -1, -1, -1, -1, -1, 3, -1, -1, -1, -1, -1, -1, -1},
67};
68
69u32 get_cpu_rev(void)
70{
71 int reg;
72 struct iim_regs *iim =
73 (struct iim_regs *)IIM_BASE_ADDR;
74 reg = readl(&iim->iim_srev);
75 if (!reg) {
76 reg = readw(ROMPATCH_REV);
77 reg <<= 4;
78 } else {
79 reg += CHIP_REV_1_0;
80 }
81
82 return 0x35000 + (reg & 0xFF);
83}
84
85static u32 get_arm_div(u32 pdr0, u32 *fi, u32 *fd)
86{
87 int *pclk_mux;
88 if (pdr0 & MXC_CCM_PDR0_AUTO_CON) {
89 pclk_mux = g_clk_mux_consumer +
90 ((pdr0 & MXC_CCM_PDR0_CON_MUX_DIV_MASK) >>
91 MXC_CCM_PDR0_CON_MUX_DIV_OFFSET);
92 } else {
93 pclk_mux = g_clk_mux_auto +
94 ((pdr0 & MXC_CCM_PDR0_AUTO_MUX_DIV_MASK) >>
95 MXC_CCM_PDR0_AUTO_MUX_DIV_OFFSET);
96 }
97
98 if ((*pclk_mux) == -1)
99 return -1;
100
101 if (fi && fd) {
102 if (!CLK_CODE_PATH(*pclk_mux)) {
103 *fi = *fd = 1;
104 return CLK_CODE_ARM(*pclk_mux);
105 }
106 if (pdr0 & MXC_CCM_PDR0_AUTO_CON) {
107 *fi = 3;
108 *fd = 4;
109 } else {
110 *fi = 2;
111 *fd = 3;
112 }
113 }
114 return CLK_CODE_ARM(*pclk_mux);
115}
116
117static int get_ahb_div(u32 pdr0)
118{
119 int *pclk_mux;
120
121 pclk_mux = g_clk_mux_consumer +
122 ((pdr0 & MXC_CCM_PDR0_CON_MUX_DIV_MASK) >>
123 MXC_CCM_PDR0_CON_MUX_DIV_OFFSET);
124
125 if ((*pclk_mux) == -1)
126 return -1;
127
128 return CLK_CODE_AHB(*pclk_mux);
129}
130
131static u32 decode_pll(u32 reg, u32 infreq)
132{
133 u32 mfi = (reg >> 10) & 0xf;
Benoît Thébaudeaucd6173b2012-08-14 10:32:54 +0000134 s32 mfn = reg & 0x3ff;
135 u32 mfd = (reg >> 16) & 0x3ff;
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000136 u32 pd = (reg >> 26) & 0xf;
137
138 mfi = mfi <= 5 ? 5 : mfi;
Benoît Thébaudeaucd6173b2012-08-14 10:32:54 +0000139 mfn = mfn >= 512 ? mfn - 1024 : mfn;
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000140 mfd += 1;
141 pd += 1;
142
Benoît Thébaudeaucd6173b2012-08-14 10:32:54 +0000143 return lldiv(2 * (u64)infreq * (mfi * mfd + mfn),
144 mfd * pd);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000145}
146
147static u32 get_mcu_main_clk(void)
148{
149 u32 arm_div = 0, fi = 0, fd = 0;
150 struct ccm_regs *ccm =
151 (struct ccm_regs *)IMX_CCM_BASE;
152 arm_div = get_arm_div(readl(&ccm->pdr0), &fi, &fd);
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000153 fi *= decode_pll(readl(&ccm->mpctl), MXC_HCLK);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000154 return fi / (arm_div * fd);
155}
156
157static u32 get_ipg_clk(void)
158{
159 u32 freq = get_mcu_main_clk();
160 struct ccm_regs *ccm =
161 (struct ccm_regs *)IMX_CCM_BASE;
162 u32 pdr0 = readl(&ccm->pdr0);
163
164 return freq / (get_ahb_div(pdr0) * 2);
165}
166
167static u32 get_ipg_per_clk(void)
168{
169 u32 freq = get_mcu_main_clk();
170 struct ccm_regs *ccm =
171 (struct ccm_regs *)IMX_CCM_BASE;
172 u32 pdr0 = readl(&ccm->pdr0);
173 u32 pdr4 = readl(&ccm->pdr4);
174 u32 div;
175 if (pdr0 & MXC_CCM_PDR0_PER_SEL) {
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000176 div = CCM_GET_DIVIDER(pdr4,
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000177 MXC_CCM_PDR4_PER0_PODF_MASK,
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000178 MXC_CCM_PDR4_PER0_PODF_OFFSET) + 1;
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000179 } else {
180 div = CCM_GET_DIVIDER(pdr0,
181 MXC_CCM_PDR0_PER_PODF_MASK,
182 MXC_CCM_PDR0_PER_PODF_OFFSET) + 1;
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000183 div *= get_ahb_div(pdr0);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000184 }
185 return freq / div;
186}
187
188u32 imx_get_uartclk(void)
189{
190 u32 freq;
191 struct ccm_regs *ccm =
192 (struct ccm_regs *)IMX_CCM_BASE;
193 u32 pdr4 = readl(&ccm->pdr4);
194
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000195 if (readl(&ccm->pdr3) & MXC_CCM_PDR3_UART_M_U)
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000196 freq = get_mcu_main_clk();
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000197 else
198 freq = decode_pll(readl(&ccm->ppctl), MXC_HCLK);
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000199 freq /= CCM_GET_DIVIDER(pdr4,
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000200 MXC_CCM_PDR4_UART_PODF_MASK,
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000201 MXC_CCM_PDR4_UART_PODF_OFFSET) + 1;
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000202 return freq;
203}
204
Benoît Thébaudeauefc91872012-08-14 10:32:21 +0000205unsigned int mxc_get_main_clock(enum mxc_main_clock clk)
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000206{
207 u32 nfc_pdf, hsp_podf;
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000208 u32 pll, ret_val = 0, usb_podf;
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000209 struct ccm_regs *ccm =
210 (struct ccm_regs *)IMX_CCM_BASE;
211
212 u32 reg = readl(&ccm->pdr0);
213 u32 reg4 = readl(&ccm->pdr4);
214
215 reg |= 0x1;
216
217 switch (clk) {
218 case CPU_CLK:
219 ret_val = get_mcu_main_clk();
220 break;
221 case AHB_CLK:
222 ret_val = get_mcu_main_clk();
223 break;
224 case HSP_CLK:
225 if (reg & CLKMODE_CONSUMER) {
226 hsp_podf = (reg >> 20) & 0x3;
227 pll = get_mcu_main_clk();
228 hsp_podf = hsp_div_table[hsp_podf][(reg>>16)&0xF];
229 if (hsp_podf > 0) {
230 ret_val = pll / hsp_podf;
231 } else {
232 puts("mismatch HSP with ARM clock setting\n");
233 ret_val = 0;
234 }
235 } else {
236 ret_val = get_mcu_main_clk();
237 }
238 break;
239 case IPG_CLK:
Fabio Estevamf231efb2011-10-13 05:34:59 +0000240 ret_val = get_ipg_clk();
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000241 break;
242 case IPG_PER_CLK:
243 ret_val = get_ipg_per_clk();
244 break;
245 case NFC_CLK:
246 nfc_pdf = (reg4 >> 28) & 0xF;
247 pll = get_mcu_main_clk();
248 /* AHB/nfc_pdf */
249 ret_val = pll / (nfc_pdf + 1);
250 break;
251 case USB_CLK:
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000252 usb_podf = (reg4 >> 22) & 0x3F;
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000253 if (reg4 & 0x200)
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000254 pll = get_mcu_main_clk();
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000255 else
256 pll = decode_pll(readl(&ccm->ppctl), MXC_HCLK);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000257
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000258 ret_val = pll / (usb_podf + 1);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000259 break;
260 default:
261 printf("Unknown clock: %d\n", clk);
262 break;
263 }
264
265 return ret_val;
266}
Benoît Thébaudeauefc91872012-08-14 10:32:21 +0000267unsigned int mxc_get_peri_clock(enum mxc_peri_clock clk)
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000268{
269 u32 ret_val = 0, pdf, pre_pdf, clk_sel;
270 struct ccm_regs *ccm =
271 (struct ccm_regs *)IMX_CCM_BASE;
272 u32 mpdr2 = readl(&ccm->pdr2);
273 u32 mpdr3 = readl(&ccm->pdr3);
274 u32 mpdr4 = readl(&ccm->pdr4);
275
276 switch (clk) {
277 case UART1_BAUD:
278 case UART2_BAUD:
279 case UART3_BAUD:
280 clk_sel = mpdr3 & (1 << 14);
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000281 pdf = (mpdr4 >> 10) & 0x3F;
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000282 ret_val = ((clk_sel != 0) ? mxc_get_main_clock(CPU_CLK) :
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000283 decode_pll(readl(&ccm->ppctl), MXC_HCLK)) / (pdf + 1);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000284 break;
285 case SSI1_BAUD:
286 pre_pdf = (mpdr2 >> 24) & 0x7;
287 pdf = mpdr2 & 0x3F;
288 clk_sel = mpdr2 & (1 << 6);
289 ret_val = ((clk_sel != 0) ? mxc_get_main_clock(CPU_CLK) :
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000290 decode_pll(readl(&ccm->ppctl), MXC_HCLK)) /
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000291 ((pre_pdf + 1) * (pdf + 1));
292 break;
293 case SSI2_BAUD:
294 pre_pdf = (mpdr2 >> 27) & 0x7;
295 pdf = (mpdr2 >> 8) & 0x3F;
296 clk_sel = mpdr2 & (1 << 6);
297 ret_val = ((clk_sel != 0) ? mxc_get_main_clock(CPU_CLK) :
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000298 decode_pll(readl(&ccm->ppctl), MXC_HCLK)) /
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000299 ((pre_pdf + 1) * (pdf + 1));
300 break;
301 case CSI_BAUD:
302 clk_sel = mpdr2 & (1 << 7);
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000303 pdf = (mpdr2 >> 16) & 0x3F;
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000304 ret_val = ((clk_sel != 0) ? mxc_get_main_clock(CPU_CLK) :
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000305 decode_pll(readl(&ccm->ppctl), MXC_HCLK)) / (pdf + 1);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000306 break;
307 case MSHC_CLK:
308 pre_pdf = readl(&ccm->pdr1);
309 clk_sel = (pre_pdf & 0x80);
310 pdf = (pre_pdf >> 22) & 0x3F;
311 pre_pdf = (pre_pdf >> 28) & 0x7;
312 ret_val = ((clk_sel != 0) ? mxc_get_main_clock(CPU_CLK) :
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000313 decode_pll(readl(&ccm->ppctl), MXC_HCLK)) /
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000314 ((pre_pdf + 1) * (pdf + 1));
315 break;
316 case ESDHC1_CLK:
317 clk_sel = mpdr3 & 0x40;
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000318 pdf = mpdr3 & 0x3F;
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000319 ret_val = ((clk_sel != 0) ? mxc_get_main_clock(CPU_CLK) :
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000320 decode_pll(readl(&ccm->ppctl), MXC_HCLK)) / (pdf + 1);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000321 break;
322 case ESDHC2_CLK:
323 clk_sel = mpdr3 & 0x40;
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000324 pdf = (mpdr3 >> 8) & 0x3F;
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000325 ret_val = ((clk_sel != 0) ? mxc_get_main_clock(CPU_CLK) :
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000326 decode_pll(readl(&ccm->ppctl), MXC_HCLK)) / (pdf + 1);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000327 break;
328 case ESDHC3_CLK:
329 clk_sel = mpdr3 & 0x40;
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000330 pdf = (mpdr3 >> 16) & 0x3F;
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000331 ret_val = ((clk_sel != 0) ? mxc_get_main_clock(CPU_CLK) :
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000332 decode_pll(readl(&ccm->ppctl), MXC_HCLK)) / (pdf + 1);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000333 break;
334 case SPDIF_CLK:
335 clk_sel = mpdr3 & 0x400000;
336 pre_pdf = (mpdr3 >> 29) & 0x7;
337 pdf = (mpdr3 >> 23) & 0x3F;
338 ret_val = ((clk_sel != 0) ? mxc_get_main_clock(CPU_CLK) :
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000339 decode_pll(readl(&ccm->ppctl), MXC_HCLK)) /
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000340 ((pre_pdf + 1) * (pdf + 1));
341 break;
342 default:
343 printf("%s(): This clock: %d not supported yet\n",
344 __func__, clk);
345 break;
346 }
347
348 return ret_val;
349}
350
351unsigned int mxc_get_clock(enum mxc_clock clk)
352{
353 switch (clk) {
354 case MXC_ARM_CLK:
355 return get_mcu_main_clk();
356 case MXC_AHB_CLK:
357 break;
358 case MXC_IPG_CLK:
359 return get_ipg_clk();
360 case MXC_IPG_PERCLK:
Matthias Weisser99ba3422012-09-24 02:46:53 +0000361 case MXC_I2C_CLK:
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000362 return get_ipg_per_clk();
363 case MXC_UART_CLK:
364 return imx_get_uartclk();
Benoît Thébaudeau8eae5692012-09-27 10:26:02 +0000365 case MXC_ESDHC1_CLK:
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000366 return mxc_get_peri_clock(ESDHC1_CLK);
Benoît Thébaudeau8eae5692012-09-27 10:26:02 +0000367 case MXC_ESDHC2_CLK:
368 return mxc_get_peri_clock(ESDHC2_CLK);
369 case MXC_ESDHC3_CLK:
370 return mxc_get_peri_clock(ESDHC3_CLK);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000371 case MXC_USB_CLK:
372 return mxc_get_main_clock(USB_CLK);
373 case MXC_FEC_CLK:
374 return get_ipg_clk();
375 case MXC_CSPI_CLK:
376 return get_ipg_clk();
377 }
378 return -1;
379}
380
381#ifdef CONFIG_FEC_MXC
382/*
383 * The MX35 has no fuse for MAC, return a NULL MAC
384 */
Fabio Estevam04fc1282011-12-20 05:46:31 +0000385void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000386{
387 memset(mac, 0, 6);
388}
389
390u32 imx_get_fecclk(void)
391{
392 return mxc_get_clock(MXC_IPG_CLK);
393}
394#endif
395
396int do_mx35_showclocks(cmd_tbl_t *cmdtp,
397 int flag, int argc, char * const argv[])
398{
399 u32 cpufreq = get_mcu_main_clk();
400 printf("mx35 cpu clock: %dMHz\n", cpufreq / 1000000);
401 printf("ipg clock : %dHz\n", get_ipg_clk());
402 printf("ipg per clock : %dHz\n", get_ipg_per_clk());
403 printf("uart clock : %dHz\n", mxc_get_clock(MXC_UART_CLK));
404
405 return 0;
406}
407
408U_BOOT_CMD(
Stefano Babicc8a02c32011-08-17 17:52:40 +0200409 clocks, CONFIG_SYS_MAXARGS, 1, do_mx35_showclocks,
410 "display clocks",
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000411 ""
412);
413
Fabio Estevam224687f2012-02-10 05:34:03 +0000414#if defined(CONFIG_DISPLAY_CPUINFO)
Stefano Babic5844e672011-08-05 12:21:37 +0200415static char *get_reset_cause(void)
416{
417 /* read RCSR register from CCM module */
418 struct ccm_regs *ccm =
419 (struct ccm_regs *)IMX_CCM_BASE;
420
421 u32 cause = readl(&ccm->rcsr) & 0x0F;
422
423 switch (cause) {
424 case 0x0000:
425 return "POR";
426 case 0x0002:
427 return "JTAG";
428 case 0x0004:
429 return "RST";
430 case 0x0008:
431 return "WDOG";
432 default:
433 return "unknown reset";
434 }
435}
436
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000437int print_cpuinfo(void)
438{
Stefano Babic5844e672011-08-05 12:21:37 +0200439 u32 srev = get_cpu_rev();
440
441 printf("CPU: Freescale i.MX35 rev %d.%d at %d MHz.\n",
442 (srev & 0xF0) >> 4, (srev & 0x0F),
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000443 get_mcu_main_clk() / 1000000);
Stefano Babic5844e672011-08-05 12:21:37 +0200444
445 printf("Reset cause: %s\n", get_reset_cause());
446
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000447 return 0;
448}
449#endif
450
451/*
452 * Initializes on-chip ethernet controllers.
453 * to override, implement board_eth_init()
454 */
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000455int cpu_eth_init(bd_t *bis)
456{
457 int rc = -ENODEV;
458
459#if defined(CONFIG_FEC_MXC)
460 rc = fecmxc_initialize(bis);
461#endif
462
463 return rc;
464}
Benoît Thébaudeau5baa2482012-08-17 10:43:48 +0000465
466#ifdef CONFIG_FSL_ESDHC
467/*
468 * Initializes on-chip MMC controllers.
469 * to override, implement board_mmc_init()
470 */
471int cpu_mmc_init(bd_t *bis)
472{
473 return fsl_esdhc_mmc_init(bis);
474}
475#endif
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000476
477int get_clocks(void)
478{
479#ifdef CONFIG_FSL_ESDHC
Benoît Thébaudeau8eae5692012-09-27 10:26:02 +0000480#if CONFIG_SYS_FSL_ESDHC_ADDR == MMC_SDHC2_BASE_ADDR
481 gd->sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
482#elif CONFIG_SYS_FSL_ESDHC_ADDR == MMC_SDHC3_BASE_ADDR
483 gd->sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
484#else
485 gd->sdhc_clk = mxc_get_clock(MXC_ESDHC1_CLK);
486#endif
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000487#endif
488 return 0;
489}
490
491void reset_cpu(ulong addr)
492{
493 struct wdog_regs *wdog = (struct wdog_regs *)WDOG_BASE_ADDR;
494 writew(4, &wdog->wcr);
495}
Stefano Babice9a05792012-10-10 21:11:43 +0000496
497#define RCSR_MEM_CTL_WEIM 0
498#define RCSR_MEM_CTL_NAND 1
499#define RCSR_MEM_CTL_ATA 2
500#define RCSR_MEM_CTL_EXPANSION 3
501#define RCSR_MEM_TYPE_NOR 0
502#define RCSR_MEM_TYPE_ONENAND 2
503#define RCSR_MEM_TYPE_SD 0
504#define RCSR_MEM_TYPE_I2C 2
505#define RCSR_MEM_TYPE_SPI 3
506
507u32 spl_boot_device(void)
508{
509 struct ccm_regs *ccm =
510 (struct ccm_regs *)IMX_CCM_BASE;
511
512 u32 rcsr = readl(&ccm->rcsr);
513 u32 mem_type, mem_ctl;
514
515 /* In external mode, no boot device is returned */
516 if ((rcsr >> 10) & 0x03)
517 return BOOT_DEVICE_NONE;
518
519 mem_ctl = (rcsr >> 25) & 0x03;
520 mem_type = (rcsr >> 23) & 0x03;
521
522 switch (mem_ctl) {
523 case RCSR_MEM_CTL_WEIM:
524 switch (mem_type) {
525 case RCSR_MEM_TYPE_NOR:
526 return BOOT_DEVICE_NOR;
527 case RCSR_MEM_TYPE_ONENAND:
528 return BOOT_DEVICE_ONE_NAND;
529 default:
530 return BOOT_DEVICE_NONE;
531 }
532 case RCSR_MEM_CTL_NAND:
533 return BOOT_DEVICE_NAND;
534 case RCSR_MEM_CTL_EXPANSION:
535 switch (mem_type) {
536 case RCSR_MEM_TYPE_SD:
537 return BOOT_DEVICE_MMC1;
538 case RCSR_MEM_TYPE_I2C:
539 return BOOT_DEVICE_I2C;
540 case RCSR_MEM_TYPE_SPI:
541 return BOOT_DEVICE_SPI;
542 default:
543 return BOOT_DEVICE_NONE;
544 }
545 }
546
547 return BOOT_DEVICE_NONE;
548}
549
550#ifdef CONFIG_SPL_BUILD
551u32 spl_boot_mode(void)
552{
553 switch (spl_boot_device()) {
554 case BOOT_DEVICE_MMC1:
555#ifdef CONFIG_SPL_FAT_SUPPORT
556 return MMCSD_MODE_FAT;
557#else
558 return MMCSD_MODE_RAW;
559#endif
560 break;
561 case BOOT_DEVICE_NAND:
562 return 0;
563 break;
564 default:
565 puts("spl: ERROR: unsupported device\n");
566 hang();
567 }
568}
569#endif