Home | History | Annotate | Line # | Download | only in common
apci.c revision 1.6
      1 /*	$NetBSD: apci.c,v 1.6 2003/11/14 16:52:40 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 <lib/libsa/stand.h>
    116 
    117 #include <hp300/dev/frodoreg.h>		/* for APCI offsets */
    118 
    119 #include <hp300/stand/common/apcireg.h>	/* for register map */
    120 #include <hp300/stand/common/dcareg.h>	/* for register bits */
    121 #include <hp300/stand/common/consdefs.h>
    122 #include <hp300/stand/common/samachdep.h>
    123 
    124 struct apciregs *apcicnaddr = 0;
    125 
    126 void
    127 apciprobe(cp)
    128 	struct consdev *cp;
    129 {
    130 
    131 	apcicnaddr = (void *)IIOV(FRODO_BASE + FRODO_APCI_OFFSET(1));
    132 
    133 	cp->cn_pri = CN_DEAD;
    134 
    135 	/*
    136 	 * Only a 425e can have an APCI console.  On all other 4xx models,
    137 	 * the "first" serial port is mapped to the DCA at select code 9.
    138 	 */
    139 	if (machineid != HP_425 || mmuid != MMUID_425_E)
    140 		return;
    141 
    142 #ifdef FORCEAPCICONSOLE
    143 	cp->cn_pri = CN_REMOTE;
    144 #else
    145 	cp->cn_pri = CN_NORMAL;
    146 #endif
    147 	curcons_scode = -2;
    148 }
    149 
    150 void
    151 apciinit(cp)
    152 	struct consdev *cp;
    153 {
    154 	struct apciregs *apci = (struct apciregs *)apcicnaddr;
    155 
    156 	/*
    157 	 * The only system on which this will happen is a 425e,
    158 	 * which does not currently have a framebuffer console
    159 	 * driver.  We use the ROM's output method to let the
    160 	 * operator know we're switching to the APCI.
    161 	 */
    162 	userom = 1;
    163 	printf("Switching to APCI console.\n");
    164 	userom = 0;
    165 
    166 	apci->ap_cfcr = CFCR_DLAB;
    167 	apci->ap_data = APCIBRD(9600) & 0xff;
    168 	apci->ap_ier  = (APCIBRD(9600) >> 8) & 0xff;
    169 	apci->ap_cfcr = CFCR_8BITS;
    170 	apci->ap_fifo =
    171 	    FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_1;
    172 	apci->ap_mcr = MCR_DTR | MCR_RTS;
    173 }
    174 
    175 /* ARGSUSED */
    176 #ifndef SMALL
    177 int
    178 apcigetchar(dev)
    179 	dev_t dev;
    180 {
    181 	struct apciregs *apci = apcicnaddr;
    182 	short stat;
    183 	int c;
    184 
    185 	if (((stat = apci->ap_lsr) & LSR_RXRDY) == 0)
    186 		return 0;
    187 	c = apci->ap_data;
    188 	return c;
    189 }
    190 #else
    191 int
    192 apcigetchar(dev)
    193 	dev_t dev;
    194 {
    195 
    196 	return 0;
    197 }
    198 #endif
    199 
    200 /* ARGSUSED */
    201 void
    202 apciputchar(dev, c)
    203 	dev_t dev;
    204 	int c;
    205 {
    206 	struct apciregs *apci = apcicnaddr;
    207 	int timo;
    208 	short stat;
    209 
    210 	/* wait a reasonable time for the transmitter to come ready */
    211 	timo = 50000;
    212 	while (((stat = apci->ap_lsr) & LSR_TXRDY) == 0 && --timo)
    213 		;
    214 	apci->ap_data = c;
    215 	/* wait for this transmission to complete */
    216 	timo = 1000000;
    217 	while (((stat = apci->ap_lsr) & LSR_TXRDY) == 0 && --timo)
    218 		;
    219 }
    220 #endif
    221