blob: 919d05c88c7724113c512e53ae5f97a427dba1c0 [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>
8#include <linux/mbus.h>
Stefan Roese41e5ee52014-10-22 12:13:17 +02009#include <asm/io.h>
Stefan Roese57303602015-05-18 16:09:43 +000010#include <asm/pl310.h>
Stefan Roese41e5ee52014-10-22 12:13:17 +020011#include <asm/arch/cpu.h>
12#include <asm/arch/soc.h>
Stefan Roese7f1adcd2015-06-29 14:58:10 +020013#include <sdhci.h>
Stefan Roese41e5ee52014-10-22 12:13:17 +020014
15#define DDR_BASE_CS_OFF(n) (0x0000 + ((n) << 3))
16#define DDR_SIZE_CS_OFF(n) (0x0004 + ((n) << 3))
17
18static struct mbus_win windows[] = {
Stefan Roese41e5ee52014-10-22 12:13:17 +020019 /* SPI */
Stefan Roese8ed20d62015-07-01 12:55:07 +020020 { MBUS_SPI_BASE, MBUS_SPI_SIZE,
21 CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_SPIFLASH },
Stefan Roese41e5ee52014-10-22 12:13:17 +020022
23 /* NOR */
Stefan Roese8ed20d62015-07-01 12:55:07 +020024 { MBUS_BOOTROM_BASE, MBUS_BOOTROM_SIZE,
25 CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_BOOTROM },
Stefan Roese41e5ee52014-10-22 12:13:17 +020026};
27
Stefan Roese42cc0342015-08-25 14:09:12 +020028void lowlevel_init(void)
29{
30 /*
31 * Dummy implementation, we only need LOWLEVEL_INIT
32 * on Armada to configure CP15 in start.S / cpu_init_cp15()
33 */
34}
35
Stefan Roese41e5ee52014-10-22 12:13:17 +020036void reset_cpu(unsigned long ignored)
37{
38 struct mvebu_system_registers *reg =
39 (struct mvebu_system_registers *)MVEBU_SYSTEM_REG_BASE;
40
41 writel(readl(&reg->rstoutn_mask) | 1, &reg->rstoutn_mask);
42 writel(readl(&reg->sys_soft_rst) | 1, &reg->sys_soft_rst);
43 while (1)
44 ;
45}
46
Stefan Roese9c6d3b72015-04-25 06:29:51 +020047int mvebu_soc_family(void)
48{
49 u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
50
Phil Sutter62029532015-12-25 14:41:24 +010051 switch (devid) {
52 case SOC_MV78230_ID:
53 case SOC_MV78260_ID:
54 case SOC_MV78460_ID:
Stefan Roese9c6d3b72015-04-25 06:29:51 +020055 return MVEBU_SOC_AXP;
Stefan Roese09e89ab2016-02-10 07:23:00 +010056
57 case SOC_88F6720_ID:
58 return MVEBU_SOC_A375;
59
Phil Sutter62029532015-12-25 14:41:24 +010060 case SOC_88F6810_ID:
61 case SOC_88F6820_ID:
62 case SOC_88F6828_ID:
Stefan Roese9c6d3b72015-04-25 06:29:51 +020063 return MVEBU_SOC_A38X;
Chris Packham0f8031a2017-09-04 17:38:31 +120064
65 case SOC_98DX3236_ID:
66 case SOC_98DX3336_ID:
67 case SOC_98DX4251_ID:
68 return MVEBU_SOC_MSYS;
Phil Sutter62029532015-12-25 14:41:24 +010069 }
Stefan Roese09e89ab2016-02-10 07:23:00 +010070
Stefan Roese9c6d3b72015-04-25 06:29:51 +020071 return MVEBU_SOC_UNKNOWN;
72}
73
Stefan Roese41e5ee52014-10-22 12:13:17 +020074#if defined(CONFIG_DISPLAY_CPUINFO)
Stefan Roesed718bf22015-12-21 12:36:40 +010075
Stefan Roese09e89ab2016-02-10 07:23:00 +010076#if defined(CONFIG_ARMADA_375)
77/* SAR frequency values for Armada 375 */
78static const struct sar_freq_modes sar_freq_tab[] = {
79 { 0, 0x0, 266, 133, 266 },
80 { 1, 0x0, 333, 167, 167 },
81 { 2, 0x0, 333, 167, 222 },
82 { 3, 0x0, 333, 167, 333 },
83 { 4, 0x0, 400, 200, 200 },
84 { 5, 0x0, 400, 200, 267 },
85 { 6, 0x0, 400, 200, 400 },
86 { 7, 0x0, 500, 250, 250 },
87 { 8, 0x0, 500, 250, 334 },
88 { 9, 0x0, 500, 250, 500 },
89 { 10, 0x0, 533, 267, 267 },
90 { 11, 0x0, 533, 267, 356 },
91 { 12, 0x0, 533, 267, 533 },
92 { 13, 0x0, 600, 300, 300 },
93 { 14, 0x0, 600, 300, 400 },
94 { 15, 0x0, 600, 300, 600 },
95 { 16, 0x0, 666, 333, 333 },
96 { 17, 0x0, 666, 333, 444 },
97 { 18, 0x0, 666, 333, 666 },
98 { 19, 0x0, 800, 400, 267 },
99 { 20, 0x0, 800, 400, 400 },
100 { 21, 0x0, 800, 400, 534 },
101 { 22, 0x0, 900, 450, 300 },
102 { 23, 0x0, 900, 450, 450 },
103 { 24, 0x0, 900, 450, 600 },
104 { 25, 0x0, 1000, 500, 500 },
105 { 26, 0x0, 1000, 500, 667 },
106 { 27, 0x0, 1000, 333, 500 },
107 { 28, 0x0, 400, 400, 400 },
108 { 29, 0x0, 1100, 550, 550 },
109 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
110};
111#elif defined(CONFIG_ARMADA_38X)
Stefan Roesed35831f2016-01-07 14:03:11 +0100112/* SAR frequency values for Armada 38x */
Stefan Roesea9fc5a22016-01-07 14:04:51 +0100113static const struct sar_freq_modes sar_freq_tab[] = {
Chris Packham0a91e1c2017-09-05 17:03:26 +1200114 { 0x0, 0x0, 666, 333, 333 },
115 { 0x2, 0x0, 800, 400, 400 },
116 { 0x4, 0x0, 1066, 533, 533 },
117 { 0x6, 0x0, 1200, 600, 600 },
118 { 0x8, 0x0, 1332, 666, 666 },
119 { 0xc, 0x0, 1600, 800, 800 },
120 { 0x10, 0x0, 1866, 933, 933 },
121 { 0x13, 0x0, 2000, 1000, 933 },
122 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
Stefan Roesed718bf22015-12-21 12:36:40 +0100123};
124#else
Stefan Roesed35831f2016-01-07 14:03:11 +0100125/* SAR frequency values for Armada XP */
Stefan Roesea9fc5a22016-01-07 14:04:51 +0100126static const struct sar_freq_modes sar_freq_tab[] = {
Stefan Roesed718bf22015-12-21 12:36:40 +0100127 { 0xa, 0x5, 800, 400, 400 },
128 { 0x1, 0x5, 1066, 533, 533 },
129 { 0x2, 0x5, 1200, 600, 600 },
130 { 0x2, 0x9, 1200, 600, 400 },
131 { 0x3, 0x5, 1333, 667, 667 },
132 { 0x4, 0x5, 1500, 750, 750 },
133 { 0x4, 0x9, 1500, 750, 500 },
134 { 0xb, 0x9, 1600, 800, 533 },
135 { 0xb, 0xa, 1600, 800, 640 },
136 { 0xb, 0x5, 1600, 800, 800 },
137 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
138};
139#endif
140
141void get_sar_freq(struct sar_freq_modes *sar_freq)
142{
143 u32 val;
144 u32 freq;
145 int i;
146
Stefan Roese09e89ab2016-02-10 07:23:00 +0100147#if defined(CONFIG_ARMADA_375)
148 val = readl(CONFIG_SAR2_REG); /* SAR - Sample At Reset */
149#else
Stefan Roesed718bf22015-12-21 12:36:40 +0100150 val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */
Stefan Roese09e89ab2016-02-10 07:23:00 +0100151#endif
Stefan Roesed718bf22015-12-21 12:36:40 +0100152 freq = (val & SAR_CPU_FREQ_MASK) >> SAR_CPU_FREQ_OFFS;
Stefan Roese09e89ab2016-02-10 07:23:00 +0100153#if defined(SAR2_CPU_FREQ_MASK)
Stefan Roesed718bf22015-12-21 12:36:40 +0100154 /*
155 * Shift CPU0 clock frequency select bit from SAR2 register
156 * into correct position
157 */
158 freq |= ((readl(CONFIG_SAR2_REG) & SAR2_CPU_FREQ_MASK)
159 >> SAR2_CPU_FREQ_OFFS) << 3;
160#endif
161 for (i = 0; sar_freq_tab[i].val != 0xff; i++) {
162 if (sar_freq_tab[i].val == freq) {
Stefan Roese09e89ab2016-02-10 07:23:00 +0100163#if defined(CONFIG_ARMADA_375) || defined(CONFIG_ARMADA_38X)
Stefan Roesed718bf22015-12-21 12:36:40 +0100164 *sar_freq = sar_freq_tab[i];
165 return;
166#else
167 int k;
168 u8 ffc;
169
170 ffc = (val & SAR_FFC_FREQ_MASK) >>
171 SAR_FFC_FREQ_OFFS;
172 for (k = i; sar_freq_tab[k].ffc != 0xff; k++) {
173 if (sar_freq_tab[k].ffc == ffc) {
174 *sar_freq = sar_freq_tab[k];
175 return;
176 }
177 }
178 i = k;
179#endif
180 }
181 }
182
183 /* SAR value not found, return 0 for frequencies */
184 *sar_freq = sar_freq_tab[i - 1];
185}
186
Stefan Roese41e5ee52014-10-22 12:13:17 +0200187int print_cpuinfo(void)
188{
189 u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
190 u8 revid = readl(MVEBU_REG_PCIE_REVID) & 0xff;
Stefan Roesed718bf22015-12-21 12:36:40 +0100191 struct sar_freq_modes sar_freq;
Stefan Roese41e5ee52014-10-22 12:13:17 +0200192
193 puts("SoC: ");
194
195 switch (devid) {
Phil Sutter62029532015-12-25 14:41:24 +0100196 case SOC_MV78230_ID:
197 puts("MV78230-");
198 break;
Stefan Roesebf0db8b2015-12-09 11:00:51 +0100199 case SOC_MV78260_ID:
200 puts("MV78260-");
201 break;
Stefan Roese41e5ee52014-10-22 12:13:17 +0200202 case SOC_MV78460_ID:
203 puts("MV78460-");
204 break;
Stefan Roese09e89ab2016-02-10 07:23:00 +0100205 case SOC_88F6720_ID:
206 puts("MV88F6720-");
207 break;
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200208 case SOC_88F6810_ID:
209 puts("MV88F6810-");
210 break;
211 case SOC_88F6820_ID:
212 puts("MV88F6820-");
213 break;
214 case SOC_88F6828_ID:
215 puts("MV88F6828-");
216 break;
Chris Packham0f8031a2017-09-04 17:38:31 +1200217 case SOC_98DX3236_ID:
218 puts("98DX3236-");
219 break;
220 case SOC_98DX3336_ID:
221 puts("98DX3336-");
222 break;
223 case SOC_98DX4251_ID:
224 puts("98DX4251-");
225 break;
Stefan Roese41e5ee52014-10-22 12:13:17 +0200226 default:
227 puts("Unknown-");
228 break;
229 }
230
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200231 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
232 switch (revid) {
233 case 1:
Stefan Roesed718bf22015-12-21 12:36:40 +0100234 puts("A0");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200235 break;
236 case 2:
Stefan Roesed718bf22015-12-21 12:36:40 +0100237 puts("B0");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200238 break;
239 default:
Stefan Roesed718bf22015-12-21 12:36:40 +0100240 printf("?? (%x)", revid);
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200241 break;
242 }
243 }
244
Stefan Roese09e89ab2016-02-10 07:23:00 +0100245 if (mvebu_soc_family() == MVEBU_SOC_A375) {
246 switch (revid) {
247 case MV_88F67XX_A0_ID:
248 puts("A0");
249 break;
250 default:
251 printf("?? (%x)", revid);
252 break;
253 }
254 }
255
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200256 if (mvebu_soc_family() == MVEBU_SOC_A38X) {
257 switch (revid) {
258 case MV_88F68XX_Z1_ID:
Stefan Roesed718bf22015-12-21 12:36:40 +0100259 puts("Z1");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200260 break;
261 case MV_88F68XX_A0_ID:
Stefan Roesed718bf22015-12-21 12:36:40 +0100262 puts("A0");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200263 break;
Chris Packhamd997ad02018-11-28 10:32:00 +1300264 case MV_88F68XX_B0_ID:
265 puts("B0");
266 break;
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200267 default:
Stefan Roesed718bf22015-12-21 12:36:40 +0100268 printf("?? (%x)", revid);
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200269 break;
270 }
Stefan Roese41e5ee52014-10-22 12:13:17 +0200271 }
272
Stefan Roesed718bf22015-12-21 12:36:40 +0100273 get_sar_freq(&sar_freq);
274 printf(" at %d MHz\n", sar_freq.p_clk);
275
Stefan Roese41e5ee52014-10-22 12:13:17 +0200276 return 0;
277}
278#endif /* CONFIG_DISPLAY_CPUINFO */
279
280/*
281 * This function initialize Controller DRAM Fastpath windows.
282 * It takes the CS size information from the 0x1500 scratch registers
283 * and sets the correct windows sizes and base addresses accordingly.
284 *
285 * These values are set in the scratch registers by the Marvell
Chris Packham1670a152018-12-14 16:27:57 +1300286 * DDR3 training code, which is executed by the SPL before the
287 * main payload (U-Boot) is executed.
Stefan Roese41e5ee52014-10-22 12:13:17 +0200288 */
289static void update_sdram_window_sizes(void)
290{
291 u64 base = 0;
292 u32 size, temp;
293 int i;
294
295 for (i = 0; i < SDRAM_MAX_CS; i++) {
296 size = readl((MVEBU_SDRAM_SCRATCH + (i * 8))) & SDRAM_ADDR_MASK;
297 if (size != 0) {
298 size |= ~(SDRAM_ADDR_MASK);
299
300 /* Set Base Address */
301 temp = (base & 0xFF000000ll) | ((base >> 32) & 0xF);
302 writel(temp, MVEBU_SDRAM_BASE + DDR_BASE_CS_OFF(i));
303
304 /*
305 * Check if out of max window size and resize
306 * the window
307 */
308 temp = (readl(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i)) &
309 ~(SDRAM_ADDR_MASK)) | 1;
310 temp |= (size & SDRAM_ADDR_MASK);
311 writel(temp, MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i));
312
313 base += ((u64)size + 1);
314 } else {
315 /*
316 * Disable window if not used, otherwise this
317 * leads to overlapping enabled windows with
318 * pretty strange results
319 */
320 clrbits_le32(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i), 1);
321 }
322 }
323}
324
Stefan Roese9f62b442015-04-24 10:49:11 +0200325void mmu_disable(void)
326{
327 asm volatile(
328 "mrc p15, 0, r0, c1, c0, 0\n"
329 "bic r0, #1\n"
330 "mcr p15, 0, r0, c1, c0, 0\n");
331}
332
Stefan Roese41e5ee52014-10-22 12:13:17 +0200333#ifdef CONFIG_ARCH_CPU_INIT
Kevin Smithe1b078e2015-05-18 16:09:44 +0000334static void set_cbar(u32 addr)
335{
336 asm("mcr p15, 4, %0, c15, c0" : : "r" (addr));
337}
338
Stefan Roesedee40d22015-07-22 18:26:13 +0200339#define MV_USB_PHY_BASE (MVEBU_AXP_USB_BASE + 0x800)
340#define MV_USB_PHY_PLL_REG(reg) (MV_USB_PHY_BASE | (((reg) & 0xF) << 2))
341#define MV_USB_X3_BASE(addr) (MVEBU_AXP_USB_BASE | BIT(11) | \
342 (((addr) & 0xF) << 6))
343#define MV_USB_X3_PHY_CHANNEL(dev, reg) (MV_USB_X3_BASE((dev) + 1) | \
344 (((reg) & 0xF) << 2))
345
346static void setup_usb_phys(void)
347{
348 int dev;
349
350 /*
351 * USB PLL init
352 */
353
354 /* Setup PLL frequency */
355 /* USB REF frequency = 25 MHz */
356 clrsetbits_le32(MV_USB_PHY_PLL_REG(1), 0x3ff, 0x605);
357
358 /* Power up PLL and PHY channel */
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100359 setbits_le32(MV_USB_PHY_PLL_REG(2), BIT(9));
Stefan Roesedee40d22015-07-22 18:26:13 +0200360
361 /* Assert VCOCAL_START */
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100362 setbits_le32(MV_USB_PHY_PLL_REG(1), BIT(21));
Stefan Roesedee40d22015-07-22 18:26:13 +0200363
364 mdelay(1);
365
366 /*
367 * USB PHY init (change from defaults) specific for 40nm (78X30 78X60)
368 */
369
370 for (dev = 0; dev < 3; dev++) {
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100371 setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 3), BIT(15));
Stefan Roesedee40d22015-07-22 18:26:13 +0200372
373 /* Assert REG_RCAL_START in channel REG 1 */
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100374 setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
Stefan Roesedee40d22015-07-22 18:26:13 +0200375 udelay(40);
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100376 clrbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
Stefan Roesedee40d22015-07-22 18:26:13 +0200377 }
378}
Kevin Smithe1b078e2015-05-18 16:09:44 +0000379
Stefan Roesef4e6ec72015-12-03 12:39:45 +0100380/*
381 * This function is not called from the SPL U-Boot version
382 */
Stefan Roese41e5ee52014-10-22 12:13:17 +0200383int arch_cpu_init(void)
384{
Stefan Roese42cc0342015-08-25 14:09:12 +0200385 struct pl310_regs *const pl310 =
386 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
387
Stefan Roesecefd7642015-08-24 11:03:50 +0200388 /*
389 * Only with disabled MMU its possible to switch the base
390 * register address on Armada 38x. Without this the SDRAM
391 * located at >= 0x4000.0000 is also not accessible, as its
392 * still locked to cache.
393 */
394 mmu_disable();
Stefan Roese9f62b442015-04-24 10:49:11 +0200395
Stefan Roese41e5ee52014-10-22 12:13:17 +0200396 /* Linux expects the internal registers to be at 0xf1000000 */
397 writel(SOC_REGS_PHY_BASE, INTREG_BASE_ADDR_REG);
Kevin Smithe1b078e2015-05-18 16:09:44 +0000398 set_cbar(SOC_REGS_PHY_BASE + 0xC000);
Stefan Roese41e5ee52014-10-22 12:13:17 +0200399
Stefan Roesecefd7642015-08-24 11:03:50 +0200400 /*
401 * From this stage on, the SoC detection is working. As we have
402 * configured the internal register base to the value used
403 * in the macros / defines in the U-Boot header (soc.h).
404 */
Stefan Roesecefd7642015-08-24 11:03:50 +0200405
Stefan Roesec86d53f2015-12-03 12:39:45 +0100406 if (mvebu_soc_family() == MVEBU_SOC_A38X) {
407 /*
408 * To fully release / unlock this area from cache, we need
409 * to flush all caches and disable the L2 cache.
410 */
411 icache_disable();
412 dcache_disable();
413 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
414 }
Stefan Roesecefd7642015-08-24 11:03:50 +0200415
Stefan Roese41e5ee52014-10-22 12:13:17 +0200416 /*
417 * We need to call mvebu_mbus_probe() before calling
418 * update_sdram_window_sizes() as it disables all previously
419 * configured mbus windows and then configures them as
420 * required for U-Boot. Calling update_sdram_window_sizes()
421 * without this configuration will not work, as the internal
422 * registers can't be accessed reliably because of potenial
423 * double mapping.
424 * After updating the SDRAM access windows we need to call
425 * mvebu_mbus_probe() again, as this now correctly configures
426 * the SDRAM areas that are later used by the MVEBU drivers
427 * (e.g. USB, NETA).
428 */
429
430 /*
431 * First disable all windows
432 */
433 mvebu_mbus_probe(NULL, 0);
434
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200435 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
436 /*
437 * Now the SDRAM access windows can be reconfigured using
438 * the information in the SDRAM scratch pad registers
439 */
440 update_sdram_window_sizes();
441 }
Stefan Roese41e5ee52014-10-22 12:13:17 +0200442
443 /*
444 * Finally the mbus windows can be configured with the
445 * updated SDRAM sizes
446 */
447 mvebu_mbus_probe(windows, ARRAY_SIZE(windows));
448
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200449 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
450 /* Enable GBE0, GBE1, LCD and NFC PUP */
451 clrsetbits_le32(ARMADA_XP_PUP_ENABLE, 0,
452 GE0_PUP_EN | GE1_PUP_EN | LCD_PUP_EN |
453 NAND_PUP_EN | SPI_PUP_EN);
Stefan Roesedee40d22015-07-22 18:26:13 +0200454
455 /* Configure USB PLL and PHYs on AXP */
456 setup_usb_phys();
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200457 }
458
459 /* Enable NAND and NAND arbiter */
460 clrsetbits_le32(MVEBU_SOC_DEV_MUX_REG, 0, NAND_EN | NAND_ARBITER_EN);
461
Stefan Roese501c0982015-07-01 13:28:39 +0200462 /* Disable MBUS error propagation */
463 clrsetbits_le32(SOC_COHERENCY_FABRIC_CTRL_REG, MBUS_ERR_PROP_EN, 0);
464
Stefan Roese41e5ee52014-10-22 12:13:17 +0200465 return 0;
466}
467#endif /* CONFIG_ARCH_CPU_INIT */
468
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200469u32 mvebu_get_nand_clock(void)
470{
Chris Packhamd7b47312016-08-22 12:38:39 +1200471 u32 reg;
472
473 if (mvebu_soc_family() == MVEBU_SOC_A38X)
474 reg = MVEBU_DFX_DIV_CLK_CTRL(1);
475 else
476 reg = MVEBU_CORE_DIV_CLK_CTRL(1);
477
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200478 return CONFIG_SYS_MVEBU_PLL_CLOCK /
Chris Packhamd7b47312016-08-22 12:38:39 +1200479 ((readl(reg) &
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200480 NAND_ECC_DIVCKL_RATIO_MASK) >> NAND_ECC_DIVCKL_RATIO_OFFS);
481}
482
Stefan Roese41e5ee52014-10-22 12:13:17 +0200483/*
484 * SOC specific misc init
485 */
486#if defined(CONFIG_ARCH_MISC_INIT)
487int arch_misc_init(void)
488{
489 /* Nothing yet, perhaps we need something here later */
490 return 0;
491}
492#endif /* CONFIG_ARCH_MISC_INIT */
493
Masahiro Yamada45a68fe2016-12-07 22:10:29 +0900494#ifdef CONFIG_MMC_SDHCI_MV
Stefan Roese7f1adcd2015-06-29 14:58:10 +0200495int board_mmc_init(bd_t *bis)
496{
497 mv_sdh_init(MVEBU_SDIO_BASE, 0, 0,
498 SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_WAIT_SEND_CMD);
499
500 return 0;
501}
502#endif
503
Stefan Roese4d991cb2015-06-29 14:58:13 +0200504#ifdef CONFIG_SCSI_AHCI_PLAT
505#define AHCI_VENDOR_SPECIFIC_0_ADDR 0xa0
506#define AHCI_VENDOR_SPECIFIC_0_DATA 0xa4
507
508#define AHCI_WINDOW_CTRL(win) (0x60 + ((win) << 4))
509#define AHCI_WINDOW_BASE(win) (0x64 + ((win) << 4))
510#define AHCI_WINDOW_SIZE(win) (0x68 + ((win) << 4))
511
512static void ahci_mvebu_mbus_config(void __iomem *base)
513{
514 const struct mbus_dram_target_info *dram;
515 int i;
516
517 dram = mvebu_mbus_dram_info();
518
519 for (i = 0; i < 4; i++) {
520 writel(0, base + AHCI_WINDOW_CTRL(i));
521 writel(0, base + AHCI_WINDOW_BASE(i));
522 writel(0, base + AHCI_WINDOW_SIZE(i));
523 }
524
525 for (i = 0; i < dram->num_cs; i++) {
526 const struct mbus_dram_window *cs = dram->cs + i;
527
528 writel((cs->mbus_attr << 8) |
529 (dram->mbus_dram_target_id << 4) | 1,
530 base + AHCI_WINDOW_CTRL(i));
531 writel(cs->base >> 16, base + AHCI_WINDOW_BASE(i));
532 writel(((cs->size - 1) & 0xffff0000),
533 base + AHCI_WINDOW_SIZE(i));
534 }
535}
536
537static void ahci_mvebu_regret_option(void __iomem *base)
538{
539 /*
540 * Enable the regret bit to allow the SATA unit to regret a
541 * request that didn't receive an acknowlegde and avoid a
542 * deadlock
543 */
544 writel(0x4, base + AHCI_VENDOR_SPECIFIC_0_ADDR);
545 writel(0x80, base + AHCI_VENDOR_SPECIFIC_0_DATA);
546}
547
548void scsi_init(void)
549{
550 printf("MVEBU SATA INIT\n");
551 ahci_mvebu_mbus_config((void __iomem *)MVEBU_SATA0_BASE);
552 ahci_mvebu_regret_option((void __iomem *)MVEBU_SATA0_BASE);
553 ahci_init((void __iomem *)MVEBU_SATA0_BASE);
554}
555#endif
556
Jon Nettleton78aa0182017-11-06 10:33:20 +0200557#ifdef CONFIG_USB_XHCI_MVEBU
558#define USB3_MAX_WINDOWS 4
559#define USB3_WIN_CTRL(w) (0x0 + ((w) * 8))
560#define USB3_WIN_BASE(w) (0x4 + ((w) * 8))
561
562static void xhci_mvebu_mbus_config(void __iomem *base,
563 const struct mbus_dram_target_info *dram)
564{
565 int i;
566
567 for (i = 0; i < USB3_MAX_WINDOWS; i++) {
568 writel(0, base + USB3_WIN_CTRL(i));
569 writel(0, base + USB3_WIN_BASE(i));
570 }
571
572 for (i = 0; i < dram->num_cs; i++) {
573 const struct mbus_dram_window *cs = dram->cs + i;
574
575 /* Write size, attributes and target id to control register */
576 writel(((cs->size - 1) & 0xffff0000) | (cs->mbus_attr << 8) |
577 (dram->mbus_dram_target_id << 4) | 1,
578 base + USB3_WIN_CTRL(i));
579
580 /* Write base address to base register */
581 writel((cs->base & 0xffff0000), base + USB3_WIN_BASE(i));
582 }
583}
584
585int board_xhci_enable(fdt_addr_t base)
586{
587 const struct mbus_dram_target_info *dram;
588
589 printf("MVEBU XHCI INIT controller @ 0x%lx\n", base);
590
591 dram = mvebu_mbus_dram_info();
592 xhci_mvebu_mbus_config((void __iomem *)base, dram);
593
594 return 0;
595}
596#endif
597
Stefan Roese41e5ee52014-10-22 12:13:17 +0200598void enable_caches(void)
599{
Stefan Roese60b75322015-04-25 06:29:55 +0200600 /* Avoid problem with e.g. neta ethernet driver */
601 invalidate_dcache_all();
602
Stefan Roeseebe78902016-02-10 09:18:46 +0100603 /*
604 * Armada 375 still has some problems with d-cache enabled in the
605 * ethernet driver (mvpp2). So lets keep the d-cache disabled
606 * until this is solved.
607 */
608 if (mvebu_soc_family() != MVEBU_SOC_A375) {
609 /* Enable D-cache. I-cache is already enabled in start.S */
610 dcache_enable();
611 }
Stefan Roese41e5ee52014-10-22 12:13:17 +0200612}
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100613
614void v7_outer_cache_enable(void)
615{
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100616 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
Stefan Roesec86d53f2015-12-03 12:39:45 +0100617 struct pl310_regs *const pl310 =
618 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100619 u32 u;
620
Stefan Roesec86d53f2015-12-03 12:39:45 +0100621 /* The L2 cache is already disabled at this point */
622
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100623 /*
624 * For Aurora cache in no outer mode, enable via the CP15
625 * coprocessor broadcasting of cache commands to L2.
626 */
627 asm volatile("mrc p15, 1, %0, c15, c2, 0" : "=r" (u));
628 u |= BIT(8); /* Set the FW bit */
629 asm volatile("mcr p15, 1, %0, c15, c2, 0" : : "r" (u));
630
631 isb();
632
633 /* Enable the L2 cache */
634 setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
635 }
636}
Stefan Roesef0e81732015-12-14 12:31:48 +0100637
638void v7_outer_cache_disable(void)
639{
640 struct pl310_regs *const pl310 =
641 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
642
643 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
644}