Marek Vasut | c140e98 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 1 | /* |
Otavio Salvador | fd96c03 | 2013-01-11 03:19:08 +0000 | [diff] [blame] | 2 | * Freescale i.MX23/i.MX28 common code |
Marek Vasut | c140e98 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 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 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 10 | * SPDX-License-Identifier: GPL-2.0+ |
Marek Vasut | c140e98 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 11 | */ |
| 12 | |
| 13 | #include <common.h> |
| 14 | #include <asm/errno.h> |
| 15 | #include <asm/io.h> |
| 16 | #include <asm/arch/clock.h> |
Stefan Roese | 136f3f4 | 2013-04-09 21:06:07 +0000 | [diff] [blame] | 17 | #include <asm/imx-common/dma.h> |
Marek Vasut | c140e98 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 18 | #include <asm/arch/gpio.h> |
Marek Vasut | 53fdab2 | 2011-11-08 23:18:13 +0000 | [diff] [blame] | 19 | #include <asm/arch/iomux.h> |
Marek Vasut | c140e98 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 20 | #include <asm/arch/imx-regs.h> |
| 21 | #include <asm/arch/sys_proto.h> |
Fabio Estevam | 570dcfd | 2013-01-08 05:21:45 +0000 | [diff] [blame] | 22 | #include <linux/compiler.h> |
Marek Vasut | c140e98 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 23 | |
Marek Vasut | 5bf48fb | 2011-11-08 23:18:23 +0000 | [diff] [blame] | 24 | DECLARE_GLOBAL_DATA_PTR; |
| 25 | |
Marek Vasut | c140e98 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 26 | /* Lowlevel init isn't used on i.MX28, so just have a dummy here */ |
| 27 | inline void lowlevel_init(void) {} |
| 28 | |
| 29 | void reset_cpu(ulong ignored) __attribute__((noreturn)); |
| 30 | |
| 31 | void reset_cpu(ulong ignored) |
| 32 | { |
Otavio Salvador | 22f4ff9 | 2012-08-05 09:05:31 +0000 | [diff] [blame] | 33 | struct mxs_rtc_regs *rtc_regs = |
| 34 | (struct mxs_rtc_regs *)MXS_RTC_BASE; |
| 35 | struct mxs_lcdif_regs *lcdif_regs = |
| 36 | (struct mxs_lcdif_regs *)MXS_LCDIF_BASE; |
Marek Vasut | 9c53b7e | 2012-05-01 11:09:47 +0000 | [diff] [blame] | 37 | |
| 38 | /* |
| 39 | * Shut down the LCD controller as it interferes with BootROM boot mode |
| 40 | * pads sampling. |
| 41 | */ |
| 42 | writel(LCDIF_CTRL_RUN, &lcdif_regs->hw_lcdif_ctrl_clr); |
Marek Vasut | c140e98 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 43 | |
| 44 | /* Wait 1 uS before doing the actual watchdog reset */ |
| 45 | writel(1, &rtc_regs->hw_rtc_watchdog); |
| 46 | writel(RTC_CTRL_WATCHDOGEN, &rtc_regs->hw_rtc_ctrl_set); |
| 47 | |
| 48 | /* Endless loop, reset will exit from here */ |
| 49 | for (;;) |
| 50 | ; |
| 51 | } |
| 52 | |
Marek Vasut | 6e5ce31 | 2012-03-15 18:33:23 +0000 | [diff] [blame] | 53 | void enable_caches(void) |
| 54 | { |
| 55 | #ifndef CONFIG_SYS_ICACHE_OFF |
| 56 | icache_enable(); |
| 57 | #endif |
| 58 | #ifndef CONFIG_SYS_DCACHE_OFF |
| 59 | dcache_enable(); |
| 60 | #endif |
| 61 | } |
| 62 | |
Marek Vasut | 39c3103 | 2013-04-25 16:37:12 +0000 | [diff] [blame] | 63 | /* |
| 64 | * This function will craft a jumptable at 0x0 which will redirect interrupt |
| 65 | * vectoring to proper location of U-Boot in RAM. |
| 66 | * |
| 67 | * The structure of the jumptable will be as follows: |
| 68 | * ldr pc, [pc, #0x18] ..... for each vector, thus repeated 8 times |
| 69 | * <destination address> ... for each previous ldr, thus also repeated 8 times |
| 70 | * |
| 71 | * The "ldr pc, [pc, #0x18]" instruction above loads address from memory at |
| 72 | * offset 0x18 from current value of PC register. Note that PC is already |
| 73 | * incremented by 4 when computing the offset, so the effective offset is |
| 74 | * actually 0x20, this the associated <destination address>. Loading the PC |
| 75 | * register with an address performs a jump to that address. |
| 76 | */ |
Marek Vasut | 5bf48fb | 2011-11-08 23:18:23 +0000 | [diff] [blame] | 77 | void mx28_fixup_vt(uint32_t start_addr) |
| 78 | { |
Marek Vasut | 39c3103 | 2013-04-25 16:37:12 +0000 | [diff] [blame] | 79 | /* ldr pc, [pc, #0x18] */ |
| 80 | const uint32_t ldr_pc = 0xe59ff018; |
| 81 | /* Jumptable location is 0x0 */ |
| 82 | uint32_t *vt = (uint32_t *)0x0; |
Marek Vasut | 5bf48fb | 2011-11-08 23:18:23 +0000 | [diff] [blame] | 83 | int i; |
| 84 | |
Marek Vasut | 39c3103 | 2013-04-25 16:37:12 +0000 | [diff] [blame] | 85 | for (i = 0; i < 8; i++) { |
Wolfgang Denk | 6ae8083 | 2014-11-06 14:02:57 +0100 | [diff] [blame] | 86 | /* cppcheck-suppress nullPointer */ |
Marek Vasut | 39c3103 | 2013-04-25 16:37:12 +0000 | [diff] [blame] | 87 | vt[i] = ldr_pc; |
Wolfgang Denk | 6ae8083 | 2014-11-06 14:02:57 +0100 | [diff] [blame] | 88 | /* cppcheck-suppress nullPointer */ |
Marek Vasut | 39c3103 | 2013-04-25 16:37:12 +0000 | [diff] [blame] | 89 | vt[i + 8] = start_addr + (4 * i); |
| 90 | } |
Marek Vasut | 5bf48fb | 2011-11-08 23:18:23 +0000 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | #ifdef CONFIG_ARCH_MISC_INIT |
| 94 | int arch_misc_init(void) |
| 95 | { |
| 96 | mx28_fixup_vt(gd->relocaddr); |
Marek Vasut | c140e98 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 97 | return 0; |
| 98 | } |
Marek Vasut | 5bf48fb | 2011-11-08 23:18:23 +0000 | [diff] [blame] | 99 | #endif |
Marek Vasut | c140e98 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 100 | |
Marek Vasut | c140e98 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 101 | int arch_cpu_init(void) |
| 102 | { |
Otavio Salvador | 22f4ff9 | 2012-08-05 09:05:31 +0000 | [diff] [blame] | 103 | struct mxs_clkctrl_regs *clkctrl_regs = |
| 104 | (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE; |
Marek Vasut | 5bf48fb | 2011-11-08 23:18:23 +0000 | [diff] [blame] | 105 | extern uint32_t _start; |
| 106 | |
| 107 | mx28_fixup_vt((uint32_t)&_start); |
Marek Vasut | c140e98 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 108 | |
| 109 | /* |
| 110 | * Enable NAND clock |
| 111 | */ |
| 112 | /* Clear bypass bit */ |
| 113 | writel(CLKCTRL_CLKSEQ_BYPASS_GPMI, |
| 114 | &clkctrl_regs->hw_clkctrl_clkseq_set); |
| 115 | |
| 116 | /* Set GPMI clock to ref_gpmi / 12 */ |
| 117 | clrsetbits_le32(&clkctrl_regs->hw_clkctrl_gpmi, |
| 118 | CLKCTRL_GPMI_CLKGATE | CLKCTRL_GPMI_DIV_MASK, 1); |
| 119 | |
| 120 | udelay(1000); |
| 121 | |
Marek Vasut | 53fdab2 | 2011-11-08 23:18:13 +0000 | [diff] [blame] | 122 | /* |
| 123 | * Configure GPIO unit |
| 124 | */ |
| 125 | mxs_gpio_init(); |
| 126 | |
Marek Vasut | 93541b4 | 2012-04-08 17:34:46 +0000 | [diff] [blame] | 127 | #ifdef CONFIG_APBH_DMA |
| 128 | /* Start APBH DMA */ |
| 129 | mxs_dma_init(); |
| 130 | #endif |
| 131 | |
Marek Vasut | c140e98 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 132 | return 0; |
| 133 | } |
Marek Vasut | c140e98 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 134 | |
| 135 | #if defined(CONFIG_DISPLAY_CPUINFO) |
Otavio Salvador | ca36b53 | 2012-07-28 11:43:47 +0000 | [diff] [blame] | 136 | static const char *get_cpu_type(void) |
| 137 | { |
Otavio Salvador | 22f4ff9 | 2012-08-05 09:05:31 +0000 | [diff] [blame] | 138 | struct mxs_digctl_regs *digctl_regs = |
| 139 | (struct mxs_digctl_regs *)MXS_DIGCTL_BASE; |
Otavio Salvador | ca36b53 | 2012-07-28 11:43:47 +0000 | [diff] [blame] | 140 | |
| 141 | switch (readl(&digctl_regs->hw_digctl_chipid) & HW_DIGCTL_CHIPID_MASK) { |
Otavio Salvador | fd96c03 | 2013-01-11 03:19:08 +0000 | [diff] [blame] | 142 | case HW_DIGCTL_CHIPID_MX23: |
| 143 | return "23"; |
Otavio Salvador | ca36b53 | 2012-07-28 11:43:47 +0000 | [diff] [blame] | 144 | case HW_DIGCTL_CHIPID_MX28: |
| 145 | return "28"; |
| 146 | default: |
| 147 | return "??"; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | static const char *get_cpu_rev(void) |
| 152 | { |
Otavio Salvador | 22f4ff9 | 2012-08-05 09:05:31 +0000 | [diff] [blame] | 153 | struct mxs_digctl_regs *digctl_regs = |
| 154 | (struct mxs_digctl_regs *)MXS_DIGCTL_BASE; |
Otavio Salvador | ca36b53 | 2012-07-28 11:43:47 +0000 | [diff] [blame] | 155 | uint8_t rev = readl(&digctl_regs->hw_digctl_chipid) & 0x000000FF; |
| 156 | |
| 157 | switch (readl(&digctl_regs->hw_digctl_chipid) & HW_DIGCTL_CHIPID_MASK) { |
Otavio Salvador | fd96c03 | 2013-01-11 03:19:08 +0000 | [diff] [blame] | 158 | case HW_DIGCTL_CHIPID_MX23: |
| 159 | switch (rev) { |
| 160 | case 0x0: |
| 161 | return "1.0"; |
| 162 | case 0x1: |
| 163 | return "1.1"; |
| 164 | case 0x2: |
| 165 | return "1.2"; |
| 166 | case 0x3: |
| 167 | return "1.3"; |
| 168 | case 0x4: |
| 169 | return "1.4"; |
| 170 | default: |
| 171 | return "??"; |
| 172 | } |
Otavio Salvador | ca36b53 | 2012-07-28 11:43:47 +0000 | [diff] [blame] | 173 | case HW_DIGCTL_CHIPID_MX28: |
| 174 | switch (rev) { |
| 175 | case 0x1: |
| 176 | return "1.2"; |
| 177 | default: |
| 178 | return "??"; |
| 179 | } |
| 180 | default: |
| 181 | return "??"; |
| 182 | } |
| 183 | } |
| 184 | |
Marek Vasut | c140e98 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 185 | int print_cpuinfo(void) |
| 186 | { |
Otavio Salvador | f930ea6 | 2012-08-05 09:05:32 +0000 | [diff] [blame] | 187 | struct mxs_spl_data *data = (struct mxs_spl_data *) |
| 188 | ((CONFIG_SYS_TEXT_BASE - sizeof(struct mxs_spl_data)) & ~0xf); |
Marek Vasut | b28fe46 | 2012-05-01 11:09:45 +0000 | [diff] [blame] | 189 | |
Otavio Salvador | ca36b53 | 2012-07-28 11:43:47 +0000 | [diff] [blame] | 190 | printf("CPU: Freescale i.MX%s rev%s at %d MHz\n", |
| 191 | get_cpu_type(), |
| 192 | get_cpu_rev(), |
| 193 | mxc_get_clock(MXC_ARM_CLK) / 1000000); |
Otavio Salvador | cbf0bf2 | 2012-08-13 09:53:12 +0000 | [diff] [blame] | 194 | printf("BOOT: %s\n", mxs_boot_modes[data->boot_mode_idx].mode); |
Marek Vasut | c140e98 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 195 | return 0; |
| 196 | } |
| 197 | #endif |
| 198 | |
| 199 | int do_mx28_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
| 200 | { |
| 201 | printf("CPU: %3d MHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000); |
| 202 | printf("BUS: %3d MHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000000); |
| 203 | printf("EMI: %3d MHz\n", mxc_get_clock(MXC_EMI_CLK)); |
| 204 | printf("GPMI: %3d MHz\n", mxc_get_clock(MXC_GPMI_CLK) / 1000000); |
| 205 | return 0; |
| 206 | } |
| 207 | |
| 208 | /* |
| 209 | * Initializes on-chip ethernet controllers. |
| 210 | */ |
Otavio Salvador | d1de2e0 | 2012-08-19 04:58:29 +0000 | [diff] [blame] | 211 | #if defined(CONFIG_MX28) && defined(CONFIG_CMD_NET) |
Marek Vasut | c140e98 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 212 | int cpu_eth_init(bd_t *bis) |
| 213 | { |
Otavio Salvador | 22f4ff9 | 2012-08-05 09:05:31 +0000 | [diff] [blame] | 214 | struct mxs_clkctrl_regs *clkctrl_regs = |
| 215 | (struct mxs_clkctrl_regs *)MXS_CLKCTRL_BASE; |
Marek Vasut | c140e98 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 216 | |
| 217 | /* Turn on ENET clocks */ |
| 218 | clrbits_le32(&clkctrl_regs->hw_clkctrl_enet, |
| 219 | CLKCTRL_ENET_SLEEP | CLKCTRL_ENET_DISABLE); |
| 220 | |
| 221 | /* Set up ENET PLL for 50 MHz */ |
| 222 | /* Power on ENET PLL */ |
| 223 | writel(CLKCTRL_PLL2CTRL0_POWER, |
| 224 | &clkctrl_regs->hw_clkctrl_pll2ctrl0_set); |
| 225 | |
| 226 | udelay(10); |
| 227 | |
| 228 | /* Gate on ENET PLL */ |
| 229 | writel(CLKCTRL_PLL2CTRL0_CLKGATE, |
| 230 | &clkctrl_regs->hw_clkctrl_pll2ctrl0_clr); |
| 231 | |
| 232 | /* Enable pad output */ |
| 233 | setbits_le32(&clkctrl_regs->hw_clkctrl_enet, CLKCTRL_ENET_CLK_OUT_EN); |
| 234 | |
| 235 | return 0; |
| 236 | } |
| 237 | #endif |
| 238 | |
Fabio Estevam | 570dcfd | 2013-01-08 05:21:45 +0000 | [diff] [blame] | 239 | __weak void mx28_adjust_mac(int dev_id, unsigned char *mac) |
Fabio Estevam | 4029c01 | 2011-12-20 06:42:29 +0000 | [diff] [blame] | 240 | { |
| 241 | mac[0] = 0x00; |
| 242 | mac[1] = 0x04; /* Use FSL vendor MAC address by default */ |
| 243 | |
| 244 | if (dev_id == 1) /* Let MAC1 be MAC0 + 1 by default */ |
| 245 | mac[5] += 1; |
| 246 | } |
| 247 | |
Fabio Estevam | 4029c01 | 2011-12-20 06:42:29 +0000 | [diff] [blame] | 248 | #ifdef CONFIG_MX28_FEC_MAC_IN_OCOTP |
| 249 | |
| 250 | #define MXS_OCOTP_MAX_TIMEOUT 1000000 |
| 251 | void imx_get_mac_from_fuse(int dev_id, unsigned char *mac) |
| 252 | { |
Otavio Salvador | 22f4ff9 | 2012-08-05 09:05:31 +0000 | [diff] [blame] | 253 | struct mxs_ocotp_regs *ocotp_regs = |
| 254 | (struct mxs_ocotp_regs *)MXS_OCOTP_BASE; |
Fabio Estevam | 4029c01 | 2011-12-20 06:42:29 +0000 | [diff] [blame] | 255 | uint32_t data; |
| 256 | |
| 257 | memset(mac, 0, 6); |
| 258 | |
| 259 | writel(OCOTP_CTRL_RD_BANK_OPEN, &ocotp_regs->hw_ocotp_ctrl_set); |
| 260 | |
Otavio Salvador | cbf0bf2 | 2012-08-13 09:53:12 +0000 | [diff] [blame] | 261 | if (mxs_wait_mask_clr(&ocotp_regs->hw_ocotp_ctrl_reg, OCOTP_CTRL_BUSY, |
Fabio Estevam | 4029c01 | 2011-12-20 06:42:29 +0000 | [diff] [blame] | 262 | MXS_OCOTP_MAX_TIMEOUT)) { |
| 263 | printf("MXS FEC: Can't get MAC from OCOTP\n"); |
| 264 | return; |
| 265 | } |
| 266 | |
| 267 | data = readl(&ocotp_regs->hw_ocotp_cust0); |
| 268 | |
| 269 | mac[2] = (data >> 24) & 0xff; |
| 270 | mac[3] = (data >> 16) & 0xff; |
| 271 | mac[4] = (data >> 8) & 0xff; |
| 272 | mac[5] = data & 0xff; |
| 273 | mx28_adjust_mac(dev_id, mac); |
| 274 | } |
| 275 | #else |
| 276 | void imx_get_mac_from_fuse(int dev_id, unsigned char *mac) |
| 277 | { |
| 278 | memset(mac, 0, 6); |
| 279 | } |
| 280 | #endif |
| 281 | |
Otavio Salvador | a2bbe0c | 2012-08-19 04:58:30 +0000 | [diff] [blame] | 282 | int mxs_dram_init(void) |
Fabio Estevam | 93f3a89 | 2011-12-20 05:46:33 +0000 | [diff] [blame] | 283 | { |
Otavio Salvador | f930ea6 | 2012-08-05 09:05:32 +0000 | [diff] [blame] | 284 | struct mxs_spl_data *data = (struct mxs_spl_data *) |
| 285 | ((CONFIG_SYS_TEXT_BASE - sizeof(struct mxs_spl_data)) & ~0xf); |
Fabio Estevam | 93f3a89 | 2011-12-20 05:46:33 +0000 | [diff] [blame] | 286 | |
Marek Vasut | 9136fe9 | 2012-05-01 11:09:44 +0000 | [diff] [blame] | 287 | if (data->mem_dram_size == 0) { |
Otavio Salvador | a2bbe0c | 2012-08-19 04:58:30 +0000 | [diff] [blame] | 288 | printf("MXS:\n" |
Marek Vasut | 9136fe9 | 2012-05-01 11:09:44 +0000 | [diff] [blame] | 289 | "Error, the RAM size passed up from SPL is 0!\n"); |
Fabio Estevam | 93f3a89 | 2011-12-20 05:46:33 +0000 | [diff] [blame] | 290 | hang(); |
| 291 | } |
| 292 | |
Marek Vasut | 9136fe9 | 2012-05-01 11:09:44 +0000 | [diff] [blame] | 293 | gd->ram_size = data->mem_dram_size; |
Fabio Estevam | 93f3a89 | 2011-12-20 05:46:33 +0000 | [diff] [blame] | 294 | return 0; |
| 295 | } |
| 296 | |
Marek Vasut | c140e98 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 297 | U_BOOT_CMD( |
| 298 | clocks, CONFIG_SYS_MAXARGS, 1, do_mx28_showclocks, |
| 299 | "display clocks", |
| 300 | "" |
| 301 | ); |