Home | History | Annotate | Line # | Download | only in common
dca.c revision 1.2
      1 /*	$NetBSD: dca.c,v 1.2 2003/08/07 16:27:40 agc Exp $	*/
      2 
      3 /*
      4  * Copyright (c) 1990, 1993
      5  *	The Regents of the University of California.  All rights reserved.
      6  *
      7  * This code is derived from software contributed to Berkeley by
      8  * the Systems Programming Group of the University of Utah Computer
      9  * Science Department.
     10  *
     11  * Redistribution and use in source and binary forms, with or without
     12  * modification, are permitted provided that the following conditions
     13  * are met:
     14  * 1. Redistributions of source code must retain the above copyright
     15  *    notice, this list of conditions and the following disclaimer.
     16  * 2. Redistributions in binary form must reproduce the above copyright
     17  *    notice, this list of conditions and the following disclaimer in the
     18  *    documentation and/or other materials provided with the distribution.
     19  * 3. Neither the name of the University nor the names of its contributors
     20  *    may be used to endorse or promote products derived from this software
     21  *    without specific prior written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  * SUCH DAMAGE.
     34  *
     35  *	@(#)dca.c	8.1 (Berkeley) 6/10/93
     36  */
     37 /*
     38  * Copyright (c) 1988 University of Utah.
     39  *
     40  * This code is derived from software contributed to Berkeley by
     41  * the Systems Programming Group of the University of Utah Computer
     42  * Science Department.
     43  *
     44  * Redistribution and use in source and binary forms, with or without
     45  * modification, are permitted provided that the following conditions
     46  * are met:
     47  * 1. Redistributions of source code must retain the above copyright
     48  *    notice, this list of conditions and the following disclaimer.
     49  * 2. Redistributions in binary form must reproduce the above copyright
     50  *    notice, this list of conditions and the following disclaimer in the
     51  *    documentation and/or other materials provided with the distribution.
     52  * 3. All advertising materials mentioning features or use of this software
     53  *    must display the following acknowledgement:
     54  *	This product includes software developed by the University of
     55  *	California, Berkeley and its contributors.
     56  * 4. Neither the name of the University nor the names of its contributors
     57  *    may be used to endorse or promote products derived from this software
     58  *    without specific prior written permission.
     59  *
     60  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     61  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     62  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     63  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     64  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     65  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     66  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     67  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     68  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     69  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     70  * SUCH DAMAGE.
     71  *
     72  *	@(#)dca.c	8.1 (Berkeley) 6/10/93
     73  */
     74 
     75 #ifdef DCACONSOLE
     76 #include <sys/param.h>
     77 #include <dev/cons.h>
     78 
     79 #include <hp300/dev/dcareg.h>
     80 
     81 #include <hp300/stand/common/consdefs.h>
     82 #include <hp300/stand/common/samachdep.h>
     83 
     84 /* If not using 4.4 devs */
     85 #ifndef dca_reset
     86 #define dca_id dca_irid
     87 #define dca_reset dca_id
     88 #endif
     89 
     90 struct dcadevice *dcacnaddr = 0;
     91 
     92 #define DCACONSCODE	9	/* XXX */
     93 
     94 void
     95 dcaprobe(cp)
     96 	struct consdev *cp;
     97 {
     98 	register struct dcadevice *dca;
     99 
    100 	dcacnaddr = (struct dcadevice *) sctoaddr(DCACONSCODE);
    101 	if (badaddr((char *)dcacnaddr)) {
    102 		cp->cn_pri = CN_DEAD;
    103 		return;
    104 	}
    105 #ifdef FORCEDCACONSOLE
    106 	cp->cn_pri = CN_REMOTE;
    107 #else
    108 	dca = dcacnaddr;
    109 	switch (dca->dca_id) {
    110 	case DCAID0:
    111 	case DCAID1:
    112 		cp->cn_pri = CN_NORMAL;
    113 		break;
    114 	case DCAREMID0:
    115 	case DCAREMID1:
    116 		cp->cn_pri = CN_REMOTE;
    117 		break;
    118 	default:
    119 		cp->cn_pri = CN_DEAD;
    120 		break;
    121 	}
    122 
    123 #endif
    124 	curcons_scode = DCACONSCODE;
    125 }
    126 
    127 void
    128 dcainit(cp)
    129 	struct consdev *cp;
    130 {
    131 	register struct dcadevice *dca = dcacnaddr;
    132 
    133 	dca->dca_reset = 0xFF;
    134 	DELAY(100);
    135 	dca->dca_ic = 0;
    136 	dca->dca_cfcr = CFCR_DLAB;
    137 	dca->dca_data = DCABRD(9600) & 0xFF;
    138 	dca->dca_ier = DCABRD(9600) >> 8;
    139 	dca->dca_cfcr = CFCR_8BITS;
    140 	dca->dca_fifo =
    141 	    FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_1;
    142 	dca->dca_mcr = MCR_DTR | MCR_RTS;
    143 }
    144 
    145 /* ARGSUSED */
    146 #ifndef SMALL
    147 int
    148 dcagetchar(dev)
    149 	dev_t dev;
    150 {
    151 	register struct dcadevice *dca = dcacnaddr;
    152 	short stat;
    153 	int c;
    154 
    155 	if (((stat = dca->dca_lsr) & LSR_RXRDY) == 0)
    156 		return(0);
    157 	c = dca->dca_data;
    158 	return(c);
    159 }
    160 #else
    161 int
    162 dcagetchar(dev)
    163 	dev_t dev;
    164 {
    165 	return(0);
    166 }
    167 #endif
    168 
    169 /* ARGSUSED */
    170 void
    171 dcaputchar(dev, c)
    172 	dev_t dev;
    173 	register int c;
    174 {
    175 	register struct dcadevice *dca = dcacnaddr;
    176 	register int timo;
    177 	short stat;
    178 
    179 	/* wait a reasonable time for the transmitter to come ready */
    180 	timo = 50000;
    181 	while (((stat = dca->dca_lsr) & LSR_TXRDY) == 0 && --timo)
    182 		;
    183 	dca->dca_data = c;
    184 	/* wait for this transmission to complete */
    185 	timo = 1000000;
    186 	while (((stat = dca->dca_lsr) & LSR_TXRDY) == 0 && --timo)
    187 		;
    188 }
    189 #endif
    190