diff mbox series

[v7,09/14] phy: phy-mtk-tphy: add a new reference clock

Message ID 1588140330-9910-10-git-send-email-chunfeng.yun@mediatek.com
State Superseded
Headers show
Series Add support for MediaTek xHCI host controller | expand

Commit Message

Chunfeng Yun (云春峰) April 29, 2020, 6:05 a.m. UTC
Usually the digital and analog phys use the same reference clock,
but some platforms have two separate reference clocks for each of
them, so add another optional clock to support them.
In order to keep the clock names consistent with PHY IP's, change
the da_ref for analog phy and ref clock for digital phy.

Signed-off-by: Chunfeng Yun <chunfeng.yun at mediatek.com>
Reviewed-by: Weijie Gao <weijie.gao at mediatek.com>
---
v7: no changes

v6: add Reviewed-by Weijie

v2~v5: no changes
---
 drivers/phy/phy-mtk-tphy.c | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/drivers/phy/phy-mtk-tphy.c b/drivers/phy/phy-mtk-tphy.c
index 20167fe7cb..81525a48b7 100644
--- a/drivers/phy/phy-mtk-tphy.c
+++ b/drivers/phy/phy-mtk-tphy.c
@@ -199,8 +199,8 @@  struct mtk_phy_instance {
 		struct u3phy_banks u3_banks;
 	};
 
-	/* reference clock of anolog phy */
-	struct clk ref_clk;
+	struct clk ref_clk;	/* reference clock of (digital) phy */
+	struct clk da_ref_clk;	/* reference clock of analog phy */
 	u32 index;
 	u32 type;
 };
@@ -450,8 +450,17 @@  static int mtk_phy_init(struct phy *phy)
 	int ret;
 
 	ret = clk_enable(&instance->ref_clk);
-	if (ret)
+	if (ret < 0) {
+		dev_err(tphy->dev, "failed to enable ref_clk\n");
 		return ret;
+	}
+
+	ret = clk_enable(&instance->da_ref_clk);
+	if (ret < 0) {
+		dev_err(tphy->dev, "failed to enable da_ref_clk %d\n", ret);
+		clk_disable(&instance->ref_clk);
+		return ret;
+	}
 
 	switch (instance->type) {
 	case PHY_TYPE_USB2:
@@ -502,6 +511,7 @@  static int mtk_phy_exit(struct phy *phy)
 	struct mtk_tphy *tphy = dev_get_priv(phy->dev);
 	struct mtk_phy_instance *instance = tphy->phys[phy->id];
 
+	clk_disable(&instance->da_ref_clk);
 	clk_disable(&instance->ref_clk);
 
 	return 0;
@@ -611,6 +621,11 @@  static int mtk_tphy_probe(struct udevice *dev)
 					     &instance->ref_clk);
 		if (err)
 			return err;
+
+		err = clk_get_optional_nodev(subnode, "da_ref",
+					     &instance->da_ref_clk);
+		if (err)
+			return err;
 	}
 
 	return 0;