blob: 009b49287b7ff96e366417791c3c06732a6294a6 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +02002/*
3 * (C) Copyright 2009
4 * Marvell Semiconductor <www.marvell.com>
5 * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +02006 */
7
8#include <common.h>
9#include <netdev.h>
10#include <asm/cache.h>
Lei Wen298ae912011-10-18 20:11:42 +053011#include <asm/io.h>
12#include <asm/arch/cpu.h>
Stefan Roesec2437842014-10-22 12:13:06 +020013#include <asm/arch/soc.h>
DrEaglead881742014-07-25 21:07:30 +020014#include <mvebu_mmc.h>
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020015
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020016void reset_cpu(unsigned long ignored)
17{
18 struct kwcpu_registers *cpureg =
19 (struct kwcpu_registers *)KW_CPU_REG_BASE;
20
21 writel(readl(&cpureg->rstoutn_mask) | (1 << 2),
22 &cpureg->rstoutn_mask);
23 writel(readl(&cpureg->sys_soft_rst) | 1,
24 &cpureg->sys_soft_rst);
25 while (1) ;
26}
27
28/*
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020029 * Window Size
30 * Used with the Base register to set the address window size and location.
31 * Must be programmed from LSB to MSB as sequence of ones followed by
32 * sequence of zeros. The number of ones specifies the size of the window in
33 * 64 KByte granularity (e.g., a value of 0x00FF specifies 256 = 16 MByte).
34 * NOTE: A value of 0x0 specifies 64-KByte size.
35 */
Prafulla Wadaskarecb1b022009-06-29 20:55:54 +053036unsigned int kw_winctrl_calcsize(unsigned int sizeval)
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020037{
38 int i;
39 unsigned int j = 0;
40 u32 val = sizeval >> 1;
41
Prafulla Wadaskarf9c72f62010-08-26 14:43:55 +053042 for (i = 0; val >= 0x10000; i++) {
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020043 j |= (1 << i);
44 val = val >> 1;
45 }
46 return (0x0000ffff & j);
47}
48
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020049/*
50 * kw_config_adr_windows - Configure address Windows
51 *
52 * There are 8 address windows supported by Kirkwood Soc to addess different
53 * devices. Each window can be configured for size, BAR and remap addr
54 * Below configuration is standard for most of the cases
55 *
56 * If remap function not used, remap_lo must be set as base
57 *
58 * Reference Documentation:
59 * Mbus-L to Mbus Bridge Registers Configuration.
60 * (Sec 25.1 and 25.3 of Datasheet)
61 */
62int kw_config_adr_windows(void)
63{
64 struct kwwin_registers *winregs =
Chris Packham4b32bb72019-03-13 20:47:01 +130065 (struct kwwin_registers *)MVEBU_CPU_WIN_BASE;
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020066
67 /* Window 0: PCIE MEM address space */
68 writel(KWCPU_WIN_CTRL_DATA(1024 * 1024 * 256, KWCPU_TARGET_PCIE,
69 KWCPU_ATTR_PCIE_MEM, KWCPU_WIN_ENABLE), &winregs[0].ctrl);
70
71 writel(KW_DEFADR_PCI_MEM, &winregs[0].base);
72 writel(KW_DEFADR_PCI_MEM, &winregs[0].remap_lo);
73 writel(0x0, &winregs[0].remap_hi);
74
75 /* Window 1: PCIE IO address space */
76 writel(KWCPU_WIN_CTRL_DATA(1024 * 64, KWCPU_TARGET_PCIE,
77 KWCPU_ATTR_PCIE_IO, KWCPU_WIN_ENABLE), &winregs[1].ctrl);
78 writel(KW_DEFADR_PCI_IO, &winregs[1].base);
Chris Packham6dd11c22019-03-13 20:47:02 +130079 writel(KW_DEFADR_PCI_IO, &winregs[1].remap_lo);
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +020080 writel(0x0, &winregs[1].remap_hi);
81
82 /* Window 2: NAND Flash address space */
83 writel(KWCPU_WIN_CTRL_DATA(1024 * 1024 * 128, KWCPU_TARGET_MEMORY,
84 KWCPU_ATTR_NANDFLASH, KWCPU_WIN_ENABLE), &winregs[2].ctrl);
85 writel(KW_DEFADR_NANDF, &winregs[2].base);
86 writel(KW_DEFADR_NANDF, &winregs[2].remap_lo);
87 writel(0x0, &winregs[2].remap_hi);
88
89 /* Window 3: SPI Flash address space */
90 writel(KWCPU_WIN_CTRL_DATA(1024 * 1024 * 128, KWCPU_TARGET_MEMORY,
91 KWCPU_ATTR_SPIFLASH, KWCPU_WIN_ENABLE), &winregs[3].ctrl);
92 writel(KW_DEFADR_SPIF, &winregs[3].base);
93 writel(KW_DEFADR_SPIF, &winregs[3].remap_lo);
94 writel(0x0, &winregs[3].remap_hi);
95
96 /* Window 4: BOOT Memory address space */
97 writel(KWCPU_WIN_CTRL_DATA(1024 * 1024 * 128, KWCPU_TARGET_MEMORY,
98 KWCPU_ATTR_BOOTROM, KWCPU_WIN_ENABLE), &winregs[4].ctrl);
99 writel(KW_DEFADR_BOOTROM, &winregs[4].base);
100
101 /* Window 5: Security SRAM address space */
102 writel(KWCPU_WIN_CTRL_DATA(1024 * 64, KWCPU_TARGET_SASRAM,
103 KWCPU_ATTR_SASRAM, KWCPU_WIN_ENABLE), &winregs[5].ctrl);
104 writel(KW_DEFADR_SASRAM, &winregs[5].base);
105
106 /* Window 6-7: Disabled */
107 writel(KWCPU_WIN_DISABLE, &winregs[6].ctrl);
108 writel(KWCPU_WIN_DISABLE, &winregs[7].ctrl);
109
110 return 0;
111}
112
Chris Packham968856c2019-03-13 20:47:03 +1300113static struct mbus_win windows[] = {
114 /* Window 0: PCIE MEM address space */
115 { KW_DEFADR_PCI_MEM, 1024 * 1024 * 256,
116 KWCPU_TARGET_PCIE, KWCPU_ATTR_PCIE_MEM },
117
118 /* Window 1: PCIE IO address space */
119 { KW_DEFADR_PCI_IO, 1024 * 64,
120 KWCPU_TARGET_PCIE, KWCPU_ATTR_PCIE_IO },
121
122 /* Window 2: NAND Flash address space */
123 { KW_DEFADR_NANDF, 1024 * 1024 * 128,
124 KWCPU_TARGET_MEMORY, KWCPU_ATTR_NANDFLASH },
125
126 /* Window 3: SPI Flash address space */
127 { KW_DEFADR_SPIF, 1024 * 1024 * 128,
128 KWCPU_TARGET_MEMORY, KWCPU_ATTR_SPIFLASH },
129
130 /* Window 4: BOOT Memory address space */
131 { KW_DEFADR_BOOTROM, 1024 * 1024 * 128,
132 KWCPU_TARGET_MEMORY, KWCPU_ATTR_BOOTROM },
133
134 /* Window 5: Security SRAM address space */
135 { KW_DEFADR_SASRAM, 1024 * 64,
136 KWCPU_TARGET_SASRAM, KWCPU_ATTR_SASRAM },
137};
138
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +0200139/*
Prafulla Wadaskar2906d772009-08-20 20:59:28 +0530140 * SYSRSTn Duration Counter Support
141 *
142 * Kirkwood SoC implements a hardware-based SYSRSTn duration counter.
143 * When SYSRSTn is asserted low, a SYSRSTn duration counter is running.
144 * The SYSRSTn duration counter is useful for implementing a manufacturer
145 * or factory reset. Upon a long reset assertion that is greater than a
146 * pre-configured environment variable value for sysrstdelay,
147 * The counter value is stored in the SYSRSTn Length Counter Register
148 * The counter is based on the 25-MHz reference clock (40ns)
149 * It is a 29-bit counter, yielding a maximum counting duration of
150 * 2^29/25 MHz (21.4 seconds). When the counter reach its maximum value,
151 * it remains at this value until counter reset is triggered by setting
152 * bit 31 of KW_REG_SYSRST_CNT
153 */
154static void kw_sysrst_action(void)
155{
156 int ret;
Simon Glass64b723f2017-08-03 12:22:12 -0600157 char *s = env_get("sysrstcmd");
Prafulla Wadaskar2906d772009-08-20 20:59:28 +0530158
159 if (!s) {
160 debug("Error.. %s failed, check sysrstcmd\n",
161 __FUNCTION__);
162 return;
163 }
164
165 debug("Starting %s process...\n", __FUNCTION__);
Simon Glassbf8c5b02012-02-14 19:59:21 +0000166 ret = run_command(s, 0);
Thomas Betker5ac00262014-06-05 20:07:56 +0200167 if (ret != 0)
Prafulla Wadaskar2906d772009-08-20 20:59:28 +0530168 debug("Error.. %s failed\n", __FUNCTION__);
169 else
170 debug("%s process finished\n", __FUNCTION__);
171}
172
173static void kw_sysrst_check(void)
174{
175 u32 sysrst_cnt, sysrst_dly;
176 char *s;
177
178 /*
179 * no action if sysrstdelay environment variable is not defined
180 */
Simon Glass64b723f2017-08-03 12:22:12 -0600181 s = env_get("sysrstdelay");
Prafulla Wadaskar2906d772009-08-20 20:59:28 +0530182 if (s == NULL)
183 return;
184
185 /* read sysrstdelay value */
186 sysrst_dly = (u32) simple_strtoul(s, NULL, 10);
187
188 /* read SysRst Length counter register (bits 28:0) */
189 sysrst_cnt = (0x1fffffff & readl(KW_REG_SYSRST_CNT));
190 debug("H/w Rst hold time: %d.%d secs\n",
191 sysrst_cnt / SYSRST_CNT_1SEC_VAL,
192 sysrst_cnt % SYSRST_CNT_1SEC_VAL);
193
194 /* clear the counter for next valid read*/
195 writel(1 << 31, KW_REG_SYSRST_CNT);
196
197 /*
198 * sysrst_action:
199 * if H/w Reset key is pressed and hold for time
200 * more than sysrst_dly in seconds
201 */
202 if (sysrst_cnt >= SYSRST_CNT_1SEC_VAL * sysrst_dly)
203 kw_sysrst_action();
204}
205
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +0200206#if defined(CONFIG_DISPLAY_CPUINFO)
207int print_cpuinfo(void)
208{
Luka Perkovf680edb2013-12-23 01:23:07 +0100209 char *rev = "??";
Prafulla Wadaskar31496292010-09-20 17:19:42 +0530210 u16 devid = (readl(KW_REG_PCIE_DEVID) >> 16) & 0xffff;
211 u8 revid = readl(KW_REG_PCIE_REVID) & 0xff;
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +0200212
Prafulla Wadaskar31496292010-09-20 17:19:42 +0530213 if ((readl(KW_REG_DEVICE_ID) & 0x03) > 2) {
214 printf("Error.. %s:Unsupported Kirkwood SoC 88F%04x\n", __FUNCTION__, devid);
215 return -1;
216 }
217
218 switch (revid) {
219 case 0:
Luka Perkovf680edb2013-12-23 01:23:07 +0100220 if (devid == 0x6281)
221 rev = "Z0";
222 else if (devid == 0x6282)
223 rev = "A0";
224 break;
225 case 1:
226 rev = "A1";
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +0200227 break;
228 case 2:
Prafulla Wadaskar31496292010-09-20 17:19:42 +0530229 rev = "A0";
230 break;
231 case 3:
232 rev = "A1";
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +0200233 break;
234 default:
Prafulla Wadaskar31496292010-09-20 17:19:42 +0530235 break;
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +0200236 }
Prafulla Wadaskar31496292010-09-20 17:19:42 +0530237
238 printf("SoC: Kirkwood 88F%04x_%s\n", devid, rev);
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +0200239 return 0;
240}
241#endif /* CONFIG_DISPLAY_CPUINFO */
242
243#ifdef CONFIG_ARCH_CPU_INIT
244int arch_cpu_init(void)
245{
246 u32 reg;
247 struct kwcpu_registers *cpureg =
248 (struct kwcpu_registers *)KW_CPU_REG_BASE;
249
Chris Packham968856c2019-03-13 20:47:03 +1300250 /* Linux expects the internal registers to be at 0xf1000000 */
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +0200251 writel(KW_REGS_PHY_BASE, KW_OFFSET_REG);
252
253 /* Enable and invalidate L2 cache in write through mode */
254 writel(readl(&cpureg->l2_cfg) | 0x18, &cpureg->l2_cfg);
255 invalidate_l2_cache();
256
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +0200257#ifdef CONFIG_KIRKWOOD_RGMII_PAD_1V8
258 /*
259 * Configures the I/O voltage of the pads connected to Egigabit
260 * Ethernet interface to 1.8V
Robert P. J. Day832d36e2013-09-16 07:15:45 -0400261 * By default it is set to 3.3V
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +0200262 */
263 reg = readl(KW_REG_MPP_OUT_DRV_REG);
264 reg |= (1 << 7);
265 writel(reg, KW_REG_MPP_OUT_DRV_REG);
266#endif
267#ifdef CONFIG_KIRKWOOD_EGIGA_INIT
268 /*
269 * Set egiga port0/1 in normal functional mode
270 * This is required becasue on kirkwood by default ports are in reset mode
271 * OS egiga driver may not have provision to set them in normal mode
272 * and if u-boot is build without network support, network may fail at OS level
273 */
274 reg = readl(KWGBE_PORT_SERIAL_CONTROL1_REG(0));
275 reg &= ~(1 << 4); /* Clear PortReset Bit */
276 writel(reg, (KWGBE_PORT_SERIAL_CONTROL1_REG(0)));
277 reg = readl(KWGBE_PORT_SERIAL_CONTROL1_REG(1));
278 reg &= ~(1 << 4); /* Clear PortReset Bit */
279 writel(reg, (KWGBE_PORT_SERIAL_CONTROL1_REG(1)));
280#endif
281#ifdef CONFIG_KIRKWOOD_PCIE_INIT
282 /*
283 * Enable PCI Express Port0
284 */
285 reg = readl(&cpureg->ctrl_stat);
286 reg |= (1 << 0); /* Set PEX0En Bit */
287 writel(reg, &cpureg->ctrl_stat);
288#endif
289 return 0;
290}
291#endif /* CONFIG_ARCH_CPU_INIT */
292
293/*
294 * SOC specific misc init
295 */
296#if defined(CONFIG_ARCH_MISC_INIT)
297int arch_misc_init(void)
298{
299 volatile u32 temp;
300
301 /*CPU streaming & write allocate */
302 temp = readfr_extra_feature_reg();
303 temp &= ~(1 << 28); /* disable wr alloc */
304 writefr_extra_feature_reg(temp);
305
306 temp = readfr_extra_feature_reg();
307 temp &= ~(1 << 29); /* streaming disabled */
308 writefr_extra_feature_reg(temp);
309
310 /* L2Cache settings */
311 temp = readfr_extra_feature_reg();
312 /* Disable L2C pre fetch - Set bit 24 */
313 temp |= (1 << 24);
314 /* enable L2C - Set bit 22 */
315 temp |= (1 << 22);
316 writefr_extra_feature_reg(temp);
317
318 icache_enable();
319 /* Change reset vector to address 0x0 */
320 temp = get_cr();
321 set_cr(temp & ~CR_V);
322
Chris Packham968856c2019-03-13 20:47:03 +1300323 /* Configure mbus windows */
324 mvebu_mbus_probe(windows, ARRAY_SIZE(windows));
325
Prafulla Wadaskar2906d772009-08-20 20:59:28 +0530326 /* checks and execute resset to factory event */
327 kw_sysrst_check();
328
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +0200329 return 0;
330}
331#endif /* CONFIG_ARCH_MISC_INIT */
332
Albert Aribaude91d7d32010-07-12 22:24:28 +0200333#ifdef CONFIG_MVGBE
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +0200334int cpu_eth_init(bd_t *bis)
335{
Albert Aribaude91d7d32010-07-12 22:24:28 +0200336 mvgbe_initialize(bis);
Prafulla Wadaskara09bbe52009-06-20 11:01:53 +0200337 return 0;
338}
339#endif
DrEaglead881742014-07-25 21:07:30 +0200340
341#ifdef CONFIG_MVEBU_MMC
342int board_mmc_init(bd_t *bis)
343{
344 mvebu_mmc_init(bis);
345 return 0;
346}
347#endif /* CONFIG_MVEBU_MMC */