usb: phy: tegra: Keep track of power on-off state
authorDmitry Osipenko <digetx@gmail.com>
Mon, 6 Jan 2020 01:34:00 +0000 (04:34 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 9 Jan 2020 10:15:31 +0000 (11:15 +0100)
The PHY driver should keep track of the enable state, otherwise enable
refcount is screwed if USB driver tries to enable PHY when it is already
enabled. This will be the case for ChipIdea and Tegra EHCI drivers once
PHY driver will gain support for the init/shutdown callbacks.

Signed-off-by: Dmitry Osipenko <digetx@gmail.com>
Link: https://lore.kernel.org/r/20200106013416.9604-5-digetx@gmail.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
drivers/usb/phy/phy-tegra-usb.c
include/linux/usb/tegra_usb_phy.h

index 99acfde4ab8d622b1235b093cbb03f1d41ca5e5d..88466c7f13e68b2cae75a47721db94f7ff77183a 100644 (file)
@@ -785,18 +785,40 @@ static void tegra_usb_phy_close(struct tegra_usb_phy *phy)
 
 static int tegra_usb_phy_power_on(struct tegra_usb_phy *phy)
 {
+       int err;
+
+       if (phy->powered_on)
+               return 0;
+
        if (phy->is_ulpi_phy)
-               return ulpi_phy_power_on(phy);
+               err = ulpi_phy_power_on(phy);
        else
-               return utmi_phy_power_on(phy);
+               err = utmi_phy_power_on(phy);
+       if (err)
+               return err;
+
+       phy->powered_on = true;
+
+       return 0;
 }
 
 static int tegra_usb_phy_power_off(struct tegra_usb_phy *phy)
 {
+       int err;
+
+       if (!phy->powered_on)
+               return 0;
+
        if (phy->is_ulpi_phy)
-               return ulpi_phy_power_off(phy);
+               err = ulpi_phy_power_off(phy);
        else
-               return utmi_phy_power_off(phy);
+               err = utmi_phy_power_off(phy);
+       if (err)
+               return err;
+
+       phy->powered_on = false;
+
+       return 0;
 }
 
 static int     tegra_usb_phy_suspend(struct usb_phy *x, int suspend)
index 0c5c3ea8b2d75ef6e8fb70f8489c55fc6a5ecc84..3ae73bdc62455e9569b36bc48825a2f5c8850a4f 100644 (file)
@@ -78,6 +78,7 @@ struct tegra_usb_phy {
        bool is_ulpi_phy;
        int reset_gpio;
        struct reset_control *pad_rst;
+       bool powered_on;
 };
 
 void tegra_usb_phy_preresume(struct usb_phy *phy);