Marek Vasut | 6e9a0a3 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 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> |
Marek Vasut | 96666a3 | 2012-04-08 17:34:46 +0000 | [diff] [blame] | 33 | #include <asm/arch/dma.h> |
Marek Vasut | 6e9a0a3 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 34 | #include <asm/arch/gpio.h> |
Marek Vasut | 6b6440d | 2011-11-08 23:18:13 +0000 | [diff] [blame] | 35 | #include <asm/arch/iomux.h> |
Marek Vasut | 6e9a0a3 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 36 | #include <asm/arch/imx-regs.h> |
| 37 | #include <asm/arch/sys_proto.h> |
| 38 | |
Marek Vasut | 22fe68f | 2011-11-08 23:18:23 +0000 | [diff] [blame] | 39 | DECLARE_GLOBAL_DATA_PTR; |
| 40 | |
Marek Vasut | 6e9a0a3 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 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 | |
| 55 | struct mx28_rtc_regs *rtc_regs = |
| 56 | (struct mx28_rtc_regs *)MXS_RTC_BASE; |
| 57 | |
| 58 | /* Wait 1 uS before doing the actual watchdog reset */ |
| 59 | writel(1, &rtc_regs->hw_rtc_watchdog); |
| 60 | writel(RTC_CTRL_WATCHDOGEN, &rtc_regs->hw_rtc_ctrl_set); |
| 61 | |
| 62 | /* Endless loop, reset will exit from here */ |
| 63 | for (;;) |
| 64 | ; |
| 65 | } |
| 66 | |
Marek Vasut | 345cd35 | 2012-03-15 18:33:23 +0000 | [diff] [blame] | 67 | void enable_caches(void) |
| 68 | { |
| 69 | #ifndef CONFIG_SYS_ICACHE_OFF |
| 70 | icache_enable(); |
| 71 | #endif |
| 72 | #ifndef CONFIG_SYS_DCACHE_OFF |
| 73 | dcache_enable(); |
| 74 | #endif |
| 75 | } |
| 76 | |
Robert Delien | b228e14 | 2012-02-26 12:15:05 +0000 | [diff] [blame] | 77 | int mx28_wait_mask_set(struct mx28_register_32 *reg, uint32_t mask, int timeout) |
Marek Vasut | 6e9a0a3 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 78 | { |
| 79 | while (--timeout) { |
| 80 | if ((readl(®->reg) & mask) == mask) |
| 81 | break; |
| 82 | udelay(1); |
| 83 | } |
| 84 | |
| 85 | return !timeout; |
| 86 | } |
| 87 | |
Robert Delien | b228e14 | 2012-02-26 12:15:05 +0000 | [diff] [blame] | 88 | int mx28_wait_mask_clr(struct mx28_register_32 *reg, uint32_t mask, int timeout) |
Marek Vasut | 6e9a0a3 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 89 | { |
| 90 | while (--timeout) { |
| 91 | if ((readl(®->reg) & mask) == 0) |
| 92 | break; |
| 93 | udelay(1); |
| 94 | } |
| 95 | |
| 96 | return !timeout; |
| 97 | } |
| 98 | |
Robert Delien | b228e14 | 2012-02-26 12:15:05 +0000 | [diff] [blame] | 99 | int mx28_reset_block(struct mx28_register_32 *reg) |
Marek Vasut | 6e9a0a3 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 100 | { |
| 101 | /* Clear SFTRST */ |
| 102 | writel(MX28_BLOCK_SFTRST, ®->reg_clr); |
| 103 | |
| 104 | if (mx28_wait_mask_clr(reg, MX28_BLOCK_SFTRST, RESET_MAX_TIMEOUT)) |
| 105 | return 1; |
| 106 | |
| 107 | /* Clear CLKGATE */ |
| 108 | writel(MX28_BLOCK_CLKGATE, ®->reg_clr); |
| 109 | |
| 110 | /* Set SFTRST */ |
| 111 | writel(MX28_BLOCK_SFTRST, ®->reg_set); |
| 112 | |
| 113 | /* Wait for CLKGATE being set */ |
| 114 | if (mx28_wait_mask_set(reg, MX28_BLOCK_CLKGATE, RESET_MAX_TIMEOUT)) |
| 115 | return 1; |
| 116 | |
| 117 | /* Clear SFTRST */ |
| 118 | writel(MX28_BLOCK_SFTRST, ®->reg_clr); |
| 119 | |
| 120 | if (mx28_wait_mask_clr(reg, MX28_BLOCK_SFTRST, RESET_MAX_TIMEOUT)) |
| 121 | return 1; |
| 122 | |
| 123 | /* Clear CLKGATE */ |
| 124 | writel(MX28_BLOCK_CLKGATE, ®->reg_clr); |
| 125 | |
| 126 | if (mx28_wait_mask_clr(reg, MX28_BLOCK_CLKGATE, RESET_MAX_TIMEOUT)) |
| 127 | return 1; |
| 128 | |
| 129 | return 0; |
| 130 | } |
| 131 | |
Marek Vasut | 22fe68f | 2011-11-08 23:18:23 +0000 | [diff] [blame] | 132 | void mx28_fixup_vt(uint32_t start_addr) |
| 133 | { |
| 134 | uint32_t *vt = (uint32_t *)0x20; |
| 135 | int i; |
| 136 | |
| 137 | for (i = 0; i < 8; i++) |
| 138 | vt[i] = start_addr + (4 * i); |
| 139 | } |
| 140 | |
| 141 | #ifdef CONFIG_ARCH_MISC_INIT |
| 142 | int arch_misc_init(void) |
| 143 | { |
| 144 | mx28_fixup_vt(gd->relocaddr); |
| 145 | return 0; |
| 146 | } |
| 147 | #endif |
| 148 | |
Marek Vasut | 6e9a0a3 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 149 | #ifdef CONFIG_ARCH_CPU_INIT |
| 150 | int arch_cpu_init(void) |
| 151 | { |
| 152 | struct mx28_clkctrl_regs *clkctrl_regs = |
| 153 | (struct mx28_clkctrl_regs *)MXS_CLKCTRL_BASE; |
Marek Vasut | 22fe68f | 2011-11-08 23:18:23 +0000 | [diff] [blame] | 154 | extern uint32_t _start; |
| 155 | |
| 156 | mx28_fixup_vt((uint32_t)&_start); |
Marek Vasut | 6e9a0a3 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 157 | |
| 158 | /* |
| 159 | * Enable NAND clock |
| 160 | */ |
| 161 | /* Clear bypass bit */ |
| 162 | writel(CLKCTRL_CLKSEQ_BYPASS_GPMI, |
| 163 | &clkctrl_regs->hw_clkctrl_clkseq_set); |
| 164 | |
| 165 | /* Set GPMI clock to ref_gpmi / 12 */ |
| 166 | clrsetbits_le32(&clkctrl_regs->hw_clkctrl_gpmi, |
| 167 | CLKCTRL_GPMI_CLKGATE | CLKCTRL_GPMI_DIV_MASK, 1); |
| 168 | |
| 169 | udelay(1000); |
| 170 | |
Marek Vasut | 6b6440d | 2011-11-08 23:18:13 +0000 | [diff] [blame] | 171 | /* |
| 172 | * Configure GPIO unit |
| 173 | */ |
| 174 | mxs_gpio_init(); |
| 175 | |
Marek Vasut | 96666a3 | 2012-04-08 17:34:46 +0000 | [diff] [blame] | 176 | #ifdef CONFIG_APBH_DMA |
| 177 | /* Start APBH DMA */ |
| 178 | mxs_dma_init(); |
| 179 | #endif |
| 180 | |
Marek Vasut | 6e9a0a3 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 181 | return 0; |
| 182 | } |
| 183 | #endif |
| 184 | |
| 185 | #if defined(CONFIG_DISPLAY_CPUINFO) |
| 186 | int print_cpuinfo(void) |
| 187 | { |
Fabio Estevam | 8218272 | 2012-01-22 16:38:08 +0000 | [diff] [blame] | 188 | printf("Freescale i.MX28 family at %d MHz\n", |
| 189 | mxc_get_clock(MXC_ARM_CLK) / 1000000); |
Marek Vasut | 6e9a0a3 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 190 | return 0; |
| 191 | } |
| 192 | #endif |
| 193 | |
| 194 | int do_mx28_showclocks(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]) |
| 195 | { |
| 196 | printf("CPU: %3d MHz\n", mxc_get_clock(MXC_ARM_CLK) / 1000000); |
| 197 | printf("BUS: %3d MHz\n", mxc_get_clock(MXC_AHB_CLK) / 1000000); |
| 198 | printf("EMI: %3d MHz\n", mxc_get_clock(MXC_EMI_CLK)); |
| 199 | printf("GPMI: %3d MHz\n", mxc_get_clock(MXC_GPMI_CLK) / 1000000); |
| 200 | return 0; |
| 201 | } |
| 202 | |
| 203 | /* |
| 204 | * Initializes on-chip ethernet controllers. |
| 205 | */ |
| 206 | #ifdef CONFIG_CMD_NET |
| 207 | int cpu_eth_init(bd_t *bis) |
| 208 | { |
| 209 | struct mx28_clkctrl_regs *clkctrl_regs = |
| 210 | (struct mx28_clkctrl_regs *)MXS_CLKCTRL_BASE; |
| 211 | |
| 212 | /* Turn on ENET clocks */ |
| 213 | clrbits_le32(&clkctrl_regs->hw_clkctrl_enet, |
| 214 | CLKCTRL_ENET_SLEEP | CLKCTRL_ENET_DISABLE); |
| 215 | |
| 216 | /* Set up ENET PLL for 50 MHz */ |
| 217 | /* Power on ENET PLL */ |
| 218 | writel(CLKCTRL_PLL2CTRL0_POWER, |
| 219 | &clkctrl_regs->hw_clkctrl_pll2ctrl0_set); |
| 220 | |
| 221 | udelay(10); |
| 222 | |
| 223 | /* Gate on ENET PLL */ |
| 224 | writel(CLKCTRL_PLL2CTRL0_CLKGATE, |
| 225 | &clkctrl_regs->hw_clkctrl_pll2ctrl0_clr); |
| 226 | |
| 227 | /* Enable pad output */ |
| 228 | setbits_le32(&clkctrl_regs->hw_clkctrl_enet, CLKCTRL_ENET_CLK_OUT_EN); |
| 229 | |
| 230 | return 0; |
| 231 | } |
| 232 | #endif |
| 233 | |
Fabio Estevam | 5cb525f | 2011-12-20 06:42:29 +0000 | [diff] [blame] | 234 | static void __mx28_adjust_mac(int dev_id, unsigned char *mac) |
| 235 | { |
| 236 | mac[0] = 0x00; |
| 237 | mac[1] = 0x04; /* Use FSL vendor MAC address by default */ |
| 238 | |
| 239 | if (dev_id == 1) /* Let MAC1 be MAC0 + 1 by default */ |
| 240 | mac[5] += 1; |
| 241 | } |
| 242 | |
| 243 | void mx28_adjust_mac(int dev_id, unsigned char *mac) |
| 244 | __attribute__((weak, alias("__mx28_adjust_mac"))); |
| 245 | |
| 246 | #ifdef CONFIG_MX28_FEC_MAC_IN_OCOTP |
| 247 | |
| 248 | #define MXS_OCOTP_MAX_TIMEOUT 1000000 |
| 249 | void imx_get_mac_from_fuse(int dev_id, unsigned char *mac) |
| 250 | { |
| 251 | struct mx28_ocotp_regs *ocotp_regs = |
| 252 | (struct mx28_ocotp_regs *)MXS_OCOTP_BASE; |
| 253 | uint32_t data; |
| 254 | |
| 255 | memset(mac, 0, 6); |
| 256 | |
| 257 | writel(OCOTP_CTRL_RD_BANK_OPEN, &ocotp_regs->hw_ocotp_ctrl_set); |
| 258 | |
| 259 | if (mx28_wait_mask_clr(&ocotp_regs->hw_ocotp_ctrl_reg, OCOTP_CTRL_BUSY, |
| 260 | MXS_OCOTP_MAX_TIMEOUT)) { |
| 261 | printf("MXS FEC: Can't get MAC from OCOTP\n"); |
| 262 | return; |
| 263 | } |
| 264 | |
| 265 | data = readl(&ocotp_regs->hw_ocotp_cust0); |
| 266 | |
| 267 | mac[2] = (data >> 24) & 0xff; |
| 268 | mac[3] = (data >> 16) & 0xff; |
| 269 | mac[4] = (data >> 8) & 0xff; |
| 270 | mac[5] = data & 0xff; |
| 271 | mx28_adjust_mac(dev_id, mac); |
| 272 | } |
| 273 | #else |
| 274 | void imx_get_mac_from_fuse(int dev_id, unsigned char *mac) |
| 275 | { |
| 276 | memset(mac, 0, 6); |
| 277 | } |
| 278 | #endif |
| 279 | |
Fabio Estevam | 5bcc6a8 | 2011-12-20 05:46:33 +0000 | [diff] [blame] | 280 | int mx28_dram_init(void) |
| 281 | { |
Marek Vasut | 0239c2f | 2012-05-01 11:09:44 +0000 | [diff] [blame^] | 282 | struct mx28_spl_data *data = (struct mx28_spl_data *) |
| 283 | ((CONFIG_SYS_TEXT_BASE - sizeof(struct mx28_spl_data)) & ~0xf); |
Fabio Estevam | 5bcc6a8 | 2011-12-20 05:46:33 +0000 | [diff] [blame] | 284 | |
Marek Vasut | 0239c2f | 2012-05-01 11:09:44 +0000 | [diff] [blame^] | 285 | if (data->mem_dram_size == 0) { |
Fabio Estevam | 5bcc6a8 | 2011-12-20 05:46:33 +0000 | [diff] [blame] | 286 | printf("MX28:\n" |
Marek Vasut | 0239c2f | 2012-05-01 11:09:44 +0000 | [diff] [blame^] | 287 | "Error, the RAM size passed up from SPL is 0!\n"); |
Fabio Estevam | 5bcc6a8 | 2011-12-20 05:46:33 +0000 | [diff] [blame] | 288 | hang(); |
| 289 | } |
| 290 | |
Marek Vasut | 0239c2f | 2012-05-01 11:09:44 +0000 | [diff] [blame^] | 291 | gd->ram_size = data->mem_dram_size; |
Fabio Estevam | 5bcc6a8 | 2011-12-20 05:46:33 +0000 | [diff] [blame] | 292 | return 0; |
| 293 | } |
| 294 | |
Marek Vasut | 6e9a0a3 | 2011-11-08 23:18:08 +0000 | [diff] [blame] | 295 | U_BOOT_CMD( |
| 296 | clocks, CONFIG_SYS_MAXARGS, 1, do_mx28_showclocks, |
| 297 | "display clocks", |
| 298 | "" |
| 299 | ); |