[PATCH net-next] net: stmmac: dwmac-qcom-ethqos: Add support for pm ops

From: Sneh Shah
Date: Sat Jan 27 2024 - 08:04:41 EST


Add qcom ethqos specific runtime and system sleep pm ops.
As part of system sleep qcom ethqos needs to disable all clocks.
This ops will be extended further with qcom specific features.

Signed-off-by: Sneh Shah <quic_snehshah@xxxxxxxxxxx>
---
.../stmicro/stmmac/dwmac-qcom-ethqos.c | 51 ++++++++++++++++++-
1 file changed, 50 insertions(+), 1 deletion(-)

diff --git a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
index 31631e3f89d0..cba601ee9e01 100644
--- a/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
+++ b/drivers/net/ethernet/stmicro/stmmac/dwmac-qcom-ethqos.c
@@ -720,6 +720,55 @@ static void ethqos_ptp_clk_freq_config(struct stmmac_priv *priv)
netdev_dbg(priv->dev, "PTP rate %d\n", plat_dat->clk_ptp_rate);
}

+static int qcom_ethqos_runtime_suspend(struct device *dev)
+{
+ struct net_device *ndev = dev_get_drvdata(dev);
+ struct stmmac_priv *priv = netdev_priv(ndev);
+
+ return stmmac_bus_clks_config(priv, false);
+}
+
+static int qcom_ethqos_runtime_resume(struct device *dev)
+{
+ struct net_device *ndev = dev_get_drvdata(dev);
+ struct stmmac_priv *priv = netdev_priv(ndev);
+
+ return stmmac_bus_clks_config(priv, true);
+}
+
+static int qcom_ethqos_suspend(struct device *dev)
+{
+ struct net_device *ndev = dev_get_drvdata(dev);
+ struct stmmac_priv *priv = netdev_priv(ndev);
+ int ret;
+
+ if (!ndev || !netif_running(ndev))
+ return -EINVAL;
+
+ ret = stmmac_suspend(dev);
+
+ return stmmac_bus_clks_config(priv, false);
+}
+
+static int qcom_ethqos_resume(struct device *dev)
+{
+ struct net_device *ndev = dev_get_drvdata(dev);
+ struct stmmac_priv *priv = netdev_priv(ndev);
+ int ret;
+
+ if (!ndev || !netif_running(ndev))
+ return -EINVAL;
+
+ stmmac_bus_clks_config(priv, true);
+
+ return stmmac_resume(dev);
+}
+
+const struct dev_pm_ops qcom_ethqos_pm_ops = {
+ SET_SYSTEM_SLEEP_PM_OPS(qcom_ethqos_suspend, qcom_ethqos_resume)
+ SET_RUNTIME_PM_OPS(qcom_ethqos_runtime_suspend, qcom_ethqos_runtime_resume, NULL)
+};
+
static int qcom_ethqos_probe(struct platform_device *pdev)
{
struct device_node *np = pdev->dev.of_node;
@@ -838,7 +887,7 @@ static struct platform_driver qcom_ethqos_driver = {
.probe = qcom_ethqos_probe,
.driver = {
.name = "qcom-ethqos",
- .pm = &stmmac_pltfr_pm_ops,
+ .pm = &qcom_ethqos_pm_ops,
.of_match_table = qcom_ethqos_match,
},
};
--
2.17.1