zs.c revision 1.44 1 1.44 isaki /* $NetBSD: zs.c,v 1.44 2016/08/05 05:32:02 isaki Exp $ */
2 1.1 oki
3 1.12 minoura /*-
4 1.12 minoura * Copyright (c) 1998 Minoura Makoto
5 1.12 minoura * Copyright (c) 1996 The NetBSD Foundation, Inc.
6 1.12 minoura * All rights reserved.
7 1.1 oki *
8 1.12 minoura * This code is derived from software contributed to The NetBSD Foundation
9 1.12 minoura * by Gordon W. Ross.
10 1.1 oki *
11 1.1 oki * Redistribution and use in source and binary forms, with or without
12 1.1 oki * modification, are permitted provided that the following conditions
13 1.1 oki * are met:
14 1.1 oki * 1. Redistributions of source code must retain the above copyright
15 1.1 oki * notice, this list of conditions and the following disclaimer.
16 1.1 oki * 2. Redistributions in binary form must reproduce the above copyright
17 1.1 oki * notice, this list of conditions and the following disclaimer in the
18 1.1 oki * documentation and/or other materials provided with the distribution.
19 1.12 minoura *
20 1.12 minoura * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
21 1.12 minoura * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22 1.12 minoura * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23 1.12 minoura * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
24 1.12 minoura * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25 1.12 minoura * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26 1.12 minoura * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27 1.12 minoura * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28 1.12 minoura * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29 1.12 minoura * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 1.12 minoura * POSSIBILITY OF SUCH DAMAGE.
31 1.1 oki */
32 1.1 oki
33 1.1 oki /*
34 1.12 minoura * Zilog Z8530 Dual UART driver (machine-dependent part)
35 1.12 minoura *
36 1.12 minoura * X68k uses one Z8530 built-in. Channel A is for RS-232C serial port;
37 1.12 minoura * while channel B is dedicated to the mouse.
38 1.15 minoura * Extra Z8530's can be installed for serial ports. This driver
39 1.15 minoura * supports up to 5 chips including the built-in one.
40 1.1 oki */
41 1.25 lukem
42 1.25 lukem #include <sys/cdefs.h>
43 1.44 isaki __KERNEL_RCSID(0, "$NetBSD: zs.c,v 1.44 2016/08/05 05:32:02 isaki Exp $");
44 1.10 jonathan
45 1.1 oki #include <sys/param.h>
46 1.1 oki #include <sys/systm.h>
47 1.12 minoura #include <sys/conf.h>
48 1.1 oki #include <sys/device.h>
49 1.1 oki #include <sys/file.h>
50 1.1 oki #include <sys/ioctl.h>
51 1.12 minoura #include <sys/kernel.h>
52 1.12 minoura #include <sys/proc.h>
53 1.1 oki #include <sys/tty.h>
54 1.1 oki #include <sys/time.h>
55 1.1 oki #include <sys/syslog.h>
56 1.35 ad #include <sys/cpu.h>
57 1.35 ad #include <sys/bus.h>
58 1.35 ad #include <sys/intr.h>
59 1.1 oki
60 1.15 minoura #include <arch/x68k/dev/intiovar.h>
61 1.12 minoura #include <machine/z8530var.h>
62 1.1 oki
63 1.1 oki #include <dev/ic/z8530reg.h>
64 1.1 oki
65 1.36 tsutsui #include "ioconf.h"
66 1.12 minoura #include "zsc.h" /* NZSC */
67 1.15 minoura #include "opt_zsc.h"
68 1.15 minoura #ifndef ZSCN_SPEED
69 1.15 minoura #define ZSCN_SPEED 9600
70 1.15 minoura #endif
71 1.12 minoura #include "zstty.h"
72 1.1 oki
73 1.1 oki
74 1.26 chs extern void Debugger(void);
75 1.1 oki
76 1.12 minoura /*
77 1.12 minoura * Some warts needed by z8530tty.c -
78 1.12 minoura * The default parity REALLY needs to be the same as the PROM uses,
79 1.12 minoura * or you can not see messages done with printf during boot-up...
80 1.12 minoura */
81 1.12 minoura int zs_def_cflag = (CREAD | CS8 | HUPCL);
82 1.15 minoura int zscn_def_cflag = (CREAD | CS8 | HUPCL);
83 1.12 minoura
84 1.12 minoura /*
85 1.12 minoura * X68k provides a 5.0 MHz clock to the ZS chips.
86 1.12 minoura */
87 1.15 minoura #define PCLK (5 * 1000 * 1000) /* PCLK pin input clock rate */
88 1.15 minoura
89 1.15 minoura
90 1.15 minoura /* Default physical addresses. */
91 1.15 minoura #define ZS_MAXDEV 5
92 1.15 minoura static bus_addr_t zs_physaddr[ZS_MAXDEV] = {
93 1.15 minoura 0x00e98000,
94 1.15 minoura 0x00eafc00,
95 1.15 minoura 0x00eafc10,
96 1.15 minoura 0x00eafc20,
97 1.15 minoura 0x00eafc30
98 1.15 minoura };
99 1.12 minoura
100 1.36 tsutsui static uint8_t zs_init_reg[16] = {
101 1.12 minoura 0, /* 0: CMD (reset, etc.) */
102 1.12 minoura 0, /* 1: No interrupts yet. */
103 1.12 minoura 0x70, /* 2: XXX: IVECT */
104 1.12 minoura ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
105 1.12 minoura ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
106 1.12 minoura ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
107 1.12 minoura 0, /* 6: TXSYNC/SYNCLO */
108 1.12 minoura 0, /* 7: RXSYNC/SYNCHI */
109 1.12 minoura 0, /* 8: alias for data port */
110 1.12 minoura ZSWR9_MASTER_IE,
111 1.12 minoura ZSWR10_NRZ, /*10: Misc. TX/RX control bits */
112 1.12 minoura ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
113 1.14 mycroft ((PCLK/32)/9600)-2, /*12: BAUDLO (default=9600) */
114 1.14 mycroft 0, /*13: BAUDHI (default=9600) */
115 1.12 minoura ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK,
116 1.13 mycroft ZSWR15_BREAK_IE,
117 1.12 minoura };
118 1.1 oki
119 1.12 minoura static volatile struct zschan *conschan = 0;
120 1.1 oki
121 1.1 oki
122 1.12 minoura /****************************************************************
123 1.12 minoura * Autoconfig
124 1.12 minoura ****************************************************************/
125 1.1 oki
126 1.1 oki /* Definition of the driver for autoconfig. */
127 1.36 tsutsui static int zs_match(device_t, cfdata_t, void *);
128 1.36 tsutsui static void zs_attach(device_t, device_t, void *);
129 1.26 chs static int zs_print(void *, const char *name);
130 1.1 oki
131 1.36 tsutsui CFATTACH_DECL_NEW(zsc, sizeof(struct zsc_softc),
132 1.22 thorpej zs_match, zs_attach, NULL, NULL);
133 1.1 oki
134 1.26 chs static int zshard(void *);
135 1.26 chs static int zs_get_speed(struct zs_chanstate *);
136 1.1 oki
137 1.1 oki
138 1.1 oki /*
139 1.12 minoura * Is the zs chip present?
140 1.1 oki */
141 1.31 isaki static int
142 1.36 tsutsui zs_match(device_t parent, cfdata_t cf, void *aux)
143 1.1 oki {
144 1.15 minoura struct intio_attach_args *ia = aux;
145 1.31 isaki struct zsdevice *zsaddr = (void *)ia->ia_addr;
146 1.15 minoura int i;
147 1.1 oki
148 1.31 isaki if (strcmp(ia->ia_name, "zsc") != 0)
149 1.1 oki return 0;
150 1.15 minoura
151 1.15 minoura for (i = 0; i < ZS_MAXDEV; i++)
152 1.31 isaki if (zsaddr == (void *)zs_physaddr[i]) /* XXX */
153 1.15 minoura break;
154 1.43 dholland if (i == ZS_MAXDEV) {
155 1.43 dholland /* not a recognized address */
156 1.15 minoura return 0;
157 1.43 dholland }
158 1.15 minoura
159 1.44 isaki ia->ia_size = 8;
160 1.44 isaki if (intio_map_allocate_region(parent, ia, INTIO_MAP_TESTONLY))
161 1.44 isaki return 0;
162 1.44 isaki
163 1.39 isaki if (badaddr((void *)IIOV(zsaddr)))
164 1.15 minoura return 0;
165 1.15 minoura
166 1.15 minoura return (1);
167 1.1 oki }
168 1.1 oki
169 1.1 oki /*
170 1.1 oki * Attach a found zs.
171 1.1 oki */
172 1.31 isaki static void
173 1.36 tsutsui zs_attach(device_t parent, device_t self, void *aux)
174 1.1 oki {
175 1.36 tsutsui struct zsc_softc *zsc = device_private(self);
176 1.15 minoura struct intio_attach_args *ia = aux;
177 1.12 minoura struct zsc_attach_args zsc_args;
178 1.1 oki volatile struct zschan *zc;
179 1.1 oki struct zs_chanstate *cs;
180 1.42 christos int r __diagused;
181 1.42 christos int s, channel;
182 1.1 oki
183 1.36 tsutsui zsc->zsc_dev = self;
184 1.36 tsutsui aprint_normal("\n");
185 1.36 tsutsui
186 1.31 isaki zsc->zsc_addr = (void *)ia->ia_addr;
187 1.15 minoura
188 1.15 minoura ia->ia_size = 8;
189 1.31 isaki r = intio_map_allocate_region(parent, ia, INTIO_MAP_ALLOCATE);
190 1.15 minoura #ifdef DIAGNOSTIC
191 1.15 minoura if (r)
192 1.31 isaki panic("zs: intio IO map corruption");
193 1.15 minoura #endif
194 1.1 oki
195 1.1 oki /*
196 1.12 minoura * Initialize software state for each channel.
197 1.1 oki */
198 1.12 minoura for (channel = 0; channel < 2; channel++) {
199 1.40 isaki device_t child;
200 1.1 oki
201 1.12 minoura zsc_args.channel = channel;
202 1.12 minoura zsc_args.hwflags = 0;
203 1.12 minoura cs = &zsc->zsc_cs_store[channel];
204 1.12 minoura zsc->zsc_cs[channel] = cs;
205 1.12 minoura
206 1.34 ad zs_lock_init(cs);
207 1.12 minoura cs->cs_channel = channel;
208 1.12 minoura cs->cs_private = NULL;
209 1.12 minoura cs->cs_ops = &zsops_null;
210 1.12 minoura cs->cs_brg_clk = PCLK / 16;
211 1.12 minoura
212 1.12 minoura if (channel == 0)
213 1.39 isaki zc = (volatile void *)IIOV(&zsc->zsc_addr->zs_chan_a);
214 1.12 minoura else
215 1.39 isaki zc = (volatile void *)IIOV(&zsc->zsc_addr->zs_chan_b);
216 1.12 minoura cs->cs_reg_csr = &zc->zc_csr;
217 1.12 minoura cs->cs_reg_data = &zc->zc_data;
218 1.12 minoura
219 1.15 minoura zs_init_reg[2] = ia->ia_intr;
220 1.18 wiz memcpy(cs->cs_creg, zs_init_reg, 16);
221 1.18 wiz memcpy(cs->cs_preg, zs_init_reg, 16);
222 1.12 minoura
223 1.15 minoura if (zc == conschan) {
224 1.15 minoura zsc_args.hwflags |= ZS_HWFLAG_CONSOLE;
225 1.15 minoura cs->cs_defspeed = zs_get_speed(cs);
226 1.15 minoura cs->cs_defcflag = zscn_def_cflag;
227 1.15 minoura } else {
228 1.15 minoura cs->cs_defspeed = 9600;
229 1.15 minoura cs->cs_defcflag = zs_def_cflag;
230 1.15 minoura }
231 1.12 minoura
232 1.12 minoura /* Make these correspond to cs_defcflag (-crtscts) */
233 1.12 minoura cs->cs_rr0_dcd = ZSRR0_DCD;
234 1.12 minoura cs->cs_rr0_cts = 0;
235 1.12 minoura cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
236 1.12 minoura cs->cs_wr5_rts = 0;
237 1.1 oki
238 1.9 msaitoh /*
239 1.12 minoura * Clear the master interrupt enable.
240 1.12 minoura * The INTENA is common to both channels,
241 1.12 minoura * so just do it on the A channel.
242 1.9 msaitoh */
243 1.12 minoura if (channel == 0) {
244 1.12 minoura s = splzs();
245 1.12 minoura zs_write_reg(cs, 9, 0);
246 1.12 minoura splx(s);
247 1.1 oki }
248 1.1 oki
249 1.1 oki /*
250 1.12 minoura * Look for a child driver for this channel.
251 1.12 minoura * The child attach will setup the hardware.
252 1.1 oki */
253 1.12 minoura child = config_found(self, (void *)&zsc_args, zs_print);
254 1.15 minoura #if ZSTTY > 0
255 1.15 minoura if (zc == conschan &&
256 1.36 tsutsui ((child && strcmp(device_xname(child), "zstty0")) ||
257 1.15 minoura child == NULL)) /* XXX */
258 1.36 tsutsui panic("%s: console device mismatch", __func__);
259 1.15 minoura #endif
260 1.12 minoura if (child == NULL) {
261 1.12 minoura /* No sub-driver. Just reset it. */
262 1.36 tsutsui uint8_t reset = (channel == 0) ?
263 1.12 minoura ZSWR9_A_RESET : ZSWR9_B_RESET;
264 1.12 minoura s = splzs();
265 1.12 minoura zs_write_reg(cs, 9, reset);
266 1.12 minoura splx(s);
267 1.1 oki }
268 1.1 oki }
269 1.1 oki
270 1.12 minoura /*
271 1.15 minoura * Now safe to install interrupt handlers.
272 1.15 minoura */
273 1.15 minoura if (intio_intr_establish(ia->ia_intr, "zs", zshard, zsc))
274 1.36 tsutsui panic("%s: interrupt vector busy", __func__);
275 1.35 ad zsc->zsc_softintr_cookie = softint_establish(SOFTINT_SERIAL,
276 1.30 tsutsui (void (*)(void *))zsc_intr_soft, zsc);
277 1.15 minoura /* XXX; evcnt_attach() ? */
278 1.15 minoura
279 1.15 minoura /*
280 1.12 minoura * Set the master interrupt enable and interrupt vector.
281 1.12 minoura * (common to both channels, do it on A)
282 1.12 minoura */
283 1.12 minoura cs = zsc->zsc_cs[0];
284 1.12 minoura s = splzs();
285 1.12 minoura /* interrupt vector */
286 1.15 minoura zs_write_reg(cs, 2, ia->ia_intr);
287 1.12 minoura /* master interrupt control (enable) */
288 1.12 minoura zs_write_reg(cs, 9, zs_init_reg[9]);
289 1.12 minoura splx(s);
290 1.1 oki }
291 1.1 oki
292 1.31 isaki static int
293 1.26 chs zs_print(void *aux, const char *name)
294 1.1 oki {
295 1.12 minoura struct zsc_attach_args *args = aux;
296 1.1 oki
297 1.12 minoura if (name != NULL)
298 1.23 thorpej aprint_normal("%s: ", name);
299 1.1 oki
300 1.12 minoura if (args->channel != -1)
301 1.23 thorpej aprint_normal(" channel %d", args->channel);
302 1.1 oki
303 1.12 minoura return UNCONF;
304 1.1 oki }
305 1.1 oki
306 1.1 oki
307 1.1 oki /*
308 1.15 minoura * For x68k-port, we don't use autovectored interrupt.
309 1.15 minoura * We do not need to look at all of the zs chips.
310 1.1 oki */
311 1.31 isaki static int
312 1.26 chs zshard(void *arg)
313 1.1 oki {
314 1.26 chs struct zsc_softc *zsc = arg;
315 1.26 chs int rval;
316 1.15 minoura int s;
317 1.1 oki
318 1.15 minoura /*
319 1.15 minoura * Actually, zs hardware ipl is 5.
320 1.15 minoura * Here we disable all interrupts to shorten the zshard
321 1.32 isaki * handling time. Otherwise, too many characters are
322 1.15 minoura * dropped.
323 1.15 minoura */
324 1.15 minoura s = splhigh();
325 1.15 minoura rval = zsc_intr_hard(zsc);
326 1.1 oki
327 1.12 minoura /* We are at splzs here, so no need to lock. */
328 1.15 minoura if (zsc->zsc_cs[0]->cs_softreq || zsc->zsc_cs[1]->cs_softreq)
329 1.35 ad softint_schedule(zsc->zsc_softintr_cookie);
330 1.42 christos splx(s);
331 1.15 minoura
332 1.12 minoura return (rval);
333 1.1 oki }
334 1.1 oki
335 1.1 oki /*
336 1.12 minoura * Compute the current baud rate given a ZS channel.
337 1.1 oki */
338 1.31 isaki static int
339 1.26 chs zs_get_speed(struct zs_chanstate *cs)
340 1.1 oki {
341 1.12 minoura int tconst;
342 1.1 oki
343 1.12 minoura tconst = zs_read_reg(cs, 12);
344 1.12 minoura tconst |= zs_read_reg(cs, 13) << 8;
345 1.12 minoura return (TCONST_TO_BPS(cs->cs_brg_clk, tconst));
346 1.1 oki }
347 1.1 oki
348 1.1 oki /*
349 1.12 minoura * MD functions for setting the baud rate and control modes.
350 1.1 oki */
351 1.31 isaki int
352 1.26 chs zs_set_speed(struct zs_chanstate *cs, int bps /* bits per second */)
353 1.1 oki {
354 1.12 minoura int tconst, real_bps;
355 1.1 oki
356 1.12 minoura if (bps == 0)
357 1.1 oki return (0);
358 1.12 minoura
359 1.12 minoura #ifdef DIAGNOSTIC
360 1.12 minoura if (cs->cs_brg_clk == 0)
361 1.12 minoura panic("zs_set_speed");
362 1.12 minoura #endif
363 1.12 minoura
364 1.12 minoura tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
365 1.12 minoura if (tconst < 0)
366 1.1 oki return (EINVAL);
367 1.1 oki
368 1.12 minoura /* Convert back to make sure we can do it. */
369 1.12 minoura real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
370 1.1 oki
371 1.15 minoura #if 0 /* XXX */
372 1.12 minoura /* XXX - Allow some tolerance here? */
373 1.12 minoura if (real_bps != bps)
374 1.12 minoura return (EINVAL);
375 1.15 minoura #else
376 1.15 minoura /*
377 1.15 minoura * Since our PCLK has somewhat strange value,
378 1.15 minoura * we have to allow tolerance here.
379 1.15 minoura */
380 1.15 minoura if (BPS_TO_TCONST(cs->cs_brg_clk, real_bps) != tconst)
381 1.15 minoura return (EINVAL);
382 1.15 minoura #endif
383 1.12 minoura
384 1.12 minoura cs->cs_preg[12] = tconst;
385 1.12 minoura cs->cs_preg[13] = tconst >> 8;
386 1.1 oki
387 1.12 minoura /* Caller will stuff the pending registers. */
388 1.12 minoura return (0);
389 1.12 minoura }
390 1.1 oki
391 1.31 isaki int
392 1.26 chs zs_set_modes(struct zs_chanstate *cs, int cflag /* bits per second */)
393 1.12 minoura {
394 1.12 minoura int s;
395 1.1 oki
396 1.1 oki /*
397 1.12 minoura * Output hardware flow control on the chip is horrendous:
398 1.12 minoura * if carrier detect drops, the receiver is disabled, and if
399 1.12 minoura * CTS drops, the transmitter is stoped IN MID CHARACTER!
400 1.12 minoura * Therefore, NEVER set the HFC bit, and instead use the
401 1.12 minoura * status interrupt to detect CTS changes.
402 1.1 oki */
403 1.12 minoura s = splzs();
404 1.17 wrstuden cs->cs_rr0_pps = 0;
405 1.17 wrstuden if ((cflag & (CLOCAL | MDMBUF)) != 0) {
406 1.12 minoura cs->cs_rr0_dcd = 0;
407 1.17 wrstuden if ((cflag & MDMBUF) == 0)
408 1.17 wrstuden cs->cs_rr0_pps = ZSRR0_DCD;
409 1.17 wrstuden } else
410 1.12 minoura cs->cs_rr0_dcd = ZSRR0_DCD;
411 1.12 minoura if ((cflag & CRTSCTS) != 0) {
412 1.12 minoura cs->cs_wr5_dtr = ZSWR5_DTR;
413 1.12 minoura cs->cs_wr5_rts = ZSWR5_RTS;
414 1.12 minoura cs->cs_rr0_cts = ZSRR0_CTS;
415 1.12 minoura } else if ((cflag & MDMBUF) != 0) {
416 1.12 minoura cs->cs_wr5_dtr = 0;
417 1.12 minoura cs->cs_wr5_rts = ZSWR5_DTR;
418 1.12 minoura cs->cs_rr0_cts = ZSRR0_DCD;
419 1.12 minoura } else {
420 1.12 minoura cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
421 1.12 minoura cs->cs_wr5_rts = 0;
422 1.12 minoura cs->cs_rr0_cts = 0;
423 1.1 oki }
424 1.1 oki splx(s);
425 1.12 minoura
426 1.12 minoura /* Caller will stuff the pending registers. */
427 1.1 oki return (0);
428 1.1 oki }
429 1.1 oki
430 1.12 minoura
431 1.1 oki /*
432 1.12 minoura * Read or write the chip with suitable delays.
433 1.1 oki */
434 1.12 minoura
435 1.36 tsutsui uint8_t
436 1.36 tsutsui zs_read_reg(struct zs_chanstate *cs, uint8_t reg)
437 1.1 oki {
438 1.36 tsutsui uint8_t val;
439 1.1 oki
440 1.12 minoura *cs->cs_reg_csr = reg;
441 1.12 minoura ZS_DELAY();
442 1.12 minoura val = *cs->cs_reg_csr;
443 1.12 minoura ZS_DELAY();
444 1.12 minoura return val;
445 1.1 oki }
446 1.1 oki
447 1.12 minoura void
448 1.36 tsutsui zs_write_reg(struct zs_chanstate *cs, uint8_t reg, uint8_t val)
449 1.1 oki {
450 1.12 minoura *cs->cs_reg_csr = reg;
451 1.12 minoura ZS_DELAY();
452 1.12 minoura *cs->cs_reg_csr = val;
453 1.12 minoura ZS_DELAY();
454 1.1 oki }
455 1.1 oki
456 1.36 tsutsui uint8_t
457 1.31 isaki zs_read_csr(struct zs_chanstate *cs)
458 1.1 oki {
459 1.36 tsutsui uint8_t val;
460 1.1 oki
461 1.12 minoura val = *cs->cs_reg_csr;
462 1.1 oki ZS_DELAY();
463 1.12 minoura return val;
464 1.1 oki }
465 1.1 oki
466 1.31 isaki void
467 1.36 tsutsui zs_write_csr(struct zs_chanstate *cs, uint8_t val)
468 1.1 oki {
469 1.12 minoura *cs->cs_reg_csr = val;
470 1.12 minoura ZS_DELAY();
471 1.1 oki }
472 1.1 oki
473 1.36 tsutsui uint8_t
474 1.31 isaki zs_read_data(struct zs_chanstate *cs)
475 1.1 oki {
476 1.36 tsutsui uint8_t val;
477 1.1 oki
478 1.12 minoura val = *cs->cs_reg_data;
479 1.12 minoura ZS_DELAY();
480 1.12 minoura return val;
481 1.1 oki }
482 1.1 oki
483 1.31 isaki void
484 1.36 tsutsui zs_write_data(struct zs_chanstate *cs, uint8_t val)
485 1.1 oki {
486 1.12 minoura *cs->cs_reg_data = val;
487 1.1 oki ZS_DELAY();
488 1.1 oki }
489 1.1 oki
490 1.15 minoura
491 1.15 minoura /****************************************************************
492 1.15 minoura * Console support functions (x68k specific!)
493 1.15 minoura * Note: this code is allowed to know about the layout of
494 1.15 minoura * the chip registers, and uses that to keep things simple.
495 1.15 minoura * XXX - I think I like the mvme167 code better. -gwr
496 1.15 minoura ****************************************************************/
497 1.15 minoura
498 1.1 oki /*
499 1.12 minoura * Handle user request to enter kernel debugger.
500 1.1 oki */
501 1.31 isaki void
502 1.26 chs zs_abort(struct zs_chanstate *cs)
503 1.1 oki {
504 1.12 minoura int rr0;
505 1.12 minoura
506 1.12 minoura /* Wait for end of break to avoid PROM abort. */
507 1.12 minoura /* XXX - Limit the wait? */
508 1.12 minoura do {
509 1.12 minoura rr0 = *cs->cs_reg_csr;
510 1.12 minoura ZS_DELAY();
511 1.12 minoura } while (rr0 & ZSRR0_BREAK);
512 1.1 oki
513 1.12 minoura #ifdef DDB
514 1.12 minoura Debugger();
515 1.12 minoura #else
516 1.31 isaki printf("BREAK!!\n");
517 1.12 minoura #endif
518 1.1 oki }
519 1.15 minoura
520 1.15 minoura
521 1.15 minoura #if NZSTTY > 0
522 1.15 minoura
523 1.15 minoura #include <dev/cons.h>
524 1.15 minoura cons_decl(zs);
525 1.15 minoura
526 1.26 chs static int zs_getc(void);
527 1.26 chs static void zs_putc(int);
528 1.15 minoura
529 1.37 isaki static struct zs_chanstate zscn_cs;
530 1.37 isaki
531 1.15 minoura /*
532 1.15 minoura * Polled input char.
533 1.15 minoura */
534 1.15 minoura static int
535 1.15 minoura zs_getc(void)
536 1.15 minoura {
537 1.26 chs int s, c, rr0;
538 1.15 minoura
539 1.15 minoura s = splzs();
540 1.15 minoura /* Wait for a character to arrive. */
541 1.15 minoura do {
542 1.15 minoura rr0 = zs_read_csr(&zscn_cs);
543 1.15 minoura } while ((rr0 & ZSRR0_RX_READY) == 0);
544 1.15 minoura
545 1.31 isaki c = zs_read_data(&zscn_cs);
546 1.15 minoura splx(s);
547 1.15 minoura
548 1.15 minoura /*
549 1.15 minoura * This is used by the kd driver to read scan codes,
550 1.15 minoura * so don't translate '\r' ==> '\n' here...
551 1.15 minoura */
552 1.15 minoura return (c);
553 1.15 minoura }
554 1.15 minoura
555 1.15 minoura /*
556 1.15 minoura * Polled output char.
557 1.15 minoura */
558 1.31 isaki static void
559 1.26 chs zs_putc(int c)
560 1.15 minoura {
561 1.26 chs int s, rr0;
562 1.15 minoura
563 1.15 minoura s = splzs();
564 1.15 minoura /* Wait for transmitter to become ready. */
565 1.15 minoura do {
566 1.31 isaki rr0 = zs_read_csr(&zscn_cs);
567 1.15 minoura } while ((rr0 & ZSRR0_TX_READY) == 0);
568 1.15 minoura
569 1.15 minoura zs_write_data(&zscn_cs, c);
570 1.15 minoura splx(s);
571 1.15 minoura }
572 1.15 minoura
573 1.31 isaki void
574 1.26 chs zscninit(struct consdev *cn)
575 1.15 minoura {
576 1.39 isaki volatile struct zschan *cnchan = (volatile void *)IIOV(ZSCN_PHYSADDR);
577 1.15 minoura int s;
578 1.15 minoura
579 1.31 isaki memset(&zscn_cs, 0, sizeof(struct zs_chanstate));
580 1.15 minoura zscn_cs.cs_reg_csr = &cnchan->zc_csr;
581 1.15 minoura zscn_cs.cs_reg_data = &cnchan->zc_data;
582 1.15 minoura zscn_cs.cs_channel = 0;
583 1.15 minoura zscn_cs.cs_brg_clk = PCLK / 16;
584 1.18 wiz memcpy(zscn_cs.cs_preg, zs_init_reg, 16);
585 1.15 minoura zscn_cs.cs_preg[4] = ZSWR4_CLK_X16 | ZSWR4_ONESB; /* XXX */
586 1.41 tsutsui zscn_cs.cs_preg[5] |= ZSWR5_DTR | ZSWR5_RTS;
587 1.15 minoura zs_set_speed(&zscn_cs, ZSCN_SPEED);
588 1.15 minoura s = splzs();
589 1.41 tsutsui zs_write_reg(&zscn_cs, 9, 0);
590 1.41 tsutsui zs_write_reg(&zscn_cs, 9, ZSWR9_HARD_RESET);
591 1.15 minoura zs_loadchannelregs(&zscn_cs);
592 1.15 minoura splx(s);
593 1.15 minoura conschan = cnchan;
594 1.15 minoura }
595 1.15 minoura
596 1.15 minoura /*
597 1.15 minoura * Polled console input putchar.
598 1.15 minoura */
599 1.31 isaki int
600 1.26 chs zscngetc(dev_t dev)
601 1.15 minoura {
602 1.15 minoura return (zs_getc());
603 1.15 minoura }
604 1.15 minoura
605 1.15 minoura /*
606 1.15 minoura * Polled console output putchar.
607 1.15 minoura */
608 1.31 isaki void
609 1.26 chs zscnputc(dev_t dev, int c)
610 1.15 minoura {
611 1.15 minoura zs_putc(c);
612 1.15 minoura }
613 1.15 minoura
614 1.31 isaki void
615 1.26 chs zscnprobe(struct consdev *cd)
616 1.15 minoura {
617 1.15 minoura int maj;
618 1.19 gehenna extern const struct cdevsw zstty_cdevsw;
619 1.15 minoura
620 1.15 minoura /* locate the major number */
621 1.19 gehenna maj = cdevsw_lookup_major(&zstty_cdevsw);
622 1.15 minoura /* XXX: minor number is 0 */
623 1.15 minoura
624 1.19 gehenna if (maj == -1)
625 1.15 minoura cd->cn_pri = CN_DEAD;
626 1.15 minoura else {
627 1.15 minoura #ifdef ZSCONSOLE
628 1.15 minoura cd->cn_pri = CN_REMOTE; /* higher than ITE (CN_INTERNAL) */
629 1.15 minoura #else
630 1.15 minoura cd->cn_pri = CN_NORMAL;
631 1.15 minoura #endif
632 1.15 minoura cd->cn_dev = makedev(maj, 0);
633 1.15 minoura }
634 1.15 minoura }
635 1.15 minoura
636 1.31 isaki void
637 1.26 chs zscnpollc(dev_t dev, int on)
638 1.15 minoura {
639 1.15 minoura }
640 1.15 minoura
641 1.15 minoura #endif
642