ARM: meson: rework soc arch file to prepare for new SoC
[oweals/u-boot.git] / arch / arm / mach-meson / board-gx.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2016 Beniamino Galvani <b.galvani@gmail.com>
4  * (C) Copyright 2018 Neil Armstrong <narmstrong@baylibre.com>
5  */
6
7 #include <common.h>
8 #include <asm/arch/eth.h>
9 #include <asm/arch/gx.h>
10 #include <asm/arch/mem.h>
11 #include <asm/io.h>
12 #include <asm/armv8/mmu.h>
13 #include <linux/sizes.h>
14 #include <phy.h>
15
16 DECLARE_GLOBAL_DATA_PTR;
17
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)
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          */
33         reg = readl(GX_AO_SEC_GP_CFG3);
34
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;
38
39         bl31_start = readl(GX_AO_SEC_GP_CFG5);
40         bl32_start = readl(GX_AO_SEC_GP_CFG4);
41
42         /*
43          * Early Meson GX Firmware revisions did not provide the reserved
44          * memory zones in the registers, keep fixed memory zone handling.
45          */
46         if (IS_ENABLED(CONFIG_MESON_GX) &&
47             !reg && !bl31_start && !bl32_start) {
48                 bl31_start = 0x10000000;
49                 bl31_size = 0x200000;
50         }
51
52         /* Add first 16MiB reserved zone */
53         meson_board_add_reserved_memory(fdt, 0, GX_FIRMWARE_MEM_SIZE);
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);
62 }
63
64 phys_size_t get_effective_memsize(void)
65 {
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;
69 }
70
71 static struct mm_region gx_mem_map[] = {
72         {
73                 .virt = 0x0UL,
74                 .phys = 0x0UL,
75                 .size = 0xc0000000UL,
76                 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
77                          PTE_BLOCK_INNER_SHARE
78         }, {
79                 .virt = 0xc0000000UL,
80                 .phys = 0xc0000000UL,
81                 .size = 0x30000000UL,
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
91 struct mm_region *mem_map = gx_mem_map;
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 }