2 * au1550_i2s.c -- Sound driver for Alchemy Au1550 MIPS
3 * Internet Edge Processor.
5 * Copyright 2004 Embedded Edge, LLC
8 * So, I was stupid.....Although this is an I2S interface, it still uses
9 * the PSC for communication. The existing au1550_psc.c should have been
10 * called au1550_ac97.c or something. Not going to rename anything now.
12 * Mostly copied from the au1550_psc.c driver and some from the
13 * PowerMac dbdma driver.
14 * We assume the processor can do memory coherent DMA.
16 * The SMBus (I2C) is required for the control of the codec. It
17 * appears at I2C address 0x36 (I2C binary 0011011). The Pb1550
18 * uses the Wolfson WM8731 codec, which is controlled over the I2C.
19 * It's connected to a 12MHz clock, so we can only reliably support
20 * 96KHz, 48KHz, 32KHz, and 8KHz data rates. The framework for variable
21 * rate audio is in place, but we currently force it to 48KHz.
23 * This program is free software; you can redistribute it and/or modify it
24 * under the terms of the GNU General Public License as published by the
25 * Free Software Foundation; either version 2 of the License, or (at your
26 * option) any later version.
28 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
29 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
30 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
31 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
32 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
33 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
34 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
35 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
36 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
37 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
39 * You should have received a copy of the GNU General Public License along
40 * with this program; if not, write to the Free Software Foundation, Inc.,
41 * 675 Mass Ave, Cambridge, MA 02139, USA.
44 #include <linux/version.h>
45 #include <linux/module.h>
46 #include <linux/string.h>
47 #include <linux/ioport.h>
48 #include <linux/sched.h>
49 #include <linux/delay.h>
50 #include <linux/sound.h>
51 #include <linux/slab.h>
52 #include <linux/soundcard.h>
53 #include <linux/init.h>
54 #include <linux/poll.h>
55 #include <linux/pci.h>
56 #include <linux/bitops.h>
57 #include <linux/proc_fs.h>
58 #include <linux/spinlock.h>
59 #include <linux/smp_lock.h>
60 #include <linux/wrapper.h>
62 #include <asm/uaccess.h>
63 #include <asm/hardirq.h>
64 #include <asm/au1000.h>
65 #include <asm/pb1550.h>
66 #include <asm/au1xxx_psc.h>
67 #include <asm/au1xxx_dbdma.h>
69 #undef OSS_DOCUMENTED_MIXER_SEMANTICS
71 #define AU1550_MODULE_NAME "Au1550 i2s audio"
72 #define PFX AU1550_MODULE_NAME
74 /* Define this if you want to try running at the 44.1 KHz rate.
75 * It's just a little off, I think it's actually 44117 or something.
76 * I did this for debugging, since many programs, including this
77 * driver, will try to upsample from 44.1 to 48 KHz.
78 * Seems to work well, we'll just leave it this way.
83 #define SAMP_RATE 44100
85 #define SAMP_RATE 48000
88 /* The number of DBDMA ring descriptors to allocate. No sense making
89 * this too large....if you can't keep up with a few you aren't likely
90 * to be able to with lots of them, either.
92 #define NUM_DBDMA_DESCRIPTORS 4
94 #define err(format, arg...) printk(KERN_ERR PFX ": " format "\n" , ## arg)
95 #define info(format, arg...) printk(KERN_INFO PFX ": " format "\n" , ## arg)
98 * 0 = no VRA, 1 = use VRA if codec supports it
99 * The framework is here, but we currently force no VRA.
102 MODULE_PARM(vra, "i");
103 MODULE_PARM_DESC(vra, "if 1 use VRA if codec supports it");
105 static struct au1550_state {
106 /* soundcore stuff */
110 struct semaphore open_sem;
111 struct semaphore sem;
113 wait_queue_head_t open_wait;
115 volatile psc_i2s_t *psc_addr;
119 unsigned sample_rate;
121 unsigned sample_size;
123 int dma_bytes_per_sample;
124 int user_bytes_per_sample;
134 unsigned total_bytes;
136 wait_queue_head_t wait;
138 /* redundant, but makes calculations easier */
140 unsigned dma_fragsize;
148 unsigned ossfragshift;
150 unsigned subdivision;
181 au1550_delay(int msec)
189 tmo = jiffies + (msec * HZ) / 1000;
191 tmo2 = tmo - jiffies;
194 schedule_timeout(tmo2);
198 /* Just a place holder. The Wolfson codec is a write only device,
199 * so we would have to keep a local copy of the data.
211 wrcodec(u8 ctlreg, u8 val)
214 extern int pb1550_wm_codec_write(u8 addr, u8 reg, u8 val);
216 /* The codec is a write only device, with a 16-bit control/data
217 * word. Although it is written as two bytes on the I2C, the
218 * format is actually 7 bits of register and 9 bits of data.
219 * The ls bit of the first byte is the ms bit of the data.
222 while ((pb1550_wm_codec_write((0x36 >> 1), ctlreg, val) != 1)
226 printk("Codec write retry %02x %02x\n", ctlreg, val);
234 wrcodec(0x1e, 0x00); /* Reset */
236 wrcodec(0x0c, 0x00); /* Power up everything */
238 wrcodec(0x12, 0x00); /* Deactivate codec */
240 wrcodec(0x08, 0x10); /* Select DAC outputs to line out */
242 wrcodec(0x0a, 0x00); /* Disable output mute */
244 wrcodec(0x05, 0x70); /* lower output volume on headphone */
246 wrcodec(0x0e, 0x02); /* Set slave, 16-bit, I2S modes */
248 wrcodec(0x10, 0x01); /* 12MHz (USB), 250fs */
250 wrcodec(0x12, 0x01); /* Activate codec */
254 /* stop the ADC before calling */
256 set_adc_rate(struct au1550_state *s, unsigned rate)
258 struct dmabuf *adc = &s->dma_adc;
259 struct dmabuf *dac = &s->dma_dac;
264 adc->src_factor = (((SAMP_RATE*2) / rate) + 1) >> 1;
265 adc->sample_rate = SAMP_RATE / adc->src_factor;
273 rate = rate > SAMP_RATE ? SAMP_RATE : rate;
275 wrcodec(0, 0); /* I don't yet know what to write here if we vra */
277 adc->sample_rate = rate;
278 dac->sample_rate = rate;
282 /* stop the DAC before calling */
284 set_dac_rate(struct au1550_state *s, unsigned rate)
286 struct dmabuf *dac = &s->dma_dac;
287 struct dmabuf *adc = &s->dma_adc;
292 dac->src_factor = (((SAMP_RATE*2) / rate) + 1) >> 1;
293 dac->sample_rate = SAMP_RATE / dac->src_factor;
300 rate = rate > SAMP_RATE ? SAMP_RATE : rate;
302 wrcodec(0, 0); /* I don't yet know what to write here if we vra */
304 adc->sample_rate = rate;
305 dac->sample_rate = rate;
310 stop_dac(struct au1550_state *s)
312 struct dmabuf *db = &s->dma_dac;
315 volatile psc_i2s_t *ip;
321 spin_lock_irqsave(&s->lock, flags);
323 ip->psc_i2spcr = PSC_I2SPCR_TP;
326 /* Wait for Transmit Busy to show disabled.
329 stat = ip->psc_i2sstat;
331 } while ((stat & PSC_I2SSTAT_TB) != 0);
333 au1xxx_dbdma_reset(db->dmanr);
337 spin_unlock_irqrestore(&s->lock, flags);
341 stop_adc(struct au1550_state *s)
343 struct dmabuf *db = &s->dma_adc;
346 volatile psc_i2s_t *ip;
352 spin_lock_irqsave(&s->lock, flags);
354 ip->psc_i2spcr = PSC_I2SPCR_RP;
357 /* Wait for Receive Busy to show disabled.
360 stat = ip->psc_i2sstat;
362 } while ((stat & PSC_I2SSTAT_RB) != 0);
364 au1xxx_dbdma_reset(db->dmanr);
368 spin_unlock_irqrestore(&s->lock, flags);
373 set_xmit_slots(int num_channels)
375 /* This is here just as a place holder. The WM8731 only
376 * supports two fixed channels.
381 set_recv_slots(int num_channels)
383 /* This is here just as a place holder. The WM8731 only
384 * supports two fixed channels.
389 start_dac(struct au1550_state *s)
391 struct dmabuf *db = &s->dma_dac;
393 volatile psc_i2s_t *ip;
398 spin_lock_irqsave(&s->lock, flags);
401 set_xmit_slots(db->num_channels);
402 ip->psc_i2spcr = PSC_I2SPCR_TC;
404 ip->psc_i2spcr = PSC_I2SPCR_TS;
407 au1xxx_dbdma_start(db->dmanr);
411 spin_unlock_irqrestore(&s->lock, flags);
415 start_adc(struct au1550_state *s)
417 struct dmabuf *db = &s->dma_adc;
419 volatile psc_i2s_t *ip;
424 /* Put two buffers on the ring to get things started.
426 for (i=0; i<2; i++) {
427 au1xxx_dbdma_put_dest(db->dmanr, db->nextIn, db->dma_fragsize);
429 db->nextIn += db->dma_fragsize;
430 if (db->nextIn >= db->rawbuf + db->dmasize)
431 db->nextIn -= db->dmasize;
435 set_recv_slots(db->num_channels);
436 au1xxx_dbdma_start(db->dmanr);
437 ip->psc_i2spcr = PSC_I2SPCR_RC;
439 ip->psc_i2spcr = PSC_I2SPCR_RS;
446 prog_dmabuf(struct au1550_state *s, struct dmabuf *db)
448 unsigned user_bytes_per_sec;
450 unsigned rate = db->sample_rate;
453 db->ready = db->mapped = 0;
454 db->buforder = 5; /* 32 * PAGE_SIZE */
455 db->rawbuf = kmalloc((PAGE_SIZE << db->buforder), GFP_KERNEL);
461 if (db->sample_size == 8)
463 if (db->num_channels == 1)
465 db->cnt_factor *= db->src_factor;
469 db->nextIn = db->nextOut = db->rawbuf;
471 db->user_bytes_per_sample = (db->sample_size>>3) * db->num_channels;
472 db->dma_bytes_per_sample = 2 * ((db->num_channels == 1) ?
473 2 : db->num_channels);
475 user_bytes_per_sec = rate * db->user_bytes_per_sample;
476 bufs = PAGE_SIZE << db->buforder;
477 if (db->ossfragshift) {
478 if ((1000 << db->ossfragshift) < user_bytes_per_sec)
479 db->fragshift = ld2(user_bytes_per_sec/1000);
481 db->fragshift = db->ossfragshift;
483 db->fragshift = ld2(user_bytes_per_sec / 100 /
484 (db->subdivision ? db->subdivision : 1));
485 if (db->fragshift < 3)
489 db->fragsize = 1 << db->fragshift;
490 db->dma_fragsize = db->fragsize * db->cnt_factor;
491 db->numfrag = bufs / db->dma_fragsize;
493 while (db->numfrag < 4 && db->fragshift > 3) {
495 db->fragsize = 1 << db->fragshift;
496 db->dma_fragsize = db->fragsize * db->cnt_factor;
497 db->numfrag = bufs / db->dma_fragsize;
500 if (db->ossmaxfrags >= 4 && db->ossmaxfrags < db->numfrag)
501 db->numfrag = db->ossmaxfrags;
503 db->dmasize = db->dma_fragsize * db->numfrag;
504 memset(db->rawbuf, 0, bufs);
506 #ifdef AU1000_VERBOSE_DEBUG
507 dbg("rate=%d, samplesize=%d, channels=%d",
508 rate, db->sample_size, db->num_channels);
509 dbg("fragsize=%d, cnt_factor=%d, dma_fragsize=%d",
510 db->fragsize, db->cnt_factor, db->dma_fragsize);
511 dbg("numfrag=%d, dmasize=%d", db->numfrag, db->dmasize);
519 prog_dmabuf_adc(struct au1550_state *s)
522 return prog_dmabuf(s, &s->dma_adc);
527 prog_dmabuf_dac(struct au1550_state *s)
530 return prog_dmabuf(s, &s->dma_dac);
534 /* hold spinlock for the following */
536 dac_dma_interrupt(int irq, void *dev_id, struct pt_regs *regs)
538 struct au1550_state *s = (struct au1550_state *) dev_id;
539 struct dmabuf *db = &s->dma_dac;
541 volatile psc_i2s_t *ip;
544 i2s_stat = ip->psc_i2sstat;
545 #ifdef AU1000_VERBOSE_DEBUG
546 if (i2s_stat & (PSC_I2SSTAT_TF | PSC_I2SSTAT_TR | PSC_I2SSTAT_TF))
547 dbg("I2S status = 0x%08x", i2s_stat);
551 if (db->count >= db->fragsize) {
552 if (au1xxx_dbdma_put_source(db->dmanr, db->nextOut,
553 db->fragsize) == 0) {
554 err("qcount < 2 and no ring room!");
556 db->nextOut += db->fragsize;
557 if (db->nextOut >= db->rawbuf + db->dmasize)
558 db->nextOut -= db->dmasize;
559 db->count -= db->fragsize;
560 db->total_bytes += db->dma_fragsize;
564 /* wake up anybody listening */
565 if (waitqueue_active(&db->wait))
571 adc_dma_interrupt(int irq, void *dev_id, struct pt_regs *regs)
573 struct au1550_state *s = (struct au1550_state *)dev_id;
574 struct dmabuf *dp = &s->dma_adc;
578 /* Pull the buffer from the dma queue.
580 au1xxx_dbdma_get_dest(dp->dmanr, (void *)(&obuf), &obytes);
582 if ((dp->count + obytes) > dp->dmasize) {
583 /* Overrun. Stop ADC and log the error
591 /* Put a new empty buffer on the destination DMA.
593 au1xxx_dbdma_put_dest(dp->dmanr, dp->nextIn, dp->dma_fragsize);
595 dp->nextIn += dp->dma_fragsize;
596 if (dp->nextIn >= dp->rawbuf + dp->dmasize)
597 dp->nextIn -= dp->dmasize;
600 dp->total_bytes += obytes;
602 /* wake up anybody listening
604 if (waitqueue_active(&dp->wait))
610 au1550_llseek(struct file *file, loff_t offset, int origin)
618 au1550_open_mixdev(struct inode *inode, struct file *file)
620 file->private_data = &au1550_state;
625 au1550_release_mixdev(struct inode *inode, struct file *file)
631 mixdev_ioctl(struct ac97_codec *codec, unsigned int cmd,
634 return codec->mixer_ioctl(codec, cmd, arg);
638 au1550_ioctl_mixdev(struct inode *inode, struct file *file,
639 unsigned int cmd, unsigned long arg)
641 struct au1550_state *s = (struct au1550_state *)file->private_data;
642 struct ac97_codec *codec = s->codec;
644 return mixdev_ioctl(codec, cmd, arg);
647 static /*const */ struct file_operations au1550_mixer_fops = {
649 llseek:au1550_llseek,
650 ioctl:au1550_ioctl_mixdev,
651 open:au1550_open_mixdev,
652 release:au1550_release_mixdev,
657 drain_dac(struct au1550_state *s, int nonblock)
662 if (s->dma_dac.mapped || !s->dma_dac.ready || s->dma_dac.stopped)
666 spin_lock_irqsave(&s->lock, flags);
667 count = s->dma_dac.count;
668 spin_unlock_irqrestore(&s->lock, flags);
671 if (signal_pending(current))
675 tmo = 1000 * count / (s->no_vra ?
676 SAMP_RATE : s->dma_dac.sample_rate);
677 tmo /= s->dma_dac.dma_bytes_per_sample;
680 if (signal_pending(current))
685 static inline u8 S16_TO_U8(s16 ch)
687 return (u8) (ch >> 8) + 0x80;
689 static inline s16 U8_TO_S16(u8 ch)
691 return (s16) (ch - 0x80) << 8;
695 * Translates user samples to dma buffer suitable for audio DAC data:
696 * If mono, copy left channel to right channel in dma buffer.
697 * If 8 bit samples, cvt to 16-bit before writing to dma buffer.
698 * If interpolating (no VRA), duplicate every audio frame src_factor times.
701 translate_from_user(struct dmabuf *db, char* dmabuf, char* userbuf,
705 int interp_bytes_per_sample;
707 int mono = (db->num_channels == 1);
709 s16 ch, dmasample[6];
711 if (db->sample_size == 16 && !mono && db->src_factor == 1) {
712 /* no translation necessary, just copy
714 if (copy_from_user(dmabuf, userbuf, dmacount))
719 interp_bytes_per_sample = db->dma_bytes_per_sample * db->src_factor;
720 num_samples = dmacount / interp_bytes_per_sample;
722 for (sample = 0; sample < num_samples; sample++) {
723 if (copy_from_user(usersample, userbuf,
724 db->user_bytes_per_sample)) {
728 for (i = 0; i < db->num_channels; i++) {
729 if (db->sample_size == 8)
730 ch = U8_TO_S16(usersample[i]);
732 ch = *((s16 *) (&usersample[i * 2]));
735 dmasample[i + 1] = ch; /* right channel */
738 /* duplicate every audio frame src_factor times
740 for (i = 0; i < db->src_factor; i++)
741 memcpy(dmabuf, dmasample, db->dma_bytes_per_sample);
743 userbuf += db->user_bytes_per_sample;
744 dmabuf += interp_bytes_per_sample;
747 return num_samples * interp_bytes_per_sample;
751 * Translates audio ADC samples to user buffer:
752 * If mono, send only left channel to user buffer.
753 * If 8 bit samples, cvt from 16 to 8 bit before writing to user buffer.
754 * If decimating (no VRA), skip over src_factor audio frames.
757 translate_to_user(struct dmabuf *db, char* userbuf, char* dmabuf,
761 int interp_bytes_per_sample;
763 int mono = (db->num_channels == 1);
766 if (db->sample_size == 16 && !mono && db->src_factor == 1) {
767 /* no translation necessary, just copy
769 if (copy_to_user(userbuf, dmabuf, dmacount))
774 interp_bytes_per_sample = db->dma_bytes_per_sample * db->src_factor;
775 num_samples = dmacount / interp_bytes_per_sample;
777 for (sample = 0; sample < num_samples; sample++) {
778 for (i = 0; i < db->num_channels; i++) {
779 if (db->sample_size == 8)
781 S16_TO_U8(*((s16 *) (&dmabuf[i * 2])));
783 *((s16 *) (&usersample[i * 2])) =
784 *((s16 *) (&dmabuf[i * 2]));
787 if (copy_to_user(userbuf, usersample,
788 db->user_bytes_per_sample)) {
792 userbuf += db->user_bytes_per_sample;
793 dmabuf += interp_bytes_per_sample;
796 return num_samples * interp_bytes_per_sample;
800 * Copy audio data to/from user buffer from/to dma buffer, taking care
801 * that we wrap when reading/writing the dma buffer. Returns actual byte
802 * count written to or read from the dma buffer.
805 copy_dmabuf_user(struct dmabuf *db, char* userbuf, int count, int to_user)
807 char *bufptr = to_user ? db->nextOut : db->nextIn;
808 char *bufend = db->rawbuf + db->dmasize;
811 if (bufptr + count > bufend) {
812 int partial = (int) (bufend - bufptr);
814 if ((cnt = translate_to_user(db, userbuf,
815 bufptr, partial)) < 0)
818 if ((cnt = translate_to_user(db, userbuf + partial,
820 count - partial)) < 0)
824 if ((cnt = translate_from_user(db, bufptr, userbuf,
828 if ((cnt = translate_from_user(db, db->rawbuf,
830 count - partial)) < 0)
836 ret = translate_to_user(db, userbuf, bufptr, count);
838 ret = translate_from_user(db, bufptr, userbuf, count);
846 au1550_read(struct file *file, char *buffer, size_t count, loff_t *ppos)
848 struct au1550_state *s = (struct au1550_state *)file->private_data;
849 struct dmabuf *db = &s->dma_adc;
850 DECLARE_WAITQUEUE(wait, current);
853 int cnt, usercnt, avail;
855 if (ppos != &file->f_pos)
859 if (!access_ok(VERIFY_WRITE, buffer, count))
863 count *= db->cnt_factor;
866 add_wait_queue(&db->wait, &wait);
869 /* wait for samples in ADC dma buffer
874 spin_lock_irqsave(&s->lock, flags);
877 __set_current_state(TASK_INTERRUPTIBLE);
878 spin_unlock_irqrestore(&s->lock, flags);
880 if (file->f_flags & O_NONBLOCK) {
887 if (signal_pending(current)) {
894 } while (avail <= 0);
896 /* copy from nextOut to user
898 if ((cnt = copy_dmabuf_user(db, buffer,
900 avail : count, 1)) < 0) {
906 spin_lock_irqsave(&s->lock, flags);
909 if (db->nextOut >= db->rawbuf + db->dmasize)
910 db->nextOut -= db->dmasize;
911 spin_unlock_irqrestore(&s->lock, flags);
914 usercnt = cnt / db->cnt_factor;
917 } /* while (count > 0) */
922 remove_wait_queue(&db->wait, &wait);
923 set_current_state(TASK_RUNNING);
928 au1550_write(struct file *file, const char *buffer, size_t count, loff_t * ppos)
930 struct au1550_state *s = (struct au1550_state *)file->private_data;
931 struct dmabuf *db = &s->dma_dac;
932 DECLARE_WAITQUEUE(wait, current);
935 int cnt, usercnt, avail;
937 #ifdef AU1000_VERBOSE_DEBUG
938 dbg("write: count=%d", count);
941 if (ppos != &file->f_pos)
945 if (!access_ok(VERIFY_READ, buffer, count))
948 count *= db->cnt_factor;
951 add_wait_queue(&db->wait, &wait);
954 /* wait for space in playback buffer
957 spin_lock_irqsave(&s->lock, flags);
958 avail = (int) db->dmasize - db->count;
960 __set_current_state(TASK_INTERRUPTIBLE);
961 spin_unlock_irqrestore(&s->lock, flags);
963 if (file->f_flags & O_NONBLOCK) {
970 if (signal_pending(current)) {
977 } while (avail <= 0);
979 /* copy from user to nextIn
981 if ((cnt = copy_dmabuf_user(db, (char *) buffer,
983 avail : count, 0)) < 0) {
989 spin_lock_irqsave(&s->lock, flags);
992 if (db->nextIn >= db->rawbuf + db->dmasize)
993 db->nextIn -= db->dmasize;
995 /* If the data is available, we want to keep two buffers
996 * on the dma queue. If the queue count reaches zero,
997 * we know the dma has stopped.
999 while ((db->dma_qcount < 2) && (db->count >= db->fragsize)) {
1000 if (au1xxx_dbdma_put_source(db->dmanr, db->nextOut,
1001 db->fragsize) == 0) {
1002 err("qcount < 2 and no ring room!");
1004 db->nextOut += db->fragsize;
1005 if (db->nextOut >= db->rawbuf + db->dmasize)
1006 db->nextOut -= db->dmasize;
1007 db->count -= db->fragsize;
1008 db->total_bytes += db->dma_fragsize;
1009 if (db->dma_qcount == 0)
1013 spin_unlock_irqrestore(&s->lock, flags);
1016 usercnt = cnt / db->cnt_factor;
1019 } /* while (count > 0) */
1024 remove_wait_queue(&db->wait, &wait);
1025 set_current_state(TASK_RUNNING);
1030 /* No kernel lock - we have our own spinlock */
1032 au1550_poll(struct file *file, struct poll_table_struct *wait)
1034 struct au1550_state *s = (struct au1550_state *)file->private_data;
1035 unsigned long flags;
1036 unsigned int mask = 0;
1038 if (file->f_mode & FMODE_WRITE) {
1039 if (!s->dma_dac.ready)
1041 poll_wait(file, &s->dma_dac.wait, wait);
1043 if (file->f_mode & FMODE_READ) {
1044 if (!s->dma_adc.ready)
1046 poll_wait(file, &s->dma_adc.wait, wait);
1049 spin_lock_irqsave(&s->lock, flags);
1051 if (file->f_mode & FMODE_READ) {
1052 if (s->dma_adc.count >= (signed)s->dma_adc.dma_fragsize)
1053 mask |= POLLIN | POLLRDNORM;
1055 if (file->f_mode & FMODE_WRITE) {
1056 if (s->dma_dac.mapped) {
1057 if (s->dma_dac.count >=
1058 (signed)s->dma_dac.dma_fragsize)
1059 mask |= POLLOUT | POLLWRNORM;
1061 if ((signed) s->dma_dac.dmasize >=
1062 s->dma_dac.count + (signed)s->dma_dac.dma_fragsize)
1063 mask |= POLLOUT | POLLWRNORM;
1066 spin_unlock_irqrestore(&s->lock, flags);
1071 au1550_mmap(struct file *file, struct vm_area_struct *vma)
1073 struct au1550_state *s = (struct au1550_state *)file->private_data;
1080 if (vma->vm_flags & VM_WRITE)
1082 else if (vma->vm_flags & VM_READ)
1088 if (vma->vm_pgoff != 0) {
1092 size = vma->vm_end - vma->vm_start;
1093 if (size > (PAGE_SIZE << db->buforder)) {
1097 if (remap_page_range(vma->vm_start, virt_to_phys(db->rawbuf),
1098 size, vma->vm_page_prot)) {
1102 vma->vm_flags &= ~VM_IO;
1111 #ifdef AU1000_VERBOSE_DEBUG
1112 static struct ioctl_str_t {
1116 {SNDCTL_DSP_RESET, "SNDCTL_DSP_RESET"},
1117 {SNDCTL_DSP_SYNC, "SNDCTL_DSP_SYNC"},
1118 {SNDCTL_DSP_SPEED, "SNDCTL_DSP_SPEED"},
1119 {SNDCTL_DSP_STEREO, "SNDCTL_DSP_STEREO"},
1120 {SNDCTL_DSP_GETBLKSIZE, "SNDCTL_DSP_GETBLKSIZE"},
1121 {SNDCTL_DSP_SAMPLESIZE, "SNDCTL_DSP_SAMPLESIZE"},
1122 {SNDCTL_DSP_CHANNELS, "SNDCTL_DSP_CHANNELS"},
1123 {SOUND_PCM_WRITE_CHANNELS, "SOUND_PCM_WRITE_CHANNELS"},
1124 {SOUND_PCM_WRITE_FILTER, "SOUND_PCM_WRITE_FILTER"},
1125 {SNDCTL_DSP_POST, "SNDCTL_DSP_POST"},
1126 {SNDCTL_DSP_SUBDIVIDE, "SNDCTL_DSP_SUBDIVIDE"},
1127 {SNDCTL_DSP_SETFRAGMENT, "SNDCTL_DSP_SETFRAGMENT"},
1128 {SNDCTL_DSP_GETFMTS, "SNDCTL_DSP_GETFMTS"},
1129 {SNDCTL_DSP_SETFMT, "SNDCTL_DSP_SETFMT"},
1130 {SNDCTL_DSP_GETOSPACE, "SNDCTL_DSP_GETOSPACE"},
1131 {SNDCTL_DSP_GETISPACE, "SNDCTL_DSP_GETISPACE"},
1132 {SNDCTL_DSP_NONBLOCK, "SNDCTL_DSP_NONBLOCK"},
1133 {SNDCTL_DSP_GETCAPS, "SNDCTL_DSP_GETCAPS"},
1134 {SNDCTL_DSP_GETTRIGGER, "SNDCTL_DSP_GETTRIGGER"},
1135 {SNDCTL_DSP_SETTRIGGER, "SNDCTL_DSP_SETTRIGGER"},
1136 {SNDCTL_DSP_GETIPTR, "SNDCTL_DSP_GETIPTR"},
1137 {SNDCTL_DSP_GETOPTR, "SNDCTL_DSP_GETOPTR"},
1138 {SNDCTL_DSP_MAPINBUF, "SNDCTL_DSP_MAPINBUF"},
1139 {SNDCTL_DSP_MAPOUTBUF, "SNDCTL_DSP_MAPOUTBUF"},
1140 {SNDCTL_DSP_SETSYNCRO, "SNDCTL_DSP_SETSYNCRO"},
1141 {SNDCTL_DSP_SETDUPLEX, "SNDCTL_DSP_SETDUPLEX"},
1142 {SNDCTL_DSP_GETODELAY, "SNDCTL_DSP_GETODELAY"},
1143 {SNDCTL_DSP_GETCHANNELMASK, "SNDCTL_DSP_GETCHANNELMASK"},
1144 {SNDCTL_DSP_BIND_CHANNEL, "SNDCTL_DSP_BIND_CHANNEL"},
1145 {OSS_GETVERSION, "OSS_GETVERSION"},
1146 {SOUND_PCM_READ_RATE, "SOUND_PCM_READ_RATE"},
1147 {SOUND_PCM_READ_CHANNELS, "SOUND_PCM_READ_CHANNELS"},
1148 {SOUND_PCM_READ_BITS, "SOUND_PCM_READ_BITS"},
1149 {SOUND_PCM_READ_FILTER, "SOUND_PCM_READ_FILTER"}
1154 dma_count_done(struct dmabuf *db)
1159 return db->dma_fragsize - au1xxx_get_dma_residue(db->dmanr);
1164 au1550_ioctl(struct inode *inode, struct file *file, unsigned int cmd,
1167 struct au1550_state *s = (struct au1550_state *)file->private_data;
1168 unsigned long flags;
1169 audio_buf_info abinfo;
1172 int val, mapped, ret, diff;
1174 mapped = ((file->f_mode & FMODE_WRITE) && s->dma_dac.mapped) ||
1175 ((file->f_mode & FMODE_READ) && s->dma_adc.mapped);
1177 #ifdef AU1000_VERBOSE_DEBUG
1178 for (count=0; count<sizeof(ioctl_str)/sizeof(ioctl_str[0]); count++) {
1179 if (ioctl_str[count].cmd == cmd)
1182 if (count < sizeof(ioctl_str) / sizeof(ioctl_str[0]))
1183 dbg("ioctl %s, arg=0x%lx", ioctl_str[count].str, arg);
1185 dbg("ioctl 0x%x unknown, arg=0x%lx", cmd, arg);
1189 case OSS_GETVERSION:
1190 return put_user(SOUND_VERSION, (int *) arg);
1192 case SNDCTL_DSP_SYNC:
1193 if (file->f_mode & FMODE_WRITE)
1194 return drain_dac(s, file->f_flags & O_NONBLOCK);
1197 case SNDCTL_DSP_SETDUPLEX:
1200 case SNDCTL_DSP_GETCAPS:
1201 return put_user(DSP_CAP_DUPLEX | DSP_CAP_REALTIME |
1202 DSP_CAP_TRIGGER | DSP_CAP_MMAP, (int *)arg);
1204 case SNDCTL_DSP_RESET:
1205 if (file->f_mode & FMODE_WRITE) {
1208 s->dma_dac.count = s->dma_dac.total_bytes = 0;
1209 s->dma_dac.nextIn = s->dma_dac.nextOut =
1212 if (file->f_mode & FMODE_READ) {
1215 s->dma_adc.count = s->dma_adc.total_bytes = 0;
1216 s->dma_adc.nextIn = s->dma_adc.nextOut =
1221 case SNDCTL_DSP_SPEED:
1222 if (get_user(val, (int *) arg))
1225 if (file->f_mode & FMODE_READ) {
1227 set_adc_rate(s, val);
1229 if (file->f_mode & FMODE_WRITE) {
1231 set_dac_rate(s, val);
1233 if (s->open_mode & FMODE_READ)
1234 if ((ret = prog_dmabuf_adc(s)))
1236 if (s->open_mode & FMODE_WRITE)
1237 if ((ret = prog_dmabuf_dac(s)))
1240 return put_user((file->f_mode & FMODE_READ) ?
1241 s->dma_adc.sample_rate :
1242 s->dma_dac.sample_rate,
1245 case SNDCTL_DSP_STEREO:
1246 if (get_user(val, (int *) arg))
1248 if (file->f_mode & FMODE_READ) {
1250 s->dma_adc.num_channels = val ? 2 : 1;
1251 if ((ret = prog_dmabuf_adc(s)))
1254 if (file->f_mode & FMODE_WRITE) {
1256 s->dma_dac.num_channels = val ? 2 : 1;
1257 if ((ret = prog_dmabuf_dac(s)))
1262 case SNDCTL_DSP_CHANNELS:
1263 if (get_user(val, (int *) arg))
1266 if (file->f_mode & FMODE_READ) {
1267 if (val < 0 || val > 2)
1270 s->dma_adc.num_channels = val;
1271 if ((ret = prog_dmabuf_adc(s)))
1274 if (file->f_mode & FMODE_WRITE) {
1284 s->dma_dac.num_channels = val;
1285 if ((ret = prog_dmabuf_dac(s)))
1289 return put_user(val, (int *) arg);
1291 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
1292 return put_user(AFMT_S16_LE | AFMT_U8, (int *) arg);
1294 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt */
1295 if (get_user(val, (int *) arg))
1297 if (val != AFMT_QUERY) {
1298 if (file->f_mode & FMODE_READ) {
1300 if (val == AFMT_S16_LE)
1301 s->dma_adc.sample_size = 16;
1304 s->dma_adc.sample_size = 8;
1306 if ((ret = prog_dmabuf_adc(s)))
1309 if (file->f_mode & FMODE_WRITE) {
1311 if (val == AFMT_S16_LE)
1312 s->dma_dac.sample_size = 16;
1315 s->dma_dac.sample_size = 8;
1317 if ((ret = prog_dmabuf_dac(s)))
1321 if (file->f_mode & FMODE_READ)
1322 val = (s->dma_adc.sample_size == 16) ?
1323 AFMT_S16_LE : AFMT_U8;
1325 val = (s->dma_dac.sample_size == 16) ?
1326 AFMT_S16_LE : AFMT_U8;
1328 return put_user(val, (int *) arg);
1330 case SNDCTL_DSP_POST:
1333 case SNDCTL_DSP_GETTRIGGER:
1335 spin_lock_irqsave(&s->lock, flags);
1336 if (file->f_mode & FMODE_READ && !s->dma_adc.stopped)
1337 val |= PCM_ENABLE_INPUT;
1338 if (file->f_mode & FMODE_WRITE && !s->dma_dac.stopped)
1339 val |= PCM_ENABLE_OUTPUT;
1340 spin_unlock_irqrestore(&s->lock, flags);
1341 return put_user(val, (int *) arg);
1343 case SNDCTL_DSP_SETTRIGGER:
1344 if (get_user(val, (int *) arg))
1346 if (file->f_mode & FMODE_READ) {
1347 if (val & PCM_ENABLE_INPUT)
1352 if (file->f_mode & FMODE_WRITE) {
1353 if (val & PCM_ENABLE_OUTPUT)
1360 case SNDCTL_DSP_GETOSPACE:
1361 if (!(file->f_mode & FMODE_WRITE))
1363 abinfo.fragsize = s->dma_dac.fragsize;
1364 spin_lock_irqsave(&s->lock, flags);
1365 count = s->dma_dac.count;
1366 count -= dma_count_done(&s->dma_dac);
1367 spin_unlock_irqrestore(&s->lock, flags);
1370 abinfo.bytes = (s->dma_dac.dmasize - count) /
1371 s->dma_dac.cnt_factor;
1372 abinfo.fragstotal = s->dma_dac.numfrag;
1373 abinfo.fragments = abinfo.bytes >> s->dma_dac.fragshift;
1374 #ifdef AU1000_VERBOSE_DEBUG
1375 dbg("bytes=%d, fragments=%d", abinfo.bytes, abinfo.fragments);
1377 return copy_to_user((void *) arg, &abinfo,
1378 sizeof(abinfo)) ? -EFAULT : 0;
1380 case SNDCTL_DSP_GETISPACE:
1381 if (!(file->f_mode & FMODE_READ))
1383 abinfo.fragsize = s->dma_adc.fragsize;
1384 spin_lock_irqsave(&s->lock, flags);
1385 count = s->dma_adc.count;
1386 count += dma_count_done(&s->dma_adc);
1387 spin_unlock_irqrestore(&s->lock, flags);
1390 abinfo.bytes = count / s->dma_adc.cnt_factor;
1391 abinfo.fragstotal = s->dma_adc.numfrag;
1392 abinfo.fragments = abinfo.bytes >> s->dma_adc.fragshift;
1393 return copy_to_user((void *) arg, &abinfo,
1394 sizeof(abinfo)) ? -EFAULT : 0;
1396 case SNDCTL_DSP_NONBLOCK:
1397 file->f_flags |= O_NONBLOCK;
1400 case SNDCTL_DSP_GETODELAY:
1401 if (!(file->f_mode & FMODE_WRITE))
1403 spin_lock_irqsave(&s->lock, flags);
1404 count = s->dma_dac.count;
1405 count -= dma_count_done(&s->dma_dac);
1406 spin_unlock_irqrestore(&s->lock, flags);
1409 count /= s->dma_dac.cnt_factor;
1410 return put_user(count, (int *) arg);
1412 case SNDCTL_DSP_GETIPTR:
1413 if (!(file->f_mode & FMODE_READ))
1415 spin_lock_irqsave(&s->lock, flags);
1416 cinfo.bytes = s->dma_adc.total_bytes;
1417 count = s->dma_adc.count;
1418 if (!s->dma_adc.stopped) {
1419 diff = dma_count_done(&s->dma_adc);
1421 cinfo.bytes += diff;
1422 cinfo.ptr = virt_to_phys(s->dma_adc.nextIn) + diff -
1423 virt_to_phys(s->dma_adc.rawbuf);
1425 cinfo.ptr = virt_to_phys(s->dma_adc.nextIn) -
1426 virt_to_phys(s->dma_adc.rawbuf);
1427 if (s->dma_adc.mapped)
1428 s->dma_adc.count &= (s->dma_adc.dma_fragsize-1);
1429 spin_unlock_irqrestore(&s->lock, flags);
1432 cinfo.blocks = count >> s->dma_adc.fragshift;
1433 return copy_to_user((void *) arg, &cinfo, sizeof(cinfo));
1435 case SNDCTL_DSP_GETOPTR:
1436 if (!(file->f_mode & FMODE_READ))
1438 spin_lock_irqsave(&s->lock, flags);
1439 cinfo.bytes = s->dma_dac.total_bytes;
1440 count = s->dma_dac.count;
1441 if (!s->dma_dac.stopped) {
1442 diff = dma_count_done(&s->dma_dac);
1444 cinfo.bytes += diff;
1445 cinfo.ptr = virt_to_phys(s->dma_dac.nextOut) + diff -
1446 virt_to_phys(s->dma_dac.rawbuf);
1448 cinfo.ptr = virt_to_phys(s->dma_dac.nextOut) -
1449 virt_to_phys(s->dma_dac.rawbuf);
1450 if (s->dma_dac.mapped)
1451 s->dma_dac.count &= (s->dma_dac.dma_fragsize-1);
1452 spin_unlock_irqrestore(&s->lock, flags);
1455 cinfo.blocks = count >> s->dma_dac.fragshift;
1456 return copy_to_user((void *) arg, &cinfo, sizeof(cinfo));
1458 case SNDCTL_DSP_GETBLKSIZE:
1459 if (file->f_mode & FMODE_WRITE)
1460 return put_user(s->dma_dac.fragsize, (int *) arg);
1462 return put_user(s->dma_adc.fragsize, (int *) arg);
1464 case SNDCTL_DSP_SETFRAGMENT:
1465 if (get_user(val, (int *) arg))
1467 if (file->f_mode & FMODE_READ) {
1469 s->dma_adc.ossfragshift = val & 0xffff;
1470 s->dma_adc.ossmaxfrags = (val >> 16) & 0xffff;
1471 if (s->dma_adc.ossfragshift < 4)
1472 s->dma_adc.ossfragshift = 4;
1473 if (s->dma_adc.ossfragshift > 15)
1474 s->dma_adc.ossfragshift = 15;
1475 if (s->dma_adc.ossmaxfrags < 4)
1476 s->dma_adc.ossmaxfrags = 4;
1477 if ((ret = prog_dmabuf_adc(s)))
1480 if (file->f_mode & FMODE_WRITE) {
1482 s->dma_dac.ossfragshift = val & 0xffff;
1483 s->dma_dac.ossmaxfrags = (val >> 16) & 0xffff;
1484 if (s->dma_dac.ossfragshift < 4)
1485 s->dma_dac.ossfragshift = 4;
1486 if (s->dma_dac.ossfragshift > 15)
1487 s->dma_dac.ossfragshift = 15;
1488 if (s->dma_dac.ossmaxfrags < 4)
1489 s->dma_dac.ossmaxfrags = 4;
1490 if ((ret = prog_dmabuf_dac(s)))
1495 case SNDCTL_DSP_SUBDIVIDE:
1496 if ((file->f_mode & FMODE_READ && s->dma_adc.subdivision) ||
1497 (file->f_mode & FMODE_WRITE && s->dma_dac.subdivision))
1499 if (get_user(val, (int *) arg))
1501 if (val != 1 && val != 2 && val != 4)
1503 if (file->f_mode & FMODE_READ) {
1505 s->dma_adc.subdivision = val;
1506 if ((ret = prog_dmabuf_adc(s)))
1509 if (file->f_mode & FMODE_WRITE) {
1511 s->dma_dac.subdivision = val;
1512 if ((ret = prog_dmabuf_dac(s)))
1517 case SOUND_PCM_READ_RATE:
1518 return put_user((file->f_mode & FMODE_READ) ?
1519 s->dma_adc.sample_rate :
1520 s->dma_dac.sample_rate,
1523 case SOUND_PCM_READ_CHANNELS:
1524 if (file->f_mode & FMODE_READ)
1525 return put_user(s->dma_adc.num_channels, (int *)arg);
1527 return put_user(s->dma_dac.num_channels, (int *)arg);
1529 case SOUND_PCM_READ_BITS:
1530 if (file->f_mode & FMODE_READ)
1531 return put_user(s->dma_adc.sample_size, (int *)arg);
1533 return put_user(s->dma_dac.sample_size, (int *)arg);
1535 case SOUND_PCM_WRITE_FILTER:
1536 case SNDCTL_DSP_SETSYNCRO:
1537 case SOUND_PCM_READ_FILTER:
1542 return mixdev_ioctl(s->codec, cmd, arg);
1550 au1550_open(struct inode *inode, struct file *file)
1552 int minor = MINOR(inode->i_rdev);
1553 DECLARE_WAITQUEUE(wait, current);
1554 struct au1550_state *s = &au1550_state;
1557 #ifdef AU1000_VERBOSE_DEBUG
1558 if (file->f_flags & O_NONBLOCK)
1559 dbg(__FUNCTION__ ": non-blocking");
1561 dbg(__FUNCTION__ ": blocking");
1564 file->private_data = s;
1565 /* wait for device to become free */
1567 while (s->open_mode & file->f_mode) {
1568 if (file->f_flags & O_NONBLOCK) {
1572 add_wait_queue(&s->open_wait, &wait);
1573 __set_current_state(TASK_INTERRUPTIBLE);
1576 remove_wait_queue(&s->open_wait, &wait);
1577 set_current_state(TASK_RUNNING);
1578 if (signal_pending(current))
1579 return -ERESTARTSYS;
1586 if (file->f_mode & FMODE_READ) {
1587 s->dma_adc.ossfragshift = s->dma_adc.ossmaxfrags =
1588 s->dma_adc.subdivision = s->dma_adc.total_bytes = 0;
1589 s->dma_adc.num_channels = 1;
1590 s->dma_adc.sample_size = 8;
1591 set_adc_rate(s, 8000);
1592 if ((minor & 0xf) == SND_DEV_DSP16)
1593 s->dma_adc.sample_size = 16;
1596 if (file->f_mode & FMODE_WRITE) {
1597 s->dma_dac.ossfragshift = s->dma_dac.ossmaxfrags =
1598 s->dma_dac.subdivision = s->dma_dac.total_bytes = 0;
1599 s->dma_dac.num_channels = 1;
1600 s->dma_dac.sample_size = 8;
1601 set_dac_rate(s, 8000);
1602 if ((minor & 0xf) == SND_DEV_DSP16)
1603 s->dma_dac.sample_size = 16;
1606 if (file->f_mode & FMODE_READ) {
1607 if ((ret = prog_dmabuf_adc(s)))
1610 if (file->f_mode & FMODE_WRITE) {
1611 if ((ret = prog_dmabuf_dac(s)))
1615 s->open_mode |= file->f_mode & (FMODE_READ | FMODE_WRITE);
1617 init_MUTEX(&s->sem);
1622 au1550_release(struct inode *inode, struct file *file)
1624 struct au1550_state *s = (struct au1550_state *)file->private_data;
1628 if (file->f_mode & FMODE_WRITE) {
1630 drain_dac(s, file->f_flags & O_NONBLOCK);
1635 if (file->f_mode & FMODE_WRITE) {
1637 kfree(s->dma_dac.rawbuf);
1638 s->dma_dac.rawbuf = NULL;
1640 if (file->f_mode & FMODE_READ) {
1642 kfree(s->dma_adc.rawbuf);
1643 s->dma_adc.rawbuf = NULL;
1645 s->open_mode &= ((~file->f_mode) & (FMODE_READ|FMODE_WRITE));
1647 wake_up(&s->open_wait);
1652 static /*const */ struct file_operations au1550_audio_fops = {
1654 llseek: au1550_llseek,
1656 write: au1550_write,
1658 ioctl: au1550_ioctl,
1661 release: au1550_release,
1664 MODULE_AUTHOR("Advanced Micro Devices (AMD), dan@embeddededge.com");
1665 MODULE_DESCRIPTION("Au1550 Audio Driver");
1667 /* Set up an internal clock for the PSC3. This will then get
1668 * driven out of the Au1550 as the master.
1673 uint clk, rate, stat;
1675 /* Wire up Freq4 as a clock for the PSC3.
1676 * We know SMBus uses Freq3.
1677 * By making changes to this rate, plus the word strobe
1678 * size, we can make fine adjustments to the actual data rate.
1680 rate = get_au1x00_speed();
1682 rate /= (11 * 1000000);
1684 rate /= (12 * 1000000);
1687 /* The FRDIV in the frequency control is (FRDIV + 1) * 2
1691 clk = au_readl(SYS_FREQCTRL1);
1693 clk &= ~(SYS_FC_FRDIV4_MASK | SYS_FC_FS4);;
1694 clk |= (rate << SYS_FC_FRDIV4_BIT);
1696 au_writel(clk, SYS_FREQCTRL1);
1699 /* Set up the clock source routing to get Freq4 to PSC3_intclk.
1701 clk = au_readl(SYS_CLKSRC);
1705 au_writel(clk, SYS_CLKSRC);
1709 static int __devinit
1712 struct au1550_state *s = &au1550_state;
1714 volatile psc_i2s_t *ip;
1719 memset(s, 0, sizeof(struct au1550_state));
1721 init_waitqueue_head(&s->dma_adc.wait);
1722 init_waitqueue_head(&s->dma_dac.wait);
1723 init_waitqueue_head(&s->open_wait);
1724 init_MUTEX(&s->open_sem);
1725 spin_lock_init(&s->lock);
1728 s->psc_addr = (volatile psc_i2s_t *)I2S_PSC_BASE;
1731 if (!request_region(PHYSADDR(ip),
1732 0x30, AU1550_MODULE_NAME)) {
1733 err("I2S Audio ports in use");
1736 /* Allocate the DMA Channels
1738 if ((s->dma_dac.dmanr = au1xxx_dbdma_chan_alloc(DBDMA_MEM_CHAN,
1739 DBDMA_I2S_TX_CHAN, dac_dma_interrupt, (void *)s)) == 0) {
1740 err("Can't get DAC DMA");
1743 au1xxx_dbdma_set_devwidth(s->dma_dac.dmanr, 16);
1744 if (au1xxx_dbdma_ring_alloc(s->dma_dac.dmanr,
1745 NUM_DBDMA_DESCRIPTORS) == 0) {
1746 err("Can't get DAC DMA descriptors");
1750 if ((s->dma_adc.dmanr = au1xxx_dbdma_chan_alloc(DBDMA_I2S_RX_CHAN,
1751 DBDMA_MEM_CHAN, adc_dma_interrupt, (void *)s)) == 0) {
1752 err("Can't get ADC DMA");
1755 au1xxx_dbdma_set_devwidth(s->dma_adc.dmanr, 16);
1756 if (au1xxx_dbdma_ring_alloc(s->dma_adc.dmanr,
1757 NUM_DBDMA_DESCRIPTORS) == 0) {
1758 err("Can't get ADC DMA descriptors");
1762 info("DAC: DMA%d, ADC: DMA%d", DBDMA_I2S_TX_CHAN, DBDMA_I2S_RX_CHAN);
1764 /* register devices */
1766 if ((s->dev_audio = register_sound_dsp(&au1550_audio_fops, -1)) < 0)
1769 if ((s->codec->dev_mixer =
1770 register_sound_mixer(&au1550_mixer_fops, -1)) < 0)
1775 /* intialize the debug proc device */
1776 s->ps = create_proc_read_entry(AU1000_MODULE_NAME, 0, NULL,
1777 proc_au1550_dump, NULL);
1778 #endif /* AU1550_DEBUG */
1782 /* The GPIO for the appropriate PSC was configured by the
1783 * board specific start up.
1785 * configure PSC for I2S Audio
1787 ip->psc_ctrl = PSC_CTRL_DISABLE; /* Disable PSC */
1789 ip->psc_sel = (PSC_SEL_CLK_INTCLK | PSC_SEL_PS_I2SMODE);
1794 ip->psc_ctrl = PSC_CTRL_ENABLE;
1797 /* Wait for PSC ready.
1800 val = ip->psc_i2sstat;
1802 } while ((val & PSC_I2SSTAT_SR) == 0);
1804 /* Configure I2S controller.
1805 * Deep FIFO, 16-bit sample, DMA, make sure DMA matches fifo size.
1806 * Actual I2S mode (first bit delayed by one clock).
1807 * Master mode (We provide the clock from the PSC).
1809 val = PSC_I2SCFG_SET_LEN(16);
1811 /* This really should be 250, but it appears that all of the
1812 * PLLs, dividers and so on in the chain shift it. That's the
1813 * problem with sourceing the clock instead of letting the very
1814 * stable codec provide it. But, the PSC doesn't appear to want
1815 * to work in slave mode, so this is what we get. It's not
1816 * studio quality timing, but it's good enough for listening
1819 val |= PSC_I2SCFG_SET_WS(252);
1821 val |= PSC_I2SCFG_SET_WS(250);
1823 val |= PSC_I2SCFG_RT_FIFO8 | PSC_I2SCFG_TT_FIFO8 | \
1824 PSC_I2SCFG_BI | PSC_I2SCFG_XM;
1826 ip->psc_i2scfg = val;
1828 val |= PSC_I2SCFG_DE_ENABLE;
1829 ip->psc_i2scfg = val;
1832 /* Wait for Device ready.
1835 val = ip->psc_i2sstat;
1837 } while ((val & PSC_I2SSTAT_DR) == 0);
1839 val = ip->psc_i2scfg;
1846 info("no VRA, interpolating and decimating");
1849 /* set mic to be the recording source */
1850 val = SOUND_MASK_MIC;
1851 mixdev_ioctl(s->codec, SOUND_MIXER_WRITE_RECSRC,
1852 (unsigned long) &val);
1854 sprintf(proc_str, "driver/%s/%d/ac97", AU1550_MODULE_NAME,
1856 s->ac97_ps = create_proc_read_entry (proc_str, 0, NULL,
1857 ac97_read_proc, &s->codec);
1865 unregister_sound_mixer(s->codec->dev_mixer);
1867 unregister_sound_dsp(s->dev_audio);
1870 au1xxx_dbdma_chan_free(s->dma_adc.dmanr);
1872 au1xxx_dbdma_chan_free(s->dma_dac.dmanr);
1874 release_region(PHYSADDR(I2S_PSC_BASE), 0x30);
1879 static void __devinit
1882 struct au1550_state *s = &au1550_state;
1888 remove_proc_entry(AU1000_MODULE_NAME, NULL);
1889 #endif /* AU1000_DEBUG */
1891 au1xxx_dbdma_chan_free(s->dma_adc.dmanr);
1892 au1xxx_dbdma_chan_free(s->dma_dac.dmanr);
1893 release_region(PHYSADDR(I2S_PSC_BASE), 0x30);
1894 unregister_sound_dsp(s->dev_audio);
1896 unregister_sound_mixer(s->codec->dev_mixer);
1903 return au1550_probe();
1907 cleanup_au1550(void)
1912 module_init(init_au1550);
1913 module_exit(cleanup_au1550);
1918 au1550_setup(char *options)
1922 if (!options || !*options)
1925 for(this_opt=strtok(options, ",");
1926 this_opt; this_opt=strtok(NULL, ",")) {
1927 if (!strncmp(this_opt, "vra", 3)) {
1935 __setup("au1550_audio=", au1550_setup);