blob: 77e403ba73a7e12b81234c0a02d363ff0058be59 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roese93e6bf42014-10-22 12:13:17 +02002/*
Stefan Roesec03a2132016-01-07 14:03:11 +01003 * Copyright (C) 2014-2016 Stefan Roese <sr@denx.de>
Stefan Roese93e6bf42014-10-22 12:13:17 +02004 */
5
6#include <common.h>
Stefan Roesebb1c0bd2015-06-29 14:58:13 +02007#include <ahci.h>
Simon Glass1d91ba72019-11-14 12:57:37 -07008#include <cpu_func.h>
Simon Glass97589732020-05-10 11:40:02 -06009#include <init.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060010#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060011#include <linux/delay.h>
Stefan Roesebb1c0bd2015-06-29 14:58:13 +020012#include <linux/mbus.h>
Stefan Roese93e6bf42014-10-22 12:13:17 +020013#include <asm/io.h>
Stefan Roese8aee4d32015-05-18 16:09:43 +000014#include <asm/pl310.h>
Stefan Roese93e6bf42014-10-22 12:13:17 +020015#include <asm/arch/cpu.h>
16#include <asm/arch/soc.h>
Marek Behúnee76b4a2021-08-16 15:19:37 +020017#include <asm/spl.h>
Stefan Roesed3e34732015-06-29 14:58:10 +020018#include <sdhci.h>
Stefan Roese93e6bf42014-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ár32301ee2022-09-09 14:41:28 +020023static const struct mbus_win windows[] = {
Stefan Roese93e6bf42014-10-22 12:13:17 +020024 /* SPI */
Stefan Roese13b109f2015-07-01 12:55:07 +020025 { MBUS_SPI_BASE, MBUS_SPI_SIZE,
26 CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_SPIFLASH },
Stefan Roese93e6bf42014-10-22 12:13:17 +020027
28 /* NOR */
Stefan Roese13b109f2015-07-01 12:55:07 +020029 { MBUS_BOOTROM_BASE, MBUS_BOOTROM_SIZE,
30 CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_BOOTROM },
Chris Packhama8f845e2019-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 Roese93e6bf42014-10-22 12:13:17 +020036};
37
Stefan Roesee1b7bfd2015-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 Seiler6f14d5f2020-12-15 16:47:52 +010046void reset_cpu(void)
Stefan Roese93e6bf42014-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únee76b4a2021-08-16 15:19:37 +020057u32 get_boot_device(void)
58{
59 u32 val;
60 u32 boot_device;
61
62 /*
Tom Rinib056ce402021-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 Rini3327dd72022-03-30 18:07:12 -040067 val = readl(BOOTROM_ERR_REG);
Marek Behúnee76b4a2021-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 Rinib056ce402021-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únee76b4a2021-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 Rinib056ce402021-09-01 07:52:08 -040084 * Now check the SAR register for the strapped boot-device
85 */
Marek Behúnee76b4a2021-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 Roese93e6bf42014-10-22 12:13:17 +0200116#if defined(CONFIG_DISPLAY_CPUINFO)
Stefan Roese2a539c82015-12-21 12:36:40 +0100117
Stefan Roese479f9af2016-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 Roesec03a2132016-01-07 14:03:11 +0100154/* SAR frequency values for Armada 38x */
Stefan Roese32139c32016-01-07 14:04:51 +0100155static const struct sar_freq_modes sar_freq_tab[] = {
Chris Packham5ccd14e2017-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 Roese2a539c82015-12-21 12:36:40 +0100165};
Chris Packhama8f845e2019-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 Roese2a539c82015-12-21 12:36:40 +0100174#else
Stefan Roesec03a2132016-01-07 14:03:11 +0100175/* SAR frequency values for Armada XP */
Stefan Roese32139c32016-01-07 14:04:51 +0100176static const struct sar_freq_modes sar_freq_tab[] = {
Stefan Roese2a539c82015-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 Packhama8f845e2019-04-11 22:22:50 +1200197#if defined(CONFIG_ARMADA_375) || defined(CONFIG_ARMADA_MSYS)
Stefan Roese479f9af2016-02-10 07:23:00 +0100198 val = readl(CONFIG_SAR2_REG); /* SAR - Sample At Reset */
199#else
Stefan Roese2a539c82015-12-21 12:36:40 +0100200 val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */
Stefan Roese479f9af2016-02-10 07:23:00 +0100201#endif
Stefan Roese2a539c82015-12-21 12:36:40 +0100202 freq = (val & SAR_CPU_FREQ_MASK) >> SAR_CPU_FREQ_OFFS;
Stefan Roese479f9af2016-02-10 07:23:00 +0100203#if defined(SAR2_CPU_FREQ_MASK)
Stefan Roese2a539c82015-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 Packhama8f845e2019-04-11 22:22:50 +1200213#if defined(CONFIG_ARMADA_375) || defined(CONFIG_ARMADA_38X) || defined(CONFIG_ARMADA_MSYS)
Stefan Roese2a539c82015-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 Roese93e6bf42014-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 Roese2a539c82015-12-21 12:36:40 +0100241 struct sar_freq_modes sar_freq;
Stefan Roese93e6bf42014-10-22 12:13:17 +0200242
243 puts("SoC: ");
244
245 switch (devid) {
Phil Sutter22e553e2015-12-25 14:41:24 +0100246 case SOC_MV78230_ID:
247 puts("MV78230-");
248 break;
Stefan Roeseb158f372015-12-09 11:00:51 +0100249 case SOC_MV78260_ID:
250 puts("MV78260-");
251 break;
Stefan Roese93e6bf42014-10-22 12:13:17 +0200252 case SOC_MV78460_ID:
253 puts("MV78460-");
254 break;
Stefan Roese479f9af2016-02-10 07:23:00 +0100255 case SOC_88F6720_ID:
256 puts("MV88F6720-");
257 break;
Stefan Roese174d23e2015-04-25 06:29:51 +0200258 case SOC_88F6810_ID:
259 puts("MV88F6810-");
Stefan Roese93e6bf42014-10-22 12:13:17 +0200260 break;
Stefan Roese174d23e2015-04-25 06:29:51 +0200261 case SOC_88F6820_ID:
262 puts("MV88F6820-");
Stefan Roese93e6bf42014-10-22 12:13:17 +0200263 break;
Stefan Roese174d23e2015-04-25 06:29:51 +0200264 case SOC_88F6828_ID:
265 puts("MV88F6828-");
Stefan Roese93e6bf42014-10-22 12:13:17 +0200266 break;
Chris Packham348109d2017-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 Roese93e6bf42014-10-22 12:13:17 +0200276 default:
Stefan Roese174d23e2015-04-25 06:29:51 +0200277 puts("Unknown-");
Stefan Roese93e6bf42014-10-22 12:13:17 +0200278 break;
279 }
280
Pali Rohárfdf415c2022-07-15 10:13:12 +0200281 switch (devid) {
282 case SOC_MV78230_ID:
283 case SOC_MV78260_ID:
284 case SOC_MV78460_ID:
Stefan Roese174d23e2015-04-25 06:29:51 +0200285 switch (revid) {
286 case 1:
Stefan Roese2a539c82015-12-21 12:36:40 +0100287 puts("A0");
Stefan Roese174d23e2015-04-25 06:29:51 +0200288 break;
289 case 2:
Stefan Roese2a539c82015-12-21 12:36:40 +0100290 puts("B0");
Stefan Roese174d23e2015-04-25 06:29:51 +0200291 break;
292 default:
Stefan Roese2a539c82015-12-21 12:36:40 +0100293 printf("?? (%x)", revid);
Stefan Roese174d23e2015-04-25 06:29:51 +0200294 break;
295 }
Pali Rohárfdf415c2022-07-15 10:13:12 +0200296 break;
Stefan Roese174d23e2015-04-25 06:29:51 +0200297
Pali Rohárfdf415c2022-07-15 10:13:12 +0200298 case SOC_88F6720_ID:
Stefan Roese479f9af2016-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árfdf415c2022-07-15 10:13:12 +0200307 break;
Stefan Roese479f9af2016-02-10 07:23:00 +0100308
Pali Rohárfdf415c2022-07-15 10:13:12 +0200309 case SOC_88F6810_ID:
310 case SOC_88F6820_ID:
311 case SOC_88F6828_ID:
Stefan Roese174d23e2015-04-25 06:29:51 +0200312 switch (revid) {
313 case MV_88F68XX_Z1_ID:
Stefan Roese2a539c82015-12-21 12:36:40 +0100314 puts("Z1");
Stefan Roese174d23e2015-04-25 06:29:51 +0200315 break;
316 case MV_88F68XX_A0_ID:
Stefan Roese2a539c82015-12-21 12:36:40 +0100317 puts("A0");
Stefan Roese174d23e2015-04-25 06:29:51 +0200318 break;
Chris Packhamec4510b2018-11-28 10:32:00 +1300319 case MV_88F68XX_B0_ID:
320 puts("B0");
321 break;
Stefan Roese174d23e2015-04-25 06:29:51 +0200322 default:
Stefan Roese2a539c82015-12-21 12:36:40 +0100323 printf("?? (%x)", revid);
Stefan Roese174d23e2015-04-25 06:29:51 +0200324 break;
325 }
Pali Rohárfdf415c2022-07-15 10:13:12 +0200326 break;
Stefan Roese174d23e2015-04-25 06:29:51 +0200327
Pali Rohárfdf415c2022-07-15 10:13:12 +0200328 case SOC_98DX3236_ID:
329 case SOC_98DX3336_ID:
330 case SOC_98DX4251_ID:
Chris Packhama8f845e2019-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árfdf415c2022-07-15 10:13:12 +0200342 break;
343
344 default:
345 printf("?? (%x)", revid);
346 break;
Chris Packhama8f845e2019-04-11 22:22:50 +1200347 }
348
Stefan Roese2a539c82015-12-21 12:36:40 +0100349 get_sar_freq(&sar_freq);
350 printf(" at %d MHz\n", sar_freq.p_clk);
351
Stefan Roese93e6bf42014-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 Packham1cd77b02018-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 Roese93e6bf42014-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 Roesef43d3232015-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 Roese0b1d5372015-12-04 13:08:34 +0100422 setbits_le32(MV_USB_PHY_PLL_REG(2), BIT(9));
Stefan Roesef43d3232015-07-22 18:26:13 +0200423
424 /* Assert VCOCAL_START */
Stefan Roese0b1d5372015-12-04 13:08:34 +0100425 setbits_le32(MV_USB_PHY_PLL_REG(1), BIT(21));
Stefan Roesef43d3232015-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 Roese0b1d5372015-12-04 13:08:34 +0100434 setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 3), BIT(15));
Stefan Roesef43d3232015-07-22 18:26:13 +0200435
436 /* Assert REG_RCAL_START in channel REG 1 */
Stefan Roese0b1d5372015-12-04 13:08:34 +0100437 setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
Stefan Roesef43d3232015-07-22 18:26:13 +0200438 udelay(40);
Stefan Roese0b1d5372015-12-04 13:08:34 +0100439 clrbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
Stefan Roesef43d3232015-07-22 18:26:13 +0200440 }
441}
Kevin Smith1ddff022015-05-18 16:09:44 +0000442
Stefan Roesee7c72282015-12-03 12:39:45 +0100443/*
444 * This function is not called from the SPL U-Boot version
445 */
Stefan Roese93e6bf42014-10-22 12:13:17 +0200446int arch_cpu_init(void)
447{
Stefan Roesee1b7bfd2015-08-25 14:09:12 +0200448 struct pl310_regs *const pl310 =
449 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
450
Pali Rohár6f90ffc2022-09-08 16:06:51 +0200451 if (!IS_ENABLED(CONFIG_ARMADA_XP)) {
Stefan Roesecaf74c92015-12-03 12:39:45 +0100452 /*
453 * To fully release / unlock this area from cache, we need
454 * to flush all caches and disable the L2 cache.
455 */
456 icache_disable();
457 dcache_disable();
458 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
459 }
Stefan Roese73acffe2015-04-24 10:49:11 +0200460
Stefan Roese93e6bf42014-10-22 12:13:17 +0200461 /*
462 * We need to call mvebu_mbus_probe() before calling
463 * update_sdram_window_sizes() as it disables all previously
464 * configured mbus windows and then configures them as
465 * required for U-Boot. Calling update_sdram_window_sizes()
466 * without this configuration will not work, as the internal
467 * registers can't be accessed reliably because of potenial
468 * double mapping.
469 * After updating the SDRAM access windows we need to call
470 * mvebu_mbus_probe() again, as this now correctly configures
471 * the SDRAM areas that are later used by the MVEBU drivers
472 * (e.g. USB, NETA).
473 */
474
475 /*
476 * First disable all windows
477 */
478 mvebu_mbus_probe(NULL, 0);
479
Pali Rohárfdf415c2022-07-15 10:13:12 +0200480 if (IS_ENABLED(CONFIG_ARMADA_XP)) {
Stefan Roese174d23e2015-04-25 06:29:51 +0200481 /*
482 * Now the SDRAM access windows can be reconfigured using
483 * the information in the SDRAM scratch pad registers
484 */
485 update_sdram_window_sizes();
486 }
Stefan Roese93e6bf42014-10-22 12:13:17 +0200487
488 /*
489 * Finally the mbus windows can be configured with the
490 * updated SDRAM sizes
491 */
492 mvebu_mbus_probe(windows, ARRAY_SIZE(windows));
493
Pali Rohárfdf415c2022-07-15 10:13:12 +0200494 if (IS_ENABLED(CONFIG_ARMADA_XP)) {
Stefan Roesebadccc32015-07-16 10:40:05 +0200495 /* Enable GBE0, GBE1, LCD and NFC PUP */
496 clrsetbits_le32(ARMADA_XP_PUP_ENABLE, 0,
497 GE0_PUP_EN | GE1_PUP_EN | LCD_PUP_EN |
498 NAND_PUP_EN | SPI_PUP_EN);
Stefan Roesef43d3232015-07-22 18:26:13 +0200499
500 /* Configure USB PLL and PHYs on AXP */
501 setup_usb_phys();
Stefan Roesebadccc32015-07-16 10:40:05 +0200502 }
503
504 /* Enable NAND and NAND arbiter */
505 clrsetbits_le32(MVEBU_SOC_DEV_MUX_REG, 0, NAND_EN | NAND_ARBITER_EN);
506
Stefan Roese8ac6dab2015-07-01 13:28:39 +0200507 /* Disable MBUS error propagation */
508 clrsetbits_le32(SOC_COHERENCY_FABRIC_CTRL_REG, MBUS_ERR_PROP_EN, 0);
509
Stefan Roese93e6bf42014-10-22 12:13:17 +0200510 return 0;
511}
512#endif /* CONFIG_ARCH_CPU_INIT */
513
Stefan Roesebadccc32015-07-16 10:40:05 +0200514u32 mvebu_get_nand_clock(void)
515{
Chris Packham460086e2016-08-22 12:38:39 +1200516 u32 reg;
517
Pali Rohárfdf415c2022-07-15 10:13:12 +0200518 if (IS_ENABLED(CONFIG_ARMADA_38X))
Chris Packham460086e2016-08-22 12:38:39 +1200519 reg = MVEBU_DFX_DIV_CLK_CTRL(1);
Pali Rohárfdf415c2022-07-15 10:13:12 +0200520 else if (IS_ENABLED(CONFIG_ARMADA_MSYS))
Chris Packham7ce3f8c2019-04-11 22:22:51 +1200521 reg = MVEBU_DFX_DIV_CLK_CTRL(8);
Chris Packham460086e2016-08-22 12:38:39 +1200522 else
523 reg = MVEBU_CORE_DIV_CLK_CTRL(1);
524
Stefan Roesebadccc32015-07-16 10:40:05 +0200525 return CONFIG_SYS_MVEBU_PLL_CLOCK /
Chris Packham460086e2016-08-22 12:38:39 +1200526 ((readl(reg) &
Stefan Roesebadccc32015-07-16 10:40:05 +0200527 NAND_ECC_DIVCKL_RATIO_MASK) >> NAND_ECC_DIVCKL_RATIO_OFFS);
528}
529
Stefan Roese93e6bf42014-10-22 12:13:17 +0200530/*
531 * SOC specific misc init
532 */
533#if defined(CONFIG_ARCH_MISC_INIT)
534int arch_misc_init(void)
535{
536 /* Nothing yet, perhaps we need something here later */
537 return 0;
538}
539#endif /* CONFIG_ARCH_MISC_INIT */
540
Pierre Bourdonb9af62d2019-04-11 04:56:58 +0200541#if defined(CONFIG_MMC_SDHCI_MV) && !defined(CONFIG_DM_MMC)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900542int board_mmc_init(struct bd_info *bis)
Stefan Roesed3e34732015-06-29 14:58:10 +0200543{
544 mv_sdh_init(MVEBU_SDIO_BASE, 0, 0,
545 SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_WAIT_SEND_CMD);
546
547 return 0;
548}
549#endif
550
Stefan Roesebb1c0bd2015-06-29 14:58:13 +0200551#define AHCI_VENDOR_SPECIFIC_0_ADDR 0xa0
552#define AHCI_VENDOR_SPECIFIC_0_DATA 0xa4
553
554#define AHCI_WINDOW_CTRL(win) (0x60 + ((win) << 4))
555#define AHCI_WINDOW_BASE(win) (0x64 + ((win) << 4))
556#define AHCI_WINDOW_SIZE(win) (0x68 + ((win) << 4))
557
558static void ahci_mvebu_mbus_config(void __iomem *base)
559{
560 const struct mbus_dram_target_info *dram;
561 int i;
562
Baruch Siach2179c772019-05-16 13:03:57 +0300563 /* mbus is not initialized in SPL; keep the ROM settings */
564 if (IS_ENABLED(CONFIG_SPL_BUILD))
565 return;
566
Stefan Roesebb1c0bd2015-06-29 14:58:13 +0200567 dram = mvebu_mbus_dram_info();
568
569 for (i = 0; i < 4; i++) {
570 writel(0, base + AHCI_WINDOW_CTRL(i));
571 writel(0, base + AHCI_WINDOW_BASE(i));
572 writel(0, base + AHCI_WINDOW_SIZE(i));
573 }
574
575 for (i = 0; i < dram->num_cs; i++) {
576 const struct mbus_dram_window *cs = dram->cs + i;
577
578 writel((cs->mbus_attr << 8) |
579 (dram->mbus_dram_target_id << 4) | 1,
580 base + AHCI_WINDOW_CTRL(i));
581 writel(cs->base >> 16, base + AHCI_WINDOW_BASE(i));
582 writel(((cs->size - 1) & 0xffff0000),
583 base + AHCI_WINDOW_SIZE(i));
584 }
585}
586
587static void ahci_mvebu_regret_option(void __iomem *base)
588{
589 /*
590 * Enable the regret bit to allow the SATA unit to regret a
591 * request that didn't receive an acknowlegde and avoid a
592 * deadlock
593 */
594 writel(0x4, base + AHCI_VENDOR_SPECIFIC_0_ADDR);
595 writel(0x80, base + AHCI_VENDOR_SPECIFIC_0_DATA);
596}
597
Baruch Siachb590a142019-03-24 13:27:43 +0200598int board_ahci_enable(void)
Stefan Roesebb1c0bd2015-06-29 14:58:13 +0200599{
Stefan Roesebb1c0bd2015-06-29 14:58:13 +0200600 ahci_mvebu_mbus_config((void __iomem *)MVEBU_SATA0_BASE);
601 ahci_mvebu_regret_option((void __iomem *)MVEBU_SATA0_BASE);
Baruch Siachb590a142019-03-24 13:27:43 +0200602
603 return 0;
604}
605
606#ifdef CONFIG_SCSI_AHCI_PLAT
607void scsi_init(void)
608{
609 printf("MVEBU SATA INIT\n");
610 board_ahci_enable();
Stefan Roesebb1c0bd2015-06-29 14:58:13 +0200611 ahci_init((void __iomem *)MVEBU_SATA0_BASE);
612}
613#endif
614
Jon Nettleton86502322017-11-06 10:33:20 +0200615#ifdef CONFIG_USB_XHCI_MVEBU
616#define USB3_MAX_WINDOWS 4
617#define USB3_WIN_CTRL(w) (0x0 + ((w) * 8))
618#define USB3_WIN_BASE(w) (0x4 + ((w) * 8))
619
620static void xhci_mvebu_mbus_config(void __iomem *base,
621 const struct mbus_dram_target_info *dram)
622{
623 int i;
624
625 for (i = 0; i < USB3_MAX_WINDOWS; i++) {
626 writel(0, base + USB3_WIN_CTRL(i));
627 writel(0, base + USB3_WIN_BASE(i));
628 }
629
630 for (i = 0; i < dram->num_cs; i++) {
631 const struct mbus_dram_window *cs = dram->cs + i;
632
633 /* Write size, attributes and target id to control register */
634 writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
635 (dram->mbus_dram_target_id << 4) | 1,
636 base + USB3_WIN_CTRL(i));
637
638 /* Write base address to base register */
639 writel((cs->base & 0xffff0000), base + USB3_WIN_BASE(i));
640 }
641}
642
643int board_xhci_enable(fdt_addr_t base)
644{
645 const struct mbus_dram_target_info *dram;
646
647 printf("MVEBU XHCI INIT controller @ 0x%lx\n", base);
648
649 dram = mvebu_mbus_dram_info();
650 xhci_mvebu_mbus_config((void __iomem *)base, dram);
651
652 return 0;
653}
654#endif
655
Stefan Roese93e6bf42014-10-22 12:13:17 +0200656void enable_caches(void)
657{
Stefan Roese7a4a5ba2015-04-25 06:29:55 +0200658 /* Avoid problem with e.g. neta ethernet driver */
659 invalidate_dcache_all();
660
Stefan Roesedafe60f2016-02-10 09:18:46 +0100661 /*
662 * Armada 375 still has some problems with d-cache enabled in the
663 * ethernet driver (mvpp2). So lets keep the d-cache disabled
664 * until this is solved.
665 */
Pali Rohárb94cb132022-09-08 16:06:50 +0200666 if (!IS_ENABLED(CONFIG_ARMADA_375)) {
Stefan Roesedafe60f2016-02-10 09:18:46 +0100667 /* Enable D-cache. I-cache is already enabled in start.S */
668 dcache_enable();
669 }
Stefan Roese93e6bf42014-10-22 12:13:17 +0200670}
Stefan Roese479a9772015-12-03 12:39:45 +0100671
672void v7_outer_cache_enable(void)
673{
Pali Rohár2100c4d2022-09-08 16:06:53 +0200674 struct pl310_regs *const pl310 =
675 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
676
677 /* The L2 cache is already disabled at this point */
678
679 /*
680 * For now L2 cache will be enabled only for Armada XP and Armada 38x.
681 * It can be enabled also for other SoCs after testing that it works fine.
682 */
683 if (!IS_ENABLED(CONFIG_ARMADA_XP) && !IS_ENABLED(CONFIG_ARMADA_38X))
684 return;
685
Pali Rohárfdf415c2022-07-15 10:13:12 +0200686 if (IS_ENABLED(CONFIG_ARMADA_XP)) {
Stefan Roese479a9772015-12-03 12:39:45 +0100687 u32 u;
688
689 /*
690 * For Aurora cache in no outer mode, enable via the CP15
691 * coprocessor broadcasting of cache commands to L2.
692 */
693 asm volatile("mrc p15, 1, %0, c15, c2, 0" : "=r" (u));
694 u |= BIT(8); /* Set the FW bit */
695 asm volatile("mcr p15, 1, %0, c15, c2, 0" : : "r" (u));
696
697 isb();
Stefan Roese479a9772015-12-03 12:39:45 +0100698 }
Pali Rohár2100c4d2022-09-08 16:06:53 +0200699
700 /* Enable the L2 cache */
701 setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
Stefan Roese479a9772015-12-03 12:39:45 +0100702}
Stefan Roese77b299c2015-12-14 12:31:48 +0100703
704void v7_outer_cache_disable(void)
705{
706 struct pl310_regs *const pl310 =
707 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
708
709 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
710}