Commit 7929985c authored by Ajit Kumar Pandey's avatar Ajit Kumar Pandey Committed by Mark Brown

ASoC: amd: acp: Initialize list to store acp_stream during pcm_open

We are currently allocating acp_stream during pcm_open and saving
it in static array corresponds to array index calculated based on
cpu dai->driver id. This approach will fail if we have single dai
linked to multiple pcm device as we will have same dai->driver id
or array index for multiple pcm open. Initialize new linked list
stream_list to store opened pcm stream info dynamically.
Signed-off-by: default avatarAjit Kumar Pandey <AjitKumar.Pandey@amd.com>
Signed-off-by: default avatarVenkata Prasad Potturu <venkataprasad.potturu@amd.com>
Reviewed-by: default avatarVijendar Mukunda <Vijendar.Mukunda@amd.com>
Link: https://lore.kernel.org/r/20220810132913.1181247-2-venkataprasad.potturu@amd.comSigned-off-by: default avatarMark Brown <broonie@kernel.org>
parent 4d39265b
...@@ -94,7 +94,7 @@ static irqreturn_t i2s_irq_handler(int irq, void *data) ...@@ -94,7 +94,7 @@ static irqreturn_t i2s_irq_handler(int irq, void *data)
struct acp_resource *rsrc = adata->rsrc; struct acp_resource *rsrc = adata->rsrc;
struct acp_stream *stream; struct acp_stream *stream;
u16 i2s_flag = 0; u16 i2s_flag = 0;
u32 ext_intr_stat, ext_intr_stat1, i; u32 ext_intr_stat, ext_intr_stat1;
if (!adata) if (!adata)
return IRQ_NONE; return IRQ_NONE;
...@@ -104,14 +104,13 @@ static irqreturn_t i2s_irq_handler(int irq, void *data) ...@@ -104,14 +104,13 @@ static irqreturn_t i2s_irq_handler(int irq, void *data)
ext_intr_stat = readl(ACP_EXTERNAL_INTR_STAT(adata, rsrc->irqp_used)); ext_intr_stat = readl(ACP_EXTERNAL_INTR_STAT(adata, rsrc->irqp_used));
for (i = 0; i < ACP_MAX_STREAM; i++) { spin_lock(&adata->acp_lock);
stream = adata->stream[i]; list_for_each_entry(stream, &adata->stream_list, list) {
if (stream && (ext_intr_stat & stream->irq_bit)) { if (stream && (ext_intr_stat & stream->irq_bit)) {
writel(stream->irq_bit, writel(stream->irq_bit,
ACP_EXTERNAL_INTR_STAT(adata, rsrc->irqp_used)); ACP_EXTERNAL_INTR_STAT(adata, rsrc->irqp_used));
snd_pcm_period_elapsed(stream->substream); snd_pcm_period_elapsed(stream->substream);
i2s_flag = 1; i2s_flag = 1;
break;
} }
if (adata->rsrc->no_of_ctrls == 2) { if (adata->rsrc->no_of_ctrls == 2) {
if (stream && (ext_intr_stat1 & stream->irq_bit)) { if (stream && (ext_intr_stat1 & stream->irq_bit)) {
...@@ -119,10 +118,10 @@ static irqreturn_t i2s_irq_handler(int irq, void *data) ...@@ -119,10 +118,10 @@ static irqreturn_t i2s_irq_handler(int irq, void *data)
(rsrc->irqp_used - 1))); (rsrc->irqp_used - 1)));
snd_pcm_period_elapsed(stream->substream); snd_pcm_period_elapsed(stream->substream);
i2s_flag = 1; i2s_flag = 1;
break;
} }
} }
} }
spin_unlock(&adata->acp_lock);
if (i2s_flag) if (i2s_flag)
return IRQ_HANDLED; return IRQ_HANDLED;
...@@ -146,9 +145,8 @@ static void config_pte_for_stream(struct acp_dev_data *adata, struct acp_stream ...@@ -146,9 +145,8 @@ static void config_pte_for_stream(struct acp_dev_data *adata, struct acp_stream
writel(0x01, adata->acp_base + ACPAXI2AXI_ATU_CTRL); writel(0x01, adata->acp_base + ACPAXI2AXI_ATU_CTRL);
} }
static void config_acp_dma(struct acp_dev_data *adata, int cpu_id, int size) static void config_acp_dma(struct acp_dev_data *adata, struct acp_stream *stream, int size)
{ {
struct acp_stream *stream = adata->stream[cpu_id];
struct snd_pcm_substream *substream = stream->substream; struct snd_pcm_substream *substream = stream->substream;
struct acp_resource *rsrc = adata->rsrc; struct acp_resource *rsrc = adata->rsrc;
dma_addr_t addr = substream->dma_buffer.addr; dma_addr_t addr = substream->dma_buffer.addr;
...@@ -174,13 +172,10 @@ static void config_acp_dma(struct acp_dev_data *adata, int cpu_id, int size) ...@@ -174,13 +172,10 @@ static void config_acp_dma(struct acp_dev_data *adata, int cpu_id, int size)
static int acp_dma_open(struct snd_soc_component *component, struct snd_pcm_substream *substream) static int acp_dma_open(struct snd_soc_component *component, struct snd_pcm_substream *substream)
{ {
struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0);
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
struct device *dev = component->dev; struct device *dev = component->dev;
struct acp_dev_data *adata = dev_get_drvdata(dev); struct acp_dev_data *adata = dev_get_drvdata(dev);
struct acp_stream *stream; struct acp_stream *stream;
int stream_id = cpu_dai->driver->id * 2 + substream->stream;
int ret; int ret;
stream = kzalloc(sizeof(*stream), GFP_KERNEL); stream = kzalloc(sizeof(*stream), GFP_KERNEL);
...@@ -188,7 +183,10 @@ static int acp_dma_open(struct snd_soc_component *component, struct snd_pcm_subs ...@@ -188,7 +183,10 @@ static int acp_dma_open(struct snd_soc_component *component, struct snd_pcm_subs
return -ENOMEM; return -ENOMEM;
stream->substream = substream; stream->substream = substream;
adata->stream[stream_id] = stream;
spin_lock_irq(&adata->acp_lock);
list_add_tail(&stream->list, &adata->stream_list);
spin_unlock_irq(&adata->acp_lock);
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
runtime->hw = acp_pcm_hardware_playback; runtime->hw = acp_pcm_hardware_playback;
...@@ -212,16 +210,13 @@ static int acp_dma_hw_params(struct snd_soc_component *component, ...@@ -212,16 +210,13 @@ static int acp_dma_hw_params(struct snd_soc_component *component,
struct snd_pcm_substream *substream, struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params) struct snd_pcm_hw_params *params)
{ {
struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
struct acp_dev_data *adata = snd_soc_component_get_drvdata(component); struct acp_dev_data *adata = snd_soc_component_get_drvdata(component);
struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0);
struct acp_stream *stream = substream->runtime->private_data; struct acp_stream *stream = substream->runtime->private_data;
int stream_id = cpu_dai->driver->id * 2 + substream->stream;
u64 size = params_buffer_bytes(params); u64 size = params_buffer_bytes(params);
/* Configure ACP DMA block with params */ /* Configure ACP DMA block with params */
config_pte_for_stream(adata, stream); config_pte_for_stream(adata, stream);
config_acp_dma(adata, stream_id, size); config_acp_dma(adata, stream, size);
return 0; return 0;
} }
...@@ -261,16 +256,15 @@ static int acp_dma_new(struct snd_soc_component *component, ...@@ -261,16 +256,15 @@ static int acp_dma_new(struct snd_soc_component *component,
static int acp_dma_close(struct snd_soc_component *component, static int acp_dma_close(struct snd_soc_component *component,
struct snd_pcm_substream *substream) struct snd_pcm_substream *substream)
{ {
struct snd_soc_pcm_runtime *soc_runtime = asoc_substream_to_rtd(substream);
struct snd_soc_dai *cpu_dai = asoc_rtd_to_cpu(soc_runtime, 0);
struct device *dev = component->dev; struct device *dev = component->dev;
struct acp_dev_data *adata = dev_get_drvdata(dev); struct acp_dev_data *adata = dev_get_drvdata(dev);
struct acp_stream *stream; struct acp_stream *stream = substream->runtime->private_data;
int stream_id = cpu_dai->driver->id * 2 + substream->stream;
stream = adata->stream[stream_id]; /* Remove entry from list */
spin_lock_irq(&adata->acp_lock);
list_del(&stream->list);
spin_unlock_irq(&adata->acp_lock);
kfree(stream); kfree(stream);
adata->stream[stream_id] = NULL;
return 0; return 0;
} }
...@@ -305,6 +299,10 @@ int acp_platform_register(struct device *dev) ...@@ -305,6 +299,10 @@ int acp_platform_register(struct device *dev)
dev_err(dev, "Fail to register acp i2s component\n"); dev_err(dev, "Fail to register acp i2s component\n");
return status; return status;
} }
INIT_LIST_HEAD(&adata->stream_list);
spin_lock_init(&adata->acp_lock);
return 0; return 0;
} }
EXPORT_SYMBOL_NS_GPL(acp_platform_register, SND_SOC_ACP_COMMON); EXPORT_SYMBOL_NS_GPL(acp_platform_register, SND_SOC_ACP_COMMON);
......
...@@ -91,6 +91,7 @@ struct acp_chip_info { ...@@ -91,6 +91,7 @@ struct acp_chip_info {
}; };
struct acp_stream { struct acp_stream {
struct list_head list;
struct snd_pcm_substream *substream; struct snd_pcm_substream *substream;
int irq_bit; int irq_bit;
int dai_id; int dai_id;
...@@ -123,7 +124,8 @@ struct acp_dev_data { ...@@ -123,7 +124,8 @@ struct acp_dev_data {
struct snd_soc_dai_driver *dai_driver; struct snd_soc_dai_driver *dai_driver;
int num_dai; int num_dai;
struct acp_stream *stream[ACP_MAX_STREAM]; struct list_head stream_list;
spinlock_t acp_lock;
struct snd_soc_acpi_mach *machines; struct snd_soc_acpi_mach *machines;
struct platform_device *mach_dev; struct platform_device *mach_dev;
......
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