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