Hi Felipe, Can you drop the part that checks the DCNRD bit, please? I made a mistake when I originally submitted this. It is not necessary to check the DCNRD bit every time before reading the link state, it should only be checked the first time after coming out of hibernation. Doing it every time is unnecessary overhead, and can even cause problems with a hibernation-enabled controller.
So for now maybe just drop the entire patch, and instead call DWC3_DSTS_USBLNKST() directly? -- Paul -----Original Message----- From: Felipe Balbi [mailto:ba...@ti.com] Sent: Tuesday, February 25, 2014 11:41 AM To: Linux USB Mailing List Cc: Paul Zimmerman; Paul Zimmerman; Felipe Balbi Subject: [PATCH 04/11] usb: dwc3: gadget: implement dwc3_gadget_get_link_state From: Paul Zimmerman <paul.zimmer...@synopsys.com> This function will be used during hibernation to get the current link state. It will be needed at least for Hibernation support. Signed-off-by: Paul Zimmerman <pa...@synopsys.com> Signed-off-by: Felipe Balbi <ba...@ti.com> --- drivers/usb/dwc3/gadget.c | 36 ++++++++++++++++++++++++++++++++++++ drivers/usb/dwc3/gadget.h | 1 + 2 files changed, 37 insertions(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 31b13c2..ff10161 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -68,6 +68,42 @@ int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode) } /** + * dwc3_gadget_get_lik_state - Gets current state of USB Link + * @dwc: pointer to our context structure + * + * Caller should take care of locking. This function will + * return the link state on success (>= 0) or -ETIMEDOUT. + */ +int dwc3_gadget_get_link_state(struct dwc3 *dwc) +{ + u32 reg; + + reg = dwc3_readl(dwc->regs, DWC3_DSTS); + + /* + * Wait until device controller is ready. + * (This only applied to 1.94a and later + * RTL releases) + */ + if (dwc->revision >= DWC3_REVISION_194A) { + int retries = 10000; + + do { + reg = dwc3_readl(dwc->regs, DWC3_DSTS); + if (!(reg & DWC3_DSTS_DCNRD)) + break; + + if (!retries) + return -ETIMEDOUT; + + udelay(5); + } while (--retries); + } + + return DWC3_DSTS_USBLNKST(reg); +} + +/** * dwc3_gadget_set_link_state - Sets USB Link to a particular State * @dwc: pointer to our context structure * @state: the state to put link into diff --git a/drivers/usb/dwc3/gadget.h b/drivers/usb/dwc3/gadget.h index febe1aa..d101244 100644 --- a/drivers/usb/dwc3/gadget.h +++ b/drivers/usb/dwc3/gadget.h @@ -86,6 +86,7 @@ void dwc3_gadget_giveback(struct dwc3_ep *dep, struct dwc3_request *req, int status); int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode); +int dwc3_gadget_get_link_state(struct dwc3 *dwc); int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state); void dwc3_ep0_interrupt(struct dwc3 *dwc, -- 1.9.0 -- To unsubscribe from this list: send the line "unsubscribe linux-usb" in the body of a message to majord...@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html