This source file includes following definitions.
- hsqprobe
- hsqprint
- hsqattach
- hsqintr
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77 #include <sys/param.h>
78 #include <sys/systm.h>
79 #include <sys/device.h>
80 #include <sys/termios.h>
81
82 #include <machine/bus.h>
83 #include <machine/intr.h>
84
85 #include <dev/isa/isavar.h>
86 #include <dev/ic/comreg.h>
87 #include <dev/ic/comvar.h>
88
89
90
91
92 #define NSLAVES (4)
93 #define UART_MASK (0x0f)
94
95 #define com_uer (com_scratch)
96 #define com_uir (com_scratch)
97
98 struct hsq_softc {
99 struct device sc_dev;
100 void *sc_ih;
101
102 bus_space_tag_t sc_iot;
103 int sc_iobase;
104
105 void *sc_slaves[NSLAVES];
106 bus_space_handle_t sc_slaveioh[NSLAVES];
107 };
108
109 int hsqprobe(struct device *, void *, void *);
110 void hsqattach(struct device *, struct device *, void *);
111 int hsqintr(void *);
112 int hsqprint(void *, const char *);
113
114 struct cfattach hsq_ca = {
115 sizeof(struct hsq_softc), hsqprobe, hsqattach
116 };
117
118 struct cfdriver hsq_cd = {
119 NULL, "hsq", DV_TTY
120 };
121
122 int
123 hsqprobe(parent, self, aux)
124 struct device *parent;
125 void *self;
126 void *aux;
127 {
128 struct isa_attach_args *ia = aux;
129 int iobase = ia->ia_iobase;
130 bus_space_tag_t iot = ia->ia_iot;
131 bus_space_handle_t ioh;
132 int i, rv = 1;
133
134
135
136
137
138
139
140
141
142 if (iobase == comconsaddr && !comconsattached)
143 goto checkmappings;
144
145
146 if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
147 rv = 0;
148 goto out;
149 }
150
151 rv = comprobe1(iot, ioh);
152 bus_space_unmap(iot, ioh, COM_NPORTS);
153 if (rv == 0)
154 goto out;
155
156 checkmappings:
157 for (i = 1; i < NSLAVES; i++) {
158 iobase += COM_NPORTS;
159
160 if (iobase == comconsaddr && !comconsattached)
161 continue;
162
163 if (bus_space_map(iot, iobase, COM_NPORTS, 0, &ioh)) {
164 rv = 0;
165 goto out;
166 }
167 bus_space_unmap(iot, ioh, COM_NPORTS);
168 }
169
170 out:
171 if (rv)
172 ia->ia_iosize = NSLAVES * COM_NPORTS;
173 return (rv);
174 }
175
176 int
177 hsqprint(aux, pnp)
178 void *aux;
179 const char *pnp;
180 {
181 struct commulti_attach_args *ca = aux;
182
183 if (pnp)
184 printf("com at %s", pnp);
185 printf(" slave %d", ca->ca_slave);
186 return (UNCONF);
187 }
188
189 void
190 hsqattach(parent, self, aux)
191 struct device *parent, *self;
192 void *aux;
193 {
194 struct hsq_softc *sc = (void *)self;
195 struct isa_attach_args *ia = aux;
196 struct commulti_attach_args ca;
197 int i;
198
199 sc->sc_iot = ia->ia_iot;
200 sc->sc_iobase = ia->ia_iobase;
201
202 for (i = 0; i < NSLAVES; i++)
203 if (bus_space_map(sc->sc_iot, sc->sc_iobase + i * COM_NPORTS,
204 COM_NPORTS, 0, &sc->sc_slaveioh[i]))
205 panic("hsqattach: couldn't map slave %d", i);
206
207
208 printf("\n");
209
210 for (i = 0; i < NSLAVES; i++) {
211 ca.ca_slave = i;
212 ca.ca_iot = sc->sc_iot;
213 ca.ca_ioh = sc->sc_slaveioh[i];
214 ca.ca_iobase = sc->sc_iobase + i * COM_NPORTS;
215 ca.ca_noien = 1;
216
217 sc->sc_slaves[i] = config_found(self, &ca, hsqprint);
218 }
219
220
221 bus_space_write_1(sc->sc_iot, sc->sc_slaveioh[0], com_uer, UART_MASK);
222
223 sc->sc_ih = isa_intr_establish(ia->ia_ic, ia->ia_irq, IST_EDGE,
224 IPL_TTY, hsqintr, sc, sc->sc_dev.dv_xname);
225 }
226
227 int
228 hsqintr(arg)
229 void *arg;
230 {
231 struct hsq_softc *sc = arg;
232 bus_space_tag_t iot = sc->sc_iot;
233 int bits;
234
235 bits = bus_space_read_1(iot, sc->sc_slaveioh[0], com_uir) & UART_MASK;
236 if ( !bits )
237 return (0);
238
239 for (;;) {
240 #define TRY(n) \
241 if ( sc->sc_slaves[n] && bits & (1 << (n)) ) \
242 comintr(sc->sc_slaves[n]);
243
244 TRY(0);
245 TRY(1);
246 TRY(2);
247 TRY(3);
248 #undef TRY
249
250 bits = bus_space_read_1(iot, sc->sc_slaveioh[0],
251 com_uir) & UART_MASK;
252 if ( !bits )
253 return (1);
254 }
255 }