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 /* -------------------------------------------------------------- */
107 unsigned long __iomem
*mmio
;
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
;
330 void __user
*argp
= (void __user
*)arg
;
332 if (cmd
== SOUND_MIXER_INFO
) {
334 memset(&info
,0,sizeof(info
));
335 strlcpy(info
.id
,"bt878",sizeof(info
.id
));
336 strlcpy(info
.name
,"Brooktree Bt878 audio",sizeof(info
.name
));
337 info
.modify_counter
= bta
->mixcount
;
338 if (copy_to_user(argp
, &info
, sizeof(info
)))
342 if (cmd
== SOUND_OLD_MIXER_INFO
) {
343 _old_mixer_info info
;
344 memset(&info
,0,sizeof(info
));
345 strlcpy(info
.id
,"bt878",sizeof(info
.id
)-1);
346 strlcpy(info
.name
,"Brooktree Bt878 audio",sizeof(info
.name
));
347 if (copy_to_user(argp
, &info
, sizeof(info
)))
351 if (cmd
== OSS_GETVERSION
)
352 return put_user(SOUND_VERSION
, (int __user
*)argp
);
355 if (_SIOC_DIR(cmd
) & _SIOC_WRITE
)
356 if (get_user(val
, (int __user
*)argp
))
360 case MIXER_READ(SOUND_MIXER_CAPS
):
361 ret
= SOUND_CAP_EXCL_INPUT
;
363 case MIXER_READ(SOUND_MIXER_STEREODEVS
):
366 case MIXER_READ(SOUND_MIXER_RECMASK
):
367 case MIXER_READ(SOUND_MIXER_DEVMASK
):
368 ret
= SOUND_MASK_LINE1
|SOUND_MASK_LINE2
|SOUND_MASK_LINE3
;
371 case MIXER_WRITE(SOUND_MIXER_RECSRC
):
372 if (val
& SOUND_MASK_LINE1
&& bta
->source
!= 0)
374 else if (val
& SOUND_MASK_LINE2
&& bta
->source
!= 1)
376 else if (val
& SOUND_MASK_LINE3
&& bta
->source
!= 2)
378 btaor((bta
->gain
[bta
->source
] << 28) |
380 0x0cffffff, REG_GPIO_DMA_CTL
);
381 case MIXER_READ(SOUND_MIXER_RECSRC
):
382 switch (bta
->source
) {
383 case 0: ret
= SOUND_MASK_LINE1
; break;
384 case 1: ret
= SOUND_MASK_LINE2
; break;
385 case 2: ret
= SOUND_MASK_LINE3
; break;
390 case MIXER_WRITE(SOUND_MIXER_LINE1
):
391 case MIXER_WRITE(SOUND_MIXER_LINE2
):
392 case MIXER_WRITE(SOUND_MIXER_LINE3
):
393 if (MIXER_WRITE(SOUND_MIXER_LINE1
) == cmd
)
395 if (MIXER_WRITE(SOUND_MIXER_LINE2
) == cmd
)
397 if (MIXER_WRITE(SOUND_MIXER_LINE3
) == cmd
)
399 bta
->gain
[i
] = (val
& 0xff) * 15 / 100;
400 if (bta
->gain
[i
] > 15) bta
->gain
[i
] = 15;
401 if (bta
->gain
[i
] < 0) bta
->gain
[i
] = 0;
402 if (i
== bta
->source
)
403 btaor((bta
->gain
[bta
->source
]<<28),
404 0x0fffffff, REG_GPIO_DMA_CTL
);
405 ret
= bta
->gain
[i
] * 100 / 15;
409 case MIXER_READ(SOUND_MIXER_LINE1
):
410 case MIXER_READ(SOUND_MIXER_LINE2
):
411 case MIXER_READ(SOUND_MIXER_LINE3
):
412 if (MIXER_READ(SOUND_MIXER_LINE1
) == cmd
)
414 if (MIXER_READ(SOUND_MIXER_LINE2
) == cmd
)
416 if (MIXER_READ(SOUND_MIXER_LINE3
) == cmd
)
418 ret
= bta
->gain
[i
] * 100 / 15;
425 if (put_user(ret
, (int __user
*)argp
))
430 static struct file_operations btaudio_mixer_fops
= {
431 .owner
= THIS_MODULE
,
433 .open
= btaudio_mixer_open
,
434 .release
= btaudio_mixer_release
,
435 .ioctl
= btaudio_mixer_ioctl
,
438 /* -------------------------------------------------------------- */
440 static int btaudio_dsp_open(struct inode
*inode
, struct file
*file
,
441 struct btaudio
*bta
, int analog
)
447 file
->private_data
= bta
;
449 bta
->analog
= analog
;
451 bta
->read_offset
= 0;
453 bta
->sampleshift
= 0;
463 static int btaudio_dsp_open_digital(struct inode
*inode
, struct file
*file
)
465 int minor
= iminor(inode
);
468 for (bta
= btaudios
; bta
!= NULL
; bta
= bta
->next
)
469 if (bta
->dsp_digital
== minor
)
475 printk("btaudio: open digital dsp [%d]\n",minor
);
476 return btaudio_dsp_open(inode
,file
,bta
,0);
479 static int btaudio_dsp_open_analog(struct inode
*inode
, struct file
*file
)
481 int minor
= iminor(inode
);
484 for (bta
= btaudios
; bta
!= NULL
; bta
= bta
->next
)
485 if (bta
->dsp_analog
== minor
)
491 printk("btaudio: open analog dsp [%d]\n",minor
);
492 return btaudio_dsp_open(inode
,file
,bta
,1);
495 static int btaudio_dsp_release(struct inode
*inode
, struct file
*file
)
497 struct btaudio
*bta
= file
->private_data
;
507 static ssize_t
btaudio_dsp_read(struct file
*file
, char __user
*buffer
,
508 size_t swcount
, loff_t
*ppos
)
510 struct btaudio
*bta
= file
->private_data
;
511 int hwcount
= swcount
<< bta
->sampleshift
;
512 int nsrc
, ndst
, err
, ret
= 0;
513 DECLARE_WAITQUEUE(wait
, current
);
515 add_wait_queue(&bta
->readq
, &wait
);
517 while (swcount
> 0) {
518 if (0 == bta
->read_count
) {
519 if (!bta
->recording
) {
520 if (0 != (err
= start_recording(bta
))) {
526 if (file
->f_flags
& O_NONBLOCK
) {
532 current
->state
= TASK_INTERRUPTIBLE
;
535 if(signal_pending(current
)) {
541 nsrc
= (bta
->read_count
< hwcount
) ? bta
->read_count
: hwcount
;
542 if (nsrc
> bta
->buf_size
- bta
->read_offset
)
543 nsrc
= bta
->buf_size
- bta
->read_offset
;
544 ndst
= nsrc
>> bta
->sampleshift
;
546 if ((bta
->analog
&& 0 == bta
->sampleshift
) ||
547 (!bta
->analog
&& 2 == bta
->channels
)) {
549 if (copy_to_user(buffer
+ ret
, bta
->buf_cpu
+ bta
->read_offset
, nsrc
)) {
555 } else if (!bta
->analog
) {
556 /* stereo => mono (digital audio) */
557 __s16
*src
= (__s16
*)(bta
->buf_cpu
+ bta
->read_offset
);
558 __s16 __user
*dst
= (__s16 __user
*)(buffer
+ ret
);
561 if (!access_ok(VERIFY_WRITE
, dst
, ndst
)) {
566 for (; n
; n
--, dst
++) {
567 avg
= (__s16
)le16_to_cpu(*src
) / 2; src
++;
568 avg
+= (__s16
)le16_to_cpu(*src
) / 2; src
++;
569 __put_user(cpu_to_le16(avg
),dst
);
572 } else if (8 == bta
->bits
) {
573 /* copy + byte downsampling (audio A/D) */
574 __u8
*src
= bta
->buf_cpu
+ bta
->read_offset
;
575 __u8 __user
*dst
= buffer
+ ret
;
577 if (!access_ok(VERIFY_WRITE
, dst
, ndst
)) {
582 for (; n
; n
--, src
+= (1 << bta
->sampleshift
), dst
++)
583 __put_user(*src
, dst
);
586 /* copy + word downsampling (audio A/D) */
587 __u16
*src
= (__u16
*)(bta
->buf_cpu
+ bta
->read_offset
);
588 __u16 __user
*dst
= (__u16 __user
*)(buffer
+ ret
);
590 if (!access_ok(VERIFY_WRITE
,dst
,ndst
)) {
595 for (; n
; n
--, src
+= (1 << bta
->sampleshift
), dst
++)
596 __put_user(*src
, dst
);
602 bta
->read_count
-= nsrc
;
603 bta
->read_offset
+= nsrc
;
604 if (bta
->read_offset
== bta
->buf_size
)
605 bta
->read_offset
= 0;
608 remove_wait_queue(&bta
->readq
, &wait
);
609 current
->state
= TASK_RUNNING
;
613 static ssize_t
btaudio_dsp_write(struct file
*file
, const char __user
*buffer
,
614 size_t count
, loff_t
*ppos
)
619 static int btaudio_dsp_ioctl(struct inode
*inode
, struct file
*file
,
620 unsigned int cmd
, unsigned long arg
)
622 struct btaudio
*bta
= file
->private_data
;
623 int s
, i
, ret
, val
= 0;
624 void __user
*argp
= (void __user
*)arg
;
625 int __user
*p
= argp
;
629 return put_user(SOUND_VERSION
, p
);
630 case SNDCTL_DSP_GETCAPS
:
633 case SNDCTL_DSP_SPEED
:
634 if (get_user(val
, p
))
637 for (s
= 0; s
< 16; s
++)
638 if (val
<< s
>= HWBASE_AD
*4/15)
640 for (i
= 15; i
>= 5; i
--)
641 if (val
<< s
<= HWBASE_AD
*4/i
)
643 bta
->sampleshift
= s
;
646 printk(KERN_DEBUG
"btaudio: rate: req=%d "
647 "dec=%d shift=%d hwrate=%d swrate=%d\n",
648 val
,i
,s
,(HWBASE_AD
*4/i
),(HWBASE_AD
*4/i
)>>s
);
650 bta
->sampleshift
= (bta
->channels
== 2) ? 0 : 1;
653 if (bta
->recording
) {
656 start_recording(bta
);
660 case SOUND_PCM_READ_RATE
:
662 return put_user(HWBASE_AD
*4/bta
->decimation
>>bta
->sampleshift
, p
);
664 return put_user(bta
->rate
, p
);
667 case SNDCTL_DSP_STEREO
:
669 if (get_user(val
, p
))
671 bta
->channels
= (val
> 0) ? 2 : 1;
672 bta
->sampleshift
= (bta
->channels
== 2) ? 0 : 1;
675 "btaudio: stereo=%d channels=%d\n",
684 "btaudio: stereo=0 channels=1\n");
687 return put_user((bta
->channels
)-1, p
);
689 case SNDCTL_DSP_CHANNELS
:
691 if (get_user(val
, p
))
693 bta
->channels
= (val
> 1) ? 2 : 1;
694 bta
->sampleshift
= (bta
->channels
== 2) ? 0 : 1;
697 "btaudio: val=%d channels=%d\n",
701 case SOUND_PCM_READ_CHANNELS
:
702 return put_user(bta
->channels
, p
);
704 case SNDCTL_DSP_GETFMTS
: /* Returns a mask */
706 return put_user(AFMT_S16_LE
|AFMT_S8
, p
);
708 return put_user(AFMT_S16_LE
, p
);
710 case SNDCTL_DSP_SETFMT
: /* Selects ONE fmt*/
711 if (get_user(val
, p
))
713 if (val
!= AFMT_QUERY
) {
715 bta
->bits
= (val
== AFMT_S8
) ? 8 : 16;
718 if (bta
->recording
) {
721 start_recording(bta
);
726 printk(KERN_DEBUG
"btaudio: fmt: bits=%d\n",bta
->bits
);
727 return put_user((bta
->bits
==16) ? AFMT_S16_LE
: AFMT_S8
,
730 case SOUND_PCM_READ_BITS
:
731 return put_user(bta
->bits
, p
);
733 case SNDCTL_DSP_NONBLOCK
:
734 file
->f_flags
|= O_NONBLOCK
;
737 case SNDCTL_DSP_RESET
:
738 if (bta
->recording
) {
744 case SNDCTL_DSP_GETBLKSIZE
:
745 if (!bta
->recording
) {
746 if (0 != (ret
= alloc_buffer(bta
)))
748 if (0 != (ret
= make_risc(bta
)))
751 return put_user(bta
->block_bytes
>>bta
->sampleshift
,p
);
753 case SNDCTL_DSP_SYNC
:
756 case SNDCTL_DSP_GETISPACE
:
761 info
.fragsize
= bta
->block_bytes
>>bta
->sampleshift
;
762 info
.fragstotal
= bta
->block_count
;
763 info
.bytes
= bta
->read_count
;
764 info
.fragments
= info
.bytes
/ info
.fragsize
;
766 printk(KERN_DEBUG
"btaudio: SNDCTL_DSP_GETISPACE "
767 "returns %d/%d/%d/%d\n",
768 info
.fragsize
, info
.fragstotal
,
769 info
.bytes
, info
.fragments
);
770 if (copy_to_user(argp
, &info
, sizeof(info
)))
775 case SNDCTL_DSP_GETTRIGGER
:
776 case SNDCTL_DSP_SETTRIGGER
:
777 case SNDCTL_DSP_SETFRAGMENT
:
784 static unsigned int btaudio_dsp_poll(struct file
*file
, struct poll_table_struct
*wait
)
786 struct btaudio
*bta
= file
->private_data
;
787 unsigned int mask
= 0;
789 poll_wait(file
, &bta
->readq
, wait
);
791 if (0 != bta
->read_count
)
792 mask
|= (POLLIN
| POLLRDNORM
);
797 static struct file_operations btaudio_digital_dsp_fops
= {
798 .owner
= THIS_MODULE
,
800 .open
= btaudio_dsp_open_digital
,
801 .release
= btaudio_dsp_release
,
802 .read
= btaudio_dsp_read
,
803 .write
= btaudio_dsp_write
,
804 .ioctl
= btaudio_dsp_ioctl
,
805 .poll
= btaudio_dsp_poll
,
808 static struct file_operations btaudio_analog_dsp_fops
= {
809 .owner
= THIS_MODULE
,
811 .open
= btaudio_dsp_open_analog
,
812 .release
= btaudio_dsp_release
,
813 .read
= btaudio_dsp_read
,
814 .write
= btaudio_dsp_write
,
815 .ioctl
= btaudio_dsp_ioctl
,
816 .poll
= btaudio_dsp_poll
,
819 /* -------------------------------------------------------------- */
821 static char *irq_name
[] = { "", "", "", "OFLOW", "", "", "", "", "", "", "",
822 "RISCI", "FBUS", "FTRGT", "FDSR", "PPERR",
823 "RIPERR", "PABORT", "OCERR", "SCERR" };
825 static irqreturn_t
btaudio_irq(int irq
, void *dev_id
, struct pt_regs
* regs
)
829 struct btaudio
*bta
= dev_id
;
834 stat
= btread(REG_INT_STAT
);
835 astat
= stat
& btread(REG_INT_MASK
);
837 return IRQ_RETVAL(handled
);
839 btwrite(astat
,REG_INT_STAT
);
843 printk(KERN_DEBUG
"btaudio: irq loop=%d risc=%x, bits:",
845 for (i
= 0; i
< (sizeof(irq_name
)/sizeof(char*)); i
++) {
847 printk(" %s",irq_name
[i
]);
848 if (astat
& (1 << i
))
853 if (stat
& IRQ_RISCI
) {
855 blocks
= (stat
>> 28) - bta
->dma_block
;
857 blocks
+= bta
->block_count
;
858 bta
->dma_block
= stat
>> 28;
859 if (bta
->read_count
+ 2*bta
->block_bytes
> bta
->buf_size
) {
861 printk(KERN_INFO
"btaudio: buffer overrun\n");
864 bta
->read_count
+= blocks
* bta
->block_bytes
;
865 wake_up_interruptible(&bta
->readq
);
870 "btaudio: Oops - irq mask cleared\n");
871 btwrite(0, REG_INT_MASK
);
877 /* -------------------------------------------------------------- */
879 static unsigned int dsp1
= -1;
880 static unsigned int dsp2
= -1;
881 static unsigned int mixer
= -1;
882 static int latency
= -1;
883 static int digital
= 1;
884 static int analog
= 1;
887 #define BTA_OSPREY200 1
889 static struct cardinfo cards
[] = {
895 .name
= "Osprey 200",
900 static int __devinit
btaudio_probe(struct pci_dev
*pci_dev
,
901 const struct pci_device_id
*pci_id
)
904 struct cardinfo
*card
= &cards
[pci_id
->driver_data
];
905 unsigned char revision
,lat
;
908 if (pci_enable_device(pci_dev
))
910 if (!request_mem_region(pci_resource_start(pci_dev
,0),
911 pci_resource_len(pci_dev
,0),
916 bta
= kmalloc(sizeof(*bta
),GFP_ATOMIC
);
921 memset(bta
,0,sizeof(*bta
));
924 bta
->irq
= pci_dev
->irq
;
925 bta
->mem
= pci_resource_start(pci_dev
,0);
926 bta
->mmio
= ioremap(pci_resource_start(pci_dev
,0),
927 pci_resource_len(pci_dev
,0));
933 bta
->decimation
= 15;
936 bta
->sampleshift
= 1;
940 bta
->rate
= card
->rate
;
944 init_MUTEX(&bta
->lock
);
945 init_waitqueue_head(&bta
->readq
);
948 printk(KERN_INFO
"btaudio: setting pci latency timer to %d\n",
950 pci_write_config_byte(pci_dev
, PCI_LATENCY_TIMER
, latency
);
952 pci_read_config_byte(pci_dev
, PCI_CLASS_REVISION
, &revision
);
953 pci_read_config_byte(pci_dev
, PCI_LATENCY_TIMER
, &lat
);
954 printk(KERN_INFO
"btaudio: Bt%x (rev %d) at %02x:%02x.%x, ",
955 pci_dev
->device
,revision
,pci_dev
->bus
->number
,
956 PCI_SLOT(pci_dev
->devfn
),PCI_FUNC(pci_dev
->devfn
));
957 printk("irq: %d, latency: %d, mmio: 0x%lx\n",
958 bta
->irq
, lat
, bta
->mem
);
959 printk("btaudio: using card config \"%s\"\n", card
->name
);
962 btwrite(0, REG_GPIO_DMA_CTL
);
963 btwrite(0, REG_INT_MASK
);
964 btwrite(~0U, REG_INT_STAT
);
965 pci_set_master(pci_dev
);
967 if ((rc
= request_irq(bta
->irq
, btaudio_irq
, SA_SHIRQ
|SA_INTERRUPT
,
968 "btaudio",(void *)bta
)) < 0) {
970 "btaudio: can't request irq (rc=%d)\n",rc
);
974 /* register devices */
976 rc
= bta
->dsp_digital
=
977 register_sound_dsp(&btaudio_digital_dsp_fops
,dsp1
);
980 "btaudio: can't register digital dsp (rc=%d)\n",rc
);
983 printk(KERN_INFO
"btaudio: registered device dsp%d [digital]\n",
984 bta
->dsp_digital
>> 4);
987 rc
= bta
->dsp_analog
=
988 register_sound_dsp(&btaudio_analog_dsp_fops
,dsp2
);
991 "btaudio: can't register analog dsp (rc=%d)\n",rc
);
994 printk(KERN_INFO
"btaudio: registered device dsp%d [analog]\n",
995 bta
->dsp_analog
>> 4);
996 rc
= bta
->mixer_dev
= register_sound_mixer(&btaudio_mixer_fops
,mixer
);
999 "btaudio: can't register mixer (rc=%d)\n",rc
);
1002 printk(KERN_INFO
"btaudio: registered device mixer%d\n",
1003 bta
->mixer_dev
>> 4);
1006 /* hook into linked list */
1007 bta
->next
= btaudios
;
1010 pci_set_drvdata(pci_dev
,bta
);
1014 unregister_sound_dsp(bta
->dsp_analog
);
1017 unregister_sound_dsp(bta
->dsp_digital
);
1019 free_irq(bta
->irq
,bta
);
1023 release_mem_region(pci_resource_start(pci_dev
,0),
1024 pci_resource_len(pci_dev
,0));
1028 static void __devexit
btaudio_remove(struct pci_dev
*pci_dev
)
1030 struct btaudio
*bta
= pci_get_drvdata(pci_dev
);
1031 struct btaudio
*walk
;
1033 /* turn off all DMA / IRQs */
1034 btand(~15, REG_GPIO_DMA_CTL
);
1035 btwrite(0, REG_INT_MASK
);
1036 btwrite(~0U, REG_INT_STAT
);
1038 /* unregister devices */
1040 unregister_sound_dsp(bta
->dsp_digital
);
1043 unregister_sound_dsp(bta
->dsp_analog
);
1044 unregister_sound_mixer(bta
->mixer_dev
);
1047 /* free resources */
1049 free_irq(bta
->irq
,bta
);
1050 release_mem_region(pci_resource_start(pci_dev
,0),
1051 pci_resource_len(pci_dev
,0));
1053 /* remove from linked list */
1054 if (bta
== btaudios
) {
1057 for (walk
= btaudios
; walk
->next
!= bta
; walk
= walk
->next
)
1058 ; /* if (NULL == walk->next) BUG(); */
1059 walk
->next
= bta
->next
;
1062 pci_set_drvdata(pci_dev
, NULL
);
1067 /* -------------------------------------------------------------- */
1069 static struct pci_device_id btaudio_pci_tbl
[] = {
1071 .vendor
= PCI_VENDOR_ID_BROOKTREE
,
1073 .subvendor
= 0x0070,
1074 .subdevice
= 0xff01,
1075 .driver_data
= BTA_OSPREY200
,
1077 .vendor
= PCI_VENDOR_ID_BROOKTREE
,
1079 .subvendor
= PCI_ANY_ID
,
1080 .subdevice
= PCI_ANY_ID
,
1082 .vendor
= PCI_VENDOR_ID_BROOKTREE
,
1084 .subvendor
= PCI_ANY_ID
,
1085 .subdevice
= PCI_ANY_ID
,
1087 /* --- end of list --- */
1091 static struct pci_driver btaudio_pci_driver
= {
1093 .id_table
= btaudio_pci_tbl
,
1094 .probe
= btaudio_probe
,
1095 .remove
= __devexit_p(btaudio_remove
),
1098 static int btaudio_init_module(void)
1100 printk(KERN_INFO
"btaudio: driver version 0.7 loaded [%s%s%s]\n",
1101 digital
? "digital" : "",
1102 analog
&& digital
? "+" : "",
1103 analog
? "analog" : "");
1104 return pci_register_driver(&btaudio_pci_driver
);
1107 static void btaudio_cleanup_module(void)
1109 pci_unregister_driver(&btaudio_pci_driver
);
1113 module_init(btaudio_init_module
);
1114 module_exit(btaudio_cleanup_module
);
1116 module_param(dsp1
, int, S_IRUGO
);
1117 module_param(dsp2
, int, S_IRUGO
);
1118 module_param(mixer
, int, S_IRUGO
);
1119 module_param(debug
, int, S_IRUGO
| S_IWUSR
);
1120 module_param(irq_debug
, int, S_IRUGO
| S_IWUSR
);
1121 module_param(digital
, int, S_IRUGO
);
1122 module_param(analog
, int, S_IRUGO
);
1123 module_param(rate
, int, S_IRUGO
);
1124 module_param(latency
, int, S_IRUGO
);
1125 MODULE_PARM_DESC(latency
,"pci latency timer");
1127 MODULE_DEVICE_TABLE(pci
, btaudio_pci_tbl
);
1128 MODULE_DESCRIPTION("bt878 audio dma driver");
1129 MODULE_AUTHOR("Gerd Knorr");
1130 MODULE_LICENSE("GPL");