]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/arm926ejs/mx28/mx28.c
merged denx master branch
[karo-tx-uboot.git] / arch / arm / cpu / arm926ejs / mx28 / mx28.c
1 /*
2  * Freescale i.MX28 common code
3  *
4  * Copyright (C) 2011 Marek Vasut <marek.vasut@gmail.com>
5  * on behalf of DENX Software Engineering GmbH
6  *
7  * Based on code from LTIB:
8  * Copyright (C) 2010 Freescale Semiconductor, Inc.
9  *
10  * See file CREDITS for list of people who contributed to this
11  * project.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License as
15  * published by the Free Software Foundation; either version 2 of
16  * the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
26  * MA 02111-1307 USA
27  */
28
29 #include <common.h>
30 #include <asm/errno.h>
31 #include <asm/io.h>
32 #include <asm/arch/clock.h>
33 #include <asm/arch/dma.h>
34 #include <asm/arch/gpio.h>
35 #include <asm/arch/iomux.h>
36 #include <asm/arch/imx-regs.h>
37 #include <asm/arch/sys_proto.h>
38
39 DECLARE_GLOBAL_DATA_PTR;
40
41 /* 1 second delay should be plenty of time for block reset. */
42 #define RESET_MAX_TIMEOUT       1000000
43
44 #define MX28_BLOCK_SFTRST       (1 << 31)
45 #define MX28_BLOCK_CLKGATE      (1 << 30)
46
47 /* Lowlevel init isn't used on i.MX28, so just have a dummy here */
48 inline void lowlevel_init(void) {}
49
50 void reset_cpu(ulong ignored) __attribute__((noreturn));
51
52 void reset_cpu(ulong ignored)
53 {
54         struct mx28_rtc_regs *rtc_regs =
55                 (struct mx28_rtc_regs *)MXS_RTC_BASE;
56         struct mx28_lcdif_regs *lcdif_regs =
57                 (struct mx28_lcdif_regs *)MXS_LCDIF_BASE;
58
59         /*
60          * Shut down the LCD controller as it interferes with BootROM boot mode
61          * pads sampling.
62          */
63         writel(LCDIF_CTRL_RUN, &lcdif_regs->hw_lcdif_ctrl_clr);
64
65         /* Wait 1 uS before doing the actual watchdog reset */
66         writel(1, &rtc_regs->hw_rtc_watchdog);
67         writel(RTC_CTRL_WATCHDOGEN, &rtc_regs->hw_rtc_ctrl_set);
68
69         /* Endless loop, reset will exit from here */
70         for (;;)
71                 ;
72 }
73
74 void enable_caches(void)
75 {
76 #ifndef CONFIG_SYS_ICACHE_OFF
77         icache_enable();
78 #endif
79 #ifndef CONFIG_SYS_DCACHE_OFF
80         dcache_enable();
81 #endif
82 }
83
84 int mx28_wait_mask_set(struct mx28_register_32 *reg, uint32_t mask, int timeout)
85 {
86         while (--timeout) {
87                 if ((readl(&reg->reg) & mask) == mask)
88                         break;
89                 udelay(1);
90         }
91
92         return !timeout;
93 }
94
95 int mx28_wait_mask_clr(struct mx28_register_32 *reg, uint32_t mask, int timeout)
96 {
97         while (--timeout) {
98                 if ((readl(&reg->reg) & mask) == 0)
99                         break;
100                 udelay(1);
101         }
102
103         return !timeout;
104 }
105
106 int mx28_reset_block(struct mx28_register_32 *reg)
107 {
108         /* Clear SFTRST */
109         writel(MX28_BLOCK_SFTRST, &reg->reg_clr);
110
111         if (mx28_wait_mask_clr(reg, MX28_BLOCK_SFTRST, RESET_MAX_TIMEOUT))
112                 return 1;
113
114         /* Clear CLKGATE */
115         writel(MX28_BLOCK_CLKGATE, &reg->reg_clr);
116
117         /* Set SFTRST */
118         writel(MX28_BLOCK_SFTRST, &reg->reg_set);
119
120         /* Wait for CLKGATE being set */
121         if (mx28_wait_mask_set(reg, MX28_BLOCK_CLKGATE, RESET_MAX_TIMEOUT))
122                 return 1;
123
124         /* Clear SFTRST */
125         writel(MX28_BLOCK_SFTRST, &reg->reg_clr);
126
127         if (mx28_wait_mask_clr(reg, MX28_BLOCK_SFTRST, RESET_MAX_TIMEOUT))
128                 return 1;
129
130         /* Clear CLKGATE */
131         writel(MX28_BLOCK_CLKGATE, &reg->reg_clr);
132
133         if (mx28_wait_mask_clr(reg, MX28_BLOCK_CLKGATE, RESET_MAX_TIMEOUT))
134                 return 1;
135
136         return 0;
137 }
138
139 void mx28_fixup_vt(uint32_t start_addr)
140 {
141         uint32_t *vt = (uint32_t *)0x20;
142         int i;
143
144         for (i = 0; i < 8; i++)
145                 vt[i] = start_addr + (4 * i);
146 }
147
148 #ifdef  CONFIG_ARCH_MISC_INIT
149 int arch_misc_init(void)
150 {
151         mx28_fixup_vt(gd->relocaddr);
152         return 0;
153 }
154 #endif
155
156 #ifdef  CONFIG_ARCH_CPU_INIT
157 int arch_cpu_init(void)
158 {
159         struct mx28_clkctrl_regs *clkctrl_regs =
160                 (struct mx28_clkctrl_regs *)MXS_CLKCTRL_BASE;
161         extern uint32_t _start;
162
163         mx28_fixup_vt((uint32_t)&_start);
164
165         /*
166          * Enable NAND clock
167          */
168         /* Clear bypass bit */
169         writel(CLKCTRL_CLKSEQ_BYPASS_GPMI,
170                 &clkctrl_regs->hw_clkctrl_clkseq_set);
171
172         /* Set GPMI clock to ref_gpmi / 12 */
173         clrsetbits_le32(&clkctrl_regs->hw_clkctrl_gpmi,
174                 CLKCTRL_GPMI_CLKGATE | CLKCTRL_GPMI_DIV_MASK, 1);
175
176         udelay(1000);
177
178         /*
179          * Configure GPIO unit
180          */
181         mxs_gpio_init();
182
183 #ifdef  CONFIG_APBH_DMA
184         /* Start APBH DMA */
185         mxs_dma_init();
186 #endif
187
188         return 0;
189 }
190 #endif
191
192 #if defined(CONFIG_DISPLAY_CPUINFO)
193 int print_cpuinfo(void)
194 {
195         struct mx28_spl_data *data = (struct mx28_spl_data *)
196                 ((CONFIG_SYS_TEXT_BASE - sizeof(struct mx28_spl_data)) & ~0xf);
197
198         printf("Freescale i.MX28 family at %d MHz\n",
199                         mxc_get_clock(MXC_ARM_CLK) / 1000000);
200         printf("BOOT:  %s\n", mx28_boot_modes[data->boot_mode_idx].mode);
201         return 0;
202 }
203 #endif
204
205 int do_mx28_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
206 {
207         printf("CPU:   %3d MHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000);
208         printf("BUS:   %3d MHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000000);
209         printf("EMI:   %3d MHz\n", mxc_get_clock(MXC_EMI_CLK));
210         printf("GPMI:  %3d MHz\n", mxc_get_clock(MXC_GPMI_CLK) / 1000000);
211         return 0;
212 }
213
214 /*
215  * Initializes on-chip ethernet controllers.
216  */
217 #ifdef  CONFIG_CMD_NET
218 int cpu_eth_init(bd_t *bis)
219 {
220         struct mx28_clkctrl_regs *clkctrl_regs =
221                 (struct mx28_clkctrl_regs *)MXS_CLKCTRL_BASE;
222
223         /* Turn on ENET clocks */
224         clrbits_le32(&clkctrl_regs->hw_clkctrl_enet,
225                 CLKCTRL_ENET_SLEEP | CLKCTRL_ENET_DISABLE);
226
227         /* Set up ENET PLL for 50 MHz */
228         /* Power on ENET PLL */
229         writel(CLKCTRL_PLL2CTRL0_POWER,
230                 &clkctrl_regs->hw_clkctrl_pll2ctrl0_set);
231
232         udelay(10);
233
234         /*
235          * Enable pad output; must be done BEFORE enabling PLL
236          * according to i.MX28 Ref. Manual Rev. 1, 2010 p. 883
237          */
238         setbits_le32(&clkctrl_regs->hw_clkctrl_enet, CLKCTRL_ENET_CLK_OUT_EN);
239
240         /* Gate on ENET PLL */
241         writel(CLKCTRL_PLL2CTRL0_CLKGATE,
242                 &clkctrl_regs->hw_clkctrl_pll2ctrl0_clr);
243
244         return 0;
245 }
246 #endif
247
248 static void __mx28_adjust_mac(int dev_id, unsigned char *mac)
249 {
250         mac[0] = 0x00;
251         mac[1] = 0x04; /* Use FSL vendor MAC address by default */
252
253         if (dev_id == 1) /* Let MAC1 be MAC0 + 1 by default */
254                 mac[5] += 1;
255 }
256
257 void mx28_adjust_mac(int dev_id, unsigned char *mac)
258         __attribute__((weak, alias("__mx28_adjust_mac")));
259
260 #ifdef  CONFIG_MX28_FEC_MAC_IN_OCOTP
261
262 #define MXS_OCOTP_MAX_TIMEOUT   1000000
263 void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
264 {
265         struct mx28_ocotp_regs *ocotp_regs =
266                 (struct mx28_ocotp_regs *)MXS_OCOTP_BASE;
267         uint32_t data;
268
269         memset(mac, 0, 6);
270
271         writel(OCOTP_CTRL_RD_BANK_OPEN, &ocotp_regs->hw_ocotp_ctrl_set);
272
273         if (mx28_wait_mask_clr(&ocotp_regs->hw_ocotp_ctrl_reg, OCOTP_CTRL_BUSY,
274                                 MXS_OCOTP_MAX_TIMEOUT)) {
275                 printf("MXS FEC: Can't get MAC from OCOTP\n");
276                 return;
277         }
278
279         data = readl(&ocotp_regs->hw_ocotp_cust0);
280
281         mac[2] = (data >> 24) & 0xff;
282         mac[3] = (data >> 16) & 0xff;
283         mac[4] = (data >> 8) & 0xff;
284         mac[5] = data & 0xff;
285         mx28_adjust_mac(dev_id, mac);
286 }
287 #else
288 void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
289 {
290         memset(mac, 0, 6);
291 }
292 #endif
293
294 int mx28_dram_init(void)
295 {
296         struct mx28_spl_data *data = (struct mx28_spl_data *)
297                 ((CONFIG_SYS_TEXT_BASE - sizeof(struct mx28_spl_data)) & ~0xf);
298
299         if (data->mem_dram_size == 0) {
300                 printf("MX28:\n"
301                         "Error, the RAM size passed up from SPL is 0!\n");
302                 hang();
303         }
304
305         gd->ram_size = data->mem_dram_size;
306         return 0;
307 }
308
309 U_BOOT_CMD(
310         clocks, CONFIG_SYS_MAXARGS, 1, do_mx28_showclocks,
311         "display clocks",
312         ""
313 );