1350b50eeSStefan Roese /*
2d35831f6SStefan Roese * Copyright (C) 2014-2016 Stefan Roese <sr@denx.de>
3350b50eeSStefan Roese *
4350b50eeSStefan Roese * SPDX-License-Identifier: GPL-2.0+
5350b50eeSStefan Roese */
6350b50eeSStefan Roese
7350b50eeSStefan Roese #include <common.h>
84d991cb3SStefan Roese #include <ahci.h>
94d991cb3SStefan Roese #include <linux/mbus.h>
10350b50eeSStefan Roese #include <asm/io.h>
115730360eSStefan Roese #include <asm/pl310.h>
12350b50eeSStefan Roese #include <asm/arch/cpu.h>
13350b50eeSStefan Roese #include <asm/arch/soc.h>
147f1adcd7SStefan Roese #include <sdhci.h>
15350b50eeSStefan Roese
16350b50eeSStefan Roese #define DDR_BASE_CS_OFF(n) (0x0000 + ((n) << 3))
17350b50eeSStefan Roese #define DDR_SIZE_CS_OFF(n) (0x0004 + ((n) << 3))
18350b50eeSStefan Roese
19350b50eeSStefan Roese static struct mbus_win windows[] = {
20350b50eeSStefan Roese /* SPI */
218ed20d65SStefan Roese { MBUS_SPI_BASE, MBUS_SPI_SIZE,
228ed20d65SStefan Roese CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_SPIFLASH },
23350b50eeSStefan Roese
24350b50eeSStefan Roese /* NOR */
258ed20d65SStefan Roese { MBUS_BOOTROM_BASE, MBUS_BOOTROM_SIZE,
268ed20d65SStefan Roese CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_BOOTROM },
27350b50eeSStefan Roese };
28350b50eeSStefan Roese
lowlevel_init(void)2942cc034fSStefan Roese void lowlevel_init(void)
3042cc034fSStefan Roese {
3142cc034fSStefan Roese /*
3242cc034fSStefan Roese * Dummy implementation, we only need LOWLEVEL_INIT
3342cc034fSStefan Roese * on Armada to configure CP15 in start.S / cpu_init_cp15()
3442cc034fSStefan Roese */
3542cc034fSStefan Roese }
3642cc034fSStefan Roese
reset_cpu(unsigned long ignored)37350b50eeSStefan Roese void reset_cpu(unsigned long ignored)
38350b50eeSStefan Roese {
39350b50eeSStefan Roese struct mvebu_system_registers *reg =
40350b50eeSStefan Roese (struct mvebu_system_registers *)MVEBU_SYSTEM_REG_BASE;
41350b50eeSStefan Roese
42350b50eeSStefan Roese writel(readl(®->rstoutn_mask) | 1, ®->rstoutn_mask);
43350b50eeSStefan Roese writel(readl(®->sys_soft_rst) | 1, ®->sys_soft_rst);
44350b50eeSStefan Roese while (1)
45350b50eeSStefan Roese ;
46350b50eeSStefan Roese }
47350b50eeSStefan Roese
mvebu_soc_family(void)489c6d3b7bSStefan Roese int mvebu_soc_family(void)
499c6d3b7bSStefan Roese {
509c6d3b7bSStefan Roese u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
519c6d3b7bSStefan Roese
526202953dSPhil Sutter switch (devid) {
536202953dSPhil Sutter case SOC_MV78230_ID:
546202953dSPhil Sutter case SOC_MV78260_ID:
556202953dSPhil Sutter case SOC_MV78460_ID:
569c6d3b7bSStefan Roese return MVEBU_SOC_AXP;
5709e89ab4SStefan Roese
5809e89ab4SStefan Roese case SOC_88F6720_ID:
5909e89ab4SStefan Roese return MVEBU_SOC_A375;
6009e89ab4SStefan Roese
616202953dSPhil Sutter case SOC_88F6810_ID:
626202953dSPhil Sutter case SOC_88F6820_ID:
636202953dSPhil Sutter case SOC_88F6828_ID:
649c6d3b7bSStefan Roese return MVEBU_SOC_A38X;
656202953dSPhil Sutter }
6609e89ab4SStefan Roese
679c6d3b7bSStefan Roese return MVEBU_SOC_UNKNOWN;
689c6d3b7bSStefan Roese }
699c6d3b7bSStefan Roese
70350b50eeSStefan Roese #if defined(CONFIG_DISPLAY_CPUINFO)
71d718bf2cSStefan Roese
7209e89ab4SStefan Roese #if defined(CONFIG_ARMADA_375)
7309e89ab4SStefan Roese /* SAR frequency values for Armada 375 */
7409e89ab4SStefan Roese static const struct sar_freq_modes sar_freq_tab[] = {
7509e89ab4SStefan Roese { 0, 0x0, 266, 133, 266 },
7609e89ab4SStefan Roese { 1, 0x0, 333, 167, 167 },
7709e89ab4SStefan Roese { 2, 0x0, 333, 167, 222 },
7809e89ab4SStefan Roese { 3, 0x0, 333, 167, 333 },
7909e89ab4SStefan Roese { 4, 0x0, 400, 200, 200 },
8009e89ab4SStefan Roese { 5, 0x0, 400, 200, 267 },
8109e89ab4SStefan Roese { 6, 0x0, 400, 200, 400 },
8209e89ab4SStefan Roese { 7, 0x0, 500, 250, 250 },
8309e89ab4SStefan Roese { 8, 0x0, 500, 250, 334 },
8409e89ab4SStefan Roese { 9, 0x0, 500, 250, 500 },
8509e89ab4SStefan Roese { 10, 0x0, 533, 267, 267 },
8609e89ab4SStefan Roese { 11, 0x0, 533, 267, 356 },
8709e89ab4SStefan Roese { 12, 0x0, 533, 267, 533 },
8809e89ab4SStefan Roese { 13, 0x0, 600, 300, 300 },
8909e89ab4SStefan Roese { 14, 0x0, 600, 300, 400 },
9009e89ab4SStefan Roese { 15, 0x0, 600, 300, 600 },
9109e89ab4SStefan Roese { 16, 0x0, 666, 333, 333 },
9209e89ab4SStefan Roese { 17, 0x0, 666, 333, 444 },
9309e89ab4SStefan Roese { 18, 0x0, 666, 333, 666 },
9409e89ab4SStefan Roese { 19, 0x0, 800, 400, 267 },
9509e89ab4SStefan Roese { 20, 0x0, 800, 400, 400 },
9609e89ab4SStefan Roese { 21, 0x0, 800, 400, 534 },
9709e89ab4SStefan Roese { 22, 0x0, 900, 450, 300 },
9809e89ab4SStefan Roese { 23, 0x0, 900, 450, 450 },
9909e89ab4SStefan Roese { 24, 0x0, 900, 450, 600 },
10009e89ab4SStefan Roese { 25, 0x0, 1000, 500, 500 },
10109e89ab4SStefan Roese { 26, 0x0, 1000, 500, 667 },
10209e89ab4SStefan Roese { 27, 0x0, 1000, 333, 500 },
10309e89ab4SStefan Roese { 28, 0x0, 400, 400, 400 },
10409e89ab4SStefan Roese { 29, 0x0, 1100, 550, 550 },
10509e89ab4SStefan Roese { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
10609e89ab4SStefan Roese };
10709e89ab4SStefan Roese #elif defined(CONFIG_ARMADA_38X)
108d35831f6SStefan Roese /* SAR frequency values for Armada 38x */
109a9fc5a24SStefan Roese static const struct sar_freq_modes sar_freq_tab[] = {
110d718bf2cSStefan Roese { 0x0, 0x0, 666, 333, 333 },
111d718bf2cSStefan Roese { 0x2, 0x0, 800, 400, 400 },
112d718bf2cSStefan Roese { 0x4, 0x0, 1066, 533, 533 },
113d718bf2cSStefan Roese { 0x6, 0x0, 1200, 600, 600 },
114d718bf2cSStefan Roese { 0x8, 0x0, 1332, 666, 666 },
115d718bf2cSStefan Roese { 0xc, 0x0, 1600, 800, 800 },
116d718bf2cSStefan Roese { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
117d718bf2cSStefan Roese };
118d718bf2cSStefan Roese #else
119d35831f6SStefan Roese /* SAR frequency values for Armada XP */
120a9fc5a24SStefan Roese static const struct sar_freq_modes sar_freq_tab[] = {
121d718bf2cSStefan Roese { 0xa, 0x5, 800, 400, 400 },
122d718bf2cSStefan Roese { 0x1, 0x5, 1066, 533, 533 },
123d718bf2cSStefan Roese { 0x2, 0x5, 1200, 600, 600 },
124d718bf2cSStefan Roese { 0x2, 0x9, 1200, 600, 400 },
125d718bf2cSStefan Roese { 0x3, 0x5, 1333, 667, 667 },
126d718bf2cSStefan Roese { 0x4, 0x5, 1500, 750, 750 },
127d718bf2cSStefan Roese { 0x4, 0x9, 1500, 750, 500 },
128d718bf2cSStefan Roese { 0xb, 0x9, 1600, 800, 533 },
129d718bf2cSStefan Roese { 0xb, 0xa, 1600, 800, 640 },
130d718bf2cSStefan Roese { 0xb, 0x5, 1600, 800, 800 },
131d718bf2cSStefan Roese { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
132d718bf2cSStefan Roese };
133d718bf2cSStefan Roese #endif
134d718bf2cSStefan Roese
get_sar_freq(struct sar_freq_modes * sar_freq)135d718bf2cSStefan Roese void get_sar_freq(struct sar_freq_modes *sar_freq)
136d718bf2cSStefan Roese {
137d718bf2cSStefan Roese u32 val;
138d718bf2cSStefan Roese u32 freq;
139d718bf2cSStefan Roese int i;
140d718bf2cSStefan Roese
14109e89ab4SStefan Roese #if defined(CONFIG_ARMADA_375)
14209e89ab4SStefan Roese val = readl(CONFIG_SAR2_REG); /* SAR - Sample At Reset */
14309e89ab4SStefan Roese #else
144d718bf2cSStefan Roese val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */
14509e89ab4SStefan Roese #endif
146d718bf2cSStefan Roese freq = (val & SAR_CPU_FREQ_MASK) >> SAR_CPU_FREQ_OFFS;
14709e89ab4SStefan Roese #if defined(SAR2_CPU_FREQ_MASK)
148d718bf2cSStefan Roese /*
149d718bf2cSStefan Roese * Shift CPU0 clock frequency select bit from SAR2 register
150d718bf2cSStefan Roese * into correct position
151d718bf2cSStefan Roese */
152d718bf2cSStefan Roese freq |= ((readl(CONFIG_SAR2_REG) & SAR2_CPU_FREQ_MASK)
153d718bf2cSStefan Roese >> SAR2_CPU_FREQ_OFFS) << 3;
154d718bf2cSStefan Roese #endif
155d718bf2cSStefan Roese for (i = 0; sar_freq_tab[i].val != 0xff; i++) {
156d718bf2cSStefan Roese if (sar_freq_tab[i].val == freq) {
15709e89ab4SStefan Roese #if defined(CONFIG_ARMADA_375) || defined(CONFIG_ARMADA_38X)
158d718bf2cSStefan Roese *sar_freq = sar_freq_tab[i];
159d718bf2cSStefan Roese return;
160d718bf2cSStefan Roese #else
161d718bf2cSStefan Roese int k;
162d718bf2cSStefan Roese u8 ffc;
163d718bf2cSStefan Roese
164d718bf2cSStefan Roese ffc = (val & SAR_FFC_FREQ_MASK) >>
165d718bf2cSStefan Roese SAR_FFC_FREQ_OFFS;
166d718bf2cSStefan Roese for (k = i; sar_freq_tab[k].ffc != 0xff; k++) {
167d718bf2cSStefan Roese if (sar_freq_tab[k].ffc == ffc) {
168d718bf2cSStefan Roese *sar_freq = sar_freq_tab[k];
169d718bf2cSStefan Roese return;
170d718bf2cSStefan Roese }
171d718bf2cSStefan Roese }
172d718bf2cSStefan Roese i = k;
173d718bf2cSStefan Roese #endif
174d718bf2cSStefan Roese }
175d718bf2cSStefan Roese }
176d718bf2cSStefan Roese
177d718bf2cSStefan Roese /* SAR value not found, return 0 for frequencies */
178d718bf2cSStefan Roese *sar_freq = sar_freq_tab[i - 1];
179d718bf2cSStefan Roese }
180d718bf2cSStefan Roese
print_cpuinfo(void)181350b50eeSStefan Roese int print_cpuinfo(void)
182350b50eeSStefan Roese {
183350b50eeSStefan Roese u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
184350b50eeSStefan Roese u8 revid = readl(MVEBU_REG_PCIE_REVID) & 0xff;
185d718bf2cSStefan Roese struct sar_freq_modes sar_freq;
186350b50eeSStefan Roese
187350b50eeSStefan Roese puts("SoC: ");
188350b50eeSStefan Roese
189350b50eeSStefan Roese switch (devid) {
1906202953dSPhil Sutter case SOC_MV78230_ID:
1916202953dSPhil Sutter puts("MV78230-");
1926202953dSPhil Sutter break;
193bf0db8b8SStefan Roese case SOC_MV78260_ID:
194bf0db8b8SStefan Roese puts("MV78260-");
195bf0db8b8SStefan Roese break;
196350b50eeSStefan Roese case SOC_MV78460_ID:
197350b50eeSStefan Roese puts("MV78460-");
198350b50eeSStefan Roese break;
19909e89ab4SStefan Roese case SOC_88F6720_ID:
20009e89ab4SStefan Roese puts("MV88F6720-");
20109e89ab4SStefan Roese break;
2029c6d3b7bSStefan Roese case SOC_88F6810_ID:
2039c6d3b7bSStefan Roese puts("MV88F6810-");
2049c6d3b7bSStefan Roese break;
2059c6d3b7bSStefan Roese case SOC_88F6820_ID:
2069c6d3b7bSStefan Roese puts("MV88F6820-");
2079c6d3b7bSStefan Roese break;
2089c6d3b7bSStefan Roese case SOC_88F6828_ID:
2099c6d3b7bSStefan Roese puts("MV88F6828-");
2109c6d3b7bSStefan Roese break;
211350b50eeSStefan Roese default:
212350b50eeSStefan Roese puts("Unknown-");
213350b50eeSStefan Roese break;
214350b50eeSStefan Roese }
215350b50eeSStefan Roese
2169c6d3b7bSStefan Roese if (mvebu_soc_family() == MVEBU_SOC_AXP) {
217350b50eeSStefan Roese switch (revid) {
218350b50eeSStefan Roese case 1:
219d718bf2cSStefan Roese puts("A0");
220350b50eeSStefan Roese break;
221350b50eeSStefan Roese case 2:
222d718bf2cSStefan Roese puts("B0");
223350b50eeSStefan Roese break;
224350b50eeSStefan Roese default:
225d718bf2cSStefan Roese printf("?? (%x)", revid);
226350b50eeSStefan Roese break;
227350b50eeSStefan Roese }
2289c6d3b7bSStefan Roese }
2299c6d3b7bSStefan Roese
23009e89ab4SStefan Roese if (mvebu_soc_family() == MVEBU_SOC_A375) {
23109e89ab4SStefan Roese switch (revid) {
23209e89ab4SStefan Roese case MV_88F67XX_A0_ID:
23309e89ab4SStefan Roese puts("A0");
23409e89ab4SStefan Roese break;
23509e89ab4SStefan Roese default:
23609e89ab4SStefan Roese printf("?? (%x)", revid);
23709e89ab4SStefan Roese break;
23809e89ab4SStefan Roese }
23909e89ab4SStefan Roese }
24009e89ab4SStefan Roese
2419c6d3b7bSStefan Roese if (mvebu_soc_family() == MVEBU_SOC_A38X) {
2429c6d3b7bSStefan Roese switch (revid) {
2439c6d3b7bSStefan Roese case MV_88F68XX_Z1_ID:
244d718bf2cSStefan Roese puts("Z1");
2459c6d3b7bSStefan Roese break;
2469c6d3b7bSStefan Roese case MV_88F68XX_A0_ID:
247d718bf2cSStefan Roese puts("A0");
2489c6d3b7bSStefan Roese break;
2499c6d3b7bSStefan Roese default:
250d718bf2cSStefan Roese printf("?? (%x)", revid);
2519c6d3b7bSStefan Roese break;
2529c6d3b7bSStefan Roese }
2539c6d3b7bSStefan Roese }
254350b50eeSStefan Roese
255d718bf2cSStefan Roese get_sar_freq(&sar_freq);
256d718bf2cSStefan Roese printf(" at %d MHz\n", sar_freq.p_clk);
257d718bf2cSStefan Roese
258350b50eeSStefan Roese return 0;
259350b50eeSStefan Roese }
260350b50eeSStefan Roese #endif /* CONFIG_DISPLAY_CPUINFO */
261350b50eeSStefan Roese
262350b50eeSStefan Roese /*
263350b50eeSStefan Roese * This function initialize Controller DRAM Fastpath windows.
264350b50eeSStefan Roese * It takes the CS size information from the 0x1500 scratch registers
265350b50eeSStefan Roese * and sets the correct windows sizes and base addresses accordingly.
266350b50eeSStefan Roese *
267350b50eeSStefan Roese * These values are set in the scratch registers by the Marvell
268350b50eeSStefan Roese * DDR3 training code, which is executed by the BootROM before the
269350b50eeSStefan Roese * main payload (U-Boot) is executed. This training code is currently
270350b50eeSStefan Roese * only available in the Marvell U-Boot version. It needs to be
271350b50eeSStefan Roese * ported to mainline U-Boot SPL at some point.
272350b50eeSStefan Roese */
update_sdram_window_sizes(void)273350b50eeSStefan Roese static void update_sdram_window_sizes(void)
274350b50eeSStefan Roese {
275350b50eeSStefan Roese u64 base = 0;
276350b50eeSStefan Roese u32 size, temp;
277350b50eeSStefan Roese int i;
278350b50eeSStefan Roese
279350b50eeSStefan Roese for (i = 0; i < SDRAM_MAX_CS; i++) {
280350b50eeSStefan Roese size = readl((MVEBU_SDRAM_SCRATCH + (i * 8))) & SDRAM_ADDR_MASK;
281350b50eeSStefan Roese if (size != 0) {
282350b50eeSStefan Roese size |= ~(SDRAM_ADDR_MASK);
283350b50eeSStefan Roese
284350b50eeSStefan Roese /* Set Base Address */
285350b50eeSStefan Roese temp = (base & 0xFF000000ll) | ((base >> 32) & 0xF);
286350b50eeSStefan Roese writel(temp, MVEBU_SDRAM_BASE + DDR_BASE_CS_OFF(i));
287350b50eeSStefan Roese
288350b50eeSStefan Roese /*
289350b50eeSStefan Roese * Check if out of max window size and resize
290350b50eeSStefan Roese * the window
291350b50eeSStefan Roese */
292350b50eeSStefan Roese temp = (readl(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i)) &
293350b50eeSStefan Roese ~(SDRAM_ADDR_MASK)) | 1;
294350b50eeSStefan Roese temp |= (size & SDRAM_ADDR_MASK);
295350b50eeSStefan Roese writel(temp, MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i));
296350b50eeSStefan Roese
297350b50eeSStefan Roese base += ((u64)size + 1);
298350b50eeSStefan Roese } else {
299350b50eeSStefan Roese /*
300350b50eeSStefan Roese * Disable window if not used, otherwise this
301350b50eeSStefan Roese * leads to overlapping enabled windows with
302350b50eeSStefan Roese * pretty strange results
303350b50eeSStefan Roese */
304350b50eeSStefan Roese clrbits_le32(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i), 1);
305350b50eeSStefan Roese }
306350b50eeSStefan Roese }
307350b50eeSStefan Roese }
308350b50eeSStefan Roese
mmu_disable(void)3099f62b44eSStefan Roese void mmu_disable(void)
3109f62b44eSStefan Roese {
3119f62b44eSStefan Roese asm volatile(
3129f62b44eSStefan Roese "mrc p15, 0, r0, c1, c0, 0\n"
3139f62b44eSStefan Roese "bic r0, #1\n"
3149f62b44eSStefan Roese "mcr p15, 0, r0, c1, c0, 0\n");
3159f62b44eSStefan Roese }
3169f62b44eSStefan Roese
317350b50eeSStefan Roese #ifdef CONFIG_ARCH_CPU_INIT
set_cbar(u32 addr)318e1b078e0SKevin Smith static void set_cbar(u32 addr)
319e1b078e0SKevin Smith {
320e1b078e0SKevin Smith asm("mcr p15, 4, %0, c15, c0" : : "r" (addr));
321e1b078e0SKevin Smith }
322e1b078e0SKevin Smith
323dee40d26SStefan Roese #define MV_USB_PHY_BASE (MVEBU_AXP_USB_BASE + 0x800)
324dee40d26SStefan Roese #define MV_USB_PHY_PLL_REG(reg) (MV_USB_PHY_BASE | (((reg) & 0xF) << 2))
325dee40d26SStefan Roese #define MV_USB_X3_BASE(addr) (MVEBU_AXP_USB_BASE | BIT(11) | \
326dee40d26SStefan Roese (((addr) & 0xF) << 6))
327dee40d26SStefan Roese #define MV_USB_X3_PHY_CHANNEL(dev, reg) (MV_USB_X3_BASE((dev) + 1) | \
328dee40d26SStefan Roese (((reg) & 0xF) << 2))
329dee40d26SStefan Roese
setup_usb_phys(void)330dee40d26SStefan Roese static void setup_usb_phys(void)
331dee40d26SStefan Roese {
332dee40d26SStefan Roese int dev;
333dee40d26SStefan Roese
334dee40d26SStefan Roese /*
335dee40d26SStefan Roese * USB PLL init
336dee40d26SStefan Roese */
337dee40d26SStefan Roese
338dee40d26SStefan Roese /* Setup PLL frequency */
339dee40d26SStefan Roese /* USB REF frequency = 25 MHz */
340dee40d26SStefan Roese clrsetbits_le32(MV_USB_PHY_PLL_REG(1), 0x3ff, 0x605);
341dee40d26SStefan Roese
342dee40d26SStefan Roese /* Power up PLL and PHY channel */
343ab8a4c6aSStefan Roese setbits_le32(MV_USB_PHY_PLL_REG(2), BIT(9));
344dee40d26SStefan Roese
345dee40d26SStefan Roese /* Assert VCOCAL_START */
346ab8a4c6aSStefan Roese setbits_le32(MV_USB_PHY_PLL_REG(1), BIT(21));
347dee40d26SStefan Roese
348dee40d26SStefan Roese mdelay(1);
349dee40d26SStefan Roese
350dee40d26SStefan Roese /*
351dee40d26SStefan Roese * USB PHY init (change from defaults) specific for 40nm (78X30 78X60)
352dee40d26SStefan Roese */
353dee40d26SStefan Roese
354dee40d26SStefan Roese for (dev = 0; dev < 3; dev++) {
355ab8a4c6aSStefan Roese setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 3), BIT(15));
356dee40d26SStefan Roese
357dee40d26SStefan Roese /* Assert REG_RCAL_START in channel REG 1 */
358ab8a4c6aSStefan Roese setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
359dee40d26SStefan Roese udelay(40);
360ab8a4c6aSStefan Roese clrbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
361dee40d26SStefan Roese }
362dee40d26SStefan Roese }
363e1b078e0SKevin Smith
364f4e6ec7dSStefan Roese /*
365f4e6ec7dSStefan Roese * This function is not called from the SPL U-Boot version
366f4e6ec7dSStefan Roese */
arch_cpu_init(void)367350b50eeSStefan Roese int arch_cpu_init(void)
368350b50eeSStefan Roese {
36942cc034fSStefan Roese struct pl310_regs *const pl310 =
37042cc034fSStefan Roese (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
37142cc034fSStefan Roese
3729f62b44eSStefan Roese /*
3739f62b44eSStefan Roese * Only with disabled MMU its possible to switch the base
3749f62b44eSStefan Roese * register address on Armada 38x. Without this the SDRAM
3759f62b44eSStefan Roese * located at >= 0x4000.0000 is also not accessible, as its
3769f62b44eSStefan Roese * still locked to cache.
3779f62b44eSStefan Roese */
3789f62b44eSStefan Roese mmu_disable();
3799f62b44eSStefan Roese
380350b50eeSStefan Roese /* Linux expects the internal registers to be at 0xf1000000 */
381350b50eeSStefan Roese writel(SOC_REGS_PHY_BASE, INTREG_BASE_ADDR_REG);
382e1b078e0SKevin Smith set_cbar(SOC_REGS_PHY_BASE + 0xC000);
383350b50eeSStefan Roese
384cefd7642SStefan Roese /*
385cefd7642SStefan Roese * From this stage on, the SoC detection is working. As we have
386cefd7642SStefan Roese * configured the internal register base to the value used
387cefd7642SStefan Roese * in the macros / defines in the U-Boot header (soc.h).
388cefd7642SStefan Roese */
389cefd7642SStefan Roese
390c86d53fdSStefan Roese if (mvebu_soc_family() == MVEBU_SOC_A38X) {
391cefd7642SStefan Roese /*
392cefd7642SStefan Roese * To fully release / unlock this area from cache, we need
393cefd7642SStefan Roese * to flush all caches and disable the L2 cache.
394cefd7642SStefan Roese */
395cefd7642SStefan Roese icache_disable();
396cefd7642SStefan Roese dcache_disable();
397cefd7642SStefan Roese clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
398c86d53fdSStefan Roese }
399cefd7642SStefan Roese
400350b50eeSStefan Roese /*
401350b50eeSStefan Roese * We need to call mvebu_mbus_probe() before calling
402350b50eeSStefan Roese * update_sdram_window_sizes() as it disables all previously
403350b50eeSStefan Roese * configured mbus windows and then configures them as
404350b50eeSStefan Roese * required for U-Boot. Calling update_sdram_window_sizes()
405350b50eeSStefan Roese * without this configuration will not work, as the internal
406350b50eeSStefan Roese * registers can't be accessed reliably because of potenial
407350b50eeSStefan Roese * double mapping.
408350b50eeSStefan Roese * After updating the SDRAM access windows we need to call
409350b50eeSStefan Roese * mvebu_mbus_probe() again, as this now correctly configures
410350b50eeSStefan Roese * the SDRAM areas that are later used by the MVEBU drivers
411350b50eeSStefan Roese * (e.g. USB, NETA).
412350b50eeSStefan Roese */
413350b50eeSStefan Roese
414350b50eeSStefan Roese /*
415350b50eeSStefan Roese * First disable all windows
416350b50eeSStefan Roese */
417350b50eeSStefan Roese mvebu_mbus_probe(NULL, 0);
418350b50eeSStefan Roese
4199c6d3b7bSStefan Roese if (mvebu_soc_family() == MVEBU_SOC_AXP) {
420350b50eeSStefan Roese /*
421350b50eeSStefan Roese * Now the SDRAM access windows can be reconfigured using
422350b50eeSStefan Roese * the information in the SDRAM scratch pad registers
423350b50eeSStefan Roese */
424350b50eeSStefan Roese update_sdram_window_sizes();
4259c6d3b7bSStefan Roese }
426350b50eeSStefan Roese
427350b50eeSStefan Roese /*
428350b50eeSStefan Roese * Finally the mbus windows can be configured with the
429350b50eeSStefan Roese * updated SDRAM sizes
430350b50eeSStefan Roese */
431350b50eeSStefan Roese mvebu_mbus_probe(windows, ARRAY_SIZE(windows));
432350b50eeSStefan Roese
4332a0b7dc3SStefan Roese if (mvebu_soc_family() == MVEBU_SOC_AXP) {
4342a0b7dc3SStefan Roese /* Enable GBE0, GBE1, LCD and NFC PUP */
4352a0b7dc3SStefan Roese clrsetbits_le32(ARMADA_XP_PUP_ENABLE, 0,
4362a0b7dc3SStefan Roese GE0_PUP_EN | GE1_PUP_EN | LCD_PUP_EN |
4372a0b7dc3SStefan Roese NAND_PUP_EN | SPI_PUP_EN);
438dee40d26SStefan Roese
439dee40d26SStefan Roese /* Configure USB PLL and PHYs on AXP */
440dee40d26SStefan Roese setup_usb_phys();
4412a0b7dc3SStefan Roese }
4422a0b7dc3SStefan Roese
4432a0b7dc3SStefan Roese /* Enable NAND and NAND arbiter */
4442a0b7dc3SStefan Roese clrsetbits_le32(MVEBU_SOC_DEV_MUX_REG, 0, NAND_EN | NAND_ARBITER_EN);
4452a0b7dc3SStefan Roese
446501c098aSStefan Roese /* Disable MBUS error propagation */
447501c098aSStefan Roese clrsetbits_le32(SOC_COHERENCY_FABRIC_CTRL_REG, MBUS_ERR_PROP_EN, 0);
448501c098aSStefan Roese
449350b50eeSStefan Roese return 0;
450350b50eeSStefan Roese }
451350b50eeSStefan Roese #endif /* CONFIG_ARCH_CPU_INIT */
452350b50eeSStefan Roese
mvebu_get_nand_clock(void)4532a0b7dc3SStefan Roese u32 mvebu_get_nand_clock(void)
4542a0b7dc3SStefan Roese {
455d7b4731eSChris Packham u32 reg;
456d7b4731eSChris Packham
457d7b4731eSChris Packham if (mvebu_soc_family() == MVEBU_SOC_A38X)
458d7b4731eSChris Packham reg = MVEBU_DFX_DIV_CLK_CTRL(1);
459d7b4731eSChris Packham else
460d7b4731eSChris Packham reg = MVEBU_CORE_DIV_CLK_CTRL(1);
461d7b4731eSChris Packham
4622a0b7dc3SStefan Roese return CONFIG_SYS_MVEBU_PLL_CLOCK /
463d7b4731eSChris Packham ((readl(reg) &
4642a0b7dc3SStefan Roese NAND_ECC_DIVCKL_RATIO_MASK) >> NAND_ECC_DIVCKL_RATIO_OFFS);
4652a0b7dc3SStefan Roese }
4662a0b7dc3SStefan Roese
467350b50eeSStefan Roese /*
468350b50eeSStefan Roese * SOC specific misc init
469350b50eeSStefan Roese */
470350b50eeSStefan Roese #if defined(CONFIG_ARCH_MISC_INIT)
arch_misc_init(void)471350b50eeSStefan Roese int arch_misc_init(void)
472350b50eeSStefan Roese {
473350b50eeSStefan Roese /* Nothing yet, perhaps we need something here later */
474350b50eeSStefan Roese return 0;
475350b50eeSStefan Roese }
476350b50eeSStefan Roese #endif /* CONFIG_ARCH_MISC_INIT */
477350b50eeSStefan Roese
478*45a68fe2SMasahiro Yamada #ifdef CONFIG_MMC_SDHCI_MV
board_mmc_init(bd_t * bis)4797f1adcd7SStefan Roese int board_mmc_init(bd_t *bis)
4807f1adcd7SStefan Roese {
4817f1adcd7SStefan Roese mv_sdh_init(MVEBU_SDIO_BASE, 0, 0,
4827f1adcd7SStefan Roese SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_WAIT_SEND_CMD);
4837f1adcd7SStefan Roese
4847f1adcd7SStefan Roese return 0;
4857f1adcd7SStefan Roese }
4867f1adcd7SStefan Roese #endif
4877f1adcd7SStefan Roese
4884d991cb3SStefan Roese #ifdef CONFIG_SCSI_AHCI_PLAT
4894d991cb3SStefan Roese #define AHCI_VENDOR_SPECIFIC_0_ADDR 0xa0
4904d991cb3SStefan Roese #define AHCI_VENDOR_SPECIFIC_0_DATA 0xa4
4914d991cb3SStefan Roese
4924d991cb3SStefan Roese #define AHCI_WINDOW_CTRL(win) (0x60 + ((win) << 4))
4934d991cb3SStefan Roese #define AHCI_WINDOW_BASE(win) (0x64 + ((win) << 4))
4944d991cb3SStefan Roese #define AHCI_WINDOW_SIZE(win) (0x68 + ((win) << 4))
4954d991cb3SStefan Roese
ahci_mvebu_mbus_config(void __iomem * base)4964d991cb3SStefan Roese static void ahci_mvebu_mbus_config(void __iomem *base)
4974d991cb3SStefan Roese {
4984d991cb3SStefan Roese const struct mbus_dram_target_info *dram;
4994d991cb3SStefan Roese int i;
5004d991cb3SStefan Roese
5014d991cb3SStefan Roese dram = mvebu_mbus_dram_info();
5024d991cb3SStefan Roese
5034d991cb3SStefan Roese for (i = 0; i < 4; i++) {
5044d991cb3SStefan Roese writel(0, base + AHCI_WINDOW_CTRL(i));
5054d991cb3SStefan Roese writel(0, base + AHCI_WINDOW_BASE(i));
5064d991cb3SStefan Roese writel(0, base + AHCI_WINDOW_SIZE(i));
5074d991cb3SStefan Roese }
5084d991cb3SStefan Roese
5094d991cb3SStefan Roese for (i = 0; i < dram->num_cs; i++) {
5104d991cb3SStefan Roese const struct mbus_dram_window *cs = dram->cs + i;
5114d991cb3SStefan Roese
5124d991cb3SStefan Roese writel((cs->mbus_attr << 8) |
5134d991cb3SStefan Roese (dram->mbus_dram_target_id << 4) | 1,
5144d991cb3SStefan Roese base + AHCI_WINDOW_CTRL(i));
5154d991cb3SStefan Roese writel(cs->base >> 16, base + AHCI_WINDOW_BASE(i));
5164d991cb3SStefan Roese writel(((cs->size - 1) & 0xffff0000),
5174d991cb3SStefan Roese base + AHCI_WINDOW_SIZE(i));
5184d991cb3SStefan Roese }
5194d991cb3SStefan Roese }
5204d991cb3SStefan Roese
ahci_mvebu_regret_option(void __iomem * base)5214d991cb3SStefan Roese static void ahci_mvebu_regret_option(void __iomem *base)
5224d991cb3SStefan Roese {
5234d991cb3SStefan Roese /*
5244d991cb3SStefan Roese * Enable the regret bit to allow the SATA unit to regret a
5254d991cb3SStefan Roese * request that didn't receive an acknowlegde and avoid a
5264d991cb3SStefan Roese * deadlock
5274d991cb3SStefan Roese */
5284d991cb3SStefan Roese writel(0x4, base + AHCI_VENDOR_SPECIFIC_0_ADDR);
5294d991cb3SStefan Roese writel(0x80, base + AHCI_VENDOR_SPECIFIC_0_DATA);
5304d991cb3SStefan Roese }
5314d991cb3SStefan Roese
scsi_init(void)5324d991cb3SStefan Roese void scsi_init(void)
5334d991cb3SStefan Roese {
5344d991cb3SStefan Roese printf("MVEBU SATA INIT\n");
5354d991cb3SStefan Roese ahci_mvebu_mbus_config((void __iomem *)MVEBU_SATA0_BASE);
5364d991cb3SStefan Roese ahci_mvebu_regret_option((void __iomem *)MVEBU_SATA0_BASE);
5374d991cb3SStefan Roese ahci_init((void __iomem *)MVEBU_SATA0_BASE);
5384d991cb3SStefan Roese }
5394d991cb3SStefan Roese #endif
5404d991cb3SStefan Roese
enable_caches(void)541350b50eeSStefan Roese void enable_caches(void)
542350b50eeSStefan Roese {
54360b75324SStefan Roese /* Avoid problem with e.g. neta ethernet driver */
54460b75324SStefan Roese invalidate_dcache_all();
54560b75324SStefan Roese
546ebe78903SStefan Roese /*
547ebe78903SStefan Roese * Armada 375 still has some problems with d-cache enabled in the
548ebe78903SStefan Roese * ethernet driver (mvpp2). So lets keep the d-cache disabled
549ebe78903SStefan Roese * until this is solved.
550ebe78903SStefan Roese */
551ebe78903SStefan Roese if (mvebu_soc_family() != MVEBU_SOC_A375) {
552350b50eeSStefan Roese /* Enable D-cache. I-cache is already enabled in start.S */
553350b50eeSStefan Roese dcache_enable();
554350b50eeSStefan Roese }
555ebe78903SStefan Roese }
5563e5ce7ceSStefan Roese
v7_outer_cache_enable(void)5573e5ce7ceSStefan Roese void v7_outer_cache_enable(void)
5583e5ce7ceSStefan Roese {
559c86d53fdSStefan Roese if (mvebu_soc_family() == MVEBU_SOC_AXP) {
5603e5ce7ceSStefan Roese struct pl310_regs *const pl310 =
5613e5ce7ceSStefan Roese (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
562c86d53fdSStefan Roese u32 u;
5633e5ce7ceSStefan Roese
5643e5ce7ceSStefan Roese /* The L2 cache is already disabled at this point */
5653e5ce7ceSStefan Roese
5663e5ce7ceSStefan Roese /*
5673e5ce7ceSStefan Roese * For Aurora cache in no outer mode, enable via the CP15
5683e5ce7ceSStefan Roese * coprocessor broadcasting of cache commands to L2.
5693e5ce7ceSStefan Roese */
5703e5ce7ceSStefan Roese asm volatile("mrc p15, 1, %0, c15, c2, 0" : "=r" (u));
5713e5ce7ceSStefan Roese u |= BIT(8); /* Set the FW bit */
5723e5ce7ceSStefan Roese asm volatile("mcr p15, 1, %0, c15, c2, 0" : : "r" (u));
5733e5ce7ceSStefan Roese
5743e5ce7ceSStefan Roese isb();
5753e5ce7ceSStefan Roese
5763e5ce7ceSStefan Roese /* Enable the L2 cache */
5773e5ce7ceSStefan Roese setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
5783e5ce7ceSStefan Roese }
5793e5ce7ceSStefan Roese }
580f0e8173aSStefan Roese
v7_outer_cache_disable(void)581f0e8173aSStefan Roese void v7_outer_cache_disable(void)
582f0e8173aSStefan Roese {
583f0e8173aSStefan Roese struct pl310_regs *const pl310 =
584f0e8173aSStefan Roese (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
585f0e8173aSStefan Roese
586f0e8173aSStefan Roese clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
587f0e8173aSStefan Roese }
588