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