blob: 99531711ee34d3f031e848f1f87fbfcaff96f02b [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>
jinghua762f9fb2021-04-30 15:29:47 +020011#include <linux/sizes.h>
Stefan Roese21b29fc2016-05-25 08:13:45 +020012#include <asm/io.h>
13#include <asm/system.h>
14#include <asm/arch/cpu.h>
15#include <asm/arch/soc.h>
16#include <asm/armv8/mmu.h>
17
Stefan Roese21b29fc2016-05-25 08:13:45 +020018/* Armada 7k/8k */
19#define MVEBU_RFU_BASE (MVEBU_REGISTER(0x6f0000))
20#define RFU_GLOBAL_SW_RST (MVEBU_RFU_BASE + 0x84)
21#define RFU_SW_RESET_OFFSET 0
22
Baruch Siach7e1d3222018-08-14 18:05:46 +030023#define SAR0_REG (MVEBU_REGISTER(0x2400200))
24#define BOOT_MODE_MASK 0x3f
25#define BOOT_MODE_OFFSET 4
26
Stefan Roese21b29fc2016-05-25 08:13:45 +020027static struct mm_region mvebu_mem_map[] = {
Konstantin Porotchkin0d92f212016-12-19 17:04:42 +020028 /* Armada 80x0 memory regions include the CP1 (slave) units */
29 {
Stefan Roese21b29fc2016-05-25 08:13:45 +020030 /* RAM */
31 .phys = 0x0UL,
32 .virt = 0x0UL,
jinghua762f9fb2021-04-30 15:29:47 +020033 .size = SZ_2G,
Stefan Roese21b29fc2016-05-25 08:13:45 +020034 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
35 PTE_BLOCK_INNER_SHARE
36 },
37 {
jinghua762f9fb2021-04-30 15:29:47 +020038 /* MMIO regions */
39 .phys = SOC_REGS_PHY_BASE,
40 .virt = SOC_REGS_PHY_BASE,
41 .size = SZ_1G,
42
Stefan Roese3fef31a2016-10-25 18:14:29 +020043 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
44 PTE_BLOCK_NON_SHARE
45 },
46 {
Stefan Roese21b29fc2016-05-25 08:13:45 +020047 0,
48 }
49};
50
51struct mm_region *mem_map = mvebu_mem_map;
52
Konstantin Porotchkin0d92f212016-12-19 17:04:42 +020053void enable_caches(void)
54{
Konstantin Porotchkin0d92f212016-12-19 17:04:42 +020055 icache_enable();
56 dcache_enable();
57}
58
Harald Seiler35b65dd2020-12-15 16:47:52 +010059void reset_cpu(void)
Stefan Roese21b29fc2016-05-25 08:13:45 +020060{
61 u32 reg;
62
63 reg = readl(RFU_GLOBAL_SW_RST);
64 reg &= ~(1 << RFU_SW_RESET_OFFSET);
65 writel(reg, RFU_GLOBAL_SW_RST);
66}
Konstantin Porotchkina2cb5592017-04-05 18:22:31 +030067
68/*
69 * TODO - implement this functionality using platform
70 * clock driver once it gets available
71 * Return NAND clock in Hz
72 */
73u32 mvebu_get_nand_clock(void)
74{
75 unsigned long NAND_FLASH_CLK_CTRL = 0xF2440700UL;
76 unsigned long NF_CLOCK_SEL_MASK = 0x1;
77 u32 reg;
78
79 reg = readl(NAND_FLASH_CLK_CTRL);
80 if (reg & NF_CLOCK_SEL_MASK)
81 return 400 * 1000000;
82 else
83 return 250 * 1000000;
84}
Baruch Siach7e1d3222018-08-14 18:05:46 +030085
86int mmc_get_env_dev(void)
87{
88 u32 reg;
89 unsigned int boot_mode;
90
91 reg = readl(SAR0_REG);
92 boot_mode = (reg >> BOOT_MODE_OFFSET) & BOOT_MODE_MASK;
93
94 switch (boot_mode) {
95 case 0x28:
96 case 0x2a:
97 return 0;
98 case 0x29:
99 case 0x2b:
100 return 1;
101 }
102
103 return CONFIG_SYS_MMC_ENV_DEV;
104}