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