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
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.
31 * Tested. Believed fully functional.
34 #include <linux/config.h>
35 #include <linux/module.h>
36 #include <linux/stddef.h>
38 #include "soundmodule.h"
42 #include "sound_config.h"
46 #include "ad1848_mixer.h"
53 int dual_dma
; /* 1, when two DMA channels allocated */
54 unsigned char MCE_bit
;
55 unsigned char saved_regs
[32];
59 int record_dev
, playback_dev
;
65 char *chip_name
, *name
;
74 #define MD_4235 8 /* Crystal Audio CS4235 */
76 /* Mixer parameters */
78 int supported_devices
, orig_devices
;
79 int supported_rec_devices
, orig_rec_devices
;
81 short mixer_reroute
[32];
83 volatile unsigned long timer_ticks
;
86 mixer_ents
*mix_devices
;
87 int mixer_output_port
;
90 typedef struct ad1848_port_info
94 unsigned char speed_bits
;
97 unsigned char format_bits
;
101 static int nr_ad1848_devs
= 0;
103 #ifdef CONFIG_SOUND_SPRO
109 static volatile char irq2dev
[17] = {
110 -1, -1, -1, -1, -1, -1, -1, -1,
111 -1, -1, -1, -1, -1, -1, -1, -1, -1
114 #if defined(CONFIG_SEQUENCER) && !defined(EXCLUDE_TIMERS) || defined(MODULE)
116 static int timer_installed
= -1;
120 static int ad_format_mask
[9 /*devc->model */ ] =
123 AFMT_U8
| AFMT_S16_LE
| AFMT_MU_LAW
| AFMT_A_LAW
,
124 AFMT_U8
| AFMT_S16_LE
| AFMT_MU_LAW
| AFMT_A_LAW
| AFMT_S16_BE
| AFMT_IMA_ADPCM
,
125 AFMT_U8
| AFMT_S16_LE
| AFMT_MU_LAW
| AFMT_A_LAW
| AFMT_S16_BE
| AFMT_IMA_ADPCM
,
126 AFMT_U8
| AFMT_S16_LE
| AFMT_MU_LAW
| AFMT_A_LAW
, /* AD1845 */
127 AFMT_U8
| AFMT_S16_LE
| AFMT_MU_LAW
| AFMT_A_LAW
| AFMT_S16_BE
| AFMT_IMA_ADPCM
,
128 AFMT_U8
| AFMT_S16_LE
| AFMT_MU_LAW
| AFMT_A_LAW
| AFMT_S16_BE
| AFMT_IMA_ADPCM
,
129 AFMT_U8
| AFMT_S16_LE
| AFMT_MU_LAW
| AFMT_A_LAW
| AFMT_S16_BE
| AFMT_IMA_ADPCM
,
130 AFMT_U8
| AFMT_S16_LE
/* CS4235 */
133 static ad1848_info adev_info
[MAX_AUDIO_DEV
];
135 #define io_Index_Addr(d) ((d)->base)
136 #define io_Indexed_Data(d) ((d)->base+1)
137 #define io_Status(d) ((d)->base+2)
138 #define io_Polled_IO(d) ((d)->base+3)
142 #define CAP_F_TIMER 0x01
143 } capabilities
[9 /*devc->model */ ] = {
146 ,{CAP_F_TIMER
} /* MD_4231 */
147 ,{CAP_F_TIMER
} /* MD_4231A */
148 ,{CAP_F_TIMER
} /* MD_1845 */
149 ,{CAP_F_TIMER
} /* MD_4232 */
151 ,{CAP_F_TIMER
} /* MD_IWAVE */
155 static int ad1848_open(int dev
, int mode
);
156 static void ad1848_close(int dev
);
157 static void ad1848_output_block(int dev
, unsigned long buf
, int count
, int intrflag
);
158 static void ad1848_start_input(int dev
, unsigned long buf
, int count
, int intrflag
);
159 static int ad1848_prepare_for_output(int dev
, int bsize
, int bcount
);
160 static int ad1848_prepare_for_input(int dev
, int bsize
, int bcount
);
161 static void ad1848_halt(int dev
);
162 static void ad1848_halt_input(int dev
);
163 static void ad1848_halt_output(int dev
);
164 static void ad1848_trigger(int dev
, int bits
);
166 #if defined(CONFIG_SEQUENCER) && !defined(EXCLUDE_TIMERS)
167 static int ad1848_tmr_install(int dev
);
168 static void ad1848_tmr_reprogram(int dev
);
172 static int ad_read(ad1848_info
* devc
, int reg
)
176 int timeout
= 900000;
178 while (timeout
> 0 && inb(devc
->base
) == 0x80) /*Are we initializing */
183 outb(((unsigned char) (reg
& 0xff) | devc
->MCE_bit
), io_Index_Addr(devc
));
184 x
= inb(io_Indexed_Data(devc
));
185 /* printk("(%02x<-%02x) ", reg|devc->MCE_bit, x); */
186 restore_flags(flags
);
191 static void ad_write(ad1848_info
* devc
, int reg
, int data
)
194 int timeout
= 900000;
196 while (timeout
> 0 && inb(devc
->base
) == 0x80) /* Are we initializing */
201 outb(((unsigned char) (reg
& 0xff) | devc
->MCE_bit
), io_Index_Addr(devc
));
202 outb(((unsigned char) (data
& 0xff)), io_Indexed_Data(devc
));
203 /* printk("(%02x->%02x) ", reg|devc->MCE_bit, data); */
204 restore_flags(flags
);
207 static void wait_for_calibration(ad1848_info
* devc
)
212 * Wait until the auto calibration process has finished.
214 * 1) Wait until the chip becomes ready (reads don't return 0x80).
215 * 2) Wait until the ACI bit of I11 gets on and then off.
219 while (timeout
> 0 && inb(devc
->base
) == 0x80)
221 if (inb(devc
->base
) & 0x80)
222 printk(KERN_WARNING
"ad1848: Auto calibration timed out(1).\n");
225 while (timeout
> 0 && !(ad_read(devc
, 11) & 0x20))
227 if (!(ad_read(devc
, 11) & 0x20))
231 while (timeout
> 0 && (ad_read(devc
, 11) & 0x20))
233 if (ad_read(devc
, 11) & 0x20)
234 if (devc
->model
!= MD_1845
)
235 printk(KERN_WARNING
"ad1848: Auto calibration timed out(3).\n");
238 static void ad_mute(ad1848_info
* devc
)
244 * Save old register settings and mute output channels
247 for (i
= 6; i
< 8; i
++)
249 prev
= devc
->saved_regs
[i
] = ad_read(devc
, i
);
254 static void ad_unmute(ad1848_info
* devc
)
258 static void ad_enter_MCE(ad1848_info
* devc
)
264 while (timeout
> 0 && inb(devc
->base
) == 0x80) /*Are we initializing */
270 devc
->MCE_bit
= 0x40;
271 prev
= inb(io_Index_Addr(devc
));
274 restore_flags(flags
);
277 outb((devc
->MCE_bit
), io_Index_Addr(devc
));
278 restore_flags(flags
);
281 static void ad_leave_MCE(ad1848_info
* devc
)
284 unsigned char prev
, acal
;
287 while (timeout
> 0 && inb(devc
->base
) == 0x80) /*Are we initializing */
293 acal
= ad_read(devc
, 9);
295 devc
->MCE_bit
= 0x00;
296 prev
= inb(io_Index_Addr(devc
));
297 outb((0x00), io_Index_Addr(devc
)); /* Clear the MCE bit */
299 if ((prev
& 0x40) == 0) /* Not in MCE mode */
301 restore_flags(flags
);
304 outb((0x00), io_Index_Addr(devc
)); /* Clear the MCE bit */
305 if (acal
& 0x08) /* Auto calibration is enabled */
306 wait_for_calibration(devc
);
307 restore_flags(flags
);
310 static int ad1848_set_recmask(ad1848_info
* devc
, int mask
)
312 unsigned char recdev
;
315 mask
&= devc
->supported_rec_devices
;
317 /* Rename the mixer bits if necessary */
318 for (i
= 0; i
< 32; i
++)
320 if (devc
->mixer_reroute
[i
] != i
)
325 mask
|= (1 << devc
->mixer_reroute
[i
]);
331 for (i
= 0; i
< 32; i
++) /* Count selected device bits */
337 mask
= SOUND_MASK_MIC
;
338 else if (n
!= 1) { /* Too many devices selected */
339 mask
&= ~devc
->recmask
; /* Filter out active settings */
342 for (i
= 0; i
< 32; i
++) /* Count selected device bits */
347 mask
= SOUND_MASK_MIC
;
354 case SOUND_MASK_LINE
:
355 case SOUND_MASK_LINE3
:
360 case SOUND_MASK_LINE1
:
364 case SOUND_MASK_IMIX
:
369 mask
= SOUND_MASK_MIC
;
374 ad_write(devc
, 0, (ad_read(devc
, 0) & 0x3f) | recdev
);
375 ad_write(devc
, 1, (ad_read(devc
, 1) & 0x3f) | recdev
);
376 } else { /* soundpro */
381 for (i
= 0; i
< 32; i
++) { /* For each bit */
382 if ((devc
->supported_rec_devices
& (1 << i
)) == 0)
383 continue; /* Device not supported */
385 for (j
= LEFT_CHN
; j
<= RIGHT_CHN
; j
++) {
386 if (devc
->mix_devices
[i
][j
].nbits
== 0) /* Inexistent channel */
391 * set_rec_bit becomes 1 if the corresponding bit in mask is set
392 * then it gets flipped if the polarity is inverse
394 set_rec_bit
= ((mask
& (1 << i
)) != 0) ^ devc
->mix_devices
[i
][j
].recpol
;
396 val
= ad_read(devc
, devc
->mix_devices
[i
][j
].recreg
);
397 val
&= ~(1 << devc
->mix_devices
[i
][j
].recpos
);
398 val
|= (set_rec_bit
<< devc
->mix_devices
[i
][j
].recpos
);
399 ad_write(devc
, devc
->mix_devices
[i
][j
].recreg
, val
);
404 /* Rename the mixer bits back if necessary */
405 for (i
= 0; i
< 32; i
++)
407 if (devc
->mixer_reroute
[i
] != i
)
409 if (mask
& (1 << devc
->mixer_reroute
[i
]))
411 mask
&= ~(1 << devc
->mixer_reroute
[i
]);
416 devc
->recmask
= mask
;
420 static void change_bits(ad1848_info
* devc
, unsigned char *regval
,
421 unsigned char *muteval
, int dev
, int chn
, int newval
)
429 set_mute_bit
= (newval
== 0) ^ devc
->mix_devices
[dev
][chn
].mutepol
;
431 if (devc
->mix_devices
[dev
][chn
].polarity
== 1) /* Reverse */
432 newval
= 100 - newval
;
434 mask
= (1 << devc
->mix_devices
[dev
][chn
].nbits
) - 1;
435 shift
= devc
->mix_devices
[dev
][chn
].bitpos
;
437 if (devc
->mix_devices
[dev
][chn
].mutepos
== 8)
438 { /* if there is no mute bit */
439 mute
= 0; /* No mute bit; do nothing special */
440 mutemask
= ~0; /* No mute bit; do nothing special */
444 mute
= (set_mute_bit
<< devc
->mix_devices
[dev
][chn
].mutepos
);
445 mutemask
= ~(1 << devc
->mix_devices
[dev
][chn
].mutepos
);
448 newval
= (int) ((newval
* mask
) + 50) / 100; /* Scale it */
449 *regval
&= ~(mask
<< shift
); /* Clear bits */
450 *regval
|= (newval
& mask
) << shift
; /* Set new value */
452 *muteval
&= mutemask
;
456 static int ad1848_mixer_get(ad1848_info
* devc
, int dev
)
458 if (!((1 << dev
) & devc
->supported_devices
))
461 dev
= devc
->mixer_reroute
[dev
];
463 return devc
->levels
[dev
];
466 static void ad1848_mixer_set_channel(ad1848_info
*devc
, int dev
, int value
, int channel
)
468 int regoffs
, muteregoffs
;
469 unsigned char val
, muteval
;
471 regoffs
= devc
->mix_devices
[dev
][channel
].regno
;
472 muteregoffs
= devc
->mix_devices
[dev
][channel
].mutereg
;
473 val
= ad_read(devc
, regoffs
);
475 if (muteregoffs
!= regoffs
) {
476 muteval
= ad_read(devc
, muteregoffs
);
477 change_bits(devc
, &val
, &muteval
, dev
, channel
, value
);
480 change_bits(devc
, &val
, &val
, dev
, channel
, value
);
482 ad_write(devc
, regoffs
, val
);
483 devc
->saved_regs
[regoffs
] = val
;
484 if (muteregoffs
!= regoffs
) {
485 ad_write(devc
, muteregoffs
, muteval
);
486 devc
->saved_regs
[muteregoffs
] = muteval
;
490 static int ad1848_mixer_set(ad1848_info
* devc
, int dev
, int value
)
492 int left
= value
& 0x000000ff;
493 int right
= (value
& 0x0000ff00) >> 8;
499 if (!(devc
->supported_devices
& (1 << dev
)))
502 dev
= devc
->mixer_reroute
[dev
];
504 if (devc
->mix_devices
[dev
][LEFT_CHN
].nbits
== 0)
512 if (devc
->mix_devices
[dev
][RIGHT_CHN
].nbits
== 0) /* Mono control */
515 retvol
= left
| (right
<< 8);
518 left
= mix_cvt
[left
];
519 right
= mix_cvt
[right
];
521 devc
->levels
[dev
] = retvol
;
524 * Set the left channel
526 ad1848_mixer_set_channel(devc
, dev
, left
, LEFT_CHN
);
529 * Set the right channel
531 if (devc
->mix_devices
[dev
][RIGHT_CHN
].nbits
== 0)
533 ad1848_mixer_set_channel(devc
, dev
, right
, RIGHT_CHN
);
539 static void ad1848_mixer_reset(ad1848_info
* devc
)
544 devc
->mix_devices
= &(ad1848_mix_devices
[0]);
546 sprintf(name
, "%s_%d", devc
->chip_name
, nr_ad1848_devs
);
548 for (i
= 0; i
< 32; i
++)
549 devc
->mixer_reroute
[i
] = i
;
551 devc
->supported_rec_devices
= MODE1_REC_DEVICES
;
558 devc
->supported_devices
= MODE2_MIXER_DEVICES
;
562 devc
->supported_devices
= C930_MIXER_DEVICES
;
563 devc
->mix_devices
= &(c930_mix_devices
[0]);
567 devc
->supported_devices
= MODE3_MIXER_DEVICES
;
568 devc
->mix_devices
= &(iwave_mix_devices
[0]);
572 devc
->supported_devices
= MODE3_MIXER_DEVICES
;
577 devc
->supported_devices
= SPRO_MIXER_DEVICES
;
578 devc
->supported_rec_devices
= SPRO_REC_DEVICES
;
579 devc
->mix_devices
= &(spro_mix_devices
[0]);
584 devc
->supported_devices
= MODE1_MIXER_DEVICES
;
587 devc
->orig_devices
= devc
->supported_devices
;
588 devc
->orig_rec_devices
= devc
->supported_rec_devices
;
590 devc
->levels
= load_mixer_volumes(name
, default_mixer_levels
, 1);
592 for (i
= 0; i
< SOUND_MIXER_NRDEVICES
; i
++)
594 if (devc
->supported_devices
& (1 << i
))
595 ad1848_mixer_set(devc
, i
, devc
->levels
[i
]);
598 ad1848_set_recmask(devc
, SOUND_MASK_MIC
);
600 devc
->mixer_output_port
= devc
->levels
[31] | AUDIO_HEADPHONE
| AUDIO_LINE_OUT
;
603 if (devc
->mixer_output_port
& AUDIO_SPEAKER
)
604 ad_write(devc
, 26, ad_read(devc
, 26) & ~0x40); /* Unmute mono out */
606 ad_write(devc
, 26, ad_read(devc
, 26) | 0x40); /* Mute mono out */
609 * From the "wouldn't it be nice if the mixer API had (better)
610 * support for custom stuff" category
612 /* Enable surround mode and SB16 mixer */
613 ad_write(devc
, 16, 0x60);
617 static int ad1848_mixer_ioctl(int dev
, unsigned int cmd
, caddr_t arg
)
619 ad1848_info
*devc
= mixer_devs
[dev
]->devc
;
622 if (cmd
== SOUND_MIXER_PRIVATE1
)
624 if (get_user(val
, (int *)arg
))
629 val
&= (AUDIO_SPEAKER
| AUDIO_HEADPHONE
| AUDIO_LINE_OUT
);
630 devc
->mixer_output_port
= val
;
631 val
|= AUDIO_HEADPHONE
| AUDIO_LINE_OUT
; /* Always on */
632 devc
->mixer_output_port
= val
;
633 if (val
& AUDIO_SPEAKER
)
634 ad_write(devc
, 26, ad_read(devc
, 26) & ~0x40); /* Unmute mono out */
636 ad_write(devc
, 26, ad_read(devc
, 26) | 0x40); /* Mute mono out */
638 val
= devc
->mixer_output_port
;
639 return put_user(val
, (int *)arg
);
641 if (cmd
== SOUND_MIXER_PRIVATE2
)
643 if (get_user(val
, (int *)arg
))
645 return(ad1848_control(AD1848_MIXER_REROUTE
, val
));
647 if (((cmd
>> 8) & 0xff) == 'M')
649 if (_SIOC_DIR(cmd
) & _SIOC_WRITE
)
653 case SOUND_MIXER_RECSRC
:
654 if (get_user(val
, (int *)arg
))
656 val
= ad1848_set_recmask(devc
, val
);
660 if (get_user(val
, (int *)arg
))
662 val
= ad1848_mixer_set(devc
, cmd
& 0xff, val
);
665 return put_user(val
, (int *)arg
);
675 case SOUND_MIXER_RECSRC
:
679 case SOUND_MIXER_DEVMASK
:
680 val
= devc
->supported_devices
;
683 case SOUND_MIXER_STEREODEVS
:
684 val
= devc
->supported_devices
;
685 if (devc
->model
!= MD_C930
)
686 val
&= ~(SOUND_MASK_SPEAKER
| SOUND_MASK_IMIX
);
689 case SOUND_MIXER_RECMASK
:
690 val
= devc
->supported_rec_devices
;
693 case SOUND_MIXER_CAPS
:
694 val
=SOUND_CAP_EXCL_INPUT
;
698 val
= ad1848_mixer_get(devc
, cmd
& 0xff);
701 return put_user(val
, (int *)arg
);
708 static int ad1848_set_speed(int dev
, int arg
)
710 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
711 ad1848_port_info
*portc
= (ad1848_port_info
*) audio_devs
[dev
]->portc
;
714 * The sampling speed is encoded in the least significant nibble of I8. The
715 * LSB selects the clock source (0=24.576 MHz, 1=16.9344 MHz) and other
716 * three bits select the divisor (indirectly):
718 * The available speeds are in the following table. Keep the speeds in
719 * the increasing order.
728 static speed_struct speed_table
[] =
730 {5510, (0 << 1) | 1},
731 {5510, (0 << 1) | 1},
732 {6620, (7 << 1) | 1},
733 {8000, (0 << 1) | 0},
734 {9600, (7 << 1) | 0},
735 {11025, (1 << 1) | 1},
736 {16000, (1 << 1) | 0},
737 {18900, (2 << 1) | 1},
738 {22050, (3 << 1) | 1},
739 {27420, (2 << 1) | 0},
740 {32000, (3 << 1) | 0},
741 {33075, (6 << 1) | 1},
742 {37800, (4 << 1) | 1},
743 {44100, (5 << 1) | 1},
744 {48000, (6 << 1) | 0}
747 int i
, n
, selected
= -1;
749 n
= sizeof(speed_table
) / sizeof(speed_struct
);
754 if (devc
->model
== MD_1845
) /* AD1845 has different timer than others */
762 portc
->speed_bits
= speed_table
[3].bits
;
765 if (arg
< speed_table
[0].speed
)
767 if (arg
> speed_table
[n
- 1].speed
)
770 for (i
= 1 /*really */ ; selected
== -1 && i
< n
; i
++)
772 if (speed_table
[i
].speed
== arg
)
774 else if (speed_table
[i
].speed
> arg
)
778 diff1
= arg
- speed_table
[i
- 1].speed
;
779 diff2
= speed_table
[i
].speed
- arg
;
789 printk(KERN_WARNING
"ad1848: Can't find speed???\n");
792 portc
->speed
= speed_table
[selected
].speed
;
793 portc
->speed_bits
= speed_table
[selected
].bits
;
797 static short ad1848_set_channels(int dev
, short arg
)
799 ad1848_port_info
*portc
= (ad1848_port_info
*) audio_devs
[dev
]->portc
;
801 if (arg
!= 1 && arg
!= 2)
802 return portc
->channels
;
804 portc
->channels
= arg
;
808 static unsigned int ad1848_set_bits(int dev
, unsigned int arg
)
810 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
811 ad1848_port_info
*portc
= (ad1848_port_info
*) audio_devs
[dev
]->portc
;
813 static struct format_tbl
860 int i
, n
= sizeof(format2bits
) / sizeof(struct format_tbl
);
863 return portc
->audio_format
;
865 if (!(arg
& ad_format_mask
[devc
->model
]))
868 portc
->audio_format
= arg
;
870 for (i
= 0; i
< n
; i
++)
871 if (format2bits
[i
].format
== arg
)
873 if ((portc
->format_bits
= format2bits
[i
].bits
) == 0)
874 return portc
->audio_format
= AFMT_U8
; /* Was not supported */
878 /* Still hanging here. Something must be terribly wrong */
879 portc
->format_bits
= 0;
880 return portc
->audio_format
= AFMT_U8
;
883 static struct audio_driver ad1848_audio_driver
=
890 ad1848_prepare_for_input
,
891 ad1848_prepare_for_output
,
903 static struct mixer_operations ad1848_mixer_operations
=
906 "AD1848/CS4248/CS4231",
910 static int ad1848_open(int dev
, int mode
)
912 ad1848_info
*devc
= NULL
;
913 ad1848_port_info
*portc
;
916 if (dev
< 0 || dev
>= num_audiodevs
)
919 devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
920 portc
= (ad1848_port_info
*) audio_devs
[dev
]->portc
;
924 if (portc
->open_mode
|| (devc
->open_mode
& mode
))
926 restore_flags(flags
);
931 if (audio_devs
[dev
]->flags
& DMA_DUPLEX
)
935 devc
->intr_active
= 0;
936 devc
->audio_mode
= 0;
937 devc
->open_mode
|= mode
;
938 portc
->open_mode
= mode
;
939 ad1848_trigger(dev
, 0);
941 if (mode
& OPEN_READ
)
942 devc
->record_dev
= dev
;
943 if (mode
& OPEN_WRITE
)
944 devc
->playback_dev
= dev
;
945 restore_flags(flags
);
947 * Mute output until the playback really starts. This decreases clicking (hope so).
954 static void ad1848_close(int dev
)
957 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
958 ad1848_port_info
*portc
= (ad1848_port_info
*) audio_devs
[dev
]->portc
;
960 DEB(printk("ad1848_close(void)\n"));
965 devc
->intr_active
= 0;
968 devc
->audio_mode
= 0;
969 devc
->open_mode
&= ~portc
->open_mode
;
970 portc
->open_mode
= 0;
973 restore_flags(flags
);
976 static void ad1848_output_block(int dev
, unsigned long buf
, int count
, int intrflag
)
978 unsigned long flags
, cnt
;
979 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
980 ad1848_port_info
*portc
= (ad1848_port_info
*) audio_devs
[dev
]->portc
;
984 if (portc
->audio_format
== AFMT_IMA_ADPCM
)
990 if (portc
->audio_format
& (AFMT_S16_LE
| AFMT_S16_BE
)) /* 16 bit data */
993 if (portc
->channels
> 1)
997 if ((devc
->audio_mode
& PCM_ENABLE_OUTPUT
) && (audio_devs
[dev
]->flags
& DMA_AUTOMODE
) &&
999 cnt
== devc
->xfer_count
)
1001 devc
->audio_mode
|= PCM_ENABLE_OUTPUT
;
1002 devc
->intr_active
= 1;
1004 * Auto DMA mode on. No need to react
1010 ad_write(devc
, 15, (unsigned char) (cnt
& 0xff));
1011 ad_write(devc
, 14, (unsigned char) ((cnt
>> 8) & 0xff));
1013 devc
->xfer_count
= cnt
;
1014 devc
->audio_mode
|= PCM_ENABLE_OUTPUT
;
1015 devc
->intr_active
= 1;
1016 restore_flags(flags
);
1019 static void ad1848_start_input(int dev
, unsigned long buf
, int count
, int intrflag
)
1021 unsigned long flags
, cnt
;
1022 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
1023 ad1848_port_info
*portc
= (ad1848_port_info
*) audio_devs
[dev
]->portc
;
1026 if (portc
->audio_format
== AFMT_IMA_ADPCM
)
1032 if (portc
->audio_format
& (AFMT_S16_LE
| AFMT_S16_BE
)) /* 16 bit data */
1035 if (portc
->channels
> 1)
1039 if ((devc
->audio_mode
& PCM_ENABLE_INPUT
) && (audio_devs
[dev
]->flags
& DMA_AUTOMODE
) &&
1041 cnt
== devc
->xfer_count
)
1043 devc
->audio_mode
|= PCM_ENABLE_INPUT
;
1044 devc
->intr_active
= 1;
1046 * Auto DMA mode on. No need to react
1052 if (devc
->model
== MD_1848
)
1054 ad_write(devc
, 15, (unsigned char) (cnt
& 0xff));
1055 ad_write(devc
, 14, (unsigned char) ((cnt
>> 8) & 0xff));
1059 ad_write(devc
, 31, (unsigned char) (cnt
& 0xff));
1060 ad_write(devc
, 30, (unsigned char) ((cnt
>> 8) & 0xff));
1065 devc
->xfer_count
= cnt
;
1066 devc
->audio_mode
|= PCM_ENABLE_INPUT
;
1067 devc
->intr_active
= 1;
1068 restore_flags(flags
);
1071 static int ad1848_prepare_for_output(int dev
, int bsize
, int bcount
)
1074 unsigned char fs
, old_fs
, tmp
= 0;
1075 unsigned long flags
;
1076 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
1077 ad1848_port_info
*portc
= (ad1848_port_info
*) audio_devs
[dev
]->portc
;
1083 fs
= portc
->speed_bits
| (portc
->format_bits
<< 5);
1085 if (portc
->channels
> 1)
1088 ad_enter_MCE(devc
); /* Enables changes to the format select reg */
1090 if (devc
->model
== MD_1845
) /* Use alternate speed select registers */
1092 fs
&= 0xf0; /* Mask off the rate select bits */
1094 ad_write(devc
, 22, (portc
->speed
>> 8) & 0xff); /* Speed MSB */
1095 ad_write(devc
, 23, portc
->speed
& 0xff); /* Speed LSB */
1097 old_fs
= ad_read(devc
, 8);
1099 if (devc
->model
== MD_4232
)
1101 tmp
= ad_read(devc
, 16);
1102 ad_write(devc
, 16, tmp
| 0x30);
1104 if (devc
->model
== MD_IWAVE
)
1105 ad_write(devc
, 17, 0xc2); /* Disable variable frequency select */
1107 ad_write(devc
, 8, fs
);
1110 * Write to I8 starts resynchronization. Wait until it completes.
1114 while (timeout
< 100 && inb(devc
->base
) != 0x80)
1117 while (timeout
< 10000 && inb(devc
->base
) == 0x80)
1120 if (devc
->model
== MD_4232
)
1121 ad_write(devc
, 16, tmp
& ~0x30);
1123 ad_leave_MCE(devc
); /*
1124 * Starts the calibration process.
1126 restore_flags(flags
);
1127 devc
->xfer_count
= 0;
1129 #if defined(CONFIG_SEQUENCER) && !defined(EXCLUDE_TIMERS)
1130 if (dev
== timer_installed
&& devc
->timer_running
)
1131 if ((fs
& 0x01) != (old_fs
& 0x01))
1133 ad1848_tmr_reprogram(dev
);
1136 ad1848_halt_output(dev
);
1140 static int ad1848_prepare_for_input(int dev
, int bsize
, int bcount
)
1143 unsigned char fs
, old_fs
, tmp
= 0;
1144 unsigned long flags
;
1145 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
1146 ad1848_port_info
*portc
= (ad1848_port_info
*) audio_devs
[dev
]->portc
;
1148 if (devc
->audio_mode
)
1153 fs
= portc
->speed_bits
| (portc
->format_bits
<< 5);
1155 if (portc
->channels
> 1)
1158 ad_enter_MCE(devc
); /* Enables changes to the format select reg */
1160 if (devc
->model
== MD_1845
) /* Use alternate speed select registers */
1162 fs
&= 0xf0; /* Mask off the rate select bits */
1164 ad_write(devc
, 22, (portc
->speed
>> 8) & 0xff); /* Speed MSB */
1165 ad_write(devc
, 23, portc
->speed
& 0xff); /* Speed LSB */
1167 if (devc
->model
== MD_4232
)
1169 tmp
= ad_read(devc
, 16);
1170 ad_write(devc
, 16, tmp
| 0x30);
1172 if (devc
->model
== MD_IWAVE
)
1173 ad_write(devc
, 17, 0xc2); /* Disable variable frequency select */
1176 * If mode >= 2 (CS4231), set I28. It's the capture format register.
1179 if (devc
->model
!= MD_1848
)
1181 old_fs
= ad_read(devc
, 28);
1182 ad_write(devc
, 28, fs
);
1185 * Write to I28 starts resynchronization. Wait until it completes.
1189 while (timeout
< 100 && inb(devc
->base
) != 0x80)
1193 while (timeout
< 10000 && inb(devc
->base
) == 0x80)
1196 if (devc
->model
!= MD_1848
&& devc
->model
!= MD_1845
)
1199 * CS4231 compatible devices don't have separate sampling rate selection
1200 * register for recording an playback. The I8 register is shared so we have to
1201 * set the speed encoding bits of it too.
1203 unsigned char tmp
= portc
->speed_bits
| (ad_read(devc
, 8) & 0xf0);
1205 ad_write(devc
, 8, tmp
);
1207 * Write to I8 starts resynchronization. Wait until it completes.
1210 while (timeout
< 100 && inb(devc
->base
) != 0x80)
1214 while (timeout
< 10000 && inb(devc
->base
) == 0x80)
1219 { /* For AD1848 set I8. */
1221 old_fs
= ad_read(devc
, 8);
1222 ad_write(devc
, 8, fs
);
1224 * Write to I8 starts resynchronization. Wait until it completes.
1227 while (timeout
< 100 && inb(devc
->base
) != 0x80)
1230 while (timeout
< 10000 && inb(devc
->base
) == 0x80)
1234 if (devc
->model
== MD_4232
)
1235 ad_write(devc
, 16, tmp
& ~0x30);
1237 ad_leave_MCE(devc
); /*
1238 * Starts the calibration process.
1240 restore_flags(flags
);
1241 devc
->xfer_count
= 0;
1243 #if defined(CONFIG_SEQUENCER) && !defined(EXCLUDE_TIMERS)
1244 if (dev
== timer_installed
&& devc
->timer_running
)
1246 if ((fs
& 0x01) != (old_fs
& 0x01))
1248 ad1848_tmr_reprogram(dev
);
1252 ad1848_halt_input(dev
);
1256 static void ad1848_halt(int dev
)
1258 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
1259 ad1848_port_info
*portc
= (ad1848_port_info
*) audio_devs
[dev
]->portc
;
1261 unsigned char bits
= ad_read(devc
, 9);
1263 if (bits
& 0x01 && (portc
->open_mode
& OPEN_WRITE
))
1264 ad1848_halt_output(dev
);
1266 if (bits
& 0x02 && (portc
->open_mode
& OPEN_READ
))
1267 ad1848_halt_input(dev
);
1268 devc
->audio_mode
= 0;
1271 static void ad1848_halt_input(int dev
)
1273 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
1274 unsigned long flags
;
1276 if (!(ad_read(devc
, 9) & 0x02))
1277 return; /* Capture not enabled */
1287 if(!isa_dma_bridge_buggy
)
1288 disable_dma(audio_devs
[dev
]->dmap_in
->dma
);
1290 for (tmout
= 0; tmout
< 100000; tmout
++)
1291 if (ad_read(devc
, 11) & 0x10)
1293 ad_write(devc
, 9, ad_read(devc
, 9) & ~0x02); /* Stop capture */
1295 if(!isa_dma_bridge_buggy
)
1296 enable_dma(audio_devs
[dev
]->dmap_in
->dma
);
1297 devc
->audio_mode
&= ~PCM_ENABLE_INPUT
;
1300 outb(0, io_Status(devc
)); /* Clear interrupt status */
1301 outb(0, io_Status(devc
)); /* Clear interrupt status */
1303 devc
->audio_mode
&= ~PCM_ENABLE_INPUT
;
1305 restore_flags(flags
);
1308 static void ad1848_halt_output(int dev
)
1310 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
1311 unsigned long flags
;
1313 if (!(ad_read(devc
, 9) & 0x01))
1314 return; /* Playback not enabled */
1323 if(!isa_dma_bridge_buggy
)
1324 disable_dma(audio_devs
[dev
]->dmap_out
->dma
);
1326 for (tmout
= 0; tmout
< 100000; tmout
++)
1327 if (ad_read(devc
, 11) & 0x10)
1329 ad_write(devc
, 9, ad_read(devc
, 9) & ~0x01); /* Stop playback */
1331 if(!isa_dma_bridge_buggy
)
1332 enable_dma(audio_devs
[dev
]->dmap_out
->dma
);
1334 devc
->audio_mode
&= ~PCM_ENABLE_OUTPUT
;
1337 outb((0), io_Status(devc
)); /* Clear interrupt status */
1338 outb((0), io_Status(devc
)); /* Clear interrupt status */
1340 devc
->audio_mode
&= ~PCM_ENABLE_OUTPUT
;
1342 restore_flags(flags
);
1345 static void ad1848_trigger(int dev
, int state
)
1347 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
1348 ad1848_port_info
*portc
= (ad1848_port_info
*) audio_devs
[dev
]->portc
;
1349 unsigned long flags
;
1350 unsigned char tmp
, old
;
1354 state
&= devc
->audio_mode
;
1356 tmp
= old
= ad_read(devc
, 9);
1358 if (portc
->open_mode
& OPEN_READ
)
1360 if (state
& PCM_ENABLE_INPUT
)
1365 if (portc
->open_mode
& OPEN_WRITE
)
1367 if (state
& PCM_ENABLE_OUTPUT
)
1372 /* ad_mute(devc); */
1375 ad_write(devc
, 9, tmp
);
1378 restore_flags(flags
);
1381 static void ad1848_init_hw(ad1848_info
* devc
)
1386 * Initial values for the indirect registers of CS4248/AD1848.
1388 static int init_values
[] =
1390 0xa8, 0xa8, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
1391 0x00, 0x0c, 0x02, 0x00, 0x8a, 0x01, 0x00, 0x00,
1393 /* Positions 16 to 31 just for CS4231/2 and ad1845 */
1394 0x80, 0x00, 0x10, 0x10, 0x00, 0x00, 0x1f, 0x40,
1395 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1399 for (i
= 0; i
< 16; i
++)
1400 ad_write(devc
, i
, init_values
[i
]);
1403 ad_mute(devc
); /* Initialize some variables */
1404 ad_unmute(devc
); /* Leave it unmuted now */
1406 if (devc
->model
> MD_1848
)
1408 ad_write(devc
, 12, ad_read(devc
, 12) | 0x40); /* Mode2 = enabled */
1410 if (devc
->model
== MD_IWAVE
)
1411 ad_write(devc
, 12, 0x6c); /* Select codec mode 3 */
1413 for (i
= 16; i
< 32; i
++)
1414 ad_write(devc
, i
, init_values
[i
]);
1416 if (devc
->model
== MD_IWAVE
)
1417 ad_write(devc
, 16, 0x30); /* Playback and capture counters enabled */
1419 if (devc
->model
> MD_1848
)
1421 if (devc
->audio_flags
& DMA_DUPLEX
)
1422 ad_write(devc
, 9, ad_read(devc
, 9) & ~0x04); /* Dual DMA mode */
1424 ad_write(devc
, 9, ad_read(devc
, 9) | 0x04); /* Single DMA mode */
1426 if (devc
->model
== MD_1845
)
1427 ad_write(devc
, 27, ad_read(devc
, 27) | 0x08); /* Alternate freq select enabled */
1429 if (devc
->model
== MD_IWAVE
)
1430 { /* Some magic Interwave specific initialization */
1431 ad_write(devc
, 12, 0x6c); /* Select codec mode 3 */
1432 ad_write(devc
, 16, 0x30); /* Playback and capture counters enabled */
1433 ad_write(devc
, 17, 0xc2); /* Alternate feature enable */
1438 devc
->audio_flags
&= ~DMA_DUPLEX
;
1439 ad_write(devc
, 9, ad_read(devc
, 9) | 0x04); /* Single DMA mode */
1441 ad_write(devc
, 12, ad_read(devc
, 12) | 0x40); /* Mode2 = enabled */
1444 outb((0), io_Status(devc
)); /* Clear pending interrupts */
1447 * Toggle the MCE bit. It completes the initialization phase.
1450 ad_enter_MCE(devc
); /* In case the bit was off */
1453 ad1848_mixer_reset(devc
);
1456 int ad1848_detect(int io_base
, int *ad_flags
, int *osp
)
1459 ad1848_info
*devc
= &adev_info
[nr_ad1848_devs
];
1460 unsigned char tmp1
= 0xff, tmp2
= 0xff;
1461 int optiC930
= 0; /* OPTi 82C930 flag */
1463 int ad1847_flag
= 0;
1464 int cs4248_flag
= 0;
1468 DDB(printk("ad1848_detect(%x)\n", io_base
));
1472 if (*ad_flags
== 0x12345678)
1477 if (*ad_flags
== 0x12345677)
1483 if (nr_ad1848_devs
>= MAX_AUDIO_DEV
)
1485 printk(KERN_ERR
"ad1848 - Too many audio devices\n");
1488 if (check_region(io_base
, 4))
1490 printk(KERN_ERR
"ad1848.c: Port %x not free.\n", io_base
);
1493 devc
->base
= io_base
;
1495 devc
->timer_running
= 0;
1496 devc
->MCE_bit
= 0x40;
1498 devc
->open_mode
= 0;
1499 devc
->chip_name
= devc
->name
= "AD1848";
1500 devc
->model
= MD_1848
; /* AD1848 or CS4248 */
1501 devc
->levels
= NULL
;
1502 devc
->debug_flag
= 0;
1505 * Check that the I/O address is in use.
1507 * The bit 0x80 of the base I/O port is known to be 0 after the
1508 * chip has performed its power on initialization. Just assume
1509 * this has happened before the OS is starting.
1511 * If the I/O address is unused, it typically returns 0xff.
1514 if (inb(devc
->base
) == 0xff)
1516 DDB(printk("ad1848_detect: The base I/O address appears to be dead\n"));
1520 * Wait for the device to stop initialization
1523 DDB(printk("ad1848_detect() - step 0\n"));
1525 for (i
= 0; i
< 10000000; i
++)
1527 unsigned char x
= inb(devc
->base
);
1529 if (x
== 0xff || !(x
& 0x80))
1533 DDB(printk("ad1848_detect() - step A\n"));
1535 if (inb(devc
->base
) == 0x80) /* Not ready. Let's wait */
1538 if ((inb(devc
->base
) & 0x80) != 0x00) /* Not a AD1848 */
1540 DDB(printk("ad1848 detect error - step A (%02x)\n", (int) inb(devc
->base
)));
1545 * Test if it's possible to change contents of the indirect registers.
1546 * Registers 0 and 1 are ADC volume registers. The bit 0x10 is read only
1547 * so try to avoid using it.
1550 DDB(printk("ad1848_detect() - step B\n"));
1551 ad_write(devc
, 0, 0xaa);
1552 ad_write(devc
, 1, 0x45); /* 0x55 with bit 0x10 clear */
1554 if ((tmp1
= ad_read(devc
, 0)) != 0xaa || (tmp2
= ad_read(devc
, 1)) != 0x45)
1556 if (tmp2
== 0x65) /* AD1847 has couple of bits hardcoded to 1 */
1560 DDB(printk("ad1848 detect error - step B (%x/%x)\n", tmp1
, tmp2
));
1564 DDB(printk("ad1848_detect() - step C\n"));
1565 ad_write(devc
, 0, 0x45);
1566 ad_write(devc
, 1, 0xaa);
1568 if ((tmp1
= ad_read(devc
, 0)) != 0x45 || (tmp2
= ad_read(devc
, 1)) != 0xaa)
1570 if (tmp2
== 0x8a) /* AD1847 has few bits hardcoded to 1 */
1574 DDB(printk("ad1848 detect error - step C (%x/%x)\n", tmp1
, tmp2
));
1580 * The indirect register I12 has some read only bits. Let's
1581 * try to change them.
1584 DDB(printk("ad1848_detect() - step D\n"));
1585 tmp
= ad_read(devc
, 12);
1586 ad_write(devc
, 12, (~tmp
) & 0x0f);
1588 if ((tmp
& 0x0f) != ((tmp1
= ad_read(devc
, 12)) & 0x0f))
1590 DDB(printk("ad1848 detect error - step D (%x)\n", tmp1
));
1595 * NOTE! Last 4 bits of the reg I12 tell the chip revision.
1596 * 0x01=RevB and 0x0A=RevC.
1600 * The original AD1848/CS4248 has just 15 indirect registers. This means
1601 * that I0 and I16 should return the same value (etc.).
1602 * However this doesn't work with CS4248. Actually it seems to be impossible
1603 * to detect if the chip is a CS4231 or CS4248.
1604 * Ensure that the Mode2 enable bit of I12 is 0. Otherwise this test fails
1609 * OPTi 82C930 has mode2 control bit in another place. This test will fail
1610 * with it. Accept this situation as a possible indication of this chip.
1613 DDB(printk("ad1848_detect() - step F\n"));
1614 ad_write(devc
, 12, 0); /* Mode2=disabled */
1616 for (i
= 0; i
< 16; i
++)
1618 if ((tmp1
= ad_read(devc
, i
)) != (tmp2
= ad_read(devc
, i
+ 16)))
1620 DDB(printk("ad1848 detect step F(%d/%x/%x) - OPTi chip???\n", i
, tmp1
, tmp2
));
1628 * Try to switch the chip to mode2 (CS4231) by setting the MODE2 bit (0x40).
1629 * The bit 0x80 is always 1 in CS4248 and CS4231.
1632 DDB(printk("ad1848_detect() - step G\n"));
1634 if (ad_flags
&& *ad_flags
== 400)
1637 ad_write(devc
, 12, 0x40); /* Set mode2, clear 0x80 */
1643 tmp1
= ad_read(devc
, 12);
1647 *ad_flags
|= AD_F_CS4248
;
1649 devc
->chip_name
= "CS4248"; /* Our best knowledge just now */
1651 if (optiC930
|| (tmp1
& 0xc0) == (0x80 | 0x40))
1654 * CS4231 detected - is it?
1656 * Verify that setting I0 doesn't change I16.
1659 DDB(printk("ad1848_detect() - step H\n"));
1660 ad_write(devc
, 16, 0); /* Set I16 to known value */
1662 ad_write(devc
, 0, 0x45);
1663 if ((tmp1
= ad_read(devc
, 16)) != 0x45) /* No change -> CS4231? */
1665 ad_write(devc
, 0, 0xaa);
1666 if ((tmp1
= ad_read(devc
, 16)) == 0xaa) /* Rotten bits? */
1668 DDB(printk("ad1848 detect error - step H(%x)\n", tmp1
));
1673 * Verify that some bits of I25 are read only.
1676 DDB(printk("ad1848_detect() - step I\n"));
1677 tmp1
= ad_read(devc
, 25); /* Original bits */
1678 ad_write(devc
, 25, ~tmp1
); /* Invert all bits */
1679 if ((ad_read(devc
, 25) & 0xe7) == (tmp1
& 0xe7))
1684 * It's at least CS4231
1687 devc
->chip_name
= "CS4231";
1688 devc
->model
= MD_4231
;
1691 * It could be an AD1845 or CS4231A as well.
1692 * CS4231 and AD1845 report the same revision info in I25
1693 * while the CS4231A reports different.
1696 id
= ad_read(devc
, 25);
1697 if ((id
& 0xe7) == 0x80) /* Device busy??? */
1698 id
= ad_read(devc
, 25);
1699 if ((id
& 0xe7) == 0x80) /* Device still busy??? */
1700 id
= ad_read(devc
, 25);
1701 DDB(printk("ad1848_detect() - step J (%02x/%02x)\n", id
, ad_read(devc
, 25)));
1703 if ((id
& 0xe7) == 0x80) {
1705 * It must be a CS4231 or AD1845. The register I23 of
1706 * CS4231 is undefined and it appears to be read only.
1707 * AD1845 uses I23 for setting sample rate. Assume
1708 * the chip is AD1845 if I23 is changeable.
1711 unsigned char tmp
= ad_read(devc
, 23);
1712 ad_write(devc
, 23, ~tmp
);
1716 devc
->model
= MD_IWAVE
;
1717 devc
->chip_name
= "IWave";
1719 else if (ad_read(devc
, 23) != tmp
) /* AD1845 ? */
1721 devc
->chip_name
= "AD1845";
1722 devc
->model
= MD_1845
;
1724 else if (cs4248_flag
)
1727 *ad_flags
|= AD_F_CS4248
;
1728 devc
->chip_name
= "CS4248";
1729 devc
->model
= MD_1848
;
1730 ad_write(devc
, 12, ad_read(devc
, 12) & ~0x40); /* Mode2 off */
1732 ad_write(devc
, 23, tmp
); /* Restore */
1736 switch (id
& 0x1f) {
1737 case 3: /* CS4236/CS4235 */
1740 ad_write(devc
, 12, ad_read(devc
, 12) | 0x60); /* switch to mode 3 */
1741 ad_write(devc
, 23, 0x9c); /* select extended register 25 */
1742 xid
= inb(io_Indexed_Data(devc
));
1743 ad_write(devc
, 12, ad_read(devc
, 12) & ~0x60); /* back to mode 0 */
1744 if ((xid
& 0x1f) == 0x1d) {
1745 devc
->chip_name
= "CS4235";
1746 devc
->model
= MD_4235
;
1748 devc
->chip_name
= "CS4236";
1749 devc
->model
= MD_4232
;
1754 case 2: /* CS4232/CS4232A */
1755 devc
->chip_name
= "CS4232";
1756 devc
->model
= MD_4232
;
1760 if ((id
& 0xe0) == 0xa0)
1762 devc
->chip_name
= "CS4231A";
1763 devc
->model
= MD_4231A
;
1767 devc
->chip_name
= "CS4321";
1768 devc
->model
= MD_4231
;
1772 default: /* maybe */
1773 DDB(printk("ad1848: I25 = %02x/%02x\n", ad_read(devc
, 25), ad_read(devc
, 25) & 0xe7));
1776 devc
->chip_name
= "82C930";
1777 devc
->model
= MD_C930
;
1781 devc
->chip_name
= "CS4231";
1782 devc
->model
= MD_4231
;
1787 ad_write(devc
, 25, tmp1
); /* Restore bits */
1789 DDB(printk("ad1848_detect() - step K\n"));
1791 } else if (tmp1
== 0x0a) {
1793 * Is it perhaps a SoundPro CMI8330?
1794 * If so, then we should be able to change indirect registers
1795 * greater than I15 after activating MODE2, even though reading
1796 * back I12 does not show it.
1800 * Let's try comparing register values
1802 for (i
= 0; i
< 16; i
++) {
1803 if ((tmp1
= ad_read(devc
, i
)) != (tmp2
= ad_read(devc
, i
+ 16))) {
1804 DDB(printk("ad1848 detect step H(%d/%x/%x) - SoundPro chip?\n", i
, tmp1
, tmp2
));
1806 devc
->chip_name
= "SoundPro CMI 8330";
1812 DDB(printk("ad1848_detect() - step L\n"));
1815 if (devc
->model
!= MD_1848
)
1816 *ad_flags
|= AD_F_CS4231
;
1818 DDB(printk("ad1848_detect() - Detected OK\n"));
1820 if (devc
->model
== MD_1848
&& ad1847_flag
)
1821 devc
->chip_name
= "AD1847";
1827 int ad1848_init(char *name
, int io_base
, int irq
, int dma_playback
, int dma_capture
, int share_dma
, int *osp
)
1830 * NOTE! If irq < 0, there is another driver which has allocated the IRQ
1831 * so that this driver doesn't need to allocate/deallocate it.
1832 * The actually used IRQ is ABS(irq).
1840 ad1848_info
*devc
= &adev_info
[nr_ad1848_devs
];
1842 ad1848_port_info
*portc
= NULL
;
1844 devc
->irq
= (irq
> 0) ? irq
: 0;
1845 devc
->open_mode
= 0;
1846 devc
->timer_ticks
= 0;
1847 devc
->dma1
= dma_playback
;
1848 devc
->dma2
= dma_capture
;
1849 devc
->audio_flags
= DMA_AUTOMODE
;
1850 devc
->playback_dev
= devc
->record_dev
= 0;
1854 if (name
!= NULL
&& name
[0] != 0)
1856 "%s (%s)", name
, devc
->chip_name
);
1859 "Generic audio codec (%s)", devc
->chip_name
);
1861 request_region(devc
->base
, 4, devc
->name
);
1863 conf_printf2(dev_name
, devc
->base
, devc
->irq
, dma_playback
, dma_capture
);
1865 if (devc
->model
== MD_1848
|| devc
->model
== MD_C930
)
1866 devc
->audio_flags
|= DMA_HARDSTOP
;
1868 if (devc
->model
> MD_1848
)
1870 if (devc
->dma1
== devc
->dma2
|| devc
->dma2
== -1 || devc
->dma1
== -1)
1871 devc
->audio_flags
&= ~DMA_DUPLEX
;
1873 devc
->audio_flags
|= DMA_DUPLEX
;
1876 portc
= (ad1848_port_info
*) kmalloc(sizeof(ad1848_port_info
), GFP_KERNEL
);
1880 if ((my_dev
= sound_install_audiodrv(AUDIO_DRIVER_VERSION
,
1882 &ad1848_audio_driver
,
1883 sizeof(struct audio_driver
),
1885 ad_format_mask
[devc
->model
],
1895 audio_devs
[my_dev
]->portc
= portc
;
1896 audio_devs
[my_dev
]->mixer_dev
= -1;
1897 memset((char *) portc
, 0, sizeof(*portc
));
1901 ad1848_init_hw(devc
);
1905 devc
->dev_no
= my_dev
;
1906 if (request_irq(devc
->irq
, adintr
, 0, devc
->name
, (void *)my_dev
) < 0)
1908 printk(KERN_WARNING
"ad1848: Unable to allocate IRQ\n");
1909 /* Don't free it either then.. */
1912 if (capabilities
[devc
->model
].flags
& CAP_F_TIMER
)
1916 unsigned char tmp
= ad_read(devc
, 16);
1919 devc
->timer_ticks
= 0;
1921 ad_write(devc
, 21, 0x00); /* Timer MSB */
1922 ad_write(devc
, 20, 0x10); /* Timer LSB */
1924 ad_write(devc
, 16, tmp
| 0x40); /* Enable timer */
1925 for (x
= 0; x
< 100000 && devc
->timer_ticks
== 0; x
++);
1926 ad_write(devc
, 16, tmp
& ~0x40); /* Disable timer */
1928 if (devc
->timer_ticks
== 0)
1929 printk(KERN_WARNING
"ad1848: Interrupt test failed (IRQ%d)\n", irq
);
1932 DDB(printk("Interrupt test OK\n"));
1940 devc
->irq_ok
= 1; /* Couldn't test. assume it's OK */
1942 irq2dev
[-irq
] = devc
->dev_no
= my_dev
;
1944 #if defined(CONFIG_SEQUENCER) && !defined(EXCLUDE_TIMERS)
1945 if ((capabilities
[devc
->model
].flags
& CAP_F_TIMER
) &&
1947 ad1848_tmr_install(my_dev
);
1952 if (sound_alloc_dma(dma_playback
, devc
->name
))
1953 printk(KERN_WARNING
"ad1848.c: Can't allocate DMA%d\n", dma_playback
);
1955 if (dma_capture
!= dma_playback
)
1956 if (sound_alloc_dma(dma_capture
, devc
->name
))
1957 printk(KERN_WARNING
"ad1848.c: Can't allocate DMA%d\n", dma_capture
);
1959 if ((e
= sound_install_mixer(MIXER_DRIVER_VERSION
,
1961 &ad1848_mixer_operations
,
1962 sizeof(struct mixer_operations
),
1965 audio_devs
[my_dev
]->mixer_dev
= e
;
1970 int ad1848_control(int cmd
, int arg
)
1974 if (nr_ad1848_devs
< 1)
1977 devc
= &adev_info
[nr_ad1848_devs
- 1];
1981 case AD1848_SET_XTAL
: /* Change clock frequency of AD1845 (only ) */
1982 if (devc
->model
!= MD_1845
)
1985 ad_write(devc
, 29, (ad_read(devc
, 29) & 0x1f) | (arg
<< 5));
1989 case AD1848_MIXER_REROUTE
:
1991 int o
= (arg
>> 8) & 0xff;
1994 if (o
< 0 || o
>= SOUND_MIXER_NRDEVICES
)
1997 if (!(devc
->supported_devices
& (1 << o
)) &&
1998 !(devc
->supported_rec_devices
& (1 << o
)))
2001 if (n
== SOUND_MIXER_NONE
)
2002 { /* Just hide this control */
2003 ad1848_mixer_set(devc
, o
, 0); /* Shut up it */
2004 devc
->supported_devices
&= ~(1 << o
);
2005 devc
->supported_rec_devices
&= ~(1 << o
);
2009 /* Make the mixer control identified by o to appear as n */
2010 if (n
< 0 || n
>= SOUND_MIXER_NRDEVICES
)
2013 devc
->mixer_reroute
[n
] = o
; /* Rename the control */
2014 if (devc
->supported_devices
& (1 << o
))
2015 devc
->supported_devices
|= (1 << n
);
2016 if (devc
->supported_rec_devices
& (1 << o
))
2017 devc
->supported_rec_devices
|= (1 << n
);
2019 devc
->supported_devices
&= ~(1 << o
);
2020 devc
->supported_rec_devices
&= ~(1 << o
);
2027 void ad1848_unload(int io_base
, int irq
, int dma_playback
, int dma_capture
, int share_dma
)
2029 int i
, mixer
, dev
= 0;
2030 ad1848_info
*devc
= NULL
;
2032 for (i
= 0; devc
== NULL
&& i
< nr_ad1848_devs
; i
++)
2034 if (adev_info
[i
].base
== io_base
)
2036 devc
= &adev_info
[i
];
2043 if(audio_devs
[dev
]->portc
!=NULL
)
2044 kfree(audio_devs
[dev
]->portc
);
2045 release_region(devc
->base
, 4);
2049 if (devc
->irq
> 0) /* There is no point in freeing irq, if it wasn't allocated */
2050 free_irq(devc
->irq
, (void *)devc
->dev_no
);
2052 sound_free_dma(dma_playback
);
2054 if (dma_playback
!= dma_capture
)
2055 sound_free_dma(dma_capture
);
2058 mixer
= audio_devs
[devc
->dev_no
]->mixer_dev
;
2060 sound_unload_mixerdev(mixer
);
2063 for ( ; i
< nr_ad1848_devs
; i
++)
2064 adev_info
[i
] = adev_info
[i
+1];
2067 printk(KERN_ERR
"ad1848: Can't find device to be unloaded. Base=%x\n", io_base
);
2070 void adintr(int irq
, void *dev_id
, struct pt_regs
*dummy
)
2072 unsigned char status
;
2075 int alt_stat
= 0xff;
2076 unsigned char c930_stat
= 0;
2080 devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
2082 interrupt_again
: /* Jump back here if int status doesn't reset */
2084 status
= inb(io_Status(devc
));
2087 printk(KERN_DEBUG
"adintr: Why?\n");
2088 if (devc
->model
== MD_1848
)
2089 outb((0), io_Status(devc
)); /* Clear interrupt status */
2093 if (devc
->model
== MD_C930
)
2094 { /* 82C930 has interrupt status register in MAD16 register MC11 */
2095 unsigned long flags
;
2100 /* 0xe0e is C930 address port
2101 * 0xe0f is C930 data port
2104 c930_stat
= inb(0xe0f);
2105 outb((~c930_stat
), 0xe0f);
2107 restore_flags(flags
);
2109 alt_stat
= (c930_stat
<< 2) & 0x30;
2111 else if (devc
->model
!= MD_1848
)
2113 alt_stat
= ad_read(devc
, 24);
2114 ad_write(devc
, 24, ad_read(devc
, 24) & ~alt_stat
); /* Selective ack */
2117 if ((devc
->open_mode
& OPEN_READ
) && (devc
->audio_mode
& PCM_ENABLE_INPUT
) && (alt_stat
& 0x20))
2119 DMAbuf_inputintr(devc
->record_dev
);
2121 if ((devc
->open_mode
& OPEN_WRITE
) && (devc
->audio_mode
& PCM_ENABLE_OUTPUT
) &&
2124 DMAbuf_outputintr(devc
->playback_dev
, 1);
2126 if (devc
->model
!= MD_1848
&& (alt_stat
& 0x40)) /* Timer interrupt */
2128 devc
->timer_ticks
++;
2129 #if defined(CONFIG_SEQUENCER) && !defined(EXCLUDE_TIMERS)
2130 if (timer_installed
== dev
&& devc
->timer_running
)
2131 sound_timer_interrupt();
2136 * Sometimes playback or capture interrupts occur while a timer interrupt
2137 * is being handled. The interrupt will not be retriggered if we don't
2138 * handle it now. Check if an interrupt is still pending and restart
2139 * the handler in this case.
2141 if (inb(io_Status(devc
)) & 0x01 && cnt
++ < 4)
2143 goto interrupt_again
;
2148 * Experimental initialization sequence for the integrated sound system
2149 * of Compaq Deskpro XL.
2152 static int init_deskpro(struct address_info
*hw_config
)
2156 if ((tmp
= inb(0xc44)) == 0xff)
2158 DDB(printk("init_deskpro: Dead port 0xc44\n"));
2161 outb((tmp
| 0x04), 0xc44); /* Select bank 1 */
2162 if (inb(0xc44) != 0x04)
2164 DDB(printk("init_deskpro: Invalid bank1 signature in port 0xc44\n"));
2168 * OK. It looks like a Deskpro so let's proceed.
2172 * I/O port 0xc44 Audio configuration register.
2174 * bits 0xc0: Audio revision bits
2175 * 0x00 = Compaq Business Audio
2176 * 0x40 = MS Sound System Compatible (reset default)
2179 * bit 0x20: No Wait State Enable
2180 * 0x00 = Disabled (reset default, DMA mode)
2181 * 0x20 = Enabled (programmed I/O mode)
2182 * bit 0x10: MS Sound System Decode Enable
2183 * 0x00 = Decoding disabled (reset default)
2184 * 0x10 = Decoding enabled
2185 * bit 0x08: FM Synthesis Decode Enable
2186 * 0x00 = Decoding Disabled (reset default)
2187 * 0x08 = Decoding enabled
2188 * bit 0x04 Bank select
2191 * bits 0x03 MSS Base address
2192 * 0x00 = 0x530 (reset default)
2199 /* Debug printing */
2200 printk("Port 0xc44 (before): ");
2201 outb((tmp
& ~0x04), 0xc44);
2202 printk("%02x ", inb(0xc44));
2203 outb((tmp
| 0x04), 0xc44);
2204 printk("%02x\n", inb(0xc44));
2207 /* Set bank 1 of the register */
2208 tmp
= 0x58; /* MSS Mode, MSS&FM decode enabled */
2210 switch (hw_config
->io_base
)
2225 DDB(printk("init_deskpro: Invalid MSS port %x\n", hw_config
->io_base
));
2228 outb((tmp
& ~0x04), 0xc44); /* Write to bank=0 */
2231 /* Debug printing */
2232 printk("Port 0xc44 (after): ");
2233 outb((tmp
& ~0x04), 0xc44); /* Select bank=0 */
2234 printk("%02x ", inb(0xc44));
2235 outb((tmp
| 0x04), 0xc44); /* Select bank=1 */
2236 printk("%02x\n", inb(0xc44));
2240 * I/O port 0xc45 FM Address Decode/MSS ID Register.
2242 * bank=0, bits 0xfe: FM synthesis Decode Compare bits 7:1 (default=0x88)
2243 * bank=0, bit 0x01: SBIC Power Control Bit
2245 * 0x01 = Powered down
2246 * bank=1, bits 0xfc: MSS ID (default=0x40)
2250 /* Debug printing */
2251 printk("Port 0xc45 (before): ");
2252 outb((tmp
& ~0x04), 0xc44); /* Select bank=0 */
2253 printk("%02x ", inb(0xc45));
2254 outb((tmp
| 0x04), 0xc44); /* Select bank=1 */
2255 printk("%02x\n", inb(0xc45));
2258 outb((tmp
& ~0x04), 0xc44); /* Select bank=0 */
2259 outb((0x88), 0xc45); /* FM base 7:0 = 0x88 */
2260 outb((tmp
| 0x04), 0xc44); /* Select bank=1 */
2261 outb((0x10), 0xc45); /* MSS ID = 0x10 (MSS port returns 0x04) */
2264 /* Debug printing */
2265 printk("Port 0xc45 (after): ");
2266 outb((tmp
& ~0x04), 0xc44); /* Select bank=0 */
2267 printk("%02x ", inb(0xc45));
2268 outb((tmp
| 0x04), 0xc44); /* Select bank=1 */
2269 printk("%02x\n", inb(0xc45));
2274 * I/O port 0xc46 FM Address Decode/Address ASIC Revision Register.
2276 * bank=0, bits 0xff: FM synthesis Decode Compare bits 15:8 (default=0x03)
2277 * bank=1, bits 0xff: Audio addressing ASIC id
2281 /* Debug printing */
2282 printk("Port 0xc46 (before): ");
2283 outb((tmp
& ~0x04), 0xc44); /* Select bank=0 */
2284 printk("%02x ", inb(0xc46));
2285 outb((tmp
| 0x04), 0xc44); /* Select bank=1 */
2286 printk("%02x\n", inb(0xc46));
2289 outb((tmp
& ~0x04), 0xc44); /* Select bank=0 */
2290 outb((0x03), 0xc46); /* FM base 15:8 = 0x03 */
2291 outb((tmp
| 0x04), 0xc44); /* Select bank=1 */
2292 outb((0x11), 0xc46); /* ASIC ID = 0x11 */
2295 /* Debug printing */
2296 printk("Port 0xc46 (after): ");
2297 outb((tmp
& ~0x04), 0xc44); /* Select bank=0 */
2298 printk("%02x ", inb(0xc46));
2299 outb((tmp
| 0x04), 0xc44); /* Select bank=1 */
2300 printk("%02x\n", inb(0xc46));
2304 * I/O port 0xc47 FM Address Decode Register.
2306 * bank=0, bits 0xff: Decode enable selection for various FM address bits
2307 * bank=1, bits 0xff: Reserved
2311 /* Debug printing */
2312 printk("Port 0xc47 (before): ");
2313 outb((tmp
& ~0x04), 0xc44); /* Select bank=0 */
2314 printk("%02x ", inb(0xc47));
2315 outb((tmp
| 0x04), 0xc44); /* Select bank=1 */
2316 printk("%02x\n", inb(0xc47));
2319 outb((tmp
& ~0x04), 0xc44); /* Select bank=0 */
2320 outb((0x7c), 0xc47); /* FM decode enable bits = 0x7c */
2321 outb((tmp
| 0x04), 0xc44); /* Select bank=1 */
2322 outb((0x00), 0xc47); /* Reserved bank1 = 0x00 */
2325 /* Debug printing */
2326 printk("Port 0xc47 (after): ");
2327 outb((tmp
& ~0x04), 0xc44); /* Select bank=0 */
2328 printk("%02x ", inb(0xc47));
2329 outb((tmp
| 0x04), 0xc44); /* Select bank=1 */
2330 printk("%02x\n", inb(0xc47));
2334 * I/O port 0xc6f = Audio Disable Function Register
2338 printk("Port 0xc6f (before) = %02x\n", inb(0xc6f));
2341 outb((0x80), 0xc6f);
2344 printk("Port 0xc6f (after) = %02x\n", inb(0xc6f));
2350 int probe_ms_sound(struct address_info
*hw_config
)
2354 DDB(printk("Entered probe_ms_sound(%x, %d)\n", hw_config
->io_base
, hw_config
->card_subtype
));
2356 if (check_region(hw_config
->io_base
, 8))
2358 printk(KERN_ERR
"MSS: I/O port conflict\n");
2361 if (hw_config
->card_subtype
== 1) /* Has no IRQ/DMA registers */
2363 /* check_opl3(0x388, hw_config); */
2364 return ad1848_detect(hw_config
->io_base
+ 4, NULL
, hw_config
->osp
);
2367 if (deskpro_xl
&& hw_config
->card_subtype
== 2) /* Compaq Deskpro XL */
2369 if (!init_deskpro(hw_config
))
2374 * Check if the IO port returns valid signature. The original MS Sound
2375 * system returns 0x04 while some cards (AudioTrix Pro for example)
2376 * return 0x00 or 0x0f.
2379 if ((tmp
= inb(hw_config
->io_base
+ 3)) == 0xff) /* Bus float */
2383 DDB(printk("I/O address is inactive (%x)\n", tmp
));
2384 if (!(ret
= ad1848_detect(hw_config
->io_base
+ 4, NULL
, hw_config
->osp
)))
2388 DDB(printk("MSS signature = %x\n", tmp
& 0x3f));
2389 if ((tmp
& 0x3f) != 0x04 &&
2390 (tmp
& 0x3f) != 0x0f &&
2391 (tmp
& 0x3f) != 0x00)
2395 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)));
2396 DDB(printk("Trying to detect codec anyway but IRQ/DMA may not work\n"));
2397 if (!(ret
= ad1848_detect(hw_config
->io_base
+ 4, NULL
, hw_config
->osp
)))
2400 hw_config
->card_subtype
= 1;
2403 if ((hw_config
->irq
!= 5) &&
2404 (hw_config
->irq
!= 7) &&
2405 (hw_config
->irq
!= 9) &&
2406 (hw_config
->irq
!= 10) &&
2407 (hw_config
->irq
!= 11) &&
2408 (hw_config
->irq
!= 12))
2410 printk(KERN_ERR
"MSS: Bad IRQ %d\n", hw_config
->irq
);
2413 if (hw_config
->dma
!= 0 && hw_config
->dma
!= 1 && hw_config
->dma
!= 3)
2415 printk(KERN_ERR
"MSS: Bad DMA %d\n", hw_config
->dma
);
2419 * Check that DMA0 is not in use with a 8 bit board.
2422 if (hw_config
->dma
== 0 && inb(hw_config
->io_base
+ 3) & 0x80)
2424 printk(KERN_ERR
"MSS: Can't use DMA0 with a 8 bit card/slot\n");
2427 if (hw_config
->irq
> 7 && hw_config
->irq
!= 9 && inb(hw_config
->io_base
+ 3) & 0x80)
2429 printk(KERN_ERR
"MSS: Can't use IRQ%d with a 8 bit card/slot\n", hw_config
->irq
);
2432 return ad1848_detect(hw_config
->io_base
+ 4, NULL
, hw_config
->osp
);
2435 void attach_ms_sound(struct address_info
*hw_config
)
2437 static char interrupt_bits
[12] =
2439 -1, -1, -1, -1, -1, 0x00, -1, 0x08, -1, 0x10, 0x18, 0x20
2441 char bits
, dma2_bit
= 0;
2443 static char dma_bits
[4] =
2448 int config_port
= hw_config
->io_base
+ 0;
2449 int version_port
= hw_config
->io_base
+ 3;
2450 int dma
= hw_config
->dma
;
2451 int dma2
= hw_config
->dma2
;
2453 if (hw_config
->card_subtype
== 1) /* Has no IRQ/DMA registers */
2455 hw_config
->slots
[0] = ad1848_init("MS Sound System", hw_config
->io_base
+ 4,
2458 hw_config
->dma2
, 0, hw_config
->osp
);
2459 request_region(hw_config
->io_base
, 4, "WSS config");
2463 * Set the IRQ and DMA addresses.
2466 bits
= interrupt_bits
[hw_config
->irq
];
2469 printk(KERN_ERR
"MSS: Bad IRQ %d\n", hw_config
->irq
);
2472 outb((bits
| 0x40), config_port
);
2473 if ((inb(version_port
) & 0x40) == 0)
2474 printk(KERN_ERR
"[MSS: IRQ Conflict?]\n");
2477 * Handle the capture DMA channel
2480 if (dma2
!= -1 && dma2
!= dma
)
2482 if (!((dma
== 0 && dma2
== 1) ||
2483 (dma
== 1 && dma2
== 0) ||
2484 (dma
== 3 && dma2
== 0)))
2485 { /* Unsupported combination. Try to swap channels */
2491 if ((dma
== 0 && dma2
== 1) ||
2492 (dma
== 1 && dma2
== 0) ||
2493 (dma
== 3 && dma2
== 0))
2495 dma2_bit
= 0x04; /* Enable capture DMA */
2499 printk(KERN_WARNING
"MSS: Invalid capture DMA\n");
2508 hw_config
->dma
= dma
;
2509 hw_config
->dma2
= dma2
;
2511 outb((bits
| dma_bits
[dma
] | dma2_bit
), config_port
); /* Write IRQ+DMA setup */
2513 hw_config
->slots
[0] = ad1848_init("MSS audio codec", hw_config
->io_base
+ 4,
2518 request_region(hw_config
->io_base
, 4, "WSS config");
2521 void unload_ms_sound(struct address_info
*hw_config
)
2523 ad1848_unload(hw_config
->io_base
+ 4,
2526 hw_config
->dma2
, 0);
2527 sound_unload_audiodev(hw_config
->slots
[0]);
2528 release_region(hw_config
->io_base
, 4);
2531 #if defined(CONFIG_SEQUENCER) && !defined(EXCLUDE_TIMERS)
2534 * Timer stuff (for /dev/music).
2537 static unsigned int current_interval
= 0;
2539 static unsigned int ad1848_tmr_start(int dev
, unsigned int usecs
)
2541 unsigned long flags
;
2542 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
2543 unsigned long xtal_nsecs
; /* nanoseconds per xtal oscillator tick */
2544 unsigned long divider
;
2550 * Length of the timer interval (in nanoseconds) depends on the
2551 * selected crystal oscillator. Check this from bit 0x01 of I8.
2553 * AD1845 has just one oscillator which has cycle time of 10.050 us
2554 * (when a 24.576 MHz xtal oscillator is used).
2556 * Convert requested interval to nanoseconds before computing
2557 * the timer divider.
2560 if (devc
->model
== MD_1845
)
2562 else if (ad_read(devc
, 8) & 0x01)
2567 divider
= (usecs
* 1000 + xtal_nsecs
/ 2) / xtal_nsecs
;
2569 if (divider
< 100) /* Don't allow shorter intervals than about 1ms */
2572 if (divider
> 65535) /* Overflow check */
2575 ad_write(devc
, 21, (divider
>> 8) & 0xff); /* Set upper bits */
2576 ad_write(devc
, 20, divider
& 0xff); /* Set lower bits */
2577 ad_write(devc
, 16, ad_read(devc
, 16) | 0x40); /* Start the timer */
2578 devc
->timer_running
= 1;
2579 restore_flags(flags
);
2581 return current_interval
= (divider
* xtal_nsecs
+ 500) / 1000;
2584 static void ad1848_tmr_reprogram(int dev
)
2587 * Audio driver has changed sampling rate so that a different xtal
2588 * oscillator was selected. We have to reprogram the timer rate.
2591 ad1848_tmr_start(dev
, current_interval
);
2592 sound_timer_syncinterval(current_interval
);
2595 static void ad1848_tmr_disable(int dev
)
2597 unsigned long flags
;
2598 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
2602 ad_write(devc
, 16, ad_read(devc
, 16) & ~0x40);
2603 devc
->timer_running
= 0;
2604 restore_flags(flags
);
2607 static void ad1848_tmr_restart(int dev
)
2609 unsigned long flags
;
2610 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
2612 if (current_interval
== 0)
2617 ad_write(devc
, 16, ad_read(devc
, 16) | 0x40);
2618 devc
->timer_running
= 1;
2619 restore_flags(flags
);
2622 static struct sound_lowlev_timer ad1848_tmr
=
2631 static int ad1848_tmr_install(int dev
)
2633 if (timer_installed
!= -1)
2634 return 0; /* Don't install another timer */
2636 timer_installed
= ad1848_tmr
.dev
= dev
;
2637 sound_timer_init(&ad1848_tmr
, audio_devs
[dev
]->name
);
2644 EXPORT_SYMBOL(ad1848_detect
);
2645 EXPORT_SYMBOL(ad1848_init
);
2646 EXPORT_SYMBOL(ad1848_unload
);
2647 EXPORT_SYMBOL(ad1848_control
);
2648 EXPORT_SYMBOL(adintr
);
2649 EXPORT_SYMBOL(probe_ms_sound
);
2650 EXPORT_SYMBOL(attach_ms_sound
);
2651 EXPORT_SYMBOL(unload_ms_sound
);
2655 MODULE_PARM(io
, "i"); /* I/O for a raw AD1848 card */
2656 MODULE_PARM(irq
, "i"); /* IRQ to use */
2657 MODULE_PARM(dma
, "i"); /* First DMA channel */
2658 MODULE_PARM(dma2
, "i"); /* Second DMA channel */
2659 MODULE_PARM(type
, "i"); /* Card type */
2660 MODULE_PARM(deskpro_xl
, "i"); /* Special magic for Deskpro XL boxen */
2661 MODULE_PARM(soundpro
, "i"); /* More special magic for SoundPro chips */
2669 static int loaded
= 0;
2671 struct address_info hw_config
;
2673 int init_module(void)
2675 printk(KERN_INFO
"ad1848/cs4248 codec driver Copyright (C) by Hannu Savolainen 1993-1996\n");
2678 if(irq
== -1 || dma
== -1)
2680 printk(KERN_WARNING
"ad1848: must give I/O , IRQ and DMA.\n");
2683 hw_config
.irq
= irq
;
2684 hw_config
.io_base
= io
;
2685 hw_config
.dma
= dma
;
2686 hw_config
.dma2
= dma2
;
2687 hw_config
.card_subtype
= type
;
2688 if(!probe_ms_sound(&hw_config
))
2690 attach_ms_sound(&hw_config
);
2697 void cleanup_module(void)
2701 unload_ms_sound(&hw_config
);