diff options
author | Jason Wright <jason@cvs.openbsd.org> | 1999-06-06 04:48:26 +0000 |
---|---|---|
committer | Jason Wright <jason@cvs.openbsd.org> | 1999-06-06 04:48:26 +0000 |
commit | 614eab8a00a236c50ae5eea41829f8e0641b6655 (patch) | |
tree | 8bef045b4bd93798b51c4126941721c2e3cd0c83 | |
parent | 912ec719ecb908d570ddcea439c18d2da32510b4 (diff) |
First cut at SUNW,CS4231 audio driver (ss4/ss5). This driver is output-only
at the moment.
-rw-r--r-- | share/man/man4/man4.sparc/Makefile | 8 | ||||
-rw-r--r-- | share/man/man4/man4.sparc/audiocs.4 | 66 | ||||
-rw-r--r-- | sys/arch/sparc/conf/GENERIC | 5 | ||||
-rw-r--r-- | sys/arch/sparc/conf/GENERIC_SCSI3 | 5 | ||||
-rw-r--r-- | sys/arch/sparc/conf/SUN4M | 5 | ||||
-rw-r--r-- | sys/arch/sparc/conf/files.sparc | 6 | ||||
-rw-r--r-- | sys/arch/sparc/dev/cs4231.c | 1526 | ||||
-rw-r--r-- | sys/arch/sparc/dev/cs4231reg.h | 439 | ||||
-rw-r--r-- | sys/arch/sparc/dev/cs4231var.h | 84 |
9 files changed, 2136 insertions, 8 deletions
diff --git a/share/man/man4/man4.sparc/Makefile b/share/man/man4/man4.sparc/Makefile index 5c5423f4d29..796a3a1a144 100644 --- a/share/man/man4/man4.sparc/Makefile +++ b/share/man/man4/man4.sparc/Makefile @@ -1,10 +1,10 @@ # from: @(#)Makefile 8.2 (Berkeley) 2/16/94 -# $Id: Makefile,v 1.12 1999/04/18 12:36:58 jason Exp $ +# $Id: Makefile,v 1.13 1999/06/06 04:48:24 jason Exp $ MAN= intro.4 -MAN+= audioamd.4 be.4 bwtwo.4 cgtwo.4 cgthree.4 cgfour.4 cgsix.4 cgeight.4 -MAN+= cgfourteen.4 esp.4 fd.4 hme.4 ie.4 kbd.4 le.4 magma.4 mem.4 ms.4 -MAN+= openprom.4 qe.4 qec.4 si.4 spif.4 sw.4 tcx.4 xbox.4 xd.4 xy.4 zs.4 +MAN+= audioamd.4 audiocs.4 be.4 bwtwo.4 cgtwo.4 cgthree.4 cgfour.4 cgsix.4 +MAN+= cgeight.4 cgfourteen.4 esp.4 fd.4 hme.4 ie.4 kbd.4 le.4 magma.4 mem.4 +MAN+= ms.4 openprom.4 qe.4 qec.4 si.4 spif.4 sw.4 tcx.4 xbox.4 xd.4 xy.4 zs.4 MLINKS= mem.4 kmem.4 MANSUBDIR=/sparc diff --git a/share/man/man4/man4.sparc/audiocs.4 b/share/man/man4/man4.sparc/audiocs.4 new file mode 100644 index 00000000000..f866cb17ec9 --- /dev/null +++ b/share/man/man4/man4.sparc/audiocs.4 @@ -0,0 +1,66 @@ +.\" $OpenBSD: audiocs.4,v 1.1 1999/06/06 04:48:25 jason Exp $ +.\" +.\" Copyright (c) 1999 Jason L. Wright (jason@thought.net) +.\" All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by Jason L. Wright +.\" 4. The name of the author may not be used to endorse or promote products +.\" derived from this software without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR +.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED +.\" WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE +.\" DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, +.\" INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES +.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR +.\" SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, +.\" STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN +.\" ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE +.\" POSSIBILITY OF SUCH DAMAGE. +.\" +.Dd June 5, 1999 +.Dt AUDIOCS 4 sparc +.Os +.Sh NAME +.Nm audiocs +.Nd SPARC CS4231 audio interface +.Sh SYNOPSIS +.Cd "audiocs0 at sbus0 slot ? offset ? " Pq "sun4m" +.Cd "audio* at audiocs?" +.Sh DESCRIPTION +The +.Nm +device uses the +.Tn Crystal Semiconductor +CS4231A +Parallel Interface, Multimedia Audio Codec +chip to implement the audio device interface described in +.Xr audio 4 . +This device is found onboard on some sun4m models, and is available +as an option card for others. +.Pp +Audio capture is currently not supported. +The +.Nm +has a maximum precision of 16 bits and has both stereo and monoaural outputs. +The output ports are: the internal speaker, line, and headphones. +.Sh SEE ALSO +.Xr ioctl 2 , +.Xr audio 4 +.Sh HISTORY +.Ox +support for +.Nm +first appeared in +.Ox 2.6 . diff --git a/sys/arch/sparc/conf/GENERIC b/sys/arch/sparc/conf/GENERIC index b4148070dcc..646c38223e1 100644 --- a/sys/arch/sparc/conf/GENERIC +++ b/sys/arch/sparc/conf/GENERIC @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC,v 1.41 1999/04/18 03:24:22 jason Exp $ +# $OpenBSD: GENERIC,v 1.42 1999/06/06 04:48:23 jason Exp $ # $NetBSD: GENERIC,v 1.48 1997/08/23 19:19:01 mjacob Exp $ # Machine architecture; required by config(8) @@ -46,6 +46,9 @@ audioamd0 at obio0 # sun4m audioamd0 at sbus0 slot ? offset ? # sun4m audio* at audioamd? +audiocs0 at sbus0 slot ? offset ? # sun4m +audio* at audiocs? + auxreg0 at mainbus0 # sun4c auxreg0 at obio0 # sun4m diff --git a/sys/arch/sparc/conf/GENERIC_SCSI3 b/sys/arch/sparc/conf/GENERIC_SCSI3 index 16fa695365e..ce2430079e3 100644 --- a/sys/arch/sparc/conf/GENERIC_SCSI3 +++ b/sys/arch/sparc/conf/GENERIC_SCSI3 @@ -1,4 +1,4 @@ -# $OpenBSD: GENERIC_SCSI3,v 1.28 1999/04/18 03:24:22 jason Exp $ +# $OpenBSD: GENERIC_SCSI3,v 1.29 1999/06/06 04:48:24 jason Exp $ # $NetBSD: GENERIC,v 1.28.2.1 1996/07/02 23:55:22 jtc Exp $ # Machine architecture; required by config(8) @@ -45,6 +45,9 @@ audioamd0 at obio0 # sun4m audioamd0 at sbus0 slot ? offset ? # sun4m audio* at audioamd? +audiocs0 at sbus0 slot ? offset ? # sun4m +audio* at audiocs? + auxreg0 at mainbus0 # sun4c auxreg0 at obio0 # sun4m diff --git a/sys/arch/sparc/conf/SUN4M b/sys/arch/sparc/conf/SUN4M index cdfa783b6d6..57ec02380fd 100644 --- a/sys/arch/sparc/conf/SUN4M +++ b/sys/arch/sparc/conf/SUN4M @@ -1,4 +1,4 @@ -# $OpenBSD: SUN4M,v 1.30 1999/04/18 03:24:22 jason Exp $ +# $OpenBSD: SUN4M,v 1.31 1999/06/06 04:48:24 jason Exp $ # $NetBSD: GENERIC,v 1.28.2.1 1996/07/02 23:55:22 jtc Exp $ # Machine architecture; required by config(8) @@ -36,6 +36,9 @@ audioamd0 at obio0 # sun4m audioamd0 at sbus0 slot ? offset ? # sun4m audio* at audioamd? +audiocs0 at sbus0 slot ? offset ? # sun4m +audio* at audiocs? + auxreg0 at obio0 # sun4m # Power status and control register found on Sun4m systems diff --git a/sys/arch/sparc/conf/files.sparc b/sys/arch/sparc/conf/files.sparc index 6504c77553c..e47bfc2e4d8 100644 --- a/sys/arch/sparc/conf/files.sparc +++ b/sys/arch/sparc/conf/files.sparc @@ -1,4 +1,4 @@ -# $OpenBSD: files.sparc,v 1.29 1999/04/18 03:24:23 jason Exp $ +# $OpenBSD: files.sparc,v 1.30 1999/06/06 04:48:24 jason Exp $ # $NetBSD: files.sparc,v 1.44 1997/08/31 21:29:16 pk Exp $ # @(#)files.sparc 8.1 (Berkeley) 7/19/93 @@ -132,6 +132,10 @@ attach audioamd at mainbus, obio, sbus file arch/sparc/dev/amd7930.c audio file arch/sparc/sparc/amd7930intr.s audio +device audiocs: audio, auconv +attach audiocs at sbus +file arch/sparc/dev/cs4231.c audiocs + # Brooktree DAC attribute define bt_dac diff --git a/sys/arch/sparc/dev/cs4231.c b/sys/arch/sparc/dev/cs4231.c new file mode 100644 index 00000000000..f9f1533105a --- /dev/null +++ b/sys/arch/sparc/dev/cs4231.c @@ -0,0 +1,1526 @@ +/* $OpenBSD: cs4231.c,v 1.1 1999/06/06 04:48:24 jason Exp $ */ + +/* + * Copyright (c) 1999 Jason L. Wright (jason@thought.net) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Jason L. Wright + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Driver for CS4231 based audio found in some sun4m systems (cs4231) + * based on ideas from the S/Linux project and the NetBSD project. + */ + +#include "audio.h" +#if NAUDIO > 0 + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/errno.h> +#include <sys/ioctl.h> +#include <sys/device.h> +#include <sys/proc.h> +#include <sys/malloc.h> + +#include <machine/autoconf.h> +#include <sparc/cpu.h> +#include <sparc/sparc/cpuvar.h> +#include <sparc/dev/sbusvar.h> +#include <sparc/dev/dmareg.h> + +#include <sys/audioio.h> +#include <dev/audio_if.h> +#include <dev/auconv.h> +#include <sparc/dev/cs4231reg.h> +#include <sparc/dev/cs4231var.h> + +#define CSAUDIO_DAC_LVL 0 +#define CSAUDIO_LINE_IN_LVL 1 +#define CSAUDIO_MONO_LVL 2 +#define CSAUDIO_CD_LVL 3 +#define CSAUDIO_MONITOR_LVL 4 +#define CSAUDIO_OUTPUT_LVL 5 +#define CSAUDIO_LINE_IN_MUTE 6 +#define CSAUDIO_DAC_MUTE 7 +#define CSAUDIO_CD_MUTE 8 +#define CSAUDIO_MONO_MUTE 9 +#define CSAUDIO_MONITOR_MUTE 10 +#define CSAUDIO_OUTPUT_MUTE 11 +#define CSAUDIO_REC_LVL 12 +#define CSAUDIO_RECORD_SOURCE 13 +#define CSAUDIO_OUTPUT 14 +#define CSAUDIO_INPUT_CLASS 15 +#define CSAUDIO_OUTPUT_CLASS 16 +#define CSAUDIO_RECORD_CLASS 17 +#define CSAUDIO_MONITOR_CLASS 18 + +#define CSPORT_AUX2 0 +#define CSPORT_AUX1 1 +#define CSPORT_DAC 2 +#define CSPORT_LINEIN 3 +#define CSPORT_MONO 4 +#define CSPORT_MONITOR 5 +#define CSPORT_SPEAKER 6 +#define CSPORT_LINEOUT 7 +#define CSPORT_HEADPHONE 8 + +#define MIC_IN_PORT 0 +#define LINE_IN_PORT 1 +#define AUX1_IN_PORT 2 +#define DAC_IN_PORT 3 + +#ifdef AUDIO_DEBUG +#define DPRINTF(x) printf x +#else +#define DPRINTF(x) +#endif + +int cs4231_match __P((struct device *, void *, void *)); +void cs4231_attach __P((struct device *, struct device *, void *)); +int cs4231_hwintr __P((void *)); + +void cs4231_wait __P((struct cs4231_softc *)); +int cs4231_set_speed __P((struct cs4231_softc *, u_long *)); +void cs4231_mute_monitor __P((struct cs4231_softc *, int)); + +/* Audio interface */ +int cs4231_open __P((void *, int)); +void cs4231_close __P((void *)); +int cs4231_query_encoding __P((void *, struct audio_encoding *)); +int cs4231_set_params __P((void *, int, int, struct audio_params *, + struct audio_params *)); +int cs4231_round_blocksize __P((void *, int)); +int cs4231_commit_settings __P((void *)); +int cs4231_halt_output __P((void *)); +int cs4231_halt_input __P((void *)); +int cs4231_getdev __P((void *, struct audio_device *)); +int cs4231_set_port __P((void *, mixer_ctrl_t *)); +int cs4231_get_port __P((void *, mixer_ctrl_t *)); +int cs4231_query_devinfo __P((void *addr, mixer_devinfo_t *)); +void * cs4231_alloc __P((void *, u_long, int, int)); +void cs4231_free __P((void *, void *, int)); +u_long cs4231_round_buffersize __P((void *, u_long)); +int cs4231_get_props __P((void *)); +int cs4231_trigger_output __P((void *, void *, void *, int, + void (*intr)__P((void *)), void *arg, struct audio_params *)); +int cs4231_trigger_input __P((void *, void *, void *, int, + void (*intr)__P((void *)), void *arg, struct audio_params *)); + +struct audio_hw_if cs4231_sa_hw_if = { + cs4231_open, + cs4231_close, + 0, + cs4231_query_encoding, + cs4231_set_params, + cs4231_round_blocksize, + cs4231_commit_settings, + 0, + 0, + 0, + 0, + cs4231_halt_output, + cs4231_halt_input, + 0, + cs4231_getdev, + 0, + cs4231_set_port, + cs4231_get_port, + cs4231_query_devinfo, + cs4231_alloc, + cs4231_free, + cs4231_round_buffersize, + 0, + cs4231_get_props, + cs4231_trigger_output, + cs4231_trigger_input +}; + +struct cfattach audiocs_ca = { + sizeof (struct cs4231_softc), cs4231_match, cs4231_attach +}; + +struct cfdriver audiocs_cd = { + NULL, "audiocs", DV_DULL +}; + +struct audio_device cs4231_device = { + "SUNW,CS4231", + "a", /* XXX b for ultra */ + "onboard1", /* XXX unknown for ultra */ +}; + +int +cs4231_match(parent, vcf, aux) + struct device *parent; + void *vcf, *aux; +{ + struct cfdata *cf = vcf; + struct confargs *ca = aux; + register struct romaux *ra = &ca->ca_ra; + + if (strcmp(cf->cf_driver->cd_name, ra->ra_name) && + strcmp("SUNW,CS4231", ra->ra_name)) { + return (0); + } + return (1); +} + +void +cs4231_attach(parent, self, aux) + struct device *parent, *self; + void *aux; +{ + struct confargs *ca = aux; + struct cs4231_softc *sc = (struct cs4231_softc *)self; + int pri; + + if (ca->ca_ra.ra_nintr != 1) { + printf(": expected 1 interrupt, got %d\n", ca->ca_ra.ra_nintr); + return; + } + pri = ca->ca_ra.ra_intr[0].int_pri; + + if (ca->ca_ra.ra_nreg != 1) { + printf(": expected 1 register set, got %d\n", + ca->ca_ra.ra_nreg); + return; + } + sc->sc_regs = mapiodev(&(ca->ca_ra.ra_reg[0]), 0, + ca->ca_ra.ra_reg[0].rr_len); + + sc->sc_node = ca->ca_ra.ra_node; + + sc->sc_burst = getpropint(ca->ca_ra.ra_node, "burst-sizes", -1); + if (sc->sc_burst == -1) + sc->sc_burst = ((struct sbus_softc *)parent)->sc_burst; + + /* Clamp at parent's burst sizes */ + sc->sc_burst &= ((struct sbus_softc *)parent)->sc_burst; + + sbus_establish(&sc->sc_sd, &sc->sc_dev); + + sc->sc_hwih.ih_fun = cs4231_hwintr; + sc->sc_hwih.ih_arg = sc; + intr_establish(ca->ca_ra.ra_intr[0].int_pri, &sc->sc_hwih); + + printf(" pri %d, softpri %d\n", pri, PIL_AUSOFT); + + evcnt_attach(&sc->sc_dev, "intr", &sc->sc_intrcnt); + + audio_attach_mi(&cs4231_sa_hw_if, sc, &sc->sc_dev); + + sc->sc_out_port = CSPORT_SPEAKER; + sc->sc_volume[CSPORT_SPEAKER].left = 192; + sc->sc_volume[CSPORT_SPEAKER].right = 192; +} + +/* + * Hardware interrupt handler + */ +int +cs4231_hwintr(v) + void *v; +{ + struct cs4231_softc *sc = (struct cs4231_softc *)v; + struct cs4231_regs *regs = sc->sc_regs; + u_int32_t csr; + u_int8_t reg, status; + struct cs_dma *p; + int r = 0; + + csr = regs->dma_csr; + status = regs->status; + if (status & (CS_STATUS_INT | CS_STATUS_SER)) { + regs->iar = CS_IAR_AFS; + reg = regs->idr; + if (reg & CS_AFS_PI) { + regs->iar = CS_IAR_PBLB; + regs->idr = 0xff; + regs->iar = CS_IAR_PBUB; + regs->idr = 0xff; + } + regs->status = 0; + } + + regs->dma_csr = csr; + if (csr & (CS_DMACSR_PI|CS_DMACSR_PMI|CS_DMACSR_PIE|CS_DMACSR_PD)) + r = 1; + + if (csr & CS_DMACSR_PM) { + u_int32_t nextaddr, togo; + + p = sc->sc_nowplaying; + togo = sc->sc_playsegsz - sc->sc_playcnt; + if (togo == 0) { + nextaddr = (u_int32_t)p->addr_dva; + sc->sc_playcnt = togo = sc->sc_blksz; + } else { + nextaddr = regs->dma_pnva + sc->sc_blksz; + if (togo > sc->sc_blksz) + togo = sc->sc_blksz; + sc->sc_playcnt += togo; + } + + regs->dma_pnva = nextaddr; + regs->dma_pnc = togo; + if (sc->sc_pintr != NULL) + (*sc->sc_pintr)(sc->sc_parg); + r = 1; + } + + if (csr & CS_DMACSR_CI) { + if (sc->sc_rintr != NULL) { + r = 1; + (*sc->sc_rintr)(sc->sc_rarg); + } + } + + return (r); +} + +void +cs4231_mute_monitor(sc, mute) + struct cs4231_softc *sc; + int mute; +{ + struct cs4231_regs *regs = sc->sc_regs; + + if (mute) { + regs->iar = CS_IAR_LDACOUT; /* left dac */ + regs->idr |= CS_LDACOUT_LDM; + regs->iar = CS_IAR_RDACOUT; /* right dac */ + regs->idr |= CS_RDACOUT_RDM; +#if 0 + regs->iar = CS_IAR_MONO; /* mono */ + regs->idr |= CS_MONO_MOM; +#endif + } + else { + regs->iar = CS_IAR_LDACOUT; /* left dac */ + regs->idr &= ~CS_LDACOUT_LDM; + regs->iar = CS_IAR_RDACOUT; /* right dac */ + regs->idr &= ~CS_RDACOUT_RDM; +#if 0 + regs->iar = CS_IAR_MONO; /* mono */ + regs->idr &= ~CS_MONO_MOM; +#endif + } +} + +int +cs4231_set_speed(sc, argp) + struct cs4231_softc *sc; + u_long *argp; + +{ + /* + * The available speeds are in the following table. Keep the speeds in + * the increasing order. + */ + typedef struct { + int speed; + u_char bits; + } speed_struct; + u_long arg = *argp; + + static speed_struct speed_table[] = { + {5510, (0 << 1) | CS_FSPB_C2SL_XTAL2}, + {5510, (0 << 1) | CS_FSPB_C2SL_XTAL2}, + {6620, (7 << 1) | CS_FSPB_C2SL_XTAL2}, + {8000, (0 << 1) | CS_FSPB_C2SL_XTAL1}, + {9600, (7 << 1) | CS_FSPB_C2SL_XTAL1}, + {11025, (1 << 1) | CS_FSPB_C2SL_XTAL2}, + {16000, (1 << 1) | CS_FSPB_C2SL_XTAL1}, + {18900, (2 << 1) | CS_FSPB_C2SL_XTAL2}, + {22050, (3 << 1) | CS_FSPB_C2SL_XTAL2}, + {27420, (2 << 1) | CS_FSPB_C2SL_XTAL1}, + {32000, (3 << 1) | CS_FSPB_C2SL_XTAL1}, + {33075, (6 << 1) | CS_FSPB_C2SL_XTAL2}, + {33075, (4 << 1) | CS_FSPB_C2SL_XTAL2}, + {44100, (5 << 1) | CS_FSPB_C2SL_XTAL2}, + {48000, (6 << 1) | CS_FSPB_C2SL_XTAL1}, + }; + + int i, n, selected = -1; + + n = sizeof(speed_table) / sizeof(speed_struct); + + if (arg < speed_table[0].speed) + selected = 0; + if (arg > speed_table[n - 1].speed) + selected = n - 1; + + for (i = 1; selected == -1 && i < n; i++) { + if (speed_table[i].speed == arg) + selected = i; + else if (speed_table[i].speed > arg) { + int diff1, diff2; + + diff1 = arg - speed_table[i - 1].speed; + diff2 = speed_table[i].speed - arg; + if (diff1 < diff2) + selected = i - 1; + else + selected = i; + } + } + + if (selected == -1) { + printf("%s: can't find speed\n", sc->sc_dev.dv_xname); + selected = 3; + } + + sc->sc_speed_bits = speed_table[selected].bits; + sc->sc_need_commit = 1; + *argp = speed_table[selected].speed; + + return (0); +} + +void +cs4231_wait(sc) + struct cs4231_softc *sc; +{ + struct cs4231_regs *regs = sc->sc_regs; + int tries; + + DELAY(100); + + regs->iar = ~(CS_IAR_MCE); + tries = CS_TIMEOUT; + while (regs->iar == CS_IAR_INIT && tries--) { + DELAY(100); + } + if (!tries) + printf("%s: waited too long to reset iar\n", + sc->sc_dev.dv_xname); + + regs->iar = CS_IAR_ERRINIT; + tries = CS_TIMEOUT; + while (regs->idr == CS_ERRINIT_ACI && tries--) { + DELAY(100); + } + if (!tries) + printf("%s: waited too long to reset errinit\n", + sc->sc_dev.dv_xname); +} + +/* + * Audio interface functions + */ +int +cs4231_open(addr, flags) + void *addr; + int flags; +{ + struct cs4231_softc *sc = addr; + struct cs4231_regs *regs = sc->sc_regs; + u_int8_t reg; + + if (sc->sc_open) + return (EBUSY); + sc->sc_open = 1; + sc->sc_locked = 0; + sc->sc_rintr = 0; + sc->sc_rarg = 0; + sc->sc_pintr = 0; + sc->sc_parg = 0; + + regs->dma_csr = CS_DMACSR_RESET; + DELAY(10); + regs->dma_csr = 0; + DELAY(10); + regs->dma_csr |= CS_DMACSR_CODEC_RESET; + + DELAY(20); + + regs->dma_csr &= ~(CS_DMACSR_CODEC_RESET); + regs->iar |= CS_IAR_MCE; + + cs4231_wait(sc); + + regs->iar = CS_IAR_MCE | CS_IAR_MODEID; + regs->idr = CS_MODEID_MODE2; + + regs->iar = CS_IAR_VID; + if ((regs->idr & CS_VID_CHIP_MASK) == CS_VID_CHIP_CS4231) { + switch (regs->idr & CS_VID_VER_MASK) { + case CS_VID_VER_CS4231A: + case CS_VID_VER_CS4231: + case CS_VID_VER_CS4232: + break; + default: + printf("%s: unknown CS version: %d\n", + sc->sc_dev.dv_xname, regs->idr & CS_VID_VER_MASK); + } + } + else { + printf("%s: unknown CS chip/version: %d/%d\n", + sc->sc_dev.dv_xname, regs->idr & CS_VID_CHIP_MASK, + regs->idr & CS_VID_VER_MASK); + } + + /* XXX TODO: setup some defaults */ + + regs->iar = ~(CS_IAR_MCE); + cs4231_wait(sc); + + regs->iar = CS_IAR_MCE | CS_IAR_IC; + reg = regs->idr; + regs->iar = CS_IAR_MCE | CS_IAR_IC; + regs->idr = reg & ~(CS_IC_CAL_CONV); + + regs->iar = ~(CS_IAR_MCE); + cs4231_wait(sc); + + regs->iar = CS_IAR_PC; + regs->idr |= CS_PC_HDPHMUTE | CS_PC_LINEMUTE; + regs->iar = CS_IAR_MONO; + regs->idr |= CS_MONO_MOM; + + switch (sc->sc_out_port) { + case CSPORT_HEADPHONE: + if (sc->mute[CSPORT_SPEAKER] == 0) { + regs->iar = CS_IAR_PC; + regs->idr &= ~CS_PC_HDPHMUTE; + } + break; + case CSPORT_SPEAKER: + if (sc->mute[CSPORT_SPEAKER] == 0) { + regs->iar = CS_IAR_MONO; + regs->idr &= ~CS_MONO_MOM; + } + break; + case CSPORT_LINEOUT: + if (sc->mute[CSPORT_SPEAKER] == 0) { + regs->iar = CS_IAR_PC; + regs->idr &= ~CS_PC_LINEMUTE; + } + break; + } + + regs->iar = CS_IAR_LDACOUT; + regs->idr &= ~CS_LDACOUT_LDA_MASK; + regs->idr |= (~(sc->sc_volume[CSPORT_SPEAKER].left >> 2)) & + CS_LDACOUT_LDA_MASK; + regs->iar = CS_IAR_RDACOUT; + regs->idr &= ~CS_RDACOUT_RDA_MASK; + regs->idr |= (~(sc->sc_volume[CSPORT_SPEAKER].right >> 2)) & + CS_RDACOUT_RDA_MASK; + + return (0); +} + +void +cs4231_close(addr) + void *addr; +{ + struct cs4231_softc *sc = addr; + + cs4231_halt_input(sc); + cs4231_halt_output(sc); + sc->sc_open = 0; +} + +int +cs4231_query_encoding(addr, fp) + void *addr; + struct audio_encoding *fp; +{ + int err = 0; + + switch (fp->index) { + case 0: + strcpy(fp->name, AudioEmulaw); + fp->encoding = AUDIO_ENCODING_ULAW; + fp->precision = 8; + fp->flags = 0; + break; + case 1: + strcpy(fp->name, AudioEalaw); + fp->encoding = AUDIO_ENCODING_ALAW; + fp->precision = 8; + fp->flags = 0; + break; + case 2: + strcpy(fp->name, AudioEslinear_le); + fp->encoding = AUDIO_ENCODING_SLINEAR_LE; + fp->precision = 16; + fp->flags = 0; + break; + case 3: + strcpy(fp->name, AudioEulinear); + fp->encoding = AUDIO_ENCODING_ULINEAR; + fp->precision = 8; + fp->flags = 0; + break; + case 4: + strcpy(fp->name, AudioEslinear_be); + fp->encoding = AUDIO_ENCODING_SLINEAR_BE; + fp->precision = 16; + fp->flags = 0; + break; + case 5: + strcpy(fp->name, AudioEslinear); + fp->encoding = AUDIO_ENCODING_SLINEAR; + fp->precision = 8; + fp->flags = AUDIO_ENCODINGFLAG_EMULATED; + break; + case 6: + strcpy(fp->name, AudioEulinear_le); + fp->encoding = AUDIO_ENCODING_ULINEAR_LE; + fp->precision = 16; + fp->flags = AUDIO_ENCODINGFLAG_EMULATED; + break; + case 7: + strcpy(fp->name, AudioEulinear_be); + fp->encoding = AUDIO_ENCODING_ULINEAR_BE; + fp->precision = 16; + fp->flags = AUDIO_ENCODINGFLAG_EMULATED; + break; + case 8: + strcpy(fp->name, AudioEadpcm); + fp->encoding = AUDIO_ENCODING_ADPCM; + fp->precision = 8; + fp->flags = 0; + break; + default: + err = EINVAL; + } + return (err); +} + +int +cs4231_set_params(addr, setmode, usemode, p, r) + void *addr; + int setmode, usemode; + struct audio_params *p, *r; +{ + struct cs4231_softc *sc = (struct cs4231_softc *)addr; + int err, bits, enc; + void (*pswcode) __P((void *, u_char *, int cnt)); + void (*rswcode) __P((void *, u_char *, int cnt)); + + enc = p->encoding; + pswcode = rswcode = 0; + switch (enc) { + case AUDIO_ENCODING_SLINEAR_LE: + if (p->precision == 8) { + enc = AUDIO_ENCODING_ULINEAR_LE; + pswcode = rswcode = change_sign8; + } + break; + case AUDIO_ENCODING_ULINEAR_LE: + if (p->precision == 16) { + enc = AUDIO_ENCODING_SLINEAR_LE; + pswcode = rswcode = change_sign16; + } + break; + case AUDIO_ENCODING_ULINEAR_BE: + if (p->precision == 16) { + enc = AUDIO_ENCODING_SLINEAR_BE; + pswcode = rswcode = change_sign16; + } + break; + } + + switch (enc) { + case AUDIO_ENCODING_ULAW: + bits = CS_CDF_FMT_ULAW >> 5; + break; + case AUDIO_ENCODING_ALAW: + bits = CS_CDF_FMT_ALAW >> 5; + break; + case AUDIO_ENCODING_ADPCM: + bits = CS_CDF_FMT_ADPCM >> 5; + break; + case AUDIO_ENCODING_SLINEAR_LE: + if (p->precision == 16) + bits = CS_CDF_FMT_LINEAR_LE >> 5; + else + return (EINVAL); + break; + case AUDIO_ENCODING_SLINEAR_BE: + if (p->precision == 16) + bits = CS_CDF_FMT_LINEAR_BE >> 5; + else + return (EINVAL); + break; + case AUDIO_ENCODING_ULINEAR_LE: + if (p->precision == 8) + bits = CS_CDF_FMT_ULINEAR >> 5; + else + return (EINVAL); + break; + default: + return (EINVAL); + } + + if (p->channels != 1 && p->channels != 2) + return (EINVAL); + + err = cs4231_set_speed(sc, &p->sample_rate); + if (err) + return (err); + + p->sw_code = pswcode; + r->sw_code = rswcode; + + sc->sc_format_bits = bits; + sc->sc_channels = p->channels; + sc->sc_precision = p->precision; + sc->sc_need_commit = 1; + return (0); +} + +int +cs4231_round_blocksize(addr, blk) + void *addr; + int blk; +{ + return (blk & (-4)); +} + +int +cs4231_commit_settings(addr) + void *addr; +{ + struct cs4231_softc *sc = (struct cs4231_softc *)addr; + struct cs4231_regs *regs = sc->sc_regs; + int s, tries; + u_char fs; + volatile u_int8_t x; + + if (sc->sc_need_commit == 0) + return (0); + + s = splaudio(); + + cs4231_mute_monitor(sc, 1); + + fs = sc->sc_speed_bits | (sc->sc_format_bits << 5); + if (sc->sc_channels == 2) + fs |= CS_FSPB_SM_STEREO; + + regs->iar = CS_IAR_MCE | CS_IAR_FSPB; + regs->idr = fs; + x = regs->idr; + x = regs->idr; + tries = 100000; + while (tries-- && regs->idr == CS_IAR_INIT); + if (tries == 0) { + printf("%s: timeout committing fspb\n", sc->sc_dev.dv_xname); + return (0); + } + + regs->iar = CS_IAR_MCE | CS_IAR_CDF; + regs->idr = fs; + x = regs->idr; + x = regs->idr; + tries = 100000; + while (tries-- && regs->idr == CS_IAR_INIT); + if (tries == 0) { + printf("%s: timeout committing cdf\n", sc->sc_dev.dv_xname); + return (0); + } + + cs4231_wait(sc); + + cs4231_mute_monitor(sc, 0); + + splx(s); + + sc->sc_need_commit = 0; + return (0); +} + +int +cs4231_halt_output(addr) + void *addr; +{ + struct cs4231_softc *sc = (struct cs4231_softc *)addr; + struct cs4231_regs *regs = sc->sc_regs; + u_int8_t r; + + regs->dma_csr &= ~(CS_DMACSR_EI | CS_DMACSR_GIE | CS_DMACSR_PIE | + CS_DMACSR_EIE | CS_DMACSR_PDMA_GO | CS_DMACSR_PMIE); + regs->iar = CS_IAR_IC; + r = regs->idr & (~CS_IC_PEN); + regs->iar = CS_IAR_IC; + regs->idr = r; + sc->sc_locked = 0; + return (0); +} + +int +cs4231_halt_input(addr) + void *addr; +{ + struct cs4231_softc *sc = (struct cs4231_softc *)addr; + struct cs4231_regs *regs = sc->sc_regs; + + regs->dma_csr = CS_DMACSR_CAPTURE_PAUSE; + regs->iar = CS_IAR_IC; + regs->idr &= ~CS_IC_CEN; + sc->sc_locked = 0; + return (0); +} + +int +cs4231_getdev(addr, retp) + void *addr; + struct audio_device *retp; +{ + *retp = cs4231_device; + return (0); +} + +int +cs4231_set_port(addr, cp) + void *addr; + mixer_ctrl_t *cp; +{ + struct cs4231_softc *sc = (struct cs4231_softc *)addr; + int error = EINVAL; + + DPRINTF(("cs4231_set_port: port=%d type=%d\n", cp->dev, cp->type)); + + switch (cp->dev) { + case CSAUDIO_DAC_LVL: + if (cp->type != AUDIO_MIXER_VALUE) + break; + if (cp->un.value.num_channels == 1) { + sc->sc_regs->iar = CS_IAR_LACIN1; + sc->sc_regs->idr = + cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] & + CS_LACIN1_GAIN_MASK; + } + else if (cp->un.value.num_channels == 2) { + sc->sc_regs->iar = CS_IAR_LACIN1; + sc->sc_regs->idr = + cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT] & + CS_LACIN1_GAIN_MASK; + sc->sc_regs->iar = CS_IAR_RACIN1; + sc->sc_regs->idr = + cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] & + CS_RACIN1_GAIN_MASK; + } else + break; + error = 0; + break; + case CSAUDIO_LINE_IN_LVL: + if (cp->type != AUDIO_MIXER_VALUE) + break; + if (cp->un.value.num_channels == 1) { + sc->sc_regs->iar = CS_IAR_LLI; + sc->sc_regs->idr = + cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] & + CS_LLI_GAIN_MASK; + } + else if (cp->un.value.num_channels == 2) { + sc->sc_regs->iar = CS_IAR_LLI; + sc->sc_regs->idr = + cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT] & + CS_LLI_GAIN_MASK; + sc->sc_regs->iar = CS_IAR_RLI; + sc->sc_regs->idr = + cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] & + CS_RLI_GAIN_MASK; + } else + break; + error = 0; + break; + case CSAUDIO_MONO_LVL: + if (cp->type != AUDIO_MIXER_VALUE) + break; + if (cp->un.value.num_channels == 1) { +#if 0 + sc->sc_regs->iar = CS_IAR_MONO; + sc->sc_regs->idr = + cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] & + CS_MONO_MIA_MASK; +#endif + } else + break; + error = 0; + break; + case CSAUDIO_CD_LVL: + if (cp->type != AUDIO_MIXER_VALUE) + break; + if (cp->un.value.num_channels == 1) { + sc->sc_regs->iar = CS_IAR_LACIN2; + sc->sc_regs->idr = + cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] & + CS_LACIN2_GAIN_MASK; + error = 0; + } + else if (cp->un.value.num_channels == 2) { + sc->sc_regs->iar = CS_IAR_LACIN2; + sc->sc_regs->idr = + cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT] & + CS_LACIN2_GAIN_MASK; + sc->sc_regs->iar = CS_IAR_RACIN2; + sc->sc_regs->idr = + cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] & + CS_RACIN2_GAIN_MASK; + error = 0; + } + else + break; + break; + case CSAUDIO_MONITOR_LVL: + if (cp->type != AUDIO_MIXER_VALUE) + break; + if (cp->un.value.num_channels == 1) { + sc->sc_regs->iar = CS_IAR_LOOP; + sc->sc_regs->idr = + cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] << 2; + } + else + break; + error = 0; + break; + + case CSAUDIO_OUTPUT_LVL: + if (cp->type != AUDIO_MIXER_VALUE) + break; + if (cp->un.value.num_channels == 1) { + sc->sc_volume[CSPORT_SPEAKER].left = + cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]; + sc->sc_volume[CSPORT_SPEAKER].right = + cp->un.value.level[AUDIO_MIXER_LEVEL_MONO]; + } + else if (cp->un.value.num_channels == 2) { + sc->sc_volume[CSPORT_SPEAKER].left = + cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT]; + sc->sc_volume[CSPORT_SPEAKER].right = + cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT]; + } + else + break; + + sc->sc_regs->iar = CS_IAR_LDACOUT; + sc->sc_regs->idr &= ~CS_LDACOUT_LDA_MASK; + sc->sc_regs->idr |= + (~(sc->sc_volume[CSPORT_SPEAKER].left >> 2)) & + CS_LDACOUT_LDA_MASK; + sc->sc_regs->iar = CS_IAR_RDACOUT; + sc->sc_regs->idr &= ~CS_RDACOUT_RDA_MASK; + sc->sc_regs->idr |= + (~(sc->sc_volume[CSPORT_SPEAKER].right >> 2)) & + CS_RDACOUT_RDA_MASK; + error = 0; + break; + + case CSAUDIO_OUTPUT: + if (cp->un.ord != CSPORT_LINEOUT && + cp->un.ord != CSPORT_SPEAKER && + cp->un.ord != CSPORT_HEADPHONE) + return (EINVAL); + sc->sc_out_port = cp->un.ord; + error = 0; + break; + case CSAUDIO_LINE_IN_MUTE: + if (cp->type != AUDIO_MIXER_ENUM) + break; + sc->mute[CSPORT_LINEIN] = cp->un.ord ? 1 : 0; + error = 0; + break; + case CSAUDIO_DAC_MUTE: + if (cp->type != AUDIO_MIXER_ENUM) + break; + sc->mute[CSPORT_AUX1] = cp->un.ord ? 1 : 0; + error = 0; + break; + case CSAUDIO_CD_MUTE: + if (cp->type != AUDIO_MIXER_ENUM) + break; + sc->mute[CSPORT_AUX2] = cp->un.ord ? 1 : 0; + error = 0; + break; + case CSAUDIO_MONO_MUTE: + if (cp->type != AUDIO_MIXER_ENUM) + break; + sc->mute[CSPORT_MONO] = cp->un.ord ? 1 : 0; + error = 0; + break; + case CSAUDIO_MONITOR_MUTE: + if (cp->type != AUDIO_MIXER_ENUM) + break; + sc->mute[CSPORT_MONITOR] = cp->un.ord ? 1 : 0; + error = 0; + break; + case CSAUDIO_OUTPUT_MUTE: + if (cp->type != AUDIO_MIXER_ENUM) + break; + sc->mute[CSPORT_SPEAKER] = cp->un.ord ? 1 : 0; + error = 0; + break; + case CSAUDIO_REC_LVL: + if (cp->type != AUDIO_MIXER_VALUE) + break; + break; + + case CSAUDIO_RECORD_SOURCE: + if (cp->type != AUDIO_MIXER_ENUM) + break; + break; + } + + return (error); +} + +int +cs4231_get_port(addr, cp) + void *addr; + mixer_ctrl_t *cp; +{ + struct cs4231_softc *sc = (struct cs4231_softc *)addr; + int error = EINVAL; + + DPRINTF(("cs4231_get_port: port=%d type=%d\n", cp->dev, cp->type)); + + switch (cp->dev) { + case CSAUDIO_DAC_LVL: + if (cp->type != AUDIO_MIXER_VALUE) + break; + if (cp->un.value.num_channels == 1) { + sc->sc_regs->iar = CS_IAR_LACIN1; + cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = + sc->sc_regs->idr & CS_LACIN1_GAIN_MASK; + } + else if (cp->un.value.num_channels == 2) { + sc->sc_regs->iar = CS_IAR_LACIN1; + cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = + sc->sc_regs->idr & CS_LACIN1_GAIN_MASK; + sc->sc_regs->iar = CS_IAR_RACIN1; + cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = + sc->sc_regs->idr & CS_RACIN1_GAIN_MASK; + } else + break; + error = 0; + break; + case CSAUDIO_LINE_IN_LVL: + if (cp->type != AUDIO_MIXER_VALUE) + break; + if (cp->un.value.num_channels == 1) { + sc->sc_regs->iar = CS_IAR_LLI; + cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = + sc->sc_regs->idr & CS_LLI_GAIN_MASK; + } + else if (cp->un.value.num_channels == 2) { + sc->sc_regs->iar = CS_IAR_LLI; + cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = + sc->sc_regs->idr & CS_LLI_GAIN_MASK; + sc->sc_regs->iar = CS_IAR_RLI; + cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = + sc->sc_regs->idr & CS_RLI_GAIN_MASK; + } else + break; + error = 0; + break; + case CSAUDIO_MONO_LVL: + if (cp->type != AUDIO_MIXER_VALUE) + break; + if (cp->un.value.num_channels == 1) { +#if 0 + sc->sc_regs->iar = CS_IAR_MONO; + cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = + sc->sc_regs->idr & CS_MONO_MIA_MASK; +#endif + } else + break; + error = 0; + break; + case CSAUDIO_CD_LVL: + if (cp->type != AUDIO_MIXER_VALUE) + break; + if (cp->un.value.num_channels == 1) { + sc->sc_regs->iar = CS_IAR_LACIN2; + cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = + sc->sc_regs->idr & CS_LACIN2_GAIN_MASK; + error = 0; + } + else if (cp->un.value.num_channels == 2) { + sc->sc_regs->iar = CS_IAR_LACIN2; + cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = + sc->sc_regs->idr & CS_LACIN2_GAIN_MASK; + sc->sc_regs->iar = CS_IAR_RACIN2; + cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = + sc->sc_regs->idr & CS_RACIN2_GAIN_MASK; + error = 0; + } + else + break; + break; + case CSAUDIO_MONITOR_LVL: + if (cp->type != AUDIO_MIXER_VALUE) + break; + if (cp->un.value.num_channels == 1) { + sc->sc_regs->iar = CS_IAR_LOOP; + cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = + sc->sc_regs->idr >> 2; + } + else + break; + error = 0; + break; + case CSAUDIO_OUTPUT_LVL: + if (cp->type != AUDIO_MIXER_VALUE) + break; + if (cp->un.value.num_channels == 1) + cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = + sc->sc_volume[CSPORT_SPEAKER].left; + else if (cp->un.value.num_channels == 2) { + cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = + sc->sc_volume[CSPORT_SPEAKER].left; + cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = + sc->sc_volume[CSPORT_SPEAKER].right; + } + else + break; + error = 0; + break; + case CSAUDIO_LINE_IN_MUTE: + if (cp->type != AUDIO_MIXER_ENUM) + break; + cp->un.ord = sc->mute[CSPORT_LINEIN] ? 1 : 0; + error = 0; + break; + case CSAUDIO_DAC_MUTE: + if (cp->type != AUDIO_MIXER_ENUM) + break; + cp->un.ord = sc->mute[CSPORT_AUX1] ? 1 : 0; + error = 0; + break; + case CSAUDIO_CD_MUTE: + if (cp->type != AUDIO_MIXER_ENUM) + break; + cp->un.ord = sc->mute[CSPORT_AUX2] ? 1 : 0; + error = 0; + break; + case CSAUDIO_MONO_MUTE: + if (cp->type != AUDIO_MIXER_ENUM) + break; + cp->un.ord = sc->mute[CSPORT_MONO] ? 1 : 0; + error = 0; + break; + case CSAUDIO_MONITOR_MUTE: + if (cp->type != AUDIO_MIXER_ENUM) + break; + cp->un.ord = sc->mute[CSPORT_MONITOR] ? 1 : 0; + error = 0; + break; + case CSAUDIO_OUTPUT_MUTE: + if (cp->type != AUDIO_MIXER_ENUM) + break; + cp->un.ord = sc->mute[CSPORT_SPEAKER] ? 1 : 0; + error = 0; + break; + case CSAUDIO_REC_LVL: + if (cp->type != AUDIO_MIXER_VALUE) + break; + if (cp->un.value.num_channels == 1) { + cp->un.value.level[AUDIO_MIXER_LEVEL_MONO] = + AUDIO_MIN_GAIN; + } else if (cp->un.value.num_channels == 2) { + cp->un.value.level[AUDIO_MIXER_LEVEL_LEFT] = + AUDIO_MIN_GAIN; + cp->un.value.level[AUDIO_MIXER_LEVEL_RIGHT] = + AUDIO_MIN_GAIN; + } else + break; + error = 0; + break; + case CSAUDIO_RECORD_SOURCE: + if (cp->type != AUDIO_MIXER_ENUM) break; + cp->un.ord = MIC_IN_PORT; + error = 0; + break; + case CSAUDIO_OUTPUT: + if (cp->type != AUDIO_MIXER_ENUM) break; + cp->un.ord = sc->sc_out_port; + error = 0; + break; + default: + printf("Invalid kind!\n"); + } + return (error); +} + +int +cs4231_query_devinfo(addr, dip) + void *addr; + mixer_devinfo_t *dip; +{ + int err = 0; + + switch (dip->index) { +#if 0 + case CSAUDIO_MIC_IN_LVL: /* microphone */ + dip->type = AUDIO_MIXER_VALUE; + dip->mixer_class = CSAUDIO_INPUT_CLASS; + dip->prev = AUDIO_MIXER_LAST; + dip->next = CSAUDIO_MIC_IN_MUTE; + strcpy(dip->label.name, AudioNmicrophone); + dip->un.v.num_channels = 2; + strcpy(dip->un.v.units.name, AudioNvolume); + break; +#endif + + case CSAUDIO_MONO_LVL: /* mono/microphone mixer */ + dip->type = AUDIO_MIXER_VALUE; + dip->mixer_class = CSAUDIO_INPUT_CLASS; + dip->prev = AUDIO_MIXER_LAST; + dip->next = CSAUDIO_MONO_MUTE; + strcpy(dip->label.name, AudioNmicrophone); + dip->un.v.num_channels = 1; + strcpy(dip->un.v.units.name, AudioNvolume); + break; + + case CSAUDIO_DAC_LVL: /* dacout */ + dip->type = AUDIO_MIXER_VALUE; + dip->mixer_class = CSAUDIO_INPUT_CLASS; + dip->prev = AUDIO_MIXER_LAST; + dip->next = CSAUDIO_DAC_MUTE; + strcpy(dip->label.name, AudioNdac); + dip->un.v.num_channels = 2; + strcpy(dip->un.v.units.name, AudioNvolume); + break; + + case CSAUDIO_LINE_IN_LVL: /* line */ + dip->type = AUDIO_MIXER_VALUE; + dip->mixer_class = CSAUDIO_INPUT_CLASS; + dip->prev = AUDIO_MIXER_LAST; + dip->next = CSAUDIO_LINE_IN_MUTE; + strcpy(dip->label.name, AudioNline); + dip->un.v.num_channels = 2; + strcpy(dip->un.v.units.name, AudioNvolume); + break; + + case CSAUDIO_CD_LVL: /* cd */ + dip->type = AUDIO_MIXER_VALUE; + dip->mixer_class = CSAUDIO_INPUT_CLASS; + dip->prev = AUDIO_MIXER_LAST; + dip->next = CSAUDIO_CD_MUTE; + strcpy(dip->label.name, AudioNcd); + dip->un.v.num_channels = 2; + strcpy(dip->un.v.units.name, AudioNvolume); + break; + + case CSAUDIO_MONITOR_LVL: /* monitor level */ + dip->type = AUDIO_MIXER_VALUE; + dip->mixer_class = CSAUDIO_MONITOR_CLASS; + dip->prev = AUDIO_MIXER_LAST; + dip->next = CSAUDIO_MONITOR_MUTE; + strcpy(dip->label.name, AudioNmonitor); + dip->un.v.num_channels = 1; + strcpy(dip->un.v.units.name, AudioNvolume); + break; + + case CSAUDIO_OUTPUT_LVL: + dip->type = AUDIO_MIXER_VALUE; + dip->mixer_class = CSAUDIO_OUTPUT_CLASS; + dip->prev = AUDIO_MIXER_LAST; + dip->next = CSAUDIO_OUTPUT_MUTE; + strcpy(dip->label.name, AudioNoutput); + dip->un.v.num_channels = 2; + strcpy(dip->un.v.units.name, AudioNvolume); + break; + + case CSAUDIO_LINE_IN_MUTE: + dip->type = AUDIO_MIXER_ENUM; + dip->mixer_class = CSAUDIO_INPUT_CLASS; + dip->prev = CSAUDIO_LINE_IN_LVL; + dip->next = AUDIO_MIXER_LAST; + goto mute; + + case CSAUDIO_DAC_MUTE: + dip->type = AUDIO_MIXER_ENUM; + dip->mixer_class = CSAUDIO_INPUT_CLASS; + dip->prev = CSAUDIO_DAC_LVL; + dip->next = AUDIO_MIXER_LAST; + goto mute; + + case CSAUDIO_CD_MUTE: + dip->type = AUDIO_MIXER_ENUM; + dip->mixer_class = CSAUDIO_INPUT_CLASS; + dip->prev = CSAUDIO_CD_LVL; + dip->next = AUDIO_MIXER_LAST; + goto mute; + + case CSAUDIO_MONO_MUTE: + dip->type = AUDIO_MIXER_ENUM; + dip->mixer_class = CSAUDIO_INPUT_CLASS; + dip->prev = CSAUDIO_MONO_LVL; + dip->next = AUDIO_MIXER_LAST; + goto mute; + + case CSAUDIO_MONITOR_MUTE: + dip->type = AUDIO_MIXER_ENUM; + dip->mixer_class = CSAUDIO_OUTPUT_CLASS; + dip->prev = CSAUDIO_MONITOR_LVL; + dip->next = AUDIO_MIXER_LAST; + goto mute; + + case CSAUDIO_OUTPUT_MUTE: + dip->type = AUDIO_MIXER_ENUM; + dip->mixer_class = CSAUDIO_OUTPUT_CLASS; + dip->prev = CSAUDIO_OUTPUT_LVL; + dip->next = AUDIO_MIXER_LAST; + goto mute; + + mute: + strcpy(dip->label.name, AudioNmute); + dip->un.e.num_mem = 2; + strcpy(dip->un.e.member[0].label.name, AudioNoff); + dip->un.e.member[0].ord = 0; + strcpy(dip->un.e.member[1].label.name, AudioNon); + dip->un.e.member[0].ord = 1; + break; + + case CSAUDIO_REC_LVL: /* record level */ + dip->type = AUDIO_MIXER_VALUE; + dip->mixer_class = CSAUDIO_RECORD_CLASS; + dip->prev = AUDIO_MIXER_LAST; + dip->next = CSAUDIO_RECORD_SOURCE; + strcpy(dip->label.name, AudioNrecord); + dip->un.v.num_channels = 2; + strcpy(dip->un.v.units.name, AudioNvolume); + break; + + case CSAUDIO_RECORD_SOURCE: + dip->type = AUDIO_MIXER_ENUM; + dip->mixer_class = CSAUDIO_RECORD_CLASS; + dip->prev = CSAUDIO_REC_LVL; + dip->next = AUDIO_MIXER_LAST; + strcpy(dip->label.name, AudioNsource); + dip->un.e.num_mem = 3; + strcpy(dip->un.e.member[0].label.name, AudioNcd); + dip->un.e.member[0].ord = DAC_IN_PORT; + strcpy(dip->un.e.member[1].label.name, AudioNmicrophone); + dip->un.e.member[1].ord = MIC_IN_PORT; + strcpy(dip->un.e.member[2].label.name, AudioNdac); + dip->un.e.member[2].ord = AUX1_IN_PORT; + strcpy(dip->un.e.member[3].label.name, AudioNline); + dip->un.e.member[3].ord = LINE_IN_PORT; + break; + + case CSAUDIO_OUTPUT: + dip->type = AUDIO_MIXER_ENUM; + dip->mixer_class = CSAUDIO_MONITOR_CLASS; + dip->prev = dip->next = AUDIO_MIXER_LAST; + strcpy(dip->label.name, AudioNoutput); + dip->un.e.num_mem = 3; + strcpy(dip->un.e.member[0].label.name, AudioNspeaker); + dip->un.e.member[0].ord = CSPORT_SPEAKER; + strcpy(dip->un.e.member[1].label.name, AudioNline); + dip->un.e.member[1].ord = CSPORT_LINEOUT; + strcpy(dip->un.e.member[2].label.name, AudioNheadphone); + dip->un.e.member[2].ord = CSPORT_HEADPHONE; + break; + + case CSAUDIO_INPUT_CLASS: /* input class descriptor */ + dip->type = AUDIO_MIXER_CLASS; + dip->mixer_class = CSAUDIO_INPUT_CLASS; + dip->prev = AUDIO_MIXER_LAST; + dip->next = AUDIO_MIXER_LAST; + strcpy(dip->label.name, AudioCinputs); + break; + + case CSAUDIO_OUTPUT_CLASS: /* output class descriptor */ + dip->type = AUDIO_MIXER_CLASS; + dip->mixer_class = CSAUDIO_OUTPUT_CLASS; + dip->prev = AUDIO_MIXER_LAST; + dip->next = AUDIO_MIXER_LAST; + strcpy(dip->label.name, AudioCoutputs); + break; + + case CSAUDIO_MONITOR_CLASS: /* monitor class descriptor */ + dip->type = AUDIO_MIXER_CLASS; + dip->mixer_class = CSAUDIO_MONITOR_CLASS; + dip->prev = AUDIO_MIXER_LAST; + dip->next = AUDIO_MIXER_LAST; + strcpy(dip->label.name, AudioCmonitor); + break; + + case CSAUDIO_RECORD_CLASS: /* record class descriptor */ + dip->type = AUDIO_MIXER_CLASS; + dip->mixer_class = CSAUDIO_RECORD_CLASS; + dip->prev = AUDIO_MIXER_LAST; + dip->next = AUDIO_MIXER_LAST; + strcpy(dip->label.name, AudioCrecord); + break; + + default: + err = ENXIO; + } + + return (err); +} + +void * +cs4231_alloc(addr, size, pool, flags) + void *addr; + u_long size; + int pool; + int flags; +{ + struct cs4231_softc *sc = (struct cs4231_softc *)addr; + struct cs_dma *p; + + p = (struct cs_dma *)malloc(sizeof(struct cs_dma), pool, flags); + if (p == NULL) + return (NULL); + + p->addr_dva = dvma_malloc(size, &p->addr, flags); + if (p->addr_dva == NULL) { + free(p, pool); + return (NULL); + } + + p->size = size; + p->next = sc->sc_dmas; + sc->sc_dmas = p; + return (p->addr); +} + +void +cs4231_free(addr, ptr, pool) + void *addr; + void *ptr; + int pool; +{ + struct cs4231_softc *sc = addr; + struct cs_dma *p, **pp; + + for (pp = &sc->sc_dmas; (p = *pp) != NULL; pp = &(*pp)->next) { + if (p->addr != ptr) + continue; + dvma_free(p->addr_dva, 16*1024, &p->addr); + *pp = p->next; + free(p, pool); + return; + } + printf("%s: attempt to free rogue pointer\n", sc->sc_dev.dv_xname); +} + +u_long +cs4231_round_buffersize(addr, size) + void *addr; + u_long size; +{ + return (size); +} + +int +cs4231_get_props(addr) + void *addr; +{ + return (AUDIO_PROP_FULLDUPLEX); +} + +int +cs4231_trigger_output(addr, start, end, blksize, intr, arg, param) + void *addr, *start, *end; + int blksize; + void (*intr) __P((void *)); + void *arg; + struct audio_params *param; +{ + struct cs4231_softc *sc = addr; + struct cs4231_regs *regs = sc->sc_regs; + struct cs_dma *p; + u_int8_t reg; + u_int32_t n, csr; + + if (sc->sc_locked != 0) { + printf("cs4231_trigger_output: already running\n"); + return (EINVAL); + } + + sc->sc_locked = 1; + sc->sc_pintr = intr; + sc->sc_parg = arg; + + p = sc->sc_dmas; + while (p != NULL && p->addr != start) + p = p->next; + if (p == NULL) { + printf("cs4231_trigger_output: bad addr: %x\n", start); + return (EINVAL); + } + + n = (char *)end - (char *)start; + + /* + * Do only `blksize' at a time, so audio_pint() is kept + * synchronous with us... + */ + sc->sc_blksz = blksize; + sc->sc_nowplaying = p; + sc->sc_playsegsz = n; + + if (n > sc->sc_blksz) + n = sc->sc_blksz; + + sc->sc_playcnt = n; + + csr = regs->dma_csr; + regs->dma_pnva = (u_int32_t)p->addr_dva; + regs->dma_pnc = n; + + if ((csr & CS_DMACSR_PDMA_GO) == 0 || (csr & CS_DMACSR_PPAUSE) != 0) { + regs->dma_csr &= ~(CS_DMACSR_PIE | CS_DMACSR_PPAUSE); + regs->dma_csr |= CS_DMACSR_EI | CS_DMACSR_GIE | + CS_DMACSR_PIE | CS_DMACSR_EIE | + CS_DMACSR_PMIE | CS_DMACSR_PDMA_GO; + regs->iar = CS_IAR_PBLB; + regs->idr = 0xff; + regs->iar = CS_IAR_PBUB; + regs->idr = 0xff; + regs->iar = CS_IAR_IC; + reg = regs->idr | CS_IC_PEN; + regs->iar = CS_IAR_IC; + regs->idr = reg; + } + return (0); +} + +int +cs4231_trigger_input(addr, start, end, blksize, intr, arg, param) + void *addr, *start, *end; + int blksize; + void (*intr) __P((void *)); + void *arg; + struct audio_params *param; +{ + return (ENXIO); +} + +#endif /* NAUDIO > 0 */ diff --git a/sys/arch/sparc/dev/cs4231reg.h b/sys/arch/sparc/dev/cs4231reg.h new file mode 100644 index 00000000000..fe92a339a76 --- /dev/null +++ b/sys/arch/sparc/dev/cs4231reg.h @@ -0,0 +1,439 @@ +/* $OpenBSD: cs4231reg.h,v 1.1 1999/06/06 04:48:24 jason Exp $ */ + +/* + * Copyright (c) 1999 Jason L. Wright (jason@thought.net) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Jason L. Wright + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Driver for the CS4231 audio in some sun4m systems + */ + +#define CS_TIMEOUT 90000 + +/* + * CS4231 registers from CS web site and Solaris 2.6 includes. + */ +struct cs4231_regs { + volatile u_int8_t iar; /* index address */ + volatile u_int8_t _padding1[3]; /* reserved */ + volatile u_int8_t idr; /* index data */ + volatile u_int8_t _padding2[3]; /* reserved */ + volatile u_int8_t status; /* status */ + volatile u_int8_t _padding3[3]; /* reserved */ + volatile u_int8_t pior; /* PIO data i/o */ + volatile u_int8_t _padding4[3]; /* reserved */ + volatile u_int32_t dma_csr; /* APC control/status */ + volatile u_int32_t _padding5[3]; /* reserved */ + volatile u_int32_t dma_cva; /* capture virtual addr */ + volatile u_int32_t dma_cc; /* capture count */ + volatile u_int32_t dma_cnva; /* capture next virtual addr */ + volatile u_int32_t dma_cnc; /* capture next count */ + volatile u_int32_t dma_pva; /* playback virtual addr */ + volatile u_int32_t dma_pc; /* playback count */ + volatile u_int32_t dma_pnva; /* playback next virtual addr */ + volatile u_int32_t dma_pnc; /* playback next count */ +}; + +/* + * The CS4231 has 4 direct access registers: iar, idr, status, pior + * + * iar and idr are used to access either 16 or 32 (mode 2 only) "indirect + * registers". + */ + +/* + * Direct mapped registers + */ + +/* cs4231_reg.iar: index address register */ +#define CS_IAR_IR_MASK 0x1f /* indirect register mask */ +#define CS_IAR_TRD 0x20 /* transfer request disable */ +#define CS_IAR_MCE 0x40 /* mode change enable */ +#define CS_IAR_INIT 0x80 /* initialization */ + +/* indirect register numbers (mode1/mode2) */ +#define CS_IAR_LADCIN 0x00 /* left adc input control */ +#define CS_IAR_RADCIN 0x01 /* right adc input control */ +#define CS_IAR_LACIN1 0x02 /* left aux #1 input control */ +#define CS_IAR_RACIN1 0x03 /* right aux #1 input control */ +#define CS_IAR_LACIN2 0x04 /* left aux #2 input control */ +#define CS_IAR_RACIN2 0x05 /* right aux #2 input control */ +#define CS_IAR_LDACOUT 0x06 /* left dac output control */ +#define CS_IAR_RDACOUT 0x07 /* right dac output control */ +#define CS_IAR_FSPB 0x08 /* fs and playback format */ +#define CS_IAR_IC 0x09 /* interface configuration */ +#define CS_IAR_PC 0x0a /* pin control */ +#define CS_IAR_ERRINIT 0x0b /* error status & init */ +#define CS_IAR_MODEID 0x0c /* mode and id */ +#define CS_IAR_LOOP 0x0d /* loopback control */ +#define CS_IAR_PBUB 0x0e /* playback upper base */ +#define CS_IAR_PBLB 0x0f /* playback lower base */ + +/* indirect register numbers (mode2 only) */ + +#define CS_IAR_AFE1 0x10 /* alt feature enable I */ +#define CS_IAR_AFE2 0x11 /* alt feature enable II */ +#define CS_IAR_LLI 0x12 /* left line input control */ +#define CS_IAR_RLI 0x13 /* right line input control */ +#define CS_IAR_TLB 0x14 /* timer lower base */ +#define CS_IAR_TUB 0x15 /* timer upper base */ +#define CS_IAR_reserved1 0x16 /* reserved */ +#define CS_IAR_AFE3 0x17 /* alt feature enable III */ +#define CS_IAR_AFS 0x18 /* alt feature status */ +#define CS_IAR_VID 0x19 /* version id */ +#define CS_IAR_MONO 0x1a /* mono input/output control */ +#define CS_IAR_reserved2 0x1b /* reserved */ +#define CS_IAR_CDF 0x1c /* capture data format */ +#define CS_IAR_reserved3 0x1d /* reserved */ +#define CS_IAR_CUB 0x1e /* capture upper base */ +#define CS_IAR_CLB 0x1f /* capture lower base */ + +/* cs4231_reg.idr: index data register */ +/* Contains the data of the indirect register indexed by the iar */ + +/* cs4231_reg.status: status register */ +#define CS_STATUS_INT 0x01 /* interrupt status(1=active) */ +#define CS_STATUS_PRDY 0x02 /* playback data ready */ +#define CS_STATUS_PL 0x04 /* playback l/r sample */ +#define CS_STATUS_PU 0x08 /* playback up/lw byte needed */ +#define CS_STATUS_SER 0x10 /* sample error */ +#define CS_STATUS_CRDY 0x20 /* capture data ready */ +#define CS_STATUS_CL 0x40 /* capture l/r sample */ +#define CS_STATUS_CU 0x80 /* capture up/lw byte needed */ + +/* cs4231_reg.pior: programmed i/o register */ +/* On write, this is the playback data byte */ +/* On read, it is the capture data byte */ + +/* + * Indirect Mapped Registers + */ + +/* Left ADC Input Control: I0 */ +#define CS_LADCIN_GAIN_MASK 0x0f /* left adc gain */ +#define CS_LADCIN_reserved 0x10 /* reserved */ +#define CS_LADCIN_LMGE 0x20 /* left mic gain enable */ +#define CS_LADCIN_SRC_MASK 0xc0 /* left adc source select */ + +#define CS_LADCIN_SRC_LINE 0x00 /* left input src: line */ +#define CS_LADCIN_SRC_AUX 0x40 /* left input src: aux */ +#define CS_LADCIN_SRC_MIC 0x80 /* left input src: mic */ +#define CS_LADCIN_SRC_LOOP 0xc0 /* left input src: loopback */ + +/* Right ADC Input Control: I1 */ +#define CS_RADCIN_GAIN_MASK 0x0f /* right adc gain */ +#define CS_RADCIN_reserved 0x10 /* reserved */ +#define CS_RADCIN_LMGE 0x20 /* right mic gain enable */ +#define CS_RADCIN_SRC_MASK 0xc0 /* right adc source select */ + +#define CS_RADCIN_SRC_LINE 0x00 /* right input src: line */ +#define CS_RADCIN_SRC_AUX 0x40 /* right input src: aux */ +#define CS_RADCIN_SRC_MIC 0x80 /* right input src: mic */ +#define CS_RADCIN_SRC_LOOP 0xc0 /* right input src: loopback */ + +/* Left Auxiliary #1 Input Control: I2 */ +#define CS_LACIN1_GAIN_MASK 0x1f /* left aux #1 mix gain */ +#define CS_LACIN1_reserved1 0x20 /* reserved */ +#define CS_LACIN1_reserved2 0x40 /* reserved */ +#define CS_LACIN1_LX1M 0x80 /* left aux #1 mute */ + +/* Right Auxiliary #1 Input Control: I3 */ +#define CS_RACIN1_GAIN_MASK 0x1f /* right aux #1 mix gain */ +#define CS_RACIN1_reserved1 0x20 /* reserved */ +#define CS_RACIN1_reserved2 0x40 /* reserved */ +#define CS_RACIN1_RX1M 0x80 /* right aux #1 mute */ + +/* Left Auxiliary #2 Input Control: I4 */ +#define CS_LACIN2_GAIN_MASK 0x1f /* left aux #2 mix gain */ +#define CS_LACIN2_reserved1 0x20 /* reserved */ +#define CS_LACIN2_reserved2 0x40 /* reserved */ +#define CS_LACIN2_LX2M 0x80 /* left aux #2 mute */ + +/* Right Auxiliary #2 Input Control: I5 */ +#define CS_RACIN2_GAIN_MASK 0x1f /* right aux #2 mix gain */ +#define CS_RACIN2_reserved1 0x20 /* reserved */ +#define CS_RACIN2_reserved2 0x40 /* reserved */ +#define CS_RACIN2_RX2M 0x80 /* right aux #2 mute */ + +/* Left DAC Output Control: I6 */ +#define CS_LDACOUT_LDA_MASK 0x3f /* left dac attenuator */ +#define CS_LDACOUT_reserved 0x40 /* reserved */ +#define CS_LDACOUT_LDM 0x80 /* left dac mute */ + +/* Right DAC Output Control: I7 */ +#define CS_RDACOUT_RDA_MASK 0x3f /* right dac attenuator */ +#define CS_RDACOUT_reserved 0x40 /* reserved */ +#define CS_RDACOUT_RDM 0x80 /* right dac mute */ + +/* Fs and Playback Data Format: I8 */ +#define CS_FSPB_C2SL 0x01 /* clock 2 source select */ +#define CS_FSPB_CFS_MASK 0x0e /* clock frequency div select */ +#define CS_FSPB_SM 0x10 /* stereo/mono select */ +#define CS_FSPB_FMT_MASK 0xe0 /* playback format select */ + +#define CS_FSPB_C2SL_XTAL1 0x00 /* use 24.576 Mhz crystal */ +#define CS_FSPB_C2SL_XTAL2 0x01 /* use 16.9344 Mhz crystal */ +#define CS_FSPB_SM_MONO 0x00 /* use mono output */ +#define CS_FSPB_SM_STEREO 0x10 /* use stereo output */ +#define CS_FSPB_FMT_ULINEAR 0x00 /* fmt: linear 8bit unsigned */ +#define CS_FSPB_FMT_ULAW 0x20 /* fmt: ulaw, 8bit companded */ +#define CS_FSPB_FMT_LINEAR_LE 0x40 /* fmt: linear 16bit little */ +#define CS_FSPB_FMT_ALAW 0x60 /* fmt: alaw, 8bit companded */ +#define CS_FSPB_FMT_reserved1 0x80 /* fmt: reserved */ +#define CS_FSPB_FMT_ADPCM 0xa0 /* fmt: adpcm 4bit */ +#define CS_FSPB_FMT_LINEAR_BE 0xc0 /* fmt: linear 16bit big */ +#define CS_FSPB_FMT_reserved2 0xe0 /* fmt: reserved */ + +/* Interface Configuration: I9 */ +#define CS_IC_PEN 0x01 /* playback enable */ +#define CS_IC_CEN 0x02 /* capture enable */ +#define CS_IC_SDC 0x04 /* single dma channel */ +#define CS_IC_CAL_MASK 0x18 /* calibration type mask */ +#define CS_IC_reserved 0x20 /* reserved */ +#define CS_IC_PPIO 0x40 /* playback pio enable */ +#define CS_IC_CPIO 0x80 /* capture pio enable */ + +#define CS_IC_CAL_NONE 0x00 /* no calibration */ +#define CS_IC_CAL_CONV 0x08 /* converter calibration */ +#define CS_IC_CAL_DAC 0x10 /* dac calibration */ +#define CS_IC_CAL_FULL 0x18 /* full calibration */ + +/* Pin Control: I10 */ +#define CS_PC_reserved1 0x01 /* reserved */ +#define CS_PC_IEN 0x02 /* interrupt enable */ +#define CS_PC_reserved2 0x04 /* reserved */ +#define CS_PC_DEN 0x08 /* dither enable */ +#define CS_PC_reserved3 0x10 /* reserved */ +#define CS_PC_reserved4 0x20 /* reserved */ +#define CS_PC_XCTL_MASK 0xc0 /* xctl control */ +#define CS_PC_LINEMUTE 0x40 /* mute line */ +#define CS_PC_HDPHMUTE 0x80 /* mute headphone */ +#define CS_PC_XCTL0 0x40 /* set xtcl0 to 1 */ +#define CS_PC_XCTL1 0x80 /* set xctl1 to 1 */ + +/* Error Status and Initialization: I11 */ +#define CS_ERRINIT_ORL_MASK 0x03 /* overrange left detect */ +#define CS_ERRINIT_ORR_MASK 0x0c /* overrange right detect */ +#define CS_ERRINIT_DRQ 0x10 /* drq status */ +#define CS_ERRINIT_ACI 0x20 /* auto-calibrate in progress */ +#define CS_ERRINIT_PUR 0x40 /* playback underrun */ +#define CS_ERRINIT_COR 0x80 /* capture overrun */ + +#define CS_ERRINIT_ORL_VLOW 0x00 /* < -1.5 dB from full scale */ +#define CS_ERRINIT_ORL_LOW 0x01 /* -1.5dB < x < 0dB */ +#define CS_ERRINIT_ORL_HIGH 0x02 /* 0dB < x < 1.5dB */ +#define CS_ERRINIT_ORL_VHIGH 0x03 /* > 1.5dB overrange */ +#define CS_ERRINIT_ORR_VLOW 0x00 /* < -1.5 dB from full scale */ +#define CS_ERRINIT_ORR_LOW 0x04 /* -1.5dB < x < 0dB */ +#define CS_ERRINIT_ORR_HIGH 0x08 /* 0dB < x < 1.5dB */ +#define CS_ERRINIT_ORR_VHIGH 0x0c /* > 1.5dB overrange */ + +/* Mode and ID: I12 */ +#define CS_MODEID_ID_MASK 0x0f /* Codec ID */ +#define CS_MODEID_reserved1 0x10 /* reserved */ +#define CS_MODEID_reserved2 0x20 /* reserved */ +#define CS_MODEID_MODE2 0x40 /* enable mode2 operation */ + +#define CS_MODEID_CS4231 0x0a /* 1010 == cs4231 */ + +/* Loopback Control: I13 */ +#define CS_LOOP_LBE 0x01 /* loopback enable */ +#define CS_LOOP_reserved 0x02 /* reserved */ +#define CS_LOOP_LBA_MASK 0xfc /* loopback attenuation */ + +/* Playback Upper Base: I14 */ + +/* Playback Lower Base: I15 */ + +/* Alternate Feature Enable I: I16 */ +#define CS_AFE1_DACZ 0x01 /* dac zero */ +#define CS_AFE1_SPE 0x02 /* serial port enable */ +#define CS_AFE1_SF_MASK 0x0c /* serial format mask */ +#define CS_AFE1_PMCE 0x10 /* playback mode change enbl */ +#define CS_AFE1_CMCE 0x20 /* capture mode change enable */ +#define CS_AFE1_TE 0x40 /* timer enable */ +#define CS_AFE1_OLB 0x80 /* output level bit */ + +#define CS_AFE1_SF_64E 0x00 /* 64 bit enhanced */ +#define CS_AFE1_SF_64 0x04 /* 64 bit */ +#define CS_AFE1_SF_32 0x08 /* 32 bit */ +#define CS_AFE1_SF_reserved 0x0c /* reserved */ +#define CS_AFE1_OLB_2 0x00 /* full scale 2Vpp (-3dB) */ +#define CS_AFE1_OLB_28 0x80 /* full scale 2.8Vpp (0dB) */ + +/* Alternate Feature Enable II: I17 */ +#define CS_AFE2_HPF 0x01 /* high pass filter enable */ +#define CS_AFE2_XTALE 0x02 /* crystal enable */ +#define CS_AFE2_APAR 0x04 /* ADPCM pb accumulator reset */ +#define CS_AFE2_reserved 0x08 /* reserved */ +#define CS_AFE2_TEST_MASK 0xf0 /* factory test bits */ + +/* Left Line Input Control: I18 */ +#define CS_LLI_GAIN_MASK 0x1f /* left line mix gain mask */ +#define CS_LLI_reserved1 0x20 /* reserved */ +#define CS_LLI_reserved2 0x40 /* reserved */ +#define CS_LLI_MUTE 0x80 /* left line mute */ + +/* Right Line Input Control: I19 */ +#define CS_RLI_GAIN_MASK 0x1f /* right line mix gain mask */ +#define CS_RLI_reserved1 0x20 /* reserved */ +#define CS_RLI_reserved2 0x40 /* reserved */ +#define CS_RLI_MUTE 0x80 /* right line mute */ + +/* Timer Lower Base: I20 */ + +/* Timer Upper Base: I21 */ + +/* Reserved: I22 */ + +/* Alternate Feature Enable III: I23 */ +#define CS_AFE3_ACF 0x01 /* ADPCM capture freeze */ +#define CS_AFE3_reserved 0xfe /* reserved bits */ + +/* Alternate Feature Status: I24 */ +#define CS_AFS_PU 0x01 /* playback underrun */ +#define CS_AFS_PO 0x02 /* playback overrun */ +#define CS_AFS_CO 0x04 /* capture underrun */ +#define CS_AFS_CU 0x08 /* capture overrun */ +#define CS_AFS_PI 0x10 /* playback interrupt */ +#define CS_AFS_CI 0x20 /* capture interrupt */ +#define CS_AFS_TI 0x40 /* timer interrupt */ +#define CS_AFS_reserved 0x80 /* reserved */ + +/* Version ID: I25 */ +#define CS_VID_CHIP_MASK 0x07 /* chip id mask */ +#define CS_VID_VER_MASK 0xe0 /* version number mask */ + +#define CS_VID_CHIP_CS4231 0x00 /* CS4231 and CS4231A */ +#define CS_VID_VER_CS4231 0x80 /* CS4231 */ +#define CS_VID_VER_CS4232 0x82 /* CS4232 */ +#define CS_VID_VER_CS4231A 0xa0 /* CS4231A */ + +/* Mono Input & Output Control: I26 */ +#define CS_MONO_MIA_MASK 0x0f /* mono attenuation mask */ +#define CS_MONO_reserved 0x10 /* reserved */ +#define CS_MONO_MBY 0x20 /* mono bypass */ +#define CS_MONO_MOM 0x40 /* mono output mute */ +#define CS_MONO_MIM 0x80 /* mono input mute */ + +/* Reserved: I27 */ + +/* Capture Data Format: I28 */ +#define CS_CDF_reserved 0x0f /* reserved bits */ +#define CS_CDF_SM 0x10 /* Stereo/mono select */ +#define CS_CDF_FMT_MASK 0xe0 /* capture format mask */ + +#define CS_CDF_SM_MONO 0x00 /* select mono capture */ +#define CS_CDF_SM_STEREO 0x10 /* select stereo capture */ +#define CS_CDF_FMT_ULINEAR 0x00 /* fmt: linear 8bit unsigned */ +#define CS_CDF_FMT_ULAW 0x20 /* fmt: ulaw, 8bit companded */ +#define CS_CDF_FMT_LINEAR_LE 0x40 /* fmt: linear 16bit little */ +#define CS_CDF_FMT_ALAW 0x60 /* fmt: alaw, 8bit companded */ +#define CS_CDF_FMT_reserved1 0x80 /* fmt: reserved */ +#define CS_CDF_FMT_ADPCM 0xa0 /* fmt: adpcm 4bit */ +#define CS_CDF_FMT_LINEAR_BE 0xc0 /* fmt: linear 16bit big */ +#define CS_CDF_FMT_reserved2 0xe0 /* fmt: reserved */ + +/* Reserved: I29 */ + +/* Capture Upper Base: I30 */ + +/* Capture Lower Base: I31 */ + +/* + * APC DMA Register definitions + */ +#define CS_DMACSR_RESET 0x00000001 /* reset */ +#define CS_DMACSR_CDMA_GO 0x00000004 /* capture dma go */ +#define CS_DMACSR_PDMA_GO 0x00000008 /* playback dma go */ +#define CS_DMACSR_CODEC_RESET 0x00000020 /* codec reset */ +#define CS_DMACSR_CPAUSE 0x00000040 /* capture dma pause */ +#define CS_DMACSR_PPAUSE 0x00000080 /* playback dma pause */ +#define CS_DMACSR_CMIE 0x00000100 /* capture pipe empty enb */ +#define CS_DMACSR_CMI 0x00000200 /* capture pipe empty intr */ +#define CS_DMACSR_CD 0x00000400 /* capture nva dirty */ +#define CS_DMACSR_CM 0x00000800 /* capture data lost */ +#define CS_DMACSR_PMIE 0x00001000 /* pb pipe empty intr enable */ +#define CS_DMACSR_PD 0x00002000 /* pb nva dirty */ +#define CS_DMACSR_PM 0x00004000 /* pb pipe empty */ +#define CS_DMACSR_PMI 0x00008000 /* pb pipe empty interrupt */ +#define CS_DMACSR_EIE 0x00010000 /* error interrupt enable */ +#define CS_DMACSR_CIE 0x00020000 /* capture intr enable */ +#define CS_DMACSR_PIE 0x00040000 /* playback intr enable */ +#define CS_DMACSR_GIE 0x00080000 /* general intr enable */ +#define CS_DMACSR_EI 0x00100000 /* error interrupt */ +#define CS_DMACSR_CI 0x00200000 /* capture interrupt */ +#define CS_DMACSR_PI 0x00400000 /* playback interrupt */ +#define CS_DMACSR_GI 0x00800000 /* general interrupt */ + +#define CS_DMACSR_PLAY ( \ + CS_DMACSR_EI | \ + CS_DMACSR_GIE | \ + CS_DMACSR_PIE | \ + CS_DMACSR_EIE | \ + CS_DMACSR_PDMA_GO | \ + CS_DMACSR_PMIE ) + +#define CS_DMACSR_CAPTURE ( \ + CS_DMACSR_EI | \ + CS_DMACSR_GIE | \ + CS_DMACSR_CIE | \ + CS_DMACSR_EIE | \ + CS_DMACSR_CDMA_GO ) + +#define CS_DMACSR_PLAY_PAUSE (~( \ + CS_DMACSR_PPAUSE | \ + CS_DMACSR_GI | \ + CS_DMACSR_PI | \ + CS_DMACSR_CI | \ + CS_DMACSR_EI | \ + CS_DMACSR_PMI | \ + CS_DMACSR_PMIE | \ + CS_DMACSR_CMI | \ + CS_DMACSR_CMIE ) ) + +#define CS_DMACSR_CAPTURE_PAUSE (~( \ + CS_DMACSR_PPAUSE | \ + CS_DMACSR_GI | \ + CS_DMACSR_PI | \ + CS_DMACSR_CI | \ + CS_DMACSR_EI | \ + CS_DMACSR_PMI | \ + CS_DMACSR_PMIE | \ + CS_DMACSR_CMI | \ + CS_DMACSR_CMIE ) ) + +#define CS_DMACSR_INTR_MASK ( \ + CS_DMACSR_GI | \ + CS_DMACSR_PI | \ + CS_DMACSR_CI | \ + CS_DMACSR_EI | \ + CS_DMACSR_PMI | \ + CS_DMACSR_CMI ) diff --git a/sys/arch/sparc/dev/cs4231var.h b/sys/arch/sparc/dev/cs4231var.h new file mode 100644 index 00000000000..926e38bd81a --- /dev/null +++ b/sys/arch/sparc/dev/cs4231var.h @@ -0,0 +1,84 @@ +/* $OpenBSD: cs4231var.h,v 1.1 1999/06/06 04:48:24 jason Exp $ */ + +/* + * Copyright (c) 1999 Jason L. Wright (jason@thought.net) + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Jason L. Wright + * 4. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN + * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Driver for CS4231 based audio found in some sun4m systems + */ + +/* + * List of device memory allocations (see cs4231_malloc/cs4231_free). + */ +struct cs_dma { + struct cs_dma *next; + caddr_t addr; /* cpu address */ + caddr_t addr_dva; /* hardware address */ + size_t size; +}; + +struct cs_volume { + u_int8_t left; + u_int8_t right; +}; + +struct cs4231_softc { + struct device sc_dev; /* base device */ + struct sbusdev sc_sd; /* sbus device */ + struct intrhand sc_hwih; /* hardware interrupt vectoring */ + struct intrhand sc_swih; /* software interrupt vectoring */ + struct cs4231_regs *sc_regs; /* CS4231/APC registers */ + struct evcnt sc_intrcnt; /* statistics */ + int sc_node; /* which sbus node */ + int sc_burst; /* XXX: DMA burst size in effect */ + int sc_open; /* already open? */ + int sc_locked; /* locked? */ + + void (*sc_rintr)(void*); /* input completion intr handler */ + void * sc_rarg; /* arg for sc_rintr() */ + void (*sc_pintr)(void*); /* output completion intr handler */ + void * sc_parg; /* arg for sc_pintr() */ + + char mute[9]; /* which devs are muted */ + u_int8_t sc_out_port; /* output port */ + struct cs_volume sc_volume[9]; /* software volume */ + + int sc_format_bits; + int sc_speed_bits; + int sc_precision; + int sc_need_commit; + int sc_channels; + u_int32_t sc_blksz; + u_int32_t sc_playcnt; + u_int32_t sc_playsegsz; + struct cs_dma *sc_dmas; /* dma list */ + struct cs_dma *sc_nowplaying; +}; |