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

Commit e81dc0f1 authored by Pratham Pratap's avatar Pratham Pratap Committed by Gerrit - the friendly Code Review server
Browse files

usb: phy: Remove flags for clock enable/disable



This change removes flags to enable/disable clocks
from phy driver so that clocks framework can take care
of ref count for enabling/disabling clocks. This change
also fixes the check if phy is already suspended or not.

Change-Id: I5073b02d1e1af53ed56d363763cde3177028cf4e
Signed-off-by: default avatarPratham Pratap <prathampratap@codeaurora.org>
parent 2913cfe3
Loading
Loading
Loading
Loading
+7 −17
Original line number Diff line number Diff line
@@ -120,7 +120,6 @@ struct qusb_phy {
	int			efuse_num_of_bits;

	int			power_enabled_ref;
	bool			clocks_enabled;
	bool			cable_connected;
	bool			suspended;
	bool			dpdm_enable;
@@ -148,10 +147,9 @@ struct qusb_phy {

static void qusb_phy_enable_clocks(struct qusb_phy *qphy, bool on)
{
	dev_dbg(qphy->phy.dev, "%s(): clocks_enabled:%d on:%d\n",
			__func__, qphy->clocks_enabled, on);
	dev_dbg(qphy->phy.dev, "%s(): on:%d\n", __func__, on);

	if (!qphy->clocks_enabled && on) {
	if (on) {
		clk_prepare_enable(qphy->ref_clk_src);
		if (qphy->ref_clk)
			clk_prepare_enable(qphy->ref_clk);
@@ -159,10 +157,7 @@ static void qusb_phy_enable_clocks(struct qusb_phy *qphy, bool on)
		if (qphy->cfg_ahb_clk)
			clk_prepare_enable(qphy->cfg_ahb_clk);

		qphy->clocks_enabled = true;
	}

	if (qphy->clocks_enabled && !on) {
	} else {
		if (qphy->cfg_ahb_clk)
			clk_disable_unprepare(qphy->cfg_ahb_clk);

@@ -170,11 +165,7 @@ static void qusb_phy_enable_clocks(struct qusb_phy *qphy, bool on)
			clk_disable_unprepare(qphy->ref_clk);

		clk_disable_unprepare(qphy->ref_clk_src);
		qphy->clocks_enabled = false;
	}

	dev_dbg(qphy->phy.dev, "%s(): clocks_enabled:%d\n", __func__,
						qphy->clocks_enabled);
}

static int qusb_phy_config_vdd(struct qusb_phy *qphy, int high)
@@ -482,8 +473,6 @@ static int qusb_phy_init(struct usb_phy *phy)
	if (ret)
		return ret;

	qusb_phy_enable_clocks(qphy, true);

	qusb_phy_reset(qphy);

	if (qphy->qusb_phy_host_init_seq && qphy->phy.flags & PHY_HOST_MODE) {
@@ -609,7 +598,7 @@ static int qusb_phy_set_suspend(struct usb_phy *phy, int suspend)
	struct qusb_phy *qphy = container_of(phy, struct qusb_phy, phy);
	u32 linestate = 0, intr_mask = 0;

	if (qphy->suspended && suspend) {
	if (qphy->suspended == suspend) {
		dev_dbg(phy->dev, "%s: USB PHY is already suspended\n",
			__func__);
		return 0;
@@ -1137,6 +1126,7 @@ static int qusb_phy_probe(struct platform_device *pdev)
	if (ret)
		usb_remove_phy(&qphy->phy);

	qphy->suspended = true;
	qusb_phy_create_debugfs(qphy);

	return ret;
@@ -1147,8 +1137,8 @@ static int qusb_phy_remove(struct platform_device *pdev)
	struct qusb_phy *qphy = platform_get_drvdata(pdev);

	usb_remove_phy(&qphy->phy);
	qusb_phy_enable_clocks(qphy, false);
	qusb_phy_enable_power(qphy, false);
	qphy->cable_connected = false;
	qusb_phy_set_suspend(&qphy->phy, true);
	debugfs_remove_recursive(qphy->root);

	return 0;
+8 −23
Original line number Diff line number Diff line
@@ -150,7 +150,6 @@ struct qusb_phy {
	int			tune2_efuse_correction;

	bool			power_enabled;
	bool			clocks_enabled;
	bool			cable_connected;
	bool			suspended;
	bool			ulpi_mode;
@@ -175,19 +174,15 @@ struct qusb_phy {

static void qusb_phy_enable_clocks(struct qusb_phy *qphy, bool on)
{
	dev_dbg(qphy->phy.dev, "%s(): clocks_enabled:%d on:%d\n",
			__func__, qphy->clocks_enabled, on);
	dev_dbg(qphy->phy.dev, "%s(): on:%d\n", __func__, on);

	if (!qphy->clocks_enabled && on) {
	if (on) {
		clk_prepare_enable(qphy->ref_clk_src);
		clk_prepare_enable(qphy->ref_clk);
		clk_prepare_enable(qphy->iface_clk);
		clk_prepare_enable(qphy->core_clk);
		clk_prepare_enable(qphy->cfg_ahb_clk);
		qphy->clocks_enabled = true;
	}

	if (qphy->clocks_enabled && !on) {
	} else {
		clk_disable_unprepare(qphy->cfg_ahb_clk);
		/*
		 * FSM depedency beween iface_clk and core_clk.
@@ -197,11 +192,8 @@ static void qusb_phy_enable_clocks(struct qusb_phy *qphy, bool on)
		clk_disable_unprepare(qphy->iface_clk);
		clk_disable_unprepare(qphy->ref_clk);
		clk_disable_unprepare(qphy->ref_clk_src);
		qphy->clocks_enabled = false;
	}

	dev_dbg(qphy->phy.dev, "%s(): clocks_enabled:%d\n", __func__,
						qphy->clocks_enabled);
}

static int qusb_phy_gdsc(struct qusb_phy *qphy, bool on)
@@ -444,8 +436,6 @@ static int qusb_phy_init(struct usb_phy *phy)
	if (ret)
		return ret;

	qusb_phy_enable_clocks(qphy, true);

	/*
	 * ref clock is enabled by default after power on reset. Linux clock
	 * driver will disable this clock as part of late init if peripheral
@@ -648,7 +638,7 @@ static int qusb_phy_set_suspend(struct usb_phy *phy, int suspend)
	struct qusb_phy *qphy = container_of(phy, struct qusb_phy, phy);
	u32 linestate = 0, intr_mask = 0;

	if (qphy->suspended && suspend) {
	if (qphy->suspended == suspend) {
		dev_dbg(phy->dev, "%s: USB PHY is already suspended\n",
			__func__);
		return 0;
@@ -1241,6 +1231,8 @@ static int qusb_phy_probe(struct platform_device *pdev)
	if (qphy->tcsr_clamp_dig_n)
		writel_relaxed(0x0, qphy->tcsr_clamp_dig_n);

	qphy->suspended = true;

	return ret;
}

@@ -1249,15 +1241,8 @@ static int qusb_phy_remove(struct platform_device *pdev)
	struct qusb_phy *qphy = platform_get_drvdata(pdev);

	usb_remove_phy(&qphy->phy);

	if (qphy->clocks_enabled) {
		clk_disable_unprepare(qphy->cfg_ahb_clk);
		clk_disable_unprepare(qphy->ref_clk);
		clk_disable_unprepare(qphy->ref_clk_src);
		qphy->clocks_enabled = false;
	}

	qusb_phy_enable_power(qphy, false);
	qphy->cable_connected = false;
	qusb_phy_set_suspend(&qphy->phy, true);

	return 0;
}