[RFC PATCH 09/10] net: ti: prueth: Adds power management support for PRU-ICSS

From: Basharath Hussain Khaja
Date: Fri Jan 10 2025 - 02:15:25 EST


From: Roger Quadros <rogerq@xxxxxx>

Changes for supporting the sleep/resume feature for PRU-ICSS.

PRU-ICSS will be kept in IDLE mode for optimal power consumption by Linux
power management subsystem and will be resumed when it is required.

Signed-off-by: Roger Quadros <rogerq@xxxxxx>
Signed-off-by: Andrew F. Davis <afd@xxxxxx>
Signed-off-by: Parvathi Pudi <parvathi@xxxxxxxxxxx>
Signed-off-by: Basharath Hussain Khaja <basharath@xxxxxxxxxxx>
---
drivers/net/ethernet/ti/icssm/icssm_prueth.c | 62 ++++++++++++++++++++
1 file changed, 62 insertions(+)

diff --git a/drivers/net/ethernet/ti/icssm/icssm_prueth.c b/drivers/net/ethernet/ti/icssm/icssm_prueth.c
index 97de6b7ebd29..7727975dab88 100644
--- a/drivers/net/ethernet/ti/icssm/icssm_prueth.c
+++ b/drivers/net/ethernet/ti/icssm/icssm_prueth.c
@@ -2325,6 +2325,67 @@ static void icssm_prueth_remove(struct platform_device *pdev)
pru_rproc_put(prueth->pru0);
}

+#ifdef CONFIG_PM_SLEEP
+static int icssm_prueth_suspend(struct device *dev)
+{
+ struct prueth *prueth = dev_get_drvdata(dev);
+ struct net_device *ndev;
+ int i, ret;
+
+ for (i = 0; i < PRUETH_NUM_MACS; i++) {
+ ndev = prueth->registered_netdevs[i];
+
+ if (!ndev)
+ continue;
+
+ if (netif_running(ndev)) {
+ netif_device_detach(ndev);
+ ret = icssm_emac_ndo_stop(ndev);
+ if (ret < 0) {
+ netdev_err(ndev, "failed to stop: %d", ret);
+ return ret;
+ }
+ }
+ }
+
+ pruss_cfg_ocp_master_ports(prueth->pruss, 0);
+
+ return 0;
+}
+
+static int icssm_prueth_resume(struct device *dev)
+{
+ struct prueth *prueth = dev_get_drvdata(dev);
+ struct net_device *ndev;
+ int i, ret;
+
+ pruss_cfg_ocp_master_ports(prueth->pruss, 1);
+
+ for (i = 0; i < PRUETH_NUM_MACS; i++) {
+ ndev = prueth->registered_netdevs[i];
+
+ if (!ndev)
+ continue;
+
+ if (netif_running(ndev)) {
+ ret = icssm_emac_ndo_open(ndev);
+ if (ret < 0) {
+ netdev_err(ndev, "failed to start: %d", ret);
+ return ret;
+ }
+ netif_device_attach(ndev);
+ }
+ }
+
+ return 0;
+}
+
+#endif /* CONFIG_PM_SLEEP */
+
+static const struct dev_pm_ops prueth_dev_pm_ops = {
+ SET_SYSTEM_SLEEP_PM_OPS(icssm_prueth_suspend, icssm_prueth_resume)
+};
+
/* AM57xx SoC-specific firmware data */
static struct prueth_private_data am57xx_prueth_pdata = {
.fw_pru[PRUSS_PRU0] = {
@@ -2349,6 +2410,7 @@ static struct platform_driver prueth_driver = {
.driver = {
.name = "prueth",
.of_match_table = prueth_dt_match,
+ .pm = &prueth_dev_pm_ops,
},
};
module_platform_driver(prueth_driver);
--
2.34.1