blob: bc9ef5e98b4f495fd4773e6f0b4bf75113f7c95e [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Kever Yang625ec502017-02-23 15:37:55 +08002/*
3 * (C) Copyright 2016 Rockchip Electronics Co., Ltd
Kever Yang625ec502017-02-23 15:37:55 +08004 */
5
6#include <common.h>
7#include <asm/armv8/mmu.h>
8#include <dwc3-uboot.h>
Kever Yangcc93c092017-06-08 15:32:05 +08009#include <power/regulator.h>
Kever Yang625ec502017-02-23 15:37:55 +080010#include <usb.h>
11
12DECLARE_GLOBAL_DATA_PTR;
13
14int board_init(void)
15{
Kever Yangcc93c092017-06-08 15:32:05 +080016 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 Yang625ec502017-02-23 15:37:55 +080023}
24
Meng Dongyangc93bef92017-06-28 19:22:44 +080025#if defined(CONFIG_USB_GADGET) && defined(CONFIG_USB_GADGET_DWC2_OTG)
26#include <usb.h>
27#include <usb/dwc2_udc.h>
28
29static 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 Yang625ec502017-02-23 15:37:55 +080035int board_usb_init(int index, enum usb_init_type init)
36{
Meng Dongyangc93bef92017-06-28 19:22:44 +080037 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
66int board_usb_cleanup(int index, enum usb_init_type init)
67{
Kever Yang625ec502017-02-23 15:37:55 +080068 return 0;
69}
Meng Dongyangc93bef92017-06-28 19:22:44 +080070#endif