Source-Changes-HG archive

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

[src/trunk]: src/sys Make am7930 driver machine independent. PR 10032 from Gr...



details:   https://anonhg.NetBSD.org/src/rev/1398e2e403db
branches:  trunk
changeset: 485611:1398e2e403db
user:      augustss <augustss%NetBSD.org@localhost>
date:      Tue May 02 06:30:49 2000 +0000

description:
Make am7930 driver machine independent. PR 10032 from Gregory McGarry.

diffstat:

 sys/conf/files         |    6 +-
 sys/dev/ic/am7930.c    |  432 ++++++++++++++++++++++++++++++++++++------------
 sys/dev/ic/am7930reg.h |  304 +++++++++++++++++-----------------
 sys/dev/ic/am7930var.h |  184 +++++---------------
 4 files changed, 526 insertions(+), 400 deletions(-)

diffs (truncated from 1133 to 300 lines):

diff -r cb54ab2d60ed -r 1398e2e403db sys/conf/files
--- a/sys/conf/files    Tue May 02 05:17:45 2000 +0000
+++ b/sys/conf/files    Tue May 02 06:30:49 2000 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files,v 1.365 2000/04/25 06:08:31 itojun Exp $
+#      $NetBSD: files,v 1.366 2000/05/02 06:30:49 augustss Exp $
 
 #      @(#)files.newconf       7.5 (Berkeley) 5/10/93
 
@@ -405,8 +405,8 @@
 file   dev/ic/ad1848.c                 ad1848
 
 # AMD 7930 audio/ISDN codec
-device audioamd: audio
-file   dev/ic/am7930.c                 audioamd
+define am7930
+file   dev/ic/am7930.c                 am7930
 
 # SPARC `SUNW,audiocs'
 device audiocs: audio, auconv, ad1848
diff -r cb54ab2d60ed -r 1398e2e403db sys/dev/ic/am7930.c
--- a/sys/dev/ic/am7930.c       Tue May 02 05:17:45 2000 +0000
+++ b/sys/dev/ic/am7930.c       Tue May 02 06:30:49 2000 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: am7930.c,v 1.42 2000/03/30 12:45:29 augustss Exp $     */
+/*     $NetBSD: am7930.c,v 1.43 2000/05/02 06:30:51 augustss Exp $     */
 
 /*
  * Copyright (c) 1995 Rolf Grossmann
@@ -32,7 +32,7 @@
 
 /*
  * Front-end attachment independent layer for AMD 79c30
- * audio driver. XXX isdn support??
+ * audio driver.  No ISDN support.
  */
 
 #include "audio.h"
@@ -53,31 +53,15 @@
 #include <dev/audio_if.h>
 
 #include <dev/ic/am7930reg.h>
-#include <machine/am7930_machdep.h>
 #include <dev/ic/am7930var.h>
 
-#define AUDIO_ROM_NAME "audio"
-
 #ifdef AUDIO_DEBUG
-
 int     am7930debug = 0;
 #define DPRINTF(x)      if (am7930debug) printf x
 #else
 #define DPRINTF(x)
 #endif
 
-/* forward declarations */
-static void init_amd __P((bus_space_tag_t bt, bus_space_handle_t bh));
-
-/*
- * Audio device descriptor (attachment independent)
- */
-
-struct audio_device am7930_device = {
-       "amd7930",
-       "x",
-       "audioamd"
-};
 
 /* The following tables stolen from former (4.4Lite's) sys/sparc/bsd_audio.c */
 
@@ -155,46 +139,58 @@
  * Reset chip and set boot-time softc defaults.
  */
 void
-am7930_init(sc)
+am7930_init(sc, flag)
        struct am7930_softc *sc;
+       int flag;
 {
-       /* Save bustag and handle in pdma struct. XXX is this MI? */
-       sc->sc_au.au_bt =  sc->sc_bustag;
-       sc->sc_au.au_bh =  sc->sc_bh;
 
-       sc->sc_map.mr_mmr1 = AMD_MMR1_GX | AMD_MMR1_GER |
-                            AMD_MMR1_GR | AMD_MMR1_STG;
+       DPRINTF(("am7930_init()\n"));
 
        /* set boot defaults */
        sc->sc_rlevel = 128;
        sc->sc_plevel = 128;
        sc->sc_mlevel = 0;
-       sc->sc_out_port = SUNAUDIO_SPEAKER;
-       init_amd(sc->sc_bustag, sc->sc_bh);
+       sc->sc_out_port = AUDIOAMD_SPEAKER_VOL;
+       sc->sc_mic_mute = 0;
+
+       /* disable sample interrupts */
+       AM7930_IWRITE(sc, AM7930_IREG_MUX_MCR4, 0);
+
+       /* initialise voice and data, and disable interrupts */
+       AM7930_IWRITE(sc, AM7930_IREG_INIT,
+               AM7930_INIT_PMS_ACTIVE | AM7930_INIT_INT_DISABLE);
+
+       if (flag == AUDIOAMD_DMA_MODE) {
+
+               /* configure PP for serial (SBP) mode */
+               AM7930_IWRITE(sc, AM7930_IREG_PP_PPCR1, AM7930_PPCR1_SBP);
+
+               /*
+                * Initialise the MUX unit - route the MAP to the PP
+                */
+               AM7930_IWRITE(sc, AM7930_IREG_MUX_MCR1,
+                       (AM7930_MCRCHAN_BA << 4) | AM7930_MCRCHAN_BD);
+               AM7930_IWRITE(sc, AM7930_IREG_MUX_MCR2, AM7930_MCRCHAN_NC);
+               AM7930_IWRITE(sc, AM7930_IREG_MUX_MCR3, AM7930_MCRCHAN_NC);
+
+       } else {
+
+               /*
+                * Initialize the MUX unit.  We use MCR3 to route the MAP
+                * through channel Bb.  MCR1 and MCR2 are unused.
+                * Setting the INT enable bit in MCR4 will generate an
+                * interrupt on each converted audio sample.
+                */
+               AM7930_IWRITE(sc, AM7930_IREG_MUX_MCR1, 0);
+               AM7930_IWRITE(sc, AM7930_IREG_MUX_MCR2, 0);
+               AM7930_IWRITE(sc, AM7930_IREG_MUX_MCR3,
+                       (AM7930_MCRCHAN_BB << 4) | AM7930_MCRCHAN_BA);
+               AM7930_IWRITE(sc, AM7930_IREG_MUX_MCR4,
+                       AM7930_MCR4_INT_ENABLE);
+       }
+
 }
 
-static void
-init_amd(bt, bh)
-       bus_space_tag_t bt;
-       bus_space_handle_t bh;
-{
-       /* disable interrupts */
-       AM7930_WRITE_REG(bt, bh, cr, AMDR_INIT);
-       AM7930_WRITE_REG(bt, bh, dr, 
-           AMD_INIT_PMS_ACTIVE | AMD_INIT_INT_DISABLE);
-
-       /*
-        * Initialize the mux unit.  We use MCR3 to route audio (MAP)
-        * through channel Bb.  MCR1 and MCR2 are unused.
-        * Setting the INT enable bit in MCR4 will generate an interrupt
-        * on each converted audio sample.
-        */
-       AM7930_WRITE_REG(bt, bh, cr, AMDR_MUX_1_4);
-       AM7930_WRITE_REG(bt, bh, dr, 0);
-       AM7930_WRITE_REG(bt, bh, dr, 0);
-       AM7930_WRITE_REG(bt, bh, dr, (AMD_MCRCHAN_BB << 4) | AMD_MCRCHAN_BA);
-       AM7930_WRITE_REG(bt, bh, dr, AMD_MCR4_INT_ENABLE);
-}
 
 int
 am7930_open(addr, flags)
@@ -210,8 +206,7 @@
        sc->sc_open = 1;
        sc->sc_locked = 0;
 
-       /* tell attach layer about open */
-       sc->sc_onopen(sc);
+       sc->sc_glue->onopen(sc);
 
        DPRINTF(("saopen: ok -> sc=0x%p\n",sc));
 
@@ -225,27 +220,49 @@
        struct am7930_softc *sc = addr;
 
        DPRINTF(("sa_close: sc=%p\n", sc));
-       /*
-        * halt i/o, clear open flag, and done.
-        */
-       sc->sc_onclose(sc);
+
+       sc->sc_glue->onclose(sc);
        sc->sc_open = 0;
 
        DPRINTF(("sa_close: closed.\n"));
 }
 
+
+/*
+ * XXX should be extended to handle a few of the more common formats.
+ */
 int
 am7930_set_params(addr, setmode, usemode, p, r)
        void *addr;
        int setmode, usemode;
        struct audio_params *p, *r;
 {
-       if (p->sample_rate < 7500 || p->sample_rate > 8500 ||
-           p->encoding != AUDIO_ENCODING_ULAW ||
-           p->precision != 8 ||
-           p->channels != 1)
-               return EINVAL;
-       p->sample_rate = 8000;  /* no other sampling rates supported by amd chip */
+       struct am7930_softc *sc = addr;
+
+       if ((usemode & AUMODE_PLAY) == AUMODE_PLAY) {
+               if (p->sample_rate < 7500 || p->sample_rate > 8500 ||
+                       p->encoding != AUDIO_ENCODING_ULAW ||
+                       p->precision != 8 ||
+                       p->channels != 1)
+                               return EINVAL;
+               p->sample_rate = 8000;
+               if (sc->sc_glue->factor > 1) {
+                       p->factor = sc->sc_glue->factor;
+                       p->sw_code = sc->sc_glue->output_conv;
+               }
+       }
+       if ((usemode & AUMODE_RECORD) == AUMODE_RECORD) {
+               if (r->sample_rate < 7500 || r->sample_rate > 8500 ||
+                       r->encoding != AUDIO_ENCODING_ULAW ||
+                       r->precision != 8 ||
+                       r->channels != 1)
+                               return EINVAL;
+               r->sample_rate = 8000;
+               if (sc->sc_glue->factor > 1) {
+                       r->factor = sc->sc_glue->factor;
+                       r->sw_code = sc->sc_glue->input_conv;
+               }
+       }
 
        return 0;
 }
@@ -278,103 +295,90 @@
        return(blk);
 }
 
+
 int
 am7930_commit_settings(addr)
        void *addr;
 {
        struct am7930_softc *sc = addr;
-       struct mapreg *map;
-       bus_space_tag_t bt = sc->sc_bustag;
-       bus_space_handle_t bh = sc->sc_bh;
+       u_int16_t ger, gr, gx, stgr;
+       u_int8_t mmr2, mmr3;
        int s, level;
 
        DPRINTF(("sa_commit.\n"));
 
-       map = &sc->sc_map;
-
-       map->mr_gx = gx_coeff[sc->sc_rlevel];
-       map->mr_stgr = gx_coeff[sc->sc_mlevel];
+       gx = gx_coeff[sc->sc_rlevel];
+       stgr = gx_coeff[sc->sc_mlevel];
 
        level = (sc->sc_plevel * (256 + NGER)) >> 8;
        if (level >= 256) {
-               map->mr_ger = ger_coeff[level - 256];
-               map->mr_gr = gx_coeff[255];
+               ger = ger_coeff[level - 256];
+               gr = gx_coeff[255];
        } else {
-               map->mr_ger = ger_coeff[0];
-               map->mr_gr = gx_coeff[level];
+               ger = ger_coeff[0];
+               gr = gx_coeff[level];
        }
 
-       if (sc->sc_out_port == SUNAUDIO_SPEAKER)
-               map->mr_mmr2 |= AMD_MMR2_LS;
-       else
-               map->mr_mmr2 &= ~AMD_MMR2_LS;
-
        s = splaudio();
 
-       AM7930_WRITE_REG(bt, bh, cr, AMDR_MAP_MMR1);
-       AM7930_WRITE_REG(bt, bh, dr, map->mr_mmr1);
-       AM7930_WRITE_REG(bt, bh, cr, AMDR_MAP_GX);
-       WAMD16(bt, bh, map->mr_gx);
-
-       AM7930_WRITE_REG(bt, bh, cr, AMDR_MAP_STG);
-       WAMD16(bt, bh, map->mr_stgr);
+       mmr2 = AM7930_IREAD(sc, AM7930_IREG_MAP_MMR2);
+       if (sc->sc_out_port == AUDIOAMD_SPEAKER_VOL)
+               mmr2 |= AM7930_MMR2_LS;
+       else
+               mmr2 &= ~AM7930_MMR2_LS;
+       AM7930_IWRITE(sc, AM7930_IREG_MAP_MMR2, mmr2);
 
-       AM7930_WRITE_REG(bt, bh, cr, AMDR_MAP_GR);
-       WAMD16(bt, bh, map->mr_gr);
+       mmr3 = AM7930_IREAD(sc, AM7930_IREG_MAP_MMR3);
+       if (sc->sc_mic_mute)
+               mmr3 |= AM7930_MMR3_MUTE;
+       else
+               mmr3 &= ~AM7930_MMR3_MUTE;
+       AM7930_IWRITE(sc, AM7930_IREG_MAP_MMR3, mmr3);
 
-       AM7930_WRITE_REG(bt, bh, cr, AMDR_MAP_GER);
-       WAMD16(bt, bh, map->mr_ger);



Home | Main Index | Thread Index | Old Index