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