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>
6 Based on the CS4232/AD1848 driver Copyright (C) by Hannu Savolainen 1993-1996
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
18 You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software
20 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
22 -------------------------------------------------------------------------------
23 NOTE! NOTE! NOTE! NOTE! NOTE! NOTE! NOTE! NOTE! NOTE!
25 This software is still under development. New versions of the driver
27 http://www.student.informatik.tu-darmstadt.de/~tek/projects/linux.html
29 http://www.tu-darmstadt.de/~tek01/projects/linux.html
31 Please report any bugs to: tek@rbg.informatik.tu-darmstadt.de
33 -------------------------------------------------------------------------------
36 cvs: $Header: /home/tek/tmp/CVSROOT/sound21/ad1816.c,v 1.28 1999/01/16 19:01:36 tek Exp $
41 Oleg Drokin: Some cleanup of load/unload functions. 1998/11/24
43 Thorsten Knabe: attach and unload rewritten,
44 some argument checks added 1998/11/30
46 Thorsten Knabe: Buggy isa bridge workaround added 1999/01/16
49 #include <linux/config.h>
50 #include <linux/module.h>
51 #include <linux/stddef.h>
52 #include "soundmodule.h"
53 #include "sound_config.h"
60 #define DEBUGWARN(x) x
62 #define CHECK_FOR_POWER { int timeout=100; \
63 while (timeout > 0 && (inb(devc->base)&0x80)!= 0x80) {\
67 printk("ad1816: Check for power failed in %s line: %d\n",__FILE__,__LINE__); \
71 /* structure to hold device specific information */
74 int base
; /* set in attach */
82 unsigned char format_bits
;
86 int recmask
; /* setup */
87 int supported_devices
;
88 int supported_rec_devices
;
89 unsigned short levels
[SOUND_MIXER_NRDEVICES
];
90 int dev_no
; /* this is the # in audio_devs and NOT
99 static int nr_ad1816_devs
= 0;
101 static int ad1816_clockfreq
=33000;
103 /* for backward mapping of irq to sound device */
105 static volatile char irq2dev
[17] = {-1, -1, -1, -1, -1, -1, -1, -1,
106 -1, -1, -1, -1, -1, -1, -1, -1, -1};
109 /* supported audio formats */
110 static int ad_format_mask
=
111 AFMT_U8
| AFMT_S16_LE
| AFMT_S16_BE
| AFMT_MU_LAW
| AFMT_A_LAW
;
113 /* array of device info structures */
114 static ad1816_info dev_info
[MAX_AUDIO_DEV
];
117 /* ------------------------------------------------------------------- */
119 /* functions for easier access to inderect registers */
121 static int ad_read (ad1816_info
* devc
, int reg
)
128 save_flags (flags
); /* make register access atomic */
130 outb ((unsigned char) (reg
& 0x3f), devc
->base
+0);
131 result
= inb(devc
->base
+2);
132 result
+= inb(devc
->base
+3)<<8;
133 restore_flags (flags
);
139 static void ad_write (ad1816_info
* devc
, int reg
, int data
)
145 save_flags (flags
); /* make register access atomic */
147 outb ((unsigned char) (reg
& 0xff), devc
->base
+0);
148 outb ((unsigned char) (data
& 0xff),devc
->base
+2);
149 outb ((unsigned char) ((data
>>8)&0xff),devc
->base
+3);
150 restore_flags (flags
);
154 /* ------------------------------------------------------------------- */
156 /* function interface required by struct audio_driver */
158 static void ad1816_halt_input (int dev
)
161 ad1816_info
*devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
162 unsigned char buffer
;
164 DEBUGINFO (printk("ad1816: halt_input called\n"));
169 if(!isa_dma_bridge_buggy
) {
170 disable_dma(audio_devs
[dev
]->dmap_in
->dma
);
173 buffer
=inb(devc
->base
+9);
175 /* disable capture */
176 outb(buffer
& ~0x01,devc
->base
+9);
179 if(!isa_dma_bridge_buggy
) {
180 enable_dma(audio_devs
[dev
]->dmap_in
->dma
);
183 /* Clear interrupt status */
184 outb (~0x40, devc
->base
+1);
186 devc
->audio_mode
&= ~PCM_ENABLE_INPUT
;
187 restore_flags (flags
);
190 static void ad1816_halt_output (int dev
)
193 ad1816_info
*devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
195 unsigned char buffer
;
197 DEBUGINFO (printk("ad1816: halt_output called!\n"));
201 /* Mute pcm output */
202 ad_write(devc
, 4, ad_read(devc
,4)|0x8080);
204 if(!isa_dma_bridge_buggy
) {
205 disable_dma(audio_devs
[dev
]->dmap_out
->dma
);
208 buffer
=inb(devc
->base
+8);
210 /* disable capture */
211 outb(buffer
& ~0x01,devc
->base
+8);
214 if(!isa_dma_bridge_buggy
) {
215 enable_dma(audio_devs
[dev
]->dmap_out
->dma
);
218 /* Clear interrupt status */
219 outb ((unsigned char)~0x80, devc
->base
+1);
221 devc
->audio_mode
&= ~PCM_ENABLE_OUTPUT
;
222 restore_flags (flags
);
225 static void ad1816_output_block (int dev
, unsigned long buf
,
226 int count
, int intrflag
)
230 ad1816_info
*devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
232 DEBUGINFO(printk("ad1816: output_block called buf=%ld count=%d flags=%d\n",buf
,count
,intrflag
));
239 /* set transfer count */
240 ad_write (devc
, 8, cnt
& 0xffff);
242 devc
->audio_mode
|= PCM_ENABLE_OUTPUT
;
243 restore_flags (flags
);
247 static void ad1816_start_input (int dev
, unsigned long buf
, int count
,
252 ad1816_info
*devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
254 DEBUGINFO(printk("ad1816: start_input called buf=%ld count=%d flags=%d\n",buf
,count
,intrflag
));
258 save_flags (flags
); /* make register access atomic */
261 /* set transfer count */
262 ad_write (devc
, 10, cnt
& 0xffff);
264 devc
->audio_mode
|= PCM_ENABLE_INPUT
;
265 restore_flags (flags
);
269 static int ad1816_ioctl (int dev
, unsigned int cmd
, caddr_t arg
)
275 static int ad1816_prepare_for_input (int dev
, int bsize
, int bcount
)
279 ad1816_info
*devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
280 unsigned char fmt_bits
;
282 DEBUGINFO (printk ("ad1816: prepare_for_input called: bsize=%d bcount=%d\n",bsize
,bcount
));
287 fmt_bits
= (devc
->format_bits
&0x7)<<3;
289 /* set mono/stereo mode */
290 if (devc
->channels
> 1) {
294 /* set Mono/Stereo in playback/capture register */
295 outb( (inb(devc
->base
+8) & ~0x3C)|fmt_bits
, devc
->base
+8);
296 outb( (inb(devc
->base
+9) & ~0x3C)|fmt_bits
, devc
->base
+9);
298 /* If compiled into kernel, AD1816_CLOCK is defined, so use it */
300 ad1816_clockfreq
=AD1816_CLOCK
;
303 /* capture/playback frequency correction for soundcards
304 with clock chips != 33MHz (allowed range 5 - 100 kHz) */
306 if (ad1816_clockfreq
<5000 || ad1816_clockfreq
>100000) {
307 ad1816_clockfreq
=33000;
310 freq
=((unsigned int)devc
->speed
*33000)/ad1816_clockfreq
;
312 /* write playback/capture speeds */
313 ad_write (devc
, 2, freq
& 0xffff);
314 ad_write (devc
, 3, freq
& 0xffff);
316 restore_flags (flags
);
318 ad1816_halt_input(dev
);
322 static int ad1816_prepare_for_output (int dev
, int bsize
, int bcount
)
326 ad1816_info
*devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
327 unsigned char fmt_bits
;
329 DEBUGINFO (printk ("ad1816: prepare_for_output called: bsize=%d bcount=%d\n",bsize
,bcount
));
331 save_flags (flags
); /* make register access atomic */
334 fmt_bits
= (devc
->format_bits
&0x7)<<3;
335 /* set mono/stereo mode */
336 if (devc
->channels
> 1) {
340 /* write format bits to playback/capture registers */
341 outb( (inb(devc
->base
+8) & ~0x3C)|fmt_bits
, devc
->base
+8);
342 outb( (inb(devc
->base
+9) & ~0x3C)|fmt_bits
, devc
->base
+9);
345 ad1816_clockfreq
=AD1816_CLOCK
;
348 /* capture/playback frequency correction for soundcards
349 with clock chips != 33MHz (allowed range 5 - 100 kHz)*/
351 if (ad1816_clockfreq
<5000 || ad1816_clockfreq
>100000) {
352 ad1816_clockfreq
=33000;
355 freq
=((unsigned int)devc
->speed
*33000)/ad1816_clockfreq
;
357 /* write playback/capture speeds */
358 ad_write (devc
, 2, freq
& 0xffff);
359 ad_write (devc
, 3, freq
& 0xffff);
361 restore_flags (flags
);
363 ad1816_halt_output(dev
);
368 static void ad1816_trigger (int dev
, int state
)
371 ad1816_info
*devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
373 DEBUGINFO (printk("ad1816: trigger called! (devc=%d,devc->base=%d\n",devc
,devc
->base
));
375 /* mode may have changed */
377 save_flags (flags
); /* make register access atomic */
380 /* mask out modes not specified on open call */
381 state
&= devc
->audio_mode
;
383 /* setup soundchip to new io-mode */
384 if (state
& PCM_ENABLE_INPUT
) {
386 outb(inb(devc
->base
+9)|0x01, devc
->base
+9);
388 /* disable capture */
389 outb(inb(devc
->base
+9)&~0x01, devc
->base
+9);
392 if (state
& PCM_ENABLE_OUTPUT
) {
393 /* enable playback */
394 outb(inb(devc
->base
+8)|0x01, devc
->base
+8);
395 /* unmute pcm output */
396 ad_write(devc
, 4, ad_read(devc
,4)&~0x8080);
398 /* mute pcm output */
399 ad_write(devc
, 4, ad_read(devc
,4)|0x8080);
400 /* disable capture */
401 outb(inb(devc
->base
+8)&~0x01, devc
->base
+8);
403 restore_flags (flags
);
407 /* halt input & output */
408 static void ad1816_halt (int dev
)
410 ad1816_halt_input(dev
);
411 ad1816_halt_output(dev
);
414 static void ad1816_reset (int dev
)
419 /* set playback speed */
420 static int ad1816_set_speed (int dev
, int arg
)
422 ad1816_info
*devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
440 static unsigned int ad1816_set_bits (int dev
, unsigned int arg
)
442 ad1816_info
*devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
444 static struct format_tbl
491 int i
, n
= sizeof (format2bits
) / sizeof (struct format_tbl
);
493 /* return current format */
495 return devc
->audio_format
;
498 devc
->audio_format
= arg
;
500 /* search matching format bits */
501 for (i
= 0; i
< n
; i
++) {
502 if (format2bits
[i
].format
== arg
) {
503 devc
->format_bits
= format2bits
[i
].bits
;
504 devc
->audio_format
= arg
;
508 /* Still hanging here. Something must be terribly wrong */
509 devc
->format_bits
= 0;
510 return devc
->audio_format
= AFMT_U8
;
513 static short ad1816_set_channels (int dev
, short arg
)
515 ad1816_info
*devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
517 if (arg
!= 1 && arg
!= 2) {
518 return devc
->channels
;
521 devc
->channels
= arg
;
526 static int ad1816_open (int dev
, int mode
)
528 ad1816_info
*devc
= NULL
;
531 /* is device number valid ? */
532 if (dev
< 0 || dev
>= num_audiodevs
) {
536 /* get device info of this dev */
537 devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
539 /* make check if device already open atomic */
544 restore_flags (flags
);
548 /* mark device as open */
551 devc
->audio_mode
= 0;
553 devc
->audio_format
=AFMT_U8
;
556 ad1816_reset(devc
->dev_no
); /* halt all pending output */
557 restore_flags (flags
);
561 static void ad1816_close (int dev
) /* close device */
564 ad1816_info
*devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
569 /* halt all pending output */
570 ad1816_reset(devc
->dev_no
);
573 devc
->audio_mode
= 0;
575 devc
->audio_format
=AFMT_U8
;
576 devc
->format_bits
= 0;
579 restore_flags (flags
);
583 /* ------------------------------------------------------------------- */
585 /* Audio driver structure */
587 static struct audio_driver ad1816_audio_driver
=
594 ad1816_prepare_for_input
,
595 ad1816_prepare_for_output
,
610 /* ------------------------------------------------------------------- */
612 /* Interrupt handler */
614 void ad1816_interrupt (int irq
, void *dev_id
, struct pt_regs
*dummy
)
616 unsigned char status
;
622 if (irq
< 0 || irq
> 15) {
623 printk ("ad1816: Got bogus interrupt %d\n", irq
);
629 if (dev
< 0 || dev
>= num_audiodevs
) {
630 printk ("ad1816: IRQ2AD1816-mapping failed for irq %d device %d\n", irq
,dev
);
634 devc
= (ad1816_info
*) audio_devs
[dev
]->devc
;
639 /* read interrupt register */
640 status
= inb (devc
->base
+1);
641 /* Clear all interrupt */
642 outb (~status
, devc
->base
+1);
644 DEBUGNOISE (printk("ad1816: Got interrupt subclass %d\n",status
));
649 DEBUGWARN(printk ("ad1816: interrupt: Got interrupt, but no reason?\n"));
651 if (devc
->opened
&& (devc
->audio_mode
& PCM_ENABLE_INPUT
)
653 DMAbuf_inputintr (dev
);
656 if (devc
->opened
&& (devc
->audio_mode
& PCM_ENABLE_OUTPUT
) &&
658 DMAbuf_outputintr (dev
, 1);
660 restore_flags(flags
);
663 /* ------------------------------------------------------------------- */
668 unsigned int regno
: 7;
669 unsigned int polarity
:1; /* 0=normal, 1=reversed */
670 unsigned int bitpos
:4;
671 unsigned int nbits
:4;
674 static char mix_cvt
[101] = {
675 0, 0,3,7,10,13,16,19,21,23,26,28,30,32,34,35,37,39,40,42,
676 43,45,46,47,49,50,51,52,53,55,56,57,58,59,60,61,62,63,64,65,
677 65,66,67,68,69,70,70,71,72,73,73,74,75,75,76,77,77,78,79,79,
678 80,81,81,82,82,83,84,84,85,85,86,86,87,87,88,88,89,89,90,90,
679 91,91,92,92,93,93,94,94,95,95,96,96,96,97,97,98,98,98,99,99,
683 typedef struct mixer_def mixer_ent
;
686 * Most of the mixer entries work in backwards. Setting the polarity field
687 * makes them to work correctly.
689 * The channel numbering used by individual soundcards is not fixed. Some
690 * cards have assigned different meanings for the AUX1, AUX2 and LINE inputs.
691 * The current version doesn't try to compensate this.
694 #define MIX_ENT(name, reg_l, pola_l, pos_l, len_l, reg_r, pola_r, pos_r, len_r) \
695 {{reg_l, pola_l, pos_l, len_l}, {reg_r, pola_r, pos_r, len_r}}
698 mixer_ent mix_devices
[SOUND_MIXER_NRDEVICES
][2] = {
699 MIX_ENT(SOUND_MIXER_VOLUME
, 14, 1, 8, 5, 14, 1, 0, 5),
700 MIX_ENT(SOUND_MIXER_BASS
, 0, 0, 0, 0, 0, 0, 0, 0),
701 MIX_ENT(SOUND_MIXER_TREBLE
, 0, 0, 0, 0, 0, 0, 0, 0),
702 MIX_ENT(SOUND_MIXER_SYNTH
, 5, 1, 8, 6, 5, 1, 0, 6),
703 MIX_ENT(SOUND_MIXER_PCM
, 4, 1, 8, 6, 4, 1, 0, 6),
704 MIX_ENT(SOUND_MIXER_SPEAKER
, 0, 0, 0, 0, 0, 0, 0, 0),
705 MIX_ENT(SOUND_MIXER_LINE
, 18, 1, 8, 5, 18, 1, 0, 5),
706 MIX_ENT(SOUND_MIXER_MIC
, 19, 1, 8, 5, 19, 1, 0, 5),
707 MIX_ENT(SOUND_MIXER_CD
, 15, 1, 8, 5, 15, 1, 0, 5),
708 MIX_ENT(SOUND_MIXER_IMIX
, 0, 0, 0, 0, 0, 0, 0, 0),
709 MIX_ENT(SOUND_MIXER_ALTPCM
, 0, 0, 0, 0, 0, 0, 0, 0),
710 MIX_ENT(SOUND_MIXER_RECLEV
, 20, 0, 8, 4, 20, 0, 0, 4),
711 MIX_ENT(SOUND_MIXER_IGAIN
, 0, 0, 0, 0, 0, 0, 0, 0),
712 MIX_ENT(SOUND_MIXER_OGAIN
, 0, 0, 0, 0, 0, 0, 0, 0),
713 MIX_ENT(SOUND_MIXER_LINE1
, 17, 1, 8, 5, 17, 1, 0, 5),
714 MIX_ENT(SOUND_MIXER_LINE2
, 16, 1, 8, 5, 16, 1, 0, 5),
715 MIX_ENT(SOUND_MIXER_LINE3
, 39, 0, 9, 4, 39, 1, 0, 5)
719 static unsigned short default_mixer_levels
[SOUND_MIXER_NRDEVICES
] =
721 0x4343, /* Master Volume */
726 0x0000, /* PC Speaker */
727 0x0000, /* Ext Line */
730 0x0000, /* Recording monitor */
732 0x0000, /* Recording level */
733 0x0000, /* Input gain */
734 0x0000, /* Output gain */
737 0x0000 /* Line3 (usually line in)*/
746 ad1816_set_recmask (ad1816_info
* devc
, int mask
)
748 unsigned char recdev
;
751 mask
&= devc
->supported_rec_devices
;
754 /* Count selected device bits */
755 for (i
= 0; i
< 32; i
++) {
756 if (mask
& (1 << i
)) {
762 mask
= SOUND_MASK_MIC
;
763 } else if (n
!= 1) { /* Too many devices selected */
764 /* Filter out active settings */
765 mask
&= ~devc
->recmask
;
768 /* Count selected device bits */
769 for (i
= 0; i
< 32; i
++) {
770 if (mask
& (1 << i
)) {
776 mask
= SOUND_MASK_MIC
;
785 case SOUND_MASK_LINE
:
793 case SOUND_MASK_LINE1
:
797 case SOUND_MASK_LINE2
:
801 case SOUND_MASK_VOLUME
:
806 mask
= SOUND_MASK_MIC
;
812 (ad_read (devc
, 20) & 0x8f8f) | recdev
| (recdev
<<8));
814 devc
->recmask
= mask
;
819 change_bits (int *regval
, int dev
, int chn
, int newval
)
824 /* Reverse polarity*/
826 if (mix_devices
[dev
][chn
].polarity
== 1) {
827 newval
= 100 - newval
;
830 mask
= (1 << mix_devices
[dev
][chn
].nbits
) - 1;
831 shift
= mix_devices
[dev
][chn
].bitpos
;
833 newval
= (int) ((newval
* mask
) + 50) / 100;
835 *regval
&= ~(mask
<< shift
);
837 *regval
|= (newval
& mask
) << shift
;
841 ad1816_mixer_get (ad1816_info
* devc
, int dev
)
843 DEBUGINFO(printk("ad1816: mixer_get called!\n"));
845 /* range check + supported mixer check */
846 if (dev
< 0 || dev
>= SOUND_MIXER_NRDEVICES
) {
849 if (!((1 << dev
) & devc
->supported_devices
)) {
853 return devc
->levels
[dev
];
857 ad1816_mixer_set (ad1816_info
* devc
, int dev
, int value
)
859 int left
= value
& 0x000000ff;
860 int right
= (value
& 0x0000ff00) >> 8;
867 DEBUGINFO(printk("ad1816: mixer_set called!\n"));
869 if (dev
< 0 || dev
>= SOUND_MIXER_NRDEVICES
) {
887 if (mix_devices
[dev
][RIGHT_CHN
].nbits
== 0) {
890 retvol
= left
| (right
<< 8);
894 left
= mix_cvt
[left
];
895 right
= mix_cvt
[right
];
897 /* reject all mixers that are not supported */
898 if (!(devc
->supported_devices
& (1 << dev
))) {
903 if (mix_devices
[dev
][LEFT_CHN
].nbits
== 0) {
907 /* keep precise volume internal */
908 devc
->levels
[dev
] = retvol
;
910 /* Set the left channel */
911 regoffs
= mix_devices
[dev
][LEFT_CHN
].regno
;
912 val
= ad_read (devc
, regoffs
);
913 change_bits (&val
, dev
, LEFT_CHN
, left
);
917 /* Mute bit masking on some registers */
918 if ( regoffs
==5 || regoffs
==14 || regoffs
==15 ||
919 regoffs
==16 || regoffs
==17 || regoffs
==18 ||
920 regoffs
==19 || regoffs
==39) {
927 ad_write (devc
, regoffs
, valmute
); /* mute */
930 * Set the right channel
933 /* Was just a mono channel */
934 if (mix_devices
[dev
][RIGHT_CHN
].nbits
== 0) {
937 regoffs
= mix_devices
[dev
][RIGHT_CHN
].regno
;
938 val
= ad_read (devc
, regoffs
);
939 change_bits (&val
, dev
, RIGHT_CHN
, right
);
942 if ( regoffs
==5 || regoffs
==14 || regoffs
==15 ||
943 regoffs
==16 || regoffs
==17 || regoffs
==18 ||
944 regoffs
==19 || regoffs
==39) {
951 ad_write (devc
, regoffs
, valmute
); /* mute */
956 #define MIXER_DEVICES ( SOUND_MASK_VOLUME | \
967 #define REC_DEVICES ( SOUND_MASK_LINE2 |\
976 ad1816_mixer_reset (ad1816_info
* devc
)
980 devc
->supported_devices
= MIXER_DEVICES
;
982 devc
->supported_rec_devices
= REC_DEVICES
;
984 for (i
= 0; i
< SOUND_MIXER_NRDEVICES
; i
++) {
985 if (devc
->supported_devices
& (1 << i
)) {
986 ad1816_mixer_set (devc
, i
, default_mixer_levels
[i
]);
989 ad1816_set_recmask (devc
, SOUND_MASK_MIC
);
993 ad1816_mixer_ioctl (int dev
, unsigned int cmd
, caddr_t arg
)
995 ad1816_info
*devc
= mixer_devs
[dev
]->devc
;
998 DEBUGINFO(printk("ad1816: mixer_ioctl called!\n"));
1001 if (((cmd
>> 8) & 0xff) == 'M') {
1004 if (_IOC_DIR (cmd
) & _IOC_WRITE
) {
1005 switch (cmd
& 0xff){
1006 case SOUND_MIXER_RECSRC
:
1008 if (get_user(val
, (int *)arg
)) {
1011 val
=ad1816_set_recmask (devc
, val
);
1012 return put_user(val
, (int *)arg
);
1016 if (get_user(val
, (int *)arg
)){
1019 if ((val
=ad1816_mixer_set (devc
, cmd
& 0xff, val
))<0) {
1022 return put_user(val
, (int *)arg
);
1027 switch (cmd
& 0xff) {
1029 case SOUND_MIXER_RECSRC
:
1031 return put_user(val
, (int *)arg
);
1034 case SOUND_MIXER_DEVMASK
:
1035 val
=devc
->supported_devices
;
1036 return put_user(val
, (int *)arg
);
1039 case SOUND_MIXER_STEREODEVS
:
1040 val
=devc
->supported_devices
& ~(SOUND_MASK_SPEAKER
| SOUND_MASK_IMIX
);
1041 return put_user(val
, (int *)arg
);
1044 case SOUND_MIXER_RECMASK
:
1045 val
=devc
->supported_rec_devices
;
1046 return put_user(val
, (int *)arg
);
1049 case SOUND_MIXER_CAPS
:
1050 val
=SOUND_CAP_EXCL_INPUT
;
1051 return put_user(val
, (int *)arg
);
1055 if ((val
=ad1816_mixer_get (devc
, cmd
& 0xff))<0) {
1058 return put_user(val
, (int *)arg
);
1068 /* ------------------------------------------------------------------- */
1070 /* Mixer structure */
1072 static struct mixer_operations ad1816_mixer_operations
=
1080 /* ------------------------------------------------------------------- */
1082 /* stuff for card recognition, init and unloading */
1085 /* replace with probe routine */
1086 int probe_ad1816 ( struct address_info
*hw_config
)
1088 ad1816_info
*devc
= &dev_info
[nr_ad1816_devs
];
1089 int io_base
=hw_config
->io_base
;
1090 int *osp
=hw_config
->osp
;
1093 printk("ad1816: AD1816 sounddriver Copyright (C) 1998 by Thorsten Knabe\n");
1094 printk("ad1816: $Header: /home/tek/tmp/CVSROOT/sound21/ad1816.c,v 1.28 1999/01/16 19:01:36 tek Exp $\n");
1095 printk("ad1816: io=0x%x, irq=%d, dma=%d, dma2=%d, isadmabug=%d\n",
1100 isa_dma_bridge_buggy
);
1102 if (check_region (io_base
, 16)) {
1103 printk ("ad1816: I/O port 0x%03x not free\n", io_base
);
1107 DEBUGLOG(printk ("ad1816: detect(%x)\n", io_base
));
1109 if (nr_ad1816_devs
>= MAX_AUDIO_DEV
) {
1110 printk ("ad1816: detect error - step 0\n");
1114 devc
->base
= io_base
;
1120 /* base+0: bit 1 must be set but not 255 */
1121 tmp
=inb(devc
->base
);
1122 if ( (tmp
&0x80)==0 || tmp
==255 ) {
1123 DEBUGLOG (printk ("ad1816: Chip is not an AD1816 or chip is not active (Test 0)\n"));
1128 /* writes to ireg 8 are copied to ireg 9 */
1129 ad_write(devc
,8,12345);
1130 if (ad_read(devc
,9)!=12345) {
1131 DEBUGLOG (printk ("ad1816: Chip is not an AD1816 (Test 1)\n"));
1135 /* writes to ireg 8 are copied to ireg 9 */
1136 ad_write(devc
,8,54321);
1137 if (ad_read(devc
,9)!=54321) {
1138 DEBUGLOG (printk ("ad1816: Chip is not an AD1816 (Test 2)\n"));
1142 /* writes to ireg 10 are copied to ireg 11 */
1143 ad_write(devc
,10,54321);
1144 if (ad_read(devc
,11)!=54321) {
1145 DEBUGLOG (printk ("ad1816: Chip is not an AD1816 (Test 3)\n"));
1149 /* writes to ireg 10 are copied to ireg 11 */
1150 ad_write(devc
,10,12345);
1151 if (ad_read(devc
,11)!=12345) {
1152 DEBUGLOG (printk ("ad1816: Chip is not an AD1816 (Test 4)\n"));
1156 /* bit in base +1 cannot be set to 1 */
1157 tmp
=inb(devc
->base
+1);
1158 outb(0xff,devc
->base
+1);
1159 if (inb(devc
->base
+1)!=tmp
) {
1160 DEBUGLOG (printk ("ad1816: Chip is not an AD1816 (Test 5)\n"));
1165 DEBUGLOG (printk ("ad1816: detect() - Detected OK\n"));
1166 DEBUGLOG (printk ("ad1816: AD1816 Version: %d\n",ad_read(devc
,45)));
1168 /* detection was successful */
1173 /* allocate resources from the kernel. If any allocation fails, free
1174 all allocated resources and exit attach.
1178 void attach_ad1816 (struct address_info
*hw_config
)
1182 ad1816_info
*devc
= &dev_info
[nr_ad1816_devs
];
1185 /* allocate i/o ports */
1186 request_region (hw_config
->io_base
, 16, "AD1816 Sound");
1187 devc
->base
= hw_config
->io_base
;
1189 /* disable all interrupts */
1192 /* Clear pending interrupts */
1193 outb (0, devc
->base
+1);
1196 if (hw_config
->irq
< 0 || hw_config
->irq
> 15) {
1197 release_region(hw_config
->io_base
, 16);
1200 if (request_irq(hw_config
->irq
, ad1816_interrupt
,0,
1202 hw_config
->osp
) < 0) {
1203 printk ("ad1816: IRQ in use\n");
1204 release_region(hw_config
->io_base
, 16);
1207 devc
->irq
=hw_config
->irq
;
1210 if (sound_alloc_dma (hw_config
->dma
, "Sound System")) {
1211 printk ("ad1816: Can't allocate DMA%d\n", hw_config
->dma
);
1212 free_irq(hw_config
->irq
,hw_config
->osp
);
1213 release_region(hw_config
->io_base
, 16);
1216 devc
->dma_playback
=hw_config
->dma
;
1218 if ( hw_config
->dma2
!= -1 && hw_config
->dma2
!= hw_config
->dma
) {
1219 if (sound_alloc_dma (hw_config
->dma2
, "Sound System (capture)")) {
1220 printk ("ad1816: Can't allocate DMA%d\n", hw_config
->dma2
);
1221 sound_free_dma(hw_config
->dma
);
1222 free_irq(hw_config
->irq
,hw_config
->osp
);
1223 release_region(hw_config
->io_base
, 16);
1226 devc
->dma_capture
=hw_config
->dma2
;
1227 devc
->audio_mode
=DMA_AUTOMODE
|DMA_DUPLEX
;
1229 devc
->dma_capture
=-1;
1230 devc
->audio_mode
=DMA_AUTOMODE
;
1233 sprintf (dev_name
,"AD1816 audio driver");
1235 conf_printf2 (dev_name
,
1236 devc
->base
, devc
->irq
, hw_config
->dma
, hw_config
->dma2
);
1238 /* register device */
1239 if ((my_dev
= sound_install_audiodrv (AUDIO_DRIVER_VERSION
,
1241 &ad1816_audio_driver
,
1242 sizeof (struct audio_driver
),
1247 hw_config
->dma2
)) < 0) {
1248 printk ("ad1816: Can't install sound driver\n");
1249 if (devc
->dma_capture
>=0) {
1250 sound_free_dma(hw_config
->dma2
);
1252 sound_free_dma(hw_config
->dma
);
1253 free_irq(hw_config
->irq
,hw_config
->osp
);
1254 release_region(hw_config
->io_base
, 16);
1259 /* fill rest of structure with reasonable default values */
1260 irq2dev
[hw_config
->irq
] = devc
->dev_no
= my_dev
;
1263 devc
->osp
= hw_config
->osp
;
1266 ad_write(devc
,32,0x80f0); /* sound system mode */
1267 ad_write(devc
,33,0x03f8); /* enable all audiosources for dsp */
1268 ad_write(devc
,4,0x8080); /* default values for volumes (muted)*/
1269 ad_write(devc
,5,0x8080);
1270 ad_write(devc
,6,0x8080);
1271 ad_write(devc
,7,0x8080);
1272 ad_write(devc
,15,0x8888);
1273 ad_write(devc
,16,0x8888);
1274 ad_write(devc
,17,0x8888);
1275 ad_write(devc
,18,0x8888);
1276 ad_write(devc
,19,0xc888); /* +20db mic active */
1277 ad_write(devc
,14,0x0000); /* Master volume unmuted full power */
1278 ad_write(devc
,39,0x009f); /* 3D effect on 0% phone out muted */
1279 ad_write(devc
,44,0x0080); /* everything on power, 3d enabled for d/a */
1280 outb(0x10,devc
->base
+8); /* set dma mode */
1281 outb(0x10,devc
->base
+9);
1283 /* enable capture + playback interrupt */
1284 ad_write(devc
,1,0xc000);
1286 /* set mixer defaults */
1287 ad1816_mixer_reset (devc
);
1289 /* register mixer */
1290 if ((audio_devs
[my_dev
]->mixer_dev
=sound_install_mixer(
1291 MIXER_DRIVER_VERSION
,
1293 &ad1816_mixer_operations
,
1294 sizeof (struct mixer_operations
),
1296 audio_devs
[my_dev
]->min_fragment
= 0;
1300 void unload_card(ad1816_info
*devc
)
1305 DEBUGLOG (printk("ad1816: Unloading card at base=%x\n",devc
->base
));
1308 mixer
= audio_devs
[dev
]->mixer_dev
;
1312 sound_unload_mixerdev(mixer
);
1314 sound_unload_audiodev(dev
);
1316 /* free dma channels */
1317 if (devc
->dma_capture
>=0) {
1318 sound_free_dma(devc
->dma_capture
);
1321 /* card wont get added if resources could not be allocated
1322 thus we need not ckeck if allocation was successful */
1323 sound_free_dma (devc
->dma_playback
);
1324 free_irq(devc
->irq
, devc
->osp
);
1325 release_region (devc
->base
, 16);
1327 DEBUGLOG (printk("ad1816: Unloading card at base=%x was successful\n",devc
->base
));
1330 printk ("ad1816: no device/card specified\n");
1334 void unload_ad1816 (struct address_info
*hw_config
)
1337 ad1816_info
*devc
= NULL
;
1339 /* remove any soundcard */
1340 if (hw_config
==NULL
) {
1341 for (i
= 0; i
< nr_ad1816_devs
; i
++) {
1342 devc
= &dev_info
[i
];
1347 /* remove specified soundcard */
1348 for (i
= 0; i
< nr_ad1816_devs
; i
++) {
1351 if (dev_info
[i
].base
== hw_config
->io_base
) {
1352 devc
= &dev_info
[i
];
1355 for ( j
=i
; j
< nr_ad1816_devs
; j
++) {
1356 dev_info
[j
] = dev_info
[j
+1];
1365 /* ----------------------------- 2.1.xxx module stuff ----------------- */
1367 EXPORT_SYMBOL(ad1816_interrupt
);
1368 EXPORT_SYMBOL(probe_ad1816
);
1369 EXPORT_SYMBOL(attach_ad1816
);
1370 EXPORT_SYMBOL(unload_ad1816
);
1380 MODULE_PARM(io
,"i");
1381 MODULE_PARM(irq
,"i");
1382 MODULE_PARM(dma
,"i");
1383 MODULE_PARM(dma2
,"i");
1384 MODULE_PARM(ad1816_clockfreq
,"i");
1386 struct address_info cfg
;
1389 int init_module(void)
1391 if (io
== -1 || irq
== -1 || dma
== -1 || dma2
== -1) {
1392 printk("ad1816: dma, dma2, irq and io must be set.\n");
1400 if (probe_ad1816(&cfg
) == 0) {
1403 attach_ad1816(&cfg
);
1409 void cleanup_module(void)
1411 unload_ad1816(NULL
);
1417 #endif /* CONFIG_AD1816 */