net: sis: sis190: use new api ethtool_{get|set}_link_ksettings
[linux-2.6/btrfs-unstable.git] / sound / oss / ad1848.c
blobf6156d8169d05b259c1fb35219efa7d6e3def735
1 /*
2 * sound/oss/ad1848.c
4 * The low level driver for the AD1848/CS4248 codec chip which
5 * is used for example in the MS Sound System.
7 * The CS4231 which is used in the GUS MAX and some other cards is
8 * upwards compatible with AD1848 and this driver is able to drive it.
10 * CS4231A and AD1845 are upward compatible with CS4231. However
11 * the new features of these chips are different.
13 * CS4232 is a PnP audio chip which contains a CS4231A (and SB, MPU).
14 * CS4232A is an improved version of CS4232.
18 * Copyright (C) by Hannu Savolainen 1993-1997
20 * OSS/Free for Linux is distributed under the GNU GENERAL PUBLIC LICENSE (GPL)
21 * Version 2 (June 1991). See the "COPYING" file distributed with this software
22 * for more info.
25 * Thomas Sailer : ioctl code reworked (vmalloc/vfree removed)
26 * general sleep/wakeup clean up.
27 * Alan Cox : reformatted. Fixed SMP bugs. Moved to kernel alloc/free
28 * of irqs. Use dev_id.
29 * Christoph Hellwig : adapted to module_init/module_exit
30 * Aki Laukkanen : added power management support
31 * Arnaldo C. de Melo : added missing restore_flags in ad1848_resume
32 * Miguel Freitas : added ISA PnP support
33 * Alan Cox : Added CS4236->4239 identification
34 * Daniel T. Cobra : Alernate config/mixer for later chips
35 * Alan Cox : Merged chip idents and config code
37 * TODO
38 * APM save restore assist code on IBM thinkpad
40 * Status:
41 * Tested. Believed fully functional.
44 #include <linux/init.h>
45 #include <linux/interrupt.h>
46 #include <linux/module.h>
47 #include <linux/stddef.h>
48 #include <linux/slab.h>
49 #include <linux/isapnp.h>
50 #include <linux/pnp.h>
51 #include <linux/spinlock.h>
53 #include "sound_config.h"
55 #include "ad1848.h"
56 #include "ad1848_mixer.h"
58 typedef struct
60 spinlock_t lock;
61 int base;
62 int irq;
63 int dma1, dma2;
64 int dual_dma; /* 1, when two DMA channels allocated */
65 int subtype;
66 unsigned char MCE_bit;
67 unsigned char saved_regs[64]; /* Includes extended register space */
68 int debug_flag;
70 int audio_flags;
71 int record_dev, playback_dev;
73 int xfer_count;
74 int audio_mode;
75 int open_mode;
76 int intr_active;
77 char *chip_name, *name;
78 int model;
79 #define MD_1848 1
80 #define MD_4231 2
81 #define MD_4231A 3
82 #define MD_1845 4
83 #define MD_4232 5
84 #define MD_C930 6
85 #define MD_IWAVE 7
86 #define MD_4235 8 /* Crystal Audio CS4235 */
87 #define MD_1845_SSCAPE 9 /* Ensoniq Soundscape PNP*/
88 #define MD_4236 10 /* 4236 and higher */
89 #define MD_42xB 11 /* CS 42xB */
90 #define MD_4239 12 /* CS4239 */
92 /* Mixer parameters */
93 int recmask;
94 int supported_devices, orig_devices;
95 int supported_rec_devices, orig_rec_devices;
96 int *levels;
97 short mixer_reroute[32];
98 int dev_no;
99 volatile unsigned long timer_ticks;
100 int timer_running;
101 int irq_ok;
102 mixer_ents *mix_devices;
103 int mixer_output_port;
104 } ad1848_info;
106 typedef struct ad1848_port_info
108 int open_mode;
109 int speed;
110 unsigned char speed_bits;
111 int channels;
112 int audio_format;
113 unsigned char format_bits;
115 ad1848_port_info;
117 static struct address_info cfg;
118 static int nr_ad1848_devs;
120 static bool deskpro_xl;
121 static bool deskpro_m;
122 static bool soundpro;
124 #ifndef EXCLUDE_TIMERS
125 static int timer_installed = -1;
126 #endif
128 static int loaded;
130 static int ad_format_mask[13 /*devc->model */ ] =
133 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW,
134 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
135 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
136 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW, /* AD1845 */
137 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
138 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
139 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
140 AFMT_U8 | AFMT_S16_LE /* CS4235 */,
141 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW /* Ensoniq Soundscape*/,
142 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
143 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM,
144 AFMT_U8 | AFMT_S16_LE | AFMT_MU_LAW | AFMT_A_LAW | AFMT_S16_BE | AFMT_IMA_ADPCM
147 static ad1848_info adev_info[MAX_AUDIO_DEV];
149 #define io_Index_Addr(d) ((d)->base)
150 #define io_Indexed_Data(d) ((d)->base+1)
151 #define io_Status(d) ((d)->base+2)
152 #define io_Polled_IO(d) ((d)->base+3)
154 static struct {
155 unsigned char flags;
156 #define CAP_F_TIMER 0x01
157 } capabilities [10 /*devc->model */ ] = {
159 ,{0} /* MD_1848 */
160 ,{CAP_F_TIMER} /* MD_4231 */
161 ,{CAP_F_TIMER} /* MD_4231A */
162 ,{CAP_F_TIMER} /* MD_1845 */
163 ,{CAP_F_TIMER} /* MD_4232 */
164 ,{0} /* MD_C930 */
165 ,{CAP_F_TIMER} /* MD_IWAVE */
166 ,{0} /* MD_4235 */
167 ,{CAP_F_TIMER} /* MD_1845_SSCAPE */
170 #ifdef CONFIG_PNP
171 static int isapnp = 1;
172 static int isapnpjump;
173 static bool reverse;
175 static int audio_activated;
176 #else
177 static int isapnp;
178 #endif
182 static int ad1848_open(int dev, int mode);
183 static void ad1848_close(int dev);
184 static void ad1848_output_block(int dev, unsigned long buf, int count, int intrflag);
185 static void ad1848_start_input(int dev, unsigned long buf, int count, int intrflag);
186 static int ad1848_prepare_for_output(int dev, int bsize, int bcount);
187 static int ad1848_prepare_for_input(int dev, int bsize, int bcount);
188 static void ad1848_halt(int dev);
189 static void ad1848_halt_input(int dev);
190 static void ad1848_halt_output(int dev);
191 static void ad1848_trigger(int dev, int bits);
192 static irqreturn_t adintr(int irq, void *dev_id);
194 #ifndef EXCLUDE_TIMERS
195 static int ad1848_tmr_install(int dev);
196 static void ad1848_tmr_reprogram(int dev);
197 #endif
199 static int ad_read(ad1848_info * devc, int reg)
201 int x;
202 int timeout = 900000;
204 while (timeout > 0 && inb(devc->base) == 0x80) /*Are we initializing */
205 timeout--;
207 if(reg < 32)
209 outb(((unsigned char) (reg & 0xff) | devc->MCE_bit), io_Index_Addr(devc));
210 x = inb(io_Indexed_Data(devc));
212 else
214 int xreg, xra;
216 xreg = (reg & 0xff) - 32;
217 xra = (((xreg & 0x0f) << 4) & 0xf0) | 0x08 | ((xreg & 0x10) >> 2);
218 outb(((unsigned char) (23 & 0xff) | devc->MCE_bit), io_Index_Addr(devc));
219 outb(((unsigned char) (xra & 0xff)), io_Indexed_Data(devc));
220 x = inb(io_Indexed_Data(devc));
223 return x;
226 static void ad_write(ad1848_info * devc, int reg, int data)
228 int timeout = 900000;
230 while (timeout > 0 && inb(devc->base) == 0x80) /* Are we initializing */
231 timeout--;
233 if(reg < 32)
235 outb(((unsigned char) (reg & 0xff) | devc->MCE_bit), io_Index_Addr(devc));
236 outb(((unsigned char) (data & 0xff)), io_Indexed_Data(devc));
238 else
240 int xreg, xra;
242 xreg = (reg & 0xff) - 32;
243 xra = (((xreg & 0x0f) << 4) & 0xf0) | 0x08 | ((xreg & 0x10) >> 2);
244 outb(((unsigned char) (23 & 0xff) | devc->MCE_bit), io_Index_Addr(devc));
245 outb(((unsigned char) (xra & 0xff)), io_Indexed_Data(devc));
246 outb((unsigned char) (data & 0xff), io_Indexed_Data(devc));
250 static void wait_for_calibration(ad1848_info * devc)
252 int timeout;
255 * Wait until the auto calibration process has finished.
257 * 1) Wait until the chip becomes ready (reads don't return 0x80).
258 * 2) Wait until the ACI bit of I11 gets on and then off.
261 timeout = 100000;
262 while (timeout > 0 && inb(devc->base) == 0x80)
263 timeout--;
264 if (inb(devc->base) & 0x80)
265 printk(KERN_WARNING "ad1848: Auto calibration timed out(1).\n");
267 timeout = 100;
268 while (timeout > 0 && !(ad_read(devc, 11) & 0x20))
269 timeout--;
270 if (!(ad_read(devc, 11) & 0x20))
271 return;
273 timeout = 80000;
274 while (timeout > 0 && (ad_read(devc, 11) & 0x20))
275 timeout--;
276 if (ad_read(devc, 11) & 0x20)
277 if ((devc->model != MD_1845) && (devc->model != MD_1845_SSCAPE))
278 printk(KERN_WARNING "ad1848: Auto calibration timed out(3).\n");
281 static void ad_mute(ad1848_info * devc)
283 int i;
284 unsigned char prev;
287 * Save old register settings and mute output channels
290 for (i = 6; i < 8; i++)
292 prev = devc->saved_regs[i] = ad_read(devc, i);
297 static void ad_unmute(ad1848_info * devc)
301 static void ad_enter_MCE(ad1848_info * devc)
303 int timeout = 1000;
304 unsigned short prev;
306 while (timeout > 0 && inb(devc->base) == 0x80) /*Are we initializing */
307 timeout--;
309 devc->MCE_bit = 0x40;
310 prev = inb(io_Index_Addr(devc));
311 if (prev & 0x40)
313 return;
315 outb((devc->MCE_bit), io_Index_Addr(devc));
318 static void ad_leave_MCE(ad1848_info * devc)
320 unsigned char prev, acal;
321 int timeout = 1000;
323 while (timeout > 0 && inb(devc->base) == 0x80) /*Are we initializing */
324 timeout--;
326 acal = ad_read(devc, 9);
328 devc->MCE_bit = 0x00;
329 prev = inb(io_Index_Addr(devc));
330 outb((0x00), io_Index_Addr(devc)); /* Clear the MCE bit */
332 if ((prev & 0x40) == 0) /* Not in MCE mode */
334 return;
336 outb((0x00), io_Index_Addr(devc)); /* Clear the MCE bit */
337 if (acal & 0x08) /* Auto calibration is enabled */
338 wait_for_calibration(devc);
341 static int ad1848_set_recmask(ad1848_info * devc, int mask)
343 unsigned char recdev;
344 int i, n;
345 unsigned long flags;
347 mask &= devc->supported_rec_devices;
349 /* Rename the mixer bits if necessary */
350 for (i = 0; i < 32; i++)
352 if (devc->mixer_reroute[i] != i)
354 if (mask & (1 << i))
356 mask &= ~(1 << i);
357 mask |= (1 << devc->mixer_reroute[i]);
362 n = 0;
363 for (i = 0; i < 32; i++) /* Count selected device bits */
364 if (mask & (1 << i))
365 n++;
367 spin_lock_irqsave(&devc->lock,flags);
368 if (!soundpro) {
369 if (n == 0)
370 mask = SOUND_MASK_MIC;
371 else if (n != 1) { /* Too many devices selected */
372 mask &= ~devc->recmask; /* Filter out active settings */
374 n = 0;
375 for (i = 0; i < 32; i++) /* Count selected device bits */
376 if (mask & (1 << i))
377 n++;
379 if (n != 1)
380 mask = SOUND_MASK_MIC;
382 switch (mask) {
383 case SOUND_MASK_MIC:
384 recdev = 2;
385 break;
387 case SOUND_MASK_LINE:
388 case SOUND_MASK_LINE3:
389 recdev = 0;
390 break;
392 case SOUND_MASK_CD:
393 case SOUND_MASK_LINE1:
394 recdev = 1;
395 break;
397 case SOUND_MASK_IMIX:
398 recdev = 3;
399 break;
401 default:
402 mask = SOUND_MASK_MIC;
403 recdev = 2;
406 recdev <<= 6;
407 ad_write(devc, 0, (ad_read(devc, 0) & 0x3f) | recdev);
408 ad_write(devc, 1, (ad_read(devc, 1) & 0x3f) | recdev);
409 } else { /* soundpro */
410 unsigned char val;
411 int set_rec_bit;
412 int j;
414 for (i = 0; i < 32; i++) { /* For each bit */
415 if ((devc->supported_rec_devices & (1 << i)) == 0)
416 continue; /* Device not supported */
418 for (j = LEFT_CHN; j <= RIGHT_CHN; j++) {
419 if (devc->mix_devices[i][j].nbits == 0) /* Inexistent channel */
420 continue;
423 * This is tricky:
424 * set_rec_bit becomes 1 if the corresponding bit in mask is set
425 * then it gets flipped if the polarity is inverse
427 set_rec_bit = ((mask & (1 << i)) != 0) ^ devc->mix_devices[i][j].recpol;
429 val = ad_read(devc, devc->mix_devices[i][j].recreg);
430 val &= ~(1 << devc->mix_devices[i][j].recpos);
431 val |= (set_rec_bit << devc->mix_devices[i][j].recpos);
432 ad_write(devc, devc->mix_devices[i][j].recreg, val);
436 spin_unlock_irqrestore(&devc->lock,flags);
438 /* Rename the mixer bits back if necessary */
439 for (i = 0; i < 32; i++)
441 if (devc->mixer_reroute[i] != i)
443 if (mask & (1 << devc->mixer_reroute[i]))
445 mask &= ~(1 << devc->mixer_reroute[i]);
446 mask |= (1 << i);
450 devc->recmask = mask;
451 return mask;
454 static void oss_change_bits(ad1848_info *devc, unsigned char *regval,
455 unsigned char *muteval, int dev, int chn, int newval)
457 unsigned char mask;
458 int shift;
459 int mute;
460 int mutemask;
461 int set_mute_bit;
463 set_mute_bit = (newval == 0) ^ devc->mix_devices[dev][chn].mutepol;
465 if (devc->mix_devices[dev][chn].polarity == 1) /* Reverse */
466 newval = 100 - newval;
468 mask = (1 << devc->mix_devices[dev][chn].nbits) - 1;
469 shift = devc->mix_devices[dev][chn].bitpos;
471 if (devc->mix_devices[dev][chn].mutepos == 8)
472 { /* if there is no mute bit */
473 mute = 0; /* No mute bit; do nothing special */
474 mutemask = ~0; /* No mute bit; do nothing special */
476 else
478 mute = (set_mute_bit << devc->mix_devices[dev][chn].mutepos);
479 mutemask = ~(1 << devc->mix_devices[dev][chn].mutepos);
482 newval = (int) ((newval * mask) + 50) / 100; /* Scale it */
483 *regval &= ~(mask << shift); /* Clear bits */
484 *regval |= (newval & mask) << shift; /* Set new value */
486 *muteval &= mutemask;
487 *muteval |= mute;
490 static int ad1848_mixer_get(ad1848_info * devc, int dev)
492 if (!((1 << dev) & devc->supported_devices))
493 return -EINVAL;
495 dev = devc->mixer_reroute[dev];
497 return devc->levels[dev];
500 static void ad1848_mixer_set_channel(ad1848_info *devc, int dev, int value, int channel)
502 int regoffs, muteregoffs;
503 unsigned char val, muteval;
504 unsigned long flags;
506 regoffs = devc->mix_devices[dev][channel].regno;
507 muteregoffs = devc->mix_devices[dev][channel].mutereg;
508 val = ad_read(devc, regoffs);
510 if (muteregoffs != regoffs) {
511 muteval = ad_read(devc, muteregoffs);
512 oss_change_bits(devc, &val, &muteval, dev, channel, value);
514 else
515 oss_change_bits(devc, &val, &val, dev, channel, value);
517 spin_lock_irqsave(&devc->lock,flags);
518 ad_write(devc, regoffs, val);
519 devc->saved_regs[regoffs] = val;
520 if (muteregoffs != regoffs) {
521 ad_write(devc, muteregoffs, muteval);
522 devc->saved_regs[muteregoffs] = muteval;
524 spin_unlock_irqrestore(&devc->lock,flags);
527 static int ad1848_mixer_set(ad1848_info * devc, int dev, int value)
529 int left = value & 0x000000ff;
530 int right = (value & 0x0000ff00) >> 8;
531 int retvol;
533 if (dev > 31)
534 return -EINVAL;
536 if (!(devc->supported_devices & (1 << dev)))
537 return -EINVAL;
539 dev = devc->mixer_reroute[dev];
541 if (devc->mix_devices[dev][LEFT_CHN].nbits == 0)
542 return -EINVAL;
544 if (left > 100)
545 left = 100;
546 if (right > 100)
547 right = 100;
549 if (devc->mix_devices[dev][RIGHT_CHN].nbits == 0) /* Mono control */
550 right = left;
552 retvol = left | (right << 8);
554 /* Scale volumes */
555 left = mix_cvt[left];
556 right = mix_cvt[right];
558 devc->levels[dev] = retvol;
561 * Set the left channel
563 ad1848_mixer_set_channel(devc, dev, left, LEFT_CHN);
566 * Set the right channel
568 if (devc->mix_devices[dev][RIGHT_CHN].nbits == 0)
569 goto out;
570 ad1848_mixer_set_channel(devc, dev, right, RIGHT_CHN);
572 out:
573 return retvol;
576 static void ad1848_mixer_reset(ad1848_info * devc)
578 int i;
579 char name[32];
580 unsigned long flags;
582 devc->mix_devices = &(ad1848_mix_devices[0]);
584 sprintf(name, "%s_%d", devc->chip_name, nr_ad1848_devs);
586 for (i = 0; i < 32; i++)
587 devc->mixer_reroute[i] = i;
589 devc->supported_rec_devices = MODE1_REC_DEVICES;
591 switch (devc->model)
593 case MD_4231:
594 case MD_4231A:
595 case MD_1845:
596 case MD_1845_SSCAPE:
597 devc->supported_devices = MODE2_MIXER_DEVICES;
598 break;
600 case MD_C930:
601 devc->supported_devices = C930_MIXER_DEVICES;
602 devc->mix_devices = &(c930_mix_devices[0]);
603 break;
605 case MD_IWAVE:
606 devc->supported_devices = MODE3_MIXER_DEVICES;
607 devc->mix_devices = &(iwave_mix_devices[0]);
608 break;
610 case MD_42xB:
611 case MD_4239:
612 devc->mix_devices = &(cs42xb_mix_devices[0]);
613 devc->supported_devices = MODE3_MIXER_DEVICES;
614 break;
615 case MD_4232:
616 case MD_4235:
617 case MD_4236:
618 devc->supported_devices = MODE3_MIXER_DEVICES;
619 break;
621 case MD_1848:
622 if (soundpro) {
623 devc->supported_devices = SPRO_MIXER_DEVICES;
624 devc->supported_rec_devices = SPRO_REC_DEVICES;
625 devc->mix_devices = &(spro_mix_devices[0]);
626 break;
629 default:
630 devc->supported_devices = MODE1_MIXER_DEVICES;
633 devc->orig_devices = devc->supported_devices;
634 devc->orig_rec_devices = devc->supported_rec_devices;
636 devc->levels = load_mixer_volumes(name, default_mixer_levels, 1);
638 for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
640 if (devc->supported_devices & (1 << i))
641 ad1848_mixer_set(devc, i, devc->levels[i]);
644 ad1848_set_recmask(devc, SOUND_MASK_MIC);
646 devc->mixer_output_port = devc->levels[31] | AUDIO_HEADPHONE | AUDIO_LINE_OUT;
648 spin_lock_irqsave(&devc->lock,flags);
649 if (!soundpro) {
650 if (devc->mixer_output_port & AUDIO_SPEAKER)
651 ad_write(devc, 26, ad_read(devc, 26) & ~0x40); /* Unmute mono out */
652 else
653 ad_write(devc, 26, ad_read(devc, 26) | 0x40); /* Mute mono out */
654 } else {
656 * From the "wouldn't it be nice if the mixer API had (better)
657 * support for custom stuff" category
659 /* Enable surround mode and SB16 mixer */
660 ad_write(devc, 16, 0x60);
662 spin_unlock_irqrestore(&devc->lock,flags);
665 static int ad1848_mixer_ioctl(int dev, unsigned int cmd, void __user *arg)
667 ad1848_info *devc = mixer_devs[dev]->devc;
668 int val;
670 if (cmd == SOUND_MIXER_PRIVATE1)
672 if (get_user(val, (int __user *)arg))
673 return -EFAULT;
675 if (val != 0xffff)
677 unsigned long flags;
678 val &= (AUDIO_SPEAKER | AUDIO_HEADPHONE | AUDIO_LINE_OUT);
679 devc->mixer_output_port = val;
680 val |= AUDIO_HEADPHONE | AUDIO_LINE_OUT; /* Always on */
681 devc->mixer_output_port = val;
682 spin_lock_irqsave(&devc->lock,flags);
683 if (val & AUDIO_SPEAKER)
684 ad_write(devc, 26, ad_read(devc, 26) & ~0x40); /* Unmute mono out */
685 else
686 ad_write(devc, 26, ad_read(devc, 26) | 0x40); /* Mute mono out */
687 spin_unlock_irqrestore(&devc->lock,flags);
689 val = devc->mixer_output_port;
690 return put_user(val, (int __user *)arg);
692 if (cmd == SOUND_MIXER_PRIVATE2)
694 if (get_user(val, (int __user *)arg))
695 return -EFAULT;
696 return(ad1848_control(AD1848_MIXER_REROUTE, val));
698 if (((cmd >> 8) & 0xff) == 'M')
700 if (_SIOC_DIR(cmd) & _SIOC_WRITE)
702 switch (cmd & 0xff)
704 case SOUND_MIXER_RECSRC:
705 if (get_user(val, (int __user *)arg))
706 return -EFAULT;
707 val = ad1848_set_recmask(devc, val);
708 break;
710 default:
711 if (get_user(val, (int __user *)arg))
712 return -EFAULT;
713 val = ad1848_mixer_set(devc, cmd & 0xff, val);
714 break;
716 return put_user(val, (int __user *)arg);
718 else
720 switch (cmd & 0xff)
723 * Return parameters
726 case SOUND_MIXER_RECSRC:
727 val = devc->recmask;
728 break;
730 case SOUND_MIXER_DEVMASK:
731 val = devc->supported_devices;
732 break;
734 case SOUND_MIXER_STEREODEVS:
735 val = devc->supported_devices;
736 if (devc->model != MD_C930)
737 val &= ~(SOUND_MASK_SPEAKER | SOUND_MASK_IMIX);
738 break;
740 case SOUND_MIXER_RECMASK:
741 val = devc->supported_rec_devices;
742 break;
744 case SOUND_MIXER_CAPS:
745 val=SOUND_CAP_EXCL_INPUT;
746 break;
748 default:
749 val = ad1848_mixer_get(devc, cmd & 0xff);
750 break;
752 return put_user(val, (int __user *)arg);
755 else
756 return -EINVAL;
759 static int ad1848_set_speed(int dev, int arg)
761 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
762 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
765 * The sampling speed is encoded in the least significant nibble of I8. The
766 * LSB selects the clock source (0=24.576 MHz, 1=16.9344 MHz) and other
767 * three bits select the divisor (indirectly):
769 * The available speeds are in the following table. Keep the speeds in
770 * the increasing order.
772 typedef struct
774 int speed;
775 unsigned char bits;
777 speed_struct;
779 static speed_struct speed_table[] =
781 {5510, (0 << 1) | 1},
782 {5510, (0 << 1) | 1},
783 {6620, (7 << 1) | 1},
784 {8000, (0 << 1) | 0},
785 {9600, (7 << 1) | 0},
786 {11025, (1 << 1) | 1},
787 {16000, (1 << 1) | 0},
788 {18900, (2 << 1) | 1},
789 {22050, (3 << 1) | 1},
790 {27420, (2 << 1) | 0},
791 {32000, (3 << 1) | 0},
792 {33075, (6 << 1) | 1},
793 {37800, (4 << 1) | 1},
794 {44100, (5 << 1) | 1},
795 {48000, (6 << 1) | 0}
798 int i, n, selected = -1;
800 n = sizeof(speed_table) / sizeof(speed_struct);
802 if (arg <= 0)
803 return portc->speed;
805 if (devc->model == MD_1845 || devc->model == MD_1845_SSCAPE) /* AD1845 has different timer than others */
807 if (arg < 4000)
808 arg = 4000;
809 if (arg > 50000)
810 arg = 50000;
812 portc->speed = arg;
813 portc->speed_bits = speed_table[3].bits;
814 return portc->speed;
816 if (arg < speed_table[0].speed)
817 selected = 0;
818 if (arg > speed_table[n - 1].speed)
819 selected = n - 1;
821 for (i = 1 /*really */ ; selected == -1 && i < n; i++)
823 if (speed_table[i].speed == arg)
824 selected = i;
825 else if (speed_table[i].speed > arg)
827 int diff1, diff2;
829 diff1 = arg - speed_table[i - 1].speed;
830 diff2 = speed_table[i].speed - arg;
832 if (diff1 < diff2)
833 selected = i - 1;
834 else
835 selected = i;
838 if (selected == -1)
840 printk(KERN_WARNING "ad1848: Can't find speed???\n");
841 selected = 3;
843 portc->speed = speed_table[selected].speed;
844 portc->speed_bits = speed_table[selected].bits;
845 return portc->speed;
848 static short ad1848_set_channels(int dev, short arg)
850 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
852 if (arg != 1 && arg != 2)
853 return portc->channels;
855 portc->channels = arg;
856 return arg;
859 static unsigned int ad1848_set_bits(int dev, unsigned int arg)
861 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
862 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
864 static struct format_tbl
866 int format;
867 unsigned char bits;
869 format2bits[] =
872 0, 0
876 AFMT_MU_LAW, 1
880 AFMT_A_LAW, 3
884 AFMT_IMA_ADPCM, 5
888 AFMT_U8, 0
892 AFMT_S16_LE, 2
896 AFMT_S16_BE, 6
900 AFMT_S8, 0
904 AFMT_U16_LE, 0
908 AFMT_U16_BE, 0
911 int i, n = sizeof(format2bits) / sizeof(struct format_tbl);
913 if (arg == 0)
914 return portc->audio_format;
916 if (!(arg & ad_format_mask[devc->model]))
917 arg = AFMT_U8;
919 portc->audio_format = arg;
921 for (i = 0; i < n; i++)
922 if (format2bits[i].format == arg)
924 if ((portc->format_bits = format2bits[i].bits) == 0)
925 return portc->audio_format = AFMT_U8; /* Was not supported */
927 return arg;
929 /* Still hanging here. Something must be terribly wrong */
930 portc->format_bits = 0;
931 return portc->audio_format = AFMT_U8;
934 static struct audio_driver ad1848_audio_driver =
936 .owner = THIS_MODULE,
937 .open = ad1848_open,
938 .close = ad1848_close,
939 .output_block = ad1848_output_block,
940 .start_input = ad1848_start_input,
941 .prepare_for_input = ad1848_prepare_for_input,
942 .prepare_for_output = ad1848_prepare_for_output,
943 .halt_io = ad1848_halt,
944 .halt_input = ad1848_halt_input,
945 .halt_output = ad1848_halt_output,
946 .trigger = ad1848_trigger,
947 .set_speed = ad1848_set_speed,
948 .set_bits = ad1848_set_bits,
949 .set_channels = ad1848_set_channels
952 static struct mixer_operations ad1848_mixer_operations =
954 .owner = THIS_MODULE,
955 .id = "SOUNDPORT",
956 .name = "AD1848/CS4248/CS4231",
957 .ioctl = ad1848_mixer_ioctl
960 static int ad1848_open(int dev, int mode)
962 ad1848_info *devc;
963 ad1848_port_info *portc;
964 unsigned long flags;
966 if (dev < 0 || dev >= num_audiodevs)
967 return -ENXIO;
969 devc = (ad1848_info *) audio_devs[dev]->devc;
970 portc = (ad1848_port_info *) audio_devs[dev]->portc;
972 /* here we don't have to protect against intr */
973 spin_lock(&devc->lock);
974 if (portc->open_mode || (devc->open_mode & mode))
976 spin_unlock(&devc->lock);
977 return -EBUSY;
979 devc->dual_dma = 0;
981 if (audio_devs[dev]->flags & DMA_DUPLEX)
983 devc->dual_dma = 1;
985 devc->intr_active = 0;
986 devc->audio_mode = 0;
987 devc->open_mode |= mode;
988 portc->open_mode = mode;
989 spin_unlock(&devc->lock);
990 ad1848_trigger(dev, 0);
992 if (mode & OPEN_READ)
993 devc->record_dev = dev;
994 if (mode & OPEN_WRITE)
995 devc->playback_dev = dev;
997 * Mute output until the playback really starts. This decreases clicking (hope so).
999 spin_lock_irqsave(&devc->lock,flags);
1000 ad_mute(devc);
1001 spin_unlock_irqrestore(&devc->lock,flags);
1003 return 0;
1006 static void ad1848_close(int dev)
1008 unsigned long flags;
1009 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1010 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1012 devc->intr_active = 0;
1013 ad1848_halt(dev);
1015 spin_lock_irqsave(&devc->lock,flags);
1017 devc->audio_mode = 0;
1018 devc->open_mode &= ~portc->open_mode;
1019 portc->open_mode = 0;
1021 ad_unmute(devc);
1022 spin_unlock_irqrestore(&devc->lock,flags);
1025 static void ad1848_output_block(int dev, unsigned long buf, int count, int intrflag)
1027 unsigned long flags, cnt;
1028 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1029 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1031 cnt = count;
1033 if (portc->audio_format == AFMT_IMA_ADPCM)
1035 cnt /= 4;
1037 else
1039 if (portc->audio_format & (AFMT_S16_LE | AFMT_S16_BE)) /* 16 bit data */
1040 cnt >>= 1;
1042 if (portc->channels > 1)
1043 cnt >>= 1;
1044 cnt--;
1046 if ((devc->audio_mode & PCM_ENABLE_OUTPUT) && (audio_devs[dev]->flags & DMA_AUTOMODE) &&
1047 intrflag &&
1048 cnt == devc->xfer_count)
1050 devc->audio_mode |= PCM_ENABLE_OUTPUT;
1051 devc->intr_active = 1;
1052 return; /*
1053 * Auto DMA mode on. No need to react
1056 spin_lock_irqsave(&devc->lock,flags);
1058 ad_write(devc, 15, (unsigned char) (cnt & 0xff));
1059 ad_write(devc, 14, (unsigned char) ((cnt >> 8) & 0xff));
1061 devc->xfer_count = cnt;
1062 devc->audio_mode |= PCM_ENABLE_OUTPUT;
1063 devc->intr_active = 1;
1064 spin_unlock_irqrestore(&devc->lock,flags);
1067 static void ad1848_start_input(int dev, unsigned long buf, int count, int intrflag)
1069 unsigned long flags, cnt;
1070 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1071 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1073 cnt = count;
1074 if (portc->audio_format == AFMT_IMA_ADPCM)
1076 cnt /= 4;
1078 else
1080 if (portc->audio_format & (AFMT_S16_LE | AFMT_S16_BE)) /* 16 bit data */
1081 cnt >>= 1;
1083 if (portc->channels > 1)
1084 cnt >>= 1;
1085 cnt--;
1087 if ((devc->audio_mode & PCM_ENABLE_INPUT) && (audio_devs[dev]->flags & DMA_AUTOMODE) &&
1088 intrflag &&
1089 cnt == devc->xfer_count)
1091 devc->audio_mode |= PCM_ENABLE_INPUT;
1092 devc->intr_active = 1;
1093 return; /*
1094 * Auto DMA mode on. No need to react
1097 spin_lock_irqsave(&devc->lock,flags);
1099 if (devc->model == MD_1848)
1101 ad_write(devc, 15, (unsigned char) (cnt & 0xff));
1102 ad_write(devc, 14, (unsigned char) ((cnt >> 8) & 0xff));
1104 else
1106 ad_write(devc, 31, (unsigned char) (cnt & 0xff));
1107 ad_write(devc, 30, (unsigned char) ((cnt >> 8) & 0xff));
1110 ad_unmute(devc);
1112 devc->xfer_count = cnt;
1113 devc->audio_mode |= PCM_ENABLE_INPUT;
1114 devc->intr_active = 1;
1115 spin_unlock_irqrestore(&devc->lock,flags);
1118 static int ad1848_prepare_for_output(int dev, int bsize, int bcount)
1120 int timeout;
1121 unsigned char fs, old_fs, tmp = 0;
1122 unsigned long flags;
1123 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1124 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1126 ad_mute(devc);
1128 spin_lock_irqsave(&devc->lock,flags);
1129 fs = portc->speed_bits | (portc->format_bits << 5);
1131 if (portc->channels > 1)
1132 fs |= 0x10;
1134 ad_enter_MCE(devc); /* Enables changes to the format select reg */
1136 if (devc->model == MD_1845 || devc->model == MD_1845_SSCAPE) /* Use alternate speed select registers */
1138 fs &= 0xf0; /* Mask off the rate select bits */
1140 ad_write(devc, 22, (portc->speed >> 8) & 0xff); /* Speed MSB */
1141 ad_write(devc, 23, portc->speed & 0xff); /* Speed LSB */
1143 old_fs = ad_read(devc, 8);
1145 if (devc->model == MD_4232 || devc->model >= MD_4236)
1147 tmp = ad_read(devc, 16);
1148 ad_write(devc, 16, tmp | 0x30);
1150 if (devc->model == MD_IWAVE)
1151 ad_write(devc, 17, 0xc2); /* Disable variable frequency select */
1153 ad_write(devc, 8, fs);
1156 * Write to I8 starts resynchronization. Wait until it completes.
1159 timeout = 0;
1160 while (timeout < 100 && inb(devc->base) != 0x80)
1161 timeout++;
1162 timeout = 0;
1163 while (timeout < 10000 && inb(devc->base) == 0x80)
1164 timeout++;
1166 if (devc->model >= MD_4232)
1167 ad_write(devc, 16, tmp & ~0x30);
1169 ad_leave_MCE(devc); /*
1170 * Starts the calibration process.
1172 spin_unlock_irqrestore(&devc->lock,flags);
1173 devc->xfer_count = 0;
1175 #ifndef EXCLUDE_TIMERS
1176 if (dev == timer_installed && devc->timer_running)
1177 if ((fs & 0x01) != (old_fs & 0x01))
1179 ad1848_tmr_reprogram(dev);
1181 #endif
1182 ad1848_halt_output(dev);
1183 return 0;
1186 static int ad1848_prepare_for_input(int dev, int bsize, int bcount)
1188 int timeout;
1189 unsigned char fs, old_fs, tmp = 0;
1190 unsigned long flags;
1191 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1192 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1194 if (devc->audio_mode)
1195 return 0;
1197 spin_lock_irqsave(&devc->lock,flags);
1198 fs = portc->speed_bits | (portc->format_bits << 5);
1200 if (portc->channels > 1)
1201 fs |= 0x10;
1203 ad_enter_MCE(devc); /* Enables changes to the format select reg */
1205 if ((devc->model == MD_1845) || (devc->model == MD_1845_SSCAPE)) /* Use alternate speed select registers */
1207 fs &= 0xf0; /* Mask off the rate select bits */
1209 ad_write(devc, 22, (portc->speed >> 8) & 0xff); /* Speed MSB */
1210 ad_write(devc, 23, portc->speed & 0xff); /* Speed LSB */
1212 if (devc->model == MD_4232)
1214 tmp = ad_read(devc, 16);
1215 ad_write(devc, 16, tmp | 0x30);
1217 if (devc->model == MD_IWAVE)
1218 ad_write(devc, 17, 0xc2); /* Disable variable frequency select */
1221 * If mode >= 2 (CS4231), set I28. It's the capture format register.
1224 if (devc->model != MD_1848)
1226 old_fs = ad_read(devc, 28);
1227 ad_write(devc, 28, fs);
1230 * Write to I28 starts resynchronization. Wait until it completes.
1233 timeout = 0;
1234 while (timeout < 100 && inb(devc->base) != 0x80)
1235 timeout++;
1237 timeout = 0;
1238 while (timeout < 10000 && inb(devc->base) == 0x80)
1239 timeout++;
1241 if (devc->model != MD_1848 && devc->model != MD_1845 && devc->model != MD_1845_SSCAPE)
1244 * CS4231 compatible devices don't have separate sampling rate selection
1245 * register for recording an playback. The I8 register is shared so we have to
1246 * set the speed encoding bits of it too.
1248 unsigned char tmp = portc->speed_bits | (ad_read(devc, 8) & 0xf0);
1250 ad_write(devc, 8, tmp);
1252 * Write to I8 starts resynchronization. Wait until it completes.
1254 timeout = 0;
1255 while (timeout < 100 && inb(devc->base) != 0x80)
1256 timeout++;
1258 timeout = 0;
1259 while (timeout < 10000 && inb(devc->base) == 0x80)
1260 timeout++;
1263 else
1264 { /* For AD1848 set I8. */
1266 old_fs = ad_read(devc, 8);
1267 ad_write(devc, 8, fs);
1269 * Write to I8 starts resynchronization. Wait until it completes.
1271 timeout = 0;
1272 while (timeout < 100 && inb(devc->base) != 0x80)
1273 timeout++;
1274 timeout = 0;
1275 while (timeout < 10000 && inb(devc->base) == 0x80)
1276 timeout++;
1279 if (devc->model == MD_4232)
1280 ad_write(devc, 16, tmp & ~0x30);
1282 ad_leave_MCE(devc); /*
1283 * Starts the calibration process.
1285 spin_unlock_irqrestore(&devc->lock,flags);
1286 devc->xfer_count = 0;
1288 #ifndef EXCLUDE_TIMERS
1289 if (dev == timer_installed && devc->timer_running)
1291 if ((fs & 0x01) != (old_fs & 0x01))
1293 ad1848_tmr_reprogram(dev);
1296 #endif
1297 ad1848_halt_input(dev);
1298 return 0;
1301 static void ad1848_halt(int dev)
1303 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1304 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1306 unsigned char bits = ad_read(devc, 9);
1308 if (bits & 0x01 && (portc->open_mode & OPEN_WRITE))
1309 ad1848_halt_output(dev);
1311 if (bits & 0x02 && (portc->open_mode & OPEN_READ))
1312 ad1848_halt_input(dev);
1313 devc->audio_mode = 0;
1316 static void ad1848_halt_input(int dev)
1318 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1319 unsigned long flags;
1321 if (!(ad_read(devc, 9) & 0x02))
1322 return; /* Capture not enabled */
1324 spin_lock_irqsave(&devc->lock,flags);
1326 ad_mute(devc);
1329 int tmout;
1331 if(!isa_dma_bridge_buggy)
1332 disable_dma(audio_devs[dev]->dmap_in->dma);
1334 for (tmout = 0; tmout < 100000; tmout++)
1335 if (ad_read(devc, 11) & 0x10)
1336 break;
1337 ad_write(devc, 9, ad_read(devc, 9) & ~0x02); /* Stop capture */
1339 if(!isa_dma_bridge_buggy)
1340 enable_dma(audio_devs[dev]->dmap_in->dma);
1341 devc->audio_mode &= ~PCM_ENABLE_INPUT;
1344 outb(0, io_Status(devc)); /* Clear interrupt status */
1345 outb(0, io_Status(devc)); /* Clear interrupt status */
1347 devc->audio_mode &= ~PCM_ENABLE_INPUT;
1349 spin_unlock_irqrestore(&devc->lock,flags);
1352 static void ad1848_halt_output(int dev)
1354 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1355 unsigned long flags;
1357 if (!(ad_read(devc, 9) & 0x01))
1358 return; /* Playback not enabled */
1360 spin_lock_irqsave(&devc->lock,flags);
1362 ad_mute(devc);
1364 int tmout;
1366 if(!isa_dma_bridge_buggy)
1367 disable_dma(audio_devs[dev]->dmap_out->dma);
1369 for (tmout = 0; tmout < 100000; tmout++)
1370 if (ad_read(devc, 11) & 0x10)
1371 break;
1372 ad_write(devc, 9, ad_read(devc, 9) & ~0x01); /* Stop playback */
1374 if(!isa_dma_bridge_buggy)
1375 enable_dma(audio_devs[dev]->dmap_out->dma);
1377 devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
1380 outb((0), io_Status(devc)); /* Clear interrupt status */
1381 outb((0), io_Status(devc)); /* Clear interrupt status */
1383 devc->audio_mode &= ~PCM_ENABLE_OUTPUT;
1385 spin_unlock_irqrestore(&devc->lock,flags);
1388 static void ad1848_trigger(int dev, int state)
1390 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
1391 ad1848_port_info *portc = (ad1848_port_info *) audio_devs[dev]->portc;
1392 unsigned long flags;
1393 unsigned char tmp, old;
1395 spin_lock_irqsave(&devc->lock,flags);
1396 state &= devc->audio_mode;
1398 tmp = old = ad_read(devc, 9);
1400 if (portc->open_mode & OPEN_READ)
1402 if (state & PCM_ENABLE_INPUT)
1403 tmp |= 0x02;
1404 else
1405 tmp &= ~0x02;
1407 if (portc->open_mode & OPEN_WRITE)
1409 if (state & PCM_ENABLE_OUTPUT)
1410 tmp |= 0x01;
1411 else
1412 tmp &= ~0x01;
1414 /* ad_mute(devc); */
1415 if (tmp != old)
1417 ad_write(devc, 9, tmp);
1418 ad_unmute(devc);
1420 spin_unlock_irqrestore(&devc->lock,flags);
1423 static void ad1848_init_hw(ad1848_info * devc)
1425 int i;
1426 int *init_values;
1429 * Initial values for the indirect registers of CS4248/AD1848.
1431 static int init_values_a[] =
1433 0xa8, 0xa8, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
1434 0x00, 0x0c, 0x02, 0x00, 0x8a, 0x01, 0x00, 0x00,
1436 /* Positions 16 to 31 just for CS4231/2 and ad1845 */
1437 0x80, 0x00, 0x10, 0x10, 0x00, 0x00, 0x1f, 0x40,
1438 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1441 static int init_values_b[] =
1444 Values for the newer chips
1445 Some of the register initialization values were changed. In
1446 order to get rid of the click that preceded PCM playback,
1447 calibration was disabled on the 10th byte. On that same byte,
1448 dual DMA was enabled; on the 11th byte, ADC dithering was
1449 enabled, since that is theoretically desirable; on the 13th
1450 byte, Mode 3 was selected, to enable access to extended
1451 registers.
1453 0xa8, 0xa8, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
1454 0x00, 0x00, 0x06, 0x00, 0xe0, 0x01, 0x00, 0x00,
1455 0x80, 0x00, 0x10, 0x10, 0x00, 0x00, 0x1f, 0x40,
1456 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1460 * Select initialisation data
1463 init_values = init_values_a;
1464 if(devc->model >= MD_4236)
1465 init_values = init_values_b;
1467 for (i = 0; i < 16; i++)
1468 ad_write(devc, i, init_values[i]);
1471 ad_mute(devc); /* Initialize some variables */
1472 ad_unmute(devc); /* Leave it unmuted now */
1474 if (devc->model > MD_1848)
1476 if (devc->model == MD_1845_SSCAPE)
1477 ad_write(devc, 12, ad_read(devc, 12) | 0x50);
1478 else
1479 ad_write(devc, 12, ad_read(devc, 12) | 0x40); /* Mode2 = enabled */
1481 if (devc->model == MD_IWAVE)
1482 ad_write(devc, 12, 0x6c); /* Select codec mode 3 */
1484 if (devc->model != MD_1845_SSCAPE)
1485 for (i = 16; i < 32; i++)
1486 ad_write(devc, i, init_values[i]);
1488 if (devc->model == MD_IWAVE)
1489 ad_write(devc, 16, 0x30); /* Playback and capture counters enabled */
1491 if (devc->model > MD_1848)
1493 if (devc->audio_flags & DMA_DUPLEX)
1494 ad_write(devc, 9, ad_read(devc, 9) & ~0x04); /* Dual DMA mode */
1495 else
1496 ad_write(devc, 9, ad_read(devc, 9) | 0x04); /* Single DMA mode */
1498 if (devc->model == MD_1845 || devc->model == MD_1845_SSCAPE)
1499 ad_write(devc, 27, ad_read(devc, 27) | 0x08); /* Alternate freq select enabled */
1501 if (devc->model == MD_IWAVE)
1502 { /* Some magic Interwave specific initialization */
1503 ad_write(devc, 12, 0x6c); /* Select codec mode 3 */
1504 ad_write(devc, 16, 0x30); /* Playback and capture counters enabled */
1505 ad_write(devc, 17, 0xc2); /* Alternate feature enable */
1508 else
1510 devc->audio_flags &= ~DMA_DUPLEX;
1511 ad_write(devc, 9, ad_read(devc, 9) | 0x04); /* Single DMA mode */
1512 if (soundpro)
1513 ad_write(devc, 12, ad_read(devc, 12) | 0x40); /* Mode2 = enabled */
1516 outb((0), io_Status(devc)); /* Clear pending interrupts */
1519 * Toggle the MCE bit. It completes the initialization phase.
1522 ad_enter_MCE(devc); /* In case the bit was off */
1523 ad_leave_MCE(devc);
1525 ad1848_mixer_reset(devc);
1528 int ad1848_detect(struct resource *ports, int *ad_flags, int *osp)
1530 unsigned char tmp;
1531 ad1848_info *devc = &adev_info[nr_ad1848_devs];
1532 unsigned char tmp1 = 0xff, tmp2 = 0xff;
1533 int optiC930 = 0; /* OPTi 82C930 flag */
1534 int interwave = 0;
1535 int ad1847_flag = 0;
1536 int cs4248_flag = 0;
1537 int sscape_flag = 0;
1538 int io_base = ports->start;
1540 int i;
1542 DDB(printk("ad1848_detect(%x)\n", io_base));
1544 if (ad_flags)
1546 if (*ad_flags == 0x12345678)
1548 interwave = 1;
1549 *ad_flags = 0;
1552 if (*ad_flags == 0x87654321)
1554 sscape_flag = 1;
1555 *ad_flags = 0;
1558 if (*ad_flags == 0x12345677)
1560 cs4248_flag = 1;
1561 *ad_flags = 0;
1564 if (nr_ad1848_devs >= MAX_AUDIO_DEV)
1566 printk(KERN_ERR "ad1848 - Too many audio devices\n");
1567 return 0;
1569 spin_lock_init(&devc->lock);
1570 devc->base = io_base;
1571 devc->irq_ok = 0;
1572 devc->timer_running = 0;
1573 devc->MCE_bit = 0x40;
1574 devc->irq = 0;
1575 devc->open_mode = 0;
1576 devc->chip_name = devc->name = "AD1848";
1577 devc->model = MD_1848; /* AD1848 or CS4248 */
1578 devc->levels = NULL;
1579 devc->debug_flag = 0;
1582 * Check that the I/O address is in use.
1584 * The bit 0x80 of the base I/O port is known to be 0 after the
1585 * chip has performed its power on initialization. Just assume
1586 * this has happened before the OS is starting.
1588 * If the I/O address is unused, it typically returns 0xff.
1591 if (inb(devc->base) == 0xff)
1593 DDB(printk("ad1848_detect: The base I/O address appears to be dead\n"));
1597 * Wait for the device to stop initialization
1600 DDB(printk("ad1848_detect() - step 0\n"));
1602 for (i = 0; i < 10000000; i++)
1604 unsigned char x = inb(devc->base);
1606 if (x == 0xff || !(x & 0x80))
1607 break;
1610 DDB(printk("ad1848_detect() - step A\n"));
1612 if (inb(devc->base) == 0x80) /* Not ready. Let's wait */
1613 ad_leave_MCE(devc);
1615 if ((inb(devc->base) & 0x80) != 0x00) /* Not a AD1848 */
1617 DDB(printk("ad1848 detect error - step A (%02x)\n", (int) inb(devc->base)));
1618 return 0;
1622 * Test if it's possible to change contents of the indirect registers.
1623 * Registers 0 and 1 are ADC volume registers. The bit 0x10 is read only
1624 * so try to avoid using it.
1627 DDB(printk("ad1848_detect() - step B\n"));
1628 ad_write(devc, 0, 0xaa);
1629 ad_write(devc, 1, 0x45); /* 0x55 with bit 0x10 clear */
1631 if ((tmp1 = ad_read(devc, 0)) != 0xaa || (tmp2 = ad_read(devc, 1)) != 0x45)
1633 if (tmp2 == 0x65) /* AD1847 has couple of bits hardcoded to 1 */
1634 ad1847_flag = 1;
1635 else
1637 DDB(printk("ad1848 detect error - step B (%x/%x)\n", tmp1, tmp2));
1638 return 0;
1641 DDB(printk("ad1848_detect() - step C\n"));
1642 ad_write(devc, 0, 0x45);
1643 ad_write(devc, 1, 0xaa);
1645 if ((tmp1 = ad_read(devc, 0)) != 0x45 || (tmp2 = ad_read(devc, 1)) != 0xaa)
1647 if (tmp2 == 0x8a) /* AD1847 has few bits hardcoded to 1 */
1648 ad1847_flag = 1;
1649 else
1651 DDB(printk("ad1848 detect error - step C (%x/%x)\n", tmp1, tmp2));
1652 return 0;
1657 * The indirect register I12 has some read only bits. Let's
1658 * try to change them.
1661 DDB(printk("ad1848_detect() - step D\n"));
1662 tmp = ad_read(devc, 12);
1663 ad_write(devc, 12, (~tmp) & 0x0f);
1665 if ((tmp & 0x0f) != ((tmp1 = ad_read(devc, 12)) & 0x0f))
1667 DDB(printk("ad1848 detect error - step D (%x)\n", tmp1));
1668 return 0;
1672 * NOTE! Last 4 bits of the reg I12 tell the chip revision.
1673 * 0x01=RevB and 0x0A=RevC.
1677 * The original AD1848/CS4248 has just 15 indirect registers. This means
1678 * that I0 and I16 should return the same value (etc.).
1679 * However this doesn't work with CS4248. Actually it seems to be impossible
1680 * to detect if the chip is a CS4231 or CS4248.
1681 * Ensure that the Mode2 enable bit of I12 is 0. Otherwise this test fails
1682 * with CS4231.
1686 * OPTi 82C930 has mode2 control bit in another place. This test will fail
1687 * with it. Accept this situation as a possible indication of this chip.
1690 DDB(printk("ad1848_detect() - step F\n"));
1691 ad_write(devc, 12, 0); /* Mode2=disabled */
1693 for (i = 0; i < 16; i++)
1695 if ((tmp1 = ad_read(devc, i)) != (tmp2 = ad_read(devc, i + 16)))
1697 DDB(printk("ad1848 detect step F(%d/%x/%x) - OPTi chip???\n", i, tmp1, tmp2));
1698 if (!ad1847_flag)
1699 optiC930 = 1;
1700 break;
1705 * Try to switch the chip to mode2 (CS4231) by setting the MODE2 bit (0x40).
1706 * The bit 0x80 is always 1 in CS4248 and CS4231.
1709 DDB(printk("ad1848_detect() - step G\n"));
1711 if (ad_flags && *ad_flags == 400)
1712 *ad_flags = 0;
1713 else
1714 ad_write(devc, 12, 0x40); /* Set mode2, clear 0x80 */
1717 if (ad_flags)
1718 *ad_flags = 0;
1720 tmp1 = ad_read(devc, 12);
1721 if (tmp1 & 0x80)
1723 if (ad_flags)
1724 *ad_flags |= AD_F_CS4248;
1726 devc->chip_name = "CS4248"; /* Our best knowledge just now */
1728 if (optiC930 || (tmp1 & 0xc0) == (0x80 | 0x40))
1731 * CS4231 detected - is it?
1733 * Verify that setting I0 doesn't change I16.
1736 DDB(printk("ad1848_detect() - step H\n"));
1737 ad_write(devc, 16, 0); /* Set I16 to known value */
1739 ad_write(devc, 0, 0x45);
1740 if ((tmp1 = ad_read(devc, 16)) != 0x45) /* No change -> CS4231? */
1742 ad_write(devc, 0, 0xaa);
1743 if ((tmp1 = ad_read(devc, 16)) == 0xaa) /* Rotten bits? */
1745 DDB(printk("ad1848 detect error - step H(%x)\n", tmp1));
1746 return 0;
1750 * Verify that some bits of I25 are read only.
1753 DDB(printk("ad1848_detect() - step I\n"));
1754 tmp1 = ad_read(devc, 25); /* Original bits */
1755 ad_write(devc, 25, ~tmp1); /* Invert all bits */
1756 if ((ad_read(devc, 25) & 0xe7) == (tmp1 & 0xe7))
1758 int id;
1761 * It's at least CS4231
1764 devc->chip_name = "CS4231";
1765 devc->model = MD_4231;
1768 * It could be an AD1845 or CS4231A as well.
1769 * CS4231 and AD1845 report the same revision info in I25
1770 * while the CS4231A reports different.
1773 id = ad_read(devc, 25);
1774 if ((id & 0xe7) == 0x80) /* Device busy??? */
1775 id = ad_read(devc, 25);
1776 if ((id & 0xe7) == 0x80) /* Device still busy??? */
1777 id = ad_read(devc, 25);
1778 DDB(printk("ad1848_detect() - step J (%02x/%02x)\n", id, ad_read(devc, 25)));
1780 if ((id & 0xe7) == 0x80) {
1782 * It must be a CS4231 or AD1845. The register I23 of
1783 * CS4231 is undefined and it appears to be read only.
1784 * AD1845 uses I23 for setting sample rate. Assume
1785 * the chip is AD1845 if I23 is changeable.
1788 unsigned char tmp = ad_read(devc, 23);
1789 ad_write(devc, 23, ~tmp);
1791 if (interwave)
1793 devc->model = MD_IWAVE;
1794 devc->chip_name = "IWave";
1796 else if (ad_read(devc, 23) != tmp) /* AD1845 ? */
1798 devc->chip_name = "AD1845";
1799 devc->model = MD_1845;
1801 else if (cs4248_flag)
1803 if (ad_flags)
1804 *ad_flags |= AD_F_CS4248;
1805 devc->chip_name = "CS4248";
1806 devc->model = MD_1848;
1807 ad_write(devc, 12, ad_read(devc, 12) & ~0x40); /* Mode2 off */
1809 ad_write(devc, 23, tmp); /* Restore */
1811 else
1813 switch (id & 0x1f) {
1814 case 3: /* CS4236/CS4235/CS42xB/CS4239 */
1816 int xid;
1817 ad_write(devc, 12, ad_read(devc, 12) | 0x60); /* switch to mode 3 */
1818 ad_write(devc, 23, 0x9c); /* select extended register 25 */
1819 xid = inb(io_Indexed_Data(devc));
1820 ad_write(devc, 12, ad_read(devc, 12) & ~0x60); /* back to mode 0 */
1821 switch (xid & 0x1f)
1823 case 0x00:
1824 devc->chip_name = "CS4237B(B)";
1825 devc->model = MD_42xB;
1826 break;
1827 case 0x08:
1828 /* Seems to be a 4238 ?? */
1829 devc->chip_name = "CS4238";
1830 devc->model = MD_42xB;
1831 break;
1832 case 0x09:
1833 devc->chip_name = "CS4238B";
1834 devc->model = MD_42xB;
1835 break;
1836 case 0x0b:
1837 devc->chip_name = "CS4236B";
1838 devc->model = MD_4236;
1839 break;
1840 case 0x10:
1841 devc->chip_name = "CS4237B";
1842 devc->model = MD_42xB;
1843 break;
1844 case 0x1d:
1845 devc->chip_name = "CS4235";
1846 devc->model = MD_4235;
1847 break;
1848 case 0x1e:
1849 devc->chip_name = "CS4239";
1850 devc->model = MD_4239;
1851 break;
1852 default:
1853 printk("Chip ident is %X.\n", xid&0x1F);
1854 devc->chip_name = "CS42xx";
1855 devc->model = MD_4232;
1856 break;
1859 break;
1861 case 2: /* CS4232/CS4232A */
1862 devc->chip_name = "CS4232";
1863 devc->model = MD_4232;
1864 break;
1866 case 0:
1867 if ((id & 0xe0) == 0xa0)
1869 devc->chip_name = "CS4231A";
1870 devc->model = MD_4231A;
1872 else
1874 devc->chip_name = "CS4321";
1875 devc->model = MD_4231;
1877 break;
1879 default: /* maybe */
1880 DDB(printk("ad1848: I25 = %02x/%02x\n", ad_read(devc, 25), ad_read(devc, 25) & 0xe7));
1881 if (optiC930)
1883 devc->chip_name = "82C930";
1884 devc->model = MD_C930;
1886 else
1888 devc->chip_name = "CS4231";
1889 devc->model = MD_4231;
1894 ad_write(devc, 25, tmp1); /* Restore bits */
1896 DDB(printk("ad1848_detect() - step K\n"));
1898 } else if (tmp1 == 0x0a) {
1900 * Is it perhaps a SoundPro CMI8330?
1901 * If so, then we should be able to change indirect registers
1902 * greater than I15 after activating MODE2, even though reading
1903 * back I12 does not show it.
1907 * Let's try comparing register values
1909 for (i = 0; i < 16; i++) {
1910 if ((tmp1 = ad_read(devc, i)) != (tmp2 = ad_read(devc, i + 16))) {
1911 DDB(printk("ad1848 detect step H(%d/%x/%x) - SoundPro chip?\n", i, tmp1, tmp2));
1912 soundpro = 1;
1913 devc->chip_name = "SoundPro CMI 8330";
1914 break;
1919 DDB(printk("ad1848_detect() - step L\n"));
1920 if (ad_flags)
1922 if (devc->model != MD_1848)
1923 *ad_flags |= AD_F_CS4231;
1925 DDB(printk("ad1848_detect() - Detected OK\n"));
1927 if (devc->model == MD_1848 && ad1847_flag)
1928 devc->chip_name = "AD1847";
1931 if (sscape_flag == 1)
1932 devc->model = MD_1845_SSCAPE;
1934 return 1;
1937 int ad1848_init (char *name, struct resource *ports, int irq, int dma_playback,
1938 int dma_capture, int share_dma, int *osp, struct module *owner)
1941 * NOTE! If irq < 0, there is another driver which has allocated the IRQ
1942 * so that this driver doesn't need to allocate/deallocate it.
1943 * The actually used IRQ is ABS(irq).
1946 int my_dev;
1947 char dev_name[100];
1948 int e;
1950 ad1848_info *devc = &adev_info[nr_ad1848_devs];
1952 ad1848_port_info *portc = NULL;
1954 devc->irq = (irq > 0) ? irq : 0;
1955 devc->open_mode = 0;
1956 devc->timer_ticks = 0;
1957 devc->dma1 = dma_playback;
1958 devc->dma2 = dma_capture;
1959 devc->subtype = cfg.card_subtype;
1960 devc->audio_flags = DMA_AUTOMODE;
1961 devc->playback_dev = devc->record_dev = 0;
1962 if (name != NULL)
1963 devc->name = name;
1965 if (name != NULL && name[0] != 0)
1966 sprintf(dev_name,
1967 "%s (%s)", name, devc->chip_name);
1968 else
1969 sprintf(dev_name,
1970 "Generic audio codec (%s)", devc->chip_name);
1972 rename_region(ports, devc->name);
1974 conf_printf2(dev_name, devc->base, devc->irq, dma_playback, dma_capture);
1976 if (devc->model == MD_1848 || devc->model == MD_C930)
1977 devc->audio_flags |= DMA_HARDSTOP;
1979 if (devc->model > MD_1848)
1981 if (devc->dma1 == devc->dma2 || devc->dma2 == -1 || devc->dma1 == -1)
1982 devc->audio_flags &= ~DMA_DUPLEX;
1983 else
1984 devc->audio_flags |= DMA_DUPLEX;
1987 portc = kmalloc(sizeof(ad1848_port_info), GFP_KERNEL);
1988 if(portc==NULL) {
1989 release_region(devc->base, 4);
1990 return -1;
1993 if ((my_dev = sound_install_audiodrv(AUDIO_DRIVER_VERSION,
1994 dev_name,
1995 &ad1848_audio_driver,
1996 sizeof(struct audio_driver),
1997 devc->audio_flags,
1998 ad_format_mask[devc->model],
1999 devc,
2000 dma_playback,
2001 dma_capture)) < 0)
2003 release_region(devc->base, 4);
2004 kfree(portc);
2005 return -1;
2008 audio_devs[my_dev]->portc = portc;
2009 audio_devs[my_dev]->mixer_dev = -1;
2010 if (owner)
2011 audio_devs[my_dev]->d->owner = owner;
2012 memset((char *) portc, 0, sizeof(*portc));
2014 nr_ad1848_devs++;
2016 ad1848_init_hw(devc);
2018 if (irq > 0)
2020 devc->dev_no = my_dev;
2021 if (request_irq(devc->irq, adintr, 0, devc->name,
2022 (void *)(long)my_dev) < 0)
2024 printk(KERN_WARNING "ad1848: Unable to allocate IRQ\n");
2025 /* Don't free it either then.. */
2026 devc->irq = 0;
2028 if (capabilities[devc->model].flags & CAP_F_TIMER)
2030 #ifndef CONFIG_SMP
2031 int x;
2032 unsigned char tmp = ad_read(devc, 16);
2033 #endif
2035 devc->timer_ticks = 0;
2037 ad_write(devc, 21, 0x00); /* Timer MSB */
2038 ad_write(devc, 20, 0x10); /* Timer LSB */
2039 #ifndef CONFIG_SMP
2040 ad_write(devc, 16, tmp | 0x40); /* Enable timer */
2041 for (x = 0; x < 100000 && devc->timer_ticks == 0; x++);
2042 ad_write(devc, 16, tmp & ~0x40); /* Disable timer */
2044 if (devc->timer_ticks == 0)
2045 printk(KERN_WARNING "ad1848: Interrupt test failed (IRQ%d)\n", irq);
2046 else
2048 DDB(printk("Interrupt test OK\n"));
2049 devc->irq_ok = 1;
2051 #else
2052 devc->irq_ok = 1;
2053 #endif
2055 else
2056 devc->irq_ok = 1; /* Couldn't test. assume it's OK */
2057 } else if (irq < 0)
2058 devc->dev_no = my_dev;
2060 #ifndef EXCLUDE_TIMERS
2061 if ((capabilities[devc->model].flags & CAP_F_TIMER) &&
2062 devc->irq_ok)
2063 ad1848_tmr_install(my_dev);
2064 #endif
2066 if (!share_dma)
2068 if (sound_alloc_dma(dma_playback, devc->name))
2069 printk(KERN_WARNING "ad1848.c: Can't allocate DMA%d\n", dma_playback);
2071 if (dma_capture != dma_playback)
2072 if (sound_alloc_dma(dma_capture, devc->name))
2073 printk(KERN_WARNING "ad1848.c: Can't allocate DMA%d\n", dma_capture);
2076 if ((e = sound_install_mixer(MIXER_DRIVER_VERSION,
2077 dev_name,
2078 &ad1848_mixer_operations,
2079 sizeof(struct mixer_operations),
2080 devc)) >= 0)
2082 audio_devs[my_dev]->mixer_dev = e;
2083 if (owner)
2084 mixer_devs[e]->owner = owner;
2086 return my_dev;
2089 int ad1848_control(int cmd, int arg)
2091 ad1848_info *devc;
2092 unsigned long flags;
2094 if (nr_ad1848_devs < 1)
2095 return -ENODEV;
2097 devc = &adev_info[nr_ad1848_devs - 1];
2099 switch (cmd)
2101 case AD1848_SET_XTAL: /* Change clock frequency of AD1845 (only ) */
2102 if (devc->model != MD_1845 && devc->model != MD_1845_SSCAPE)
2103 return -EINVAL;
2104 spin_lock_irqsave(&devc->lock,flags);
2105 ad_enter_MCE(devc);
2106 ad_write(devc, 29, (ad_read(devc, 29) & 0x1f) | (arg << 5));
2107 ad_leave_MCE(devc);
2108 spin_unlock_irqrestore(&devc->lock,flags);
2109 break;
2111 case AD1848_MIXER_REROUTE:
2113 int o = (arg >> 8) & 0xff;
2114 int n = arg & 0xff;
2116 if (o < 0 || o >= SOUND_MIXER_NRDEVICES)
2117 return -EINVAL;
2119 if (!(devc->supported_devices & (1 << o)) &&
2120 !(devc->supported_rec_devices & (1 << o)))
2121 return -EINVAL;
2123 if (n == SOUND_MIXER_NONE)
2124 { /* Just hide this control */
2125 ad1848_mixer_set(devc, o, 0); /* Shut up it */
2126 devc->supported_devices &= ~(1 << o);
2127 devc->supported_rec_devices &= ~(1 << o);
2128 break;
2131 /* Make the mixer control identified by o to appear as n */
2132 if (n < 0 || n >= SOUND_MIXER_NRDEVICES)
2133 return -EINVAL;
2135 devc->mixer_reroute[n] = o; /* Rename the control */
2136 if (devc->supported_devices & (1 << o))
2137 devc->supported_devices |= (1 << n);
2138 if (devc->supported_rec_devices & (1 << o))
2139 devc->supported_rec_devices |= (1 << n);
2141 devc->supported_devices &= ~(1 << o);
2142 devc->supported_rec_devices &= ~(1 << o);
2144 break;
2146 return 0;
2149 void ad1848_unload(int io_base, int irq, int dma_playback, int dma_capture, int share_dma)
2151 int i, mixer, dev = 0;
2152 ad1848_info *devc = NULL;
2154 for (i = 0; devc == NULL && i < nr_ad1848_devs; i++)
2156 if (adev_info[i].base == io_base)
2158 devc = &adev_info[i];
2159 dev = devc->dev_no;
2163 if (devc != NULL)
2165 kfree(audio_devs[dev]->portc);
2166 release_region(devc->base, 4);
2168 if (!share_dma)
2170 if (devc->irq > 0) /* There is no point in freeing irq, if it wasn't allocated */
2171 free_irq(devc->irq, (void *)(long)devc->dev_no);
2173 sound_free_dma(dma_playback);
2175 if (dma_playback != dma_capture)
2176 sound_free_dma(dma_capture);
2179 mixer = audio_devs[devc->dev_no]->mixer_dev;
2180 if(mixer>=0)
2181 sound_unload_mixerdev(mixer);
2183 nr_ad1848_devs--;
2184 for ( ; i < nr_ad1848_devs ; i++)
2185 adev_info[i] = adev_info[i+1];
2187 else
2188 printk(KERN_ERR "ad1848: Can't find device to be unloaded. Base=%x\n", io_base);
2191 static irqreturn_t adintr(int irq, void *dev_id)
2193 unsigned char status;
2194 ad1848_info *devc;
2195 int dev;
2196 int alt_stat = 0xff;
2197 unsigned char c930_stat = 0;
2198 int cnt = 0;
2200 dev = (long)dev_id;
2201 devc = (ad1848_info *) audio_devs[dev]->devc;
2203 interrupt_again: /* Jump back here if int status doesn't reset */
2205 status = inb(io_Status(devc));
2207 if (status == 0x80)
2208 printk(KERN_DEBUG "adintr: Why?\n");
2209 if (devc->model == MD_1848)
2210 outb((0), io_Status(devc)); /* Clear interrupt status */
2212 if (status & 0x01)
2214 if (devc->model == MD_C930)
2215 { /* 82C930 has interrupt status register in MAD16 register MC11 */
2217 spin_lock(&devc->lock);
2219 /* 0xe0e is C930 address port
2220 * 0xe0f is C930 data port
2222 outb(11, 0xe0e);
2223 c930_stat = inb(0xe0f);
2224 outb((~c930_stat), 0xe0f);
2226 spin_unlock(&devc->lock);
2228 alt_stat = (c930_stat << 2) & 0x30;
2230 else if (devc->model != MD_1848)
2232 spin_lock(&devc->lock);
2233 alt_stat = ad_read(devc, 24);
2234 ad_write(devc, 24, ad_read(devc, 24) & ~alt_stat); /* Selective ack */
2235 spin_unlock(&devc->lock);
2238 if ((devc->open_mode & OPEN_READ) && (devc->audio_mode & PCM_ENABLE_INPUT) && (alt_stat & 0x20))
2240 DMAbuf_inputintr(devc->record_dev);
2242 if ((devc->open_mode & OPEN_WRITE) && (devc->audio_mode & PCM_ENABLE_OUTPUT) &&
2243 (alt_stat & 0x10))
2245 DMAbuf_outputintr(devc->playback_dev, 1);
2247 if (devc->model != MD_1848 && (alt_stat & 0x40)) /* Timer interrupt */
2249 devc->timer_ticks++;
2250 #ifndef EXCLUDE_TIMERS
2251 if (timer_installed == dev && devc->timer_running)
2252 sound_timer_interrupt();
2253 #endif
2257 * Sometimes playback or capture interrupts occur while a timer interrupt
2258 * is being handled. The interrupt will not be retriggered if we don't
2259 * handle it now. Check if an interrupt is still pending and restart
2260 * the handler in this case.
2262 if (inb(io_Status(devc)) & 0x01 && cnt++ < 4)
2264 goto interrupt_again;
2266 return IRQ_HANDLED;
2270 * Experimental initialization sequence for the integrated sound system
2271 * of the Compaq Deskpro M.
2274 static int init_deskpro_m(struct address_info *hw_config)
2276 unsigned char tmp;
2278 if ((tmp = inb(0xc44)) == 0xff)
2280 DDB(printk("init_deskpro_m: Dead port 0xc44\n"));
2281 return 0;
2284 outb(0x10, 0xc44);
2285 outb(0x40, 0xc45);
2286 outb(0x00, 0xc46);
2287 outb(0xe8, 0xc47);
2288 outb(0x14, 0xc44);
2289 outb(0x40, 0xc45);
2290 outb(0x00, 0xc46);
2291 outb(0xe8, 0xc47);
2292 outb(0x10, 0xc44);
2294 return 1;
2298 * Experimental initialization sequence for the integrated sound system
2299 * of Compaq Deskpro XL.
2302 static int init_deskpro(struct address_info *hw_config)
2304 unsigned char tmp;
2306 if ((tmp = inb(0xc44)) == 0xff)
2308 DDB(printk("init_deskpro: Dead port 0xc44\n"));
2309 return 0;
2311 outb((tmp | 0x04), 0xc44); /* Select bank 1 */
2312 if (inb(0xc44) != 0x04)
2314 DDB(printk("init_deskpro: Invalid bank1 signature in port 0xc44\n"));
2315 return 0;
2318 * OK. It looks like a Deskpro so let's proceed.
2322 * I/O port 0xc44 Audio configuration register.
2324 * bits 0xc0: Audio revision bits
2325 * 0x00 = Compaq Business Audio
2326 * 0x40 = MS Sound System Compatible (reset default)
2327 * 0x80 = Reserved
2328 * 0xc0 = Reserved
2329 * bit 0x20: No Wait State Enable
2330 * 0x00 = Disabled (reset default, DMA mode)
2331 * 0x20 = Enabled (programmed I/O mode)
2332 * bit 0x10: MS Sound System Decode Enable
2333 * 0x00 = Decoding disabled (reset default)
2334 * 0x10 = Decoding enabled
2335 * bit 0x08: FM Synthesis Decode Enable
2336 * 0x00 = Decoding Disabled (reset default)
2337 * 0x08 = Decoding enabled
2338 * bit 0x04 Bank select
2339 * 0x00 = Bank 0
2340 * 0x04 = Bank 1
2341 * bits 0x03 MSS Base address
2342 * 0x00 = 0x530 (reset default)
2343 * 0x01 = 0x604
2344 * 0x02 = 0xf40
2345 * 0x03 = 0xe80
2348 #ifdef DEBUGXL
2349 /* Debug printing */
2350 printk("Port 0xc44 (before): ");
2351 outb((tmp & ~0x04), 0xc44);
2352 printk("%02x ", inb(0xc44));
2353 outb((tmp | 0x04), 0xc44);
2354 printk("%02x\n", inb(0xc44));
2355 #endif
2357 /* Set bank 1 of the register */
2358 tmp = 0x58; /* MSS Mode, MSS&FM decode enabled */
2360 switch (hw_config->io_base)
2362 case 0x530:
2363 tmp |= 0x00;
2364 break;
2365 case 0x604:
2366 tmp |= 0x01;
2367 break;
2368 case 0xf40:
2369 tmp |= 0x02;
2370 break;
2371 case 0xe80:
2372 tmp |= 0x03;
2373 break;
2374 default:
2375 DDB(printk("init_deskpro: Invalid MSS port %x\n", hw_config->io_base));
2376 return 0;
2378 outb((tmp & ~0x04), 0xc44); /* Write to bank=0 */
2380 #ifdef DEBUGXL
2381 /* Debug printing */
2382 printk("Port 0xc44 (after): ");
2383 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2384 printk("%02x ", inb(0xc44));
2385 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2386 printk("%02x\n", inb(0xc44));
2387 #endif
2390 * I/O port 0xc45 FM Address Decode/MSS ID Register.
2392 * bank=0, bits 0xfe: FM synthesis Decode Compare bits 7:1 (default=0x88)
2393 * bank=0, bit 0x01: SBIC Power Control Bit
2394 * 0x00 = Powered up
2395 * 0x01 = Powered down
2396 * bank=1, bits 0xfc: MSS ID (default=0x40)
2399 #ifdef DEBUGXL
2400 /* Debug printing */
2401 printk("Port 0xc45 (before): ");
2402 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2403 printk("%02x ", inb(0xc45));
2404 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2405 printk("%02x\n", inb(0xc45));
2406 #endif
2408 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2409 outb((0x88), 0xc45); /* FM base 7:0 = 0x88 */
2410 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2411 outb((0x10), 0xc45); /* MSS ID = 0x10 (MSS port returns 0x04) */
2413 #ifdef DEBUGXL
2414 /* Debug printing */
2415 printk("Port 0xc45 (after): ");
2416 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2417 printk("%02x ", inb(0xc45));
2418 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2419 printk("%02x\n", inb(0xc45));
2420 #endif
2424 * I/O port 0xc46 FM Address Decode/Address ASIC Revision Register.
2426 * bank=0, bits 0xff: FM synthesis Decode Compare bits 15:8 (default=0x03)
2427 * bank=1, bits 0xff: Audio addressing ASIC id
2430 #ifdef DEBUGXL
2431 /* Debug printing */
2432 printk("Port 0xc46 (before): ");
2433 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2434 printk("%02x ", inb(0xc46));
2435 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2436 printk("%02x\n", inb(0xc46));
2437 #endif
2439 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2440 outb((0x03), 0xc46); /* FM base 15:8 = 0x03 */
2441 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2442 outb((0x11), 0xc46); /* ASIC ID = 0x11 */
2444 #ifdef DEBUGXL
2445 /* Debug printing */
2446 printk("Port 0xc46 (after): ");
2447 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2448 printk("%02x ", inb(0xc46));
2449 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2450 printk("%02x\n", inb(0xc46));
2451 #endif
2454 * I/O port 0xc47 FM Address Decode Register.
2456 * bank=0, bits 0xff: Decode enable selection for various FM address bits
2457 * bank=1, bits 0xff: Reserved
2460 #ifdef DEBUGXL
2461 /* Debug printing */
2462 printk("Port 0xc47 (before): ");
2463 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2464 printk("%02x ", inb(0xc47));
2465 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2466 printk("%02x\n", inb(0xc47));
2467 #endif
2469 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2470 outb((0x7c), 0xc47); /* FM decode enable bits = 0x7c */
2471 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2472 outb((0x00), 0xc47); /* Reserved bank1 = 0x00 */
2474 #ifdef DEBUGXL
2475 /* Debug printing */
2476 printk("Port 0xc47 (after): ");
2477 outb((tmp & ~0x04), 0xc44); /* Select bank=0 */
2478 printk("%02x ", inb(0xc47));
2479 outb((tmp | 0x04), 0xc44); /* Select bank=1 */
2480 printk("%02x\n", inb(0xc47));
2481 #endif
2484 * I/O port 0xc6f = Audio Disable Function Register
2487 #ifdef DEBUGXL
2488 printk("Port 0xc6f (before) = %02x\n", inb(0xc6f));
2489 #endif
2491 outb((0x80), 0xc6f);
2493 #ifdef DEBUGXL
2494 printk("Port 0xc6f (after) = %02x\n", inb(0xc6f));
2495 #endif
2497 return 1;
2500 int probe_ms_sound(struct address_info *hw_config, struct resource *ports)
2502 unsigned char tmp;
2504 DDB(printk("Entered probe_ms_sound(%x, %d)\n", hw_config->io_base, hw_config->card_subtype));
2506 if (hw_config->card_subtype == 1) /* Has no IRQ/DMA registers */
2508 /* check_opl3(0x388, hw_config); */
2509 return ad1848_detect(ports, NULL, hw_config->osp);
2512 if (deskpro_xl && hw_config->card_subtype == 2) /* Compaq Deskpro XL */
2514 if (!init_deskpro(hw_config))
2515 return 0;
2518 if (deskpro_m) /* Compaq Deskpro M */
2520 if (!init_deskpro_m(hw_config))
2521 return 0;
2525 * Check if the IO port returns valid signature. The original MS Sound
2526 * system returns 0x04 while some cards (AudioTrix Pro for example)
2527 * return 0x00 or 0x0f.
2530 if ((tmp = inb(hw_config->io_base + 3)) == 0xff) /* Bus float */
2532 int ret;
2534 DDB(printk("I/O address is inactive (%x)\n", tmp));
2535 if (!(ret = ad1848_detect(ports, NULL, hw_config->osp)))
2536 return 0;
2537 return 1;
2539 DDB(printk("MSS signature = %x\n", tmp & 0x3f));
2540 if ((tmp & 0x3f) != 0x04 &&
2541 (tmp & 0x3f) != 0x0f &&
2542 (tmp & 0x3f) != 0x00)
2544 int ret;
2546 MDB(printk(KERN_ERR "No MSS signature detected on port 0x%x (0x%x)\n", hw_config->io_base, (int) inb(hw_config->io_base + 3)));
2547 DDB(printk("Trying to detect codec anyway but IRQ/DMA may not work\n"));
2548 if (!(ret = ad1848_detect(ports, NULL, hw_config->osp)))
2549 return 0;
2551 hw_config->card_subtype = 1;
2552 return 1;
2554 if ((hw_config->irq != 5) &&
2555 (hw_config->irq != 7) &&
2556 (hw_config->irq != 9) &&
2557 (hw_config->irq != 10) &&
2558 (hw_config->irq != 11) &&
2559 (hw_config->irq != 12))
2561 printk(KERN_ERR "MSS: Bad IRQ %d\n", hw_config->irq);
2562 return 0;
2564 if (hw_config->dma != 0 && hw_config->dma != 1 && hw_config->dma != 3)
2566 printk(KERN_ERR "MSS: Bad DMA %d\n", hw_config->dma);
2567 return 0;
2570 * Check that DMA0 is not in use with a 8 bit board.
2573 if (hw_config->dma == 0 && inb(hw_config->io_base + 3) & 0x80)
2575 printk(KERN_ERR "MSS: Can't use DMA0 with a 8 bit card/slot\n");
2576 return 0;
2578 if (hw_config->irq > 7 && hw_config->irq != 9 && inb(hw_config->io_base + 3) & 0x80)
2580 printk(KERN_ERR "MSS: Can't use IRQ%d with a 8 bit card/slot\n", hw_config->irq);
2581 return 0;
2583 return ad1848_detect(ports, NULL, hw_config->osp);
2586 void attach_ms_sound(struct address_info *hw_config, struct resource *ports, struct module *owner)
2588 static signed char interrupt_bits[12] =
2590 -1, -1, -1, -1, -1, 0x00, -1, 0x08, -1, 0x10, 0x18, 0x20
2592 signed char bits;
2593 char dma2_bit = 0;
2595 static char dma_bits[4] =
2597 1, 2, 0, 3
2600 int config_port = hw_config->io_base + 0;
2601 int version_port = hw_config->io_base + 3;
2602 int dma = hw_config->dma;
2603 int dma2 = hw_config->dma2;
2605 if (hw_config->card_subtype == 1) /* Has no IRQ/DMA registers */
2607 hw_config->slots[0] = ad1848_init("MS Sound System", ports,
2608 hw_config->irq,
2609 hw_config->dma,
2610 hw_config->dma2, 0,
2611 hw_config->osp,
2612 owner);
2613 return;
2616 * Set the IRQ and DMA addresses.
2619 bits = interrupt_bits[hw_config->irq];
2620 if (bits == -1)
2622 printk(KERN_ERR "MSS: Bad IRQ %d\n", hw_config->irq);
2623 release_region(ports->start, 4);
2624 release_region(ports->start - 4, 4);
2625 return;
2627 outb((bits | 0x40), config_port);
2628 if ((inb(version_port) & 0x40) == 0)
2629 printk(KERN_ERR "[MSS: IRQ Conflict?]\n");
2632 * Handle the capture DMA channel
2635 if (dma2 != -1 && dma2 != dma)
2637 if (!((dma == 0 && dma2 == 1) ||
2638 (dma == 1 && dma2 == 0) ||
2639 (dma == 3 && dma2 == 0)))
2640 { /* Unsupported combination. Try to swap channels */
2641 int tmp = dma;
2643 dma = dma2;
2644 dma2 = tmp;
2646 if ((dma == 0 && dma2 == 1) ||
2647 (dma == 1 && dma2 == 0) ||
2648 (dma == 3 && dma2 == 0))
2650 dma2_bit = 0x04; /* Enable capture DMA */
2652 else
2654 printk(KERN_WARNING "MSS: Invalid capture DMA\n");
2655 dma2 = dma;
2658 else
2660 dma2 = dma;
2663 hw_config->dma = dma;
2664 hw_config->dma2 = dma2;
2666 outb((bits | dma_bits[dma] | dma2_bit), config_port); /* Write IRQ+DMA setup */
2668 hw_config->slots[0] = ad1848_init("MS Sound System", ports,
2669 hw_config->irq,
2670 dma, dma2, 0,
2671 hw_config->osp,
2672 THIS_MODULE);
2675 void unload_ms_sound(struct address_info *hw_config)
2677 ad1848_unload(hw_config->io_base + 4,
2678 hw_config->irq,
2679 hw_config->dma,
2680 hw_config->dma2, 0);
2681 sound_unload_audiodev(hw_config->slots[0]);
2682 release_region(hw_config->io_base, 4);
2685 #ifndef EXCLUDE_TIMERS
2688 * Timer stuff (for /dev/music).
2691 static unsigned int current_interval;
2693 static unsigned int ad1848_tmr_start(int dev, unsigned int usecs)
2695 unsigned long flags;
2696 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
2697 unsigned long xtal_nsecs; /* nanoseconds per xtal oscillator tick */
2698 unsigned long divider;
2700 spin_lock_irqsave(&devc->lock,flags);
2703 * Length of the timer interval (in nanoseconds) depends on the
2704 * selected crystal oscillator. Check this from bit 0x01 of I8.
2706 * AD1845 has just one oscillator which has cycle time of 10.050 us
2707 * (when a 24.576 MHz xtal oscillator is used).
2709 * Convert requested interval to nanoseconds before computing
2710 * the timer divider.
2713 if (devc->model == MD_1845 || devc->model == MD_1845_SSCAPE)
2714 xtal_nsecs = 10050;
2715 else if (ad_read(devc, 8) & 0x01)
2716 xtal_nsecs = 9920;
2717 else
2718 xtal_nsecs = 9969;
2720 divider = (usecs * 1000 + xtal_nsecs / 2) / xtal_nsecs;
2722 if (divider < 100) /* Don't allow shorter intervals than about 1ms */
2723 divider = 100;
2725 if (divider > 65535) /* Overflow check */
2726 divider = 65535;
2728 ad_write(devc, 21, (divider >> 8) & 0xff); /* Set upper bits */
2729 ad_write(devc, 20, divider & 0xff); /* Set lower bits */
2730 ad_write(devc, 16, ad_read(devc, 16) | 0x40); /* Start the timer */
2731 devc->timer_running = 1;
2732 spin_unlock_irqrestore(&devc->lock,flags);
2734 return current_interval = (divider * xtal_nsecs + 500) / 1000;
2737 static void ad1848_tmr_reprogram(int dev)
2740 * Audio driver has changed sampling rate so that a different xtal
2741 * oscillator was selected. We have to reprogram the timer rate.
2744 ad1848_tmr_start(dev, current_interval);
2745 sound_timer_syncinterval(current_interval);
2748 static void ad1848_tmr_disable(int dev)
2750 unsigned long flags;
2751 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
2753 spin_lock_irqsave(&devc->lock,flags);
2754 ad_write(devc, 16, ad_read(devc, 16) & ~0x40);
2755 devc->timer_running = 0;
2756 spin_unlock_irqrestore(&devc->lock,flags);
2759 static void ad1848_tmr_restart(int dev)
2761 unsigned long flags;
2762 ad1848_info *devc = (ad1848_info *) audio_devs[dev]->devc;
2764 if (current_interval == 0)
2765 return;
2767 spin_lock_irqsave(&devc->lock,flags);
2768 ad_write(devc, 16, ad_read(devc, 16) | 0x40);
2769 devc->timer_running = 1;
2770 spin_unlock_irqrestore(&devc->lock,flags);
2773 static struct sound_lowlev_timer ad1848_tmr =
2777 ad1848_tmr_start,
2778 ad1848_tmr_disable,
2779 ad1848_tmr_restart
2782 static int ad1848_tmr_install(int dev)
2784 if (timer_installed != -1)
2785 return 0; /* Don't install another timer */
2787 timer_installed = ad1848_tmr.dev = dev;
2788 sound_timer_init(&ad1848_tmr, audio_devs[dev]->name);
2790 return 1;
2792 #endif /* EXCLUDE_TIMERS */
2794 EXPORT_SYMBOL(ad1848_detect);
2795 EXPORT_SYMBOL(ad1848_init);
2796 EXPORT_SYMBOL(ad1848_unload);
2797 EXPORT_SYMBOL(ad1848_control);
2798 EXPORT_SYMBOL(probe_ms_sound);
2799 EXPORT_SYMBOL(attach_ms_sound);
2800 EXPORT_SYMBOL(unload_ms_sound);
2802 static int __initdata io = -1;
2803 static int __initdata irq = -1;
2804 static int __initdata dma = -1;
2805 static int __initdata dma2 = -1;
2806 static int __initdata type = 0;
2808 module_param(io, int, 0); /* I/O for a raw AD1848 card */
2809 module_param(irq, int, 0); /* IRQ to use */
2810 module_param(dma, int, 0); /* First DMA channel */
2811 module_param(dma2, int, 0); /* Second DMA channel */
2812 module_param(type, int, 0); /* Card type */
2813 module_param(deskpro_xl, bool, 0); /* Special magic for Deskpro XL boxen */
2814 module_param(deskpro_m, bool, 0); /* Special magic for Deskpro M box */
2815 module_param(soundpro, bool, 0); /* More special magic for SoundPro chips */
2817 #ifdef CONFIG_PNP
2818 module_param(isapnp, int, 0);
2819 module_param(isapnpjump, int, 0);
2820 module_param(reverse, bool, 0);
2821 MODULE_PARM_DESC(isapnp, "When set to 0, Plug & Play support will be disabled");
2822 MODULE_PARM_DESC(isapnpjump, "Jumps to a specific slot in the driver's PnP table. Use the source, Luke.");
2823 MODULE_PARM_DESC(reverse, "When set to 1, will reverse ISAPnP search order");
2825 static struct pnp_dev *ad1848_dev = NULL;
2827 /* Please add new entries at the end of the table */
2828 static struct {
2829 char *name;
2830 unsigned short card_vendor, card_device,
2831 vendor, function;
2832 short mss_io, irq, dma, dma2; /* index into isapnp table */
2833 int type;
2834 } ad1848_isapnp_list[] __initdata = {
2835 {"CMI 8330 SoundPRO",
2836 ISAPNP_VENDOR('C','M','I'), ISAPNP_DEVICE(0x0001),
2837 ISAPNP_VENDOR('@','@','@'), ISAPNP_FUNCTION(0x0001),
2838 0, 0, 0,-1, 0},
2839 {"CS4232 based card",
2840 ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2841 ISAPNP_VENDOR('C','S','C'), ISAPNP_FUNCTION(0x0000),
2842 0, 0, 0, 1, 0},
2843 {"CS4232 based card",
2844 ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2845 ISAPNP_VENDOR('C','S','C'), ISAPNP_FUNCTION(0x0100),
2846 0, 0, 0, 1, 0},
2847 {"OPL3-SA2 WSS mode",
2848 ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2849 ISAPNP_VENDOR('Y','M','H'), ISAPNP_FUNCTION(0x0021),
2850 1, 0, 0, 1, 1},
2851 {"Advanced Gravis InterWave Audio",
2852 ISAPNP_VENDOR('G','R','V'), ISAPNP_DEVICE(0x0001),
2853 ISAPNP_VENDOR('G','R','V'), ISAPNP_FUNCTION(0x0000),
2854 0, 0, 0, 1, 0},
2855 {NULL}
2858 #ifdef MODULE
2859 static struct isapnp_device_id id_table[] = {
2860 { ISAPNP_VENDOR('C','M','I'), ISAPNP_DEVICE(0x0001),
2861 ISAPNP_VENDOR('@','@','@'), ISAPNP_FUNCTION(0x0001), 0 },
2862 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2863 ISAPNP_VENDOR('C','S','C'), ISAPNP_FUNCTION(0x0000), 0 },
2864 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2865 ISAPNP_VENDOR('C','S','C'), ISAPNP_FUNCTION(0x0100), 0 },
2866 /* The main driver for this card is opl3sa2
2867 { ISAPNP_ANY_ID, ISAPNP_ANY_ID,
2868 ISAPNP_VENDOR('Y','M','H'), ISAPNP_FUNCTION(0x0021), 0 },
2870 { ISAPNP_VENDOR('G','R','V'), ISAPNP_DEVICE(0x0001),
2871 ISAPNP_VENDOR('G','R','V'), ISAPNP_FUNCTION(0x0000), 0 },
2875 MODULE_DEVICE_TABLE(isapnp, id_table);
2876 #endif
2878 static struct pnp_dev *activate_dev(char *devname, char *resname, struct pnp_dev *dev)
2880 int err;
2882 err = pnp_device_attach(dev);
2883 if (err < 0)
2884 return(NULL);
2886 if((err = pnp_activate_dev(dev)) < 0) {
2887 printk(KERN_ERR "ad1848: %s %s config failed (out of resources?)[%d]\n", devname, resname, err);
2889 pnp_device_detach(dev);
2891 return(NULL);
2893 audio_activated = 1;
2894 return(dev);
2897 static struct pnp_dev __init *ad1848_init_generic(struct pnp_card *bus,
2898 struct address_info *hw_config, int slot)
2901 /* Configure Audio device */
2902 if((ad1848_dev = pnp_find_dev(bus, ad1848_isapnp_list[slot].vendor, ad1848_isapnp_list[slot].function, NULL)))
2904 if((ad1848_dev = activate_dev(ad1848_isapnp_list[slot].name, "ad1848", ad1848_dev)))
2906 hw_config->io_base = pnp_port_start(ad1848_dev, ad1848_isapnp_list[slot].mss_io);
2907 hw_config->irq = pnp_irq(ad1848_dev, ad1848_isapnp_list[slot].irq);
2908 hw_config->dma = pnp_dma(ad1848_dev, ad1848_isapnp_list[slot].dma);
2909 if(ad1848_isapnp_list[slot].dma2 != -1)
2910 hw_config->dma2 = pnp_dma(ad1848_dev, ad1848_isapnp_list[slot].dma2);
2911 else
2912 hw_config->dma2 = -1;
2913 hw_config->card_subtype = ad1848_isapnp_list[slot].type;
2914 } else
2915 return(NULL);
2916 } else
2917 return(NULL);
2919 return(ad1848_dev);
2922 static int __init ad1848_isapnp_init(struct address_info *hw_config, struct pnp_card *bus, int slot)
2924 char *busname = bus->name[0] ? bus->name : ad1848_isapnp_list[slot].name;
2926 /* Initialize this baby. */
2928 if(ad1848_init_generic(bus, hw_config, slot)) {
2929 /* We got it. */
2931 printk(KERN_NOTICE "ad1848: PnP reports '%s' at i/o %#x, irq %d, dma %d, %d\n",
2932 busname,
2933 hw_config->io_base, hw_config->irq, hw_config->dma,
2934 hw_config->dma2);
2935 return 1;
2937 return 0;
2940 static int __init ad1848_isapnp_probe(struct address_info *hw_config)
2942 static int first = 1;
2943 int i;
2945 /* Count entries in sb_isapnp_list */
2946 for (i = 0; ad1848_isapnp_list[i].card_vendor != 0; i++);
2947 i--;
2949 /* Check and adjust isapnpjump */
2950 if( isapnpjump < 0 || isapnpjump > i) {
2951 isapnpjump = reverse ? i : 0;
2952 printk(KERN_ERR "ad1848: Valid range for isapnpjump is 0-%d. Adjusted to %d.\n", i, isapnpjump);
2955 if(!first || !reverse)
2956 i = isapnpjump;
2957 first = 0;
2958 while(ad1848_isapnp_list[i].card_vendor != 0) {
2959 static struct pnp_card *bus = NULL;
2961 while ((bus = pnp_find_card(
2962 ad1848_isapnp_list[i].card_vendor,
2963 ad1848_isapnp_list[i].card_device,
2964 bus))) {
2966 if(ad1848_isapnp_init(hw_config, bus, i)) {
2967 isapnpjump = i; /* start next search from here */
2968 return 0;
2971 i += reverse ? -1 : 1;
2974 return -ENODEV;
2976 #endif
2979 static int __init init_ad1848(void)
2981 printk(KERN_INFO "ad1848/cs4248 codec driver Copyright (C) by Hannu Savolainen 1993-1996\n");
2983 #ifdef CONFIG_PNP
2984 if(isapnp && (ad1848_isapnp_probe(&cfg) < 0) ) {
2985 printk(KERN_NOTICE "ad1848: No ISAPnP cards found, trying standard ones...\n");
2986 isapnp = 0;
2988 #endif
2990 if(io != -1) {
2991 struct resource *ports;
2992 if( isapnp == 0 )
2994 if(irq == -1 || dma == -1) {
2995 printk(KERN_WARNING "ad1848: must give I/O , IRQ and DMA.\n");
2996 return -EINVAL;
2999 cfg.irq = irq;
3000 cfg.io_base = io;
3001 cfg.dma = dma;
3002 cfg.dma2 = dma2;
3003 cfg.card_subtype = type;
3006 ports = request_region(io + 4, 4, "ad1848");
3008 if (!ports)
3009 return -EBUSY;
3011 if (!request_region(io, 4, "WSS config")) {
3012 release_region(io + 4, 4);
3013 return -EBUSY;
3016 if (!probe_ms_sound(&cfg, ports)) {
3017 release_region(io + 4, 4);
3018 release_region(io, 4);
3019 return -ENODEV;
3021 attach_ms_sound(&cfg, ports, THIS_MODULE);
3022 loaded = 1;
3024 return 0;
3027 static void __exit cleanup_ad1848(void)
3029 if(loaded)
3030 unload_ms_sound(&cfg);
3032 #ifdef CONFIG_PNP
3033 if(ad1848_dev){
3034 if(audio_activated)
3035 pnp_device_detach(ad1848_dev);
3037 #endif
3040 module_init(init_ad1848);
3041 module_exit(cleanup_ad1848);
3043 #ifndef MODULE
3044 static int __init setup_ad1848(char *str)
3046 /* io, irq, dma, dma2, type */
3047 int ints[6];
3049 str = get_options(str, ARRAY_SIZE(ints), ints);
3051 io = ints[1];
3052 irq = ints[2];
3053 dma = ints[3];
3054 dma2 = ints[4];
3055 type = ints[5];
3057 return 1;
3060 __setup("ad1848=", setup_ad1848);
3061 #endif
3062 MODULE_LICENSE("GPL");