blob: 939abce000f6ec2ed5c9b8c0ec391ef3cba21d2a [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Stefan Roesecb410332016-05-25 08:13:45 +02002/*
3 * Copyright (C) 2016 Stefan Roese <sr@denx.de>
Stefan Roesecb410332016-05-25 08:13:45 +02004 */
5
6#include <common.h>
Simon Glass1d91ba72019-11-14 12:57:37 -07007#include <cpu_func.h>
Stefan Roesecb410332016-05-25 08:13:45 +02008#include <dm.h>
9#include <fdtdec.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +090010#include <linux/libfdt.h>
jinghuaccbd9cc2021-04-30 15:29:47 +020011#include <linux/sizes.h>
Stefan Roesecb410332016-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>
Grzegorz Jaszczyk77f26562021-04-30 15:29:48 +020017#include <mach/fw_info.h>
Stefan Roesecb410332016-05-25 08:13:45 +020018
Stefan Roesecb410332016-05-25 08:13:45 +020019/* Armada 7k/8k */
20#define MVEBU_RFU_BASE (MVEBU_REGISTER(0x6f0000))
21#define RFU_GLOBAL_SW_RST (MVEBU_RFU_BASE + 0x84)
22#define RFU_SW_RESET_OFFSET 0
23
Baruch Siach0d022902018-08-14 18:05:46 +030024#define SAR0_REG (MVEBU_REGISTER(0x2400200))
25#define BOOT_MODE_MASK 0x3f
26#define BOOT_MODE_OFFSET 4
27
Stefan Roesecb410332016-05-25 08:13:45 +020028static struct mm_region mvebu_mem_map[] = {
Konstantin Porotchkin8f00f692016-12-19 17:04:42 +020029 /* Armada 80x0 memory regions include the CP1 (slave) units */
30 {
Grzegorz Jaszczyk77f26562021-04-30 15:29:48 +020031 /* RAM 0-64MB */
Stefan Roesecb410332016-05-25 08:13:45 +020032 .phys = 0x0UL,
33 .virt = 0x0UL,
Grzegorz Jaszczyk77f26562021-04-30 15:29:48 +020034 .size = ATF_REGION_START,
35 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
36 PTE_BLOCK_INNER_SHARE
37 },
38 /* ATF and TEE region 0x4000000-0x5400000 not mapped */
39 {
40 /* RAM 66MB-2GB */
41 .phys = ATF_REGION_END,
42 .virt = ATF_REGION_END,
jinghuaccbd9cc2021-04-30 15:29:47 +020043 .size = SZ_2G,
Stefan Roesecb410332016-05-25 08:13:45 +020044 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
45 PTE_BLOCK_INNER_SHARE
46 },
47 {
jinghuaccbd9cc2021-04-30 15:29:47 +020048 /* MMIO regions */
Grzegorz Jaszczyk0beff3c2021-04-30 15:29:50 +020049 .phys = MMIO_REGS_PHY_BASE,
50 .virt = MMIO_REGS_PHY_BASE,
jinghuaccbd9cc2021-04-30 15:29:47 +020051 .size = SZ_1G,
52
Stefan Roese5c22e302016-10-25 18:14:29 +020053 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
54 PTE_BLOCK_NON_SHARE
55 },
56 {
Stefan Roesecb410332016-05-25 08:13:45 +020057 0,
58 }
59};
60
61struct mm_region *mem_map = mvebu_mem_map;
62
Konstantin Porotchkin8f00f692016-12-19 17:04:42 +020063void enable_caches(void)
64{
Konstantin Porotchkin8f00f692016-12-19 17:04:42 +020065 icache_enable();
66 dcache_enable();
67}
68
Harald Seiler6f14d5f2020-12-15 16:47:52 +010069void reset_cpu(void)
Stefan Roesecb410332016-05-25 08:13:45 +020070{
71 u32 reg;
72
73 reg = readl(RFU_GLOBAL_SW_RST);
74 reg &= ~(1 << RFU_SW_RESET_OFFSET);
75 writel(reg, RFU_GLOBAL_SW_RST);
76}
Konstantin Porotchkine13b5ed2017-04-05 18:22:31 +030077
78/*
79 * TODO - implement this functionality using platform
80 * clock driver once it gets available
81 * Return NAND clock in Hz
82 */
83u32 mvebu_get_nand_clock(void)
84{
85 unsigned long NAND_FLASH_CLK_CTRL = 0xF2440700UL;
86 unsigned long NF_CLOCK_SEL_MASK = 0x1;
87 u32 reg;
88
89 reg = readl(NAND_FLASH_CLK_CTRL);
90 if (reg & NF_CLOCK_SEL_MASK)
91 return 400 * 1000000;
92 else
93 return 250 * 1000000;
94}
Baruch Siach0d022902018-08-14 18:05:46 +030095
96int mmc_get_env_dev(void)
97{
98 u32 reg;
99 unsigned int boot_mode;
100
101 reg = readl(SAR0_REG);
102 boot_mode = (reg >> BOOT_MODE_OFFSET) & BOOT_MODE_MASK;
103
104 switch (boot_mode) {
105 case 0x28:
106 case 0x2a:
107 return 0;
108 case 0x29:
109 case 0x2b:
110 return 1;
111 }
112
113 return CONFIG_SYS_MMC_ENV_DEV;
114}