Home | History | Annotate | Line # | Download | only in ic
attimer.c revision 1.1.6.2
      1  1.1.6.2  kent /*	$NetBSD: attimer.c,v 1.1.6.2 2005/04/29 11:28:49 kent Exp $	*/
      2  1.1.6.2  kent 
      3  1.1.6.2  kent /*
      4  1.1.6.2  kent  *  Copyright (c) 2005 The NetBSD Foundation.
      5  1.1.6.2  kent  *  All rights reserved.
      6  1.1.6.2  kent  *
      7  1.1.6.2  kent  *  This code is derived from software contributed to the NetBSD Foundation
      8  1.1.6.2  kent  *   by Quentin Garnier.
      9  1.1.6.2  kent  *
     10  1.1.6.2  kent  *  Redistribution and use in source and binary forms, with or without
     11  1.1.6.2  kent  *  modification, are permitted provided that the following conditions
     12  1.1.6.2  kent  *  are met:
     13  1.1.6.2  kent  *  1. Redistributions of source code must retain the above copyright
     14  1.1.6.2  kent  *     notice, this list of conditions and the following disclaimer.
     15  1.1.6.2  kent  *  2. Redistributions in binary form must reproduce the above copyright
     16  1.1.6.2  kent  *     notice, this list of conditions and the following disclaimer in the
     17  1.1.6.2  kent  *     documentation and/or other materials provided with the distribution.
     18  1.1.6.2  kent  *  3. All advertising materials mentioning features or use of this software
     19  1.1.6.2  kent  *     must display the following acknowledgement:
     20  1.1.6.2  kent  *         This product includes software developed by the NetBSD
     21  1.1.6.2  kent  *         Foundation, Inc. and its contributors.
     22  1.1.6.2  kent  *  4. Neither the name of The NetBSD Foundation nor the names of its
     23  1.1.6.2  kent  *     contributors may be used to endorse or promote products derived
     24  1.1.6.2  kent  *     from this software without specific prior written permission.
     25  1.1.6.2  kent  *
     26  1.1.6.2  kent  *  THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  1.1.6.2  kent  *  ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  1.1.6.2  kent  *  TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  1.1.6.2  kent  *  PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  1.1.6.2  kent  *  BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  1.1.6.2  kent  *  CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  1.1.6.2  kent  *  SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  1.1.6.2  kent  *  INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  1.1.6.2  kent  *  CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  1.1.6.2  kent  *  ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  1.1.6.2  kent  *  POSSIBILITY OF SUCH DAMAGE.
     37  1.1.6.2  kent  */
     38  1.1.6.2  kent 
     39  1.1.6.2  kent /*
     40  1.1.6.2  kent  * AT Timer
     41  1.1.6.2  kent  *
     42  1.1.6.2  kent  * This code only allows control over the pitch of the speaker (pcppi(4)).
     43  1.1.6.2  kent  */
     44  1.1.6.2  kent 
     45  1.1.6.2  kent #include <sys/cdefs.h>
     46  1.1.6.2  kent __KERNEL_RCSID(0, "$NetBSD: attimer.c,v 1.1.6.2 2005/04/29 11:28:49 kent Exp $");
     47  1.1.6.2  kent 
     48  1.1.6.2  kent #include <sys/param.h>
     49  1.1.6.2  kent #include <sys/systm.h>
     50  1.1.6.2  kent #include <sys/kernel.h>
     51  1.1.6.2  kent #include <sys/device.h>
     52  1.1.6.2  kent 
     53  1.1.6.2  kent #include <machine/bus.h>
     54  1.1.6.2  kent 
     55  1.1.6.2  kent #include <dev/isa/isareg.h>
     56  1.1.6.2  kent 
     57  1.1.6.2  kent #include <dev/ic/attimervar.h>
     58  1.1.6.2  kent #include <dev/ic/i8253reg.h>
     59  1.1.6.2  kent 
     60  1.1.6.2  kent extern struct cfdriver attimer_cd;
     61  1.1.6.2  kent 
     62  1.1.6.2  kent void
     63  1.1.6.2  kent attimer_attach(struct attimer_softc *sc)
     64  1.1.6.2  kent {
     65  1.1.6.2  kent 	sc->sc_flags |= ATT_CONFIGURED;
     66  1.1.6.2  kent }
     67  1.1.6.2  kent 
     68  1.1.6.2  kent /*
     69  1.1.6.2  kent  * This is slightly artificial.  While the code looks fine, I can't help
     70  1.1.6.2  kent  * but pray I'll get the attimer object associated to the pcppi object
     71  1.1.6.2  kent  * that calls the routine.
     72  1.1.6.2  kent  *
     73  1.1.6.2  kent  * There's not much at risk here, as there's about no chance to have a
     74  1.1.6.2  kent  * computer with more than one pcppi/attimer accessible.
     75  1.1.6.2  kent  */
     76  1.1.6.2  kent 
     77  1.1.6.2  kent struct attimer_softc *
     78  1.1.6.2  kent attimer_attach_speaker()
     79  1.1.6.2  kent {
     80  1.1.6.2  kent 	int i;
     81  1.1.6.2  kent 	struct attimer_softc *sc;
     82  1.1.6.2  kent 
     83  1.1.6.2  kent 	for (i = 0; i < attimer_cd.cd_ndevs; i++)
     84  1.1.6.2  kent 		if (attimer_cd.cd_devs[i] != NULL) {
     85  1.1.6.2  kent 			sc = (struct attimer_softc *)attimer_cd.cd_devs[i];
     86  1.1.6.2  kent 			if ((sc->sc_flags & ATT_CONFIGURED) &&
     87  1.1.6.2  kent 			    !(sc->sc_flags & ATT_ATTACHED)) {
     88  1.1.6.2  kent 				sc->sc_flags |= ATT_ATTACHED;
     89  1.1.6.2  kent 				return sc;
     90  1.1.6.2  kent 			}
     91  1.1.6.2  kent 		}
     92  1.1.6.2  kent 	return NULL;
     93  1.1.6.2  kent }
     94  1.1.6.2  kent 
     95  1.1.6.2  kent void
     96  1.1.6.2  kent attimer_set_pitch(struct attimer_softc *sc, int pitch)
     97  1.1.6.2  kent {
     98  1.1.6.2  kent 	int s;
     99  1.1.6.2  kent 	s = splhigh();
    100  1.1.6.2  kent 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, TIMER_MODE,
    101  1.1.6.2  kent 	    TIMER_SEL2 | TIMER_16BIT | TIMER_SQWAVE);
    102  1.1.6.2  kent 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, TIMER_CNTR2,
    103  1.1.6.2  kent 	    TIMER_DIV(pitch) % 256);
    104  1.1.6.2  kent 	bus_space_write_1(sc->sc_iot, sc->sc_ioh, TIMER_CNTR2,
    105  1.1.6.2  kent 	    TIMER_DIV(pitch) / 256);
    106  1.1.6.2  kent 	splx(s);
    107  1.1.6.2  kent }
    108