Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame^] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Kever Yang | 975a2ab | 2017-02-23 15:37:55 +0800 | [diff] [blame] | 2 | /* |
| 3 | * (C) Copyright 2016 Rockchip Electronics Co., Ltd |
Kever Yang | 975a2ab | 2017-02-23 15:37:55 +0800 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <asm/armv8/mmu.h> |
| 8 | #include <dwc3-uboot.h> |
Kever Yang | 0d5967d | 2017-06-08 15:32:05 +0800 | [diff] [blame] | 9 | #include <power/regulator.h> |
Kever Yang | 975a2ab | 2017-02-23 15:37:55 +0800 | [diff] [blame] | 10 | #include <usb.h> |
| 11 | |
| 12 | DECLARE_GLOBAL_DATA_PTR; |
| 13 | |
| 14 | int board_init(void) |
| 15 | { |
Kever Yang | 0d5967d | 2017-06-08 15:32:05 +0800 | [diff] [blame] | 16 | int ret; |
| 17 | |
| 18 | ret = regulators_enable_boot_on(false); |
| 19 | if (ret) |
| 20 | debug("%s: Cannot enable boot on regulator\n", __func__); |
| 21 | |
| 22 | return ret; |
Kever Yang | 975a2ab | 2017-02-23 15:37:55 +0800 | [diff] [blame] | 23 | } |
| 24 | |
Meng Dongyang | f8ef72c | 2017-06-28 19:22:44 +0800 | [diff] [blame] | 25 | #if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG) |
| 26 | #include <usb.h> |
| 27 | #include <usb/dwc2_udc.h> |
| 28 | |
| 29 | static struct dwc2_plat_otg_data rk3328_otg_data = { |
| 30 | .rx_fifo_sz = 512, |
| 31 | .np_tx_fifo_sz = 16, |
| 32 | .tx_fifo_sz = 128, |
| 33 | }; |
| 34 | |
Kever Yang | 975a2ab | 2017-02-23 15:37:55 +0800 | [diff] [blame] | 35 | int board_usb_init(int index, enum usb_init_type init) |
| 36 | { |
Meng Dongyang | f8ef72c | 2017-06-28 19:22:44 +0800 | [diff] [blame] | 37 | int node; |
| 38 | const char *mode; |
| 39 | bool matched = false; |
| 40 | const void *blob = gd->fdt_blob; |
| 41 | |
| 42 | /* find the usb_otg node */ |
| 43 | node = fdt_node_offset_by_compatible(blob, -1, |
| 44 | "rockchip,rk3328-usb"); |
| 45 | |
| 46 | while (node > 0) { |
| 47 | mode = fdt_getprop(blob, node, "dr_mode", NULL); |
| 48 | if (mode && strcmp(mode, "otg") == 0) { |
| 49 | matched = true; |
| 50 | break; |
| 51 | } |
| 52 | |
| 53 | node = fdt_node_offset_by_compatible(blob, node, |
| 54 | "rockchip,rk3328-usb"); |
| 55 | } |
| 56 | if (!matched) { |
| 57 | debug("Not found usb_otg device\n"); |
| 58 | return -ENODEV; |
| 59 | } |
| 60 | |
| 61 | rk3328_otg_data.regs_otg = fdtdec_get_addr(blob, node, "reg"); |
| 62 | |
| 63 | return dwc2_udc_probe(&rk3328_otg_data); |
| 64 | } |
| 65 | |
| 66 | int board_usb_cleanup(int index, enum usb_init_type init) |
| 67 | { |
Kever Yang | 975a2ab | 2017-02-23 15:37:55 +0800 | [diff] [blame] | 68 | return 0; |
| 69 | } |
Meng Dongyang | f8ef72c | 2017-06-28 19:22:44 +0800 | [diff] [blame] | 70 | #endif |