dca.c revision 1.7 1 1.7 rmind /* $NetBSD: dca.c,v 1.7 2011/02/08 20:20:14 rmind Exp $ */
2 1.1 thorpej
3 1.1 thorpej /*
4 1.7 rmind * Copyright (c) 1988 University of Utah.
5 1.1 thorpej * Copyright (c) 1990, 1993
6 1.1 thorpej * The Regents of the University of California. All rights reserved.
7 1.2 agc *
8 1.2 agc * This code is derived from software contributed to Berkeley by
9 1.2 agc * the Systems Programming Group of the University of Utah Computer
10 1.2 agc * Science Department.
11 1.2 agc *
12 1.2 agc * Redistribution and use in source and binary forms, with or without
13 1.2 agc * modification, are permitted provided that the following conditions
14 1.2 agc * are met:
15 1.2 agc * 1. Redistributions of source code must retain the above copyright
16 1.2 agc * notice, this list of conditions and the following disclaimer.
17 1.2 agc * 2. Redistributions in binary form must reproduce the above copyright
18 1.2 agc * notice, this list of conditions and the following disclaimer in the
19 1.2 agc * documentation and/or other materials provided with the distribution.
20 1.2 agc * 3. Neither the name of the University nor the names of its contributors
21 1.2 agc * may be used to endorse or promote products derived from this software
22 1.2 agc * without specific prior written permission.
23 1.2 agc *
24 1.2 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 1.2 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 1.2 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 1.2 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 1.2 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 1.2 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 1.2 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 1.2 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 1.2 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 1.2 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 1.2 agc * SUCH DAMAGE.
35 1.2 agc *
36 1.2 agc * @(#)dca.c 8.1 (Berkeley) 6/10/93
37 1.2 agc */
38 1.1 thorpej
39 1.1 thorpej #ifdef DCACONSOLE
40 1.1 thorpej #include <sys/param.h>
41 1.1 thorpej #include <dev/cons.h>
42 1.1 thorpej
43 1.3 tsutsui #include <hp300/stand/common/dcareg.h>
44 1.1 thorpej #include <hp300/stand/common/consdefs.h>
45 1.1 thorpej #include <hp300/stand/common/samachdep.h>
46 1.1 thorpej
47 1.1 thorpej /* If not using 4.4 devs */
48 1.1 thorpej #ifndef dca_reset
49 1.1 thorpej #define dca_id dca_irid
50 1.1 thorpej #define dca_reset dca_id
51 1.1 thorpej #endif
52 1.1 thorpej
53 1.1 thorpej struct dcadevice *dcacnaddr = 0;
54 1.1 thorpej
55 1.1 thorpej #define DCACONSCODE 9 /* XXX */
56 1.1 thorpej
57 1.1 thorpej void
58 1.5 tsutsui dcaprobe(struct consdev *cp)
59 1.1 thorpej {
60 1.4 tsutsui struct dcadevice *dca;
61 1.1 thorpej
62 1.1 thorpej dcacnaddr = (struct dcadevice *) sctoaddr(DCACONSCODE);
63 1.1 thorpej if (badaddr((char *)dcacnaddr)) {
64 1.1 thorpej cp->cn_pri = CN_DEAD;
65 1.1 thorpej return;
66 1.1 thorpej }
67 1.1 thorpej #ifdef FORCEDCACONSOLE
68 1.1 thorpej cp->cn_pri = CN_REMOTE;
69 1.1 thorpej #else
70 1.1 thorpej dca = dcacnaddr;
71 1.1 thorpej switch (dca->dca_id) {
72 1.1 thorpej case DCAID0:
73 1.1 thorpej case DCAID1:
74 1.1 thorpej cp->cn_pri = CN_NORMAL;
75 1.1 thorpej break;
76 1.1 thorpej case DCAREMID0:
77 1.1 thorpej case DCAREMID1:
78 1.1 thorpej cp->cn_pri = CN_REMOTE;
79 1.1 thorpej break;
80 1.1 thorpej default:
81 1.1 thorpej cp->cn_pri = CN_DEAD;
82 1.1 thorpej break;
83 1.1 thorpej }
84 1.1 thorpej
85 1.1 thorpej #endif
86 1.1 thorpej curcons_scode = DCACONSCODE;
87 1.1 thorpej }
88 1.1 thorpej
89 1.1 thorpej void
90 1.5 tsutsui dcainit(struct consdev *cp)
91 1.1 thorpej {
92 1.4 tsutsui struct dcadevice *dca = dcacnaddr;
93 1.1 thorpej
94 1.1 thorpej dca->dca_reset = 0xFF;
95 1.1 thorpej DELAY(100);
96 1.1 thorpej dca->dca_ic = 0;
97 1.1 thorpej dca->dca_cfcr = CFCR_DLAB;
98 1.1 thorpej dca->dca_data = DCABRD(9600) & 0xFF;
99 1.1 thorpej dca->dca_ier = DCABRD(9600) >> 8;
100 1.1 thorpej dca->dca_cfcr = CFCR_8BITS;
101 1.1 thorpej dca->dca_fifo =
102 1.1 thorpej FIFO_ENABLE | FIFO_RCV_RST | FIFO_XMT_RST | FIFO_TRIGGER_1;
103 1.1 thorpej dca->dca_mcr = MCR_DTR | MCR_RTS;
104 1.1 thorpej }
105 1.1 thorpej
106 1.1 thorpej /* ARGSUSED */
107 1.1 thorpej #ifndef SMALL
108 1.1 thorpej int
109 1.5 tsutsui dcagetchar(dev_t dev)
110 1.1 thorpej {
111 1.4 tsutsui struct dcadevice *dca = dcacnaddr;
112 1.1 thorpej short stat;
113 1.1 thorpej int c;
114 1.1 thorpej
115 1.1 thorpej if (((stat = dca->dca_lsr) & LSR_RXRDY) == 0)
116 1.4 tsutsui return 0;
117 1.1 thorpej c = dca->dca_data;
118 1.4 tsutsui return c;
119 1.1 thorpej }
120 1.1 thorpej #else
121 1.1 thorpej int
122 1.5 tsutsui dcagetchar(dev_t dev)
123 1.1 thorpej {
124 1.4 tsutsui
125 1.4 tsutsui return 0;
126 1.1 thorpej }
127 1.1 thorpej #endif
128 1.1 thorpej
129 1.1 thorpej /* ARGSUSED */
130 1.1 thorpej void
131 1.5 tsutsui dcaputchar(dev_t dev, int c)
132 1.1 thorpej {
133 1.4 tsutsui struct dcadevice *dca = dcacnaddr;
134 1.4 tsutsui int timo;
135 1.1 thorpej short stat;
136 1.1 thorpej
137 1.1 thorpej /* wait a reasonable time for the transmitter to come ready */
138 1.1 thorpej timo = 50000;
139 1.1 thorpej while (((stat = dca->dca_lsr) & LSR_TXRDY) == 0 && --timo)
140 1.1 thorpej ;
141 1.1 thorpej dca->dca_data = c;
142 1.1 thorpej /* wait for this transmission to complete */
143 1.1 thorpej timo = 1000000;
144 1.1 thorpej while (((stat = dca->dca_lsr) & LSR_TXRDY) == 0 && --timo)
145 1.1 thorpej ;
146 1.1 thorpej }
147 1.1 thorpej #endif
148