xref: /netbsd-src/sys/arch/hp300/stand/common/apci.c (revision 6d7bfad47a75cb30de24f135a00cf0d394eddeec)
1 /*	$NetBSD: apci.c,v 1.14 2023/04/21 22:44:27 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  *
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
apciprobe(struct consdev * cp)85 apciprobe(struct consdev *cp)
86 {
87 	volatile uint8_t *frodoregs;
88 
89 	cp->cn_pri = CN_DEAD;
90 
91 	/*
92 	 * Only a 425e can have an APCI console.  On all other 4xx models,
93 	 * the "first" serial port is mapped to the DCA at select code 9.
94 	 */
95 	if (machineid != HP_425 || mmuid != MMUID_425_E)
96 		return;
97 
98 	/*
99 	 * Check the service switch. On the 425e, this is a physical
100 	 * switch, unlike other frodo-based machines, so we can use it
101 	 * as a serial vs internal video selector, since the PROM can not
102 	 * be configured for serial console.
103 	 */
104 	frodoregs = (volatile u_int8_t *)IIOV(INTIOBASE + FRODO_BASE);
105 	if (badaddr((char *)frodoregs) == 0 &&
106 	    (frodoregs[FRODO_IISR] & FRODO_IISR_SERVICE) == 0)
107 		cp->cn_pri = CN_REMOTE;
108 	else
109 		cp->cn_pri = CN_NORMAL;
110 
111 #ifdef FORCEAPCICONSOLE
112 	cp->cn_pri = CN_REMOTE;
113 #endif
114 	curcons_scode = -2;
115 
116 	apcicnaddr =
117 	    (void *)IIOV(INTIOBASE + FRODO_BASE + FRODO_APCI_OFFSET(1));
118 }
119 
120 void
apciinit(struct consdev * cp)121 apciinit(struct consdev *cp)
122 {
123 	struct apciregs *apci = (struct apciregs *)apcicnaddr;
124 
125 	/*
126 	 * The only system on which this will happen is a 425e,
127 	 * which does not currently have a framebuffer console
128 	 * driver.  We use the ROM's output method to let the
129 	 * operator know we're switching to the APCI.
130 	 */
131 	userom = 1;
132 	printf("Switching to APCI console.\n");
133 	userom = 0;
134 
135 	apci->ap_cfcr = CFCR_DLAB;
136 	apci->ap_data = APCIBRD(9600) & 0xff;
137 	apci->ap_ier  = (APCIBRD(9600) >> 8) & 0xff;
138 	apci->ap_cfcr = CFCR_8BITS;
139 	apci->ap_fifo =
140 	    FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_1;
141 	apci->ap_mcr = MCR_DTR | MCR_RTS;
142 }
143 
144 #ifndef SMALL
145 int
apcigetchar(dev_t dev)146 apcigetchar(dev_t dev)
147 {
148 	struct apciregs *apci = apcicnaddr;
149 	short stat;
150 	int c;
151 
152 	if (((stat = apci->ap_lsr) & LSR_RXRDY) == 0)
153 		return 0;
154 	c = apci->ap_data;
155 	return c;
156 }
157 #else
158 int
apcigetchar(dev_t dev)159 apcigetchar(dev_t dev)
160 {
161 
162 	return 0;
163 }
164 #endif
165 
166 void
apciputchar(dev_t dev,int c)167 apciputchar(dev_t dev, int c)
168 {
169 	struct apciregs *apci = apcicnaddr;
170 	int timo;
171 	short stat;
172 
173 	/* wait a reasonable time for the transmitter to come ready */
174 	timo = 50000;
175 	while (((stat = apci->ap_lsr) & LSR_TXRDY) == 0 && --timo)
176 		;
177 	apci->ap_data = c;
178 	/* wait for this transmission to complete */
179 	timo = 1000000;
180 	while (((stat = apci->ap_lsr) & LSR_TXRDY) == 0 && --timo)
181 		;
182 }
183 #endif
184