aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>2017-05-09 12:18:36 -0400
committerTakashi Iwai <tiwai@suse.de>2017-05-15 11:07:00 -0400
commit020c5260c2b16469b99c65c37982b4be4c435b56 (patch)
treea4a687f6fff7e7a37f1b43a2d9eea7cc19a104b7
parent2ea659a9ef488125eb46da6eb571de5eae5c43f6 (diff)
ALSA: atmel: Remove AVR32 bits from the driver
AVR32 is gone. Now it's time to clean up the driver by removing leftovers that was used by AVR32 related code. Acked-by: Nicolas Ferre <nicolas.ferre@microchip.com> Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--sound/atmel/Kconfig13
-rw-r--r--sound/atmel/Makefile2
-rw-r--r--sound/atmel/abdac.c610
-rw-r--r--sound/atmel/ac97c.c447
4 files changed, 74 insertions, 998 deletions
diff --git a/sound/atmel/Kconfig b/sound/atmel/Kconfig
index 94de43a096f1..d789cbcb9106 100644
--- a/sound/atmel/Kconfig
+++ b/sound/atmel/Kconfig
@@ -1,18 +1,11 @@
1menu "Atmel devices (AVR32 and AT91)" 1menu "Atmel devices (AT91)"
2 depends on AVR32 || ARCH_AT91 2 depends on ARCH_AT91
3
4config SND_ATMEL_ABDAC
5 tristate "Atmel Audio Bitstream DAC (ABDAC) driver"
6 select SND_PCM
7 depends on DW_DMAC && AVR32
8 help
9 ALSA sound driver for the Atmel Audio Bitstream DAC (ABDAC).
10 3
11config SND_ATMEL_AC97C 4config SND_ATMEL_AC97C
12 tristate "Atmel AC97 Controller (AC97C) driver" 5 tristate "Atmel AC97 Controller (AC97C) driver"
13 select SND_PCM 6 select SND_PCM
14 select SND_AC97_CODEC 7 select SND_AC97_CODEC
15 depends on (DW_DMAC && AVR32) || ARCH_AT91 8 depends on ARCH_AT91
16 help 9 help
17 ALSA sound driver for the Atmel AC97 controller. 10 ALSA sound driver for the Atmel AC97 controller.
18 11
diff --git a/sound/atmel/Makefile b/sound/atmel/Makefile
index 219dcfac6086..d4009d1430ed 100644
--- a/sound/atmel/Makefile
+++ b/sound/atmel/Makefile
@@ -1,5 +1,3 @@
1snd-atmel-abdac-objs := abdac.o
2snd-atmel-ac97c-objs := ac97c.o 1snd-atmel-ac97c-objs := ac97c.o
3 2
4obj-$(CONFIG_SND_ATMEL_ABDAC) += snd-atmel-abdac.o
5obj-$(CONFIG_SND_ATMEL_AC97C) += snd-atmel-ac97c.o 3obj-$(CONFIG_SND_ATMEL_AC97C) += snd-atmel-ac97c.o
diff --git a/sound/atmel/abdac.c b/sound/atmel/abdac.c
deleted file mode 100644
index 558618802000..000000000000
--- a/sound/atmel/abdac.c
+++ /dev/null
@@ -1,610 +0,0 @@
1/*
2 * Driver for the Atmel on-chip Audio Bitstream DAC (ABDAC)
3 *
4 * Copyright (C) 2006-2009 Atmel Corporation
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License version 2 as published by
8 * the Free Software Foundation.
9 */
10#include <linux/clk.h>
11#include <linux/bitmap.h>
12#include <linux/dmaengine.h>
13#include <linux/dma-mapping.h>
14#include <linux/init.h>
15#include <linux/interrupt.h>
16#include <linux/module.h>
17#include <linux/platform_device.h>
18#include <linux/types.h>
19#include <linux/io.h>
20
21#include <sound/core.h>
22#include <sound/initval.h>
23#include <sound/pcm.h>
24#include <sound/pcm_params.h>
25#include <sound/atmel-abdac.h>
26
27#include <linux/platform_data/dma-dw.h>
28#include <linux/dma/dw.h>
29
30/* DAC register offsets */
31#define DAC_DATA 0x0000
32#define DAC_CTRL 0x0008
33#define DAC_INT_MASK 0x000c
34#define DAC_INT_EN 0x0010
35#define DAC_INT_DIS 0x0014
36#define DAC_INT_CLR 0x0018
37#define DAC_INT_STATUS 0x001c
38
39/* Bitfields in CTRL */
40#define DAC_SWAP_OFFSET 30
41#define DAC_SWAP_SIZE 1
42#define DAC_EN_OFFSET 31
43#define DAC_EN_SIZE 1
44
45/* Bitfields in INT_MASK/INT_EN/INT_DIS/INT_STATUS/INT_CLR */
46#define DAC_UNDERRUN_OFFSET 28
47#define DAC_UNDERRUN_SIZE 1
48#define DAC_TX_READY_OFFSET 29
49#define DAC_TX_READY_SIZE 1
50
51/* Bit manipulation macros */
52#define DAC_BIT(name) \
53 (1 << DAC_##name##_OFFSET)
54#define DAC_BF(name, value) \
55 (((value) & ((1 << DAC_##name##_SIZE) - 1)) \
56 << DAC_##name##_OFFSET)
57#define DAC_BFEXT(name, value) \
58 (((value) >> DAC_##name##_OFFSET) \
59 & ((1 << DAC_##name##_SIZE) - 1))
60#define DAC_BFINS(name, value, old) \
61 (((old) & ~(((1 << DAC_##name##_SIZE) - 1) \
62 << DAC_##name##_OFFSET)) \
63 | DAC_BF(name, value))
64
65/* Register access macros */
66#define dac_readl(port, reg) \
67 __raw_readl((port)->regs + DAC_##reg)
68#define dac_writel(port, reg, value) \
69 __raw_writel((value), (port)->regs + DAC_##reg)
70
71/*
72 * ABDAC supports a maximum of 6 different rates from a generic clock. The
73 * generic clock has a power of two divider, which gives 6 steps from 192 kHz
74 * to 5112 Hz.
75 */
76#define MAX_NUM_RATES 6
77/* ALSA seems to use rates between 192000 Hz and 5112 Hz. */
78#define RATE_MAX 192000
79#define RATE_MIN 5112
80
81enum {
82 DMA_READY = 0,
83};
84
85struct atmel_abdac_dma {
86 struct dma_chan *chan;
87 struct dw_cyclic_desc *cdesc;
88};
89
90struct atmel_abdac {
91 struct clk *pclk;
92 struct clk *sample_clk;
93 struct platform_device *pdev;
94 struct atmel_abdac_dma dma;
95
96 struct snd_pcm_hw_constraint_list constraints_rates;
97 struct snd_pcm_substream *substream;
98 struct snd_card *card;
99 struct snd_pcm *pcm;
100
101 void __iomem *regs;
102 unsigned long flags;
103 unsigned int rates[MAX_NUM_RATES];
104 unsigned int rates_num;
105 int irq;
106};
107
108#define get_dac(card) ((struct atmel_abdac *)(card)->private_data)
109
110/* This function is called by the DMA driver. */
111static void atmel_abdac_dma_period_done(void *arg)
112{
113 struct atmel_abdac *dac = arg;
114 snd_pcm_period_elapsed(dac->substream);
115}
116
117static int atmel_abdac_prepare_dma(struct atmel_abdac *dac,
118 struct snd_pcm_substream *substream,
119 enum dma_data_direction direction)
120{
121 struct dma_chan *chan = dac->dma.chan;
122 struct dw_cyclic_desc *cdesc;
123 struct snd_pcm_runtime *runtime = substream->runtime;
124 unsigned long buffer_len, period_len;
125
126 /*
127 * We don't do DMA on "complex" transfers, i.e. with
128 * non-halfword-aligned buffers or lengths.
129 */
130 if (runtime->dma_addr & 1 || runtime->buffer_size & 1) {
131 dev_dbg(&dac->pdev->dev, "too complex transfer\n");
132 return -EINVAL;
133 }
134
135 buffer_len = frames_to_bytes(runtime, runtime->buffer_size);
136 period_len = frames_to_bytes(runtime, runtime->period_size);
137
138 cdesc = dw_dma_cyclic_prep(chan, runtime->dma_addr, buffer_len,
139 period_len, DMA_MEM_TO_DEV);
140 if (IS_ERR(cdesc)) {
141 dev_dbg(&dac->pdev->dev, "could not prepare cyclic DMA\n");
142 return PTR_ERR(cdesc);
143 }
144
145 cdesc->period_callback = atmel_abdac_dma_period_done;
146 cdesc->period_callback_param = dac;
147
148 dac->dma.cdesc = cdesc;
149
150 set_bit(DMA_READY, &dac->flags);
151
152 return 0;
153}
154
155static struct snd_pcm_hardware atmel_abdac_hw = {
156 .info = (SNDRV_PCM_INFO_MMAP
157 | SNDRV_PCM_INFO_MMAP_VALID
158 | SNDRV_PCM_INFO_INTERLEAVED
159 | SNDRV_PCM_INFO_BLOCK_TRANSFER
160 | SNDRV_PCM_INFO_RESUME
161 | SNDRV_PCM_INFO_PAUSE),
162 .formats = (SNDRV_PCM_FMTBIT_S16_BE),
163 .rates = (SNDRV_PCM_RATE_KNOT),
164 .rate_min = RATE_MIN,
165 .rate_max = RATE_MAX,
166 .channels_min = 2,
167 .channels_max = 2,
168 .buffer_bytes_max = 64 * 4096,
169 .period_bytes_min = 4096,
170 .period_bytes_max = 4096,
171 .periods_min = 6,
172 .periods_max = 64,
173};
174
175static int atmel_abdac_open(struct snd_pcm_substream *substream)
176{
177 struct atmel_abdac *dac = snd_pcm_substream_chip(substream);
178
179 dac->substream = substream;
180 atmel_abdac_hw.rate_max = dac->rates[dac->rates_num - 1];
181 atmel_abdac_hw.rate_min = dac->rates[0];
182 substream->runtime->hw = atmel_abdac_hw;
183
184 return snd_pcm_hw_constraint_list(substream->runtime, 0,
185 SNDRV_PCM_HW_PARAM_RATE, &dac->constraints_rates);
186}
187
188static int atmel_abdac_close(struct snd_pcm_substream *substream)
189{
190 struct atmel_abdac *dac = snd_pcm_substream_chip(substream);
191 dac->substream = NULL;
192 return 0;
193}
194
195static int atmel_abdac_hw_params(struct snd_pcm_substream *substream,
196 struct snd_pcm_hw_params *hw_params)
197{
198 struct atmel_abdac *dac = snd_pcm_substream_chip(substream);
199 int retval;
200
201 retval = snd_pcm_lib_malloc_pages(substream,
202 params_buffer_bytes(hw_params));
203 if (retval < 0)
204 return retval;
205 /* snd_pcm_lib_malloc_pages returns 1 if buffer is changed. */
206 if (retval == 1)
207 if (test_and_clear_bit(DMA_READY, &dac->flags))
208 dw_dma_cyclic_free(dac->dma.chan);
209
210 return retval;
211}
212
213static int atmel_abdac_hw_free(struct snd_pcm_substream *substream)
214{
215 struct atmel_abdac *dac = snd_pcm_substream_chip(substream);
216 if (test_and_clear_bit(DMA_READY, &dac->flags))
217 dw_dma_cyclic_free(dac->dma.chan);
218 return snd_pcm_lib_free_pages(substream);
219}
220
221static int atmel_abdac_prepare(struct snd_pcm_substream *substream)
222{
223 struct atmel_abdac *dac = snd_pcm_substream_chip(substream);
224 int retval;
225
226 retval = clk_set_rate(dac->sample_clk, 256 * substream->runtime->rate);
227 if (retval)
228 return retval;
229
230 if (!test_bit(DMA_READY, &dac->flags))
231 retval = atmel_abdac_prepare_dma(dac, substream, DMA_TO_DEVICE);
232
233 return retval;
234}
235
236static int atmel_abdac_trigger(struct snd_pcm_substream *substream, int cmd)
237{
238 struct atmel_abdac *dac = snd_pcm_substream_chip(substream);
239 int retval = 0;
240
241 switch (cmd) {
242 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */
243 case SNDRV_PCM_TRIGGER_RESUME: /* fall through */
244 case SNDRV_PCM_TRIGGER_START:
245 clk_prepare_enable(dac->sample_clk);
246 retval = dw_dma_cyclic_start(dac->dma.chan);
247 if (retval)
248 goto out;
249 dac_writel(dac, CTRL, DAC_BIT(EN));
250 break;
251 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* fall through */
252 case SNDRV_PCM_TRIGGER_SUSPEND: /* fall through */
253 case SNDRV_PCM_TRIGGER_STOP:
254 dw_dma_cyclic_stop(dac->dma.chan);
255 dac_writel(dac, DATA, 0);
256 dac_writel(dac, CTRL, 0);
257 clk_disable_unprepare(dac->sample_clk);
258 break;
259 default:
260 retval = -EINVAL;
261 break;
262 }
263out:
264 return retval;
265}
266
267static snd_pcm_uframes_t
268atmel_abdac_pointer(struct snd_pcm_substream *substream)
269{
270 struct atmel_abdac *dac = snd_pcm_substream_chip(substream);
271 struct snd_pcm_runtime *runtime = substream->runtime;
272 snd_pcm_uframes_t frames;
273 unsigned long bytes;
274
275 bytes = dw_dma_get_src_addr(dac->dma.chan);
276 bytes -= runtime->dma_addr;
277
278 frames = bytes_to_frames(runtime, bytes);
279 if (frames >= runtime->buffer_size)
280 frames -= runtime->buffer_size;
281
282 return frames;
283}
284
285static irqreturn_t abdac_interrupt(int irq, void *dev_id)
286{
287 struct atmel_abdac *dac = dev_id;
288 u32 status;
289
290 status = dac_readl(dac, INT_STATUS);
291 if (status & DAC_BIT(UNDERRUN)) {
292 dev_err(&dac->pdev->dev, "underrun detected\n");
293 dac_writel(dac, INT_CLR, DAC_BIT(UNDERRUN));
294 } else {
295 dev_err(&dac->pdev->dev, "spurious interrupt (status=0x%x)\n",
296 status);
297 dac_writel(dac, INT_CLR, status);
298 }
299
300 return IRQ_HANDLED;
301}
302
303static struct snd_pcm_ops atmel_abdac_ops = {
304 .open = atmel_abdac_open,
305 .close = atmel_abdac_close,
306 .ioctl = snd_pcm_lib_ioctl,
307 .hw_params = atmel_abdac_hw_params,
308 .hw_free = atmel_abdac_hw_free,
309 .prepare = atmel_abdac_prepare,
310 .trigger = atmel_abdac_trigger,
311 .pointer = atmel_abdac_pointer,
312};
313
314static int atmel_abdac_pcm_new(struct atmel_abdac *dac)
315{
316 struct snd_pcm_hardware hw = atmel_abdac_hw;
317 struct snd_pcm *pcm;
318 int retval;
319
320 retval = snd_pcm_new(dac->card, dac->card->shortname,
321 dac->pdev->id, 1, 0, &pcm);
322 if (retval)
323 return retval;
324
325 strcpy(pcm->name, dac->card->shortname);
326 pcm->private_data = dac;
327 pcm->info_flags = 0;
328 dac->pcm = pcm;
329
330 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &atmel_abdac_ops);
331
332 retval = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
333 &dac->pdev->dev, hw.periods_min * hw.period_bytes_min,
334 hw.buffer_bytes_max);
335
336 return retval;
337}
338
339static bool filter(struct dma_chan *chan, void *slave)
340{
341 struct dw_dma_slave *dws = slave;
342
343 if (dws->dma_dev == chan->device->dev) {
344 chan->private = dws;
345 return true;
346 } else
347 return false;
348}
349
350static int set_sample_rates(struct atmel_abdac *dac)
351{
352 long new_rate = RATE_MAX;
353 int retval = -EINVAL;
354 int index = 0;
355
356 /* we start at 192 kHz and work our way down to 5112 Hz */
357 while (new_rate >= RATE_MIN && index < (MAX_NUM_RATES + 1)) {
358 new_rate = clk_round_rate(dac->sample_clk, 256 * new_rate);
359 if (new_rate <= 0)
360 break;
361 /* make sure we are below the ABDAC clock */
362 if (index < MAX_NUM_RATES &&
363 new_rate <= clk_get_rate(dac->pclk)) {
364 dac->rates[index] = new_rate / 256;
365 index++;
366 }
367 /* divide by 256 and then by two to get next rate */
368 new_rate /= 256 * 2;
369 }
370
371 if (index) {
372 int i;
373
374 /* reverse array, smallest go first */
375 for (i = 0; i < (index / 2); i++) {
376 unsigned int tmp = dac->rates[index - 1 - i];
377 dac->rates[index - 1 - i] = dac->rates[i];
378 dac->rates[i] = tmp;
379 }
380
381 dac->constraints_rates.count = index;
382 dac->constraints_rates.list = dac->rates;
383 dac->constraints_rates.mask = 0;
384 dac->rates_num = index;
385
386 retval = 0;
387 }
388
389 return retval;
390}
391
392static int atmel_abdac_probe(struct platform_device *pdev)
393{
394 struct snd_card *card;
395 struct atmel_abdac *dac;
396 struct resource *regs;
397 struct atmel_abdac_pdata *pdata;
398 struct clk *pclk;
399 struct clk *sample_clk;
400 int retval;
401 int irq;
402
403 regs = platform_get_resource(pdev, IORESOURCE_MEM, 0);
404 if (!regs) {
405 dev_dbg(&pdev->dev, "no memory resource\n");
406 return -ENXIO;
407 }
408
409 irq = platform_get_irq(pdev, 0);
410 if (irq < 0) {
411 dev_dbg(&pdev->dev, "could not get IRQ number\n");
412 return irq;
413 }
414
415 pdata = pdev->dev.platform_data;
416 if (!pdata) {
417 dev_dbg(&pdev->dev, "no platform data\n");
418 return -ENXIO;
419 }
420
421 pclk = clk_get(&pdev->dev, "pclk");
422 if (IS_ERR(pclk)) {
423 dev_dbg(&pdev->dev, "no peripheral clock\n");
424 return PTR_ERR(pclk);
425 }
426 sample_clk = clk_get(&pdev->dev, "sample_clk");
427 if (IS_ERR(sample_clk)) {
428 dev_dbg(&pdev->dev, "no sample clock\n");
429 retval = PTR_ERR(sample_clk);
430 goto out_put_pclk;
431 }
432 clk_prepare_enable(pclk);
433
434 retval = snd_card_new(&pdev->dev, SNDRV_DEFAULT_IDX1,
435 SNDRV_DEFAULT_STR1, THIS_MODULE,
436 sizeof(struct atmel_abdac), &card);
437 if (retval) {
438 dev_dbg(&pdev->dev, "could not create sound card device\n");
439 goto out_put_sample_clk;
440 }
441
442 dac = get_dac(card);
443
444 dac->irq = irq;
445 dac->card = card;
446 dac->pclk = pclk;
447 dac->sample_clk = sample_clk;
448 dac->pdev = pdev;
449
450 retval = set_sample_rates(dac);
451 if (retval < 0) {
452 dev_dbg(&pdev->dev, "could not set supported rates\n");
453 goto out_free_card;
454 }
455
456 dac->regs = ioremap(regs->start, resource_size(regs));
457 if (!dac->regs) {
458 dev_dbg(&pdev->dev, "could not remap register memory\n");
459 retval = -ENOMEM;
460 goto out_free_card;
461 }
462
463 /* make sure the DAC is silent and disabled */
464 dac_writel(dac, DATA, 0);
465 dac_writel(dac, CTRL, 0);
466
467 retval = request_irq(irq, abdac_interrupt, 0, "abdac", dac);
468 if (retval) {
469 dev_dbg(&pdev->dev, "could not request irq\n");
470 goto out_unmap_regs;
471 }
472
473 if (pdata->dws.dma_dev) {
474 dma_cap_mask_t mask;
475
476 dma_cap_zero(mask);
477 dma_cap_set(DMA_SLAVE, mask);
478
479 dac->dma.chan = dma_request_channel(mask, filter, &pdata->dws);
480 if (dac->dma.chan) {
481 struct dma_slave_config dma_conf = {
482 .dst_addr = regs->start + DAC_DATA,
483 .dst_addr_width = DMA_SLAVE_BUSWIDTH_4_BYTES,
484 .src_maxburst = 1,
485 .dst_maxburst = 1,
486 .direction = DMA_MEM_TO_DEV,
487 .device_fc = false,
488 };
489
490 dmaengine_slave_config(dac->dma.chan, &dma_conf);
491 }
492 }
493 if (!pdata->dws.dma_dev || !dac->dma.chan) {
494 dev_dbg(&pdev->dev, "DMA not available\n");
495 retval = -ENODEV;
496 goto out_unmap_regs;
497 }
498
499 strcpy(card->driver, "Atmel ABDAC");
500 strcpy(card->shortname, "Atmel ABDAC");
501 sprintf(card->longname, "Atmel Audio Bitstream DAC");
502
503 retval = atmel_abdac_pcm_new(dac);
504 if (retval) {
505 dev_dbg(&pdev->dev, "could not register ABDAC pcm device\n");
506 goto out_release_dma;
507 }
508
509 retval = snd_card_register(card);
510 if (retval) {
511 dev_dbg(&pdev->dev, "could not register sound card\n");
512 goto out_release_dma;
513 }
514
515 platform_set_drvdata(pdev, card);
516
517 dev_info(&pdev->dev, "Atmel ABDAC at 0x%p using %s\n",
518 dac->regs, dev_name(&dac->dma.chan->dev->device));
519
520 return retval;
521
522out_release_dma:
523 dma_release_channel(dac->dma.chan);
524 dac->dma.chan = NULL;
525out_unmap_regs:
526 iounmap(dac->regs);
527out_free_card:
528 snd_card_free(card);
529out_put_sample_clk:
530 clk_put(sample_clk);
531 clk_disable_unprepare(pclk);
532out_put_pclk:
533 clk_put(pclk);
534 return retval;
535}
536
537#ifdef CONFIG_PM_SLEEP
538static int atmel_abdac_suspend(struct device *pdev)
539{
540 struct snd_card *card = dev_get_drvdata(pdev);
541 struct atmel_abdac *dac = card->private_data;
542
543 dw_dma_cyclic_stop(dac->dma.chan);
544 clk_disable_unprepare(dac->sample_clk);
545 clk_disable_unprepare(dac->pclk);
546
547 return 0;
548}
549
550static int atmel_abdac_resume(struct device *pdev)
551{
552 struct snd_card *card = dev_get_drvdata(pdev);
553 struct atmel_abdac *dac = card->private_data;
554
555 clk_prepare_enable(dac->pclk);
556 clk_prepare_enable(dac->sample_clk);
557 if (test_bit(DMA_READY, &dac->flags))
558 dw_dma_cyclic_start(dac->dma.chan);
559
560 return 0;
561}
562
563static SIMPLE_DEV_PM_OPS(atmel_abdac_pm, atmel_abdac_suspend, atmel_abdac_resume);
564#define ATMEL_ABDAC_PM_OPS &atmel_abdac_pm
565#else
566#define ATMEL_ABDAC_PM_OPS NULL
567#endif
568
569static int atmel_abdac_remove(struct platform_device *pdev)
570{
571 struct snd_card *card = platform_get_drvdata(pdev);
572 struct atmel_abdac *dac = get_dac(card);
573
574 clk_put(dac->sample_clk);
575 clk_disable_unprepare(dac->pclk);
576 clk_put(dac->pclk);
577
578 dma_release_channel(dac->dma.chan);
579 dac->dma.chan = NULL;
580 iounmap(dac->regs);
581 free_irq(dac->irq, dac);
582 snd_card_free(card);
583
584 return 0;
585}
586
587static struct platform_driver atmel_abdac_driver = {
588 .remove = atmel_abdac_remove,
589 .driver = {
590 .name = "atmel_abdac",
591 .pm = ATMEL_ABDAC_PM_OPS,
592 },
593};
594
595static int __init atmel_abdac_init(void)
596{
597 return platform_driver_probe(&atmel_abdac_driver,
598 atmel_abdac_probe);
599}
600module_init(atmel_abdac_init);
601
602static void __exit atmel_abdac_exit(void)
603{
604 platform_driver_unregister(&atmel_abdac_driver);
605}
606module_exit(atmel_abdac_exit);
607
608MODULE_LICENSE("GPL");
609MODULE_DESCRIPTION("Driver for Atmel Audio Bitstream DAC (ABDAC)");
610MODULE_AUTHOR("Hans-Christian Egtvedt <egtvedt@samfundet.no>");
diff --git a/sound/atmel/ac97c.c b/sound/atmel/ac97c.c
index 6dad042630d8..65e6948e3995 100644
--- a/sound/atmel/ac97c.c
+++ b/sound/atmel/ac97c.c
@@ -11,8 +11,6 @@
11#include <linux/delay.h> 11#include <linux/delay.h>
12#include <linux/bitmap.h> 12#include <linux/bitmap.h>
13#include <linux/device.h> 13#include <linux/device.h>
14#include <linux/dmaengine.h>
15#include <linux/dma-mapping.h>
16#include <linux/atmel_pdc.h> 14#include <linux/atmel_pdc.h>
17#include <linux/init.h> 15#include <linux/init.h>
18#include <linux/interrupt.h> 16#include <linux/interrupt.h>
@@ -34,36 +32,14 @@
34#include <sound/atmel-ac97c.h> 32#include <sound/atmel-ac97c.h>
35#include <sound/memalloc.h> 33#include <sound/memalloc.h>
36 34
37#include <linux/platform_data/dma-dw.h>
38#include <linux/dma/dw.h>
39
40#ifdef CONFIG_AVR32
41#include <mach/cpu.h>
42#else
43#define cpu_is_at32ap7000() 0
44#endif
45
46#include "ac97c.h" 35#include "ac97c.h"
47 36
48enum {
49 DMA_TX_READY = 0,
50 DMA_RX_READY,
51 DMA_TX_CHAN_PRESENT,
52 DMA_RX_CHAN_PRESENT,
53};
54
55/* Serialize access to opened variable */ 37/* Serialize access to opened variable */
56static DEFINE_MUTEX(opened_mutex); 38static DEFINE_MUTEX(opened_mutex);
57 39
58struct atmel_ac97c_dma {
59 struct dma_chan *rx_chan;
60 struct dma_chan *tx_chan;
61};
62
63struct atmel_ac97c { 40struct atmel_ac97c {
64 struct clk *pclk; 41 struct clk *pclk;
65 struct platform_device *pdev; 42 struct platform_device *pdev;
66 struct atmel_ac97c_dma dma;
67 43
68 struct snd_pcm_substream *playback_substream; 44 struct snd_pcm_substream *playback_substream;
69 struct snd_pcm_substream *capture_substream; 45 struct snd_pcm_substream *capture_substream;
@@ -74,7 +50,6 @@ struct atmel_ac97c {
74 50
75 u64 cur_format; 51 u64 cur_format;
76 unsigned int cur_rate; 52 unsigned int cur_rate;
77 unsigned long flags;
78 int playback_period, capture_period; 53 int playback_period, capture_period;
79 /* Serialize access to opened variable */ 54 /* Serialize access to opened variable */
80 spinlock_t lock; 55 spinlock_t lock;
@@ -91,65 +66,6 @@ struct atmel_ac97c {
91#define ac97c_readl(chip, reg) \ 66#define ac97c_readl(chip, reg) \
92 __raw_readl((chip)->regs + AC97C_##reg) 67 __raw_readl((chip)->regs + AC97C_##reg)
93 68
94/* This function is called by the DMA driver. */
95static void atmel_ac97c_dma_playback_period_done(void *arg)
96{
97 struct atmel_ac97c *chip = arg;
98 snd_pcm_period_elapsed(chip->playback_substream);
99}
100
101static void atmel_ac97c_dma_capture_period_done(void *arg)
102{
103 struct atmel_ac97c *chip = arg;
104 snd_pcm_period_elapsed(chip->capture_substream);
105}
106
107static int atmel_ac97c_prepare_dma(struct atmel_ac97c *chip,
108 struct snd_pcm_substream *substream,
109 enum dma_transfer_direction direction)
110{
111 struct dma_chan *chan;
112 struct dw_cyclic_desc *cdesc;
113 struct snd_pcm_runtime *runtime = substream->runtime;
114 unsigned long buffer_len, period_len;
115
116 /*
117 * We don't do DMA on "complex" transfers, i.e. with
118 * non-halfword-aligned buffers or lengths.
119 */
120 if (runtime->dma_addr & 1 || runtime->buffer_size & 1) {
121 dev_dbg(&chip->pdev->dev, "too complex transfer\n");
122 return -EINVAL;
123 }
124
125 if (direction == DMA_MEM_TO_DEV)
126 chan = chip->dma.tx_chan;
127 else
128 chan = chip->dma.rx_chan;
129
130 buffer_len = frames_to_bytes(runtime, runtime->buffer_size);
131 period_len = frames_to_bytes(runtime, runtime->period_size);
132
133 cdesc = dw_dma_cyclic_prep(chan, runtime->dma_addr, buffer_len,
134 period_len, direction);
135 if (IS_ERR(cdesc)) {
136 dev_dbg(&chip->pdev->dev, "could not prepare cyclic DMA\n");
137 return PTR_ERR(cdesc);
138 }
139
140 if (direction == DMA_MEM_TO_DEV) {
141 cdesc->period_callback = atmel_ac97c_dma_playback_period_done;
142 set_bit(DMA_TX_READY, &chip->flags);
143 } else {
144 cdesc->period_callback = atmel_ac97c_dma_capture_period_done;
145 set_bit(DMA_RX_READY, &chip->flags);
146 }
147
148 cdesc->period_callback_param = chip;
149
150 return 0;
151}
152
153static struct snd_pcm_hardware atmel_ac97c_hw = { 69static struct snd_pcm_hardware atmel_ac97c_hw = {
154 .info = (SNDRV_PCM_INFO_MMAP 70 .info = (SNDRV_PCM_INFO_MMAP
155 | SNDRV_PCM_INFO_MMAP_VALID 71 | SNDRV_PCM_INFO_MMAP_VALID
@@ -254,13 +170,7 @@ static int atmel_ac97c_playback_hw_params(struct snd_pcm_substream *substream,
254 params_buffer_bytes(hw_params)); 170 params_buffer_bytes(hw_params));
255 if (retval < 0) 171 if (retval < 0)
256 return retval; 172 return retval;
257 /* snd_pcm_lib_malloc_pages returns 1 if buffer is changed. */ 173
258 if (cpu_is_at32ap7000()) {
259 /* snd_pcm_lib_malloc_pages returns 1 if buffer is changed. */
260 if (retval == 1)
261 if (test_and_clear_bit(DMA_TX_READY, &chip->flags))
262 dw_dma_cyclic_free(chip->dma.tx_chan);
263 }
264 /* Set restrictions to params. */ 174 /* Set restrictions to params. */
265 mutex_lock(&opened_mutex); 175 mutex_lock(&opened_mutex);
266 chip->cur_rate = params_rate(hw_params); 176 chip->cur_rate = params_rate(hw_params);
@@ -280,10 +190,6 @@ static int atmel_ac97c_capture_hw_params(struct snd_pcm_substream *substream,
280 params_buffer_bytes(hw_params)); 190 params_buffer_bytes(hw_params));
281 if (retval < 0) 191 if (retval < 0)
282 return retval; 192 return retval;
283 /* snd_pcm_lib_malloc_pages returns 1 if buffer is changed. */
284 if (cpu_is_at32ap7000() && retval == 1)
285 if (test_and_clear_bit(DMA_RX_READY, &chip->flags))
286 dw_dma_cyclic_free(chip->dma.rx_chan);
287 193
288 /* Set restrictions to params. */ 194 /* Set restrictions to params. */
289 mutex_lock(&opened_mutex); 195 mutex_lock(&opened_mutex);
@@ -294,26 +200,6 @@ static int atmel_ac97c_capture_hw_params(struct snd_pcm_substream *substream,
294 return retval; 200 return retval;
295} 201}
296 202
297static int atmel_ac97c_playback_hw_free(struct snd_pcm_substream *substream)
298{
299 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
300 if (cpu_is_at32ap7000()) {
301 if (test_and_clear_bit(DMA_TX_READY, &chip->flags))
302 dw_dma_cyclic_free(chip->dma.tx_chan);
303 }
304 return snd_pcm_lib_free_pages(substream);
305}
306
307static int atmel_ac97c_capture_hw_free(struct snd_pcm_substream *substream)
308{
309 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
310 if (cpu_is_at32ap7000()) {
311 if (test_and_clear_bit(DMA_RX_READY, &chip->flags))
312 dw_dma_cyclic_free(chip->dma.rx_chan);
313 }
314 return snd_pcm_lib_free_pages(substream);
315}
316
317static int atmel_ac97c_playback_prepare(struct snd_pcm_substream *substream) 203static int atmel_ac97c_playback_prepare(struct snd_pcm_substream *substream)
318{ 204{
319 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream); 205 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
@@ -349,8 +235,6 @@ static int atmel_ac97c_playback_prepare(struct snd_pcm_substream *substream)
349 235
350 switch (runtime->format) { 236 switch (runtime->format) {
351 case SNDRV_PCM_FORMAT_S16_LE: 237 case SNDRV_PCM_FORMAT_S16_LE:
352 if (cpu_is_at32ap7000())
353 word |= AC97C_CMR_CEM_LITTLE;
354 break; 238 break;
355 case SNDRV_PCM_FORMAT_S16_BE: /* fall through */ 239 case SNDRV_PCM_FORMAT_S16_BE: /* fall through */
356 word &= ~(AC97C_CMR_CEM_LITTLE); 240 word &= ~(AC97C_CMR_CEM_LITTLE);
@@ -389,18 +273,11 @@ static int atmel_ac97c_playback_prepare(struct snd_pcm_substream *substream)
389 dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n", 273 dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n",
390 runtime->rate); 274 runtime->rate);
391 275
392 if (cpu_is_at32ap7000()) { 276 /* Initialize and start the PDC */
393 if (!test_bit(DMA_TX_READY, &chip->flags)) 277 writel(runtime->dma_addr, chip->regs + ATMEL_PDC_TPR);
394 retval = atmel_ac97c_prepare_dma(chip, substream, 278 writel(block_size / 2, chip->regs + ATMEL_PDC_TCR);
395 DMA_MEM_TO_DEV); 279 writel(runtime->dma_addr + block_size, chip->regs + ATMEL_PDC_TNPR);
396 } else { 280 writel(block_size / 2, chip->regs + ATMEL_PDC_TNCR);
397 /* Initialize and start the PDC */
398 writel(runtime->dma_addr, chip->regs + ATMEL_PDC_TPR);
399 writel(block_size / 2, chip->regs + ATMEL_PDC_TCR);
400 writel(runtime->dma_addr + block_size,
401 chip->regs + ATMEL_PDC_TNPR);
402 writel(block_size / 2, chip->regs + ATMEL_PDC_TNCR);
403 }
404 281
405 return retval; 282 return retval;
406} 283}
@@ -440,8 +317,6 @@ static int atmel_ac97c_capture_prepare(struct snd_pcm_substream *substream)
440 317
441 switch (runtime->format) { 318 switch (runtime->format) {
442 case SNDRV_PCM_FORMAT_S16_LE: 319 case SNDRV_PCM_FORMAT_S16_LE:
443 if (cpu_is_at32ap7000())
444 word |= AC97C_CMR_CEM_LITTLE;
445 break; 320 break;
446 case SNDRV_PCM_FORMAT_S16_BE: /* fall through */ 321 case SNDRV_PCM_FORMAT_S16_BE: /* fall through */
447 word &= ~(AC97C_CMR_CEM_LITTLE); 322 word &= ~(AC97C_CMR_CEM_LITTLE);
@@ -480,18 +355,11 @@ static int atmel_ac97c_capture_prepare(struct snd_pcm_substream *substream)
480 dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n", 355 dev_dbg(&chip->pdev->dev, "could not set rate %d Hz\n",
481 runtime->rate); 356 runtime->rate);
482 357
483 if (cpu_is_at32ap7000()) { 358 /* Initialize and start the PDC */
484 if (!test_bit(DMA_RX_READY, &chip->flags)) 359 writel(runtime->dma_addr, chip->regs + ATMEL_PDC_RPR);
485 retval = atmel_ac97c_prepare_dma(chip, substream, 360 writel(block_size / 2, chip->regs + ATMEL_PDC_RCR);
486 DMA_DEV_TO_MEM); 361 writel(runtime->dma_addr + block_size, chip->regs + ATMEL_PDC_RNPR);
487 } else { 362 writel(block_size / 2, chip->regs + ATMEL_PDC_RNCR);
488 /* Initialize and start the PDC */
489 writel(runtime->dma_addr, chip->regs + ATMEL_PDC_RPR);
490 writel(block_size / 2, chip->regs + ATMEL_PDC_RCR);
491 writel(runtime->dma_addr + block_size,
492 chip->regs + ATMEL_PDC_RNPR);
493 writel(block_size / 2, chip->regs + ATMEL_PDC_RNCR);
494 }
495 363
496 return retval; 364 return retval;
497} 365}
@@ -501,7 +369,6 @@ atmel_ac97c_playback_trigger(struct snd_pcm_substream *substream, int cmd)
501{ 369{
502 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream); 370 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
503 unsigned long camr, ptcr = 0; 371 unsigned long camr, ptcr = 0;
504 int retval = 0;
505 372
506 camr = ac97c_readl(chip, CAMR); 373 camr = ac97c_readl(chip, CAMR);
507 374
@@ -509,35 +376,23 @@ atmel_ac97c_playback_trigger(struct snd_pcm_substream *substream, int cmd)
509 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */ 376 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */
510 case SNDRV_PCM_TRIGGER_RESUME: /* fall through */ 377 case SNDRV_PCM_TRIGGER_RESUME: /* fall through */
511 case SNDRV_PCM_TRIGGER_START: 378 case SNDRV_PCM_TRIGGER_START:
512 if (cpu_is_at32ap7000()) { 379 ptcr = ATMEL_PDC_TXTEN;
513 retval = dw_dma_cyclic_start(chip->dma.tx_chan);
514 if (retval)
515 goto out;
516 } else {
517 ptcr = ATMEL_PDC_TXTEN;
518 }
519 camr |= AC97C_CMR_CENA | AC97C_CSR_ENDTX; 380 camr |= AC97C_CMR_CENA | AC97C_CSR_ENDTX;
520 break; 381 break;
521 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* fall through */ 382 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* fall through */
522 case SNDRV_PCM_TRIGGER_SUSPEND: /* fall through */ 383 case SNDRV_PCM_TRIGGER_SUSPEND: /* fall through */
523 case SNDRV_PCM_TRIGGER_STOP: 384 case SNDRV_PCM_TRIGGER_STOP:
524 if (cpu_is_at32ap7000()) 385 ptcr |= ATMEL_PDC_TXTDIS;
525 dw_dma_cyclic_stop(chip->dma.tx_chan);
526 else
527 ptcr |= ATMEL_PDC_TXTDIS;
528 if (chip->opened <= 1) 386 if (chip->opened <= 1)
529 camr &= ~AC97C_CMR_CENA; 387 camr &= ~AC97C_CMR_CENA;
530 break; 388 break;
531 default: 389 default:
532 retval = -EINVAL; 390 return -EINVAL;
533 goto out;
534 } 391 }
535 392
536 ac97c_writel(chip, CAMR, camr); 393 ac97c_writel(chip, CAMR, camr);
537 if (!cpu_is_at32ap7000()) 394 writel(ptcr, chip->regs + ATMEL_PDC_PTCR);
538 writel(ptcr, chip->regs + ATMEL_PDC_PTCR); 395 return 0;
539out:
540 return retval;
541} 396}
542 397
543static int 398static int
@@ -545,7 +400,6 @@ atmel_ac97c_capture_trigger(struct snd_pcm_substream *substream, int cmd)
545{ 400{
546 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream); 401 struct atmel_ac97c *chip = snd_pcm_substream_chip(substream);
547 unsigned long camr, ptcr = 0; 402 unsigned long camr, ptcr = 0;
548 int retval = 0;
549 403
550 camr = ac97c_readl(chip, CAMR); 404 camr = ac97c_readl(chip, CAMR);
551 ptcr = readl(chip->regs + ATMEL_PDC_PTSR); 405 ptcr = readl(chip->regs + ATMEL_PDC_PTSR);
@@ -554,35 +408,23 @@ atmel_ac97c_capture_trigger(struct snd_pcm_substream *substream, int cmd)
554 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */ 408 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: /* fall through */
555 case SNDRV_PCM_TRIGGER_RESUME: /* fall through */ 409 case SNDRV_PCM_TRIGGER_RESUME: /* fall through */
556 case SNDRV_PCM_TRIGGER_START: 410 case SNDRV_PCM_TRIGGER_START:
557 if (cpu_is_at32ap7000()) { 411 ptcr = ATMEL_PDC_RXTEN;
558 retval = dw_dma_cyclic_start(chip->dma.rx_chan);
559 if (retval)
560 goto out;
561 } else {
562 ptcr = ATMEL_PDC_RXTEN;
563 }
564 camr |= AC97C_CMR_CENA | AC97C_CSR_ENDRX; 412 camr |= AC97C_CMR_CENA | AC97C_CSR_ENDRX;
565 break; 413 break;
566 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* fall through */ 414 case SNDRV_PCM_TRIGGER_PAUSE_PUSH: /* fall through */
567 case SNDRV_PCM_TRIGGER_SUSPEND: /* fall through */ 415 case SNDRV_PCM_TRIGGER_SUSPEND: /* fall through */
568 case SNDRV_PCM_TRIGGER_STOP: 416 case SNDRV_PCM_TRIGGER_STOP:
569 if (cpu_is_at32ap7000()) 417 ptcr |= ATMEL_PDC_RXTDIS;
570 dw_dma_cyclic_stop(chip->dma.rx_chan);
571 else
572 ptcr |= (ATMEL_PDC_RXTDIS);
573 if (chip->opened <= 1) 418 if (chip->opened <= 1)
574 camr &= ~AC97C_CMR_CENA; 419 camr &= ~AC97C_CMR_CENA;
575 break; 420 break;
576 default: 421 default:
577 retval = -EINVAL; 422 return -EINVAL;
578 break;
579 } 423 }
580 424
581 ac97c_writel(chip, CAMR, camr); 425 ac97c_writel(chip, CAMR, camr);
582 if (!cpu_is_at32ap7000()) 426 writel(ptcr, chip->regs + ATMEL_PDC_PTCR);
583 writel(ptcr, chip->regs + ATMEL_PDC_PTCR); 427 return 0;
584out:
585 return retval;
586} 428}
587 429
588static snd_pcm_uframes_t 430static snd_pcm_uframes_t
@@ -593,10 +435,7 @@ atmel_ac97c_playback_pointer(struct snd_pcm_substream *substream)
593 snd_pcm_uframes_t frames; 435 snd_pcm_uframes_t frames;
594 unsigned long bytes; 436 unsigned long bytes;
595 437
596 if (cpu_is_at32ap7000()) 438 bytes = readl(chip->regs + ATMEL_PDC_TPR);
597 bytes = dw_dma_get_src_addr(chip->dma.tx_chan);
598 else
599 bytes = readl(chip->regs + ATMEL_PDC_TPR);
600 bytes -= runtime->dma_addr; 439 bytes -= runtime->dma_addr;
601 440
602 frames = bytes_to_frames(runtime, bytes); 441 frames = bytes_to_frames(runtime, bytes);
@@ -613,10 +452,7 @@ atmel_ac97c_capture_pointer(struct snd_pcm_substream *substream)
613 snd_pcm_uframes_t frames; 452 snd_pcm_uframes_t frames;
614 unsigned long bytes; 453 unsigned long bytes;
615 454
616 if (cpu_is_at32ap7000()) 455 bytes = readl(chip->regs + ATMEL_PDC_RPR);
617 bytes = dw_dma_get_dst_addr(chip->dma.rx_chan);
618 else
619 bytes = readl(chip->regs + ATMEL_PDC_RPR);
620 bytes -= runtime->dma_addr; 456 bytes -= runtime->dma_addr;
621 457
622 frames = bytes_to_frames(runtime, bytes); 458 frames = bytes_to_frames(runtime, bytes);
@@ -630,7 +466,7 @@ static struct snd_pcm_ops atmel_ac97_playback_ops = {
630 .close = atmel_ac97c_playback_close, 466 .close = atmel_ac97c_playback_close,
631 .ioctl = snd_pcm_lib_ioctl, 467 .ioctl = snd_pcm_lib_ioctl,
632 .hw_params = atmel_ac97c_playback_hw_params, 468 .hw_params = atmel_ac97c_playback_hw_params,
633 .hw_free = atmel_ac97c_playback_hw_free, 469 .hw_free = snd_pcm_lib_free_pages,
634 .prepare = atmel_ac97c_playback_prepare, 470 .prepare = atmel_ac97c_playback_prepare,
635 .trigger = atmel_ac97c_playback_trigger, 471 .trigger = atmel_ac97c_playback_trigger,
636 .pointer = atmel_ac97c_playback_pointer, 472 .pointer = atmel_ac97c_playback_pointer,
@@ -641,7 +477,7 @@ static struct snd_pcm_ops atmel_ac97_capture_ops = {
641 .close = atmel_ac97c_capture_close, 477 .close = atmel_ac97c_capture_close,
642 .ioctl = snd_pcm_lib_ioctl, 478 .ioctl = snd_pcm_lib_ioctl,
643 .hw_params = atmel_ac97c_capture_hw_params, 479 .hw_params = atmel_ac97c_capture_hw_params,
644 .hw_free = atmel_ac97c_capture_hw_free, 480 .hw_free = snd_pcm_lib_free_pages,
645 .prepare = atmel_ac97c_capture_prepare, 481 .prepare = atmel_ac97c_capture_prepare,
646 .trigger = atmel_ac97c_capture_trigger, 482 .trigger = atmel_ac97c_capture_trigger,
647 .pointer = atmel_ac97c_capture_pointer, 483 .pointer = atmel_ac97c_capture_pointer,
@@ -666,49 +502,40 @@ static irqreturn_t atmel_ac97c_interrupt(int irq, void *dev)
666 casr & AC97C_CSR_TXEMPTY ? " TXEMPTY" : "", 502 casr & AC97C_CSR_TXEMPTY ? " TXEMPTY" : "",
667 casr & AC97C_CSR_TXRDY ? " TXRDY" : "", 503 casr & AC97C_CSR_TXRDY ? " TXRDY" : "",
668 !casr ? " NONE" : ""); 504 !casr ? " NONE" : "");
669 if (!cpu_is_at32ap7000()) { 505 if ((casr & camr) & AC97C_CSR_ENDTX) {
670 if ((casr & camr) & AC97C_CSR_ENDTX) { 506 runtime = chip->playback_substream->runtime;
671 runtime = chip->playback_substream->runtime; 507 block_size = frames_to_bytes(runtime, runtime->period_size);
672 block_size = frames_to_bytes(runtime, 508 chip->playback_period++;
673 runtime->period_size); 509
674 chip->playback_period++; 510 if (chip->playback_period == runtime->periods)
675 511 chip->playback_period = 0;
676 if (chip->playback_period == runtime->periods) 512 next_period = chip->playback_period + 1;
677 chip->playback_period = 0; 513 if (next_period == runtime->periods)
678 next_period = chip->playback_period + 1; 514 next_period = 0;
679 if (next_period == runtime->periods) 515
680 next_period = 0; 516 offset = block_size * next_period;
681 517
682 offset = block_size * next_period; 518 writel(runtime->dma_addr + offset, chip->regs + ATMEL_PDC_TNPR);
683 519 writel(block_size / 2, chip->regs + ATMEL_PDC_TNCR);
684 writel(runtime->dma_addr + offset, 520
685 chip->regs + ATMEL_PDC_TNPR); 521 snd_pcm_period_elapsed(chip->playback_substream);
686 writel(block_size / 2, 522 }
687 chip->regs + ATMEL_PDC_TNCR); 523 if ((casr & camr) & AC97C_CSR_ENDRX) {
688 524 runtime = chip->capture_substream->runtime;
689 snd_pcm_period_elapsed( 525 block_size = frames_to_bytes(runtime, runtime->period_size);
690 chip->playback_substream); 526 chip->capture_period++;
691 } 527
692 if ((casr & camr) & AC97C_CSR_ENDRX) { 528 if (chip->capture_period == runtime->periods)
693 runtime = chip->capture_substream->runtime; 529 chip->capture_period = 0;
694 block_size = frames_to_bytes(runtime, 530 next_period = chip->capture_period + 1;
695 runtime->period_size); 531 if (next_period == runtime->periods)
696 chip->capture_period++; 532 next_period = 0;
697 533
698 if (chip->capture_period == runtime->periods) 534 offset = block_size * next_period;
699 chip->capture_period = 0; 535
700 next_period = chip->capture_period + 1; 536 writel(runtime->dma_addr + offset, chip->regs + ATMEL_PDC_RNPR);
701 if (next_period == runtime->periods) 537 writel(block_size / 2, chip->regs + ATMEL_PDC_RNCR);
702 next_period = 0; 538 snd_pcm_period_elapsed(chip->capture_substream);
703
704 offset = block_size * next_period;
705
706 writel(runtime->dma_addr + offset,
707 chip->regs + ATMEL_PDC_RNPR);
708 writel(block_size / 2,
709 chip->regs + ATMEL_PDC_RNCR);
710 snd_pcm_period_elapsed(chip->capture_substream);
711 }
712 } 539 }
713 retval = IRQ_HANDLED; 540 retval = IRQ_HANDLED;
714 } 541 }
@@ -763,29 +590,20 @@ static int atmel_ac97c_pcm_new(struct atmel_ac97c *chip)
763{ 590{
764 struct snd_pcm *pcm; 591 struct snd_pcm *pcm;
765 struct snd_pcm_hardware hw = atmel_ac97c_hw; 592 struct snd_pcm_hardware hw = atmel_ac97c_hw;
766 int capture, playback, retval, err; 593 int retval;
767 594
768 capture = test_bit(DMA_RX_CHAN_PRESENT, &chip->flags); 595 retval = snd_ac97_pcm_assign(chip->ac97_bus,
769 playback = test_bit(DMA_TX_CHAN_PRESENT, &chip->flags); 596 ARRAY_SIZE(at91_ac97_pcm_defs),
597 at91_ac97_pcm_defs);
598 if (retval)
599 return retval;
770 600
771 if (!cpu_is_at32ap7000()) { 601 retval = snd_pcm_new(chip->card, chip->card->shortname, 0, 1, 1, &pcm);
772 err = snd_ac97_pcm_assign(chip->ac97_bus,
773 ARRAY_SIZE(at91_ac97_pcm_defs),
774 at91_ac97_pcm_defs);
775 if (err)
776 return err;
777 }
778 retval = snd_pcm_new(chip->card, chip->card->shortname,
779 0, playback, capture, &pcm);
780 if (retval) 602 if (retval)
781 return retval; 603 return retval;
782 604
783 if (capture) 605 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, &atmel_ac97_capture_ops);
784 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_CAPTURE, 606 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK, &atmel_ac97_playback_ops);
785 &atmel_ac97_capture_ops);
786 if (playback)
787 snd_pcm_set_ops(pcm, SNDRV_PCM_STREAM_PLAYBACK,
788 &atmel_ac97_playback_ops);
789 607
790 retval = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV, 608 retval = snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV,
791 &chip->pdev->dev, hw.periods_min * hw.period_bytes_min, 609 &chip->pdev->dev, hw.periods_min * hw.period_bytes_min,
@@ -875,17 +693,6 @@ timed_out:
875 return 0xffff; 693 return 0xffff;
876} 694}
877 695
878static bool filter(struct dma_chan *chan, void *slave)
879{
880 struct dw_dma_slave *dws = slave;
881
882 if (dws->dma_dev == chan->device->dev) {
883 chan->private = dws;
884 return true;
885 } else
886 return false;
887}
888
889static void atmel_ac97c_reset(struct atmel_ac97c *chip) 696static void atmel_ac97c_reset(struct atmel_ac97c *chip)
890{ 697{
891 ac97c_writel(chip, MR, 0); 698 ac97c_writel(chip, MR, 0);
@@ -971,12 +778,7 @@ static int atmel_ac97c_probe(struct platform_device *pdev)
971 return -ENXIO; 778 return -ENXIO;
972 } 779 }
973 780
974 if (cpu_is_at32ap7000()) { 781 pclk = clk_get(&pdev->dev, "ac97_clk");
975 pclk = clk_get(&pdev->dev, "pclk");
976 } else {
977 pclk = clk_get(&pdev->dev, "ac97_clk");
978 }
979
980 if (IS_ERR(pclk)) { 782 if (IS_ERR(pclk)) {
981 dev_dbg(&pdev->dev, "no peripheral clock\n"); 783 dev_dbg(&pdev->dev, "no peripheral clock\n");
982 return PTR_ERR(pclk); 784 return PTR_ERR(pclk);
@@ -1047,88 +849,16 @@ static int atmel_ac97c_probe(struct platform_device *pdev)
1047 goto err_ac97_bus; 849 goto err_ac97_bus;
1048 } 850 }
1049 851
1050 if (cpu_is_at32ap7000()) {
1051 if (pdata->rx_dws.dma_dev) {
1052 dma_cap_mask_t mask;
1053
1054 dma_cap_zero(mask);
1055 dma_cap_set(DMA_SLAVE, mask);
1056
1057 chip->dma.rx_chan = dma_request_channel(mask, filter,
1058 &pdata->rx_dws);
1059 if (chip->dma.rx_chan) {
1060 struct dma_slave_config dma_conf = {
1061 .src_addr = regs->start + AC97C_CARHR +
1062 2,
1063 .src_addr_width =
1064 DMA_SLAVE_BUSWIDTH_2_BYTES,
1065 .src_maxburst = 1,
1066 .dst_maxburst = 1,
1067 .direction = DMA_DEV_TO_MEM,
1068 .device_fc = false,
1069 };
1070
1071 dmaengine_slave_config(chip->dma.rx_chan,
1072 &dma_conf);
1073 }
1074
1075 dev_info(&chip->pdev->dev, "using %s for DMA RX\n",
1076 dev_name(&chip->dma.rx_chan->dev->device));
1077 set_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
1078 }
1079
1080 if (pdata->tx_dws.dma_dev) {
1081 dma_cap_mask_t mask;
1082
1083 dma_cap_zero(mask);
1084 dma_cap_set(DMA_SLAVE, mask);
1085
1086 chip->dma.tx_chan = dma_request_channel(mask, filter,
1087 &pdata->tx_dws);
1088 if (chip->dma.tx_chan) {
1089 struct dma_slave_config dma_conf = {
1090 .dst_addr = regs->start + AC97C_CATHR +
1091 2,
1092 .dst_addr_width =
1093 DMA_SLAVE_BUSWIDTH_2_BYTES,
1094 .src_maxburst = 1,
1095 .dst_maxburst = 1,
1096 .direction = DMA_MEM_TO_DEV,
1097 .device_fc = false,
1098 };
1099
1100 dmaengine_slave_config(chip->dma.tx_chan,
1101 &dma_conf);
1102 }
1103
1104 dev_info(&chip->pdev->dev, "using %s for DMA TX\n",
1105 dev_name(&chip->dma.tx_chan->dev->device));
1106 set_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
1107 }
1108
1109 if (!test_bit(DMA_RX_CHAN_PRESENT, &chip->flags) &&
1110 !test_bit(DMA_TX_CHAN_PRESENT, &chip->flags)) {
1111 dev_dbg(&pdev->dev, "DMA not available\n");
1112 retval = -ENODEV;
1113 goto err_dma;
1114 }
1115 } else {
1116 /* Just pretend that we have DMA channel(for at91 i is actually
1117 * the PDC) */
1118 set_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
1119 set_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
1120 }
1121
1122 retval = atmel_ac97c_pcm_new(chip); 852 retval = atmel_ac97c_pcm_new(chip);
1123 if (retval) { 853 if (retval) {
1124 dev_dbg(&pdev->dev, "could not register ac97 pcm device\n"); 854 dev_dbg(&pdev->dev, "could not register ac97 pcm device\n");
1125 goto err_dma; 855 goto err_ac97_bus;
1126 } 856 }
1127 857
1128 retval = snd_card_register(card); 858 retval = snd_card_register(card);
1129 if (retval) { 859 if (retval) {
1130 dev_dbg(&pdev->dev, "could not register sound card\n"); 860 dev_dbg(&pdev->dev, "could not register sound card\n");
1131 goto err_dma; 861 goto err_ac97_bus;
1132 } 862 }
1133 863
1134 platform_set_drvdata(pdev, card); 864 platform_set_drvdata(pdev, card);
@@ -1138,17 +868,6 @@ static int atmel_ac97c_probe(struct platform_device *pdev)
1138 868
1139 return 0; 869 return 0;
1140 870
1141err_dma:
1142 if (cpu_is_at32ap7000()) {
1143 if (test_bit(DMA_RX_CHAN_PRESENT, &chip->flags))
1144 dma_release_channel(chip->dma.rx_chan);
1145 if (test_bit(DMA_TX_CHAN_PRESENT, &chip->flags))
1146 dma_release_channel(chip->dma.tx_chan);
1147 clear_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
1148 clear_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
1149 chip->dma.rx_chan = NULL;
1150 chip->dma.tx_chan = NULL;
1151 }
1152err_ac97_bus: 871err_ac97_bus:
1153 if (gpio_is_valid(chip->reset_pin)) 872 if (gpio_is_valid(chip->reset_pin))
1154 gpio_free(chip->reset_pin); 873 gpio_free(chip->reset_pin);
@@ -1170,14 +889,7 @@ static int atmel_ac97c_suspend(struct device *pdev)
1170 struct snd_card *card = dev_get_drvdata(pdev); 889 struct snd_card *card = dev_get_drvdata(pdev);
1171 struct atmel_ac97c *chip = card->private_data; 890 struct atmel_ac97c *chip = card->private_data;
1172 891
1173 if (cpu_is_at32ap7000()) {
1174 if (test_bit(DMA_RX_READY, &chip->flags))
1175 dw_dma_cyclic_stop(chip->dma.rx_chan);
1176 if (test_bit(DMA_TX_READY, &chip->flags))
1177 dw_dma_cyclic_stop(chip->dma.tx_chan);
1178 }
1179 clk_disable_unprepare(chip->pclk); 892 clk_disable_unprepare(chip->pclk);
1180
1181 return 0; 893 return 0;
1182} 894}
1183 895
@@ -1187,12 +899,6 @@ static int atmel_ac97c_resume(struct device *pdev)
1187 struct atmel_ac97c *chip = card->private_data; 899 struct atmel_ac97c *chip = card->private_data;
1188 900
1189 clk_prepare_enable(chip->pclk); 901 clk_prepare_enable(chip->pclk);
1190 if (cpu_is_at32ap7000()) {
1191 if (test_bit(DMA_RX_READY, &chip->flags))
1192 dw_dma_cyclic_start(chip->dma.rx_chan);
1193 if (test_bit(DMA_TX_READY, &chip->flags))
1194 dw_dma_cyclic_start(chip->dma.tx_chan);
1195 }
1196 return 0; 902 return 0;
1197} 903}
1198 904
@@ -1219,17 +925,6 @@ static int atmel_ac97c_remove(struct platform_device *pdev)
1219 iounmap(chip->regs); 925 iounmap(chip->regs);
1220 free_irq(chip->irq, chip); 926 free_irq(chip->irq, chip);
1221 927
1222 if (cpu_is_at32ap7000()) {
1223 if (test_bit(DMA_RX_CHAN_PRESENT, &chip->flags))
1224 dma_release_channel(chip->dma.rx_chan);
1225 if (test_bit(DMA_TX_CHAN_PRESENT, &chip->flags))
1226 dma_release_channel(chip->dma.tx_chan);
1227 clear_bit(DMA_RX_CHAN_PRESENT, &chip->flags);
1228 clear_bit(DMA_TX_CHAN_PRESENT, &chip->flags);
1229 chip->dma.rx_chan = NULL;
1230 chip->dma.tx_chan = NULL;
1231 }
1232
1233 snd_card_free(card); 928 snd_card_free(card);
1234 929
1235 return 0; 930 return 0;