Home | History | Annotate | Line # | Download | only in dev
zs.c revision 1.69.8.1
      1  1.69.8.1    bouyer /*	$NetBSD: zs.c,v 1.69.8.1 2000/11/20 20:25:35 bouyer Exp $	*/
      2      1.18   deraadt 
      3      1.50       gwr /*-
      4      1.50       gwr  * Copyright (c) 1996 The NetBSD Foundation, Inc.
      5      1.50       gwr  * All rights reserved.
      6       1.1   deraadt  *
      7      1.50       gwr  * This code is derived from software contributed to The NetBSD Foundation
      8      1.50       gwr  * by Gordon W. Ross.
      9       1.1   deraadt  *
     10       1.1   deraadt  * Redistribution and use in source and binary forms, with or without
     11       1.1   deraadt  * modification, are permitted provided that the following conditions
     12       1.1   deraadt  * are met:
     13       1.1   deraadt  * 1. Redistributions of source code must retain the above copyright
     14       1.1   deraadt  *    notice, this list of conditions and the following disclaimer.
     15       1.1   deraadt  * 2. Redistributions in binary form must reproduce the above copyright
     16       1.1   deraadt  *    notice, this list of conditions and the following disclaimer in the
     17       1.1   deraadt  *    documentation and/or other materials provided with the distribution.
     18       1.1   deraadt  * 3. All advertising materials mentioning features or use of this software
     19       1.1   deraadt  *    must display the following acknowledgement:
     20      1.50       gwr  *        This product includes software developed by the NetBSD
     21      1.50       gwr  *        Foundation, Inc. and its contributors.
     22      1.50       gwr  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23      1.50       gwr  *    contributors may be used to endorse or promote products derived
     24      1.50       gwr  *    from this software without specific prior written permission.
     25      1.50       gwr  *
     26      1.50       gwr  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27      1.50       gwr  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28      1.50       gwr  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29      1.50       gwr  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30      1.50       gwr  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31      1.50       gwr  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32      1.50       gwr  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33      1.50       gwr  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34      1.50       gwr  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35      1.50       gwr  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36      1.50       gwr  * POSSIBILITY OF SUCH DAMAGE.
     37       1.1   deraadt  */
     38       1.1   deraadt 
     39       1.1   deraadt /*
     40      1.50       gwr  * Zilog Z8530 Dual UART driver (machine-dependent part)
     41      1.50       gwr  *
     42      1.50       gwr  * Runs two serial lines per chip using slave drivers.
     43      1.50       gwr  * Plain tty/async lines use the zs_async slave.
     44      1.50       gwr  * Sun keyboard/mouse uses the zs_kbd/zs_ms slaves.
     45       1.1   deraadt  */
     46      1.61  jonathan 
     47      1.61  jonathan #include "opt_ddb.h"
     48      1.38       mrg 
     49       1.1   deraadt #include <sys/param.h>
     50      1.34  christos #include <sys/systm.h>
     51      1.50       gwr #include <sys/conf.h>
     52       1.1   deraadt #include <sys/device.h>
     53       1.1   deraadt #include <sys/file.h>
     54       1.1   deraadt #include <sys/ioctl.h>
     55      1.50       gwr #include <sys/kernel.h>
     56      1.50       gwr #include <sys/proc.h>
     57       1.1   deraadt #include <sys/tty.h>
     58       1.1   deraadt #include <sys/time.h>
     59       1.1   deraadt #include <sys/syslog.h>
     60       1.1   deraadt 
     61      1.64        pk #include <machine/bsd_openprom.h>
     62       1.1   deraadt #include <machine/autoconf.h>
     63  1.69.8.1    bouyer #include <machine/intr.h>
     64      1.37  christos #include <machine/conf.h>
     65      1.50       gwr #include <machine/eeprom.h>
     66      1.50       gwr #include <machine/psl.h>
     67      1.50       gwr #include <machine/z8530var.h>
     68      1.50       gwr 
     69      1.50       gwr #include <dev/cons.h>
     70      1.50       gwr #include <dev/ic/z8530reg.h>
     71       1.1   deraadt 
     72       1.1   deraadt #include <sparc/sparc/vaddrs.h>
     73       1.1   deraadt #include <sparc/sparc/auxreg.h>
     74  1.69.8.1    bouyer #include <sparc/sparc/auxiotwo.h>
     75      1.50       gwr #include <sparc/dev/cons.h>
     76      1.50       gwr 
     77      1.50       gwr #include "kbd.h"	/* NKBD */
     78      1.50       gwr #include "zs.h" 	/* NZS */
     79       1.1   deraadt 
     80      1.50       gwr /* Make life easier for the initialized arrays here. */
     81      1.50       gwr #if NZS < 3
     82      1.50       gwr #undef  NZS
     83      1.50       gwr #define NZS 3
     84       1.1   deraadt #endif
     85       1.1   deraadt 
     86      1.50       gwr /*
     87      1.50       gwr  * Some warts needed by z8530tty.c -
     88      1.50       gwr  * The default parity REALLY needs to be the same as the PROM uses,
     89      1.50       gwr  * or you can not see messages done with printf during boot-up...
     90      1.50       gwr  */
     91      1.50       gwr int zs_def_cflag = (CREAD | CS8 | HUPCL);
     92      1.50       gwr int zs_major = 12;
     93       1.1   deraadt 
     94      1.50       gwr /*
     95      1.50       gwr  * The Sun provides a 4.9152 MHz clock to the ZS chips.
     96      1.50       gwr  */
     97      1.50       gwr #define PCLK	(9600 * 512)	/* PCLK pin input clock rate */
     98       1.1   deraadt 
     99       1.1   deraadt /*
    100       1.1   deraadt  * Select software interrupt bit based on TTY ipl.
    101       1.1   deraadt  */
    102       1.1   deraadt #if PIL_TTY == 1
    103       1.1   deraadt # define IE_ZSSOFT IE_L1
    104       1.1   deraadt #elif PIL_TTY == 4
    105       1.1   deraadt # define IE_ZSSOFT IE_L4
    106       1.1   deraadt #elif PIL_TTY == 6
    107       1.1   deraadt # define IE_ZSSOFT IE_L6
    108       1.1   deraadt #else
    109       1.1   deraadt # error "no suitable software interrupt bit"
    110       1.1   deraadt #endif
    111       1.1   deraadt 
    112      1.50       gwr #define	ZS_DELAY()		(CPU_ISSUN4C ? (0) : delay(2))
    113       1.1   deraadt 
    114      1.50       gwr /* The layout of this is hardware-dependent (padding, order). */
    115      1.50       gwr struct zschan {
    116      1.50       gwr 	volatile u_char	zc_csr;		/* ctrl,status, and indirect access */
    117      1.50       gwr 	u_char		zc_xxx0;
    118      1.50       gwr 	volatile u_char	zc_data;	/* data */
    119      1.50       gwr 	u_char		zc_xxx1;
    120      1.35   thorpej };
    121      1.50       gwr struct zsdevice {
    122      1.50       gwr 	/* Yes, they are backwards. */
    123      1.50       gwr 	struct	zschan zs_chan_b;
    124      1.50       gwr 	struct	zschan zs_chan_a;
    125      1.35   thorpej };
    126       1.1   deraadt 
    127  1.69.8.1    bouyer /* ZS channel used as the console device (if any) */
    128  1.69.8.1    bouyer void *zs_conschan_get, *zs_conschan_put;
    129       1.1   deraadt 
    130      1.50       gwr static u_char zs_init_reg[16] = {
    131      1.50       gwr 	0,	/* 0: CMD (reset, etc.) */
    132      1.50       gwr 	0,	/* 1: No interrupts yet. */
    133      1.50       gwr 	0,	/* 2: IVECT */
    134      1.50       gwr 	ZSWR3_RX_8 | ZSWR3_RX_ENABLE,
    135      1.50       gwr 	ZSWR4_CLK_X16 | ZSWR4_ONESB | ZSWR4_EVENP,
    136      1.50       gwr 	ZSWR5_TX_8 | ZSWR5_TX_ENABLE,
    137      1.50       gwr 	0,	/* 6: TXSYNC/SYNCLO */
    138      1.50       gwr 	0,	/* 7: RXSYNC/SYNCHI */
    139      1.50       gwr 	0,	/* 8: alias for data port */
    140      1.50       gwr 	ZSWR9_MASTER_IE | ZSWR9_NO_VECTOR,
    141      1.50       gwr 	0,	/*10: Misc. TX/RX control bits */
    142      1.50       gwr 	ZSWR11_TXCLK_BAUD | ZSWR11_RXCLK_BAUD,
    143      1.63   mycroft 	((PCLK/32)/9600)-2,	/*12: BAUDLO (default=9600) */
    144      1.63   mycroft 	0,			/*13: BAUDHI (default=9600) */
    145      1.50       gwr 	ZSWR14_BAUD_ENA | ZSWR14_BAUD_FROM_PCLK,
    146      1.62   mycroft 	ZSWR15_BREAK_IE,
    147      1.50       gwr };
    148       1.1   deraadt 
    149  1.69.8.1    bouyer /* Console ops */
    150  1.69.8.1    bouyer static int  zscngetc __P((dev_t));
    151  1.69.8.1    bouyer static void zscnputc __P((dev_t, int));
    152  1.69.8.1    bouyer static void zscnpollc __P((dev_t, int));
    153  1.69.8.1    bouyer 
    154  1.69.8.1    bouyer struct consdev zs_consdev = {
    155  1.69.8.1    bouyer 	NULL,
    156  1.69.8.1    bouyer 	NULL,
    157  1.69.8.1    bouyer 	zscngetc,
    158  1.69.8.1    bouyer 	zscnputc,
    159  1.69.8.1    bouyer 	zscnpollc,
    160  1.69.8.1    bouyer 	NULL,
    161  1.69.8.1    bouyer };
    162      1.34  christos 
    163      1.34  christos 
    164      1.50       gwr /****************************************************************
    165      1.50       gwr  * Autoconfig
    166      1.50       gwr  ****************************************************************/
    167       1.1   deraadt 
    168      1.50       gwr /* Definition of the driver for autoconfig. */
    169      1.57        pk static int  zs_match_mainbus __P((struct device *, struct cfdata *, void *));
    170      1.57        pk static int  zs_match_obio __P((struct device *, struct cfdata *, void *));
    171      1.57        pk static void zs_attach_mainbus __P((struct device *, struct device *, void *));
    172      1.57        pk static void zs_attach_obio __P((struct device *, struct device *, void *));
    173      1.57        pk 
    174  1.69.8.1    bouyer 
    175  1.69.8.1    bouyer static void zs_attach __P((struct zsc_softc *, struct zsdevice *, int));
    176      1.50       gwr static int  zs_print __P((void *, const char *name));
    177       1.1   deraadt 
    178      1.57        pk struct cfattach zs_mainbus_ca = {
    179      1.57        pk 	sizeof(struct zsc_softc), zs_match_mainbus, zs_attach_mainbus
    180      1.57        pk };
    181      1.57        pk 
    182      1.57        pk struct cfattach zs_obio_ca = {
    183      1.57        pk 	sizeof(struct zsc_softc), zs_match_obio, zs_attach_obio
    184      1.50       gwr };
    185       1.1   deraadt 
    186      1.55   thorpej extern struct cfdriver zs_cd;
    187      1.34  christos 
    188      1.50       gwr /* Interrupt handlers. */
    189      1.50       gwr static int zshard __P((void *));
    190      1.50       gwr static int zssoft __P((void *));
    191      1.12   deraadt 
    192      1.50       gwr static int zs_get_speed __P((struct zs_chanstate *));
    193      1.12   deraadt 
    194  1.69.8.1    bouyer /* Console device support */
    195  1.69.8.1    bouyer static int zs_console_flags __P((int, int, int));
    196  1.69.8.1    bouyer 
    197  1.69.8.1    bouyer /* Power management hooks */
    198  1.69.8.1    bouyer int  zs_enable __P((struct zs_chanstate *));
    199  1.69.8.1    bouyer void zs_disable __P((struct zs_chanstate *));
    200  1.69.8.1    bouyer 
    201      1.12   deraadt 
    202       1.1   deraadt /*
    203      1.50       gwr  * Is the zs chip present?
    204       1.1   deraadt  */
    205       1.1   deraadt static int
    206      1.57        pk zs_match_mainbus(parent, cf, aux)
    207      1.16   deraadt 	struct device *parent;
    208      1.45        pk 	struct cfdata *cf;
    209      1.45        pk 	void *aux;
    210       1.1   deraadt {
    211      1.57        pk 	struct mainbus_attach_args *ma = aux;
    212       1.1   deraadt 
    213      1.57        pk 	if (strcmp(cf->cf_driver->cd_name, ma->ma_name) != 0)
    214      1.14   deraadt 		return (0);
    215      1.57        pk 
    216  1.69.8.1    bouyer 	return (1);
    217       1.1   deraadt }
    218       1.1   deraadt 
    219      1.57        pk static int
    220      1.57        pk zs_match_obio(parent, cf, aux)
    221      1.57        pk 	struct device *parent;
    222      1.57        pk 	struct cfdata *cf;
    223      1.57        pk 	void *aux;
    224      1.57        pk {
    225      1.57        pk 	union obio_attach_args *uoba = aux;
    226      1.57        pk 	struct obio4_attach_args *oba;
    227      1.57        pk 
    228      1.57        pk 	if (uoba->uoba_isobio4 == 0) {
    229      1.57        pk 		struct sbus_attach_args *sa = &uoba->uoba_sbus;
    230      1.57        pk 
    231      1.57        pk 		if (strcmp(cf->cf_driver->cd_name, sa->sa_name) != 0)
    232      1.57        pk 			return (0);
    233      1.57        pk 
    234  1.69.8.1    bouyer 		return (1);
    235      1.57        pk 	}
    236      1.57        pk 
    237      1.57        pk 	oba = &uoba->uoba_oba4;
    238      1.58        pk 	return (bus_space_probe(oba->oba_bustag, 0, oba->oba_paddr,
    239      1.58        pk 			        1, 0, 0, NULL, NULL));
    240      1.57        pk }
    241      1.57        pk 
    242      1.57        pk static void
    243      1.57        pk zs_attach_mainbus(parent, self, aux)
    244      1.57        pk 	struct device *parent;
    245      1.57        pk 	struct device *self;
    246      1.57        pk 	void *aux;
    247      1.57        pk {
    248      1.57        pk 	struct zsc_softc *zsc = (void *) self;
    249      1.57        pk 	struct mainbus_attach_args *ma = aux;
    250      1.57        pk 
    251      1.57        pk 	zsc->zsc_bustag = ma->ma_bustag;
    252      1.57        pk 	zsc->zsc_dmatag = ma->ma_dmatag;
    253  1.69.8.1    bouyer 	zsc->zsc_promunit = getpropint(ma->ma_node, "slave", -2);
    254  1.69.8.1    bouyer 	zsc->zsc_node = ma->ma_node;
    255      1.57        pk 
    256  1.69.8.1    bouyer 	/*
    257  1.69.8.1    bouyer 	 * For machines with zs on mainbus (all sun4c models), we expect
    258  1.69.8.1    bouyer 	 * the device registers to be mapped by the PROM.
    259  1.69.8.1    bouyer 	 */
    260  1.69.8.1    bouyer 	zs_attach(zsc, ma->ma_promvaddr, ma->ma_pri);
    261      1.57        pk }
    262      1.57        pk 
    263      1.57        pk static void
    264      1.57        pk zs_attach_obio(parent, self, aux)
    265      1.57        pk 	struct device *parent;
    266      1.57        pk 	struct device *self;
    267      1.57        pk 	void *aux;
    268      1.57        pk {
    269      1.57        pk 	struct zsc_softc *zsc = (void *) self;
    270      1.57        pk 	union obio_attach_args *uoba = aux;
    271      1.57        pk 
    272      1.57        pk 	if (uoba->uoba_isobio4 == 0) {
    273      1.57        pk 		struct sbus_attach_args *sa = &uoba->uoba_sbus;
    274  1.69.8.1    bouyer 		void *va;
    275  1.69.8.1    bouyer 		struct zs_chanstate *cs;
    276  1.69.8.1    bouyer 		int channel;
    277  1.69.8.1    bouyer 
    278  1.69.8.1    bouyer 		if (sa->sa_nintr == 0) {
    279  1.69.8.1    bouyer 			printf(" no interrupt lines\n");
    280  1.69.8.1    bouyer 			return;
    281  1.69.8.1    bouyer 		}
    282  1.69.8.1    bouyer 
    283  1.69.8.1    bouyer 		/*
    284  1.69.8.1    bouyer 		 * Some sun4m models (Javastations) may not map the zs device.
    285  1.69.8.1    bouyer 		 */
    286  1.69.8.1    bouyer 		if (sa->sa_npromvaddrs > 0)
    287  1.69.8.1    bouyer 			va = (void *)sa->sa_promvaddr;
    288  1.69.8.1    bouyer 		else {
    289  1.69.8.1    bouyer 			bus_space_handle_t bh;
    290  1.69.8.1    bouyer 
    291  1.69.8.1    bouyer 			if (sbus_bus_map(sa->sa_bustag,
    292  1.69.8.1    bouyer 					  sa->sa_slot,
    293  1.69.8.1    bouyer 					  sa->sa_offset,
    294  1.69.8.1    bouyer 					  sa->sa_size,
    295  1.69.8.1    bouyer 					  BUS_SPACE_MAP_LINEAR,
    296  1.69.8.1    bouyer 					  0, &bh) != 0) {
    297  1.69.8.1    bouyer 				printf(" cannot map zs registers\n");
    298  1.69.8.1    bouyer 				return;
    299  1.69.8.1    bouyer 			}
    300  1.69.8.1    bouyer 			va = (void *)bh;
    301  1.69.8.1    bouyer 		}
    302  1.69.8.1    bouyer 
    303  1.69.8.1    bouyer 		/*
    304  1.69.8.1    bouyer 		 * Check if power state can be set, e.g. Tadpole 3GX
    305  1.69.8.1    bouyer 		 */
    306  1.69.8.1    bouyer 		if (getpropint(sa->sa_node, "pwr-on-auxio2", 0))
    307  1.69.8.1    bouyer 		{
    308  1.69.8.1    bouyer 			printf (" powered via auxio2");
    309  1.69.8.1    bouyer 			for (channel = 0; channel < 2; channel++) {
    310  1.69.8.1    bouyer 				cs = &zsc->zsc_cs_store[channel];
    311  1.69.8.1    bouyer 				cs->enable = zs_enable;
    312  1.69.8.1    bouyer 				cs->disable = zs_disable;
    313  1.69.8.1    bouyer 			}
    314  1.69.8.1    bouyer 		}
    315  1.69.8.1    bouyer 
    316      1.57        pk 		zsc->zsc_bustag = sa->sa_bustag;
    317      1.57        pk 		zsc->zsc_dmatag = sa->sa_dmatag;
    318  1.69.8.1    bouyer 		zsc->zsc_promunit = getpropint(sa->sa_node, "slave", -2);
    319  1.69.8.1    bouyer 		zsc->zsc_node = sa->sa_node;
    320  1.69.8.1    bouyer 		zs_attach(zsc, va, sa->sa_pri);
    321      1.57        pk 	} else {
    322      1.57        pk 		struct obio4_attach_args *oba = &uoba->uoba_oba4;
    323  1.69.8.1    bouyer 		bus_space_handle_t bh;
    324  1.69.8.1    bouyer 		bus_addr_t paddr = oba->oba_paddr;
    325  1.69.8.1    bouyer 
    326  1.69.8.1    bouyer 		/*
    327  1.69.8.1    bouyer 		 * As for zs on mainbus, we require a PROM mapping.
    328  1.69.8.1    bouyer 		 */
    329  1.69.8.1    bouyer 		if (bus_space_map(oba->oba_bustag,
    330  1.69.8.1    bouyer 				  paddr,
    331  1.69.8.1    bouyer 				  sizeof(struct zsdevice),
    332  1.69.8.1    bouyer 				  BUS_SPACE_MAP_LINEAR | OBIO_BUS_MAP_USE_ROM,
    333  1.69.8.1    bouyer 				  &bh) != 0) {
    334  1.69.8.1    bouyer 			printf(" cannot map zs registers\n");
    335  1.69.8.1    bouyer 			return;
    336  1.69.8.1    bouyer 		}
    337      1.57        pk 		zsc->zsc_bustag = oba->oba_bustag;
    338      1.57        pk 		zsc->zsc_dmatag = oba->oba_dmatag;
    339  1.69.8.1    bouyer 		/* Find prom unit by physical address */
    340  1.69.8.1    bouyer 		if (cpuinfo.cpu_type == CPUTYP_4_100)
    341  1.69.8.1    bouyer 			/*
    342  1.69.8.1    bouyer 			 * On the sun4/100, the top-most 4 bits are zero
    343  1.69.8.1    bouyer 			 * on obio addresses; force them to 1's for the
    344  1.69.8.1    bouyer 			 * sake of the comparison here.
    345  1.69.8.1    bouyer 			 */
    346  1.69.8.1    bouyer 			paddr |= 0xf0000000;
    347  1.69.8.1    bouyer 		zsc->zsc_promunit =
    348  1.69.8.1    bouyer 			(paddr == 0xf1000000) ? 0 :
    349  1.69.8.1    bouyer 			(paddr == 0xf0000000) ? 1 :
    350  1.69.8.1    bouyer 			(paddr == 0xe0000000) ? 2 : -2;
    351  1.69.8.1    bouyer 
    352  1.69.8.1    bouyer 		zs_attach(zsc, (void *)bh, oba->oba_pri);
    353      1.57        pk 	}
    354      1.57        pk }
    355       1.1   deraadt /*
    356       1.1   deraadt  * Attach a found zs.
    357       1.1   deraadt  *
    358       1.1   deraadt  * USE ROM PROPERTIES port-a-ignore-cd AND port-b-ignore-cd FOR
    359       1.1   deraadt  * SOFT CARRIER, AND keyboard PROPERTY FOR KEYBOARD/MOUSE?
    360       1.1   deraadt  */
    361       1.1   deraadt static void
    362  1.69.8.1    bouyer zs_attach(zsc, zsd, pri)
    363      1.57        pk 	struct zsc_softc *zsc;
    364  1.69.8.1    bouyer 	struct zsdevice *zsd;
    365      1.57        pk 	int pri;
    366       1.1   deraadt {
    367      1.50       gwr 	struct zsc_attach_args zsc_args;
    368      1.50       gwr 	struct zs_chanstate *cs;
    369  1.69.8.1    bouyer 	int s, channel;
    370       1.1   deraadt 	static int didintr, prevpri;
    371       1.1   deraadt 
    372  1.69.8.1    bouyer 	if (zsd == NULL) {
    373  1.69.8.1    bouyer 		printf("configuration incomplete\n");
    374  1.69.8.1    bouyer 		return;
    375  1.69.8.1    bouyer 	}
    376  1.69.8.1    bouyer 
    377      1.57        pk 	printf(" softpri %d\n", PIL_TTY);
    378      1.50       gwr 
    379      1.50       gwr 	/*
    380      1.50       gwr 	 * Initialize software state for each channel.
    381      1.50       gwr 	 */
    382      1.50       gwr 	for (channel = 0; channel < 2; channel++) {
    383  1.69.8.1    bouyer 		struct zschan *zc;
    384  1.69.8.1    bouyer 
    385      1.50       gwr 		zsc_args.channel = channel;
    386      1.50       gwr 		cs = &zsc->zsc_cs_store[channel];
    387      1.50       gwr 		zsc->zsc_cs[channel] = cs;
    388      1.50       gwr 
    389      1.50       gwr 		cs->cs_channel = channel;
    390      1.50       gwr 		cs->cs_private = NULL;
    391      1.50       gwr 		cs->cs_ops = &zsops_null;
    392      1.50       gwr 		cs->cs_brg_clk = PCLK / 16;
    393      1.50       gwr 
    394  1.69.8.1    bouyer 		zc = (channel == 0) ? &zsd->zs_chan_a : &zsd->zs_chan_b;
    395  1.69.8.1    bouyer 
    396  1.69.8.1    bouyer 		zsc_args.hwflags = zs_console_flags(zsc->zsc_promunit,
    397  1.69.8.1    bouyer 						    zsc->zsc_node,
    398  1.69.8.1    bouyer 						    channel);
    399  1.69.8.1    bouyer 
    400  1.69.8.1    bouyer 		if (zsc_args.hwflags & ZS_HWFLAG_CONSOLE) {
    401  1.69.8.1    bouyer 			zsc_args.hwflags |= ZS_HWFLAG_USE_CONSDEV;
    402  1.69.8.1    bouyer 			zsc_args.consdev = &zs_consdev;
    403  1.69.8.1    bouyer 		}
    404  1.69.8.1    bouyer 
    405  1.69.8.1    bouyer 		if ((zsc_args.hwflags & ZS_HWFLAG_CONSOLE_INPUT) != 0) {
    406  1.69.8.1    bouyer 			zs_conschan_get = zc;
    407  1.69.8.1    bouyer 		}
    408  1.69.8.1    bouyer 		if ((zsc_args.hwflags & ZS_HWFLAG_CONSOLE_OUTPUT) != 0) {
    409  1.69.8.1    bouyer 			zs_conschan_put = zc;
    410  1.69.8.1    bouyer 		}
    411  1.69.8.1    bouyer 		/* Childs need to set cn_dev, etc */
    412  1.69.8.1    bouyer 
    413      1.50       gwr 		cs->cs_reg_csr  = &zc->zc_csr;
    414      1.50       gwr 		cs->cs_reg_data = &zc->zc_data;
    415      1.50       gwr 
    416      1.50       gwr 		bcopy(zs_init_reg, cs->cs_creg, 16);
    417      1.50       gwr 		bcopy(zs_init_reg, cs->cs_preg, 16);
    418      1.50       gwr 
    419  1.69.8.1    bouyer 		/* XXX: Consult PROM properties for this?! */
    420  1.69.8.1    bouyer 		cs->cs_defspeed = zs_get_speed(cs);
    421      1.50       gwr 		cs->cs_defcflag = zs_def_cflag;
    422      1.50       gwr 
    423      1.50       gwr 		/* Make these correspond to cs_defcflag (-crtscts) */
    424      1.50       gwr 		cs->cs_rr0_dcd = ZSRR0_DCD;
    425      1.50       gwr 		cs->cs_rr0_cts = 0;
    426      1.50       gwr 		cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
    427      1.50       gwr 		cs->cs_wr5_rts = 0;
    428      1.50       gwr 
    429      1.50       gwr 		/*
    430      1.50       gwr 		 * Clear the master interrupt enable.
    431      1.50       gwr 		 * The INTENA is common to both channels,
    432      1.50       gwr 		 * so just do it on the A channel.
    433      1.50       gwr 		 */
    434      1.50       gwr 		if (channel == 0) {
    435      1.50       gwr 			zs_write_reg(cs, 9, 0);
    436      1.50       gwr 		}
    437      1.50       gwr 
    438      1.50       gwr 		/*
    439      1.50       gwr 		 * Look for a child driver for this channel.
    440      1.50       gwr 		 * The child attach will setup the hardware.
    441      1.50       gwr 		 */
    442      1.57        pk 		if (!config_found(&zsc->zsc_dev, (void *)&zsc_args, zs_print)) {
    443      1.50       gwr 			/* No sub-driver.  Just reset it. */
    444      1.50       gwr 			u_char reset = (channel == 0) ?
    445      1.50       gwr 				ZSWR9_A_RESET : ZSWR9_B_RESET;
    446      1.56       mrg 			s = splzs();
    447      1.50       gwr 			zs_write_reg(cs,  9, reset);
    448      1.50       gwr 			splx(s);
    449      1.50       gwr 		}
    450      1.50       gwr 	}
    451      1.50       gwr 
    452      1.50       gwr 	/*
    453      1.50       gwr 	 * Now safe to install interrupt handlers.  Note the arguments
    454      1.50       gwr 	 * to the interrupt handlers aren't used.  Note, we only do this
    455      1.50       gwr 	 * once since both SCCs interrupt at the same level and vector.
    456      1.50       gwr 	 */
    457       1.1   deraadt 	if (!didintr) {
    458       1.1   deraadt 		didintr = 1;
    459       1.1   deraadt 		prevpri = pri;
    460  1.69.8.1    bouyer 		bus_intr_establish(zsc->zsc_bustag, pri, IPL_SERIAL, 0,
    461  1.69.8.1    bouyer 				   zshard, NULL);
    462  1.69.8.1    bouyer 		bus_intr_establish(zsc->zsc_bustag, PIL_TTY,
    463  1.69.8.1    bouyer 				   IPL_SOFTSERIAL,
    464  1.69.8.1    bouyer 				   BUS_INTR_ESTABLISH_SOFTINTR,
    465  1.69.8.1    bouyer 				   zssoft, NULL);
    466       1.1   deraadt 	} else if (pri != prevpri)
    467       1.1   deraadt 		panic("broken zs interrupt scheme");
    468      1.57        pk 
    469  1.69.8.1    bouyer 	evcnt_attach_dynamic(&zsc->zsc_intrcnt, EVCNT_TYPE_INTR, NULL,
    470  1.69.8.1    bouyer 	    zsc->zsc_dev.dv_xname, "intr");
    471       1.1   deraadt 
    472       1.1   deraadt 	/*
    473      1.50       gwr 	 * Set the master interrupt enable and interrupt vector.
    474      1.50       gwr 	 * (common to both channels, do it on A)
    475       1.1   deraadt 	 */
    476      1.50       gwr 	cs = zsc->zsc_cs[0];
    477       1.1   deraadt 	s = splhigh();
    478      1.50       gwr 	/* interrupt vector */
    479      1.50       gwr 	zs_write_reg(cs, 2, zs_init_reg[2]);
    480      1.50       gwr 	/* master interrupt control (enable) */
    481      1.50       gwr 	zs_write_reg(cs, 9, zs_init_reg[9]);
    482      1.50       gwr 	splx(s);
    483      1.50       gwr 
    484      1.50       gwr #if 0
    485      1.47        pk 	/*
    486      1.50       gwr 	 * XXX: L1A hack - We would like to be able to break into
    487      1.50       gwr 	 * the debugger during the rest of autoconfiguration, so
    488      1.50       gwr 	 * lower interrupts just enough to let zs interrupts in.
    489      1.50       gwr 	 * This is done after both zs devices are attached.
    490      1.50       gwr 	 */
    491  1.69.8.1    bouyer 	if (zsc->zsc_promunit == 1) {
    492      1.50       gwr 		printf("zs1: enabling zs interrupts\n");
    493      1.50       gwr 		(void)splfd(); /* XXX: splzs - 1 */
    494      1.47        pk 	}
    495      1.50       gwr #endif
    496       1.1   deraadt }
    497       1.1   deraadt 
    498      1.50       gwr static int
    499      1.50       gwr zs_print(aux, name)
    500      1.50       gwr 	void *aux;
    501      1.50       gwr 	const char *name;
    502       1.1   deraadt {
    503      1.50       gwr 	struct zsc_attach_args *args = aux;
    504       1.1   deraadt 
    505      1.50       gwr 	if (name != NULL)
    506      1.50       gwr 		printf("%s: ", name);
    507       1.1   deraadt 
    508      1.50       gwr 	if (args->channel != -1)
    509      1.50       gwr 		printf(" channel %d", args->channel);
    510       1.1   deraadt 
    511      1.57        pk 	return (UNCONF);
    512       1.1   deraadt }
    513       1.1   deraadt 
    514      1.50       gwr static volatile int zssoftpending;
    515       1.1   deraadt 
    516       1.1   deraadt /*
    517      1.50       gwr  * Our ZS chips all share a common, autovectored interrupt,
    518      1.50       gwr  * so we have to look at all of them on each interrupt.
    519       1.1   deraadt  */
    520       1.1   deraadt static int
    521      1.50       gwr zshard(arg)
    522      1.50       gwr 	void *arg;
    523       1.1   deraadt {
    524  1.69.8.1    bouyer 	struct zsc_softc *zsc;
    525  1.69.8.1    bouyer 	int unit, rr3, rval, softreq;
    526       1.1   deraadt 
    527      1.50       gwr 	rval = softreq = 0;
    528      1.50       gwr 	for (unit = 0; unit < zs_cd.cd_ndevs; unit++) {
    529  1.69.8.1    bouyer 		struct zs_chanstate *cs;
    530  1.69.8.1    bouyer 
    531      1.50       gwr 		zsc = zs_cd.cd_devs[unit];
    532      1.50       gwr 		if (zsc == NULL)
    533      1.50       gwr 			continue;
    534      1.50       gwr 		rr3 = zsc_intr_hard(zsc);
    535      1.50       gwr 		/* Count up the interrupts. */
    536      1.50       gwr 		if (rr3) {
    537      1.50       gwr 			rval |= rr3;
    538      1.50       gwr 			zsc->zsc_intrcnt.ev_count++;
    539      1.50       gwr 		}
    540  1.69.8.1    bouyer 		if ((cs = zsc->zsc_cs[0]) != NULL)
    541  1.69.8.1    bouyer 			softreq |= cs->cs_softreq;
    542  1.69.8.1    bouyer 		if ((cs = zsc->zsc_cs[1]) != NULL)
    543  1.69.8.1    bouyer 			softreq |= cs->cs_softreq;
    544      1.50       gwr 	}
    545       1.1   deraadt 
    546      1.50       gwr 	/* We are at splzs here, so no need to lock. */
    547      1.50       gwr 	if (softreq && (zssoftpending == 0)) {
    548      1.50       gwr 		zssoftpending = IE_ZSSOFT;
    549      1.50       gwr #if defined(SUN4M)
    550      1.50       gwr 		if (CPU_ISSUN4M)
    551      1.50       gwr 			raise(0, PIL_TTY);
    552      1.50       gwr 		else
    553      1.50       gwr #endif
    554      1.56       mrg 			ienab_bis(IE_ZSSOFT);
    555      1.50       gwr 	}
    556      1.50       gwr 	return (rval);
    557       1.1   deraadt }
    558       1.1   deraadt 
    559       1.1   deraadt /*
    560      1.50       gwr  * Similar scheme as for zshard (look at all of them)
    561       1.1   deraadt  */
    562      1.50       gwr static int
    563      1.50       gwr zssoft(arg)
    564      1.50       gwr 	void *arg;
    565       1.1   deraadt {
    566  1.69.8.1    bouyer 	struct zsc_softc *zsc;
    567  1.69.8.1    bouyer 	int s, unit;
    568       1.1   deraadt 
    569      1.50       gwr 	/* This is not the only ISR on this IPL. */
    570      1.50       gwr 	if (zssoftpending == 0)
    571      1.50       gwr 		return (0);
    572       1.1   deraadt 
    573      1.50       gwr 	/*
    574      1.50       gwr 	 * The soft intr. bit will be set by zshard only if
    575      1.50       gwr 	 * the variable zssoftpending is zero.  The order of
    576      1.50       gwr 	 * these next two statements prevents our clearing
    577      1.50       gwr 	 * the soft intr bit just after zshard has set it.
    578      1.50       gwr 	 */
    579      1.50       gwr 	/* ienab_bic(IE_ZSSOFT); */
    580      1.50       gwr 	zssoftpending = 0;
    581       1.1   deraadt 
    582      1.50       gwr 	/* Make sure we call the tty layer at spltty. */
    583       1.1   deraadt 	s = spltty();
    584      1.50       gwr 	for (unit = 0; unit < zs_cd.cd_ndevs; unit++) {
    585      1.50       gwr 		zsc = zs_cd.cd_devs[unit];
    586      1.50       gwr 		if (zsc == NULL)
    587      1.50       gwr 			continue;
    588      1.56       mrg 		(void)zsc_intr_soft(zsc);
    589       1.1   deraadt 	}
    590       1.1   deraadt 	splx(s);
    591      1.50       gwr 	return (1);
    592       1.1   deraadt }
    593       1.1   deraadt 
    594      1.50       gwr 
    595       1.1   deraadt /*
    596      1.50       gwr  * Compute the current baud rate given a ZS channel.
    597       1.1   deraadt  */
    598      1.50       gwr static int
    599      1.50       gwr zs_get_speed(cs)
    600      1.50       gwr 	struct zs_chanstate *cs;
    601      1.50       gwr {
    602      1.50       gwr 	int tconst;
    603      1.50       gwr 
    604      1.50       gwr 	tconst = zs_read_reg(cs, 12);
    605      1.50       gwr 	tconst |= zs_read_reg(cs, 13) << 8;
    606      1.50       gwr 	return (TCONST_TO_BPS(cs->cs_brg_clk, tconst));
    607       1.1   deraadt }
    608       1.1   deraadt 
    609       1.1   deraadt /*
    610      1.50       gwr  * MD functions for setting the baud rate and control modes.
    611       1.1   deraadt  */
    612       1.1   deraadt int
    613      1.50       gwr zs_set_speed(cs, bps)
    614      1.50       gwr 	struct zs_chanstate *cs;
    615      1.50       gwr 	int bps;	/* bits per second */
    616       1.1   deraadt {
    617      1.50       gwr 	int tconst, real_bps;
    618      1.50       gwr 
    619      1.50       gwr 	if (bps == 0)
    620      1.50       gwr 		return (0);
    621       1.1   deraadt 
    622      1.50       gwr #ifdef	DIAGNOSTIC
    623      1.50       gwr 	if (cs->cs_brg_clk == 0)
    624      1.50       gwr 		panic("zs_set_speed");
    625      1.50       gwr #endif
    626      1.50       gwr 
    627      1.50       gwr 	tconst = BPS_TO_TCONST(cs->cs_brg_clk, bps);
    628      1.50       gwr 	if (tconst < 0)
    629      1.50       gwr 		return (EINVAL);
    630      1.28        pk 
    631      1.50       gwr 	/* Convert back to make sure we can do it. */
    632      1.50       gwr 	real_bps = TCONST_TO_BPS(cs->cs_brg_clk, tconst);
    633       1.1   deraadt 
    634      1.50       gwr 	/* XXX - Allow some tolerance here? */
    635      1.50       gwr 	if (real_bps != bps)
    636      1.50       gwr 		return (EINVAL);
    637      1.28        pk 
    638      1.50       gwr 	cs->cs_preg[12] = tconst;
    639      1.50       gwr 	cs->cs_preg[13] = tconst >> 8;
    640       1.1   deraadt 
    641      1.50       gwr 	/* Caller will stuff the pending registers. */
    642      1.50       gwr 	return (0);
    643      1.28        pk }
    644      1.28        pk 
    645      1.50       gwr int
    646      1.50       gwr zs_set_modes(cs, cflag)
    647      1.50       gwr 	struct zs_chanstate *cs;
    648      1.50       gwr 	int cflag;	/* bits per second */
    649      1.28        pk {
    650      1.50       gwr 	int s;
    651      1.28        pk 
    652      1.50       gwr 	/*
    653      1.50       gwr 	 * Output hardware flow control on the chip is horrendous:
    654      1.50       gwr 	 * if carrier detect drops, the receiver is disabled, and if
    655      1.50       gwr 	 * CTS drops, the transmitter is stoped IN MID CHARACTER!
    656      1.50       gwr 	 * Therefore, NEVER set the HFC bit, and instead use the
    657      1.50       gwr 	 * status interrupt to detect CTS changes.
    658      1.50       gwr 	 */
    659      1.50       gwr 	s = splzs();
    660      1.69  wrstuden 	cs->cs_rr0_pps = 0;
    661      1.69  wrstuden 	if ((cflag & (CLOCAL | MDMBUF)) != 0) {
    662      1.50       gwr 		cs->cs_rr0_dcd = 0;
    663      1.69  wrstuden 		if ((cflag & MDMBUF) == 0)
    664      1.69  wrstuden 			cs->cs_rr0_pps = ZSRR0_DCD;
    665      1.69  wrstuden 	} else
    666      1.50       gwr 		cs->cs_rr0_dcd = ZSRR0_DCD;
    667      1.52   mycroft 	if ((cflag & CRTSCTS) != 0) {
    668      1.50       gwr 		cs->cs_wr5_dtr = ZSWR5_DTR;
    669      1.50       gwr 		cs->cs_wr5_rts = ZSWR5_RTS;
    670      1.53   mycroft 		cs->cs_rr0_cts = ZSRR0_CTS;
    671      1.53   mycroft 	} else if ((cflag & CDTRCTS) != 0) {
    672      1.53   mycroft 		cs->cs_wr5_dtr = 0;
    673      1.53   mycroft 		cs->cs_wr5_rts = ZSWR5_DTR;
    674      1.50       gwr 		cs->cs_rr0_cts = ZSRR0_CTS;
    675      1.52   mycroft 	} else if ((cflag & MDMBUF) != 0) {
    676      1.52   mycroft 		cs->cs_wr5_dtr = 0;
    677      1.52   mycroft 		cs->cs_wr5_rts = ZSWR5_DTR;
    678      1.52   mycroft 		cs->cs_rr0_cts = ZSRR0_DCD;
    679      1.50       gwr 	} else {
    680      1.50       gwr 		cs->cs_wr5_dtr = ZSWR5_DTR | ZSWR5_RTS;
    681      1.50       gwr 		cs->cs_wr5_rts = 0;
    682      1.50       gwr 		cs->cs_rr0_cts = 0;
    683      1.50       gwr 	}
    684      1.50       gwr 	splx(s);
    685      1.28        pk 
    686      1.50       gwr 	/* Caller will stuff the pending registers. */
    687      1.50       gwr 	return (0);
    688      1.38       mrg }
    689      1.28        pk 
    690       1.1   deraadt 
    691       1.1   deraadt /*
    692      1.50       gwr  * Read or write the chip with suitable delays.
    693       1.1   deraadt  */
    694      1.50       gwr 
    695      1.50       gwr u_char
    696      1.50       gwr zs_read_reg(cs, reg)
    697      1.50       gwr 	struct zs_chanstate *cs;
    698      1.50       gwr 	u_char reg;
    699       1.1   deraadt {
    700      1.50       gwr 	u_char val;
    701      1.14   deraadt 
    702      1.50       gwr 	*cs->cs_reg_csr = reg;
    703      1.50       gwr 	ZS_DELAY();
    704      1.50       gwr 	val = *cs->cs_reg_csr;
    705      1.50       gwr 	ZS_DELAY();
    706      1.57        pk 	return (val);
    707       1.1   deraadt }
    708       1.1   deraadt 
    709      1.50       gwr void
    710      1.50       gwr zs_write_reg(cs, reg, val)
    711      1.50       gwr 	struct zs_chanstate *cs;
    712      1.50       gwr 	u_char reg, val;
    713       1.1   deraadt {
    714      1.50       gwr 	*cs->cs_reg_csr = reg;
    715      1.14   deraadt 	ZS_DELAY();
    716      1.50       gwr 	*cs->cs_reg_csr = val;
    717      1.14   deraadt 	ZS_DELAY();
    718      1.50       gwr }
    719       1.1   deraadt 
    720      1.56       mrg u_char
    721      1.56       mrg zs_read_csr(cs)
    722      1.50       gwr 	struct zs_chanstate *cs;
    723      1.50       gwr {
    724  1.69.8.1    bouyer 	u_char val;
    725       1.1   deraadt 
    726      1.50       gwr 	val = *cs->cs_reg_csr;
    727      1.14   deraadt 	ZS_DELAY();
    728      1.57        pk 	return (val);
    729       1.1   deraadt }
    730       1.1   deraadt 
    731  1.69.8.1    bouyer void
    732  1.69.8.1    bouyer zs_write_csr(cs, val)
    733      1.50       gwr 	struct zs_chanstate *cs;
    734      1.50       gwr 	u_char val;
    735      1.50       gwr {
    736      1.50       gwr 	*cs->cs_reg_csr = val;
    737      1.14   deraadt 	ZS_DELAY();
    738       1.1   deraadt }
    739       1.1   deraadt 
    740  1.69.8.1    bouyer u_char
    741  1.69.8.1    bouyer zs_read_data(cs)
    742      1.50       gwr 	struct zs_chanstate *cs;
    743       1.1   deraadt {
    744  1.69.8.1    bouyer 	u_char val;
    745       1.1   deraadt 
    746      1.50       gwr 	val = *cs->cs_reg_data;
    747      1.29        pk 	ZS_DELAY();
    748      1.57        pk 	return (val);
    749      1.50       gwr }
    750      1.50       gwr 
    751      1.50       gwr void  zs_write_data(cs, val)
    752      1.50       gwr 	struct zs_chanstate *cs;
    753      1.50       gwr 	u_char val;
    754      1.50       gwr {
    755      1.50       gwr 	*cs->cs_reg_data = val;
    756      1.14   deraadt 	ZS_DELAY();
    757       1.1   deraadt }
    758       1.1   deraadt 
    759      1.50       gwr /****************************************************************
    760      1.50       gwr  * Console support functions (Sun specific!)
    761      1.50       gwr  * Note: this code is allowed to know about the layout of
    762      1.50       gwr  * the chip registers, and uses that to keep things simple.
    763      1.50       gwr  * XXX - I think I like the mvme167 code better. -gwr
    764      1.50       gwr  ****************************************************************/
    765      1.50       gwr 
    766      1.50       gwr /*
    767      1.50       gwr  * Handle user request to enter kernel debugger.
    768      1.50       gwr  */
    769      1.34  christos void
    770      1.50       gwr zs_abort(cs)
    771      1.50       gwr 	struct zs_chanstate *cs;
    772       1.1   deraadt {
    773  1.69.8.1    bouyer 	struct zschan *zc = zs_conschan_get;
    774      1.50       gwr 	int rr0;
    775      1.50       gwr 
    776      1.50       gwr 	/* Wait for end of break to avoid PROM abort. */
    777      1.50       gwr 	/* XXX - Limit the wait? */
    778      1.50       gwr 	do {
    779      1.50       gwr 		rr0 = zc->zc_csr;
    780      1.50       gwr 		ZS_DELAY();
    781      1.50       gwr 	} while (rr0 & ZSRR0_BREAK);
    782       1.1   deraadt 
    783      1.49        pk #if defined(KGDB)
    784      1.50       gwr 	zskgdb(cs);
    785      1.49        pk #elif defined(DDB)
    786       1.5        pk 	Debugger();
    787       1.5        pk #else
    788      1.44  christos 	printf("stopping on keyboard abort\n");
    789       1.1   deraadt 	callrom();
    790       1.5        pk #endif
    791       1.1   deraadt }
    792       1.1   deraadt 
    793  1.69.8.1    bouyer static int  zs_getc __P((void *arg));
    794  1.69.8.1    bouyer static void zs_putc __P((void *arg, int c));
    795  1.69.8.1    bouyer 
    796       1.1   deraadt /*
    797      1.50       gwr  * Polled input char.
    798       1.1   deraadt  */
    799      1.50       gwr int
    800      1.50       gwr zs_getc(arg)
    801      1.50       gwr 	void *arg;
    802       1.1   deraadt {
    803  1.69.8.1    bouyer 	struct zschan *zc = arg;
    804  1.69.8.1    bouyer 	int s, c, rr0;
    805       1.1   deraadt 
    806      1.50       gwr 	s = splhigh();
    807      1.50       gwr 	/* Wait for a character to arrive. */
    808      1.50       gwr 	do {
    809      1.50       gwr 		rr0 = zc->zc_csr;
    810      1.50       gwr 		ZS_DELAY();
    811      1.50       gwr 	} while ((rr0 & ZSRR0_RX_READY) == 0);
    812       1.1   deraadt 
    813      1.50       gwr 	c = zc->zc_data;
    814      1.50       gwr 	ZS_DELAY();
    815      1.50       gwr 	splx(s);
    816       1.1   deraadt 
    817      1.50       gwr 	/*
    818      1.50       gwr 	 * This is used by the kd driver to read scan codes,
    819      1.50       gwr 	 * so don't translate '\r' ==> '\n' here...
    820      1.50       gwr 	 */
    821      1.50       gwr 	return (c);
    822       1.1   deraadt }
    823       1.1   deraadt 
    824       1.1   deraadt /*
    825      1.50       gwr  * Polled output char.
    826       1.1   deraadt  */
    827      1.50       gwr void
    828      1.50       gwr zs_putc(arg, c)
    829      1.16   deraadt 	void *arg;
    830      1.50       gwr 	int c;
    831       1.1   deraadt {
    832  1.69.8.1    bouyer 	struct zschan *zc = arg;
    833  1.69.8.1    bouyer 	int s, rr0;
    834       1.1   deraadt 
    835      1.50       gwr 	s = splhigh();
    836      1.59   mycroft 
    837      1.50       gwr 	/* Wait for transmitter to become ready. */
    838      1.50       gwr 	do {
    839      1.50       gwr 		rr0 = zc->zc_csr;
    840      1.50       gwr 		ZS_DELAY();
    841      1.50       gwr 	} while ((rr0 & ZSRR0_TX_READY) == 0);
    842      1.21   deraadt 
    843      1.60       chs 	/*
    844      1.60       chs 	 * Send the next character.
    845      1.60       chs 	 * Now you'd think that this could be followed by a ZS_DELAY()
    846      1.60       chs 	 * just like all the other chip accesses, but it turns out that
    847      1.60       chs 	 * the `transmit-ready' interrupt isn't de-asserted until
    848      1.60       chs 	 * some period of time after the register write completes
    849      1.60       chs 	 * (more than a couple instructions).  So to avoid stray
    850      1.60       chs 	 * interrupts we put in the 2us delay regardless of cpu model.
    851      1.60       chs 	 */
    852      1.50       gwr 	zc->zc_data = c;
    853      1.60       chs 	delay(2);
    854      1.59   mycroft 
    855      1.50       gwr 	splx(s);
    856      1.50       gwr }
    857      1.21   deraadt 
    858      1.50       gwr /*****************************************************************/
    859       1.1   deraadt /*
    860      1.50       gwr  * Polled console input putchar.
    861       1.1   deraadt  */
    862  1.69.8.1    bouyer int
    863      1.50       gwr zscngetc(dev)
    864      1.50       gwr 	dev_t dev;
    865      1.50       gwr {
    866  1.69.8.1    bouyer 	return (zs_getc(zs_conschan_get));
    867       1.1   deraadt }
    868       1.1   deraadt 
    869       1.1   deraadt /*
    870      1.50       gwr  * Polled console output putchar.
    871       1.1   deraadt  */
    872  1.69.8.1    bouyer void
    873      1.50       gwr zscnputc(dev, c)
    874      1.50       gwr 	dev_t dev;
    875      1.50       gwr 	int c;
    876      1.50       gwr {
    877  1.69.8.1    bouyer 	zs_putc(zs_conschan_put, c);
    878      1.50       gwr }
    879       1.1   deraadt 
    880      1.50       gwr void
    881  1.69.8.1    bouyer zscnpollc(dev, on)
    882      1.50       gwr 	dev_t dev;
    883  1.69.8.1    bouyer 	int on;
    884       1.1   deraadt {
    885  1.69.8.1    bouyer 	/* No action needed */
    886       1.1   deraadt }
    887       1.1   deraadt 
    888      1.67        pk int
    889  1.69.8.1    bouyer zs_console_flags(promunit, node, channel)
    890  1.69.8.1    bouyer 	int promunit;
    891      1.67        pk 	int node;
    892  1.69.8.1    bouyer 	int channel;
    893       1.1   deraadt {
    894  1.69.8.1    bouyer 	int cookie, flags = 0;
    895      1.65        pk 
    896      1.65        pk 	switch (prom_version()) {
    897      1.65        pk 	case PROM_OLDMON:
    898      1.65        pk 	case PROM_OBP_V0:
    899  1.69.8.1    bouyer 		/*
    900  1.69.8.1    bouyer 		 * Use `promunit' and `channel' to derive the PROM
    901  1.69.8.1    bouyer 		 * stdio handles that correspond to this device.
    902  1.69.8.1    bouyer 		 */
    903  1.69.8.1    bouyer 		if (promunit == 0)
    904  1.69.8.1    bouyer 			cookie = PROMDEV_TTYA + channel;
    905  1.69.8.1    bouyer 		else if (promunit == 1 && channel == 0)
    906  1.69.8.1    bouyer 			cookie = PROMDEV_KBD;
    907  1.69.8.1    bouyer 		else
    908  1.69.8.1    bouyer 			cookie = -1;
    909  1.69.8.1    bouyer 
    910  1.69.8.1    bouyer 		if (cookie == prom_stdin())
    911  1.69.8.1    bouyer 			flags |= ZS_HWFLAG_CONSOLE_INPUT;
    912  1.69.8.1    bouyer 
    913  1.69.8.1    bouyer 		/*
    914  1.69.8.1    bouyer 		 * Prevent the keyboard from matching the output device
    915  1.69.8.1    bouyer 		 * (note that PROMDEV_KBD == PROMDEV_SCREEN == 0!).
    916  1.69.8.1    bouyer 		 */
    917  1.69.8.1    bouyer 		if (cookie != PROMDEV_KBD && cookie == prom_stdout())
    918  1.69.8.1    bouyer 			flags |= ZS_HWFLAG_CONSOLE_OUTPUT;
    919  1.69.8.1    bouyer 
    920      1.65        pk 		break;
    921  1.69.8.1    bouyer 
    922      1.65        pk 	case PROM_OBP_V2:
    923      1.65        pk 	case PROM_OBP_V3:
    924      1.65        pk 	case PROM_OPENFIRM:
    925  1.69.8.1    bouyer 
    926      1.50       gwr 		/*
    927  1.69.8.1    bouyer 		 * Match the nodes and device arguments prepared by
    928  1.69.8.1    bouyer 		 * consinit() against our device node and channel.
    929  1.69.8.1    bouyer 		 * (The device argument is the part of the OBP path
    930  1.69.8.1    bouyer 		 * following the colon, as in `/obio/zs@0,100000:a')
    931      1.50       gwr 		 */
    932      1.66        pk 
    933  1.69.8.1    bouyer 		/* Default to channel 0 if there are no explicit prom args */
    934  1.69.8.1    bouyer 		cookie = 0;
    935      1.67        pk 
    936  1.69.8.1    bouyer 		if (node == prom_stdin_node) {
    937  1.69.8.1    bouyer 			if (prom_stdin_args[0] != '\0')
    938  1.69.8.1    bouyer 				/* Translate (a,b) -> (0,1) */
    939  1.69.8.1    bouyer 				cookie = prom_stdin_args[0] - 'a';
    940      1.67        pk 
    941  1.69.8.1    bouyer 			if (channel == cookie)
    942  1.69.8.1    bouyer 				flags |= ZS_HWFLAG_CONSOLE_INPUT;
    943      1.50       gwr 		}
    944  1.69.8.1    bouyer 
    945  1.69.8.1    bouyer 		if (node == prom_stdout_node) {
    946  1.69.8.1    bouyer 			if (prom_stdout_args[0] != '\0')
    947  1.69.8.1    bouyer 				/* Translate (a,b) -> (0,1) */
    948  1.69.8.1    bouyer 				cookie = prom_stdout_args[0] - 'a';
    949  1.69.8.1    bouyer 
    950  1.69.8.1    bouyer 			if (channel == cookie)
    951  1.69.8.1    bouyer 				flags |= ZS_HWFLAG_CONSOLE_OUTPUT;
    952      1.50       gwr 		}
    953  1.69.8.1    bouyer 
    954      1.65        pk 		break;
    955      1.68        pk 
    956      1.68        pk 	default:
    957  1.69.8.1    bouyer 		break;
    958      1.50       gwr 	}
    959      1.50       gwr 
    960  1.69.8.1    bouyer 	return (flags);
    961  1.69.8.1    bouyer }
    962      1.50       gwr 
    963  1.69.8.1    bouyer /*
    964  1.69.8.1    bouyer  * Power management hooks for zsopen() and zsclose().
    965  1.69.8.1    bouyer  * We use them to power on/off the ports, if necessary.
    966  1.69.8.1    bouyer  */
    967  1.69.8.1    bouyer int
    968  1.69.8.1    bouyer zs_enable(cs)
    969  1.69.8.1    bouyer 	struct zs_chanstate *cs;
    970  1.69.8.1    bouyer {
    971  1.69.8.1    bouyer 	auxiotwoserialendis (ZS_ENABLE);
    972  1.69.8.1    bouyer 	cs->enabled = 1;
    973  1.69.8.1    bouyer 	return(0);
    974  1.69.8.1    bouyer }
    975       1.1   deraadt 
    976  1.69.8.1    bouyer void
    977  1.69.8.1    bouyer zs_disable(cs)
    978  1.69.8.1    bouyer 	struct zs_chanstate *cs;
    979  1.69.8.1    bouyer {
    980  1.69.8.1    bouyer 	auxiotwoserialendis (ZS_DISABLE);
    981  1.69.8.1    bouyer 	cs->enabled = 0;
    982       1.1   deraadt }
    983