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