Source-Changes-HG archive

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

[src/netbsd-1-5]: src/sys/arch/macppc/dev Pull up revision 1.1 (new, requeste...



details:   https://anonhg.NetBSD.org/src/rev/9ed7ee834e26
branches:  netbsd-1-5
changeset: 490655:9ed7ee834e26
user:      he <he%NetBSD.org@localhost>
date:      Sun Feb 04 20:22:48 2001 +0000

description:
Pull up revision 1.1 (new, requested by mycroft):
  Add new driver for Apple sound chip.

diffstat:

 sys/arch/macppc/dev/awacs.c |  848 ++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 848 insertions(+), 0 deletions(-)

diffs (truncated from 852 to 300 lines):

diff -r a785846b4f05 -r 9ed7ee834e26 sys/arch/macppc/dev/awacs.c
--- /dev/null   Thu Jan 01 00:00:00 1970 +0000
+++ b/sys/arch/macppc/dev/awacs.c       Sun Feb 04 20:22:48 2001 +0000
@@ -0,0 +1,848 @@
+/*     $NetBSD: awacs.c,v 1.3.2.2 2001/02/04 20:22:48 he Exp $ */
+
+/*-
+ * Copyright (c) 2000 Tsubai Masanari.  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 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.
+ */
+
+#include <sys/param.h>
+#include <sys/audioio.h>
+#include <sys/device.h>
+#include <sys/malloc.h>
+#include <sys/systm.h>
+
+#include <dev/auconv.h>
+#include <dev/audio_if.h>
+#include <dev/mulaw.h>
+
+#include <uvm/uvm_extern.h>
+
+#include <machine/autoconf.h>
+#include <machine/pio.h>
+#include <macppc/dev/dbdma.h>
+
+#ifdef AWACS_DEBUG
+# define DPRINTF printf
+#else
+# define DPRINTF while (0) printf
+#endif
+
+struct awacs_softc {
+       struct device sc_dev;
+
+       void (*sc_ointr)(void *);       /* dma completion intr handler */
+       void *sc_oarg;                  /* arg for sc_ointr() */
+       int sc_opages;                  /* # of output pages */
+
+       void (*sc_iintr)(void *);       /* dma completion intr handler */
+       void *sc_iarg;                  /* arg for sc_iintr() */
+
+       u_int sc_record_source;         /* recording source mask */
+       u_int sc_output_mask;           /* output source mask */
+
+       char *sc_reg;
+       u_int sc_codecctl0;
+       u_int sc_codecctl1;
+       u_int sc_codecctl2;
+       u_int sc_codecctl4;
+       u_int sc_soundctl;
+
+       struct dbdma_regmap *sc_odma;
+       struct dbdma_regmap *sc_idma;
+       struct dbdma_command *sc_odmacmd;
+       struct dbdma_command *sc_idmacmd;
+};
+
+int awacs_match(struct device *, struct cfdata *, void *);
+void awacs_attach(struct device *, struct device *, void *);
+int awacs_intr(void *);
+
+int awacs_open(void *, int);
+void awacs_close(void *);
+int awacs_query_encoding(void *, struct audio_encoding *);
+int awacs_set_params(void *, int, int, struct audio_params *,
+                        struct audio_params *);
+int awacs_round_blocksize(void *, int);
+int awacs_trigger_output(void *, void *, void *, int, void (*)(void *),
+                            void *, struct audio_params *);
+int awacs_trigger_input(void *, void *, void *, int, void (*)(void *),
+                           void *, struct audio_params *);
+int awacs_halt_output(void *);
+int awacs_halt_input(void *);
+int awacs_getdev(void *, struct audio_device *);
+int awacs_set_port(void *, mixer_ctrl_t *);
+int awacs_get_port(void *, mixer_ctrl_t *);
+int awacs_query_devinfo(void *, mixer_devinfo_t *);
+size_t awacs_round_buffersize(void *, int, size_t);
+paddr_t awacs_mappage(void *, void *, off_t, int);
+int awacs_get_props(void *);
+
+static inline u_int awacs_read_reg(struct awacs_softc *, int);
+static inline void awacs_write_reg(struct awacs_softc *, int, int);
+void awacs_write_codec(struct awacs_softc *, int);
+void awacs_set_speaker_volume(struct awacs_softc *, int, int);
+void awacs_set_ext_volume(struct awacs_softc *, int, int);
+int awacs_set_rate(struct awacs_softc *, int);
+
+struct cfattach awacs_ca = {
+       sizeof(struct awacs_softc), awacs_match, awacs_attach
+};
+
+struct audio_hw_if awacs_hw_if = {
+       awacs_open,
+       awacs_close,
+       NULL,
+       awacs_query_encoding,
+       awacs_set_params,
+       awacs_round_blocksize,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       NULL,
+       awacs_halt_output,
+       awacs_halt_input,
+       NULL,
+       awacs_getdev,
+       NULL,
+       awacs_set_port,
+       awacs_get_port,
+       awacs_query_devinfo,
+       NULL,
+       NULL,
+       awacs_round_buffersize,
+       awacs_mappage,
+       awacs_get_props,
+       awacs_trigger_output,
+       awacs_trigger_input,
+};
+
+struct audio_device awacs_device = {
+       "AWACS",
+       "",
+       "awacs"
+};
+
+/* register offset */
+#define AWACS_SOUND_CTRL       0x00
+#define AWACS_CODEC_CTRL       0x10
+#define AWACS_CODEC_STATUS     0x20
+#define AWACS_CLIP_COUNT       0x30
+#define AWACS_BYTE_SWAP                0x40
+
+/* sound control */
+#define AWACS_INPUT_SUBFRAME0  0x00000001
+#define AWACS_INPUT_SUBFRAME1  0x00000002
+#define AWACS_INPUT_SUBFRAME2  0x00000004
+#define AWACS_INPUT_SUBFRAME3  0x00000008
+
+#define AWACS_OUTPUT_SUBFRAME0 0x00000010
+#define AWACS_OUTPUT_SUBFRAME1 0x00000020
+#define AWACS_OUTPUT_SUBFRAME2 0x00000040
+#define AWACS_OUTPUT_SUBFRAME3 0x00000080
+
+#define AWACS_RATE_44100       0x00000000
+#define AWACS_RATE_29400       0x00000100
+#define AWACS_RATE_22050       0x00000200
+#define AWACS_RATE_17640       0x00000300
+#define AWACS_RATE_14700       0x00000400
+#define AWACS_RATE_11025       0x00000500
+#define AWACS_RATE_8820                0x00000600
+#define AWACS_RATE_7350                0x00000700
+#define AWACS_RATE_MASK                0x00000700
+
+/* codec control */
+#define AWACS_CODEC_ADDR0      0x00000000
+#define AWACS_CODEC_ADDR1      0x00001000
+#define AWACS_CODEC_ADDR2      0x00002000
+#define AWACS_CODEC_ADDR4      0x00004000
+#define AWACS_CODEC_EMSEL0     0x00000000
+#define AWACS_CODEC_EMSEL1     0x00400000
+#define AWACS_CODEC_EMSEL2     0x00800000
+#define AWACS_CODEC_EMSEL4     0x00c00000
+#define AWACS_CODEC_BUSY       0x01000000
+
+/* cc0 */
+#define AWACS_DEFAULT_CD_GAIN  0x000000bb
+#define AWACS_INPUT_CD         0x00000200
+#define AWACS_INPUT_MIC                0x00000400
+#define AWACS_INPUT_MASK       0x00000e00
+
+/* cc1 */
+#define AWACS_MUTE_SPEAKER     0x00000080
+#define AWACS_MUTE_HEADPHONE   0x00000200
+
+int
+awacs_match(parent, match, aux)
+       struct device *parent;
+       struct cfdata *match;
+       void *aux;
+{
+       struct confargs *ca = aux;
+
+       if (strcmp(ca->ca_name, "awacs") != 0 &&
+           strcmp(ca->ca_name, "davbus") != 0)
+               return 0;
+
+       if (ca->ca_nreg < 24 || ca->ca_nintr < 12)
+               return 0;
+
+       return 1;
+}
+
+void
+awacs_attach(parent, self, aux)
+       struct device *parent;
+       struct device *self;
+       void *aux;
+{
+       struct awacs_softc *sc = (struct awacs_softc *)self;
+       struct confargs *ca = aux;
+
+       ca->ca_reg[0] += ca->ca_baseaddr;
+       ca->ca_reg[2] += ca->ca_baseaddr;
+       ca->ca_reg[4] += ca->ca_baseaddr;
+
+       sc->sc_reg = mapiodev(ca->ca_reg[0], ca->ca_reg[1]);
+
+       sc->sc_odma = mapiodev(ca->ca_reg[2], ca->ca_reg[3]); /* out */
+       sc->sc_idma = mapiodev(ca->ca_reg[4], ca->ca_reg[5]); /* in */
+       sc->sc_odmacmd = dbdma_alloc(20 * sizeof(struct dbdma_command));
+       sc->sc_idmacmd = dbdma_alloc(20 * sizeof(struct dbdma_command));
+
+       intr_establish(ca->ca_intr[0], IST_LEVEL, IPL_AUDIO, awacs_intr, sc);
+       intr_establish(ca->ca_intr[1], IST_LEVEL, IPL_AUDIO, awacs_intr, sc);
+       intr_establish(ca->ca_intr[2], IST_LEVEL, IPL_AUDIO, awacs_intr, sc);
+
+       printf(": irq %d,%d,%d\n",
+               ca->ca_intr[0], ca->ca_intr[1], ca->ca_intr[2]);
+
+       sc->sc_soundctl = AWACS_INPUT_SUBFRAME0 | AWACS_OUTPUT_SUBFRAME0 |
+               AWACS_RATE_44100;
+       awacs_write_reg(sc, AWACS_SOUND_CTRL, sc->sc_soundctl);
+
+       sc->sc_codecctl0 = AWACS_CODEC_ADDR0 | AWACS_CODEC_EMSEL0;
+       sc->sc_codecctl1 = AWACS_CODEC_ADDR1 | AWACS_CODEC_EMSEL0;
+       sc->sc_codecctl2 = AWACS_CODEC_ADDR2 | AWACS_CODEC_EMSEL0;
+       sc->sc_codecctl4 = AWACS_CODEC_ADDR4 | AWACS_CODEC_EMSEL0;
+
+       sc->sc_codecctl0 |= AWACS_INPUT_CD | AWACS_DEFAULT_CD_GAIN;
+       awacs_write_codec(sc, sc->sc_codecctl0);
+
+       /* Set initial volume[s] */
+       awacs_set_speaker_volume(sc, 80, 80);
+
+       /* Set loopback (for CD?) */
+       sc->sc_codecctl1 |= 0x440;
+       awacs_write_codec(sc, sc->sc_codecctl1);
+
+       sc->sc_output_mask = 1 << 0;
+
+       sc->sc_codecctl1 &= ~AWACS_MUTE_SPEAKER;
+       sc->sc_codecctl1 |= AWACS_MUTE_HEADPHONE;
+       awacs_write_codec(sc, sc->sc_codecctl1);
+
+       /* Enable interrupts and looping mode. */
+       /* XXX ... */
+
+       audio_attach_mi(&awacs_hw_if, sc, &sc->sc_dev);
+}
+
+u_int
+awacs_read_reg(sc, reg)
+       struct awacs_softc *sc;
+       int reg;
+{
+       char *addr = sc->sc_reg;
+
+       return in32rb(addr + reg);
+}
+
+void
+awacs_write_reg(sc, reg, val)
+       struct awacs_softc *sc;
+       int reg, val;
+{
+       char *addr = sc->sc_reg;
+
+       out32rb(addr + reg, val);
+}
+
+void
+awacs_write_codec(sc, value)
+       struct awacs_softc *sc;
+       int value;
+{



Home | Main Index | Thread Index | Old Index