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