Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2009 |
| 4 | * Marvell Semiconductor <www.marvell.com> |
| 5 | * Written-by: Prafulla Wadaskar <prafulla@marvell.com> |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
Simon Glass | adaaa48 | 2019-11-14 12:57:43 -0700 | [diff] [blame] | 8 | #include <command.h> |
Simon Glass | afb0215 | 2019-12-28 10:45:01 -0700 | [diff] [blame] | 9 | #include <cpu_func.h> |
Simon Glass | 0af6e2d | 2019-08-01 09:46:52 -0600 | [diff] [blame] | 10 | #include <env.h> |
Simon Glass | 9758973 | 2020-05-10 11:40:02 -0600 | [diff] [blame] | 11 | #include <init.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Simon Glass | 274e0b0 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 13 | #include <net.h> |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 14 | #include <netdev.h> |
| 15 | #include <asm/cache.h> |
Lei Wen | 298ae91 | 2011-10-18 20:11:42 +0530 | [diff] [blame] | 16 | #include <asm/io.h> |
| 17 | #include <asm/arch/cpu.h> |
Stefan Roese | c243784 | 2014-10-22 12:13:06 +0200 | [diff] [blame] | 18 | #include <asm/arch/soc.h> |
DrEagle | ad88174 | 2014-07-25 21:07:30 +0200 | [diff] [blame] | 19 | #include <mvebu_mmc.h> |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 20 | |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 21 | void reset_cpu(void) |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 22 | { |
| 23 | struct kwcpu_registers *cpureg = |
| 24 | (struct kwcpu_registers *)KW_CPU_REG_BASE; |
| 25 | |
| 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); |
| 30 | while (1) ; |
| 31 | } |
| 32 | |
| 33 | /* |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 34 | * Window Size |
| 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. |
| 40 | */ |
Prafulla Wadaskar | ecb1b02 | 2009-06-29 20:55:54 +0530 | [diff] [blame] | 41 | unsigned int kw_winctrl_calcsize(unsigned int sizeval) |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 42 | { |
| 43 | int i; |
| 44 | unsigned int j = 0; |
| 45 | u32 val = sizeval >> 1; |
| 46 | |
Prafulla Wadaskar | f9c72f6 | 2010-08-26 14:43:55 +0530 | [diff] [blame] | 47 | for (i = 0; val >= 0x10000; i++) { |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 48 | j |= (1 << i); |
| 49 | val = val >> 1; |
| 50 | } |
| 51 | return (0x0000ffff & j); |
| 52 | } |
| 53 | |
Pali Rohár | 32301ee | 2022-09-09 14:41:28 +0200 | [diff] [blame] | 54 | static const struct mbus_win windows[] = { |
Chris Packham | 968856c | 2019-03-13 20:47:03 +1300 | [diff] [blame] | 55 | /* Window 0: PCIE MEM address space */ |
Pali Rohár | ed9bcb9 | 2022-01-13 14:28:04 +0100 | [diff] [blame] | 56 | { KW_DEFADR_PCI_MEM, KW_DEFADR_PCI_MEM_SIZE, |
Chris Packham | 968856c | 2019-03-13 20:47:03 +1300 | [diff] [blame] | 57 | KWCPU_TARGET_PCIE, KWCPU_ATTR_PCIE_MEM }, |
| 58 | |
| 59 | /* Window 1: PCIE IO address space */ |
Pali Rohár | ed9bcb9 | 2022-01-13 14:28:04 +0100 | [diff] [blame] | 60 | { KW_DEFADR_PCI_IO, KW_DEFADR_PCI_IO_SIZE, |
Chris Packham | 968856c | 2019-03-13 20:47:03 +1300 | [diff] [blame] | 61 | KWCPU_TARGET_PCIE, KWCPU_ATTR_PCIE_IO }, |
| 62 | |
| 63 | /* Window 2: NAND Flash address space */ |
| 64 | { KW_DEFADR_NANDF, 1024 * 1024 * 128, |
| 65 | KWCPU_TARGET_MEMORY, KWCPU_ATTR_NANDFLASH }, |
| 66 | |
| 67 | /* Window 3: SPI Flash address space */ |
| 68 | { KW_DEFADR_SPIF, 1024 * 1024 * 128, |
| 69 | KWCPU_TARGET_MEMORY, KWCPU_ATTR_SPIFLASH }, |
| 70 | |
| 71 | /* Window 4: BOOT Memory address space */ |
| 72 | { KW_DEFADR_BOOTROM, 1024 * 1024 * 128, |
| 73 | KWCPU_TARGET_MEMORY, KWCPU_ATTR_BOOTROM }, |
| 74 | |
| 75 | /* Window 5: Security SRAM address space */ |
| 76 | { KW_DEFADR_SASRAM, 1024 * 64, |
| 77 | KWCPU_TARGET_SASRAM, KWCPU_ATTR_SASRAM }, |
| 78 | }; |
| 79 | |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 80 | /* |
Prafulla Wadaskar | 2906d77 | 2009-08-20 20:59:28 +0530 | [diff] [blame] | 81 | * SYSRSTn Duration Counter Support |
| 82 | * |
| 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 |
| 94 | */ |
| 95 | static void kw_sysrst_action(void) |
| 96 | { |
| 97 | int ret; |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 98 | char *s = env_get("sysrstcmd"); |
Prafulla Wadaskar | 2906d77 | 2009-08-20 20:59:28 +0530 | [diff] [blame] | 99 | |
| 100 | if (!s) { |
| 101 | debug("Error.. %s failed, check sysrstcmd\n", |
| 102 | __FUNCTION__); |
| 103 | return; |
| 104 | } |
| 105 | |
| 106 | debug("Starting %s process...\n", __FUNCTION__); |
Simon Glass | bf8c5b0 | 2012-02-14 19:59:21 +0000 | [diff] [blame] | 107 | ret = run_command(s, 0); |
Thomas Betker | 5ac0026 | 2014-06-05 20:07:56 +0200 | [diff] [blame] | 108 | if (ret != 0) |
Prafulla Wadaskar | 2906d77 | 2009-08-20 20:59:28 +0530 | [diff] [blame] | 109 | debug("Error.. %s failed\n", __FUNCTION__); |
| 110 | else |
| 111 | debug("%s process finished\n", __FUNCTION__); |
| 112 | } |
| 113 | |
| 114 | static void kw_sysrst_check(void) |
| 115 | { |
| 116 | u32 sysrst_cnt, sysrst_dly; |
| 117 | char *s; |
| 118 | |
| 119 | /* |
| 120 | * no action if sysrstdelay environment variable is not defined |
| 121 | */ |
Simon Glass | 64b723f | 2017-08-03 12:22:12 -0600 | [diff] [blame] | 122 | s = env_get("sysrstdelay"); |
Prafulla Wadaskar | 2906d77 | 2009-08-20 20:59:28 +0530 | [diff] [blame] | 123 | if (s == NULL) |
| 124 | return; |
| 125 | |
| 126 | /* read sysrstdelay value */ |
Simon Glass | ff9b903 | 2021-07-24 09:03:30 -0600 | [diff] [blame] | 127 | sysrst_dly = (u32)dectoul(s, NULL); |
Prafulla Wadaskar | 2906d77 | 2009-08-20 20:59:28 +0530 | [diff] [blame] | 128 | |
| 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); |
| 134 | |
| 135 | /* clear the counter for next valid read*/ |
| 136 | writel(1 << 31, KW_REG_SYSRST_CNT); |
| 137 | |
| 138 | /* |
| 139 | * sysrst_action: |
| 140 | * if H/w Reset key is pressed and hold for time |
| 141 | * more than sysrst_dly in seconds |
| 142 | */ |
| 143 | if (sysrst_cnt >= SYSRST_CNT_1SEC_VAL * sysrst_dly) |
| 144 | kw_sysrst_action(); |
| 145 | } |
| 146 | |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 147 | #if defined(CONFIG_DISPLAY_CPUINFO) |
| 148 | int print_cpuinfo(void) |
| 149 | { |
Luka Perkov | f680edb | 2013-12-23 01:23:07 +0100 | [diff] [blame] | 150 | char *rev = "??"; |
Prafulla Wadaskar | 3149629 | 2010-09-20 17:19:42 +0530 | [diff] [blame] | 151 | u16 devid = (readl(KW_REG_PCIE_DEVID) >> 16) & 0xffff; |
| 152 | u8 revid = readl(KW_REG_PCIE_REVID) & 0xff; |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 153 | |
Prafulla Wadaskar | 3149629 | 2010-09-20 17:19:42 +0530 | [diff] [blame] | 154 | if ((readl(KW_REG_DEVICE_ID) & 0x03) > 2) { |
| 155 | printf("Error.. %s:Unsupported Kirkwood SoC 88F%04x\n", __FUNCTION__, devid); |
| 156 | return -1; |
| 157 | } |
| 158 | |
| 159 | switch (revid) { |
| 160 | case 0: |
Luka Perkov | f680edb | 2013-12-23 01:23:07 +0100 | [diff] [blame] | 161 | if (devid == 0x6281) |
| 162 | rev = "Z0"; |
| 163 | else if (devid == 0x6282) |
| 164 | rev = "A0"; |
| 165 | break; |
| 166 | case 1: |
| 167 | rev = "A1"; |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 168 | break; |
| 169 | case 2: |
Prafulla Wadaskar | 3149629 | 2010-09-20 17:19:42 +0530 | [diff] [blame] | 170 | rev = "A0"; |
| 171 | break; |
| 172 | case 3: |
| 173 | rev = "A1"; |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 174 | break; |
| 175 | default: |
Prafulla Wadaskar | 3149629 | 2010-09-20 17:19:42 +0530 | [diff] [blame] | 176 | break; |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 177 | } |
Prafulla Wadaskar | 3149629 | 2010-09-20 17:19:42 +0530 | [diff] [blame] | 178 | |
| 179 | printf("SoC: Kirkwood 88F%04x_%s\n", devid, rev); |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 180 | return 0; |
| 181 | } |
| 182 | #endif /* CONFIG_DISPLAY_CPUINFO */ |
| 183 | |
| 184 | #ifdef CONFIG_ARCH_CPU_INIT |
| 185 | int arch_cpu_init(void) |
| 186 | { |
| 187 | u32 reg; |
| 188 | struct kwcpu_registers *cpureg = |
| 189 | (struct kwcpu_registers *)KW_CPU_REG_BASE; |
| 190 | |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 191 | /* Enable and invalidate L2 cache in write through mode */ |
| 192 | writel(readl(&cpureg->l2_cfg) | 0x18, &cpureg->l2_cfg); |
| 193 | invalidate_l2_cache(); |
| 194 | |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 195 | #ifdef CONFIG_KIRKWOOD_RGMII_PAD_1V8 |
| 196 | /* |
| 197 | * Configures the I/O voltage of the pads connected to Egigabit |
| 198 | * Ethernet interface to 1.8V |
Robert P. J. Day | 832d36e | 2013-09-16 07:15:45 -0400 | [diff] [blame] | 199 | * By default it is set to 3.3V |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 200 | */ |
| 201 | reg = readl(KW_REG_MPP_OUT_DRV_REG); |
| 202 | reg |= (1 << 7); |
| 203 | writel(reg, KW_REG_MPP_OUT_DRV_REG); |
| 204 | #endif |
| 205 | #ifdef CONFIG_KIRKWOOD_EGIGA_INIT |
| 206 | /* |
| 207 | * Set egiga port0/1 in normal functional mode |
| 208 | * This is required becasue on kirkwood by default ports are in reset mode |
| 209 | * OS egiga driver may not have provision to set them in normal mode |
| 210 | * and if u-boot is build without network support, network may fail at OS level |
| 211 | */ |
| 212 | reg = readl(KWGBE_PORT_SERIAL_CONTROL1_REG(0)); |
| 213 | reg &= ~(1 << 4); /* Clear PortReset Bit */ |
| 214 | writel(reg, (KWGBE_PORT_SERIAL_CONTROL1_REG(0))); |
| 215 | reg = readl(KWGBE_PORT_SERIAL_CONTROL1_REG(1)); |
| 216 | reg &= ~(1 << 4); /* Clear PortReset Bit */ |
| 217 | writel(reg, (KWGBE_PORT_SERIAL_CONTROL1_REG(1))); |
| 218 | #endif |
| 219 | #ifdef CONFIG_KIRKWOOD_PCIE_INIT |
| 220 | /* |
| 221 | * Enable PCI Express Port0 |
| 222 | */ |
| 223 | reg = readl(&cpureg->ctrl_stat); |
| 224 | reg |= (1 << 0); /* Set PEX0En Bit */ |
| 225 | writel(reg, &cpureg->ctrl_stat); |
| 226 | #endif |
| 227 | return 0; |
| 228 | } |
| 229 | #endif /* CONFIG_ARCH_CPU_INIT */ |
| 230 | |
| 231 | /* |
| 232 | * SOC specific misc init |
| 233 | */ |
| 234 | #if defined(CONFIG_ARCH_MISC_INIT) |
| 235 | int arch_misc_init(void) |
| 236 | { |
| 237 | volatile u32 temp; |
| 238 | |
| 239 | /*CPU streaming & write allocate */ |
| 240 | temp = readfr_extra_feature_reg(); |
| 241 | temp &= ~(1 << 28); /* disable wr alloc */ |
| 242 | writefr_extra_feature_reg(temp); |
| 243 | |
| 244 | temp = readfr_extra_feature_reg(); |
| 245 | temp &= ~(1 << 29); /* streaming disabled */ |
| 246 | writefr_extra_feature_reg(temp); |
| 247 | |
| 248 | /* L2Cache settings */ |
| 249 | temp = readfr_extra_feature_reg(); |
| 250 | /* Disable L2C pre fetch - Set bit 24 */ |
| 251 | temp |= (1 << 24); |
| 252 | /* enable L2C - Set bit 22 */ |
| 253 | temp |= (1 << 22); |
| 254 | writefr_extra_feature_reg(temp); |
| 255 | |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 256 | /* Change reset vector to address 0x0 */ |
| 257 | temp = get_cr(); |
| 258 | set_cr(temp & ~CR_V); |
| 259 | |
Chris Packham | 968856c | 2019-03-13 20:47:03 +1300 | [diff] [blame] | 260 | /* Configure mbus windows */ |
| 261 | mvebu_mbus_probe(windows, ARRAY_SIZE(windows)); |
| 262 | |
Prafulla Wadaskar | 2906d77 | 2009-08-20 20:59:28 +0530 | [diff] [blame] | 263 | /* checks and execute resset to factory event */ |
| 264 | kw_sysrst_check(); |
| 265 | |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 266 | return 0; |
| 267 | } |
| 268 | #endif /* CONFIG_ARCH_MISC_INIT */ |
| 269 | |
Albert Aribaud | e91d7d3 | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 270 | #ifdef CONFIG_MVGBE |
Masahiro Yamada | f7ed78b | 2020-06-26 15:13:33 +0900 | [diff] [blame] | 271 | int cpu_eth_init(struct bd_info *bis) |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 272 | { |
Albert Aribaud | e91d7d3 | 2010-07-12 22:24:28 +0200 | [diff] [blame] | 273 | mvgbe_initialize(bis); |
Prafulla Wadaskar | a09bbe5 | 2009-06-20 11:01:53 +0200 | [diff] [blame] | 274 | return 0; |
| 275 | } |
| 276 | #endif |