blob: 3d50a5d8ee9a39dbe911f711272950a06b4ccd4d [file] [log] [blame]
Stefano Babica521a772010-01-20 18:19:32 +01001/*
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>
Stefano Babicac41d4d2010-03-05 17:54:37 +010028#include <asm/arch/clock.h>
Fabio Estevamf231efb2011-10-13 05:34:59 +000029#include <asm/arch/sys_proto.h>
30
Stefano Babica521a772010-01-20 18:19:32 +010031#include <asm/errno.h>
32#include <asm/io.h>
Troy Kisky0ca618c2012-08-15 10:31:20 +000033#include <asm/imx-common/boot_mode.h>
Stefano Babica521a772010-01-20 18:19:32 +010034
Liu Hui-R64343baa2d782011-01-03 22:27:35 +000035#if !(defined(CONFIG_MX51) || defined(CONFIG_MX53))
Jason Liue7a7ed22010-10-18 11:09:26 +080036#error "CPU_TYPE not defined"
37#endif
38
Stefano Babica521a772010-01-20 18:19:32 +010039u32 get_cpu_rev(void)
40{
Liu Hui-R64343baa2d782011-01-03 22:27:35 +000041#ifdef CONFIG_MX51
42 int system_rev = 0x51000;
43#else
44 int system_rev = 0x53000;
45#endif
Jason Liue7a7ed22010-10-18 11:09:26 +080046 int reg = __raw_readl(ROM_SI_REV);
Stefano Babica521a772010-01-20 18:19:32 +010047
Liu Hui-R64343baa2d782011-01-03 22:27:35 +000048#if defined(CONFIG_MX51)
Stefano Babica521a772010-01-20 18:19:32 +010049 switch (reg) {
50 case 0x02:
Jason Liue7a7ed22010-10-18 11:09:26 +080051 system_rev |= CHIP_REV_1_1;
Stefano Babica521a772010-01-20 18:19:32 +010052 break;
53 case 0x10:
54 if ((__raw_readl(GPIO1_BASE_ADDR + 0x0) & (0x1 << 22)) == 0)
Jason Liue7a7ed22010-10-18 11:09:26 +080055 system_rev |= CHIP_REV_2_5;
Stefano Babica521a772010-01-20 18:19:32 +010056 else
Jason Liue7a7ed22010-10-18 11:09:26 +080057 system_rev |= CHIP_REV_2_0;
Stefano Babica521a772010-01-20 18:19:32 +010058 break;
59 case 0x20:
Jason Liue7a7ed22010-10-18 11:09:26 +080060 system_rev |= CHIP_REV_3_0;
Stefano Babica521a772010-01-20 18:19:32 +010061 break;
Liu Hui-R64343baa2d782011-01-03 22:27:35 +000062 default:
63 system_rev |= CHIP_REV_1_0;
64 break;
65 }
66#else
Fabio Estevam000f4d02011-04-26 10:50:15 +000067 if (reg < 0x20)
Jason Liue7a7ed22010-10-18 11:09:26 +080068 system_rev |= CHIP_REV_1_0;
Fabio Estevam000f4d02011-04-26 10:50:15 +000069 else
70 system_rev |= reg;
Liu Hui-R64343baa2d782011-01-03 22:27:35 +000071#endif
Stefano Babica521a772010-01-20 18:19:32 +010072 return system_rev;
73}
74
Fabio Estevame993b0d2013-04-24 14:44:25 +000075#ifdef CONFIG_REVISION_TAG
76u32 __weak get_board_rev(void)
77{
78 return get_cpu_rev();
79}
80#endif
81
Benoît Thébaudeaub8aaed32012-08-14 03:17:52 +000082#ifndef CONFIG_SYS_DCACHE_OFF
83void enable_caches(void)
84{
85 /* Enable D-cache. I-cache is already enabled in start.S */
86 dcache_enable();
87}
88#endif
89
Stefano Babica521a772010-01-20 18:19:32 +010090#if defined(CONFIG_FEC_MXC)
Jason Liuce0e55e2012-01-31 02:07:29 +000091void imx_get_mac_from_fuse(int dev_id, unsigned char *mac)
Liu Hui-R643434df66192010-11-18 23:45:55 +000092{
93 int i;
94 struct iim_regs *iim = (struct iim_regs *)IMX_IIM_BASE;
95 struct fuse_bank *bank = &iim->bank[1];
96 struct fuse_bank1_regs *fuse =
97 (struct fuse_bank1_regs *)bank->fuse_regs;
98
99 for (i = 0; i < 6; i++)
100 mac[i] = readl(&fuse->mac_addr[i]) & 0xff;
101}
102#endif
Stefano Babica521a772010-01-20 18:19:32 +0100103
Fabio Estevam88a22a22011-06-07 07:02:52 +0000104void set_chipselect_size(int const cs_size)
105{
106 unsigned int reg;
107 struct iomuxc *iomuxc_regs = (struct iomuxc *)IOMUXC_BASE_ADDR;
108 reg = readl(&iomuxc_regs->gpr1);
109
110 switch (cs_size) {
111 case CS0_128:
112 reg &= ~0x7; /* CS0=128MB, CS1=0, CS2=0, CS3=0 */
113 reg |= 0x5;
114 break;
115 case CS0_64M_CS1_64M:
116 reg &= ~0x3F; /* CS0=64MB, CS1=64MB, CS2=0, CS3=0 */
117 reg |= 0x1B;
118 break;
119 case CS0_64M_CS1_32M_CS2_32M:
120 reg &= ~0x1FF; /* CS0=64MB, CS1=32MB, CS2=32MB, CS3=0 */
121 reg |= 0x4B;
122 break;
123 case CS0_32M_CS1_32M_CS2_32M_CS3_32M:
124 reg &= ~0xFFF; /* CS0=32MB, CS1=32MB, CS2=32MB, CS3=32MB */
125 reg |= 0x249;
126 break;
127 default:
128 printf("Unknown chip select size: %d\n", cs_size);
129 break;
130 }
131
132 writel(reg, &iomuxc_regs->gpr1);
133}
Troy Kisky0ca618c2012-08-15 10:31:20 +0000134
135#ifdef CONFIG_MX53
136void boot_mode_apply(unsigned cfg_val)
137{
138 writel(cfg_val, &((struct srtc_regs *)SRTC_BASE_ADDR)->lpgr);
139}
140/*
141 * cfg_val will be used for
142 * Boot_cfg3[7:0]:Boot_cfg2[7:0]:Boot_cfg1[7:0]
143 *
144 * If bit 28 of LPGR is set upon watchdog reset,
145 * bits[25:0] of LPGR will move to SBMR.
146 */
147const struct boot_mode soc_boot_modes[] = {
148 {"normal", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x00)},
149 /* usb or serial download */
150 {"usb", MAKE_CFGVAL(0x00, 0x00, 0x00, 0x13)},
151 {"sata", MAKE_CFGVAL(0x28, 0x00, 0x00, 0x12)},
152 {"escpi1:0", MAKE_CFGVAL(0x38, 0x20, 0x00, 0x12)},
153 {"escpi1:1", MAKE_CFGVAL(0x38, 0x20, 0x04, 0x12)},
154 {"escpi1:2", MAKE_CFGVAL(0x38, 0x20, 0x08, 0x12)},
155 {"escpi1:3", MAKE_CFGVAL(0x38, 0x20, 0x0c, 0x12)},
156 /* 4 bit bus width */
157 {"esdhc1", MAKE_CFGVAL(0x40, 0x20, 0x00, 0x12)},
158 {"esdhc2", MAKE_CFGVAL(0x40, 0x20, 0x08, 0x12)},
159 {"esdhc3", MAKE_CFGVAL(0x40, 0x20, 0x10, 0x12)},
160 {"esdhc4", MAKE_CFGVAL(0x40, 0x20, 0x18, 0x12)},
161 {NULL, 0},
162};
163#endif