Skip to content

Commit 58ceb57

Browse files
zonquebroonie
authored andcommitted
ASoC: pxa: pxa-pcm-lib: switch over to snd-soc-dmaengine-pcm
This patch removes the old PXA DMA API usage and switches over to generic functions provided by snd-soc-dmaengine-pcm. More cleanups may be done on top of this, and some function stubs can now be removed completetly. However, the intention here was to keep the transition as small as possible. This was tested on the mioa701 pxa27x board. Signed-off-by: Daniel Mack <zonque@gmail.com> [trivial change from mmp-dma to pxa-dma] Signed-off-by: Robert Jarzmik <robert.jarzmik@free.fr> Signed-off-by: Mark Brown <broonie@kernel.org>
1 parent 5c0e869 commit 58ceb57

8 files changed

Lines changed: 85 additions & 228 deletions

File tree

‎include/sound/pxa2xx-lib.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ extern int __pxa2xx_pcm_hw_free(struct snd_pcm_substream *substream);
1212
extern int pxa2xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd);
1313
extern snd_pcm_uframes_t pxa2xx_pcm_pointer(struct snd_pcm_substream *substream);
1414
extern int __pxa2xx_pcm_prepare(struct snd_pcm_substream *substream);
15-
extern void pxa2xx_pcm_dma_irq(int dma_ch, void *dev_id);
1615
extern int __pxa2xx_pcm_open(struct snd_pcm_substream *substream);
1716
extern int __pxa2xx_pcm_close(struct snd_pcm_substream *substream);
1817
extern int pxa2xx_pcm_mmap(struct snd_pcm_substream *substream,

‎sound/arm/pxa2xx-ac97.c‎

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <linux/module.h>
1616
#include <linux/platform_device.h>
1717
#include <linux/dmaengine.h>
18+
#include <linux/dma/pxa-dma.h>
1819

1920
#include <sound/core.h>
2021
#include <sound/pcm.h>
@@ -43,15 +44,23 @@ static struct snd_ac97_bus_ops pxa2xx_ac97_ops = {
4344
.reset = pxa2xx_ac97_reset,
4445
};
4546

46-
static unsigned long pxa2xx_ac97_pcm_out_req = 12;
47+
static struct pxad_param pxa2xx_ac97_pcm_out_req = {
48+
.prio = PXAD_PRIO_LOWEST,
49+
.drcmr = 12,
50+
};
51+
4752
static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_out = {
4853
.addr = __PREG(PCDR),
4954
.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
5055
.maxburst = 32,
5156
.filter_data = &pxa2xx_ac97_pcm_out_req,
5257
};
5358

54-
static unsigned long pxa2xx_ac97_pcm_in_req = 11;
59+
static struct pxad_param pxa2xx_ac97_pcm_in_req = {
60+
.prio = PXAD_PRIO_LOWEST,
61+
.drcmr = 11,
62+
};
63+
5564
static struct snd_dmaengine_dai_dma_data pxa2xx_ac97_pcm_in = {
5665
.addr = __PREG(PCDR),
5766
.addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,

‎sound/arm/pxa2xx-pcm-lib.c‎

Lines changed: 36 additions & 165 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,14 @@
88
#include <linux/module.h>
99
#include <linux/dma-mapping.h>
1010
#include <linux/dmaengine.h>
11+
#include <linux/dma/pxa-dma.h>
1112

1213
#include <sound/core.h>
1314
#include <sound/pcm.h>
1415
#include <sound/pcm_params.h>
1516
#include <sound/pxa2xx-lib.h>
1617
#include <sound/dmaengine_pcm.h>
1718

18-
#include <mach/dma.h>
19-
2019
#include "pxa2xx-pcm.h"
2120

2221
static const struct snd_pcm_hardware pxa2xx_pcm_hardware = {
@@ -31,188 +30,81 @@ static const struct snd_pcm_hardware pxa2xx_pcm_hardware = {
3130
.period_bytes_min = 32,
3231
.period_bytes_max = 8192 - 32,
3332
.periods_min = 1,
34-
.periods_max = PAGE_SIZE/sizeof(pxa_dma_desc),
33+
.periods_max = 256,
3534
.buffer_bytes_max = 128 * 1024,
3635
.fifo_size = 32,
3736
};
3837

3938
int __pxa2xx_pcm_hw_params(struct snd_pcm_substream *substream,
4039
struct snd_pcm_hw_params *params)
4140
{
42-
struct snd_pcm_runtime *runtime = substream->runtime;
43-
struct pxa2xx_runtime_data *rtd = runtime->private_data;
44-
size_t totsize = params_buffer_bytes(params);
45-
size_t period = params_period_bytes(params);
46-
pxa_dma_desc *dma_desc;
47-
dma_addr_t dma_buff_phys, next_desc_phys;
48-
u32 dcmd = DCMD_INCSRCADDR | DCMD_FLOWTRG;
41+
struct dma_chan *chan = snd_dmaengine_pcm_get_chan(substream);
42+
struct snd_soc_pcm_runtime *rtd = substream->private_data;
43+
struct snd_dmaengine_dai_dma_data *dma_params;
44+
struct dma_slave_config config;
45+
int ret;
4946

50-
/* temporary transition hack */
51-
switch (rtd->params->addr_width) {
52-
case DMA_SLAVE_BUSWIDTH_1_BYTE:
53-
dcmd |= DCMD_WIDTH1;
54-
break;
55-
case DMA_SLAVE_BUSWIDTH_2_BYTES:
56-
dcmd |= DCMD_WIDTH2;
57-
break;
58-
case DMA_SLAVE_BUSWIDTH_4_BYTES:
59-
dcmd |= DCMD_WIDTH4;
60-
break;
61-
default:
62-
/* can't happen */
63-
break;
64-
}
47+
dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
48+
if (!dma_params)
49+
return 0;
6550

66-
switch (rtd->params->maxburst) {
67-
case 8:
68-
dcmd |= DCMD_BURST8;
69-
break;
70-
case 16:
71-
dcmd |= DCMD_BURST16;
72-
break;
73-
case 32:
74-
dcmd |= DCMD_BURST32;
75-
break;
76-
}
51+
ret = snd_hwparams_to_dma_slave_config(substream, params, &config);
52+
if (ret)
53+
return ret;
7754

78-
snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
79-
runtime->dma_bytes = totsize;
55+
snd_dmaengine_pcm_set_config_from_dai_data(substream,
56+
snd_soc_dai_get_dma_data(rtd->cpu_dai, substream),
57+
&config);
8058

81-
dma_desc = rtd->dma_desc_array;
82-
next_desc_phys = rtd->dma_desc_array_phys;
83-
dma_buff_phys = runtime->dma_addr;
84-
do {
85-
next_desc_phys += sizeof(pxa_dma_desc);
86-
dma_desc->ddadr = next_desc_phys;
87-
if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
88-
dma_desc->dsadr = dma_buff_phys;
89-
dma_desc->dtadr = rtd->params->addr;
90-
} else {
91-
dma_desc->dsadr = rtd->params->addr;
92-
dma_desc->dtadr = dma_buff_phys;
93-
}
94-
if (period > totsize)
95-
period = totsize;
96-
dma_desc->dcmd = dcmd | period | DCMD_ENDIRQEN;
97-
dma_desc++;
98-
dma_buff_phys += period;
99-
} while (totsize -= period);
100-
dma_desc[-1].ddadr = rtd->dma_desc_array_phys;
59+
ret = dmaengine_slave_config(chan, &config);
60+
if (ret)
61+
return ret;
62+
63+
snd_pcm_set_runtime_buffer(substream, &substream->dma_buffer);
10164

10265
return 0;
10366
}
10467
EXPORT_SYMBOL(__pxa2xx_pcm_hw_params);
10568

10669
int __pxa2xx_pcm_hw_free(struct snd_pcm_substream *substream)
10770
{
108-
struct pxa2xx_runtime_data *rtd = substream->runtime->private_data;
109-
110-
if (rtd && rtd->params && rtd->params->filter_data) {
111-
unsigned long req = *(unsigned long *) rtd->params->filter_data;
112-
DRCMR(req) = 0;
113-
}
114-
11571
snd_pcm_set_runtime_buffer(substream, NULL);
11672
return 0;
11773
}
11874
EXPORT_SYMBOL(__pxa2xx_pcm_hw_free);
11975

12076
int pxa2xx_pcm_trigger(struct snd_pcm_substream *substream, int cmd)
12177
{
122-
struct pxa2xx_runtime_data *prtd = substream->runtime->private_data;
123-
int ret = 0;
124-
125-
switch (cmd) {
126-
case SNDRV_PCM_TRIGGER_START:
127-
DDADR(prtd->dma_ch) = prtd->dma_desc_array_phys;
128-
DCSR(prtd->dma_ch) = DCSR_RUN;
129-
break;
130-
131-
case SNDRV_PCM_TRIGGER_STOP:
132-
case SNDRV_PCM_TRIGGER_SUSPEND:
133-
case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
134-
DCSR(prtd->dma_ch) &= ~DCSR_RUN;
135-
break;
136-
137-
case SNDRV_PCM_TRIGGER_RESUME:
138-
DCSR(prtd->dma_ch) |= DCSR_RUN;
139-
break;
140-
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
141-
DDADR(prtd->dma_ch) = prtd->dma_desc_array_phys;
142-
DCSR(prtd->dma_ch) |= DCSR_RUN;
143-
break;
144-
145-
default:
146-
ret = -EINVAL;
147-
}
148-
149-
return ret;
78+
return snd_dmaengine_pcm_trigger(substream, cmd);
15079
}
15180
EXPORT_SYMBOL(pxa2xx_pcm_trigger);
15281

15382
snd_pcm_uframes_t
15483
pxa2xx_pcm_pointer(struct snd_pcm_substream *substream)
15584
{
156-
struct snd_pcm_runtime *runtime = substream->runtime;
157-
struct pxa2xx_runtime_data *prtd = runtime->private_data;
158-
159-
dma_addr_t ptr = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
160-
DSADR(prtd->dma_ch) : DTADR(prtd->dma_ch);
161-
snd_pcm_uframes_t x = bytes_to_frames(runtime, ptr - runtime->dma_addr);
162-
163-
if (x == runtime->buffer_size)
164-
x = 0;
165-
return x;
85+
return snd_dmaengine_pcm_pointer(substream);
16686
}
16787
EXPORT_SYMBOL(pxa2xx_pcm_pointer);
16888

16989
int __pxa2xx_pcm_prepare(struct snd_pcm_substream *substream)
17090
{
171-
struct pxa2xx_runtime_data *prtd = substream->runtime->private_data;
172-
unsigned long req;
173-
174-
if (!prtd || !prtd->params)
175-
return 0;
176-
177-
if (prtd->dma_ch == -1)
178-
return -EINVAL;
179-
180-
DCSR(prtd->dma_ch) &= ~DCSR_RUN;
181-
DCSR(prtd->dma_ch) = 0;
182-
DCMD(prtd->dma_ch) = 0;
183-
req = *(unsigned long *) prtd->params->filter_data;
184-
DRCMR(req) = prtd->dma_ch | DRCMR_MAPVLD;
185-
18691
return 0;
18792
}
18893
EXPORT_SYMBOL(__pxa2xx_pcm_prepare);
18994

190-
void pxa2xx_pcm_dma_irq(int dma_ch, void *dev_id)
191-
{
192-
struct snd_pcm_substream *substream = dev_id;
193-
int dcsr;
194-
195-
dcsr = DCSR(dma_ch);
196-
DCSR(dma_ch) = dcsr & ~DCSR_STOPIRQEN;
197-
198-
if (dcsr & DCSR_ENDINTR) {
199-
snd_pcm_period_elapsed(substream);
200-
} else {
201-
printk(KERN_ERR "DMA error on channel %d (DCSR=%#x)\n",
202-
dma_ch, dcsr);
203-
snd_pcm_stop_xrun(substream);
204-
}
205-
}
206-
EXPORT_SYMBOL(pxa2xx_pcm_dma_irq);
207-
20895
int __pxa2xx_pcm_open(struct snd_pcm_substream *substream)
20996
{
97+
struct snd_soc_pcm_runtime *rtd = substream->private_data;
21098
struct snd_pcm_runtime *runtime = substream->runtime;
211-
struct pxa2xx_runtime_data *rtd;
99+
struct snd_dmaengine_dai_dma_data *dma_params;
212100
int ret;
213101

214102
runtime->hw = pxa2xx_pcm_hardware;
215103

104+
dma_params = snd_soc_dai_get_dma_data(rtd->cpu_dai, substream);
105+
if (!dma_params)
106+
return 0;
107+
216108
/*
217109
* For mysterious reasons (and despite what the manual says)
218110
* playback samples are lost if the DMA count is not a multiple
@@ -221,48 +113,27 @@ int __pxa2xx_pcm_open(struct snd_pcm_substream *substream)
221113
ret = snd_pcm_hw_constraint_step(runtime, 0,
222114
SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 32);
223115
if (ret)
224-
goto out;
116+
return ret;
225117

226118
ret = snd_pcm_hw_constraint_step(runtime, 0,
227119
SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 32);
228120
if (ret)
229-
goto out;
121+
return ret;
230122

231123
ret = snd_pcm_hw_constraint_integer(runtime,
232124
SNDRV_PCM_HW_PARAM_PERIODS);
233125
if (ret < 0)
234-
goto out;
235-
236-
ret = -ENOMEM;
237-
rtd = kzalloc(sizeof(*rtd), GFP_KERNEL);
238-
if (!rtd)
239-
goto out;
240-
rtd->dma_desc_array =
241-
dma_alloc_writecombine(substream->pcm->card->dev, PAGE_SIZE,
242-
&rtd->dma_desc_array_phys, GFP_KERNEL);
243-
if (!rtd->dma_desc_array)
244-
goto err1;
126+
return ret;
245127

246-
rtd->dma_ch = -1;
247-
runtime->private_data = rtd;
248-
return 0;
249-
250-
err1:
251-
kfree(rtd);
252-
out:
253-
return ret;
128+
return snd_dmaengine_pcm_open_request_chan(substream,
129+
pxad_filter_fn,
130+
dma_params->filter_data);
254131
}
255132
EXPORT_SYMBOL(__pxa2xx_pcm_open);
256133

257134
int __pxa2xx_pcm_close(struct snd_pcm_substream *substream)
258135
{
259-
struct snd_pcm_runtime *runtime = substream->runtime;
260-
struct pxa2xx_runtime_data *rtd = runtime->private_data;
261-
262-
dma_free_writecombine(substream->pcm->card->dev, PAGE_SIZE,
263-
rtd->dma_desc_array, rtd->dma_desc_array_phys);
264-
kfree(rtd);
265-
return 0;
136+
return snd_dmaengine_pcm_close_release_chan(substream);
266137
}
267138
EXPORT_SYMBOL(__pxa2xx_pcm_close);
268139

‎sound/arm/pxa2xx-pcm.c‎

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,13 @@ static int pxa2xx_pcm_open(struct snd_pcm_substream *substream)
4646

4747
rtd->params = (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) ?
4848
client->playback_params : client->capture_params;
49-
ret = pxa_request_dma("dma", DMA_PRIO_LOW,
50-
pxa2xx_pcm_dma_irq, substream);
51-
if (ret < 0)
52-
goto err2;
53-
rtd->dma_ch = ret;
5449

5550
ret = client->startup(substream);
5651
if (!ret)
57-
goto out;
52+
goto err2;
53+
54+
return 0;
5855

59-
pxa_free_dma(rtd->dma_ch);
6056
err2:
6157
__pxa2xx_pcm_close(substream);
6258
out:
@@ -66,9 +62,7 @@ static int pxa2xx_pcm_open(struct snd_pcm_substream *substream)
6662
static int pxa2xx_pcm_close(struct snd_pcm_substream *substream)
6763
{
6864
struct pxa2xx_pcm_client *client = substream->private_data;
69-
struct pxa2xx_runtime_data *rtd = substream->runtime->private_data;
7065

71-
pxa_free_dma(rtd->dma_ch);
7266
client->shutdown(substream);
7367

7468
return __pxa2xx_pcm_close(substream);

‎sound/arm/pxa2xx-pcm.h‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@
1313
struct pxa2xx_runtime_data {
1414
int dma_ch;
1515
struct snd_dmaengine_dai_dma_data *params;
16-
struct pxa_dma_desc *dma_desc_array;
17-
dma_addr_t dma_desc_array_phys;
1816
};
1917

2018
struct pxa2xx_pcm_client {

0 commit comments

Comments
 (0)