[BACK]Return to ics2101.c CVS log [TXT][DIR] Up to [local] / sys / dev / isa

Annotation of sys/dev/isa/ics2101.c, Revision 1.1

1.1     ! nbrk        1: /* $OpenBSD: ics2101.c,v 1.6 2003/04/10 10:11:24 miod Exp $ */
        !             2: /* $NetBSD: ics2101.c,v 1.6 1997/10/09 07:57:23 jtc Exp $ */
        !             3:
        !             4: /*-
        !             5:  * Copyright (c) 1996 The NetBSD Foundation, Inc.
        !             6:  * All rights reserved.
        !             7:  *
        !             8:  * This code is derived from software contributed to The NetBSD Foundation
        !             9:  * by Ken Hornstein and John Kohl.
        !            10:  *
        !            11:  * Redistribution and use in source and binary forms, with or without
        !            12:  * modification, are permitted provided that the following conditions
        !            13:  * are met:
        !            14:  * 1. Redistributions of source code must retain the above copyright
        !            15:  *    notice, this list of conditions and the following disclaimer.
        !            16:  * 2. Redistributions in binary form must reproduce the above copyright
        !            17:  *    notice, this list of conditions and the following disclaimer in the
        !            18:  *    documentation and/or other materials provided with the distribution.
        !            19:  * 3. All advertising materials mentioning features or use of this software
        !            20:  *    must display the following acknowledgement:
        !            21:  *        This product includes software developed by the NetBSD
        !            22:  *       Foundation, Inc. and its contributors.
        !            23:  * 4. Neither the name of The NetBSD Foundation nor the names of its
        !            24:  *    contributors may be used to endorse or promote products derived
        !            25:  *    from this software without specific prior written permission.
        !            26:  *
        !            27:  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
        !            28:  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
        !            29:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
        !            30:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
        !            31:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
        !            32:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
        !            33:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
        !            34:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
        !            35:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
        !            36:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
        !            37:  * POSSIBILITY OF SUCH DAMAGE.
        !            38:  */
        !            39:
        !            40: #include <sys/param.h>
        !            41: #include <sys/systm.h>
        !            42: #include <sys/errno.h>
        !            43: #include <sys/ioctl.h>
        !            44: #include <sys/syslog.h>
        !            45: #include <sys/device.h>
        !            46: #include <sys/proc.h>
        !            47: #include <sys/buf.h>
        !            48:
        !            49: #include <machine/cpu.h>
        !            50:
        !            51: #include <sys/audioio.h>
        !            52: #include <dev/audio_if.h>
        !            53:
        !            54: #include <dev/isa/isavar.h>
        !            55: #include <dev/isa/isadmavar.h>
        !            56:
        !            57: #include <dev/ic/ics2101reg.h>
        !            58: #include <dev/isa/ics2101var.h>
        !            59:
        !            60:
        !            61: #define ICS_VALUE      0x01
        !            62: #define ICS_MUTE       0x02
        !            63: #define ICS_MUTE_MUTED 0x04
        !            64:
        !            65: /* convert from [AUDIO_MIN_GAIN,AUDIO_MAX_GAIN] (0,255) to
        !            66:    [ICSMIX_MAX_ATTN,ICSMIX_MIN_ATTN] (0,127) */
        !            67:
        !            68: #define cvt_value(val) ((val) >> 1)
        !            69:
        !            70: static void ics2101_mix_doit(struct ics2101_softc *, u_int, u_int, u_int,
        !            71:     u_int);
        !            72: /*
        !            73:  * Program one channel of the ICS mixer
        !            74:  */
        !            75:
        !            76:
        !            77: static void
        !            78: ics2101_mix_doit(sc, chan, side, value, flags)
        !            79:        struct ics2101_softc *sc;
        !            80:        u_int chan, side, value, flags;
        !            81: {
        !            82:        bus_space_tag_t iot = sc->sc_iot;
        !            83:        unsigned char flip_left[6] = {0x01, 0x01, 0x01, 0x02, 0x01, 0x02};
        !            84:        unsigned char flip_right[6] = {0x02, 0x02, 0x02, 0x01, 0x02, 0x01};
        !            85:        register unsigned char ctrl_addr;
        !            86:        register unsigned char attn_addr;
        !            87:        register unsigned char normal;
        !            88:        int s;
        !            89:
        !            90:        if (chan < ICSMIX_CHAN_0 || chan > ICSMIX_CHAN_5)
        !            91:                return;
        !            92:        if (side != ICSMIX_LEFT && side != ICSMIX_RIGHT)
        !            93:                return;
        !            94:
        !            95:        if (flags & ICS_MUTE) {
        !            96:                value = cvt_value(sc->sc_setting[chan][side]);
        !            97:                sc->sc_mute[chan][side] = flags & ICS_MUTE_MUTED;
        !            98:        } else if (flags & ICS_VALUE) {
        !            99:                sc->sc_setting[chan][side] = value;
        !           100:                value = cvt_value(value);
        !           101:                if (value > ICSMIX_MIN_ATTN)
        !           102:                        value = ICSMIX_MIN_ATTN;
        !           103:        } else
        !           104:                return;
        !           105:
        !           106:        ctrl_addr = chan << 3;
        !           107:        attn_addr = chan << 3;
        !           108:
        !           109:        if (side == ICSMIX_LEFT) {
        !           110:                ctrl_addr |= ICSMIX_CTRL_LEFT;
        !           111:                attn_addr |= ICSMIX_ATTN_LEFT;
        !           112:                if (sc->sc_mute[chan][side])
        !           113:                        normal = 0x0;
        !           114:                else if (sc->sc_flags & ICS_FLIP)
        !           115:                        normal = flip_left[chan];
        !           116:                else
        !           117:                        normal = 0x01;
        !           118:        } else {
        !           119:                ctrl_addr |= ICSMIX_CTRL_RIGHT;
        !           120:                attn_addr |= ICSMIX_ATTN_RIGHT;
        !           121:                if (sc->sc_mute[chan][side])
        !           122:                        normal = 0x0;
        !           123:                else if (sc->sc_flags & ICS_FLIP)
        !           124:                        normal = flip_right[chan];
        !           125:                else
        !           126:                        normal = 0x02;
        !           127:        }
        !           128:
        !           129:        s = splaudio();
        !           130:
        !           131:        bus_space_write_1(iot, sc->sc_selio_ioh, sc->sc_selio, ctrl_addr);
        !           132:        bus_space_write_1(iot, sc->sc_dataio_ioh, sc->sc_dataio, normal);
        !           133:
        !           134:        bus_space_write_1(iot, sc->sc_selio_ioh, sc->sc_selio, attn_addr);
        !           135:        bus_space_write_1(iot, sc->sc_dataio_ioh, sc->sc_dataio, (unsigned char) value);
        !           136:
        !           137:        splx(s);
        !           138: }
        !           139:
        !           140: void
        !           141: ics2101_mix_mute(sc, chan, side, domute)
        !           142:        struct ics2101_softc *sc;
        !           143:        unsigned int chan, side, domute;
        !           144: {
        !           145:     ics2101_mix_doit(sc, chan, side, 0,
        !           146:                     domute ? ICS_MUTE|ICS_MUTE_MUTED : ICS_MUTE);
        !           147: }
        !           148:
        !           149: void
        !           150: ics2101_mix_attenuate(sc, chan, side, value)
        !           151:        struct ics2101_softc *sc;
        !           152:        unsigned int chan, side, value;
        !           153: {
        !           154:     ics2101_mix_doit(sc, chan, side, value, ICS_VALUE);
        !           155: }

CVSweb