From 8949490f70cf2cda615fb0fd0ddc299b531e6e48 Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Tue, 21 Feb 2012 17:47:57 +0100 Subject: ASoC: mxs-pcm: Remove unused fields from struct mxs_pcm_runtime_data Signed-off-by: Lars-Peter Clausen Signed-off-by: Mark Brown --- sound/soc/mxs/mxs-pcm.c | 5 ----- 1 file changed, 5 deletions(-) (limited to 'sound/soc/mxs/mxs-pcm.c') diff --git a/sound/soc/mxs/mxs-pcm.c b/sound/soc/mxs/mxs-pcm.c index 105f42a394df..06c18ecffbb4 100644 --- a/sound/soc/mxs/mxs-pcm.c +++ b/sound/soc/mxs/mxs-pcm.c @@ -119,19 +119,14 @@ static int snd_mxs_pcm_hw_params(struct snd_pcm_substream *substream, return ret; chan = iprtd->dma_chan; - iprtd->size = params_buffer_bytes(params); iprtd->periods = params_periods(params); iprtd->period_bytes = params_period_bytes(params); iprtd->offset = 0; - iprtd->period_time = HZ / (params_rate(params) / - params_period_size(params)); snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer); dma_addr = runtime->dma_addr; - iprtd->buf = substream->dma_buffer.area; - iprtd->desc = chan->device->device_prep_dma_cyclic(chan, dma_addr, iprtd->period_bytes * iprtd->periods, iprtd->period_bytes, -- cgit v1.2.3 From 95a771ca16ad63cfd665bebadbc543857db6fa4e Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 22 Feb 2012 10:49:07 +0100 Subject: ASoC: mxs-pcm: Request DMA channel early Request the DMA channel in the PCM open callback instead of the hwparams callback, this allows us to let open fail if no dma channel is available. This also fixes a bug where the channel will be requested multiple times if hwparams is called multiple times. Signed-off-by: Lars-Peter Clausen Tested-by: Shawn Guo Signed-off-by: Mark Brown --- sound/soc/mxs/mxs-pcm.c | 28 ++++++++-------------------- 1 file changed, 8 insertions(+), 20 deletions(-) (limited to 'sound/soc/mxs/mxs-pcm.c') diff --git a/sound/soc/mxs/mxs-pcm.c b/sound/soc/mxs/mxs-pcm.c index 06c18ecffbb4..5b8c8d314060 100644 --- a/sound/soc/mxs/mxs-pcm.c +++ b/sound/soc/mxs/mxs-pcm.c @@ -85,8 +85,7 @@ static bool filter(struct dma_chan *chan, void *param) return true; } -static int mxs_dma_alloc(struct snd_pcm_substream *substream, - struct snd_pcm_hw_params *params) +static int mxs_dma_alloc(struct snd_pcm_substream *substream) { struct snd_soc_pcm_runtime *rtd = substream->private_data; struct snd_pcm_runtime *runtime = substream->runtime; @@ -112,11 +111,7 @@ static int snd_mxs_pcm_hw_params(struct snd_pcm_substream *substream, struct mxs_pcm_runtime_data *iprtd = runtime->private_data; unsigned long dma_addr; struct dma_chan *chan; - int ret; - ret = mxs_dma_alloc(substream, params); - if (ret) - return ret; chan = iprtd->dma_chan; iprtd->periods = params_periods(params); @@ -143,19 +138,6 @@ static int snd_mxs_pcm_hw_params(struct snd_pcm_substream *substream, return 0; } -static int snd_mxs_pcm_hw_free(struct snd_pcm_substream *substream) -{ - struct snd_pcm_runtime *runtime = substream->runtime; - struct mxs_pcm_runtime_data *iprtd = runtime->private_data; - - if (iprtd->dma_chan) { - dma_release_channel(iprtd->dma_chan); - iprtd->dma_chan = NULL; - } - - return 0; -} - static int snd_mxs_pcm_trigger(struct snd_pcm_substream *substream, int cmd) { struct snd_pcm_runtime *runtime = substream->runtime; @@ -208,6 +190,12 @@ static int snd_mxs_open(struct snd_pcm_substream *substream) return ret; } + ret = mxs_dma_alloc(substream); + if (ret) { + kfree(iprtd); + return ret; + } + snd_soc_set_runtime_hwparams(substream, &snd_mxs_hardware); return 0; @@ -218,6 +206,7 @@ static int snd_mxs_close(struct snd_pcm_substream *substream) struct snd_pcm_runtime *runtime = substream->runtime; struct mxs_pcm_runtime_data *iprtd = runtime->private_data; + dma_release_channel(iprtd->dma_chan); kfree(iprtd); return 0; @@ -239,7 +228,6 @@ static struct snd_pcm_ops mxs_pcm_ops = { .close = snd_mxs_close, .ioctl = snd_pcm_lib_ioctl, .hw_params = snd_mxs_pcm_hw_params, - .hw_free = snd_mxs_pcm_hw_free, .trigger = snd_mxs_pcm_trigger, .pointer = snd_mxs_pcm_pointer, .mmap = snd_mxs_pcm_mmap, -- cgit v1.2.3 From 016ab467aa53639d68b03386885c481b8761018e Mon Sep 17 00:00:00 2001 From: Lars-Peter Clausen Date: Wed, 22 Feb 2012 10:49:10 +0100 Subject: ASoC: mxs-pcm: Use dmaengine PCM helper functions Signed-off-by: Lars-Peter Clausen Tested-by: Shawn Guo Acked-by: Vinod Koul Signed-off-by: Mark Brown --- sound/soc/mxs/mxs-pcm.c | 136 +++++++++--------------------------------------- 1 file changed, 24 insertions(+), 112 deletions(-) (limited to 'sound/soc/mxs/mxs-pcm.c') diff --git a/sound/soc/mxs/mxs-pcm.c b/sound/soc/mxs/mxs-pcm.c index 5b8c8d314060..6ca1f46d84a4 100644 --- a/sound/soc/mxs/mxs-pcm.c +++ b/sound/soc/mxs/mxs-pcm.c @@ -34,10 +34,16 @@ #include #include #include +#include #include #include "mxs-pcm.h" +struct mxs_pcm_dma_data { + struct mxs_dma_data dma_data; + struct mxs_pcm_dma_params *dma_params; +}; + static struct snd_pcm_hardware snd_mxs_hardware = { .info = SNDRV_PCM_INFO_MMAP | SNDRV_PCM_INFO_MMAP_VALID | @@ -58,21 +64,10 @@ static struct snd_pcm_hardware snd_mxs_hardware = { }; -static void audio_dma_irq(void *data) -{ - struct snd_pcm_substream *substream = (struct snd_pcm_substream *)data; - struct snd_pcm_runtime *runtime = substream->runtime; - struct mxs_pcm_runtime_data *iprtd = runtime->private_data; - - iprtd->offset += iprtd->period_bytes; - iprtd->offset %= iprtd->period_bytes * iprtd->periods; - snd_pcm_period_elapsed(substream); -} - static bool filter(struct dma_chan *chan, void *param) { - struct mxs_pcm_runtime_data *iprtd = param; - struct mxs_pcm_dma_params *dma_params = iprtd->dma_params; + struct mxs_pcm_dma_data *pcm_dma_data = param; + struct mxs_pcm_dma_params *dma_params = pcm_dma_data->dma_params; if (!mxs_dma_is_apbx(chan)) return false; @@ -80,134 +75,51 @@ static bool filter(struct dma_chan *chan, void *param) if (chan->chan_id != dma_params->chan_num) return false; - chan->private = &iprtd->dma_data; + chan->private = &pcm_dma_data->dma_data; return true; } -static int mxs_dma_alloc(struct snd_pcm_substream *substream) -{ - struct snd_soc_pcm_runtime *rtd = substream->private_data; - struct snd_pcm_runtime *runtime = substream->runtime; - struct mxs_pcm_runtime_data *iprtd = runtime->private_data; - dma_cap_mask_t mask; - - iprtd->dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); - - dma_cap_zero(mask); - dma_cap_set(DMA_SLAVE, mask); - iprtd->dma_data.chan_irq = iprtd->dma_params->chan_irq; - iprtd->dma_chan = dma_request_channel(mask, filter, iprtd); - if (!iprtd->dma_chan) - return -EINVAL; - - return 0; -} - static int snd_mxs_pcm_hw_params(struct snd_pcm_substream *substream, struct snd_pcm_hw_params *params) { - struct snd_pcm_runtime *runtime = substream->runtime; - struct mxs_pcm_runtime_data *iprtd = runtime->private_data; - unsigned long dma_addr; - struct dma_chan *chan; - - chan = iprtd->dma_chan; - - iprtd->periods = params_periods(params); - iprtd->period_bytes = params_period_bytes(params); - iprtd->offset = 0; - snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer); - dma_addr = runtime->dma_addr; - - iprtd->desc = chan->device->device_prep_dma_cyclic(chan, dma_addr, - iprtd->period_bytes * iprtd->periods, - iprtd->period_bytes, - substream->stream == SNDRV_PCM_STREAM_PLAYBACK ? - DMA_MEM_TO_DEV : DMA_DEV_TO_MEM); - if (!iprtd->desc) { - dev_err(&chan->dev->device, "cannot prepare slave dma\n"); - return -EINVAL; - } - - iprtd->desc->callback = audio_dma_irq; - iprtd->desc->callback_param = substream; - return 0; } -static int snd_mxs_pcm_trigger(struct snd_pcm_substream *substream, int cmd) -{ - struct snd_pcm_runtime *runtime = substream->runtime; - struct mxs_pcm_runtime_data *iprtd = runtime->private_data; - - switch (cmd) { - case SNDRV_PCM_TRIGGER_START: - case SNDRV_PCM_TRIGGER_RESUME: - case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: - dmaengine_submit(iprtd->desc); - - break; - case SNDRV_PCM_TRIGGER_STOP: - case SNDRV_PCM_TRIGGER_SUSPEND: - case SNDRV_PCM_TRIGGER_PAUSE_PUSH: - dmaengine_terminate_all(iprtd->dma_chan); - - break; - default: - return -EINVAL; - } - - return 0; -} - -static snd_pcm_uframes_t snd_mxs_pcm_pointer( - struct snd_pcm_substream *substream) -{ - struct snd_pcm_runtime *runtime = substream->runtime; - struct mxs_pcm_runtime_data *iprtd = runtime->private_data; - - return bytes_to_frames(substream->runtime, iprtd->offset); -} - static int snd_mxs_open(struct snd_pcm_substream *substream) { - struct snd_pcm_runtime *runtime = substream->runtime; - struct mxs_pcm_runtime_data *iprtd; + struct snd_soc_pcm_runtime *rtd = substream->private_data; + struct mxs_pcm_dma_data *pcm_dma_data; int ret; - iprtd = kzalloc(sizeof(*iprtd), GFP_KERNEL); - if (iprtd == NULL) + pcm_dma_data = kzalloc(sizeof(*pcm_dma_data), GFP_KERNEL); + if (pcm_dma_data == NULL) return -ENOMEM; - runtime->private_data = iprtd; - ret = snd_pcm_hw_constraint_integer(substream->runtime, - SNDRV_PCM_HW_PARAM_PERIODS); - if (ret < 0) { - kfree(iprtd); - return ret; - } + pcm_dma_data->dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream); + pcm_dma_data->dma_data.chan_irq = pcm_dma_data->dma_params->chan_irq; - ret = mxs_dma_alloc(substream); + ret = snd_dmaengine_pcm_open(substream, filter, pcm_dma_data); if (ret) { - kfree(iprtd); + kfree(pcm_dma_data); return ret; } snd_soc_set_runtime_hwparams(substream, &snd_mxs_hardware); + snd_dmaengine_pcm_set_data(substream, pcm_dma_data); + return 0; } static int snd_mxs_close(struct snd_pcm_substream *substream) { - struct snd_pcm_runtime *runtime = substream->runtime; - struct mxs_pcm_runtime_data *iprtd = runtime->private_data; + struct mxs_pcm_dma_data *pcm_dma_data = snd_dmaengine_pcm_get_data(substream); - dma_release_channel(iprtd->dma_chan); - kfree(iprtd); + snd_dmaengine_pcm_close(substream); + kfree(pcm_dma_data); return 0; } @@ -228,8 +140,8 @@ static struct snd_pcm_ops mxs_pcm_ops = { .close = snd_mxs_close, .ioctl = snd_pcm_lib_ioctl, .hw_params = snd_mxs_pcm_hw_params, - .trigger = snd_mxs_pcm_trigger, - .pointer = snd_mxs_pcm_pointer, + .trigger = snd_dmaengine_pcm_trigger, + .pointer = snd_dmaengine_pcm_pointer, .mmap = snd_mxs_pcm_mmap, }; -- cgit v1.2.3