blob: 58ee67eca50f32c086f0e1d689674732cbb644b5 [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
Simon Glass1d91ba72019-11-14 12:57:37 -070011#include <cpu_func.h>
Simon Glass97589732020-05-10 11:40:02 -060012#include <init.h>
Simon Glass274e0b02020-05-10 11:39:56 -060013#include <net.h>
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053014#include <netdev.h>
15#include <asm/cache.h>
Lei Wen749941a2011-10-24 16:27:32 +000016#include <asm/io.h>
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053017#include <u-boot/md5.h>
Lei Wen749941a2011-10-24 16:27:32 +000018#include <asm/arch/cpu.h>
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053019
20#define BUFLEN 16
21
Harald Seiler6f14d5f2020-12-15 16:47:52 +010022void reset_cpu(void)
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053023{
24 struct orion5x_cpu_registers *cpureg =
25 (struct orion5x_cpu_registers *)ORION5X_CPU_REG_BASE;
26
27 writel(readl(&cpureg->rstoutn_mask) | (1 << 2),
28 &cpureg->rstoutn_mask);
29 writel(readl(&cpureg->sys_soft_rst) | 1,
30 &cpureg->sys_soft_rst);
31 while (1)
32 ;
33}
34
35/*
Albert Aribaud787aba32010-10-07 20:19:53 +053036 * Compute Window Size field value from size expressed in bytes
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053037 * Used with the Base register to set the address window size and location.
38 * Must be programmed from LSB to MSB as sequence of ones followed by
39 * sequence of zeros. The number of ones specifies the size of the window in
Albert Aribaud787aba32010-10-07 20:19:53 +053040 * 64 KiB granularity (e.g., a value of 0x00FF specifies 256 = 16 MiB).
41 * NOTES:
42 * 1) A sizeval equal to 0x0 specifies 4 GiB.
43 * 2) A return value of 0x0 specifies 64 KiB.
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053044 */
45unsigned int orion5x_winctrl_calcsize(unsigned int sizeval)
46{
Albert Aribaud787aba32010-10-07 20:19:53 +053047 /*
48 * Calculate the number of 64 KiB blocks needed minus one (rounding up).
49 * For sizeval > 0 this is equivalent to:
50 * sizeval = (u32) ceil((double) sizeval / 65536.0) - 1
51 */
52 sizeval = (sizeval - 1) >> 16;
53
54 /*
55 * Propagate 'one' bits to the right by 'oring' them.
56 * We need only treat bits 15-0.
57 */
58 sizeval |= sizeval >> 1; /* 'Or' bit 15 onto bit 14 */
59 sizeval |= sizeval >> 2; /* 'Or' bits 15-14 onto bits 13-12 */
60 sizeval |= sizeval >> 4; /* 'Or' bits 15-12 onto bits 11-8 */
61 sizeval |= sizeval >> 8; /* 'Or' bits 15-8 onto bits 7-0*/
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053062
Albert Aribaud787aba32010-10-07 20:19:53 +053063 return sizeval;
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053064}
65
66/*
67 * orion5x_config_adr_windows - Configure address Windows
68 *
69 * There are 8 address windows supported by Orion5x Soc to addess different
70 * devices. Each window can be configured for size, BAR and remap addr
71 * Below configuration is standard for most of the cases
72 *
73 * If remap function not used, remap_lo must be set as base
74 *
Albert Aribaudfd5f9732010-09-23 21:49:23 +020075 * NOTES:
76 *
77 * 1) in order to avoid windows with inconsistent control and base values
78 * (which could prevent access to BOOTCS and hence execution from FLASH)
79 * always disable window before writing the base value then reenable it
80 * by writing the control value.
81 *
82 * 2) in order to avoid losing access to BOOTCS when disabling window 7,
83 * first configure window 6 for BOOTCS, then configure window 7 for BOOTCS,
84 * then configure windows 6 for its own target.
85 *
Albert Aribaudac2ba9e2010-06-17 19:36:07 +053086 * Reference Documentation:
87 * Mbus-L to Mbus Bridge Registers Configuration.
88 * (Sec 25.1 and 25.3 of Datasheet)
89 */
90int orion5x_config_adr_windows(void)
91{
92 struct orion5x_win_registers *winregs =
93 (struct orion5x_win_registers *)ORION5X_CPU_WIN_BASE;
94
Albert Aribaudfd5f9732010-09-23 21:49:23 +020095/* Disable window 0, configure it for its intended target, enable it. */
96 writel(0, &winregs[0].ctrl);
Albert Aribaudf4704d02010-07-13 09:04:26 +020097 writel(ORION5X_ADR_PCIE_MEM, &winregs[0].base);
98 writel(ORION5X_ADR_PCIE_MEM_REMAP_LO, &winregs[0].remap_lo);
99 writel(ORION5X_ADR_PCIE_MEM_REMAP_HI, &winregs[0].remap_hi);
Albert Aribaudfd5f9732010-09-23 21:49:23 +0200100 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCIE_MEM,
101 ORION5X_TARGET_PCIE, ORION5X_ATTR_PCIE_MEM,
102 ORION5X_WIN_ENABLE), &winregs[0].ctrl);
103/* Disable window 1, configure it for its intended target, enable it. */
104 writel(0, &winregs[1].ctrl);
Albert Aribaudf4704d02010-07-13 09:04:26 +0200105 writel(ORION5X_ADR_PCIE_IO, &winregs[1].base);
106 writel(ORION5X_ADR_PCIE_IO_REMAP_LO, &winregs[1].remap_lo);
107 writel(ORION5X_ADR_PCIE_IO_REMAP_HI, &winregs[1].remap_hi);
Albert Aribaudfd5f9732010-09-23 21:49:23 +0200108 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCIE_IO,
109 ORION5X_TARGET_PCIE, ORION5X_ATTR_PCIE_IO,
110 ORION5X_WIN_ENABLE), &winregs[1].ctrl);
111/* Disable window 2, configure it for its intended target, enable it. */
112 writel(0, &winregs[2].ctrl);
113 writel(ORION5X_ADR_PCI_MEM, &winregs[2].base);
Albert Aribaudf4704d02010-07-13 09:04:26 +0200114 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCI_MEM,
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530115 ORION5X_TARGET_PCI, ORION5X_ATTR_PCI_MEM,
116 ORION5X_WIN_ENABLE), &winregs[2].ctrl);
Albert Aribaudfd5f9732010-09-23 21:49:23 +0200117/* Disable window 3, configure it for its intended target, enable it. */
118 writel(0, &winregs[3].ctrl);
119 writel(ORION5X_ADR_PCI_IO, &winregs[3].base);
Albert Aribaudf4704d02010-07-13 09:04:26 +0200120 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_PCI_IO,
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530121 ORION5X_TARGET_PCI, ORION5X_ATTR_PCI_IO,
122 ORION5X_WIN_ENABLE), &winregs[3].ctrl);
Albert Aribaudfd5f9732010-09-23 21:49:23 +0200123/* Disable window 4, configure it for its intended target, enable it. */
124 writel(0, &winregs[4].ctrl);
125 writel(ORION5X_ADR_DEV_CS0, &winregs[4].base);
Albert Aribaudf4704d02010-07-13 09:04:26 +0200126 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_DEV_CS0,
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530127 ORION5X_TARGET_DEVICE, ORION5X_ATTR_DEV_CS0,
128 ORION5X_WIN_ENABLE), &winregs[4].ctrl);
Albert Aribaudfd5f9732010-09-23 21:49:23 +0200129/* Disable window 5, configure it for its intended target, enable it. */
130 writel(0, &winregs[5].ctrl);
131 writel(ORION5X_ADR_DEV_CS1, &winregs[5].base);
Albert Aribaudf4704d02010-07-13 09:04:26 +0200132 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_DEV_CS1,
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530133 ORION5X_TARGET_DEVICE, ORION5X_ATTR_DEV_CS1,
134 ORION5X_WIN_ENABLE), &winregs[5].ctrl);
Albert Aribaudfd5f9732010-09-23 21:49:23 +0200135/* Disable window 6, configure it for FLASH, enable it. */
136 writel(0, &winregs[6].ctrl);
137 writel(ORION5X_ADR_BOOTROM, &winregs[6].base);
138 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_BOOTROM,
139 ORION5X_TARGET_DEVICE, ORION5X_ATTR_BOOTROM,
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530140 ORION5X_WIN_ENABLE), &winregs[6].ctrl);
Albert Aribaudfd5f9732010-09-23 21:49:23 +0200141/* Disable window 7, configure it for FLASH, enable it. */
142 writel(0, &winregs[7].ctrl);
143 writel(ORION5X_ADR_BOOTROM, &winregs[7].base);
Albert Aribaudf4704d02010-07-13 09:04:26 +0200144 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_BOOTROM,
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530145 ORION5X_TARGET_DEVICE, ORION5X_ATTR_BOOTROM,
146 ORION5X_WIN_ENABLE), &winregs[7].ctrl);
Albert Aribaudfd5f9732010-09-23 21:49:23 +0200147/* Disable window 6, configure it for its intended target, enable it. */
148 writel(0, &winregs[6].ctrl);
149 writel(ORION5X_ADR_DEV_CS2, &winregs[6].base);
150 writel(ORION5X_CPU_WIN_CTRL_DATA(ORION5X_SZ_DEV_CS2,
151 ORION5X_TARGET_DEVICE, ORION5X_ATTR_DEV_CS2,
152 ORION5X_WIN_ENABLE), &winregs[6].ctrl);
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530153
154 return 0;
155}
156
157/*
158 * Orion5x identification is done through PCIE space.
159 */
160
161u32 orion5x_device_id(void)
162{
163 return readl(PCIE_DEV_ID_OFF) >> 16;
164}
165
166u32 orion5x_device_rev(void)
167{
168 return readl(PCIE_DEV_REV_OFF) & 0xff;
169}
170
171#if defined(CONFIG_DISPLAY_CPUINFO)
172
173/* Display device and revision IDs.
174 * This function must cover all known device/revision
175 * combinations, not only the one for which u-boot is
176 * compiled; this way, one can identify actual HW in
177 * case of a mismatch.
178 */
179int print_cpuinfo(void)
180{
Albert ARIBAUDd6d4ec82012-10-09 09:28:15 +0000181 char dev_str[7]; /* room enough for 0x0000 plus null byte */
182 char rev_str[5]; /* room enough for 0x00 plus null byte */
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530183 char *dev_name = NULL;
184 char *rev_name = NULL;
185
186 u32 dev = orion5x_device_id();
187 u32 rev = orion5x_device_rev();
188
189 if (dev == MV88F5181_DEV_ID) {
190 dev_name = "MV88F5181";
191 if (rev == MV88F5181_REV_B1)
192 rev_name = "B1";
193 else if (rev == MV88F5181L_REV_A1) {
194 dev_name = "MV88F5181L";
195 rev_name = "A1";
196 } else if (rev == MV88F5181L_REV_A0) {
197 dev_name = "MV88F5181L";
198 rev_name = "A0";
199 }
200 } else if (dev == MV88F5182_DEV_ID) {
201 dev_name = "MV88F5182";
202 if (rev == MV88F5182_REV_A2)
203 rev_name = "A2";
204 } else if (dev == MV88F5281_DEV_ID) {
205 dev_name = "MV88F5281";
206 if (rev == MV88F5281_REV_D2)
207 rev_name = "D2";
208 else if (rev == MV88F5281_REV_D1)
209 rev_name = "D1";
210 else if (rev == MV88F5281_REV_D0)
211 rev_name = "D0";
212 } else if (dev == MV88F6183_DEV_ID) {
213 dev_name = "MV88F6183";
214 if (rev == MV88F6183_REV_B0)
215 rev_name = "B0";
216 }
217 if (dev_name == NULL) {
218 sprintf(dev_str, "0x%04x", dev);
219 dev_name = dev_str;
220 }
221 if (rev_name == NULL) {
222 sprintf(rev_str, "0x%02x", rev);
223 rev_name = rev_str;
224 }
225
226 printf("SoC: Orion5x %s-%s\n", dev_name, rev_name);
227
228 return 0;
229}
230#endif /* CONFIG_DISPLAY_CPUINFO */
231
232#ifdef CONFIG_ARCH_CPU_INIT
233int arch_cpu_init(void)
234{
235 /* Enable and invalidate L2 cache in write through mode */
236 invalidate_l2_cache();
237
Albert ARIBAUD2ac37922015-01-31 22:55:38 +0100238#ifdef CONFIG_SPL_BUILD
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530239 orion5x_config_adr_windows();
Albert ARIBAUD2ac37922015-01-31 22:55:38 +0100240#endif
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530241
242 return 0;
243}
244#endif /* CONFIG_ARCH_CPU_INIT */
245
246/*
247 * SOC specific misc init
248 */
249#if defined(CONFIG_ARCH_MISC_INIT)
250int arch_misc_init(void)
251{
252 u32 temp;
253
254 /*CPU streaming & write allocate */
255 temp = readfr_extra_feature_reg();
256 temp &= ~(1 << 28); /* disable wr alloc */
257 writefr_extra_feature_reg(temp);
258
259 temp = readfr_extra_feature_reg();
260 temp &= ~(1 << 29); /* streaming disabled */
261 writefr_extra_feature_reg(temp);
262
263 /* L2Cache settings */
264 temp = readfr_extra_feature_reg();
265 /* Disable L2C pre fetch - Set bit 24 */
266 temp |= (1 << 24);
267 /* enable L2C - Set bit 22 */
268 temp |= (1 << 22);
269 writefr_extra_feature_reg(temp);
270
271 icache_enable();
272 /* Change reset vector to address 0x0 */
273 temp = get_cr();
274 set_cr(temp & ~CR_V);
275
276 /* Set CPIOs and MPPs - values provided by board
277 include file */
Albert Aribaud65a236d2010-06-22 15:50:28 +0530278 writel(ORION5X_MPP0_7, ORION5X_MPP_BASE+0x00);
279 writel(ORION5X_MPP8_15, ORION5X_MPP_BASE+0x04);
280 writel(ORION5X_MPP16_23, ORION5X_MPP_BASE+0x50);
Albert ARIBAUDdea1cfb2012-08-16 06:35:21 +0000281 writel(ORION5X_GPIO_OUT_VALUE, ORION5X_GPIO_BASE+0x00);
Albert Aribaud65a236d2010-06-22 15:50:28 +0530282 writel(ORION5X_GPIO_OUT_ENABLE, ORION5X_GPIO_BASE+0x04);
Albert ARIBAUDdea1cfb2012-08-16 06:35:21 +0000283 writel(ORION5X_GPIO_IN_POLARITY, ORION5X_GPIO_BASE+0x0c);
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530284
Albert Aribaudfd5f9732010-09-23 21:49:23 +0200285 /* initialize timer */
286 timer_init_r();
Albert Aribaudac2ba9e2010-06-17 19:36:07 +0530287 return 0;
288}
289#endif /* CONFIG_ARCH_MISC_INIT */
Albert Aribaud8a995232010-07-12 22:24:29 +0200290
291#ifdef CONFIG_MVGBE
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900292int cpu_eth_init(struct bd_info *bis)
Albert Aribaud8a995232010-07-12 22:24:29 +0200293{
294 mvgbe_initialize(bis);
295 return 0;
296}
297#endif