zs.c revision 1.1.8.4 1 1.1.8.4 thorpej /* $NetBSD: zs.c,v 1.1.8.4 2003/01/03 16:41:15 thorpej Exp $ */
2 1.1.8.2 nathanw
3 1.1.8.2 nathanw /*-
4 1.1.8.2 nathanw * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 1.1.8.2 nathanw * All rights reserved.
6 1.1.8.2 nathanw *
7 1.1.8.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.1.8.2 nathanw * by Gordon W. Ross.
9 1.1.8.2 nathanw *
10 1.1.8.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.1.8.2 nathanw * modification, are permitted provided that the following conditions
12 1.1.8.2 nathanw * are met:
13 1.1.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.1.8.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.1.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.1.8.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.1.8.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.1.8.2 nathanw * must display the following acknowledgement:
20 1.1.8.2 nathanw * This product includes software developed by the NetBSD
21 1.1.8.2 nathanw * Foundation, Inc. and its contributors.
22 1.1.8.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.1.8.2 nathanw * contributors may be used to endorse or promote products derived
24 1.1.8.2 nathanw * from this software without specific prior written permission.
25 1.1.8.2 nathanw *
26 1.1.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.1.8.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.1.8.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.1.8.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.1.8.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.1.8.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.1.8.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.1.8.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.1.8.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.1.8.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.1.8.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.1.8.2 nathanw */
38 1.1.8.2 nathanw
39 1.1.8.2 nathanw /*
40 1.1.8.2 nathanw * Zilog Z8530 Dual UART driver (machine-dependent part)
41 1.1.8.2 nathanw *
42 1.1.8.2 nathanw * Runs two serial lines per chip using slave drivers.
43 1.1.8.2 nathanw * Plain tty/async lines use the zs_async slave.
44 1.1.8.2 nathanw */
45 1.1.8.2 nathanw
46 1.1.8.2 nathanw #include "opt_ddb.h"
47 1.1.8.2 nathanw
48 1.1.8.2 nathanw #include <sys/param.h>
49 1.1.8.2 nathanw #include <sys/systm.h>
50 1.1.8.2 nathanw #include <sys/conf.h>
51 1.1.8.2 nathanw #include <sys/device.h>
52 1.1.8.2 nathanw #include <sys/file.h>
53 1.1.8.2 nathanw #include <sys/ioctl.h>
54 1.1.8.2 nathanw #include <sys/kernel.h>
55 1.1.8.2 nathanw #include <sys/malloc.h>
56 1.1.8.2 nathanw #include <sys/proc.h>
57 1.1.8.2 nathanw #include <sys/tty.h>
58 1.1.8.2 nathanw #include <sys/time.h>
59 1.1.8.2 nathanw #include <sys/syslog.h>
60 1.1.8.2 nathanw
61 1.1.8.2 nathanw #include <dev/cons.h>
62 1.1.8.2 nathanw #include <dev/ic/z8530reg.h>
63 1.1.8.2 nathanw
64 1.1.8.2 nathanw #include <machine/cpu.h>
65 1.1.8.2 nathanw
66 1.1.8.2 nathanw #include <machine/z8530var.h>
67 1.1.8.2 nathanw #include <cesfic/dev/zsvar.h>
68 1.1.8.2 nathanw
69 1.1.8.2 nathanw int zs_getc __P((void*));
70 1.1.8.2 nathanw void zs_putc __P((void*, int));
71 1.1.8.2 nathanw
72 1.1.8.2 nathanw static struct zs_chanstate zs_conschan_store;
73 1.1.8.2 nathanw static int zs_hwflags[2][2];
74 1.1.8.2 nathanw int zssoftpending;
75 1.1.8.2 nathanw
76 1.1.8.2 nathanw extern struct cfdriver zsc_cd;
77 1.1.8.2 nathanw
78 1.1.8.2 nathanw u_char zs_init_reg[16] = {
79 1.1.8.2 nathanw 0, /* 0: CMD (reset, etc.) */
80 1.1.8.2 nathanw 0, /* 1: No interrupts yet. */
81 1.1.8.2 nathanw 0x18 + ZSHARD_PRI, /* IVECT */
82 1.1.8.2 nathanw ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
83 1.1.8.2 nathanw ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
84 1.1.8.2 nathanw ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
85 1.1.8.2 nathanw 0, /* 6: TXSYNC/SYNCLO */
86 1.1.8.2 nathanw 0, /* 7: RXSYNC/SYNCHI */
87 1.1.8.2 nathanw 0, /* 8: alias for data port */
88 1.1.8.2 nathanw ZSWR9_MASTER_IE,
89 1.1.8.2 nathanw 0, /*10: Misc. TX/RX control bits */
90 1.1.8.2 nathanw ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
91 1.1.8.2 nathanw 11, /*12: BAUDLO (default=9600) */
92 1.1.8.2 nathanw 0, /*13: BAUDHI (default=9600) */
93 1.1.8.2 nathanw ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK,
94 1.1.8.2 nathanw ZSWR15_BREAK_IE | ZSWR15_DCD_IE,
95 1.1.8.2 nathanw };
96 1.1.8.2 nathanw
97 1.1.8.2 nathanw static int zsc_print __P((void *, const char *));
98 1.1.8.2 nathanw int zscngetc __P((dev_t));
99 1.1.8.2 nathanw void zscnputc __P((dev_t, int));
100 1.1.8.2 nathanw
101 1.1.8.2 nathanw static struct consdev zscons = { NULL, NULL,
102 1.1.8.2 nathanw zscngetc, zscnputc, nullcnpollc, 0, NODEV, 1 };
103 1.1.8.2 nathanw
104 1.1.8.2 nathanw void
105 1.1.8.2 nathanw zs_config(zsc, base)
106 1.1.8.2 nathanw struct zsc_softc *zsc;
107 1.1.8.2 nathanw char *base;
108 1.1.8.2 nathanw {
109 1.1.8.2 nathanw struct zsc_attach_args zsc_args;
110 1.1.8.2 nathanw struct zs_chanstate *cs;
111 1.1.8.2 nathanw int zsc_unit, channel, s;
112 1.1.8.2 nathanw
113 1.1.8.2 nathanw zsc_unit = zsc->zsc_dev.dv_unit;
114 1.1.8.2 nathanw printf(": Zilog 8530 SCC\n");
115 1.1.8.2 nathanw
116 1.1.8.2 nathanw /*
117 1.1.8.2 nathanw * Initialize software state for each channel.
118 1.1.8.2 nathanw */
119 1.1.8.2 nathanw for (channel = 0; channel < 2; channel++) {
120 1.1.8.2 nathanw zsc_args.channel = channel;
121 1.1.8.2 nathanw zsc_args.hwflags = zs_hwflags[zsc_unit][channel];
122 1.1.8.2 nathanw
123 1.1.8.2 nathanw /*
124 1.1.8.2 nathanw * If we're the console, copy the channel state, and
125 1.1.8.2 nathanw * adjust the console channel pointer.
126 1.1.8.2 nathanw */
127 1.1.8.2 nathanw if (zsc_args.hwflags & ZS_HWFLAG_CONSOLE) {
128 1.1.8.2 nathanw cs = &zs_conschan_store;
129 1.1.8.2 nathanw } else {
130 1.1.8.2 nathanw cs = malloc(sizeof(struct zs_chanstate),
131 1.1.8.3 nathanw M_DEVBUF, M_NOWAIT | M_ZERO);
132 1.1.8.2 nathanw if(channel==0){
133 1.1.8.2 nathanw cs->cs_reg_csr = base+7;
134 1.1.8.2 nathanw cs->cs_reg_data = base+15;
135 1.1.8.2 nathanw } else {
136 1.1.8.2 nathanw cs->cs_reg_csr = base+3;
137 1.1.8.2 nathanw cs->cs_reg_data = base+11;
138 1.1.8.2 nathanw }
139 1.1.8.2 nathanw bcopy(zs_init_reg, cs->cs_creg, 16);
140 1.1.8.2 nathanw bcopy(zs_init_reg, cs->cs_preg, 16);
141 1.1.8.2 nathanw cs->cs_defspeed = 9600;
142 1.1.8.2 nathanw }
143 1.1.8.2 nathanw zsc->zsc_cs[channel] = cs;
144 1.1.8.2 nathanw
145 1.1.8.2 nathanw cs->cs_defcflag = CREAD | CS8 | HUPCL;
146 1.1.8.2 nathanw
147 1.1.8.2 nathanw /* Make these correspond to cs_defcflag (-crtscts) */
148 1.1.8.2 nathanw cs->cs_rr0_dcd = ZSRR0_DCD;
149 1.1.8.2 nathanw cs->cs_rr0_cts = 0;
150 1.1.8.2 nathanw cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
151 1.1.8.2 nathanw cs->cs_wr5_rts = 0;
152 1.1.8.2 nathanw
153 1.1.8.2 nathanw cs->cs_channel = channel;
154 1.1.8.2 nathanw cs->cs_private = NULL;
155 1.1.8.2 nathanw cs->cs_ops = &zsops_null;
156 1.1.8.2 nathanw cs->cs_brg_clk = 4000000 / 16;
157 1.1.8.2 nathanw
158 1.1.8.2 nathanw /*
159 1.1.8.2 nathanw * Clear the master interrupt enable.
160 1.1.8.2 nathanw * The INTENA is common to both channels,
161 1.1.8.2 nathanw * so just do it on the A channel.
162 1.1.8.2 nathanw */
163 1.1.8.2 nathanw if (channel == 0) {
164 1.1.8.2 nathanw zs_write_reg(cs, 9, 0);
165 1.1.8.2 nathanw }
166 1.1.8.2 nathanw
167 1.1.8.2 nathanw /*
168 1.1.8.2 nathanw * Look for a child driver for this channel.
169 1.1.8.2 nathanw * The child attach will setup the hardware.
170 1.1.8.2 nathanw */
171 1.1.8.2 nathanw if (!config_found(&zsc->zsc_dev, (void *)&zsc_args, zsc_print)) {
172 1.1.8.2 nathanw /* No sub-driver. Just reset it. */
173 1.1.8.2 nathanw u_char reset = (channel == 0) ?
174 1.1.8.2 nathanw ZSWR9_A_RESET : ZSWR9_B_RESET;
175 1.1.8.2 nathanw s = splzs();
176 1.1.8.2 nathanw zs_write_reg(cs, 9, reset);
177 1.1.8.2 nathanw splx(s);
178 1.1.8.2 nathanw }
179 1.1.8.2 nathanw }
180 1.1.8.2 nathanw }
181 1.1.8.2 nathanw
182 1.1.8.2 nathanw static int
183 1.1.8.2 nathanw zsc_print(aux, name)
184 1.1.8.2 nathanw void *aux;
185 1.1.8.2 nathanw const char *name;
186 1.1.8.2 nathanw {
187 1.1.8.2 nathanw struct zsc_attach_args *args = aux;
188 1.1.8.2 nathanw
189 1.1.8.2 nathanw if (name != NULL)
190 1.1.8.4 thorpej aprint_normal("%s: ", name);
191 1.1.8.2 nathanw
192 1.1.8.2 nathanw if (args->channel != -1)
193 1.1.8.4 thorpej aprint_normal(" channel %d", args->channel);
194 1.1.8.2 nathanw
195 1.1.8.2 nathanw return UNCONF;
196 1.1.8.2 nathanw }
197 1.1.8.2 nathanw
198 1.1.8.2 nathanw int
199 1.1.8.2 nathanw zshard(arg)
200 1.1.8.2 nathanw void *arg;
201 1.1.8.2 nathanw {
202 1.1.8.2 nathanw register struct zsc_softc *zsc;
203 1.1.8.2 nathanw register int unit, rval;
204 1.1.8.2 nathanw
205 1.1.8.2 nathanw rval = 0;
206 1.1.8.2 nathanw for (unit = 0; unit < zsc_cd.cd_ndevs; unit++) {
207 1.1.8.2 nathanw zsc = zsc_cd.cd_devs[unit];
208 1.1.8.2 nathanw if (zsc == NULL)
209 1.1.8.2 nathanw continue;
210 1.1.8.2 nathanw rval |= zsc_intr_hard(zsc);
211 1.1.8.2 nathanw if ((zsc->zsc_cs[0]->cs_softreq) ||
212 1.1.8.2 nathanw (zsc->zsc_cs[1]->cs_softreq))
213 1.1.8.2 nathanw {
214 1.1.8.2 nathanw /* zsc_req_softint(zsc); */
215 1.1.8.2 nathanw /* We are at splzs here, so no need to lock. */
216 1.1.8.2 nathanw if (zssoftpending == 0) {
217 1.1.8.2 nathanw zssoftpending = 1;
218 1.1.8.2 nathanw setsoftzs();
219 1.1.8.2 nathanw }
220 1.1.8.2 nathanw }
221 1.1.8.2 nathanw }
222 1.1.8.2 nathanw return (rval);
223 1.1.8.2 nathanw }
224 1.1.8.2 nathanw
225 1.1.8.2 nathanw void
226 1.1.8.2 nathanw softzs()
227 1.1.8.2 nathanw {
228 1.1.8.2 nathanw register struct zsc_softc *zsc;
229 1.1.8.2 nathanw register int unit;
230 1.1.8.2 nathanw
231 1.1.8.2 nathanw /* This is not the only ISR on this IPL. */
232 1.1.8.2 nathanw if (zssoftpending == 0)
233 1.1.8.2 nathanw return;
234 1.1.8.2 nathanw
235 1.1.8.2 nathanw /*
236 1.1.8.2 nathanw * The soft intr. bit will be set by zshard only if
237 1.1.8.2 nathanw * the variable zssoftpending is zero.
238 1.1.8.2 nathanw */
239 1.1.8.2 nathanw zssoftpending = 0;
240 1.1.8.2 nathanw
241 1.1.8.2 nathanw for (unit = 0; unit < zsc_cd.cd_ndevs; ++unit) {
242 1.1.8.2 nathanw zsc = zsc_cd.cd_devs[unit];
243 1.1.8.2 nathanw if (zsc == NULL)
244 1.1.8.2 nathanw continue;
245 1.1.8.2 nathanw (void) zsc_intr_soft(zsc);
246 1.1.8.2 nathanw }
247 1.1.8.2 nathanw return;
248 1.1.8.2 nathanw }
249 1.1.8.2 nathanw
250 1.1.8.2 nathanw u_char
251 1.1.8.2 nathanw zs_read_reg(cs, reg)
252 1.1.8.2 nathanw struct zs_chanstate *cs;
253 1.1.8.2 nathanw u_char reg;
254 1.1.8.2 nathanw {
255 1.1.8.2 nathanw u_char val;
256 1.1.8.2 nathanw
257 1.1.8.2 nathanw *cs->cs_reg_csr = reg;
258 1.1.8.2 nathanw ZS_DELAY();
259 1.1.8.2 nathanw val = *cs->cs_reg_csr;
260 1.1.8.2 nathanw ZS_DELAY();
261 1.1.8.2 nathanw return val;
262 1.1.8.2 nathanw }
263 1.1.8.2 nathanw
264 1.1.8.2 nathanw void
265 1.1.8.2 nathanw zs_write_reg(cs, reg, val)
266 1.1.8.2 nathanw struct zs_chanstate *cs;
267 1.1.8.2 nathanw u_char reg, val;
268 1.1.8.2 nathanw {
269 1.1.8.2 nathanw *cs->cs_reg_csr = reg;
270 1.1.8.2 nathanw ZS_DELAY();
271 1.1.8.2 nathanw *cs->cs_reg_csr = val;
272 1.1.8.2 nathanw ZS_DELAY();
273 1.1.8.2 nathanw }
274 1.1.8.2 nathanw
275 1.1.8.2 nathanw u_char zs_read_csr(cs)
276 1.1.8.2 nathanw struct zs_chanstate *cs;
277 1.1.8.2 nathanw {
278 1.1.8.2 nathanw register u_char val;
279 1.1.8.2 nathanw
280 1.1.8.2 nathanw val = *cs->cs_reg_csr;
281 1.1.8.2 nathanw ZS_DELAY();
282 1.1.8.2 nathanw return val;
283 1.1.8.2 nathanw }
284 1.1.8.2 nathanw
285 1.1.8.2 nathanw void zs_write_csr(cs, val)
286 1.1.8.2 nathanw struct zs_chanstate *cs;
287 1.1.8.2 nathanw u_char val;
288 1.1.8.2 nathanw {
289 1.1.8.2 nathanw *cs->cs_reg_csr = val;
290 1.1.8.2 nathanw ZS_DELAY();
291 1.1.8.2 nathanw }
292 1.1.8.2 nathanw
293 1.1.8.2 nathanw u_char zs_read_data(cs)
294 1.1.8.2 nathanw struct zs_chanstate *cs;
295 1.1.8.2 nathanw {
296 1.1.8.2 nathanw register u_char val;
297 1.1.8.2 nathanw
298 1.1.8.2 nathanw val = *cs->cs_reg_data;
299 1.1.8.2 nathanw ZS_DELAY();
300 1.1.8.2 nathanw return val;
301 1.1.8.2 nathanw }
302 1.1.8.2 nathanw
303 1.1.8.2 nathanw void zs_write_data(cs, val)
304 1.1.8.2 nathanw struct zs_chanstate *cs;
305 1.1.8.2 nathanw u_char val;
306 1.1.8.2 nathanw {
307 1.1.8.2 nathanw *cs->cs_reg_data = val;
308 1.1.8.2 nathanw ZS_DELAY();
309 1.1.8.2 nathanw }
310 1.1.8.2 nathanw
311 1.1.8.2 nathanw int
312 1.1.8.2 nathanw zs_set_speed(cs, bps)
313 1.1.8.2 nathanw struct zs_chanstate *cs;
314 1.1.8.2 nathanw int bps; /* bits per second */
315 1.1.8.2 nathanw {
316 1.1.8.2 nathanw int tconst, real_bps;
317 1.1.8.2 nathanw
318 1.1.8.2 nathanw tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
319 1.1.8.2 nathanw
320 1.1.8.2 nathanw if (tconst < 0)
321 1.1.8.2 nathanw return (EINVAL);
322 1.1.8.2 nathanw
323 1.1.8.2 nathanw /* Convert back to make sure we can do it. */
324 1.1.8.2 nathanw real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
325 1.1.8.2 nathanw #if 0
326 1.1.8.2 nathanw /* XXX - Allow some tolerance here? */
327 1.1.8.2 nathanw if (real_bps != bps)
328 1.1.8.2 nathanw return (EINVAL);
329 1.1.8.2 nathanw #endif
330 1.1.8.2 nathanw cs->cs_preg[12] = tconst;
331 1.1.8.2 nathanw cs->cs_preg[13] = tconst >> 8;
332 1.1.8.2 nathanw
333 1.1.8.2 nathanw return (0);
334 1.1.8.2 nathanw }
335 1.1.8.2 nathanw
336 1.1.8.2 nathanw int
337 1.1.8.2 nathanw zs_set_modes(cs, cflag)
338 1.1.8.2 nathanw struct zs_chanstate *cs;
339 1.1.8.2 nathanw int cflag; /* bits per second */
340 1.1.8.2 nathanw {
341 1.1.8.2 nathanw int s;
342 1.1.8.2 nathanw
343 1.1.8.2 nathanw /*
344 1.1.8.2 nathanw * Output hardware flow control on the chip is horrendous:
345 1.1.8.2 nathanw * if carrier detect drops, the receiver is disabled, and if
346 1.1.8.2 nathanw * CTS drops, the transmitter is stoped IN MID CHARACTER!
347 1.1.8.2 nathanw * Therefore, NEVER set the HFC bit, and instead use the
348 1.1.8.2 nathanw * status interrupt to detect CTS changes.
349 1.1.8.2 nathanw */
350 1.1.8.2 nathanw s = splzs();
351 1.1.8.2 nathanw #if 0 /* XXX - See below. */
352 1.1.8.2 nathanw if (cflag & CLOCAL) {
353 1.1.8.2 nathanw cs->cs_rr0_dcd = 0;
354 1.1.8.2 nathanw cs->cs_preg[15] &= ~ZSWR15_DCD_IE;
355 1.1.8.2 nathanw } else {
356 1.1.8.2 nathanw /* XXX - Need to notice DCD change here... */
357 1.1.8.2 nathanw cs->cs_rr0_dcd = ZSRR0_DCD;
358 1.1.8.2 nathanw cs->cs_preg[15] |= ZSWR15_DCD_IE;
359 1.1.8.2 nathanw }
360 1.1.8.2 nathanw #endif /* XXX */
361 1.1.8.2 nathanw if (cflag & CRTSCTS) {
362 1.1.8.2 nathanw cs->cs_wr5_dtr = ZSWR5_DTR;
363 1.1.8.2 nathanw cs->cs_wr5_rts = ZSWR5_RTS;
364 1.1.8.2 nathanw cs->cs_rr0_cts = ZSRR0_CTS;
365 1.1.8.2 nathanw cs->cs_preg[15] |= ZSWR15_CTS_IE;
366 1.1.8.2 nathanw } else {
367 1.1.8.2 nathanw cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
368 1.1.8.2 nathanw cs->cs_wr5_rts = 0;
369 1.1.8.2 nathanw cs->cs_rr0_cts = 0;
370 1.1.8.2 nathanw cs->cs_preg[15] &= ~ZSWR15_CTS_IE;
371 1.1.8.2 nathanw }
372 1.1.8.2 nathanw splx(s);
373 1.1.8.2 nathanw
374 1.1.8.2 nathanw /* Caller will stuff the pending registers. */
375 1.1.8.2 nathanw return (0);
376 1.1.8.2 nathanw }
377 1.1.8.2 nathanw
378 1.1.8.2 nathanw /*
379 1.1.8.2 nathanw * Handle user request to enter kernel debugger.
380 1.1.8.2 nathanw */
381 1.1.8.2 nathanw void
382 1.1.8.2 nathanw zs_abort(cs)
383 1.1.8.2 nathanw struct zs_chanstate *cs;
384 1.1.8.2 nathanw {
385 1.1.8.2 nathanw int rr0;
386 1.1.8.2 nathanw
387 1.1.8.2 nathanw /* Wait for end of break to avoid PROM abort. */
388 1.1.8.2 nathanw /* XXX - Limit the wait? */
389 1.1.8.2 nathanw do {
390 1.1.8.2 nathanw rr0 = *cs->cs_reg_csr;
391 1.1.8.2 nathanw ZS_DELAY();
392 1.1.8.2 nathanw } while (rr0 & ZSRR0_BREAK);
393 1.1.8.2 nathanw #ifdef DDB
394 1.1.8.2 nathanw console_debugger();
395 1.1.8.2 nathanw #endif
396 1.1.8.2 nathanw }
397 1.1.8.2 nathanw
398 1.1.8.2 nathanw /*
399 1.1.8.2 nathanw * Polled input char.
400 1.1.8.2 nathanw */
401 1.1.8.2 nathanw int
402 1.1.8.2 nathanw zs_getc(arg)
403 1.1.8.2 nathanw void *arg;
404 1.1.8.2 nathanw {
405 1.1.8.2 nathanw register struct zs_chanstate *cs = arg;
406 1.1.8.2 nathanw register int s, c, rr0, stat;
407 1.1.8.2 nathanw
408 1.1.8.2 nathanw s = splhigh();
409 1.1.8.2 nathanw top:
410 1.1.8.2 nathanw /* Wait for a character to arrive. */
411 1.1.8.2 nathanw do {
412 1.1.8.2 nathanw rr0 = *cs->cs_reg_csr;
413 1.1.8.2 nathanw ZS_DELAY();
414 1.1.8.2 nathanw } while ((rr0 & ZSRR0_RX_READY) == 0);
415 1.1.8.2 nathanw
416 1.1.8.2 nathanw /* Read error register. */
417 1.1.8.2 nathanw stat = zs_read_reg(cs, 1) & (ZSRR1_FE | ZSRR1_DO | ZSRR1_PE);
418 1.1.8.2 nathanw if (stat) {
419 1.1.8.2 nathanw zs_write_csr(cs, ZSM_RESET_ERR);
420 1.1.8.2 nathanw goto top;
421 1.1.8.2 nathanw }
422 1.1.8.2 nathanw
423 1.1.8.2 nathanw /* Read character. */
424 1.1.8.2 nathanw c = *cs->cs_reg_data;
425 1.1.8.2 nathanw ZS_DELAY();
426 1.1.8.2 nathanw splx(s);
427 1.1.8.2 nathanw
428 1.1.8.2 nathanw return (c);
429 1.1.8.2 nathanw }
430 1.1.8.2 nathanw
431 1.1.8.2 nathanw /*
432 1.1.8.2 nathanw * Polled output char.
433 1.1.8.2 nathanw */
434 1.1.8.2 nathanw void
435 1.1.8.2 nathanw zs_putc(arg, c)
436 1.1.8.2 nathanw void *arg;
437 1.1.8.2 nathanw int c;
438 1.1.8.2 nathanw {
439 1.1.8.2 nathanw register struct zs_chanstate *cs = arg;
440 1.1.8.2 nathanw register int s, rr0;
441 1.1.8.2 nathanw
442 1.1.8.2 nathanw s = splhigh();
443 1.1.8.2 nathanw /* Wait for transmitter to become ready. */
444 1.1.8.2 nathanw do {
445 1.1.8.2 nathanw rr0 = *cs->cs_reg_csr;
446 1.1.8.2 nathanw ZS_DELAY();
447 1.1.8.2 nathanw } while ((rr0 & ZSRR0_TX_READY) == 0);
448 1.1.8.2 nathanw
449 1.1.8.2 nathanw *cs->cs_reg_data = c;
450 1.1.8.2 nathanw ZS_DELAY();
451 1.1.8.2 nathanw splx(s);
452 1.1.8.2 nathanw }
453 1.1.8.2 nathanw
454 1.1.8.2 nathanw int zscngetc(dev)
455 1.1.8.2 nathanw dev_t dev;
456 1.1.8.2 nathanw {
457 1.1.8.2 nathanw register struct zs_chanstate *cs = &zs_conschan_store;
458 1.1.8.2 nathanw register int c;
459 1.1.8.2 nathanw
460 1.1.8.2 nathanw c = zs_getc(cs);
461 1.1.8.2 nathanw return (c);
462 1.1.8.2 nathanw }
463 1.1.8.2 nathanw
464 1.1.8.2 nathanw void zscnputc(dev, c)
465 1.1.8.2 nathanw dev_t dev;
466 1.1.8.2 nathanw int c;
467 1.1.8.2 nathanw {
468 1.1.8.2 nathanw register struct zs_chanstate *cs = &zs_conschan_store;
469 1.1.8.2 nathanw
470 1.1.8.2 nathanw zs_putc(cs, c);
471 1.1.8.2 nathanw }
472 1.1.8.2 nathanw
473 1.1.8.2 nathanw /*
474 1.1.8.2 nathanw * Common parts of console init.
475 1.1.8.2 nathanw */
476 1.1.8.2 nathanw void
477 1.1.8.2 nathanw zs_cninit(base)
478 1.1.8.2 nathanw void *base;
479 1.1.8.2 nathanw {
480 1.1.8.2 nathanw struct zs_chanstate *cs;
481 1.1.8.2 nathanw /*
482 1.1.8.2 nathanw * Pointer to channel state. Later, the console channel
483 1.1.8.2 nathanw * state is copied into the softc, and the console channel
484 1.1.8.2 nathanw * pointer adjusted to point to the new copy.
485 1.1.8.2 nathanw */
486 1.1.8.2 nathanw cs = &zs_conschan_store;
487 1.1.8.2 nathanw zs_hwflags[0][0] = ZS_HWFLAG_CONSOLE;
488 1.1.8.2 nathanw
489 1.1.8.2 nathanw /* Setup temporary chanstate. */
490 1.1.8.3 nathanw cs->cs_reg_csr = (char *)base + 7;
491 1.1.8.3 nathanw cs->cs_reg_data = (char *)base + 15;
492 1.1.8.2 nathanw
493 1.1.8.2 nathanw /* Initialize the pending registers. */
494 1.1.8.2 nathanw bcopy(zs_init_reg, cs->cs_preg, 16);
495 1.1.8.2 nathanw cs->cs_preg[5] |= (ZSWR5_DTR | ZSWR5_RTS);
496 1.1.8.2 nathanw
497 1.1.8.2 nathanw /* XXX: Preserve BAUD rate from boot loader. */
498 1.1.8.2 nathanw /* XXX: Also, why reset the chip here? -gwr */
499 1.1.8.2 nathanw /* cs->cs_defspeed = zs_get_speed(cs); */
500 1.1.8.2 nathanw cs->cs_defspeed = 9600; /* XXX */
501 1.1.8.2 nathanw
502 1.1.8.2 nathanw /* Clear the master interrupt enable. */
503 1.1.8.2 nathanw zs_write_reg(cs, 9, 0);
504 1.1.8.2 nathanw
505 1.1.8.2 nathanw /* Reset the whole SCC chip. */
506 1.1.8.2 nathanw zs_write_reg(cs, 9, ZSWR9_HARD_RESET);
507 1.1.8.2 nathanw
508 1.1.8.2 nathanw /* Copy "pending" to "current" and H/W. */
509 1.1.8.2 nathanw zs_loadchannelregs(cs);
510 1.1.8.2 nathanw
511 1.1.8.2 nathanw /* Point the console at the SCC. */
512 1.1.8.2 nathanw cn_tab = &zscons;
513 1.1.8.2 nathanw }
514