Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (C) 2016 Stefan Roese <sr@denx.de> |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
Simon Glass | 1d91ba7 | 2019-11-14 12:57:37 -0700 | [diff] [blame] | 7 | #include <cpu_func.h> |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 8 | #include <dm.h> |
| 9 | #include <fdtdec.h> |
Masahiro Yamada | 75f82d0 | 2018-03-05 01:20:11 +0900 | [diff] [blame] | 10 | #include <linux/libfdt.h> |
jinghua | ccbd9cc | 2021-04-30 15:29:47 +0200 | [diff] [blame] | 11 | #include <linux/sizes.h> |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 12 | #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 Jaszczyk | 77f2656 | 2021-04-30 15:29:48 +0200 | [diff] [blame] | 17 | #include <mach/fw_info.h> |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 18 | |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 19 | /* 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 Siach | 0d02290 | 2018-08-14 18:05:46 +0300 | [diff] [blame] | 24 | #define SAR0_REG (MVEBU_REGISTER(0x2400200)) |
| 25 | #define BOOT_MODE_MASK 0x3f |
| 26 | #define BOOT_MODE_OFFSET 4 |
| 27 | |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 28 | static struct mm_region mvebu_mem_map[] = { |
Konstantin Porotchkin | 8f00f69 | 2016-12-19 17:04:42 +0200 | [diff] [blame] | 29 | /* Armada 80x0 memory regions include the CP1 (slave) units */ |
| 30 | { |
Grzegorz Jaszczyk | 77f2656 | 2021-04-30 15:29:48 +0200 | [diff] [blame] | 31 | /* RAM 0-64MB */ |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 32 | .phys = 0x0UL, |
| 33 | .virt = 0x0UL, |
Grzegorz Jaszczyk | 77f2656 | 2021-04-30 15:29:48 +0200 | [diff] [blame] | 34 | .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, |
jinghua | ccbd9cc | 2021-04-30 15:29:47 +0200 | [diff] [blame] | 43 | .size = SZ_2G, |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 44 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 45 | PTE_BLOCK_INNER_SHARE |
| 46 | }, |
| 47 | { |
jinghua | ccbd9cc | 2021-04-30 15:29:47 +0200 | [diff] [blame] | 48 | /* MMIO regions */ |
Grzegorz Jaszczyk | 0beff3c | 2021-04-30 15:29:50 +0200 | [diff] [blame] | 49 | .phys = MMIO_REGS_PHY_BASE, |
| 50 | .virt = MMIO_REGS_PHY_BASE, |
jinghua | ccbd9cc | 2021-04-30 15:29:47 +0200 | [diff] [blame] | 51 | .size = SZ_1G, |
| 52 | |
Stefan Roese | 5c22e30 | 2016-10-25 18:14:29 +0200 | [diff] [blame] | 53 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 54 | PTE_BLOCK_NON_SHARE |
| 55 | }, |
| 56 | { |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 57 | 0, |
| 58 | } |
| 59 | }; |
| 60 | |
| 61 | struct mm_region *mem_map = mvebu_mem_map; |
| 62 | |
Konstantin Porotchkin | 8f00f69 | 2016-12-19 17:04:42 +0200 | [diff] [blame] | 63 | void enable_caches(void) |
| 64 | { |
Konstantin Porotchkin | 8f00f69 | 2016-12-19 17:04:42 +0200 | [diff] [blame] | 65 | icache_enable(); |
| 66 | dcache_enable(); |
| 67 | } |
| 68 | |
Harald Seiler | 6f14d5f | 2020-12-15 16:47:52 +0100 | [diff] [blame] | 69 | void reset_cpu(void) |
Stefan Roese | cb41033 | 2016-05-25 08:13:45 +0200 | [diff] [blame] | 70 | { |
| 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 Porotchkin | e13b5ed | 2017-04-05 18:22:31 +0300 | [diff] [blame] | 77 | |
| 78 | /* |
| 79 | * TODO - implement this functionality using platform |
| 80 | * clock driver once it gets available |
| 81 | * Return NAND clock in Hz |
| 82 | */ |
| 83 | u32 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 Siach | 0d02290 | 2018-08-14 18:05:46 +0300 | [diff] [blame] | 95 | |
| 96 | int 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 | } |