Home | History | Annotate | Line # | Download | only in g2
      1 /*	$NetBSD: aica.c,v 1.31 2024/02/07 04:20:27 msaitoh Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2003 SHIMIZU Ryo
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  *
     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. The name of the author may not be used to endorse or promote products
     17  *    derived from this software without specific prior written permission.
     18  *
     19  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     20  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     21  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     22  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     23  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     24  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     25  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     26  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     27  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     28  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     29  */
     30 
     31 #include <sys/cdefs.h>
     32 __KERNEL_RCSID(0, "$NetBSD: aica.c,v 1.31 2024/02/07 04:20:27 msaitoh Exp $");
     33 
     34 #include <sys/param.h>
     35 #include <sys/systm.h>
     36 #include <sys/device.h>
     37 #include <sys/kernel.h>
     38 #include <sys/proc.h>
     39 #include <sys/audioio.h>
     40 #include <sys/bus.h>
     41 
     42 #include <dev/audio/audio_if.h>
     43 #include <dev/audio/audiovar.h>	/* AUDIO_MIN_FREQUENCY */
     44 
     45 #include <machine/sysasicvar.h>
     46 
     47 #include <dreamcast/dev/g2/g2busvar.h>
     48 #include <dreamcast/dev/g2/aicavar.h>
     49 #include <dreamcast/dev/microcode/aica_armcode.h>
     50 
     51 #define	AICA_REG_ADDR	0x00700000
     52 #define	AICA_RAM_START	0x00800000
     53 #define	AICA_RAM_SIZE	0x00200000
     54 #define	AICA_NCHAN	64
     55 #define	AICA_TIMEOUT	0x1800
     56 
     57 struct aica_softc {
     58 	device_t		sc_dev;		/* base device */
     59 	kmutex_t		sc_lock;
     60 	kmutex_t		sc_intr_lock;
     61 	bus_space_tag_t		sc_memt;
     62 	bus_space_handle_t	sc_aica_regh;
     63 	bus_space_handle_t	sc_aica_memh;
     64 
     65 	/* audio property */
     66 	int			sc_precision;
     67 	int			sc_channels;
     68 	int			sc_rate;
     69 	void			(*sc_intr)(void *);
     70 	void			*sc_intr_arg;
     71 
     72 	int			sc_output_master;
     73 	int			sc_output_gain[2];
     74 #define	AICA_VOLUME_LEFT	0
     75 #define	AICA_VOLUME_RIGHT	1
     76 
     77 	/* work for output */
     78 	void			*sc_buffer;
     79 	void			*sc_buffer_start;
     80 	void			*sc_buffer_end;
     81 	int			sc_blksize;
     82 	int			sc_nextfill;
     83 };
     84 
     85 static const struct audio_format aica_formats[] = {
     86 	{
     87 		.mode		= AUMODE_PLAY,
     88 		.encoding	= AUDIO_ENCODING_SLINEAR_LE,
     89 		.validbits	= 16,
     90 		.precision	= 16,
     91 		.channels	= 2,
     92 		.channel_mask	= AUFMT_STEREO,
     93 		.frequency_type	= 0,
     94 		.frequency	= { AUDIO_MIN_FREQUENCY, 65536 },
     95 	},
     96 };
     97 #define AICA_NFORMATS	__arraycount(aica_formats)
     98 
     99 int aica_match(device_t, cfdata_t, void *);
    100 void aica_attach(device_t, device_t, void *);
    101 int aica_print(void *, const char *);
    102 
    103 CFATTACH_DECL_NEW(aica, sizeof(struct aica_softc), aica_match, aica_attach,
    104     NULL, NULL);
    105 
    106 const struct audio_device aica_device = {
    107 	"Dreamcast Sound",
    108 	"",
    109 	"aica"
    110 };
    111 
    112 inline static void aica_g2fifo_wait(void);
    113 void aica_enable(struct aica_softc *);
    114 void aica_disable(struct aica_softc *);
    115 void aica_memwrite(struct aica_softc *, bus_size_t, uint32_t *, int);
    116 void aica_ch2p16write(struct aica_softc *, bus_size_t, uint16_t *, int);
    117 void aica_ch2p8write(struct aica_softc *, bus_size_t, uint8_t *, int);
    118 void aica_command(struct aica_softc *, uint32_t);
    119 void aica_sendparam(struct aica_softc *, uint32_t, int, int);
    120 void aica_play(struct aica_softc *, int, int, int, int);
    121 void aica_fillbuffer(struct aica_softc *);
    122 
    123 /* intr */
    124 int aica_intr(void *);
    125 
    126 /* for audio */
    127 int aica_query_format(void *, audio_format_query_t *);
    128 int aica_set_format(void *, int,
    129     const audio_params_t *, const audio_params_t *,
    130     audio_filter_reg_t *, audio_filter_reg_t *);
    131 int aica_round_blocksize(void *, int, int, const audio_params_t *);
    132 size_t aica_round_buffersize(void *, int, size_t);
    133 int aica_trigger_output(void *, void *, void *, int, void (*)(void *), void *,
    134     const audio_params_t *);
    135 int aica_halt_output(void *);
    136 int aica_getdev(void *, struct audio_device *);
    137 int aica_set_port(void *, mixer_ctrl_t *);
    138 int aica_get_port(void *, mixer_ctrl_t *);
    139 int aica_query_devinfo(void *, mixer_devinfo_t *);
    140 void aica_encode(int, int, int, int, u_char *, u_short **);
    141 int aica_get_props(void *);
    142 void aica_get_locks(void *, kmutex_t **, kmutex_t **);
    143 
    144 const struct audio_hw_if aica_hw_if = {
    145 	.query_format		= aica_query_format,
    146 	.set_format		= aica_set_format,
    147 	.round_blocksize	= aica_round_blocksize,
    148 	.halt_output		= aica_halt_output,
    149 	.getdev			= aica_getdev,
    150 	.set_port		= aica_set_port,
    151 	.get_port		= aica_get_port,
    152 	.query_devinfo		= aica_query_devinfo,
    153 	.round_buffersize	= aica_round_buffersize,
    154 	.get_props		= aica_get_props,
    155 	.trigger_output		= aica_trigger_output,
    156 	.get_locks		= aica_get_locks,
    157 };
    158 
    159 int
    160 aica_match(device_t parent, cfdata_t cf, void *aux)
    161 {
    162 	static int aica_matched = 0;
    163 
    164 	if (aica_matched)
    165 		return 0;
    166 
    167 	aica_matched = 1;
    168 	return 1;
    169 }
    170 
    171 void
    172 aica_attach(device_t parent, device_t self, void *aux)
    173 {
    174 	struct aica_softc *sc;
    175 	struct g2bus_attach_args *ga;
    176 	int i;
    177 
    178 	sc = device_private(self);
    179 	ga = aux;
    180 	sc->sc_dev = self;
    181 	sc->sc_memt = ga->ga_memt;
    182 
    183 	mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_NONE);
    184 	mutex_init(&sc->sc_intr_lock, MUTEX_DEFAULT, IPL_SCHED);
    185 
    186 	if (bus_space_map(sc->sc_memt, AICA_REG_ADDR, 0x3000, 0,
    187 	    &sc->sc_aica_regh) != 0) {
    188 		aprint_error(": can't map AICA register space\n");
    189 		return;
    190 	}
    191 
    192 	if (bus_space_map(sc->sc_memt, AICA_RAM_START, AICA_RAM_SIZE, 0,
    193 	    &sc->sc_aica_memh) != 0) {
    194 		aprint_error(": can't map AICA memory space\n");
    195 		return;
    196 	}
    197 
    198 	aprint_normal(": ARM7 Sound Processing Unit\n");
    199 
    200 	aica_disable(sc);
    201 
    202 	for (i = 0; i < AICA_NCHAN; i++)
    203 		bus_space_write_4(sc->sc_memt,sc->sc_aica_regh, i << 7,
    204 		    ((bus_space_read_4(sc->sc_memt, sc->sc_aica_regh, i << 7)
    205 		    & ~0x4000) | 0x8000));
    206 
    207 	/* load microcode, and clear memory */
    208 	bus_space_set_region_4(sc->sc_memt, sc->sc_aica_memh,
    209 	    0, 0, AICA_RAM_SIZE / 4);
    210 
    211 	aica_memwrite(sc, 0, aica_armcode, sizeof(aica_armcode));
    212 
    213 	aica_enable(sc);
    214 
    215 	aprint_normal_dev(self, "interrupting at %s\n",
    216 	    sysasic_intr_string(SYSASIC_IRL9));
    217 	sysasic_intr_establish(SYSASIC_EVENT_AICA, IPL_BIO, SYSASIC_IRL9,
    218 	    aica_intr, sc);
    219 
    220 	audio_attach_mi(&aica_hw_if, sc, self);
    221 
    222 	/* init parameters */
    223 	sc->sc_output_master = 255;
    224 	sc->sc_output_gain[AICA_VOLUME_LEFT]  = 255;
    225 	sc->sc_output_gain[AICA_VOLUME_RIGHT] = 255;
    226 }
    227 
    228 void
    229 aica_enable(struct aica_softc *sc)
    230 {
    231 
    232 	bus_space_write_4(sc->sc_memt, sc->sc_aica_regh, 0x28a8, 24);
    233 	bus_space_write_4(sc->sc_memt, sc->sc_aica_regh, 0x2c00,
    234 	    bus_space_read_4(sc->sc_memt, sc->sc_aica_regh, 0x2c00) & ~1);
    235 }
    236 
    237 void
    238 aica_disable(struct aica_softc *sc)
    239 {
    240 
    241 	bus_space_write_4(sc->sc_memt, sc->sc_aica_regh, 0x2c00,
    242 	    bus_space_read_4(sc->sc_memt, sc->sc_aica_regh, 0x2c00) | 1);
    243 }
    244 
    245 inline static void
    246 aica_g2fifo_wait(void)
    247 {
    248 	int i;
    249 
    250 	i = AICA_TIMEOUT;
    251 	while (--i > 0)
    252 		if ((*(volatile uint32_t *)0xa05f688c) & 0x11)
    253 			break;
    254 }
    255 
    256 void
    257 aica_memwrite(struct aica_softc *sc, bus_size_t offset, uint32_t *src, int len)
    258 {
    259 	int n;
    260 
    261 	KASSERT((offset & 3) == 0);
    262 	n = (len + 3) / 4;	/* uint32_t * n (aligned) */
    263 
    264 	aica_g2fifo_wait();
    265 	bus_space_write_region_4(sc->sc_memt, sc->sc_aica_memh,
    266 	    offset, src, n);
    267 }
    268 
    269 void
    270 aica_ch2p16write(struct aica_softc *sc, bus_size_t offset, uint16_t *src,
    271     int len)
    272 {
    273 	union {
    274 		uint32_t w[8];
    275 		uint16_t s[16];
    276 	} buf;
    277 	uint16_t *p;
    278 	int i;
    279 
    280 	KASSERT((offset & 3) == 0);
    281 
    282 	while (len >= 32) {
    283 		p = buf.s;
    284 		*p++ = *src++; src++;
    285 		*p++ = *src++; src++;
    286 		*p++ = *src++; src++;
    287 		*p++ = *src++; src++;
    288 		*p++ = *src++; src++;
    289 		*p++ = *src++; src++;
    290 		*p++ = *src++; src++;
    291 		*p++ = *src++; src++;
    292 		*p++ = *src++; src++;
    293 		*p++ = *src++; src++;
    294 		*p++ = *src++; src++;
    295 		*p++ = *src++; src++;
    296 		*p++ = *src++; src++;
    297 		*p++ = *src++; src++;
    298 		*p++ = *src++; src++;
    299 		*p++ = *src++; src++;
    300 
    301 		aica_g2fifo_wait();
    302 		bus_space_write_region_4(sc->sc_memt, sc->sc_aica_memh,
    303 		    offset, buf.w , 32 / 4);
    304 
    305 		offset += sizeof(uint16_t) * 16;
    306 		len -= 32;
    307 	}
    308 
    309 	if (len / 2 > 0) {
    310 		p = buf.s;
    311 		for (i = 0; i < len / 2; i++) {
    312 			*p++ = *src++; src++;
    313 		}
    314 
    315 		aica_g2fifo_wait();
    316 		bus_space_write_region_4(sc->sc_memt, sc->sc_aica_memh,
    317 		    offset, buf.w, len / 4);
    318 	}
    319 }
    320 
    321 void
    322 aica_ch2p8write(struct aica_softc *sc, bus_size_t offset, uint8_t *src,
    323     int len)
    324 {
    325 	uint32_t buf[8];
    326 	uint8_t *p;
    327 	int i;
    328 
    329 	KASSERT((offset & 3) == 0);
    330 	while (len >= 32) {
    331 		p = (uint8_t *)buf;
    332 
    333 		*p++ = *src++; src++;
    334 		*p++ = *src++; src++;
    335 		*p++ = *src++; src++;
    336 		*p++ = *src++; src++;
    337 		*p++ = *src++; src++;
    338 		*p++ = *src++; src++;
    339 		*p++ = *src++; src++;
    340 		*p++ = *src++; src++;
    341 		*p++ = *src++; src++;
    342 		*p++ = *src++; src++;
    343 		*p++ = *src++; src++;
    344 		*p++ = *src++; src++;
    345 		*p++ = *src++; src++;
    346 		*p++ = *src++; src++;
    347 		*p++ = *src++; src++;
    348 		*p++ = *src++; src++;
    349 		*p++ = *src++; src++;
    350 		*p++ = *src++; src++;
    351 		*p++ = *src++; src++;
    352 		*p++ = *src++; src++;
    353 		*p++ = *src++; src++;
    354 		*p++ = *src++; src++;
    355 		*p++ = *src++; src++;
    356 		*p++ = *src++; src++;
    357 		*p++ = *src++; src++;
    358 		*p++ = *src++; src++;
    359 		*p++ = *src++; src++;
    360 		*p++ = *src++; src++;
    361 		*p++ = *src++; src++;
    362 		*p++ = *src++; src++;
    363 		*p++ = *src++; src++;
    364 		*p++ = *src++; src++;
    365 
    366 		aica_g2fifo_wait();
    367 		bus_space_write_region_4(sc->sc_memt, sc->sc_aica_memh,
    368 		    offset, buf, 32 / 4);
    369 
    370 		offset += 32;
    371 		len -= 32;
    372 	}
    373 
    374 	if (len) {
    375 		p = (uint8_t *)buf;
    376 		for (i = 0; i < len; i++) {
    377 			*p++ = *src++; src++;
    378 		}
    379 
    380 		aica_g2fifo_wait();
    381 		bus_space_write_region_4(sc->sc_memt, sc->sc_aica_memh,
    382 		    offset, buf, len / 4);
    383 	}
    384 }
    385 
    386 int
    387 aica_query_format(void *addr, audio_format_query_t *afp)
    388 {
    389 
    390 	return audio_query_format(aica_formats, AICA_NFORMATS, afp);
    391 }
    392 
    393 int
    394 aica_set_format(void *addr, int setmode,
    395     const audio_params_t *play, const audio_params_t *rec,
    396     audio_filter_reg_t *pfil, audio_filter_reg_t *rfil)
    397 {
    398 	struct aica_softc *sc;
    399 
    400 	sc = addr;
    401 	sc->sc_precision = play->precision;
    402 	sc->sc_channels = play->channels;
    403 	sc->sc_rate = play->sample_rate;
    404 	return 0;
    405 }
    406 
    407 int
    408 aica_round_blocksize(void *addr, int blk, int mode, const audio_params_t *param)
    409 {
    410 #if 0	/* XXX this has not worked since kent-audio1 merge? */
    411 	struct aica_softc *sc;
    412 
    413 	sc = addr;
    414 	switch (sc->sc_precision) {
    415 	case 4:
    416 		if (sc->sc_channels == 1)
    417 			return AICA_DMABUF_SIZE / 4;
    418 		else
    419 			return AICA_DMABUF_SIZE / 2;
    420 		break;
    421 	case 8:
    422 		if (sc->sc_channels == 1)
    423 			return AICA_DMABUF_SIZE / 2;
    424 		else
    425 			return AICA_DMABUF_SIZE;
    426 		break;
    427 	case 16:
    428 		if (sc->sc_channels == 1)
    429 			return AICA_DMABUF_SIZE;
    430 		else
    431 			return AICA_DMABUF_SIZE * 2;
    432 		break;
    433 	default:
    434 		break;
    435 	}
    436 
    437 #endif
    438 	return AICA_DMABUF_SIZE / 4;
    439 }
    440 
    441 size_t
    442 aica_round_buffersize(void *addr, int dir, size_t bufsize)
    443 {
    444 	struct aica_softc *sc;
    445 
    446 	sc = addr;
    447 	if (bufsize > 65536 * sc->sc_channels)
    448 		return 65536 * sc->sc_channels;
    449 	return bufsize;
    450 }
    451 
    452 void
    453 aica_command(struct aica_softc *sc, uint32_t command)
    454 {
    455 
    456 	bus_space_write_4(sc->sc_memt, sc->sc_aica_memh,
    457 	    AICA_ARM_CMD_COMMAND, command);
    458 	bus_space_write_4(sc->sc_memt,sc->sc_aica_memh, AICA_ARM_CMD_SERIAL,
    459 	    bus_space_read_4(sc->sc_memt, sc->sc_aica_memh,
    460 	    AICA_ARM_CMD_SERIAL) + 1);
    461 }
    462 
    463 void
    464 aica_sendparam(struct aica_softc *sc, uint32_t command,
    465     int32_t lparam, int32_t rparam)
    466 {
    467 
    468 	bus_space_write_4(sc->sc_memt,sc->sc_aica_memh,
    469 	    AICA_ARM_CMD_LPARAM, lparam);
    470 	bus_space_write_4(sc->sc_memt,sc->sc_aica_memh,
    471 	    AICA_ARM_CMD_RPARAM, rparam);
    472 
    473 	aica_command(sc, command);
    474 }
    475 
    476 void
    477 aica_play(struct aica_softc *sc, int blksize, int channel, int rate, int prec)
    478 {
    479 
    480 	bus_space_write_4(sc->sc_memt,sc->sc_aica_memh,
    481 	    AICA_ARM_CMD_BLOCKSIZE, blksize);
    482 	bus_space_write_4(sc->sc_memt,sc->sc_aica_memh,
    483 	    AICA_ARM_CMD_CHANNEL, channel);
    484 	bus_space_write_4(sc->sc_memt,sc->sc_aica_memh,
    485 	    AICA_ARM_CMD_RATE, rate);
    486 	bus_space_write_4(sc->sc_memt,sc->sc_aica_memh,
    487 	    AICA_ARM_CMD_PRECISION, prec);
    488 
    489 	aica_command(sc, AICA_COMMAND_PLAY);
    490 }
    491 
    492 void
    493 aica_fillbuffer(struct aica_softc *sc)
    494 {
    495 
    496 	if (sc->sc_channels == 2) {
    497 		if (sc->sc_precision == 16) {
    498 			aica_ch2p16write(sc,
    499 			    AICA_DMABUF_LEFT + sc->sc_nextfill,
    500 			    (uint16_t *)sc->sc_buffer + 0, sc->sc_blksize / 2);
    501 			aica_ch2p16write(sc,
    502 			    AICA_DMABUF_RIGHT + sc->sc_nextfill,
    503 			    (uint16_t *)sc->sc_buffer + 1, sc->sc_blksize / 2);
    504 		} else if (sc->sc_precision == 8) {
    505 			aica_ch2p8write(sc, AICA_DMABUF_LEFT + sc->sc_nextfill,
    506 			    (uint8_t *)sc->sc_buffer + 0, sc->sc_blksize / 2);
    507 			aica_ch2p8write(sc, AICA_DMABUF_RIGHT + sc->sc_nextfill,
    508 			    (uint8_t *)sc->sc_buffer + 1, sc->sc_blksize / 2);
    509 		}
    510 	} else {
    511 		aica_memwrite(sc, AICA_DMABUF_MONO + sc->sc_nextfill,
    512 		    sc->sc_buffer, sc->sc_blksize);
    513 	}
    514 
    515 	sc->sc_buffer = (int8_t *)sc->sc_buffer + sc->sc_blksize;
    516 	if (sc->sc_buffer >= sc->sc_buffer_end)
    517 		sc->sc_buffer = sc->sc_buffer_start;
    518 
    519 	sc->sc_nextfill ^= sc->sc_blksize / sc->sc_channels;
    520 }
    521 
    522 int
    523 aica_intr(void *arg)
    524 {
    525 	struct aica_softc *sc;
    526 
    527 	sc = arg;
    528 
    529 	mutex_spin_enter(&sc->sc_intr_lock);
    530 
    531 	aica_fillbuffer(sc);
    532 
    533 	/* call audio interrupt handler (audio_pintr()) */
    534 	if (sc->sc_intr != NULL) {
    535 		(*(sc->sc_intr))(sc->sc_intr_arg);
    536 	}
    537 
    538 	/* clear SPU interrupt */
    539 	bus_space_write_4(sc->sc_memt, sc->sc_aica_regh, 0x28bc, 0x20);
    540 
    541 	mutex_spin_exit(&sc->sc_intr_lock);
    542 
    543 	return 1;
    544 }
    545 
    546 int
    547 aica_trigger_output(void *addr, void *start, void *end, int blksize,
    548     void (*intr)(void *), void *arg, const audio_params_t *param)
    549 {
    550 	struct aica_softc *sc;
    551 
    552 	sc = addr;
    553 
    554 	sc->sc_buffer_start = sc->sc_buffer = start;
    555 	sc->sc_buffer_end = end;
    556 	sc->sc_blksize = blksize;
    557 	sc->sc_nextfill = 0;
    558 
    559 	sc->sc_intr = intr;
    560 	sc->sc_intr_arg = arg;
    561 
    562 	/*
    563 	 * The aica arm side driver uses a double buffer to play sounds.
    564 	 * we need to fill two buffers before playing.
    565 	 */
    566 	aica_fillbuffer(sc);
    567 	aica_fillbuffer(sc);
    568 
    569 	/* ...and start playing */
    570 	aica_play(sc, blksize / sc->sc_channels, sc->sc_channels, sc->sc_rate,
    571 	    sc->sc_precision);
    572 
    573 	return 0;
    574 }
    575 
    576 int
    577 aica_halt_output(void *addr)
    578 {
    579 	struct aica_softc *sc;
    580 
    581 	sc = addr;
    582 	aica_command(sc, AICA_COMMAND_STOP);
    583 	sc->sc_intr = NULL;
    584 	return 0;
    585 }
    586 
    587 int
    588 aica_getdev(void *addr, struct audio_device *ret)
    589 {
    590 
    591 	*ret = aica_device;
    592 	return 0;
    593 }
    594 
    595 int
    596 aica_set_port(void *addr, mixer_ctrl_t *mc)
    597 {
    598 	struct aica_softc *sc;
    599 
    600 	sc = addr;
    601 	switch (mc->dev) {
    602 	case AICA_MASTER_VOL:
    603 		sc->sc_output_master =
    604 		    mc->un.value.level[AUDIO_MIXER_LEVEL_MONO] & 0xff;
    605 		aica_sendparam(sc, AICA_COMMAND_MVOL,
    606 		    sc->sc_output_master, sc->sc_output_master);
    607 		break;
    608 	case AICA_OUTPUT_GAIN:
    609 		sc->sc_output_gain[AICA_VOLUME_LEFT] =
    610 		    mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT]  & 0xff;
    611 		sc->sc_output_gain[AICA_VOLUME_RIGHT] =
    612 		    mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] & 0xff;
    613 		aica_sendparam(sc, AICA_COMMAND_VOL,
    614 		    sc->sc_output_gain[AICA_VOLUME_LEFT],
    615 		    sc->sc_output_gain[AICA_VOLUME_RIGHT]);
    616 		break;
    617 	default:
    618 		return EINVAL;
    619 	}
    620 
    621 	return 0;
    622 }
    623 
    624 int
    625 aica_get_port(void *addr, mixer_ctrl_t *mc)
    626 {
    627 	struct aica_softc *sc;
    628 
    629 	sc = addr;
    630 	switch (mc->dev) {
    631 	case AICA_MASTER_VOL:
    632 		if (mc->un.value.num_channels != 1)
    633 			return EINVAL;
    634 		mc->un.value.level[AUDIO_MIXER_LEVEL_MONO] =
    635 		    L16TO256(L256TO16(sc->sc_output_master));
    636 		break;
    637 	case AICA_OUTPUT_GAIN:
    638 		mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] =
    639 		    sc->sc_output_gain[AICA_VOLUME_LEFT];
    640 		mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] =
    641 		    sc->sc_output_gain[AICA_VOLUME_RIGHT];
    642 		break;
    643 	default:
    644 		return EINVAL;
    645 	}
    646 	return 0;
    647 }
    648 
    649 int
    650 aica_query_devinfo(void *addr, mixer_devinfo_t *md)
    651 {
    652 
    653 	switch (md->index) {
    654 	case AICA_MASTER_VOL:
    655 		md->type = AUDIO_MIXER_VALUE;
    656 		md->mixer_class = AICA_OUTPUT_CLASS;
    657 		md->prev = md->next = AUDIO_MIXER_LAST;
    658 		strcpy(md->label.name, AudioNmaster);
    659 		md->un.v.num_channels = 1;
    660 		strcpy(md->un.v.units.name, AudioNvolume);
    661 		return 0;
    662 	case AICA_OUTPUT_GAIN:
    663 		md->type = AUDIO_MIXER_VALUE;
    664 		md->mixer_class = AICA_OUTPUT_CLASS;
    665 		md->prev = md->next = AUDIO_MIXER_LAST;
    666 		strcpy(md->label.name, AudioNoutput);
    667 		md->un.v.num_channels = 2;
    668 		strcpy(md->label.name, AudioNvolume);
    669 		return 0;
    670 	case AICA_OUTPUT_CLASS:
    671 		md->type = AUDIO_MIXER_CLASS;
    672 		md->mixer_class = AICA_OUTPUT_CLASS;
    673 		md->next = md->prev = AUDIO_MIXER_LAST;
    674 		strcpy(md->label.name, AudioCoutputs);
    675 		return 0;
    676 	}
    677 
    678 	return ENXIO;
    679 }
    680 
    681 int
    682 aica_get_props(void *addr)
    683 {
    684 
    685 	return AUDIO_PROP_PLAYBACK;
    686 }
    687 
    688 void
    689 aica_get_locks(void *addr, kmutex_t **intr, kmutex_t **thread)
    690 {
    691 	struct aica_softc *sc;
    692 
    693 	sc = addr;
    694 	*intr = &sc->sc_intr_lock;
    695 	*thread = &sc->sc_lock;
    696 }
    697