12 #include <linux/module.h>
16 #include <linux/device.h>
31 #define DRIVER_NAME "aaci-pl041"
33 #define FRAME_PERIOD_US 21
69 static void aaci_ac97_write(
struct snd_ac97 *ac97,
unsigned short reg,
81 aaci_ac97_select_codec(aaci, ac97);
102 "timeout waiting for write to complete\n");
110 static unsigned short aaci_ac97_read(
struct snd_ac97 *ac97,
unsigned short reg)
121 aaci_ac97_select_codec(aaci, ac97);
139 dev_err(&aaci->
dev->dev,
"timeout on slot 1 TX busy\n");
156 dev_err(&aaci->
dev->dev,
"timeout on RX valid\n");
166 }
else if (--retries) {
168 "ac97 read back fail. retry\n");
172 "wrong ac97 register read back (%x != %x)\n",
191 }
while (val & mask && timeout--);
199 static void aaci_fifo_irq(
struct aaci *aaci,
int channel,
u32 mask)
202 dev_warn(&aaci->
dev->dev,
"RX overrun on chan %d\n", channel);
207 dev_warn(&aaci->
dev->dev,
"RX timeout on chan %d\n", channel);
213 bool period_elapsed =
false;
222 spin_lock(&aacirun->
lock);
229 if (aacirun->
bytes <= 0) {
231 period_elapsed =
true;
242 aacirun->
bytes -= len;
245 for( ; len > 0; len -= 16) {
247 "ldmia %1, {r0, r1, r2, r3}\n\t"
248 "stmia %0!, {r0, r1, r2, r3}"
250 :
"r" (aacirun->
fifo)
251 :
"r0",
"r1",
"r2",
"r3",
"cc");
253 if (ptr >= aacirun->
end)
254 ptr = aacirun->
start;
260 spin_unlock(&aacirun->
lock);
267 dev_dbg(&aaci->
dev->dev,
"TX underrun on chan %d\n", channel);
273 bool period_elapsed =
false;
282 spin_lock(&aacirun->
lock);
289 if (aacirun->
bytes <= 0) {
291 period_elapsed =
true;
302 aacirun->
bytes -= len;
305 for ( ; len > 0; len -= 16) {
307 "ldmia %0!, {r0, r1, r2, r3}\n\t"
308 "stmia %1, {r0, r1, r2, r3}"
310 :
"r" (aacirun->
fifo)
311 :
"r0",
"r1",
"r2",
"r3",
"cc");
313 if (ptr >= aacirun->
end)
314 ptr = aacirun->
start;
320 spin_unlock(&aacirun->
lock);
329 struct aaci *aaci =
devid;
336 for (i = 0; i < 4; i++, m >>= 7) {
338 aaci_fifo_irq(aaci, i, m);
367 .buffer_bytes_max = 64 * 1024,
368 .period_bytes_min = 256,
387 struct aaci *aaci = rule->
private;
388 unsigned int mask = 1 << 0,
slots;
399 ARRAY_SIZE(channel_list), channel_list, mask);
417 runtime->
hw = aaci_hw_info;
418 runtime->
hw.rates = aacirun->
pcm->rates;
422 runtime->
hw.channels_max = 6;
427 aaci_rule_channels, aaci,
432 if (aacirun->
pcm->r[1].slots)
444 if (!aaci->
users++) {
498 static const u32 channels_to_slotmask[] = {
510 int dbl = rate > 48000;
513 aaci_pcm_hw_free(substream);
520 if (dbl && channels != 2)
529 aacirun->
pcm->r[dbl].slots);
533 aacirun->
cr |= channels_to_slotmask[channels + dbl * 2];
551 aacirun->
period = snd_pcm_lib_period_bytes(substream);
553 aacirun->
end = aacirun->
start + snd_pcm_lib_buffer_bytes(substream);
566 return bytes_to_frames(runtime, bytes);
573 static void aaci_pcm_playback_stop(
struct aaci_runtime *aacirun)
581 aaci_chan_wait_ready(aacirun,
SR_TXB);
585 static void aaci_pcm_playback_start(
struct aaci_runtime *aacirun)
589 aaci_chan_wait_ready(aacirun,
SR_TXB);
608 aaci_pcm_playback_start(aacirun);
612 aaci_pcm_playback_start(aacirun);
616 aaci_pcm_playback_stop(aacirun);
620 aaci_pcm_playback_stop(aacirun);
633 spin_unlock_irqrestore(&aacirun->
lock, flags);
639 .open = aaci_pcm_open,
640 .close = aaci_pcm_close,
642 .hw_params = aaci_pcm_hw_params,
643 .hw_free = aaci_pcm_hw_free,
644 .prepare = aaci_pcm_prepare,
645 .trigger = aaci_pcm_playback_trigger,
646 .pointer = aaci_pcm_pointer,
649 static void aaci_pcm_capture_stop(
struct aaci_runtime *aacirun)
653 aaci_chan_wait_ready(aacirun,
SR_RXB);
664 static void aaci_pcm_capture_start(
struct aaci_runtime *aacirun)
668 aaci_chan_wait_ready(aacirun,
SR_RXB);
672 aacirun->
cr |= 0xf << 17;
683 static int aaci_pcm_capture_trigger(
struct snd_pcm_substream *substream,
int cmd)
693 aaci_pcm_capture_start(aacirun);
697 aaci_pcm_capture_start(aacirun);
701 aaci_pcm_capture_stop(aacirun);
705 aaci_pcm_capture_stop(aacirun);
718 spin_unlock_irqrestore(&aacirun->
lock, flags);
728 aaci_pcm_prepare(substream);
742 .open = aaci_pcm_open,
743 .close = aaci_pcm_close,
745 .hw_params = aaci_pcm_hw_params,
746 .hw_free = aaci_pcm_hw_free,
747 .prepare = aaci_pcm_capture_prepare,
748 .trigger = aaci_pcm_capture_trigger,
749 .pointer = aaci_pcm_pointer,
760 snd_pcm_suspend_all(aaci->
pcm);
782 #define aaci_do_suspend NULL
783 #define aaci_do_resume NULL
784 #define aaci_suspend NULL
785 #define aaci_resume NULL
831 .
write = aaci_ac97_write,
832 .read = aaci_ac97_read,
835 static int __devinit aaci_probe_ac97(
struct aaci *aaci)
859 ac97_bus->
clock = 48000;
864 ac97_template.
num = 0;
875 if (ac97_is_audio(ac97))
889 static void aaci_free_card(
struct snd_card *card)
912 "%s PL%03x rev%u at 0x%08llx, irq %d",
914 (
unsigned long long)dev->
res.start, dev->
irq[0]);
929 static int __devinit aaci_init_pcm(
struct aaci *aaci)
951 static unsigned int __devinit aaci_size_fifo(
struct aaci *aaci)
997 aaci = aaci_init_card(dev);
1023 for (i = 0; i < 4; i++) {
1038 ret = aaci_probe_ac97(aaci);
1054 ret = aaci_init_pcm(aaci);
1092 static struct amba_id aaci_ids[] = {
1106 .probe = aaci_probe,
1110 .id_table = aaci_ids,