Home | History | Annotate | Line # | Download | only in common
apci.c revision 1.5
      1 /*	$NetBSD: apci.c,v 1.5 2003/11/08 12:02:33 tsutsui Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 1997, 1999 The NetBSD Foundation, Inc.
      5  * All rights reserved.
      6  *
      7  * This code is derived from software contributed to The NetBSD Foundation
      8  * by Jason R. Thorpe.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     13  * 1. Redistributions of source code must retain the above copyright
     14  *    notice, this list of conditions and the following disclaimer.
     15  * 2. Redistributions in binary form must reproduce the above copyright
     16  *    notice, this list of conditions and the following disclaimer in the
     17  *    documentation and/or other materials provided with the distribution.
     18  * 3. All advertising materials mentioning features or use of this software
     19  *    must display the following acknowledgement:
     20  *	This product includes software developed by the NetBSD
     21  *	Foundation, Inc. and its contributors.
     22  * 4. Neither the name of The NetBSD Foundation nor the names of its
     23  *    contributors may be used to endorse or promote products derived
     24  *    from this software without specific prior written permission.
     25  *
     26  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     27  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     28  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     29  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     30  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     31  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     32  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     33  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     34  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     35  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     36  * POSSIBILITY OF SUCH DAMAGE.
     37  */
     38 
     39 /*
     40  * Copyright (c) 1990, 1993
     41  *	The Regents of the University of California.  All rights reserved.
     42  *
     43  * This code is derived from software contributed to Berkeley by
     44  * the Systems Programming Group of the University of Utah Computer
     45  * Science Department.
     46  *
     47  * Redistribution and use in source and binary forms, with or without
     48  * modification, are permitted provided that the following conditions
     49  * are met:
     50  * 1. Redistributions of source code must retain the above copyright
     51  *    notice, this list of conditions and the following disclaimer.
     52  * 2. Redistributions in binary form must reproduce the above copyright
     53  *    notice, this list of conditions and the following disclaimer in the
     54  *    documentation and/or other materials provided with the distribution.
     55  * 3. Neither the name of the University nor the names of its contributors
     56  *    may be used to endorse or promote products derived from this software
     57  *    without specific prior written permission.
     58  *
     59  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     60  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     61  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     62  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     63  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     64  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     65  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     66  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     67  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     68  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     69  * SUCH DAMAGE.
     70  *
     71  *	@(#)dca.c	8.1 (Berkeley) 6/10/93
     72  */
     73 /*
     74  * Copyright (c) 1988 University of Utah.
     75  *
     76  * This code is derived from software contributed to Berkeley by
     77  * the Systems Programming Group of the University of Utah Computer
     78  * Science Department.
     79  *
     80  * Redistribution and use in source and binary forms, with or without
     81  * modification, are permitted provided that the following conditions
     82  * are met:
     83  * 1. Redistributions of source code must retain the above copyright
     84  *    notice, this list of conditions and the following disclaimer.
     85  * 2. Redistributions in binary form must reproduce the above copyright
     86  *    notice, this list of conditions and the following disclaimer in the
     87  *    documentation and/or other materials provided with the distribution.
     88  * 3. All advertising materials mentioning features or use of this software
     89  *    must display the following acknowledgement:
     90  *	This product includes software developed by the University of
     91  *	California, Berkeley and its contributors.
     92  * 4. Neither the name of the University nor the names of its contributors
     93  *    may be used to endorse or promote products derived from this software
     94  *    without specific prior written permission.
     95  *
     96  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     97  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     98  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     99  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
    100  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
    101  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
    102  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
    103  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
    104  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    105  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
    106  * SUCH DAMAGE.
    107  *
    108  *	@(#)dca.c	8.1 (Berkeley) 6/10/93
    109  */
    110 
    111 #ifdef APCICONSOLE
    112 #include <sys/param.h>
    113 #include <dev/cons.h>
    114 
    115 #include <hp300/dev/frodoreg.h>		/* for APCI offsets */
    116 
    117 #include <hp300/stand/common/apcireg.h>	/* for register map */
    118 #include <hp300/stand/common/dcareg.h>	/* for register bits */
    119 #include <hp300/stand/common/consdefs.h>
    120 #include <hp300/stand/common/samachdep.h>
    121 
    122 struct apciregs *apcicnaddr = 0;
    123 
    124 void
    125 apciprobe(cp)
    126 	struct consdev *cp;
    127 {
    128 	struct apciregs *apci = apcicnaddr =
    129 	    (struct apciregs *)IIOV(FRODO_BASE + FRODO_APCI_OFFSET(1));
    130 
    131 	cp->cn_pri = CN_DEAD;
    132 
    133 	/*
    134 	 * Only a 425e can have an APCI console.  On all other 4xx models,
    135 	 * the "first" serial port is mapped to the DCA at select code 9.
    136 	 */
    137 	if (machineid != HP_425 || mmuid != MMUID_425_E)
    138 		return;
    139 
    140 #ifdef FORCEAPCICONSOLE
    141 	cp->cn_pri = CN_REMOTE;
    142 #else
    143 	cp->cn_pri = CN_NORMAL;
    144 #endif
    145 	curcons_scode = -2;
    146 }
    147 
    148 void
    149 apciinit(cp)
    150 	struct consdev *cp;
    151 {
    152 	struct apciregs *apci = (struct apciregs *)apcicnaddr;
    153 
    154 	/*
    155 	 * The only system on which this will happen is a 425e,
    156 	 * which does not currently have a framebuffer console
    157 	 * driver.  We use the ROM's output method to let the
    158 	 * operator know we're switching to the APCI.
    159 	 */
    160 	userom = 1;
    161 	printf("Switching to APCI console.\n");
    162 	userom = 0;
    163 
    164 	apci->ap_cfcr = CFCR_DLAB;
    165 	apci->ap_data = APCIBRD(9600) & 0xff;
    166 	apci->ap_ier  = (APCIBRD(9600) >> 8) & 0xff;
    167 	apci->ap_cfcr = CFCR_8BITS;
    168 	apci->ap_fifo =
    169 	    FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_1;
    170 	apci->ap_mcr = MCR_DTR | MCR_RTS;
    171 }
    172 
    173 /* ARGSUSED */
    174 #ifndef SMALL
    175 int
    176 apcigetchar(dev)
    177 	dev_t dev;
    178 {
    179 	register struct apciregs *apci = apcicnaddr;
    180 	short stat;
    181 	int c;
    182 
    183 	if (((stat = apci->ap_lsr) & LSR_RXRDY) == 0)
    184 		return (0);
    185 	c = apci->ap_data;
    186 	return (c);
    187 }
    188 #else
    189 int
    190 apcigetchar(dev)
    191 	dev_t dev;
    192 {
    193 	return (0);
    194 }
    195 #endif
    196 
    197 /* ARGSUSED */
    198 void
    199 apciputchar(dev, c)
    200 	dev_t dev;
    201 	int c;
    202 {
    203 	struct apciregs *apci = apcicnaddr;
    204 	int timo;
    205 	short stat;
    206 
    207 	/* wait a reasonable time for the transmitter to come ready */
    208 	timo = 50000;
    209 	while (((stat = apci->ap_lsr) & LSR_TXRDY) == 0 && --timo)
    210 		;
    211 	apci->ap_data = c;
    212 	/* wait for this transmission to complete */
    213 	timo = 1000000;
    214 	while (((stat = apci->ap_lsr) & LSR_TXRDY) == 0 && --timo)
    215 		;
    216 }
    217 #endif
    218