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