blob: 7908f75809c5eb3d5a8bc22c659c364195d3f1f3 [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
Simon Glass1d91ba72019-11-14 12:57:37 -07006#include <cpu_func.h>
Stefan Roesecb410332016-05-25 08:13:45 +02007#include <dm.h>
8#include <fdtdec.h>
Masahiro Yamada75f82d02018-03-05 01:20:11 +09009#include <linux/libfdt.h>
jinghuaccbd9cc2021-04-30 15:29:47 +020010#include <linux/sizes.h>
Stefan Roesecb410332016-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>
Grzegorz Jaszczyk77f26562021-04-30 15:29:48 +020016#include <mach/fw_info.h>
Stefan Roesecb410332016-05-25 08:13:45 +020017
Stefan Roesecb410332016-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 Siach0d022902018-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 Roesecb410332016-05-25 08:13:45 +020027static struct mm_region mvebu_mem_map[] = {
Konstantin Porotchkin8f00f692016-12-19 17:04:42 +020028 /* Armada 80x0 memory regions include the CP1 (slave) units */
29 {
Grzegorz Jaszczyk77f26562021-04-30 15:29:48 +020030 /* RAM 0-64MB */
Stefan Roesecb410332016-05-25 08:13:45 +020031 .phys = 0x0UL,
32 .virt = 0x0UL,
Grzegorz Jaszczyk77f26562021-04-30 15:29:48 +020033 .size = ATF_REGION_START,
34 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
35 PTE_BLOCK_INNER_SHARE
36 },
37 /* ATF and TEE region 0x4000000-0x5400000 not mapped */
38 {
39 /* RAM 66MB-2GB */
40 .phys = ATF_REGION_END,
41 .virt = ATF_REGION_END,
jinghuaccbd9cc2021-04-30 15:29:47 +020042 .size = SZ_2G,
Stefan Roesecb410332016-05-25 08:13:45 +020043 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
44 PTE_BLOCK_INNER_SHARE
45 },
46 {
jinghuaccbd9cc2021-04-30 15:29:47 +020047 /* MMIO regions */
Grzegorz Jaszczyk0beff3c2021-04-30 15:29:50 +020048 .phys = MMIO_REGS_PHY_BASE,
49 .virt = MMIO_REGS_PHY_BASE,
jinghuaccbd9cc2021-04-30 15:29:47 +020050 .size = SZ_1G,
51
Stefan Roese5c22e302016-10-25 18:14:29 +020052 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
53 PTE_BLOCK_NON_SHARE
54 },
55 {
Stefan Roesecb410332016-05-25 08:13:45 +020056 0,
57 }
58};
59
60struct mm_region *mem_map = mvebu_mem_map;
61
Konstantin Porotchkin8f00f692016-12-19 17:04:42 +020062void enable_caches(void)
63{
Konstantin Porotchkin8f00f692016-12-19 17:04:42 +020064 icache_enable();
65 dcache_enable();
66}
67
Harald Seiler6f14d5f2020-12-15 16:47:52 +010068void reset_cpu(void)
Stefan Roesecb410332016-05-25 08:13:45 +020069{
70 u32 reg;
71
72 reg = readl(RFU_GLOBAL_SW_RST);
73 reg &= ~(1 << RFU_SW_RESET_OFFSET);
74 writel(reg, RFU_GLOBAL_SW_RST);
75}
Konstantin Porotchkine13b5ed2017-04-05 18:22:31 +030076
77/*
78 * TODO - implement this functionality using platform
79 * clock driver once it gets available
80 * Return NAND clock in Hz
81 */
82u32 mvebu_get_nand_clock(void)
83{
84 unsigned long NAND_FLASH_CLK_CTRL = 0xF2440700UL;
85 unsigned long NF_CLOCK_SEL_MASK = 0x1;
86 u32 reg;
87
88 reg = readl(NAND_FLASH_CLK_CTRL);
89 if (reg & NF_CLOCK_SEL_MASK)
90 return 400 * 1000000;
91 else
92 return 250 * 1000000;
93}
Baruch Siach0d022902018-08-14 18:05:46 +030094
95int mmc_get_env_dev(void)
96{
97 u32 reg;
98 unsigned int boot_mode;
99
100 reg = readl(SAR0_REG);
101 boot_mode = (reg >> BOOT_MODE_OFFSET) & BOOT_MODE_MASK;
102
103 switch (boot_mode) {
104 case 0x28:
105 case 0x2a:
106 return 0;
107 case 0x29:
108 case 0x2b:
109 return 1;
110 }
111
112 return CONFIG_SYS_MMC_ENV_DEV;
113}