diff options
Diffstat (limited to 'sound/atmel/ac97c.c')
-rw-r--r-- | sound/atmel/ac97c.c | 451 |
1 files changed, 73 insertions, 378 deletions
diff --git a/sound/atmel/ac97c.c b/sound/atmel/ac97c.c index 6dad042630d8..9d2c9d9af688 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 | ||
48 | enum { | ||
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 */ |
56 | static DEFINE_MUTEX(opened_mutex); | 38 | static DEFINE_MUTEX(opened_mutex); |
57 | 39 | ||
58 | struct atmel_ac97c_dma { | ||
59 | struct dma_chan *rx_chan; | ||
60 | struct dma_chan *tx_chan; | ||
61 | }; | ||
62 | |||
63 | struct atmel_ac97c { | 40 | struct 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. */ | ||
95 | static 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 | |||
101 | static 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 | |||
107 | static 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 | |||
153 | static struct snd_pcm_hardware atmel_ac97c_hw = { | 69 | static 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 | ||
297 | static 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 | |||
307 | static 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 | |||
317 | static int atmel_ac97c_playback_prepare(struct snd_pcm_substream *substream) | 203 | static 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; |
539 | out: | ||
540 | return retval; | ||
541 | } | 396 | } |
542 | 397 | ||
543 | static int | 398 | static 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; |
584 | out: | ||
585 | return retval; | ||
586 | } | 428 | } |
587 | 429 | ||
588 | static snd_pcm_uframes_t | 430 | static 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 | ||
878 | static 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 | |||
889 | static void atmel_ac97c_reset(struct atmel_ac97c *chip) | 696 | static void atmel_ac97c_reset(struct atmel_ac97c *chip) |
890 | { | 697 | { |
891 | ac97c_writel(chip, MR, 0); | 698 | ac97c_writel(chip, MR, 0); |
@@ -967,16 +774,11 @@ static int atmel_ac97c_probe(struct platform_device *pdev) | |||
967 | 774 | ||
968 | irq = platform_get_irq(pdev, 0); | 775 | irq = platform_get_irq(pdev, 0); |
969 | if (irq < 0) { | 776 | if (irq < 0) { |
970 | dev_dbg(&pdev->dev, "could not get irq\n"); | 777 | dev_dbg(&pdev->dev, "could not get irq: %d\n", irq); |
971 | return -ENXIO; | 778 | return irq; |
972 | } | ||
973 | |||
974 | if (cpu_is_at32ap7000()) { | ||
975 | pclk = clk_get(&pdev->dev, "pclk"); | ||
976 | } else { | ||
977 | pclk = clk_get(&pdev->dev, "ac97_clk"); | ||
978 | } | 779 | } |
979 | 780 | ||
781 | pclk = clk_get(&pdev->dev, "ac97_clk"); | ||
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 | ||
1141 | err_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 | } | ||
1152 | err_ac97_bus: | 871 | err_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; |