Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Beniamino Galvani | bfcef28 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2016 Beniamino Galvani <b.galvani@gmail.com> |
Jerome Brunet | 33e3378 | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 4 | * (C) Copyright 2018 Neil Armstrong <narmstrong@baylibre.com> |
Beniamino Galvani | bfcef28 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Neil Armstrong | d96a782 | 2018-07-27 14:10:00 +0200 | [diff] [blame] | 8 | #include <asm/arch/boot.h> |
Jerome Brunet | 33e3378 | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 9 | #include <asm/arch/eth.h> |
Neil Armstrong | f0f3762 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 10 | #include <asm/arch/gx.h> |
Jerome Brunet | 33e3378 | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 11 | #include <asm/arch/mem.h> |
Maxime Jourdan | 0cc53fa | 2018-12-11 12:52:04 +0100 | [diff] [blame] | 12 | #include <asm/arch/meson-vpu.h> |
Neil Armstrong | c7be3e5 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 13 | #include <asm/io.h> |
Jerome Brunet | 33e3378 | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 14 | #include <asm/armv8/mmu.h> |
| 15 | #include <linux/sizes.h> |
| 16 | #include <phy.h> |
Beniamino Galvani | bfcef28 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 17 | |
| 18 | DECLARE_GLOBAL_DATA_PTR; |
| 19 | |
Neil Armstrong | d96a782 | 2018-07-27 14:10:00 +0200 | [diff] [blame] | 20 | int meson_get_boot_device(void) |
| 21 | { |
| 22 | return readl(GX_AO_SEC_GP_CFG0) & GX_AO_BOOT_DEVICE; |
| 23 | } |
| 24 | |
Jerome Brunet | 33e3378 | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 25 | /* Configure the reserved memory zones exported by the secure registers |
| 26 | * into EFI and DTB reserved memory entries. |
| 27 | */ |
| 28 | void meson_init_reserved_memory(void *fdt) |
Neil Armstrong | c7be3e5 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 29 | { |
| 30 | u64 bl31_size, bl31_start; |
| 31 | u64 bl32_size, bl32_start; |
| 32 | u32 reg; |
| 33 | |
| 34 | /* |
| 35 | * Get ARM Trusted Firmware reserved memory zones in : |
| 36 | * - AO_SEC_GP_CFG3: bl32 & bl31 size in KiB, can be 0 |
| 37 | * - AO_SEC_GP_CFG5: bl31 physical start address, can be NULL |
| 38 | * - AO_SEC_GP_CFG4: bl32 physical start address, can be NULL |
| 39 | */ |
Neil Armstrong | f0f3762 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 40 | reg = readl(GX_AO_SEC_GP_CFG3); |
Neil Armstrong | c7be3e5 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 41 | |
Neil Armstrong | f0f3762 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 42 | bl31_size = ((reg & GX_AO_BL31_RSVMEM_SIZE_MASK) |
| 43 | >> GX_AO_BL31_RSVMEM_SIZE_SHIFT) * SZ_1K; |
| 44 | bl32_size = (reg & GX_AO_BL32_RSVMEM_SIZE_MASK) * SZ_1K; |
Neil Armstrong | c7be3e5 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 45 | |
Neil Armstrong | f0f3762 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 46 | bl31_start = readl(GX_AO_SEC_GP_CFG5); |
| 47 | bl32_start = readl(GX_AO_SEC_GP_CFG4); |
Neil Armstrong | c7be3e5 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 48 | |
| 49 | /* |
Neil Armstrong | f0f3762 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 50 | * Early Meson GX Firmware revisions did not provide the reserved |
Neil Armstrong | c7be3e5 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 51 | * memory zones in the registers, keep fixed memory zone handling. |
| 52 | */ |
Neil Armstrong | f0f3762 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 53 | if (IS_ENABLED(CONFIG_MESON_GX) && |
Neil Armstrong | c7be3e5 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 54 | !reg && !bl31_start && !bl32_start) { |
| 55 | bl31_start = 0x10000000; |
| 56 | bl31_size = 0x200000; |
| 57 | } |
| 58 | |
| 59 | /* Add first 16MiB reserved zone */ |
Neil Armstrong | f0f3762 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 60 | meson_board_add_reserved_memory(fdt, 0, GX_FIRMWARE_MEM_SIZE); |
Neil Armstrong | c7be3e5 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 61 | |
| 62 | /* Add BL31 reserved zone */ |
| 63 | if (bl31_start && bl31_size) |
| 64 | meson_board_add_reserved_memory(fdt, bl31_start, bl31_size); |
| 65 | |
| 66 | /* Add BL32 reserved zone */ |
| 67 | if (bl32_start && bl32_size) |
| 68 | meson_board_add_reserved_memory(fdt, bl32_start, bl32_size); |
Maxime Jourdan | 0cc53fa | 2018-12-11 12:52:04 +0100 | [diff] [blame] | 69 | |
| 70 | #if defined(CONFIG_VIDEO_MESON) |
| 71 | meson_vpu_rsv_fb(fdt); |
| 72 | #endif |
Beniamino Galvani | bfcef28 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 73 | } |
| 74 | |
Jerome Brunet | 33e3378 | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 75 | phys_size_t get_effective_memsize(void) |
Beniamino Galvani | bfcef28 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 76 | { |
Jerome Brunet | 33e3378 | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 77 | /* Size is reported in MiB, convert it in bytes */ |
| 78 | return ((readl(GX_AO_SEC_GP_CFG0) & GX_AO_MEM_SIZE_MASK) |
| 79 | >> GX_AO_MEM_SIZE_SHIFT) * SZ_1M; |
Beniamino Galvani | bfcef28 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 80 | } |
| 81 | |
Neil Armstrong | f0f3762 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 82 | static struct mm_region gx_mem_map[] = { |
Beniamino Galvani | bfcef28 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 83 | { |
York Sun | cd4b0c5 | 2016-06-24 16:46:22 -0700 | [diff] [blame] | 84 | .virt = 0x0UL, |
| 85 | .phys = 0x0UL, |
Loic Devulder | c45414b | 2018-09-25 16:30:35 +0200 | [diff] [blame] | 86 | .size = 0xc0000000UL, |
Beniamino Galvani | bfcef28 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 87 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 88 | PTE_BLOCK_INNER_SHARE |
| 89 | }, { |
Loic Devulder | c45414b | 2018-09-25 16:30:35 +0200 | [diff] [blame] | 90 | .virt = 0xc0000000UL, |
| 91 | .phys = 0xc0000000UL, |
| 92 | .size = 0x30000000UL, |
Beniamino Galvani | bfcef28 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 93 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 94 | PTE_BLOCK_NON_SHARE | |
| 95 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 96 | }, { |
| 97 | /* List terminator */ |
| 98 | 0, |
| 99 | } |
| 100 | }; |
| 101 | |
Neil Armstrong | f0f3762 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 102 | struct mm_region *mem_map = gx_mem_map; |
Jerome Brunet | 33e3378 | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 103 | |
| 104 | /* Configure the Ethernet MAC with the requested interface mode |
| 105 | * with some optional flags. |
| 106 | */ |
| 107 | void meson_eth_init(phy_interface_t mode, unsigned int flags) |
| 108 | { |
| 109 | switch (mode) { |
| 110 | case PHY_INTERFACE_MODE_RGMII: |
| 111 | case PHY_INTERFACE_MODE_RGMII_ID: |
| 112 | case PHY_INTERFACE_MODE_RGMII_RXID: |
| 113 | case PHY_INTERFACE_MODE_RGMII_TXID: |
| 114 | /* Set RGMII mode */ |
| 115 | setbits_le32(GX_ETH_REG_0, GX_ETH_REG_0_PHY_INTF | |
| 116 | GX_ETH_REG_0_TX_PHASE(1) | |
| 117 | GX_ETH_REG_0_TX_RATIO(4) | |
| 118 | GX_ETH_REG_0_PHY_CLK_EN | |
| 119 | GX_ETH_REG_0_CLK_EN); |
| 120 | break; |
| 121 | |
| 122 | case PHY_INTERFACE_MODE_RMII: |
| 123 | /* Set RMII mode */ |
| 124 | out_le32(GX_ETH_REG_0, GX_ETH_REG_0_INVERT_RMII_CLK | |
| 125 | GX_ETH_REG_0_CLK_EN); |
| 126 | |
| 127 | /* Use GXL RMII Internal PHY */ |
| 128 | if (IS_ENABLED(CONFIG_MESON_GXL) && |
| 129 | (flags & MESON_USE_INTERNAL_RMII_PHY)) { |
| 130 | writel(0x10110181, GX_ETH_REG_2); |
| 131 | writel(0xe40908ff, GX_ETH_REG_3); |
| 132 | } |
| 133 | |
| 134 | break; |
| 135 | |
| 136 | default: |
| 137 | printf("Invalid Ethernet interface mode\n"); |
| 138 | return; |
| 139 | } |
| 140 | |
| 141 | /* Enable power gate */ |
| 142 | clrbits_le32(GX_MEM_PD_REG_0, GX_MEM_PD_REG_0_ETH_MASK); |
| 143 | } |