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