blob: 8f8e3003854c213d7b04c2e974058230f90b605b [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Prafulla Wadaskar4efb77d2009-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 Wadaskar4efb77d2009-06-20 11:01:53 +02006 */
7
8#include <common.h>
9#include <netdev.h>
10#include <asm/cache.h>
Lei Wena7efd712011-10-18 20:11:42 +053011#include <asm/io.h>
12#include <asm/arch/cpu.h>
Stefan Roese3dc23f72014-10-22 12:13:06 +020013#include <asm/arch/soc.h>
DrEagle3fe3b4f2014-07-25 21:07:30 +020014#include <mvebu_mmc.h>
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020015
Prafulla Wadaskar4efb77d2009-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 Wadaskar4efb77d2009-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 Wadaskar78eabb92009-06-29 20:55:54 +053036unsigned int kw_winctrl_calcsize(unsigned int sizeval)
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020037{
38 int i;
39 unsigned int j = 0;
40 u32 val = sizeval >> 1;
41
Prafulla Wadaskarf1060562010-08-26 14:43:55 +053042 for (i = 0; val >= 0x10000; i++) {
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020043 j |= (1 << i);
44 val = val >> 1;
45 }
46 return (0x0000ffff & j);
47}
48
Chris Packham8ef078b2019-03-13 20:47:03 +130049static struct mbus_win windows[] = {
50 /* Window 0: PCIE MEM address space */
51 { KW_DEFADR_PCI_MEM, 1024 * 1024 * 256,
52 KWCPU_TARGET_PCIE, KWCPU_ATTR_PCIE_MEM },
53
54 /* Window 1: PCIE IO address space */
55 { KW_DEFADR_PCI_IO, 1024 * 64,
56 KWCPU_TARGET_PCIE, KWCPU_ATTR_PCIE_IO },
57
58 /* Window 2: NAND Flash address space */
59 { KW_DEFADR_NANDF, 1024 * 1024 * 128,
60 KWCPU_TARGET_MEMORY, KWCPU_ATTR_NANDFLASH },
61
62 /* Window 3: SPI Flash address space */
63 { KW_DEFADR_SPIF, 1024 * 1024 * 128,
64 KWCPU_TARGET_MEMORY, KWCPU_ATTR_SPIFLASH },
65
66 /* Window 4: BOOT Memory address space */
67 { KW_DEFADR_BOOTROM, 1024 * 1024 * 128,
68 KWCPU_TARGET_MEMORY, KWCPU_ATTR_BOOTROM },
69
70 /* Window 5: Security SRAM address space */
71 { KW_DEFADR_SASRAM, 1024 * 64,
72 KWCPU_TARGET_SASRAM, KWCPU_ATTR_SASRAM },
73};
74
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +020075/*
Prafulla Wadaskar49d2cb42009-08-20 20:59:28 +053076 * SYSRSTn Duration Counter Support
77 *
78 * Kirkwood SoC implements a hardware-based SYSRSTn duration counter.
79 * When SYSRSTn is asserted low, a SYSRSTn duration counter is running.
80 * The SYSRSTn duration counter is useful for implementing a manufacturer
81 * or factory reset. Upon a long reset assertion that is greater than a
82 * pre-configured environment variable value for sysrstdelay,
83 * The counter value is stored in the SYSRSTn Length Counter Register
84 * The counter is based on the 25-MHz reference clock (40ns)
85 * It is a 29-bit counter, yielding a maximum counting duration of
86 * 2^29/25 MHz (21.4 seconds). When the counter reach its maximum value,
87 * it remains at this value until counter reset is triggered by setting
88 * bit 31 of KW_REG_SYSRST_CNT
89 */
90static void kw_sysrst_action(void)
91{
92 int ret;
Simon Glass00caae62017-08-03 12:22:12 -060093 char *s = env_get("sysrstcmd");
Prafulla Wadaskar49d2cb42009-08-20 20:59:28 +053094
95 if (!s) {
96 debug("Error.. %s failed, check sysrstcmd\n",
97 __FUNCTION__);
98 return;
99 }
100
101 debug("Starting %s process...\n", __FUNCTION__);
Simon Glass53071532012-02-14 19:59:21 +0000102 ret = run_command(s, 0);
Thomas Betker73671da2014-06-05 20:07:56 +0200103 if (ret != 0)
Prafulla Wadaskar49d2cb42009-08-20 20:59:28 +0530104 debug("Error.. %s failed\n", __FUNCTION__);
105 else
106 debug("%s process finished\n", __FUNCTION__);
107}
108
109static void kw_sysrst_check(void)
110{
111 u32 sysrst_cnt, sysrst_dly;
112 char *s;
113
114 /*
115 * no action if sysrstdelay environment variable is not defined
116 */
Simon Glass00caae62017-08-03 12:22:12 -0600117 s = env_get("sysrstdelay");
Prafulla Wadaskar49d2cb42009-08-20 20:59:28 +0530118 if (s == NULL)
119 return;
120
121 /* read sysrstdelay value */
122 sysrst_dly = (u32) simple_strtoul(s, NULL, 10);
123
124 /* read SysRst Length counter register (bits 28:0) */
125 sysrst_cnt = (0x1fffffff & readl(KW_REG_SYSRST_CNT));
126 debug("H/w Rst hold time: %d.%d secs\n",
127 sysrst_cnt / SYSRST_CNT_1SEC_VAL,
128 sysrst_cnt % SYSRST_CNT_1SEC_VAL);
129
130 /* clear the counter for next valid read*/
131 writel(1 << 31, KW_REG_SYSRST_CNT);
132
133 /*
134 * sysrst_action:
135 * if H/w Reset key is pressed and hold for time
136 * more than sysrst_dly in seconds
137 */
138 if (sysrst_cnt >= SYSRST_CNT_1SEC_VAL * sysrst_dly)
139 kw_sysrst_action();
140}
141
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +0200142#if defined(CONFIG_DISPLAY_CPUINFO)
143int print_cpuinfo(void)
144{
Luka Perkov62d1e992013-12-23 01:23:07 +0100145 char *rev = "??";
Prafulla Wadaskarc0cd0202010-09-20 17:19:42 +0530146 u16 devid = (readl(KW_REG_PCIE_DEVID) >> 16) & 0xffff;
147 u8 revid = readl(KW_REG_PCIE_REVID) & 0xff;
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +0200148
Prafulla Wadaskarc0cd0202010-09-20 17:19:42 +0530149 if ((readl(KW_REG_DEVICE_ID) & 0x03) > 2) {
150 printf("Error.. %s:Unsupported Kirkwood SoC 88F%04x\n", __FUNCTION__, devid);
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +0200151 return -1;
152 }
Prafulla Wadaskarc0cd0202010-09-20 17:19:42 +0530153
154 switch (revid) {
155 case 0:
Luka Perkov62d1e992013-12-23 01:23:07 +0100156 if (devid == 0x6281)
157 rev = "Z0";
158 else if (devid == 0x6282)
159 rev = "A0";
160 break;
161 case 1:
162 rev = "A1";
Prafulla Wadaskarc0cd0202010-09-20 17:19:42 +0530163 break;
164 case 2:
165 rev = "A0";
166 break;
167 case 3:
168 rev = "A1";
169 break;
170 default:
Prafulla Wadaskarc0cd0202010-09-20 17:19:42 +0530171 break;
172 }
173
174 printf("SoC: Kirkwood 88F%04x_%s\n", devid, rev);
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +0200175 return 0;
176}
177#endif /* CONFIG_DISPLAY_CPUINFO */
178
179#ifdef CONFIG_ARCH_CPU_INIT
180int arch_cpu_init(void)
181{
182 u32 reg;
183 struct kwcpu_registers *cpureg =
184 (struct kwcpu_registers *)KW_CPU_REG_BASE;
185
Chris Packham8ef078b2019-03-13 20:47:03 +1300186 /* Linux expects the internal registers to be at 0xf1000000 */
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +0200187 writel(KW_REGS_PHY_BASE, KW_OFFSET_REG);
188
189 /* Enable and invalidate L2 cache in write through mode */
190 writel(readl(&cpureg->l2_cfg) | 0x18, &cpureg->l2_cfg);
191 invalidate_l2_cache();
192
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +0200193#ifdef CONFIG_KIRKWOOD_RGMII_PAD_1V8
194 /*
195 * Configures the I/O voltage of the pads connected to Egigabit
196 * Ethernet interface to 1.8V
Robert P. J. Day1bce2ae2013-09-16 07:15:45 -0400197 * By default it is set to 3.3V
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +0200198 */
199 reg = readl(KW_REG_MPP_OUT_DRV_REG);
200 reg |= (1 << 7);
201 writel(reg, KW_REG_MPP_OUT_DRV_REG);
202#endif
203#ifdef CONFIG_KIRKWOOD_EGIGA_INIT
204 /*
205 * Set egiga port0/1 in normal functional mode
206 * This is required becasue on kirkwood by default ports are in reset mode
207 * OS egiga driver may not have provision to set them in normal mode
208 * and if u-boot is build without network support, network may fail at OS level
209 */
210 reg = readl(KWGBE_PORT_SERIAL_CONTROL1_REG(0));
211 reg &= ~(1 << 4); /* Clear PortReset Bit */
212 writel(reg, (KWGBE_PORT_SERIAL_CONTROL1_REG(0)));
213 reg = readl(KWGBE_PORT_SERIAL_CONTROL1_REG(1));
214 reg &= ~(1 << 4); /* Clear PortReset Bit */
215 writel(reg, (KWGBE_PORT_SERIAL_CONTROL1_REG(1)));
216#endif
217#ifdef CONFIG_KIRKWOOD_PCIE_INIT
218 /*
219 * Enable PCI Express Port0
220 */
221 reg = readl(&cpureg->ctrl_stat);
222 reg |= (1 << 0); /* Set PEX0En Bit */
223 writel(reg, &cpureg->ctrl_stat);
224#endif
225 return 0;
226}
227#endif /* CONFIG_ARCH_CPU_INIT */
228
229/*
230 * SOC specific misc init
231 */
232#if defined(CONFIG_ARCH_MISC_INIT)
233int arch_misc_init(void)
234{
235 volatile u32 temp;
236
237 /*CPU streaming & write allocate */
238 temp = readfr_extra_feature_reg();
239 temp &= ~(1 << 28); /* disable wr alloc */
240 writefr_extra_feature_reg(temp);
241
242 temp = readfr_extra_feature_reg();
243 temp &= ~(1 << 29); /* streaming disabled */
244 writefr_extra_feature_reg(temp);
245
246 /* L2Cache settings */
247 temp = readfr_extra_feature_reg();
248 /* Disable L2C pre fetch - Set bit 24 */
249 temp |= (1 << 24);
250 /* enable L2C - Set bit 22 */
251 temp |= (1 << 22);
252 writefr_extra_feature_reg(temp);
253
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +0200254 /* Change reset vector to address 0x0 */
255 temp = get_cr();
256 set_cr(temp & ~CR_V);
257
Chris Packham8ef078b2019-03-13 20:47:03 +1300258 /* Configure mbus windows */
259 mvebu_mbus_probe(windows, ARRAY_SIZE(windows));
260
Prafulla Wadaskar49d2cb42009-08-20 20:59:28 +0530261 /* checks and execute resset to factory event */
262 kw_sysrst_check();
263
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +0200264 return 0;
265}
266#endif /* CONFIG_ARCH_MISC_INIT */
267
Albert Aribaudd44265a2010-07-12 22:24:28 +0200268#ifdef CONFIG_MVGBE
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +0200269int cpu_eth_init(bd_t *bis)
270{
Albert Aribaudd44265a2010-07-12 22:24:28 +0200271 mvgbe_initialize(bis);
Prafulla Wadaskar4efb77d2009-06-20 11:01:53 +0200272 return 0;
273}
274#endif
DrEagle3fe3b4f2014-07-25 21:07:30 +0200275
276#ifdef CONFIG_MVEBU_MMC
277int board_mmc_init(bd_t *bis)
278{
279 mvebu_mmc_init(bis);
280 return 0;
281}
282#endif /* CONFIG_MVEBU_MMC */