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