zs.c revision 1.65.4.1 1 1.65.4.1 yamt /* $NetBSD: zs.c,v 1.65.4.1 2008/05/16 02:23:15 yamt Exp $ */
2 1.1 eeh
3 1.1 eeh /*-
4 1.1 eeh * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 1.1 eeh * All rights reserved.
6 1.1 eeh *
7 1.1 eeh * This code is derived from software contributed to The NetBSD Foundation
8 1.1 eeh * by Gordon W. Ross.
9 1.1 eeh *
10 1.1 eeh * Redistribution and use in source and binary forms, with or without
11 1.1 eeh * modification, are permitted provided that the following conditions
12 1.1 eeh * are met:
13 1.1 eeh * 1. Redistributions of source code must retain the above copyright
14 1.1 eeh * notice, this list of conditions and the following disclaimer.
15 1.1 eeh * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 eeh * notice, this list of conditions and the following disclaimer in the
17 1.1 eeh * documentation and/or other materials provided with the distribution.
18 1.1 eeh *
19 1.1 eeh * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 eeh * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 eeh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 eeh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 eeh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 eeh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 eeh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 eeh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 eeh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 eeh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 eeh * POSSIBILITY OF SUCH DAMAGE.
30 1.1 eeh */
31 1.1 eeh
32 1.1 eeh /*
33 1.1 eeh * Zilog Z8530 Dual UART driver (machine-dependent part)
34 1.1 eeh *
35 1.1 eeh * Runs two serial lines per chip using slave drivers.
36 1.1 eeh * Plain tty/async lines use the zs_async slave.
37 1.1 eeh * Sun keyboard/mouse uses the zs_kbd/zs_ms slaves.
38 1.1 eeh */
39 1.47 lukem
40 1.47 lukem #include <sys/cdefs.h>
41 1.65.4.1 yamt __KERNEL_RCSID(0, "$NetBSD: zs.c,v 1.65.4.1 2008/05/16 02:23:15 yamt Exp $");
42 1.2 jonathan
43 1.2 jonathan #include "opt_ddb.h"
44 1.29 lukem #include "opt_kgdb.h"
45 1.1 eeh
46 1.1 eeh #include <sys/param.h>
47 1.1 eeh #include <sys/systm.h>
48 1.1 eeh #include <sys/conf.h>
49 1.1 eeh #include <sys/device.h>
50 1.1 eeh #include <sys/file.h>
51 1.1 eeh #include <sys/ioctl.h>
52 1.1 eeh #include <sys/kernel.h>
53 1.1 eeh #include <sys/proc.h>
54 1.1 eeh #include <sys/tty.h>
55 1.1 eeh #include <sys/time.h>
56 1.1 eeh #include <sys/syslog.h>
57 1.64 ad #include <sys/intr.h>
58 1.1 eeh
59 1.1 eeh #include <machine/autoconf.h>
60 1.1 eeh #include <machine/openfirm.h>
61 1.1 eeh #include <machine/cpu.h>
62 1.1 eeh #include <machine/eeprom.h>
63 1.1 eeh #include <machine/psl.h>
64 1.1 eeh #include <machine/z8530var.h>
65 1.1 eeh
66 1.1 eeh #include <dev/cons.h>
67 1.1 eeh #include <dev/ic/z8530reg.h>
68 1.26 eeh #include <dev/sun/kbd_ms_ttyvar.h>
69 1.16 mrg #include <ddb/db_output.h>
70 1.1 eeh
71 1.1 eeh #include <sparc64/dev/cons.h>
72 1.1 eeh
73 1.65 tsutsui #include "ioconf.h"
74 1.1 eeh #include "kbd.h" /* NKBD */
75 1.26 eeh #include "ms.h" /* NMS */
76 1.1 eeh #include "zs.h" /* NZS */
77 1.1 eeh
78 1.1 eeh /* Make life easier for the initialized arrays here. */
79 1.1 eeh #if NZS < 3
80 1.1 eeh #undef NZS
81 1.1 eeh #define NZS 3
82 1.1 eeh #endif
83 1.1 eeh
84 1.1 eeh /*
85 1.1 eeh * Some warts needed by z8530tty.c -
86 1.1 eeh * The default parity REALLY needs to be the same as the PROM uses,
87 1.1 eeh * or you can not see messages done with printf during boot-up...
88 1.1 eeh */
89 1.1 eeh int zs_def_cflag = (CREAD | CS8 | HUPCL);
90 1.1 eeh
91 1.1 eeh /*
92 1.1 eeh * The Sun provides a 4.9152 MHz clock to the ZS chips.
93 1.1 eeh */
94 1.1 eeh #define PCLK (9600 * 512) /* PCLK pin input clock rate */
95 1.1 eeh
96 1.10 eeh #define ZS_DELAY()
97 1.1 eeh
98 1.1 eeh /* The layout of this is hardware-dependent (padding, order). */
99 1.1 eeh struct zschan {
100 1.65 tsutsui volatile uint8_t zc_csr; /* ctrl,status, and indirect access */
101 1.65 tsutsui uint8_t zc_xxx0;
102 1.65 tsutsui volatile uint8_t zc_data; /* data */
103 1.65 tsutsui uint8_t zc_xxx1;
104 1.1 eeh };
105 1.1 eeh struct zsdevice {
106 1.1 eeh /* Yes, they are backwards. */
107 1.1 eeh struct zschan zs_chan_b;
108 1.1 eeh struct zschan zs_chan_a;
109 1.1 eeh };
110 1.1 eeh
111 1.20 eeh /* ZS channel used as the console device (if any) */
112 1.20 eeh void *zs_conschan_get, *zs_conschan_put;
113 1.20 eeh
114 1.1 eeh /* Saved PROM mappings */
115 1.1 eeh static struct zsdevice *zsaddr[NZS];
116 1.1 eeh
117 1.65 tsutsui static uint8_t zs_init_reg[16] = {
118 1.1 eeh 0, /* 0: CMD (reset, etc.) */
119 1.1 eeh 0, /* 1: No interrupts yet. */
120 1.1 eeh 0, /* 2: IVECT */
121 1.1 eeh ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
122 1.1 eeh ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
123 1.1 eeh ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
124 1.1 eeh 0, /* 6: TXSYNC/SYNCLO */
125 1.1 eeh 0, /* 7: RXSYNC/SYNCHI */
126 1.1 eeh 0, /* 8: alias for data port */
127 1.1 eeh ZSWR9_MASTER_IE | ZSWR9_NO_VECTOR,
128 1.1 eeh 0, /*10: Misc. TX/RX control bits */
129 1.1 eeh ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
130 1.7 mycroft ((PCLK/32)/9600)-2, /*12: BAUDLO (default=9600) */
131 1.7 mycroft 0, /*13: BAUDHI (default=9600) */
132 1.1 eeh ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK,
133 1.6 mycroft ZSWR15_BREAK_IE,
134 1.1 eeh };
135 1.1 eeh
136 1.20 eeh /* Console ops */
137 1.57 cdi static int zscngetc(dev_t);
138 1.57 cdi static void zscnputc(dev_t, int);
139 1.57 cdi static void zscnpollc(dev_t, int);
140 1.20 eeh
141 1.20 eeh struct consdev zs_consdev = {
142 1.62 martin .cn_getc = zscngetc,
143 1.62 martin .cn_putc = zscnputc,
144 1.62 martin .cn_pollc = zscnpollc,
145 1.20 eeh };
146 1.1 eeh
147 1.1 eeh
148 1.1 eeh /****************************************************************
149 1.1 eeh * Autoconfig
150 1.1 eeh ****************************************************************/
151 1.1 eeh
152 1.1 eeh /* Definition of the driver for autoconfig. */
153 1.65 tsutsui static int zs_match_sbus(device_t, cfdata_t, void *);
154 1.65 tsutsui static void zs_attach_sbus(device_t, device_t, void *);
155 1.1 eeh
156 1.57 cdi static void zs_attach(struct zsc_softc *, struct zsdevice *, int);
157 1.57 cdi static int zs_print(void *, const char *);
158 1.1 eeh
159 1.65 tsutsui CFATTACH_DECL_NEW(zs, sizeof(struct zsc_softc),
160 1.48 petrov zs_match_sbus, zs_attach_sbus, NULL, NULL);
161 1.1 eeh
162 1.1 eeh /* Interrupt handlers. */
163 1.57 cdi int zscheckintr(void *);
164 1.57 cdi static int zshard(void *);
165 1.57 cdi static void zssoft(void *);
166 1.1 eeh
167 1.57 cdi static int zs_get_speed(struct zs_chanstate *);
168 1.1 eeh
169 1.20 eeh /* Console device support */
170 1.57 cdi static int zs_console_flags(int, int, int);
171 1.20 eeh
172 1.20 eeh /* Power management hooks */
173 1.57 cdi int zs_enable(struct zs_chanstate *);
174 1.57 cdi void zs_disable(struct zs_chanstate *);
175 1.1 eeh
176 1.55 macallan /* from dev/ic/z8530tty.c */
177 1.55 macallan struct tty *zstty_get_tty_from_dev(struct device *);
178 1.55 macallan
179 1.1 eeh /*
180 1.1 eeh * Is the zs chip present?
181 1.1 eeh */
182 1.1 eeh static int
183 1.65 tsutsui zs_match_sbus(device_t parent, cfdata_t cf, void *aux)
184 1.1 eeh {
185 1.1 eeh struct sbus_attach_args *sa = aux;
186 1.1 eeh
187 1.39 thorpej if (strcmp(cf->cf_name, sa->sa_name) != 0)
188 1.1 eeh return (0);
189 1.1 eeh
190 1.20 eeh return (1);
191 1.1 eeh }
192 1.1 eeh
193 1.1 eeh static void
194 1.65 tsutsui zs_attach_sbus(device_t parent, device_t self, void *aux)
195 1.1 eeh {
196 1.65 tsutsui struct zsc_softc *zsc = device_private(self);
197 1.1 eeh struct sbus_attach_args *sa = aux;
198 1.33 eeh bus_space_handle_t bh;
199 1.65 tsutsui int zs_unit;
200 1.65 tsutsui
201 1.65 tsutsui zsc->zsc_dev = self;
202 1.65 tsutsui zs_unit = device_unit(self);
203 1.1 eeh
204 1.20 eeh if (sa->sa_nintr == 0) {
205 1.65 tsutsui aprint_error(": no interrupt lines\n");
206 1.20 eeh return;
207 1.20 eeh }
208 1.1 eeh
209 1.33 eeh /* Use the mapping setup by the Sun PROM if possible. */
210 1.10 eeh if (zsaddr[zs_unit] == NULL) {
211 1.20 eeh /* Only map registers once. */
212 1.10 eeh if (sa->sa_npromvaddrs) {
213 1.10 eeh /*
214 1.10 eeh * We're converting from a 32-bit pointer to a 64-bit
215 1.10 eeh * pointer. Since the 32-bit entity is negative, but
216 1.10 eeh * the kernel is still mapped into the lower 4GB
217 1.10 eeh * range, this needs to be zero-extended.
218 1.10 eeh *
219 1.10 eeh * XXXXX If we map the kernel and devices into the
220 1.10 eeh * high 4GB range, this needs to be changed to
221 1.10 eeh * sign-extend the address.
222 1.10 eeh */
223 1.33 eeh sparc_promaddr_to_handle(sa->sa_bustag,
224 1.34 eeh sa->sa_promvaddrs[0], &bh);
225 1.33 eeh
226 1.10 eeh } else {
227 1.10 eeh
228 1.10 eeh if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
229 1.10 eeh sa->sa_offset,
230 1.10 eeh sa->sa_size,
231 1.10 eeh BUS_SPACE_MAP_LINEAR,
232 1.33 eeh &bh) != 0) {
233 1.65 tsutsui aprint_error(": cannot map registers\n");
234 1.10 eeh return;
235 1.10 eeh }
236 1.10 eeh }
237 1.65 tsutsui zsaddr[zs_unit] = bus_space_vaddr(sa->sa_bustag, bh);
238 1.10 eeh }
239 1.20 eeh zsc->zsc_bustag = sa->sa_bustag;
240 1.20 eeh zsc->zsc_dmatag = sa->sa_dmatag;
241 1.51 pk zsc->zsc_promunit = prom_getpropint(sa->sa_node, "slave", -2);
242 1.20 eeh zsc->zsc_node = sa->sa_node;
243 1.20 eeh zs_attach(zsc, zsaddr[zs_unit], sa->sa_pri);
244 1.1 eeh }
245 1.1 eeh
246 1.1 eeh /*
247 1.1 eeh * Attach a found zs.
248 1.1 eeh *
249 1.1 eeh * USE ROM PROPERTIES port-a-ignore-cd AND port-b-ignore-cd FOR
250 1.1 eeh * SOFT CARRIER, AND keyboard PROPERTY FOR KEYBOARD/MOUSE?
251 1.1 eeh */
252 1.1 eeh static void
253 1.57 cdi zs_attach(struct zsc_softc *zsc, struct zsdevice *zsd, int pri)
254 1.1 eeh {
255 1.1 eeh struct zsc_attach_args zsc_args;
256 1.1 eeh struct zs_chanstate *cs;
257 1.64 ad int s, channel;
258 1.20 eeh
259 1.20 eeh if (zsd == NULL) {
260 1.65 tsutsui aprint_error(": configuration incomplete\n");
261 1.20 eeh return;
262 1.20 eeh }
263 1.1 eeh
264 1.1 eeh /*
265 1.1 eeh * Initialize software state for each channel.
266 1.1 eeh */
267 1.1 eeh for (channel = 0; channel < 2; channel++) {
268 1.20 eeh struct zschan *zc;
269 1.26 eeh struct device *child;
270 1.20 eeh
271 1.1 eeh zsc_args.channel = channel;
272 1.1 eeh cs = &zsc->zsc_cs_store[channel];
273 1.1 eeh zsc->zsc_cs[channel] = cs;
274 1.1 eeh
275 1.63 ad zs_lock_init(cs);
276 1.1 eeh cs->cs_channel = channel;
277 1.1 eeh cs->cs_private = NULL;
278 1.1 eeh cs->cs_ops = &zsops_null;
279 1.1 eeh cs->cs_brg_clk = PCLK / 16;
280 1.1 eeh
281 1.20 eeh zc = (channel == 0) ? &zsd->zs_chan_a : &zsd->zs_chan_b;
282 1.20 eeh
283 1.26 eeh zsc_args.consdev = NULL;
284 1.20 eeh zsc_args.hwflags = zs_console_flags(zsc->zsc_promunit,
285 1.20 eeh zsc->zsc_node,
286 1.20 eeh channel);
287 1.20 eeh
288 1.20 eeh if (zsc_args.hwflags & ZS_HWFLAG_CONSOLE) {
289 1.20 eeh zsc_args.hwflags |= ZS_HWFLAG_USE_CONSDEV;
290 1.20 eeh zsc_args.consdev = &zs_consdev;
291 1.11 eeh }
292 1.20 eeh
293 1.20 eeh if ((zsc_args.hwflags & ZS_HWFLAG_CONSOLE_INPUT) != 0) {
294 1.20 eeh zs_conschan_get = zc;
295 1.20 eeh }
296 1.20 eeh if ((zsc_args.hwflags & ZS_HWFLAG_CONSOLE_OUTPUT) != 0) {
297 1.20 eeh zs_conschan_put = zc;
298 1.20 eeh }
299 1.20 eeh
300 1.31 eeh /* Children need to set cn_dev, etc */
301 1.1 eeh cs->cs_reg_csr = &zc->zc_csr;
302 1.1 eeh cs->cs_reg_data = &zc->zc_data;
303 1.1 eeh
304 1.49 martin memcpy(cs->cs_creg, zs_init_reg, 16);
305 1.49 martin memcpy(cs->cs_preg, zs_init_reg, 16);
306 1.1 eeh
307 1.20 eeh /* XXX: Consult PROM properties for this?! */
308 1.20 eeh cs->cs_defspeed = zs_get_speed(cs);
309 1.1 eeh cs->cs_defcflag = zs_def_cflag;
310 1.1 eeh
311 1.1 eeh /* Make these correspond to cs_defcflag (-crtscts) */
312 1.1 eeh cs->cs_rr0_dcd = ZSRR0_DCD;
313 1.1 eeh cs->cs_rr0_cts = 0;
314 1.1 eeh cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
315 1.1 eeh cs->cs_wr5_rts = 0;
316 1.1 eeh
317 1.1 eeh /*
318 1.1 eeh * Clear the master interrupt enable.
319 1.1 eeh * The INTENA is common to both channels,
320 1.1 eeh * so just do it on the A channel.
321 1.1 eeh */
322 1.1 eeh if (channel == 0) {
323 1.1 eeh zs_write_reg(cs, 9, 0);
324 1.1 eeh }
325 1.1 eeh
326 1.1 eeh /*
327 1.1 eeh * Look for a child driver for this channel.
328 1.1 eeh * The child attach will setup the hardware.
329 1.1 eeh */
330 1.65 tsutsui child = config_found(zsc->zsc_dev, (void *)&zsc_args,
331 1.55 macallan zs_print);
332 1.55 macallan if (child == NULL) {
333 1.1 eeh /* No sub-driver. Just reset it. */
334 1.65 tsutsui uint8_t reset = (channel == 0) ?
335 1.1 eeh ZSWR9_A_RESET : ZSWR9_B_RESET;
336 1.1 eeh s = splzs();
337 1.1 eeh zs_write_reg(cs, 9, reset);
338 1.1 eeh splx(s);
339 1.26 eeh }
340 1.26 eeh #if (NKBD > 0) || (NMS > 0)
341 1.26 eeh /*
342 1.26 eeh * If this was a zstty it has a keyboard
343 1.26 eeh * property on it we need to attach the
344 1.26 eeh * sunkbd and sunms line disciplines.
345 1.26 eeh */
346 1.26 eeh if (child
347 1.60 thorpej && (device_is_a(child, "zstty"))
348 1.51 pk && (prom_getproplen(zsc->zsc_node, "keyboard") == 0)) {
349 1.26 eeh struct kbd_ms_tty_attach_args kma;
350 1.26 eeh struct tty *tp;
351 1.26 eeh
352 1.55 macallan kma.kmta_tp = tp = zstty_get_tty_from_dev(child);
353 1.26 eeh kma.kmta_dev = tp->t_dev;
354 1.26 eeh kma.kmta_consdev = zsc_args.consdev;
355 1.26 eeh
356 1.26 eeh /* Attach 'em if we got 'em. */
357 1.26 eeh #if (NKBD > 0)
358 1.26 eeh if (channel == 0) {
359 1.26 eeh kma.kmta_name = "keyboard";
360 1.26 eeh config_found(child, (void *)&kma, NULL);
361 1.26 eeh }
362 1.26 eeh #endif
363 1.26 eeh #if (NMS > 0)
364 1.26 eeh if (channel == 1) {
365 1.26 eeh kma.kmta_name = "mouse";
366 1.26 eeh config_found(child, (void *)&kma, NULL);
367 1.26 eeh }
368 1.26 eeh #endif
369 1.1 eeh }
370 1.26 eeh #endif
371 1.1 eeh }
372 1.1 eeh
373 1.1 eeh /*
374 1.1 eeh * Now safe to install interrupt handlers. Note the arguments
375 1.1 eeh * to the interrupt handlers aren't used. Note, we only do this
376 1.1 eeh * once since both SCCs interrupt at the same level and vector.
377 1.1 eeh */
378 1.44 pk bus_intr_establish(zsc->zsc_bustag, pri, IPL_SERIAL, zshard, zsc);
379 1.64 ad if (!(zsc->zsc_softintr = softint_establish(SOFTINT_SERIAL, zssoft, zsc)))
380 1.40 provos panic("zsattach: could not establish soft interrupt");
381 1.1 eeh
382 1.21 cgd evcnt_attach_dynamic(&zsc->zsc_intrcnt, EVCNT_TYPE_INTR, NULL,
383 1.65 tsutsui device_xname(zsc->zsc_dev), "intr");
384 1.1 eeh
385 1.24 eeh
386 1.1 eeh /*
387 1.1 eeh * Set the master interrupt enable and interrupt vector.
388 1.1 eeh * (common to both channels, do it on A)
389 1.1 eeh */
390 1.1 eeh cs = zsc->zsc_cs[0];
391 1.1 eeh s = splhigh();
392 1.1 eeh /* interrupt vector */
393 1.1 eeh zs_write_reg(cs, 2, zs_init_reg[2]);
394 1.1 eeh /* master interrupt control (enable) */
395 1.1 eeh zs_write_reg(cs, 9, zs_init_reg[9]);
396 1.1 eeh splx(s);
397 1.1 eeh
398 1.1 eeh }
399 1.1 eeh
400 1.1 eeh static int
401 1.57 cdi zs_print(void *aux, const char *name)
402 1.1 eeh {
403 1.1 eeh struct zsc_attach_args *args = aux;
404 1.1 eeh
405 1.1 eeh if (name != NULL)
406 1.45 thorpej aprint_normal("%s: ", name);
407 1.1 eeh
408 1.1 eeh if (args->channel != -1)
409 1.45 thorpej aprint_normal(" channel %d", args->channel);
410 1.1 eeh
411 1.1 eeh return (UNCONF);
412 1.1 eeh }
413 1.1 eeh
414 1.24 eeh /* Deprecate this? */
415 1.1 eeh static volatile int zssoftpending;
416 1.1 eeh
417 1.1 eeh static int
418 1.57 cdi zshard(void *arg)
419 1.1 eeh {
420 1.65 tsutsui struct zsc_softc *zsc = arg;
421 1.24 eeh int rr3, rval;
422 1.24 eeh
423 1.24 eeh rval = 0;
424 1.24 eeh while ((rr3 = zsc_intr_hard(zsc))) {
425 1.24 eeh /* Count up the interrupts. */
426 1.24 eeh rval |= rr3;
427 1.24 eeh zsc->zsc_intrcnt.ev_count++;
428 1.24 eeh }
429 1.24 eeh if (((zsc->zsc_cs[0] && zsc->zsc_cs[0]->cs_softreq) ||
430 1.24 eeh (zsc->zsc_cs[1] && zsc->zsc_cs[1]->cs_softreq)) &&
431 1.24 eeh zsc->zsc_softintr) {
432 1.24 eeh zssoftpending = PIL_TTY;
433 1.64 ad softint_schedule(zsc->zsc_softintr);
434 1.24 eeh }
435 1.24 eeh return (rval);
436 1.24 eeh }
437 1.24 eeh
438 1.24 eeh int
439 1.57 cdi zscheckintr(void *arg)
440 1.24 eeh {
441 1.20 eeh struct zsc_softc *zsc;
442 1.24 eeh int unit, rval;
443 1.1 eeh
444 1.24 eeh rval = 0;
445 1.1 eeh for (unit = 0; unit < zs_cd.cd_ndevs; unit++) {
446 1.20 eeh
447 1.65 tsutsui zsc = device_private(zs_cd.cd_devs[unit]);
448 1.1 eeh if (zsc == NULL)
449 1.1 eeh continue;
450 1.24 eeh rval = (zshard((void *)zsc) || rval);
451 1.1 eeh }
452 1.1 eeh return (rval);
453 1.1 eeh }
454 1.1 eeh
455 1.24 eeh
456 1.1 eeh /*
457 1.24 eeh * We need this only for TTY_DEBUG purposes.
458 1.1 eeh */
459 1.28 fvdl static void
460 1.57 cdi zssoft(void *arg)
461 1.1 eeh {
462 1.65 tsutsui struct zsc_softc *zsc = arg;
463 1.24 eeh int s;
464 1.1 eeh
465 1.1 eeh /* Make sure we call the tty layer at spltty. */
466 1.1 eeh s = spltty();
467 1.24 eeh zssoftpending = 0;
468 1.24 eeh (void)zsc_intr_soft(zsc);
469 1.13 eeh #ifdef TTY_DEBUG
470 1.24 eeh {
471 1.24 eeh struct zstty_softc *zst0 = zsc->zsc_cs[0]->cs_private;
472 1.24 eeh struct zstty_softc *zst1 = zsc->zsc_cs[1]->cs_private;
473 1.24 eeh if (zst0->zst_overflows || zst1->zst_overflows ) {
474 1.24 eeh struct trapframe *frame = (struct trapframe *)arg;
475 1.24 eeh
476 1.24 eeh printf("zs silo overflow from %p\n",
477 1.24 eeh (long)frame->tf_pc);
478 1.13 eeh }
479 1.24 eeh }
480 1.13 eeh #endif
481 1.1 eeh splx(s);
482 1.1 eeh }
483 1.1 eeh
484 1.1 eeh
485 1.1 eeh /*
486 1.1 eeh * Compute the current baud rate given a ZS channel.
487 1.1 eeh */
488 1.1 eeh static int
489 1.57 cdi zs_get_speed(struct zs_chanstate *cs)
490 1.1 eeh {
491 1.1 eeh int tconst;
492 1.1 eeh
493 1.1 eeh tconst = zs_read_reg(cs, 12);
494 1.1 eeh tconst |= zs_read_reg(cs, 13) << 8;
495 1.1 eeh return (TCONST_TO_BPS(cs->cs_brg_clk, tconst));
496 1.1 eeh }
497 1.1 eeh
498 1.1 eeh /*
499 1.1 eeh * MD functions for setting the baud rate and control modes.
500 1.1 eeh */
501 1.1 eeh int
502 1.58 cdi zs_set_speed(struct zs_chanstate *cs, int bps /* bits per second */)
503 1.1 eeh {
504 1.1 eeh int tconst, real_bps;
505 1.1 eeh
506 1.1 eeh if (bps == 0)
507 1.1 eeh return (0);
508 1.1 eeh
509 1.1 eeh #ifdef DIAGNOSTIC
510 1.1 eeh if (cs->cs_brg_clk == 0)
511 1.1 eeh panic("zs_set_speed");
512 1.1 eeh #endif
513 1.1 eeh
514 1.1 eeh tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
515 1.1 eeh if (tconst < 0)
516 1.1 eeh return (EINVAL);
517 1.1 eeh
518 1.1 eeh /* Convert back to make sure we can do it. */
519 1.1 eeh real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
520 1.1 eeh
521 1.1 eeh /* XXX - Allow some tolerance here? */
522 1.1 eeh if (real_bps != bps)
523 1.1 eeh return (EINVAL);
524 1.1 eeh
525 1.1 eeh cs->cs_preg[12] = tconst;
526 1.1 eeh cs->cs_preg[13] = tconst >> 8;
527 1.1 eeh
528 1.1 eeh /* Caller will stuff the pending registers. */
529 1.1 eeh return (0);
530 1.1 eeh }
531 1.1 eeh
532 1.1 eeh int
533 1.58 cdi zs_set_modes(struct zs_chanstate *cs, int cflag)
534 1.1 eeh {
535 1.1 eeh int s;
536 1.1 eeh
537 1.1 eeh /*
538 1.1 eeh * Output hardware flow control on the chip is horrendous:
539 1.1 eeh * if carrier detect drops, the receiver is disabled, and if
540 1.1 eeh * CTS drops, the transmitter is stoped IN MID CHARACTER!
541 1.1 eeh * Therefore, NEVER set the HFC bit, and instead use the
542 1.1 eeh * status interrupt to detect CTS changes.
543 1.1 eeh */
544 1.1 eeh s = splzs();
545 1.9 wrstuden cs->cs_rr0_pps = 0;
546 1.9 wrstuden if ((cflag & (CLOCAL | MDMBUF)) != 0) {
547 1.1 eeh cs->cs_rr0_dcd = 0;
548 1.9 wrstuden if ((cflag & MDMBUF) == 0)
549 1.9 wrstuden cs->cs_rr0_pps = ZSRR0_DCD;
550 1.9 wrstuden } else
551 1.1 eeh cs->cs_rr0_dcd = ZSRR0_DCD;
552 1.1 eeh if ((cflag & CRTSCTS) != 0) {
553 1.1 eeh cs->cs_wr5_dtr = ZSWR5_DTR;
554 1.1 eeh cs->cs_wr5_rts = ZSWR5_RTS;
555 1.1 eeh cs->cs_rr0_cts = ZSRR0_CTS;
556 1.1 eeh } else if ((cflag & CDTRCTS) != 0) {
557 1.1 eeh cs->cs_wr5_dtr = 0;
558 1.1 eeh cs->cs_wr5_rts = ZSWR5_DTR;
559 1.1 eeh cs->cs_rr0_cts = ZSRR0_CTS;
560 1.1 eeh } else if ((cflag & MDMBUF) != 0) {
561 1.1 eeh cs->cs_wr5_dtr = 0;
562 1.1 eeh cs->cs_wr5_rts = ZSWR5_DTR;
563 1.1 eeh cs->cs_rr0_cts = ZSRR0_DCD;
564 1.1 eeh } else {
565 1.1 eeh cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
566 1.1 eeh cs->cs_wr5_rts = 0;
567 1.1 eeh cs->cs_rr0_cts = 0;
568 1.1 eeh }
569 1.1 eeh splx(s);
570 1.1 eeh
571 1.1 eeh /* Caller will stuff the pending registers. */
572 1.1 eeh return (0);
573 1.1 eeh }
574 1.1 eeh
575 1.1 eeh
576 1.1 eeh /*
577 1.1 eeh * Read or write the chip with suitable delays.
578 1.1 eeh */
579 1.1 eeh
580 1.1 eeh u_char
581 1.58 cdi zs_read_reg(struct zs_chanstate *cs, u_char reg)
582 1.1 eeh {
583 1.1 eeh u_char val;
584 1.1 eeh
585 1.1 eeh *cs->cs_reg_csr = reg;
586 1.1 eeh ZS_DELAY();
587 1.1 eeh val = *cs->cs_reg_csr;
588 1.1 eeh ZS_DELAY();
589 1.1 eeh return (val);
590 1.1 eeh }
591 1.1 eeh
592 1.1 eeh void
593 1.58 cdi zs_write_reg(struct zs_chanstate *cs, u_char reg, u_char val)
594 1.1 eeh {
595 1.1 eeh *cs->cs_reg_csr = reg;
596 1.1 eeh ZS_DELAY();
597 1.1 eeh *cs->cs_reg_csr = val;
598 1.1 eeh ZS_DELAY();
599 1.1 eeh }
600 1.1 eeh
601 1.1 eeh u_char
602 1.58 cdi zs_read_csr(struct zs_chanstate *cs)
603 1.1 eeh {
604 1.20 eeh u_char val;
605 1.1 eeh
606 1.1 eeh val = *cs->cs_reg_csr;
607 1.1 eeh ZS_DELAY();
608 1.1 eeh return (val);
609 1.1 eeh }
610 1.1 eeh
611 1.58 cdi void
612 1.58 cdi zs_write_csr(struct zs_chanstate *cs, u_char val)
613 1.1 eeh {
614 1.1 eeh *cs->cs_reg_csr = val;
615 1.1 eeh ZS_DELAY();
616 1.1 eeh }
617 1.1 eeh
618 1.58 cdi u_char
619 1.58 cdi zs_read_data(struct zs_chanstate *cs)
620 1.1 eeh {
621 1.20 eeh u_char val;
622 1.1 eeh
623 1.1 eeh val = *cs->cs_reg_data;
624 1.1 eeh ZS_DELAY();
625 1.1 eeh return (val);
626 1.1 eeh }
627 1.1 eeh
628 1.58 cdi void
629 1.58 cdi zs_write_data(struct zs_chanstate *cs, u_char val)
630 1.1 eeh {
631 1.1 eeh *cs->cs_reg_data = val;
632 1.1 eeh ZS_DELAY();
633 1.1 eeh }
634 1.1 eeh
635 1.1 eeh /****************************************************************
636 1.1 eeh * Console support functions (Sun specific!)
637 1.1 eeh * Note: this code is allowed to know about the layout of
638 1.1 eeh * the chip registers, and uses that to keep things simple.
639 1.1 eeh * XXX - I think I like the mvme167 code better. -gwr
640 1.1 eeh ****************************************************************/
641 1.1 eeh
642 1.57 cdi extern void Debugger(void);
643 1.1 eeh
644 1.1 eeh /*
645 1.1 eeh * Handle user request to enter kernel debugger.
646 1.1 eeh */
647 1.1 eeh void
648 1.58 cdi zs_abort(struct zs_chanstate *cs)
649 1.1 eeh {
650 1.20 eeh volatile struct zschan *zc = zs_conschan_get;
651 1.1 eeh int rr0;
652 1.1 eeh
653 1.1 eeh /* Wait for end of break to avoid PROM abort. */
654 1.1 eeh /* XXX - Limit the wait? */
655 1.1 eeh do {
656 1.1 eeh rr0 = zc->zc_csr;
657 1.1 eeh ZS_DELAY();
658 1.1 eeh } while (rr0 & ZSRR0_BREAK);
659 1.1 eeh
660 1.1 eeh #if defined(KGDB)
661 1.1 eeh zskgdb(cs);
662 1.1 eeh #elif defined(DDB)
663 1.12 eeh {
664 1.12 eeh extern int db_active;
665 1.12 eeh
666 1.12 eeh if (!db_active)
667 1.12 eeh Debugger();
668 1.12 eeh else
669 1.12 eeh /* Debugger is probably hozed */
670 1.12 eeh callrom();
671 1.12 eeh }
672 1.1 eeh #else
673 1.1 eeh printf("stopping on keyboard abort\n");
674 1.1 eeh callrom();
675 1.1 eeh #endif
676 1.1 eeh }
677 1.1 eeh
678 1.20 eeh
679 1.1 eeh /*
680 1.1 eeh * Polled input char.
681 1.1 eeh */
682 1.1 eeh int
683 1.58 cdi zs_getc(void *arg)
684 1.1 eeh {
685 1.20 eeh volatile struct zschan *zc = arg;
686 1.20 eeh int s, c, rr0;
687 1.1 eeh
688 1.1 eeh s = splhigh();
689 1.1 eeh /* Wait for a character to arrive. */
690 1.1 eeh do {
691 1.1 eeh rr0 = zc->zc_csr;
692 1.1 eeh ZS_DELAY();
693 1.1 eeh } while ((rr0 & ZSRR0_RX_READY) == 0);
694 1.1 eeh
695 1.1 eeh c = zc->zc_data;
696 1.1 eeh ZS_DELAY();
697 1.1 eeh splx(s);
698 1.1 eeh
699 1.1 eeh /*
700 1.1 eeh * This is used by the kd driver to read scan codes,
701 1.1 eeh * so don't translate '\r' ==> '\n' here...
702 1.1 eeh */
703 1.1 eeh return (c);
704 1.1 eeh }
705 1.1 eeh
706 1.1 eeh /*
707 1.1 eeh * Polled output char.
708 1.1 eeh */
709 1.1 eeh void
710 1.58 cdi zs_putc(void *arg, int c)
711 1.1 eeh {
712 1.20 eeh volatile struct zschan *zc = arg;
713 1.20 eeh int s, rr0;
714 1.1 eeh
715 1.1 eeh s = splhigh();
716 1.1 eeh
717 1.1 eeh /* Wait for transmitter to become ready. */
718 1.1 eeh do {
719 1.1 eeh rr0 = zc->zc_csr;
720 1.1 eeh ZS_DELAY();
721 1.1 eeh } while ((rr0 & ZSRR0_TX_READY) == 0);
722 1.1 eeh
723 1.1 eeh /*
724 1.1 eeh * Send the next character.
725 1.1 eeh * Now you'd think that this could be followed by a ZS_DELAY()
726 1.1 eeh * just like all the other chip accesses, but it turns out that
727 1.1 eeh * the `transmit-ready' interrupt isn't de-asserted until
728 1.1 eeh * some period of time after the register write completes
729 1.1 eeh * (more than a couple instructions). So to avoid stray
730 1.50 wiz * interrupts we put in the 2us delay regardless of CPU model.
731 1.1 eeh */
732 1.1 eeh zc->zc_data = c;
733 1.1 eeh delay(2);
734 1.1 eeh
735 1.1 eeh splx(s);
736 1.1 eeh }
737 1.1 eeh
738 1.1 eeh /*****************************************************************/
739 1.1 eeh
740 1.1 eeh
741 1.20 eeh
742 1.1 eeh
743 1.1 eeh /*
744 1.1 eeh * Polled console input putchar.
745 1.1 eeh */
746 1.1 eeh static int
747 1.57 cdi zscngetc(dev_t dev)
748 1.1 eeh {
749 1.20 eeh return (zs_getc(zs_conschan_get));
750 1.1 eeh }
751 1.1 eeh
752 1.1 eeh /*
753 1.1 eeh * Polled console output putchar.
754 1.1 eeh */
755 1.1 eeh static void
756 1.57 cdi zscnputc(dev_t dev, int c)
757 1.1 eeh {
758 1.20 eeh zs_putc(zs_conschan_put, c);
759 1.5 eeh }
760 1.5 eeh
761 1.5 eeh int swallow_zsintrs;
762 1.5 eeh
763 1.5 eeh static void
764 1.57 cdi zscnpollc(dev_t dev, int on)
765 1.5 eeh {
766 1.5 eeh /*
767 1.5 eeh * Need to tell zs driver to acknowledge all interrupts or we get
768 1.5 eeh * annoying spurious interrupt messages. This is because mucking
769 1.5 eeh * with spl() levels during polling does not prevent interrupts from
770 1.5 eeh * being generated.
771 1.5 eeh */
772 1.5 eeh
773 1.5 eeh if (on) swallow_zsintrs++;
774 1.5 eeh else swallow_zsintrs--;
775 1.1 eeh }
776 1.20 eeh
777 1.20 eeh int
778 1.57 cdi zs_console_flags(int promunit, int node, int channel)
779 1.20 eeh {
780 1.20 eeh int cookie, flags = 0;
781 1.20 eeh char buf[255];
782 1.20 eeh
783 1.20 eeh /*
784 1.53 pk * We'll just do the OBP grovelling down here since that's
785 1.20 eeh * the only type of firmware we support.
786 1.20 eeh */
787 1.20 eeh
788 1.20 eeh /* Default to channel 0 if there are no explicit prom args */
789 1.20 eeh cookie = 0;
790 1.54 pk if (node == prom_instance_to_package(prom_stdin())) {
791 1.61 martin if (prom_getoption("input-device", buf, sizeof buf) == 0 &&
792 1.53 pk strcmp("ttyb", buf) == 0)
793 1.53 pk cookie = 1;
794 1.20 eeh
795 1.20 eeh if (channel == cookie)
796 1.20 eeh flags |= ZS_HWFLAG_CONSOLE_INPUT;
797 1.20 eeh }
798 1.20 eeh
799 1.54 pk if (node == prom_instance_to_package(prom_stdout())) {
800 1.61 martin if (prom_getoption("output-device", buf, sizeof buf) == 0 &&
801 1.53 pk strcmp("ttyb", buf) == 0)
802 1.53 pk cookie = 1;
803 1.20 eeh
804 1.20 eeh if (channel == cookie)
805 1.20 eeh flags |= ZS_HWFLAG_CONSOLE_OUTPUT;
806 1.20 eeh }
807 1.20 eeh
808 1.20 eeh return (flags);
809 1.20 eeh }
810 1.20 eeh
811