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