Home | History | Annotate | Line # | Download | only in obio
rambo.c revision 1.1
      1 /*	$NetBSD: rambo.c,v 1.1 2000/08/12 22:58:58 wdk Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 2000 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Wayne Knowles
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *        This product includes software developed by the NetBSD
     21  *        Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 #include <sys/param.h>
     40 #include <sys/kernel.h>
     41 #include <sys/device.h>
     42 #include <sys/systm.h>
     43 
     44 #include <machine/cpu.h>
     45 #include <machine/mainboard.h>
     46 #include <machine/autoconf.h>
     47 #include <machine/sysconf.h>
     48 #include <machine/bus.h>
     49 
     50 #include <mipsco/obio/rambo.h>
     51 
     52 /*
     53  * Timer & Interrupt manipulation routines for the Rambo Custom ASIC
     54  */
     55 
     56 static int	rambo_match  __P((struct device *, struct cfdata *, void *));
     57 static void	rambo_attach __P((struct device *, struct device *, void *));
     58 static unsigned rambo_clkread __P((void));
     59 
     60 struct rambo_softc {
     61         struct device		dev;
     62 	struct evcnt		sc_intrcnt;
     63 	bus_space_tag_t		sc_bst;
     64 	bus_space_handle_t	sc_bsh;
     65 	u_int32_t		sc_tclast;
     66 	u_int32_t		sc_hzticks;
     67 };
     68 
     69 static struct rambo_softc *rambo;
     70 
     71 struct cfattach rambo_ca = {
     72 	sizeof(struct rambo_softc), rambo_match, rambo_attach
     73 };
     74 
     75 static int
     76 rambo_match(parent, cf, aux)
     77 	struct device *parent;
     78 	struct cfdata *cf;
     79 	void *aux;
     80 {
     81 	return 1;
     82 }
     83 
     84 static void
     85 rambo_attach(parent, self, aux)
     86 	struct device *parent, *self;
     87 	void *aux;
     88 {
     89 	struct confargs *ca = aux;
     90 	struct rambo_softc *sc = (void *)self;
     91 
     92 	sc->sc_bst = ca->ca_bustag;
     93 
     94 	if (bus_space_map(ca->ca_bustag, ca->ca_addr, 256,
     95 			  BUS_SPACE_MAP_LINEAR,
     96 			  &sc->sc_bsh) != 0) {
     97 		printf(": cannot map registers\n");
     98 		return;
     99 	}
    100 	evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
    101 			     "timer", "intr");
    102 
    103 	/* Setup RAMBO Timer to generate timer interrupts */
    104 	sc->sc_hzticks = HZ_TO_TICKS(hz);
    105 
    106 	sc->sc_tclast = sc->sc_hzticks;
    107 	bus_space_write_4(sc->sc_bst, sc->sc_bsh, RB_TCOUNT, 0);
    108 	bus_space_write_4(sc->sc_bst, sc->sc_bsh, RB_TBREAK, sc->sc_hzticks);
    109 
    110 	bus_space_write_4(sc->sc_bst, sc->sc_bsh, RB_CTLREG,
    111 			  RB_PARITY_EN | RB_BUZZOFF | RB_CLR_IOERR);
    112 
    113 	printf(": parity enabled\n");
    114 	rambo = sc;
    115 	platform.clkread = rambo_clkread;
    116 }
    117 
    118 void
    119 rambo_clkintr(cf)
    120     struct clockframe *cf;
    121 {
    122     register u_int32_t tbreak, tclast;
    123     register int       cycles = 0;
    124 
    125     rambo->sc_intrcnt.ev_count++;
    126     tbreak = bus_space_read_4(rambo->sc_bst, rambo->sc_bsh, RB_TBREAK);
    127     /* This will also clear the interrupt */
    128     while ((tclast=bus_space_read_4(rambo->sc_bst, rambo->sc_bsh,
    129 				    RB_TCOUNT)) >= tbreak) {
    130 	    hardclock(cf);
    131 	    tbreak += rambo->sc_hzticks;
    132 	    cycles++;
    133     }
    134 
    135     bus_space_write_4(rambo->sc_bst, rambo->sc_bsh, RB_TBREAK, tbreak);
    136     rambo->sc_tclast = tclast;
    137 }
    138 
    139 /*
    140  * Calculate the number of microseconds since the last clock tick
    141  */
    142 unsigned
    143 rambo_clkread()
    144 {
    145         register u_int32_t tcount;
    146 	register u_int32_t tusec;
    147 
    148 	int s = splclock();
    149 	tcount = bus_space_read_4(rambo->sc_bst, rambo->sc_bsh, RB_TCOUNT);
    150 	tusec  = TICKS_TO_USECS(tcount-rambo->sc_tclast, hz);
    151 	splx(s);
    152 
    153 	return tusec;
    154 }
    155