Home | History | Annotate | Line # | Download | only in dev
toccata.c revision 1.17
      1 /* $NetBSD: toccata.c,v 1.17 2014/01/22 00:25:16 christos 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.17 2014/01/22 00:25:16 christos 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_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 	toccata_open,
    181 	toccata_close,
    182 	0,	/*
    183 		 * XXX toccata_drain could be written:
    184 		 * sleep for play interrupt. This loses less than 512 bytes of
    185 		 * sample data, otherwise up to 1024.
    186 		 */
    187 	ad1848_query_encoding,
    188 	ad1848_set_params,
    189 	toccata_round_blocksize,
    190 	ad1848_commit_settings,
    191 	0,	/* init_output */	/* XXX need this to prefill? */
    192 	0,	/* init_input */
    193 	toccata_start_output,
    194 	toccata_start_input,
    195 	toccata_halt_output,
    196 	toccata_halt_input,
    197 	0,	/* speaker */
    198 	toccata_getdev,
    199 	0,	/* setfd */
    200 	toccata_set_port,
    201 	toccata_get_port,
    202 	toccata_query_devinfo,
    203 	0,	/* alloc/free */
    204 	0,
    205 	toccata_round_buffersize, /* round_buffer */
    206 	0,	/* mappage */
    207 	toccata_get_props,
    208 	0,	/* trigger_output */
    209 	0,
    210 	0,
    211 	toccata_get_locks,
    212 };
    213 
    214 struct toccata_softc {
    215 	struct ad1848_softc	sc_ad;
    216 	struct isr		sc_isr;
    217 	volatile uint8_t	*sc_boardp; /* only need a few addresses! */
    218 
    219 	void			(*sc_captmore)(void *);
    220 	void			 *sc_captarg;
    221 	void			 *sc_captbuf;
    222 	int			sc_captbufsz;
    223 
    224 	void			(*sc_playmore)(void *);
    225 	void			 *sc_playarg;
    226 
    227 	kmutex_t		sc_lock;
    228 	kmutex_t		sc_intr_lock;
    229 };
    230 
    231 int toccata_match(device_t, cfdata_t, void *);
    232 void toccata_attach(device_t, device_t, void *);
    233 
    234 CFATTACH_DECL_NEW(toccata, sizeof(struct toccata_softc),
    235     toccata_match, toccata_attach, NULL, NULL);
    236 
    237 int
    238 toccata_match(device_t parent, cfdata_t cfp, void *aux)
    239 {
    240 	struct zbus_args *zap;
    241 
    242 	zap = aux;
    243 
    244 	if (zap->manid != 18260)
    245 		return (0);
    246 
    247 	if (zap->prodid != 12)
    248 		return (0);
    249 
    250 	return (1);
    251 }
    252 
    253 void
    254 toccata_attach(device_t parent, device_t self, void *aux)
    255 {
    256 	struct toccata_softc *sc;
    257 	struct ad1848_softc *asc;
    258 	struct zbus_args *zap;
    259 	volatile uint8_t *boardp;
    260 
    261 	sc = device_private(self);
    262 	asc = &sc->sc_ad;
    263 	asc->sc_dev = self;
    264 	zap = aux;
    265 
    266 	boardp = (volatile uint8_t *)zap->va;
    267 	sc->sc_boardp = boardp;
    268 
    269 	*boardp = TOCC_RST;
    270 	delay(500000);		/* look up value */
    271 	*boardp = TOCC_ACT;
    272 
    273 	asc->parent = sc;
    274 	asc->sc_readreg = toccata_readreg;
    275 	asc->sc_writereg = toccata_writereg;
    276 
    277 	asc->chip_name = "ad1848";
    278 	asc->mode = 1;
    279 	ad1848_attach(asc);
    280 	printf("\n");
    281 
    282 	sc->sc_captbuf = 0;
    283 	sc->sc_playmore = 0;
    284 
    285 	mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
    286 	mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_SCHED);
    287 
    288 	sc->sc_isr.isr_ipl = 6;
    289 	sc->sc_isr.isr_arg = sc;
    290 	sc->sc_isr.isr_intr = toccata_intr;
    291 	add_isr(&sc->sc_isr);
    292 
    293 	audio_attach_mi(&audiocs_hw_if, sc, self);
    294 
    295 }
    296 
    297 /* interrupt handler */
    298 int
    299 toccata_intr(void *tag) {
    300 	struct toccata_softc *sc;
    301 	uint8_t *buf;
    302 	volatile uint8_t *fifo;
    303 	uint8_t status;
    304 	int i;
    305 
    306 	sc = tag;
    307 
    308 	mutex_spin_enter(&sc->sc_intr_lock);
    309 
    310 	status = *(sc->sc_boardp);
    311 
    312 	if (status & TOCC_FIFO_INT) {	/* active low */
    313 		mutex_spin_exit(&sc->sc_intr_lock);
    314 		return 0;
    315 	}
    316 
    317 	if (status & TOCC_FIFO_PBHE) {
    318 		if (sc->sc_playmore) {
    319 			(*sc->sc_playmore)(sc->sc_playarg);
    320 			mutex_spin_exit(&sc->sc_intr_lock);
    321 			return 1;
    322 		}
    323 	} else if (status & TOCC_FIFO_CPHF) {
    324 		if (sc->sc_captbuf) {
    325 			buf = sc->sc_captbuf;
    326 			fifo = sc->sc_boardp + TOCC_FIFO_DATA;
    327 
    328 			for (i = sc->sc_captbufsz/4 - 1; i>=0; --i) {
    329 				*buf++ = *fifo;
    330 				*buf++ = *fifo;
    331 				*buf++ = *fifo;
    332 				*buf++ = *fifo;
    333 			}
    334 
    335 			/* XXX if (sc->sc_captmore) { */
    336 			(*sc->sc_captmore)(sc->sc_captarg);
    337 			mutex_spin_exit(&sc->sc_intr_lock);
    338 			return 1;
    339 		}
    340 	}
    341 
    342 	/*
    343 	 * Something is wrong; switch interrupts off to avoid wedging the
    344 	 * machine, and notify the alpha tester.
    345 	 * Normally, the halt_* functions should have switched off the
    346 	 * FIFO interrupt.
    347 	 */
    348 #ifdef DEBUG
    349 	printf("%s: got unexpected interrupt %x\n",
    350 	    device_xname(sc->sc_ad.sc_dev), status);
    351 #endif
    352 	*sc->sc_boardp = TOCC_ACT;
    353 	mutex_spin_exit(&sc->sc_intr_lock);
    354 	return 1;
    355 }
    356 
    357 /* support for ad1848 functions */
    358 
    359 int
    360 toccata_readreg(struct ad1848_softc *asc, int offset)
    361 {
    362 	struct toccata_softc *sc;
    363 
    364 	sc = (struct toccata_softc *)asc;
    365 	return *(sc->sc_boardp + TOCC_CODEC_ADDR +
    366 		offset * (TOCC_CODEC_REG - TOCC_CODEC_ADDR));
    367 }
    368 
    369 void
    370 toccata_writereg(struct ad1848_softc *asc, int offset, int value)
    371 {
    372 	struct toccata_softc *sc;
    373 
    374 	sc = (struct toccata_softc *)asc;
    375 	*(sc->sc_boardp + TOCC_CODEC_ADDR +
    376 		offset * (TOCC_CODEC_REG - TOCC_CODEC_ADDR)) = value;
    377 }
    378 
    379 /* our own copy of open/close; we don't ever enable the ad1848 interrupts */
    380 int
    381 toccata_open(void *addr, int flags)
    382 {
    383 	struct toccata_softc *sc;
    384 	struct ad1848_softc *asc;
    385 
    386 	sc = addr;
    387 	asc = &sc->sc_ad;
    388 
    389 	asc->open_mode = flags;
    390 	/* If recording && monitoring, the playback part is also used. */
    391 	if (flags & FREAD && asc->mute[AD1848_MONITOR_CHANNEL] == 0)
    392 		ad1848_mute_wave_output(asc, WAVE_UNMUTE1, 1);
    393 
    394 #ifdef AUDIO_DEBUG
    395 	if (ad1848debug)
    396 		ad1848_dump_regs(asc);
    397 #endif
    398 
    399 	return 0;
    400 }
    401 
    402 void
    403 toccata_close(void *addr)
    404 {
    405 	struct toccata_softc *sc;
    406 	struct ad1848_softc *asc;
    407 	unsigned reg;
    408 
    409 	sc = addr;
    410 	asc = &sc->sc_ad;
    411 	asc->open_mode = 0;
    412 
    413 	ad1848_mute_wave_output(asc, WAVE_UNMUTE1, 0);
    414 
    415 	reg = ad_read(&sc->sc_ad, SP_INTERFACE_CONFIG);
    416 	ad_write(&sc->sc_ad, SP_INTERFACE_CONFIG,
    417 		(reg & ~(CAPTURE_ENABLE|PLAYBACK_ENABLE)));
    418 
    419 	/* Disable interrupts */
    420 	*sc->sc_boardp = TOCC_ACT;
    421 #ifdef AUDIO_DEBUG
    422 	if (ad1848debug)
    423 		ad1848_dump_regs(asc);
    424 #endif
    425 }
    426 
    427 int
    428 toccata_round_blocksize(void *addr, int blk,
    429 			int mode, const audio_params_t *param)
    430 {
    431 	int ret;
    432 
    433 	ret = blk > 512 ? 512 : (blk & -4);
    434 
    435 	return ret;
    436 }
    437 
    438 size_t
    439 toccata_round_buffersize(void *addr, int direction, size_t suggested)
    440 {
    441 
    442 	return suggested & -4;
    443 }
    444 
    445 struct audio_device toccata_device = {
    446 	"toccata", "x", "audio"
    447 };
    448 
    449 int
    450 toccata_getdev(void *addr, struct audio_device *retp)
    451 {
    452 
    453 	*retp = toccata_device;
    454 	return 0;
    455 }
    456 
    457 int
    458 toccata_get_props(void *addr)
    459 {
    460 	return 0;
    461 }
    462 
    463 void
    464 toccata_get_locks(void *opaque, kmutex_t **intr, kmutex_t **thread)
    465 {
    466 	struct toccata_softc *sc = opaque;
    467 
    468 	*intr = &sc->sc_intr_lock;
    469 	*thread = &sc->sc_lock;
    470 }
    471 
    472 int
    473 toccata_halt_input(void *addr)
    474 {
    475 	struct toccata_softc *sc;
    476 	unsigned reg;
    477 
    478 	sc = addr;
    479 
    480 	/* we're half_duplex; be brutal */
    481 	*sc->sc_boardp = TOCC_CP_TAIL;
    482 	sc->sc_captmore = 0;
    483 	sc->sc_captbuf = 0;
    484 
    485 	reg = ad_read(&sc->sc_ad, SP_INTERFACE_CONFIG);
    486 	ad_write(&sc->sc_ad, SP_INTERFACE_CONFIG, (reg & ~CAPTURE_ENABLE));
    487 
    488 	return 0;
    489 }
    490 
    491 int
    492 toccata_start_input(void *addr, void *block, int blksize,
    493 	void (*intr)(void *), void *intrarg)
    494 {
    495 	struct toccata_softc *sc;
    496 	unsigned int reg;
    497 	volatile uint8_t *cmd;
    498 
    499 	sc = addr;
    500 	cmd = sc->sc_boardp;
    501 
    502 	if (sc->sc_captmore == 0) {
    503 
    504 		/* we're half-duplex, be brutal */
    505 		*cmd = TOCC_ACT;
    506 		*cmd = TOCC_CP_MAIN;
    507 
    508 		reg = ad_read(&sc->sc_ad, SP_INTERFACE_CONFIG);
    509 		ad_write(&sc->sc_ad, SP_INTERFACE_CONFIG,
    510 		    (reg | CAPTURE_ENABLE));
    511 
    512 	}
    513 
    514 	sc->sc_captarg = intrarg;
    515 	sc->sc_captmore = intr;
    516 	sc->sc_captbuf = (uint8_t *)block;
    517 	sc->sc_captbufsz = blksize;
    518 
    519 	return 0;
    520 }
    521 
    522 int
    523 toccata_halt_output(void *addr)
    524 {
    525 	struct toccata_softc *sc;
    526 	unsigned int reg;
    527 
    528 	sc = addr;
    529 
    530 	/* we're half_duplex; be brutal */
    531 	*sc->sc_boardp = TOCC_PB_TAIL;
    532 	sc->sc_playmore = 0;
    533 
    534 	reg = ad_read(&sc->sc_ad, SP_INTERFACE_CONFIG);
    535 	ad_write(&sc->sc_ad, SP_INTERFACE_CONFIG, (reg & ~PLAYBACK_ENABLE));
    536 
    537 	return 0;
    538 }
    539 
    540 int
    541 toccata_start_output(void *addr, void *block, int blksize,
    542 	void (*intr)(void*), void *intrarg)
    543 {
    544 	struct toccata_softc *sc;
    545 	unsigned reg;
    546 	int i;
    547 	volatile uint8_t *cmd, *fifo;
    548 	uint8_t *buf;
    549 
    550 	sc = addr;
    551 	buf = block;
    552 
    553 	cmd = sc->sc_boardp;
    554 	fifo = sc->sc_boardp + TOCC_FIFO_DATA;
    555 
    556 	if (sc->sc_playmore == 0) {
    557 		*cmd = TOCC_ACT;
    558 		*cmd = TOCC_PB_PREP;
    559 	}
    560 
    561 	/*
    562 	 * We rounded the blocksize to a multiple of 4 bytes. Modest
    563 	 * unrolling saves 2% of cputime playing 48000 16bit stereo
    564 	 * on 68040/25MHz.
    565 	 */
    566 
    567 	for (i = blksize/4 - 1; i>=0; --i) {
    568 		*fifo = *buf++;
    569 		*fifo = *buf++;
    570 		*fifo = *buf++;
    571 		*fifo = *buf++;
    572 	}
    573 
    574 	if (sc->sc_playmore == 0) {
    575 		reg = ad_read(&sc->sc_ad, SP_INTERFACE_CONFIG);
    576 		ad_write(&sc->sc_ad, SP_INTERFACE_CONFIG,
    577 		    (reg | PLAYBACK_ENABLE));
    578 
    579 		/* we're half-duplex, be brutal */
    580 		*sc->sc_boardp = TOCC_PB_MAIN;
    581 	}
    582 
    583 	sc->sc_playarg = intrarg;
    584 	sc->sc_playmore = intr;
    585 
    586 	return 0;
    587 }
    588 
    589 static ad1848_devmap_t csmapping[] = {
    590 	{ TOCCATA_MIC_IN_LVL, AD1848_KIND_MICGAIN, -1 },
    591 	{ TOCCATA_AUX1_LVL, AD1848_KIND_LVL, AD1848_AUX1_CHANNEL },
    592 	{ TOCCATA_AUX1_MUTE, AD1848_KIND_MUTE, AD1848_AUX1_CHANNEL },
    593 	{ TOCCATA_AUX2_LVL, AD1848_KIND_LVL, AD1848_AUX2_CHANNEL },
    594 	{ TOCCATA_AUX2_MUTE, AD1848_KIND_MUTE, AD1848_AUX2_CHANNEL },
    595 	{ TOCCATA_OUTPUT_LVL, AD1848_KIND_LVL, AD1848_DAC_CHANNEL },
    596 	{ TOCCATA_MONITOR_LVL, AD1848_KIND_LVL, AD1848_MONITOR_CHANNEL },
    597 	{ TOCCATA_MONITOR_MUTE, AD1848_KIND_MUTE, AD1848_MONITOR_CHANNEL },
    598 	{ TOCCATA_REC_LVL, AD1848_KIND_RECORDGAIN, -1 },
    599 	{ TOCCATA_RECORD_SOURCE, AD1848_KIND_RECORDSOURCE, -1 },
    600 /* only in mode 2: */
    601 	{ TOCCATA_LINE_IN_LVL, AD1848_KIND_LVL, AD1848_LINE_CHANNEL },
    602 	{ TOCCATA_LINE_IN_MUTE, AD1848_KIND_MUTE, AD1848_LINE_CHANNEL },
    603 };
    604 
    605 #define nummap (sizeof(csmapping) / sizeof(csmapping[0]))
    606 
    607 int
    608 toccata_set_port(void *addr, mixer_ctrl_t *cp)
    609 {
    610 	struct ad1848_softc *ac;
    611 
    612 	/* printf("set_port(%d)\n", cp->dev); */
    613 	ac = addr;
    614 	return ad1848_mixer_set_port(ac, csmapping,
    615 		ac->mode == 2 ? nummap : nummap - 2, cp);
    616 }
    617 
    618 int
    619 toccata_get_port(void *addr, mixer_ctrl_t *cp)
    620 {
    621 	struct ad1848_softc *ac;
    622 
    623 	/* printf("get_port(%d)\n", cp->dev); */
    624 	ac = addr;
    625 	return ad1848_mixer_get_port(ac, csmapping,
    626 		ac->mode == 2 ? nummap : nummap - 2, cp);
    627 }
    628 
    629 int
    630 toccata_query_devinfo(void *addr, mixer_devinfo_t *dip)
    631 {
    632 
    633 	switch(dip->index) {
    634 	case TOCCATA_MIC_IN_LVL:	/* Microphone */
    635 		dip->type = AUDIO_MIXER_VALUE;
    636 		dip->mixer_class = TOCCATA_INPUT_CLASS;
    637 		dip->prev = dip->next = AUDIO_MIXER_LAST;
    638 		strcpy(dip->label.name, AudioNmicrophone);
    639 		dip->un.v.num_channels = 1;
    640 		strcpy(dip->un.v.units.name, AudioNvolume);
    641 		break;
    642 #if 0
    643 
    644 	case TOCCATA_MONO_LVL:	/* mono/microphone mixer */
    645 		dip->type = AUDIO_MIXER_VALUE;
    646 		dip->mixer_class = TOCCATA_INPUT_CLASS;
    647 		dip->prev = AUDIO_MIXER_LAST;
    648 		dip->next = TOCCATA_MONO_MUTE;
    649 		strcpy(dip->label.name, AudioNmicrophone);
    650 		dip->un.v.num_channels = 1;
    651 		strcpy(dip->un.v.units.name, AudioNvolume);
    652 		break;
    653 #endif
    654 
    655 	case TOCCATA_AUX1_LVL:		/*  dacout */
    656 		dip->type = AUDIO_MIXER_VALUE;
    657 		dip->mixer_class = TOCCATA_INPUT_CLASS;
    658 		dip->prev = AUDIO_MIXER_LAST;
    659 		dip->next = TOCCATA_AUX1_MUTE;
    660 		strcpy(dip->label.name, "aux1");
    661 		dip->un.v.num_channels = 2;
    662 		strcpy(dip->un.v.units.name, AudioNvolume);
    663 		break;
    664 
    665 	case TOCCATA_AUX1_MUTE:
    666 		dip->mixer_class = TOCCATA_INPUT_CLASS;
    667 		dip->type = AUDIO_MIXER_ENUM;
    668 		dip->prev = TOCCATA_AUX1_LVL;
    669 		dip->next = AUDIO_MIXER_LAST;
    670 		goto mute;
    671 
    672 
    673 
    674 	case TOCCATA_AUX2_LVL:
    675 		dip->type = AUDIO_MIXER_VALUE;
    676 		dip->mixer_class = TOCCATA_INPUT_CLASS;
    677 		dip->prev = AUDIO_MIXER_LAST;
    678 		dip->next = TOCCATA_AUX2_MUTE;
    679 		strcpy(dip->label.name, "aux2");
    680 		dip->un.v.num_channels = 2;
    681 		strcpy(dip->un.v.units.name, AudioNvolume);
    682 		break;
    683 
    684 	case TOCCATA_AUX2_MUTE:
    685 		dip->mixer_class = TOCCATA_INPUT_CLASS;
    686 		dip->type = AUDIO_MIXER_ENUM;
    687 		dip->prev = TOCCATA_AUX2_LVL;
    688 		dip->next = AUDIO_MIXER_LAST;
    689 		goto mute;
    690 
    691 
    692 	case TOCCATA_MONITOR_LVL:	/* monitor level */
    693 		dip->type = AUDIO_MIXER_VALUE;
    694 		dip->mixer_class = TOCCATA_MONITOR_CLASS;
    695 		dip->next = TOCCATA_MONITOR_MUTE;
    696 		dip->prev = AUDIO_MIXER_LAST;
    697 		strcpy(dip->label.name, AudioNmonitor);
    698 		dip->un.v.num_channels = 1;
    699 		strcpy(dip->un.v.units.name, AudioNvolume);
    700 		break;
    701 
    702 	case TOCCATA_OUTPUT_LVL:	/* output volume */
    703 		dip->type = AUDIO_MIXER_VALUE;
    704 		dip->mixer_class = TOCCATA_OUTPUT_CLASS;
    705 		dip->prev = dip->next = AUDIO_MIXER_LAST;
    706 		strcpy(dip->label.name, AudioNmaster);
    707 		dip->un.v.num_channels = 2;
    708 		strcpy(dip->un.v.units.name, AudioNvolume);
    709 		break;
    710 #if 0
    711 	case TOCCATA_LINE_IN_LVL:	/* line */
    712 		dip->type = AUDIO_MIXER_VALUE;
    713 		dip->mixer_class = TOCCATA_INPUT_CLASS;
    714 		dip->prev = AUDIO_MIXER_LAST;
    715 		dip->next = TOCCATA_LINE_IN_MUTE;
    716 		strcpy(dip->label.name, AudioNline);
    717 		dip->un.v.num_channels = 2;
    718 		strcpy(dip->un.v.units.name, AudioNvolume);
    719 		break;
    720 
    721 	case TOCCATA_LINE_IN_MUTE:
    722 		dip->mixer_class = TOCCATA_INPUT_CLASS;
    723 		dip->type = AUDIO_MIXER_ENUM;
    724 		dip->prev = TOCCATA_LINE_IN_LVL;
    725 		dip->next = AUDIO_MIXER_LAST;
    726 		goto mute;
    727 #endif
    728 	case TOCCATA_MONITOR_MUTE:
    729 		dip->mixer_class = TOCCATA_MONITOR_CLASS;
    730 		dip->type = AUDIO_MIXER_ENUM;
    731 		dip->prev = TOCCATA_MONITOR_LVL;
    732 		dip->next = AUDIO_MIXER_LAST;
    733 	mute:
    734 		strcpy(dip->label.name, AudioNmute);
    735 		dip->un.e.num_mem = 2;
    736 		strcpy(dip->un.e.member[0].label.name, AudioNoff);
    737 		dip->un.e.member[0].ord = 0;
    738 		strcpy(dip->un.e.member[1].label.name, AudioNon);
    739 		dip->un.e.member[1].ord = 1;
    740 		break;
    741 
    742 	case TOCCATA_REC_LVL:	/* record level */
    743 		dip->type = AUDIO_MIXER_VALUE;
    744 		dip->mixer_class = TOCCATA_INPUT_CLASS;
    745 		dip->prev = AUDIO_MIXER_LAST;
    746 		dip->next = TOCCATA_RECORD_SOURCE;
    747 		strcpy(dip->label.name, AudioNrecord);
    748 		dip->un.v.num_channels = 2;
    749 		strcpy(dip->un.v.units.name, AudioNvolume);
    750 		break;
    751 
    752 	case TOCCATA_RECORD_SOURCE:
    753 		dip->mixer_class = TOCCATA_RECORD_CLASS;
    754 		dip->type = AUDIO_MIXER_ENUM;
    755 		dip->prev = TOCCATA_REC_LVL;
    756 		dip->next = AUDIO_MIXER_LAST;
    757 		strcpy(dip->label.name, AudioNsource);
    758 		dip->un.e.num_mem = 4;
    759 		strcpy(dip->un.e.member[0].label.name, AudioNmicrophone);
    760 		dip->un.e.member[1].ord = MIC_IN_PORT;
    761 		strcpy(dip->un.e.member[1].label.name, AudioNline);
    762 		dip->un.e.member[3].ord = LINE_IN_PORT;
    763 		strcpy(dip->un.e.member[2].label.name, "aux1");
    764 		dip->un.e.member[2].ord = AUX1_IN_PORT;
    765 		strcpy(dip->un.e.member[3].label.name, AudioNoutput);
    766 		dip->un.e.member[0].ord = DAC_IN_PORT;
    767 		break;
    768 
    769 	case TOCCATA_INPUT_CLASS:		/* input class descriptor */
    770 		dip->type = AUDIO_MIXER_CLASS;
    771 		dip->mixer_class = TOCCATA_INPUT_CLASS;
    772 		dip->next = dip->prev = AUDIO_MIXER_LAST;
    773 		strcpy(dip->label.name, AudioCinputs);
    774 		break;
    775 
    776 	case TOCCATA_OUTPUT_CLASS:		/* output class descriptor */
    777 		dip->type = AUDIO_MIXER_CLASS;
    778 		dip->mixer_class = TOCCATA_OUTPUT_CLASS;
    779 		dip->next = dip->prev = AUDIO_MIXER_LAST;
    780 		strcpy(dip->label.name, AudioCoutputs);
    781 		break;
    782 
    783 	case TOCCATA_MONITOR_CLASS:		/* monitor class descriptor */
    784 		dip->type = AUDIO_MIXER_CLASS;
    785 		dip->mixer_class = TOCCATA_MONITOR_CLASS;
    786 		dip->next = dip->prev = AUDIO_MIXER_LAST;
    787 		strcpy(dip->label.name, AudioCmonitor);
    788 		break;
    789 
    790 	case TOCCATA_RECORD_CLASS:		/* record source class */
    791 		dip->type = AUDIO_MIXER_CLASS;
    792 		dip->mixer_class = TOCCATA_RECORD_CLASS;
    793 		dip->next = dip->prev = AUDIO_MIXER_LAST;
    794 		strcpy(dip->label.name, AudioCrecord);
    795 		break;
    796 
    797 	default:
    798 		return ENXIO;
    799 		/*NOTREACHED*/
    800 	}
    801 
    802 	return 0;
    803 }
    804