blob: 79b5f4f34f46aaaa47107b9714149ad5be15ccb7 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Albert Aribaudac2ba9e2010-06-17 19:36:07 +05302/*
Albert ARIBAUD340983d2011-04-22 19:41:02 +02003 * Copyright (C) 2010 Albert ARIBAUD <albert.u.boot@aribaud.net>
Albert Aribaudac2ba9e2010-06-17 19:36:07 +05304 *
5 * Based on original Kirkwood support which is
6 * (C) Copyright 2009
7 * Marvell Semiconductor <www.marvell.com>
8 * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
Albert Aribaudac2ba9e2010-06-17 19:36:07 +05309 */
10
11#include <common.h>
12#include <netdev.h>
13#include <asm/cache.h>
Lei Wen749941a2011-10-24 16:27:32 +000014#include <asm/io.h>
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053015#include <u-boot/md5.h>
Lei Wen749941a2011-10-24 16:27:32 +000016#include <asm/arch/cpu.h>
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053017
18#define BUFLEN 16
19
20void reset_cpu(unsigned long ignored)
21{
22 struct orion5x_cpu_registers *cpureg =
23 (struct orion5x_cpu_registers *)ORION5X_CPU_REG_BASE;
24
25 writel(readl(&cpureg->rstoutn_mask) | (1 << 2),
26 &cpureg->rstoutn_mask);
27 writel(readl(&cpureg->sys_soft_rst) | 1,
28 &cpureg->sys_soft_rst);
29 while (1)
30 ;
31}
32
33/*
Albert Aribaud787aba32010-10-07 20:19:53 +053034 * Compute Window Size field value from size expressed in bytes
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053035 * Used with the Base register to set the address window size and location.
36 * Must be programmed from LSB to MSB as sequence of ones followed by
37 * sequence of zeros. The number of ones specifies the size of the window in
Albert Aribaud787aba32010-10-07 20:19:53 +053038 * 64 KiB granularity (e.g., a value of 0x00FF specifies 256 = 16 MiB).
39 * NOTES:
40 * 1) A sizeval equal to 0x0 specifies 4 GiB.
41 * 2) A return value of 0x0 specifies 64 KiB.
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053042 */
43unsigned int orion5x_winctrl_calcsize(unsigned int sizeval)
44{
Albert Aribaud787aba32010-10-07 20:19:53 +053045 /*
46 * Calculate the number of 64 KiB blocks needed minus one (rounding up).
47 * For sizeval > 0 this is equivalent to:
48 * sizeval = (u32) ceil((double) sizeval / 65536.0) - 1
49 */
50 sizeval = (sizeval - 1) >> 16;
51
52 /*
53 * Propagate 'one' bits to the right by 'oring' them.
54 * We need only treat bits 15-0.
55 */
56 sizeval |= sizeval >> 1; /* 'Or' bit 15 onto bit 14 */
57 sizeval |= sizeval >> 2; /* 'Or' bits 15-14 onto bits 13-12 */
58 sizeval |= sizeval >> 4; /* 'Or' bits 15-12 onto bits 11-8 */
59 sizeval |= sizeval >> 8; /* 'Or' bits 15-8 onto bits 7-0*/
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053060
Albert Aribaud787aba32010-10-07 20:19:53 +053061 return sizeval;
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053062}
63
64/*
65 * orion5x_config_adr_windows - Configure address Windows
66 *
67 * There are 8 address windows supported by Orion5x Soc to addess different
68 * devices. Each window can be configured for size, BAR and remap addr
69 * Below configuration is standard for most of the cases
70 *
71 * If remap function not used, remap_lo must be set as base
72 *
Albert Aribaudfd5f9732010-09-23 21:49:23 +020073 * NOTES:
74 *
75 * 1) in order to avoid windows with inconsistent control and base values
76 * (which could prevent access to BOOTCS and hence execution from FLASH)
77 * always disable window before writing the base value then reenable it
78 * by writing the control value.
79 *
80 * 2) in order to avoid losing access to BOOTCS when disabling window 7,
81 * first configure window 6 for BOOTCS, then configure window 7 for BOOTCS,
82 * then configure windows 6 for its own target.
83 *
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053084 * Reference Documentation:
85 * Mbus-L to Mbus Bridge Registers Configuration.
86 * (Sec 25.1 and 25.3 of Datasheet)
87 */
88int orion5x_config_adr_windows(void)
89{
90 struct orion5x_win_registers *winregs =
91 (struct orion5x_win_registers *)ORION5X_CPU_WIN_BASE;
92
Albert Aribaudfd5f9732010-09-23 21:49:23 +020093/* Disable window 0, configure it for its intended target, enable it. */
94 writel(0, &winregs[0].ctrl);
Albert Aribaudf4704d02010-07-13 09:04:26 +020095 writel(ORION5X_ADR_PCIE_MEM, &winregs[0].base);
96 writel(ORION5X_ADR_PCIE_MEM_REMAP_LO, &winregs[0].remap_lo);
97 writel(ORION5X_ADR_PCIE_MEM_REMAP_HI, &winregs[0].remap_hi);
Albert Aribaudfd5f9732010-09-23 21:49:23 +020098 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCIE_MEM,
99 ORION5X_TARGET_PCIE, ORION5X_ATTR_PCIE_MEM,
100 ORION5X_WIN_ENABLE), &winregs[0].ctrl);
101/* Disable window 1, configure it for its intended target, enable it. */
102 writel(0, &winregs[1].ctrl);
Albert Aribaudf4704d02010-07-13 09:04:26 +0200103 writel(ORION5X_ADR_PCIE_IO, &winregs[1].base);
104 writel(ORION5X_ADR_PCIE_IO_REMAP_LO, &winregs[1].remap_lo);
105 writel(ORION5X_ADR_PCIE_IO_REMAP_HI, &winregs[1].remap_hi);
Albert Aribaudfd5f9732010-09-23 21:49:23 +0200106 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCIE_IO,
107 ORION5X_TARGET_PCIE, ORION5X_ATTR_PCIE_IO,
108 ORION5X_WIN_ENABLE), &winregs[1].ctrl);
109/* Disable window 2, configure it for its intended target, enable it. */
110 writel(0, &winregs[2].ctrl);
111 writel(ORION5X_ADR_PCI_MEM, &winregs[2].base);
Albert Aribaudf4704d02010-07-13 09:04:26 +0200112 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCI_MEM,
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530113 ORION5X_TARGET_PCI, ORION5X_ATTR_PCI_MEM,
114 ORION5X_WIN_ENABLE), &winregs[2].ctrl);
Albert Aribaudfd5f9732010-09-23 21:49:23 +0200115/* Disable window 3, configure it for its intended target, enable it. */
116 writel(0, &winregs[3].ctrl);
117 writel(ORION5X_ADR_PCI_IO, &winregs[3].base);
Albert Aribaudf4704d02010-07-13 09:04:26 +0200118 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCI_IO,
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530119 ORION5X_TARGET_PCI, ORION5X_ATTR_PCI_IO,
120 ORION5X_WIN_ENABLE), &winregs[3].ctrl);
Albert Aribaudfd5f9732010-09-23 21:49:23 +0200121/* Disable window 4, configure it for its intended target, enable it. */
122 writel(0, &winregs[4].ctrl);
123 writel(ORION5X_ADR_DEV_CS0, &winregs[4].base);
Albert Aribaudf4704d02010-07-13 09:04:26 +0200124 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_DEV_CS0,
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530125 ORION5X_TARGET_DEVICE, ORION5X_ATTR_DEV_CS0,
126 ORION5X_WIN_ENABLE), &winregs[4].ctrl);
Albert Aribaudfd5f9732010-09-23 21:49:23 +0200127/* Disable window 5, configure it for its intended target, enable it. */
128 writel(0, &winregs[5].ctrl);
129 writel(ORION5X_ADR_DEV_CS1, &winregs[5].base);
Albert Aribaudf4704d02010-07-13 09:04:26 +0200130 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_DEV_CS1,
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530131 ORION5X_TARGET_DEVICE, ORION5X_ATTR_DEV_CS1,
132 ORION5X_WIN_ENABLE), &winregs[5].ctrl);
Albert Aribaudfd5f9732010-09-23 21:49:23 +0200133/* Disable window 6, configure it for FLASH, enable it. */
134 writel(0, &winregs[6].ctrl);
135 writel(ORION5X_ADR_BOOTROM, &winregs[6].base);
136 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_BOOTROM,
137 ORION5X_TARGET_DEVICE, ORION5X_ATTR_BOOTROM,
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530138 ORION5X_WIN_ENABLE), &winregs[6].ctrl);
Albert Aribaudfd5f9732010-09-23 21:49:23 +0200139/* Disable window 7, configure it for FLASH, enable it. */
140 writel(0, &winregs[7].ctrl);
141 writel(ORION5X_ADR_BOOTROM, &winregs[7].base);
Albert Aribaudf4704d02010-07-13 09:04:26 +0200142 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_BOOTROM,
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530143 ORION5X_TARGET_DEVICE, ORION5X_ATTR_BOOTROM,
144 ORION5X_WIN_ENABLE), &winregs[7].ctrl);
Albert Aribaudfd5f9732010-09-23 21:49:23 +0200145/* Disable window 6, configure it for its intended target, enable it. */
146 writel(0, &winregs[6].ctrl);
147 writel(ORION5X_ADR_DEV_CS2, &winregs[6].base);
148 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_DEV_CS2,
149 ORION5X_TARGET_DEVICE, ORION5X_ATTR_DEV_CS2,
150 ORION5X_WIN_ENABLE), &winregs[6].ctrl);
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530151
152 return 0;
153}
154
155/*
156 * Orion5x identification is done through PCIE space.
157 */
158
159u32 orion5x_device_id(void)
160{
161 return readl(PCIE_DEV_ID_OFF) >> 16;
162}
163
164u32 orion5x_device_rev(void)
165{
166 return readl(PCIE_DEV_REV_OFF) & 0xff;
167}
168
169#if defined(CONFIG_DISPLAY_CPUINFO)
170
171/* Display device and revision IDs.
172 * This function must cover all known device/revision
173 * combinations, not only the one for which u-boot is
174 * compiled; this way, one can identify actual HW in
175 * case of a mismatch.
176 */
177int print_cpuinfo(void)
178{
Albert ARIBAUDd6d4ec82012-10-09 09:28:15 +0000179 char dev_str[7]; /* room enough for 0x0000 plus null byte */
180 char rev_str[5]; /* room enough for 0x00 plus null byte */
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530181 char *dev_name = NULL;
182 char *rev_name = NULL;
183
184 u32 dev = orion5x_device_id();
185 u32 rev = orion5x_device_rev();
186
187 if (dev == MV88F5181_DEV_ID) {
188 dev_name = "MV88F5181";
189 if (rev == MV88F5181_REV_B1)
190 rev_name = "B1";
191 else if (rev == MV88F5181L_REV_A1) {
192 dev_name = "MV88F5181L";
193 rev_name = "A1";
194 } else if (rev == MV88F5181L_REV_A0) {
195 dev_name = "MV88F5181L";
196 rev_name = "A0";
197 }
198 } else if (dev == MV88F5182_DEV_ID) {
199 dev_name = "MV88F5182";
200 if (rev == MV88F5182_REV_A2)
201 rev_name = "A2";
202 } else if (dev == MV88F5281_DEV_ID) {
203 dev_name = "MV88F5281";
204 if (rev == MV88F5281_REV_D2)
205 rev_name = "D2";
206 else if (rev == MV88F5281_REV_D1)
207 rev_name = "D1";
208 else if (rev == MV88F5281_REV_D0)
209 rev_name = "D0";
210 } else if (dev == MV88F6183_DEV_ID) {
211 dev_name = "MV88F6183";
212 if (rev == MV88F6183_REV_B0)
213 rev_name = "B0";
214 }
215 if (dev_name == NULL) {
216 sprintf(dev_str, "0x%04x", dev);
217 dev_name = dev_str;
218 }
219 if (rev_name == NULL) {
220 sprintf(rev_str, "0x%02x", rev);
221 rev_name = rev_str;
222 }
223
224 printf("SoC: Orion5x %s-%s\n", dev_name, rev_name);
225
226 return 0;
227}
228#endif /* CONFIG_DISPLAY_CPUINFO */
229
230#ifdef CONFIG_ARCH_CPU_INIT
231int arch_cpu_init(void)
232{
233 /* Enable and invalidate L2 cache in write through mode */
234 invalidate_l2_cache();
235
Albert ARIBAUD2ac37922015-01-31 22:55:38 +0100236#ifdef CONFIG_SPL_BUILD
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530237 orion5x_config_adr_windows();
Albert ARIBAUD2ac37922015-01-31 22:55:38 +0100238#endif
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530239
240 return 0;
241}
242#endif /* CONFIG_ARCH_CPU_INIT */
243
244/*
245 * SOC specific misc init
246 */
247#if defined(CONFIG_ARCH_MISC_INIT)
248int arch_misc_init(void)
249{
250 u32 temp;
251
252 /*CPU streaming & write allocate */
253 temp = readfr_extra_feature_reg();
254 temp &= ~(1 << 28); /* disable wr alloc */
255 writefr_extra_feature_reg(temp);
256
257 temp = readfr_extra_feature_reg();
258 temp &= ~(1 << 29); /* streaming disabled */
259 writefr_extra_feature_reg(temp);
260
261 /* L2Cache settings */
262 temp = readfr_extra_feature_reg();
263 /* Disable L2C pre fetch - Set bit 24 */
264 temp |= (1 << 24);
265 /* enable L2C - Set bit 22 */
266 temp |= (1 << 22);
267 writefr_extra_feature_reg(temp);
268
269 icache_enable();
270 /* Change reset vector to address 0x0 */
271 temp = get_cr();
272 set_cr(temp & ~CR_V);
273
274 /* Set CPIOs and MPPs - values provided by board
275 include file */
Albert Aribaud65a236d2010-06-22 15:50:28 +0530276 writel(ORION5X_MPP0_7, ORION5X_MPP_BASE+0x00);
277 writel(ORION5X_MPP8_15, ORION5X_MPP_BASE+0x04);
278 writel(ORION5X_MPP16_23, ORION5X_MPP_BASE+0x50);
Albert ARIBAUDdea1cfb2012-08-16 06:35:21 +0000279 writel(ORION5X_GPIO_OUT_VALUE, ORION5X_GPIO_BASE+0x00);
Albert Aribaud65a236d2010-06-22 15:50:28 +0530280 writel(ORION5X_GPIO_OUT_ENABLE, ORION5X_GPIO_BASE+0x04);
Albert ARIBAUDdea1cfb2012-08-16 06:35:21 +0000281 writel(ORION5X_GPIO_IN_POLARITY, ORION5X_GPIO_BASE+0x0c);
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530282
Albert Aribaudfd5f9732010-09-23 21:49:23 +0200283 /* initialize timer */
284 timer_init_r();
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530285 return 0;
286}
287#endif /* CONFIG_ARCH_MISC_INIT */
Albert Aribaud8a995232010-07-12 22:24:29 +0200288
289#ifdef CONFIG_MVGBE
290int cpu_eth_init(bd_t *bis)
291{
292 mvgbe_initialize(bis);
293 return 0;
294}
295#endif