Message ID | 20240712-dwc-mp-v1-3-295e5c4e3ec9@nxp.com (mailing list archive) |
---|---|
State | Superseded |
Headers | show |
Series | usb: imx8mp: collect some improvement | expand |
On Fri, Jul 12, 2024, Frank Li wrote: > From: Li Jun <jun.li@nxp.com> > > The runtime resume will happen before system resume if system wakeup by > device mode wakeup event(e.g, VBUS). Add a flag to avoid init twice. What's the consequence of going through the resuming sequence twice? Will this cause any functional issue? Thanks, Thinh > > Reviewed-by: Peter Chen <peter.chen@nxp.com> > Signed-off-by: Li Jun <jun.li@nxp.com> > Signed-off-by: Frank Li <Frank.Li@nxp.com> > --- > drivers/usb/dwc3/core.c | 13 +++++++++++++ > drivers/usb/dwc3/core.h | 1 + > 2 files changed, 14 insertions(+) > > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c > index 734de2a8bd212..d60917fad8c52 100644 > --- a/drivers/usb/dwc3/core.c > +++ b/drivers/usb/dwc3/core.c > @@ -950,6 +950,8 @@ static void dwc3_core_exit(struct dwc3 *dwc) > dwc3_phy_exit(dwc); > dwc3_clk_disable(dwc); > reset_control_assert(dwc->reset); > + > + dwc->core_inited = false; > } > > static bool dwc3_core_is_valid(struct dwc3 *dwc) > @@ -1446,6 +1448,8 @@ static int dwc3_core_init(struct dwc3 *dwc) > dwc3_writel(dwc->regs, DWC3_LLUCTL, reg); > } > > + dwc->core_inited = true; > + > return 0; > > err_power_off_phy: > @@ -2375,6 +2379,15 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) > > switch (dwc->current_dr_role) { > case DWC3_GCTL_PRTCAP_DEVICE: > + /* > + * system resume may come after runtime resume > + * e.g. rpm suspend -> pm suspend -> wakeup > + * -> rpm resume -> system resume, so if already > + * runtime resumed, system resume should skip it. > + */ > + if (dwc->core_inited) > + break; > + > ret = dwc3_core_init_for_resume(dwc); > if (ret) > return ret; > diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h > index 1e561fd8b86e2..8a4bfd9a25b19 100644 > --- a/drivers/usb/dwc3/core.h > +++ b/drivers/usb/dwc3/core.h > @@ -1195,6 +1195,7 @@ struct dwc3 { > struct clk *utmi_clk; > struct clk *pipe_clk; > > + bool core_inited; > struct reset_control *reset; > > struct usb_phy *usb2_phy; > > -- > 2.34.1 >
On Wed, Aug 07, 2024 at 01:13:52AM +0000, Thinh Nguyen wrote: > On Fri, Jul 12, 2024, Frank Li wrote: > > From: Li Jun <jun.li@nxp.com> > > > > The runtime resume will happen before system resume if system wakeup by > > device mode wakeup event(e.g, VBUS). Add a flag to avoid init twice. > > What's the consequence of going through the resuming sequence twice? > Will this cause any functional issue? static int dwc3_core_init_for_resume(struct dwc3 *dwc) { ... ret = dwc3_clk_enable(dwc); if (ret) goto assert_reset; ... } clk will be enabled twice, the reference count in clk will be wrong because clk_disable() only once at suspend. So clk will be always ON at next suspend. Frank Li > > Thanks, > Thinh > > > > > Reviewed-by: Peter Chen <peter.chen@nxp.com> > > Signed-off-by: Li Jun <jun.li@nxp.com> > > Signed-off-by: Frank Li <Frank.Li@nxp.com> > > --- > > drivers/usb/dwc3/core.c | 13 +++++++++++++ > > drivers/usb/dwc3/core.h | 1 + > > 2 files changed, 14 insertions(+) > > > > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c > > index 734de2a8bd212..d60917fad8c52 100644 > > --- a/drivers/usb/dwc3/core.c > > +++ b/drivers/usb/dwc3/core.c > > @@ -950,6 +950,8 @@ static void dwc3_core_exit(struct dwc3 *dwc) > > dwc3_phy_exit(dwc); > > dwc3_clk_disable(dwc); > > reset_control_assert(dwc->reset); > > + > > + dwc->core_inited = false; > > } > > > > static bool dwc3_core_is_valid(struct dwc3 *dwc) > > @@ -1446,6 +1448,8 @@ static int dwc3_core_init(struct dwc3 *dwc) > > dwc3_writel(dwc->regs, DWC3_LLUCTL, reg); > > } > > > > + dwc->core_inited = true; > > + > > return 0; > > > > err_power_off_phy: > > @@ -2375,6 +2379,15 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) > > > > switch (dwc->current_dr_role) { > > case DWC3_GCTL_PRTCAP_DEVICE: > > + /* > > + * system resume may come after runtime resume > > + * e.g. rpm suspend -> pm suspend -> wakeup > > + * -> rpm resume -> system resume, so if already > > + * runtime resumed, system resume should skip it. > > + */ > > + if (dwc->core_inited) > > + break; > > + > > ret = dwc3_core_init_for_resume(dwc); > > if (ret) > > return ret; > > diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h > > index 1e561fd8b86e2..8a4bfd9a25b19 100644 > > --- a/drivers/usb/dwc3/core.h > > +++ b/drivers/usb/dwc3/core.h > > @@ -1195,6 +1195,7 @@ struct dwc3 { > > struct clk *utmi_clk; > > struct clk *pipe_clk; > > > > + bool core_inited; > > struct reset_control *reset; > > > > struct usb_phy *usb2_phy; > > > > -- > > 2.34.1 > >
On Fri, Aug 09, 2024, Frank Li wrote: > On Wed, Aug 07, 2024 at 01:13:52AM +0000, Thinh Nguyen wrote: > > On Fri, Jul 12, 2024, Frank Li wrote: > > > From: Li Jun <jun.li@nxp.com> > > > > > > The runtime resume will happen before system resume if system wakeup by > > > device mode wakeup event(e.g, VBUS). Add a flag to avoid init twice. > > > > What's the consequence of going through the resuming sequence twice? > > Will this cause any functional issue? > > static int dwc3_core_init_for_resume(struct dwc3 *dwc) > { > > ... > ret = dwc3_clk_enable(dwc); > if (ret) > goto assert_reset; > > ... > } > > clk will be enabled twice, the reference count in clk will be wrong because > clk_disable() only once at suspend. Please capture these info in the commit message. > > So clk will be always ON at next suspend. > > Frank Li > dwc3_clk_enable() happens in probe() and dwc3_core_init_for_resume(), but you're checking dwc->core_inited in dwc3_core_init(). Why? If the issue is only related to clk_enable(), perhaps just check that? (minor nit: rename core_inited to core_initialized if you plan to do that) Thanks, Thinh > > > > > > Reviewed-by: Peter Chen <peter.chen@nxp.com> > > > Signed-off-by: Li Jun <jun.li@nxp.com> > > > Signed-off-by: Frank Li <Frank.Li@nxp.com> > > > --- > > > drivers/usb/dwc3/core.c | 13 +++++++++++++ > > > drivers/usb/dwc3/core.h | 1 + > > > 2 files changed, 14 insertions(+) > > > > > > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c > > > index 734de2a8bd212..d60917fad8c52 100644 > > > --- a/drivers/usb/dwc3/core.c > > > +++ b/drivers/usb/dwc3/core.c > > > @@ -950,6 +950,8 @@ static void dwc3_core_exit(struct dwc3 *dwc) > > > dwc3_phy_exit(dwc); > > > dwc3_clk_disable(dwc); > > > reset_control_assert(dwc->reset); > > > + > > > + dwc->core_inited = false; > > > } > > > > > > static bool dwc3_core_is_valid(struct dwc3 *dwc) > > > @@ -1446,6 +1448,8 @@ static int dwc3_core_init(struct dwc3 *dwc) > > > dwc3_writel(dwc->regs, DWC3_LLUCTL, reg); > > > } > > > > > > + dwc->core_inited = true; > > > + > > > return 0; > > > > > > err_power_off_phy: > > > @@ -2375,6 +2379,15 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) > > > > > > switch (dwc->current_dr_role) { > > > case DWC3_GCTL_PRTCAP_DEVICE: > > > + /* > > > + * system resume may come after runtime resume > > > + * e.g. rpm suspend -> pm suspend -> wakeup > > > + * -> rpm resume -> system resume, so if already > > > + * runtime resumed, system resume should skip it. > > > + */ > > > + if (dwc->core_inited) > > > + break; > > > + > > > ret = dwc3_core_init_for_resume(dwc); > > > if (ret) > > > return ret; > > > diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h > > > index 1e561fd8b86e2..8a4bfd9a25b19 100644 > > > --- a/drivers/usb/dwc3/core.h > > > +++ b/drivers/usb/dwc3/core.h > > > @@ -1195,6 +1195,7 @@ struct dwc3 { > > > struct clk *utmi_clk; > > > struct clk *pipe_clk; > > > > > > + bool core_inited; > > > struct reset_control *reset; > > > > > > struct usb_phy *usb2_phy; > > > > > > -- > > > 2.34.1 > > >
On Fri, Aug 09, 2024 at 11:18:53PM +0000, Thinh Nguyen wrote: > On Fri, Aug 09, 2024, Frank Li wrote: > > On Wed, Aug 07, 2024 at 01:13:52AM +0000, Thinh Nguyen wrote: > > > On Fri, Jul 12, 2024, Frank Li wrote: > > > > From: Li Jun <jun.li@nxp.com> > > > > > > > > The runtime resume will happen before system resume if system wakeup by > > > > device mode wakeup event(e.g, VBUS). Add a flag to avoid init twice. > > > > > > What's the consequence of going through the resuming sequence twice? > > > Will this cause any functional issue? > > > > static int dwc3_core_init_for_resume(struct dwc3 *dwc) > > { > > > > ... > > ret = dwc3_clk_enable(dwc); > > if (ret) > > goto assert_reset; > > > > ... > > } > > > > clk will be enabled twice, the reference count in clk will be wrong because > > clk_disable() only once at suspend. > > Please capture these info in the commit message. > > > > > So clk will be always ON at next suspend. > > > > Frank Li > > > > dwc3_clk_enable() happens in probe() and dwc3_core_init_for_resume(), > but you're checking dwc->core_inited in dwc3_core_init(). Why? I have not check dwc->core_inited in dwc3_core_init(). Just set init value dwc->core_inited = true Do you means dwc3_core_init() as dwc3_resume_common()? > > If the issue is only related to clk_enable(), perhaps just check that? This should be major one. Any paired operator between suspend/resume should have issue. Frank > > (minor nit: rename core_inited to core_initialized if you plan to do > that) > > Thanks, > Thinh > > > > > > > > > Reviewed-by: Peter Chen <peter.chen@nxp.com> > > > > Signed-off-by: Li Jun <jun.li@nxp.com> > > > > Signed-off-by: Frank Li <Frank.Li@nxp.com> > > > > --- > > > > drivers/usb/dwc3/core.c | 13 +++++++++++++ > > > > drivers/usb/dwc3/core.h | 1 + > > > > 2 files changed, 14 insertions(+) > > > > > > > > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c > > > > index 734de2a8bd212..d60917fad8c52 100644 > > > > --- a/drivers/usb/dwc3/core.c > > > > +++ b/drivers/usb/dwc3/core.c > > > > @@ -950,6 +950,8 @@ static void dwc3_core_exit(struct dwc3 *dwc) > > > > dwc3_phy_exit(dwc); > > > > dwc3_clk_disable(dwc); > > > > reset_control_assert(dwc->reset); > > > > + > > > > + dwc->core_inited = false; > > > > } > > > > > > > > static bool dwc3_core_is_valid(struct dwc3 *dwc) > > > > @@ -1446,6 +1448,8 @@ static int dwc3_core_init(struct dwc3 *dwc) > > > > dwc3_writel(dwc->regs, DWC3_LLUCTL, reg); > > > > } > > > > > > > > + dwc->core_inited = true; > > > > + > > > > return 0; > > > > > > > > err_power_off_phy: > > > > @@ -2375,6 +2379,15 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) > > > > > > > > switch (dwc->current_dr_role) { > > > > case DWC3_GCTL_PRTCAP_DEVICE: > > > > + /* > > > > + * system resume may come after runtime resume > > > > + * e.g. rpm suspend -> pm suspend -> wakeup > > > > + * -> rpm resume -> system resume, so if already > > > > + * runtime resumed, system resume should skip it. > > > > + */ > > > > + if (dwc->core_inited) > > > > + break; > > > > + > > > > ret = dwc3_core_init_for_resume(dwc); > > > > if (ret) > > > > return ret; > > > > diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h > > > > index 1e561fd8b86e2..8a4bfd9a25b19 100644 > > > > --- a/drivers/usb/dwc3/core.h > > > > +++ b/drivers/usb/dwc3/core.h > > > > @@ -1195,6 +1195,7 @@ struct dwc3 { > > > > struct clk *utmi_clk; > > > > struct clk *pipe_clk; > > > > > > > > + bool core_inited; > > > > struct reset_control *reset; > > > > > > > > struct usb_phy *usb2_phy; > > > > > > > > -- > > > > 2.34.1 > > > >
On Tue, Aug 13, 2024, Frank Li wrote: > On Fri, Aug 09, 2024 at 11:18:53PM +0000, Thinh Nguyen wrote: > > On Fri, Aug 09, 2024, Frank Li wrote: > > > On Wed, Aug 07, 2024 at 01:13:52AM +0000, Thinh Nguyen wrote: > > > > On Fri, Jul 12, 2024, Frank Li wrote: > > > > > From: Li Jun <jun.li@nxp.com> > > > > > > > > > > The runtime resume will happen before system resume if system wakeup by > > > > > device mode wakeup event(e.g, VBUS). Add a flag to avoid init twice. > > > > > > > > What's the consequence of going through the resuming sequence twice? > > > > Will this cause any functional issue? > > > > > > static int dwc3_core_init_for_resume(struct dwc3 *dwc) > > > { > > > > > > ... > > > ret = dwc3_clk_enable(dwc); > > > if (ret) > > > goto assert_reset; > > > > > > ... > > > } > > > > > > clk will be enabled twice, the reference count in clk will be wrong because > > > clk_disable() only once at suspend. > > > > Please capture these info in the commit message. > > > > > > > > So clk will be always ON at next suspend. > > > > > > Frank Li > > > > > > > dwc3_clk_enable() happens in probe() and dwc3_core_init_for_resume(), > > but you're checking dwc->core_inited in dwc3_core_init(). Why? > > I have not check dwc->core_inited in dwc3_core_init(). Just set init value > dwc->core_inited = true > > Do you means dwc3_core_init() as dwc3_resume_common()? > You set the dwc->core_inited in dwc3_core_init(). However, you use this flag to also check if dwc3_clk_enable() is done. dwc3_clk_enable() is not done in dwc3_core_init(). > > > > If the issue is only related to clk_enable(), perhaps just check that? > > This should be major one. Any paired operator between suspend/resume should > have issue. > I don't know what else could be a problem in dwc3_core_init(). As far as I know, it's only dwc3_clk_enable(). I questioned because of the mismatch use of the check, where the issue you mentioned is outside of dwc3_core_init(). Perhaps the flag should not be set there. If that's the case, rename the flag to match the check condition (if necessary). > > > > > (minor nit: rename core_inited to core_initialized if you plan to do > > that) > > > > Thanks, > > Thinh > > > > > > > > > > > > Reviewed-by: Peter Chen <peter.chen@nxp.com> > > > > > Signed-off-by: Li Jun <jun.li@nxp.com> > > > > > Signed-off-by: Frank Li <Frank.Li@nxp.com> > > > > > --- > > > > > drivers/usb/dwc3/core.c | 13 +++++++++++++ > > > > > drivers/usb/dwc3/core.h | 1 + > > > > > 2 files changed, 14 insertions(+) > > > > > > > > > > diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c > > > > > index 734de2a8bd212..d60917fad8c52 100644 > > > > > --- a/drivers/usb/dwc3/core.c > > > > > +++ b/drivers/usb/dwc3/core.c > > > > > @@ -950,6 +950,8 @@ static void dwc3_core_exit(struct dwc3 *dwc) > > > > > dwc3_phy_exit(dwc); > > > > > dwc3_clk_disable(dwc); > > > > > reset_control_assert(dwc->reset); > > > > > + > > > > > + dwc->core_inited = false; > > > > > } > > > > > > > > > > static bool dwc3_core_is_valid(struct dwc3 *dwc) > > > > > @@ -1446,6 +1448,8 @@ static int dwc3_core_init(struct dwc3 *dwc) > > > > > dwc3_writel(dwc->regs, DWC3_LLUCTL, reg); > > > > > } > > > > > > > > > > + dwc->core_inited = true; > > > > > + > > > > > return 0; > > > > > > > > > > err_power_off_phy: > > > > > @@ -2375,6 +2379,15 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) > > > > > > > > > > switch (dwc->current_dr_role) { > > > > > case DWC3_GCTL_PRTCAP_DEVICE: > > > > > + /* > > > > > + * system resume may come after runtime resume > > > > > + * e.g. rpm suspend -> pm suspend -> wakeup > > > > > + * -> rpm resume -> system resume, so if already > > > > > + * runtime resumed, system resume should skip it. > > > > > + */ > > > > > + if (dwc->core_inited) > > > > > + break; > > > > > + > > > > > ret = dwc3_core_init_for_resume(dwc); > > > > > if (ret) > > > > > return ret; > > > > > diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h > > > > > index 1e561fd8b86e2..8a4bfd9a25b19 100644 > > > > > --- a/drivers/usb/dwc3/core.h > > > > > +++ b/drivers/usb/dwc3/core.h > > > > > @@ -1195,6 +1195,7 @@ struct dwc3 { > > > > > struct clk *utmi_clk; > > > > > struct clk *pipe_clk; > > > > > > > > > > + bool core_inited; Document new member of the struct. > > > > > struct reset_control *reset; > > > > > > > > > > struct usb_phy *usb2_phy; > > > > > > > > > > -- > > > > > 2.34.1 > > > > > Thanks, Thinh
diff --git a/drivers/usb/dwc3/core.c b/drivers/usb/dwc3/core.c index 734de2a8bd212..d60917fad8c52 100644 --- a/drivers/usb/dwc3/core.c +++ b/drivers/usb/dwc3/core.c @@ -950,6 +950,8 @@ static void dwc3_core_exit(struct dwc3 *dwc) dwc3_phy_exit(dwc); dwc3_clk_disable(dwc); reset_control_assert(dwc->reset); + + dwc->core_inited = false; } static bool dwc3_core_is_valid(struct dwc3 *dwc) @@ -1446,6 +1448,8 @@ static int dwc3_core_init(struct dwc3 *dwc) dwc3_writel(dwc->regs, DWC3_LLUCTL, reg); } + dwc->core_inited = true; + return 0; err_power_off_phy: @@ -2375,6 +2379,15 @@ static int dwc3_resume_common(struct dwc3 *dwc, pm_message_t msg) switch (dwc->current_dr_role) { case DWC3_GCTL_PRTCAP_DEVICE: + /* + * system resume may come after runtime resume + * e.g. rpm suspend -> pm suspend -> wakeup + * -> rpm resume -> system resume, so if already + * runtime resumed, system resume should skip it. + */ + if (dwc->core_inited) + break; + ret = dwc3_core_init_for_resume(dwc); if (ret) return ret; diff --git a/drivers/usb/dwc3/core.h b/drivers/usb/dwc3/core.h index 1e561fd8b86e2..8a4bfd9a25b19 100644 --- a/drivers/usb/dwc3/core.h +++ b/drivers/usb/dwc3/core.h @@ -1195,6 +1195,7 @@ struct dwc3 { struct clk *utmi_clk; struct clk *pipe_clk; + bool core_inited; struct reset_control *reset; struct usb_phy *usb2_phy;