zs.c revision 1.37 1 1.37 gwr /* $NetBSD: zs.c,v 1.37 1996/05/17 19:35:14 gwr Exp $ */
2 1.10 cgd
3 1.1 glass /*
4 1.31 gwr * Copyright (c) 1995 Gordon W. Ross
5 1.31 gwr * All rights reserved.
6 1.1 glass *
7 1.1 glass * Redistribution and use in source and binary forms, with or without
8 1.1 glass * modification, are permitted provided that the following conditions
9 1.1 glass * are met:
10 1.1 glass * 1. Redistributions of source code must retain the above copyright
11 1.1 glass * notice, this list of conditions and the following disclaimer.
12 1.1 glass * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 glass * notice, this list of conditions and the following disclaimer in the
14 1.1 glass * documentation and/or other materials provided with the distribution.
15 1.31 gwr * 3. The name of the author may not be used to endorse or promote products
16 1.31 gwr * derived from this software without specific prior written permission.
17 1.31 gwr * 4. All advertising materials mentioning features or use of this software
18 1.1 glass * must display the following acknowledgement:
19 1.31 gwr * This product includes software developed by Gordon Ross
20 1.1 glass *
21 1.31 gwr * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.31 gwr * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.31 gwr * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.31 gwr * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.31 gwr * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.31 gwr * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.31 gwr * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.31 gwr * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.31 gwr * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.31 gwr * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.1 glass */
32 1.1 glass
33 1.1 glass /*
34 1.31 gwr * Zilog Z8530 Dual UART driver (machine-dependent part)
35 1.1 glass *
36 1.31 gwr * Runs two serial lines per chip using slave drivers.
37 1.31 gwr * Plain tty/async lines use the zs_async slave.
38 1.31 gwr * Sun keyboard/mouse uses the zs_kbd/zs_ms slaves.
39 1.1 glass */
40 1.1 glass
41 1.5 gwr #include <sys/param.h>
42 1.1 glass #include <sys/systm.h>
43 1.1 glass #include <sys/proc.h>
44 1.1 glass #include <sys/device.h>
45 1.1 glass #include <sys/conf.h>
46 1.1 glass #include <sys/file.h>
47 1.1 glass #include <sys/ioctl.h>
48 1.1 glass #include <sys/tty.h>
49 1.1 glass #include <sys/time.h>
50 1.1 glass #include <sys/kernel.h>
51 1.1 glass #include <sys/syslog.h>
52 1.1 glass
53 1.31 gwr #include <dev/cons.h>
54 1.31 gwr #include <dev/ic/z8530reg.h>
55 1.31 gwr #include <machine/z8530var.h>
56 1.31 gwr
57 1.1 glass #include <machine/autoconf.h>
58 1.1 glass #include <machine/cpu.h>
59 1.31 gwr #include <machine/eeprom.h>
60 1.18 gwr #include <machine/isr.h>
61 1.1 glass #include <machine/obio.h>
62 1.3 gwr #include <machine/mon.h>
63 1.1 glass
64 1.16 gwr /*
65 1.31 gwr * XXX: Hard code this to make console init easier...
66 1.16 gwr */
67 1.31 gwr #define NZS 2 /* XXX */
68 1.1 glass
69 1.1 glass
70 1.2 glass /* The Sun3 provides a 4.9152 MHz clock to the ZS chips. */
71 1.2 glass #define PCLK (9600 * 512) /* PCLK pin input clock rate */
72 1.2 glass
73 1.2 glass /*
74 1.22 gwr * Define interrupt levels.
75 1.2 glass */
76 1.2 glass #define ZSHARD_PRI 6 /* Wired on the CPU board... */
77 1.22 gwr #define ZSSOFT_PRI 3 /* Want tty pri (4) but this is OK. */
78 1.1 glass
79 1.33 gwr #define ZS_DELAY() delay(2)
80 1.31 gwr
81 1.31 gwr /* The layout of this is hardware-dependent (padding, order). */
82 1.31 gwr struct zschan {
83 1.31 gwr volatile u_char zc_csr; /* ctrl,status, and indirect access */
84 1.31 gwr u_char zc_xxx0;
85 1.31 gwr volatile u_char zc_data; /* data */
86 1.31 gwr u_char zc_xxx1;
87 1.31 gwr };
88 1.31 gwr struct zsdevice {
89 1.31 gwr /* Yes, they are backwards. */
90 1.31 gwr struct zschan zs_chan_b;
91 1.31 gwr struct zschan zs_chan_a;
92 1.1 glass };
93 1.1 glass
94 1.1 glass
95 1.31 gwr /* Default OBIO addresses. */
96 1.31 gwr static int zs_physaddr[NZS] = { OBIO_KEYBD_MS, OBIO_ZS };
97 1.31 gwr /* Saved PROM mappings */
98 1.31 gwr static struct zsdevice *zsaddr[NZS]; /* See zs_init() */
99 1.31 gwr /* Flags from cninit() */
100 1.31 gwr static int zs_hwflags[NZS][2];
101 1.31 gwr /* Default speed for each channel */
102 1.31 gwr static int zs_defspeed[NZS][2] = {
103 1.31 gwr { 1200, /* keyboard */
104 1.31 gwr 1200 }, /* mouse */
105 1.31 gwr { 9600, /* ttya */
106 1.31 gwr 9600 }, /* ttyb */
107 1.31 gwr };
108 1.13 gwr
109 1.1 glass
110 1.31 gwr /* Find PROM mappings (for console support). */
111 1.31 gwr void zs_init()
112 1.31 gwr {
113 1.31 gwr int i;
114 1.1 glass
115 1.31 gwr for (i = 0; i < NZS; i++) {
116 1.31 gwr zsaddr[i] = (struct zsdevice *)
117 1.31 gwr obio_find_mapping(zs_physaddr[i], OBIO_ZS_SIZE);
118 1.31 gwr }
119 1.31 gwr }
120 1.1 glass
121 1.13 gwr
122 1.31 gwr struct zschan *
123 1.31 gwr zs_get_chan_addr(zsc_unit, channel)
124 1.31 gwr int zsc_unit, channel;
125 1.31 gwr {
126 1.31 gwr struct zsdevice *addr;
127 1.31 gwr struct zschan *zc;
128 1.31 gwr
129 1.31 gwr if (zsc_unit >= NZS)
130 1.31 gwr return NULL;
131 1.31 gwr addr = zsaddr[zsc_unit];
132 1.31 gwr if (addr == NULL)
133 1.31 gwr return NULL;
134 1.31 gwr if (channel == 0) {
135 1.31 gwr zc = &addr->zs_chan_a;
136 1.31 gwr } else {
137 1.31 gwr zc = &addr->zs_chan_b;
138 1.31 gwr }
139 1.31 gwr return (zc);
140 1.31 gwr }
141 1.13 gwr
142 1.18 gwr
143 1.18 gwr static u_char zs_init_reg[16] = {
144 1.18 gwr 0, /* 0: CMD (reset, etc.) */
145 1.18 gwr ZSWR1_RIE | ZSWR1_TIE | ZSWR1_SIE,
146 1.18 gwr 0x18 + ZSHARD_PRI, /* IVECT */
147 1.18 gwr ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
148 1.18 gwr ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
149 1.18 gwr ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
150 1.18 gwr 0, /* 6: TXSYNC/SYNCLO */
151 1.18 gwr 0, /* 7: RXSYNC/SYNCHI */
152 1.18 gwr 0, /* 8: alias for data port */
153 1.31 gwr ZSWR9_MASTER_IE,
154 1.18 gwr 0, /*10: Misc. TX/RX control bits */
155 1.18 gwr ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
156 1.31 gwr 14, /*12: BAUDLO (default=9600) */
157 1.31 gwr 0, /*13: BAUDHI (default=9600) */
158 1.18 gwr ZSWR14_BAUD_FROM_PCLK | ZSWR14_BAUD_ENA,
159 1.18 gwr ZSWR15_BREAK_IE | ZSWR15_DCD_IE,
160 1.18 gwr };
161 1.9 gwr
162 1.21 gwr
163 1.31 gwr /****************************************************************
164 1.31 gwr * Autoconfig
165 1.31 gwr ****************************************************************/
166 1.31 gwr
167 1.31 gwr /* Definition of the driver for autoconfig. */
168 1.35 gwr static int zsc_match __P((struct device *, void *, void *));
169 1.35 gwr static void zsc_attach __P((struct device *, struct device *, void *));
170 1.35 gwr static int zsc_print __P((void *, char *name));
171 1.31 gwr
172 1.34 thorpej struct cfattach zsc_ca = {
173 1.34 thorpej sizeof(struct zsc_softc), zsc_match, zsc_attach
174 1.34 thorpej };
175 1.34 thorpej
176 1.34 thorpej struct cfdriver zsc_cd = {
177 1.34 thorpej NULL, "zsc", DV_DULL
178 1.31 gwr };
179 1.31 gwr
180 1.31 gwr static int zshard(void *);
181 1.31 gwr static int zssoft(void *);
182 1.31 gwr
183 1.9 gwr
184 1.1 glass /*
185 1.31 gwr * Is the zs chip present?
186 1.1 glass */
187 1.1 glass static int
188 1.31 gwr zsc_match(parent, vcf, aux)
189 1.31 gwr struct device *parent;
190 1.35 gwr void *vcf, *aux;
191 1.1 glass {
192 1.12 gwr struct cfdata *cf = vcf;
193 1.31 gwr struct confargs *ca = aux;
194 1.35 gwr int pa, unit, x;
195 1.35 gwr void *va;
196 1.13 gwr
197 1.13 gwr unit = cf->cf_unit;
198 1.13 gwr if (unit < 0 || unit >= NZS)
199 1.13 gwr return (0);
200 1.1 glass
201 1.35 gwr /*
202 1.35 gwr * OBIO match functions may be called for every possible
203 1.35 gwr * physical address, so match only our physical address.
204 1.35 gwr * This driver only supports its default mappings, so
205 1.35 gwr * non-default locators must match our defaults.
206 1.35 gwr */
207 1.35 gwr if ((pa = cf->cf_paddr) == -1) {
208 1.35 gwr /* Use our default PA. */
209 1.35 gwr pa = zs_physaddr[unit];
210 1.35 gwr } else {
211 1.35 gwr /* Validate the given PA. */
212 1.35 gwr if (pa != zs_physaddr[unit])
213 1.35 gwr return (0);
214 1.35 gwr }
215 1.35 gwr if (pa != ca->ca_paddr)
216 1.35 gwr return (0);
217 1.35 gwr
218 1.31 gwr /* Make sure zs_init() found mappings. */
219 1.35 gwr va = zsaddr[unit];
220 1.35 gwr if (va == NULL)
221 1.21 gwr return (0);
222 1.21 gwr
223 1.21 gwr /* This returns -1 on a fault (bus error). */
224 1.35 gwr x = peek_byte(va);
225 1.14 gwr return (x != -1);
226 1.1 glass }
227 1.1 glass
228 1.1 glass /*
229 1.1 glass * Attach a found zs.
230 1.1 glass *
231 1.31 gwr * Match slave number to zs unit number, so that misconfiguration will
232 1.31 gwr * not set up the keyboard as ttya, etc.
233 1.1 glass */
234 1.1 glass static void
235 1.31 gwr zsc_attach(parent, self, aux)
236 1.31 gwr struct device *parent;
237 1.31 gwr struct device *self;
238 1.31 gwr void *aux;
239 1.31 gwr {
240 1.31 gwr struct zsc_softc *zsc = (void *) self;
241 1.35 gwr struct cfdata *cf = self->dv_cfdata;
242 1.31 gwr struct confargs *ca = aux;
243 1.31 gwr struct zsc_attach_args zsc_args;
244 1.31 gwr volatile struct zschan *zc;
245 1.31 gwr struct zs_chanstate *cs;
246 1.35 gwr int zsc_unit, intpri, channel;
247 1.31 gwr int reset, s;
248 1.2 glass static int didintr;
249 1.2 glass
250 1.31 gwr zsc_unit = zsc->zsc_dev.dv_unit;
251 1.13 gwr
252 1.35 gwr if ((intpri = cf->cf_intpri) == -1)
253 1.35 gwr intpri = ZSHARD_PRI;
254 1.35 gwr
255 1.35 gwr printf(" level %d (softpri %d)\n", intpri, ZSSOFT_PRI);
256 1.1 glass
257 1.31 gwr /* Use the mapping setup by the Sun PROM. */
258 1.31 gwr if (zsaddr[zsc_unit] == NULL)
259 1.31 gwr panic("zs_attach: zs%d not mapped\n", zsc_unit);
260 1.31 gwr
261 1.31 gwr /*
262 1.31 gwr * Initialize software state for each channel.
263 1.31 gwr */
264 1.31 gwr for (channel = 0; channel < 2; channel++) {
265 1.31 gwr cs = &zsc->zsc_cs[channel];
266 1.31 gwr
267 1.31 gwr zc = zs_get_chan_addr(zsc_unit, channel);
268 1.31 gwr cs->cs_reg_csr = &zc->zc_csr;
269 1.31 gwr cs->cs_reg_data = &zc->zc_data;
270 1.1 glass
271 1.31 gwr cs->cs_channel = channel;
272 1.31 gwr cs->cs_private = NULL;
273 1.31 gwr cs->cs_ops = &zsops_null;
274 1.31 gwr
275 1.31 gwr /* Define BAUD rate clock for the MI code. */
276 1.37 gwr cs->cs_brg_clk = PCLK / 16;
277 1.31 gwr
278 1.31 gwr /* XXX: get defspeed from EEPROM instead? */
279 1.31 gwr cs->cs_defspeed = zs_defspeed[zsc_unit][channel];
280 1.2 glass
281 1.31 gwr bcopy(zs_init_reg, cs->cs_creg, 16);
282 1.31 gwr bcopy(zs_init_reg, cs->cs_preg, 16);
283 1.15 gwr
284 1.1 glass /*
285 1.31 gwr * Clear the master interrupt enable.
286 1.31 gwr * The INTENA is common to both channels,
287 1.31 gwr * so just do it on the A channel.
288 1.1 glass */
289 1.31 gwr if (channel == 0) {
290 1.32 gwr zs_write_reg(cs, 9, 0);
291 1.31 gwr }
292 1.15 gwr
293 1.1 glass /*
294 1.31 gwr * Look for a child driver for this channel.
295 1.31 gwr * The child attach will setup the hardware.
296 1.1 glass */
297 1.31 gwr zsc_args.channel = channel;
298 1.31 gwr zsc_args.hwflags = zs_hwflags[zsc_unit][channel];
299 1.36 cgd if (config_found(self, (void *)&zsc_args, zsc_print) == NULL) {
300 1.31 gwr /* No sub-driver. Just reset it. */
301 1.31 gwr reset = (channel == 0) ?
302 1.31 gwr ZSWR9_A_RESET : ZSWR9_B_RESET;
303 1.31 gwr s = splzs();
304 1.32 gwr zs_write_reg(cs, 9, reset);
305 1.31 gwr splx(s);
306 1.31 gwr }
307 1.1 glass }
308 1.1 glass
309 1.31 gwr /* Now safe to install interrupt handlers */
310 1.31 gwr if (!didintr) {
311 1.31 gwr didintr = 1;
312 1.31 gwr isr_add_autovect(zssoft, NULL, ZSSOFT_PRI);
313 1.31 gwr isr_add_autovect(zshard, NULL, ZSHARD_PRI);
314 1.31 gwr }
315 1.24 gwr
316 1.31 gwr /*
317 1.31 gwr * Set the master interrupt enable and interrupt vector.
318 1.31 gwr * (common to both channels, do it on A)
319 1.31 gwr */
320 1.31 gwr cs = &zsc->zsc_cs[0];
321 1.31 gwr s = splzs();
322 1.31 gwr /* interrupt vector */
323 1.32 gwr zs_write_reg(cs, 2, zs_init_reg[2]);
324 1.31 gwr /* master interrupt control (enable) */
325 1.32 gwr zs_write_reg(cs, 9, zs_init_reg[9]);
326 1.31 gwr splx(s);
327 1.35 gwr }
328 1.35 gwr
329 1.35 gwr static int
330 1.35 gwr zsc_print(aux, name)
331 1.35 gwr void *aux;
332 1.35 gwr char *name;
333 1.35 gwr {
334 1.35 gwr struct zsc_attach_args *args = aux;
335 1.35 gwr
336 1.35 gwr if (name != NULL)
337 1.35 gwr printf("%s: ", name);
338 1.35 gwr
339 1.35 gwr if (args->channel != -1)
340 1.35 gwr printf(" channel %d", args->channel);
341 1.35 gwr
342 1.35 gwr return UNCONF;
343 1.24 gwr }
344 1.24 gwr
345 1.31 gwr static int
346 1.31 gwr zshard(arg)
347 1.31 gwr void *arg;
348 1.1 glass {
349 1.31 gwr struct zsc_softc *zsc;
350 1.31 gwr int unit, rval;
351 1.31 gwr
352 1.31 gwr /* Do ttya/ttyb first, because they go faster. */
353 1.31 gwr rval = 0;
354 1.34 thorpej unit = zsc_cd.cd_ndevs;
355 1.31 gwr while (--unit >= 0) {
356 1.34 thorpej zsc = zsc_cd.cd_devs[unit];
357 1.31 gwr if (zsc != NULL) {
358 1.31 gwr rval |= zsc_intr_hard(zsc);
359 1.31 gwr }
360 1.31 gwr }
361 1.31 gwr return (rval);
362 1.1 glass }
363 1.1 glass
364 1.31 gwr int zssoftpending;
365 1.2 glass
366 1.31 gwr void
367 1.31 gwr zsc_req_softint(zsc)
368 1.31 gwr struct zsc_softc *zsc;
369 1.31 gwr {
370 1.31 gwr if (zssoftpending == 0) {
371 1.31 gwr /* We are at splzs here, so no need to lock. */
372 1.31 gwr zssoftpending = ZSSOFT_PRI;
373 1.31 gwr isr_soft_request(ZSSOFT_PRI);
374 1.3 gwr }
375 1.3 gwr }
376 1.3 gwr
377 1.3 gwr static int
378 1.31 gwr zssoft(arg)
379 1.31 gwr void *arg;
380 1.3 gwr {
381 1.31 gwr struct zsc_softc *zsc;
382 1.31 gwr int unit;
383 1.31 gwr
384 1.31 gwr /* This is not the only ISR on this IPL. */
385 1.31 gwr if (zssoftpending == 0)
386 1.31 gwr return (0);
387 1.3 gwr
388 1.31 gwr /*
389 1.31 gwr * The soft intr. bit will be set by zshard only if
390 1.31 gwr * the variable zssoftpending is zero. The order of
391 1.31 gwr * these next two statements prevents our clearing
392 1.31 gwr * the soft intr bit just after zshard has set it.
393 1.31 gwr */
394 1.31 gwr isr_soft_clear(ZSSOFT_PRI);
395 1.31 gwr zssoftpending = 0;
396 1.2 glass
397 1.31 gwr /* Do ttya/ttyb first, because they go faster. */
398 1.34 thorpej unit = zsc_cd.cd_ndevs;
399 1.31 gwr while (--unit >= 0) {
400 1.34 thorpej zsc = zsc_cd.cd_devs[unit];
401 1.31 gwr if (zsc != NULL) {
402 1.31 gwr (void) zsc_intr_soft(zsc);
403 1.31 gwr }
404 1.3 gwr }
405 1.31 gwr return (1);
406 1.2 glass }
407 1.2 glass
408 1.2 glass
409 1.31 gwr /*
410 1.31 gwr * Read or write the chip with suitable delays.
411 1.31 gwr */
412 1.2 glass
413 1.31 gwr u_char
414 1.31 gwr zs_read_reg(cs, reg)
415 1.31 gwr struct zs_chanstate *cs;
416 1.31 gwr u_char reg;
417 1.1 glass {
418 1.31 gwr u_char val;
419 1.1 glass
420 1.31 gwr *cs->cs_reg_csr = reg;
421 1.31 gwr ZS_DELAY();
422 1.31 gwr val = *cs->cs_reg_csr;
423 1.31 gwr ZS_DELAY();
424 1.31 gwr return val;
425 1.17 gwr }
426 1.3 gwr
427 1.31 gwr void
428 1.31 gwr zs_write_reg(cs, reg, val)
429 1.31 gwr struct zs_chanstate *cs;
430 1.31 gwr u_char reg, val;
431 1.17 gwr {
432 1.31 gwr *cs->cs_reg_csr = reg;
433 1.31 gwr ZS_DELAY();
434 1.31 gwr *cs->cs_reg_csr = val;
435 1.32 gwr ZS_DELAY();
436 1.32 gwr }
437 1.32 gwr
438 1.32 gwr u_char zs_read_csr(cs)
439 1.32 gwr struct zs_chanstate *cs;
440 1.32 gwr {
441 1.32 gwr register u_char v;
442 1.32 gwr
443 1.32 gwr v = *cs->cs_reg_csr;
444 1.32 gwr ZS_DELAY();
445 1.32 gwr return v;
446 1.32 gwr }
447 1.32 gwr
448 1.32 gwr u_char zs_read_data(cs)
449 1.32 gwr struct zs_chanstate *cs;
450 1.32 gwr {
451 1.32 gwr register u_char v;
452 1.32 gwr
453 1.32 gwr v = *cs->cs_reg_data;
454 1.32 gwr ZS_DELAY();
455 1.32 gwr return v;
456 1.32 gwr }
457 1.32 gwr
458 1.32 gwr void zs_write_csr(cs, val)
459 1.32 gwr struct zs_chanstate *cs;
460 1.32 gwr u_char val;
461 1.32 gwr {
462 1.32 gwr *cs->cs_reg_csr = val;
463 1.32 gwr ZS_DELAY();
464 1.32 gwr }
465 1.32 gwr
466 1.32 gwr void zs_write_data(cs, val)
467 1.32 gwr struct zs_chanstate *cs;
468 1.32 gwr u_char val;
469 1.32 gwr {
470 1.32 gwr *cs->cs_reg_data = val;
471 1.31 gwr ZS_DELAY();
472 1.1 glass }
473 1.3 gwr
474 1.31 gwr /****************************************************************
475 1.31 gwr * Console support functions (Sun3 specific!)
476 1.31 gwr ****************************************************************/
477 1.1 glass
478 1.2 glass /*
479 1.31 gwr * Polled input char.
480 1.2 glass */
481 1.2 glass int
482 1.31 gwr zs_getc(arg)
483 1.31 gwr void *arg;
484 1.2 glass {
485 1.31 gwr register volatile struct zschan *zc = arg;
486 1.25 gwr register int s, c, rr0;
487 1.2 glass
488 1.2 glass s = splhigh();
489 1.9 gwr /* Wait for a character to arrive. */
490 1.25 gwr do {
491 1.25 gwr rr0 = zc->zc_csr;
492 1.3 gwr ZS_DELAY();
493 1.25 gwr } while ((rr0 & ZSRR0_RX_READY) == 0);
494 1.9 gwr
495 1.2 glass c = zc->zc_data;
496 1.9 gwr ZS_DELAY();
497 1.2 glass splx(s);
498 1.17 gwr
499 1.17 gwr /*
500 1.17 gwr * This is used by the kd driver to read scan codes,
501 1.17 gwr * so don't translate '\r' ==> '\n' here...
502 1.17 gwr */
503 1.2 glass return (c);
504 1.2 glass }
505 1.1 glass
506 1.1 glass /*
507 1.31 gwr * Polled output char.
508 1.1 glass */
509 1.31 gwr void
510 1.31 gwr zs_putc(arg, c)
511 1.31 gwr void *arg;
512 1.1 glass int c;
513 1.1 glass {
514 1.31 gwr register volatile struct zschan *zc = arg;
515 1.25 gwr register int s, rr0;
516 1.1 glass
517 1.9 gwr s = splhigh();
518 1.9 gwr /* Wait for transmitter to become ready. */
519 1.25 gwr do {
520 1.25 gwr rr0 = zc->zc_csr;
521 1.3 gwr ZS_DELAY();
522 1.25 gwr } while ((rr0 & ZSRR0_TX_READY) == 0);
523 1.9 gwr
524 1.1 glass zc->zc_data = c;
525 1.3 gwr ZS_DELAY();
526 1.1 glass splx(s);
527 1.1 glass }
528 1.2 glass
529 1.31 gwr extern struct consdev consdev_kd; /* keyboard/display */
530 1.31 gwr extern struct consdev consdev_tty;
531 1.31 gwr extern struct consdev *cn_tab; /* physical console device info */
532 1.31 gwr extern void nullcnpollc();
533 1.31 gwr
534 1.31 gwr void *zs_conschan;
535 1.31 gwr
536 1.1 glass /*
537 1.31 gwr * This function replaces sys/dev/cninit.c
538 1.31 gwr * Determine which device is the console using
539 1.31 gwr * the "console" byte from the EEPROM.
540 1.1 glass */
541 1.31 gwr void
542 1.31 gwr cninit()
543 1.1 glass {
544 1.31 gwr struct zschan *zc;
545 1.31 gwr struct consdev *cn;
546 1.31 gwr int zsc_unit, channel;
547 1.31 gwr
548 1.31 gwr switch (ee_console) {
549 1.31 gwr
550 1.31 gwr case EE_CONS_TTYA:
551 1.31 gwr case EE_CONS_TTYB:
552 1.31 gwr zsc_unit = 1;
553 1.31 gwr channel = (ee_console & 1);
554 1.31 gwr cn = &consdev_tty;
555 1.31 gwr cn->cn_dev = makedev(ZSTTY_MAJOR, channel);
556 1.31 gwr cn->cn_pri = CN_REMOTE;
557 1.31 gwr break;
558 1.1 glass
559 1.31 gwr default:
560 1.31 gwr mon_printf("cninit: unknown eeprom console setting\n");
561 1.31 gwr /* assume keyboard/display */
562 1.31 gwr /* fallthrough */
563 1.31 gwr case EE_CONS_BW:
564 1.31 gwr case EE_CONS_COLOR:
565 1.31 gwr case EE_CONS_P4OPT:
566 1.31 gwr zsc_unit = 0;
567 1.31 gwr channel = 0;
568 1.31 gwr cn = &consdev_kd;
569 1.31 gwr /* Set cn_dev, cn_pri in kd.c */
570 1.31 gwr break;
571 1.1 glass }
572 1.1 glass
573 1.31 gwr zc = zs_get_chan_addr(zsc_unit, channel);
574 1.31 gwr if (zc == NULL) {
575 1.31 gwr mon_printf("cninit: zs not mapped.\n");
576 1.31 gwr return;
577 1.31 gwr }
578 1.31 gwr zs_conschan = zc;
579 1.31 gwr zs_hwflags[zsc_unit][channel] = ZS_HWFLAG_CONSOLE;
580 1.31 gwr cn_tab = cn;
581 1.31 gwr (*cn->cn_init)(cn);
582 1.1 glass }
583 1.1 glass
584 1.1 glass
585 1.31 gwr /* We never call this. */
586 1.31 gwr void
587 1.31 gwr nullcnprobe(cn)
588 1.31 gwr struct consdev *cn;
589 1.1 glass {
590 1.1 glass }
591 1.1 glass
592 1.31 gwr void
593 1.31 gwr zscninit(cn)
594 1.31 gwr struct consdev *cn;
595 1.1 glass {
596 1.31 gwr int unit = minor(cn->cn_dev) & 1;
597 1.1 glass
598 1.31 gwr mon_printf("console is zstty%d (tty%c)\n",
599 1.31 gwr unit, unit + 'a');
600 1.1 glass }
601 1.1 glass
602 1.1 glass /*
603 1.31 gwr * Polled console input putchar.
604 1.1 glass */
605 1.1 glass int
606 1.31 gwr zscngetc(dev)
607 1.29 gwr dev_t dev;
608 1.1 glass {
609 1.31 gwr register volatile struct zschan *zc = zs_conschan;
610 1.31 gwr register int c;
611 1.1 glass
612 1.31 gwr c = zs_getc(zc);
613 1.31 gwr return (c);
614 1.1 glass }
615 1.1 glass
616 1.1 glass /*
617 1.31 gwr * Polled console output putchar.
618 1.1 glass */
619 1.31 gwr void
620 1.31 gwr zscnputc(dev, c)
621 1.29 gwr dev_t dev;
622 1.31 gwr int c;
623 1.1 glass {
624 1.31 gwr register volatile struct zschan *zc = zs_conschan;
625 1.1 glass
626 1.31 gwr zs_putc(zc, c);
627 1.1 glass }
628 1.1 glass
629 1.1 glass
630 1.31 gwr struct consdev consdev_tty = {
631 1.31 gwr nullcnprobe,
632 1.31 gwr zscninit,
633 1.31 gwr zscngetc,
634 1.31 gwr zscnputc,
635 1.31 gwr nullcnpollc,
636 1.31 gwr };
637 1.31 gwr
638 1.1 glass
639 1.1 glass /*
640 1.31 gwr * Handle user request to enter kernel debugger.
641 1.1 glass */
642 1.31 gwr void
643 1.31 gwr zs_abort()
644 1.1 glass {
645 1.31 gwr register volatile struct zschan *zc = zs_conschan;
646 1.31 gwr int rr0;
647 1.3 gwr
648 1.31 gwr /* Wait for end of break to avoid PROM abort. */
649 1.31 gwr /* XXX - Limit the wait? */
650 1.31 gwr do {
651 1.31 gwr rr0 = zc->zc_csr;
652 1.31 gwr ZS_DELAY();
653 1.31 gwr } while (rr0 & ZSRR0_BREAK);
654 1.1 glass
655 1.31 gwr /* XXX - Always available, but may be the PROM monitor. */
656 1.31 gwr Debugger();
657 1.1 glass }
658