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

Commit 41b44184 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>
Signed-off-by: default avatarUdipto Goswami <ugoswami@codeaurora.org>
parent 6ae0f106
Loading
Loading
Loading
Loading
+7 −17
Original line number Original line Diff line number Diff line
@@ -127,7 +127,6 @@ struct qusb_phy {
	int			efuse_num_of_bits;
	int			efuse_num_of_bits;


	int			power_enabled_ref;
	int			power_enabled_ref;
	bool			clocks_enabled;
	bool			cable_connected;
	bool			cable_connected;
	bool			suspended;
	bool			suspended;
	bool			dpdm_enable;
	bool			dpdm_enable;
@@ -229,10 +228,9 @@ static int qusb_phy_get_socrev(struct device *dev, struct qusb_phy *qphy)


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


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


		qphy->clocks_enabled = true;
	} else {
	}

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


@@ -251,11 +246,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);


		clk_disable_unprepare(qphy->ref_clk_src);
		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)
static int qusb_phy_config_vdd(struct qusb_phy *qphy, int high)
@@ -572,8 +563,6 @@ static int qusb_phy_init(struct usb_phy *phy)
	if (ret)
	if (ret)
		return ret;
		return ret;


	qusb_phy_enable_clocks(qphy, true);

	qusb_phy_reset(qphy);
	qusb_phy_reset(qphy);


	if (qphy->qusb_phy_host_init_seq && qphy->phy.flags & PHY_HOST_MODE) {
	if (qphy->qusb_phy_host_init_seq && qphy->phy.flags & PHY_HOST_MODE) {
@@ -735,7 +724,7 @@ static int qusb_phy_set_suspend(struct usb_phy *phy, int suspend)
	struct qusb_phy *qphy = container_of(phy, struct qusb_phy, phy);
	struct qusb_phy *qphy = container_of(phy, struct qusb_phy, phy);
	u32 linestate = 0, intr_mask = 0;
	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",
		dev_dbg(phy->dev, "%s: USB PHY is already suspended\n",
			__func__);
			__func__);
		return 0;
		return 0;
@@ -1361,6 +1350,7 @@ static int qusb_phy_probe(struct platform_device *pdev)
	if (ret)
	if (ret)
		usb_remove_phy(&qphy->phy);
		usb_remove_phy(&qphy->phy);


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


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


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


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


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


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


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

	if (qphy->clocks_enabled && !on) {
		clk_disable_unprepare(qphy->cfg_ahb_clk);
		clk_disable_unprepare(qphy->cfg_ahb_clk);
		/*
		/*
		 * FSM depedency beween iface_clk and core_clk.
		 * FSM depedency beween iface_clk and core_clk.
@@ -194,11 +189,8 @@ static void qusb_phy_enable_clocks(struct qusb_phy *qphy, bool on)
		clk_disable_unprepare(qphy->iface_clk);
		clk_disable_unprepare(qphy->iface_clk);
		clk_disable_unprepare(qphy->ref_clk);
		clk_disable_unprepare(qphy->ref_clk);
		clk_disable_unprepare(qphy->ref_clk_src);
		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)
static int qusb_phy_gdsc(struct qusb_phy *qphy, bool on)
@@ -441,8 +433,6 @@ static int qusb_phy_init(struct usb_phy *phy)
	if (ret)
	if (ret)
		return ret;
		return ret;


	qusb_phy_enable_clocks(qphy, true);

	/*
	/*
	 * ref clock is enabled by default after power on reset. Linux clock
	 * ref clock is enabled by default after power on reset. Linux clock
	 * driver will disable this clock as part of late init if peripheral
	 * driver will disable this clock as part of late init if peripheral
@@ -646,7 +636,7 @@ static int qusb_phy_set_suspend(struct usb_phy *phy, int suspend)
	struct qusb_phy *qphy = container_of(phy, struct qusb_phy, phy);
	struct qusb_phy *qphy = container_of(phy, struct qusb_phy, phy);
	u32 linestate = 0, intr_mask = 0;
	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",
		dev_dbg(phy->dev, "%s: USB PHY is already suspended\n",
			__func__);
			__func__);
		return 0;
		return 0;
@@ -1227,6 +1217,8 @@ static int qusb_phy_probe(struct platform_device *pdev)
	if (qphy->tcsr_clamp_dig_n)
	if (qphy->tcsr_clamp_dig_n)
		writel_relaxed(0x0, qphy->tcsr_clamp_dig_n);
		writel_relaxed(0x0, qphy->tcsr_clamp_dig_n);


	qphy->suspended = true;

	return ret;
	return ret;
}
}


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


	usb_remove_phy(&qphy->phy);
	usb_remove_phy(&qphy->phy);

	qphy->cable_connected = false;
	if (qphy->clocks_enabled) {
	qusb_phy_set_suspend(&qphy->phy, true);
		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);


	return 0;
	return 0;
}
}