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