Home | History | Annotate | Line # | Download | only in ic
ac97.c revision 1.39
      1 /*      $NetBSD: ac97.c,v 1.39 2003/01/20 07:22:15 simonb Exp $ */
      2 /*	$OpenBSD: ac97.c,v 1.8 2000/07/19 09:01:35 csapuntz Exp $	*/
      3 
      4 /*
      5  * Copyright (c) 1999, 2000 Constantine Sapuntzakis
      6  *
      7  * Author:        Constantine Sapuntzakis <csapuntz (at) stanford.edu>
      8  *
      9  * Redistribution and use in source and binary forms, with or without
     10  * modification, are permitted provided that the following conditions
     11  * are met:
     12  * 1. Redistributions of source code must retain the above copyright
     13  *    notice, this list of conditions and the following disclaimer.
     14  * 2. Redistributions in binary form must reproduce the above copyright
     15  *    notice, this list of conditions and the following disclaimer in the
     16  *    documentation and/or other materials provided with the distribution.
     17  * 3. The name of the author may not be used to endorse or promote
     18  *    products derived from this software without specific prior written
     19  *    permission.
     20  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS
     21  * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
     22  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     23  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE
     24  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
     26  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
     27  * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
     28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     29  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
     30  * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
     31  * DAMAGE
     32  */
     33 
     34 /* Partially inspired by FreeBSD's sys/dev/pcm/ac97.c. It came with
     35    the following copyright */
     36 
     37 /*
     38  * Copyright (c) 1999 Cameron Grant <gandalf (at) vilnya.demon.co.uk>
     39  * All rights reserved.
     40  *
     41  * Redistribution and use in source and binary forms, with or without
     42  * modification, are permitted provided that the following conditions
     43  * are met:
     44  * 1. Redistributions of source code must retain the above copyright
     45  *    notice, this list of conditions and the following disclaimer.
     46  * 2. Redistributions in binary form must reproduce the above copyright
     47  *    notice, this list of conditions and the following disclaimer in the
     48  *    documentation and/or other materials provided with the distribution.
     49  *
     50  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     51  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     52  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     53  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     54  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     55  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     56  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     57  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     58  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     59  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     60  * SUCH DAMAGE.
     61  *
     62  * $FreeBSD$
     63  */
     64 
     65 #include <sys/cdefs.h>
     66 __KERNEL_RCSID(0, "$NetBSD: ac97.c,v 1.39 2003/01/20 07:22:15 simonb Exp $");
     67 
     68 #include <sys/param.h>
     69 #include <sys/systm.h>
     70 #include <sys/kernel.h>
     71 #include <sys/malloc.h>
     72 #include <sys/device.h>
     73 
     74 #include <sys/audioio.h>
     75 #include <dev/audio_if.h>
     76 
     77 #include <dev/ic/ac97reg.h>
     78 #include <dev/ic/ac97var.h>
     79 
     80 #define Ac97Ntone	"tone"
     81 #define Ac97Nphone	"phone"
     82 
     83 static const struct audio_mixer_enum ac97_on_off = { 2,
     84 					       { { { AudioNoff } , 0 },
     85 						 { { AudioNon }  , 1 } }};
     86 
     87 static const struct audio_mixer_enum ac97_mic_select = { 2,
     88 					       { { { AudioNmicrophone "0" },
     89 						   0 },
     90 						 { { AudioNmicrophone "1" },
     91 						   1 } }};
     92 
     93 static const struct audio_mixer_enum ac97_mono_select = { 2,
     94 					       { { { AudioNmixerout },
     95 						   0 },
     96 						 { { AudioNmicrophone },
     97 						   1 } }};
     98 
     99 static const struct audio_mixer_enum ac97_source = { 8,
    100 					       { { { AudioNmicrophone } , 0 },
    101 						 { { AudioNcd }, 1 },
    102 						 { { AudioNvideo }, 2 },
    103 						 { { AudioNaux }, 3 },
    104 						 { { AudioNline }, 4 },
    105 						 { { AudioNmixerout }, 5 },
    106 						 { { AudioNmixerout AudioNmono }, 6 },
    107 						 { { Ac97Nphone }, 7 }}};
    108 
    109 /*
    110  * Due to different values for each source that uses these structures,
    111  * the ac97_query_devinfo function sets delta in mixer_devinfo_t using
    112  * ac97_source_info.bits.
    113  */
    114 static const struct audio_mixer_value ac97_volume_stereo = { { AudioNvolume },
    115 						       2 };
    116 
    117 static const struct audio_mixer_value ac97_volume_mono = { { AudioNvolume },
    118 						     1 };
    119 
    120 #define WRAP(a)  &a, sizeof(a)
    121 
    122 const struct ac97_source_info {
    123 	const char *class;
    124 	const char *device;
    125 	const char *qualifier;
    126 
    127 	int  type;
    128 	const void *info;
    129 	int  info_size;
    130 
    131 	u_int8_t  reg;
    132 	u_int16_t default_value;
    133 	u_int8_t  bits:3;
    134 	u_int8_t  ofs:4;
    135 	u_int8_t  mute:1;
    136 	u_int8_t  polarity:1;   /* Does 0 == MAX or MIN */
    137 	enum {
    138 		CHECK_NONE = 0,
    139 		CHECK_SURROUND,
    140 		CHECK_CENTER,
    141 		CHECK_LFE,
    142 		CHECK_HEADPHONES,
    143 		CHECK_TONE,
    144 		CHECK_MIC,
    145 		CHECK_LOUDNESS,
    146 		CHECK_3D
    147 	} req_feature;
    148 
    149 	int  prev;
    150 	int  next;
    151 	int  mixer_class;
    152 } source_info[] = {
    153 	{ AudioCinputs,		NULL,		NULL,
    154 	  AUDIO_MIXER_CLASS, },
    155 	{ AudioCoutputs,	NULL,		NULL,
    156 	  AUDIO_MIXER_CLASS, },
    157 	{ AudioCrecord,		NULL,		NULL,
    158 	  AUDIO_MIXER_CLASS, },
    159 	/* Stereo master volume*/
    160 	{ AudioCoutputs,	AudioNmaster,	NULL,
    161 	  AUDIO_MIXER_VALUE, WRAP(ac97_volume_stereo),
    162 	  AC97_REG_MASTER_VOLUME, 0x8000, 5, 0, 1,
    163 	},
    164 	/* Mono volume */
    165 	{ AudioCoutputs,	AudioNmono,	NULL,
    166 	  AUDIO_MIXER_VALUE, WRAP(ac97_volume_mono),
    167 	  AC97_REG_MASTER_VOLUME_MONO, 0x8000, 6, 0, 1,
    168 	},
    169 	{ AudioCoutputs,	AudioNmono,	AudioNsource,
    170 	  AUDIO_MIXER_ENUM, WRAP(ac97_mono_select),
    171 	  AC97_REG_GP, 0x0000, 1, 9, 0,
    172 	},
    173 	/* Headphone volume */
    174 	{ AudioCoutputs,	AudioNheadphone, NULL,
    175 	  AUDIO_MIXER_VALUE, WRAP(ac97_volume_stereo),
    176 	  AC97_REG_HEADPHONE_VOLUME, 0x8000, 6, 0, 1, 0, CHECK_HEADPHONES
    177 	},
    178 	/* Surround volume - logic hard coded for mute */
    179 	{ AudioCoutputs,	AudioNsurround,	NULL,
    180 	  AUDIO_MIXER_VALUE, WRAP(ac97_volume_stereo),
    181 	  AC97_REG_SURR_MASTER, 0x8080, 5, 0, 1, 0, CHECK_SURROUND
    182 	},
    183 	/* Center volume*/
    184 	{ AudioCoutputs,	AudioNcenter,	NULL,
    185 	  AUDIO_MIXER_VALUE, WRAP(ac97_volume_mono),
    186 	  AC97_REG_CENTER_LFE_MASTER, 0x8080, 5, 0, 0, 0, CHECK_CENTER
    187 	},
    188 	{ AudioCoutputs,	AudioNcenter,	AudioNmute,
    189 	  AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
    190 	  AC97_REG_CENTER_LFE_MASTER, 0x8080, 1, 7, 0, 0, CHECK_CENTER
    191 	},
    192 	/* LFE volume*/
    193 	{ AudioCoutputs,	AudioNlfe,	NULL,
    194 	  AUDIO_MIXER_VALUE, WRAP(ac97_volume_mono),
    195 	  AC97_REG_CENTER_LFE_MASTER, 0x8080, 5, 8, 0, 0, CHECK_LFE
    196 	},
    197 	{ AudioCoutputs,	AudioNlfe,	AudioNmute,
    198 	  AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
    199 	  AC97_REG_CENTER_LFE_MASTER, 0x8080, 1, 15, 0, 0, CHECK_LFE
    200 	},
    201 	/* Tone */
    202 	{ AudioCoutputs,	Ac97Ntone,	NULL,
    203 	  AUDIO_MIXER_VALUE, WRAP(ac97_volume_stereo),
    204 	  AC97_REG_MASTER_TONE, 0x0f0f, 4, 0, 0, 0, CHECK_TONE
    205 	},
    206 	/* PC Beep Volume */
    207 	{ AudioCinputs,		AudioNspeaker,	NULL,
    208 	  AUDIO_MIXER_VALUE, WRAP(ac97_volume_mono),
    209 	  AC97_REG_PCBEEP_VOLUME, 0x0000, 4, 1, 1,
    210 	},
    211 
    212 	/* Phone */
    213 	{ AudioCinputs,		Ac97Nphone,	NULL,
    214 	  AUDIO_MIXER_VALUE, WRAP(ac97_volume_mono),
    215 	  AC97_REG_PHONE_VOLUME, 0x8008, 5, 0, 1,
    216 	},
    217 	/* Mic Volume */
    218 	{ AudioCinputs,		AudioNmicrophone, NULL,
    219 	  AUDIO_MIXER_VALUE, WRAP(ac97_volume_mono),
    220 	  AC97_REG_MIC_VOLUME, 0x8008, 5, 0, 1,
    221 	},
    222 	{ AudioCinputs,		AudioNmicrophone, AudioNpreamp,
    223 	  AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
    224 	  AC97_REG_MIC_VOLUME, 0x8008, 1, 6, 0,
    225 	},
    226 	{ AudioCinputs,		AudioNmicrophone, AudioNsource,
    227 	  AUDIO_MIXER_ENUM, WRAP(ac97_mic_select),
    228 	  AC97_REG_GP, 0x0000, 1, 8, 0,
    229 	},
    230 	/* Line in Volume */
    231 	{ AudioCinputs,		AudioNline,	NULL,
    232 	  AUDIO_MIXER_VALUE, WRAP(ac97_volume_stereo),
    233 	  AC97_REG_LINEIN_VOLUME, 0x8808, 5, 0, 1,
    234 	},
    235 	/* CD Volume */
    236 	{ AudioCinputs,		AudioNcd,	NULL,
    237 	  AUDIO_MIXER_VALUE, WRAP(ac97_volume_stereo),
    238 	  AC97_REG_CD_VOLUME, 0x8808, 5, 0, 1,
    239 	},
    240 	/* Video Volume */
    241 	{ AudioCinputs,		AudioNvideo,	NULL,
    242 	  AUDIO_MIXER_VALUE, WRAP(ac97_volume_stereo),
    243 	  AC97_REG_VIDEO_VOLUME, 0x8808, 5, 0, 1,
    244 	},
    245 	/* AUX volume */
    246 	{ AudioCinputs,		AudioNaux,	NULL,
    247 	  AUDIO_MIXER_VALUE, WRAP(ac97_volume_stereo),
    248 	  AC97_REG_AUX_VOLUME, 0x8808, 5, 0, 1,
    249 	},
    250 	/* PCM out volume */
    251 	{ AudioCinputs,		AudioNdac,	NULL,
    252 	  AUDIO_MIXER_VALUE, WRAP(ac97_volume_stereo),
    253 	  AC97_REG_PCMOUT_VOLUME, 0x8808, 5, 0, 1,
    254 	},
    255 	/* Record Source - some logic for this is hard coded - see below */
    256 	{ AudioCrecord,		AudioNsource,	NULL,
    257 	  AUDIO_MIXER_ENUM, WRAP(ac97_source),
    258 	  AC97_REG_RECORD_SELECT, 0x0000, 3, 0, 0,
    259 	},
    260 	/* Record Gain */
    261 	{ AudioCrecord,		AudioNvolume,	NULL,
    262 	  AUDIO_MIXER_VALUE, WRAP(ac97_volume_stereo),
    263 	  AC97_REG_RECORD_GAIN, 0x8000, 4, 0, 1, 1,
    264 	},
    265 	/* Record Gain mic */
    266 	{ AudioCrecord,		AudioNmicrophone, NULL,
    267 	  AUDIO_MIXER_VALUE, WRAP(ac97_volume_mono),
    268 	  AC97_REG_RECORD_GAIN_MIC, 0x8000, 4, 0, 1, 1, CHECK_MIC
    269 	},
    270 	/* */
    271 	{ AudioCoutputs,	AudioNloudness,	NULL,
    272 	  AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
    273 	  AC97_REG_GP, 0x0000, 1, 12, 0, 0, CHECK_LOUDNESS
    274 	},
    275 	{ AudioCoutputs,	AudioNspatial,	NULL,
    276 	  AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
    277 	  AC97_REG_GP, 0x0000, 1, 13, 0, 1, CHECK_3D
    278 	},
    279 	{ AudioCoutputs,	AudioNspatial,	"center",
    280 	  AUDIO_MIXER_VALUE, WRAP(ac97_volume_mono),
    281 	  AC97_REG_3D_CONTROL, 0x0000, 4, 8, 0, 1, CHECK_3D
    282 	},
    283 	{ AudioCoutputs,	AudioNspatial,	"depth",
    284 	  AUDIO_MIXER_VALUE, WRAP(ac97_volume_mono),
    285 	  AC97_REG_3D_CONTROL, 0x0000, 4, 0, 0, 1, CHECK_3D
    286 	},
    287 
    288 	/* Missing features: Simulated Stereo, POP, Loopback mode */
    289 } ;
    290 
    291 #define SOURCE_INFO_SIZE (sizeof(source_info)/sizeof(source_info[0]))
    292 
    293 /*
    294  * Check out http://developer.intel.com/pc-supp/platform/ac97/ for
    295  * information on AC-97
    296  */
    297 
    298 struct ac97_softc {
    299 	/* ac97_codec_if must be at the first of ac97_softc. */
    300 	struct ac97_codec_if codec_if;
    301 
    302 	struct ac97_host_if *host_if;
    303 
    304 #define MAX_SOURCES	(2 * SOURCE_INFO_SIZE)
    305 	struct ac97_source_info source_info[MAX_SOURCES];
    306 	int num_source_info;
    307 
    308 	enum ac97_host_flags host_flags;
    309 	unsigned int ac97_clock; /* usually 48000 */
    310 #define AC97_STANDARD_CLOCK	48000U
    311 	u_int16_t caps;		/* -> AC97_REG_RESET */
    312 	u_int16_t ext_id;	/* -> AC97_REG_EXT_AUDIO_ID */
    313 	u_int16_t shadow_reg[128];
    314 };
    315 
    316 int ac97_mixer_get_port __P((struct ac97_codec_if *self, mixer_ctrl_t *cp));
    317 int ac97_mixer_set_port __P((struct ac97_codec_if *self, mixer_ctrl_t *));
    318 int ac97_query_devinfo __P((struct ac97_codec_if *self, mixer_devinfo_t *));
    319 int ac97_get_portnum_by_name __P((struct ac97_codec_if *, const char *,
    320 				  const char *, const char *));
    321 void ac97_restore_shadow __P((struct ac97_codec_if *self));
    322 int ac97_set_rate(struct ac97_codec_if *codec_if, int target, u_long *rate);
    323 void ac97_set_clock(struct ac97_codec_if *codec_if, unsigned int clock);
    324 u_int16_t ac97_get_extcaps(struct ac97_codec_if *codec_if);
    325 int ac97_add_port(struct ac97_softc *as, const struct ac97_source_info *src);
    326 
    327 static void ac97_alc650_init(struct ac97_softc *);
    328 static void ac97_vt1616_init(struct ac97_softc *);
    329 
    330 struct ac97_codec_if_vtbl ac97civ = {
    331 	ac97_mixer_get_port,
    332 	ac97_mixer_set_port,
    333 	ac97_query_devinfo,
    334 	ac97_get_portnum_by_name,
    335 	ac97_restore_shadow,
    336 	ac97_get_extcaps,
    337 	ac97_set_rate,
    338 	ac97_set_clock,
    339 };
    340 
    341 static const struct ac97_codecid {
    342 	u_int32_t id;
    343 	u_int32_t mask;
    344 	const char *name;
    345 	void (*init)(struct ac97_softc *);
    346 } ac97codecid[] = {
    347 	/*
    348 	 * Analog Devices SoundMAX
    349 	 * http://www.soundmax.com/products/information/codecs.html
    350 	 * http://www.analog.com/productSelection/pdf/AD1881A_0.pdf
    351 	 * http://www.analog.com/productSelection/pdf/AD1885_0.pdf
    352 	 * http://www.analog.com/productSelection/pdf/AD1981A_0.pdf
    353 	 * http://www.analog.com/productSelection/pdf/AD1981B_0.pdf
    354 	 */
    355 	{ AC97_CODEC_ID('A', 'D', 'S', 3),
    356 	  0xffffffff,			"Analog Devices AD1819B" },
    357 	{ AC97_CODEC_ID('A', 'D', 'S', 0x40),
    358 	  0xffffffff,			"Analog Devices AD1881" },
    359 	{ AC97_CODEC_ID('A', 'D', 'S', 0x48),
    360 	  0xffffffff,			"Analog Devices AD1881A" },
    361 	{ AC97_CODEC_ID('A', 'D', 'S', 0x60),
    362 	  0xffffffff,			"Analog Devices AD1885" },
    363 	{ AC97_CODEC_ID('A', 'D', 'S', 0x61),
    364 	  0xffffffff,			"Analog Devices AD1886" },
    365 	{ AC97_CODEC_ID('A', 'D', 'S', 0x63),
    366 	  0xffffffff,			"Analog Devices AD1886A" },
    367 	{ AC97_CODEC_ID('A', 'D', 'S', 0x70),
    368 	  0xffffffff,			"Analog Devices AD1981" },
    369 	{ AC97_CODEC_ID('A', 'D', 'S', 0x72),
    370 	  0xffffffff,			"Analog Devices AD1981A" },
    371 	{ AC97_CODEC_ID('A', 'D', 'S', 0x74),
    372 	  0xffffffff,			"Analog Devices AD1981B" },
    373 	{ AC97_CODEC_ID('A', 'D', 'S', 0),
    374 	  AC97_VENDOR_ID_MASK,		"Analog Devices unknown" },
    375 
    376 	/*
    377 	 * Datasheets:
    378 	 *	http://www.asahi-kasei.co.jp/akm/usa/product/ak4541/ek4541.pdf
    379 	 *	http://www.asahi-kasei.co.jp/akm/usa/product/ak4543/ek4543.pdf
    380 	 *	http://www.asahi-kasei.co.jp/akm/usa/product/ak4544a/ek4544a.pdf
    381 	 *	http://www.asahi-kasei.co.jp/akm/usa/product/ak4545/ek4545.pdf
    382 	 */
    383 	{ AC97_CODEC_ID('A', 'K', 'M', 0),
    384 	  0xffffffff,			"Asahi Kasei AK4540"	},
    385 	{ AC97_CODEC_ID('A', 'K', 'M', 1),
    386 	  0xffffffff,			"Asahi Kasei AK4542"	},
    387 	{ AC97_CODEC_ID('A', 'K', 'M', 2),
    388 	  0xffffffff,			"Asahi Kasei AK4541/AK4543" },
    389 	{ AC97_CODEC_ID('A', 'K', 'M', 5),
    390 	  0xffffffff,			"Asahi Kasei AK4544" },
    391 	{ AC97_CODEC_ID('A', 'K', 'M', 6),
    392 	  0xffffffff,			"Asahi Kasei AK4544A" },
    393 	{ AC97_CODEC_ID('A', 'K', 'M', 7),
    394 	  0xffffffff,			"Asahi Kasei AK4545" },
    395 	{ AC97_CODEC_ID('A', 'K', 'M', 0),
    396 	  AC97_VENDOR_ID_MASK,		"Asahi Kasei unknown" },
    397 
    398 	/*
    399 	 * Realtek & Avance Logic
    400 	 *	http://www.realtek.com.tw/downloads/downloads1-3.aspx?lineid=5&famid=All&series=All&Spec=True
    401 	 */
    402 	{ AC97_CODEC_ID('A', 'L', 'C', 0x00),
    403 	  0xfffffff0,			"Realtek RL5306"	},
    404 	{ AC97_CODEC_ID('A', 'L', 'C', 0x10),
    405 	  0xfffffff0,			"Realtek RL5382"	},
    406 	{ AC97_CODEC_ID('A', 'L', 'C', 0x20),
    407 	  0xfffffff0,			"Realtek RL5383/RL5522/ALC100"	},
    408 	{ AC97_CODEC_ID('A', 'L', 'G', 0x10),
    409 	  0xffffffff,			"Avance Logic ALC200/ALC201"	},
    410 	{ AC97_CODEC_ID('A', 'L', 'G', 0x20),
    411 	  0xffffffff,			"Avance Logic ALC650", ac97_alc650_init },
    412 	{ AC97_CODEC_ID('A', 'L', 'G', 0x30),
    413 	  0xffffffff,			"Avance Logic ALC101"	},
    414 	{ AC97_CODEC_ID('A', 'L', 'G', 0x40),
    415 	  0xffffffff,			"Avance Logic ALC202"	},
    416 	{ AC97_CODEC_ID('A', 'L', 'G', 0x50),
    417 	  0xffffffff,			"Avance Logic ALC250"	},
    418 	{ AC97_CODEC_ID('A', 'L', 'C', 0),
    419 	  AC97_VENDOR_ID_MASK,		"Realtek unknown"	},
    420 	{ AC97_CODEC_ID('A', 'L', 'G', 0),
    421 	  AC97_VENDOR_ID_MASK,		"Avance Logic unknown"	},
    422 
    423 	/* Cirrus Logic, Crystal series:
    424 	 *  'C' 'R' 'Y' 0x0[0-7]  - CS4297
    425 	 *              0x1[0-7]  - CS4297A
    426 	 *              0x2[0-7]  - CS4298
    427 	 *              0x2[8-f]  - CS4294
    428 	 *              0x3[0-7]  - CS4299
    429 	 *              0x4[8-f]  - CS4201
    430 	 *              0x5[8-f]  - CS4205
    431 	 *              0x6[0-7]  - CS4291
    432 	 *              0x7[0-7]  - CS4202
    433 	 * Datasheets:
    434 	 *	http://www.cirrus.com/pubs/cs4297A-5.pdf?DocumentID=593
    435 	 *	http://www.cirrus.com/pubs/cs4294.pdf?DocumentID=32
    436 	 *	http://www.cirrus.com/pubs/cs4299-5.pdf?DocumentID=594
    437 	 *	http://www.cirrus.com/pubs/cs4201-2.pdf?DocumentID=492
    438 	 *	http://www.cirrus.com/pubs/cs4205-2.pdf?DocumentID=492
    439 	 *	http://www.cirrus.com/pubs/cs4202-1.pdf?DocumentID=852
    440 	 */
    441 	{ AC97_CODEC_ID('C', 'R', 'Y', 0x00),
    442 	  0xfffffff8,			"Crystal CS4297",	},
    443 	{ AC97_CODEC_ID('C', 'R', 'Y', 0x10),
    444 	  0xfffffff8,			"Crystal CS4297A",	},
    445 	{ AC97_CODEC_ID('C', 'R', 'Y', 0x20),
    446 	  0xfffffff8,			"Crystal CS4298",	},
    447 	{ AC97_CODEC_ID('C', 'R', 'Y', 0x28),
    448 	  0xfffffff8,			"Crystal CS4294",	},
    449 	{ AC97_CODEC_ID('C', 'R', 'Y', 0x30),
    450 	  0xfffffff8,			"Crystal CS4299",	},
    451 	{ AC97_CODEC_ID('C', 'R', 'Y', 0x48),
    452 	  0xfffffff8,			"Crystal CS4201",	},
    453 	{ AC97_CODEC_ID('C', 'R', 'Y', 0x58),
    454 	  0xfffffff8,			"Crystal CS4205",	},
    455 	{ AC97_CODEC_ID('C', 'R', 'Y', 0x60),
    456 	  0xfffffff8,			"Crystal CS4291",	},
    457 	{ AC97_CODEC_ID('C', 'R', 'Y', 0x70),
    458 	  0xfffffff8,			"Crystal CS4202",	},
    459 	{ AC97_CODEC_ID('C', 'R', 'Y', 0),
    460 	  AC97_VENDOR_ID_MASK,		"Cirrus Logic unknown",	},
    461 
    462 	{ 0x45838308, 0xffffffff,	"ESS Technology ES1921", },
    463 	{ 0x45838300, AC97_VENDOR_ID_MASK, "ESS Technology unknown", },
    464 
    465 	{ AC97_CODEC_ID('H', 'R', 'S', 0),
    466 	  0xffffffff,			"Intersil HMP9701",	},
    467 	{ AC97_CODEC_ID('H', 'R', 'S', 0),
    468 	  AC97_VENDOR_ID_MASK,		"Intersil unknown",	},
    469 
    470 	/*
    471 	 * IC Ensemble (VIA)
    472 	 *	http://www.viatech.com/en/datasheet/DS1616.pdf
    473 	 */
    474 	{ AC97_CODEC_ID('I', 'C', 'E', 0x01),
    475 	  0xffffffff,			"ICEnsemble ICE1230/VT1611",	},
    476 	{ AC97_CODEC_ID('I', 'C', 'E', 0x11),
    477 	  0xffffffff,			"ICEnsemble ICE1232/VT1611A",	},
    478 	{ AC97_CODEC_ID('I', 'C', 'E', 0x14),
    479 	  0xffffffff,			"ICEnsemble ICE1232A",	},
    480 	{ AC97_CODEC_ID('I', 'C', 'E', 0x51),
    481 	  0xffffffff,			"VIA Technologies VT1616", ac97_vt1616_init },
    482 	{ AC97_CODEC_ID('I', 'C', 'E', 0),
    483 	  AC97_VENDOR_ID_MASK,		"ICEnsemble unknown",	},
    484 
    485 	{ AC97_CODEC_ID('N', 'S', 'C', 0),
    486 	  0xffffffff,			"National Semiconductor LM454[03568]", },
    487 	{ AC97_CODEC_ID('N', 'S', 'C', 49),
    488 	  0xffffffff,			"National Semiconductor LM4549", },
    489 	{ AC97_CODEC_ID('N', 'S', 'C', 0),
    490 	  AC97_VENDOR_ID_MASK,		"National Semiconductor unknown", },
    491 
    492 	{ AC97_CODEC_ID('S', 'I', 'L', 34),
    493 	  0xffffffff,			"Silicon Laboratory Si3036", },
    494 	{ AC97_CODEC_ID('S', 'I', 'L', 35),
    495 	  0xffffffff,			"Silicon Laboratory Si3038", },
    496 	{ AC97_CODEC_ID('S', 'I', 'L', 0),
    497 	  AC97_VENDOR_ID_MASK,		"Silicon Laboratory unknown", },
    498 
    499 	{ AC97_CODEC_ID('T', 'R', 'A', 2),
    500 	  0xffffffff,			"TriTech TR28022",	},
    501 	{ AC97_CODEC_ID('T', 'R', 'A', 3),
    502 	  0xffffffff,			"TriTech TR28023",	},
    503 	{ AC97_CODEC_ID('T', 'R', 'A', 6),
    504 	  0xffffffff,			"TriTech TR28026",	},
    505 	{ AC97_CODEC_ID('T', 'R', 'A', 8),
    506 	  0xffffffff,			"TriTech TR28028",	},
    507 	{ AC97_CODEC_ID('T', 'R', 'A', 35),
    508 	  0xffffffff,			"TriTech TR28602",	},
    509 	{ AC97_CODEC_ID('T', 'R', 'A', 0),
    510 	  AC97_VENDOR_ID_MASK,		"TriTech unknown",	},
    511 
    512 	{ AC97_CODEC_ID('T', 'X', 'N', 0x20),
    513 	  0xffffffff,			"Texas Instruments TLC320AD9xC", },
    514 	{ AC97_CODEC_ID('T', 'X', 'N', 0),
    515 	  AC97_VENDOR_ID_MASK,		"Texas Instruments unknown", },
    516 
    517 	/*
    518 	 * VIA
    519 	 * http://www.viatech.com/en/multimedia/audio.jsp
    520 	 */
    521 	{ AC97_CODEC_ID('V', 'I', 'A', 0x61),
    522 	  0xffffffff,			"VIA Technologies VT1612A", },
    523 	{ AC97_CODEC_ID('V', 'I', 'A', 0),
    524 	  AC97_VENDOR_ID_MASK,		"VIA Technologies unknown", },
    525 
    526 	{ AC97_CODEC_ID('W', 'E', 'C', 1),
    527 	  0xffffffff,			"Winbond W83971D",	},
    528 	{ AC97_CODEC_ID('W', 'E', 'C', 0),
    529 	  AC97_VENDOR_ID_MASK,		"Winbond unknown",	},
    530 
    531 	/*
    532 	 * http://www.wolfsonmicro.com/product_list.asp?cid=64
    533 	 *	http://www.wolfsonmicro.com/download.asp/did.56/WM9701A.pdf - 00
    534 	 *	http://www.wolfsonmicro.com/download.asp/did.57/WM9703.pdf  - 03
    535 	 *	http://www.wolfsonmicro.com/download.asp/did.58/WM9704M.pdf - 04
    536 	 *	http://www.wolfsonmicro.com/download.asp/did.59/WM9704Q.pdf - 04
    537 	 *	http://www.wolfsonmicro.com/download.asp/did.184/WM9705_Rev34.pdf - 05
    538 	 *	http://www.wolfsonmicro.com/download.asp/did.60/WM9707.pdf  - 03
    539 	 *	http://www.wolfsonmicro.com/download.asp/did.136/WM9708.pdf - 03
    540 	 *	http://www.wolfsonmicro.com/download.asp/did.243/WM9710.pdf - 05
    541 	 */
    542 	{ AC97_CODEC_ID('W', 'M', 'L', 0),
    543 	  0xffffffff,			"Wolfson WM9701A",	},
    544 	{ AC97_CODEC_ID('W', 'M', 'L', 3),
    545 	  0xffffffff,			"Wolfson WM9703/WM9707/WM9708",	},
    546 	{ AC97_CODEC_ID('W', 'M', 'L', 4),
    547 	  0xffffffff,			"Wolfson WM9704",	},
    548 	{ AC97_CODEC_ID('W', 'M', 'L', 5),
    549 	  0xffffffff,			"Wolfson WM9705/WM9710", },
    550 	{ AC97_CODEC_ID('W', 'M', 'L', 0),
    551 	  AC97_VENDOR_ID_MASK,		"Wolfson unknown",	},
    552 
    553 	/*
    554 	 * http://www.yamaha.co.jp/english/product/lsi/us/products/pcaudio.html
    555 	 * Datasheets:
    556 	 *	http://www.yamaha.co.jp/english/product/lsi/us/products/pdf/4MF743A20.pdf
    557 	 *	http://www.yamaha.co.jp/english/product/lsi/us/products/pdf/4MF753A20.pdf
    558 	 */
    559 	{ AC97_CODEC_ID('Y', 'M', 'H', 0),
    560 	  0xffffffff,			"Yamaha YMF743-S",	},
    561 	{ AC97_CODEC_ID('Y', 'M', 'H', 3),
    562 	  0xffffffff,			"Yamaha YMF753-S",	},
    563 	{ AC97_CODEC_ID('Y', 'M', 'H', 0),
    564 	  AC97_VENDOR_ID_MASK,		"Yamaha unknown",	},
    565 
    566 	/*
    567 	 * http://www.sigmatel.com/audio/audio_codecs.htm
    568 	 */
    569 	{ 0x83847600, 0xffffffff,	"SigmaTel STAC9700",	},
    570 	{ 0x83847604, 0xffffffff,	"SigmaTel STAC9701/3/4/5", },
    571 	{ 0x83847605, 0xffffffff,	"SigmaTel STAC9704",	},
    572 	{ 0x83847608, 0xffffffff,	"SigmaTel STAC9708",	},
    573 	{ 0x83847609, 0xffffffff,	"SigmaTel STAC9721/23",	},
    574 	{ 0x83847644, 0xffffffff,	"SigmaTel STAC9744/45",	},
    575 	{ 0x83847650, 0xffffffff,	"SigmaTel STAC9750/51",	},
    576 	{ 0x83847656, 0xffffffff,	"SigmaTel STAC9756/57",	},
    577 	{ 0x83847666, 0xffffffff,	"SigmaTel STAC9766/67",	},
    578 	{ 0x83847684, 0xffffffff,	"SigmaTel STAC9783/84",	},
    579 	{ 0x83847600, AC97_VENDOR_ID_MASK, "SigmaTel unknown",	},
    580 
    581 	{ 0,
    582 	  0,			NULL,			}
    583 };
    584 
    585 static const char * const ac97enhancement[] = {
    586 	"no 3D stereo",
    587 	"Analog Devices Phat Stereo",
    588 	"Creative",
    589 	"National Semi 3D",
    590 	"Yamaha Ymersion",
    591 	"BBE 3D",
    592 	"Crystal Semi 3D",
    593 	"Qsound QXpander",
    594 	"Spatializer 3D",
    595 	"SRS 3D",
    596 	"Platform Tech 3D",
    597 	"AKM 3D",
    598 	"Aureal",
    599 	"AZTECH 3D",
    600 	"Binaura 3D",
    601 	"ESS Technology",
    602 	"Harman International VMAx",
    603 	"Nvidea 3D",
    604 	"Philips Incredible Sound",
    605 	"Texas Instruments' 3D",
    606 	"VLSI Technology 3D",
    607 	"TriTech 3D",
    608 	"Realtek 3D",
    609 	"Samsung 3D",
    610 	"Wolfson Microelectronics 3D",
    611 	"Delta Integration 3D",
    612 	"SigmaTel 3D",
    613 	"KS Waves 3D",
    614 	"Rockwell 3D",
    615 	"Unknown 3D",
    616 	"Unknown 3D",
    617 	"Unknown 3D",
    618 };
    619 
    620 static const char * const ac97feature[] = {
    621 	"dedicated mic channel",
    622 	"reserved",
    623 	"tone",
    624 	"simulated stereo",
    625 	"headphone",
    626 	"bass boost",
    627 	"18 bit DAC",
    628 	"20 bit DAC",
    629 	"18 bit ADC",
    630 	"20 bit ADC"
    631 };
    632 
    633 
    634 int ac97_str_equal __P((const char *, const char *));
    635 int ac97_check_capability(struct ac97_softc *, int);
    636 void ac97_setup_source_info __P((struct ac97_softc *));
    637 void ac97_read __P((struct ac97_softc *, u_int8_t, u_int16_t *));
    638 void ac97_setup_defaults __P((struct ac97_softc *));
    639 int ac97_write __P((struct ac97_softc *, u_int8_t, u_int16_t));
    640 
    641 /* #define AC97_DEBUG 10 */
    642 
    643 #ifdef AUDIO_DEBUG
    644 #define DPRINTF(x)	if (ac97debug) printf x
    645 #define DPRINTFN(n,x)	if (ac97debug>(n)) printf x
    646 #ifdef AC97_DEBUG
    647 int	ac97debug = AC97_DEBUG;
    648 #else
    649 int	ac97debug = 0;
    650 #endif
    651 #else
    652 #define DPRINTF(x)
    653 #define DPRINTFN(n,x)
    654 #endif
    655 
    656 void
    657 ac97_read(as, reg, val)
    658 	struct ac97_softc *as;
    659 	u_int8_t reg;
    660 	u_int16_t *val;
    661 {
    662 
    663 	if (as->host_flags & AC97_HOST_DONT_READ &&
    664 	    (reg != AC97_REG_VENDOR_ID1 && reg != AC97_REG_VENDOR_ID2 &&
    665 	     reg != AC97_REG_RESET)) {
    666 		*val = as->shadow_reg[reg >> 1];
    667 		return;
    668 	}
    669 
    670 	if (as->host_if->read(as->host_if->arg, reg, val)) {
    671 		*val = as->shadow_reg[reg >> 1];
    672 	}
    673 }
    674 
    675 int
    676 ac97_write(as, reg, val)
    677 	struct ac97_softc *as;
    678 	u_int8_t reg;
    679 	u_int16_t val;
    680 {
    681 
    682 	as->shadow_reg[reg >> 1] = val;
    683 
    684 	return (as->host_if->write(as->host_if->arg, reg, val));
    685 }
    686 
    687 void
    688 ac97_setup_defaults(as)
    689 	struct ac97_softc *as;
    690 {
    691 	int idx;
    692 	const struct ac97_source_info *si;
    693 
    694 	memset(as->shadow_reg, 0, sizeof(as->shadow_reg));
    695 
    696 	for (idx = 0; idx < SOURCE_INFO_SIZE; idx++) {
    697 		si = &source_info[idx];
    698 		ac97_write(as, si->reg, si->default_value);
    699 	}
    700 }
    701 
    702 void
    703 ac97_restore_shadow(self)
    704 	struct ac97_codec_if *self;
    705 {
    706 	struct ac97_softc *as = (struct ac97_softc *) self;
    707 	int idx;
    708 	const struct ac97_source_info *si;
    709 
    710 	for (idx = 0; idx < SOURCE_INFO_SIZE; idx++) {
    711 		si = &source_info[idx];
    712 		ac97_write(as, si->reg, as->shadow_reg[si->reg >> 1]);
    713 	}
    714 }
    715 
    716 int
    717 ac97_str_equal(a, b)
    718 	const char *a, *b;
    719 {
    720 	return ((a == b) || (a && b && (!strcmp(a, b))));
    721 }
    722 
    723 int
    724 ac97_check_capability(struct ac97_softc *as, int check)
    725 {
    726 	switch (check) {
    727 	case CHECK_NONE:
    728 		return 1;
    729 	case CHECK_SURROUND:
    730 		return as->ext_id & AC97_EXT_AUDIO_SDAC;
    731 	case CHECK_CENTER:
    732 		return as->ext_id & AC97_EXT_AUDIO_CDAC;
    733 	case CHECK_LFE:
    734 		return as->ext_id & AC97_EXT_AUDIO_LDAC;
    735 	case CHECK_HEADPHONES:
    736 		return as->caps & AC97_CAPS_HEADPHONES;
    737 	case CHECK_TONE:
    738 		return as->caps & AC97_CAPS_TONECTRL;
    739 	case CHECK_MIC:
    740 		return as->caps & AC97_CAPS_MICIN;
    741 	case CHECK_LOUDNESS:
    742 		return as->caps & AC97_CAPS_LOUDNESS;
    743 	case CHECK_3D:
    744 		return AC97_CAPS_ENHANCEMENT(as->caps) != 0;
    745 	default:
    746 		printf("%s: internal error: feature=%d\n", __func__, check);
    747 		return 0;
    748 	}
    749 }
    750 
    751 void
    752 ac97_setup_source_info(as)
    753 	struct ac97_softc *as;
    754 {
    755 	int idx, ouridx;
    756 	struct ac97_source_info *si, *si2;
    757 
    758 	for (idx = 0, ouridx = 0; idx < SOURCE_INFO_SIZE; idx++) {
    759 		si = &as->source_info[ouridx];
    760 
    761 		if (!ac97_check_capability(as, source_info[idx].req_feature))
    762 			continue;
    763 
    764 		memcpy(si, &source_info[idx], sizeof(*si));
    765 
    766 		switch (si->type) {
    767 		case AUDIO_MIXER_CLASS:
    768 			si->mixer_class = ouridx;
    769 			ouridx++;
    770 			break;
    771 		case AUDIO_MIXER_VALUE:
    772 			/* Todo - Test to see if it works */
    773 			ouridx++;
    774 
    775 			/* Add an entry for mute, if necessary */
    776 			if (si->mute) {
    777 				si = &as->source_info[ouridx];
    778 				memcpy(si, &source_info[idx], sizeof(*si));
    779 				si->qualifier = AudioNmute;
    780 				si->type = AUDIO_MIXER_ENUM;
    781 				si->info = &ac97_on_off;
    782 				si->info_size = sizeof(ac97_on_off);
    783 				si->bits = 1;
    784 				si->ofs = 15;
    785 				si->mute = 0;
    786 				si->polarity = 0;
    787 				ouridx++;
    788 			}
    789 			break;
    790 		case AUDIO_MIXER_ENUM:
    791 			/* Todo - Test to see if it works */
    792 			ouridx++;
    793 			break;
    794 		default:
    795 			printf ("ac97: shouldn't get here\n");
    796 			break;
    797 		}
    798 	}
    799 
    800 	as->num_source_info = ouridx;
    801 
    802 	for (idx = 0; idx < as->num_source_info; idx++) {
    803 		int idx2, previdx;
    804 
    805 		si = &as->source_info[idx];
    806 
    807 		/* Find mixer class */
    808 		for (idx2 = 0; idx2 < as->num_source_info; idx2++) {
    809 			si2 = &as->source_info[idx2];
    810 
    811 			if (si2->type == AUDIO_MIXER_CLASS &&
    812 			    ac97_str_equal(si->class,
    813 					   si2->class)) {
    814 				si->mixer_class = idx2;
    815 			}
    816 		}
    817 
    818 
    819 		/* Setup prev and next pointers */
    820 		if (si->prev != 0)
    821 			continue;
    822 
    823 		if (si->qualifier)
    824 			continue;
    825 
    826 		si->prev = AUDIO_MIXER_LAST;
    827 		previdx = idx;
    828 
    829 		for (idx2 = 0; idx2 < as->num_source_info; idx2++) {
    830 			if (idx2 == idx)
    831 				continue;
    832 
    833 			si2 = &as->source_info[idx2];
    834 
    835 			if (!si2->prev &&
    836 			    ac97_str_equal(si->class, si2->class) &&
    837 			    ac97_str_equal(si->device, si2->device)) {
    838 				as->source_info[previdx].next = idx2;
    839 				as->source_info[idx2].prev = previdx;
    840 
    841 				previdx = idx2;
    842 			}
    843 		}
    844 
    845 		as->source_info[previdx].next = AUDIO_MIXER_LAST;
    846 	}
    847 }
    848 
    849 int
    850 ac97_attach(host_if)
    851 	struct ac97_host_if *host_if;
    852 {
    853 	struct ac97_softc *as;
    854 	struct device *sc_dev = (struct device *)host_if->arg;
    855 	int error, i, j;
    856 	u_int32_t id;
    857 	u_int16_t id1, id2;
    858 	u_int16_t extstat, rate;
    859 	mixer_ctrl_t ctl;
    860 	const char *delim;
    861 	void (*initfunc)(struct ac97_softc *);
    862 
    863 	initfunc = NULL;
    864 	as = malloc(sizeof(struct ac97_softc), M_DEVBUF, M_WAITOK|M_ZERO);
    865 
    866 	if (as == NULL)
    867 		return (ENOMEM);
    868 
    869 	as->codec_if.vtbl = &ac97civ;
    870 	as->host_if = host_if;
    871 
    872 	if ((error = host_if->attach(host_if->arg, &as->codec_if))) {
    873 		free(as, M_DEVBUF);
    874 		return (error);
    875 	}
    876 
    877 	host_if->reset(host_if->arg);
    878 
    879 	host_if->write(host_if->arg, AC97_REG_POWER, 0);
    880 	host_if->write(host_if->arg, AC97_REG_RESET, 0);
    881 
    882 	if (host_if->flags)
    883 		as->host_flags = host_if->flags(host_if->arg);
    884 
    885 	ac97_setup_defaults(as);
    886 	ac97_read(as, AC97_REG_VENDOR_ID1, &id1);
    887 	ac97_read(as, AC97_REG_VENDOR_ID2, &id2);
    888 	ac97_read(as, AC97_REG_RESET, &as->caps);
    889 
    890 	id = (id1 << 16) | id2;
    891 
    892 	printf("%s: ", sc_dev->dv_xname);
    893 
    894 	for (i = 0; ; i++) {
    895 		if (ac97codecid[i].id == 0) {
    896 			char pnp[4];
    897 
    898 			AC97_GET_CODEC_ID(id, pnp);
    899 #define ISASCII(c) ((c) >= ' ' && (c) < 0x7f)
    900 			if (ISASCII(pnp[0]) && ISASCII(pnp[1]) &&
    901 			    ISASCII(pnp[2]))
    902 				printf("%c%c%c%d", pnp[0], pnp[1], pnp[2],
    903 				    pnp[3]);
    904 			else
    905 				printf("unknown (0x%08x)", id);
    906 			break;
    907 		}
    908 		if (ac97codecid[i].id == (id & ac97codecid[i].mask)) {
    909 			printf("%s", ac97codecid[i].name);
    910 			if (ac97codecid[i].mask == AC97_VENDOR_ID_MASK) {
    911 				printf(" (0x%08x)", id);
    912 			}
    913 			initfunc = ac97codecid[i].init;
    914 			break;
    915 		}
    916 	}
    917 	printf(" codec; ");
    918 	for (i = j = 0; i < 10; i++) {
    919 		if (as->caps & (1 << i)) {
    920 			printf("%s%s", j? ", " : "", ac97feature[i]);
    921 			j++;
    922 		}
    923 	}
    924 	printf("%s%s\n", j ? ", " : "",
    925 	       ac97enhancement[AC97_CAPS_ENHANCEMENT(as->caps)]);
    926 
    927 	as->ac97_clock = AC97_STANDARD_CLOCK;
    928 	ac97_read(as, AC97_REG_EXT_AUDIO_ID, &as->ext_id);
    929 	if (as->ext_id & (AC97_EXT_AUDIO_VRA | AC97_EXT_AUDIO_DRA
    930 			  | AC97_EXT_AUDIO_SPDIF | AC97_EXT_AUDIO_VRM
    931 			  | AC97_EXT_AUDIO_CDAC | AC97_EXT_AUDIO_SDAC
    932 			  | AC97_EXT_AUDIO_LDAC)) {
    933 		printf("%s:", sc_dev->dv_xname);
    934 		delim = "";
    935 
    936 		ac97_read(as, AC97_REG_EXT_AUDIO_CTRL, &extstat);
    937 		if (as->ext_id & AC97_EXT_AUDIO_VRA) {
    938 			printf("%s variable rate audio", delim);
    939 			delim = ",";
    940 			extstat |= AC97_EXT_AUDIO_VRA;
    941 		}
    942 		if (as->ext_id & AC97_EXT_AUDIO_DRA) {
    943 			printf("%s double rate output", delim);
    944 			delim = ",";
    945 		}
    946 		extstat &= ~AC97_EXT_AUDIO_DRA;
    947 		if (as->ext_id & AC97_EXT_AUDIO_SPDIF) {
    948 			printf("%s S/PDIF", delim);
    949 			delim = ",";
    950 		}
    951 		if (as->ext_id & AC97_EXT_AUDIO_VRM) {
    952 			printf("%s variable rate dedicated mic", delim);
    953 			delim = ",";
    954 			extstat |= AC97_EXT_AUDIO_VRM;
    955 		}
    956 		if (as->ext_id & AC97_EXT_AUDIO_CDAC) {
    957 			printf("%s center DAC", delim);
    958 			delim = ",";
    959 			extstat |= AC97_EXT_AUDIO_CDAC;
    960 		}
    961 		if (as->ext_id & AC97_EXT_AUDIO_SDAC) {
    962 			printf("%s surround DAC", delim);
    963 			delim = ",";
    964 			extstat |= AC97_EXT_AUDIO_SDAC;
    965 		}
    966 		if (as->ext_id & AC97_EXT_AUDIO_LDAC) {
    967 			printf("%s LFE DAC", delim);
    968 			extstat |= AC97_EXT_AUDIO_LDAC;
    969 		}
    970 		printf("\n");
    971 
    972 		ac97_write(as, AC97_REG_EXT_AUDIO_CTRL, extstat);
    973 		if (as->ext_id & AC97_EXT_AUDIO_VRA) {
    974 			/* VRA should be enabled. */
    975 			/* so it claims to do variable rate, let's make sure */
    976 			ac97_write(as, AC97_REG_PCM_FRONT_DAC_RATE, 44100);
    977 			ac97_read(as, AC97_REG_PCM_FRONT_DAC_RATE, &rate);
    978 			if (rate != 44100) {
    979 				/* We can't believe ext_id */
    980 				as->ext_id = 0;
    981 				printf("%s: Ignore these capabilities.\n",
    982 				       sc_dev->dv_xname);
    983 			}
    984 			/* restore the default value */
    985 			ac97_write(as, AC97_REG_PCM_FRONT_DAC_RATE,
    986 				   AC97_SINGLE_RATE);
    987 		}
    988 	}
    989 
    990 	ac97_setup_source_info(as);
    991 
    992 	DELAY(900 * 1000);
    993 	memset(&ctl, 0, sizeof(ctl));
    994 
    995 	/* disable mutes */
    996 	for (i = 0; i < 11; i++) {
    997 		static struct {
    998 			char *class, *device;
    999 		} d[11] = {
   1000 			{ AudioCoutputs, AudioNmaster},
   1001 			{ AudioCoutputs, AudioNheadphone},
   1002 			{ AudioCoutputs, AudioNsurround},
   1003 			{ AudioCoutputs, AudioNcenter},
   1004 			{ AudioCoutputs, AudioNlfe},
   1005 			{ AudioCinputs, AudioNdac},
   1006 			{ AudioCinputs, AudioNcd},
   1007 			{ AudioCinputs, AudioNline},
   1008 			{ AudioCinputs, AudioNaux},
   1009 			{ AudioCinputs, AudioNvideo},
   1010 			{ AudioCrecord, AudioNvolume},
   1011 		};
   1012 
   1013 		ctl.type = AUDIO_MIXER_ENUM;
   1014 		ctl.un.ord = 0;
   1015 
   1016 		ctl.dev = ac97_get_portnum_by_name(&as->codec_if,
   1017 			d[i].class, d[i].device, AudioNmute);
   1018 		ac97_mixer_set_port(&as->codec_if, &ctl);
   1019 	}
   1020 	ctl.type = AUDIO_MIXER_ENUM;
   1021 	ctl.un.ord = 0;
   1022 	ctl.dev = ac97_get_portnum_by_name(&as->codec_if, AudioCrecord,
   1023 					   AudioNsource, NULL);
   1024 	ac97_mixer_set_port(&as->codec_if, &ctl);
   1025 
   1026 	/* set a reasonable default volume */
   1027 	ctl.type = AUDIO_MIXER_VALUE;
   1028 	ctl.un.value.num_channels = 2;
   1029 	ctl.un.value.level[AUDIO_MIXER_LEVEL_LEFT] = \
   1030 	ctl.un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = 127;
   1031 	ctl.dev = ac97_get_portnum_by_name(&as->codec_if, AudioCoutputs,
   1032 					   AudioNmaster, NULL);
   1033 	ac97_mixer_set_port(&as->codec_if, &ctl);
   1034 	ctl.dev = ac97_get_portnum_by_name(&as->codec_if, AudioCoutputs,
   1035 					   AudioNsurround, NULL);
   1036 	ac97_mixer_set_port(&as->codec_if, &ctl);
   1037 	ctl.un.value.num_channels = 1;
   1038 	ctl.dev = ac97_get_portnum_by_name(&as->codec_if, AudioCoutputs,
   1039 					   AudioNcenter, NULL);
   1040 	ac97_mixer_set_port(&as->codec_if, &ctl);
   1041 	ctl.dev = ac97_get_portnum_by_name(&as->codec_if, AudioCoutputs,
   1042 					   AudioNlfe, NULL);
   1043 	ac97_mixer_set_port(&as->codec_if, &ctl);
   1044 
   1045 	if (initfunc != NULL)
   1046 		initfunc(as);
   1047 	return (0);
   1048 }
   1049 
   1050 
   1051 int
   1052 ac97_query_devinfo(codec_if, dip)
   1053 	struct ac97_codec_if *codec_if;
   1054 	mixer_devinfo_t *dip;
   1055 {
   1056 	struct ac97_softc *as = (struct ac97_softc *)codec_if;
   1057 
   1058 	if (dip->index < as->num_source_info) {
   1059 		struct ac97_source_info *si = &as->source_info[dip->index];
   1060 		const char *name;
   1061 
   1062 		dip->type = si->type;
   1063 		dip->mixer_class = si->mixer_class;
   1064 		dip->prev = si->prev;
   1065 		dip->next = si->next;
   1066 
   1067 		if (si->qualifier)
   1068 			name = si->qualifier;
   1069 		else if (si->device)
   1070 			name = si->device;
   1071 		else if (si->class)
   1072 			name = si->class;
   1073 		else
   1074 			name = 0;
   1075 
   1076 		if (name)
   1077 			strcpy(dip->label.name, name);
   1078 
   1079 		memcpy(&dip->un, si->info, si->info_size);
   1080 
   1081 		/* Set the delta for volume sources */
   1082 		if (dip->type == AUDIO_MIXER_VALUE)
   1083 			dip->un.v.delta = 1 << (8 - si->bits);
   1084 
   1085 		return (0);
   1086 	}
   1087 
   1088 	return (ENXIO);
   1089 }
   1090 
   1091 
   1092 
   1093 int
   1094 ac97_mixer_set_port(codec_if, cp)
   1095 	struct ac97_codec_if *codec_if;
   1096 	mixer_ctrl_t *cp;
   1097 {
   1098 	struct ac97_softc *as = (struct ac97_softc *)codec_if;
   1099 	struct ac97_source_info *si = &as->source_info[cp->dev];
   1100 	u_int16_t mask;
   1101 	u_int16_t val, newval;
   1102 	int error;
   1103 
   1104 	if (cp->dev < 0 || cp->dev >= as->num_source_info)
   1105 		return (EINVAL);
   1106 
   1107 	if (cp->type != si->type)
   1108 		return (EINVAL);
   1109 
   1110 	ac97_read(as, si->reg, &val);
   1111 
   1112 	DPRINTFN(5, ("read(%x) = %x\n", si->reg, val));
   1113 
   1114 	mask = (1 << si->bits) - 1;
   1115 
   1116 	switch (cp->type) {
   1117 	case AUDIO_MIXER_ENUM:
   1118 		if (cp->un.ord > mask || cp->un.ord < 0)
   1119 			return (EINVAL);
   1120 
   1121 		newval = (cp->un.ord << si->ofs);
   1122 		if (si->reg == AC97_REG_RECORD_SELECT) {
   1123 			newval |= (newval << (8 + si->ofs));
   1124 			mask |= (mask << 8);
   1125 			mask = mask << si->ofs;
   1126 		} else if (si->reg == AC97_REG_SURR_MASTER) {
   1127 			newval = cp->un.ord ? 0x8080 : 0x0000;
   1128 			mask = 0x8080;
   1129 		} else
   1130 			mask = mask << si->ofs;
   1131 		break;
   1132 	case AUDIO_MIXER_VALUE:
   1133 	{
   1134 		const struct audio_mixer_value *value = si->info;
   1135 		u_int16_t  l, r;
   1136 
   1137 		if ((cp->un.value.num_channels <= 0) ||
   1138 		    (cp->un.value.num_channels > value->num_channels))
   1139 			return (EINVAL);
   1140 
   1141 		if (cp->un.value.num_channels == 1) {
   1142 			l = r = cp->un.value.level[AUDIO_MIXER_LEVEL_MONO];
   1143 		} else {
   1144 			if (!(as->host_flags & AC97_HOST_SWAPPED_CHANNELS)) {
   1145 				l = cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT];
   1146 				r = cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT];
   1147 			} else {	/* left/right is reversed here */
   1148 				r = cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT];
   1149 				l = cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT];
   1150 			}
   1151 
   1152 		}
   1153 
   1154 		if (!si->polarity) {
   1155 			l = 255 - l;
   1156 			r = 255 - r;
   1157 		}
   1158 
   1159 		l = l >> (8 - si->bits);
   1160 		r = r >> (8 - si->bits);
   1161 
   1162 		newval = ((l & mask) << si->ofs);
   1163 		if (value->num_channels == 2) {
   1164 			newval = (newval << 8) | ((r & mask) << si->ofs);
   1165 			mask |= (mask << 8);
   1166 		}
   1167 		mask = mask << si->ofs;
   1168 		break;
   1169 	}
   1170 	default:
   1171 		return (EINVAL);
   1172 	}
   1173 
   1174 	error = ac97_write(as, si->reg, (val & ~mask) | newval);
   1175 	if (error)
   1176 		return (error);
   1177 
   1178 	return (0);
   1179 }
   1180 
   1181 int
   1182 ac97_get_portnum_by_name(codec_if, class, device, qualifier)
   1183 	struct ac97_codec_if *codec_if;
   1184 	const char *class, *device, *qualifier;
   1185 {
   1186 	struct ac97_softc *as = (struct ac97_softc *)codec_if;
   1187 	int idx;
   1188 
   1189 	for (idx = 0; idx < as->num_source_info; idx++) {
   1190 		struct ac97_source_info *si = &as->source_info[idx];
   1191 		if (ac97_str_equal(class, si->class) &&
   1192 		    ac97_str_equal(device, si->device) &&
   1193 		    ac97_str_equal(qualifier, si->qualifier))
   1194 			return (idx);
   1195 	}
   1196 
   1197 	return (-1);
   1198 }
   1199 
   1200 int
   1201 ac97_mixer_get_port(codec_if, cp)
   1202 	struct ac97_codec_if *codec_if;
   1203 	mixer_ctrl_t *cp;
   1204 {
   1205 	struct ac97_softc *as = (struct ac97_softc *)codec_if;
   1206 	struct ac97_source_info *si = &as->source_info[cp->dev];
   1207 	u_int16_t mask;
   1208 	u_int16_t val;
   1209 
   1210 	if (cp->dev < 0 || cp->dev >= as->num_source_info)
   1211 		return (EINVAL);
   1212 
   1213 	if (cp->type != si->type)
   1214 		return (EINVAL);
   1215 
   1216 	ac97_read(as, si->reg, &val);
   1217 
   1218 	DPRINTFN(5, ("read(%x) = %x\n", si->reg, val));
   1219 
   1220 	mask = (1 << si->bits) - 1;
   1221 
   1222 	switch (cp->type) {
   1223 	case AUDIO_MIXER_ENUM:
   1224 		cp->un.ord = (val >> si->ofs) & mask;
   1225 		DPRINTFN(4, ("AUDIO_MIXER_ENUM: %x %d %x %d\n",
   1226 			     val, si->ofs, mask, cp->un.ord));
   1227 		break;
   1228 	case AUDIO_MIXER_VALUE:
   1229 	{
   1230 		const struct audio_mixer_value *value = si->info;
   1231 		u_int16_t  l, r;
   1232 
   1233 		if ((cp->un.value.num_channels <= 0) ||
   1234 		    (cp->un.value.num_channels > value->num_channels))
   1235 			return (EINVAL);
   1236 
   1237 		if (value->num_channels == 1) {
   1238 			l = r = (val >> si->ofs) & mask;
   1239 		} else {
   1240 			if (!(as->host_flags & AC97_HOST_SWAPPED_CHANNELS)) {
   1241 				l = (val >> (si->ofs + 8)) & mask;
   1242 				r = (val >> si->ofs) & mask;
   1243 			} else {	/* host has reversed channels */
   1244 				r = (val >> (si->ofs + 8)) & mask;
   1245 				l = (val >> si->ofs) & mask;
   1246 			}
   1247 		}
   1248 
   1249 		l = (l << (8 - si->bits));
   1250 		r = (r << (8 - si->bits));
   1251 		if (!si->polarity) {
   1252 			l = 255 - l;
   1253 			r = 255 - r;
   1254 		}
   1255 
   1256 		/* The EAP driver averages l and r for stereo
   1257 		   channels that are requested in MONO mode. Does this
   1258 		   make sense? */
   1259 		if (cp->un.value.num_channels == 1) {
   1260 			cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = l;
   1261 		} else if (cp->un.value.num_channels == 2) {
   1262 			cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = l;
   1263 			cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = r;
   1264 		}
   1265 
   1266 		break;
   1267 	}
   1268 	default:
   1269 		return (EINVAL);
   1270 	}
   1271 
   1272 	return (0);
   1273 }
   1274 
   1275 
   1276 int
   1277 ac97_set_rate(struct ac97_codec_if *codec_if, int target, u_long *rate)
   1278 {
   1279 	struct ac97_softc *as;
   1280 	u_long value;
   1281 	u_int16_t ext_stat;
   1282 	u_int16_t actual;
   1283 	u_int16_t power;
   1284 	u_int16_t power_bit;
   1285 
   1286 	as = (struct ac97_softc *)codec_if;
   1287 	if (target == AC97_REG_PCM_MIC_ADC_RATE) {
   1288 		if (!(as->ext_id & AC97_EXT_AUDIO_VRM)) {
   1289 			*rate = AC97_SINGLE_RATE;
   1290 			return 0;
   1291 		}
   1292 	} else {
   1293 		if (!(as->ext_id & AC97_EXT_AUDIO_VRA)) {
   1294 			*rate = AC97_SINGLE_RATE;
   1295 			return 0;
   1296 		}
   1297 	}
   1298 	value = *rate * AC97_STANDARD_CLOCK / as->ac97_clock;
   1299 	ext_stat = 0;
   1300 	/*
   1301 	 * PCM_FRONT_DAC_RATE/PCM_SURR_DAC_RATE/PCM_LFE_DAC_RATE
   1302 	 *	Check VRA, DRA
   1303 	 * PCM_LR_ADC_RATE
   1304 	 *	Check VRA
   1305 	 * PCM_MIC_ADC_RATE
   1306 	 *	Check VRM
   1307 	 */
   1308 	switch (target) {
   1309 	case AC97_REG_PCM_FRONT_DAC_RATE:
   1310 	case AC97_REG_PCM_SURR_DAC_RATE:
   1311 	case AC97_REG_PCM_LFE_DAC_RATE:
   1312 		power_bit = AC97_POWER_OUT;
   1313 		if (!(as->ext_id & AC97_EXT_AUDIO_VRA)) {
   1314 			*rate = AC97_SINGLE_RATE;
   1315 			return 0;
   1316 		}
   1317 		if (as->ext_id & AC97_EXT_AUDIO_DRA) {
   1318 			ac97_read(as, AC97_REG_EXT_AUDIO_CTRL, &ext_stat);
   1319 			if (value > 0x1ffff) {
   1320 				return EINVAL;
   1321 			} else if (value > 0xffff) {
   1322 				/* Enable DRA */
   1323 				ext_stat |= AC97_EXT_AUDIO_DRA;
   1324 				ac97_write(as, AC97_REG_EXT_AUDIO_CTRL, ext_stat);
   1325 				value /= 2;
   1326 			} else {
   1327 				/* Disable DRA */
   1328 				ext_stat &= ~AC97_EXT_AUDIO_DRA;
   1329 				ac97_write(as, AC97_REG_EXT_AUDIO_CTRL, ext_stat);
   1330 			}
   1331 		} else {
   1332 			if (value > 0xffff)
   1333 				return EINVAL;
   1334 		}
   1335 		break;
   1336 	case AC97_REG_PCM_LR_ADC_RATE:
   1337 		power_bit = AC97_POWER_IN;
   1338 		if (!(as->ext_id & AC97_EXT_AUDIO_VRA)) {
   1339 			*rate = AC97_SINGLE_RATE;
   1340 			return 0;
   1341 		}
   1342 		if (value > 0xffff)
   1343 			return EINVAL;
   1344 		break;
   1345 	case AC97_REG_PCM_MIC_ADC_RATE:
   1346 		power_bit = AC97_POWER_IN;
   1347 		if (!(as->ext_id & AC97_EXT_AUDIO_VRM)) {
   1348 			*rate = AC97_SINGLE_RATE;
   1349 			return 0;
   1350 		}
   1351 		if (value > 0xffff)
   1352 			return EINVAL;
   1353 		break;
   1354 	default:
   1355 		printf("%s: Unknown register: 0x%x\n", __func__, target);
   1356 		return EINVAL;
   1357 	}
   1358 
   1359 	ac97_read(as, AC97_REG_POWER, &power);
   1360 	ac97_write(as, AC97_REG_POWER, power | power_bit);
   1361 
   1362 	ac97_write(as, target, (u_int16_t)value);
   1363 	ac97_read(as, target, &actual);
   1364 	actual = (u_int32_t)actual * as->ac97_clock / AC97_STANDARD_CLOCK;
   1365 
   1366 	ac97_write(as, AC97_REG_POWER, power);
   1367 	if (ext_stat & AC97_EXT_AUDIO_DRA) {
   1368 		*rate = actual * 2;
   1369 	} else {
   1370 		*rate = actual;
   1371 	}
   1372 	return 0;
   1373 }
   1374 
   1375 void
   1376 ac97_set_clock(struct ac97_codec_if *codec_if, unsigned int clock)
   1377 {
   1378 	struct ac97_softc *as;
   1379 
   1380 	as = (struct ac97_softc *)codec_if;
   1381 	as->ac97_clock = clock;
   1382 }
   1383 
   1384 u_int16_t
   1385 ac97_get_extcaps(struct ac97_codec_if *codec_if)
   1386 {
   1387 	struct ac97_softc *as;
   1388 
   1389 	as = (struct ac97_softc *)codec_if;
   1390 	return as->ext_id;
   1391 }
   1392 
   1393 int
   1394 ac97_add_port(struct ac97_softc *as, const struct ac97_source_info *src)
   1395 {
   1396 	struct ac97_source_info *si;
   1397 	int ouridx, idx;
   1398 
   1399 	if (as->num_source_info >= MAX_SOURCES) {
   1400 		printf("%s: internal error: increase MAX_SOURCES in %s\n",
   1401 		       __func__, __FILE__);
   1402 		return -1;
   1403 	}
   1404 	if (!ac97_check_capability(as, src->req_feature))
   1405 		return -1;
   1406 	ouridx = as->num_source_info;
   1407 	si = &as->source_info[ouridx];
   1408 	memcpy(si, src, sizeof(*si));
   1409 
   1410 	switch (si->type) {
   1411 	case AUDIO_MIXER_CLASS:
   1412 	case AUDIO_MIXER_VALUE:
   1413 		printf("%s: adding class/value is not supported yet.\n",
   1414 		       __func__);
   1415 		return -1;
   1416 	case AUDIO_MIXER_ENUM:
   1417 		break;
   1418 	default:
   1419 		printf("%s: unknown type: %d\n", __func__, si->type);
   1420 		return -1;
   1421 	}
   1422 	as->num_source_info++;
   1423 
   1424 	si->mixer_class = ac97_get_portnum_by_name(&as->codec_if, si->class,
   1425 						   NULL, NULL);
   1426 	/* Find the root of the device */
   1427 	idx = ac97_get_portnum_by_name(&as->codec_if, si->class,
   1428 				       si->device, NULL);
   1429 	/* Find the last item */
   1430 	while (as->source_info[idx].next != AUDIO_MIXER_LAST)
   1431 		idx = as->source_info[idx].next;
   1432 	/* Append */
   1433 	as->source_info[idx].next = ouridx;
   1434 	si->prev = idx;
   1435 	si->next = AUDIO_MIXER_LAST;
   1436 
   1437 	return 0;
   1438 }
   1439 
   1440 #define ALC650_REG_MULTI_CHANNEL_CONTROL	0x6a
   1441 #define		ALC650_MCC_SLOT_MODIFY_MASK		0xc000
   1442 #define		ALC650_MCC_FRONTDAC_FROM_SPDIFIN	0x2000 /* 13 */
   1443 #define		ALC650_MCC_SPDIFOUT_FROM_ADC		0x1000 /* 12 */
   1444 #define		ALC650_MCC_PCM_FROM_SPDIFIN		0x0800 /* 11 */
   1445 #define		ALC650_MCC_MIC_OR_CENTERLFE		0x0400 /* 10 */
   1446 #define		ALC650_MCC_LINEIN_OR_SURROUND		0x0200 /* 9 */
   1447 #define		ALC650_MCC_INDEPENDENT_MASTER_L		0x0080 /* 7 */
   1448 #define		ALC650_MCC_INDEPENDENT_MASTER_R		0x0040 /* 6 */
   1449 #define		ALC650_MCC_ANALOG_TO_CENTERLFE		0x0020 /* 5 */
   1450 #define		ALC650_MCC_ANALOG_TO_SURROUND		0x0010 /* 4 */
   1451 #define		ALC650_MCC_EXCHANGE_CENTERLFE		0x0008 /* 3 */
   1452 #define		ALC650_MCC_CENTERLFE_DOWNMIX		0x0004 /* 2 */
   1453 #define		ALC650_MCC_SURROUND_DOWNMIX		0x0002 /* 1 */
   1454 #define		ALC650_MCC_LINEOUT_TO_SURROUND		0x0001 /* 0 */
   1455 static void
   1456 ac97_alc650_init(struct ac97_softc *as)
   1457 {
   1458 	static const struct ac97_source_info sources[6] = {
   1459 		{ AudioCoutputs, AudioNsurround, "lineinjack",
   1460 		  AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
   1461 		  ALC650_REG_MULTI_CHANNEL_CONTROL,
   1462 		  0x0000, 1, 9, 0, 0, CHECK_SURROUND },
   1463 		{ AudioCoutputs, AudioNsurround, "mixtofront",
   1464 		  AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
   1465 		  ALC650_REG_MULTI_CHANNEL_CONTROL,
   1466 		  0x0000, 1, 1, 0, 0, CHECK_SURROUND },
   1467 		{ AudioCoutputs, AudioNcenter, "micjack",
   1468 		  AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
   1469 		  ALC650_REG_MULTI_CHANNEL_CONTROL,
   1470 		  0x0000, 1, 10, 0, 0, CHECK_CENTER },
   1471 		{ AudioCoutputs, AudioNlfe, "micjack",
   1472 		  AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
   1473 		  ALC650_REG_MULTI_CHANNEL_CONTROL,
   1474 		  0x0000, 1, 10, 0, 0, CHECK_LFE },
   1475 		{ AudioCoutputs, AudioNcenter, "mixtofront",
   1476 		  AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
   1477 		  ALC650_REG_MULTI_CHANNEL_CONTROL,
   1478 		  0x0000, 1, 2, 0, 0, CHECK_CENTER },
   1479 		{ AudioCoutputs, AudioNlfe, "mixtofront",
   1480 		  AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
   1481 		  ALC650_REG_MULTI_CHANNEL_CONTROL,
   1482 		  0x0000, 1, 2, 0, 0, CHECK_LFE },
   1483 	};
   1484 
   1485 	ac97_add_port(as, &sources[0]);
   1486 	ac97_add_port(as, &sources[1]);
   1487 	ac97_add_port(as, &sources[2]);
   1488 	ac97_add_port(as, &sources[3]);
   1489 	ac97_add_port(as, &sources[4]);
   1490 	ac97_add_port(as, &sources[5]);
   1491 }
   1492 
   1493 #define VT1616_REG_IO_CONTROL	0x5a
   1494 #define		VT1616_IC_LVL			(1 << 15)
   1495 #define		VT1616_IC_LFECENTER_TO_FRONT	(1 << 12)
   1496 #define		VT1616_IC_SURROUND_TO_FRONT	(1 << 11)
   1497 #define		VT1616_IC_BPDC			(1 << 10)
   1498 #define		VT1616_IC_DC			(1 << 9)
   1499 #define		VT1616_IC_IB_MASK		0x000c
   1500 static void
   1501 ac97_vt1616_init(struct ac97_softc *as)
   1502 {
   1503 	static const struct ac97_source_info sources[3] = {
   1504 		{ AudioCoutputs, AudioNsurround, "mixtofront",
   1505 		  AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
   1506 		  VT1616_REG_IO_CONTROL,
   1507 		  0x0000, 1, 11, 0, 0, CHECK_SURROUND },
   1508 		{ AudioCoutputs, AudioNcenter, "mixtofront",
   1509 		  AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
   1510 		  VT1616_REG_IO_CONTROL,
   1511 		  0x0000, 1, 12, 0, 0, CHECK_CENTER },
   1512 		{ AudioCoutputs, AudioNlfe, "mixtofront",
   1513 		  AUDIO_MIXER_ENUM, WRAP(ac97_on_off),
   1514 		  VT1616_REG_IO_CONTROL,
   1515 		  0x0000, 1, 12, 0, 0, CHECK_LFE },
   1516 	};
   1517 
   1518 	ac97_add_port(as, &sources[0]);
   1519 	ac97_add_port(as, &sources[1]);
   1520 	ac97_add_port(as, &sources[2]);
   1521 }
   1522 
   1523