ASoC: Introduce dmaengine pcm helper functions
Subsystems (4)
Lars-Peter Clausen
maintainercover ASoC: Introduce dmaengine pcm helper functions
Same series as send out yesterday (sans the cleanup patches which already have been applied), since I forgot to Cc alsa-devel. Sorry for the noice if you got the series twice.
This patch series introduces a new set of helper functions for dmaengine based PCM drivers. Currently we have 6 different dmaengine based PCM drivers which are all more or less similar in structure, but all have also individual requirements which can't easily be generalized. So that's why this series does not introduce a generic dmaengine PCM driver but rather a set of helper functions which can be used to implement the common bits between such dmaengine based PCM drivers.
The helper functions only provide infrastructure code for dmaengines which provide thed evice_prep_dma_cyclic. While it is possible to add support for dmaengine, which only provide device_prep_slave_sg, it is in my opinion a better idea to either implement the missing functionality in the dmaengine driver or provide a emulation layer for cyclic transfer within the dmaengine framework itself. This has the advantage that it is also available outside of ALSA.
This series converts the three PCM drivers which already use the circular dmaengine prepare function. Since I don't have access to hardware using the converted drivers the patches have only been compile tested. But the helper functions introduced in this series have been runtime tested with a platform which is not upstream yet.
The first two patches restructure the iMX and MXS drivers to request their DMA channel in the PCM open callback instead of the hwparams callback. This is done to make their structure more similar to what it will be when using the helper functions and make the actual patch converting them to the new dmaengine PCM helper functions less intrusive. The next patch introduces the helper functions and the last three patches respectively convert the imx, mxs and ep39xx dmaengine based PCM drivers to use the new set of helper functions.
The set of helper functions consists of a open, a close, a trigger and a pointer callback and also a function to convert hwparams to a dma_slave_config. The trigger and pointer callbacks can usually be used directly for the pcm_ops callbacks. The open callback wants to be called from a driver specific open function which may do some driver specific setup tasks and provide the helper open callback with a dma filter function. If the driver specific open functions allocates resources they need to be freed in a driver specific close function which has to call the helper close callback. If not the helper close callback can be assigned directly to the pcm_ops struct.
If a driver needs to keep additional driver specific data around it can be done by using snd_dmaengine_pcm_{get,set}_data. Normally a driver should not require to keep additional data around, but all of the converted drivers need this, because of this horrible abusive pattern where the dma channels private field gets assigned configuration data in the filter callback. We should hopefully be able to get rid of this pattern with Guennadi Liakhovetski's patches[1], which add a slave configuration parameter to dma_request_channel, and with it the need for storing extra private data.
While the DMA helper functions only use generic ALSA functions and nothing ASoC specific I've placed the, under ASoC for now since the only users are ASoC driver.
- Lars
[1] https://lkml.org/lkml/2012/2/1/227
Lars-Peter Clausen (7):
ASoC: imx-ssi: Set dma data early
ASoC: imx-pcm: Request DMA channel early
ASoC: mxs-pcm: Request DMA channel early
ASoC: Add dmaengine PCM helper functions
ASoC: imx-pcm-dma: Use dmaengine PCM helper functions
ASoC: mxs-pcm: Use dmaengine PCM helper functions
ASoC: ep93xx-pcm: Use dmaengine PCM helper functions
include/sound/dmaengine_pcm.h | 49 +++++++ sound/soc/Kconfig | 3 + sound/soc/Makefile | 3 + sound/soc/ep93xx/Kconfig | 1 + sound/soc/ep93xx/ep93xx-pcm.c | 148 +++----------------- sound/soc/imx/Kconfig | 1 + sound/soc/imx/imx-pcm-dma-mx2.c | 196 ++++---------------------- sound/soc/imx/imx-ssi.c | 28 +++- sound/soc/mxs/Kconfig | 1 + sound/soc/mxs/mxs-pcm.c | 152 ++++----------------- sound/soc/mxs/mxs-pcm.h | 12 -- sound/soc/soc-dmaengine-pcm.c | 287 +++++++++++++++++++++++++++++++++++++++ 12 files changed, 443 insertions(+), 438 deletions(-) create mode 100644 include/sound/dmaengine_pcm.h create mode 100644 sound/soc/soc-dmaengine-pcm.c
Signature · 1 line
1.7.9
Lars-Peter Clausen
maintainerRFC 1/7 ASoC: imx-ssi: Set dma data early
Move the call to snd_soc_dai_set_dma_data from the hw_params callback to the startup callback. This allows us to use the dma data in the pcm driver's open callback.
--- sound/soc/imx/imx-ssi.c | 28 ++++++++++++++++++++-------- 1 files changed, 20 insertions(+), 8 deletions(-)
sound/soc/imx/imx-ssi.c +20 -8
@@ -233,6 +233,23 @@ static int imx_ssi_set_dai_clkdiv(struct snd_soc_dai *cpu_dai,return 0 ; } +static int imx_ssi_startup (struct snd_pcm_substream *substream, +struct snd_soc_dai *cpu_dai) +{ +struct imx_ssi *ssi =snd_soc_dai_get_drvdata (cpu_dai); +struct imx_pcm_dma_params *dma_data; + +/* Tx/Rx config */ +if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) + dma_data = &ssi->dma_params_tx; +else + dma_data = &ssi->dma_params_rx; + +snd_soc_dai_set_dma_data (cpu_dai, substream, dma_data); + +return 0 ; +} +/* * Should only be called when port is inactive (i.e. SSIEN = 0), * although can be called multiple times by upper layers.
@@ -242,23 +259,17 @@ static int imx_ssi_hw_params(struct snd_pcm_substream *substream, struct snd_soc_dai *cpu_dai) {struct imx_ssi *ssi =snd_soc_dai_get_drvdata (cpu_dai); -struct imx_pcm_dma_params *dma_data;u32 reg, sccr;/* Tx/Rx config */ -if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) { +if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) reg =SSI_STCCR ; - dma_data = &ssi->dma_params_tx; - }else { +else reg =SSI_SRCCR ; - dma_data = &ssi->dma_params_rx; - }if (ssi->flags &IMX_SSI_SYN ) reg =SSI_STCCR ; -snd_soc_dai_set_dma_data (cpu_dai, substream, dma_data); - sccr =readl (ssi->base + reg) & ~SSI_STCCR_WL_MASK ;/* DAI data (word) size */
@@ -343,6 +354,7 @@ static int imx_ssi_trigger(struct snd_pcm_substream *substream, int cmd, }static const struct snd_soc_dai_ops imx_ssi_pcm_dai_ops = { + .startup = imx_ssi_startup, .hw_params = imx_ssi_hw_params, .set_fmt = imx_ssi_set_dai_fmt, .set_clkdiv = imx_ssi_set_dai_clkdiv,
Signature · 1 line
1.7.9
Mark Brown
AppliedRe: [RFC 1/7] ASoC: imx-ssi: Set dma data early
Quoted 3 lines · Lars-Peter Clausen
Move the call to
snd_soc_dai_set_dma_datafrom thehw_paramscallback to the startup callback. This allows us to use the dma data in the pcm driver's open callback.
Applied, thanks.
Lars-Peter Clausen
maintainerRFC 2/7 ASoC: imx-pcm: Request DMA channel early
In reply to Lars-Peter ClausenRequest the DMA channel in the pcm open callback. This allows us to let open fail if there is no dma channel available.
--- sound/soc/imx/imx-pcm-dma-mx2.c | 78 ++++++++++++++++----------------------- 1 files changed, 32 insertions(+), 46 deletions(-)
sound/soc/imx/imx-pcm-dma-mx2.c +32 -46
@@ -65,17 +65,13 @@ static bool filter(struct dma_chan *chan, void *param)return true; } -static int imx_ssi_dma_alloc (struct snd_pcm_substream *substream, -struct snd_pcm_hw_params *params) +static int imx_ssi_dma_alloc (struct snd_pcm_substream *substream) {struct snd_soc_pcm_runtime *rtd = substream->private_data;struct imx_pcm_dma_params *dma_params;struct snd_pcm_runtime *runtime = substream->runtime;struct imx_pcm_runtime_data *iprtd = runtime->private_data; -struct dma_slave_config slave_config;dma_cap_mask_t mask; -enum dma_slave_buswidth buswidth; -int ret; dma_params =snd_soc_dai_get_dma_data (rtd->cpu_dai, substream);
@@ -84,13 +80,29 @@ static int imx_ssi_dma_alloc(struct snd_pcm_substream *substream, iprtd->dma_data.dma_request = dma_params->dma;/* Try to grab a DMA channel */ -if (!iprtd->dma_chan) { -dma_cap_zero (mask); -dma_cap_set (DMA_SLAVE , mask); - iprtd->dma_chan =dma_request_channel (mask, filter, iprtd); -if (!iprtd->dma_chan) -return -EINVAL ; - } +dma_cap_zero (mask); +dma_cap_set (DMA_SLAVE , mask); + iprtd->dma_chan =dma_request_channel (mask, filter, iprtd); +if (!iprtd->dma_chan) +return -EINVAL ; + +return 0 ; +} + +static int snd_imx_pcm_hw_params (struct snd_pcm_substream *substream, +struct snd_pcm_hw_params *params) +{ +struct snd_soc_pcm_runtime *rtd = substream->private_data; +struct snd_pcm_runtime *runtime = substream->runtime; +struct imx_pcm_runtime_data *iprtd = runtime->private_data; +struct dma_chan *chan = iprtd->dma_chan; +struct imx_pcm_dma_params *dma_params; +struct dma_slave_config slave_config; +enum dma_slave_buswidth buswidth; +unsigned long dma_addr; +int ret; + + dma_params =snd_soc_dai_get_dma_data (rtd->cpu_dai, substream);switch (params_format (params)) {case SNDRV_PCM_FORMAT_S16_LE :
@@ -116,29 +128,10 @@ static int imx_ssi_dma_alloc(struct snd_pcm_substream *substream, slave_config.src_maxburst = dma_params->burstsize; } - ret =dmaengine_slave_config (iprtd->dma_chan, &slave_config); + ret =dmaengine_slave_config (chan, &slave_config);if (ret)return ret; -return 0 ; -} - -static int snd_imx_pcm_hw_params (struct snd_pcm_substream *substream, -struct snd_pcm_hw_params *params) -{ -struct snd_soc_pcm_runtime *rtd = substream->private_data; -struct snd_pcm_runtime *runtime = substream->runtime; -struct imx_pcm_runtime_data *iprtd = runtime->private_data; -unsigned long dma_addr; -struct dma_chan *chan; -struct imx_pcm_dma_params *dma_params; -int ret; - - dma_params =snd_soc_dai_get_dma_data (rtd->cpu_dai, substream); - ret =imx_ssi_dma_alloc (substream, params); -if (ret) -return ret; - chan = iprtd->dma_chan; iprtd->periods =params_periods (params); iprtd->period_bytes =params_period_bytes (params);
@@ -164,19 +157,6 @@ static int snd_imx_pcm_hw_params(struct snd_pcm_substream *substream,return 0 ; } -static int snd_imx_pcm_hw_free (struct snd_pcm_substream *substream) -{ -struct snd_pcm_runtime *runtime = substream->runtime; -struct imx_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_imx_pcm_trigger (struct snd_pcm_substream *substream,int cmd) {struct snd_pcm_runtime *runtime = substream->runtime;
@@ -251,6 +231,12 @@ static int snd_imx_open(struct snd_pcm_substream *substream)return ret; } + ret =imx_ssi_dma_alloc (substream); +if (ret <0 ) { +kfree (iprtd); +return ret; + } +snd_soc_set_runtime_hwparams (substream, &snd_imx_hardware);return 0 ;
@@ -261,6 +247,7 @@ static int snd_imx_close(struct snd_pcm_substream *substream)struct snd_pcm_runtime *runtime = substream->runtime;struct imx_pcm_runtime_data *iprtd = runtime->private_data; +dma_release_channel (iprtd->dma_chan);kfree (iprtd);return 0 ;
@@ -271,7 +258,6 @@ static struct snd_pcm_ops imx_pcm_ops = { .close = snd_imx_close, .ioctl = snd_pcm_lib_ioctl, .hw_params = snd_imx_pcm_hw_params, - .hw_free = snd_imx_pcm_hw_free, .trigger = snd_imx_pcm_trigger, .pointer = snd_imx_pcm_pointer, .mmap = snd_imx_pcm_mmap,
Signature · 1 line
1.7.9
Mark Brown
AppliedRe: [RFC 2/7] ASoC: imx-pcm: Request DMA channel early
Quoted 2 lines · Lars-Peter Clausen
Request the DMA channel in the pcm open callback. This allows us to let open fail if there is no dma channel available.
Applied, thanks.
Lars-Peter Clausen
maintainerRFC 3/7 ASoC: mxs-pcm: Request DMA channel early
In reply to Lars-Peter ClausenRequest 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.
--- sound/soc/mxs/mxs-pcm.c | 28 ++++++++-------------------- 1 files changed, 8 insertions(+), 20 deletions(-)
sound/soc/mxs/mxs-pcm.c +8 -20
@@ -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,
Signature · 1 line
1.7.9
Mark Brown
AppliedRe: [RFC 3/7] ASoC: mxs-pcm: Request DMA channel early
Quoted 4 lines · Lars-Peter Clausen
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.
Applied, thanks.
Lars-Peter Clausen
maintainerRFC 4/7 ASoC: Add dmaengine PCM helper functions
In reply to Lars-Peter ClausenThis patch adds a set of functions which are intended to be used when implementing a dmaengine based sound PCM driver.
--- include/sound/dmaengine_pcm.h | 49 +++++++ sound/soc/Kconfig | 3 + sound/soc/Makefile | 3 + sound/soc/soc-dmaengine-pcm.c | 287 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 342 insertions(+), 0 deletions(-) create mode 100644 include/sound/dmaengine_pcm.h create mode 100644 sound/soc/soc-dmaengine-pcm.c
include/sound/dmaengine_pcm.h new file +49 -0
@@ -0,0 +1,49 @@ +/* +* Copyright (C) 2012, Analog Devices Inc. +* Author: Lars-Peter Clausen <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at your +* option) any later version. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 675 Mass Ave, Cambridge, MA 02139, USA. +* +*/ +#ifndef __SOUND_DMAENGINE_PCM_H__ +#define __SOUND_DMAENGINE_PCM_H__ + +#include <sound/pcm.h> +#include <linux/dmaengine.h> + +/** +* snd_pcm_substream_to_dma_direction - Get dma_transfer_direction for a PCM +* substream +* @substream: PCM substream +*/ +static inline enum dma_transfer_direction +snd_pcm_substream_to_dma_direction (const struct snd_pcm_substream *substream) +{ +if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) +return DMA_MEM_TO_DEV ; +else +return DMA_DEV_TO_MEM ; +} + +void snd_dmaengine_pcm_set_data (struct snd_pcm_substream *substream,void *data); +void *snd_dmaengine_pcm_get_data (struct snd_pcm_substream *substream); + +int snd_hwparams_to_dma_slave_config (const struct snd_pcm_substream *substream, +const struct snd_pcm_hw_params *params,struct dma_slave_config *slave_config); +int snd_dmaengine_pcm_trigger (struct snd_pcm_substream *substream,int cmd); +snd_pcm_uframes_t snd_dmaengine_pcm_pointer (struct snd_pcm_substream *substream); + +int snd_dmaengine_pcm_open (struct snd_pcm_substream *substream, +dma_filter_fn filter_fn,void *filter_data); +int snd_dmaengine_pcm_close (struct snd_pcm_substream *substream); + +struct dma_chan *snd_dmaengine_pcm_get_chan (struct snd_pcm_substream *substream); + +#endif
sound/soc/Kconfig +3 -0
@@ -25,6 +25,9 @@ if SND_SOC config SND_SOC_AC97_BUS bool +config SND_SOC_DMAENGINE_PCM + bool + # All the supported SoCs source "sound/soc/atmel/Kconfig" source "sound/soc/au1x/Kconfig"
sound/soc/Makefile +3 -0
@@ -1,6 +1,9 @@ snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-cache.o soc-utils.o snd-soc-core-objs += soc-pcm.o soc-io.o +snd-soc-dmaengine-pcm-objs := soc-dmaengine-pcm.o +obj-$(CONFIG_SND_SOC_DMAENGINE_PCM) += snd-soc-dmaengine-pcm.o + obj-$(CONFIG_SND_SOC) += snd-soc-core.o obj-$(CONFIG_SND_SOC) += codecs/ obj-$(CONFIG_SND_SOC) += atmel/
sound/soc/soc-dmaengine-pcm.c new file +287 -0
287 lines not on this page · raw message
Signature · 1 line
1.7.9
Re: [RFC 4/7] ASoC: Add dmaengine PCM helper functions
Quoted 2 lines · Lars-Peter Clausen
This patch adds a set of functions which are intended to be used when implementing a dmaengine based sound PCM driver.
This isn't going to be usable on sa11x0 platforms, because we need to know the struct device underlying the DMA device before we allocate the buffers.
Lars-Peter Clausen
maintainerRe: [RFC 4/7] ASoC: Add dmaengine PCM helper functions
Quoted 7 lines · Russell King - ARM Linux
Quoted 2 lines · Lars-Peter Clausen
This patch adds a set of functions which are intended to be used when implementing a dmaengine based sound PCM driver.
This isn't going to be usable on sa11x0 platforms, because we need to know the struct device underlying the DMA device before we allocate the buffers.
Which means the dma channel has to be requested before allocating the buffers. Which can be done. Not with the current code but it can be implemented on top of it.
I had a look at your 'generic' dmaengine PCM driver patch. And it looks like you went to opposite way as I did in this patch. You implemented one driver which is supposed to work for all cases, while my patch provides a set of helper functions which can be used to implement a PCM driver. Your patch only supports non-cyclic transfers, mine only supports cyclic transfers.
Your driver emulates cyclic transfers using non-cyclic transfers, in my opinion it is better to add such a emulation layer to the dmaengine core itself. This will allow other users to benefit from this as well and it doesn't have to be reimplemented in other subsystems/driver. Also users don't have to be updated if a dmaengine driver gets native support for cyclic transfers. But, well, the code exists and it is a step in the right direction so we should probably use it.
I suppose we could rearrange the code so that we can share most of it between the cyclic and non-cyclic case. The non-cyclic case needs special handling everywhere, which can be made conditional.
- Lars
Re: [RFC 4/7] ASoC: Add dmaengine PCM helper functions
In reply to Lars-Peter ClausenQuoted 2 lines · Lars-Peter Clausen
This patch adds a set of functions which are intended to be used when implementing a dmaengine based sound PCM driver.
Adding Morimoto-san as he has just implemented dmaengine support for fsi which should also be able to use the same framework. Not cutting any of the text so he can see it.
Quoted 391 lines
Signed-off-by Lars-Peter Clausen <[email protected]>Tested-by Shawn Guo <[email protected]>--- include/sound/dmaengine_pcm.h | 49 +++++++ sound/soc/Kconfig | 3 + sound/soc/Makefile | 3 + sound/soc/soc-dmaengine-pcm.c | 287 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 342 insertions(+), 0 deletions(-) create mode 100644 include/sound/dmaengine_pcm.h create mode 100644 sound/soc/soc-dmaengine-pcm.cinclude/sound/dmaengine_pcm.h new file +49
-0@@ -0,0 +1,49 @@ +/* +* Copyright (C) 2012, Analog Devices Inc. +* Author: Lars-Peter Clausen <[email protected]> +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at your +* option) any later version. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 675 Mass Ave, Cambridge, MA 02139, USA. +* +*/ +#ifndef __SOUND_DMAENGINE_PCM_H__ +#define __SOUND_DMAENGINE_PCM_H__ + +#include <sound/pcm.h> +#include <linux/dmaengine.h> + +/** +* snd_pcm_substream_to_dma_direction - Get dma_transfer_direction for a PCM +* substream +* @substream: PCM substream +*/ +static inline enum dma_transfer_direction +snd_pcm_substream_to_dma_direction (const struct snd_pcm_substream *substream) +{ +if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) +return DMA_MEM_TO_DEV ; +else +return DMA_DEV_TO_MEM ; +} + +void snd_dmaengine_pcm_set_data (struct snd_pcm_substream *substream,void *data); +void *snd_dmaengine_pcm_get_data (struct snd_pcm_substream *substream); + +int snd_hwparams_to_dma_slave_config (const struct snd_pcm_substream *substream, +const struct snd_pcm_hw_params *params,struct dma_slave_config *slave_config); +int snd_dmaengine_pcm_trigger (struct snd_pcm_substream *substream,int cmd); +snd_pcm_uframes_t snd_dmaengine_pcm_pointer (struct snd_pcm_substream *substream); + +int snd_dmaengine_pcm_open (struct snd_pcm_substream *substream, +dma_filter_fn filter_fn,void *filter_data); +int snd_dmaengine_pcm_close (struct snd_pcm_substream *substream); + +struct dma_chan *snd_dmaengine_pcm_get_chan (struct snd_pcm_substream *substream); + +#endif sound/soc/Kconfig +3
-0@@ -25,6 +25,9 @@ if SND_SOC config SND_SOC_AC97_BUS bool +config SND_SOC_DMAENGINE_PCM + bool + # All the supported SoCs source "sound/soc/atmel/Kconfig" source "sound/soc/au1x/Kconfig"sound/soc/Makefile +3
-0@@ -1,6 +1,9 @@ snd-soc-core-objs := soc-core.o soc-dapm.o soc-jack.o soc-cache.o soc-utils.o snd-soc-core-objs += soc-pcm.o soc-io.o +snd-soc-dmaengine-pcm-objs := soc-dmaengine-pcm.o +obj-$(CONFIG_SND_SOC_DMAENGINE_PCM) += snd-soc-dmaengine-pcm.o + obj-$(CONFIG_SND_SOC) += snd-soc-core.o obj-$(CONFIG_SND_SOC) += codecs/ obj-$(CONFIG_SND_SOC) += atmel/sound/soc/soc-dmaengine-pcm.c new file +287
-0@@ -0,0 +1,287 @@ +/* +* Copyright (C) 2012, Analog Devices Inc. +* Author: Lars-Peter Clausen <[email protected]> +* +* Based on: +* imx-pcm-dma-mx2.c, Copyright 2009 Sascha Hauer <[email protected]> +* mxs-pcm.c, Copyright (C) 2011 Freescale Semiconductor, Inc. +* ep93xx-pcm.c, Copyright (C) 2006 Lennert Buytenhek <[email protected]> +* Copyright (C) 2006 Applied Data Systems +* +* This program is free software; you can redistribute it and/or modify it +* under the terms of the GNU General Public License as published by the +* Free Software Foundation; either version 2 of the License, or (at your +* option) any later version. +* +* You should have received a copy of the GNU General Public License along +* with this program; if not, write to the Free Software Foundation, Inc., +* 675 Mass Ave, Cambridge, MA 02139, USA. +* +*/ +#include <linux/module.h> +#include <linux/init.h> +#include <linux/dmaengine.h> +#include <linux/slab.h> +#include <sound/pcm.h> +#include <sound/pcm_params.h> +#include <sound/soc.h> + +#include <sound/dmaengine_pcm.h> + +struct dmaengine_pcm_runtime_data { +struct dma_chan *dma_chan; + +unsigned int pos; + +void *data; +}; + +static inline struct dmaengine_pcm_runtime_data *substream_to_prtd ( +const struct snd_pcm_substream *substream) +{ +return substream->runtime->private_data; +} + +/** +* snd_dmaengine_pcm_set_data - Set dmaengine substream private data +* @substream: PCM substream +* @data: Data to set +*/ +void snd_dmaengine_pcm_set_data (struct snd_pcm_substream *substream,void *data) +{ +struct dmaengine_pcm_runtime_data *prtd =substream_to_prtd (substream); + + prtd->data = data; +} +EXPORT_SYMBOL_GPL (snd_dmaengine_pcm_set_data); + +/** +* snd_dmaengine_pcm_get_data - Get dmaeinge substream private data +* @substream: PCM substream +* +* Returns the data previously set with snd_dmaengine_pcm_set_data +*/ +void *snd_dmaengine_pcm_get_data (struct snd_pcm_substream *substream) +{ +struct dmaengine_pcm_runtime_data *prtd =substream_to_prtd (substream); + +return prtd->data; +} +EXPORT_SYMBOL_GPL (snd_dmaengine_pcm_get_data); + +struct dma_chan *snd_dmaengine_pcm_get_chan (struct snd_pcm_substream *substream) +{ +struct dmaengine_pcm_runtime_data *prtd =substream_to_prtd (substream); + +return prtd->dma_chan; +} +EXPORT_SYMBOL_GPL (snd_dmaengine_pcm_get_chan); + +/** +* snd_hwparams_to_dma_slave_config - Convert hw_params to dma_slave_config +* @substream: PCM substream +* @params: hw_params +* @slave_config: DMA slave config +* +* This function can be used to initialize a dma_slave_config from a substream +* and hw_params in a dmaengine based PCM driver implementation. +*/ +int snd_hwparams_to_dma_slave_config (const struct snd_pcm_substream *substream, +const struct snd_pcm_hw_params *params, +struct dma_slave_config *slave_config) +{ +enum dma_slave_buswidth buswidth; + +switch (params_format (params)) { +case SNDRV_PCM_FORMAT_S8 : + buswidth =DMA_SLAVE_BUSWIDTH_1_BYTE ; +break ; +case SNDRV_PCM_FORMAT_S16_LE : + buswidth =DMA_SLAVE_BUSWIDTH_2_BYTES ; +break ; +case SNDRV_PCM_FORMAT_S18_3LE : +case SNDRV_PCM_FORMAT_S20_3LE : +case SNDRV_PCM_FORMAT_S24_LE : +case SNDRV_PCM_FORMAT_S32_LE : + buswidth =DMA_SLAVE_BUSWIDTH_4_BYTES ; +break ; +default : +return -EINVAL ; + } + +if (substream->stream ==SNDRV_PCM_STREAM_PLAYBACK ) { + slave_config->direction =DMA_MEM_TO_DEV ; + slave_config->dst_addr_width = buswidth; + }else { + slave_config->direction =DMA_DEV_TO_MEM ; + slave_config->src_addr_width = buswidth; + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (snd_hwparams_to_dma_slave_config); + +static void dmaengine_pcm_dma_complete (void *arg) +{ +struct snd_pcm_substream *substream = arg; +struct dmaengine_pcm_runtime_data *prtd =substream_to_prtd (substream); + + prtd->pos +=snd_pcm_lib_period_bytes (substream); +if (prtd->pos >=snd_pcm_lib_buffer_bytes (substream)) + prtd->pos =0 ; + +snd_pcm_period_elapsed (substream); +} + +static int dmaengine_pcm_prepare_and_submit (struct snd_pcm_substream *substream) +{ +struct dmaengine_pcm_runtime_data *prtd =substream_to_prtd (substream); +struct dma_chan *chan = prtd->dma_chan; +struct dma_async_tx_descriptor *desc; +enum dma_transfer_direction direction; + + direction =snd_pcm_substream_to_dma_direction (substream); + + desc = chan->device->device_prep_dma_cyclic (chan, + substream->runtime->dma_addr, +snd_pcm_lib_buffer_bytes (substream), +snd_pcm_lib_period_bytes (substream), direction); + +if (!desc) +return -ENOMEM ; + + desc->callback = dmaengine_pcm_dma_complete; + desc->callback_param = substream; +dmaengine_submit (desc); + +return 0 ; +} + +/** +* snd_dmaengine_pcm_trigger - dmaengine based PCM trigger implementation +* @substream: PCM substream +* @cmd: Trigger command +* +* Returns 0 on success, a negative error code otherwise. +* +* This function can be used as the PCM trigger callback for dmaengine based PCM +* driver implementations. +*/ +int snd_dmaengine_pcm_trigger (struct snd_pcm_substream *substream,int cmd) +{ +struct dmaengine_pcm_runtime_data *prtd =substream_to_prtd (substream); +int ret; + +switch (cmd) { +case SNDRV_PCM_TRIGGER_START : + ret =dmaengine_pcm_prepare_and_submit (substream); +if (ret) +return ret; +dma_async_issue_pending (prtd->dma_chan); +break ; +case SNDRV_PCM_TRIGGER_RESUME : +case SNDRV_PCM_TRIGGER_PAUSE_RELEASE : +dmaengine_resume (prtd->dma_chan); +break ; +case SNDRV_PCM_TRIGGER_SUSPEND : +case SNDRV_PCM_TRIGGER_PAUSE_PUSH : +dmaengine_pause (prtd->dma_chan); +break ; +case SNDRV_PCM_TRIGGER_STOP : +dmaengine_terminate_all (prtd->dma_chan); +break ; +default : +return -EINVAL ; + } + +return 0 ; +} +EXPORT_SYMBOL_GPL (snd_dmaengine_pcm_trigger); + +/** +* snd_dmaengine_pcm_pointer - dmaengine based PCM pointer implementation +* @substream: PCM substream +* +* This function can be used as the PCM pointer callback for dmaengine based PCM +* driver implementations. +*/ +snd_pcm_uframes_t snd_dmaengine_pcm_pointer (struct snd_pcm_substream *substream) +{ +struct dmaengine_pcm_runtime_data *prtd =substream_to_prtd (substream); +return bytes_to_frames (substream->runtime, prtd->pos); +} +EXPORT_SYMBOL_GPL (snd_dmaengine_pcm_pointer); + +static int dmaengine_pcm_request_channel (struct dmaengine_pcm_runtime_data *prtd, +dma_filter_fn filter_fn,void *filter_data) +{ +dma_cap_mask_t mask; + +dma_cap_zero (mask); +dma_cap_set (DMA_SLAVE , mask); +dma_cap_set (DMA_CYCLIC , mask); + prtd->dma_chan =dma_request_channel (mask, filter_fn, filter_data); + +if (!prtd->dma_chan) +return -ENXIO ; + +return 0 ; +} + +/** +* snd_dmaengine_pcm_open - Open a dmaengine based PCM substream +* @substream: PCM substream +* @filter_fn: Filter function used to request the DMA channel +* @filter_data: Data passed to the DMA filter function +* +* Returns 0 on success, a negative error code otherwise. +* +* This function will request a DMA channel using the passed filter function and +* data. The function should usually be called from the pcm open callback. +* +* Note that this function will use private_data field of the substream's +* runtime. So it is not availabe to your pcm driver implementation. If you need +* to keep additional data attached to a substream use +* snd_dmaeinge_pcm_{set,get}_data. +*/ +int snd_dmaengine_pcm_open (struct snd_pcm_substream *substream, +dma_filter_fn filter_fn,void *filter_data) +{ +struct dmaengine_pcm_runtime_data *prtd; +int ret; + + ret =snd_pcm_hw_constraint_integer (substream->runtime, +SNDRV_PCM_HW_PARAM_PERIODS ); +if (ret <0 ) +return ret; + + prtd =kzalloc (sizeof (*prtd),GFP_KERNEL ); +if (!prtd) +return -ENOMEM ; + + ret =dmaengine_pcm_request_channel (prtd, filter_fn, filter_data); +if (ret <0 ) { +kfree (prtd); +return ret; + } + + substream->runtime->private_data = prtd; + +return 0 ; +} +EXPORT_SYMBOL_GPL (snd_dmaengine_pcm_open); + +/** +* snd_dmaengine_pcm_close - Close a dmaengine based PCM substream +* @substream: PCM substream +*/ +int snd_dmaengine_pcm_close (struct snd_pcm_substream *substream) +{ +struct dmaengine_pcm_runtime_data *prtd =substream_to_prtd (substream); + +dma_release_channel (prtd->dma_chan); +kfree (prtd); + +return 0 ; +} +EXPORT_SYMBOL_GPL (snd_dmaengine_pcm_close);Signature · 1 line
1.7.9
Re: [RFC 4/7] ASoC: Add dmaengine PCM helper functions
In reply to Lars-Peter ClausenQuoted 2 lines · Lars-Peter Clausen
This patch adds a set of functions which are intended to be used when implementing a dmaengine based sound PCM driver.
Looks good - if you need to resend then:
Quoted 4 lines
+ * Note that this function will use
private_datafield of the substream's
+ * runtime. So it is not availabe to your pcm driver implementation. If you need
+ * to keep additional data attached to a substream use
+ * snd_dmaeinge_pcm_{set,get}_data.
there's a typo here but no need to resend just for that.
I'd like to see some review from both Morimoto-san as we should convert fsi over to this too, Vinod I guess you're also pretty much happy given your comments on the previous version?
For the non-cyclic DMAs the idea of emulating at the dmaengine layer does seem very sensible but if that's hard then having the code at the ASoC level and pushing it down later seems fine. We do have several platforms with non-cyclic DMA so it's a general need.
Vinod Koul
Acked-byRe: [RFC 4/7] ASoC: Add dmaengine PCM helper functions
Quoted 11 lines · Mark Brown
Quoted 2 lines · Lars-Peter Clausen
This patch adds a set of functions which are intended to be used when implementing a dmaengine based sound PCM driver.
Looks good - if you need to resend then:
Quoted 4 lines
+ * Note that this function will use
private_datafield of the substream's
+ * runtime. So it is not availabe to your pcm driver implementation. If you need
+ * to keep additional data attached to a substream use
+ * snd_dmaeinge_pcm_{set,get}_data.
Quoted 5 lines
there's a typo here but no need to resend just for that.
I'd like to see some review from both Morimoto-san as we should convert fsi over to this too, Vinod I guess you're also pretty much happy given your comments on the previous version?
Sure,
Quoted 5 lines
For the non-cyclic DMAs the idea of emulating at the dmaengine layer does seem very sensible but if that's hard then having the code at the ASoC level and pushing it down later seems fine. We do have several platforms with non-cyclic DMA so it's a general need.
I think this should be pushed to dmaengine rather than in ASoC. That way ASoC can always request circular and we emulate the behavior in dmaengine for dmacs who don't support this
Signature · 1 line
~Vinod
Re: [RFC 4/7] ASoC: Add dmaengine PCM helper functions
Quoted 10 lines · Vinod Koul
Quoted 4 lines · Mark Brown
For the non-cyclic DMAs the idea of emulating at the dmaengine layer does seem very sensible but if that's hard then having the code at the ASoC level and pushing it down later seems fine. We do have several platforms with non-cyclic DMA so it's a general need.
I think this should be pushed to dmaengine rather than in ASoC. That way ASoC can always request circular and we emulate the behavior in dmaengine for dmacs who don't support this
That's what I just said. I'm just saying that if for some reason it's going to be difficult to implement I don't mind carrying code at the ASoC layer while that work is done.
Re: [RFC 4/7] ASoC: Add dmaengine PCM helper functions
In reply to Mark BrownQuoted 13 lines · Mark Brown
Quoted 2 lines · Lars-Peter Clausen
This patch adds a set of functions which are intended to be used when implementing a dmaengine based sound PCM driver.
Looks good - if you need to resend then:
Quoted 4 lines
+ * Note that this function will use
private_datafield of the substream's
+ * runtime. So it is not availabe to your pcm driver implementation. If you need
+ * to keep additional data attached to a substream use
+ * snd_dmaeinge_pcm_{set,get}_data.there's a typo here but no need to resend just for that.
Quoted 8 lines
I'd like to see some review from both Morimoto-san as we should convert fsi over to this too, Vinod I guess you're also pretty much happy given your comments on the previous version?
For the non-cyclic DMAs the idea of emulating at the dmaengine layer does seem very sensible but if that's hard then having the code at the ASoC level and pushing it down later seems fine. We do have several platforms with non-cyclic DMA so it's a general need.
I think you're making the assumption that other people need cyclic transfers. I've seen little evidence that anyone other than sound needs such things, so I don't think there's justification to push this code into every DMA engine driver.
Remember, there's no common code to a DMA engine driver at all, everyone implements their own way with their own bugs. I would agree with you if there was some decent DMA engine infrastructure to abstract out such things, but there isn't.
So what you're asking is for N different ways of doing this, instead of having one centralized way.
Re: [RFC 4/7] ASoC: Add dmaengine PCM helper functions
Quoted 4 lines · Russell King - ARM Linux
I think you're making the assumption that other people need cyclic transfers. I've seen little evidence that anyone other than sound needs such things, so I don't think there's justification to push this code into every DMA engine driver.
The idea was to have the library code to do this in the dmaengine core rather in drivers. Doing it in the drivers would be silly, it should be in library code somewhere. If we are going to librify it then pushing the code as far up the stack as we can seems like a smart move.
Quoted 7 lines
Remember, there's no common code to a DMA engine driver at all, everyone implements their own way with their own bugs. I would agree with you if there was some decent DMA engine infrastructure to abstract out such things, but there isn't.
So what you're asking is for N different ways of doing this, instead of having one centralized way.
Well, Vinod seemed to also think that dmaengine ought to be able to cope with emulating this and I really don't see why it shouldn't be. It does know the capabilities of the underlying driver and it gets to look at all the calls going into the driver before the driver does. If ASoC can interpose itself I don't see why dmaengine can't.
Re: [RFC 4/7] ASoC: Add dmaengine PCM helper functions
Quoted 5 lines · Mark Brown
Well, Vinod seemed to also think that dmaengine ought to be able to cope with emulating this and I really don't see why it shouldn't be. It does know the capabilities of the underlying driver and it gets to look at all the calls going into the driver before the driver does. If ASoC can interpose itself I don't see why dmaengine can't.
Have you ever looked at the DMA engine drivers? It's a total mess. Even something as basic as the DMA engine driver assigning a cookie to the descriptor is implemented in each driver in their own unique way.
Completion of DMA descriptors is a similar thing - every driver implements this in their own unique way.
The only really common thing in the DMA engine drivers is that they all share the same API. Nothing much more than that is shared.
It's something I have been chipping away at for a while, trying to extract out common parts into a library, but it's really not that easy.
So, there's no way in hell that I want to see any more stuff pushed down into the DMA engine drivers until we have a proper DMA engine library in place to stop all this idiotic code duplication throughout every driver. Especially if it means everyone will be implementing their own cyclic emulation in their individual drivers.
And lets not forget that it's not just a question of "oh we can just queue up buffer after buffer". Doing it properly for audio does need to ensure that the DMA engine driver is capable of getting the next buffer chained into the hardware before the previous buffer has completed, so the transfer continues across a buffer boundary without needing the intervention of an interrupt handler. Otherwise you get glitches in the audio.
So, there's a lot more here that DMA engine stuff needs to get fixed than just a simple "layer on top".
Re: [RFC 4/7] ASoC: Add dmaengine PCM helper functions
Quoted 9 lines · Russell King - ARM Linux
Quoted 5 lines · Mark Brown
Well, Vinod seemed to also think that dmaengine ought to be able to cope with emulating this and I really don't see why it shouldn't be. It does know the capabilities of the underlying driver and it gets to look at all the calls going into the driver before the driver does. If ASoC can interpose itself I don't see why dmaengine can't.
Have you ever looked at the DMA engine drivers? It's a total mess.
Not in enormous detail, no.
Quoted 8 lines
Even something as basic as the DMA engine driver assigning a cookie to the descriptor is implemented in each driver in their own unique way.
Completion of DMA descriptors is a similar thing - every driver implements this in their own unique way.
The only really common thing in the DMA engine drivers is that they all share the same API. Nothing much more than that is shared.
Plus they're going through a common vtable and accessors which is the main thing here I expect.
Quoted 5 lines
So, there's no way in hell that I want to see any more stuff pushed down into the DMA engine drivers until we have a proper DMA engine library in place to stop all this idiotic code duplication throughout every driver. Especially if it means everyone will be implementing their own cyclic emulation in their individual drivers.
I've not seen any suggestion from anyone that that's a good idea.
Quoted 2 lines
So, there's a lot more here that DMA engine stuff needs to get fixed than just a simple "layer on top".
Well, if we can't do it with a layer in the dmaengine code then I don't see how we could do it in ASoC either, presumably the issues that block doing it in the dmaengine core code would also cause issues doing it in ASoC?
I'm not saying there's nothing that needs fixing in the dmaengine code, and like I say I'm not too worried about carrying things in ASoC if the dmaengine code is intractably difficult, but I'm not sure that the issues you're rasing aren't orthogonal to the issues with emulating cyclic transfers.
Re: [RFC 4/7] ASoC: Add dmaengine PCM helper functions
Quoted 10 lines · Mark Brown
Well, if we can't do it with a layer in the dmaengine code then I don't see how we could do it in ASoC either, presumably the issues that block doing it in the dmaengine core code would also cause issues doing it in ASoC?
I'm not saying there's nothing that needs fixing in the dmaengine code, and like I say I'm not too worried about carrying things in ASoC if the dmaengine code is intractably difficult, but I'm not sure that the issues you're rasing aren't orthogonal to the issues with emulating cyclic transfers.
Look, I spent a number of weeks working on the SA11x0 DMA engine code and ALSA side to get something which worked reliably, and a simple solution doesn't work. I've been looking at the DMA engine code probably for longer than Vinod has been involved with it. I've been working on cleaning up all the DMA engine drivers extracting some of the common bits from them. I'm very familiar with level of crap in the DMA engine stuff. I know what I'm talking about.
The point that I'm making is that there's more to this than just adding a layer. If you think that's all that there is, then you haven't properly understood the SA11x0 audio support patch set that I have, and the interactions between the individual patches. That's not surprising because I haven't posted the patches yet, and I haven't explained them either.
And since I'm spending today working on x86 kernel instability (thanks to Linux for taking out my laptop last night) I've little time to spend discussing the fine points of this, let alone any other ARM stuff.
Re: [RFC 4/7] ASoC: Add dmaengine PCM helper functions
Quoted 7 lines · Russell King - ARM Linux
Look, I spent a number of weeks working on the SA11x0 DMA engine code and ALSA side to get something which worked reliably, and a simple solution doesn't work. I've been looking at the DMA engine code probably for longer than Vinod has been involved with it. I've been working on cleaning up all the DMA engine drivers extracting some of the common bits from them. I'm very familiar with level of crap in the DMA engine stuff. I know what I'm talking about.
OK, fair enough - like I say the thing I'm not getting is why this is resolvable in a dmaengine client but not in dmaengine itself. If nothing else I'd expect the core to be able to insert a proxy client.
Quoted 6 lines
The point that I'm making is that there's more to this than just adding a layer. If you think that's all that there is, then you haven't properly understood the SA11x0 audio support patch set that I have, and the interactions between the individual patches. That's not surprising because I haven't posted the patches yet, and I haven't explained them either.
Indeed, I've not really looked at the code in any great detail at your code as you didn't post it (I only looked at all because it showed up in -next) and there were some issues at the subsystem level so I stopped pretty quickly.
Re: [RFC 4/7] ASoC: Add dmaengine PCM helper functions
In reply to Russell King - ARM LinuxQuoted 33 lines · Russell King - ARM Linux
Quoted 5 lines · Mark Brown
Well, Vinod seemed to also think that dmaengine ought to be able to cope with emulating this and I really don't see why it shouldn't be. It does know the capabilities of the underlying driver and it gets to look at all the calls going into the driver before the driver does. If ASoC can interpose itself I don't see why dmaengine can't.
Have you ever looked at the DMA engine drivers? It's a total mess. Even something as basic as the DMA engine driver assigning a cookie to the descriptor is implemented in each driver in their own unique way.
Completion of DMA descriptors is a similar thing - every driver implements this in their own unique way.
The only really common thing in the DMA engine drivers is that they all share the same API. Nothing much more than that is shared.
It's something I have been chipping away at for a while, trying to extract out common parts into a library, but it's really not that easy.
So, there's no way in hell that I want to see any more stuff pushed down into the DMA engine drivers until we have a proper DMA engine library in place to stop all this idiotic code duplication throughout every driver. Especially if it means everyone will be implementing their own cyclic emulation in their individual drivers.
And lets not forget that it's not just a question of "oh we can just queue up buffer after buffer". Doing it properly for audio does need to ensure that the DMA engine driver is capable of getting the next buffer chained into the hardware before the previous buffer has completed, so the transfer continues across a buffer boundary without needing the intervention of an interrupt handler. Otherwise you get glitches in the audio.
Quoted 2 lines
So, there's a lot more here that DMA engine stuff needs to get fixed than just a simple "layer on top".
I would agree with Russell that some of dma drivers are messy, but then were also a victim of ambiguous API. Now at least we have a clear direction of what is expected out of dma driver and what is not. Except for channel mapping stuff, rest has a clarity.
So the new drivers and fixes now are going in the right direction (hopefully you will agree with me on this) and we are frankly in much better state then we were one year back.
Said that, we still have lot of work to do to improve :)
And I see this as another opportunity. Having a common library for these kind of common subsystem operations forces people to write proper driver and forces them to fix existing issue. Now, new support for DMAengine in asoc wont come without using this library and if it does work on a particular driver that is precondition for fixes as well.
Similarly I would really love to see such libraries in other subsystems which would help us in making the usage of dmaengine and dmac standard and straight forward for users.
Signature · 1 line
~Vinod
Re: [RFC 4/7] ASoC: Add dmaengine PCM helper functions
In reply to Lars-Peter ClausenQuoted 2 lines · Lars-Peter Clausen
This patch adds a set of functions which are intended to be used when implementing a dmaengine based sound PCM driver.
Having this framework is a substantial win and I got bored waiting for the repost of this and the subsequent patches (especially given that the merge window is drawing nearer). Since the fix for ep93xx is so simple and it works on i.MX I went ahead and applied everything except the ep93xx conversion. Thanks!
Please resend the ep93xx conversion along with the tweak to the core so we can get that working. It would also be good to update FSI to use this library as it's also using dmaengine (the patch having been merged just before this one it got missed in the updates I expect).
Lars-Peter Clausen
maintainerRe: [RFC 4/7] ASoC: Add dmaengine PCM helper functions
Quoted 4 lines · Mark Brown
Quoted 2 lines · Lars-Peter Clausen
This patch adds a set of functions which are intended to be used when implementing a dmaengine based sound PCM driver.
Quoted 8 lines
Having this framework is a substantial win and I got bored waiting for the repost of this and the subsequent patches (especially given that the merge window is drawing nearer). Since the fix for ep93xx is so simple and it works on i.MX I went ahead and applied everything except the ep93xx conversion. Thanks!
Please resend the ep93xx conversion along with the tweak to the core so we can get that working.
I was at trade show for the rest of last week, without much time for anything else. I will submit the missing patches in a moment.
Quoted 3 lines
It would also be good to update FSI to use this library as it's also using dmaengine (the patch having been merged just before this one it got missed in the updates I expect).
I've had a look at the FSI dmaengine driver and it is not straight forward to convert. For one it does not use cyclic dma transfers so it is more something for Russel's patch and on the other hand the FSI PCM driver introduces another layer of indirection which is used to be able to switch between PIO and DMA. But as a result the functions the dmaengine PCM framework provides don't really fit anymore.
- Lars
Re: [RFC 4/7] ASoC: Add dmaengine PCM helper functions
Quoted 7 lines · Lars-Peter Clausen
Quoted 2 lines · Mark Brown
Please resend the ep93xx conversion along with the tweak to the core so we can get that working.
I was at trade show for the rest of last week, without much time for anything else. I will submit the missing patches in a moment.
No problem, I figured it was something like that and didn't see any reason not to get the changes into 3.4 - it's a substantial win all round and the fixes are pretty minior.
Quoted 10 lines
Quoted 3 lines
It would also be good to update FSI to use this library as it's also using dmaengine (the patch having been merged just before this one it got missed in the updates I expect).
I've had a look at the FSI dmaengine driver and it is not straight forward to convert. For one it does not use cyclic dma transfers so it is more something for Russel's patch and on the other hand the FSI PCM driver introduces another layer of indirection which is used to be able to switch between PIO and DMA. But as a result the functions the dmaengine PCM framework provides don't really fit anymore.
OK, fair enough.
Re: [RFC 4/7] ASoC: Add dmaengine PCM helper functions
Hi Lars, Mark
Quoted 4 lines
Quoted 3 lines
Quoted 3 lines
It would also be good to update FSI to use this library as it's also using dmaengine (the patch having been merged just before this one it got missed in the updates I expect).
Quoted 8 lines
Quoted 6 lines
I've had a look at the FSI dmaengine driver and it is not straight forward to convert. For one it does not use cyclic dma transfers so it is more something for Russel's patch and on the other hand the FSI PCM driver introduces another layer of indirection which is used to be able to switch between PIO and DMA. But as a result the functions the dmaengine PCM framework provides don't really fit anymore.
OK, fair enough.
FSI can switch PIO/DMA, but it will be decided on _probe() timing, not runtime switch. PIO/DMA is depend on SuperH CPU/platform supporting status.
And yes, it doesn't use cyclic dma transfer since I don't know how to use it :)
I forgot detail, but I used sound/soc/sh/siu_pcm.c and sound/soc/txx9/txx9aclc.c as sample code when I created FSI DMAEngine support.
If ASoC layer supports dmaengine helper functions, I can switch to it by my incremental patch.
Best regards
---
Kuninori Morimoto
Re: [RFC 4/7] ASoC: Add dmaengine PCM helper functions
Quoted 6 lines · Kuninori Morimoto
And yes, it doesn't use cyclic dma transfer since I don't know how to use it :)
I forgot detail, but I used
sound/soc/sh/siu_pcm.candsound/soc/txx9/txx9aclc.cas sample code when I created FSI DMAEngine support.If ASoC layer supports dmaengine helper functions, I can switch to it by my incremental patch.
OK, great - if the hardware supports cyclic mode then I guess the best thing is to enable that in dmaengine then switch over to using the new library once that's merged (unless someone comes along and implements cyclic emulation support first).
Lars-Peter Clausen
maintainerRFC 5/7 ASoC: imx-pcm-dma: Use dmaengine PCM helper functions
In reply to Lars-Peter Clausen--- sound/soc/imx/Kconfig | 1 + sound/soc/imx/imx-pcm-dma-mx2.c | 176 ++++++--------------------------------- 2 files changed, 28 insertions(+), 149 deletions(-)
sound/soc/imx/Kconfig +1 -0
@@ -14,6 +14,7 @@ config SND_MXC_SOC_FIQ tristate config SND_MXC_SOC_MX2 + select SND_SOC_DMAENGINE_PCM tristate config SND_MXC_SOC_WM1133_EV1
sound/soc/imx/imx-pcm-dma-mx2.c +27 -149
247 lines not on this page · raw message
Signature · 1 line
1.7.9
Lars-Peter Clausen
maintainerRFC 6/7 ASoC: mxs-pcm: Use dmaengine PCM helper functions
In reply to Lars-Peter Clausen--- sound/soc/mxs/Kconfig | 1 + sound/soc/mxs/mxs-pcm.c | 136 ++++++++-------------------------------------- sound/soc/mxs/mxs-pcm.h | 12 ---- 3 files changed, 25 insertions(+), 124 deletions(-)
sound/soc/mxs/Kconfig +1 -0
@@ -1,6 +1,7 @@ menuconfig SND_MXS_SOC tristate "SoC Audio for Freescale MXS CPUs" depends on ARCH_MXS + select SND_SOC_DMAENGINE_PCM help Say Y or M if you want to add support for codecs attached to the MXS SAIF interface.
sound/soc/mxs/mxs-pcm.c +24 -112
197 lines not on this page · raw message
sound/soc/mxs/mxs-pcm.h +0 -12
@@ -19,21 +19,9 @@#ifndef _MXS_PCM_H#define _MXS_PCM_H -#include <mach/dma.h> -struct mxs_pcm_dma_params {int chan_irq;int chan_num; }; -struct mxs_pcm_runtime_data { -int period_bytes; -int periods; -unsigned long offset; -struct dma_async_tx_descriptor *desc; -struct dma_chan *dma_chan; -struct mxs_dma_data dma_data; -struct mxs_pcm_dma_params *dma_params; -}; -#endif
Signature · 1 line
1.7.9
Lars-Peter Clausen
maintainerRFC 7/7 ASoC: ep93xx-pcm: Use dmaengine PCM helper functions
In reply to Lars-Peter Clausen--- sound/soc/ep93xx/Kconfig | 1 + sound/soc/ep93xx/ep93xx-pcm.c | 148 ++++++----------------------------------- 2 files changed, 23 insertions(+), 126 deletions(-)
sound/soc/ep93xx/Kconfig +1 -0
@@ -1,6 +1,7 @@ config SND_EP93XX_SOC tristate "SoC Audio support for the Cirrus Logic EP93xx series" depends on ARCH_EP93XX && SND_SOC + select SND_SOC_DMAENGINE_PCM help Say Y or M if you want to add support for codecs attached to the EP93xx I2S or AC97 interfaces.
sound/soc/ep93xx/ep93xx-pcm.c +22 -126
201 lines not on this page · raw message
Signature · 1 line
1.7.9
Re: [RFC 7/7] ASoC: ep93xx-pcm: Use dmaengine PCM helper functions
Quoted 1 line · Lars-Peter Clausen
Signed-off-by Lars-Peter Clausen <[email protected]>
For some reason, this doesn't work on my ep93xx based Sim.One board. On playback with mpg123 when I press stop, it continues to play whatever was on the ring-buffer forever. Without the patches it works fine.
I'll try to find some time to debug this further.
Lars-Peter Clausen
maintainerRe: [RFC 7/7] ASoC: ep93xx-pcm: Use dmaengine PCM helper functions
Quoted 8 lines · Mika Westerberg
Quoted 1 line · Lars-Peter Clausen
Signed-off-by Lars-Peter Clausen <[email protected]>For some reason, this doesn't work on my ep93xx based Sim.One board. On playback with mpg123 when I press stop, it continues to play whatever was on the ring-buffer forever. Without the patches it works fine.
I'll try to find some time to debug this further.
Hm, that’s interesting. The original ep93xx pcm driver was almost identical to what the common helper functions do. The only difference I can spot right now is, that it doesn't call dma_issue_pending after submitting the descriptor. Could you try to comment out the dma_issue_pending in soc-dmaengine-pcm.c and test whether it makes a difference?
Thanks,
- Lars
Re: [RFC 7/7] ASoC: ep93xx-pcm: Use dmaengine PCM helper functions
Quoted 8 lines · Lars-Peter Clausen
Quoted 7 lines · Mika Westerberg
Quoted 1 line · Lars-Peter Clausen
Signed-off-by Lars-Peter Clausen <[email protected]>For some reason, this doesn't work on my ep93xx based Sim.One board. On playback with mpg123 when I press stop, it continues to play whatever was on the ring-buffer forever. Without the patches it works fine.
Quoted 7 lines
Quoted 1 line
I'll try to find some time to debug this further.
Hm, that’s interesting. The original ep93xx pcm driver was almost identical to what the common helper functions do. The only difference I can spot right now is, that it doesn't call
dma_issue_pendingafter submitting the descriptor. Could you try to comment out thedma_issue_pendinginsoc-dmaengine-pcm.cand test whether it makes a difference?
I did try that but there was no effect, unfortunately.
However, I noticed that prtd->pos was never set to zero as it was in the original ep93xx-pcm driver. With following addition to your patch, playback works fine.
sound/soc/soc-dmaengine-pcm.c +1 -0
@@ -142,6 +142,7 @@ static int dmaengine_pcm_prepare_and_submit(struct snd_pcm_substream *substream) direction =snd_pcm_substream_to_dma_direction (substream); + prtd->pos =0 ; desc = chan->device->device_prep_dma_cyclic(chan, substream->runtime->dma_addr, snd_pcm_lib_buffer_bytes(substream),
_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Lars-Peter Clausen
maintainerRe: [RFC 7/7] ASoC: ep93xx-pcm: Use dmaengine PCM helper functions
Quoted 17 lines · Mika Westerberg
Quoted 8 lines · Lars-Peter Clausen
Quoted 7 lines · Mika Westerberg
Quoted 1 line · Lars-Peter Clausen
Signed-off-by Lars-Peter Clausen <[email protected]>For some reason, this doesn't work on my ep93xx based Sim.One board. On playback with mpg123 when I press stop, it continues to play whatever was on the ring-buffer forever. Without the patches it works fine.
Quoted 7 lines
Quoted 1 line
I'll try to find some time to debug this further.
Hm, that’s interesting. The original ep93xx pcm driver was almost identical to what the common helper functions do. The only difference I can spot right now is, that it doesn't call
dma_issue_pendingafter submitting the descriptor. Could you try to comment out thedma_issue_pendinginsoc-dmaengine-pcm.cand test whether it makes a difference?
Quoted 6 lines
I did try that but there was no effect, unfortunately.
However, I noticed that
prtd->poswas never set to zero as it was in the original ep93xx-pcm driver. With following addition to your patch, playback works fine.
Ah, nice :)
Thanks,
- Lars
Quoted 16 lines
sound/soc/soc-dmaengine-pcm.c +1
-0@@ -142,6 +142,7 @@ static int dmaengine_pcm_prepare_and_submit(struct snd_pcm_substream *substream) direction =snd_pcm_substream_to_dma_direction (substream); + prtd->pos =0 ; desc = chan->device->device_prep_dma_cyclic(chan, substream->runtime->dma_addr, snd_pcm_lib_buffer_bytes(substream),_______________________________________________
Alsa-devel mailing list
[email protected]
http://mailman.alsa-project.org/mailman/listinfo/alsa-devel
Re: [RFC 7/7] ASoC: ep93xx-pcm: Use dmaengine PCM helper functions
Quoted 7 lines · Lars-Peter Clausen
Quoted 3 lines · Mika Westerberg
However, I noticed that
prtd->poswas never set to zero as it was in the original ep93xx-pcm driver. With following addition to your patch, playback works fine.Ah, nice :)
Looking good. Can you please resend the series with this fix applied and all the acks you've collected?
Lars-Peter Clausen
maintainerRe: [RFC 7/7] ASoC: ep93xx-pcm: Use dmaengine PCM helper functions
Quoted 11 lines · Mark Brown
Quoted 7 lines · Lars-Peter Clausen
Quoted 3 lines · Mika Westerberg
However, I noticed that
prtd->poswas never set to zero as it was in the original ep93xx-pcm driver. With following addition to your patch, playback works fine.Ah, nice :)
Looking good. Can you please resend the series with this fix applied and all the acks you've collected?
I don't think there were any Acked-bys, just a Tested-by from Shawn Guo.
Mika, can I get a Tested-by or Acked-by for this patch from you?
Thanks,
- Lars
Re: [RFC 7/7] ASoC: ep93xx-pcm: Use dmaengine PCM helper functions
Quoted 6 lines · Lars-Peter Clausen
Quoted 2 lines · Mark Brown
Looking good. Can you please resend the series with this fix applied and all the acks you've collected?
I don't think there were any Acked-bys, just a Tested-by from Shawn Guo.
I think Vinod acked it, ICBW though.
Mika Westerberg
Tested-byRe: [RFC 7/7] ASoC: ep93xx-pcm: Use dmaengine PCM helper functions
In reply to Lars-Peter ClausenQuoted 8 lines · Lars-Peter Clausen
Quoted 7 lines · Mark Brown
Quoted 5 lines · Lars-Peter Clausen
Quoted 3 lines · Mika Westerberg
However, I noticed that
prtd->poswas never set to zero as it was in the original ep93xx-pcm driver. With following addition to your patch, playback works fine.
Quoted 8 lines
Quoted 4 lines
Quoted 1 line
Ah, nice :)
Looking good. Can you please resend the series with this fix applied and all the acks you've collected?
I don't think there were any Acked-bys, just a Tested-by from Shawn Guo.
Mika, can I get a Tested-by or Acked-by for this patch from you?
Sure,