Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Beniamino Galvani | bfcef28 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2016 Beniamino Galvani <b.galvani@gmail.com> |
Jerome Brunet | 33e3378 | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 4 | * (C) Copyright 2018 Neil Armstrong <narmstrong@baylibre.com> |
Beniamino Galvani | bfcef28 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #include <common.h> |
Simon Glass | 9b4a205 | 2019-12-28 10:45:05 -0700 | [diff] [blame] | 8 | #include <init.h> |
Simon Glass | 90526e9 | 2020-05-10 11:39:56 -0600 | [diff] [blame] | 9 | #include <net.h> |
Neil Armstrong | d96a782 | 2018-07-27 14:10:00 +0200 | [diff] [blame] | 10 | #include <asm/arch/boot.h> |
Jerome Brunet | 33e3378 | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 11 | #include <asm/arch/eth.h> |
Neil Armstrong | f0f3762 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 12 | #include <asm/arch/gx.h> |
Jerome Brunet | 33e3378 | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 13 | #include <asm/arch/mem.h> |
Maxime Jourdan | 0cc53fa | 2018-12-11 12:52:04 +0100 | [diff] [blame] | 14 | #include <asm/arch/meson-vpu.h> |
Simon Glass | 401d1c4 | 2020-10-30 21:38:53 -0600 | [diff] [blame] | 15 | #include <asm/global_data.h> |
Neil Armstrong | c7be3e5 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 16 | #include <asm/io.h> |
Jerome Brunet | 33e3378 | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 17 | #include <asm/armv8/mmu.h> |
| 18 | #include <linux/sizes.h> |
Neil Armstrong | dc999e5 | 2020-03-30 11:27:25 +0200 | [diff] [blame] | 19 | #include <usb.h> |
| 20 | #include <linux/usb/otg.h> |
| 21 | #include <asm/arch/usb-gx.h> |
| 22 | #include <usb/dwc2_udc.h> |
| 23 | #include <clk.h> |
Jerome Brunet | 33e3378 | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 24 | #include <phy.h> |
Beniamino Galvani | bfcef28 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 25 | |
| 26 | DECLARE_GLOBAL_DATA_PTR; |
| 27 | |
Neil Armstrong | d96a782 | 2018-07-27 14:10:00 +0200 | [diff] [blame] | 28 | int meson_get_boot_device(void) |
| 29 | { |
| 30 | return readl(GX_AO_SEC_GP_CFG0) & GX_AO_BOOT_DEVICE; |
| 31 | } |
| 32 | |
Jerome Brunet | 33e3378 | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 33 | /* Configure the reserved memory zones exported by the secure registers |
| 34 | * into EFI and DTB reserved memory entries. |
| 35 | */ |
| 36 | void meson_init_reserved_memory(void *fdt) |
Neil Armstrong | c7be3e5 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 37 | { |
| 38 | u64 bl31_size, bl31_start; |
| 39 | u64 bl32_size, bl32_start; |
| 40 | u32 reg; |
| 41 | |
| 42 | /* |
| 43 | * Get ARM Trusted Firmware reserved memory zones in : |
| 44 | * - AO_SEC_GP_CFG3: bl32 & bl31 size in KiB, can be 0 |
| 45 | * - AO_SEC_GP_CFG5: bl31 physical start address, can be NULL |
| 46 | * - AO_SEC_GP_CFG4: bl32 physical start address, can be NULL |
| 47 | */ |
Neil Armstrong | f0f3762 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 48 | reg = readl(GX_AO_SEC_GP_CFG3); |
Neil Armstrong | c7be3e5 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 49 | |
Neil Armstrong | f0f3762 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 50 | bl31_size = ((reg & GX_AO_BL31_RSVMEM_SIZE_MASK) |
| 51 | >> GX_AO_BL31_RSVMEM_SIZE_SHIFT) * SZ_1K; |
| 52 | bl32_size = (reg & GX_AO_BL32_RSVMEM_SIZE_MASK) * SZ_1K; |
Neil Armstrong | c7be3e5 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 53 | |
Neil Armstrong | f0f3762 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 54 | bl31_start = readl(GX_AO_SEC_GP_CFG5); |
| 55 | bl32_start = readl(GX_AO_SEC_GP_CFG4); |
Neil Armstrong | c7be3e5 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 56 | |
| 57 | /* |
Neil Armstrong | f0f3762 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 58 | * Early Meson GX Firmware revisions did not provide the reserved |
Neil Armstrong | c7be3e5 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 59 | * memory zones in the registers, keep fixed memory zone handling. |
| 60 | */ |
Neil Armstrong | f0f3762 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 61 | if (IS_ENABLED(CONFIG_MESON_GX) && |
Neil Armstrong | c7be3e5 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 62 | !reg && !bl31_start && !bl32_start) { |
| 63 | bl31_start = 0x10000000; |
| 64 | bl31_size = 0x200000; |
| 65 | } |
| 66 | |
| 67 | /* Add first 16MiB reserved zone */ |
Neil Armstrong | f0f3762 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 68 | meson_board_add_reserved_memory(fdt, 0, GX_FIRMWARE_MEM_SIZE); |
Neil Armstrong | c7be3e5 | 2017-11-27 10:35:46 +0100 | [diff] [blame] | 69 | |
| 70 | /* Add BL31 reserved zone */ |
| 71 | if (bl31_start && bl31_size) |
| 72 | meson_board_add_reserved_memory(fdt, bl31_start, bl31_size); |
| 73 | |
| 74 | /* Add BL32 reserved zone */ |
| 75 | if (bl32_start && bl32_size) |
| 76 | meson_board_add_reserved_memory(fdt, bl32_start, bl32_size); |
Maxime Jourdan | 0cc53fa | 2018-12-11 12:52:04 +0100 | [diff] [blame] | 77 | |
| 78 | #if defined(CONFIG_VIDEO_MESON) |
| 79 | meson_vpu_rsv_fb(fdt); |
| 80 | #endif |
Beniamino Galvani | bfcef28 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 81 | } |
| 82 | |
Jerome Brunet | 33e3378 | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 83 | phys_size_t get_effective_memsize(void) |
Beniamino Galvani | bfcef28 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 84 | { |
Jerome Brunet | 33e3378 | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 85 | /* Size is reported in MiB, convert it in bytes */ |
| 86 | return ((readl(GX_AO_SEC_GP_CFG0) & GX_AO_MEM_SIZE_MASK) |
| 87 | >> GX_AO_MEM_SIZE_SHIFT) * SZ_1M; |
Beniamino Galvani | bfcef28 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 88 | } |
| 89 | |
Neil Armstrong | f0f3762 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 90 | static struct mm_region gx_mem_map[] = { |
Beniamino Galvani | bfcef28 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 91 | { |
York Sun | cd4b0c5 | 2016-06-24 16:46:22 -0700 | [diff] [blame] | 92 | .virt = 0x0UL, |
| 93 | .phys = 0x0UL, |
Loic Devulder | c45414b | 2018-09-25 16:30:35 +0200 | [diff] [blame] | 94 | .size = 0xc0000000UL, |
Beniamino Galvani | bfcef28 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 95 | .attrs = PTE_BLOCK_MEMTYPE(MT_NORMAL) | |
| 96 | PTE_BLOCK_INNER_SHARE |
| 97 | }, { |
Loic Devulder | c45414b | 2018-09-25 16:30:35 +0200 | [diff] [blame] | 98 | .virt = 0xc0000000UL, |
| 99 | .phys = 0xc0000000UL, |
| 100 | .size = 0x30000000UL, |
Beniamino Galvani | bfcef28 | 2016-05-08 08:30:16 +0200 | [diff] [blame] | 101 | .attrs = PTE_BLOCK_MEMTYPE(MT_DEVICE_NGNRNE) | |
| 102 | PTE_BLOCK_NON_SHARE | |
| 103 | PTE_BLOCK_PXN | PTE_BLOCK_UXN |
| 104 | }, { |
| 105 | /* List terminator */ |
| 106 | 0, |
| 107 | } |
| 108 | }; |
| 109 | |
Neil Armstrong | f0f3762 | 2018-04-11 17:13:45 +0200 | [diff] [blame] | 110 | struct mm_region *mem_map = gx_mem_map; |
Jerome Brunet | 33e3378 | 2018-10-05 17:00:37 +0200 | [diff] [blame] | 111 | |
Neil Armstrong | 7ccc737 | 2020-09-10 10:48:14 +0200 | [diff] [blame] | 112 | #if CONFIG_IS_ENABLED(USB_DWC3_MESON_GXL) && \ |
Neil Armstrong | dc999e5 | 2020-03-30 11:27:25 +0200 | [diff] [blame] | 113 | CONFIG_IS_ENABLED(USB_GADGET_DWC2_OTG) |
| 114 | static struct dwc2_plat_otg_data meson_gx_dwc2_data; |
Neil Armstrong | dc999e5 | 2020-03-30 11:27:25 +0200 | [diff] [blame] | 115 | |
| 116 | int board_usb_init(int index, enum usb_init_type init) |
| 117 | { |
Neil Armstrong | 7ccc737 | 2020-09-10 10:48:14 +0200 | [diff] [blame] | 118 | struct fdtdec_phandle_args args; |
| 119 | const void *blob = gd->fdt_blob; |
| 120 | int node, dwc2_node; |
| 121 | struct udevice *dev, *clk_dev; |
Neil Armstrong | dc999e5 | 2020-03-30 11:27:25 +0200 | [diff] [blame] | 122 | struct clk clk; |
Neil Armstrong | 7ccc737 | 2020-09-10 10:48:14 +0200 | [diff] [blame] | 123 | int ret; |
| 124 | |
| 125 | /* find the usb glue node */ |
| 126 | node = fdt_node_offset_by_compatible(blob, -1, |
| 127 | "amlogic,meson-gxl-usb-ctrl"); |
| 128 | if (node < 0) { |
| 129 | node = fdt_node_offset_by_compatible(blob, -1, |
| 130 | "amlogic,meson-gxm-usb-ctrl"); |
| 131 | if (node < 0) { |
| 132 | debug("Not found usb-control node\n"); |
| 133 | return -ENODEV; |
| 134 | } |
| 135 | } |
| 136 | |
| 137 | if (!fdtdec_get_is_enabled(blob, node)) { |
| 138 | debug("usb is disabled in the device tree\n"); |
| 139 | return -ENODEV; |
| 140 | } |
| 141 | |
| 142 | ret = uclass_get_device_by_of_offset(UCLASS_SIMPLE_BUS, node, &dev); |
| 143 | if (ret) { |
| 144 | debug("Not found usb-control device\n"); |
| 145 | return ret; |
| 146 | } |
Neil Armstrong | dc999e5 | 2020-03-30 11:27:25 +0200 | [diff] [blame] | 147 | |
| 148 | /* find the dwc2 node */ |
Neil Armstrong | 7ccc737 | 2020-09-10 10:48:14 +0200 | [diff] [blame] | 149 | dwc2_node = fdt_node_offset_by_compatible(blob, node, |
| 150 | "amlogic,meson-g12a-usb"); |
| 151 | if (dwc2_node < 0) { |
Neil Armstrong | dc999e5 | 2020-03-30 11:27:25 +0200 | [diff] [blame] | 152 | debug("Not found dwc2 node\n"); |
| 153 | return -ENODEV; |
| 154 | } |
| 155 | |
Neil Armstrong | 7ccc737 | 2020-09-10 10:48:14 +0200 | [diff] [blame] | 156 | if (!fdtdec_get_is_enabled(blob, dwc2_node)) { |
Neil Armstrong | dc999e5 | 2020-03-30 11:27:25 +0200 | [diff] [blame] | 157 | debug("dwc2 is disabled in the device tree\n"); |
| 158 | return -ENODEV; |
| 159 | } |
| 160 | |
Neil Armstrong | 7ccc737 | 2020-09-10 10:48:14 +0200 | [diff] [blame] | 161 | meson_gx_dwc2_data.regs_otg = fdtdec_get_addr(blob, dwc2_node, "reg"); |
Neil Armstrong | dc999e5 | 2020-03-30 11:27:25 +0200 | [diff] [blame] | 162 | if (meson_gx_dwc2_data.regs_otg == FDT_ADDR_T_NONE) { |
| 163 | debug("usbotg: can't get base address\n"); |
| 164 | return -ENODATA; |
| 165 | } |
| 166 | |
| 167 | /* Enable clock */ |
Neil Armstrong | 7ccc737 | 2020-09-10 10:48:14 +0200 | [diff] [blame] | 168 | ret = fdtdec_parse_phandle_with_args(blob, dwc2_node, "clocks", |
Neil Armstrong | dc999e5 | 2020-03-30 11:27:25 +0200 | [diff] [blame] | 169 | "#clock-cells", 0, 0, &args); |
| 170 | if (ret) { |
| 171 | debug("usbotg has no clocks defined in the device tree\n"); |
| 172 | return ret; |
| 173 | } |
| 174 | |
Neil Armstrong | 7ccc737 | 2020-09-10 10:48:14 +0200 | [diff] [blame] | 175 | ret = uclass_get_device_by_of_offset(UCLASS_CLK, args.node, &clk_dev); |
Neil Armstrong | dc999e5 | 2020-03-30 11:27:25 +0200 | [diff] [blame] | 176 | if (ret) |
| 177 | return ret; |
| 178 | |
| 179 | if (args.args_count != 1) { |
| 180 | debug("Can't find clock ID in the device tree\n"); |
| 181 | return -ENODATA; |
| 182 | } |
| 183 | |
| 184 | clk.dev = clk_dev; |
| 185 | clk.id = args.args[0]; |
| 186 | |
| 187 | ret = clk_enable(&clk); |
| 188 | if (ret) { |
| 189 | debug("Failed to enable usbotg clock\n"); |
| 190 | return ret; |
| 191 | } |
| 192 | |
Neil Armstrong | 7ccc737 | 2020-09-10 10:48:14 +0200 | [diff] [blame] | 193 | meson_gx_dwc2_data.rx_fifo_sz = fdtdec_get_int(blob, dwc2_node, |
| 194 | "g-rx-fifo-size", 0); |
| 195 | meson_gx_dwc2_data.np_tx_fifo_sz = fdtdec_get_int(blob, dwc2_node, |
| 196 | "g-np-tx-fifo-size", 0); |
| 197 | meson_gx_dwc2_data.tx_fifo_sz = fdtdec_get_int(blob, dwc2_node, |
| 198 | "g-tx-fifo-size", 0); |
| 199 | |
| 200 | /* Switch to peripheral mode */ |
| 201 | ret = dwc3_meson_gxl_force_mode(dev, USB_DR_MODE_PERIPHERAL); |
| 202 | if (ret) |
| 203 | return ret; |
Neil Armstrong | dc999e5 | 2020-03-30 11:27:25 +0200 | [diff] [blame] | 204 | |
| 205 | return dwc2_udc_probe(&meson_gx_dwc2_data); |
| 206 | } |
| 207 | |
| 208 | int board_usb_cleanup(int index, enum usb_init_type init) |
| 209 | { |
Neil Armstrong | 7ccc737 | 2020-09-10 10:48:14 +0200 | [diff] [blame] | 210 | const void *blob = gd->fdt_blob; |
| 211 | struct udevice *dev; |
| 212 | int node; |
| 213 | int ret; |
Neil Armstrong | dc999e5 | 2020-03-30 11:27:25 +0200 | [diff] [blame] | 214 | |
Neil Armstrong | 7ccc737 | 2020-09-10 10:48:14 +0200 | [diff] [blame] | 215 | /* find the usb glue node */ |
| 216 | node = fdt_node_offset_by_compatible(blob, -1, |
| 217 | "amlogic,meson-gxl-usb-ctrl"); |
| 218 | if (node < 0) { |
| 219 | node = fdt_node_offset_by_compatible(blob, -1, |
| 220 | "amlogic,meson-gxm-usb-ctrl"); |
| 221 | if (node < 0) { |
| 222 | debug("Not found usb-control node\n"); |
| 223 | return -ENODEV; |
| 224 | } |
| 225 | } |
Neil Armstrong | dc999e5 | 2020-03-30 11:27:25 +0200 | [diff] [blame] | 226 | |
Neil Armstrong | 7ccc737 | 2020-09-10 10:48:14 +0200 | [diff] [blame] | 227 | if (!fdtdec_get_is_enabled(blob, node)) |
| 228 | return -ENODEV; |
| 229 | |
| 230 | ret = uclass_get_device_by_of_offset(UCLASS_SIMPLE_BUS, node, &dev); |
| 231 | if (ret) |
| 232 | return ret; |
| 233 | |
| 234 | /* Switch to OTG mode */ |
| 235 | ret = dwc3_meson_gxl_force_mode(dev, USB_DR_MODE_HOST); |
| 236 | if (ret) |
| 237 | return ret; |
Neil Armstrong | dc999e5 | 2020-03-30 11:27:25 +0200 | [diff] [blame] | 238 | |
| 239 | return 0; |
| 240 | } |
| 241 | #endif |