3 * AD1816 lowlevel sound driver for Linux 2.2.0 and above
5 * Copyright (C) 1998 by Thorsten Knabe <tek@rbg.informatik.tu-darmstadt.de>
7 * Based on the CS4232/AD1848 driver Copyright (C) by Hannu Savolainen 1993-1996
11 * status: experimental
15 * Oleg Drokin: Some cleanup of load/unload functions. 1998/11/24
17 * Thorsten Knabe: attach and unload rewritten,
18 * some argument checks added 1998/11/30
20 * Thorsten Knabe: Buggy isa bridge workaround added 1999/01/16
22 * David Moews/Thorsten Knabe: Introduced options
23 * parameter. Added slightly modified patch from
24 * David Moews to disable dsp audio sources by setting
25 * bit 0 of options parameter. This seems to be
26 * required by some Aztech/Newcom SC-16 cards. 1999/04/18
28 * Christoph Hellwig: Adapted to module_init/module_exit. 2000/03/03
30 * Christoph Hellwig: Added isapnp support 2000/03/15
33 #include <linux/config.h>
34 #include <linux/module.h>
35 #include <linux/init.h>
36 #include <linux/isapnp.h>
37 #include <linux/stddef.h>
39 #include "sound_config.h"
46 #define CHECK_FOR_POWER { int timeout=100; \
47 while (timeout > 0 && (inb(devc->base)&0x80)!= 0x80) {\
51 printk("ad1816: Check for power failed in %s line: %d\n",__FILE__,__LINE__); \
55 /* structure to hold device specific information */
58 int base
; /* set in attach */
66 unsigned char format_bits
;
70 int recmask
; /* setup */
71 int supported_devices
;
72 int supported_rec_devices
;
73 unsigned short levels
[SOUND_MIXER_NRDEVICES
];
74 int dev_no
; /* this is the # in audio_devs and NOT
81 static int nr_ad1816_devs
= 0;
82 static int ad1816_clockfreq
=33000;
85 /* for backward mapping of irq to sound device */
87 static volatile char irq2dev
[17] = {-1, -1, -1, -1, -1, -1, -1, -1,
88 -1, -1, -1, -1, -1, -1, -1, -1, -1};
91 /* supported audio formats */
92 static int ad_format_mask
=
93 AFMT_U8
| AFMT_S16_LE
| AFMT_S16_BE
| AFMT_MU_LAW
| AFMT_A_LAW
;
95 /* array of device info structures */
96 static ad1816_info dev_info
[MAX_AUDIO_DEV
];
99 /* ------------------------------------------------------------------- */
101 /* functions for easier access to inderect registers */
103 static int ad_read (ad1816_info
* devc
, int reg
)
110 save_flags (flags
); /* make register access atomic */
112 outb ((unsigned char) (reg
& 0x3f), devc
->base
+0);
113 result
= inb(devc
->base
+2);
114 result
+= inb(devc
->base
+3)<<8;
115 restore_flags (flags
);
121 static void ad_write (ad1816_info
* devc
, int reg
, int data
)
127 save_flags (flags
); /* make register access atomic */
129 outb ((unsigned char) (reg
& 0xff), devc
->base
+0);
130 outb ((unsigned char) (data
& 0xff),devc
->base
+2);
131 outb ((unsigned char) ((data
>>8)&0xff),devc
->base
+3);
132 restore_flags (flags
);
136 /* ------------------------------------------------------------------- */
138 /* function interface required by struct audio_driver */
140 static void ad1816_halt_input (int dev
)
143 ad1816_info
*devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
144 unsigned char buffer
;
146 DEBUGINFO (printk("ad1816: halt_input called\n"));
151 if(!isa_dma_bridge_buggy
) {
152 disable_dma(audio_devs
[dev
]->dmap_in
->dma
);
155 buffer
=inb(devc
->base
+9);
157 /* disable capture */
158 outb(buffer
& ~0x01,devc
->base
+9);
161 if(!isa_dma_bridge_buggy
) {
162 enable_dma(audio_devs
[dev
]->dmap_in
->dma
);
165 /* Clear interrupt status */
166 outb (~0x40, devc
->base
+1);
168 devc
->audio_mode
&= ~PCM_ENABLE_INPUT
;
169 restore_flags (flags
);
172 static void ad1816_halt_output (int dev
)
175 ad1816_info
*devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
177 unsigned char buffer
;
179 DEBUGINFO (printk("ad1816: halt_output called!\n"));
183 /* Mute pcm output */
184 ad_write(devc
, 4, ad_read(devc
,4)|0x8080);
186 if(!isa_dma_bridge_buggy
) {
187 disable_dma(audio_devs
[dev
]->dmap_out
->dma
);
190 buffer
=inb(devc
->base
+8);
192 /* disable capture */
193 outb(buffer
& ~0x01,devc
->base
+8);
196 if(!isa_dma_bridge_buggy
) {
197 enable_dma(audio_devs
[dev
]->dmap_out
->dma
);
200 /* Clear interrupt status */
201 outb ((unsigned char)~0x80, devc
->base
+1);
203 devc
->audio_mode
&= ~PCM_ENABLE_OUTPUT
;
204 restore_flags (flags
);
207 static void ad1816_output_block (int dev
, unsigned long buf
,
208 int count
, int intrflag
)
212 ad1816_info
*devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
214 DEBUGINFO(printk("ad1816: output_block called buf=%ld count=%d flags=%d\n",buf
,count
,intrflag
));
221 /* set transfer count */
222 ad_write (devc
, 8, cnt
& 0xffff);
224 devc
->audio_mode
|= PCM_ENABLE_OUTPUT
;
225 restore_flags (flags
);
229 static void ad1816_start_input (int dev
, unsigned long buf
, int count
,
234 ad1816_info
*devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
236 DEBUGINFO(printk("ad1816: start_input called buf=%ld count=%d flags=%d\n",buf
,count
,intrflag
));
240 save_flags (flags
); /* make register access atomic */
243 /* set transfer count */
244 ad_write (devc
, 10, cnt
& 0xffff);
246 devc
->audio_mode
|= PCM_ENABLE_INPUT
;
247 restore_flags (flags
);
250 static int ad1816_prepare_for_input (int dev
, int bsize
, int bcount
)
254 ad1816_info
*devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
255 unsigned char fmt_bits
;
257 DEBUGINFO (printk ("ad1816: prepare_for_input called: bsize=%d bcount=%d\n",bsize
,bcount
));
262 fmt_bits
= (devc
->format_bits
&0x7)<<3;
264 /* set mono/stereo mode */
265 if (devc
->channels
> 1) {
269 /* set Mono/Stereo in playback/capture register */
270 outb( (inb(devc
->base
+8) & ~0x3C)|fmt_bits
, devc
->base
+8);
271 outb( (inb(devc
->base
+9) & ~0x3C)|fmt_bits
, devc
->base
+9);
273 /* If compiled into kernel, AD1816_CLOCK is defined, so use it */
275 ad1816_clockfreq
=AD1816_CLOCK
;
278 /* capture/playback frequency correction for soundcards
279 with clock chips != 33MHz (allowed range 5 - 100 kHz) */
281 if (ad1816_clockfreq
<5000 || ad1816_clockfreq
>100000) {
282 ad1816_clockfreq
=33000;
285 freq
=((unsigned int)devc
->speed
*33000)/ad1816_clockfreq
;
287 /* write playback/capture speeds */
288 ad_write (devc
, 2, freq
& 0xffff);
289 ad_write (devc
, 3, freq
& 0xffff);
291 restore_flags (flags
);
293 ad1816_halt_input(dev
);
297 static int ad1816_prepare_for_output (int dev
, int bsize
, int bcount
)
301 ad1816_info
*devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
302 unsigned char fmt_bits
;
304 DEBUGINFO (printk ("ad1816: prepare_for_output called: bsize=%d bcount=%d\n",bsize
,bcount
));
306 save_flags (flags
); /* make register access atomic */
309 fmt_bits
= (devc
->format_bits
&0x7)<<3;
310 /* set mono/stereo mode */
311 if (devc
->channels
> 1) {
315 /* write format bits to playback/capture registers */
316 outb( (inb(devc
->base
+8) & ~0x3C)|fmt_bits
, devc
->base
+8);
317 outb( (inb(devc
->base
+9) & ~0x3C)|fmt_bits
, devc
->base
+9);
320 ad1816_clockfreq
=AD1816_CLOCK
;
323 /* capture/playback frequency correction for soundcards
324 with clock chips != 33MHz (allowed range 5 - 100 kHz)*/
326 if (ad1816_clockfreq
<5000 || ad1816_clockfreq
>100000) {
327 ad1816_clockfreq
=33000;
330 freq
=((unsigned int)devc
->speed
*33000)/ad1816_clockfreq
;
332 /* write playback/capture speeds */
333 ad_write (devc
, 2, freq
& 0xffff);
334 ad_write (devc
, 3, freq
& 0xffff);
336 restore_flags (flags
);
338 ad1816_halt_output(dev
);
343 static void ad1816_trigger (int dev
, int state
)
346 ad1816_info
*devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
348 DEBUGINFO (printk("ad1816: trigger called! (devc=%d,devc->base=%d\n", devc
, devc
->base
));
350 /* mode may have changed */
352 save_flags (flags
); /* make register access atomic */
355 /* mask out modes not specified on open call */
356 state
&= devc
->audio_mode
;
358 /* setup soundchip to new io-mode */
359 if (state
& PCM_ENABLE_INPUT
) {
361 outb(inb(devc
->base
+9)|0x01, devc
->base
+9);
363 /* disable capture */
364 outb(inb(devc
->base
+9)&~0x01, devc
->base
+9);
367 if (state
& PCM_ENABLE_OUTPUT
) {
368 /* enable playback */
369 outb(inb(devc
->base
+8)|0x01, devc
->base
+8);
370 /* unmute pcm output */
371 ad_write(devc
, 4, ad_read(devc
,4)&~0x8080);
373 /* mute pcm output */
374 ad_write(devc
, 4, ad_read(devc
,4)|0x8080);
375 /* disable capture */
376 outb(inb(devc
->base
+8)&~0x01, devc
->base
+8);
378 restore_flags (flags
);
382 /* halt input & output */
383 static void ad1816_halt (int dev
)
385 ad1816_halt_input(dev
);
386 ad1816_halt_output(dev
);
389 static void ad1816_reset (int dev
)
394 /* set playback speed */
395 static int ad1816_set_speed (int dev
, int arg
)
397 ad1816_info
*devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
415 static unsigned int ad1816_set_bits (int dev
, unsigned int arg
)
417 ad1816_info
*devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
419 static struct format_tbl
{
426 { AFMT_IMA_ADPCM
, 0 },
435 int i
, n
= sizeof (format2bits
) / sizeof (struct format_tbl
);
437 /* return current format */
439 return devc
->audio_format
;
441 devc
->audio_format
= arg
;
443 /* search matching format bits */
444 for (i
= 0; i
< n
; i
++)
445 if (format2bits
[i
].format
== arg
) {
446 devc
->format_bits
= format2bits
[i
].bits
;
447 devc
->audio_format
= arg
;
451 /* Still hanging here. Something must be terribly wrong */
452 devc
->format_bits
= 0;
453 return devc
->audio_format
= AFMT_U8
;
456 static short ad1816_set_channels (int dev
, short arg
)
458 ad1816_info
*devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
460 if (arg
!= 1 && arg
!= 2)
461 return devc
->channels
;
463 devc
->channels
= arg
;
468 static int ad1816_open (int dev
, int mode
)
470 ad1816_info
*devc
= NULL
;
473 /* is device number valid ? */
474 if (dev
< 0 || dev
>= num_audiodevs
)
477 /* get device info of this dev */
478 devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
480 /* make check if device already open atomic */
485 restore_flags (flags
);
489 /* mark device as open */
492 devc
->audio_mode
= 0;
494 devc
->audio_format
=AFMT_U8
;
497 ad1816_reset(devc
->dev_no
); /* halt all pending output */
498 restore_flags (flags
);
502 static void ad1816_close (int dev
) /* close device */
505 ad1816_info
*devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
510 /* halt all pending output */
511 ad1816_reset(devc
->dev_no
);
514 devc
->audio_mode
= 0;
516 devc
->audio_format
=AFMT_U8
;
517 devc
->format_bits
= 0;
520 restore_flags (flags
);
524 /* ------------------------------------------------------------------- */
526 /* Audio driver structure */
528 static struct audio_driver ad1816_audio_driver
=
533 output_block
: ad1816_output_block
,
534 start_input
: ad1816_start_input
,
535 prepare_for_input
: ad1816_prepare_for_input
,
536 prepare_for_output
: ad1816_prepare_for_output
,
537 halt_io
: ad1816_halt
,
538 halt_input
: ad1816_halt_input
,
539 halt_output
: ad1816_halt_output
,
540 trigger
: ad1816_trigger
,
541 set_speed
: ad1816_set_speed
,
542 set_bits
: ad1816_set_bits
,
543 set_channels
: ad1816_set_channels
,
547 /* ------------------------------------------------------------------- */
549 /* Interrupt handler */
552 static void ad1816_interrupt (int irq
, void *dev_id
, struct pt_regs
*dummy
)
554 unsigned char status
;
560 if (irq
< 0 || irq
> 15) {
561 printk ("ad1816: Got bogus interrupt %d\n", irq
);
567 if (dev
< 0 || dev
>= num_audiodevs
) {
568 printk ("ad1816: IRQ2AD1816-mapping failed for irq %d device %d\n", irq
,dev
);
572 devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
577 /* read interrupt register */
578 status
= inb (devc
->base
+1);
579 /* Clear all interrupt */
580 outb (~status
, devc
->base
+1);
582 DEBUGNOISE (printk("ad1816: Got interrupt subclass %d\n",status
));
587 DEBUGWARN(printk ("ad1816: interrupt: Got interrupt, but no reason?\n"));
589 if (devc
->opened
&& (devc
->audio_mode
& PCM_ENABLE_INPUT
) && (status
&64))
590 DMAbuf_inputintr (dev
);
592 if (devc
->opened
&& (devc
->audio_mode
& PCM_ENABLE_OUTPUT
) && (status
& 128))
593 DMAbuf_outputintr (dev
, 1);
595 restore_flags(flags
);
598 /* ------------------------------------------------------------------- */
603 unsigned int regno
: 7;
604 unsigned int polarity
:1; /* 0=normal, 1=reversed */
605 unsigned int bitpos
:4;
606 unsigned int nbits
:4;
609 static char mix_cvt
[101] = {
610 0, 0, 3, 7,10,13,16,19,21,23,26,28,30,32,34,35,37,39,40,42,
611 43,45,46,47,49,50,51,52,53,55,56,57,58,59,60,61,62,63,64,65,
612 65,66,67,68,69,70,70,71,72,73,73,74,75,75,76,77,77,78,79,79,
613 80,81,81,82,82,83,84,84,85,85,86,86,87,87,88,88,89,89,90,90,
614 91,91,92,92,93,93,94,94,95,95,96,96,96,97,97,98,98,98,99,99,
618 typedef struct mixer_def mixer_ent
;
621 * Most of the mixer entries work in backwards. Setting the polarity field
622 * makes them to work correctly.
624 * The channel numbering used by individual soundcards is not fixed. Some
625 * cards have assigned different meanings for the AUX1, AUX2 and LINE inputs.
626 * The current version doesn't try to compensate this.
629 #define MIX_ENT(name, reg_l, pola_l, pos_l, len_l, reg_r, pola_r, pos_r, len_r) \
630 {{reg_l, pola_l, pos_l, len_l}, {reg_r, pola_r, pos_r, len_r}}
633 mixer_ent mix_devices
[SOUND_MIXER_NRDEVICES
][2] = {
634 MIX_ENT(SOUND_MIXER_VOLUME
, 14, 1, 8, 5, 14, 1, 0, 5),
635 MIX_ENT(SOUND_MIXER_BASS
, 0, 0, 0, 0, 0, 0, 0, 0),
636 MIX_ENT(SOUND_MIXER_TREBLE
, 0, 0, 0, 0, 0, 0, 0, 0),
637 MIX_ENT(SOUND_MIXER_SYNTH
, 5, 1, 8, 6, 5, 1, 0, 6),
638 MIX_ENT(SOUND_MIXER_PCM
, 4, 1, 8, 6, 4, 1, 0, 6),
639 MIX_ENT(SOUND_MIXER_SPEAKER
, 0, 0, 0, 0, 0, 0, 0, 0),
640 MIX_ENT(SOUND_MIXER_LINE
, 18, 1, 8, 5, 18, 1, 0, 5),
641 MIX_ENT(SOUND_MIXER_MIC
, 19, 1, 8, 5, 19, 1, 0, 5),
642 MIX_ENT(SOUND_MIXER_CD
, 15, 1, 8, 5, 15, 1, 0, 5),
643 MIX_ENT(SOUND_MIXER_IMIX
, 0, 0, 0, 0, 0, 0, 0, 0),
644 MIX_ENT(SOUND_MIXER_ALTPCM
, 0, 0, 0, 0, 0, 0, 0, 0),
645 MIX_ENT(SOUND_MIXER_RECLEV
, 20, 0, 8, 4, 20, 0, 0, 4),
646 MIX_ENT(SOUND_MIXER_IGAIN
, 0, 0, 0, 0, 0, 0, 0, 0),
647 MIX_ENT(SOUND_MIXER_OGAIN
, 0, 0, 0, 0, 0, 0, 0, 0),
648 MIX_ENT(SOUND_MIXER_LINE1
, 17, 1, 8, 5, 17, 1, 0, 5),
649 MIX_ENT(SOUND_MIXER_LINE2
, 16, 1, 8, 5, 16, 1, 0, 5),
650 MIX_ENT(SOUND_MIXER_LINE3
, 39, 0, 9, 4, 39, 1, 0, 5)
654 static unsigned short default_mixer_levels
[SOUND_MIXER_NRDEVICES
] =
656 0x4343, /* Master Volume */
661 0x0000, /* PC Speaker */
662 0x0000, /* Ext Line */
665 0x0000, /* Recording monitor */
667 0x0000, /* Recording level */
668 0x0000, /* Input gain */
669 0x0000, /* Output gain */
672 0x0000 /* Line3 (usually line in)*/
681 ad1816_set_recmask (ad1816_info
* devc
, int mask
)
683 unsigned char recdev
;
686 mask
&= devc
->supported_rec_devices
;
689 /* Count selected device bits */
690 for (i
= 0; i
< 32; i
++)
695 mask
= SOUND_MASK_MIC
;
696 else if (n
!= 1) { /* Too many devices selected */
697 /* Filter out active settings */
698 mask
&= ~devc
->recmask
;
701 /* Count selected device bits */
702 for (i
= 0; i
< 32; i
++)
707 mask
= SOUND_MASK_MIC
;
715 case SOUND_MASK_LINE
:
723 case SOUND_MASK_LINE1
:
727 case SOUND_MASK_LINE2
:
731 case SOUND_MASK_VOLUME
:
736 mask
= SOUND_MASK_MIC
;
742 (ad_read (devc
, 20) & 0x8f8f) | recdev
| (recdev
<<8));
744 devc
->recmask
= mask
;
749 change_bits (int *regval
, int dev
, int chn
, int newval
)
754 /* Reverse polarity*/
756 if (mix_devices
[dev
][chn
].polarity
== 1)
757 newval
= 100 - newval
;
759 mask
= (1 << mix_devices
[dev
][chn
].nbits
) - 1;
760 shift
= mix_devices
[dev
][chn
].bitpos
;
762 newval
= (int) ((newval
* mask
) + 50) / 100;
764 *regval
&= ~(mask
<< shift
);
766 *regval
|= (newval
& mask
) << shift
;
770 ad1816_mixer_get (ad1816_info
* devc
, int dev
)
772 DEBUGINFO(printk("ad1816: mixer_get called!\n"));
774 /* range check + supported mixer check */
775 if (dev
< 0 || dev
>= SOUND_MIXER_NRDEVICES
)
777 if (!((1 << dev
) & devc
->supported_devices
))
780 return devc
->levels
[dev
];
784 ad1816_mixer_set (ad1816_info
* devc
, int dev
, int value
)
786 int left
= value
& 0x000000ff;
787 int right
= (value
& 0x0000ff00) >> 8;
794 DEBUGINFO(printk("ad1816: mixer_set called!\n"));
796 if (dev
< 0 || dev
>= SOUND_MIXER_NRDEVICES
)
809 if (mix_devices
[dev
][RIGHT_CHN
].nbits
== 0)
811 retvol
= left
| (right
<< 8);
815 left
= mix_cvt
[left
];
816 right
= mix_cvt
[right
];
818 /* reject all mixers that are not supported */
819 if (!(devc
->supported_devices
& (1 << dev
)))
823 if (mix_devices
[dev
][LEFT_CHN
].nbits
== 0)
826 /* keep precise volume internal */
827 devc
->levels
[dev
] = retvol
;
829 /* Set the left channel */
830 regoffs
= mix_devices
[dev
][LEFT_CHN
].regno
;
831 val
= ad_read (devc
, regoffs
);
832 change_bits (&val
, dev
, LEFT_CHN
, left
);
836 /* Mute bit masking on some registers */
837 if ( regoffs
==5 || regoffs
==14 || regoffs
==15 ||
838 regoffs
==16 || regoffs
==17 || regoffs
==18 ||
839 regoffs
==19 || regoffs
==39) {
845 ad_write (devc
, regoffs
, valmute
); /* mute */
848 * Set the right channel
851 /* Was just a mono channel */
852 if (mix_devices
[dev
][RIGHT_CHN
].nbits
== 0)
855 regoffs
= mix_devices
[dev
][RIGHT_CHN
].regno
;
856 val
= ad_read (devc
, regoffs
);
857 change_bits (&val
, dev
, RIGHT_CHN
, right
);
860 if ( regoffs
==5 || regoffs
==14 || regoffs
==15 ||
861 regoffs
==16 || regoffs
==17 || regoffs
==18 ||
862 regoffs
==19 || regoffs
==39) {
868 ad_write (devc
, regoffs
, valmute
); /* mute */
873 #define MIXER_DEVICES ( SOUND_MASK_VOLUME | \
884 #define REC_DEVICES ( SOUND_MASK_LINE2 |\
893 ad1816_mixer_reset (ad1816_info
* devc
)
897 devc
->supported_devices
= MIXER_DEVICES
;
899 devc
->supported_rec_devices
= REC_DEVICES
;
901 for (i
= 0; i
< SOUND_MIXER_NRDEVICES
; i
++)
902 if (devc
->supported_devices
& (1 << i
))
903 ad1816_mixer_set (devc
, i
, default_mixer_levels
[i
]);
904 ad1816_set_recmask (devc
, SOUND_MASK_MIC
);
908 ad1816_mixer_ioctl (int dev
, unsigned int cmd
, caddr_t arg
)
910 ad1816_info
*devc
= mixer_devs
[dev
]->devc
;
913 DEBUGINFO(printk("ad1816: mixer_ioctl called!\n"));
916 if (((cmd
>> 8) & 0xff) == 'M') {
919 if (_SIOC_DIR (cmd
) & _SIOC_WRITE
) {
921 case SOUND_MIXER_RECSRC
:
923 if (get_user(val
, (int *)arg
))
925 val
=ad1816_set_recmask (devc
, val
);
926 return put_user(val
, (int *)arg
);
930 if (get_user(val
, (int *)arg
))
932 if ((val
=ad1816_mixer_set (devc
, cmd
& 0xff, val
))<0)
935 return put_user(val
, (int *)arg
);
939 switch (cmd
& 0xff) {
941 case SOUND_MIXER_RECSRC
:
943 return put_user(val
, (int *)arg
);
946 case SOUND_MIXER_DEVMASK
:
947 val
=devc
->supported_devices
;
948 return put_user(val
, (int *)arg
);
951 case SOUND_MIXER_STEREODEVS
:
952 val
=devc
->supported_devices
& ~(SOUND_MASK_SPEAKER
| SOUND_MASK_IMIX
);
953 return put_user(val
, (int *)arg
);
956 case SOUND_MIXER_RECMASK
:
957 val
=devc
->supported_rec_devices
;
958 return put_user(val
, (int *)arg
);
961 case SOUND_MIXER_CAPS
:
962 val
=SOUND_CAP_EXCL_INPUT
;
963 return put_user(val
, (int *)arg
);
967 if ((val
=ad1816_mixer_get (devc
, cmd
& 0xff))<0)
970 return put_user(val
, (int *)arg
);
978 /* ------------------------------------------------------------------- */
980 /* Mixer structure */
982 static struct mixer_operations ad1816_mixer_operations
= {
985 name
: "AD1816 Mixer",
986 ioctl
: ad1816_mixer_ioctl
990 /* ------------------------------------------------------------------- */
992 /* stuff for card recognition, init and unloading */
995 /* replace with probe routine */
996 static int __init
probe_ad1816 ( struct address_info
*hw_config
)
998 ad1816_info
*devc
= &dev_info
[nr_ad1816_devs
];
999 int io_base
=hw_config
->io_base
;
1000 int *osp
=hw_config
->osp
;
1003 printk("ad1816: AD1816 sounddriver Copyright (C) 1998 by Thorsten Knabe\n");
1004 printk("ad1816: io=0x%x, irq=%d, dma=%d, dma2=%d, clockfreq=%d, options=%d isadmabug=%d\n",
1011 isa_dma_bridge_buggy
);
1013 if (check_region (io_base
, 16)) {
1014 printk ("ad1816: I/O port 0x%03x not free\n", io_base
);
1018 DEBUGLOG(printk ("ad1816: detect(%x)\n", io_base
));
1020 if (nr_ad1816_devs
>= MAX_AUDIO_DEV
) {
1021 printk ("ad1816: detect error - step 0\n");
1025 devc
->base
= io_base
;
1031 /* base+0: bit 1 must be set but not 255 */
1032 tmp
=inb(devc
->base
);
1033 if ( (tmp
&0x80)==0 || tmp
==255 ) {
1034 DEBUGLOG (printk ("ad1816: Chip is not an AD1816 or chip is not active (Test 0)\n"));
1039 /* writes to ireg 8 are copied to ireg 9 */
1040 ad_write(devc
,8,12345);
1041 if (ad_read(devc
,9)!=12345) {
1042 DEBUGLOG (printk ("ad1816: Chip is not an AD1816 (Test 1)\n"));
1046 /* writes to ireg 8 are copied to ireg 9 */
1047 ad_write(devc
,8,54321);
1048 if (ad_read(devc
,9)!=54321) {
1049 DEBUGLOG (printk ("ad1816: Chip is not an AD1816 (Test 2)\n"));
1054 /* writes to ireg 10 are copied to ireg 11 */
1055 ad_write(devc
,10,54321);
1056 if (ad_read(devc
,11)!=54321) {
1057 DEBUGLOG (printk ("ad1816: Chip is not an AD1816 (Test 3)\n"));
1061 /* writes to ireg 10 are copied to ireg 11 */
1062 ad_write(devc
,10,12345);
1063 if (ad_read(devc
,11)!=12345) {
1064 DEBUGLOG (printk ("ad1816: Chip is not an AD1816 (Test 4)\n"));
1068 /* bit in base +1 cannot be set to 1 */
1069 tmp
=inb(devc
->base
+1);
1070 outb(0xff,devc
->base
+1);
1071 if (inb(devc
->base
+1)!=tmp
) {
1072 DEBUGLOG (printk ("ad1816: Chip is not an AD1816 (Test 5)\n"));
1077 DEBUGLOG (printk ("ad1816: detect() - Detected OK\n"));
1078 DEBUGLOG (printk ("ad1816: AD1816 Version: %d\n",ad_read(devc
,45)));
1080 /* detection was successful */
1085 /* allocate resources from the kernel. If any allocation fails, free
1086 all allocated resources and exit attach.
1090 static void __init
attach_ad1816 (struct address_info
*hw_config
)
1094 ad1816_info
*devc
= &dev_info
[nr_ad1816_devs
];
1097 /* allocate i/o ports */
1098 request_region (hw_config
->io_base
, 16, "AD1816 Sound");
1099 devc
->base
= hw_config
->io_base
;
1101 /* disable all interrupts */
1104 /* Clear pending interrupts */
1105 outb (0, devc
->base
+1);
1108 if (hw_config
->irq
< 0 || hw_config
->irq
> 15) {
1109 release_region(hw_config
->io_base
, 16);
1112 if (request_irq(hw_config
->irq
, ad1816_interrupt
,0,
1114 hw_config
->osp
) < 0) {
1115 printk ("ad1816: IRQ in use\n");
1116 release_region(hw_config
->io_base
, 16);
1119 devc
->irq
=hw_config
->irq
;
1122 if (sound_alloc_dma (hw_config
->dma
, "Sound System")) {
1123 printk ("ad1816: Can't allocate DMA%d\n", hw_config
->dma
);
1124 free_irq(hw_config
->irq
,hw_config
->osp
);
1125 release_region(hw_config
->io_base
, 16);
1128 devc
->dma_playback
=hw_config
->dma
;
1130 if ( hw_config
->dma2
!= -1 && hw_config
->dma2
!= hw_config
->dma
) {
1131 if (sound_alloc_dma (hw_config
->dma2
, "Sound System (capture)")) {
1132 printk ("ad1816: Can't allocate DMA%d\n", hw_config
->dma2
);
1133 sound_free_dma(hw_config
->dma
);
1134 free_irq(hw_config
->irq
,hw_config
->osp
);
1135 release_region(hw_config
->io_base
, 16);
1138 devc
->dma_capture
=hw_config
->dma2
;
1139 devc
->audio_mode
=DMA_AUTOMODE
|DMA_DUPLEX
;
1141 devc
->dma_capture
=-1;
1142 devc
->audio_mode
=DMA_AUTOMODE
;
1145 sprintf (dev_name
,"AD1816 audio driver");
1147 conf_printf2 (dev_name
,
1148 devc
->base
, devc
->irq
, hw_config
->dma
, hw_config
->dma2
);
1150 /* register device */
1151 if ((my_dev
= sound_install_audiodrv (AUDIO_DRIVER_VERSION
,
1153 &ad1816_audio_driver
,
1154 sizeof (struct audio_driver
),
1159 hw_config
->dma2
)) < 0) {
1160 printk ("ad1816: Can't install sound driver\n");
1161 if (devc
->dma_capture
>=0) {
1162 sound_free_dma(hw_config
->dma2
);
1164 sound_free_dma(hw_config
->dma
);
1165 free_irq(hw_config
->irq
,hw_config
->osp
);
1166 release_region(hw_config
->io_base
, 16);
1171 /* fill rest of structure with reasonable default values */
1172 irq2dev
[hw_config
->irq
] = devc
->dev_no
= my_dev
;
1175 devc
->osp
= hw_config
->osp
;
1178 ad_write(devc
,32,0x80f0); /* sound system mode */
1180 ad_write(devc
,33,0); /* disable all audiosources for dsp */
1182 ad_write(devc
,33,0x03f8); /* enable all audiosources for dsp */
1184 ad_write(devc
,4,0x8080); /* default values for volumes (muted)*/
1185 ad_write(devc
,5,0x8080);
1186 ad_write(devc
,6,0x8080);
1187 ad_write(devc
,7,0x8080);
1188 ad_write(devc
,15,0x8888);
1189 ad_write(devc
,16,0x8888);
1190 ad_write(devc
,17,0x8888);
1191 ad_write(devc
,18,0x8888);
1192 ad_write(devc
,19,0xc888); /* +20db mic active */
1193 ad_write(devc
,14,0x0000); /* Master volume unmuted */
1194 ad_write(devc
,39,0x009f); /* 3D effect on 0% phone out muted */
1195 ad_write(devc
,44,0x0080); /* everything on power, 3d enabled for d/a */
1196 outb(0x10,devc
->base
+8); /* set dma mode */
1197 outb(0x10,devc
->base
+9);
1199 /* enable capture + playback interrupt */
1200 ad_write(devc
,1,0xc000);
1202 /* set mixer defaults */
1203 ad1816_mixer_reset (devc
);
1205 /* register mixer */
1206 if ((audio_devs
[my_dev
]->mixer_dev
=sound_install_mixer(
1207 MIXER_DRIVER_VERSION
,
1209 &ad1816_mixer_operations
,
1210 sizeof (struct mixer_operations
),
1212 audio_devs
[my_dev
]->min_fragment
= 0;
1216 static void __exit
unload_card(ad1816_info
*devc
)
1221 DEBUGLOG (printk("ad1816: Unloading card at base=%x\n",devc
->base
));
1224 mixer
= audio_devs
[dev
]->mixer_dev
;
1228 sound_unload_mixerdev(mixer
);
1230 sound_unload_audiodev(dev
);
1232 /* free dma channels */
1233 if (devc
->dma_capture
>=0) {
1234 sound_free_dma(devc
->dma_capture
);
1237 /* card wont get added if resources could not be allocated
1238 thus we need not ckeck if allocation was successful */
1239 sound_free_dma (devc
->dma_playback
);
1240 free_irq(devc
->irq
, devc
->osp
);
1241 release_region (devc
->base
, 16);
1243 DEBUGLOG (printk("ad1816: Unloading card at base=%x was successful\n",devc
->base
));
1246 printk ("ad1816: no device/card specified\n");
1250 static struct address_info cfg
;
1252 static int __initdata io
= -1;
1253 static int __initdata irq
= -1;
1254 static int __initdata dma
= -1;
1255 static int __initdata dma2
= -1;
1257 #if defined CONFIG_ISAPNP || defined CONFIG_ISAPNP_MODULE
1258 struct pci_dev
*ad1816_dev
= NULL
;
1260 static int activated
= 1;
1262 static int isapnp
= 1;
1263 static int isapnpjump
= 0;
1265 MODULE_PARM(isapnp
, "i");
1266 MODULE_PARM(isapnpjump
, "i");
1269 static int isapnp
= 0;
1272 MODULE_PARM(io
,"i");
1273 MODULE_PARM(irq
,"i");
1274 MODULE_PARM(dma
,"i");
1275 MODULE_PARM(dma2
,"i");
1276 MODULE_PARM(ad1816_clockfreq
,"i");
1277 MODULE_PARM(options
,"i");
1279 #if defined CONFIG_ISAPNP || defined CONFIG_ISAPNP_MODULE
1281 static struct pci_dev
*activate_dev(char *devname
, char *resname
, struct pci_dev
*dev
)
1290 if((err
= dev
->activate(dev
)) < 0) {
1291 printk(KERN_ERR
"ad1816: %s %s config failed (out of resources?)[%d]\n",
1292 devname
, resname
, err
);
1293 dev
->deactivate(dev
);
1300 static struct pci_dev
*ad1816_init_generic(struct pci_bus
*bus
, struct pci_dev
*card
,
1301 struct address_info
*hw_config
)
1303 if((ad1816_dev
= isapnp_find_dev(bus
, card
->vendor
, card
->device
, NULL
))) {
1304 ad1816_dev
->prepare(ad1816_dev
);
1306 if((ad1816_dev
= activate_dev("Analog Devices 1816(A)", "ad1816", ad1816_dev
))) {
1307 hw_config
->io_base
= ad1816_dev
->resource
[2].start
;
1308 hw_config
->irq
= ad1816_dev
->irq_resource
[0].start
;
1309 hw_config
->dma
= ad1816_dev
->dma_resource
[0].start
;
1310 hw_config
->dma2
= ad1816_dev
->dma_resource
[1].start
;
1318 unsigned short vendor
;
1319 unsigned short function
;
1320 struct pci_dev
* (*initfunc
)(struct pci_bus
*, struct pci_dev
*, struct address_info
*);
1322 } isapnp_ad1816_list
[] __initdata
= {
1323 {ISAPNP_VENDOR('A','D','S'), ISAPNP_FUNCTION(0x7150), &ad1816_init_generic
, "Analog Devices 1815" },
1324 {ISAPNP_VENDOR('A','D','S'), ISAPNP_FUNCTION(0x7180), &ad1816_init_generic
, "Analog Devices 1816A" },
1328 static int __init
ad1816_init_isapnp(struct address_info
*hw_config
,
1329 struct pci_bus
*bus
, struct pci_dev
*card
, int slot
)
1331 struct pci_dev
*idev
= NULL
;
1333 /* You missed the init func? That's bad. */
1334 if(isapnp_ad1816_list
[slot
].initfunc
) {
1335 char *busname
= bus
->name
[0] ? bus
->name
: isapnp_ad1816_list
[slot
].name
;
1337 printk(KERN_INFO
"ad1816: %s detected\n", busname
);
1339 /* Initialize this baby. */
1340 if((idev
= isapnp_ad1816_list
[slot
].initfunc(bus
, card
, hw_config
))) {
1343 printk(KERN_NOTICE
"ad1816: ISAPnP reports '%s' at i/o %#x, irq %d, dma %d, %d\n",
1345 hw_config
->io_base
, hw_config
->irq
, hw_config
->dma
,
1349 printk(KERN_INFO
"ad1816: Failed to initialize %s\n", busname
);
1351 printk(KERN_ERR
"ad1816: Bad entry in ad1816.c PnP table\n");
1357 * Actually this routine will detect and configure only the first card with successful
1358 * initialization. isapnpjump could be used to jump to a specific entry.
1359 * Please always add entries at the end of the array.
1360 * Should this be fixed? - azummo
1363 int __init
ad1816_probe_isapnp(struct address_info
*hw_config
)
1367 /* Count entries in isapnp_ad1816_list */
1368 for (i
= 0; isapnp_ad1816_list
[i
].vendor
!= 0; i
++)
1370 /* Check and adjust isapnpjump */
1371 if( isapnpjump
< 0 || isapnpjump
> ( i
- 1 ) ) {
1372 printk(KERN_ERR
"ad1816: Valid range for isapnpjump is 0-%d. Adjusted to 0.\n", i
-1);
1376 for (i
= isapnpjump
; isapnp_ad1816_list
[i
].vendor
!= 0; i
++) {
1377 struct pci_dev
*card
= NULL
;
1379 while ((card
= isapnp_find_dev(NULL
, isapnp_ad1816_list
[i
].vendor
,
1380 isapnp_ad1816_list
[i
].function
, card
)))
1381 if(ad1816_init_isapnp(hw_config
, card
->bus
, card
, i
))
1389 static int __init
init_ad1816(void)
1392 #if defined CONFIG_ISAPNP || defined CONFIG_ISAPNP_MODULE
1393 if(isapnp
&& (ad1816_probe_isapnp(&cfg
) < 0) ) {
1394 printk(KERN_NOTICE
"ad1816: No ISAPnP cards found, trying standard ones...\n");
1406 if (cfg
.io_base
== -1 || cfg
.irq
== -1 || cfg
.dma
== -1 || cfg
.dma2
== -1) {
1407 printk(KERN_INFO
"ad1816: dma, dma2, irq and io must be set.\n");
1411 if (probe_ad1816(&cfg
) == 0) {
1415 attach_ad1816(&cfg
);
1420 static void __exit
cleanup_ad1816 (void)
1423 ad1816_info
*devc
= NULL
;
1425 /* remove any soundcard */
1426 for (i
= 0; i
< nr_ad1816_devs
; i
++) {
1427 devc
= &dev_info
[i
];
1432 #if defined CONFIG_ISAPNP || defined CONFIG_ISAPNP_MODULE
1435 ad1816_dev
->deactivate(ad1816_dev
);
1439 module_init(init_ad1816
);
1440 module_exit(cleanup_ad1816
);
1443 static int __init
setup_ad1816(char *str
)
1445 /* io, irq, dma, dma2 */
1448 str
= get_options(str
, ARRAY_SIZE(ints
), ints
);
1458 __setup("ad1816=", setup_ad1816
);