diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/core/usbh_core.c b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/core/usbh_core.c index 9e038cdff..60aac05f5 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/core/usbh_core.c +++ b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/core/usbh_core.c @@ -33,6 +33,7 @@ Modification: usb core uses naive_mmap to assign virtual and physical addresses #include "usbh_core.h" #include "usbh_hub.h" #include "usb_hc_xhci.h" +#include "rk3568_usb.h" #include "usyscall.h" #include "usbh_rndis.h" @@ -1020,10 +1021,14 @@ int usb_hc_init(uint32_t id) struct usbh_bus* usb = usbh_get_bus_of_index(id); if (USB_HC_XHCI == usb->usb_hc_type) { - ret = xhci_usb_hc_init(usb->id); + ret = dwc3_generic_host_probe(id); + if (ret) { + return ret; + } + ret = xhci_usb_hc_init(id); } else { - USB_LOG_WRN("invalid usb controller type %d \r\n", usb->usb_hc_type); + USB_LOG_WRN("usb_hc_init invalid usb controller type %d \r\n", usb->usb_hc_type); return -EINVAL; } diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/dev/rk3568/rk3568_usb.c b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/dev/rk3568/rk3568_usb.c index 1fd288525..8fec80135 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/dev/rk3568/rk3568_usb.c +++ b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/dev/rk3568/rk3568_usb.c @@ -1,14 +1,67 @@ +/************************************************* +File name: rk3568_usb.c +Description: the dwc3 host probe function adapted to xiuos. +Others: take RK3568 codes uboot\drivers\usb\dwc3\dwc3-generic.c +*************************************************/ #include "rk3568_usb.h" +#include "usb_hc_xhci.h" struct dwc3 dwc3_rk3568[CONFIG_USBHOST_XHCI_NUM]; -int dwc3_generic_host_probe(uint32_t id){ - return 0; +static uint32_t usb_get_maximum_speed(uint32_t id) +{ + return USB_SPEED_SUPER; +} + +static enum usb_dr_mode usb_get_dr_mode(uint32_t id) +{ + return USB_DR_MODE_HOST; } -int dwc3_generic_probe(uint32_t id){ - return 0; +int dwc3_generic_host_probe(uint32_t id) +{ + struct dwc3 *dwc3; + + USB_ASSERT(id < CONFIG_USBHOST_XHCI_NUM); + dwc3 = &(dwc3_rk3568[id]); + memset(dwc3, 0, sizeof(*dwc3)); + dwc3->id = id; + + return dwc3_generic_probe(dwc3); +} + + +int dwc3_generic_probe(struct dwc3 *dwc3) +{ + int rc; + uintptr_t base; + uintptr_t base_vir; + int len; + + dwc3->maximum_speed = usb_get_maximum_speed(dwc3->id); + dwc3->dr_mode = usb_get_dr_mode(dwc3->id); + + dwc3_of_parse(dwc3); + + base = usb_hc_get_register_base(dwc3->id); + base_vir = usb_hc_get_register_vir_base(dwc3->id); + + dwc3->regs = (void *)base + DWC3_GLOBALS_REGS_START; + dwc3->regs_vir = (void *)base_vir + DWC3_GLOBALS_REGS_START; + len = DWC3_OTG_REGS_END - DWC3_GLOBALS_REGS_START + 1; + + if(!mmap((uintptr_t)dwc3->regs_vir, (uintptr_t)dwc3->regs, len, true)){ + USB_LOG_ERR("%s mmap fail\r\n", __func__); + return -ENOMEM; + } + + rc = dwc3_init(dwc3); + if (rc) { + return rc; + } + + return 0; } \ No newline at end of file diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/dev/rk3568/rk3568_usb.h b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/dev/rk3568/rk3568_usb.h index 21abd4a09..73398a283 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/dev/rk3568/rk3568_usb.h +++ b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/dev/rk3568/rk3568_usb.h @@ -4,6 +4,6 @@ #include "dwc3.h" int dwc3_generic_host_probe(uint32_t id); -int dwc3_generic_probe(uint32_t id); +int dwc3_generic_probe(struct dwc3 *dwc3); #endif diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/port/dwc3/dwc3.c b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/port/dwc3/dwc3.c index 9bc28841c..a1803b307 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/port/dwc3/dwc3.c +++ b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/port/dwc3/dwc3.c @@ -2,8 +2,52 @@ #include "usb_config.h" -void dwc3_of_parse(struct dwc3 *dwc){ +void dwc3_of_parse(struct dwc3 *dwc) +{ + uint8_t lpm_nyet_threshold; + uint8_t tx_de_emphasis; + uint8_t hird_threshold; + + /* default to highest possible threshold */ + lpm_nyet_threshold = 0xff; + + /* default to -3.5dB de-emphasis */ + tx_de_emphasis = 1; + + /* + * default to assert utmi_sleep_n and use maximum allowed HIRD + * threshold value of 0b1100 + */ + hird_threshold = 12; + + dwc->hsphy_mode = usb_get_phy_mode(dwc->id); + + /* xiuos: The parameters are updated according to the dts of RK3568 */ + dwc->has_lpm_erratum = 0; + lpm_nyet_threshold = lpm_nyet_threshold; + dwc->is_utmi_l1_suspend = 0; + hird_threshold = hird_threshold; + dwc->disable_scramble_quirk = 0; + dwc->u2exit_lfps_quirk = 0; + dwc->u2ss_inp3_quirk = 0; + dwc->req_p1p2p3_quirk = 0; + dwc->del_p1p2p3_quirk = 0; + dwc->del_phy_power_chg_quirk = 0; + dwc->lfps_filter_quirk = 0; + dwc->rx_detect_poll_quirk = 0; + dwc->dis_u3_susphy_quirk = 0; + dwc->dis_u2_susphy_quirk = 0; + dwc->dis_enblslpm_quirk = 1; + dwc->dis_u2_freeclk_exists_quirk = 1; + dwc->tx_de_emphasis_quirk = 0; + tx_de_emphasis = tx_de_emphasis; + + dwc->lpm_nyet_threshold = lpm_nyet_threshold; + dwc->tx_de_emphasis = tx_de_emphasis; + + dwc->hird_threshold = hird_threshold + | (dwc->is_utmi_l1_suspend << 4); } diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/port/dwc3/dwc3.h b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/port/dwc3/dwc3.h index b0b0eca31..eb49d2edf 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/port/dwc3/dwc3.h +++ b/Ubiquitous/XiZi_AIoT/services/drivers/usb/components/port/dwc3/dwc3.h @@ -627,9 +627,12 @@ struct dwc3 { uintptr_t scratch_addr; struct dwc3_request ep0_usb_req; - /* device lock */ + /* The id is USB3_0 or USB3_1 */ + uint32_t id; + + /* device lock */ usb_osal_mutex_t lock; - + struct dwc3_event_buffer **ev_buffs; struct dwc3_ep *eps[DWC3_ENDPOINTS_NUM]; diff --git a/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/Makefile b/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/Makefile index ca7596a97..fc1425831 100644 --- a/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/Makefile +++ b/Ubiquitous/XiZi_AIoT/services/drivers/usb/usb_service/Makefile @@ -12,10 +12,14 @@ session = $(KERNEL_ROOT)/services/app/session.o libipc = $(KERNEL_ROOT)/services/app/libipc.o libsem = $(KERNEL_ROOT)/services/app/libsemaphore.o -usb_components = $(KERNEL_ROOT)/services/drivers/usb/components/rndis_host.o \ +usb_components = \ + $(KERNEL_ROOT)/services/drivers/usb/components/dwc3.o \ + $(KERNEL_ROOT)/services/drivers/usb/components/rk3568_usb.o \ + $(KERNEL_ROOT)/services/drivers/usb/components/rndis_host.o \ $(KERNEL_ROOT)/services/drivers/usb/components/usb_hc_xhci.o \ $(KERNEL_ROOT)/services/drivers/usb/components/usb_mem.o \ $(KERNEL_ROOT)/services/drivers/usb/components/usb_osal.o \ + $(KERNEL_ROOT)/services/drivers/usb/components/usb_phy.o \ $(KERNEL_ROOT)/services/drivers/usb/components/usbh_core.o \ $(KERNEL_ROOT)/services/drivers/usb/components/usbh_hub.o \ $(KERNEL_ROOT)/services/drivers/usb/components/usbh_rndis.o \