1 1.46 thorpej /* $NetBSD: zs.c,v 1.46 2024/01/18 05:12:29 thorpej Exp $ */ 2 1.1 chuck 3 1.10 thorpej /*- 4 1.10 thorpej * Copyright (c) 1996 The NetBSD Foundation, Inc. 5 1.1 chuck * All rights reserved. 6 1.1 chuck * 7 1.10 thorpej * This code is derived from software contributed to The NetBSD Foundation 8 1.10 thorpej * by Gordon W. Ross. 9 1.10 thorpej * 10 1.1 chuck * Redistribution and use in source and binary forms, with or without 11 1.1 chuck * modification, are permitted provided that the following conditions 12 1.1 chuck * are met: 13 1.1 chuck * 1. Redistributions of source code must retain the above copyright 14 1.1 chuck * notice, this list of conditions and the following disclaimer. 15 1.1 chuck * 2. Redistributions in binary form must reproduce the above copyright 16 1.1 chuck * notice, this list of conditions and the following disclaimer in the 17 1.1 chuck * documentation and/or other materials provided with the distribution. 18 1.1 chuck * 19 1.10 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 1.10 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 1.10 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 1.12 gwr * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 1.12 gwr * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 1.10 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 1.10 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 1.10 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 1.10 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 1.10 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 1.10 thorpej * POSSIBILITY OF SUCH DAMAGE. 30 1.1 chuck */ 31 1.4 chuck 32 1.1 chuck /* 33 1.4 chuck * Zilog Z8530 Dual UART driver (machine-dependent part) 34 1.4 chuck * 35 1.4 chuck * Runs two serial lines per chip using slave drivers. 36 1.4 chuck * Plain tty/async lines use the zs_async slave. 37 1.4 chuck * 38 1.33 keihan * Modified for NetBSD/mvme68k by Jason R. Thorpe <thorpej (at) NetBSD.org> 39 1.1 chuck */ 40 1.32 lukem 41 1.32 lukem #include <sys/cdefs.h> 42 1.46 thorpej __KERNEL_RCSID(0, "$NetBSD: zs.c,v 1.46 2024/01/18 05:12:29 thorpej Exp $"); 43 1.46 thorpej 44 1.46 thorpej #include "opt_mvmeconf.h" 45 1.4 chuck 46 1.1 chuck #include <sys/param.h> 47 1.4 chuck #include <sys/systm.h> 48 1.11 gwr #include <sys/conf.h> 49 1.4 chuck #include <sys/device.h> 50 1.4 chuck #include <sys/file.h> 51 1.1 chuck #include <sys/ioctl.h> 52 1.11 gwr #include <sys/kernel.h> 53 1.11 gwr #include <sys/proc.h> 54 1.1 chuck #include <sys/tty.h> 55 1.4 chuck #include <sys/time.h> 56 1.1 chuck #include <sys/syslog.h> 57 1.37 ad #include <sys/cpu.h> 58 1.37 ad #include <sys/bus.h> 59 1.37 ad #include <sys/intr.h> 60 1.4 chuck 61 1.1 chuck #include <dev/cons.h> 62 1.4 chuck #include <dev/ic/z8530reg.h> 63 1.4 chuck #include <machine/z8530var.h> 64 1.1 chuck 65 1.4 chuck #include <mvme68k/dev/zsvar.h> 66 1.1 chuck 67 1.38 tsutsui #include "ioconf.h" 68 1.38 tsutsui 69 1.11 gwr /* 70 1.11 gwr * Some warts needed by z8530tty.c - 71 1.11 gwr * The default parity REALLY needs to be the same as the PROM uses, 72 1.11 gwr * or you can not see messages done with printf during boot-up... 73 1.11 gwr */ 74 1.11 gwr int zs_def_cflag = (CREAD | CS8 | HUPCL); 75 1.11 gwr 76 1.4 chuck /* Flags from zscnprobe() */ 77 1.11 gwr static int zs_hwflags[NZSC][2]; 78 1.1 chuck 79 1.4 chuck /* Default speed for each channel */ 80 1.11 gwr static int zs_defspeed[NZSC][2] = { 81 1.4 chuck { 9600, /* port 1 */ 82 1.4 chuck 9600 }, /* port 2 */ 83 1.4 chuck { 9600, /* port 3 */ 84 1.4 chuck 9600 }, /* port 4 */ 85 1.4 chuck }; 86 1.1 chuck 87 1.4 chuck static struct zs_chanstate zs_conschan_store; 88 1.4 chuck static struct zs_chanstate *zs_conschan; 89 1.1 chuck 90 1.39 tsutsui uint8_t zs_init_reg[16] = { 91 1.4 chuck 0, /* 0: CMD (reset, etc.) */ 92 1.11 gwr 0, /* 1: No interrupts yet. */ 93 1.4 chuck 0x18 + ZSHARD_PRI, /* IVECT */ 94 1.4 chuck ZSWR3_RX_8 | ZSWR3_RX_ENABLE, 95 1.4 chuck ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP, 96 1.4 chuck ZSWR5_TX_8 | ZSWR5_TX_ENABLE, 97 1.4 chuck 0, /* 6: TXSYNC/SYNCLO */ 98 1.4 chuck 0, /* 7: RXSYNC/SYNCHI */ 99 1.4 chuck 0, /* 8: alias for data port */ 100 1.4 chuck ZSWR9_MASTER_IE, 101 1.4 chuck 0, /*10: Misc. TX/RX control bits */ 102 1.4 chuck ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD, 103 1.22 scw 0, /*12: BAUDLO (default=9600) */ 104 1.17 mycroft 0, /*13: BAUDHI (default=9600) */ 105 1.11 gwr ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK, 106 1.16 mycroft ZSWR15_BREAK_IE, 107 1.2 thorpej }; 108 1.2 thorpej 109 1.1 chuck 110 1.4 chuck /**************************************************************** 111 1.4 chuck * Autoconfig 112 1.4 chuck ****************************************************************/ 113 1.1 chuck 114 1.4 chuck /* Definition of the driver for autoconfig. */ 115 1.38 tsutsui static int zsc_print(void *, const char *name); 116 1.38 tsutsui int zs_getc(void *); 117 1.38 tsutsui void zs_putc(void *, int); 118 1.1 chuck 119 1.19 scw #if 0 120 1.38 tsutsui static int zs_get_speed(struct zs_chanstate *); 121 1.19 scw #endif 122 1.11 gwr 123 1.19 scw cons_decl(zsc_pcc); 124 1.19 scw 125 1.19 scw 126 1.4 chuck /* 127 1.4 chuck * Configure children of an SCC. 128 1.4 chuck */ 129 1.4 chuck void 130 1.38 tsutsui zs_config(struct zsc_softc *zsc, struct zsdevice *zs, int vector, int pclk) 131 1.4 chuck { 132 1.4 chuck struct zsc_attach_args zsc_args; 133 1.4 chuck volatile struct zschan *zc; 134 1.4 chuck struct zs_chanstate *cs; 135 1.4 chuck int zsc_unit, channel, s; 136 1.4 chuck 137 1.39 tsutsui zsc_unit = device_unit(zsc->zsc_dev); 138 1.22 scw printf(": Zilog 8530 SCC at vector 0x%x\n", vector); 139 1.19 scw 140 1.4 chuck /* 141 1.4 chuck * Initialize software state for each channel. 142 1.4 chuck */ 143 1.4 chuck for (channel = 0; channel < 2; channel++) { 144 1.11 gwr zsc_args.channel = channel; 145 1.11 gwr zsc_args.hwflags = zs_hwflags[zsc_unit][channel]; 146 1.11 gwr cs = &zsc->zsc_cs_store[channel]; 147 1.11 gwr zsc->zsc_cs[channel] = cs; 148 1.4 chuck 149 1.4 chuck /* 150 1.4 chuck * If we're the console, copy the channel state, and 151 1.4 chuck * adjust the console channel pointer. 152 1.4 chuck */ 153 1.11 gwr if (zsc_args.hwflags & ZS_HWFLAG_CONSOLE) { 154 1.28 scw memcpy(cs, zs_conschan, sizeof(struct zs_chanstate)); 155 1.4 chuck zs_conschan = cs; 156 1.4 chuck } else { 157 1.19 scw zc = (channel == 0) ? &zs->zs_chan_a : &zs->zs_chan_b; 158 1.22 scw cs->cs_reg_csr = zc->zc_csr; 159 1.22 scw cs->cs_reg_data = zc->zc_data; 160 1.28 scw memcpy(cs->cs_creg, zs_init_reg, 16); 161 1.28 scw memcpy(cs->cs_preg, zs_init_reg, 16); 162 1.11 gwr cs->cs_defspeed = zs_defspeed[zsc_unit][channel]; 163 1.4 chuck } 164 1.26 scw 165 1.42 scw zs_lock_init(cs); 166 1.26 scw cs->cs_brg_clk = pclk / 16; 167 1.22 scw cs->cs_creg[2] = cs->cs_preg[2] = vector; 168 1.26 scw zs_set_speed(cs, cs->cs_defspeed); 169 1.26 scw cs->cs_creg[12] = cs->cs_preg[12]; 170 1.26 scw cs->cs_creg[13] = cs->cs_preg[13]; 171 1.11 gwr cs->cs_defcflag = zs_def_cflag; 172 1.1 chuck 173 1.12 gwr /* Make these correspond to cs_defcflag (-crtscts) */ 174 1.12 gwr cs->cs_rr0_dcd = ZSRR0_DCD; 175 1.12 gwr cs->cs_rr0_cts = 0; 176 1.12 gwr cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS; 177 1.12 gwr cs->cs_wr5_rts = 0; 178 1.12 gwr 179 1.4 chuck cs->cs_channel = channel; 180 1.4 chuck cs->cs_private = NULL; 181 1.4 chuck cs->cs_ops = &zsops_null; 182 1.4 chuck 183 1.4 chuck /* 184 1.4 chuck * Clear the master interrupt enable. 185 1.4 chuck * The INTENA is common to both channels, 186 1.4 chuck * so just do it on the A channel. 187 1.22 scw * Write the interrupt vector while we're at it. 188 1.4 chuck */ 189 1.4 chuck if (channel == 0) { 190 1.4 chuck zs_write_reg(cs, 9, 0); 191 1.22 scw zs_write_reg(cs, 2, vector); 192 1.4 chuck } 193 1.1 chuck 194 1.4 chuck /* 195 1.4 chuck * Look for a child driver for this channel. 196 1.4 chuck * The child attach will setup the hardware. 197 1.4 chuck */ 198 1.39 tsutsui if (!config_found(zsc->zsc_dev, (void *)&zsc_args, 199 1.44 thorpej zsc_print, CFARGS_NONE)) { 200 1.4 chuck /* No sub-driver. Just reset it. */ 201 1.39 tsutsui uint8_t reset = (channel == 0) ? 202 1.4 chuck ZSWR9_A_RESET : ZSWR9_B_RESET; 203 1.4 chuck s = splzs(); 204 1.4 chuck zs_write_reg(cs, 9, reset); 205 1.4 chuck splx(s); 206 1.4 chuck } 207 1.4 chuck } 208 1.1 chuck 209 1.4 chuck /* 210 1.20 scw * Allocate a software interrupt cookie. 211 1.4 chuck */ 212 1.37 ad zsc->zsc_softintr_cookie = softint_establish(SOFTINT_SERIAL, 213 1.20 scw (void (*)(void *)) zsc_intr_soft, zsc); 214 1.21 scw #ifdef DEBUG 215 1.20 scw assert(zsc->zsc_softintr_cookie); 216 1.21 scw #endif 217 1.1 chuck } 218 1.1 chuck 219 1.4 chuck static int 220 1.38 tsutsui zsc_print(void *aux, const char *name) 221 1.1 chuck { 222 1.4 chuck struct zsc_attach_args *args = aux; 223 1.1 chuck 224 1.4 chuck if (name != NULL) 225 1.30 thorpej aprint_normal("%s: ", name); 226 1.1 chuck 227 1.4 chuck if (args->channel != -1) 228 1.30 thorpej aprint_normal(" channel %d", args->channel); 229 1.1 chuck 230 1.4 chuck return UNCONF; 231 1.1 chuck } 232 1.1 chuck 233 1.25 scw #if defined(MVME162) || defined(MVME172) 234 1.22 scw /* 235 1.22 scw * Our ZS chips each have their own interrupt vector. 236 1.22 scw */ 237 1.22 scw int 238 1.38 tsutsui zshard_unshared(void *arg) 239 1.22 scw { 240 1.22 scw struct zsc_softc *zsc = arg; 241 1.22 scw int rval; 242 1.22 scw 243 1.22 scw rval = zsc_intr_hard(zsc); 244 1.22 scw 245 1.27 scw if (rval) { 246 1.27 scw if ((zsc->zsc_cs[0]->cs_softreq) || 247 1.27 scw (zsc->zsc_cs[1]->cs_softreq)) 248 1.37 ad softint_schedule(zsc->zsc_softintr_cookie); 249 1.27 scw zsc->zsc_evcnt.ev_count++; 250 1.27 scw } 251 1.22 scw 252 1.38 tsutsui return rval; 253 1.22 scw } 254 1.22 scw #endif 255 1.22 scw 256 1.22 scw #ifdef MVME147 257 1.11 gwr /* 258 1.22 scw * Our ZS chips all share a common, PCC-vectored interrupt, 259 1.11 gwr * so we have to look at all of them on each interrupt. 260 1.11 gwr */ 261 1.1 chuck int 262 1.38 tsutsui zshard_shared(void *arg) 263 1.4 chuck { 264 1.15 scw struct zsc_softc *zsc; 265 1.15 scw int unit, rval; 266 1.1 chuck 267 1.4 chuck rval = 0; 268 1.11 gwr for (unit = 0; unit < zsc_cd.cd_ndevs; unit++) { 269 1.41 cegger zsc = device_lookup_private(&zsc_cd, unit); 270 1.27 scw if (zsc != NULL && zsc_intr_hard(zsc)) { 271 1.27 scw if ((zsc->zsc_cs[0]->cs_softreq) || 272 1.27 scw (zsc->zsc_cs[1]->cs_softreq)) 273 1.37 ad softint_schedule(zsc->zsc_softintr_cookie); 274 1.27 scw zsc->zsc_evcnt.ev_count++; 275 1.27 scw rval++; 276 1.27 scw } 277 1.1 chuck } 278 1.38 tsutsui return rval; 279 1.1 chuck } 280 1.22 scw #endif 281 1.1 chuck 282 1.1 chuck 283 1.19 scw #if 0 284 1.4 chuck /* 285 1.11 gwr * Compute the current baud rate given a ZSCC channel. 286 1.11 gwr */ 287 1.11 gwr static int 288 1.38 tsutsui zs_get_speed(struct zs_chanstate *cs) 289 1.11 gwr { 290 1.11 gwr int tconst; 291 1.11 gwr 292 1.11 gwr tconst = zs_read_reg(cs, 12); 293 1.11 gwr tconst |= zs_read_reg(cs, 13) << 8; 294 1.38 tsutsui return TCONST_TO_BPS(cs->cs_brg_clk, tconst); 295 1.11 gwr } 296 1.19 scw #endif 297 1.11 gwr 298 1.11 gwr /* 299 1.11 gwr * MD functions for setting the baud rate and control modes. 300 1.11 gwr */ 301 1.11 gwr int 302 1.38 tsutsui zs_set_speed(struct zs_chanstate *cs, int bps) 303 1.11 gwr { 304 1.11 gwr int tconst, real_bps; 305 1.11 gwr 306 1.11 gwr if (bps == 0) 307 1.38 tsutsui return 0; 308 1.11 gwr 309 1.11 gwr #ifdef DIAGNOSTIC 310 1.11 gwr if (cs->cs_brg_clk == 0) 311 1.11 gwr panic("zs_set_speed"); 312 1.11 gwr #endif 313 1.11 gwr 314 1.11 gwr tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps); 315 1.11 gwr if (tconst < 0) 316 1.38 tsutsui return EINVAL; 317 1.11 gwr 318 1.11 gwr /* Convert back to make sure we can do it. */ 319 1.11 gwr real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst); 320 1.11 gwr 321 1.23 scw /* Allow 2% tolerance WRT the required bps */ 322 1.24 scw if (((abs(real_bps - bps) * 1000) / bps) > 20) 323 1.38 tsutsui return EINVAL; 324 1.11 gwr 325 1.11 gwr cs->cs_preg[12] = tconst; 326 1.11 gwr cs->cs_preg[13] = tconst >> 8; 327 1.11 gwr 328 1.11 gwr /* Caller will stuff the pending registers. */ 329 1.38 tsutsui return 0; 330 1.11 gwr } 331 1.11 gwr 332 1.11 gwr int 333 1.38 tsutsui zs_set_modes(struct zs_chanstate *cs, int cflag) 334 1.11 gwr { 335 1.11 gwr int s; 336 1.11 gwr 337 1.11 gwr /* 338 1.11 gwr * Output hardware flow control on the chip is horrendous: 339 1.11 gwr * if carrier detect drops, the receiver is disabled, and if 340 1.45 andvar * CTS drops, the transmitter is stopped IN MID CHARACTER! 341 1.11 gwr * Therefore, NEVER set the HFC bit, and instead use the 342 1.11 gwr * status interrupt to detect CTS changes. 343 1.11 gwr */ 344 1.11 gwr s = splzs(); 345 1.18 wrstuden cs->cs_rr0_pps = 0; 346 1.18 wrstuden if ((cflag & (CLOCAL | MDMBUF)) != 0) { 347 1.11 gwr cs->cs_rr0_dcd = 0; 348 1.18 wrstuden if ((cflag & MDMBUF) == 0) 349 1.18 wrstuden cs->cs_rr0_pps = ZSRR0_DCD; 350 1.18 wrstuden } else 351 1.11 gwr cs->cs_rr0_dcd = ZSRR0_DCD; 352 1.13 mycroft if ((cflag & CRTSCTS) != 0) { 353 1.11 gwr cs->cs_wr5_dtr = ZSWR5_DTR; 354 1.11 gwr cs->cs_wr5_rts = ZSWR5_RTS; 355 1.11 gwr cs->cs_rr0_cts = ZSRR0_CTS; 356 1.13 mycroft } else if ((cflag & MDMBUF) != 0) { 357 1.13 mycroft cs->cs_wr5_dtr = 0; 358 1.13 mycroft cs->cs_wr5_rts = ZSWR5_DTR; 359 1.13 mycroft cs->cs_rr0_cts = ZSRR0_DCD; 360 1.11 gwr } else { 361 1.11 gwr cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS; 362 1.11 gwr cs->cs_wr5_rts = 0; 363 1.11 gwr cs->cs_rr0_cts = 0; 364 1.11 gwr } 365 1.11 gwr splx(s); 366 1.11 gwr 367 1.11 gwr /* Caller will stuff the pending registers. */ 368 1.38 tsutsui return 0; 369 1.11 gwr } 370 1.11 gwr 371 1.11 gwr 372 1.11 gwr /* 373 1.4 chuck * Read or write the chip with suitable delays. 374 1.4 chuck */ 375 1.1 chuck 376 1.39 tsutsui uint8_t 377 1.39 tsutsui zs_read_reg(struct zs_chanstate *cs, uint8_t reg) 378 1.4 chuck { 379 1.39 tsutsui uint8_t val; 380 1.4 chuck 381 1.4 chuck *cs->cs_reg_csr = reg; 382 1.4 chuck ZS_DELAY(); 383 1.4 chuck val = *cs->cs_reg_csr; 384 1.4 chuck ZS_DELAY(); 385 1.4 chuck return val; 386 1.1 chuck } 387 1.1 chuck 388 1.4 chuck void 389 1.39 tsutsui zs_write_reg(struct zs_chanstate *cs, uint8_t reg, uint8_t val) 390 1.4 chuck { 391 1.38 tsutsui 392 1.4 chuck *cs->cs_reg_csr = reg; 393 1.4 chuck ZS_DELAY(); 394 1.4 chuck *cs->cs_reg_csr = val; 395 1.4 chuck ZS_DELAY(); 396 1.1 chuck } 397 1.1 chuck 398 1.39 tsutsui uint8_t 399 1.39 tsutsui zs_read_csr(struct zs_chanstate *cs) 400 1.1 chuck { 401 1.39 tsutsui uint8_t val; 402 1.1 chuck 403 1.11 gwr val = *cs->cs_reg_csr; 404 1.4 chuck ZS_DELAY(); 405 1.11 gwr return val; 406 1.1 chuck } 407 1.1 chuck 408 1.38 tsutsui void 409 1.39 tsutsui zs_write_csr(struct zs_chanstate *cs, uint8_t val) 410 1.1 chuck { 411 1.38 tsutsui 412 1.11 gwr *cs->cs_reg_csr = val; 413 1.4 chuck ZS_DELAY(); 414 1.1 chuck } 415 1.1 chuck 416 1.39 tsutsui uint8_t 417 1.38 tsutsui zs_read_data(struct zs_chanstate *cs) 418 1.1 chuck { 419 1.39 tsutsui uint8_t val; 420 1.11 gwr 421 1.11 gwr val = *cs->cs_reg_data; 422 1.4 chuck ZS_DELAY(); 423 1.11 gwr return val; 424 1.1 chuck } 425 1.1 chuck 426 1.38 tsutsui void 427 1.39 tsutsui zs_write_data(struct zs_chanstate *cs, uint8_t val) 428 1.1 chuck { 429 1.38 tsutsui 430 1.4 chuck *cs->cs_reg_data = val; 431 1.4 chuck ZS_DELAY(); 432 1.1 chuck } 433 1.1 chuck 434 1.4 chuck /**************************************************************** 435 1.4 chuck * Console support functions (MVME specific!) 436 1.4 chuck ****************************************************************/ 437 1.4 chuck 438 1.1 chuck /* 439 1.4 chuck * Polled input char. 440 1.1 chuck */ 441 1.1 chuck int 442 1.38 tsutsui zs_getc(void *arg) 443 1.1 chuck { 444 1.15 scw struct zs_chanstate *cs = arg; 445 1.15 scw int s, c, rr0, stat; 446 1.1 chuck 447 1.4 chuck s = splhigh(); 448 1.4 chuck top: 449 1.4 chuck /* Wait for a character to arrive. */ 450 1.4 chuck do { 451 1.5 chuck rr0 = *cs->cs_reg_csr; 452 1.4 chuck ZS_DELAY(); 453 1.4 chuck } while ((rr0 & ZSRR0_RX_READY) == 0); 454 1.4 chuck 455 1.4 chuck /* Read error register. */ 456 1.4 chuck stat = zs_read_reg(cs, 1) & (ZSRR1_FE | ZSRR1_DO | ZSRR1_PE); 457 1.4 chuck if (stat) { 458 1.4 chuck zs_write_csr(cs, ZSM_RESET_ERR); 459 1.4 chuck goto top; 460 1.4 chuck } 461 1.4 chuck 462 1.4 chuck /* Read character. */ 463 1.4 chuck c = *cs->cs_reg_data; 464 1.4 chuck ZS_DELAY(); 465 1.4 chuck splx(s); 466 1.1 chuck 467 1.38 tsutsui return c; 468 1.1 chuck } 469 1.1 chuck 470 1.4 chuck /* 471 1.4 chuck * Polled output char. 472 1.4 chuck */ 473 1.1 chuck void 474 1.38 tsutsui zs_putc(void *arg, int c) 475 1.4 chuck { 476 1.15 scw struct zs_chanstate *cs = arg; 477 1.15 scw int s, rr0; 478 1.4 chuck 479 1.4 chuck s = splhigh(); 480 1.4 chuck /* Wait for transmitter to become ready. */ 481 1.4 chuck do { 482 1.4 chuck rr0 = *cs->cs_reg_csr; 483 1.4 chuck ZS_DELAY(); 484 1.4 chuck } while ((rr0 & ZSRR0_TX_READY) == 0); 485 1.1 chuck 486 1.4 chuck *cs->cs_reg_data = c; 487 1.4 chuck ZS_DELAY(); 488 1.4 chuck splx(s); 489 1.1 chuck } 490 1.1 chuck 491 1.1 chuck /* 492 1.4 chuck * Common parts of console init. 493 1.1 chuck */ 494 1.4 chuck void 495 1.38 tsutsui zs_cnconfig(int zsc_unit, int channel, struct zsdevice *zs, int pclk) 496 1.4 chuck { 497 1.4 chuck struct zs_chanstate *cs; 498 1.19 scw struct zschan *zc; 499 1.19 scw 500 1.19 scw zc = (channel == 0) ? &zs->zs_chan_a : &zs->zs_chan_b; 501 1.4 chuck 502 1.4 chuck /* 503 1.4 chuck * Pointer to channel state. Later, the console channel 504 1.4 chuck * state is copied into the softc, and the console channel 505 1.4 chuck * pointer adjusted to point to the new copy. 506 1.4 chuck */ 507 1.4 chuck zs_conschan = cs = &zs_conschan_store; 508 1.4 chuck zs_hwflags[zsc_unit][channel] = ZS_HWFLAG_CONSOLE; 509 1.4 chuck 510 1.11 gwr /* Setup temporary chanstate. */ 511 1.26 scw cs->cs_brg_clk = pclk / 16; 512 1.22 scw cs->cs_reg_csr = zc->zc_csr; 513 1.22 scw cs->cs_reg_data = zc->zc_data; 514 1.4 chuck 515 1.11 gwr /* Initialize the pending registers. */ 516 1.28 scw memcpy(cs->cs_preg, zs_init_reg, 16); 517 1.11 gwr cs->cs_preg[5] |= (ZSWR5_DTR | ZSWR5_RTS); 518 1.4 chuck 519 1.19 scw #if 0 520 1.11 gwr /* XXX: Preserve BAUD rate from boot loader. */ 521 1.11 gwr /* XXX: Also, why reset the chip here? -gwr */ 522 1.19 scw cs->cs_defspeed = zs_get_speed(cs); 523 1.19 scw #else 524 1.11 gwr cs->cs_defspeed = 9600; /* XXX */ 525 1.19 scw #endif 526 1.26 scw zs_set_speed(cs, cs->cs_defspeed); 527 1.26 scw cs->cs_creg[12] = cs->cs_preg[12]; 528 1.26 scw cs->cs_creg[13] = cs->cs_preg[13]; 529 1.4 chuck 530 1.11 gwr /* Clear the master interrupt enable. */ 531 1.11 gwr zs_write_reg(cs, 9, 0); 532 1.4 chuck 533 1.11 gwr /* Reset the whole SCC chip. */ 534 1.4 chuck zs_write_reg(cs, 9, ZSWR9_HARD_RESET); 535 1.4 chuck 536 1.11 gwr /* Copy "pending" to "current" and H/W. */ 537 1.11 gwr zs_loadchannelregs(cs); 538 1.1 chuck } 539 1.1 chuck 540 1.4 chuck /* 541 1.4 chuck * Polled console input putchar. 542 1.4 chuck */ 543 1.1 chuck int 544 1.38 tsutsui zsc_pcccngetc(dev_t dev) 545 1.1 chuck { 546 1.15 scw struct zs_chanstate *cs = zs_conschan; 547 1.15 scw int c; 548 1.1 chuck 549 1.4 chuck c = zs_getc(cs); 550 1.38 tsutsui return c; 551 1.1 chuck } 552 1.1 chuck 553 1.4 chuck /* 554 1.4 chuck * Polled console output putchar. 555 1.4 chuck */ 556 1.4 chuck void 557 1.38 tsutsui zsc_pcccnputc(dev_t dev, int c) 558 1.1 chuck { 559 1.15 scw struct zs_chanstate *cs = zs_conschan; 560 1.1 chuck 561 1.4 chuck zs_putc(cs, c); 562 1.1 chuck } 563 1.1 chuck 564 1.4 chuck /* 565 1.4 chuck * Handle user request to enter kernel debugger. 566 1.4 chuck */ 567 1.4 chuck void 568 1.38 tsutsui zs_abort(struct zs_chanstate *cs) 569 1.1 chuck { 570 1.4 chuck int rr0; 571 1.1 chuck 572 1.4 chuck /* Wait for end of break to avoid PROM abort. */ 573 1.4 chuck /* XXX - Limit the wait? */ 574 1.4 chuck do { 575 1.4 chuck rr0 = *cs->cs_reg_csr; 576 1.4 chuck ZS_DELAY(); 577 1.4 chuck } while (rr0 & ZSRR0_BREAK); 578 1.1 chuck 579 1.4 chuck mvme68k_abort("SERIAL LINE ABORT"); 580 1.1 chuck } 581