* [PATCH 0/4] usb: gadget: Link state changes
@ 2019-10-22 19:09 Thinh Nguyen
2019-10-22 19:09 ` [PATCH 1/4] usb: dwc3: gadget: Don't send unintended link state change Thinh Nguyen
` (3 more replies)
0 siblings, 4 replies; 7+ messages in thread
From: Thinh Nguyen @ 2019-10-22 19:09 UTC (permalink / raw)
To: Felipe Balbi, Thinh Nguyen, linux-usb; +Cc: John Youn
This patch series adds some fixes to how dwc3 handles cases related to
link state changes.
Thinh Nguyen (4):
usb: dwc3: gadget: Don't send unintended link state change
usb: dwc3: gadget: Set link state to RX_Detect on disconnect
usb: dwc3: gadget: Clear DCTL.ULSTCHNGREQ before set
usb: dwc3: debug: Remove newline printout
drivers/usb/dwc3/debug.h | 4 ++--
drivers/usb/dwc3/gadget.c | 26 ++++++++++++++++++++++++++
2 files changed, 28 insertions(+), 2 deletions(-)
--
2.11.0
^ permalink raw reply [flat|nested] 7+ messages in thread* [PATCH 1/4] usb: dwc3: gadget: Don't send unintended link state change 2019-10-22 19:09 [PATCH 0/4] usb: gadget: Link state changes Thinh Nguyen @ 2019-10-22 19:09 ` Thinh Nguyen 2019-10-23 6:21 ` Felipe Balbi 2019-10-22 19:09 ` [PATCH 2/4] usb: dwc3: gadget: Set link state to RX_Detect on disconnect Thinh Nguyen ` (2 subsequent siblings) 3 siblings, 1 reply; 7+ messages in thread From: Thinh Nguyen @ 2019-10-22 19:09 UTC (permalink / raw) To: Felipe Balbi, Thinh Nguyen, linux-usb; +Cc: John Youn DCTL.ULSTCHNGREQ is a write-only field. When doing a read-modify-write to DCTL, the driver must make sure that there's no unintended link state change request from whatever is read from DCTL.ULSTCHNGREQ. Set link state change to no-action when the driver writes to DCTL. Signed-off-by: Thinh Nguyen <thinhn@synopsys.com> --- drivers/usb/dwc3/gadget.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 86dc1db788a9..24178b4b9d46 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -57,6 +57,8 @@ int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode) return -EINVAL; } + /* Don't send link state change request */ + reg &= ~DWC3_DCTL_ULSTCHNGREQ_MASK; dwc3_writel(dwc->regs, DWC3_DCTL, reg); return 0; @@ -1822,6 +1824,9 @@ static int dwc3_gadget_run_stop(struct dwc3 *dwc, int is_on, int suspend) dwc->pullups_connected = false; } + /* Don't send link state change request */ + reg &= ~DWC3_DCTL_ULSTCHNGREQ_MASK; + dwc3_writel(dwc->regs, DWC3_DCTL, reg); do { @@ -2744,6 +2749,10 @@ static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc) int reg; reg = dwc3_readl(dwc->regs, DWC3_DCTL); + + /* Don't send link state change request */ + reg &= ~DWC3_DCTL_ULSTCHNGREQ_MASK; + reg &= ~DWC3_DCTL_INITU1ENA; dwc3_writel(dwc->regs, DWC3_DCTL, reg); @@ -2799,6 +2808,10 @@ static void dwc3_gadget_reset_interrupt(struct dwc3 *dwc) dwc3_reset_gadget(dwc); reg = dwc3_readl(dwc->regs, DWC3_DCTL); + + /* Don't send link state change request */ + reg &= ~DWC3_DCTL_ULSTCHNGREQ_MASK; + reg &= ~DWC3_DCTL_TSTCTRL_MASK; dwc3_writel(dwc->regs, DWC3_DCTL, reg); dwc->test_mode = false; @@ -2904,10 +2917,15 @@ static void dwc3_gadget_conndone_interrupt(struct dwc3 *dwc) if (dwc->has_lpm_erratum && dwc->revision >= DWC3_REVISION_240A) reg |= DWC3_DCTL_NYET_THRES(dwc->lpm_nyet_threshold); + /* Don't send link state change request */ + reg &= ~DWC3_DCTL_ULSTCHNGREQ_MASK; dwc3_writel(dwc->regs, DWC3_DCTL, reg); } else { reg = dwc3_readl(dwc->regs, DWC3_DCTL); reg &= ~DWC3_DCTL_HIRD_THRES_MASK; + + /* Don't send link state change request */ + reg &= ~DWC3_DCTL_ULSTCHNGREQ_MASK; dwc3_writel(dwc->regs, DWC3_DCTL, reg); } @@ -3017,6 +3035,9 @@ static void dwc3_gadget_linksts_change_interrupt(struct dwc3 *dwc, reg &= ~u1u2; + /* Don't send link state change request */ + reg &= ~DWC3_DCTL_ULSTCHNGREQ_MASK; + dwc3_writel(dwc->regs, DWC3_DCTL, reg); break; default: -- 2.11.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* Re: [PATCH 1/4] usb: dwc3: gadget: Don't send unintended link state change 2019-10-22 19:09 ` [PATCH 1/4] usb: dwc3: gadget: Don't send unintended link state change Thinh Nguyen @ 2019-10-23 6:21 ` Felipe Balbi 2019-10-24 2:10 ` Thinh Nguyen 0 siblings, 1 reply; 7+ messages in thread From: Felipe Balbi @ 2019-10-23 6:21 UTC (permalink / raw) To: Thinh Nguyen, Thinh Nguyen, linux-usb; +Cc: John Youn [-- Attachment #1: Type: text/plain, Size: 1206 bytes --] Hi Thinh, Thinh Nguyen <Thinh.Nguyen@synopsys.com> writes: > DCTL.ULSTCHNGREQ is a write-only field. When doing a read-modify-write > to DCTL, the driver must make sure that there's no unintended link state > change request from whatever is read from DCTL.ULSTCHNGREQ. Set link > state change to no-action when the driver writes to DCTL. > > Signed-off-by: Thinh Nguyen <thinhn@synopsys.com> WHAT A GREAT CATCH!!! However, let's do one small change here: > --- > drivers/usb/dwc3/gadget.c | 21 +++++++++++++++++++++ > 1 file changed, 21 insertions(+) > > diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c > index 86dc1db788a9..24178b4b9d46 100644 > --- a/drivers/usb/dwc3/gadget.c > +++ b/drivers/usb/dwc3/gadget.c > @@ -57,6 +57,8 @@ int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode) > return -EINVAL; > } > > + /* Don't send link state change request */ > + reg &= ~DWC3_DCTL_ULSTCHNGREQ_MASK; > dwc3_writel(dwc->regs, DWC3_DCTL, reg); Let's a small macro or a little function to wrap this. Something dwc3_dctl_write_safe() or something long those line. Then that macro/function will make sure to clear those bits. -- balbi [-- Attachment #2: signature.asc --] [-- Type: application/pgp-signature, Size: 832 bytes --] ^ permalink raw reply [flat|nested] 7+ messages in thread
* Re: [PATCH 1/4] usb: dwc3: gadget: Don't send unintended link state change 2019-10-23 6:21 ` Felipe Balbi @ 2019-10-24 2:10 ` Thinh Nguyen 0 siblings, 0 replies; 7+ messages in thread From: Thinh Nguyen @ 2019-10-24 2:10 UTC (permalink / raw) To: Felipe Balbi, Thinh Nguyen, linux-usb@vger.kernel.org; +Cc: John Youn Hi, Felipe Balbi wrote: > Thinh Nguyen <Thinh.Nguyen@synopsys.com> writes: >> DCTL.ULSTCHNGREQ is a write-only field. When doing a read-modify-write >> to DCTL, the driver must make sure that there's no unintended link state >> change request from whatever is read from DCTL.ULSTCHNGREQ. Set link >> state change to no-action when the driver writes to DCTL. >> >> Signed-off-by: Thinh Nguyen <thinhn@synopsys.com> > WHAT A GREAT CATCH!!! However, let's do one small change here: > >> --- >> drivers/usb/dwc3/gadget.c | 21 +++++++++++++++++++++ >> 1 file changed, 21 insertions(+) >> >> diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c >> index 86dc1db788a9..24178b4b9d46 100644 >> --- a/drivers/usb/dwc3/gadget.c >> +++ b/drivers/usb/dwc3/gadget.c >> @@ -57,6 +57,8 @@ int dwc3_gadget_set_test_mode(struct dwc3 *dwc, int mode) >> return -EINVAL; >> } >> >> + /* Don't send link state change request */ >> + reg &= ~DWC3_DCTL_ULSTCHNGREQ_MASK; >> dwc3_writel(dwc->regs, DWC3_DCTL, reg); > Let's a small macro or a little function to wrap this. Something > dwc3_dctl_write_safe() or something long those line. > > Then that macro/function will make sure to clear those bits. Sure. I'll resend with the change. Thanks, Thinh ^ permalink raw reply [flat|nested] 7+ messages in thread
* [PATCH 2/4] usb: dwc3: gadget: Set link state to RX_Detect on disconnect 2019-10-22 19:09 [PATCH 0/4] usb: gadget: Link state changes Thinh Nguyen 2019-10-22 19:09 ` [PATCH 1/4] usb: dwc3: gadget: Don't send unintended link state change Thinh Nguyen @ 2019-10-22 19:09 ` Thinh Nguyen 2019-10-22 19:10 ` [PATCH 3/4] usb: dwc3: gadget: Clear DCTL.ULSTCHNGREQ before set Thinh Nguyen 2019-10-22 19:10 ` [PATCH 4/4] usb: dwc3: debug: Remove newline printout Thinh Nguyen 3 siblings, 0 replies; 7+ messages in thread From: Thinh Nguyen @ 2019-10-22 19:09 UTC (permalink / raw) To: Felipe Balbi, Thinh Nguyen, linux-usb; +Cc: John Youn When DWC3 receives disconnect event, it needs to set the link state to RX_Detect. DWC_usb3 3.30a programming guide 4.1.7 Signed-off-by: Thinh Nguyen <thinhn@synopsys.com> --- drivers/usb/dwc3/gadget.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 24178b4b9d46..37631d2e2a2e 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -2748,6 +2748,8 @@ static void dwc3_gadget_disconnect_interrupt(struct dwc3 *dwc) { int reg; + dwc3_gadget_set_link_state(dwc, DWC3_LINK_STATE_RX_DET); + reg = dwc3_readl(dwc->regs, DWC3_DCTL); /* Don't send link state change request */ -- 2.11.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 3/4] usb: dwc3: gadget: Clear DCTL.ULSTCHNGREQ before set 2019-10-22 19:09 [PATCH 0/4] usb: gadget: Link state changes Thinh Nguyen 2019-10-22 19:09 ` [PATCH 1/4] usb: dwc3: gadget: Don't send unintended link state change Thinh Nguyen 2019-10-22 19:09 ` [PATCH 2/4] usb: dwc3: gadget: Set link state to RX_Detect on disconnect Thinh Nguyen @ 2019-10-22 19:10 ` Thinh Nguyen 2019-10-22 19:10 ` [PATCH 4/4] usb: dwc3: debug: Remove newline printout Thinh Nguyen 3 siblings, 0 replies; 7+ messages in thread From: Thinh Nguyen @ 2019-10-22 19:10 UTC (permalink / raw) To: Felipe Balbi, Thinh Nguyen, linux-usb; +Cc: John Youn Send a no-action link state change request before the actual request so DWC3 can send the same request whenever we call dwc3_gadget_set_link_state(). Signed-off-by: Thinh Nguyen <thinhn@synopsys.com> --- drivers/usb/dwc3/gadget.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c index 37631d2e2a2e..03d58254d1e6 100644 --- a/drivers/usb/dwc3/gadget.c +++ b/drivers/usb/dwc3/gadget.c @@ -113,6 +113,9 @@ int dwc3_gadget_set_link_state(struct dwc3 *dwc, enum dwc3_link_state state) reg = dwc3_readl(dwc->regs, DWC3_DCTL); reg &= ~DWC3_DCTL_ULSTCHNGREQ_MASK; + /* set no action before sending new link state change */ + dwc3_writel(dwc->regs, DWC3_DCTL, reg); + /* set requested state */ reg |= DWC3_DCTL_ULSTCHNGREQ(state); dwc3_writel(dwc->regs, DWC3_DCTL, reg); -- 2.11.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
* [PATCH 4/4] usb: dwc3: debug: Remove newline printout 2019-10-22 19:09 [PATCH 0/4] usb: gadget: Link state changes Thinh Nguyen ` (2 preceding siblings ...) 2019-10-22 19:10 ` [PATCH 3/4] usb: dwc3: gadget: Clear DCTL.ULSTCHNGREQ before set Thinh Nguyen @ 2019-10-22 19:10 ` Thinh Nguyen 3 siblings, 0 replies; 7+ messages in thread From: Thinh Nguyen @ 2019-10-22 19:10 UTC (permalink / raw) To: Felipe Balbi, Thinh Nguyen, linux-usb; +Cc: John Youn The newline from the unknown link state tracepoint doesn't follow the other tracepoints, and it looks unsightly. Let's remove it. Signed-off-by: Thinh Nguyen <thinhn@synopsys.com> --- drivers/usb/dwc3/debug.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/usb/dwc3/debug.h b/drivers/usb/dwc3/debug.h index 9baabed87d61..e56beb9d1e36 100644 --- a/drivers/usb/dwc3/debug.h +++ b/drivers/usb/dwc3/debug.h @@ -112,7 +112,7 @@ dwc3_gadget_link_string(enum dwc3_link_state link_state) case DWC3_LINK_STATE_RESUME: return "Resume"; default: - return "UNKNOWN link state\n"; + return "UNKNOWN link state"; } } @@ -141,7 +141,7 @@ dwc3_gadget_hs_link_string(enum dwc3_link_state link_state) case DWC3_LINK_STATE_RESUME: return "Resume"; default: - return "UNKNOWN link state\n"; + return "UNKNOWN link state"; } } -- 2.11.0 ^ permalink raw reply related [flat|nested] 7+ messages in thread
end of thread, other threads:[~2019-10-24 2:10 UTC | newest] Thread overview: 7+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2019-10-22 19:09 [PATCH 0/4] usb: gadget: Link state changes Thinh Nguyen 2019-10-22 19:09 ` [PATCH 1/4] usb: dwc3: gadget: Don't send unintended link state change Thinh Nguyen 2019-10-23 6:21 ` Felipe Balbi 2019-10-24 2:10 ` Thinh Nguyen 2019-10-22 19:09 ` [PATCH 2/4] usb: dwc3: gadget: Set link state to RX_Detect on disconnect Thinh Nguyen 2019-10-22 19:10 ` [PATCH 3/4] usb: dwc3: gadget: Clear DCTL.ULSTCHNGREQ before set Thinh Nguyen 2019-10-22 19:10 ` [PATCH 4/4] usb: dwc3: debug: Remove newline printout Thinh Nguyen
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).