Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/tc Improve am7930 family drivers to share more code.



details:   https://anonhg.NetBSD.org/src/rev/0bce4a2c20fc
branches:  trunk
changeset: 938597:0bce4a2c20fc
user:      isaki <isaki%NetBSD.org@localhost>
date:      Sat Sep 12 05:19:15 2020 +0000

description:
Improve am7930 family drivers to share more code.
audioamd(4) on sparc, vsaudio(4) on vax, and bba(4) are.
- Remove complex and useless callbacks: onopen, onclose, and
  indirect_{read,write}.  This makes audioamd and vsaudio almost the same.
- Remove (already disabled) assembly fast interrupt path from audioamd(4).
  cf. http://mail-index.netbsd.org/source-changes/2009/12/19/msg004585.html
- Use trigger_* method rather than start_* method.  It's more suitable.
vsaudio(4) was tested by naru@, bba(4) was tested by tsutsui@.

diffstat:

 sys/arch/sparc/conf/files.sparc         |    3 +-
 sys/arch/sparc/dev/audioamd.c           |  319 +-----------------------------
 sys/arch/sparc/dev/audioamdvar.h        |   45 ----
 sys/arch/sparc/include/am7930_machdep.h |   14 -
 sys/arch/sparc/sparc/amd7930intr.s      |  205 --------------------
 sys/arch/sparc/sparc/genassym.cf        |   11 +-
 sys/arch/vax/vsa/vsaudio.c              |  324 ++-----------------------------
 sys/dev/ic/am7930.c                     |  241 ++++++++++++++++++++---
 sys/dev/ic/am7930var.h                  |   47 ++-
 sys/dev/tc/bba.c                        |  129 ++----------
 10 files changed, 306 insertions(+), 1032 deletions(-)

diffs (truncated from 1865 to 300 lines):

diff -r 1843ef62cfb9 -r 0bce4a2c20fc sys/arch/sparc/conf/files.sparc
--- a/sys/arch/sparc/conf/files.sparc   Sat Sep 12 01:36:26 2020 +0000
+++ b/sys/arch/sparc/conf/files.sparc   Sat Sep 12 05:19:15 2020 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files.sparc,v 1.159 2019/03/01 02:28:27 macallan Exp $
+#      $NetBSD: files.sparc,v 1.160 2020/09/12 05:19:15 isaki Exp $
 
 # @(#)files.sparc      8.1 (Berkeley) 7/19/93
 # sparc-specific configuration info
@@ -233,7 +233,6 @@
 attach audioamd at obio with audioamd_obio
 attach audioamd at sbus with audioamd_sbus
 file   arch/sparc/dev/audioamd.c               audioamd
-file   arch/sparc/sparc/amd7930intr.s          audioamd
 
 device apc
 attach apc at sbus
diff -r 1843ef62cfb9 -r 0bce4a2c20fc sys/arch/sparc/dev/audioamd.c
--- a/sys/arch/sparc/dev/audioamd.c     Sat Sep 12 01:36:26 2020 +0000
+++ b/sys/arch/sparc/dev/audioamd.c     Sat Sep 12 05:19:15 2020 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: audioamd.c,v 1.29 2019/05/08 13:40:16 isaki Exp $      */
+/*     $NetBSD: audioamd.c,v 1.30 2020/09/12 05:19:16 isaki Exp $      */
 /*     NetBSD: am7930_sparc.c,v 1.44 1999/03/14 22:29:00 jonathan Exp  */
 
 /*
@@ -32,7 +32,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: audioamd.c,v 1.29 2019/05/08 13:40:16 isaki Exp $");
+__KERNEL_RCSID(0, "$NetBSD: audioamd.c,v 1.30 2020/09/12 05:19:16 isaki Exp $");
 
 #include "audio.h"
 #if NAUDIO > 0
@@ -52,52 +52,14 @@
 
 #include <dev/ic/am7930reg.h>
 #include <dev/ic/am7930var.h>
-#include <sparc/dev/audioamdvar.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 */
-int    am7930hwintr(void *);
-struct auio *auiop;
-void   am7930swintr(void *);
-
-/* from amd7930intr.s: */
-void   amd7930_trap(void);
-
-/*
- * interrupt-handler status
- */
-struct am7930_intrhand {
-       int     (*ih_fun)(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    *sc_sicookie;           /* softintr(9) cookie */
-       kmutex_t        sc_lock;
 };
 
 int    audioamd_mainbus_match(device_t, cfdata_t, void *);
@@ -121,40 +83,25 @@
  * Define our interface into the am7930 MI driver.
  */
 
-uint8_t        audioamd_codec_iread(struct am7930_softc *, int);
-uint16_t       audioamd_codec_iread16(struct am7930_softc *, int);
-uint8_t        audioamd_codec_dread(struct audioamd_softc *, int);
-void   audioamd_codec_iwrite(struct am7930_softc *, int, uint8_t);
-void   audioamd_codec_iwrite16(struct am7930_softc *, int, uint16_t);
-void   audioamd_codec_dwrite(struct audioamd_softc *, int, uint8_t);
-void   audioamd_onopen(struct am7930_softc *);
-void   audioamd_onclose(struct am7930_softc *);
+uint8_t        audioamd_codec_dread(struct am7930_softc *, int);
+void   audioamd_codec_dwrite(struct am7930_softc *, int, uint8_t);
 
 struct am7930_glue audioamd_glue = {
-       audioamd_codec_iread,
-       audioamd_codec_iwrite,
-       audioamd_codec_iread16,
-       audioamd_codec_iwrite16,
-       audioamd_onopen,
-       audioamd_onclose,
+       audioamd_codec_dread,
+       audioamd_codec_dwrite,
 };
 
 /*
  * Define our interface to the higher level audio driver.
  */
-int    audioamd_start_output(void *, void *, int, void (*)(void *), void *);
-int    audioamd_start_input(void *, void *, int, void (*)(void *), void *);
 int    audioamd_getdev(void *, struct audio_device *);
-void   audioamd_get_locks(void *opaque, kmutex_t **intr, kmutex_t **thread);
 
 const struct audio_hw_if sa_hw_if = {
-       .open                   = am7930_open,
-       .close                  = am7930_close,
        .query_format           = am7930_query_format,
        .set_format             = am7930_set_format,
        .commit_settings        = am7930_commit_settings,
-       .start_output           = audioamd_start_output,        /* md */
-       .start_input            = audioamd_start_input,         /* md */
+       .trigger_output         = am7930_trigger_output,
+       .trigger_input          = am7930_trigger_input,
        .halt_output            = am7930_halt_output,
        .halt_input             = am7930_halt_input,
        .getdev                 = audioamd_getdev,
@@ -162,7 +109,7 @@
        .get_port               = am7930_get_port,
        .query_devinfo          = am7930_query_devinfo,
        .get_props              = am7930_get_props,
-       .get_locks              = audioamd_get_locks,
+       .get_locks              = am7930_get_locks,
 };
 
 struct audio_device audioamd_device = {
@@ -280,258 +227,42 @@
 void
 audioamd_attach(struct audioamd_softc *sc, int pri)
 {
+       struct am7930_softc *amsc = &sc->sc_am7930;
        device_t self;
 
        /*
         * Set up glue for MI code early; we use some of it here.
         */
-       self = sc->sc_am7930.sc_dev;
-       sc->sc_am7930.sc_glue = &audioamd_glue;
-       mutex_init(&sc->sc_lock, MUTEX_DEFAULT, IPL_HIGH);
-
-       am7930_init(&sc->sc_am7930, AUDIOAMD_POLL_MODE);
+       amsc->sc_glue = &audioamd_glue;
+       am7930_init(amsc, AUDIOAMD_POLL_MODE);
 
-       auiop = &sc->sc_au;
-
-       /* Copy bus tag & handle for use by am7930_trap */
-       sc->sc_au.au_bt = sc->sc_bt;
-       sc->sc_au.au_bh = sc->sc_bh;
        (void)bus_intr_establish2(sc->sc_bt, pri, IPL_HIGH,
-                                 am7930hwintr, sc,
-#ifdef notyet /* XXX amd7930intr.s needs to be fixed for MI softint(9) */
-                                 amd7930_trap
-#else
-                                 NULL
-#endif
-                                 );
+                                 am7930_hwintr, sc, NULL);
 
-       sc->sc_sicookie = softint_establish(SOFTINT_SERIAL, am7930swintr, sc);
-       if (sc->sc_sicookie == NULL) {
-               printf("\n%s: cannot establish software interrupt\n",
-                       device_xname(self));
-               return;
-       }
+       printf("\n");
 
-       printf(" softpri %d\n", IPL_SOFTAUDIO);
-
-
-       evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
+       self = amsc->sc_dev;
+       evcnt_attach_dynamic(&amsc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
            device_xname(self), "intr");
 
        audio_attach_mi(&sa_hw_if, sc, self);
 }
 
 
-void
-audioamd_onopen(struct am7930_softc *sc)
-{
-       struct audioamd_softc *mdsc;
-
-       mdsc = (struct audioamd_softc *)sc;
-
-       /* reset pdma state */
-       mutex_spin_enter(&mdsc->sc_lock);
-       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;
-       mutex_spin_exit(&mdsc->sc_lock);
-}
-
-
-void
-audioamd_onclose(struct am7930_softc *sc)
-{
-       /* On sparc, just do the chipset-level halt. */
-       am7930_halt_input(sc);
-       am7930_halt_output(sc);
-}
-
-int
-audioamd_start_output(void *addr, void *p, int cc,
-                     void (*intr)(void *), void *arg)
-{
-       struct audioamd_softc *sc;
-
-       DPRINTFN(1, ("sa_start_output: cc=%d %p (%p)\n", cc, intr, arg));
-       sc = addr;
-
-       mutex_spin_enter(&sc->sc_lock);
-       audioamd_codec_iwrite(&sc->sc_am7930,
-           AM7930_IREG_INIT, AM7930_INIT_PMS_ACTIVE);
-       sc->sc_pintr = intr;
-       sc->sc_parg = arg;
-       sc->sc_au.au_pdata = p;
-       sc->sc_au.au_pend = (char *)p + cc - 1;
-       mutex_spin_exit(&sc->sc_lock);
-
-       DPRINTF(("sa_start_output: started intrs.\n"));
-       return(0);
-}
-
-int
-audioamd_start_input(void *addr, void *p, int cc,
-                    void (*intr)(void *), void *arg)
-{
-       struct audioamd_softc *sc;
-
-       DPRINTFN(1, ("sa_start_input: cc=%d %p (%p)\n", cc, intr, arg));
-       sc = addr;
-
-       mutex_spin_enter(&sc->sc_lock);
-       audioamd_codec_iwrite(&sc->sc_am7930,
-           AM7930_IREG_INIT, AM7930_INIT_PMS_ACTIVE);
-       sc->sc_rintr = intr;
-       sc->sc_rarg = arg;
-       sc->sc_au.au_rdata = p;
-       sc->sc_au.au_rend = (char *)p + cc -1;
-       mutex_spin_exit(&sc->sc_lock);
-
-       DPRINTF(("sa_start_input: started intrs.\n"));
-
-       return(0);
-}
-
-
-/*
- * Pseudo-DMA support: either C or locore assember.
- */
-
-int
-am7930hwintr(void *v)
-{
-       struct audioamd_softc *sc;
-       struct auio *au;
-       uint8_t *d, *e;
-       int k;
-
-       sc = v;
-       au = &sc->sc_au;
-       mutex_spin_enter(&sc->sc_lock);
-
-       /* clear interrupt */
-       k = audioamd_codec_dread(sc, AM7930_DREG_IR);
-       if ((k & (AM7930_IR_DTTHRSH|AM7930_IR_DRTHRSH|AM7930_IR_DSRI|
-                 AM7930_IR_DERI|AM7930_IR_BBUFF)) == 0) {
-               mutex_spin_exit(&sc->sc_lock);
-               return 0;
-       }
-
-       /* 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++;



Home | Main Index | Thread Index | Old Index