]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
6e9a0a39 | 2 | /* |
f69077e4 | 3 | * Freescale i.MX23/i.MX28 common code |
6e9a0a39 MV |
4 | * |
5 | * Copyright (C) 2011 Marek Vasut <[email protected]> | |
6 | * on behalf of DENX Software Engineering GmbH | |
7 | * | |
8 | * Based on code from LTIB: | |
9 | * Copyright (C) 2010 Freescale Semiconductor, Inc. | |
6e9a0a39 MV |
10 | */ |
11 | ||
12 | #include <common.h> | |
9a3b4ceb | 13 | #include <cpu_func.h> |
db41d65a | 14 | #include <hang.h> |
90526e9f | 15 | #include <net.h> |
1221ce45 | 16 | #include <linux/errno.h> |
6e9a0a39 MV |
17 | #include <asm/io.h> |
18 | #include <asm/arch/clock.h> | |
552a848e | 19 | #include <asm/mach-imx/dma.h> |
6e9a0a39 | 20 | #include <asm/arch/gpio.h> |
6b6440de | 21 | #include <asm/arch/iomux.h> |
6e9a0a39 MV |
22 | #include <asm/arch/imx-regs.h> |
23 | #include <asm/arch/sys_proto.h> | |
f0930882 | 24 | #include <linux/compiler.h> |
6e9a0a39 | 25 | |
22fe68fb MV |
26 | DECLARE_GLOBAL_DATA_PTR; |
27 | ||
6e9a0a39 | 28 | /* Lowlevel init isn't used on i.MX28, so just have a dummy here */ |
9482aeda | 29 | __weak void lowlevel_init(void) {} |
6e9a0a39 MV |
30 | |
31 | void reset_cpu(ulong ignored) __attribute__((noreturn)); | |
32 | ||
33 | void reset_cpu(ulong ignored) | |
34 | { | |
9c471142 OS |
35 | struct mxs_rtc_regs *rtc_regs = |
36 | (struct mxs_rtc_regs *)MXS_RTC_BASE; | |
37 | struct mxs_lcdif_regs *lcdif_regs = | |
38 | (struct mxs_lcdif_regs *)MXS_LCDIF_BASE; | |
8d4c759f MV |
39 | |
40 | /* | |
41 | * Shut down the LCD controller as it interferes with BootROM boot mode | |
42 | * pads sampling. | |
43 | */ | |
44 | writel(LCDIF_CTRL_RUN, &lcdif_regs->hw_lcdif_ctrl_clr); | |
6e9a0a39 MV |
45 | |
46 | /* Wait 1 uS before doing the actual watchdog reset */ | |
47 | writel(1, &rtc_regs->hw_rtc_watchdog); | |
48 | writel(RTC_CTRL_WATCHDOGEN, &rtc_regs->hw_rtc_ctrl_set); | |
49 | ||
50 | /* Endless loop, reset will exit from here */ | |
51 | for (;;) | |
52 | ; | |
53 | } | |
54 | ||
86fb7b3d MV |
55 | /* |
56 | * This function will craft a jumptable at 0x0 which will redirect interrupt | |
57 | * vectoring to proper location of U-Boot in RAM. | |
58 | * | |
59 | * The structure of the jumptable will be as follows: | |
60 | * ldr pc, [pc, #0x18] ..... for each vector, thus repeated 8 times | |
61 | * <destination address> ... for each previous ldr, thus also repeated 8 times | |
62 | * | |
63 | * The "ldr pc, [pc, #0x18]" instruction above loads address from memory at | |
64 | * offset 0x18 from current value of PC register. Note that PC is already | |
65 | * incremented by 4 when computing the offset, so the effective offset is | |
66 | * actually 0x20, this the associated <destination address>. Loading the PC | |
67 | * register with an address performs a jump to that address. | |
68 | */ | |
22fe68fb MV |
69 | void mx28_fixup_vt(uint32_t start_addr) |
70 | { | |
86fb7b3d MV |
71 | /* ldr pc, [pc, #0x18] */ |
72 | const uint32_t ldr_pc = 0xe59ff018; | |
73 | /* Jumptable location is 0x0 */ | |
74 | uint32_t *vt = (uint32_t *)0x0; | |
22fe68fb MV |
75 | int i; |
76 | ||
86fb7b3d | 77 | for (i = 0; i < 8; i++) { |
0060517a | 78 | /* cppcheck-suppress nullPointer */ |
86fb7b3d | 79 | vt[i] = ldr_pc; |
0060517a | 80 | /* cppcheck-suppress nullPointer */ |
86fb7b3d MV |
81 | vt[i + 8] = start_addr + (4 * i); |
82 | } | |
22fe68fb MV |
83 | } |
84 | ||
85 | #ifdef CONFIG_ARCH_MISC_INIT | |
86 | int arch_misc_init(void) | |
87 | { | |
88 | mx28_fixup_vt(gd->relocaddr); | |
89 | return 0; | |
90 | } | |
91 | #endif | |
92 | ||
6e9a0a39 MV |
93 | int arch_cpu_init(void) |
94 | { | |
9c471142 OS |
95 | struct mxs_clkctrl_regs *clkctrl_regs = |
96 | (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE; | |
22fe68fb MV |
97 | extern uint32_t _start; |
98 | ||
99 | mx28_fixup_vt((uint32_t)&_start); | |
6e9a0a39 MV |
100 | |
101 | /* | |
102 | * Enable NAND clock | |
103 | */ | |
fb946252 | 104 | /* Set bypass bit */ |
6e9a0a39 MV |
105 | writel(CLKCTRL_CLKSEQ_BYPASS_GPMI, |
106 | &clkctrl_regs->hw_clkctrl_clkseq_set); | |
107 | ||
fb946252 | 108 | /* Set GPMI clock to ref_xtal / 1 */ |
abaf5c98 RV |
109 | clrbits_le32(&clkctrl_regs->hw_clkctrl_gpmi, CLKCTRL_GPMI_CLKGATE); |
110 | while (readl(&clkctrl_regs->hw_clkctrl_gpmi) & CLKCTRL_GPMI_CLKGATE) | |
111 | ; | |
6e9a0a39 | 112 | clrsetbits_le32(&clkctrl_regs->hw_clkctrl_gpmi, |
abaf5c98 | 113 | CLKCTRL_GPMI_DIV_MASK, 1); |
6e9a0a39 MV |
114 | |
115 | udelay(1000); | |
116 | ||
6b6440de MV |
117 | /* |
118 | * Configure GPIO unit | |
119 | */ | |
120 | mxs_gpio_init(); | |
121 | ||
96666a39 MV |
122 | #ifdef CONFIG_APBH_DMA |
123 | /* Start APBH DMA */ | |
124 | mxs_dma_init(); | |
125 | #endif | |
126 | ||
6e9a0a39 MV |
127 | return 0; |
128 | } | |
6e9a0a39 | 129 | |
bf3b9cb6 | 130 | u32 get_cpu_rev(void) |
b0261b12 | 131 | { |
9c471142 OS |
132 | struct mxs_digctl_regs *digctl_regs = |
133 | (struct mxs_digctl_regs *)MXS_DIGCTL_BASE; | |
b0261b12 OS |
134 | uint8_t rev = readl(&digctl_regs->hw_digctl_chipid) & 0x000000FF; |
135 | ||
136 | switch (readl(&digctl_regs->hw_digctl_chipid) & HW_DIGCTL_CHIPID_MASK) { | |
f69077e4 OS |
137 | case HW_DIGCTL_CHIPID_MX23: |
138 | switch (rev) { | |
139 | case 0x0: | |
f69077e4 | 140 | case 0x1: |
f69077e4 | 141 | case 0x2: |
f69077e4 | 142 | case 0x3: |
f69077e4 | 143 | case 0x4: |
bf3b9cb6 | 144 | return (MXC_CPU_MX23 << 12) | (rev + 0x10); |
f69077e4 | 145 | default: |
bf3b9cb6 | 146 | return 0; |
f69077e4 | 147 | } |
b0261b12 OS |
148 | case HW_DIGCTL_CHIPID_MX28: |
149 | switch (rev) { | |
150 | case 0x1: | |
bf3b9cb6 | 151 | return (MXC_CPU_MX28 << 12) | 0x12; |
b0261b12 | 152 | default: |
bf3b9cb6 | 153 | return 0; |
b0261b12 | 154 | } |
bf3b9cb6 PF |
155 | default: |
156 | return 0; | |
157 | } | |
158 | } | |
159 | ||
160 | #if defined(CONFIG_DISPLAY_CPUINFO) | |
161 | const char *get_imx_type(u32 imxtype) | |
162 | { | |
163 | switch (imxtype) { | |
164 | case MXC_CPU_MX23: | |
d2ba7a6a | 165 | return "23"; |
bf3b9cb6 | 166 | case MXC_CPU_MX28: |
d2ba7a6a | 167 | return "28"; |
b0261b12 OS |
168 | default: |
169 | return "??"; | |
170 | } | |
171 | } | |
172 | ||
6e9a0a39 MV |
173 | int print_cpuinfo(void) |
174 | { | |
bf3b9cb6 | 175 | u32 cpurev; |
33ea1193 | 176 | struct mxs_spl_data *data = MXS_SPL_DATA; |
f8c4a86b | 177 | |
bf3b9cb6 PF |
178 | cpurev = get_cpu_rev(); |
179 | printf("CPU: Freescale i.MX%s rev%d.%d at %d MHz\n", | |
180 | get_imx_type((cpurev & 0xFF000) >> 12), | |
181 | (cpurev & 0x000F0) >> 4, | |
182 | (cpurev & 0x0000F) >> 0, | |
b0261b12 | 183 | mxc_get_clock(MXC_ARM_CLK) / 1000000); |
fa7a51cb | 184 | printf("BOOT: %s\n", mxs_boot_modes[data->boot_mode_idx].mode); |
6e9a0a39 MV |
185 | return 0; |
186 | } | |
187 | #endif | |
188 | ||
189 | int do_mx28_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) | |
190 | { | |
191 | printf("CPU: %3d MHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000); | |
192 | printf("BUS: %3d MHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000000); | |
193 | printf("EMI: %3d MHz\n", mxc_get_clock(MXC_EMI_CLK)); | |
194 | printf("GPMI: %3d MHz\n", mxc_get_clock(MXC_GPMI_CLK) / 1000000); | |
195 | return 0; | |
196 | } | |
197 | ||
198 | /* | |
199 | * Initializes on-chip ethernet controllers. | |
200 | */ | |
89ce53ff | 201 | #if defined(CONFIG_MX28) && defined(CONFIG_CMD_NET) |
6e9a0a39 MV |
202 | int cpu_eth_init(bd_t *bis) |
203 | { | |
9c471142 OS |
204 | struct mxs_clkctrl_regs *clkctrl_regs = |
205 | (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE; | |
6e9a0a39 MV |
206 | |
207 | /* Turn on ENET clocks */ | |
208 | clrbits_le32(&clkctrl_regs->hw_clkctrl_enet, | |
209 | CLKCTRL_ENET_SLEEP | CLKCTRL_ENET_DISABLE); | |
210 | ||
211 | /* Set up ENET PLL for 50 MHz */ | |
212 | /* Power on ENET PLL */ | |
213 | writel(CLKCTRL_PLL2CTRL0_POWER, | |
214 | &clkctrl_regs->hw_clkctrl_pll2ctrl0_set); | |
215 | ||
216 | udelay(10); | |
217 | ||
218 | /* Gate on ENET PLL */ | |
219 | writel(CLKCTRL_PLL2CTRL0_CLKGATE, | |
220 | &clkctrl_regs->hw_clkctrl_pll2ctrl0_clr); | |
221 | ||
222 | /* Enable pad output */ | |
223 | setbits_le32(&clkctrl_regs->hw_clkctrl_enet, CLKCTRL_ENET_CLK_OUT_EN); | |
224 | ||
225 | return 0; | |
226 | } | |
227 | #endif | |
228 | ||
f0930882 | 229 | __weak void mx28_adjust_mac(int dev_id, unsigned char *mac) |
5cb525f3 FE |
230 | { |
231 | mac[0] = 0x00; | |
232 | mac[1] = 0x04; /* Use FSL vendor MAC address by default */ | |
233 | ||
234 | if (dev_id == 1) /* Let MAC1 be MAC0 + 1 by default */ | |
235 | mac[5] += 1; | |
236 | } | |
237 | ||
5cb525f3 FE |
238 | #ifdef CONFIG_MX28_FEC_MAC_IN_OCOTP |
239 | ||
240 | #define MXS_OCOTP_MAX_TIMEOUT 1000000 | |
241 | void imx_get_mac_from_fuse(int dev_id, unsigned char *mac) | |
242 | { | |
9c471142 OS |
243 | struct mxs_ocotp_regs *ocotp_regs = |
244 | (struct mxs_ocotp_regs *)MXS_OCOTP_BASE; | |
5cb525f3 FE |
245 | uint32_t data; |
246 | ||
247 | memset(mac, 0, 6); | |
248 | ||
249 | writel(OCOTP_CTRL_RD_BANK_OPEN, &ocotp_regs->hw_ocotp_ctrl_set); | |
250 | ||
fa7a51cb | 251 | if (mxs_wait_mask_clr(&ocotp_regs->hw_ocotp_ctrl_reg, OCOTP_CTRL_BUSY, |
5cb525f3 FE |
252 | MXS_OCOTP_MAX_TIMEOUT)) { |
253 | printf("MXS FEC: Can't get MAC from OCOTP\n"); | |
254 | return; | |
255 | } | |
256 | ||
257 | data = readl(&ocotp_regs->hw_ocotp_cust0); | |
258 | ||
259 | mac[2] = (data >> 24) & 0xff; | |
260 | mac[3] = (data >> 16) & 0xff; | |
261 | mac[4] = (data >> 8) & 0xff; | |
262 | mac[5] = data & 0xff; | |
263 | mx28_adjust_mac(dev_id, mac); | |
264 | } | |
265 | #else | |
266 | void imx_get_mac_from_fuse(int dev_id, unsigned char *mac) | |
267 | { | |
268 | memset(mac, 0, 6); | |
269 | } | |
270 | #endif | |
271 | ||
72f8ebf1 | 272 | int mxs_dram_init(void) |
5bcc6a89 | 273 | { |
33ea1193 | 274 | struct mxs_spl_data *data = MXS_SPL_DATA; |
5bcc6a89 | 275 | |
0239c2fb | 276 | if (data->mem_dram_size == 0) { |
72f8ebf1 | 277 | printf("MXS:\n" |
0239c2fb | 278 | "Error, the RAM size passed up from SPL is 0!\n"); |
5bcc6a89 FE |
279 | hang(); |
280 | } | |
281 | ||
0239c2fb | 282 | gd->ram_size = data->mem_dram_size; |
5bcc6a89 FE |
283 | return 0; |
284 | } | |
285 | ||
6e9a0a39 MV |
286 | U_BOOT_CMD( |
287 | clocks, CONFIG_SYS_MAXARGS, 1, do_mx28_showclocks, | |
288 | "display clocks", | |
289 | "" | |
290 | ); |