blob: fb241c7e4ddd39c03a1eca460df5f33a1880c576 [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>
Stefan Roese4d991cb2015-06-29 14:58:13 +02009#include <linux/mbus.h>
Stefan Roese41e5ee52014-10-22 12:13:17 +020010#include <asm/io.h>
Stefan Roese57303602015-05-18 16:09:43 +000011#include <asm/pl310.h>
Stefan Roese41e5ee52014-10-22 12:13:17 +020012#include <asm/arch/cpu.h>
13#include <asm/arch/soc.h>
Stefan Roese7f1adcd2015-06-29 14:58:10 +020014#include <sdhci.h>
Stefan Roese41e5ee52014-10-22 12:13:17 +020015
16#define DDR_BASE_CS_OFF(n) (0x0000 + ((n) << 3))
17#define DDR_SIZE_CS_OFF(n) (0x0004 + ((n) << 3))
18
19static struct mbus_win windows[] = {
Stefan Roese41e5ee52014-10-22 12:13:17 +020020 /* SPI */
Stefan Roese8ed20d62015-07-01 12:55:07 +020021 { MBUS_SPI_BASE, MBUS_SPI_SIZE,
22 CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_SPIFLASH },
Stefan Roese41e5ee52014-10-22 12:13:17 +020023
24 /* NOR */
Stefan Roese8ed20d62015-07-01 12:55:07 +020025 { MBUS_BOOTROM_BASE, MBUS_BOOTROM_SIZE,
26 CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_BOOTROM },
Chris Packham0d0df462019-04-11 22:22:50 +120027
28#ifdef CONFIG_ARMADA_MSYS
29 /* DFX */
30 { MBUS_DFX_BASE, MBUS_DFX_SIZE, CPU_TARGET_DFX, 0 },
31#endif
Stefan Roese41e5ee52014-10-22 12:13:17 +020032};
33
Stefan Roese42cc0342015-08-25 14:09:12 +020034void lowlevel_init(void)
35{
36 /*
37 * Dummy implementation, we only need LOWLEVEL_INIT
38 * on Armada to configure CP15 in start.S / cpu_init_cp15()
39 */
40}
41
Stefan Roese41e5ee52014-10-22 12:13:17 +020042void reset_cpu(unsigned long ignored)
43{
44 struct mvebu_system_registers *reg =
45 (struct mvebu_system_registers *)MVEBU_SYSTEM_REG_BASE;
46
47 writel(readl(&reg->rstoutn_mask) | 1, &reg->rstoutn_mask);
48 writel(readl(&reg->sys_soft_rst) | 1, &reg->sys_soft_rst);
49 while (1)
50 ;
51}
52
Stefan Roese9c6d3b72015-04-25 06:29:51 +020053int mvebu_soc_family(void)
54{
55 u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
56
Phil Sutter62029532015-12-25 14:41:24 +010057 switch (devid) {
58 case SOC_MV78230_ID:
59 case SOC_MV78260_ID:
60 case SOC_MV78460_ID:
Stefan Roese9c6d3b72015-04-25 06:29:51 +020061 return MVEBU_SOC_AXP;
Stefan Roese09e89ab2016-02-10 07:23:00 +010062
63 case SOC_88F6720_ID:
64 return MVEBU_SOC_A375;
65
Phil Sutter62029532015-12-25 14:41:24 +010066 case SOC_88F6810_ID:
67 case SOC_88F6820_ID:
68 case SOC_88F6828_ID:
Stefan Roese9c6d3b72015-04-25 06:29:51 +020069 return MVEBU_SOC_A38X;
Chris Packham0f8031a2017-09-04 17:38:31 +120070
71 case SOC_98DX3236_ID:
72 case SOC_98DX3336_ID:
73 case SOC_98DX4251_ID:
74 return MVEBU_SOC_MSYS;
Phil Sutter62029532015-12-25 14:41:24 +010075 }
Stefan Roese09e89ab2016-02-10 07:23:00 +010076
Stefan Roese9c6d3b72015-04-25 06:29:51 +020077 return MVEBU_SOC_UNKNOWN;
78}
79
Stefan Roese41e5ee52014-10-22 12:13:17 +020080#if defined(CONFIG_DISPLAY_CPUINFO)
Stefan Roesed718bf22015-12-21 12:36:40 +010081
Stefan Roese09e89ab2016-02-10 07:23:00 +010082#if defined(CONFIG_ARMADA_375)
83/* SAR frequency values for Armada 375 */
84static const struct sar_freq_modes sar_freq_tab[] = {
85 { 0, 0x0, 266, 133, 266 },
86 { 1, 0x0, 333, 167, 167 },
87 { 2, 0x0, 333, 167, 222 },
88 { 3, 0x0, 333, 167, 333 },
89 { 4, 0x0, 400, 200, 200 },
90 { 5, 0x0, 400, 200, 267 },
91 { 6, 0x0, 400, 200, 400 },
92 { 7, 0x0, 500, 250, 250 },
93 { 8, 0x0, 500, 250, 334 },
94 { 9, 0x0, 500, 250, 500 },
95 { 10, 0x0, 533, 267, 267 },
96 { 11, 0x0, 533, 267, 356 },
97 { 12, 0x0, 533, 267, 533 },
98 { 13, 0x0, 600, 300, 300 },
99 { 14, 0x0, 600, 300, 400 },
100 { 15, 0x0, 600, 300, 600 },
101 { 16, 0x0, 666, 333, 333 },
102 { 17, 0x0, 666, 333, 444 },
103 { 18, 0x0, 666, 333, 666 },
104 { 19, 0x0, 800, 400, 267 },
105 { 20, 0x0, 800, 400, 400 },
106 { 21, 0x0, 800, 400, 534 },
107 { 22, 0x0, 900, 450, 300 },
108 { 23, 0x0, 900, 450, 450 },
109 { 24, 0x0, 900, 450, 600 },
110 { 25, 0x0, 1000, 500, 500 },
111 { 26, 0x0, 1000, 500, 667 },
112 { 27, 0x0, 1000, 333, 500 },
113 { 28, 0x0, 400, 400, 400 },
114 { 29, 0x0, 1100, 550, 550 },
115 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
116};
117#elif defined(CONFIG_ARMADA_38X)
Stefan Roesed35831f2016-01-07 14:03:11 +0100118/* SAR frequency values for Armada 38x */
Stefan Roesea9fc5a22016-01-07 14:04:51 +0100119static const struct sar_freq_modes sar_freq_tab[] = {
Chris Packham0a91e1c2017-09-05 17:03:26 +1200120 { 0x0, 0x0, 666, 333, 333 },
121 { 0x2, 0x0, 800, 400, 400 },
122 { 0x4, 0x0, 1066, 533, 533 },
123 { 0x6, 0x0, 1200, 600, 600 },
124 { 0x8, 0x0, 1332, 666, 666 },
125 { 0xc, 0x0, 1600, 800, 800 },
126 { 0x10, 0x0, 1866, 933, 933 },
127 { 0x13, 0x0, 2000, 1000, 933 },
128 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
Stefan Roesed718bf22015-12-21 12:36:40 +0100129};
Chris Packham0d0df462019-04-11 22:22:50 +1200130#elif defined(CONFIG_ARMADA_MSYS)
131static const struct sar_freq_modes sar_freq_tab[] = {
132 { 0x0, 0x0, 400, 400, 400 },
133 { 0x2, 0x0, 667, 333, 667 },
134 { 0x3, 0x0, 800, 400, 800 },
135 { 0x5, 0x0, 800, 400, 800 },
136 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
137};
Stefan Roesed718bf22015-12-21 12:36:40 +0100138#else
Stefan Roesed35831f2016-01-07 14:03:11 +0100139/* SAR frequency values for Armada XP */
Stefan Roesea9fc5a22016-01-07 14:04:51 +0100140static const struct sar_freq_modes sar_freq_tab[] = {
Stefan Roesed718bf22015-12-21 12:36:40 +0100141 { 0xa, 0x5, 800, 400, 400 },
142 { 0x1, 0x5, 1066, 533, 533 },
143 { 0x2, 0x5, 1200, 600, 600 },
144 { 0x2, 0x9, 1200, 600, 400 },
145 { 0x3, 0x5, 1333, 667, 667 },
146 { 0x4, 0x5, 1500, 750, 750 },
147 { 0x4, 0x9, 1500, 750, 500 },
148 { 0xb, 0x9, 1600, 800, 533 },
149 { 0xb, 0xa, 1600, 800, 640 },
150 { 0xb, 0x5, 1600, 800, 800 },
151 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
152};
153#endif
154
155void get_sar_freq(struct sar_freq_modes *sar_freq)
156{
157 u32 val;
158 u32 freq;
159 int i;
160
Chris Packham0d0df462019-04-11 22:22:50 +1200161#if defined(CONFIG_ARMADA_375) || defined(CONFIG_ARMADA_MSYS)
Stefan Roese09e89ab2016-02-10 07:23:00 +0100162 val = readl(CONFIG_SAR2_REG); /* SAR - Sample At Reset */
163#else
Stefan Roesed718bf22015-12-21 12:36:40 +0100164 val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */
Stefan Roese09e89ab2016-02-10 07:23:00 +0100165#endif
Stefan Roesed718bf22015-12-21 12:36:40 +0100166 freq = (val & SAR_CPU_FREQ_MASK) >> SAR_CPU_FREQ_OFFS;
Stefan Roese09e89ab2016-02-10 07:23:00 +0100167#if defined(SAR2_CPU_FREQ_MASK)
Stefan Roesed718bf22015-12-21 12:36:40 +0100168 /*
169 * Shift CPU0 clock frequency select bit from SAR2 register
170 * into correct position
171 */
172 freq |= ((readl(CONFIG_SAR2_REG) & SAR2_CPU_FREQ_MASK)
173 >> SAR2_CPU_FREQ_OFFS) << 3;
174#endif
175 for (i = 0; sar_freq_tab[i].val != 0xff; i++) {
176 if (sar_freq_tab[i].val == freq) {
Chris Packham0d0df462019-04-11 22:22:50 +1200177#if defined(CONFIG_ARMADA_375) || defined(CONFIG_ARMADA_38X) || defined(CONFIG_ARMADA_MSYS)
Stefan Roesed718bf22015-12-21 12:36:40 +0100178 *sar_freq = sar_freq_tab[i];
179 return;
180#else
181 int k;
182 u8 ffc;
183
184 ffc = (val & SAR_FFC_FREQ_MASK) >>
185 SAR_FFC_FREQ_OFFS;
186 for (k = i; sar_freq_tab[k].ffc != 0xff; k++) {
187 if (sar_freq_tab[k].ffc == ffc) {
188 *sar_freq = sar_freq_tab[k];
189 return;
190 }
191 }
192 i = k;
193#endif
194 }
195 }
196
197 /* SAR value not found, return 0 for frequencies */
198 *sar_freq = sar_freq_tab[i - 1];
199}
200
Stefan Roese41e5ee52014-10-22 12:13:17 +0200201int print_cpuinfo(void)
202{
203 u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
204 u8 revid = readl(MVEBU_REG_PCIE_REVID) & 0xff;
Stefan Roesed718bf22015-12-21 12:36:40 +0100205 struct sar_freq_modes sar_freq;
Stefan Roese41e5ee52014-10-22 12:13:17 +0200206
207 puts("SoC: ");
208
209 switch (devid) {
Phil Sutter62029532015-12-25 14:41:24 +0100210 case SOC_MV78230_ID:
211 puts("MV78230-");
212 break;
Stefan Roesebf0db8b2015-12-09 11:00:51 +0100213 case SOC_MV78260_ID:
214 puts("MV78260-");
215 break;
Stefan Roese41e5ee52014-10-22 12:13:17 +0200216 case SOC_MV78460_ID:
217 puts("MV78460-");
218 break;
Stefan Roese09e89ab2016-02-10 07:23:00 +0100219 case SOC_88F6720_ID:
220 puts("MV88F6720-");
221 break;
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200222 case SOC_88F6810_ID:
223 puts("MV88F6810-");
224 break;
225 case SOC_88F6820_ID:
226 puts("MV88F6820-");
227 break;
228 case SOC_88F6828_ID:
229 puts("MV88F6828-");
230 break;
Chris Packham0f8031a2017-09-04 17:38:31 +1200231 case SOC_98DX3236_ID:
232 puts("98DX3236-");
233 break;
234 case SOC_98DX3336_ID:
235 puts("98DX3336-");
236 break;
237 case SOC_98DX4251_ID:
238 puts("98DX4251-");
239 break;
Stefan Roese41e5ee52014-10-22 12:13:17 +0200240 default:
241 puts("Unknown-");
242 break;
243 }
244
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200245 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
246 switch (revid) {
247 case 1:
Stefan Roesed718bf22015-12-21 12:36:40 +0100248 puts("A0");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200249 break;
250 case 2:
Stefan Roesed718bf22015-12-21 12:36:40 +0100251 puts("B0");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200252 break;
253 default:
Stefan Roesed718bf22015-12-21 12:36:40 +0100254 printf("?? (%x)", revid);
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200255 break;
256 }
257 }
258
Stefan Roese09e89ab2016-02-10 07:23:00 +0100259 if (mvebu_soc_family() == MVEBU_SOC_A375) {
260 switch (revid) {
261 case MV_88F67XX_A0_ID:
262 puts("A0");
263 break;
264 default:
265 printf("?? (%x)", revid);
266 break;
267 }
268 }
269
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200270 if (mvebu_soc_family() == MVEBU_SOC_A38X) {
271 switch (revid) {
272 case MV_88F68XX_Z1_ID:
Stefan Roesed718bf22015-12-21 12:36:40 +0100273 puts("Z1");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200274 break;
275 case MV_88F68XX_A0_ID:
Stefan Roesed718bf22015-12-21 12:36:40 +0100276 puts("A0");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200277 break;
Chris Packhamd997ad02018-11-28 10:32:00 +1300278 case MV_88F68XX_B0_ID:
279 puts("B0");
280 break;
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200281 default:
Stefan Roesed718bf22015-12-21 12:36:40 +0100282 printf("?? (%x)", revid);
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200283 break;
284 }
Stefan Roese41e5ee52014-10-22 12:13:17 +0200285 }
286
Chris Packham0d0df462019-04-11 22:22:50 +1200287 if (mvebu_soc_family() == MVEBU_SOC_MSYS) {
288 switch (revid) {
289 case 3:
290 puts("A0");
291 break;
292 case 4:
293 puts("A1");
294 break;
295 default:
296 printf("?? (%x)", revid);
297 break;
298 }
299 }
300
Stefan Roesed718bf22015-12-21 12:36:40 +0100301 get_sar_freq(&sar_freq);
302 printf(" at %d MHz\n", sar_freq.p_clk);
303
Stefan Roese41e5ee52014-10-22 12:13:17 +0200304 return 0;
305}
306#endif /* CONFIG_DISPLAY_CPUINFO */
307
308/*
309 * This function initialize Controller DRAM Fastpath windows.
310 * It takes the CS size information from the 0x1500 scratch registers
311 * and sets the correct windows sizes and base addresses accordingly.
312 *
313 * These values are set in the scratch registers by the Marvell
Chris Packham1670a152018-12-14 16:27:57 +1300314 * DDR3 training code, which is executed by the SPL before the
315 * main payload (U-Boot) is executed.
Stefan Roese41e5ee52014-10-22 12:13:17 +0200316 */
317static void update_sdram_window_sizes(void)
318{
319 u64 base = 0;
320 u32 size, temp;
321 int i;
322
323 for (i = 0; i < SDRAM_MAX_CS; i++) {
324 size = readl((MVEBU_SDRAM_SCRATCH + (i * 8))) & SDRAM_ADDR_MASK;
325 if (size != 0) {
326 size |= ~(SDRAM_ADDR_MASK);
327
328 /* Set Base Address */
329 temp = (base & 0xFF000000ll) | ((base >> 32) & 0xF);
330 writel(temp, MVEBU_SDRAM_BASE + DDR_BASE_CS_OFF(i));
331
332 /*
333 * Check if out of max window size and resize
334 * the window
335 */
336 temp = (readl(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i)) &
337 ~(SDRAM_ADDR_MASK)) | 1;
338 temp |= (size & SDRAM_ADDR_MASK);
339 writel(temp, MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i));
340
341 base += ((u64)size + 1);
342 } else {
343 /*
344 * Disable window if not used, otherwise this
345 * leads to overlapping enabled windows with
346 * pretty strange results
347 */
348 clrbits_le32(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i), 1);
349 }
350 }
351}
352
Stefan Roese9f62b442015-04-24 10:49:11 +0200353void mmu_disable(void)
354{
355 asm volatile(
356 "mrc p15, 0, r0, c1, c0, 0\n"
357 "bic r0, #1\n"
358 "mcr p15, 0, r0, c1, c0, 0\n");
359}
360
Stefan Roese41e5ee52014-10-22 12:13:17 +0200361#ifdef CONFIG_ARCH_CPU_INIT
Kevin Smithe1b078e2015-05-18 16:09:44 +0000362static void set_cbar(u32 addr)
363{
364 asm("mcr p15, 4, %0, c15, c0" : : "r" (addr));
365}
366
Stefan Roesedee40d22015-07-22 18:26:13 +0200367#define MV_USB_PHY_BASE (MVEBU_AXP_USB_BASE + 0x800)
368#define MV_USB_PHY_PLL_REG(reg) (MV_USB_PHY_BASE | (((reg) & 0xF) << 2))
369#define MV_USB_X3_BASE(addr) (MVEBU_AXP_USB_BASE | BIT(11) | \
370 (((addr) & 0xF) << 6))
371#define MV_USB_X3_PHY_CHANNEL(dev, reg) (MV_USB_X3_BASE((dev) + 1) | \
372 (((reg) & 0xF) << 2))
373
374static void setup_usb_phys(void)
375{
376 int dev;
377
378 /*
379 * USB PLL init
380 */
381
382 /* Setup PLL frequency */
383 /* USB REF frequency = 25 MHz */
384 clrsetbits_le32(MV_USB_PHY_PLL_REG(1), 0x3ff, 0x605);
385
386 /* Power up PLL and PHY channel */
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100387 setbits_le32(MV_USB_PHY_PLL_REG(2), BIT(9));
Stefan Roesedee40d22015-07-22 18:26:13 +0200388
389 /* Assert VCOCAL_START */
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100390 setbits_le32(MV_USB_PHY_PLL_REG(1), BIT(21));
Stefan Roesedee40d22015-07-22 18:26:13 +0200391
392 mdelay(1);
393
394 /*
395 * USB PHY init (change from defaults) specific for 40nm (78X30 78X60)
396 */
397
398 for (dev = 0; dev < 3; dev++) {
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100399 setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 3), BIT(15));
Stefan Roesedee40d22015-07-22 18:26:13 +0200400
401 /* Assert REG_RCAL_START in channel REG 1 */
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100402 setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
Stefan Roesedee40d22015-07-22 18:26:13 +0200403 udelay(40);
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100404 clrbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
Stefan Roesedee40d22015-07-22 18:26:13 +0200405 }
406}
Kevin Smithe1b078e2015-05-18 16:09:44 +0000407
Stefan Roesef4e6ec72015-12-03 12:39:45 +0100408/*
409 * This function is not called from the SPL U-Boot version
410 */
Stefan Roese41e5ee52014-10-22 12:13:17 +0200411int arch_cpu_init(void)
412{
Stefan Roese42cc0342015-08-25 14:09:12 +0200413 struct pl310_regs *const pl310 =
414 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
415
Stefan Roesecefd7642015-08-24 11:03:50 +0200416 /*
417 * Only with disabled MMU its possible to switch the base
418 * register address on Armada 38x. Without this the SDRAM
419 * located at >= 0x4000.0000 is also not accessible, as its
420 * still locked to cache.
421 */
422 mmu_disable();
Stefan Roese9f62b442015-04-24 10:49:11 +0200423
Stefan Roese41e5ee52014-10-22 12:13:17 +0200424 /* Linux expects the internal registers to be at 0xf1000000 */
425 writel(SOC_REGS_PHY_BASE, INTREG_BASE_ADDR_REG);
Kevin Smithe1b078e2015-05-18 16:09:44 +0000426 set_cbar(SOC_REGS_PHY_BASE + 0xC000);
Stefan Roese41e5ee52014-10-22 12:13:17 +0200427
Stefan Roesecefd7642015-08-24 11:03:50 +0200428 /*
429 * From this stage on, the SoC detection is working. As we have
430 * configured the internal register base to the value used
431 * in the macros / defines in the U-Boot header (soc.h).
432 */
Stefan Roesecefd7642015-08-24 11:03:50 +0200433
Stefan Roesec86d53f2015-12-03 12:39:45 +0100434 if (mvebu_soc_family() == MVEBU_SOC_A38X) {
435 /*
436 * To fully release / unlock this area from cache, we need
437 * to flush all caches and disable the L2 cache.
438 */
439 icache_disable();
440 dcache_disable();
441 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
442 }
Stefan Roesecefd7642015-08-24 11:03:50 +0200443
Stefan Roese41e5ee52014-10-22 12:13:17 +0200444 /*
445 * We need to call mvebu_mbus_probe() before calling
446 * update_sdram_window_sizes() as it disables all previously
447 * configured mbus windows and then configures them as
448 * required for U-Boot. Calling update_sdram_window_sizes()
449 * without this configuration will not work, as the internal
450 * registers can't be accessed reliably because of potenial
451 * double mapping.
452 * After updating the SDRAM access windows we need to call
453 * mvebu_mbus_probe() again, as this now correctly configures
454 * the SDRAM areas that are later used by the MVEBU drivers
455 * (e.g. USB, NETA).
456 */
457
458 /*
459 * First disable all windows
460 */
461 mvebu_mbus_probe(NULL, 0);
462
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200463 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
464 /*
465 * Now the SDRAM access windows can be reconfigured using
466 * the information in the SDRAM scratch pad registers
467 */
468 update_sdram_window_sizes();
469 }
Stefan Roese41e5ee52014-10-22 12:13:17 +0200470
471 /*
472 * Finally the mbus windows can be configured with the
473 * updated SDRAM sizes
474 */
475 mvebu_mbus_probe(windows, ARRAY_SIZE(windows));
476
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200477 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
478 /* Enable GBE0, GBE1, LCD and NFC PUP */
479 clrsetbits_le32(ARMADA_XP_PUP_ENABLE, 0,
480 GE0_PUP_EN | GE1_PUP_EN | LCD_PUP_EN |
481 NAND_PUP_EN | SPI_PUP_EN);
Stefan Roesedee40d22015-07-22 18:26:13 +0200482
483 /* Configure USB PLL and PHYs on AXP */
484 setup_usb_phys();
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200485 }
486
487 /* Enable NAND and NAND arbiter */
488 clrsetbits_le32(MVEBU_SOC_DEV_MUX_REG, 0, NAND_EN | NAND_ARBITER_EN);
489
Stefan Roese501c0982015-07-01 13:28:39 +0200490 /* Disable MBUS error propagation */
491 clrsetbits_le32(SOC_COHERENCY_FABRIC_CTRL_REG, MBUS_ERR_PROP_EN, 0);
492
Stefan Roese41e5ee52014-10-22 12:13:17 +0200493 return 0;
494}
495#endif /* CONFIG_ARCH_CPU_INIT */
496
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200497u32 mvebu_get_nand_clock(void)
498{
Chris Packhamd7b47312016-08-22 12:38:39 +1200499 u32 reg;
500
501 if (mvebu_soc_family() == MVEBU_SOC_A38X)
502 reg = MVEBU_DFX_DIV_CLK_CTRL(1);
Chris Packham689f9cf2019-04-11 22:22:51 +1200503 else if (mvebu_soc_family() == MVEBU_SOC_MSYS)
504 reg = MVEBU_DFX_DIV_CLK_CTRL(8);
Chris Packhamd7b47312016-08-22 12:38:39 +1200505 else
506 reg = MVEBU_CORE_DIV_CLK_CTRL(1);
507
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200508 return CONFIG_SYS_MVEBU_PLL_CLOCK /
Chris Packhamd7b47312016-08-22 12:38:39 +1200509 ((readl(reg) &
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200510 NAND_ECC_DIVCKL_RATIO_MASK) >> NAND_ECC_DIVCKL_RATIO_OFFS);
511}
512
Stefan Roese41e5ee52014-10-22 12:13:17 +0200513/*
514 * SOC specific misc init
515 */
516#if defined(CONFIG_ARCH_MISC_INIT)
517int arch_misc_init(void)
518{
519 /* Nothing yet, perhaps we need something here later */
520 return 0;
521}
522#endif /* CONFIG_ARCH_MISC_INIT */
523
Pierre Bourdon4ec9dd42019-04-11 04:56:58 +0200524#if defined(CONFIG_MMC_SDHCI_MV) && !defined(CONFIG_DM_MMC)
Stefan Roese7f1adcd2015-06-29 14:58:10 +0200525int board_mmc_init(bd_t *bis)
526{
527 mv_sdh_init(MVEBU_SDIO_BASE, 0, 0,
528 SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_WAIT_SEND_CMD);
529
530 return 0;
531}
532#endif
533
Stefan Roese4d991cb2015-06-29 14:58:13 +0200534#define AHCI_VENDOR_SPECIFIC_0_ADDR 0xa0
535#define AHCI_VENDOR_SPECIFIC_0_DATA 0xa4
536
537#define AHCI_WINDOW_CTRL(win) (0x60 + ((win) << 4))
538#define AHCI_WINDOW_BASE(win) (0x64 + ((win) << 4))
539#define AHCI_WINDOW_SIZE(win) (0x68 + ((win) << 4))
540
541static void ahci_mvebu_mbus_config(void __iomem *base)
542{
543 const struct mbus_dram_target_info *dram;
544 int i;
545
Baruch Siachf0aa1252019-05-16 13:03:57 +0300546 /* mbus is not initialized in SPL; keep the ROM settings */
547 if (IS_ENABLED(CONFIG_SPL_BUILD))
548 return;
549
Stefan Roese4d991cb2015-06-29 14:58:13 +0200550 dram = mvebu_mbus_dram_info();
551
552 for (i = 0; i < 4; i++) {
553 writel(0, base + AHCI_WINDOW_CTRL(i));
554 writel(0, base + AHCI_WINDOW_BASE(i));
555 writel(0, base + AHCI_WINDOW_SIZE(i));
556 }
557
558 for (i = 0; i < dram->num_cs; i++) {
559 const struct mbus_dram_window *cs = dram->cs + i;
560
561 writel((cs->mbus_attr << 8) |
562 (dram->mbus_dram_target_id << 4) | 1,
563 base + AHCI_WINDOW_CTRL(i));
564 writel(cs->base >> 16, base + AHCI_WINDOW_BASE(i));
565 writel(((cs->size - 1) & 0xffff0000),
566 base + AHCI_WINDOW_SIZE(i));
567 }
568}
569
570static void ahci_mvebu_regret_option(void __iomem *base)
571{
572 /*
573 * Enable the regret bit to allow the SATA unit to regret a
574 * request that didn't receive an acknowlegde and avoid a
575 * deadlock
576 */
577 writel(0x4, base + AHCI_VENDOR_SPECIFIC_0_ADDR);
578 writel(0x80, base + AHCI_VENDOR_SPECIFIC_0_DATA);
579}
580
Baruch Siach4b11e5f2019-03-24 13:27:43 +0200581int board_ahci_enable(void)
582{
583 ahci_mvebu_mbus_config((void __iomem *)MVEBU_SATA0_BASE);
584 ahci_mvebu_regret_option((void __iomem *)MVEBU_SATA0_BASE);
585
586 return 0;
587}
588
589#ifdef CONFIG_SCSI_AHCI_PLAT
Stefan Roese4d991cb2015-06-29 14:58:13 +0200590void scsi_init(void)
591{
592 printf("MVEBU SATA INIT\n");
Baruch Siach4b11e5f2019-03-24 13:27:43 +0200593 board_ahci_enable();
Stefan Roese4d991cb2015-06-29 14:58:13 +0200594 ahci_init((void __iomem *)MVEBU_SATA0_BASE);
595}
596#endif
597
Jon Nettleton78aa0182017-11-06 10:33:20 +0200598#ifdef CONFIG_USB_XHCI_MVEBU
599#define USB3_MAX_WINDOWS 4
600#define USB3_WIN_CTRL(w) (0x0 + ((w) * 8))
601#define USB3_WIN_BASE(w) (0x4 + ((w) * 8))
602
603static void xhci_mvebu_mbus_config(void __iomem *base,
604 const struct mbus_dram_target_info *dram)
605{
606 int i;
607
608 for (i = 0; i < USB3_MAX_WINDOWS; i++) {
609 writel(0, base + USB3_WIN_CTRL(i));
610 writel(0, base + USB3_WIN_BASE(i));
611 }
612
613 for (i = 0; i < dram->num_cs; i++) {
614 const struct mbus_dram_window *cs = dram->cs + i;
615
616 /* Write size, attributes and target id to control register */
617 writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
618 (dram->mbus_dram_target_id << 4) | 1,
619 base + USB3_WIN_CTRL(i));
620
621 /* Write base address to base register */
622 writel((cs->base & 0xffff0000), base + USB3_WIN_BASE(i));
623 }
624}
625
626int board_xhci_enable(fdt_addr_t base)
627{
628 const struct mbus_dram_target_info *dram;
629
630 printf("MVEBU XHCI INIT controller @ 0x%lx\n", base);
631
632 dram = mvebu_mbus_dram_info();
633 xhci_mvebu_mbus_config((void __iomem *)base, dram);
634
635 return 0;
636}
637#endif
638
Stefan Roese41e5ee52014-10-22 12:13:17 +0200639void enable_caches(void)
640{
Stefan Roese60b75322015-04-25 06:29:55 +0200641 /* Avoid problem with e.g. neta ethernet driver */
642 invalidate_dcache_all();
643
Stefan Roeseebe78902016-02-10 09:18:46 +0100644 /*
645 * Armada 375 still has some problems with d-cache enabled in the
646 * ethernet driver (mvpp2). So lets keep the d-cache disabled
647 * until this is solved.
648 */
649 if (mvebu_soc_family() != MVEBU_SOC_A375) {
650 /* Enable D-cache. I-cache is already enabled in start.S */
651 dcache_enable();
652 }
Stefan Roese41e5ee52014-10-22 12:13:17 +0200653}
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100654
655void v7_outer_cache_enable(void)
656{
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100657 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
Stefan Roesec86d53f2015-12-03 12:39:45 +0100658 struct pl310_regs *const pl310 =
659 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100660 u32 u;
661
Stefan Roesec86d53f2015-12-03 12:39:45 +0100662 /* The L2 cache is already disabled at this point */
663
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100664 /*
665 * For Aurora cache in no outer mode, enable via the CP15
666 * coprocessor broadcasting of cache commands to L2.
667 */
668 asm volatile("mrc p15, 1, %0, c15, c2, 0" : "=r" (u));
669 u |= BIT(8); /* Set the FW bit */
670 asm volatile("mcr p15, 1, %0, c15, c2, 0" : : "r" (u));
671
672 isb();
673
674 /* Enable the L2 cache */
675 setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
676 }
677}
Stefan Roesef0e81732015-12-14 12:31:48 +0100678
679void v7_outer_cache_disable(void)
680{
681 struct pl310_regs *const pl310 =
682 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
683
684 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
685}