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 <linux/mutex.h>
37 #include <asm/uaccess.h>
42 #define btwrite(dat,adr) writel((dat), (bta->mmio+(adr)))
43 #define btread(adr) readl(bta->mmio+(adr))
45 #define btand(dat,adr) btwrite((dat) & btread(adr), adr)
46 #define btor(dat,adr) btwrite((dat) | btread(adr), adr)
47 #define btaor(dat,mask,adr) btwrite((dat) | ((mask) & btread(adr)), adr)
49 /* registers (shifted because bta->mmio is long) */
50 #define REG_INT_STAT (0x100 >> 2)
51 #define REG_INT_MASK (0x104 >> 2)
52 #define REG_GPIO_DMA_CTL (0x10c >> 2)
53 #define REG_PACKET_LEN (0x110 >> 2)
54 #define REG_RISC_STRT_ADD (0x114 >> 2)
55 #define REG_RISC_COUNT (0x120 >> 2)
57 /* IRQ bits - REG_INT_(STAT|MASK) */
58 #define IRQ_SCERR (1 << 19)
59 #define IRQ_OCERR (1 << 18)
60 #define IRQ_PABORT (1 << 17)
61 #define IRQ_RIPERR (1 << 16)
62 #define IRQ_PPERR (1 << 15)
63 #define IRQ_FDSR (1 << 14)
64 #define IRQ_FTRGT (1 << 13)
65 #define IRQ_FBUS (1 << 12)
66 #define IRQ_RISCI (1 << 11)
67 #define IRQ_OFLOW (1 << 3)
69 #define IRQ_BTAUDIO (IRQ_SCERR | IRQ_OCERR | IRQ_PABORT | IRQ_RIPERR |\
70 IRQ_PPERR | IRQ_FDSR | IRQ_FTRGT | IRQ_FBUS |\
73 /* REG_GPIO_DMA_CTL bits */
74 #define DMA_CTL_A_PWRDN (1 << 26)
75 #define DMA_CTL_DA_SBR (1 << 14)
76 #define DMA_CTL_DA_ES2 (1 << 13)
77 #define DMA_CTL_ACAP_EN (1 << 4)
78 #define DMA_CTL_RISC_EN (1 << 1)
79 #define DMA_CTL_FIFO_EN (1 << 0)
81 /* RISC instructions */
82 #define RISC_WRITE (0x01 << 28)
83 #define RISC_JUMP (0x07 << 28)
84 #define RISC_SYNC (0x08 << 28)
87 #define RISC_WR_SOL (1 << 27)
88 #define RISC_WR_EOL (1 << 26)
89 #define RISC_IRQ (1 << 24)
90 #define RISC_SYNC_RESYNC (1 << 15)
91 #define RISC_SYNC_FM1 0x06
92 #define RISC_SYNC_VRO 0x0c
94 #define HWBASE_AD (448000)
96 /* -------------------------------------------------------------- */
100 struct btaudio
*next
;
109 unsigned long __iomem
*mmio
;
115 /* risc instructions */
116 unsigned int risc_size
;
117 unsigned long *risc_cpu
;
121 unsigned int buf_size
;
122 unsigned char *buf_cpu
;
131 /* read fifo management */
136 wait_queue_head_t readq
;
155 static struct btaudio
*btaudios
;
156 static unsigned int debug
;
157 static unsigned int irq_debug
;
159 /* -------------------------------------------------------------- */
161 #define BUF_DEFAULT 128*1024
164 static int alloc_buffer(struct btaudio
*bta
)
166 if (NULL
== bta
->buf_cpu
) {
167 for (bta
->buf_size
= BUF_DEFAULT
; bta
->buf_size
>= BUF_MIN
;
168 bta
->buf_size
= bta
->buf_size
>> 1) {
169 bta
->buf_cpu
= pci_alloc_consistent
170 (bta
->pci
, bta
->buf_size
, &bta
->buf_dma
);
171 if (NULL
!= bta
->buf_cpu
)
174 if (NULL
== bta
->buf_cpu
)
176 memset(bta
->buf_cpu
,0,bta
->buf_size
);
178 if (NULL
== bta
->risc_cpu
) {
179 bta
->risc_size
= PAGE_SIZE
;
180 bta
->risc_cpu
= pci_alloc_consistent
181 (bta
->pci
, bta
->risc_size
, &bta
->risc_dma
);
182 if (NULL
== bta
->risc_cpu
) {
183 pci_free_consistent(bta
->pci
, bta
->buf_size
, bta
->buf_cpu
, bta
->buf_dma
);
191 static void free_buffer(struct btaudio
*bta
)
193 if (NULL
!= bta
->buf_cpu
) {
194 pci_free_consistent(bta
->pci
, bta
->buf_size
,
195 bta
->buf_cpu
, bta
->buf_dma
);
198 if (NULL
!= bta
->risc_cpu
) {
199 pci_free_consistent(bta
->pci
, bta
->risc_size
,
200 bta
->risc_cpu
, bta
->risc_dma
);
201 bta
->risc_cpu
= NULL
;
205 static int make_risc(struct btaudio
*bta
)
207 int rp
, bp
, line
, block
;
210 bta
->block_bytes
= bta
->buf_size
>> 4;
211 bta
->block_count
= 1 << 4;
212 bta
->line_bytes
= bta
->block_bytes
;
213 bta
->line_count
= bta
->block_count
;
214 while (bta
->line_bytes
> 4095) {
215 bta
->line_bytes
>>= 1;
216 bta
->line_count
<<= 1;
218 if (bta
->line_count
> 255)
222 "btaudio: bufsize=%d - bs=%d bc=%d - ls=%d, lc=%d\n",
223 bta
->buf_size
,bta
->block_bytes
,bta
->block_count
,
224 bta
->line_bytes
,bta
->line_count
);
227 bta
->risc_cpu
[rp
++] = cpu_to_le32(RISC_SYNC
|RISC_SYNC_FM1
);
228 bta
->risc_cpu
[rp
++] = cpu_to_le32(0);
229 for (line
= 0; line
< bta
->line_count
; line
++) {
230 risc
= RISC_WRITE
| RISC_WR_SOL
| RISC_WR_EOL
;
231 risc
|= bta
->line_bytes
;
232 if (0 == (bp
& (bta
->block_bytes
-1))) {
234 risc
|= (block
& 0x0f) << 16;
235 risc
|= (~block
& 0x0f) << 20;
238 bta
->risc_cpu
[rp
++] = cpu_to_le32(risc
);
239 bta
->risc_cpu
[rp
++] = cpu_to_le32(bta
->buf_dma
+ bp
);
240 bp
+= bta
->line_bytes
;
242 bta
->risc_cpu
[rp
++] = cpu_to_le32(RISC_SYNC
|RISC_SYNC_VRO
);
243 bta
->risc_cpu
[rp
++] = cpu_to_le32(0);
244 bta
->risc_cpu
[rp
++] = cpu_to_le32(RISC_JUMP
);
245 bta
->risc_cpu
[rp
++] = cpu_to_le32(bta
->risc_dma
);
249 static int start_recording(struct btaudio
*bta
)
253 if (0 != (ret
= alloc_buffer(bta
)))
255 if (0 != (ret
= make_risc(bta
)))
258 btwrite(bta
->risc_dma
, REG_RISC_STRT_ADD
);
259 btwrite((bta
->line_count
<< 16) | bta
->line_bytes
,
261 btwrite(IRQ_BTAUDIO
, REG_INT_MASK
);
263 btwrite(DMA_CTL_ACAP_EN
|
267 ((bta
->bits
== 8) ? DMA_CTL_DA_SBR
: 0) |
268 (bta
->gain
[bta
->source
] << 28) |
269 (bta
->source
<< 24) |
270 (bta
->decimation
<< 8),
273 btwrite(DMA_CTL_ACAP_EN
|
279 ((bta
->bits
== 8) ? DMA_CTL_DA_SBR
: 0) |
280 (bta
->gain
[bta
->source
] << 28) |
281 (bta
->source
<< 24) |
282 (bta
->decimation
<< 8),
286 bta
->read_offset
= 0;
290 printk(KERN_DEBUG
"btaudio: recording started\n");
294 static void stop_recording(struct btaudio
*bta
)
296 btand(~15, REG_GPIO_DMA_CTL
);
299 printk(KERN_DEBUG
"btaudio: recording stopped\n");
303 /* -------------------------------------------------------------- */
305 static int btaudio_mixer_open(struct inode
*inode
, struct file
*file
)
307 int minor
= iminor(inode
);
310 for (bta
= btaudios
; bta
!= NULL
; bta
= bta
->next
)
311 if (bta
->mixer_dev
== minor
)
317 printk("btaudio: open mixer [%d]\n",minor
);
318 file
->private_data
= bta
;
322 static int btaudio_mixer_release(struct inode
*inode
, struct file
*file
)
327 static int btaudio_mixer_ioctl(struct inode
*inode
, struct file
*file
,
328 unsigned int cmd
, unsigned long arg
)
330 struct btaudio
*bta
= file
->private_data
;
332 void __user
*argp
= (void __user
*)arg
;
334 if (cmd
== SOUND_MIXER_INFO
) {
336 memset(&info
,0,sizeof(info
));
337 strlcpy(info
.id
,"bt878",sizeof(info
.id
));
338 strlcpy(info
.name
,"Brooktree Bt878 audio",sizeof(info
.name
));
339 info
.modify_counter
= bta
->mixcount
;
340 if (copy_to_user(argp
, &info
, sizeof(info
)))
344 if (cmd
== SOUND_OLD_MIXER_INFO
) {
345 _old_mixer_info info
;
346 memset(&info
,0,sizeof(info
));
347 strlcpy(info
.id
, "bt878", sizeof(info
.id
));
348 strlcpy(info
.name
,"Brooktree Bt878 audio",sizeof(info
.name
));
349 if (copy_to_user(argp
, &info
, sizeof(info
)))
353 if (cmd
== OSS_GETVERSION
)
354 return put_user(SOUND_VERSION
, (int __user
*)argp
);
357 if (_SIOC_DIR(cmd
) & _SIOC_WRITE
)
358 if (get_user(val
, (int __user
*)argp
))
362 case MIXER_READ(SOUND_MIXER_CAPS
):
363 ret
= SOUND_CAP_EXCL_INPUT
;
365 case MIXER_READ(SOUND_MIXER_STEREODEVS
):
368 case MIXER_READ(SOUND_MIXER_RECMASK
):
369 case MIXER_READ(SOUND_MIXER_DEVMASK
):
370 ret
= SOUND_MASK_LINE1
|SOUND_MASK_LINE2
|SOUND_MASK_LINE3
;
373 case MIXER_WRITE(SOUND_MIXER_RECSRC
):
374 if (val
& SOUND_MASK_LINE1
&& bta
->source
!= 0)
376 else if (val
& SOUND_MASK_LINE2
&& bta
->source
!= 1)
378 else if (val
& SOUND_MASK_LINE3
&& bta
->source
!= 2)
380 btaor((bta
->gain
[bta
->source
] << 28) |
382 0x0cffffff, REG_GPIO_DMA_CTL
);
383 case MIXER_READ(SOUND_MIXER_RECSRC
):
384 switch (bta
->source
) {
385 case 0: ret
= SOUND_MASK_LINE1
; break;
386 case 1: ret
= SOUND_MASK_LINE2
; break;
387 case 2: ret
= SOUND_MASK_LINE3
; break;
392 case MIXER_WRITE(SOUND_MIXER_LINE1
):
393 case MIXER_WRITE(SOUND_MIXER_LINE2
):
394 case MIXER_WRITE(SOUND_MIXER_LINE3
):
395 if (MIXER_WRITE(SOUND_MIXER_LINE1
) == cmd
)
397 if (MIXER_WRITE(SOUND_MIXER_LINE2
) == cmd
)
399 if (MIXER_WRITE(SOUND_MIXER_LINE3
) == cmd
)
401 bta
->gain
[i
] = (val
& 0xff) * 15 / 100;
402 if (bta
->gain
[i
] > 15) bta
->gain
[i
] = 15;
403 if (bta
->gain
[i
] < 0) bta
->gain
[i
] = 0;
404 if (i
== bta
->source
)
405 btaor((bta
->gain
[bta
->source
]<<28),
406 0x0fffffff, REG_GPIO_DMA_CTL
);
407 ret
= bta
->gain
[i
] * 100 / 15;
411 case MIXER_READ(SOUND_MIXER_LINE1
):
412 case MIXER_READ(SOUND_MIXER_LINE2
):
413 case MIXER_READ(SOUND_MIXER_LINE3
):
414 if (MIXER_READ(SOUND_MIXER_LINE1
) == cmd
)
416 if (MIXER_READ(SOUND_MIXER_LINE2
) == cmd
)
418 if (MIXER_READ(SOUND_MIXER_LINE3
) == cmd
)
420 ret
= bta
->gain
[i
] * 100 / 15;
427 if (put_user(ret
, (int __user
*)argp
))
432 static const struct file_operations btaudio_mixer_fops
= {
433 .owner
= THIS_MODULE
,
435 .open
= btaudio_mixer_open
,
436 .release
= btaudio_mixer_release
,
437 .ioctl
= btaudio_mixer_ioctl
,
440 /* -------------------------------------------------------------- */
442 static int btaudio_dsp_open(struct inode
*inode
, struct file
*file
,
443 struct btaudio
*bta
, int analog
)
445 mutex_lock(&bta
->lock
);
449 file
->private_data
= bta
;
451 bta
->analog
= analog
;
453 bta
->read_offset
= 0;
455 bta
->sampleshift
= 0;
457 mutex_unlock(&bta
->lock
);
461 mutex_unlock(&bta
->lock
);
465 static int btaudio_dsp_open_digital(struct inode
*inode
, struct file
*file
)
467 int minor
= iminor(inode
);
470 for (bta
= btaudios
; bta
!= NULL
; bta
= bta
->next
)
471 if (bta
->dsp_digital
== minor
)
477 printk("btaudio: open digital dsp [%d]\n",minor
);
478 return btaudio_dsp_open(inode
,file
,bta
,0);
481 static int btaudio_dsp_open_analog(struct inode
*inode
, struct file
*file
)
483 int minor
= iminor(inode
);
486 for (bta
= btaudios
; bta
!= NULL
; bta
= bta
->next
)
487 if (bta
->dsp_analog
== minor
)
493 printk("btaudio: open analog dsp [%d]\n",minor
);
494 return btaudio_dsp_open(inode
,file
,bta
,1);
497 static int btaudio_dsp_release(struct inode
*inode
, struct file
*file
)
499 struct btaudio
*bta
= file
->private_data
;
501 mutex_lock(&bta
->lock
);
505 mutex_unlock(&bta
->lock
);
509 static ssize_t
btaudio_dsp_read(struct file
*file
, char __user
*buffer
,
510 size_t swcount
, loff_t
*ppos
)
512 struct btaudio
*bta
= file
->private_data
;
513 int hwcount
= swcount
<< bta
->sampleshift
;
514 int nsrc
, ndst
, err
, ret
= 0;
515 DECLARE_WAITQUEUE(wait
, current
);
517 add_wait_queue(&bta
->readq
, &wait
);
518 mutex_lock(&bta
->lock
);
519 while (swcount
> 0) {
520 if (0 == bta
->read_count
) {
521 if (!bta
->recording
) {
522 if (0 != (err
= start_recording(bta
))) {
528 if (file
->f_flags
& O_NONBLOCK
) {
533 mutex_unlock(&bta
->lock
);
534 current
->state
= TASK_INTERRUPTIBLE
;
536 mutex_lock(&bta
->lock
);
537 if(signal_pending(current
)) {
543 nsrc
= (bta
->read_count
< hwcount
) ? bta
->read_count
: hwcount
;
544 if (nsrc
> bta
->buf_size
- bta
->read_offset
)
545 nsrc
= bta
->buf_size
- bta
->read_offset
;
546 ndst
= nsrc
>> bta
->sampleshift
;
548 if ((bta
->analog
&& 0 == bta
->sampleshift
) ||
549 (!bta
->analog
&& 2 == bta
->channels
)) {
551 if (copy_to_user(buffer
+ ret
, bta
->buf_cpu
+ bta
->read_offset
, nsrc
)) {
557 } else if (!bta
->analog
) {
558 /* stereo => mono (digital audio) */
559 __s16
*src
= (__s16
*)(bta
->buf_cpu
+ bta
->read_offset
);
560 __s16 __user
*dst
= (__s16 __user
*)(buffer
+ ret
);
563 if (!access_ok(VERIFY_WRITE
, dst
, ndst
)) {
568 for (; n
; n
--, dst
++) {
569 avg
= (__s16
)le16_to_cpu(*src
) / 2; src
++;
570 avg
+= (__s16
)le16_to_cpu(*src
) / 2; src
++;
571 __put_user(cpu_to_le16(avg
),dst
);
574 } else if (8 == bta
->bits
) {
575 /* copy + byte downsampling (audio A/D) */
576 __u8
*src
= bta
->buf_cpu
+ bta
->read_offset
;
577 __u8 __user
*dst
= buffer
+ ret
;
579 if (!access_ok(VERIFY_WRITE
, dst
, ndst
)) {
584 for (; n
; n
--, src
+= (1 << bta
->sampleshift
), dst
++)
585 __put_user(*src
, dst
);
588 /* copy + word downsampling (audio A/D) */
589 __u16
*src
= (__u16
*)(bta
->buf_cpu
+ bta
->read_offset
);
590 __u16 __user
*dst
= (__u16 __user
*)(buffer
+ ret
);
592 if (!access_ok(VERIFY_WRITE
,dst
,ndst
)) {
597 for (; n
; n
--, src
+= (1 << bta
->sampleshift
), dst
++)
598 __put_user(*src
, dst
);
604 bta
->read_count
-= nsrc
;
605 bta
->read_offset
+= nsrc
;
606 if (bta
->read_offset
== bta
->buf_size
)
607 bta
->read_offset
= 0;
609 mutex_unlock(&bta
->lock
);
610 remove_wait_queue(&bta
->readq
, &wait
);
611 current
->state
= TASK_RUNNING
;
615 static ssize_t
btaudio_dsp_write(struct file
*file
, const char __user
*buffer
,
616 size_t count
, loff_t
*ppos
)
621 static int btaudio_dsp_ioctl(struct inode
*inode
, struct file
*file
,
622 unsigned int cmd
, unsigned long arg
)
624 struct btaudio
*bta
= file
->private_data
;
625 int s
, i
, ret
, val
= 0;
626 void __user
*argp
= (void __user
*)arg
;
627 int __user
*p
= argp
;
631 return put_user(SOUND_VERSION
, p
);
632 case SNDCTL_DSP_GETCAPS
:
635 case SNDCTL_DSP_SPEED
:
636 if (get_user(val
, p
))
639 for (s
= 0; s
< 16; s
++)
640 if (val
<< s
>= HWBASE_AD
*4/15)
642 for (i
= 15; i
>= 5; i
--)
643 if (val
<< s
<= HWBASE_AD
*4/i
)
645 bta
->sampleshift
= s
;
648 printk(KERN_DEBUG
"btaudio: rate: req=%d "
649 "dec=%d shift=%d hwrate=%d swrate=%d\n",
650 val
,i
,s
,(HWBASE_AD
*4/i
),(HWBASE_AD
*4/i
)>>s
);
652 bta
->sampleshift
= (bta
->channels
== 2) ? 0 : 1;
655 if (bta
->recording
) {
656 mutex_lock(&bta
->lock
);
658 start_recording(bta
);
659 mutex_unlock(&bta
->lock
);
662 case SOUND_PCM_READ_RATE
:
664 return put_user(HWBASE_AD
*4/bta
->decimation
>>bta
->sampleshift
, p
);
666 return put_user(bta
->rate
, p
);
669 case SNDCTL_DSP_STEREO
:
671 if (get_user(val
, p
))
673 bta
->channels
= (val
> 0) ? 2 : 1;
674 bta
->sampleshift
= (bta
->channels
== 2) ? 0 : 1;
677 "btaudio: stereo=%d channels=%d\n",
686 "btaudio: stereo=0 channels=1\n");
689 return put_user((bta
->channels
)-1, p
);
691 case SNDCTL_DSP_CHANNELS
:
693 if (get_user(val
, p
))
695 bta
->channels
= (val
> 1) ? 2 : 1;
696 bta
->sampleshift
= (bta
->channels
== 2) ? 0 : 1;
699 "btaudio: val=%d channels=%d\n",
703 case SOUND_PCM_READ_CHANNELS
:
704 return put_user(bta
->channels
, p
);
706 case SNDCTL_DSP_GETFMTS
: /* Returns a mask */
708 return put_user(AFMT_S16_LE
|AFMT_S8
, p
);
710 return put_user(AFMT_S16_LE
, p
);
712 case SNDCTL_DSP_SETFMT
: /* Selects ONE fmt*/
713 if (get_user(val
, p
))
715 if (val
!= AFMT_QUERY
) {
717 bta
->bits
= (val
== AFMT_S8
) ? 8 : 16;
720 if (bta
->recording
) {
721 mutex_lock(&bta
->lock
);
723 start_recording(bta
);
724 mutex_unlock(&bta
->lock
);
728 printk(KERN_DEBUG
"btaudio: fmt: bits=%d\n",bta
->bits
);
729 return put_user((bta
->bits
==16) ? AFMT_S16_LE
: AFMT_S8
,
732 case SOUND_PCM_READ_BITS
:
733 return put_user(bta
->bits
, p
);
735 case SNDCTL_DSP_NONBLOCK
:
736 file
->f_flags
|= O_NONBLOCK
;
739 case SNDCTL_DSP_RESET
:
740 if (bta
->recording
) {
741 mutex_lock(&bta
->lock
);
743 mutex_unlock(&bta
->lock
);
746 case SNDCTL_DSP_GETBLKSIZE
:
747 if (!bta
->recording
) {
748 if (0 != (ret
= alloc_buffer(bta
)))
750 if (0 != (ret
= make_risc(bta
)))
753 return put_user(bta
->block_bytes
>>bta
->sampleshift
,p
);
755 case SNDCTL_DSP_SYNC
:
758 case SNDCTL_DSP_GETISPACE
:
763 info
.fragsize
= bta
->block_bytes
>>bta
->sampleshift
;
764 info
.fragstotal
= bta
->block_count
;
765 info
.bytes
= bta
->read_count
;
766 info
.fragments
= info
.bytes
/ info
.fragsize
;
768 printk(KERN_DEBUG
"btaudio: SNDCTL_DSP_GETISPACE "
769 "returns %d/%d/%d/%d\n",
770 info
.fragsize
, info
.fragstotal
,
771 info
.bytes
, info
.fragments
);
772 if (copy_to_user(argp
, &info
, sizeof(info
)))
777 case SNDCTL_DSP_GETTRIGGER
:
778 case SNDCTL_DSP_SETTRIGGER
:
779 case SNDCTL_DSP_SETFRAGMENT
:
786 static unsigned int btaudio_dsp_poll(struct file
*file
, struct poll_table_struct
*wait
)
788 struct btaudio
*bta
= file
->private_data
;
789 unsigned int mask
= 0;
791 poll_wait(file
, &bta
->readq
, wait
);
793 if (0 != bta
->read_count
)
794 mask
|= (POLLIN
| POLLRDNORM
);
799 static const struct file_operations btaudio_digital_dsp_fops
= {
800 .owner
= THIS_MODULE
,
802 .open
= btaudio_dsp_open_digital
,
803 .release
= btaudio_dsp_release
,
804 .read
= btaudio_dsp_read
,
805 .write
= btaudio_dsp_write
,
806 .ioctl
= btaudio_dsp_ioctl
,
807 .poll
= btaudio_dsp_poll
,
810 static const struct file_operations btaudio_analog_dsp_fops
= {
811 .owner
= THIS_MODULE
,
813 .open
= btaudio_dsp_open_analog
,
814 .release
= btaudio_dsp_release
,
815 .read
= btaudio_dsp_read
,
816 .write
= btaudio_dsp_write
,
817 .ioctl
= btaudio_dsp_ioctl
,
818 .poll
= btaudio_dsp_poll
,
821 /* -------------------------------------------------------------- */
823 static char *irq_name
[] = { "", "", "", "OFLOW", "", "", "", "", "", "", "",
824 "RISCI", "FBUS", "FTRGT", "FDSR", "PPERR",
825 "RIPERR", "PABORT", "OCERR", "SCERR" };
827 static irqreturn_t
btaudio_irq(int irq
, void *dev_id
)
831 struct btaudio
*bta
= dev_id
;
836 stat
= btread(REG_INT_STAT
);
837 astat
= stat
& btread(REG_INT_MASK
);
839 return IRQ_RETVAL(handled
);
841 btwrite(astat
,REG_INT_STAT
);
845 printk(KERN_DEBUG
"btaudio: irq loop=%d risc=%x, bits:",
847 for (i
= 0; i
< (sizeof(irq_name
)/sizeof(char*)); i
++) {
849 printk(" %s",irq_name
[i
]);
850 if (astat
& (1 << i
))
855 if (stat
& IRQ_RISCI
) {
857 blocks
= (stat
>> 28) - bta
->dma_block
;
859 blocks
+= bta
->block_count
;
860 bta
->dma_block
= stat
>> 28;
861 if (bta
->read_count
+ 2*bta
->block_bytes
> bta
->buf_size
) {
863 printk(KERN_INFO
"btaudio: buffer overrun\n");
866 bta
->read_count
+= blocks
* bta
->block_bytes
;
867 wake_up_interruptible(&bta
->readq
);
872 "btaudio: Oops - irq mask cleared\n");
873 btwrite(0, REG_INT_MASK
);
879 /* -------------------------------------------------------------- */
881 static unsigned int dsp1
= -1;
882 static unsigned int dsp2
= -1;
883 static unsigned int mixer
= -1;
884 static int latency
= -1;
885 static int digital
= 1;
886 static int analog
= 1;
889 #define BTA_OSPREY200 1
891 static struct cardinfo cards
[] = {
897 .name
= "Osprey 200",
902 static int __devinit
btaudio_probe(struct pci_dev
*pci_dev
,
903 const struct pci_device_id
*pci_id
)
906 struct cardinfo
*card
= &cards
[pci_id
->driver_data
];
907 unsigned char revision
,lat
;
910 if (pci_enable_device(pci_dev
))
912 if (!request_mem_region(pci_resource_start(pci_dev
,0),
913 pci_resource_len(pci_dev
,0),
918 bta
= kzalloc(sizeof(*bta
),GFP_ATOMIC
);
925 bta
->irq
= pci_dev
->irq
;
926 bta
->mem
= pci_resource_start(pci_dev
,0);
927 bta
->mmio
= ioremap(pci_resource_start(pci_dev
,0),
928 pci_resource_len(pci_dev
,0));
934 bta
->decimation
= 15;
937 bta
->sampleshift
= 1;
941 bta
->rate
= card
->rate
;
945 mutex_init(&bta
->lock
);
946 init_waitqueue_head(&bta
->readq
);
949 printk(KERN_INFO
"btaudio: setting pci latency timer to %d\n",
951 pci_write_config_byte(pci_dev
, PCI_LATENCY_TIMER
, latency
);
953 pci_read_config_byte(pci_dev
, PCI_CLASS_REVISION
, &revision
);
954 pci_read_config_byte(pci_dev
, PCI_LATENCY_TIMER
, &lat
);
955 printk(KERN_INFO
"btaudio: Bt%x (rev %d) at %02x:%02x.%x, ",
956 pci_dev
->device
,revision
,pci_dev
->bus
->number
,
957 PCI_SLOT(pci_dev
->devfn
),PCI_FUNC(pci_dev
->devfn
));
958 printk("irq: %d, latency: %d, mmio: 0x%lx\n",
959 bta
->irq
, lat
, bta
->mem
);
960 printk("btaudio: using card config \"%s\"\n", card
->name
);
963 btwrite(0, REG_GPIO_DMA_CTL
);
964 btwrite(0, REG_INT_MASK
);
965 btwrite(~0U, REG_INT_STAT
);
966 pci_set_master(pci_dev
);
968 if ((rc
= request_irq(bta
->irq
, btaudio_irq
, IRQF_SHARED
|IRQF_DISABLED
,
969 "btaudio",(void *)bta
)) < 0) {
971 "btaudio: can't request irq (rc=%d)\n",rc
);
975 /* register devices */
977 rc
= bta
->dsp_digital
=
978 register_sound_dsp(&btaudio_digital_dsp_fops
,dsp1
);
981 "btaudio: can't register digital dsp (rc=%d)\n",rc
);
984 printk(KERN_INFO
"btaudio: registered device dsp%d [digital]\n",
985 bta
->dsp_digital
>> 4);
988 rc
= bta
->dsp_analog
=
989 register_sound_dsp(&btaudio_analog_dsp_fops
,dsp2
);
992 "btaudio: can't register analog dsp (rc=%d)\n",rc
);
995 printk(KERN_INFO
"btaudio: registered device dsp%d [analog]\n",
996 bta
->dsp_analog
>> 4);
997 rc
= bta
->mixer_dev
= register_sound_mixer(&btaudio_mixer_fops
,mixer
);
1000 "btaudio: can't register mixer (rc=%d)\n",rc
);
1003 printk(KERN_INFO
"btaudio: registered device mixer%d\n",
1004 bta
->mixer_dev
>> 4);
1007 /* hook into linked list */
1008 bta
->next
= btaudios
;
1011 pci_set_drvdata(pci_dev
,bta
);
1015 unregister_sound_dsp(bta
->dsp_analog
);
1018 unregister_sound_dsp(bta
->dsp_digital
);
1020 free_irq(bta
->irq
,bta
);
1025 release_mem_region(pci_resource_start(pci_dev
,0),
1026 pci_resource_len(pci_dev
,0));
1030 static void __devexit
btaudio_remove(struct pci_dev
*pci_dev
)
1032 struct btaudio
*bta
= pci_get_drvdata(pci_dev
);
1033 struct btaudio
*walk
;
1035 /* turn off all DMA / IRQs */
1036 btand(~15, REG_GPIO_DMA_CTL
);
1037 btwrite(0, REG_INT_MASK
);
1038 btwrite(~0U, REG_INT_STAT
);
1040 /* unregister devices */
1042 unregister_sound_dsp(bta
->dsp_digital
);
1045 unregister_sound_dsp(bta
->dsp_analog
);
1046 unregister_sound_mixer(bta
->mixer_dev
);
1049 /* free resources */
1051 free_irq(bta
->irq
,bta
);
1052 release_mem_region(pci_resource_start(pci_dev
,0),
1053 pci_resource_len(pci_dev
,0));
1056 /* remove from linked list */
1057 if (bta
== btaudios
) {
1060 for (walk
= btaudios
; walk
->next
!= bta
; walk
= walk
->next
)
1061 ; /* if (NULL == walk->next) BUG(); */
1062 walk
->next
= bta
->next
;
1065 pci_set_drvdata(pci_dev
, NULL
);
1070 /* -------------------------------------------------------------- */
1072 static struct pci_device_id btaudio_pci_tbl
[] = {
1074 .vendor
= PCI_VENDOR_ID_BROOKTREE
,
1076 .subvendor
= 0x0070,
1077 .subdevice
= 0xff01,
1078 .driver_data
= BTA_OSPREY200
,
1080 .vendor
= PCI_VENDOR_ID_BROOKTREE
,
1082 .subvendor
= PCI_ANY_ID
,
1083 .subdevice
= PCI_ANY_ID
,
1085 .vendor
= PCI_VENDOR_ID_BROOKTREE
,
1087 .subvendor
= PCI_ANY_ID
,
1088 .subdevice
= PCI_ANY_ID
,
1090 /* --- end of list --- */
1094 static struct pci_driver btaudio_pci_driver
= {
1096 .id_table
= btaudio_pci_tbl
,
1097 .probe
= btaudio_probe
,
1098 .remove
= __devexit_p(btaudio_remove
),
1101 static int btaudio_init_module(void)
1103 printk(KERN_INFO
"btaudio: driver version 0.7 loaded [%s%s%s]\n",
1104 digital
? "digital" : "",
1105 analog
&& digital
? "+" : "",
1106 analog
? "analog" : "");
1107 return pci_register_driver(&btaudio_pci_driver
);
1110 static void btaudio_cleanup_module(void)
1112 pci_unregister_driver(&btaudio_pci_driver
);
1116 module_init(btaudio_init_module
);
1117 module_exit(btaudio_cleanup_module
);
1119 module_param(dsp1
, int, S_IRUGO
);
1120 module_param(dsp2
, int, S_IRUGO
);
1121 module_param(mixer
, int, S_IRUGO
);
1122 module_param(debug
, int, S_IRUGO
| S_IWUSR
);
1123 module_param(irq_debug
, int, S_IRUGO
| S_IWUSR
);
1124 module_param(digital
, int, S_IRUGO
);
1125 module_param(analog
, int, S_IRUGO
);
1126 module_param(rate
, int, S_IRUGO
);
1127 module_param(latency
, int, S_IRUGO
);
1128 MODULE_PARM_DESC(latency
,"pci latency timer");
1130 MODULE_DEVICE_TABLE(pci
, btaudio_pci_tbl
);
1131 MODULE_DESCRIPTION("bt878 audio dma driver");
1132 MODULE_AUTHOR("Gerd Knorr");
1133 MODULE_LICENSE("GPL");