blob: 0272dd7352d85ffb31a5fac69cc653f6b3ca0a51 [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
23static 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
Stefan Roese174d23e2015-04-25 06:29:51 +020057int mvebu_soc_family(void)
58{
59 u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
60
Phil Sutter22e553e2015-12-25 14:41:24 +010061 switch (devid) {
62 case SOC_MV78230_ID:
63 case SOC_MV78260_ID:
64 case SOC_MV78460_ID:
Stefan Roese174d23e2015-04-25 06:29:51 +020065 return MVEBU_SOC_AXP;
Stefan Roese479f9af2016-02-10 07:23:00 +010066
67 case SOC_88F6720_ID:
68 return MVEBU_SOC_A375;
69
Phil Sutter22e553e2015-12-25 14:41:24 +010070 case SOC_88F6810_ID:
71 case SOC_88F6820_ID:
72 case SOC_88F6828_ID:
Stefan Roese174d23e2015-04-25 06:29:51 +020073 return MVEBU_SOC_A38X;
Chris Packham348109d2017-09-04 17:38:31 +120074
75 case SOC_98DX3236_ID:
76 case SOC_98DX3336_ID:
77 case SOC_98DX4251_ID:
78 return MVEBU_SOC_MSYS;
Phil Sutter22e553e2015-12-25 14:41:24 +010079 }
Stefan Roese479f9af2016-02-10 07:23:00 +010080
Stefan Roese174d23e2015-04-25 06:29:51 +020081 return MVEBU_SOC_UNKNOWN;
82}
83
Marek Behúnee76b4a2021-08-16 15:19:37 +020084u32 get_boot_device(void)
85{
86 u32 val;
87 u32 boot_device;
88
89 /*
Tom Rinib056ce402021-09-01 07:52:08 -040090 * First check, if UART boot-mode is active. This can only
91 * be done, via the bootrom error register. Here the
92 * MSB marks if the UART mode is active.
93 */
Marek Behúnee76b4a2021-08-16 15:19:37 +020094 val = readl(CONFIG_BOOTROM_ERR_REG);
95 boot_device = (val & BOOTROM_ERR_MODE_MASK) >> BOOTROM_ERR_MODE_OFFS;
96 debug("BOOTROM_REG=0x%08x boot_device=0x%x\n", val, boot_device);
97 if (boot_device == BOOTROM_ERR_MODE_UART)
98 return BOOT_DEVICE_UART;
99
100#ifdef CONFIG_ARMADA_38X
101 /*
Tom Rinib056ce402021-09-01 07:52:08 -0400102 * If the bootrom error code contains any other than zeros it's an
103 * error condition and the bootROM has fallen back to UART boot
104 */
Marek Behúnee76b4a2021-08-16 15:19:37 +0200105 boot_device = (val & BOOTROM_ERR_CODE_MASK) >> BOOTROM_ERR_CODE_OFFS;
106 if (boot_device)
107 return BOOT_DEVICE_UART;
108#endif
109
110 /*
Tom Rinib056ce402021-09-01 07:52:08 -0400111 * Now check the SAR register for the strapped boot-device
112 */
Marek Behúnee76b4a2021-08-16 15:19:37 +0200113 val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */
114 boot_device = (val & BOOT_DEV_SEL_MASK) >> BOOT_DEV_SEL_OFFS;
115 debug("SAR_REG=0x%08x boot_device=0x%x\n", val, boot_device);
116 switch (boot_device) {
117#ifdef BOOT_FROM_NAND
118 case BOOT_FROM_NAND:
119 return BOOT_DEVICE_NAND;
120#endif
121#ifdef BOOT_FROM_MMC
122 case BOOT_FROM_MMC:
123 case BOOT_FROM_MMC_ALT:
124 return BOOT_DEVICE_MMC1;
125#endif
126 case BOOT_FROM_UART:
127#ifdef BOOT_FROM_UART_ALT
128 case BOOT_FROM_UART_ALT:
129#endif
130 return BOOT_DEVICE_UART;
131#ifdef BOOT_FROM_SATA
132 case BOOT_FROM_SATA:
133 case BOOT_FROM_SATA_ALT:
134 return BOOT_DEVICE_SATA;
135#endif
136 case BOOT_FROM_SPI:
137 return BOOT_DEVICE_SPI;
138 default:
139 return BOOT_DEVICE_BOOTROM;
140 };
141}
142
Stefan Roese93e6bf42014-10-22 12:13:17 +0200143#if defined(CONFIG_DISPLAY_CPUINFO)
Stefan Roese2a539c82015-12-21 12:36:40 +0100144
Stefan Roese479f9af2016-02-10 07:23:00 +0100145#if defined(CONFIG_ARMADA_375)
146/* SAR frequency values for Armada 375 */
147static const struct sar_freq_modes sar_freq_tab[] = {
148 { 0, 0x0, 266, 133, 266 },
149 { 1, 0x0, 333, 167, 167 },
150 { 2, 0x0, 333, 167, 222 },
151 { 3, 0x0, 333, 167, 333 },
152 { 4, 0x0, 400, 200, 200 },
153 { 5, 0x0, 400, 200, 267 },
154 { 6, 0x0, 400, 200, 400 },
155 { 7, 0x0, 500, 250, 250 },
156 { 8, 0x0, 500, 250, 334 },
157 { 9, 0x0, 500, 250, 500 },
158 { 10, 0x0, 533, 267, 267 },
159 { 11, 0x0, 533, 267, 356 },
160 { 12, 0x0, 533, 267, 533 },
161 { 13, 0x0, 600, 300, 300 },
162 { 14, 0x0, 600, 300, 400 },
163 { 15, 0x0, 600, 300, 600 },
164 { 16, 0x0, 666, 333, 333 },
165 { 17, 0x0, 666, 333, 444 },
166 { 18, 0x0, 666, 333, 666 },
167 { 19, 0x0, 800, 400, 267 },
168 { 20, 0x0, 800, 400, 400 },
169 { 21, 0x0, 800, 400, 534 },
170 { 22, 0x0, 900, 450, 300 },
171 { 23, 0x0, 900, 450, 450 },
172 { 24, 0x0, 900, 450, 600 },
173 { 25, 0x0, 1000, 500, 500 },
174 { 26, 0x0, 1000, 500, 667 },
175 { 27, 0x0, 1000, 333, 500 },
176 { 28, 0x0, 400, 400, 400 },
177 { 29, 0x0, 1100, 550, 550 },
178 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
179};
180#elif defined(CONFIG_ARMADA_38X)
Stefan Roesec03a2132016-01-07 14:03:11 +0100181/* SAR frequency values for Armada 38x */
Stefan Roese32139c32016-01-07 14:04:51 +0100182static const struct sar_freq_modes sar_freq_tab[] = {
Chris Packham5ccd14e2017-09-05 17:03:26 +1200183 { 0x0, 0x0, 666, 333, 333 },
184 { 0x2, 0x0, 800, 400, 400 },
185 { 0x4, 0x0, 1066, 533, 533 },
186 { 0x6, 0x0, 1200, 600, 600 },
187 { 0x8, 0x0, 1332, 666, 666 },
188 { 0xc, 0x0, 1600, 800, 800 },
189 { 0x10, 0x0, 1866, 933, 933 },
190 { 0x13, 0x0, 2000, 1000, 933 },
191 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
Stefan Roese2a539c82015-12-21 12:36:40 +0100192};
Chris Packhama8f845e2019-04-11 22:22:50 +1200193#elif defined(CONFIG_ARMADA_MSYS)
194static const struct sar_freq_modes sar_freq_tab[] = {
195 { 0x0, 0x0, 400, 400, 400 },
196 { 0x2, 0x0, 667, 333, 667 },
197 { 0x3, 0x0, 800, 400, 800 },
198 { 0x5, 0x0, 800, 400, 800 },
199 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
200};
Stefan Roese2a539c82015-12-21 12:36:40 +0100201#else
Stefan Roesec03a2132016-01-07 14:03:11 +0100202/* SAR frequency values for Armada XP */
Stefan Roese32139c32016-01-07 14:04:51 +0100203static const struct sar_freq_modes sar_freq_tab[] = {
Stefan Roese2a539c82015-12-21 12:36:40 +0100204 { 0xa, 0x5, 800, 400, 400 },
205 { 0x1, 0x5, 1066, 533, 533 },
206 { 0x2, 0x5, 1200, 600, 600 },
207 { 0x2, 0x9, 1200, 600, 400 },
208 { 0x3, 0x5, 1333, 667, 667 },
209 { 0x4, 0x5, 1500, 750, 750 },
210 { 0x4, 0x9, 1500, 750, 500 },
211 { 0xb, 0x9, 1600, 800, 533 },
212 { 0xb, 0xa, 1600, 800, 640 },
213 { 0xb, 0x5, 1600, 800, 800 },
214 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
215};
216#endif
217
218void get_sar_freq(struct sar_freq_modes *sar_freq)
219{
220 u32 val;
221 u32 freq;
222 int i;
223
Chris Packhama8f845e2019-04-11 22:22:50 +1200224#if defined(CONFIG_ARMADA_375) || defined(CONFIG_ARMADA_MSYS)
Stefan Roese479f9af2016-02-10 07:23:00 +0100225 val = readl(CONFIG_SAR2_REG); /* SAR - Sample At Reset */
226#else
Stefan Roese2a539c82015-12-21 12:36:40 +0100227 val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */
Stefan Roese479f9af2016-02-10 07:23:00 +0100228#endif
Stefan Roese2a539c82015-12-21 12:36:40 +0100229 freq = (val & SAR_CPU_FREQ_MASK) >> SAR_CPU_FREQ_OFFS;
Stefan Roese479f9af2016-02-10 07:23:00 +0100230#if defined(SAR2_CPU_FREQ_MASK)
Stefan Roese2a539c82015-12-21 12:36:40 +0100231 /*
232 * Shift CPU0 clock frequency select bit from SAR2 register
233 * into correct position
234 */
235 freq |= ((readl(CONFIG_SAR2_REG) & SAR2_CPU_FREQ_MASK)
236 >> SAR2_CPU_FREQ_OFFS) << 3;
237#endif
238 for (i = 0; sar_freq_tab[i].val != 0xff; i++) {
239 if (sar_freq_tab[i].val == freq) {
Chris Packhama8f845e2019-04-11 22:22:50 +1200240#if defined(CONFIG_ARMADA_375) || defined(CONFIG_ARMADA_38X) || defined(CONFIG_ARMADA_MSYS)
Stefan Roese2a539c82015-12-21 12:36:40 +0100241 *sar_freq = sar_freq_tab[i];
242 return;
243#else
244 int k;
245 u8 ffc;
246
247 ffc = (val & SAR_FFC_FREQ_MASK) >>
248 SAR_FFC_FREQ_OFFS;
249 for (k = i; sar_freq_tab[k].ffc != 0xff; k++) {
250 if (sar_freq_tab[k].ffc == ffc) {
251 *sar_freq = sar_freq_tab[k];
252 return;
253 }
254 }
255 i = k;
256#endif
257 }
258 }
259
260 /* SAR value not found, return 0 for frequencies */
261 *sar_freq = sar_freq_tab[i - 1];
262}
263
Stefan Roese93e6bf42014-10-22 12:13:17 +0200264int print_cpuinfo(void)
265{
266 u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
267 u8 revid = readl(MVEBU_REG_PCIE_REVID) & 0xff;
Stefan Roese2a539c82015-12-21 12:36:40 +0100268 struct sar_freq_modes sar_freq;
Stefan Roese93e6bf42014-10-22 12:13:17 +0200269
270 puts("SoC: ");
271
272 switch (devid) {
Phil Sutter22e553e2015-12-25 14:41:24 +0100273 case SOC_MV78230_ID:
274 puts("MV78230-");
275 break;
Stefan Roeseb158f372015-12-09 11:00:51 +0100276 case SOC_MV78260_ID:
277 puts("MV78260-");
278 break;
Stefan Roese93e6bf42014-10-22 12:13:17 +0200279 case SOC_MV78460_ID:
280 puts("MV78460-");
281 break;
Stefan Roese479f9af2016-02-10 07:23:00 +0100282 case SOC_88F6720_ID:
283 puts("MV88F6720-");
284 break;
Stefan Roese174d23e2015-04-25 06:29:51 +0200285 case SOC_88F6810_ID:
286 puts("MV88F6810-");
Stefan Roese93e6bf42014-10-22 12:13:17 +0200287 break;
Stefan Roese174d23e2015-04-25 06:29:51 +0200288 case SOC_88F6820_ID:
289 puts("MV88F6820-");
Stefan Roese93e6bf42014-10-22 12:13:17 +0200290 break;
Stefan Roese174d23e2015-04-25 06:29:51 +0200291 case SOC_88F6828_ID:
292 puts("MV88F6828-");
Stefan Roese93e6bf42014-10-22 12:13:17 +0200293 break;
Chris Packham348109d2017-09-04 17:38:31 +1200294 case SOC_98DX3236_ID:
295 puts("98DX3236-");
296 break;
297 case SOC_98DX3336_ID:
298 puts("98DX3336-");
299 break;
300 case SOC_98DX4251_ID:
301 puts("98DX4251-");
302 break;
Stefan Roese93e6bf42014-10-22 12:13:17 +0200303 default:
Stefan Roese174d23e2015-04-25 06:29:51 +0200304 puts("Unknown-");
Stefan Roese93e6bf42014-10-22 12:13:17 +0200305 break;
306 }
307
Stefan Roese174d23e2015-04-25 06:29:51 +0200308 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
309 switch (revid) {
310 case 1:
Stefan Roese2a539c82015-12-21 12:36:40 +0100311 puts("A0");
Stefan Roese174d23e2015-04-25 06:29:51 +0200312 break;
313 case 2:
Stefan Roese2a539c82015-12-21 12:36:40 +0100314 puts("B0");
Stefan Roese174d23e2015-04-25 06:29:51 +0200315 break;
316 default:
Stefan Roese2a539c82015-12-21 12:36:40 +0100317 printf("?? (%x)", revid);
Stefan Roese174d23e2015-04-25 06:29:51 +0200318 break;
319 }
320 }
321
Stefan Roese479f9af2016-02-10 07:23:00 +0100322 if (mvebu_soc_family() == MVEBU_SOC_A375) {
323 switch (revid) {
324 case MV_88F67XX_A0_ID:
325 puts("A0");
326 break;
327 default:
328 printf("?? (%x)", revid);
329 break;
330 }
331 }
332
Stefan Roese174d23e2015-04-25 06:29:51 +0200333 if (mvebu_soc_family() == MVEBU_SOC_A38X) {
334 switch (revid) {
335 case MV_88F68XX_Z1_ID:
Stefan Roese2a539c82015-12-21 12:36:40 +0100336 puts("Z1");
Stefan Roese174d23e2015-04-25 06:29:51 +0200337 break;
338 case MV_88F68XX_A0_ID:
Stefan Roese2a539c82015-12-21 12:36:40 +0100339 puts("A0");
Stefan Roese174d23e2015-04-25 06:29:51 +0200340 break;
Chris Packhamec4510b2018-11-28 10:32:00 +1300341 case MV_88F68XX_B0_ID:
342 puts("B0");
343 break;
Stefan Roese174d23e2015-04-25 06:29:51 +0200344 default:
Stefan Roese2a539c82015-12-21 12:36:40 +0100345 printf("?? (%x)", revid);
Stefan Roese174d23e2015-04-25 06:29:51 +0200346 break;
347 }
348 }
349
Chris Packhama8f845e2019-04-11 22:22:50 +1200350 if (mvebu_soc_family() == MVEBU_SOC_MSYS) {
351 switch (revid) {
352 case 3:
353 puts("A0");
354 break;
355 case 4:
356 puts("A1");
357 break;
358 default:
359 printf("?? (%x)", revid);
360 break;
361 }
362 }
363
Stefan Roese2a539c82015-12-21 12:36:40 +0100364 get_sar_freq(&sar_freq);
365 printf(" at %d MHz\n", sar_freq.p_clk);
366
Stefan Roese93e6bf42014-10-22 12:13:17 +0200367 return 0;
368}
369#endif /* CONFIG_DISPLAY_CPUINFO */
370
371/*
372 * This function initialize Controller DRAM Fastpath windows.
373 * It takes the CS size information from the 0x1500 scratch registers
374 * and sets the correct windows sizes and base addresses accordingly.
375 *
376 * These values are set in the scratch registers by the Marvell
Chris Packham1cd77b02018-12-14 16:27:57 +1300377 * DDR3 training code, which is executed by the SPL before the
378 * main payload (U-Boot) is executed.
Stefan Roese93e6bf42014-10-22 12:13:17 +0200379 */
380static void update_sdram_window_sizes(void)
381{
382 u64 base = 0;
383 u32 size, temp;
384 int i;
385
386 for (i = 0; i < SDRAM_MAX_CS; i++) {
387 size = readl((MVEBU_SDRAM_SCRATCH + (i * 8))) & SDRAM_ADDR_MASK;
388 if (size != 0) {
389 size |= ~(SDRAM_ADDR_MASK);
390
391 /* Set Base Address */
392 temp = (base & 0xFF000000ll) | ((base >> 32) & 0xF);
393 writel(temp, MVEBU_SDRAM_BASE + DDR_BASE_CS_OFF(i));
394
395 /*
396 * Check if out of max window size and resize
397 * the window
398 */
399 temp = (readl(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i)) &
400 ~(SDRAM_ADDR_MASK)) | 1;
401 temp |= (size & SDRAM_ADDR_MASK);
402 writel(temp, MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i));
403
404 base += ((u64)size + 1);
405 } else {
406 /*
407 * Disable window if not used, otherwise this
408 * leads to overlapping enabled windows with
409 * pretty strange results
410 */
411 clrbits_le32(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i), 1);
412 }
413 }
414}
415
Stefan Roese73acffe2015-04-24 10:49:11 +0200416void mmu_disable(void)
417{
418 asm volatile(
419 "mrc p15, 0, r0, c1, c0, 0\n"
420 "bic r0, #1\n"
421 "mcr p15, 0, r0, c1, c0, 0\n");
422}
423
Stefan Roese93e6bf42014-10-22 12:13:17 +0200424#ifdef CONFIG_ARCH_CPU_INIT
Kevin Smith1ddff022015-05-18 16:09:44 +0000425static void set_cbar(u32 addr)
426{
427 asm("mcr p15, 4, %0, c15, c0" : : "r" (addr));
428}
429
Stefan Roesef43d3232015-07-22 18:26:13 +0200430#define MV_USB_PHY_BASE (MVEBU_AXP_USB_BASE + 0x800)
431#define MV_USB_PHY_PLL_REG(reg) (MV_USB_PHY_BASE | (((reg) & 0xF) << 2))
432#define MV_USB_X3_BASE(addr) (MVEBU_AXP_USB_BASE | BIT(11) | \
433 (((addr) & 0xF) << 6))
434#define MV_USB_X3_PHY_CHANNEL(dev, reg) (MV_USB_X3_BASE((dev) + 1) | \
435 (((reg) & 0xF) << 2))
436
437static void setup_usb_phys(void)
438{
439 int dev;
440
441 /*
442 * USB PLL init
443 */
444
445 /* Setup PLL frequency */
446 /* USB REF frequency = 25 MHz */
447 clrsetbits_le32(MV_USB_PHY_PLL_REG(1), 0x3ff, 0x605);
448
449 /* Power up PLL and PHY channel */
Stefan Roese0b1d5372015-12-04 13:08:34 +0100450 setbits_le32(MV_USB_PHY_PLL_REG(2), BIT(9));
Stefan Roesef43d3232015-07-22 18:26:13 +0200451
452 /* Assert VCOCAL_START */
Stefan Roese0b1d5372015-12-04 13:08:34 +0100453 setbits_le32(MV_USB_PHY_PLL_REG(1), BIT(21));
Stefan Roesef43d3232015-07-22 18:26:13 +0200454
455 mdelay(1);
456
457 /*
458 * USB PHY init (change from defaults) specific for 40nm (78X30 78X60)
459 */
460
461 for (dev = 0; dev < 3; dev++) {
Stefan Roese0b1d5372015-12-04 13:08:34 +0100462 setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 3), BIT(15));
Stefan Roesef43d3232015-07-22 18:26:13 +0200463
464 /* Assert REG_RCAL_START in channel REG 1 */
Stefan Roese0b1d5372015-12-04 13:08:34 +0100465 setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
Stefan Roesef43d3232015-07-22 18:26:13 +0200466 udelay(40);
Stefan Roese0b1d5372015-12-04 13:08:34 +0100467 clrbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
Stefan Roesef43d3232015-07-22 18:26:13 +0200468 }
469}
Kevin Smith1ddff022015-05-18 16:09:44 +0000470
Stefan Roesee7c72282015-12-03 12:39:45 +0100471/*
472 * This function is not called from the SPL U-Boot version
473 */
Stefan Roese93e6bf42014-10-22 12:13:17 +0200474int arch_cpu_init(void)
475{
Stefan Roesee1b7bfd2015-08-25 14:09:12 +0200476 struct pl310_regs *const pl310 =
477 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
478
Stefan Roesee5d63862015-08-24 11:03:50 +0200479 /*
480 * Only with disabled MMU its possible to switch the base
481 * register address on Armada 38x. Without this the SDRAM
482 * located at >= 0x4000.0000 is also not accessible, as its
483 * still locked to cache.
484 */
485 mmu_disable();
Stefan Roesee5d63862015-08-24 11:03:50 +0200486
487 /* Linux expects the internal registers to be at 0xf1000000 */
488 writel(SOC_REGS_PHY_BASE, INTREG_BASE_ADDR_REG);
489 set_cbar(SOC_REGS_PHY_BASE + 0xC000);
490
Stefan Roesee5d63862015-08-24 11:03:50 +0200491 /*
492 * From this stage on, the SoC detection is working. As we have
493 * configured the internal register base to the value used
494 * in the macros / defines in the U-Boot header (soc.h).
495 */
Stefan Roeseb07f01d2015-07-01 13:23:52 +0200496
Stefan Roesecaf74c92015-12-03 12:39:45 +0100497 if (mvebu_soc_family() == MVEBU_SOC_A38X) {
498 /*
499 * To fully release / unlock this area from cache, we need
500 * to flush all caches and disable the L2 cache.
501 */
502 icache_disable();
503 dcache_disable();
504 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
505 }
Stefan Roese73acffe2015-04-24 10:49:11 +0200506
Stefan Roese93e6bf42014-10-22 12:13:17 +0200507 /*
508 * We need to call mvebu_mbus_probe() before calling
509 * update_sdram_window_sizes() as it disables all previously
510 * configured mbus windows and then configures them as
511 * required for U-Boot. Calling update_sdram_window_sizes()
512 * without this configuration will not work, as the internal
513 * registers can't be accessed reliably because of potenial
514 * double mapping.
515 * After updating the SDRAM access windows we need to call
516 * mvebu_mbus_probe() again, as this now correctly configures
517 * the SDRAM areas that are later used by the MVEBU drivers
518 * (e.g. USB, NETA).
519 */
520
521 /*
522 * First disable all windows
523 */
524 mvebu_mbus_probe(NULL, 0);
525
Stefan Roese174d23e2015-04-25 06:29:51 +0200526 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
527 /*
528 * Now the SDRAM access windows can be reconfigured using
529 * the information in the SDRAM scratch pad registers
530 */
531 update_sdram_window_sizes();
532 }
Stefan Roese93e6bf42014-10-22 12:13:17 +0200533
534 /*
535 * Finally the mbus windows can be configured with the
536 * updated SDRAM sizes
537 */
538 mvebu_mbus_probe(windows, ARRAY_SIZE(windows));
539
Stefan Roesebadccc32015-07-16 10:40:05 +0200540 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
541 /* Enable GBE0, GBE1, LCD and NFC PUP */
542 clrsetbits_le32(ARMADA_XP_PUP_ENABLE, 0,
543 GE0_PUP_EN | GE1_PUP_EN | LCD_PUP_EN |
544 NAND_PUP_EN | SPI_PUP_EN);
Stefan Roesef43d3232015-07-22 18:26:13 +0200545
546 /* Configure USB PLL and PHYs on AXP */
547 setup_usb_phys();
Stefan Roesebadccc32015-07-16 10:40:05 +0200548 }
549
550 /* Enable NAND and NAND arbiter */
551 clrsetbits_le32(MVEBU_SOC_DEV_MUX_REG, 0, NAND_EN | NAND_ARBITER_EN);
552
Stefan Roese8ac6dab2015-07-01 13:28:39 +0200553 /* Disable MBUS error propagation */
554 clrsetbits_le32(SOC_COHERENCY_FABRIC_CTRL_REG, MBUS_ERR_PROP_EN, 0);
555
Stefan Roese93e6bf42014-10-22 12:13:17 +0200556 return 0;
557}
558#endif /* CONFIG_ARCH_CPU_INIT */
559
Stefan Roesebadccc32015-07-16 10:40:05 +0200560u32 mvebu_get_nand_clock(void)
561{
Chris Packham460086e2016-08-22 12:38:39 +1200562 u32 reg;
563
564 if (mvebu_soc_family() == MVEBU_SOC_A38X)
565 reg = MVEBU_DFX_DIV_CLK_CTRL(1);
Chris Packham7ce3f8c2019-04-11 22:22:51 +1200566 else if (mvebu_soc_family() == MVEBU_SOC_MSYS)
567 reg = MVEBU_DFX_DIV_CLK_CTRL(8);
Chris Packham460086e2016-08-22 12:38:39 +1200568 else
569 reg = MVEBU_CORE_DIV_CLK_CTRL(1);
570
Stefan Roesebadccc32015-07-16 10:40:05 +0200571 return CONFIG_SYS_MVEBU_PLL_CLOCK /
Chris Packham460086e2016-08-22 12:38:39 +1200572 ((readl(reg) &
Stefan Roesebadccc32015-07-16 10:40:05 +0200573 NAND_ECC_DIVCKL_RATIO_MASK) >> NAND_ECC_DIVCKL_RATIO_OFFS);
574}
575
Stefan Roese93e6bf42014-10-22 12:13:17 +0200576/*
577 * SOC specific misc init
578 */
579#if defined(CONFIG_ARCH_MISC_INIT)
580int arch_misc_init(void)
581{
582 /* Nothing yet, perhaps we need something here later */
583 return 0;
584}
585#endif /* CONFIG_ARCH_MISC_INIT */
586
Pierre Bourdonb9af62d2019-04-11 04:56:58 +0200587#if defined(CONFIG_MMC_SDHCI_MV) && !defined(CONFIG_DM_MMC)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900588int board_mmc_init(struct bd_info *bis)
Stefan Roesed3e34732015-06-29 14:58:10 +0200589{
590 mv_sdh_init(MVEBU_SDIO_BASE, 0, 0,
591 SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_WAIT_SEND_CMD);
592
593 return 0;
594}
595#endif
596
Stefan Roesebb1c0bd2015-06-29 14:58:13 +0200597#define AHCI_VENDOR_SPECIFIC_0_ADDR 0xa0
598#define AHCI_VENDOR_SPECIFIC_0_DATA 0xa4
599
600#define AHCI_WINDOW_CTRL(win) (0x60 + ((win) << 4))
601#define AHCI_WINDOW_BASE(win) (0x64 + ((win) << 4))
602#define AHCI_WINDOW_SIZE(win) (0x68 + ((win) << 4))
603
604static void ahci_mvebu_mbus_config(void __iomem *base)
605{
606 const struct mbus_dram_target_info *dram;
607 int i;
608
Baruch Siach2179c772019-05-16 13:03:57 +0300609 /* mbus is not initialized in SPL; keep the ROM settings */
610 if (IS_ENABLED(CONFIG_SPL_BUILD))
611 return;
612
Stefan Roesebb1c0bd2015-06-29 14:58:13 +0200613 dram = mvebu_mbus_dram_info();
614
615 for (i = 0; i < 4; i++) {
616 writel(0, base + AHCI_WINDOW_CTRL(i));
617 writel(0, base + AHCI_WINDOW_BASE(i));
618 writel(0, base + AHCI_WINDOW_SIZE(i));
619 }
620
621 for (i = 0; i < dram->num_cs; i++) {
622 const struct mbus_dram_window *cs = dram->cs + i;
623
624 writel((cs->mbus_attr << 8) |
625 (dram->mbus_dram_target_id << 4) | 1,
626 base + AHCI_WINDOW_CTRL(i));
627 writel(cs->base >> 16, base + AHCI_WINDOW_BASE(i));
628 writel(((cs->size - 1) & 0xffff0000),
629 base + AHCI_WINDOW_SIZE(i));
630 }
631}
632
633static void ahci_mvebu_regret_option(void __iomem *base)
634{
635 /*
636 * Enable the regret bit to allow the SATA unit to regret a
637 * request that didn't receive an acknowlegde and avoid a
638 * deadlock
639 */
640 writel(0x4, base + AHCI_VENDOR_SPECIFIC_0_ADDR);
641 writel(0x80, base + AHCI_VENDOR_SPECIFIC_0_DATA);
642}
643
Baruch Siachb590a142019-03-24 13:27:43 +0200644int board_ahci_enable(void)
Stefan Roesebb1c0bd2015-06-29 14:58:13 +0200645{
Stefan Roesebb1c0bd2015-06-29 14:58:13 +0200646 ahci_mvebu_mbus_config((void __iomem *)MVEBU_SATA0_BASE);
647 ahci_mvebu_regret_option((void __iomem *)MVEBU_SATA0_BASE);
Baruch Siachb590a142019-03-24 13:27:43 +0200648
649 return 0;
650}
651
652#ifdef CONFIG_SCSI_AHCI_PLAT
653void scsi_init(void)
654{
655 printf("MVEBU SATA INIT\n");
656 board_ahci_enable();
Stefan Roesebb1c0bd2015-06-29 14:58:13 +0200657 ahci_init((void __iomem *)MVEBU_SATA0_BASE);
658}
659#endif
660
Jon Nettleton86502322017-11-06 10:33:20 +0200661#ifdef CONFIG_USB_XHCI_MVEBU
662#define USB3_MAX_WINDOWS 4
663#define USB3_WIN_CTRL(w) (0x0 + ((w) * 8))
664#define USB3_WIN_BASE(w) (0x4 + ((w) * 8))
665
666static void xhci_mvebu_mbus_config(void __iomem *base,
667 const struct mbus_dram_target_info *dram)
668{
669 int i;
670
671 for (i = 0; i < USB3_MAX_WINDOWS; i++) {
672 writel(0, base + USB3_WIN_CTRL(i));
673 writel(0, base + USB3_WIN_BASE(i));
674 }
675
676 for (i = 0; i < dram->num_cs; i++) {
677 const struct mbus_dram_window *cs = dram->cs + i;
678
679 /* Write size, attributes and target id to control register */
680 writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
681 (dram->mbus_dram_target_id << 4) | 1,
682 base + USB3_WIN_CTRL(i));
683
684 /* Write base address to base register */
685 writel((cs->base & 0xffff0000), base + USB3_WIN_BASE(i));
686 }
687}
688
689int board_xhci_enable(fdt_addr_t base)
690{
691 const struct mbus_dram_target_info *dram;
692
693 printf("MVEBU XHCI INIT controller @ 0x%lx\n", base);
694
695 dram = mvebu_mbus_dram_info();
696 xhci_mvebu_mbus_config((void __iomem *)base, dram);
697
698 return 0;
699}
700#endif
701
Stefan Roese93e6bf42014-10-22 12:13:17 +0200702void enable_caches(void)
703{
Stefan Roese7a4a5ba2015-04-25 06:29:55 +0200704 /* Avoid problem with e.g. neta ethernet driver */
705 invalidate_dcache_all();
706
Stefan Roesedafe60f2016-02-10 09:18:46 +0100707 /*
708 * Armada 375 still has some problems with d-cache enabled in the
709 * ethernet driver (mvpp2). So lets keep the d-cache disabled
710 * until this is solved.
711 */
712 if (mvebu_soc_family() != MVEBU_SOC_A375) {
713 /* Enable D-cache. I-cache is already enabled in start.S */
714 dcache_enable();
715 }
Stefan Roese93e6bf42014-10-22 12:13:17 +0200716}
Stefan Roese479a9772015-12-03 12:39:45 +0100717
718void v7_outer_cache_enable(void)
719{
Stefan Roese479a9772015-12-03 12:39:45 +0100720 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
Stefan Roesecaf74c92015-12-03 12:39:45 +0100721 struct pl310_regs *const pl310 =
722 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
Stefan Roese479a9772015-12-03 12:39:45 +0100723 u32 u;
724
Stefan Roesecaf74c92015-12-03 12:39:45 +0100725 /* The L2 cache is already disabled at this point */
726
Stefan Roese479a9772015-12-03 12:39:45 +0100727 /*
728 * For Aurora cache in no outer mode, enable via the CP15
729 * coprocessor broadcasting of cache commands to L2.
730 */
731 asm volatile("mrc p15, 1, %0, c15, c2, 0" : "=r" (u));
732 u |= BIT(8); /* Set the FW bit */
733 asm volatile("mcr p15, 1, %0, c15, c2, 0" : : "r" (u));
734
735 isb();
736
737 /* Enable the L2 cache */
738 setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
739 }
740}
Stefan Roese77b299c2015-12-14 12:31:48 +0100741
742void v7_outer_cache_disable(void)
743{
744 struct pl310_regs *const pl310 =
745 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
746
747 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
748}