[BACK]Return to snapper.c CVS log [TXT][DIR] Up to [local] / sys / arch / macppc / dev

Annotation of sys/arch/macppc/dev/snapper.c, Revision 1.1

1.1     ! nbrk        1: /*     $OpenBSD: snapper.c,v 1.28 2007/04/23 16:27:20 deraadt Exp $    */
        !             2: /*     $NetBSD: snapper.c,v 1.1 2003/12/27 02:19:34 grant Exp $        */
        !             3:
        !             4: /*-
        !             5:  * Copyright (c) 2002 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://focus.ti.com/docs/prod/folders/print/tas3004.html
        !            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 SNAPPER_DEBUG
        !            49: # define DPRINTF printf
        !            50: #else
        !            51: # define DPRINTF while (0) printf
        !            52: #endif
        !            53:
        !            54: /* XXX */
        !            55: #define snapper_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: void snapper_init(struct snapper_softc *);
        !            62: int snapper_getdev(void *, struct audio_device *);
        !            63: int snapper_match(struct device *, void *, void *);
        !            64: void snapper_attach(struct device *, struct device *, void *);
        !            65: void snapper_defer(struct device *);
        !            66: void snapper_set_volume(struct snapper_softc *, int, int);
        !            67: void snapper_set_bass(struct snapper_softc *, int);
        !            68: void snapper_set_treble(struct snapper_softc *, int);
        !            69:
        !            70: int tas3004_write(struct snapper_softc *, u_int, const void *);
        !            71: int tas3004_init(struct snapper_softc *);
        !            72:
        !            73: struct cfattach snapper_ca = {
        !            74:        sizeof(struct snapper_softc), snapper_match, snapper_attach
        !            75: };
        !            76: struct cfdriver snapper_cd = {
        !            77:        NULL, "snapper", DV_DULL
        !            78: };
        !            79:
        !            80: struct audio_hw_if snapper_hw_if = {
        !            81:        i2s_open,
        !            82:        i2s_close,
        !            83:        NULL,
        !            84:        i2s_query_encoding,
        !            85:        i2s_set_params,
        !            86:        i2s_round_blocksize,
        !            87:        NULL,
        !            88:        NULL,
        !            89:        NULL,
        !            90:        NULL,
        !            91:        NULL,
        !            92:        i2s_halt_output,
        !            93:        i2s_halt_input,
        !            94:        NULL,
        !            95:        snapper_getdev,
        !            96:        NULL,
        !            97:        i2s_set_port,
        !            98:        i2s_get_port,
        !            99:        i2s_query_devinfo,
        !           100:        i2s_allocm,             /* allocm */
        !           101:        NULL,
        !           102:        i2s_round_buffersize,
        !           103:        i2s_mappage,
        !           104:        i2s_get_props,
        !           105:        i2s_trigger_output,
        !           106:        i2s_trigger_input,
        !           107: };
        !           108:
        !           109: struct audio_device snapper_device = {
        !           110:        "SNAPPER",
        !           111:        "",
        !           112:        "snapper"
        !           113: };
        !           114:
        !           115: const uint8_t snapper_trebletab[] = {
        !           116:        0x96,   /* -18dB */
        !           117:        0x94,   /* -17dB */
        !           118:        0x92,   /* -16dB */
        !           119:        0x90,   /* -15dB */
        !           120:        0x8e,   /* -14dB */
        !           121:        0x8c,   /* -13dB */
        !           122:        0x8a,   /* -12dB */
        !           123:        0x88,   /* -11dB */
        !           124:        0x86,   /* -10dB */
        !           125:        0x84,   /* -9dB */
        !           126:        0x82,   /* -8dB */
        !           127:        0x80,   /* -7dB */
        !           128:        0x7e,   /* -6dB */
        !           129:        0x7c,   /* -5dB */
        !           130:        0x7a,   /* -4dB */
        !           131:        0x78,   /* -3dB */
        !           132:        0x76,   /* -2dB */
        !           133:        0x74,   /* -1dB */
        !           134:        0x72,   /* 0dB */
        !           135:        0x70,   /* 1dB */
        !           136:        0x6d,   /* 2dB */
        !           137:        0x6b,   /* 3dB */
        !           138:        0x68,   /* 4dB */
        !           139:        0x65,   /* 5dB */
        !           140:        0x62,   /* 6dB */
        !           141:        0x5d,   /* 7dB */
        !           142:        0x59,   /* 8dB */
        !           143:        0x53,   /* 9dB */
        !           144:        0x4d,   /* 10dB */
        !           145:        0x47,   /* 11dB */
        !           146:        0x3f,   /* 12dB */
        !           147:        0x36,   /* 13dB */
        !           148:        0x2c,   /* 14dB */
        !           149:        0x20,   /* 15dB */
        !           150:        0x13,   /* 16dB */
        !           151:        0x04,   /* 17dB */
        !           152:        0x01,   /* 18dB */
        !           153: };
        !           154:
        !           155: const uint8_t snapper_basstab[] = {
        !           156:        0x96,   /* -18dB */
        !           157:        0x94,   /* -17dB */
        !           158:        0x92,   /* -16dB */
        !           159:        0x90,   /* -15dB */
        !           160:        0x8e,   /* -14dB */
        !           161:        0x8c,   /* -13dB */
        !           162:        0x8a,   /* -12dB */
        !           163:        0x88,   /* -11dB */
        !           164:        0x86,   /* -10dB */
        !           165:        0x84,   /* -9dB */
        !           166:        0x82,   /* -8dB */
        !           167:        0x80,   /* -7dB */
        !           168:        0x7e,   /* -6dB */
        !           169:        0x7c,   /* -5dB */
        !           170:        0x7a,   /* -4dB */
        !           171:        0x78,   /* -3dB */
        !           172:        0x76,   /* -2dB */
        !           173:        0x74,   /* -1dB */
        !           174:        0x72,   /* 0dB */
        !           175:        0x6f,   /* 1dB */
        !           176:        0x6d,   /* 2dB */
        !           177:        0x6a,   /* 3dB */
        !           178:        0x67,   /* 4dB */
        !           179:        0x65,   /* 5dB */
        !           180:        0x62,   /* 6dB */
        !           181:        0x5f,   /* 7dB */
        !           182:        0x5b,   /* 8dB */
        !           183:        0x55,   /* 9dB */
        !           184:        0x4f,   /* 10dB */
        !           185:        0x49,   /* 11dB */
        !           186:        0x43,   /* 12dB */
        !           187:        0x3b,   /* 13dB */
        !           188:        0x33,   /* 14dB */
        !           189:        0x29,   /* 15dB */
        !           190:        0x1e,   /* 16dB */
        !           191:        0x11,   /* 17dB */
        !           192:        0x01,   /* 18dB */
        !           193: };
        !           194:
        !           195: /* TAS3004 registers */
        !           196: #define DEQ_MCR1       0x01    /* Main control register 1 (1byte) */
        !           197: #define DEQ_DRC                0x02    /* Dynamic range compression (6bytes?) */
        !           198: #define DEQ_VOLUME     0x04    /* Volume (6bytes) */
        !           199: #define DEQ_TREBLE     0x05    /* Treble control (1byte) */
        !           200: #define DEQ_BASS       0x06    /* Bass control (1byte) */
        !           201: #define DEQ_MIXER_L    0x07    /* Mixer left gain (9bytes) */
        !           202: #define DEQ_MIXER_R    0x08    /* Mixer right gain (9bytes) */
        !           203: #define DEQ_LB0                0x0a    /* Left biquad 0 (15bytes) */
        !           204: #define DEQ_LB1                0x0b    /* Left biquad 1 (15bytes) */
        !           205: #define DEQ_LB2                0x0c    /* Left biquad 2 (15bytes) */
        !           206: #define DEQ_LB3                0x0d    /* Left biquad 3 (15bytes) */
        !           207: #define DEQ_LB4                0x0e    /* Left biquad 4 (15bytes) */
        !           208: #define DEQ_LB5                0x0f    /* Left biquad 5 (15bytes) */
        !           209: #define DEQ_LB6                0x10    /* Left biquad 6 (15bytes) */
        !           210: #define DEQ_RB0                0x13    /* Right biquad 0 (15bytes) */
        !           211: #define DEQ_RB1                0x14    /* Right biquad 1 (15bytes) */
        !           212: #define DEQ_RB2                0x15    /* Right biquad 2 (15bytes) */
        !           213: #define DEQ_RB3                0x16    /* Right biquad 3 (15bytes) */
        !           214: #define DEQ_RB4                0x17    /* Right biquad 4 (15bytes) */
        !           215: #define DEQ_RB5                0x18    /* Right biquad 5 (15bytes) */
        !           216: #define DEQ_RB6                0x19    /* Right biquad 6 (15bytes) */
        !           217: #define DEQ_LLB                0x21    /* Left loudness biquad (15bytes) */
        !           218: #define DEQ_RLB                0x22    /* Right loudness biquad (15bytes) */
        !           219: #define DEQ_LLB_GAIN   0x23    /* Left loudness biquad gain (3bytes) */
        !           220: #define DEQ_RLB_GAIN   0x24    /* Right loudness biquad gain (3bytes) */
        !           221: #define DEQ_ACR                0x40    /* Analog control register (1byte) */
        !           222: #define DEQ_MCR2       0x43    /* Main control register 2 (1byte) */
        !           223:
        !           224: #define DEQ_MCR1_FL    0x80    /* Fast load */
        !           225: #define DEQ_MCR1_SC    0x40    /* SCLK frequency */
        !           226: #define  DEQ_MCR1_SC_32        0x00    /*  32fs */
        !           227: #define  DEQ_MCR1_SC_64        0x40    /*  64fs */
        !           228: #define DEQ_MCR1_SM    0x30    /* Output serial port mode */
        !           229: #define  DEQ_MCR1_SM_L 0x00    /*  Left justified */
        !           230: #define  DEQ_MCR1_SM_R 0x10    /*  Right justified */
        !           231: #define  DEQ_MCR1_SM_I2S 0x20  /*  I2S */
        !           232: #define DEQ_MCR1_W     0x03    /* Serial port word length */
        !           233: #define  DEQ_MCR1_W_16 0x00    /*  16 bit */
        !           234: #define  DEQ_MCR1_W_18 0x01    /*  18 bit */
        !           235: #define  DEQ_MCR1_W_20 0x02    /*  20 bit */
        !           236:
        !           237: #define DEQ_MCR2_DL    0x80    /* Download */
        !           238: #define DEQ_MCR2_AP    0x02    /* All pass mode */
        !           239:
        !           240: #define DEQ_ACR_ADM    0x80    /* ADC output mode */
        !           241: #define DEQ_ACR_LRB    0x40    /* Select B input */
        !           242: #define DEQ_ACR_DM     0x0c    /* De-emphasis control */
        !           243: #define  DEQ_ACR_DM_OFF        0x00    /*  off */
        !           244: #define  DEQ_ACR_DM_48 0x04    /*  fs = 48kHz */
        !           245: #define  DEQ_ACR_DM_44 0x08    /*  fs = 44.1kHz */
        !           246: #define DEQ_ACR_INP    0x02    /* Analog input select */
        !           247: #define  DEQ_ACR_INP_A 0x00    /*  A */
        !           248: #define  DEQ_ACR_INP_B 0x02    /*  B */
        !           249: #define DEQ_ACR_APD    0x01    /* Analog power down */
        !           250:
        !           251: struct tas3004_reg {
        !           252:        u_char MCR1[1];
        !           253:        u_char DRC[6];
        !           254:        u_char VOLUME[6];
        !           255:        u_char TREBLE[1];
        !           256:        u_char BASS[1];
        !           257:        u_char MIXER_L[9];
        !           258:        u_char MIXER_R[9];
        !           259:        u_char LB0[15];
        !           260:        u_char LB1[15];
        !           261:        u_char LB2[15];
        !           262:        u_char LB3[15];
        !           263:        u_char LB4[15];
        !           264:        u_char LB5[15];
        !           265:        u_char LB6[15];
        !           266:        u_char RB0[15];
        !           267:        u_char RB1[15];
        !           268:        u_char RB2[15];
        !           269:        u_char RB3[15];
        !           270:        u_char RB4[15];
        !           271:        u_char RB5[15];
        !           272:        u_char RB6[15];
        !           273:        u_char LLB[15];
        !           274:        u_char RLB[15];
        !           275:        u_char LLB_GAIN[3];
        !           276:        u_char RLB_GAIN[3];
        !           277:        u_char ACR[1];
        !           278:        u_char MCR2[1];
        !           279: };
        !           280:
        !           281: int
        !           282: snapper_match(struct device *parent, void *match, void *aux)
        !           283: {
        !           284:        struct confargs *ca = aux;
        !           285:        int soundbus, soundchip, soundcodec;
        !           286:        char compat[32];
        !           287:
        !           288:        if (strcmp(ca->ca_name, "i2s") != 0)
        !           289:                return (0);
        !           290:
        !           291:        if ((soundbus = OF_child(ca->ca_node)) == 0 ||
        !           292:            (soundchip = OF_child(soundbus)) == 0)
        !           293:                return (0);
        !           294:
        !           295:        bzero(compat, sizeof compat);
        !           296:        OF_getprop(soundchip, "compatible", compat, sizeof compat);
        !           297:
        !           298:        if (strcmp(compat, "snapper") == 0)
        !           299:                return (1);
        !           300:
        !           301:        if (OF_getprop(soundchip, "platform-tas-codec-ref",
        !           302:            &soundcodec, sizeof soundcodec) == sizeof soundcodec)
        !           303:                return (1);
        !           304:
        !           305:        return (0);
        !           306: }
        !           307:
        !           308: void
        !           309: snapper_attach(struct device *parent, struct device *self, void *aux)
        !           310: {
        !           311:        struct snapper_softc *sc = (struct snapper_softc *)self;
        !           312:
        !           313:        sc->sc_setvolume = snapper_set_volume;
        !           314:        sc->sc_setbass = snapper_set_bass;
        !           315:        sc->sc_settreble = snapper_set_treble;
        !           316:
        !           317:        i2s_attach(parent, sc, aux);
        !           318:        config_defer(self, snapper_defer);
        !           319: }
        !           320:
        !           321: void
        !           322: snapper_defer(struct device *dev)
        !           323: {
        !           324:        struct snapper_softc *sc = (struct snapper_softc *)dev;
        !           325:        struct device *dv;
        !           326:
        !           327:        TAILQ_FOREACH(dv, &alldevs, dv_list)
        !           328:                if (strncmp(dv->dv_xname, "kiic", 4) == 0 &&
        !           329:                    strncmp(dv->dv_parent->dv_xname, "macobio", 7) == 0)
        !           330:                        sc->sc_i2c = dv;
        !           331:        if (sc->sc_i2c == NULL) {
        !           332:                printf("%s: unable to find i2c\n", sc->sc_dev.dv_xname);
        !           333:                return;
        !           334:        }
        !           335:
        !           336:        /* XXX If i2c has failed to attach, what should we do? */
        !           337:
        !           338:        audio_attach_mi(&snapper_hw_if, sc, &sc->sc_dev);
        !           339:
        !           340:        /* kiic_setmode(sc->sc_i2c, I2C_STDSUBMODE); */
        !           341:        snapper_init(sc);
        !           342: }
        !           343:
        !           344: void
        !           345: snapper_set_volume(struct snapper_softc *sc, int left, int right)
        !           346: {
        !           347:        u_char vol[6];
        !           348:
        !           349:        sc->sc_vol_l = left;
        !           350:        sc->sc_vol_r = right;
        !           351:
        !           352:        left <<= 8;     /* XXX for now */
        !           353:        right <<= 8;
        !           354:
        !           355:        vol[0] = left >> 16;
        !           356:        vol[1] = left >> 8;
        !           357:        vol[2] = left;
        !           358:        vol[3] = right >> 16;
        !           359:        vol[4] = right >> 8;
        !           360:        vol[5] = right;
        !           361:
        !           362:        tas3004_write(sc, DEQ_VOLUME, vol);
        !           363: }
        !           364:
        !           365: void
        !           366: snapper_set_treble(struct snapper_softc *sc, int value)
        !           367: {
        !           368:        uint8_t reg;
        !           369:
        !           370:        if ((value >= 0) && (value <= 255) && (value != sc->sc_treble)) {
        !           371:                reg = snapper_trebletab[(value >> 3) + 2];
        !           372:                if (tas3004_write(sc, DEQ_TREBLE, &reg) < 0)
        !           373:                        return;
        !           374:                sc->sc_treble = value;
        !           375:        }
        !           376: }
        !           377:
        !           378: void
        !           379: snapper_set_bass(struct snapper_softc *sc, int value)
        !           380: {
        !           381:        uint8_t reg;
        !           382:
        !           383:        if ((value >= 0) && (value <= 255) && (value != sc->sc_bass)) {
        !           384:                reg = snapper_basstab[(value >> 3) + 2];
        !           385:                if (tas3004_write(sc, DEQ_BASS, &reg) < 0)
        !           386:                        return;
        !           387:                sc->sc_bass = value;
        !           388:        }
        !           389: }
        !           390:
        !           391: const struct tas3004_reg tas3004_initdata = {
        !           392:        { DEQ_MCR1_SC_64 | DEQ_MCR1_SM_I2S | DEQ_MCR1_W_20 },   /* MCR1 */
        !           393:        { 1, 0, 0, 0, 0, 0 },                                   /* DRC */
        !           394:        { 0, 0, 0, 0, 0, 0 },                                   /* VOLUME */
        !           395:        { 0x72 },                                               /* TREBLE */
        !           396:        { 0x72 },                                               /* BASS */
        !           397:        { 0x10, 0x00, 0x00, 0, 0, 0, 0, 0, 0 },                 /* MIXER_L */
        !           398:        { 0x10, 0x00, 0x00, 0, 0, 0, 0, 0, 0 },                 /* MIXER_R */
        !           399:        { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },     /* BIQUAD */
        !           400:        { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },     /* BIQUAD */
        !           401:        { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },     /* BIQUAD */
        !           402:        { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },     /* BIQUAD */
        !           403:        { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },     /* BIQUAD */
        !           404:        { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },     /* BIQUAD */
        !           405:        { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },     /* BIQUAD */
        !           406:        { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },     /* BIQUAD */
        !           407:        { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },     /* BIQUAD */
        !           408:        { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },     /* BIQUAD */
        !           409:        { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },     /* BIQUAD */
        !           410:        { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },     /* BIQUAD */
        !           411:        { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },     /* BIQUAD */
        !           412:        { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },     /* BIQUAD */
        !           413:        { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },     /* BIQUAD */
        !           414:        { 0x10, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 },     /* BIQUAD */
        !           415:        { 0, 0, 0 },                                            /* LLB_GAIN */
        !           416:        { 0, 0, 0 },                                            /* RLB_GAIN */
        !           417:        { 0 },                                                  /* ACR */
        !           418:        { 0 }                                                   /* MCR2 */
        !           419: };
        !           420:
        !           421: const char tas3004_regsize[] = {
        !           422:        0,                                      /* 0x00 */
        !           423:        sizeof tas3004_initdata.MCR1,           /* 0x01 */
        !           424:        sizeof tas3004_initdata.DRC,            /* 0x02 */
        !           425:        0,                                      /* 0x03 */
        !           426:        sizeof tas3004_initdata.VOLUME,         /* 0x04 */
        !           427:        sizeof tas3004_initdata.TREBLE,         /* 0x05 */
        !           428:        sizeof tas3004_initdata.BASS,           /* 0x06 */
        !           429:        sizeof tas3004_initdata.MIXER_L,        /* 0x07 */
        !           430:        sizeof tas3004_initdata.MIXER_R,        /* 0x08 */
        !           431:        0,                                      /* 0x09 */
        !           432:        sizeof tas3004_initdata.LB0,            /* 0x0a */
        !           433:        sizeof tas3004_initdata.LB1,            /* 0x0b */
        !           434:        sizeof tas3004_initdata.LB2,            /* 0x0c */
        !           435:        sizeof tas3004_initdata.LB3,            /* 0x0d */
        !           436:        sizeof tas3004_initdata.LB4,            /* 0x0e */
        !           437:        sizeof tas3004_initdata.LB5,            /* 0x0f */
        !           438:        sizeof tas3004_initdata.LB6,            /* 0x10 */
        !           439:        0,                                      /* 0x11 */
        !           440:        0,                                      /* 0x12 */
        !           441:        sizeof tas3004_initdata.RB0,            /* 0x13 */
        !           442:        sizeof tas3004_initdata.RB1,            /* 0x14 */
        !           443:        sizeof tas3004_initdata.RB2,            /* 0x15 */
        !           444:        sizeof tas3004_initdata.RB3,            /* 0x16 */
        !           445:        sizeof tas3004_initdata.RB4,            /* 0x17 */
        !           446:        sizeof tas3004_initdata.RB5,            /* 0x18 */
        !           447:        sizeof tas3004_initdata.RB6,            /* 0x19 */
        !           448:        0,0,0,0, 0,0,
        !           449:        0,                                      /* 0x20 */
        !           450:        sizeof tas3004_initdata.LLB,            /* 0x21 */
        !           451:        sizeof tas3004_initdata.RLB,            /* 0x22 */
        !           452:        sizeof tas3004_initdata.LLB_GAIN,       /* 0x23 */
        !           453:        sizeof tas3004_initdata.RLB_GAIN,       /* 0x24 */
        !           454:        0,0,0,0, 0,0,0,0, 0,0,0,
        !           455:        0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
        !           456:        sizeof tas3004_initdata.ACR,            /* 0x40 */
        !           457:        0,                                      /* 0x41 */
        !           458:        0,                                      /* 0x42 */
        !           459:        sizeof tas3004_initdata.MCR2            /* 0x43 */
        !           460: };
        !           461:
        !           462: #define DEQaddr 0x6a
        !           463:
        !           464: int
        !           465: tas3004_write(struct snapper_softc *sc, u_int reg, const void *data)
        !           466: {
        !           467:        int size;
        !           468:
        !           469:        KASSERT(reg < sizeof tas3004_regsize);
        !           470:        size = tas3004_regsize[reg];
        !           471:        KASSERT(size > 0);
        !           472:
        !           473:        if (kiic_write(sc->sc_i2c, DEQaddr, reg, data, size))
        !           474:                return (-1);
        !           475:
        !           476:        return (0);
        !           477: }
        !           478:
        !           479: #define DEQ_WRITE(sc, reg, addr) \
        !           480:        if (tas3004_write(sc, reg, addr)) goto err
        !           481:
        !           482: int
        !           483: tas3004_init(struct snapper_softc *sc)
        !           484: {
        !           485:        deq_reset(sc);
        !           486:
        !           487:        DEQ_WRITE(sc, DEQ_LB0, tas3004_initdata.LB0);
        !           488:        DEQ_WRITE(sc, DEQ_LB1, tas3004_initdata.LB1);
        !           489:        DEQ_WRITE(sc, DEQ_LB2, tas3004_initdata.LB2);
        !           490:        DEQ_WRITE(sc, DEQ_LB3, tas3004_initdata.LB3);
        !           491:        DEQ_WRITE(sc, DEQ_LB4, tas3004_initdata.LB4);
        !           492:        DEQ_WRITE(sc, DEQ_LB5, tas3004_initdata.LB5);
        !           493:        DEQ_WRITE(sc, DEQ_LB6, tas3004_initdata.LB6);
        !           494:        DEQ_WRITE(sc, DEQ_RB0, tas3004_initdata.RB0);
        !           495:        DEQ_WRITE(sc, DEQ_RB1, tas3004_initdata.RB1);
        !           496:        DEQ_WRITE(sc, DEQ_RB1, tas3004_initdata.RB1);
        !           497:        DEQ_WRITE(sc, DEQ_RB2, tas3004_initdata.RB2);
        !           498:        DEQ_WRITE(sc, DEQ_RB3, tas3004_initdata.RB3);
        !           499:        DEQ_WRITE(sc, DEQ_RB4, tas3004_initdata.RB4);
        !           500:        DEQ_WRITE(sc, DEQ_RB5, tas3004_initdata.RB5);
        !           501:        DEQ_WRITE(sc, DEQ_MCR1, tas3004_initdata.MCR1);
        !           502:        DEQ_WRITE(sc, DEQ_MCR2, tas3004_initdata.MCR2);
        !           503:        DEQ_WRITE(sc, DEQ_DRC, tas3004_initdata.DRC);
        !           504:        DEQ_WRITE(sc, DEQ_VOLUME, tas3004_initdata.VOLUME);
        !           505:        DEQ_WRITE(sc, DEQ_TREBLE, tas3004_initdata.TREBLE);
        !           506:        DEQ_WRITE(sc, DEQ_BASS, tas3004_initdata.BASS);
        !           507:        DEQ_WRITE(sc, DEQ_MIXER_L, tas3004_initdata.MIXER_L);
        !           508:        DEQ_WRITE(sc, DEQ_MIXER_R, tas3004_initdata.MIXER_R);
        !           509:        DEQ_WRITE(sc, DEQ_LLB, tas3004_initdata.LLB);
        !           510:        DEQ_WRITE(sc, DEQ_RLB, tas3004_initdata.RLB);
        !           511:        DEQ_WRITE(sc, DEQ_LLB_GAIN, tas3004_initdata.LLB_GAIN);
        !           512:        DEQ_WRITE(sc, DEQ_RLB_GAIN, tas3004_initdata.RLB_GAIN);
        !           513:        DEQ_WRITE(sc, DEQ_ACR, tas3004_initdata.ACR);
        !           514:
        !           515:        return (0);
        !           516: err:
        !           517:        printf("%s: tas3004_init failed\n", sc->sc_dev.dv_xname);
        !           518:        return (-1);
        !           519: }
        !           520:
        !           521: void
        !           522: snapper_init(struct snapper_softc *sc)
        !           523: {
        !           524:
        !           525:        /* "sample-rates" (44100, 48000) */
        !           526:        i2s_set_rate(sc, 44100);
        !           527:
        !           528: #if 1
        !           529:        /* Enable I2C interrupts. */
        !           530: #define IER 4
        !           531: #define I2C_INT_DATA 0x01
        !           532: #define I2C_INT_ADDR 0x02
        !           533: #define I2C_INT_STOP 0x04
        !           534:        kiic_writereg(sc->sc_i2c, IER,I2C_INT_DATA|I2C_INT_ADDR|I2C_INT_STOP);
        !           535: #endif
        !           536:
        !           537:        if (tas3004_init(sc))
        !           538:                return;
        !           539:
        !           540:        snapper_set_volume(sc, 80, 80);
        !           541: }
        !           542:
        !           543: int
        !           544: snapper_getdev(void *h, struct audio_device *retp)
        !           545: {
        !           546:        *retp = snapper_device;
        !           547:        return (0);
        !           548: }

CVSweb