dl.c revision 1.34 1 1.33 elad /* $NetBSD: dl.c,v 1.34 2006/05/15 20:44:04 yamt Exp $ */
2 1.2 thorpej
3 1.2 thorpej /*-
4 1.2 thorpej * Copyright (c) 1996, 1997 The NetBSD Foundation, Inc.
5 1.2 thorpej * All rights reserved.
6 1.2 thorpej *
7 1.2 thorpej * This code is derived from software contributed to The NetBSD Foundation
8 1.2 thorpej * by Jason R. Thorpe.
9 1.2 thorpej *
10 1.2 thorpej * Redistribution and use in source and binary forms, with or without
11 1.2 thorpej * modification, are permitted provided that the following conditions
12 1.2 thorpej * are met:
13 1.2 thorpej * 1. Redistributions of source code must retain the above copyright
14 1.2 thorpej * notice, this list of conditions and the following disclaimer.
15 1.2 thorpej * 2. Redistributions in binary form must reproduce the above copyright
16 1.2 thorpej * notice, this list of conditions and the following disclaimer in the
17 1.2 thorpej * documentation and/or other materials provided with the distribution.
18 1.2 thorpej * 3. All advertising materials mentioning features or use of this software
19 1.2 thorpej * must display the following acknowledgement:
20 1.2 thorpej * This product includes software developed by the NetBSD
21 1.2 thorpej * Foundation, Inc. and its contributors.
22 1.2 thorpej * 4. Neither the name of The NetBSD Foundation nor the names of its
23 1.2 thorpej * contributors may be used to endorse or promote products derived
24 1.2 thorpej * from this software without specific prior written permission.
25 1.2 thorpej *
26 1.2 thorpej * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 1.2 thorpej * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 1.2 thorpej * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 1.2 thorpej * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 1.2 thorpej * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 1.2 thorpej * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 1.2 thorpej * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 1.2 thorpej * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 1.2 thorpej * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 1.2 thorpej * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 1.2 thorpej * POSSIBILITY OF SUCH DAMAGE.
37 1.2 thorpej */
38 1.2 thorpej
39 1.1 ragge /*
40 1.28 bjh21 * Copyright (c) 1997 Ben Harris. All rights reserved.
41 1.27 agc * Copyright (c) 1982, 1986, 1990, 1992, 1993
42 1.27 agc * The Regents of the University of California. All rights reserved.
43 1.27 agc *
44 1.27 agc * This code is derived from software contributed to Berkeley by
45 1.27 agc * Ralph Campbell and Rick Macklem.
46 1.27 agc *
47 1.27 agc * Redistribution and use in source and binary forms, with or without
48 1.27 agc * modification, are permitted provided that the following conditions
49 1.27 agc * are met:
50 1.27 agc * 1. Redistributions of source code must retain the above copyright
51 1.27 agc * notice, this list of conditions and the following disclaimer.
52 1.27 agc * 2. Redistributions in binary form must reproduce the above copyright
53 1.27 agc * notice, this list of conditions and the following disclaimer in the
54 1.27 agc * documentation and/or other materials provided with the distribution.
55 1.27 agc * 3. Neither the name of the University nor the names of its contributors
56 1.27 agc * may be used to endorse or promote products derived from this software
57 1.27 agc * without specific prior written permission.
58 1.27 agc *
59 1.27 agc * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
60 1.27 agc * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
61 1.27 agc * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
62 1.27 agc * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
63 1.27 agc * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
64 1.27 agc * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
65 1.27 agc * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 1.27 agc * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 1.27 agc * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 1.27 agc * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 1.27 agc * SUCH DAMAGE.
70 1.27 agc */
71 1.27 agc
72 1.27 agc /*
73 1.1 ragge * Copyright (c) 1996 Ken C. Wellsch. All rights reserved.
74 1.1 ragge *
75 1.1 ragge * This code is derived from software contributed to Berkeley by
76 1.1 ragge * Ralph Campbell and Rick Macklem.
77 1.1 ragge *
78 1.1 ragge * Redistribution and use in source and binary forms, with or without
79 1.1 ragge * modification, are permitted provided that the following conditions
80 1.1 ragge * are met:
81 1.1 ragge * 1. Redistributions of source code must retain the above copyright
82 1.1 ragge * notice, this list of conditions and the following disclaimer.
83 1.1 ragge * 2. Redistributions in binary form must reproduce the above copyright
84 1.1 ragge * notice, this list of conditions and the following disclaimer in the
85 1.1 ragge * documentation and/or other materials provided with the distribution.
86 1.1 ragge * 3. All advertising materials mentioning features or use of this software
87 1.1 ragge * must display the following acknowledgement:
88 1.1 ragge * This product includes software developed by the University of
89 1.1 ragge * California, Berkeley and its contributors.
90 1.1 ragge * 4. Neither the name of the University nor the names of its contributors
91 1.1 ragge * may be used to endorse or promote products derived from this software
92 1.1 ragge * without specific prior written permission.
93 1.1 ragge *
94 1.1 ragge * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
95 1.1 ragge * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
96 1.1 ragge * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
97 1.1 ragge * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
98 1.1 ragge * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
99 1.1 ragge * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
100 1.1 ragge * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
101 1.1 ragge * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
102 1.1 ragge * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
103 1.1 ragge * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
104 1.1 ragge * SUCH DAMAGE.
105 1.1 ragge */
106 1.1 ragge
107 1.1 ragge /*
108 1.1 ragge * dl.c -- Device driver for the DL11 and DLV11 serial cards.
109 1.1 ragge *
110 1.1 ragge * OS-interface code derived from the dz and dca (hp300) drivers.
111 1.1 ragge */
112 1.19 lukem
113 1.19 lukem #include <sys/cdefs.h>
114 1.33 elad __KERNEL_RCSID(0, "$NetBSD: dl.c,v 1.34 2006/05/15 20:44:04 yamt Exp $");
115 1.1 ragge
116 1.1 ragge #include <sys/param.h>
117 1.1 ragge #include <sys/systm.h>
118 1.1 ragge #include <sys/ioctl.h>
119 1.1 ragge #include <sys/tty.h>
120 1.1 ragge #include <sys/proc.h>
121 1.1 ragge #include <sys/buf.h>
122 1.1 ragge #include <sys/conf.h>
123 1.1 ragge #include <sys/file.h>
124 1.1 ragge #include <sys/uio.h>
125 1.1 ragge #include <sys/kernel.h>
126 1.1 ragge #include <sys/syslog.h>
127 1.1 ragge #include <sys/device.h>
128 1.34 yamt #include <sys/kauth.h>
129 1.1 ragge
130 1.7 ragge #include <machine/bus.h>
131 1.1 ragge
132 1.10 ragge #include <dev/qbus/ubavar.h>
133 1.1 ragge
134 1.10 ragge #include <dev/qbus/dlreg.h>
135 1.1 ragge
136 1.7 ragge #include "ioconf.h"
137 1.1 ragge
138 1.1 ragge struct dl_softc {
139 1.1 ragge struct device sc_dev;
140 1.13 matt struct evcnt sc_rintrcnt;
141 1.13 matt struct evcnt sc_tintrcnt;
142 1.7 ragge bus_space_tag_t sc_iot;
143 1.7 ragge bus_space_handle_t sc_ioh;
144 1.7 ragge struct tty *sc_tty;
145 1.1 ragge };
146 1.1 ragge
147 1.13 matt static int dl_match (struct device *, struct cfdata *, void *);
148 1.13 matt static void dl_attach (struct device *, struct device *, void *);
149 1.13 matt static void dlrint (void *);
150 1.13 matt static void dlxint (void *);
151 1.13 matt static void dlstart (struct tty *);
152 1.13 matt static int dlparam (struct tty *, struct termios *);
153 1.13 matt static void dlbrk (struct dl_softc *, int);
154 1.1 ragge
155 1.24 thorpej CFATTACH_DECL(dl, sizeof(struct dl_softc),
156 1.25 thorpej dl_match, dl_attach, NULL, NULL);
157 1.21 gehenna
158 1.21 gehenna dev_type_open(dlopen);
159 1.21 gehenna dev_type_close(dlclose);
160 1.21 gehenna dev_type_read(dlread);
161 1.21 gehenna dev_type_write(dlwrite);
162 1.21 gehenna dev_type_ioctl(dlioctl);
163 1.21 gehenna dev_type_stop(dlstop);
164 1.21 gehenna dev_type_tty(dltty);
165 1.21 gehenna dev_type_poll(dlpoll);
166 1.21 gehenna
167 1.21 gehenna const struct cdevsw dl_cdevsw = {
168 1.21 gehenna dlopen, dlclose, dlread, dlwrite, dlioctl,
169 1.26 jdolecek dlstop, dltty, dlpoll, nommap, ttykqfilter, D_TTY
170 1.1 ragge };
171 1.3 thorpej
172 1.7 ragge #define DL_READ_WORD(reg) \
173 1.7 ragge bus_space_read_2(sc->sc_iot, sc->sc_ioh, reg)
174 1.7 ragge #define DL_WRITE_WORD(reg, val) \
175 1.7 ragge bus_space_write_2(sc->sc_iot, sc->sc_ioh, reg, val)
176 1.7 ragge #define DL_WRITE_BYTE(reg, val) \
177 1.7 ragge bus_space_write_1(sc->sc_iot, sc->sc_ioh, reg, val)
178 1.1 ragge
179 1.1 ragge /* Autoconfig handles: setup the controller to interrupt, */
180 1.1 ragge /* then complete the housecleaning for full operation */
181 1.1 ragge
182 1.1 ragge static int
183 1.14 matt dl_match (struct device *parent, struct cfdata *cf, void *aux)
184 1.1 ragge {
185 1.1 ragge struct uba_attach_args *ua = aux;
186 1.1 ragge
187 1.1 ragge #ifdef DL_DEBUG
188 1.7 ragge printf("Probing for dl at %lo ... ", (long)ua->ua_iaddr);
189 1.1 ragge #endif
190 1.1 ragge
191 1.7 ragge bus_space_write_2(ua->ua_iot, ua->ua_ioh, DL_UBA_XCSR, DL_XCSR_TXIE);
192 1.7 ragge if (bus_space_read_2(ua->ua_iot, ua->ua_ioh, DL_UBA_XCSR) !=
193 1.7 ragge (DL_XCSR_TXIE | DL_XCSR_TX_READY)) {
194 1.1 ragge #ifdef DL_DEBUG
195 1.29 simonb printf("failed (step 1; XCSR = %.4b)\n",
196 1.29 simonb bus_space_read_2(ua->ua_iot, ua->ua_ioh, DL_UBA_XCSR),
197 1.7 ragge DL_XCSR_BITS);
198 1.1 ragge #endif
199 1.1 ragge return 0;
200 1.1 ragge }
201 1.29 simonb
202 1.1 ragge /*
203 1.1 ragge * We have to force an interrupt so the uba driver can work
204 1.1 ragge * out where we are. Unfortunately, the only way to make a
205 1.1 ragge * DL11 interrupt is to get it to send or receive a
206 1.1 ragge * character. We'll send a NUL and hope it doesn't hurt
207 1.1 ragge * anything.
208 1.1 ragge */
209 1.1 ragge
210 1.7 ragge bus_space_write_1(ua->ua_iot, ua->ua_ioh, DL_UBA_XBUFL, '\0');
211 1.1 ragge #if 0 /* This test seems to fail 2/3 of the time :-( */
212 1.1 ragge if (dladdr->dl_xcsr != (DL_XCSR_TXIE)) {
213 1.1 ragge #ifdef DL_DEBUG
214 1.29 simonb printf("failed (step 2; XCSR = %.4b)\n", dladdr->dl_xcsr,
215 1.29 simonb DL_XCSR_BITS);
216 1.1 ragge #endif
217 1.1 ragge return 0;
218 1.1 ragge }
219 1.1 ragge #endif
220 1.1 ragge DELAY(100000); /* delay 1/10 s for character to transmit */
221 1.7 ragge if (bus_space_read_2(ua->ua_iot, ua->ua_ioh, DL_UBA_XCSR) !=
222 1.7 ragge (DL_XCSR_TXIE | DL_XCSR_TX_READY)) {
223 1.1 ragge #ifdef DL_DEBUG
224 1.29 simonb printf("failed (step 3; XCSR = %.4b)\n",
225 1.7 ragge bus_space_read_2(ua->ua_iot, ua->ua_ioh, DL_UBA_XCSR),
226 1.7 ragge DL_XCSR_BITS);
227 1.1 ragge #endif
228 1.1 ragge return 0;
229 1.1 ragge }
230 1.1 ragge
231 1.1 ragge
232 1.29 simonb /* What else do I need to do? */
233 1.1 ragge
234 1.1 ragge return 1;
235 1.1 ragge
236 1.1 ragge }
237 1.1 ragge
238 1.1 ragge static void
239 1.14 matt dl_attach (struct device *parent, struct device *self, void *aux)
240 1.1 ragge {
241 1.32 thorpej struct dl_softc *sc = device_private(self);
242 1.12 augustss struct uba_attach_args *ua = aux;
243 1.1 ragge
244 1.7 ragge sc->sc_iot = ua->ua_iot;
245 1.7 ragge sc->sc_ioh = ua->ua_ioh;
246 1.29 simonb
247 1.1 ragge /* Tidy up the device */
248 1.1 ragge
249 1.7 ragge DL_WRITE_WORD(DL_UBA_RCSR, DL_RCSR_RXIE);
250 1.7 ragge DL_WRITE_WORD(DL_UBA_XCSR, DL_XCSR_TXIE);
251 1.1 ragge
252 1.1 ragge /* Initialize our softc structure. Should be done in open? */
253 1.29 simonb
254 1.1 ragge sc->sc_tty = ttymalloc();
255 1.1 ragge tty_attach(sc->sc_tty);
256 1.1 ragge
257 1.11 matt /* Now register the TX & RX interrupt handlers */
258 1.13 matt uba_intr_establish(ua->ua_icookie, ua->ua_cvec,
259 1.13 matt dlxint, sc, &sc->sc_tintrcnt);
260 1.13 matt uba_intr_establish(ua->ua_icookie, ua->ua_cvec - 4,
261 1.13 matt dlrint, sc, &sc->sc_rintrcnt);
262 1.14 matt evcnt_attach_dynamic(&sc->sc_rintrcnt, EVCNT_TYPE_INTR, ua->ua_evcnt,
263 1.14 matt sc->sc_dev.dv_xname, "rintr");
264 1.14 matt evcnt_attach_dynamic(&sc->sc_tintrcnt, EVCNT_TYPE_INTR, ua->ua_evcnt,
265 1.14 matt sc->sc_dev.dv_xname, "tintr");
266 1.1 ragge
267 1.1 ragge printf("\n");
268 1.1 ragge }
269 1.1 ragge
270 1.1 ragge /* Receiver Interrupt Handler */
271 1.1 ragge
272 1.1 ragge static void
273 1.14 matt dlrint(void *arg)
274 1.1 ragge {
275 1.14 matt struct dl_softc *sc = arg;
276 1.1 ragge
277 1.7 ragge if (DL_READ_WORD(DL_UBA_RCSR) & DL_RCSR_RX_DONE) {
278 1.14 matt struct tty *tp = sc->sc_tty;
279 1.14 matt unsigned c;
280 1.14 matt int cc;
281 1.14 matt
282 1.29 simonb c = DL_READ_WORD(DL_UBA_RBUF);
283 1.1 ragge cc = c & 0xFF;
284 1.1 ragge
285 1.1 ragge if (!(tp->t_state & TS_ISOPEN)) {
286 1.1 ragge wakeup((caddr_t)&tp->t_rawq);
287 1.1 ragge return;
288 1.1 ragge }
289 1.1 ragge
290 1.14 matt if (c & DL_RBUF_OVERRUN_ERR) {
291 1.1 ragge /*
292 1.1 ragge * XXX: This should really be logged somwhere
293 1.1 ragge * else where we can afford the time.
294 1.1 ragge */
295 1.1 ragge log(LOG_WARNING, "%s: rx overrun\n",
296 1.1 ragge sc->sc_dev.dv_xname);
297 1.14 matt }
298 1.1 ragge if (c & DL_RBUF_FRAMING_ERR)
299 1.1 ragge cc |= TTY_FE;
300 1.1 ragge if (c & DL_RBUF_PARITY_ERR)
301 1.1 ragge cc |= TTY_PE;
302 1.1 ragge
303 1.15 eeh (*tp->t_linesw->l_rint)(cc, tp);
304 1.14 matt #if defined(DIAGNOSTIC)
305 1.14 matt } else {
306 1.1 ragge log(LOG_WARNING, "%s: stray rx interrupt\n",
307 1.1 ragge sc->sc_dev.dv_xname);
308 1.14 matt #endif
309 1.14 matt }
310 1.1 ragge }
311 1.1 ragge
312 1.1 ragge /* Transmitter Interrupt Handler */
313 1.1 ragge
314 1.1 ragge static void
315 1.14 matt dlxint(void *arg)
316 1.1 ragge {
317 1.11 matt struct dl_softc *sc = arg;
318 1.14 matt struct tty *tp = sc->sc_tty;
319 1.14 matt
320 1.1 ragge tp->t_state &= ~(TS_BUSY | TS_FLUSH);
321 1.16 enami (*tp->t_linesw->l_start)(tp);
322 1.29 simonb
323 1.1 ragge return;
324 1.1 ragge }
325 1.1 ragge
326 1.1 ragge int
327 1.31 christos dlopen(dev_t dev, int flag, int mode, struct lwp *l)
328 1.1 ragge {
329 1.31 christos struct proc *p = l->l_proc;
330 1.12 augustss struct tty *tp;
331 1.14 matt struct dl_softc *sc;
332 1.12 augustss int unit;
333 1.1 ragge
334 1.7 ragge unit = minor(dev);
335 1.1 ragge
336 1.1 ragge if (unit >= dl_cd.cd_ndevs || dl_cd.cd_devs[unit] == NULL)
337 1.1 ragge return ENXIO;
338 1.1 ragge sc = dl_cd.cd_devs[unit];
339 1.1 ragge
340 1.1 ragge tp = sc->sc_tty;
341 1.1 ragge if (tp == NULL)
342 1.1 ragge return ENODEV;
343 1.1 ragge tp->t_oproc = dlstart;
344 1.1 ragge tp->t_param = dlparam;
345 1.1 ragge tp->t_dev = dev;
346 1.1 ragge
347 1.1 ragge if (!(tp->t_state & TS_ISOPEN)) {
348 1.1 ragge ttychars(tp);
349 1.1 ragge tp->t_iflag = TTYDEF_IFLAG;
350 1.1 ragge tp->t_oflag = TTYDEF_OFLAG;
351 1.1 ragge /* No modem control, so set CLOCAL. */
352 1.1 ragge tp->t_cflag = TTYDEF_CFLAG | CLOCAL;
353 1.1 ragge tp->t_lflag = TTYDEF_LFLAG;
354 1.1 ragge tp->t_ispeed = tp->t_ospeed = TTYDEF_SPEED;
355 1.29 simonb
356 1.1 ragge dlparam(tp, &tp->t_termios);
357 1.1 ragge ttsetwater(tp);
358 1.29 simonb
359 1.30 kleink } else if ((tp->t_state & TS_XCLUDE) &&
360 1.34 yamt kauth_authorize_generic(p->p_cred, KAUTH_GENERIC_ISSUSER,
361 1.34 yamt &p->p_acflag) != 0)
362 1.1 ragge return EBUSY;
363 1.1 ragge
364 1.15 eeh return ((*tp->t_linesw->l_open)(dev, tp));
365 1.1 ragge }
366 1.1 ragge
367 1.1 ragge /*ARGSUSED*/
368 1.1 ragge int
369 1.31 christos dlclose(dev_t dev, int flag, int mode, struct lwp *l)
370 1.1 ragge {
371 1.14 matt struct dl_softc *sc = dl_cd.cd_devs[minor(dev)];
372 1.14 matt struct tty *tp = sc->sc_tty;
373 1.1 ragge
374 1.15 eeh (*tp->t_linesw->l_close)(tp, flag);
375 1.1 ragge
376 1.1 ragge /* Make sure a BREAK state is not left enabled. */
377 1.1 ragge dlbrk(sc, 0);
378 1.1 ragge
379 1.1 ragge return (ttyclose(tp));
380 1.1 ragge }
381 1.1 ragge
382 1.1 ragge int
383 1.14 matt dlread(dev_t dev, struct uio *uio, int flag)
384 1.1 ragge {
385 1.14 matt struct dl_softc *sc = dl_cd.cd_devs[minor(dev)];
386 1.14 matt struct tty *tp = sc->sc_tty;
387 1.1 ragge
388 1.15 eeh return ((*tp->t_linesw->l_read)(tp, uio, flag));
389 1.1 ragge }
390 1.1 ragge
391 1.1 ragge int
392 1.14 matt dlwrite(dev_t dev, struct uio *uio, int flag)
393 1.1 ragge {
394 1.14 matt struct dl_softc *sc = dl_cd.cd_devs[minor(dev)];
395 1.14 matt struct tty *tp = sc->sc_tty;
396 1.1 ragge
397 1.15 eeh return ((*tp->t_linesw->l_write)(tp, uio, flag));
398 1.17 scw }
399 1.17 scw
400 1.17 scw int
401 1.31 christos dlpoll(dev_t dev, int events, struct lwp *l)
402 1.17 scw {
403 1.17 scw struct dl_softc *sc = dl_cd.cd_devs[minor(dev)];
404 1.17 scw struct tty *tp = sc->sc_tty;
405 1.29 simonb
406 1.31 christos return ((*tp->t_linesw->l_poll)(tp, events, l));
407 1.1 ragge }
408 1.1 ragge
409 1.1 ragge int
410 1.31 christos dlioctl(dev_t dev, unsigned long cmd, caddr_t data, int flag, struct lwp *l)
411 1.1 ragge {
412 1.14 matt struct dl_softc *sc = dl_cd.cd_devs[minor(dev)];
413 1.29 simonb struct tty *tp = sc->sc_tty;
414 1.29 simonb int error;
415 1.1 ragge
416 1.1 ragge
417 1.31 christos error = (*tp->t_linesw->l_ioctl)(tp, cmd, data, flag, l);
418 1.29 simonb if (error != EPASSTHROUGH)
419 1.29 simonb return (error);
420 1.20 atatat
421 1.31 christos error = ttioctl(tp, cmd, data, flag, l);
422 1.29 simonb if (error != EPASSTHROUGH)
423 1.29 simonb return (error);
424 1.1 ragge
425 1.1 ragge switch (cmd) {
426 1.1 ragge
427 1.29 simonb case TIOCSBRK:
428 1.29 simonb dlbrk(sc, 1);
429 1.29 simonb break;
430 1.29 simonb
431 1.29 simonb case TIOCCBRK:
432 1.29 simonb dlbrk(sc, 0);
433 1.29 simonb break;
434 1.29 simonb
435 1.29 simonb case TIOCMGET:
436 1.1 ragge /* No modem control, assume they're all low. */
437 1.29 simonb *(int *)data = 0;
438 1.29 simonb break;
439 1.1 ragge
440 1.29 simonb default:
441 1.29 simonb return (EPASSTHROUGH);
442 1.29 simonb }
443 1.29 simonb return (0);
444 1.1 ragge }
445 1.1 ragge
446 1.1 ragge struct tty *
447 1.14 matt dltty(dev_t dev)
448 1.1 ragge {
449 1.14 matt struct dl_softc *sc = dl_cd.cd_devs[minor(dev)];
450 1.14 matt
451 1.1 ragge return sc->sc_tty;
452 1.1 ragge }
453 1.1 ragge
454 1.1 ragge void
455 1.14 matt dlstop(struct tty *tp, int flag)
456 1.1 ragge {
457 1.14 matt int s = spltty();
458 1.1 ragge
459 1.14 matt if ((tp->t_state & (TS_BUSY|TS_TTSTOP)) == TS_BUSY)
460 1.14 matt tp->t_state |= TS_FLUSH;
461 1.29 simonb splx(s);
462 1.1 ragge }
463 1.1 ragge
464 1.1 ragge static void
465 1.14 matt dlstart(struct tty *tp)
466 1.1 ragge {
467 1.14 matt struct dl_softc *sc = dl_cd.cd_devs[minor(tp->t_dev)];
468 1.14 matt int s = spltty();
469 1.1 ragge
470 1.29 simonb if (tp->t_state & (TS_TIMEOUT|TS_BUSY|TS_TTSTOP))
471 1.29 simonb goto out;
472 1.29 simonb if (tp->t_outq.c_cc <= tp->t_lowat) {
473 1.29 simonb if (tp->t_state & TS_ASLEEP) {
474 1.29 simonb tp->t_state &= ~TS_ASLEEP;
475 1.29 simonb wakeup((caddr_t)&tp->t_outq);
476 1.29 simonb }
477 1.29 simonb selwakeup(&tp->t_wsel);
478 1.29 simonb }
479 1.29 simonb if (tp->t_outq.c_cc == 0)
480 1.29 simonb goto out;
481 1.1 ragge
482 1.1 ragge
483 1.7 ragge if (DL_READ_WORD(DL_UBA_XCSR) & DL_XCSR_TX_READY) {
484 1.1 ragge tp->t_state |= TS_BUSY;
485 1.7 ragge DL_WRITE_BYTE(DL_UBA_XBUFL, getc(&tp->t_outq));
486 1.1 ragge }
487 1.1 ragge out:
488 1.1 ragge splx(s);
489 1.1 ragge return;
490 1.1 ragge }
491 1.1 ragge
492 1.1 ragge /*ARGSUSED*/
493 1.1 ragge static int
494 1.14 matt dlparam(struct tty *tp, struct termios *t)
495 1.1 ragge {
496 1.1 ragge /*
497 1.1 ragge * All this kind of stuff (speed, character format, whatever)
498 1.1 ragge * is set by jumpers on the card. Changing it is thus rather
499 1.1 ragge * tricky for a mere device driver.
500 1.1 ragge */
501 1.1 ragge return 0;
502 1.1 ragge }
503 1.1 ragge
504 1.1 ragge static void
505 1.14 matt dlbrk(struct dl_softc *sc, int state)
506 1.1 ragge {
507 1.7 ragge int s = spltty();
508 1.7 ragge
509 1.7 ragge if (state) {
510 1.7 ragge DL_WRITE_WORD(DL_UBA_XCSR, DL_READ_WORD(DL_UBA_XCSR) |
511 1.7 ragge DL_XCSR_TX_BREAK);
512 1.7 ragge } else {
513 1.7 ragge DL_WRITE_WORD(DL_UBA_XCSR, DL_READ_WORD(DL_UBA_XCSR) &
514 1.7 ragge ~DL_XCSR_TX_BREAK);
515 1.7 ragge }
516 1.1 ragge splx(s);
517 1.1 ragge }
518