Skip to contentSkip to conversation

phy: rockchip-typec: add pm runtime support

PATCH Superseded Chris Zhong 4 participants 6 messages Sep 7, 2016 – Sep 8, 2016

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 phy: rockchip-typec: add pm runtime support

Adds pm_runtime support for rockchip Type-C, so that power domain is enabled only when there is a transaction going on to help save power.

---

Changes in v2:
-- add pm_runtime_put_sync in err case

 drivers/phy/phy-rockchip-typec.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/phy/phy-rockchip-typec.c +19 -0
index fb58a27..0b2f528 100644
@@ -552,6 +552,12 @@ static int tcphy_phy_init(struct rockchip_typec_phy *tcphy, u8 mode)
 		goto err_clk_core;
 	}
 
+	ret = pm_runtime_get_sync(tcphy->dev);
+	if (ret < 0) {
+		dev_err(tcphy->dev, "cannot get pm runtime %d\n", ret);
+		goto err_clk_ref;
+	}
+
 	reset_control_deassert(tcphy->tcphy_rst);
 
 	property_enable(tcphy, &cfg->typec_conn_dir, tcphy->flip);
@@ -600,8 +606,10 @@ static int tcphy_phy_init(struct rockchip_typec_phy *tcphy, u8 mode)
 	return 0;
 
 err_wait_pma:
+	pm_runtime_put_sync(tcphy->dev);
 	reset_control_assert(tcphy->uphy_rst);
 	reset_control_assert(tcphy->tcphy_rst);
+err_clk_ref:
 	clk_disable_unprepare(tcphy->clk_ref);
 err_clk_core:
 	clk_disable_unprepare(tcphy->clk_core);
@@ -610,6 +618,7 @@ err_clk_core:
 
 static void tcphy_phy_deinit(struct rockchip_typec_phy *tcphy)
 {
+	pm_runtime_put_sync(tcphy->dev);
 	reset_control_assert(tcphy->tcphy_rst);
 	reset_control_assert(tcphy->uphy_rst);
 	reset_control_assert(tcphy->pipe_rst);
@@ -987,6 +996,15 @@ static int rockchip_typec_phy_probe(struct platform_device *pdev)
 		return PTR_ERR(phy_provider);
 	}
 
+	pm_runtime_enable(dev);
+
+	return 0;
+}
+
+static int rockchip_typec_phy_remove(struct platform_device *pdev)
+{
+	pm_runtime_disable(&pdev->dev);
+
 	return 0;
 }
 
@@ -999,6 +1017,7 @@ MODULE_DEVICE_TABLE(of, rockchip_typec_phy_dt_ids);
 
 static struct platform_driver rockchip_typec_phy_driver = {
 	.probe		= rockchip_typec_phy_probe,
+	.remove		= rockchip_typec_phy_remove,
 	.driver		= {
 		.name	= "rockchip-typec-phy",
 		.of_match_table = rockchip_typec_phy_dt_ids,
Signature · 1 line
1.9.1
#1 lore raw

PATCH v2 2/2 arm64: dts: rk3399: add powerdomain for typec

The tcpc power domain will try to power up/down the power of Type-C PHY. Hence, we need control it in Type-C PHY driver with the pm_runtime helper.

---

Changes in v2: None

 arch/arm64/boot/dts/rockchip/rk3399.dtsi | 2 ++
 1 file changed, 2 insertions(+)
arch/arm64/boot/dts/rockchip/rk3399.dtsi +2 -0
index 8c51095..3eb52b3 100644
@@ -1262,6 +1262,7 @@
 		clock-names = "tcpdcore", "tcpdphy-ref";
 		assigned-clocks = <&cru SCLK_UPHY0_TCPDCORE>;
 		assigned-clock-rates = <50000000>;
+		power-domains = <&power RK3399_PD_TCPD0>;
 		resets = <&cru SRST_UPHY0>,
 			 <&cru SRST_UPHY0_PIPE_L00>,
 			 <&cru SRST_P_UPHY0_TCPHY>;
@@ -1290,6 +1291,7 @@
 		clock-names = "tcpdcore", "tcpdphy-ref";
 		assigned-clocks = <&cru SCLK_UPHY1_TCPDCORE>;
 		assigned-clock-rates = <50000000>;
+		power-domains = <&power RK3399_PD_TCPD1>;
 		resets = <&cru SRST_UPHY1>,
 			 <&cru SRST_UPHY1_PIPE_L00>,
 			 <&cru SRST_P_UPHY1_TCPHY>;
Signature · 1 line
1.9.1
maintainer
#2 lore raw

Re: [PATCH v2 2/2] arm64: dts: rk3399: add powerdomain for typec

Am Mittwoch, 7. September 2016, 16:06:17 CEST schrieb Chris Zhong:

Quoted 4 lines

The tcpc power domain will try to power up/down the power of Type-C PHY. Hence, we need control it in Type-C PHY driver with the pm_runtime helper.

applied to my dts64 branch for 4.9 (or 4.10) after fixing the subject (rockchip: instead of rk3399:), as even without the advanced logic from patch1 the driver core will already make sure to at least powerup the domain before probe and power-down after remove.

Heiko

#3 lore raw
In reply to Chris Zhong

Hi,

Quoted 17 lines · Chris Zhong

Adds pm_runtime support for rockchip Type-C, so that power domain is enabled only when there is a transaction going on to help save power.

---

Changes in v2:
-- add pm_runtime_put_sync in err case

 drivers/phy/phy-rockchip-typec.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)
drivers/phy/phy-rockchip-typec.c +0 -0
index fb58a27..0b2f528 100644

drivers/phy/phy-rockchip-typec.c static int tcphy_phy_init(struct rockchip_typec_phy *tcphy, u8 mode) · line 559

Quoted 8 lines
drivers/phy/phy-rockchip-typec.c +5 -0
@@ -552,6 +552,12 @@ static int tcphy_phy_init(struct rockchip_typec_phy *tcphy, u8 mode)
 		goto err_clk_core;
 	}
 
+	ret = pm_runtime_get_sync(tcphy->dev);
+	if (ret < 0) {
+		dev_err(tcphy->dev, "cannot get pm runtime %d\n", ret);
+		goto err_clk_ref;
+	}

phy_core will do get_sync for you if.. <see below>

Quoted 24 lines
drivers/phy/phy-rockchip-typec.c +4 -0
+
 	reset_control_deassert(tcphy->tcphy_rst);
 
 	property_enable(tcphy, &cfg->typec_conn_dir, tcphy->flip);
@@ -600,8 +606,10 @@ static int tcphy_phy_init(struct rockchip_typec_phy *tcphy, u8 mode)
 	return 0;
 
 err_wait_pma:
+	pm_runtime_put_sync(tcphy->dev);
 	reset_control_assert(tcphy->uphy_rst);
 	reset_control_assert(tcphy->tcphy_rst);
+err_clk_ref:
 	clk_disable_unprepare(tcphy->clk_ref);
 err_clk_core:
 	clk_disable_unprepare(tcphy->clk_core);
@@ -610,6 +618,7 @@ err_clk_core:
 
 static void tcphy_phy_deinit(struct rockchip_typec_phy *tcphy)
 {
+	pm_runtime_put_sync(tcphy->dev);
 	reset_control_assert(tcphy->tcphy_rst);
 	reset_control_assert(tcphy->uphy_rst);
 	reset_control_assert(tcphy->pipe_rst);

drivers/phy/phy-rockchip-typec.c static int rockchip_typec_phy_probe(struct platform_device *pdev) · line 999

Quoted 4 lines
drivers/phy/phy-rockchip-typec.c +1 -0
@@ -987,6 +996,15 @@ static int rockchip_typec_phy_probe(struct platform_device *pdev)
 		return PTR_ERR(phy_provider);
 	}
 
+	pm_runtime_enable(dev);

... pm_runtime_enable is invoked before phy_create.

Thanks
Kishon

#4 lore raw

PATCH RESEND v3 1/2 phy: rockchip-typec: add pm runtime support

Adds pm_runtime support for rockchip Type-C, so that power domain is enabled only when there is a transaction going on to help save power.

---

Changes in v3:
- use phy_core pm_runtime

Changes in v2:
- add pm_runtime_put_sync in err case

 drivers/phy/phy-rockchip-typec.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/phy/phy-rockchip-typec.c +10 -0
index fb58a27..7cfb0f8 100644
@@ -960,6 +960,8 @@ static int rockchip_typec_phy_probe(struct platform_device *pdev)
 		return PTR_ERR(tcphy->extcon);
 	}
 
+	pm_runtime_enable(dev);
+
 	for_each_available_child_of_node(np, child_np) {
 		struct phy *phy;
 
@@ -990,6 +992,13 @@ static int rockchip_typec_phy_probe(struct platform_device *pdev)
 	return 0;
 }
 
+static int rockchip_typec_phy_remove(struct platform_device *pdev)
+{
+	pm_runtime_disable(&pdev->dev);
+
+	return 0;
+}
+
 static const struct of_device_id rockchip_typec_phy_dt_ids[] = {
 	{ .compatible = "rockchip,rk3399-typec-phy" },
 	{}
@@ -999,6 +1008,7 @@ MODULE_DEVICE_TABLE(of, rockchip_typec_phy_dt_ids);
 
 static struct platform_driver rockchip_typec_phy_driver = {
 	.probe		= rockchip_typec_phy_probe,
+	.remove		= rockchip_typec_phy_remove,
 	.driver		= {
 		.name	= "rockchip-typec-phy",
 		.of_match_table = rockchip_typec_phy_dt_ids,
Signature · 1 line
1.9.1
#5 lore raw
Quoted 20 lines · Chris Zhong

Adds pm_runtime support for rockchip Type-C, so that power domain is enabled only when there is a transaction going on to help save power.

---

Changes in v3:
- use phy_core pm_runtime

Changes in v2:
- add pm_runtime_put_sync in err case

 drivers/phy/phy-rockchip-typec.c | 10 ++++++++++
 1 file changed, 10 insertions(+)
drivers/phy/phy-rockchip-typec.c +0 -0
index fb58a27..7cfb0f8 100644

drivers/phy/phy-rockchip-typec.c static int rockchip_typec_phy_probe(struct platform_device *pdev) · line 964

Quoted 5 lines
drivers/phy/phy-rockchip-typec.c +2 -0
@@ -960,6 +960,8 @@ static int rockchip_typec_phy_probe(struct platform_device *pdev)
                return PTR_ERR(tcphy->extcon);
        }
 
+       pm_runtime_enable(dev);
+

Does this now need a matching pm_runtime_disable() in error cases ?

Guenter

Quoted 28 lines
drivers/phy/phy-rockchip-typec.c +8 -1
        for_each_available_child_of_node(np, child_np) {
                struct phy *phy;
 
@@ -990,6 +992,13 @@ static int rockchip_typec_phy_probe(struct platform_device *pdev)
        return 0;
 }
 
+static int rockchip_typec_phy_remove(struct platform_device *pdev)
+{
+       pm_runtime_disable(&pdev->dev);
+
+       return 0;
+}
+
 static const struct of_device_id rockchip_typec_phy_dt_ids[] = {
        { .compatible = "rockchip,rk3399-typec-phy" },
        {}
@@ -999,6 +1008,7 @@ MODULE_DEVICE_TABLE(of, rockchip_typec_phy_dt_ids);
 
 static struct platform_driver rockchip_typec_phy_driver = {
        .probe          = rockchip_typec_phy_probe,
+       .remove         = rockchip_typec_phy_remove,
        .driver         = {
                .name   = "rockchip-typec-phy",
                .of_match_table = rockchip_typec_phy_dt_ids,
--

1.9.1