aboutsummaryrefslogtreecommitdiffstats
path: root/sound/arm
diff options
context:
space:
mode:
authorGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
committerGlenn Elliott <gelliott@cs.unc.edu>2012-03-04 19:47:13 -0500
commitc71c03bda1e86c9d5198c5d83f712e695c4f2a1e (patch)
treeecb166cb3e2b7e2adb3b5e292245fefd23381ac8 /sound/arm
parentea53c912f8a86a8567697115b6a0d8152beee5c8 (diff)
parent6a00f206debf8a5c8899055726ad127dbeeed098 (diff)
Merge branch 'mpi-master' into wip-k-fmlpwip-k-fmlp
Conflicts: litmus/sched_cedf.c
Diffstat (limited to 'sound/arm')
-rw-r--r--sound/arm/aaci.c341
-rw-r--r--sound/arm/aaci.h9
-rw-r--r--sound/arm/pxa2xx-pcm-lib.c3
3 files changed, 172 insertions, 181 deletions
diff --git a/sound/arm/aaci.c b/sound/arm/aaci.c
index 91acc9a243ec..d0cead38d5fb 100644
--- a/sound/arm/aaci.c
+++ b/sound/arm/aaci.c
@@ -30,6 +30,8 @@
30 30
31#define DRIVER_NAME "aaci-pl041" 31#define DRIVER_NAME "aaci-pl041"
32 32
33#define FRAME_PERIOD_US 21
34
33/* 35/*
34 * PM support is not complete. Turn it off. 36 * PM support is not complete. Turn it off.
35 */ 37 */
@@ -48,7 +50,11 @@ static void aaci_ac97_select_codec(struct aaci *aaci, struct snd_ac97 *ac97)
48 if (v & SLFR_1RXV) 50 if (v & SLFR_1RXV)
49 readl(aaci->base + AACI_SL1RX); 51 readl(aaci->base + AACI_SL1RX);
50 52
51 writel(maincr, aaci->base + AACI_MAINCR); 53 if (maincr != readl(aaci->base + AACI_MAINCR)) {
54 writel(maincr, aaci->base + AACI_MAINCR);
55 readl(aaci->base + AACI_MAINCR);
56 udelay(1);
57 }
52} 58}
53 59
54/* 60/*
@@ -64,8 +70,8 @@ static void aaci_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
64 unsigned short val) 70 unsigned short val)
65{ 71{
66 struct aaci *aaci = ac97->private_data; 72 struct aaci *aaci = ac97->private_data;
73 int timeout;
67 u32 v; 74 u32 v;
68 int timeout = 5000;
69 75
70 if (ac97->num >= 4) 76 if (ac97->num >= 4)
71 return; 77 return;
@@ -81,14 +87,17 @@ static void aaci_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
81 writel(val << 4, aaci->base + AACI_SL2TX); 87 writel(val << 4, aaci->base + AACI_SL2TX);
82 writel(reg << 12, aaci->base + AACI_SL1TX); 88 writel(reg << 12, aaci->base + AACI_SL1TX);
83 89
84 /* 90 /* Initially, wait one frame period */
85 * Wait for the transmission of both slots to complete. 91 udelay(FRAME_PERIOD_US);
86 */ 92
93 /* And then wait an additional eight frame periods for it to be sent */
94 timeout = FRAME_PERIOD_US * 8;
87 do { 95 do {
96 udelay(1);
88 v = readl(aaci->base + AACI_SLFR); 97 v = readl(aaci->base + AACI_SLFR);
89 } while ((v & (SLFR_1TXB|SLFR_2TXB)) && --timeout); 98 } while ((v & (SLFR_1TXB|SLFR_2TXB)) && --timeout);
90 99
91 if (!timeout) 100 if (v & (SLFR_1TXB|SLFR_2TXB))
92 dev_err(&aaci->dev->dev, 101 dev_err(&aaci->dev->dev,
93 "timeout waiting for write to complete\n"); 102 "timeout waiting for write to complete\n");
94 103
@@ -101,9 +110,8 @@ static void aaci_ac97_write(struct snd_ac97 *ac97, unsigned short reg,
101static unsigned short aaci_ac97_read(struct snd_ac97 *ac97, unsigned short reg) 110static unsigned short aaci_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
102{ 111{
103 struct aaci *aaci = ac97->private_data; 112 struct aaci *aaci = ac97->private_data;
113 int timeout, retries = 10;
104 u32 v; 114 u32 v;
105 int timeout = 5000;
106 int retries = 10;
107 115
108 if (ac97->num >= 4) 116 if (ac97->num >= 4)
109 return ~0; 117 return ~0;
@@ -117,35 +125,34 @@ static unsigned short aaci_ac97_read(struct snd_ac97 *ac97, unsigned short reg)
117 */ 125 */
118 writel((reg << 12) | (1 << 19), aaci->base + AACI_SL1TX); 126 writel((reg << 12) | (1 << 19), aaci->base + AACI_SL1TX);
119 127
120 /* 128 /* Initially, wait one frame period */
121 * Wait for the transmission to complete. 129 udelay(FRAME_PERIOD_US);
122 */ 130
131 /* And then wait an additional eight frame periods for it to be sent */
132 timeout = FRAME_PERIOD_US * 8;
123 do { 133 do {
134 udelay(1);
124 v = readl(aaci->base + AACI_SLFR); 135 v = readl(aaci->base + AACI_SLFR);
125 } while ((v & SLFR_1TXB) && --timeout); 136 } while ((v & SLFR_1TXB) && --timeout);
126 137
127 if (!timeout) { 138 if (v & SLFR_1TXB) {
128 dev_err(&aaci->dev->dev, "timeout on slot 1 TX busy\n"); 139 dev_err(&aaci->dev->dev, "timeout on slot 1 TX busy\n");
129 v = ~0; 140 v = ~0;
130 goto out; 141 goto out;
131 } 142 }
132 143
133 /* 144 /* Now wait for the response frame */
134 * Give the AC'97 codec more than enough time 145 udelay(FRAME_PERIOD_US);
135 * to respond. (42us = ~2 frames at 48kHz.)
136 */
137 udelay(42);
138 146
139 /* 147 /* And then wait an additional eight frame periods for data */
140 * Wait for slot 2 to indicate data. 148 timeout = FRAME_PERIOD_US * 8;
141 */
142 timeout = 5000;
143 do { 149 do {
150 udelay(1);
144 cond_resched(); 151 cond_resched();
145 v = readl(aaci->base + AACI_SLFR) & (SLFR_1RXV|SLFR_2RXV); 152 v = readl(aaci->base + AACI_SLFR) & (SLFR_1RXV|SLFR_2RXV);
146 } while ((v != (SLFR_1RXV|SLFR_2RXV)) && --timeout); 153 } while ((v != (SLFR_1RXV|SLFR_2RXV)) && --timeout);
147 154
148 if (!timeout) { 155 if (v != (SLFR_1RXV|SLFR_2RXV)) {
149 dev_err(&aaci->dev->dev, "timeout on RX valid\n"); 156 dev_err(&aaci->dev->dev, "timeout on RX valid\n");
150 v = ~0; 157 v = ~0;
151 goto out; 158 goto out;
@@ -179,6 +186,7 @@ aaci_chan_wait_ready(struct aaci_runtime *aacirun, unsigned long mask)
179 int timeout = 5000; 186 int timeout = 5000;
180 187
181 do { 188 do {
189 udelay(1);
182 val = readl(aacirun->base + AACI_SR); 190 val = readl(aacirun->base + AACI_SR);
183 } while (val & mask && timeout--); 191 } while (val & mask && timeout--);
184} 192}
@@ -202,6 +210,7 @@ static void aaci_fifo_irq(struct aaci *aaci, int channel, u32 mask)
202 210
203 if (mask & ISR_RXINTR) { 211 if (mask & ISR_RXINTR) {
204 struct aaci_runtime *aacirun = &aaci->capture; 212 struct aaci_runtime *aacirun = &aaci->capture;
213 bool period_elapsed = false;
205 void *ptr; 214 void *ptr;
206 215
207 if (!aacirun->substream || !aacirun->start) { 216 if (!aacirun->substream || !aacirun->start) {
@@ -214,15 +223,12 @@ static void aaci_fifo_irq(struct aaci *aaci, int channel, u32 mask)
214 223
215 ptr = aacirun->ptr; 224 ptr = aacirun->ptr;
216 do { 225 do {
217 unsigned int len = aacirun->fifosz; 226 unsigned int len = aacirun->fifo_bytes;
218 u32 val; 227 u32 val;
219 228
220 if (aacirun->bytes <= 0) { 229 if (aacirun->bytes <= 0) {
221 aacirun->bytes += aacirun->period; 230 aacirun->bytes += aacirun->period;
222 aacirun->ptr = ptr; 231 period_elapsed = true;
223 spin_unlock(&aacirun->lock);
224 snd_pcm_period_elapsed(aacirun->substream);
225 spin_lock(&aacirun->lock);
226 } 232 }
227 if (!(aacirun->cr & CR_EN)) 233 if (!(aacirun->cr & CR_EN))
228 break; 234 break;
@@ -252,6 +258,9 @@ static void aaci_fifo_irq(struct aaci *aaci, int channel, u32 mask)
252 aacirun->ptr = ptr; 258 aacirun->ptr = ptr;
253 259
254 spin_unlock(&aacirun->lock); 260 spin_unlock(&aacirun->lock);
261
262 if (period_elapsed)
263 snd_pcm_period_elapsed(aacirun->substream);
255 } 264 }
256 265
257 if (mask & ISR_URINTR) { 266 if (mask & ISR_URINTR) {
@@ -261,6 +270,7 @@ static void aaci_fifo_irq(struct aaci *aaci, int channel, u32 mask)
261 270
262 if (mask & ISR_TXINTR) { 271 if (mask & ISR_TXINTR) {
263 struct aaci_runtime *aacirun = &aaci->playback; 272 struct aaci_runtime *aacirun = &aaci->playback;
273 bool period_elapsed = false;
264 void *ptr; 274 void *ptr;
265 275
266 if (!aacirun->substream || !aacirun->start) { 276 if (!aacirun->substream || !aacirun->start) {
@@ -273,15 +283,12 @@ static void aaci_fifo_irq(struct aaci *aaci, int channel, u32 mask)
273 283
274 ptr = aacirun->ptr; 284 ptr = aacirun->ptr;
275 do { 285 do {
276 unsigned int len = aacirun->fifosz; 286 unsigned int len = aacirun->fifo_bytes;
277 u32 val; 287 u32 val;
278 288
279 if (aacirun->bytes <= 0) { 289 if (aacirun->bytes <= 0) {
280 aacirun->bytes += aacirun->period; 290 aacirun->bytes += aacirun->period;
281 aacirun->ptr = ptr; 291 period_elapsed = true;
282 spin_unlock(&aacirun->lock);
283 snd_pcm_period_elapsed(aacirun->substream);
284 spin_lock(&aacirun->lock);
285 } 292 }
286 if (!(aacirun->cr & CR_EN)) 293 if (!(aacirun->cr & CR_EN))
287 break; 294 break;
@@ -311,6 +318,9 @@ static void aaci_fifo_irq(struct aaci *aaci, int channel, u32 mask)
311 aacirun->ptr = ptr; 318 aacirun->ptr = ptr;
312 319
313 spin_unlock(&aacirun->lock); 320 spin_unlock(&aacirun->lock);
321
322 if (period_elapsed)
323 snd_pcm_period_elapsed(aacirun->substream);
314 } 324 }
315} 325}
316 326
@@ -353,7 +363,7 @@ static struct snd_pcm_hardware aaci_hw_info = {
353 363
354 /* rates are setup from the AC'97 codec */ 364 /* rates are setup from the AC'97 codec */
355 .channels_min = 2, 365 .channels_min = 2,
356 .channels_max = 6, 366 .channels_max = 2,
357 .buffer_bytes_max = 64 * 1024, 367 .buffer_bytes_max = 64 * 1024,
358 .period_bytes_min = 256, 368 .period_bytes_min = 256,
359 .period_bytes_max = PAGE_SIZE, 369 .period_bytes_max = PAGE_SIZE,
@@ -361,12 +371,46 @@ static struct snd_pcm_hardware aaci_hw_info = {
361 .periods_max = PAGE_SIZE / 16, 371 .periods_max = PAGE_SIZE / 16,
362}; 372};
363 373
364static int __aaci_pcm_open(struct aaci *aaci, 374/*
365 struct snd_pcm_substream *substream, 375 * We can support two and four channel audio. Unfortunately
366 struct aaci_runtime *aacirun) 376 * six channel audio requires a non-standard channel ordering:
377 * 2 -> FL(3), FR(4)
378 * 4 -> FL(3), FR(4), SL(7), SR(8)
379 * 6 -> FL(3), FR(4), SL(7), SR(8), C(6), LFE(9) (required)
380 * FL(3), FR(4), C(6), SL(7), SR(8), LFE(9) (actual)
381 * This requires an ALSA configuration file to correct.
382 */
383static int aaci_rule_channels(struct snd_pcm_hw_params *p,
384 struct snd_pcm_hw_rule *rule)
385{
386 static unsigned int channel_list[] = { 2, 4, 6 };
387 struct aaci *aaci = rule->private;
388 unsigned int mask = 1 << 0, slots;
389
390 /* pcms[0] is the our 5.1 PCM instance. */
391 slots = aaci->ac97_bus->pcms[0].r[0].slots;
392 if (slots & (1 << AC97_SLOT_PCM_SLEFT)) {
393 mask |= 1 << 1;
394 if (slots & (1 << AC97_SLOT_LFE))
395 mask |= 1 << 2;
396 }
397
398 return snd_interval_list(hw_param_interval(p, rule->var),
399 ARRAY_SIZE(channel_list), channel_list, mask);
400}
401
402static int aaci_pcm_open(struct snd_pcm_substream *substream)
367{ 403{
368 struct snd_pcm_runtime *runtime = substream->runtime; 404 struct snd_pcm_runtime *runtime = substream->runtime;
369 int ret; 405 struct aaci *aaci = substream->private_data;
406 struct aaci_runtime *aacirun;
407 int ret = 0;
408
409 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
410 aacirun = &aaci->playback;
411 } else {
412 aacirun = &aaci->capture;
413 }
370 414
371 aacirun->substream = substream; 415 aacirun->substream = substream;
372 runtime->private_data = aacirun; 416 runtime->private_data = aacirun;
@@ -374,27 +418,37 @@ static int __aaci_pcm_open(struct aaci *aaci,
374 runtime->hw.rates = aacirun->pcm->rates; 418 runtime->hw.rates = aacirun->pcm->rates;
375 snd_pcm_limit_hw_rates(runtime); 419 snd_pcm_limit_hw_rates(runtime);
376 420
377 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK && 421 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
378 aacirun->pcm->r[1].slots) 422 runtime->hw.channels_max = 6;
379 snd_ac97_pcm_double_rate_rules(runtime); 423
424 /* Add rule describing channel dependency. */
425 ret = snd_pcm_hw_rule_add(substream->runtime, 0,
426 SNDRV_PCM_HW_PARAM_CHANNELS,
427 aaci_rule_channels, aaci,
428 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
429 if (ret)
430 return ret;
431
432 if (aacirun->pcm->r[1].slots)
433 snd_ac97_pcm_double_rate_rules(runtime);
434 }
380 435
381 /* 436 /*
382 * FIXME: ALSA specifies fifo_size in bytes. If we're in normal 437 * ALSA wants the byte-size of the FIFOs. As we only support
383 * mode, each 32-bit word contains one sample. If we're in 438 * 16-bit samples, this is twice the FIFO depth irrespective
384 * compact mode, each 32-bit word contains two samples, effectively 439 * of whether it's in compact mode or not.
385 * halving the FIFO size. However, we don't know for sure which
386 * we'll be using at this point. We set this to the lower limit.
387 */ 440 */
388 runtime->hw.fifo_size = aaci->fifosize * 2; 441 runtime->hw.fifo_size = aaci->fifo_depth * 2;
389 442
390 ret = request_irq(aaci->dev->irq[0], aaci_irq, IRQF_SHARED|IRQF_DISABLED, 443 mutex_lock(&aaci->irq_lock);
391 DRIVER_NAME, aaci); 444 if (!aaci->users++) {
392 if (ret) 445 ret = request_irq(aaci->dev->irq[0], aaci_irq,
393 goto out; 446 IRQF_SHARED | IRQF_DISABLED, DRIVER_NAME, aaci);
394 447 if (ret != 0)
395 return 0; 448 aaci->users--;
449 }
450 mutex_unlock(&aaci->irq_lock);
396 451
397 out:
398 return ret; 452 return ret;
399} 453}
400 454
@@ -410,7 +464,11 @@ static int aaci_pcm_close(struct snd_pcm_substream *substream)
410 WARN_ON(aacirun->cr & CR_EN); 464 WARN_ON(aacirun->cr & CR_EN);
411 465
412 aacirun->substream = NULL; 466 aacirun->substream = NULL;
413 free_irq(aaci->dev->irq[0], aaci); 467
468 mutex_lock(&aaci->irq_lock);
469 if (!--aaci->users)
470 free_irq(aaci->dev->irq[0], aaci);
471 mutex_unlock(&aaci->irq_lock);
414 472
415 return 0; 473 return 0;
416} 474}
@@ -436,12 +494,21 @@ static int aaci_pcm_hw_free(struct snd_pcm_substream *substream)
436 return 0; 494 return 0;
437} 495}
438 496
497/* Channel to slot mask */
498static const u32 channels_to_slotmask[] = {
499 [2] = CR_SL3 | CR_SL4,
500 [4] = CR_SL3 | CR_SL4 | CR_SL7 | CR_SL8,
501 [6] = CR_SL3 | CR_SL4 | CR_SL7 | CR_SL8 | CR_SL6 | CR_SL9,
502};
503
439static int aaci_pcm_hw_params(struct snd_pcm_substream *substream, 504static int aaci_pcm_hw_params(struct snd_pcm_substream *substream,
440 struct aaci_runtime *aacirun,
441 struct snd_pcm_hw_params *params) 505 struct snd_pcm_hw_params *params)
442{ 506{
507 struct aaci_runtime *aacirun = substream->runtime->private_data;
508 unsigned int channels = params_channels(params);
509 unsigned int rate = params_rate(params);
510 int dbl = rate > 48000;
443 int err; 511 int err;
444 struct aaci *aaci = substream->private_data;
445 512
446 aaci_pcm_hw_free(substream); 513 aaci_pcm_hw_free(substream);
447 if (aacirun->pcm_open) { 514 if (aacirun->pcm_open) {
@@ -449,22 +516,28 @@ static int aaci_pcm_hw_params(struct snd_pcm_substream *substream,
449 aacirun->pcm_open = 0; 516 aacirun->pcm_open = 0;
450 } 517 }
451 518
519 /* channels is already limited to 2, 4, or 6 by aaci_rule_channels */
520 if (dbl && channels != 2)
521 return -EINVAL;
522
452 err = snd_pcm_lib_malloc_pages(substream, 523 err = snd_pcm_lib_malloc_pages(substream,
453 params_buffer_bytes(params)); 524 params_buffer_bytes(params));
454 if (err >= 0) { 525 if (err >= 0) {
455 unsigned int rate = params_rate(params); 526 struct aaci *aaci = substream->private_data;
456 int dbl = rate > 48000;
457 527
458 err = snd_ac97_pcm_open(aacirun->pcm, rate, 528 err = snd_ac97_pcm_open(aacirun->pcm, rate, channels,
459 params_channels(params),
460 aacirun->pcm->r[dbl].slots); 529 aacirun->pcm->r[dbl].slots);
461 530
462 aacirun->pcm_open = err == 0; 531 aacirun->pcm_open = err == 0;
463 aacirun->cr = CR_FEN | CR_COMPACT | CR_SZ16; 532 aacirun->cr = CR_FEN | CR_COMPACT | CR_SZ16;
464 aacirun->fifosz = aaci->fifosize * 4; 533 aacirun->cr |= channels_to_slotmask[channels + dbl * 2];
465 534
466 if (aacirun->cr & CR_COMPACT) 535 /*
467 aacirun->fifosz >>= 1; 536 * fifo_bytes is the number of bytes we transfer to/from
537 * the FIFO, including padding. So that's x4. As we're
538 * in compact mode, the FIFO is half the size.
539 */
540 aacirun->fifo_bytes = aaci->fifo_depth * 4 / 2;
468 } 541 }
469 542
470 return err; 543 return err;
@@ -475,11 +548,11 @@ static int aaci_pcm_prepare(struct snd_pcm_substream *substream)
475 struct snd_pcm_runtime *runtime = substream->runtime; 548 struct snd_pcm_runtime *runtime = substream->runtime;
476 struct aaci_runtime *aacirun = runtime->private_data; 549 struct aaci_runtime *aacirun = runtime->private_data;
477 550
551 aacirun->period = snd_pcm_lib_period_bytes(substream);
478 aacirun->start = runtime->dma_area; 552 aacirun->start = runtime->dma_area;
479 aacirun->end = aacirun->start + snd_pcm_lib_buffer_bytes(substream); 553 aacirun->end = aacirun->start + snd_pcm_lib_buffer_bytes(substream);
480 aacirun->ptr = aacirun->start; 554 aacirun->ptr = aacirun->start;
481 aacirun->period = 555 aacirun->bytes = aacirun->period;
482 aacirun->bytes = frames_to_bytes(runtime, runtime->period_size);
483 556
484 return 0; 557 return 0;
485} 558}
@@ -497,89 +570,6 @@ static snd_pcm_uframes_t aaci_pcm_pointer(struct snd_pcm_substream *substream)
497/* 570/*
498 * Playback specific ALSA stuff 571 * Playback specific ALSA stuff
499 */ 572 */
500static const u32 channels_to_txmask[] = {
501 [2] = CR_SL3 | CR_SL4,
502 [4] = CR_SL3 | CR_SL4 | CR_SL7 | CR_SL8,
503 [6] = CR_SL3 | CR_SL4 | CR_SL7 | CR_SL8 | CR_SL6 | CR_SL9,
504};
505
506/*
507 * We can support two and four channel audio. Unfortunately
508 * six channel audio requires a non-standard channel ordering:
509 * 2 -> FL(3), FR(4)
510 * 4 -> FL(3), FR(4), SL(7), SR(8)
511 * 6 -> FL(3), FR(4), SL(7), SR(8), C(6), LFE(9) (required)
512 * FL(3), FR(4), C(6), SL(7), SR(8), LFE(9) (actual)
513 * This requires an ALSA configuration file to correct.
514 */
515static unsigned int channel_list[] = { 2, 4, 6 };
516
517static int
518aaci_rule_channels(struct snd_pcm_hw_params *p, struct snd_pcm_hw_rule *rule)
519{
520 struct aaci *aaci = rule->private;
521 unsigned int chan_mask = 1 << 0, slots;
522
523 /*
524 * pcms[0] is the our 5.1 PCM instance.
525 */
526 slots = aaci->ac97_bus->pcms[0].r[0].slots;
527 if (slots & (1 << AC97_SLOT_PCM_SLEFT)) {
528 chan_mask |= 1 << 1;
529 if (slots & (1 << AC97_SLOT_LFE))
530 chan_mask |= 1 << 2;
531 }
532
533 return snd_interval_list(hw_param_interval(p, rule->var),
534 ARRAY_SIZE(channel_list), channel_list,
535 chan_mask);
536}
537
538static int aaci_pcm_open(struct snd_pcm_substream *substream)
539{
540 struct aaci *aaci = substream->private_data;
541 int ret;
542
543 /*
544 * Add rule describing channel dependency.
545 */
546 ret = snd_pcm_hw_rule_add(substream->runtime, 0,
547 SNDRV_PCM_HW_PARAM_CHANNELS,
548 aaci_rule_channels, aaci,
549 SNDRV_PCM_HW_PARAM_CHANNELS, -1);
550 if (ret)
551 return ret;
552
553 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
554 ret = __aaci_pcm_open(aaci, substream, &aaci->playback);
555 } else {
556 ret = __aaci_pcm_open(aaci, substream, &aaci->capture);
557 }
558 return ret;
559}
560
561static int aaci_pcm_playback_hw_params(struct snd_pcm_substream *substream,
562 struct snd_pcm_hw_params *params)
563{
564 struct aaci_runtime *aacirun = substream->runtime->private_data;
565 unsigned int channels = params_channels(params);
566 int ret;
567
568 WARN_ON(channels >= ARRAY_SIZE(channels_to_txmask) ||
569 !channels_to_txmask[channels]);
570
571 ret = aaci_pcm_hw_params(substream, aacirun, params);
572
573 /*
574 * Enable FIFO, compact mode, 16 bits per sample.
575 * FIXME: double rate slots?
576 */
577 if (ret >= 0)
578 aacirun->cr |= channels_to_txmask[channels];
579
580 return ret;
581}
582
583static void aaci_pcm_playback_stop(struct aaci_runtime *aacirun) 573static void aaci_pcm_playback_stop(struct aaci_runtime *aacirun)
584{ 574{
585 u32 ie; 575 u32 ie;
@@ -649,27 +639,13 @@ static struct snd_pcm_ops aaci_playback_ops = {
649 .open = aaci_pcm_open, 639 .open = aaci_pcm_open,
650 .close = aaci_pcm_close, 640 .close = aaci_pcm_close,
651 .ioctl = snd_pcm_lib_ioctl, 641 .ioctl = snd_pcm_lib_ioctl,
652 .hw_params = aaci_pcm_playback_hw_params, 642 .hw_params = aaci_pcm_hw_params,
653 .hw_free = aaci_pcm_hw_free, 643 .hw_free = aaci_pcm_hw_free,
654 .prepare = aaci_pcm_prepare, 644 .prepare = aaci_pcm_prepare,
655 .trigger = aaci_pcm_playback_trigger, 645 .trigger = aaci_pcm_playback_trigger,
656 .pointer = aaci_pcm_pointer, 646 .pointer = aaci_pcm_pointer,
657}; 647};
658 648
659static int aaci_pcm_capture_hw_params(struct snd_pcm_substream *substream,
660 struct snd_pcm_hw_params *params)
661{
662 struct aaci_runtime *aacirun = substream->runtime->private_data;
663 int ret;
664
665 ret = aaci_pcm_hw_params(substream, aacirun, params);
666 if (ret >= 0)
667 /* Line in record: slot 3 and 4 */
668 aacirun->cr |= CR_SL3 | CR_SL4;
669
670 return ret;
671}
672
673static void aaci_pcm_capture_stop(struct aaci_runtime *aacirun) 649static void aaci_pcm_capture_stop(struct aaci_runtime *aacirun)
674{ 650{
675 u32 ie; 651 u32 ie;
@@ -766,7 +742,7 @@ static struct snd_pcm_ops aaci_capture_ops = {
766 .open = aaci_pcm_open, 742 .open = aaci_pcm_open,
767 .close = aaci_pcm_close, 743 .close = aaci_pcm_close,
768 .ioctl = snd_pcm_lib_ioctl, 744 .ioctl = snd_pcm_lib_ioctl,
769 .hw_params = aaci_pcm_capture_hw_params, 745 .hw_params = aaci_pcm_hw_params,
770 .hw_free = aaci_pcm_hw_free, 746 .hw_free = aaci_pcm_hw_free,
771 .prepare = aaci_pcm_capture_prepare, 747 .prepare = aaci_pcm_capture_prepare,
772 .trigger = aaci_pcm_capture_trigger, 748 .trigger = aaci_pcm_capture_trigger,
@@ -874,7 +850,7 @@ static int __devinit aaci_probe_ac97(struct aaci *aaci)
874 * Give the AC'97 codec more than enough time 850 * Give the AC'97 codec more than enough time
875 * to wake up. (42us = ~2 frames at 48kHz.) 851 * to wake up. (42us = ~2 frames at 48kHz.)
876 */ 852 */
877 udelay(42); 853 udelay(FRAME_PERIOD_US * 2);
878 854
879 ret = snd_ac97_bus(aaci->card, 0, &aaci_bus_ops, aaci, &ac97_bus); 855 ret = snd_ac97_bus(aaci->card, 0, &aaci_bus_ops, aaci, &ac97_bus);
880 if (ret) 856 if (ret)
@@ -933,12 +909,13 @@ static struct aaci * __devinit aaci_init_card(struct amba_device *dev)
933 strlcpy(card->driver, DRIVER_NAME, sizeof(card->driver)); 909 strlcpy(card->driver, DRIVER_NAME, sizeof(card->driver));
934 strlcpy(card->shortname, "ARM AC'97 Interface", sizeof(card->shortname)); 910 strlcpy(card->shortname, "ARM AC'97 Interface", sizeof(card->shortname));
935 snprintf(card->longname, sizeof(card->longname), 911 snprintf(card->longname, sizeof(card->longname),
936 "%s at 0x%016llx, irq %d", 912 "%s PL%03x rev%u at 0x%08llx, irq %d",
937 card->shortname, (unsigned long long)dev->res.start, 913 card->shortname, amba_part(dev), amba_rev(dev),
938 dev->irq[0]); 914 (unsigned long long)dev->res.start, dev->irq[0]);
939 915
940 aaci = card->private_data; 916 aaci = card->private_data;
941 mutex_init(&aaci->ac97_sem); 917 mutex_init(&aaci->ac97_sem);
918 mutex_init(&aaci->irq_lock);
942 aaci->card = card; 919 aaci->card = card;
943 aaci->dev = dev; 920 aaci->dev = dev;
944 921
@@ -976,6 +953,10 @@ static unsigned int __devinit aaci_size_fifo(struct aaci *aaci)
976 struct aaci_runtime *aacirun = &aaci->playback; 953 struct aaci_runtime *aacirun = &aaci->playback;
977 int i; 954 int i;
978 955
956 /*
957 * Enable the channel, but don't assign it to any slots, so
958 * it won't empty onto the AC'97 link.
959 */
979 writel(CR_FEN | CR_SZ16 | CR_EN, aacirun->base + AACI_TXCR); 960 writel(CR_FEN | CR_SZ16 | CR_EN, aacirun->base + AACI_TXCR);
980 961
981 for (i = 0; !(readl(aacirun->base + AACI_SR) & SR_TXFF) && i < 4096; i++) 962 for (i = 0; !(readl(aacirun->base + AACI_SR) & SR_TXFF) && i < 4096; i++)
@@ -989,10 +970,12 @@ static unsigned int __devinit aaci_size_fifo(struct aaci *aaci)
989 * disabling the channel doesn't clear the FIFO. 970 * disabling the channel doesn't clear the FIFO.
990 */ 971 */
991 writel(aaci->maincr & ~MAINCR_IE, aaci->base + AACI_MAINCR); 972 writel(aaci->maincr & ~MAINCR_IE, aaci->base + AACI_MAINCR);
973 readl(aaci->base + AACI_MAINCR);
974 udelay(1);
992 writel(aaci->maincr, aaci->base + AACI_MAINCR); 975 writel(aaci->maincr, aaci->base + AACI_MAINCR);
993 976
994 /* 977 /*
995 * If we hit 4096, we failed. Go back to the specified 978 * If we hit 4096 entries, we failed. Go back to the specified
996 * fifo depth. 979 * fifo depth.
997 */ 980 */
998 if (i == 4096) 981 if (i == 4096)
@@ -1001,7 +984,8 @@ static unsigned int __devinit aaci_size_fifo(struct aaci *aaci)
1001 return i; 984 return i;
1002} 985}
1003 986
1004static int __devinit aaci_probe(struct amba_device *dev, struct amba_id *id) 987static int __devinit aaci_probe(struct amba_device *dev,
988 const struct amba_id *id)
1005{ 989{
1006 struct aaci *aaci; 990 struct aaci *aaci;
1007 int ret, i; 991 int ret, i;
@@ -1057,11 +1041,12 @@ static int __devinit aaci_probe(struct amba_device *dev, struct amba_id *id)
1057 1041
1058 /* 1042 /*
1059 * Size the FIFOs (must be multiple of 16). 1043 * Size the FIFOs (must be multiple of 16).
1044 * This is the number of entries in the FIFO.
1060 */ 1045 */
1061 aaci->fifosize = aaci_size_fifo(aaci); 1046 aaci->fifo_depth = aaci_size_fifo(aaci);
1062 if (aaci->fifosize & 15) { 1047 if (aaci->fifo_depth & 15) {
1063 printk(KERN_WARNING "AACI: fifosize = %d not supported\n", 1048 printk(KERN_WARNING "AACI: FIFO depth %d not supported\n",
1064 aaci->fifosize); 1049 aaci->fifo_depth);
1065 ret = -ENODEV; 1050 ret = -ENODEV;
1066 goto out; 1051 goto out;
1067 } 1052 }
@@ -1074,8 +1059,8 @@ static int __devinit aaci_probe(struct amba_device *dev, struct amba_id *id)
1074 1059
1075 ret = snd_card_register(aaci->card); 1060 ret = snd_card_register(aaci->card);
1076 if (ret == 0) { 1061 if (ret == 0) {
1077 dev_info(&dev->dev, "%s, fifo %d\n", aaci->card->longname, 1062 dev_info(&dev->dev, "%s\n", aaci->card->longname);
1078 aaci->fifosize); 1063 dev_info(&dev->dev, "FIFO %u entries\n", aaci->fifo_depth);
1079 amba_set_drvdata(dev, aaci->card); 1064 amba_set_drvdata(dev, aaci->card);
1080 return ret; 1065 return ret;
1081 } 1066 }
diff --git a/sound/arm/aaci.h b/sound/arm/aaci.h
index 6a4a2eebdda1..5791bd5bd2ab 100644
--- a/sound/arm/aaci.h
+++ b/sound/arm/aaci.h
@@ -210,6 +210,8 @@ struct aaci_runtime {
210 u32 cr; 210 u32 cr;
211 struct snd_pcm_substream *substream; 211 struct snd_pcm_substream *substream;
212 212
213 unsigned int period; /* byte size of a "period" */
214
213 /* 215 /*
214 * PIO support 216 * PIO support
215 */ 217 */
@@ -217,15 +219,16 @@ struct aaci_runtime {
217 void *end; 219 void *end;
218 void *ptr; 220 void *ptr;
219 int bytes; 221 int bytes;
220 unsigned int period; 222 unsigned int fifo_bytes;
221 unsigned int fifosz;
222}; 223};
223 224
224struct aaci { 225struct aaci {
225 struct amba_device *dev; 226 struct amba_device *dev;
226 struct snd_card *card; 227 struct snd_card *card;
227 void __iomem *base; 228 void __iomem *base;
228 unsigned int fifosize; 229 unsigned int fifo_depth;
230 unsigned int users;
231 struct mutex irq_lock;
229 232
230 /* AC'97 */ 233 /* AC'97 */
231 struct mutex ac97_sem; 234 struct mutex ac97_sem;
diff --git a/sound/arm/pxa2xx-pcm-lib.c b/sound/arm/pxa2xx-pcm-lib.c
index 8808b82311b1..76e0d5695075 100644
--- a/sound/arm/pxa2xx-pcm-lib.c
+++ b/sound/arm/pxa2xx-pcm-lib.c
@@ -140,6 +140,9 @@ int __pxa2xx_pcm_prepare(struct snd_pcm_substream *substream)
140 if (!prtd || !prtd->params) 140 if (!prtd || !prtd->params)
141 return 0; 141 return 0;
142 142
143 if (prtd->dma_ch == -1)
144 return -EINVAL;
145
143 DCSR(prtd->dma_ch) &= ~DCSR_RUN; 146 DCSR(prtd->dma_ch) &= ~DCSR_RUN;
144 DCSR(prtd->dma_ch) = 0; 147 DCSR(prtd->dma_ch) = 0;
145 DCMD(prtd->dma_ch) = 0; 148 DCMD(prtd->dma_ch) = 0;