- Port clock calibration code (auich_calibrate) from ich.c of FreeBSD to solve
kern/16373. - SiS 7012 support from kern/17716 submitted by Quentin Garnier. - ICH4 support - Experimental support for nForce MCP, AMD768 and AMD8111. - Rename the short name for ICH3: "i830M" -> "ICH3"
This commit is contained in:
parent
38b5f64780
commit
3898bab95a
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: auich.c,v 1.17 2002/04/11 10:54:23 augustss Exp $ */
|
||||
/* $NetBSD: auich.c,v 1.18 2002/08/07 10:31:09 kent Exp $ */
|
||||
|
||||
/*-
|
||||
* Copyright (c) 2000 The NetBSD Foundation, Inc.
|
||||
@ -66,21 +66,55 @@
|
||||
* from OpenBSD: ich.c,v 1.3 2000/08/11 06:17:18 mickey Exp
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2000 Katsurajima Naoto <raven@katsurajima.seya.yokohama.jp>
|
||||
* Copyright (c) 2001 Cameron Grant <cg@freebsd.org>
|
||||
* 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.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``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 OR CONTRIBUTORS 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, WHETHERIN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THEPOSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* auich_calibrate() was from FreeBSD: ich.c,v 1.22 2002/06/27 22:36:01 scottl Exp
|
||||
*/
|
||||
|
||||
|
||||
/* #define ICH_DEBUG */
|
||||
/*
|
||||
* AC'97 audio found on Intel 810/820/440MX chipsets.
|
||||
* http://developer.intel.com/design/chipsets/datashts/290655.htm
|
||||
* http://developer.intel.com/design/chipsets/manuals/298028.htm
|
||||
* ICH3:http://www.intel.com/design/chipsets/datashts/290716.htm
|
||||
* ICH4:http://www.intel.com/design/chipsets/datashts/290744.htm
|
||||
*
|
||||
* TODO:
|
||||
*
|
||||
* - Probe codecs for supported sample rates.
|
||||
*
|
||||
* - Add support for the microphone input.
|
||||
* - 4ch/6ch support.
|
||||
* - auich_calibrate() is called in auich_open(). It causes about 0.1sec
|
||||
* delay in the first open(). auich_calibrate() should be called in
|
||||
* auich_attach(). However microtime() doesn't work in the attach
|
||||
* stage.
|
||||
*/
|
||||
|
||||
#include <sys/cdefs.h>
|
||||
__KERNEL_RCSID(0, "$NetBSD: auich.c,v 1.17 2002/04/11 10:54:23 augustss Exp $");
|
||||
__KERNEL_RCSID(0, "$NetBSD: auich.c,v 1.18 2002/08/07 10:31:09 kent Exp $");
|
||||
|
||||
#include <sys/param.h>
|
||||
#include <sys/systm.h>
|
||||
@ -169,6 +203,12 @@ struct auich_softc {
|
||||
struct auich_dma *sc_dmas;
|
||||
|
||||
int sc_fixed_rate;
|
||||
int sc_ac97rate;
|
||||
int sc_ignore_codecready;
|
||||
|
||||
/* SiS 7012 hack */
|
||||
int sc_sample_size;
|
||||
int sc_sts_reg;
|
||||
|
||||
void (*sc_pintr)(void *);
|
||||
void *sc_parg;
|
||||
@ -233,6 +273,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);
|
||||
unsigned int auich_calibrate(struct auich_softc *sc);
|
||||
|
||||
|
||||
struct audio_hw_if auich_hw_if = {
|
||||
@ -271,21 +312,31 @@ int auich_write_codec(void *, u_int8_t, u_int16_t);
|
||||
void auich_reset_codec(void *);
|
||||
|
||||
static const struct auich_devtype {
|
||||
int vendor;
|
||||
int product;
|
||||
const char *name;
|
||||
const char *shortname;
|
||||
} auich_devices[] = {
|
||||
{ PCI_PRODUCT_INTEL_82801AA_ACA,
|
||||
{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801AA_ACA,
|
||||
"i82801AA (ICH) AC-97 Audio", "ICH" },
|
||||
{ PCI_PRODUCT_INTEL_82801AB_ACA,
|
||||
"i82801AB (ICH0) AC-97 Audio", "ICH0" },
|
||||
{ PCI_PRODUCT_INTEL_82801BA_ACA,
|
||||
{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801AB_ACA,
|
||||
"i82801AB (ICH0) AC-97 Audio", "ICH0" }, /* i810-L */
|
||||
{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801BA_ACA,
|
||||
"i82801BA (ICH2) AC-97 Audio", "ICH2" },
|
||||
{ PCI_PRODUCT_INTEL_82440MX_ACA,
|
||||
{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82440MX_ACA,
|
||||
"i82440MX AC-97 Audio", "440MX" },
|
||||
{ PCI_PRODUCT_INTEL_82801CA_AC,
|
||||
"i82801CA AC-97 Audio", "i830M" },
|
||||
|
||||
{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801CA_AC,
|
||||
"i82801CA (ICH3) AC-97 Audio", "ICH3" }, /* i830Mx i845MP/MZ*/
|
||||
{ PCI_VENDOR_INTEL, PCI_PRODUCT_INTEL_82801DB_AC,
|
||||
"i82801DB (ICH4) AC-97 Audio", "ICH4" }, /* i845E i845Gx */
|
||||
{ PCI_VENDOR_SIS, PCI_PRODUCT_SIS_7012_AC,
|
||||
"SiS 7012 AC-97 Audio", "SiS7012" },
|
||||
{ PCI_VENDOR_NVIDIA, PCI_PRODUCT_NVIDIA_NFORCE_MCP_AC,
|
||||
"nForce MCP AC-97 Audio", "nForce-MCP" },
|
||||
{ PCI_VENDOR_AMD, PCI_PRODUCT_AMD_PBC768_AC,
|
||||
"AMD768 AC-97 Audio", "AMD768" },
|
||||
{ PCI_VENDOR_AMD, PCI_PRODUCT_AMD_PBC8111_AC,
|
||||
"AMD8111 AC-97 Audio", "AMD8111" },
|
||||
{ 0,
|
||||
NULL, NULL },
|
||||
};
|
||||
@ -295,11 +346,9 @@ auich_lookup(struct pci_attach_args *pa)
|
||||
{
|
||||
const struct auich_devtype *d;
|
||||
|
||||
if (PCI_VENDOR(pa->pa_id) != PCI_VENDOR_INTEL)
|
||||
return (NULL);
|
||||
|
||||
for (d = auich_devices; d->name != NULL; d++) {
|
||||
if (PCI_PRODUCT(pa->pa_id) == d->product)
|
||||
if (PCI_VENDOR(pa->pa_id) == d->vendor
|
||||
&& PCI_PRODUCT(pa->pa_id) == d->product)
|
||||
return (d);
|
||||
}
|
||||
|
||||
@ -328,6 +377,7 @@ auich_attach(struct device *parent, struct device *self, void *aux)
|
||||
const char *intrstr;
|
||||
const struct auich_devtype *d;
|
||||
u_int16_t ext_id, ext_status;
|
||||
u_int32_t status;
|
||||
|
||||
d = auich_lookup(pa);
|
||||
if (d == NULL)
|
||||
@ -375,6 +425,16 @@ auich_attach(struct device *parent, struct device *self, void *aux)
|
||||
sprintf(sc->sc_audev.version, "0x%02x", PCI_REVISION(pa->pa_class));
|
||||
strcpy(sc->sc_audev.config, sc->sc_dev.dv_xname);
|
||||
|
||||
/* SiS 7012 needs special handling */
|
||||
if (d->vendor == PCI_VENDOR_SIS
|
||||
&& d->product == PCI_PRODUCT_SIS_7012_AC) {
|
||||
sc->sc_sts_reg = ICH_PICB;
|
||||
sc->sc_sample_size = 1;
|
||||
} else {
|
||||
sc->sc_sts_reg = ICH_STS;
|
||||
sc->sc_sample_size = 2;
|
||||
}
|
||||
|
||||
/* Set up DMA lists. */
|
||||
sc->ptr_pcmo = sc->ptr_pcmi = sc->ptr_mici = 0;
|
||||
auich_alloc_cdata(sc);
|
||||
@ -384,6 +444,23 @@ auich_attach(struct device *parent, struct device *self, void *aux)
|
||||
|
||||
/* Reset codec and AC'97 */
|
||||
auich_reset_codec(sc);
|
||||
status = bus_space_read_4(sc->iot, sc->aud_ioh, ICH_GSTS);
|
||||
if (!(status & ICH_PCR)) { /* reset failure */
|
||||
if (d->vendor == PCI_VENDOR_INTEL
|
||||
&& d->product == PCI_PRODUCT_INTEL_82801DB_AC) {
|
||||
/* MSI 845G Max never return ICH_PCR */
|
||||
sc->sc_ignore_codecready = TRUE;
|
||||
} else {
|
||||
return;
|
||||
}
|
||||
}
|
||||
/* Print capabilities though there are no supports for now */
|
||||
if ((status & ICH_SAMPLE_CAP) == ICH_POM20)
|
||||
printf("%s: 20 bit precision support\n", sc->sc_dev.dv_xname);
|
||||
if ((status & ICH_CHAN_CAP) == ICH_PCM4)
|
||||
printf("%s: 4ch PCM output support\n", sc->sc_dev.dv_xname);
|
||||
if ((status & ICH_CHAN_CAP) == ICH_PCM6)
|
||||
printf("%s: 6ch PCM output support\n", sc->sc_dev.dv_xname);
|
||||
|
||||
sc->host_if.arg = sc;
|
||||
sc->host_if.attach = auich_attach_codec;
|
||||
@ -404,10 +481,12 @@ auich_attach(struct device *parent, struct device *self, void *aux)
|
||||
auich_write_codec(sc, AC97_REG_EXTENDED_STATUS, ext_status);
|
||||
|
||||
/* so it claims to do variable rate, let's make sure */
|
||||
sc->sc_ac97rate = FIXED_RATE;
|
||||
if (auich_set_rate(sc, AUMODE_PLAY, 44100) == 44100)
|
||||
sc->sc_fixed_rate = 0;
|
||||
else
|
||||
sc->sc_fixed_rate = FIXED_RATE;
|
||||
sc->sc_ac97rate = 0;
|
||||
} else {
|
||||
sc->sc_fixed_rate = FIXED_RATE;
|
||||
}
|
||||
@ -429,8 +508,9 @@ auich_read_codec(void *v, u_int8_t reg, u_int16_t *val)
|
||||
int i;
|
||||
uint32_t status;
|
||||
|
||||
if (!(bus_space_read_4(sc->iot, sc->aud_ioh, ICH_GSTS) & ICH_PCR)) {
|
||||
printf("auich_read_codec: codec is not ready.");
|
||||
status = bus_space_read_4(sc->iot, sc->aud_ioh, ICH_GSTS);
|
||||
if (!sc->sc_ignore_codecready && !(status & ICH_PCR)) {
|
||||
printf("auich_read_codec: codec is not ready (0x%x)\n", status);
|
||||
*val = 0xffff;
|
||||
return -1;
|
||||
}
|
||||
@ -464,7 +544,8 @@ auich_write_codec(void *v, u_int8_t reg, u_int16_t val)
|
||||
int i;
|
||||
|
||||
DPRINTF(ICH_DEBUG_CODECIO, ("auich_write_codec(%x, %x)\n", reg, val));
|
||||
if (!(bus_space_read_4(sc->iot, sc->aud_ioh, ICH_GSTS) & ICH_PCR)) {
|
||||
if (!sc->sc_ignore_codecready
|
||||
&& !(bus_space_read_4(sc->iot, sc->aud_ioh, ICH_GSTS) & ICH_PCR)) {
|
||||
printf("auich_write_codec: codec is not ready.");
|
||||
return -1;
|
||||
}
|
||||
@ -497,20 +578,27 @@ auich_reset_codec(void *v)
|
||||
{
|
||||
struct auich_softc *sc = v;
|
||||
int i;
|
||||
uint32_t control;
|
||||
|
||||
bus_space_write_4(sc->iot, sc->aud_ioh, ICH_GCTRL, 0);
|
||||
DELAY(10);
|
||||
bus_space_write_4(sc->iot, sc->aud_ioh, ICH_GCTRL, ICH_CRESET);
|
||||
control = bus_space_read_4(sc->iot, sc->aud_ioh, ICH_GCTRL);
|
||||
control &= ~(ICH_ACLSO | ICH_PCM246_MASK);
|
||||
control |= (control & ICH_CRESET) ? ICH_WRESET : ICH_CRESET;
|
||||
bus_space_write_4(sc->iot, sc->aud_ioh, ICH_GCTRL, control);
|
||||
|
||||
for (i = 500000; i-- &&
|
||||
!(bus_space_read_4(sc->iot, sc->aud_ioh, ICH_GSTS) & ICH_PCR);
|
||||
DELAY(1)); /* or ICH_SCR? */
|
||||
if (i <= 0)
|
||||
printf("%s: auich_reset_codec: time out\n", sc->sc_dev.dv_xname);
|
||||
}
|
||||
|
||||
int
|
||||
auich_open(void *v, int flags)
|
||||
{
|
||||
struct auich_softc *sc = v;
|
||||
|
||||
if (!sc->sc_fixed_rate && sc->sc_ac97rate == 0)
|
||||
sc->sc_ac97rate = auich_calibrate(sc);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -588,23 +676,26 @@ int
|
||||
auich_set_rate(struct auich_softc *sc, int mode, uint 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);
|
||||
|
||||
rvalue = srate * FIXED_RATE / sc->sc_ac97rate;
|
||||
if (mode == AUMODE_PLAY) {
|
||||
auich_write_codec(sc, AC97_REG_PCM_FRONT_DAC_RATE, srate);
|
||||
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, srate);
|
||||
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);
|
||||
|
||||
return rate;
|
||||
rvalue = rate * sc->sc_ac97rate / FIXED_RATE;
|
||||
return rvalue;
|
||||
}
|
||||
|
||||
int
|
||||
@ -641,8 +732,12 @@ auich_set_params(void *v, int setmode, int usemode, struct audio_params *play,
|
||||
/* setup hardware formats */
|
||||
p->hw_encoding = AUDIO_ENCODING_SLINEAR_LE;
|
||||
p->hw_precision = 16;
|
||||
|
||||
/* If manaural is requested, aurateconv expands a monaural
|
||||
* stream to stereo. */
|
||||
if (p->channels < 2)
|
||||
p->hw_channels = 2;
|
||||
|
||||
switch (p->encoding) {
|
||||
case AUDIO_ENCODING_SLINEAR_BE:
|
||||
if (p->precision == 16) {
|
||||
@ -715,12 +810,15 @@ auich_set_params(void *v, int setmode, int usemode, struct audio_params *play,
|
||||
return (EINVAL);
|
||||
}
|
||||
|
||||
if (sc->sc_fixed_rate)
|
||||
if (sc->sc_fixed_rate) {
|
||||
p->hw_sample_rate = sc->sc_fixed_rate;
|
||||
else
|
||||
} else {
|
||||
p->hw_sample_rate = auich_set_rate(sc, mode,
|
||||
p->sample_rate);
|
||||
}
|
||||
/* If hw_sample_rate is different from sample_rate, aurateconv
|
||||
* works. */
|
||||
}
|
||||
|
||||
return (0);
|
||||
}
|
||||
@ -880,7 +978,7 @@ auich_intr(void *v)
|
||||
DPRINTF(ICH_DEBUG_DMA, ("auich_intr: gsts=0x%x\n", gsts));
|
||||
|
||||
if (gsts & ICH_POINT) {
|
||||
sts = bus_space_read_2(sc->iot, sc->aud_ioh, ICH_PCMO+ICH_STS);
|
||||
sts = bus_space_read_2(sc->iot, sc->aud_ioh, ICH_PCMO+sc->sc_sts_reg);
|
||||
DPRINTF(ICH_DEBUG_DMA,
|
||||
("auich_intr: osts=0x%x\n", sts));
|
||||
|
||||
@ -899,7 +997,7 @@ auich_intr(void *v)
|
||||
q = &sc->dmalist_pcmo[qptr];
|
||||
|
||||
q->base = sc->pcmo_p;
|
||||
q->len = (sc->pcmo_blksize / 2) | ICH_DMAF_IOC;
|
||||
q->len = (sc->pcmo_blksize / sc->sc_sample_size) | ICH_DMAF_IOC;
|
||||
DPRINTF(ICH_DEBUG_DMA,
|
||||
("auich_intr: %p, %p = %x @ 0x%x\n",
|
||||
&sc->dmalist_pcmo[i], q,
|
||||
@ -923,14 +1021,14 @@ auich_intr(void *v)
|
||||
sc->sc_pintr(sc->sc_parg);
|
||||
|
||||
/* int ack */
|
||||
bus_space_write_2(sc->iot, sc->aud_ioh, ICH_PCMO + ICH_STS,
|
||||
bus_space_write_2(sc->iot, sc->aud_ioh, ICH_PCMO + sc->sc_sts_reg,
|
||||
sts & (ICH_LVBCI | ICH_CELV | ICH_BCIS | ICH_FIFOE));
|
||||
bus_space_write_2(sc->iot, sc->aud_ioh, ICH_GSTS, ICH_POINT);
|
||||
ret++;
|
||||
}
|
||||
|
||||
if (gsts & ICH_PIINT) {
|
||||
sts = bus_space_read_2(sc->iot, sc->aud_ioh, ICH_PCMI+ICH_STS);
|
||||
sts = bus_space_read_2(sc->iot, sc->aud_ioh, ICH_PCMI+sc->sc_sts_reg);
|
||||
DPRINTF(ICH_DEBUG_DMA,
|
||||
("auich_intr: ists=0x%x\n", sts));
|
||||
|
||||
@ -949,7 +1047,7 @@ auich_intr(void *v)
|
||||
q = &sc->dmalist_pcmi[qptr];
|
||||
|
||||
q->base = sc->pcmi_p;
|
||||
q->len = (sc->pcmi_blksize / 2) | ICH_DMAF_IOC;
|
||||
q->len = (sc->pcmi_blksize / sc->sc_sample_size) | ICH_DMAF_IOC;
|
||||
DPRINTF(ICH_DEBUG_DMA,
|
||||
("auich_intr: %p, %p = %x @ 0x%x\n",
|
||||
&sc->dmalist_pcmi[i], q,
|
||||
@ -973,14 +1071,14 @@ auich_intr(void *v)
|
||||
sc->sc_rintr(sc->sc_rarg);
|
||||
|
||||
/* int ack */
|
||||
bus_space_write_2(sc->iot, sc->aud_ioh, ICH_PCMI + ICH_STS,
|
||||
bus_space_write_2(sc->iot, sc->aud_ioh, ICH_PCMI + sc->sc_sts_reg,
|
||||
sts & (ICH_LVBCI | ICH_CELV | ICH_BCIS | ICH_FIFOE));
|
||||
bus_space_write_2(sc->iot, sc->aud_ioh, ICH_GSTS, ICH_POINT);
|
||||
ret++;
|
||||
}
|
||||
|
||||
if (gsts & ICH_MIINT) {
|
||||
sts = bus_space_read_2(sc->iot, sc->aud_ioh, ICH_MICI+ICH_STS);
|
||||
sts = bus_space_read_2(sc->iot, sc->aud_ioh, ICH_MICI+sc->sc_sts_reg);
|
||||
DPRINTF(ICH_DEBUG_DMA,
|
||||
("auich_intr: ists=0x%x\n", sts));
|
||||
if (sts & ICH_FIFOE)
|
||||
@ -1032,7 +1130,7 @@ auich_trigger_output(void *v, void *start, void *end, int blksize,
|
||||
sc->ptr_pcmo = 0;
|
||||
q = &sc->dmalist_pcmo[sc->ptr_pcmo];
|
||||
q->base = sc->pcmo_start;
|
||||
q->len = (blksize / 2) | ICH_DMAF_IOC;
|
||||
q->len = (blksize / sc->sc_sample_size) | ICH_DMAF_IOC;
|
||||
if (++sc->ptr_pcmo == ICH_DMALIST_MAX)
|
||||
sc->ptr_pcmo = 0;
|
||||
|
||||
@ -1089,7 +1187,7 @@ auich_trigger_input(v, start, end, blksize, intr, arg, param)
|
||||
sc->ptr_pcmi = 0;
|
||||
q = &sc->dmalist_pcmi[sc->ptr_pcmi];
|
||||
q->base = sc->pcmi_start;
|
||||
q->len = (blksize / 2) | ICH_DMAF_IOC;
|
||||
q->len = (blksize / sc->sc_sample_size) | ICH_DMAF_IOC;
|
||||
if (++sc->ptr_pcmi == ICH_DMALIST_MAX)
|
||||
sc->ptr_pcmi = 0;
|
||||
|
||||
@ -1244,3 +1342,105 @@ auich_powerhook(int why, void *addr)
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* -------------------------------------------------------------------- */
|
||||
/* Calibrate card (some boards are overclocked and need scaling) */
|
||||
|
||||
unsigned int
|
||||
auich_calibrate(struct auich_softc *sc)
|
||||
{
|
||||
struct timeval t1, t2;
|
||||
u_int8_t ociv, nciv;
|
||||
u_int32_t wait_us, actual_48k_rate, bytes, ac97rate;
|
||||
void *temp_buffer;
|
||||
struct auich_dma *p;
|
||||
|
||||
ac97rate = 48000;
|
||||
/*
|
||||
* Grab audio from input for fixed interval and compare how
|
||||
* much we actually get with what we expect. Interval needs
|
||||
* to be sufficiently short that no interrupts are
|
||||
* generated.
|
||||
*/
|
||||
|
||||
/* Setup a buffer */
|
||||
bytes = 16000;
|
||||
temp_buffer = auich_allocm(sc, AUMODE_RECORD, bytes, M_DEVBUF, M_WAITOK);
|
||||
for (p = sc->sc_dmas; p && KERNADDR(p) != temp_buffer; p = p->next)
|
||||
;
|
||||
if (p == NULL) {
|
||||
printf("auich_calibrate: bad address %p\n", temp_buffer);
|
||||
return ac97rate;
|
||||
}
|
||||
sc->dmalist_pcmi[0].base = DMAADDR(p);
|
||||
sc->dmalist_pcmi[0].len = (bytes / sc->sc_sample_size) | ICH_DMAF_IOC;
|
||||
|
||||
/*
|
||||
* our data format is stereo, 16 bit so each sample is 4 bytes.
|
||||
* assuming we get 48000 samples per second, we get 192000 bytes/sec.
|
||||
* we're going to start recording with interrupts disabled and measure
|
||||
* the time taken for one block to complete. we know the block size,
|
||||
* we know the time in microseconds, we calculate the sample rate:
|
||||
*
|
||||
* actual_rate [bps] = bytes / (time [s] * 4)
|
||||
* actual_rate [bps] = (bytes * 1000000) / (time [us] * 4)
|
||||
* actual_rate [Hz] = (bytes * 250000) / time [us]
|
||||
*/
|
||||
|
||||
/* prepare */
|
||||
ociv = bus_space_read_1(sc->iot, sc->aud_ioh, ICH_PCMI + ICH_CIV);
|
||||
nciv = ociv;
|
||||
bus_space_write_4(sc->iot, sc->aud_ioh, ICH_PCMI + ICH_BDBAR,
|
||||
sc->sc_cddma + ICH_PCMI_OFF(0));
|
||||
bus_space_write_1(sc->iot, sc->aud_ioh, ICH_PCMI + ICH_LVI,
|
||||
(0 - 1) & ICH_LVI_MASK);
|
||||
|
||||
/* start */
|
||||
microtime(&t1);
|
||||
bus_space_write_1(sc->iot, sc->aud_ioh, ICH_PCMI + ICH_CTRL, ICH_RPBM);
|
||||
|
||||
/* wait */
|
||||
while (nciv == ociv) {
|
||||
microtime(&t2);
|
||||
if (t2.tv_sec - t1.tv_sec > 1)
|
||||
break;
|
||||
nciv = bus_space_read_1(sc->iot, sc->aud_ioh,
|
||||
ICH_PCMI + ICH_CIV);
|
||||
}
|
||||
microtime(&t2);
|
||||
|
||||
/* stop */
|
||||
bus_space_write_1(sc->iot, sc->aud_ioh, ICH_PCMI + ICH_CTRL, 0);
|
||||
|
||||
/* reset */
|
||||
DELAY(100);
|
||||
bus_space_write_1(sc->iot, sc->aud_ioh, ICH_PCMI + ICH_CTRL, ICH_RR);
|
||||
|
||||
/* turn time delta into us */
|
||||
wait_us = ((t2.tv_sec - t1.tv_sec) * 1000000) + t2.tv_usec - t1.tv_usec;
|
||||
|
||||
auich_freem(sc, temp_buffer, M_DEVBUF);
|
||||
|
||||
if (nciv == ociv) {
|
||||
printf("%s: ac97 link rate calibration timed out after %d us\n",
|
||||
sc->sc_dev.dv_xname, wait_us);
|
||||
return ac97rate;
|
||||
}
|
||||
|
||||
actual_48k_rate = (bytes * 250000) / wait_us;
|
||||
|
||||
if (actual_48k_rate < 47500 || actual_48k_rate > 48500) {
|
||||
ac97rate = actual_48k_rate;
|
||||
}
|
||||
|
||||
if (ac97rate != 48000) {
|
||||
printf("%s: measured ac97 link rate at %d Hz",
|
||||
sc->sc_dev.dv_xname, actual_48k_rate);
|
||||
if (ac97rate != actual_48k_rate)
|
||||
printf(", will use %d Hz", ac97rate);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
return ac97rate;
|
||||
}
|
||||
|
@ -1,4 +1,4 @@
|
||||
/* $NetBSD: auichreg.h,v 1.2 2000/11/28 16:57:16 thorpej Exp $ */
|
||||
/* $NetBSD: auichreg.h,v 1.3 2002/08/07 10:31:09 kent Exp $ */
|
||||
|
||||
/*
|
||||
* Copyright (c) 2000 Michael Shalayeff
|
||||
@ -70,6 +70,16 @@
|
||||
#define ICH_MICI 0x20
|
||||
|
||||
#define ICH_GCTRL 0x2c
|
||||
#define ICH_SSM_78 0x40000000 /* S/PDIF slots 7 and 8 */
|
||||
#define ICH_SSM_69 0x80000000 /* S/PDIF slots 6 and 9 */
|
||||
#define ICH_SSM_1011 0xc0000000 /* S/PDIF slots 10 and 11 */
|
||||
#define ICH_POM16 0x000000 /* PCM out precision 16bit */
|
||||
#define ICH_POM20 0x400000 /* PCM out precision 20bit */
|
||||
#define ICH_PCM246_MASK 0x300000
|
||||
#define ICH_PCM2 0x000000 /* 2ch output */
|
||||
#define ICH_PCM4 0x100000 /* 4ch output */
|
||||
#define ICH_PCM6 0x200000 /* 6ch output */
|
||||
#define ICH_S2RIE 0x40 /* int when tertiary codec resume */
|
||||
#define ICH_SRIE 0x20 /* int when 2ndary codec resume */
|
||||
#define ICH_PRIE 0x10 /* int when primary codec resume */
|
||||
#define ICH_ACLSO 0x08 /* aclink shut off */
|
||||
@ -77,6 +87,14 @@
|
||||
#define ICH_CRESET 0x02 /* cold reset */
|
||||
#define ICH_GIE 0x01 /* gpi int enable */
|
||||
#define ICH_GSTS 0x30
|
||||
#define ICH_S2RI 0x20000000 /* tertiary resume int */
|
||||
#define ICH_S2CR 0x10000000 /* tertiary codec ready */
|
||||
#define ICH_BCS 0x08000000 /* bit clock stopped */
|
||||
#define ICH_SPINT 0x04000000 /* S/PDIF int */
|
||||
#define ICH_P2INT 0x02000000 /* PCM-In 2 int */
|
||||
#define ICH_M2INT 0x01000000 /* mic 2 int */
|
||||
#define ICH_SAMPLE_CAP 0x00c00000 /* sampling precision capability */
|
||||
#define ICH_CHAN_CAP 0x00300000 /* multi-channel capability */
|
||||
#define ICH_MD3 0x20000 /* pwr-dn semaphore for modem */
|
||||
#define ICH_AD3 0x10000 /* pwr-dn semaphore for audio */
|
||||
#define ICH_RCS 0x08000 /* read completion status */
|
||||
|
Loading…
Reference in New Issue
Block a user