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