xref: /openbsd-src/sys/dev/pci/eso.c (revision 0b7734b3d77bb9b21afec6f4621cae6c805dbd45)
1 /*	$OpenBSD: eso.c,v 1.41 2016/01/14 00:07:32 jsg Exp $	*/
2 /*	$NetBSD: eso.c,v 1.48 2006/12/18 23:13:39 kleink Exp $	*/
3 
4 /*
5  * Copyright (c) 1999, 2000, 2004 Klaus J. Klein
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
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,
24  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29  * SUCH DAMAGE.
30  */
31 
32 /*
33  * ESS Technology Inc. Solo-1 PCI AudioDrive (ES1938/1946) device driver.
34  */
35 
36 #include <sys/param.h>
37 #include <sys/systm.h>
38 #include <sys/kernel.h>
39 #include <sys/malloc.h>
40 #include <sys/device.h>
41 
42 #include <dev/pci/pcidevs.h>
43 #include <dev/pci/pcivar.h>
44 
45 #include <sys/audioio.h>
46 #include <dev/audio_if.h>
47 #include <dev/midi_if.h>
48 
49 #include <dev/ic/mpuvar.h>
50 #include <dev/ic/i8237reg.h>
51 #include <dev/pci/esoreg.h>
52 #include <dev/pci/esovar.h>
53 
54 #include <machine/bus.h>
55 #include <machine/intr.h>
56 
57 /*
58  * XXX Work around the 24-bit implementation limit of the Audio 1 DMA
59  * XXX engine by allocating through the ISA DMA tag.
60  */
61 #if defined(__amd64__) || defined(__i386__)
62 #include "isa.h"
63 #if NISA > 0
64 #include <dev/isa/isavar.h>
65 #endif
66 #endif
67 
68 #if defined(AUDIO_DEBUG) || defined(DEBUG)
69 #define	DPRINTF(x)	if (esodebug) printf x
70 int	esodebug = 0;
71 #else
72 #define	DPRINTF(x)
73 #endif
74 
75 struct eso_dma {
76 	bus_dma_tag_t		ed_dmat;
77 	bus_dmamap_t		ed_map;
78 	caddr_t			ed_addr;
79 	bus_dma_segment_t	ed_segs[1];
80 	int			ed_nsegs;
81 	size_t			ed_size;
82 	struct eso_dma *	ed_next;
83 };
84 
85 #define KVADDR(dma)	((void *)(dma)->ed_addr)
86 #define DMAADDR(dma)	((dma)->ed_map->dm_segs[0].ds_addr)
87 
88 int eso_match(struct device *, void *, void *);
89 void eso_attach(struct device *, struct device *, void *);
90 int eso_activate(struct device *, int);
91 void eso_defer(struct device *);
92 
93 struct cfattach eso_ca = {
94 	sizeof (struct eso_softc), eso_match, eso_attach, NULL,
95 	eso_activate
96 };
97 
98 struct cfdriver eso_cd = {
99 	NULL, "eso", DV_DULL
100 };
101 
102 /* PCI interface */
103 int eso_intr(void *);
104 
105 /* MI audio layer interface */
106 int	eso_open(void *, int);
107 void	eso_close(void *);
108 int	eso_query_encoding(void *, struct audio_encoding *);
109 int	eso_set_params(void *, int, int, struct audio_params *,
110 		    struct audio_params *);
111 void	eso_get_default_params(void *, int, struct audio_params *);
112 int	eso_round_blocksize(void *, int);
113 int	eso_halt_output(void *);
114 int	eso_halt_input(void *);
115 int	eso_getdev(void *, struct audio_device *);
116 int	eso_set_port(void *, mixer_ctrl_t *);
117 int	eso_get_port(void *, mixer_ctrl_t *);
118 int	eso_query_devinfo(void *, mixer_devinfo_t *);
119 void *	eso_allocm(void *, int, size_t, int, int);
120 void	eso_freem(void *, void *, int);
121 size_t	eso_round_buffersize(void *, int, size_t);
122 paddr_t	eso_mappage(void *, void *, off_t, int);
123 int	eso_get_props(void *);
124 int	eso_trigger_output(void *, void *, void *, int,
125 		    void (*)(void *), void *, struct audio_params *);
126 int	eso_trigger_input(void *, void *, void *, int,
127 		    void (*)(void *), void *, struct audio_params *);
128 void	eso_setup(struct eso_softc *, int, int);
129 
130 struct audio_hw_if eso_hw_if = {
131 	eso_open,
132 	eso_close,
133 	NULL,			/* drain */
134 	eso_query_encoding,
135 	eso_set_params,
136 	eso_round_blocksize,
137 	NULL,			/* commit_settings */
138 	NULL,			/* init_output */
139 	NULL,			/* init_input */
140 	NULL,			/* start_output */
141 	NULL,			/* start_input */
142 	eso_halt_output,
143 	eso_halt_input,
144 	NULL,			/* speaker_ctl */
145 	eso_getdev,
146 	NULL,			/* setfd */
147 	eso_set_port,
148 	eso_get_port,
149 	eso_query_devinfo,
150 	eso_allocm,
151 	eso_freem,
152 	eso_round_buffersize,
153 	eso_mappage,
154 	eso_get_props,
155 	eso_trigger_output,
156 	eso_trigger_input,
157 	eso_get_default_params
158 };
159 
160 const char * const eso_rev2model[] = {
161 	"ES1938",
162 	"ES1946",
163 	"ES1946 rev E"
164 };
165 
166 
167 /*
168  * Utility routines
169  */
170 
171 /* Register access etc. */
172 uint8_t	eso_read_ctlreg(struct eso_softc *, uint8_t);
173 uint8_t	eso_read_mixreg(struct eso_softc *, uint8_t);
174 uint8_t	eso_read_rdr(struct eso_softc *);
175 void	eso_reload_master_vol(struct eso_softc *);
176 int	eso_reset(struct eso_softc *);
177 void	eso_set_gain(struct eso_softc *, uint);
178 int	eso_set_recsrc(struct eso_softc *, uint);
179 int	eso_set_monooutsrc(struct eso_softc *, uint);
180 int	eso_set_monoinbypass(struct eso_softc *, uint);
181 int	eso_set_preamp(struct eso_softc *, uint);
182 void	eso_write_cmd(struct eso_softc *, uint8_t);
183 void	eso_write_ctlreg(struct eso_softc *, uint8_t, uint8_t);
184 void	eso_write_mixreg(struct eso_softc *, uint8_t, uint8_t);
185 
186 /* DMA memory allocation */
187 int	eso_allocmem(struct eso_softc *, size_t, size_t, size_t,
188 		    int, int, struct eso_dma *);
189 void	eso_freemem(struct eso_dma *);
190 
191 
192 int
193 eso_match(struct device *parent, void *match, void *aux)
194 {
195 	struct pci_attach_args *pa = aux;
196 
197 	if (PCI_VENDOR(pa->pa_id) == PCI_VENDOR_ESSTECH &&
198 	    PCI_PRODUCT(pa->pa_id) == PCI_PRODUCT_ESSTECH_SOLO1)
199 		return (1);
200 
201 	return (0);
202 }
203 
204 void
205 eso_attach(struct device *parent, struct device *self, void *aux)
206 {
207 	struct eso_softc *sc = (struct eso_softc *)self;
208 	struct pci_attach_args *pa = aux;
209 	struct audio_attach_args aa;
210 	pci_intr_handle_t ih;
211 	bus_addr_t vcbase;
212 	const char *intrstring;
213 	uint8_t mvctl;
214 
215 	sc->sc_revision = PCI_REVISION(pa->pa_class);
216 
217 	if (sc->sc_revision <
218 	    sizeof (eso_rev2model) / sizeof (eso_rev2model[0]))
219 		printf(": %s", eso_rev2model[sc->sc_revision]);
220 	else
221 		printf(": (unknown rev. 0x%02x)", sc->sc_revision);
222 
223 	/* Map I/O registers. */
224 	if (pci_mapreg_map(pa, ESO_PCI_BAR_IO, PCI_MAPREG_TYPE_IO, 0,
225 	    &sc->sc_iot, &sc->sc_ioh, NULL, NULL, 0)) {
226 		printf(": can't map i/o space\n");
227 		return;
228 	}
229 	if (pci_mapreg_map(pa, ESO_PCI_BAR_SB, PCI_MAPREG_TYPE_IO, 0,
230 	    &sc->sc_sb_iot, &sc->sc_sb_ioh, NULL, NULL, 0)) {
231 		printf(": can't map SB I/O space\n");
232 		return;
233 	}
234 	if (pci_mapreg_map(pa, ESO_PCI_BAR_VC, PCI_MAPREG_TYPE_IO, 0,
235 	    &sc->sc_dmac_iot, &sc->sc_dmac_ioh, &vcbase, &sc->sc_vcsize, 0)) {
236 		vcbase = 0;
237 		sc->sc_vcsize = 0x10; /* From the data sheet. */
238 	}
239 	if (pci_mapreg_map(pa, ESO_PCI_BAR_MPU, PCI_MAPREG_TYPE_IO, 0,
240 	    &sc->sc_mpu_iot, &sc->sc_mpu_ioh, NULL, NULL, 0)) {
241 		printf(": can't map MPU I/O space\n");
242 		return;
243 	}
244 
245 	sc->sc_dmat = pa->pa_dmat;
246 	sc->sc_dmas = NULL;
247 	sc->sc_dmac_configured = 0;
248 
249 	sc->sc_pa = *pa;
250 
251 	eso_setup(sc, 1, 0);
252 
253 	/* map and establish the interrupt. */
254 	if (pci_intr_map(pa, &ih)) {
255 		printf(", couldn't map interrupt\n");
256 		return;
257 	}
258 	intrstring = pci_intr_string(pa->pa_pc, ih);
259 	sc->sc_ih  = pci_intr_establish(pa->pa_pc, ih, IPL_AUDIO | IPL_MPSAFE,
260 	    eso_intr, sc, sc->sc_dev.dv_xname);
261 	if (sc->sc_ih == NULL) {
262 		printf(", couldn't establish interrupt");
263 		if (intrstring != NULL)
264 			printf(" at %s", intrstring);
265 		printf("\n");
266 		return;
267 	}
268 	printf(", %s\n", intrstring);
269 
270 	/*
271 	 * Set up the DDMA Control register; a suitable I/O region has been
272 	 * supposedly mapped in the VC base address register.
273 	 *
274 	 * The Solo-1 has an ... interesting silicon bug that causes it to
275 	 * not respond to I/O space accesses to the Audio 1 DMA controller
276 	 * if the latter's mapping base address is aligned on a 1K boundary.
277 	 * As a consequence, it is quite possible for the mapping provided
278 	 * in the VC BAR to be useless.  To work around this, we defer this
279 	 * part until all autoconfiguration on our parent bus is completed
280 	 * and then try to map it ourselves in fulfillment of the constraint.
281 	 *
282 	 * According to the register map we may write to the low 16 bits
283 	 * only, but experimenting has shown we're safe.
284 	 * -kjk
285 	 */
286 
287 	if (ESO_VALID_DDMAC_BASE(vcbase)) {
288 		pci_conf_write(pa->pa_pc, pa->pa_tag, ESO_PCI_DDMAC,
289 			       vcbase | ESO_PCI_DDMAC_DE);
290 		sc->sc_dmac_configured = 1;
291 		sc->sc_dmac_addr = vcbase;
292 
293 		printf("%s: mapping Audio 1 DMA using VC I/O space at 0x%lx\n",
294 		       sc->sc_dev.dv_xname, (unsigned long)vcbase);
295 	} else {
296 		DPRINTF(("%s: VC I/O space at 0x%lx not suitable, deferring\n",
297 			 sc->sc_dev.dv_xname, (unsigned long)vcbase));
298 		config_defer((struct device *)sc, eso_defer);
299 	}
300 
301 	audio_attach_mi(&eso_hw_if, sc, &sc->sc_dev);
302 
303 	aa.type = AUDIODEV_TYPE_OPL;
304 	aa.hwif = NULL;
305 	aa.hdl = NULL;
306 	(void)config_found(&sc->sc_dev, &aa, audioprint);
307 
308 	aa.type = AUDIODEV_TYPE_MPU;
309 	aa.hwif = NULL;
310 	aa.hdl = NULL;
311 	sc->sc_mpudev = config_found(&sc->sc_dev, &aa, audioprint);
312 	if (sc->sc_mpudev != NULL) {
313 		/* Unmask the MPU irq. */
314 		mvctl = eso_read_mixreg(sc, ESO_MIXREG_MVCTL);
315 		mvctl |= ESO_MIXREG_MVCTL_MPUIRQM;
316 		eso_write_mixreg(sc, ESO_MIXREG_MVCTL, mvctl);
317 	}
318 }
319 
320 void
321 eso_setup(struct eso_softc *sc, int verbose, int resuming)
322 {
323 	struct pci_attach_args *pa = &sc->sc_pa;
324 	uint8_t a2mode, tmp;
325 	int idx;
326 
327 	/* Reset the device; bail out upon failure. */
328 	if (eso_reset(sc) != 0) {
329 		if (verbose) printf(", can't reset\n");
330 		return;
331 	}
332 
333 	/* Select the DMA/IRQ policy: DDMA, ISA IRQ emulation disabled. */
334 	pci_conf_write(pa->pa_pc, pa->pa_tag, ESO_PCI_S1C,
335 		       pci_conf_read(pa->pa_pc, pa->pa_tag, ESO_PCI_S1C) &
336 		       ~(ESO_PCI_S1C_IRQP_MASK | ESO_PCI_S1C_DMAP_MASK));
337 
338 	/* Enable the relevant DMA interrupts. */
339 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, ESO_IO_IRQCTL,
340 	    ESO_IO_IRQCTL_A1IRQ | ESO_IO_IRQCTL_A2IRQ | ESO_IO_IRQCTL_HVIRQ |
341 	    ESO_IO_IRQCTL_MPUIRQ);
342 
343 	/* Set up A1's sample rate generator for new-style parameters. */
344 	a2mode = eso_read_mixreg(sc, ESO_MIXREG_A2MODE);
345 	a2mode |= ESO_MIXREG_A2MODE_NEWA1 | ESO_MIXREG_A2MODE_ASYNC;
346 	eso_write_mixreg(sc, ESO_MIXREG_A2MODE, a2mode);
347 
348 	/* Slave Master Volume to Hardware Volume Control Counter, unmask IRQ. */
349 	tmp = eso_read_mixreg(sc, ESO_MIXREG_MVCTL);
350 	tmp &= ~ESO_MIXREG_MVCTL_SPLIT;
351 	tmp |= ESO_MIXREG_MVCTL_HVIRQM;
352 	eso_write_mixreg(sc, ESO_MIXREG_MVCTL, tmp);
353 
354 	if (!resuming) {
355 		/* Set mixer regs to something reasonable, needs work. */
356 		sc->sc_recmon = sc->sc_spatializer = sc->sc_mvmute = 0;
357 		eso_set_monooutsrc(sc, ESO_MIXREG_MPM_MOMUTE);
358 		eso_set_monoinbypass(sc, 0);
359 		eso_set_preamp(sc, 1);
360 		for (idx = 0; idx < ESO_NGAINDEVS; idx++) {
361 			int v;
362 
363 			switch (idx) {
364  			case ESO_MIC_PLAY_VOL:
365 			case ESO_LINE_PLAY_VOL:
366 			case ESO_CD_PLAY_VOL:
367 			case ESO_MONO_PLAY_VOL:
368 			case ESO_AUXB_PLAY_VOL:
369 			case ESO_DAC_REC_VOL:
370 			case ESO_LINE_REC_VOL:
371 			case ESO_SYNTH_REC_VOL:
372 			case ESO_CD_REC_VOL:
373 			case ESO_MONO_REC_VOL:
374 			case ESO_AUXB_REC_VOL:
375 			case ESO_SPATIALIZER:
376 				v = 0;
377 				break;
378 			case ESO_MASTER_VOL:
379 				v = ESO_GAIN_TO_6BIT(AUDIO_MAX_GAIN / 2);
380 				break;
381 			default:
382 				v = ESO_GAIN_TO_4BIT(AUDIO_MAX_GAIN / 2);
383 				break;
384 			}
385 			sc->sc_gain[idx][ESO_LEFT] =
386 			    sc->sc_gain[idx][ESO_RIGHT] = v;
387 			eso_set_gain(sc, idx);
388 		}
389 		eso_set_recsrc(sc, ESO_MIXREG_ERS_MIC);
390 	} else {
391 		eso_set_monooutsrc(sc, sc->sc_monooutsrc);
392 		eso_set_monoinbypass(sc, sc->sc_monoinbypass);
393 		eso_set_preamp(sc, sc->sc_preamp);
394 		eso_set_recsrc(sc, sc->sc_recsrc);
395 
396 		/* recmon */
397 		tmp = eso_read_ctlreg(sc, ESO_CTLREG_ACTL);
398 		if (sc->sc_recmon)
399 			tmp |= ESO_CTLREG_ACTL_RECMON;
400 		else
401 			tmp &= ~ESO_CTLREG_ACTL_RECMON;
402 		eso_write_ctlreg(sc, ESO_CTLREG_ACTL, tmp);
403 
404 		/* spatializer enable */
405 		tmp = eso_read_mixreg(sc, ESO_MIXREG_SPAT);
406 		if (sc->sc_spatializer)
407 			tmp |= ESO_MIXREG_SPAT_ENB;
408 		else
409 			tmp &= ~ESO_MIXREG_SPAT_ENB;
410 		eso_write_mixreg(sc, ESO_MIXREG_SPAT,
411 		    tmp | ESO_MIXREG_SPAT_RSTREL);
412 
413 		/* master volume mute */
414 		if (sc->sc_mvmute) {
415 			eso_write_mixreg(sc, ESO_MIXREG_LMVM,
416 			    eso_read_mixreg(sc, ESO_MIXREG_LMVM) |
417 			    ESO_MIXREG_LMVM_MUTE);
418 			eso_write_mixreg(sc, ESO_MIXREG_RMVM,
419 			    eso_read_mixreg(sc, ESO_MIXREG_RMVM) |
420 			    ESO_MIXREG_RMVM_MUTE);
421 		} else {
422 			eso_write_mixreg(sc, ESO_MIXREG_LMVM,
423 			    eso_read_mixreg(sc, ESO_MIXREG_LMVM) &
424 			    ~ESO_MIXREG_LMVM_MUTE);
425 			eso_write_mixreg(sc, ESO_MIXREG_RMVM,
426 			    eso_read_mixreg(sc, ESO_MIXREG_RMVM) &
427 			    ~ESO_MIXREG_RMVM_MUTE);
428 		}
429 
430 		for (idx = 0; idx < ESO_NGAINDEVS; idx++)
431 			eso_set_gain(sc, idx);
432 	}
433 }
434 
435 void
436 eso_defer(struct device *self)
437 {
438 	struct eso_softc *sc = (struct eso_softc *)self;
439 	struct pci_attach_args *pa = &sc->sc_pa;
440 	bus_addr_t addr, start;
441 
442 	printf("%s: ", sc->sc_dev.dv_xname);
443 
444 	/*
445 	 * This is outright ugly, but since we must not make assumptions
446 	 * on the underlying allocator's behaviour it's the most straight-
447 	 * forward way to implement it.  Note that we skip over the first
448 	 * 1K region, which is typically occupied by an attached ISA bus.
449 	 */
450 	for (start = 0x0400; start < 0xffff; start += 0x0400) {
451 		if (bus_space_alloc(sc->sc_iot,
452 		    start + sc->sc_vcsize, start + 0x0400 - 1,
453 		    sc->sc_vcsize, sc->sc_vcsize, 0, 0, &addr,
454 		    &sc->sc_dmac_ioh) != 0)
455 			continue;
456 
457 		pci_conf_write(pa->pa_pc, pa->pa_tag, ESO_PCI_DDMAC,
458 		    addr | ESO_PCI_DDMAC_DE);
459 		sc->sc_dmac_iot = sc->sc_iot;
460 		sc->sc_dmac_configured = 1;
461 		sc->sc_dmac_addr = addr;
462 		printf("mapping Audio 1 DMA using I/O space at 0x%lx\n",
463 		    (unsigned long)addr);
464 
465 		return;
466 	}
467 
468 	printf("can't map Audio 1 DMA into I/O space\n");
469 }
470 
471 void
472 eso_write_cmd(struct eso_softc *sc, uint8_t cmd)
473 {
474 	int i;
475 
476 	/* Poll for busy indicator to become clear. */
477 	for (i = 0; i < ESO_WDR_TIMEOUT; i++) {
478 		if ((bus_space_read_1(sc->sc_sb_iot, sc->sc_sb_ioh, ESO_SB_RSR)
479 		    & ESO_SB_RSR_BUSY) == 0) {
480 			bus_space_write_1(sc->sc_sb_iot, sc->sc_sb_ioh,
481 			    ESO_SB_WDR, cmd);
482 			return;
483 		} else {
484 			delay(10);
485 		}
486 	}
487 
488 	printf("%s: WDR timeout\n", sc->sc_dev.dv_xname);
489 }
490 
491 /* Write to a controller register */
492 void
493 eso_write_ctlreg(struct eso_softc *sc, uint8_t reg, uint8_t val)
494 {
495 
496 	/* DPRINTF(("ctlreg 0x%02x = 0x%02x\n", reg, val)); */
497 
498 	eso_write_cmd(sc, reg);
499 	eso_write_cmd(sc, val);
500 }
501 
502 /* Read out the Read Data Register */
503 uint8_t
504 eso_read_rdr(struct eso_softc *sc)
505 {
506 	int i;
507 
508 	for (i = 0; i < ESO_RDR_TIMEOUT; i++) {
509 		if (bus_space_read_1(sc->sc_sb_iot, sc->sc_sb_ioh,
510 		    ESO_SB_RBSR) & ESO_SB_RBSR_RDAV) {
511 			return (bus_space_read_1(sc->sc_sb_iot,
512 			    sc->sc_sb_ioh, ESO_SB_RDR));
513 		} else {
514 			delay(10);
515 		}
516 	}
517 
518 	printf("%s: RDR timeout\n", sc->sc_dev.dv_xname);
519 	return (-1);
520 }
521 
522 
523 uint8_t
524 eso_read_ctlreg(struct eso_softc *sc, uint8_t reg)
525 {
526 	eso_write_cmd(sc, ESO_CMD_RCR);
527 	eso_write_cmd(sc, reg);
528 	return (eso_read_rdr(sc));
529 }
530 
531 void
532 eso_write_mixreg(struct eso_softc *sc, uint8_t reg, uint8_t val)
533 {
534 	/* DPRINTF(("mixreg 0x%02x = 0x%02x\n", reg, val)); */
535 
536 	bus_space_write_1(sc->sc_sb_iot, sc->sc_sb_ioh, ESO_SB_MIXERADDR, reg);
537 	bus_space_write_1(sc->sc_sb_iot, sc->sc_sb_ioh, ESO_SB_MIXERDATA, val);
538 }
539 
540 uint8_t
541 eso_read_mixreg(struct eso_softc *sc, uint8_t reg)
542 {
543 	uint8_t val;
544 
545 	bus_space_write_1(sc->sc_sb_iot, sc->sc_sb_ioh, ESO_SB_MIXERADDR, reg);
546 	val = bus_space_read_1(sc->sc_sb_iot, sc->sc_sb_ioh, ESO_SB_MIXERDATA);
547 	return (val);
548 }
549 
550 int
551 eso_intr(void *hdl)
552 {
553 	struct eso_softc *sc = hdl;
554 	uint8_t irqctl;
555 
556 	mtx_enter(&audio_lock);
557 	irqctl = bus_space_read_1(sc->sc_iot, sc->sc_ioh, ESO_IO_IRQCTL);
558 
559 	/* If it wasn't ours, that's all she wrote. */
560 	if ((irqctl & (ESO_IO_IRQCTL_A1IRQ | ESO_IO_IRQCTL_A2IRQ |
561 	    ESO_IO_IRQCTL_HVIRQ | ESO_IO_IRQCTL_MPUIRQ)) == 0) {
562 		mtx_leave(&audio_lock);
563 		return (0);
564 	}
565 
566 	if (irqctl & ESO_IO_IRQCTL_A1IRQ) {
567 		/* Clear interrupt. */
568 		(void)bus_space_read_1(sc->sc_sb_iot, sc->sc_sb_ioh,
569 		    ESO_SB_RBSR);
570 
571 		if (sc->sc_rintr)
572 			sc->sc_rintr(sc->sc_rarg);
573 		else
574 			wakeup(&sc->sc_rintr);
575 	}
576 
577 	if (irqctl & ESO_IO_IRQCTL_A2IRQ) {
578 		/*
579 		 * Clear the A2 IRQ latch: the cached value reflects the
580 		 * current DAC settings with the IRQ latch bit not set.
581 		 */
582 		eso_write_mixreg(sc, ESO_MIXREG_A2C2, sc->sc_a2c2);
583 
584 		if (sc->sc_pintr)
585 			sc->sc_pintr(sc->sc_parg);
586 		else
587 			wakeup(&sc->sc_pintr);
588 	}
589 
590 	if (irqctl & ESO_IO_IRQCTL_HVIRQ) {
591 		/* Clear interrupt. */
592 		eso_write_mixreg(sc, ESO_MIXREG_CHVIR, ESO_MIXREG_CHVIR_CHVIR);
593 
594 		/*
595 		 * Raise a flag to cause a lazy update of the in-softc gain
596 		 * values the next time the software mixer is read to keep
597 		 * interrupt service cost low.  ~0 cannot occur otherwise
598 		 * as the master volume has a precision of 6 bits only.
599 		 */
600 		sc->sc_gain[ESO_MASTER_VOL][ESO_LEFT] = (uint8_t)~0;
601 	}
602 
603 #if NMPU > 0
604 	if ((irqctl & ESO_IO_IRQCTL_MPUIRQ) && sc->sc_mpudev != NULL)
605 		mpu_intr(sc->sc_mpudev);
606 #endif
607 
608 	mtx_leave(&audio_lock);
609 	return (1);
610 }
611 
612 /* Perform a software reset, including DMA FIFOs. */
613 int
614 eso_reset(struct eso_softc *sc)
615 {
616 	int i;
617 
618 	bus_space_write_1(sc->sc_sb_iot, sc->sc_sb_ioh, ESO_SB_RESET,
619 	    ESO_SB_RESET_SW | ESO_SB_RESET_FIFO);
620 	/* `Delay' suggested in the data sheet. */
621 	(void)bus_space_read_1(sc->sc_sb_iot, sc->sc_sb_ioh, ESO_SB_STATUS);
622 	bus_space_write_1(sc->sc_sb_iot, sc->sc_sb_ioh, ESO_SB_RESET, 0);
623 
624 	/* Wait for reset to take effect. */
625 	for (i = 0; i < ESO_RESET_TIMEOUT; i++) {
626 		/* Poll for data to become available. */
627 		if ((bus_space_read_1(sc->sc_sb_iot, sc->sc_sb_ioh,
628 		    ESO_SB_RBSR) & ESO_SB_RBSR_RDAV) != 0 &&
629 		    bus_space_read_1(sc->sc_sb_iot, sc->sc_sb_ioh,
630 			ESO_SB_RDR) == ESO_SB_RDR_RESETMAGIC) {
631 
632 			/* Activate Solo-1 extension commands. */
633 			eso_write_cmd(sc, ESO_CMD_EXTENB);
634 			/* Reset mixer registers. */
635 			eso_write_mixreg(sc, ESO_MIXREG_RESET,
636 			    ESO_MIXREG_RESET_RESET);
637 
638 			return (0);
639 		} else {
640 			delay(1000);
641 		}
642 	}
643 
644 	printf("%s: reset timeout\n", sc->sc_dev.dv_xname);
645 	return (-1);
646 }
647 
648 
649 /* ARGSUSED */
650 int
651 eso_open(void *hdl, int flags)
652 {
653 	return (0);
654 }
655 
656 void
657 eso_close(void *hdl)
658 {
659 }
660 
661 int
662 eso_query_encoding(void *hdl, struct audio_encoding *fp)
663 {
664 	switch (fp->index) {
665 	case 0:
666 		strlcpy(fp->name, AudioEulinear, sizeof fp->name);
667 		fp->encoding = AUDIO_ENCODING_ULINEAR;
668 		fp->precision = 8;
669 		fp->flags = 0;
670 		break;
671 	case 1:
672 		strlcpy(fp->name, AudioEslinear, sizeof fp->name);
673 		fp->encoding = AUDIO_ENCODING_SLINEAR;
674 		fp->precision = 8;
675 		fp->flags = 0;
676 		break;
677 	case 2:
678 		strlcpy(fp->name, AudioEslinear_le, sizeof fp->name);
679 		fp->encoding = AUDIO_ENCODING_SLINEAR_LE;
680 		fp->precision = 16;
681 		fp->flags = 0;
682 		break;
683 	case 3:
684 		strlcpy(fp->name, AudioEulinear_le, sizeof fp->name);
685 		fp->encoding = AUDIO_ENCODING_ULINEAR_LE;
686 		fp->precision = 16;
687 		fp->flags = 0;
688 		break;
689 	default:
690 		return (EINVAL);
691 	}
692 	fp->bps = AUDIO_BPS(fp->precision);
693 	fp->msb = 1;
694 
695 	return (0);
696 }
697 
698 void
699 eso_get_default_params(void *addr, int mode, struct audio_params *params)
700 {
701 	params->sample_rate = 48000;
702 	params->encoding = AUDIO_ENCODING_ULINEAR_LE;
703 	params->precision = 16;
704 	params->bps = 2;
705 	params->msb = 1;
706 	params->channels = 2;
707 }
708 
709 int
710 eso_set_params(void *hdl, int setmode, int usemode,
711     struct audio_params *play, struct audio_params *rec)
712 {
713 	struct eso_softc *sc = hdl;
714 	struct audio_params *p;
715 	int mode, r[2], rd[2], ar[2], clk;
716 	uint srg, fltdiv;
717 
718 	for (mode = AUMODE_RECORD; mode != -1;
719 	     mode = mode == AUMODE_RECORD ? AUMODE_PLAY : -1) {
720 		if ((setmode & mode) == 0)
721 			continue;
722 
723 		p = (mode == AUMODE_PLAY) ? play : rec;
724 
725 		if (p->sample_rate < ESO_MINRATE)
726 			p->sample_rate = ESO_MINRATE;
727 		if (p->sample_rate > ESO_MAXRATE)
728 			p->sample_rate = ESO_MAXRATE;
729 		if (p->precision > 16)
730 			p->precision = 16;
731 		if (p->channels > 2)
732 			p->channels = 2;
733 
734 		switch (p->encoding) {
735 		case AUDIO_ENCODING_SLINEAR_BE:
736 		case AUDIO_ENCODING_ULINEAR_BE:
737 			if (p->precision != 8)
738 				return EINVAL;
739 			break;
740 		case AUDIO_ENCODING_SLINEAR_LE:
741 		case AUDIO_ENCODING_ULINEAR_LE:
742 			break;
743 		default:
744 			return (EINVAL);
745 		}
746 		p->bps = AUDIO_BPS(p->precision);
747 		p->msb = 1;
748 
749 		/*
750 		 * We'll compute both possible sample rate dividers and pick
751 		 * the one with the least error.
752 		 */
753 #define ABS(x) ((x) < 0 ? -(x) : (x))
754 		r[0] = ESO_CLK0 /
755 		    (128 - (rd[0] = 128 - ESO_CLK0 / p->sample_rate));
756 		r[1] = ESO_CLK1 /
757 		    (128 - (rd[1] = 128 - ESO_CLK1 / p->sample_rate));
758 
759 		ar[0] = p->sample_rate - r[0];
760 		ar[1] = p->sample_rate - r[1];
761 		clk = ABS(ar[0]) > ABS(ar[1]) ? 1 : 0;
762 		srg = rd[clk] | (clk == 1 ? ESO_CLK1_SELECT : 0x00);
763 
764 		/* Roll-off frequency of 87%, as in the ES1888 driver. */
765 		fltdiv = 256 - 200279L / r[clk];
766 
767 		/* Update to reflect the possibly inexact rate. */
768 		p->sample_rate = r[clk];
769 
770 		if (mode == AUMODE_RECORD) {
771 			/* Audio 1 */
772 			DPRINTF(("A1 srg 0x%02x fdiv 0x%02x\n", srg, fltdiv));
773 			eso_write_ctlreg(sc, ESO_CTLREG_SRG, srg);
774 			eso_write_ctlreg(sc, ESO_CTLREG_FLTDIV, fltdiv);
775 		} else {
776 			/* Audio 2 */
777 			DPRINTF(("A2 srg 0x%02x fdiv 0x%02x\n", srg, fltdiv));
778 			eso_write_mixreg(sc, ESO_MIXREG_A2SRG, srg);
779 			eso_write_mixreg(sc, ESO_MIXREG_A2FLTDIV, fltdiv);
780 		}
781 #undef ABS
782 
783 	}
784 
785 	return (0);
786 }
787 
788 int
789 eso_round_blocksize(void *hdl, int blk)
790 {
791 	return ((blk + 31) & -32); /* keep good alignment; at least 16 req'd */
792 }
793 
794 int
795 eso_halt_output(void *hdl)
796 {
797 	struct eso_softc *sc = hdl;
798 	int error;
799 
800 	DPRINTF(("%s: halt_output\n", sc->sc_dev.dv_xname));
801 
802 	/*
803 	 * Disable auto-initialize DMA, allowing the FIFO to drain and then
804 	 * stop.  The interrupt callback pointer is cleared at this
805 	 * point so that an outstanding FIFO interrupt for the remaining data
806 	 * will be acknowledged without further processing.
807 	 *
808 	 * This does not immediately `abort' an operation in progress (c.f.
809 	 * audio(9)) but is the method to leave the FIFO behind in a clean
810 	 * state with the least hair.  (Besides, that item needs to be
811 	 * rephrased for trigger_*()-based DMA environments.)
812 	 */
813 	mtx_enter(&audio_lock);
814 	eso_write_mixreg(sc, ESO_MIXREG_A2C1,
815 	    ESO_MIXREG_A2C1_FIFOENB | ESO_MIXREG_A2C1_DMAENB);
816 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, ESO_IO_A2DMAM,
817 	    ESO_IO_A2DMAM_DMAENB);
818 
819 	sc->sc_pintr = NULL;
820 	error = msleep(&sc->sc_pintr, &audio_lock, PWAIT, "esoho", sc->sc_pdrain);
821 	mtx_leave(&audio_lock);
822 
823 	/* Shut down DMA completely. */
824 	eso_write_mixreg(sc, ESO_MIXREG_A2C1, 0);
825 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, ESO_IO_A2DMAM, 0);
826 
827 	return (error == EWOULDBLOCK ? 0 : error);
828 }
829 
830 int
831 eso_halt_input(void *hdl)
832 {
833 	struct eso_softc *sc = hdl;
834 	int error;
835 
836 	DPRINTF(("%s: halt_input\n", sc->sc_dev.dv_xname));
837 
838 	/* Just like eso_halt_output(), but for Audio 1. */
839 	mtx_enter(&audio_lock);
840 	eso_write_ctlreg(sc, ESO_CTLREG_A1C2,
841 	    ESO_CTLREG_A1C2_READ | ESO_CTLREG_A1C2_ADC |
842 	    ESO_CTLREG_A1C2_DMAENB);
843 	bus_space_write_1(sc->sc_dmac_iot, sc->sc_dmac_ioh, ESO_DMAC_MODE,
844 	    DMA37MD_WRITE | DMA37MD_DEMAND);
845 
846 	sc->sc_rintr = NULL;
847 	error = msleep(&sc->sc_rintr, &audio_lock, PWAIT, "esohi", sc->sc_rdrain);
848 	mtx_leave(&audio_lock);
849 
850 	/* Shut down DMA completely. */
851 	eso_write_ctlreg(sc, ESO_CTLREG_A1C2,
852 	    ESO_CTLREG_A1C2_READ | ESO_CTLREG_A1C2_ADC);
853 	bus_space_write_1(sc->sc_dmac_iot, sc->sc_dmac_ioh, ESO_DMAC_MASK,
854 	    ESO_DMAC_MASK_MASK);
855 
856 	return (error == EWOULDBLOCK ? 0 : error);
857 }
858 
859 int
860 eso_getdev(void *hdl, struct audio_device *retp)
861 {
862 	struct eso_softc *sc = hdl;
863 
864 	strlcpy(retp->name, "ESS Solo-1", sizeof retp->name);
865 	snprintf(retp->version, sizeof retp->version, "0x%02x",
866 	    sc->sc_revision);
867 	if (sc->sc_revision <
868 	    sizeof (eso_rev2model) / sizeof (eso_rev2model[0]))
869 		strlcpy(retp->config, eso_rev2model[sc->sc_revision],
870 		    sizeof retp->config);
871 	else
872 		strlcpy(retp->config, "unknown", sizeof retp->config);
873 
874 	return (0);
875 }
876 
877 int
878 eso_set_port(void *hdl, mixer_ctrl_t *cp)
879 {
880 	struct eso_softc *sc = hdl;
881 	uint lgain, rgain;
882 	uint8_t tmp;
883 	int rc = 0;
884 
885 	mtx_enter(&audio_lock);
886 	switch (cp->dev) {
887 	case ESO_DAC_PLAY_VOL:
888 	case ESO_MIC_PLAY_VOL:
889 	case ESO_LINE_PLAY_VOL:
890 	case ESO_SYNTH_PLAY_VOL:
891 	case ESO_CD_PLAY_VOL:
892 	case ESO_AUXB_PLAY_VOL:
893 	case ESO_RECORD_VOL:
894 	case ESO_DAC_REC_VOL:
895 	case ESO_MIC_REC_VOL:
896 	case ESO_LINE_REC_VOL:
897 	case ESO_SYNTH_REC_VOL:
898 	case ESO_CD_REC_VOL:
899 	case ESO_AUXB_REC_VOL:
900 		if (cp->type != AUDIO_MIXER_VALUE)
901 			goto error;
902 
903 		/*
904 		 * Stereo-capable mixer ports: if we get a single-channel
905 		 * gain value passed in, then we duplicate it to both left
906 		 * and right channels.
907 		 */
908 		switch (cp->un.value.num_channels) {
909 		case 1:
910 			lgain = rgain = ESO_GAIN_TO_4BIT(
911 			    cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]);
912 			break;
913 		case 2:
914 			lgain = ESO_GAIN_TO_4BIT(
915 			    cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT]);
916 			rgain = ESO_GAIN_TO_4BIT(
917 			    cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT]);
918 			break;
919 		default:
920 			goto error;
921 		}
922 
923 		sc->sc_gain[cp->dev][ESO_LEFT] = lgain;
924 		sc->sc_gain[cp->dev][ESO_RIGHT] = rgain;
925 		eso_set_gain(sc, cp->dev);
926 		break;
927 
928 	case ESO_MASTER_VOL:
929 		if (cp->type != AUDIO_MIXER_VALUE)
930 			goto error;
931 
932 		/* Like above, but a precision of 6 bits. */
933 		switch (cp->un.value.num_channels) {
934 		case 1:
935 			lgain = rgain = ESO_GAIN_TO_6BIT(
936 			    cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]);
937 			break;
938 		case 2:
939 			lgain = ESO_GAIN_TO_6BIT(
940 			    cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT]);
941 			rgain = ESO_GAIN_TO_6BIT(
942 			    cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT]);
943 			break;
944 		default:
945 			goto error;
946 		}
947 
948 		sc->sc_gain[cp->dev][ESO_LEFT] = lgain;
949 		sc->sc_gain[cp->dev][ESO_RIGHT] = rgain;
950 		eso_set_gain(sc, cp->dev);
951 		break;
952 
953 	case ESO_SPATIALIZER:
954 		if (cp->type != AUDIO_MIXER_VALUE ||
955 		    cp->un.value.num_channels != 1)
956 			goto error;
957 
958 		sc->sc_gain[cp->dev][ESO_LEFT] =
959 		    sc->sc_gain[cp->dev][ESO_RIGHT] =
960 		    ESO_GAIN_TO_6BIT(
961 			cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]);
962 		eso_set_gain(sc, cp->dev);
963 		break;
964 
965 	case ESO_MONO_PLAY_VOL:
966 	case ESO_MONO_REC_VOL:
967 		if (cp->type != AUDIO_MIXER_VALUE ||
968 		    cp->un.value.num_channels != 1)
969 			goto error;
970 
971 		sc->sc_gain[cp->dev][ESO_LEFT] =
972 		    sc->sc_gain[cp->dev][ESO_RIGHT] =
973 		    ESO_GAIN_TO_4BIT(
974 			cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]);
975 		eso_set_gain(sc, cp->dev);
976 		break;
977 
978 	case ESO_PCSPEAKER_VOL:
979 		if (cp->type != AUDIO_MIXER_VALUE ||
980 		    cp->un.value.num_channels != 1)
981 			goto error;
982 
983 		sc->sc_gain[cp->dev][ESO_LEFT] =
984 		    sc->sc_gain[cp->dev][ESO_RIGHT] =
985 		    ESO_GAIN_TO_3BIT(
986 			cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]);
987 		eso_set_gain(sc, cp->dev);
988 		break;
989 
990 	case ESO_SPATIALIZER_ENABLE:
991 		if (cp->type != AUDIO_MIXER_ENUM)
992 			goto error;
993 
994 		sc->sc_spatializer = (cp->un.ord != 0);
995 
996 		tmp = eso_read_mixreg(sc, ESO_MIXREG_SPAT);
997 		if (sc->sc_spatializer)
998 			tmp |= ESO_MIXREG_SPAT_ENB;
999 		else
1000 			tmp &= ~ESO_MIXREG_SPAT_ENB;
1001 		eso_write_mixreg(sc, ESO_MIXREG_SPAT,
1002 		    tmp | ESO_MIXREG_SPAT_RSTREL);
1003 		break;
1004 
1005 	case ESO_MASTER_MUTE:
1006 		if (cp->type != AUDIO_MIXER_ENUM)
1007 			goto error;
1008 
1009 		sc->sc_mvmute = (cp->un.ord != 0);
1010 
1011 		if (sc->sc_mvmute) {
1012 			eso_write_mixreg(sc, ESO_MIXREG_LMVM,
1013 			    eso_read_mixreg(sc, ESO_MIXREG_LMVM) |
1014 			    ESO_MIXREG_LMVM_MUTE);
1015 			eso_write_mixreg(sc, ESO_MIXREG_RMVM,
1016 			    eso_read_mixreg(sc, ESO_MIXREG_RMVM) |
1017 			    ESO_MIXREG_RMVM_MUTE);
1018 		} else {
1019 			eso_write_mixreg(sc, ESO_MIXREG_LMVM,
1020 			    eso_read_mixreg(sc, ESO_MIXREG_LMVM) &
1021 			    ~ESO_MIXREG_LMVM_MUTE);
1022 			eso_write_mixreg(sc, ESO_MIXREG_RMVM,
1023 			    eso_read_mixreg(sc, ESO_MIXREG_RMVM) &
1024 			    ~ESO_MIXREG_RMVM_MUTE);
1025 		}
1026 		break;
1027 
1028 	case ESO_MONOOUT_SOURCE:
1029 		if (cp->type != AUDIO_MIXER_ENUM)
1030 			goto error;
1031 
1032 		rc = eso_set_monooutsrc(sc, cp->un.ord);
1033 		break;
1034 
1035 	case ESO_MONOIN_BYPASS:
1036 		if (cp->type != AUDIO_MIXER_ENUM)
1037 			goto error;
1038 
1039 		rc = eso_set_monoinbypass(sc, cp->un.ord);
1040 		break;
1041 
1042 	case ESO_RECORD_MONITOR:
1043 		if (cp->type != AUDIO_MIXER_ENUM)
1044 			goto error;
1045 
1046 		sc->sc_recmon = (cp->un.ord != 0);
1047 
1048 		tmp = eso_read_ctlreg(sc, ESO_CTLREG_ACTL);
1049 		if (sc->sc_recmon)
1050 			tmp |= ESO_CTLREG_ACTL_RECMON;
1051 		else
1052 			tmp &= ~ESO_CTLREG_ACTL_RECMON;
1053 		eso_write_ctlreg(sc, ESO_CTLREG_ACTL, tmp);
1054 		break;
1055 
1056 	case ESO_RECORD_SOURCE:
1057 		if (cp->type != AUDIO_MIXER_ENUM)
1058 			goto error;
1059 
1060 		rc = eso_set_recsrc(sc, cp->un.ord);
1061 		break;
1062 
1063 	case ESO_MIC_PREAMP:
1064 		if (cp->type != AUDIO_MIXER_ENUM)
1065 			goto error;
1066 
1067 		rc = eso_set_preamp(sc, cp->un.ord);
1068 		break;
1069 
1070 	default:
1071 		goto error;
1072 	}
1073 
1074 	mtx_leave(&audio_lock);
1075 	return rc;
1076 error:
1077 	mtx_leave(&audio_lock);
1078 	return EINVAL;
1079 }
1080 
1081 int
1082 eso_get_port(void *hdl, mixer_ctrl_t *cp)
1083 {
1084 	struct eso_softc *sc = hdl;
1085 
1086 	mtx_enter(&audio_lock);
1087 	switch (cp->dev) {
1088 	case ESO_MASTER_VOL:
1089 		/* Reload from mixer after hardware volume control use. */
1090 		if (sc->sc_gain[cp->dev][ESO_LEFT] == (uint8_t)~0)
1091 			eso_reload_master_vol(sc);
1092 		/* FALLTHROUGH */
1093 	case ESO_DAC_PLAY_VOL:
1094 	case ESO_MIC_PLAY_VOL:
1095 	case ESO_LINE_PLAY_VOL:
1096 	case ESO_SYNTH_PLAY_VOL:
1097 	case ESO_CD_PLAY_VOL:
1098 	case ESO_AUXB_PLAY_VOL:
1099 	case ESO_RECORD_VOL:
1100 	case ESO_DAC_REC_VOL:
1101 	case ESO_MIC_REC_VOL:
1102 	case ESO_LINE_REC_VOL:
1103 	case ESO_SYNTH_REC_VOL:
1104 	case ESO_CD_REC_VOL:
1105 	case ESO_AUXB_REC_VOL:
1106 		/*
1107 		 * Stereo-capable ports: if a single-channel query is made,
1108 		 * just return the left channel's value (since single-channel
1109 		 * settings themselves are applied to both channels).
1110 		 */
1111 		switch (cp->un.value.num_channels) {
1112 		case 1:
1113 			cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] =
1114 			    sc->sc_gain[cp->dev][ESO_LEFT];
1115 			break;
1116 		case 2:
1117 			cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT] =
1118 			    sc->sc_gain[cp->dev][ESO_LEFT];
1119 			cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] =
1120 			    sc->sc_gain[cp->dev][ESO_RIGHT];
1121 			break;
1122 		default:
1123 			goto error;
1124 		}
1125 		break;
1126 
1127 	case ESO_MONO_PLAY_VOL:
1128 	case ESO_PCSPEAKER_VOL:
1129 	case ESO_MONO_REC_VOL:
1130 	case ESO_SPATIALIZER:
1131 		if (cp->un.value.num_channels != 1)
1132 			goto error;
1133 		cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] =
1134 		    sc->sc_gain[cp->dev][ESO_LEFT];
1135 		break;
1136 
1137 	case ESO_RECORD_MONITOR:
1138 		cp->un.ord = sc->sc_recmon;
1139 		break;
1140 
1141 	case ESO_RECORD_SOURCE:
1142 		cp->un.ord = sc->sc_recsrc;
1143 		break;
1144 
1145 	case ESO_MONOOUT_SOURCE:
1146 		cp->un.ord = sc->sc_monooutsrc;
1147 		break;
1148 
1149 	case ESO_MONOIN_BYPASS:
1150 		cp->un.ord = sc->sc_monoinbypass;
1151 		break;
1152 
1153 	case ESO_SPATIALIZER_ENABLE:
1154 		cp->un.ord = sc->sc_spatializer;
1155 		break;
1156 
1157 	case ESO_MIC_PREAMP:
1158 		cp->un.ord = sc->sc_preamp;
1159 		break;
1160 
1161 	case ESO_MASTER_MUTE:
1162 		/* Reload from mixer after hardware volume control use. */
1163 		if (sc->sc_gain[ESO_MASTER_VOL][ESO_LEFT] == (uint8_t)~0)
1164 			eso_reload_master_vol(sc);
1165 		cp->un.ord = sc->sc_mvmute;
1166 		break;
1167 
1168 	default:
1169 		goto error;
1170 	}
1171 
1172 	mtx_leave(&audio_lock);
1173 	return 0;
1174 error:
1175 	mtx_leave(&audio_lock);
1176 	return EINVAL;
1177 }
1178 
1179 int
1180 eso_query_devinfo(void *hdl, mixer_devinfo_t *dip)
1181 {
1182 	switch (dip->index) {
1183 	case ESO_DAC_PLAY_VOL:
1184 		dip->mixer_class = ESO_INPUT_CLASS;
1185 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1186 		strlcpy(dip->label.name, AudioNdac, sizeof dip->label.name);
1187 		dip->type = AUDIO_MIXER_VALUE;
1188 		dip->un.v.num_channels = 2;
1189 		strlcpy(dip->un.v.units.name, AudioNvolume,
1190 		    sizeof dip->un.v.units.name);
1191 		break;
1192 	case ESO_MIC_PLAY_VOL:
1193 		dip->mixer_class = ESO_INPUT_CLASS;
1194 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1195 		strlcpy(dip->label.name, AudioNmicrophone,
1196 		    sizeof dip->label.name);
1197 		dip->type = AUDIO_MIXER_VALUE;
1198 		dip->un.v.num_channels = 2;
1199 		strlcpy(dip->un.v.units.name, AudioNvolume,
1200 		    sizeof dip->un.v.units.name);
1201 		break;
1202 	case ESO_LINE_PLAY_VOL:
1203 		dip->mixer_class = ESO_INPUT_CLASS;
1204 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1205 		strlcpy(dip->label.name, AudioNline, sizeof dip->label.name);
1206 		dip->type = AUDIO_MIXER_VALUE;
1207 		dip->un.v.num_channels = 2;
1208 		strlcpy(dip->un.v.units.name, AudioNvolume,
1209 		    sizeof dip->un.v.units.name);
1210 		break;
1211 	case ESO_SYNTH_PLAY_VOL:
1212 		dip->mixer_class = ESO_INPUT_CLASS;
1213 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1214 		strlcpy(dip->label.name, AudioNfmsynth,
1215 		    sizeof dip->label.name);
1216 		dip->type = AUDIO_MIXER_VALUE;
1217 		dip->un.v.num_channels = 2;
1218 		strlcpy(dip->un.v.units.name, AudioNvolume,
1219 		    sizeof dip->un.v.units.name);
1220 		break;
1221 	case ESO_MONO_PLAY_VOL:
1222 		dip->mixer_class = ESO_INPUT_CLASS;
1223 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1224 		strlcpy(dip->label.name, "mono_in", sizeof dip->label.name);
1225 		dip->type = AUDIO_MIXER_VALUE;
1226 		dip->un.v.num_channels = 1;
1227 		strlcpy(dip->un.v.units.name, AudioNvolume,
1228 		    sizeof dip->un.v.units.name);
1229 		break;
1230 	case ESO_CD_PLAY_VOL:
1231 		dip->mixer_class = ESO_INPUT_CLASS;
1232 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1233 		strlcpy(dip->label.name, AudioNcd, sizeof dip->label.name);
1234 		dip->type = AUDIO_MIXER_VALUE;
1235 		dip->un.v.num_channels = 2;
1236 		strlcpy(dip->un.v.units.name, AudioNvolume,
1237 		    sizeof dip->un.v.units.name);
1238 		break;
1239 	case ESO_AUXB_PLAY_VOL:
1240 		dip->mixer_class = ESO_INPUT_CLASS;
1241 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1242 		strlcpy(dip->label.name, "auxb", sizeof dip->label.name);
1243 		dip->type = AUDIO_MIXER_VALUE;
1244 		dip->un.v.num_channels = 2;
1245 		strlcpy(dip->un.v.units.name, AudioNvolume,
1246 		    sizeof dip->un.v.units.name);
1247 		break;
1248 	case ESO_MIC_PREAMP:
1249 		dip->mixer_class = ESO_MICROPHONE_CLASS;
1250 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1251 		strlcpy(dip->label.name, AudioNpreamp, sizeof dip->label.name);
1252 		dip->type = AUDIO_MIXER_ENUM;
1253 		dip->un.e.num_mem = 2;
1254 		strlcpy(dip->un.e.member[0].label.name, AudioNoff,
1255 		    sizeof dip->un.e.member[0].label.name);
1256 		dip->un.e.member[0].ord = 0;
1257 		strlcpy(dip->un.e.member[1].label.name, AudioNon,
1258 		    sizeof dip->un.e.member[1].label.name);
1259 		dip->un.e.member[1].ord = 1;
1260 		break;
1261 	case ESO_MICROPHONE_CLASS:
1262 		dip->mixer_class = ESO_MICROPHONE_CLASS;
1263 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1264 		strlcpy(dip->label.name, AudioNmicrophone,
1265 		    sizeof dip->label.name);
1266 		dip->type = AUDIO_MIXER_CLASS;
1267 		break;
1268 	case ESO_INPUT_CLASS:
1269 		dip->mixer_class = ESO_INPUT_CLASS;
1270 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1271 		strlcpy(dip->label.name, AudioCinputs, sizeof dip->label.name);
1272 		dip->type = AUDIO_MIXER_CLASS;
1273 		break;
1274 	case ESO_MASTER_VOL:
1275 		dip->mixer_class = ESO_OUTPUT_CLASS;
1276 		dip->prev = AUDIO_MIXER_LAST;
1277 		dip->next = ESO_MASTER_MUTE;
1278 		strlcpy(dip->label.name, AudioNmaster, sizeof dip->label.name);
1279 		dip->type = AUDIO_MIXER_VALUE;
1280 		dip->un.v.num_channels = 2;
1281 		strlcpy(dip->un.v.units.name, AudioNvolume,
1282 		    sizeof dip->un.v.units.name);
1283 		break;
1284 	case ESO_MASTER_MUTE:
1285 		dip->mixer_class = ESO_OUTPUT_CLASS;
1286 		dip->prev = ESO_MASTER_VOL;
1287 		dip->next = AUDIO_MIXER_LAST;
1288 		strlcpy(dip->label.name, AudioNmute, sizeof dip->label.name);
1289 		dip->type = AUDIO_MIXER_ENUM;
1290 		dip->un.e.num_mem = 2;
1291 		strlcpy(dip->un.e.member[0].label.name, AudioNoff,
1292 		    sizeof dip->un.e.member[0].label.name);
1293 		dip->un.e.member[0].ord = 0;
1294 		strlcpy(dip->un.e.member[1].label.name, AudioNon,
1295 		    sizeof dip->un.e.member[1].label.name);
1296 		dip->un.e.member[1].ord = 1;
1297 		break;
1298 	case ESO_PCSPEAKER_VOL:
1299 		dip->mixer_class = ESO_OUTPUT_CLASS;
1300 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1301 		strlcpy(dip->label.name, "pc_speaker", sizeof dip->label.name);
1302 		dip->type = AUDIO_MIXER_VALUE;
1303 		dip->un.v.num_channels = 1;
1304 		strlcpy(dip->un.v.units.name, AudioNvolume,
1305 		    sizeof dip->un.v.units.name);
1306 		break;
1307 	case ESO_MONOOUT_SOURCE:
1308 		dip->mixer_class = ESO_OUTPUT_CLASS;
1309 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1310 		strlcpy(dip->label.name, "mono_out", sizeof dip->label.name);
1311 		dip->type = AUDIO_MIXER_ENUM;
1312 		dip->un.e.num_mem = 3;
1313 		strlcpy(dip->un.e.member[0].label.name, AudioNmute,
1314 		    sizeof dip->un.e.member[0].label.name);
1315 		dip->un.e.member[0].ord = ESO_MIXREG_MPM_MOMUTE;
1316 		strlcpy(dip->un.e.member[1].label.name, AudioNdac,
1317 		    sizeof dip->un.e.member[1].label.name);
1318 		dip->un.e.member[1].ord = ESO_MIXREG_MPM_MOA2R;
1319 		strlcpy(dip->un.e.member[2].label.name, AudioNmixerout,
1320 		    sizeof dip->un.e.member[2].label.name);
1321 		dip->un.e.member[2].ord = ESO_MIXREG_MPM_MOREC;
1322 		break;
1323 	case ESO_MONOIN_BYPASS:
1324 		dip->mixer_class = ESO_MONOIN_CLASS;
1325 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1326 		strlcpy(dip->label.name, "bypass", sizeof dip->label.name);
1327 		dip->type = AUDIO_MIXER_ENUM;
1328 		dip->un.e.num_mem = 2;
1329 		strlcpy(dip->un.e.member[0].label.name, AudioNoff,
1330 		    sizeof dip->un.e.member[0].label.name);
1331 		dip->un.e.member[0].ord = 0;
1332 		strlcpy(dip->un.e.member[1].label.name, AudioNon,
1333 		    sizeof dip->un.e.member[1].label.name);
1334 		dip->un.e.member[1].ord = 1;
1335 		break;
1336 	case ESO_MONOIN_CLASS:
1337 		dip->mixer_class = ESO_MONOIN_CLASS;
1338 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1339 		strlcpy(dip->label.name, "mono_in", sizeof dip->label.name);
1340 		dip->type = AUDIO_MIXER_CLASS;
1341 		break;
1342 	case ESO_SPATIALIZER:
1343 		dip->mixer_class = ESO_OUTPUT_CLASS;
1344 		dip->prev = AUDIO_MIXER_LAST;
1345 		dip->next = ESO_SPATIALIZER_ENABLE;
1346 		strlcpy(dip->label.name, AudioNspatial,
1347 		    sizeof dip->label.name);
1348 		dip->type = AUDIO_MIXER_VALUE;
1349 		dip->un.v.num_channels = 1;
1350 		strlcpy(dip->un.v.units.name, "level",
1351 		    sizeof dip->un.v.units.name);
1352 		break;
1353 	case ESO_SPATIALIZER_ENABLE:
1354 		dip->mixer_class = ESO_OUTPUT_CLASS;
1355 		dip->prev = ESO_SPATIALIZER;
1356 		dip->next = AUDIO_MIXER_LAST;
1357 		strlcpy(dip->label.name, "enable", sizeof dip->label.name);
1358 		dip->type = AUDIO_MIXER_ENUM;
1359 		dip->un.e.num_mem = 2;
1360 		strlcpy(dip->un.e.member[0].label.name, AudioNoff,
1361 		    sizeof dip->un.e.member[0].label.name);
1362 		dip->un.e.member[0].ord = 0;
1363 		strlcpy(dip->un.e.member[1].label.name, AudioNon,
1364 		    sizeof dip->un.e.member[1].label.name);
1365 		dip->un.e.member[1].ord = 1;
1366 		break;
1367 	case ESO_OUTPUT_CLASS:
1368 		dip->mixer_class = ESO_OUTPUT_CLASS;
1369 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1370 		strlcpy(dip->label.name, AudioCoutputs,
1371 		    sizeof dip->label.name);
1372 		dip->type = AUDIO_MIXER_CLASS;
1373 		break;
1374 	case ESO_RECORD_MONITOR:
1375 		dip->mixer_class = ESO_MONITOR_CLASS;
1376 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1377 		strlcpy(dip->label.name, AudioNmute, sizeof dip->label.name);
1378 		dip->type = AUDIO_MIXER_ENUM;
1379 		dip->un.e.num_mem = 2;
1380 		strlcpy(dip->un.e.member[0].label.name, AudioNoff,
1381 		    sizeof dip->un.e.member[0].label.name);
1382 		dip->un.e.member[0].ord = 0;
1383 		strlcpy(dip->un.e.member[1].label.name, AudioNon,
1384 		    sizeof dip->un.e.member[1].label.name);
1385 		dip->un.e.member[1].ord = 1;
1386 		break;
1387 	case ESO_MONITOR_CLASS:
1388 		dip->mixer_class = ESO_MONITOR_CLASS;
1389 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1390 		strlcpy(dip->label.name, AudioCmonitor,
1391 		    sizeof dip->label.name);
1392 		dip->type = AUDIO_MIXER_CLASS;
1393 		break;
1394 	case ESO_RECORD_VOL:
1395 		dip->mixer_class = ESO_RECORD_CLASS;
1396 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1397 		strlcpy(dip->label.name, AudioNrecord, sizeof dip->label.name);
1398 		dip->type = AUDIO_MIXER_VALUE;
1399 		strlcpy(dip->un.v.units.name, AudioNvolume,
1400 		    sizeof dip->un.v.units.name);
1401 		break;
1402 	case ESO_RECORD_SOURCE:
1403 		dip->mixer_class = ESO_RECORD_CLASS;
1404 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1405 		strlcpy(dip->label.name, AudioNsource, sizeof dip->label.name);
1406 		dip->type = AUDIO_MIXER_ENUM;
1407 		dip->un.e.num_mem = 4;
1408 		strlcpy(dip->un.e.member[0].label.name, AudioNmicrophone,
1409 		    sizeof dip->un.e.member[0].label.name);
1410 		dip->un.e.member[0].ord = ESO_MIXREG_ERS_MIC;
1411 		strlcpy(dip->un.e.member[1].label.name, AudioNline,
1412 		    sizeof dip->un.e.member[1].label.name);
1413 		dip->un.e.member[1].ord = ESO_MIXREG_ERS_LINE;
1414 		strlcpy(dip->un.e.member[2].label.name, AudioNcd,
1415 		    sizeof dip->un.e.member[2].label.name);
1416 		dip->un.e.member[2].ord = ESO_MIXREG_ERS_CD;
1417 		strlcpy(dip->un.e.member[3].label.name, AudioNmixerout,
1418 		    sizeof dip->un.e.member[3].label.name);
1419 		dip->un.e.member[3].ord = ESO_MIXREG_ERS_MIXER;
1420 		break;
1421 	case ESO_DAC_REC_VOL:
1422 		dip->mixer_class = ESO_RECORD_CLASS;
1423 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1424 		strlcpy(dip->label.name, AudioNdac, sizeof dip->label.name);
1425 		dip->type = AUDIO_MIXER_VALUE;
1426 		dip->un.v.num_channels = 2;
1427 		strlcpy(dip->un.v.units.name, AudioNvolume,
1428 		    sizeof dip->un.v.units.name);
1429 		break;
1430 	case ESO_MIC_REC_VOL:
1431 		dip->mixer_class = ESO_RECORD_CLASS;
1432 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1433 		strlcpy(dip->label.name, AudioNmicrophone,
1434 		    sizeof dip->label.name);
1435 		dip->type = AUDIO_MIXER_VALUE;
1436 		dip->un.v.num_channels = 2;
1437 		strlcpy(dip->un.v.units.name, AudioNvolume,
1438 		    sizeof dip->un.v.units.name);
1439 		break;
1440 	case ESO_LINE_REC_VOL:
1441 		dip->mixer_class = ESO_RECORD_CLASS;
1442 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1443 		strlcpy(dip->label.name, AudioNline, sizeof dip->label.name);
1444 		dip->type = AUDIO_MIXER_VALUE;
1445 		dip->un.v.num_channels = 2;
1446 		strlcpy(dip->un.v.units.name, AudioNvolume,
1447 		    sizeof dip->un.v.units.name);
1448 		break;
1449 	case ESO_SYNTH_REC_VOL:
1450 		dip->mixer_class = ESO_RECORD_CLASS;
1451 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1452 		strlcpy(dip->label.name, AudioNfmsynth,
1453 		    sizeof dip->label.name);
1454 		dip->type = AUDIO_MIXER_VALUE;
1455 		dip->un.v.num_channels = 2;
1456 		strlcpy(dip->un.v.units.name, AudioNvolume,
1457 		    sizeof dip->un.v.units.name);
1458 		break;
1459 	case ESO_MONO_REC_VOL:
1460 		dip->mixer_class = ESO_RECORD_CLASS;
1461 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1462 		strlcpy(dip->label.name, "mono_in", sizeof dip->label.name);
1463 		dip->type = AUDIO_MIXER_VALUE;
1464 		dip->un.v.num_channels = 1; /* No lies */
1465 		strlcpy(dip->un.v.units.name, AudioNvolume,
1466 		    sizeof dip->un.v.units.name);
1467 		break;
1468 	case ESO_CD_REC_VOL:
1469 		dip->mixer_class = ESO_RECORD_CLASS;
1470 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1471 		strlcpy(dip->label.name, AudioNcd, sizeof dip->label.name);
1472 		dip->type = AUDIO_MIXER_VALUE;
1473 		dip->un.v.num_channels = 2;
1474 		strlcpy(dip->un.v.units.name, AudioNvolume,
1475 		    sizeof dip->un.v.units.name);
1476 		break;
1477 	case ESO_AUXB_REC_VOL:
1478 		dip->mixer_class = ESO_RECORD_CLASS;
1479 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1480 		strlcpy(dip->label.name, "auxb", sizeof dip->label.name);
1481 		dip->type = AUDIO_MIXER_VALUE;
1482 		dip->un.v.num_channels = 2;
1483 		strlcpy(dip->un.v.units.name, AudioNvolume,
1484 		    sizeof dip->un.v.units.name);
1485 		break;
1486 	case ESO_RECORD_CLASS:
1487 		dip->mixer_class = ESO_RECORD_CLASS;
1488 		dip->next = dip->prev = AUDIO_MIXER_LAST;
1489 		strlcpy(dip->label.name, AudioCrecord, sizeof dip->label.name);
1490 		dip->type = AUDIO_MIXER_CLASS;
1491 		break;
1492 	default:
1493 		return (ENXIO);
1494 	}
1495 
1496 	return (0);
1497 }
1498 
1499 int
1500 eso_allocmem(struct eso_softc *sc, size_t size, size_t align,
1501     size_t boundary, int flags, int direction, struct eso_dma *ed)
1502 {
1503 	int error, wait;
1504 
1505 	wait = (flags & M_NOWAIT) ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK;
1506 	ed->ed_size = size;
1507 
1508 	error = bus_dmamem_alloc(ed->ed_dmat, ed->ed_size, align, boundary,
1509 	    ed->ed_segs, sizeof (ed->ed_segs) / sizeof (ed->ed_segs[0]),
1510 	    &ed->ed_nsegs, wait);
1511 	if (error)
1512 		goto out;
1513 
1514 	error = bus_dmamem_map(ed->ed_dmat, ed->ed_segs, ed->ed_nsegs,
1515 	    ed->ed_size, &ed->ed_addr, wait | BUS_DMA_COHERENT);
1516 	if (error)
1517 		goto free;
1518 
1519 	error = bus_dmamap_create(ed->ed_dmat, ed->ed_size, 1, ed->ed_size,
1520 	    boundary,  wait, &ed->ed_map);
1521 	if (error)
1522 		goto unmap;
1523 
1524 	error = bus_dmamap_load(ed->ed_dmat, ed->ed_map, ed->ed_addr,
1525 	    ed->ed_size, NULL, wait |
1526 	    ((direction == AUMODE_RECORD) ? BUS_DMA_READ : BUS_DMA_WRITE));
1527 	if (error)
1528 		goto destroy;
1529 
1530 	return (0);
1531 
1532  destroy:
1533 	bus_dmamap_destroy(ed->ed_dmat, ed->ed_map);
1534  unmap:
1535 	bus_dmamem_unmap(ed->ed_dmat, ed->ed_addr, ed->ed_size);
1536  free:
1537 	bus_dmamem_free(ed->ed_dmat, ed->ed_segs, ed->ed_nsegs);
1538  out:
1539 	return (error);
1540 }
1541 
1542 void
1543 eso_freemem(struct eso_dma *ed)
1544 {
1545 	bus_dmamap_unload(ed->ed_dmat, ed->ed_map);
1546 	bus_dmamap_destroy(ed->ed_dmat, ed->ed_map);
1547 	bus_dmamem_unmap(ed->ed_dmat, ed->ed_addr, ed->ed_size);
1548 	bus_dmamem_free(ed->ed_dmat, ed->ed_segs, ed->ed_nsegs);
1549 }
1550 
1551 void *
1552 eso_allocm(void *hdl, int direction, size_t size, int type, int flags)
1553 {
1554 	struct eso_softc *sc = hdl;
1555 	struct eso_dma *ed;
1556 	size_t boundary;
1557 	int error;
1558 
1559 	if ((ed = malloc(sizeof (*ed), type, flags)) == NULL)
1560 		return (NULL);
1561 
1562 	/*
1563 	 * Apparently the Audio 1 DMA controller's current address
1564 	 * register can't roll over a 64K address boundary, so we have to
1565 	 * take care of that ourselves.  Similarly, the Audio 2 DMA
1566 	 * controller needs a 1M address boundary.
1567 	 */
1568 	if (direction == AUMODE_RECORD)
1569 		boundary = 0x10000;
1570 	else
1571 		boundary = 0x100000;
1572 
1573 	/*
1574 	 * XXX Work around allocation problems for Audio 1, which
1575 	 * XXX implements the 24 low address bits only, with
1576 	 * XXX machine-specific DMA tag use.
1577 	 */
1578 #if defined(__alpha__)
1579 	/*
1580 	 * XXX Force allocation through the (ISA) SGMAP.
1581 	 */
1582 	if (direction == AUMODE_RECORD)
1583 		ed->ed_dmat = alphabus_dma_get_tag(sc->sc_dmat, ALPHA_BUS_ISA);
1584 	else
1585 #elif defined(__amd64__) || defined(__i386__)
1586 	/*
1587 	 * XXX Force allocation through the ISA DMA tag.
1588 	 */
1589 	if (direction == AUMODE_RECORD)
1590 		ed->ed_dmat = &isa_bus_dma_tag;
1591 	else
1592 #endif
1593 		ed->ed_dmat = sc->sc_dmat;
1594 
1595 	error = eso_allocmem(sc, size, 32, boundary, flags, direction, ed);
1596 	if (error) {
1597 		free(ed, type, 0);
1598 		return (NULL);
1599 	}
1600 	ed->ed_next = sc->sc_dmas;
1601 	sc->sc_dmas = ed;
1602 
1603 	return (KVADDR(ed));
1604 }
1605 
1606 void
1607 eso_freem(void *hdl, void *addr, int type)
1608 {
1609 	struct eso_softc *sc = hdl;
1610 	struct eso_dma *p, **pp;
1611 
1612 	for (pp = &sc->sc_dmas; (p = *pp) != NULL; pp = &p->ed_next) {
1613 		if (KVADDR(p) == addr) {
1614 			eso_freemem(p);
1615 			*pp = p->ed_next;
1616 			free(p, type, 0);
1617 			return;
1618 		}
1619 	}
1620 }
1621 
1622 size_t
1623 eso_round_buffersize(void *hdl, int direction, size_t bufsize)
1624 {
1625 	size_t maxsize;
1626 
1627 	/*
1628 	 * The playback DMA buffer size on the Solo-1 is limited to 0xfff0
1629 	 * bytes.  This is because IO_A2DMAC is a two byte value
1630 	 * indicating the literal byte count, and the 4 least significant
1631 	 * bits are read-only.  Zero is not used as a special case for
1632 	 * 0x10000.
1633 	 *
1634 	 * For recording, DMAC_DMAC is the byte count - 1, so 0x10000 can
1635 	 * be represented.
1636 	 */
1637 	maxsize = (direction == AUMODE_PLAY) ? 0xfff0 : 0x10000;
1638 
1639 	if (bufsize > maxsize)
1640 		bufsize = maxsize;
1641 
1642 	return (bufsize);
1643 }
1644 
1645 paddr_t
1646 eso_mappage(void *hdl, void *addr, off_t offs, int prot)
1647 {
1648 	struct eso_softc *sc = hdl;
1649 	struct eso_dma *ed;
1650 
1651 	if (offs < 0)
1652 		return (-1);
1653 	for (ed = sc->sc_dmas; ed != NULL && KVADDR(ed) != addr;
1654 	     ed = ed->ed_next)
1655 		;
1656 	if (ed == NULL)
1657 		return (-1);
1658 
1659 	return (bus_dmamem_mmap(ed->ed_dmat, ed->ed_segs, ed->ed_nsegs,
1660 	    offs, prot, BUS_DMA_WAITOK));
1661 }
1662 
1663 /* ARGSUSED */
1664 int
1665 eso_get_props(void *hdl)
1666 {
1667 	return (AUDIO_PROP_MMAP | AUDIO_PROP_INDEPENDENT |
1668 	    AUDIO_PROP_FULLDUPLEX);
1669 }
1670 
1671 int
1672 eso_trigger_output(void *hdl, void *start, void *end, int blksize,
1673     void (*intr)(void *), void *arg, struct audio_params *param)
1674 {
1675 	struct eso_softc *sc = hdl;
1676 	struct eso_dma *ed;
1677 	uint8_t a2c1;
1678 
1679 	DPRINTF((
1680 	    "%s: trigger_output: start %p, end %p, blksize %d, intr %p(%p)\n",
1681 	    sc->sc_dev.dv_xname, start, end, blksize, intr, arg));
1682 	DPRINTF(("%s: param: rate %lu, encoding %u, precision %u, channels %u\n",
1683 	    sc->sc_dev.dv_xname, param->sample_rate, param->encoding,
1684 	    param->precision, param->channels));
1685 
1686 	/* Find DMA buffer. */
1687 	for (ed = sc->sc_dmas; ed != NULL && KVADDR(ed) != start;
1688 	     ed = ed->ed_next)
1689 		;
1690 	if (ed == NULL) {
1691 		printf("%s: trigger_output: bad addr %p\n",
1692 		    sc->sc_dev.dv_xname, start);
1693 		return (EINVAL);
1694 	}
1695 	DPRINTF(("%s: output dmaaddr %lx\n",
1696 	    sc->sc_dev.dv_xname, (unsigned long)DMAADDR(ed)));
1697 
1698 	sc->sc_pintr = intr;
1699 	sc->sc_parg = arg;
1700 
1701 	/* Compute drain timeout. */
1702 	sc->sc_pdrain = hz * (blksize * 3 / 2) /
1703 	    (param->sample_rate * param->channels * param->bps);
1704 
1705 	/* DMA transfer count (in `words'!) reload using 2's complement. */
1706 	blksize = -(blksize >> 1);
1707 	eso_write_mixreg(sc, ESO_MIXREG_A2TCRLO, blksize & 0xff);
1708 	eso_write_mixreg(sc, ESO_MIXREG_A2TCRHI, blksize >> 8);
1709 
1710 	/* Update DAC to reflect DMA count and audio parameters. */
1711 	/* Note: we cache A2C2 in order to avoid r/m/w at interrupt time. */
1712 	if (param->precision == 16)
1713 		sc->sc_a2c2 |= ESO_MIXREG_A2C2_16BIT;
1714 	else
1715 		sc->sc_a2c2 &= ~ESO_MIXREG_A2C2_16BIT;
1716 	if (param->channels == 2)
1717 		sc->sc_a2c2 |= ESO_MIXREG_A2C2_STEREO;
1718 	else
1719 		sc->sc_a2c2 &= ~ESO_MIXREG_A2C2_STEREO;
1720 	if (param->encoding == AUDIO_ENCODING_SLINEAR_BE ||
1721 	    param->encoding == AUDIO_ENCODING_SLINEAR_LE)
1722 		sc->sc_a2c2 |= ESO_MIXREG_A2C2_SIGNED;
1723 	else
1724 		sc->sc_a2c2 &= ~ESO_MIXREG_A2C2_SIGNED;
1725 	/* Unmask IRQ. */
1726 	sc->sc_a2c2 |= ESO_MIXREG_A2C2_IRQM;
1727 	eso_write_mixreg(sc, ESO_MIXREG_A2C2, sc->sc_a2c2);
1728 
1729 	/* Set up DMA controller. */
1730 	bus_space_write_4(sc->sc_iot, sc->sc_ioh, ESO_IO_A2DMAA, DMAADDR(ed));
1731 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, ESO_IO_A2DMAC,
1732 	    (uint8_t *)end - (uint8_t *)start);
1733 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, ESO_IO_A2DMAM,
1734 	    ESO_IO_A2DMAM_DMAENB | ESO_IO_A2DMAM_AUTO);
1735 
1736 	/* Start DMA. */
1737 	mtx_enter(&audio_lock);
1738 	a2c1 = eso_read_mixreg(sc, ESO_MIXREG_A2C1);
1739 	a2c1 &= ~ESO_MIXREG_A2C1_RESV0; /* Paranoia? XXX bit 5 */
1740 	a2c1 |= ESO_MIXREG_A2C1_FIFOENB | ESO_MIXREG_A2C1_DMAENB |
1741 	    ESO_MIXREG_A2C1_AUTO;
1742 	eso_write_mixreg(sc, ESO_MIXREG_A2C1, a2c1);
1743 	mtx_leave(&audio_lock);
1744 	return (0);
1745 }
1746 
1747 int
1748 eso_trigger_input(void *hdl, void *start, void *end, int blksize,
1749     void (*intr)(void *), void *arg, struct audio_params *param)
1750 {
1751 	struct eso_softc *sc = hdl;
1752 	struct eso_dma *ed;
1753 	uint8_t actl, a1c1;
1754 
1755 	DPRINTF((
1756 	    "%s: trigger_input: start %p, end %p, blksize %d, intr %p(%p)\n",
1757 	    sc->sc_dev.dv_xname, start, end, blksize, intr, arg));
1758 	DPRINTF(("%s: param: rate %lu, encoding %u, precision %u, channels %u\n",
1759 	    sc->sc_dev.dv_xname, param->sample_rate, param->encoding,
1760 	    param->precision, param->channels));
1761 
1762 	/*
1763 	 * If we failed to configure the Audio 1 DMA controller, bail here
1764 	 * while retaining availability of the DAC direction (in Audio 2).
1765 	 */
1766 	if (!sc->sc_dmac_configured)
1767 		return (EIO);
1768 
1769 	/* Find DMA buffer. */
1770 	for (ed = sc->sc_dmas; ed != NULL && KVADDR(ed) != start;
1771 	     ed = ed->ed_next)
1772 		;
1773 	if (ed == NULL) {
1774 		printf("%s: trigger_input: bad addr %p\n",
1775 		    sc->sc_dev.dv_xname, start);
1776 		return (EINVAL);
1777 	}
1778 	DPRINTF(("%s: input dmaaddr %lx\n",
1779 	    sc->sc_dev.dv_xname, (unsigned long)DMAADDR(ed)));
1780 
1781 	sc->sc_rintr = intr;
1782 	sc->sc_rarg = arg;
1783 
1784 	/* Compute drain timeout. */
1785 	sc->sc_rdrain = hz * (blksize * 3 / 2) /
1786 	    (param->sample_rate * param->channels * param->bps);
1787 
1788 	/* Set up ADC DMA converter parameters. */
1789 	actl = eso_read_ctlreg(sc, ESO_CTLREG_ACTL);
1790 	if (param->channels == 2) {
1791 		actl &= ~ESO_CTLREG_ACTL_MONO;
1792 		actl |= ESO_CTLREG_ACTL_STEREO;
1793 	} else {
1794 		actl &= ~ESO_CTLREG_ACTL_STEREO;
1795 		actl |= ESO_CTLREG_ACTL_MONO;
1796 	}
1797 	eso_write_ctlreg(sc, ESO_CTLREG_ACTL, actl);
1798 
1799 	/* Set up Transfer Type: maybe move to attach time? */
1800 	eso_write_ctlreg(sc, ESO_CTLREG_A1TT, ESO_CTLREG_A1TT_DEMAND4);
1801 
1802 	/* DMA transfer count reload using 2's complement. */
1803 	blksize = -blksize;
1804 	eso_write_ctlreg(sc, ESO_CTLREG_A1TCRLO, blksize & 0xff);
1805 	eso_write_ctlreg(sc, ESO_CTLREG_A1TCRHI, blksize >> 8);
1806 
1807 	/* Set up and enable Audio 1 DMA FIFO. */
1808 	a1c1 = ESO_CTLREG_A1C1_RESV1 | ESO_CTLREG_A1C1_FIFOENB;
1809 	if (param->precision == 16)
1810 		a1c1 |= ESO_CTLREG_A1C1_16BIT;
1811 	if (param->channels == 2)
1812 		a1c1 |= ESO_CTLREG_A1C1_STEREO;
1813 	else
1814 		a1c1 |= ESO_CTLREG_A1C1_MONO;
1815 	if (param->encoding == AUDIO_ENCODING_SLINEAR_BE ||
1816 	    param->encoding == AUDIO_ENCODING_SLINEAR_LE)
1817 		a1c1 |= ESO_CTLREG_A1C1_SIGNED;
1818 	eso_write_ctlreg(sc, ESO_CTLREG_A1C1, a1c1);
1819 
1820 	/* Set up ADC IRQ/DRQ parameters. */
1821 	eso_write_ctlreg(sc, ESO_CTLREG_LAIC,
1822 	    ESO_CTLREG_LAIC_PINENB | ESO_CTLREG_LAIC_EXTENB);
1823 	eso_write_ctlreg(sc, ESO_CTLREG_DRQCTL,
1824 	    ESO_CTLREG_DRQCTL_ENB1 | ESO_CTLREG_DRQCTL_EXTENB);
1825 
1826 	/* Set up and enable DMA controller. */
1827 	bus_space_write_1(sc->sc_dmac_iot, sc->sc_dmac_ioh, ESO_DMAC_CLEAR, 0);
1828 	bus_space_write_1(sc->sc_dmac_iot, sc->sc_dmac_ioh, ESO_DMAC_MASK,
1829 	    ESO_DMAC_MASK_MASK);
1830 	bus_space_write_1(sc->sc_dmac_iot, sc->sc_dmac_ioh, ESO_DMAC_MODE,
1831 	    DMA37MD_WRITE | DMA37MD_LOOP | DMA37MD_DEMAND);
1832 	bus_space_write_4(sc->sc_dmac_iot, sc->sc_dmac_ioh, ESO_DMAC_DMAA,
1833 	    DMAADDR(ed));
1834 	bus_space_write_2(sc->sc_dmac_iot, sc->sc_dmac_ioh, ESO_DMAC_DMAC,
1835 	    (uint8_t *)end - (uint8_t *)start - 1);
1836 	bus_space_write_1(sc->sc_dmac_iot, sc->sc_dmac_ioh, ESO_DMAC_MASK, 0);
1837 
1838 	/* Start DMA. */
1839 	mtx_enter(&audio_lock);
1840 	eso_write_ctlreg(sc, ESO_CTLREG_A1C2,
1841 	    ESO_CTLREG_A1C2_DMAENB | ESO_CTLREG_A1C2_READ |
1842 	    ESO_CTLREG_A1C2_AUTO | ESO_CTLREG_A1C2_ADC);
1843 	mtx_leave(&audio_lock);
1844 	return (0);
1845 }
1846 
1847 /*
1848  * Mixer utility functions.
1849  */
1850 int
1851 eso_set_recsrc(struct eso_softc *sc, u_int recsrc)
1852 {
1853 	mixer_devinfo_t di;
1854 	int i, error;
1855 
1856 	di.index = ESO_RECORD_SOURCE;
1857 	error = eso_query_devinfo(sc, &di);
1858 	if (error != 0) {
1859 		printf("eso_set_recsrc: eso_query_devinfo failed");
1860 		return (error);
1861 	}
1862 
1863 	for (i = 0; i < di.un.e.num_mem; i++) {
1864 		if (recsrc == di.un.e.member[i].ord) {
1865 			eso_write_mixreg(sc, ESO_MIXREG_ERS, recsrc);
1866 			sc->sc_recsrc = recsrc;
1867 			return (0);
1868 		}
1869 	}
1870 
1871 	return (EINVAL);
1872 }
1873 
1874 int
1875 eso_set_monooutsrc(struct eso_softc *sc, uint monooutsrc)
1876 {
1877 	mixer_devinfo_t di;
1878 	int i, error;
1879 	uint8_t mpm;
1880 
1881 	di.index = ESO_MONOOUT_SOURCE;
1882 	error = eso_query_devinfo(sc, &di);
1883 	if (error != 0) {
1884 		printf("eso_set_monooutsrc: eso_query_devinfo failed");
1885 		return (error);
1886 	}
1887 
1888 	for (i = 0; i < di.un.e.num_mem; i++) {
1889 		if (monooutsrc == di.un.e.member[i].ord) {
1890 			mpm = eso_read_mixreg(sc, ESO_MIXREG_MPM);
1891 			mpm &= ~ESO_MIXREG_MPM_MOMASK;
1892 			mpm |= monooutsrc;
1893 			eso_write_mixreg(sc, ESO_MIXREG_MPM, mpm);
1894 			sc->sc_monooutsrc = monooutsrc;
1895 			return (0);
1896 		}
1897 	}
1898 
1899 	return (EINVAL);
1900 }
1901 
1902 int
1903 eso_set_monoinbypass(struct eso_softc *sc, uint monoinbypass)
1904 {
1905 	mixer_devinfo_t di;
1906 	int i, error;
1907 	uint8_t mpm;
1908 
1909 	di.index = ESO_MONOIN_BYPASS;
1910 	error = eso_query_devinfo(sc, &di);
1911 	if (error != 0) {
1912 		printf("eso_set_monoinbypass: eso_query_devinfo failed");
1913 		return (error);
1914 	}
1915 
1916 	for (i = 0; i < di.un.e.num_mem; i++) {
1917 		if (monoinbypass == di.un.e.member[i].ord) {
1918 			mpm = eso_read_mixreg(sc, ESO_MIXREG_MPM);
1919 			mpm &= ~(ESO_MIXREG_MPM_MOMASK | ESO_MIXREG_MPM_RESV0);
1920 			mpm |= (monoinbypass ? ESO_MIXREG_MPM_MIBYPASS : 0);
1921 			eso_write_mixreg(sc, ESO_MIXREG_MPM, mpm);
1922 			sc->sc_monoinbypass = monoinbypass;
1923 			return (0);
1924 		}
1925 	}
1926 
1927 	return (EINVAL);
1928 }
1929 
1930 int
1931 eso_set_preamp(struct eso_softc *sc, uint preamp)
1932 {
1933 	mixer_devinfo_t di;
1934 	int i, error;
1935 	uint8_t mpm;
1936 
1937 	di.index = ESO_MIC_PREAMP;
1938 	error = eso_query_devinfo(sc, &di);
1939 	if (error != 0) {
1940 		printf("eso_set_preamp: eso_query_devinfo failed");
1941 		return (error);
1942 	}
1943 
1944 	for (i = 0; i < di.un.e.num_mem; i++) {
1945 		if (preamp == di.un.e.member[i].ord) {
1946 			mpm = eso_read_mixreg(sc, ESO_MIXREG_MPM);
1947 			mpm &= ~(ESO_MIXREG_MPM_PREAMP | ESO_MIXREG_MPM_RESV0);
1948 			mpm |= (preamp ? ESO_MIXREG_MPM_PREAMP : 0);
1949 			eso_write_mixreg(sc, ESO_MIXREG_MPM, mpm);
1950 			sc->sc_preamp = preamp;
1951 			return (0);
1952 		}
1953 	}
1954 
1955 	return (EINVAL);
1956 }
1957 
1958 /*
1959  * Reload Master Volume and Mute values in softc from mixer; used when
1960  * those have previously been invalidated by use of hardware volume controls.
1961  */
1962 void
1963 eso_reload_master_vol(struct eso_softc *sc)
1964 {
1965 	uint8_t mv;
1966 
1967 	mv = eso_read_mixreg(sc, ESO_MIXREG_LMVM);
1968 	sc->sc_gain[ESO_MASTER_VOL][ESO_LEFT] =
1969 	    (mv & ~ESO_MIXREG_LMVM_MUTE) << 2;
1970 	mv = eso_read_mixreg(sc, ESO_MIXREG_LMVM);
1971 	sc->sc_gain[ESO_MASTER_VOL][ESO_RIGHT] =
1972 	    (mv & ~ESO_MIXREG_RMVM_MUTE) << 2;
1973 	/* Currently both channels are muted simultaneously; either is OK. */
1974 	sc->sc_mvmute = (mv & ESO_MIXREG_RMVM_MUTE) != 0;
1975 }
1976 
1977 void
1978 eso_set_gain(struct eso_softc *sc, uint port)
1979 {
1980 	uint8_t mixreg, tmp;
1981 
1982 	switch (port) {
1983 	case ESO_DAC_PLAY_VOL:
1984 		mixreg = ESO_MIXREG_PVR_A2;
1985 		break;
1986 	case ESO_MIC_PLAY_VOL:
1987 		mixreg = ESO_MIXREG_PVR_MIC;
1988 		break;
1989 	case ESO_LINE_PLAY_VOL:
1990 		mixreg = ESO_MIXREG_PVR_LINE;
1991 		break;
1992 	case ESO_SYNTH_PLAY_VOL:
1993 		mixreg = ESO_MIXREG_PVR_SYNTH;
1994 		break;
1995 	case ESO_CD_PLAY_VOL:
1996 		mixreg = ESO_MIXREG_PVR_CD;
1997 		break;
1998 	case ESO_AUXB_PLAY_VOL:
1999 		mixreg = ESO_MIXREG_PVR_AUXB;
2000 		break;
2001 	case ESO_DAC_REC_VOL:
2002 		mixreg = ESO_MIXREG_RVR_A2;
2003 		break;
2004 	case ESO_MIC_REC_VOL:
2005 		mixreg = ESO_MIXREG_RVR_MIC;
2006 		break;
2007 	case ESO_LINE_REC_VOL:
2008 		mixreg = ESO_MIXREG_RVR_LINE;
2009 		break;
2010 	case ESO_SYNTH_REC_VOL:
2011 		mixreg = ESO_MIXREG_RVR_SYNTH;
2012 		break;
2013 	case ESO_CD_REC_VOL:
2014 		mixreg = ESO_MIXREG_RVR_CD;
2015 		break;
2016 	case ESO_AUXB_REC_VOL:
2017 		mixreg = ESO_MIXREG_RVR_AUXB;
2018 		break;
2019 	case ESO_MONO_PLAY_VOL:
2020 		mixreg = ESO_MIXREG_PVR_MONO;
2021 		break;
2022 	case ESO_MONO_REC_VOL:
2023 		mixreg = ESO_MIXREG_RVR_MONO;
2024 		break;
2025 	case ESO_PCSPEAKER_VOL:
2026 		/* Special case - only 3-bit, mono, and reserved bits. */
2027 		tmp = eso_read_mixreg(sc, ESO_MIXREG_PCSVR);
2028 		tmp &= ESO_MIXREG_PCSVR_RESV;
2029 		/* Map bits 7:5 -> 2:0. */
2030 		tmp |= (sc->sc_gain[port][ESO_LEFT] >> 5);
2031 		eso_write_mixreg(sc, ESO_MIXREG_PCSVR, tmp);
2032 		return;
2033 	case ESO_MASTER_VOL:
2034 		/* Special case - separate regs, and 6-bit precision. */
2035 		/* Map bits 7:2 -> 5:0, reflect mute settings. */
2036 		eso_write_mixreg(sc, ESO_MIXREG_LMVM,
2037 		    (sc->sc_gain[port][ESO_LEFT] >> 2) |
2038 		    (sc->sc_mvmute ? ESO_MIXREG_LMVM_MUTE : 0x00));
2039 		eso_write_mixreg(sc, ESO_MIXREG_RMVM,
2040 		    (sc->sc_gain[port][ESO_RIGHT] >> 2) |
2041 		    (sc->sc_mvmute ? ESO_MIXREG_RMVM_MUTE : 0x00));
2042 		return;
2043 	case ESO_SPATIALIZER:
2044 		/* Special case - only `mono', and higher precision. */
2045 		eso_write_mixreg(sc, ESO_MIXREG_SPATLVL,
2046 		    sc->sc_gain[port][ESO_LEFT]);
2047 		return;
2048 	case ESO_RECORD_VOL:
2049 		/* Very Special case, controller register. */
2050 		eso_write_ctlreg(sc, ESO_CTLREG_RECLVL,ESO_4BIT_GAIN_TO_STEREO(
2051 		   sc->sc_gain[port][ESO_LEFT], sc->sc_gain[port][ESO_RIGHT]));
2052 		return;
2053 	default:
2054 #ifdef DIAGNOSTIC
2055 		printf("eso_set_gain: bad port %u", port);
2056 		return;
2057 		/* NOTREACHED */
2058 #else
2059 		return;
2060 #endif
2061 		}
2062 
2063 	eso_write_mixreg(sc, mixreg, ESO_4BIT_GAIN_TO_STEREO(
2064 	    sc->sc_gain[port][ESO_LEFT], sc->sc_gain[port][ESO_RIGHT]));
2065 }
2066 
2067 int
2068 eso_activate(struct device *self, int act)
2069 {
2070 	struct eso_softc *sc = (struct eso_softc *)self;
2071 	uint8_t tmp;
2072 	int rv = 0;
2073 
2074 	switch (act) {
2075 	case DVACT_QUIESCE:
2076 		rv = config_activate_children(self, act);
2077 		tmp = bus_space_read_1(sc->sc_iot, sc->sc_ioh, ESO_IO_IRQCTL);
2078 		tmp &= ~(ESO_IO_IRQCTL_MASK);
2079 		bus_space_write_1(sc->sc_iot, sc->sc_ioh, ESO_IO_IRQCTL, tmp);
2080 		break;
2081 	case DVACT_SUSPEND:
2082 		bus_space_write_1(sc->sc_iot, sc->sc_ioh, ESO_IO_A2DMAM, 0);
2083 		bus_space_write_1(sc->sc_dmac_iot, sc->sc_dmac_ioh,
2084 		    ESO_DMAC_CLEAR, 0);
2085 		bus_space_write_1(sc->sc_sb_iot, sc->sc_sb_ioh,
2086 		    ESO_SB_STATUSFLAGS, 3);
2087 		/* shut down dma */
2088 		pci_conf_write(sc->sc_pa.pa_pc, sc->sc_pa.pa_tag,
2089 		    ESO_PCI_DDMAC, 0);
2090 		break;
2091 	case DVACT_RESUME:
2092 		eso_setup(sc, 1, 1);
2093 		pci_conf_write(sc->sc_pa.pa_pc, sc->sc_pa.pa_tag,
2094 		    ESO_PCI_DDMAC, sc->sc_dmac_addr | ESO_PCI_DDMAC_DE);
2095 		rv = config_activate_children(self, act);
2096 		break;
2097 	default:
2098 		rv = config_activate_children(self, act);
2099 		break;
2100 	}
2101 	return (rv);
2102 }
2103