mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Thinh Nguyen <Thinh.Nguyen@synopsys.com>
To: Frank Li <Frank.li@nxp.com>
Cc: Thinh Nguyen <Thinh.Nguyen@synopsys.com>,
	Mathias Nyman <mathias.nyman@intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Shawn Guo <shawnguo@kernel.org>,
	Sascha Hauer <s.hauer@pengutronix.de>,
	Pengutronix Kernel Team <kernel@pengutronix.de>,
	Fabio Estevam <festevam@gmail.com>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"imx@lists.linux.dev" <imx@lists.linux.dev>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"jun.li@nxp.com" <jun.li@nxp.com>,
	Peter Chen <peter.chen@nxp.com>
Subject: Re: [PATCH 3/4] usb: dwc3: core: add a core init flag for device mode resume
Date: Tue, 13 Aug 2024 23:56:48 +0000	[thread overview]
Message-ID: <20240813235642.zaxom3jbuomfwghf@synopsys.com> (raw)
In-Reply-To: <ZruQZ/Y/aqIcO0tq@lizhi-Precision-Tower-5810>

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

  reply	other threads:[~2024-08-13 23:57 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-12 15:40 [PATCH 0/4] usb: imx8mp: collect some improvement Frank Li
2024-07-12 15:40 ` [PATCH 1/4] usb: host: xhci-plat: Parse xhci-missing_cas_quirk and apply quirk Frank Li
2024-07-12 15:40 ` [PATCH 2/4] usb: dwc3: imx8mp: add 2 software managed quirk properties for host mode Frank Li
2024-08-07  1:08   ` Thinh Nguyen
2024-07-12 15:40 ` [PATCH 3/4] usb: dwc3: core: add a core init flag for device mode resume Frank Li
2024-08-07  1:13   ` Thinh Nguyen
2024-08-09 16:25     ` Frank Li
2024-08-09 23:18       ` Thinh Nguyen
2024-08-13 16:57         ` Frank Li
2024-08-13 23:56           ` Thinh Nguyen [this message]
2024-07-12 15:40 ` [PATCH 4/4] usb: dwc3: imx8mp: disable SS_CON and U3 wakeup for system sleep Frank Li
2024-08-07  1:20   ` Thinh Nguyen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240813235642.zaxom3jbuomfwghf@synopsys.com \
    --to=thinh.nguyen@synopsys.com \
    --cc=Frank.li@nxp.com \
    --cc=festevam@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=imx@lists.linux.dev \
    --cc=jun.li@nxp.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=mathias.nyman@intel.com \
    --cc=peter.chen@nxp.com \
    --cc=s.hauer@pengutronix.de \
    --cc=shawnguo@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®