Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit ab896376 authored by Linux Build Service Account's avatar Linux Build Service Account Committed by Gerrit - the friendly Code Review server
Browse files

Merge "usb: phy-msm-qusb-v2: Add support for reference counting of regulators"

parents ceb4b4ad 164cc1b4
Loading
Loading
Loading
Loading
+57 −43
Original line number Diff line number Diff line
@@ -79,6 +79,7 @@ enum qusb_phy_reg {

struct qusb_phy {
	struct usb_phy		phy;
	struct mutex		lock;
	void __iomem		*base;
	void __iomem		*efuse_reg;

@@ -103,7 +104,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;
@@ -171,23 +172,36 @@ static int qusb_phy_config_vdd(struct qusb_phy *qphy, int high)
	return ret;
}

static int qusb_phy_enable_power(struct qusb_phy *qphy, bool on,
						bool toggle_vdd)
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 (toggle_vdd && 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)
	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;

	if (toggle_vdd) {
		dev_dbg(qphy->phy.dev, "Skip turning off PHYs' regulators\n");
		goto done;
	}

	ret = qusb_phy_config_vdd(qphy, true);
	if (ret) {
		dev_err(qphy->phy.dev, "Unable to config VDD:%d\n",
@@ -200,7 +214,6 @@ static int qusb_phy_enable_power(struct qusb_phy *qphy, bool on,
		dev_err(qphy->phy.dev, "Unable to enable VDD\n");
		goto unconfig_vdd;
	}
	}

	ret = regulator_set_load(qphy->vdda18, QUSB2PHY_1P8_HPM_LOAD);
	if (ret < 0) {
@@ -242,10 +255,9 @@ static int qusb_phy_enable_power(struct qusb_phy *qphy, bool on,
		goto unset_vdd33;
	}

	if (toggle_vdd)
		qphy->power_enabled = true;

	pr_debug("%s(): QUSB PHY's regulators are turned ON.\n", __func__);

	mutex_unlock(&qphy->lock);
	return ret;

disable_vdda33:
@@ -281,7 +293,6 @@ static int qusb_phy_enable_power(struct qusb_phy *qphy, bool on,
		dev_err(qphy->phy.dev, "Unable to set LPM of vdda18\n");

disable_vdd:
	if (toggle_vdd) {
	ret = regulator_disable(qphy->vdd);
	if (ret)
		dev_err(qphy->phy.dev, "Unable to disable vdd:%d\n",
@@ -292,11 +303,14 @@ static int qusb_phy_enable_power(struct qusb_phy *qphy, bool on,
	if (ret)
		dev_err(qphy->phy.dev, "Unable unconfig VDD:%d\n",
							ret);
	}
err_vdd:
	if (toggle_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;
}

@@ -394,7 +408,7 @@ static int qusb_phy_init(struct usb_phy *phy)

	dev_dbg(phy->dev, "%s\n", __func__);

	ret = qusb_phy_enable_power(qphy, true, true);
	ret = qusb_phy_enable_power(qphy, true);
	if (ret)
		return ret;

@@ -576,7 +590,7 @@ static int qusb_phy_set_suspend(struct usb_phy *phy, int suspend)
				qphy->base + qphy->phy_reg[INTR_CTRL]);
			qusb_phy_reset(qphy);
			qusb_phy_enable_clocks(qphy, false);
			qusb_phy_enable_power(qphy, false, true);
			qusb_phy_enable_power(qphy, false);
		}
		qphy->suspended = true;
	} else {
@@ -595,7 +609,6 @@ static int qusb_phy_set_suspend(struct usb_phy *phy, int suspend)
			/* Makes sure that above write goes through */
			wmb();
		} else { /* Cable connect case */
			qusb_phy_enable_power(qphy, true, true);
			qusb_phy_enable_clocks(qphy, true);
		}
		qphy->suspended = false;
@@ -640,7 +653,7 @@ static int qusb_phy_dpdm_regulator_enable(struct regulator_dev *rdev)
				__func__, qphy->dpdm_enable);

	if (!qphy->dpdm_enable) {
		ret = qusb_phy_enable_power(qphy, true, false);
		ret = qusb_phy_enable_power(qphy, true);
		if (ret < 0) {
			dev_dbg(qphy->phy.dev,
				"dpdm regulator enable failed:%d\n", ret);
@@ -661,7 +674,7 @@ static int qusb_phy_dpdm_regulator_disable(struct regulator_dev *rdev)
				__func__, qphy->dpdm_enable);

	if (qphy->dpdm_enable) {
		ret = qusb_phy_enable_power(qphy, false, false);
		ret = qusb_phy_enable_power(qphy, false);
		if (ret < 0) {
			dev_dbg(qphy->phy.dev,
				"dpdm regulator disable failed:%d\n", ret);
@@ -968,6 +981,7 @@ static int qusb_phy_probe(struct platform_device *pdev)
		return PTR_ERR(qphy->vdda18);
	}

	mutex_init(&qphy->lock);
	platform_set_drvdata(pdev, qphy);

	qphy->phy.label			= "msm-qusb-phy-v2";
@@ -995,7 +1009,7 @@ static int qusb_phy_remove(struct platform_device *pdev)

	usb_remove_phy(&qphy->phy);
	qusb_phy_enable_clocks(qphy, false);
	qusb_phy_enable_power(qphy, false, true);
	qusb_phy_enable_power(qphy, false);

	return 0;
}