xref: /netbsd/sys/arch/amiga/dev/toccata.c (revision 33cb8414)
1 /* $NetBSD: toccata.c,v 1.21 2020/02/29 05:51:10 isaki Exp $ */
2 
3 /*-
4  * Copyright (c) 1998, 1999, 2001, 2002 The NetBSD Foundation, Inc.
5  * All rights reserved.
6  *
7  * This code is derived from software contributed to The NetBSD Foundation
8  * by Paul Kranenburg and Ignatios Souvatzis.
9  *
10  * Redistribution and use in source and binary forms, with or without
11  * modification, are permitted provided that the following conditions
12  * are met:
13  * 1. Redistributions of source code must retain the above copyright
14  *    notice, this list of conditions and the following disclaimer.
15  * 2. Redistributions in binary form must reproduce the above copyright
16  *    notice, this list of conditions and the following disclaimer in the
17  *    documentation and/or other materials provided with the distribution.
18  *
19  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29  * POSSIBILITY OF SUCH DAMAGE.
30  */
31 
32 #include <sys/cdefs.h>
33 __KERNEL_RCSID(0, "$NetBSD: toccata.c,v 1.21 2020/02/29 05:51:10 isaki Exp $");
34 
35 #include <sys/types.h>
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/device.h>
40 #include <sys/fcntl.h>		/* FREAD */
41 #include <sys/bus.h>
42 
43 #include <sys/audioio.h>
44 #include <dev/audio/audio_if.h>
45 
46 #include <dev/ic/ad1848reg.h>
47 #include <dev/ic/ad1848var.h>
48 
49 #include <amiga/dev/zbusvar.h>
50 #include <amiga/amiga/isr.h>
51 
52 
53 /* Register offsets. XXX All of this is guesswork. */
54 
55 /*
56  * The Toccata board consists of: GALs for ZBus AutoConfig(tm) glue, GALs
57  * that interface the FIFO chips and the audio codec chip to the ZBus,
58  * an AD1848 (or AD1845), and 2 Integrated Device Technology 7202LA
59  * (1024x9bit FIFO) chips.
60  */
61 
62 #define TOCC_FIFO_STAT	0x1ffe
63 #define TOCC_FIFO_DATA	0x2000
64 
65 /*
66  * I don't know whether the AD1848 PIO data registers are connected... and
67  * at 2 or 3 accesses to read or write a data byte in the best case, I better
68  * don't even think about it. The AD1848 address/status and data port are
69  * here:
70  */
71 #define TOCC_CODEC_ADDR	0x67FF
72 #define TOCC_CODEC_STAT	TOCC_CODEC_ADDR
73 #define TOCC_CODEC_REG	0x6801
74 
75 /* fifo status bits, read */
76 
77 #define TOCC_FIFO_INT	0x80	/* active low; together with one of those: */
78 
79 #define TOCC_FIFO_PBHE	0x08	/* playback fifo is half empty (active high) */
80 #define TOCC_FIFO_CPHF	0x04	/* capture fifo is half full (active high) */
81 
82 /* fifo status bits, write */
83 
84 /*
85  * seems to work like this:
86  * init: write 2; delay; write 1
87  *
88  * capture: write 1; write 1+4+8+0x40	(0x4D)
89  * capt. int: read 512 bytes out of fifo.
90  * capt. int off by writing 1+4+8	(0x0D)
91  *
92  * playback: write 1; write 1 + 0x10;	(0x11)
93  * 3/4 fill fifo with silence; init codec;
94  * write 1+4+0x10+0x80			(0x95)
95  * pb int: write 512 bytes to fifo
96  * pb int off by writing 1+4+0x10	(0x15)
97  */
98 
99 #define TOCC_RST	0x02
100 #define TOCC_ACT	0x01
101 #define TOCC_MAGIC	0x04
102 
103 #define TOCC_PB_INTENA	0x80
104 #define TOCC_PB_FILL	0x10
105 
106 #define TOCC_PB_PREP	(TOCC_ACT + TOCC_PB_FILL)
107 #define TOCC_PB_TAIL	(TOCC_PB_PREP + TOCC_MAGIC)
108 #define TOCC_PB_MAIN	(TOCC_PB_TAIL + TOCC_PB_INTENA)
109 
110 #define TOCC_CP_INTENA	0x40
111 #define TOCC_CP_RUN	0x08
112 
113 #define TOCC_CP_TAIL	(TOCC_ACT + TOCC_CP_RUN)
114 #define TOCC_CP_MAIN	(TOCC_CP_TAIL + TOCC_CP_INTENA + TOCC_MAGIC)
115 
116 /*
117  * For the port stuff. Similar to the cs4231 table, but MONO is not wired
118  * on the Toccata, which was designed for the AD1848. Also we know how
119  * to handle input.
120  */
121 
122 #define TOCCATA_INPUT_CLASS	0
123 #define TOCCATA_OUTPUT_CLASS	1
124 #define TOCCATA_MONITOR_CLASS	2
125 #define TOCCATA_RECORD_CLASS	3
126 
127 #define TOCCATA_RECORD_SOURCE	4
128 #define TOCCATA_REC_LVL		5
129 
130 #define TOCCATA_MIC_IN_LVL	6
131 
132 #define TOCCATA_AUX1_LVL	7
133 #define TOCCATA_AUX1_MUTE	8
134 
135 #define TOCCATA_AUX2_LVL	9
136 #define TOCCATA_AUX2_MUTE	10
137 
138 #define TOCCATA_MONITOR_LVL	11
139 #define TOCCATA_MONITOR_MUTE	12
140 #define TOCCATA_OUTPUT_LVL	13
141 
142 /* only on AD1845 in mode 2 */
143 
144 #define TOCCATA_LINE_IN_LVL	14
145 #define TOCCATA_LINE_IN_MUTE	15
146 
147 /* special, need support */
148 #define TOCCATA_MIC_LVL		16
149 #define TOCCATA_MIC_MUTE	17
150 
151 
152 
153 /* prototypes */
154 
155 int toccata_intr(void *);
156 int toccata_readreg(struct ad1848_softc *, int);
157 void toccata_writereg(struct ad1848_softc *, int, int);
158 
159 int toccata_round_blocksize(void *, int, int, const audio_params_t *);
160 size_t toccata_round_buffersize(void *, int, size_t);
161 
162 int toccata_open(void *, int);
163 void toccata_close(void *);
164 int toccata_getdev(void *, struct audio_device *);
165 int toccata_get_props(void *);
166 
167 int toccata_halt_input(void *);
168 int toccata_halt_output(void *);
169 int toccata_start_input(void *, void *, int, void (*)(void *), void *);
170 int toccata_start_output(void *, void *, int, void (*)(void *), void *);
171 
172 /* I suspect  those should be in a shared file */
173 int toccata_set_port(void *, mixer_ctrl_t *);
174 int toccata_get_port(void *, mixer_ctrl_t *);
175 int toccata_query_devinfo(void *, mixer_devinfo_t *);
176 
177 void toccata_get_locks(void *, kmutex_t **, kmutex_t **);
178 
179 const struct audio_hw_if audiocs_hw_if = {
180 	.open			= toccata_open,
181 	.close			= toccata_close,
182 	.query_format		= ad1848_query_format,
183 	.set_format		= ad1848_set_format,
184 	.round_blocksize	= toccata_round_blocksize,
185 	.commit_settings	= ad1848_commit_settings,
186 	.init_output		= NULL,	/* XXX need this to prefill? */
187 	.init_input		= NULL,
188 	.start_output		= toccata_start_output,
189 	.start_input		= toccata_start_input,
190 	.halt_output		= toccata_halt_output,
191 	.halt_input		= toccata_halt_input,
192 	.getdev			= toccata_getdev,
193 	.set_port		= toccata_set_port,
194 	.get_port		= toccata_get_port,
195 	.query_devinfo		= toccata_query_devinfo,
196 	.round_buffersize	= toccata_round_buffersize,
197 	.get_props		= toccata_get_props,
198 	.get_locks		= toccata_get_locks,
199 };
200 
201 struct toccata_softc {
202 	struct ad1848_softc	sc_ad;
203 	struct isr		sc_isr;
204 	volatile uint8_t	*sc_boardp; /* only need a few addresses! */
205 
206 	void			(*sc_captmore)(void *);
207 	void			 *sc_captarg;
208 	void			 *sc_captbuf;
209 	int			sc_captbufsz;
210 
211 	void			(*sc_playmore)(void *);
212 	void			 *sc_playarg;
213 
214 	kmutex_t		sc_lock;
215 	kmutex_t		sc_intr_lock;
216 };
217 
218 int toccata_match(device_t, cfdata_t, void *);
219 void toccata_attach(device_t, device_t, void *);
220 
221 CFATTACH_DECL_NEW(toccata, sizeof(struct toccata_softc),
222     toccata_match, toccata_attach, NULL, NULL);
223 
224 int
toccata_match(device_t parent,cfdata_t cfp,void * aux)225 toccata_match(device_t parent, cfdata_t cfp, void *aux)
226 {
227 	struct zbus_args *zap;
228 
229 	zap = aux;
230 
231 	if (zap->manid != 18260)
232 		return (0);
233 
234 	if (zap->prodid != 12)
235 		return (0);
236 
237 	return (1);
238 }
239 
240 void
toccata_attach(device_t parent,device_t self,void * aux)241 toccata_attach(device_t parent, device_t self, void *aux)
242 {
243 	struct toccata_softc *sc;
244 	struct ad1848_softc *asc;
245 	struct zbus_args *zap;
246 	volatile uint8_t *boardp;
247 
248 	sc = device_private(self);
249 	asc = &sc->sc_ad;
250 	asc->sc_dev = self;
251 	zap = aux;
252 
253 	boardp = (volatile uint8_t *)zap->va;
254 	sc->sc_boardp = boardp;
255 
256 	*boardp = TOCC_RST;
257 	delay(500000);		/* look up value */
258 	*boardp = TOCC_ACT;
259 
260 	asc->parent = sc;
261 	asc->sc_readreg = toccata_readreg;
262 	asc->sc_writereg = toccata_writereg;
263 
264 	asc->chip_name = "ad1848";
265 	asc->mode = 1;
266 	ad1848_attach(asc);
267 	printf("\n");
268 
269 	sc->sc_captbuf = 0;
270 	sc->sc_playmore = 0;
271 
272 	mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
273 	mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_SCHED);
274 
275 	sc->sc_isr.isr_ipl = 6;
276 	sc->sc_isr.isr_arg = sc;
277 	sc->sc_isr.isr_intr = toccata_intr;
278 	add_isr(&sc->sc_isr);
279 
280 	audio_attach_mi(&audiocs_hw_if, sc, self);
281 
282 }
283 
284 /* interrupt handler */
285 int
toccata_intr(void * tag)286 toccata_intr(void *tag) {
287 	struct toccata_softc *sc;
288 	uint8_t *buf;
289 	volatile uint8_t *fifo;
290 	uint8_t status;
291 	int i;
292 
293 	sc = tag;
294 
295 	mutex_spin_enter(&sc->sc_intr_lock);
296 
297 	status = *(sc->sc_boardp);
298 
299 	if (status & TOCC_FIFO_INT) {	/* active low */
300 		mutex_spin_exit(&sc->sc_intr_lock);
301 		return 0;
302 	}
303 
304 	if (status & TOCC_FIFO_PBHE) {
305 		if (sc->sc_playmore) {
306 			(*sc->sc_playmore)(sc->sc_playarg);
307 			mutex_spin_exit(&sc->sc_intr_lock);
308 			return 1;
309 		}
310 	} else if (status & TOCC_FIFO_CPHF) {
311 		if (sc->sc_captbuf) {
312 			buf = sc->sc_captbuf;
313 			fifo = sc->sc_boardp + TOCC_FIFO_DATA;
314 
315 			for (i = sc->sc_captbufsz/4 - 1; i>=0; --i) {
316 				*buf++ = *fifo;
317 				*buf++ = *fifo;
318 				*buf++ = *fifo;
319 				*buf++ = *fifo;
320 			}
321 
322 			/* XXX if (sc->sc_captmore) { */
323 			(*sc->sc_captmore)(sc->sc_captarg);
324 			mutex_spin_exit(&sc->sc_intr_lock);
325 			return 1;
326 		}
327 	}
328 
329 	/*
330 	 * Something is wrong; switch interrupts off to avoid wedging the
331 	 * machine, and notify the alpha tester.
332 	 * Normally, the halt_* functions should have switched off the
333 	 * FIFO interrupt.
334 	 */
335 #ifdef DEBUG
336 	printf("%s: got unexpected interrupt %x\n",
337 	    device_xname(sc->sc_ad.sc_dev), status);
338 #endif
339 	*sc->sc_boardp = TOCC_ACT;
340 	mutex_spin_exit(&sc->sc_intr_lock);
341 	return 1;
342 }
343 
344 /* support for ad1848 functions */
345 
346 int
toccata_readreg(struct ad1848_softc * asc,int offset)347 toccata_readreg(struct ad1848_softc *asc, int offset)
348 {
349 	struct toccata_softc *sc;
350 
351 	sc = (struct toccata_softc *)asc;
352 	return *(sc->sc_boardp + TOCC_CODEC_ADDR +
353 		offset * (TOCC_CODEC_REG - TOCC_CODEC_ADDR));
354 }
355 
356 void
toccata_writereg(struct ad1848_softc * asc,int offset,int value)357 toccata_writereg(struct ad1848_softc *asc, int offset, int value)
358 {
359 	struct toccata_softc *sc;
360 
361 	sc = (struct toccata_softc *)asc;
362 	*(sc->sc_boardp + TOCC_CODEC_ADDR +
363 		offset * (TOCC_CODEC_REG - TOCC_CODEC_ADDR)) = value;
364 }
365 
366 /* our own copy of open/close; we don't ever enable the ad1848 interrupts */
367 int
toccata_open(void * addr,int flags)368 toccata_open(void *addr, int flags)
369 {
370 	struct toccata_softc *sc;
371 	struct ad1848_softc *asc;
372 
373 	sc = addr;
374 	asc = &sc->sc_ad;
375 
376 	asc->open_mode = flags;
377 	/* If recording && monitoring, the playback part is also used. */
378 	if (flags & FREAD && asc->mute[AD1848_MONITOR_CHANNEL] == 0)
379 		ad1848_mute_wave_output(asc, WAVE_UNMUTE1, 1);
380 
381 #ifdef AUDIO_DEBUG
382 	if (ad1848debug)
383 		ad1848_dump_regs(asc);
384 #endif
385 
386 	return 0;
387 }
388 
389 void
toccata_close(void * addr)390 toccata_close(void *addr)
391 {
392 	struct toccata_softc *sc;
393 	struct ad1848_softc *asc;
394 	unsigned reg;
395 
396 	sc = addr;
397 	asc = &sc->sc_ad;
398 	asc->open_mode = 0;
399 
400 	ad1848_mute_wave_output(asc, WAVE_UNMUTE1, 0);
401 
402 	reg = ad_read(&sc->sc_ad, SP_INTERFACE_CONFIG);
403 	ad_write(&sc->sc_ad, SP_INTERFACE_CONFIG,
404 		(reg & ~(CAPTURE_ENABLE|PLAYBACK_ENABLE)));
405 
406 	/* Disable interrupts */
407 	*sc->sc_boardp = TOCC_ACT;
408 #ifdef AUDIO_DEBUG
409 	if (ad1848debug)
410 		ad1848_dump_regs(asc);
411 #endif
412 }
413 
414 int
toccata_round_blocksize(void * addr,int blk,int mode,const audio_params_t * param)415 toccata_round_blocksize(void *addr, int blk,
416 			int mode, const audio_params_t *param)
417 {
418 
419 	if (blk > 512)
420 		blk = 512;
421 	return blk;
422 }
423 
424 size_t
toccata_round_buffersize(void * addr,int direction,size_t suggested)425 toccata_round_buffersize(void *addr, int direction, size_t suggested)
426 {
427 
428 	return suggested & -4;
429 }
430 
431 struct audio_device toccata_device = {
432 	"toccata", "x", "audio"
433 };
434 
435 int
toccata_getdev(void * addr,struct audio_device * retp)436 toccata_getdev(void *addr, struct audio_device *retp)
437 {
438 
439 	*retp = toccata_device;
440 	return 0;
441 }
442 
443 int
toccata_get_props(void * addr)444 toccata_get_props(void *addr)
445 {
446 
447 	return AUDIO_PROP_PLAYBACK | AUDIO_PROP_CAPTURE;
448 }
449 
450 void
toccata_get_locks(void * opaque,kmutex_t ** intr,kmutex_t ** thread)451 toccata_get_locks(void *opaque, kmutex_t **intr, kmutex_t **thread)
452 {
453 	struct toccata_softc *sc = opaque;
454 
455 	*intr = &sc->sc_intr_lock;
456 	*thread = &sc->sc_lock;
457 }
458 
459 int
toccata_halt_input(void * addr)460 toccata_halt_input(void *addr)
461 {
462 	struct toccata_softc *sc;
463 	unsigned reg;
464 
465 	sc = addr;
466 
467 	/* we're half_duplex; be brutal */
468 	*sc->sc_boardp = TOCC_CP_TAIL;
469 	sc->sc_captmore = 0;
470 	sc->sc_captbuf = 0;
471 
472 	reg = ad_read(&sc->sc_ad, SP_INTERFACE_CONFIG);
473 	ad_write(&sc->sc_ad, SP_INTERFACE_CONFIG, (reg & ~CAPTURE_ENABLE));
474 
475 	return 0;
476 }
477 
478 int
toccata_start_input(void * addr,void * block,int blksize,void (* intr)(void *),void * intrarg)479 toccata_start_input(void *addr, void *block, int blksize,
480 	void (*intr)(void *), void *intrarg)
481 {
482 	struct toccata_softc *sc;
483 	unsigned int reg;
484 	volatile uint8_t *cmd;
485 
486 	sc = addr;
487 	cmd = sc->sc_boardp;
488 
489 	if (sc->sc_captmore == 0) {
490 
491 		/* we're half-duplex, be brutal */
492 		*cmd = TOCC_ACT;
493 		*cmd = TOCC_CP_MAIN;
494 
495 		reg = ad_read(&sc->sc_ad, SP_INTERFACE_CONFIG);
496 		ad_write(&sc->sc_ad, SP_INTERFACE_CONFIG,
497 		    (reg | CAPTURE_ENABLE));
498 
499 	}
500 
501 	sc->sc_captarg = intrarg;
502 	sc->sc_captmore = intr;
503 	sc->sc_captbuf = (uint8_t *)block;
504 	sc->sc_captbufsz = blksize;
505 
506 	return 0;
507 }
508 
509 int
toccata_halt_output(void * addr)510 toccata_halt_output(void *addr)
511 {
512 	struct toccata_softc *sc;
513 	unsigned int reg;
514 
515 	sc = addr;
516 
517 	/* we're half_duplex; be brutal */
518 	*sc->sc_boardp = TOCC_PB_TAIL;
519 	sc->sc_playmore = 0;
520 
521 	reg = ad_read(&sc->sc_ad, SP_INTERFACE_CONFIG);
522 	ad_write(&sc->sc_ad, SP_INTERFACE_CONFIG, (reg & ~PLAYBACK_ENABLE));
523 
524 	return 0;
525 }
526 
527 int
toccata_start_output(void * addr,void * block,int blksize,void (* intr)(void *),void * intrarg)528 toccata_start_output(void *addr, void *block, int blksize,
529 	void (*intr)(void*), void *intrarg)
530 {
531 	struct toccata_softc *sc;
532 	unsigned reg;
533 	int i;
534 	volatile uint8_t *cmd, *fifo;
535 	uint8_t *buf;
536 
537 	sc = addr;
538 	buf = block;
539 
540 	cmd = sc->sc_boardp;
541 	fifo = sc->sc_boardp + TOCC_FIFO_DATA;
542 
543 	if (sc->sc_playmore == 0) {
544 		*cmd = TOCC_ACT;
545 		*cmd = TOCC_PB_PREP;
546 	}
547 
548 	/*
549 	 * We rounded the blocksize to a multiple of 4 bytes. Modest
550 	 * unrolling saves 2% of cputime playing 48000 16bit stereo
551 	 * on 68040/25MHz.
552 	 */
553 
554 	for (i = blksize/4 - 1; i>=0; --i) {
555 		*fifo = *buf++;
556 		*fifo = *buf++;
557 		*fifo = *buf++;
558 		*fifo = *buf++;
559 	}
560 
561 	if (sc->sc_playmore == 0) {
562 		reg = ad_read(&sc->sc_ad, SP_INTERFACE_CONFIG);
563 		ad_write(&sc->sc_ad, SP_INTERFACE_CONFIG,
564 		    (reg | PLAYBACK_ENABLE));
565 
566 		/* we're half-duplex, be brutal */
567 		*sc->sc_boardp = TOCC_PB_MAIN;
568 	}
569 
570 	sc->sc_playarg = intrarg;
571 	sc->sc_playmore = intr;
572 
573 	return 0;
574 }
575 
576 static ad1848_devmap_t csmapping[] = {
577 	{ TOCCATA_MIC_IN_LVL, AD1848_KIND_MICGAIN, -1 },
578 	{ TOCCATA_AUX1_LVL, AD1848_KIND_LVL, AD1848_AUX1_CHANNEL },
579 	{ TOCCATA_AUX1_MUTE, AD1848_KIND_MUTE, AD1848_AUX1_CHANNEL },
580 	{ TOCCATA_AUX2_LVL, AD1848_KIND_LVL, AD1848_AUX2_CHANNEL },
581 	{ TOCCATA_AUX2_MUTE, AD1848_KIND_MUTE, AD1848_AUX2_CHANNEL },
582 	{ TOCCATA_OUTPUT_LVL, AD1848_KIND_LVL, AD1848_DAC_CHANNEL },
583 	{ TOCCATA_MONITOR_LVL, AD1848_KIND_LVL, AD1848_MONITOR_CHANNEL },
584 	{ TOCCATA_MONITOR_MUTE, AD1848_KIND_MUTE, AD1848_MONITOR_CHANNEL },
585 	{ TOCCATA_REC_LVL, AD1848_KIND_RECORDGAIN, -1 },
586 	{ TOCCATA_RECORD_SOURCE, AD1848_KIND_RECORDSOURCE, -1 },
587 /* only in mode 2: */
588 	{ TOCCATA_LINE_IN_LVL, AD1848_KIND_LVL, AD1848_LINE_CHANNEL },
589 	{ TOCCATA_LINE_IN_MUTE, AD1848_KIND_MUTE, AD1848_LINE_CHANNEL },
590 };
591 
592 #define nummap (sizeof(csmapping) / sizeof(csmapping[0]))
593 
594 int
toccata_set_port(void * addr,mixer_ctrl_t * cp)595 toccata_set_port(void *addr, mixer_ctrl_t *cp)
596 {
597 	struct ad1848_softc *ac;
598 
599 	/* printf("set_port(%d)\n", cp->dev); */
600 	ac = addr;
601 	return ad1848_mixer_set_port(ac, csmapping,
602 		ac->mode == 2 ? nummap : nummap - 2, cp);
603 }
604 
605 int
toccata_get_port(void * addr,mixer_ctrl_t * cp)606 toccata_get_port(void *addr, mixer_ctrl_t *cp)
607 {
608 	struct ad1848_softc *ac;
609 
610 	/* printf("get_port(%d)\n", cp->dev); */
611 	ac = addr;
612 	return ad1848_mixer_get_port(ac, csmapping,
613 		ac->mode == 2 ? nummap : nummap - 2, cp);
614 }
615 
616 int
toccata_query_devinfo(void * addr,mixer_devinfo_t * dip)617 toccata_query_devinfo(void *addr, mixer_devinfo_t *dip)
618 {
619 
620 	switch(dip->index) {
621 	case TOCCATA_MIC_IN_LVL:	/* Microphone */
622 		dip->type = AUDIO_MIXER_VALUE;
623 		dip->mixer_class = TOCCATA_INPUT_CLASS;
624 		dip->prev = dip->next = AUDIO_MIXER_LAST;
625 		strcpy(dip->label.name, AudioNmicrophone);
626 		dip->un.v.num_channels = 1;
627 		strcpy(dip->un.v.units.name, AudioNvolume);
628 		break;
629 #if 0
630 
631 	case TOCCATA_MONO_LVL:	/* mono/microphone mixer */
632 		dip->type = AUDIO_MIXER_VALUE;
633 		dip->mixer_class = TOCCATA_INPUT_CLASS;
634 		dip->prev = AUDIO_MIXER_LAST;
635 		dip->next = TOCCATA_MONO_MUTE;
636 		strcpy(dip->label.name, AudioNmicrophone);
637 		dip->un.v.num_channels = 1;
638 		strcpy(dip->un.v.units.name, AudioNvolume);
639 		break;
640 #endif
641 
642 	case TOCCATA_AUX1_LVL:		/*  dacout */
643 		dip->type = AUDIO_MIXER_VALUE;
644 		dip->mixer_class = TOCCATA_INPUT_CLASS;
645 		dip->prev = AUDIO_MIXER_LAST;
646 		dip->next = TOCCATA_AUX1_MUTE;
647 		strcpy(dip->label.name, "aux1");
648 		dip->un.v.num_channels = 2;
649 		strcpy(dip->un.v.units.name, AudioNvolume);
650 		break;
651 
652 	case TOCCATA_AUX1_MUTE:
653 		dip->mixer_class = TOCCATA_INPUT_CLASS;
654 		dip->type = AUDIO_MIXER_ENUM;
655 		dip->prev = TOCCATA_AUX1_LVL;
656 		dip->next = AUDIO_MIXER_LAST;
657 		goto mute;
658 
659 
660 
661 	case TOCCATA_AUX2_LVL:
662 		dip->type = AUDIO_MIXER_VALUE;
663 		dip->mixer_class = TOCCATA_INPUT_CLASS;
664 		dip->prev = AUDIO_MIXER_LAST;
665 		dip->next = TOCCATA_AUX2_MUTE;
666 		strcpy(dip->label.name, "aux2");
667 		dip->un.v.num_channels = 2;
668 		strcpy(dip->un.v.units.name, AudioNvolume);
669 		break;
670 
671 	case TOCCATA_AUX2_MUTE:
672 		dip->mixer_class = TOCCATA_INPUT_CLASS;
673 		dip->type = AUDIO_MIXER_ENUM;
674 		dip->prev = TOCCATA_AUX2_LVL;
675 		dip->next = AUDIO_MIXER_LAST;
676 		goto mute;
677 
678 
679 	case TOCCATA_MONITOR_LVL:	/* monitor level */
680 		dip->type = AUDIO_MIXER_VALUE;
681 		dip->mixer_class = TOCCATA_MONITOR_CLASS;
682 		dip->next = TOCCATA_MONITOR_MUTE;
683 		dip->prev = AUDIO_MIXER_LAST;
684 		strcpy(dip->label.name, AudioNmonitor);
685 		dip->un.v.num_channels = 1;
686 		strcpy(dip->un.v.units.name, AudioNvolume);
687 		break;
688 
689 	case TOCCATA_OUTPUT_LVL:	/* output volume */
690 		dip->type = AUDIO_MIXER_VALUE;
691 		dip->mixer_class = TOCCATA_OUTPUT_CLASS;
692 		dip->prev = dip->next = AUDIO_MIXER_LAST;
693 		strcpy(dip->label.name, AudioNmaster);
694 		dip->un.v.num_channels = 2;
695 		strcpy(dip->un.v.units.name, AudioNvolume);
696 		break;
697 #if 0
698 	case TOCCATA_LINE_IN_LVL:	/* line */
699 		dip->type = AUDIO_MIXER_VALUE;
700 		dip->mixer_class = TOCCATA_INPUT_CLASS;
701 		dip->prev = AUDIO_MIXER_LAST;
702 		dip->next = TOCCATA_LINE_IN_MUTE;
703 		strcpy(dip->label.name, AudioNline);
704 		dip->un.v.num_channels = 2;
705 		strcpy(dip->un.v.units.name, AudioNvolume);
706 		break;
707 
708 	case TOCCATA_LINE_IN_MUTE:
709 		dip->mixer_class = TOCCATA_INPUT_CLASS;
710 		dip->type = AUDIO_MIXER_ENUM;
711 		dip->prev = TOCCATA_LINE_IN_LVL;
712 		dip->next = AUDIO_MIXER_LAST;
713 		goto mute;
714 #endif
715 	case TOCCATA_MONITOR_MUTE:
716 		dip->mixer_class = TOCCATA_MONITOR_CLASS;
717 		dip->type = AUDIO_MIXER_ENUM;
718 		dip->prev = TOCCATA_MONITOR_LVL;
719 		dip->next = AUDIO_MIXER_LAST;
720 	mute:
721 		strcpy(dip->label.name, AudioNmute);
722 		dip->un.e.num_mem = 2;
723 		strcpy(dip->un.e.member[0].label.name, AudioNoff);
724 		dip->un.e.member[0].ord = 0;
725 		strcpy(dip->un.e.member[1].label.name, AudioNon);
726 		dip->un.e.member[1].ord = 1;
727 		break;
728 
729 	case TOCCATA_REC_LVL:	/* record level */
730 		dip->type = AUDIO_MIXER_VALUE;
731 		dip->mixer_class = TOCCATA_INPUT_CLASS;
732 		dip->prev = AUDIO_MIXER_LAST;
733 		dip->next = TOCCATA_RECORD_SOURCE;
734 		strcpy(dip->label.name, AudioNrecord);
735 		dip->un.v.num_channels = 2;
736 		strcpy(dip->un.v.units.name, AudioNvolume);
737 		break;
738 
739 	case TOCCATA_RECORD_SOURCE:
740 		dip->mixer_class = TOCCATA_RECORD_CLASS;
741 		dip->type = AUDIO_MIXER_ENUM;
742 		dip->prev = TOCCATA_REC_LVL;
743 		dip->next = AUDIO_MIXER_LAST;
744 		strcpy(dip->label.name, AudioNsource);
745 		dip->un.e.num_mem = 4;
746 		strcpy(dip->un.e.member[0].label.name, AudioNmicrophone);
747 		dip->un.e.member[1].ord = MIC_IN_PORT;
748 		strcpy(dip->un.e.member[1].label.name, AudioNline);
749 		dip->un.e.member[3].ord = LINE_IN_PORT;
750 		strcpy(dip->un.e.member[2].label.name, "aux1");
751 		dip->un.e.member[2].ord = AUX1_IN_PORT;
752 		strcpy(dip->un.e.member[3].label.name, AudioNoutput);
753 		dip->un.e.member[0].ord = DAC_IN_PORT;
754 		break;
755 
756 	case TOCCATA_INPUT_CLASS:		/* input class descriptor */
757 		dip->type = AUDIO_MIXER_CLASS;
758 		dip->mixer_class = TOCCATA_INPUT_CLASS;
759 		dip->next = dip->prev = AUDIO_MIXER_LAST;
760 		strcpy(dip->label.name, AudioCinputs);
761 		break;
762 
763 	case TOCCATA_OUTPUT_CLASS:		/* output class descriptor */
764 		dip->type = AUDIO_MIXER_CLASS;
765 		dip->mixer_class = TOCCATA_OUTPUT_CLASS;
766 		dip->next = dip->prev = AUDIO_MIXER_LAST;
767 		strcpy(dip->label.name, AudioCoutputs);
768 		break;
769 
770 	case TOCCATA_MONITOR_CLASS:		/* monitor class descriptor */
771 		dip->type = AUDIO_MIXER_CLASS;
772 		dip->mixer_class = TOCCATA_MONITOR_CLASS;
773 		dip->next = dip->prev = AUDIO_MIXER_LAST;
774 		strcpy(dip->label.name, AudioCmonitor);
775 		break;
776 
777 	case TOCCATA_RECORD_CLASS:		/* record source class */
778 		dip->type = AUDIO_MIXER_CLASS;
779 		dip->mixer_class = TOCCATA_RECORD_CLASS;
780 		dip->next = dip->prev = AUDIO_MIXER_LAST;
781 		strcpy(dip->label.name, AudioCrecord);
782 		break;
783 
784 	default:
785 		return ENXIO;
786 		/*NOTREACHED*/
787 	}
788 
789 	return 0;
790 }
791