Annotation of sys/arch/macppc/dev/daca.c, Revision 1.1
1.1 ! nbrk 1: /* $OpenBSD: daca.c,v 1.4 2007/04/23 16:27:20 deraadt Exp $ */
! 2: /* $Id: daca.c,v 1.4 2007/04/23 16:27:20 deraadt Exp $ */
! 3:
! 4: /*-
! 5: * Copyright (c) 2002,2003 Tsubai Masanari. All rights reserved.
! 6: *
! 7: * Redistribution and use in source and binary forms, with or without
! 8: * modification, are permitted provided that the following conditions
! 9: * are met:
! 10: * 1. Redistributions of source code must retain the above copyright
! 11: * notice, this list of conditions and the following disclaimer.
! 12: * 2. Redistributions in binary form must reproduce the above copyright
! 13: * notice, this list of conditions and the following disclaimer in the
! 14: * documentation and/or other materials provided with the distribution.
! 15: * 3. The name of the author may not be used to endorse or promote products
! 16: * derived from this software without specific prior written permission.
! 17: *
! 18: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
! 19: * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
! 20: * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
! 21: * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
! 22: * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
! 23: * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
! 24: * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
! 25: * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
! 26: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
! 27: * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
! 28: */
! 29:
! 30: /*
! 31: * Datasheet is available from
! 32: * http://www.indata.si/grega/pdfs/dac3550a.pdf
! 33: */
! 34:
! 35: #include <sys/param.h>
! 36: #include <sys/audioio.h>
! 37: #include <sys/device.h>
! 38: #include <sys/systm.h>
! 39:
! 40: #include <dev/audio_if.h>
! 41: #include <dev/ofw/openfirm.h>
! 42: #include <macppc/dev/dbdma.h>
! 43:
! 44: #include <machine/autoconf.h>
! 45:
! 46: #include <macppc/dev/i2svar.h>
! 47:
! 48: #ifdef DACA_DEBUG
! 49: # define DPRINTF printf
! 50: #else
! 51: # define DPRINTF while (0) printf
! 52: #endif
! 53:
! 54: /* XXX */
! 55: #define daca_softc i2s_softc
! 56:
! 57: /* XXX */
! 58: int kiic_write(struct device *, int, int, const void *, int);
! 59: int kiic_writereg(struct device *, int, u_int);
! 60:
! 61: int daca_getdev(void *, struct audio_device *);
! 62: int daca_match(struct device *, void *, void *);
! 63: void daca_attach(struct device *, struct device *, void *);
! 64: void daca_defer(struct device *);
! 65: void daca_init(struct daca_softc *);
! 66: void daca_set_volume(struct daca_softc *, int, int);
! 67:
! 68: struct cfattach daca_ca = {
! 69: sizeof(struct daca_softc), daca_match, daca_attach
! 70: };
! 71:
! 72: struct cfdriver daca_cd = {
! 73: NULL, "daca", DV_DULL
! 74: };
! 75:
! 76: struct audio_hw_if daca_hw_if = {
! 77: i2s_open,
! 78: i2s_close,
! 79: NULL,
! 80: i2s_query_encoding,
! 81: i2s_set_params,
! 82: i2s_round_blocksize,
! 83: NULL,
! 84: NULL,
! 85: NULL,
! 86: NULL,
! 87: NULL,
! 88: i2s_halt_output,
! 89: i2s_halt_input,
! 90: NULL,
! 91: daca_getdev,
! 92: NULL,
! 93: i2s_set_port,
! 94: i2s_get_port,
! 95: i2s_query_devinfo,
! 96: i2s_allocm, /* allocm */
! 97: NULL,
! 98: i2s_round_buffersize,
! 99: i2s_mappage,
! 100: i2s_get_props,
! 101: i2s_trigger_output,
! 102: i2s_trigger_input,
! 103: };
! 104:
! 105: struct audio_device daca_device = {
! 106: "DACA",
! 107: "",
! 108: "daca"
! 109: };
! 110:
! 111: /* DAC3550A registers */
! 112: #define DEQ_SR 0x01 /* Sample rate control (8) */
! 113: #define DEQ_AVOL 0x02 /* Analog volume (16) */
! 114: #define DEQ_GCFG 0x03 /* Global configuration (8) */
! 115:
! 116: int
! 117: daca_match(struct device *parent, void *match, void *aux)
! 118: {
! 119: struct confargs *ca = aux;
! 120: int soundbus, soundchip;
! 121: char compat[32];
! 122:
! 123: if (strcmp(ca->ca_name, "i2s") != 0)
! 124: return (0);
! 125:
! 126: if ((soundbus = OF_child(ca->ca_node)) == 0 ||
! 127: (soundchip = OF_child(soundbus)) == 0)
! 128: return (0);
! 129:
! 130: bzero(compat, sizeof compat);
! 131: OF_getprop(soundchip, "compatible", compat, sizeof compat);
! 132:
! 133: if (strcmp(compat, "daca") != 0)
! 134: return (0);
! 135:
! 136: return (1);
! 137: }
! 138:
! 139: #define DEQaddr 0x9a
! 140:
! 141: void
! 142: daca_attach(struct device *parent,struct device *self, void *aux)
! 143: {
! 144: struct daca_softc *sc = (struct daca_softc *)self;
! 145:
! 146: sc->sc_setvolume = daca_set_volume;
! 147:
! 148: i2s_attach(parent, sc, aux);
! 149: config_defer(self, daca_defer);
! 150: }
! 151:
! 152: void
! 153: daca_defer(struct device *dev)
! 154: {
! 155: struct daca_softc *sc = (struct daca_softc *)dev;
! 156: struct device *dv;
! 157:
! 158: TAILQ_FOREACH(dv, &alldevs, dv_list)
! 159: if (strncmp(dv->dv_xname, "kiic", 4) == 0 &&
! 160: strncmp(dv->dv_parent->dv_xname, "macobio", 7) == 0)
! 161: sc->sc_i2c = dv;
! 162: if (sc->sc_i2c == NULL) {
! 163: printf("%s: unable to find i2c\n", sc->sc_dev.dv_xname);
! 164: return;
! 165: }
! 166:
! 167: /* XXX If i2c has failed to attach, what should we do? */
! 168:
! 169: audio_attach_mi(&daca_hw_if, sc, &sc->sc_dev);
! 170:
! 171: daca_init(sc);
! 172: }
! 173:
! 174: void
! 175: daca_init(struct daca_softc *sc)
! 176: {
! 177: i2s_set_rate(sc, 44100);
! 178: kiic_writereg(sc->sc_i2c, 4, 0x01 | 0x02 | 0x04);
! 179: }
! 180:
! 181: int
! 182: daca_getdev(void *h, struct audio_device *retp)
! 183: {
! 184: *retp = daca_device;
! 185: return (0);
! 186: }
! 187:
! 188: void
! 189: daca_set_volume(struct daca_softc *sc, int left, int right)
! 190: {
! 191: u_int16_t data;
! 192:
! 193: sc->sc_vol_l = left;
! 194: sc->sc_vol_r = right;
! 195:
! 196: left >>= 2;
! 197: right >>= 2;
! 198: data = left << 8 | right;
! 199: kiic_write(sc->sc_i2c, DEQaddr, DEQ_AVOL, &data, 2);
! 200: }
CVSweb