blob: 1f8cdf8744e6cf1c2e4f82af4d88e008de63540c [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>
Simon Glass9edefc22019-11-14 12:57:37 -07008#include <cpu_func.h>
Simon Glass691d7192020-05-10 11:40:02 -06009#include <init.h>
Simon Glasscd93d622020-05-10 11:40:13 -060010#include <linux/bitops.h>
Simon Glassc05ed002020-05-10 11:40:11 -060011#include <linux/delay.h>
Stefan Roese4d991cb2015-06-29 14:58:13 +020012#include <linux/mbus.h>
Stefan Roese41e5ee52014-10-22 12:13:17 +020013#include <asm/io.h>
Stefan Roese57303602015-05-18 16:09:43 +000014#include <asm/pl310.h>
Stefan Roese41e5ee52014-10-22 12:13:17 +020015#include <asm/arch/cpu.h>
16#include <asm/arch/soc.h>
Marek Behúndc595e32021-08-16 15:19:37 +020017#include <asm/spl.h>
Stefan Roese7f1adcd2015-06-29 14:58:10 +020018#include <sdhci.h>
Stefan Roese41e5ee52014-10-22 12:13:17 +020019
20#define DDR_BASE_CS_OFF(n) (0x0000 + ((n) << 3))
21#define DDR_SIZE_CS_OFF(n) (0x0004 + ((n) << 3))
22
Pali Rohárb1205192022-09-09 14:41:28 +020023static const struct mbus_win windows[] = {
Stefan Roese41e5ee52014-10-22 12:13:17 +020024 /* SPI */
Stefan Roese8ed20d62015-07-01 12:55:07 +020025 { MBUS_SPI_BASE, MBUS_SPI_SIZE,
26 CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_SPIFLASH },
Stefan Roese41e5ee52014-10-22 12:13:17 +020027
28 /* NOR */
Stefan Roese8ed20d62015-07-01 12:55:07 +020029 { MBUS_BOOTROM_BASE, MBUS_BOOTROM_SIZE,
30 CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_BOOTROM },
Chris Packham0d0df462019-04-11 22:22:50 +120031
32#ifdef CONFIG_ARMADA_MSYS
33 /* DFX */
34 { MBUS_DFX_BASE, MBUS_DFX_SIZE, CPU_TARGET_DFX, 0 },
35#endif
Stefan Roese41e5ee52014-10-22 12:13:17 +020036};
37
Stefan Roese42cc0342015-08-25 14:09:12 +020038void lowlevel_init(void)
39{
40 /*
41 * Dummy implementation, we only need LOWLEVEL_INIT
42 * on Armada to configure CP15 in start.S / cpu_init_cp15()
43 */
44}
45
Harald Seiler35b65dd2020-12-15 16:47:52 +010046void reset_cpu(void)
Stefan Roese41e5ee52014-10-22 12:13:17 +020047{
48 struct mvebu_system_registers *reg =
49 (struct mvebu_system_registers *)MVEBU_SYSTEM_REG_BASE;
50
51 writel(readl(&reg->rstoutn_mask) | 1, &reg->rstoutn_mask);
52 writel(readl(&reg->sys_soft_rst) | 1, &reg->sys_soft_rst);
53 while (1)
54 ;
55}
56
Marek Behúndc595e32021-08-16 15:19:37 +020057u32 get_boot_device(void)
58{
59 u32 val;
60 u32 boot_device;
61
62 /*
Tom Rini48cf96f2021-09-01 07:52:08 -040063 * First check, if UART boot-mode is active. This can only
64 * be done, via the bootrom error register. Here the
65 * MSB marks if the UART mode is active.
66 */
Tom Rini4e4fff72022-03-30 18:07:12 -040067 val = readl(BOOTROM_ERR_REG);
Marek Behúndc595e32021-08-16 15:19:37 +020068 boot_device = (val & BOOTROM_ERR_MODE_MASK) >> BOOTROM_ERR_MODE_OFFS;
69 debug("BOOTROM_REG=0x%08x boot_device=0x%x\n", val, boot_device);
70 if (boot_device == BOOTROM_ERR_MODE_UART)
71 return BOOT_DEVICE_UART;
72
73#ifdef CONFIG_ARMADA_38X
74 /*
Tom Rini48cf96f2021-09-01 07:52:08 -040075 * If the bootrom error code contains any other than zeros it's an
76 * error condition and the bootROM has fallen back to UART boot
77 */
Marek Behúndc595e32021-08-16 15:19:37 +020078 boot_device = (val & BOOTROM_ERR_CODE_MASK) >> BOOTROM_ERR_CODE_OFFS;
79 if (boot_device)
80 return BOOT_DEVICE_UART;
81#endif
82
83 /*
Tom Rini48cf96f2021-09-01 07:52:08 -040084 * Now check the SAR register for the strapped boot-device
85 */
Marek Behúndc595e32021-08-16 15:19:37 +020086 val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */
87 boot_device = (val & BOOT_DEV_SEL_MASK) >> BOOT_DEV_SEL_OFFS;
88 debug("SAR_REG=0x%08x boot_device=0x%x\n", val, boot_device);
89 switch (boot_device) {
90#ifdef BOOT_FROM_NAND
91 case BOOT_FROM_NAND:
92 return BOOT_DEVICE_NAND;
93#endif
94#ifdef BOOT_FROM_MMC
95 case BOOT_FROM_MMC:
96 case BOOT_FROM_MMC_ALT:
97 return BOOT_DEVICE_MMC1;
98#endif
99 case BOOT_FROM_UART:
100#ifdef BOOT_FROM_UART_ALT
101 case BOOT_FROM_UART_ALT:
102#endif
103 return BOOT_DEVICE_UART;
104#ifdef BOOT_FROM_SATA
105 case BOOT_FROM_SATA:
106 case BOOT_FROM_SATA_ALT:
107 return BOOT_DEVICE_SATA;
108#endif
109 case BOOT_FROM_SPI:
110 return BOOT_DEVICE_SPI;
111 default:
112 return BOOT_DEVICE_BOOTROM;
113 };
114}
115
Stefan Roese41e5ee52014-10-22 12:13:17 +0200116#if defined(CONFIG_DISPLAY_CPUINFO)
Stefan Roesed718bf22015-12-21 12:36:40 +0100117
Stefan Roese09e89ab2016-02-10 07:23:00 +0100118#if defined(CONFIG_ARMADA_375)
119/* SAR frequency values for Armada 375 */
120static const struct sar_freq_modes sar_freq_tab[] = {
121 { 0, 0x0, 266, 133, 266 },
122 { 1, 0x0, 333, 167, 167 },
123 { 2, 0x0, 333, 167, 222 },
124 { 3, 0x0, 333, 167, 333 },
125 { 4, 0x0, 400, 200, 200 },
126 { 5, 0x0, 400, 200, 267 },
127 { 6, 0x0, 400, 200, 400 },
128 { 7, 0x0, 500, 250, 250 },
129 { 8, 0x0, 500, 250, 334 },
130 { 9, 0x0, 500, 250, 500 },
131 { 10, 0x0, 533, 267, 267 },
132 { 11, 0x0, 533, 267, 356 },
133 { 12, 0x0, 533, 267, 533 },
134 { 13, 0x0, 600, 300, 300 },
135 { 14, 0x0, 600, 300, 400 },
136 { 15, 0x0, 600, 300, 600 },
137 { 16, 0x0, 666, 333, 333 },
138 { 17, 0x0, 666, 333, 444 },
139 { 18, 0x0, 666, 333, 666 },
140 { 19, 0x0, 800, 400, 267 },
141 { 20, 0x0, 800, 400, 400 },
142 { 21, 0x0, 800, 400, 534 },
143 { 22, 0x0, 900, 450, 300 },
144 { 23, 0x0, 900, 450, 450 },
145 { 24, 0x0, 900, 450, 600 },
146 { 25, 0x0, 1000, 500, 500 },
147 { 26, 0x0, 1000, 500, 667 },
148 { 27, 0x0, 1000, 333, 500 },
149 { 28, 0x0, 400, 400, 400 },
150 { 29, 0x0, 1100, 550, 550 },
151 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
152};
153#elif defined(CONFIG_ARMADA_38X)
Stefan Roesed35831f2016-01-07 14:03:11 +0100154/* SAR frequency values for Armada 38x */
Stefan Roesea9fc5a22016-01-07 14:04:51 +0100155static const struct sar_freq_modes sar_freq_tab[] = {
Chris Packham0a91e1c2017-09-05 17:03:26 +1200156 { 0x0, 0x0, 666, 333, 333 },
157 { 0x2, 0x0, 800, 400, 400 },
158 { 0x4, 0x0, 1066, 533, 533 },
159 { 0x6, 0x0, 1200, 600, 600 },
160 { 0x8, 0x0, 1332, 666, 666 },
161 { 0xc, 0x0, 1600, 800, 800 },
162 { 0x10, 0x0, 1866, 933, 933 },
163 { 0x13, 0x0, 2000, 1000, 933 },
164 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
Stefan Roesed718bf22015-12-21 12:36:40 +0100165};
Chris Packham0d0df462019-04-11 22:22:50 +1200166#elif defined(CONFIG_ARMADA_MSYS)
167static const struct sar_freq_modes sar_freq_tab[] = {
168 { 0x0, 0x0, 400, 400, 400 },
169 { 0x2, 0x0, 667, 333, 667 },
170 { 0x3, 0x0, 800, 400, 800 },
171 { 0x5, 0x0, 800, 400, 800 },
172 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
173};
Stefan Roesed718bf22015-12-21 12:36:40 +0100174#else
Stefan Roesed35831f2016-01-07 14:03:11 +0100175/* SAR frequency values for Armada XP */
Stefan Roesea9fc5a22016-01-07 14:04:51 +0100176static const struct sar_freq_modes sar_freq_tab[] = {
Stefan Roesed718bf22015-12-21 12:36:40 +0100177 { 0xa, 0x5, 800, 400, 400 },
178 { 0x1, 0x5, 1066, 533, 533 },
179 { 0x2, 0x5, 1200, 600, 600 },
180 { 0x2, 0x9, 1200, 600, 400 },
181 { 0x3, 0x5, 1333, 667, 667 },
182 { 0x4, 0x5, 1500, 750, 750 },
183 { 0x4, 0x9, 1500, 750, 500 },
184 { 0xb, 0x9, 1600, 800, 533 },
185 { 0xb, 0xa, 1600, 800, 640 },
186 { 0xb, 0x5, 1600, 800, 800 },
187 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
188};
189#endif
190
191void get_sar_freq(struct sar_freq_modes *sar_freq)
192{
193 u32 val;
194 u32 freq;
195 int i;
196
Chris Packham0d0df462019-04-11 22:22:50 +1200197#if defined(CONFIG_ARMADA_375) || defined(CONFIG_ARMADA_MSYS)
Stefan Roese09e89ab2016-02-10 07:23:00 +0100198 val = readl(CONFIG_SAR2_REG); /* SAR - Sample At Reset */
199#else
Stefan Roesed718bf22015-12-21 12:36:40 +0100200 val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */
Stefan Roese09e89ab2016-02-10 07:23:00 +0100201#endif
Stefan Roesed718bf22015-12-21 12:36:40 +0100202 freq = (val & SAR_CPU_FREQ_MASK) >> SAR_CPU_FREQ_OFFS;
Stefan Roese09e89ab2016-02-10 07:23:00 +0100203#if defined(SAR2_CPU_FREQ_MASK)
Stefan Roesed718bf22015-12-21 12:36:40 +0100204 /*
205 * Shift CPU0 clock frequency select bit from SAR2 register
206 * into correct position
207 */
208 freq |= ((readl(CONFIG_SAR2_REG) & SAR2_CPU_FREQ_MASK)
209 >> SAR2_CPU_FREQ_OFFS) << 3;
210#endif
211 for (i = 0; sar_freq_tab[i].val != 0xff; i++) {
212 if (sar_freq_tab[i].val == freq) {
Chris Packham0d0df462019-04-11 22:22:50 +1200213#if defined(CONFIG_ARMADA_375) || defined(CONFIG_ARMADA_38X) || defined(CONFIG_ARMADA_MSYS)
Stefan Roesed718bf22015-12-21 12:36:40 +0100214 *sar_freq = sar_freq_tab[i];
215 return;
216#else
217 int k;
218 u8 ffc;
219
220 ffc = (val & SAR_FFC_FREQ_MASK) >>
221 SAR_FFC_FREQ_OFFS;
222 for (k = i; sar_freq_tab[k].ffc != 0xff; k++) {
223 if (sar_freq_tab[k].ffc == ffc) {
224 *sar_freq = sar_freq_tab[k];
225 return;
226 }
227 }
228 i = k;
229#endif
230 }
231 }
232
233 /* SAR value not found, return 0 for frequencies */
234 *sar_freq = sar_freq_tab[i - 1];
235}
236
Stefan Roese41e5ee52014-10-22 12:13:17 +0200237int print_cpuinfo(void)
238{
239 u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
240 u8 revid = readl(MVEBU_REG_PCIE_REVID) & 0xff;
Stefan Roesed718bf22015-12-21 12:36:40 +0100241 struct sar_freq_modes sar_freq;
Stefan Roese41e5ee52014-10-22 12:13:17 +0200242
243 puts("SoC: ");
244
245 switch (devid) {
Phil Sutter62029532015-12-25 14:41:24 +0100246 case SOC_MV78230_ID:
247 puts("MV78230-");
248 break;
Stefan Roesebf0db8b2015-12-09 11:00:51 +0100249 case SOC_MV78260_ID:
250 puts("MV78260-");
251 break;
Stefan Roese41e5ee52014-10-22 12:13:17 +0200252 case SOC_MV78460_ID:
253 puts("MV78460-");
254 break;
Stefan Roese09e89ab2016-02-10 07:23:00 +0100255 case SOC_88F6720_ID:
256 puts("MV88F6720-");
257 break;
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200258 case SOC_88F6810_ID:
259 puts("MV88F6810-");
260 break;
261 case SOC_88F6820_ID:
262 puts("MV88F6820-");
263 break;
264 case SOC_88F6828_ID:
265 puts("MV88F6828-");
266 break;
Chris Packham0f8031a2017-09-04 17:38:31 +1200267 case SOC_98DX3236_ID:
268 puts("98DX3236-");
269 break;
270 case SOC_98DX3336_ID:
271 puts("98DX3336-");
272 break;
273 case SOC_98DX4251_ID:
274 puts("98DX4251-");
275 break;
Stefan Roese41e5ee52014-10-22 12:13:17 +0200276 default:
277 puts("Unknown-");
278 break;
279 }
280
Pali Rohár33089332022-07-15 10:13:12 +0200281 switch (devid) {
282 case SOC_MV78230_ID:
283 case SOC_MV78260_ID:
284 case SOC_MV78460_ID:
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200285 switch (revid) {
286 case 1:
Stefan Roesed718bf22015-12-21 12:36:40 +0100287 puts("A0");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200288 break;
289 case 2:
Stefan Roesed718bf22015-12-21 12:36:40 +0100290 puts("B0");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200291 break;
292 default:
Stefan Roesed718bf22015-12-21 12:36:40 +0100293 printf("?? (%x)", revid);
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200294 break;
295 }
Pali Rohár33089332022-07-15 10:13:12 +0200296 break;
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200297
Pali Rohár33089332022-07-15 10:13:12 +0200298 case SOC_88F6720_ID:
Stefan Roese09e89ab2016-02-10 07:23:00 +0100299 switch (revid) {
300 case MV_88F67XX_A0_ID:
301 puts("A0");
302 break;
303 default:
304 printf("?? (%x)", revid);
305 break;
306 }
Pali Rohár33089332022-07-15 10:13:12 +0200307 break;
Stefan Roese09e89ab2016-02-10 07:23:00 +0100308
Pali Rohár33089332022-07-15 10:13:12 +0200309 case SOC_88F6810_ID:
310 case SOC_88F6820_ID:
311 case SOC_88F6828_ID:
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200312 switch (revid) {
313 case MV_88F68XX_Z1_ID:
Stefan Roesed718bf22015-12-21 12:36:40 +0100314 puts("Z1");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200315 break;
316 case MV_88F68XX_A0_ID:
Stefan Roesed718bf22015-12-21 12:36:40 +0100317 puts("A0");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200318 break;
Chris Packhamd997ad02018-11-28 10:32:00 +1300319 case MV_88F68XX_B0_ID:
320 puts("B0");
321 break;
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200322 default:
Stefan Roesed718bf22015-12-21 12:36:40 +0100323 printf("?? (%x)", revid);
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200324 break;
325 }
Pali Rohár33089332022-07-15 10:13:12 +0200326 break;
Stefan Roese41e5ee52014-10-22 12:13:17 +0200327
Pali Rohár33089332022-07-15 10:13:12 +0200328 case SOC_98DX3236_ID:
329 case SOC_98DX3336_ID:
330 case SOC_98DX4251_ID:
Chris Packham0d0df462019-04-11 22:22:50 +1200331 switch (revid) {
332 case 3:
333 puts("A0");
334 break;
335 case 4:
336 puts("A1");
337 break;
338 default:
339 printf("?? (%x)", revid);
340 break;
341 }
Pali Rohár33089332022-07-15 10:13:12 +0200342 break;
343
344 default:
345 printf("?? (%x)", revid);
346 break;
Chris Packham0d0df462019-04-11 22:22:50 +1200347 }
348
Stefan Roesed718bf22015-12-21 12:36:40 +0100349 get_sar_freq(&sar_freq);
350 printf(" at %d MHz\n", sar_freq.p_clk);
351
Stefan Roese41e5ee52014-10-22 12:13:17 +0200352 return 0;
353}
354#endif /* CONFIG_DISPLAY_CPUINFO */
355
356/*
357 * This function initialize Controller DRAM Fastpath windows.
358 * It takes the CS size information from the 0x1500 scratch registers
359 * and sets the correct windows sizes and base addresses accordingly.
360 *
361 * These values are set in the scratch registers by the Marvell
Chris Packham1670a152018-12-14 16:27:57 +1300362 * DDR3 training code, which is executed by the SPL before the
363 * main payload (U-Boot) is executed.
Stefan Roese41e5ee52014-10-22 12:13:17 +0200364 */
365static void update_sdram_window_sizes(void)
366{
367 u64 base = 0;
368 u32 size, temp;
369 int i;
370
371 for (i = 0; i < SDRAM_MAX_CS; i++) {
372 size = readl((MVEBU_SDRAM_SCRATCH + (i * 8))) & SDRAM_ADDR_MASK;
373 if (size != 0) {
374 size |= ~(SDRAM_ADDR_MASK);
375
376 /* Set Base Address */
377 temp = (base & 0xFF000000ll) | ((base >> 32) & 0xF);
378 writel(temp, MVEBU_SDRAM_BASE + DDR_BASE_CS_OFF(i));
379
380 /*
381 * Check if out of max window size and resize
382 * the window
383 */
384 temp = (readl(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i)) &
385 ~(SDRAM_ADDR_MASK)) | 1;
386 temp |= (size & SDRAM_ADDR_MASK);
387 writel(temp, MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i));
388
389 base += ((u64)size + 1);
390 } else {
391 /*
392 * Disable window if not used, otherwise this
393 * leads to overlapping enabled windows with
394 * pretty strange results
395 */
396 clrbits_le32(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i), 1);
397 }
398 }
399}
400
401#ifdef CONFIG_ARCH_CPU_INIT
Stefan Roesedee40d22015-07-22 18:26:13 +0200402#define MV_USB_PHY_BASE (MVEBU_AXP_USB_BASE + 0x800)
403#define MV_USB_PHY_PLL_REG(reg) (MV_USB_PHY_BASE | (((reg) & 0xF) << 2))
404#define MV_USB_X3_BASE(addr) (MVEBU_AXP_USB_BASE | BIT(11) | \
405 (((addr) & 0xF) << 6))
406#define MV_USB_X3_PHY_CHANNEL(dev, reg) (MV_USB_X3_BASE((dev) + 1) | \
407 (((reg) & 0xF) << 2))
408
409static void setup_usb_phys(void)
410{
411 int dev;
412
413 /*
414 * USB PLL init
415 */
416
417 /* Setup PLL frequency */
418 /* USB REF frequency = 25 MHz */
419 clrsetbits_le32(MV_USB_PHY_PLL_REG(1), 0x3ff, 0x605);
420
421 /* Power up PLL and PHY channel */
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100422 setbits_le32(MV_USB_PHY_PLL_REG(2), BIT(9));
Stefan Roesedee40d22015-07-22 18:26:13 +0200423
424 /* Assert VCOCAL_START */
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100425 setbits_le32(MV_USB_PHY_PLL_REG(1), BIT(21));
Stefan Roesedee40d22015-07-22 18:26:13 +0200426
427 mdelay(1);
428
429 /*
430 * USB PHY init (change from defaults) specific for 40nm (78X30 78X60)
431 */
432
433 for (dev = 0; dev < 3; dev++) {
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100434 setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 3), BIT(15));
Stefan Roesedee40d22015-07-22 18:26:13 +0200435
436 /* Assert REG_RCAL_START in channel REG 1 */
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100437 setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
Stefan Roesedee40d22015-07-22 18:26:13 +0200438 udelay(40);
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100439 clrbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
Stefan Roesedee40d22015-07-22 18:26:13 +0200440 }
441}
Kevin Smithe1b078e2015-05-18 16:09:44 +0000442
Stefan Roesef4e6ec72015-12-03 12:39:45 +0100443/*
444 * This function is not called from the SPL U-Boot version
445 */
Stefan Roese41e5ee52014-10-22 12:13:17 +0200446int arch_cpu_init(void)
447{
Stefan Roese41e5ee52014-10-22 12:13:17 +0200448 /*
449 * We need to call mvebu_mbus_probe() before calling
450 * update_sdram_window_sizes() as it disables all previously
451 * configured mbus windows and then configures them as
452 * required for U-Boot. Calling update_sdram_window_sizes()
453 * without this configuration will not work, as the internal
454 * registers can't be accessed reliably because of potenial
455 * double mapping.
456 * After updating the SDRAM access windows we need to call
457 * mvebu_mbus_probe() again, as this now correctly configures
458 * the SDRAM areas that are later used by the MVEBU drivers
459 * (e.g. USB, NETA).
460 */
461
462 /*
463 * First disable all windows
464 */
465 mvebu_mbus_probe(NULL, 0);
466
Pali Rohár33089332022-07-15 10:13:12 +0200467 if (IS_ENABLED(CONFIG_ARMADA_XP)) {
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200468 /*
469 * Now the SDRAM access windows can be reconfigured using
470 * the information in the SDRAM scratch pad registers
471 */
472 update_sdram_window_sizes();
473 }
Stefan Roese41e5ee52014-10-22 12:13:17 +0200474
475 /*
476 * Finally the mbus windows can be configured with the
477 * updated SDRAM sizes
478 */
479 mvebu_mbus_probe(windows, ARRAY_SIZE(windows));
480
Pali Rohár33089332022-07-15 10:13:12 +0200481 if (IS_ENABLED(CONFIG_ARMADA_XP)) {
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200482 /* Enable GBE0, GBE1, LCD and NFC PUP */
483 clrsetbits_le32(ARMADA_XP_PUP_ENABLE, 0,
484 GE0_PUP_EN | GE1_PUP_EN | LCD_PUP_EN |
485 NAND_PUP_EN | SPI_PUP_EN);
Stefan Roesedee40d22015-07-22 18:26:13 +0200486
487 /* Configure USB PLL and PHYs on AXP */
488 setup_usb_phys();
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200489 }
490
491 /* Enable NAND and NAND arbiter */
492 clrsetbits_le32(MVEBU_SOC_DEV_MUX_REG, 0, NAND_EN | NAND_ARBITER_EN);
493
Stefan Roese501c0982015-07-01 13:28:39 +0200494 /* Disable MBUS error propagation */
495 clrsetbits_le32(SOC_COHERENCY_FABRIC_CTRL_REG, MBUS_ERR_PROP_EN, 0);
496
Stefan Roese41e5ee52014-10-22 12:13:17 +0200497 return 0;
498}
499#endif /* CONFIG_ARCH_CPU_INIT */
500
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200501u32 mvebu_get_nand_clock(void)
502{
Chris Packhamd7b47312016-08-22 12:38:39 +1200503 u32 reg;
504
Pali Rohár33089332022-07-15 10:13:12 +0200505 if (IS_ENABLED(CONFIG_ARMADA_38X))
Chris Packhamd7b47312016-08-22 12:38:39 +1200506 reg = MVEBU_DFX_DIV_CLK_CTRL(1);
Pali Rohár33089332022-07-15 10:13:12 +0200507 else if (IS_ENABLED(CONFIG_ARMADA_MSYS))
Chris Packham689f9cf2019-04-11 22:22:51 +1200508 reg = MVEBU_DFX_DIV_CLK_CTRL(8);
Chris Packhamd7b47312016-08-22 12:38:39 +1200509 else
510 reg = MVEBU_CORE_DIV_CLK_CTRL(1);
511
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200512 return CONFIG_SYS_MVEBU_PLL_CLOCK /
Chris Packhamd7b47312016-08-22 12:38:39 +1200513 ((readl(reg) &
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200514 NAND_ECC_DIVCKL_RATIO_MASK) >> NAND_ECC_DIVCKL_RATIO_OFFS);
515}
516
Stefan Roese41e5ee52014-10-22 12:13:17 +0200517/*
518 * SOC specific misc init
519 */
520#if defined(CONFIG_ARCH_MISC_INIT)
521int arch_misc_init(void)
522{
523 /* Nothing yet, perhaps we need something here later */
524 return 0;
525}
526#endif /* CONFIG_ARCH_MISC_INIT */
527
Pierre Bourdon4ec9dd42019-04-11 04:56:58 +0200528#if defined(CONFIG_MMC_SDHCI_MV) && !defined(CONFIG_DM_MMC)
Masahiro Yamadab75d8dc2020-06-26 15:13:33 +0900529int board_mmc_init(struct bd_info *bis)
Stefan Roese7f1adcd2015-06-29 14:58:10 +0200530{
531 mv_sdh_init(MVEBU_SDIO_BASE, 0, 0,
532 SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_WAIT_SEND_CMD);
533
534 return 0;
535}
536#endif
537
Stefan Roese4d991cb2015-06-29 14:58:13 +0200538#define AHCI_VENDOR_SPECIFIC_0_ADDR 0xa0
539#define AHCI_VENDOR_SPECIFIC_0_DATA 0xa4
540
541#define AHCI_WINDOW_CTRL(win) (0x60 + ((win) << 4))
542#define AHCI_WINDOW_BASE(win) (0x64 + ((win) << 4))
543#define AHCI_WINDOW_SIZE(win) (0x68 + ((win) << 4))
544
545static void ahci_mvebu_mbus_config(void __iomem *base)
546{
547 const struct mbus_dram_target_info *dram;
548 int i;
549
Baruch Siachf0aa1252019-05-16 13:03:57 +0300550 /* mbus is not initialized in SPL; keep the ROM settings */
551 if (IS_ENABLED(CONFIG_SPL_BUILD))
552 return;
553
Stefan Roese4d991cb2015-06-29 14:58:13 +0200554 dram = mvebu_mbus_dram_info();
555
556 for (i = 0; i < 4; i++) {
557 writel(0, base + AHCI_WINDOW_CTRL(i));
558 writel(0, base + AHCI_WINDOW_BASE(i));
559 writel(0, base + AHCI_WINDOW_SIZE(i));
560 }
561
562 for (i = 0; i < dram->num_cs; i++) {
563 const struct mbus_dram_window *cs = dram->cs + i;
564
565 writel((cs->mbus_attr << 8) |
566 (dram->mbus_dram_target_id << 4) | 1,
567 base + AHCI_WINDOW_CTRL(i));
568 writel(cs->base >> 16, base + AHCI_WINDOW_BASE(i));
569 writel(((cs->size - 1) & 0xffff0000),
570 base + AHCI_WINDOW_SIZE(i));
571 }
572}
573
574static void ahci_mvebu_regret_option(void __iomem *base)
575{
576 /*
577 * Enable the regret bit to allow the SATA unit to regret a
578 * request that didn't receive an acknowlegde and avoid a
579 * deadlock
580 */
581 writel(0x4, base + AHCI_VENDOR_SPECIFIC_0_ADDR);
582 writel(0x80, base + AHCI_VENDOR_SPECIFIC_0_DATA);
583}
584
Baruch Siach4b11e5f2019-03-24 13:27:43 +0200585int board_ahci_enable(void)
586{
587 ahci_mvebu_mbus_config((void __iomem *)MVEBU_SATA0_BASE);
588 ahci_mvebu_regret_option((void __iomem *)MVEBU_SATA0_BASE);
589
590 return 0;
591}
592
593#ifdef CONFIG_SCSI_AHCI_PLAT
Stefan Roese4d991cb2015-06-29 14:58:13 +0200594void scsi_init(void)
595{
596 printf("MVEBU SATA INIT\n");
Baruch Siach4b11e5f2019-03-24 13:27:43 +0200597 board_ahci_enable();
Stefan Roese4d991cb2015-06-29 14:58:13 +0200598 ahci_init((void __iomem *)MVEBU_SATA0_BASE);
599}
600#endif
601
Jon Nettleton78aa0182017-11-06 10:33:20 +0200602#ifdef CONFIG_USB_XHCI_MVEBU
603#define USB3_MAX_WINDOWS 4
604#define USB3_WIN_CTRL(w) (0x0 + ((w) * 8))
605#define USB3_WIN_BASE(w) (0x4 + ((w) * 8))
606
607static void xhci_mvebu_mbus_config(void __iomem *base,
608 const struct mbus_dram_target_info *dram)
609{
610 int i;
611
612 for (i = 0; i < USB3_MAX_WINDOWS; i++) {
613 writel(0, base + USB3_WIN_CTRL(i));
614 writel(0, base + USB3_WIN_BASE(i));
615 }
616
617 for (i = 0; i < dram->num_cs; i++) {
618 const struct mbus_dram_window *cs = dram->cs + i;
619
620 /* Write size, attributes and target id to control register */
621 writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
622 (dram->mbus_dram_target_id << 4) | 1,
623 base + USB3_WIN_CTRL(i));
624
625 /* Write base address to base register */
626 writel((cs->base & 0xffff0000), base + USB3_WIN_BASE(i));
627 }
628}
629
630int board_xhci_enable(fdt_addr_t base)
631{
632 const struct mbus_dram_target_info *dram;
633
634 printf("MVEBU XHCI INIT controller @ 0x%lx\n", base);
635
636 dram = mvebu_mbus_dram_info();
637 xhci_mvebu_mbus_config((void __iomem *)base, dram);
638
639 return 0;
640}
641#endif
642
Stefan Roese41e5ee52014-10-22 12:13:17 +0200643void enable_caches(void)
644{
Stefan Roese60b75322015-04-25 06:29:55 +0200645 /* Avoid problem with e.g. neta ethernet driver */
646 invalidate_dcache_all();
647
Stefan Roeseebe78902016-02-10 09:18:46 +0100648 /*
649 * Armada 375 still has some problems with d-cache enabled in the
650 * ethernet driver (mvpp2). So lets keep the d-cache disabled
651 * until this is solved.
652 */
Pali Rohár117ef652022-09-08 16:06:50 +0200653 if (!IS_ENABLED(CONFIG_ARMADA_375)) {
Stefan Roeseebe78902016-02-10 09:18:46 +0100654 /* Enable D-cache. I-cache is already enabled in start.S */
655 dcache_enable();
656 }
Stefan Roese41e5ee52014-10-22 12:13:17 +0200657}
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100658
659void v7_outer_cache_enable(void)
660{
Pali Rohár4f2333b2022-09-08 16:06:53 +0200661 struct pl310_regs *const pl310 =
662 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100663
Pali Rohár4f2333b2022-09-08 16:06:53 +0200664 /* The L2 cache is already disabled at this point */
665
666 /*
667 * For now L2 cache will be enabled only for Armada XP and Armada 38x.
668 * It can be enabled also for other SoCs after testing that it works fine.
669 */
670 if (!IS_ENABLED(CONFIG_ARMADA_XP) && !IS_ENABLED(CONFIG_ARMADA_38X))
671 return;
672
673 if (IS_ENABLED(CONFIG_ARMADA_XP)) {
674 u32 u;
Stefan Roesec86d53f2015-12-03 12:39:45 +0100675
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100676 /*
677 * For Aurora cache in no outer mode, enable via the CP15
678 * coprocessor broadcasting of cache commands to L2.
679 */
680 asm volatile("mrc p15, 1, %0, c15, c2, 0" : "=r" (u));
681 u |= BIT(8); /* Set the FW bit */
682 asm volatile("mcr p15, 1, %0, c15, c2, 0" : : "r" (u));
683
684 isb();
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100685 }
Pali Rohár4f2333b2022-09-08 16:06:53 +0200686
687 /* Enable the L2 cache */
688 setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100689}
Stefan Roesef0e81732015-12-14 12:31:48 +0100690
691void v7_outer_cache_disable(void)
692{
693 struct pl310_regs *const pl310 =
694 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
695
696 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
697}