usb: dwc2: Add function for session B check
authorPatrick Delaunay <patrick.delaunay@st.com>
Fri, 29 Mar 2019 14:42:18 +0000 (15:42 +0100)
committerMarek Vasut <marex@denx.de>
Sun, 21 Apr 2019 08:26:52 +0000 (10:26 +0200)
Add a new function to check the session B validity, to be use to check
cable connection.

Signed-off-by: Patrick Delaunay <patrick.delaunay@st.com>
Reviewed-by: Lukasz Majewski <lukma@denx.de>
drivers/usb/gadget/dwc2_udc_otg.c
include/usb/dwc2_udc.h

index 146f11e710804955a93dc7a4a57add5365244a5f..b1efad115ecc2516ee65b35ee250615c83ec0df3 100644 (file)
@@ -1151,4 +1151,13 @@ U_BOOT_DRIVER(dwc2_udc_otg) = {
        .platdata_auto_alloc_size = sizeof(struct dwc2_plat_otg_data),
        .priv_auto_alloc_size = sizeof(struct dwc2_priv_data),
 };
+
+int dwc2_udc_B_session_valid(struct udevice *dev)
+{
+       struct dwc2_plat_otg_data *platdata = dev_get_platdata(dev);
+       struct dwc2_usbotg_reg *usbotg_reg =
+               (struct dwc2_usbotg_reg *)platdata->regs_otg;
+
+       return readl(&usbotg_reg->gotgctl) & B_SESSION_VALID;
+}
 #endif /* CONFIG_IS_ENABLED(DM_USB_GADGET) */
index 3cf20eab92dd3f853122b4a66d6d455a582fad4b..8a426b631ef9aec3b4930fc03c71cea911b776ec 100644 (file)
@@ -27,4 +27,6 @@ struct dwc2_plat_otg_data {
 
 int dwc2_udc_probe(struct dwc2_plat_otg_data *pdata);
 
+int dwc2_udc_B_session_valid(struct udevice *dev);
+
 #endif /* __DWC2_USB_GADGET */