Commit 45aa83cb authored by Vijendar Mukunda's avatar Vijendar Mukunda Committed by Mark Brown

ASoC: amd: ps: use acp_lock to protect common registers in pdm driver

Retrieve acp_lock mutex as platform data and use it for protecting
ACP common registers access in acp pdm driver.
Signed-off-by: default avatarVijendar Mukunda <Vijendar.Mukunda@amd.com>
Link: https://lore.kernel.org/r/20230104055435.321327-2-Vijendar.Mukunda@amd.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent f763fb2f
...@@ -88,6 +88,7 @@ struct pdm_stream_instance { ...@@ -88,6 +88,7 @@ struct pdm_stream_instance {
struct pdm_dev_data { struct pdm_dev_data {
u32 pdm_irq; u32 pdm_irq;
void __iomem *acp63_base; void __iomem *acp63_base;
struct mutex *acp_lock;
struct snd_pcm_substream *capture_stream; struct snd_pcm_substream *capture_stream;
}; };
......
...@@ -59,22 +59,26 @@ static void acp63_enable_pdm_clock(void __iomem *acp_base) ...@@ -59,22 +59,26 @@ static void acp63_enable_pdm_clock(void __iomem *acp_base)
acp63_writel(pdm_ctrl, acp_base + ACP_WOV_MISC_CTRL); acp63_writel(pdm_ctrl, acp_base + ACP_WOV_MISC_CTRL);
} }
static void acp63_enable_pdm_interrupts(void __iomem *acp_base) static void acp63_enable_pdm_interrupts(struct pdm_dev_data *adata)
{ {
u32 ext_int_ctrl; u32 ext_int_ctrl;
ext_int_ctrl = acp63_readl(acp_base + ACP_EXTERNAL_INTR_CNTL); mutex_lock(adata->acp_lock);
ext_int_ctrl = acp63_readl(adata->acp63_base + ACP_EXTERNAL_INTR_CNTL);
ext_int_ctrl |= PDM_DMA_INTR_MASK; ext_int_ctrl |= PDM_DMA_INTR_MASK;
acp63_writel(ext_int_ctrl, acp_base + ACP_EXTERNAL_INTR_CNTL); acp63_writel(ext_int_ctrl, adata->acp63_base + ACP_EXTERNAL_INTR_CNTL);
mutex_unlock(adata->acp_lock);
} }
static void acp63_disable_pdm_interrupts(void __iomem *acp_base) static void acp63_disable_pdm_interrupts(struct pdm_dev_data *adata)
{ {
u32 ext_int_ctrl; u32 ext_int_ctrl;
ext_int_ctrl = acp63_readl(acp_base + ACP_EXTERNAL_INTR_CNTL); mutex_lock(adata->acp_lock);
ext_int_ctrl = acp63_readl(adata->acp63_base + ACP_EXTERNAL_INTR_CNTL);
ext_int_ctrl &= ~PDM_DMA_INTR_MASK; ext_int_ctrl &= ~PDM_DMA_INTR_MASK;
acp63_writel(ext_int_ctrl, acp_base + ACP_EXTERNAL_INTR_CNTL); acp63_writel(ext_int_ctrl, adata->acp63_base + ACP_EXTERNAL_INTR_CNTL);
mutex_unlock(adata->acp_lock);
} }
static bool acp63_check_pdm_dma_status(void __iomem *acp_base) static bool acp63_check_pdm_dma_status(void __iomem *acp_base)
...@@ -196,7 +200,7 @@ static int acp63_pdm_dma_open(struct snd_soc_component *component, ...@@ -196,7 +200,7 @@ static int acp63_pdm_dma_open(struct snd_soc_component *component,
return ret; return ret;
} }
acp63_enable_pdm_interrupts(adata->acp63_base); acp63_enable_pdm_interrupts(adata);
if (substream->stream == SNDRV_PCM_STREAM_CAPTURE) if (substream->stream == SNDRV_PCM_STREAM_CAPTURE)
adata->capture_stream = substream; adata->capture_stream = substream;
...@@ -272,7 +276,7 @@ static int acp63_pdm_dma_close(struct snd_soc_component *component, ...@@ -272,7 +276,7 @@ static int acp63_pdm_dma_close(struct snd_soc_component *component,
struct pdm_dev_data *adata = dev_get_drvdata(component->dev); struct pdm_dev_data *adata = dev_get_drvdata(component->dev);
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
acp63_disable_pdm_interrupts(adata->acp63_base); acp63_disable_pdm_interrupts(adata);
adata->capture_stream = NULL; adata->capture_stream = NULL;
kfree(runtime->private_data); kfree(runtime->private_data);
return 0; return 0;
...@@ -353,6 +357,10 @@ static int acp63_pdm_audio_probe(struct platform_device *pdev) ...@@ -353,6 +357,10 @@ static int acp63_pdm_audio_probe(struct platform_device *pdev)
struct pdm_dev_data *adata; struct pdm_dev_data *adata;
int status; int status;
if (!pdev->dev.platform_data) {
dev_err(&pdev->dev, "platform_data not retrieved\n");
return -ENODEV;
}
res = platform_get_resource(pdev, IORESOURCE_MEM, 0); res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!res) { if (!res) {
dev_err(&pdev->dev, "IORESOURCE_MEM FAILED\n"); dev_err(&pdev->dev, "IORESOURCE_MEM FAILED\n");
...@@ -368,7 +376,7 @@ static int acp63_pdm_audio_probe(struct platform_device *pdev) ...@@ -368,7 +376,7 @@ static int acp63_pdm_audio_probe(struct platform_device *pdev)
return -ENOMEM; return -ENOMEM;
adata->capture_stream = NULL; adata->capture_stream = NULL;
adata->acp_lock = pdev->dev.platform_data;
dev_set_drvdata(&pdev->dev, adata); dev_set_drvdata(&pdev->dev, adata);
status = devm_snd_soc_register_component(&pdev->dev, status = devm_snd_soc_register_component(&pdev->dev,
&acp63_pdm_component, &acp63_pdm_component,
...@@ -408,7 +416,7 @@ static int __maybe_unused acp63_pdm_resume(struct device *dev) ...@@ -408,7 +416,7 @@ static int __maybe_unused acp63_pdm_resume(struct device *dev)
acp63_init_pdm_ring_buffer(PDM_MEM_WINDOW_START, buffer_len, acp63_init_pdm_ring_buffer(PDM_MEM_WINDOW_START, buffer_len,
period_bytes, adata->acp63_base); period_bytes, adata->acp63_base);
} }
acp63_enable_pdm_interrupts(adata->acp63_base); acp63_enable_pdm_interrupts(adata);
return 0; return 0;
} }
...@@ -417,7 +425,7 @@ static int __maybe_unused acp63_pdm_suspend(struct device *dev) ...@@ -417,7 +425,7 @@ static int __maybe_unused acp63_pdm_suspend(struct device *dev)
struct pdm_dev_data *adata; struct pdm_dev_data *adata;
adata = dev_get_drvdata(dev); adata = dev_get_drvdata(dev);
acp63_disable_pdm_interrupts(adata->acp63_base); acp63_disable_pdm_interrupts(adata);
return 0; return 0;
} }
...@@ -426,7 +434,7 @@ static int __maybe_unused acp63_pdm_runtime_resume(struct device *dev) ...@@ -426,7 +434,7 @@ static int __maybe_unused acp63_pdm_runtime_resume(struct device *dev)
struct pdm_dev_data *adata; struct pdm_dev_data *adata;
adata = dev_get_drvdata(dev); adata = dev_get_drvdata(dev);
acp63_enable_pdm_interrupts(adata->acp63_base); acp63_enable_pdm_interrupts(adata);
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment