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