Otavio Salvador | 374dfcd | 2018-11-30 11:34:15 -0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * (C) Copyright 2015 Google, Inc |
| 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | |
| 8 | DECLARE_GLOBAL_DATA_PTR; |
| 9 | |
| 10 | #if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG) |
| 11 | #include <usb.h> |
| 12 | #include <usb/dwc2_udc.h> |
| 13 | |
Kever Yang | 3f4a2a7 | 2019-07-22 20:02:00 +0800 | [diff] [blame] | 14 | static struct dwc2_plat_otg_data otg_data = { |
Otavio Salvador | 374dfcd | 2018-11-30 11:34:15 -0200 | [diff] [blame] | 15 | .rx_fifo_sz = 512, |
| 16 | .np_tx_fifo_sz = 16, |
| 17 | .tx_fifo_sz = 128, |
| 18 | }; |
| 19 | |
| 20 | int board_usb_init(int index, enum usb_init_type init) |
| 21 | { |
Kever Yang | 3f4a2a7 | 2019-07-22 20:02:00 +0800 | [diff] [blame] | 22 | int node; |
Otavio Salvador | 374dfcd | 2018-11-30 11:34:15 -0200 | [diff] [blame] | 23 | const char *mode; |
Kever Yang | 3f4a2a7 | 2019-07-22 20:02:00 +0800 | [diff] [blame] | 24 | bool matched = false; |
| 25 | const void *blob = gd->fdt_blob; |
Otavio Salvador | 374dfcd | 2018-11-30 11:34:15 -0200 | [diff] [blame] | 26 | |
| 27 | /* find the usb_otg node */ |
Kever Yang | 3f4a2a7 | 2019-07-22 20:02:00 +0800 | [diff] [blame] | 28 | node = fdt_node_offset_by_compatible(blob, -1, "snps,dwc2"); |
| 29 | |
Otavio Salvador | 374dfcd | 2018-11-30 11:34:15 -0200 | [diff] [blame] | 30 | while (node > 0) { |
| 31 | mode = fdt_getprop(blob, node, "dr_mode", NULL); |
| 32 | if (mode && strcmp(mode, "otg") == 0) { |
| 33 | matched = true; |
| 34 | break; |
| 35 | } |
| 36 | |
Kever Yang | 3f4a2a7 | 2019-07-22 20:02:00 +0800 | [diff] [blame] | 37 | node = fdt_node_offset_by_compatible(blob, node, "snps,dwc2"); |
Otavio Salvador | 374dfcd | 2018-11-30 11:34:15 -0200 | [diff] [blame] | 38 | } |
Otavio Salvador | 374dfcd | 2018-11-30 11:34:15 -0200 | [diff] [blame] | 39 | if (!matched) { |
Kever Yang | 3f4a2a7 | 2019-07-22 20:02:00 +0800 | [diff] [blame] | 40 | debug("Not found usb_otg device\n"); |
Otavio Salvador | 374dfcd | 2018-11-30 11:34:15 -0200 | [diff] [blame] | 41 | return -ENODEV; |
| 42 | } |
Kever Yang | 3f4a2a7 | 2019-07-22 20:02:00 +0800 | [diff] [blame] | 43 | otg_data.regs_otg = fdtdec_get_addr(blob, node, "reg"); |
Otavio Salvador | 374dfcd | 2018-11-30 11:34:15 -0200 | [diff] [blame] | 44 | |
Kever Yang | 3f4a2a7 | 2019-07-22 20:02:00 +0800 | [diff] [blame] | 45 | return dwc2_udc_probe(&otg_data); |
Otavio Salvador | 374dfcd | 2018-11-30 11:34:15 -0200 | [diff] [blame] | 46 | } |
| 47 | |
| 48 | int board_usb_cleanup(int index, enum usb_init_type init) |
| 49 | { |
| 50 | return 0; |
| 51 | } |
| 52 | #endif |