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