Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 1 | /* |
| 2 | * (C) Copyright 2007 |
| 3 | * Sascha Hauer, Pengutronix |
| 4 | * |
| 5 | * (C) Copyright 2009 Freescale Semiconductor, Inc. |
| 6 | * |
Wolfgang Denk | d79de1d | 2013-07-08 09:37:19 +0200 | [diff] [blame] | 7 | * SPDX-License-Identifier: GPL-2.0+ |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 8 | */ |
| 9 | |
| 10 | #include <common.h> |
| 11 | #include <asm/arch/imx-regs.h> |
Stefano Babic | ac41d4d | 2010-03-05 17:54:37 +0100 | [diff] [blame] | 12 | #include <asm/arch/clock.h> |
Fabio Estevam | f231efb | 2011-10-13 05:34:59 +0000 | [diff] [blame] | 13 | #include <asm/arch/sys_proto.h> |
| 14 | |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 15 | #include <asm/errno.h> |
| 16 | #include <asm/io.h> |
Troy Kisky | 0ca618c | 2012-08-15 10:31:20 +0000 | [diff] [blame] | 17 | #include <asm/imx-common/boot_mode.h> |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 18 | |
Liu Hui-R64343 | baa2d78 | 2011-01-03 22:27:35 +0000 | [diff] [blame] | 19 | #if !(defined(CONFIG_MX51) || defined(CONFIG_MX53)) |
Jason Liu | e7a7ed2 | 2010-10-18 11:09:26 +0800 | [diff] [blame] | 20 | #error "CPU_TYPE not defined" |
| 21 | #endif |
| 22 | |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 23 | u32 get_cpu_rev(void) |
| 24 | { |
Liu Hui-R64343 | baa2d78 | 2011-01-03 22:27:35 +0000 | [diff] [blame] | 25 | #ifdef CONFIG_MX51 |
| 26 | int system_rev = 0x51000; |
| 27 | #else |
| 28 | int system_rev = 0x53000; |
| 29 | #endif |
Jason Liu | e7a7ed2 | 2010-10-18 11:09:26 +0800 | [diff] [blame] | 30 | int reg = __raw_readl(ROM_SI_REV); |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 31 | |
Liu Hui-R64343 | baa2d78 | 2011-01-03 22:27:35 +0000 | [diff] [blame] | 32 | #if defined(CONFIG_MX51) |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 33 | switch (reg) { |
| 34 | case 0x02: |
Jason Liu | e7a7ed2 | 2010-10-18 11:09:26 +0800 | [diff] [blame] | 35 | system_rev |= CHIP_REV_1_1; |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 36 | break; |
| 37 | case 0x10: |
| 38 | if ((__raw_readl(GPIO1_BASE_ADDR + 0x0) & (0x1 << 22)) == 0) |
Jason Liu | e7a7ed2 | 2010-10-18 11:09:26 +0800 | [diff] [blame] | 39 | system_rev |= CHIP_REV_2_5; |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 40 | else |
Jason Liu | e7a7ed2 | 2010-10-18 11:09:26 +0800 | [diff] [blame] | 41 | system_rev |= CHIP_REV_2_0; |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 42 | break; |
| 43 | case 0x20: |
Jason Liu | e7a7ed2 | 2010-10-18 11:09:26 +0800 | [diff] [blame] | 44 | system_rev |= CHIP_REV_3_0; |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 45 | break; |
Liu Hui-R64343 | baa2d78 | 2011-01-03 22:27:35 +0000 | [diff] [blame] | 46 | default: |
| 47 | system_rev |= CHIP_REV_1_0; |
| 48 | break; |
| 49 | } |
| 50 | #else |
Fabio Estevam | 000f4d0 | 2011-04-26 10:50:15 +0000 | [diff] [blame] | 51 | if (reg < 0x20) |
Jason Liu | e7a7ed2 | 2010-10-18 11:09:26 +0800 | [diff] [blame] | 52 | system_rev |= CHIP_REV_1_0; |
Fabio Estevam | 000f4d0 | 2011-04-26 10:50:15 +0000 | [diff] [blame] | 53 | else |
| 54 | system_rev |= reg; |
Liu Hui-R64343 | baa2d78 | 2011-01-03 22:27:35 +0000 | [diff] [blame] | 55 | #endif |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 56 | return system_rev; |
| 57 | } |
| 58 | |
Fabio Estevam | e993b0d | 2013-04-24 14:44:25 +0000 | [diff] [blame] | 59 | #ifdef CONFIG_REVISION_TAG |
| 60 | u32 __weak get_board_rev(void) |
| 61 | { |
| 62 | return get_cpu_rev(); |
| 63 | } |
| 64 | #endif |
| 65 | |
Benoît Thébaudeau | b8aaed3 | 2012-08-14 03:17:52 +0000 | [diff] [blame] | 66 | #ifndef CONFIG_SYS_DCACHE_OFF |
| 67 | void enable_caches(void) |
| 68 | { |
| 69 | /* Enable D-cache. I-cache is already enabled in start.S */ |
| 70 | dcache_enable(); |
| 71 | } |
| 72 | #endif |
| 73 | |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 74 | #if defined(CONFIG_FEC_MXC) |
Jason Liu | ce0e55e | 2012-01-31 02:07:29 +0000 | [diff] [blame] | 75 | void imx_get_mac_from_fuse(int dev_id, unsigned char *mac) |
Liu Hui-R64343 | 4df6619 | 2010-11-18 23:45:55 +0000 | [diff] [blame] | 76 | { |
| 77 | int i; |
| 78 | struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE; |
| 79 | struct fuse_bank *bank = &iim->bank[1]; |
| 80 | struct fuse_bank1_regs *fuse = |
| 81 | (struct fuse_bank1_regs *)bank->fuse_regs; |
| 82 | |
| 83 | for (i = 0; i < 6; i++) |
| 84 | mac[i] = readl(&fuse->mac_addr[i]) & 0xff; |
| 85 | } |
| 86 | #endif |
Stefano Babic | a521a77 | 2010-01-20 18:19:32 +0100 | [diff] [blame] | 87 | |
Fabio Estevam | 88a22a2 | 2011-06-07 07:02:52 +0000 | [diff] [blame] | 88 | void set_chipselect_size(int const cs_size) |
| 89 | { |
| 90 | unsigned int reg; |
| 91 | struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR; |
| 92 | reg = readl(&iomuxc_regs->gpr1); |
| 93 | |
| 94 | switch (cs_size) { |
| 95 | case CS0_128: |
| 96 | reg &= ~0x7; /* CS0=128MB, CS1=0, CS2=0, CS3=0 */ |
| 97 | reg |= 0x5; |
| 98 | break; |
| 99 | case CS0_64M_CS1_64M: |
| 100 | reg &= ~0x3F; /* CS0=64MB, CS1=64MB, CS2=0, CS3=0 */ |
| 101 | reg |= 0x1B; |
| 102 | break; |
| 103 | case CS0_64M_CS1_32M_CS2_32M: |
| 104 | reg &= ~0x1FF; /* CS0=64MB, CS1=32MB, CS2=32MB, CS3=0 */ |
| 105 | reg |= 0x4B; |
| 106 | break; |
| 107 | case CS0_32M_CS1_32M_CS2_32M_CS3_32M: |
| 108 | reg &= ~0xFFF; /* CS0=32MB, CS1=32MB, CS2=32MB, CS3=32MB */ |
| 109 | reg |= 0x249; |
| 110 | break; |
| 111 | default: |
| 112 | printf("Unknown chip select size: %d\n", cs_size); |
| 113 | break; |
| 114 | } |
| 115 | |
| 116 | writel(reg, &iomuxc_regs->gpr1); |
| 117 | } |
Troy Kisky | 0ca618c | 2012-08-15 10:31:20 +0000 | [diff] [blame] | 118 | |
| 119 | #ifdef CONFIG_MX53 |
| 120 | void boot_mode_apply(unsigned cfg_val) |
| 121 | { |
| 122 | writel(cfg_val, &((struct srtc_regs *)SRTC_BASE_ADDR)->lpgr); |
| 123 | } |
| 124 | /* |
| 125 | * cfg_val will be used for |
| 126 | * Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0] |
| 127 | * |
| 128 | * If bit 28 of LPGR is set upon watchdog reset, |
| 129 | * bits[25:0] of LPGR will move to SBMR. |
| 130 | */ |
| 131 | const struct boot_mode soc_boot_modes[] = { |
| 132 | {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)}, |
| 133 | /* usb or serial download */ |
| 134 | {"usb", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x13)}, |
| 135 | {"sata", MAKE_CFGVAL(0x28, 0x00, 0x00, 0x12)}, |
| 136 | {"escpi1:0", MAKE_CFGVAL(0x38, 0x20, 0x00, 0x12)}, |
| 137 | {"escpi1:1", MAKE_CFGVAL(0x38, 0x20, 0x04, 0x12)}, |
| 138 | {"escpi1:2", MAKE_CFGVAL(0x38, 0x20, 0x08, 0x12)}, |
| 139 | {"escpi1:3", MAKE_CFGVAL(0x38, 0x20, 0x0c, 0x12)}, |
| 140 | /* 4 bit bus width */ |
| 141 | {"esdhc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x12)}, |
| 142 | {"esdhc2", MAKE_CFGVAL(0x40, 0x20, 0x08, 0x12)}, |
| 143 | {"esdhc3", MAKE_CFGVAL(0x40, 0x20, 0x10, 0x12)}, |
| 144 | {"esdhc4", MAKE_CFGVAL(0x40, 0x20, 0x18, 0x12)}, |
| 145 | {NULL, 0}, |
| 146 | }; |
| 147 | #endif |