zs.c revision 1.84.4.3 1 1.84.4.3 nathanw /* $NetBSD: zs.c,v 1.84.4.3 2002/08/27 23:45:31 nathanw Exp $ */
2 1.84.4.2 nathanw
3 1.84.4.2 nathanw /*-
4 1.84.4.2 nathanw * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 1.84.4.2 nathanw * All rights reserved.
6 1.84.4.2 nathanw *
7 1.84.4.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.84.4.2 nathanw * by Gordon W. Ross.
9 1.84.4.2 nathanw *
10 1.84.4.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.84.4.2 nathanw * modification, are permitted provided that the following conditions
12 1.84.4.2 nathanw * are met:
13 1.84.4.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.84.4.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.84.4.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.84.4.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.84.4.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.84.4.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.84.4.2 nathanw * must display the following acknowledgement:
20 1.84.4.2 nathanw * This product includes software developed by the NetBSD
21 1.84.4.2 nathanw * Foundation, Inc. and its contributors.
22 1.84.4.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.84.4.2 nathanw * contributors may be used to endorse or promote products derived
24 1.84.4.2 nathanw * from this software without specific prior written permission.
25 1.84.4.2 nathanw *
26 1.84.4.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.84.4.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.84.4.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.84.4.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.84.4.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.84.4.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.84.4.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.84.4.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.84.4.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.84.4.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.84.4.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.84.4.2 nathanw */
38 1.84.4.2 nathanw
39 1.84.4.2 nathanw /*
40 1.84.4.2 nathanw * Zilog Z8530 Dual UART driver (machine-dependent part)
41 1.84.4.2 nathanw *
42 1.84.4.2 nathanw * Runs two serial lines per chip using slave drivers.
43 1.84.4.2 nathanw * Plain tty/async lines use the zs_async slave.
44 1.84.4.2 nathanw * Sun keyboard/mouse uses the zs_kbd/zs_ms slaves.
45 1.84.4.2 nathanw */
46 1.84.4.2 nathanw
47 1.84.4.2 nathanw #include "opt_ddb.h"
48 1.84.4.2 nathanw #include "opt_kgdb.h"
49 1.84.4.3 nathanw #include "opt_sparc_arch.h"
50 1.84.4.2 nathanw
51 1.84.4.2 nathanw #include <sys/param.h>
52 1.84.4.2 nathanw #include <sys/systm.h>
53 1.84.4.2 nathanw #include <sys/conf.h>
54 1.84.4.2 nathanw #include <sys/device.h>
55 1.84.4.2 nathanw #include <sys/file.h>
56 1.84.4.2 nathanw #include <sys/ioctl.h>
57 1.84.4.2 nathanw #include <sys/kernel.h>
58 1.84.4.2 nathanw #include <sys/proc.h>
59 1.84.4.2 nathanw #include <sys/tty.h>
60 1.84.4.2 nathanw #include <sys/time.h>
61 1.84.4.2 nathanw #include <sys/syslog.h>
62 1.84.4.2 nathanw
63 1.84.4.2 nathanw #include <machine/bsd_openprom.h>
64 1.84.4.2 nathanw #include <machine/autoconf.h>
65 1.84.4.2 nathanw #include <machine/intr.h>
66 1.84.4.2 nathanw #include <machine/conf.h>
67 1.84.4.2 nathanw #include <machine/eeprom.h>
68 1.84.4.2 nathanw #include <machine/psl.h>
69 1.84.4.2 nathanw #include <machine/z8530var.h>
70 1.84.4.2 nathanw
71 1.84.4.2 nathanw #include <dev/cons.h>
72 1.84.4.2 nathanw #include <dev/ic/z8530reg.h>
73 1.84.4.2 nathanw
74 1.84.4.2 nathanw #include <sparc/sparc/vaddrs.h>
75 1.84.4.2 nathanw #include <sparc/sparc/auxreg.h>
76 1.84.4.2 nathanw #include <sparc/sparc/auxiotwo.h>
77 1.84.4.2 nathanw #include <sparc/dev/cons.h>
78 1.84.4.2 nathanw
79 1.84.4.2 nathanw #include "kbd.h" /* NKBD */
80 1.84.4.2 nathanw #include "zs.h" /* NZS */
81 1.84.4.2 nathanw
82 1.84.4.2 nathanw /* Make life easier for the initialized arrays here. */
83 1.84.4.2 nathanw #if NZS < 3
84 1.84.4.2 nathanw #undef NZS
85 1.84.4.2 nathanw #define NZS 3
86 1.84.4.2 nathanw #endif
87 1.84.4.2 nathanw
88 1.84.4.2 nathanw /*
89 1.84.4.2 nathanw * Some warts needed by z8530tty.c -
90 1.84.4.2 nathanw * The default parity REALLY needs to be the same as the PROM uses,
91 1.84.4.2 nathanw * or you can not see messages done with printf during boot-up...
92 1.84.4.2 nathanw */
93 1.84.4.2 nathanw int zs_def_cflag = (CREAD | CS8 | HUPCL);
94 1.84.4.2 nathanw int zs_major = 12;
95 1.84.4.2 nathanw
96 1.84.4.2 nathanw /*
97 1.84.4.2 nathanw * The Sun provides a 4.9152 MHz clock to the ZS chips.
98 1.84.4.2 nathanw */
99 1.84.4.2 nathanw #define PCLK (9600 * 512) /* PCLK pin input clock rate */
100 1.84.4.2 nathanw
101 1.84.4.2 nathanw /*
102 1.84.4.2 nathanw * Select software interrupt bit based on TTY ipl.
103 1.84.4.2 nathanw */
104 1.84.4.2 nathanw #if PIL_TTY == 1
105 1.84.4.2 nathanw # define IE_ZSSOFT IE_L1
106 1.84.4.2 nathanw #elif PIL_TTY == 4
107 1.84.4.2 nathanw # define IE_ZSSOFT IE_L4
108 1.84.4.2 nathanw #elif PIL_TTY == 6
109 1.84.4.2 nathanw # define IE_ZSSOFT IE_L6
110 1.84.4.2 nathanw #else
111 1.84.4.2 nathanw # error "no suitable software interrupt bit"
112 1.84.4.2 nathanw #endif
113 1.84.4.2 nathanw
114 1.84.4.2 nathanw #define ZS_DELAY() (CPU_ISSUN4C ? (0) : delay(2))
115 1.84.4.2 nathanw
116 1.84.4.2 nathanw /* The layout of this is hardware-dependent (padding, order). */
117 1.84.4.2 nathanw struct zschan {
118 1.84.4.2 nathanw volatile u_char zc_csr; /* ctrl,status, and indirect access */
119 1.84.4.2 nathanw u_char zc_xxx0;
120 1.84.4.2 nathanw volatile u_char zc_data; /* data */
121 1.84.4.2 nathanw u_char zc_xxx1;
122 1.84.4.2 nathanw };
123 1.84.4.2 nathanw struct zsdevice {
124 1.84.4.2 nathanw /* Yes, they are backwards. */
125 1.84.4.2 nathanw struct zschan zs_chan_b;
126 1.84.4.2 nathanw struct zschan zs_chan_a;
127 1.84.4.2 nathanw };
128 1.84.4.2 nathanw
129 1.84.4.2 nathanw /* ZS channel used as the console device (if any) */
130 1.84.4.2 nathanw void *zs_conschan_get, *zs_conschan_put;
131 1.84.4.2 nathanw
132 1.84.4.2 nathanw static u_char zs_init_reg[16] = {
133 1.84.4.2 nathanw 0, /* 0: CMD (reset, etc.) */
134 1.84.4.2 nathanw 0, /* 1: No interrupts yet. */
135 1.84.4.2 nathanw 0, /* 2: IVECT */
136 1.84.4.2 nathanw ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
137 1.84.4.2 nathanw ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
138 1.84.4.2 nathanw ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
139 1.84.4.2 nathanw 0, /* 6: TXSYNC/SYNCLO */
140 1.84.4.2 nathanw 0, /* 7: RXSYNC/SYNCHI */
141 1.84.4.2 nathanw 0, /* 8: alias for data port */
142 1.84.4.2 nathanw ZSWR9_MASTER_IE | ZSWR9_NO_VECTOR,
143 1.84.4.2 nathanw 0, /*10: Misc. TX/RX control bits */
144 1.84.4.2 nathanw ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
145 1.84.4.2 nathanw ((PCLK/32)/9600)-2, /*12: BAUDLO (default=9600) */
146 1.84.4.2 nathanw 0, /*13: BAUDHI (default=9600) */
147 1.84.4.2 nathanw ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK,
148 1.84.4.2 nathanw ZSWR15_BREAK_IE,
149 1.84.4.2 nathanw };
150 1.84.4.2 nathanw
151 1.84.4.2 nathanw /* Console ops */
152 1.84.4.2 nathanw static int zscngetc __P((dev_t));
153 1.84.4.2 nathanw static void zscnputc __P((dev_t, int));
154 1.84.4.2 nathanw static void zscnpollc __P((dev_t, int));
155 1.84.4.2 nathanw
156 1.84.4.2 nathanw struct consdev zs_consdev = {
157 1.84.4.2 nathanw NULL,
158 1.84.4.2 nathanw NULL,
159 1.84.4.2 nathanw zscngetc,
160 1.84.4.2 nathanw zscnputc,
161 1.84.4.2 nathanw zscnpollc,
162 1.84.4.2 nathanw NULL,
163 1.84.4.2 nathanw };
164 1.84.4.2 nathanw
165 1.84.4.2 nathanw
166 1.84.4.2 nathanw /****************************************************************
167 1.84.4.2 nathanw * Autoconfig
168 1.84.4.2 nathanw ****************************************************************/
169 1.84.4.2 nathanw
170 1.84.4.2 nathanw /* Definition of the driver for autoconfig. */
171 1.84.4.2 nathanw static int zs_match_mainbus __P((struct device *, struct cfdata *, void *));
172 1.84.4.2 nathanw static int zs_match_obio __P((struct device *, struct cfdata *, void *));
173 1.84.4.2 nathanw static void zs_attach_mainbus __P((struct device *, struct device *, void *));
174 1.84.4.2 nathanw static void zs_attach_obio __P((struct device *, struct device *, void *));
175 1.84.4.2 nathanw
176 1.84.4.3 nathanw #if defined(SUN4D)
177 1.84.4.3 nathanw #include <sparc/dev/bootbusvar.h>
178 1.84.4.3 nathanw
179 1.84.4.3 nathanw static int zs_match_bootbus __P((struct device *, struct cfdata *, void *));
180 1.84.4.3 nathanw static void zs_attach_bootbus __P((struct device *, struct device *, void *));
181 1.84.4.3 nathanw
182 1.84.4.3 nathanw struct cfattach zs_bootbus_ca = {
183 1.84.4.3 nathanw sizeof(struct zsc_softc), zs_match_bootbus, zs_attach_bootbus
184 1.84.4.3 nathanw };
185 1.84.4.3 nathanw #endif /* SUN4D */
186 1.84.4.2 nathanw
187 1.84.4.2 nathanw static void zs_attach __P((struct zsc_softc *, struct zsdevice *, int));
188 1.84.4.2 nathanw static int zs_print __P((void *, const char *name));
189 1.84.4.2 nathanw
190 1.84.4.2 nathanw struct cfattach zs_mainbus_ca = {
191 1.84.4.2 nathanw sizeof(struct zsc_softc), zs_match_mainbus, zs_attach_mainbus
192 1.84.4.2 nathanw };
193 1.84.4.2 nathanw
194 1.84.4.2 nathanw struct cfattach zs_obio_ca = {
195 1.84.4.2 nathanw sizeof(struct zsc_softc), zs_match_obio, zs_attach_obio
196 1.84.4.2 nathanw };
197 1.84.4.2 nathanw
198 1.84.4.2 nathanw extern struct cfdriver zs_cd;
199 1.84.4.2 nathanw
200 1.84.4.2 nathanw /* Interrupt handlers. */
201 1.84.4.2 nathanw static int zshard __P((void *));
202 1.84.4.2 nathanw static int zssoft __P((void *));
203 1.84.4.2 nathanw
204 1.84.4.2 nathanw static int zs_get_speed __P((struct zs_chanstate *));
205 1.84.4.2 nathanw
206 1.84.4.2 nathanw /* Console device support */
207 1.84.4.2 nathanw static int zs_console_flags __P((int, int, int));
208 1.84.4.2 nathanw
209 1.84.4.2 nathanw /* Power management hooks */
210 1.84.4.2 nathanw int zs_enable __P((struct zs_chanstate *));
211 1.84.4.2 nathanw void zs_disable __P((struct zs_chanstate *));
212 1.84.4.2 nathanw
213 1.84.4.2 nathanw
214 1.84.4.2 nathanw /*
215 1.84.4.2 nathanw * Is the zs chip present?
216 1.84.4.2 nathanw */
217 1.84.4.2 nathanw static int
218 1.84.4.2 nathanw zs_match_mainbus(parent, cf, aux)
219 1.84.4.2 nathanw struct device *parent;
220 1.84.4.2 nathanw struct cfdata *cf;
221 1.84.4.2 nathanw void *aux;
222 1.84.4.2 nathanw {
223 1.84.4.2 nathanw struct mainbus_attach_args *ma = aux;
224 1.84.4.2 nathanw
225 1.84.4.2 nathanw if (strcmp(cf->cf_driver->cd_name, ma->ma_name) != 0)
226 1.84.4.2 nathanw return (0);
227 1.84.4.2 nathanw
228 1.84.4.2 nathanw return (1);
229 1.84.4.2 nathanw }
230 1.84.4.2 nathanw
231 1.84.4.2 nathanw static int
232 1.84.4.2 nathanw zs_match_obio(parent, cf, aux)
233 1.84.4.2 nathanw struct device *parent;
234 1.84.4.2 nathanw struct cfdata *cf;
235 1.84.4.2 nathanw void *aux;
236 1.84.4.2 nathanw {
237 1.84.4.2 nathanw union obio_attach_args *uoba = aux;
238 1.84.4.2 nathanw struct obio4_attach_args *oba;
239 1.84.4.2 nathanw
240 1.84.4.2 nathanw if (uoba->uoba_isobio4 == 0) {
241 1.84.4.2 nathanw struct sbus_attach_args *sa = &uoba->uoba_sbus;
242 1.84.4.2 nathanw
243 1.84.4.2 nathanw if (strcmp(cf->cf_driver->cd_name, sa->sa_name) != 0)
244 1.84.4.2 nathanw return (0);
245 1.84.4.2 nathanw
246 1.84.4.2 nathanw return (1);
247 1.84.4.2 nathanw }
248 1.84.4.2 nathanw
249 1.84.4.2 nathanw oba = &uoba->uoba_oba4;
250 1.84.4.2 nathanw return (bus_space_probe(oba->oba_bustag, oba->oba_paddr,
251 1.84.4.2 nathanw 1, 0, 0, NULL, NULL));
252 1.84.4.2 nathanw }
253 1.84.4.2 nathanw
254 1.84.4.3 nathanw #if defined(SUN4D)
255 1.84.4.3 nathanw static int
256 1.84.4.3 nathanw zs_match_bootbus(parent, cf, aux)
257 1.84.4.3 nathanw struct device *parent;
258 1.84.4.3 nathanw struct cfdata *cf;
259 1.84.4.3 nathanw void *aux;
260 1.84.4.3 nathanw {
261 1.84.4.3 nathanw struct bootbus_attach_args *baa = aux;
262 1.84.4.3 nathanw
263 1.84.4.3 nathanw return (strcmp(cf->cf_driver->cd_name, baa->ba_name) == 0);
264 1.84.4.3 nathanw }
265 1.84.4.3 nathanw #endif /* SUN4D */
266 1.84.4.3 nathanw
267 1.84.4.2 nathanw static void
268 1.84.4.2 nathanw zs_attach_mainbus(parent, self, aux)
269 1.84.4.2 nathanw struct device *parent;
270 1.84.4.2 nathanw struct device *self;
271 1.84.4.2 nathanw void *aux;
272 1.84.4.2 nathanw {
273 1.84.4.2 nathanw struct zsc_softc *zsc = (void *) self;
274 1.84.4.2 nathanw struct mainbus_attach_args *ma = aux;
275 1.84.4.2 nathanw
276 1.84.4.2 nathanw zsc->zsc_bustag = ma->ma_bustag;
277 1.84.4.2 nathanw zsc->zsc_dmatag = ma->ma_dmatag;
278 1.84.4.2 nathanw zsc->zsc_promunit = PROM_getpropint(ma->ma_node, "slave", -2);
279 1.84.4.2 nathanw zsc->zsc_node = ma->ma_node;
280 1.84.4.2 nathanw
281 1.84.4.2 nathanw /*
282 1.84.4.2 nathanw * For machines with zs on mainbus (all sun4c models), we expect
283 1.84.4.2 nathanw * the device registers to be mapped by the PROM.
284 1.84.4.2 nathanw */
285 1.84.4.2 nathanw zs_attach(zsc, ma->ma_promvaddr, ma->ma_pri);
286 1.84.4.2 nathanw }
287 1.84.4.2 nathanw
288 1.84.4.2 nathanw static void
289 1.84.4.2 nathanw zs_attach_obio(parent, self, aux)
290 1.84.4.2 nathanw struct device *parent;
291 1.84.4.2 nathanw struct device *self;
292 1.84.4.2 nathanw void *aux;
293 1.84.4.2 nathanw {
294 1.84.4.2 nathanw struct zsc_softc *zsc = (void *) self;
295 1.84.4.2 nathanw union obio_attach_args *uoba = aux;
296 1.84.4.2 nathanw
297 1.84.4.2 nathanw if (uoba->uoba_isobio4 == 0) {
298 1.84.4.2 nathanw struct sbus_attach_args *sa = &uoba->uoba_sbus;
299 1.84.4.2 nathanw void *va;
300 1.84.4.2 nathanw struct zs_chanstate *cs;
301 1.84.4.2 nathanw int channel;
302 1.84.4.2 nathanw
303 1.84.4.2 nathanw if (sa->sa_nintr == 0) {
304 1.84.4.2 nathanw printf(" no interrupt lines\n");
305 1.84.4.2 nathanw return;
306 1.84.4.2 nathanw }
307 1.84.4.2 nathanw
308 1.84.4.2 nathanw /*
309 1.84.4.2 nathanw * Some sun4m models (Javastations) may not map the zs device.
310 1.84.4.2 nathanw */
311 1.84.4.2 nathanw if (sa->sa_npromvaddrs > 0)
312 1.84.4.2 nathanw va = (void *)sa->sa_promvaddr;
313 1.84.4.2 nathanw else {
314 1.84.4.2 nathanw bus_space_handle_t bh;
315 1.84.4.2 nathanw
316 1.84.4.2 nathanw if (sbus_bus_map(sa->sa_bustag,
317 1.84.4.2 nathanw sa->sa_slot,
318 1.84.4.2 nathanw sa->sa_offset,
319 1.84.4.2 nathanw sa->sa_size,
320 1.84.4.2 nathanw BUS_SPACE_MAP_LINEAR, &bh) != 0) {
321 1.84.4.2 nathanw printf(" cannot map zs registers\n");
322 1.84.4.2 nathanw return;
323 1.84.4.2 nathanw }
324 1.84.4.2 nathanw va = (void *)bh;
325 1.84.4.2 nathanw }
326 1.84.4.2 nathanw
327 1.84.4.2 nathanw /*
328 1.84.4.2 nathanw * Check if power state can be set, e.g. Tadpole 3GX
329 1.84.4.2 nathanw */
330 1.84.4.2 nathanw if (PROM_getpropint(sa->sa_node, "pwr-on-auxio2", 0))
331 1.84.4.2 nathanw {
332 1.84.4.2 nathanw printf (" powered via auxio2");
333 1.84.4.2 nathanw for (channel = 0; channel < 2; channel++) {
334 1.84.4.2 nathanw cs = &zsc->zsc_cs_store[channel];
335 1.84.4.2 nathanw cs->enable = zs_enable;
336 1.84.4.2 nathanw cs->disable = zs_disable;
337 1.84.4.2 nathanw }
338 1.84.4.2 nathanw }
339 1.84.4.2 nathanw
340 1.84.4.2 nathanw zsc->zsc_bustag = sa->sa_bustag;
341 1.84.4.2 nathanw zsc->zsc_dmatag = sa->sa_dmatag;
342 1.84.4.2 nathanw zsc->zsc_promunit = PROM_getpropint(sa->sa_node, "slave", -2);
343 1.84.4.2 nathanw zsc->zsc_node = sa->sa_node;
344 1.84.4.2 nathanw zs_attach(zsc, va, sa->sa_pri);
345 1.84.4.2 nathanw } else {
346 1.84.4.2 nathanw struct obio4_attach_args *oba = &uoba->uoba_oba4;
347 1.84.4.2 nathanw bus_space_handle_t bh;
348 1.84.4.2 nathanw bus_addr_t paddr = oba->oba_paddr;
349 1.84.4.2 nathanw
350 1.84.4.2 nathanw /*
351 1.84.4.2 nathanw * As for zs on mainbus, we require a PROM mapping.
352 1.84.4.2 nathanw */
353 1.84.4.2 nathanw if (bus_space_map(oba->oba_bustag,
354 1.84.4.2 nathanw paddr,
355 1.84.4.2 nathanw sizeof(struct zsdevice),
356 1.84.4.2 nathanw BUS_SPACE_MAP_LINEAR | OBIO_BUS_MAP_USE_ROM,
357 1.84.4.2 nathanw &bh) != 0) {
358 1.84.4.2 nathanw printf(" cannot map zs registers\n");
359 1.84.4.2 nathanw return;
360 1.84.4.2 nathanw }
361 1.84.4.2 nathanw zsc->zsc_bustag = oba->oba_bustag;
362 1.84.4.2 nathanw zsc->zsc_dmatag = oba->oba_dmatag;
363 1.84.4.2 nathanw /* Find prom unit by physical address */
364 1.84.4.2 nathanw if (cpuinfo.cpu_type == CPUTYP_4_100)
365 1.84.4.2 nathanw /*
366 1.84.4.2 nathanw * On the sun4/100, the top-most 4 bits are zero
367 1.84.4.2 nathanw * on obio addresses; force them to 1's for the
368 1.84.4.2 nathanw * sake of the comparison here.
369 1.84.4.2 nathanw */
370 1.84.4.2 nathanw paddr |= 0xf0000000;
371 1.84.4.2 nathanw zsc->zsc_promunit =
372 1.84.4.2 nathanw (paddr == 0xf1000000) ? 0 :
373 1.84.4.2 nathanw (paddr == 0xf0000000) ? 1 :
374 1.84.4.2 nathanw (paddr == 0xe0000000) ? 2 : -2;
375 1.84.4.2 nathanw
376 1.84.4.2 nathanw zs_attach(zsc, (void *)bh, oba->oba_pri);
377 1.84.4.2 nathanw }
378 1.84.4.2 nathanw }
379 1.84.4.3 nathanw
380 1.84.4.3 nathanw #if defined(SUN4D)
381 1.84.4.3 nathanw static void
382 1.84.4.3 nathanw zs_attach_bootbus(parent, self, aux)
383 1.84.4.3 nathanw struct device *parent;
384 1.84.4.3 nathanw struct device *self;
385 1.84.4.3 nathanw void *aux;
386 1.84.4.3 nathanw {
387 1.84.4.3 nathanw struct zsc_softc *zsc = (void *) self;
388 1.84.4.3 nathanw struct bootbus_attach_args *baa = aux;
389 1.84.4.3 nathanw void *va;
390 1.84.4.3 nathanw
391 1.84.4.3 nathanw if (baa->ba_nintr == 0) {
392 1.84.4.3 nathanw printf(": no interrupt lines\n");
393 1.84.4.3 nathanw return;
394 1.84.4.3 nathanw }
395 1.84.4.3 nathanw
396 1.84.4.3 nathanw if (baa->ba_npromvaddrs > 0)
397 1.84.4.3 nathanw va = (void *) baa->ba_promvaddrs;
398 1.84.4.3 nathanw else {
399 1.84.4.3 nathanw bus_space_handle_t bh;
400 1.84.4.3 nathanw
401 1.84.4.3 nathanw if (bus_space_map(baa->ba_bustag,
402 1.84.4.3 nathanw BUS_ADDR(baa->ba_slot, baa->ba_offset),
403 1.84.4.3 nathanw baa->ba_size, BUS_SPACE_MAP_LINEAR, &bh) != 0) {
404 1.84.4.3 nathanw printf(": cannot map zs registers\n");
405 1.84.4.3 nathanw return;
406 1.84.4.3 nathanw }
407 1.84.4.3 nathanw va = (void *) bh;
408 1.84.4.3 nathanw }
409 1.84.4.3 nathanw
410 1.84.4.3 nathanw zsc->zsc_bustag = baa->ba_bustag;
411 1.84.4.3 nathanw zsc->zsc_promunit = PROM_getpropint(baa->ba_node, "slave", -2);
412 1.84.4.3 nathanw zsc->zsc_node = baa->ba_node;
413 1.84.4.3 nathanw zs_attach(zsc, va, baa->ba_intr[0].oi_pri);
414 1.84.4.3 nathanw }
415 1.84.4.3 nathanw #endif /* SUN4D */
416 1.84.4.3 nathanw
417 1.84.4.2 nathanw /*
418 1.84.4.2 nathanw * Attach a found zs.
419 1.84.4.2 nathanw *
420 1.84.4.2 nathanw * USE ROM PROPERTIES port-a-ignore-cd AND port-b-ignore-cd FOR
421 1.84.4.2 nathanw * SOFT CARRIER, AND keyboard PROPERTY FOR KEYBOARD/MOUSE?
422 1.84.4.2 nathanw */
423 1.84.4.2 nathanw static void
424 1.84.4.2 nathanw zs_attach(zsc, zsd, pri)
425 1.84.4.2 nathanw struct zsc_softc *zsc;
426 1.84.4.2 nathanw struct zsdevice *zsd;
427 1.84.4.2 nathanw int pri;
428 1.84.4.2 nathanw {
429 1.84.4.2 nathanw struct zsc_attach_args zsc_args;
430 1.84.4.2 nathanw struct zs_chanstate *cs;
431 1.84.4.2 nathanw int s, channel;
432 1.84.4.2 nathanw static int didintr, prevpri;
433 1.84.4.2 nathanw
434 1.84.4.2 nathanw if (zsd == NULL) {
435 1.84.4.2 nathanw printf("configuration incomplete\n");
436 1.84.4.2 nathanw return;
437 1.84.4.2 nathanw }
438 1.84.4.2 nathanw
439 1.84.4.2 nathanw printf(" softpri %d\n", PIL_TTY);
440 1.84.4.2 nathanw
441 1.84.4.2 nathanw /*
442 1.84.4.2 nathanw * Initialize software state for each channel.
443 1.84.4.2 nathanw */
444 1.84.4.2 nathanw for (channel = 0; channel < 2; channel++) {
445 1.84.4.2 nathanw struct zschan *zc;
446 1.84.4.2 nathanw
447 1.84.4.2 nathanw zsc_args.channel = channel;
448 1.84.4.2 nathanw cs = &zsc->zsc_cs_store[channel];
449 1.84.4.2 nathanw zsc->zsc_cs[channel] = cs;
450 1.84.4.2 nathanw
451 1.84.4.2 nathanw cs->cs_channel = channel;
452 1.84.4.2 nathanw cs->cs_private = NULL;
453 1.84.4.2 nathanw cs->cs_ops = &zsops_null;
454 1.84.4.2 nathanw cs->cs_brg_clk = PCLK / 16;
455 1.84.4.2 nathanw
456 1.84.4.2 nathanw zc = (channel == 0) ? &zsd->zs_chan_a : &zsd->zs_chan_b;
457 1.84.4.2 nathanw
458 1.84.4.2 nathanw zsc_args.hwflags = zs_console_flags(zsc->zsc_promunit,
459 1.84.4.2 nathanw zsc->zsc_node,
460 1.84.4.2 nathanw channel);
461 1.84.4.2 nathanw
462 1.84.4.2 nathanw if (zsc_args.hwflags & ZS_HWFLAG_CONSOLE) {
463 1.84.4.2 nathanw zsc_args.hwflags |= ZS_HWFLAG_USE_CONSDEV;
464 1.84.4.2 nathanw zsc_args.consdev = &zs_consdev;
465 1.84.4.2 nathanw }
466 1.84.4.2 nathanw
467 1.84.4.2 nathanw if ((zsc_args.hwflags & ZS_HWFLAG_CONSOLE_INPUT) != 0) {
468 1.84.4.2 nathanw zs_conschan_get = zc;
469 1.84.4.2 nathanw }
470 1.84.4.2 nathanw if ((zsc_args.hwflags & ZS_HWFLAG_CONSOLE_OUTPUT) != 0) {
471 1.84.4.2 nathanw zs_conschan_put = zc;
472 1.84.4.2 nathanw }
473 1.84.4.2 nathanw /* Childs need to set cn_dev, etc */
474 1.84.4.2 nathanw
475 1.84.4.2 nathanw cs->cs_reg_csr = &zc->zc_csr;
476 1.84.4.2 nathanw cs->cs_reg_data = &zc->zc_data;
477 1.84.4.2 nathanw
478 1.84.4.2 nathanw bcopy(zs_init_reg, cs->cs_creg, 16);
479 1.84.4.2 nathanw bcopy(zs_init_reg, cs->cs_preg, 16);
480 1.84.4.2 nathanw
481 1.84.4.2 nathanw /* XXX: Consult PROM properties for this?! */
482 1.84.4.2 nathanw cs->cs_defspeed = zs_get_speed(cs);
483 1.84.4.2 nathanw cs->cs_defcflag = zs_def_cflag;
484 1.84.4.2 nathanw
485 1.84.4.2 nathanw /* Make these correspond to cs_defcflag (-crtscts) */
486 1.84.4.2 nathanw cs->cs_rr0_dcd = ZSRR0_DCD;
487 1.84.4.2 nathanw cs->cs_rr0_cts = 0;
488 1.84.4.2 nathanw cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
489 1.84.4.2 nathanw cs->cs_wr5_rts = 0;
490 1.84.4.2 nathanw
491 1.84.4.2 nathanw /*
492 1.84.4.2 nathanw * Clear the master interrupt enable.
493 1.84.4.2 nathanw * The INTENA is common to both channels,
494 1.84.4.2 nathanw * so just do it on the A channel.
495 1.84.4.2 nathanw */
496 1.84.4.2 nathanw if (channel == 0) {
497 1.84.4.2 nathanw zs_write_reg(cs, 9, 0);
498 1.84.4.2 nathanw }
499 1.84.4.2 nathanw
500 1.84.4.2 nathanw /*
501 1.84.4.2 nathanw * Look for a child driver for this channel.
502 1.84.4.2 nathanw * The child attach will setup the hardware.
503 1.84.4.2 nathanw */
504 1.84.4.2 nathanw if (!config_found(&zsc->zsc_dev, (void *)&zsc_args, zs_print)) {
505 1.84.4.2 nathanw /* No sub-driver. Just reset it. */
506 1.84.4.2 nathanw u_char reset = (channel == 0) ?
507 1.84.4.2 nathanw ZSWR9_A_RESET : ZSWR9_B_RESET;
508 1.84.4.2 nathanw s = splzs();
509 1.84.4.2 nathanw zs_write_reg(cs, 9, reset);
510 1.84.4.2 nathanw splx(s);
511 1.84.4.2 nathanw }
512 1.84.4.2 nathanw }
513 1.84.4.2 nathanw
514 1.84.4.2 nathanw /*
515 1.84.4.2 nathanw * Now safe to install interrupt handlers. Note the arguments
516 1.84.4.2 nathanw * to the interrupt handlers aren't used. Note, we only do this
517 1.84.4.2 nathanw * once since both SCCs interrupt at the same level and vector.
518 1.84.4.2 nathanw */
519 1.84.4.2 nathanw if (!didintr) {
520 1.84.4.2 nathanw didintr = 1;
521 1.84.4.2 nathanw prevpri = pri;
522 1.84.4.2 nathanw bus_intr_establish(zsc->zsc_bustag, pri, IPL_SERIAL, 0,
523 1.84.4.2 nathanw zshard, NULL);
524 1.84.4.2 nathanw bus_intr_establish(zsc->zsc_bustag, PIL_TTY,
525 1.84.4.2 nathanw IPL_SOFTSERIAL,
526 1.84.4.2 nathanw BUS_INTR_ESTABLISH_SOFTINTR,
527 1.84.4.2 nathanw zssoft, NULL);
528 1.84.4.2 nathanw } else if (pri != prevpri)
529 1.84.4.2 nathanw panic("broken zs interrupt scheme");
530 1.84.4.2 nathanw
531 1.84.4.2 nathanw evcnt_attach_dynamic(&zsc->zsc_intrcnt, EVCNT_TYPE_INTR, NULL,
532 1.84.4.2 nathanw zsc->zsc_dev.dv_xname, "intr");
533 1.84.4.2 nathanw
534 1.84.4.2 nathanw /*
535 1.84.4.2 nathanw * Set the master interrupt enable and interrupt vector.
536 1.84.4.2 nathanw * (common to both channels, do it on A)
537 1.84.4.2 nathanw */
538 1.84.4.2 nathanw cs = zsc->zsc_cs[0];
539 1.84.4.2 nathanw s = splhigh();
540 1.84.4.2 nathanw /* interrupt vector */
541 1.84.4.2 nathanw zs_write_reg(cs, 2, zs_init_reg[2]);
542 1.84.4.2 nathanw /* master interrupt control (enable) */
543 1.84.4.2 nathanw zs_write_reg(cs, 9, zs_init_reg[9]);
544 1.84.4.2 nathanw splx(s);
545 1.84.4.2 nathanw
546 1.84.4.2 nathanw #if 0
547 1.84.4.2 nathanw /*
548 1.84.4.2 nathanw * XXX: L1A hack - We would like to be able to break into
549 1.84.4.2 nathanw * the debugger during the rest of autoconfiguration, so
550 1.84.4.2 nathanw * lower interrupts just enough to let zs interrupts in.
551 1.84.4.2 nathanw * This is done after both zs devices are attached.
552 1.84.4.2 nathanw */
553 1.84.4.2 nathanw if (zsc->zsc_promunit == 1) {
554 1.84.4.2 nathanw printf("zs1: enabling zs interrupts\n");
555 1.84.4.2 nathanw (void)splfd(); /* XXX: splzs - 1 */
556 1.84.4.2 nathanw }
557 1.84.4.2 nathanw #endif
558 1.84.4.2 nathanw }
559 1.84.4.2 nathanw
560 1.84.4.2 nathanw static int
561 1.84.4.2 nathanw zs_print(aux, name)
562 1.84.4.2 nathanw void *aux;
563 1.84.4.2 nathanw const char *name;
564 1.84.4.2 nathanw {
565 1.84.4.2 nathanw struct zsc_attach_args *args = aux;
566 1.84.4.2 nathanw
567 1.84.4.2 nathanw if (name != NULL)
568 1.84.4.2 nathanw printf("%s: ", name);
569 1.84.4.2 nathanw
570 1.84.4.2 nathanw if (args->channel != -1)
571 1.84.4.2 nathanw printf(" channel %d", args->channel);
572 1.84.4.2 nathanw
573 1.84.4.2 nathanw return (UNCONF);
574 1.84.4.2 nathanw }
575 1.84.4.2 nathanw
576 1.84.4.2 nathanw static volatile int zssoftpending;
577 1.84.4.2 nathanw
578 1.84.4.2 nathanw /*
579 1.84.4.2 nathanw * Our ZS chips all share a common, autovectored interrupt,
580 1.84.4.2 nathanw * so we have to look at all of them on each interrupt.
581 1.84.4.2 nathanw */
582 1.84.4.2 nathanw static int
583 1.84.4.2 nathanw zshard(arg)
584 1.84.4.2 nathanw void *arg;
585 1.84.4.2 nathanw {
586 1.84.4.2 nathanw struct zsc_softc *zsc;
587 1.84.4.2 nathanw int unit, rr3, rval, softreq;
588 1.84.4.2 nathanw
589 1.84.4.2 nathanw rval = softreq = 0;
590 1.84.4.2 nathanw for (unit = 0; unit < zs_cd.cd_ndevs; unit++) {
591 1.84.4.2 nathanw struct zs_chanstate *cs;
592 1.84.4.2 nathanw
593 1.84.4.2 nathanw zsc = zs_cd.cd_devs[unit];
594 1.84.4.2 nathanw if (zsc == NULL)
595 1.84.4.2 nathanw continue;
596 1.84.4.2 nathanw rr3 = zsc_intr_hard(zsc);
597 1.84.4.2 nathanw /* Count up the interrupts. */
598 1.84.4.2 nathanw if (rr3) {
599 1.84.4.2 nathanw rval |= rr3;
600 1.84.4.2 nathanw zsc->zsc_intrcnt.ev_count++;
601 1.84.4.2 nathanw }
602 1.84.4.2 nathanw if ((cs = zsc->zsc_cs[0]) != NULL)
603 1.84.4.2 nathanw softreq |= cs->cs_softreq;
604 1.84.4.2 nathanw if ((cs = zsc->zsc_cs[1]) != NULL)
605 1.84.4.2 nathanw softreq |= cs->cs_softreq;
606 1.84.4.2 nathanw }
607 1.84.4.2 nathanw
608 1.84.4.2 nathanw /* We are at splzs here, so no need to lock. */
609 1.84.4.2 nathanw if (softreq && (zssoftpending == 0)) {
610 1.84.4.2 nathanw zssoftpending = IE_ZSSOFT;
611 1.84.4.2 nathanw #if defined(SUN4M)
612 1.84.4.2 nathanw if (CPU_ISSUN4M)
613 1.84.4.2 nathanw raise(0, PIL_TTY);
614 1.84.4.2 nathanw else
615 1.84.4.2 nathanw #endif
616 1.84.4.2 nathanw ienab_bis(IE_ZSSOFT);
617 1.84.4.2 nathanw }
618 1.84.4.2 nathanw return (rval);
619 1.84.4.2 nathanw }
620 1.84.4.2 nathanw
621 1.84.4.2 nathanw /*
622 1.84.4.2 nathanw * Similar scheme as for zshard (look at all of them)
623 1.84.4.2 nathanw */
624 1.84.4.2 nathanw static int
625 1.84.4.2 nathanw zssoft(arg)
626 1.84.4.2 nathanw void *arg;
627 1.84.4.2 nathanw {
628 1.84.4.2 nathanw struct zsc_softc *zsc;
629 1.84.4.2 nathanw int s, unit;
630 1.84.4.2 nathanw
631 1.84.4.2 nathanw /* This is not the only ISR on this IPL. */
632 1.84.4.2 nathanw if (zssoftpending == 0)
633 1.84.4.2 nathanw return (0);
634 1.84.4.2 nathanw
635 1.84.4.2 nathanw /*
636 1.84.4.2 nathanw * The soft intr. bit will be set by zshard only if
637 1.84.4.2 nathanw * the variable zssoftpending is zero. The order of
638 1.84.4.2 nathanw * these next two statements prevents our clearing
639 1.84.4.2 nathanw * the soft intr bit just after zshard has set it.
640 1.84.4.2 nathanw */
641 1.84.4.2 nathanw /* ienab_bic(IE_ZSSOFT); */
642 1.84.4.2 nathanw zssoftpending = 0;
643 1.84.4.2 nathanw
644 1.84.4.2 nathanw /* Make sure we call the tty layer at spltty. */
645 1.84.4.2 nathanw s = spltty();
646 1.84.4.2 nathanw for (unit = 0; unit < zs_cd.cd_ndevs; unit++) {
647 1.84.4.2 nathanw zsc = zs_cd.cd_devs[unit];
648 1.84.4.2 nathanw if (zsc == NULL)
649 1.84.4.2 nathanw continue;
650 1.84.4.2 nathanw (void)zsc_intr_soft(zsc);
651 1.84.4.2 nathanw }
652 1.84.4.2 nathanw splx(s);
653 1.84.4.2 nathanw return (1);
654 1.84.4.2 nathanw }
655 1.84.4.2 nathanw
656 1.84.4.2 nathanw
657 1.84.4.2 nathanw /*
658 1.84.4.2 nathanw * Compute the current baud rate given a ZS channel.
659 1.84.4.2 nathanw */
660 1.84.4.2 nathanw static int
661 1.84.4.2 nathanw zs_get_speed(cs)
662 1.84.4.2 nathanw struct zs_chanstate *cs;
663 1.84.4.2 nathanw {
664 1.84.4.2 nathanw int tconst;
665 1.84.4.2 nathanw
666 1.84.4.2 nathanw tconst = zs_read_reg(cs, 12);
667 1.84.4.2 nathanw tconst |= zs_read_reg(cs, 13) << 8;
668 1.84.4.2 nathanw return (TCONST_TO_BPS(cs->cs_brg_clk, tconst));
669 1.84.4.2 nathanw }
670 1.84.4.2 nathanw
671 1.84.4.2 nathanw /*
672 1.84.4.2 nathanw * MD functions for setting the baud rate and control modes.
673 1.84.4.2 nathanw */
674 1.84.4.2 nathanw int
675 1.84.4.2 nathanw zs_set_speed(cs, bps)
676 1.84.4.2 nathanw struct zs_chanstate *cs;
677 1.84.4.2 nathanw int bps; /* bits per second */
678 1.84.4.2 nathanw {
679 1.84.4.2 nathanw int tconst, real_bps;
680 1.84.4.2 nathanw
681 1.84.4.2 nathanw if (bps == 0)
682 1.84.4.2 nathanw return (0);
683 1.84.4.2 nathanw
684 1.84.4.2 nathanw #ifdef DIAGNOSTIC
685 1.84.4.2 nathanw if (cs->cs_brg_clk == 0)
686 1.84.4.2 nathanw panic("zs_set_speed");
687 1.84.4.2 nathanw #endif
688 1.84.4.2 nathanw
689 1.84.4.2 nathanw tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
690 1.84.4.2 nathanw if (tconst < 0)
691 1.84.4.2 nathanw return (EINVAL);
692 1.84.4.2 nathanw
693 1.84.4.2 nathanw /* Convert back to make sure we can do it. */
694 1.84.4.2 nathanw real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
695 1.84.4.2 nathanw
696 1.84.4.2 nathanw /* XXX - Allow some tolerance here? */
697 1.84.4.2 nathanw if (real_bps != bps)
698 1.84.4.2 nathanw return (EINVAL);
699 1.84.4.2 nathanw
700 1.84.4.2 nathanw cs->cs_preg[12] = tconst;
701 1.84.4.2 nathanw cs->cs_preg[13] = tconst >> 8;
702 1.84.4.2 nathanw
703 1.84.4.2 nathanw /* Caller will stuff the pending registers. */
704 1.84.4.2 nathanw return (0);
705 1.84.4.2 nathanw }
706 1.84.4.2 nathanw
707 1.84.4.2 nathanw int
708 1.84.4.2 nathanw zs_set_modes(cs, cflag)
709 1.84.4.2 nathanw struct zs_chanstate *cs;
710 1.84.4.2 nathanw int cflag; /* bits per second */
711 1.84.4.2 nathanw {
712 1.84.4.2 nathanw int s;
713 1.84.4.2 nathanw
714 1.84.4.2 nathanw /*
715 1.84.4.2 nathanw * Output hardware flow control on the chip is horrendous:
716 1.84.4.2 nathanw * if carrier detect drops, the receiver is disabled, and if
717 1.84.4.2 nathanw * CTS drops, the transmitter is stoped IN MID CHARACTER!
718 1.84.4.2 nathanw * Therefore, NEVER set the HFC bit, and instead use the
719 1.84.4.2 nathanw * status interrupt to detect CTS changes.
720 1.84.4.2 nathanw */
721 1.84.4.2 nathanw s = splzs();
722 1.84.4.2 nathanw cs->cs_rr0_pps = 0;
723 1.84.4.2 nathanw if ((cflag & (CLOCAL | MDMBUF)) != 0) {
724 1.84.4.2 nathanw cs->cs_rr0_dcd = 0;
725 1.84.4.2 nathanw if ((cflag & MDMBUF) == 0)
726 1.84.4.2 nathanw cs->cs_rr0_pps = ZSRR0_DCD;
727 1.84.4.2 nathanw } else
728 1.84.4.2 nathanw cs->cs_rr0_dcd = ZSRR0_DCD;
729 1.84.4.2 nathanw if ((cflag & CRTSCTS) != 0) {
730 1.84.4.2 nathanw cs->cs_wr5_dtr = ZSWR5_DTR;
731 1.84.4.2 nathanw cs->cs_wr5_rts = ZSWR5_RTS;
732 1.84.4.2 nathanw cs->cs_rr0_cts = ZSRR0_CTS;
733 1.84.4.2 nathanw } else if ((cflag & CDTRCTS) != 0) {
734 1.84.4.2 nathanw cs->cs_wr5_dtr = 0;
735 1.84.4.2 nathanw cs->cs_wr5_rts = ZSWR5_DTR;
736 1.84.4.2 nathanw cs->cs_rr0_cts = ZSRR0_CTS;
737 1.84.4.2 nathanw } else if ((cflag & MDMBUF) != 0) {
738 1.84.4.2 nathanw cs->cs_wr5_dtr = 0;
739 1.84.4.2 nathanw cs->cs_wr5_rts = ZSWR5_DTR;
740 1.84.4.2 nathanw cs->cs_rr0_cts = ZSRR0_DCD;
741 1.84.4.2 nathanw } else {
742 1.84.4.2 nathanw cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
743 1.84.4.2 nathanw cs->cs_wr5_rts = 0;
744 1.84.4.2 nathanw cs->cs_rr0_cts = 0;
745 1.84.4.2 nathanw }
746 1.84.4.2 nathanw splx(s);
747 1.84.4.2 nathanw
748 1.84.4.2 nathanw /* Caller will stuff the pending registers. */
749 1.84.4.2 nathanw return (0);
750 1.84.4.2 nathanw }
751 1.84.4.2 nathanw
752 1.84.4.2 nathanw
753 1.84.4.2 nathanw /*
754 1.84.4.2 nathanw * Read or write the chip with suitable delays.
755 1.84.4.2 nathanw */
756 1.84.4.2 nathanw
757 1.84.4.2 nathanw u_char
758 1.84.4.2 nathanw zs_read_reg(cs, reg)
759 1.84.4.2 nathanw struct zs_chanstate *cs;
760 1.84.4.2 nathanw u_char reg;
761 1.84.4.2 nathanw {
762 1.84.4.2 nathanw u_char val;
763 1.84.4.2 nathanw
764 1.84.4.2 nathanw *cs->cs_reg_csr = reg;
765 1.84.4.2 nathanw ZS_DELAY();
766 1.84.4.2 nathanw val = *cs->cs_reg_csr;
767 1.84.4.2 nathanw ZS_DELAY();
768 1.84.4.2 nathanw return (val);
769 1.84.4.2 nathanw }
770 1.84.4.2 nathanw
771 1.84.4.2 nathanw void
772 1.84.4.2 nathanw zs_write_reg(cs, reg, val)
773 1.84.4.2 nathanw struct zs_chanstate *cs;
774 1.84.4.2 nathanw u_char reg, val;
775 1.84.4.2 nathanw {
776 1.84.4.2 nathanw *cs->cs_reg_csr = reg;
777 1.84.4.2 nathanw ZS_DELAY();
778 1.84.4.2 nathanw *cs->cs_reg_csr = val;
779 1.84.4.2 nathanw ZS_DELAY();
780 1.84.4.2 nathanw }
781 1.84.4.2 nathanw
782 1.84.4.2 nathanw u_char
783 1.84.4.2 nathanw zs_read_csr(cs)
784 1.84.4.2 nathanw struct zs_chanstate *cs;
785 1.84.4.2 nathanw {
786 1.84.4.2 nathanw u_char val;
787 1.84.4.2 nathanw
788 1.84.4.2 nathanw val = *cs->cs_reg_csr;
789 1.84.4.2 nathanw ZS_DELAY();
790 1.84.4.2 nathanw return (val);
791 1.84.4.2 nathanw }
792 1.84.4.2 nathanw
793 1.84.4.2 nathanw void
794 1.84.4.2 nathanw zs_write_csr(cs, val)
795 1.84.4.2 nathanw struct zs_chanstate *cs;
796 1.84.4.2 nathanw u_char val;
797 1.84.4.2 nathanw {
798 1.84.4.2 nathanw *cs->cs_reg_csr = val;
799 1.84.4.2 nathanw ZS_DELAY();
800 1.84.4.2 nathanw }
801 1.84.4.2 nathanw
802 1.84.4.2 nathanw u_char
803 1.84.4.2 nathanw zs_read_data(cs)
804 1.84.4.2 nathanw struct zs_chanstate *cs;
805 1.84.4.2 nathanw {
806 1.84.4.2 nathanw u_char val;
807 1.84.4.2 nathanw
808 1.84.4.2 nathanw val = *cs->cs_reg_data;
809 1.84.4.2 nathanw ZS_DELAY();
810 1.84.4.2 nathanw return (val);
811 1.84.4.2 nathanw }
812 1.84.4.2 nathanw
813 1.84.4.2 nathanw void zs_write_data(cs, val)
814 1.84.4.2 nathanw struct zs_chanstate *cs;
815 1.84.4.2 nathanw u_char val;
816 1.84.4.2 nathanw {
817 1.84.4.2 nathanw *cs->cs_reg_data = val;
818 1.84.4.2 nathanw ZS_DELAY();
819 1.84.4.2 nathanw }
820 1.84.4.2 nathanw
821 1.84.4.2 nathanw /****************************************************************
822 1.84.4.2 nathanw * Console support functions (Sun specific!)
823 1.84.4.2 nathanw * Note: this code is allowed to know about the layout of
824 1.84.4.2 nathanw * the chip registers, and uses that to keep things simple.
825 1.84.4.2 nathanw * XXX - I think I like the mvme167 code better. -gwr
826 1.84.4.2 nathanw ****************************************************************/
827 1.84.4.2 nathanw
828 1.84.4.2 nathanw /*
829 1.84.4.2 nathanw * Handle user request to enter kernel debugger.
830 1.84.4.2 nathanw */
831 1.84.4.2 nathanw void
832 1.84.4.2 nathanw zs_abort(cs)
833 1.84.4.2 nathanw struct zs_chanstate *cs;
834 1.84.4.2 nathanw {
835 1.84.4.2 nathanw struct zschan *zc = zs_conschan_get;
836 1.84.4.2 nathanw int rr0;
837 1.84.4.2 nathanw
838 1.84.4.2 nathanw /* Wait for end of break to avoid PROM abort. */
839 1.84.4.2 nathanw /* XXX - Limit the wait? */
840 1.84.4.2 nathanw do {
841 1.84.4.2 nathanw rr0 = zc->zc_csr;
842 1.84.4.2 nathanw ZS_DELAY();
843 1.84.4.2 nathanw } while (rr0 & ZSRR0_BREAK);
844 1.84.4.2 nathanw
845 1.84.4.2 nathanw #if defined(KGDB)
846 1.84.4.2 nathanw zskgdb(cs);
847 1.84.4.2 nathanw #elif defined(DDB)
848 1.84.4.2 nathanw Debugger();
849 1.84.4.2 nathanw #else
850 1.84.4.2 nathanw printf("stopping on keyboard abort\n");
851 1.84.4.2 nathanw callrom();
852 1.84.4.2 nathanw #endif
853 1.84.4.2 nathanw }
854 1.84.4.2 nathanw
855 1.84.4.2 nathanw int zs_getc __P((void *arg));
856 1.84.4.2 nathanw void zs_putc __P((void *arg, int c));
857 1.84.4.2 nathanw
858 1.84.4.2 nathanw /*
859 1.84.4.2 nathanw * Polled input char.
860 1.84.4.2 nathanw */
861 1.84.4.2 nathanw int
862 1.84.4.2 nathanw zs_getc(arg)
863 1.84.4.2 nathanw void *arg;
864 1.84.4.2 nathanw {
865 1.84.4.2 nathanw struct zschan *zc = arg;
866 1.84.4.2 nathanw int s, c, rr0;
867 1.84.4.2 nathanw
868 1.84.4.2 nathanw s = splhigh();
869 1.84.4.2 nathanw /* Wait for a character to arrive. */
870 1.84.4.2 nathanw do {
871 1.84.4.2 nathanw rr0 = zc->zc_csr;
872 1.84.4.2 nathanw ZS_DELAY();
873 1.84.4.2 nathanw } while ((rr0 & ZSRR0_RX_READY) == 0);
874 1.84.4.2 nathanw
875 1.84.4.2 nathanw c = zc->zc_data;
876 1.84.4.2 nathanw ZS_DELAY();
877 1.84.4.2 nathanw splx(s);
878 1.84.4.2 nathanw
879 1.84.4.2 nathanw /*
880 1.84.4.2 nathanw * This is used by the kd driver to read scan codes,
881 1.84.4.2 nathanw * so don't translate '\r' ==> '\n' here...
882 1.84.4.2 nathanw */
883 1.84.4.2 nathanw return (c);
884 1.84.4.2 nathanw }
885 1.84.4.2 nathanw
886 1.84.4.2 nathanw /*
887 1.84.4.2 nathanw * Polled output char.
888 1.84.4.2 nathanw */
889 1.84.4.2 nathanw void
890 1.84.4.2 nathanw zs_putc(arg, c)
891 1.84.4.2 nathanw void *arg;
892 1.84.4.2 nathanw int c;
893 1.84.4.2 nathanw {
894 1.84.4.2 nathanw struct zschan *zc = arg;
895 1.84.4.2 nathanw int s, rr0;
896 1.84.4.2 nathanw
897 1.84.4.2 nathanw s = splhigh();
898 1.84.4.2 nathanw
899 1.84.4.2 nathanw /* Wait for transmitter to become ready. */
900 1.84.4.2 nathanw do {
901 1.84.4.2 nathanw rr0 = zc->zc_csr;
902 1.84.4.2 nathanw ZS_DELAY();
903 1.84.4.2 nathanw } while ((rr0 & ZSRR0_TX_READY) == 0);
904 1.84.4.2 nathanw
905 1.84.4.2 nathanw /*
906 1.84.4.2 nathanw * Send the next character.
907 1.84.4.2 nathanw * Now you'd think that this could be followed by a ZS_DELAY()
908 1.84.4.2 nathanw * just like all the other chip accesses, but it turns out that
909 1.84.4.2 nathanw * the `transmit-ready' interrupt isn't de-asserted until
910 1.84.4.2 nathanw * some period of time after the register write completes
911 1.84.4.2 nathanw * (more than a couple instructions). So to avoid stray
912 1.84.4.2 nathanw * interrupts we put in the 2us delay regardless of cpu model.
913 1.84.4.2 nathanw */
914 1.84.4.2 nathanw zc->zc_data = c;
915 1.84.4.2 nathanw delay(2);
916 1.84.4.2 nathanw
917 1.84.4.2 nathanw splx(s);
918 1.84.4.2 nathanw }
919 1.84.4.2 nathanw
920 1.84.4.2 nathanw /*****************************************************************/
921 1.84.4.2 nathanw /*
922 1.84.4.2 nathanw * Polled console input putchar.
923 1.84.4.2 nathanw */
924 1.84.4.2 nathanw int
925 1.84.4.2 nathanw zscngetc(dev)
926 1.84.4.2 nathanw dev_t dev;
927 1.84.4.2 nathanw {
928 1.84.4.2 nathanw return (zs_getc(zs_conschan_get));
929 1.84.4.2 nathanw }
930 1.84.4.2 nathanw
931 1.84.4.2 nathanw /*
932 1.84.4.2 nathanw * Polled console output putchar.
933 1.84.4.2 nathanw */
934 1.84.4.2 nathanw void
935 1.84.4.2 nathanw zscnputc(dev, c)
936 1.84.4.2 nathanw dev_t dev;
937 1.84.4.2 nathanw int c;
938 1.84.4.2 nathanw {
939 1.84.4.2 nathanw zs_putc(zs_conschan_put, c);
940 1.84.4.2 nathanw }
941 1.84.4.2 nathanw
942 1.84.4.2 nathanw void
943 1.84.4.2 nathanw zscnpollc(dev, on)
944 1.84.4.2 nathanw dev_t dev;
945 1.84.4.2 nathanw int on;
946 1.84.4.2 nathanw {
947 1.84.4.2 nathanw /* No action needed */
948 1.84.4.2 nathanw }
949 1.84.4.2 nathanw
950 1.84.4.2 nathanw int
951 1.84.4.2 nathanw zs_console_flags(promunit, node, channel)
952 1.84.4.2 nathanw int promunit;
953 1.84.4.2 nathanw int node;
954 1.84.4.2 nathanw int channel;
955 1.84.4.2 nathanw {
956 1.84.4.2 nathanw int cookie, flags = 0;
957 1.84.4.2 nathanw
958 1.84.4.2 nathanw switch (prom_version()) {
959 1.84.4.2 nathanw case PROM_OLDMON:
960 1.84.4.2 nathanw case PROM_OBP_V0:
961 1.84.4.2 nathanw /*
962 1.84.4.2 nathanw * Use `promunit' and `channel' to derive the PROM
963 1.84.4.2 nathanw * stdio handles that correspond to this device.
964 1.84.4.2 nathanw */
965 1.84.4.2 nathanw if (promunit == 0)
966 1.84.4.2 nathanw cookie = PROMDEV_TTYA + channel;
967 1.84.4.2 nathanw else if (promunit == 1 && channel == 0)
968 1.84.4.2 nathanw cookie = PROMDEV_KBD;
969 1.84.4.2 nathanw else
970 1.84.4.2 nathanw cookie = -1;
971 1.84.4.2 nathanw
972 1.84.4.2 nathanw if (cookie == prom_stdin())
973 1.84.4.2 nathanw flags |= ZS_HWFLAG_CONSOLE_INPUT;
974 1.84.4.2 nathanw
975 1.84.4.2 nathanw /*
976 1.84.4.2 nathanw * Prevent the keyboard from matching the output device
977 1.84.4.2 nathanw * (note that PROMDEV_KBD == PROMDEV_SCREEN == 0!).
978 1.84.4.2 nathanw */
979 1.84.4.2 nathanw if (cookie != PROMDEV_KBD && cookie == prom_stdout())
980 1.84.4.2 nathanw flags |= ZS_HWFLAG_CONSOLE_OUTPUT;
981 1.84.4.2 nathanw
982 1.84.4.2 nathanw break;
983 1.84.4.2 nathanw
984 1.84.4.2 nathanw case PROM_OBP_V2:
985 1.84.4.2 nathanw case PROM_OBP_V3:
986 1.84.4.2 nathanw case PROM_OPENFIRM:
987 1.84.4.2 nathanw
988 1.84.4.2 nathanw /*
989 1.84.4.2 nathanw * Match the nodes and device arguments prepared by
990 1.84.4.2 nathanw * consinit() against our device node and channel.
991 1.84.4.2 nathanw * (The device argument is the part of the OBP path
992 1.84.4.2 nathanw * following the colon, as in `/obio/zs@0,100000:a')
993 1.84.4.2 nathanw */
994 1.84.4.2 nathanw
995 1.84.4.2 nathanw /* Default to channel 0 if there are no explicit prom args */
996 1.84.4.2 nathanw cookie = 0;
997 1.84.4.2 nathanw
998 1.84.4.2 nathanw if (node == prom_stdin_node) {
999 1.84.4.2 nathanw if (prom_stdin_args[0] != '\0')
1000 1.84.4.2 nathanw /* Translate (a,b) -> (0,1) */
1001 1.84.4.2 nathanw cookie = prom_stdin_args[0] - 'a';
1002 1.84.4.2 nathanw
1003 1.84.4.2 nathanw if (channel == cookie)
1004 1.84.4.2 nathanw flags |= ZS_HWFLAG_CONSOLE_INPUT;
1005 1.84.4.2 nathanw }
1006 1.84.4.2 nathanw
1007 1.84.4.2 nathanw if (node == prom_stdout_node) {
1008 1.84.4.2 nathanw if (prom_stdout_args[0] != '\0')
1009 1.84.4.2 nathanw /* Translate (a,b) -> (0,1) */
1010 1.84.4.2 nathanw cookie = prom_stdout_args[0] - 'a';
1011 1.84.4.2 nathanw
1012 1.84.4.2 nathanw if (channel == cookie)
1013 1.84.4.2 nathanw flags |= ZS_HWFLAG_CONSOLE_OUTPUT;
1014 1.84.4.2 nathanw }
1015 1.84.4.2 nathanw
1016 1.84.4.2 nathanw break;
1017 1.84.4.2 nathanw
1018 1.84.4.2 nathanw default:
1019 1.84.4.2 nathanw break;
1020 1.84.4.2 nathanw }
1021 1.84.4.2 nathanw
1022 1.84.4.2 nathanw return (flags);
1023 1.84.4.2 nathanw }
1024 1.84.4.2 nathanw
1025 1.84.4.2 nathanw /*
1026 1.84.4.2 nathanw * Power management hooks for zsopen() and zsclose().
1027 1.84.4.2 nathanw * We use them to power on/off the ports, if necessary.
1028 1.84.4.2 nathanw */
1029 1.84.4.2 nathanw int
1030 1.84.4.2 nathanw zs_enable(cs)
1031 1.84.4.2 nathanw struct zs_chanstate *cs;
1032 1.84.4.2 nathanw {
1033 1.84.4.2 nathanw auxiotwoserialendis (ZS_ENABLE);
1034 1.84.4.2 nathanw cs->enabled = 1;
1035 1.84.4.2 nathanw return(0);
1036 1.84.4.2 nathanw }
1037 1.84.4.2 nathanw
1038 1.84.4.2 nathanw void
1039 1.84.4.2 nathanw zs_disable(cs)
1040 1.84.4.2 nathanw struct zs_chanstate *cs;
1041 1.84.4.2 nathanw {
1042 1.84.4.2 nathanw auxiotwoserialendis (ZS_DISABLE);
1043 1.84.4.2 nathanw cs->enabled = 0;
1044 1.84.4.2 nathanw }
1045