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

Commit 2b3c2209 authored by Pratham Pratap's avatar Pratham Pratap
Browse files

usb: phy: qusb: Add wrapper function for phy reset



Currently the phy driver is asserting and deasserting
usb phy reset signal to reset qusb phy. This changes adds
a wrapper function around the assert and deassert of usb
phy reset signal to make the code more readable and remove
code duplicacy.

Change-Id: I4fa03ae2d6bccf7386fcf3a7aa5df0345054147d
Signed-off-by: default avatarPratham Pratap <prathampratap@codeaurora.org>
parent 1c2af547
Loading
Loading
Loading
Loading
+21 −44
Original line number Diff line number Diff line
@@ -505,10 +505,25 @@ static void qusb_phy_write_seq(void __iomem *base, u32 *seq, int cnt,
	}
}

static void qusb_phy_reset(struct qusb_phy *qphy)
{
	int ret = 0;

	ret = reset_control_assert(qphy->phy_reset);
	if (ret)
		dev_err(qphy->phy.dev, "%s: phy_reset assert failed\n",
				__func__);
	usleep_range(100, 150);
	ret = reset_control_deassert(qphy->phy_reset);
	if (ret)
		dev_err(qphy->phy.dev, "%s: phy_reset deassert failed\n",
				__func__);
}

static int qusb_phy_init(struct usb_phy *phy)
{
	struct qusb_phy *qphy = container_of(phy, struct qusb_phy, phy);
	int ret, reset_val = 0;
	int reset_val = 0;
	u8 reg;
	bool pll_lock_fail = false;

@@ -537,13 +552,7 @@ static int qusb_phy_init(struct usb_phy *phy)
	}

	/* Perform phy reset */
	ret = reset_control_assert(qphy->phy_reset);
	if (ret)
		dev_err(phy->dev, "%s: phy_reset assert failed\n", __func__);
	usleep_range(100, 150);
	ret = reset_control_deassert(qphy->phy_reset);
	if (ret)
		dev_err(phy->dev, "%s: phy_reset deassert failed\n", __func__);
	qusb_phy_reset(qphy);

	/* Disable the PHY */
	if (qphy->major_rev < 2)
@@ -907,15 +916,7 @@ static int qusb_phy_drive_dp_pulse(struct usb_phy *phy,
	}
	qusb_phy_gdsc(qphy, true);
	qusb_phy_enable_clocks(qphy, true);

	ret = reset_control_assert(qphy->phy_reset);
	if (ret)
		dev_err(qphy->phy.dev, "phyassert failed\n");
	usleep_range(100, 150);
	ret = reset_control_deassert(qphy->phy_reset);
	if (ret)
		dev_err(qphy->phy.dev, "deassert failed\n");

	qusb_phy_reset(qphy);
	/* Configure PHY to enable control on DP/DM lines */
	writel_relaxed(CLAMP_N_EN | FREEZIO_N | POWER_DOWN,
				qphy->base + QUSB2PHY_PORT_POWERDOWN);
@@ -1002,13 +1003,7 @@ static int qusb_phy_dpdm_regulator_enable(struct regulator_dev *rdev)
			qusb_phy_enable_clocks(qphy, true);

			dev_dbg(qphy->phy.dev, "RESET QUSB PHY\n");
			ret = reset_control_assert(qphy->phy_reset);
			if (ret)
				dev_err(qphy->phy.dev, "phyassert failed\n");
			usleep_range(100, 150);
			ret = reset_control_deassert(qphy->phy_reset);
			if (ret)
				dev_err(qphy->phy.dev, "deassert failed\n");
			qusb_phy_reset(qphy);

			/*
			 * Phy in non-driving mode leaves Dp and Dm
@@ -1062,14 +1057,7 @@ static int qusb_phy_dpdm_regulator_disable(struct regulator_dev *rdev)
		 * reset is to bring out the PHY from high-Z state
		 * and avoid extra current consumption.
		 */
		ret = reset_control_assert(qphy->phy_reset);
		if (ret)
			dev_err(qphy->phy.dev, "phyassert failed\n");
		usleep_range(100, 150);
		ret = reset_control_deassert(qphy->phy_reset);
		if (ret)
			dev_err(qphy->phy.dev, "deassert failed\n");

		qusb_phy_reset(qphy);
		ret = qusb_phy_enable_power(qphy, false);
		if (ret < 0) {
			dev_dbg(qphy->phy.dev,
@@ -1405,18 +1393,7 @@ static int qusb_phy_prepare_chg_det(struct qusb_phy *qphy)

static void qusb_phy_unprepare_chg_det(struct qusb_phy *qphy)
{
	int ret;

	ret = reset_control_assert(qphy->phy_reset);
	if (ret)
		dev_err(qphy->phy.dev, "phyassert failed\n");

	usleep_range(100, 150);

	ret = reset_control_deassert(qphy->phy_reset);
	if (ret)
		dev_err(qphy->phy.dev, "deassert failed\n");

	qusb_phy_reset(qphy);
	qusb_phy_enable_clocks(qphy, false);
	qusb_phy_clear_tcsr_clamp(qphy, false);
	qusb_phy_enable_power(qphy, false);