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