1 // SPDX-License-Identifier: GPL-2.0+
4 * Marvell Semiconductor <www.marvell.com>
5 * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
15 #include <asm/cache.h>
17 #include <asm/arch/cpu.h>
18 #include <asm/arch/soc.h>
19 #include <mvebu_mmc.h>
21 void reset_cpu(unsigned long ignored)
23 struct kwcpu_registers *cpureg =
24 (struct kwcpu_registers *)KW_CPU_REG_BASE;
26 writel(readl(&cpureg->rstoutn_mask) | (1 << 2),
27 &cpureg->rstoutn_mask);
28 writel(readl(&cpureg->sys_soft_rst) | 1,
29 &cpureg->sys_soft_rst);
35 * 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
38 * 64 KByte granularity (e.g., a value of 0x00FF specifies 256 = 16 MByte).
39 * NOTE: A value of 0x0 specifies 64-KByte size.
41 unsigned int kw_winctrl_calcsize(unsigned int sizeval)
45 u32 val = sizeval >> 1;
47 for (i = 0; val >= 0x10000; i++) {
51 return (0x0000ffff & j);
54 static struct mbus_win windows[] = {
55 /* Window 0: PCIE MEM address space */
56 { KW_DEFADR_PCI_MEM, 1024 * 1024 * 256,
57 KWCPU_TARGET_PCIE, KWCPU_ATTR_PCIE_MEM },
59 /* Window 1: PCIE IO address space */
60 { KW_DEFADR_PCI_IO, 1024 * 64,
61 KWCPU_TARGET_PCIE, KWCPU_ATTR_PCIE_IO },
63 /* Window 2: NAND Flash address space */
64 { KW_DEFADR_NANDF, 1024 * 1024 * 128,
65 KWCPU_TARGET_MEMORY, KWCPU_ATTR_NANDFLASH },
67 /* Window 3: SPI Flash address space */
68 { KW_DEFADR_SPIF, 1024 * 1024 * 128,
69 KWCPU_TARGET_MEMORY, KWCPU_ATTR_SPIFLASH },
71 /* Window 4: BOOT Memory address space */
72 { KW_DEFADR_BOOTROM, 1024 * 1024 * 128,
73 KWCPU_TARGET_MEMORY, KWCPU_ATTR_BOOTROM },
75 /* Window 5: Security SRAM address space */
76 { KW_DEFADR_SASRAM, 1024 * 64,
77 KWCPU_TARGET_SASRAM, KWCPU_ATTR_SASRAM },
81 * SYSRSTn Duration Counter Support
83 * Kirkwood SoC implements a hardware-based SYSRSTn duration counter.
84 * When SYSRSTn is asserted low, a SYSRSTn duration counter is running.
85 * The SYSRSTn duration counter is useful for implementing a manufacturer
86 * or factory reset. Upon a long reset assertion that is greater than a
87 * pre-configured environment variable value for sysrstdelay,
88 * The counter value is stored in the SYSRSTn Length Counter Register
89 * The counter is based on the 25-MHz reference clock (40ns)
90 * It is a 29-bit counter, yielding a maximum counting duration of
91 * 2^29/25 MHz (21.4 seconds). When the counter reach its maximum value,
92 * it remains at this value until counter reset is triggered by setting
93 * bit 31 of KW_REG_SYSRST_CNT
95 static void kw_sysrst_action(void)
98 char *s = env_get("sysrstcmd");
101 debug("Error.. %s failed, check sysrstcmd\n",
106 debug("Starting %s process...\n", __FUNCTION__);
107 ret = run_command(s, 0);
109 debug("Error.. %s failed\n", __FUNCTION__);
111 debug("%s process finished\n", __FUNCTION__);
114 static void kw_sysrst_check(void)
116 u32 sysrst_cnt, sysrst_dly;
120 * no action if sysrstdelay environment variable is not defined
122 s = env_get("sysrstdelay");
126 /* read sysrstdelay value */
127 sysrst_dly = (u32) simple_strtoul(s, NULL, 10);
129 /* read SysRst Length counter register (bits 28:0) */
130 sysrst_cnt = (0x1fffffff & readl(KW_REG_SYSRST_CNT));
131 debug("H/w Rst hold time: %d.%d secs\n",
132 sysrst_cnt / SYSRST_CNT_1SEC_VAL,
133 sysrst_cnt % SYSRST_CNT_1SEC_VAL);
135 /* clear the counter for next valid read*/
136 writel(1 << 31, KW_REG_SYSRST_CNT);
140 * if H/w Reset key is pressed and hold for time
141 * more than sysrst_dly in seconds
143 if (sysrst_cnt >= SYSRST_CNT_1SEC_VAL * sysrst_dly)
147 #if defined(CONFIG_DISPLAY_CPUINFO)
148 int print_cpuinfo(void)
151 u16 devid = (readl(KW_REG_PCIE_DEVID) >> 16) & 0xffff;
152 u8 revid = readl(KW_REG_PCIE_REVID) & 0xff;
154 if ((readl(KW_REG_DEVICE_ID) & 0x03) > 2) {
155 printf("Error.. %s:Unsupported Kirkwood SoC 88F%04x\n", __FUNCTION__, devid);
163 else if (devid == 0x6282)
179 printf("SoC: Kirkwood 88F%04x_%s\n", devid, rev);
182 #endif /* CONFIG_DISPLAY_CPUINFO */
184 #ifdef CONFIG_ARCH_CPU_INIT
185 int arch_cpu_init(void)
188 struct kwcpu_registers *cpureg =
189 (struct kwcpu_registers *)KW_CPU_REG_BASE;
191 /* Linux expects the internal registers to be at 0xf1000000 */
192 writel(KW_REGS_PHY_BASE, KW_OFFSET_REG);
194 /* Enable and invalidate L2 cache in write through mode */
195 writel(readl(&cpureg->l2_cfg) | 0x18, &cpureg->l2_cfg);
196 invalidate_l2_cache();
198 #ifdef CONFIG_KIRKWOOD_RGMII_PAD_1V8
200 * Configures the I/O voltage of the pads connected to Egigabit
201 * Ethernet interface to 1.8V
202 * By default it is set to 3.3V
204 reg = readl(KW_REG_MPP_OUT_DRV_REG);
206 writel(reg, KW_REG_MPP_OUT_DRV_REG);
208 #ifdef CONFIG_KIRKWOOD_EGIGA_INIT
210 * Set egiga port0/1 in normal functional mode
211 * This is required becasue on kirkwood by default ports are in reset mode
212 * OS egiga driver may not have provision to set them in normal mode
213 * and if u-boot is build without network support, network may fail at OS level
215 reg = readl(KWGBE_PORT_SERIAL_CONTROL1_REG(0));
216 reg &= ~(1 << 4); /* Clear PortReset Bit */
217 writel(reg, (KWGBE_PORT_SERIAL_CONTROL1_REG(0)));
218 reg = readl(KWGBE_PORT_SERIAL_CONTROL1_REG(1));
219 reg &= ~(1 << 4); /* Clear PortReset Bit */
220 writel(reg, (KWGBE_PORT_SERIAL_CONTROL1_REG(1)));
222 #ifdef CONFIG_KIRKWOOD_PCIE_INIT
224 * Enable PCI Express Port0
226 reg = readl(&cpureg->ctrl_stat);
227 reg |= (1 << 0); /* Set PEX0En Bit */
228 writel(reg, &cpureg->ctrl_stat);
232 #endif /* CONFIG_ARCH_CPU_INIT */
235 * SOC specific misc init
237 #if defined(CONFIG_ARCH_MISC_INIT)
238 int arch_misc_init(void)
242 /*CPU streaming & write allocate */
243 temp = readfr_extra_feature_reg();
244 temp &= ~(1 << 28); /* disable wr alloc */
245 writefr_extra_feature_reg(temp);
247 temp = readfr_extra_feature_reg();
248 temp &= ~(1 << 29); /* streaming disabled */
249 writefr_extra_feature_reg(temp);
251 /* L2Cache settings */
252 temp = readfr_extra_feature_reg();
253 /* Disable L2C pre fetch - Set bit 24 */
255 /* enable L2C - Set bit 22 */
257 writefr_extra_feature_reg(temp);
259 /* Change reset vector to address 0x0 */
261 set_cr(temp & ~CR_V);
263 /* Configure mbus windows */
264 mvebu_mbus_probe(windows, ARRAY_SIZE(windows));
266 /* checks and execute resset to factory event */
271 #endif /* CONFIG_ARCH_MISC_INIT */
274 int cpu_eth_init(bd_t *bis)
276 mvgbe_initialize(bis);
281 #ifdef CONFIG_MVEBU_MMC
282 int board_mmc_init(bd_t *bis)
287 #endif /* CONFIG_MVEBU_MMC */