setup enviroment for compilation
[linux-2.4.21-pre4.git] / drivers / sound / ac97_codec.c
1
2 /*
3  * ac97_codec.c: Generic AC97 mixer/modem module
4  *
5  * Derived from ac97 mixer in maestro and trident driver.
6  *
7  * Copyright 2000 Silicon Integrated System Corporation
8  *
9  *      This program is free software; you can redistribute it and/or modify
10  *      it under the terms of the GNU General Public License as published by
11  *      the Free Software Foundation; either version 2 of the License, or
12  *      (at your option) any later version.
13  *
14  *      This program is distributed in the hope that it will be useful,
15  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  *      GNU General Public License for more details.
18  *
19  *      You should have received a copy of the GNU General Public License
20  *      along with this program; if not, write to the Free Software
21  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22  *
23  **************************************************************************
24  *
25  * The Intel Audio Codec '97 specification is available at the Intel
26  * audio homepage: http://developer.intel.com/ial/scalableplatforms/audio/
27  *
28  * The specification itself is currently available at:
29  * ftp://download.intel.com/ial/scalableplatforms/ac97r22.pdf
30  *
31  **************************************************************************
32  *
33  * History
34  * Mar 28, 2002 Randolph Bentson <bentson@holmsjoen.com>
35  *      corrections to support WM9707 in ViewPad 1000
36  * v0.4 Mar 15 2000 Ollie Lho
37  *      dual codecs support verified with 4 channels output
38  * v0.3 Feb 22 2000 Ollie Lho
39  *      bug fix for record mask setting
40  * v0.2 Feb 10 2000 Ollie Lho
41  *      add ac97_read_proc for /proc/driver/{vendor}/ac97
42  * v0.1 Jan 14 2000 Ollie Lho <ollie@sis.com.tw> 
43  *      Isolated from trident.c to support multiple ac97 codec
44  */
45 #include <linux/module.h>
46 #include <linux/version.h>
47 #include <linux/kernel.h>
48 #include <linux/string.h>
49 #include <linux/errno.h>
50 #include <linux/bitops.h>
51 #include <linux/delay.h>
52 #include <linux/ac97_codec.h>
53 #include <asm/uaccess.h>
54
55 #define CODEC_ID_BUFSZ 14
56
57 static int ac97_read_mixer(struct ac97_codec *codec, int oss_channel);
58 static void ac97_write_mixer(struct ac97_codec *codec, int oss_channel, 
59                              unsigned int left, unsigned int right);
60 static void ac97_set_mixer(struct ac97_codec *codec, unsigned int oss_mixer, unsigned int val );
61 static int ac97_recmask_io(struct ac97_codec *codec, int rw, int mask);
62 static int ac97_mixer_ioctl(struct ac97_codec *codec, unsigned int cmd, unsigned long arg);
63
64 static int ac97_init_mixer(struct ac97_codec *codec);
65
66 static int wolfson_init00(struct ac97_codec * codec);
67 static int wolfson_init03(struct ac97_codec * codec);
68 static int wolfson_init04(struct ac97_codec * codec);
69 static int tritech_init(struct ac97_codec * codec);
70 static int tritech_maestro_init(struct ac97_codec * codec);
71 static int sigmatel_9708_init(struct ac97_codec *codec);
72 static int sigmatel_9721_init(struct ac97_codec *codec);
73 static int sigmatel_9744_init(struct ac97_codec *codec);
74 static int ad1886_init(struct ac97_codec *codec);
75 static int eapd_control(struct ac97_codec *codec, int);
76 static int crystal_digital_control(struct ac97_codec *codec, int mode);
77
78
79 /*
80  *      AC97 operations.
81  *
82  *      If you are adding a codec then you should be able to use
83  *              eapd_ops - any codec that supports EAPD amp control (most)
84  *              null_ops - any ancient codec that supports nothing
85  *
86  *      The three functions are
87  *              init - used for non AC97 standard initialisation
88  *              amplifier - used to do amplifier control (1=on 0=off)
89  *              digital - switch to digital modes (0 = analog)
90  *
91  *      Not all codecs support all features, not all drivers use all the
92  *      operations yet
93  */
94  
95 static struct ac97_ops null_ops = { NULL, NULL, NULL };
96 static struct ac97_ops default_ops = { NULL, eapd_control, NULL };
97 static struct ac97_ops wolfson_ops00 = { wolfson_init00, NULL, NULL };
98 static struct ac97_ops wolfson_ops03 = { wolfson_init03, NULL, NULL };
99 static struct ac97_ops wolfson_ops04 = { wolfson_init04, NULL, NULL };
100 static struct ac97_ops tritech_ops = { tritech_init, NULL, NULL };
101 static struct ac97_ops tritech_m_ops = { tritech_maestro_init, NULL, NULL };
102 static struct ac97_ops sigmatel_9708_ops = { sigmatel_9708_init, NULL, NULL };
103 static struct ac97_ops sigmatel_9721_ops = { sigmatel_9721_init, NULL, NULL };
104 static struct ac97_ops sigmatel_9744_ops = { sigmatel_9744_init, NULL, NULL };
105 static struct ac97_ops crystal_digital_ops = { NULL, eapd_control, crystal_digital_control };
106 static struct ac97_ops ad1886_ops = { ad1886_init, eapd_control, NULL };
107
108 /* sorted by vendor/device id */
109 static const struct {
110         u32 id;
111         char *name;
112         struct ac97_ops *ops;
113 } ac97_codec_ids[] = {
114         {0x41445303, "Analog Devices AD1819",   &null_ops},
115         {0x41445340, "Analog Devices AD1881",   &null_ops},
116         {0x41445348, "Analog Devices AD1881A",  &null_ops},
117         {0x41445360, "Analog Devices AD1885",   &default_ops},
118         {0x41445361, "Analog Devices AD1886",   &ad1886_ops},
119         {0x41445460, "Analog Devices AD1885",   &default_ops},
120         {0x41445461, "Analog Devices AD1886",   &ad1886_ops},
121         {0x414B4D00, "Asahi Kasei AK4540",      &null_ops},
122         {0x414B4D01, "Asahi Kasei AK4542",      &null_ops},
123         {0x414B4D02, "Asahi Kasei AK4543",      &null_ops},
124         {0x414C4710, "ALC200/200P",             &null_ops},
125         {0x414C4720, "ALC650",                  &null_ops},
126         {0x43525900, "Cirrus Logic CS4297",     &default_ops},
127         {0x43525903, "Cirrus Logic CS4297",     &default_ops},
128         {0x43525913, "Cirrus Logic CS4297A rev A", &default_ops},
129         {0x43525914, "Cirrus Logic CS4297A rev B", &default_ops},
130         {0x43525923, "Cirrus Logic CS4298",     &null_ops},
131         {0x4352592B, "Cirrus Logic CS4294",     &null_ops},
132         {0x4352592D, "Cirrus Logic CS4294",     &null_ops},
133         {0x43525931, "Cirrus Logic CS4299 rev A", &crystal_digital_ops},
134         {0x43525933, "Cirrus Logic CS4299 rev C", &crystal_digital_ops},
135         {0x43525934, "Cirrus Logic CS4299 rev D", &crystal_digital_ops},
136         {0x45838308, "ESS Allegro ES1988",      &null_ops},
137         {0x49434511, "ICE1232",                 &null_ops}, /* I hope --jk */
138         {0x4e534331, "National Semiconductor LM4549", &null_ops},
139         {0x53494c22, "Silicon Laboratory Si3036", &null_ops},
140         {0x53494c23, "Silicon Laboratory Si3038", &null_ops},
141         {0x545200FF, "TriTech TR?????",         &tritech_m_ops},
142         {0x54524102, "TriTech TR28022",         &null_ops},
143         {0x54524103, "TriTech TR28023",         &null_ops},
144         {0x54524106, "TriTech TR28026",         &null_ops},
145         {0x54524108, "TriTech TR28028",         &tritech_ops},
146         {0x54524123, "TriTech TR A5",           &null_ops},
147         {0x574D4C00, "Wolfson WM9700A",         &wolfson_ops00},
148         {0x574D4C03, "Wolfson WM9703/WM9707",   &wolfson_ops03},
149         {0x574D4C04, "Wolfson WM9704M/WM9704Q", &wolfson_ops04},
150         {0x83847600, "SigmaTel STAC????",       &null_ops},
151         {0x83847604, "SigmaTel STAC9701/3/4/5", &null_ops},
152         {0x83847605, "SigmaTel STAC9704",       &null_ops},
153         {0x83847608, "SigmaTel STAC9708",       &sigmatel_9708_ops},
154         {0x83847609, "SigmaTel STAC9721/23",    &sigmatel_9721_ops},
155         {0x83847644, "SigmaTel STAC9744/45",    &sigmatel_9744_ops},
156         {0x83847656, "SigmaTel STAC9756/57",    &sigmatel_9744_ops},
157         {0x83847666, "SigmaTel STAC9750T",      &sigmatel_9744_ops},
158         {0x83847684, "SigmaTel STAC9783/84?",   &null_ops},
159         {0x57454301, "Winbond 83971D",          &null_ops},
160 };
161
162 static const char *ac97_stereo_enhancements[] =
163 {
164         /*   0 */ "No 3D Stereo Enhancement",
165         /*   1 */ "Analog Devices Phat Stereo",
166         /*   2 */ "Creative Stereo Enhancement",
167         /*   3 */ "National Semi 3D Stereo Enhancement",
168         /*   4 */ "YAMAHA Ymersion",
169         /*   5 */ "BBE 3D Stereo Enhancement",
170         /*   6 */ "Crystal Semi 3D Stereo Enhancement",
171         /*   7 */ "Qsound QXpander",
172         /*   8 */ "Spatializer 3D Stereo Enhancement",
173         /*   9 */ "SRS 3D Stereo Enhancement",
174         /*  10 */ "Platform Tech 3D Stereo Enhancement",
175         /*  11 */ "AKM 3D Audio",
176         /*  12 */ "Aureal Stereo Enhancement",
177         /*  13 */ "Aztech 3D Enhancement",
178         /*  14 */ "Binaura 3D Audio Enhancement",
179         /*  15 */ "ESS Technology Stereo Enhancement",
180         /*  16 */ "Harman International VMAx",
181         /*  17 */ "Nvidea 3D Stereo Enhancement",
182         /*  18 */ "Philips Incredible Sound",
183         /*  19 */ "Texas Instruments 3D Stereo Enhancement",
184         /*  20 */ "VLSI Technology 3D Stereo Enhancement",
185         /*  21 */ "TriTech 3D Stereo Enhancement",
186         /*  22 */ "Realtek 3D Stereo Enhancement",
187         /*  23 */ "Samsung 3D Stereo Enhancement",
188         /*  24 */ "Wolfson Microelectronics 3D Enhancement",
189         /*  25 */ "Delta Integration 3D Enhancement",
190         /*  26 */ "SigmaTel 3D Enhancement",
191         /*  27 */ "Winbond 3D Stereo Enhancement",
192         /*  28 */ "Rockwell 3D Stereo Enhancement",
193         /*  29 */ "Reserved 29",
194         /*  30 */ "Reserved 30",
195         /*  31 */ "Reserved 31"
196 };
197
198 /* this table has default mixer values for all OSS mixers. */
199 static struct mixer_defaults {
200         int mixer;
201         unsigned int value;
202 } mixer_defaults[SOUND_MIXER_NRDEVICES] = {
203         /* all values 0 -> 100 in bytes */
204         {SOUND_MIXER_VOLUME,    0x4343},
205         {SOUND_MIXER_BASS,      0x4343},
206         {SOUND_MIXER_TREBLE,    0x4343},
207         {SOUND_MIXER_PCM,       0x4343},
208         {SOUND_MIXER_SPEAKER,   0x4343},
209         {SOUND_MIXER_LINE,      0x4343},
210         {SOUND_MIXER_MIC,       0x0000},
211         {SOUND_MIXER_CD,        0x4343},
212         {SOUND_MIXER_ALTPCM,    0x4343},
213         {SOUND_MIXER_IGAIN,     0x4343},
214         {SOUND_MIXER_LINE1,     0x4343},
215         {SOUND_MIXER_PHONEIN,   0x4343},
216         {SOUND_MIXER_PHONEOUT,  0x4343},
217         {SOUND_MIXER_VIDEO,     0x4343},
218         {-1,0}
219 };
220
221 /* table to scale scale from OSS mixer value to AC97 mixer register value */    
222 static struct ac97_mixer_hw {
223         unsigned char offset;
224         int scale;
225 } ac97_hw[SOUND_MIXER_NRDEVICES]= {
226         [SOUND_MIXER_VOLUME]    =       {AC97_MASTER_VOL_STEREO,64},
227         [SOUND_MIXER_BASS]      =       {AC97_MASTER_TONE,      16},
228         [SOUND_MIXER_TREBLE]    =       {AC97_MASTER_TONE,      16},
229         [SOUND_MIXER_PCM]       =       {AC97_PCMOUT_VOL,       32},
230         [SOUND_MIXER_SPEAKER]   =       {AC97_PCBEEP_VOL,       16},
231         [SOUND_MIXER_LINE]      =       {AC97_LINEIN_VOL,       32},
232         [SOUND_MIXER_MIC]       =       {AC97_MIC_VOL,          32},
233         [SOUND_MIXER_CD]        =       {AC97_CD_VOL,           32},
234         [SOUND_MIXER_ALTPCM]    =       {AC97_HEADPHONE_VOL,    64},
235         [SOUND_MIXER_IGAIN]     =       {AC97_RECORD_GAIN,      16},
236         [SOUND_MIXER_LINE1]     =       {AC97_AUX_VOL,          32},
237         [SOUND_MIXER_PHONEIN]   =       {AC97_PHONE_VOL,        32},
238         [SOUND_MIXER_PHONEOUT]  =       {AC97_MASTER_VOL_MONO,  64},
239         [SOUND_MIXER_VIDEO]     =       {AC97_VIDEO_VOL,        32},
240 };
241
242 /* the following tables allow us to go from OSS <-> ac97 quickly. */
243 enum ac97_recsettings {
244         AC97_REC_MIC=0,
245         AC97_REC_CD,
246         AC97_REC_VIDEO,
247         AC97_REC_AUX,
248         AC97_REC_LINE,
249         AC97_REC_STEREO, /* combination of all enabled outputs..  */
250         AC97_REC_MONO,        /*.. or the mono equivalent */
251         AC97_REC_PHONE
252 };
253
254 static const unsigned int ac97_rm2oss[] = {
255         [AC97_REC_MIC]   = SOUND_MIXER_MIC,
256         [AC97_REC_CD]    = SOUND_MIXER_CD,
257         [AC97_REC_VIDEO] = SOUND_MIXER_VIDEO,
258         [AC97_REC_AUX]   = SOUND_MIXER_LINE1,
259         [AC97_REC_LINE]  = SOUND_MIXER_LINE,
260         [AC97_REC_STEREO]= SOUND_MIXER_IGAIN,
261         [AC97_REC_PHONE] = SOUND_MIXER_PHONEIN
262 };
263
264 /* indexed by bit position */
265 static const unsigned int ac97_oss_rm[] = {
266         [SOUND_MIXER_MIC]       = AC97_REC_MIC,
267         [SOUND_MIXER_CD]        = AC97_REC_CD,
268         [SOUND_MIXER_VIDEO]     = AC97_REC_VIDEO,
269         [SOUND_MIXER_LINE1]     = AC97_REC_AUX,
270         [SOUND_MIXER_LINE]      = AC97_REC_LINE,
271         [SOUND_MIXER_IGAIN]     = AC97_REC_STEREO,
272         [SOUND_MIXER_PHONEIN]   = AC97_REC_PHONE
273 };
274
275 /* reads the given OSS mixer from the ac97 the caller must have insured that the ac97 knows
276    about that given mixer, and should be holding a spinlock for the card */
277 static int ac97_read_mixer(struct ac97_codec *codec, int oss_channel) 
278 {
279         u16 val;
280         int ret = 0;
281         int scale;
282         struct ac97_mixer_hw *mh = &ac97_hw[oss_channel];
283
284         val = codec->codec_read(codec , mh->offset);
285
286         if (val & AC97_MUTE) {
287                 ret = 0;
288         } else if (AC97_STEREO_MASK & (1 << oss_channel)) {
289                 /* nice stereo mixers .. */
290                 int left,right;
291
292                 left = (val >> 8)  & 0x7f;
293                 right = val  & 0x7f;
294
295                 if (oss_channel == SOUND_MIXER_IGAIN) {
296                         right = (right * 100) / mh->scale;
297                         left = (left * 100) / mh->scale;
298                 } else {
299                         /* these may have 5 or 6 bit resolution */
300                         if(oss_channel == SOUND_MIXER_VOLUME || oss_channel == SOUND_MIXER_ALTPCM)
301                                 scale = (1 << codec->bit_resolution);
302                         else
303                                 scale = mh->scale;
304
305                         right = 100 - ((right * 100) / scale);
306                         left = 100 - ((left * 100) / scale);
307                 }
308                 ret = left | (right << 8);
309         } else if (oss_channel == SOUND_MIXER_SPEAKER) {
310                 ret = 100 - ((((val & 0x1e)>>1) * 100) / mh->scale);
311         } else if (oss_channel == SOUND_MIXER_PHONEIN) {
312                 ret = 100 - (((val & 0x1f) * 100) / mh->scale);
313         } else if (oss_channel == SOUND_MIXER_PHONEOUT) {
314                 scale = (1 << codec->bit_resolution);
315                 ret = 100 - (((val & 0x1f) * 100) / scale);
316         } else if (oss_channel == SOUND_MIXER_MIC) {
317                 ret = 100 - (((val & 0x1f) * 100) / mh->scale);
318                 /*  the low bit is optional in the tone sliders and masking
319                     it lets us avoid the 0xf 'bypass'.. */
320         } else if (oss_channel == SOUND_MIXER_BASS) {
321                 ret = 100 - ((((val >> 8) & 0xe) * 100) / mh->scale);
322         } else if (oss_channel == SOUND_MIXER_TREBLE) {
323                 ret = 100 - (((val & 0xe) * 100) / mh->scale);
324         }
325
326 #ifdef DEBUG
327         printk("ac97_codec: read OSS mixer %2d (%s ac97 register 0x%02x), "
328                "0x%04x -> 0x%04x\n",
329                oss_channel, codec->id ? "Secondary" : "Primary",
330                mh->offset, val, ret);
331 #endif
332
333         return ret;
334 }
335
336 /* write the OSS encoded volume to the given OSS encoded mixer, again caller's job to
337    make sure all is well in arg land, call with spinlock held */
338 static void ac97_write_mixer(struct ac97_codec *codec, int oss_channel,
339                       unsigned int left, unsigned int right)
340 {
341         u16 val = 0;
342         int scale;
343         struct ac97_mixer_hw *mh = &ac97_hw[oss_channel];
344
345 #ifdef DEBUG
346         printk("ac97_codec: wrote OSS mixer %2d (%s ac97 register 0x%02x), "
347                "left vol:%2d, right vol:%2d:",
348                oss_channel, codec->id ? "Secondary" : "Primary",
349                mh->offset, left, right);
350 #endif
351
352         if (AC97_STEREO_MASK & (1 << oss_channel)) {
353                 /* stereo mixers */
354                 if (left == 0 && right == 0) {
355                         val = AC97_MUTE;
356                 } else {
357                         if (oss_channel == SOUND_MIXER_IGAIN) {
358                                 right = (right * mh->scale) / 100;
359                                 left = (left * mh->scale) / 100;
360                                 if (right >= mh->scale)
361                                         right = mh->scale-1;
362                                 if (left >= mh->scale)
363                                         left = mh->scale-1;
364                         } else {
365                                 /* these may have 5 or 6 bit resolution */
366                                 if (oss_channel == SOUND_MIXER_VOLUME ||
367                                     oss_channel == SOUND_MIXER_ALTPCM)
368                                         scale = (1 << codec->bit_resolution);
369                                 else
370                                         scale = mh->scale;
371
372                                 right = ((100 - right) * scale) / 100;
373                                 left = ((100 - left) * scale) / 100;
374                                 if (right >= scale)
375                                         right = scale-1;
376                                 if (left >= scale)
377                                         left = scale-1;
378                         }
379                         val = (left << 8) | right;
380                 }
381         } else if (oss_channel == SOUND_MIXER_BASS) {
382                 val = codec->codec_read(codec , mh->offset) & ~0x0f00;
383                 left = ((100 - left) * mh->scale) / 100;
384                 if (left >= mh->scale)
385                         left = mh->scale-1;
386                 val |= (left << 8) & 0x0e00;
387         } else if (oss_channel == SOUND_MIXER_TREBLE) {
388                 val = codec->codec_read(codec , mh->offset) & ~0x000f;
389                 left = ((100 - left) * mh->scale) / 100;
390                 if (left >= mh->scale)
391                         left = mh->scale-1;
392                 val |= left & 0x000e;
393         } else if(left == 0) {
394                 val = AC97_MUTE;
395         } else if (oss_channel == SOUND_MIXER_SPEAKER) {
396                 left = ((100 - left) * mh->scale) / 100;
397                 if (left >= mh->scale)
398                         left = mh->scale-1;
399                 val = left << 1;
400         } else if (oss_channel == SOUND_MIXER_PHONEIN) {
401                 left = ((100 - left) * mh->scale) / 100;
402                 if (left >= mh->scale)
403                         left = mh->scale-1;
404                 val = left;
405         } else if (oss_channel == SOUND_MIXER_PHONEOUT) {
406                 scale = (1 << codec->bit_resolution);
407                 left = ((100 - left) * scale) / 100;
408                 if (left >= mh->scale)
409                         left = mh->scale-1;
410                 val = left;
411         } else if (oss_channel == SOUND_MIXER_MIC) {
412                 val = codec->codec_read(codec , mh->offset) & ~0x801f;
413                 left = ((100 - left) * mh->scale) / 100;
414                 if (left >= mh->scale)
415                         left = mh->scale-1;
416                 val |= left;
417                 /*  the low bit is optional in the tone sliders and masking
418                     it lets us avoid the 0xf 'bypass'.. */
419         }
420 #ifdef DEBUG
421         printk(" 0x%04x", val);
422 #endif
423
424         codec->codec_write(codec, mh->offset, val);
425
426 #ifdef DEBUG
427         val = codec->codec_read(codec, mh->offset);
428         printk(" -> 0x%04x\n", val);
429 #endif
430 }
431
432 /* a thin wrapper for write_mixer */
433 static void ac97_set_mixer(struct ac97_codec *codec, unsigned int oss_mixer, unsigned int val ) 
434 {
435         unsigned int left,right;
436
437         /* cleanse input a little */
438         right = ((val >> 8)  & 0xff) ;
439         left = (val  & 0xff) ;
440
441         if (right > 100) right = 100;
442         if (left > 100) left = 100;
443
444         codec->mixer_state[oss_mixer] = (right << 8) | left;
445         codec->write_mixer(codec, oss_mixer, left, right);
446 }
447
448 /* read or write the recmask, the ac97 can really have left and right recording
449    inputs independantly set, but OSS doesn't seem to want us to express that to
450    the user. the caller guarantees that we have a supported bit set, and they
451    must be holding the card's spinlock */
452 static int ac97_recmask_io(struct ac97_codec *codec, int rw, int mask) 
453 {
454         unsigned int val;
455
456         if (rw) {
457                 /* read it from the card */
458                 val = codec->codec_read(codec, AC97_RECORD_SELECT);
459 #ifdef DEBUG
460                 printk("ac97_codec: ac97 recmask to set to 0x%04x\n", val);
461 #endif
462                 return (1 << ac97_rm2oss[val & 0x07]);
463         }
464
465         /* else, write the first set in the mask as the
466            output */    
467         /* clear out current set value first (AC97 supports only 1 input!) */
468         val = (1 << ac97_rm2oss[codec->codec_read(codec, AC97_RECORD_SELECT) & 0x07]);
469         if (mask != val)
470             mask &= ~val;
471        
472         val = ffs(mask); 
473         val = ac97_oss_rm[val-1];
474         val |= val << 8;  /* set both channels */
475
476 #ifdef DEBUG
477         printk("ac97_codec: setting ac97 recmask to 0x%04x\n", val);
478 #endif
479
480         codec->codec_write(codec, AC97_RECORD_SELECT, val);
481
482         return 0;
483 };
484
485 static int ac97_mixer_ioctl(struct ac97_codec *codec, unsigned int cmd, unsigned long arg)
486 {
487         int i, val = 0;
488
489         if (cmd == SOUND_MIXER_INFO) {
490                 mixer_info info;
491                 strncpy(info.id, codec->name, sizeof(info.id));
492                 strncpy(info.name, codec->name, sizeof(info.name));
493                 info.modify_counter = codec->modcnt;
494                 if (copy_to_user((void *)arg, &info, sizeof(info)))
495                         return -EFAULT;
496                 return 0;
497         }
498         if (cmd == SOUND_OLD_MIXER_INFO) {
499                 _old_mixer_info info;
500                 strncpy(info.id, codec->name, sizeof(info.id));
501                 strncpy(info.name, codec->name, sizeof(info.name));
502                 if (copy_to_user((void *)arg, &info, sizeof(info)))
503                         return -EFAULT;
504                 return 0;
505         }
506
507         if (_IOC_TYPE(cmd) != 'M' || _SIOC_SIZE(cmd) != sizeof(int))
508                 return -EINVAL;
509
510         if (cmd == OSS_GETVERSION)
511                 return put_user(SOUND_VERSION, (int *)arg);
512
513         if (_SIOC_DIR(cmd) == _SIOC_READ) {
514                 switch (_IOC_NR(cmd)) {
515                 case SOUND_MIXER_RECSRC: /* give them the current record source */
516                         if (!codec->recmask_io) {
517                                 val = 0;
518                         } else {
519                                 val = codec->recmask_io(codec, 1, 0);
520                         }
521                         break;
522
523                 case SOUND_MIXER_DEVMASK: /* give them the supported mixers */
524                         val = codec->supported_mixers;
525                         break;
526
527                 case SOUND_MIXER_RECMASK: /* Arg contains a bit for each supported recording source */
528                         val = codec->record_sources;
529                         break;
530
531                 case SOUND_MIXER_STEREODEVS: /* Mixer channels supporting stereo */
532                         val = codec->stereo_mixers;
533                         break;
534
535                 case SOUND_MIXER_CAPS:
536                         val = SOUND_CAP_EXCL_INPUT;
537                         break;
538
539                 default: /* read a specific mixer */
540                         i = _IOC_NR(cmd);
541
542                         if (!supported_mixer(codec, i)) 
543                                 return -EINVAL;
544
545                         /* do we ever want to touch the hardware? */
546                         /* val = codec->read_mixer(codec, i); */
547                         val = codec->mixer_state[i];
548                         break;
549                 }
550                 return put_user(val, (int *)arg);
551         }
552
553         if (_SIOC_DIR(cmd) == (_SIOC_WRITE|_SIOC_READ)) {
554                 codec->modcnt++;
555                 if (get_user(val, (int *)arg))
556                         return -EFAULT;
557
558                 switch (_IOC_NR(cmd)) {
559                 case SOUND_MIXER_RECSRC: /* Arg contains a bit for each recording source */
560                         if (!codec->recmask_io) return -EINVAL;
561                         if (!val) return 0;
562                         if (!(val &= codec->record_sources)) return -EINVAL;
563
564                         codec->recmask_io(codec, 0, val);
565
566                         return 0;
567                 default: /* write a specific mixer */
568                         i = _IOC_NR(cmd);
569
570                         if (!supported_mixer(codec, i)) 
571                                 return -EINVAL;
572
573                         ac97_set_mixer(codec, i, val);
574
575                         return 0;
576                 }
577         }
578         return -EINVAL;
579 }
580
581 /* entry point for /proc/driver/controller_vendor/ac97/%d */
582 int ac97_read_proc (char *page, char **start, off_t off,
583                     int count, int *eof, void *data)
584 {
585         int len = 0, cap, extid, val, id1, id2;
586         struct ac97_codec *codec;
587         int is_ac97_20 = 0;
588
589         if ((codec = data) == NULL)
590                 return -ENODEV;
591
592         id1 = codec->codec_read(codec, AC97_VENDOR_ID1);
593         id2 = codec->codec_read(codec, AC97_VENDOR_ID2);
594         len += sprintf (page+len, "Vendor name      : %s\n", codec->name);
595         len += sprintf (page+len, "Vendor id        : %04X %04X\n", id1, id2);
596
597         extid = codec->codec_read(codec, AC97_EXTENDED_ID);
598         extid &= ~((1<<2)|(1<<4)|(1<<5)|(1<<10)|(1<<11)|(1<<12)|(1<<13));
599         len += sprintf (page+len, "AC97 Version     : %s\n",
600                         extid ? "2.0 or later" : "1.0");
601         if (extid) is_ac97_20 = 1;
602
603         cap = codec->codec_read(codec, AC97_RESET);
604         len += sprintf (page+len, "Capabilities     :%s%s%s%s%s%s\n",
605                         cap & 0x0001 ? " -dedicated MIC PCM IN channel-" : "",
606                         cap & 0x0002 ? " -reserved1-" : "",
607                         cap & 0x0004 ? " -bass & treble-" : "",
608                         cap & 0x0008 ? " -simulated stereo-" : "",
609                         cap & 0x0010 ? " -headphone out-" : "",
610                         cap & 0x0020 ? " -loudness-" : "");
611         val = cap & 0x00c0;
612         len += sprintf (page+len, "DAC resolutions  :%s%s%s\n",
613                         " -16-bit-",
614                         val & 0x0040 ? " -18-bit-" : "",
615                         val & 0x0080 ? " -20-bit-" : "");
616         val = cap & 0x0300;
617         len += sprintf (page+len, "ADC resolutions  :%s%s%s\n",
618                         " -16-bit-",
619                         val & 0x0100 ? " -18-bit-" : "",
620                         val & 0x0200 ? " -20-bit-" : "");
621         len += sprintf (page+len, "3D enhancement   : %s\n",
622                         ac97_stereo_enhancements[(cap >> 10) & 0x1f]);
623
624         val = codec->codec_read(codec, AC97_GENERAL_PURPOSE);
625         len += sprintf (page+len, "POP path         : %s 3D\n"
626                         "Sim. stereo      : %s\n"
627                         "3D enhancement   : %s\n"
628                         "Loudness         : %s\n"
629                         "Mono output      : %s\n"
630                         "MIC select       : %s\n"
631                         "ADC/DAC loopback : %s\n",
632                         val & 0x8000 ? "post" : "pre",
633                         val & 0x4000 ? "on" : "off",
634                         val & 0x2000 ? "on" : "off",
635                         val & 0x1000 ? "on" : "off",
636                         val & 0x0200 ? "MIC" : "MIX",
637                         val & 0x0100 ? "MIC2" : "MIC1",
638                         val & 0x0080 ? "on" : "off");
639
640         extid = codec->codec_read(codec, AC97_EXTENDED_ID);
641         cap = extid;
642         len += sprintf (page+len, "Ext Capabilities :%s%s%s%s%s%s%s\n",
643                         cap & 0x0001 ? " -var rate PCM audio-" : "",
644                         cap & 0x0002 ? " -2x PCM audio out-" : "",
645                         cap & 0x0008 ? " -var rate MIC in-" : "",
646                         cap & 0x0040 ? " -PCM center DAC-" : "",
647                         cap & 0x0080 ? " -PCM surround DAC-" : "",
648                         cap & 0x0100 ? " -PCM LFE DAC-" : "",
649                         cap & 0x0200 ? " -slot/DAC mappings-" : "");
650         if (is_ac97_20) {
651                 len += sprintf (page+len, "Front DAC rate   : %d\n",
652                                 codec->codec_read(codec, AC97_PCM_FRONT_DAC_RATE));
653         }
654
655         return len;
656 }
657
658 /**
659  *      codec_id        -  Turn id1/id2 into a PnP string
660  *      @id1: Vendor ID1
661  *      @id2: Vendor ID2
662  *      @buf: CODEC_ID_BUFSZ byte buffer
663  *
664  *      Fills buf with a zero terminated PnP ident string for the id1/id2
665  *      pair. For convenience the return is the passed in buffer pointer.
666  */
667  
668 static char *codec_id(u16 id1, u16 id2, char *buf)
669 {
670         if(id1&0x8080) {
671                 snprintf(buf, CODEC_ID_BUFSZ, "0x%04x:0x%04x", id1, id2);
672         } else {
673                 buf[0] = (id1 >> 8);
674                 buf[1] = (id1 & 0xFF);
675                 buf[2] = (id2 >> 8);
676                 snprintf(buf+3, CODEC_ID_BUFSZ - 3, "%d", id2&0xFF);
677         }
678         return buf;
679 }
680  
681 /**
682  *      ac97_probe_codec - Initialize and setup AC97-compatible codec
683  *      @codec: (in/out) Kernel info for a single AC97 codec
684  *
685  *      Reset the AC97 codec, then initialize the mixer and
686  *      the rest of the @codec structure.
687  *
688  *      The codec_read and codec_write fields of @codec are
689  *      required to be setup and working when this function
690  *      is called.  All other fields are set by this function.
691  *
692  *      codec_wait field of @codec can optionally be provided
693  *      when calling this function.  If codec_wait is not %NULL,
694  *      this function will call codec_wait any time it is
695  *      necessary to wait for the audio chip to reach the
696  *      codec-ready state.  If codec_wait is %NULL, then
697  *      the default behavior is to call schedule_timeout.
698  *      Currently codec_wait is used to wait for AC97 codec
699  *      reset to complete. 
700  *
701  *      Returns 1 (true) on success, or 0 (false) on failure.
702  */
703  
704 int ac97_probe_codec(struct ac97_codec *codec)
705 {
706         u16 id1, id2;
707         u16 audio, modem;
708         int i;
709         char cidbuf[CODEC_ID_BUFSZ];
710
711         /* probing AC97 codec, AC97 2.0 says that bit 15 of register 0x00 (reset) should 
712          * be read zero.
713          *
714          * FIXME: is the following comment outdated?  -jgarzik 
715          * Probing of AC97 in this way is not reliable, it is not even SAFE !!
716          */
717         codec->codec_write(codec, AC97_RESET, 0L);
718
719         /* also according to spec, we wait for codec-ready state */     
720         if (codec->codec_wait)
721                 codec->codec_wait(codec);
722         else
723                 udelay(10);
724
725         if ((audio = codec->codec_read(codec, AC97_RESET)) & 0x8000) {
726                 printk(KERN_ERR "ac97_codec: %s ac97 codec not present\n",
727                        (codec->id & 0x2) ? (codec->id&1 ? "4th" : "Tertiary") 
728                        : (codec->id&1 ? "Secondary":  "Primary"));
729                 return 0;
730         }
731
732         /* probe for Modem Codec */
733         codec->codec_write(codec, AC97_EXTENDED_MODEM_ID, 0L);
734         modem = codec->codec_read(codec, AC97_EXTENDED_MODEM_ID) & 1;
735         modem |= (audio&2);
736         audio &= ~2;
737
738         codec->name = NULL;
739         codec->codec_ops = &null_ops;
740
741         id1 = codec->codec_read(codec, AC97_VENDOR_ID1);
742         id2 = codec->codec_read(codec, AC97_VENDOR_ID2);
743         for (i = 0; i < ARRAY_SIZE(ac97_codec_ids); i++) {
744                 if (ac97_codec_ids[i].id == ((id1 << 16) | id2)) {
745                         codec->type = ac97_codec_ids[i].id;
746                         codec->name = ac97_codec_ids[i].name;
747                         codec->codec_ops = ac97_codec_ids[i].ops;
748                         break;
749                 }
750         }
751         if (codec->name == NULL)
752                 codec->name = "Unknown";
753         printk(KERN_INFO "ac97_codec: AC97 %s codec, id: %s (%s)\n", 
754                 modem ? "Modem" : (audio ? "Audio" : ""),
755                codec_id(id1, id2, cidbuf), codec->name);
756
757         return ac97_init_mixer(codec);
758 }
759
760 static int ac97_init_mixer(struct ac97_codec *codec)
761 {
762         u16 cap;
763         int i;
764
765         cap = codec->codec_read(codec, AC97_RESET);
766
767         /* mixer masks */
768         codec->supported_mixers = AC97_SUPPORTED_MASK;
769         codec->stereo_mixers = AC97_STEREO_MASK;
770         codec->record_sources = AC97_RECORD_MASK;
771         if (!(cap & 0x04))
772                 codec->supported_mixers &= ~(SOUND_MASK_BASS|SOUND_MASK_TREBLE);
773         if (!(cap & 0x10))
774                 codec->supported_mixers &= ~SOUND_MASK_ALTPCM;
775
776         /* detect bit resolution */
777         codec->codec_write(codec, AC97_MASTER_VOL_STEREO, 0x2020);
778         if(codec->codec_read(codec, AC97_MASTER_VOL_STEREO) == 0x2020)
779                 codec->bit_resolution = 6;
780         else
781                 codec->bit_resolution = 5;
782
783         /* generic OSS to AC97 wrapper */
784         codec->read_mixer = ac97_read_mixer;
785         codec->write_mixer = ac97_write_mixer;
786         codec->recmask_io = ac97_recmask_io;
787         codec->mixer_ioctl = ac97_mixer_ioctl;
788
789         /* codec specific initialization for 4-6 channel output or secondary codec stuff */
790         if (codec->codec_ops->init != NULL) {
791                 codec->codec_ops->init(codec);
792         }
793
794         /* initialize mixer channel volumes */
795         for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
796                 struct mixer_defaults *md = &mixer_defaults[i];
797                 if (md->mixer == -1) 
798                         break;
799                 if (!supported_mixer(codec, md->mixer)) 
800                         continue;
801                 ac97_set_mixer(codec, md->mixer, md->value);
802         }
803
804         return 1;
805 }
806
807 #define AC97_SIGMATEL_ANALOG    0x6c    /* Analog Special */
808 #define AC97_SIGMATEL_DAC2INVERT 0x6e
809 #define AC97_SIGMATEL_BIAS1     0x70
810 #define AC97_SIGMATEL_BIAS2     0x72
811 #define AC97_SIGMATEL_MULTICHN  0x74    /* Multi-Channel programming */
812 #define AC97_SIGMATEL_CIC1      0x76
813 #define AC97_SIGMATEL_CIC2      0x78
814
815
816 static int sigmatel_9708_init(struct ac97_codec * codec)
817 {
818         u16 codec72, codec6c;
819
820         codec72 = codec->codec_read(codec, AC97_SIGMATEL_BIAS2) & 0x8000;
821         codec6c = codec->codec_read(codec, AC97_SIGMATEL_ANALOG);
822
823         if ((codec72==0) && (codec6c==0)) {
824                 codec->codec_write(codec, AC97_SIGMATEL_CIC1, 0xabba);
825                 codec->codec_write(codec, AC97_SIGMATEL_CIC2, 0x1000);
826                 codec->codec_write(codec, AC97_SIGMATEL_BIAS1, 0xabba);
827                 codec->codec_write(codec, AC97_SIGMATEL_BIAS2, 0x0007);
828         } else if ((codec72==0x8000) && (codec6c==0)) {
829                 codec->codec_write(codec, AC97_SIGMATEL_CIC1, 0xabba);
830                 codec->codec_write(codec, AC97_SIGMATEL_CIC2, 0x1001);
831                 codec->codec_write(codec, AC97_SIGMATEL_DAC2INVERT, 0x0008);
832         } else if ((codec72==0x8000) && (codec6c==0x0080)) {
833                 /* nothing */
834         }
835         codec->codec_write(codec, AC97_SIGMATEL_MULTICHN, 0x0000);
836         return 0;
837 }
838
839
840 static int sigmatel_9721_init(struct ac97_codec * codec)
841 {
842         /* Only set up secondary codec */
843         if (codec->id == 0)
844                 return 0;
845
846         codec->codec_write(codec, AC97_SURROUND_MASTER, 0L);
847
848         /* initialize SigmaTel STAC9721/23 as secondary codec, decoding AC link
849            sloc 3,4 = 0x01, slot 7,8 = 0x00, */
850         codec->codec_write(codec, AC97_SIGMATEL_MULTICHN, 0x00);
851
852         /* we don't have the crystal when we are on an AMR card, so use
853            BIT_CLK as our clock source. Write the magic word ABBA and read
854            back to enable register 0x78 */
855         codec->codec_write(codec, AC97_SIGMATEL_CIC1, 0xabba);
856         codec->codec_read(codec, AC97_SIGMATEL_CIC1);
857
858         /* sync all the clocks*/
859         codec->codec_write(codec, AC97_SIGMATEL_CIC2, 0x3802);
860
861         return 0;
862 }
863
864
865 static int sigmatel_9744_init(struct ac97_codec * codec)
866 {
867         // patch for SigmaTel
868         codec->codec_write(codec, AC97_SIGMATEL_CIC1, 0xabba);
869         codec->codec_write(codec, AC97_SIGMATEL_CIC2, 0x0000); // is this correct? --jk
870         codec->codec_write(codec, AC97_SIGMATEL_BIAS1, 0xabba);
871         codec->codec_write(codec, AC97_SIGMATEL_BIAS2, 0x0002);
872         codec->codec_write(codec, AC97_SIGMATEL_MULTICHN, 0x0000);
873         return 0;
874 }
875
876
877 static int wolfson_init00(struct ac97_codec * codec)
878 {
879         /* This initialization is suspect, but not known to be wrong.
880            It was copied from the initialization for the WM9704Q, but
881            that same sequence is known to fail for the WM9707.  Thus
882            this warning may help someone with hardware to test
883            this code. */
884         codec->codec_write(codec, 0x72, 0x0808);
885         codec->codec_write(codec, 0x74, 0x0808);
886
887         // patch for DVD noise
888         codec->codec_write(codec, 0x5a, 0x0200);
889
890         // init vol as PCM vol
891         codec->codec_write(codec, 0x70,
892                 codec->codec_read(codec, AC97_PCMOUT_VOL));
893
894         codec->codec_write(codec, AC97_SURROUND_MASTER, 0x0000);
895         return 0;
896 }
897
898
899 static int wolfson_init03(struct ac97_codec * codec)
900 {
901         /* this is known to work for the ViewSonic ViewPad 1000 */
902         codec->codec_write(codec, 0x72, 0x0808);
903         codec->codec_write(codec, 0x20, 0x8000);
904         return 0;
905 }
906
907
908 static int wolfson_init04(struct ac97_codec * codec)
909 {
910         codec->codec_write(codec, 0x72, 0x0808);
911         codec->codec_write(codec, 0x74, 0x0808);
912
913         // patch for DVD noise
914         codec->codec_write(codec, 0x5a, 0x0200);
915
916         // init vol as PCM vol
917         codec->codec_write(codec, 0x70,
918                 codec->codec_read(codec, AC97_PCMOUT_VOL));
919
920         codec->codec_write(codec, AC97_SURROUND_MASTER, 0x0000);
921         return 0;
922 }
923
924
925 static int tritech_init(struct ac97_codec * codec)
926 {
927         codec->codec_write(codec, 0x26, 0x0300);
928         codec->codec_write(codec, 0x26, 0x0000);
929         codec->codec_write(codec, AC97_SURROUND_MASTER, 0x0000);
930         codec->codec_write(codec, AC97_RESERVED_3A, 0x0000);
931         return 0;
932 }
933
934
935 /* copied from drivers/sound/maestro.c */
936 static int tritech_maestro_init(struct ac97_codec * codec)
937 {
938         /* no idea what this does */
939         codec->codec_write(codec, 0x2A, 0x0001);
940         codec->codec_write(codec, 0x2C, 0x0000);
941         codec->codec_write(codec, 0x2C, 0XFFFF);
942         return 0;
943 }
944
945
946
947 /* 
948  *      Presario700 workaround 
949  *      for Jack Sense/SPDIF Register mis-setting causing
950  *      no audible output
951  *      by Santiago Nullo 04/05/2002
952  */
953
954 #define AC97_AD1886_JACK_SENSE 0x72
955
956 static int ad1886_init(struct ac97_codec * codec)
957 {
958         /* from AD1886 Specs */
959         codec->codec_write(codec, AC97_AD1886_JACK_SENSE, 0x0010);
960         return 0;
961 }
962
963
964
965
966 /*
967  *      This is basically standard AC97. It should work as a default for
968  *      almost all modern codecs. Note that some cards wire EAPD *backwards*
969  *      That side of it is up to the card driver not us to cope with.
970  *
971  */
972
973 static int eapd_control(struct ac97_codec * codec, int on)
974 {
975         if(on)
976                 codec->codec_write(codec, AC97_POWER_CONTROL,
977                         codec->codec_read(codec, AC97_POWER_CONTROL)|0x8000);
978         else
979                 codec->codec_write(codec, AC97_POWER_CONTROL,
980                         codec->codec_read(codec, AC97_POWER_CONTROL)&~0x8000);
981         return 0;
982 }
983
984 /*
985  *      Crystal digital audio control (CS4299
986  */
987  
988 static int crystal_digital_control(struct ac97_codec *codec, int mode)
989 {
990         u16 cv;
991
992         switch(mode)
993         {
994                 case 0: cv = 0x0; break;        /* SPEN off */
995                 case 1: cv = 0x8004; break;     /* 48KHz digital */
996                 case 2: cv = 0x8104; break;     /* 44.1KHz digital */
997                 default:
998                         return -1;              /* Not supported yet(eg AC3) */
999         }
1000         codec->codec_write(codec, 0x68, cv);
1001         return 0;
1002 }
1003
1004 /* copied from drivers/sound/maestro.c */
1005 #if 0  /* there has been 1 person on the planet with a pt101 that we
1006         know of.  If they care, they can put this back in :) */
1007 static int pt101_init(struct ac97_codec * codec)
1008 {
1009         printk(KERN_INFO "ac97_codec: PT101 Codec detected, initializing but _not_ installing mixer device.\n");
1010         /* who knows.. */
1011         codec->codec_write(codec, 0x2A, 0x0001);
1012         codec->codec_write(codec, 0x2C, 0x0000);
1013         codec->codec_write(codec, 0x2C, 0xFFFF);
1014         codec->codec_write(codec, 0x10, 0x9F1F);
1015         codec->codec_write(codec, 0x12, 0x0808);
1016         codec->codec_write(codec, 0x14, 0x9F1F);
1017         codec->codec_write(codec, 0x16, 0x9F1F);
1018         codec->codec_write(codec, 0x18, 0x0404);
1019         codec->codec_write(codec, 0x1A, 0x0000);
1020         codec->codec_write(codec, 0x1C, 0x0000);
1021         codec->codec_write(codec, 0x02, 0x0404);
1022         codec->codec_write(codec, 0x04, 0x0808);
1023         codec->codec_write(codec, 0x0C, 0x801F);
1024         codec->codec_write(codec, 0x0E, 0x801F);
1025         return 0;
1026 }
1027 #endif
1028         
1029
1030 EXPORT_SYMBOL(ac97_read_proc);
1031 EXPORT_SYMBOL(ac97_probe_codec);
1032
1033 /*
1034  *      AC97 library support routines
1035  */     
1036  
1037 /**
1038  *      ac97_set_dac_rate       -       set codec rate adaption
1039  *      @codec: ac97 code
1040  *      @rate: rate in hertz
1041  *
1042  *      Set the DAC rate. Assumes the codec supports VRA. The caller is
1043  *      expected to have checked this little detail.
1044  */
1045  
1046 unsigned int ac97_set_dac_rate(struct ac97_codec *codec, unsigned int rate)
1047 {
1048         unsigned int new_rate = rate;
1049         u32 dacp;
1050         u32 mast_vol, phone_vol, mono_vol, pcm_vol;
1051         u32 mute_vol = 0x8000;  /* The mute volume? */
1052
1053         if(rate != codec->codec_read(codec, AC97_PCM_FRONT_DAC_RATE))
1054         {
1055                 /* Mute several registers */
1056                 mast_vol = codec->codec_read(codec, AC97_MASTER_VOL_STEREO);
1057                 mono_vol = codec->codec_read(codec, AC97_MASTER_VOL_MONO);
1058                 phone_vol = codec->codec_read(codec, AC97_HEADPHONE_VOL);
1059                 pcm_vol = codec->codec_read(codec, AC97_PCMOUT_VOL);
1060                 codec->codec_write(codec, AC97_MASTER_VOL_STEREO, mute_vol);
1061                 codec->codec_write(codec, AC97_MASTER_VOL_MONO, mute_vol);
1062                 codec->codec_write(codec, AC97_HEADPHONE_VOL, mute_vol);
1063                 codec->codec_write(codec, AC97_PCMOUT_VOL, mute_vol);
1064                 
1065                 /* Power down the DAC */
1066                 dacp=codec->codec_read(codec, AC97_POWER_CONTROL);
1067                 codec->codec_write(codec, AC97_POWER_CONTROL, dacp|0x0200);
1068                 /* Load the rate and read the effective rate */
1069                 codec->codec_write(codec, AC97_PCM_FRONT_DAC_RATE, rate);
1070                 new_rate=codec->codec_read(codec, AC97_PCM_FRONT_DAC_RATE);
1071                 /* Power it back up */
1072                 codec->codec_write(codec, AC97_POWER_CONTROL, dacp);
1073
1074                 /* Restore volumes */
1075                 codec->codec_write(codec, AC97_MASTER_VOL_STEREO, mast_vol);
1076                 codec->codec_write(codec, AC97_MASTER_VOL_MONO, mono_vol);
1077                 codec->codec_write(codec, AC97_HEADPHONE_VOL, phone_vol);
1078                 codec->codec_write(codec, AC97_PCMOUT_VOL, pcm_vol);
1079         }
1080         return new_rate;
1081 }
1082
1083 EXPORT_SYMBOL(ac97_set_dac_rate);
1084
1085 /**
1086  *      ac97_set_adc_rate       -       set codec rate adaption
1087  *      @codec: ac97 code
1088  *      @rate: rate in hertz
1089  *
1090  *      Set the ADC rate. Assumes the codec supports VRA. The caller is
1091  *      expected to have checked this little detail.
1092  */
1093
1094 unsigned int ac97_set_adc_rate(struct ac97_codec *codec, unsigned int rate)
1095 {
1096         unsigned int new_rate = rate;
1097         u32 dacp;
1098
1099         if(rate != codec->codec_read(codec, AC97_PCM_LR_ADC_RATE))
1100         {
1101                 /* Power down the ADC */
1102                 dacp=codec->codec_read(codec, AC97_POWER_CONTROL);
1103                 codec->codec_write(codec, AC97_POWER_CONTROL, dacp|0x0100);
1104                 /* Load the rate and read the effective rate */
1105                 codec->codec_write(codec, AC97_PCM_LR_ADC_RATE, rate);
1106                 new_rate=codec->codec_read(codec, AC97_PCM_LR_ADC_RATE);
1107                 /* Power it back up */
1108                 codec->codec_write(codec, AC97_POWER_CONTROL, dacp);
1109         }
1110         return new_rate;
1111 }
1112
1113 EXPORT_SYMBOL(ac97_set_adc_rate);
1114
1115 int ac97_save_state(struct ac97_codec *codec)
1116 {
1117         return 0;       
1118 }
1119
1120 EXPORT_SYMBOL(ac97_save_state);
1121
1122 int ac97_restore_state(struct ac97_codec *codec)
1123 {
1124         int i;
1125         unsigned int left, right, val;
1126
1127         for (i = 0; i < SOUND_MIXER_NRDEVICES; i++) {
1128                 if (!supported_mixer(codec, i)) 
1129                         continue;
1130
1131                 val = codec->mixer_state[i];
1132                 right = val >> 8;
1133                 left = val  & 0xff;
1134                 codec->write_mixer(codec, i, left, right);
1135         }
1136         return 0;
1137 }
1138
1139 EXPORT_SYMBOL(ac97_restore_state);
1140
1141 MODULE_LICENSE("GPL");