blob: 570966a4465accecd1cf6116b3a0cde2a0ef0bd2 [file] [log] [blame]
Stefan Roese41e5ee52014-10-22 12:13:17 +02001/*
Stefan Roese9c6d3b72015-04-25 06:29:51 +02002 * Copyright (C) 2014-2015 Stefan Roese <sr@denx.de>
Stefan Roese41e5ee52014-10-22 12:13:17 +02003 *
4 * SPDX-License-Identifier: GPL-2.0+
5 */
6
7#include <common.h>
8#include <netdev.h>
Stefan Roese4d991cb2015-06-29 14:58:13 +02009#include <ahci.h>
10#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 },
Stefan Roese41e5ee52014-10-22 12:13:17 +020028};
29
Stefan Roese42cc0342015-08-25 14:09:12 +020030void lowlevel_init(void)
31{
32 /*
33 * Dummy implementation, we only need LOWLEVEL_INIT
34 * on Armada to configure CP15 in start.S / cpu_init_cp15()
35 */
36}
37
Stefan Roese41e5ee52014-10-22 12:13:17 +020038void reset_cpu(unsigned long ignored)
39{
40 struct mvebu_system_registers *reg =
41 (struct mvebu_system_registers *)MVEBU_SYSTEM_REG_BASE;
42
43 writel(readl(&reg->rstoutn_mask) | 1, &reg->rstoutn_mask);
44 writel(readl(&reg->sys_soft_rst) | 1, &reg->sys_soft_rst);
45 while (1)
46 ;
47}
48
Stefan Roese9c6d3b72015-04-25 06:29:51 +020049int mvebu_soc_family(void)
50{
51 u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
52
53 if (devid == SOC_MV78460_ID)
54 return MVEBU_SOC_AXP;
55
56 if (devid == SOC_88F6810_ID || devid == SOC_88F6820_ID ||
57 devid == SOC_88F6828_ID)
58 return MVEBU_SOC_A38X;
59
60 return MVEBU_SOC_UNKNOWN;
61}
62
Stefan Roese41e5ee52014-10-22 12:13:17 +020063#if defined(CONFIG_DISPLAY_CPUINFO)
64int print_cpuinfo(void)
65{
66 u16 devid = (readl(MVEBU_REG_PCIE_DEVID) >> 16) & 0xffff;
67 u8 revid = readl(MVEBU_REG_PCIE_REVID) & 0xff;
68
69 puts("SoC: ");
70
71 switch (devid) {
72 case SOC_MV78460_ID:
73 puts("MV78460-");
74 break;
Stefan Roese9c6d3b72015-04-25 06:29:51 +020075 case SOC_88F6810_ID:
76 puts("MV88F6810-");
77 break;
78 case SOC_88F6820_ID:
79 puts("MV88F6820-");
80 break;
81 case SOC_88F6828_ID:
82 puts("MV88F6828-");
83 break;
Stefan Roese41e5ee52014-10-22 12:13:17 +020084 default:
85 puts("Unknown-");
86 break;
87 }
88
Stefan Roese9c6d3b72015-04-25 06:29:51 +020089 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
90 switch (revid) {
91 case 1:
92 puts("A0\n");
93 break;
94 case 2:
95 puts("B0\n");
96 break;
97 default:
98 printf("?? (%x)\n", revid);
99 break;
100 }
101 }
102
103 if (mvebu_soc_family() == MVEBU_SOC_A38X) {
104 switch (revid) {
105 case MV_88F68XX_Z1_ID:
106 puts("Z1\n");
107 break;
108 case MV_88F68XX_A0_ID:
109 puts("A0\n");
110 break;
111 default:
112 printf("?? (%x)\n", revid);
113 break;
114 }
Stefan Roese41e5ee52014-10-22 12:13:17 +0200115 }
116
117 return 0;
118}
119#endif /* CONFIG_DISPLAY_CPUINFO */
120
121/*
122 * This function initialize Controller DRAM Fastpath windows.
123 * It takes the CS size information from the 0x1500 scratch registers
124 * and sets the correct windows sizes and base addresses accordingly.
125 *
126 * These values are set in the scratch registers by the Marvell
127 * DDR3 training code, which is executed by the BootROM before the
128 * main payload (U-Boot) is executed. This training code is currently
129 * only available in the Marvell U-Boot version. It needs to be
130 * ported to mainline U-Boot SPL at some point.
131 */
132static void update_sdram_window_sizes(void)
133{
134 u64 base = 0;
135 u32 size, temp;
136 int i;
137
138 for (i = 0; i < SDRAM_MAX_CS; i++) {
139 size = readl((MVEBU_SDRAM_SCRATCH + (i * 8))) & SDRAM_ADDR_MASK;
140 if (size != 0) {
141 size |= ~(SDRAM_ADDR_MASK);
142
143 /* Set Base Address */
144 temp = (base & 0xFF000000ll) | ((base >> 32) & 0xF);
145 writel(temp, MVEBU_SDRAM_BASE + DDR_BASE_CS_OFF(i));
146
147 /*
148 * Check if out of max window size and resize
149 * the window
150 */
151 temp = (readl(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i)) &
152 ~(SDRAM_ADDR_MASK)) | 1;
153 temp |= (size & SDRAM_ADDR_MASK);
154 writel(temp, MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i));
155
156 base += ((u64)size + 1);
157 } else {
158 /*
159 * Disable window if not used, otherwise this
160 * leads to overlapping enabled windows with
161 * pretty strange results
162 */
163 clrbits_le32(MVEBU_SDRAM_BASE + DDR_SIZE_CS_OFF(i), 1);
164 }
165 }
166}
167
Stefan Roese9f62b442015-04-24 10:49:11 +0200168void mmu_disable(void)
169{
170 asm volatile(
171 "mrc p15, 0, r0, c1, c0, 0\n"
172 "bic r0, #1\n"
173 "mcr p15, 0, r0, c1, c0, 0\n");
174}
175
Stefan Roese41e5ee52014-10-22 12:13:17 +0200176#ifdef CONFIG_ARCH_CPU_INIT
Kevin Smithe1b078e2015-05-18 16:09:44 +0000177static void set_cbar(u32 addr)
178{
179 asm("mcr p15, 4, %0, c15, c0" : : "r" (addr));
180}
181
Stefan Roesedee40d22015-07-22 18:26:13 +0200182#define MV_USB_PHY_BASE (MVEBU_AXP_USB_BASE + 0x800)
183#define MV_USB_PHY_PLL_REG(reg) (MV_USB_PHY_BASE | (((reg) & 0xF) << 2))
184#define MV_USB_X3_BASE(addr) (MVEBU_AXP_USB_BASE | BIT(11) | \
185 (((addr) & 0xF) << 6))
186#define MV_USB_X3_PHY_CHANNEL(dev, reg) (MV_USB_X3_BASE((dev) + 1) | \
187 (((reg) & 0xF) << 2))
188
189static void setup_usb_phys(void)
190{
191 int dev;
192
193 /*
194 * USB PLL init
195 */
196
197 /* Setup PLL frequency */
198 /* USB REF frequency = 25 MHz */
199 clrsetbits_le32(MV_USB_PHY_PLL_REG(1), 0x3ff, 0x605);
200
201 /* Power up PLL and PHY channel */
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100202 setbits_le32(MV_USB_PHY_PLL_REG(2), BIT(9));
Stefan Roesedee40d22015-07-22 18:26:13 +0200203
204 /* Assert VCOCAL_START */
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100205 setbits_le32(MV_USB_PHY_PLL_REG(1), BIT(21));
Stefan Roesedee40d22015-07-22 18:26:13 +0200206
207 mdelay(1);
208
209 /*
210 * USB PHY init (change from defaults) specific for 40nm (78X30 78X60)
211 */
212
213 for (dev = 0; dev < 3; dev++) {
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100214 setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 3), BIT(15));
Stefan Roesedee40d22015-07-22 18:26:13 +0200215
216 /* Assert REG_RCAL_START in channel REG 1 */
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100217 setbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
Stefan Roesedee40d22015-07-22 18:26:13 +0200218 udelay(40);
Stefan Roeseab8a4c62015-12-04 13:08:34 +0100219 clrbits_le32(MV_USB_X3_PHY_CHANNEL(dev, 1), BIT(12));
Stefan Roesedee40d22015-07-22 18:26:13 +0200220 }
221}
Kevin Smithe1b078e2015-05-18 16:09:44 +0000222
Stefan Roesef4e6ec72015-12-03 12:39:45 +0100223/*
224 * This function is not called from the SPL U-Boot version
225 */
Stefan Roese41e5ee52014-10-22 12:13:17 +0200226int arch_cpu_init(void)
227{
Stefan Roese42cc0342015-08-25 14:09:12 +0200228 struct pl310_regs *const pl310 =
229 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
230
Stefan Roesecefd7642015-08-24 11:03:50 +0200231 /*
232 * Only with disabled MMU its possible to switch the base
233 * register address on Armada 38x. Without this the SDRAM
234 * located at >= 0x4000.0000 is also not accessible, as its
235 * still locked to cache.
236 */
237 mmu_disable();
Stefan Roese9f62b442015-04-24 10:49:11 +0200238
Stefan Roese41e5ee52014-10-22 12:13:17 +0200239 /* Linux expects the internal registers to be at 0xf1000000 */
240 writel(SOC_REGS_PHY_BASE, INTREG_BASE_ADDR_REG);
Kevin Smithe1b078e2015-05-18 16:09:44 +0000241 set_cbar(SOC_REGS_PHY_BASE + 0xC000);
Stefan Roese41e5ee52014-10-22 12:13:17 +0200242
Stefan Roesecefd7642015-08-24 11:03:50 +0200243 /*
244 * From this stage on, the SoC detection is working. As we have
245 * configured the internal register base to the value used
246 * in the macros / defines in the U-Boot header (soc.h).
247 */
Stefan Roesecefd7642015-08-24 11:03:50 +0200248
Stefan Roesec86d53f2015-12-03 12:39:45 +0100249 if (mvebu_soc_family() == MVEBU_SOC_A38X) {
250 /*
251 * To fully release / unlock this area from cache, we need
252 * to flush all caches and disable the L2 cache.
253 */
254 icache_disable();
255 dcache_disable();
256 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
257 }
Stefan Roesecefd7642015-08-24 11:03:50 +0200258
Stefan Roese41e5ee52014-10-22 12:13:17 +0200259 /*
260 * We need to call mvebu_mbus_probe() before calling
261 * update_sdram_window_sizes() as it disables all previously
262 * configured mbus windows and then configures them as
263 * required for U-Boot. Calling update_sdram_window_sizes()
264 * without this configuration will not work, as the internal
265 * registers can't be accessed reliably because of potenial
266 * double mapping.
267 * After updating the SDRAM access windows we need to call
268 * mvebu_mbus_probe() again, as this now correctly configures
269 * the SDRAM areas that are later used by the MVEBU drivers
270 * (e.g. USB, NETA).
271 */
272
273 /*
274 * First disable all windows
275 */
276 mvebu_mbus_probe(NULL, 0);
277
Stefan Roese9c6d3b72015-04-25 06:29:51 +0200278 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
279 /*
280 * Now the SDRAM access windows can be reconfigured using
281 * the information in the SDRAM scratch pad registers
282 */
283 update_sdram_window_sizes();
284 }
Stefan Roese41e5ee52014-10-22 12:13:17 +0200285
286 /*
287 * Finally the mbus windows can be configured with the
288 * updated SDRAM sizes
289 */
290 mvebu_mbus_probe(windows, ARRAY_SIZE(windows));
291
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200292 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
293 /* Enable GBE0, GBE1, LCD and NFC PUP */
294 clrsetbits_le32(ARMADA_XP_PUP_ENABLE, 0,
295 GE0_PUP_EN | GE1_PUP_EN | LCD_PUP_EN |
296 NAND_PUP_EN | SPI_PUP_EN);
Stefan Roesedee40d22015-07-22 18:26:13 +0200297
298 /* Configure USB PLL and PHYs on AXP */
299 setup_usb_phys();
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200300 }
301
302 /* Enable NAND and NAND arbiter */
303 clrsetbits_le32(MVEBU_SOC_DEV_MUX_REG, 0, NAND_EN | NAND_ARBITER_EN);
304
Stefan Roese501c0982015-07-01 13:28:39 +0200305 /* Disable MBUS error propagation */
306 clrsetbits_le32(SOC_COHERENCY_FABRIC_CTRL_REG, MBUS_ERR_PROP_EN, 0);
307
Stefan Roese41e5ee52014-10-22 12:13:17 +0200308 return 0;
309}
310#endif /* CONFIG_ARCH_CPU_INIT */
311
Stefan Roese2a0b7dc2015-07-16 10:40:05 +0200312u32 mvebu_get_nand_clock(void)
313{
314 return CONFIG_SYS_MVEBU_PLL_CLOCK /
315 ((readl(MVEBU_CORE_DIV_CLK_CTRL(1)) &
316 NAND_ECC_DIVCKL_RATIO_MASK) >> NAND_ECC_DIVCKL_RATIO_OFFS);
317}
318
Stefan Roese41e5ee52014-10-22 12:13:17 +0200319/*
320 * SOC specific misc init
321 */
322#if defined(CONFIG_ARCH_MISC_INIT)
323int arch_misc_init(void)
324{
325 /* Nothing yet, perhaps we need something here later */
326 return 0;
327}
328#endif /* CONFIG_ARCH_MISC_INIT */
329
Stefan Roese7f1adcd2015-06-29 14:58:10 +0200330#ifdef CONFIG_MV_SDHCI
331int board_mmc_init(bd_t *bis)
332{
333 mv_sdh_init(MVEBU_SDIO_BASE, 0, 0,
334 SDHCI_QUIRK_32BIT_DMA_ADDR | SDHCI_QUIRK_WAIT_SEND_CMD);
335
336 return 0;
337}
338#endif
339
Stefan Roese4d991cb2015-06-29 14:58:13 +0200340#ifdef CONFIG_SCSI_AHCI_PLAT
341#define AHCI_VENDOR_SPECIFIC_0_ADDR 0xa0
342#define AHCI_VENDOR_SPECIFIC_0_DATA 0xa4
343
344#define AHCI_WINDOW_CTRL(win) (0x60 + ((win) << 4))
345#define AHCI_WINDOW_BASE(win) (0x64 + ((win) << 4))
346#define AHCI_WINDOW_SIZE(win) (0x68 + ((win) << 4))
347
348static void ahci_mvebu_mbus_config(void __iomem *base)
349{
350 const struct mbus_dram_target_info *dram;
351 int i;
352
353 dram = mvebu_mbus_dram_info();
354
355 for (i = 0; i < 4; i++) {
356 writel(0, base + AHCI_WINDOW_CTRL(i));
357 writel(0, base + AHCI_WINDOW_BASE(i));
358 writel(0, base + AHCI_WINDOW_SIZE(i));
359 }
360
361 for (i = 0; i < dram->num_cs; i++) {
362 const struct mbus_dram_window *cs = dram->cs + i;
363
364 writel((cs->mbus_attr << 8) |
365 (dram->mbus_dram_target_id << 4) | 1,
366 base + AHCI_WINDOW_CTRL(i));
367 writel(cs->base >> 16, base + AHCI_WINDOW_BASE(i));
368 writel(((cs->size - 1) & 0xffff0000),
369 base + AHCI_WINDOW_SIZE(i));
370 }
371}
372
373static void ahci_mvebu_regret_option(void __iomem *base)
374{
375 /*
376 * Enable the regret bit to allow the SATA unit to regret a
377 * request that didn't receive an acknowlegde and avoid a
378 * deadlock
379 */
380 writel(0x4, base + AHCI_VENDOR_SPECIFIC_0_ADDR);
381 writel(0x80, base + AHCI_VENDOR_SPECIFIC_0_DATA);
382}
383
384void scsi_init(void)
385{
386 printf("MVEBU SATA INIT\n");
387 ahci_mvebu_mbus_config((void __iomem *)MVEBU_SATA0_BASE);
388 ahci_mvebu_regret_option((void __iomem *)MVEBU_SATA0_BASE);
389 ahci_init((void __iomem *)MVEBU_SATA0_BASE);
390}
391#endif
392
Stefan Roese41e5ee52014-10-22 12:13:17 +0200393void enable_caches(void)
394{
Stefan Roese60b75322015-04-25 06:29:55 +0200395 /* Avoid problem with e.g. neta ethernet driver */
396 invalidate_dcache_all();
397
Stefan Roese41e5ee52014-10-22 12:13:17 +0200398 /* Enable D-cache. I-cache is already enabled in start.S */
399 dcache_enable();
400}
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100401
402void v7_outer_cache_enable(void)
403{
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100404 if (mvebu_soc_family() == MVEBU_SOC_AXP) {
Stefan Roesec86d53f2015-12-03 12:39:45 +0100405 struct pl310_regs *const pl310 =
406 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100407 u32 u;
408
Stefan Roesec86d53f2015-12-03 12:39:45 +0100409 /* The L2 cache is already disabled at this point */
410
Stefan Roese3e5ce7c2015-12-03 12:39:45 +0100411 /*
412 * For Aurora cache in no outer mode, enable via the CP15
413 * coprocessor broadcasting of cache commands to L2.
414 */
415 asm volatile("mrc p15, 1, %0, c15, c2, 0" : "=r" (u));
416 u |= BIT(8); /* Set the FW bit */
417 asm volatile("mcr p15, 1, %0, c15, c2, 0" : : "r" (u));
418
419 isb();
420
421 /* Enable the L2 cache */
422 setbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
423 }
424}
Stefan Roesef0e81732015-12-14 12:31:48 +0100425
426void v7_outer_cache_disable(void)
427{
428 struct pl310_regs *const pl310 =
429 (struct pl310_regs *)CONFIG_SYS_PL310_BASE;
430
431 clrbits_le32(&pl310->pl310_ctrl, L2X0_CTRL_EN);
432}