diff mbox

[RFC,01/15] ASoC: qcom: use snd_dma_alloc/free* apis

Message ID 1454347680-10307-1-git-send-email-srinivas.kandagatla@linaro.org (mailing list archive)
State RFC
Delegated to: Andy Gross
Headers show

Commit Message

Srinivas Kandagatla Feb. 1, 2016, 5:27 p.m. UTC
There is no point in having local allocation functions when the driver
can use snd_dma_alloc/free() apis. This patch replaces the local versions
of the dma allocation apis with the snd_dma_alloc/free() apis.

Signed-off-by: Srinivas Kandagatla <srinivas.kandagatla@linaro.org>
---
 sound/soc/qcom/lpass-platform.c | 41 +++++------------------------------------
 1 file changed, 5 insertions(+), 36 deletions(-)

Comments

Kenneth Westfield Feb. 3, 2016, 12:35 a.m. UTC | #1
On Mon, Feb 01, 2016 at 09:27:59AM -0800, Srinivas Kandagatla wrote:
> diff --git a/sound/soc/qcom/lpass-platform.c
> b/sound/soc/qcom/lpass-platform.c
> index 4aeb8e1..a6dce1b 100644
> --- a/sound/soc/qcom/lpass-platform.c
> +++ b/sound/soc/qcom/lpass-platform.c
> @@ -439,39 +439,6 @@ static irqreturn_t lpass_platform_lpaif_irq(int irq,
> void *data)
>  	return IRQ_HANDLED;
>  }
>  
> -static int lpass_platform_alloc_buffer(struct snd_pcm_substream
> *substream,
> -		struct snd_soc_pcm_runtime *rt)
> -{
> -	struct snd_dma_buffer *buf = &substream->dma_buffer;
> -	size_t size = lpass_platform_pcm_hardware.buffer_bytes_max;
> -
> -	buf->dev.type = SNDRV_DMA_TYPE_DEV;
> -	buf->dev.dev = rt->platform->dev;
> -	buf->private_data = NULL;
> -	buf->area = dma_alloc_coherent(rt->platform->dev, size,
> &buf->addr,
> -			GFP_KERNEL);
> -	if (!buf->area) {
> -		dev_err(rt->platform->dev, "%s: Could not allocate DMA
> buffer\n",
> -				__func__);
> -		return -ENOMEM;
> -	}

...

> @@ -499,7 +467,8 @@ static int lpass_platform_pcm_new(struct
> snd_soc_pcm_runtime *soc_runtime)
>  
>  	snd_soc_pcm_set_drvdata(soc_runtime, data);
>  
> -	ret = lpass_platform_alloc_buffer(substream, soc_runtime);
> +	ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, pcm->card->dev,
> +				size, &substream->dma_buffer);
>  	if (ret)
>  		return ret;
>  

Is there a particular reason for using the soundcard device (pcm-card->dev)
rather than the platform device (rt->platform->dev) for memory
allocation?  Especially considering you posted a fix for this several
weeks ago (ASoC: qcom: use correct device pointer in dma allocation).
Srinivas Kandagatla Feb. 3, 2016, 8:48 a.m. UTC | #2
On 03/02/16 00:35, Kenneth Westfield wrote:
> On Mon, Feb 01, 2016 at 09:27:59AM -0800, Srinivas Kandagatla wrote:
>> diff --git a/sound/soc/qcom/lpass-platform.c
>> b/sound/soc/qcom/lpass-platform.c
>> index 4aeb8e1..a6dce1b 100644
>> --- a/sound/soc/qcom/lpass-platform.c
>> +++ b/sound/soc/qcom/lpass-platform.c
>> @@ -439,39 +439,6 @@ static irqreturn_t lpass_platform_lpaif_irq(int irq,
>> void *data)
>>   	return IRQ_HANDLED;
>>   }
>>
>> -static int lpass_platform_alloc_buffer(struct snd_pcm_substream
>> *substream,
>> -		struct snd_soc_pcm_runtime *rt)
>> -{
>> -	struct snd_dma_buffer *buf = &substream->dma_buffer;
>> -	size_t size = lpass_platform_pcm_hardware.buffer_bytes_max;
>> -
>> -	buf->dev.type = SNDRV_DMA_TYPE_DEV;
>> -	buf->dev.dev = rt->platform->dev;
>> -	buf->private_data = NULL;
>> -	buf->area = dma_alloc_coherent(rt->platform->dev, size,
>> &buf->addr,
>> -			GFP_KERNEL);
>> -	if (!buf->area) {
>> -		dev_err(rt->platform->dev, "%s: Could not allocate DMA
>> buffer\n",
>> -				__func__);
>> -		return -ENOMEM;
>> -	}
>
> ...
>
>> @@ -499,7 +467,8 @@ static int lpass_platform_pcm_new(struct
>> snd_soc_pcm_runtime *soc_runtime)
>>
>>   	snd_soc_pcm_set_drvdata(soc_runtime, data);
>>
>> -	ret = lpass_platform_alloc_buffer(substream, soc_runtime);
>> +	ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, pcm->card->dev,
>> +				size, &substream->dma_buffer);
>>   	if (ret)
>>   		return ret;
>>
>
> Is there a particular reason for using the soundcard device (pcm-card->dev)
> rather than the platform device (rt->platform->dev) for memory
> allocation?  Especially considering you posted a fix for this several
> weeks ago (ASoC: qcom: use correct device pointer in dma allocation).

Thanks for spotting this, I will fix it and resend it with platform->dev.

>
--
To unsubscribe from this list: send the line "unsubscribe linux-arm-msm" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
diff mbox

Patch

diff --git a/sound/soc/qcom/lpass-platform.c b/sound/soc/qcom/lpass-platform.c
index 4aeb8e1..a6dce1b 100644
--- a/sound/soc/qcom/lpass-platform.c
+++ b/sound/soc/qcom/lpass-platform.c
@@ -439,39 +439,6 @@  static irqreturn_t lpass_platform_lpaif_irq(int irq, void *data)
 	return IRQ_HANDLED;
 }
 
-static int lpass_platform_alloc_buffer(struct snd_pcm_substream *substream,
-		struct snd_soc_pcm_runtime *rt)
-{
-	struct snd_dma_buffer *buf = &substream->dma_buffer;
-	size_t size = lpass_platform_pcm_hardware.buffer_bytes_max;
-
-	buf->dev.type = SNDRV_DMA_TYPE_DEV;
-	buf->dev.dev = rt->platform->dev;
-	buf->private_data = NULL;
-	buf->area = dma_alloc_coherent(rt->platform->dev, size, &buf->addr,
-			GFP_KERNEL);
-	if (!buf->area) {
-		dev_err(rt->platform->dev, "%s: Could not allocate DMA buffer\n",
-				__func__);
-		return -ENOMEM;
-	}
-	buf->bytes = size;
-
-	return 0;
-}
-
-static void lpass_platform_free_buffer(struct snd_pcm_substream *substream,
-		struct snd_soc_pcm_runtime *rt)
-{
-	struct snd_dma_buffer *buf = &substream->dma_buffer;
-
-	if (buf->area) {
-		dma_free_coherent(rt->dev, buf->bytes, buf->area,
-				buf->addr);
-	}
-	buf->area = NULL;
-}
-
 static int lpass_platform_pcm_new(struct snd_soc_pcm_runtime *soc_runtime)
 {
 	struct snd_pcm *pcm = soc_runtime->pcm;
@@ -483,6 +450,7 @@  static int lpass_platform_pcm_new(struct snd_soc_pcm_runtime *soc_runtime)
 	struct lpass_variant *v = drvdata->variant;
 	int ret;
 	struct lpass_pcm_data *data;
+	size_t size = lpass_platform_pcm_hardware.buffer_bytes_max;
 
 	data = devm_kzalloc(soc_runtime->dev, sizeof(*data), GFP_KERNEL);
 	if (!data)
@@ -499,7 +467,8 @@  static int lpass_platform_pcm_new(struct snd_soc_pcm_runtime *soc_runtime)
 
 	snd_soc_pcm_set_drvdata(soc_runtime, data);
 
-	ret = lpass_platform_alloc_buffer(substream, soc_runtime);
+	ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, pcm->card->dev,
+				size, &substream->dma_buffer);
 	if (ret)
 		return ret;
 
@@ -514,7 +483,7 @@  static int lpass_platform_pcm_new(struct snd_soc_pcm_runtime *soc_runtime)
 	return 0;
 
 err_buf:
-	lpass_platform_free_buffer(substream, soc_runtime);
+	snd_dma_free_pages(&substream->dma_buffer);
 	return ret;
 }
 
@@ -533,7 +502,7 @@  static void lpass_platform_pcm_free(struct snd_pcm *pcm)
 	if (v->free_dma_channel)
 		v->free_dma_channel(drvdata, data->rdma_ch);
 
-	lpass_platform_free_buffer(substream, soc_runtime);
+	snd_dma_free_pages(&substream->dma_buffer);
 }
 
 static struct snd_soc_platform_driver lpass_platform_driver = {