blob: 90e584ac585e3f9820e9df062c07424cb3ae3bb0 [file] [log] [blame]
John Rigby9c146032010-01-25 23:12:56 -07001/*
2 * (C) Copyright 2009 DENX Software Engineering
3 * Author: John Rigby <jrigby@gmail.com>
4 *
5 * Based on mx27/generic.c:
6 * Copyright (c) 2008 Eric Jarrige <eric.jarrige@armadeus.org>
7 * Copyright (c) 2009 Ilya Yanok <yanok@emcraft.com>
8 *
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License as
11 * published by the Free Software Foundation; either version 2 of
12 * the License, or (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
22 * MA 02111-1307 USA
23 */
24
25#include <common.h>
26#include <div64.h>
27#include <netdev.h>
28#include <asm/io.h>
29#include <asm/arch/imx-regs.h>
30#include <asm/arch/imx25-pinmux.h>
Timo Ketola738fa8d2012-04-18 22:55:28 +000031#include <asm/arch/clock.h>
John Rigby9c146032010-01-25 23:12:56 -070032#ifdef CONFIG_MXC_MMC
33#include <asm/arch/mxcmmc.h>
34#endif
35
Timo Ketola738fa8d2012-04-18 22:55:28 +000036#ifdef CONFIG_FSL_ESDHC
37DECLARE_GLOBAL_DATA_PTR;
38#endif
39
John Rigby9c146032010-01-25 23:12:56 -070040/*
41 * get the system pll clock in Hz
42 *
43 * mfi + mfn / (mfd +1)
44 * f = 2 * f_ref * --------------------
45 * pd + 1
46 */
Fabio Estevamf231efb2011-10-13 05:34:59 +000047static unsigned int imx_decode_pll(unsigned int pll, unsigned int f_ref)
John Rigby9c146032010-01-25 23:12:56 -070048{
49 unsigned int mfi = (pll >> CCM_PLL_MFI_SHIFT)
50 & CCM_PLL_MFI_MASK;
51 unsigned int mfn = (pll >> CCM_PLL_MFN_SHIFT)
52 & CCM_PLL_MFN_MASK;
53 unsigned int mfd = (pll >> CCM_PLL_MFD_SHIFT)
54 & CCM_PLL_MFD_MASK;
55 unsigned int pd = (pll >> CCM_PLL_PD_SHIFT)
56 & CCM_PLL_PD_MASK;
57
58 mfi = mfi <= 5 ? 5 : mfi;
59
Fabio Estevamf231efb2011-10-13 05:34:59 +000060 return lldiv(2 * (u64) f_ref * (mfi * (mfd + 1) + mfn),
John Rigby9c146032010-01-25 23:12:56 -070061 (mfd + 1) * (pd + 1));
62}
63
Fabio Estevamf231efb2011-10-13 05:34:59 +000064static ulong imx_get_mpllclk(void)
John Rigby9c146032010-01-25 23:12:56 -070065{
66 struct ccm_regs *ccm = (struct ccm_regs *)IMX_CCM_BASE;
Benoît Thébaudeaud2dd29d2012-08-21 11:05:12 +000067 ulong fref = MXC_HCLK;
John Rigby9c146032010-01-25 23:12:56 -070068
Fabio Estevamf231efb2011-10-13 05:34:59 +000069 return imx_decode_pll(readl(&ccm->mpctl), fref);
John Rigby9c146032010-01-25 23:12:56 -070070}
71
Fabio Estevamf231efb2011-10-13 05:34:59 +000072ulong imx_get_armclk(void)
John Rigby9c146032010-01-25 23:12:56 -070073{
74 struct ccm_regs *ccm = (struct ccm_regs *)IMX_CCM_BASE;
Fabio Estevamf231efb2011-10-13 05:34:59 +000075 ulong cctl = readl(&ccm->cctl);
76 ulong fref = imx_get_mpllclk();
John Rigby9c146032010-01-25 23:12:56 -070077 ulong div;
78
79 if (cctl & CCM_CCTL_ARM_SRC)
Fabio Estevamf231efb2011-10-13 05:34:59 +000080 fref = lldiv((fref * 3), 4);
John Rigby9c146032010-01-25 23:12:56 -070081
82 div = ((cctl >> CCM_CCTL_ARM_DIV_SHIFT)
83 & CCM_CCTL_ARM_DIV_MASK) + 1;
84
Fabio Estevamf231efb2011-10-13 05:34:59 +000085 return lldiv(fref, div);
John Rigby9c146032010-01-25 23:12:56 -070086}
87
Fabio Estevamf231efb2011-10-13 05:34:59 +000088ulong imx_get_ahbclk(void)
John Rigby9c146032010-01-25 23:12:56 -070089{
90 struct ccm_regs *ccm = (struct ccm_regs *)IMX_CCM_BASE;
Fabio Estevamf231efb2011-10-13 05:34:59 +000091 ulong cctl = readl(&ccm->cctl);
92 ulong fref = imx_get_armclk();
John Rigby9c146032010-01-25 23:12:56 -070093 ulong div;
94
95 div = ((cctl >> CCM_CCTL_AHB_DIV_SHIFT)
96 & CCM_CCTL_AHB_DIV_MASK) + 1;
97
Fabio Estevamf231efb2011-10-13 05:34:59 +000098 return lldiv(fref, div);
John Rigby9c146032010-01-25 23:12:56 -070099}
100
Fabio Estevamf231efb2011-10-13 05:34:59 +0000101ulong imx_get_perclk(int clk)
John Rigby9c146032010-01-25 23:12:56 -0700102{
103 struct ccm_regs *ccm = (struct ccm_regs *)IMX_CCM_BASE;
Fabio Estevamf231efb2011-10-13 05:34:59 +0000104 ulong fref = imx_get_ahbclk();
John Rigby9c146032010-01-25 23:12:56 -0700105 ulong div;
106
Fabio Estevamf231efb2011-10-13 05:34:59 +0000107 div = readl(&ccm->pcdr[CCM_PERCLK_REG(clk)]);
108 div = ((div >> CCM_PERCLK_SHIFT(clk)) & CCM_PERCLK_MASK) + 1;
John Rigby9c146032010-01-25 23:12:56 -0700109
Fabio Estevamf231efb2011-10-13 05:34:59 +0000110 return lldiv(fref, div);
John Rigby9c146032010-01-25 23:12:56 -0700111}
112
Timo Ketola738fa8d2012-04-18 22:55:28 +0000113unsigned int mxc_get_clock(enum mxc_clock clk)
114{
115 if (clk >= MXC_CLK_NUM)
116 return -1;
117 switch (clk) {
118 case MXC_ARM_CLK:
119 return imx_get_armclk();
120 case MXC_FEC_CLK:
121 return imx_get_ahbclk();
122 default:
123 return imx_get_perclk(clk);
124 }
125}
126
Fabio Estevam51f23542011-09-02 05:38:54 +0000127u32 get_cpu_rev(void)
128{
129 u32 srev;
130 u32 system_rev = 0x25000;
131
132 /* read SREV register from IIM module */
133 struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
134 srev = readl(&iim->iim_srev);
135
136 switch (srev) {
137 case 0x00:
138 system_rev |= CHIP_REV_1_0;
139 break;
140 case 0x01:
141 system_rev |= CHIP_REV_1_1;
142 break;
143 default:
144 system_rev |= 0x8000;
145 break;
146 }
147
148 return system_rev;
149}
150
John Rigby9c146032010-01-25 23:12:56 -0700151#if defined(CONFIG_DISPLAY_CPUINFO)
Fabio Estevam4c6b02e2011-09-23 05:13:22 +0000152static char *get_reset_cause(void)
153{
154 /* read RCSR register from CCM module */
155 struct ccm_regs *ccm =
156 (struct ccm_regs *)IMX_CCM_BASE;
157
158 u32 cause = readl(&ccm->rcsr) & 0x0f;
159
160 if (cause == 0)
161 return "POR";
162 else if (cause == 1)
163 return "RST";
164 else if ((cause & 2) == 2)
165 return "WDOG";
166 else if ((cause & 4) == 4)
167 return "SW RESET";
168 else if ((cause & 8) == 8)
169 return "JTAG";
170 else
171 return "unknown reset";
172
173}
174
Fabio Estevamf231efb2011-10-13 05:34:59 +0000175int print_cpuinfo(void)
John Rigby9c146032010-01-25 23:12:56 -0700176{
177 char buf[32];
Fabio Estevam51f23542011-09-02 05:38:54 +0000178 u32 cpurev = get_cpu_rev();
John Rigby9c146032010-01-25 23:12:56 -0700179
Fabio Estevam9a423242011-09-02 05:38:55 +0000180 printf("CPU: Freescale i.MX25 rev%d.%d%s at %s MHz\n",
Fabio Estevam51f23542011-09-02 05:38:54 +0000181 (cpurev & 0xF0) >> 4, (cpurev & 0x0F),
182 ((cpurev & 0x8000) ? " unknown" : ""),
Fabio Estevamf231efb2011-10-13 05:34:59 +0000183 strmhz(buf, imx_get_armclk()));
Fabio Estevam9a423242011-09-02 05:38:55 +0000184 printf("Reset cause: %s\n\n", get_reset_cause());
John Rigby9c146032010-01-25 23:12:56 -0700185 return 0;
186}
187#endif
188
Benoît Thébaudeau463b6852012-08-14 03:17:33 +0000189void enable_caches(void)
190{
191#ifndef CONFIG_SYS_DCACHE_OFF
192 /* Enable D-cache. I-cache is already enabled in start.S */
193 dcache_enable();
194#endif
195}
196
Fabio Estevamf231efb2011-10-13 05:34:59 +0000197int cpu_eth_init(bd_t *bis)
John Rigby9c146032010-01-25 23:12:56 -0700198{
199#if defined(CONFIG_FEC_MXC)
200 struct ccm_regs *ccm = (struct ccm_regs *)IMX_CCM_BASE;
201 ulong val;
202
Fabio Estevamf231efb2011-10-13 05:34:59 +0000203 val = readl(&ccm->cgr0);
John Rigby9c146032010-01-25 23:12:56 -0700204 val |= (1 << 23);
Fabio Estevamf231efb2011-10-13 05:34:59 +0000205 writel(val, &ccm->cgr0);
206 return fecmxc_initialize(bis);
John Rigby9c146032010-01-25 23:12:56 -0700207#else
208 return 0;
209#endif
Timo Ketola738fa8d2012-04-18 22:55:28 +0000210}
211
212int get_clocks(void)
213{
214#ifdef CONFIG_FSL_ESDHC
215 gd->sdhc_clk = mxc_get_clock(MXC_ESDHC_CLK);
216#endif
217 return 0;
John Rigby9c146032010-01-25 23:12:56 -0700218}
219
220/*
221 * Initializes on-chip MMC controllers.
222 * to override, implement board_mmc_init()
223 */
Fabio Estevamf231efb2011-10-13 05:34:59 +0000224int cpu_mmc_init(bd_t *bis)
John Rigby9c146032010-01-25 23:12:56 -0700225{
226#ifdef CONFIG_MXC_MMC
Fabio Estevamf231efb2011-10-13 05:34:59 +0000227 return mxc_mmc_init(bis);
John Rigby9c146032010-01-25 23:12:56 -0700228#else
229 return 0;
230#endif
231}
232
233#ifdef CONFIG_MXC_UART
Fabio Estevam59e6fc52011-03-02 10:14:27 +0100234void mx25_uart1_init_pins(void)
John Rigby9c146032010-01-25 23:12:56 -0700235{
236 struct iomuxc_mux_ctl *muxctl;
237 struct iomuxc_pad_ctl *padctl;
238 u32 inpadctl;
239 u32 outpadctl;
240 u32 muxmode0;
241
242 muxctl = (struct iomuxc_mux_ctl *)IMX_IOPADMUX_BASE;
243 padctl = (struct iomuxc_pad_ctl *)IMX_IOPADCTL_BASE;
Fabio Estevamf231efb2011-10-13 05:34:59 +0000244 muxmode0 = MX25_PIN_MUX_MODE(0);
John Rigby9c146032010-01-25 23:12:56 -0700245 /*
246 * set up input pins with hysteresis and 100K pull-ups
247 */
248 inpadctl = MX25_PIN_PAD_CTL_HYS
249 | MX25_PIN_PAD_CTL_PKE
250 | MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_100K_PU;
251
252 /*
253 * set up output pins with 100K pull-downs
254 * FIXME: need to revisit this
255 * PUE is ignored if PKE is not set
256 * so the right value here is likely
257 * 0x0 for no pull up/down
258 * or
259 * 0xc0 for 100k pull down
260 */
261 outpadctl = MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_100K_PD;
262
263 /* UART1 */
264 /* rxd */
Fabio Estevamf231efb2011-10-13 05:34:59 +0000265 writel(muxmode0, &muxctl->pad_uart1_rxd);
266 writel(inpadctl, &padctl->pad_uart1_rxd);
John Rigby9c146032010-01-25 23:12:56 -0700267
268 /* txd */
Fabio Estevamf231efb2011-10-13 05:34:59 +0000269 writel(muxmode0, &muxctl->pad_uart1_txd);
270 writel(outpadctl, &padctl->pad_uart1_txd);
John Rigby9c146032010-01-25 23:12:56 -0700271
272 /* rts */
Fabio Estevamf231efb2011-10-13 05:34:59 +0000273 writel(muxmode0, &muxctl->pad_uart1_rts);
274 writel(outpadctl, &padctl->pad_uart1_rts);
John Rigby9c146032010-01-25 23:12:56 -0700275
276 /* cts */
Fabio Estevamf231efb2011-10-13 05:34:59 +0000277 writel(muxmode0, &muxctl->pad_uart1_cts);
278 writel(inpadctl, &padctl->pad_uart1_cts);
John Rigby9c146032010-01-25 23:12:56 -0700279}
280#endif /* CONFIG_MXC_UART */
281
282#ifdef CONFIG_FEC_MXC
Fabio Estevamf231efb2011-10-13 05:34:59 +0000283void mx25_fec_init_pins(void)
John Rigby9c146032010-01-25 23:12:56 -0700284{
285 struct iomuxc_mux_ctl *muxctl;
286 struct iomuxc_pad_ctl *padctl;
287 u32 inpadctl_100kpd;
288 u32 inpadctl_22kpu;
289 u32 outpadctl;
290 u32 muxmode0;
291
292 muxctl = (struct iomuxc_mux_ctl *)IMX_IOPADMUX_BASE;
293 padctl = (struct iomuxc_pad_ctl *)IMX_IOPADCTL_BASE;
Fabio Estevamf231efb2011-10-13 05:34:59 +0000294 muxmode0 = MX25_PIN_MUX_MODE(0);
John Rigby9c146032010-01-25 23:12:56 -0700295 inpadctl_100kpd = MX25_PIN_PAD_CTL_HYS
296 | MX25_PIN_PAD_CTL_PKE
297 | MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_100K_PD;
298 inpadctl_22kpu = MX25_PIN_PAD_CTL_HYS
299 | MX25_PIN_PAD_CTL_PKE
300 | MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_22K_PU;
301 /*
302 * set up output pins with 100K pull-downs
303 * FIXME: need to revisit this
304 * PUE is ignored if PKE is not set
305 * so the right value here is likely
306 * 0x0 for no pull
307 * or
308 * 0xc0 for 100k pull down
309 */
310 outpadctl = MX25_PIN_PAD_CTL_PUE | MX25_PIN_PAD_CTL_100K_PD;
311
312 /* FEC_TX_CLK */
Fabio Estevamf231efb2011-10-13 05:34:59 +0000313 writel(muxmode0, &muxctl->pad_fec_tx_clk);
314 writel(inpadctl_100kpd, &padctl->pad_fec_tx_clk);
John Rigby9c146032010-01-25 23:12:56 -0700315
316 /* FEC_RX_DV */
Fabio Estevamf231efb2011-10-13 05:34:59 +0000317 writel(muxmode0, &muxctl->pad_fec_rx_dv);
318 writel(inpadctl_100kpd, &padctl->pad_fec_rx_dv);
John Rigby9c146032010-01-25 23:12:56 -0700319
320 /* FEC_RDATA0 */
Fabio Estevamf231efb2011-10-13 05:34:59 +0000321 writel(muxmode0, &muxctl->pad_fec_rdata0);
322 writel(inpadctl_100kpd, &padctl->pad_fec_rdata0);
John Rigby9c146032010-01-25 23:12:56 -0700323
324 /* FEC_TDATA0 */
Fabio Estevamf231efb2011-10-13 05:34:59 +0000325 writel(muxmode0, &muxctl->pad_fec_tdata0);
326 writel(outpadctl, &padctl->pad_fec_tdata0);
John Rigby9c146032010-01-25 23:12:56 -0700327
328 /* FEC_TX_EN */
Fabio Estevamf231efb2011-10-13 05:34:59 +0000329 writel(muxmode0, &muxctl->pad_fec_tx_en);
330 writel(outpadctl, &padctl->pad_fec_tx_en);
John Rigby9c146032010-01-25 23:12:56 -0700331
332 /* FEC_MDC */
Fabio Estevamf231efb2011-10-13 05:34:59 +0000333 writel(muxmode0, &muxctl->pad_fec_mdc);
334 writel(outpadctl, &padctl->pad_fec_mdc);
John Rigby9c146032010-01-25 23:12:56 -0700335
336 /* FEC_MDIO */
Fabio Estevamf231efb2011-10-13 05:34:59 +0000337 writel(muxmode0, &muxctl->pad_fec_mdio);
338 writel(inpadctl_22kpu, &padctl->pad_fec_mdio);
John Rigby9c146032010-01-25 23:12:56 -0700339
340 /* FEC_RDATA1 */
Fabio Estevamf231efb2011-10-13 05:34:59 +0000341 writel(muxmode0, &muxctl->pad_fec_rdata1);
342 writel(inpadctl_100kpd, &padctl->pad_fec_rdata1);
John Rigby9c146032010-01-25 23:12:56 -0700343
344 /* FEC_TDATA1 */
Fabio Estevamf231efb2011-10-13 05:34:59 +0000345 writel(muxmode0, &muxctl->pad_fec_tdata1);
346 writel(outpadctl, &padctl->pad_fec_tdata1);
John Rigby9c146032010-01-25 23:12:56 -0700347
348}
Liu Hui-R643434df66192010-11-18 23:45:55 +0000349
Fabio Estevam04fc1282011-12-20 05:46:31 +0000350void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
Liu Hui-R643434df66192010-11-18 23:45:55 +0000351{
352 int i;
353 struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
354 struct fuse_bank *bank = &iim->bank[0];
355 struct fuse_bank0_regs *fuse =
356 (struct fuse_bank0_regs *)bank->fuse_regs;
357
358 for (i = 0; i < 6; i++)
359 mac[i] = readl(&fuse->mac_addr[i]) & 0xff;
360}
John Rigby9c146032010-01-25 23:12:56 -0700361#endif /* CONFIG_FEC_MXC */