com_vrip.c revision 1.7 1 /* $NetBSD: com_vrip.c,v 1.7 2001/04/30 11:42:19 takemura 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 <sys/param.h>
38 #include <sys/systm.h>
39 #include <sys/device.h>
40 #include <sys/reboot.h>
41
42 #include <sys/termios.h>
43
44 #include <machine/intr.h>
45 #include <machine/bus.h>
46
47 #include <machine/platid.h>
48 #include <machine/platid_mask.h>
49 #include <machine/config_hook.h>
50
51 #include <hpcmips/vr/vr.h>
52 #include <hpcmips/vr/vripvar.h>
53 #include <hpcmips/vr/cmureg.h>
54 #include <hpcmips/vr/siureg.h>
55
56 #include <dev/ic/comvar.h>
57 #include <dev/ic/comreg.h>
58
59 #include "opt_vr41xx.h"
60 #include <hpcmips/vr/vrgiuvar.h>
61 #include <hpcmips/vr/com_vripvar.h>
62
63 #include "locators.h"
64
65 #define COMVRIPDEBUG
66 #ifdef COMVRIPDEBUG
67 int com_vrip_debug = 0;
68 #define DPRINTF(arg) if (com_vrip_debug) printf arg;
69 #define VPRINTF(arg) if (com_vrip_debug || bootverbose) printf arg;
70 #else
71 #define DPRINTF(arg)
72 #define VPRINTF(arg) if (bootverbose) printf arg;
73 #endif
74
75 struct com_vrip_softc {
76 struct com_softc sc_com;
77 int sc_pwctl;
78 };
79
80 static int com_vrip_probe __P((struct device *, struct cfdata *, void *));
81 static void com_vrip_attach __P((struct device *, struct device *, void *));
82 static int com_vrip_common_probe __P((bus_space_tag_t iot, int iobase));
83 int find_comenableport_from_cfdata __P((int *));
84
85 void vrcmu_init __P((void));
86 void vrcmu_supply __P((int));
87 void vrcmu_mask __P((int));
88
89 struct cfattach com_vrip_ca = {
90 sizeof(struct com_vrip_softc), com_vrip_probe, com_vrip_attach
91 };
92
93 /* For serial console */
94 extern struct cfdata cfdata[];
95 int
96 find_comenableport_from_cfdata(int *port)
97 {
98 platid_mask_t mask;
99 struct cfdata *cf;
100 int id;
101
102 printf ("COM enable port: ");
103 for (cf = cfdata; cf->cf_driver; cf++) {
104 if (strcmp(cf->cf_driver->cd_name, "pwctl"))
105 continue;
106 mask = PLATID_DEREF(cf->cf_loc[HPCIOIFCF_PLATFORM]);
107 id = cf->cf_loc[HPCIOIFCF_ID];
108 if (platid_match(&platid, &mask) &&
109 id == CONFIG_HOOK_POWERCONTROL_COM0)
110 goto found;
111 }
112 *port = -1;
113 printf ("not found\n");
114 return (0);
115 found:
116 *port = cf->cf_loc[HPCIOIFCF_PORT];
117 printf ("#%d\n", *port);
118
119 return (1);
120 }
121
122 int
123 com_vrip_cndb_attach(iot, iobase, rate, frequency, cflag, kgdb)
124 bus_space_tag_t iot;
125 int iobase;
126 int rate, frequency;
127 tcflag_t cflag;
128 int kgdb;
129 {
130 int port;
131 /* Platform dependent setting */
132 __vrcmu_supply(CMUMSKSSIU | CMUMSKSIU, 1);
133 if (find_comenableport_from_cfdata(&port))
134 __vrgiu_out(port, 1);
135
136 if (!com_vrip_common_probe(iot, iobase))
137 return (EIO); /* I can't find appropriate error number. */
138 #ifdef KGDB
139 if (kgdb)
140 return (com_kgdb_attach(iot, iobase, rate, frequency, cflag));
141 else
142 #endif
143 return (comcnattach(iot, iobase, rate, frequency, cflag));
144 }
145
146 static int
147 com_vrip_common_probe(iot, iobase)
148 bus_space_tag_t iot;
149 int iobase;
150 {
151 bus_space_handle_t ioh;
152 int rv;
153
154 if (bus_space_map(iot, iobase, 1, 0, &ioh)) {
155 printf(": can't map i/o space\n");
156 return 0;
157 }
158 rv = comprobe1(iot, ioh);
159 bus_space_unmap(iot, ioh, 1);
160 return (rv);
161 }
162
163 static int
164 com_vrip_probe(parent, cf, aux)
165 struct device *parent;
166 struct cfdata *cf;
167 void *aux;
168 {
169 struct vrip_attach_args *va = aux;
170 bus_space_tag_t iot = va->va_iot;
171 int rv;
172
173 DPRINTF(("==com_vrip_probe"));
174
175 if (va->va_addr == VRIPCF_ADDR_DEFAULT ||
176 va->va_intr == VRIPCF_INTR_DEFAULT) {
177 printf(": need addr and intr.\n");
178 return (0);
179 }
180
181 if (!va->va_cf || !va->va_cf->cf_clock)
182 return 0; /* not yet CMU attached. Try again later. */
183
184 va->va_cf->cf_clock(va->va_cc, CMUMSKSSIU | CMUMSKSIU, 1);
185
186 if (com_is_console(iot, va->va_addr, 0)) {
187 /*
188 * We have alredy probed.
189 */
190 rv = 1;
191 } else {
192 rv = com_vrip_common_probe(iot, va->va_addr);
193 }
194
195 DPRINTF((rv ? ": found COM ports\n" : ": can't probe COM device\n"));
196
197 if (rv) {
198 va->va_size = COM_NPORTS;
199 }
200 return (rv);
201 }
202
203
204 static void
205 com_vrip_attach(parent, self, aux)
206 struct device *parent, *self;
207 void *aux;
208 {
209 struct com_vrip_softc *vsc = (void *) self;
210 struct com_softc *sc = &vsc->sc_com;
211 struct vrip_attach_args *va = aux;
212
213 bus_space_tag_t iot = va->va_iot;
214 bus_space_handle_t ioh;
215
216 vsc->sc_pwctl = sc->sc_dev.dv_cfdata->cf_loc[VRIPCF_PWCTL];
217
218 DPRINTF(("==com_vrip_attach"));
219
220 if (bus_space_map(iot, va->va_addr, 1, 0, &ioh)) {
221 printf(": can't map bus space\n");
222 return;
223 }
224 sc->sc_iobase = va->va_addr;
225 sc->sc_iot = iot;
226 sc->sc_ioh = ioh;
227
228 sc->enable = NULL; /* XXX: CMU control */
229 sc->disable = NULL;
230
231 sc->sc_frequency = VRCOM_FREQ;
232 /* Power management */
233 va->va_cf->cf_clock(va->va_cc, CMUMSKSSIU | CMUMSKSIU, 1);
234 /*
235 va->va_gf->gf_portwrite(va->va_gc, GIUPORT_COM, 1);
236 */
237 /* XXX, locale 'ID' must be need */
238 config_hook_call(CONFIG_HOOK_POWERCONTROL, vsc->sc_pwctl, (void*)1);
239
240 DPRINTF(("Try to attach com.\n"));
241 com_attach_subr(sc);
242
243 DPRINTF(("Establish intr"));
244 vrip_intr_establish(va->va_vc, va->va_intr, IPL_TTY, comintr, self);
245
246 DPRINTF((":return()"));
247 VPRINTF(("%s: pwctl %d\n", vsc->sc_com.sc_dev.dv_xname, vsc->sc_pwctl));
248 }
249