2 btaudio - bt878 audio dma driver for linux 2.4.x
4 (c) 2000-2002 Gerd Knorr <kraxel@bytesex.org>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 #include <linux/module.h>
23 #include <linux/errno.h>
24 #include <linux/pci.h>
25 #include <linux/sched.h>
26 #include <linux/signal.h>
27 #include <linux/types.h>
28 #include <linux/interrupt.h>
29 #include <linux/init.h>
30 #include <linux/poll.h>
31 #include <linux/sound.h>
32 #include <linux/soundcard.h>
33 #include <linux/slab.h>
34 #include <linux/kdev_t.h>
35 #include <asm/uaccess.h>
40 #define btwrite(dat,adr) writel((dat), (bta->mmio+(adr)))
41 #define btread(adr) readl(bta->mmio+(adr))
43 #define btand(dat,adr) btwrite((dat) & btread(adr), adr)
44 #define btor(dat,adr) btwrite((dat) | btread(adr), adr)
45 #define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
47 /* registers (shifted because bta->mmio is long) */
48 #define REG_INT_STAT (0x100 >> 2)
49 #define REG_INT_MASK (0x104 >> 2)
50 #define REG_GPIO_DMA_CTL (0x10c >> 2)
51 #define REG_PACKET_LEN (0x110 >> 2)
52 #define REG_RISC_STRT_ADD (0x114 >> 2)
53 #define REG_RISC_COUNT (0x120 >> 2)
55 /* IRQ bits - REG_INT_(STAT|MASK) */
56 #define IRQ_SCERR (1 << 19)
57 #define IRQ_OCERR (1 << 18)
58 #define IRQ_PABORT (1 << 17)
59 #define IRQ_RIPERR (1 << 16)
60 #define IRQ_PPERR (1 << 15)
61 #define IRQ_FDSR (1 << 14)
62 #define IRQ_FTRGT (1 << 13)
63 #define IRQ_FBUS (1 << 12)
64 #define IRQ_RISCI (1 << 11)
65 #define IRQ_OFLOW (1 << 3)
67 #define IRQ_BTAUDIO (IRQ_SCERR | IRQ_OCERR | IRQ_PABORT | IRQ_RIPERR |\
68 IRQ_PPERR | IRQ_FDSR | IRQ_FTRGT | IRQ_FBUS |\
71 /* REG_GPIO_DMA_CTL bits */
72 #define DMA_CTL_A_PWRDN (1 << 26)
73 #define DMA_CTL_DA_SBR (1 << 14)
74 #define DMA_CTL_DA_ES2 (1 << 13)
75 #define DMA_CTL_ACAP_EN (1 << 4)
76 #define DMA_CTL_RISC_EN (1 << 1)
77 #define DMA_CTL_FIFO_EN (1 << 0)
79 /* RISC instructions */
80 #define RISC_WRITE (0x01 << 28)
81 #define RISC_JUMP (0x07 << 28)
82 #define RISC_SYNC (0x08 << 28)
85 #define RISC_WR_SOL (1 << 27)
86 #define RISC_WR_EOL (1 << 26)
87 #define RISC_IRQ (1 << 24)
88 #define RISC_SYNC_RESYNC (1 << 15)
89 #define RISC_SYNC_FM1 0x06
90 #define RISC_SYNC_VRO 0x0c
92 #define HWBASE_AD (448000)
94 /* -------------------------------------------------------------- */
111 struct semaphore lock;
113 /* risc instructions */
114 unsigned int risc_size;
115 unsigned long *risc_cpu;
119 unsigned int buf_size;
120 unsigned char *buf_cpu;
129 /* read fifo management */
134 wait_queue_head_t readq;
153 static struct btaudio *btaudios;
154 static unsigned int debug;
155 static unsigned int irq_debug;
157 /* -------------------------------------------------------------- */
159 #define BUF_DEFAULT 128*1024
162 static int alloc_buffer(struct btaudio *bta)
164 if (NULL == bta->buf_cpu) {
165 for (bta->buf_size = BUF_DEFAULT; bta->buf_size >= BUF_MIN;
166 bta->buf_size = bta->buf_size >> 1) {
167 bta->buf_cpu = pci_alloc_consistent
168 (bta->pci, bta->buf_size, &bta->buf_dma);
169 if (NULL != bta->buf_cpu)
172 if (NULL == bta->buf_cpu)
174 memset(bta->buf_cpu,0,bta->buf_size);
176 if (NULL == bta->risc_cpu) {
177 bta->risc_size = PAGE_SIZE;
178 bta->risc_cpu = pci_alloc_consistent
179 (bta->pci, bta->risc_size, &bta->risc_dma);
180 if (NULL == bta->risc_cpu) {
181 pci_free_consistent(bta->pci, bta->buf_size, bta->buf_cpu, bta->buf_dma);
189 static void free_buffer(struct btaudio *bta)
191 if (NULL != bta->buf_cpu) {
192 pci_free_consistent(bta->pci, bta->buf_size,
193 bta->buf_cpu, bta->buf_dma);
196 if (NULL != bta->risc_cpu) {
197 pci_free_consistent(bta->pci, bta->risc_size,
198 bta->risc_cpu, bta->risc_dma);
199 bta->risc_cpu = NULL;
203 static int make_risc(struct btaudio *bta)
205 int rp, bp, line, block;
208 bta->block_bytes = bta->buf_size >> 4;
209 bta->block_count = 1 << 4;
210 bta->line_bytes = bta->block_bytes;
211 bta->line_count = bta->block_count;
212 while (bta->line_bytes > 4095) {
213 bta->line_bytes >>= 1;
214 bta->line_count <<= 1;
216 if (bta->line_count > 255)
220 "btaudio: bufsize=%d - bs=%d bc=%d - ls=%d, lc=%d\n",
221 bta->buf_size,bta->block_bytes,bta->block_count,
222 bta->line_bytes,bta->line_count);
225 bta->risc_cpu[rp++] = cpu_to_le32(RISC_SYNC|RISC_SYNC_FM1);
226 bta->risc_cpu[rp++] = cpu_to_le32(0);
227 for (line = 0; line < bta->line_count; line++) {
228 risc = RISC_WRITE | RISC_WR_SOL | RISC_WR_EOL;
229 risc |= bta->line_bytes;
230 if (0 == (bp & (bta->block_bytes-1))) {
232 risc |= (block & 0x0f) << 16;
233 risc |= (~block & 0x0f) << 20;
236 bta->risc_cpu[rp++] = cpu_to_le32(risc);
237 bta->risc_cpu[rp++] = cpu_to_le32(bta->buf_dma + bp);
238 bp += bta->line_bytes;
240 bta->risc_cpu[rp++] = cpu_to_le32(RISC_SYNC|RISC_SYNC_VRO);
241 bta->risc_cpu[rp++] = cpu_to_le32(0);
242 bta->risc_cpu[rp++] = cpu_to_le32(RISC_JUMP);
243 bta->risc_cpu[rp++] = cpu_to_le32(bta->risc_dma);
247 static int start_recording(struct btaudio *bta)
251 if (0 != (ret = alloc_buffer(bta)))
253 if (0 != (ret = make_risc(bta)))
256 btwrite(bta->risc_dma, REG_RISC_STRT_ADD);
257 btwrite((bta->line_count << 16) | bta->line_bytes,
259 btwrite(IRQ_BTAUDIO, REG_INT_MASK);
261 btwrite(DMA_CTL_ACAP_EN |
265 ((bta->bits == 8) ? DMA_CTL_DA_SBR : 0) |
266 (bta->gain[bta->source] << 28) |
267 (bta->source << 24) |
268 (bta->decimation << 8),
271 btwrite(DMA_CTL_ACAP_EN |
277 ((bta->bits == 8) ? DMA_CTL_DA_SBR : 0) |
278 (bta->gain[bta->source] << 28) |
279 (bta->source << 24) |
280 (bta->decimation << 8),
284 bta->read_offset = 0;
288 printk(KERN_DEBUG "btaudio: recording started\n");
292 static void stop_recording(struct btaudio *bta)
294 btand(~15, REG_GPIO_DMA_CTL);
297 printk(KERN_DEBUG "btaudio: recording stopped\n");
301 /* -------------------------------------------------------------- */
303 static int btaudio_mixer_open(struct inode *inode, struct file *file)
305 int minor = iminor(inode);
308 for (bta = btaudios; bta != NULL; bta = bta->next)
309 if (bta->mixer_dev == minor)
315 printk("btaudio: open mixer [%d]\n",minor);
316 file->private_data = bta;
320 static int btaudio_mixer_release(struct inode *inode, struct file *file)
325 static int btaudio_mixer_ioctl(struct inode *inode, struct file *file,
326 unsigned int cmd, unsigned long arg)
328 struct btaudio *bta = file->private_data;
331 if (cmd == SOUND_MIXER_INFO) {
333 memset(&info,0,sizeof(info));
334 strlcpy(info.id,"bt878",sizeof(info.id));
335 strlcpy(info.name,"Brooktree Bt878 audio",sizeof(info.name));
336 info.modify_counter = bta->mixcount;
337 if (copy_to_user((void *)arg, &info, sizeof(info)))
341 if (cmd == SOUND_OLD_MIXER_INFO) {
342 _old_mixer_info info;
343 memset(&info,0,sizeof(info));
344 strlcpy(info.id,"bt878",sizeof(info.id)-1);
345 strlcpy(info.name,"Brooktree Bt878 audio",sizeof(info.name));
346 if (copy_to_user((void *)arg, &info, sizeof(info)))
350 if (cmd == OSS_GETVERSION)
351 return put_user(SOUND_VERSION, (int *)arg);
354 if (_SIOC_DIR(cmd) & _SIOC_WRITE)
355 if (get_user(val, (int *)arg))
359 case MIXER_READ(SOUND_MIXER_CAPS):
360 ret = SOUND_CAP_EXCL_INPUT;
362 case MIXER_READ(SOUND_MIXER_STEREODEVS):
365 case MIXER_READ(SOUND_MIXER_RECMASK):
366 case MIXER_READ(SOUND_MIXER_DEVMASK):
367 ret = SOUND_MASK_LINE1|SOUND_MASK_LINE2|SOUND_MASK_LINE3;
370 case MIXER_WRITE(SOUND_MIXER_RECSRC):
371 if (val & SOUND_MASK_LINE1 && bta->source != 0)
373 else if (val & SOUND_MASK_LINE2 && bta->source != 1)
375 else if (val & SOUND_MASK_LINE3 && bta->source != 2)
377 btaor((bta->gain[bta->source] << 28) |
379 0x0cffffff, REG_GPIO_DMA_CTL);
380 case MIXER_READ(SOUND_MIXER_RECSRC):
381 switch (bta->source) {
382 case 0: ret = SOUND_MASK_LINE1; break;
383 case 1: ret = SOUND_MASK_LINE2; break;
384 case 2: ret = SOUND_MASK_LINE3; break;
389 case MIXER_WRITE(SOUND_MIXER_LINE1):
390 case MIXER_WRITE(SOUND_MIXER_LINE2):
391 case MIXER_WRITE(SOUND_MIXER_LINE3):
392 if (MIXER_WRITE(SOUND_MIXER_LINE1) == cmd)
394 if (MIXER_WRITE(SOUND_MIXER_LINE2) == cmd)
396 if (MIXER_WRITE(SOUND_MIXER_LINE3) == cmd)
398 bta->gain[i] = (val & 0xff) * 15 / 100;
399 if (bta->gain[i] > 15) bta->gain[i] = 15;
400 if (bta->gain[i] < 0) bta->gain[i] = 0;
401 if (i == bta->source)
402 btaor((bta->gain[bta->source]<<28),
403 0x0fffffff, REG_GPIO_DMA_CTL);
404 ret = bta->gain[i] * 100 / 15;
408 case MIXER_READ(SOUND_MIXER_LINE1):
409 case MIXER_READ(SOUND_MIXER_LINE2):
410 case MIXER_READ(SOUND_MIXER_LINE3):
411 if (MIXER_READ(SOUND_MIXER_LINE1) == cmd)
413 if (MIXER_READ(SOUND_MIXER_LINE2) == cmd)
415 if (MIXER_READ(SOUND_MIXER_LINE3) == cmd)
417 ret = bta->gain[i] * 100 / 15;
424 if (put_user(ret, (int *)arg))
429 static struct file_operations btaudio_mixer_fops = {
430 .owner = THIS_MODULE,
432 .open = btaudio_mixer_open,
433 .release = btaudio_mixer_release,
434 .ioctl = btaudio_mixer_ioctl,
437 /* -------------------------------------------------------------- */
439 static int btaudio_dsp_open(struct inode *inode, struct file *file,
440 struct btaudio *bta, int analog)
446 file->private_data = bta;
448 bta->analog = analog;
450 bta->read_offset = 0;
452 bta->sampleshift = 0;
462 static int btaudio_dsp_open_digital(struct inode *inode, struct file *file)
464 int minor = iminor(inode);
467 for (bta = btaudios; bta != NULL; bta = bta->next)
468 if (bta->dsp_digital == minor)
474 printk("btaudio: open digital dsp [%d]\n",minor);
475 return btaudio_dsp_open(inode,file,bta,0);
478 static int btaudio_dsp_open_analog(struct inode *inode, struct file *file)
480 int minor = iminor(inode);
483 for (bta = btaudios; bta != NULL; bta = bta->next)
484 if (bta->dsp_analog == minor)
490 printk("btaudio: open analog dsp [%d]\n",minor);
491 return btaudio_dsp_open(inode,file,bta,1);
494 static int btaudio_dsp_release(struct inode *inode, struct file *file)
496 struct btaudio *bta = file->private_data;
506 static ssize_t btaudio_dsp_read(struct file *file, char *buffer,
507 size_t swcount, loff_t *ppos)
509 struct btaudio *bta = file->private_data;
510 int hwcount = swcount << bta->sampleshift;
511 int nsrc, ndst, err, ret = 0;
512 DECLARE_WAITQUEUE(wait, current);
514 add_wait_queue(&bta->readq, &wait);
516 while (swcount > 0) {
517 if (0 == bta->read_count) {
518 if (!bta->recording) {
519 if (0 != (err = start_recording(bta))) {
525 if (file->f_flags & O_NONBLOCK) {
531 current->state = TASK_INTERRUPTIBLE;
534 if(signal_pending(current)) {
540 nsrc = (bta->read_count < hwcount) ? bta->read_count : hwcount;
541 if (nsrc > bta->buf_size - bta->read_offset)
542 nsrc = bta->buf_size - bta->read_offset;
543 ndst = nsrc >> bta->sampleshift;
545 if ((bta->analog && 0 == bta->sampleshift) ||
546 (!bta->analog && 2 == bta->channels)) {
548 if (copy_to_user(buffer + ret, bta->buf_cpu + bta->read_offset, nsrc)) {
554 } else if (!bta->analog) {
555 /* stereo => mono (digital audio) */
556 __s16 *src = (__s16*)(bta->buf_cpu + bta->read_offset);
557 __s16 *dst = (__s16*)(buffer + ret);
560 if (0 != verify_area(VERIFY_WRITE,dst,ndst)) {
565 for (; n; n--, dst++) {
566 avg = (__s16)le16_to_cpu(*src) / 2; src++;
567 avg += (__s16)le16_to_cpu(*src) / 2; src++;
568 __put_user(cpu_to_le16(avg),(__u16*)(dst));
571 } else if (8 == bta->bits) {
572 /* copy + byte downsampling (audio A/D) */
573 __u8 *src = bta->buf_cpu + bta->read_offset;
574 __u8 *dst = buffer + ret;
576 if (0 != verify_area(VERIFY_WRITE,dst,ndst)) {
581 for (; n; n--, src += (1 << bta->sampleshift), dst++)
582 __put_user(*src,(__u8*)(dst));
585 /* copy + word downsampling (audio A/D) */
586 __u16 *src = (__u16*)(bta->buf_cpu + bta->read_offset);
587 __u16 *dst = (__u16*)(buffer + ret);
589 if (0 != verify_area(VERIFY_WRITE,dst,ndst)) {
594 for (; n; n--, src += (1 << bta->sampleshift), dst++)
595 __put_user(*src,(__u16*)(dst));
601 bta->read_count -= nsrc;
602 bta->read_offset += nsrc;
603 if (bta->read_offset == bta->buf_size)
604 bta->read_offset = 0;
607 remove_wait_queue(&bta->readq, &wait);
608 current->state = TASK_RUNNING;
612 static ssize_t btaudio_dsp_write(struct file *file, const char *buffer,
613 size_t count, loff_t *ppos)
618 static int btaudio_dsp_ioctl(struct inode *inode, struct file *file,
619 unsigned int cmd, unsigned long arg)
621 struct btaudio *bta = file->private_data;
622 int s, i, ret, val = 0;
626 return put_user(SOUND_VERSION, (int *)arg);
627 case SNDCTL_DSP_GETCAPS:
630 case SNDCTL_DSP_SPEED:
631 if (get_user(val, (int*)arg))
634 for (s = 0; s < 16; s++)
635 if (val << s >= HWBASE_AD*4/15)
637 for (i = 15; i >= 5; i--)
638 if (val << s <= HWBASE_AD*4/i)
640 bta->sampleshift = s;
643 printk(KERN_DEBUG "btaudio: rate: req=%d "
644 "dec=%d shift=%d hwrate=%d swrate=%d\n",
645 val,i,s,(HWBASE_AD*4/i),(HWBASE_AD*4/i)>>s);
647 bta->sampleshift = (bta->channels == 2) ? 0 : 1;
650 if (bta->recording) {
653 start_recording(bta);
657 case SOUND_PCM_READ_RATE:
659 return put_user(HWBASE_AD*4/bta->decimation>>bta->sampleshift, (int*)arg);
661 return put_user(bta->rate, (int*)arg);
664 case SNDCTL_DSP_STEREO:
666 if (get_user(val, (int*)arg))
668 bta->channels = (val > 0) ? 2 : 1;
669 bta->sampleshift = (bta->channels == 2) ? 0 : 1;
672 "btaudio: stereo=%d channels=%d\n",
681 "btaudio: stereo=0 channels=1\n");
684 return put_user((bta->channels)-1, (int *)arg);
686 case SNDCTL_DSP_CHANNELS:
688 if (get_user(val, (int*)arg))
690 bta->channels = (val > 1) ? 2 : 1;
691 bta->sampleshift = (bta->channels == 2) ? 0 : 1;
694 "btaudio: val=%d channels=%d\n",
698 case SOUND_PCM_READ_CHANNELS:
699 return put_user(bta->channels, (int *)arg);
701 case SNDCTL_DSP_GETFMTS: /* Returns a mask */
703 return put_user(AFMT_S16_LE|AFMT_S8, (int*)arg);
705 return put_user(AFMT_S16_LE, (int*)arg);
707 case SNDCTL_DSP_SETFMT: /* Selects ONE fmt*/
708 if (get_user(val, (int*)arg))
710 if (val != AFMT_QUERY) {
712 bta->bits = (val == AFMT_S8) ? 8 : 16;
715 if (bta->recording) {
718 start_recording(bta);
723 printk(KERN_DEBUG "btaudio: fmt: bits=%d\n",bta->bits);
724 return put_user((bta->bits==16) ? AFMT_S16_LE : AFMT_S8,
727 case SOUND_PCM_READ_BITS:
728 return put_user(bta->bits, (int*)arg);
730 case SNDCTL_DSP_NONBLOCK:
731 file->f_flags |= O_NONBLOCK;
734 case SNDCTL_DSP_RESET:
735 if (bta->recording) {
741 case SNDCTL_DSP_GETBLKSIZE:
742 if (!bta->recording) {
743 if (0 != (ret = alloc_buffer(bta)))
745 if (0 != (ret = make_risc(bta)))
748 return put_user(bta->block_bytes>>bta->sampleshift,(int*)arg);
750 case SNDCTL_DSP_SYNC:
753 case SNDCTL_DSP_GETISPACE:
758 info.fragsize = bta->block_bytes>>bta->sampleshift;
759 info.fragstotal = bta->block_count;
760 info.bytes = bta->read_count;
761 info.fragments = info.bytes / info.fragsize;
763 printk(KERN_DEBUG "btaudio: SNDCTL_DSP_GETISPACE "
764 "returns %d/%d/%d/%d\n",
765 info.fragsize, info.fragstotal,
766 info.bytes, info.fragments);
767 if (copy_to_user((void *)arg, &info, sizeof(info)))
772 case SNDCTL_DSP_GETTRIGGER:
773 case SNDCTL_DSP_SETTRIGGER:
774 case SNDCTL_DSP_SETFRAGMENT:
781 static unsigned int btaudio_dsp_poll(struct file *file, struct poll_table_struct *wait)
783 struct btaudio *bta = file->private_data;
784 unsigned int mask = 0;
786 poll_wait(file, &bta->readq, wait);
788 if (0 != bta->read_count)
789 mask |= (POLLIN | POLLRDNORM);
794 static struct file_operations btaudio_digital_dsp_fops = {
795 .owner = THIS_MODULE,
797 .open = btaudio_dsp_open_digital,
798 .release = btaudio_dsp_release,
799 .read = btaudio_dsp_read,
800 .write = btaudio_dsp_write,
801 .ioctl = btaudio_dsp_ioctl,
802 .poll = btaudio_dsp_poll,
805 static struct file_operations btaudio_analog_dsp_fops = {
806 .owner = THIS_MODULE,
808 .open = btaudio_dsp_open_analog,
809 .release = btaudio_dsp_release,
810 .read = btaudio_dsp_read,
811 .write = btaudio_dsp_write,
812 .ioctl = btaudio_dsp_ioctl,
813 .poll = btaudio_dsp_poll,
816 /* -------------------------------------------------------------- */
818 static char *irq_name[] = { "", "", "", "OFLOW", "", "", "", "", "", "", "",
819 "RISCI", "FBUS", "FTRGT", "FDSR", "PPERR",
820 "RIPERR", "PABORT", "OCERR", "SCERR" };
822 static irqreturn_t btaudio_irq(int irq, void *dev_id, struct pt_regs * regs)
826 struct btaudio *bta = dev_id;
831 stat = btread(REG_INT_STAT);
832 astat = stat & btread(REG_INT_MASK);
834 return IRQ_RETVAL(handled);
836 btwrite(astat,REG_INT_STAT);
840 printk(KERN_DEBUG "btaudio: irq loop=%d risc=%x, bits:",
842 for (i = 0; i < (sizeof(irq_name)/sizeof(char*)); i++) {
844 printk(" %s",irq_name[i]);
845 if (astat & (1 << i))
850 if (stat & IRQ_RISCI) {
852 blocks = (stat >> 28) - bta->dma_block;
854 blocks += bta->block_count;
855 bta->dma_block = stat >> 28;
856 if (bta->read_count + 2*bta->block_bytes > bta->buf_size) {
858 printk(KERN_INFO "btaudio: buffer overrun\n");
861 bta->read_count += blocks * bta->block_bytes;
862 wake_up_interruptible(&bta->readq);
867 "btaudio: Oops - irq mask cleared\n");
868 btwrite(0, REG_INT_MASK);
874 /* -------------------------------------------------------------- */
876 static unsigned int dsp1 = -1;
877 static unsigned int dsp2 = -1;
878 static unsigned int mixer = -1;
879 static int latency = -1;
880 static int digital = 1;
881 static int analog = 1;
884 #define BTA_OSPREY200 1
886 static struct cardinfo cards[] = {
892 .name = "Osprey 200",
897 static int __devinit btaudio_probe(struct pci_dev *pci_dev,
898 const struct pci_device_id *pci_id)
901 struct cardinfo *card = &cards[pci_id->driver_data];
902 unsigned char revision,lat;
905 if (pci_enable_device(pci_dev))
907 if (!request_mem_region(pci_resource_start(pci_dev,0),
908 pci_resource_len(pci_dev,0),
913 bta = kmalloc(sizeof(*bta),GFP_ATOMIC);
918 memset(bta,0,sizeof(*bta));
921 bta->irq = pci_dev->irq;
922 bta->mem = pci_resource_start(pci_dev,0);
923 bta->mmio = ioremap(pci_resource_start(pci_dev,0),
924 pci_resource_len(pci_dev,0));
930 bta->decimation = 15;
933 bta->sampleshift = 1;
937 bta->rate = card->rate;
941 init_MUTEX(&bta->lock);
942 init_waitqueue_head(&bta->readq);
945 printk(KERN_INFO "btaudio: setting pci latency timer to %d\n",
947 pci_write_config_byte(pci_dev, PCI_LATENCY_TIMER, latency);
949 pci_read_config_byte(pci_dev, PCI_CLASS_REVISION, &revision);
950 pci_read_config_byte(pci_dev, PCI_LATENCY_TIMER, &lat);
951 printk(KERN_INFO "btaudio: Bt%x (rev %d) at %02x:%02x.%x, ",
952 pci_dev->device,revision,pci_dev->bus->number,
953 PCI_SLOT(pci_dev->devfn),PCI_FUNC(pci_dev->devfn));
954 printk("irq: %d, latency: %d, mmio: 0x%lx\n",
955 bta->irq, lat, bta->mem);
956 printk("btaudio: using card config \"%s\"\n", card->name);
959 btwrite(0, REG_GPIO_DMA_CTL);
960 btwrite(0, REG_INT_MASK);
961 btwrite(~0x0UL, REG_INT_STAT);
962 pci_set_master(pci_dev);
964 if ((rc = request_irq(bta->irq, btaudio_irq, SA_SHIRQ|SA_INTERRUPT,
965 "btaudio",(void *)bta)) < 0) {
967 "btaudio: can't request irq (rc=%d)\n",rc);
971 /* register devices */
973 rc = bta->dsp_digital =
974 register_sound_dsp(&btaudio_digital_dsp_fops,dsp1);
977 "btaudio: can't register digital dsp (rc=%d)\n",rc);
980 printk(KERN_INFO "btaudio: registered device dsp%d [digital]\n",
981 bta->dsp_digital >> 4);
984 rc = bta->dsp_analog =
985 register_sound_dsp(&btaudio_analog_dsp_fops,dsp2);
988 "btaudio: can't register analog dsp (rc=%d)\n",rc);
991 printk(KERN_INFO "btaudio: registered device dsp%d [analog]\n",
992 bta->dsp_analog >> 4);
993 rc = bta->mixer_dev = register_sound_mixer(&btaudio_mixer_fops,mixer);
996 "btaudio: can't register mixer (rc=%d)\n",rc);
999 printk(KERN_INFO "btaudio: registered device mixer%d\n",
1000 bta->mixer_dev >> 4);
1003 /* hook into linked list */
1004 bta->next = btaudios;
1007 pci_set_drvdata(pci_dev,bta);
1011 unregister_sound_dsp(bta->dsp_analog);
1014 unregister_sound_dsp(bta->dsp_digital);
1016 free_irq(bta->irq,bta);
1020 release_mem_region(pci_resource_start(pci_dev,0),
1021 pci_resource_len(pci_dev,0));
1025 static void __devexit btaudio_remove(struct pci_dev *pci_dev)
1027 struct btaudio *bta = pci_get_drvdata(pci_dev);
1028 struct btaudio *walk;
1030 /* turn off all DMA / IRQs */
1031 btand(~15, REG_GPIO_DMA_CTL);
1032 btwrite(0, REG_INT_MASK);
1033 btwrite(~0x0UL, REG_INT_STAT);
1035 /* unregister devices */
1037 unregister_sound_dsp(bta->dsp_digital);
1040 unregister_sound_dsp(bta->dsp_analog);
1041 unregister_sound_mixer(bta->mixer_dev);
1044 /* free resources */
1046 free_irq(bta->irq,bta);
1047 release_mem_region(pci_resource_start(pci_dev,0),
1048 pci_resource_len(pci_dev,0));
1050 /* remove from linked list */
1051 if (bta == btaudios) {
1054 for (walk = btaudios; walk->next != bta; walk = walk->next)
1055 ; /* if (NULL == walk->next) BUG(); */
1056 walk->next = bta->next;
1059 pci_set_drvdata(pci_dev, NULL);
1064 /* -------------------------------------------------------------- */
1066 static struct pci_device_id btaudio_pci_tbl[] = {
1068 .vendor = PCI_VENDOR_ID_BROOKTREE,
1070 .subvendor = 0x0070,
1071 .subdevice = 0xff01,
1072 .driver_data = BTA_OSPREY200,
1074 .vendor = PCI_VENDOR_ID_BROOKTREE,
1076 .subvendor = PCI_ANY_ID,
1077 .subdevice = PCI_ANY_ID,
1079 .vendor = PCI_VENDOR_ID_BROOKTREE,
1081 .subvendor = PCI_ANY_ID,
1082 .subdevice = PCI_ANY_ID,
1084 /* --- end of list --- */
1088 static struct pci_driver btaudio_pci_driver = {
1090 .id_table = btaudio_pci_tbl,
1091 .probe = btaudio_probe,
1092 .remove = __devexit_p(btaudio_remove),
1095 static int btaudio_init_module(void)
1097 printk(KERN_INFO "btaudio: driver version 0.7 loaded [%s%s%s]\n",
1098 digital ? "digital" : "",
1099 analog && digital ? "+" : "",
1100 analog ? "analog" : "");
1101 return pci_module_init(&btaudio_pci_driver);
1104 static void btaudio_cleanup_module(void)
1106 pci_unregister_driver(&btaudio_pci_driver);
1110 module_init(btaudio_init_module);
1111 module_exit(btaudio_cleanup_module);
1113 MODULE_PARM(dsp1,"i");
1114 MODULE_PARM(dsp2,"i");
1115 MODULE_PARM(mixer,"i");
1116 MODULE_PARM(debug,"i");
1117 MODULE_PARM(irq_debug,"i");
1118 MODULE_PARM(digital,"i");
1119 MODULE_PARM(analog,"i");
1120 MODULE_PARM(rate,"i");
1121 MODULE_PARM(latency,"i");
1122 MODULE_PARM_DESC(latency,"pci latency timer");
1124 MODULE_DEVICE_TABLE(pci, btaudio_pci_tbl);
1125 MODULE_DESCRIPTION("bt878 audio dma driver");
1126 MODULE_AUTHOR("Gerd Knorr");
1127 MODULE_LICENSE("GPL");