diff mbox series

[4/5] ASoC: amd: add RPL Platform pci driver pm-ops

Message ID 20220721061035.91139-4-Syed.SabaKareem@amd.com (mailing list archive)
State Accepted
Commit bc1100f29d1d0bfcd36ba3690a945235ffe149c8
Headers show
Series [1/5] ASoC: amd: add RPL Platform acp header file | expand

Commit Message

Saba Kareem, Syed July 21, 2022, 6:10 a.m. UTC
From: Syed Saba Kareem <Syed.SabaKareem@amd.com>

Add RPL Platform ACP PCI driver pm ops.

Signed-off-by: Syed Saba Kareem <Syed.SabaKareem@amd.com>
Reviewed-by: Vijendar Mukunda <Vijendar.Mukunda@amd.com>
---
 sound/soc/amd/rpl/rpl-pci-acp6x.c | 40 +++++++++++++++++++++++++++++++
 sound/soc/amd/rpl/rpl_acp6x.h     | 15 ++++++++++++
 2 files changed, 55 insertions(+)
diff mbox series

Patch

diff --git a/sound/soc/amd/rpl/rpl-pci-acp6x.c b/sound/soc/amd/rpl/rpl-pci-acp6x.c
index 71ae90a00f36..a8e548ed991b 100644
--- a/sound/soc/amd/rpl/rpl-pci-acp6x.c
+++ b/sound/soc/amd/rpl/rpl-pci-acp6x.c
@@ -10,6 +10,7 @@ 
 #include <linux/io.h>
 #include <linux/delay.h>
 #include <linux/platform_device.h>
+#include <linux/pm_runtime.h>
 
 #include "rpl_acp6x.h"
 
@@ -144,6 +145,11 @@  static int snd_rpl_probe(struct pci_dev *pci,
 	ret = rpl_init(adata->acp6x_base);
 	if (ret)
 		goto release_regions;
+	pm_runtime_set_autosuspend_delay(&pci->dev, ACP_SUSPEND_DELAY_MS);
+	pm_runtime_use_autosuspend(&pci->dev);
+	pm_runtime_put_noidle(&pci->dev);
+	pm_runtime_allow(&pci->dev);
+
 	return 0;
 release_regions:
 	pci_release_regions(pci);
@@ -153,6 +159,35 @@  static int snd_rpl_probe(struct pci_dev *pci,
 	return ret;
 }
 
+static int __maybe_unused snd_rpl_suspend(struct device *dev)
+{
+	struct rpl_dev_data *adata;
+	int ret;
+
+	adata = dev_get_drvdata(dev);
+	ret = rpl_deinit(adata->acp6x_base);
+	if (ret)
+		dev_err(dev, "ACP de-init failed\n");
+	return ret;
+}
+
+static int __maybe_unused snd_rpl_resume(struct device *dev)
+{
+	struct rpl_dev_data *adata;
+	int ret;
+
+	adata = dev_get_drvdata(dev);
+	ret = rpl_init(adata->acp6x_base);
+	if (ret)
+		dev_err(dev, "ACP init failed\n");
+	return ret;
+}
+
+static const struct dev_pm_ops rpl_pm = {
+	SET_RUNTIME_PM_OPS(snd_rpl_suspend, snd_rpl_resume, NULL)
+	SET_SYSTEM_SLEEP_PM_OPS(snd_rpl_suspend, snd_rpl_resume)
+};
+
 static void snd_rpl_remove(struct pci_dev *pci)
 {
 	struct rpl_dev_data *adata;
@@ -162,6 +197,8 @@  static void snd_rpl_remove(struct pci_dev *pci)
 	ret = rpl_deinit(adata->acp6x_base);
 	if (ret)
 		dev_err(&pci->dev, "ACP de-init failed\n");
+	pm_runtime_forbid(&pci->dev);
+	pm_runtime_get_noresume(&pci->dev);
 	pci_release_regions(pci);
 	pci_disable_device(pci);
 }
@@ -179,6 +216,9 @@  static struct pci_driver rpl_acp6x_driver  = {
 	.id_table = snd_rpl_ids,
 	.probe = snd_rpl_probe,
 	.remove = snd_rpl_remove,
+	.driver = {
+		.pm = &rpl_pm,
+	}
 };
 
 module_pci_driver(rpl_acp6x_driver);
diff --git a/sound/soc/amd/rpl/rpl_acp6x.h b/sound/soc/amd/rpl/rpl_acp6x.h
index 5de19d5c892e..f5816a33632e 100644
--- a/sound/soc/amd/rpl/rpl_acp6x.h
+++ b/sound/soc/amd/rpl/rpl_acp6x.h
@@ -10,6 +10,21 @@ 
 #define ACP_DEVICE_ID 0x15E2
 #define ACP6x_PHY_BASE_ADDRESS 0x1240000
 
+#define ACP_SOFT_RESET_SOFTRESET_AUDDONE_MASK   0x00010001
+#define ACP_PGFSM_CNTL_POWER_ON_MASK    1
+#define ACP_PGFSM_CNTL_POWER_OFF_MASK   0
+#define ACP_PGFSM_STATUS_MASK           3
+#define ACP_POWERED_ON                  0
+#define ACP_POWER_ON_IN_PROGRESS        1
+#define ACP_POWERED_OFF                 2
+#define ACP_POWER_OFF_IN_PROGRESS       3
+
+#define DELAY_US        5
+#define ACP_COUNTER     20000
+
+/* time in ms for runtime suspend delay */
+#define ACP_SUSPEND_DELAY_MS    2000
+
 static inline u32 rpl_acp_readl(void __iomem *base_addr)
 {
 	return readl(base_addr - ACP6x_PHY_BASE_ADDRESS);