blob: 3ee589891b1af035f2f7a63791af55757448991c [file] [log] [blame]
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +01001// SPDX-License-Identifier: (GPL-2.0+ OR MIT)
2/*
3 * Copyright (c) 2018 Microsemi Corporation
4 */
5
6#include <common.h>
7
8#include <asm/io.h>
9#include <asm/types.h>
Lars Povlsen1470ce22020-02-06 10:45:40 +010010#include <asm/mipsregs.h>
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +010011
12#include <mach/tlb.h>
13#include <mach/ddr.h>
14
15DECLARE_GLOBAL_DATA_PTR;
16
17#if CONFIG_SYS_SDRAM_SIZE <= SZ_64M
18#define MSCC_RAM_TLB_SIZE SZ_64M
19#define MSCC_ATTRIB2 MMU_REGIO_INVAL
20#elif CONFIG_SYS_SDRAM_SIZE <= SZ_128M
21#define MSCC_RAM_TLB_SIZE SZ_64M
22#define MSCC_ATTRIB2 MMU_REGIO_RW
23#elif CONFIG_SYS_SDRAM_SIZE <= SZ_256M
24#define MSCC_RAM_TLB_SIZE SZ_256M
25#define MSCC_ATTRIB2 MMU_REGIO_INVAL
26#elif CONFIG_SYS_SDRAM_SIZE <= SZ_512M
27#define MSCC_RAM_TLB_SIZE SZ_256M
28#define MSCC_ATTRIB2 MMU_REGIO_RW
29#else
30#define MSCC_RAM_TLB_SIZE SZ_512M
31#define MSCC_ATTRIB2 MMU_REGIO_RW
32#endif
33
34/* NOTE: lowlevel_init() function does not have access to the
35 * stack. Thus, all called functions must be inlined, and (any) local
36 * variables must be kept in registers.
37 */
38void vcoreiii_tlb_init(void)
39{
40 register int tlbix = 0;
41
42 /*
43 * Unlike most of the MIPS based SoCs, the IO register address
44 * are not in KSEG0. The mainline linux kernel built in legacy
45 * mode needs to access some of the registers very early in
46 * the boot and make the assumption that the bootloader has
47 * already configured them, so we have to match this
48 * expectation.
49 */
50 create_tlb(tlbix++, MSCC_IO_ORIGIN1_OFFSET, SZ_16M, MMU_REGIO_RW,
51 MMU_REGIO_RW);
Gregory CLEMENT819b57212018-12-14 16:16:48 +010052#ifdef CONFIG_SOC_LUTON
53 create_tlb(tlbix++, MSCC_IO_ORIGIN2_OFFSET, SZ_16M, MMU_REGIO_RW,
54 MMU_REGIO_RW);
55#endif
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +010056
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +010057 /*
58 * If U-Boot is located in NOR then we want to be able to use
59 * the data cache in order to boot in a decent duration
60 */
61 create_tlb(tlbix++, MSCC_FLASH_TO, SZ_16M, MMU_REGIO_RO_C,
62 MMU_REGIO_RO_C);
63 create_tlb(tlbix++, MSCC_FLASH_TO + SZ_32M, SZ_16M, MMU_REGIO_RO_C,
64 MMU_REGIO_RO_C);
65
66 /*
67 * Using cache for RAM also helps to improve boot time. Thanks
68 * to this the time to relocate U-Boot in RAM went from 2.092
69 * secs to 0.104 secs.
70 */
71 create_tlb(tlbix++, MSCC_DDR_TO, MSCC_RAM_TLB_SIZE, MMU_REGIO_RW,
72 MSCC_ATTRIB2);
73
Lars Povlsen1470ce22020-02-06 10:45:40 +010074 /* Enable mapping (using TLB) kuseg by clearing the bit ERL,
75 * which is set on reset.
76 */
77 write_c0_status(read_c0_status() & ~ST0_ERL);
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +010078}
79
80int mach_cpu_init(void)
81{
82 /* Speed up NOR flash access */
Gregory CLEMENT819b57212018-12-14 16:16:48 +010083#ifdef CONFIG_SOC_LUTON
84 writel(ICPU_PI_MST_CFG_TRISTATE_CTRL +
85 ICPU_PI_MST_CFG_CLK_DIV(4), BASE_CFG + ICPU_PI_MST_CFG);
86
87 writel(ICPU_SPI_MST_CFG_FAST_READ_ENA +
88 ICPU_SPI_MST_CFG_CS_DESELECT_TIME(0x19) +
89 ICPU_SPI_MST_CFG_CLK_DIV(9), BASE_CFG + ICPU_SPI_MST_CFG);
90#else
Horatiu Vultur914e7872019-01-23 16:39:42 +010091#if defined(CONFIG_SOC_OCELOT) || defined(CONFIG_SOC_SERVAL)
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +010092 writel(ICPU_SPI_MST_CFG_CS_DESELECT_TIME(0x19) +
93 ICPU_SPI_MST_CFG_CLK_DIV(9), BASE_CFG + ICPU_SPI_MST_CFG);
Horatiu Vultur8a22b882019-01-12 18:56:56 +010094#endif
Horatiu Vulturc15620a2019-01-17 15:33:27 +010095#if defined(CONFIG_SOC_JR2) || defined(CONFIG_SOC_SERVALT)
Horatiu Vultur8a22b882019-01-12 18:56:56 +010096 writel(ICPU_SPI_MST_CFG_FAST_READ_ENA +
97 ICPU_SPI_MST_CFG_CS_DESELECT_TIME(0x19) +
98 ICPU_SPI_MST_CFG_CLK_DIV(14), BASE_CFG + ICPU_SPI_MST_CFG);
99#endif
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +0100100 /*
101 * Legacy and mainline linux kernel expect that the
102 * interruption map was set as it was done by redboot.
103 */
104 writel(~0, BASE_CFG + ICPU_DST_INTR_MAP(0));
105 writel(0, BASE_CFG + ICPU_DST_INTR_MAP(1));
106 writel(0, BASE_CFG + ICPU_DST_INTR_MAP(2));
107 writel(0, BASE_CFG + ICPU_DST_INTR_MAP(3));
Gregory CLEMENT819b57212018-12-14 16:16:48 +0100108#endif
Gregory CLEMENTaf05ee52018-12-14 16:16:47 +0100109 return 0;
110}