rockchip: TPL banner should depend on CONFIG_TPL_BANNER_PRINT
[oweals/u-boot.git] / arch / arm / mach-kirkwood / cpu.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2009
4  * Marvell Semiconductor <www.marvell.com>
5  * Written-by: Prafulla Wadaskar <prafulla@marvell.com>
6  */
7
8 #include <common.h>
9 #include <netdev.h>
10 #include <asm/cache.h>
11 #include <asm/io.h>
12 #include <asm/arch/cpu.h>
13 #include <asm/arch/soc.h>
14 #include <mvebu_mmc.h>
15
16 void 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 /*
29  * 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  */
36 unsigned int kw_winctrl_calcsize(unsigned int sizeval)
37 {
38         int i;
39         unsigned int j = 0;
40         u32 val = sizeval >> 1;
41
42         for (i = 0; val >= 0x10000; i++) {
43                 j |= (1 << i);
44                 val = val >> 1;
45         }
46         return (0x0000ffff & j);
47 }
48
49 static 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
75 /*
76  * 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  */
90 static void kw_sysrst_action(void)
91 {
92         int ret;
93         char *s = env_get("sysrstcmd");
94
95         if (!s) {
96                 debug("Error.. %s failed, check sysrstcmd\n",
97                         __FUNCTION__);
98                 return;
99         }
100
101         debug("Starting %s process...\n", __FUNCTION__);
102         ret = run_command(s, 0);
103         if (ret != 0)
104                 debug("Error.. %s failed\n", __FUNCTION__);
105         else
106                 debug("%s process finished\n", __FUNCTION__);
107 }
108
109 static 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          */
117         s = env_get("sysrstdelay");
118         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
142 #if defined(CONFIG_DISPLAY_CPUINFO)
143 int print_cpuinfo(void)
144 {
145         char *rev = "??";
146         u16 devid = (readl(KW_REG_PCIE_DEVID) >> 16) & 0xffff;
147         u8 revid = readl(KW_REG_PCIE_REVID) & 0xff;
148
149         if ((readl(KW_REG_DEVICE_ID) & 0x03) > 2) {
150                 printf("Error.. %s:Unsupported Kirkwood SoC 88F%04x\n", __FUNCTION__, devid);
151                 return -1;
152         }
153
154         switch (revid) {
155         case 0:
156                 if (devid == 0x6281)
157                         rev = "Z0";
158                 else if (devid == 0x6282)
159                         rev = "A0";
160                 break;
161         case 1:
162                 rev = "A1";
163                 break;
164         case 2:
165                 rev = "A0";
166                 break;
167         case 3:
168                 rev = "A1";
169                 break;
170         default:
171                 break;
172         }
173
174         printf("SoC:   Kirkwood 88F%04x_%s\n", devid, rev);
175         return 0;
176 }
177 #endif /* CONFIG_DISPLAY_CPUINFO */
178
179 #ifdef CONFIG_ARCH_CPU_INIT
180 int arch_cpu_init(void)
181 {
182         u32 reg;
183         struct kwcpu_registers *cpureg =
184                 (struct kwcpu_registers *)KW_CPU_REG_BASE;
185
186         /* Linux expects the internal registers to be at 0xf1000000 */
187         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
193 #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
197          * By default it is set to 3.3V
198          */
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)
233 int 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
254         /* Change reset vector to address 0x0 */
255         temp = get_cr();
256         set_cr(temp & ~CR_V);
257
258         /* Configure mbus windows */
259         mvebu_mbus_probe(windows, ARRAY_SIZE(windows));
260
261         /* checks and execute resset to factory event */
262         kw_sysrst_check();
263
264         return 0;
265 }
266 #endif /* CONFIG_ARCH_MISC_INIT */
267
268 #ifdef CONFIG_MVGBE
269 int cpu_eth_init(bd_t *bis)
270 {
271         mvgbe_initialize(bis);
272         return 0;
273 }
274 #endif
275
276 #ifdef CONFIG_MVEBU_MMC
277 int board_mmc_init(bd_t *bis)
278 {
279         mvebu_mmc_init(bis);
280         return 0;
281 }
282 #endif /* CONFIG_MVEBU_MMC */