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