2 * Copyright (C) 2010 Albert ARIBAUD <albert.u.boot@aribaud.net>
4 * Based on original Kirkwood support which is
6 * Marvell Semiconductor <www.marvell.com>
7 * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
9 * See file CREDITS for list of people who contributed to this
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License as
14 * published by the Free Software Foundation; either version 2 of
15 * the License, or (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
30 #include <asm/cache.h>
32 #include <u-boot/md5.h>
33 #include <asm/arch/cpu.h>
38 void reset_cpu(unsigned long ignored)
40 struct orion5x_cpu_registers *cpureg =
41 (struct orion5x_cpu_registers *)ORION5X_CPU_REG_BASE;
43 writel(readl(&cpureg->rstoutn_mask) | (1 << 2),
44 &cpureg->rstoutn_mask);
45 writel(readl(&cpureg->sys_soft_rst) | 1,
46 &cpureg->sys_soft_rst);
52 * Compute Window Size field value from size expressed in bytes
53 * Used with the Base register to set the address window size and location.
54 * Must be programmed from LSB to MSB as sequence of ones followed by
55 * sequence of zeros. The number of ones specifies the size of the window in
56 * 64 KiB granularity (e.g., a value of 0x00FF specifies 256 = 16 MiB).
58 * 1) A sizeval equal to 0x0 specifies 4 GiB.
59 * 2) A return value of 0x0 specifies 64 KiB.
61 unsigned int orion5x_winctrl_calcsize(unsigned int sizeval)
64 * Calculate the number of 64 KiB blocks needed minus one (rounding up).
65 * For sizeval > 0 this is equivalent to:
66 * sizeval = (u32) ceil((double) sizeval / 65536.0) - 1
68 sizeval = (sizeval - 1) >> 16;
71 * Propagate 'one' bits to the right by 'oring' them.
72 * We need only treat bits 15-0.
74 sizeval |= sizeval >> 1; /* 'Or' bit 15 onto bit 14 */
75 sizeval |= sizeval >> 2; /* 'Or' bits 15-14 onto bits 13-12 */
76 sizeval |= sizeval >> 4; /* 'Or' bits 15-12 onto bits 11-8 */
77 sizeval |= sizeval >> 8; /* 'Or' bits 15-8 onto bits 7-0*/
83 * orion5x_config_adr_windows - Configure address Windows
85 * There are 8 address windows supported by Orion5x Soc to addess different
86 * devices. Each window can be configured for size, BAR and remap addr
87 * Below configuration is standard for most of the cases
89 * If remap function not used, remap_lo must be set as base
93 * 1) in order to avoid windows with inconsistent control and base values
94 * (which could prevent access to BOOTCS and hence execution from FLASH)
95 * always disable window before writing the base value then reenable it
96 * by writing the control value.
98 * 2) in order to avoid losing access to BOOTCS when disabling window 7,
99 * first configure window 6 for BOOTCS, then configure window 7 for BOOTCS,
100 * then configure windows 6 for its own target.
102 * Reference Documentation:
103 * Mbus-L to Mbus Bridge Registers Configuration.
104 * (Sec 25.1 and 25.3 of Datasheet)
106 int orion5x_config_adr_windows(void)
108 struct orion5x_win_registers *winregs =
109 (struct orion5x_win_registers *)ORION5X_CPU_WIN_BASE;
111 /* Disable window 0, configure it for its intended target, enable it. */
112 writel(0, &winregs[0].ctrl);
113 writel(ORION5X_ADR_PCIE_MEM, &winregs[0].base);
114 writel(ORION5X_ADR_PCIE_MEM_REMAP_LO, &winregs[0].remap_lo);
115 writel(ORION5X_ADR_PCIE_MEM_REMAP_HI, &winregs[0].remap_hi);
116 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCIE_MEM,
117 ORION5X_TARGET_PCIE, ORION5X_ATTR_PCIE_MEM,
118 ORION5X_WIN_ENABLE), &winregs[0].ctrl);
119 /* Disable window 1, configure it for its intended target, enable it. */
120 writel(0, &winregs[1].ctrl);
121 writel(ORION5X_ADR_PCIE_IO, &winregs[1].base);
122 writel(ORION5X_ADR_PCIE_IO_REMAP_LO, &winregs[1].remap_lo);
123 writel(ORION5X_ADR_PCIE_IO_REMAP_HI, &winregs[1].remap_hi);
124 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCIE_IO,
125 ORION5X_TARGET_PCIE, ORION5X_ATTR_PCIE_IO,
126 ORION5X_WIN_ENABLE), &winregs[1].ctrl);
127 /* Disable window 2, configure it for its intended target, enable it. */
128 writel(0, &winregs[2].ctrl);
129 writel(ORION5X_ADR_PCI_MEM, &winregs[2].base);
130 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCI_MEM,
131 ORION5X_TARGET_PCI, ORION5X_ATTR_PCI_MEM,
132 ORION5X_WIN_ENABLE), &winregs[2].ctrl);
133 /* Disable window 3, configure it for its intended target, enable it. */
134 writel(0, &winregs[3].ctrl);
135 writel(ORION5X_ADR_PCI_IO, &winregs[3].base);
136 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCI_IO,
137 ORION5X_TARGET_PCI, ORION5X_ATTR_PCI_IO,
138 ORION5X_WIN_ENABLE), &winregs[3].ctrl);
139 /* Disable window 4, configure it for its intended target, enable it. */
140 writel(0, &winregs[4].ctrl);
141 writel(ORION5X_ADR_DEV_CS0, &winregs[4].base);
142 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_DEV_CS0,
143 ORION5X_TARGET_DEVICE, ORION5X_ATTR_DEV_CS0,
144 ORION5X_WIN_ENABLE), &winregs[4].ctrl);
145 /* Disable window 5, configure it for its intended target, enable it. */
146 writel(0, &winregs[5].ctrl);
147 writel(ORION5X_ADR_DEV_CS1, &winregs[5].base);
148 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_DEV_CS1,
149 ORION5X_TARGET_DEVICE, ORION5X_ATTR_DEV_CS1,
150 ORION5X_WIN_ENABLE), &winregs[5].ctrl);
151 /* Disable window 6, configure it for FLASH, enable it. */
152 writel(0, &winregs[6].ctrl);
153 writel(ORION5X_ADR_BOOTROM, &winregs[6].base);
154 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_BOOTROM,
155 ORION5X_TARGET_DEVICE, ORION5X_ATTR_BOOTROM,
156 ORION5X_WIN_ENABLE), &winregs[6].ctrl);
157 /* Disable window 7, configure it for FLASH, enable it. */
158 writel(0, &winregs[7].ctrl);
159 writel(ORION5X_ADR_BOOTROM, &winregs[7].base);
160 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_BOOTROM,
161 ORION5X_TARGET_DEVICE, ORION5X_ATTR_BOOTROM,
162 ORION5X_WIN_ENABLE), &winregs[7].ctrl);
163 /* Disable window 6, configure it for its intended target, enable it. */
164 writel(0, &winregs[6].ctrl);
165 writel(ORION5X_ADR_DEV_CS2, &winregs[6].base);
166 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_DEV_CS2,
167 ORION5X_TARGET_DEVICE, ORION5X_ATTR_DEV_CS2,
168 ORION5X_WIN_ENABLE), &winregs[6].ctrl);
174 * Orion5x identification is done through PCIE space.
177 u32 orion5x_device_id(void)
179 return readl(PCIE_DEV_ID_OFF) >> 16;
182 u32 orion5x_device_rev(void)
184 return readl(PCIE_DEV_REV_OFF) & 0xff;
187 #if defined(CONFIG_DISPLAY_CPUINFO)
189 /* Display device and revision IDs.
190 * This function must cover all known device/revision
191 * combinations, not only the one for which u-boot is
192 * compiled; this way, one can identify actual HW in
193 * case of a mismatch.
195 int print_cpuinfo(void)
197 char dev_str[] = "0x0000";
198 char rev_str[] = "0x00";
199 char *dev_name = NULL;
200 char *rev_name = NULL;
202 u32 dev = orion5x_device_id();
203 u32 rev = orion5x_device_rev();
205 if (dev == MV88F5181_DEV_ID) {
206 dev_name = "MV88F5181";
207 if (rev == MV88F5181_REV_B1)
209 else if (rev == MV88F5181L_REV_A1) {
210 dev_name = "MV88F5181L";
212 } else if (rev == MV88F5181L_REV_A0) {
213 dev_name = "MV88F5181L";
216 } else if (dev == MV88F5182_DEV_ID) {
217 dev_name = "MV88F5182";
218 if (rev == MV88F5182_REV_A2)
220 } else if (dev == MV88F5281_DEV_ID) {
221 dev_name = "MV88F5281";
222 if (rev == MV88F5281_REV_D2)
224 else if (rev == MV88F5281_REV_D1)
226 else if (rev == MV88F5281_REV_D0)
228 } else if (dev == MV88F6183_DEV_ID) {
229 dev_name = "MV88F6183";
230 if (rev == MV88F6183_REV_B0)
233 if (dev_name == NULL) {
234 sprintf(dev_str, "0x%04x", dev);
237 if (rev_name == NULL) {
238 sprintf(rev_str, "0x%02x", rev);
242 printf("SoC: Orion5x %s-%s\n", dev_name, rev_name);
246 #endif /* CONFIG_DISPLAY_CPUINFO */
248 #ifdef CONFIG_ARCH_CPU_INIT
249 int arch_cpu_init(void)
251 /* Enable and invalidate L2 cache in write through mode */
252 invalidate_l2_cache();
254 orion5x_config_adr_windows();
258 #endif /* CONFIG_ARCH_CPU_INIT */
261 * SOC specific misc init
263 #if defined(CONFIG_ARCH_MISC_INIT)
264 int arch_misc_init(void)
268 /*CPU streaming & write allocate */
269 temp = readfr_extra_feature_reg();
270 temp &= ~(1 << 28); /* disable wr alloc */
271 writefr_extra_feature_reg(temp);
273 temp = readfr_extra_feature_reg();
274 temp &= ~(1 << 29); /* streaming disabled */
275 writefr_extra_feature_reg(temp);
277 /* L2Cache settings */
278 temp = readfr_extra_feature_reg();
279 /* Disable L2C pre fetch - Set bit 24 */
281 /* enable L2C - Set bit 22 */
283 writefr_extra_feature_reg(temp);
286 /* Change reset vector to address 0x0 */
288 set_cr(temp & ~CR_V);
290 /* Set CPIOs and MPPs - values provided by board
292 writel(ORION5X_MPP0_7, ORION5X_MPP_BASE+0x00);
293 writel(ORION5X_MPP8_15, ORION5X_MPP_BASE+0x04);
294 writel(ORION5X_MPP16_23, ORION5X_MPP_BASE+0x50);
295 writel(ORION5X_GPIO_OUT_ENABLE, ORION5X_GPIO_BASE+0x04);
297 /* initialize timer */
301 #endif /* CONFIG_ARCH_MISC_INIT */
304 int cpu_eth_init(bd_t *bis)
306 mvgbe_initialize(bis);