xref: /netbsd-src/sys/arch/hp300/stand/common/dcm.c (revision 8b0f9554ff8762542c4defc4f70e1eb76fb508fa)
1 /*	$NetBSD: dcm.c,v 1.7 2007/03/04 05:59:50 christos Exp $	*/
2 
3 /*
4  * Copyright (c) 1990, 1993
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * This code is derived from software contributed to Berkeley by
8  * the Systems Programming Group of the University of Utah Computer
9  * Science Department.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. Neither the name of the University nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33  * SUCH DAMAGE.
34  *
35  *	@(#)dcm.c	8.1 (Berkeley) 6/10/93
36  */
37 /*
38  * Copyright (c) 1988 University of Utah.
39  *
40  * This code is derived from software contributed to Berkeley by
41  * the Systems Programming Group of the University of Utah Computer
42  * Science Department.
43  *
44  * Redistribution and use in source and binary forms, with or without
45  * modification, are permitted provided that the following conditions
46  * are met:
47  * 1. Redistributions of source code must retain the above copyright
48  *    notice, this list of conditions and the following disclaimer.
49  * 2. Redistributions in binary form must reproduce the above copyright
50  *    notice, this list of conditions and the following disclaimer in the
51  *    documentation and/or other materials provided with the distribution.
52  * 3. All advertising materials mentioning features or use of this software
53  *    must display the following acknowledgement:
54  *	This product includes software developed by the University of
55  *	California, Berkeley and its contributors.
56  * 4. Neither the name of the University nor the names of its contributors
57  *    may be used to endorse or promote products derived from this software
58  *    without specific prior written permission.
59  *
60  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
61  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
62  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
63  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
64  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
65  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
66  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
67  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
68  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
69  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
70  * SUCH DAMAGE.
71  *
72  *	@(#)dcm.c	8.1 (Berkeley) 6/10/93
73  */
74 
75 #ifdef DCMCONSOLE
76 #include <sys/param.h>
77 #include <dev/cons.h>
78 
79 #include <hp300/dev/dcmreg.h>
80 
81 #include <hp300/stand/common/consdefs.h>
82 #include <hp300/stand/common/samachdep.h>
83 #include <hp300/stand/common/device.h>
84 
85 struct dcmdevice *dcmcnaddr = NULL;
86 
87 #define	DCMCONUNIT	1	/* XXX */
88 
89 void
90 dcmprobe(struct consdev *cp)
91 {
92 	struct hp_hw *hw;
93 	struct dcmdevice *dcm;
94 
95 	for (hw = sc_table; hw < &sc_table[MAXCTLRS]; hw++)
96 		if (HW_ISDEV(hw, D_COMMDCM) && !badaddr((void *)hw->hw_kva))
97 			break;
98 	if (!HW_ISDEV(hw, D_COMMDCM)) {
99 		cp->cn_pri = CN_DEAD;
100 		return;
101 	}
102 	dcmcnaddr = (struct dcmdevice *) hw->hw_kva;
103 
104 #ifdef FORCEDCMCONSOLE
105 	cp->cn_pri = CN_REMOTE;
106 #else
107 	dcm = dcmcnaddr;
108 	switch (dcm->dcm_rsid) {
109 	case DCMID:
110 		cp->cn_pri = CN_NORMAL;
111 		break;
112 	case DCMID|DCMCON:
113 		cp->cn_pri = CN_REMOTE;
114 		break;
115 	default:
116 		cp->cn_pri = CN_DEAD;
117 		break;
118 	}
119 
120 	curcons_scode = hw->hw_sc;
121 #endif
122 }
123 
124 void
125 dcminit(struct consdev *cp)
126 {
127 	struct dcmdevice *dcm = dcmcnaddr;
128 	int port = DCMCONUNIT;
129 
130 	dcm->dcm_ic = IC_ID;
131 	while (dcm->dcm_thead[port].ptr != dcm->dcm_ttail[port].ptr)
132 		;
133 	dcm->dcm_data[port].dcm_baud = BR_9600;
134 	dcm->dcm_data[port].dcm_conf = LC_8BITS | LC_1STOP;
135 	SEM_LOCK(dcm);
136 	dcm->dcm_cmdtab[port].dcm_data |= CT_CON;
137 	dcm->dcm_cr |= (1 << port);
138 	SEM_UNLOCK(dcm);
139 	DELAY(15000);
140 }
141 
142 /* ARGSUSED */
143 #ifndef SMALL
144 int
145 dcmgetchar(dev_t dev)
146 {
147 	struct dcmdevice *dcm = dcmcnaddr;
148 	struct dcmrfifo *fifo;
149 	struct dcmpreg *pp;
150 	unsigned int head;
151 	int c, stat, port;
152 
153 	port = DCMCONUNIT;
154 	pp = dcm_preg(dcm, port);
155 	head = pp->r_head & RX_MASK;
156 	if (head == (pp->r_tail & RX_MASK))
157 		return 0;
158 	fifo = &dcm->dcm_rfifos[3-port][head>>1];
159 	c = fifo->data_char;
160 	stat = fifo->data_stat;
161 	pp->r_head = (head + 2) & RX_MASK;
162 	SEM_LOCK(dcm);
163 	stat = dcm->dcm_iir;
164 	SEM_UNLOCK(dcm);
165 	return c;
166 }
167 #else
168 int
169 dcmgetchar(dev_t dev)
170 {
171 
172 	return 0;
173 }
174 #endif
175 
176 /* ARGSUSED */
177 void
178 dcmputchar(dev_t dev, int c)
179 {
180 	struct dcmdevice *dcm = dcmcnaddr;
181 	struct dcmpreg *pp;
182 	int timo;
183 	unsigned int tail;
184 	int port, stat;
185 
186 	port = DCMCONUNIT;
187 	pp = dcm_preg(dcm, port);
188 	tail = pp->t_tail & TX_MASK;
189 	timo = 50000;
190 	while (tail != (pp->t_head & TX_MASK) && --timo)
191 		;
192 	dcm->dcm_tfifos[3-port][tail].data_char = c;
193 	pp->t_tail = tail = (tail + 1) & TX_MASK;
194 	SEM_LOCK(dcm);
195 	dcm->dcm_cmdtab[port].dcm_data |= CT_TX;
196 	dcm->dcm_cr |= (1 << port);
197 	SEM_UNLOCK(dcm);
198 	timo = 1000000;
199 	while (tail != (pp->t_head & TX_MASK) && --timo)
200 		;
201 	SEM_LOCK(dcm);
202 	stat = dcm->dcm_iir;
203 	SEM_UNLOCK(dcm);
204 }
205 #endif
206