No empty .Rs/.Re
[netbsd-mini2440.git] / sys / arch / hp300 / stand / common / dcm.c
blobeded6130415bb234ae96436bccfe55f6ba5950e4
1 /* $NetBSD: dcm.c,v 1.6 2005/12/11 12:17:19 christos Exp $ */
3 /*
4 * Copyright (c) 1990, 1993
5 * The Regents of the University of California. All rights reserved.
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.
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.
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.
35 * @(#)dcm.c 8.1 (Berkeley) 6/10/93
38 * Copyright (c) 1988 University of Utah.
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.
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.
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.
72 * @(#)dcm.c 8.1 (Berkeley) 6/10/93
75 #ifdef DCMCONSOLE
76 #include <sys/param.h>
77 #include <dev/cons.h>
79 #include <hp300/dev/dcmreg.h>
81 #include <hp300/stand/common/consdefs.h>
82 #include <hp300/stand/common/samachdep.h>
83 #include <hp300/stand/common/device.h>
85 struct dcmdevice *dcmcnaddr = NULL;
87 #define DCMCONUNIT 1 /* XXX */
89 void
90 dcmprobe(struct consdev *cp)
92 struct hp_hw *hw;
93 struct dcmdevice *dcm;
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;
102 dcmcnaddr = (struct dcmdevice *) hw->hw_kva;
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;
120 curcons_scode = hw->hw_sc;
121 #endif
124 void
125 dcminit(struct consdev *cp)
127 struct dcmdevice *dcm = dcmcnaddr;
128 int port = DCMCONUNIT;
130 dcm->dcm_ic = IC_ID;
131 while (dcm->dcm_thead[port].ptr != dcm->dcm_ttail[port].ptr)
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);
142 /* ARGSUSED */
143 #ifndef SMALL
145 dcmgetchar(dev_t dev)
147 struct dcmdevice *dcm = dcmcnaddr;
148 struct dcmrfifo *fifo;
149 struct dcmpreg *pp;
150 unsigned int head;
151 int c, stat, port;
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;
167 #else
169 dcmgetchar(dev_t dev)
172 return 0;
174 #endif
176 /* ARGSUSED */
177 void
178 dcmputchar(dev_t dev, int c)
180 struct dcmdevice *dcm = dcmcnaddr;
181 struct dcmpreg *pp;
182 int timo;
183 unsigned int tail;
184 int port, stat;
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)
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)
201 SEM_LOCK(dcm);
202 stat = dcm->dcm_iir;
203 SEM_UNLOCK(dcm);
205 #endif