xref: /openbsd-src/sys/dev/ic/am7930.c (revision 50b7afb2c2c0993b0894d4e34bf857cb13ed9c80)
1 /*	$OpenBSD: am7930.c,v 1.5 2013/05/15 21:22:28 ratchov Exp $	*/
2 /*	$NetBSD: am7930.c,v 1.44 2001/11/13 13:14:34 lukem Exp $	*/
3 
4 /*
5  * Copyright (c) 1995 Rolf Grossmann
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by Rolf Grossmann.
19  * 4. The name of the author may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 /*
35  * Front-end attachment independent layer for AMD 79c30
36  * audio driver.  No ISDN support.
37  */
38 
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/errno.h>
42 #include <sys/ioctl.h>
43 #include <sys/device.h>
44 #include <sys/proc.h>
45 
46 #include <sys/audioio.h>
47 #include <dev/audio_if.h>
48 #include <dev/mulaw.h>
49 
50 #include <dev/ic/am7930reg.h>
51 #include <dev/ic/am7930var.h>
52 
53 #ifdef AUDIO_DEBUG
54 int	am7930debug = 0;
55 #define	DPRINTF(x)	if (am7930debug) printf x
56 #else
57 #define	DPRINTF(x)
58 #endif
59 
60 
61 /* The following tables stolen from former (4.4Lite's) sys/sparc/bsd_audio.c */
62 
63 /*
64  * gx, gr & stg gains.  this table must contain 256 elements with
65  * the 0th being "infinity" (the magic value 9008).  The remaining
66  * elements match sun's gain curve (but with higher resolution):
67  * -18 to 0dB in .16dB steps then 0 to 12dB in .08dB steps.
68  */
69 static const uint16_t gx_coeff[256] = {
70 	0x9008, 0x8e7c, 0x8e51, 0x8e45, 0x8d42, 0x8d3b, 0x8c36, 0x8c33,
71 	0x8b32, 0x8b2a, 0x8b2b, 0x8b2c, 0x8b25, 0x8b23, 0x8b22, 0x8b22,
72 	0x9122, 0x8b1a, 0x8aa3, 0x8aa3, 0x8b1c, 0x8aa6, 0x912d, 0x912b,
73 	0x8aab, 0x8b12, 0x8aaa, 0x8ab2, 0x9132, 0x8ab4, 0x913c, 0x8abb,
74 	0x9142, 0x9144, 0x9151, 0x8ad5, 0x8aeb, 0x8a79, 0x8a5a, 0x8a4a,
75 	0x8b03, 0x91c2, 0x91bb, 0x8a3f, 0x8a33, 0x91b2, 0x9212, 0x9213,
76 	0x8a2c, 0x921d, 0x8a23, 0x921a, 0x9222, 0x9223, 0x922d, 0x9231,
77 	0x9234, 0x9242, 0x925b, 0x92dd, 0x92c1, 0x92b3, 0x92ab, 0x92a4,
78 	0x92a2, 0x932b, 0x9341, 0x93d3, 0x93b2, 0x93a2, 0x943c, 0x94b2,
79 	0x953a, 0x9653, 0x9782, 0x9e21, 0x9d23, 0x9cd2, 0x9c23, 0x9baa,
80 	0x9bde, 0x9b33, 0x9b22, 0x9b1d, 0x9ab2, 0xa142, 0xa1e5, 0x9a3b,
81 	0xa213, 0xa1a2, 0xa231, 0xa2eb, 0xa313, 0xa334, 0xa421, 0xa54b,
82 	0xada4, 0xac23, 0xab3b, 0xaaab, 0xaa5c, 0xb1a3, 0xb2ca, 0xb3bd,
83 	0xbe24, 0xbb2b, 0xba33, 0xc32b, 0xcb5a, 0xd2a2, 0xe31d, 0x0808,
84 	0x72ba, 0x62c2, 0x5c32, 0x52db, 0x513e, 0x4cce, 0x43b2, 0x4243,
85 	0x41b4, 0x3b12, 0x3bc3, 0x3df2, 0x34bd, 0x3334, 0x32c2, 0x3224,
86 	0x31aa, 0x2a7b, 0x2aaa, 0x2b23, 0x2bba, 0x2c42, 0x2e23, 0x25bb,
87 	0x242b, 0x240f, 0x231a, 0x22bb, 0x2241, 0x2223, 0x221f, 0x1a33,
88 	0x1a4a, 0x1acd, 0x2132, 0x1b1b, 0x1b2c, 0x1b62, 0x1c12, 0x1c32,
89 	0x1d1b, 0x1e71, 0x16b1, 0x1522, 0x1434, 0x1412, 0x1352, 0x1323,
90 	0x1315, 0x12bc, 0x127a, 0x1235, 0x1226, 0x11a2, 0x1216, 0x0a2a,
91 	0x11bc, 0x11d1, 0x1163, 0x0ac2, 0x0ab2, 0x0aab, 0x0b1b, 0x0b23,
92 	0x0b33, 0x0c0f, 0x0bb3, 0x0c1b, 0x0c3e, 0x0cb1, 0x0d4c, 0x0ec1,
93 	0x079a, 0x0614, 0x0521, 0x047c, 0x0422, 0x03b1, 0x03e3, 0x0333,
94 	0x0322, 0x031c, 0x02aa, 0x02ba, 0x02f2, 0x0242, 0x0232, 0x0227,
95 	0x0222, 0x021b, 0x01ad, 0x0212, 0x01b2, 0x01bb, 0x01cb, 0x01f6,
96 	0x0152, 0x013a, 0x0133, 0x0131, 0x012c, 0x0123, 0x0122, 0x00a2,
97 	0x011b, 0x011e, 0x0114, 0x00b1, 0x00aa, 0x00b3, 0x00bd, 0x00ba,
98 	0x00c5, 0x00d3, 0x00f3, 0x0062, 0x0051, 0x0042, 0x003b, 0x0033,
99 	0x0032, 0x002a, 0x002c, 0x0025, 0x0023, 0x0022, 0x001a, 0x0021,
100 	0x001b, 0x001b, 0x001d, 0x0015, 0x0013, 0x0013, 0x0012, 0x0012,
101 	0x000a, 0x000a, 0x0011, 0x0011, 0x000b, 0x000b, 0x000c, 0x000e,
102 };
103 
104 /*
105  * second stage play gain.
106  */
107 static const uint16_t ger_coeff[] = {
108 	0x431f, /* 5. dB */
109 	0x331f, /* 5.5 dB */
110 	0x40dd, /* 6. dB */
111 	0x11dd, /* 6.5 dB */
112 	0x440f, /* 7. dB */
113 	0x411f, /* 7.5 dB */
114 	0x311f, /* 8. dB */
115 	0x5520, /* 8.5 dB */
116 	0x10dd, /* 9. dB */
117 	0x4211, /* 9.5 dB */
118 	0x410f, /* 10. dB */
119 	0x111f, /* 10.5 dB */
120 	0x600b, /* 11. dB */
121 	0x00dd, /* 11.5 dB */
122 	0x4210, /* 12. dB */
123 	0x110f, /* 13. dB */
124 	0x7200, /* 14. dB */
125 	0x2110, /* 15. dB */
126 	0x2200, /* 15.9 dB */
127 	0x000b, /* 16.9 dB */
128 	0x000f  /* 18. dB */
129 #define NGER (sizeof(ger_coeff) / sizeof(ger_coeff[0]))
130 };
131 
132 
133 /*
134  * Reset chip and set boot-time softc defaults.
135  */
136 void
137 am7930_init(struct am7930_softc *sc, int flag)
138 {
139 	DPRINTF(("am7930_init()\n"));
140 
141 	/* set boot defaults */
142 	sc->sc_rlevel = 128;
143 	sc->sc_plevel = 128;
144 	sc->sc_mlevel = 0;
145 	sc->sc_out_port = AUDIOAMD_SPEAKER_VOL;
146 	sc->sc_mic_mute = 0;
147 
148 	/* disable sample interrupts */
149 	AM7930_IWRITE(sc, AM7930_IREG_MUX_MCR4, 0);
150 
151 	/* initialise voice and data, and disable interrupts */
152 	AM7930_IWRITE(sc, AM7930_IREG_INIT,
153 	    AM7930_INIT_PMS_ACTIVE | AM7930_INIT_INT_DISABLE);
154 
155 	if (flag == AUDIOAMD_DMA_MODE) {
156 		/* configure PP for serial (SBP) mode */
157 		AM7930_IWRITE(sc, AM7930_IREG_PP_PPCR1, AM7930_PPCR1_SBP);
158 
159 		/*
160 		 * Initialise the MUX unit - route the MAP to the PP
161 		 */
162 		AM7930_IWRITE(sc, AM7930_IREG_MUX_MCR1,
163 		    (AM7930_MCRCHAN_BA << 4) | AM7930_MCRCHAN_BD);
164 		AM7930_IWRITE(sc, AM7930_IREG_MUX_MCR2, AM7930_MCRCHAN_NC);
165 		AM7930_IWRITE(sc, AM7930_IREG_MUX_MCR3, AM7930_MCRCHAN_NC);
166 	} else {
167 		/*
168 		 * Initialize the MUX unit.  We use MCR3 to route the MAP
169 		 * through channel Bb.  MCR1 and MCR2 are unused.
170 		 * Setting the INT enable bit in MCR4 will generate an
171 		 * interrupt on each converted audio sample.
172 		 */
173 		AM7930_IWRITE(sc, AM7930_IREG_MUX_MCR1, 0);
174 		AM7930_IWRITE(sc, AM7930_IREG_MUX_MCR2, 0);
175 		AM7930_IWRITE(sc, AM7930_IREG_MUX_MCR3,
176 		    (AM7930_MCRCHAN_BB << 4) | AM7930_MCRCHAN_BA);
177 		AM7930_IWRITE(sc, AM7930_IREG_MUX_MCR4,
178 		    AM7930_MCR4_INT_ENABLE);
179 	}
180 }
181 
182 int
183 am7930_open(void *addr, int flags)
184 {
185 	struct am7930_softc *sc = addr;
186 
187 	DPRINTF(("sa_open: unit %p\n", sc));
188 	if (sc->sc_open)
189 		return EBUSY;
190 	sc->sc_open = 1;
191 	sc->sc_locked = 0;
192 
193 	sc->sc_glue->onopen(sc);
194 	DPRINTF(("saopen: ok -> sc=%p\n",sc));
195 	return 0;
196 }
197 
198 void
199 am7930_close(void *addr)
200 {
201 	struct am7930_softc *sc = addr;
202 
203 	DPRINTF(("sa_close: sc=%p\n", sc));
204 	sc->sc_glue->onclose(sc);
205 	sc->sc_open = 0;
206 	DPRINTF(("sa_close: closed.\n"));
207 }
208 
209 int
210 am7930_set_params(void *addr, int setmode, int usemode,
211     struct audio_params *play, struct audio_params *rec)
212 {
213 	struct am7930_softc *sc = addr;
214 	struct audio_params *p;
215 	int mode;
216 
217 	for (mode = AUMODE_RECORD; mode != -1;
218 	    mode = mode == AUMODE_RECORD ? AUMODE_PLAY : -1) {
219 		if ((setmode & mode) == 0)
220 			continue;
221 
222 		p = mode == AUMODE_PLAY ? play : rec;
223 		if (p == NULL)
224 			continue;
225 
226 		switch (p->encoding) {
227 		case AUDIO_ENCODING_ULAW:
228 			p->sw_code = NULL;
229 			break;
230 		case AUDIO_ENCODING_SLINEAR:
231 		case AUDIO_ENCODING_SLINEAR_BE:
232 		case AUDIO_ENCODING_SLINEAR_LE:
233 			if (mode == AUMODE_PLAY)
234 				p->sw_code = slinear8_to_mulaw;
235 			else
236 				p->sw_code = mulaw_to_slinear8;
237 			break;
238 		case AUDIO_ENCODING_ULINEAR:
239 		case AUDIO_ENCODING_ULINEAR_BE:
240 		case AUDIO_ENCODING_ULINEAR_LE:
241 			if (mode == AUMODE_PLAY)
242 				p->sw_code = ulinear8_to_mulaw;
243 			else
244 				p->sw_code = mulaw_to_ulinear8;
245 			break;
246 		case AUDIO_ENCODING_ALAW:
247 			if (mode == AUMODE_PLAY)
248 				p->sw_code = alaw_to_mulaw;
249 			else
250 				p->sw_code = mulaw_to_alaw;
251 			break;
252 		default:
253 			return EINVAL;
254 		}
255 		p->precision = 8;
256 		p->bps = 1;
257 		p->msb = 1;
258 		p->channels = 1;
259 		/* no other rates supported by amd chip */
260 		p->sample_rate = 8000;
261 
262 		if (sc->sc_glue->factor > 1) {
263 			p->factor = sc->sc_glue->factor;
264 			/*
265 			 * Remember which converter routine had been
266 			 * selected, if any, since there is no way
267 			 * to stack filters yet.
268 			 *
269 			 * Note that we rely upon the converters working
270 			 * in place (i.e. with factor == 1), which is
271 			 * correct as long as we don't try to emulate
272 			 * 16-bit encodings.
273 			 */
274 			if (mode == AUMODE_PLAY) {
275 				sc->play_sw_code = p->sw_code;
276 				p->sw_code = sc->sc_glue->output_conv;
277 			} else {
278 				sc->rec_sw_code = p->sw_code;
279 				p->sw_code = sc->sc_glue->input_conv;
280 			}
281 		}
282 	}
283 
284 	return 0;
285 }
286 
287 int
288 am7930_query_encoding(void *addr, struct audio_encoding *fp)
289 {
290 	switch (fp->index) {
291 	case 0:
292 		strlcpy(fp->name, AudioEmulaw, sizeof fp->name);
293 		fp->encoding = AUDIO_ENCODING_ULAW;
294 		fp->precision = 8;
295 		fp->bps = 1;
296 		fp->msb = 1;
297 		fp->flags = 0;
298 		break;
299 	case 1:
300 		strlcpy(fp->name, AudioEslinear, sizeof fp->name);
301 		fp->encoding = AUDIO_ENCODING_SLINEAR;
302 		fp->precision = 8;
303 		fp->bps = 1;
304 		fp->msb = 1;
305 		fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
306 		break;
307 	case 2:
308 		strlcpy(fp->name, AudioEulinear, sizeof fp->name);
309 		fp->encoding = AUDIO_ENCODING_ULINEAR;
310 		fp->precision = 8;
311 		fp->bps = 1;
312 		fp->msb = 1;
313 		fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
314 		break;
315 	case 3:
316 		strlcpy(fp->name, AudioEalaw, sizeof fp->name);
317 		fp->encoding = AUDIO_ENCODING_ALAW;
318 		fp->precision = 8;
319 		fp->bps = 1;
320 		fp->msb = 1;
321 		fp->flags = AUDIO_ENCODINGFLAG_EMULATED;
322 		break;
323 	default:
324 		return EINVAL;
325 		/*NOTREACHED*/
326 	}
327 	return 0;
328 }
329 
330 int
331 am7930_round_blocksize(void *addr, int blk)
332 {
333 	return blk;
334 }
335 
336 int
337 am7930_commit_settings(void *addr)
338 {
339 	struct am7930_softc *sc = addr;
340 	uint16_t ger, gr, gx, stgr;
341 	uint8_t mmr2, mmr3;
342 	int level;
343 
344 	DPRINTF(("sa_commit.\n"));
345 	gx = gx_coeff[sc->sc_rlevel];
346 	stgr = gx_coeff[sc->sc_mlevel];
347 
348 	level = (sc->sc_plevel * (256 + NGER)) >> 8;
349 	if (level >= 256) {
350 		ger = ger_coeff[level - 256];
351 		gr = gx_coeff[255];
352 	} else {
353 		ger = ger_coeff[0];
354 		gr = gx_coeff[level];
355 	}
356 
357 	/* XXX: this is called before DMA is setup, useful ? */
358 	mtx_enter(&audio_lock);
359 
360 	mmr2 = AM7930_IREAD(sc, AM7930_IREG_MAP_MMR2);
361 	if (sc->sc_out_port == AUDIOAMD_SPEAKER_VOL)
362 		mmr2 |= AM7930_MMR2_LS;
363 	else
364 		mmr2 &= ~AM7930_MMR2_LS;
365 	AM7930_IWRITE(sc, AM7930_IREG_MAP_MMR2, mmr2);
366 
367 	mmr3 = AM7930_IREAD(sc, AM7930_IREG_MAP_MMR3);
368 	if (sc->sc_mic_mute)
369 		mmr3 |= AM7930_MMR3_MUTE;
370 	else
371 		mmr3 &= ~AM7930_MMR3_MUTE;
372 	AM7930_IWRITE(sc, AM7930_IREG_MAP_MMR3, mmr3);
373 
374 	AM7930_IWRITE(sc, AM7930_IREG_MAP_MMR1,
375 	    AM7930_MMR1_GX | AM7930_MMR1_GER |
376 	    AM7930_MMR1_GR | AM7930_MMR1_STG);
377 
378 	AM7930_IWRITE16(sc, AM7930_IREG_MAP_GX, gx);
379 	AM7930_IWRITE16(sc, AM7930_IREG_MAP_STG, stgr);
380 	AM7930_IWRITE16(sc, AM7930_IREG_MAP_GR, gr);
381 	AM7930_IWRITE16(sc, AM7930_IREG_MAP_GER, ger);
382 
383 	mtx_leave(&audio_lock);
384 
385 	return 0;
386 }
387 
388 int
389 am7930_halt_output(void *addr)
390 {
391 	struct am7930_softc *sc = addr;
392 
393 	/* XXX only halt, if input is also halted ?? */
394 	AM7930_IWRITE(sc, AM7930_IREG_INIT,
395 	    AM7930_INIT_PMS_ACTIVE | AM7930_INIT_INT_DISABLE);
396 	sc->sc_locked = 0;
397 	return 0;
398 }
399 
400 int
401 am7930_halt_input(void *addr)
402 {
403 	struct am7930_softc *sc = addr;
404 
405 	/* XXX only halt, if output is also halted ?? */
406 	AM7930_IWRITE(sc, AM7930_IREG_INIT,
407 	    AM7930_INIT_PMS_ACTIVE | AM7930_INIT_INT_DISABLE);
408 	sc->sc_locked = 0;
409 	return 0;
410 }
411 
412 /*
413  * XXX chip is full-duplex, but really attach-dependent.
414  * For now we know of no half-duplex attachments.
415  */
416 int
417 am7930_get_props(void *addr)
418 {
419 	return AUDIO_PROP_FULLDUPLEX;
420 }
421 
422 /*
423  * Attach-dependent channel set/query
424  */
425 int
426 am7930_set_port(void *addr, mixer_ctrl_t *cp)
427 {
428 	struct am7930_softc *sc = addr;
429 
430 	DPRINTF(("am7930_set_port: port=%d", cp->dev));
431 	if (cp->dev == AUDIOAMD_RECORD_SOURCE ||
432 	    cp->dev == AUDIOAMD_MONITOR_OUTPUT ||
433 	    cp->dev == AUDIOAMD_MIC_MUTE) {
434 		if (cp->type != AUDIO_MIXER_ENUM)
435 			return EINVAL;
436 	} else if (cp->type != AUDIO_MIXER_VALUE ||
437 	    cp->un.value.num_channels != 1) {
438 		return EINVAL;
439 	}
440 
441 	switch(cp->dev) {
442 	case AUDIOAMD_MIC_VOL:
443 		sc->sc_rlevel = cp->un.value.level[AUDIO_MIXER_LEVEL_MONO];
444 		break;
445 	case AUDIOAMD_SPEAKER_VOL:
446 	case AUDIOAMD_HEADPHONES_VOL:
447 		sc->sc_plevel = cp->un.value.level[AUDIO_MIXER_LEVEL_MONO];
448 		break;
449 	case AUDIOAMD_MONITOR_VOL:
450 		sc->sc_mlevel = cp->un.value.level[AUDIO_MIXER_LEVEL_MONO];
451 		break;
452 	case AUDIOAMD_RECORD_SOURCE:
453 		if (cp->un.ord != AUDIOAMD_MIC_VOL)
454 			return EINVAL;
455 		break;
456 	case AUDIOAMD_MIC_MUTE:
457 		sc->sc_mic_mute = cp->un.ord;
458 		break;
459 	case AUDIOAMD_MONITOR_OUTPUT:
460 		if (cp->un.ord != AUDIOAMD_SPEAKER_VOL &&
461 		    cp->un.ord != AUDIOAMD_HEADPHONES_VOL)
462 			return EINVAL;
463 		sc->sc_out_port = cp->un.ord;
464 		break;
465 	default:
466 		return EINVAL;
467 		/* NOTREACHED */
468 	}
469 	return 0;
470 }
471 
472 int
473 am7930_get_port(void *addr, mixer_ctrl_t *cp)
474 {
475 	struct am7930_softc *sc = addr;
476 
477 	DPRINTF(("am7930_get_port: port=%d\n", cp->dev));
478 	if (cp->dev == AUDIOAMD_RECORD_SOURCE ||
479 	    cp->dev == AUDIOAMD_MONITOR_OUTPUT ||
480 	    cp->dev == AUDIOAMD_MIC_MUTE) {
481 		if (cp->type != AUDIO_MIXER_ENUM)
482 			return EINVAL;
483 	} else if (cp->type != AUDIO_MIXER_VALUE ||
484 	    cp->un.value.num_channels != 1) {
485 		return EINVAL;
486 	}
487 
488 	switch(cp->dev) {
489 	case AUDIOAMD_MIC_VOL:
490 		cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = sc->sc_rlevel;
491 		break;
492 	case AUDIOAMD_SPEAKER_VOL:
493 	case AUDIOAMD_HEADPHONES_VOL:
494 		cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = sc->sc_plevel;
495 		break;
496 	case AUDIOAMD_MONITOR_VOL:
497 		cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = sc->sc_mlevel;
498 		break;
499 	case AUDIOAMD_RECORD_SOURCE:
500 		cp->un.ord = AUDIOAMD_MIC_VOL;
501 		break;
502 	case AUDIOAMD_MIC_MUTE:
503 		cp->un.ord = sc->sc_mic_mute;
504 		break;
505 	case AUDIOAMD_MONITOR_OUTPUT:
506 		cp->un.ord = sc->sc_out_port;
507 		break;
508 	default:
509 		return EINVAL;
510 		/* NOTREACHED */
511 	}
512 	return 0;
513 }
514 
515 
516 /*
517  * Define mixer control facilities.
518  */
519 int
520 am7930_query_devinfo(void *addr, mixer_devinfo_t *dip)
521 {
522 	DPRINTF(("am7930_query_devinfo()\n"));
523 
524 	switch(dip->index) {
525 	case AUDIOAMD_MIC_VOL:
526 		dip->type = AUDIO_MIXER_VALUE;
527 		dip->mixer_class = AUDIOAMD_INPUT_CLASS;
528 		dip->prev =  AUDIO_MIXER_LAST;
529 		dip->next = AUDIOAMD_MIC_MUTE;
530 		strlcpy(dip->label.name, AudioNmicrophone,
531 		    sizeof dip->label.name);
532 		dip->un.v.num_channels = 1;
533 		strlcpy(dip->un.v.units.name, AudioNvolume,
534 		    sizeof dip->un.v.units.name);
535 		break;
536 	case AUDIOAMD_SPEAKER_VOL:
537 		dip->type = AUDIO_MIXER_VALUE;
538 		dip->mixer_class = AUDIOAMD_OUTPUT_CLASS;
539 		dip->prev = dip->next = AUDIO_MIXER_LAST;
540 		strlcpy(dip->label.name, AudioNspeaker,
541 		    sizeof dip->label.name);
542 		dip->un.v.num_channels = 1;
543 		strlcpy(dip->un.v.units.name, AudioNvolume,
544 		    sizeof dip->un.v.units.name);
545 		break;
546 	case AUDIOAMD_HEADPHONES_VOL:
547 		dip->type = AUDIO_MIXER_VALUE;
548 		dip->mixer_class = AUDIOAMD_OUTPUT_CLASS;
549 		dip->prev = dip->next = AUDIO_MIXER_LAST;
550 		strlcpy(dip->label.name, AudioNheadphone,
551 		    sizeof dip->label.name);
552 		dip->un.v.num_channels = 1;
553 		strlcpy(dip->un.v.units.name, AudioNvolume,
554 		    sizeof dip->un.v.units.name);
555 		break;
556 	case AUDIOAMD_MONITOR_VOL:
557 		dip->type = AUDIO_MIXER_VALUE;
558 		dip->mixer_class = AUDIOAMD_MONITOR_CLASS;
559 		dip->prev = dip->next = AUDIO_MIXER_LAST;
560 		strlcpy(dip->label.name, AudioNmonitor,
561 		    sizeof dip->label.name);
562 		dip->un.v.num_channels = 1;
563 		strlcpy(dip->un.v.units.name, AudioNvolume,
564 		    sizeof dip->un.v.units.name);
565 		break;
566 	case AUDIOAMD_RECORD_SOURCE:
567 		dip->type = AUDIO_MIXER_ENUM;
568 		dip->mixer_class = AUDIOAMD_RECORD_CLASS;
569 		dip->prev = dip->next = AUDIO_MIXER_LAST;
570 		strlcpy(dip->label.name, AudioNsource,
571 		    sizeof dip->label.name);
572 		dip->un.e.num_mem = 1;
573 		strlcpy(dip->un.e.member[0].label.name, AudioNmicrophone,
574 		    sizeof dip->un.e.member[0].label.name);
575 		dip->un.e.member[0].ord = AUDIOAMD_MIC_VOL;
576 		break;
577 	case AUDIOAMD_MONITOR_OUTPUT:
578 		dip->type = AUDIO_MIXER_ENUM;
579 		dip->mixer_class = AUDIOAMD_MONITOR_CLASS;
580 		dip->prev = dip->next = AUDIO_MIXER_LAST;
581 		strlcpy(dip->label.name, AudioNoutput,
582 		    sizeof dip->label.name);
583 		dip->un.e.num_mem = 2;
584 		strlcpy(dip->un.e.member[0].label.name, AudioNspeaker,
585 		    sizeof dip->un.e.member[0].label.name);
586 		dip->un.e.member[0].ord = AUDIOAMD_SPEAKER_VOL;
587 		strlcpy(dip->un.e.member[1].label.name, AudioNheadphone,
588 		    sizeof dip->un.e.member[1].label.name);
589 		dip->un.e.member[1].ord = AUDIOAMD_HEADPHONES_VOL;
590 		break;
591 	case AUDIOAMD_MIC_MUTE:
592 		dip->type = AUDIO_MIXER_ENUM;
593 		dip->mixer_class = AUDIOAMD_INPUT_CLASS;
594 		dip->prev =  AUDIOAMD_MIC_VOL;
595 		dip->next = AUDIO_MIXER_LAST;
596 		strlcpy(dip->label.name, AudioNmute,
597 		    sizeof dip->label.name);
598 		dip->un.e.num_mem = 2;
599 		strlcpy(dip->un.e.member[0].label.name, AudioNoff,
600 		    sizeof dip->un.e.member[0].label.name);
601 		dip->un.e.member[0].ord = 0;
602 		strlcpy(dip->un.e.member[1].label.name, AudioNon,
603 		    sizeof dip->un.e.member[1].label.name);
604 		dip->un.e.member[1].ord = 1;
605 		break;
606 	case AUDIOAMD_INPUT_CLASS:
607 		dip->type = AUDIO_MIXER_CLASS;
608 		dip->mixer_class = AUDIOAMD_INPUT_CLASS;
609 		dip->prev = dip->next = AUDIO_MIXER_LAST;
610 		strlcpy(dip->label.name, AudioCinputs,
611 		    sizeof dip->label.name);
612 		break;
613 	case AUDIOAMD_OUTPUT_CLASS:
614 		dip->type = AUDIO_MIXER_CLASS;
615 		dip->mixer_class = AUDIOAMD_OUTPUT_CLASS;
616 		dip->prev = dip->next = AUDIO_MIXER_LAST;
617 		strlcpy(dip->label.name, AudioCoutputs,
618 		    sizeof dip->label.name);
619 		break;
620 	case AUDIOAMD_RECORD_CLASS:
621 		dip->type = AUDIO_MIXER_CLASS;
622 		dip->mixer_class = AUDIOAMD_RECORD_CLASS;
623 		dip->prev = dip->next = AUDIO_MIXER_LAST;
624 		strlcpy(dip->label.name, AudioCrecord,
625 		    sizeof dip->label.name);
626 		break;
627 	case AUDIOAMD_MONITOR_CLASS:
628 		dip->type = AUDIO_MIXER_CLASS;
629 		dip->mixer_class = AUDIOAMD_MONITOR_CLASS;
630 		dip->prev = dip->next = AUDIO_MIXER_LAST;
631 		strlcpy(dip->label.name, AudioCmonitor,
632 		    sizeof dip->label.name);
633 		break;
634 	default:
635 		return ENXIO;
636 		/*NOTREACHED*/
637 	}
638 
639 	DPRINTF(("AUDIO_MIXER_DEVINFO: name=%s\n", dip->label.name));
640 
641 	return 0;
642 }
643