blob: f4b7a4fa80108176784794cfab8d577c784a1f3c [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roese41e5ee52014-10-22 12:13:17 +02002/*
Stefan Roesed35831f2016-01-07 14:03:11 +01003 * Copyright (C) 2014-2016 Stefan Roese <sr@denx.de>
Stefan Roese41e5ee52014-10-22 12:13:17 +02004 */
5
6#include <common.h>
Stefan Roese4d991cb2015-06-29 14:58:13 +02007#include <ahci.h>
8#include <linux/mbus.h>
Stefan Roese41e5ee52014-10-22 12:13:17 +02009#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[] = {
Stefan Roese41e5ee52014-10-22 12:13:17 +020019 /* SPI */
Stefan Roese8ed20d62015-07-01 12:55:07 +020020 { MBUS_SPI_BASE, MBUS_SPI_SIZE,
21 CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_SPIFLASH },
Stefan Roese41e5ee52014-10-22 12:13:17 +020022
23 /* NOR */
Stefan Roese8ed20d62015-07-01 12:55:07 +020024 { MBUS_BOOTROM_BASE, MBUS_BOOTROM_SIZE,
25 CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_BOOTROM },
Chris Packham0d0df462019-04-11 22:22:50 +120026
27#ifdef CONFIG_ARMADA_MSYS
28 /* DFX */
29 { MBUS_DFX_BASE, MBUS_DFX_SIZE, CPU_TARGET_DFX, 0 },
30#endif
Stefan Roese41e5ee52014-10-22 12:13:17 +020031};
32
Stefan Roese42cc0342015-08-25 14:09:12 +020033void lowlevel_init(void)
34{
35 /*
36 * Dummy implementation, we only need LOWLEVEL_INIT
37 * on Armada to configure CP15 in start.S / cpu_init_cp15()
38 */
39}
40
Stefan Roese41e5ee52014-10-22 12:13:17 +020041void reset_cpu(unsigned long ignored)
42{
43 struct mvebu_system_registers *reg =
44 (struct mvebu_system_registers *)MVEBU_SYSTEM_REG_BASE;
45
46 writel(readl(&reg->rstoutn_mask) | 1, &reg->rstoutn_mask);
47 writel(readl(&reg->sys_soft_rst) | 1, &reg->sys_soft_rst);
48 while (1)
49 ;
50}
51
Stefan Roese9c6d3b72015-04-25 06:29:51 +020052int mvebu_soc_family(void)
53{
54 u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
55
Phil Sutter62029532015-12-25 14:41:24 +010056 switch (devid) {
57 case SOC_MV78230_ID:
58 case SOC_MV78260_ID:
59 case SOC_MV78460_ID:
Stefan Roese9c6d3b72015-04-25 06:29:51 +020060 return MVEBU_SOC_AXP;
Stefan Roese09e89ab2016-02-10 07:23:00 +010061
62 case SOC_88F6720_ID:
63 return MVEBU_SOC_A375;
64
Phil Sutter62029532015-12-25 14:41:24 +010065 case SOC_88F6810_ID:
66 case SOC_88F6820_ID:
67 case SOC_88F6828_ID:
Stefan Roese9c6d3b72015-04-25 06:29:51 +020068 return MVEBU_SOC_A38X;
Chris Packham0f8031a2017-09-04 17:38:31 +120069
70 case SOC_98DX3236_ID:
71 case SOC_98DX3336_ID:
72 case SOC_98DX4251_ID:
73 return MVEBU_SOC_MSYS;
Phil Sutter62029532015-12-25 14:41:24 +010074 }
Stefan Roese09e89ab2016-02-10 07:23:00 +010075
Stefan Roese9c6d3b72015-04-25 06:29:51 +020076 return MVEBU_SOC_UNKNOWN;
77}
78
Stefan Roese41e5ee52014-10-22 12:13:17 +020079#if defined(CONFIG_DISPLAY_CPUINFO)
Stefan Roesed718bf22015-12-21 12:36:40 +010080
Stefan Roese09e89ab2016-02-10 07:23:00 +010081#if defined(CONFIG_ARMADA_375)
82/* SAR frequency values for Armada 375 */
83static const struct sar_freq_modes sar_freq_tab[] = {
84 { 0, 0x0, 266, 133, 266 },
85 { 1, 0x0, 333, 167, 167 },
86 { 2, 0x0, 333, 167, 222 },
87 { 3, 0x0, 333, 167, 333 },
88 { 4, 0x0, 400, 200, 200 },
89 { 5, 0x0, 400, 200, 267 },
90 { 6, 0x0, 400, 200, 400 },
91 { 7, 0x0, 500, 250, 250 },
92 { 8, 0x0, 500, 250, 334 },
93 { 9, 0x0, 500, 250, 500 },
94 { 10, 0x0, 533, 267, 267 },
95 { 11, 0x0, 533, 267, 356 },
96 { 12, 0x0, 533, 267, 533 },
97 { 13, 0x0, 600, 300, 300 },
98 { 14, 0x0, 600, 300, 400 },
99 { 15, 0x0, 600, 300, 600 },
100 { 16, 0x0, 666, 333, 333 },
101 { 17, 0x0, 666, 333, 444 },
102 { 18, 0x0, 666, 333, 666 },
103 { 19, 0x0, 800, 400, 267 },
104 { 20, 0x0, 800, 400, 400 },
105 { 21, 0x0, 800, 400, 534 },
106 { 22, 0x0, 900, 450, 300 },
107 { 23, 0x0, 900, 450, 450 },
108 { 24, 0x0, 900, 450, 600 },
109 { 25, 0x0, 1000, 500, 500 },
110 { 26, 0x0, 1000, 500, 667 },
111 { 27, 0x0, 1000, 333, 500 },
112 { 28, 0x0, 400, 400, 400 },
113 { 29, 0x0, 1100, 550, 550 },
114 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
115};
116#elif defined(CONFIG_ARMADA_38X)
Stefan Roesed35831f2016-01-07 14:03:11 +0100117/* SAR frequency values for Armada 38x */
Stefan Roesea9fc5a22016-01-07 14:04:51 +0100118static const struct sar_freq_modes sar_freq_tab[] = {
Chris Packham0a91e1c2017-09-05 17:03:26 +1200119 { 0x0, 0x0, 666, 333, 333 },
120 { 0x2, 0x0, 800, 400, 400 },
121 { 0x4, 0x0, 1066, 533, 533 },
122 { 0x6, 0x0, 1200, 600, 600 },
123 { 0x8, 0x0, 1332, 666, 666 },
124 { 0xc, 0x0, 1600, 800, 800 },
125 { 0x10, 0x0, 1866, 933, 933 },
126 { 0x13, 0x0, 2000, 1000, 933 },
127 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
Stefan Roesed718bf22015-12-21 12:36:40 +0100128};
Chris Packham0d0df462019-04-11 22:22:50 +1200129#elif defined(CONFIG_ARMADA_MSYS)
130static const struct sar_freq_modes sar_freq_tab[] = {
131 { 0x0, 0x0, 400, 400, 400 },
132 { 0x2, 0x0, 667, 333, 667 },
133 { 0x3, 0x0, 800, 400, 800 },
134 { 0x5, 0x0, 800, 400, 800 },
135 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
136};
Stefan Roesed718bf22015-12-21 12:36:40 +0100137#else
Stefan Roesed35831f2016-01-07 14:03:11 +0100138/* SAR frequency values for Armada XP */
Stefan Roesea9fc5a22016-01-07 14:04:51 +0100139static const struct sar_freq_modes sar_freq_tab[] = {
Stefan Roesed718bf22015-12-21 12:36:40 +0100140 { 0xa, 0x5, 800, 400, 400 },
141 { 0x1, 0x5, 1066, 533, 533 },
142 { 0x2, 0x5, 1200, 600, 600 },
143 { 0x2, 0x9, 1200, 600, 400 },
144 { 0x3, 0x5, 1333, 667, 667 },
145 { 0x4, 0x5, 1500, 750, 750 },
146 { 0x4, 0x9, 1500, 750, 500 },
147 { 0xb, 0x9, 1600, 800, 533 },
148 { 0xb, 0xa, 1600, 800, 640 },
149 { 0xb, 0x5, 1600, 800, 800 },
150 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
151};
152#endif
153
154void get_sar_freq(struct sar_freq_modes *sar_freq)
155{
156 u32 val;
157 u32 freq;
158 int i;
159
Chris Packham0d0df462019-04-11 22:22:50 +1200160#if defined(CONFIG_ARMADA_375) || defined(CONFIG_ARMADA_MSYS)
Stefan Roese09e89ab2016-02-10 07:23:00 +0100161 val = readl(CONFIG_SAR2_REG); /* SAR - Sample At Reset */
162#else
Stefan Roesed718bf22015-12-21 12:36:40 +0100163 val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */
Stefan Roese09e89ab2016-02-10 07:23:00 +0100164#endif
Stefan Roesed718bf22015-12-21 12:36:40 +0100165 freq = (val & SAR_CPU_FREQ_MASK) >> SAR_CPU_FREQ_OFFS;
Stefan Roese09e89ab2016-02-10 07:23:00 +0100166#if defined(SAR2_CPU_FREQ_MASK)
Stefan Roesed718bf22015-12-21 12:36:40 +0100167 /*
168 * Shift CPU0 clock frequency select bit from SAR2 register
169 * into correct position
170 */
171 freq |= ((readl(CONFIG_SAR2_REG) & SAR2_CPU_FREQ_MASK)
172 >> SAR2_CPU_FREQ_OFFS) << 3;
173#endif
174 for (i = 0; sar_freq_tab[i].val != 0xff; i++) {
175 if (sar_freq_tab[i].val == freq) {
Chris Packham0d0df462019-04-11 22:22:50 +1200176#if defined(CONFIG_ARMADA_375) || defined(CONFIG_ARMADA_38X) || defined(CONFIG_ARMADA_MSYS)
Stefan Roesed718bf22015-12-21 12:36:40 +0100177 *sar_freq = sar_freq_tab[i];
178 return;
179#else
180 int k;
181 u8 ffc;
182
183 ffc = (val & SAR_FFC_FREQ_MASK) >>
184 SAR_FFC_FREQ_OFFS;
185 for (k = i; sar_freq_tab[k].ffc != 0xff; k++) {
186 if (sar_freq_tab[k].ffc == ffc) {
187 *sar_freq = sar_freq_tab[k];
188 return;
189 }
190 }
191 i = k;
192#endif
193 }
194 }
195
196 /* SAR value not found, return 0 for frequencies */
197 *sar_freq = sar_freq_tab[i - 1];
198}
199
Stefan Roese41e5ee52014-10-22 12:13:17 +0200200int print_cpuinfo(void)
201{
202 u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
203 u8 revid = readl(MVEBU_REG_PCIE_REVID) & 0xff;
Stefan Roesed718bf22015-12-21 12:36:40 +0100204 struct sar_freq_modes sar_freq;
Stefan Roese41e5ee52014-10-22 12:13:17 +0200205
206 puts("SoC: ");
207
208 switch (devid) {
Phil Sutter62029532015-12-25 14:41:24 +0100209 case SOC_MV78230_ID:
210 puts("MV78230-");
211 break;
Stefan Roesebf0db8b2015-12-09 11:00:51 +0100212 case SOC_MV78260_ID:
213 puts("MV78260-");
214 break;
Stefan Roese41e5ee52014-10-22 12:13:17 +0200215 case SOC_MV78460_ID:
216 puts("MV78460-");
217 break;
Stefan Roese09e89ab2016-02-10 07:23:00 +0100218 case SOC_88F6720_ID:
219 puts("MV88F6720-");
220 break;
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200221 case SOC_88F6810_ID:
222 puts("MV88F6810-");
223 break;
224 case SOC_88F6820_ID:
225 puts("MV88F6820-");
226 break;
227 case SOC_88F6828_ID:
228 puts("MV88F6828-");
229 break;
Chris Packham0f8031a2017-09-04 17:38:31 +1200230 case SOC_98DX3236_ID:
231 puts("98DX3236-");
232 break;
233 case SOC_98DX3336_ID:
234 puts("98DX3336-");
235 break;
236 case SOC_98DX4251_ID:
237 puts("98DX4251-");
238 break;
Stefan Roese41e5ee52014-10-22 12:13:17 +0200239 default:
240 puts("Unknown-");
241 break;
242 }
243
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200244 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
245 switch (revid) {
246 case 1:
Stefan Roesed718bf22015-12-21 12:36:40 +0100247 puts("A0");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200248 break;
249 case 2:
Stefan Roesed718bf22015-12-21 12:36:40 +0100250 puts("B0");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200251 break;
252 default:
Stefan Roesed718bf22015-12-21 12:36:40 +0100253 printf("?? (%x)", revid);
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200254 break;
255 }
256 }
257
Stefan Roese09e89ab2016-02-10 07:23:00 +0100258 if (mvebu_soc_family() == MVEBU_SOC_A375) {
259 switch (revid) {
260 case MV_88F67XX_A0_ID:
261 puts("A0");
262 break;
263 default:
264 printf("?? (%x)", revid);
265 break;
266 }
267 }
268
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200269 if (mvebu_soc_family() == MVEBU_SOC_A38X) {
270 switch (revid) {
271 case MV_88F68XX_Z1_ID:
Stefan Roesed718bf22015-12-21 12:36:40 +0100272 puts("Z1");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200273 break;
274 case MV_88F68XX_A0_ID:
Stefan Roesed718bf22015-12-21 12:36:40 +0100275 puts("A0");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200276 break;
Chris Packhamd997ad02018-11-28 10:32:00 +1300277 case MV_88F68XX_B0_ID:
278 puts("B0");
279 break;
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200280 default:
Stefan Roesed718bf22015-12-21 12:36:40 +0100281 printf("?? (%x)", revid);
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200282 break;
283 }
Stefan Roese41e5ee52014-10-22 12:13:17 +0200284 }
285
Chris Packham0d0df462019-04-11 22:22:50 +1200286 if (mvebu_soc_family() == MVEBU_SOC_MSYS) {
287 switch (revid) {
288 case 3:
289 puts("A0");
290 break;
291 case 4:
292 puts("A1");
293 break;
294 default:
295 printf("?? (%x)", revid);
296 break;
297 }
298 }
299
Stefan Roesed718bf22015-12-21 12:36:40 +0100300 get_sar_freq(&sar_freq);
301 printf(" at %d MHz\n", sar_freq.p_clk);
302
Stefan Roese41e5ee52014-10-22 12:13:17 +0200303 return 0;
304}
305#endif /* CONFIG_DISPLAY_CPUINFO */
306
307/*
308 * This function initialize Controller DRAM Fastpath windows.
309 * It takes the CS size information from the 0x1500 scratch registers
310 * and sets the correct windows sizes and base addresses accordingly.
311 *
312 * These values are set in the scratch registers by the Marvell
Chris Packham1670a152018-12-14 16:27:57 +1300313 * DDR3 training code, which is executed by the SPL before the
314 * main payload (U-Boot) is executed.
Stefan Roese41e5ee52014-10-22 12:13:17 +0200315 */
316static void update_sdram_window_sizes(void)
317{
318 u64 base = 0;
319 u32 size, temp;
320 int i;
321
322 for (i = 0; i < SDRAM_MAX_CS; i++) {
323 size = readl((MVEBU_SDRAM_SCRATCH + (i * 8))) & SDRAM_ADDR_MASK;
324 if (size != 0) {
325 size |= ~(SDRAM_ADDR_MASK);
326
327 /* Set Base Address */
328 temp = (base & 0xFF000000ll) | ((base >> 32) & 0xF);
329 writel(temp, MVEBU_SDRAM_BASE + DDR_BASE_CS_OFF(i));
330
331 /*
332 * Check if out of max window size and resize
333 * the window
334 */
335 temp = (readl(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i)) &
336 ~(SDRAM_ADDR_MASK)) | 1;
337 temp |= (size & SDRAM_ADDR_MASK);
338 writel(temp, MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i));
339
340 base += ((u64)size + 1);
341 } else {
342 /*
343 * Disable window if not used, otherwise this
344 * leads to overlapping enabled windows with
345 * pretty strange results
346 */
347 clrbits_le32(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i), 1);
348 }
349 }
350}
351
Stefan Roese9f62b442015-04-24 10:49:11 +0200352void mmu_disable(void)
353{
354 asm volatile(
355 "mrc p15, 0, r0, c1, c0, 0\n"
356 "bic r0, #1\n"
357 "mcr p15, 0, r0, c1, c0, 0\n");
358}
359
Stefan Roese41e5ee52014-10-22 12:13:17 +0200360#ifdef CONFIG_ARCH_CPU_INIT
Kevin Smithe1b078e2015-05-18 16:09:44 +0000361static void set_cbar(u32 addr)
362{
363 asm("mcr p15, 4, %0, c15, c0" : : "r" (addr));
364}
365
Stefan Roesedee40d22015-07-22 18:26:13 +0200366#define MV_USB_PHY_BASE (MVEBU_AXP_USB_BASE + 0x800)
367#define MV_USB_PHY_PLL_REG(reg) (MV_USB_PHY_BASE | (((reg) & 0xF) << 2))
368#define MV_USB_X3_BASE(addr) (MVEBU_AXP_USB_BASE | BIT(11) | \
369 (((addr) & 0xF) << 6))
370#define MV_USB_X3_PHY_CHANNEL(dev, reg) (MV_USB_X3_BASE((dev) + 1) | \
371 (((reg) & 0xF) << 2))
372
373static void setup_usb_phys(void)
374{
375 int dev;
376
377 /*
378 * USB PLL init
379 */
380
381 /* Setup PLL frequency */
382 /* USB REF frequency = 25 MHz */
383 clrsetbits_le32(MV_USB_PHY_PLL_REG(1), 0x3ff, 0x605);
384
385 /* Power up PLL and PHY channel */
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100386 setbits_le32(MV_USB_PHY_PLL_REG(2), BIT(9));
Stefan Roesedee40d22015-07-22 18:26:13 +0200387
388 /* Assert VCOCAL_START */
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100389 setbits_le32(MV_USB_PHY_PLL_REG(1), BIT(21));
Stefan Roesedee40d22015-07-22 18:26:13 +0200390
391 mdelay(1);
392
393 /*
394 * USB PHY init (change from defaults) specific for 40nm (78X30 78X60)
395 */
396
397 for (dev = 0; dev < 3; dev++) {
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100398 setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 3), BIT(15));
Stefan Roesedee40d22015-07-22 18:26:13 +0200399
400 /* Assert REG_RCAL_START in channel REG 1 */
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100401 setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
Stefan Roesedee40d22015-07-22 18:26:13 +0200402 udelay(40);
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100403 clrbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
Stefan Roesedee40d22015-07-22 18:26:13 +0200404 }
405}
Kevin Smithe1b078e2015-05-18 16:09:44 +0000406
Stefan Roesef4e6ec72015-12-03 12:39:45 +0100407/*
408 * This function is not called from the SPL U-Boot version
409 */
Stefan Roese41e5ee52014-10-22 12:13:17 +0200410int arch_cpu_init(void)
411{
Stefan Roese42cc0342015-08-25 14:09:12 +0200412 struct pl310_regs *const pl310 =
413 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
414
Stefan Roesecefd7642015-08-24 11:03:50 +0200415 /*
416 * Only with disabled MMU its possible to switch the base
417 * register address on Armada 38x. Without this the SDRAM
418 * located at >= 0x4000.0000 is also not accessible, as its
419 * still locked to cache.
420 */
421 mmu_disable();
Stefan Roese9f62b442015-04-24 10:49:11 +0200422
Stefan Roese41e5ee52014-10-22 12:13:17 +0200423 /* Linux expects the internal registers to be at 0xf1000000 */
424 writel(SOC_REGS_PHY_BASE, INTREG_BASE_ADDR_REG);
Kevin Smithe1b078e2015-05-18 16:09:44 +0000425 set_cbar(SOC_REGS_PHY_BASE + 0xC000);
Stefan Roese41e5ee52014-10-22 12:13:17 +0200426
Stefan Roesecefd7642015-08-24 11:03:50 +0200427 /*
428 * From this stage on, the SoC detection is working. As we have
429 * configured the internal register base to the value used
430 * in the macros / defines in the U-Boot header (soc.h).
431 */
Stefan Roesecefd7642015-08-24 11:03:50 +0200432
Stefan Roesec86d53f2015-12-03 12:39:45 +0100433 if (mvebu_soc_family() == MVEBU_SOC_A38X) {
434 /*
435 * To fully release / unlock this area from cache, we need
436 * to flush all caches and disable the L2 cache.
437 */
438 icache_disable();
439 dcache_disable();
440 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
441 }
Stefan Roesecefd7642015-08-24 11:03:50 +0200442
Stefan Roese41e5ee52014-10-22 12:13:17 +0200443 /*
444 * We need to call mvebu_mbus_probe() before calling
445 * update_sdram_window_sizes() as it disables all previously
446 * configured mbus windows and then configures them as
447 * required for U-Boot. Calling update_sdram_window_sizes()
448 * without this configuration will not work, as the internal
449 * registers can't be accessed reliably because of potenial
450 * double mapping.
451 * After updating the SDRAM access windows we need to call
452 * mvebu_mbus_probe() again, as this now correctly configures
453 * the SDRAM areas that are later used by the MVEBU drivers
454 * (e.g. USB, NETA).
455 */
456
457 /*
458 * First disable all windows
459 */
460 mvebu_mbus_probe(NULL, 0);
461
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200462 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
463 /*
464 * Now the SDRAM access windows can be reconfigured using
465 * the information in the SDRAM scratch pad registers
466 */
467 update_sdram_window_sizes();
468 }
Stefan Roese41e5ee52014-10-22 12:13:17 +0200469
470 /*
471 * Finally the mbus windows can be configured with the
472 * updated SDRAM sizes
473 */
474 mvebu_mbus_probe(windows, ARRAY_SIZE(windows));
475
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200476 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
477 /* Enable GBE0, GBE1, LCD and NFC PUP */
478 clrsetbits_le32(ARMADA_XP_PUP_ENABLE, 0,
479 GE0_PUP_EN | GE1_PUP_EN | LCD_PUP_EN |
480 NAND_PUP_EN | SPI_PUP_EN);
Stefan Roesedee40d22015-07-22 18:26:13 +0200481
482 /* Configure USB PLL and PHYs on AXP */
483 setup_usb_phys();
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200484 }
485
486 /* Enable NAND and NAND arbiter */
487 clrsetbits_le32(MVEBU_SOC_DEV_MUX_REG, 0, NAND_EN | NAND_ARBITER_EN);
488
Stefan Roese501c0982015-07-01 13:28:39 +0200489 /* Disable MBUS error propagation */
490 clrsetbits_le32(SOC_COHERENCY_FABRIC_CTRL_REG, MBUS_ERR_PROP_EN, 0);
491
Stefan Roese41e5ee52014-10-22 12:13:17 +0200492 return 0;
493}
494#endif /* CONFIG_ARCH_CPU_INIT */
495
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200496u32 mvebu_get_nand_clock(void)
497{
Chris Packhamd7b47312016-08-22 12:38:39 +1200498 u32 reg;
499
500 if (mvebu_soc_family() == MVEBU_SOC_A38X)
501 reg = MVEBU_DFX_DIV_CLK_CTRL(1);
Chris Packham689f9cf2019-04-11 22:22:51 +1200502 else if (mvebu_soc_family() == MVEBU_SOC_MSYS)
503 reg = MVEBU_DFX_DIV_CLK_CTRL(8);
Chris Packhamd7b47312016-08-22 12:38:39 +1200504 else
505 reg = MVEBU_CORE_DIV_CLK_CTRL(1);
506
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200507 return CONFIG_SYS_MVEBU_PLL_CLOCK /
Chris Packhamd7b47312016-08-22 12:38:39 +1200508 ((readl(reg) &
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200509 NAND_ECC_DIVCKL_RATIO_MASK) >> NAND_ECC_DIVCKL_RATIO_OFFS);
510}
511
Stefan Roese41e5ee52014-10-22 12:13:17 +0200512/*
513 * SOC specific misc init
514 */
515#if defined(CONFIG_ARCH_MISC_INIT)
516int arch_misc_init(void)
517{
518 /* Nothing yet, perhaps we need something here later */
519 return 0;
520}
521#endif /* CONFIG_ARCH_MISC_INIT */
522
Pierre Bourdon4ec9dd42019-04-11 04:56:58 +0200523#if defined(CONFIG_MMC_SDHCI_MV) && !defined(CONFIG_DM_MMC)
Stefan Roese7f1adcd2015-06-29 14:58:10 +0200524int board_mmc_init(bd_t *bis)
525{
526 mv_sdh_init(MVEBU_SDIO_BASE, 0, 0,
527 SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_WAIT_SEND_CMD);
528
529 return 0;
530}
531#endif
532
Stefan Roese4d991cb2015-06-29 14:58:13 +0200533#define AHCI_VENDOR_SPECIFIC_0_ADDR 0xa0
534#define AHCI_VENDOR_SPECIFIC_0_DATA 0xa4
535
536#define AHCI_WINDOW_CTRL(win) (0x60 + ((win) << 4))
537#define AHCI_WINDOW_BASE(win) (0x64 + ((win) << 4))
538#define AHCI_WINDOW_SIZE(win) (0x68 + ((win) << 4))
539
540static void ahci_mvebu_mbus_config(void __iomem *base)
541{
542 const struct mbus_dram_target_info *dram;
543 int i;
544
Baruch Siachf0aa1252019-05-16 13:03:57 +0300545 /* mbus is not initialized in SPL; keep the ROM settings */
546 if (IS_ENABLED(CONFIG_SPL_BUILD))
547 return;
548
Stefan Roese4d991cb2015-06-29 14:58:13 +0200549 dram = mvebu_mbus_dram_info();
550
551 for (i = 0; i < 4; i++) {
552 writel(0, base + AHCI_WINDOW_CTRL(i));
553 writel(0, base + AHCI_WINDOW_BASE(i));
554 writel(0, base + AHCI_WINDOW_SIZE(i));
555 }
556
557 for (i = 0; i < dram->num_cs; i++) {
558 const struct mbus_dram_window *cs = dram->cs + i;
559
560 writel((cs->mbus_attr << 8) |
561 (dram->mbus_dram_target_id << 4) | 1,
562 base + AHCI_WINDOW_CTRL(i));
563 writel(cs->base >> 16, base + AHCI_WINDOW_BASE(i));
564 writel(((cs->size - 1) & 0xffff0000),
565 base + AHCI_WINDOW_SIZE(i));
566 }
567}
568
569static void ahci_mvebu_regret_option(void __iomem *base)
570{
571 /*
572 * Enable the regret bit to allow the SATA unit to regret a
573 * request that didn't receive an acknowlegde and avoid a
574 * deadlock
575 */
576 writel(0x4, base + AHCI_VENDOR_SPECIFIC_0_ADDR);
577 writel(0x80, base + AHCI_VENDOR_SPECIFIC_0_DATA);
578}
579
Baruch Siach4b11e5f2019-03-24 13:27:43 +0200580int board_ahci_enable(void)
581{
582 ahci_mvebu_mbus_config((void __iomem *)MVEBU_SATA0_BASE);
583 ahci_mvebu_regret_option((void __iomem *)MVEBU_SATA0_BASE);
584
585 return 0;
586}
587
588#ifdef CONFIG_SCSI_AHCI_PLAT
Stefan Roese4d991cb2015-06-29 14:58:13 +0200589void scsi_init(void)
590{
591 printf("MVEBU SATA INIT\n");
Baruch Siach4b11e5f2019-03-24 13:27:43 +0200592 board_ahci_enable();
Stefan Roese4d991cb2015-06-29 14:58:13 +0200593 ahci_init((void __iomem *)MVEBU_SATA0_BASE);
594}
595#endif
596
Jon Nettleton78aa0182017-11-06 10:33:20 +0200597#ifdef CONFIG_USB_XHCI_MVEBU
598#define USB3_MAX_WINDOWS 4
599#define USB3_WIN_CTRL(w) (0x0 + ((w) * 8))
600#define USB3_WIN_BASE(w) (0x4 + ((w) * 8))
601
602static void xhci_mvebu_mbus_config(void __iomem *base,
603 const struct mbus_dram_target_info *dram)
604{
605 int i;
606
607 for (i = 0; i < USB3_MAX_WINDOWS; i++) {
608 writel(0, base + USB3_WIN_CTRL(i));
609 writel(0, base + USB3_WIN_BASE(i));
610 }
611
612 for (i = 0; i < dram->num_cs; i++) {
613 const struct mbus_dram_window *cs = dram->cs + i;
614
615 /* Write size, attributes and target id to control register */
616 writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
617 (dram->mbus_dram_target_id << 4) | 1,
618 base + USB3_WIN_CTRL(i));
619
620 /* Write base address to base register */
621 writel((cs->base & 0xffff0000), base + USB3_WIN_BASE(i));
622 }
623}
624
625int board_xhci_enable(fdt_addr_t base)
626{
627 const struct mbus_dram_target_info *dram;
628
629 printf("MVEBU XHCI INIT controller @ 0x%lx\n", base);
630
631 dram = mvebu_mbus_dram_info();
632 xhci_mvebu_mbus_config((void __iomem *)base, dram);
633
634 return 0;
635}
636#endif
637
Stefan Roese41e5ee52014-10-22 12:13:17 +0200638void enable_caches(void)
639{
Stefan Roese60b75322015-04-25 06:29:55 +0200640 /* Avoid problem with e.g. neta ethernet driver */
641 invalidate_dcache_all();
642
Stefan Roeseebe78902016-02-10 09:18:46 +0100643 /*
644 * Armada 375 still has some problems with d-cache enabled in the
645 * ethernet driver (mvpp2). So lets keep the d-cache disabled
646 * until this is solved.
647 */
648 if (mvebu_soc_family() != MVEBU_SOC_A375) {
649 /* Enable D-cache. I-cache is already enabled in start.S */
650 dcache_enable();
651 }
Stefan Roese41e5ee52014-10-22 12:13:17 +0200652}
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100653
654void v7_outer_cache_enable(void)
655{
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100656 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
Stefan Roesec86d53f2015-12-03 12:39:45 +0100657 struct pl310_regs *const pl310 =
658 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100659 u32 u;
660
Stefan Roesec86d53f2015-12-03 12:39:45 +0100661 /* The L2 cache is already disabled at this point */
662
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100663 /*
664 * For Aurora cache in no outer mode, enable via the CP15
665 * coprocessor broadcasting of cache commands to L2.
666 */
667 asm volatile("mrc p15, 1, %0, c15, c2, 0" : "=r" (u));
668 u |= BIT(8); /* Set the FW bit */
669 asm volatile("mcr p15, 1, %0, c15, c2, 0" : : "r" (u));
670
671 isb();
672
673 /* Enable the L2 cache */
674 setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
675 }
676}
Stefan Roesef0e81732015-12-14 12:31:48 +0100677
678void v7_outer_cache_disable(void)
679{
680 struct pl310_regs *const pl310 =
681 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
682
683 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
684}