blob: 531d0fb44cdb8c2061abe4ef03a1f91f867c27fe [file] [log] [blame]
Stefan Roese41e5ee52014-10-22 12:13:17 +02001/*
Stefan Roese9c6d3b72015-04-25 06:29:51 +02002 * Copyright (C) 2014-2015 Stefan Roese <sr@denx.de>
Stefan Roese41e5ee52014-10-22 12:13:17 +02003 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <netdev.h>
9#include <asm/io.h>
Stefan Roese57303602015-05-18 16:09:43 +000010#include <asm/pl310.h>
Stefan Roese41e5ee52014-10-22 12:13:17 +020011#include <asm/arch/cpu.h>
12#include <asm/arch/soc.h>
Stefan Roese7f1adcd2015-06-29 14:58:10 +020013#include <sdhci.h>
Stefan Roese41e5ee52014-10-22 12:13:17 +020014
15#define DDR_BASE_CS_OFF(n) (0x0000 + ((n) << 3))
16#define DDR_SIZE_CS_OFF(n) (0x0004 + ((n) << 3))
17
18static struct mbus_win windows[] = {
19 /* PCIE MEM address space */
20 { DEFADR_PCI_MEM, 256 << 20, CPU_TARGET_PCIE13, CPU_ATTR_PCIE_MEM },
21
22 /* PCIE IO address space */
23 { DEFADR_PCI_IO, 64 << 10, CPU_TARGET_PCIE13, CPU_ATTR_PCIE_IO },
24
25 /* SPI */
26 { DEFADR_SPIF, 8 << 20, CPU_TARGET_DEVICEBUS_BOOTROM_SPI,
27 CPU_ATTR_SPIFLASH },
28
29 /* NOR */
30 { DEFADR_BOOTROM, 8 << 20, CPU_TARGET_DEVICEBUS_BOOTROM_SPI,
31 CPU_ATTR_BOOTROM },
32};
33
34void reset_cpu(unsigned long ignored)
35{
36 struct mvebu_system_registers *reg =
37 (struct mvebu_system_registers *)MVEBU_SYSTEM_REG_BASE;
38
39 writel(readl(&reg->rstoutn_mask) | 1, &reg->rstoutn_mask);
40 writel(readl(&reg->sys_soft_rst) | 1, &reg->sys_soft_rst);
41 while (1)
42 ;
43}
44
Stefan Roese9c6d3b72015-04-25 06:29:51 +020045int mvebu_soc_family(void)
46{
47 u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
48
49 if (devid == SOC_MV78460_ID)
50 return MVEBU_SOC_AXP;
51
52 if (devid == SOC_88F6810_ID || devid == SOC_88F6820_ID ||
53 devid == SOC_88F6828_ID)
54 return MVEBU_SOC_A38X;
55
56 return MVEBU_SOC_UNKNOWN;
57}
58
Stefan Roese41e5ee52014-10-22 12:13:17 +020059#if defined(CONFIG_DISPLAY_CPUINFO)
60int print_cpuinfo(void)
61{
62 u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
63 u8 revid = readl(MVEBU_REG_PCIE_REVID) & 0xff;
64
65 puts("SoC: ");
66
67 switch (devid) {
68 case SOC_MV78460_ID:
69 puts("MV78460-");
70 break;
Stefan Roese9c6d3b72015-04-25 06:29:51 +020071 case SOC_88F6810_ID:
72 puts("MV88F6810-");
73 break;
74 case SOC_88F6820_ID:
75 puts("MV88F6820-");
76 break;
77 case SOC_88F6828_ID:
78 puts("MV88F6828-");
79 break;
Stefan Roese41e5ee52014-10-22 12:13:17 +020080 default:
81 puts("Unknown-");
82 break;
83 }
84
Stefan Roese9c6d3b72015-04-25 06:29:51 +020085 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
86 switch (revid) {
87 case 1:
88 puts("A0\n");
89 break;
90 case 2:
91 puts("B0\n");
92 break;
93 default:
94 printf("?? (%x)\n", revid);
95 break;
96 }
97 }
98
99 if (mvebu_soc_family() == MVEBU_SOC_A38X) {
100 switch (revid) {
101 case MV_88F68XX_Z1_ID:
102 puts("Z1\n");
103 break;
104 case MV_88F68XX_A0_ID:
105 puts("A0\n");
106 break;
107 default:
108 printf("?? (%x)\n", revid);
109 break;
110 }
Stefan Roese41e5ee52014-10-22 12:13:17 +0200111 }
112
113 return 0;
114}
115#endif /* CONFIG_DISPLAY_CPUINFO */
116
117/*
118 * This function initialize Controller DRAM Fastpath windows.
119 * It takes the CS size information from the 0x1500 scratch registers
120 * and sets the correct windows sizes and base addresses accordingly.
121 *
122 * These values are set in the scratch registers by the Marvell
123 * DDR3 training code, which is executed by the BootROM before the
124 * main payload (U-Boot) is executed. This training code is currently
125 * only available in the Marvell U-Boot version. It needs to be
126 * ported to mainline U-Boot SPL at some point.
127 */
128static void update_sdram_window_sizes(void)
129{
130 u64 base = 0;
131 u32 size, temp;
132 int i;
133
134 for (i = 0; i < SDRAM_MAX_CS; i++) {
135 size = readl((MVEBU_SDRAM_SCRATCH + (i * 8))) & SDRAM_ADDR_MASK;
136 if (size != 0) {
137 size |= ~(SDRAM_ADDR_MASK);
138
139 /* Set Base Address */
140 temp = (base & 0xFF000000ll) | ((base >> 32) & 0xF);
141 writel(temp, MVEBU_SDRAM_BASE + DDR_BASE_CS_OFF(i));
142
143 /*
144 * Check if out of max window size and resize
145 * the window
146 */
147 temp = (readl(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i)) &
148 ~(SDRAM_ADDR_MASK)) | 1;
149 temp |= (size & SDRAM_ADDR_MASK);
150 writel(temp, MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i));
151
152 base += ((u64)size + 1);
153 } else {
154 /*
155 * Disable window if not used, otherwise this
156 * leads to overlapping enabled windows with
157 * pretty strange results
158 */
159 clrbits_le32(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i), 1);
160 }
161 }
162}
163
164#ifdef CONFIG_ARCH_CPU_INIT
Kevin Smithe1b078e2015-05-18 16:09:44 +0000165static void set_cbar(u32 addr)
166{
167 asm("mcr p15, 4, %0, c15, c0" : : "r" (addr));
168}
169
170
Stefan Roese41e5ee52014-10-22 12:13:17 +0200171int arch_cpu_init(void)
172{
173 /* Linux expects the internal registers to be at 0xf1000000 */
174 writel(SOC_REGS_PHY_BASE, INTREG_BASE_ADDR_REG);
Kevin Smithe1b078e2015-05-18 16:09:44 +0000175 set_cbar(SOC_REGS_PHY_BASE + 0xC000);
Stefan Roese41e5ee52014-10-22 12:13:17 +0200176
177 /*
178 * We need to call mvebu_mbus_probe() before calling
179 * update_sdram_window_sizes() as it disables all previously
180 * configured mbus windows and then configures them as
181 * required for U-Boot. Calling update_sdram_window_sizes()
182 * without this configuration will not work, as the internal
183 * registers can't be accessed reliably because of potenial
184 * double mapping.
185 * After updating the SDRAM access windows we need to call
186 * mvebu_mbus_probe() again, as this now correctly configures
187 * the SDRAM areas that are later used by the MVEBU drivers
188 * (e.g. USB, NETA).
189 */
190
191 /*
192 * First disable all windows
193 */
194 mvebu_mbus_probe(NULL, 0);
195
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200196 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
197 /*
198 * Now the SDRAM access windows can be reconfigured using
199 * the information in the SDRAM scratch pad registers
200 */
201 update_sdram_window_sizes();
202 }
Stefan Roese41e5ee52014-10-22 12:13:17 +0200203
204 /*
205 * Finally the mbus windows can be configured with the
206 * updated SDRAM sizes
207 */
208 mvebu_mbus_probe(windows, ARRAY_SIZE(windows));
209
210 return 0;
211}
212#endif /* CONFIG_ARCH_CPU_INIT */
213
214/*
215 * SOC specific misc init
216 */
217#if defined(CONFIG_ARCH_MISC_INIT)
218int arch_misc_init(void)
219{
220 /* Nothing yet, perhaps we need something here later */
221 return 0;
222}
223#endif /* CONFIG_ARCH_MISC_INIT */
224
225#ifdef CONFIG_MVNETA
226int cpu_eth_init(bd_t *bis)
227{
Stefan Roesecae90082015-04-25 06:29:52 +0200228 u32 enet_base[] = { MVEBU_EGIGA0_BASE, MVEBU_EGIGA1_BASE,
229 MVEBU_EGIGA2_BASE, MVEBU_EGIGA3_BASE };
230 u8 phy_addr[] = CONFIG_PHY_ADDR;
231 int i;
232
233 /*
234 * Only Armada XP supports all 4 ethernet interfaces. A38x has
235 * slightly different base addresses for its 2-3 interfaces.
236 */
237 if (mvebu_soc_family() != MVEBU_SOC_AXP) {
238 enet_base[1] = MVEBU_EGIGA2_BASE;
239 enet_base[2] = MVEBU_EGIGA3_BASE;
240 }
241
242 for (i = 0; i < ARRAY_SIZE(phy_addr); i++)
243 mvneta_initialize(bis, enet_base[i], i, phy_addr[i]);
Stefan Roese41e5ee52014-10-22 12:13:17 +0200244
245 return 0;
246}
247#endif
248
Stefan Roese7f1adcd2015-06-29 14:58:10 +0200249#ifdef CONFIG_MV_SDHCI
250int board_mmc_init(bd_t *bis)
251{
252 mv_sdh_init(MVEBU_SDIO_BASE, 0, 0,
253 SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_WAIT_SEND_CMD);
254
255 return 0;
256}
257#endif
258
Stefan Roese41e5ee52014-10-22 12:13:17 +0200259#ifndef CONFIG_SYS_DCACHE_OFF
260void enable_caches(void)
261{
Stefan Roese57303602015-05-18 16:09:43 +0000262 struct pl310_regs *const pl310 =
263 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
264
265 /* First disable L2 cache - may still be enable from BootROM */
266 if (mvebu_soc_family() == MVEBU_SOC_A38X)
267 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
268
Stefan Roese60b75322015-04-25 06:29:55 +0200269 /* Avoid problem with e.g. neta ethernet driver */
270 invalidate_dcache_all();
271
Stefan Roese41e5ee52014-10-22 12:13:17 +0200272 /* Enable D-cache. I-cache is already enabled in start.S */
273 dcache_enable();
274}
275#endif