]> git.baikalelectronics.ru Git - kernel.git/commitdiff
ASoC: amd: add RPL Platform pci driver pm-ops
authorSyed Saba Kareem <Syed.SabaKareem@amd.com>
Thu, 21 Jul 2022 06:10:01 +0000 (11:40 +0530)
committerMark Brown <broonie@kernel.org>
Thu, 21 Jul 2022 22:25:18 +0000 (23:25 +0100)
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>
Link: https://lore.kernel.org/r/20220721061035.91139-4-Syed.SabaKareem@amd.com
Signed-off-by: Mark Brown <broonie@kernel.org>
sound/soc/amd/rpl/rpl-pci-acp6x.c
sound/soc/amd/rpl/rpl_acp6x.h

index 71ae90a00f3624aff5b44ca291d2f6a0d88b57d0..a8e548ed991bbbc3a7bc170a9b586234f79c929d 100644 (file)
@@ -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 @@ disable_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);
index 5de19d5c892e10fa087538e2e16faa693a7d8866..f5816a33632ec3d18d29b2bcad2fef6b5800e390 100644 (file)
 #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);