2013-07-02 09:07:10

by Bo Shen

[permalink] [raw]
Subject: [PATCH 0/2] ASoC: atmel-pcm: use generic dmaengine framework

this patch series is based on next-20130701

Bo Shen (2):
ASoC: atmel_ssc_dai: move set dma data to startup callback
ASoC: atmel-pcm: use generic dmaengine framework

sound/soc/atmel/atmel-pcm-dma.c | 118 ++++++---------------------------------
sound/soc/atmel/atmel_ssc_dai.c | 33 ++++++-----
2 files changed, 32 insertions(+), 119 deletions(-)

--
1.7.9.5


2013-07-02 09:07:12

by Bo Shen

[permalink] [raw]
Subject: [PATCH 1/2] ASoC: atmel_ssc_dai: move set dma data to startup callback

move set dma data to startup callback function, if the set dma
data exist in hw_params callback, so the dma data only usable when
call hw_params, if want use it before hw_params callback, it will
cause NULL pointer access oops

Signed-off-by: Bo Shen <[email protected]>
---
sound/soc/atmel/atmel_ssc_dai.c | 33 ++++++++++++++++-----------------
1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/sound/soc/atmel/atmel_ssc_dai.c b/sound/soc/atmel/atmel_ssc_dai.c
index f3fdfa0..6cf9cf1 100644
--- a/sound/soc/atmel/atmel_ssc_dai.c
+++ b/sound/soc/atmel/atmel_ssc_dai.c
@@ -196,15 +196,27 @@ static int atmel_ssc_startup(struct snd_pcm_substream *substream,
struct snd_soc_dai *dai)
{
struct atmel_ssc_info *ssc_p = &ssc_info[dai->id];
- int dir_mask;
+ struct atmel_pcm_dma_params *dma_params;
+ int dir, dir_mask;

pr_debug("atmel_ssc_startup: SSC_SR=0x%u\n",
ssc_readl(ssc_p->ssc->regs, SR));

- if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK)
+ if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
+ dir = 0;
dir_mask = SSC_DIR_MASK_PLAYBACK;
- else
+ } else {
+ dir = 1;
dir_mask = SSC_DIR_MASK_CAPTURE;
+ }
+
+ dma_params = &ssc_dma_params[dai->id][dir];
+ dma_params->ssc = ssc_p->ssc;
+ dma_params->substream = substream;
+
+ ssc_p->dma_params[dir] = dma_params;
+
+ snd_soc_dai_set_dma_data(dai, substream, dma_params);

spin_lock_irq(&ssc_p->lock);
if (ssc_p->dir_mask & dir_mask) {
@@ -325,7 +337,6 @@ static int atmel_ssc_hw_params(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *params,
struct snd_soc_dai *dai)
{
- struct snd_soc_pcm_runtime *rtd = snd_pcm_substream_chip(substream);
int id = dai->id;
struct atmel_ssc_info *ssc_p = &ssc_info[id];
struct atmel_pcm_dma_params *dma_params;
@@ -344,19 +355,7 @@ static int atmel_ssc_hw_params(struct snd_pcm_substream *substream,
else
dir = 1;

- dma_params = &ssc_dma_params[id][dir];
- dma_params->ssc = ssc_p->ssc;
- dma_params->substream = substream;
-
- ssc_p->dma_params[dir] = dma_params;
-
- /*
- * The snd_soc_pcm_stream->dma_data field is only used to communicate
- * the appropriate DMA parameters to the pcm driver hw_params()
- * function. It should not be used for other purposes
- * as it is common to all substreams.
- */
- snd_soc_dai_set_dma_data(rtd->cpu_dai, substream, dma_params);
+ dma_params = ssc_p->dma_params[dir];

channels = params_channels(params);

--
1.7.9.5

2013-07-02 09:07:46

by Bo Shen

[permalink] [raw]
Subject: [PATCH 2/2] ASoC: atmel-pcm: use generic dmaengine framework

Align atmel pcm to use ASoC generic dmaengine framework

Signed-off-by: Bo Shen <[email protected]>

---
sound/soc/atmel/atmel-pcm-dma.c | 118 ++++++---------------------------------
1 file changed, 16 insertions(+), 102 deletions(-)

diff --git a/sound/soc/atmel/atmel-pcm-dma.c b/sound/soc/atmel/atmel-pcm-dma.c
index 1d38fd0..0f6c701 100644
--- a/sound/soc/atmel/atmel-pcm-dma.c
+++ b/sound/soc/atmel/atmel-pcm-dma.c
@@ -89,138 +89,52 @@ static void atmel_pcm_dma_irq(u32 ssc_sr,
}
}

-/*--------------------------------------------------------------------------*\
- * DMAENGINE operations
-\*--------------------------------------------------------------------------*/
-static bool filter(struct dma_chan *chan, void *slave)
-{
- struct at_dma_slave *sl = slave;
-
- if (sl->dma_dev == chan->device->dev) {
- chan->private = sl;
- return true;
- } else {
- return false;
- }
-}
-
static int atmel_pcm_configure_dma(struct snd_pcm_substream *substream,
- struct snd_pcm_hw_params *params, struct atmel_pcm_dma_params *prtd)
+ struct snd_pcm_hw_params *params, struct dma_slave_config *slave_config)
{
+ struct snd_soc_pcm_runtime *rtd = substream->private_data;
+ struct atmel_pcm_dma_params *prtd;
struct ssc_device *ssc;
- struct dma_chan *dma_chan;
- struct dma_slave_config slave_config;
int ret;

+ prtd = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
ssc = prtd->ssc;

- ret = snd_hwparams_to_dma_slave_config(substream, params,
- &slave_config);
+ ret = snd_hwparams_to_dma_slave_config(substream, params, slave_config);
if (ret) {
pr_err("atmel-pcm: hwparams to dma slave configure failed\n");
return ret;
}

if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
- slave_config.dst_addr = (dma_addr_t)ssc->phybase + SSC_THR;
- slave_config.dst_maxburst = 1;
+ slave_config->dst_addr = (dma_addr_t)ssc->phybase + SSC_THR;
+ slave_config->dst_maxburst = 1;
} else {
- slave_config.src_addr = (dma_addr_t)ssc->phybase + SSC_RHR;
- slave_config.src_maxburst = 1;
- }
-
- dma_chan = snd_dmaengine_pcm_get_chan(substream);
- if (dmaengine_slave_config(dma_chan, &slave_config)) {
- pr_err("atmel-pcm: failed to configure dma channel\n");
- ret = -EBUSY;
- return ret;
- }
-
- return 0;
-}
-
-static int atmel_pcm_hw_params(struct snd_pcm_substream *substream,
- struct snd_pcm_hw_params *params)
-{
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
- struct atmel_pcm_dma_params *prtd;
- struct ssc_device *ssc;
- struct at_dma_slave *sdata = NULL;
- int ret;
-
- snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
-
- prtd = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
- ssc = prtd->ssc;
- if (ssc->pdev)
- sdata = ssc->pdev->dev.platform_data;
-
- ret = snd_dmaengine_pcm_open_request_chan(substream, filter, sdata);
- if (ret) {
- pr_err("atmel-pcm: dmaengine pcm open failed\n");
- return -EINVAL;
- }
-
- ret = atmel_pcm_configure_dma(substream, params, prtd);
- if (ret) {
- pr_err("atmel-pcm: failed to configure dmai\n");
- goto err;
+ slave_config->src_addr = (dma_addr_t)ssc->phybase + SSC_RHR;
+ slave_config->src_maxburst = 1;
}

prtd->dma_intr_handler = atmel_pcm_dma_irq;

return 0;
-err:
- snd_dmaengine_pcm_close_release_chan(substream);
- return ret;
}

-static int atmel_pcm_dma_prepare(struct snd_pcm_substream *substream)
-{
- struct snd_soc_pcm_runtime *rtd = substream->private_data;
- struct atmel_pcm_dma_params *prtd;
-
- prtd = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
-
- ssc_writex(prtd->ssc->regs, SSC_IER, prtd->mask->ssc_error);
- ssc_writex(prtd->ssc->regs, SSC_CR, prtd->mask->ssc_enable);
-
- return 0;
-}
-
-static int atmel_pcm_open(struct snd_pcm_substream *substream)
-{
- snd_soc_set_runtime_hwparams(substream, &atmel_pcm_dma_hardware);
-
- return 0;
-}
-
-static struct snd_pcm_ops atmel_pcm_ops = {
- .open = atmel_pcm_open,
- .close = snd_dmaengine_pcm_close_release_chan,
- .ioctl = snd_pcm_lib_ioctl,
- .hw_params = atmel_pcm_hw_params,
- .prepare = atmel_pcm_dma_prepare,
- .trigger = snd_dmaengine_pcm_trigger,
- .pointer = snd_dmaengine_pcm_pointer_no_residue,
- .mmap = atmel_pcm_mmap,
-};
-
-static struct snd_soc_platform_driver atmel_soc_platform = {
- .ops = &atmel_pcm_ops,
- .pcm_new = atmel_pcm_new,
- .pcm_free = atmel_pcm_free,
+static const struct snd_dmaengine_pcm_config atmel_dmaengine_pcm_config = {
+ .prepare_slave_config = atmel_pcm_configure_dma,
+ .pcm_hardware = &atmel_pcm_dma_hardware,
+ .prealloc_buffer_size = ATMEL_SSC_DMABUF_SIZE,
};

int atmel_pcm_dma_platform_register(struct device *dev)
{
- return snd_soc_register_platform(dev, &atmel_soc_platform);
+ return snd_dmaengine_pcm_register(dev, &atmel_dmaengine_pcm_config,
+ SND_DMAENGINE_PCM_FLAG_NO_RESIDUE);
}
EXPORT_SYMBOL(atmel_pcm_dma_platform_register);

void atmel_pcm_dma_platform_unregister(struct device *dev)
{
- snd_soc_unregister_platform(dev);
+ snd_dmaengine_pcm_unregister(dev);
}
EXPORT_SYMBOL(atmel_pcm_dma_platform_unregister);

--
1.7.9.5

2013-07-02 15:22:24

by Lars-Peter Clausen

[permalink] [raw]
Subject: Re: [alsa-devel] [PATCH 1/2] ASoC: atmel_ssc_dai: move set dma data to startup callback

On 07/02/2013 11:04 AM, Bo Shen wrote:
[...]
> + dma_params->substream = substream;

Unrelated to this patch, but having a substream field in the dma_params seems
to be redundant, since you need to know the substream to get the dma_params in
the first place. Looking at the code it also seems to be unused other than this
assignment. Maybe you can send a follow up patch to remove it.

[...]

2013-07-02 15:31:07

by Lars-Peter Clausen

[permalink] [raw]
Subject: Re: [alsa-devel] [PATCH 2/2] ASoC: atmel-pcm: use generic dmaengine framework

On 07/02/2013 11:04 AM, Bo Shen wrote:
[...]
> -/*--------------------------------------------------------------------------*\
> - * DMAENGINE operations
> -\*--------------------------------------------------------------------------*/
> -static bool filter(struct dma_chan *chan, void *slave)
> -{
> - struct at_dma_slave *sl = slave;
> -
> - if (sl->dma_dev == chan->device->dev) {
> - chan->private = sl;
> - return true;
> - } else {
> - return false;
> - }
> -}

I'm wondering why is filtering no longer required?

[...]
> + slave_config->dst_addr = (dma_addr_t)ssc->phybase + SSC_THR;
[...]
> + slave_config->src_addr = (dma_addr_t)ssc->phybase + SSC_RHR;

Change the type of phybase to dma_addr_t

[...]
> }
>
> -static int atmel_pcm_dma_prepare(struct snd_pcm_substream *substream)
> -{
> - struct snd_soc_pcm_runtime *rtd = substream->private_data;
> - struct atmel_pcm_dma_params *prtd;
> -
> - prtd = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
> -
> - ssc_writex(prtd->ssc->regs, SSC_IER, prtd->mask->ssc_error);
> - ssc_writex(prtd->ssc->regs, SSC_CR, prtd->mask->ssc_enable);

These writes are also completely lost

> -
> - return 0;
> -}

I think it would also be good to get rid of any references to the ssc struct
from the DMA driver and move them over to the DAI driver.

- Lars

2013-07-03 01:20:56

by Bo Shen

[permalink] [raw]
Subject: Re: [alsa-devel] [PATCH 1/2] ASoC: atmel_ssc_dai: move set dma data to startup callback

Hi Lars-Peter,

On 7/2/2013 23:25, Lars-Peter Clausen wrote:
> On 07/02/2013 11:04 AM, Bo Shen wrote:
> [...]
>> + dma_params->substream = substream;
>
> Unrelated to this patch, but having a substream field in the dma_params seems
> to be redundant, since you need to know the substream to get the dma_params in
> the first place. Looking at the code it also seems to be unused other than this
> assignment. Maybe you can send a follow up patch to remove it.
>
> [...]
>

Yes, this is redundant. I will remove it in next version patches.

Best Regards,
Bo Shen

2013-07-03 01:34:22

by Bo Shen

[permalink] [raw]
Subject: Re: [alsa-devel] [PATCH 2/2] ASoC: atmel-pcm: use generic dmaengine framework

Hi Lars-Peter,

On 7/2/2013 23:34, Lars-Peter Clausen wrote:
> On 07/02/2013 11:04 AM, Bo Shen wrote:
> [...]
>> -/*--------------------------------------------------------------------------*\
>> - * DMAENGINE operations
>> -\*--------------------------------------------------------------------------*/
>> -static bool filter(struct dma_chan *chan, void *slave)
>> -{
>> - struct at_dma_slave *sl = slave;
>> -
>> - if (sl->dma_dev == chan->device->dev) {
>> - chan->private = sl;
>> - return true;
>> - } else {
>> - return false;
>> - }
>> -}
>
> I'm wondering why is filtering no longer required?

Now this is handled by at_dma_filter in at_hdmac driver. More
information, you can reference: <driver/dma/at_hdmac.c> file

> [...]
>> + slave_config->dst_addr = (dma_addr_t)ssc->phybase + SSC_THR;
> [...]
>> + slave_config->src_addr = (dma_addr_t)ssc->phybase + SSC_RHR;
>
> Change the type of phybase to dma_addr_t

It should be:
slave_config->dst_addr = (dma_addr_t)(ssc->phybase + SSC_THR);
slave_config->src_addr = (dma_addr_t)(ssc->phybase + SSC_RHR);

> [...]
>> }
>>
>> -static int atmel_pcm_dma_prepare(struct snd_pcm_substream *substream)
>> -{
>> - struct snd_soc_pcm_runtime *rtd = substream->private_data;
>> - struct atmel_pcm_dma_params *prtd;
>> -
>> - prtd = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
>> -
>> - ssc_writex(prtd->ssc->regs, SSC_IER, prtd->mask->ssc_error);
>> - ssc_writex(prtd->ssc->regs, SSC_CR, prtd->mask->ssc_enable);
>
> These writes are also completely lost

This will be moved to DAI driver startup callback function.

>> -
>> - return 0;
>> -}
>
> I think it would also be good to get rid of any references to the ssc struct
> from the DMA driver and move them over to the DAI driver.

I will try to implement this in next version patch.

Thanks.

> - Lars
>

Best Regards,
Bo Shen

2013-07-03 05:23:05

by Bo Shen

[permalink] [raw]
Subject: Re: [alsa-devel] [PATCH 1/2] ASoC: atmel_ssc_dai: move set dma data to startup callback

Hi Lars,

On 7/3/2013 09:20, Bo Shen wrote:
> Hi Lars-Peter,
>
> On 7/2/2013 23:25, Lars-Peter Clausen wrote:
>> On 07/02/2013 11:04 AM, Bo Shen wrote:
>> [...]
>>> + dma_params->substream = substream;
>>
>> Unrelated to this patch, but having a substream field in the
>> dma_params seems
>> to be redundant, since you need to know the substream to get the
>> dma_params in
>> the first place. Looking at the code it also seems to be unused other
>> than this
>> assignment. Maybe you can send a follow up patch to remove it.
>>
>> [...]
>>
>
> Yes, this is redundant. I will remove it in next version patches.

Sorry for mistake, this substream parameter need by the interrupt for
PDC transfer, so, I will keep it.

Best Regards,
Bo Shen

2013-07-03 07:33:15

by Lars-Peter Clausen

[permalink] [raw]
Subject: Re: [alsa-devel] [PATCH 2/2] ASoC: atmel-pcm: use generic dmaengine framework

On 07/03/2013 03:33 AM, Bo Shen wrote:
> Hi Lars-Peter,
>
> On 7/2/2013 23:34, Lars-Peter Clausen wrote:
>> On 07/02/2013 11:04 AM, Bo Shen wrote:
>> [...]
>>> -/*--------------------------------------------------------------------------*\
>>> - * DMAENGINE operations
>>> -\*--------------------------------------------------------------------------*/
>>> -static bool filter(struct dma_chan *chan, void *slave)
>>> -{
>>> - struct at_dma_slave *sl = slave;
>>> -
>>> - if (sl->dma_dev == chan->device->dev) {
>>> - chan->private = sl;
>>> - return true;
>>> - } else {
>>> - return false;
>>> - }
>>> -}
>>
>> I'm wondering why is filtering no longer required?
>
> Now this is handled by at_dma_filter in at_hdmac driver. More information, you
> can reference: <driver/dma/at_hdmac.c> file

Ok, so the DMA channel is now supplied via devicetree. This is really a change
that should be listed in the changelog.

>
>> [...]
>>> + slave_config->dst_addr = (dma_addr_t)ssc->phybase + SSC_THR;
>> [...]
>>> + slave_config->src_addr = (dma_addr_t)ssc->phybase + SSC_RHR;
>>
>> Change the type of phybase to dma_addr_t
>
> It should be:
> slave_config->dst_addr = (dma_addr_t)(ssc->phybase + SSC_THR);
> slave_config->src_addr = (dma_addr_t)(ssc->phybase + SSC_RHR);

The type of phybase in the ssc_device struct should be changed from
resource_size_t to dma_addr_t.

2013-07-03 07:58:22

by Bo Shen

[permalink] [raw]
Subject: Re: [alsa-devel] [PATCH 2/2] ASoC: atmel-pcm: use generic dmaengine framework

Hi Lars,

On 7/3/2013 15:36, Lars-Peter Clausen wrote:
>>>> + slave_config->dst_addr = (dma_addr_t)ssc->phybase + SSC_THR;
>>> >>[...]
>>>> >>>+ slave_config->src_addr = (dma_addr_t)ssc->phybase + SSC_RHR;
>>> >>
>>> >>Change the type of phybase to dma_addr_t
>> >
>> >It should be:
>> >slave_config->dst_addr = (dma_addr_t)(ssc->phybase + SSC_THR);
>> >slave_config->src_addr = (dma_addr_t)(ssc->phybase + SSC_RHR);
> The type of phybase in the ssc_device struct should be changed from
> resource_size_t to dma_addr_t.

Actually, the phybase in ssc_device structure is resource_size_t which
used to access the ssc device register.
Here, we use ssc register as dma source address or destination address,
so we convert it to dma_addr_t type. So, not need to change, am I right?

Best Regards,
Bo Shen

2013-07-03 08:04:54

by Lars-Peter Clausen

[permalink] [raw]
Subject: Re: [alsa-devel] [PATCH 2/2] ASoC: atmel-pcm: use generic dmaengine framework

On 07/03/2013 09:57 AM, Bo Shen wrote:
> Hi Lars,
>
> On 7/3/2013 15:36, Lars-Peter Clausen wrote:
>>>>> + slave_config->dst_addr = (dma_addr_t)ssc->phybase + SSC_THR;
>>>> >>[...]
>>>>> >>>+ slave_config->src_addr = (dma_addr_t)ssc->phybase + SSC_RHR;
>>>> >>
>>>> >>Change the type of phybase to dma_addr_t
>>> >
>>> >It should be:
>>> >slave_config->dst_addr = (dma_addr_t)(ssc->phybase + SSC_THR);
>>> >slave_config->src_addr = (dma_addr_t)(ssc->phybase + SSC_RHR);
>> The type of phybase in the ssc_device struct should be changed from
>> resource_size_t to dma_addr_t.
>
> Actually, the phybase in ssc_device structure is resource_size_t which used to
> access the ssc device register.
> Here, we use ssc register as dma source address or destination address, so we
> convert it to dma_addr_t type. So, not need to change, am I right?

Isn't 'regs' used to access the registers? As far as I can see phybase is only
used in the audio DMA driver.

- Lars

2013-07-03 08:15:34

by Bo Shen

[permalink] [raw]
Subject: Re: [alsa-devel] [PATCH 2/2] ASoC: atmel-pcm: use generic dmaengine framework

Hi Lars,

On 7/3/2013 16:08, Lars-Peter Clausen wrote:
> On 07/03/2013 09:57 AM, Bo Shen wrote:
>> Hi Lars,
>>
>> On 7/3/2013 15:36, Lars-Peter Clausen wrote:
>>>>>> + slave_config->dst_addr = (dma_addr_t)ssc->phybase + SSC_THR;
>>>>>>> [...]
>>>>>>>>> + slave_config->src_addr = (dma_addr_t)ssc->phybase + SSC_RHR;
>>>>>>>
>>>>>>> Change the type of phybase to dma_addr_t
>>>>>
>>>>> It should be:
>>>>> slave_config->dst_addr = (dma_addr_t)(ssc->phybase + SSC_THR);
>>>>> slave_config->src_addr = (dma_addr_t)(ssc->phybase + SSC_RHR);
>>> The type of phybase in the ssc_device struct should be changed from
>>> resource_size_t to dma_addr_t.
>>
>> Actually, the phybase in ssc_device structure is resource_size_t which used to
>> access the ssc device register.
>> Here, we use ssc register as dma source address or destination address, so we
>> convert it to dma_addr_t type. So, not need to change, am I right?
>
> Isn't 'regs' used to access the registers? As far as I can see phybase is only
> used in the audio DMA driver.

Thanks for point out this. I will change the phybase type from
resource_size_t to dma_addr_t.

> - Lars
>

Best Regards,
Bo Shen