Skip to content

Commit a4f6b41

Browse files
Wayne Changjfvogel
authored andcommitted
phy: tegra: xusb: Use a bitmask for UTMI pad power state tracking
commit b47158fb42959c417ff2662075c0d46fb783d5d1 upstream. The current implementation uses bias_pad_enable as a reference count to manage the shared bias pad for all UTMI PHYs. However, during system suspension with connected USB devices, multiple power-down requests for the UTMI pad result in a mismatch in the reference count, which in turn produces warnings such as: [ 237.762967] WARNING: CPU: 10 PID: 1618 at tegra186_utmi_pad_power_down+0x160/0x170 [ 237.763103] Call trace: [ 237.763104] tegra186_utmi_pad_power_down+0x160/0x170 [ 237.763107] tegra186_utmi_phy_power_off+0x10/0x30 [ 237.763110] phy_power_off+0x48/0x100 [ 237.763113] tegra_xusb_enter_elpg+0x204/0x500 [ 237.763119] tegra_xusb_suspend+0x48/0x140 [ 237.763122] platform_pm_suspend+0x2c/0xb0 [ 237.763125] dpm_run_callback.isra.0+0x20/0xa0 [ 237.763127] __device_suspend+0x118/0x330 [ 237.763129] dpm_suspend+0x10c/0x1f0 [ 237.763130] dpm_suspend_start+0x88/0xb0 [ 237.763132] suspend_devices_and_enter+0x120/0x500 [ 237.763135] pm_suspend+0x1ec/0x270 The root cause was traced back to the dynamic power-down changes introduced in commit a30951d ("xhci: tegra: USB2 pad power controls"), where the UTMI pad was being powered down without verifying its current state. This unbalanced behavior led to discrepancies in the reference count. To rectify this issue, this patch replaces the single reference counter with a bitmask, renamed to utmi_pad_enabled. Each bit in the mask corresponds to one of the four USB2 PHYs, allowing us to track each pad's enablement status individually. With this change: - The bias pad is powered on only when the mask is clear. - Each UTMI pad is powered on or down based on its corresponding bit in the mask, preventing redundant operations. - The overall power state of the shared bias pad is maintained correctly during suspend/resume cycles. The mutex used to prevent race conditions during UTMI pad enable/disable operations has been moved from the tegra186_utmi_bias_pad_power_on/off functions to the parent functions tegra186_utmi_pad_power_on/down. This change ensures that there are no race conditions when updating the bitmask. Cc: [email protected] Fixes: a30951d ("xhci: tegra: USB2 pad power controls") Signed-off-by: Wayne Chang <[email protected]> Reviewed-by: Jon Hunter <[email protected]> Tested-by: Jon Hunter <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Vinod Koul <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 1db527f0cb8f677adadd4e28e5bc77aaf5d4e4c9) Signed-off-by: Jack Vogel <[email protected]>
1 parent 8eed1b4 commit a4f6b41

File tree

1 file changed

+27
-17
lines changed

1 file changed

+27
-17
lines changed

drivers/phy/tegra/xusb-tegra186.c

Lines changed: 27 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -237,6 +237,8 @@
237237
#define DATA0_VAL_PD BIT(1)
238238
#define USE_XUSB_AO BIT(4)
239239

240+
#define TEGRA_UTMI_PAD_MAX 4
241+
240242
#define TEGRA186_LANE(_name, _offset, _shift, _mask, _type) \
241243
{ \
242244
.name = _name, \
@@ -269,7 +271,7 @@ struct tegra186_xusb_padctl {
269271

270272
/* UTMI bias and tracking */
271273
struct clk *usb2_trk_clk;
272-
unsigned int bias_pad_enable;
274+
DECLARE_BITMAP(utmi_pad_enabled, TEGRA_UTMI_PAD_MAX);
273275

274276
/* padctl context */
275277
struct tegra186_xusb_padctl_context context;
@@ -603,12 +605,8 @@ static void tegra186_utmi_bias_pad_power_on(struct tegra_xusb_padctl *padctl)
603605
u32 value;
604606
int err;
605607

606-
mutex_lock(&padctl->lock);
607-
608-
if (priv->bias_pad_enable++ > 0) {
609-
mutex_unlock(&padctl->lock);
608+
if (!bitmap_empty(priv->utmi_pad_enabled, TEGRA_UTMI_PAD_MAX))
610609
return;
611-
}
612610

613611
err = clk_prepare_enable(priv->usb2_trk_clk);
614612
if (err < 0)
@@ -667,17 +665,8 @@ static void tegra186_utmi_bias_pad_power_off(struct tegra_xusb_padctl *padctl)
667665
struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl);
668666
u32 value;
669667

670-
mutex_lock(&padctl->lock);
671-
672-
if (WARN_ON(priv->bias_pad_enable == 0)) {
673-
mutex_unlock(&padctl->lock);
674-
return;
675-
}
676-
677-
if (--priv->bias_pad_enable > 0) {
678-
mutex_unlock(&padctl->lock);
668+
if (!bitmap_empty(priv->utmi_pad_enabled, TEGRA_UTMI_PAD_MAX))
679669
return;
680-
}
681670

682671
value = padctl_readl(padctl, XUSB_PADCTL_USB2_BIAS_PAD_CTL1);
683672
value |= USB2_PD_TRK;
@@ -690,13 +679,13 @@ static void tegra186_utmi_bias_pad_power_off(struct tegra_xusb_padctl *padctl)
690679
clk_disable_unprepare(priv->usb2_trk_clk);
691680
}
692681

693-
mutex_unlock(&padctl->lock);
694682
}
695683

696684
static void tegra186_utmi_pad_power_on(struct phy *phy)
697685
{
698686
struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
699687
struct tegra_xusb_padctl *padctl = lane->pad->padctl;
688+
struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl);
700689
struct tegra_xusb_usb2_port *port;
701690
struct device *dev = padctl->dev;
702691
unsigned int index = lane->index;
@@ -705,9 +694,16 @@ static void tegra186_utmi_pad_power_on(struct phy *phy)
705694
if (!phy)
706695
return;
707696

697+
mutex_lock(&padctl->lock);
698+
if (test_bit(index, priv->utmi_pad_enabled)) {
699+
mutex_unlock(&padctl->lock);
700+
return;
701+
}
702+
708703
port = tegra_xusb_find_usb2_port(padctl, index);
709704
if (!port) {
710705
dev_err(dev, "no port found for USB2 lane %u\n", index);
706+
mutex_unlock(&padctl->lock);
711707
return;
712708
}
713709

@@ -724,18 +720,28 @@ static void tegra186_utmi_pad_power_on(struct phy *phy)
724720
value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index));
725721
value &= ~USB2_OTG_PD_DR;
726722
padctl_writel(padctl, value, XUSB_PADCTL_USB2_OTG_PADX_CTL1(index));
723+
724+
set_bit(index, priv->utmi_pad_enabled);
725+
mutex_unlock(&padctl->lock);
727726
}
728727

729728
static void tegra186_utmi_pad_power_down(struct phy *phy)
730729
{
731730
struct tegra_xusb_lane *lane = phy_get_drvdata(phy);
732731
struct tegra_xusb_padctl *padctl = lane->pad->padctl;
732+
struct tegra186_xusb_padctl *priv = to_tegra186_xusb_padctl(padctl);
733733
unsigned int index = lane->index;
734734
u32 value;
735735

736736
if (!phy)
737737
return;
738738

739+
mutex_lock(&padctl->lock);
740+
if (!test_bit(index, priv->utmi_pad_enabled)) {
741+
mutex_unlock(&padctl->lock);
742+
return;
743+
}
744+
739745
dev_dbg(padctl->dev, "power down UTMI pad %u\n", index);
740746

741747
value = padctl_readl(padctl, XUSB_PADCTL_USB2_OTG_PADX_CTL0(index));
@@ -748,7 +754,11 @@ static void tegra186_utmi_pad_power_down(struct phy *phy)
748754

749755
udelay(2);
750756

757+
clear_bit(index, priv->utmi_pad_enabled);
758+
751759
tegra186_utmi_bias_pad_power_off(padctl);
760+
761+
mutex_unlock(&padctl->lock);
752762
}
753763

754764
static int tegra186_xusb_padctl_vbus_override(struct tegra_xusb_padctl *padctl,

0 commit comments

Comments
 (0)