xref: /netbsd-src/sys/arch/hp300/stand/common/apci.c (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1 /*	$NetBSD: apci.c,v 1.9 2006/07/19 19:23:56 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 #include <hp300/dev/intioreg.h>		/* for frodo offsets */
119 
120 #include <hp300/stand/common/apcireg.h>	/* for register map */
121 #include <hp300/stand/common/dcareg.h>	/* for register bits */
122 #include <hp300/stand/common/consdefs.h>
123 #include <hp300/stand/common/samachdep.h>
124 
125 struct apciregs *apcicnaddr = 0;
126 
127 void
128 apciprobe(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(struct consdev *cp)
152 {
153 	struct apciregs *apci = (struct apciregs *)apcicnaddr;
154 
155 	/*
156 	 * The only system on which this will happen is a 425e,
157 	 * which does not currently have a framebuffer console
158 	 * driver.  We use the ROM's output method to let the
159 	 * operator know we're switching to the APCI.
160 	 */
161 	userom = 1;
162 	printf("Switching to APCI console.\n");
163 	userom = 0;
164 
165 	apci->ap_cfcr = CFCR_DLAB;
166 	apci->ap_data = APCIBRD(9600) & 0xff;
167 	apci->ap_ier  = (APCIBRD(9600) >> 8) & 0xff;
168 	apci->ap_cfcr = CFCR_8BITS;
169 	apci->ap_fifo =
170 	    FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_1;
171 	apci->ap_mcr = MCR_DTR | MCR_RTS;
172 }
173 
174 /* ARGSUSED */
175 #ifndef SMALL
176 int
177 apcigetchar(dev_t dev)
178 {
179 	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_t dev)
191 {
192 
193 	return 0;
194 }
195 #endif
196 
197 /* ARGSUSED */
198 void
199 apciputchar(dev_t dev, int c)
200 {
201 	struct apciregs *apci = apcicnaddr;
202 	int timo;
203 	short stat;
204 
205 	/* wait a reasonable time for the transmitter to come ready */
206 	timo = 50000;
207 	while (((stat = apci->ap_lsr) & LSR_TXRDY) == 0 && --timo)
208 		;
209 	apci->ap_data = c;
210 	/* wait for this transmission to complete */
211 	timo = 1000000;
212 	while (((stat = apci->ap_lsr) & LSR_TXRDY) == 0 && --timo)
213 		;
214 }
215 #endif
216