Skip to content

Commit cefc1ca

Browse files
Wayne Changvinodkoul
authored andcommitted
phy: tegra: xusb: Fix unbalanced regulator disable in UTMI PHY mode
When transitioning from USB_ROLE_DEVICE to USB_ROLE_NONE, the code assumed that the regulator should be disabled. However, if the regulator is marked as always-on, regulator_is_enabled() continues to return true, leading to an incorrect attempt to disable a regulator which is not enabled. This can result in warnings such as: [ 250.155624] WARNING: CPU: 1 PID: 7326 at drivers/regulator/core.c:3004 _regulator_disable+0xe4/0x1a0 [ 250.155652] unbalanced disables for VIN_SYS_5V0 To fix this, we move the regulator control logic into tegra186_xusb_padctl_id_override() function since it's directly related to the ID override state. The regulator is now only disabled when the role transitions from USB_ROLE_HOST to USB_ROLE_NONE, by checking the VBUS_ID register. This ensures that regulator enable/disable operations are properly balanced and only occur when actually transitioning to/from host mode. Fixes: 49d46e3 ("phy: tegra: xusb: Add set_mode support for UTMI phy on Tegra186") Cc: [email protected] 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]>
1 parent 7be5487 commit cefc1ca

File tree

1 file changed

+37
-22
lines changed

1 file changed

+37
-22
lines changed

drivers/phy/tegra/xusb-tegra186.c

Lines changed: 37 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -783,13 +783,15 @@ static int tegra186_xusb_padctl_vbus_override(struct tegra_xusb_padctl *padctl,
783783
}
784784

785785
static int tegra186_xusb_padctl_id_override(struct tegra_xusb_padctl *padctl,
786-
bool status)
786+
struct tegra_xusb_usb2_port *port, bool status)
787787
{
788-
u32 value;
788+
u32 value, id_override;
789+
int err = 0;
789790

790791
dev_dbg(padctl->dev, "%s id override\n", status ? "set" : "clear");
791792

792793
value = padctl_readl(padctl, USB2_VBUS_ID);
794+
id_override = value & ID_OVERRIDE(~0);
793795

794796
if (status) {
795797
if (value & VBUS_OVERRIDE) {
@@ -800,15 +802,35 @@ static int tegra186_xusb_padctl_id_override(struct tegra_xusb_padctl *padctl,
800802
value = padctl_readl(padctl, USB2_VBUS_ID);
801803
}
802804

803-
value &= ~ID_OVERRIDE(~0);
804-
value |= ID_OVERRIDE_GROUNDED;
805+
if (id_override != ID_OVERRIDE_GROUNDED) {
806+
value &= ~ID_OVERRIDE(~0);
807+
value |= ID_OVERRIDE_GROUNDED;
808+
padctl_writel(padctl, value, USB2_VBUS_ID);
809+
810+
err = regulator_enable(port->supply);
811+
if (err) {
812+
dev_err(padctl->dev, "Failed to enable regulator: %d\n", err);
813+
return err;
814+
}
815+
}
805816
} else {
806-
value &= ~ID_OVERRIDE(~0);
807-
value |= ID_OVERRIDE_FLOATING;
817+
if (id_override == ID_OVERRIDE_GROUNDED) {
818+
/*
819+
* The regulator is disabled only when the role transitions
820+
* from USB_ROLE_HOST to USB_ROLE_NONE.
821+
*/
822+
err = regulator_disable(port->supply);
823+
if (err) {
824+
dev_err(padctl->dev, "Failed to disable regulator: %d\n", err);
825+
return err;
826+
}
827+
828+
value &= ~ID_OVERRIDE(~0);
829+
value |= ID_OVERRIDE_FLOATING;
830+
padctl_writel(padctl, value, USB2_VBUS_ID);
831+
}
808832
}
809833

810-
padctl_writel(padctl, value, USB2_VBUS_ID);
811-
812834
return 0;
813835
}
814836

@@ -827,27 +849,20 @@ static int tegra186_utmi_phy_set_mode(struct phy *phy, enum phy_mode mode,
827849

828850
if (mode == PHY_MODE_USB_OTG) {
829851
if (submode == USB_ROLE_HOST) {
830-
tegra186_xusb_padctl_id_override(padctl, true);
831-
832-
err = regulator_enable(port->supply);
852+
err = tegra186_xusb_padctl_id_override(padctl, port, true);
853+
if (err)
854+
goto out;
833855
} else if (submode == USB_ROLE_DEVICE) {
834856
tegra186_xusb_padctl_vbus_override(padctl, true);
835857
} else if (submode == USB_ROLE_NONE) {
836-
/*
837-
* When port is peripheral only or role transitions to
838-
* USB_ROLE_NONE from USB_ROLE_DEVICE, regulator is not
839-
* enabled.
840-
*/
841-
if (regulator_is_enabled(port->supply))
842-
regulator_disable(port->supply);
843-
844-
tegra186_xusb_padctl_id_override(padctl, false);
858+
err = tegra186_xusb_padctl_id_override(padctl, port, false);
859+
if (err)
860+
goto out;
845861
tegra186_xusb_padctl_vbus_override(padctl, false);
846862
}
847863
}
848-
864+
out:
849865
mutex_unlock(&padctl->lock);
850-
851866
return err;
852867
}
853868

0 commit comments

Comments
 (0)