vrdsu.c revision 1.4.10.1 1 /* $NetBSD: vrdsu.c,v 1.4.10.1 2002/12/12 22:54:18 he 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 #include <uvm/uvm_param.h>
33
34 #include <machine/bus.h>
35
36 #include <hpcmips/vr/vripif.h>
37 #include <hpcmips/vr/dsureg.h>
38 #include <hpcmips/vr/vrdsuvar.h>
39
40 struct vrdsu_softc {
41 struct device sc_dev;
42 bus_space_tag_t sc_iot;
43 bus_space_handle_t sc_ioh;
44 };
45
46 static int vrdsumatch(struct device *, struct cfdata *, void *);
47 static void vrdsuattach(struct device *, struct device *, void *);
48
49 static void vrdsu_write(struct vrdsu_softc *, int, unsigned short);
50 static unsigned short vrdsu_read(struct vrdsu_softc *, int);
51
52 struct cfattach vrdsu_ca = {
53 sizeof(struct vrdsu_softc), vrdsumatch, vrdsuattach
54 };
55
56 struct vrdsu_softc *the_dsu_sc = NULL;
57
58 static inline void
59 vrdsu_write(struct vrdsu_softc *sc, int port, unsigned short val)
60 {
61
62 bus_space_write_2(sc->sc_iot, sc->sc_ioh, port, val);
63 }
64
65 static inline unsigned short
66 vrdsu_read(struct vrdsu_softc *sc, int port)
67 {
68
69 return (bus_space_read_2(sc->sc_iot, sc->sc_ioh, port));
70 }
71
72 static int
73 vrdsumatch(struct device *parent, struct cfdata *cf, void *aux)
74 {
75
76 return (1);
77 }
78
79 static void
80 vrdsuattach(struct device *parent, struct device *self, void *aux)
81 {
82 struct vrdsu_softc *sc = (struct vrdsu_softc *)self;
83 struct vrip_attach_args *va = aux;
84
85 sc->sc_iot = va->va_iot;
86 if (bus_space_map(va->va_iot, va->va_addr, va->va_size,
87 0, &sc->sc_ioh)) {
88 printf(": can't map bus space\n");
89 return;
90 }
91 printf("\n");
92 the_dsu_sc = sc;
93 }
94
95 void
96 vrdsu_reset()
97 {
98
99 if (the_dsu_sc) {
100 splhigh();
101 vrdsu_write(the_dsu_sc, DSUSET_REG_W, 1); /* 1 sec */
102 vrdsu_write(the_dsu_sc, DSUCNT_REG_W, DSUCNT_DSWEN);
103 /*
104 * wipe out all physical memory for clean WinCE boot.
105 */
106 memset((void *)MIPS_PHYS_TO_KSEG1(0), 0, ptoa(physmem) - 0);
107 while (1);
108 } else {
109 printf("%s(%d): There is no DSU.", __FILE__, __LINE__);
110 }
111 }
112