]> Git Repo - u-boot.git/blob - arch/arm/mach-meson/board-g12a.c
common: Drop net.h from common header
[u-boot.git] / arch / arm / mach-meson / board-g12a.c
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2016 Beniamino Galvani <[email protected]>
4  * (C) Copyright 2018 Neil Armstrong <[email protected]>
5  */
6
7 #include <common.h>
8 #include <init.h>
9 #include <net.h>
10 #include <asm/arch/boot.h>
11 #include <asm/arch/eth.h>
12 #include <asm/arch/g12a.h>
13 #include <asm/arch/mem.h>
14 #include <asm/arch/meson-vpu.h>
15 #include <asm/io.h>
16 #include <asm/armv8/mmu.h>
17 #include <linux/sizes.h>
18 #include <usb.h>
19 #include <linux/usb/otg.h>
20 #include <asm/arch/usb.h>
21 #include <usb/dwc2_udc.h>
22 #include <phy.h>
23 #include <clk.h>
24
25 DECLARE_GLOBAL_DATA_PTR;
26
27 int meson_get_boot_device(void)
28 {
29         return readl(G12A_AO_SEC_GP_CFG0) & G12A_AO_BOOT_DEVICE;
30 }
31
32 /* Configure the reserved memory zones exported by the secure registers
33  * into EFI and DTB reserved memory entries.
34  */
35 void meson_init_reserved_memory(void *fdt)
36 {
37         u64 bl31_size, bl31_start;
38         u64 bl32_size, bl32_start;
39         u32 reg;
40
41         /*
42          * Get ARM Trusted Firmware reserved memory zones in :
43          * - AO_SEC_GP_CFG3: bl32 & bl31 size in KiB, can be 0
44          * - AO_SEC_GP_CFG5: bl31 physical start address, can be NULL
45          * - AO_SEC_GP_CFG4: bl32 physical start address, can be NULL
46          */
47         reg = readl(G12A_AO_SEC_GP_CFG3);
48
49         bl31_size = ((reg & G12A_AO_BL31_RSVMEM_SIZE_MASK)
50                         >> G12A_AO_BL31_RSVMEM_SIZE_SHIFT) * SZ_1K;
51         bl32_size = (reg & G12A_AO_BL32_RSVMEM_SIZE_MASK) * SZ_1K;
52
53         bl31_start = readl(G12A_AO_SEC_GP_CFG5);
54         bl32_start = readl(G12A_AO_SEC_GP_CFG4);
55
56         /* Add BL31 reserved zone */
57         if (bl31_start && bl31_size)
58                 meson_board_add_reserved_memory(fdt, bl31_start, bl31_size);
59
60         /* Add BL32 reserved zone */
61         if (bl32_start && bl32_size)
62                 meson_board_add_reserved_memory(fdt, bl32_start, bl32_size);
63
64 #if defined(CONFIG_VIDEO_MESON)
65         meson_vpu_rsv_fb(fdt);
66 #endif
67 }
68
69 phys_size_t get_effective_memsize(void)
70 {
71         /* Size is reported in MiB, convert it in bytes */
72         return min(((readl(G12A_AO_SEC_GP_CFG0) & G12A_AO_MEM_SIZE_MASK)
73                         >> G12A_AO_MEM_SIZE_SHIFT) * SZ_1M, 0xf5000000);
74 }
75
76 static struct mm_region g12a_mem_map[] = {
77         {
78                 .virt = 0x0UL,
79                 .phys = 0x0UL,
80                 .size = 0xf5000000UL,
81                 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
82                          PTE_BLOCK_INNER_SHARE
83         }, {
84                 .virt = 0xf5000000UL,
85                 .phys = 0xf5000000UL,
86                 .size = 0x0b000000UL,
87                 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
88                          PTE_BLOCK_NON_SHARE |
89                          PTE_BLOCK_PXN | PTE_BLOCK_UXN
90         }, {
91                 /* List terminator */
92                 0,
93         }
94 };
95
96 struct mm_region *mem_map = g12a_mem_map;
97
98 static void g12a_enable_external_mdio(void)
99 {
100         writel(0x0, ETH_PHY_CNTL2);
101 }
102
103 static void g12a_enable_internal_mdio(void)
104 {
105         /* Fire up the PHY PLL */
106         writel(0x29c0040a, ETH_PLL_CNTL0);
107         writel(0x927e0000, ETH_PLL_CNTL1);
108         writel(0xac5f49e5, ETH_PLL_CNTL2);
109         writel(0x00000000, ETH_PLL_CNTL3);
110         writel(0x00000000, ETH_PLL_CNTL4);
111         writel(0x20200000, ETH_PLL_CNTL5);
112         writel(0x0000c002, ETH_PLL_CNTL6);
113         writel(0x00000023, ETH_PLL_CNTL7);
114         writel(0x39c0040a, ETH_PLL_CNTL0);
115         writel(0x19c0040a, ETH_PLL_CNTL0);
116
117         /* Select the internal MDIO */
118         writel(0x33000180, ETH_PHY_CNTL0);
119         writel(0x00074043, ETH_PHY_CNTL1);
120         writel(0x00000260, ETH_PHY_CNTL2);
121 }
122
123 /* Configure the Ethernet MAC with the requested interface mode
124  * with some optional flags.
125  */
126 void meson_eth_init(phy_interface_t mode, unsigned int flags)
127 {
128         switch (mode) {
129         case PHY_INTERFACE_MODE_RGMII:
130         case PHY_INTERFACE_MODE_RGMII_ID:
131         case PHY_INTERFACE_MODE_RGMII_RXID:
132         case PHY_INTERFACE_MODE_RGMII_TXID:
133                 /* Set RGMII mode */
134                 setbits_le32(G12A_ETH_REG_0, G12A_ETH_REG_0_PHY_INTF_RGMII |
135                              G12A_ETH_REG_0_TX_PHASE(1) |
136                              G12A_ETH_REG_0_TX_RATIO(4) |
137                              G12A_ETH_REG_0_PHY_CLK_EN |
138                              G12A_ETH_REG_0_CLK_EN);
139                 g12a_enable_external_mdio();
140                 break;
141
142         case PHY_INTERFACE_MODE_RMII:
143                 /* Set RMII mode */
144                 out_le32(G12A_ETH_REG_0, G12A_ETH_REG_0_PHY_INTF_RMII |
145                                         G12A_ETH_REG_0_INVERT_RMII_CLK |
146                                         G12A_ETH_REG_0_CLK_EN);
147
148                 /* Use G12A RMII Internal PHY */
149                 if (flags & MESON_USE_INTERNAL_RMII_PHY)
150                         g12a_enable_internal_mdio();
151                 else
152                         g12a_enable_external_mdio();
153
154                 break;
155
156         default:
157                 printf("Invalid Ethernet interface mode\n");
158                 return;
159         }
160
161         /* Enable power gate */
162         clrbits_le32(G12A_MEM_PD_REG_0, G12A_MEM_PD_REG_0_ETH_MASK);
163 }
164
165 #if CONFIG_IS_ENABLED(USB_DWC3_MESON_G12A) && \
166         CONFIG_IS_ENABLED(USB_GADGET_DWC2_OTG)
167 static struct dwc2_plat_otg_data meson_g12a_dwc2_data;
168
169 int board_usb_init(int index, enum usb_init_type init)
170 {
171         struct fdtdec_phandle_args args;
172         const void *blob = gd->fdt_blob;
173         int node, dwc2_node;
174         struct udevice *dev, *clk_dev;
175         struct clk clk;
176         int ret;
177
178         /* find the usb glue node */
179         node = fdt_node_offset_by_compatible(blob, -1,
180                                              "amlogic,meson-g12a-usb-ctrl");
181         if (node < 0) {
182                 debug("Not found usb-control node\n");
183                 return -ENODEV;
184         }
185
186         if (!fdtdec_get_is_enabled(blob, node)) {
187                 debug("usb is disabled in the device tree\n");
188                 return -ENODEV;
189         }
190
191         ret = uclass_get_device_by_of_offset(UCLASS_SIMPLE_BUS, node, &dev);
192         if (ret) {
193                 debug("Not found usb-control device\n");
194                 return ret;
195         }
196
197         /* find the dwc2 node */
198         dwc2_node = fdt_node_offset_by_compatible(blob, node,
199                                                   "amlogic,meson-g12a-usb");
200         if (dwc2_node < 0) {
201                 debug("Not found dwc2 node\n");
202                 return -ENODEV;
203         }
204
205         if (!fdtdec_get_is_enabled(blob, dwc2_node)) {
206                 debug("dwc2 is disabled in the device tree\n");
207                 return -ENODEV;
208         }
209
210         meson_g12a_dwc2_data.regs_otg = fdtdec_get_addr(blob, dwc2_node, "reg");
211         if (meson_g12a_dwc2_data.regs_otg == FDT_ADDR_T_NONE) {
212                 debug("usbotg: can't get base address\n");
213                 return -ENODATA;
214         }
215
216         /* Enable clock */
217         ret = fdtdec_parse_phandle_with_args(blob, dwc2_node, "clocks",
218                                              "#clock-cells", 0, 0, &args);
219         if (ret) {
220                 debug("usbotg has no clocks defined in the device tree\n");
221                 return ret;
222         }
223
224         ret = uclass_get_device_by_of_offset(UCLASS_CLK, args.node, &clk_dev);
225         if (ret)
226                 return ret;
227
228         if (args.args_count != 1) {
229                 debug("Can't find clock ID in the device tree\n");
230                 return -ENODATA;
231         }
232
233         clk.dev = clk_dev;
234         clk.id = args.args[0];
235
236         ret = clk_enable(&clk);
237         if (ret) {
238                 debug("Failed to enable usbotg clock\n");
239                 return ret;
240         }
241
242         meson_g12a_dwc2_data.rx_fifo_sz = fdtdec_get_int(blob, dwc2_node,
243                                                      "g-rx-fifo-size", 0);
244         meson_g12a_dwc2_data.np_tx_fifo_sz = fdtdec_get_int(blob, dwc2_node,
245                                                         "g-np-tx-fifo-size", 0);
246         meson_g12a_dwc2_data.tx_fifo_sz = fdtdec_get_int(blob, dwc2_node,
247                                                      "g-tx-fifo-size", 0);
248
249         /* Switch to peripheral mode */
250         ret = dwc3_meson_g12a_force_mode(dev, USB_DR_MODE_PERIPHERAL);
251         if (ret)
252                 return ret;
253
254         return dwc2_udc_probe(&meson_g12a_dwc2_data);
255 }
256
257 int board_usb_cleanup(int index, enum usb_init_type init)
258 {
259         const void *blob = gd->fdt_blob;
260         struct udevice *dev;
261         int node;
262         int ret;
263
264         /* find the usb glue node */
265         node = fdt_node_offset_by_compatible(blob, -1,
266                                              "amlogic,meson-g12a-usb-ctrl");
267         if (node < 0)
268                 return -ENODEV;
269
270         if (!fdtdec_get_is_enabled(blob, node))
271                 return -ENODEV;
272
273         ret = uclass_get_device_by_of_offset(UCLASS_SIMPLE_BUS, node, &dev);
274         if (ret)
275                 return ret;
276
277         /* Switch to OTG mode */
278         ret = dwc3_meson_g12a_force_mode(dev, USB_DR_MODE_HOST);
279         if (ret)
280                 return ret;
281
282         return 0;
283 }
284 #endif
This page took 0.043119 seconds and 4 git commands to generate.