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