summaryrefslogtreecommitdiff
path: root/sys/dev/pci/auich.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/dev/pci/auich.c')
-rw-r--r--sys/dev/pci/auich.c151
1 files changed, 139 insertions, 12 deletions
diff --git a/sys/dev/pci/auich.c b/sys/dev/pci/auich.c
index dedaedb6885..b64968a6373 100644
--- a/sys/dev/pci/auich.c
+++ b/sys/dev/pci/auich.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: auich.c,v 1.84 2010/08/03 22:58:58 jakemsr Exp $ */
+/* $OpenBSD: auich.c,v 1.85 2010/08/08 20:37:33 jakemsr Exp $ */
/*
* Copyright (c) 2000,2001 Michael Shalayeff
@@ -174,7 +174,9 @@ struct auich_softc {
void *sc_ih;
audio_device_t sc_audev;
+ struct device *audiodev;
+ pcireg_t pci_id;
bus_space_tag_t iot;
bus_space_tag_t iot_mix;
bus_space_handle_t mix_ioh;
@@ -201,6 +203,7 @@ struct auich_softc {
void (*intr)(void *);
void *arg;
+ int running;
} pcmo, pcmi, mici;
struct auich_dma *sc_pdma; /* play */
@@ -227,6 +230,10 @@ struct auich_softc {
int sc_pcm2;
int sc_pcm4;
int sc_pcm6;
+
+ u_int last_rrate;
+ u_int last_prate;
+ u_int last_pchan;
};
#ifdef AUICH_DEBUG
@@ -247,8 +254,11 @@ int auich_match(struct device *, void *, void *);
void auich_attach(struct device *, struct device *, void *);
int auich_intr(void *);
+int auich_activate(struct device *, int);
+
struct cfattach auich_ca = {
- sizeof(struct auich_softc), auich_match, auich_attach
+ sizeof(struct auich_softc), auich_match, auich_attach,
+ NULL, auich_activate
};
static const struct auich_devtype {
@@ -289,7 +299,7 @@ int auich_query_encoding(void *, struct audio_encoding *);
int auich_set_params(void *, int, int, struct audio_params *,
struct audio_params *);
int auich_round_blocksize(void *, int);
-void auich_halt_pipe(struct auich_softc *, int);
+void auich_halt_pipe(struct auich_softc *, int, struct auich_ring *);
int auich_halt_output(void *);
int auich_halt_input(void *);
int auich_getdev(void *, struct audio_device *);
@@ -312,6 +322,9 @@ int auich_allocmem(struct auich_softc *, size_t, size_t, struct auich_dma *);
int auich_freemem(struct auich_softc *, struct auich_dma *);
void auich_get_default_params(void *, int, struct audio_params *);
+int auich_suspend(struct auich_softc *);
+int auich_resume(struct auich_softc *);
+
void auich_powerhook(int, void *);
struct audio_hw_if auich_hw_if = {
@@ -431,6 +444,7 @@ auich_attach(parent, self, aux)
}
}
sc->dmat = pa->pa_dmat;
+ sc->pci_id = pa->pa_id;
if (pci_intr_map(pa, &ih)) {
printf(": can't map interrupt\n");
@@ -536,7 +550,7 @@ auich_attach(parent, self, aux)
}
sc->codec_if->vtbl->unlock(sc->codec_if);
- audio_attach_mi(&auich_hw_if, sc, &sc->sc_dev);
+ sc->audiodev = audio_attach_mi(&auich_hw_if, sc, &sc->sc_dev);
/* Watch for power changes */
sc->suspend = PWR_RESUME;
@@ -546,6 +560,29 @@ auich_attach(parent, self, aux)
}
int
+auich_activate(struct device *self, int act)
+{
+ struct auich_softc *sc = (struct auich_softc *)self;
+ int ret = 0;
+
+ switch (act) {
+ case DVACT_ACTIVATE:
+ return ret;
+ case DVACT_DEACTIVATE:
+ if (sc->audiodev != NULL)
+ ret = config_deactivate(sc->audiodev);
+ return ret;
+ case DVACT_SUSPEND:
+ auich_suspend(sc);
+ return ret;
+ case DVACT_RESUME:
+ auich_resume(sc);
+ return ret;
+ }
+ return EOPNOTSUPP;
+}
+
+int
auich_read_codec(v, reg, val)
void *v;
u_int8_t reg;
@@ -974,6 +1011,8 @@ auich_set_params(v, setmode, usemode, play, rec)
adj_rate = orate * AUICH_FIXED_RATE / sc->sc_ac97rate;
play->sample_rate = adj_rate;
+ sc->last_prate = play->sample_rate;
+
error = ac97_set_rate(sc->codec_if,
AC97_REG_PCM_LFE_DAC_RATE, &play->sample_rate);
if (error)
@@ -1001,6 +1040,8 @@ auich_set_params(v, setmode, usemode, play, rec)
else if (play->channels == 6)
control |= sc->sc_pcm6;
bus_space_write_4(sc->iot, sc->aud_ioh, AUICH_GCTRL, control);
+
+ sc->last_pchan = play->channels;
}
if (setmode & AUMODE_RECORD) {
@@ -1160,6 +1201,7 @@ auich_set_params(v, setmode, usemode, play, rec)
if (sc->sc_ac97rate != 0)
rec->sample_rate = orate * AUICH_FIXED_RATE /
sc->sc_ac97rate;
+ sc->last_rrate = rec->sample_rate;
error = ac97_set_rate(sc->codec_if, AC97_REG_PCM_LR_ADC_RATE,
&rec->sample_rate);
if (error)
@@ -1180,7 +1222,7 @@ auich_round_blocksize(v, blk)
void
-auich_halt_pipe(struct auich_softc *sc, int pipe)
+auich_halt_pipe(struct auich_softc *sc, int pipe, struct auich_ring *ring)
{
int i;
uint32_t sts;
@@ -1205,6 +1247,8 @@ auich_halt_pipe(struct auich_softc *sc, int pipe)
if (i > 0)
DPRINTF(AUICH_DEBUG_DMA,
("auich_halt_pipe: halt took %d cycles\n", i));
+
+ ring->running = 0;
}
@@ -1216,7 +1260,7 @@ auich_halt_output(v)
DPRINTF(AUICH_DEBUG_DMA, ("%s: halt_output\n", sc->sc_dev.dv_xname));
- auich_halt_pipe(sc, AUICH_PCMO);
+ auich_halt_pipe(sc, AUICH_PCMO, &sc->pcmo);
sc->pcmo.intr = NULL;
@@ -1234,8 +1278,8 @@ auich_halt_input(v)
/* XXX halt both unless known otherwise */
- auich_halt_pipe(sc, AUICH_PCMI);
- auich_halt_pipe(sc, AUICH_MICI);
+ auich_halt_pipe(sc, AUICH_PCMI, &sc->pcmi);
+ auich_halt_pipe(sc, AUICH_MICI, &sc->mici);
sc->pcmi.intr = NULL;
@@ -1528,6 +1572,8 @@ auich_trigger_pipe(struct auich_softc *sc, int pipe, struct auich_ring *ring)
(qptr - 1) & AUICH_LVI_MASK);
bus_space_write_1(sc->iot, sc->aud_ioh, pipe + AUICH_CTRL,
AUICH_IOCE | AUICH_FEIE | AUICH_RPBM);
+
+ ring->running = 1;
}
void
@@ -1785,6 +1831,87 @@ auich_alloc_cdata(struct auich_softc *sc)
return error;
}
+int
+auich_suspend(struct auich_softc *sc)
+{
+ if (sc->pcmo.running) {
+ auich_halt_pipe(sc, AUICH_PCMO, &sc->pcmo);
+ sc->pcmo.running = 1;
+ }
+ if (sc->pcmi.running) {
+ auich_halt_pipe(sc, AUICH_PCMI, &sc->pcmi);
+ sc->pcmi.running = 1;
+ }
+ if (sc->mici.running) {
+ auich_halt_pipe(sc, AUICH_MICI, &sc->mici);
+ sc->mici.running = 1;
+ }
+
+ return (0);
+}
+
+int
+auich_resume(struct auich_softc *sc)
+{
+ struct auich_ring *ring;
+ u_long rate, control;
+
+ /* SiS 7012 needs special handling */
+ if (PCI_VENDOR(sc->pci_id) == PCI_VENDOR_SIS &&
+ PCI_PRODUCT(sc->pci_id) == PCI_PRODUCT_SIS_7012_ACA) {
+ /* un-mute output */
+ bus_space_write_4(sc->iot, sc->aud_ioh, ICH_SIS_NV_CTL,
+ bus_space_read_4(sc->iot, sc->aud_ioh, ICH_SIS_NV_CTL) |
+ ICH_SIS_CTL_UNMUTE);
+ }
+
+ ac97_resume(&sc->host_if, sc->codec_if);
+
+ ring = &sc->pcmo;
+ if (ring->running) {
+
+ rate = sc->last_prate;
+ ac97_set_rate(sc->codec_if, AC97_REG_PCM_LFE_DAC_RATE, &rate);
+
+ rate = sc->last_prate;
+ ac97_set_rate(sc->codec_if, AC97_REG_PCM_SURR_DAC_RATE, &rate);
+
+ rate = sc->last_prate;
+ ac97_set_rate(sc->codec_if, AC97_REG_PCM_FRONT_DAC_RATE, &rate);
+
+ control = bus_space_read_4(sc->iot, sc->aud_ioh, AUICH_GCTRL);
+ control &= ~(sc->sc_pcm246_mask);
+ if (sc->last_pchan == 4)
+ control |= sc->sc_pcm4;
+ else if (sc->last_pchan == 6)
+ control |= sc->sc_pcm6;
+ bus_space_write_4(sc->iot, sc->aud_ioh, AUICH_GCTRL, control);
+
+ bus_space_write_4(sc->iot, sc->aud_ioh,
+ AUICH_PCMO + AUICH_BDBAR, sc->sc_cddma + AUICH_PCMO_OFF(0));
+ auich_trigger_pipe(sc, AUICH_PCMO, ring);
+ }
+
+ ring = &sc->pcmi;
+ if (ring->running) {
+ rate = sc->last_rrate;
+ ac97_set_rate(sc->codec_if, AC97_REG_PCM_LR_ADC_RATE, &rate);
+ bus_space_write_4(sc->iot, sc->aud_ioh,
+ AUICH_PCMI + AUICH_BDBAR, sc->sc_cddma + AUICH_PCMI_OFF(0));
+ auich_trigger_pipe(sc, AUICH_PCMI, ring);
+ }
+
+ ring = &sc->mici;
+ if (ring->running) {
+ rate = sc->last_rrate;
+ ac97_set_rate(sc->codec_if, AC97_REG_PCM_MIC_ADC_RATE, &rate);
+ bus_space_write_4(sc->iot, sc->aud_ioh,
+ AUICH_MICI + AUICH_BDBAR, sc->sc_cddma + AUICH_MICI_OFF(0));
+ auich_trigger_pipe(sc, AUICH_MICI, ring);
+ }
+
+ return (0);
+}
void
auich_powerhook(why, self)
@@ -1928,8 +2055,8 @@ auich_calibrate(struct auich_softc *sc)
sc->sc_dev.dv_xname, wait_us, sts,
AUICH_ISTS_BITS, civ);
/* reset and clean up*/
- auich_halt_pipe(sc, AUICH_PCMI);
- auich_halt_pipe(sc, AUICH_MICI);
+ auich_halt_pipe(sc, AUICH_PCMI, &sc->pcmi);
+ auich_halt_pipe(sc, AUICH_MICI, &sc->mici);
auich_freem(sc, temp_buffer, M_DEVBUF);
/* return default sample rate */
return (ac97rate);
@@ -1941,8 +2068,8 @@ auich_calibrate(struct auich_softc *sc)
sc->sc_dev.dv_xname, wait_us, sts, AUICH_ISTS_BITS, civ));
/* reset and clean up */
- auich_halt_pipe(sc, AUICH_PCMI);
- auich_halt_pipe(sc, AUICH_MICI);
+ auich_halt_pipe(sc, AUICH_PCMI, &sc->pcmi);
+ auich_halt_pipe(sc, AUICH_MICI, &sc->mici);
auich_freem(sc, temp_buffer, M_DEVBUF);
#ifdef AUICH_DEBUG