]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - arch/arm/cpu/armv7/mx5/soc.c
TX6 Release 2013-04-22
[karo-tx-uboot.git] / arch / arm / cpu / armv7 / mx5 / soc.c
1 /*
2  * (C) Copyright 2007
3  * Sascha Hauer, Pengutronix
4  *
5  * (C) Copyright 2009 Freescale Semiconductor, Inc.
6  *
7  * See file CREDITS for list of people who contributed to this
8  * project.
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License as
12  * published by the Free Software Foundation; either version 2 of
13  * the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
23  * MA 02111-1307 USA
24  */
25
26 #include <common.h>
27 #include <asm/arch/imx-regs.h>
28 #include <asm/arch/clock.h>
29 #include <asm/arch/sys_proto.h>
30
31 #include <asm/errno.h>
32 #include <asm/io.h>
33 #include <asm/imx-common/boot_mode.h>
34
35 #if !(defined(CONFIG_MX51) || defined(CONFIG_MX53))
36 #error "CPU_TYPE not defined"
37 #endif
38
39 #ifdef CONFIG_HW_WATCHDOG
40 #define wdog_base       ((void *)WDOG1_BASE_ADDR)
41 #define WDOG_WCR        0x00
42 #define WCR_WDE         (1 << 2)
43 #define WDOG_WSR        0x02
44
45 void hw_watchdog_reset(void)
46 {
47         if (readw(wdog_base + WDOG_WCR) & WCR_WDE) {
48                 static u16 toggle = 0xaaaa;
49
50                 writew(toggle, wdog_base + WDOG_WSR);
51                 toggle ^= 0xffff;
52         }
53 }
54 #endif
55
56 u32 get_cpu_rev(void)
57 {
58 #ifdef CONFIG_MX51
59         int system_rev = 0x51000;
60 #else
61         int system_rev = 0x53000;
62 #endif
63         int reg = __raw_readl(ROM_SI_REV);
64
65 #if defined(CONFIG_MX51)
66         switch (reg) {
67         case 0x02:
68                 system_rev |= CHIP_REV_1_1;
69                 break;
70         case 0x10:
71                 if ((__raw_readl(GPIO1_BASE_ADDR + 0x0) & (0x1 << 22)) == 0)
72                         system_rev |= CHIP_REV_2_5;
73                 else
74                         system_rev |= CHIP_REV_2_0;
75                 break;
76         case 0x20:
77                 system_rev |= CHIP_REV_3_0;
78                 break;
79         default:
80                 system_rev |= CHIP_REV_1_0;
81                 break;
82         }
83 #else
84         if (reg < 0x20)
85                 system_rev |= CHIP_REV_1_0;
86         else
87                 system_rev |= reg;
88 #endif
89         return system_rev;
90 }
91
92 #ifndef CONFIG_SYS_DCACHE_OFF
93 void enable_caches(void)
94 {
95         /* Enable D-cache. I-cache is already enabled in start.S */
96         dcache_enable();
97 }
98 #endif
99
100 #if defined(CONFIG_FEC_MXC)
101 static void __imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
102 {
103         int i;
104         struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
105         struct fuse_bank *bank = &iim->bank[1];
106         struct fuse_bank1_regs *fuse =
107                         (struct fuse_bank1_regs *)bank->fuse_regs;
108
109         for (i = 0; i < 6; i++)
110                 mac[i] = readl(&fuse->mac_addr[i]) & 0xff;
111 }
112
113 void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
114         __attribute__((weak, alias("__imx_get_mac_from_fuse")));
115
116 #endif
117
118 void set_chipselect_size(int const cs_size)
119 {
120         unsigned int reg;
121         struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
122         reg = readl(&iomuxc_regs->gpr1);
123
124         switch (cs_size) {
125         case CS0_128:
126                 reg &= ~0x7;    /* CS0=128MB, CS1=0, CS2=0, CS3=0 */
127                 reg |= 0x5;
128                 break;
129         case CS0_64M_CS1_64M:
130                 reg &= ~0x3F;   /* CS0=64MB, CS1=64MB, CS2=0, CS3=0 */
131                 reg |= 0x1B;
132                 break;
133         case CS0_64M_CS1_32M_CS2_32M:
134                 reg &= ~0x1FF;  /* CS0=64MB, CS1=32MB, CS2=32MB, CS3=0 */
135                 reg |= 0x4B;
136                 break;
137         case CS0_32M_CS1_32M_CS2_32M_CS3_32M:
138                 reg &= ~0xFFF;  /* CS0=32MB, CS1=32MB, CS2=32MB, CS3=32MB */
139                 reg |= 0x249;
140                 break;
141         default:
142                 printf("Unknown chip select size: %d\n", cs_size);
143                 break;
144         }
145
146         writel(reg, &iomuxc_regs->gpr1);
147 }
148
149 #ifdef CONFIG_MX53
150 void boot_mode_apply(unsigned cfg_val)
151 {
152         writel(cfg_val, &((struct srtc_regs *)SRTC_BASE_ADDR)->lpgr);
153 }
154 /*
155  * cfg_val will be used for
156  * Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
157  *
158  * If bit 28 of LPGR is set upon watchdog reset,
159  * bits[25:0] of LPGR will move to SBMR.
160  */
161 const struct boot_mode soc_boot_modes[] = {
162         {"normal",      MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)},
163         /* usb or serial download */
164         {"usb",         MAKE_CFGVAL(0x00, 0x00, 0x00, 0x13)},
165         {"sata",        MAKE_CFGVAL(0x28, 0x00, 0x00, 0x12)},
166         {"escpi1:0",    MAKE_CFGVAL(0x38, 0x20, 0x00, 0x12)},
167         {"escpi1:1",    MAKE_CFGVAL(0x38, 0x20, 0x04, 0x12)},
168         {"escpi1:2",    MAKE_CFGVAL(0x38, 0x20, 0x08, 0x12)},
169         {"escpi1:3",    MAKE_CFGVAL(0x38, 0x20, 0x0c, 0x12)},
170         /* 4 bit bus width */
171         {"esdhc1",      MAKE_CFGVAL(0x40, 0x20, 0x00, 0x12)},
172         {"esdhc2",      MAKE_CFGVAL(0x40, 0x20, 0x08, 0x12)},
173         {"esdhc3",      MAKE_CFGVAL(0x40, 0x20, 0x10, 0x12)},
174         {"esdhc4",      MAKE_CFGVAL(0x40, 0x20, 0x18, 0x12)},
175         {NULL,          0},
176 };
177 #endif