blob: 529dac905951bd7b820f4a2cba13cd05ccfb4d75 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roese21b29fc2016-05-25 08:13:45 +02002/*
3 * Copyright (C) 2016 Stefan Roese <sr@denx.de>
Stefan Roese21b29fc2016-05-25 08:13:45 +02004 */
5
6#include <common.h>
Simon Glass9edefc22019-11-14 12:57:37 -07007#include <cpu_func.h>
Stefan Roese21b29fc2016-05-25 08:13:45 +02008#include <dm.h>
9#include <fdtdec.h>
Masahiro Yamadab08c8c42018-03-05 01:20:11 +090010#include <linux/libfdt.h>
Stefan Roese21b29fc2016-05-25 08:13:45 +020011#include <asm/io.h>
12#include <asm/system.h>
13#include <asm/arch/cpu.h>
14#include <asm/arch/soc.h>
15#include <asm/armv8/mmu.h>
16
Stefan Roese21b29fc2016-05-25 08:13:45 +020017/* Armada 7k/8k */
18#define MVEBU_RFU_BASE (MVEBU_REGISTER(0x6f0000))
19#define RFU_GLOBAL_SW_RST (MVEBU_RFU_BASE + 0x84)
20#define RFU_SW_RESET_OFFSET 0
21
Baruch Siach7e1d3222018-08-14 18:05:46 +030022#define SAR0_REG (MVEBU_REGISTER(0x2400200))
23#define BOOT_MODE_MASK 0x3f
24#define BOOT_MODE_OFFSET 4
25
Konstantin Porotchkin0d92f212016-12-19 17:04:42 +020026/*
27 * The following table includes all memory regions for Armada 7k and
28 * 8k SoCs. The Armada 7k is missing the CP110 slave regions here. Lets
29 * define these regions at the beginning of the struct so that they
30 * can be easier removed later dynamically if an Armada 7k device is detected.
31 * For a detailed memory map, please see doc/mvebu/armada-8k-memory.txt
32 */
33#define ARMADA_7K8K_COMMON_REGIONS_START 2
Stefan Roese21b29fc2016-05-25 08:13:45 +020034static struct mm_region mvebu_mem_map[] = {
Konstantin Porotchkin0d92f212016-12-19 17:04:42 +020035 /* Armada 80x0 memory regions include the CP1 (slave) units */
36 {
37 /* SRAM, MMIO regions - CP110 slave region */
38 .phys = 0xf4000000UL,
39 .virt = 0xf4000000UL,
40 .size = 0x02000000UL, /* 32MiB internal registers */
41 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
42 PTE_BLOCK_NON_SHARE
43 },
44 {
45 /* PCI CP1 regions */
46 .phys = 0xfa000000UL,
47 .virt = 0xfa000000UL,
48 .size = 0x04000000UL, /* 64MiB CP110 slave PCI space */
49 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
50 PTE_BLOCK_NON_SHARE
51 },
52 /* Armada 80x0 and 70x0 common memory regions start here */
Stefan Roese21b29fc2016-05-25 08:13:45 +020053 {
54 /* RAM */
55 .phys = 0x0UL,
56 .virt = 0x0UL,
57 .size = 0x80000000UL,
58 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
59 PTE_BLOCK_INNER_SHARE
60 },
61 {
62 /* SRAM, MMIO regions - AP806 region */
63 .phys = 0xf0000000UL,
64 .virt = 0xf0000000UL,
65 .size = 0x01000000UL, /* 16MiB internal registers */
66 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
67 PTE_BLOCK_NON_SHARE
68 },
69 {
Stefan Roese3fef31a2016-10-25 18:14:29 +020070 /* SRAM, MMIO regions - CP110 master region */
Stefan Roese21b29fc2016-05-25 08:13:45 +020071 .phys = 0xf2000000UL,
72 .virt = 0xf2000000UL,
73 .size = 0x02000000UL, /* 32MiB internal registers */
74 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
75 PTE_BLOCK_NON_SHARE
76 },
77 {
Konstantin Porotchkin0d92f212016-12-19 17:04:42 +020078 /* PCI CP0 regions */
79 .phys = 0xf6000000UL,
80 .virt = 0xf6000000UL,
81 .size = 0x04000000UL, /* 64MiB CP110 master PCI space */
Stefan Roese3fef31a2016-10-25 18:14:29 +020082 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
83 PTE_BLOCK_NON_SHARE
84 },
85 {
Stefan Roese21b29fc2016-05-25 08:13:45 +020086 0,
87 }
88};
89
90struct mm_region *mem_map = mvebu_mem_map;
91
Konstantin Porotchkin0d92f212016-12-19 17:04:42 +020092void enable_caches(void)
93{
94 /*
95 * Armada 7k is not equipped with the CP110 slave CP. In case this
96 * code runs on an Armada 7k device, lets remove the CP110 slave
97 * entries from the memory mapping by moving the start to the
98 * common regions.
99 */
100 if (of_machine_is_compatible("marvell,armada7040"))
101 mem_map = &mvebu_mem_map[ARMADA_7K8K_COMMON_REGIONS_START];
102
103 icache_enable();
104 dcache_enable();
105}
106
Stefan Roese21b29fc2016-05-25 08:13:45 +0200107void reset_cpu(ulong ignored)
108{
109 u32 reg;
110
111 reg = readl(RFU_GLOBAL_SW_RST);
112 reg &= ~(1 << RFU_SW_RESET_OFFSET);
113 writel(reg, RFU_GLOBAL_SW_RST);
114}
Konstantin Porotchkina2cb5592017-04-05 18:22:31 +0300115
116/*
117 * TODO - implement this functionality using platform
118 * clock driver once it gets available
119 * Return NAND clock in Hz
120 */
121u32 mvebu_get_nand_clock(void)
122{
123 unsigned long NAND_FLASH_CLK_CTRL = 0xF2440700UL;
124 unsigned long NF_CLOCK_SEL_MASK = 0x1;
125 u32 reg;
126
127 reg = readl(NAND_FLASH_CLK_CTRL);
128 if (reg & NF_CLOCK_SEL_MASK)
129 return 400 * 1000000;
130 else
131 return 250 * 1000000;
132}
Baruch Siach7e1d3222018-08-14 18:05:46 +0300133
134int mmc_get_env_dev(void)
135{
136 u32 reg;
137 unsigned int boot_mode;
138
139 reg = readl(SAR0_REG);
140 boot_mode = (reg >> BOOT_MODE_OFFSET) & BOOT_MODE_MASK;
141
142 switch (boot_mode) {
143 case 0x28:
144 case 0x2a:
145 return 0;
146 case 0x29:
147 case 0x2b:
148 return 1;
149 }
150
151 return CONFIG_SYS_MMC_ENV_DEV;
152}