zs.c revision 1.31 1 1.31 pk /* $NetBSD: zs.c,v 1.31 2003/01/28 12:35:33 pk 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.20 scw #include <machine/intr.h>
67 1.1 chuck
68 1.4 chuck #include <mvme68k/dev/zsvar.h>
69 1.1 chuck
70 1.11 gwr /*
71 1.11 gwr * Some warts needed by z8530tty.c -
72 1.11 gwr * The default parity REALLY needs to be the same as the PROM uses,
73 1.11 gwr * or you can not see messages done with printf during boot-up...
74 1.11 gwr */
75 1.11 gwr int zs_def_cflag = (CREAD | CS8 | HUPCL);
76 1.11 gwr
77 1.4 chuck /* Flags from zscnprobe() */
78 1.11 gwr static int zs_hwflags[NZSC][2];
79 1.1 chuck
80 1.4 chuck /* Default speed for each channel */
81 1.11 gwr static int zs_defspeed[NZSC][2] = {
82 1.4 chuck { 9600, /* port 1 */
83 1.4 chuck 9600 }, /* port 2 */
84 1.4 chuck { 9600, /* port 3 */
85 1.4 chuck 9600 }, /* port 4 */
86 1.4 chuck };
87 1.1 chuck
88 1.4 chuck static struct zs_chanstate zs_conschan_store;
89 1.4 chuck static struct zs_chanstate *zs_conschan;
90 1.1 chuck
91 1.4 chuck u_char zs_init_reg[16] = {
92 1.4 chuck 0, /* 0: CMD (reset, etc.) */
93 1.11 gwr 0, /* 1: No interrupts yet. */
94 1.4 chuck 0x18 + ZSHARD_PRI, /* IVECT */
95 1.4 chuck ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
96 1.4 chuck ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
97 1.4 chuck ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
98 1.4 chuck 0, /* 6: TXSYNC/SYNCLO */
99 1.4 chuck 0, /* 7: RXSYNC/SYNCHI */
100 1.4 chuck 0, /* 8: alias for data port */
101 1.4 chuck ZSWR9_MASTER_IE,
102 1.4 chuck 0, /*10: Misc. TX/RX control bits */
103 1.4 chuck ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
104 1.22 scw 0, /*12: BAUDLO (default=9600) */
105 1.17 mycroft 0, /*13: BAUDHI (default=9600) */
106 1.11 gwr ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK,
107 1.16 mycroft ZSWR15_BREAK_IE,
108 1.2 thorpej };
109 1.2 thorpej
110 1.1 chuck
111 1.4 chuck /****************************************************************
112 1.4 chuck * Autoconfig
113 1.4 chuck ****************************************************************/
114 1.1 chuck
115 1.4 chuck /* Definition of the driver for autoconfig. */
116 1.7 cgd static int zsc_print __P((void *, const char *name));
117 1.19 scw int zs_getc __P((void *));
118 1.19 scw void zs_putc __P((void *, int));
119 1.1 chuck
120 1.19 scw #if 0
121 1.11 gwr static int zs_get_speed __P((struct zs_chanstate *));
122 1.19 scw #endif
123 1.11 gwr
124 1.14 thorpej extern struct cfdriver zsc_cd;
125 1.1 chuck
126 1.19 scw cons_decl(zsc_pcc);
127 1.19 scw
128 1.19 scw
129 1.4 chuck /*
130 1.4 chuck * Configure children of an SCC.
131 1.4 chuck */
132 1.4 chuck void
133 1.22 scw zs_config(zsc, zs, vector, pclk)
134 1.4 chuck struct zsc_softc *zsc;
135 1.22 scw struct zsdevice *zs;
136 1.22 scw int vector, pclk;
137 1.4 chuck {
138 1.4 chuck struct zsc_attach_args zsc_args;
139 1.4 chuck volatile struct zschan *zc;
140 1.4 chuck struct zs_chanstate *cs;
141 1.4 chuck int zsc_unit, channel, s;
142 1.4 chuck
143 1.4 chuck zsc_unit = zsc->zsc_dev.dv_unit;
144 1.22 scw printf(": Zilog 8530 SCC at vector 0x%x\n", vector);
145 1.19 scw
146 1.4 chuck /*
147 1.4 chuck * Initialize software state for each channel.
148 1.4 chuck */
149 1.4 chuck for (channel = 0; channel < 2; channel++) {
150 1.11 gwr zsc_args.channel = channel;
151 1.11 gwr zsc_args.hwflags = zs_hwflags[zsc_unit][channel];
152 1.11 gwr cs = &zsc->zsc_cs_store[channel];
153 1.11 gwr zsc->zsc_cs[channel] = cs;
154 1.31 pk simple_lock_init(&cs->cs_lock);
155 1.4 chuck
156 1.4 chuck /*
157 1.4 chuck * If we're the console, copy the channel state, and
158 1.4 chuck * adjust the console channel pointer.
159 1.4 chuck */
160 1.11 gwr if (zsc_args.hwflags & ZS_HWFLAG_CONSOLE) {
161 1.28 scw memcpy(cs, zs_conschan, sizeof(struct zs_chanstate));
162 1.4 chuck zs_conschan = cs;
163 1.4 chuck } else {
164 1.19 scw zc = (channel == 0) ? &zs->zs_chan_a : &zs->zs_chan_b;
165 1.22 scw cs->cs_reg_csr = zc->zc_csr;
166 1.22 scw cs->cs_reg_data = zc->zc_data;
167 1.28 scw memcpy(cs->cs_creg, zs_init_reg, 16);
168 1.28 scw memcpy(cs->cs_preg, zs_init_reg, 16);
169 1.11 gwr cs->cs_defspeed = zs_defspeed[zsc_unit][channel];
170 1.4 chuck }
171 1.26 scw
172 1.26 scw cs->cs_brg_clk = pclk / 16;
173 1.22 scw cs->cs_creg[2] = cs->cs_preg[2] = vector;
174 1.26 scw zs_set_speed(cs, cs->cs_defspeed);
175 1.26 scw cs->cs_creg[12] = cs->cs_preg[12];
176 1.26 scw cs->cs_creg[13] = cs->cs_preg[13];
177 1.11 gwr cs->cs_defcflag = zs_def_cflag;
178 1.1 chuck
179 1.12 gwr /* Make these correspond to cs_defcflag (-crtscts) */
180 1.12 gwr cs->cs_rr0_dcd = ZSRR0_DCD;
181 1.12 gwr cs->cs_rr0_cts = 0;
182 1.12 gwr cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
183 1.12 gwr cs->cs_wr5_rts = 0;
184 1.12 gwr
185 1.4 chuck cs->cs_channel = channel;
186 1.4 chuck cs->cs_private = NULL;
187 1.4 chuck cs->cs_ops = &zsops_null;
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.22 scw * Write the interrupt vector while we're at it.
194 1.4 chuck */
195 1.4 chuck if (channel == 0) {
196 1.4 chuck zs_write_reg(cs, 9, 0);
197 1.22 scw zs_write_reg(cs, 2, vector);
198 1.4 chuck }
199 1.1 chuck
200 1.4 chuck /*
201 1.4 chuck * Look for a child driver for this channel.
202 1.4 chuck * The child attach will setup the hardware.
203 1.4 chuck */
204 1.11 gwr if (!config_found(&zsc->zsc_dev, (void *)&zsc_args, zsc_print)) {
205 1.4 chuck /* No sub-driver. Just reset it. */
206 1.11 gwr u_char reset = (channel == 0) ?
207 1.4 chuck ZSWR9_A_RESET : ZSWR9_B_RESET;
208 1.4 chuck s = splzs();
209 1.4 chuck zs_write_reg(cs, 9, reset);
210 1.4 chuck splx(s);
211 1.4 chuck }
212 1.4 chuck }
213 1.1 chuck
214 1.4 chuck /*
215 1.20 scw * Allocate a software interrupt cookie.
216 1.4 chuck */
217 1.20 scw zsc->zsc_softintr_cookie = softintr_establish(IPL_SOFTSERIAL,
218 1.20 scw (void (*)(void *)) zsc_intr_soft, zsc);
219 1.21 scw #ifdef DEBUG
220 1.20 scw assert(zsc->zsc_softintr_cookie);
221 1.21 scw #endif
222 1.1 chuck }
223 1.1 chuck
224 1.4 chuck static int
225 1.4 chuck zsc_print(aux, name)
226 1.4 chuck void *aux;
227 1.7 cgd const char *name;
228 1.1 chuck {
229 1.4 chuck struct zsc_attach_args *args = aux;
230 1.1 chuck
231 1.4 chuck if (name != NULL)
232 1.30 thorpej aprint_normal("%s: ", name);
233 1.1 chuck
234 1.4 chuck if (args->channel != -1)
235 1.30 thorpej aprint_normal(" channel %d", args->channel);
236 1.1 chuck
237 1.4 chuck return UNCONF;
238 1.1 chuck }
239 1.1 chuck
240 1.25 scw #if defined(MVME162) || defined(MVME172)
241 1.22 scw /*
242 1.22 scw * Our ZS chips each have their own interrupt vector.
243 1.22 scw */
244 1.22 scw int
245 1.22 scw zshard_unshared(arg)
246 1.22 scw void *arg;
247 1.22 scw {
248 1.22 scw struct zsc_softc *zsc = arg;
249 1.22 scw int rval;
250 1.22 scw
251 1.22 scw rval = zsc_intr_hard(zsc);
252 1.22 scw
253 1.27 scw if (rval) {
254 1.27 scw if ((zsc->zsc_cs[0]->cs_softreq) ||
255 1.27 scw (zsc->zsc_cs[1]->cs_softreq))
256 1.27 scw softintr_schedule(zsc->zsc_softintr_cookie);
257 1.27 scw zsc->zsc_evcnt.ev_count++;
258 1.27 scw }
259 1.22 scw
260 1.22 scw return (rval);
261 1.22 scw }
262 1.22 scw #endif
263 1.22 scw
264 1.22 scw #ifdef MVME147
265 1.11 gwr /*
266 1.22 scw * Our ZS chips all share a common, PCC-vectored interrupt,
267 1.11 gwr * so we have to look at all of them on each interrupt.
268 1.11 gwr */
269 1.1 chuck int
270 1.22 scw zshard_shared(arg)
271 1.4 chuck void *arg;
272 1.4 chuck {
273 1.15 scw struct zsc_softc *zsc;
274 1.15 scw int unit, rval;
275 1.1 chuck
276 1.4 chuck rval = 0;
277 1.11 gwr for (unit = 0; unit < zsc_cd.cd_ndevs; unit++) {
278 1.4 chuck zsc = zsc_cd.cd_devs[unit];
279 1.27 scw if (zsc != NULL && zsc_intr_hard(zsc)) {
280 1.27 scw if ((zsc->zsc_cs[0]->cs_softreq) ||
281 1.27 scw (zsc->zsc_cs[1]->cs_softreq))
282 1.27 scw softintr_schedule(zsc->zsc_softintr_cookie);
283 1.27 scw zsc->zsc_evcnt.ev_count++;
284 1.27 scw rval++;
285 1.27 scw }
286 1.1 chuck }
287 1.4 chuck return (rval);
288 1.1 chuck }
289 1.22 scw #endif
290 1.1 chuck
291 1.1 chuck
292 1.19 scw #if 0
293 1.4 chuck /*
294 1.11 gwr * Compute the current baud rate given a ZSCC channel.
295 1.11 gwr */
296 1.11 gwr static int
297 1.11 gwr zs_get_speed(cs)
298 1.11 gwr struct zs_chanstate *cs;
299 1.11 gwr {
300 1.11 gwr int tconst;
301 1.11 gwr
302 1.11 gwr tconst = zs_read_reg(cs, 12);
303 1.11 gwr tconst |= zs_read_reg(cs, 13) << 8;
304 1.11 gwr return (TCONST_TO_BPS(cs->cs_brg_clk, tconst));
305 1.11 gwr }
306 1.19 scw #endif
307 1.11 gwr
308 1.11 gwr /*
309 1.11 gwr * MD functions for setting the baud rate and control modes.
310 1.11 gwr */
311 1.11 gwr int
312 1.11 gwr zs_set_speed(cs, bps)
313 1.11 gwr struct zs_chanstate *cs;
314 1.11 gwr int bps; /* bits per second */
315 1.11 gwr {
316 1.11 gwr int tconst, real_bps;
317 1.11 gwr
318 1.11 gwr if (bps == 0)
319 1.11 gwr return (0);
320 1.11 gwr
321 1.11 gwr #ifdef DIAGNOSTIC
322 1.11 gwr if (cs->cs_brg_clk == 0)
323 1.11 gwr panic("zs_set_speed");
324 1.11 gwr #endif
325 1.11 gwr
326 1.11 gwr tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
327 1.11 gwr if (tconst < 0)
328 1.11 gwr return (EINVAL);
329 1.11 gwr
330 1.11 gwr /* Convert back to make sure we can do it. */
331 1.11 gwr real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
332 1.11 gwr
333 1.23 scw /* Allow 2% tolerance WRT the required bps */
334 1.24 scw if (((abs(real_bps - bps) * 1000) / bps) > 20)
335 1.11 gwr return (EINVAL);
336 1.11 gwr
337 1.11 gwr cs->cs_preg[12] = tconst;
338 1.11 gwr cs->cs_preg[13] = tconst >> 8;
339 1.11 gwr
340 1.11 gwr /* Caller will stuff the pending registers. */
341 1.11 gwr return (0);
342 1.11 gwr }
343 1.11 gwr
344 1.11 gwr int
345 1.11 gwr zs_set_modes(cs, cflag)
346 1.11 gwr struct zs_chanstate *cs;
347 1.11 gwr int cflag; /* bits per second */
348 1.11 gwr {
349 1.11 gwr int s;
350 1.11 gwr
351 1.11 gwr /*
352 1.11 gwr * Output hardware flow control on the chip is horrendous:
353 1.11 gwr * if carrier detect drops, the receiver is disabled, and if
354 1.11 gwr * CTS drops, the transmitter is stoped IN MID CHARACTER!
355 1.11 gwr * Therefore, NEVER set the HFC bit, and instead use the
356 1.11 gwr * status interrupt to detect CTS changes.
357 1.11 gwr */
358 1.11 gwr s = splzs();
359 1.18 wrstuden cs->cs_rr0_pps = 0;
360 1.18 wrstuden if ((cflag & (CLOCAL | MDMBUF)) != 0) {
361 1.11 gwr cs->cs_rr0_dcd = 0;
362 1.18 wrstuden if ((cflag & MDMBUF) == 0)
363 1.18 wrstuden cs->cs_rr0_pps = ZSRR0_DCD;
364 1.18 wrstuden } else
365 1.11 gwr cs->cs_rr0_dcd = ZSRR0_DCD;
366 1.13 mycroft if ((cflag & CRTSCTS) != 0) {
367 1.11 gwr cs->cs_wr5_dtr = ZSWR5_DTR;
368 1.11 gwr cs->cs_wr5_rts = ZSWR5_RTS;
369 1.11 gwr cs->cs_rr0_cts = ZSRR0_CTS;
370 1.13 mycroft } else if ((cflag & MDMBUF) != 0) {
371 1.13 mycroft cs->cs_wr5_dtr = 0;
372 1.13 mycroft cs->cs_wr5_rts = ZSWR5_DTR;
373 1.13 mycroft cs->cs_rr0_cts = ZSRR0_DCD;
374 1.11 gwr } else {
375 1.11 gwr cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
376 1.11 gwr cs->cs_wr5_rts = 0;
377 1.11 gwr cs->cs_rr0_cts = 0;
378 1.11 gwr }
379 1.11 gwr splx(s);
380 1.11 gwr
381 1.11 gwr /* Caller will stuff the pending registers. */
382 1.11 gwr return (0);
383 1.11 gwr }
384 1.11 gwr
385 1.11 gwr
386 1.11 gwr /*
387 1.4 chuck * Read or write the chip with suitable delays.
388 1.4 chuck */
389 1.1 chuck
390 1.4 chuck u_char
391 1.4 chuck zs_read_reg(cs, reg)
392 1.4 chuck struct zs_chanstate *cs;
393 1.4 chuck u_char reg;
394 1.4 chuck {
395 1.4 chuck u_char val;
396 1.4 chuck
397 1.4 chuck *cs->cs_reg_csr = reg;
398 1.4 chuck ZS_DELAY();
399 1.4 chuck val = *cs->cs_reg_csr;
400 1.4 chuck ZS_DELAY();
401 1.4 chuck return val;
402 1.1 chuck }
403 1.1 chuck
404 1.4 chuck void
405 1.4 chuck zs_write_reg(cs, reg, val)
406 1.4 chuck struct zs_chanstate *cs;
407 1.4 chuck u_char reg, val;
408 1.4 chuck {
409 1.4 chuck *cs->cs_reg_csr = reg;
410 1.4 chuck ZS_DELAY();
411 1.4 chuck *cs->cs_reg_csr = val;
412 1.4 chuck ZS_DELAY();
413 1.1 chuck }
414 1.1 chuck
415 1.4 chuck u_char zs_read_csr(cs)
416 1.4 chuck struct zs_chanstate *cs;
417 1.1 chuck {
418 1.15 scw u_char val;
419 1.1 chuck
420 1.11 gwr val = *cs->cs_reg_csr;
421 1.4 chuck ZS_DELAY();
422 1.11 gwr return val;
423 1.1 chuck }
424 1.1 chuck
425 1.11 gwr void zs_write_csr(cs, val)
426 1.4 chuck struct zs_chanstate *cs;
427 1.11 gwr u_char val;
428 1.1 chuck {
429 1.11 gwr *cs->cs_reg_csr = val;
430 1.4 chuck ZS_DELAY();
431 1.1 chuck }
432 1.1 chuck
433 1.11 gwr u_char zs_read_data(cs)
434 1.4 chuck struct zs_chanstate *cs;
435 1.1 chuck {
436 1.15 scw u_char val;
437 1.11 gwr
438 1.11 gwr val = *cs->cs_reg_data;
439 1.4 chuck ZS_DELAY();
440 1.11 gwr return val;
441 1.1 chuck }
442 1.1 chuck
443 1.4 chuck void zs_write_data(cs, val)
444 1.4 chuck struct zs_chanstate *cs;
445 1.4 chuck u_char val;
446 1.1 chuck {
447 1.4 chuck *cs->cs_reg_data = val;
448 1.4 chuck ZS_DELAY();
449 1.1 chuck }
450 1.1 chuck
451 1.4 chuck /****************************************************************
452 1.4 chuck * Console support functions (MVME specific!)
453 1.4 chuck ****************************************************************/
454 1.4 chuck
455 1.1 chuck /*
456 1.4 chuck * Polled input char.
457 1.1 chuck */
458 1.1 chuck int
459 1.4 chuck zs_getc(arg)
460 1.4 chuck void *arg;
461 1.1 chuck {
462 1.15 scw struct zs_chanstate *cs = arg;
463 1.15 scw int s, c, rr0, stat;
464 1.1 chuck
465 1.4 chuck s = splhigh();
466 1.4 chuck top:
467 1.4 chuck /* Wait for a character to arrive. */
468 1.4 chuck do {
469 1.5 chuck rr0 = *cs->cs_reg_csr;
470 1.4 chuck ZS_DELAY();
471 1.4 chuck } while ((rr0 & ZSRR0_RX_READY) == 0);
472 1.4 chuck
473 1.4 chuck /* Read error register. */
474 1.4 chuck stat = zs_read_reg(cs, 1) & (ZSRR1_FE | ZSRR1_DO | ZSRR1_PE);
475 1.4 chuck if (stat) {
476 1.4 chuck zs_write_csr(cs, ZSM_RESET_ERR);
477 1.4 chuck goto top;
478 1.4 chuck }
479 1.4 chuck
480 1.4 chuck /* Read character. */
481 1.4 chuck c = *cs->cs_reg_data;
482 1.4 chuck ZS_DELAY();
483 1.4 chuck splx(s);
484 1.1 chuck
485 1.4 chuck return (c);
486 1.1 chuck }
487 1.1 chuck
488 1.4 chuck /*
489 1.4 chuck * Polled output char.
490 1.4 chuck */
491 1.1 chuck void
492 1.4 chuck zs_putc(arg, c)
493 1.4 chuck void *arg;
494 1.4 chuck int c;
495 1.4 chuck {
496 1.15 scw struct zs_chanstate *cs = arg;
497 1.15 scw int s, rr0;
498 1.4 chuck
499 1.4 chuck s = splhigh();
500 1.4 chuck /* Wait for transmitter to become ready. */
501 1.4 chuck do {
502 1.4 chuck rr0 = *cs->cs_reg_csr;
503 1.4 chuck ZS_DELAY();
504 1.4 chuck } while ((rr0 & ZSRR0_TX_READY) == 0);
505 1.1 chuck
506 1.4 chuck *cs->cs_reg_data = c;
507 1.4 chuck ZS_DELAY();
508 1.4 chuck splx(s);
509 1.1 chuck }
510 1.1 chuck
511 1.1 chuck /*
512 1.4 chuck * Common parts of console init.
513 1.1 chuck */
514 1.4 chuck void
515 1.22 scw zs_cnconfig(zsc_unit, channel, zs, pclk)
516 1.4 chuck int zsc_unit, channel;
517 1.22 scw struct zsdevice *zs;
518 1.22 scw int pclk;
519 1.4 chuck {
520 1.4 chuck struct zs_chanstate *cs;
521 1.19 scw struct zschan *zc;
522 1.19 scw
523 1.19 scw zc = (channel == 0) ? &zs->zs_chan_a : &zs->zs_chan_b;
524 1.4 chuck
525 1.4 chuck /*
526 1.4 chuck * Pointer to channel state. Later, the console channel
527 1.4 chuck * state is copied into the softc, and the console channel
528 1.4 chuck * pointer adjusted to point to the new copy.
529 1.4 chuck */
530 1.4 chuck zs_conschan = cs = &zs_conschan_store;
531 1.4 chuck zs_hwflags[zsc_unit][channel] = ZS_HWFLAG_CONSOLE;
532 1.4 chuck
533 1.11 gwr /* Setup temporary chanstate. */
534 1.26 scw cs->cs_brg_clk = pclk / 16;
535 1.22 scw cs->cs_reg_csr = zc->zc_csr;
536 1.22 scw cs->cs_reg_data = zc->zc_data;
537 1.4 chuck
538 1.11 gwr /* Initialize the pending registers. */
539 1.28 scw memcpy(cs->cs_preg, zs_init_reg, 16);
540 1.11 gwr cs->cs_preg[5] |= (ZSWR5_DTR | ZSWR5_RTS);
541 1.4 chuck
542 1.19 scw #if 0
543 1.11 gwr /* XXX: Preserve BAUD rate from boot loader. */
544 1.11 gwr /* XXX: Also, why reset the chip here? -gwr */
545 1.19 scw cs->cs_defspeed = zs_get_speed(cs);
546 1.19 scw #else
547 1.11 gwr cs->cs_defspeed = 9600; /* XXX */
548 1.19 scw #endif
549 1.26 scw zs_set_speed(cs, cs->cs_defspeed);
550 1.26 scw cs->cs_creg[12] = cs->cs_preg[12];
551 1.26 scw cs->cs_creg[13] = cs->cs_preg[13];
552 1.4 chuck
553 1.11 gwr /* Clear the master interrupt enable. */
554 1.11 gwr zs_write_reg(cs, 9, 0);
555 1.4 chuck
556 1.11 gwr /* Reset the whole SCC chip. */
557 1.4 chuck zs_write_reg(cs, 9, ZSWR9_HARD_RESET);
558 1.4 chuck
559 1.11 gwr /* Copy "pending" to "current" and H/W. */
560 1.11 gwr zs_loadchannelregs(cs);
561 1.1 chuck }
562 1.1 chuck
563 1.4 chuck /*
564 1.4 chuck * Polled console input putchar.
565 1.4 chuck */
566 1.1 chuck int
567 1.19 scw zsc_pcccngetc(dev)
568 1.4 chuck dev_t dev;
569 1.1 chuck {
570 1.15 scw struct zs_chanstate *cs = zs_conschan;
571 1.15 scw int c;
572 1.1 chuck
573 1.4 chuck c = zs_getc(cs);
574 1.4 chuck return (c);
575 1.1 chuck }
576 1.1 chuck
577 1.4 chuck /*
578 1.4 chuck * Polled console output putchar.
579 1.4 chuck */
580 1.4 chuck void
581 1.19 scw zsc_pcccnputc(dev, c)
582 1.4 chuck dev_t dev;
583 1.4 chuck int c;
584 1.1 chuck {
585 1.15 scw struct zs_chanstate *cs = zs_conschan;
586 1.1 chuck
587 1.4 chuck zs_putc(cs, c);
588 1.1 chuck }
589 1.1 chuck
590 1.4 chuck /*
591 1.4 chuck * Handle user request to enter kernel debugger.
592 1.4 chuck */
593 1.4 chuck void
594 1.11 gwr zs_abort(cs)
595 1.11 gwr struct zs_chanstate *cs;
596 1.1 chuck {
597 1.4 chuck int rr0;
598 1.1 chuck
599 1.4 chuck /* Wait for end of break to avoid PROM abort. */
600 1.4 chuck /* XXX - Limit the wait? */
601 1.4 chuck do {
602 1.4 chuck rr0 = *cs->cs_reg_csr;
603 1.4 chuck ZS_DELAY();
604 1.4 chuck } while (rr0 & ZSRR0_BREAK);
605 1.1 chuck
606 1.4 chuck mvme68k_abort("SERIAL LINE ABORT");
607 1.1 chuck }
608