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/ic/attimer.c

Version: -  FREEBSD  -  FREEBSD-12-STABLE  -  FREEBSD-12-0  -  FREEBSD-11-STABLE  -  FREEBSD-11-2  -  FREEBSD-11-1  -  FREEBSD-11-0  -  FREEBSD-10-STABLE  -  FREEBSD-10-4  -  FREEBSD-10-3  -  FREEBSD-10-2  -  FREEBSD-10-1  -  FREEBSD-10-0  -  FREEBSD-9-STABLE  -  FREEBSD-9-3  -  FREEBSD-9-2  -  FREEBSD-9-1  -  FREEBSD-9-0  -  FREEBSD-8-STABLE  -  FREEBSD-8-4  -  FREEBSD-8-3  -  FREEBSD-8-2  -  FREEBSD-8-1  -  FREEBSD-8-0  -  FREEBSD-7-STABLE  -  FREEBSD-7-4  -  FREEBSD-7-3  -  FREEBSD-7-2  -  FREEBSD-7-1  -  FREEBSD-7-0  -  FREEBSD-6-STABLE  -  FREEBSD-6-4  -  FREEBSD-6-3  -  FREEBSD-6-2  -  FREEBSD-6-1  -  FREEBSD-6-0  -  FREEBSD-5-STABLE  -  FREEBSD-5-5  -  FREEBSD-5-4  -  FREEBSD-5-3  -  FREEBSD-5-2  -  FREEBSD-5-1  -  FREEBSD-5-0  -  FREEBSD-4-STABLE  -  FREEBSD-3-STABLE  -  FREEBSD22  -  linux-2.6  -  linux-2.4.22  -  MK83  -  MK84  -  PLAN9  -  DFBSD  -  NETBSD  -  NETBSD5  -  NETBSD4  -  NETBSD3  -  NETBSD20  -  OPENBSD  -  xnu-517  -  xnu-792  -  xnu-792.6.70  -  xnu-1228  -  xnu-1456.1.26  -  xnu-1699.24.8  -  xnu-2050.18.24  -  OPENSOLARIS  -  minix-3-1-1 
SearchContext: -  none  -  3  -  10 

    1 /*      $NetBSD: attimer.c,v 1.9 2008/06/12 22:30:30 cegger Exp $       */
    2 
    3 /*
    4  *  Copyright (c) 2005 The NetBSD Foundation.
    5  *  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  *
   16  *  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
   17  *  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
   18  *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
   19  *  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
   20  *  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
   21  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
   22  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
   23  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
   24  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
   25  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
   26  *  POSSIBILITY OF SUCH DAMAGE.
   27  */
   28 
   29 /*
   30  * AT Timer
   31  *
   32  * This code only allows control over the pitch of the speaker (pcppi(4)).
   33  */
   34 
   35 #include <sys/cdefs.h>
   36 __KERNEL_RCSID(0, "$NetBSD: attimer.c,v 1.9 2008/06/12 22:30:30 cegger Exp $");
   37 
   38 #include <sys/param.h>
   39 #include <sys/systm.h>
   40 #include <sys/kernel.h>
   41 #include <sys/device.h>
   42 
   43 #include <sys/bus.h>
   44 
   45 #include <dev/isa/isareg.h>
   46 
   47 #include <dev/ic/attimervar.h>
   48 #include <dev/ic/i8253reg.h>
   49 
   50 extern struct cfdriver attimer_cd;
   51 
   52 void
   53 attimer_attach(struct attimer_softc *sc)
   54 {
   55         sc->sc_flags |= ATT_CONFIGURED;
   56 
   57         if (!pmf_device_register(sc->sc_dev, NULL, NULL))
   58                 aprint_error_dev(sc->sc_dev, "couldn't establish power handler\n");
   59 }
   60 
   61 int
   62 attimer_detach(device_t self, int flags)
   63 {
   64         struct attimer_softc *sc = device_private(self);
   65 
   66         pmf_device_deregister(self);
   67         sc->sc_flags &= ~ATT_CONFIGURED;
   68         bus_space_unmap(sc->sc_iot, sc->sc_ioh, sc->sc_size);
   69         return 0;
   70 }
   71 
   72 /*
   73  * This is slightly artificial.  While the code looks fine, I can't help
   74  * but pray I'll get the attimer object associated to the pcppi object
   75  * that calls the routine.
   76  *
   77  * There's not much at risk here, as there's about no chance to have a
   78  * computer with more than one pcppi/attimer accessible.
   79  */
   80 
   81 device_t
   82 attimer_attach_speaker(void)
   83 {
   84         int i;
   85         struct attimer_softc *sc;
   86 
   87         for (i = 0; i < attimer_cd.cd_ndevs; i++) {
   88                 sc = device_lookup_private(&attimer_cd, i);
   89                 if (sc == NULL)
   90                         continue;
   91                 if ((sc->sc_flags & ATT_CONFIGURED) &&
   92                     !(sc->sc_flags & ATT_ATTACHED)) {
   93                         sc->sc_flags |= ATT_ATTACHED;
   94                         return sc->sc_dev;
   95                 }
   96         }
   97         return NULL;
   98 }
   99 
  100 void
  101 attimer_set_pitch(device_t dev, int pitch)
  102 {
  103         struct attimer_softc *sc = device_private(dev);
  104         int s;
  105 
  106         s = splhigh();
  107         bus_space_write_1(sc->sc_iot, sc->sc_ioh, TIMER_MODE,
  108             TIMER_SEL2 | TIMER_16BIT | TIMER_SQWAVE);
  109         bus_space_write_1(sc->sc_iot, sc->sc_ioh, TIMER_CNTR2,
  110             TIMER_DIV(pitch) % 256);
  111         bus_space_write_1(sc->sc_iot, sc->sc_ioh, TIMER_CNTR2,
  112             TIMER_DIV(pitch) / 256);
  113         splx(s);
  114 }

Cache object: 8bd1b5849773d51865789aa0824f7717


[ 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.