blob: 56999f608a3843b0160d1cbf520a05730831a90f [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
Pali Rohárdca22e52023-02-03 21:34:27 +010028 /* BootROM */
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
Pali Rohár465ecee2023-02-03 21:41:45 +010038/* SPI0 CS0 Flash of size MBUS_SPI_SIZE is mapped to address MBUS_SPI_BASE */
39#if CONFIG_ENV_SPI_BUS == 0 && CONFIG_ENV_SPI_CS == 0 && \
40 CONFIG_ENV_OFFSET + CONFIG_ENV_SIZE <= MBUS_SPI_SIZE
41void *env_sf_get_env_addr(void)
42{
43 return (void *)MBUS_SPI_BASE + CONFIG_ENV_OFFSET;
44}
45#endif
46
Stefan Roesee1b7bfd2015-08-25 14:09:12 +020047void lowlevel_init(void)
48{
49 /*
50 * Dummy implementation, we only need LOWLEVEL_INIT
51 * on Armada to configure CP15 in start.S / cpu_init_cp15()
52 */
53}
54
Harald Seiler6f14d5f2020-12-15 16:47:52 +010055void reset_cpu(void)
Stefan Roese93e6bf42014-10-22 12:13:17 +020056{
57 struct mvebu_system_registers *reg =
58 (struct mvebu_system_registers *)MVEBU_SYSTEM_REG_BASE;
59
60 writel(readl(&reg->rstoutn_mask) | 1, &reg->rstoutn_mask);
61 writel(readl(&reg->sys_soft_rst) | 1, &reg->sys_soft_rst);
62 while (1)
63 ;
64}
65
Marek Behúnee76b4a2021-08-16 15:19:37 +020066u32 get_boot_device(void)
67{
68 u32 val;
69 u32 boot_device;
70
71 /*
Tom Rinib056ce402021-09-01 07:52:08 -040072 * First check, if UART boot-mode is active. This can only
73 * be done, via the bootrom error register. Here the
74 * MSB marks if the UART mode is active.
75 */
Tom Rini3327dd72022-03-30 18:07:12 -040076 val = readl(BOOTROM_ERR_REG);
Marek Behúnee76b4a2021-08-16 15:19:37 +020077 boot_device = (val & BOOTROM_ERR_MODE_MASK) >> BOOTROM_ERR_MODE_OFFS;
78 debug("BOOTROM_REG=0x%08x boot_device=0x%x\n", val, boot_device);
79 if (boot_device == BOOTROM_ERR_MODE_UART)
80 return BOOT_DEVICE_UART;
81
82#ifdef CONFIG_ARMADA_38X
83 /*
Tom Rinib056ce402021-09-01 07:52:08 -040084 * If the bootrom error code contains any other than zeros it's an
85 * error condition and the bootROM has fallen back to UART boot
86 */
Marek Behúnee76b4a2021-08-16 15:19:37 +020087 boot_device = (val & BOOTROM_ERR_CODE_MASK) >> BOOTROM_ERR_CODE_OFFS;
88 if (boot_device)
89 return BOOT_DEVICE_UART;
90#endif
91
92 /*
Tom Rinib056ce402021-09-01 07:52:08 -040093 * Now check the SAR register for the strapped boot-device
94 */
Tom Rini253b6a22022-12-04 10:13:42 -050095 val = readl(CFG_SAR_REG); /* SAR - Sample At Reset */
Marek Behúnee76b4a2021-08-16 15:19:37 +020096 boot_device = (val & BOOT_DEV_SEL_MASK) >> BOOT_DEV_SEL_OFFS;
97 debug("SAR_REG=0x%08x boot_device=0x%x\n", val, boot_device);
98 switch (boot_device) {
99#ifdef BOOT_FROM_NAND
100 case BOOT_FROM_NAND:
101 return BOOT_DEVICE_NAND;
102#endif
103#ifdef BOOT_FROM_MMC
104 case BOOT_FROM_MMC:
105 case BOOT_FROM_MMC_ALT:
106 return BOOT_DEVICE_MMC1;
107#endif
108 case BOOT_FROM_UART:
109#ifdef BOOT_FROM_UART_ALT
110 case BOOT_FROM_UART_ALT:
111#endif
112 return BOOT_DEVICE_UART;
113#ifdef BOOT_FROM_SATA
114 case BOOT_FROM_SATA:
115 case BOOT_FROM_SATA_ALT:
116 return BOOT_DEVICE_SATA;
117#endif
118 case BOOT_FROM_SPI:
119 return BOOT_DEVICE_SPI;
120 default:
121 return BOOT_DEVICE_BOOTROM;
122 };
123}
124
Stefan Roese93e6bf42014-10-22 12:13:17 +0200125#if defined(CONFIG_DISPLAY_CPUINFO)
Stefan Roese2a539c82015-12-21 12:36:40 +0100126
Stefan Roese479f9af2016-02-10 07:23:00 +0100127#if defined(CONFIG_ARMADA_375)
128/* SAR frequency values for Armada 375 */
129static const struct sar_freq_modes sar_freq_tab[] = {
130 { 0, 0x0, 266, 133, 266 },
131 { 1, 0x0, 333, 167, 167 },
132 { 2, 0x0, 333, 167, 222 },
133 { 3, 0x0, 333, 167, 333 },
134 { 4, 0x0, 400, 200, 200 },
135 { 5, 0x0, 400, 200, 267 },
136 { 6, 0x0, 400, 200, 400 },
137 { 7, 0x0, 500, 250, 250 },
138 { 8, 0x0, 500, 250, 334 },
139 { 9, 0x0, 500, 250, 500 },
140 { 10, 0x0, 533, 267, 267 },
141 { 11, 0x0, 533, 267, 356 },
142 { 12, 0x0, 533, 267, 533 },
143 { 13, 0x0, 600, 300, 300 },
144 { 14, 0x0, 600, 300, 400 },
145 { 15, 0x0, 600, 300, 600 },
146 { 16, 0x0, 666, 333, 333 },
147 { 17, 0x0, 666, 333, 444 },
148 { 18, 0x0, 666, 333, 666 },
149 { 19, 0x0, 800, 400, 267 },
150 { 20, 0x0, 800, 400, 400 },
151 { 21, 0x0, 800, 400, 534 },
152 { 22, 0x0, 900, 450, 300 },
153 { 23, 0x0, 900, 450, 450 },
154 { 24, 0x0, 900, 450, 600 },
155 { 25, 0x0, 1000, 500, 500 },
156 { 26, 0x0, 1000, 500, 667 },
157 { 27, 0x0, 1000, 333, 500 },
158 { 28, 0x0, 400, 400, 400 },
159 { 29, 0x0, 1100, 550, 550 },
160 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
161};
162#elif defined(CONFIG_ARMADA_38X)
Stefan Roesec03a2132016-01-07 14:03:11 +0100163/* SAR frequency values for Armada 38x */
Stefan Roese32139c32016-01-07 14:04:51 +0100164static const struct sar_freq_modes sar_freq_tab[] = {
Chris Packham5ccd14e2017-09-05 17:03:26 +1200165 { 0x0, 0x0, 666, 333, 333 },
166 { 0x2, 0x0, 800, 400, 400 },
167 { 0x4, 0x0, 1066, 533, 533 },
168 { 0x6, 0x0, 1200, 600, 600 },
169 { 0x8, 0x0, 1332, 666, 666 },
170 { 0xc, 0x0, 1600, 800, 800 },
171 { 0x10, 0x0, 1866, 933, 933 },
172 { 0x13, 0x0, 2000, 1000, 933 },
173 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
Stefan Roese2a539c82015-12-21 12:36:40 +0100174};
Chris Packhama8f845e2019-04-11 22:22:50 +1200175#elif defined(CONFIG_ARMADA_MSYS)
176static const struct sar_freq_modes sar_freq_tab[] = {
177 { 0x0, 0x0, 400, 400, 400 },
178 { 0x2, 0x0, 667, 333, 667 },
179 { 0x3, 0x0, 800, 400, 800 },
180 { 0x5, 0x0, 800, 400, 800 },
181 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
182};
Stefan Roese2a539c82015-12-21 12:36:40 +0100183#else
Stefan Roesec03a2132016-01-07 14:03:11 +0100184/* SAR frequency values for Armada XP */
Stefan Roese32139c32016-01-07 14:04:51 +0100185static const struct sar_freq_modes sar_freq_tab[] = {
Stefan Roese2a539c82015-12-21 12:36:40 +0100186 { 0xa, 0x5, 800, 400, 400 },
187 { 0x1, 0x5, 1066, 533, 533 },
188 { 0x2, 0x5, 1200, 600, 600 },
189 { 0x2, 0x9, 1200, 600, 400 },
190 { 0x3, 0x5, 1333, 667, 667 },
191 { 0x4, 0x5, 1500, 750, 750 },
192 { 0x4, 0x9, 1500, 750, 500 },
193 { 0xb, 0x9, 1600, 800, 533 },
194 { 0xb, 0xa, 1600, 800, 640 },
195 { 0xb, 0x5, 1600, 800, 800 },
196 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
197};
198#endif
199
200void get_sar_freq(struct sar_freq_modes *sar_freq)
201{
202 u32 val;
203 u32 freq;
204 int i;
205
Chris Packhama8f845e2019-04-11 22:22:50 +1200206#if defined(CONFIG_ARMADA_375) || defined(CONFIG_ARMADA_MSYS)
Tom Rinid7b93782022-12-04 10:13:41 -0500207 val = readl(CFG_SAR2_REG); /* SAR - Sample At Reset */
Stefan Roese479f9af2016-02-10 07:23:00 +0100208#else
Tom Rini253b6a22022-12-04 10:13:42 -0500209 val = readl(CFG_SAR_REG); /* SAR - Sample At Reset */
Stefan Roese479f9af2016-02-10 07:23:00 +0100210#endif
Stefan Roese2a539c82015-12-21 12:36:40 +0100211 freq = (val & SAR_CPU_FREQ_MASK) >> SAR_CPU_FREQ_OFFS;
Stefan Roese479f9af2016-02-10 07:23:00 +0100212#if defined(SAR2_CPU_FREQ_MASK)
Stefan Roese2a539c82015-12-21 12:36:40 +0100213 /*
214 * Shift CPU0 clock frequency select bit from SAR2 register
215 * into correct position
216 */
Tom Rinid7b93782022-12-04 10:13:41 -0500217 freq |= ((readl(CFG_SAR2_REG) & SAR2_CPU_FREQ_MASK)
Stefan Roese2a539c82015-12-21 12:36:40 +0100218 >> SAR2_CPU_FREQ_OFFS) << 3;
219#endif
220 for (i = 0; sar_freq_tab[i].val != 0xff; i++) {
221 if (sar_freq_tab[i].val == freq) {
Chris Packhama8f845e2019-04-11 22:22:50 +1200222#if defined(CONFIG_ARMADA_375) || defined(CONFIG_ARMADA_38X) || defined(CONFIG_ARMADA_MSYS)
Stefan Roese2a539c82015-12-21 12:36:40 +0100223 *sar_freq = sar_freq_tab[i];
224 return;
225#else
226 int k;
227 u8 ffc;
228
229 ffc = (val & SAR_FFC_FREQ_MASK) >>
230 SAR_FFC_FREQ_OFFS;
231 for (k = i; sar_freq_tab[k].ffc != 0xff; k++) {
232 if (sar_freq_tab[k].ffc == ffc) {
233 *sar_freq = sar_freq_tab[k];
234 return;
235 }
236 }
237 i = k;
238#endif
239 }
240 }
241
242 /* SAR value not found, return 0 for frequencies */
243 *sar_freq = sar_freq_tab[i - 1];
244}
245
Stefan Roese93e6bf42014-10-22 12:13:17 +0200246int print_cpuinfo(void)
247{
248 u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
249 u8 revid = readl(MVEBU_REG_PCIE_REVID) & 0xff;
Stefan Roese2a539c82015-12-21 12:36:40 +0100250 struct sar_freq_modes sar_freq;
Stefan Roese93e6bf42014-10-22 12:13:17 +0200251
252 puts("SoC: ");
253
254 switch (devid) {
Phil Sutter22e553e2015-12-25 14:41:24 +0100255 case SOC_MV78230_ID:
256 puts("MV78230-");
257 break;
Stefan Roeseb158f372015-12-09 11:00:51 +0100258 case SOC_MV78260_ID:
259 puts("MV78260-");
260 break;
Stefan Roese93e6bf42014-10-22 12:13:17 +0200261 case SOC_MV78460_ID:
262 puts("MV78460-");
263 break;
Stefan Roese479f9af2016-02-10 07:23:00 +0100264 case SOC_88F6720_ID:
265 puts("MV88F6720-");
266 break;
Stefan Roese174d23e2015-04-25 06:29:51 +0200267 case SOC_88F6810_ID:
268 puts("MV88F6810-");
Stefan Roese93e6bf42014-10-22 12:13:17 +0200269 break;
Stefan Roese174d23e2015-04-25 06:29:51 +0200270 case SOC_88F6820_ID:
271 puts("MV88F6820-");
Stefan Roese93e6bf42014-10-22 12:13:17 +0200272 break;
Stefan Roese174d23e2015-04-25 06:29:51 +0200273 case SOC_88F6828_ID:
274 puts("MV88F6828-");
Stefan Roese93e6bf42014-10-22 12:13:17 +0200275 break;
Chris Packham348109d2017-09-04 17:38:31 +1200276 case SOC_98DX3236_ID:
277 puts("98DX3236-");
278 break;
279 case SOC_98DX3336_ID:
280 puts("98DX3336-");
281 break;
282 case SOC_98DX4251_ID:
283 puts("98DX4251-");
284 break;
Stefan Roese93e6bf42014-10-22 12:13:17 +0200285 default:
Stefan Roese174d23e2015-04-25 06:29:51 +0200286 puts("Unknown-");
Stefan Roese93e6bf42014-10-22 12:13:17 +0200287 break;
288 }
289
Pali Rohárfdf415c2022-07-15 10:13:12 +0200290 switch (devid) {
291 case SOC_MV78230_ID:
292 case SOC_MV78260_ID:
293 case SOC_MV78460_ID:
Stefan Roese174d23e2015-04-25 06:29:51 +0200294 switch (revid) {
295 case 1:
Stefan Roese2a539c82015-12-21 12:36:40 +0100296 puts("A0");
Stefan Roese174d23e2015-04-25 06:29:51 +0200297 break;
298 case 2:
Stefan Roese2a539c82015-12-21 12:36:40 +0100299 puts("B0");
Stefan Roese174d23e2015-04-25 06:29:51 +0200300 break;
301 default:
Stefan Roese2a539c82015-12-21 12:36:40 +0100302 printf("?? (%x)", revid);
Stefan Roese174d23e2015-04-25 06:29:51 +0200303 break;
304 }
Pali Rohárfdf415c2022-07-15 10:13:12 +0200305 break;
Stefan Roese174d23e2015-04-25 06:29:51 +0200306
Pali Rohárfdf415c2022-07-15 10:13:12 +0200307 case SOC_88F6720_ID:
Stefan Roese479f9af2016-02-10 07:23:00 +0100308 switch (revid) {
309 case MV_88F67XX_A0_ID:
310 puts("A0");
311 break;
312 default:
313 printf("?? (%x)", revid);
314 break;
315 }
Pali Rohárfdf415c2022-07-15 10:13:12 +0200316 break;
Stefan Roese479f9af2016-02-10 07:23:00 +0100317
Pali Rohárfdf415c2022-07-15 10:13:12 +0200318 case SOC_88F6810_ID:
319 case SOC_88F6820_ID:
320 case SOC_88F6828_ID:
Stefan Roese174d23e2015-04-25 06:29:51 +0200321 switch (revid) {
322 case MV_88F68XX_Z1_ID:
Stefan Roese2a539c82015-12-21 12:36:40 +0100323 puts("Z1");
Stefan Roese174d23e2015-04-25 06:29:51 +0200324 break;
325 case MV_88F68XX_A0_ID:
Stefan Roese2a539c82015-12-21 12:36:40 +0100326 puts("A0");
Stefan Roese174d23e2015-04-25 06:29:51 +0200327 break;
Chris Packhamec4510b2018-11-28 10:32:00 +1300328 case MV_88F68XX_B0_ID:
329 puts("B0");
330 break;
Stefan Roese174d23e2015-04-25 06:29:51 +0200331 default:
Stefan Roese2a539c82015-12-21 12:36:40 +0100332 printf("?? (%x)", revid);
Stefan Roese174d23e2015-04-25 06:29:51 +0200333 break;
334 }
Pali Rohárfdf415c2022-07-15 10:13:12 +0200335 break;
Stefan Roese174d23e2015-04-25 06:29:51 +0200336
Pali Rohárfdf415c2022-07-15 10:13:12 +0200337 case SOC_98DX3236_ID:
338 case SOC_98DX3336_ID:
339 case SOC_98DX4251_ID:
Chris Packhama8f845e2019-04-11 22:22:50 +1200340 switch (revid) {
341 case 3:
342 puts("A0");
343 break;
344 case 4:
345 puts("A1");
346 break;
347 default:
348 printf("?? (%x)", revid);
349 break;
350 }
Pali Rohárfdf415c2022-07-15 10:13:12 +0200351 break;
352
353 default:
354 printf("?? (%x)", revid);
355 break;
Chris Packhama8f845e2019-04-11 22:22:50 +1200356 }
357
Stefan Roese2a539c82015-12-21 12:36:40 +0100358 get_sar_freq(&sar_freq);
359 printf(" at %d MHz\n", sar_freq.p_clk);
360
Stefan Roese93e6bf42014-10-22 12:13:17 +0200361 return 0;
362}
363#endif /* CONFIG_DISPLAY_CPUINFO */
364
365/*
366 * This function initialize Controller DRAM Fastpath windows.
367 * It takes the CS size information from the 0x1500 scratch registers
368 * and sets the correct windows sizes and base addresses accordingly.
369 *
370 * These values are set in the scratch registers by the Marvell
Chris Packham1cd77b02018-12-14 16:27:57 +1300371 * DDR3 training code, which is executed by the SPL before the
372 * main payload (U-Boot) is executed.
Stefan Roese93e6bf42014-10-22 12:13:17 +0200373 */
374static void update_sdram_window_sizes(void)
375{
376 u64 base = 0;
377 u32 size, temp;
378 int i;
379
380 for (i = 0; i < SDRAM_MAX_CS; i++) {
381 size = readl((MVEBU_SDRAM_SCRATCH + (i * 8))) & SDRAM_ADDR_MASK;
382 if (size != 0) {
383 size |= ~(SDRAM_ADDR_MASK);
384
385 /* Set Base Address */
386 temp = (base & 0xFF000000ll) | ((base >> 32) & 0xF);
387 writel(temp, MVEBU_SDRAM_BASE + DDR_BASE_CS_OFF(i));
388
389 /*
390 * Check if out of max window size and resize
391 * the window
392 */
393 temp = (readl(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i)) &
394 ~(SDRAM_ADDR_MASK)) | 1;
395 temp |= (size & SDRAM_ADDR_MASK);
396 writel(temp, MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i));
397
398 base += ((u64)size + 1);
399 } else {
400 /*
401 * Disable window if not used, otherwise this
402 * leads to overlapping enabled windows with
403 * pretty strange results
404 */
405 clrbits_le32(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i), 1);
406 }
407 }
408}
409
410#ifdef CONFIG_ARCH_CPU_INIT
Stefan Roesef43d3232015-07-22 18:26:13 +0200411#define MV_USB_PHY_BASE (MVEBU_AXP_USB_BASE + 0x800)
412#define MV_USB_PHY_PLL_REG(reg) (MV_USB_PHY_BASE | (((reg) & 0xF) << 2))
413#define MV_USB_X3_BASE(addr) (MVEBU_AXP_USB_BASE | BIT(11) | \
414 (((addr) & 0xF) << 6))
415#define MV_USB_X3_PHY_CHANNEL(dev, reg) (MV_USB_X3_BASE((dev) + 1) | \
416 (((reg) & 0xF) << 2))
417
418static void setup_usb_phys(void)
419{
420 int dev;
421
422 /*
423 * USB PLL init
424 */
425
426 /* Setup PLL frequency */
427 /* USB REF frequency = 25 MHz */
428 clrsetbits_le32(MV_USB_PHY_PLL_REG(1), 0x3ff, 0x605);
429
430 /* Power up PLL and PHY channel */
Stefan Roese0b1d5372015-12-04 13:08:34 +0100431 setbits_le32(MV_USB_PHY_PLL_REG(2), BIT(9));
Stefan Roesef43d3232015-07-22 18:26:13 +0200432
433 /* Assert VCOCAL_START */
Stefan Roese0b1d5372015-12-04 13:08:34 +0100434 setbits_le32(MV_USB_PHY_PLL_REG(1), BIT(21));
Stefan Roesef43d3232015-07-22 18:26:13 +0200435
436 mdelay(1);
437
438 /*
439 * USB PHY init (change from defaults) specific for 40nm (78X30 78X60)
440 */
441
442 for (dev = 0; dev < 3; dev++) {
Stefan Roese0b1d5372015-12-04 13:08:34 +0100443 setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 3), BIT(15));
Stefan Roesef43d3232015-07-22 18:26:13 +0200444
445 /* Assert REG_RCAL_START in channel REG 1 */
Stefan Roese0b1d5372015-12-04 13:08:34 +0100446 setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
Stefan Roesef43d3232015-07-22 18:26:13 +0200447 udelay(40);
Stefan Roese0b1d5372015-12-04 13:08:34 +0100448 clrbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
Stefan Roesef43d3232015-07-22 18:26:13 +0200449 }
450}
Kevin Smith1ddff022015-05-18 16:09:44 +0000451
Stefan Roesee7c72282015-12-03 12:39:45 +0100452/*
453 * This function is not called from the SPL U-Boot version
454 */
Stefan Roese93e6bf42014-10-22 12:13:17 +0200455int arch_cpu_init(void)
456{
Stefan Roese93e6bf42014-10-22 12:13:17 +0200457 /*
458 * We need to call mvebu_mbus_probe() before calling
459 * update_sdram_window_sizes() as it disables all previously
460 * configured mbus windows and then configures them as
461 * required for U-Boot. Calling update_sdram_window_sizes()
462 * without this configuration will not work, as the internal
463 * registers can't be accessed reliably because of potenial
464 * double mapping.
465 * After updating the SDRAM access windows we need to call
466 * mvebu_mbus_probe() again, as this now correctly configures
467 * the SDRAM areas that are later used by the MVEBU drivers
468 * (e.g. USB, NETA).
469 */
470
471 /*
472 * First disable all windows
473 */
474 mvebu_mbus_probe(NULL, 0);
475
Pali Rohárfdf415c2022-07-15 10:13:12 +0200476 if (IS_ENABLED(CONFIG_ARMADA_XP)) {
Stefan Roese174d23e2015-04-25 06:29:51 +0200477 /*
478 * Now the SDRAM access windows can be reconfigured using
479 * the information in the SDRAM scratch pad registers
480 */
481 update_sdram_window_sizes();
482 }
Stefan Roese93e6bf42014-10-22 12:13:17 +0200483
484 /*
485 * Finally the mbus windows can be configured with the
486 * updated SDRAM sizes
487 */
488 mvebu_mbus_probe(windows, ARRAY_SIZE(windows));
489
Pali Rohárfdf415c2022-07-15 10:13:12 +0200490 if (IS_ENABLED(CONFIG_ARMADA_XP)) {
Stefan Roesebadccc32015-07-16 10:40:05 +0200491 /* Enable GBE0, GBE1, LCD and NFC PUP */
492 clrsetbits_le32(ARMADA_XP_PUP_ENABLE, 0,
493 GE0_PUP_EN | GE1_PUP_EN | LCD_PUP_EN |
494 NAND_PUP_EN | SPI_PUP_EN);
Stefan Roesef43d3232015-07-22 18:26:13 +0200495
496 /* Configure USB PLL and PHYs on AXP */
497 setup_usb_phys();
Stefan Roesebadccc32015-07-16 10:40:05 +0200498 }
499
500 /* Enable NAND and NAND arbiter */
501 clrsetbits_le32(MVEBU_SOC_DEV_MUX_REG, 0, NAND_EN | NAND_ARBITER_EN);
502
Stefan Roese8ac6dab2015-07-01 13:28:39 +0200503 /* Disable MBUS error propagation */
504 clrsetbits_le32(SOC_COHERENCY_FABRIC_CTRL_REG, MBUS_ERR_PROP_EN, 0);
505
Stefan Roese93e6bf42014-10-22 12:13:17 +0200506 return 0;
507}
508#endif /* CONFIG_ARCH_CPU_INIT */
509
Stefan Roesebadccc32015-07-16 10:40:05 +0200510u32 mvebu_get_nand_clock(void)
511{
Chris Packham460086e2016-08-22 12:38:39 +1200512 u32 reg;
513
Pali Rohárfdf415c2022-07-15 10:13:12 +0200514 if (IS_ENABLED(CONFIG_ARMADA_38X))
Chris Packham460086e2016-08-22 12:38:39 +1200515 reg = MVEBU_DFX_DIV_CLK_CTRL(1);
Pali Rohárfdf415c2022-07-15 10:13:12 +0200516 else if (IS_ENABLED(CONFIG_ARMADA_MSYS))
Chris Packham7ce3f8c2019-04-11 22:22:51 +1200517 reg = MVEBU_DFX_DIV_CLK_CTRL(8);
Chris Packham460086e2016-08-22 12:38:39 +1200518 else
519 reg = MVEBU_CORE_DIV_CLK_CTRL(1);
520
Stefan Roesebadccc32015-07-16 10:40:05 +0200521 return CONFIG_SYS_MVEBU_PLL_CLOCK /
Chris Packham460086e2016-08-22 12:38:39 +1200522 ((readl(reg) &
Stefan Roesebadccc32015-07-16 10:40:05 +0200523 NAND_ECC_DIVCKL_RATIO_MASK) >> NAND_ECC_DIVCKL_RATIO_OFFS);
524}
525
Pierre Bourdonb9af62d2019-04-11 04:56:58 +0200526#if defined(CONFIG_MMC_SDHCI_MV) && !defined(CONFIG_DM_MMC)
Masahiro Yamadaf7ed78b2020-06-26 15:13:33 +0900527int board_mmc_init(struct bd_info *bis)
Stefan Roesed3e34732015-06-29 14:58:10 +0200528{
529 mv_sdh_init(MVEBU_SDIO_BASE, 0, 0,
530 SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_WAIT_SEND_CMD);
531
532 return 0;
533}
534#endif
535
Stefan Roesebb1c0bd2015-06-29 14:58:13 +0200536#define AHCI_VENDOR_SPECIFIC_0_ADDR 0xa0
537#define AHCI_VENDOR_SPECIFIC_0_DATA 0xa4
538
539#define AHCI_WINDOW_CTRL(win) (0x60 + ((win) << 4))
540#define AHCI_WINDOW_BASE(win) (0x64 + ((win) << 4))
541#define AHCI_WINDOW_SIZE(win) (0x68 + ((win) << 4))
542
543static void ahci_mvebu_mbus_config(void __iomem *base)
544{
545 const struct mbus_dram_target_info *dram;
546 int i;
547
Baruch Siach2179c772019-05-16 13:03:57 +0300548 /* mbus is not initialized in SPL; keep the ROM settings */
549 if (IS_ENABLED(CONFIG_SPL_BUILD))
550 return;
551
Stefan Roesebb1c0bd2015-06-29 14:58:13 +0200552 dram = mvebu_mbus_dram_info();
553
554 for (i = 0; i < 4; i++) {
555 writel(0, base + AHCI_WINDOW_CTRL(i));
556 writel(0, base + AHCI_WINDOW_BASE(i));
557 writel(0, base + AHCI_WINDOW_SIZE(i));
558 }
559
560 for (i = 0; i < dram->num_cs; i++) {
561 const struct mbus_dram_window *cs = dram->cs + i;
562
563 writel((cs->mbus_attr << 8) |
564 (dram->mbus_dram_target_id << 4) | 1,
565 base + AHCI_WINDOW_CTRL(i));
566 writel(cs->base >> 16, base + AHCI_WINDOW_BASE(i));
567 writel(((cs->size - 1) & 0xffff0000),
568 base + AHCI_WINDOW_SIZE(i));
569 }
570}
571
572static void ahci_mvebu_regret_option(void __iomem *base)
573{
574 /*
575 * Enable the regret bit to allow the SATA unit to regret a
576 * request that didn't receive an acknowlegde and avoid a
577 * deadlock
578 */
579 writel(0x4, base + AHCI_VENDOR_SPECIFIC_0_ADDR);
580 writel(0x80, base + AHCI_VENDOR_SPECIFIC_0_DATA);
581}
582
Baruch Siachb590a142019-03-24 13:27:43 +0200583int board_ahci_enable(void)
Stefan Roesebb1c0bd2015-06-29 14:58:13 +0200584{
Stefan Roesebb1c0bd2015-06-29 14:58:13 +0200585 ahci_mvebu_mbus_config((void __iomem *)MVEBU_SATA0_BASE);
586 ahci_mvebu_regret_option((void __iomem *)MVEBU_SATA0_BASE);
Baruch Siachb590a142019-03-24 13:27:43 +0200587
588 return 0;
589}
590
591#ifdef CONFIG_SCSI_AHCI_PLAT
592void scsi_init(void)
593{
594 printf("MVEBU SATA INIT\n");
595 board_ahci_enable();
Stefan Roesebb1c0bd2015-06-29 14:58:13 +0200596 ahci_init((void __iomem *)MVEBU_SATA0_BASE);
597}
598#endif
599
Jon Nettleton86502322017-11-06 10:33:20 +0200600#ifdef CONFIG_USB_XHCI_MVEBU
601#define USB3_MAX_WINDOWS 4
602#define USB3_WIN_CTRL(w) (0x0 + ((w) * 8))
603#define USB3_WIN_BASE(w) (0x4 + ((w) * 8))
604
605static void xhci_mvebu_mbus_config(void __iomem *base,
606 const struct mbus_dram_target_info *dram)
607{
608 int i;
609
610 for (i = 0; i < USB3_MAX_WINDOWS; i++) {
611 writel(0, base + USB3_WIN_CTRL(i));
612 writel(0, base + USB3_WIN_BASE(i));
613 }
614
615 for (i = 0; i < dram->num_cs; i++) {
616 const struct mbus_dram_window *cs = dram->cs + i;
617
618 /* Write size, attributes and target id to control register */
619 writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
620 (dram->mbus_dram_target_id << 4) | 1,
621 base + USB3_WIN_CTRL(i));
622
623 /* Write base address to base register */
624 writel((cs->base & 0xffff0000), base + USB3_WIN_BASE(i));
625 }
626}
627
628int board_xhci_enable(fdt_addr_t base)
629{
630 const struct mbus_dram_target_info *dram;
631
632 printf("MVEBU XHCI INIT controller @ 0x%lx\n", base);
633
634 dram = mvebu_mbus_dram_info();
635 xhci_mvebu_mbus_config((void __iomem *)base, dram);
636
637 return 0;
638}
639#endif
640
Stefan Roese93e6bf42014-10-22 12:13:17 +0200641void enable_caches(void)
642{
Stefan Roese7a4a5ba2015-04-25 06:29:55 +0200643 /* Avoid problem with e.g. neta ethernet driver */
644 invalidate_dcache_all();
645
Stefan Roesedafe60f2016-02-10 09:18:46 +0100646 /*
647 * Armada 375 still has some problems with d-cache enabled in the
648 * ethernet driver (mvpp2). So lets keep the d-cache disabled
649 * until this is solved.
650 */
Pali Rohárb94cb132022-09-08 16:06:50 +0200651 if (!IS_ENABLED(CONFIG_ARMADA_375)) {
Stefan Roesedafe60f2016-02-10 09:18:46 +0100652 /* Enable D-cache. I-cache is already enabled in start.S */
653 dcache_enable();
654 }
Stefan Roese93e6bf42014-10-22 12:13:17 +0200655}
Stefan Roese479a9772015-12-03 12:39:45 +0100656
657void v7_outer_cache_enable(void)
658{
Pali Rohár2100c4d2022-09-08 16:06:53 +0200659 struct pl310_regs *const pl310 =
Tom Rini6a5dccc2022-11-16 13:10:41 -0500660 (struct pl310_regs *)CFG_SYS_PL310_BASE;
Pali Rohár2100c4d2022-09-08 16:06:53 +0200661
662 /* The L2 cache is already disabled at this point */
663
664 /*
665 * For now L2 cache will be enabled only for Armada XP and Armada 38x.
666 * It can be enabled also for other SoCs after testing that it works fine.
667 */
668 if (!IS_ENABLED(CONFIG_ARMADA_XP) && !IS_ENABLED(CONFIG_ARMADA_38X))
669 return;
670
Pali Rohárfdf415c2022-07-15 10:13:12 +0200671 if (IS_ENABLED(CONFIG_ARMADA_XP)) {
Stefan Roese479a9772015-12-03 12:39:45 +0100672 u32 u;
673
674 /*
675 * For Aurora cache in no outer mode, enable via the CP15
676 * coprocessor broadcasting of cache commands to L2.
677 */
678 asm volatile("mrc p15, 1, %0, c15, c2, 0" : "=r" (u));
679 u |= BIT(8); /* Set the FW bit */
680 asm volatile("mcr p15, 1, %0, c15, c2, 0" : : "r" (u));
681
682 isb();
Stefan Roese479a9772015-12-03 12:39:45 +0100683 }
Pali Rohár2100c4d2022-09-08 16:06:53 +0200684
685 /* Enable the L2 cache */
686 setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
Stefan Roese479a9772015-12-03 12:39:45 +0100687}
Stefan Roese77b299c2015-12-14 12:31:48 +0100688
689void v7_outer_cache_disable(void)
690{
691 struct pl310_regs *const pl310 =
Tom Rini6a5dccc2022-11-16 13:10:41 -0500692 (struct pl310_regs *)CFG_SYS_PL310_BASE;
Stefan Roese77b299c2015-12-14 12:31:48 +0100693
694 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
695}