ARM: rockchip: rv1108: Add a board_usb_init for USB OTG
[oweals/u-boot.git] / arch / arm / mach-rockchip / rv1108-board.c
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
14 static struct dwc2_plat_otg_data rv1108_otg_data = {
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 {
22         const void *blob = gd->fdt_blob;
23         bool matched = false;
24         int node, phy_node;
25         u32 grf_phy_offset;
26         const char *mode;
27
28         /* find the usb_otg node */
29         node = fdt_node_offset_by_compatible(blob, -1, "rockchip,rk3066-usb");
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
37                 node = fdt_node_offset_by_compatible(blob, node,
38                                                      "rockchip,rk3066-usb");
39         }
40
41         if (!matched) {
42                 debug("usb_otg device not found\n");
43                 return -ENODEV;
44         }
45
46         rv1108_otg_data.regs_otg = fdtdec_get_addr(blob, node, "reg");
47
48         node = fdtdec_lookup_phandle(blob, node, "phys");
49         if (node <= 0) {
50                 debug("phys node not found\n");
51                 return -ENODEV;
52         }
53
54         phy_node = fdt_parent_offset(blob, node);
55         if (phy_node <= 0) {
56                 debug("usb phy node not found\n");
57                 return -ENODEV;
58         }
59
60         rv1108_otg_data.phy_of_node = phy_node;
61         grf_phy_offset = fdtdec_get_addr(blob, node, "reg");
62
63         /* find the grf node */
64         node = fdt_node_offset_by_compatible(blob, -1,
65                                              "rockchip,rv1108-grf");
66         if (node <= 0) {
67                 debug("grf node not found\n");
68                 return -ENODEV;
69         }
70
71         rv1108_otg_data.regs_phy = grf_phy_offset + fdtdec_get_addr(blob, node,
72                                                                     "reg");
73
74         return dwc2_udc_probe(&rv1108_otg_data);
75 }
76
77 int board_usb_cleanup(int index, enum usb_init_type init)
78 {
79         return 0;
80 }
81 #endif