com_vrip.c revision 1.11 1 /* $NetBSD: com_vrip.c,v 1.11 2002/01/27 14:18:12 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 "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/vrcpudef.h>
55 #include <hpcmips/vr/vripif.h>
56 #include <hpcmips/vr/vripvar.h>
57 #include <hpcmips/vr/cmureg.h>
58 #include <hpcmips/vr/siureg.h>
59
60 #include <dev/ic/comvar.h>
61 #include <dev/ic/comreg.h>
62
63 #include "opt_vr41xx.h"
64 #include <hpcmips/vr/vrgiuvar.h>
65 #include <hpcmips/vr/com_vripvar.h>
66
67 #include "locators.h"
68
69 #define COMVRIPDEBUG
70 #ifdef COMVRIPDEBUG
71 int com_vrip_debug = 0;
72 #define DPRINTF(arg) if (com_vrip_debug) printf arg;
73 #define VPRINTF(arg) if (com_vrip_debug || bootverbose) printf arg;
74 #else
75 #define DPRINTF(arg)
76 #define VPRINTF(arg) if (bootverbose) printf arg;
77 #endif
78
79 struct com_vrip_softc {
80 struct com_softc sc_com;
81 int sc_pwctl;
82 };
83
84 static int com_vrip_probe(struct device *, struct cfdata *, void *);
85 static void com_vrip_attach(struct device *, struct device *, void *);
86 static int com_vrip_common_probe(bus_space_tag_t, int);
87 int find_comenableport_from_cfdata(int *);
88
89 void vrcmu_init(void);
90 void vrcmu_supply(int);
91 void vrcmu_mask(int);
92
93 struct cfattach com_vrip_ca = {
94 sizeof(struct com_vrip_softc), com_vrip_probe, com_vrip_attach
95 };
96
97 /* For serial console */
98 extern struct cfdata cfdata[];
99 int
100 find_comenableport_from_cfdata(int *port)
101 {
102 platid_mask_t mask;
103 struct cfdata *cf;
104 int id;
105
106 printf ("COM enable port: ");
107 for (cf = cfdata; cf->cf_driver; cf++) {
108 if (strcmp(cf->cf_driver->cd_name, "pwctl"))
109 continue;
110 mask = PLATID_DEREF(cf->cf_loc[HPCIOIFCF_PLATFORM]);
111 id = cf->cf_loc[HPCIOIFCF_ID];
112 if (platid_match(&platid, &mask) &&
113 id == CONFIG_HOOK_POWERCONTROL_COM0)
114 goto found;
115 }
116 *port = -1;
117 printf ("not found\n");
118 return (0);
119 found:
120 *port = cf->cf_loc[HPCIOIFCF_PORT];
121 printf ("#%d\n", *port);
122
123 return (1);
124 }
125
126 int
127 com_vrip_cndb_attach(bus_space_tag_t iot, int iobase, int rate, int frequency,
128 tcflag_t cflag, int kgdb)
129 {
130 int port;
131 /* Platform dependent setting */
132 __vrcmu_supply(CMUMASK_SIU, 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(bus_space_tag_t iot, int iobase)
148 {
149 bus_space_handle_t ioh;
150 int rv;
151
152 if (bus_space_map(iot, iobase, 1, 0, &ioh)) {
153 printf(": can't map i/o space\n");
154 return 0;
155 }
156 rv = comprobe1(iot, ioh);
157 bus_space_unmap(iot, ioh, 1);
158 return (rv);
159 }
160
161 static int
162 com_vrip_probe(struct device *parent, struct cfdata *cf, void *aux)
163 {
164 struct vrip_attach_args *va = aux;
165 bus_space_tag_t iot = va->va_iot;
166 int rv;
167
168 DPRINTF(("==com_vrip_probe"));
169
170 if (va->va_addr == VRIPIFCF_ADDR_DEFAULT ||
171 va->va_unit == VRIPIFCF_UNIT_DEFAULT) {
172 printf(": need addr and intr.\n");
173 return (0);
174 }
175
176 vrip_power(va->va_vc, va->va_unit, 1);
177
178 if (com_is_console(iot, va->va_addr, 0)) {
179 /*
180 * We have alredy probed.
181 */
182 rv = 1;
183 } else {
184 rv = com_vrip_common_probe(iot, va->va_addr);
185 }
186
187 DPRINTF((rv ? ": found COM ports\n" : ": can't probe COM device\n"));
188
189 if (rv) {
190 va->va_size = COM_NPORTS;
191 }
192 return (rv);
193 }
194
195
196 static void
197 com_vrip_attach(struct device *parent, struct device *self, void *aux)
198 {
199 struct com_vrip_softc *vsc = (void *) self;
200 struct com_softc *sc = &vsc->sc_com;
201 struct vrip_attach_args *va = aux;
202
203 bus_space_tag_t iot = va->va_iot;
204 bus_space_handle_t ioh;
205
206 vsc->sc_pwctl = sc->sc_dev.dv_cfdata->cf_loc[VRIPIFCF_PWCTL];
207
208 DPRINTF(("==com_vrip_attach"));
209
210 if (bus_space_map(iot, va->va_addr, 1, 0, &ioh)) {
211 printf(": can't map bus space\n");
212 return;
213 }
214 sc->sc_iobase = va->va_addr;
215 sc->sc_iot = iot;
216 sc->sc_ioh = ioh;
217
218 sc->enable = NULL; /* XXX: CMU control */
219 sc->disable = NULL;
220
221 sc->sc_frequency = VRCOM_FREQ;
222 /* Power management */
223 vrip_power(va->va_vc, va->va_unit, 1);
224 /* XXX, locale 'ID' must be need */
225 config_hook_call(CONFIG_HOOK_POWERCONTROL, vsc->sc_pwctl, (void*)1);
226
227 DPRINTF(("Try to attach com.\n"));
228 com_attach_subr(sc);
229
230 DPRINTF(("Establish intr"));
231 if (!vrip_intr_establish(va->va_vc, va->va_unit, 0, IPL_TTY,
232 comintr, self)) {
233 printf("%s: can't map interrupt line.\n", sc->sc_dev.dv_xname);
234 }
235
236 DPRINTF((":return()"));
237 VPRINTF(("%s: pwctl %d\n", vsc->sc_com.sc_dev.dv_xname, vsc->sc_pwctl));
238 }
239