zs.c revision 1.6.8.3 1 1.6.8.3 nathanw /* $NetBSD: zs.c,v 1.6.8.3 2002/10/18 02:39:07 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.3 nathanw CFATTACH_DECL(zsc, sizeof(struct zsc_softc),
151 1.6.8.3 nathanw zs_match, zs_attach, NULL, NULL);
152 1.6.8.2 nathanw
153 1.6.8.2 nathanw extern struct cfdriver zsc_cd;
154 1.6.8.2 nathanw
155 1.6.8.2 nathanw static int zshard __P((void *));
156 1.6.8.2 nathanw void zssoft __P((void *));
157 1.6.8.2 nathanw #if 0
158 1.6.8.2 nathanw static int zs_get_speed __P((struct zs_chanstate *));
159 1.6.8.2 nathanw #endif
160 1.6.8.2 nathanw
161 1.6.8.2 nathanw /*
162 1.6.8.2 nathanw * Is the zs chip present?
163 1.6.8.2 nathanw */
164 1.6.8.2 nathanw static int
165 1.6.8.2 nathanw zs_match(parent, cf, aux)
166 1.6.8.2 nathanw struct device *parent;
167 1.6.8.2 nathanw struct cfdata *cf;
168 1.6.8.2 nathanw void *aux;
169 1.6.8.2 nathanw {
170 1.6.8.2 nathanw struct hb_attach_args *ha = aux;
171 1.6.8.2 nathanw u_int addr;
172 1.6.8.2 nathanw
173 1.6.8.2 nathanw if (strcmp(ha->ha_name, "zsc"))
174 1.6.8.2 nathanw return 0;
175 1.6.8.2 nathanw
176 1.6.8.2 nathanw /* XXX no default address */
177 1.6.8.2 nathanw if (ha->ha_address == -1)
178 1.6.8.2 nathanw return 0;
179 1.6.8.2 nathanw
180 1.6.8.2 nathanw addr = IIOV(ha->ha_address);
181 1.6.8.2 nathanw /* This returns -1 on a fault (bus error). */
182 1.6.8.2 nathanw if (badaddr((void *)addr, 1))
183 1.6.8.2 nathanw return 0;
184 1.6.8.2 nathanw
185 1.6.8.2 nathanw return 1;
186 1.6.8.2 nathanw }
187 1.6.8.2 nathanw
188 1.6.8.2 nathanw /*
189 1.6.8.2 nathanw * Attach a found zs.
190 1.6.8.2 nathanw */
191 1.6.8.2 nathanw static void
192 1.6.8.2 nathanw zs_attach(parent, self, aux)
193 1.6.8.2 nathanw struct device *parent;
194 1.6.8.2 nathanw struct device *self;
195 1.6.8.2 nathanw void *aux;
196 1.6.8.2 nathanw {
197 1.6.8.2 nathanw struct zsc_softc *zsc = (void *) self;
198 1.6.8.2 nathanw struct cfdata *cf = self->dv_cfdata;
199 1.6.8.2 nathanw struct hb_attach_args *ha = aux;
200 1.6.8.2 nathanw struct zsc_attach_args zsc_args;
201 1.6.8.2 nathanw struct zsdevice *zs;
202 1.6.8.2 nathanw struct zschan *zc;
203 1.6.8.2 nathanw struct zs_chanstate *cs;
204 1.6.8.2 nathanw int s, channel, clk;
205 1.6.8.2 nathanw
206 1.6.8.2 nathanw zs = (void *)IIOV(ha->ha_address);
207 1.6.8.2 nathanw
208 1.6.8.2 nathanw clk = cf->cf_flags;
209 1.6.8.2 nathanw if (clk < 0 || clk >= NPCLK)
210 1.6.8.2 nathanw clk = 0;
211 1.6.8.2 nathanw
212 1.6.8.2 nathanw printf("\n");
213 1.6.8.2 nathanw
214 1.6.8.2 nathanw /*
215 1.6.8.2 nathanw * Initialize software state for each channel.
216 1.6.8.2 nathanw */
217 1.6.8.2 nathanw for (channel = 0; channel < 2; channel++) {
218 1.6.8.2 nathanw zsc_args.channel = channel;
219 1.6.8.2 nathanw cs = &zsc->zsc_cs_store[channel];
220 1.6.8.2 nathanw zsc->zsc_cs[channel] = cs;
221 1.6.8.2 nathanw zc = (channel == 0) ? &zs->zs_chan_a : &zs->zs_chan_b;
222 1.6.8.2 nathanw
223 1.6.8.2 nathanw if (ha->ha_vect != -1)
224 1.6.8.2 nathanw zs_init_reg[2] = ha->ha_vect;
225 1.6.8.2 nathanw
226 1.6.8.2 nathanw if (zc == zc_cons) {
227 1.6.8.2 nathanw memcpy(cs, zs_conschan, sizeof(struct zs_chanstate));
228 1.6.8.2 nathanw zs_conschan = cs;
229 1.6.8.2 nathanw zsc_args.hwflags = ZS_HWFLAG_CONSOLE;
230 1.6.8.2 nathanw } else {
231 1.6.8.2 nathanw cs->cs_reg_csr = &zc->zc_csr;
232 1.6.8.2 nathanw cs->cs_reg_data = &zc->zc_data;
233 1.6.8.2 nathanw memcpy(cs->cs_creg, zs_init_reg, 16);
234 1.6.8.2 nathanw memcpy(cs->cs_preg, zs_init_reg, 16);
235 1.6.8.2 nathanw cs->cs_defspeed = zs_defspeed;
236 1.6.8.2 nathanw zsc_args.hwflags = 0;
237 1.6.8.2 nathanw }
238 1.6.8.2 nathanw
239 1.6.8.2 nathanw cs->cs_defcflag = zs_def_cflag;
240 1.6.8.2 nathanw
241 1.6.8.2 nathanw cs->cs_channel = channel;
242 1.6.8.2 nathanw cs->cs_private = NULL;
243 1.6.8.2 nathanw cs->cs_ops = &zsops_null;
244 1.6.8.2 nathanw cs->cs_brg_clk = pclk[clk] / 16;
245 1.6.8.2 nathanw
246 1.6.8.2 nathanw /* Make these correspond to cs_defcflag (-crtscts) */
247 1.6.8.2 nathanw cs->cs_rr0_dcd = ZSRR0_DCD;
248 1.6.8.2 nathanw cs->cs_rr0_cts = 0;
249 1.6.8.2 nathanw cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
250 1.6.8.2 nathanw cs->cs_wr5_rts = 0;
251 1.6.8.2 nathanw
252 1.6.8.2 nathanw /*
253 1.6.8.2 nathanw * Clear the master interrupt enable.
254 1.6.8.2 nathanw * The INTENA is common to both channels,
255 1.6.8.2 nathanw * so just do it on the A channel.
256 1.6.8.2 nathanw */
257 1.6.8.2 nathanw if (channel == 0) {
258 1.6.8.2 nathanw s = splhigh();
259 1.6.8.2 nathanw zs_write_reg(cs, 9, 0);
260 1.6.8.2 nathanw splx(s);
261 1.6.8.2 nathanw }
262 1.6.8.2 nathanw
263 1.6.8.2 nathanw /*
264 1.6.8.2 nathanw * Look for a child driver for this channel.
265 1.6.8.2 nathanw * The child attach will setup the hardware.
266 1.6.8.2 nathanw */
267 1.6.8.2 nathanw if (!config_found(self, (void *)&zsc_args, zs_print)) {
268 1.6.8.2 nathanw /* No sub-driver. Just reset it. */
269 1.6.8.2 nathanw u_char reset = (channel == 0) ?
270 1.6.8.2 nathanw ZSWR9_A_RESET : ZSWR9_B_RESET;
271 1.6.8.2 nathanw s = splhigh();
272 1.6.8.2 nathanw zs_write_reg(cs, 9, reset);
273 1.6.8.2 nathanw splx(s);
274 1.6.8.2 nathanw }
275 1.6.8.2 nathanw }
276 1.6.8.2 nathanw
277 1.6.8.2 nathanw /*
278 1.6.8.2 nathanw * Now safe to install interrupt handlers.
279 1.6.8.2 nathanw */
280 1.6.8.2 nathanw hb_intr_establish(zs_init_reg[2], zshard, ZSHARD_PRI, zsc);
281 1.6.8.2 nathanw
282 1.6.8.2 nathanw /*
283 1.6.8.2 nathanw * Set the master interrupt enable and interrupt vector.
284 1.6.8.2 nathanw * (common to both channels, do it on A)
285 1.6.8.2 nathanw */
286 1.6.8.2 nathanw cs = zsc->zsc_cs[0];
287 1.6.8.2 nathanw s = splhigh();
288 1.6.8.2 nathanw /* interrupt vector */
289 1.6.8.2 nathanw zs_write_reg(cs, 2, zs_init_reg[2]);
290 1.6.8.2 nathanw /* master interrupt control (enable) */
291 1.6.8.2 nathanw zs_write_reg(cs, 9, zs_init_reg[9]);
292 1.6.8.2 nathanw splx(s);
293 1.6.8.2 nathanw
294 1.6.8.2 nathanw if (zs_sir == 0)
295 1.6.8.2 nathanw zs_sir = allocate_sir(zssoft, zsc);
296 1.6.8.2 nathanw }
297 1.6.8.2 nathanw
298 1.6.8.2 nathanw static int
299 1.6.8.2 nathanw zs_print(aux, name)
300 1.6.8.2 nathanw void *aux;
301 1.6.8.2 nathanw const char *name;
302 1.6.8.2 nathanw {
303 1.6.8.2 nathanw struct zsc_attach_args *args = aux;
304 1.6.8.2 nathanw
305 1.6.8.2 nathanw if (name != NULL)
306 1.6.8.2 nathanw printf("%s: ", name);
307 1.6.8.2 nathanw
308 1.6.8.2 nathanw if (args->channel != -1)
309 1.6.8.2 nathanw printf(" channel %d", args->channel);
310 1.6.8.2 nathanw
311 1.6.8.2 nathanw return UNCONF;
312 1.6.8.2 nathanw }
313 1.6.8.2 nathanw
314 1.6.8.2 nathanw /*
315 1.6.8.2 nathanw * For news68k-port, we don't use autovectored interrupt.
316 1.6.8.2 nathanw * We do not need to look at all of the zs chips.
317 1.6.8.2 nathanw */
318 1.6.8.2 nathanw static int
319 1.6.8.2 nathanw zshard(arg)
320 1.6.8.2 nathanw void *arg;
321 1.6.8.2 nathanw {
322 1.6.8.2 nathanw struct zsc_softc *zsc = arg;
323 1.6.8.2 nathanw int rval;
324 1.6.8.2 nathanw
325 1.6.8.2 nathanw rval = zsc_intr_hard(zsc);
326 1.6.8.2 nathanw
327 1.6.8.2 nathanw /* We are at splzs here, so no need to lock. */
328 1.6.8.2 nathanw if (zsc->zsc_cs[0]->cs_softreq || zsc->zsc_cs[1]->cs_softreq) {
329 1.6.8.2 nathanw setsoftint(zs_sir);
330 1.6.8.2 nathanw }
331 1.6.8.2 nathanw
332 1.6.8.2 nathanw return (rval);
333 1.6.8.2 nathanw }
334 1.6.8.2 nathanw
335 1.6.8.2 nathanw /*
336 1.6.8.2 nathanw * Shared among the all chips. We have to look at all of them.
337 1.6.8.2 nathanw */
338 1.6.8.2 nathanw void
339 1.6.8.2 nathanw zssoft(arg)
340 1.6.8.2 nathanw void *arg;
341 1.6.8.2 nathanw {
342 1.6.8.2 nathanw struct zsc_softc *zsc;
343 1.6.8.2 nathanw int s, unit;
344 1.6.8.2 nathanw
345 1.6.8.2 nathanw /* Make sure we call the tty layer at spltty. */
346 1.6.8.2 nathanw s = spltty();
347 1.6.8.2 nathanw for (unit = 0; unit < zsc_cd.cd_ndevs; unit++) {
348 1.6.8.2 nathanw zsc = zsc_cd.cd_devs[unit];
349 1.6.8.2 nathanw if (zsc == NULL)
350 1.6.8.2 nathanw continue;
351 1.6.8.2 nathanw (void) zsc_intr_soft(zsc);
352 1.6.8.2 nathanw }
353 1.6.8.2 nathanw splx(s);
354 1.6.8.2 nathanw }
355 1.6.8.2 nathanw
356 1.6.8.2 nathanw /*
357 1.6.8.2 nathanw * Compute the current baud rate given a ZS channel.
358 1.6.8.2 nathanw */
359 1.6.8.2 nathanw #if 0
360 1.6.8.2 nathanw static int
361 1.6.8.2 nathanw zs_get_speed(cs)
362 1.6.8.2 nathanw struct zs_chanstate *cs;
363 1.6.8.2 nathanw {
364 1.6.8.2 nathanw int tconst;
365 1.6.8.2 nathanw
366 1.6.8.2 nathanw tconst = zs_read_reg(cs, 12);
367 1.6.8.2 nathanw tconst |= zs_read_reg(cs, 13) << 8;
368 1.6.8.2 nathanw return (TCONST_TO_BPS(cs->cs_brg_clk, tconst));
369 1.6.8.2 nathanw }
370 1.6.8.2 nathanw #endif
371 1.6.8.2 nathanw
372 1.6.8.2 nathanw /*
373 1.6.8.2 nathanw * MD functions for setting the baud rate and control modes.
374 1.6.8.2 nathanw */
375 1.6.8.2 nathanw int
376 1.6.8.2 nathanw zs_set_speed(cs, bps)
377 1.6.8.2 nathanw struct zs_chanstate *cs;
378 1.6.8.2 nathanw int bps; /* bits per second */
379 1.6.8.2 nathanw {
380 1.6.8.2 nathanw int tconst, real_bps;
381 1.6.8.2 nathanw
382 1.6.8.2 nathanw if (bps == 0)
383 1.6.8.2 nathanw return (0);
384 1.6.8.2 nathanw
385 1.6.8.2 nathanw #ifdef DIAGNOSTIC
386 1.6.8.2 nathanw if (cs->cs_brg_clk == 0)
387 1.6.8.2 nathanw panic("zs_set_speed");
388 1.6.8.2 nathanw #endif
389 1.6.8.2 nathanw
390 1.6.8.2 nathanw tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
391 1.6.8.2 nathanw if (tconst < 0)
392 1.6.8.2 nathanw return (EINVAL);
393 1.6.8.2 nathanw
394 1.6.8.2 nathanw /* Convert back to make sure we can do it. */
395 1.6.8.2 nathanw real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
396 1.6.8.2 nathanw
397 1.6.8.2 nathanw /* XXX - Allow some tolerance here? */
398 1.6.8.2 nathanw if (real_bps != bps)
399 1.6.8.2 nathanw return (EINVAL);
400 1.6.8.2 nathanw
401 1.6.8.2 nathanw cs->cs_preg[12] = tconst;
402 1.6.8.2 nathanw cs->cs_preg[13] = tconst >> 8;
403 1.6.8.2 nathanw
404 1.6.8.2 nathanw /* Caller will stuff the pending registers. */
405 1.6.8.2 nathanw return (0);
406 1.6.8.2 nathanw }
407 1.6.8.2 nathanw
408 1.6.8.2 nathanw int
409 1.6.8.2 nathanw zs_set_modes(cs, cflag)
410 1.6.8.2 nathanw struct zs_chanstate *cs;
411 1.6.8.2 nathanw int cflag; /* bits per second */
412 1.6.8.2 nathanw {
413 1.6.8.2 nathanw int s;
414 1.6.8.2 nathanw
415 1.6.8.2 nathanw /*
416 1.6.8.2 nathanw * Output hardware flow control on the chip is horrendous:
417 1.6.8.2 nathanw * if carrier detect drops, the receiver is disabled, and if
418 1.6.8.2 nathanw * CTS drops, the transmitter is stoped IN MID CHARACTER!
419 1.6.8.2 nathanw * Therefore, NEVER set the HFC bit, and instead use the
420 1.6.8.2 nathanw * status interrupt to detect CTS changes.
421 1.6.8.2 nathanw */
422 1.6.8.2 nathanw s = splzs();
423 1.6.8.2 nathanw cs->cs_rr0_pps = 0;
424 1.6.8.2 nathanw if ((cflag & (CLOCAL | MDMBUF)) != 0) {
425 1.6.8.2 nathanw cs->cs_rr0_dcd = 0;
426 1.6.8.2 nathanw if ((cflag & MDMBUF) == 0)
427 1.6.8.2 nathanw cs->cs_rr0_pps = ZSRR0_DCD;
428 1.6.8.2 nathanw } else
429 1.6.8.2 nathanw cs->cs_rr0_dcd = ZSRR0_DCD;
430 1.6.8.2 nathanw if ((cflag & CRTSCTS) != 0) {
431 1.6.8.2 nathanw cs->cs_wr5_dtr = ZSWR5_DTR;
432 1.6.8.2 nathanw cs->cs_wr5_rts = ZSWR5_RTS;
433 1.6.8.2 nathanw cs->cs_rr0_cts = ZSRR0_CTS;
434 1.6.8.2 nathanw } else if ((cflag & MDMBUF) != 0) {
435 1.6.8.2 nathanw cs->cs_wr5_dtr = 0;
436 1.6.8.2 nathanw cs->cs_wr5_rts = ZSWR5_DTR;
437 1.6.8.2 nathanw cs->cs_rr0_cts = ZSRR0_DCD;
438 1.6.8.2 nathanw } else {
439 1.6.8.2 nathanw cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
440 1.6.8.2 nathanw cs->cs_wr5_rts = 0;
441 1.6.8.2 nathanw cs->cs_rr0_cts = 0;
442 1.6.8.2 nathanw }
443 1.6.8.2 nathanw splx(s);
444 1.6.8.2 nathanw
445 1.6.8.2 nathanw /* Caller will stuff the pending registers. */
446 1.6.8.2 nathanw return (0);
447 1.6.8.2 nathanw }
448 1.6.8.2 nathanw
449 1.6.8.2 nathanw
450 1.6.8.2 nathanw /*
451 1.6.8.2 nathanw * Read or write the chip with suitable delays.
452 1.6.8.2 nathanw */
453 1.6.8.2 nathanw
454 1.6.8.2 nathanw u_char
455 1.6.8.2 nathanw zs_read_reg(cs, reg)
456 1.6.8.2 nathanw struct zs_chanstate *cs;
457 1.6.8.2 nathanw u_char reg;
458 1.6.8.2 nathanw {
459 1.6.8.2 nathanw u_char val;
460 1.6.8.2 nathanw
461 1.6.8.2 nathanw *cs->cs_reg_csr = reg;
462 1.6.8.2 nathanw ZS_DELAY();
463 1.6.8.2 nathanw val = *cs->cs_reg_csr;
464 1.6.8.2 nathanw ZS_DELAY();
465 1.6.8.2 nathanw return val;
466 1.6.8.2 nathanw }
467 1.6.8.2 nathanw
468 1.6.8.2 nathanw void
469 1.6.8.2 nathanw zs_write_reg(cs, reg, val)
470 1.6.8.2 nathanw struct zs_chanstate *cs;
471 1.6.8.2 nathanw u_char reg, val;
472 1.6.8.2 nathanw {
473 1.6.8.2 nathanw *cs->cs_reg_csr = reg;
474 1.6.8.2 nathanw ZS_DELAY();
475 1.6.8.2 nathanw *cs->cs_reg_csr = val;
476 1.6.8.2 nathanw ZS_DELAY();
477 1.6.8.2 nathanw }
478 1.6.8.2 nathanw
479 1.6.8.2 nathanw u_char
480 1.6.8.2 nathanw zs_read_csr(cs)
481 1.6.8.2 nathanw struct zs_chanstate *cs;
482 1.6.8.2 nathanw {
483 1.6.8.2 nathanw u_char val;
484 1.6.8.2 nathanw
485 1.6.8.2 nathanw val = *cs->cs_reg_csr;
486 1.6.8.2 nathanw ZS_DELAY();
487 1.6.8.2 nathanw return val;
488 1.6.8.2 nathanw }
489 1.6.8.2 nathanw
490 1.6.8.2 nathanw void
491 1.6.8.2 nathanw zs_write_csr(cs, val)
492 1.6.8.2 nathanw struct zs_chanstate *cs;
493 1.6.8.2 nathanw u_char val;
494 1.6.8.2 nathanw {
495 1.6.8.2 nathanw *cs->cs_reg_csr = val;
496 1.6.8.2 nathanw ZS_DELAY();
497 1.6.8.2 nathanw }
498 1.6.8.2 nathanw
499 1.6.8.2 nathanw u_char
500 1.6.8.2 nathanw zs_read_data(cs)
501 1.6.8.2 nathanw struct zs_chanstate *cs;
502 1.6.8.2 nathanw {
503 1.6.8.2 nathanw u_char val;
504 1.6.8.2 nathanw
505 1.6.8.2 nathanw val = *cs->cs_reg_data;
506 1.6.8.2 nathanw ZS_DELAY();
507 1.6.8.2 nathanw return val;
508 1.6.8.2 nathanw }
509 1.6.8.2 nathanw
510 1.6.8.2 nathanw void
511 1.6.8.2 nathanw zs_write_data(cs, val)
512 1.6.8.2 nathanw struct zs_chanstate *cs;
513 1.6.8.2 nathanw u_char val;
514 1.6.8.2 nathanw {
515 1.6.8.2 nathanw *cs->cs_reg_data = val;
516 1.6.8.2 nathanw ZS_DELAY();
517 1.6.8.2 nathanw }
518 1.6.8.2 nathanw
519 1.6.8.2 nathanw void
520 1.6.8.2 nathanw zs_abort(cs)
521 1.6.8.2 nathanw struct zs_chanstate *cs;
522 1.6.8.2 nathanw {
523 1.6.8.2 nathanw #ifdef DDB
524 1.6.8.2 nathanw Debugger();
525 1.6.8.2 nathanw #endif
526 1.6.8.2 nathanw }
527 1.6.8.2 nathanw
528 1.6.8.2 nathanw /*
529 1.6.8.2 nathanw * Polled input char.
530 1.6.8.2 nathanw */
531 1.6.8.2 nathanw int
532 1.6.8.2 nathanw zs_getc(arg)
533 1.6.8.2 nathanw void *arg;
534 1.6.8.2 nathanw {
535 1.6.8.2 nathanw struct zs_chanstate *cs = arg;
536 1.6.8.2 nathanw int s, c, rr0;
537 1.6.8.2 nathanw
538 1.6.8.2 nathanw s = splhigh();
539 1.6.8.2 nathanw /* Wait for a character to arrive. */
540 1.6.8.2 nathanw do {
541 1.6.8.2 nathanw rr0 = *cs->cs_reg_csr;
542 1.6.8.2 nathanw ZS_DELAY();
543 1.6.8.2 nathanw } while ((rr0 & ZSRR0_RX_READY) == 0);
544 1.6.8.2 nathanw
545 1.6.8.2 nathanw c = *cs->cs_reg_data;
546 1.6.8.2 nathanw ZS_DELAY();
547 1.6.8.2 nathanw splx(s);
548 1.6.8.2 nathanw
549 1.6.8.2 nathanw return c;
550 1.6.8.2 nathanw }
551 1.6.8.2 nathanw
552 1.6.8.2 nathanw /*
553 1.6.8.2 nathanw * Polled output char.
554 1.6.8.2 nathanw */
555 1.6.8.2 nathanw void
556 1.6.8.2 nathanw zs_putc(arg, c)
557 1.6.8.2 nathanw void *arg;
558 1.6.8.2 nathanw int c;
559 1.6.8.2 nathanw {
560 1.6.8.2 nathanw struct zs_chanstate *cs = arg;
561 1.6.8.2 nathanw int s, rr0;
562 1.6.8.2 nathanw
563 1.6.8.2 nathanw s = splhigh();
564 1.6.8.2 nathanw /* Wait for transmitter to become ready. */
565 1.6.8.2 nathanw do {
566 1.6.8.2 nathanw rr0 = *cs->cs_reg_csr;
567 1.6.8.2 nathanw ZS_DELAY();
568 1.6.8.2 nathanw } while ((rr0 & ZSRR0_TX_READY) == 0);
569 1.6.8.2 nathanw
570 1.6.8.2 nathanw *cs->cs_reg_data = c;
571 1.6.8.2 nathanw ZS_DELAY();
572 1.6.8.2 nathanw splx(s);
573 1.6.8.2 nathanw }
574 1.6.8.2 nathanw
575 1.6.8.2 nathanw /*****************************************************************/
576 1.6.8.2 nathanw
577 1.6.8.2 nathanw static void zscnprobe __P((struct consdev *));
578 1.6.8.2 nathanw static void zscninit __P((struct consdev *));
579 1.6.8.2 nathanw static int zscngetc __P((dev_t));
580 1.6.8.2 nathanw static void zscnputc __P((dev_t, int));
581 1.6.8.2 nathanw
582 1.6.8.2 nathanw struct consdev consdev_zs = {
583 1.6.8.2 nathanw zscnprobe,
584 1.6.8.2 nathanw zscninit,
585 1.6.8.2 nathanw zscngetc,
586 1.6.8.2 nathanw zscnputc,
587 1.6.8.2 nathanw nullcnpollc,
588 1.6.8.2 nathanw NULL,
589 1.6.8.2 nathanw };
590 1.6.8.2 nathanw
591 1.6.8.2 nathanw static void
592 1.6.8.2 nathanw zscnprobe(cn)
593 1.6.8.2 nathanw struct consdev *cn;
594 1.6.8.2 nathanw {
595 1.6.8.2 nathanw extern const struct cdevsw zstty_cdevsw;
596 1.6.8.2 nathanw extern int tty00_is_console;
597 1.6.8.2 nathanw
598 1.6.8.2 nathanw cn->cn_dev = makedev(cdevsw_lookup_major(&zstty_cdevsw), 0);
599 1.6.8.2 nathanw if (tty00_is_console)
600 1.6.8.2 nathanw cn->cn_pri = CN_REMOTE;
601 1.6.8.2 nathanw else
602 1.6.8.2 nathanw cn->cn_pri = CN_NORMAL;
603 1.6.8.2 nathanw }
604 1.6.8.2 nathanw
605 1.6.8.2 nathanw static void
606 1.6.8.2 nathanw zscninit(cn)
607 1.6.8.2 nathanw struct consdev *cn;
608 1.6.8.2 nathanw {
609 1.6.8.2 nathanw struct zs_chanstate *cs;
610 1.6.8.2 nathanw
611 1.6.8.2 nathanw extern volatile u_char *sccport0a;
612 1.6.8.2 nathanw
613 1.6.8.2 nathanw zc_cons = (struct zschan *)sccport0a; /* XXX */
614 1.6.8.2 nathanw
615 1.6.8.2 nathanw zs_conschan = cs = &zs_conschan_store;
616 1.6.8.2 nathanw
617 1.6.8.2 nathanw /* Setup temporary chanstate. */
618 1.6.8.2 nathanw cs->cs_reg_csr = &zc_cons->zc_csr;
619 1.6.8.2 nathanw cs->cs_reg_data = &zc_cons->zc_data;
620 1.6.8.2 nathanw
621 1.6.8.2 nathanw /* Initialize the pending registers. */
622 1.6.8.2 nathanw memcpy(cs->cs_preg, zs_init_reg, 16);
623 1.6.8.2 nathanw cs->cs_preg[5] |= ZSWR5_DTR | ZSWR5_RTS;
624 1.6.8.2 nathanw
625 1.6.8.2 nathanw cs->cs_preg[12] = BPS_TO_TCONST(pclk[systype] / 16, 9600); /* XXX */
626 1.6.8.2 nathanw cs->cs_preg[13] = 0;
627 1.6.8.2 nathanw cs->cs_defspeed = 9600;
628 1.6.8.2 nathanw
629 1.6.8.2 nathanw /* Clear the master interrupt enable. */
630 1.6.8.2 nathanw zs_write_reg(cs, 9, 0);
631 1.6.8.2 nathanw
632 1.6.8.2 nathanw /* Reset the whole SCC chip. */
633 1.6.8.2 nathanw zs_write_reg(cs, 9, ZSWR9_HARD_RESET);
634 1.6.8.2 nathanw
635 1.6.8.2 nathanw /* Copy "pending" to "current" and H/W */
636 1.6.8.2 nathanw zs_loadchannelregs(cs);
637 1.6.8.2 nathanw }
638 1.6.8.2 nathanw
639 1.6.8.2 nathanw static int
640 1.6.8.2 nathanw zscngetc(dev)
641 1.6.8.2 nathanw dev_t dev;
642 1.6.8.2 nathanw {
643 1.6.8.2 nathanw return zs_getc((void *)zs_conschan);
644 1.6.8.2 nathanw }
645 1.6.8.2 nathanw
646 1.6.8.2 nathanw static void
647 1.6.8.2 nathanw zscnputc(dev, c)
648 1.6.8.2 nathanw dev_t dev;
649 1.6.8.2 nathanw int c;
650 1.6.8.2 nathanw {
651 1.6.8.2 nathanw zs_putc((void *)zs_conschan, c);
652 1.6.8.2 nathanw }
653