Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/pci Device driver for the built-in audio on Intel IC...



details:   https://anonhg.NetBSD.org/src/rev/cecf78d5d724
branches:  trunk
changeset: 499737:cecf78d5d724
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Tue Nov 28 05:12:29 2000 +0000

description:
Device driver for the built-in audio on Intel ICH, ICH0, ICH2,
and i440MX chipsets.  Based on a driver by Michael Shalayeff,
modified somewhat by me to use bus_dma properly, and fix some
audio encoding emulation bugs.

Thanks to Manuel Bouyer for testing and feedback.

diffstat:

 sys/dev/pci/auich.c    |  1121 ++++++++++++++++++++++++++++++++++++++++++++++++
 sys/dev/pci/auichreg.h |   147 ++++++
 sys/dev/pci/files.pci  |     7 +-
 3 files changed, 1274 insertions(+), 1 deletions(-)

diffs (truncated from 1297 to 300 lines):

diff -r 04a5b4872c94 -r cecf78d5d724 sys/dev/pci/auich.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/dev/pci/auich.c       Tue Nov 28 05:12:29 2000 +0000
@@ -0,0 +1,1121 @@
+/*     $NetBSD: auich.c,v 1.1 2000/11/28 05:12:29 thorpej Exp $        */
+
+/*-
+ * Copyright (c) 2000 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jason R. Thorpe.
+ *
+ * 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.
+ * 3. All advertising materials mentioning features or use of this software
+ *    must display the following acknowledgement:
+ *     This product includes software developed by the NetBSD
+ *     Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ *    contributors may be used to endorse or promote products derived
+ *    from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * Copyright (c) 2000 Michael Shalayeff
+ * 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.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 HIS RELATIVES 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 MIND, USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
+ * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+ * THE POSSIBILITY OF SUCH DAMAGE.
+ *
+ *     from OpenBSD: ich.c,v 1.3 2000/08/11 06:17:18 mickey 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
+ *
+ * TODO:
+ *
+ *     - Probe codecs for supported sample rates.
+ *
+ *     - Add support for the microphone input.
+ */
+
+#include <sys/param.h>
+#include <sys/systm.h>
+#include <sys/kernel.h>
+#include <sys/malloc.h>
+#include <sys/device.h>
+#include <sys/fcntl.h>
+#include <sys/proc.h>
+
+#include <uvm/uvm_extern.h>    /* for PAGE_SIZE */
+
+#include <dev/pci/pcidevs.h>
+#include <dev/pci/pcivar.h>
+#include <dev/pci/auichreg.h>
+
+#include <sys/audioio.h>
+#include <dev/audio_if.h>
+#include <dev/mulaw.h>
+#include <dev/auconv.h>
+
+#include <machine/bus.h>
+
+#include <dev/ic/ac97var.h>
+
+struct auich_dma {
+       bus_dmamap_t map;
+       caddr_t addr;
+       bus_dma_segment_t segs[1];
+       int nsegs;
+       size_t size;
+       struct auich_dma *next;
+};
+
+#define        DMAADDR(p)      ((p)->map->dm_segs[0].ds_addr)
+#define        KERNADDR(p)     ((void *)((p)->addr))
+
+struct auich_cdata {
+       struct auich_dmalist ic_dmalist_pcmo[ICH_DMALIST_MAX];
+       struct auich_dmalist ic_dmalist_pcmi[ICH_DMALIST_MAX];
+       struct auich_dmalist ic_dmalist_mici[ICH_DMALIST_MAX];
+};
+
+#define        ICH_CDOFF(x)            offsetof(struct auich_cdata, x)
+#define        ICH_PCMO_OFF(x)         ICH_CDOFF(ic_dmalist_pcmo[(x)])
+#define        ICH_PCMI_OFF(x)         ICH_CDOFF(ic_dmalist_pcmi[(x)])
+#define        ICH_MICI_OFF(x)         ICH_CDOFF(ic_dmalist_mici[(x)])
+
+struct auich_softc {
+       struct device sc_dev;
+       void *sc_ih;
+
+       audio_device_t sc_audev;
+
+       bus_space_tag_t iot;
+       bus_space_handle_t mix_ioh;
+       bus_space_handle_t aud_ioh;
+       bus_dma_tag_t dmat;
+
+       struct ac97_codec_if *codec_if;
+       struct ac97_host_if host_if;
+
+       /* DMA scatter-gather lists. */
+       bus_dmamap_t sc_cddmamap;
+#define        sc_cddma        sc_cddmamap->dm_segs[0].ds_addr
+
+       struct auich_cdata *sc_cdata;
+#define        dmalist_pcmo    sc_cdata->ic_dmalist_pcmo
+#define        dmalist_pcmi    sc_cdata->ic_dmalist_pcmi
+#define        dmalist_mici    sc_cdata->ic_dmalist_mici
+
+       int     ptr_pcmo,
+               ptr_pcmi,
+               ptr_mici;
+
+       /* i/o buffer pointers */
+       u_int32_t pcmo_start, pcmo_p, pcmo_end;
+       int pcmo_blksize, pcmo_fifoe;
+
+       u_int32_t pcmi_start, pcmi_p, pcmi_end;
+       int pcmi_blksize, pcmi_fifoe;
+
+       u_int32_t mici_start, mici_p, mici_end;
+       int mici_blksize, mici_fifoe;
+
+       struct auich_dma *sc_dmas;
+
+       void (*sc_pintr)(void *);
+       void *sc_parg;
+
+       void (*sc_rintr)(void *);
+       void *sc_rarg;
+};
+
+/* Debug */
+#ifdef AUDIO_DEBUG
+#define        DPRINTF(l,x)    do { if (auich_debug & (l)) printf x; } while(0)
+int auich_debug = 0xfffe;
+#define        ICH_DEBUG_CODECIO       0x0001
+#define        ICH_DEBUG_DMA           0x0002
+#define        ICH_DEBUG_PARAM         0x0004
+#else
+#define        DPRINTF(x,y)    /* nothing */
+#endif
+
+int    auich_match(struct device *, struct cfdata *, void *);
+void   auich_attach(struct device *, struct device *, void *);
+int    auich_intr(void *);
+
+struct cfattach auich_ca = {
+       sizeof(struct auich_softc), auich_match, auich_attach
+};
+
+int    auich_open(void *, int);
+void   auich_close(void *);
+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);
+int    auich_halt_output(void *);
+int    auich_halt_input(void *);
+int    auich_getdev(void *, struct audio_device *);
+int    auich_set_port(void *, mixer_ctrl_t *);
+int    auich_get_port(void *, mixer_ctrl_t *);
+int    auich_query_devinfo(void *, mixer_devinfo_t *);
+void   *auich_allocm(void *, int, size_t, int, int);
+void   auich_freem(void *, void *, int);
+size_t auich_round_buffersize(void *, int, size_t);
+paddr_t        auich_mappage(void *, void *, off_t, int);
+int    auich_get_props(void *);
+int    auich_trigger_output(void *, void *, void *, int, void (*)(void *),
+           void *, struct audio_params *);
+int    auich_trigger_input(void *, void *, void *, int, void (*)(void *),
+           void *, struct audio_params *);
+
+int    auich_alloc_cdata(struct auich_softc *);
+
+int    auich_allocmem(struct auich_softc *, size_t, size_t,
+           struct auich_dma *);
+int    auich_freemem(struct auich_softc *, struct auich_dma *);
+
+struct audio_hw_if auich_hw_if = {
+       auich_open,
+       auich_close,
+       NULL,                   /* drain */
+       auich_query_encoding,
+       auich_set_params,
+       auich_round_blocksize,
+       NULL,                   /* commit_setting */
+       NULL,                   /* init_output */
+       NULL,                   /* init_input */
+       NULL,                   /* start_output */
+       NULL,                   /* start_input */
+       auich_halt_output,
+       auich_halt_input,
+       NULL,                   /* speaker_ctl */
+       auich_getdev,
+       NULL,                   /* getfd */
+       auich_set_port,
+       auich_get_port,
+       auich_query_devinfo,
+       auich_allocm,
+       auich_freem,
+       auich_round_buffersize,
+       auich_mappage,
+       auich_get_props,
+       auich_trigger_output,
+       auich_trigger_input,
+};
+
+int    auich_attach_codec(void *, struct ac97_codec_if *);
+int    auich_read_codec(void *, u_int8_t, u_int16_t *);
+int    auich_write_codec(void *, u_int8_t, u_int16_t);
+void   auich_reset_codec(void *);
+
+static const struct auich_devtype {
+       int     product;
+       const char *name;
+       const char *shortname;
+} auich_devices[] = {
+       { 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,
+           "i82801BA (ICH2) AC-97 Audio",      "ICH2" },
+       { PCI_PRODUCT_INTEL_82440MX_ACA,
+           "i82440MX AC-97 Audio",             "440MX" },
+
+       { 0,
+           NULL,                       NULL },
+};
+
+static const struct auich_devtype *
+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)
+                       return (d);
+       }
+
+       return (NULL);
+}
+
+int
+auich_match(struct device *parent, struct cfdata *match, void *aux)
+{
+       struct pci_attach_args *pa = aux;
+
+       if (auich_lookup(pa) != NULL)
+               return (1);
+



Home | Main Index | Thread Index | Old Index