blob: ab8b02956b28c5a992daf48ee910c1b59f8f5086 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roese41e5ee52014-10-22 12:13:17 +02002/*
Stefan Roesed35831f2016-01-07 14:03:11 +01003 * Copyright (C) 2014-2016 Stefan Roese <sr@denx.de>
Stefan Roese41e5ee52014-10-22 12:13:17 +02004 */
5
6#include <common.h>
Stefan Roese4d991cb2015-06-29 14:58:13 +02007#include <ahci.h>
Simon Glass9edefc22019-11-14 12:57:37 -07008#include <cpu_func.h>
Simon Glass691d7192020-05-10 11:40:02 -06009#include <init.h>
Stefan Roese4d991cb2015-06-29 14:58:13 +020010#include <linux/mbus.h>
Stefan Roese41e5ee52014-10-22 12:13:17 +020011#include <asm/io.h>
Stefan Roese57303602015-05-18 16:09:43 +000012#include <asm/pl310.h>
Stefan Roese41e5ee52014-10-22 12:13:17 +020013#include <asm/arch/cpu.h>
14#include <asm/arch/soc.h>
Stefan Roese7f1adcd2015-06-29 14:58:10 +020015#include <sdhci.h>
Stefan Roese41e5ee52014-10-22 12:13:17 +020016
17#define DDR_BASE_CS_OFF(n) (0x0000 + ((n) << 3))
18#define DDR_SIZE_CS_OFF(n) (0x0004 + ((n) << 3))
19
20static struct mbus_win windows[] = {
Stefan Roese41e5ee52014-10-22 12:13:17 +020021 /* SPI */
Stefan Roese8ed20d62015-07-01 12:55:07 +020022 { MBUS_SPI_BASE, MBUS_SPI_SIZE,
23 CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_SPIFLASH },
Stefan Roese41e5ee52014-10-22 12:13:17 +020024
25 /* NOR */
Stefan Roese8ed20d62015-07-01 12:55:07 +020026 { MBUS_BOOTROM_BASE, MBUS_BOOTROM_SIZE,
27 CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_BOOTROM },
Chris Packham0d0df462019-04-11 22:22:50 +120028
29#ifdef CONFIG_ARMADA_MSYS
30 /* DFX */
31 { MBUS_DFX_BASE, MBUS_DFX_SIZE, CPU_TARGET_DFX, 0 },
32#endif
Stefan Roese41e5ee52014-10-22 12:13:17 +020033};
34
Stefan Roese42cc0342015-08-25 14:09:12 +020035void lowlevel_init(void)
36{
37 /*
38 * Dummy implementation, we only need LOWLEVEL_INIT
39 * on Armada to configure CP15 in start.S / cpu_init_cp15()
40 */
41}
42
Stefan Roese41e5ee52014-10-22 12:13:17 +020043void reset_cpu(unsigned long ignored)
44{
45 struct mvebu_system_registers *reg =
46 (struct mvebu_system_registers *)MVEBU_SYSTEM_REG_BASE;
47
48 writel(readl(&reg->rstoutn_mask) | 1, &reg->rstoutn_mask);
49 writel(readl(&reg->sys_soft_rst) | 1, &reg->sys_soft_rst);
50 while (1)
51 ;
52}
53
Stefan Roese9c6d3b72015-04-25 06:29:51 +020054int mvebu_soc_family(void)
55{
56 u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
57
Phil Sutter62029532015-12-25 14:41:24 +010058 switch (devid) {
59 case SOC_MV78230_ID:
60 case SOC_MV78260_ID:
61 case SOC_MV78460_ID:
Stefan Roese9c6d3b72015-04-25 06:29:51 +020062 return MVEBU_SOC_AXP;
Stefan Roese09e89ab2016-02-10 07:23:00 +010063
64 case SOC_88F6720_ID:
65 return MVEBU_SOC_A375;
66
Phil Sutter62029532015-12-25 14:41:24 +010067 case SOC_88F6810_ID:
68 case SOC_88F6820_ID:
69 case SOC_88F6828_ID:
Stefan Roese9c6d3b72015-04-25 06:29:51 +020070 return MVEBU_SOC_A38X;
Chris Packham0f8031a2017-09-04 17:38:31 +120071
72 case SOC_98DX3236_ID:
73 case SOC_98DX3336_ID:
74 case SOC_98DX4251_ID:
75 return MVEBU_SOC_MSYS;
Phil Sutter62029532015-12-25 14:41:24 +010076 }
Stefan Roese09e89ab2016-02-10 07:23:00 +010077
Stefan Roese9c6d3b72015-04-25 06:29:51 +020078 return MVEBU_SOC_UNKNOWN;
79}
80
Stefan Roese41e5ee52014-10-22 12:13:17 +020081#if defined(CONFIG_DISPLAY_CPUINFO)
Stefan Roesed718bf22015-12-21 12:36:40 +010082
Stefan Roese09e89ab2016-02-10 07:23:00 +010083#if defined(CONFIG_ARMADA_375)
84/* SAR frequency values for Armada 375 */
85static const struct sar_freq_modes sar_freq_tab[] = {
86 { 0, 0x0, 266, 133, 266 },
87 { 1, 0x0, 333, 167, 167 },
88 { 2, 0x0, 333, 167, 222 },
89 { 3, 0x0, 333, 167, 333 },
90 { 4, 0x0, 400, 200, 200 },
91 { 5, 0x0, 400, 200, 267 },
92 { 6, 0x0, 400, 200, 400 },
93 { 7, 0x0, 500, 250, 250 },
94 { 8, 0x0, 500, 250, 334 },
95 { 9, 0x0, 500, 250, 500 },
96 { 10, 0x0, 533, 267, 267 },
97 { 11, 0x0, 533, 267, 356 },
98 { 12, 0x0, 533, 267, 533 },
99 { 13, 0x0, 600, 300, 300 },
100 { 14, 0x0, 600, 300, 400 },
101 { 15, 0x0, 600, 300, 600 },
102 { 16, 0x0, 666, 333, 333 },
103 { 17, 0x0, 666, 333, 444 },
104 { 18, 0x0, 666, 333, 666 },
105 { 19, 0x0, 800, 400, 267 },
106 { 20, 0x0, 800, 400, 400 },
107 { 21, 0x0, 800, 400, 534 },
108 { 22, 0x0, 900, 450, 300 },
109 { 23, 0x0, 900, 450, 450 },
110 { 24, 0x0, 900, 450, 600 },
111 { 25, 0x0, 1000, 500, 500 },
112 { 26, 0x0, 1000, 500, 667 },
113 { 27, 0x0, 1000, 333, 500 },
114 { 28, 0x0, 400, 400, 400 },
115 { 29, 0x0, 1100, 550, 550 },
116 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
117};
118#elif defined(CONFIG_ARMADA_38X)
Stefan Roesed35831f2016-01-07 14:03:11 +0100119/* SAR frequency values for Armada 38x */
Stefan Roesea9fc5a22016-01-07 14:04:51 +0100120static const struct sar_freq_modes sar_freq_tab[] = {
Chris Packham0a91e1c2017-09-05 17:03:26 +1200121 { 0x0, 0x0, 666, 333, 333 },
122 { 0x2, 0x0, 800, 400, 400 },
123 { 0x4, 0x0, 1066, 533, 533 },
124 { 0x6, 0x0, 1200, 600, 600 },
125 { 0x8, 0x0, 1332, 666, 666 },
126 { 0xc, 0x0, 1600, 800, 800 },
127 { 0x10, 0x0, 1866, 933, 933 },
128 { 0x13, 0x0, 2000, 1000, 933 },
129 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
Stefan Roesed718bf22015-12-21 12:36:40 +0100130};
Chris Packham0d0df462019-04-11 22:22:50 +1200131#elif defined(CONFIG_ARMADA_MSYS)
132static const struct sar_freq_modes sar_freq_tab[] = {
133 { 0x0, 0x0, 400, 400, 400 },
134 { 0x2, 0x0, 667, 333, 667 },
135 { 0x3, 0x0, 800, 400, 800 },
136 { 0x5, 0x0, 800, 400, 800 },
137 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
138};
Stefan Roesed718bf22015-12-21 12:36:40 +0100139#else
Stefan Roesed35831f2016-01-07 14:03:11 +0100140/* SAR frequency values for Armada XP */
Stefan Roesea9fc5a22016-01-07 14:04:51 +0100141static const struct sar_freq_modes sar_freq_tab[] = {
Stefan Roesed718bf22015-12-21 12:36:40 +0100142 { 0xa, 0x5, 800, 400, 400 },
143 { 0x1, 0x5, 1066, 533, 533 },
144 { 0x2, 0x5, 1200, 600, 600 },
145 { 0x2, 0x9, 1200, 600, 400 },
146 { 0x3, 0x5, 1333, 667, 667 },
147 { 0x4, 0x5, 1500, 750, 750 },
148 { 0x4, 0x9, 1500, 750, 500 },
149 { 0xb, 0x9, 1600, 800, 533 },
150 { 0xb, 0xa, 1600, 800, 640 },
151 { 0xb, 0x5, 1600, 800, 800 },
152 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
153};
154#endif
155
156void get_sar_freq(struct sar_freq_modes *sar_freq)
157{
158 u32 val;
159 u32 freq;
160 int i;
161
Chris Packham0d0df462019-04-11 22:22:50 +1200162#if defined(CONFIG_ARMADA_375) || defined(CONFIG_ARMADA_MSYS)
Stefan Roese09e89ab2016-02-10 07:23:00 +0100163 val = readl(CONFIG_SAR2_REG); /* SAR - Sample At Reset */
164#else
Stefan Roesed718bf22015-12-21 12:36:40 +0100165 val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */
Stefan Roese09e89ab2016-02-10 07:23:00 +0100166#endif
Stefan Roesed718bf22015-12-21 12:36:40 +0100167 freq = (val & SAR_CPU_FREQ_MASK) >> SAR_CPU_FREQ_OFFS;
Stefan Roese09e89ab2016-02-10 07:23:00 +0100168#if defined(SAR2_CPU_FREQ_MASK)
Stefan Roesed718bf22015-12-21 12:36:40 +0100169 /*
170 * Shift CPU0 clock frequency select bit from SAR2 register
171 * into correct position
172 */
173 freq |= ((readl(CONFIG_SAR2_REG) & SAR2_CPU_FREQ_MASK)
174 >> SAR2_CPU_FREQ_OFFS) << 3;
175#endif
176 for (i = 0; sar_freq_tab[i].val != 0xff; i++) {
177 if (sar_freq_tab[i].val == freq) {
Chris Packham0d0df462019-04-11 22:22:50 +1200178#if defined(CONFIG_ARMADA_375) || defined(CONFIG_ARMADA_38X) || defined(CONFIG_ARMADA_MSYS)
Stefan Roesed718bf22015-12-21 12:36:40 +0100179 *sar_freq = sar_freq_tab[i];
180 return;
181#else
182 int k;
183 u8 ffc;
184
185 ffc = (val & SAR_FFC_FREQ_MASK) >>
186 SAR_FFC_FREQ_OFFS;
187 for (k = i; sar_freq_tab[k].ffc != 0xff; k++) {
188 if (sar_freq_tab[k].ffc == ffc) {
189 *sar_freq = sar_freq_tab[k];
190 return;
191 }
192 }
193 i = k;
194#endif
195 }
196 }
197
198 /* SAR value not found, return 0 for frequencies */
199 *sar_freq = sar_freq_tab[i - 1];
200}
201
Stefan Roese41e5ee52014-10-22 12:13:17 +0200202int print_cpuinfo(void)
203{
204 u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
205 u8 revid = readl(MVEBU_REG_PCIE_REVID) & 0xff;
Stefan Roesed718bf22015-12-21 12:36:40 +0100206 struct sar_freq_modes sar_freq;
Stefan Roese41e5ee52014-10-22 12:13:17 +0200207
208 puts("SoC: ");
209
210 switch (devid) {
Phil Sutter62029532015-12-25 14:41:24 +0100211 case SOC_MV78230_ID:
212 puts("MV78230-");
213 break;
Stefan Roesebf0db8b2015-12-09 11:00:51 +0100214 case SOC_MV78260_ID:
215 puts("MV78260-");
216 break;
Stefan Roese41e5ee52014-10-22 12:13:17 +0200217 case SOC_MV78460_ID:
218 puts("MV78460-");
219 break;
Stefan Roese09e89ab2016-02-10 07:23:00 +0100220 case SOC_88F6720_ID:
221 puts("MV88F6720-");
222 break;
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200223 case SOC_88F6810_ID:
224 puts("MV88F6810-");
225 break;
226 case SOC_88F6820_ID:
227 puts("MV88F6820-");
228 break;
229 case SOC_88F6828_ID:
230 puts("MV88F6828-");
231 break;
Chris Packham0f8031a2017-09-04 17:38:31 +1200232 case SOC_98DX3236_ID:
233 puts("98DX3236-");
234 break;
235 case SOC_98DX3336_ID:
236 puts("98DX3336-");
237 break;
238 case SOC_98DX4251_ID:
239 puts("98DX4251-");
240 break;
Stefan Roese41e5ee52014-10-22 12:13:17 +0200241 default:
242 puts("Unknown-");
243 break;
244 }
245
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200246 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
247 switch (revid) {
248 case 1:
Stefan Roesed718bf22015-12-21 12:36:40 +0100249 puts("A0");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200250 break;
251 case 2:
Stefan Roesed718bf22015-12-21 12:36:40 +0100252 puts("B0");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200253 break;
254 default:
Stefan Roesed718bf22015-12-21 12:36:40 +0100255 printf("?? (%x)", revid);
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200256 break;
257 }
258 }
259
Stefan Roese09e89ab2016-02-10 07:23:00 +0100260 if (mvebu_soc_family() == MVEBU_SOC_A375) {
261 switch (revid) {
262 case MV_88F67XX_A0_ID:
263 puts("A0");
264 break;
265 default:
266 printf("?? (%x)", revid);
267 break;
268 }
269 }
270
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200271 if (mvebu_soc_family() == MVEBU_SOC_A38X) {
272 switch (revid) {
273 case MV_88F68XX_Z1_ID:
Stefan Roesed718bf22015-12-21 12:36:40 +0100274 puts("Z1");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200275 break;
276 case MV_88F68XX_A0_ID:
Stefan Roesed718bf22015-12-21 12:36:40 +0100277 puts("A0");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200278 break;
Chris Packhamd997ad02018-11-28 10:32:00 +1300279 case MV_88F68XX_B0_ID:
280 puts("B0");
281 break;
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200282 default:
Stefan Roesed718bf22015-12-21 12:36:40 +0100283 printf("?? (%x)", revid);
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200284 break;
285 }
Stefan Roese41e5ee52014-10-22 12:13:17 +0200286 }
287
Chris Packham0d0df462019-04-11 22:22:50 +1200288 if (mvebu_soc_family() == MVEBU_SOC_MSYS) {
289 switch (revid) {
290 case 3:
291 puts("A0");
292 break;
293 case 4:
294 puts("A1");
295 break;
296 default:
297 printf("?? (%x)", revid);
298 break;
299 }
300 }
301
Stefan Roesed718bf22015-12-21 12:36:40 +0100302 get_sar_freq(&sar_freq);
303 printf(" at %d MHz\n", sar_freq.p_clk);
304
Stefan Roese41e5ee52014-10-22 12:13:17 +0200305 return 0;
306}
307#endif /* CONFIG_DISPLAY_CPUINFO */
308
309/*
310 * This function initialize Controller DRAM Fastpath windows.
311 * It takes the CS size information from the 0x1500 scratch registers
312 * and sets the correct windows sizes and base addresses accordingly.
313 *
314 * These values are set in the scratch registers by the Marvell
Chris Packham1670a152018-12-14 16:27:57 +1300315 * DDR3 training code, which is executed by the SPL before the
316 * main payload (U-Boot) is executed.
Stefan Roese41e5ee52014-10-22 12:13:17 +0200317 */
318static void update_sdram_window_sizes(void)
319{
320 u64 base = 0;
321 u32 size, temp;
322 int i;
323
324 for (i = 0; i < SDRAM_MAX_CS; i++) {
325 size = readl((MVEBU_SDRAM_SCRATCH + (i * 8))) & SDRAM_ADDR_MASK;
326 if (size != 0) {
327 size |= ~(SDRAM_ADDR_MASK);
328
329 /* Set Base Address */
330 temp = (base & 0xFF000000ll) | ((base >> 32) & 0xF);
331 writel(temp, MVEBU_SDRAM_BASE + DDR_BASE_CS_OFF(i));
332
333 /*
334 * Check if out of max window size and resize
335 * the window
336 */
337 temp = (readl(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i)) &
338 ~(SDRAM_ADDR_MASK)) | 1;
339 temp |= (size & SDRAM_ADDR_MASK);
340 writel(temp, MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i));
341
342 base += ((u64)size + 1);
343 } else {
344 /*
345 * Disable window if not used, otherwise this
346 * leads to overlapping enabled windows with
347 * pretty strange results
348 */
349 clrbits_le32(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i), 1);
350 }
351 }
352}
353
Stefan Roese9f62b442015-04-24 10:49:11 +0200354void mmu_disable(void)
355{
356 asm volatile(
357 "mrc p15, 0, r0, c1, c0, 0\n"
358 "bic r0, #1\n"
359 "mcr p15, 0, r0, c1, c0, 0\n");
360}
361
Stefan Roese41e5ee52014-10-22 12:13:17 +0200362#ifdef CONFIG_ARCH_CPU_INIT
Kevin Smithe1b078e2015-05-18 16:09:44 +0000363static void set_cbar(u32 addr)
364{
365 asm("mcr p15, 4, %0, c15, c0" : : "r" (addr));
366}
367
Stefan Roesedee40d22015-07-22 18:26:13 +0200368#define MV_USB_PHY_BASE (MVEBU_AXP_USB_BASE + 0x800)
369#define MV_USB_PHY_PLL_REG(reg) (MV_USB_PHY_BASE | (((reg) & 0xF) << 2))
370#define MV_USB_X3_BASE(addr) (MVEBU_AXP_USB_BASE | BIT(11) | \
371 (((addr) & 0xF) << 6))
372#define MV_USB_X3_PHY_CHANNEL(dev, reg) (MV_USB_X3_BASE((dev) + 1) | \
373 (((reg) & 0xF) << 2))
374
375static void setup_usb_phys(void)
376{
377 int dev;
378
379 /*
380 * USB PLL init
381 */
382
383 /* Setup PLL frequency */
384 /* USB REF frequency = 25 MHz */
385 clrsetbits_le32(MV_USB_PHY_PLL_REG(1), 0x3ff, 0x605);
386
387 /* Power up PLL and PHY channel */
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100388 setbits_le32(MV_USB_PHY_PLL_REG(2), BIT(9));
Stefan Roesedee40d22015-07-22 18:26:13 +0200389
390 /* Assert VCOCAL_START */
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100391 setbits_le32(MV_USB_PHY_PLL_REG(1), BIT(21));
Stefan Roesedee40d22015-07-22 18:26:13 +0200392
393 mdelay(1);
394
395 /*
396 * USB PHY init (change from defaults) specific for 40nm (78X30 78X60)
397 */
398
399 for (dev = 0; dev < 3; dev++) {
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100400 setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 3), BIT(15));
Stefan Roesedee40d22015-07-22 18:26:13 +0200401
402 /* Assert REG_RCAL_START in channel REG 1 */
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100403 setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
Stefan Roesedee40d22015-07-22 18:26:13 +0200404 udelay(40);
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100405 clrbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
Stefan Roesedee40d22015-07-22 18:26:13 +0200406 }
407}
Kevin Smithe1b078e2015-05-18 16:09:44 +0000408
Stefan Roesef4e6ec72015-12-03 12:39:45 +0100409/*
410 * This function is not called from the SPL U-Boot version
411 */
Stefan Roese41e5ee52014-10-22 12:13:17 +0200412int arch_cpu_init(void)
413{
Stefan Roese42cc0342015-08-25 14:09:12 +0200414 struct pl310_regs *const pl310 =
415 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
416
Stefan Roesecefd7642015-08-24 11:03:50 +0200417 /*
418 * Only with disabled MMU its possible to switch the base
419 * register address on Armada 38x. Without this the SDRAM
420 * located at >= 0x4000.0000 is also not accessible, as its
421 * still locked to cache.
422 */
423 mmu_disable();
Stefan Roese9f62b442015-04-24 10:49:11 +0200424
Stefan Roese41e5ee52014-10-22 12:13:17 +0200425 /* Linux expects the internal registers to be at 0xf1000000 */
426 writel(SOC_REGS_PHY_BASE, INTREG_BASE_ADDR_REG);
Kevin Smithe1b078e2015-05-18 16:09:44 +0000427 set_cbar(SOC_REGS_PHY_BASE + 0xC000);
Stefan Roese41e5ee52014-10-22 12:13:17 +0200428
Stefan Roesecefd7642015-08-24 11:03:50 +0200429 /*
430 * From this stage on, the SoC detection is working. As we have
431 * configured the internal register base to the value used
432 * in the macros / defines in the U-Boot header (soc.h).
433 */
Stefan Roesecefd7642015-08-24 11:03:50 +0200434
Stefan Roesec86d53f2015-12-03 12:39:45 +0100435 if (mvebu_soc_family() == MVEBU_SOC_A38X) {
436 /*
437 * To fully release / unlock this area from cache, we need
438 * to flush all caches and disable the L2 cache.
439 */
440 icache_disable();
441 dcache_disable();
442 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
443 }
Stefan Roesecefd7642015-08-24 11:03:50 +0200444
Stefan Roese41e5ee52014-10-22 12:13:17 +0200445 /*
446 * We need to call mvebu_mbus_probe() before calling
447 * update_sdram_window_sizes() as it disables all previously
448 * configured mbus windows and then configures them as
449 * required for U-Boot. Calling update_sdram_window_sizes()
450 * without this configuration will not work, as the internal
451 * registers can't be accessed reliably because of potenial
452 * double mapping.
453 * After updating the SDRAM access windows we need to call
454 * mvebu_mbus_probe() again, as this now correctly configures
455 * the SDRAM areas that are later used by the MVEBU drivers
456 * (e.g. USB, NETA).
457 */
458
459 /*
460 * First disable all windows
461 */
462 mvebu_mbus_probe(NULL, 0);
463
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200464 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
465 /*
466 * Now the SDRAM access windows can be reconfigured using
467 * the information in the SDRAM scratch pad registers
468 */
469 update_sdram_window_sizes();
470 }
Stefan Roese41e5ee52014-10-22 12:13:17 +0200471
472 /*
473 * Finally the mbus windows can be configured with the
474 * updated SDRAM sizes
475 */
476 mvebu_mbus_probe(windows, ARRAY_SIZE(windows));
477
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200478 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
479 /* Enable GBE0, GBE1, LCD and NFC PUP */
480 clrsetbits_le32(ARMADA_XP_PUP_ENABLE, 0,
481 GE0_PUP_EN | GE1_PUP_EN | LCD_PUP_EN |
482 NAND_PUP_EN | SPI_PUP_EN);
Stefan Roesedee40d22015-07-22 18:26:13 +0200483
484 /* Configure USB PLL and PHYs on AXP */
485 setup_usb_phys();
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200486 }
487
488 /* Enable NAND and NAND arbiter */
489 clrsetbits_le32(MVEBU_SOC_DEV_MUX_REG, 0, NAND_EN | NAND_ARBITER_EN);
490
Stefan Roese501c0982015-07-01 13:28:39 +0200491 /* Disable MBUS error propagation */
492 clrsetbits_le32(SOC_COHERENCY_FABRIC_CTRL_REG, MBUS_ERR_PROP_EN, 0);
493
Stefan Roese41e5ee52014-10-22 12:13:17 +0200494 return 0;
495}
496#endif /* CONFIG_ARCH_CPU_INIT */
497
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200498u32 mvebu_get_nand_clock(void)
499{
Chris Packhamd7b47312016-08-22 12:38:39 +1200500 u32 reg;
501
502 if (mvebu_soc_family() == MVEBU_SOC_A38X)
503 reg = MVEBU_DFX_DIV_CLK_CTRL(1);
Chris Packham689f9cf2019-04-11 22:22:51 +1200504 else if (mvebu_soc_family() == MVEBU_SOC_MSYS)
505 reg = MVEBU_DFX_DIV_CLK_CTRL(8);
Chris Packhamd7b47312016-08-22 12:38:39 +1200506 else
507 reg = MVEBU_CORE_DIV_CLK_CTRL(1);
508
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200509 return CONFIG_SYS_MVEBU_PLL_CLOCK /
Chris Packhamd7b47312016-08-22 12:38:39 +1200510 ((readl(reg) &
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200511 NAND_ECC_DIVCKL_RATIO_MASK) >> NAND_ECC_DIVCKL_RATIO_OFFS);
512}
513
Stefan Roese41e5ee52014-10-22 12:13:17 +0200514/*
515 * SOC specific misc init
516 */
517#if defined(CONFIG_ARCH_MISC_INIT)
518int arch_misc_init(void)
519{
520 /* Nothing yet, perhaps we need something here later */
521 return 0;
522}
523#endif /* CONFIG_ARCH_MISC_INIT */
524
Pierre Bourdon4ec9dd42019-04-11 04:56:58 +0200525#if defined(CONFIG_MMC_SDHCI_MV) && !defined(CONFIG_DM_MMC)
Stefan Roese7f1adcd2015-06-29 14:58:10 +0200526int board_mmc_init(bd_t *bis)
527{
528 mv_sdh_init(MVEBU_SDIO_BASE, 0, 0,
529 SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_WAIT_SEND_CMD);
530
531 return 0;
532}
533#endif
534
Stefan Roese4d991cb2015-06-29 14:58:13 +0200535#define AHCI_VENDOR_SPECIFIC_0_ADDR 0xa0
536#define AHCI_VENDOR_SPECIFIC_0_DATA 0xa4
537
538#define AHCI_WINDOW_CTRL(win) (0x60 + ((win) << 4))
539#define AHCI_WINDOW_BASE(win) (0x64 + ((win) << 4))
540#define AHCI_WINDOW_SIZE(win) (0x68 + ((win) << 4))
541
542static void ahci_mvebu_mbus_config(void __iomem *base)
543{
544 const struct mbus_dram_target_info *dram;
545 int i;
546
Baruch Siachf0aa1252019-05-16 13:03:57 +0300547 /* mbus is not initialized in SPL; keep the ROM settings */
548 if (IS_ENABLED(CONFIG_SPL_BUILD))
549 return;
550
Stefan Roese4d991cb2015-06-29 14:58:13 +0200551 dram = mvebu_mbus_dram_info();
552
553 for (i = 0; i < 4; i++) {
554 writel(0, base + AHCI_WINDOW_CTRL(i));
555 writel(0, base + AHCI_WINDOW_BASE(i));
556 writel(0, base + AHCI_WINDOW_SIZE(i));
557 }
558
559 for (i = 0; i < dram->num_cs; i++) {
560 const struct mbus_dram_window *cs = dram->cs + i;
561
562 writel((cs->mbus_attr << 8) |
563 (dram->mbus_dram_target_id << 4) | 1,
564 base + AHCI_WINDOW_CTRL(i));
565 writel(cs->base >> 16, base + AHCI_WINDOW_BASE(i));
566 writel(((cs->size - 1) & 0xffff0000),
567 base + AHCI_WINDOW_SIZE(i));
568 }
569}
570
571static void ahci_mvebu_regret_option(void __iomem *base)
572{
573 /*
574 * Enable the regret bit to allow the SATA unit to regret a
575 * request that didn't receive an acknowlegde and avoid a
576 * deadlock
577 */
578 writel(0x4, base + AHCI_VENDOR_SPECIFIC_0_ADDR);
579 writel(0x80, base + AHCI_VENDOR_SPECIFIC_0_DATA);
580}
581
Baruch Siach4b11e5f2019-03-24 13:27:43 +0200582int board_ahci_enable(void)
583{
584 ahci_mvebu_mbus_config((void __iomem *)MVEBU_SATA0_BASE);
585 ahci_mvebu_regret_option((void __iomem *)MVEBU_SATA0_BASE);
586
587 return 0;
588}
589
590#ifdef CONFIG_SCSI_AHCI_PLAT
Stefan Roese4d991cb2015-06-29 14:58:13 +0200591void scsi_init(void)
592{
593 printf("MVEBU SATA INIT\n");
Baruch Siach4b11e5f2019-03-24 13:27:43 +0200594 board_ahci_enable();
Stefan Roese4d991cb2015-06-29 14:58:13 +0200595 ahci_init((void __iomem *)MVEBU_SATA0_BASE);
596}
597#endif
598
Jon Nettleton78aa0182017-11-06 10:33:20 +0200599#ifdef CONFIG_USB_XHCI_MVEBU
600#define USB3_MAX_WINDOWS 4
601#define USB3_WIN_CTRL(w) (0x0 + ((w) * 8))
602#define USB3_WIN_BASE(w) (0x4 + ((w) * 8))
603
604static void xhci_mvebu_mbus_config(void __iomem *base,
605 const struct mbus_dram_target_info *dram)
606{
607 int i;
608
609 for (i = 0; i < USB3_MAX_WINDOWS; i++) {
610 writel(0, base + USB3_WIN_CTRL(i));
611 writel(0, base + USB3_WIN_BASE(i));
612 }
613
614 for (i = 0; i < dram->num_cs; i++) {
615 const struct mbus_dram_window *cs = dram->cs + i;
616
617 /* Write size, attributes and target id to control register */
618 writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
619 (dram->mbus_dram_target_id << 4) | 1,
620 base + USB3_WIN_CTRL(i));
621
622 /* Write base address to base register */
623 writel((cs->base & 0xffff0000), base + USB3_WIN_BASE(i));
624 }
625}
626
627int board_xhci_enable(fdt_addr_t base)
628{
629 const struct mbus_dram_target_info *dram;
630
631 printf("MVEBU XHCI INIT controller @ 0x%lx\n", base);
632
633 dram = mvebu_mbus_dram_info();
634 xhci_mvebu_mbus_config((void __iomem *)base, dram);
635
636 return 0;
637}
638#endif
639
Stefan Roese41e5ee52014-10-22 12:13:17 +0200640void enable_caches(void)
641{
Stefan Roese60b75322015-04-25 06:29:55 +0200642 /* Avoid problem with e.g. neta ethernet driver */
643 invalidate_dcache_all();
644
Stefan Roeseebe78902016-02-10 09:18:46 +0100645 /*
646 * Armada 375 still has some problems with d-cache enabled in the
647 * ethernet driver (mvpp2). So lets keep the d-cache disabled
648 * until this is solved.
649 */
650 if (mvebu_soc_family() != MVEBU_SOC_A375) {
651 /* Enable D-cache. I-cache is already enabled in start.S */
652 dcache_enable();
653 }
Stefan Roese41e5ee52014-10-22 12:13:17 +0200654}
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100655
656void v7_outer_cache_enable(void)
657{
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100658 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
Stefan Roesec86d53f2015-12-03 12:39:45 +0100659 struct pl310_regs *const pl310 =
660 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100661 u32 u;
662
Stefan Roesec86d53f2015-12-03 12:39:45 +0100663 /* The L2 cache is already disabled at this point */
664
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100665 /*
666 * For Aurora cache in no outer mode, enable via the CP15
667 * coprocessor broadcasting of cache commands to L2.
668 */
669 asm volatile("mrc p15, 1, %0, c15, c2, 0" : "=r" (u));
670 u |= BIT(8); /* Set the FW bit */
671 asm volatile("mcr p15, 1, %0, c15, c2, 0" : : "r" (u));
672
673 isb();
674
675 /* Enable the L2 cache */
676 setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
677 }
678}
Stefan Roesef0e81732015-12-14 12:31:48 +0100679
680void v7_outer_cache_disable(void)
681{
682 struct pl310_regs *const pl310 =
683 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
684
685 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
686}