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