Home | History | Annotate | Line # | Download | only in vr
vrdsu.c revision 1.3.4.3
      1  1.3.4.3  nathanw /*	$NetBSD: vrdsu.c,v 1.3.4.3 2002/10/18 02:37:19 nathanw Exp $	*/
      2  1.3.4.2  nathanw 
      3  1.3.4.2  nathanw /*
      4  1.3.4.2  nathanw  * Copyright (c) 1999 Shin Takemura All rights reserved.
      5  1.3.4.2  nathanw  * Copyright (c) 1999 PocketBSD Project. All rights reserved.
      6  1.3.4.2  nathanw  *
      7  1.3.4.2  nathanw  * Redistribution and use in source and binary forms, with or without
      8  1.3.4.2  nathanw  * modification, are permitted provided that the following conditions
      9  1.3.4.2  nathanw  * are met:
     10  1.3.4.2  nathanw  * 1. Redistributions of source code must retain the above copyright
     11  1.3.4.2  nathanw  *    notice, this list of conditions and the following disclaimer.
     12  1.3.4.2  nathanw  * 2. Redistributions in binary form must reproduce the above copyright
     13  1.3.4.2  nathanw  *    notice, this list of conditions and the following disclaimer in the
     14  1.3.4.2  nathanw  *    documentation and/or other materials provided with the distribution.
     15  1.3.4.2  nathanw  *
     16  1.3.4.2  nathanw  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
     17  1.3.4.2  nathanw  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     18  1.3.4.2  nathanw  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     19  1.3.4.2  nathanw  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
     20  1.3.4.2  nathanw  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     21  1.3.4.2  nathanw  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     22  1.3.4.2  nathanw  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     23  1.3.4.2  nathanw  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     24  1.3.4.2  nathanw  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  1.3.4.2  nathanw  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  1.3.4.2  nathanw  * SUCH DAMAGE.
     27  1.3.4.2  nathanw  */
     28  1.3.4.2  nathanw 
     29  1.3.4.2  nathanw #include <sys/param.h>
     30  1.3.4.2  nathanw #include <sys/systm.h>
     31  1.3.4.2  nathanw #include <sys/device.h>
     32  1.3.4.2  nathanw 
     33  1.3.4.2  nathanw #include <machine/bus.h>
     34  1.3.4.2  nathanw 
     35  1.3.4.2  nathanw #include <hpcmips/vr/vripif.h>
     36  1.3.4.2  nathanw #include <hpcmips/vr/dsureg.h>
     37  1.3.4.2  nathanw #include <hpcmips/vr/vrdsuvar.h>
     38  1.3.4.2  nathanw 
     39  1.3.4.2  nathanw struct vrdsu_softc {
     40  1.3.4.2  nathanw 	struct device sc_dev;
     41  1.3.4.2  nathanw 	bus_space_tag_t sc_iot;
     42  1.3.4.2  nathanw 	bus_space_handle_t sc_ioh;
     43  1.3.4.2  nathanw };
     44  1.3.4.2  nathanw 
     45  1.3.4.2  nathanw static int vrdsumatch(struct device *, struct cfdata *, void *);
     46  1.3.4.2  nathanw static void vrdsuattach(struct device *, struct device *, void *);
     47  1.3.4.2  nathanw 
     48  1.3.4.2  nathanw static void vrdsu_write(struct vrdsu_softc *, int, unsigned short);
     49  1.3.4.2  nathanw static unsigned short vrdsu_read(struct vrdsu_softc *, int);
     50  1.3.4.2  nathanw 
     51  1.3.4.3  nathanw CFATTACH_DECL(vrdsu, sizeof(struct vrdsu_softc),
     52  1.3.4.3  nathanw     vrdsumatch, vrdsuattach, NULL, NULL);
     53  1.3.4.2  nathanw 
     54  1.3.4.2  nathanw struct vrdsu_softc *the_dsu_sc = NULL;
     55  1.3.4.2  nathanw 
     56  1.3.4.2  nathanw static inline void
     57  1.3.4.2  nathanw vrdsu_write(struct vrdsu_softc *sc, int port, unsigned short val)
     58  1.3.4.2  nathanw {
     59  1.3.4.2  nathanw 
     60  1.3.4.2  nathanw 	bus_space_write_2(sc->sc_iot, sc->sc_ioh, port, val);
     61  1.3.4.2  nathanw }
     62  1.3.4.2  nathanw 
     63  1.3.4.2  nathanw static inline unsigned short
     64  1.3.4.2  nathanw vrdsu_read(struct vrdsu_softc *sc, int port)
     65  1.3.4.2  nathanw {
     66  1.3.4.2  nathanw 
     67  1.3.4.2  nathanw 	return (bus_space_read_2(sc->sc_iot, sc->sc_ioh, port));
     68  1.3.4.2  nathanw }
     69  1.3.4.2  nathanw 
     70  1.3.4.2  nathanw static int
     71  1.3.4.2  nathanw vrdsumatch(struct device *parent, struct cfdata *cf, void *aux)
     72  1.3.4.2  nathanw {
     73  1.3.4.2  nathanw 
     74  1.3.4.2  nathanw 	return (1);
     75  1.3.4.2  nathanw }
     76  1.3.4.2  nathanw 
     77  1.3.4.2  nathanw static void
     78  1.3.4.2  nathanw vrdsuattach(struct device *parent, struct device *self, void *aux)
     79  1.3.4.2  nathanw {
     80  1.3.4.2  nathanw 	struct vrdsu_softc *sc = (struct vrdsu_softc *)self;
     81  1.3.4.2  nathanw 	struct vrip_attach_args *va = aux;
     82  1.3.4.2  nathanw 
     83  1.3.4.2  nathanw 	sc->sc_iot = va->va_iot;
     84  1.3.4.2  nathanw 	if (bus_space_map(va->va_iot, va->va_addr, va->va_size,
     85  1.3.4.2  nathanw 	    0, &sc->sc_ioh)) {
     86  1.3.4.2  nathanw 		printf(": can't map bus space\n");
     87  1.3.4.2  nathanw 		return;
     88  1.3.4.2  nathanw 	}
     89  1.3.4.2  nathanw 	printf("\n");
     90  1.3.4.2  nathanw 	the_dsu_sc = sc;
     91  1.3.4.2  nathanw }
     92  1.3.4.2  nathanw 
     93  1.3.4.2  nathanw void
     94  1.3.4.2  nathanw vrdsu_reset()
     95  1.3.4.2  nathanw {
     96  1.3.4.2  nathanw 
     97  1.3.4.2  nathanw 	if (the_dsu_sc) {
     98  1.3.4.2  nathanw 		splhigh();
     99  1.3.4.2  nathanw 		vrdsu_write(the_dsu_sc, DSUSET_REG_W, 1); /* 1 sec */
    100  1.3.4.2  nathanw 		vrdsu_write(the_dsu_sc, DSUCNT_REG_W, DSUCNT_DSWEN);
    101  1.3.4.2  nathanw 		while (1);
    102  1.3.4.2  nathanw 	} else {
    103  1.3.4.2  nathanw 		printf("%s(%d): There is no DSU.", __FILE__, __LINE__);
    104  1.3.4.2  nathanw 	}
    105  1.3.4.2  nathanw }
    106