summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/usb/phy/phy-msm-qusb-v2.c49
1 files changed, 34 insertions, 15 deletions
diff --git a/drivers/usb/phy/phy-msm-qusb-v2.c b/drivers/usb/phy/phy-msm-qusb-v2.c
index 9686c1e24f6b..de4f93afdc97 100644
--- a/drivers/usb/phy/phy-msm-qusb-v2.c
+++ b/drivers/usb/phy/phy-msm-qusb-v2.c
@@ -76,6 +76,7 @@ MODULE_PARM_DESC(phy_tune1, "QUSB PHY v2 TUNE1");
struct qusb_phy {
struct usb_phy phy;
+ struct mutex lock;
void __iomem *base;
void __iomem *efuse_reg;
void __iomem *tcsr_clamp_dig_n;
@@ -100,7 +101,7 @@ struct qusb_phy {
int efuse_bit_pos;
int efuse_num_of_bits;
- bool power_enabled;
+ int power_enabled_ref;
bool clocks_enabled;
bool cable_connected;
bool suspended;
@@ -164,16 +165,31 @@ static int qusb_phy_enable_power(struct qusb_phy *qphy, bool on)
{
int ret = 0;
- dev_dbg(qphy->phy.dev, "%s turn %s regulators. power_enabled:%d\n",
- __func__, on ? "on" : "off", qphy->power_enabled);
+ mutex_lock(&qphy->lock);
- if (qphy->power_enabled == on) {
- dev_dbg(qphy->phy.dev, "PHYs' regulators are already ON.\n");
- return 0;
+ dev_dbg(qphy->phy.dev,
+ "%s:req to turn %s regulators. power_enabled_ref:%d\n",
+ __func__, on ? "on" : "off", qphy->power_enabled_ref);
+
+ if (on && ++qphy->power_enabled_ref > 1) {
+ dev_dbg(qphy->phy.dev, "PHYs' regulators are already on\n");
+ goto done;
}
- if (!on)
- goto disable_vdda33;
+ if (!on) {
+ if (on == qphy->power_enabled_ref) {
+ dev_dbg(qphy->phy.dev,
+ "PHYs' regulators are already off\n");
+ goto done;
+ }
+
+ qphy->power_enabled_ref--;
+ if (!qphy->power_enabled_ref)
+ goto disable_vdda33;
+
+ dev_dbg(qphy->phy.dev, "Skip turning off PHYs' regulators\n");
+ goto done;
+ }
ret = qusb_phy_config_vdd(qphy, true);
if (ret) {
@@ -248,9 +264,9 @@ static int qusb_phy_enable_power(struct qusb_phy *qphy, bool on)
goto unset_vdd33;
}
- qphy->power_enabled = true;
-
pr_debug("%s(): QUSB PHY's regulators are turned ON.\n", __func__);
+
+ mutex_unlock(&qphy->lock);
return ret;
disable_vdda33:
@@ -311,8 +327,13 @@ unconfig_vdd:
dev_err(qphy->phy.dev, "Unable unconfig VDD:%d\n",
ret);
err_vdd:
- qphy->power_enabled = false;
dev_dbg(qphy->phy.dev, "QUSB PHY's regulators are turned OFF.\n");
+
+ /* in case of error in turning on regulators */
+ if (qphy->power_enabled_ref)
+ qphy->power_enabled_ref--;
+done:
+ mutex_unlock(&qphy->lock);
return ret;
}
@@ -445,10 +466,6 @@ static int qusb_phy_init(struct usb_phy *phy)
dev_dbg(phy->dev, "%s\n", __func__);
- ret = qusb_phy_enable_power(qphy, true);
- if (ret)
- return ret;
-
/* bump up vdda33 voltage to operating level*/
ret = regulator_set_voltage(qphy->vdda33, qphy->vdda33_levels[1],
qphy->vdda33_levels[2]);
@@ -1056,6 +1073,8 @@ static int qusb_phy_probe(struct platform_device *pdev)
return PTR_ERR(qphy->vdda12);
}
+ mutex_init(&qphy->lock);
+
platform_set_drvdata(pdev, qphy);
qphy->phy.label = "msm-qusb-phy-v2";