blob: f1397f87c5b643d53ff276602cb00c50d0eb3fbf [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Beniamino Galvanid1037e42016-05-08 08:30:16 +02002/*
3 * (C) Copyright 2016 Beniamino Galvani <b.galvani@gmail.com>
Jerome Brunetf897c4b2018-10-05 17:00:37 +02004 * (C) Copyright 2018 Neil Armstrong <narmstrong@baylibre.com>
Beniamino Galvanid1037e42016-05-08 08:30:16 +02005 */
6
7#include <common.h>
Jerome Brunetf897c4b2018-10-05 17:00:37 +02008#include <asm/arch/eth.h>
Neil Armstrong6e89d922018-04-11 17:13:45 +02009#include <asm/arch/gx.h>
Jerome Brunetf897c4b2018-10-05 17:00:37 +020010#include <asm/arch/mem.h>
11#include <asm/io.h>
Beniamino Galvanid1037e42016-05-08 08:30:16 +020012#include <asm/armv8/mmu.h>
Neil Armstrong8b245692017-11-27 10:35:46 +010013#include <linux/sizes.h>
Jerome Brunetf897c4b2018-10-05 17:00:37 +020014#include <phy.h>
Beniamino Galvanid1037e42016-05-08 08:30:16 +020015
16DECLARE_GLOBAL_DATA_PTR;
17
Jerome Brunetf897c4b2018-10-05 17:00:37 +020018/* Configure the reserved memory zones exported by the secure registers
19 * into EFI and DTB reserved memory entries.
20 */
21void meson_init_reserved_memory(void *fdt)
Neil Armstrong8b245692017-11-27 10:35:46 +010022{
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 Armstrong6e89d922018-04-11 17:13:45 +020033 reg = readl(GX_AO_SEC_GP_CFG3);
Neil Armstrong8b245692017-11-27 10:35:46 +010034
Neil Armstrong6e89d922018-04-11 17:13:45 +020035 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 Armstrong8b245692017-11-27 10:35:46 +010038
Neil Armstrong6e89d922018-04-11 17:13:45 +020039 bl31_start = readl(GX_AO_SEC_GP_CFG5);
40 bl32_start = readl(GX_AO_SEC_GP_CFG4);
Neil Armstrong8b245692017-11-27 10:35:46 +010041
42 /*
Neil Armstrong6e89d922018-04-11 17:13:45 +020043 * Early Meson GX Firmware revisions did not provide the reserved
Neil Armstrong8b245692017-11-27 10:35:46 +010044 * memory zones in the registers, keep fixed memory zone handling.
45 */
Neil Armstrong6e89d922018-04-11 17:13:45 +020046 if (IS_ENABLED(CONFIG_MESON_GX) &&
Neil Armstrong8b245692017-11-27 10:35:46 +010047 !reg && !bl31_start && !bl32_start) {
48 bl31_start = 0x10000000;
49 bl31_size = 0x200000;
50 }
51
52 /* Add first 16MiB reserved zone */
Neil Armstrong6e89d922018-04-11 17:13:45 +020053 meson_board_add_reserved_memory(fdt, 0, GX_FIRMWARE_MEM_SIZE);
Neil Armstrong8b245692017-11-27 10:35:46 +010054
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 Galvanid1037e42016-05-08 08:30:16 +020062}
63
Jerome Brunetf897c4b2018-10-05 17:00:37 +020064phys_size_t get_effective_memsize(void)
Beniamino Galvanid1037e42016-05-08 08:30:16 +020065{
Jerome Brunetf897c4b2018-10-05 17:00:37 +020066 /* 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 Galvanid1037e42016-05-08 08:30:16 +020069}
70
Neil Armstrong6e89d922018-04-11 17:13:45 +020071static struct mm_region gx_mem_map[] = {
Beniamino Galvanid1037e42016-05-08 08:30:16 +020072 {
York Sunc7104e52016-06-24 16:46:22 -070073 .virt = 0x0UL,
74 .phys = 0x0UL,
Loic Devulderc067c582018-09-25 16:30:35 +020075 .size = 0xc0000000UL,
Beniamino Galvanid1037e42016-05-08 08:30:16 +020076 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
77 PTE_BLOCK_INNER_SHARE
78 }, {
Loic Devulderc067c582018-09-25 16:30:35 +020079 .virt = 0xc0000000UL,
80 .phys = 0xc0000000UL,
81 .size = 0x30000000UL,
Beniamino Galvanid1037e42016-05-08 08:30:16 +020082 .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 Armstrong6e89d922018-04-11 17:13:45 +020091struct mm_region *mem_map = gx_mem_map;
Jerome Brunetf897c4b2018-10-05 17:00:37 +020092
93/* Configure the Ethernet MAC with the requested interface mode
94 * with some optional flags.
95 */
96void 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}