blob: c56b0aeb7926f600c69f731161ad32c140c5ac2c [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>
Simon Glassc05ed002020-05-10 11:40:11 -060010#include <linux/delay.h>
Stefan Roese4d991cb2015-06-29 14:58:13 +020011#include <linux/mbus.h>
Stefan Roese41e5ee52014-10-22 12:13:17 +020012#include <asm/io.h>
Stefan Roese57303602015-05-18 16:09:43 +000013#include <asm/pl310.h>
Stefan Roese41e5ee52014-10-22 12:13:17 +020014#include <asm/arch/cpu.h>
15#include <asm/arch/soc.h>
Stefan Roese7f1adcd2015-06-29 14:58:10 +020016#include <sdhci.h>
Stefan Roese41e5ee52014-10-22 12:13:17 +020017
18#define DDR_BASE_CS_OFF(n) (0x0000 + ((n) << 3))
19#define DDR_SIZE_CS_OFF(n) (0x0004 + ((n) << 3))
20
21static struct mbus_win windows[] = {
Stefan Roese41e5ee52014-10-22 12:13:17 +020022 /* SPI */
Stefan Roese8ed20d62015-07-01 12:55:07 +020023 { MBUS_SPI_BASE, MBUS_SPI_SIZE,
24 CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_SPIFLASH },
Stefan Roese41e5ee52014-10-22 12:13:17 +020025
26 /* NOR */
Stefan Roese8ed20d62015-07-01 12:55:07 +020027 { MBUS_BOOTROM_BASE, MBUS_BOOTROM_SIZE,
28 CPU_TARGET_DEVICEBUS_BOOTROM_SPI, CPU_ATTR_BOOTROM },
Chris Packham0d0df462019-04-11 22:22:50 +120029
30#ifdef CONFIG_ARMADA_MSYS
31 /* DFX */
32 { MBUS_DFX_BASE, MBUS_DFX_SIZE, CPU_TARGET_DFX, 0 },
33#endif
Stefan Roese41e5ee52014-10-22 12:13:17 +020034};
35
Stefan Roese42cc0342015-08-25 14:09:12 +020036void lowlevel_init(void)
37{
38 /*
39 * Dummy implementation, we only need LOWLEVEL_INIT
40 * on Armada to configure CP15 in start.S / cpu_init_cp15()
41 */
42}
43
Stefan Roese41e5ee52014-10-22 12:13:17 +020044void reset_cpu(unsigned long ignored)
45{
46 struct mvebu_system_registers *reg =
47 (struct mvebu_system_registers *)MVEBU_SYSTEM_REG_BASE;
48
49 writel(readl(&reg->rstoutn_mask) | 1, &reg->rstoutn_mask);
50 writel(readl(&reg->sys_soft_rst) | 1, &reg->sys_soft_rst);
51 while (1)
52 ;
53}
54
Stefan Roese9c6d3b72015-04-25 06:29:51 +020055int mvebu_soc_family(void)
56{
57 u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
58
Phil Sutter62029532015-12-25 14:41:24 +010059 switch (devid) {
60 case SOC_MV78230_ID:
61 case SOC_MV78260_ID:
62 case SOC_MV78460_ID:
Stefan Roese9c6d3b72015-04-25 06:29:51 +020063 return MVEBU_SOC_AXP;
Stefan Roese09e89ab2016-02-10 07:23:00 +010064
65 case SOC_88F6720_ID:
66 return MVEBU_SOC_A375;
67
Phil Sutter62029532015-12-25 14:41:24 +010068 case SOC_88F6810_ID:
69 case SOC_88F6820_ID:
70 case SOC_88F6828_ID:
Stefan Roese9c6d3b72015-04-25 06:29:51 +020071 return MVEBU_SOC_A38X;
Chris Packham0f8031a2017-09-04 17:38:31 +120072
73 case SOC_98DX3236_ID:
74 case SOC_98DX3336_ID:
75 case SOC_98DX4251_ID:
76 return MVEBU_SOC_MSYS;
Phil Sutter62029532015-12-25 14:41:24 +010077 }
Stefan Roese09e89ab2016-02-10 07:23:00 +010078
Stefan Roese9c6d3b72015-04-25 06:29:51 +020079 return MVEBU_SOC_UNKNOWN;
80}
81
Stefan Roese41e5ee52014-10-22 12:13:17 +020082#if defined(CONFIG_DISPLAY_CPUINFO)
Stefan Roesed718bf22015-12-21 12:36:40 +010083
Stefan Roese09e89ab2016-02-10 07:23:00 +010084#if defined(CONFIG_ARMADA_375)
85/* SAR frequency values for Armada 375 */
86static const struct sar_freq_modes sar_freq_tab[] = {
87 { 0, 0x0, 266, 133, 266 },
88 { 1, 0x0, 333, 167, 167 },
89 { 2, 0x0, 333, 167, 222 },
90 { 3, 0x0, 333, 167, 333 },
91 { 4, 0x0, 400, 200, 200 },
92 { 5, 0x0, 400, 200, 267 },
93 { 6, 0x0, 400, 200, 400 },
94 { 7, 0x0, 500, 250, 250 },
95 { 8, 0x0, 500, 250, 334 },
96 { 9, 0x0, 500, 250, 500 },
97 { 10, 0x0, 533, 267, 267 },
98 { 11, 0x0, 533, 267, 356 },
99 { 12, 0x0, 533, 267, 533 },
100 { 13, 0x0, 600, 300, 300 },
101 { 14, 0x0, 600, 300, 400 },
102 { 15, 0x0, 600, 300, 600 },
103 { 16, 0x0, 666, 333, 333 },
104 { 17, 0x0, 666, 333, 444 },
105 { 18, 0x0, 666, 333, 666 },
106 { 19, 0x0, 800, 400, 267 },
107 { 20, 0x0, 800, 400, 400 },
108 { 21, 0x0, 800, 400, 534 },
109 { 22, 0x0, 900, 450, 300 },
110 { 23, 0x0, 900, 450, 450 },
111 { 24, 0x0, 900, 450, 600 },
112 { 25, 0x0, 1000, 500, 500 },
113 { 26, 0x0, 1000, 500, 667 },
114 { 27, 0x0, 1000, 333, 500 },
115 { 28, 0x0, 400, 400, 400 },
116 { 29, 0x0, 1100, 550, 550 },
117 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
118};
119#elif defined(CONFIG_ARMADA_38X)
Stefan Roesed35831f2016-01-07 14:03:11 +0100120/* SAR frequency values for Armada 38x */
Stefan Roesea9fc5a22016-01-07 14:04:51 +0100121static const struct sar_freq_modes sar_freq_tab[] = {
Chris Packham0a91e1c2017-09-05 17:03:26 +1200122 { 0x0, 0x0, 666, 333, 333 },
123 { 0x2, 0x0, 800, 400, 400 },
124 { 0x4, 0x0, 1066, 533, 533 },
125 { 0x6, 0x0, 1200, 600, 600 },
126 { 0x8, 0x0, 1332, 666, 666 },
127 { 0xc, 0x0, 1600, 800, 800 },
128 { 0x10, 0x0, 1866, 933, 933 },
129 { 0x13, 0x0, 2000, 1000, 933 },
130 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
Stefan Roesed718bf22015-12-21 12:36:40 +0100131};
Chris Packham0d0df462019-04-11 22:22:50 +1200132#elif defined(CONFIG_ARMADA_MSYS)
133static const struct sar_freq_modes sar_freq_tab[] = {
134 { 0x0, 0x0, 400, 400, 400 },
135 { 0x2, 0x0, 667, 333, 667 },
136 { 0x3, 0x0, 800, 400, 800 },
137 { 0x5, 0x0, 800, 400, 800 },
138 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
139};
Stefan Roesed718bf22015-12-21 12:36:40 +0100140#else
Stefan Roesed35831f2016-01-07 14:03:11 +0100141/* SAR frequency values for Armada XP */
Stefan Roesea9fc5a22016-01-07 14:04:51 +0100142static const struct sar_freq_modes sar_freq_tab[] = {
Stefan Roesed718bf22015-12-21 12:36:40 +0100143 { 0xa, 0x5, 800, 400, 400 },
144 { 0x1, 0x5, 1066, 533, 533 },
145 { 0x2, 0x5, 1200, 600, 600 },
146 { 0x2, 0x9, 1200, 600, 400 },
147 { 0x3, 0x5, 1333, 667, 667 },
148 { 0x4, 0x5, 1500, 750, 750 },
149 { 0x4, 0x9, 1500, 750, 500 },
150 { 0xb, 0x9, 1600, 800, 533 },
151 { 0xb, 0xa, 1600, 800, 640 },
152 { 0xb, 0x5, 1600, 800, 800 },
153 { 0xff, 0xff, 0, 0, 0 } /* 0xff marks end of array */
154};
155#endif
156
157void get_sar_freq(struct sar_freq_modes *sar_freq)
158{
159 u32 val;
160 u32 freq;
161 int i;
162
Chris Packham0d0df462019-04-11 22:22:50 +1200163#if defined(CONFIG_ARMADA_375) || defined(CONFIG_ARMADA_MSYS)
Stefan Roese09e89ab2016-02-10 07:23:00 +0100164 val = readl(CONFIG_SAR2_REG); /* SAR - Sample At Reset */
165#else
Stefan Roesed718bf22015-12-21 12:36:40 +0100166 val = readl(CONFIG_SAR_REG); /* SAR - Sample At Reset */
Stefan Roese09e89ab2016-02-10 07:23:00 +0100167#endif
Stefan Roesed718bf22015-12-21 12:36:40 +0100168 freq = (val & SAR_CPU_FREQ_MASK) >> SAR_CPU_FREQ_OFFS;
Stefan Roese09e89ab2016-02-10 07:23:00 +0100169#if defined(SAR2_CPU_FREQ_MASK)
Stefan Roesed718bf22015-12-21 12:36:40 +0100170 /*
171 * Shift CPU0 clock frequency select bit from SAR2 register
172 * into correct position
173 */
174 freq |= ((readl(CONFIG_SAR2_REG) & SAR2_CPU_FREQ_MASK)
175 >> SAR2_CPU_FREQ_OFFS) << 3;
176#endif
177 for (i = 0; sar_freq_tab[i].val != 0xff; i++) {
178 if (sar_freq_tab[i].val == freq) {
Chris Packham0d0df462019-04-11 22:22:50 +1200179#if defined(CONFIG_ARMADA_375) || defined(CONFIG_ARMADA_38X) || defined(CONFIG_ARMADA_MSYS)
Stefan Roesed718bf22015-12-21 12:36:40 +0100180 *sar_freq = sar_freq_tab[i];
181 return;
182#else
183 int k;
184 u8 ffc;
185
186 ffc = (val & SAR_FFC_FREQ_MASK) >>
187 SAR_FFC_FREQ_OFFS;
188 for (k = i; sar_freq_tab[k].ffc != 0xff; k++) {
189 if (sar_freq_tab[k].ffc == ffc) {
190 *sar_freq = sar_freq_tab[k];
191 return;
192 }
193 }
194 i = k;
195#endif
196 }
197 }
198
199 /* SAR value not found, return 0 for frequencies */
200 *sar_freq = sar_freq_tab[i - 1];
201}
202
Stefan Roese41e5ee52014-10-22 12:13:17 +0200203int print_cpuinfo(void)
204{
205 u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
206 u8 revid = readl(MVEBU_REG_PCIE_REVID) & 0xff;
Stefan Roesed718bf22015-12-21 12:36:40 +0100207 struct sar_freq_modes sar_freq;
Stefan Roese41e5ee52014-10-22 12:13:17 +0200208
209 puts("SoC: ");
210
211 switch (devid) {
Phil Sutter62029532015-12-25 14:41:24 +0100212 case SOC_MV78230_ID:
213 puts("MV78230-");
214 break;
Stefan Roesebf0db8b2015-12-09 11:00:51 +0100215 case SOC_MV78260_ID:
216 puts("MV78260-");
217 break;
Stefan Roese41e5ee52014-10-22 12:13:17 +0200218 case SOC_MV78460_ID:
219 puts("MV78460-");
220 break;
Stefan Roese09e89ab2016-02-10 07:23:00 +0100221 case SOC_88F6720_ID:
222 puts("MV88F6720-");
223 break;
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200224 case SOC_88F6810_ID:
225 puts("MV88F6810-");
226 break;
227 case SOC_88F6820_ID:
228 puts("MV88F6820-");
229 break;
230 case SOC_88F6828_ID:
231 puts("MV88F6828-");
232 break;
Chris Packham0f8031a2017-09-04 17:38:31 +1200233 case SOC_98DX3236_ID:
234 puts("98DX3236-");
235 break;
236 case SOC_98DX3336_ID:
237 puts("98DX3336-");
238 break;
239 case SOC_98DX4251_ID:
240 puts("98DX4251-");
241 break;
Stefan Roese41e5ee52014-10-22 12:13:17 +0200242 default:
243 puts("Unknown-");
244 break;
245 }
246
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200247 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
248 switch (revid) {
249 case 1:
Stefan Roesed718bf22015-12-21 12:36:40 +0100250 puts("A0");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200251 break;
252 case 2:
Stefan Roesed718bf22015-12-21 12:36:40 +0100253 puts("B0");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200254 break;
255 default:
Stefan Roesed718bf22015-12-21 12:36:40 +0100256 printf("?? (%x)", revid);
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200257 break;
258 }
259 }
260
Stefan Roese09e89ab2016-02-10 07:23:00 +0100261 if (mvebu_soc_family() == MVEBU_SOC_A375) {
262 switch (revid) {
263 case MV_88F67XX_A0_ID:
264 puts("A0");
265 break;
266 default:
267 printf("?? (%x)", revid);
268 break;
269 }
270 }
271
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200272 if (mvebu_soc_family() == MVEBU_SOC_A38X) {
273 switch (revid) {
274 case MV_88F68XX_Z1_ID:
Stefan Roesed718bf22015-12-21 12:36:40 +0100275 puts("Z1");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200276 break;
277 case MV_88F68XX_A0_ID:
Stefan Roesed718bf22015-12-21 12:36:40 +0100278 puts("A0");
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200279 break;
Chris Packhamd997ad02018-11-28 10:32:00 +1300280 case MV_88F68XX_B0_ID:
281 puts("B0");
282 break;
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200283 default:
Stefan Roesed718bf22015-12-21 12:36:40 +0100284 printf("?? (%x)", revid);
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200285 break;
286 }
Stefan Roese41e5ee52014-10-22 12:13:17 +0200287 }
288
Chris Packham0d0df462019-04-11 22:22:50 +1200289 if (mvebu_soc_family() == MVEBU_SOC_MSYS) {
290 switch (revid) {
291 case 3:
292 puts("A0");
293 break;
294 case 4:
295 puts("A1");
296 break;
297 default:
298 printf("?? (%x)", revid);
299 break;
300 }
301 }
302
Stefan Roesed718bf22015-12-21 12:36:40 +0100303 get_sar_freq(&sar_freq);
304 printf(" at %d MHz\n", sar_freq.p_clk);
305
Stefan Roese41e5ee52014-10-22 12:13:17 +0200306 return 0;
307}
308#endif /* CONFIG_DISPLAY_CPUINFO */
309
310/*
311 * This function initialize Controller DRAM Fastpath windows.
312 * It takes the CS size information from the 0x1500 scratch registers
313 * and sets the correct windows sizes and base addresses accordingly.
314 *
315 * These values are set in the scratch registers by the Marvell
Chris Packham1670a152018-12-14 16:27:57 +1300316 * DDR3 training code, which is executed by the SPL before the
317 * main payload (U-Boot) is executed.
Stefan Roese41e5ee52014-10-22 12:13:17 +0200318 */
319static void update_sdram_window_sizes(void)
320{
321 u64 base = 0;
322 u32 size, temp;
323 int i;
324
325 for (i = 0; i < SDRAM_MAX_CS; i++) {
326 size = readl((MVEBU_SDRAM_SCRATCH + (i * 8))) & SDRAM_ADDR_MASK;
327 if (size != 0) {
328 size |= ~(SDRAM_ADDR_MASK);
329
330 /* Set Base Address */
331 temp = (base & 0xFF000000ll) | ((base >> 32) & 0xF);
332 writel(temp, MVEBU_SDRAM_BASE + DDR_BASE_CS_OFF(i));
333
334 /*
335 * Check if out of max window size and resize
336 * the window
337 */
338 temp = (readl(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i)) &
339 ~(SDRAM_ADDR_MASK)) | 1;
340 temp |= (size & SDRAM_ADDR_MASK);
341 writel(temp, MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i));
342
343 base += ((u64)size + 1);
344 } else {
345 /*
346 * Disable window if not used, otherwise this
347 * leads to overlapping enabled windows with
348 * pretty strange results
349 */
350 clrbits_le32(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i), 1);
351 }
352 }
353}
354
Stefan Roese9f62b442015-04-24 10:49:11 +0200355void mmu_disable(void)
356{
357 asm volatile(
358 "mrc p15, 0, r0, c1, c0, 0\n"
359 "bic r0, #1\n"
360 "mcr p15, 0, r0, c1, c0, 0\n");
361}
362
Stefan Roese41e5ee52014-10-22 12:13:17 +0200363#ifdef CONFIG_ARCH_CPU_INIT
Kevin Smithe1b078e2015-05-18 16:09:44 +0000364static void set_cbar(u32 addr)
365{
366 asm("mcr p15, 4, %0, c15, c0" : : "r" (addr));
367}
368
Stefan Roesedee40d22015-07-22 18:26:13 +0200369#define MV_USB_PHY_BASE (MVEBU_AXP_USB_BASE + 0x800)
370#define MV_USB_PHY_PLL_REG(reg) (MV_USB_PHY_BASE | (((reg) & 0xF) << 2))
371#define MV_USB_X3_BASE(addr) (MVEBU_AXP_USB_BASE | BIT(11) | \
372 (((addr) & 0xF) << 6))
373#define MV_USB_X3_PHY_CHANNEL(dev, reg) (MV_USB_X3_BASE((dev) + 1) | \
374 (((reg) & 0xF) << 2))
375
376static void setup_usb_phys(void)
377{
378 int dev;
379
380 /*
381 * USB PLL init
382 */
383
384 /* Setup PLL frequency */
385 /* USB REF frequency = 25 MHz */
386 clrsetbits_le32(MV_USB_PHY_PLL_REG(1), 0x3ff, 0x605);
387
388 /* Power up PLL and PHY channel */
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100389 setbits_le32(MV_USB_PHY_PLL_REG(2), BIT(9));
Stefan Roesedee40d22015-07-22 18:26:13 +0200390
391 /* Assert VCOCAL_START */
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100392 setbits_le32(MV_USB_PHY_PLL_REG(1), BIT(21));
Stefan Roesedee40d22015-07-22 18:26:13 +0200393
394 mdelay(1);
395
396 /*
397 * USB PHY init (change from defaults) specific for 40nm (78X30 78X60)
398 */
399
400 for (dev = 0; dev < 3; dev++) {
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100401 setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 3), BIT(15));
Stefan Roesedee40d22015-07-22 18:26:13 +0200402
403 /* Assert REG_RCAL_START in channel REG 1 */
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100404 setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
Stefan Roesedee40d22015-07-22 18:26:13 +0200405 udelay(40);
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100406 clrbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
Stefan Roesedee40d22015-07-22 18:26:13 +0200407 }
408}
Kevin Smithe1b078e2015-05-18 16:09:44 +0000409
Stefan Roesef4e6ec72015-12-03 12:39:45 +0100410/*
411 * This function is not called from the SPL U-Boot version
412 */
Stefan Roese41e5ee52014-10-22 12:13:17 +0200413int arch_cpu_init(void)
414{
Stefan Roese42cc0342015-08-25 14:09:12 +0200415 struct pl310_regs *const pl310 =
416 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
417
Stefan Roesecefd7642015-08-24 11:03:50 +0200418 /*
419 * Only with disabled MMU its possible to switch the base
420 * register address on Armada 38x. Without this the SDRAM
421 * located at >= 0x4000.0000 is also not accessible, as its
422 * still locked to cache.
423 */
424 mmu_disable();
Stefan Roese9f62b442015-04-24 10:49:11 +0200425
Stefan Roese41e5ee52014-10-22 12:13:17 +0200426 /* Linux expects the internal registers to be at 0xf1000000 */
427 writel(SOC_REGS_PHY_BASE, INTREG_BASE_ADDR_REG);
Kevin Smithe1b078e2015-05-18 16:09:44 +0000428 set_cbar(SOC_REGS_PHY_BASE + 0xC000);
Stefan Roese41e5ee52014-10-22 12:13:17 +0200429
Stefan Roesecefd7642015-08-24 11:03:50 +0200430 /*
431 * From this stage on, the SoC detection is working. As we have
432 * configured the internal register base to the value used
433 * in the macros / defines in the U-Boot header (soc.h).
434 */
Stefan Roesecefd7642015-08-24 11:03:50 +0200435
Stefan Roesec86d53f2015-12-03 12:39:45 +0100436 if (mvebu_soc_family() == MVEBU_SOC_A38X) {
437 /*
438 * To fully release / unlock this area from cache, we need
439 * to flush all caches and disable the L2 cache.
440 */
441 icache_disable();
442 dcache_disable();
443 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
444 }
Stefan Roesecefd7642015-08-24 11:03:50 +0200445
Stefan Roese41e5ee52014-10-22 12:13:17 +0200446 /*
447 * We need to call mvebu_mbus_probe() before calling
448 * update_sdram_window_sizes() as it disables all previously
449 * configured mbus windows and then configures them as
450 * required for U-Boot. Calling update_sdram_window_sizes()
451 * without this configuration will not work, as the internal
452 * registers can't be accessed reliably because of potenial
453 * double mapping.
454 * After updating the SDRAM access windows we need to call
455 * mvebu_mbus_probe() again, as this now correctly configures
456 * the SDRAM areas that are later used by the MVEBU drivers
457 * (e.g. USB, NETA).
458 */
459
460 /*
461 * First disable all windows
462 */
463 mvebu_mbus_probe(NULL, 0);
464
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200465 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
466 /*
467 * Now the SDRAM access windows can be reconfigured using
468 * the information in the SDRAM scratch pad registers
469 */
470 update_sdram_window_sizes();
471 }
Stefan Roese41e5ee52014-10-22 12:13:17 +0200472
473 /*
474 * Finally the mbus windows can be configured with the
475 * updated SDRAM sizes
476 */
477 mvebu_mbus_probe(windows, ARRAY_SIZE(windows));
478
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200479 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
480 /* Enable GBE0, GBE1, LCD and NFC PUP */
481 clrsetbits_le32(ARMADA_XP_PUP_ENABLE, 0,
482 GE0_PUP_EN | GE1_PUP_EN | LCD_PUP_EN |
483 NAND_PUP_EN | SPI_PUP_EN);
Stefan Roesedee40d22015-07-22 18:26:13 +0200484
485 /* Configure USB PLL and PHYs on AXP */
486 setup_usb_phys();
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200487 }
488
489 /* Enable NAND and NAND arbiter */
490 clrsetbits_le32(MVEBU_SOC_DEV_MUX_REG, 0, NAND_EN | NAND_ARBITER_EN);
491
Stefan Roese501c0982015-07-01 13:28:39 +0200492 /* Disable MBUS error propagation */
493 clrsetbits_le32(SOC_COHERENCY_FABRIC_CTRL_REG, MBUS_ERR_PROP_EN, 0);
494
Stefan Roese41e5ee52014-10-22 12:13:17 +0200495 return 0;
496}
497#endif /* CONFIG_ARCH_CPU_INIT */
498
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200499u32 mvebu_get_nand_clock(void)
500{
Chris Packhamd7b47312016-08-22 12:38:39 +1200501 u32 reg;
502
503 if (mvebu_soc_family() == MVEBU_SOC_A38X)
504 reg = MVEBU_DFX_DIV_CLK_CTRL(1);
Chris Packham689f9cf2019-04-11 22:22:51 +1200505 else if (mvebu_soc_family() == MVEBU_SOC_MSYS)
506 reg = MVEBU_DFX_DIV_CLK_CTRL(8);
Chris Packhamd7b47312016-08-22 12:38:39 +1200507 else
508 reg = MVEBU_CORE_DIV_CLK_CTRL(1);
509
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200510 return CONFIG_SYS_MVEBU_PLL_CLOCK /
Chris Packhamd7b47312016-08-22 12:38:39 +1200511 ((readl(reg) &
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200512 NAND_ECC_DIVCKL_RATIO_MASK) >> NAND_ECC_DIVCKL_RATIO_OFFS);
513}
514
Stefan Roese41e5ee52014-10-22 12:13:17 +0200515/*
516 * SOC specific misc init
517 */
518#if defined(CONFIG_ARCH_MISC_INIT)
519int arch_misc_init(void)
520{
521 /* Nothing yet, perhaps we need something here later */
522 return 0;
523}
524#endif /* CONFIG_ARCH_MISC_INIT */
525
Pierre Bourdon4ec9dd42019-04-11 04:56:58 +0200526#if defined(CONFIG_MMC_SDHCI_MV) && !defined(CONFIG_DM_MMC)
Stefan Roese7f1adcd2015-06-29 14:58:10 +0200527int board_mmc_init(bd_t *bis)
528{
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 Roese4d991cb2015-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 Siachf0aa1252019-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 Roese4d991cb2015-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 Siach4b11e5f2019-03-24 13:27:43 +0200583int board_ahci_enable(void)
584{
585 ahci_mvebu_mbus_config((void __iomem *)MVEBU_SATA0_BASE);
586 ahci_mvebu_regret_option((void __iomem *)MVEBU_SATA0_BASE);
587
588 return 0;
589}
590
591#ifdef CONFIG_SCSI_AHCI_PLAT
Stefan Roese4d991cb2015-06-29 14:58:13 +0200592void scsi_init(void)
593{
594 printf("MVEBU SATA INIT\n");
Baruch Siach4b11e5f2019-03-24 13:27:43 +0200595 board_ahci_enable();
Stefan Roese4d991cb2015-06-29 14:58:13 +0200596 ahci_init((void __iomem *)MVEBU_SATA0_BASE);
597}
598#endif
599
Jon Nettleton78aa0182017-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 Roese41e5ee52014-10-22 12:13:17 +0200641void enable_caches(void)
642{
Stefan Roese60b75322015-04-25 06:29:55 +0200643 /* Avoid problem with e.g. neta ethernet driver */
644 invalidate_dcache_all();
645
Stefan Roeseebe78902016-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 */
651 if (mvebu_soc_family() != MVEBU_SOC_A375) {
652 /* Enable D-cache. I-cache is already enabled in start.S */
653 dcache_enable();
654 }
Stefan Roese41e5ee52014-10-22 12:13:17 +0200655}
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100656
657void v7_outer_cache_enable(void)
658{
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100659 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
Stefan Roesec86d53f2015-12-03 12:39:45 +0100660 struct pl310_regs *const pl310 =
661 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100662 u32 u;
663
Stefan Roesec86d53f2015-12-03 12:39:45 +0100664 /* The L2 cache is already disabled at this point */
665
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100666 /*
667 * For Aurora cache in no outer mode, enable via the CP15
668 * coprocessor broadcasting of cache commands to L2.
669 */
670 asm volatile("mrc p15, 1, %0, c15, c2, 0" : "=r" (u));
671 u |= BIT(8); /* Set the FW bit */
672 asm volatile("mcr p15, 1, %0, c15, c2, 0" : : "r" (u));
673
674 isb();
675
676 /* Enable the L2 cache */
677 setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
678 }
679}
Stefan Roesef0e81732015-12-14 12:31:48 +0100680
681void v7_outer_cache_disable(void)
682{
683 struct pl310_regs *const pl310 =
684 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
685
686 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
687}