com_vrip.c revision 1.8 1 /* $NetBSD: com_vrip.c,v 1.8 2001/05/30 15:24:30 lukem Exp $ */
2
3 /*-
4 * Copyright (c) 1999 SASAKI Takesi. 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 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the PocketBSD project
18 * and its contributors.
19 * 4. Neither the name of the project nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 *
35 */
36
37 #include "opt_kgdb.h"
38
39 #include <sys/param.h>
40 #include <sys/systm.h>
41 #include <sys/device.h>
42 #include <sys/reboot.h>
43
44 #include <sys/termios.h>
45
46 #include <machine/intr.h>
47 #include <machine/bus.h>
48
49 #include <machine/platid.h>
50 #include <machine/platid_mask.h>
51 #include <machine/config_hook.h>
52
53 #include <hpcmips/vr/vr.h>
54 #include <hpcmips/vr/vripvar.h>
55 #include <hpcmips/vr/cmureg.h>
56 #include <hpcmips/vr/siureg.h>
57
58 #include <dev/ic/comvar.h>
59 #include <dev/ic/comreg.h>
60
61 #include "opt_vr41xx.h"
62 #include <hpcmips/vr/vrgiuvar.h>
63 #include <hpcmips/vr/com_vripvar.h>
64
65 #include "locators.h"
66
67 #define COMVRIPDEBUG
68 #ifdef COMVRIPDEBUG
69 int com_vrip_debug = 0;
70 #define DPRINTF(arg) if (com_vrip_debug) printf arg;
71 #define VPRINTF(arg) if (com_vrip_debug || bootverbose) printf arg;
72 #else
73 #define DPRINTF(arg)
74 #define VPRINTF(arg) if (bootverbose) printf arg;
75 #endif
76
77 struct com_vrip_softc {
78 struct com_softc sc_com;
79 int sc_pwctl;
80 };
81
82 static int com_vrip_probe __P((struct device *, struct cfdata *, void *));
83 static void com_vrip_attach __P((struct device *, struct device *, void *));
84 static int com_vrip_common_probe __P((bus_space_tag_t iot, int iobase));
85 int find_comenableport_from_cfdata __P((int *));
86
87 void vrcmu_init __P((void));
88 void vrcmu_supply __P((int));
89 void vrcmu_mask __P((int));
90
91 struct cfattach com_vrip_ca = {
92 sizeof(struct com_vrip_softc), com_vrip_probe, com_vrip_attach
93 };
94
95 /* For serial console */
96 extern struct cfdata cfdata[];
97 int
98 find_comenableport_from_cfdata(int *port)
99 {
100 platid_mask_t mask;
101 struct cfdata *cf;
102 int id;
103
104 printf ("COM enable port: ");
105 for (cf = cfdata; cf->cf_driver; cf++) {
106 if (strcmp(cf->cf_driver->cd_name, "pwctl"))
107 continue;
108 mask = PLATID_DEREF(cf->cf_loc[HPCIOIFCF_PLATFORM]);
109 id = cf->cf_loc[HPCIOIFCF_ID];
110 if (platid_match(&platid, &mask) &&
111 id == CONFIG_HOOK_POWERCONTROL_COM0)
112 goto found;
113 }
114 *port = -1;
115 printf ("not found\n");
116 return (0);
117 found:
118 *port = cf->cf_loc[HPCIOIFCF_PORT];
119 printf ("#%d\n", *port);
120
121 return (1);
122 }
123
124 int
125 com_vrip_cndb_attach(iot, iobase, rate, frequency, cflag, kgdb)
126 bus_space_tag_t iot;
127 int iobase;
128 int rate, frequency;
129 tcflag_t cflag;
130 int kgdb;
131 {
132 int port;
133 /* Platform dependent setting */
134 __vrcmu_supply(CMUMSKSSIU | CMUMSKSIU, 1);
135 if (find_comenableport_from_cfdata(&port))
136 __vrgiu_out(port, 1);
137
138 if (!com_vrip_common_probe(iot, iobase))
139 return (EIO); /* I can't find appropriate error number. */
140 #ifdef KGDB
141 if (kgdb)
142 return (com_kgdb_attach(iot, iobase, rate, frequency, cflag));
143 else
144 #endif
145 return (comcnattach(iot, iobase, rate, frequency, cflag));
146 }
147
148 static int
149 com_vrip_common_probe(iot, iobase)
150 bus_space_tag_t iot;
151 int iobase;
152 {
153 bus_space_handle_t ioh;
154 int rv;
155
156 if (bus_space_map(iot, iobase, 1, 0, &ioh)) {
157 printf(": can't map i/o space\n");
158 return 0;
159 }
160 rv = comprobe1(iot, ioh);
161 bus_space_unmap(iot, ioh, 1);
162 return (rv);
163 }
164
165 static int
166 com_vrip_probe(parent, cf, aux)
167 struct device *parent;
168 struct cfdata *cf;
169 void *aux;
170 {
171 struct vrip_attach_args *va = aux;
172 bus_space_tag_t iot = va->va_iot;
173 int rv;
174
175 DPRINTF(("==com_vrip_probe"));
176
177 if (va->va_addr == VRIPCF_ADDR_DEFAULT ||
178 va->va_intr == VRIPCF_INTR_DEFAULT) {
179 printf(": need addr and intr.\n");
180 return (0);
181 }
182
183 if (!va->va_cf || !va->va_cf->cf_clock)
184 return 0; /* not yet CMU attached. Try again later. */
185
186 va->va_cf->cf_clock(va->va_cc, CMUMSKSSIU | CMUMSKSIU, 1);
187
188 if (com_is_console(iot, va->va_addr, 0)) {
189 /*
190 * We have alredy probed.
191 */
192 rv = 1;
193 } else {
194 rv = com_vrip_common_probe(iot, va->va_addr);
195 }
196
197 DPRINTF((rv ? ": found COM ports\n" : ": can't probe COM device\n"));
198
199 if (rv) {
200 va->va_size = COM_NPORTS;
201 }
202 return (rv);
203 }
204
205
206 static void
207 com_vrip_attach(parent, self, aux)
208 struct device *parent, *self;
209 void *aux;
210 {
211 struct com_vrip_softc *vsc = (void *) self;
212 struct com_softc *sc = &vsc->sc_com;
213 struct vrip_attach_args *va = aux;
214
215 bus_space_tag_t iot = va->va_iot;
216 bus_space_handle_t ioh;
217
218 vsc->sc_pwctl = sc->sc_dev.dv_cfdata->cf_loc[VRIPCF_PWCTL];
219
220 DPRINTF(("==com_vrip_attach"));
221
222 if (bus_space_map(iot, va->va_addr, 1, 0, &ioh)) {
223 printf(": can't map bus space\n");
224 return;
225 }
226 sc->sc_iobase = va->va_addr;
227 sc->sc_iot = iot;
228 sc->sc_ioh = ioh;
229
230 sc->enable = NULL; /* XXX: CMU control */
231 sc->disable = NULL;
232
233 sc->sc_frequency = VRCOM_FREQ;
234 /* Power management */
235 va->va_cf->cf_clock(va->va_cc, CMUMSKSSIU | CMUMSKSIU, 1);
236 /*
237 va->va_gf->gf_portwrite(va->va_gc, GIUPORT_COM, 1);
238 */
239 /* XXX, locale 'ID' must be need */
240 config_hook_call(CONFIG_HOOK_POWERCONTROL, vsc->sc_pwctl, (void*)1);
241
242 DPRINTF(("Try to attach com.\n"));
243 com_attach_subr(sc);
244
245 DPRINTF(("Establish intr"));
246 vrip_intr_establish(va->va_vc, va->va_intr, IPL_TTY, comintr, self);
247
248 DPRINTF((":return()"));
249 VPRINTF(("%s: pwctl %d\n", vsc->sc_com.sc_dev.dv_xname, vsc->sc_pwctl));
250 }
251