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