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