Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci auich_softc:



details:   https://anonhg.NetBSD.org/src/rev/0d203d99df5d
branches:  trunk
changeset: 537911:0d203d99df5d
user:      kent <kent%NetBSD.org@localhost>
date:      Tue Oct 08 10:25:45 2002 +0000

description:
auich_softc:
Remove sc_fixed_rate and sc_ac97rate.  ac97_softc has such
information.

auich_attach():
Remove VRA/VRM enabling code.  ac97_attach() does it.

auich_set_rate():
Use ac97_codec_if::set_rate().

auich_get_props():
Return no AUDIO_PROP_MMAP if the codec is fixed-rate.

auichreg.h:
Remove unnecessary ICH_PM_*.

diffstat:

 sys/dev/pci/auich.c    |  88 +++++++++++++++----------------------------------
 sys/dev/pci/auichreg.h |   7 +---
 2 files changed, 29 insertions(+), 66 deletions(-)

diffs (200 lines):

diff -r 40aa7a9475ef -r 0d203d99df5d sys/dev/pci/auich.c
--- a/sys/dev/pci/auich.c       Tue Oct 08 09:59:27 2002 +0000
+++ b/sys/dev/pci/auich.c       Tue Oct 08 10:25:45 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: auich.c,v 1.26 2002/10/06 16:33:36 kent Exp $  */
+/*     $NetBSD: auich.c,v 1.27 2002/10/08 10:25:45 kent Exp $  */
 
 /*-
  * Copyright (c) 2000 The NetBSD Foundation, Inc.
@@ -114,7 +114,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: auich.c,v 1.26 2002/10/06 16:33:36 kent Exp $");
+__KERNEL_RCSID(0, "$NetBSD: auich.c,v 1.27 2002/10/08 10:25:45 kent Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -202,9 +202,7 @@
 
        struct auich_dma *sc_dmas;
 
-       int sc_fixed_rate;
        int sc_calibrated;      /* sc_ac97rate has correct value */
-       int sc_ac97rate;
        int sc_ignore_codecready;
 
        /* SiS 7012 hack */
@@ -223,7 +221,8 @@
        u_int16_t ext_status;
 };
 
-#define FIXED_RATE 48000
+#define IS_FIXED_RATE(codec)   !((codec)->vtbl->get_extcaps(codec) \
+                                 & AC97_EXT_AUDIO_VRA)
 
 /* Debug */
 #ifdef AUDIO_DEBUG
@@ -272,7 +271,7 @@
 int    auich_freemem(struct auich_softc *, struct auich_dma *);
 
 void   auich_powerhook(int, void *);
-int    auich_set_rate(struct auich_softc *sc, int mode, uint srate);
+int    auich_set_rate(struct auich_softc *sc, int mode, u_long* srate);
 unsigned int auich_calibrate(struct auich_softc *sc);
 
 
@@ -376,7 +375,6 @@
        pcireg_t csr;
        const char *intrstr;
        const struct auich_devtype *d;
-       u_int16_t ext_id, ext_status;
        u_int32_t status;
 
        d = auich_lookup(pa);
@@ -448,7 +446,6 @@
        DPRINTF(ICH_DEBUG_DMA, ("auich_attach: lists %p %p %p\n",
            sc->dmalist_pcmo, sc->dmalist_pcmi, sc->dmalist_mici));
 
-       sc->sc_ac97rate = FIXED_RATE;
        /* Reset codec and AC'97 */
        auich_reset_codec(sc);
        status = bus_space_read_4(sc->iot, sc->aud_ioh, ICH_GSTS);
@@ -478,26 +475,6 @@
        if (ac97_attach(&sc->host_if) != 0)
                return;
 
-       auich_read_codec(sc, AC97_REG_EXT_AUDIO_ID, &ext_id);
-       if ((ext_id & (AC97_EXT_AUDIO_VRA | AC97_EXT_AUDIO_VRM)) != 0) {
-               auich_read_codec(sc, AC97_REG_EXT_AUDIO_CTRL, &ext_status);
-               if ((ext_id & AC97_EXT_AUDIO_VRA) != 0)
-                       ext_status |= AC97_EXT_AUDIO_VRA;
-               if ((ext_id & AC97_EXT_AUDIO_VRM) != 0)
-                       ext_status |= AC97_EXT_AUDIO_VRM;
-               auich_write_codec(sc, AC97_REG_EXT_AUDIO_CTRL, ext_status);
-
-               /* so it claims to do variable rate, let's make sure */
-               if (auich_set_rate(sc, AUMODE_PLAY, 44100) == 44100)
-                       sc->sc_fixed_rate = 0;
-               else
-                       sc->sc_fixed_rate = FIXED_RATE;
-       } else {
-               sc->sc_fixed_rate = FIXED_RATE;
-       }
-       if (sc->sc_fixed_rate)
-               printf("%s: warning, fixed rate codec\n", sc->sc_dev.dv_xname);
-
        audio_attach_mi(&auich_hw_if, sc, &sc->sc_dev);
 
        /* Watch for power change */
@@ -601,9 +578,10 @@
 auich_open(void *v, int flags)
 {
        struct auich_softc *sc = v;
+       struct ac97_codec_if *codec = sc->codec_if;
 
-       if (!sc->sc_fixed_rate && !sc->sc_calibrated) {
-               sc->sc_ac97rate = auich_calibrate(sc);
+       if (!IS_FIXED_RATE(codec) && !sc->sc_calibrated) {
+               codec->vtbl->set_clock(codec, auich_calibrate(sc));
                sc->sc_calibrated = TRUE;
        }
        return 0;
@@ -680,30 +658,13 @@
 }
 
 int
-auich_set_rate(struct auich_softc *sc, int mode, uint srate)
+auich_set_rate(struct auich_softc *sc, int mode, u_long* srate)
 {
-       u_int16_t val, rate, inout;
-       u_int32_t rvalue;
-
-       inout = mode == AUMODE_PLAY ? ICH_PM_PCMO : ICH_PM_PCMI;
-
-       auich_read_codec(sc, AC97_REG_POWER, &val);
-       auich_write_codec(sc, AC97_REG_POWER, val | inout);
+       int reg;
 
-       rvalue = srate * FIXED_RATE / sc->sc_ac97rate;
-       if (mode == AUMODE_PLAY) {
-               auich_write_codec(sc, AC97_REG_PCM_FRONT_DAC_RATE, rvalue);
-               auich_read_codec(sc, AC97_REG_PCM_FRONT_DAC_RATE, &rate);
-       } else {
-               auich_write_codec(sc, AC97_REG_PCM_LR_ADC_RATE, rvalue);
-               auich_read_codec(sc, AC97_REG_PCM_LR_ADC_RATE, &rate);
-       }
-
-       auich_write_codec(sc, AC97_REG_POWER, val);
-
-       /* Cast to avoid integer overflow */
-       rvalue = (u_int32_t)rate * sc->sc_ac97rate / FIXED_RATE;
-       return rvalue;
+       reg = mode == AUMODE_PLAY
+               ? AC97_REG_PCM_FRONT_DAC_RATE : AC97_REG_PCM_LR_ADC_RATE;
+       return sc->codec_if->vtbl->set_rate(sc->codec_if, reg, srate);
 }
 
 int
@@ -818,14 +779,12 @@
                        return (EINVAL);
                }
 
-               if (sc->sc_fixed_rate) {
-                       p->hw_sample_rate = sc->sc_fixed_rate;
+               if (IS_FIXED_RATE(sc->codec_if)) {
+                       return auich_set_rate(sc, mode, &p->hw_sample_rate);
+                       /* If hw_sample_rate is changed, aurateconv works. */
                } else {
-                       p->hw_sample_rate = auich_set_rate(sc, mode,
-                                                          p->sample_rate);
+                       return auich_set_rate(sc, mode, &p->sample_rate);
                }
-               /* If hw_sample_rate is different from sample_rate, aurateconv
-                * works. */
        }
 
        return (0);
@@ -971,9 +930,18 @@
 int
 auich_get_props(void *v)
 {
+       struct auich_softc *sc = v;
+       int props;
 
-       return (AUDIO_PROP_MMAP | AUDIO_PROP_INDEPENDENT |
-               AUDIO_PROP_FULLDUPLEX);
+       props = AUDIO_PROP_INDEPENDENT | AUDIO_PROP_FULLDUPLEX;
+       /*
+        * Even if the codec is fixed-rate, set_param() succeeds for any sample
+        * rate because of aurateconv.  Applications can't know what rate the
+        * device can process in the case of mmap().
+        */
+       if (!IS_FIXED_RATE(sc->codec_if))
+               props |= AUDIO_PROP_MMAP;
+       return props;
 }
 
 int
diff -r 40aa7a9475ef -r 0d203d99df5d sys/dev/pci/auichreg.h
--- a/sys/dev/pci/auichreg.h    Tue Oct 08 09:59:27 2002 +0000
+++ b/sys/dev/pci/auichreg.h    Tue Oct 08 10:25:45 2002 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: auichreg.h,v 1.3 2002/08/07 10:31:09 kent Exp $        */
+/*     $NetBSD: auichreg.h,v 1.4 2002/10/08 10:25:45 kent Exp $        */
 
 /*
  * Copyright (c) 2000 Michael Shalayeff
@@ -115,11 +115,6 @@
 #define        ICH_CAS         0x34    /* 1/8 bit */
 #define        ICH_SEMATIMO    1000    /* us */
 
-/* Bits in the AC97_REG_POWER register */
-#define                ICH_PM_PCMI     0x100
-#define                ICH_PM_PCMO     0x200
-#define                ICH_PM_MICI     0x400
-
 /*
  * according to the dev/audiovar.h AU_RING_SIZE is 2^16, what fits
  * in our limits perfectly, i.e. setting it to higher value



Home | Main Index | Thread Index | Old Index