zs.c revision 1.15.8.3 1 1.15.8.3 nathanw /* $NetBSD: zs.c,v 1.15.8.3 2002/10/18 02:39:15 nathanw Exp $ */
2 1.15.8.2 nathanw
3 1.15.8.2 nathanw /*-
4 1.15.8.2 nathanw * Copyright (c) 1996 The NetBSD Foundation, Inc.
5 1.15.8.2 nathanw * All rights reserved.
6 1.15.8.2 nathanw *
7 1.15.8.2 nathanw * This code is derived from software contributed to The NetBSD Foundation
8 1.15.8.2 nathanw * by Gordon W. Ross.
9 1.15.8.2 nathanw *
10 1.15.8.2 nathanw * Redistribution and use in source and binary forms, with or without
11 1.15.8.2 nathanw * modification, are permitted provided that the following conditions
12 1.15.8.2 nathanw * are met:
13 1.15.8.2 nathanw * 1. Redistributions of source code must retain the above copyright
14 1.15.8.2 nathanw * notice, this list of conditions and the following disclaimer.
15 1.15.8.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
16 1.15.8.2 nathanw * notice, this list of conditions and the following disclaimer in the
17 1.15.8.2 nathanw * documentation and/or other materials provided with the distribution.
18 1.15.8.2 nathanw * 3. All advertising materials mentioning features or use of this software
19 1.15.8.2 nathanw * must display the following acknowledgement:
20 1.15.8.2 nathanw * This product includes software developed by the NetBSD
21 1.15.8.2 nathanw * Foundation, Inc. and its contributors.
22 1.15.8.2 nathanw * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.15.8.2 nathanw * contributors may be used to endorse or promote products derived
24 1.15.8.2 nathanw * from this software without specific prior written permission.
25 1.15.8.2 nathanw *
26 1.15.8.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.15.8.2 nathanw * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.15.8.2 nathanw * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.15.8.2 nathanw * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.15.8.2 nathanw * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.15.8.2 nathanw * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.15.8.2 nathanw * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.15.8.2 nathanw * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.15.8.2 nathanw * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.15.8.2 nathanw * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.15.8.2 nathanw * POSSIBILITY OF SUCH DAMAGE.
37 1.15.8.2 nathanw */
38 1.15.8.2 nathanw
39 1.15.8.2 nathanw /*
40 1.15.8.2 nathanw * Zilog Z8530 Dual UART driver (machine-dependent part)
41 1.15.8.2 nathanw *
42 1.15.8.2 nathanw * Runs two serial lines per chip using slave drivers.
43 1.15.8.2 nathanw * Plain tty/async lines use the zs_async slave.
44 1.15.8.2 nathanw * Sun keyboard/mouse uses the zs_kbd/zs_ms slaves.
45 1.15.8.2 nathanw */
46 1.15.8.2 nathanw
47 1.15.8.2 nathanw /* This was snarfed from the netbsd sparc/dev/zs.c at version 1.56
48 1.15.8.2 nathanw * and then updated to reflect changes in 1.59
49 1.15.8.2 nathanw * by Darrin B Jewell <jewell (at) mit.edu> Mon Mar 30 20:24:46 1998
50 1.15.8.2 nathanw */
51 1.15.8.2 nathanw
52 1.15.8.2 nathanw #include "opt_ddb.h"
53 1.15.8.2 nathanw #include "opt_kgdb.h"
54 1.15.8.2 nathanw #include "opt_serial.h"
55 1.15.8.2 nathanw
56 1.15.8.2 nathanw #include <sys/param.h>
57 1.15.8.2 nathanw #include <sys/systm.h>
58 1.15.8.2 nathanw #include <sys/conf.h>
59 1.15.8.2 nathanw #include <sys/device.h>
60 1.15.8.2 nathanw #include <sys/file.h>
61 1.15.8.2 nathanw #include <sys/ioctl.h>
62 1.15.8.2 nathanw #include <sys/kernel.h>
63 1.15.8.2 nathanw #include <sys/proc.h>
64 1.15.8.2 nathanw #include <sys/tty.h>
65 1.15.8.2 nathanw #include <sys/time.h>
66 1.15.8.2 nathanw #include <sys/syslog.h>
67 1.15.8.2 nathanw
68 1.15.8.2 nathanw #include <machine/autoconf.h>
69 1.15.8.2 nathanw #include <machine/cpu.h>
70 1.15.8.2 nathanw #include <machine/psl.h>
71 1.15.8.2 nathanw
72 1.15.8.2 nathanw #include <dev/cons.h>
73 1.15.8.2 nathanw
74 1.15.8.2 nathanw #include <dev/ic/z8530reg.h>
75 1.15.8.2 nathanw #include <machine/z8530var.h>
76 1.15.8.2 nathanw
77 1.15.8.2 nathanw #include <next68k/next68k/isr.h>
78 1.15.8.2 nathanw
79 1.15.8.2 nathanw #include <next68k/dev/intiovar.h>
80 1.15.8.2 nathanw #include <next68k/dev/zs_cons.h>
81 1.15.8.2 nathanw
82 1.15.8.2 nathanw #include "zsc.h" /* NZSC */
83 1.15.8.2 nathanw
84 1.15.8.2 nathanw #if (NZSC < 0)
85 1.15.8.2 nathanw #error "No serial controllers?"
86 1.15.8.2 nathanw #endif
87 1.15.8.2 nathanw
88 1.15.8.2 nathanw /*
89 1.15.8.2 nathanw * Some warts needed by z8530tty.c -
90 1.15.8.2 nathanw * The default parity REALLY needs to be the same as the PROM uses,
91 1.15.8.2 nathanw * or you can not see messages done with printf during boot-up...
92 1.15.8.2 nathanw */
93 1.15.8.2 nathanw int zs_def_cflag = (CREAD | CS8 | HUPCL);
94 1.15.8.2 nathanw
95 1.15.8.2 nathanw /*
96 1.15.8.2 nathanw * The NeXT provides a 3.686400 MHz clock to the ZS chips.
97 1.15.8.2 nathanw */
98 1.15.8.2 nathanw #define PCLK (9600 * 384) /* PCLK pin input clock rate */
99 1.15.8.2 nathanw
100 1.15.8.2 nathanw #define ZS_DELAY() delay(2)
101 1.15.8.2 nathanw
102 1.15.8.2 nathanw /* The layout of this is hardware-dependent (padding, order). */
103 1.15.8.2 nathanw struct zschan {
104 1.15.8.2 nathanw volatile u_char zc_csr; /* ctrl,status, and indirect access */
105 1.15.8.2 nathanw u_char zc_xxx0;
106 1.15.8.2 nathanw volatile u_char zc_data; /* data */
107 1.15.8.2 nathanw u_char zc_xxx1;
108 1.15.8.2 nathanw };
109 1.15.8.2 nathanw
110 1.15.8.2 nathanw static char *zsaddr[NZSC];
111 1.15.8.2 nathanw
112 1.15.8.2 nathanw /* Flags from cninit() */
113 1.15.8.2 nathanw static int zs_hwflags[NZSC][2];
114 1.15.8.2 nathanw
115 1.15.8.2 nathanw /* Default speed for each channel */
116 1.15.8.2 nathanw static int zs_defspeed[NZSC][2] = {
117 1.15.8.2 nathanw { 9600, /* ttya */
118 1.15.8.2 nathanw 9600 }, /* ttyb */
119 1.15.8.2 nathanw };
120 1.15.8.2 nathanw
121 1.15.8.2 nathanw static u_char zs_init_reg[16] = {
122 1.15.8.2 nathanw 0, /* 0: CMD (reset, etc.) */
123 1.15.8.2 nathanw 0, /* 1: No interrupts yet. */
124 1.15.8.2 nathanw 0x18 + NEXT_I_IPL(NEXT_I_SCC), /* 2: IVECT */
125 1.15.8.2 nathanw ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
126 1.15.8.2 nathanw ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
127 1.15.8.2 nathanw ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
128 1.15.8.2 nathanw 0, /* 6: TXSYNC/SYNCLO */
129 1.15.8.2 nathanw 0, /* 7: RXSYNC/SYNCHI */
130 1.15.8.2 nathanw 0, /* 8: alias for data port */
131 1.15.8.2 nathanw ZSWR9_MASTER_IE,
132 1.15.8.2 nathanw 0, /*10: Misc. TX/RX control bits */
133 1.15.8.2 nathanw ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
134 1.15.8.2 nathanw ((PCLK/32)/9600)-2, /*12: BAUDLO (default=9600) */
135 1.15.8.2 nathanw 0, /*13: BAUDHI (default=9600) */
136 1.15.8.2 nathanw ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK,
137 1.15.8.2 nathanw ZSWR15_BREAK_IE,
138 1.15.8.2 nathanw };
139 1.15.8.2 nathanw
140 1.15.8.2 nathanw struct zschan *
141 1.15.8.2 nathanw zs_get_chan_addr(zs_unit, channel)
142 1.15.8.2 nathanw int zs_unit, channel;
143 1.15.8.2 nathanw {
144 1.15.8.2 nathanw char *addr;
145 1.15.8.2 nathanw struct zschan *zc;
146 1.15.8.2 nathanw
147 1.15.8.2 nathanw if (zs_unit >= NZSC)
148 1.15.8.2 nathanw return (NULL);
149 1.15.8.2 nathanw addr = zsaddr[zs_unit];
150 1.15.8.2 nathanw if (addr == NULL)
151 1.15.8.2 nathanw return (NULL);
152 1.15.8.2 nathanw if (channel == 0) {
153 1.15.8.2 nathanw /* handle the fact the ports are intertwined. */
154 1.15.8.2 nathanw zc = (struct zschan *)(addr+1);
155 1.15.8.2 nathanw } else {
156 1.15.8.2 nathanw zc = (struct zschan *)(addr);
157 1.15.8.2 nathanw }
158 1.15.8.2 nathanw return (zc);
159 1.15.8.2 nathanw }
160 1.15.8.2 nathanw
161 1.15.8.2 nathanw
162 1.15.8.2 nathanw /****************************************************************
163 1.15.8.2 nathanw * Autoconfig
164 1.15.8.2 nathanw ****************************************************************/
165 1.15.8.2 nathanw
166 1.15.8.2 nathanw /* Definition of the driver for autoconfig. */
167 1.15.8.2 nathanw static int zs_match __P((struct device *, struct cfdata *, void *));
168 1.15.8.2 nathanw static void zs_attach __P((struct device *, struct device *, void *));
169 1.15.8.2 nathanw static int zs_print __P((void *, const char *name));
170 1.15.8.2 nathanw
171 1.15.8.2 nathanw extern int zs_getc __P((void *arg));
172 1.15.8.2 nathanw extern void zs_putc __P((void *arg, int c));
173 1.15.8.2 nathanw
174 1.15.8.3 nathanw CFATTACH_DECL(zsc, sizeof(struct zsc_softc),
175 1.15.8.3 nathanw zs_match, zs_attach, NULL, NULL);
176 1.15.8.2 nathanw
177 1.15.8.2 nathanw extern struct cfdriver zsc_cd;
178 1.15.8.2 nathanw
179 1.15.8.2 nathanw /* Interrupt handlers. */
180 1.15.8.2 nathanw static int zshard __P((void *));
181 1.15.8.2 nathanw static void zssoft __P((void *));
182 1.15.8.2 nathanw
183 1.15.8.2 nathanw static int zs_get_speed __P((struct zs_chanstate *));
184 1.15.8.2 nathanw
185 1.15.8.2 nathanw
186 1.15.8.2 nathanw /*
187 1.15.8.2 nathanw * Is the zs chip present?
188 1.15.8.2 nathanw */
189 1.15.8.2 nathanw static int
190 1.15.8.2 nathanw zs_match(parent, cf, aux)
191 1.15.8.2 nathanw struct device *parent;
192 1.15.8.2 nathanw struct cfdata *cf;
193 1.15.8.2 nathanw void *aux;
194 1.15.8.2 nathanw {
195 1.15.8.2 nathanw struct intio_attach_args *ia = (struct intio_attach_args *)aux;
196 1.15.8.2 nathanw
197 1.15.8.2 nathanw if (zsaddr[cf->cf_unit] == NULL)
198 1.15.8.2 nathanw return(0);
199 1.15.8.2 nathanw
200 1.15.8.2 nathanw ia->ia_addr = (void *)zsaddr[cf->cf_unit];
201 1.15.8.2 nathanw
202 1.15.8.2 nathanw return(1);
203 1.15.8.2 nathanw }
204 1.15.8.2 nathanw
205 1.15.8.2 nathanw /*
206 1.15.8.2 nathanw * Attach a found zs.
207 1.15.8.2 nathanw *
208 1.15.8.2 nathanw * USE ROM PROPERTIES port-a-ignore-cd AND port-b-ignore-cd FOR
209 1.15.8.2 nathanw * SOFT CARRIER, AND keyboard PROPERTY FOR KEYBOARD/MOUSE?
210 1.15.8.2 nathanw */
211 1.15.8.2 nathanw static void
212 1.15.8.2 nathanw zs_attach(parent, self, aux)
213 1.15.8.2 nathanw struct device *parent;
214 1.15.8.2 nathanw struct device *self;
215 1.15.8.2 nathanw void *aux;
216 1.15.8.2 nathanw {
217 1.15.8.2 nathanw struct zsc_softc *zsc = (void *) self;
218 1.15.8.2 nathanw struct zsc_attach_args zsc_args;
219 1.15.8.2 nathanw volatile struct zschan *zc;
220 1.15.8.2 nathanw struct zs_chanstate *cs;
221 1.15.8.2 nathanw int s, zs_unit, channel;
222 1.15.8.2 nathanw
223 1.15.8.2 nathanw printf("\n");
224 1.15.8.2 nathanw
225 1.15.8.2 nathanw zs_unit = zsc->zsc_dev.dv_unit;
226 1.15.8.2 nathanw
227 1.15.8.2 nathanw if (zs_unit == 0) {
228 1.15.8.2 nathanw zsaddr[0] = (void *)IIOV(NEXT_P_SCC);
229 1.15.8.2 nathanw }
230 1.15.8.2 nathanw
231 1.15.8.2 nathanw if (zsaddr[zs_unit] == NULL)
232 1.15.8.3 nathanw panic("zs_attach: zs%d not mapped", zs_unit);
233 1.15.8.2 nathanw
234 1.15.8.2 nathanw /*
235 1.15.8.2 nathanw * Initialize software state for each channel.
236 1.15.8.2 nathanw */
237 1.15.8.2 nathanw for (channel = 0; channel < 2; channel++) {
238 1.15.8.2 nathanw zsc_args.channel = channel;
239 1.15.8.2 nathanw zsc_args.hwflags = zs_hwflags[zs_unit][channel];
240 1.15.8.2 nathanw cs = &zsc->zsc_cs_store[channel];
241 1.15.8.2 nathanw zsc->zsc_cs[channel] = cs;
242 1.15.8.2 nathanw
243 1.15.8.2 nathanw cs->cs_channel = channel;
244 1.15.8.2 nathanw cs->cs_private = NULL;
245 1.15.8.2 nathanw cs->cs_ops = &zsops_null;
246 1.15.8.2 nathanw cs->cs_brg_clk = PCLK / 16;
247 1.15.8.2 nathanw
248 1.15.8.2 nathanw zc = zs_get_chan_addr(zs_unit, channel);
249 1.15.8.2 nathanw cs->cs_reg_csr = &zc->zc_csr;
250 1.15.8.2 nathanw cs->cs_reg_data = &zc->zc_data;
251 1.15.8.2 nathanw
252 1.15.8.2 nathanw bcopy(zs_init_reg, cs->cs_creg, 16);
253 1.15.8.2 nathanw bcopy(zs_init_reg, cs->cs_preg, 16);
254 1.15.8.2 nathanw
255 1.15.8.2 nathanw /* XXX: Get these from the PROM properties! */
256 1.15.8.2 nathanw /* XXX: See the mvme167 code. Better. */
257 1.15.8.2 nathanw if (zsc_args.hwflags & ZS_HWFLAG_CONSOLE)
258 1.15.8.2 nathanw cs->cs_defspeed = zs_get_speed(cs);
259 1.15.8.2 nathanw else
260 1.15.8.2 nathanw cs->cs_defspeed = zs_defspeed[zs_unit][channel];
261 1.15.8.2 nathanw cs->cs_defcflag = zs_def_cflag;
262 1.15.8.2 nathanw
263 1.15.8.2 nathanw /* Make these correspond to cs_defcflag (-crtscts) */
264 1.15.8.2 nathanw cs->cs_rr0_dcd = ZSRR0_DCD;
265 1.15.8.2 nathanw cs->cs_rr0_cts = 0;
266 1.15.8.2 nathanw cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
267 1.15.8.2 nathanw cs->cs_wr5_rts = 0;
268 1.15.8.2 nathanw
269 1.15.8.2 nathanw /*
270 1.15.8.2 nathanw * Clear the master interrupt enable.
271 1.15.8.2 nathanw * The INTENA is common to both channels,
272 1.15.8.2 nathanw * so just do it on the A channel.
273 1.15.8.2 nathanw */
274 1.15.8.2 nathanw if (channel == 0) {
275 1.15.8.2 nathanw zs_write_reg(cs, 9, 0);
276 1.15.8.2 nathanw }
277 1.15.8.2 nathanw
278 1.15.8.2 nathanw /*
279 1.15.8.2 nathanw * Look for a child driver for this channel.
280 1.15.8.2 nathanw * The child attach will setup the hardware.
281 1.15.8.2 nathanw */
282 1.15.8.2 nathanw if (!config_found(self, (void *)&zsc_args, zs_print)) {
283 1.15.8.2 nathanw /* No sub-driver. Just reset it. */
284 1.15.8.2 nathanw u_char reset = (channel == 0) ?
285 1.15.8.2 nathanw ZSWR9_A_RESET : ZSWR9_B_RESET;
286 1.15.8.2 nathanw s = splzs();
287 1.15.8.2 nathanw zs_write_reg(cs, 9, reset);
288 1.15.8.2 nathanw splx(s);
289 1.15.8.2 nathanw }
290 1.15.8.2 nathanw }
291 1.15.8.2 nathanw
292 1.15.8.2 nathanw isrlink_autovec(zshard, NULL, NEXT_I_IPL(NEXT_I_SCC), 0, NULL);
293 1.15.8.2 nathanw INTR_ENABLE(NEXT_I_SCC);
294 1.15.8.2 nathanw
295 1.15.8.2 nathanw {
296 1.15.8.2 nathanw int sir;
297 1.15.8.2 nathanw sir = allocate_sir(zssoft, zsc);
298 1.15.8.2 nathanw if (sir != SIR_SERIAL) {
299 1.15.8.2 nathanw panic("Unexpected zssoft sir");
300 1.15.8.2 nathanw }
301 1.15.8.2 nathanw }
302 1.15.8.2 nathanw
303 1.15.8.2 nathanw /*
304 1.15.8.2 nathanw * Set the master interrupt enable and interrupt vector.
305 1.15.8.2 nathanw * (common to both channels, do it on A)
306 1.15.8.2 nathanw */
307 1.15.8.2 nathanw cs = zsc->zsc_cs[0];
308 1.15.8.2 nathanw s = splhigh();
309 1.15.8.2 nathanw /* interrupt vector */
310 1.15.8.2 nathanw zs_write_reg(cs, 2, zs_init_reg[2]);
311 1.15.8.2 nathanw /* master interrupt control (enable) */
312 1.15.8.2 nathanw zs_write_reg(cs, 9, zs_init_reg[9]);
313 1.15.8.2 nathanw splx(s);
314 1.15.8.2 nathanw }
315 1.15.8.2 nathanw
316 1.15.8.2 nathanw static int
317 1.15.8.2 nathanw zs_print(aux, name)
318 1.15.8.2 nathanw void *aux;
319 1.15.8.2 nathanw const char *name;
320 1.15.8.2 nathanw {
321 1.15.8.2 nathanw struct zsc_attach_args *args = aux;
322 1.15.8.2 nathanw
323 1.15.8.2 nathanw if (name != NULL)
324 1.15.8.2 nathanw printf("%s: ", name);
325 1.15.8.2 nathanw
326 1.15.8.2 nathanw if (args->channel != -1)
327 1.15.8.2 nathanw printf(" channel %d", args->channel);
328 1.15.8.2 nathanw
329 1.15.8.2 nathanw return (UNCONF);
330 1.15.8.2 nathanw }
331 1.15.8.2 nathanw
332 1.15.8.2 nathanw static volatile int zssoftpending;
333 1.15.8.2 nathanw
334 1.15.8.2 nathanw /*
335 1.15.8.2 nathanw * Our ZS chips all share a common, autovectored interrupt,
336 1.15.8.2 nathanw * so we have to look at all of them on each interrupt.
337 1.15.8.2 nathanw */
338 1.15.8.2 nathanw static int
339 1.15.8.2 nathanw zshard(arg)
340 1.15.8.2 nathanw void *arg;
341 1.15.8.2 nathanw {
342 1.15.8.2 nathanw register struct zsc_softc *zsc;
343 1.15.8.2 nathanw register int unit, rr3, rval, softreq;
344 1.15.8.2 nathanw if (!INTR_OCCURRED(NEXT_I_SCC)) return 0;
345 1.15.8.2 nathanw
346 1.15.8.2 nathanw rval = softreq = 0;
347 1.15.8.2 nathanw for (unit = 0; unit < zsc_cd.cd_ndevs; unit++) {
348 1.15.8.2 nathanw zsc = zsc_cd.cd_devs[unit];
349 1.15.8.2 nathanw if (zsc == NULL)
350 1.15.8.2 nathanw continue;
351 1.15.8.2 nathanw rr3 = zsc_intr_hard(zsc);
352 1.15.8.2 nathanw /* Count up the interrupts. */
353 1.15.8.2 nathanw if (rr3) {
354 1.15.8.2 nathanw rval |= rr3;
355 1.15.8.2 nathanw zsc->zsc_intrcnt.ev_count++;
356 1.15.8.2 nathanw }
357 1.15.8.2 nathanw softreq |= zsc->zsc_cs[0]->cs_softreq;
358 1.15.8.2 nathanw softreq |= zsc->zsc_cs[1]->cs_softreq;
359 1.15.8.2 nathanw }
360 1.15.8.2 nathanw
361 1.15.8.2 nathanw /* We are at splzs here, so no need to lock. */
362 1.15.8.2 nathanw if (softreq && (zssoftpending == 0)) {
363 1.15.8.2 nathanw zssoftpending = 1;
364 1.15.8.2 nathanw setsoftserial();
365 1.15.8.2 nathanw }
366 1.15.8.2 nathanw return(1);
367 1.15.8.2 nathanw }
368 1.15.8.2 nathanw
369 1.15.8.2 nathanw /*
370 1.15.8.2 nathanw * Similar scheme as for zshard (look at all of them)
371 1.15.8.2 nathanw */
372 1.15.8.2 nathanw static void
373 1.15.8.2 nathanw zssoft(arg)
374 1.15.8.2 nathanw void *arg;
375 1.15.8.2 nathanw {
376 1.15.8.2 nathanw register struct zsc_softc *zsc;
377 1.15.8.2 nathanw register int s, unit;
378 1.15.8.2 nathanw
379 1.15.8.2 nathanw /* This is not the only ISR on this IPL. */
380 1.15.8.2 nathanw if (zssoftpending == 0)
381 1.15.8.2 nathanw panic("zssoft not pending");
382 1.15.8.2 nathanw
383 1.15.8.2 nathanw /*
384 1.15.8.2 nathanw * The soft intr. bit will be set by zshard only if
385 1.15.8.2 nathanw * the variable zssoftpending is zero. The order of
386 1.15.8.2 nathanw * these next two statements prevents our clearing
387 1.15.8.2 nathanw * the soft intr bit just after zshard has set it.
388 1.15.8.2 nathanw */
389 1.15.8.2 nathanw /* ienab_bic(IE_ZSSOFT); */
390 1.15.8.2 nathanw zssoftpending = 0;
391 1.15.8.2 nathanw
392 1.15.8.2 nathanw /* Make sure we call the tty layer at spltty. */
393 1.15.8.2 nathanw s = spltty();
394 1.15.8.2 nathanw for (unit = 0; unit < zsc_cd.cd_ndevs; unit++) {
395 1.15.8.2 nathanw zsc = zsc_cd.cd_devs[unit];
396 1.15.8.2 nathanw if (zsc == NULL)
397 1.15.8.2 nathanw continue;
398 1.15.8.2 nathanw (void)zsc_intr_soft(zsc);
399 1.15.8.2 nathanw }
400 1.15.8.2 nathanw splx(s);
401 1.15.8.2 nathanw }
402 1.15.8.2 nathanw
403 1.15.8.2 nathanw
404 1.15.8.2 nathanw /*
405 1.15.8.2 nathanw * Compute the current baud rate given a ZS channel.
406 1.15.8.2 nathanw */
407 1.15.8.2 nathanw static int
408 1.15.8.2 nathanw zs_get_speed(cs)
409 1.15.8.2 nathanw struct zs_chanstate *cs;
410 1.15.8.2 nathanw {
411 1.15.8.2 nathanw int tconst;
412 1.15.8.2 nathanw
413 1.15.8.2 nathanw tconst = zs_read_reg(cs, 12);
414 1.15.8.2 nathanw tconst |= zs_read_reg(cs, 13) << 8;
415 1.15.8.2 nathanw return (TCONST_TO_BPS(cs->cs_brg_clk, tconst));
416 1.15.8.2 nathanw }
417 1.15.8.2 nathanw
418 1.15.8.2 nathanw /*
419 1.15.8.2 nathanw * MD functions for setting the baud rate and control modes.
420 1.15.8.2 nathanw */
421 1.15.8.2 nathanw int
422 1.15.8.2 nathanw zs_set_speed(cs, bps)
423 1.15.8.2 nathanw struct zs_chanstate *cs;
424 1.15.8.2 nathanw int bps; /* bits per second */
425 1.15.8.2 nathanw {
426 1.15.8.2 nathanw int tconst, real_bps;
427 1.15.8.2 nathanw
428 1.15.8.2 nathanw if (bps == 0)
429 1.15.8.2 nathanw return (0);
430 1.15.8.2 nathanw
431 1.15.8.2 nathanw #ifdef DIAGNOSTIC
432 1.15.8.2 nathanw if (cs->cs_brg_clk == 0)
433 1.15.8.2 nathanw panic("zs_set_speed");
434 1.15.8.2 nathanw #endif
435 1.15.8.2 nathanw
436 1.15.8.2 nathanw tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
437 1.15.8.2 nathanw if (tconst < 0)
438 1.15.8.2 nathanw return (EINVAL);
439 1.15.8.2 nathanw
440 1.15.8.2 nathanw /* Convert back to make sure we can do it. */
441 1.15.8.2 nathanw real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
442 1.15.8.2 nathanw
443 1.15.8.2 nathanw /* XXX - Allow some tolerance here? */
444 1.15.8.2 nathanw if (real_bps != bps)
445 1.15.8.2 nathanw return (EINVAL);
446 1.15.8.2 nathanw
447 1.15.8.2 nathanw cs->cs_preg[12] = tconst;
448 1.15.8.2 nathanw cs->cs_preg[13] = tconst >> 8;
449 1.15.8.2 nathanw
450 1.15.8.2 nathanw /* Caller will stuff the pending registers. */
451 1.15.8.2 nathanw return (0);
452 1.15.8.2 nathanw }
453 1.15.8.2 nathanw
454 1.15.8.2 nathanw int
455 1.15.8.2 nathanw zs_set_modes(cs, cflag)
456 1.15.8.2 nathanw struct zs_chanstate *cs;
457 1.15.8.2 nathanw int cflag; /* bits per second */
458 1.15.8.2 nathanw {
459 1.15.8.2 nathanw int s;
460 1.15.8.2 nathanw
461 1.15.8.2 nathanw /*
462 1.15.8.2 nathanw * Output hardware flow control on the chip is horrendous:
463 1.15.8.2 nathanw * if carrier detect drops, the receiver is disabled, and if
464 1.15.8.2 nathanw * CTS drops, the transmitter is stoped IN MID CHARACTER!
465 1.15.8.2 nathanw * Therefore, NEVER set the HFC bit, and instead use the
466 1.15.8.2 nathanw * status interrupt to detect CTS changes.
467 1.15.8.2 nathanw */
468 1.15.8.2 nathanw s = splzs();
469 1.15.8.2 nathanw cs->cs_rr0_pps = 0;
470 1.15.8.2 nathanw if ((cflag & (CLOCAL | MDMBUF)) != 0) {
471 1.15.8.2 nathanw cs->cs_rr0_dcd = 0;
472 1.15.8.2 nathanw if ((cflag & MDMBUF) == 0)
473 1.15.8.2 nathanw cs->cs_rr0_pps = ZSRR0_DCD;
474 1.15.8.2 nathanw } else
475 1.15.8.2 nathanw cs->cs_rr0_dcd = ZSRR0_DCD;
476 1.15.8.2 nathanw if ((cflag & CRTSCTS) != 0) {
477 1.15.8.2 nathanw cs->cs_wr5_dtr = ZSWR5_DTR;
478 1.15.8.2 nathanw cs->cs_wr5_rts = ZSWR5_RTS;
479 1.15.8.2 nathanw cs->cs_rr0_cts = ZSRR0_CTS;
480 1.15.8.2 nathanw } else if ((cflag & CDTRCTS) != 0) {
481 1.15.8.2 nathanw cs->cs_wr5_dtr = 0;
482 1.15.8.2 nathanw cs->cs_wr5_rts = ZSWR5_DTR;
483 1.15.8.2 nathanw cs->cs_rr0_cts = ZSRR0_CTS;
484 1.15.8.2 nathanw } else if ((cflag & MDMBUF) != 0) {
485 1.15.8.2 nathanw cs->cs_wr5_dtr = 0;
486 1.15.8.2 nathanw cs->cs_wr5_rts = ZSWR5_DTR;
487 1.15.8.2 nathanw cs->cs_rr0_cts = ZSRR0_DCD;
488 1.15.8.2 nathanw } else {
489 1.15.8.2 nathanw cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
490 1.15.8.2 nathanw cs->cs_wr5_rts = 0;
491 1.15.8.2 nathanw cs->cs_rr0_cts = 0;
492 1.15.8.2 nathanw }
493 1.15.8.2 nathanw splx(s);
494 1.15.8.2 nathanw
495 1.15.8.2 nathanw /* Caller will stuff the pending registers. */
496 1.15.8.2 nathanw return (0);
497 1.15.8.2 nathanw }
498 1.15.8.2 nathanw
499 1.15.8.2 nathanw /*
500 1.15.8.2 nathanw * Read or write the chip with suitable delays.
501 1.15.8.2 nathanw */
502 1.15.8.2 nathanw
503 1.15.8.2 nathanw u_char
504 1.15.8.2 nathanw zs_read_reg(cs, reg)
505 1.15.8.2 nathanw struct zs_chanstate *cs;
506 1.15.8.2 nathanw u_char reg;
507 1.15.8.2 nathanw {
508 1.15.8.2 nathanw u_char val;
509 1.15.8.2 nathanw
510 1.15.8.2 nathanw *cs->cs_reg_csr = reg;
511 1.15.8.2 nathanw ZS_DELAY();
512 1.15.8.2 nathanw val = *cs->cs_reg_csr;
513 1.15.8.2 nathanw ZS_DELAY();
514 1.15.8.2 nathanw return (val);
515 1.15.8.2 nathanw }
516 1.15.8.2 nathanw
517 1.15.8.2 nathanw void
518 1.15.8.2 nathanw zs_write_reg(cs, reg, val)
519 1.15.8.2 nathanw struct zs_chanstate *cs;
520 1.15.8.2 nathanw u_char reg, val;
521 1.15.8.2 nathanw {
522 1.15.8.2 nathanw *cs->cs_reg_csr = reg;
523 1.15.8.2 nathanw ZS_DELAY();
524 1.15.8.2 nathanw *cs->cs_reg_csr = val;
525 1.15.8.2 nathanw ZS_DELAY();
526 1.15.8.2 nathanw }
527 1.15.8.2 nathanw
528 1.15.8.2 nathanw u_char
529 1.15.8.2 nathanw zs_read_csr(cs)
530 1.15.8.2 nathanw struct zs_chanstate *cs;
531 1.15.8.2 nathanw {
532 1.15.8.2 nathanw register u_char val;
533 1.15.8.2 nathanw
534 1.15.8.2 nathanw val = *cs->cs_reg_csr;
535 1.15.8.2 nathanw ZS_DELAY();
536 1.15.8.2 nathanw return (val);
537 1.15.8.2 nathanw }
538 1.15.8.2 nathanw
539 1.15.8.2 nathanw void zs_write_csr(cs, val)
540 1.15.8.2 nathanw struct zs_chanstate *cs;
541 1.15.8.2 nathanw u_char val;
542 1.15.8.2 nathanw {
543 1.15.8.2 nathanw *cs->cs_reg_csr = val;
544 1.15.8.2 nathanw ZS_DELAY();
545 1.15.8.2 nathanw }
546 1.15.8.2 nathanw
547 1.15.8.2 nathanw u_char zs_read_data(cs)
548 1.15.8.2 nathanw struct zs_chanstate *cs;
549 1.15.8.2 nathanw {
550 1.15.8.2 nathanw register u_char val;
551 1.15.8.2 nathanw
552 1.15.8.2 nathanw val = *cs->cs_reg_data;
553 1.15.8.2 nathanw ZS_DELAY();
554 1.15.8.2 nathanw return (val);
555 1.15.8.2 nathanw }
556 1.15.8.2 nathanw
557 1.15.8.2 nathanw void zs_write_data(cs, val)
558 1.15.8.2 nathanw struct zs_chanstate *cs;
559 1.15.8.2 nathanw u_char val;
560 1.15.8.2 nathanw {
561 1.15.8.2 nathanw *cs->cs_reg_data = val;
562 1.15.8.2 nathanw ZS_DELAY();
563 1.15.8.2 nathanw }
564 1.15.8.2 nathanw
565 1.15.8.2 nathanw /****************************************************************
566 1.15.8.2 nathanw * Console support functions (Sun specific!)
567 1.15.8.2 nathanw * Note: this code is allowed to know about the layout of
568 1.15.8.2 nathanw * the chip registers, and uses that to keep things simple.
569 1.15.8.2 nathanw * XXX - I think I like the mvme167 code better. -gwr
570 1.15.8.2 nathanw ****************************************************************/
571 1.15.8.2 nathanw
572 1.15.8.2 nathanw extern void Debugger __P((void));
573 1.15.8.2 nathanw void *zs_conschan;
574 1.15.8.2 nathanw int zs_consunit = 0;
575 1.15.8.2 nathanw
576 1.15.8.2 nathanw /*
577 1.15.8.2 nathanw * Handle user request to enter kernel debugger.
578 1.15.8.2 nathanw */
579 1.15.8.2 nathanw void
580 1.15.8.2 nathanw zs_abort(cs)
581 1.15.8.2 nathanw struct zs_chanstate *cs;
582 1.15.8.2 nathanw {
583 1.15.8.2 nathanw #if defined(ZS_CONSOLE_ABORT)
584 1.15.8.2 nathanw register volatile struct zschan *zc = zs_conschan;
585 1.15.8.2 nathanw int rr0;
586 1.15.8.2 nathanw
587 1.15.8.2 nathanw /* Wait for end of break to avoid PROM abort. */
588 1.15.8.2 nathanw /* XXX - Limit the wait? */
589 1.15.8.2 nathanw do {
590 1.15.8.2 nathanw rr0 = zc->zc_csr;
591 1.15.8.2 nathanw ZS_DELAY();
592 1.15.8.2 nathanw } while (rr0 & ZSRR0_BREAK);
593 1.15.8.2 nathanw
594 1.15.8.2 nathanw #if defined(KGDB)
595 1.15.8.2 nathanw zskgdb(cs);
596 1.15.8.2 nathanw #elif defined(DDB)
597 1.15.8.2 nathanw Debugger();
598 1.15.8.2 nathanw #else
599 1.15.8.2 nathanw /* XXX eventually, drop into next rom monitor here */
600 1.15.8.2 nathanw printf("stopping on keyboard abort not supported without DDB or KGDB\n");
601 1.15.8.2 nathanw #endif
602 1.15.8.2 nathanw #else /* !ZS_CONSOLE_ABORT */
603 1.15.8.2 nathanw return;
604 1.15.8.2 nathanw #endif
605 1.15.8.2 nathanw }
606 1.15.8.2 nathanw
607 1.15.8.2 nathanw /*
608 1.15.8.2 nathanw * Polled input char.
609 1.15.8.2 nathanw */
610 1.15.8.2 nathanw int
611 1.15.8.2 nathanw zs_getc(arg)
612 1.15.8.2 nathanw void *arg;
613 1.15.8.2 nathanw {
614 1.15.8.2 nathanw register volatile struct zschan *zc = arg;
615 1.15.8.2 nathanw register int s, c, rr0;
616 1.15.8.2 nathanw
617 1.15.8.2 nathanw s = splhigh();
618 1.15.8.2 nathanw /* Wait for a character to arrive. */
619 1.15.8.2 nathanw do {
620 1.15.8.2 nathanw rr0 = zc->zc_csr;
621 1.15.8.2 nathanw ZS_DELAY();
622 1.15.8.2 nathanw } while ((rr0 & ZSRR0_RX_READY) == 0);
623 1.15.8.2 nathanw
624 1.15.8.2 nathanw c = zc->zc_data;
625 1.15.8.2 nathanw ZS_DELAY();
626 1.15.8.2 nathanw splx(s);
627 1.15.8.2 nathanw
628 1.15.8.2 nathanw /*
629 1.15.8.2 nathanw * This is used by the kd driver to read scan codes,
630 1.15.8.2 nathanw * so don't translate '\r' ==> '\n' here...
631 1.15.8.2 nathanw */
632 1.15.8.2 nathanw return (c);
633 1.15.8.2 nathanw }
634 1.15.8.2 nathanw
635 1.15.8.2 nathanw /*
636 1.15.8.2 nathanw * Polled output char.
637 1.15.8.2 nathanw */
638 1.15.8.2 nathanw void
639 1.15.8.2 nathanw zs_putc(arg, c)
640 1.15.8.2 nathanw void *arg;
641 1.15.8.2 nathanw int c;
642 1.15.8.2 nathanw {
643 1.15.8.2 nathanw register volatile struct zschan *zc = arg;
644 1.15.8.2 nathanw register int s, rr0;
645 1.15.8.2 nathanw
646 1.15.8.2 nathanw s = splhigh();
647 1.15.8.2 nathanw /* Wait for transmitter to become ready. */
648 1.15.8.2 nathanw do {
649 1.15.8.2 nathanw rr0 = zc->zc_csr;
650 1.15.8.2 nathanw ZS_DELAY();
651 1.15.8.2 nathanw } while ((rr0 & ZSRR0_TX_READY) == 0);
652 1.15.8.2 nathanw
653 1.15.8.2 nathanw
654 1.15.8.2 nathanw zc->zc_data = c;
655 1.15.8.2 nathanw ZS_DELAY();
656 1.15.8.2 nathanw
657 1.15.8.2 nathanw splx(s);
658 1.15.8.2 nathanw }
659 1.15.8.2 nathanw
660 1.15.8.2 nathanw /*****************************************************************/
661 1.15.8.2 nathanw
662 1.15.8.2 nathanw void zscninit __P((struct consdev *));
663 1.15.8.2 nathanw int zscngetc __P((dev_t));
664 1.15.8.2 nathanw void zscnputc __P((dev_t, int));
665 1.15.8.2 nathanw void zscnprobe __P((struct consdev *));
666 1.15.8.2 nathanw
667 1.15.8.2 nathanw void
668 1.15.8.2 nathanw zscnprobe(cp)
669 1.15.8.2 nathanw struct consdev * cp;
670 1.15.8.2 nathanw {
671 1.15.8.2 nathanw extern const struct cdevsw zstty_cdevsw;
672 1.15.8.2 nathanw int maj;
673 1.15.8.2 nathanw maj = cdevsw_lookup_major(&zstty_cdevsw);
674 1.15.8.2 nathanw if (maj != -1) {
675 1.15.8.2 nathanw #ifdef SERCONSOLE
676 1.15.8.2 nathanw cp->cn_pri = CN_REMOTE;
677 1.15.8.2 nathanw #else
678 1.15.8.2 nathanw cp->cn_pri = CN_NORMAL; /* Lower than CN_INTERNAL */
679 1.15.8.2 nathanw #endif
680 1.15.8.2 nathanw zs_consunit = 0;
681 1.15.8.2 nathanw zsaddr[0] = (void *)IIOV(NEXT_P_SCC);
682 1.15.8.2 nathanw cp->cn_dev = makedev(maj, zs_consunit);
683 1.15.8.2 nathanw zs_conschan = zs_get_chan_addr(0, zs_consunit);
684 1.15.8.2 nathanw } else {
685 1.15.8.2 nathanw cp->cn_pri = CN_DEAD;
686 1.15.8.2 nathanw }
687 1.15.8.2 nathanw }
688 1.15.8.2 nathanw
689 1.15.8.2 nathanw
690 1.15.8.2 nathanw void
691 1.15.8.2 nathanw zscninit(cn)
692 1.15.8.2 nathanw struct consdev *cn;
693 1.15.8.2 nathanw {
694 1.15.8.2 nathanw zs_hwflags[0][zs_consunit] = ZS_HWFLAG_CONSOLE;
695 1.15.8.2 nathanw
696 1.15.8.2 nathanw {
697 1.15.8.2 nathanw struct zs_chanstate xcs;
698 1.15.8.2 nathanw struct zs_chanstate *cs;
699 1.15.8.2 nathanw volatile struct zschan *zc;
700 1.15.8.2 nathanw int tconst, s;
701 1.15.8.2 nathanw
702 1.15.8.2 nathanw /* Setup temporary chanstate. */
703 1.15.8.2 nathanw bzero((caddr_t)&xcs, sizeof(xcs));
704 1.15.8.2 nathanw cs = &xcs;
705 1.15.8.2 nathanw zc = zs_conschan;
706 1.15.8.2 nathanw cs->cs_reg_csr = &zc->zc_csr;
707 1.15.8.2 nathanw cs->cs_reg_data = &zc->zc_data;
708 1.15.8.2 nathanw cs->cs_channel = zs_consunit;
709 1.15.8.2 nathanw cs->cs_brg_clk = PCLK / 16;
710 1.15.8.2 nathanw
711 1.15.8.2 nathanw bcopy(zs_init_reg, cs->cs_preg, 16);
712 1.15.8.2 nathanw cs->cs_preg[5] |= ZSWR5_DTR | ZSWR5_RTS;
713 1.15.8.2 nathanw cs->cs_preg[15] = ZSWR15_BREAK_IE;
714 1.15.8.2 nathanw
715 1.15.8.2 nathanw tconst = BPS_TO_TCONST(cs->cs_brg_clk,
716 1.15.8.2 nathanw zs_defspeed[0][zs_consunit]);
717 1.15.8.2 nathanw cs->cs_preg[12] = tconst;
718 1.15.8.2 nathanw cs->cs_preg[13] = tconst >> 8;
719 1.15.8.2 nathanw /* can't use zs_set_speed as we haven't set up the
720 1.15.8.2 nathanw * signal sources, and it's not worth it for now
721 1.15.8.2 nathanw */
722 1.15.8.2 nathanw
723 1.15.8.2 nathanw cs->cs_preg[9] &= ~ZSWR9_MASTER_IE;
724 1.15.8.2 nathanw /* no interrupts until later, after attach. */
725 1.15.8.2 nathanw
726 1.15.8.2 nathanw s = splhigh();
727 1.15.8.2 nathanw zs_loadchannelregs(cs);
728 1.15.8.2 nathanw splx(s);
729 1.15.8.2 nathanw }
730 1.15.8.2 nathanw
731 1.15.8.2 nathanw printf("\nNetBSD/next68k console\n");
732 1.15.8.2 nathanw }
733 1.15.8.2 nathanw
734 1.15.8.2 nathanw /*
735 1.15.8.2 nathanw * Polled console input putchar.
736 1.15.8.2 nathanw */
737 1.15.8.2 nathanw int
738 1.15.8.2 nathanw zscngetc(dev)
739 1.15.8.2 nathanw dev_t dev;
740 1.15.8.2 nathanw {
741 1.15.8.2 nathanw return (zs_getc(zs_conschan));
742 1.15.8.2 nathanw }
743 1.15.8.2 nathanw
744 1.15.8.2 nathanw /*
745 1.15.8.2 nathanw * Polled console output putchar.
746 1.15.8.2 nathanw */
747 1.15.8.2 nathanw void
748 1.15.8.2 nathanw zscnputc(dev, c)
749 1.15.8.2 nathanw dev_t dev;
750 1.15.8.2 nathanw int c;
751 1.15.8.2 nathanw {
752 1.15.8.2 nathanw zs_putc(zs_conschan, c);
753 1.15.8.2 nathanw }
754 1.15.8.2 nathanw
755 1.15.8.2 nathanw /*****************************************************************/
756