]> Git Repo - J-u-boot.git/blob - arch/arm/mach-meson/board-gx.c
Merge tag 'for-v2020.07' of https://gitlab.denx.de/u-boot/custodians/u-boot-i2c
[J-u-boot.git] / arch / arm / mach-meson / board-gx.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 <asm/arch/boot.h>
10 #include <asm/arch/eth.h>
11 #include <asm/arch/gx.h>
12 #include <asm/arch/mem.h>
13 #include <asm/arch/meson-vpu.h>
14 #include <asm/io.h>
15 #include <asm/armv8/mmu.h>
16 #include <linux/sizes.h>
17 #include <usb.h>
18 #include <linux/usb/otg.h>
19 #include <asm/arch/usb-gx.h>
20 #include <usb/dwc2_udc.h>
21 #include <clk.h>
22 #include <phy.h>
23
24 DECLARE_GLOBAL_DATA_PTR;
25
26 int meson_get_boot_device(void)
27 {
28         return readl(GX_AO_SEC_GP_CFG0) & GX_AO_BOOT_DEVICE;
29 }
30
31 /* Configure the reserved memory zones exported by the secure registers
32  * into EFI and DTB reserved memory entries.
33  */
34 void meson_init_reserved_memory(void *fdt)
35 {
36         u64 bl31_size, bl31_start;
37         u64 bl32_size, bl32_start;
38         u32 reg;
39
40         /*
41          * Get ARM Trusted Firmware reserved memory zones in :
42          * - AO_SEC_GP_CFG3: bl32 & bl31 size in KiB, can be 0
43          * - AO_SEC_GP_CFG5: bl31 physical start address, can be NULL
44          * - AO_SEC_GP_CFG4: bl32 physical start address, can be NULL
45          */
46         reg = readl(GX_AO_SEC_GP_CFG3);
47
48         bl31_size = ((reg & GX_AO_BL31_RSVMEM_SIZE_MASK)
49                         >> GX_AO_BL31_RSVMEM_SIZE_SHIFT) * SZ_1K;
50         bl32_size = (reg & GX_AO_BL32_RSVMEM_SIZE_MASK) * SZ_1K;
51
52         bl31_start = readl(GX_AO_SEC_GP_CFG5);
53         bl32_start = readl(GX_AO_SEC_GP_CFG4);
54
55         /*
56          * Early Meson GX Firmware revisions did not provide the reserved
57          * memory zones in the registers, keep fixed memory zone handling.
58          */
59         if (IS_ENABLED(CONFIG_MESON_GX) &&
60             !reg && !bl31_start && !bl32_start) {
61                 bl31_start = 0x10000000;
62                 bl31_size = 0x200000;
63         }
64
65         /* Add first 16MiB reserved zone */
66         meson_board_add_reserved_memory(fdt, 0, GX_FIRMWARE_MEM_SIZE);
67
68         /* Add BL31 reserved zone */
69         if (bl31_start && bl31_size)
70                 meson_board_add_reserved_memory(fdt, bl31_start, bl31_size);
71
72         /* Add BL32 reserved zone */
73         if (bl32_start && bl32_size)
74                 meson_board_add_reserved_memory(fdt, bl32_start, bl32_size);
75
76 #if defined(CONFIG_VIDEO_MESON)
77         meson_vpu_rsv_fb(fdt);
78 #endif
79 }
80
81 phys_size_t get_effective_memsize(void)
82 {
83         /* Size is reported in MiB, convert it in bytes */
84         return ((readl(GX_AO_SEC_GP_CFG0) & GX_AO_MEM_SIZE_MASK)
85                         >> GX_AO_MEM_SIZE_SHIFT) * SZ_1M;
86 }
87
88 static struct mm_region gx_mem_map[] = {
89         {
90                 .virt = 0x0UL,
91                 .phys = 0x0UL,
92                 .size = 0xc0000000UL,
93                 .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) |
94                          PTE_BLOCK_INNER_SHARE
95         }, {
96                 .virt = 0xc0000000UL,
97                 .phys = 0xc0000000UL,
98                 .size = 0x30000000UL,
99                 .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) |
100                          PTE_BLOCK_NON_SHARE |
101                          PTE_BLOCK_PXN | PTE_BLOCK_UXN
102         }, {
103                 /* List terminator */
104                 0,
105         }
106 };
107
108 struct mm_region *mem_map = gx_mem_map;
109
110 /* Configure the Ethernet MAC with the requested interface mode
111  * with some optional flags.
112  */
113 void meson_eth_init(phy_interface_t mode, unsigned int flags)
114 {
115         switch (mode) {
116         case PHY_INTERFACE_MODE_RGMII:
117         case PHY_INTERFACE_MODE_RGMII_ID:
118         case PHY_INTERFACE_MODE_RGMII_RXID:
119         case PHY_INTERFACE_MODE_RGMII_TXID:
120                 /* Set RGMII mode */
121                 setbits_le32(GX_ETH_REG_0, GX_ETH_REG_0_PHY_INTF |
122                              GX_ETH_REG_0_TX_PHASE(1) |
123                              GX_ETH_REG_0_TX_RATIO(4) |
124                              GX_ETH_REG_0_PHY_CLK_EN |
125                              GX_ETH_REG_0_CLK_EN);
126
127                 /* Reset to external PHY */
128                 if(!IS_ENABLED(CONFIG_MESON_GXBB))
129                         writel(0x2009087f, GX_ETH_REG_3);
130
131                 break;
132
133         case PHY_INTERFACE_MODE_RMII:
134                 /* Set RMII mode */
135                 out_le32(GX_ETH_REG_0, GX_ETH_REG_0_INVERT_RMII_CLK |
136                                          GX_ETH_REG_0_CLK_EN);
137
138                 /* Use GXL RMII Internal PHY (also on GXM) */
139                 if (!IS_ENABLED(CONFIG_MESON_GXBB)) {
140                         if ((flags & MESON_USE_INTERNAL_RMII_PHY)) {
141                                 writel(0x10110181, GX_ETH_REG_2);
142                                 writel(0xe40908ff, GX_ETH_REG_3);
143                         } else
144                                 writel(0x2009087f, GX_ETH_REG_3);
145                 }
146
147                 break;
148
149         default:
150                 printf("Invalid Ethernet interface mode\n");
151                 return;
152         }
153
154         /* Enable power gate */
155         clrbits_le32(GX_MEM_PD_REG_0, GX_MEM_PD_REG_0_ETH_MASK);
156 }
157
158 #if CONFIG_IS_ENABLED(USB_XHCI_DWC3_OF_SIMPLE) && \
159         CONFIG_IS_ENABLED(USB_GADGET_DWC2_OTG)
160 static struct dwc2_plat_otg_data meson_gx_dwc2_data;
161 static struct phy usb_phys[2];
162
163 int board_usb_init(int index, enum usb_init_type init)
164 {
165         struct ofnode_phandle_args args;
166         struct udevice *clk_dev;
167         ofnode dwc2_node;
168         struct clk clk;
169         int ret, i;
170         u32 val;
171
172         /* find the dwc2 node */
173         dwc2_node = ofnode_by_compatible(ofnode_null(), "snps,dwc2");
174         if (!ofnode_valid(dwc2_node)) {
175                 debug("Not found dwc2 node\n");
176                 return -ENODEV;
177         }
178
179         if (!ofnode_is_available(dwc2_node)) {
180                 debug("dwc2 is disabled in the device tree\n");
181                 return -ENODEV;
182         }
183
184         /* get the PHYs */
185         for (i = 0; i < 2; i++) {
186                 ret = generic_phy_get_by_node(dwc2_node, i, &usb_phys[i]);
187                 if (ret && ret != -ENOENT) {
188                         pr_err("Failed to get USB PHY%d for %s\n",
189                                i, ofnode_get_name(dwc2_node));
190                         return ret;
191                 }
192         }
193
194         for (i = 0; i < 2; i++) {
195                 ret = generic_phy_init(&usb_phys[i]);
196                 if (ret) {
197                         pr_err("Can't init USB PHY%d for %s\n",
198                                i, ofnode_get_name(dwc2_node));
199                         return ret;
200                 }
201         }
202
203         for (i = 0; i < 2; i++) {
204                 ret = generic_phy_power_on(&usb_phys[i]);
205                 if (ret) {
206                         pr_err("Can't power USB PHY%d for %s\n",
207                                i, ofnode_get_name(dwc2_node));
208                         return ret;
209                 }
210         }
211
212         phy_meson_gxl_usb3_set_mode(&usb_phys[0], USB_DR_MODE_PERIPHERAL);
213         phy_meson_gxl_usb2_set_mode(&usb_phys[1], USB_DR_MODE_PERIPHERAL);
214
215         meson_gx_dwc2_data.regs_otg = ofnode_get_addr(dwc2_node);
216         if (meson_gx_dwc2_data.regs_otg == FDT_ADDR_T_NONE) {
217                 debug("usbotg: can't get base address\n");
218                 return -ENODATA;
219         }
220
221         /* Enable clock */
222         ret = ofnode_parse_phandle_with_args(dwc2_node, "clocks",
223                                              "#clock-cells", 0, 0, &args);
224         if (ret) {
225                 debug("usbotg has no clocks defined in the device tree\n");
226                 return ret;
227         }
228
229         ret = uclass_get_device_by_ofnode(UCLASS_CLK, args.node, &clk_dev);
230         if (ret)
231                 return ret;
232
233         if (args.args_count != 1) {
234                 debug("Can't find clock ID in the device tree\n");
235                 return -ENODATA;
236         }
237
238         clk.dev = clk_dev;
239         clk.id = args.args[0];
240
241         ret = clk_enable(&clk);
242         if (ret) {
243                 debug("Failed to enable usbotg clock\n");
244                 return ret;
245         }
246
247         ofnode_read_u32(dwc2_node, "g-rx-fifo-size", &val);
248         meson_gx_dwc2_data.rx_fifo_sz = val;
249         ofnode_read_u32(dwc2_node, "g-np-tx-fifo-size", &val);
250         meson_gx_dwc2_data.np_tx_fifo_sz = val;
251         ofnode_read_u32(dwc2_node, "g-tx-fifo-size", &val);
252         meson_gx_dwc2_data.tx_fifo_sz = val;
253
254         return dwc2_udc_probe(&meson_gx_dwc2_data);
255 }
256
257 int board_usb_cleanup(int index, enum usb_init_type init)
258 {
259         int i;
260
261         phy_meson_gxl_usb3_set_mode(&usb_phys[0], USB_DR_MODE_HOST);
262         phy_meson_gxl_usb2_set_mode(&usb_phys[1], USB_DR_MODE_HOST);
263
264         for (i = 0; i < 2; i++)
265                 usb_phys[i].dev = NULL;
266
267         return 0;
268 }
269 #endif
This page took 0.040102 seconds and 4 git commands to generate.