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