1 // SPDX-License-Identifier: GPL-2.0+
4 * Marvell Semiconductor <www.marvell.com>
5 * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
10 #include <asm/cache.h>
12 #include <asm/arch/cpu.h>
13 #include <asm/arch/soc.h>
14 #include <mvebu_mmc.h>
16 void reset_cpu(unsigned long ignored)
18 struct kwcpu_registers *cpureg =
19 (struct kwcpu_registers *)KW_CPU_REG_BASE;
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);
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.
36 unsigned int kw_winctrl_calcsize(unsigned int sizeval)
40 u32 val = sizeval >> 1;
42 for (i = 0; val >= 0x10000; i++) {
46 return (0x0000ffff & j);
50 * kw_config_adr_windows - Configure address Windows
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
56 * If remap function not used, remap_lo must be set as base
58 * Reference Documentation:
59 * Mbus-L to Mbus Bridge Registers Configuration.
60 * (Sec 25.1 and 25.3 of Datasheet)
62 int kw_config_adr_windows(void)
64 struct kwwin_registers *winregs =
65 (struct kwwin_registers *)KW_CPU_WIN_BASE;
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);
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);
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);
79 writel(KW_DEFADR_PCI_IO_REMAP, &winregs[1].remap_lo);
80 writel(0x0, &winregs[1].remap_hi);
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);
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);
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);
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);
106 /* Window 6-7: Disabled */
107 writel(KWCPU_WIN_DISABLE, &winregs[6].ctrl);
108 writel(KWCPU_WIN_DISABLE, &winregs[7].ctrl);
114 * SYSRSTn Duration Counter Support
116 * Kirkwood SoC implements a hardware-based SYSRSTn duration counter.
117 * When SYSRSTn is asserted low, a SYSRSTn duration counter is running.
118 * The SYSRSTn duration counter is useful for implementing a manufacturer
119 * or factory reset. Upon a long reset assertion that is greater than a
120 * pre-configured environment variable value for sysrstdelay,
121 * The counter value is stored in the SYSRSTn Length Counter Register
122 * The counter is based on the 25-MHz reference clock (40ns)
123 * It is a 29-bit counter, yielding a maximum counting duration of
124 * 2^29/25 MHz (21.4 seconds). When the counter reach its maximum value,
125 * it remains at this value until counter reset is triggered by setting
126 * bit 31 of KW_REG_SYSRST_CNT
128 static void kw_sysrst_action(void)
131 char *s = env_get("sysrstcmd");
134 debug("Error.. %s failed, check sysrstcmd\n",
139 debug("Starting %s process...\n", __FUNCTION__);
140 ret = run_command(s, 0);
142 debug("Error.. %s failed\n", __FUNCTION__);
144 debug("%s process finished\n", __FUNCTION__);
147 static void kw_sysrst_check(void)
149 u32 sysrst_cnt, sysrst_dly;
153 * no action if sysrstdelay environment variable is not defined
155 s = env_get("sysrstdelay");
159 /* read sysrstdelay value */
160 sysrst_dly = (u32) simple_strtoul(s, NULL, 10);
162 /* read SysRst Length counter register (bits 28:0) */
163 sysrst_cnt = (0x1fffffff & readl(KW_REG_SYSRST_CNT));
164 debug("H/w Rst hold time: %d.%d secs\n",
165 sysrst_cnt / SYSRST_CNT_1SEC_VAL,
166 sysrst_cnt % SYSRST_CNT_1SEC_VAL);
168 /* clear the counter for next valid read*/
169 writel(1 << 31, KW_REG_SYSRST_CNT);
173 * if H/w Reset key is pressed and hold for time
174 * more than sysrst_dly in seconds
176 if (sysrst_cnt >= SYSRST_CNT_1SEC_VAL * sysrst_dly)
180 #if defined(CONFIG_DISPLAY_CPUINFO)
181 int print_cpuinfo(void)
184 u16 devid = (readl(KW_REG_PCIE_DEVID) >> 16) & 0xffff;
185 u8 revid = readl(KW_REG_PCIE_REVID) & 0xff;
187 if ((readl(KW_REG_DEVICE_ID) & 0x03) > 2) {
188 printf("Error.. %s:Unsupported Kirkwood SoC 88F%04x\n", __FUNCTION__, devid);
196 else if (devid == 0x6282)
212 printf("SoC: Kirkwood 88F%04x_%s\n", devid, rev);
215 #endif /* CONFIG_DISPLAY_CPUINFO */
217 #ifdef CONFIG_ARCH_CPU_INIT
218 int arch_cpu_init(void)
221 struct kwcpu_registers *cpureg =
222 (struct kwcpu_registers *)KW_CPU_REG_BASE;
224 /* Linux expects` the internal registers to be at 0xf1000000 */
225 writel(KW_REGS_PHY_BASE, KW_OFFSET_REG);
227 /* Enable and invalidate L2 cache in write through mode */
228 writel(readl(&cpureg->l2_cfg) | 0x18, &cpureg->l2_cfg);
229 invalidate_l2_cache();
231 kw_config_adr_windows();
233 #ifdef CONFIG_KIRKWOOD_RGMII_PAD_1V8
235 * Configures the I/O voltage of the pads connected to Egigabit
236 * Ethernet interface to 1.8V
237 * By default it is set to 3.3V
239 reg = readl(KW_REG_MPP_OUT_DRV_REG);
241 writel(reg, KW_REG_MPP_OUT_DRV_REG);
243 #ifdef CONFIG_KIRKWOOD_EGIGA_INIT
245 * Set egiga port0/1 in normal functional mode
246 * This is required becasue on kirkwood by default ports are in reset mode
247 * OS egiga driver may not have provision to set them in normal mode
248 * and if u-boot is build without network support, network may fail at OS level
250 reg = readl(KWGBE_PORT_SERIAL_CONTROL1_REG(0));
251 reg &= ~(1 << 4); /* Clear PortReset Bit */
252 writel(reg, (KWGBE_PORT_SERIAL_CONTROL1_REG(0)));
253 reg = readl(KWGBE_PORT_SERIAL_CONTROL1_REG(1));
254 reg &= ~(1 << 4); /* Clear PortReset Bit */
255 writel(reg, (KWGBE_PORT_SERIAL_CONTROL1_REG(1)));
257 #ifdef CONFIG_KIRKWOOD_PCIE_INIT
259 * Enable PCI Express Port0
261 reg = readl(&cpureg->ctrl_stat);
262 reg |= (1 << 0); /* Set PEX0En Bit */
263 writel(reg, &cpureg->ctrl_stat);
267 #endif /* CONFIG_ARCH_CPU_INIT */
270 * SOC specific misc init
272 #if defined(CONFIG_ARCH_MISC_INIT)
273 int arch_misc_init(void)
277 /*CPU streaming & write allocate */
278 temp = readfr_extra_feature_reg();
279 temp &= ~(1 << 28); /* disable wr alloc */
280 writefr_extra_feature_reg(temp);
282 temp = readfr_extra_feature_reg();
283 temp &= ~(1 << 29); /* streaming disabled */
284 writefr_extra_feature_reg(temp);
286 /* L2Cache settings */
287 temp = readfr_extra_feature_reg();
288 /* Disable L2C pre fetch - Set bit 24 */
290 /* enable L2C - Set bit 22 */
292 writefr_extra_feature_reg(temp);
295 /* Change reset vector to address 0x0 */
297 set_cr(temp & ~CR_V);
299 /* checks and execute resset to factory event */
304 #endif /* CONFIG_ARCH_MISC_INIT */
307 int cpu_eth_init(bd_t *bis)
309 mvgbe_initialize(bis);
314 #ifdef CONFIG_MVEBU_MMC
315 int board_mmc_init(bd_t *bis)
320 #endif /* CONFIG_MVEBU_MMC */