1 /* $NetBSD: eso.c,v 1.56 2009/05/12 08:23:00 cegger Exp $ */
4 * Copyright (c) 1999, 2000, 2004 Klaus J. Klein
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. The name of the author may not be used to endorse or promote products
16 * derived from this software without specific prior written permission.
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
20 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
21 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
22 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
25 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * ESS Technology Inc. Solo-1 PCI AudioDrive (ES1938/1946) device driver.
35 #include <sys/cdefs.h>
36 __KERNEL_RCSID(0, "$NetBSD: eso.c,v 1.56 2009/05/12 08:23:00 cegger Exp $");
40 #include <sys/param.h>
41 #include <sys/systm.h>
42 #include <sys/kernel.h>
43 #include <sys/malloc.h>
44 #include <sys/device.h>
45 #include <sys/queue.h>
48 #include <dev/pci/pcidevs.h>
49 #include <dev/pci/pcivar.h>
51 #include <sys/audioio.h>
52 #include <dev/audio_if.h>
53 #include <dev/midi_if.h>
55 #include <dev/mulaw.h>
56 #include <dev/auconv.h>
58 #include <dev/ic/mpuvar.h>
59 #include <dev/ic/i8237reg.h>
60 #include <dev/pci/esoreg.h>
61 #include <dev/pci/esovar.h>
67 * XXX Work around the 24-bit implementation limit of the Audio 1 DMA
68 * XXX engine by allocating through the ISA DMA tag.
70 #if defined(amd64) || defined(i386)
73 #include <dev/isa/isavar.h>
77 #if defined(AUDIO_DEBUG) || defined(DEBUG)
78 #define DPRINTF(x) printf x
84 bus_dma_tag_t ed_dmat
;
87 bus_dma_segment_t ed_segs
[1];
90 SLIST_ENTRY(eso_dma
) ed_slist
;
93 #define KVADDR(dma) ((void *)(dma)->ed_kva)
94 #define DMAADDR(dma) ((dma)->ed_map->dm_segs[0].ds_addr)
96 /* Autoconfiguration interface */
97 static int eso_match(device_t
, cfdata_t
, void *);
98 static void eso_attach(device_t
, device_t
, void *);
99 static void eso_defer(device_t
);
100 static int eso_print(void *, const char *);
102 CFATTACH_DECL(eso
, sizeof (struct eso_softc
),
103 eso_match
, eso_attach
, NULL
, NULL
);
106 static int eso_intr(void *);
108 /* MI audio layer interface */
109 static int eso_query_encoding(void *, struct audio_encoding
*);
110 static int eso_set_params(void *, int, int, audio_params_t
*,
111 audio_params_t
*, stream_filter_list_t
*,
112 stream_filter_list_t
*);
113 static int eso_round_blocksize(void *, int, int, const audio_params_t
*);
114 static int eso_halt_output(void *);
115 static int eso_halt_input(void *);
116 static int eso_getdev(void *, struct audio_device
*);
117 static int eso_set_port(void *, mixer_ctrl_t
*);
118 static int eso_get_port(void *, mixer_ctrl_t
*);
119 static int eso_query_devinfo(void *, mixer_devinfo_t
*);
120 static void * eso_allocm(void *, int, size_t, struct malloc_type
*, int);
121 static void eso_freem(void *, void *, struct malloc_type
*);
122 static size_t eso_round_buffersize(void *, int, size_t);
123 static paddr_t
eso_mappage(void *, void *, off_t
, int);
124 static int eso_get_props(void *);
125 static int eso_trigger_output(void *, void *, void *, int,
126 void (*)(void *), void *, const audio_params_t
*);
127 static int eso_trigger_input(void *, void *, void *, int,
128 void (*)(void *), void *, const audio_params_t
*);
130 static const struct audio_hw_if eso_hw_if
= {
137 NULL
, /* commit_settings */
138 NULL
, /* init_output */
139 NULL
, /* init_input */
140 NULL
, /* start_output */
141 NULL
, /* start_input */
144 NULL
, /* speaker_ctl */
152 eso_round_buffersize
,
157 NULL
, /* dev_ioctl */
158 NULL
, /* powerstate */
161 static const char * const eso_rev2model
[] = {
167 #define ESO_NFORMATS 8
168 static const struct audio_format eso_formats
[ESO_NFORMATS
] = {
169 {NULL
, AUMODE_PLAY
| AUMODE_RECORD
, AUDIO_ENCODING_SLINEAR_LE
, 16, 16,
170 2, AUFMT_STEREO
, 0, {ESO_MINRATE
, ESO_MAXRATE
}},
171 {NULL
, AUMODE_PLAY
| AUMODE_RECORD
, AUDIO_ENCODING_SLINEAR_LE
, 16, 16,
172 1, AUFMT_MONAURAL
, 0, {ESO_MINRATE
, ESO_MAXRATE
}},
173 {NULL
, AUMODE_PLAY
| AUMODE_RECORD
, AUDIO_ENCODING_ULINEAR_LE
, 16, 16,
174 2, AUFMT_STEREO
, 0, {ESO_MINRATE
, ESO_MAXRATE
}},
175 {NULL
, AUMODE_PLAY
| AUMODE_RECORD
, AUDIO_ENCODING_ULINEAR_LE
, 16, 16,
176 1, AUFMT_MONAURAL
, 0, {ESO_MINRATE
, ESO_MAXRATE
}},
177 {NULL
, AUMODE_PLAY
| AUMODE_RECORD
, AUDIO_ENCODING_SLINEAR_LE
, 8, 8,
178 2, AUFMT_STEREO
, 0, {ESO_MINRATE
, ESO_MAXRATE
}},
179 {NULL
, AUMODE_PLAY
| AUMODE_RECORD
, AUDIO_ENCODING_SLINEAR_LE
, 8, 8,
180 1, AUFMT_MONAURAL
, 0, {ESO_MINRATE
, ESO_MAXRATE
}},
181 {NULL
, AUMODE_PLAY
| AUMODE_RECORD
, AUDIO_ENCODING_ULINEAR_LE
, 8, 8,
182 2, AUFMT_STEREO
, 0, {ESO_MINRATE
, ESO_MAXRATE
}},
183 {NULL
, AUMODE_PLAY
| AUMODE_RECORD
, AUDIO_ENCODING_ULINEAR_LE
, 8, 8,
184 1, AUFMT_MONAURAL
, 0, {ESO_MINRATE
, ESO_MAXRATE
}}
191 /* Register access etc. */
192 static uint8_t eso_read_ctlreg(struct eso_softc
*, uint8_t);
193 static uint8_t eso_read_mixreg(struct eso_softc
*, uint8_t);
194 static uint8_t eso_read_rdr(struct eso_softc
*);
195 static void eso_reload_master_vol(struct eso_softc
*);
196 static int eso_reset(struct eso_softc
*);
197 static void eso_set_gain(struct eso_softc
*, unsigned int);
198 static int eso_set_recsrc(struct eso_softc
*, unsigned int);
199 static int eso_set_monooutsrc(struct eso_softc
*, unsigned int);
200 static int eso_set_monoinbypass(struct eso_softc
*, unsigned int);
201 static int eso_set_preamp(struct eso_softc
*, unsigned int);
202 static void eso_write_cmd(struct eso_softc
*, uint8_t);
203 static void eso_write_ctlreg(struct eso_softc
*, uint8_t, uint8_t);
204 static void eso_write_mixreg(struct eso_softc
*, uint8_t, uint8_t);
205 /* DMA memory allocation */
206 static int eso_allocmem(struct eso_softc
*, size_t, size_t, size_t,
207 int, int, struct eso_dma
*);
208 static void eso_freemem(struct eso_dma
*);
209 static struct eso_dma
* eso_kva2dma(const struct eso_softc
*, const void *);
213 eso_match(device_t parent
, cfdata_t match
, void *aux
)
215 struct pci_attach_args
*pa
;
218 if (PCI_VENDOR(pa
->pa_id
) == PCI_VENDOR_ESSTECH
&&
219 PCI_PRODUCT(pa
->pa_id
) == PCI_PRODUCT_ESSTECH_SOLO1
)
226 eso_attach(device_t parent
, device_t self
, void *aux
)
228 struct eso_softc
*sc
;
229 struct pci_attach_args
*pa
;
230 struct audio_attach_args aa
;
231 pci_intr_handle_t ih
;
233 const char *intrstring
;
235 uint8_t a2mode
, mvctl
;
237 sc
= device_private(self
);
239 aprint_naive(": Audio controller\n");
241 sc
->sc_revision
= PCI_REVISION(pa
->pa_class
);
243 aprint_normal(": ESS Solo-1 PCI AudioDrive ");
244 if (sc
->sc_revision
<
245 sizeof (eso_rev2model
) / sizeof (eso_rev2model
[0]))
246 aprint_normal("%s\n", eso_rev2model
[sc
->sc_revision
]);
248 aprint_normal("(unknown rev. 0x%02x)\n", sc
->sc_revision
);
250 /* Map I/O registers. */
251 if (pci_mapreg_map(pa
, ESO_PCI_BAR_IO
, PCI_MAPREG_TYPE_IO
, 0,
252 &sc
->sc_iot
, &sc
->sc_ioh
, NULL
, NULL
)) {
253 aprint_error_dev(&sc
->sc_dev
, "can't map I/O space\n");
256 if (pci_mapreg_map(pa
, ESO_PCI_BAR_SB
, PCI_MAPREG_TYPE_IO
, 0,
257 &sc
->sc_sb_iot
, &sc
->sc_sb_ioh
, NULL
, NULL
)) {
258 aprint_error_dev(&sc
->sc_dev
, "can't map SB I/O space\n");
261 if (pci_mapreg_map(pa
, ESO_PCI_BAR_VC
, PCI_MAPREG_TYPE_IO
, 0,
262 &sc
->sc_dmac_iot
, &sc
->sc_dmac_ioh
, &vcbase
, &sc
->sc_vcsize
)) {
263 aprint_error_dev(&sc
->sc_dev
, "can't map VC I/O space\n");
264 /* Don't bail out yet: we can map it later, see below. */
266 sc
->sc_vcsize
= 0x10; /* From the data sheet. */
268 if (pci_mapreg_map(pa
, ESO_PCI_BAR_MPU
, PCI_MAPREG_TYPE_IO
, 0,
269 &sc
->sc_mpu_iot
, &sc
->sc_mpu_ioh
, NULL
, NULL
)) {
270 aprint_error_dev(&sc
->sc_dev
, "can't map MPU I/O space\n");
273 if (pci_mapreg_map(pa
, ESO_PCI_BAR_GAME
, PCI_MAPREG_TYPE_IO
, 0,
274 &sc
->sc_game_iot
, &sc
->sc_game_ioh
, NULL
, NULL
)) {
275 aprint_error_dev(&sc
->sc_dev
, "can't map Game I/O space\n");
279 sc
->sc_dmat
= pa
->pa_dmat
;
280 SLIST_INIT(&sc
->sc_dmas
);
281 sc
->sc_dmac_configured
= 0;
283 /* Enable bus mastering. */
284 pci_conf_write(pa
->pa_pc
, pa
->pa_tag
, PCI_COMMAND_STATUS_REG
,
285 pci_conf_read(pa
->pa_pc
, pa
->pa_tag
, PCI_COMMAND_STATUS_REG
) |
286 PCI_COMMAND_MASTER_ENABLE
);
288 /* Reset the device; bail out upon failure. */
289 if (eso_reset(sc
) != 0) {
290 aprint_error_dev(&sc
->sc_dev
, "can't reset\n");
294 /* Select the DMA/IRQ policy: DDMA, ISA IRQ emulation disabled. */
295 pci_conf_write(pa
->pa_pc
, pa
->pa_tag
, ESO_PCI_S1C
,
296 pci_conf_read(pa
->pa_pc
, pa
->pa_tag
, ESO_PCI_S1C
) &
297 ~(ESO_PCI_S1C_IRQP_MASK
| ESO_PCI_S1C_DMAP_MASK
));
299 /* Enable the relevant (DMA) interrupts. */
300 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, ESO_IO_IRQCTL
,
301 ESO_IO_IRQCTL_A1IRQ
| ESO_IO_IRQCTL_A2IRQ
| ESO_IO_IRQCTL_HVIRQ
|
302 ESO_IO_IRQCTL_MPUIRQ
);
304 /* Set up A1's sample rate generator for new-style parameters. */
305 a2mode
= eso_read_mixreg(sc
, ESO_MIXREG_A2MODE
);
306 a2mode
|= ESO_MIXREG_A2MODE_NEWA1
| ESO_MIXREG_A2MODE_ASYNC
;
307 eso_write_mixreg(sc
, ESO_MIXREG_A2MODE
, a2mode
);
309 /* Slave Master Volume to Hardware Volume Control Counter, unmask IRQ.*/
310 mvctl
= eso_read_mixreg(sc
, ESO_MIXREG_MVCTL
);
311 mvctl
&= ~ESO_MIXREG_MVCTL_SPLIT
;
312 mvctl
|= ESO_MIXREG_MVCTL_HVIRQM
;
313 eso_write_mixreg(sc
, ESO_MIXREG_MVCTL
, mvctl
);
315 /* Set mixer regs to something reasonable, needs work. */
316 sc
->sc_recmon
= sc
->sc_spatializer
= sc
->sc_mvmute
= 0;
317 eso_set_monooutsrc(sc
, ESO_MIXREG_MPM_MOMUTE
);
318 eso_set_monoinbypass(sc
, 0);
319 eso_set_preamp(sc
, 1);
320 for (idx
= 0; idx
< ESO_NGAINDEVS
; idx
++) {
324 case ESO_MIC_PLAY_VOL
:
325 case ESO_LINE_PLAY_VOL
:
326 case ESO_CD_PLAY_VOL
:
327 case ESO_MONO_PLAY_VOL
:
328 case ESO_AUXB_PLAY_VOL
:
329 case ESO_DAC_REC_VOL
:
330 case ESO_LINE_REC_VOL
:
331 case ESO_SYNTH_REC_VOL
:
333 case ESO_MONO_REC_VOL
:
334 case ESO_AUXB_REC_VOL
:
335 case ESO_SPATIALIZER
:
339 v
= ESO_GAIN_TO_6BIT(AUDIO_MAX_GAIN
/ 2);
342 v
= ESO_GAIN_TO_4BIT(AUDIO_MAX_GAIN
/ 2);
345 sc
->sc_gain
[idx
][ESO_LEFT
] = sc
->sc_gain
[idx
][ESO_RIGHT
] = v
;
346 eso_set_gain(sc
, idx
);
348 eso_set_recsrc(sc
, ESO_MIXREG_ERS_MIC
);
350 /* Map and establish the interrupt. */
351 if (pci_intr_map(pa
, &ih
)) {
352 aprint_error_dev(&sc
->sc_dev
, "couldn't map interrupt\n");
355 intrstring
= pci_intr_string(pa
->pa_pc
, ih
);
356 sc
->sc_ih
= pci_intr_establish(pa
->pa_pc
, ih
, IPL_AUDIO
, eso_intr
, sc
);
357 if (sc
->sc_ih
== NULL
) {
358 aprint_error_dev(&sc
->sc_dev
, "couldn't establish interrupt");
359 if (intrstring
!= NULL
)
360 aprint_error(" at %s", intrstring
);
364 aprint_normal_dev(&sc
->sc_dev
, "interrupting at %s\n",
368 * Set up the DDMA Control register; a suitable I/O region has been
369 * supposedly mapped in the VC base address register.
371 * The Solo-1 has an ... interesting silicon bug that causes it to
372 * not respond to I/O space accesses to the Audio 1 DMA controller
373 * if the latter's mapping base address is aligned on a 1K boundary.
374 * As a consequence, it is quite possible for the mapping provided
375 * in the VC BAR to be useless. To work around this, we defer this
376 * part until all autoconfiguration on our parent bus is completed
377 * and then try to map it ourselves in fulfillment of the constraint.
379 * According to the register map we may write to the low 16 bits
380 * only, but experimenting has shown we're safe.
383 if (ESO_VALID_DDMAC_BASE(vcbase
)) {
384 pci_conf_write(pa
->pa_pc
, pa
->pa_tag
, ESO_PCI_DDMAC
,
385 vcbase
| ESO_PCI_DDMAC_DE
);
386 sc
->sc_dmac_configured
= 1;
388 aprint_normal_dev(&sc
->sc_dev
,
389 "mapping Audio 1 DMA using VC I/O space at 0x%lx\n",
390 (unsigned long)vcbase
);
392 DPRINTF(("%s: VC I/O space at 0x%lx not suitable, deferring\n",
393 device_xname(&sc
->sc_dev
), (unsigned long)vcbase
));
395 config_defer(self
, eso_defer
);
398 audio_attach_mi(&eso_hw_if
, sc
, &sc
->sc_dev
);
400 aa
.type
= AUDIODEV_TYPE_OPL
;
403 (void)config_found(&sc
->sc_dev
, &aa
, audioprint
);
405 aa
.type
= AUDIODEV_TYPE_MPU
;
408 sc
->sc_mpudev
= config_found(&sc
->sc_dev
, &aa
, audioprint
);
409 if (sc
->sc_mpudev
!= NULL
) {
410 /* Unmask the MPU irq. */
411 mvctl
= eso_read_mixreg(sc
, ESO_MIXREG_MVCTL
);
412 mvctl
|= ESO_MIXREG_MVCTL_MPUIRQM
;
413 eso_write_mixreg(sc
, ESO_MIXREG_MVCTL
, mvctl
);
416 aa
.type
= AUDIODEV_TYPE_AUX
;
419 (void)config_found(&sc
->sc_dev
, &aa
, eso_print
);
423 eso_defer(device_t self
)
425 struct eso_softc
*sc
;
426 struct pci_attach_args
*pa
;
427 bus_addr_t addr
, start
;
429 sc
= device_private(self
);
431 aprint_normal_dev(&sc
->sc_dev
, "");
434 * This is outright ugly, but since we must not make assumptions
435 * on the underlying allocator's behaviour it's the most straight-
436 * forward way to implement it. Note that we skip over the first
437 * 1K region, which is typically occupied by an attached ISA bus.
439 for (start
= 0x0400; start
< 0xffff; start
+= 0x0400) {
440 if (bus_space_alloc(sc
->sc_iot
,
441 start
+ sc
->sc_vcsize
, start
+ 0x0400 - 1,
442 sc
->sc_vcsize
, sc
->sc_vcsize
, 0, 0, &addr
,
443 &sc
->sc_dmac_ioh
) != 0)
446 pci_conf_write(pa
->pa_pc
, pa
->pa_tag
, ESO_PCI_DDMAC
,
447 addr
| ESO_PCI_DDMAC_DE
);
448 sc
->sc_dmac_iot
= sc
->sc_iot
;
449 sc
->sc_dmac_configured
= 1;
450 aprint_normal("mapping Audio 1 DMA using I/O space at 0x%lx\n",
451 (unsigned long)addr
);
456 aprint_error("can't map Audio 1 DMA into I/O space\n");
461 eso_print(void *aux
, const char *pnp
)
464 /* Only joys can attach via this; easy. */
466 aprint_normal("joy at %s:", pnp
);
472 eso_write_cmd(struct eso_softc
*sc
, uint8_t cmd
)
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
,
488 printf("%s: WDR timeout\n", device_xname(&sc
->sc_dev
));
492 /* Write to a controller register */
494 eso_write_ctlreg(struct eso_softc
*sc
, uint8_t reg
, uint8_t val
)
497 /* DPRINTF(("ctlreg 0x%02x = 0x%02x\n", reg, val)); */
499 eso_write_cmd(sc
, reg
);
500 eso_write_cmd(sc
, val
);
503 /* Read out the Read Data Register */
505 eso_read_rdr(struct eso_softc
*sc
)
509 for (i
= 0; i
< ESO_RDR_TIMEOUT
; i
++) {
510 if (bus_space_read_1(sc
->sc_sb_iot
, sc
->sc_sb_ioh
,
511 ESO_SB_RBSR
) & ESO_SB_RBSR_RDAV
) {
512 return (bus_space_read_1(sc
->sc_sb_iot
,
513 sc
->sc_sb_ioh
, ESO_SB_RDR
));
519 printf("%s: RDR timeout\n", device_xname(&sc
->sc_dev
));
524 eso_read_ctlreg(struct eso_softc
*sc
, uint8_t reg
)
527 eso_write_cmd(sc
, ESO_CMD_RCR
);
528 eso_write_cmd(sc
, reg
);
529 return eso_read_rdr(sc
);
533 eso_write_mixreg(struct eso_softc
*sc
, uint8_t reg
, uint8_t val
)
537 /* DPRINTF(("mixreg 0x%02x = 0x%02x\n", reg, val)); */
540 bus_space_write_1(sc
->sc_sb_iot
, sc
->sc_sb_ioh
, ESO_SB_MIXERADDR
, reg
);
541 bus_space_write_1(sc
->sc_sb_iot
, sc
->sc_sb_ioh
, ESO_SB_MIXERDATA
, val
);
546 eso_read_mixreg(struct eso_softc
*sc
, uint8_t reg
)
552 bus_space_write_1(sc
->sc_sb_iot
, sc
->sc_sb_ioh
, ESO_SB_MIXERADDR
, reg
);
553 val
= bus_space_read_1(sc
->sc_sb_iot
, sc
->sc_sb_ioh
, ESO_SB_MIXERDATA
);
562 struct eso_softc
*sc
= hdl
;
564 struct mpu_softc
*sc_mpu
= device_private(sc
->sc_mpudev
);
568 irqctl
= bus_space_read_1(sc
->sc_iot
, sc
->sc_ioh
, ESO_IO_IRQCTL
);
570 /* If it wasn't ours, that's all she wrote. */
571 if ((irqctl
& (ESO_IO_IRQCTL_A1IRQ
| ESO_IO_IRQCTL_A2IRQ
|
572 ESO_IO_IRQCTL_HVIRQ
| ESO_IO_IRQCTL_MPUIRQ
)) == 0)
575 if (irqctl
& ESO_IO_IRQCTL_A1IRQ
) {
576 /* Clear interrupt. */
577 (void)bus_space_read_1(sc
->sc_sb_iot
, sc
->sc_sb_ioh
,
581 sc
->sc_rintr(sc
->sc_rarg
);
583 wakeup(&sc
->sc_rintr
);
586 if (irqctl
& ESO_IO_IRQCTL_A2IRQ
) {
588 * Clear the A2 IRQ latch: the cached value reflects the
589 * current DAC settings with the IRQ latch bit not set.
591 eso_write_mixreg(sc
, ESO_MIXREG_A2C2
, sc
->sc_a2c2
);
594 sc
->sc_pintr(sc
->sc_parg
);
596 wakeup(&sc
->sc_pintr
);
599 if (irqctl
& ESO_IO_IRQCTL_HVIRQ
) {
600 /* Clear interrupt. */
601 eso_write_mixreg(sc
, ESO_MIXREG_CHVIR
, ESO_MIXREG_CHVIR_CHVIR
);
604 * Raise a flag to cause a lazy update of the in-softc gain
605 * values the next time the software mixer is read to keep
606 * interrupt service cost low. ~0 cannot occur otherwise
607 * as the master volume has a precision of 6 bits only.
609 sc
->sc_gain
[ESO_MASTER_VOL
][ESO_LEFT
] = (uint8_t)~0;
613 if ((irqctl
& ESO_IO_IRQCTL_MPUIRQ
) && sc_mpu
!= NULL
)
620 /* Perform a software reset, including DMA FIFOs. */
622 eso_reset(struct eso_softc
*sc
)
626 bus_space_write_1(sc
->sc_sb_iot
, sc
->sc_sb_ioh
, ESO_SB_RESET
,
627 ESO_SB_RESET_SW
| ESO_SB_RESET_FIFO
);
628 /* `Delay' suggested in the data sheet. */
629 (void)bus_space_read_1(sc
->sc_sb_iot
, sc
->sc_sb_ioh
, ESO_SB_STATUS
);
630 bus_space_write_1(sc
->sc_sb_iot
, sc
->sc_sb_ioh
, ESO_SB_RESET
, 0);
632 /* Wait for reset to take effect. */
633 for (i
= 0; i
< ESO_RESET_TIMEOUT
; i
++) {
634 /* Poll for data to become available. */
635 if ((bus_space_read_1(sc
->sc_sb_iot
, sc
->sc_sb_ioh
,
636 ESO_SB_RBSR
) & ESO_SB_RBSR_RDAV
) != 0 &&
637 bus_space_read_1(sc
->sc_sb_iot
, sc
->sc_sb_ioh
,
638 ESO_SB_RDR
) == ESO_SB_RDR_RESETMAGIC
) {
640 /* Activate Solo-1 extension commands. */
641 eso_write_cmd(sc
, ESO_CMD_EXTENB
);
642 /* Reset mixer registers. */
643 eso_write_mixreg(sc
, ESO_MIXREG_RESET
,
644 ESO_MIXREG_RESET_RESET
);
652 printf("%s: reset timeout\n", device_xname(&sc
->sc_dev
));
657 eso_query_encoding(void *hdl
, struct audio_encoding
*fp
)
662 strcpy(fp
->name
, AudioEulinear
);
663 fp
->encoding
= AUDIO_ENCODING_ULINEAR
;
668 strcpy(fp
->name
, AudioEmulaw
);
669 fp
->encoding
= AUDIO_ENCODING_ULAW
;
671 fp
->flags
= AUDIO_ENCODINGFLAG_EMULATED
;
674 strcpy(fp
->name
, AudioEalaw
);
675 fp
->encoding
= AUDIO_ENCODING_ALAW
;
677 fp
->flags
= AUDIO_ENCODINGFLAG_EMULATED
;
680 strcpy(fp
->name
, AudioEslinear
);
681 fp
->encoding
= AUDIO_ENCODING_SLINEAR
;
686 strcpy(fp
->name
, AudioEslinear_le
);
687 fp
->encoding
= AUDIO_ENCODING_SLINEAR_LE
;
689 fp
->flags
= AUDIO_ENCODINGFLAG_EMULATED
;
692 strcpy(fp
->name
, AudioEulinear_le
);
693 fp
->encoding
= AUDIO_ENCODING_ULINEAR_LE
;
695 fp
->flags
= AUDIO_ENCODINGFLAG_EMULATED
;
698 strcpy(fp
->name
, AudioEslinear_be
);
699 fp
->encoding
= AUDIO_ENCODING_SLINEAR_BE
;
701 fp
->flags
= AUDIO_ENCODINGFLAG_EMULATED
;
704 strcpy(fp
->name
, AudioEulinear_be
);
705 fp
->encoding
= AUDIO_ENCODING_ULINEAR_BE
;
707 fp
->flags
= AUDIO_ENCODINGFLAG_EMULATED
;
717 eso_set_params(void *hdl
, int setmode
, int usemode
,
718 audio_params_t
*play
, audio_params_t
*rec
, stream_filter_list_t
*pfil
,
719 stream_filter_list_t
*rfil
)
721 struct eso_softc
*sc
;
722 struct audio_params
*p
;
723 stream_filter_list_t
*fil
;
724 int mode
, r
[2], rd
[2], ar
[2], clk
;
725 unsigned int srg
, fltdiv
;
729 for (mode
= AUMODE_RECORD
; mode
!= -1;
730 mode
= mode
== AUMODE_RECORD
? AUMODE_PLAY
: -1) {
731 if ((setmode
& mode
) == 0)
734 p
= (mode
== AUMODE_PLAY
) ? play
: rec
;
736 if (p
->sample_rate
< ESO_MINRATE
||
737 p
->sample_rate
> ESO_MAXRATE
||
738 (p
->precision
!= 8 && p
->precision
!= 16) ||
739 (p
->channels
!= 1 && p
->channels
!= 2))
743 * We'll compute both possible sample rate dividers and pick
744 * the one with the least error.
746 #define ABS(x) ((x) < 0 ? -(x) : (x))
748 (128 - (rd
[0] = 128 - ESO_CLK0
/ p
->sample_rate
));
750 (128 - (rd
[1] = 128 - ESO_CLK1
/ p
->sample_rate
));
752 ar
[0] = p
->sample_rate
- r
[0];
753 ar
[1] = p
->sample_rate
- r
[1];
754 clk
= ABS(ar
[0]) > ABS(ar
[1]) ? 1 : 0;
755 srg
= rd
[clk
] | (clk
== 1 ? ESO_CLK1_SELECT
: 0x00);
757 /* Roll-off frequency of 87%, as in the ES1888 driver. */
758 fltdiv
= 256 - 200279L / r
[clk
];
760 /* Update to reflect the possibly inexact rate. */
761 p
->sample_rate
= r
[clk
];
763 fil
= (mode
== AUMODE_PLAY
) ? pfil
: rfil
;
764 i
= auconv_set_converter(eso_formats
, ESO_NFORMATS
,
765 mode
, p
, FALSE
, fil
);
768 if (mode
== AUMODE_RECORD
) {
770 DPRINTF(("A1 srg 0x%02x fdiv 0x%02x\n", srg
, fltdiv
));
771 eso_write_ctlreg(sc
, ESO_CTLREG_SRG
, srg
);
772 eso_write_ctlreg(sc
, ESO_CTLREG_FLTDIV
, fltdiv
);
775 DPRINTF(("A2 srg 0x%02x fdiv 0x%02x\n", srg
, fltdiv
));
776 eso_write_mixreg(sc
, ESO_MIXREG_A2SRG
, srg
);
777 eso_write_mixreg(sc
, ESO_MIXREG_A2FLTDIV
, fltdiv
);
787 eso_round_blocksize(void *hdl
, int blk
, int mode
,
788 const audio_params_t
*param
)
791 return blk
& -32; /* keep good alignment; at least 16 req'd */
795 eso_halt_output(void *hdl
)
797 struct eso_softc
*sc
;
801 DPRINTF(("%s: halt_output\n", device_xname(&sc
->sc_dev
)));
804 * Disable auto-initialize DMA, allowing the FIFO to drain and then
805 * stop. The interrupt callback pointer is cleared at this
806 * point so that an outstanding FIFO interrupt for the remaining data
807 * will be acknowledged without further processing.
809 * This does not immediately `abort' an operation in progress (c.f.
810 * audio(9)) but is the method to leave the FIFO behind in a clean
811 * state with the least hair. (Besides, that item needs to be
812 * rephrased for trigger_*()-based DMA environments.)
815 eso_write_mixreg(sc
, ESO_MIXREG_A2C1
,
816 ESO_MIXREG_A2C1_FIFOENB
| ESO_MIXREG_A2C1_DMAENB
);
817 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, ESO_IO_A2DMAM
,
818 ESO_IO_A2DMAM_DMAENB
);
821 error
= tsleep(&sc
->sc_pintr
, PCATCH
| PWAIT
, "esoho", sc
->sc_pdrain
);
824 /* Shut down DMA completely. */
825 eso_write_mixreg(sc
, ESO_MIXREG_A2C1
, 0);
826 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, ESO_IO_A2DMAM
, 0);
828 return error
== EWOULDBLOCK
? 0 : error
;
832 eso_halt_input(void *hdl
)
834 struct eso_softc
*sc
;
838 DPRINTF(("%s: halt_input\n", device_xname(&sc
->sc_dev
)));
840 /* Just like eso_halt_output(), but for Audio 1. */
842 eso_write_ctlreg(sc
, ESO_CTLREG_A1C2
,
843 ESO_CTLREG_A1C2_READ
| ESO_CTLREG_A1C2_ADC
|
844 ESO_CTLREG_A1C2_DMAENB
);
845 bus_space_write_1(sc
->sc_dmac_iot
, sc
->sc_dmac_ioh
, ESO_DMAC_MODE
,
846 DMA37MD_WRITE
| DMA37MD_DEMAND
);
849 error
= tsleep(&sc
->sc_rintr
, PCATCH
| PWAIT
, "esohi", sc
->sc_rdrain
);
852 /* Shut down DMA completely. */
853 eso_write_ctlreg(sc
, ESO_CTLREG_A1C2
,
854 ESO_CTLREG_A1C2_READ
| ESO_CTLREG_A1C2_ADC
);
855 bus_space_write_1(sc
->sc_dmac_iot
, sc
->sc_dmac_ioh
, ESO_DMAC_MASK
,
858 return error
== EWOULDBLOCK
? 0 : error
;
862 eso_getdev(void *hdl
, struct audio_device
*retp
)
864 struct eso_softc
*sc
;
867 strncpy(retp
->name
, "ESS Solo-1", sizeof (retp
->name
));
868 snprintf(retp
->version
, sizeof (retp
->version
), "0x%02x",
870 if (sc
->sc_revision
<
871 sizeof (eso_rev2model
) / sizeof (eso_rev2model
[0]))
872 strncpy(retp
->config
, eso_rev2model
[sc
->sc_revision
],
873 sizeof (retp
->config
));
875 strncpy(retp
->config
, "unknown", sizeof (retp
->config
));
881 eso_set_port(void *hdl
, mixer_ctrl_t
*cp
)
883 struct eso_softc
*sc
;
884 unsigned int lgain
, rgain
;
889 case ESO_DAC_PLAY_VOL
:
890 case ESO_MIC_PLAY_VOL
:
891 case ESO_LINE_PLAY_VOL
:
892 case ESO_SYNTH_PLAY_VOL
:
893 case ESO_CD_PLAY_VOL
:
894 case ESO_AUXB_PLAY_VOL
:
896 case ESO_DAC_REC_VOL
:
897 case ESO_MIC_REC_VOL
:
898 case ESO_LINE_REC_VOL
:
899 case ESO_SYNTH_REC_VOL
:
901 case ESO_AUXB_REC_VOL
:
902 if (cp
->type
!= AUDIO_MIXER_VALUE
)
906 * Stereo-capable mixer ports: if we get a single-channel
907 * gain value passed in, then we duplicate it to both left
908 * and right channels.
910 switch (cp
->un
.value
.num_channels
) {
912 lgain
= rgain
= ESO_GAIN_TO_4BIT(
913 cp
->un
.value
.level
[AUDIO_MIXER_LEVEL_MONO
]);
916 lgain
= ESO_GAIN_TO_4BIT(
917 cp
->un
.value
.level
[AUDIO_MIXER_LEVEL_LEFT
]);
918 rgain
= ESO_GAIN_TO_4BIT(
919 cp
->un
.value
.level
[AUDIO_MIXER_LEVEL_RIGHT
]);
925 sc
->sc_gain
[cp
->dev
][ESO_LEFT
] = lgain
;
926 sc
->sc_gain
[cp
->dev
][ESO_RIGHT
] = rgain
;
927 eso_set_gain(sc
, cp
->dev
);
931 if (cp
->type
!= AUDIO_MIXER_VALUE
)
934 /* Like above, but a precision of 6 bits. */
935 switch (cp
->un
.value
.num_channels
) {
937 lgain
= rgain
= ESO_GAIN_TO_6BIT(
938 cp
->un
.value
.level
[AUDIO_MIXER_LEVEL_MONO
]);
941 lgain
= ESO_GAIN_TO_6BIT(
942 cp
->un
.value
.level
[AUDIO_MIXER_LEVEL_LEFT
]);
943 rgain
= ESO_GAIN_TO_6BIT(
944 cp
->un
.value
.level
[AUDIO_MIXER_LEVEL_RIGHT
]);
950 sc
->sc_gain
[cp
->dev
][ESO_LEFT
] = lgain
;
951 sc
->sc_gain
[cp
->dev
][ESO_RIGHT
] = rgain
;
952 eso_set_gain(sc
, cp
->dev
);
955 case ESO_SPATIALIZER
:
956 if (cp
->type
!= AUDIO_MIXER_VALUE
||
957 cp
->un
.value
.num_channels
!= 1)
960 sc
->sc_gain
[cp
->dev
][ESO_LEFT
] =
961 sc
->sc_gain
[cp
->dev
][ESO_RIGHT
] =
963 cp
->un
.value
.level
[AUDIO_MIXER_LEVEL_MONO
]);
964 eso_set_gain(sc
, cp
->dev
);
967 case ESO_MONO_PLAY_VOL
:
968 case ESO_MONO_REC_VOL
:
969 if (cp
->type
!= AUDIO_MIXER_VALUE
||
970 cp
->un
.value
.num_channels
!= 1)
973 sc
->sc_gain
[cp
->dev
][ESO_LEFT
] =
974 sc
->sc_gain
[cp
->dev
][ESO_RIGHT
] =
976 cp
->un
.value
.level
[AUDIO_MIXER_LEVEL_MONO
]);
977 eso_set_gain(sc
, cp
->dev
);
980 case ESO_PCSPEAKER_VOL
:
981 if (cp
->type
!= AUDIO_MIXER_VALUE
||
982 cp
->un
.value
.num_channels
!= 1)
985 sc
->sc_gain
[cp
->dev
][ESO_LEFT
] =
986 sc
->sc_gain
[cp
->dev
][ESO_RIGHT
] =
988 cp
->un
.value
.level
[AUDIO_MIXER_LEVEL_MONO
]);
989 eso_set_gain(sc
, cp
->dev
);
992 case ESO_SPATIALIZER_ENABLE
:
993 if (cp
->type
!= AUDIO_MIXER_ENUM
)
996 sc
->sc_spatializer
= (cp
->un
.ord
!= 0);
998 tmp
= eso_read_mixreg(sc
, ESO_MIXREG_SPAT
);
999 if (sc
->sc_spatializer
)
1000 tmp
|= ESO_MIXREG_SPAT_ENB
;
1002 tmp
&= ~ESO_MIXREG_SPAT_ENB
;
1003 eso_write_mixreg(sc
, ESO_MIXREG_SPAT
,
1004 tmp
| ESO_MIXREG_SPAT_RSTREL
);
1007 case ESO_MASTER_MUTE
:
1008 if (cp
->type
!= AUDIO_MIXER_ENUM
)
1011 sc
->sc_mvmute
= (cp
->un
.ord
!= 0);
1013 if (sc
->sc_mvmute
) {
1014 eso_write_mixreg(sc
, ESO_MIXREG_LMVM
,
1015 eso_read_mixreg(sc
, ESO_MIXREG_LMVM
) |
1016 ESO_MIXREG_LMVM_MUTE
);
1017 eso_write_mixreg(sc
, ESO_MIXREG_RMVM
,
1018 eso_read_mixreg(sc
, ESO_MIXREG_RMVM
) |
1019 ESO_MIXREG_RMVM_MUTE
);
1021 eso_write_mixreg(sc
, ESO_MIXREG_LMVM
,
1022 eso_read_mixreg(sc
, ESO_MIXREG_LMVM
) &
1023 ~ESO_MIXREG_LMVM_MUTE
);
1024 eso_write_mixreg(sc
, ESO_MIXREG_RMVM
,
1025 eso_read_mixreg(sc
, ESO_MIXREG_RMVM
) &
1026 ~ESO_MIXREG_RMVM_MUTE
);
1030 case ESO_MONOOUT_SOURCE
:
1031 if (cp
->type
!= AUDIO_MIXER_ENUM
)
1034 return eso_set_monooutsrc(sc
, cp
->un
.ord
);
1036 case ESO_MONOIN_BYPASS
:
1037 if (cp
->type
!= AUDIO_MIXER_ENUM
)
1040 return (eso_set_monoinbypass(sc
, cp
->un
.ord
));
1042 case ESO_RECORD_MONITOR
:
1043 if (cp
->type
!= AUDIO_MIXER_ENUM
)
1046 sc
->sc_recmon
= (cp
->un
.ord
!= 0);
1048 tmp
= eso_read_ctlreg(sc
, ESO_CTLREG_ACTL
);
1050 tmp
|= ESO_CTLREG_ACTL_RECMON
;
1052 tmp
&= ~ESO_CTLREG_ACTL_RECMON
;
1053 eso_write_ctlreg(sc
, ESO_CTLREG_ACTL
, tmp
);
1056 case ESO_RECORD_SOURCE
:
1057 if (cp
->type
!= AUDIO_MIXER_ENUM
)
1060 return eso_set_recsrc(sc
, cp
->un
.ord
);
1062 case ESO_MIC_PREAMP
:
1063 if (cp
->type
!= AUDIO_MIXER_ENUM
)
1066 return eso_set_preamp(sc
, cp
->un
.ord
);
1076 eso_get_port(void *hdl
, mixer_ctrl_t
*cp
)
1078 struct eso_softc
*sc
;
1082 case ESO_MASTER_VOL
:
1083 /* Reload from mixer after hardware volume control use. */
1084 if (sc
->sc_gain
[cp
->dev
][ESO_LEFT
] == (uint8_t)~0)
1085 eso_reload_master_vol(sc
);
1087 case ESO_DAC_PLAY_VOL
:
1088 case ESO_MIC_PLAY_VOL
:
1089 case ESO_LINE_PLAY_VOL
:
1090 case ESO_SYNTH_PLAY_VOL
:
1091 case ESO_CD_PLAY_VOL
:
1092 case ESO_AUXB_PLAY_VOL
:
1093 case ESO_RECORD_VOL
:
1094 case ESO_DAC_REC_VOL
:
1095 case ESO_MIC_REC_VOL
:
1096 case ESO_LINE_REC_VOL
:
1097 case ESO_SYNTH_REC_VOL
:
1098 case ESO_CD_REC_VOL
:
1099 case ESO_AUXB_REC_VOL
:
1101 * Stereo-capable ports: if a single-channel query is made,
1102 * just return the left channel's value (since single-channel
1103 * settings themselves are applied to both channels).
1105 switch (cp
->un
.value
.num_channels
) {
1107 cp
->un
.value
.level
[AUDIO_MIXER_LEVEL_MONO
] =
1108 sc
->sc_gain
[cp
->dev
][ESO_LEFT
];
1111 cp
->un
.value
.level
[AUDIO_MIXER_LEVEL_LEFT
] =
1112 sc
->sc_gain
[cp
->dev
][ESO_LEFT
];
1113 cp
->un
.value
.level
[AUDIO_MIXER_LEVEL_RIGHT
] =
1114 sc
->sc_gain
[cp
->dev
][ESO_RIGHT
];
1121 case ESO_MONO_PLAY_VOL
:
1122 case ESO_PCSPEAKER_VOL
:
1123 case ESO_MONO_REC_VOL
:
1124 case ESO_SPATIALIZER
:
1125 if (cp
->un
.value
.num_channels
!= 1)
1127 cp
->un
.value
.level
[AUDIO_MIXER_LEVEL_MONO
] =
1128 sc
->sc_gain
[cp
->dev
][ESO_LEFT
];
1131 case ESO_RECORD_MONITOR
:
1132 cp
->un
.ord
= sc
->sc_recmon
;
1135 case ESO_RECORD_SOURCE
:
1136 cp
->un
.ord
= sc
->sc_recsrc
;
1139 case ESO_MONOOUT_SOURCE
:
1140 cp
->un
.ord
= sc
->sc_monooutsrc
;
1143 case ESO_MONOIN_BYPASS
:
1144 cp
->un
.ord
= sc
->sc_monoinbypass
;
1147 case ESO_SPATIALIZER_ENABLE
:
1148 cp
->un
.ord
= sc
->sc_spatializer
;
1151 case ESO_MIC_PREAMP
:
1152 cp
->un
.ord
= sc
->sc_preamp
;
1155 case ESO_MASTER_MUTE
:
1156 /* Reload from mixer after hardware volume control use. */
1157 if (sc
->sc_gain
[ESO_MASTER_VOL
][ESO_LEFT
] == (uint8_t)~0)
1158 eso_reload_master_vol(sc
);
1159 cp
->un
.ord
= sc
->sc_mvmute
;
1170 eso_query_devinfo(void *hdl
, mixer_devinfo_t
*dip
)
1173 switch (dip
->index
) {
1174 case ESO_DAC_PLAY_VOL
:
1175 dip
->mixer_class
= ESO_INPUT_CLASS
;
1176 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1177 strcpy(dip
->label
.name
, AudioNdac
);
1178 dip
->type
= AUDIO_MIXER_VALUE
;
1179 dip
->un
.v
.num_channels
= 2;
1180 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
1182 case ESO_MIC_PLAY_VOL
:
1183 dip
->mixer_class
= ESO_INPUT_CLASS
;
1184 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1185 strcpy(dip
->label
.name
, AudioNmicrophone
);
1186 dip
->type
= AUDIO_MIXER_VALUE
;
1187 dip
->un
.v
.num_channels
= 2;
1188 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
1190 case ESO_LINE_PLAY_VOL
:
1191 dip
->mixer_class
= ESO_INPUT_CLASS
;
1192 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1193 strcpy(dip
->label
.name
, AudioNline
);
1194 dip
->type
= AUDIO_MIXER_VALUE
;
1195 dip
->un
.v
.num_channels
= 2;
1196 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
1198 case ESO_SYNTH_PLAY_VOL
:
1199 dip
->mixer_class
= ESO_INPUT_CLASS
;
1200 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1201 strcpy(dip
->label
.name
, AudioNfmsynth
);
1202 dip
->type
= AUDIO_MIXER_VALUE
;
1203 dip
->un
.v
.num_channels
= 2;
1204 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
1206 case ESO_MONO_PLAY_VOL
:
1207 dip
->mixer_class
= ESO_INPUT_CLASS
;
1208 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1209 strcpy(dip
->label
.name
, "mono_in");
1210 dip
->type
= AUDIO_MIXER_VALUE
;
1211 dip
->un
.v
.num_channels
= 1;
1212 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
1214 case ESO_CD_PLAY_VOL
:
1215 dip
->mixer_class
= ESO_INPUT_CLASS
;
1216 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1217 strcpy(dip
->label
.name
, AudioNcd
);
1218 dip
->type
= AUDIO_MIXER_VALUE
;
1219 dip
->un
.v
.num_channels
= 2;
1220 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
1222 case ESO_AUXB_PLAY_VOL
:
1223 dip
->mixer_class
= ESO_INPUT_CLASS
;
1224 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1225 strcpy(dip
->label
.name
, "auxb");
1226 dip
->type
= AUDIO_MIXER_VALUE
;
1227 dip
->un
.v
.num_channels
= 2;
1228 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
1231 case ESO_MIC_PREAMP
:
1232 dip
->mixer_class
= ESO_MICROPHONE_CLASS
;
1233 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1234 strcpy(dip
->label
.name
, AudioNpreamp
);
1235 dip
->type
= AUDIO_MIXER_ENUM
;
1236 dip
->un
.e
.num_mem
= 2;
1237 strcpy(dip
->un
.e
.member
[0].label
.name
, AudioNoff
);
1238 dip
->un
.e
.member
[0].ord
= 0;
1239 strcpy(dip
->un
.e
.member
[1].label
.name
, AudioNon
);
1240 dip
->un
.e
.member
[1].ord
= 1;
1242 case ESO_MICROPHONE_CLASS
:
1243 dip
->mixer_class
= ESO_MICROPHONE_CLASS
;
1244 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1245 strcpy(dip
->label
.name
, AudioNmicrophone
);
1246 dip
->type
= AUDIO_MIXER_CLASS
;
1249 case ESO_INPUT_CLASS
:
1250 dip
->mixer_class
= ESO_INPUT_CLASS
;
1251 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1252 strcpy(dip
->label
.name
, AudioCinputs
);
1253 dip
->type
= AUDIO_MIXER_CLASS
;
1256 case ESO_MASTER_VOL
:
1257 dip
->mixer_class
= ESO_OUTPUT_CLASS
;
1258 dip
->prev
= AUDIO_MIXER_LAST
;
1259 dip
->next
= ESO_MASTER_MUTE
;
1260 strcpy(dip
->label
.name
, AudioNmaster
);
1261 dip
->type
= AUDIO_MIXER_VALUE
;
1262 dip
->un
.v
.num_channels
= 2;
1263 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
1265 case ESO_MASTER_MUTE
:
1266 dip
->mixer_class
= ESO_OUTPUT_CLASS
;
1267 dip
->prev
= ESO_MASTER_VOL
;
1268 dip
->next
= AUDIO_MIXER_LAST
;
1269 strcpy(dip
->label
.name
, AudioNmute
);
1270 dip
->type
= AUDIO_MIXER_ENUM
;
1271 dip
->un
.e
.num_mem
= 2;
1272 strcpy(dip
->un
.e
.member
[0].label
.name
, AudioNoff
);
1273 dip
->un
.e
.member
[0].ord
= 0;
1274 strcpy(dip
->un
.e
.member
[1].label
.name
, AudioNon
);
1275 dip
->un
.e
.member
[1].ord
= 1;
1278 case ESO_PCSPEAKER_VOL
:
1279 dip
->mixer_class
= ESO_OUTPUT_CLASS
;
1280 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1281 strcpy(dip
->label
.name
, "pc_speaker");
1282 dip
->type
= AUDIO_MIXER_VALUE
;
1283 dip
->un
.v
.num_channels
= 1;
1284 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
1286 case ESO_MONOOUT_SOURCE
:
1287 dip
->mixer_class
= ESO_OUTPUT_CLASS
;
1288 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1289 strcpy(dip
->label
.name
, "mono_out");
1290 dip
->type
= AUDIO_MIXER_ENUM
;
1291 dip
->un
.e
.num_mem
= 3;
1292 strcpy(dip
->un
.e
.member
[0].label
.name
, AudioNmute
);
1293 dip
->un
.e
.member
[0].ord
= ESO_MIXREG_MPM_MOMUTE
;
1294 strcpy(dip
->un
.e
.member
[1].label
.name
, AudioNdac
);
1295 dip
->un
.e
.member
[1].ord
= ESO_MIXREG_MPM_MOA2R
;
1296 strcpy(dip
->un
.e
.member
[2].label
.name
, AudioNmixerout
);
1297 dip
->un
.e
.member
[2].ord
= ESO_MIXREG_MPM_MOREC
;
1300 case ESO_MONOIN_BYPASS
:
1301 dip
->mixer_class
= ESO_MONOIN_CLASS
;
1302 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1303 strcpy(dip
->label
.name
, "bypass");
1304 dip
->type
= AUDIO_MIXER_ENUM
;
1305 dip
->un
.e
.num_mem
= 2;
1306 strcpy(dip
->un
.e
.member
[0].label
.name
, AudioNoff
);
1307 dip
->un
.e
.member
[0].ord
= 0;
1308 strcpy(dip
->un
.e
.member
[1].label
.name
, AudioNon
);
1309 dip
->un
.e
.member
[1].ord
= 1;
1311 case ESO_MONOIN_CLASS
:
1312 dip
->mixer_class
= ESO_MONOIN_CLASS
;
1313 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1314 strcpy(dip
->label
.name
, "mono_in");
1315 dip
->type
= AUDIO_MIXER_CLASS
;
1318 case ESO_SPATIALIZER
:
1319 dip
->mixer_class
= ESO_OUTPUT_CLASS
;
1320 dip
->prev
= AUDIO_MIXER_LAST
;
1321 dip
->next
= ESO_SPATIALIZER_ENABLE
;
1322 strcpy(dip
->label
.name
, AudioNspatial
);
1323 dip
->type
= AUDIO_MIXER_VALUE
;
1324 dip
->un
.v
.num_channels
= 1;
1325 strcpy(dip
->un
.v
.units
.name
, "level");
1327 case ESO_SPATIALIZER_ENABLE
:
1328 dip
->mixer_class
= ESO_OUTPUT_CLASS
;
1329 dip
->prev
= ESO_SPATIALIZER
;
1330 dip
->next
= AUDIO_MIXER_LAST
;
1331 strcpy(dip
->label
.name
, "enable");
1332 dip
->type
= AUDIO_MIXER_ENUM
;
1333 dip
->un
.e
.num_mem
= 2;
1334 strcpy(dip
->un
.e
.member
[0].label
.name
, AudioNoff
);
1335 dip
->un
.e
.member
[0].ord
= 0;
1336 strcpy(dip
->un
.e
.member
[1].label
.name
, AudioNon
);
1337 dip
->un
.e
.member
[1].ord
= 1;
1340 case ESO_OUTPUT_CLASS
:
1341 dip
->mixer_class
= ESO_OUTPUT_CLASS
;
1342 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1343 strcpy(dip
->label
.name
, AudioCoutputs
);
1344 dip
->type
= AUDIO_MIXER_CLASS
;
1347 case ESO_RECORD_MONITOR
:
1348 dip
->mixer_class
= ESO_MONITOR_CLASS
;
1349 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1350 strcpy(dip
->label
.name
, AudioNmute
);
1351 dip
->type
= AUDIO_MIXER_ENUM
;
1352 dip
->un
.e
.num_mem
= 2;
1353 strcpy(dip
->un
.e
.member
[0].label
.name
, AudioNoff
);
1354 dip
->un
.e
.member
[0].ord
= 0;
1355 strcpy(dip
->un
.e
.member
[1].label
.name
, AudioNon
);
1356 dip
->un
.e
.member
[1].ord
= 1;
1358 case ESO_MONITOR_CLASS
:
1359 dip
->mixer_class
= ESO_MONITOR_CLASS
;
1360 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1361 strcpy(dip
->label
.name
, AudioCmonitor
);
1362 dip
->type
= AUDIO_MIXER_CLASS
;
1365 case ESO_RECORD_VOL
:
1366 dip
->mixer_class
= ESO_RECORD_CLASS
;
1367 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1368 strcpy(dip
->label
.name
, AudioNrecord
);
1369 dip
->type
= AUDIO_MIXER_VALUE
;
1370 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
1372 case ESO_RECORD_SOURCE
:
1373 dip
->mixer_class
= ESO_RECORD_CLASS
;
1374 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1375 strcpy(dip
->label
.name
, AudioNsource
);
1376 dip
->type
= AUDIO_MIXER_ENUM
;
1377 dip
->un
.e
.num_mem
= 4;
1378 strcpy(dip
->un
.e
.member
[0].label
.name
, AudioNmicrophone
);
1379 dip
->un
.e
.member
[0].ord
= ESO_MIXREG_ERS_MIC
;
1380 strcpy(dip
->un
.e
.member
[1].label
.name
, AudioNline
);
1381 dip
->un
.e
.member
[1].ord
= ESO_MIXREG_ERS_LINE
;
1382 strcpy(dip
->un
.e
.member
[2].label
.name
, AudioNcd
);
1383 dip
->un
.e
.member
[2].ord
= ESO_MIXREG_ERS_CD
;
1384 strcpy(dip
->un
.e
.member
[3].label
.name
, AudioNmixerout
);
1385 dip
->un
.e
.member
[3].ord
= ESO_MIXREG_ERS_MIXER
;
1387 case ESO_DAC_REC_VOL
:
1388 dip
->mixer_class
= ESO_RECORD_CLASS
;
1389 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1390 strcpy(dip
->label
.name
, AudioNdac
);
1391 dip
->type
= AUDIO_MIXER_VALUE
;
1392 dip
->un
.v
.num_channels
= 2;
1393 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
1395 case ESO_MIC_REC_VOL
:
1396 dip
->mixer_class
= ESO_RECORD_CLASS
;
1397 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1398 strcpy(dip
->label
.name
, AudioNmicrophone
);
1399 dip
->type
= AUDIO_MIXER_VALUE
;
1400 dip
->un
.v
.num_channels
= 2;
1401 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
1403 case ESO_LINE_REC_VOL
:
1404 dip
->mixer_class
= ESO_RECORD_CLASS
;
1405 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1406 strcpy(dip
->label
.name
, AudioNline
);
1407 dip
->type
= AUDIO_MIXER_VALUE
;
1408 dip
->un
.v
.num_channels
= 2;
1409 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
1411 case ESO_SYNTH_REC_VOL
:
1412 dip
->mixer_class
= ESO_RECORD_CLASS
;
1413 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1414 strcpy(dip
->label
.name
, AudioNfmsynth
);
1415 dip
->type
= AUDIO_MIXER_VALUE
;
1416 dip
->un
.v
.num_channels
= 2;
1417 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
1419 case ESO_MONO_REC_VOL
:
1420 dip
->mixer_class
= ESO_RECORD_CLASS
;
1421 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1422 strcpy(dip
->label
.name
, "mono_in");
1423 dip
->type
= AUDIO_MIXER_VALUE
;
1424 dip
->un
.v
.num_channels
= 1; /* No lies */
1425 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
1427 case ESO_CD_REC_VOL
:
1428 dip
->mixer_class
= ESO_RECORD_CLASS
;
1429 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1430 strcpy(dip
->label
.name
, AudioNcd
);
1431 dip
->type
= AUDIO_MIXER_VALUE
;
1432 dip
->un
.v
.num_channels
= 2;
1433 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
1435 case ESO_AUXB_REC_VOL
:
1436 dip
->mixer_class
= ESO_RECORD_CLASS
;
1437 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1438 strcpy(dip
->label
.name
, "auxb");
1439 dip
->type
= AUDIO_MIXER_VALUE
;
1440 dip
->un
.v
.num_channels
= 2;
1441 strcpy(dip
->un
.v
.units
.name
, AudioNvolume
);
1443 case ESO_RECORD_CLASS
:
1444 dip
->mixer_class
= ESO_RECORD_CLASS
;
1445 dip
->next
= dip
->prev
= AUDIO_MIXER_LAST
;
1446 strcpy(dip
->label
.name
, AudioCrecord
);
1447 dip
->type
= AUDIO_MIXER_CLASS
;
1458 eso_allocmem(struct eso_softc
*sc
, size_t size
, size_t align
,
1459 size_t boundary
, int flags
, int direction
, struct eso_dma
*ed
)
1463 wait
= (flags
& M_NOWAIT
) ? BUS_DMA_NOWAIT
: BUS_DMA_WAITOK
;
1466 error
= bus_dmamem_alloc(ed
->ed_dmat
, ed
->ed_size
, align
, boundary
,
1467 ed
->ed_segs
, sizeof (ed
->ed_segs
) / sizeof (ed
->ed_segs
[0]),
1468 &ed
->ed_nsegs
, wait
);
1472 error
= bus_dmamem_map(ed
->ed_dmat
, ed
->ed_segs
, ed
->ed_nsegs
,
1473 ed
->ed_size
, &ed
->ed_kva
, wait
| BUS_DMA_COHERENT
);
1477 error
= bus_dmamap_create(ed
->ed_dmat
, ed
->ed_size
, 1, ed
->ed_size
, 0,
1482 error
= bus_dmamap_load(ed
->ed_dmat
, ed
->ed_map
, ed
->ed_kva
,
1483 ed
->ed_size
, NULL
, wait
|
1484 (direction
== AUMODE_RECORD
) ? BUS_DMA_READ
: BUS_DMA_WRITE
);
1491 bus_dmamap_destroy(ed
->ed_dmat
, ed
->ed_map
);
1493 bus_dmamem_unmap(ed
->ed_dmat
, ed
->ed_kva
, ed
->ed_size
);
1495 bus_dmamem_free(ed
->ed_dmat
, ed
->ed_segs
, ed
->ed_nsegs
);
1501 eso_freemem(struct eso_dma
*ed
)
1504 bus_dmamap_unload(ed
->ed_dmat
, ed
->ed_map
);
1505 bus_dmamap_destroy(ed
->ed_dmat
, ed
->ed_map
);
1506 bus_dmamem_unmap(ed
->ed_dmat
, ed
->ed_kva
, ed
->ed_size
);
1507 bus_dmamem_free(ed
->ed_dmat
, ed
->ed_segs
, ed
->ed_nsegs
);
1510 static struct eso_dma
*
1511 eso_kva2dma(const struct eso_softc
*sc
, const void *kva
)
1515 SLIST_FOREACH(p
, &sc
->sc_dmas
, ed_slist
) {
1516 if (KVADDR(p
) == kva
)
1520 panic("%s: kva2dma: bad kva: %p", sc
->sc_dev
.dv_xname
, kva
);
1525 eso_allocm(void *hdl
, int direction
, size_t size
, struct malloc_type
*type
,
1528 struct eso_softc
*sc
;
1534 if ((ed
= malloc(sizeof (*ed
), type
, flags
)) == NULL
)
1538 * Apparently the Audio 1 DMA controller's current address
1539 * register can't roll over a 64K address boundary, so we have to
1540 * take care of that ourselves. Similarly, the Audio 2 DMA
1541 * controller needs a 1M address boundary.
1543 if (direction
== AUMODE_RECORD
)
1546 boundary
= 0x100000;
1549 * XXX Work around allocation problems for Audio 1, which
1550 * XXX implements the 24 low address bits only, with
1551 * XXX machine-specific DMA tag use.
1555 * XXX Force allocation through the (ISA) SGMAP.
1557 if (direction
== AUMODE_RECORD
)
1558 ed
->ed_dmat
= alphabus_dma_get_tag(sc
->sc_dmat
, ALPHA_BUS_ISA
);
1560 #elif defined(amd64) || defined(i386)
1562 * XXX Force allocation through the ISA DMA tag.
1564 if (direction
== AUMODE_RECORD
)
1565 ed
->ed_dmat
= &isa_bus_dma_tag
;
1568 ed
->ed_dmat
= sc
->sc_dmat
;
1570 error
= eso_allocmem(sc
, size
, 32, boundary
, flags
, direction
, ed
);
1575 SLIST_INSERT_HEAD(&sc
->sc_dmas
, ed
, ed_slist
);
1581 eso_freem(void *hdl
, void *addr
, struct malloc_type
*type
)
1583 struct eso_softc
*sc
;
1587 p
= eso_kva2dma(sc
, addr
);
1589 SLIST_REMOVE(&sc
->sc_dmas
, p
, eso_dma
, ed_slist
);
1595 eso_round_buffersize(void *hdl
, int direction
, size_t bufsize
)
1600 * The playback DMA buffer size on the Solo-1 is limited to 0xfff0
1601 * bytes. This is because IO_A2DMAC is a two byte value
1602 * indicating the literal byte count, and the 4 least significant
1603 * bits are read-only. Zero is not used as a special case for
1606 * For recording, DMAC_DMAC is the byte count - 1, so 0x10000 can
1609 maxsize
= (direction
== AUMODE_PLAY
) ? 0xfff0 : 0x10000;
1611 if (bufsize
> maxsize
)
1618 eso_mappage(void *hdl
, void *addr
, off_t offs
, int prot
)
1620 struct eso_softc
*sc
;
1626 ed
= eso_kva2dma(sc
, addr
);
1628 return bus_dmamem_mmap(ed
->ed_dmat
, ed
->ed_segs
, ed
->ed_nsegs
,
1629 offs
, prot
, BUS_DMA_WAITOK
);
1634 eso_get_props(void *hdl
)
1637 return AUDIO_PROP_MMAP
| AUDIO_PROP_INDEPENDENT
|
1638 AUDIO_PROP_FULLDUPLEX
;
1642 eso_trigger_output(void *hdl
, void *start
, void *end
, int blksize
,
1643 void (*intr
)(void *), void *arg
, const audio_params_t
*param
)
1645 struct eso_softc
*sc
;
1651 "%s: trigger_output: start %p, end %p, blksize %d, intr %p(%p)\n",
1652 device_xname(&sc
->sc_dev
), start
, end
, blksize
, intr
, arg
));
1653 DPRINTF(("%s: param: rate %u, encoding %u, precision %u, channels %u\n",
1654 device_xname(&sc
->sc_dev
), param
->sample_rate
, param
->encoding
,
1655 param
->precision
, param
->channels
));
1657 /* Find DMA buffer. */
1658 ed
= eso_kva2dma(sc
, start
);
1659 DPRINTF(("%s: dmaaddr %lx\n",
1660 device_xname(&sc
->sc_dev
), (unsigned long)DMAADDR(ed
)));
1662 sc
->sc_pintr
= intr
;
1665 /* Compute drain timeout. */
1666 sc
->sc_pdrain
= (blksize
* NBBY
* hz
) /
1667 (param
->sample_rate
* param
->channels
*
1668 param
->precision
) + 2; /* slop */
1670 /* DMA transfer count (in `words'!) reload using 2's complement. */
1671 blksize
= -(blksize
>> 1);
1672 eso_write_mixreg(sc
, ESO_MIXREG_A2TCRLO
, blksize
& 0xff);
1673 eso_write_mixreg(sc
, ESO_MIXREG_A2TCRHI
, blksize
>> 8);
1675 /* Update DAC to reflect DMA count and audio parameters. */
1676 /* Note: we cache A2C2 in order to avoid r/m/w at interrupt time. */
1677 if (param
->precision
== 16)
1678 sc
->sc_a2c2
|= ESO_MIXREG_A2C2_16BIT
;
1680 sc
->sc_a2c2
&= ~ESO_MIXREG_A2C2_16BIT
;
1681 if (param
->channels
== 2)
1682 sc
->sc_a2c2
|= ESO_MIXREG_A2C2_STEREO
;
1684 sc
->sc_a2c2
&= ~ESO_MIXREG_A2C2_STEREO
;
1685 if (param
->encoding
== AUDIO_ENCODING_SLINEAR_BE
||
1686 param
->encoding
== AUDIO_ENCODING_SLINEAR_LE
)
1687 sc
->sc_a2c2
|= ESO_MIXREG_A2C2_SIGNED
;
1689 sc
->sc_a2c2
&= ~ESO_MIXREG_A2C2_SIGNED
;
1691 sc
->sc_a2c2
|= ESO_MIXREG_A2C2_IRQM
;
1692 eso_write_mixreg(sc
, ESO_MIXREG_A2C2
, sc
->sc_a2c2
);
1694 /* Set up DMA controller. */
1695 bus_space_write_4(sc
->sc_iot
, sc
->sc_ioh
, ESO_IO_A2DMAA
,
1697 bus_space_write_2(sc
->sc_iot
, sc
->sc_ioh
, ESO_IO_A2DMAC
,
1698 (uint8_t *)end
- (uint8_t *)start
);
1699 bus_space_write_1(sc
->sc_iot
, sc
->sc_ioh
, ESO_IO_A2DMAM
,
1700 ESO_IO_A2DMAM_DMAENB
| ESO_IO_A2DMAM_AUTO
);
1703 a2c1
= eso_read_mixreg(sc
, ESO_MIXREG_A2C1
);
1704 a2c1
&= ~ESO_MIXREG_A2C1_RESV0
; /* Paranoia? XXX bit 5 */
1705 a2c1
|= ESO_MIXREG_A2C1_FIFOENB
| ESO_MIXREG_A2C1_DMAENB
|
1706 ESO_MIXREG_A2C1_AUTO
;
1707 eso_write_mixreg(sc
, ESO_MIXREG_A2C1
, a2c1
);
1713 eso_trigger_input(void *hdl
, void *start
, void *end
, int blksize
,
1714 void (*intr
)(void *), void *arg
, const audio_params_t
*param
)
1716 struct eso_softc
*sc
;
1722 "%s: trigger_input: start %p, end %p, blksize %d, intr %p(%p)\n",
1723 device_xname(&sc
->sc_dev
), start
, end
, blksize
, intr
, arg
));
1724 DPRINTF(("%s: param: rate %u, encoding %u, precision %u, channels %u\n",
1725 device_xname(&sc
->sc_dev
), param
->sample_rate
, param
->encoding
,
1726 param
->precision
, param
->channels
));
1729 * If we failed to configure the Audio 1 DMA controller, bail here
1730 * while retaining availability of the DAC direction (in Audio 2).
1732 if (!sc
->sc_dmac_configured
)
1735 /* Find DMA buffer. */
1736 ed
= eso_kva2dma(sc
, start
);
1737 DPRINTF(("%s: dmaaddr %lx\n",
1738 device_xname(&sc
->sc_dev
), (unsigned long)DMAADDR(ed
)));
1740 sc
->sc_rintr
= intr
;
1743 /* Compute drain timeout. */
1744 sc
->sc_rdrain
= (blksize
* NBBY
* hz
) /
1745 (param
->sample_rate
* param
->channels
*
1746 param
->precision
) + 2; /* slop */
1748 /* Set up ADC DMA converter parameters. */
1749 actl
= eso_read_ctlreg(sc
, ESO_CTLREG_ACTL
);
1750 if (param
->channels
== 2) {
1751 actl
&= ~ESO_CTLREG_ACTL_MONO
;
1752 actl
|= ESO_CTLREG_ACTL_STEREO
;
1754 actl
&= ~ESO_CTLREG_ACTL_STEREO
;
1755 actl
|= ESO_CTLREG_ACTL_MONO
;
1757 eso_write_ctlreg(sc
, ESO_CTLREG_ACTL
, actl
);
1759 /* Set up Transfer Type: maybe move to attach time? */
1760 eso_write_ctlreg(sc
, ESO_CTLREG_A1TT
, ESO_CTLREG_A1TT_DEMAND4
);
1762 /* DMA transfer count reload using 2's complement. */
1764 eso_write_ctlreg(sc
, ESO_CTLREG_A1TCRLO
, blksize
& 0xff);
1765 eso_write_ctlreg(sc
, ESO_CTLREG_A1TCRHI
, blksize
>> 8);
1767 /* Set up and enable Audio 1 DMA FIFO. */
1768 a1c1
= ESO_CTLREG_A1C1_RESV1
| ESO_CTLREG_A1C1_FIFOENB
;
1769 if (param
->precision
== 16)
1770 a1c1
|= ESO_CTLREG_A1C1_16BIT
;
1771 if (param
->channels
== 2)
1772 a1c1
|= ESO_CTLREG_A1C1_STEREO
;
1774 a1c1
|= ESO_CTLREG_A1C1_MONO
;
1775 if (param
->encoding
== AUDIO_ENCODING_SLINEAR_BE
||
1776 param
->encoding
== AUDIO_ENCODING_SLINEAR_LE
)
1777 a1c1
|= ESO_CTLREG_A1C1_SIGNED
;
1778 eso_write_ctlreg(sc
, ESO_CTLREG_A1C1
, a1c1
);
1780 /* Set up ADC IRQ/DRQ parameters. */
1781 eso_write_ctlreg(sc
, ESO_CTLREG_LAIC
,
1782 ESO_CTLREG_LAIC_PINENB
| ESO_CTLREG_LAIC_EXTENB
);
1783 eso_write_ctlreg(sc
, ESO_CTLREG_DRQCTL
,
1784 ESO_CTLREG_DRQCTL_ENB1
| ESO_CTLREG_DRQCTL_EXTENB
);
1786 /* Set up and enable DMA controller. */
1787 bus_space_write_1(sc
->sc_dmac_iot
, sc
->sc_dmac_ioh
, ESO_DMAC_CLEAR
, 0);
1788 bus_space_write_1(sc
->sc_dmac_iot
, sc
->sc_dmac_ioh
, ESO_DMAC_MASK
,
1789 ESO_DMAC_MASK_MASK
);
1790 bus_space_write_1(sc
->sc_dmac_iot
, sc
->sc_dmac_ioh
, ESO_DMAC_MODE
,
1791 DMA37MD_WRITE
| DMA37MD_LOOP
| DMA37MD_DEMAND
);
1792 bus_space_write_4(sc
->sc_dmac_iot
, sc
->sc_dmac_ioh
, ESO_DMAC_DMAA
,
1794 bus_space_write_2(sc
->sc_dmac_iot
, sc
->sc_dmac_ioh
, ESO_DMAC_DMAC
,
1795 (uint8_t *)end
- (uint8_t *)start
- 1);
1796 bus_space_write_1(sc
->sc_dmac_iot
, sc
->sc_dmac_ioh
, ESO_DMAC_MASK
, 0);
1799 eso_write_ctlreg(sc
, ESO_CTLREG_A1C2
,
1800 ESO_CTLREG_A1C2_DMAENB
| ESO_CTLREG_A1C2_READ
|
1801 ESO_CTLREG_A1C2_AUTO
| ESO_CTLREG_A1C2_ADC
);
1807 * Mixer utility functions.
1810 eso_set_recsrc(struct eso_softc
*sc
, unsigned int recsrc
)
1815 di
.index
= ESO_RECORD_SOURCE
;
1816 if (eso_query_devinfo(sc
, &di
) != 0)
1817 panic("eso_set_recsrc: eso_query_devinfo failed");
1819 for (i
= 0; i
< di
.un
.e
.num_mem
; i
++) {
1820 if (recsrc
== di
.un
.e
.member
[i
].ord
) {
1821 eso_write_mixreg(sc
, ESO_MIXREG_ERS
, recsrc
);
1822 sc
->sc_recsrc
= recsrc
;
1831 eso_set_monooutsrc(struct eso_softc
*sc
, unsigned int monooutsrc
)
1837 di
.index
= ESO_MONOOUT_SOURCE
;
1838 if (eso_query_devinfo(sc
, &di
) != 0)
1839 panic("eso_set_monooutsrc: eso_query_devinfo failed");
1841 for (i
= 0; i
< di
.un
.e
.num_mem
; i
++) {
1842 if (monooutsrc
== di
.un
.e
.member
[i
].ord
) {
1843 mpm
= eso_read_mixreg(sc
, ESO_MIXREG_MPM
);
1844 mpm
&= ~ESO_MIXREG_MPM_MOMASK
;
1846 eso_write_mixreg(sc
, ESO_MIXREG_MPM
, mpm
);
1847 sc
->sc_monooutsrc
= monooutsrc
;
1856 eso_set_monoinbypass(struct eso_softc
*sc
, unsigned int monoinbypass
)
1862 di
.index
= ESO_MONOIN_BYPASS
;
1863 if (eso_query_devinfo(sc
, &di
) != 0)
1864 panic("eso_set_monoinbypass: eso_query_devinfo failed");
1866 for (i
= 0; i
< di
.un
.e
.num_mem
; i
++) {
1867 if (monoinbypass
== di
.un
.e
.member
[i
].ord
) {
1868 mpm
= eso_read_mixreg(sc
, ESO_MIXREG_MPM
);
1869 mpm
&= ~(ESO_MIXREG_MPM_MOMASK
| ESO_MIXREG_MPM_RESV0
);
1870 mpm
|= (monoinbypass
? ESO_MIXREG_MPM_MIBYPASS
: 0);
1871 eso_write_mixreg(sc
, ESO_MIXREG_MPM
, mpm
);
1872 sc
->sc_monoinbypass
= monoinbypass
;
1881 eso_set_preamp(struct eso_softc
*sc
, unsigned int preamp
)
1887 di
.index
= ESO_MIC_PREAMP
;
1888 if (eso_query_devinfo(sc
, &di
) != 0)
1889 panic("eso_set_preamp: eso_query_devinfo failed");
1891 for (i
= 0; i
< di
.un
.e
.num_mem
; i
++) {
1892 if (preamp
== di
.un
.e
.member
[i
].ord
) {
1893 mpm
= eso_read_mixreg(sc
, ESO_MIXREG_MPM
);
1894 mpm
&= ~(ESO_MIXREG_MPM_PREAMP
| ESO_MIXREG_MPM_RESV0
);
1895 mpm
|= (preamp
? ESO_MIXREG_MPM_PREAMP
: 0);
1896 eso_write_mixreg(sc
, ESO_MIXREG_MPM
, mpm
);
1897 sc
->sc_preamp
= preamp
;
1906 * Reload Master Volume and Mute values in softc from mixer; used when
1907 * those have previously been invalidated by use of hardware volume controls.
1910 eso_reload_master_vol(struct eso_softc
*sc
)
1914 mv
= eso_read_mixreg(sc
, ESO_MIXREG_LMVM
);
1915 sc
->sc_gain
[ESO_MASTER_VOL
][ESO_LEFT
] =
1916 (mv
& ~ESO_MIXREG_LMVM_MUTE
) << 2;
1917 mv
= eso_read_mixreg(sc
, ESO_MIXREG_LMVM
);
1918 sc
->sc_gain
[ESO_MASTER_VOL
][ESO_RIGHT
] =
1919 (mv
& ~ESO_MIXREG_RMVM_MUTE
) << 2;
1920 /* Currently both channels are muted simultaneously; either is OK. */
1921 sc
->sc_mvmute
= (mv
& ESO_MIXREG_RMVM_MUTE
) != 0;
1925 eso_set_gain(struct eso_softc
*sc
, unsigned int port
)
1927 uint8_t mixreg
, tmp
;
1930 case ESO_DAC_PLAY_VOL
:
1931 mixreg
= ESO_MIXREG_PVR_A2
;
1933 case ESO_MIC_PLAY_VOL
:
1934 mixreg
= ESO_MIXREG_PVR_MIC
;
1936 case ESO_LINE_PLAY_VOL
:
1937 mixreg
= ESO_MIXREG_PVR_LINE
;
1939 case ESO_SYNTH_PLAY_VOL
:
1940 mixreg
= ESO_MIXREG_PVR_SYNTH
;
1942 case ESO_CD_PLAY_VOL
:
1943 mixreg
= ESO_MIXREG_PVR_CD
;
1945 case ESO_AUXB_PLAY_VOL
:
1946 mixreg
= ESO_MIXREG_PVR_AUXB
;
1949 case ESO_DAC_REC_VOL
:
1950 mixreg
= ESO_MIXREG_RVR_A2
;
1952 case ESO_MIC_REC_VOL
:
1953 mixreg
= ESO_MIXREG_RVR_MIC
;
1955 case ESO_LINE_REC_VOL
:
1956 mixreg
= ESO_MIXREG_RVR_LINE
;
1958 case ESO_SYNTH_REC_VOL
:
1959 mixreg
= ESO_MIXREG_RVR_SYNTH
;
1961 case ESO_CD_REC_VOL
:
1962 mixreg
= ESO_MIXREG_RVR_CD
;
1964 case ESO_AUXB_REC_VOL
:
1965 mixreg
= ESO_MIXREG_RVR_AUXB
;
1967 case ESO_MONO_PLAY_VOL
:
1968 mixreg
= ESO_MIXREG_PVR_MONO
;
1970 case ESO_MONO_REC_VOL
:
1971 mixreg
= ESO_MIXREG_RVR_MONO
;
1974 case ESO_PCSPEAKER_VOL
:
1975 /* Special case - only 3-bit, mono, and reserved bits. */
1976 tmp
= eso_read_mixreg(sc
, ESO_MIXREG_PCSVR
);
1977 tmp
&= ESO_MIXREG_PCSVR_RESV
;
1978 /* Map bits 7:5 -> 2:0. */
1979 tmp
|= (sc
->sc_gain
[port
][ESO_LEFT
] >> 5);
1980 eso_write_mixreg(sc
, ESO_MIXREG_PCSVR
, tmp
);
1983 case ESO_MASTER_VOL
:
1984 /* Special case - separate regs, and 6-bit precision. */
1985 /* Map bits 7:2 -> 5:0, reflect mute settings. */
1986 eso_write_mixreg(sc
, ESO_MIXREG_LMVM
,
1987 (sc
->sc_gain
[port
][ESO_LEFT
] >> 2) |
1988 (sc
->sc_mvmute
? ESO_MIXREG_LMVM_MUTE
: 0x00));
1989 eso_write_mixreg(sc
, ESO_MIXREG_RMVM
,
1990 (sc
->sc_gain
[port
][ESO_RIGHT
] >> 2) |
1991 (sc
->sc_mvmute
? ESO_MIXREG_RMVM_MUTE
: 0x00));
1994 case ESO_SPATIALIZER
:
1995 /* Special case - only `mono', and higher precision. */
1996 eso_write_mixreg(sc
, ESO_MIXREG_SPATLVL
,
1997 sc
->sc_gain
[port
][ESO_LEFT
]);
2000 case ESO_RECORD_VOL
:
2001 /* Very Special case, controller register. */
2002 eso_write_ctlreg(sc
, ESO_CTLREG_RECLVL
,ESO_4BIT_GAIN_TO_STEREO(
2003 sc
->sc_gain
[port
][ESO_LEFT
], sc
->sc_gain
[port
][ESO_RIGHT
]));
2008 panic("eso_set_gain: bad port %u", port
);
2015 eso_write_mixreg(sc
, mixreg
, ESO_4BIT_GAIN_TO_STEREO(
2016 sc
->sc_gain
[port
][ESO_LEFT
], sc
->sc_gain
[port
][ESO_RIGHT
]));