com_vrip.c revision 1.10.4.2 1 1.10.4.2 nathanw /* $NetBSD: com_vrip.c,v 1.10.4.2 2002/02/28 04:10:04 nathanw Exp $ */
2 1.10.4.2 nathanw
3 1.10.4.2 nathanw /*-
4 1.10.4.2 nathanw * Copyright (c) 1999 SASAKI Takesi. All rights reserved.
5 1.10.4.2 nathanw * Copyright (c) 1999, 2002 PocketBSD Project. All rights reserved.
6 1.10.4.2 nathanw *
7 1.10.4.2 nathanw * Redistribution and use in source and binary forms, with or without
8 1.10.4.2 nathanw * modification, are permitted provided that the following conditions
9 1.10.4.2 nathanw * are met:
10 1.10.4.2 nathanw * 1. Redistributions of source code must retain the above copyright
11 1.10.4.2 nathanw * notice, this list of conditions and the following disclaimer.
12 1.10.4.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
13 1.10.4.2 nathanw * notice, this list of conditions and the following disclaimer in the
14 1.10.4.2 nathanw * documentation and/or other materials provided with the distribution.
15 1.10.4.2 nathanw * 3. All advertising materials mentioning features or use of this software
16 1.10.4.2 nathanw * must display the following acknowledgement:
17 1.10.4.2 nathanw * This product includes software developed by the PocketBSD project
18 1.10.4.2 nathanw * and its contributors.
19 1.10.4.2 nathanw * 4. Neither the name of the project nor the names of its contributors
20 1.10.4.2 nathanw * may be used to endorse or promote products derived from this software
21 1.10.4.2 nathanw * without specific prior written permission.
22 1.10.4.2 nathanw *
23 1.10.4.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 1.10.4.2 nathanw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 1.10.4.2 nathanw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 1.10.4.2 nathanw * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 1.10.4.2 nathanw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 1.10.4.2 nathanw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 1.10.4.2 nathanw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 1.10.4.2 nathanw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 1.10.4.2 nathanw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 1.10.4.2 nathanw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 1.10.4.2 nathanw * SUCH DAMAGE.
34 1.10.4.2 nathanw *
35 1.10.4.2 nathanw */
36 1.10.4.2 nathanw
37 1.10.4.2 nathanw #include "opt_kgdb.h"
38 1.10.4.2 nathanw
39 1.10.4.2 nathanw #include <sys/param.h>
40 1.10.4.2 nathanw #include <sys/systm.h>
41 1.10.4.2 nathanw #include <sys/device.h>
42 1.10.4.2 nathanw #include <sys/reboot.h>
43 1.10.4.2 nathanw
44 1.10.4.2 nathanw #include <sys/termios.h>
45 1.10.4.2 nathanw
46 1.10.4.2 nathanw #include <machine/intr.h>
47 1.10.4.2 nathanw #include <machine/bus.h>
48 1.10.4.2 nathanw
49 1.10.4.2 nathanw #include <machine/platid.h>
50 1.10.4.2 nathanw #include <machine/platid_mask.h>
51 1.10.4.2 nathanw #include <machine/config_hook.h>
52 1.10.4.2 nathanw
53 1.10.4.2 nathanw #include <hpcmips/vr/vr.h>
54 1.10.4.2 nathanw #include <hpcmips/vr/vrcpudef.h>
55 1.10.4.2 nathanw #include <hpcmips/vr/vripif.h>
56 1.10.4.2 nathanw #include <hpcmips/vr/vripvar.h>
57 1.10.4.2 nathanw #include <hpcmips/vr/cmureg.h>
58 1.10.4.2 nathanw #include <hpcmips/vr/siureg.h>
59 1.10.4.2 nathanw
60 1.10.4.2 nathanw #include <dev/ic/comvar.h>
61 1.10.4.2 nathanw #include <dev/ic/comreg.h>
62 1.10.4.2 nathanw
63 1.10.4.2 nathanw #include "opt_vr41xx.h"
64 1.10.4.2 nathanw #include <hpcmips/vr/com_vripvar.h>
65 1.10.4.2 nathanw
66 1.10.4.2 nathanw #include "locators.h"
67 1.10.4.2 nathanw
68 1.10.4.2 nathanw #define COMVRIPDEBUG
69 1.10.4.2 nathanw #ifdef COMVRIPDEBUG
70 1.10.4.2 nathanw int com_vrip_debug = 0;
71 1.10.4.2 nathanw #define DPRINTF(arg) if (com_vrip_debug) printf arg;
72 1.10.4.2 nathanw #define VPRINTF(arg) if (com_vrip_debug || bootverbose) printf arg;
73 1.10.4.2 nathanw #else
74 1.10.4.2 nathanw #define DPRINTF(arg)
75 1.10.4.2 nathanw #define VPRINTF(arg) if (bootverbose) printf arg;
76 1.10.4.2 nathanw #endif
77 1.10.4.2 nathanw
78 1.10.4.2 nathanw struct com_vrip_softc {
79 1.10.4.2 nathanw struct com_softc sc_com;
80 1.10.4.2 nathanw int sc_pwctl;
81 1.10.4.2 nathanw };
82 1.10.4.2 nathanw
83 1.10.4.2 nathanw static int com_vrip_probe(struct device *, struct cfdata *, void *);
84 1.10.4.2 nathanw static void com_vrip_attach(struct device *, struct device *, void *);
85 1.10.4.2 nathanw static int com_vrip_common_probe(bus_space_tag_t, int);
86 1.10.4.2 nathanw
87 1.10.4.2 nathanw void vrcmu_init(void);
88 1.10.4.2 nathanw void vrcmu_supply(int);
89 1.10.4.2 nathanw void vrcmu_mask(int);
90 1.10.4.2 nathanw
91 1.10.4.2 nathanw struct cfattach com_vrip_ca = {
92 1.10.4.2 nathanw sizeof(struct com_vrip_softc), com_vrip_probe, com_vrip_attach
93 1.10.4.2 nathanw };
94 1.10.4.2 nathanw
95 1.10.4.2 nathanw int
96 1.10.4.2 nathanw com_vrip_cndb_attach(bus_space_tag_t iot, int iobase, int rate, int frequency,
97 1.10.4.2 nathanw tcflag_t cflag, int kgdb)
98 1.10.4.2 nathanw {
99 1.10.4.2 nathanw
100 1.10.4.2 nathanw if (!com_vrip_common_probe(iot, iobase))
101 1.10.4.2 nathanw return (EIO); /* I can't find appropriate error number. */
102 1.10.4.2 nathanw #ifdef KGDB
103 1.10.4.2 nathanw if (kgdb)
104 1.10.4.2 nathanw return (com_kgdb_attach(iot, iobase, rate, frequency, cflag));
105 1.10.4.2 nathanw else
106 1.10.4.2 nathanw #endif
107 1.10.4.2 nathanw return (comcnattach(iot, iobase, rate, frequency, cflag));
108 1.10.4.2 nathanw }
109 1.10.4.2 nathanw
110 1.10.4.2 nathanw static int
111 1.10.4.2 nathanw com_vrip_common_probe(bus_space_tag_t iot, int iobase)
112 1.10.4.2 nathanw {
113 1.10.4.2 nathanw bus_space_handle_t ioh;
114 1.10.4.2 nathanw int rv;
115 1.10.4.2 nathanw
116 1.10.4.2 nathanw if (bus_space_map(iot, iobase, 1, 0, &ioh)) {
117 1.10.4.2 nathanw printf(": can't map i/o space\n");
118 1.10.4.2 nathanw return 0;
119 1.10.4.2 nathanw }
120 1.10.4.2 nathanw rv = comprobe1(iot, ioh);
121 1.10.4.2 nathanw bus_space_unmap(iot, ioh, 1);
122 1.10.4.2 nathanw return (rv);
123 1.10.4.2 nathanw }
124 1.10.4.2 nathanw
125 1.10.4.2 nathanw static int
126 1.10.4.2 nathanw com_vrip_probe(struct device *parent, struct cfdata *cf, void *aux)
127 1.10.4.2 nathanw {
128 1.10.4.2 nathanw struct vrip_attach_args *va = aux;
129 1.10.4.2 nathanw bus_space_tag_t iot = va->va_iot;
130 1.10.4.2 nathanw int rv;
131 1.10.4.2 nathanw
132 1.10.4.2 nathanw DPRINTF(("==com_vrip_probe"));
133 1.10.4.2 nathanw
134 1.10.4.2 nathanw if (va->va_addr == VRIPIFCF_ADDR_DEFAULT ||
135 1.10.4.2 nathanw va->va_unit == VRIPIFCF_UNIT_DEFAULT) {
136 1.10.4.2 nathanw printf(": need addr and intr.\n");
137 1.10.4.2 nathanw return (0);
138 1.10.4.2 nathanw }
139 1.10.4.2 nathanw
140 1.10.4.2 nathanw vrip_power(va->va_vc, va->va_unit, 1);
141 1.10.4.2 nathanw
142 1.10.4.2 nathanw if (com_is_console(iot, va->va_addr, 0)) {
143 1.10.4.2 nathanw /*
144 1.10.4.2 nathanw * We have alredy probed.
145 1.10.4.2 nathanw */
146 1.10.4.2 nathanw rv = 1;
147 1.10.4.2 nathanw } else {
148 1.10.4.2 nathanw rv = com_vrip_common_probe(iot, va->va_addr);
149 1.10.4.2 nathanw }
150 1.10.4.2 nathanw
151 1.10.4.2 nathanw DPRINTF((rv ? ": found COM ports\n" : ": can't probe COM device\n"));
152 1.10.4.2 nathanw
153 1.10.4.2 nathanw if (rv) {
154 1.10.4.2 nathanw va->va_size = COM_NPORTS;
155 1.10.4.2 nathanw }
156 1.10.4.2 nathanw return (rv);
157 1.10.4.2 nathanw }
158 1.10.4.2 nathanw
159 1.10.4.2 nathanw
160 1.10.4.2 nathanw static void
161 1.10.4.2 nathanw com_vrip_attach(struct device *parent, struct device *self, void *aux)
162 1.10.4.2 nathanw {
163 1.10.4.2 nathanw struct com_vrip_softc *vsc = (void *) self;
164 1.10.4.2 nathanw struct com_softc *sc = &vsc->sc_com;
165 1.10.4.2 nathanw struct vrip_attach_args *va = aux;
166 1.10.4.2 nathanw
167 1.10.4.2 nathanw bus_space_tag_t iot = va->va_iot;
168 1.10.4.2 nathanw bus_space_handle_t ioh;
169 1.10.4.2 nathanw
170 1.10.4.2 nathanw vsc->sc_pwctl = sc->sc_dev.dv_cfdata->cf_loc[VRIPIFCF_PWCTL];
171 1.10.4.2 nathanw
172 1.10.4.2 nathanw DPRINTF(("==com_vrip_attach"));
173 1.10.4.2 nathanw
174 1.10.4.2 nathanw if (bus_space_map(iot, va->va_addr, 1, 0, &ioh)) {
175 1.10.4.2 nathanw printf(": can't map bus space\n");
176 1.10.4.2 nathanw return;
177 1.10.4.2 nathanw }
178 1.10.4.2 nathanw sc->sc_iobase = va->va_addr;
179 1.10.4.2 nathanw sc->sc_iot = iot;
180 1.10.4.2 nathanw sc->sc_ioh = ioh;
181 1.10.4.2 nathanw
182 1.10.4.2 nathanw sc->enable = NULL; /* XXX: CMU control */
183 1.10.4.2 nathanw sc->disable = NULL;
184 1.10.4.2 nathanw
185 1.10.4.2 nathanw sc->sc_frequency = VRCOM_FREQ;
186 1.10.4.2 nathanw /* Power management */
187 1.10.4.2 nathanw vrip_power(va->va_vc, va->va_unit, 1);
188 1.10.4.2 nathanw /* XXX, locale 'ID' must be need */
189 1.10.4.2 nathanw config_hook_call(CONFIG_HOOK_POWERCONTROL, vsc->sc_pwctl, (void*)1);
190 1.10.4.2 nathanw
191 1.10.4.2 nathanw DPRINTF(("Try to attach com.\n"));
192 1.10.4.2 nathanw com_attach_subr(sc);
193 1.10.4.2 nathanw
194 1.10.4.2 nathanw DPRINTF(("Establish intr"));
195 1.10.4.2 nathanw if (!vrip_intr_establish(va->va_vc, va->va_unit, 0, IPL_TTY,
196 1.10.4.2 nathanw comintr, self)) {
197 1.10.4.2 nathanw printf("%s: can't map interrupt line.\n", sc->sc_dev.dv_xname);
198 1.10.4.2 nathanw }
199 1.10.4.2 nathanw
200 1.10.4.2 nathanw DPRINTF((":return()"));
201 1.10.4.2 nathanw VPRINTF(("%s: pwctl %d\n", vsc->sc_com.sc_dev.dv_xname, vsc->sc_pwctl));
202 1.10.4.2 nathanw }
203