1 // SPDX-License-Identifier: GPL-2.0+
2 /*
3  * (C) Copyright 2016 Rockchip Electronics Co., Ltd
4  */
5 
6 #include <common.h>
7 #include <asm/armv8/mmu.h>
8 #include <dwc3-uboot.h>
9 #include <power/regulator.h>
10 #include <usb.h>
11 
12 DECLARE_GLOBAL_DATA_PTR;
13 
14 int board_init(void)
15 {
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;
23 }
24 
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 
35 int board_usb_init(int index, enum usb_init_type init)
36 {
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 {
68 	return 0;
69 }
70 #endif
71