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 */
75 #define MD_1845_SSCAPE 9 /* Ensoniq Soundscape PNP*/
77 /* Mixer parameters */
79 int supported_devices
, orig_devices
;
80 int supported_rec_devices
, orig_rec_devices
;
82 short mixer_reroute
[32];
84 volatile unsigned long timer_ticks
;
87 mixer_ents
*mix_devices
;
88 int mixer_output_port
;
91 typedef struct ad1848_port_info
95 unsigned char speed_bits
;
98 unsigned char format_bits
;
102 static int nr_ad1848_devs
= 0;
105 #ifdef CONFIG_SOUND_SPRO
111 static volatile signed char irq2dev
[17] = {
112 -1, -1, -1, -1, -1, -1, -1, -1,
113 -1, -1, -1, -1, -1, -1, -1, -1, -1
116 #if defined(CONFIG_SEQUENCER) && !defined(EXCLUDE_TIMERS) || defined(MODULE)
118 static int timer_installed
= -1;
122 static int ad_format_mask
[10 /*devc->model */ ] =
125 AFMT_U8
| AFMT_S16_LE
| AFMT_MU_LAW
| AFMT_A_LAW
,
126 AFMT_U8
| AFMT_S16_LE
| AFMT_MU_LAW
| AFMT_A_LAW
| AFMT_S16_BE
| AFMT_IMA_ADPCM
,
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
, /* AD1845 */
129 AFMT_U8
| AFMT_S16_LE
| AFMT_MU_LAW
| AFMT_A_LAW
| AFMT_S16_BE
| AFMT_IMA_ADPCM
,
130 AFMT_U8
| AFMT_S16_LE
| AFMT_MU_LAW
| AFMT_A_LAW
| AFMT_S16_BE
| AFMT_IMA_ADPCM
,
131 AFMT_U8
| AFMT_S16_LE
| AFMT_MU_LAW
| AFMT_A_LAW
| AFMT_S16_BE
| AFMT_IMA_ADPCM
,
132 AFMT_U8
| AFMT_S16_LE
/* CS4235 */,
133 AFMT_U8
| AFMT_S16_LE
| AFMT_MU_LAW
| AFMT_A_LAW
/* Ensoniq Soundscape*/
136 static ad1848_info adev_info
[MAX_AUDIO_DEV
];
138 #define io_Index_Addr(d) ((d)->base)
139 #define io_Indexed_Data(d) ((d)->base+1)
140 #define io_Status(d) ((d)->base+2)
141 #define io_Polled_IO(d) ((d)->base+3)
145 #define CAP_F_TIMER 0x01
146 } capabilities
[10 /*devc->model */ ] = {
149 ,{CAP_F_TIMER
} /* MD_4231 */
150 ,{CAP_F_TIMER
} /* MD_4231A */
151 ,{CAP_F_TIMER
} /* MD_1845 */
152 ,{CAP_F_TIMER
} /* MD_4232 */
154 ,{CAP_F_TIMER
} /* MD_IWAVE */
156 ,{CAP_F_TIMER
} /* MD_1845_SSCAPE */
159 static int ad1848_open(int dev
, int mode
);
160 static void ad1848_close(int dev
);
161 static void ad1848_output_block(int dev
, unsigned long buf
, int count
, int intrflag
);
162 static void ad1848_start_input(int dev
, unsigned long buf
, int count
, int intrflag
);
163 static int ad1848_prepare_for_output(int dev
, int bsize
, int bcount
);
164 static int ad1848_prepare_for_input(int dev
, int bsize
, int bcount
);
165 static void ad1848_halt(int dev
);
166 static void ad1848_halt_input(int dev
);
167 static void ad1848_halt_output(int dev
);
168 static void ad1848_trigger(int dev
, int bits
);
170 #if defined(CONFIG_SEQUENCER) && !defined(EXCLUDE_TIMERS)
171 static int ad1848_tmr_install(int dev
);
172 static void ad1848_tmr_reprogram(int dev
);
176 static int ad_read(ad1848_info
* devc
, int reg
)
180 int timeout
= 900000;
182 while (timeout
> 0 && inb(devc
->base
) == 0x80) /*Are we initializing */
187 outb(((unsigned char) (reg
& 0xff) | devc
->MCE_bit
), io_Index_Addr(devc
));
188 x
= inb(io_Indexed_Data(devc
));
189 /* printk("(%02x<-%02x) ", reg|devc->MCE_bit, x); */
190 restore_flags(flags
);
195 static void ad_write(ad1848_info
* devc
, int reg
, int data
)
198 int timeout
= 900000;
200 while (timeout
> 0 && inb(devc
->base
) == 0x80) /* Are we initializing */
205 outb(((unsigned char) (reg
& 0xff) | devc
->MCE_bit
), io_Index_Addr(devc
));
206 outb(((unsigned char) (data
& 0xff)), io_Indexed_Data(devc
));
207 /* printk("(%02x->%02x) ", reg|devc->MCE_bit, data); */
208 restore_flags(flags
);
211 static void wait_for_calibration(ad1848_info
* devc
)
216 * Wait until the auto calibration process has finished.
218 * 1) Wait until the chip becomes ready (reads don't return 0x80).
219 * 2) Wait until the ACI bit of I11 gets on and then off.
223 while (timeout
> 0 && inb(devc
->base
) == 0x80)
225 if (inb(devc
->base
) & 0x80)
226 printk(KERN_WARNING
"ad1848: Auto calibration timed out(1).\n");
229 while (timeout
> 0 && !(ad_read(devc
, 11) & 0x20))
231 if (!(ad_read(devc
, 11) & 0x20))
235 while (timeout
> 0 && (ad_read(devc
, 11) & 0x20))
237 if (ad_read(devc
, 11) & 0x20)
238 if ( (devc
->model
!= MD_1845
) || (devc
->model
!= MD_1845_SSCAPE
))
239 printk(KERN_WARNING
"ad1848: Auto calibration timed out(3).\n");
242 static void ad_mute(ad1848_info
* devc
)
248 * Save old register settings and mute output channels
251 for (i
= 6; i
< 8; i
++)
253 prev
= devc
->saved_regs
[i
] = ad_read(devc
, i
);
258 static void ad_unmute(ad1848_info
* devc
)
262 static void ad_enter_MCE(ad1848_info
* devc
)
268 while (timeout
> 0 && inb(devc
->base
) == 0x80) /*Are we initializing */
274 devc
->MCE_bit
= 0x40;
275 prev
= inb(io_Index_Addr(devc
));
278 restore_flags(flags
);
281 outb((devc
->MCE_bit
), io_Index_Addr(devc
));
282 restore_flags(flags
);
285 static void ad_leave_MCE(ad1848_info
* devc
)
288 unsigned char prev
, acal
;
291 while (timeout
> 0 && inb(devc
->base
) == 0x80) /*Are we initializing */
297 acal
= ad_read(devc
, 9);
299 devc
->MCE_bit
= 0x00;
300 prev
= inb(io_Index_Addr(devc
));
301 outb((0x00), io_Index_Addr(devc
)); /* Clear the MCE bit */
303 if ((prev
& 0x40) == 0) /* Not in MCE mode */
305 restore_flags(flags
);
308 outb((0x00), io_Index_Addr(devc
)); /* Clear the MCE bit */
309 if (acal
& 0x08) /* Auto calibration is enabled */
310 wait_for_calibration(devc
);
311 restore_flags(flags
);
314 static int ad1848_set_recmask(ad1848_info
* devc
, int mask
)
316 unsigned char recdev
;
319 mask
&= devc
->supported_rec_devices
;
321 /* Rename the mixer bits if necessary */
322 for (i
= 0; i
< 32; i
++)
324 if (devc
->mixer_reroute
[i
] != i
)
329 mask
|= (1 << devc
->mixer_reroute
[i
]);
335 for (i
= 0; i
< 32; i
++) /* Count selected device bits */
341 mask
= SOUND_MASK_MIC
;
342 else if (n
!= 1) { /* Too many devices selected */
343 mask
&= ~devc
->recmask
; /* Filter out active settings */
346 for (i
= 0; i
< 32; i
++) /* Count selected device bits */
351 mask
= SOUND_MASK_MIC
;
358 case SOUND_MASK_LINE
:
359 case SOUND_MASK_LINE3
:
364 case SOUND_MASK_LINE1
:
368 case SOUND_MASK_IMIX
:
373 mask
= SOUND_MASK_MIC
;
378 ad_write(devc
, 0, (ad_read(devc
, 0) & 0x3f) | recdev
);
379 ad_write(devc
, 1, (ad_read(devc
, 1) & 0x3f) | recdev
);
380 } else { /* soundpro */
385 for (i
= 0; i
< 32; i
++) { /* For each bit */
386 if ((devc
->supported_rec_devices
& (1 << i
)) == 0)
387 continue; /* Device not supported */
389 for (j
= LEFT_CHN
; j
<= RIGHT_CHN
; j
++) {
390 if (devc
->mix_devices
[i
][j
].nbits
== 0) /* Inexistent channel */
395 * set_rec_bit becomes 1 if the corresponding bit in mask is set
396 * then it gets flipped if the polarity is inverse
398 set_rec_bit
= ((mask
& (1 << i
)) != 0) ^ devc
->mix_devices
[i
][j
].recpol
;
400 val
= ad_read(devc
, devc
->mix_devices
[i
][j
].recreg
);
401 val
&= ~(1 << devc
->mix_devices
[i
][j
].recpos
);
402 val
|= (set_rec_bit
<< devc
->mix_devices
[i
][j
].recpos
);
403 ad_write(devc
, devc
->mix_devices
[i
][j
].recreg
, val
);
408 /* Rename the mixer bits back if necessary */
409 for (i
= 0; i
< 32; i
++)
411 if (devc
->mixer_reroute
[i
] != i
)
413 if (mask
& (1 << devc
->mixer_reroute
[i
]))
415 mask
&= ~(1 << devc
->mixer_reroute
[i
]);
420 devc
->recmask
= mask
;
424 static void change_bits(ad1848_info
* devc
, unsigned char *regval
,
425 unsigned char *muteval
, int dev
, int chn
, int newval
)
433 set_mute_bit
= (newval
== 0) ^ devc
->mix_devices
[dev
][chn
].mutepol
;
435 if (devc
->mix_devices
[dev
][chn
].polarity
== 1) /* Reverse */
436 newval
= 100 - newval
;
438 mask
= (1 << devc
->mix_devices
[dev
][chn
].nbits
) - 1;
439 shift
= devc
->mix_devices
[dev
][chn
].bitpos
;
441 if (devc
->mix_devices
[dev
][chn
].mutepos
== 8)
442 { /* if there is no mute bit */
443 mute
= 0; /* No mute bit; do nothing special */
444 mutemask
= ~0; /* No mute bit; do nothing special */
448 mute
= (set_mute_bit
<< devc
->mix_devices
[dev
][chn
].mutepos
);
449 mutemask
= ~(1 << devc
->mix_devices
[dev
][chn
].mutepos
);
452 newval
= (int) ((newval
* mask
) + 50) / 100; /* Scale it */
453 *regval
&= ~(mask
<< shift
); /* Clear bits */
454 *regval
|= (newval
& mask
) << shift
; /* Set new value */
456 *muteval
&= mutemask
;
460 static int ad1848_mixer_get(ad1848_info
* devc
, int dev
)
462 if (!((1 << dev
) & devc
->supported_devices
))
465 dev
= devc
->mixer_reroute
[dev
];
467 return devc
->levels
[dev
];
470 static void ad1848_mixer_set_channel(ad1848_info
*devc
, int dev
, int value
, int channel
)
472 int regoffs
, muteregoffs
;
473 unsigned char val
, muteval
;
475 regoffs
= devc
->mix_devices
[dev
][channel
].regno
;
476 muteregoffs
= devc
->mix_devices
[dev
][channel
].mutereg
;
477 val
= ad_read(devc
, regoffs
);
479 if (muteregoffs
!= regoffs
) {
480 muteval
= ad_read(devc
, muteregoffs
);
481 change_bits(devc
, &val
, &muteval
, dev
, channel
, value
);
484 change_bits(devc
, &val
, &val
, dev
, channel
, value
);
486 ad_write(devc
, regoffs
, val
);
487 devc
->saved_regs
[regoffs
] = val
;
488 if (muteregoffs
!= regoffs
) {
489 ad_write(devc
, muteregoffs
, muteval
);
490 devc
->saved_regs
[muteregoffs
] = muteval
;
494 static int ad1848_mixer_set(ad1848_info
* devc
, int dev
, int value
)
496 int left
= value
& 0x000000ff;
497 int right
= (value
& 0x0000ff00) >> 8;
503 if (!(devc
->supported_devices
& (1 << dev
)))
506 dev
= devc
->mixer_reroute
[dev
];
508 if (devc
->mix_devices
[dev
][LEFT_CHN
].nbits
== 0)
516 if (devc
->mix_devices
[dev
][RIGHT_CHN
].nbits
== 0) /* Mono control */
519 retvol
= left
| (right
<< 8);
522 left
= mix_cvt
[left
];
523 right
= mix_cvt
[right
];
525 devc
->levels
[dev
] = retvol
;
528 * Set the left channel
530 ad1848_mixer_set_channel(devc
, dev
, left
, LEFT_CHN
);
533 * Set the right channel
535 if (devc
->mix_devices
[dev
][RIGHT_CHN
].nbits
== 0)
537 ad1848_mixer_set_channel(devc
, dev
, right
, RIGHT_CHN
);
543 static void ad1848_mixer_reset(ad1848_info
* devc
)
548 devc
->mix_devices
= &(ad1848_mix_devices
[0]);
550 sprintf(name
, "%s_%d", devc
->chip_name
, nr_ad1848_devs
);
552 for (i
= 0; i
< 32; i
++)
553 devc
->mixer_reroute
[i
] = i
;
555 devc
->supported_rec_devices
= MODE1_REC_DEVICES
;
563 devc
->supported_devices
= MODE2_MIXER_DEVICES
;
567 devc
->supported_devices
= C930_MIXER_DEVICES
;
568 devc
->mix_devices
= &(c930_mix_devices
[0]);
572 devc
->supported_devices
= MODE3_MIXER_DEVICES
;
573 devc
->mix_devices
= &(iwave_mix_devices
[0]);
577 devc
->supported_devices
= MODE3_MIXER_DEVICES
;
582 devc
->supported_devices
= SPRO_MIXER_DEVICES
;
583 devc
->supported_rec_devices
= SPRO_REC_DEVICES
;
584 devc
->mix_devices
= &(spro_mix_devices
[0]);
589 devc
->supported_devices
= MODE1_MIXER_DEVICES
;
592 devc
->orig_devices
= devc
->supported_devices
;
593 devc
->orig_rec_devices
= devc
->supported_rec_devices
;
595 devc
->levels
= load_mixer_volumes(name
, default_mixer_levels
, 1);
597 for (i
= 0; i
< SOUND_MIXER_NRDEVICES
; i
++)
599 if (devc
->supported_devices
& (1 << i
))
600 ad1848_mixer_set(devc
, i
, devc
->levels
[i
]);
603 ad1848_set_recmask(devc
, SOUND_MASK_MIC
);
605 devc
->mixer_output_port
= devc
->levels
[31] | AUDIO_HEADPHONE
| AUDIO_LINE_OUT
;
608 if (devc
->mixer_output_port
& AUDIO_SPEAKER
)
609 ad_write(devc
, 26, ad_read(devc
, 26) & ~0x40); /* Unmute mono out */
611 ad_write(devc
, 26, ad_read(devc
, 26) | 0x40); /* Mute mono out */
614 * From the "wouldn't it be nice if the mixer API had (better)
615 * support for custom stuff" category
617 /* Enable surround mode and SB16 mixer */
618 ad_write(devc
, 16, 0x60);
622 static int ad1848_mixer_ioctl(int dev
, unsigned int cmd
, caddr_t arg
)
624 ad1848_info
*devc
= mixer_devs
[dev
]->devc
;
627 if (cmd
== SOUND_MIXER_PRIVATE1
)
629 if (get_user(val
, (int *)arg
))
634 val
&= (AUDIO_SPEAKER
| AUDIO_HEADPHONE
| AUDIO_LINE_OUT
);
635 devc
->mixer_output_port
= val
;
636 val
|= AUDIO_HEADPHONE
| AUDIO_LINE_OUT
; /* Always on */
637 devc
->mixer_output_port
= val
;
638 if (val
& AUDIO_SPEAKER
)
639 ad_write(devc
, 26, ad_read(devc
, 26) & ~0x40); /* Unmute mono out */
641 ad_write(devc
, 26, ad_read(devc
, 26) | 0x40); /* Mute mono out */
643 val
= devc
->mixer_output_port
;
644 return put_user(val
, (int *)arg
);
646 if (cmd
== SOUND_MIXER_PRIVATE2
)
648 if (get_user(val
, (int *)arg
))
650 return(ad1848_control(AD1848_MIXER_REROUTE
, val
));
652 if (((cmd
>> 8) & 0xff) == 'M')
654 if (_SIOC_DIR(cmd
) & _SIOC_WRITE
)
658 case SOUND_MIXER_RECSRC
:
659 if (get_user(val
, (int *)arg
))
661 val
= ad1848_set_recmask(devc
, val
);
665 if (get_user(val
, (int *)arg
))
667 val
= ad1848_mixer_set(devc
, cmd
& 0xff, val
);
670 return put_user(val
, (int *)arg
);
680 case SOUND_MIXER_RECSRC
:
684 case SOUND_MIXER_DEVMASK
:
685 val
= devc
->supported_devices
;
688 case SOUND_MIXER_STEREODEVS
:
689 val
= devc
->supported_devices
;
690 if (devc
->model
!= MD_C930
)
691 val
&= ~(SOUND_MASK_SPEAKER
| SOUND_MASK_IMIX
);
694 case SOUND_MIXER_RECMASK
:
695 val
= devc
->supported_rec_devices
;
698 case SOUND_MIXER_CAPS
:
699 val
=SOUND_CAP_EXCL_INPUT
;
703 val
= ad1848_mixer_get(devc
, cmd
& 0xff);
706 return put_user(val
, (int *)arg
);
713 static int ad1848_set_speed(int dev
, int arg
)
715 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
716 ad1848_port_info
*portc
= (ad1848_port_info
*) audio_devs
[dev
]->portc
;
719 * The sampling speed is encoded in the least significant nibble of I8. The
720 * LSB selects the clock source (0=24.576 MHz, 1=16.9344 MHz) and other
721 * three bits select the divisor (indirectly):
723 * The available speeds are in the following table. Keep the speeds in
724 * the increasing order.
733 static speed_struct speed_table
[] =
735 {5510, (0 << 1) | 1},
736 {5510, (0 << 1) | 1},
737 {6620, (7 << 1) | 1},
738 {8000, (0 << 1) | 0},
739 {9600, (7 << 1) | 0},
740 {11025, (1 << 1) | 1},
741 {16000, (1 << 1) | 0},
742 {18900, (2 << 1) | 1},
743 {22050, (3 << 1) | 1},
744 {27420, (2 << 1) | 0},
745 {32000, (3 << 1) | 0},
746 {33075, (6 << 1) | 1},
747 {37800, (4 << 1) | 1},
748 {44100, (5 << 1) | 1},
749 {48000, (6 << 1) | 0}
752 int i
, n
, selected
= -1;
754 n
= sizeof(speed_table
) / sizeof(speed_struct
);
759 if (devc
->model
== MD_1845
|| devc
->model
== MD_1845_SSCAPE
) /* AD1845 has different timer than others */
767 portc
->speed_bits
= speed_table
[3].bits
;
770 if (arg
< speed_table
[0].speed
)
772 if (arg
> speed_table
[n
- 1].speed
)
775 for (i
= 1 /*really */ ; selected
== -1 && i
< n
; i
++)
777 if (speed_table
[i
].speed
== arg
)
779 else if (speed_table
[i
].speed
> arg
)
783 diff1
= arg
- speed_table
[i
- 1].speed
;
784 diff2
= speed_table
[i
].speed
- arg
;
794 printk(KERN_WARNING
"ad1848: Can't find speed???\n");
797 portc
->speed
= speed_table
[selected
].speed
;
798 portc
->speed_bits
= speed_table
[selected
].bits
;
802 static short ad1848_set_channels(int dev
, short arg
)
804 ad1848_port_info
*portc
= (ad1848_port_info
*) audio_devs
[dev
]->portc
;
806 if (arg
!= 1 && arg
!= 2)
807 return portc
->channels
;
809 portc
->channels
= arg
;
813 static unsigned int ad1848_set_bits(int dev
, unsigned int arg
)
815 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
816 ad1848_port_info
*portc
= (ad1848_port_info
*) audio_devs
[dev
]->portc
;
818 static struct format_tbl
865 int i
, n
= sizeof(format2bits
) / sizeof(struct format_tbl
);
868 return portc
->audio_format
;
870 if (!(arg
& ad_format_mask
[devc
->model
]))
873 portc
->audio_format
= arg
;
875 for (i
= 0; i
< n
; i
++)
876 if (format2bits
[i
].format
== arg
)
878 if ((portc
->format_bits
= format2bits
[i
].bits
) == 0)
879 return portc
->audio_format
= AFMT_U8
; /* Was not supported */
883 /* Still hanging here. Something must be terribly wrong */
884 portc
->format_bits
= 0;
885 return portc
->audio_format
= AFMT_U8
;
888 static struct audio_driver ad1848_audio_driver
=
895 ad1848_prepare_for_input
,
896 ad1848_prepare_for_output
,
908 static struct mixer_operations ad1848_mixer_operations
=
911 "AD1848/CS4248/CS4231",
915 static int ad1848_open(int dev
, int mode
)
917 ad1848_info
*devc
= NULL
;
918 ad1848_port_info
*portc
;
921 if (dev
< 0 || dev
>= num_audiodevs
)
924 devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
925 portc
= (ad1848_port_info
*) audio_devs
[dev
]->portc
;
929 if (portc
->open_mode
|| (devc
->open_mode
& mode
))
931 restore_flags(flags
);
936 if (audio_devs
[dev
]->flags
& DMA_DUPLEX
)
940 devc
->intr_active
= 0;
941 devc
->audio_mode
= 0;
942 devc
->open_mode
|= mode
;
943 portc
->open_mode
= mode
;
944 ad1848_trigger(dev
, 0);
946 if (mode
& OPEN_READ
)
947 devc
->record_dev
= dev
;
948 if (mode
& OPEN_WRITE
)
949 devc
->playback_dev
= dev
;
950 restore_flags(flags
);
952 * Mute output until the playback really starts. This decreases clicking (hope so).
959 static void ad1848_close(int dev
)
962 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
963 ad1848_port_info
*portc
= (ad1848_port_info
*) audio_devs
[dev
]->portc
;
965 DEB(printk("ad1848_close(void)\n"));
970 devc
->intr_active
= 0;
973 devc
->audio_mode
= 0;
974 devc
->open_mode
&= ~portc
->open_mode
;
975 portc
->open_mode
= 0;
978 restore_flags(flags
);
981 static void ad1848_output_block(int dev
, unsigned long buf
, int count
, int intrflag
)
983 unsigned long flags
, cnt
;
984 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
985 ad1848_port_info
*portc
= (ad1848_port_info
*) audio_devs
[dev
]->portc
;
989 if (portc
->audio_format
== AFMT_IMA_ADPCM
)
995 if (portc
->audio_format
& (AFMT_S16_LE
| AFMT_S16_BE
)) /* 16 bit data */
998 if (portc
->channels
> 1)
1002 if ((devc
->audio_mode
& PCM_ENABLE_OUTPUT
) && (audio_devs
[dev
]->flags
& DMA_AUTOMODE
) &&
1004 cnt
== devc
->xfer_count
)
1006 devc
->audio_mode
|= PCM_ENABLE_OUTPUT
;
1007 devc
->intr_active
= 1;
1009 * Auto DMA mode on. No need to react
1015 ad_write(devc
, 15, (unsigned char) (cnt
& 0xff));
1016 ad_write(devc
, 14, (unsigned char) ((cnt
>> 8) & 0xff));
1018 devc
->xfer_count
= cnt
;
1019 devc
->audio_mode
|= PCM_ENABLE_OUTPUT
;
1020 devc
->intr_active
= 1;
1021 restore_flags(flags
);
1024 static void ad1848_start_input(int dev
, unsigned long buf
, int count
, int intrflag
)
1026 unsigned long flags
, cnt
;
1027 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
1028 ad1848_port_info
*portc
= (ad1848_port_info
*) audio_devs
[dev
]->portc
;
1031 if (portc
->audio_format
== AFMT_IMA_ADPCM
)
1037 if (portc
->audio_format
& (AFMT_S16_LE
| AFMT_S16_BE
)) /* 16 bit data */
1040 if (portc
->channels
> 1)
1044 if ((devc
->audio_mode
& PCM_ENABLE_INPUT
) && (audio_devs
[dev
]->flags
& DMA_AUTOMODE
) &&
1046 cnt
== devc
->xfer_count
)
1048 devc
->audio_mode
|= PCM_ENABLE_INPUT
;
1049 devc
->intr_active
= 1;
1051 * Auto DMA mode on. No need to react
1057 if (devc
->model
== MD_1848
)
1059 ad_write(devc
, 15, (unsigned char) (cnt
& 0xff));
1060 ad_write(devc
, 14, (unsigned char) ((cnt
>> 8) & 0xff));
1064 ad_write(devc
, 31, (unsigned char) (cnt
& 0xff));
1065 ad_write(devc
, 30, (unsigned char) ((cnt
>> 8) & 0xff));
1070 devc
->xfer_count
= cnt
;
1071 devc
->audio_mode
|= PCM_ENABLE_INPUT
;
1072 devc
->intr_active
= 1;
1073 restore_flags(flags
);
1076 static int ad1848_prepare_for_output(int dev
, int bsize
, int bcount
)
1079 unsigned char fs
, old_fs
, tmp
= 0;
1080 unsigned long flags
;
1081 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
1082 ad1848_port_info
*portc
= (ad1848_port_info
*) audio_devs
[dev
]->portc
;
1088 fs
= portc
->speed_bits
| (portc
->format_bits
<< 5);
1090 if (portc
->channels
> 1)
1093 ad_enter_MCE(devc
); /* Enables changes to the format select reg */
1095 if (devc
->model
== MD_1845
|| devc
->model
== MD_1845_SSCAPE
) /* Use alternate speed select registers */
1097 fs
&= 0xf0; /* Mask off the rate select bits */
1099 ad_write(devc
, 22, (portc
->speed
>> 8) & 0xff); /* Speed MSB */
1100 ad_write(devc
, 23, portc
->speed
& 0xff); /* Speed LSB */
1102 old_fs
= ad_read(devc
, 8);
1104 if (devc
->model
== MD_4232
)
1106 tmp
= ad_read(devc
, 16);
1107 ad_write(devc
, 16, tmp
| 0x30);
1109 if (devc
->model
== MD_IWAVE
)
1110 ad_write(devc
, 17, 0xc2); /* Disable variable frequency select */
1112 ad_write(devc
, 8, fs
);
1115 * Write to I8 starts resynchronization. Wait until it completes.
1119 while (timeout
< 100 && inb(devc
->base
) != 0x80)
1122 while (timeout
< 10000 && inb(devc
->base
) == 0x80)
1125 if (devc
->model
== MD_4232
)
1126 ad_write(devc
, 16, tmp
& ~0x30);
1128 ad_leave_MCE(devc
); /*
1129 * Starts the calibration process.
1131 restore_flags(flags
);
1132 devc
->xfer_count
= 0;
1134 #if defined(CONFIG_SEQUENCER) && !defined(EXCLUDE_TIMERS)
1135 if (dev
== timer_installed
&& devc
->timer_running
)
1136 if ((fs
& 0x01) != (old_fs
& 0x01))
1138 ad1848_tmr_reprogram(dev
);
1141 ad1848_halt_output(dev
);
1145 static int ad1848_prepare_for_input(int dev
, int bsize
, int bcount
)
1148 unsigned char fs
, old_fs
, tmp
= 0;
1149 unsigned long flags
;
1150 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
1151 ad1848_port_info
*portc
= (ad1848_port_info
*) audio_devs
[dev
]->portc
;
1153 if (devc
->audio_mode
)
1158 fs
= portc
->speed_bits
| (portc
->format_bits
<< 5);
1160 if (portc
->channels
> 1)
1163 ad_enter_MCE(devc
); /* Enables changes to the format select reg */
1165 if ((devc
->model
== MD_1845
) || (devc
->model
== MD_1845_SSCAPE
)) /* Use alternate speed select registers */
1167 fs
&= 0xf0; /* Mask off the rate select bits */
1169 ad_write(devc
, 22, (portc
->speed
>> 8) & 0xff); /* Speed MSB */
1170 ad_write(devc
, 23, portc
->speed
& 0xff); /* Speed LSB */
1172 if (devc
->model
== MD_4232
)
1174 tmp
= ad_read(devc
, 16);
1175 ad_write(devc
, 16, tmp
| 0x30);
1177 if (devc
->model
== MD_IWAVE
)
1178 ad_write(devc
, 17, 0xc2); /* Disable variable frequency select */
1181 * If mode >= 2 (CS4231), set I28. It's the capture format register.
1184 if (devc
->model
!= MD_1848
)
1186 old_fs
= ad_read(devc
, 28);
1187 ad_write(devc
, 28, fs
);
1190 * Write to I28 starts resynchronization. Wait until it completes.
1194 while (timeout
< 100 && inb(devc
->base
) != 0x80)
1198 while (timeout
< 10000 && inb(devc
->base
) == 0x80)
1201 if (devc
->model
!= MD_1848
&& devc
->model
!= MD_1845
&& devc
->model
!= MD_1845_SSCAPE
)
1204 * CS4231 compatible devices don't have separate sampling rate selection
1205 * register for recording an playback. The I8 register is shared so we have to
1206 * set the speed encoding bits of it too.
1208 unsigned char tmp
= portc
->speed_bits
| (ad_read(devc
, 8) & 0xf0);
1210 ad_write(devc
, 8, tmp
);
1212 * Write to I8 starts resynchronization. Wait until it completes.
1215 while (timeout
< 100 && inb(devc
->base
) != 0x80)
1219 while (timeout
< 10000 && inb(devc
->base
) == 0x80)
1224 { /* For AD1848 set I8. */
1226 old_fs
= ad_read(devc
, 8);
1227 ad_write(devc
, 8, fs
);
1229 * Write to I8 starts resynchronization. Wait until it completes.
1232 while (timeout
< 100 && inb(devc
->base
) != 0x80)
1235 while (timeout
< 10000 && inb(devc
->base
) == 0x80)
1239 if (devc
->model
== MD_4232
)
1240 ad_write(devc
, 16, tmp
& ~0x30);
1242 ad_leave_MCE(devc
); /*
1243 * Starts the calibration process.
1245 restore_flags(flags
);
1246 devc
->xfer_count
= 0;
1248 #if defined(CONFIG_SEQUENCER) && !defined(EXCLUDE_TIMERS)
1249 if (dev
== timer_installed
&& devc
->timer_running
)
1251 if ((fs
& 0x01) != (old_fs
& 0x01))
1253 ad1848_tmr_reprogram(dev
);
1257 ad1848_halt_input(dev
);
1261 static void ad1848_halt(int dev
)
1263 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
1264 ad1848_port_info
*portc
= (ad1848_port_info
*) audio_devs
[dev
]->portc
;
1266 unsigned char bits
= ad_read(devc
, 9);
1268 if (bits
& 0x01 && (portc
->open_mode
& OPEN_WRITE
))
1269 ad1848_halt_output(dev
);
1271 if (bits
& 0x02 && (portc
->open_mode
& OPEN_READ
))
1272 ad1848_halt_input(dev
);
1273 devc
->audio_mode
= 0;
1276 static void ad1848_halt_input(int dev
)
1278 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
1279 unsigned long flags
;
1281 if (!(ad_read(devc
, 9) & 0x02))
1282 return; /* Capture not enabled */
1292 if(!isa_dma_bridge_buggy
)
1293 disable_dma(audio_devs
[dev
]->dmap_in
->dma
);
1295 for (tmout
= 0; tmout
< 100000; tmout
++)
1296 if (ad_read(devc
, 11) & 0x10)
1298 ad_write(devc
, 9, ad_read(devc
, 9) & ~0x02); /* Stop capture */
1300 if(!isa_dma_bridge_buggy
)
1301 enable_dma(audio_devs
[dev
]->dmap_in
->dma
);
1302 devc
->audio_mode
&= ~PCM_ENABLE_INPUT
;
1305 outb(0, io_Status(devc
)); /* Clear interrupt status */
1306 outb(0, io_Status(devc
)); /* Clear interrupt status */
1308 devc
->audio_mode
&= ~PCM_ENABLE_INPUT
;
1310 restore_flags(flags
);
1313 static void ad1848_halt_output(int dev
)
1315 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
1316 unsigned long flags
;
1318 if (!(ad_read(devc
, 9) & 0x01))
1319 return; /* Playback not enabled */
1328 if(!isa_dma_bridge_buggy
)
1329 disable_dma(audio_devs
[dev
]->dmap_out
->dma
);
1331 for (tmout
= 0; tmout
< 100000; tmout
++)
1332 if (ad_read(devc
, 11) & 0x10)
1334 ad_write(devc
, 9, ad_read(devc
, 9) & ~0x01); /* Stop playback */
1336 if(!isa_dma_bridge_buggy
)
1337 enable_dma(audio_devs
[dev
]->dmap_out
->dma
);
1339 devc
->audio_mode
&= ~PCM_ENABLE_OUTPUT
;
1342 outb((0), io_Status(devc
)); /* Clear interrupt status */
1343 outb((0), io_Status(devc
)); /* Clear interrupt status */
1345 devc
->audio_mode
&= ~PCM_ENABLE_OUTPUT
;
1347 restore_flags(flags
);
1350 static void ad1848_trigger(int dev
, int state
)
1352 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
1353 ad1848_port_info
*portc
= (ad1848_port_info
*) audio_devs
[dev
]->portc
;
1354 unsigned long flags
;
1355 unsigned char tmp
, old
;
1359 state
&= devc
->audio_mode
;
1361 tmp
= old
= ad_read(devc
, 9);
1363 if (portc
->open_mode
& OPEN_READ
)
1365 if (state
& PCM_ENABLE_INPUT
)
1370 if (portc
->open_mode
& OPEN_WRITE
)
1372 if (state
& PCM_ENABLE_OUTPUT
)
1377 /* ad_mute(devc); */
1380 ad_write(devc
, 9, tmp
);
1383 restore_flags(flags
);
1386 static void ad1848_init_hw(ad1848_info
* devc
)
1391 * Initial values for the indirect registers of CS4248/AD1848.
1393 static int init_values
[] =
1395 0xa8, 0xa8, 0x08, 0x08, 0x08, 0x08, 0x00, 0x00,
1396 0x00, 0x0c, 0x02, 0x00, 0x8a, 0x01, 0x00, 0x00,
1398 /* Positions 16 to 31 just for CS4231/2 and ad1845 */
1399 0x80, 0x00, 0x10, 0x10, 0x00, 0x00, 0x1f, 0x40,
1400 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
1404 for (i
= 0; i
< 16; i
++)
1405 ad_write(devc
, i
, init_values
[i
]);
1408 ad_mute(devc
); /* Initialize some variables */
1409 ad_unmute(devc
); /* Leave it unmuted now */
1411 if (devc
->model
> MD_1848
)
1413 if (devc
->model
== MD_1845_SSCAPE
)
1414 ad_write(devc
, 12, ad_read(devc
, 12) | 0x50);
1416 ad_write(devc
, 12, ad_read(devc
, 12) | 0x40); /* Mode2 = enabled */
1418 if (devc
->model
== MD_IWAVE
)
1419 ad_write(devc
, 12, 0x6c); /* Select codec mode 3 */
1421 if (devc
-> model
!= MD_1845_SSCAPE
)
1422 for (i
= 16; i
< 32; i
++)
1423 ad_write(devc
, i
, init_values
[i
]);
1425 if (devc
->model
== MD_IWAVE
)
1426 ad_write(devc
, 16, 0x30); /* Playback and capture counters enabled */
1428 if (devc
->model
> MD_1848
)
1430 if (devc
->audio_flags
& DMA_DUPLEX
)
1431 ad_write(devc
, 9, ad_read(devc
, 9) & ~0x04); /* Dual DMA mode */
1433 ad_write(devc
, 9, ad_read(devc
, 9) | 0x04); /* Single DMA mode */
1435 if (devc
->model
== MD_1845
|| devc
->model
== MD_1845_SSCAPE
)
1436 ad_write(devc
, 27, ad_read(devc
, 27) | 0x08); /* Alternate freq select enabled */
1438 if (devc
->model
== MD_IWAVE
)
1439 { /* Some magic Interwave specific initialization */
1440 ad_write(devc
, 12, 0x6c); /* Select codec mode 3 */
1441 ad_write(devc
, 16, 0x30); /* Playback and capture counters enabled */
1442 ad_write(devc
, 17, 0xc2); /* Alternate feature enable */
1447 devc
->audio_flags
&= ~DMA_DUPLEX
;
1448 ad_write(devc
, 9, ad_read(devc
, 9) | 0x04); /* Single DMA mode */
1450 ad_write(devc
, 12, ad_read(devc
, 12) | 0x40); /* Mode2 = enabled */
1453 outb((0), io_Status(devc
)); /* Clear pending interrupts */
1456 * Toggle the MCE bit. It completes the initialization phase.
1459 ad_enter_MCE(devc
); /* In case the bit was off */
1462 ad1848_mixer_reset(devc
);
1465 int ad1848_detect(int io_base
, int *ad_flags
, int *osp
)
1468 ad1848_info
*devc
= &adev_info
[nr_ad1848_devs
];
1469 unsigned char tmp1
= 0xff, tmp2
= 0xff;
1470 int optiC930
= 0; /* OPTi 82C930 flag */
1472 int ad1847_flag
= 0;
1473 int cs4248_flag
= 0;
1474 int sscape_flag
= 0;
1478 DDB(printk("ad1848_detect(%x)\n", io_base
));
1482 if (*ad_flags
== 0x12345678)
1488 if (*ad_flags
== 0x87654321)
1494 if (*ad_flags
== 0x12345677)
1500 if (nr_ad1848_devs
>= MAX_AUDIO_DEV
)
1502 printk(KERN_ERR
"ad1848 - Too many audio devices\n");
1505 if (check_region(io_base
, 4))
1507 printk(KERN_ERR
"ad1848.c: Port %x not free.\n", io_base
);
1510 devc
->base
= io_base
;
1512 devc
->timer_running
= 0;
1513 devc
->MCE_bit
= 0x40;
1515 devc
->open_mode
= 0;
1516 devc
->chip_name
= devc
->name
= "AD1848";
1517 devc
->model
= MD_1848
; /* AD1848 or CS4248 */
1518 devc
->levels
= NULL
;
1519 devc
->debug_flag
= 0;
1522 * Check that the I/O address is in use.
1524 * The bit 0x80 of the base I/O port is known to be 0 after the
1525 * chip has performed its power on initialization. Just assume
1526 * this has happened before the OS is starting.
1528 * If the I/O address is unused, it typically returns 0xff.
1531 if (inb(devc
->base
) == 0xff)
1533 DDB(printk("ad1848_detect: The base I/O address appears to be dead\n"));
1537 * Wait for the device to stop initialization
1540 DDB(printk("ad1848_detect() - step 0\n"));
1542 for (i
= 0; i
< 10000000; i
++)
1544 unsigned char x
= inb(devc
->base
);
1546 if (x
== 0xff || !(x
& 0x80))
1550 DDB(printk("ad1848_detect() - step A\n"));
1552 if (inb(devc
->base
) == 0x80) /* Not ready. Let's wait */
1555 if ((inb(devc
->base
) & 0x80) != 0x00) /* Not a AD1848 */
1557 DDB(printk("ad1848 detect error - step A (%02x)\n", (int) inb(devc
->base
)));
1562 * Test if it's possible to change contents of the indirect registers.
1563 * Registers 0 and 1 are ADC volume registers. The bit 0x10 is read only
1564 * so try to avoid using it.
1567 DDB(printk("ad1848_detect() - step B\n"));
1568 ad_write(devc
, 0, 0xaa);
1569 ad_write(devc
, 1, 0x45); /* 0x55 with bit 0x10 clear */
1571 if ((tmp1
= ad_read(devc
, 0)) != 0xaa || (tmp2
= ad_read(devc
, 1)) != 0x45)
1573 if (tmp2
== 0x65) /* AD1847 has couple of bits hardcoded to 1 */
1577 DDB(printk("ad1848 detect error - step B (%x/%x)\n", tmp1
, tmp2
));
1581 DDB(printk("ad1848_detect() - step C\n"));
1582 ad_write(devc
, 0, 0x45);
1583 ad_write(devc
, 1, 0xaa);
1585 if ((tmp1
= ad_read(devc
, 0)) != 0x45 || (tmp2
= ad_read(devc
, 1)) != 0xaa)
1587 if (tmp2
== 0x8a) /* AD1847 has few bits hardcoded to 1 */
1591 DDB(printk("ad1848 detect error - step C (%x/%x)\n", tmp1
, tmp2
));
1597 * The indirect register I12 has some read only bits. Let's
1598 * try to change them.
1601 DDB(printk("ad1848_detect() - step D\n"));
1602 tmp
= ad_read(devc
, 12);
1603 ad_write(devc
, 12, (~tmp
) & 0x0f);
1605 if ((tmp
& 0x0f) != ((tmp1
= ad_read(devc
, 12)) & 0x0f))
1607 DDB(printk("ad1848 detect error - step D (%x)\n", tmp1
));
1612 * NOTE! Last 4 bits of the reg I12 tell the chip revision.
1613 * 0x01=RevB and 0x0A=RevC.
1617 * The original AD1848/CS4248 has just 15 indirect registers. This means
1618 * that I0 and I16 should return the same value (etc.).
1619 * However this doesn't work with CS4248. Actually it seems to be impossible
1620 * to detect if the chip is a CS4231 or CS4248.
1621 * Ensure that the Mode2 enable bit of I12 is 0. Otherwise this test fails
1626 * OPTi 82C930 has mode2 control bit in another place. This test will fail
1627 * with it. Accept this situation as a possible indication of this chip.
1630 DDB(printk("ad1848_detect() - step F\n"));
1631 ad_write(devc
, 12, 0); /* Mode2=disabled */
1633 for (i
= 0; i
< 16; i
++)
1635 if ((tmp1
= ad_read(devc
, i
)) != (tmp2
= ad_read(devc
, i
+ 16)))
1637 DDB(printk("ad1848 detect step F(%d/%x/%x) - OPTi chip???\n", i
, tmp1
, tmp2
));
1645 * Try to switch the chip to mode2 (CS4231) by setting the MODE2 bit (0x40).
1646 * The bit 0x80 is always 1 in CS4248 and CS4231.
1649 DDB(printk("ad1848_detect() - step G\n"));
1651 if (ad_flags
&& *ad_flags
== 400)
1654 ad_write(devc
, 12, 0x40); /* Set mode2, clear 0x80 */
1660 tmp1
= ad_read(devc
, 12);
1664 *ad_flags
|= AD_F_CS4248
;
1666 devc
->chip_name
= "CS4248"; /* Our best knowledge just now */
1668 if (optiC930
|| (tmp1
& 0xc0) == (0x80 | 0x40))
1671 * CS4231 detected - is it?
1673 * Verify that setting I0 doesn't change I16.
1676 DDB(printk("ad1848_detect() - step H\n"));
1677 ad_write(devc
, 16, 0); /* Set I16 to known value */
1679 ad_write(devc
, 0, 0x45);
1680 if ((tmp1
= ad_read(devc
, 16)) != 0x45) /* No change -> CS4231? */
1682 ad_write(devc
, 0, 0xaa);
1683 if ((tmp1
= ad_read(devc
, 16)) == 0xaa) /* Rotten bits? */
1685 DDB(printk("ad1848 detect error - step H(%x)\n", tmp1
));
1690 * Verify that some bits of I25 are read only.
1693 DDB(printk("ad1848_detect() - step I\n"));
1694 tmp1
= ad_read(devc
, 25); /* Original bits */
1695 ad_write(devc
, 25, ~tmp1
); /* Invert all bits */
1696 if ((ad_read(devc
, 25) & 0xe7) == (tmp1
& 0xe7))
1701 * It's at least CS4231
1704 devc
->chip_name
= "CS4231";
1705 devc
->model
= MD_4231
;
1708 * It could be an AD1845 or CS4231A as well.
1709 * CS4231 and AD1845 report the same revision info in I25
1710 * while the CS4231A reports different.
1713 id
= ad_read(devc
, 25);
1714 if ((id
& 0xe7) == 0x80) /* Device busy??? */
1715 id
= ad_read(devc
, 25);
1716 if ((id
& 0xe7) == 0x80) /* Device still busy??? */
1717 id
= ad_read(devc
, 25);
1718 DDB(printk("ad1848_detect() - step J (%02x/%02x)\n", id
, ad_read(devc
, 25)));
1720 if ((id
& 0xe7) == 0x80) {
1722 * It must be a CS4231 or AD1845. The register I23 of
1723 * CS4231 is undefined and it appears to be read only.
1724 * AD1845 uses I23 for setting sample rate. Assume
1725 * the chip is AD1845 if I23 is changeable.
1728 unsigned char tmp
= ad_read(devc
, 23);
1729 ad_write(devc
, 23, ~tmp
);
1733 devc
->model
= MD_IWAVE
;
1734 devc
->chip_name
= "IWave";
1736 else if (ad_read(devc
, 23) != tmp
) /* AD1845 ? */
1738 devc
->chip_name
= "AD1845";
1739 devc
->model
= MD_1845
;
1741 else if (cs4248_flag
)
1744 *ad_flags
|= AD_F_CS4248
;
1745 devc
->chip_name
= "CS4248";
1746 devc
->model
= MD_1848
;
1747 ad_write(devc
, 12, ad_read(devc
, 12) & ~0x40); /* Mode2 off */
1749 ad_write(devc
, 23, tmp
); /* Restore */
1753 switch (id
& 0x1f) {
1754 case 3: /* CS4236/CS4235 */
1757 ad_write(devc
, 12, ad_read(devc
, 12) | 0x60); /* switch to mode 3 */
1758 ad_write(devc
, 23, 0x9c); /* select extended register 25 */
1759 xid
= inb(io_Indexed_Data(devc
));
1760 ad_write(devc
, 12, ad_read(devc
, 12) & ~0x60); /* back to mode 0 */
1761 if ((xid
& 0x1f) == 0x1d) {
1762 devc
->chip_name
= "CS4235";
1763 devc
->model
= MD_4235
;
1765 devc
->chip_name
= "CS4236";
1766 devc
->model
= MD_4232
;
1771 case 2: /* CS4232/CS4232A */
1772 devc
->chip_name
= "CS4232";
1773 devc
->model
= MD_4232
;
1777 if ((id
& 0xe0) == 0xa0)
1779 devc
->chip_name
= "CS4231A";
1780 devc
->model
= MD_4231A
;
1784 devc
->chip_name
= "CS4321";
1785 devc
->model
= MD_4231
;
1789 default: /* maybe */
1790 DDB(printk("ad1848: I25 = %02x/%02x\n", ad_read(devc
, 25), ad_read(devc
, 25) & 0xe7));
1793 devc
->chip_name
= "82C930";
1794 devc
->model
= MD_C930
;
1798 devc
->chip_name
= "CS4231";
1799 devc
->model
= MD_4231
;
1804 ad_write(devc
, 25, tmp1
); /* Restore bits */
1806 DDB(printk("ad1848_detect() - step K\n"));
1808 } else if (tmp1
== 0x0a) {
1810 * Is it perhaps a SoundPro CMI8330?
1811 * If so, then we should be able to change indirect registers
1812 * greater than I15 after activating MODE2, even though reading
1813 * back I12 does not show it.
1817 * Let's try comparing register values
1819 for (i
= 0; i
< 16; i
++) {
1820 if ((tmp1
= ad_read(devc
, i
)) != (tmp2
= ad_read(devc
, i
+ 16))) {
1821 DDB(printk("ad1848 detect step H(%d/%x/%x) - SoundPro chip?\n", i
, tmp1
, tmp2
));
1823 devc
->chip_name
= "SoundPro CMI 8330";
1829 DDB(printk("ad1848_detect() - step L\n"));
1832 if (devc
->model
!= MD_1848
)
1833 *ad_flags
|= AD_F_CS4231
;
1835 DDB(printk("ad1848_detect() - Detected OK\n"));
1837 if (devc
->model
== MD_1848
&& ad1847_flag
)
1838 devc
->chip_name
= "AD1847";
1841 if (sscape_flag
== 1)
1842 devc
->model
= MD_1845_SSCAPE
;
1847 int ad1848_init(char *name
, int io_base
, int irq
, int dma_playback
, int dma_capture
, int share_dma
, int *osp
)
1850 * NOTE! If irq < 0, there is another driver which has allocated the IRQ
1851 * so that this driver doesn't need to allocate/deallocate it.
1852 * The actually used IRQ is ABS(irq).
1860 ad1848_info
*devc
= &adev_info
[nr_ad1848_devs
];
1862 ad1848_port_info
*portc
= NULL
;
1864 devc
->irq
= (irq
> 0) ? irq
: 0;
1865 devc
->open_mode
= 0;
1866 devc
->timer_ticks
= 0;
1867 devc
->dma1
= dma_playback
;
1868 devc
->dma2
= dma_capture
;
1869 devc
->audio_flags
= DMA_AUTOMODE
;
1870 devc
->playback_dev
= devc
->record_dev
= 0;
1874 if (name
!= NULL
&& name
[0] != 0)
1876 "%s (%s)", name
, devc
->chip_name
);
1879 "Generic audio codec (%s)", devc
->chip_name
);
1881 request_region(devc
->base
, 4, devc
->name
);
1883 conf_printf2(dev_name
, devc
->base
, devc
->irq
, dma_playback
, dma_capture
);
1885 if (devc
->model
== MD_1848
|| devc
->model
== MD_C930
)
1886 devc
->audio_flags
|= DMA_HARDSTOP
;
1888 if (devc
->model
> MD_1848
)
1890 if (devc
->dma1
== devc
->dma2
|| devc
->dma2
== -1 || devc
->dma1
== -1)
1891 devc
->audio_flags
&= ~DMA_DUPLEX
;
1893 devc
->audio_flags
|= DMA_DUPLEX
;
1896 portc
= (ad1848_port_info
*) kmalloc(sizeof(ad1848_port_info
), GFP_KERNEL
);
1900 if ((my_dev
= sound_install_audiodrv(AUDIO_DRIVER_VERSION
,
1902 &ad1848_audio_driver
,
1903 sizeof(struct audio_driver
),
1905 ad_format_mask
[devc
->model
],
1915 audio_devs
[my_dev
]->portc
= portc
;
1916 audio_devs
[my_dev
]->mixer_dev
= -1;
1917 memset((char *) portc
, 0, sizeof(*portc
));
1921 ad1848_init_hw(devc
);
1925 devc
->dev_no
= my_dev
;
1926 if (request_irq(devc
->irq
, adintr
, 0, devc
->name
, (void *)my_dev
) < 0)
1928 printk(KERN_WARNING
"ad1848: Unable to allocate IRQ\n");
1929 /* Don't free it either then.. */
1932 if (capabilities
[devc
->model
].flags
& CAP_F_TIMER
)
1936 unsigned char tmp
= ad_read(devc
, 16);
1939 devc
->timer_ticks
= 0;
1941 ad_write(devc
, 21, 0x00); /* Timer MSB */
1942 ad_write(devc
, 20, 0x10); /* Timer LSB */
1944 ad_write(devc
, 16, tmp
| 0x40); /* Enable timer */
1945 for (x
= 0; x
< 100000 && devc
->timer_ticks
== 0; x
++);
1946 ad_write(devc
, 16, tmp
& ~0x40); /* Disable timer */
1948 if (devc
->timer_ticks
== 0)
1949 printk(KERN_WARNING
"ad1848: Interrupt test failed (IRQ%d)\n", irq
);
1952 DDB(printk("Interrupt test OK\n"));
1960 devc
->irq_ok
= 1; /* Couldn't test. assume it's OK */
1962 irq2dev
[-irq
] = devc
->dev_no
= my_dev
;
1964 #if defined(CONFIG_SEQUENCER) && !defined(EXCLUDE_TIMERS)
1965 if ((capabilities
[devc
->model
].flags
& CAP_F_TIMER
) &&
1967 ad1848_tmr_install(my_dev
);
1972 if (sound_alloc_dma(dma_playback
, devc
->name
))
1973 printk(KERN_WARNING
"ad1848.c: Can't allocate DMA%d\n", dma_playback
);
1975 if (dma_capture
!= dma_playback
)
1976 if (sound_alloc_dma(dma_capture
, devc
->name
))
1977 printk(KERN_WARNING
"ad1848.c: Can't allocate DMA%d\n", dma_capture
);
1979 if ((e
= sound_install_mixer(MIXER_DRIVER_VERSION
,
1981 &ad1848_mixer_operations
,
1982 sizeof(struct mixer_operations
),
1985 audio_devs
[my_dev
]->mixer_dev
= e
;
1990 int ad1848_control(int cmd
, int arg
)
1994 if (nr_ad1848_devs
< 1)
1997 devc
= &adev_info
[nr_ad1848_devs
- 1];
2001 case AD1848_SET_XTAL
: /* Change clock frequency of AD1845 (only ) */
2002 if (devc
->model
!= MD_1845
|| devc
->model
!= MD_1845_SSCAPE
)
2005 ad_write(devc
, 29, (ad_read(devc
, 29) & 0x1f) | (arg
<< 5));
2009 case AD1848_MIXER_REROUTE
:
2011 int o
= (arg
>> 8) & 0xff;
2014 if (o
< 0 || o
>= SOUND_MIXER_NRDEVICES
)
2017 if (!(devc
->supported_devices
& (1 << o
)) &&
2018 !(devc
->supported_rec_devices
& (1 << o
)))
2021 if (n
== SOUND_MIXER_NONE
)
2022 { /* Just hide this control */
2023 ad1848_mixer_set(devc
, o
, 0); /* Shut up it */
2024 devc
->supported_devices
&= ~(1 << o
);
2025 devc
->supported_rec_devices
&= ~(1 << o
);
2029 /* Make the mixer control identified by o to appear as n */
2030 if (n
< 0 || n
>= SOUND_MIXER_NRDEVICES
)
2033 devc
->mixer_reroute
[n
] = o
; /* Rename the control */
2034 if (devc
->supported_devices
& (1 << o
))
2035 devc
->supported_devices
|= (1 << n
);
2036 if (devc
->supported_rec_devices
& (1 << o
))
2037 devc
->supported_rec_devices
|= (1 << n
);
2039 devc
->supported_devices
&= ~(1 << o
);
2040 devc
->supported_rec_devices
&= ~(1 << o
);
2047 void ad1848_unload(int io_base
, int irq
, int dma_playback
, int dma_capture
, int share_dma
)
2049 int i
, mixer
, dev
= 0;
2050 ad1848_info
*devc
= NULL
;
2052 for (i
= 0; devc
== NULL
&& i
< nr_ad1848_devs
; i
++)
2054 if (adev_info
[i
].base
== io_base
)
2056 devc
= &adev_info
[i
];
2063 if(audio_devs
[dev
]->portc
!=NULL
)
2064 kfree(audio_devs
[dev
]->portc
);
2065 release_region(devc
->base
, 4);
2069 if (devc
->irq
> 0) /* There is no point in freeing irq, if it wasn't allocated */
2070 free_irq(devc
->irq
, (void *)devc
->dev_no
);
2072 sound_free_dma(dma_playback
);
2074 if (dma_playback
!= dma_capture
)
2075 sound_free_dma(dma_capture
);
2078 mixer
= audio_devs
[devc
->dev_no
]->mixer_dev
;
2080 sound_unload_mixerdev(mixer
);
2083 for ( ; i
< nr_ad1848_devs
; i
++)
2084 adev_info
[i
] = adev_info
[i
+1];
2087 printk(KERN_ERR
"ad1848: Can't find device to be unloaded. Base=%x\n", io_base
);
2090 void adintr(int irq
, void *dev_id
, struct pt_regs
*dummy
)
2092 unsigned char status
;
2095 int alt_stat
= 0xff;
2096 unsigned char c930_stat
= 0;
2100 devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
2102 interrupt_again
: /* Jump back here if int status doesn't reset */
2104 status
= inb(io_Status(devc
));
2107 printk(KERN_DEBUG
"adintr: Why?\n");
2108 if (devc
->model
== MD_1848
)
2109 outb((0), io_Status(devc
)); /* Clear interrupt status */
2113 if (devc
->model
== MD_C930
)
2114 { /* 82C930 has interrupt status register in MAD16 register MC11 */
2115 unsigned long flags
;
2120 /* 0xe0e is C930 address port
2121 * 0xe0f is C930 data port
2124 c930_stat
= inb(0xe0f);
2125 outb((~c930_stat
), 0xe0f);
2127 restore_flags(flags
);
2129 alt_stat
= (c930_stat
<< 2) & 0x30;
2131 else if (devc
->model
!= MD_1848
)
2133 alt_stat
= ad_read(devc
, 24);
2134 ad_write(devc
, 24, ad_read(devc
, 24) & ~alt_stat
); /* Selective ack */
2137 if ((devc
->open_mode
& OPEN_READ
) && (devc
->audio_mode
& PCM_ENABLE_INPUT
) && (alt_stat
& 0x20))
2139 DMAbuf_inputintr(devc
->record_dev
);
2141 if ((devc
->open_mode
& OPEN_WRITE
) && (devc
->audio_mode
& PCM_ENABLE_OUTPUT
) &&
2144 DMAbuf_outputintr(devc
->playback_dev
, 1);
2146 if (devc
->model
!= MD_1848
&& (alt_stat
& 0x40)) /* Timer interrupt */
2148 devc
->timer_ticks
++;
2149 #if defined(CONFIG_SEQUENCER) && !defined(EXCLUDE_TIMERS)
2150 if (timer_installed
== dev
&& devc
->timer_running
)
2151 sound_timer_interrupt();
2156 * Sometimes playback or capture interrupts occur while a timer interrupt
2157 * is being handled. The interrupt will not be retriggered if we don't
2158 * handle it now. Check if an interrupt is still pending and restart
2159 * the handler in this case.
2161 if (inb(io_Status(devc
)) & 0x01 && cnt
++ < 4)
2163 goto interrupt_again
;
2168 * Experimental initialization sequence for the integrated sound system
2169 * of the Compaq Deskpro M.
2172 static int init_deskpro_m(struct address_info
*hw_config
)
2176 if ((tmp
= inb(0xc44)) == 0xff)
2178 DDB(printk("init_deskpro_m: Dead port 0xc44\n"));
2196 * Experimental initialization sequence for the integrated sound system
2197 * of Compaq Deskpro XL.
2200 static int init_deskpro(struct address_info
*hw_config
)
2204 if ((tmp
= inb(0xc44)) == 0xff)
2206 DDB(printk("init_deskpro: Dead port 0xc44\n"));
2209 outb((tmp
| 0x04), 0xc44); /* Select bank 1 */
2210 if (inb(0xc44) != 0x04)
2212 DDB(printk("init_deskpro: Invalid bank1 signature in port 0xc44\n"));
2216 * OK. It looks like a Deskpro so let's proceed.
2220 * I/O port 0xc44 Audio configuration register.
2222 * bits 0xc0: Audio revision bits
2223 * 0x00 = Compaq Business Audio
2224 * 0x40 = MS Sound System Compatible (reset default)
2227 * bit 0x20: No Wait State Enable
2228 * 0x00 = Disabled (reset default, DMA mode)
2229 * 0x20 = Enabled (programmed I/O mode)
2230 * bit 0x10: MS Sound System Decode Enable
2231 * 0x00 = Decoding disabled (reset default)
2232 * 0x10 = Decoding enabled
2233 * bit 0x08: FM Synthesis Decode Enable
2234 * 0x00 = Decoding Disabled (reset default)
2235 * 0x08 = Decoding enabled
2236 * bit 0x04 Bank select
2239 * bits 0x03 MSS Base address
2240 * 0x00 = 0x530 (reset default)
2247 /* Debug printing */
2248 printk("Port 0xc44 (before): ");
2249 outb((tmp
& ~0x04), 0xc44);
2250 printk("%02x ", inb(0xc44));
2251 outb((tmp
| 0x04), 0xc44);
2252 printk("%02x\n", inb(0xc44));
2255 /* Set bank 1 of the register */
2256 tmp
= 0x58; /* MSS Mode, MSS&FM decode enabled */
2258 switch (hw_config
->io_base
)
2273 DDB(printk("init_deskpro: Invalid MSS port %x\n", hw_config
->io_base
));
2276 outb((tmp
& ~0x04), 0xc44); /* Write to bank=0 */
2279 /* Debug printing */
2280 printk("Port 0xc44 (after): ");
2281 outb((tmp
& ~0x04), 0xc44); /* Select bank=0 */
2282 printk("%02x ", inb(0xc44));
2283 outb((tmp
| 0x04), 0xc44); /* Select bank=1 */
2284 printk("%02x\n", inb(0xc44));
2288 * I/O port 0xc45 FM Address Decode/MSS ID Register.
2290 * bank=0, bits 0xfe: FM synthesis Decode Compare bits 7:1 (default=0x88)
2291 * bank=0, bit 0x01: SBIC Power Control Bit
2293 * 0x01 = Powered down
2294 * bank=1, bits 0xfc: MSS ID (default=0x40)
2298 /* Debug printing */
2299 printk("Port 0xc45 (before): ");
2300 outb((tmp
& ~0x04), 0xc44); /* Select bank=0 */
2301 printk("%02x ", inb(0xc45));
2302 outb((tmp
| 0x04), 0xc44); /* Select bank=1 */
2303 printk("%02x\n", inb(0xc45));
2306 outb((tmp
& ~0x04), 0xc44); /* Select bank=0 */
2307 outb((0x88), 0xc45); /* FM base 7:0 = 0x88 */
2308 outb((tmp
| 0x04), 0xc44); /* Select bank=1 */
2309 outb((0x10), 0xc45); /* MSS ID = 0x10 (MSS port returns 0x04) */
2312 /* Debug printing */
2313 printk("Port 0xc45 (after): ");
2314 outb((tmp
& ~0x04), 0xc44); /* Select bank=0 */
2315 printk("%02x ", inb(0xc45));
2316 outb((tmp
| 0x04), 0xc44); /* Select bank=1 */
2317 printk("%02x\n", inb(0xc45));
2322 * I/O port 0xc46 FM Address Decode/Address ASIC Revision Register.
2324 * bank=0, bits 0xff: FM synthesis Decode Compare bits 15:8 (default=0x03)
2325 * bank=1, bits 0xff: Audio addressing ASIC id
2329 /* Debug printing */
2330 printk("Port 0xc46 (before): ");
2331 outb((tmp
& ~0x04), 0xc44); /* Select bank=0 */
2332 printk("%02x ", inb(0xc46));
2333 outb((tmp
| 0x04), 0xc44); /* Select bank=1 */
2334 printk("%02x\n", inb(0xc46));
2337 outb((tmp
& ~0x04), 0xc44); /* Select bank=0 */
2338 outb((0x03), 0xc46); /* FM base 15:8 = 0x03 */
2339 outb((tmp
| 0x04), 0xc44); /* Select bank=1 */
2340 outb((0x11), 0xc46); /* ASIC ID = 0x11 */
2343 /* Debug printing */
2344 printk("Port 0xc46 (after): ");
2345 outb((tmp
& ~0x04), 0xc44); /* Select bank=0 */
2346 printk("%02x ", inb(0xc46));
2347 outb((tmp
| 0x04), 0xc44); /* Select bank=1 */
2348 printk("%02x\n", inb(0xc46));
2352 * I/O port 0xc47 FM Address Decode Register.
2354 * bank=0, bits 0xff: Decode enable selection for various FM address bits
2355 * bank=1, bits 0xff: Reserved
2359 /* Debug printing */
2360 printk("Port 0xc47 (before): ");
2361 outb((tmp
& ~0x04), 0xc44); /* Select bank=0 */
2362 printk("%02x ", inb(0xc47));
2363 outb((tmp
| 0x04), 0xc44); /* Select bank=1 */
2364 printk("%02x\n", inb(0xc47));
2367 outb((tmp
& ~0x04), 0xc44); /* Select bank=0 */
2368 outb((0x7c), 0xc47); /* FM decode enable bits = 0x7c */
2369 outb((tmp
| 0x04), 0xc44); /* Select bank=1 */
2370 outb((0x00), 0xc47); /* Reserved bank1 = 0x00 */
2373 /* Debug printing */
2374 printk("Port 0xc47 (after): ");
2375 outb((tmp
& ~0x04), 0xc44); /* Select bank=0 */
2376 printk("%02x ", inb(0xc47));
2377 outb((tmp
| 0x04), 0xc44); /* Select bank=1 */
2378 printk("%02x\n", inb(0xc47));
2382 * I/O port 0xc6f = Audio Disable Function Register
2386 printk("Port 0xc6f (before) = %02x\n", inb(0xc6f));
2389 outb((0x80), 0xc6f);
2392 printk("Port 0xc6f (after) = %02x\n", inb(0xc6f));
2398 int probe_ms_sound(struct address_info
*hw_config
)
2402 DDB(printk("Entered probe_ms_sound(%x, %d)\n", hw_config
->io_base
, hw_config
->card_subtype
));
2404 if (check_region(hw_config
->io_base
, 8))
2406 printk(KERN_ERR
"MSS: I/O port conflict\n");
2409 if (hw_config
->card_subtype
== 1) /* Has no IRQ/DMA registers */
2411 /* check_opl3(0x388, hw_config); */
2412 return ad1848_detect(hw_config
->io_base
+ 4, NULL
, hw_config
->osp
);
2415 if (deskpro_xl
&& hw_config
->card_subtype
== 2) /* Compaq Deskpro XL */
2417 if (!init_deskpro(hw_config
))
2421 if (deskpro_m
) /* Compaq Deskpro M */
2423 if (!init_deskpro_m(hw_config
))
2428 * Check if the IO port returns valid signature. The original MS Sound
2429 * system returns 0x04 while some cards (AudioTrix Pro for example)
2430 * return 0x00 or 0x0f.
2433 if ((tmp
= inb(hw_config
->io_base
+ 3)) == 0xff) /* Bus float */
2437 DDB(printk("I/O address is inactive (%x)\n", tmp
));
2438 if (!(ret
= ad1848_detect(hw_config
->io_base
+ 4, NULL
, hw_config
->osp
)))
2442 DDB(printk("MSS signature = %x\n", tmp
& 0x3f));
2443 if ((tmp
& 0x3f) != 0x04 &&
2444 (tmp
& 0x3f) != 0x0f &&
2445 (tmp
& 0x3f) != 0x00)
2449 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)));
2450 DDB(printk("Trying to detect codec anyway but IRQ/DMA may not work\n"));
2451 if (!(ret
= ad1848_detect(hw_config
->io_base
+ 4, NULL
, hw_config
->osp
)))
2454 hw_config
->card_subtype
= 1;
2457 if ((hw_config
->irq
!= 5) &&
2458 (hw_config
->irq
!= 7) &&
2459 (hw_config
->irq
!= 9) &&
2460 (hw_config
->irq
!= 10) &&
2461 (hw_config
->irq
!= 11) &&
2462 (hw_config
->irq
!= 12))
2464 printk(KERN_ERR
"MSS: Bad IRQ %d\n", hw_config
->irq
);
2467 if (hw_config
->dma
!= 0 && hw_config
->dma
!= 1 && hw_config
->dma
!= 3)
2469 printk(KERN_ERR
"MSS: Bad DMA %d\n", hw_config
->dma
);
2473 * Check that DMA0 is not in use with a 8 bit board.
2476 if (hw_config
->dma
== 0 && inb(hw_config
->io_base
+ 3) & 0x80)
2478 printk(KERN_ERR
"MSS: Can't use DMA0 with a 8 bit card/slot\n");
2481 if (hw_config
->irq
> 7 && hw_config
->irq
!= 9 && inb(hw_config
->io_base
+ 3) & 0x80)
2483 printk(KERN_ERR
"MSS: Can't use IRQ%d with a 8 bit card/slot\n", hw_config
->irq
);
2486 return ad1848_detect(hw_config
->io_base
+ 4, NULL
, hw_config
->osp
);
2489 void attach_ms_sound(struct address_info
*hw_config
)
2491 static signed char interrupt_bits
[12] =
2493 -1, -1, -1, -1, -1, 0x00, -1, 0x08, -1, 0x10, 0x18, 0x20
2498 static char dma_bits
[4] =
2503 int config_port
= hw_config
->io_base
+ 0;
2504 int version_port
= hw_config
->io_base
+ 3;
2505 int dma
= hw_config
->dma
;
2506 int dma2
= hw_config
->dma2
;
2508 if (hw_config
->card_subtype
== 1) /* Has no IRQ/DMA registers */
2510 hw_config
->slots
[0] = ad1848_init("MS Sound System", hw_config
->io_base
+ 4,
2513 hw_config
->dma2
, 0, hw_config
->osp
);
2514 request_region(hw_config
->io_base
, 4, "WSS config");
2518 * Set the IRQ and DMA addresses.
2521 bits
= interrupt_bits
[hw_config
->irq
];
2524 printk(KERN_ERR
"MSS: Bad IRQ %d\n", hw_config
->irq
);
2527 outb((bits
| 0x40), config_port
);
2528 if ((inb(version_port
) & 0x40) == 0)
2529 printk(KERN_ERR
"[MSS: IRQ Conflict?]\n");
2532 * Handle the capture DMA channel
2535 if (dma2
!= -1 && dma2
!= dma
)
2537 if (!((dma
== 0 && dma2
== 1) ||
2538 (dma
== 1 && dma2
== 0) ||
2539 (dma
== 3 && dma2
== 0)))
2540 { /* Unsupported combination. Try to swap channels */
2546 if ((dma
== 0 && dma2
== 1) ||
2547 (dma
== 1 && dma2
== 0) ||
2548 (dma
== 3 && dma2
== 0))
2550 dma2_bit
= 0x04; /* Enable capture DMA */
2554 printk(KERN_WARNING
"MSS: Invalid capture DMA\n");
2563 hw_config
->dma
= dma
;
2564 hw_config
->dma2
= dma2
;
2566 outb((bits
| dma_bits
[dma
] | dma2_bit
), config_port
); /* Write IRQ+DMA setup */
2568 hw_config
->slots
[0] = ad1848_init("MSS audio codec", hw_config
->io_base
+ 4,
2573 request_region(hw_config
->io_base
, 4, "WSS config");
2576 void unload_ms_sound(struct address_info
*hw_config
)
2578 ad1848_unload(hw_config
->io_base
+ 4,
2581 hw_config
->dma2
, 0);
2582 sound_unload_audiodev(hw_config
->slots
[0]);
2583 release_region(hw_config
->io_base
, 4);
2586 #if defined(CONFIG_SEQUENCER) && !defined(EXCLUDE_TIMERS)
2589 * Timer stuff (for /dev/music).
2592 static unsigned int current_interval
= 0;
2594 static unsigned int ad1848_tmr_start(int dev
, unsigned int usecs
)
2596 unsigned long flags
;
2597 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
2598 unsigned long xtal_nsecs
; /* nanoseconds per xtal oscillator tick */
2599 unsigned long divider
;
2605 * Length of the timer interval (in nanoseconds) depends on the
2606 * selected crystal oscillator. Check this from bit 0x01 of I8.
2608 * AD1845 has just one oscillator which has cycle time of 10.050 us
2609 * (when a 24.576 MHz xtal oscillator is used).
2611 * Convert requested interval to nanoseconds before computing
2612 * the timer divider.
2615 if (devc
->model
== MD_1845
|| devc
->model
== MD_1845_SSCAPE
)
2617 else if (ad_read(devc
, 8) & 0x01)
2622 divider
= (usecs
* 1000 + xtal_nsecs
/ 2) / xtal_nsecs
;
2624 if (divider
< 100) /* Don't allow shorter intervals than about 1ms */
2627 if (divider
> 65535) /* Overflow check */
2630 ad_write(devc
, 21, (divider
>> 8) & 0xff); /* Set upper bits */
2631 ad_write(devc
, 20, divider
& 0xff); /* Set lower bits */
2632 ad_write(devc
, 16, ad_read(devc
, 16) | 0x40); /* Start the timer */
2633 devc
->timer_running
= 1;
2634 restore_flags(flags
);
2636 return current_interval
= (divider
* xtal_nsecs
+ 500) / 1000;
2639 static void ad1848_tmr_reprogram(int dev
)
2642 * Audio driver has changed sampling rate so that a different xtal
2643 * oscillator was selected. We have to reprogram the timer rate.
2646 ad1848_tmr_start(dev
, current_interval
);
2647 sound_timer_syncinterval(current_interval
);
2650 static void ad1848_tmr_disable(int dev
)
2652 unsigned long flags
;
2653 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
2657 ad_write(devc
, 16, ad_read(devc
, 16) & ~0x40);
2658 devc
->timer_running
= 0;
2659 restore_flags(flags
);
2662 static void ad1848_tmr_restart(int dev
)
2664 unsigned long flags
;
2665 ad1848_info
*devc
= (ad1848_info
*) audio_devs
[dev
]->devc
;
2667 if (current_interval
== 0)
2672 ad_write(devc
, 16, ad_read(devc
, 16) | 0x40);
2673 devc
->timer_running
= 1;
2674 restore_flags(flags
);
2677 static struct sound_lowlev_timer ad1848_tmr
=
2686 static int ad1848_tmr_install(int dev
)
2688 if (timer_installed
!= -1)
2689 return 0; /* Don't install another timer */
2691 timer_installed
= ad1848_tmr
.dev
= dev
;
2692 sound_timer_init(&ad1848_tmr
, audio_devs
[dev
]->name
);
2699 EXPORT_SYMBOL(ad1848_detect
);
2700 EXPORT_SYMBOL(ad1848_init
);
2701 EXPORT_SYMBOL(ad1848_unload
);
2702 EXPORT_SYMBOL(ad1848_control
);
2703 EXPORT_SYMBOL(adintr
);
2704 EXPORT_SYMBOL(probe_ms_sound
);
2705 EXPORT_SYMBOL(attach_ms_sound
);
2706 EXPORT_SYMBOL(unload_ms_sound
);
2710 MODULE_PARM(io
, "i"); /* I/O for a raw AD1848 card */
2711 MODULE_PARM(irq
, "i"); /* IRQ to use */
2712 MODULE_PARM(dma
, "i"); /* First DMA channel */
2713 MODULE_PARM(dma2
, "i"); /* Second DMA channel */
2714 MODULE_PARM(type
, "i"); /* Card type */
2715 MODULE_PARM(deskpro_xl
, "i"); /* Special magic for Deskpro XL boxen */
2716 MODULE_PARM(deskpro_m
, "i"); /* Special magic for Deskpro M box */
2717 MODULE_PARM(soundpro
, "i"); /* More special magic for SoundPro chips */
2725 static int loaded
= 0;
2727 struct address_info hw_config
;
2729 int init_module(void)
2731 printk(KERN_INFO
"ad1848/cs4248 codec driver Copyright (C) by Hannu Savolainen 1993-1996\n");
2734 if(irq
== -1 || dma
== -1)
2736 printk(KERN_WARNING
"ad1848: must give I/O , IRQ and DMA.\n");
2739 hw_config
.irq
= irq
;
2740 hw_config
.io_base
= io
;
2741 hw_config
.dma
= dma
;
2742 hw_config
.dma2
= dma2
;
2743 hw_config
.card_subtype
= type
;
2744 if(!probe_ms_sound(&hw_config
))
2746 attach_ms_sound(&hw_config
);
2753 void cleanup_module(void)
2757 unload_ms_sound(&hw_config
);