The Design and Implementation of the FreeBSD Operating System, Second Edition
Now available: The Design and Implementation of the FreeBSD Operating System (Second Edition)


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]

FreeBSD/Linux Kernel Cross Reference
sys/dev/isa/ics2101.c

Version: -  FREEBSD  -  FREEBSD-13-STABLE  -  FREEBSD-13-0  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  l41  -  OPENBSD  -  linux-2.6  -  MK84  -  PLAN9  -  xnu-8792 
SearchContext: -  none  -  3  -  10 

    1 /* $OpenBSD: ics2101.c,v 1.10 2021/03/07 06:17:03 jsg 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  *
   20  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   21  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   24  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   25  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   26  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   27  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   30  * POSSIBILITY OF SUCH DAMAGE.
   31  */
   32 
   33 #include <sys/param.h>
   34 #include <sys/systm.h>
   35 #include <sys/errno.h>
   36 #include <sys/ioctl.h>
   37 #include <sys/syslog.h>
   38 #include <sys/device.h>
   39 #include <sys/buf.h>
   40 
   41 #include <machine/cpu.h>
   42 
   43 #include <sys/audioio.h>
   44 #include <dev/audio_if.h>
   45 
   46 #include <dev/isa/isavar.h>
   47 #include <dev/isa/isadmavar.h>
   48 
   49 #include <dev/ic/ics2101reg.h>
   50 #include <dev/isa/ics2101var.h>
   51 
   52 
   53 #define ICS_VALUE       0x01
   54 #define ICS_MUTE        0x02
   55 #define ICS_MUTE_MUTED  0x04
   56 
   57 /* convert from [AUDIO_MIN_GAIN,AUDIO_MAX_GAIN] (0,255) to
   58    [ICSMIX_MAX_ATTN,ICSMIX_MIN_ATTN] (0,127) */
   59 
   60 #define cvt_value(val) ((val) >> 1)
   61 
   62 static void ics2101_mix_doit(struct ics2101_softc *, u_int, u_int, u_int,
   63     u_int);
   64 /*
   65  * Program one channel of the ICS mixer
   66  */
   67 
   68 
   69 static void
   70 ics2101_mix_doit(struct ics2101_softc *sc, u_int chan, u_int side, u_int value,
   71     u_int flags)
   72 {
   73         bus_space_tag_t iot = sc->sc_iot;
   74         unsigned char flip_left[6] = {0x01, 0x01, 0x01, 0x02, 0x01, 0x02};
   75         unsigned char flip_right[6] = {0x02, 0x02, 0x02, 0x01, 0x02, 0x01};
   76         register unsigned char ctrl_addr;
   77         register unsigned char attn_addr;
   78         register unsigned char normal;
   79 
   80         if (chan < ICSMIX_CHAN_0 || chan > ICSMIX_CHAN_5)
   81                 return;
   82         if (side != ICSMIX_LEFT && side != ICSMIX_RIGHT)
   83                 return;
   84 
   85         if (flags & ICS_MUTE) {
   86                 value = cvt_value(sc->sc_setting[chan][side]);
   87                 sc->sc_mute[chan][side] = flags & ICS_MUTE_MUTED;
   88         } else if (flags & ICS_VALUE) {
   89                 sc->sc_setting[chan][side] = value;
   90                 value = cvt_value(value);
   91                 if (value > ICSMIX_MIN_ATTN)
   92                         value = ICSMIX_MIN_ATTN;
   93         } else
   94                 return;
   95 
   96         ctrl_addr = chan << 3;
   97         attn_addr = chan << 3;
   98 
   99         if (side == ICSMIX_LEFT) {
  100                 ctrl_addr |= ICSMIX_CTRL_LEFT;
  101                 attn_addr |= ICSMIX_ATTN_LEFT;
  102                 if (sc->sc_mute[chan][side])
  103                         normal = 0x0;
  104                 else if (sc->sc_flags & ICS_FLIP)
  105                         normal = flip_left[chan];
  106                 else
  107                         normal = 0x01;
  108         } else {
  109                 ctrl_addr |= ICSMIX_CTRL_RIGHT;
  110                 attn_addr |= ICSMIX_ATTN_RIGHT;
  111                 if (sc->sc_mute[chan][side])
  112                         normal = 0x0;
  113                 else if (sc->sc_flags & ICS_FLIP)
  114                         normal = flip_right[chan];
  115                 else
  116                         normal = 0x02;
  117         }
  118 
  119         mtx_enter(&audio_lock);
  120 
  121         bus_space_write_1(iot, sc->sc_selio_ioh, sc->sc_selio, ctrl_addr);
  122         bus_space_write_1(iot, sc->sc_dataio_ioh, sc->sc_dataio, normal);
  123 
  124         bus_space_write_1(iot, sc->sc_selio_ioh, sc->sc_selio, attn_addr);
  125         bus_space_write_1(iot, sc->sc_dataio_ioh, sc->sc_dataio, (unsigned char) value);
  126 
  127         mtx_leave(&audio_lock);
  128 }
  129 
  130 void
  131 ics2101_mix_mute(struct ics2101_softc *sc, unsigned int chan, unsigned int side,
  132     unsigned int domute)
  133 {
  134     ics2101_mix_doit(sc, chan, side, 0,
  135                      domute ? ICS_MUTE|ICS_MUTE_MUTED : ICS_MUTE);
  136 }
  137 
  138 void
  139 ics2101_mix_attenuate(struct ics2101_softc *sc, unsigned int chan,
  140     unsigned int side, unsigned int value)
  141 {
  142     ics2101_mix_doit(sc, chan, side, value, ICS_VALUE);
  143 }

Cache object: 86e6b5d84c162af5d988e6091f8b6995


[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ] [ list types ] [ track identifier ]


This page is part of the FreeBSD/Linux Linux Kernel Cross-Reference, and was automatically generated using a modified version of the LXR engine.