zs.c revision 1.19 1 1.19 scw /* $NetBSD: zs.c,v 1.19 2000/03/18 22:33:05 scw Exp $ */
2 1.1 chuck
3 1.10 thorpej /*-
4 1.10 thorpej * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 1.1 chuck * All rights reserved.
6 1.1 chuck *
7 1.10 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.10 thorpej * by Gordon W. Ross.
9 1.10 thorpej *
10 1.1 chuck * Redistribution and use in source and binary forms, with or without
11 1.1 chuck * modification, are permitted provided that the following conditions
12 1.1 chuck * are met:
13 1.1 chuck * 1. Redistributions of source code must retain the above copyright
14 1.1 chuck * notice, this list of conditions and the following disclaimer.
15 1.1 chuck * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 chuck * notice, this list of conditions and the following disclaimer in the
17 1.1 chuck * documentation and/or other materials provided with the distribution.
18 1.10 thorpej * 3. All advertising materials mentioning features or use of this software
19 1.4 chuck * must display the following acknowledgement:
20 1.10 thorpej * This product includes software developed by the NetBSD
21 1.10 thorpej * Foundation, Inc. and its contributors.
22 1.10 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.10 thorpej * contributors may be used to endorse or promote products derived
24 1.10 thorpej * from this software without specific prior written permission.
25 1.1 chuck *
26 1.10 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.10 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.10 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.12 gwr * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.12 gwr * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.10 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.10 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.10 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.10 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.10 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.10 thorpej * POSSIBILITY OF SUCH DAMAGE.
37 1.1 chuck */
38 1.4 chuck
39 1.1 chuck /*
40 1.4 chuck * Zilog Z8530 Dual UART driver (machine-dependent part)
41 1.4 chuck *
42 1.4 chuck * Runs two serial lines per chip using slave drivers.
43 1.4 chuck * Plain tty/async lines use the zs_async slave.
44 1.4 chuck *
45 1.4 chuck * Modified for NetBSD/mvme68k by Jason R. Thorpe <thorpej (at) NetBSD.ORG>
46 1.1 chuck */
47 1.4 chuck
48 1.1 chuck #include <sys/param.h>
49 1.4 chuck #include <sys/systm.h>
50 1.11 gwr #include <sys/conf.h>
51 1.4 chuck #include <sys/device.h>
52 1.4 chuck #include <sys/file.h>
53 1.1 chuck #include <sys/ioctl.h>
54 1.11 gwr #include <sys/kernel.h>
55 1.11 gwr #include <sys/proc.h>
56 1.1 chuck #include <sys/tty.h>
57 1.4 chuck #include <sys/time.h>
58 1.1 chuck #include <sys/syslog.h>
59 1.4 chuck
60 1.1 chuck #include <dev/cons.h>
61 1.4 chuck #include <dev/ic/z8530reg.h>
62 1.4 chuck #include <machine/z8530var.h>
63 1.1 chuck
64 1.4 chuck #include <machine/cpu.h>
65 1.19 scw #include <machine/bus.h>
66 1.1 chuck
67 1.4 chuck #include <mvme68k/dev/zsvar.h>
68 1.1 chuck
69 1.11 gwr /*
70 1.11 gwr * Some warts needed by z8530tty.c -
71 1.11 gwr * The default parity REALLY needs to be the same as the PROM uses,
72 1.11 gwr * or you can not see messages done with printf during boot-up...
73 1.11 gwr */
74 1.11 gwr int zs_def_cflag = (CREAD | CS8 | HUPCL);
75 1.11 gwr /* XXX Shouldn't hardcode the minor number... */
76 1.11 gwr int zs_major = 12;
77 1.11 gwr
78 1.4 chuck static u_long zs_sir; /* software interrupt cookie */
79 1.1 chuck
80 1.4 chuck /* Flags from zscnprobe() */
81 1.11 gwr static int zs_hwflags[NZSC][2];
82 1.1 chuck
83 1.4 chuck /* Default speed for each channel */
84 1.11 gwr static int zs_defspeed[NZSC][2] = {
85 1.4 chuck { 9600, /* port 1 */
86 1.4 chuck 9600 }, /* port 2 */
87 1.4 chuck { 9600, /* port 3 */
88 1.4 chuck 9600 }, /* port 4 */
89 1.4 chuck };
90 1.1 chuck
91 1.4 chuck static struct zs_chanstate zs_conschan_store;
92 1.4 chuck static struct zs_chanstate *zs_conschan;
93 1.1 chuck
94 1.4 chuck u_char zs_init_reg[16] = {
95 1.4 chuck 0, /* 0: CMD (reset, etc.) */
96 1.11 gwr 0, /* 1: No interrupts yet. */
97 1.4 chuck 0x18 + ZSHARD_PRI, /* IVECT */
98 1.4 chuck ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
99 1.4 chuck ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
100 1.4 chuck ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
101 1.4 chuck 0, /* 6: TXSYNC/SYNCLO */
102 1.4 chuck 0, /* 7: RXSYNC/SYNCHI */
103 1.4 chuck 0, /* 8: alias for data port */
104 1.4 chuck ZSWR9_MASTER_IE,
105 1.4 chuck 0, /*10: Misc. TX/RX control bits */
106 1.4 chuck ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
107 1.17 mycroft ((PCLK/32)/9600)-2, /*12: BAUDLO (default=9600) */
108 1.17 mycroft 0, /*13: BAUDHI (default=9600) */
109 1.11 gwr ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK,
110 1.16 mycroft ZSWR15_BREAK_IE,
111 1.2 thorpej };
112 1.2 thorpej
113 1.1 chuck
114 1.4 chuck /****************************************************************
115 1.4 chuck * Autoconfig
116 1.4 chuck ****************************************************************/
117 1.1 chuck
118 1.4 chuck /* Definition of the driver for autoconfig. */
119 1.7 cgd static int zsc_print __P((void *, const char *name));
120 1.19 scw int zs_getc __P((void *));
121 1.19 scw void zs_putc __P((void *, int));
122 1.1 chuck
123 1.19 scw #if 0
124 1.11 gwr static int zs_get_speed __P((struct zs_chanstate *));
125 1.19 scw #endif
126 1.11 gwr
127 1.14 thorpej extern struct cfdriver zsc_cd;
128 1.1 chuck
129 1.19 scw cons_decl(zsc_pcc);
130 1.19 scw
131 1.19 scw
132 1.4 chuck /*
133 1.4 chuck * Configure children of an SCC.
134 1.4 chuck */
135 1.4 chuck void
136 1.19 scw zs_config(zsc, bust, bush)
137 1.4 chuck struct zsc_softc *zsc;
138 1.19 scw bus_space_tag_t bust;
139 1.19 scw bus_space_handle_t bush;
140 1.4 chuck {
141 1.4 chuck struct zsc_attach_args zsc_args;
142 1.19 scw struct zsdevice *zs;
143 1.4 chuck volatile struct zschan *zc;
144 1.4 chuck struct zs_chanstate *cs;
145 1.4 chuck int zsc_unit, channel, s;
146 1.4 chuck
147 1.4 chuck zsc_unit = zsc->zsc_dev.dv_unit;
148 1.9 christos printf(": Zilog 8530 SCC\n");
149 1.4 chuck
150 1.19 scw zs = (struct zsdevice *) bush; /* XXXXXXXX */
151 1.19 scw
152 1.4 chuck /*
153 1.4 chuck * Initialize software state for each channel.
154 1.4 chuck */
155 1.4 chuck for (channel = 0; channel < 2; channel++) {
156 1.11 gwr zsc_args.channel = channel;
157 1.11 gwr zsc_args.hwflags = zs_hwflags[zsc_unit][channel];
158 1.11 gwr cs = &zsc->zsc_cs_store[channel];
159 1.11 gwr zsc->zsc_cs[channel] = cs;
160 1.4 chuck
161 1.4 chuck /*
162 1.4 chuck * If we're the console, copy the channel state, and
163 1.4 chuck * adjust the console channel pointer.
164 1.4 chuck */
165 1.11 gwr if (zsc_args.hwflags & ZS_HWFLAG_CONSOLE) {
166 1.4 chuck bcopy(zs_conschan, cs, sizeof(struct zs_chanstate));
167 1.4 chuck zs_conschan = cs;
168 1.4 chuck } else {
169 1.19 scw zc = (channel == 0) ? &zs->zs_chan_a : &zs->zs_chan_b;
170 1.4 chuck cs->cs_reg_csr = &zc->zc_csr;
171 1.4 chuck cs->cs_reg_data = &zc->zc_data;
172 1.4 chuck bcopy(zs_init_reg, cs->cs_creg, 16);
173 1.4 chuck bcopy(zs_init_reg, cs->cs_preg, 16);
174 1.11 gwr cs->cs_defspeed = zs_defspeed[zsc_unit][channel];
175 1.4 chuck }
176 1.11 gwr cs->cs_defcflag = zs_def_cflag;
177 1.1 chuck
178 1.12 gwr /* Make these correspond to cs_defcflag (-crtscts) */
179 1.12 gwr cs->cs_rr0_dcd = ZSRR0_DCD;
180 1.12 gwr cs->cs_rr0_cts = 0;
181 1.12 gwr cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
182 1.12 gwr cs->cs_wr5_rts = 0;
183 1.12 gwr
184 1.4 chuck cs->cs_channel = channel;
185 1.4 chuck cs->cs_private = NULL;
186 1.4 chuck cs->cs_ops = &zsops_null;
187 1.11 gwr cs->cs_brg_clk = PCLK / 16;
188 1.4 chuck
189 1.4 chuck /*
190 1.4 chuck * Clear the master interrupt enable.
191 1.4 chuck * The INTENA is common to both channels,
192 1.4 chuck * so just do it on the A channel.
193 1.4 chuck */
194 1.4 chuck if (channel == 0) {
195 1.4 chuck zs_write_reg(cs, 9, 0);
196 1.4 chuck }
197 1.1 chuck
198 1.4 chuck /*
199 1.4 chuck * Look for a child driver for this channel.
200 1.4 chuck * The child attach will setup the hardware.
201 1.4 chuck */
202 1.11 gwr if (!config_found(&zsc->zsc_dev, (void *)&zsc_args, zsc_print)) {
203 1.4 chuck /* No sub-driver. Just reset it. */
204 1.11 gwr u_char reset = (channel == 0) ?
205 1.4 chuck ZSWR9_A_RESET : ZSWR9_B_RESET;
206 1.4 chuck s = splzs();
207 1.4 chuck zs_write_reg(cs, 9, reset);
208 1.4 chuck splx(s);
209 1.4 chuck }
210 1.4 chuck }
211 1.1 chuck
212 1.4 chuck /*
213 1.4 chuck * Allocate a software interrupt cookie. Note that the argument
214 1.4 chuck * "zsc" is never actually used in the software interrupt
215 1.4 chuck * handler.
216 1.4 chuck */
217 1.4 chuck if (zs_sir == 0)
218 1.4 chuck zs_sir = allocate_sir(zssoft, zsc);
219 1.1 chuck }
220 1.1 chuck
221 1.4 chuck static int
222 1.4 chuck zsc_print(aux, name)
223 1.4 chuck void *aux;
224 1.7 cgd const char *name;
225 1.1 chuck {
226 1.4 chuck struct zsc_attach_args *args = aux;
227 1.1 chuck
228 1.4 chuck if (name != NULL)
229 1.9 christos printf("%s: ", name);
230 1.1 chuck
231 1.4 chuck if (args->channel != -1)
232 1.9 christos printf(" channel %d", args->channel);
233 1.1 chuck
234 1.4 chuck return UNCONF;
235 1.1 chuck }
236 1.1 chuck
237 1.11 gwr static int zssoftpending;
238 1.11 gwr
239 1.11 gwr /*
240 1.11 gwr * Our ZS chips all share a common, autovectored interrupt,
241 1.11 gwr * so we have to look at all of them on each interrupt.
242 1.11 gwr */
243 1.1 chuck int
244 1.4 chuck zshard(arg)
245 1.4 chuck void *arg;
246 1.4 chuck {
247 1.15 scw struct zsc_softc *zsc;
248 1.15 scw int unit, rval;
249 1.1 chuck
250 1.4 chuck rval = 0;
251 1.11 gwr for (unit = 0; unit < zsc_cd.cd_ndevs; unit++) {
252 1.4 chuck zsc = zsc_cd.cd_devs[unit];
253 1.11 gwr if (zsc == NULL)
254 1.11 gwr continue;
255 1.11 gwr rval |= zsc_intr_hard(zsc);
256 1.11 gwr if ((zsc->zsc_cs[0]->cs_softreq) ||
257 1.11 gwr (zsc->zsc_cs[1]->cs_softreq))
258 1.11 gwr {
259 1.11 gwr /* zsc_req_softint(zsc); */
260 1.11 gwr /* We are at splzs here, so no need to lock. */
261 1.11 gwr if (zssoftpending == 0) {
262 1.11 gwr zssoftpending = zs_sir;
263 1.11 gwr setsoftint(zs_sir);
264 1.11 gwr }
265 1.4 chuck }
266 1.1 chuck }
267 1.4 chuck return (rval);
268 1.1 chuck }
269 1.1 chuck
270 1.11 gwr /*
271 1.11 gwr * Similar scheme as for zshard (look at all of them)
272 1.11 gwr */
273 1.19 scw void
274 1.4 chuck zssoft(arg)
275 1.4 chuck void *arg;
276 1.1 chuck {
277 1.15 scw struct zsc_softc *zsc;
278 1.15 scw int unit;
279 1.4 chuck
280 1.4 chuck /* This is not the only ISR on this IPL. */
281 1.4 chuck if (zssoftpending == 0)
282 1.19 scw return;
283 1.4 chuck
284 1.4 chuck /*
285 1.4 chuck * The soft intr. bit will be set by zshard only if
286 1.4 chuck * the variable zssoftpending is zero.
287 1.4 chuck */
288 1.4 chuck zssoftpending = 0;
289 1.4 chuck
290 1.4 chuck for (unit = 0; unit < zsc_cd.cd_ndevs; ++unit) {
291 1.4 chuck zsc = zsc_cd.cd_devs[unit];
292 1.11 gwr if (zsc == NULL)
293 1.11 gwr continue;
294 1.11 gwr (void) zsc_intr_soft(zsc);
295 1.1 chuck }
296 1.1 chuck }
297 1.1 chuck
298 1.19 scw #if 0
299 1.4 chuck /*
300 1.11 gwr * Compute the current baud rate given a ZSCC channel.
301 1.11 gwr */
302 1.11 gwr static int
303 1.11 gwr zs_get_speed(cs)
304 1.11 gwr struct zs_chanstate *cs;
305 1.11 gwr {
306 1.11 gwr int tconst;
307 1.11 gwr
308 1.11 gwr tconst = zs_read_reg(cs, 12);
309 1.11 gwr tconst |= zs_read_reg(cs, 13) << 8;
310 1.11 gwr return (TCONST_TO_BPS(cs->cs_brg_clk, tconst));
311 1.11 gwr }
312 1.19 scw #endif
313 1.11 gwr
314 1.11 gwr /*
315 1.11 gwr * MD functions for setting the baud rate and control modes.
316 1.11 gwr */
317 1.11 gwr int
318 1.11 gwr zs_set_speed(cs, bps)
319 1.11 gwr struct zs_chanstate *cs;
320 1.11 gwr int bps; /* bits per second */
321 1.11 gwr {
322 1.11 gwr int tconst, real_bps;
323 1.11 gwr
324 1.11 gwr if (bps == 0)
325 1.11 gwr return (0);
326 1.11 gwr
327 1.11 gwr #ifdef DIAGNOSTIC
328 1.11 gwr if (cs->cs_brg_clk == 0)
329 1.11 gwr panic("zs_set_speed");
330 1.11 gwr #endif
331 1.11 gwr
332 1.11 gwr tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
333 1.11 gwr if (tconst < 0)
334 1.11 gwr return (EINVAL);
335 1.11 gwr
336 1.11 gwr /* Convert back to make sure we can do it. */
337 1.11 gwr real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
338 1.11 gwr
339 1.11 gwr /* XXX - Allow some tolerance here? */
340 1.11 gwr if (real_bps != bps)
341 1.11 gwr return (EINVAL);
342 1.11 gwr
343 1.11 gwr cs->cs_preg[12] = tconst;
344 1.11 gwr cs->cs_preg[13] = tconst >> 8;
345 1.11 gwr
346 1.11 gwr /* Caller will stuff the pending registers. */
347 1.11 gwr return (0);
348 1.11 gwr }
349 1.11 gwr
350 1.11 gwr int
351 1.11 gwr zs_set_modes(cs, cflag)
352 1.11 gwr struct zs_chanstate *cs;
353 1.11 gwr int cflag; /* bits per second */
354 1.11 gwr {
355 1.11 gwr int s;
356 1.11 gwr
357 1.11 gwr /*
358 1.11 gwr * Output hardware flow control on the chip is horrendous:
359 1.11 gwr * if carrier detect drops, the receiver is disabled, and if
360 1.11 gwr * CTS drops, the transmitter is stoped IN MID CHARACTER!
361 1.11 gwr * Therefore, NEVER set the HFC bit, and instead use the
362 1.11 gwr * status interrupt to detect CTS changes.
363 1.11 gwr */
364 1.11 gwr s = splzs();
365 1.18 wrstuden cs->cs_rr0_pps = 0;
366 1.18 wrstuden if ((cflag & (CLOCAL | MDMBUF)) != 0) {
367 1.11 gwr cs->cs_rr0_dcd = 0;
368 1.18 wrstuden if ((cflag & MDMBUF) == 0)
369 1.18 wrstuden cs->cs_rr0_pps = ZSRR0_DCD;
370 1.18 wrstuden } else
371 1.11 gwr cs->cs_rr0_dcd = ZSRR0_DCD;
372 1.13 mycroft if ((cflag & CRTSCTS) != 0) {
373 1.11 gwr cs->cs_wr5_dtr = ZSWR5_DTR;
374 1.11 gwr cs->cs_wr5_rts = ZSWR5_RTS;
375 1.11 gwr cs->cs_rr0_cts = ZSRR0_CTS;
376 1.13 mycroft } else if ((cflag & MDMBUF) != 0) {
377 1.13 mycroft cs->cs_wr5_dtr = 0;
378 1.13 mycroft cs->cs_wr5_rts = ZSWR5_DTR;
379 1.13 mycroft cs->cs_rr0_cts = ZSRR0_DCD;
380 1.11 gwr } else {
381 1.11 gwr cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
382 1.11 gwr cs->cs_wr5_rts = 0;
383 1.11 gwr cs->cs_rr0_cts = 0;
384 1.11 gwr }
385 1.11 gwr splx(s);
386 1.11 gwr
387 1.11 gwr /* Caller will stuff the pending registers. */
388 1.11 gwr return (0);
389 1.11 gwr }
390 1.11 gwr
391 1.11 gwr
392 1.11 gwr /*
393 1.4 chuck * Read or write the chip with suitable delays.
394 1.4 chuck */
395 1.1 chuck
396 1.4 chuck u_char
397 1.4 chuck zs_read_reg(cs, reg)
398 1.4 chuck struct zs_chanstate *cs;
399 1.4 chuck u_char reg;
400 1.4 chuck {
401 1.4 chuck u_char val;
402 1.4 chuck
403 1.4 chuck *cs->cs_reg_csr = reg;
404 1.4 chuck ZS_DELAY();
405 1.4 chuck val = *cs->cs_reg_csr;
406 1.4 chuck ZS_DELAY();
407 1.4 chuck return val;
408 1.1 chuck }
409 1.1 chuck
410 1.4 chuck void
411 1.4 chuck zs_write_reg(cs, reg, val)
412 1.4 chuck struct zs_chanstate *cs;
413 1.4 chuck u_char reg, val;
414 1.4 chuck {
415 1.4 chuck *cs->cs_reg_csr = reg;
416 1.4 chuck ZS_DELAY();
417 1.4 chuck *cs->cs_reg_csr = val;
418 1.4 chuck ZS_DELAY();
419 1.1 chuck }
420 1.1 chuck
421 1.4 chuck u_char zs_read_csr(cs)
422 1.4 chuck struct zs_chanstate *cs;
423 1.1 chuck {
424 1.15 scw u_char val;
425 1.1 chuck
426 1.11 gwr val = *cs->cs_reg_csr;
427 1.4 chuck ZS_DELAY();
428 1.11 gwr return val;
429 1.1 chuck }
430 1.1 chuck
431 1.11 gwr void zs_write_csr(cs, val)
432 1.4 chuck struct zs_chanstate *cs;
433 1.11 gwr u_char val;
434 1.1 chuck {
435 1.11 gwr *cs->cs_reg_csr = val;
436 1.4 chuck ZS_DELAY();
437 1.1 chuck }
438 1.1 chuck
439 1.11 gwr u_char zs_read_data(cs)
440 1.4 chuck struct zs_chanstate *cs;
441 1.1 chuck {
442 1.15 scw u_char val;
443 1.11 gwr
444 1.11 gwr val = *cs->cs_reg_data;
445 1.4 chuck ZS_DELAY();
446 1.11 gwr return val;
447 1.1 chuck }
448 1.1 chuck
449 1.4 chuck void zs_write_data(cs, val)
450 1.4 chuck struct zs_chanstate *cs;
451 1.4 chuck u_char val;
452 1.1 chuck {
453 1.4 chuck *cs->cs_reg_data = val;
454 1.4 chuck ZS_DELAY();
455 1.1 chuck }
456 1.1 chuck
457 1.4 chuck /****************************************************************
458 1.4 chuck * Console support functions (MVME specific!)
459 1.4 chuck ****************************************************************/
460 1.4 chuck
461 1.1 chuck /*
462 1.4 chuck * Polled input char.
463 1.1 chuck */
464 1.1 chuck int
465 1.4 chuck zs_getc(arg)
466 1.4 chuck void *arg;
467 1.1 chuck {
468 1.15 scw struct zs_chanstate *cs = arg;
469 1.15 scw int s, c, rr0, stat;
470 1.1 chuck
471 1.4 chuck s = splhigh();
472 1.4 chuck top:
473 1.4 chuck /* Wait for a character to arrive. */
474 1.4 chuck do {
475 1.5 chuck rr0 = *cs->cs_reg_csr;
476 1.4 chuck ZS_DELAY();
477 1.4 chuck } while ((rr0 & ZSRR0_RX_READY) == 0);
478 1.4 chuck
479 1.4 chuck /* Read error register. */
480 1.4 chuck stat = zs_read_reg(cs, 1) & (ZSRR1_FE | ZSRR1_DO | ZSRR1_PE);
481 1.4 chuck if (stat) {
482 1.4 chuck zs_write_csr(cs, ZSM_RESET_ERR);
483 1.4 chuck goto top;
484 1.4 chuck }
485 1.4 chuck
486 1.4 chuck /* Read character. */
487 1.4 chuck c = *cs->cs_reg_data;
488 1.4 chuck ZS_DELAY();
489 1.4 chuck splx(s);
490 1.1 chuck
491 1.4 chuck return (c);
492 1.1 chuck }
493 1.1 chuck
494 1.4 chuck /*
495 1.4 chuck * Polled output char.
496 1.4 chuck */
497 1.1 chuck void
498 1.4 chuck zs_putc(arg, c)
499 1.4 chuck void *arg;
500 1.4 chuck int c;
501 1.4 chuck {
502 1.15 scw struct zs_chanstate *cs = arg;
503 1.15 scw int s, rr0;
504 1.4 chuck
505 1.4 chuck s = splhigh();
506 1.4 chuck /* Wait for transmitter to become ready. */
507 1.4 chuck do {
508 1.4 chuck rr0 = *cs->cs_reg_csr;
509 1.4 chuck ZS_DELAY();
510 1.4 chuck } while ((rr0 & ZSRR0_TX_READY) == 0);
511 1.1 chuck
512 1.4 chuck *cs->cs_reg_data = c;
513 1.4 chuck ZS_DELAY();
514 1.4 chuck splx(s);
515 1.1 chuck }
516 1.1 chuck
517 1.1 chuck /*
518 1.4 chuck * Common parts of console init.
519 1.1 chuck */
520 1.4 chuck void
521 1.19 scw zs_cnconfig(zsc_unit, channel, bust, bush)
522 1.4 chuck int zsc_unit, channel;
523 1.19 scw bus_space_tag_t bust;
524 1.19 scw bus_space_handle_t bush;
525 1.4 chuck {
526 1.4 chuck struct zs_chanstate *cs;
527 1.19 scw struct zsdevice *zs;
528 1.19 scw struct zschan *zc;
529 1.19 scw
530 1.19 scw zs = (struct zsdevice *) bush; /* XXXXXXXX */
531 1.19 scw zc = (channel == 0) ? &zs->zs_chan_a : &zs->zs_chan_b;
532 1.4 chuck
533 1.4 chuck /*
534 1.4 chuck * Pointer to channel state. Later, the console channel
535 1.4 chuck * state is copied into the softc, and the console channel
536 1.4 chuck * pointer adjusted to point to the new copy.
537 1.4 chuck */
538 1.4 chuck zs_conschan = cs = &zs_conschan_store;
539 1.4 chuck zs_hwflags[zsc_unit][channel] = ZS_HWFLAG_CONSOLE;
540 1.4 chuck
541 1.11 gwr /* Setup temporary chanstate. */
542 1.4 chuck cs->cs_reg_csr = &zc->zc_csr;
543 1.4 chuck cs->cs_reg_data = &zc->zc_data;
544 1.4 chuck
545 1.11 gwr /* Initialize the pending registers. */
546 1.11 gwr bcopy(zs_init_reg, cs->cs_preg, 16);
547 1.11 gwr cs->cs_preg[5] |= (ZSWR5_DTR | ZSWR5_RTS);
548 1.4 chuck
549 1.19 scw #if 0
550 1.11 gwr /* XXX: Preserve BAUD rate from boot loader. */
551 1.11 gwr /* XXX: Also, why reset the chip here? -gwr */
552 1.19 scw cs->cs_defspeed = zs_get_speed(cs);
553 1.19 scw #else
554 1.11 gwr cs->cs_defspeed = 9600; /* XXX */
555 1.19 scw #endif
556 1.4 chuck
557 1.11 gwr /* Clear the master interrupt enable. */
558 1.11 gwr zs_write_reg(cs, 9, 0);
559 1.4 chuck
560 1.11 gwr /* Reset the whole SCC chip. */
561 1.4 chuck zs_write_reg(cs, 9, ZSWR9_HARD_RESET);
562 1.4 chuck
563 1.11 gwr /* Copy "pending" to "current" and H/W. */
564 1.11 gwr zs_loadchannelregs(cs);
565 1.1 chuck }
566 1.1 chuck
567 1.4 chuck /*
568 1.4 chuck * Polled console input putchar.
569 1.4 chuck */
570 1.1 chuck int
571 1.19 scw zsc_pcccngetc(dev)
572 1.4 chuck dev_t dev;
573 1.1 chuck {
574 1.15 scw struct zs_chanstate *cs = zs_conschan;
575 1.15 scw int c;
576 1.1 chuck
577 1.4 chuck c = zs_getc(cs);
578 1.4 chuck return (c);
579 1.1 chuck }
580 1.1 chuck
581 1.4 chuck /*
582 1.4 chuck * Polled console output putchar.
583 1.4 chuck */
584 1.4 chuck void
585 1.19 scw zsc_pcccnputc(dev, c)
586 1.4 chuck dev_t dev;
587 1.4 chuck int c;
588 1.1 chuck {
589 1.15 scw struct zs_chanstate *cs = zs_conschan;
590 1.1 chuck
591 1.4 chuck zs_putc(cs, c);
592 1.1 chuck }
593 1.1 chuck
594 1.4 chuck /*
595 1.4 chuck * Handle user request to enter kernel debugger.
596 1.4 chuck */
597 1.4 chuck void
598 1.11 gwr zs_abort(cs)
599 1.11 gwr struct zs_chanstate *cs;
600 1.1 chuck {
601 1.4 chuck int rr0;
602 1.1 chuck
603 1.4 chuck /* Wait for end of break to avoid PROM abort. */
604 1.4 chuck /* XXX - Limit the wait? */
605 1.4 chuck do {
606 1.4 chuck rr0 = *cs->cs_reg_csr;
607 1.4 chuck ZS_DELAY();
608 1.4 chuck } while (rr0 & ZSRR0_BREAK);
609 1.1 chuck
610 1.4 chuck mvme68k_abort("SERIAL LINE ABORT");
611 1.1 chuck }
612