Subject: port-sparc/10033: changes to NetBSD/sparc audio driver to utilise new am7930 driver structure
To: None <gnats-bugs@gnats.netbsd.org>
From: None <g.mcgarry@ieee.org>
List: netbsd-bugs
Date: 05/01/2000 15:34:39
>Number: 10033
>Category: port-sparc
>Synopsis: changes to NetBSD/sparc audio driver to utilise new am7930 driver structure
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: port-sparc-maintainer
>State: open
>Class: change-request
>Submitter-Id: net
>Arrival-Date: Mon May 01 15:35:00 PDT 2000
>Closed-Date:
>Last-Modified:
>Originator: Gregory McGarry
>Release: 1.4X
>Organization:
>Environment:
I don't have a sparc to test these patches on.
>Description:
The am7930 NetBSD/sparc audio driver was strongly tied to the am7930
driver. The am7930 driver needed to be changed to accommodate the
turbochannel audio (NetBSD/alpha and NetBSD/pmax) [kern/10032]. These
changes to the NetBSD/sparc audio driver use the new am7930 driver
structure.
>How-To-Repeat:
>Fix:
*** audioamd.c.orig Thu Dec 23 15:24:12 1999
--- audioamd.c Thu Dec 23 16:31:56 1999
***************
*** 0 ****
--- 1,521 ----
+ /* $NetBSD$ */
+ /* NetBSD: am7930_sparc.c,v 1.44 1999/03/14 22:29:00 jonathan Exp */
+
+ /*
+ * Copyright (c) 1995 Rolf Grossmann
+ * 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 Rolf Grossmann.
+ * 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.
+ */
+
+ #include "audio.h"
+ #if NAUDIO > 0
+
+ #include <sys/param.h>
+ #include <sys/systm.h>
+ #include <sys/errno.h>
+ #include <sys/device.h>
+
+ #include <machine/bus.h>
+ #include <machine/autoconf.h>
+ #include <machine/cpu.h>
+
+ #include <sys/audioio.h>
+ #include <dev/audio_if.h>
+
+ #include <dev/ic/am7930reg.h>
+ #include <dev/ic/am7930var.h>
+
+ #define AUDIO_ROM_NAME "audio"
+
+ #ifdef AUDIO_DEBUG
+ #define DPRINTF(x) if (am7930debug) printf x
+ #define DPRINTFN(n,x) if (am7930debug>(n)) printf x
+ #else
+ #define DPRINTF(x)
+ #define DPRINTFN(n,x)
+ #endif /* AUDIO_DEBUG */
+
+
+ /* interrupt interfaces */
+ #ifdef AUDIO_C_HANDLER
+ int am7930hwintr __P((void *));
+ #if defined(SUN4M)
+ #define AUDIO_SET_SWINTR do { \
+ if (CPU_ISSUN4M) \
+ raise(0, 4); \
+ else \
+ ienab_bis(IE_L4); \
+ } while(0);
+ #else
+ #define AUDIO_SET_SWINTR ienab_bis(IE_L4)
+ #endif /* defined(SUN4M) */
+ #else
+ struct auio *auiop;
+ #endif /* AUDIO_C_HANDLER */
+ int am7930swintr __P((void *));
+
+ /*
+ * pdma state
+ */
+ struct auio {
+ bus_space_tag_t au_bt; /* bus tag */
+ bus_space_handle_t au_bh; /* handle to chip registers */
+
+ u_int8_t *au_rdata; /* record data */
+ u_int8_t *au_rend; /* end of record data */
+ u_int8_t *au_pdata; /* play data */
+ u_int8_t *au_pend; /* end of play data */
+ struct evcnt au_intrcnt; /* statistics */
+ };
+
+ /*
+ * interrupt-handler status
+ */
+ struct am7930_intrhand {
+ int (*ih_fun) __P((void *));
+ void *ih_arg;
+ };
+
+ struct audioamd_softc {
+ struct am7930_softc sc_am7930; /* glue to MI code */
+
+ bus_space_tag_t sc_bt; /* bus cookie */
+ bus_space_handle_t sc_bh; /* device registers */
+
+ struct am7930_intrhand sc_ih; /* interrupt vector (hw or sw) */
+ 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() */
+
+ /* sc_au is special in that the hardware interrupt handler uses it */
+ struct auio sc_au; /* recv and xmit buffers, etc */
+ #define sc_intrcnt sc_au.au_intrcnt /* statistics */
+ };
+
+ void audioamd_mainbus_attach __P((struct device *,
+ struct device *, void *));
+ int audioamd_mainbus_match __P((struct device *, struct cfdata *, void *));
+ void audioamd_sbus_attach __P((struct device *, struct device *, void *));
+ int audioamd_sbus_match __P((struct device *, struct cfdata *, void *));
+ void audioamd_attach(struct audioamd_softc *sc, int);
+
+ struct cfattach audioamd_mainbus_ca = {
+ sizeof(struct audioamd_softc),
+ audioamd_mainbus_match,
+ audioamd_mainbus_attach
+ };
+
+ struct cfattach audioamd_sbus_ca = {
+ sizeof(struct audioamd_softc),
+ audioamd_sbus_match,
+ audioamd_sbus_attach
+ };
+
+ /*
+ * Define our interface into the am7930 MI driver.
+ */
+
+ u_int8_t audioamd_codec_iread __P((struct am7930_softc *, int));
+ u_int16_t audioamd_codec_iread16 __P((struct am7930_softc *, int));
+ void audioamd_codec_iwrite __P((struct am7930_softc *, int, u_int8_t));
+ void audioamd_codec_iwrite16 __P((struct am7930_softc *, int, u_int16_t));
+ void audioamd_onopen __P((struct am7930_softc *sc));
+ void audioamd_onclose __P((struct am7930_softc *sc));
+
+ struct am7930_glue audioamd_glue = {
+ audioamd_codec_iread,
+ audioamd_codec_iwrite,
+ audioamd_codec_iread16,
+ audioamd_codec_iwrite16,
+ audioamd_onopen,
+ audioamd_onclose,
+ 0,
+ 0,
+ 0,
+ };
+
+ /*
+ * Define our interface to the higher level audio driver.
+ */
+ int audioamd_start_output __P((void *, void *, int, void (*)(void *),
+ void *));
+ int audioamd_start_input __P((void *, void *, int, void (*)(void *),
+ void *));
+
+ struct audio_hw_if sa_hw_if = {
+ am7930_open,
+ am7930_close,
+ 0,
+ am7930_query_encoding,
+ am7930_set_params,
+ am7930_round_blocksize,
+ am7930_commit_settings,
+ 0,
+ 0,
+ audioamd_start_output, /* md */
+ audioamd_start_input, /* md */
+ am7930_halt_output,
+ am7930_halt_input,
+ 0,
+ audioamd_getdev,
+ 0,
+ am7930_set_port,
+ am7930_get_port,
+ am7930_query_devinfo,
+ 0,
+ 0,
+ 0,
+ 0,
+ am7930_get_props,
+ };
+
+ struct audio_device audioamd_device = {
+ "am7930",
+ "x",
+ "audioamd"
+ };
+
+
+ int
+ audioamd_mainbus_match(parent, cf, aux)
+ struct device *parent;
+ struct cfdata *cf;
+ void *aux;
+ {
+ struct mainbus_attach_args *ma = aux;
+
+ if (CPU_ISSUN4)
+ return (0);
+ return (strcmp(AUDIO_ROM_NAME, ma->ma_name) == 0);
+ }
+
+ int
+ audioamd_sbus_match(parent, cf, aux)
+ struct device *parent;
+ struct cfdata *cf;
+ void *aux;
+ {
+ struct sbus_attach_args *sa = aux;
+
+ return (strcmp(AUDIO_ROM_NAME, sa->sa_name) == 0);
+ }
+
+ void
+ audioamd_mainbus_attach(parent, self, aux)
+ struct device *parent, *self;
+ void *aux;
+ {
+ struct mainbus_attach_args *ma = aux;
+ struct audioamd_softc *sc = (struct audioamd_softc *)self;
+ bus_space_handle_t bh;
+
+ sc->sc_bt = ma->ma_bustag;
+
+ if (bus_space_map2(
+ ma->ma_bustag,
+ ma->ma_iospace,
+ ma->ma_paddr,
+ sizeof(struct am7930),
+ BUS_SPACE_MAP_LINEAR,
+ 0,
+ &bh) != 0) {
+ printf("%s: cannot map registers\n", self->dv_xname);
+ return;
+ }
+ sc->sc_bh = bh;
+ audioamd_attach(sc, ma->ma_pri);
+ }
+
+
+ void
+ audioamd_sbus_attach(parent, self, aux)
+ struct device *parent, *self;
+ void *aux;
+ {
+ struct sbus_attach_args *sa = aux;
+ struct audioamd_softc *sc = (struct audioamd_softc *)self;
+ bus_space_handle_t bh;
+
+ sc->sc_bt = sa->sa_bustag;
+
+ if (sbus_bus_map(
+ sa->sa_bustag,
+ sa->sa_slot,
+ sa->sa_offset,
+ sizeof(struct am7930),
+ 0, 0,
+ &bh) != 0) {
+ printf("%s: cannot map registers\n", self->dv_xname);
+ return;
+ }
+ sc->sc_bh = bh;
+ audioamd_attach(sc, sa->sa_pri);
+ }
+
+ void
+ audioamd_attach(sc, pri)
+ struct audioamd_softc *sc;
+ int pri;
+ {
+
+ printf(" softpri %d\n", PIL_AUSOFT);
+
+ /*
+ * Set up glue for MI code early; we use some of it here.
+ */
+ sc->sc_glue = &audioamd_glue;
+
+ am7930_init(sc, AUDIOAMD_POLL_MODE);
+
+ #ifndef AUDIO_C_HANDLER
+ auiop = &sc->sc_au;
+ (void)bus_intr_establish(sc->sc_bt, pri,
+ BUS_INTR_ESTABLISH_FASTTRAP,
+ (int (*) __P((void *)))amd7930_trap, NULL);
+ #else
+ (void)bus_intr_establish(sc->sc_bt, pri, 0,
+ am7930hwintr, &sc->sc_au);
+ #endif
+ (void)bus_intr_establish(sc->sc_bt, PIL_AUSOFT,
+ BUS_INTR_ESTABLISH_SOFTINTR,
+ am7930swintr, sc);
+
+ evcnt_attach(&sc->sc_dev, "intr", &sc->sc_intrcnt);
+
+ audio_attach_mi(&sa_hw_if, sc, &sc->sc_dev);
+ }
+
+
+ void
+ audioamd_onopen(sc)
+ struct am7930_softc *sc;
+ {
+ struct audioamd_softc *mdsc = (struct audioamd *)sc;
+
+ /* reset pdma state */
+ mdsc->sc_rintr = 0;
+ mdsc->sc_rarg = 0;
+ mdsc->sc_pintr = 0;
+ mdsc->sc_parg = 0;
+
+ mdsc->sc_au.au_rdata = 0;
+ mdsc->sc_au.au_pdata = 0;
+ }
+
+
+ void
+ audioamd_onclose(sc)
+ struct am7930_softc *sc;
+ {
+ /* On sparc, just do the chipset-level halt. */
+ am7930_halt_input(sc);
+ am7930_halt_output(sc);
+ }
+
+ int
+ audioamd_output(addr, p, cc, intr, arg)
+ void *addr;
+ void *p;
+ int cc;
+ void (*intr) __P((void *));
+ void *arg;
+ {
+ struct audioamd_softc *sc = addr;
+
+ DPRINTFN(1, ("sa_start_output: cc=%d %p (%p)\n", cc, intr, arg));
+
+ if (!sc->sc_locked) {
+ audioamd_codec_iwrite(sc,
+ AM7930_IREG_INIT, AM7930_INIT_PMS_ACTIVE);
+ sc->sc_locked = 1;
+ DPRINTF(("sa_start_output: started intrs.\n"));
+ }
+ sc->sc_pintr = intr;
+ sc->sc_parg = arg;
+ sc->sc_au.au_pdata = p;
+ sc->sc_au.au_pend = (char *)p + cc - 1;
+ return(0);
+ }
+
+ int
+ am7930_start_input(addr, p, cc, intr, arg)
+ void *addr;
+ void *p;
+ int cc;
+ void (*intr) __P((void *));
+ void *arg;
+ {
+ struct audioamd_softc *sc = addr;
+
+ DPRINTFN(1, ("sa_start_input: cc=%d %p (%p)\n", cc, intr, arg));
+
+ if (!sc->sc_locked) {
+ audioamd_codec_iwrite(sc,
+ AM7930_IREG_INIT, AM7930_INIT_PMS_ACTIVE);
+ sc->sc_locked = 1;
+ DPRINTF(("sa_start_input: started intrs.\n"));
+ }
+ sc->sc_rintr = intr;
+ sc->sc_rarg = arg;
+ sc->sc_au.au_rdata = p;
+ sc->sc_au.au_rend = (char *)p + cc -1;
+ return(0);
+ }
+
+
+ /*
+ * Pseudo-DMA support: either C or locore assember.
+ */
+
+ #ifdef AUDIO_C_HANDLER
+ int
+ am7930hwintr(au0)
+ void *au0;
+ {
+ struct auio *au = au0;
+ u_int8_t *d, *e;
+ int k;
+
+ /* XXX where is sc? */
+
+ /* clear interrupt */
+ k = audioamd_codec_dread(sc, AM7930_DREG_IR);
+
+ /* receive incoming data */
+ d = au->au_rdata;
+ e = au->au_rend;
+ if (d && d <= e) {
+ *d = audioamd_codec_dread(sc, AM7930_DREG_BBRB);
+ au->au_rdata++;
+ if (d == e) {
+ DPRINTFN(1, ("am7930hwintr: swintr(r) requested"));
+ AUDIO_SET_SWINTR;
+ }
+ }
+
+ /* send outgoing data */
+ d = au->au_pdata;
+ e = au->au_pend;
+ if (d && d <= e) {
+ audioamd_codec_dwrite(sc, AM7930_DREG_BBTB, *d);
+ au->au_pdata++;
+ if (d == e) {
+ DPRINTFN(1, ("am7930hwintr: swintr(p) requested"));
+ AUDIO_SET_SWINTR;
+ }
+ }
+
+ *(au->au_intrcnt)++;
+ return (1);
+ }
+ #endif /* AUDIO_C_HANDLER */
+
+ int
+ am7930swintr(sc0)
+ void *sc0;
+ {
+ struct audioamd_softc *sc = sc0;
+ struct auio *au;
+ int s, ret = 0;
+
+ DPRINTFN(1, ("audiointr: sc=%p\n", sc););
+
+ au = &sc->sc_au;
+ s = splaudio();
+ if (au->au_rdata > au->au_rend && sc->sc_rintr != NULL) {
+ splx(s);
+ ret = 1;
+ (*sc->sc_rintr)(sc->sc_rarg);
+ s = splaudio();
+ }
+ if (au->au_pdata > au->au_pend && sc->sc_pintr != NULL) {
+ splx(s);
+ ret = 1;
+ (*sc->sc_pintr)(sc->sc_parg);
+ } else
+ splx(s);
+ return (ret);
+ }
+
+
+ /* indirect write */
+ void
+ audioamd_codec_iwrite(sc, reg, val)
+ struct am7930_softc *sc;
+ int reg;
+ u_int8_t val;
+ {
+ audioamd_codec_dwrite(sc, AM7930_DREG_CR, reg);
+ audioamd_codec_dwrite(sc, AM7930_DREG_DR, val);
+ }
+
+
+ void
+ audioamd_codec_iwrite16(sc, reg, val)
+ struct am7930_softc *sc;
+ int reg;
+ u_int16_t val;
+ {
+ audioamd_codec_dwrite(sc, AM7930_DREG_CR, reg);
+ audioamd_codec_dwrite(sc, AM7930_DREG_DR, val);
+ audioamd_codec_dwrite(sc, AM7930_DREG_DR, val>>8);
+ }
+
+
+ /* indirect read */
+ u_int8_t
+ audioamd_codec_iread(sc, reg)
+ struct am7930_softc *sc;
+ int reg;
+ {
+ audioamd_codec_dwrite(sc, AM7930_DREG_CR, reg);
+ return audioamd_codec_dread(sc, AM7930_DREG_DR);
+ }
+
+ /* direct write */
+ void
+ audioamd_codec_dwrite(sc, reg, val)
+ struct am7930_softc *sc;
+ int reg;
+ u_int8_t val;
+ {
+ struct audioamd_softc *mdsc = (struct audioamd_softc *)sc;
+ bus_space_write_1(mdsc->sc_bt, mdsc->sc_bh, reg, val);
+ }
+
+ /* direct read */
+ u_int8_t
+ bba_codec_dread(sc, reg)
+ struct am7930_softc *sc;
+ int reg;
+ {
+ struct audioamd_softc *mdsc = (struct audioamd_softc *)sc;
+ return bus_space_read_1(mdsc->sc_bt, mdsc->sc_bh, reg);
+ }
+
+ #endif /* NAUDIO > 0 */
*** files.sparc.orig Thu Dec 23 15:25:14 1999
--- files.sparc Thu Dec 23 16:37:09 1999
***************
*** 129,138 ****
attach esp at obio with esp_obio
file arch/sparc/dev/esp_obio.c esp_obio
! attach audioamd at mainbus with audioamd_mainbus
! attach audioamd at sbus with audioamd_sbus
! file arch/sparc/dev/am7930_sparc.c audioamd
! file arch/sparc/sparc/amd7930intr.s audioamd
# Brooktree DAC attribute
define bt_dac
--- 129,139 ----
attach esp at obio with esp_obio
file arch/sparc/dev/esp_obio.c esp_obio
! device audioamd: audio, am7930
! attach audioamd at mainbus with audioamd_mainbus
! attach audioamd at sbus with audioamd_sbus
! file arch/sparc/dev/audioamd.c audioamd
! file arch/sparc/sparc/am7930intr.s audioamd
# Brooktree DAC attribute
define bt_dac
>Release-Note:
>Audit-Trail:
>Unformatted: