2021-07-07 05:41:55

by Vijendar Mukunda

[permalink] [raw]
Subject: [PATCH 03/12] add acp5x init/de-init functions

From: Vijendar Mukunda <[email protected]>

Add Vangogh ACP PCI driver init/deinit functions.

Signed-off-by: Vijendar Mukunda <[email protected]>
---
sound/soc/amd/vangogh/acp5x.h | 12 +++
sound/soc/amd/vangogh/pci-acp5x.c | 135 ++++++++++++++++++++++++++++++
2 files changed, 147 insertions(+)

diff --git a/sound/soc/amd/vangogh/acp5x.h b/sound/soc/amd/vangogh/acp5x.h
index a5e7f7cb65a1..11b555306958 100644
--- a/sound/soc/amd/vangogh/acp5x.h
+++ b/sound/soc/amd/vangogh/acp5x.h
@@ -9,6 +9,18 @@

#define ACP5x_PHY_BASE_ADDRESS 0x1240000
#define ACP_DEVICE_ID 0x15E2
+#define ACP_SOFT_RESET_SOFTRESET_AUDDONE_MASK 0x00010001
+
+#define ACP_PGFSM_CNTL_POWER_ON_MASK 0x01
+#define ACP_PGFSM_CNTL_POWER_OFF_MASK 0x00
+#define ACP_PGFSM_STATUS_MASK 0x03
+#define ACP_POWERED_ON 0x00
+#define ACP_POWER_ON_IN_PROGRESS 0x01
+#define ACP_POWERED_OFF 0x02
+#define ACP_POWER_OFF_IN_PROGRESS 0x03
+
+#define ACP_ERR_INTR_MASK 0x20000000
+#define ACP_EXT_INTR_STAT_CLEAR_MASK 0xFFFFFFFF

static inline u32 acp_readl(void __iomem *base_addr)
{
diff --git a/sound/soc/amd/vangogh/pci-acp5x.c b/sound/soc/amd/vangogh/pci-acp5x.c
index e56d060a5cb9..dbe8fef3e294 100644
--- a/sound/soc/amd/vangogh/pci-acp5x.c
+++ b/sound/soc/amd/vangogh/pci-acp5x.c
@@ -7,13 +7,138 @@
#include <linux/pci.h>
#include <linux/module.h>
#include <linux/io.h>
+#include <linux/delay.h>

#include "acp5x.h"

+static int acp_power_gating;
+module_param(acp_power_gating, int, 0644);
+MODULE_PARM_DESC(acp_power_gating, "acp power gating flag");
+
struct acp5x_dev_data {
void __iomem *acp5x_base;
};

+static int acp5x_power_on(void __iomem *acp5x_base)
+{
+ u32 val;
+ int timeout;
+
+ val = acp_readl(acp5x_base + ACP_PGFSM_STATUS);
+
+ if (val == 0)
+ return val;
+
+ if ((val & ACP_PGFSM_STATUS_MASK) !=
+ ACP_POWER_ON_IN_PROGRESS)
+ acp_writel(ACP_PGFSM_CNTL_POWER_ON_MASK,
+ acp5x_base + ACP_PGFSM_CONTROL);
+ timeout = 0;
+ while (++timeout < 500) {
+ val = acp_readl(acp5x_base + ACP_PGFSM_STATUS);
+ if (!val)
+ return 0;
+ udelay(1);
+ }
+ return -ETIMEDOUT;
+}
+
+static int acp5x_power_off(void __iomem *acp5x_base)
+{
+ u32 val;
+ int timeout;
+
+ acp_writel(ACP_PGFSM_CNTL_POWER_OFF_MASK,
+ acp5x_base + ACP_PGFSM_CONTROL);
+ timeout = 0;
+ while (++timeout < 500) {
+ val = acp_readl(acp5x_base + ACP_PGFSM_STATUS);
+ if ((val & ACP_PGFSM_STATUS_MASK) == ACP_POWERED_OFF)
+ return 0;
+ udelay(1);
+ }
+ return -ETIMEDOUT;
+}
+
+static int acp5x_reset(void __iomem *acp5x_base)
+{
+ u32 val;
+ int timeout;
+
+ acp_writel(1, acp5x_base + ACP_SOFT_RESET);
+ timeout = 0;
+ while (++timeout < 500) {
+ val = acp_readl(acp5x_base + ACP_SOFT_RESET);
+ if (val & ACP_SOFT_RESET_SOFTRESET_AUDDONE_MASK)
+ break;
+ cpu_relax();
+ }
+ acp_writel(0, acp5x_base + ACP_SOFT_RESET);
+ timeout = 0;
+ while (++timeout < 500) {
+ val = acp_readl(acp5x_base + ACP_SOFT_RESET);
+ if (!val)
+ return 0;
+ cpu_relax();
+ }
+ return -ETIMEDOUT;
+}
+
+static void acp5x_enable_interrupts(void __iomem *acp5x_base)
+{
+ acp_writel(0x01, acp5x_base + ACP_EXTERNAL_INTR_ENB);
+}
+
+static void acp5x_disable_interrupts(void __iomem *acp5x_base)
+{
+ acp_writel(ACP_EXT_INTR_STAT_CLEAR_MASK, acp5x_base +
+ ACP_EXTERNAL_INTR_STAT);
+ acp_writel(0x00, acp5x_base + ACP_EXTERNAL_INTR_CNTL);
+ acp_writel(0x00, acp5x_base + ACP_EXTERNAL_INTR_ENB);
+}
+
+static int acp5x_init(void __iomem *acp5x_base)
+{
+ int ret;
+
+ /* power on */
+ ret = acp5x_power_on(acp5x_base);
+ if (ret) {
+ pr_err("ACP5x power on failed\n");
+ return ret;
+ }
+ /* Reset */
+ ret = acp5x_reset(acp5x_base);
+ if (ret) {
+ pr_err("ACP5x reset failed\n");
+ return ret;
+ }
+ acp5x_enable_interrupts(acp5x_base);
+ return 0;
+}
+
+static int acp5x_deinit(void __iomem *acp5x_base)
+{
+ int ret;
+
+ acp5x_disable_interrupts(acp5x_base);
+ /* Reset */
+ ret = acp5x_reset(acp5x_base);
+ if (ret) {
+ pr_err("ACP5x reset failed\n");
+ return ret;
+ }
+ /* power off */
+ if (acp_power_gating) {
+ ret = acp5x_power_off(acp5x_base);
+ if (ret) {
+ pr_err("ACP5x power off failed\n");
+ return ret;
+ }
+ }
+ return 0;
+}
+
static int snd_acp5x_probe(struct pci_dev *pci,
const struct pci_device_id *pci_id)
{
@@ -50,6 +175,9 @@ static int snd_acp5x_probe(struct pci_dev *pci,
}
pci_set_master(pci);
pci_set_drvdata(pci, adata);
+ ret = acp5x_init(adata->acp5x_base);
+ if (ret)
+ goto release_regions;

release_regions:
pci_release_regions(pci);
@@ -61,6 +189,13 @@ static int snd_acp5x_probe(struct pci_dev *pci,

static void snd_acp5x_remove(struct pci_dev *pci)
{
+ struct acp5x_dev_data *adata;
+ int ret;
+
+ adata = pci_get_drvdata(pci);
+ ret = acp5x_deinit(adata->acp5x_base);
+ if (ret)
+ dev_err(&pci->dev, "ACP de-init failed\n");
pci_release_regions(pci);
pci_disable_device(pci);
}
--
2.17.1


2021-07-07 16:36:51

by Pierre-Louis Bossart

[permalink] [raw]
Subject: Re: [PATCH 03/12] add acp5x init/de-init functions

Missing 'ASoC: amd' prefix in commit subject?


> +static int acp5x_power_on(void __iomem *acp5x_base)
> +{
> + u32 val;
> + int timeout;
> +
> + val = acp_readl(acp5x_base + ACP_PGFSM_STATUS);
> +
> + if (val == 0)
> + return val;
> +
> + if ((val & ACP_PGFSM_STATUS_MASK) !=
> + ACP_POWER_ON_IN_PROGRESS)
> + acp_writel(ACP_PGFSM_CNTL_POWER_ON_MASK,
> + acp5x_base + ACP_PGFSM_CONTROL);
> + timeout = 0;
> + while (++timeout < 500) {
> + val = acp_readl(acp5x_base + ACP_PGFSM_STATUS);
> + if (!val)

Shouldn't you use something like
if ((val & ACP_PGFSM_STATUS_MASK) == ACP_POWERED_ON)
for symmetry with the power-off case?

> + return 0;
> + udelay(1);
> + }
> + return -ETIMEDOUT;
> +}
> +
> +static int acp5x_power_off(void __iomem *acp5x_base)
> +{
> + u32 val;
> + int timeout;
> +
> + acp_writel(ACP_PGFSM_CNTL_POWER_OFF_MASK,
> + acp5x_base + ACP_PGFSM_CONTROL);
> + timeout = 0;
> + while (++timeout < 500) {
> + val = acp_readl(acp5x_base + ACP_PGFSM_STATUS);
> + if ((val & ACP_PGFSM_STATUS_MASK) == ACP_POWERED_OFF)
> + return 0;
> + udelay(1);
> + }
> + return -ETIMEDOUT;
> +}
> +
> +static int acp5x_reset(void __iomem *acp5x_base)
> +{
> + u32 val;
> + int timeout;
> +
> + acp_writel(1, acp5x_base + ACP_SOFT_RESET);
> + timeout = 0;
> + while (++timeout < 500) {
> + val = acp_readl(acp5x_base + ACP_SOFT_RESET);
> + if (val & ACP_SOFT_RESET_SOFTRESET_AUDDONE_MASK)
> + break;
> + cpu_relax();
> + }
> + acp_writel(0, acp5x_base + ACP_SOFT_RESET);
> + timeout = 0;
> + while (++timeout < 500) {
> + val = acp_readl(acp5x_base + ACP_SOFT_RESET);
> + if (!val)
> + return 0;
> + cpu_relax();
> + }
> + return -ETIMEDOUT;
> +}
> +
> +static void acp5x_enable_interrupts(void __iomem *acp5x_base)
> +{
> + acp_writel(0x01, acp5x_base + ACP_EXTERNAL_INTR_ENB);
> +}
> +
> +static void acp5x_disable_interrupts(void __iomem *acp5x_base)
> +{
> + acp_writel(ACP_EXT_INTR_STAT_CLEAR_MASK, acp5x_base +
> + ACP_EXTERNAL_INTR_STAT);
> + acp_writel(0x00, acp5x_base + ACP_EXTERNAL_INTR_CNTL);
> + acp_writel(0x00, acp5x_base + ACP_EXTERNAL_INTR_ENB);
> +}
> +
> +static int acp5x_init(void __iomem *acp5x_base)
> +{
> + int ret;
> +
> + /* power on */
> + ret = acp5x_power_on(acp5x_base);
> + if (ret) {
> + pr_err("ACP5x power on failed\n");
> + return ret;
> + }
> + /* Reset */
> + ret = acp5x_reset(acp5x_base);
> + if (ret) {
> + pr_err("ACP5x reset failed\n");
> + return ret;
> + }
> + acp5x_enable_interrupts(acp5x_base);
> + return 0;
> +}
> +
> +static int acp5x_deinit(void __iomem *acp5x_base)
> +{
> + int ret;
> +
> + acp5x_disable_interrupts(acp5x_base);
> + /* Reset */
> + ret = acp5x_reset(acp5x_base);
> + if (ret) {
> + pr_err("ACP5x reset failed\n");
> + return ret;
> + }
> + /* power off */
> + if (acp_power_gating) {
> + ret = acp5x_power_off(acp5x_base);
> + if (ret) {
> + pr_err("ACP5x power off failed\n");
> + return ret;
> + }
> + }
> + return 0;

shouldn't you have a sequence for shutdown that ignores the acp_power_gating parameter?

2021-07-08 13:13:38

by Vijendar Mukunda

[permalink] [raw]
Subject: Re: [PATCH 03/12] add acp5x init/de-init functions

On 7/7/21 9:45 PM, Pierre-Louis Bossart wrote:
> Missing 'ASoC: amd' prefix in commit subject?
Will add prefix.
>
>
>> +static int acp5x_power_on(void __iomem *acp5x_base)
>> +{
>> + u32 val;
>> + int timeout;
>> +
>> + val = acp_readl(acp5x_base + ACP_PGFSM_STATUS);
>> +
>> + if (val == 0)
>> + return val;
>> +
>> + if ((val & ACP_PGFSM_STATUS_MASK) !=
>> + ACP_POWER_ON_IN_PROGRESS)
>> + acp_writel(ACP_PGFSM_CNTL_POWER_ON_MASK,
>> + acp5x_base + ACP_PGFSM_CONTROL);
>> + timeout = 0;
>> + while (++timeout < 500) {
>> + val = acp_readl(acp5x_base + ACP_PGFSM_STATUS);
>> + if (!val)
>
> Shouldn't you use something like
> if ((val & ACP_PGFSM_STATUS_MASK) == ACP_POWERED_ON)
> for symmetry with the power-off case?
Yes we can do that. will fix it.
>
>> + return 0;
>> + udelay(1);
>> + }
>> + return -ETIMEDOUT;
>> +}
>> +
>> +static int acp5x_power_off(void __iomem *acp5x_base)
>> +{
>> + u32 val;
>> + int timeout;
>> +
>> + acp_writel(ACP_PGFSM_CNTL_POWER_OFF_MASK,
>> + acp5x_base + ACP_PGFSM_CONTROL);
>> + timeout = 0;
>> + while (++timeout < 500) {
>> + val = acp_readl(acp5x_base + ACP_PGFSM_STATUS);
>> + if ((val & ACP_PGFSM_STATUS_MASK) == ACP_POWERED_OFF)
>> + return 0;
>> + udelay(1);
>> + }
>> + return -ETIMEDOUT;
>> +}
>> +
>> +static int acp5x_reset(void __iomem *acp5x_base)
>> +{
>> + u32 val;
>> + int timeout;
>> +
>> + acp_writel(1, acp5x_base + ACP_SOFT_RESET);
>> + timeout = 0;
>> + while (++timeout < 500) {
>> + val = acp_readl(acp5x_base + ACP_SOFT_RESET);
>> + if (val & ACP_SOFT_RESET_SOFTRESET_AUDDONE_MASK)
>> + break;
>> + cpu_relax();
>> + }
>> + acp_writel(0, acp5x_base + ACP_SOFT_RESET);
>> + timeout = 0;
>> + while (++timeout < 500) {
>> + val = acp_readl(acp5x_base + ACP_SOFT_RESET);
>> + if (!val)
>> + return 0;
>> + cpu_relax();
>> + }
>> + return -ETIMEDOUT;
>> +}
>> +
>> +static void acp5x_enable_interrupts(void __iomem *acp5x_base)
>> +{
>> + acp_writel(0x01, acp5x_base + ACP_EXTERNAL_INTR_ENB);
>> +}
>> +
>> +static void acp5x_disable_interrupts(void __iomem *acp5x_base)
>> +{
>> + acp_writel(ACP_EXT_INTR_STAT_CLEAR_MASK, acp5x_base +
>> + ACP_EXTERNAL_INTR_STAT);
>> + acp_writel(0x00, acp5x_base + ACP_EXTERNAL_INTR_CNTL);
>> + acp_writel(0x00, acp5x_base + ACP_EXTERNAL_INTR_ENB);
>> +}
>> +
>> +static int acp5x_init(void __iomem *acp5x_base)
>> +{
>> + int ret;
>> +
>> + /* power on */
>> + ret = acp5x_power_on(acp5x_base);
>> + if (ret) {
>> + pr_err("ACP5x power on failed\n");
>> + return ret;
>> + }
>> + /* Reset */
>> + ret = acp5x_reset(acp5x_base);
>> + if (ret) {
>> + pr_err("ACP5x reset failed\n");
>> + return ret;
>> + }
>> + acp5x_enable_interrupts(acp5x_base);
>> + return 0;
>> +}
>> +
>> +static int acp5x_deinit(void __iomem *acp5x_base)
>> +{
>> + int ret;
>> +
>> + acp5x_disable_interrupts(acp5x_base);
>> + /* Reset */
>> + ret = acp5x_reset(acp5x_base);
>> + if (ret) {
>> + pr_err("ACP5x reset failed\n");
>> + return ret;
>> + }
>> + /* power off */
>> + if (acp_power_gating) {
>> + ret = acp5x_power_off(acp5x_base);
>> + if (ret) {
>> + pr_err("ACP5x power off failed\n");
>> + return ret;
>> + }
>> + }
>> + return 0;
>
> shouldn't you have a sequence for shutdown that ignores the acp_power_gating parameter?
>
BIOS will apply ACP Power gating(which is part of ACP power off
sequence) when ACP enters D3 state. i.e BIOS will control ACP Power gating.

acp5x_power_off() API is no longer required.This was implemented to
verify ACP Power gating during initial driver bring up.

We will drop acp5x_power_off() API, will remove acp_power_gating
parameter and post the new version.