Home | History | Annotate | Line # | Download | only in dev
awacs.c revision 1.2.2.4
      1 /*	$NetBSD: awacs.c,v 1.2.2.4 2001/02/11 19:11:04 bouyer Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2000 Tsubai Masanari.  All rights reserved.
      5  *
      6  * Redistribution and use in source and binary forms, with or without
      7  * modification, are permitted provided that the following conditions
      8  * are met:
      9  * 1. Redistributions of source code must retain the above copyright
     10  *    notice, this list of conditions and the following disclaimer.
     11  * 2. Redistributions in binary form must reproduce the above copyright
     12  *    notice, this list of conditions and the following disclaimer in the
     13  *    documentation and/or other materials provided with the distribution.
     14  * 3. The name of the author may not be used to endorse or promote products
     15  *    derived from this software without specific prior written permission.
     16  *
     17  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     18  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     19  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     20  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     21  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     22  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     23  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     24  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     25  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
     26  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 
     29 #include <sys/param.h>
     30 #include <sys/audioio.h>
     31 #include <sys/device.h>
     32 #include <sys/malloc.h>
     33 #include <sys/systm.h>
     34 
     35 #include <dev/auconv.h>
     36 #include <dev/audio_if.h>
     37 #include <dev/mulaw.h>
     38 
     39 #include <uvm/uvm_extern.h>
     40 
     41 #include <machine/autoconf.h>
     42 #include <machine/pio.h>
     43 #include <macppc/dev/dbdma.h>
     44 
     45 #ifdef AWACS_DEBUG
     46 # define DPRINTF printf
     47 #else
     48 # define DPRINTF while (0) printf
     49 #endif
     50 
     51 struct awacs_softc {
     52 	struct device sc_dev;
     53 
     54 	void (*sc_ointr)(void *);	/* dma completion intr handler */
     55 	void *sc_oarg;			/* arg for sc_ointr() */
     56 	int sc_opages;			/* # of output pages */
     57 
     58 	void (*sc_iintr)(void *);	/* dma completion intr handler */
     59 	void *sc_iarg;			/* arg for sc_iintr() */
     60 
     61 	u_int sc_record_source;		/* recording source mask */
     62 	u_int sc_output_mask;		/* output source mask */
     63 
     64 	char *sc_reg;
     65 	u_int sc_codecctl0;
     66 	u_int sc_codecctl1;
     67 	u_int sc_codecctl2;
     68 	u_int sc_codecctl4;
     69 	u_int sc_soundctl;
     70 
     71 	struct dbdma_regmap *sc_odma;
     72 	struct dbdma_regmap *sc_idma;
     73 	struct dbdma_command *sc_odmacmd;
     74 	struct dbdma_command *sc_idmacmd;
     75 };
     76 
     77 int awacs_match(struct device *, struct cfdata *, void *);
     78 void awacs_attach(struct device *, struct device *, void *);
     79 int awacs_intr(void *);
     80 
     81 int awacs_open(void *, int);
     82 void awacs_close(void *);
     83 int awacs_query_encoding(void *, struct audio_encoding *);
     84 int awacs_set_params(void *, int, int, struct audio_params *,
     85 			 struct audio_params *);
     86 int awacs_round_blocksize(void *, int);
     87 int awacs_trigger_output(void *, void *, void *, int, void (*)(void *),
     88 			     void *, struct audio_params *);
     89 int awacs_trigger_input(void *, void *, void *, int, void (*)(void *),
     90 			    void *, struct audio_params *);
     91 int awacs_halt_output(void *);
     92 int awacs_halt_input(void *);
     93 int awacs_getdev(void *, struct audio_device *);
     94 int awacs_set_port(void *, mixer_ctrl_t *);
     95 int awacs_get_port(void *, mixer_ctrl_t *);
     96 int awacs_query_devinfo(void *, mixer_devinfo_t *);
     97 size_t awacs_round_buffersize(void *, int, size_t);
     98 paddr_t awacs_mappage(void *, void *, off_t, int);
     99 int awacs_get_props(void *);
    100 
    101 static inline u_int awacs_read_reg(struct awacs_softc *, int);
    102 static inline void awacs_write_reg(struct awacs_softc *, int, int);
    103 void awacs_write_codec(struct awacs_softc *, int);
    104 void awacs_set_speaker_volume(struct awacs_softc *, int, int);
    105 void awacs_set_ext_volume(struct awacs_softc *, int, int);
    106 int awacs_set_rate(struct awacs_softc *, int);
    107 
    108 struct cfattach awacs_ca = {
    109 	sizeof(struct awacs_softc), awacs_match, awacs_attach
    110 };
    111 
    112 struct audio_hw_if awacs_hw_if = {
    113 	awacs_open,
    114 	awacs_close,
    115 	NULL,
    116 	awacs_query_encoding,
    117 	awacs_set_params,
    118 	awacs_round_blocksize,
    119 	NULL,
    120 	NULL,
    121 	NULL,
    122 	NULL,
    123 	NULL,
    124 	awacs_halt_output,
    125 	awacs_halt_input,
    126 	NULL,
    127 	awacs_getdev,
    128 	NULL,
    129 	awacs_set_port,
    130 	awacs_get_port,
    131 	awacs_query_devinfo,
    132 	NULL,
    133 	NULL,
    134 	awacs_round_buffersize,
    135 	awacs_mappage,
    136 	awacs_get_props,
    137 	awacs_trigger_output,
    138 	awacs_trigger_input,
    139 };
    140 
    141 struct audio_device awacs_device = {
    142 	"AWACS",
    143 	"",
    144 	"awacs"
    145 };
    146 
    147 /* register offset */
    148 #define AWACS_SOUND_CTRL	0x00
    149 #define AWACS_CODEC_CTRL	0x10
    150 #define AWACS_CODEC_STATUS	0x20
    151 #define AWACS_CLIP_COUNT	0x30
    152 #define AWACS_BYTE_SWAP		0x40
    153 
    154 /* sound control */
    155 #define AWACS_INPUT_SUBFRAME0	0x00000001
    156 #define AWACS_INPUT_SUBFRAME1	0x00000002
    157 #define AWACS_INPUT_SUBFRAME2	0x00000004
    158 #define AWACS_INPUT_SUBFRAME3	0x00000008
    159 
    160 #define AWACS_OUTPUT_SUBFRAME0	0x00000010
    161 #define AWACS_OUTPUT_SUBFRAME1	0x00000020
    162 #define AWACS_OUTPUT_SUBFRAME2	0x00000040
    163 #define AWACS_OUTPUT_SUBFRAME3	0x00000080
    164 
    165 #define AWACS_RATE_44100	0x00000000
    166 #define AWACS_RATE_29400	0x00000100
    167 #define AWACS_RATE_22050	0x00000200
    168 #define AWACS_RATE_17640	0x00000300
    169 #define AWACS_RATE_14700	0x00000400
    170 #define AWACS_RATE_11025	0x00000500
    171 #define AWACS_RATE_8820		0x00000600
    172 #define AWACS_RATE_7350		0x00000700
    173 #define AWACS_RATE_MASK		0x00000700
    174 
    175 /* codec control */
    176 #define AWACS_CODEC_ADDR0	0x00000000
    177 #define AWACS_CODEC_ADDR1	0x00001000
    178 #define AWACS_CODEC_ADDR2	0x00002000
    179 #define AWACS_CODEC_ADDR4	0x00004000
    180 #define AWACS_CODEC_EMSEL0	0x00000000
    181 #define AWACS_CODEC_EMSEL1	0x00400000
    182 #define AWACS_CODEC_EMSEL2	0x00800000
    183 #define AWACS_CODEC_EMSEL4	0x00c00000
    184 #define AWACS_CODEC_BUSY	0x01000000
    185 
    186 /* cc0 */
    187 #define AWACS_DEFAULT_CD_GAIN	0x000000bb
    188 #define AWACS_INPUT_CD		0x00000200
    189 #define AWACS_INPUT_MIC		0x00000400
    190 #define AWACS_INPUT_MASK	0x00000e00
    191 
    192 /* cc1 */
    193 #define AWACS_MUTE_SPEAKER	0x00000080
    194 #define AWACS_MUTE_HEADPHONE	0x00000200
    195 
    196 int
    197 awacs_match(parent, match, aux)
    198 	struct device *parent;
    199 	struct cfdata *match;
    200 	void *aux;
    201 {
    202 	struct confargs *ca = aux;
    203 
    204 	if (strcmp(ca->ca_name, "awacs") != 0 &&
    205 	    strcmp(ca->ca_name, "davbus") != 0)
    206 		return 0;
    207 
    208 	if (ca->ca_nreg < 24 || ca->ca_nintr < 12)
    209 		return 0;
    210 
    211 	/* XXX for now */
    212 	if (ca->ca_nintr > 12)
    213 		return 0;
    214 
    215 	return 1;
    216 }
    217 
    218 void
    219 awacs_attach(parent, self, aux)
    220 	struct device *parent;
    221 	struct device *self;
    222 	void *aux;
    223 {
    224 	struct awacs_softc *sc = (struct awacs_softc *)self;
    225 	struct confargs *ca = aux;
    226 
    227 	ca->ca_reg[0] += ca->ca_baseaddr;
    228 	ca->ca_reg[2] += ca->ca_baseaddr;
    229 	ca->ca_reg[4] += ca->ca_baseaddr;
    230 
    231 	sc->sc_reg = mapiodev(ca->ca_reg[0], ca->ca_reg[1]);
    232 
    233 	sc->sc_odma = mapiodev(ca->ca_reg[2], ca->ca_reg[3]); /* out */
    234 	sc->sc_idma = mapiodev(ca->ca_reg[4], ca->ca_reg[5]); /* in */
    235 	sc->sc_odmacmd = dbdma_alloc(20 * sizeof(struct dbdma_command));
    236 	sc->sc_idmacmd = dbdma_alloc(20 * sizeof(struct dbdma_command));
    237 
    238 	intr_establish(ca->ca_intr[0], IST_LEVEL, IPL_AUDIO, awacs_intr, sc);
    239 	intr_establish(ca->ca_intr[1], IST_LEVEL, IPL_AUDIO, awacs_intr, sc);
    240 	intr_establish(ca->ca_intr[2], IST_LEVEL, IPL_AUDIO, awacs_intr, sc);
    241 
    242 	printf(": irq %d,%d,%d\n",
    243 		ca->ca_intr[0], ca->ca_intr[1], ca->ca_intr[2]);
    244 
    245 	sc->sc_soundctl = AWACS_INPUT_SUBFRAME0 | AWACS_OUTPUT_SUBFRAME0 |
    246 		AWACS_RATE_44100;
    247 	awacs_write_reg(sc, AWACS_SOUND_CTRL, sc->sc_soundctl);
    248 
    249 	sc->sc_codecctl0 = AWACS_CODEC_ADDR0 | AWACS_CODEC_EMSEL0;
    250 	sc->sc_codecctl1 = AWACS_CODEC_ADDR1 | AWACS_CODEC_EMSEL0;
    251 	sc->sc_codecctl2 = AWACS_CODEC_ADDR2 | AWACS_CODEC_EMSEL0;
    252 	sc->sc_codecctl4 = AWACS_CODEC_ADDR4 | AWACS_CODEC_EMSEL0;
    253 
    254 	sc->sc_codecctl0 |= AWACS_INPUT_CD | AWACS_DEFAULT_CD_GAIN;
    255 	awacs_write_codec(sc, sc->sc_codecctl0);
    256 
    257 	/* Set initial volume[s] */
    258 	awacs_set_speaker_volume(sc, 80, 80);
    259 
    260 	/* Set loopback (for CD?) */
    261 	sc->sc_codecctl1 |= 0x440;
    262 	awacs_write_codec(sc, sc->sc_codecctl1);
    263 
    264 	sc->sc_output_mask = 1 << 0;
    265 
    266 	sc->sc_codecctl1 &= ~AWACS_MUTE_SPEAKER;
    267 	sc->sc_codecctl1 |= AWACS_MUTE_HEADPHONE;
    268 	awacs_write_codec(sc, sc->sc_codecctl1);
    269 
    270 	/* Enable interrupts and looping mode. */
    271 	/* XXX ... */
    272 
    273 	audio_attach_mi(&awacs_hw_if, sc, &sc->sc_dev);
    274 }
    275 
    276 u_int
    277 awacs_read_reg(sc, reg)
    278 	struct awacs_softc *sc;
    279 	int reg;
    280 {
    281 	char *addr = sc->sc_reg;
    282 
    283 	return in32rb(addr + reg);
    284 }
    285 
    286 void
    287 awacs_write_reg(sc, reg, val)
    288 	struct awacs_softc *sc;
    289 	int reg, val;
    290 {
    291 	char *addr = sc->sc_reg;
    292 
    293 	out32rb(addr + reg, val);
    294 }
    295 
    296 void
    297 awacs_write_codec(sc, value)
    298 	struct awacs_softc *sc;
    299 	int value;
    300 {
    301 	awacs_write_reg(sc, AWACS_CODEC_CTRL, value);
    302 	while (awacs_read_reg(sc, AWACS_CODEC_CTRL) & AWACS_CODEC_BUSY);
    303 }
    304 
    305 int
    306 awacs_intr(v)
    307 	void *v;
    308 {
    309 	struct awacs_softc *sc = v;
    310 	struct dbdma_command *cmd = sc->sc_odmacmd;
    311 	int count = sc->sc_opages;
    312 	int status;
    313 
    314 	/* Fill used buffer(s). */
    315 	while (count-- > 0) {
    316 		/* if DBDMA_INT_ALWAYS */
    317 		if (in16rb(&cmd->d_command) & 0x30) {	/* XXX */
    318 			status = in16rb(&cmd->d_status);
    319 			cmd->d_status = 0;
    320 			if (status)	/* status == 0x8400 */
    321 				if (sc->sc_ointr)
    322 					(*sc->sc_ointr)(sc->sc_oarg);
    323 		}
    324 		cmd++;
    325 	}
    326 
    327 	return 1;
    328 }
    329 
    330 int
    331 awacs_open(h, flags)
    332 	void *h;
    333 	int flags;
    334 {
    335 	return 0;
    336 }
    337 
    338 /*
    339  * Close function is called at splaudio().
    340  */
    341 void
    342 awacs_close(h)
    343 	void *h;
    344 {
    345 	struct awacs_softc *sc = h;
    346 
    347 	awacs_halt_output(sc);
    348 	awacs_halt_input(sc);
    349 
    350 	sc->sc_ointr = 0;
    351 	sc->sc_iintr = 0;
    352 }
    353 
    354 int
    355 awacs_query_encoding(h, ae)
    356 	void *h;
    357 	struct audio_encoding *ae;
    358 {
    359 	switch (ae->index) {
    360 	case 0:
    361 		strcpy(ae->name, AudioEslinear);
    362 		ae->encoding = AUDIO_ENCODING_SLINEAR;
    363 		ae->precision = 16;
    364 		ae->flags = 0;
    365 		return 0;
    366 	case 1:
    367 		strcpy(ae->name, AudioEslinear_be);
    368 		ae->encoding = AUDIO_ENCODING_SLINEAR_BE;
    369 		ae->precision = 16;
    370 		ae->flags = 0;
    371 		return 0;
    372 	case 2:
    373 		strcpy(ae->name, AudioEslinear_le);
    374 		ae->encoding = AUDIO_ENCODING_SLINEAR_LE;
    375 		ae->precision = 16;
    376 		ae->flags = 0;
    377 		return 0;
    378 	case 3:
    379 		strcpy(ae->name, AudioEmulaw);
    380 		ae->encoding = AUDIO_ENCODING_ULAW;
    381 		ae->precision = 8;
    382 		ae->flags = AUDIO_ENCODINGFLAG_EMULATED;
    383 		return 0;
    384 	case 4:
    385 		strcpy(ae->name, AudioEalaw);
    386 		ae->encoding = AUDIO_ENCODING_ALAW;
    387 		ae->precision = 8;
    388 		ae->flags = AUDIO_ENCODINGFLAG_EMULATED;
    389 		return 0;
    390 	default:
    391 		return EINVAL;
    392 	}
    393 }
    394 
    395 static void
    396 mono16_to_stereo16(v, p, cc)
    397 	void *v;
    398 	u_char *p;
    399 	int cc;
    400 {
    401 	int x;
    402 	int16_t *src, *dst;
    403 
    404 	src = (void *)(p + cc);
    405 	dst = (void *)(p + cc * 2);
    406 	while (cc > 0) {
    407 		x = *--src;
    408 		*--dst = x;
    409 		*--dst = x;
    410 		cc -= 2;
    411 	}
    412 }
    413 
    414 int
    415 awacs_set_params(h, setmode, usemode, play, rec)
    416 	void *h;
    417 	int setmode, usemode;
    418 	struct audio_params *play, *rec;
    419 {
    420 	struct awacs_softc *sc = h;
    421 	struct audio_params *p;
    422 	int mode, rate;
    423 
    424 	/*
    425 	 * This device only has one clock, so make the sample rates match.
    426 	 */
    427 	if (play->sample_rate != rec->sample_rate &&
    428 	    usemode == (AUMODE_PLAY | AUMODE_RECORD)) {
    429 		if (setmode == AUMODE_PLAY) {
    430 			rec->sample_rate = play->sample_rate;
    431 			setmode |= AUMODE_RECORD;
    432 		} else if (setmode == AUMODE_RECORD) {
    433 			play->sample_rate = rec->sample_rate;
    434 			setmode |= AUMODE_PLAY;
    435 		} else
    436 			return EINVAL;
    437 	}
    438 
    439 	for (mode = AUMODE_RECORD; mode != -1;
    440 	     mode = mode == AUMODE_RECORD ? AUMODE_PLAY : -1) {
    441 		if ((setmode & mode) == 0)
    442 			continue;
    443 
    444 		p = mode == AUMODE_PLAY ? play : rec;
    445 
    446 		if (p->sample_rate < 4000 || p->sample_rate > 50000 ||
    447 		    (p->precision != 8 && p->precision != 16) ||
    448 		    (p->channels != 1 && p->channels != 2))
    449 			return EINVAL;
    450 
    451 		p->factor = 1;
    452 		p->sw_code = 0;
    453 		awacs_write_reg(sc, AWACS_BYTE_SWAP, 0);
    454 
    455 		switch (p->encoding) {
    456 
    457 		case AUDIO_ENCODING_SLINEAR_LE:
    458 			awacs_write_reg(sc, AWACS_BYTE_SWAP, 1);
    459 		case AUDIO_ENCODING_SLINEAR_BE:
    460 			if (p->channels == 1) {
    461 				p->factor = 2;
    462 				p->sw_code = mono16_to_stereo16;
    463 				break;
    464 			}
    465 			if (p->precision != 16)
    466 				return EINVAL;
    467 				/* p->sw_code = change_sign8; */
    468 			break;
    469 
    470 		case AUDIO_ENCODING_ULINEAR_LE:
    471 			awacs_write_reg(sc, AWACS_BYTE_SWAP, 1);
    472 		case AUDIO_ENCODING_ULINEAR_BE:
    473 			if (p->precision == 16)
    474 				p->sw_code = change_sign16_be;
    475 			else
    476 				return EINVAL;
    477 			break;
    478 
    479 		case AUDIO_ENCODING_ULAW:
    480 			if (mode == AUMODE_PLAY) {
    481 				p->factor = 2;
    482 				p->sw_code = mulaw_to_slinear16_be;
    483 			} else
    484 				p->sw_code = ulinear8_to_mulaw;
    485 			break;
    486 
    487 		case AUDIO_ENCODING_ALAW:
    488 			if (mode == AUMODE_PLAY) {
    489 				p->factor = 2;
    490 				p->sw_code = alaw_to_slinear16_be;
    491 			} else
    492 				p->sw_code = ulinear8_to_alaw;
    493 			break;
    494 
    495 		default:
    496 			return EINVAL;
    497 		}
    498 	}
    499 
    500 	/* Set the speed */
    501 	rate = p->sample_rate;
    502 
    503 	awacs_set_rate(sc, rate);
    504 
    505 	return 0;
    506 }
    507 
    508 int
    509 awacs_round_blocksize(h, size)
    510 	void *h;
    511 	int size;
    512 {
    513 	return size & ~PGOFSET;
    514 }
    515 
    516 int
    517 awacs_halt_output(h)
    518 	void *h;
    519 {
    520 	struct awacs_softc *sc = h;
    521 
    522 	dbdma_stop(sc->sc_odma);
    523 	dbdma_reset(sc->sc_odma);
    524 	return 0;
    525 }
    526 
    527 int
    528 awacs_halt_input(h)
    529 	void *h;
    530 {
    531 	struct awacs_softc *sc = h;
    532 
    533 	dbdma_stop(sc->sc_idma);
    534 	dbdma_reset(sc->sc_idma);
    535 	return 0;
    536 }
    537 
    538 int
    539 awacs_getdev(h, retp)
    540 	void *h;
    541 	struct audio_device *retp;
    542 {
    543 	*retp = awacs_device;
    544 	return 0;
    545 }
    546 
    547 enum {
    548 	AWACS_OUTPUT_SELECT,
    549 	AWACS_VOL_SPEAKER,
    550 	AWACS_VOL_HEADPHONE,
    551 	AWACS_OUTPUT_CLASS,
    552 	AWACS_MONITOR_CLASS,
    553 	AWACS_ENUM_LAST
    554 };
    555 
    556 int
    557 awacs_set_port(h, mc)
    558 	void *h;
    559 	mixer_ctrl_t *mc;
    560 {
    561 	struct awacs_softc *sc = h;
    562 	int l, r;
    563 
    564 	DPRINTF("awacs_set_port dev = %d, type = %d\n", mc->dev, mc->type);
    565 
    566 	l = mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT];
    567 	r = mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT];
    568 
    569 	switch (mc->dev) {
    570 	case AWACS_OUTPUT_SELECT:
    571 		/* no change necessary? */
    572 		if (mc->un.mask == sc->sc_output_mask)
    573 			return 0;
    574 		switch(mc->un.mask) {
    575 		case 1<<0: /* speaker */
    576 			sc->sc_codecctl1 &= ~AWACS_MUTE_SPEAKER;
    577 			sc->sc_codecctl1 |= AWACS_MUTE_HEADPHONE;
    578 			awacs_write_codec(sc, sc->sc_codecctl1);
    579 			break;
    580 		case 1<<1: /* headphones */
    581 			sc->sc_codecctl1 |= AWACS_MUTE_SPEAKER;
    582 			sc->sc_codecctl1 &= ~AWACS_MUTE_HEADPHONE;
    583 			awacs_write_codec(sc, sc->sc_codecctl1);
    584 			break;
    585 		default: /* XXX */
    586 			return -1;
    587 		}
    588 		sc->sc_output_mask = mc->un.mask;
    589 		return 0;
    590 
    591 	case AWACS_VOL_SPEAKER:
    592 		awacs_set_speaker_volume(sc, l, r);
    593 		return 0;
    594 
    595 	case AWACS_VOL_HEADPHONE:
    596 		awacs_set_ext_volume(sc, l, r);
    597 		return 0;
    598 	}
    599 
    600 	return ENXIO;
    601 }
    602 
    603 int
    604 awacs_get_port(h, mc)
    605 	void *h;
    606 	mixer_ctrl_t *mc;
    607 {
    608 	struct awacs_softc *sc = h;
    609 	int vol, l, r;
    610 
    611 	DPRINTF("awacs_get_port dev = %d, type = %d\n", mc->dev, mc->type);
    612 
    613 	switch (mc->dev) {
    614 	case AWACS_OUTPUT_SELECT:
    615 		mc->un.mask = sc->sc_output_mask;
    616 		return 0;
    617 
    618 	case AWACS_VOL_SPEAKER:
    619 		vol = sc->sc_codecctl4;
    620 		l = (15 - ((vol & 0x3c0) >> 6)) * 16;
    621 		r = (15 - (vol & 0x0f)) * 16;
    622 		mc->un.mask = 1 << 0;
    623 		mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = l;
    624 		mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = r;
    625 		return 0;
    626 
    627 	case AWACS_VOL_HEADPHONE:
    628 		vol = sc->sc_codecctl2;
    629 		l = (15 - ((vol & 0x3c0) >> 6)) * 16;
    630 		r = (15 - (vol & 0x0f)) * 16;
    631 		mc->un.mask = 1 << 1;
    632 		mc->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = l;
    633 		mc->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = r;
    634 		return 0;
    635 
    636 	default:
    637 		return ENXIO;
    638 	}
    639 
    640 	return 0;
    641 }
    642 
    643 int
    644 awacs_query_devinfo(h, dip)
    645 	void *h;
    646 	mixer_devinfo_t *dip;
    647 {
    648 
    649 	DPRINTF("query_devinfo %d\n", dip->index);
    650 
    651 	switch (dip->index) {
    652 
    653 	case AWACS_OUTPUT_SELECT:
    654 		dip->mixer_class = AWACS_MONITOR_CLASS;
    655 		strcpy(dip->label.name, AudioNoutput);
    656 		dip->type = AUDIO_MIXER_SET;
    657 		dip->prev = dip->next = AUDIO_MIXER_LAST;
    658 		dip->un.s.num_mem = 2;
    659 		strcpy(dip->un.s.member[0].label.name, AudioNspeaker);
    660 		dip->un.s.member[0].mask = 1 << 0;
    661 		strcpy(dip->un.s.member[1].label.name, AudioNheadphone);
    662 		dip->un.s.member[1].mask = 1 << 1;
    663 		return 0;
    664 
    665 	case AWACS_VOL_SPEAKER:
    666 		dip->mixer_class = AWACS_OUTPUT_CLASS;
    667 		strcpy(dip->label.name, AudioNspeaker);
    668 		dip->type = AUDIO_MIXER_VALUE;
    669 		dip->prev = dip->next = AUDIO_MIXER_LAST;
    670 		dip->un.v.num_channels = 2;
    671 		strcpy(dip->un.v.units.name, AudioNvolume);
    672 		return 0;
    673 
    674 	case AWACS_VOL_HEADPHONE:
    675 		dip->mixer_class = AWACS_OUTPUT_CLASS;
    676 		strcpy(dip->label.name, AudioNheadphone);
    677 		dip->type = AUDIO_MIXER_VALUE;
    678 		dip->prev = dip->next = AUDIO_MIXER_LAST;
    679 		dip->un.v.num_channels = 2;
    680 		strcpy(dip->un.v.units.name, AudioNvolume);
    681 		return 0;
    682 
    683 	case AWACS_MONITOR_CLASS:
    684 		dip->mixer_class = AWACS_MONITOR_CLASS;
    685 		strcpy(dip->label.name, AudioCmonitor);
    686 		dip->type = AUDIO_MIXER_CLASS;
    687 		dip->next = dip->prev = AUDIO_MIXER_LAST;
    688 		return 0;
    689 
    690 	case AWACS_OUTPUT_CLASS:
    691 		dip->mixer_class = AWACS_OUTPUT_CLASS;
    692 		strcpy(dip->label.name, AudioCoutputs);
    693 		dip->type = AUDIO_MIXER_CLASS;
    694 		dip->next = dip->prev = AUDIO_MIXER_LAST;
    695 		return 0;
    696 	}
    697 
    698 	return ENXIO;
    699 }
    700 
    701 size_t
    702 awacs_round_buffersize(h, dir, size)
    703 	void *h;
    704 	int dir;
    705 	size_t size;
    706 {
    707 	if (size > 65536)
    708 		size = 65536;
    709 	return size;
    710 }
    711 
    712 paddr_t
    713 awacs_mappage(h, mem, off, prot)
    714 	void *h;
    715 	void *mem;
    716 	off_t off;
    717 	int prot;
    718 {
    719 	if (off < 0)
    720 		return -1;
    721 	return -1;	/* XXX */
    722 }
    723 
    724 int
    725 awacs_get_props(h)
    726 	void *h;
    727 {
    728 	return AUDIO_PROP_FULLDUPLEX /* | AUDIO_PROP_MMAP */;
    729 }
    730 
    731 int
    732 awacs_trigger_output(h, start, end, bsize, intr, arg, param)
    733 	void *h;
    734 	void *start, *end;
    735 	int bsize;
    736 	void (*intr)(void *);
    737 	void *arg;
    738 	struct audio_params *param;
    739 {
    740 	struct awacs_softc *sc = h;
    741 	struct dbdma_command *cmd = sc->sc_odmacmd;
    742 	vaddr_t va;
    743 	int i, len, intmode;
    744 
    745 	DPRINTF("trigger_output %p %p 0x%x\n", start, end, bsize);
    746 
    747 	sc->sc_ointr = intr;
    748 	sc->sc_oarg = arg;
    749 	sc->sc_opages = ((char *)end - (char *)start) / NBPG;
    750 
    751 #ifdef DIAGNOSTIC
    752 	if (sc->sc_opages > 16)
    753 		panic("awacs_trigger_output");
    754 #endif
    755 
    756 	va = (vaddr_t)start;
    757 	len = 0;
    758 	for (i = sc->sc_opages; i > 0; i--) {
    759 		len += NBPG;
    760 		if (len < bsize)
    761 			intmode = DBDMA_INT_NEVER;
    762 		else {
    763 			len = 0;
    764 			intmode = DBDMA_INT_ALWAYS;
    765 		}
    766 
    767 		DBDMA_BUILD(cmd, DBDMA_CMD_OUT_MORE, 0, NBPG, vtophys(va),
    768 			intmode, DBDMA_WAIT_NEVER, DBDMA_BRANCH_NEVER);
    769 		va += NBPG;
    770 		cmd++;
    771 	}
    772 
    773 	DBDMA_BUILD(cmd, DBDMA_CMD_NOP, 0, 0, 0,
    774 		DBDMA_INT_NEVER, DBDMA_WAIT_NEVER, DBDMA_BRANCH_ALWAYS);
    775 	dbdma_st32(&cmd->d_cmddep, vtophys((vaddr_t)sc->sc_odmacmd));
    776 
    777 	dbdma_start(sc->sc_odma, sc->sc_odmacmd);
    778 
    779 	return 0;
    780 }
    781 
    782 int
    783 awacs_trigger_input(h, start, end, bsize, intr, arg, param)
    784 	void *h;
    785 	void *start, *end;
    786 	int bsize;
    787 	void (*intr)(void *);
    788 	void *arg;
    789 	struct audio_params *param;
    790 {
    791 	printf("awacs_trigger_input called\n");
    792 
    793 	return 1;
    794 }
    795 
    796 void
    797 awacs_set_speaker_volume(sc, left, right)
    798 	struct awacs_softc *sc;
    799 	int left, right;
    800 {
    801 	int lval = 15 - (left  & 0xff) / 16;
    802 	int rval = 15 - (right & 0xff) / 16;
    803 
    804 	DPRINTF("speaker_volume %d %d\n", lval, rval);
    805 
    806 	sc->sc_codecctl4 &= ~0x3cf;
    807 	sc->sc_codecctl4 |= (lval << 6) | rval;
    808 	awacs_write_codec(sc, sc->sc_codecctl4);
    809 }
    810 
    811 void
    812 awacs_set_ext_volume(sc, left, right)
    813 	struct awacs_softc *sc;
    814 	int left, right;
    815 {
    816 	int lval = 15 - (left  & 0xff) / 16;
    817 	int rval = 15 - (right & 0xff) / 16;
    818 
    819 	DPRINTF("ext_volume %d %d\n", lval, rval);
    820 
    821 	sc->sc_codecctl2 &= ~0x3cf;
    822 	sc->sc_codecctl2 |= (lval << 6) | rval;
    823 	awacs_write_codec(sc, sc->sc_codecctl2);
    824 }
    825 
    826 int
    827 awacs_set_rate(sc, rate)
    828 	struct awacs_softc *sc;
    829 	int rate;
    830 {
    831 	int c;
    832 
    833 	switch (rate) {
    834 
    835 	case 44100:
    836 		c = AWACS_RATE_44100;
    837 		break;
    838 	case 29400:
    839 		c = AWACS_RATE_29400;
    840 		break;
    841 	case 22050:
    842 		c = AWACS_RATE_22050;
    843 		break;
    844 	case 17640:
    845 		c = AWACS_RATE_17640;
    846 		break;
    847 	case 14700:
    848 		c = AWACS_RATE_14700;
    849 		break;
    850 	case 11025:
    851 		c = AWACS_RATE_11025;
    852 		break;
    853 	case 8820:
    854 		c = AWACS_RATE_8820;
    855 		break;
    856 	case 7350:
    857 		c = AWACS_RATE_7350;
    858 		break;
    859 	default:
    860 		return -1;
    861 	}
    862 
    863 	sc->sc_soundctl &= ~AWACS_RATE_MASK;
    864 	sc->sc_soundctl |= c;
    865 	awacs_write_reg(sc, AWACS_SOUND_CTRL, sc->sc_soundctl);
    866 
    867 	return 0;
    868 }
    869