hc
2024-03-26 e0728245c89800c2038c23308f2d88969d5b41c8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
 * SPDX-License-Identifier:     GPL-2.0+
 *
 * (C) Copyright 2021 Rockchip Electronics Co., Ltd
 */
 
#include <common.h>
#include <dwc3-uboot.h>
#include <usb.h>
#include <linux/usb/phy-rockchip-usbdp.h>
#include <asm/io.h>
#include <rockusb.h>
 
DECLARE_GLOBAL_DATA_PTR;
 
#ifdef CONFIG_USB_DWC3
#define CRU_BASE        0xfd7c0000
#define CRU_SOFTRST_CON42    0x0aa8
 
static struct dwc3_device dwc3_device_data = {
   .maximum_speed = USB_SPEED_SUPER,
   .base = 0xfc000000,
   .dr_mode = USB_DR_MODE_PERIPHERAL,
   .index = 0,
   .dis_u2_susphy_quirk = 1,
   .dis_u1u2_quirk = 1,
   .usb2_phyif_utmi_width = 16,
};
 
int usb_gadget_handle_interrupts(int index)
{
   dwc3_uboot_handle_interrupt(0);
   return 0;
}
 
bool rkusb_usb3_capable(void)
{
   return true;
}
 
static void usb_reset_otg_controller(void)
{
   writel(0x00100010, CRU_BASE + CRU_SOFTRST_CON42);
   mdelay(1);
   writel(0x00100000, CRU_BASE + CRU_SOFTRST_CON42);
   mdelay(1);
}
 
int board_usb_init(int index, enum usb_init_type init)
{
   u32 ret = 0;
 
   usb_reset_otg_controller();
 
#if defined(CONFIG_SUPPORT_USBPLUG)
   dwc3_device_data.maximum_speed = USB_SPEED_HIGH;
 
   if (rkusb_switch_usb3_enabled()) {
       dwc3_device_data.maximum_speed = USB_SPEED_SUPER;
       ret = rockchip_u3phy_uboot_init();
       if (ret) {
           rkusb_force_to_usb2(true);
           dwc3_device_data.maximum_speed = USB_SPEED_HIGH;
       }
   }
#else
   ret = rockchip_u3phy_uboot_init();
   if (ret) {
       rkusb_force_to_usb2(true);
       dwc3_device_data.maximum_speed = USB_SPEED_HIGH;
   }
#endif
 
   return dwc3_uboot_init(&dwc3_device_data);
}
 
#if defined(CONFIG_SUPPORT_USBPLUG)
int board_usb_cleanup(int index, enum usb_init_type init)
{
   dwc3_uboot_exit(index);
   return 0;
}
#endif
 
#endif