Linux-USB Archive on lore.kernel.org
 help / color / Atom feed
From: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>
To: Artur Petrosyan <Arthur.Petrosyan@synopsys.com>,
	Felipe Balbi <balbi@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	Douglas Anderson <dianders@chromium.org>
Cc: John Youn <John.Youn@synopsys.com>,
	Paul Zimmerman <paulz@synopsys.com>,
	"stable@vger.kernel.org" <stable@vger.kernel.org>,
	Kever Yang <kever.yang@rock-chips.com>
Subject: Re: [PATCH v3 13/14] usb: dwc2: Fix partial power down exiting by system resume
Date: Thu, 8 Apr 2021 13:40:52 +0000
Message-ID: <93c724db-3f71-09c1-1c8f-cb931b793740@synopsys.com> (raw)
In-Reply-To: <20210408094607.1A9BAA0094@mailhost.synopsys.com>

On 4/8/2021 1:46 PM, Artur Petrosyan wrote:
> Fixes the implementation of exiting from partial power down
> power saving mode when PC is resumed.
> 
> Added port connection status checking which prevents exiting from
> Partial Power Down mode from _dwc2_hcd_resume() if not in Partial
> Power Down mode.
> 
> Rearranged the implementation to get rid of many "if"
> statements.
> 
> NOTE: Switch case statement is used for hibernation partial
> power down and clock gating mode determination. In this patch
> only Partial Power Down is implemented the Hibernation and
> clock gating implementations are planned to be added.
> 
> Cc: <stable@vger.kernel.org>
> Fixes: 6f6d70597c15 ("usb: dwc2: bus suspend/resume for hosts with DWC2_POWER_DOWN_PARAM_NONE")
> Signed-off-by: Artur Petrosyan <Arthur.Petrosyan@synopsys.com>

Acked-by: Minas Harutyunyan <Minas.Harutyunyan@synopsys.com>

> ---
>   Changes in v3:
>   - None
>   Changes in v2:
>   - None
> 
>   drivers/usb/dwc2/hcd.c | 90 +++++++++++++++++++++---------------------
>   1 file changed, 46 insertions(+), 44 deletions(-)
> 
> diff --git a/drivers/usb/dwc2/hcd.c b/drivers/usb/dwc2/hcd.c
> index 34030bafdff4..f096006df96f 100644
> --- a/drivers/usb/dwc2/hcd.c
> +++ b/drivers/usb/dwc2/hcd.c
> @@ -4427,7 +4427,7 @@ static int _dwc2_hcd_resume(struct usb_hcd *hcd)
>   {
>   	struct dwc2_hsotg *hsotg = dwc2_hcd_to_hsotg(hcd);
>   	unsigned long flags;
> -	u32 pcgctl;
> +	u32 hprt0;
>   	int ret = 0;
>   
>   	spin_lock_irqsave(&hsotg->lock, flags);
> @@ -4438,11 +4438,40 @@ static int _dwc2_hcd_resume(struct usb_hcd *hcd)
>   	if (hsotg->lx_state != DWC2_L2)
>   		goto unlock;
>   
> -	if (hsotg->params.power_down > DWC2_POWER_DOWN_PARAM_PARTIAL) {
> +	hprt0 = dwc2_read_hprt0(hsotg);
> +
> +	/*
> +	 * Added port connection status checking which prevents exiting from
> +	 * Partial Power Down mode from _dwc2_hcd_resume() if not in Partial
> +	 * Power Down mode.
> +	 */
> +	if (hprt0 & HPRT0_CONNSTS) {
> +		hsotg->lx_state = DWC2_L0;
> +		goto unlock;
> +	}
> +
> +	switch (hsotg->params.power_down) {
> +	case DWC2_POWER_DOWN_PARAM_PARTIAL:
> +		ret = dwc2_exit_partial_power_down(hsotg, 0, true);
> +		if (ret)
> +			dev_err(hsotg->dev,
> +				"exit partial_power_down failed\n");
> +		/*
> +		 * Set HW accessible bit before powering on the controller
> +		 * since an interrupt may rise.
> +		 */
> +		set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
> +		break;
> +	case DWC2_POWER_DOWN_PARAM_HIBERNATION:
> +	case DWC2_POWER_DOWN_PARAM_NONE:
> +	default:
>   		hsotg->lx_state = DWC2_L0;
>   		goto unlock;
>   	}
>   
> +	/* Change Root port status, as port status change occurred after resume.*/
> +	hsotg->flags.b.port_suspend_change = 1;
> +
>   	/*
>   	 * Enable power if not already done.
>   	 * This must not be spinlocked since duration
> @@ -4454,52 +4483,25 @@ static int _dwc2_hcd_resume(struct usb_hcd *hcd)
>   		spin_lock_irqsave(&hsotg->lock, flags);
>   	}
>   
> -	if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_PARTIAL) {
> -		/*
> -		 * Set HW accessible bit before powering on the controller
> -		 * since an interrupt may rise.
> -		 */
> -		set_bit(HCD_FLAG_HW_ACCESSIBLE, &hcd->flags);
> -
> -
> -		/* Exit partial_power_down */
> -		ret = dwc2_exit_partial_power_down(hsotg, 0, true);
> -		if (ret && (ret != -ENOTSUPP))
> -			dev_err(hsotg->dev, "exit partial_power_down failed\n");
> -	} else {
> -		pcgctl = readl(hsotg->regs + PCGCTL);
> -		pcgctl &= ~PCGCTL_STOPPCLK;
> -		writel(pcgctl, hsotg->regs + PCGCTL);
> -	}
> -
> -	hsotg->lx_state = DWC2_L0;
> -
> +	/* Enable external vbus supply after resuming the port. */
>   	spin_unlock_irqrestore(&hsotg->lock, flags);
> +	dwc2_vbus_supply_init(hsotg);
>   
> -	if (hsotg->bus_suspended) {
> -		spin_lock_irqsave(&hsotg->lock, flags);
> -		hsotg->flags.b.port_suspend_change = 1;
> -		spin_unlock_irqrestore(&hsotg->lock, flags);
> -		dwc2_port_resume(hsotg);
> -	} else {
> -		if (hsotg->params.power_down == DWC2_POWER_DOWN_PARAM_PARTIAL) {
> -			dwc2_vbus_supply_init(hsotg);
> -
> -			/* Wait for controller to correctly update D+/D- level */
> -			usleep_range(3000, 5000);
> -		}
> +	/* Wait for controller to correctly update D+/D- level */
> +	usleep_range(3000, 5000);
> +	spin_lock_irqsave(&hsotg->lock, flags);
>   
> -		/*
> -		 * Clear Port Enable and Port Status changes.
> -		 * Enable Port Power.
> -		 */
> -		dwc2_writel(hsotg, HPRT0_PWR | HPRT0_CONNDET |
> -				HPRT0_ENACHG, HPRT0);
> -		/* Wait for controller to detect Port Connect */
> -		usleep_range(5000, 7000);
> -	}
> +	/*
> +	 * Clear Port Enable and Port Status changes.
> +	 * Enable Port Power.
> +	 */
> +	dwc2_writel(hsotg, HPRT0_PWR | HPRT0_CONNDET |
> +			HPRT0_ENACHG, HPRT0);
>   
> -	return ret;
> +	/* Wait for controller to detect Port Connect */
> +	spin_unlock_irqrestore(&hsotg->lock, flags);
> +	usleep_range(5000, 7000);
> +	spin_lock_irqsave(&hsotg->lock, flags);
>   unlock:
>   	spin_unlock_irqrestore(&hsotg->lock, flags);
>   
> 


  reply index

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-07 10:00 [PATCH 00/14] usb: dwc2: Fix Partial Power down issues Artur Petrosyan
2021-04-07 10:08 ` [PATCH 13/14] usb: dwc2: Fix partial power down exiting by system resume Artur Petrosyan
2021-04-08  5:57 ` [PATCH 00/14] usb: dwc2: Fix Partial Power down issues Artur Petrosyan
2021-04-08  6:09   ` Greg Kroah-Hartman
2021-04-08  7:28 ` [PATCH v2 " Artur Petrosyan
2021-04-08  9:17   ` Artur Petrosyan
2021-04-08 10:09     ` Artur Petrosyan
2021-04-08 11:00       ` Greg Kroah-Hartman
2021-04-08  7:30 ` [PATCH v2 13/14] usb: dwc2: Fix partial power down exiting by system resume Artur Petrosyan
2021-04-08  9:44 ` [PATCH v3 00/14] usb: dwc2: Fix Partial Power down issues Artur Petrosyan
2021-04-08  9:44 ` [PATCH v3 01/14] usb: dwc2: Add device partial power down functions Artur Petrosyan
2021-04-08  9:44 ` [PATCH v3 02/14] usb: dwc2: Add host " Artur Petrosyan
2021-04-08  9:44 ` [PATCH v3 03/14] usb: dwc2: Update enter and exit " Artur Petrosyan
2021-04-08  9:44 ` [PATCH v3 04/14] usb: dwc2: Add partial power down exit flow in wakeup intr Artur Petrosyan
2021-04-08  9:45 ` [PATCH v3 05/14] usb: dwc2: Update port suspend/resume function definitions Artur Petrosyan
2021-04-08 13:39   ` Minas Harutyunyan
2021-04-08  9:45 ` [PATCH v3 06/14] usb: dwc2: Add enter partial power down when port is suspended Artur Petrosyan
2021-04-08 13:39   ` Minas Harutyunyan
2021-04-08  9:45 ` [PATCH v3 07/14] usb: dwc2: Add exit partial power down when port is resumed Artur Petrosyan
2021-04-08 13:39   ` Minas Harutyunyan
2021-04-08  9:45 ` [PATCH v3 08/14] usb: dwc2: Add exit partial power down when port reset is asserted Artur Petrosyan
2021-04-08 13:39   ` Minas Harutyunyan
2021-04-08  9:45 ` [PATCH v3 09/14] usb: dwc2: Add part. power down exit from dwc2_conn_id_status_change() Artur Petrosyan
2021-04-08  9:45 ` [PATCH v3 10/14] usb: dwc2: Allow exit partial power down in urb enqueue Artur Petrosyan
2021-04-08 13:40   ` Minas Harutyunyan
2021-04-08  9:45 ` [PATCH v3 11/14] usb: dwc2: Fix session request interrupt handler Artur Petrosyan
2021-04-08  9:45 ` [PATCH v3 12/14] usb: dwc2: Update partial power down entering by system suspend Artur Petrosyan
2021-04-08 13:40   ` Minas Harutyunyan
2021-04-08  9:46 ` [PATCH v3 13/14] usb: dwc2: Fix partial power down exiting by system resume Artur Petrosyan
2021-04-08 13:40   ` Minas Harutyunyan [this message]
2021-04-08  9:46 ` [PATCH v3 14/14] usb: dwc2: Add exit partial power down before removing driver Artur Petrosyan
2021-04-08 13:41   ` Minas Harutyunyan

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=93c724db-3f71-09c1-1c8f-cb931b793740@synopsys.com \
    --to=minas.harutyunyan@synopsys.com \
    --cc=Arthur.Petrosyan@synopsys.com \
    --cc=John.Youn@synopsys.com \
    --cc=balbi@kernel.org \
    --cc=dianders@chromium.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=kever.yang@rock-chips.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=paulz@synopsys.com \
    --cc=stable@vger.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

Linux-USB Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-usb/0 linux-usb/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-usb linux-usb/ https://lore.kernel.org/linux-usb \
		linux-usb@vger.kernel.org
	public-inbox-index linux-usb

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-usb


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git