linux-tegra.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v1 1/2] usb: phy: tegra: Wait for VBUS wakeup status deassertion on suspend
@ 2021-06-13 14:59 Dmitry Osipenko
  2021-06-13 14:59 ` [PATCH v1 2/2] usb: phy: tegra: Correct definition of B_SESS_VLD_WAKEUP_EN bit Dmitry Osipenko
                   ` (3 more replies)
  0 siblings, 4 replies; 6+ messages in thread
From: Dmitry Osipenko @ 2021-06-13 14:59 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Peter Chen, Greg Kroah-Hartman,
	Felipe Balbi, Maxim Schwalm
  Cc: linux-tegra, linux-usb, linux-kernel

Some devices need an extra delay after losing VBUS, otherwise VBUS may
be detected as active at suspend time, preventing the PHY's suspension
by the VBUS detection sensor. This problem was found on Asus Transformer
TF700T (Tegra30) tablet device, where the USB PHY wakes up immediately
from suspend because VBUS sensor continues to detect VBUS as active after
disconnection. We need to poll the PHY's VBUS wakeup status until it's
deasserted before suspending PHY in order to fix this minor trouble.

Fixes: 35192007d28d ("usb: phy: tegra: Support waking up from a low power mode")
Reported-by: Maxim Schwalm <maxim.schwalm@gmail.com> # Asus TF700T
Tested-by: Maxim Schwalm <maxim.schwalm@gmail.com> # Asus TF700T
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/usb/phy/phy-tegra-usb.c | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/drivers/usb/phy/phy-tegra-usb.c b/drivers/usb/phy/phy-tegra-usb.c
index fc5c6cab58ba..ff482c694200 100644
--- a/drivers/usb/phy/phy-tegra-usb.c
+++ b/drivers/usb/phy/phy-tegra-usb.c
@@ -64,6 +64,7 @@
 #define   A_VBUS_VLD_WAKEUP_EN			BIT(30)
 
 #define USB_PHY_VBUS_WAKEUP_ID			0x408
+#define   VBUS_WAKEUP_STS			BIT(10)
 #define   VBUS_WAKEUP_WAKEUP_EN			BIT(30)
 
 #define USB1_LEGACY_CTRL			0x410
@@ -645,6 +646,15 @@ static int utmi_phy_power_off(struct tegra_usb_phy *phy)
 	void __iomem *base = phy->regs;
 	u32 val;
 
+	/*
+	 * Give hardware time to settle down after VBUS disconnection,
+	 * otherwise PHY will immediately wake up from suspend.
+	 */
+	if (phy->wakeup_enabled && phy->mode != USB_DR_MODE_HOST)
+		readl_relaxed_poll_timeout(base + USB_PHY_VBUS_WAKEUP_ID,
+					   val, !(val & VBUS_WAKEUP_STS),
+					   5000, 100000);
+
 	utmi_phy_clk_disable(phy);
 
 	/* PHY won't resume if reset is asserted */
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* [PATCH v1 2/2] usb: phy: tegra: Correct definition of B_SESS_VLD_WAKEUP_EN bit
  2021-06-13 14:59 [PATCH v1 1/2] usb: phy: tegra: Wait for VBUS wakeup status deassertion on suspend Dmitry Osipenko
@ 2021-06-13 14:59 ` Dmitry Osipenko
  2021-06-15  1:05 ` [PATCH v1 1/2] usb: phy: tegra: Wait for VBUS wakeup status deassertion on suspend Peter Chen
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 6+ messages in thread
From: Dmitry Osipenko @ 2021-06-13 14:59 UTC (permalink / raw)
  To: Thierry Reding, Jonathan Hunter, Peter Chen, Greg Kroah-Hartman,
	Felipe Balbi, Maxim Schwalm
  Cc: linux-tegra, linux-usb, linux-kernel

The B_SESS_VLD_WAKEUP_EN bit 6 was added by a mistake in a previous
commit. This bit corresponds to B_SESS_END_WAKEUP_EN, which we don't use.
The B_VBUS_VLD_WAKEUP_EN doesn't exist at all and B_SESS_VLD_WAKEUP_EN
needs to be in place of it. We don't utilize B-sensors in the driver,
so it never was a problem, nevertheless let's correct the definition of
the bits.

Fixes: 35192007d28d ("usb: phy: tegra: Support waking up from a low power mode")
Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
---
 drivers/usb/phy/phy-tegra-usb.c | 5 ++---
 1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/usb/phy/phy-tegra-usb.c b/drivers/usb/phy/phy-tegra-usb.c
index ff482c694200..cd425b937750 100644
--- a/drivers/usb/phy/phy-tegra-usb.c
+++ b/drivers/usb/phy/phy-tegra-usb.c
@@ -58,8 +58,7 @@
 #define   USB_WAKEUP_DEBOUNCE_COUNT(x)		(((x) & 0x7) << 16)
 
 #define USB_PHY_VBUS_SENSORS			0x404
-#define   B_SESS_VLD_WAKEUP_EN			BIT(6)
-#define   B_VBUS_VLD_WAKEUP_EN			BIT(14)
+#define   B_SESS_VLD_WAKEUP_EN			BIT(14)
 #define   A_SESS_VLD_WAKEUP_EN			BIT(22)
 #define   A_VBUS_VLD_WAKEUP_EN			BIT(30)
 
@@ -548,7 +547,7 @@ static int utmi_phy_power_on(struct tegra_usb_phy *phy)
 
 		val = readl_relaxed(base + USB_PHY_VBUS_SENSORS);
 		val &= ~(A_VBUS_VLD_WAKEUP_EN | A_SESS_VLD_WAKEUP_EN);
-		val &= ~(B_VBUS_VLD_WAKEUP_EN | B_SESS_VLD_WAKEUP_EN);
+		val &= ~(B_SESS_VLD_WAKEUP_EN);
 		writel_relaxed(val, base + USB_PHY_VBUS_SENSORS);
 
 		val = readl_relaxed(base + UTMIP_BAT_CHRG_CFG0);
-- 
2.30.2


^ permalink raw reply related	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 1/2] usb: phy: tegra: Wait for VBUS wakeup status deassertion on suspend
  2021-06-13 14:59 [PATCH v1 1/2] usb: phy: tegra: Wait for VBUS wakeup status deassertion on suspend Dmitry Osipenko
  2021-06-13 14:59 ` [PATCH v1 2/2] usb: phy: tegra: Correct definition of B_SESS_VLD_WAKEUP_EN bit Dmitry Osipenko
@ 2021-06-15  1:05 ` Peter Chen
  2021-06-15 14:48   ` Dmitry Osipenko
  2021-06-15  1:06 ` Peter Chen
  2021-06-16  0:56 ` Peter Chen
  3 siblings, 1 reply; 6+ messages in thread
From: Peter Chen @ 2021-06-15  1:05 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: Thierry Reding, Jonathan Hunter, Greg Kroah-Hartman,
	Felipe Balbi, Maxim Schwalm, linux-tegra, linux-usb,
	linux-kernel

On 21-06-13 17:59:35, Dmitry Osipenko wrote:
> Some devices need an extra delay after losing VBUS, otherwise VBUS may
> be detected as active at suspend time, preventing the PHY's suspension
> by the VBUS detection sensor. This problem was found on Asus Transformer
> TF700T (Tegra30) tablet device, where the USB PHY wakes up immediately
> from suspend because VBUS sensor continues to detect VBUS as active after
> disconnection. We need to poll the PHY's VBUS wakeup status until it's
> deasserted before suspending PHY in order to fix this minor trouble.
> 
> Fixes: 35192007d28d ("usb: phy: tegra: Support waking up from a low power mode")
> Reported-by: Maxim Schwalm <maxim.schwalm@gmail.com> # Asus TF700T
> Tested-by: Maxim Schwalm <maxim.schwalm@gmail.com> # Asus TF700T
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
>  drivers/usb/phy/phy-tegra-usb.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/usb/phy/phy-tegra-usb.c b/drivers/usb/phy/phy-tegra-usb.c
> index fc5c6cab58ba..ff482c694200 100644
> --- a/drivers/usb/phy/phy-tegra-usb.c
> +++ b/drivers/usb/phy/phy-tegra-usb.c
> @@ -64,6 +64,7 @@
>  #define   A_VBUS_VLD_WAKEUP_EN			BIT(30)
>  
>  #define USB_PHY_VBUS_WAKEUP_ID			0x408
> +#define   VBUS_WAKEUP_STS			BIT(10)
>  #define   VBUS_WAKEUP_WAKEUP_EN			BIT(30)
>  
>  #define USB1_LEGACY_CTRL			0x410
> @@ -645,6 +646,15 @@ static int utmi_phy_power_off(struct tegra_usb_phy *phy)
>  	void __iomem *base = phy->regs;
>  	u32 val;
>  
> +	/*
> +	 * Give hardware time to settle down after VBUS disconnection,
> +	 * otherwise PHY will immediately wake up from suspend.
> +	 */
> +	if (phy->wakeup_enabled && phy->mode != USB_DR_MODE_HOST)
> +		readl_relaxed_poll_timeout(base + USB_PHY_VBUS_WAKEUP_ID,
> +					   val, !(val & VBUS_WAKEUP_STS),
> +					   5000, 100000);
> +

Where will clear VBUS_WAKEUP_STS? Or it will be cleared by HW after VBUS lower than
B Session Valid?

-- 

Thanks,
Peter Chen


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 1/2] usb: phy: tegra: Wait for VBUS wakeup status deassertion on suspend
  2021-06-13 14:59 [PATCH v1 1/2] usb: phy: tegra: Wait for VBUS wakeup status deassertion on suspend Dmitry Osipenko
  2021-06-13 14:59 ` [PATCH v1 2/2] usb: phy: tegra: Correct definition of B_SESS_VLD_WAKEUP_EN bit Dmitry Osipenko
  2021-06-15  1:05 ` [PATCH v1 1/2] usb: phy: tegra: Wait for VBUS wakeup status deassertion on suspend Peter Chen
@ 2021-06-15  1:06 ` Peter Chen
  2021-06-16  0:56 ` Peter Chen
  3 siblings, 0 replies; 6+ messages in thread
From: Peter Chen @ 2021-06-15  1:06 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: Thierry Reding, Jonathan Hunter, Greg Kroah-Hartman,
	Felipe Balbi, Maxim Schwalm, linux-tegra, linux-usb,
	linux-kernel

On 21-06-13 17:59:35, Dmitry Osipenko wrote:
> Some devices need an extra delay after losing VBUS, otherwise VBUS may
> be detected as active at suspend time, preventing the PHY's suspension
> by the VBUS detection sensor. This problem was found on Asus Transformer
> TF700T (Tegra30) tablet device, where the USB PHY wakes up immediately
> from suspend because VBUS sensor continues to detect VBUS as active after
> disconnection. We need to poll the PHY's VBUS wakeup status until it's
> deasserted before suspending PHY in order to fix this minor trouble.
> 
> Fixes: 35192007d28d ("usb: phy: tegra: Support waking up from a low power mode")
> Reported-by: Maxim Schwalm <maxim.schwalm@gmail.com> # Asus TF700T
> Tested-by: Maxim Schwalm <maxim.schwalm@gmail.com> # Asus TF700T
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>

Reviewed-by: Peter Chen <peter.chen@kernel.org>
> ---
>  drivers/usb/phy/phy-tegra-usb.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/usb/phy/phy-tegra-usb.c b/drivers/usb/phy/phy-tegra-usb.c
> index fc5c6cab58ba..ff482c694200 100644
> --- a/drivers/usb/phy/phy-tegra-usb.c
> +++ b/drivers/usb/phy/phy-tegra-usb.c
> @@ -64,6 +64,7 @@
>  #define   A_VBUS_VLD_WAKEUP_EN			BIT(30)
>  
>  #define USB_PHY_VBUS_WAKEUP_ID			0x408
> +#define   VBUS_WAKEUP_STS			BIT(10)
>  #define   VBUS_WAKEUP_WAKEUP_EN			BIT(30)
>  
>  #define USB1_LEGACY_CTRL			0x410
> @@ -645,6 +646,15 @@ static int utmi_phy_power_off(struct tegra_usb_phy *phy)
>  	void __iomem *base = phy->regs;
>  	u32 val;
>  
> +	/*
> +	 * Give hardware time to settle down after VBUS disconnection,
> +	 * otherwise PHY will immediately wake up from suspend.
> +	 */
> +	if (phy->wakeup_enabled && phy->mode != USB_DR_MODE_HOST)
> +		readl_relaxed_poll_timeout(base + USB_PHY_VBUS_WAKEUP_ID,
> +					   val, !(val & VBUS_WAKEUP_STS),
> +					   5000, 100000);
> +
>  	utmi_phy_clk_disable(phy);
>  
>  	/* PHY won't resume if reset is asserted */
> -- 
> 2.30.2
> 

-- 

Thanks,
Peter Chen


^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 1/2] usb: phy: tegra: Wait for VBUS wakeup status deassertion on suspend
  2021-06-15  1:05 ` [PATCH v1 1/2] usb: phy: tegra: Wait for VBUS wakeup status deassertion on suspend Peter Chen
@ 2021-06-15 14:48   ` Dmitry Osipenko
  0 siblings, 0 replies; 6+ messages in thread
From: Dmitry Osipenko @ 2021-06-15 14:48 UTC (permalink / raw)
  To: Peter Chen
  Cc: Thierry Reding, Jonathan Hunter, Greg Kroah-Hartman,
	Felipe Balbi, Maxim Schwalm, linux-tegra, linux-usb,
	linux-kernel

15.06.2021 04:05, Peter Chen пишет:
> On 21-06-13 17:59:35, Dmitry Osipenko wrote:
>> Some devices need an extra delay after losing VBUS, otherwise VBUS may
>> be detected as active at suspend time, preventing the PHY's suspension
>> by the VBUS detection sensor. This problem was found on Asus Transformer
>> TF700T (Tegra30) tablet device, where the USB PHY wakes up immediately
>> from suspend because VBUS sensor continues to detect VBUS as active after
>> disconnection. We need to poll the PHY's VBUS wakeup status until it's
>> deasserted before suspending PHY in order to fix this minor trouble.
>>
>> Fixes: 35192007d28d ("usb: phy: tegra: Support waking up from a low power mode")
>> Reported-by: Maxim Schwalm <maxim.schwalm@gmail.com> # Asus TF700T
>> Tested-by: Maxim Schwalm <maxim.schwalm@gmail.com> # Asus TF700T
>> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
>> ---
>>  drivers/usb/phy/phy-tegra-usb.c | 10 ++++++++++
>>  1 file changed, 10 insertions(+)
>>
>> diff --git a/drivers/usb/phy/phy-tegra-usb.c b/drivers/usb/phy/phy-tegra-usb.c
>> index fc5c6cab58ba..ff482c694200 100644
>> --- a/drivers/usb/phy/phy-tegra-usb.c
>> +++ b/drivers/usb/phy/phy-tegra-usb.c
>> @@ -64,6 +64,7 @@
>>  #define   A_VBUS_VLD_WAKEUP_EN			BIT(30)
>>  
>>  #define USB_PHY_VBUS_WAKEUP_ID			0x408
>> +#define   VBUS_WAKEUP_STS			BIT(10)
>>  #define   VBUS_WAKEUP_WAKEUP_EN			BIT(30)
>>  
>>  #define USB1_LEGACY_CTRL			0x410
>> @@ -645,6 +646,15 @@ static int utmi_phy_power_off(struct tegra_usb_phy *phy)
>>  	void __iomem *base = phy->regs;
>>  	u32 val;
>>  
>> +	/*
>> +	 * Give hardware time to settle down after VBUS disconnection,
>> +	 * otherwise PHY will immediately wake up from suspend.
>> +	 */
>> +	if (phy->wakeup_enabled && phy->mode != USB_DR_MODE_HOST)
>> +		readl_relaxed_poll_timeout(base + USB_PHY_VBUS_WAKEUP_ID,
>> +					   val, !(val & VBUS_WAKEUP_STS),
>> +					   5000, 100000);
>> +
> 
> Where will clear VBUS_WAKEUP_STS? Or it will be cleared by HW after VBUS lower than
> B Session Valid?

It's cleared by hardware. Tegra documentation doesn't explicitly saying
what voltage level is used by the VBUS_WAKEUP sensor, but it implies the
session-valid level.

There are two sensors that could be used for detection of
cable-insertion into B-device USB port of Tegra: VBUS_WAKEUP and
A_SESS_VLD (from perspective of Tegra as a B-device).

The VBUS_WAKEUP sensor may not work in some hardware configurations,
always outputting 0. Seems it depends on whether port is OTG-capable
(VBUS_WAKEUP works) or fixed to a device mode. IIUC, only VBUS_WAKEUP
sensor can generate wake event that can resume system for a deepest
suspend state.

^ permalink raw reply	[flat|nested] 6+ messages in thread

* Re: [PATCH v1 1/2] usb: phy: tegra: Wait for VBUS wakeup status deassertion on suspend
  2021-06-13 14:59 [PATCH v1 1/2] usb: phy: tegra: Wait for VBUS wakeup status deassertion on suspend Dmitry Osipenko
                   ` (2 preceding siblings ...)
  2021-06-15  1:06 ` Peter Chen
@ 2021-06-16  0:56 ` Peter Chen
  3 siblings, 0 replies; 6+ messages in thread
From: Peter Chen @ 2021-06-16  0:56 UTC (permalink / raw)
  To: Dmitry Osipenko
  Cc: Thierry Reding, Jonathan Hunter, Greg Kroah-Hartman,
	Felipe Balbi, Maxim Schwalm, linux-tegra, linux-usb,
	linux-kernel

On 21-06-13 17:59:35, Dmitry Osipenko wrote:
> Some devices need an extra delay after losing VBUS, otherwise VBUS may
> be detected as active at suspend time, preventing the PHY's suspension
> by the VBUS detection sensor. This problem was found on Asus Transformer
> TF700T (Tegra30) tablet device, where the USB PHY wakes up immediately
> from suspend because VBUS sensor continues to detect VBUS as active after
> disconnection. We need to poll the PHY's VBUS wakeup status until it's
> deasserted before suspending PHY in order to fix this minor trouble.
> 
> Fixes: 35192007d28d ("usb: phy: tegra: Support waking up from a low power mode")
> Reported-by: Maxim Schwalm <maxim.schwalm@gmail.com> # Asus TF700T
> Tested-by: Maxim Schwalm <maxim.schwalm@gmail.com> # Asus TF700T
> Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
> ---
>  drivers/usb/phy/phy-tegra-usb.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/drivers/usb/phy/phy-tegra-usb.c b/drivers/usb/phy/phy-tegra-usb.c
> index fc5c6cab58ba..ff482c694200 100644
> --- a/drivers/usb/phy/phy-tegra-usb.c
> +++ b/drivers/usb/phy/phy-tegra-usb.c
> @@ -64,6 +64,7 @@
>  #define   A_VBUS_VLD_WAKEUP_EN			BIT(30)
>  
>  #define USB_PHY_VBUS_WAKEUP_ID			0x408
> +#define   VBUS_WAKEUP_STS			BIT(10)
>  #define   VBUS_WAKEUP_WAKEUP_EN			BIT(30)
>  
>  #define USB1_LEGACY_CTRL			0x410
> @@ -645,6 +646,15 @@ static int utmi_phy_power_off(struct tegra_usb_phy *phy)
>  	void __iomem *base = phy->regs;
>  	u32 val;
>  
> +	/*
> +	 * Give hardware time to settle down after VBUS disconnection,
> +	 * otherwise PHY will immediately wake up from suspend.
> +	 */
> +	if (phy->wakeup_enabled && phy->mode != USB_DR_MODE_HOST)
> +		readl_relaxed_poll_timeout(base + USB_PHY_VBUS_WAKEUP_ID,
> +					   val, !(val & VBUS_WAKEUP_STS),
> +					   5000, 100000);
> +

Reviewed-by: Peter Chen <peter.chen@kernel.org>


>  	utmi_phy_clk_disable(phy);
>  
>  	/* PHY won't resume if reset is asserted */
> -- 
> 2.30.2
> 

-- 

Thanks,
Peter Chen


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-06-16  0:56 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-13 14:59 [PATCH v1 1/2] usb: phy: tegra: Wait for VBUS wakeup status deassertion on suspend Dmitry Osipenko
2021-06-13 14:59 ` [PATCH v1 2/2] usb: phy: tegra: Correct definition of B_SESS_VLD_WAKEUP_EN bit Dmitry Osipenko
2021-06-15  1:05 ` [PATCH v1 1/2] usb: phy: tegra: Wait for VBUS wakeup status deassertion on suspend Peter Chen
2021-06-15 14:48   ` Dmitry Osipenko
2021-06-15  1:06 ` Peter Chen
2021-06-16  0:56 ` Peter Chen

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).