2 * cyclades cyclom-y serial driver
3 * Andrew Herbert <andrew@werple.apana.org.au>, 17 August 1993
5 * Copyright (c) 1993 Andrew Herbert.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. The name Andrew Herbert may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY ``AS IS'' AND ANY EXPRESS OR IMPLIED
20 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
21 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
22 * NO EVENT SHALL I BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
23 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
24 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
25 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
26 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
27 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
28 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 * $FreeBSD: src/sys/i386/isa/cy.c,v 1.97.2.2 2001/08/22 13:04:58 bde Exp $
33 #include "opt_compat.h"
43 * Temporary compile-time configuration options.
45 #define RxFifoThreshold (CD1400_RX_FIFO_SIZE / 2)
46 /* Number of chars in the receiver FIFO before an
47 * an interrupt is generated. Should depend on
48 * line speed. Needs to be about 6 on a 486DX33
49 * for 4 active ports at 115200 bps. Why doesn't
52 #define PollMode /* Use polling-based irq service routine, not the
53 * hardware svcack lines. Must be defined for
54 * Cyclom-16Y boards. Less efficient for Cyclom-8Ys,
55 * and stops 4 * 115200 bps from working.
57 #undef Smarts /* Enable slightly more CD1400 intelligence. Mainly
58 * the output CR/LF processing, plus we can avoid a
59 * few checks usually done in ttyinput().
61 * XXX not fully implemented, and not particularly
64 #undef CyDebug /* Include debugging code (not very expensive). */
66 /* These will go away. */
70 #include <sys/param.h>
71 #include <sys/systm.h>
75 #include <sys/dkstat.h>
76 #include <sys/fcntl.h>
77 #include <sys/interrupt.h>
78 #include <sys/kernel.h>
79 #include <sys/malloc.h>
80 #include <sys/syslog.h>
81 #include <machine/clock.h>
82 #include <machine/ipl.h>
84 #include <machine/lock.h>
86 #include <machine/psl.h>
88 #include <i386/isa/isa_device.h>
89 #include <i386/isa/cyreg.h>
90 #include <i386/isa/ic/cd1400.h>
93 #define disable_intr() COM_DISABLE_INTR()
94 #define enable_intr() COM_ENABLE_INTR()
98 * Dictionary so that I can name everything *sio* or *com* to compare with
99 * sio.c. There is also lots of ugly formatting and unnecessary ifdefs to
100 * simplify the comparision. These will go away.
102 #define LSR_BI CD1400_RDSR_BREAK
103 #define LSR_FE CD1400_RDSR_FE
104 #define LSR_OE CD1400_RDSR_OE
105 #define LSR_PE CD1400_RDSR_PE
106 #define MCR_DTR CD1400_MSVR2_DTR
107 #define MCR_RTS CD1400_MSVR1_RTS
108 #define MSR_CTS CD1400_MSVR2_CTS
109 #define MSR_DCD CD1400_MSVR2_CD
110 #define MSR_DSR CD1400_MSVR2_DSR
111 #define MSR_RI CD1400_MSVR2_RI
112 #define NSIO (NCY * CY_MAX_PORTS)
113 #define comconsole cyconsole
114 #define comdefaultrate cydefaultrate
115 #define com_events cy_events
116 #define comhardclose cyhardclose
117 #define commctl cymctl
118 #define comparam cyparam
119 #define comspeed cyspeed
120 #define comstart cystart
121 #define comwakeup cywakeup
122 #define nsio_tty ncy_tty
123 #define p_com_addr p_cy_addr
124 #define sioattach cyattach
125 #define sioclose cyclose
126 #define siodriver cydriver
127 #define siodtrwakeup cydtrwakeup
128 #define sioinput cyinput
129 #define siointr cyintr
130 #define siointr1 cyintr1
131 #define sioioctl cyioctl
132 #define sioopen cyopen
133 #define siopoll cypoll
134 #define sioprobe cyprobe
135 #define siosettimeout cysettimeout
136 #define siosetwater cysetwater
137 #define comstop cystop
138 #define siowrite cywrite
139 #define sio_registered cy_registered
140 #define sio_timeout cy_timeout
141 #define sio_timeout_handle cy_timeout_handle
142 #define sio_timeouts_until_log cy_timeouts_until_log
143 #define sio_tty cy_tty
145 #define CY_MAX_PORTS (CD1400_NO_OF_CHANNELS * CY_MAX_CD1400s)
147 /* We encode the cyclom unit number (cyu) in spare bits in the IVR's. */
148 #define CD1400_xIVR_CHAN_SHIFT 3
149 #define CD1400_xIVR_CHAN 0x1F
152 * ETC states. com->etc may also contain a hardware ETC command value,
153 * meaning that execution of that command is pending.
155 #define ETC_NONE 0 /* we depend on bzero() setting this */
156 #define ETC_BREAK_STARTING 1
157 #define ETC_BREAK_STARTED 2
158 #define ETC_BREAK_ENDING 3
159 #define ETC_BREAK_ENDED 4
161 #define LOTS_OF_EVENTS 64 /* helps separate urgent events from input */
163 #define CALLOUT_MASK 0x80
164 #define CONTROL_MASK 0x60
165 #define CONTROL_INIT_STATE 0x20
166 #define CONTROL_LOCK_STATE 0x40
167 #define DEV_TO_UNIT(dev) (MINOR_TO_UNIT(minor(dev)))
168 #define MINOR_MAGIC_MASK (CALLOUT_MASK | CONTROL_MASK)
170 * Not all of the magic is parametrized in the following macros. 16 and
171 * 0xff are related to the bitfields in a udev_t. CY_MAX_PORTS must be
172 * ((0xff & ~MINOR_MAGIC_MASK) + 1) for things to work.
174 #define MINOR_TO_UNIT(mynor) (((mynor) >> 16) * CY_MAX_PORTS \
175 | (((mynor) & 0xff) & ~MINOR_MAGIC_MASK))
176 #define UNIT_TO_MINOR(unit) (((unit) / CY_MAX_PORTS) << 16 \
177 | (((unit) & 0xff) & ~MINOR_MAGIC_MASK))
181 * (CS_BUSY | CS_TTGO) and (CS_BUSY | CS_TTGO | CS_ODEVREADY) must be higher
182 * than the other bits so that they can be tested as a group without masking
185 * The following com and tty flags correspond closely:
186 * CS_BUSY = TS_BUSY (maintained by comstart(), siopoll() and
188 * CS_TTGO = ~TS_TTSTOP (maintained by comparam() and comstart())
189 * CS_CTS_OFLOW = CCTS_OFLOW (maintained by comparam())
190 * CS_RTS_IFLOW = CRTS_IFLOW (maintained by comparam())
191 * TS_FLUSH is not used.
192 * XXX I think TIOCSETA doesn't clear TS_TTSTOP when it clears IXON.
193 * XXX CS_*FLOW should be CF_*FLOW in com->flags (control flags not state).
195 #define CS_BUSY 0x80 /* output in progress */
196 #define CS_TTGO 0x40 /* output not stopped by XOFF */
197 #define CS_ODEVREADY 0x20 /* external device h/w ready (CTS) */
198 #define CS_CHECKMSR 1 /* check of MSR scheduled */
199 #define CS_CTS_OFLOW 2 /* use CTS output flow control */
200 #define CS_DTR_OFF 0x10 /* DTR held off */
201 #define CS_ODONE 4 /* output completed */
202 #define CS_RTS_IFLOW 8 /* use RTS input flow control */
203 #define CSE_ODONE 1 /* output transmitted */
205 static char const * const error_desc[] = {
208 #define CE_INTERRUPT_BUF_OVERFLOW 1
209 "interrupt-level buffer overflow",
210 #define CE_TTY_BUF_OVERFLOW 2
211 "tty-level buffer overflow",
215 #define CE_RECORD(com, errnum) (++(com)->delta_error_counts[errnum])
217 /* types. XXX - should be elsewhere */
218 typedef u_char bool_t; /* boolean */
219 typedef u_char volatile *cy_addr;
221 /* queue of linear buffers */
223 u_char *l_head; /* next char to process */
224 u_char *l_tail; /* one past the last char to process */
225 struct lbq *l_next; /* next in queue */
226 bool_t l_queued; /* nonzero if queued */
229 /* com device structure */
231 u_char state; /* miscellaneous flag bits */
232 bool_t active_out; /* nonzero if the callout device is open */
234 u_char cfcr_image; /* copy of value written to CFCR */
236 u_char etc; /* pending Embedded Transmit Command */
237 u_char extra_state; /* more flag bits, separate for order trick */
239 u_char fifo_image; /* copy of value written to FIFO */
241 u_char gfrcr_image; /* copy of value read from GFRCR */
243 bool_t hasfifo; /* nonzero for 16550 UARTs */
244 bool_t loses_outints; /* nonzero if device loses output interrupts */
246 u_char mcr_dtr; /* MCR bit that is wired to DTR */
247 u_char mcr_image; /* copy of value written to MCR */
248 u_char mcr_rts; /* MCR bit that is wired to RTS */
251 bool_t multiport; /* is this unit part of a multiport device? */
252 #endif /* COM_MULTIPORT */
253 bool_t no_irq; /* nonzero if irq is not attached */
254 bool_t poll; /* nonzero if polling is required */
255 bool_t poll_output; /* nonzero if polling for output is required */
257 int unit; /* unit number */
258 int dtr_wait; /* time to hold DTR down on close (* 1/hz) */
262 u_int wopeners; /* # processes waiting for DCD in open() */
265 * The high level of the driver never reads status registers directly
266 * because there would be too many side effects to handle conveniently.
267 * Instead, it reads copies of the registers stored here by the
270 u_char last_modem_status; /* last MSR read by intr handler */
271 u_char prev_modem_status; /* last MSR handled by high level */
273 u_char hotchar; /* ldisc-specific char to be handled ASAP */
274 u_char *ibuf; /* start of input buffer */
275 u_char *ibufend; /* end of input buffer */
276 u_char *ibufold; /* old input buffer, to be freed */
277 u_char *ihighwater; /* threshold in input buffer */
278 u_char *iptr; /* next free spot in input buffer */
279 int ibufsize; /* size of ibuf (not include error bytes) */
280 int ierroff; /* offset of error bytes in ibuf */
282 struct lbq obufq; /* head of queue of output buffers */
283 struct lbq obufs[2]; /* output buffers */
285 int cy_align; /* index for register alignment */
286 cy_addr cy_iobase; /* base address of this port's cyclom */
287 cy_addr iobase; /* base address of this port's cd1400 */
288 int mcr_rts_reg; /* cd1400 reg number of reg holding mcr_rts */
290 struct tty *tp; /* cross reference */
293 struct termios it_in; /* should be in struct tty */
294 struct termios it_out;
297 struct termios lt_in; /* should be in struct tty */
298 struct termios lt_out;
301 bool_t do_dcd_timestamp;
302 struct timeval timestamp;
303 struct timeval dcd_timestamp;
305 u_long bytes_in; /* statistics */
307 u_int delta_error_counts[CE_NTYPES];
308 u_long error_counts[CE_NTYPES];
310 u_int recv_exception; /* exception chars received */
311 u_int mdm; /* modem signal changes */
313 u_int start_count; /* no. of calls to comstart() */
314 u_int start_real; /* no. of calls that did something */
316 u_char car; /* CD1400 CAR shadow (if first unit in cd) */
317 u_char channel_control;/* CD1400 CCR control command shadow */
318 u_char cor[3]; /* CD1400 COR1-3 shadows */
319 u_char intr_enable; /* CD1400 SRER shadow */
322 * Data area for output buffers. Someday we should build the output
323 * buffer queue without copying data.
329 /* PCI driver entry point. */
330 int cyattach_common __P((cy_addr cy_iobase, int cy_align));
333 static int cy_units __P((cy_addr cy_iobase, int cy_align));
334 static int sioattach __P((struct isa_device *dev));
335 static void cd1400_channel_cmd __P((struct com_s *com, int cmd));
336 static void cd1400_channel_cmd_wait __P((struct com_s *com));
337 static void cd_etc __P((struct com_s *com, int etc));
338 static int cd_getreg __P((struct com_s *com, int reg));
339 static void cd_setreg __P((struct com_s *com, int reg, int val));
340 static timeout_t siodtrwakeup;
341 static void comhardclose __P((struct com_s *com));
342 static void sioinput __P((struct com_s *com));
344 static void siointr1 __P((struct com_s *com));
346 static int commctl __P((struct com_s *com, int bits, int how));
347 static int comparam __P((struct tty *tp, struct termios *t));
348 static swihand_t siopoll;
349 static int sioprobe __P((struct isa_device *dev));
350 static void siosettimeout __P((void));
351 static int siosetwater __P((struct com_s *com, speed_t speed));
352 static int comspeed __P((speed_t speed, u_long cy_clock,
354 static void comstart __P((struct tty *tp));
355 static void comstop __P((struct tty *tp, int rw));
356 static timeout_t comwakeup;
357 static void disc_optim __P((struct tty *tp, struct termios *t,
361 void cystatus __P((int unit));
364 static char driver_name[] = "cy";
366 /* table and macro for fast conversion from a unit number to its com struct */
367 static struct com_s *p_com_addr[NSIO];
368 #define com_addr(unit) (p_com_addr[unit])
370 struct isa_driver siodriver = {
371 sioprobe, sioattach, driver_name
374 static d_open_t sioopen;
375 static d_close_t sioclose;
376 static d_write_t siowrite;
377 static d_ioctl_t sioioctl;
379 #define CDEV_MAJOR 48
380 static struct cdevsw sio_cdevsw = {
382 /* close */ sioclose,
384 /* write */ siowrite,
385 /* ioctl */ sioioctl,
388 /* strategy */ nostrategy,
389 /* name */ driver_name,
390 /* maj */ CDEV_MAJOR,
393 /* flags */ D_TTY | D_KQFILTER,
395 /* kqfilter */ ttykqfilter,
398 static int comconsole = -1;
399 static speed_t comdefaultrate = TTYDEF_SPEED;
400 static u_int com_events; /* input chars + weighted output completions */
401 static bool_t sio_registered;
402 static int sio_timeout;
403 static int sio_timeouts_until_log;
404 static struct callout_handle sio_timeout_handle
405 = CALLOUT_HANDLE_INITIALIZER(&sio_timeout_handle);
407 static struct tty *sio_tty[NSIO];
409 static struct tty sio_tty[NSIO];
411 static const int nsio_tty = NSIO;
414 static u_int cd_inbs;
415 static u_int cy_inbs;
416 static u_int cd_outbs;
417 static u_int cy_outbs;
418 static u_int cy_svrr_probes;
419 static u_int cy_timeouts;
422 static int cy_chip_offset[] = {
423 0x0000, 0x0400, 0x0800, 0x0c00, 0x0200, 0x0600, 0x0a00, 0x0e00,
425 static int cy_nr_cd1400s[NCY];
426 static int cy_total_devices;
427 #undef RxFifoThreshold
428 static int volatile RxFifoThreshold = (CD1400_RX_FIFO_SIZE / 2);
432 struct isa_device *dev;
436 iobase = (cy_addr)dev->id_maddr;
438 /* Cyclom-16Y hardware reset (Cyclom-8Ys don't care) */
439 cy_inb(iobase, CY16_RESET, 0); /* XXX? */
440 DELAY(500); /* wait for the board to get its act together */
442 /* this is needed to get the board out of reset */
443 cy_outb(iobase, CY_CLEAR_INTR, 0, 0);
446 return (cy_units(iobase, 0) == 0 ? 0 : -1);
450 cy_units(cy_iobase, cy_align)
455 u_char firmware_version;
459 for (cyu = 0; cyu < CY_MAX_CD1400s; ++cyu) {
460 iobase = cy_iobase + (cy_chip_offset[cyu] << cy_align);
462 /* wait for chip to become ready for new command */
463 for (i = 0; i < 10; i++) {
465 if (!cd_inb(iobase, CD1400_CCR, cy_align))
469 /* clear the GFRCR register */
470 cd_outb(iobase, CD1400_GFRCR, cy_align, 0);
472 /* issue a reset command */
473 cd_outb(iobase, CD1400_CCR, cy_align,
474 CD1400_CCR_CMDRESET | CD1400_CCR_FULLRESET);
476 /* wait for the CD1400 to initialize itself */
477 for (i = 0; i < 200; i++) {
480 /* retrieve firmware version */
481 firmware_version = cd_inb(iobase, CD1400_GFRCR,
483 if ((firmware_version & 0xf0) == 0x40)
488 * Anything in the 0x40-0x4F range is fine.
489 * If one CD1400 is bad then we don't support higher
490 * numbered good ones on this board.
492 if ((firmware_version & 0xf0) != 0x40)
500 struct isa_device *isdp;
504 adapter = cyattach_common((cy_addr) isdp->id_maddr, 0);
510 * This kludge is to allow ISA/PCI device specifications in the
511 * kernel config file to be in any order.
513 if (isdp->id_unit != adapter) {
514 printf("cy%d: attached as cy%d\n", isdp->id_unit, adapter);
515 isdp->id_unit = adapter; /* XXX */
517 isdp->id_ointr = siointr;
518 /* isdp->id_ri_flags |= RI_FAST; XXX unimplemented - use newbus! */
523 cyattach_common(cy_iobase, cy_align)
529 u_char firmware_version;
535 adapter = cy_total_devices;
536 if ((u_int)adapter >= NCY) {
538 "cy%d: can't attach adapter: insufficient cy devices configured\n",
542 ncyu = cy_units(cy_iobase, cy_align);
545 cy_nr_cd1400s[adapter] = ncyu;
548 unit = adapter * CY_MAX_PORTS;
549 for (cyu = 0; cyu < ncyu; ++cyu) {
552 iobase = (cy_addr) (cy_iobase
553 + (cy_chip_offset[cyu] << cy_align));
554 firmware_version = cd_inb(iobase, CD1400_GFRCR, cy_align);
556 /* Set up a receive timeout period of than 1+ ms. */
557 cd_outb(iobase, CD1400_PPR, cy_align,
558 howmany(CY_CLOCK(firmware_version)
559 / CD1400_PPR_PRESCALER, 1000));
561 for (cdu = 0; cdu < CD1400_NO_OF_CHANNELS; ++cdu, ++unit) {
565 com = malloc(sizeof *com, M_DEVBUF, M_NOWAIT);
568 bzero(com, sizeof *com);
570 com->gfrcr_image = firmware_version;
571 if (CY_RTS_DTR_SWAPPED(firmware_version)) {
572 com->mcr_dtr = MCR_RTS;
573 com->mcr_rts = MCR_DTR;
574 com->mcr_rts_reg = CD1400_MSVR2;
576 com->mcr_dtr = MCR_DTR;
577 com->mcr_rts = MCR_RTS;
578 com->mcr_rts_reg = CD1400_MSVR1;
580 com->dtr_wait = 3 * hz;
581 com->obufs[0].l_head = com->obuf1;
582 com->obufs[1].l_head = com->obuf2;
584 com->cy_align = cy_align;
585 com->cy_iobase = cy_iobase;
586 com->iobase = iobase;
587 com->car = ~CD1400_CAR_CHAN;
590 * We don't use all the flags from <sys/ttydefaults.h> since they
591 * are only relevant for logins. It's important to have echo off
592 * initially so that the line doesn't start blathering before the
593 * echo flag can be turned off.
595 com->it_in.c_iflag = 0;
596 com->it_in.c_oflag = 0;
597 com->it_in.c_cflag = TTYDEF_CFLAG;
598 com->it_in.c_lflag = 0;
599 if (unit == comconsole) {
600 com->it_in.c_iflag = TTYDEF_IFLAG;
601 com->it_in.c_oflag = TTYDEF_OFLAG;
602 com->it_in.c_cflag = TTYDEF_CFLAG | CLOCAL;
603 com->it_in.c_lflag = TTYDEF_LFLAG;
604 com->lt_out.c_cflag = com->lt_in.c_cflag = CLOCAL;
606 if (siosetwater(com, com->it_in.c_ispeed) != 0) {
612 termioschars(&com->it_in);
613 com->it_in.c_ispeed = com->it_in.c_ospeed = comdefaultrate;
614 com->it_out = com->it_in;
617 com_addr(unit) = com;
620 if (!sio_registered) {
621 cdevsw_add(&sio_cdevsw);
622 register_swi(SWI_TTY, siopoll);
623 sio_registered = TRUE;
625 minorbase = UNIT_TO_MINOR(unit);
626 make_dev(&sio_cdevsw, minorbase,
627 UID_ROOT, GID_WHEEL, 0600, "ttyc%r%r", adapter,
628 unit % CY_MAX_PORTS);
629 make_dev(&sio_cdevsw, minorbase | CONTROL_INIT_STATE,
630 UID_ROOT, GID_WHEEL, 0600, "ttyic%r%r", adapter,
631 unit % CY_MAX_PORTS);
632 make_dev(&sio_cdevsw, minorbase | CONTROL_LOCK_STATE,
633 UID_ROOT, GID_WHEEL, 0600, "ttylc%r%r", adapter,
634 unit % CY_MAX_PORTS);
635 make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK,
636 UID_UUCP, GID_DIALER, 0660, "cuac%r%r", adapter,
637 unit % CY_MAX_PORTS);
638 make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK | CONTROL_INIT_STATE,
639 UID_UUCP, GID_DIALER, 0660, "cuaic%r%r", adapter,
640 unit % CY_MAX_PORTS);
641 make_dev(&sio_cdevsw, minorbase | CALLOUT_MASK | CONTROL_LOCK_STATE,
642 UID_UUCP, GID_DIALER, 0660, "cualc%r%r", adapter,
643 unit % CY_MAX_PORTS);
647 /* ensure an edge for the next interrupt */
648 cy_outb(cy_iobase, CY_CLEAR_INTR, cy_align, 0);
654 sioopen(dev, flag, mode, p)
668 unit = MINOR_TO_UNIT(mynor);
669 if ((u_int) unit >= NSIO || (com = com_addr(unit)) == NULL)
671 if (mynor & CONTROL_MASK)
674 tp = com->tp = sio_tty[unit] = ttymalloc(sio_tty[unit]);
676 tp = com->tp = &sio_tty[unit];
681 * We jump to this label after all non-interrupted sleeps to pick
682 * up any changes of the device state.
685 while (com->state & CS_DTR_OFF) {
686 error = tsleep(&com->dtr_wait, TTIPRI | PCATCH, "cydtr", 0);
690 if (tp->t_state & TS_ISOPEN) {
692 * The device is open, so everything has been initialized.
695 if (mynor & CALLOUT_MASK) {
696 if (!com->active_out) {
701 if (com->active_out) {
702 if (flag & O_NONBLOCK) {
706 error = tsleep(&com->active_out,
707 TTIPRI | PCATCH, "cybi", 0);
713 if (tp->t_state & TS_XCLUDE &&
720 * The device isn't open, so there are no conflicts.
721 * Initialize it. Initialization is done twice in many
722 * cases: to preempt sleeping callin opens if we are
723 * callout, and to complete a callin open after DCD rises.
725 tp->t_oproc = comstart;
726 tp->t_stop = comstop;
727 tp->t_param = comparam;
729 tp->t_termios = mynor & CALLOUT_MASK
730 ? com->it_out : com->it_in;
732 /* Encode per-board unit in LIVR for access in intr routines. */
733 cd_setreg(com, CD1400_LIVR,
734 (unit & CD1400_xIVR_CHAN) << CD1400_xIVR_CHAN_SHIFT);
736 (void)commctl(com, TIOCM_DTR | TIOCM_RTS, DMSET);
738 com->poll = com->no_irq;
739 com->poll_output = com->loses_outints;
742 error = comparam(tp, &tp->t_termios);
749 * (Re)enable and flush fifos.
751 * Certain SMC chips cause problems if the fifos
752 * are enabled while input is ready. Turn off the
753 * fifo if necessary to clear the input. We test
754 * the input ready bit after enabling the fifos
755 * since we've already enabled them in comparam()
756 * and to handle races between enabling and fresh
760 outb(iobase + com_fifo,
761 FIFO_RCV_RST | FIFO_XMT_RST
764 if (!(inb(com->line_status_port) & LSR_RXRDY))
766 outb(iobase + com_fifo, 0);
768 (void) inb(com->data_port);
773 (void) inb(com->line_status_port);
774 (void) inb(com->data_port);
775 com->prev_modem_status = com->last_modem_status
776 = inb(com->modem_status_port);
777 outb(iobase + com_ier, IER_ERXRDY | IER_ETXRDY | IER_ERLS
782 * Flush fifos. This requires a full channel reset which
783 * also disables the transmitter and receiver. Recover
786 cd1400_channel_cmd(com,
787 CD1400_CCR_CMDRESET | CD1400_CCR_CHANRESET);
788 cd1400_channel_cmd(com, com->channel_control);
791 com->prev_modem_status = com->last_modem_status
792 = cd_getreg(com, CD1400_MSVR2);
793 cd_setreg(com, CD1400_SRER,
795 = CD1400_SRER_MDMCH | CD1400_SRER_RXDATA);
799 * Handle initial DCD. Callout devices get a fake initial
800 * DCD (trapdoor DCD). If we are callout, then any sleeping
801 * callin opens get woken up and resume sleeping on "cybi"
802 * instead of "cydcd".
805 * XXX `mynor & CALLOUT_MASK' should be
806 * `tp->t_cflag & (SOFT_CARRIER | TRAPDOOR_CARRIER) where
807 * TRAPDOOR_CARRIER is the default initial state for callout
808 * devices and SOFT_CARRIER is like CLOCAL except it hides
811 if (com->prev_modem_status & MSR_DCD || mynor & CALLOUT_MASK)
812 (*linesw[tp->t_line].l_modem)(tp, 1);
815 * Wait for DCD if necessary.
817 if (!(tp->t_state & TS_CARR_ON) && !(mynor & CALLOUT_MASK)
818 && !(tp->t_cflag & CLOCAL) && !(flag & O_NONBLOCK)) {
820 error = tsleep(TSA_CARR_ON(tp), TTIPRI | PCATCH, "cydcd", 0);
826 error = (*linesw[tp->t_line].l_open)(dev, tp);
827 disc_optim(tp, &tp->t_termios, com);
828 if (tp->t_state & TS_ISOPEN && mynor & CALLOUT_MASK)
829 com->active_out = TRUE;
833 if (!(tp->t_state & TS_ISOPEN) && com->wopeners == 0)
839 sioclose(dev, flag, mode, p)
851 if (mynor & CONTROL_MASK)
853 com = com_addr(MINOR_TO_UNIT(mynor));
856 cd_etc(com, CD1400_ETC_STOPBREAK);
857 (*linesw[tp->t_line].l_close)(tp, flag);
858 disc_optim(tp, &tp->t_termios, com);
859 comstop(tp, FREAD | FWRITE);
864 #ifdef broken /* session holds a ref to the tty; can't deallocate */
866 com->tp = sio_tty[unit] = NULL;
881 iobase = com->iobase;
885 com->poll_output = FALSE;
887 com->do_timestamp = 0;
889 outb(iobase + com_cfcr, com->cfcr_image &= ~CFCR_SBREAK);
894 cd_setreg(com, CD1400_COR2, com->cor[1] &= ~CD1400_COR2_ETC);
896 cd1400_channel_cmd(com, CD1400_CCR_CMDRESET | CD1400_CCR_FTF);
901 outb(iobase + com_ier, 0);
904 cd_setreg(com, CD1400_SRER, com->intr_enable = 0);
908 if ((tp->t_cflag & HUPCL)
910 * XXX we will miss any carrier drop between here and the
911 * next open. Perhaps we should watch DCD even when the
912 * port is closed; it is not sufficient to check it at
913 * the next open because it might go up and down while
914 * we're not watching.
917 && !(com->prev_modem_status & MSR_DCD)
918 && !(com->it_in.c_cflag & CLOCAL))
919 || !(tp->t_state & TS_ISOPEN)) {
920 (void)commctl(com, TIOCM_DTR, DMBIC);
922 /* Disable receiver (leave transmitter enabled). */
923 com->channel_control = CD1400_CCR_CMDCHANCTL
926 cd1400_channel_cmd(com, com->channel_control);
928 if (com->dtr_wait != 0 && !(com->state & CS_DTR_OFF)) {
929 timeout(siodtrwakeup, com, com->dtr_wait);
930 com->state |= CS_DTR_OFF;
937 * Disable fifos so that they are off after controlled
938 * reboots. Some BIOSes fail to detect 16550s when the
941 outb(iobase + com_fifo, 0);
944 com->active_out = FALSE;
945 wakeup(&com->active_out);
946 wakeup(TSA_CARR_ON(tp)); /* restart any wopeners */
951 siowrite(dev, uio, flag)
961 if (mynor & CONTROL_MASK)
964 unit = MINOR_TO_UNIT(mynor);
965 tp = com_addr(unit)->tp;
967 * (XXX) We disallow virtual consoles if the physical console is
968 * a serial port. This is in case there is a display attached that
969 * is not the console. In that situation we don't need/want the X
970 * server taking over the console.
972 if (constty != NULL && unit == comconsole)
975 /* XXX duplicate ttwrite(), but without so much output processing on
976 * CR & LF chars. Hardly worth the effort, given that high-throughput
977 * sessions are raw anyhow.
980 return ((*linesw[tp->t_line].l_write)(tp, uio, flag));
990 com = (struct com_s *)chan;
991 com->state &= ~CS_DTR_OFF;
992 wakeup(&com->dtr_wait);
1007 if (!(tp->t_state & TS_ISOPEN)) {
1008 com_events -= (com->iptr - com->ibuf);
1009 com->iptr = com->ibuf;
1012 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
1014 * Avoid the grotesquely inefficient lineswitch routine
1015 * (ttyinput) in "raw" mode. It usually takes about 450
1016 * instructions (that's without canonical processing or echo!).
1017 * slinput is reasonably fast (usually 40 instructions plus
1022 incc = com->iptr - buf;
1023 if (tp->t_rawq.c_cc + incc > tp->t_ihiwat
1024 && (com->state & CS_RTS_IFLOW
1025 || tp->t_iflag & IXOFF)
1026 && !(tp->t_state & TS_TBLOCK))
1028 com->delta_error_counts[CE_TTY_BUF_OVERFLOW]
1029 += b_to_q((char *)buf, incc, &tp->t_rawq);
1033 tp->t_rawcc += incc;
1035 if (tp->t_state & TS_TTSTOP
1036 && (tp->t_iflag & IXANY
1037 || tp->t_cc[VSTART] == tp->t_cc[VSTOP])) {
1038 tp->t_state &= ~TS_TTSTOP;
1039 tp->t_lflag &= ~FLUSHO;
1043 } while (buf < com->iptr);
1047 line_status = buf[com->ierroff];
1050 & (LSR_BI | LSR_FE | LSR_OE | LSR_PE)) {
1051 if (line_status & LSR_BI)
1052 recv_data |= TTY_BI;
1053 if (line_status & LSR_FE)
1054 recv_data |= TTY_FE;
1055 if (line_status & LSR_OE)
1056 recv_data |= TTY_OE;
1057 if (line_status & LSR_PE)
1058 recv_data |= TTY_PE;
1060 (*linesw[tp->t_line].l_rint)(recv_data, tp);
1062 } while (buf < com->iptr);
1064 com_events -= (com->iptr - com->ibuf);
1065 com->iptr = com->ibuf;
1068 * There is now room for another low-level buffer full of input,
1069 * so enable RTS if it is now disabled and there is room in the
1070 * high-level buffer.
1072 if ((com->state & CS_RTS_IFLOW) && !(com->mcr_image & com->mcr_rts) &&
1073 !(tp->t_state & TS_TBLOCK))
1075 outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
1077 cd_setreg(com, com->mcr_rts_reg,
1078 com->mcr_image |= com->mcr_rts);
1093 COM_LOCK(); /* XXX could this be placed down lower in the loop? */
1095 baseu = unit * CY_MAX_PORTS;
1096 cy_align = com_addr(baseu)->cy_align;
1097 cy_iobase = com_addr(baseu)->cy_iobase;
1099 /* check each CD1400 in turn */
1100 for (cyu = 0; cyu < cy_nr_cd1400s[unit]; ++cyu) {
1101 iobase = (cy_addr) (cy_iobase
1102 + (cy_chip_offset[cyu] << cy_align));
1103 /* poll to see if it has any work */
1104 status = cd_inb(iobase, CD1400_SVRR, cy_align);
1110 /* service requests as appropriate, giving priority to RX */
1111 if (status & CD1400_SVRR_RXRDY) {
1123 save_rir = cd_inb(iobase, CD1400_RIR, cy_align);
1125 /* enter rx service */
1126 cd_outb(iobase, CD1400_CAR, cy_align, save_rir);
1127 com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS)->car
1128 = save_rir & CD1400_CAR_CHAN;
1130 serv_type = cd_inb(iobase, CD1400_RIVR, cy_align);
1131 com = com_addr(baseu
1132 + ((serv_type >> CD1400_xIVR_CHAN_SHIFT)
1133 & CD1400_xIVR_CHAN));
1135 /* ack receive service */
1136 serv_type = cy_inb(iobase, CY8_SVCACKR, cy_align);
1138 com = com_addr(baseu +
1139 + ((serv_type >> CD1400_xIVR_CHAN_SHIFT)
1140 & CD1400_xIVR_CHAN));
1143 if (serv_type & CD1400_RIVR_EXCEPTION) {
1144 ++com->recv_exception;
1145 line_status = cd_inb(iobase, CD1400_RDSR, cy_align);
1146 /* break/unnattached error bits or real input? */
1147 recv_data = cd_inb(iobase, CD1400_RDSR, cy_align);
1148 #ifndef SOFT_HOTCHAR
1149 if (line_status & CD1400_RDSR_SPECIAL
1150 && com->hotchar != 0)
1153 #if 1 /* XXX "intelligent" PFO error handling would break O error handling */
1154 if (line_status & (LSR_PE|LSR_FE|LSR_BI)) {
1156 Don't store PE if IGNPAR and BI if IGNBRK,
1157 this hack allows "raw" tty optimization
1158 works even if IGN* is set.
1160 if ( com->tp == NULL
1161 || !(com->tp->t_state & TS_ISOPEN)
1162 || ((line_status & (LSR_PE|LSR_FE))
1163 && (com->tp->t_iflag & IGNPAR))
1164 || ((line_status & LSR_BI)
1165 && (com->tp->t_iflag & IGNBRK)))
1167 if ( (line_status & (LSR_PE|LSR_FE))
1168 && (com->tp->t_state & TS_CAN_BYPASS_L_RINT)
1169 && ((line_status & LSR_FE)
1170 || ((line_status & LSR_PE)
1171 && (com->tp->t_iflag & INPCK))))
1177 if (com->hotchar != 0 && recv_data == com->hotchar)
1181 if (ioptr >= com->ibufend)
1182 CE_RECORD(com, CE_INTERRUPT_BUF_OVERFLOW);
1184 if (com->do_timestamp)
1185 microtime(&com->timestamp);
1187 ioptr[0] = recv_data;
1188 ioptr[com->ierroff] = line_status;
1189 com->iptr = ++ioptr;
1190 if (ioptr == com->ihighwater
1191 && com->state & CS_RTS_IFLOW)
1193 outb(com->modem_ctl_port,
1194 com->mcr_image &= ~MCR_RTS);
1196 cd_outb(iobase, com->mcr_rts_reg,
1201 if (line_status & LSR_OE)
1202 CE_RECORD(com, CE_OVERRUN);
1208 count = cd_inb(iobase, CD1400_RDCR, cy_align);
1211 com->bytes_in += count;
1213 ifree = com->ibufend - ioptr;
1214 if (count > ifree) {
1216 com_events += ifree;
1218 if (com->do_timestamp)
1219 microtime(&com->timestamp);
1221 recv_data = cd_inb(iobase,
1225 if (com->hotchar != 0
1230 ioptr[0] = recv_data;
1231 ioptr[com->ierroff] = 0;
1233 } while (--ifree != 0);
1235 com->delta_error_counts
1236 [CE_INTERRUPT_BUF_OVERFLOW] += count;
1238 recv_data = cd_inb(iobase, CD1400_RDSR,
1241 if (com->hotchar != 0
1242 && recv_data == com->hotchar)
1245 } while (--count != 0);
1247 if (com->do_timestamp)
1248 microtime(&com->timestamp);
1249 if (ioptr <= com->ihighwater
1250 && ioptr + count > com->ihighwater
1251 && com->state & CS_RTS_IFLOW)
1253 outb(com->modem_ctl_port,
1254 com->mcr_image &= ~MCR_RTS);
1256 cd_outb(iobase, com->mcr_rts_reg,
1261 com_events += count;
1263 recv_data = cd_inb(iobase, CD1400_RDSR,
1266 if (com->hotchar != 0
1267 && recv_data == com->hotchar)
1270 ioptr[0] = recv_data;
1271 ioptr[com->ierroff] = 0;
1273 } while (--count != 0);
1279 /* terminate service context */
1281 cd_outb(iobase, CD1400_RIR, cy_align,
1283 & ~(CD1400_RIR_RDIREQ | CD1400_RIR_RBUSY));
1285 cd_outb(iobase, CD1400_EOSRR, cy_align, 0);
1288 if (status & CD1400_SVRR_MDMCH) {
1290 u_char modem_status;
1298 save_mir = cd_inb(iobase, CD1400_MIR, cy_align);
1300 /* enter modem service */
1301 cd_outb(iobase, CD1400_CAR, cy_align, save_mir);
1302 com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS)->car
1303 = save_mir & CD1400_CAR_CHAN;
1305 com = com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS
1306 + (save_mir & CD1400_MIR_CHAN));
1308 /* ack modem service */
1309 vector = cy_inb(iobase, CY8_SVCACKM, cy_align);
1311 com = com_addr(baseu
1312 + ((vector >> CD1400_xIVR_CHAN_SHIFT)
1313 & CD1400_xIVR_CHAN));
1316 modem_status = cd_inb(iobase, CD1400_MSVR2, cy_align);
1317 if (modem_status != com->last_modem_status) {
1318 if (com->do_dcd_timestamp
1319 && !(com->last_modem_status & MSR_DCD)
1320 && modem_status & MSR_DCD)
1321 microtime(&com->dcd_timestamp);
1324 * Schedule high level to handle DCD changes. Note
1325 * that we don't use the delta bits anywhere. Some
1326 * UARTs mess them up, and it's easy to remember the
1327 * previous bits and calculate the delta.
1329 com->last_modem_status = modem_status;
1330 if (!(com->state & CS_CHECKMSR)) {
1331 com_events += LOTS_OF_EVENTS;
1332 com->state |= CS_CHECKMSR;
1336 #ifdef SOFT_CTS_OFLOW
1337 /* handle CTS change immediately for crisp flow ctl */
1338 if (com->state & CS_CTS_OFLOW) {
1339 if (modem_status & MSR_CTS) {
1340 com->state |= CS_ODEVREADY;
1341 if (com->state >= (CS_BUSY | CS_TTGO
1343 && !(com->intr_enable
1344 & CD1400_SRER_TXRDY))
1345 cd_outb(iobase, CD1400_SRER,
1349 & ~CD1400_SRER_TXMPTY
1350 | CD1400_SRER_TXRDY);
1352 com->state &= ~CS_ODEVREADY;
1353 if (com->intr_enable
1354 & CD1400_SRER_TXRDY)
1355 cd_outb(iobase, CD1400_SRER,
1359 & ~CD1400_SRER_TXRDY
1360 | CD1400_SRER_TXMPTY);
1366 /* terminate service context */
1368 cd_outb(iobase, CD1400_MIR, cy_align,
1370 & ~(CD1400_MIR_RDIREQ | CD1400_MIR_RBUSY));
1372 cd_outb(iobase, CD1400_EOSRR, cy_align, 0);
1375 if (status & CD1400_SVRR_TXRDY) {
1384 save_tir = cd_inb(iobase, CD1400_TIR, cy_align);
1386 /* enter tx service */
1387 cd_outb(iobase, CD1400_CAR, cy_align, save_tir);
1388 com_addr(baseu + cyu * CD1400_NO_OF_CHANNELS)->car
1389 = save_tir & CD1400_CAR_CHAN;
1391 com = com_addr(baseu
1392 + cyu * CD1400_NO_OF_CHANNELS
1393 + (save_tir & CD1400_TIR_CHAN));
1395 /* ack transmit service */
1396 vector = cy_inb(iobase, CY8_SVCACKT, cy_align);
1398 com = com_addr(baseu
1399 + ((vector >> CD1400_xIVR_CHAN_SHIFT)
1400 & CD1400_xIVR_CHAN));
1403 if (com->etc != ETC_NONE) {
1404 if (com->intr_enable & CD1400_SRER_TXRDY) {
1406 * Here due to sloppy SRER_TXRDY
1407 * enabling. Ignore. Come back when
1410 cd_outb(iobase, CD1400_SRER, cy_align,
1413 & ~CD1400_SRER_TXRDY)
1414 | CD1400_SRER_TXMPTY);
1415 goto terminate_tx_service;
1418 case CD1400_ETC_SENDBREAK:
1419 case CD1400_ETC_STOPBREAK:
1421 * Start the command. Come back on
1422 * next tx empty interrupt, hopefully
1423 * after command has been executed.
1425 cd_outb(iobase, CD1400_COR2, cy_align,
1426 com->cor[1] |= CD1400_COR2_ETC);
1427 cd_outb(iobase, CD1400_TDR, cy_align,
1429 cd_outb(iobase, CD1400_TDR, cy_align,
1431 if (com->etc == CD1400_ETC_SENDBREAK)
1432 com->etc = ETC_BREAK_STARTING;
1434 com->etc = ETC_BREAK_ENDING;
1435 goto terminate_tx_service;
1436 case ETC_BREAK_STARTING:
1438 * BREAK is now on. Continue with
1439 * SRER_TXMPTY processing, hopefully
1442 com->etc = ETC_BREAK_STARTED;
1444 case ETC_BREAK_STARTED:
1446 * Came back due to sloppy SRER_TXMPTY
1447 * enabling. Hope again.
1450 case ETC_BREAK_ENDING:
1452 * BREAK is now off. Continue with
1453 * SRER_TXMPTY processing and don't
1454 * come back. The SWI handler will
1455 * restart tx interrupts if necessary.
1457 cd_outb(iobase, CD1400_COR2, cy_align,
1459 &= ~CD1400_COR2_ETC);
1460 com->etc = ETC_BREAK_ENDED;
1461 if (!(com->state & CS_ODONE)) {
1462 com_events += LOTS_OF_EVENTS;
1463 com->state |= CS_ODONE;
1467 case ETC_BREAK_ENDED:
1469 * Shouldn't get here. Hope again.
1474 if (com->intr_enable & CD1400_SRER_TXMPTY) {
1475 if (!(com->extra_state & CSE_ODONE)) {
1476 com_events += LOTS_OF_EVENTS;
1477 com->extra_state |= CSE_ODONE;
1480 cd_outb(iobase, CD1400_SRER, cy_align,
1482 &= ~CD1400_SRER_TXMPTY);
1483 goto terminate_tx_service;
1485 if (com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)) {
1489 ioptr = com->obufq.l_head;
1490 ocount = com->obufq.l_tail - ioptr;
1491 if (ocount > CD1400_TX_FIFO_SIZE)
1492 ocount = CD1400_TX_FIFO_SIZE;
1493 com->bytes_out += ocount;
1495 cd_outb(iobase, CD1400_TDR, cy_align,
1497 while (--ocount != 0);
1498 com->obufq.l_head = ioptr;
1499 if (ioptr >= com->obufq.l_tail) {
1502 qp = com->obufq.l_next;
1503 qp->l_queued = FALSE;
1506 com->obufq.l_head = qp->l_head;
1507 com->obufq.l_tail = qp->l_tail;
1508 com->obufq.l_next = qp;
1510 /* output just completed */
1511 com->state &= ~CS_BUSY;
1514 * The setting of CSE_ODONE may be
1515 * stale here. We currently only
1516 * use it when CS_BUSY is set, and
1517 * fixing it when we clear CS_BUSY
1520 if (com->extra_state & CSE_ODONE) {
1521 com_events -= LOTS_OF_EVENTS;
1522 com->extra_state &= ~CSE_ODONE;
1525 cd_outb(iobase, CD1400_SRER, cy_align,
1528 & ~CD1400_SRER_TXRDY)
1529 | CD1400_SRER_TXMPTY);
1531 if (!(com->state & CS_ODONE)) {
1532 com_events += LOTS_OF_EVENTS;
1533 com->state |= CS_ODONE;
1535 /* handle at high level ASAP */
1541 /* terminate service context */
1542 terminate_tx_service:
1544 cd_outb(iobase, CD1400_TIR, cy_align,
1546 & ~(CD1400_TIR_RDIREQ | CD1400_TIR_RBUSY));
1548 cd_outb(iobase, CD1400_EOSRR, cy_align, 0);
1553 /* ensure an edge for the next interrupt */
1554 cy_outb(cy_iobase, CY_CLEAR_INTR, cy_align, 0);
1570 sioioctl(dev, cmd, data, flag, p)
1582 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1584 struct termios term;
1588 com = com_addr(MINOR_TO_UNIT(mynor));
1589 if (mynor & CONTROL_MASK) {
1592 switch (mynor & CONTROL_MASK) {
1593 case CONTROL_INIT_STATE:
1594 ct = mynor & CALLOUT_MASK ? &com->it_out : &com->it_in;
1596 case CONTROL_LOCK_STATE:
1597 ct = mynor & CALLOUT_MASK ? &com->lt_out : &com->lt_in;
1600 return (ENODEV); /* /dev/nodev */
1607 *ct = *(struct termios *)data;
1610 *(struct termios *)data = *ct;
1613 *(int *)data = TTYDISC;
1616 bzero(data, sizeof(struct winsize));
1623 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1624 term = tp->t_termios;
1626 error = ttsetcompat(tp, &cmd, data, &term);
1630 data = (caddr_t)&term;
1632 if (cmd == TIOCSETA || cmd == TIOCSETAW || cmd == TIOCSETAF) {
1634 struct termios *dt = (struct termios *)data;
1635 struct termios *lt = mynor & CALLOUT_MASK
1636 ? &com->lt_out : &com->lt_in;
1638 dt->c_iflag = (tp->t_iflag & lt->c_iflag)
1639 | (dt->c_iflag & ~lt->c_iflag);
1640 dt->c_oflag = (tp->t_oflag & lt->c_oflag)
1641 | (dt->c_oflag & ~lt->c_oflag);
1642 dt->c_cflag = (tp->t_cflag & lt->c_cflag)
1643 | (dt->c_cflag & ~lt->c_cflag);
1644 dt->c_lflag = (tp->t_lflag & lt->c_lflag)
1645 | (dt->c_lflag & ~lt->c_lflag);
1646 for (cc = 0; cc < NCCS; ++cc)
1647 if (lt->c_cc[cc] != 0)
1648 dt->c_cc[cc] = tp->t_cc[cc];
1649 if (lt->c_ispeed != 0)
1650 dt->c_ispeed = tp->t_ispeed;
1651 if (lt->c_ospeed != 0)
1652 dt->c_ospeed = tp->t_ospeed;
1654 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
1655 if (error != ENOIOCTL)
1658 error = ttioctl(tp, cmd, data, flag);
1659 disc_optim(tp, &tp->t_termios, com);
1660 if (error != ENOIOCTL) {
1667 outb(iobase + com_cfcr, com->cfcr_image |= CFCR_SBREAK);
1669 cd_etc(com, CD1400_ETC_SENDBREAK);
1674 outb(iobase + com_cfcr, com->cfcr_image &= ~CFCR_SBREAK);
1676 cd_etc(com, CD1400_ETC_STOPBREAK);
1680 (void)commctl(com, TIOCM_DTR, DMBIS);
1683 (void)commctl(com, TIOCM_DTR, DMBIC);
1686 * XXX should disallow changing MCR_RTS if CS_RTS_IFLOW is set. The
1687 * changes get undone on the next call to comparam().
1690 (void)commctl(com, *(int *)data, DMSET);
1693 (void)commctl(com, *(int *)data, DMBIS);
1696 (void)commctl(com, *(int *)data, DMBIC);
1699 *(int *)data = commctl(com, 0, DMGET);
1702 /* must be root since the wait applies to following logins */
1708 com->dtr_wait = *(int *)data * hz / 100;
1711 *(int *)data = com->dtr_wait * 100 / hz;
1714 com->do_timestamp = TRUE;
1715 *(struct timeval *)data = com->timestamp;
1717 case TIOCDCDTIMESTAMP:
1718 com->do_dcd_timestamp = TRUE;
1719 *(struct timeval *)data = com->dcd_timestamp;
1737 if (com_events == 0)
1740 for (unit = 0; unit < NSIO; ++unit) {
1745 com = com_addr(unit);
1751 * XXX forget any events related to closed devices
1752 * (actually never opened devices) so that we don't
1756 incc = com->iptr - com->ibuf;
1757 com->iptr = com->ibuf;
1758 if (com->state & CS_CHECKMSR) {
1759 incc += LOTS_OF_EVENTS;
1760 com->state &= ~CS_CHECKMSR;
1766 "sio%d: %d events for device with no tp\n",
1770 if (com->iptr != com->ibuf) {
1775 if (com->state & CS_CHECKMSR) {
1776 u_char delta_modem_status;
1779 delta_modem_status = com->last_modem_status
1780 ^ com->prev_modem_status;
1781 com->prev_modem_status = com->last_modem_status;
1782 com_events -= LOTS_OF_EVENTS;
1783 com->state &= ~CS_CHECKMSR;
1785 if (delta_modem_status & MSR_DCD)
1786 (*linesw[tp->t_line].l_modem)
1787 (tp, com->prev_modem_status & MSR_DCD);
1789 if (com->extra_state & CSE_ODONE) {
1791 com_events -= LOTS_OF_EVENTS;
1792 com->extra_state &= ~CSE_ODONE;
1794 if (!(com->state & CS_BUSY)) {
1795 tp->t_state &= ~TS_BUSY;
1798 if (com->etc != ETC_NONE) {
1799 if (com->etc == ETC_BREAK_ENDED)
1800 com->etc = ETC_NONE;
1804 if (com->state & CS_ODONE) {
1806 com_events -= LOTS_OF_EVENTS;
1807 com->state &= ~CS_ODONE;
1809 (*linesw[tp->t_line].l_start)(tp);
1811 if (com_events == 0)
1814 if (com_events >= LOTS_OF_EVENTS)
1838 /* do historical conversions */
1839 if (t->c_ispeed == 0)
1840 t->c_ispeed = t->c_ospeed;
1842 unit = DEV_TO_UNIT(tp->t_dev);
1843 com = com_addr(unit);
1845 /* check requested parameters */
1846 cy_clock = CY_CLOCK(com->gfrcr_image);
1847 idivisor = comspeed(t->c_ispeed, cy_clock, &iprescaler);
1850 odivisor = comspeed(t->c_ospeed, cy_clock, &oprescaler);
1854 /* parameters are OK, convert them to the com struct and the device */
1857 (void)commctl(com, TIOCM_DTR, DMBIC); /* hang up line */
1859 (void)commctl(com, TIOCM_DTR, DMBIS);
1862 * This returns with interrupts disabled so that we can complete
1863 * the speed change atomically.
1865 (void) siosetwater(com, t->c_ispeed);
1867 /* XXX we don't actually change the speed atomically. */
1870 if (idivisor != 0) {
1871 cd_setreg(com, CD1400_RBPR, idivisor);
1872 cd_setreg(com, CD1400_RCOR, iprescaler);
1874 if (odivisor != 0) {
1875 cd_setreg(com, CD1400_TBPR, odivisor);
1876 cd_setreg(com, CD1400_TCOR, oprescaler);
1882 * transmitter enable (always set)
1885 opt = CD1400_CCR_CMDCHANCTL | CD1400_CCR_XMTEN
1886 | (cflag & CREAD ? CD1400_CCR_RCVEN : CD1400_CCR_RCVDIS);
1887 if (opt != com->channel_control) {
1888 com->channel_control = opt;
1889 cd1400_channel_cmd(com, opt);
1893 /* set special chars */
1894 /* XXX if one is _POSIX_VDISABLE, can't use some others */
1895 if (t->c_cc[VSTOP] != _POSIX_VDISABLE)
1896 cd_setreg(com, CD1400_SCHR1, t->c_cc[VSTOP]);
1897 if (t->c_cc[VSTART] != _POSIX_VDISABLE)
1898 cd_setreg(com, CD1400_SCHR2, t->c_cc[VSTART]);
1899 if (t->c_cc[VINTR] != _POSIX_VDISABLE)
1900 cd_setreg(com, CD1400_SCHR3, t->c_cc[VINTR]);
1901 if (t->c_cc[VSUSP] != _POSIX_VDISABLE)
1902 cd_setreg(com, CD1400_SCHR4, t->c_cc[VSUSP]);
1906 * set channel option register 1 -
1913 if (cflag & PARENB) {
1915 opt |= CD1400_COR1_PARODD;
1916 opt |= CD1400_COR1_PARNORMAL;
1919 if (!(iflag & INPCK))
1920 opt |= CD1400_COR1_NOINPCK;
1923 if (cflag & CSTOPB) {
1925 opt |= CD1400_COR1_STOP2;
1928 switch (cflag & CSIZE) {
1931 opt |= CD1400_COR1_CS5;
1935 opt |= CD1400_COR1_CS6;
1939 opt |= CD1400_COR1_CS7;
1943 opt |= CD1400_COR1_CS8;
1947 if (opt != com->cor[0]) {
1948 cor_change |= CD1400_CCR_COR1;
1949 cd_setreg(com, CD1400_COR1, com->cor[0] = opt);
1953 * Set receive time-out period, normally to max(one char time, 5 ms).
1955 if (t->c_ispeed == 0)
1956 itimeout = cd_getreg(com, CD1400_RTPR);
1958 itimeout = (1000 * bits + t->c_ispeed - 1) / t->c_ispeed;
1964 if (itimeout < MIN_RTP)
1967 if (!(t->c_lflag & ICANON) && t->c_cc[VMIN] != 0 && t->c_cc[VTIME] != 0
1968 && t->c_cc[VTIME] * 10 > itimeout)
1969 itimeout = t->c_cc[VTIME] * 10;
1972 cd_setreg(com, CD1400_RTPR, itimeout);
1975 * set channel option register 2 -
1981 opt |= CD1400_COR2_IXANY;
1983 opt |= CD1400_COR2_IXOFF;
1985 #ifndef SOFT_CTS_OFLOW
1986 if (cflag & CCTS_OFLOW)
1987 opt |= CD1400_COR2_CCTS_OFLOW;
1990 if (opt != com->cor[1]) {
1991 cor_change |= CD1400_CCR_COR2;
1992 cd_setreg(com, CD1400_COR2, com->cor[1] = opt);
1997 * set channel option register 3 -
1998 * receiver FIFO interrupt threshold
2001 opt = RxFifoThreshold;
2003 if (t->c_lflag & ICANON)
2004 opt |= CD1400_COR3_SCD34; /* detect INTR & SUSP chars */
2006 /* detect and transparently handle START and STOP chars */
2007 opt |= CD1400_COR3_FCT | CD1400_COR3_SCD12;
2009 if (opt != com->cor[2]) {
2010 cor_change |= CD1400_CCR_COR3;
2011 cd_setreg(com, CD1400_COR3, com->cor[2] = opt);
2014 /* notify the CD1400 if COR1-3 have changed */
2016 cd1400_channel_cmd(com, CD1400_CCR_CMDCORCHG | cor_change);
2019 * set channel option register 4 -
2022 * received exception processing
2026 opt |= CD1400_COR4_IGNCR;
2029 * we need a new ttyinput() for this, as we don't want to
2030 * have ICRNL && INLCR being done in both layers, or to have
2031 * synchronisation problems
2034 opt |= CD1400_COR4_ICRNL;
2036 opt |= CD1400_COR4_INLCR;
2039 opt |= CD1400_COR4_IGNBRK | CD1400_COR4_NOBRKINT;
2041 * The `-ignbrk -brkint parmrk' case is not handled by the hardware,
2042 * so only tell the hardware about -brkint if -parmrk.
2044 if (!(iflag & (BRKINT | PARMRK)))
2045 opt |= CD1400_COR4_NOBRKINT;
2047 /* XXX using this "intelligence" breaks reporting of overruns. */
2049 opt |= CD1400_COR4_PFO_DISCARD;
2052 opt |= CD1400_COR4_PFO_ESC;
2054 opt |= CD1400_COR4_PFO_NUL;
2057 opt |= CD1400_COR4_PFO_EXCEPTION;
2059 cd_setreg(com, CD1400_COR4, opt);
2062 * set channel option register 5 -
2066 opt |= CD1400_COR5_ISTRIP;
2067 if (t->c_iflag & IEXTEN)
2068 /* enable LNEXT (e.g. ctrl-v quoting) handling */
2069 opt |= CD1400_COR5_LNEXT;
2071 if (t->c_oflag & ONLCR)
2072 opt |= CD1400_COR5_ONLCR;
2073 if (t->c_oflag & OCRNL)
2074 opt |= CD1400_COR5_OCRNL;
2076 cd_setreg(com, CD1400_COR5, opt);
2079 * We always generate modem status change interrupts for CD changes.
2080 * Among other things, this is necessary to track TS_CARR_ON for
2081 * pstat to print even when the driver doesn't care. CD changes
2082 * should be rare so interrupts for them are not worth extra code to
2083 * avoid. We avoid interrupts for other modem status changes (except
2084 * for CTS changes when SOFT_CTS_OFLOW is configured) since this is
2085 * simplest and best.
2089 * set modem change option register 1
2090 * generate modem interrupts on which 1 -> 0 input transitions
2091 * also controls auto-DTR output flow-control, which we don't use
2093 opt = CD1400_MCOR1_CDzd;
2094 #ifdef SOFT_CTS_OFLOW
2095 if (cflag & CCTS_OFLOW)
2096 opt |= CD1400_MCOR1_CTSzd;
2098 cd_setreg(com, CD1400_MCOR1, opt);
2101 * set modem change option register 2
2102 * generate modem interrupts on specific 0 -> 1 input transitions
2104 opt = CD1400_MCOR2_CDod;
2105 #ifdef SOFT_CTS_OFLOW
2106 if (cflag & CCTS_OFLOW)
2107 opt |= CD1400_MCOR2_CTSod;
2109 cd_setreg(com, CD1400_MCOR2, opt);
2112 * XXX should have done this long ago, but there is too much state
2113 * to change all atomically.
2117 com->state &= ~CS_TTGO;
2118 if (!(tp->t_state & TS_TTSTOP))
2119 com->state |= CS_TTGO;
2120 if (cflag & CRTS_IFLOW) {
2121 com->state |= CS_RTS_IFLOW;
2123 * If CS_RTS_IFLOW just changed from off to on, the change
2124 * needs to be propagated to MCR_RTS. This isn't urgent,
2125 * so do it later by calling comstart() instead of repeating
2126 * a lot of code from comstart() here.
2128 } else if (com->state & CS_RTS_IFLOW) {
2129 com->state &= ~CS_RTS_IFLOW;
2131 * CS_RTS_IFLOW just changed from on to off. Force MCR_RTS
2132 * on here, since comstart() won't do it later.
2135 outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
2137 cd_setreg(com, com->mcr_rts_reg,
2138 com->mcr_image |= com->mcr_rts);
2143 * Set up state to handle output flow control.
2144 * XXX - worth handling MDMBUF (DCD) flow control at the lowest level?
2145 * Now has 10+ msec latency, while CTS flow has 50- usec latency.
2147 com->state |= CS_ODEVREADY;
2148 #ifdef SOFT_CTS_OFLOW
2149 com->state &= ~CS_CTS_OFLOW;
2150 if (cflag & CCTS_OFLOW) {
2151 com->state |= CS_CTS_OFLOW;
2152 if (!(com->last_modem_status & MSR_CTS))
2153 com->state &= ~CS_ODEVREADY;
2156 /* XXX shouldn't call functions while intrs are disabled. */
2157 disc_optim(tp, t, com);
2160 * Recover from fiddling with CS_TTGO. We used to call siointr1()
2161 * unconditionally, but that defeated the careful discarding of
2162 * stale input in sioopen().
2164 if (com->state >= (CS_BUSY | CS_TTGO))
2167 if (com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)) {
2168 if (!(com->intr_enable & CD1400_SRER_TXRDY))
2169 cd_setreg(com, CD1400_SRER,
2171 = (com->intr_enable & ~CD1400_SRER_TXMPTY)
2172 | CD1400_SRER_TXRDY);
2174 if (com->intr_enable & CD1400_SRER_TXRDY)
2175 cd_setreg(com, CD1400_SRER,
2177 = (com->intr_enable & ~CD1400_SRER_TXRDY)
2178 | CD1400_SRER_TXMPTY);
2184 if (com->ibufold != NULL) {
2185 free(com->ibufold, M_DEVBUF);
2186 com->ibufold = NULL;
2192 siosetwater(com, speed)
2202 * Make the buffer size large enough to handle a softtty interrupt
2203 * latency of about 2 ticks without loss of throughput or data
2204 * (about 3 ticks if input flow control is not used or not honoured,
2205 * but a bit less for CS5-CS7 modes).
2207 cp4ticks = speed / 10 / hz * 4;
2208 for (ibufsize = 128; ibufsize < cp4ticks;)
2210 if (ibufsize == com->ibufsize) {
2216 * Allocate input buffer. The extra factor of 2 in the size is
2217 * to allow for an error byte for each input byte.
2219 ibuf = malloc(2 * ibufsize, M_DEVBUF, M_NOWAIT);
2225 /* Initialize non-critical variables. */
2226 com->ibufold = com->ibuf;
2227 com->ibufsize = ibufsize;
2230 tp->t_ififosize = 2 * ibufsize;
2231 tp->t_ispeedwat = (speed_t)-1;
2232 tp->t_ospeedwat = (speed_t)-1;
2236 * Read current input buffer, if any. Continue with interrupts
2240 if (com->iptr != com->ibuf)
2244 * Initialize critical variables, including input buffer watermarks.
2245 * The external device is asked to stop sending when the buffer
2246 * exactly reaches high water, or when the high level requests it.
2247 * The high level is notified immediately (rather than at a later
2248 * clock tick) when this watermark is reached.
2249 * The buffer size is chosen so the watermark should almost never
2251 * The low watermark is invisibly 0 since the buffer is always
2252 * emptied all at once.
2254 com->iptr = com->ibuf = ibuf;
2255 com->ibufend = ibuf + ibufsize;
2256 com->ierroff = ibufsize;
2257 com->ihighwater = ibuf + 3 * ibufsize / 4;
2272 unit = DEV_TO_UNIT(tp->t_dev);
2273 com = com_addr(unit);
2282 if (tp->t_state & TS_TTSTOP) {
2283 com->state &= ~CS_TTGO;
2284 if (com->intr_enable & CD1400_SRER_TXRDY)
2285 cd_setreg(com, CD1400_SRER,
2287 = (com->intr_enable & ~CD1400_SRER_TXRDY)
2288 | CD1400_SRER_TXMPTY);
2290 com->state |= CS_TTGO;
2291 if (com->state >= (CS_BUSY | CS_TTGO | CS_ODEVREADY)
2292 && !(com->intr_enable & CD1400_SRER_TXRDY))
2293 cd_setreg(com, CD1400_SRER,
2295 = (com->intr_enable & ~CD1400_SRER_TXMPTY)
2296 | CD1400_SRER_TXRDY);
2298 if (tp->t_state & TS_TBLOCK) {
2299 if (com->mcr_image & com->mcr_rts && com->state & CS_RTS_IFLOW)
2301 outb(com->modem_ctl_port, com->mcr_image &= ~MCR_RTS);
2303 cd_setreg(com, com->mcr_rts_reg,
2304 com->mcr_image &= ~com->mcr_rts);
2307 if (!(com->mcr_image & com->mcr_rts)
2308 && com->iptr < com->ihighwater
2309 && com->state & CS_RTS_IFLOW)
2311 outb(com->modem_ctl_port, com->mcr_image |= MCR_RTS);
2313 cd_setreg(com, com->mcr_rts_reg,
2314 com->mcr_image |= com->mcr_rts);
2318 if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
2323 if (tp->t_outq.c_cc != 0) {
2327 if (!com->obufs[0].l_queued) {
2331 com->obufs[0].l_tail
2332 = com->obuf1 + q_to_b(&tp->t_outq, com->obuf1,
2334 com->obufs[0].l_next = NULL;
2335 com->obufs[0].l_queued = TRUE;
2337 if (com->state & CS_BUSY) {
2338 qp = com->obufq.l_next;
2339 while ((next = qp->l_next) != NULL)
2341 qp->l_next = &com->obufs[0];
2343 com->obufq.l_head = com->obufs[0].l_head;
2344 com->obufq.l_tail = com->obufs[0].l_tail;
2345 com->obufq.l_next = &com->obufs[0];
2346 com->state |= CS_BUSY;
2347 if (com->state >= (CS_BUSY | CS_TTGO
2349 cd_setreg(com, CD1400_SRER,
2352 & ~CD1400_SRER_TXMPTY)
2353 | CD1400_SRER_TXRDY);
2357 if (tp->t_outq.c_cc != 0 && !com->obufs[1].l_queued) {
2361 com->obufs[1].l_tail
2362 = com->obuf2 + q_to_b(&tp->t_outq, com->obuf2,
2364 com->obufs[1].l_next = NULL;
2365 com->obufs[1].l_queued = TRUE;
2367 if (com->state & CS_BUSY) {
2368 qp = com->obufq.l_next;
2369 while ((next = qp->l_next) != NULL)
2371 qp->l_next = &com->obufs[1];
2373 com->obufq.l_head = com->obufs[1].l_head;
2374 com->obufq.l_tail = com->obufs[1].l_tail;
2375 com->obufq.l_next = &com->obufs[1];
2376 com->state |= CS_BUSY;
2377 if (com->state >= (CS_BUSY | CS_TTGO
2379 cd_setreg(com, CD1400_SRER,
2382 & ~CD1400_SRER_TXMPTY)
2383 | CD1400_SRER_TXRDY);
2387 tp->t_state |= TS_BUSY;
2395 if (com->state >= (CS_BUSY | CS_TTGO))
2396 siointr1(com); /* fake interrupt to start output */
2411 com = com_addr(DEV_TO_UNIT(tp->t_dev));
2415 com->obufs[0].l_queued = FALSE;
2416 com->obufs[1].l_queued = FALSE;
2417 if (com->extra_state & CSE_ODONE) {
2418 com_events -= LOTS_OF_EVENTS;
2419 com->extra_state &= ~CSE_ODONE;
2420 if (com->etc != ETC_NONE) {
2421 if (com->etc == ETC_BREAK_ENDED)
2422 com->etc = ETC_NONE;
2426 com->tp->t_state &= ~TS_BUSY;
2427 if (com->state & CS_ODONE)
2428 com_events -= LOTS_OF_EVENTS;
2429 com->state &= ~(CS_ODONE | CS_BUSY);
2432 /* XXX no way to reset only input fifo. */
2433 com_events -= (com->iptr - com->ibuf);
2434 com->iptr = com->ibuf;
2439 if (rw & FWRITE && com->etc == ETC_NONE)
2440 cd1400_channel_cmd(com, CD1400_CCR_CMDRESET | CD1400_CCR_FTF);
2445 commctl(com, bits, how)
2454 if (com->channel_control & CD1400_CCR_RCVEN)
2456 mcr = com->mcr_image;
2457 if (mcr & com->mcr_dtr)
2459 if (mcr & com->mcr_rts)
2460 /* XXX wired on for Cyclom-8Ys */
2464 * We must read the modem status from the hardware because
2465 * we don't generate modem status change interrupts for all
2466 * changes, so com->prev_modem_status is not guaranteed to
2467 * be up to date. This is safe, unlike for sio, because
2468 * reading the status register doesn't clear pending modem
2469 * status change interrupts.
2471 msr = cd_getreg(com, CD1400_MSVR2);
2480 /* XXX not connected except for Cyclom-16Y? */
2485 if (bits & TIOCM_DTR)
2486 mcr |= com->mcr_dtr;
2487 if (bits & TIOCM_RTS)
2488 mcr |= com->mcr_rts;
2492 com->mcr_image = mcr;
2493 cd_setreg(com, CD1400_MSVR1, mcr);
2494 cd_setreg(com, CD1400_MSVR2, mcr);
2497 com->mcr_image = mcr = com->mcr_image | mcr;
2498 cd_setreg(com, CD1400_MSVR1, mcr);
2499 cd_setreg(com, CD1400_MSVR2, mcr);
2502 com->mcr_image = mcr = com->mcr_image & ~mcr;
2503 cd_setreg(com, CD1400_MSVR1, mcr);
2504 cd_setreg(com, CD1400_MSVR2, mcr);
2519 * Set our timeout period to 1 second if no polled devices are open.
2520 * Otherwise set it to max(1/200, 1/hz).
2521 * Enable timeouts iff some device is open.
2523 untimeout(comwakeup, (void *)NULL, sio_timeout_handle);
2526 for (unit = 0; unit < NSIO; ++unit) {
2527 com = com_addr(unit);
2528 if (com != NULL && com->tp != NULL
2529 && com->tp->t_state & TS_ISOPEN) {
2532 if (com->poll || com->poll_output) {
2533 sio_timeout = hz > 200 ? hz / 200 : 1;
2540 sio_timeouts_until_log = hz / sio_timeout;
2541 sio_timeout_handle = timeout(comwakeup, (void *)NULL,
2544 /* Flush error messages, if any. */
2545 sio_timeouts_until_log = 1;
2546 comwakeup((void *)NULL);
2547 untimeout(comwakeup, (void *)NULL, sio_timeout_handle);
2558 sio_timeout_handle = timeout(comwakeup, (void *)NULL, sio_timeout);
2562 * Recover from lost output interrupts.
2563 * Poll any lines that don't use interrupts.
2565 for (unit = 0; unit < NSIO; ++unit) {
2566 com = com_addr(unit);
2568 && (com->state >= (CS_BUSY | CS_TTGO) || com->poll)) {
2577 * Check for and log errors, but not too often.
2579 if (--sio_timeouts_until_log > 0)
2581 sio_timeouts_until_log = hz / sio_timeout;
2582 for (unit = 0; unit < NSIO; ++unit) {
2585 com = com_addr(unit);
2588 for (errnum = 0; errnum < CE_NTYPES; ++errnum) {
2593 delta = com->delta_error_counts[errnum];
2594 com->delta_error_counts[errnum] = 0;
2598 total = com->error_counts[errnum] += delta;
2599 log(LOG_ERR, "cy%d: %u more %s%s (total %lu)\n",
2600 unit, delta, error_desc[errnum],
2601 delta == 1 ? "" : "s", total);
2607 disc_optim(tp, t, com)
2612 #ifndef SOFT_HOTCHAR
2617 * XXX can skip a lot more cases if Smarts. Maybe
2618 * (IGNCR | ISTRIP | IXON) in c_iflag. But perhaps we
2619 * shouldn't skip if (TS_CNTTB | TS_LNCH) is set in t_state.
2621 if (!(t->c_iflag & (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP | IXON))
2622 && (!(t->c_iflag & BRKINT) || (t->c_iflag & IGNBRK))
2623 && (!(t->c_iflag & PARMRK)
2624 || (t->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))
2625 && !(t->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN))
2626 && linesw[tp->t_line].l_rint == ttyinput)
2627 tp->t_state |= TS_CAN_BYPASS_L_RINT;
2629 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
2630 com->hotchar = linesw[tp->t_line].l_hotchar;
2631 #ifndef SOFT_HOTCHAR
2632 opt = com->cor[2] & ~CD1400_COR3_SCD34;
2633 if (com->hotchar != 0) {
2634 cd_setreg(com, CD1400_SCHR3, com->hotchar);
2635 cd_setreg(com, CD1400_SCHR4, com->hotchar);
2636 opt |= CD1400_COR3_SCD34;
2638 if (opt != com->cor[2]) {
2639 cd_setreg(com, CD1400_COR3, com->cor[2] = opt);
2640 cd1400_channel_cmd(com, CD1400_CCR_CMDCORCHG | CD1400_CCR_COR3);
2646 /* standard line discipline input routine */
2652 /* XXX duplicate ttyinput(), but without the IXOFF/IXON/ISTRIP/IPARMRK
2653 * bits, as they are done by the CD1400. Hardly worth the effort,
2654 * given that high-throughput sessions are raw anyhow.
2660 comspeed(speed, cy_clock, prescaler_io)
2673 if (speed < 0 || speed > 150000)
2676 /* determine which prescaler to use */
2677 for (prescaler_unit = 4, prescaler = 2048; prescaler_unit;
2678 prescaler_unit--, prescaler >>= 2) {
2679 if (cy_clock / prescaler / speed > 63)
2683 divider = (cy_clock / prescaler * 2 / speed + 1) / 2; /* round off */
2686 actual = cy_clock/prescaler/divider;
2688 /* 10 times error in percent: */
2689 error = ((actual - (long)speed) * 2000 / (long)speed + 1) / 2;
2691 /* 3.0% max error tolerance */
2692 if (error < -30 || error > 30)
2696 printf("prescaler = %d (%d)\n", prescaler, prescaler_unit);
2697 printf("divider = %d (%x)\n", divider, divider);
2698 printf("actual = %d\n", actual);
2699 printf("error = %d\n", error);
2702 *prescaler_io = prescaler_unit;
2707 cd1400_channel_cmd(com, cmd)
2711 cd1400_channel_cmd_wait(com);
2712 cd_setreg(com, CD1400_CCR, cmd);
2713 cd1400_channel_cmd_wait(com);
2717 cd1400_channel_cmd_wait(com)
2720 struct timeval start;
2724 if (cd_getreg(com, CD1400_CCR) == 0)
2728 if (cd_getreg(com, CD1400_CCR) == 0)
2731 usec = 1000000 * (tv.tv_sec - start.tv_sec) +
2732 tv.tv_usec - start.tv_usec;
2735 "cy%d: channel command timeout (%ld usec)\n",
2748 * We can't change the hardware's ETC state while there are any
2749 * characters in the tx fifo, since those characters would be
2750 * interpreted as commands! Unputting characters from the fifo
2751 * is difficult, so we wait up to 12 character times for the fifo
2752 * to drain. The command will be delayed for up to 2 character
2753 * times for the tx to become empty. Unputting characters from
2754 * the tx holding and shift registers is impossible, so we wait
2755 * for the tx to become empty so that the command is sure to be
2756 * executed soon after we issue it.
2759 if (com->etc == etc) {
2763 if ((etc == CD1400_ETC_SENDBREAK
2764 && (com->etc == ETC_BREAK_STARTING
2765 || com->etc == ETC_BREAK_STARTED))
2766 || (etc == CD1400_ETC_STOPBREAK
2767 && (com->etc == ETC_BREAK_ENDING || com->etc == ETC_BREAK_ENDED
2768 || com->etc == ETC_NONE))) {
2773 cd_setreg(com, CD1400_SRER,
2775 = (com->intr_enable & ~CD1400_SRER_TXRDY) | CD1400_SRER_TXMPTY);
2778 while (com->etc == etc
2779 && tsleep(&com->etc, TTIPRI | PCATCH, "cyetc", 0) == 0)
2788 struct com_s *basecom;
2795 basecom = com_addr(com->unit & ~(CD1400_NO_OF_CHANNELS - 1));
2796 car = com->unit & CD1400_CAR_CHAN;
2797 cy_align = com->cy_align;
2798 iobase = com->iobase;
2802 if (basecom->car != car)
2803 cd_outb(iobase, CD1400_CAR, cy_align, basecom->car = car);
2804 val = cd_inb(iobase, reg, cy_align);
2811 cd_setreg(com, reg, val)
2816 struct com_s *basecom;
2822 basecom = com_addr(com->unit & ~(CD1400_NO_OF_CHANNELS - 1));
2823 car = com->unit & CD1400_CAR_CHAN;
2824 cy_align = com->cy_align;
2825 iobase = com->iobase;
2829 if (basecom->car != car)
2830 cd_outb(iobase, CD1400_CAR, cy_align, basecom->car = car);
2831 cd_outb(iobase, reg, cy_align, val);
2847 com = com_addr(unit);
2848 printf("info for channel %d\n", unit);
2849 printf("------------------\n");
2850 printf("total cyclom service probes:\t%d\n", cy_svrr_probes);
2851 printf("calls to upper layer:\t\t%d\n", cy_timeouts);
2854 iobase = com->iobase;
2856 printf("cd1400 base address:\\tt%p\n", iobase);
2857 printf("saved channel_control:\t\t0x%02x\n", com->channel_control);
2858 printf("saved cor1-3:\t\t\t0x%02x 0x%02x 0x%02x\n",
2859 com->cor[0], com->cor[1], com->cor[2]);
2860 printf("service request enable reg:\t0x%02x (0x%02x cached)\n",
2861 cd_getreg(com, CD1400_SRER), com->intr_enable);
2862 printf("service request register:\t0x%02x\n",
2863 cd_inb(iobase, CD1400_SVRR, com->cy_align));
2864 printf("modem status:\t\t\t0x%02x (0x%02x cached)\n",
2865 cd_getreg(com, CD1400_MSVR2), com->prev_modem_status);
2866 printf("rx/tx/mdm interrupt registers:\t0x%02x 0x%02x 0x%02x\n",
2867 cd_inb(iobase, CD1400_RIR, com->cy_align),
2868 cd_inb(iobase, CD1400_TIR, com->cy_align),
2869 cd_inb(iobase, CD1400_MIR, com->cy_align));
2871 printf("com state:\t\t\t0x%02x\n", com->state);
2872 printf("calls to comstart():\t\t%d (%d useful)\n",
2873 com->start_count, com->start_real);
2874 printf("rx buffer chars free:\t\t%d\n", com->iptr - com->ibuf);
2876 if (com->obufs[0].l_queued)
2877 ocount += com->obufs[0].l_tail - com->obufs[0].l_head;
2878 if (com->obufs[1].l_queued)
2879 ocount += com->obufs[1].l_tail - com->obufs[1].l_head;
2880 printf("tx buffer chars:\t\t%u\n", ocount);
2881 printf("received chars:\t\t\t%d\n", com->bytes_in);
2882 printf("received exceptions:\t\t%d\n", com->recv_exception);
2883 printf("modem signal deltas:\t\t%d\n", com->mdm);
2884 printf("transmitted chars:\t\t%d\n", com->bytes_out);
2888 printf("tty state:\t\t\t0x%08x\n", tp->t_state);
2890 "upper layer queue lengths:\t%d raw, %d canon, %d output\n",
2891 tp->t_rawq.c_cc, tp->t_canq.c_cc, tp->t_outq.c_cc);
2893 printf("tty state:\t\t\tclosed\n");
2895 #endif /* CyDebug */