zs.c revision 1.31.4.3 1 1.31.4.3 nathanw /* $NetBSD: zs.c,v 1.31.4.3 2002/09/17 21:17:59 nathanw Exp $ */
2 1.31.4.2 nathanw
3 1.31.4.2 nathanw /*-
4 1.31.4.2 nathanw * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 1.31.4.2 nathanw * All rights reserved.
6 1.31.4.2 nathanw *
7 1.31.4.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.31.4.2 nathanw * by Gordon W. Ross.
9 1.31.4.2 nathanw *
10 1.31.4.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.31.4.2 nathanw * modification, are permitted provided that the following conditions
12 1.31.4.2 nathanw * are met:
13 1.31.4.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.31.4.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.31.4.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.31.4.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.31.4.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.31.4.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.31.4.2 nathanw * must display the following acknowledgement:
20 1.31.4.2 nathanw * This product includes software developed by the NetBSD
21 1.31.4.2 nathanw * Foundation, Inc. and its contributors.
22 1.31.4.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.31.4.2 nathanw * contributors may be used to endorse or promote products derived
24 1.31.4.2 nathanw * from this software without specific prior written permission.
25 1.31.4.2 nathanw *
26 1.31.4.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.31.4.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.31.4.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.31.4.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.31.4.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.31.4.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.31.4.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.31.4.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.31.4.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.31.4.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.31.4.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.31.4.2 nathanw */
38 1.31.4.2 nathanw
39 1.31.4.2 nathanw /*
40 1.31.4.2 nathanw * Zilog Z8530 Dual UART driver (machine-dependent part)
41 1.31.4.2 nathanw *
42 1.31.4.2 nathanw * Runs two serial lines per chip using slave drivers.
43 1.31.4.2 nathanw * Plain tty/async lines use the zs_async slave.
44 1.31.4.2 nathanw * Sun keyboard/mouse uses the zs_kbd/zs_ms slaves.
45 1.31.4.2 nathanw */
46 1.31.4.2 nathanw
47 1.31.4.2 nathanw #include "opt_ddb.h"
48 1.31.4.2 nathanw #include "opt_kgdb.h"
49 1.31.4.2 nathanw
50 1.31.4.2 nathanw #include <sys/param.h>
51 1.31.4.2 nathanw #include <sys/systm.h>
52 1.31.4.2 nathanw #include <sys/conf.h>
53 1.31.4.2 nathanw #include <sys/device.h>
54 1.31.4.2 nathanw #include <sys/file.h>
55 1.31.4.2 nathanw #include <sys/ioctl.h>
56 1.31.4.2 nathanw #include <sys/kernel.h>
57 1.31.4.2 nathanw #include <sys/proc.h>
58 1.31.4.2 nathanw #include <sys/tty.h>
59 1.31.4.2 nathanw #include <sys/time.h>
60 1.31.4.2 nathanw #include <sys/syslog.h>
61 1.31.4.2 nathanw
62 1.31.4.2 nathanw #include <machine/autoconf.h>
63 1.31.4.2 nathanw #include <machine/openfirm.h>
64 1.31.4.2 nathanw #include <machine/cpu.h>
65 1.31.4.2 nathanw #include <machine/eeprom.h>
66 1.31.4.2 nathanw #include <machine/psl.h>
67 1.31.4.2 nathanw #include <machine/z8530var.h>
68 1.31.4.2 nathanw
69 1.31.4.2 nathanw #include <dev/cons.h>
70 1.31.4.2 nathanw #include <dev/ic/z8530reg.h>
71 1.31.4.2 nathanw #include <dev/sun/kbd_ms_ttyvar.h>
72 1.31.4.2 nathanw #include <ddb/db_output.h>
73 1.31.4.2 nathanw
74 1.31.4.2 nathanw #include <sparc64/dev/cons.h>
75 1.31.4.2 nathanw
76 1.31.4.2 nathanw #include "kbd.h" /* NKBD */
77 1.31.4.2 nathanw #include "ms.h" /* NMS */
78 1.31.4.2 nathanw #include "zs.h" /* NZS */
79 1.31.4.2 nathanw
80 1.31.4.2 nathanw /* Make life easier for the initialized arrays here. */
81 1.31.4.2 nathanw #if NZS < 3
82 1.31.4.2 nathanw #undef NZS
83 1.31.4.2 nathanw #define NZS 3
84 1.31.4.2 nathanw #endif
85 1.31.4.2 nathanw
86 1.31.4.2 nathanw /*
87 1.31.4.2 nathanw * Some warts needed by z8530tty.c -
88 1.31.4.2 nathanw * The default parity REALLY needs to be the same as the PROM uses,
89 1.31.4.2 nathanw * or you can not see messages done with printf during boot-up...
90 1.31.4.2 nathanw */
91 1.31.4.2 nathanw int zs_def_cflag = (CREAD | CS8 | HUPCL);
92 1.31.4.2 nathanw
93 1.31.4.2 nathanw /*
94 1.31.4.2 nathanw * The Sun provides a 4.9152 MHz clock to the ZS chips.
95 1.31.4.2 nathanw */
96 1.31.4.2 nathanw #define PCLK (9600 * 512) /* PCLK pin input clock rate */
97 1.31.4.2 nathanw
98 1.31.4.2 nathanw #define ZS_DELAY()
99 1.31.4.2 nathanw
100 1.31.4.2 nathanw /* The layout of this is hardware-dependent (padding, order). */
101 1.31.4.2 nathanw struct zschan {
102 1.31.4.2 nathanw volatile u_char zc_csr; /* ctrl,status, and indirect access */
103 1.31.4.2 nathanw u_char zc_xxx0;
104 1.31.4.2 nathanw volatile u_char zc_data; /* data */
105 1.31.4.2 nathanw u_char zc_xxx1;
106 1.31.4.2 nathanw };
107 1.31.4.2 nathanw struct zsdevice {
108 1.31.4.2 nathanw /* Yes, they are backwards. */
109 1.31.4.2 nathanw struct zschan zs_chan_b;
110 1.31.4.2 nathanw struct zschan zs_chan_a;
111 1.31.4.2 nathanw };
112 1.31.4.2 nathanw
113 1.31.4.2 nathanw /* ZS channel used as the console device (if any) */
114 1.31.4.2 nathanw void *zs_conschan_get, *zs_conschan_put;
115 1.31.4.2 nathanw
116 1.31.4.2 nathanw /* Saved PROM mappings */
117 1.31.4.2 nathanw static struct zsdevice *zsaddr[NZS];
118 1.31.4.2 nathanw
119 1.31.4.2 nathanw static u_char zs_init_reg[16] = {
120 1.31.4.2 nathanw 0, /* 0: CMD (reset, etc.) */
121 1.31.4.2 nathanw 0, /* 1: No interrupts yet. */
122 1.31.4.2 nathanw 0, /* 2: IVECT */
123 1.31.4.2 nathanw ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
124 1.31.4.2 nathanw ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
125 1.31.4.2 nathanw ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
126 1.31.4.2 nathanw 0, /* 6: TXSYNC/SYNCLO */
127 1.31.4.2 nathanw 0, /* 7: RXSYNC/SYNCHI */
128 1.31.4.2 nathanw 0, /* 8: alias for data port */
129 1.31.4.2 nathanw ZSWR9_MASTER_IE | ZSWR9_NO_VECTOR,
130 1.31.4.2 nathanw 0, /*10: Misc. TX/RX control bits */
131 1.31.4.2 nathanw ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
132 1.31.4.2 nathanw ((PCLK/32)/9600)-2, /*12: BAUDLO (default=9600) */
133 1.31.4.2 nathanw 0, /*13: BAUDHI (default=9600) */
134 1.31.4.2 nathanw ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK,
135 1.31.4.2 nathanw ZSWR15_BREAK_IE,
136 1.31.4.2 nathanw };
137 1.31.4.2 nathanw
138 1.31.4.2 nathanw /* Console ops */
139 1.31.4.2 nathanw static int zscngetc __P((dev_t));
140 1.31.4.2 nathanw static void zscnputc __P((dev_t, int));
141 1.31.4.2 nathanw static void zscnpollc __P((dev_t, int));
142 1.31.4.2 nathanw
143 1.31.4.2 nathanw struct consdev zs_consdev = {
144 1.31.4.2 nathanw NULL,
145 1.31.4.2 nathanw NULL,
146 1.31.4.2 nathanw zscngetc,
147 1.31.4.2 nathanw zscnputc,
148 1.31.4.2 nathanw zscnpollc,
149 1.31.4.2 nathanw NULL,
150 1.31.4.2 nathanw };
151 1.31.4.2 nathanw
152 1.31.4.2 nathanw
153 1.31.4.2 nathanw /****************************************************************
154 1.31.4.2 nathanw * Autoconfig
155 1.31.4.2 nathanw ****************************************************************/
156 1.31.4.2 nathanw
157 1.31.4.2 nathanw /* Definition of the driver for autoconfig. */
158 1.31.4.2 nathanw static int zs_match_mainbus __P((struct device *, struct cfdata *, void *));
159 1.31.4.2 nathanw static void zs_attach_mainbus __P((struct device *, struct device *, void *));
160 1.31.4.2 nathanw
161 1.31.4.2 nathanw static void zs_attach __P((struct zsc_softc *, struct zsdevice *, int));
162 1.31.4.2 nathanw static int zs_print __P((void *, const char *name));
163 1.31.4.2 nathanw
164 1.31.4.2 nathanw /* Do we really need this ? */
165 1.31.4.2 nathanw struct cfattach zs_ca = {
166 1.31.4.2 nathanw sizeof(struct zsc_softc), zs_match_mainbus, zs_attach_mainbus
167 1.31.4.2 nathanw };
168 1.31.4.2 nathanw
169 1.31.4.2 nathanw struct cfattach zs_mainbus_ca = {
170 1.31.4.2 nathanw sizeof(struct zsc_softc), zs_match_mainbus, zs_attach_mainbus
171 1.31.4.2 nathanw };
172 1.31.4.2 nathanw
173 1.31.4.2 nathanw extern struct cfdriver zs_cd;
174 1.31.4.2 nathanw extern int stdinnode;
175 1.31.4.2 nathanw extern int fbnode;
176 1.31.4.2 nathanw
177 1.31.4.2 nathanw /* Interrupt handlers. */
178 1.31.4.2 nathanw int zscheckintr __P((void *));
179 1.31.4.2 nathanw static int zshard __P((void *));
180 1.31.4.2 nathanw static void zssoft __P((void *));
181 1.31.4.2 nathanw
182 1.31.4.2 nathanw static int zs_get_speed __P((struct zs_chanstate *));
183 1.31.4.2 nathanw
184 1.31.4.2 nathanw /* Console device support */
185 1.31.4.2 nathanw static int zs_console_flags __P((int, int, int));
186 1.31.4.2 nathanw
187 1.31.4.2 nathanw /* Power management hooks */
188 1.31.4.2 nathanw int zs_enable __P((struct zs_chanstate *));
189 1.31.4.2 nathanw void zs_disable __P((struct zs_chanstate *));
190 1.31.4.2 nathanw
191 1.31.4.2 nathanw /*
192 1.31.4.2 nathanw * Is the zs chip present?
193 1.31.4.2 nathanw */
194 1.31.4.2 nathanw static int
195 1.31.4.2 nathanw zs_match_mainbus(parent, cf, aux)
196 1.31.4.2 nathanw struct device *parent;
197 1.31.4.2 nathanw struct cfdata *cf;
198 1.31.4.2 nathanw void *aux;
199 1.31.4.2 nathanw {
200 1.31.4.2 nathanw struct sbus_attach_args *sa = aux;
201 1.31.4.2 nathanw
202 1.31.4.2 nathanw if (strcmp(cf->cf_driver->cd_name, sa->sa_name) != 0)
203 1.31.4.2 nathanw return (0);
204 1.31.4.2 nathanw
205 1.31.4.2 nathanw return (1);
206 1.31.4.2 nathanw }
207 1.31.4.2 nathanw
208 1.31.4.2 nathanw static void
209 1.31.4.2 nathanw zs_attach_mainbus(parent, self, aux)
210 1.31.4.2 nathanw struct device *parent;
211 1.31.4.2 nathanw struct device *self;
212 1.31.4.2 nathanw void *aux;
213 1.31.4.2 nathanw {
214 1.31.4.2 nathanw struct zsc_softc *zsc = (void *) self;
215 1.31.4.2 nathanw struct sbus_attach_args *sa = aux;
216 1.31.4.2 nathanw bus_space_handle_t bh;
217 1.31.4.2 nathanw int zs_unit = zsc->zsc_dev.dv_unit;
218 1.31.4.2 nathanw
219 1.31.4.2 nathanw if (sa->sa_nintr == 0) {
220 1.31.4.2 nathanw printf(" no interrupt lines\n");
221 1.31.4.2 nathanw return;
222 1.31.4.2 nathanw }
223 1.31.4.2 nathanw
224 1.31.4.2 nathanw /* Use the mapping setup by the Sun PROM if possible. */
225 1.31.4.2 nathanw if (zsaddr[zs_unit] == NULL) {
226 1.31.4.2 nathanw /* Only map registers once. */
227 1.31.4.2 nathanw if (sa->sa_npromvaddrs) {
228 1.31.4.2 nathanw /*
229 1.31.4.2 nathanw * We're converting from a 32-bit pointer to a 64-bit
230 1.31.4.2 nathanw * pointer. Since the 32-bit entity is negative, but
231 1.31.4.2 nathanw * the kernel is still mapped into the lower 4GB
232 1.31.4.2 nathanw * range, this needs to be zero-extended.
233 1.31.4.2 nathanw *
234 1.31.4.2 nathanw * XXXXX If we map the kernel and devices into the
235 1.31.4.2 nathanw * high 4GB range, this needs to be changed to
236 1.31.4.2 nathanw * sign-extend the address.
237 1.31.4.2 nathanw */
238 1.31.4.2 nathanw sparc_promaddr_to_handle(sa->sa_bustag,
239 1.31.4.2 nathanw sa->sa_promvaddrs[0], &bh);
240 1.31.4.2 nathanw
241 1.31.4.2 nathanw } else {
242 1.31.4.2 nathanw
243 1.31.4.2 nathanw if (sbus_bus_map(sa->sa_bustag, sa->sa_slot,
244 1.31.4.2 nathanw sa->sa_offset,
245 1.31.4.2 nathanw sa->sa_size,
246 1.31.4.2 nathanw BUS_SPACE_MAP_LINEAR,
247 1.31.4.2 nathanw &bh) != 0) {
248 1.31.4.2 nathanw printf("%s @ sbus: cannot map registers\n",
249 1.31.4.2 nathanw self->dv_xname);
250 1.31.4.2 nathanw return;
251 1.31.4.2 nathanw }
252 1.31.4.2 nathanw }
253 1.31.4.2 nathanw zsaddr[zs_unit] = (struct zsdevice *)
254 1.31.4.2 nathanw bus_space_vaddr(sa->sa_bustag, bh);
255 1.31.4.2 nathanw }
256 1.31.4.2 nathanw zsc->zsc_bustag = sa->sa_bustag;
257 1.31.4.2 nathanw zsc->zsc_dmatag = sa->sa_dmatag;
258 1.31.4.2 nathanw zsc->zsc_promunit = PROM_getpropint(sa->sa_node, "slave", -2);
259 1.31.4.2 nathanw zsc->zsc_node = sa->sa_node;
260 1.31.4.2 nathanw zs_attach(zsc, zsaddr[zs_unit], sa->sa_pri);
261 1.31.4.2 nathanw }
262 1.31.4.2 nathanw
263 1.31.4.2 nathanw /*
264 1.31.4.2 nathanw * Attach a found zs.
265 1.31.4.2 nathanw *
266 1.31.4.2 nathanw * USE ROM PROPERTIES port-a-ignore-cd AND port-b-ignore-cd FOR
267 1.31.4.2 nathanw * SOFT CARRIER, AND keyboard PROPERTY FOR KEYBOARD/MOUSE?
268 1.31.4.2 nathanw */
269 1.31.4.2 nathanw static void
270 1.31.4.2 nathanw zs_attach(zsc, zsd, pri)
271 1.31.4.2 nathanw struct zsc_softc *zsc;
272 1.31.4.2 nathanw struct zsdevice *zsd;
273 1.31.4.2 nathanw int pri;
274 1.31.4.2 nathanw {
275 1.31.4.2 nathanw struct zsc_attach_args zsc_args;
276 1.31.4.2 nathanw struct zs_chanstate *cs;
277 1.31.4.2 nathanw int s, channel, softpri = PIL_TTY;
278 1.31.4.2 nathanw
279 1.31.4.2 nathanw if (zsd == NULL) {
280 1.31.4.2 nathanw printf("configuration incomplete\n");
281 1.31.4.2 nathanw return;
282 1.31.4.2 nathanw }
283 1.31.4.2 nathanw
284 1.31.4.2 nathanw printf(" softpri %d\n", softpri);
285 1.31.4.2 nathanw
286 1.31.4.2 nathanw /*
287 1.31.4.2 nathanw * Initialize software state for each channel.
288 1.31.4.2 nathanw */
289 1.31.4.2 nathanw for (channel = 0; channel < 2; channel++) {
290 1.31.4.2 nathanw struct zschan *zc;
291 1.31.4.2 nathanw struct device *child;
292 1.31.4.3 nathanw #if (NKBD > 0) || (NMS > 0)
293 1.31.4.2 nathanw extern struct cfdriver zstty_cd; /* in ioconf.c */
294 1.31.4.3 nathanw #endif
295 1.31.4.2 nathanw
296 1.31.4.2 nathanw zsc_args.channel = channel;
297 1.31.4.2 nathanw cs = &zsc->zsc_cs_store[channel];
298 1.31.4.2 nathanw zsc->zsc_cs[channel] = cs;
299 1.31.4.2 nathanw
300 1.31.4.2 nathanw cs->cs_channel = channel;
301 1.31.4.2 nathanw cs->cs_private = NULL;
302 1.31.4.2 nathanw cs->cs_ops = &zsops_null;
303 1.31.4.2 nathanw cs->cs_brg_clk = PCLK / 16;
304 1.31.4.2 nathanw
305 1.31.4.2 nathanw zc = (channel == 0) ? &zsd->zs_chan_a : &zsd->zs_chan_b;
306 1.31.4.2 nathanw
307 1.31.4.2 nathanw zsc_args.consdev = NULL;
308 1.31.4.2 nathanw zsc_args.hwflags = zs_console_flags(zsc->zsc_promunit,
309 1.31.4.2 nathanw zsc->zsc_node,
310 1.31.4.2 nathanw channel);
311 1.31.4.2 nathanw
312 1.31.4.2 nathanw if (zsc_args.hwflags & ZS_HWFLAG_CONSOLE) {
313 1.31.4.2 nathanw zsc_args.hwflags |= ZS_HWFLAG_USE_CONSDEV;
314 1.31.4.2 nathanw zsc_args.consdev = &zs_consdev;
315 1.31.4.2 nathanw }
316 1.31.4.2 nathanw
317 1.31.4.2 nathanw if ((zsc_args.hwflags & ZS_HWFLAG_CONSOLE_INPUT) != 0) {
318 1.31.4.2 nathanw zs_conschan_get = zc;
319 1.31.4.2 nathanw }
320 1.31.4.2 nathanw if ((zsc_args.hwflags & ZS_HWFLAG_CONSOLE_OUTPUT) != 0) {
321 1.31.4.2 nathanw zs_conschan_put = zc;
322 1.31.4.2 nathanw }
323 1.31.4.2 nathanw
324 1.31.4.2 nathanw /* Children need to set cn_dev, etc */
325 1.31.4.2 nathanw cs->cs_reg_csr = &zc->zc_csr;
326 1.31.4.2 nathanw cs->cs_reg_data = &zc->zc_data;
327 1.31.4.2 nathanw
328 1.31.4.2 nathanw bcopy(zs_init_reg, cs->cs_creg, 16);
329 1.31.4.2 nathanw bcopy(zs_init_reg, cs->cs_preg, 16);
330 1.31.4.2 nathanw
331 1.31.4.2 nathanw /* XXX: Consult PROM properties for this?! */
332 1.31.4.2 nathanw cs->cs_defspeed = zs_get_speed(cs);
333 1.31.4.2 nathanw cs->cs_defcflag = zs_def_cflag;
334 1.31.4.2 nathanw
335 1.31.4.2 nathanw /* Make these correspond to cs_defcflag (-crtscts) */
336 1.31.4.2 nathanw cs->cs_rr0_dcd = ZSRR0_DCD;
337 1.31.4.2 nathanw cs->cs_rr0_cts = 0;
338 1.31.4.2 nathanw cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
339 1.31.4.2 nathanw cs->cs_wr5_rts = 0;
340 1.31.4.2 nathanw
341 1.31.4.2 nathanw /*
342 1.31.4.2 nathanw * Clear the master interrupt enable.
343 1.31.4.2 nathanw * The INTENA is common to both channels,
344 1.31.4.2 nathanw * so just do it on the A channel.
345 1.31.4.2 nathanw */
346 1.31.4.2 nathanw if (channel == 0) {
347 1.31.4.2 nathanw zs_write_reg(cs, 9, 0);
348 1.31.4.2 nathanw }
349 1.31.4.2 nathanw
350 1.31.4.2 nathanw /*
351 1.31.4.2 nathanw * Look for a child driver for this channel.
352 1.31.4.2 nathanw * The child attach will setup the hardware.
353 1.31.4.2 nathanw */
354 1.31.4.2 nathanw if (!(child =
355 1.31.4.2 nathanw config_found(&zsc->zsc_dev, (void *)&zsc_args, zs_print))) {
356 1.31.4.2 nathanw /* No sub-driver. Just reset it. */
357 1.31.4.2 nathanw u_char reset = (channel == 0) ?
358 1.31.4.2 nathanw ZSWR9_A_RESET : ZSWR9_B_RESET;
359 1.31.4.2 nathanw s = splzs();
360 1.31.4.2 nathanw zs_write_reg(cs, 9, reset);
361 1.31.4.2 nathanw splx(s);
362 1.31.4.2 nathanw }
363 1.31.4.2 nathanw #if (NKBD > 0) || (NMS > 0)
364 1.31.4.2 nathanw /*
365 1.31.4.2 nathanw * If this was a zstty it has a keyboard
366 1.31.4.2 nathanw * property on it we need to attach the
367 1.31.4.2 nathanw * sunkbd and sunms line disciplines.
368 1.31.4.2 nathanw */
369 1.31.4.2 nathanw if (child
370 1.31.4.2 nathanw && (child->dv_cfdata->cf_driver == &zstty_cd)
371 1.31.4.2 nathanw && (PROM_getproplen(zsc->zsc_node, "keyboard") == 0)) {
372 1.31.4.2 nathanw struct kbd_ms_tty_attach_args kma;
373 1.31.4.2 nathanw struct zstty_softc {
374 1.31.4.2 nathanw /* The following are the only fields we need here */
375 1.31.4.2 nathanw struct device zst_dev;
376 1.31.4.2 nathanw struct tty *zst_tty;
377 1.31.4.2 nathanw struct zs_chanstate *zst_cs;
378 1.31.4.2 nathanw } *zst = (struct zstty_softc *)child;
379 1.31.4.2 nathanw struct tty *tp;
380 1.31.4.2 nathanw
381 1.31.4.2 nathanw kma.kmta_tp = tp = zst->zst_tty;
382 1.31.4.2 nathanw kma.kmta_dev = tp->t_dev;
383 1.31.4.2 nathanw kma.kmta_consdev = zsc_args.consdev;
384 1.31.4.2 nathanw
385 1.31.4.2 nathanw /* Attach 'em if we got 'em. */
386 1.31.4.2 nathanw #if (NKBD > 0)
387 1.31.4.2 nathanw if (channel == 0) {
388 1.31.4.2 nathanw kma.kmta_name = "keyboard";
389 1.31.4.2 nathanw config_found(child, (void *)&kma, NULL);
390 1.31.4.2 nathanw }
391 1.31.4.2 nathanw #endif
392 1.31.4.2 nathanw #if (NMS > 0)
393 1.31.4.2 nathanw if (channel == 1) {
394 1.31.4.2 nathanw kma.kmta_name = "mouse";
395 1.31.4.2 nathanw config_found(child, (void *)&kma, NULL);
396 1.31.4.2 nathanw }
397 1.31.4.2 nathanw #endif
398 1.31.4.2 nathanw }
399 1.31.4.2 nathanw #endif
400 1.31.4.2 nathanw }
401 1.31.4.2 nathanw
402 1.31.4.2 nathanw /*
403 1.31.4.2 nathanw * Now safe to install interrupt handlers. Note the arguments
404 1.31.4.2 nathanw * to the interrupt handlers aren't used. Note, we only do this
405 1.31.4.2 nathanw * once since both SCCs interrupt at the same level and vector.
406 1.31.4.2 nathanw */
407 1.31.4.2 nathanw bus_intr_establish(zsc->zsc_bustag, pri, IPL_SERIAL, 0, zshard, zsc);
408 1.31.4.2 nathanw if (!(zsc->zsc_softintr = softintr_establish(softpri, zssoft, zsc)))
409 1.31.4.2 nathanw panic("zsattach: could not establish soft interrupt\n");
410 1.31.4.2 nathanw
411 1.31.4.2 nathanw evcnt_attach_dynamic(&zsc->zsc_intrcnt, EVCNT_TYPE_INTR, NULL,
412 1.31.4.2 nathanw zsc->zsc_dev.dv_xname, "intr");
413 1.31.4.2 nathanw
414 1.31.4.2 nathanw
415 1.31.4.2 nathanw /*
416 1.31.4.2 nathanw * Set the master interrupt enable and interrupt vector.
417 1.31.4.2 nathanw * (common to both channels, do it on A)
418 1.31.4.2 nathanw */
419 1.31.4.2 nathanw cs = zsc->zsc_cs[0];
420 1.31.4.2 nathanw s = splhigh();
421 1.31.4.2 nathanw /* interrupt vector */
422 1.31.4.2 nathanw zs_write_reg(cs, 2, zs_init_reg[2]);
423 1.31.4.2 nathanw /* master interrupt control (enable) */
424 1.31.4.2 nathanw zs_write_reg(cs, 9, zs_init_reg[9]);
425 1.31.4.2 nathanw splx(s);
426 1.31.4.2 nathanw
427 1.31.4.2 nathanw }
428 1.31.4.2 nathanw
429 1.31.4.2 nathanw static int
430 1.31.4.2 nathanw zs_print(aux, name)
431 1.31.4.2 nathanw void *aux;
432 1.31.4.2 nathanw const char *name;
433 1.31.4.2 nathanw {
434 1.31.4.2 nathanw struct zsc_attach_args *args = aux;
435 1.31.4.2 nathanw
436 1.31.4.2 nathanw if (name != NULL)
437 1.31.4.2 nathanw printf("%s: ", name);
438 1.31.4.2 nathanw
439 1.31.4.2 nathanw if (args->channel != -1)
440 1.31.4.2 nathanw printf(" channel %d", args->channel);
441 1.31.4.2 nathanw
442 1.31.4.2 nathanw return (UNCONF);
443 1.31.4.2 nathanw }
444 1.31.4.2 nathanw
445 1.31.4.2 nathanw /* Deprecate this? */
446 1.31.4.2 nathanw static volatile int zssoftpending;
447 1.31.4.2 nathanw
448 1.31.4.2 nathanw static int
449 1.31.4.2 nathanw zshard(arg)
450 1.31.4.2 nathanw void *arg;
451 1.31.4.2 nathanw {
452 1.31.4.2 nathanw struct zsc_softc *zsc = (struct zsc_softc *)arg;
453 1.31.4.2 nathanw int rr3, rval;
454 1.31.4.2 nathanw
455 1.31.4.2 nathanw rval = 0;
456 1.31.4.2 nathanw while ((rr3 = zsc_intr_hard(zsc))) {
457 1.31.4.2 nathanw /* Count up the interrupts. */
458 1.31.4.2 nathanw rval |= rr3;
459 1.31.4.2 nathanw zsc->zsc_intrcnt.ev_count++;
460 1.31.4.2 nathanw }
461 1.31.4.2 nathanw if (((zsc->zsc_cs[0] && zsc->zsc_cs[0]->cs_softreq) ||
462 1.31.4.2 nathanw (zsc->zsc_cs[1] && zsc->zsc_cs[1]->cs_softreq)) &&
463 1.31.4.2 nathanw zsc->zsc_softintr) {
464 1.31.4.2 nathanw zssoftpending = PIL_TTY;
465 1.31.4.2 nathanw softintr_schedule(zsc->zsc_softintr);
466 1.31.4.2 nathanw }
467 1.31.4.2 nathanw return (rval);
468 1.31.4.2 nathanw }
469 1.31.4.2 nathanw
470 1.31.4.2 nathanw int
471 1.31.4.2 nathanw zscheckintr(arg)
472 1.31.4.2 nathanw void *arg;
473 1.31.4.2 nathanw {
474 1.31.4.2 nathanw struct zsc_softc *zsc;
475 1.31.4.2 nathanw int unit, rval;
476 1.31.4.2 nathanw
477 1.31.4.2 nathanw rval = 0;
478 1.31.4.2 nathanw for (unit = 0; unit < zs_cd.cd_ndevs; unit++) {
479 1.31.4.2 nathanw
480 1.31.4.2 nathanw zsc = zs_cd.cd_devs[unit];
481 1.31.4.2 nathanw if (zsc == NULL)
482 1.31.4.2 nathanw continue;
483 1.31.4.2 nathanw rval = (zshard((void *)zsc) || rval);
484 1.31.4.2 nathanw }
485 1.31.4.2 nathanw return (rval);
486 1.31.4.2 nathanw }
487 1.31.4.2 nathanw
488 1.31.4.2 nathanw
489 1.31.4.2 nathanw /*
490 1.31.4.2 nathanw * We need this only for TTY_DEBUG purposes.
491 1.31.4.2 nathanw */
492 1.31.4.2 nathanw static void
493 1.31.4.2 nathanw zssoft(arg)
494 1.31.4.2 nathanw void *arg;
495 1.31.4.2 nathanw {
496 1.31.4.2 nathanw struct zsc_softc *zsc = (struct zsc_softc *)arg;
497 1.31.4.2 nathanw int s;
498 1.31.4.2 nathanw
499 1.31.4.2 nathanw /* Make sure we call the tty layer at spltty. */
500 1.31.4.2 nathanw s = spltty();
501 1.31.4.2 nathanw zssoftpending = 0;
502 1.31.4.2 nathanw (void)zsc_intr_soft(zsc);
503 1.31.4.2 nathanw #ifdef TTY_DEBUG
504 1.31.4.2 nathanw {
505 1.31.4.2 nathanw struct zstty_softc *zst0 = zsc->zsc_cs[0]->cs_private;
506 1.31.4.2 nathanw struct zstty_softc *zst1 = zsc->zsc_cs[1]->cs_private;
507 1.31.4.2 nathanw if (zst0->zst_overflows || zst1->zst_overflows ) {
508 1.31.4.2 nathanw struct trapframe *frame = (struct trapframe *)arg;
509 1.31.4.2 nathanw
510 1.31.4.2 nathanw printf("zs silo overflow from %p\n",
511 1.31.4.2 nathanw (long)frame->tf_pc);
512 1.31.4.2 nathanw }
513 1.31.4.2 nathanw }
514 1.31.4.2 nathanw #endif
515 1.31.4.2 nathanw splx(s);
516 1.31.4.2 nathanw }
517 1.31.4.2 nathanw
518 1.31.4.2 nathanw
519 1.31.4.2 nathanw /*
520 1.31.4.2 nathanw * Compute the current baud rate given a ZS channel.
521 1.31.4.2 nathanw */
522 1.31.4.2 nathanw static int
523 1.31.4.2 nathanw zs_get_speed(cs)
524 1.31.4.2 nathanw struct zs_chanstate *cs;
525 1.31.4.2 nathanw {
526 1.31.4.2 nathanw int tconst;
527 1.31.4.2 nathanw
528 1.31.4.2 nathanw tconst = zs_read_reg(cs, 12);
529 1.31.4.2 nathanw tconst |= zs_read_reg(cs, 13) << 8;
530 1.31.4.2 nathanw return (TCONST_TO_BPS(cs->cs_brg_clk, tconst));
531 1.31.4.2 nathanw }
532 1.31.4.2 nathanw
533 1.31.4.2 nathanw /*
534 1.31.4.2 nathanw * MD functions for setting the baud rate and control modes.
535 1.31.4.2 nathanw */
536 1.31.4.2 nathanw int
537 1.31.4.2 nathanw zs_set_speed(cs, bps)
538 1.31.4.2 nathanw struct zs_chanstate *cs;
539 1.31.4.2 nathanw int bps; /* bits per second */
540 1.31.4.2 nathanw {
541 1.31.4.2 nathanw int tconst, real_bps;
542 1.31.4.2 nathanw
543 1.31.4.2 nathanw if (bps == 0)
544 1.31.4.2 nathanw return (0);
545 1.31.4.2 nathanw
546 1.31.4.2 nathanw #ifdef DIAGNOSTIC
547 1.31.4.2 nathanw if (cs->cs_brg_clk == 0)
548 1.31.4.2 nathanw panic("zs_set_speed");
549 1.31.4.2 nathanw #endif
550 1.31.4.2 nathanw
551 1.31.4.2 nathanw tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
552 1.31.4.2 nathanw if (tconst < 0)
553 1.31.4.2 nathanw return (EINVAL);
554 1.31.4.2 nathanw
555 1.31.4.2 nathanw /* Convert back to make sure we can do it. */
556 1.31.4.2 nathanw real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
557 1.31.4.2 nathanw
558 1.31.4.2 nathanw /* XXX - Allow some tolerance here? */
559 1.31.4.2 nathanw if (real_bps != bps)
560 1.31.4.2 nathanw return (EINVAL);
561 1.31.4.2 nathanw
562 1.31.4.2 nathanw cs->cs_preg[12] = tconst;
563 1.31.4.2 nathanw cs->cs_preg[13] = tconst >> 8;
564 1.31.4.2 nathanw
565 1.31.4.2 nathanw /* Caller will stuff the pending registers. */
566 1.31.4.2 nathanw return (0);
567 1.31.4.2 nathanw }
568 1.31.4.2 nathanw
569 1.31.4.2 nathanw int
570 1.31.4.2 nathanw zs_set_modes(cs, cflag)
571 1.31.4.2 nathanw struct zs_chanstate *cs;
572 1.31.4.2 nathanw int cflag; /* bits per second */
573 1.31.4.2 nathanw {
574 1.31.4.2 nathanw int s;
575 1.31.4.2 nathanw
576 1.31.4.2 nathanw /*
577 1.31.4.2 nathanw * Output hardware flow control on the chip is horrendous:
578 1.31.4.2 nathanw * if carrier detect drops, the receiver is disabled, and if
579 1.31.4.2 nathanw * CTS drops, the transmitter is stoped IN MID CHARACTER!
580 1.31.4.2 nathanw * Therefore, NEVER set the HFC bit, and instead use the
581 1.31.4.2 nathanw * status interrupt to detect CTS changes.
582 1.31.4.2 nathanw */
583 1.31.4.2 nathanw s = splzs();
584 1.31.4.2 nathanw cs->cs_rr0_pps = 0;
585 1.31.4.2 nathanw if ((cflag & (CLOCAL | MDMBUF)) != 0) {
586 1.31.4.2 nathanw cs->cs_rr0_dcd = 0;
587 1.31.4.2 nathanw if ((cflag & MDMBUF) == 0)
588 1.31.4.2 nathanw cs->cs_rr0_pps = ZSRR0_DCD;
589 1.31.4.2 nathanw } else
590 1.31.4.2 nathanw cs->cs_rr0_dcd = ZSRR0_DCD;
591 1.31.4.2 nathanw if ((cflag & CRTSCTS) != 0) {
592 1.31.4.2 nathanw cs->cs_wr5_dtr = ZSWR5_DTR;
593 1.31.4.2 nathanw cs->cs_wr5_rts = ZSWR5_RTS;
594 1.31.4.2 nathanw cs->cs_rr0_cts = ZSRR0_CTS;
595 1.31.4.2 nathanw } else if ((cflag & CDTRCTS) != 0) {
596 1.31.4.2 nathanw cs->cs_wr5_dtr = 0;
597 1.31.4.2 nathanw cs->cs_wr5_rts = ZSWR5_DTR;
598 1.31.4.2 nathanw cs->cs_rr0_cts = ZSRR0_CTS;
599 1.31.4.2 nathanw } else if ((cflag & MDMBUF) != 0) {
600 1.31.4.2 nathanw cs->cs_wr5_dtr = 0;
601 1.31.4.2 nathanw cs->cs_wr5_rts = ZSWR5_DTR;
602 1.31.4.2 nathanw cs->cs_rr0_cts = ZSRR0_DCD;
603 1.31.4.2 nathanw } else {
604 1.31.4.2 nathanw cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
605 1.31.4.2 nathanw cs->cs_wr5_rts = 0;
606 1.31.4.2 nathanw cs->cs_rr0_cts = 0;
607 1.31.4.2 nathanw }
608 1.31.4.2 nathanw splx(s);
609 1.31.4.2 nathanw
610 1.31.4.2 nathanw /* Caller will stuff the pending registers. */
611 1.31.4.2 nathanw return (0);
612 1.31.4.2 nathanw }
613 1.31.4.2 nathanw
614 1.31.4.2 nathanw
615 1.31.4.2 nathanw /*
616 1.31.4.2 nathanw * Read or write the chip with suitable delays.
617 1.31.4.2 nathanw */
618 1.31.4.2 nathanw
619 1.31.4.2 nathanw u_char
620 1.31.4.2 nathanw zs_read_reg(cs, reg)
621 1.31.4.2 nathanw struct zs_chanstate *cs;
622 1.31.4.2 nathanw u_char reg;
623 1.31.4.2 nathanw {
624 1.31.4.2 nathanw u_char val;
625 1.31.4.2 nathanw
626 1.31.4.2 nathanw *cs->cs_reg_csr = reg;
627 1.31.4.2 nathanw ZS_DELAY();
628 1.31.4.2 nathanw val = *cs->cs_reg_csr;
629 1.31.4.2 nathanw ZS_DELAY();
630 1.31.4.2 nathanw return (val);
631 1.31.4.2 nathanw }
632 1.31.4.2 nathanw
633 1.31.4.2 nathanw void
634 1.31.4.2 nathanw zs_write_reg(cs, reg, val)
635 1.31.4.2 nathanw struct zs_chanstate *cs;
636 1.31.4.2 nathanw u_char reg, val;
637 1.31.4.2 nathanw {
638 1.31.4.2 nathanw *cs->cs_reg_csr = reg;
639 1.31.4.2 nathanw ZS_DELAY();
640 1.31.4.2 nathanw *cs->cs_reg_csr = val;
641 1.31.4.2 nathanw ZS_DELAY();
642 1.31.4.2 nathanw }
643 1.31.4.2 nathanw
644 1.31.4.2 nathanw u_char
645 1.31.4.2 nathanw zs_read_csr(cs)
646 1.31.4.2 nathanw struct zs_chanstate *cs;
647 1.31.4.2 nathanw {
648 1.31.4.2 nathanw u_char val;
649 1.31.4.2 nathanw
650 1.31.4.2 nathanw val = *cs->cs_reg_csr;
651 1.31.4.2 nathanw ZS_DELAY();
652 1.31.4.2 nathanw return (val);
653 1.31.4.2 nathanw }
654 1.31.4.2 nathanw
655 1.31.4.2 nathanw void zs_write_csr(cs, val)
656 1.31.4.2 nathanw struct zs_chanstate *cs;
657 1.31.4.2 nathanw u_char val;
658 1.31.4.2 nathanw {
659 1.31.4.2 nathanw *cs->cs_reg_csr = val;
660 1.31.4.2 nathanw ZS_DELAY();
661 1.31.4.2 nathanw }
662 1.31.4.2 nathanw
663 1.31.4.2 nathanw u_char zs_read_data(cs)
664 1.31.4.2 nathanw struct zs_chanstate *cs;
665 1.31.4.2 nathanw {
666 1.31.4.2 nathanw u_char val;
667 1.31.4.2 nathanw
668 1.31.4.2 nathanw val = *cs->cs_reg_data;
669 1.31.4.2 nathanw ZS_DELAY();
670 1.31.4.2 nathanw return (val);
671 1.31.4.2 nathanw }
672 1.31.4.2 nathanw
673 1.31.4.2 nathanw void zs_write_data(cs, val)
674 1.31.4.2 nathanw struct zs_chanstate *cs;
675 1.31.4.2 nathanw u_char val;
676 1.31.4.2 nathanw {
677 1.31.4.2 nathanw *cs->cs_reg_data = val;
678 1.31.4.2 nathanw ZS_DELAY();
679 1.31.4.2 nathanw }
680 1.31.4.2 nathanw
681 1.31.4.2 nathanw /****************************************************************
682 1.31.4.2 nathanw * Console support functions (Sun specific!)
683 1.31.4.2 nathanw * Note: this code is allowed to know about the layout of
684 1.31.4.2 nathanw * the chip registers, and uses that to keep things simple.
685 1.31.4.2 nathanw * XXX - I think I like the mvme167 code better. -gwr
686 1.31.4.2 nathanw ****************************************************************/
687 1.31.4.2 nathanw
688 1.31.4.2 nathanw extern void Debugger __P((void));
689 1.31.4.2 nathanw
690 1.31.4.2 nathanw /*
691 1.31.4.2 nathanw * Handle user request to enter kernel debugger.
692 1.31.4.2 nathanw */
693 1.31.4.2 nathanw void
694 1.31.4.2 nathanw zs_abort(cs)
695 1.31.4.2 nathanw struct zs_chanstate *cs;
696 1.31.4.2 nathanw {
697 1.31.4.2 nathanw volatile struct zschan *zc = zs_conschan_get;
698 1.31.4.2 nathanw int rr0;
699 1.31.4.2 nathanw
700 1.31.4.2 nathanw /* Wait for end of break to avoid PROM abort. */
701 1.31.4.2 nathanw /* XXX - Limit the wait? */
702 1.31.4.2 nathanw do {
703 1.31.4.2 nathanw rr0 = zc->zc_csr;
704 1.31.4.2 nathanw ZS_DELAY();
705 1.31.4.2 nathanw } while (rr0 & ZSRR0_BREAK);
706 1.31.4.2 nathanw
707 1.31.4.2 nathanw #if defined(KGDB)
708 1.31.4.2 nathanw zskgdb(cs);
709 1.31.4.2 nathanw #elif defined(DDB)
710 1.31.4.2 nathanw {
711 1.31.4.2 nathanw extern int db_active;
712 1.31.4.2 nathanw
713 1.31.4.2 nathanw if (!db_active)
714 1.31.4.2 nathanw Debugger();
715 1.31.4.2 nathanw else
716 1.31.4.2 nathanw /* Debugger is probably hozed */
717 1.31.4.2 nathanw callrom();
718 1.31.4.2 nathanw }
719 1.31.4.2 nathanw #else
720 1.31.4.2 nathanw printf("stopping on keyboard abort\n");
721 1.31.4.2 nathanw callrom();
722 1.31.4.2 nathanw #endif
723 1.31.4.2 nathanw }
724 1.31.4.2 nathanw
725 1.31.4.2 nathanw
726 1.31.4.2 nathanw /*
727 1.31.4.2 nathanw * Polled input char.
728 1.31.4.2 nathanw */
729 1.31.4.2 nathanw int
730 1.31.4.2 nathanw zs_getc(arg)
731 1.31.4.2 nathanw void *arg;
732 1.31.4.2 nathanw {
733 1.31.4.2 nathanw volatile struct zschan *zc = arg;
734 1.31.4.2 nathanw int s, c, rr0;
735 1.31.4.2 nathanw
736 1.31.4.2 nathanw s = splhigh();
737 1.31.4.2 nathanw /* Wait for a character to arrive. */
738 1.31.4.2 nathanw do {
739 1.31.4.2 nathanw rr0 = zc->zc_csr;
740 1.31.4.2 nathanw ZS_DELAY();
741 1.31.4.2 nathanw } while ((rr0 & ZSRR0_RX_READY) == 0);
742 1.31.4.2 nathanw
743 1.31.4.2 nathanw c = zc->zc_data;
744 1.31.4.2 nathanw ZS_DELAY();
745 1.31.4.2 nathanw splx(s);
746 1.31.4.2 nathanw
747 1.31.4.2 nathanw /*
748 1.31.4.2 nathanw * This is used by the kd driver to read scan codes,
749 1.31.4.2 nathanw * so don't translate '\r' ==> '\n' here...
750 1.31.4.2 nathanw */
751 1.31.4.2 nathanw return (c);
752 1.31.4.2 nathanw }
753 1.31.4.2 nathanw
754 1.31.4.2 nathanw /*
755 1.31.4.2 nathanw * Polled output char.
756 1.31.4.2 nathanw */
757 1.31.4.2 nathanw void
758 1.31.4.2 nathanw zs_putc(arg, c)
759 1.31.4.2 nathanw void *arg;
760 1.31.4.2 nathanw int c;
761 1.31.4.2 nathanw {
762 1.31.4.2 nathanw volatile struct zschan *zc = arg;
763 1.31.4.2 nathanw int s, rr0;
764 1.31.4.2 nathanw
765 1.31.4.2 nathanw s = splhigh();
766 1.31.4.2 nathanw
767 1.31.4.2 nathanw /* Wait for transmitter to become ready. */
768 1.31.4.2 nathanw do {
769 1.31.4.2 nathanw rr0 = zc->zc_csr;
770 1.31.4.2 nathanw ZS_DELAY();
771 1.31.4.2 nathanw } while ((rr0 & ZSRR0_TX_READY) == 0);
772 1.31.4.2 nathanw
773 1.31.4.2 nathanw /*
774 1.31.4.2 nathanw * Send the next character.
775 1.31.4.2 nathanw * Now you'd think that this could be followed by a ZS_DELAY()
776 1.31.4.2 nathanw * just like all the other chip accesses, but it turns out that
777 1.31.4.2 nathanw * the `transmit-ready' interrupt isn't de-asserted until
778 1.31.4.2 nathanw * some period of time after the register write completes
779 1.31.4.2 nathanw * (more than a couple instructions). So to avoid stray
780 1.31.4.2 nathanw * interrupts we put in the 2us delay regardless of cpu model.
781 1.31.4.2 nathanw */
782 1.31.4.2 nathanw zc->zc_data = c;
783 1.31.4.2 nathanw delay(2);
784 1.31.4.2 nathanw
785 1.31.4.2 nathanw splx(s);
786 1.31.4.2 nathanw }
787 1.31.4.2 nathanw
788 1.31.4.2 nathanw /*****************************************************************/
789 1.31.4.2 nathanw
790 1.31.4.2 nathanw
791 1.31.4.2 nathanw
792 1.31.4.2 nathanw
793 1.31.4.2 nathanw /*
794 1.31.4.2 nathanw * Polled console input putchar.
795 1.31.4.2 nathanw */
796 1.31.4.2 nathanw static int
797 1.31.4.2 nathanw zscngetc(dev)
798 1.31.4.2 nathanw dev_t dev;
799 1.31.4.2 nathanw {
800 1.31.4.2 nathanw return (zs_getc(zs_conschan_get));
801 1.31.4.2 nathanw }
802 1.31.4.2 nathanw
803 1.31.4.2 nathanw /*
804 1.31.4.2 nathanw * Polled console output putchar.
805 1.31.4.2 nathanw */
806 1.31.4.2 nathanw static void
807 1.31.4.2 nathanw zscnputc(dev, c)
808 1.31.4.2 nathanw dev_t dev;
809 1.31.4.2 nathanw int c;
810 1.31.4.2 nathanw {
811 1.31.4.2 nathanw zs_putc(zs_conschan_put, c);
812 1.31.4.2 nathanw }
813 1.31.4.2 nathanw
814 1.31.4.2 nathanw int swallow_zsintrs;
815 1.31.4.2 nathanw
816 1.31.4.2 nathanw static void
817 1.31.4.2 nathanw zscnpollc(dev, on)
818 1.31.4.2 nathanw dev_t dev;
819 1.31.4.2 nathanw int on;
820 1.31.4.2 nathanw {
821 1.31.4.2 nathanw /*
822 1.31.4.2 nathanw * Need to tell zs driver to acknowledge all interrupts or we get
823 1.31.4.2 nathanw * annoying spurious interrupt messages. This is because mucking
824 1.31.4.2 nathanw * with spl() levels during polling does not prevent interrupts from
825 1.31.4.2 nathanw * being generated.
826 1.31.4.2 nathanw */
827 1.31.4.2 nathanw
828 1.31.4.2 nathanw if (on) swallow_zsintrs++;
829 1.31.4.2 nathanw else swallow_zsintrs--;
830 1.31.4.2 nathanw }
831 1.31.4.2 nathanw
832 1.31.4.2 nathanw int
833 1.31.4.2 nathanw zs_console_flags(promunit, node, channel)
834 1.31.4.2 nathanw int promunit;
835 1.31.4.2 nathanw int node;
836 1.31.4.2 nathanw int channel;
837 1.31.4.2 nathanw {
838 1.31.4.2 nathanw int cookie, flags = 0;
839 1.31.4.2 nathanw u_int chosen;
840 1.31.4.2 nathanw char buf[255];
841 1.31.4.2 nathanw
842 1.31.4.2 nathanw /*
843 1.31.4.2 nathanw * We'll just to the OBP grovelling down here since that's
844 1.31.4.2 nathanw * the only type of firmware we support.
845 1.31.4.2 nathanw */
846 1.31.4.2 nathanw chosen = OF_finddevice("/chosen");
847 1.31.4.2 nathanw
848 1.31.4.2 nathanw /* Default to channel 0 if there are no explicit prom args */
849 1.31.4.2 nathanw cookie = 0;
850 1.31.4.2 nathanw if (node == OF_instance_to_package(OF_stdin())) {
851 1.31.4.2 nathanw if (OF_getprop(chosen, "input-device", buf, sizeof(buf)) != -1) {
852 1.31.4.2 nathanw
853 1.31.4.2 nathanw if (!strcmp("ttyb", buf))
854 1.31.4.2 nathanw cookie = 1;
855 1.31.4.2 nathanw }
856 1.31.4.2 nathanw
857 1.31.4.2 nathanw if (channel == cookie)
858 1.31.4.2 nathanw flags |= ZS_HWFLAG_CONSOLE_INPUT;
859 1.31.4.2 nathanw }
860 1.31.4.2 nathanw
861 1.31.4.2 nathanw if (node == OF_instance_to_package(OF_stdout())) {
862 1.31.4.2 nathanw if (OF_getprop(chosen, "output-device", buf, sizeof(buf)) != -1) {
863 1.31.4.2 nathanw
864 1.31.4.2 nathanw if (!strcmp("ttyb", buf))
865 1.31.4.2 nathanw cookie = 1;
866 1.31.4.2 nathanw }
867 1.31.4.2 nathanw
868 1.31.4.2 nathanw if (channel == cookie)
869 1.31.4.2 nathanw flags |= ZS_HWFLAG_CONSOLE_OUTPUT;
870 1.31.4.2 nathanw }
871 1.31.4.2 nathanw
872 1.31.4.2 nathanw return (flags);
873 1.31.4.2 nathanw }
874 1.31.4.2 nathanw
875