blob: cbf76ab4feec57bed2b6ef576a4c5751668d7da5 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefano Babic1c2b3ac2011-01-20 07:49:52 +00002/*
3 * (C) Copyright 2007
4 * Sascha Hauer, Pengutronix
5 *
6 * (C) Copyright 2008-2010 Freescale Semiconductor, Inc.
Stefano Babic1c2b3ac2011-01-20 07:49:52 +00007 */
8
9#include <common.h>
Simon Glass85d65312019-12-28 10:44:58 -070010#include <clock_legacy.h>
Simon Glassed38aef2020-05-10 11:40:03 -060011#include <command.h>
Benoît Thébaudeaucd6173b2012-08-14 10:32:54 +000012#include <div64.h>
Simon Glass97589732020-05-10 11:40:02 -060013#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060014#include <net.h>
Simon Glass3ba929a2020-10-30 21:38:53 -060015#include <asm/global_data.h>
Stefano Babic1c2b3ac2011-01-20 07:49:52 +000016#include <asm/io.h>
Masahiro Yamada56a931c2016-09-21 11:28:55 +090017#include <linux/errno.h>
Stefano Babic1c2b3ac2011-01-20 07:49:52 +000018#include <asm/arch/imx-regs.h>
19#include <asm/arch/crm_regs.h>
20#include <asm/arch/clock.h>
21#include <asm/arch/sys_proto.h>
Yangbo Lu73340382019-06-21 11:42:28 +080022#ifdef CONFIG_FSL_ESDHC_IMX
23#include <fsl_esdhc_imx.h>
Benoît Thébaudeau5baa2482012-08-17 10:43:48 +000024#endif
Stefano Babic1c2b3ac2011-01-20 07:49:52 +000025#include <netdev.h>
Stefano Babice9a05792012-10-10 21:11:43 +000026#include <spl.h>
Stefano Babic1c2b3ac2011-01-20 07:49:52 +000027
28#define CLK_CODE(arm, ahb, sel) (((arm) << 16) + ((ahb) << 8) + (sel))
29#define CLK_CODE_ARM(c) (((c) >> 16) & 0xFF)
30#define CLK_CODE_AHB(c) (((c) >> 8) & 0xFF)
31#define CLK_CODE_PATH(c) ((c) & 0xFF)
32
33#define CCM_GET_DIVIDER(x, m, o) (((x) & (m)) >> (o))
34
Yangbo Lu73340382019-06-21 11:42:28 +080035#ifdef CONFIG_FSL_ESDHC_IMX
Stefano Babic1c2b3ac2011-01-20 07:49:52 +000036DECLARE_GLOBAL_DATA_PTR;
37#endif
38
39static int g_clk_mux_auto[8] = {
40 CLK_CODE(1, 3, 0), CLK_CODE(1, 2, 1), CLK_CODE(2, 1, 1), -1,
41 CLK_CODE(1, 6, 0), CLK_CODE(1, 4, 1), CLK_CODE(2, 2, 1), -1,
42};
43
44static int g_clk_mux_consumer[16] = {
45 CLK_CODE(1, 4, 0), CLK_CODE(1, 3, 1), CLK_CODE(1, 3, 1), -1,
46 -1, -1, CLK_CODE(4, 1, 0), CLK_CODE(1, 5, 0),
47 CLK_CODE(1, 8, 1), CLK_CODE(1, 6, 1), CLK_CODE(2, 4, 0), -1,
48 -1, -1, CLK_CODE(4, 2, 0), -1,
49};
50
51static int hsp_div_table[3][16] = {
52 {4, 3, 2, -1, -1, -1, 1, 5, 4, 3, 2, -1, -1, -1, 1, -1},
53 {-1, -1, -1, -1, -1, -1, -1, -1, 8, 6, 4, -1, -1, -1, 2, -1},
54 {3, -1, -1, -1, -1, -1, -1, -1, 3, -1, -1, -1, -1, -1, -1, -1},
55};
56
57u32 get_cpu_rev(void)
58{
59 int reg;
60 struct iim_regs *iim =
61 (struct iim_regs *)IIM_BASE_ADDR;
62 reg = readl(&iim->iim_srev);
63 if (!reg) {
64 reg = readw(ROMPATCH_REV);
65 reg <<= 4;
66 } else {
67 reg += CHIP_REV_1_0;
68 }
69
70 return 0x35000 + (reg & 0xFF);
71}
72
73static u32 get_arm_div(u32 pdr0, u32 *fi, u32 *fd)
74{
75 int *pclk_mux;
76 if (pdr0 & MXC_CCM_PDR0_AUTO_CON) {
77 pclk_mux = g_clk_mux_consumer +
78 ((pdr0 & MXC_CCM_PDR0_CON_MUX_DIV_MASK) >>
79 MXC_CCM_PDR0_CON_MUX_DIV_OFFSET);
80 } else {
81 pclk_mux = g_clk_mux_auto +
82 ((pdr0 & MXC_CCM_PDR0_AUTO_MUX_DIV_MASK) >>
83 MXC_CCM_PDR0_AUTO_MUX_DIV_OFFSET);
84 }
85
86 if ((*pclk_mux) == -1)
87 return -1;
88
89 if (fi && fd) {
90 if (!CLK_CODE_PATH(*pclk_mux)) {
91 *fi = *fd = 1;
92 return CLK_CODE_ARM(*pclk_mux);
93 }
94 if (pdr0 & MXC_CCM_PDR0_AUTO_CON) {
95 *fi = 3;
96 *fd = 4;
97 } else {
98 *fi = 2;
99 *fd = 3;
100 }
101 }
102 return CLK_CODE_ARM(*pclk_mux);
103}
104
105static int get_ahb_div(u32 pdr0)
106{
107 int *pclk_mux;
108
109 pclk_mux = g_clk_mux_consumer +
110 ((pdr0 & MXC_CCM_PDR0_CON_MUX_DIV_MASK) >>
111 MXC_CCM_PDR0_CON_MUX_DIV_OFFSET);
112
113 if ((*pclk_mux) == -1)
114 return -1;
115
116 return CLK_CODE_AHB(*pclk_mux);
117}
118
119static u32 decode_pll(u32 reg, u32 infreq)
120{
121 u32 mfi = (reg >> 10) & 0xf;
Benoît Thébaudeaucd6173b2012-08-14 10:32:54 +0000122 s32 mfn = reg & 0x3ff;
123 u32 mfd = (reg >> 16) & 0x3ff;
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000124 u32 pd = (reg >> 26) & 0xf;
125
126 mfi = mfi <= 5 ? 5 : mfi;
Benoît Thébaudeaucd6173b2012-08-14 10:32:54 +0000127 mfn = mfn >= 512 ? mfn - 1024 : mfn;
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000128 mfd += 1;
129 pd += 1;
130
Benoît Thébaudeaucd6173b2012-08-14 10:32:54 +0000131 return lldiv(2 * (u64)infreq * (mfi * mfd + mfn),
132 mfd * pd);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000133}
134
135static u32 get_mcu_main_clk(void)
136{
137 u32 arm_div = 0, fi = 0, fd = 0;
138 struct ccm_regs *ccm =
139 (struct ccm_regs *)IMX_CCM_BASE;
140 arm_div = get_arm_div(readl(&ccm->pdr0), &fi, &fd);
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000141 fi *= decode_pll(readl(&ccm->mpctl), MXC_HCLK);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000142 return fi / (arm_div * fd);
143}
144
145static u32 get_ipg_clk(void)
146{
147 u32 freq = get_mcu_main_clk();
148 struct ccm_regs *ccm =
149 (struct ccm_regs *)IMX_CCM_BASE;
150 u32 pdr0 = readl(&ccm->pdr0);
151
152 return freq / (get_ahb_div(pdr0) * 2);
153}
154
155static u32 get_ipg_per_clk(void)
156{
157 u32 freq = get_mcu_main_clk();
158 struct ccm_regs *ccm =
159 (struct ccm_regs *)IMX_CCM_BASE;
160 u32 pdr0 = readl(&ccm->pdr0);
161 u32 pdr4 = readl(&ccm->pdr4);
162 u32 div;
163 if (pdr0 & MXC_CCM_PDR0_PER_SEL) {
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000164 div = CCM_GET_DIVIDER(pdr4,
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000165 MXC_CCM_PDR4_PER0_PODF_MASK,
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000166 MXC_CCM_PDR4_PER0_PODF_OFFSET) + 1;
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000167 } else {
168 div = CCM_GET_DIVIDER(pdr0,
169 MXC_CCM_PDR0_PER_PODF_MASK,
170 MXC_CCM_PDR0_PER_PODF_OFFSET) + 1;
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000171 div *= get_ahb_div(pdr0);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000172 }
173 return freq / div;
174}
175
176u32 imx_get_uartclk(void)
177{
178 u32 freq;
179 struct ccm_regs *ccm =
180 (struct ccm_regs *)IMX_CCM_BASE;
181 u32 pdr4 = readl(&ccm->pdr4);
182
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000183 if (readl(&ccm->pdr3) & MXC_CCM_PDR3_UART_M_U)
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000184 freq = get_mcu_main_clk();
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000185 else
186 freq = decode_pll(readl(&ccm->ppctl), MXC_HCLK);
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000187 freq /= CCM_GET_DIVIDER(pdr4,
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000188 MXC_CCM_PDR4_UART_PODF_MASK,
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000189 MXC_CCM_PDR4_UART_PODF_OFFSET) + 1;
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000190 return freq;
191}
192
Benoît Thébaudeauefc91872012-08-14 10:32:21 +0000193unsigned int mxc_get_main_clock(enum mxc_main_clock clk)
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000194{
195 u32 nfc_pdf, hsp_podf;
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000196 u32 pll, ret_val = 0, usb_podf;
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000197 struct ccm_regs *ccm =
198 (struct ccm_regs *)IMX_CCM_BASE;
199
200 u32 reg = readl(&ccm->pdr0);
201 u32 reg4 = readl(&ccm->pdr4);
202
203 reg |= 0x1;
204
205 switch (clk) {
206 case CPU_CLK:
207 ret_val = get_mcu_main_clk();
208 break;
209 case AHB_CLK:
210 ret_val = get_mcu_main_clk();
211 break;
212 case HSP_CLK:
213 if (reg & CLKMODE_CONSUMER) {
214 hsp_podf = (reg >> 20) & 0x3;
215 pll = get_mcu_main_clk();
216 hsp_podf = hsp_div_table[hsp_podf][(reg>>16)&0xF];
217 if (hsp_podf > 0) {
218 ret_val = pll / hsp_podf;
219 } else {
220 puts("mismatch HSP with ARM clock setting\n");
221 ret_val = 0;
222 }
223 } else {
224 ret_val = get_mcu_main_clk();
225 }
226 break;
227 case IPG_CLK:
Fabio Estevamf231efb2011-10-13 05:34:59 +0000228 ret_val = get_ipg_clk();
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000229 break;
230 case IPG_PER_CLK:
231 ret_val = get_ipg_per_clk();
232 break;
233 case NFC_CLK:
234 nfc_pdf = (reg4 >> 28) & 0xF;
235 pll = get_mcu_main_clk();
236 /* AHB/nfc_pdf */
237 ret_val = pll / (nfc_pdf + 1);
238 break;
239 case USB_CLK:
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000240 usb_podf = (reg4 >> 22) & 0x3F;
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000241 if (reg4 & 0x200)
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000242 pll = get_mcu_main_clk();
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000243 else
244 pll = decode_pll(readl(&ccm->ppctl), MXC_HCLK);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000245
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000246 ret_val = pll / (usb_podf + 1);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000247 break;
248 default:
249 printf("Unknown clock: %d\n", clk);
250 break;
251 }
252
253 return ret_val;
254}
Benoît Thébaudeauefc91872012-08-14 10:32:21 +0000255unsigned int mxc_get_peri_clock(enum mxc_peri_clock clk)
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000256{
257 u32 ret_val = 0, pdf, pre_pdf, clk_sel;
258 struct ccm_regs *ccm =
259 (struct ccm_regs *)IMX_CCM_BASE;
260 u32 mpdr2 = readl(&ccm->pdr2);
261 u32 mpdr3 = readl(&ccm->pdr3);
262 u32 mpdr4 = readl(&ccm->pdr4);
263
264 switch (clk) {
265 case UART1_BAUD:
266 case UART2_BAUD:
267 case UART3_BAUD:
268 clk_sel = mpdr3 & (1 << 14);
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000269 pdf = (mpdr4 >> 10) & 0x3F;
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000270 ret_val = ((clk_sel != 0) ? mxc_get_main_clock(CPU_CLK) :
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000271 decode_pll(readl(&ccm->ppctl), MXC_HCLK)) / (pdf + 1);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000272 break;
273 case SSI1_BAUD:
274 pre_pdf = (mpdr2 >> 24) & 0x7;
275 pdf = mpdr2 & 0x3F;
276 clk_sel = mpdr2 & (1 << 6);
277 ret_val = ((clk_sel != 0) ? mxc_get_main_clock(CPU_CLK) :
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000278 decode_pll(readl(&ccm->ppctl), MXC_HCLK)) /
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000279 ((pre_pdf + 1) * (pdf + 1));
280 break;
281 case SSI2_BAUD:
282 pre_pdf = (mpdr2 >> 27) & 0x7;
283 pdf = (mpdr2 >> 8) & 0x3F;
284 clk_sel = mpdr2 & (1 << 6);
285 ret_val = ((clk_sel != 0) ? mxc_get_main_clock(CPU_CLK) :
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000286 decode_pll(readl(&ccm->ppctl), MXC_HCLK)) /
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000287 ((pre_pdf + 1) * (pdf + 1));
288 break;
289 case CSI_BAUD:
290 clk_sel = mpdr2 & (1 << 7);
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000291 pdf = (mpdr2 >> 16) & 0x3F;
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000292 ret_val = ((clk_sel != 0) ? mxc_get_main_clock(CPU_CLK) :
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000293 decode_pll(readl(&ccm->ppctl), MXC_HCLK)) / (pdf + 1);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000294 break;
295 case MSHC_CLK:
296 pre_pdf = readl(&ccm->pdr1);
297 clk_sel = (pre_pdf & 0x80);
298 pdf = (pre_pdf >> 22) & 0x3F;
299 pre_pdf = (pre_pdf >> 28) & 0x7;
300 ret_val = ((clk_sel != 0) ? mxc_get_main_clock(CPU_CLK) :
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000301 decode_pll(readl(&ccm->ppctl), MXC_HCLK)) /
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000302 ((pre_pdf + 1) * (pdf + 1));
303 break;
304 case ESDHC1_CLK:
305 clk_sel = mpdr3 & 0x40;
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000306 pdf = mpdr3 & 0x3F;
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000307 ret_val = ((clk_sel != 0) ? mxc_get_main_clock(CPU_CLK) :
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000308 decode_pll(readl(&ccm->ppctl), MXC_HCLK)) / (pdf + 1);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000309 break;
310 case ESDHC2_CLK:
311 clk_sel = mpdr3 & 0x40;
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000312 pdf = (mpdr3 >> 8) & 0x3F;
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000313 ret_val = ((clk_sel != 0) ? mxc_get_main_clock(CPU_CLK) :
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000314 decode_pll(readl(&ccm->ppctl), MXC_HCLK)) / (pdf + 1);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000315 break;
316 case ESDHC3_CLK:
317 clk_sel = mpdr3 & 0x40;
Benoît Thébaudeaua83e26d2012-08-14 10:33:27 +0000318 pdf = (mpdr3 >> 16) & 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 SPDIF_CLK:
323 clk_sel = mpdr3 & 0x400000;
324 pre_pdf = (mpdr3 >> 29) & 0x7;
325 pdf = (mpdr3 >> 23) & 0x3F;
326 ret_val = ((clk_sel != 0) ? mxc_get_main_clock(CPU_CLK) :
Benoît Thébaudeaue4528342012-08-21 11:07:20 +0000327 decode_pll(readl(&ccm->ppctl), MXC_HCLK)) /
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000328 ((pre_pdf + 1) * (pdf + 1));
329 break;
330 default:
331 printf("%s(): This clock: %d not supported yet\n",
332 __func__, clk);
333 break;
334 }
335
336 return ret_val;
337}
338
339unsigned int mxc_get_clock(enum mxc_clock clk)
340{
341 switch (clk) {
342 case MXC_ARM_CLK:
343 return get_mcu_main_clk();
344 case MXC_AHB_CLK:
345 break;
346 case MXC_IPG_CLK:
347 return get_ipg_clk();
348 case MXC_IPG_PERCLK:
Matthias Weisser99ba3422012-09-24 02:46:53 +0000349 case MXC_I2C_CLK:
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000350 return get_ipg_per_clk();
351 case MXC_UART_CLK:
352 return imx_get_uartclk();
Benoît Thébaudeau8eae5692012-09-27 10:26:02 +0000353 case MXC_ESDHC1_CLK:
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000354 return mxc_get_peri_clock(ESDHC1_CLK);
Benoît Thébaudeau8eae5692012-09-27 10:26:02 +0000355 case MXC_ESDHC2_CLK:
356 return mxc_get_peri_clock(ESDHC2_CLK);
357 case MXC_ESDHC3_CLK:
358 return mxc_get_peri_clock(ESDHC3_CLK);
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000359 case MXC_USB_CLK:
360 return mxc_get_main_clock(USB_CLK);
361 case MXC_FEC_CLK:
362 return get_ipg_clk();
363 case MXC_CSPI_CLK:
364 return get_ipg_clk();
365 }
366 return -1;
367}
368
369#ifdef CONFIG_FEC_MXC
370/*
371 * The MX35 has no fuse for MAC, return a NULL MAC
372 */
Fabio Estevam04fc1282011-12-20 05:46:31 +0000373void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000374{
375 memset(mac, 0, 6);
376}
377
378u32 imx_get_fecclk(void)
379{
380 return mxc_get_clock(MXC_IPG_CLK);
381}
382#endif
383
Simon Glassed38aef2020-05-10 11:40:03 -0600384int do_mx35_showclocks(struct cmd_tbl *cmdtp, int flag, int argc,
385 char *const argv[])
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000386{
387 u32 cpufreq = get_mcu_main_clk();
388 printf("mx35 cpu clock: %dMHz\n", cpufreq / 1000000);
389 printf("ipg clock : %dHz\n", get_ipg_clk());
390 printf("ipg per clock : %dHz\n", get_ipg_per_clk());
391 printf("uart clock : %dHz\n", mxc_get_clock(MXC_UART_CLK));
392
393 return 0;
394}
395
396U_BOOT_CMD(
Stefano Babicc8a02c32011-08-17 17:52:40 +0200397 clocks, CONFIG_SYS_MAXARGS, 1, do_mx35_showclocks,
398 "display clocks",
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000399 ""
400);
401
Fabio Estevam224687f2012-02-10 05:34:03 +0000402#if defined(CONFIG_DISPLAY_CPUINFO)
Stefano Babic5844e672011-08-05 12:21:37 +0200403static char *get_reset_cause(void)
404{
405 /* read RCSR register from CCM module */
406 struct ccm_regs *ccm =
407 (struct ccm_regs *)IMX_CCM_BASE;
408
409 u32 cause = readl(&ccm->rcsr) & 0x0F;
410
411 switch (cause) {
412 case 0x0000:
413 return "POR";
414 case 0x0002:
415 return "JTAG";
416 case 0x0004:
417 return "RST";
418 case 0x0008:
419 return "WDOG";
420 default:
421 return "unknown reset";
422 }
423}
424
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000425int print_cpuinfo(void)
426{
Stefano Babic5844e672011-08-05 12:21:37 +0200427 u32 srev = get_cpu_rev();
428
429 printf("CPU: Freescale i.MX35 rev %d.%d at %d MHz.\n",
430 (srev & 0xF0) >> 4, (srev & 0x0F),
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000431 get_mcu_main_clk() / 1000000);
Stefano Babic5844e672011-08-05 12:21:37 +0200432
433 printf("Reset cause: %s\n", get_reset_cause());
434
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000435 return 0;
436}
437#endif
438
439/*
440 * Initializes on-chip ethernet controllers.
441 * to override, implement board_eth_init()
442 */
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900443int cpu_eth_init(struct bd_info *bis)
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000444{
445 int rc = -ENODEV;
446
447#if defined(CONFIG_FEC_MXC)
448 rc = fecmxc_initialize(bis);
449#endif
450
451 return rc;
452}
Benoît Thébaudeau5baa2482012-08-17 10:43:48 +0000453
Yangbo Lu73340382019-06-21 11:42:28 +0800454#ifdef CONFIG_FSL_ESDHC_IMX
Benoît Thébaudeau5baa2482012-08-17 10:43:48 +0000455/*
456 * Initializes on-chip MMC controllers.
457 * to override, implement board_mmc_init()
458 */
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900459int cpu_mmc_init(struct bd_info *bis)
Benoît Thébaudeau5baa2482012-08-17 10:43:48 +0000460{
461 return fsl_esdhc_mmc_init(bis);
462}
463#endif
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000464
465int get_clocks(void)
466{
Yangbo Lu73340382019-06-21 11:42:28 +0800467#ifdef CONFIG_FSL_ESDHC_IMX
Benoît Thébaudeau8eae5692012-09-27 10:26:02 +0000468#if CONFIG_SYS_FSL_ESDHC_ADDR == MMC_SDHC2_BASE_ADDR
Simon Glass9e247d12012-12-13 20:49:05 +0000469 gd->arch.sdhc_clk = mxc_get_clock(MXC_ESDHC2_CLK);
Benoît Thébaudeau8eae5692012-09-27 10:26:02 +0000470#elif CONFIG_SYS_FSL_ESDHC_ADDR == MMC_SDHC3_BASE_ADDR
Simon Glass9e247d12012-12-13 20:49:05 +0000471 gd->arch.sdhc_clk = mxc_get_clock(MXC_ESDHC3_CLK);
Benoît Thébaudeau8eae5692012-09-27 10:26:02 +0000472#else
Simon Glass9e247d12012-12-13 20:49:05 +0000473 gd->arch.sdhc_clk = mxc_get_clock(MXC_ESDHC1_CLK);
Benoît Thébaudeau8eae5692012-09-27 10:26:02 +0000474#endif
Stefano Babic1c2b3ac2011-01-20 07:49:52 +0000475#endif
476 return 0;
477}
478
Stefano Babice9a05792012-10-10 21:11:43 +0000479#define RCSR_MEM_CTL_WEIM 0
480#define RCSR_MEM_CTL_NAND 1
481#define RCSR_MEM_CTL_ATA 2
482#define RCSR_MEM_CTL_EXPANSION 3
483#define RCSR_MEM_TYPE_NOR 0
484#define RCSR_MEM_TYPE_ONENAND 2
485#define RCSR_MEM_TYPE_SD 0
486#define RCSR_MEM_TYPE_I2C 2
487#define RCSR_MEM_TYPE_SPI 3
488
489u32 spl_boot_device(void)
490{
491 struct ccm_regs *ccm =
492 (struct ccm_regs *)IMX_CCM_BASE;
493
494 u32 rcsr = readl(&ccm->rcsr);
495 u32 mem_type, mem_ctl;
496
497 /* In external mode, no boot device is returned */
498 if ((rcsr >> 10) & 0x03)
499 return BOOT_DEVICE_NONE;
500
501 mem_ctl = (rcsr >> 25) & 0x03;
502 mem_type = (rcsr >> 23) & 0x03;
503
504 switch (mem_ctl) {
505 case RCSR_MEM_CTL_WEIM:
506 switch (mem_type) {
507 case RCSR_MEM_TYPE_NOR:
508 return BOOT_DEVICE_NOR;
509 case RCSR_MEM_TYPE_ONENAND:
Enric Balletbo i Serracdba2be2013-02-07 23:14:46 +0000510 return BOOT_DEVICE_ONENAND;
Stefano Babice9a05792012-10-10 21:11:43 +0000511 default:
512 return BOOT_DEVICE_NONE;
513 }
514 case RCSR_MEM_CTL_NAND:
515 return BOOT_DEVICE_NAND;
516 case RCSR_MEM_CTL_EXPANSION:
517 switch (mem_type) {
518 case RCSR_MEM_TYPE_SD:
519 return BOOT_DEVICE_MMC1;
520 case RCSR_MEM_TYPE_I2C:
521 return BOOT_DEVICE_I2C;
522 case RCSR_MEM_TYPE_SPI:
523 return BOOT_DEVICE_SPI;
524 default:
525 return BOOT_DEVICE_NONE;
526 }
527 }
528
529 return BOOT_DEVICE_NONE;
530}