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