1 /*****************************************************************************/
4 * stallion.c -- stallion multiport serial driver.
6 * Copyright (c) 1995-1996 Greg Ungerer (gerg@stallion.oz.au).
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. All advertising materials mentioning features or use of this software
18 * must display the following acknowledgement:
19 * This product includes software developed by Greg Ungerer.
20 * 4. Neither the name of the author nor the names of any co-contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * $FreeBSD: src/sys/i386/isa/stallion.c,v 1.39.2.2 2001/08/30 12:29:57 murray Exp $
37 * $DragonFly: src/sys/dev/serial/stl/stallion.c,v 1.27 2008/08/02 01:14:43 dillon Exp $
40 /*****************************************************************************/
45 #include "opt_compat.h"
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/kernel.h>
50 #include <sys/malloc.h>
55 #include <sys/fcntl.h>
56 #include <sys/thread2.h>
57 #include <bus/isa/isa_device.h>
58 #include <machine_base/isa/ic/scd1400.h>
59 #include <machine_base/isa/ic/sc26198.h>
60 #include <machine/comstats.h>
63 #include <bus/pci/pcivar.h>
64 #include <bus/pci/pcireg.h>
69 /*****************************************************************************/
72 * Define the version level of the kernel - so we can compile in the
73 * appropriate bits of code. By default this will compile for a 2.1
84 /*****************************************************************************/
87 * Define different board types. At the moment I have only declared
88 * those boards that this driver supports. But I will use the standard
89 * "assigned" board numbers. In the future this driver will support
90 * some of the other Stallion boards. Currently supported boards are
91 * abbreviated as EIO = EasyIO and ECH = EasyConnection 8/32.
97 #define BRD_ECH64PCI 27
98 #define BRD_EASYIOPCI 28
101 * When using the BSD "config" stuff there is no easy way to specifiy
102 * a secondary IO address region. So it is hard wired here. Also the
103 * shared interrupt information is hard wired here...
105 static unsigned int stl_ioshared = 0x280;
106 static unsigned int stl_irqshared = 0;
108 /*****************************************************************************/
111 * Define important driver limitations.
113 #define STL_MAXBRDS 8
114 #define STL_MAXPANELS 4
115 #define STL_MAXBANKS 8
116 #define STL_PORTSPERPANEL 16
117 #define STL_PORTSPERBRD 64
120 * Define the important minor number break down bits. These have been
121 * chosen to be "compatible" with the standard sio driver minor numbers.
122 * Extra high bits are used to distinguish between boards.
124 #define STL_CALLOUTDEV 0x80
125 #define STL_CTRLLOCK 0x40
126 #define STL_CTRLINIT 0x20
127 #define STL_CTRLDEV (STL_CTRLLOCK | STL_CTRLINIT)
129 #define STL_MEMDEV 0x07000000
131 #define STL_DEFSPEED TTYDEF_SPEED
132 #define STL_DEFCFLAG (CS8 | CREAD | HUPCL)
135 * I haven't really decided (or measured) what buffer sizes give
136 * a good balance between performance and memory usage. These seem
137 * to work pretty well...
139 #define STL_RXBUFSIZE 2048
140 #define STL_TXBUFSIZE 2048
142 #define STL_TXBUFLOW (STL_TXBUFSIZE / 4)
143 #define STL_RXBUFHIGH (3 * STL_RXBUFSIZE / 4)
145 /*****************************************************************************/
148 * Define our local driver identity first. Set up stuff to deal with
149 * all the local structures required by a serial tty driver.
151 static const char stl_drvname[] = "stl";
152 static const char stl_longdrvname[] = "Stallion Multiport Serial Driver";
153 static const char stl_drvversion[] = "2.0.0";
154 static int stl_brdprobed[STL_MAXBRDS];
156 static int stl_nrbrds = 0;
157 static int stl_doingtimeout = 0;
158 static struct callout stl_poll_ch;
160 static const char __file__[] = /*__FILE__*/ "stallion.c";
163 * Define global stats structures. Not used often, and can be
164 * re-used for each stats call.
166 static combrd_t stl_brdstats;
167 static comstats_t stl_comstats;
169 /*****************************************************************************/
172 * Define a set of structures to hold all the board/panel/port info
173 * for our ports. These will be dynamically allocated as required.
177 * Define a ring queue structure for each port. This will hold the
178 * TX data waiting to be output. Characters are fed into this buffer
179 * from the line discipline (or even direct from user space!) and
180 * then fed into the UARTs during interrupts. Will use a clasic ring
181 * queue here for this. The good thing about this type of ring queue
182 * is that the head and tail pointers can be updated without interrupt
183 * protection - since "write" code only needs to change the head, and
184 * interrupt code only needs to change the tail.
194 * Port, panel and board structures to hold status info about each.
195 * The board structure contains pointers to structures for each panel
196 * connected to it, and in turn each panel structure contains pointers
197 * for each port structure for each port on that panel. Note that
198 * the port structure also contains the board and panel number that it
199 * is associated with, this makes it (fairly) easy to get back to the
200 * board/panel info for a port. Also note that the tty struct is at
201 * the top of the structure, this is important, since the code uses
202 * this fact to get the port struct pointer from the tty struct
205 typedef struct stlport {
223 unsigned int rxignoremsk;
224 unsigned int rxmarkmsk;
225 unsigned int crenable;
228 struct termios initintios;
229 struct termios initouttios;
230 struct termios lockintios;
231 struct termios lockouttios;
232 struct timeval timestamp;
237 struct callout dtr_ch;
240 typedef struct stlpanel {
247 unsigned int ackmask;
248 void (*isr)(struct stlpanel *panelp, unsigned int iobase);
250 stlport_t *ports[STL_PORTSPERPANEL];
253 typedef struct stlbrd {
263 unsigned int ioaddr1;
264 unsigned int ioaddr2;
265 unsigned int iostatus;
267 unsigned int ioctrlval;
270 void (*isr)(struct stlbrd *brdp);
271 unsigned int bnkpageaddr[STL_MAXBANKS];
272 unsigned int bnkstataddr[STL_MAXBANKS];
273 stlpanel_t *bnk2panel[STL_MAXBANKS];
274 stlpanel_t *panels[STL_MAXPANELS];
275 stlport_t *ports[STL_PORTSPERBRD];
278 static stlbrd_t *stl_brds[STL_MAXBRDS];
281 * Per board state flags. Used with the state field of the board struct.
282 * Not really much here yet!
284 #define BRD_FOUND 0x1
287 * Define the port structure state flags. These set of flags are
288 * modified at interrupt time - so setting and reseting them needs
291 #define ASY_TXLOW 0x1
292 #define ASY_RXDATA 0x2
293 #define ASY_DCDCHANGE 0x4
294 #define ASY_DTRWAIT 0x8
295 #define ASY_RTSFLOW 0x10
296 #define ASY_RTSFLOWMODE 0x20
297 #define ASY_CTSFLOWMODE 0x40
298 #define ASY_TXFLOWED 0x80
299 #define ASY_TXBUSY 0x100
300 #define ASY_TXEMPTY 0x200
302 #define ASY_ACTIVE (ASY_TXLOW | ASY_RXDATA | ASY_DCDCHANGE)
305 * Define an array of board names as printable strings. Handy for
306 * referencing boards when printing trace and stuff.
308 static char *stl_brdnames[] = {
340 /*****************************************************************************/
343 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
344 * to the directly accessable io ports of these boards (not the cd1400
345 * uarts - they are in scd1400.h).
347 #define EIO_8PORTRS 0x04
348 #define EIO_4PORTRS 0x05
349 #define EIO_8PORTDI 0x00
350 #define EIO_8PORTM 0x06
352 #define EIO_IDBITMASK 0x07
354 #define EIO_BRDMASK 0xf0
357 #define ID_BRD16 0x30
359 #define EIO_INTRPEND 0x08
360 #define EIO_INTEDGE 0x00
361 #define EIO_INTLEVEL 0x08
364 #define ECH_IDBITMASK 0xe0
365 #define ECH_BRDENABLE 0x08
366 #define ECH_BRDDISABLE 0x00
367 #define ECH_INTENABLE 0x01
368 #define ECH_INTDISABLE 0x00
369 #define ECH_INTLEVEL 0x02
370 #define ECH_INTEDGE 0x00
371 #define ECH_INTRPEND 0x01
372 #define ECH_BRDRESET 0x01
374 #define ECHMC_INTENABLE 0x01
375 #define ECHMC_BRDRESET 0x02
377 #define ECH_PNLSTATUS 2
378 #define ECH_PNL16PORT 0x20
379 #define ECH_PNLIDMASK 0x07
380 #define ECH_PNLXPID 0x40
381 #define ECH_PNLINTRPEND 0x80
382 #define ECH_ADDR2MASK 0x1e0
384 #define EIO_CLK 25000000
385 #define EIO_CLK8M 20000000
386 #define ECH_CLK EIO_CLK
389 * Define the PCI vendor and device ID for Stallion PCI boards.
391 #define STL_PCINSVENDID 0x100b
392 #define STL_PCINSDEVID 0xd001
394 #define STL_PCIVENDID 0x124d
395 #define STL_PCI32DEVID 0x0000
396 #define STL_PCI64DEVID 0x0002
397 #define STL_PCIEIODEVID 0x0003
399 #define STL_PCIBADCLASS 0x0101
401 typedef struct stlpcibrd {
402 unsigned short vendid;
403 unsigned short devid;
407 static stlpcibrd_t stl_pcibrds[] = {
408 { STL_PCIVENDID, STL_PCI64DEVID, BRD_ECH64PCI },
409 { STL_PCIVENDID, STL_PCIEIODEVID, BRD_EASYIOPCI },
410 { STL_PCIVENDID, STL_PCI32DEVID, BRD_ECHPCI },
411 { STL_PCINSVENDID, STL_PCINSDEVID, BRD_ECHPCI },
414 static int stl_nrpcibrds = sizeof(stl_pcibrds) / sizeof(stlpcibrd_t);
416 /*****************************************************************************/
419 * Define the vector mapping bits for the programmable interrupt board
420 * hardware. These bits encode the interrupt for the board to use - it
421 * is software selectable (except the EIO-8M).
423 static unsigned char stl_vecmap[] = {
424 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
425 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
429 * Set up enable and disable macros for the ECH boards. They require
430 * the secondary io address space to be activated and deactivated.
431 * This way all ECH boards can share their secondary io region.
432 * If this is an ECH-PCI board then also need to set the page pointer
433 * to point to the correct page.
435 #define BRDENABLE(brdnr,pagenr) \
436 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
437 outb(stl_brds[(brdnr)]->ioctrl, \
438 (stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE));\
439 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
440 outb(stl_brds[(brdnr)]->ioctrl, (pagenr));
442 #define BRDDISABLE(brdnr) \
443 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
444 outb(stl_brds[(brdnr)]->ioctrl, \
445 (stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE));
448 * Define some spare buffer space for un-wanted received characters.
450 static char stl_unwanted[SC26198_RXFIFOSIZE];
452 /*****************************************************************************/
455 * Define macros to extract a brd and port number from a minor number.
456 * This uses the extended minor number range in the upper 2 bytes of
457 * the device number. This gives us plenty of minor numbers to play
460 #define MKDEV2BRD(m) ((minor(m) & 0x00700000) >> 20)
461 #define MKDEV2PORT(m) ((minor(m) & 0x1f) | ((minor(m) & 0x00010000) >> 11))
464 * Define some handy local macros...
467 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
470 /*****************************************************************************/
473 * Declare all those functions in this driver! First up is the set of
474 * externally visible functions.
477 static int stlprobe(struct isa_device *idp);
478 static int stlattach(struct isa_device *idp);
480 STATIC d_open_t stlopen;
481 STATIC d_close_t stlclose;
482 STATIC d_ioctl_t stlioctl;
485 * Internal function prototypes.
487 static stlport_t *stl_dev2port(cdev_t dev);
488 static int stl_findfreeunit(void);
489 static int stl_rawopen(stlport_t *portp);
490 static int stl_rawclose(stlport_t *portp);
491 static void stl_flush(stlport_t *portp, int flag);
492 static int stl_param(struct tty *tp, struct termios *tiosp);
493 static void stl_start(struct tty *tp);
494 static void stl_stop(struct tty *tp, int);
495 static void stl_ttyoptim(stlport_t *portp, struct termios *tiosp);
496 static void stl_dotimeout(void);
497 static void stl_poll(void *arg);
498 static void stl_rxprocess(stlport_t *portp);
499 static void stl_flowcontrol(stlport_t *portp, int hw, int sw);
500 static void stl_dtrwakeup(void *arg);
501 static int stl_brdinit(stlbrd_t *brdp);
502 static int stl_initeio(stlbrd_t *brdp);
503 static int stl_initech(stlbrd_t *brdp);
504 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
505 static void stl_eiointr(stlbrd_t *brdp);
506 static void stl_echatintr(stlbrd_t *brdp);
507 static void stl_echmcaintr(stlbrd_t *brdp);
508 static void stl_echpciintr(stlbrd_t *brdp);
509 static void stl_echpci64intr(stlbrd_t *brdp);
510 static int stl_memioctl(cdev_t dev, unsigned long cmd, caddr_t data,
512 static int stl_getbrdstats(caddr_t data);
513 static int stl_getportstats(stlport_t *portp, caddr_t data);
514 static int stl_clrportstats(stlport_t *portp, caddr_t data);
515 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
516 static void stlintr(void *);
519 static const char *stlpciprobe(pcici_t tag, pcidi_t type);
520 static void stlpciattach(pcici_t tag, int unit);
521 static void stlpciintr(void * arg);
525 * CD1400 uart specific handling functions.
527 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value);
528 static int stl_cd1400getreg(stlport_t *portp, int regnr);
529 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value);
530 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
531 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
532 static int stl_cd1400setport(stlport_t *portp, struct termios *tiosp);
533 static int stl_cd1400getsignals(stlport_t *portp);
534 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts);
535 static void stl_cd1400ccrwait(stlport_t *portp);
536 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx);
537 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx);
538 static void stl_cd1400disableintrs(stlport_t *portp);
539 static void stl_cd1400sendbreak(stlport_t *portp, long len);
540 static void stl_cd1400sendflow(stlport_t *portp, int hw, int sw);
541 static int stl_cd1400datastate(stlport_t *portp);
542 static void stl_cd1400flush(stlport_t *portp, int flag);
543 static __inline void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr);
544 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr);
545 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr);
546 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase);
547 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase);
550 * SC26198 uart specific handling functions.
552 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value);
553 static int stl_sc26198getreg(stlport_t *portp, int regnr);
554 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value);
555 static int stl_sc26198getglobreg(stlport_t *portp, int regnr);
556 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
557 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
558 static int stl_sc26198setport(stlport_t *portp, struct termios *tiosp);
559 static int stl_sc26198getsignals(stlport_t *portp);
560 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts);
561 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx);
562 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx);
563 static void stl_sc26198disableintrs(stlport_t *portp);
564 static void stl_sc26198sendbreak(stlport_t *portp, long len);
565 static void stl_sc26198sendflow(stlport_t *portp, int hw, int sw);
566 static int stl_sc26198datastate(stlport_t *portp);
567 static void stl_sc26198flush(stlport_t *portp, int flag);
568 static void stl_sc26198txunflow(stlport_t *portp);
569 static void stl_sc26198wait(stlport_t *portp);
570 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase);
571 static void stl_sc26198txisr(stlport_t *port);
572 static void stl_sc26198rxisr(stlport_t *port, unsigned int iack);
573 static void stl_sc26198rxgoodchars(stlport_t *portp);
574 static void stl_sc26198rxbadchars(stlport_t *portp);
575 static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
577 /*****************************************************************************/
580 * Generic UART support structure.
582 typedef struct uart {
583 int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp);
584 void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
585 int (*setport)(stlport_t *portp, struct termios *tiosp);
586 int (*getsignals)(stlport_t *portp);
587 void (*setsignals)(stlport_t *portp, int dtr, int rts);
588 void (*enablerxtx)(stlport_t *portp, int rx, int tx);
589 void (*startrxtx)(stlport_t *portp, int rx, int tx);
590 void (*disableintrs)(stlport_t *portp);
591 void (*sendbreak)(stlport_t *portp, long len);
592 void (*sendflow)(stlport_t *portp, int hw, int sw);
593 void (*flush)(stlport_t *portp, int flag);
594 int (*datastate)(stlport_t *portp);
595 void (*intr)(stlpanel_t *panelp, unsigned int iobase);
599 * Define some macros to make calling these functions nice and clean.
601 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
602 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
603 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
604 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
605 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
606 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
607 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
608 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
609 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
610 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
611 #define stl_uartflush (* ((uart_t *) portp->uartp)->flush)
612 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
614 /*****************************************************************************/
617 * CD1400 UART specific data initialization.
619 static uart_t stl_cd1400uart = {
623 stl_cd1400getsignals,
624 stl_cd1400setsignals,
625 stl_cd1400enablerxtx,
627 stl_cd1400disableintrs,
636 * Define the offsets within the register bank of a cd1400 based panel.
637 * These io address offsets are common to the EasyIO board as well.
645 #define EREG_BANKSIZE 8
647 #define CD1400_CLK 25000000
648 #define CD1400_CLK8M 20000000
651 * Define the cd1400 baud rate clocks. These are used when calculating
652 * what clock and divisor to use for the required baud rate. Also
653 * define the maximum baud rate allowed, and the default base baud.
655 static int stl_cd1400clkdivs[] = {
656 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
660 * Define the maximum baud rate of the cd1400 devices.
662 #define CD1400_MAXBAUD 230400
664 /*****************************************************************************/
667 * SC26198 UART specific data initization.
669 static uart_t stl_sc26198uart = {
670 stl_sc26198panelinit,
673 stl_sc26198getsignals,
674 stl_sc26198setsignals,
675 stl_sc26198enablerxtx,
676 stl_sc26198startrxtx,
677 stl_sc26198disableintrs,
678 stl_sc26198sendbreak,
681 stl_sc26198datastate,
686 * Define the offsets within the register bank of a sc26198 based panel.
694 #define XP_BANKSIZE 4
697 * Define the sc26198 baud rate table. Offsets within the table
698 * represent the actual baud rate selector of sc26198 registers.
700 static unsigned int sc26198_baudtable[] = {
701 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
702 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
706 #define SC26198_NRBAUDS (sizeof(sc26198_baudtable) / sizeof(unsigned int))
709 * Define the maximum baud rate of the sc26198 devices.
711 #define SC26198_MAXBAUD 460800
713 /*****************************************************************************/
716 * Declare the driver isa structure.
718 struct isa_driver stldriver = {
719 stlprobe, stlattach, "stl"
722 /*****************************************************************************/
727 * Declare the driver pci structure.
729 static unsigned long stl_count;
731 static struct pci_device stlpcidriver = {
739 COMPAT_PCI_DRIVER (stlpci, stlpcidriver);
743 /*****************************************************************************/
748 * FreeBSD-2.2+ kernel linkage.
751 #define CDEV_MAJOR 72
752 static struct dev_ops stl_ops = {
753 { "stl", CDEV_MAJOR, D_TTY | D_KQFILTER },
760 .d_kqfilter = ttykqfilter,
761 .d_revoke = ttyrevoke
764 static void stl_drvinit(void *unused)
768 SYSINIT(sidev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,stl_drvinit,NULL)
772 /*****************************************************************************/
775 * Probe for some type of EasyIO or EasyConnection 8/32 board at
776 * the supplied address. All we do is check if we can find the
777 * board ID for the board... (Note, PCI boards not checked here,
778 * they are done in the stlpciprobe() routine).
781 static int stlprobe(struct isa_device *idp)
786 kprintf("stlprobe(idp=%x): unit=%d iobase=%x\n", (int) idp,
787 idp->id_unit, idp->id_iobase);
790 if (idp->id_unit > STL_MAXBRDS)
793 status = inb(idp->id_iobase + 1);
794 if ((status & ECH_IDBITMASK) == ECH_ID) {
795 stl_brdprobed[idp->id_unit] = BRD_ECH;
799 status = inb(idp->id_iobase + 2);
800 switch (status & EIO_IDBITMASK) {
806 stl_brdprobed[idp->id_unit] = BRD_EASYIO;
815 /*****************************************************************************/
818 * Find an available internal board number (unit number). The problem
819 * is that the same unit numbers can be assigned to different boards
820 * detected during the ISA and PCI initialization phases.
823 static int stl_findfreeunit(void)
827 for (i = 0; (i < STL_MAXBRDS); i++)
828 if (stl_brds[i] == NULL)
830 return((i >= STL_MAXBRDS) ? -1 : i);
833 /*****************************************************************************/
836 * Allocate resources for and initialize the specified board.
839 static int stlattach(struct isa_device *idp)
842 int boardnr, portnr, minor_dev;
845 kprintf("stlattach(idp=%p): unit=%d iobase=%x\n", (void *) idp,
846 idp->id_unit, idp->id_iobase);
849 /* idp->id_intr = (inthand2_t *)stlintr; */
851 brdp = kmalloc(sizeof(stlbrd_t), M_TTYS, M_WAITOK | M_ZERO);
853 if ((brdp->brdnr = stl_findfreeunit()) < 0) {
854 kprintf("STALLION: too many boards found, max=%d\n",
858 if (brdp->brdnr >= stl_nrbrds)
859 stl_nrbrds = brdp->brdnr + 1;
861 brdp->unitid = idp->id_unit;
862 brdp->brdtype = stl_brdprobed[idp->id_unit];
863 brdp->ioaddr1 = idp->id_iobase;
864 brdp->ioaddr2 = stl_ioshared;
865 brdp->irq = ffs(idp->id_irq) - 1;
866 brdp->irqtype = stl_irqshared;
869 /* register devices for DEVFS */
870 boardnr = brdp->brdnr;
871 dev_ops_add(&stl_ops, 31, boardnr);
872 make_dev(&stl_ops, boardnr + 0x1000000, UID_ROOT, GID_WHEEL,
873 0600, "staliomem%d", boardnr);
875 for (portnr = 0, minor_dev = boardnr * 0x100000;
876 portnr < 32; portnr++, minor_dev++) {
878 make_dev(&stl_ops, minor_dev,
879 UID_ROOT, GID_WHEEL, 0600,
880 "ttyE%d", portnr + (boardnr * 64));
881 make_dev(&stl_ops, minor_dev + 32,
882 UID_ROOT, GID_WHEEL, 0600,
883 "ttyiE%d", portnr + (boardnr * 64));
884 make_dev(&stl_ops, minor_dev + 64,
885 UID_ROOT, GID_WHEEL, 0600,
886 "ttylE%d", portnr + (boardnr * 64));
887 make_dev(&stl_ops, minor_dev + 128,
888 UID_ROOT, GID_WHEEL, 0600,
889 "cue%d", portnr + (boardnr * 64));
890 make_dev(&stl_ops, minor_dev + 160,
891 UID_ROOT, GID_WHEEL, 0600,
892 "cuie%d", portnr + (boardnr * 64));
893 make_dev(&stl_ops, minor_dev + 192,
894 UID_ROOT, GID_WHEEL, 0600,
895 "cule%d", portnr + (boardnr * 64));
898 make_dev(&stl_ops, minor_dev + 0x10000,
899 UID_ROOT, GID_WHEEL, 0600,
900 "ttyE%d", portnr + (boardnr * 64) + 32);
901 make_dev(&stl_ops, minor_dev + 32 + 0x10000,
902 UID_ROOT, GID_WHEEL, 0600,
903 "ttyiE%d", portnr + (boardnr * 64) + 32);
904 make_dev(&stl_ops, minor_dev + 64 + 0x10000,
905 UID_ROOT, GID_WHEEL, 0600,
906 "ttylE%d", portnr + (boardnr * 64) + 32);
907 make_dev(&stl_ops, minor_dev + 128 + 0x10000,
908 UID_ROOT, GID_WHEEL, 0600,
909 "cue%d", portnr + (boardnr * 64) + 32);
910 make_dev(&stl_ops, minor_dev + 160 + 0x10000,
911 UID_ROOT, GID_WHEEL, 0600,
912 "cuie%d", portnr + (boardnr * 64) + 32);
913 make_dev(&stl_ops, minor_dev + 192 + 0x10000,
914 UID_ROOT, GID_WHEEL, 0600,
915 "cule%d", portnr + (boardnr * 64) + 32);
917 boardnr = brdp->brdnr;
918 make_dev(&stl_ops, boardnr + 0x1000000, UID_ROOT, GID_WHEEL,
919 0600, "staliomem%d", boardnr);
921 for (portnr = 0, minor_dev = boardnr * 0x100000;
922 portnr < 32; portnr++, minor_dev++) {
924 make_dev(&stl_ops, minor_dev,
925 UID_ROOT, GID_WHEEL, 0600,
926 "ttyE%d", portnr + (boardnr * 64));
927 make_dev(&stl_ops, minor_dev + 32,
928 UID_ROOT, GID_WHEEL, 0600,
929 "ttyiE%d", portnr + (boardnr * 64));
930 make_dev(&stl_ops, minor_dev + 64,
931 UID_ROOT, GID_WHEEL, 0600,
932 "ttylE%d", portnr + (boardnr * 64));
933 make_dev(&stl_ops, minor_dev + 128,
934 UID_ROOT, GID_WHEEL, 0600,
935 "cue%d", portnr + (boardnr * 64));
936 make_dev(&stl_ops, minor_dev + 160,
937 UID_ROOT, GID_WHEEL, 0600,
938 "cuie%d", portnr + (boardnr * 64));
939 make_dev(&stl_ops, minor_dev + 192,
940 UID_ROOT, GID_WHEEL, 0600,
941 "cule%d", portnr + (boardnr * 64));
944 make_dev(&stl_ops, minor_dev + 0x10000,
945 UID_ROOT, GID_WHEEL, 0600,
946 "ttyE%d", portnr + (boardnr * 64) + 32);
947 make_dev(&stl_ops, minor_dev + 32 + 0x10000,
948 UID_ROOT, GID_WHEEL, 0600,
949 "ttyiE%d", portnr + (boardnr * 64) + 32);
950 make_dev(&stl_ops, minor_dev + 64 + 0x10000,
951 UID_ROOT, GID_WHEEL, 0600,
952 "ttylE%d", portnr + (boardnr * 64) + 32);
953 make_dev(&stl_ops, minor_dev + 128 + 0x10000,
954 UID_ROOT, GID_WHEEL, 0600,
955 "cue%d", portnr + (boardnr * 64) + 32);
956 make_dev(&stl_ops, minor_dev + 160 + 0x10000,
957 UID_ROOT, GID_WHEEL, 0600,
958 "cuie%d", portnr + (boardnr * 64) + 32);
959 make_dev(&stl_ops, minor_dev + 192 + 0x10000,
960 UID_ROOT, GID_WHEEL, 0600,
961 "cule%d", portnr + (boardnr * 64) + 32);
967 /*****************************************************************************/
972 * Probe specifically for the PCI boards. We need to be a little
973 * carefull here, since it looks sort like a Nat Semi IDE chip...
976 static const char *stlpciprobe(pcici_t tag, pcidi_t type)
982 kprintf("stlpciprobe(tag=%x,type=%x)\n", (int) &tag, (int) type);
986 for (i = 0; (i < stl_nrpcibrds); i++) {
987 if (((type & 0xffff) == stl_pcibrds[i].vendid) &&
988 (((type >> 16) & 0xffff) == stl_pcibrds[i].devid)) {
989 brdtype = stl_pcibrds[i].brdtype;
997 class = pci_conf_read(tag, PCI_CLASS_REG);
998 if ((class & PCI_CLASS_MASK) == PCI_CLASS_MASS_STORAGE)
1001 return(stl_brdnames[brdtype]);
1004 /*****************************************************************************/
1007 * Allocate resources for and initialize the specified PCI board.
1010 void stlpciattach(pcici_t tag, int unit)
1013 unsigned int bar[4];
1016 int boardnr, portnr, minor_dev;
1019 kprintf("stlpciattach(tag=%x,unit=%x)\n", (int) &tag, unit);
1022 brdp = kmalloc(sizeof(stlbrd_t), M_TTYS, M_WAITOK | M_ZERO);
1024 if ((unit < 0) || (unit > STL_MAXBRDS)) {
1025 kprintf("STALLION: bad PCI board unit number=%d\n", unit);
1030 * Allocate us a new driver unique unit number.
1032 if ((brdp->brdnr = stl_findfreeunit()) < 0) {
1033 kprintf("STALLION: too many boards found, max=%d\n",
1037 if (brdp->brdnr >= stl_nrbrds)
1038 stl_nrbrds = brdp->brdnr + 1;
1041 * Determine what type of PCI board this is...
1043 id = (unsigned int) pci_conf_read(tag, 0x0);
1044 for (i = 0; (i < stl_nrpcibrds); i++) {
1045 if (((id & 0xffff) == stl_pcibrds[i].vendid) &&
1046 (((id >> 16) & 0xffff) == stl_pcibrds[i].devid)) {
1047 brdp->brdtype = stl_pcibrds[i].brdtype;
1052 if (i >= stl_nrpcibrds) {
1053 kprintf("STALLION: probed PCI board unknown type=%x\n", id);
1057 for (i = 0; (i < 4); i++)
1058 bar[i] = (unsigned int) pci_conf_read(tag, 0x10 + (i * 4)) &
1061 switch (brdp->brdtype) {
1063 brdp->ioaddr1 = bar[1];
1064 brdp->ioaddr2 = bar[2];
1067 brdp->ioaddr1 = bar[2];
1068 brdp->ioaddr2 = bar[1];
1071 brdp->ioaddr1 = bar[1];
1072 brdp->ioaddr2 = bar[0];
1075 kprintf("STALLION: unknown PCI board type=%d\n", brdp->brdtype);
1080 brdp->unitid = brdp->brdnr; /* PCI units auto-assigned */
1081 brdp->irq = ((int) pci_conf_read(tag, 0x3c)) & 0xff;
1083 if (pci_map_int(tag, stlpciintr, NULL) == 0) {
1084 kprintf("STALLION: failed to map interrupt irq=%d for unit=%d\n",
1085 brdp->irq, brdp->brdnr);
1091 /* register devices for DEVFS */
1092 boardnr = brdp->brdnr;
1093 make_dev(&stl_ops, boardnr + 0x1000000, UID_ROOT, GID_WHEEL,
1094 0600, "staliomem%d", boardnr);
1096 for (portnr = 0, minor_dev = boardnr * 0x100000;
1097 portnr < 32; portnr++, minor_dev++) {
1099 make_dev(&stl_ops, minor_dev,
1100 UID_ROOT, GID_WHEEL, 0600,
1101 "ttyE%d", portnr + (boardnr * 64));
1102 make_dev(&stl_ops, minor_dev + 32,
1103 UID_ROOT, GID_WHEEL, 0600,
1104 "ttyiE%d", portnr + (boardnr * 64));
1105 make_dev(&stl_ops, minor_dev + 64,
1106 UID_ROOT, GID_WHEEL, 0600,
1107 "ttylE%d", portnr + (boardnr * 64));
1108 make_dev(&stl_ops, minor_dev + 128,
1109 UID_ROOT, GID_WHEEL, 0600,
1110 "cue%d", portnr + (boardnr * 64));
1111 make_dev(&stl_ops, minor_dev + 160,
1112 UID_ROOT, GID_WHEEL, 0600,
1113 "cuie%d", portnr + (boardnr * 64));
1114 make_dev(&stl_ops, minor_dev + 192,
1115 UID_ROOT, GID_WHEEL, 0600,
1116 "cule%d", portnr + (boardnr * 64));
1119 make_dev(&stl_ops, minor_dev + 0x10000,
1120 UID_ROOT, GID_WHEEL, 0600,
1121 "ttyE%d", portnr + (boardnr * 64) + 32);
1122 make_dev(&stl_ops, minor_dev + 32 + 0x10000,
1123 UID_ROOT, GID_WHEEL, 0600,
1124 "ttyiE%d", portnr + (boardnr * 64) + 32);
1125 make_dev(&stl_ops, minor_dev + 64 + 0x10000,
1126 UID_ROOT, GID_WHEEL, 0600,
1127 "ttylE%d", portnr + (boardnr * 64) + 32);
1128 make_dev(&stl_ops, minor_dev + 128 + 0x10000,
1129 UID_ROOT, GID_WHEEL, 0600,
1130 "cue%d", portnr + (boardnr * 64) + 32);
1131 make_dev(&stl_ops, minor_dev + 160 + 0x10000,
1132 UID_ROOT, GID_WHEEL, 0600,
1133 "cuie%d", portnr + (boardnr * 64) + 32);
1134 make_dev(&stl_ops, minor_dev + 192 + 0x10000,
1135 UID_ROOT, GID_WHEEL, 0600,
1136 "cule%d", portnr + (boardnr * 64) + 32);
1142 /*****************************************************************************/
1144 STATIC int stlopen(struct dev_open_args *ap)
1146 cdev_t dev = ap->a_head.a_dev;
1152 kprintf("stlopen(dev=%x,flag=%x,mode=%x,p=%x)\n", (int) dev, flag,
1157 * Firstly check if the supplied device number is a valid device.
1159 if (minor(dev) & STL_MEMDEV)
1162 portp = stl_dev2port(dev);
1165 if (minor(dev) & STL_CTRLDEV)
1169 callout = minor(dev) & STL_CALLOUTDEV;
1176 * Wait here for the DTR drop timeout period to expire.
1178 while (portp->state & ASY_DTRWAIT) {
1179 error = tsleep(&portp->dtrwait, PCATCH, "stldtr", 0);
1185 * We have a valid device, so now we check if it is already open.
1186 * If not then initialize the port hardware and set up the tty
1187 * struct as required.
1189 if ((tp->t_state & TS_ISOPEN) == 0) {
1190 tp->t_oproc = stl_start;
1191 tp->t_stop = stl_stop;
1192 tp->t_param = stl_param;
1194 tp->t_termios = callout ? portp->initouttios :
1198 if ((portp->sigs & TIOCM_CD) || callout)
1199 (*linesw[tp->t_line].l_modem)(tp, 1);
1202 if (portp->callout == 0) {
1207 if (portp->callout != 0) {
1208 if (ap->a_oflags & O_NONBLOCK) {
1212 error = tsleep(&portp->callout,
1213 PCATCH, "stlcall", 0);
1216 goto stlopen_restart;
1219 if ((tp->t_state & TS_XCLUDE) && priv_check_cred(ap->a_cred, PRIV_ROOT, 0)) {
1226 * If this port is not the callout device and we do not have carrier
1227 * then we need to sleep, waiting for it to be asserted.
1229 if (((tp->t_state & TS_CARR_ON) == 0) && !callout &&
1230 ((tp->t_cflag & CLOCAL) == 0) &&
1231 ((ap->a_oflags & O_NONBLOCK) == 0)) {
1233 error = tsleep(TSA_CARR_ON(tp), PCATCH, "stldcd", 0);
1237 goto stlopen_restart;
1241 * Open the line discipline.
1243 error = (*linesw[tp->t_line].l_open)(dev, tp);
1244 stl_ttyoptim(portp, &tp->t_termios);
1245 if ((tp->t_state & TS_ISOPEN) && callout)
1249 * If for any reason we get to here and the port is not actually
1250 * open then close of the physical hardware - no point leaving it
1251 * active when the open failed...
1255 if (((tp->t_state & TS_ISOPEN) == 0) && (portp->waitopens == 0))
1256 stl_rawclose(portp);
1261 /*****************************************************************************/
1263 STATIC int stlclose(struct dev_close_args *ap)
1265 cdev_t dev = ap->a_head.a_dev;
1270 kprintf("stlclose(dev=%s,flag=%x,mode=%x,p=%p)\n", devtoname(dev),
1271 flag, mode, (void *) p);
1274 if (minor(dev) & STL_MEMDEV)
1276 if (minor(dev) & STL_CTRLDEV)
1279 portp = stl_dev2port(dev);
1285 (*linesw[tp->t_line].l_close)(tp, ap->a_fflag);
1286 stl_ttyoptim(portp, &tp->t_termios);
1287 stl_rawclose(portp);
1293 /*****************************************************************************/
1297 STATIC void stl_stop(struct tty *tp, int rw)
1300 kprintf("stl_stop(tp=%x,rw=%x)\n", (int) tp, rw);
1303 stl_flush((stlport_t *) tp, rw);
1308 STATIC int stlstop(struct tty *tp, int rw)
1311 kprintf("stlstop(tp=%x,rw=%x)\n", (int) tp, rw);
1314 stl_flush((stlport_t *) tp, rw);
1320 /*****************************************************************************/
1322 STATIC int stlioctl(struct dev_ioctl_args *ap)
1324 cdev_t dev = ap->a_head.a_dev;
1325 u_long cmd = ap->a_cmd;
1326 caddr_t data = ap->a_data;
1327 struct termios *newtios, *localtios;
1333 kprintf("stlioctl(dev=%s,cmd=%lx,data=%p,flag=%x)\n",
1334 devtoname(dev), cmd, (void *) data, ap->a_fflag);
1337 if (minor(dev) & STL_MEMDEV)
1338 return(stl_memioctl(dev, cmd, data, ap->a_fflag));
1340 portp = stl_dev2port(dev);
1347 * First up handle ioctls on the control devices.
1349 if (minor(dev) & STL_CTRLDEV) {
1350 if ((minor(dev) & STL_CTRLDEV) == STL_CTRLINIT)
1351 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1352 &portp->initouttios : &portp->initintios;
1353 else if ((minor(dev) & STL_CTRLDEV) == STL_CTRLLOCK)
1354 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1355 &portp->lockouttios : &portp->lockintios;
1361 if ((error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0)) == 0)
1362 *localtios = *((struct termios *) data);
1365 *((struct termios *) data) = *localtios;
1368 *((int *) data) = TTYDISC;
1371 bzero(data, sizeof(struct winsize));
1381 * Deal with 4.3 compatibility issues if we have too...
1383 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1385 struct termios tios;
1386 unsigned long oldcmd;
1388 tios = tp->t_termios;
1390 if ((error = ttsetcompat(tp, &cmd, data, &tios)))
1393 data = (caddr_t) &tios;
1398 * Carry out some pre-cmd processing work first...
1399 * Hmmm, not so sure we want this, disable for now...
1401 if ((cmd == TIOCSETA) || (cmd == TIOCSETAW) || (cmd == TIOCSETAF)) {
1402 newtios = (struct termios *) data;
1403 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1404 &portp->lockouttios : &portp->lockintios;
1406 newtios->c_iflag = (tp->t_iflag & localtios->c_iflag) |
1407 (newtios->c_iflag & ~localtios->c_iflag);
1408 newtios->c_oflag = (tp->t_oflag & localtios->c_oflag) |
1409 (newtios->c_oflag & ~localtios->c_oflag);
1410 newtios->c_cflag = (tp->t_cflag & localtios->c_cflag) |
1411 (newtios->c_cflag & ~localtios->c_cflag);
1412 newtios->c_lflag = (tp->t_lflag & localtios->c_lflag) |
1413 (newtios->c_lflag & ~localtios->c_lflag);
1414 for (i = 0; (i < NCCS); i++) {
1415 if (localtios->c_cc[i] != 0)
1416 newtios->c_cc[i] = tp->t_cc[i];
1418 if (localtios->c_ispeed != 0)
1419 newtios->c_ispeed = tp->t_ispeed;
1420 if (localtios->c_ospeed != 0)
1421 newtios->c_ospeed = tp->t_ospeed;
1425 * Call the line discipline and the common command processing to
1426 * process this command (if they can).
1428 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data,
1429 ap->a_fflag, ap->a_cred);
1430 if (error != ENOIOCTL)
1434 error = ttioctl(tp, cmd, data, ap->a_fflag);
1435 stl_ttyoptim(portp, &tp->t_termios);
1436 if (error != ENOIOCTL) {
1444 * Process local commands here. These are all commands that only we
1445 * can take care of (they all rely on actually doing something special
1446 * to the actual hardware).
1450 stl_sendbreak(portp, -1);
1453 stl_sendbreak(portp, -2);
1456 stl_setsignals(portp, 1, -1);
1459 stl_setsignals(portp, 0, -1);
1462 i = *((int *) data);
1463 stl_setsignals(portp, ((i & TIOCM_DTR) ? 1 : 0),
1464 ((i & TIOCM_RTS) ? 1 : 0));
1467 i = *((int *) data);
1468 stl_setsignals(portp, ((i & TIOCM_DTR) ? 1 : -1),
1469 ((i & TIOCM_RTS) ? 1 : -1));
1472 i = *((int *) data);
1473 stl_setsignals(portp, ((i & TIOCM_DTR) ? 0 : -1),
1474 ((i & TIOCM_RTS) ? 0 : -1));
1477 *((int *) data) = (stl_getsignals(portp) | TIOCM_LE);
1480 if ((error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0)) == 0)
1481 portp->dtrwait = *((int *) data) * hz / 100;
1484 *((int *) data) = portp->dtrwait * 100 / hz;
1487 portp->dotimestamp = 1;
1488 *((struct timeval *) data) = portp->timestamp;
1498 /*****************************************************************************/
1501 * Convert the specified minor device number into a port struct
1502 * pointer. Return NULL if the device number is not a valid port.
1505 STATIC stlport_t *stl_dev2port(cdev_t dev)
1509 brdp = stl_brds[MKDEV2BRD(dev)];
1512 return(brdp->ports[MKDEV2PORT(dev)]);
1515 /*****************************************************************************/
1518 * Initialize the port hardware. This involves enabling the transmitter
1519 * and receiver, setting the port configuration, and setting the initial
1523 static int stl_rawopen(stlport_t *portp)
1526 kprintf("stl_rawopen(portp=%p): brdnr=%d panelnr=%d portnr=%d\n",
1527 (void *) portp, portp->brdnr, portp->panelnr, portp->portnr);
1530 stl_setport(portp, &portp->tty.t_termios);
1531 portp->sigs = stl_getsignals(portp);
1532 stl_setsignals(portp, 1, 1);
1533 stl_enablerxtx(portp, 1, 1);
1534 stl_startrxtx(portp, 1, 0);
1538 /*****************************************************************************/
1541 * Shutdown the hardware of a port. Disable its transmitter and
1542 * receiver, and maybe drop signals if appropriate.
1545 static int stl_rawclose(stlport_t *portp)
1550 kprintf("stl_rawclose(portp=%p): brdnr=%d panelnr=%d portnr=%d\n",
1551 (void *) portp, portp->brdnr, portp->panelnr, portp->portnr);
1555 stl_disableintrs(portp);
1556 stl_enablerxtx(portp, 0, 0);
1557 stl_flush(portp, (FWRITE | FREAD));
1558 if (tp->t_cflag & HUPCL) {
1559 stl_setsignals(portp, 0, 0);
1560 if (portp->dtrwait != 0) {
1561 portp->state |= ASY_DTRWAIT;
1562 callout_reset(&portp->dtr_ch, portp->dtrwait,
1563 stl_dtrwakeup, portp);
1568 portp->state &= ~(ASY_ACTIVE | ASY_RTSFLOW);
1569 wakeup(&portp->callout);
1570 wakeup(TSA_CARR_ON(tp));
1574 /*****************************************************************************/
1577 * Clear the DTR waiting flag, and wake up any sleepers waiting for
1578 * DTR wait period to finish.
1581 static void stl_dtrwakeup(void *arg)
1585 portp = (stlport_t *) arg;
1586 portp->state &= ~ASY_DTRWAIT;
1587 wakeup(&portp->dtrwait);
1590 /*****************************************************************************/
1593 * Start (or continue) the transfer of TX data on this port. If the
1594 * port is not currently busy then load up the interrupt ring queue
1595 * buffer and kick of the transmitter. If the port is running low on
1596 * TX data then refill the ring queue. This routine is also used to
1597 * activate input flow control!
1600 static void stl_start(struct tty *tp)
1603 unsigned int len, stlen;
1607 portp = (stlport_t *) tp;
1610 kprintf("stl_start(tp=%x): brdnr=%d portnr=%d\n", (int) tp,
1611 portp->brdnr, portp->portnr);
1617 * Check if the ports input has been blocked, and take appropriate action.
1618 * Not very often do we really need to do anything, so make it quick.
1620 if (tp->t_state & TS_TBLOCK) {
1621 if ((portp->state & ASY_RTSFLOWMODE) &&
1622 ((portp->state & ASY_RTSFLOW) == 0))
1623 stl_flowcontrol(portp, 0, -1);
1625 if (portp->state & ASY_RTSFLOW)
1626 stl_flowcontrol(portp, 1, -1);
1631 * Check if the output cooked clist buffers are near empty, wake up
1632 * the line discipline to fill it up.
1634 if (tp->t_outq.c_cc <= tp->t_lowat) {
1635 if (tp->t_state & TS_ASLEEP) {
1636 tp->t_state &= ~TS_ASLEEP;
1637 wakeup(&tp->t_outq);
1639 selwakeup(&tp->t_wsel);
1643 if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
1649 * Copy data from the clists into the interrupt ring queue. This will
1650 * require at most 2 copys... What we do is calculate how many chars
1651 * can fit into the ring queue, and how many can fit in 1 copy. If after
1652 * the first copy there is still more room then do the second copy.
1653 * The beauty of this type of ring queue is that we do not need to
1654 * spl protect our-selves, since we only ever update the head pointer,
1655 * and the interrupt routine only ever updates the tail pointer.
1657 if (tp->t_outq.c_cc != 0) {
1658 head = portp->tx.head;
1659 tail = portp->tx.tail;
1661 len = STL_TXBUFSIZE - (head - tail) - 1;
1662 stlen = portp->tx.endbuf - head;
1664 len = tail - head - 1;
1669 stlen = MIN(len, stlen);
1670 count = q_to_b(&tp->t_outq, head, stlen);
1673 if (head >= portp->tx.endbuf) {
1674 head = portp->tx.buf;
1676 stlen = q_to_b(&tp->t_outq, head, len);
1681 portp->tx.head = head;
1683 stl_startrxtx(portp, -1, 1);
1687 * If we sent something, make sure we are called again.
1689 tp->t_state |= TS_BUSY;
1694 * Do any writer wakeups.
1702 /*****************************************************************************/
1704 static void stl_flush(stlport_t *portp, int flag)
1710 kprintf("stl_flush(portp=%x,flag=%x)\n", (int) portp, flag);
1718 if (flag & FWRITE) {
1719 stl_uartflush(portp, FWRITE);
1720 portp->tx.tail = portp->tx.head;
1724 * The only thing to watch out for when flushing the read side is
1725 * the RX status buffer. The interrupt code relys on the status
1726 * bytes as being zeroed all the time (it does not bother setting
1727 * a good char status to 0, it expects that it already will be).
1728 * We also need to un-flow the RX channel if flow control was
1732 head = portp->rx.head;
1733 tail = portp->rx.tail;
1738 len = portp->rx.endbuf - tail;
1739 bzero(portp->rxstatus.buf,
1740 (head - portp->rx.buf));
1742 bzero((tail + STL_RXBUFSIZE), len);
1743 portp->rx.tail = head;
1746 if ((portp->state & ASY_RTSFLOW) &&
1747 ((portp->tty.t_state & TS_TBLOCK) == 0))
1748 stl_flowcontrol(portp, 1, -1);
1754 /*****************************************************************************/
1757 * Interrupt handler for host based boards. Interrupts for all boards
1758 * are vectored through here.
1761 void stlintr(void *arg)
1767 kprintf("stlintr(unit=%d)\n", (int)arg);
1770 for (i = 0; (i < stl_nrbrds); i++) {
1771 if ((brdp = stl_brds[i]) == NULL)
1773 if (brdp->state == 0)
1775 (* brdp->isr)(brdp);
1779 /*****************************************************************************/
1783 static void stlpciintr(void *arg)
1790 /*****************************************************************************/
1793 * Interrupt service routine for EasyIO boards.
1796 static void stl_eiointr(stlbrd_t *brdp)
1802 kprintf("stl_eiointr(brdp=%p)\n", brdp);
1805 panelp = (stlpanel_t *) brdp->panels[0];
1806 iobase = panelp->iobase;
1807 while (inb(brdp->iostatus) & EIO_INTRPEND)
1808 (* panelp->isr)(panelp, iobase);
1812 * Interrupt service routine for ECH-AT board types.
1815 static void stl_echatintr(stlbrd_t *brdp)
1818 unsigned int ioaddr;
1821 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDENABLE));
1823 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1824 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1825 ioaddr = brdp->bnkstataddr[bnknr];
1826 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1827 panelp = brdp->bnk2panel[bnknr];
1828 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1833 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDDISABLE));
1836 /*****************************************************************************/
1839 * Interrupt service routine for ECH-MCA board types.
1842 static void stl_echmcaintr(stlbrd_t *brdp)
1845 unsigned int ioaddr;
1848 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1849 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1850 ioaddr = brdp->bnkstataddr[bnknr];
1851 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1852 panelp = brdp->bnk2panel[bnknr];
1853 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1859 /*****************************************************************************/
1862 * Interrupt service routine for ECH-PCI board types.
1865 static void stl_echpciintr(stlbrd_t *brdp)
1868 unsigned int ioaddr;
1872 kprintf("stl_echpciintr(brdp=%x)\n", (int) brdp);
1877 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1878 outb(brdp->ioctrl, brdp->bnkpageaddr[bnknr]);
1879 ioaddr = brdp->bnkstataddr[bnknr];
1880 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1881 panelp = brdp->bnk2panel[bnknr];
1882 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1891 /*****************************************************************************/
1894 * Interrupt service routine for EC8/64-PCI board types.
1897 static void stl_echpci64intr(stlbrd_t *brdp)
1900 unsigned int ioaddr;
1904 kprintf("stl_echpci64intr(brdp=%p)\n", brdp);
1907 while (inb(brdp->ioctrl) & 0x1) {
1908 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1909 ioaddr = brdp->bnkstataddr[bnknr];
1911 kprintf(" --> ioaddr=%x status=%x(%x)\n", ioaddr, inb(ioaddr) & ECH_PNLINTRPEND, inb(ioaddr));
1913 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1914 panelp = brdp->bnk2panel[bnknr];
1915 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1921 /*****************************************************************************/
1924 * If we haven't scheduled a timeout then do it, some port needs high
1928 static void stl_dotimeout(void)
1931 kprintf("stl_dotimeout()\n");
1933 if (stl_doingtimeout == 0) {
1934 if ((stl_poll_ch.c_flags & CALLOUT_DID_INIT) == 0)
1935 callout_init(&stl_poll_ch);
1936 callout_reset(&stl_poll_ch, 1, stl_poll, NULL);
1941 /*****************************************************************************/
1944 * Service "software" level processing. Too slow or painfull to be done
1945 * at real hardware interrupt time. This way we might also be able to
1946 * do some service on other waiting ports as well...
1949 static void stl_poll(void *arg)
1954 int brdnr, portnr, rearm;
1957 kprintf("stl_poll()\n");
1960 stl_doingtimeout = 0;
1964 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1965 if ((brdp = stl_brds[brdnr]) == NULL)
1967 for (portnr = 0; (portnr < brdp->nrports); portnr++) {
1968 if ((portp = brdp->ports[portnr]) == NULL)
1970 if ((portp->state & ASY_ACTIVE) == 0)
1974 if (portp->state & ASY_RXDATA)
1975 stl_rxprocess(portp);
1976 if (portp->state & ASY_DCDCHANGE) {
1977 portp->state &= ~ASY_DCDCHANGE;
1978 portp->sigs = stl_getsignals(portp);
1979 (*linesw[tp->t_line].l_modem)(tp,
1980 (portp->sigs & TIOCM_CD));
1982 if (portp->state & ASY_TXEMPTY) {
1983 if (stl_datastate(portp) == 0) {
1984 portp->state &= ~ASY_TXEMPTY;
1985 tp->t_state &= ~TS_BUSY;
1986 (*linesw[tp->t_line].l_start)(tp);
1989 if (portp->state & ASY_TXLOW) {
1990 portp->state &= ~ASY_TXLOW;
1991 (*linesw[tp->t_line].l_start)(tp);
1994 if (portp->state & ASY_ACTIVE)
2004 /*****************************************************************************/
2007 * Process the RX data that has been buffered up in the RX ring queue.
2010 static void stl_rxprocess(stlport_t *portp)
2013 unsigned int len, stlen, lostlen;
2019 kprintf("stl_rxprocess(portp=%x): brdnr=%d portnr=%d\n", (int) portp,
2020 portp->brdnr, portp->portnr);
2024 portp->state &= ~ASY_RXDATA;
2026 if ((tp->t_state & TS_ISOPEN) == 0) {
2027 stl_flush(portp, FREAD);
2032 * Calculate the amount of data in the RX ring queue. Also calculate
2033 * the largest single copy size...
2035 head = portp->rx.head;
2036 tail = portp->rx.tail;
2041 len = STL_RXBUFSIZE - (tail - head);
2042 stlen = portp->rx.endbuf - tail;
2045 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
2047 if (((tp->t_rawq.c_cc + len) >= TTYHOG) &&
2048 ((portp->state & ASY_RTSFLOWMODE) ||
2049 (tp->t_iflag & IXOFF)) &&
2050 ((tp->t_state & TS_TBLOCK) == 0)) {
2051 ch = TTYHOG - tp->t_rawq.c_cc - 1;
2052 len = (ch > 0) ? ch : 0;
2053 stlen = MIN(stlen, len);
2056 lostlen = b_to_q(tail, stlen, &tp->t_rawq);
2059 if (tail >= portp->rx.endbuf) {
2060 tail = portp->rx.buf;
2061 lostlen += b_to_q(tail, len, &tp->t_rawq);
2064 portp->stats.rxlost += lostlen;
2066 portp->rx.tail = tail;
2069 while (portp->rx.tail != head) {
2070 ch = (unsigned char) *(portp->rx.tail);
2071 status = *(portp->rx.tail + STL_RXBUFSIZE);
2073 *(portp->rx.tail + STL_RXBUFSIZE) = 0;
2074 if (status & ST_BREAK)
2076 if (status & ST_FRAMING)
2078 if (status & ST_PARITY)
2080 if (status & ST_OVERRUN)
2083 (*linesw[tp->t_line].l_rint)(ch, tp);
2084 if (portp->rx.tail == head)
2087 if (++(portp->rx.tail) >= portp->rx.endbuf)
2088 portp->rx.tail = portp->rx.buf;
2092 if (head != portp->rx.tail)
2093 portp->state |= ASY_RXDATA;
2096 * If we were flow controled then maybe the buffer is low enough that
2097 * we can re-activate it.
2099 if ((portp->state & ASY_RTSFLOW) && ((tp->t_state & TS_TBLOCK) == 0))
2100 stl_flowcontrol(portp, 1, -1);
2103 /*****************************************************************************/
2105 static int stl_param(struct tty *tp, struct termios *tiosp)
2109 portp = (stlport_t *) tp;
2113 return(stl_setport(portp, tiosp));
2116 /*****************************************************************************/
2119 * Action the flow control as required. The hw and sw args inform the
2120 * routine what flow control methods it should try.
2123 static void stl_flowcontrol(stlport_t *portp, int hw, int sw)
2125 unsigned char *head, *tail;
2129 kprintf("stl_flowcontrol(portp=%x,hw=%d,sw=%d)\n", (int) portp, hw, sw);
2134 if (portp->state & ASY_RTSFLOWMODE) {
2136 if ((portp->state & ASY_RTSFLOW) == 0)
2138 } else if (hw > 0) {
2139 if (portp->state & ASY_RTSFLOW) {
2140 head = portp->rx.head;
2141 tail = portp->rx.tail;
2142 len = (head >= tail) ? (head - tail) :
2143 (STL_RXBUFSIZE - (tail - head));
2144 if (len < STL_RXBUFHIGH)
2151 * We have worked out what to do, if anything. So now apply it to the
2154 stl_sendflow(portp, hwflow, sw);
2157 /*****************************************************************************/
2160 * Enable l_rint processing bypass mode if tty modes allow it.
2163 static void stl_ttyoptim(stlport_t *portp, struct termios *tiosp)
2168 if (((tiosp->c_iflag &
2169 (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP)) == 0) &&
2170 (((tiosp->c_iflag & BRKINT) == 0) || (tiosp->c_iflag & IGNBRK)) &&
2171 (((tiosp->c_iflag & PARMRK) == 0) ||
2172 ((tiosp->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))) &&
2173 ((tiosp->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN)) ==0) &&
2174 (linesw[tp->t_line].l_rint == ttyinput))
2175 tp->t_state |= TS_CAN_BYPASS_L_RINT;
2177 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
2178 portp->hotchar = linesw[tp->t_line].l_hotchar;
2181 /*****************************************************************************/
2184 * Try and find and initialize all the ports on a panel. We don't care
2185 * what sort of board these ports are on - since the port io registers
2186 * are almost identical when dealing with ports.
2189 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2192 unsigned int chipmask;
2196 kprintf("stl_initports(panelp=%x)\n", (int) panelp);
2199 chipmask = stl_panelinit(brdp, panelp);
2202 * All UART's are initialized if found. Now go through and setup
2203 * each ports data structures. Also initialize each individual
2206 for (i = 0; (i < panelp->nrports); i++) {
2207 portp = kmalloc(sizeof(stlport_t), M_TTYS, M_WAITOK | M_ZERO);
2210 portp->brdnr = panelp->brdnr;
2211 portp->panelnr = panelp->panelnr;
2212 portp->uartp = panelp->uartp;
2213 portp->clk = brdp->clk;
2214 panelp->ports[i] = portp;
2216 j = STL_TXBUFSIZE + (2 * STL_RXBUFSIZE);
2217 portp->tx.buf = kmalloc(j, M_TTYS, M_WAITOK);
2218 portp->tx.endbuf = portp->tx.buf + STL_TXBUFSIZE;
2219 portp->tx.head = portp->tx.buf;
2220 portp->tx.tail = portp->tx.buf;
2221 portp->rx.buf = portp->tx.buf + STL_TXBUFSIZE;
2222 portp->rx.endbuf = portp->rx.buf + STL_RXBUFSIZE;
2223 portp->rx.head = portp->rx.buf;
2224 portp->rx.tail = portp->rx.buf;
2225 portp->rxstatus.buf = portp->rx.buf + STL_RXBUFSIZE;
2226 portp->rxstatus.endbuf = portp->rxstatus.buf + STL_RXBUFSIZE;
2227 portp->rxstatus.head = portp->rxstatus.buf;
2228 portp->rxstatus.tail = portp->rxstatus.buf;
2229 bzero(portp->rxstatus.head, STL_RXBUFSIZE);
2231 portp->initintios.c_ispeed = STL_DEFSPEED;
2232 portp->initintios.c_ospeed = STL_DEFSPEED;
2233 portp->initintios.c_cflag = STL_DEFCFLAG;
2234 portp->initintios.c_iflag = 0;
2235 portp->initintios.c_oflag = 0;
2236 portp->initintios.c_lflag = 0;
2237 bcopy(&ttydefchars[0], &portp->initintios.c_cc[0],
2238 sizeof(portp->initintios.c_cc));
2239 portp->initouttios = portp->initintios;
2240 portp->dtrwait = 3 * hz;
2241 callout_init(&portp->dtr_ch);
2243 stl_portinit(brdp, panelp, portp);
2249 /*****************************************************************************/
2252 * Try to find and initialize an EasyIO board.
2255 static int stl_initeio(stlbrd_t *brdp)
2258 unsigned int status;
2261 kprintf("stl_initeio(brdp=%x)\n", (int) brdp);
2264 brdp->ioctrl = brdp->ioaddr1 + 1;
2265 brdp->iostatus = brdp->ioaddr1 + 2;
2266 brdp->clk = EIO_CLK;
2267 brdp->isr = stl_eiointr;
2269 status = inb(brdp->iostatus);
2270 switch (status & EIO_IDBITMASK) {
2272 brdp->clk = EIO_CLK8M;
2282 switch (status & EIO_BRDMASK) {
2301 if (brdp->brdtype == BRD_EASYIOPCI) {
2302 outb((brdp->ioaddr2 + 0x4c), 0x41);
2305 * Check that the supplied IRQ is good and then use it to setup the
2306 * programmable interrupt bits on EIO board. Also set the edge/level
2307 * triggered interrupt bit.
2309 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2310 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2311 kprintf("STALLION: invalid irq=%d for brd=%d\n",
2312 brdp->irq, brdp->brdnr);
2315 outb(brdp->ioctrl, (stl_vecmap[brdp->irq] |
2316 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)));
2319 panelp = kmalloc(sizeof(stlpanel_t), M_TTYS, M_WAITOK | M_ZERO);
2320 panelp->brdnr = brdp->brdnr;
2321 panelp->panelnr = 0;
2322 panelp->nrports = brdp->nrports;
2323 panelp->iobase = brdp->ioaddr1;
2324 panelp->hwid = status;
2325 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2326 panelp->uartp = (void *) &stl_sc26198uart;
2327 panelp->isr = stl_sc26198intr;
2329 panelp->uartp = (void *) &stl_cd1400uart;
2330 panelp->isr = stl_cd1400eiointr;
2332 brdp->panels[0] = panelp;
2334 brdp->hwid = status;
2335 brdp->state |= BRD_FOUND;
2339 /*****************************************************************************/
2342 * Try to find an ECH board and initialize it. This code is capable of
2343 * dealing with all types of ECH board.
2346 static int stl_initech(stlbrd_t *brdp)
2349 unsigned int status, nxtid;
2350 int panelnr, ioaddr, banknr, i;
2353 kprintf("stl_initech(brdp=%x)\n", (int) brdp);
2357 * Set up the initial board register contents for boards. This varys a
2358 * bit between the different board types. So we need to handle each
2359 * separately. Also do a check that the supplied IRQ is good.
2361 switch (brdp->brdtype) {
2364 brdp->isr = stl_echatintr;
2365 brdp->ioctrl = brdp->ioaddr1 + 1;
2366 brdp->iostatus = brdp->ioaddr1 + 1;
2367 status = inb(brdp->iostatus);
2368 if ((status & ECH_IDBITMASK) != ECH_ID)
2370 brdp->hwid = status;
2372 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2373 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2374 kprintf("STALLION: invalid irq=%d for brd=%d\n",
2375 brdp->irq, brdp->brdnr);
2378 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2379 status |= (stl_vecmap[brdp->irq] << 1);
2380 outb(brdp->ioaddr1, (status | ECH_BRDRESET));
2381 brdp->ioctrlval = ECH_INTENABLE |
2382 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2383 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDENABLE));
2384 outb(brdp->ioaddr1, status);
2388 brdp->isr = stl_echmcaintr;
2389 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2390 brdp->iostatus = brdp->ioctrl;
2391 status = inb(brdp->iostatus);
2392 if ((status & ECH_IDBITMASK) != ECH_ID)
2394 brdp->hwid = status;
2396 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2397 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2398 kprintf("STALLION: invalid irq=%d for brd=%d\n",
2399 brdp->irq, brdp->brdnr);
2402 outb(brdp->ioctrl, ECHMC_BRDRESET);
2403 outb(brdp->ioctrl, ECHMC_INTENABLE);
2407 brdp->isr = stl_echpciintr;
2408 brdp->ioctrl = brdp->ioaddr1 + 2;
2412 brdp->isr = stl_echpci64intr;
2413 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2414 outb((brdp->ioaddr1 + 0x4c), 0x43);
2418 kprintf("STALLION: unknown board type=%d\n", brdp->brdtype);
2422 brdp->clk = ECH_CLK;
2425 * Scan through the secondary io address space looking for panels.
2426 * As we find'em allocate and initialize panel structures for each.
2428 ioaddr = brdp->ioaddr2;
2433 for (i = 0; (i < STL_MAXPANELS); i++) {
2434 if (brdp->brdtype == BRD_ECHPCI) {
2435 outb(brdp->ioctrl, nxtid);
2436 ioaddr = brdp->ioaddr2;
2438 status = inb(ioaddr + ECH_PNLSTATUS);
2439 if ((status & ECH_PNLIDMASK) != nxtid)
2441 panelp = kmalloc(sizeof(stlpanel_t), M_TTYS, M_WAITOK | M_ZERO);
2442 panelp->brdnr = brdp->brdnr;
2443 panelp->panelnr = panelnr;
2444 panelp->iobase = ioaddr;
2445 panelp->pagenr = nxtid;
2446 panelp->hwid = status;
2447 brdp->bnk2panel[banknr] = panelp;
2448 brdp->bnkpageaddr[banknr] = nxtid;
2449 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2451 if (status & ECH_PNLXPID) {
2452 panelp->uartp = (void *) &stl_sc26198uart;
2453 panelp->isr = stl_sc26198intr;
2454 if (status & ECH_PNL16PORT) {
2455 panelp->nrports = 16;
2456 brdp->bnk2panel[banknr] = panelp;
2457 brdp->bnkpageaddr[banknr] = nxtid;
2458 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2461 panelp->nrports = 8;
2464 panelp->uartp = (void *) &stl_cd1400uart;
2465 panelp->isr = stl_cd1400echintr;
2466 if (status & ECH_PNL16PORT) {
2467 panelp->nrports = 16;
2468 panelp->ackmask = 0x80;
2469 if (brdp->brdtype != BRD_ECHPCI)
2470 ioaddr += EREG_BANKSIZE;
2471 brdp->bnk2panel[banknr] = panelp;
2472 brdp->bnkpageaddr[banknr] = ++nxtid;
2473 brdp->bnkstataddr[banknr++] = ioaddr +
2476 panelp->nrports = 8;
2477 panelp->ackmask = 0xc0;
2482 ioaddr += EREG_BANKSIZE;
2483 brdp->nrports += panelp->nrports;
2484 brdp->panels[panelnr++] = panelp;
2485 if ((brdp->brdtype == BRD_ECH) || (brdp->brdtype == BRD_ECHMC)){
2486 if (ioaddr >= (brdp->ioaddr2 + 0x20)) {
2487 kprintf("STALLION: too many ports attached "
2488 "to board %d, remove last module\n",
2495 brdp->nrpanels = panelnr;
2496 brdp->nrbnks = banknr;
2497 if (brdp->brdtype == BRD_ECH)
2498 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDDISABLE));
2500 brdp->state |= BRD_FOUND;
2504 /*****************************************************************************/
2507 * Initialize and configure the specified board. This firstly probes
2508 * for the board, if it is found then the board is initialized and
2509 * then all its ports are initialized as well.
2512 static int stl_brdinit(stlbrd_t *brdp)
2518 kprintf("stl_brdinit(brdp=%x): unit=%d type=%d io1=%x io2=%x irq=%d\n",
2519 (int) brdp, brdp->brdnr, brdp->brdtype, brdp->ioaddr1,
2520 brdp->ioaddr2, brdp->irq);
2523 switch (brdp->brdtype) {
2535 kprintf("STALLION: unit=%d is unknown board type=%d\n",
2536 brdp->brdnr, brdp->brdtype);
2540 stl_brds[brdp->brdnr] = brdp;
2541 if ((brdp->state & BRD_FOUND) == 0) {
2543 kprintf("STALLION: %s board not found, unit=%d io=%x irq=%d\n",
2544 stl_brdnames[brdp->brdtype], brdp->brdnr,
2545 brdp->ioaddr1, brdp->irq);
2550 for (i = 0, k = 0; (i < STL_MAXPANELS); i++) {
2551 panelp = brdp->panels[i];
2552 if (panelp != NULL) {
2553 stl_initports(brdp, panelp);
2554 for (j = 0; (j < panelp->nrports); j++)
2555 brdp->ports[k++] = panelp->ports[j];
2559 kprintf("stl%d: %s (driver version %s) unit=%d nrpanels=%d nrports=%d\n",
2560 brdp->unitid, stl_brdnames[brdp->brdtype], stl_drvversion,
2561 brdp->brdnr, brdp->nrpanels, brdp->nrports);
2565 /*****************************************************************************/
2568 * Return the board stats structure to user app.
2571 static int stl_getbrdstats(caddr_t data)
2577 stl_brdstats = *((combrd_t *) data);
2578 if (stl_brdstats.brd >= STL_MAXBRDS)
2580 brdp = stl_brds[stl_brdstats.brd];
2584 bzero(&stl_brdstats, sizeof(combrd_t));
2585 stl_brdstats.brd = brdp->brdnr;
2586 stl_brdstats.type = brdp->brdtype;
2587 stl_brdstats.hwid = brdp->hwid;
2588 stl_brdstats.state = brdp->state;
2589 stl_brdstats.ioaddr = brdp->ioaddr1;
2590 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2591 stl_brdstats.irq = brdp->irq;
2592 stl_brdstats.nrpanels = brdp->nrpanels;
2593 stl_brdstats.nrports = brdp->nrports;
2594 for (i = 0; (i < brdp->nrpanels); i++) {
2595 panelp = brdp->panels[i];
2596 stl_brdstats.panels[i].panel = i;
2597 stl_brdstats.panels[i].hwid = panelp->hwid;
2598 stl_brdstats.panels[i].nrports = panelp->nrports;
2601 *((combrd_t *) data) = stl_brdstats;
2605 /*****************************************************************************/
2608 * Resolve the referenced port number into a port struct pointer.
2611 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2616 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2618 brdp = stl_brds[brdnr];
2621 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2623 panelp = brdp->panels[panelnr];
2626 if ((portnr < 0) || (portnr >= panelp->nrports))
2628 return(panelp->ports[portnr]);
2631 /*****************************************************************************/
2634 * Return the port stats structure to user app. A NULL port struct
2635 * pointer passed in means that we need to find out from the app
2636 * what port to get stats for (used through board control device).
2639 static int stl_getportstats(stlport_t *portp, caddr_t data)
2641 unsigned char *head, *tail;
2643 if (portp == NULL) {
2644 stl_comstats = *((comstats_t *) data);
2645 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2651 portp->stats.state = portp->state;
2652 /*portp->stats.flags = portp->flags;*/
2653 portp->stats.hwid = portp->hwid;
2654 portp->stats.ttystate = portp->tty.t_state;
2655 portp->stats.cflags = portp->tty.t_cflag;
2656 portp->stats.iflags = portp->tty.t_iflag;
2657 portp->stats.oflags = portp->tty.t_oflag;
2658 portp->stats.lflags = portp->tty.t_lflag;
2660 head = portp->tx.head;
2661 tail = portp->tx.tail;
2662 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2663 (STL_TXBUFSIZE - (tail - head)));
2665 head = portp->rx.head;
2666 tail = portp->rx.tail;
2667 portp->stats.rxbuffered = (head >= tail) ? (head - tail) :
2668 (STL_RXBUFSIZE - (tail - head));
2670 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2672 *((comstats_t *) data) = portp->stats;
2676 /*****************************************************************************/
2679 * Clear the port stats structure. We also return it zeroed out...
2682 static int stl_clrportstats(stlport_t *portp, caddr_t data)
2684 if (portp == NULL) {
2685 stl_comstats = *((comstats_t *) data);
2686 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2692 bzero(&portp->stats, sizeof(comstats_t));
2693 portp->stats.brd = portp->brdnr;
2694 portp->stats.panel = portp->panelnr;
2695 portp->stats.port = portp->portnr;
2696 *((comstats_t *) data) = stl_comstats;
2700 /*****************************************************************************/
2703 * The "staliomem" device is used for stats collection in this driver.
2706 static int stl_memioctl(cdev_t dev, unsigned long cmd, caddr_t data, int flag)
2711 kprintf("stl_memioctl(dev=%s,cmd=%lx,data=%p,flag=%x)\n",
2712 devtoname(dev), cmd, (void *) data, flag);
2718 case COM_GETPORTSTATS:
2719 rc = stl_getportstats(NULL, data);
2721 case COM_CLRPORTSTATS:
2722 rc = stl_clrportstats(NULL, data);
2724 case COM_GETBRDSTATS:
2725 rc = stl_getbrdstats(data);
2735 /*****************************************************************************/
2737 /*****************************************************************************/
2738 /* CD1400 UART CODE */
2739 /*****************************************************************************/
2742 * These functions get/set/update the registers of the cd1400 UARTs.
2743 * Access to the cd1400 registers is via an address/data io port pair.
2746 static int stl_cd1400getreg(stlport_t *portp, int regnr)
2748 outb(portp->ioaddr, (regnr + portp->uartaddr));
2749 return(inb(portp->ioaddr + EREG_DATA));
2752 /*****************************************************************************/
2754 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
2756 outb(portp->ioaddr, (regnr + portp->uartaddr));
2757 outb((portp->ioaddr + EREG_DATA), value);
2760 /*****************************************************************************/
2762 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
2764 outb(portp->ioaddr, (regnr + portp->uartaddr));
2765 if (inb(portp->ioaddr + EREG_DATA) != value) {
2766 outb((portp->ioaddr + EREG_DATA), value);
2772 /*****************************************************************************/
2774 static void stl_cd1400flush(stlport_t *portp, int flag)
2778 kprintf("stl_cd1400flush(portp=%x,flag=%x)\n", (int) portp, flag);
2786 if (flag & FWRITE) {
2787 BRDENABLE(portp->brdnr, portp->pagenr);
2788 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2789 stl_cd1400ccrwait(portp);
2790 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
2791 stl_cd1400ccrwait(portp);
2792 BRDDISABLE(portp->brdnr);
2802 /*****************************************************************************/
2804 static void stl_cd1400ccrwait(stlport_t *portp)
2808 for (i = 0; (i < CCR_MAXWAIT); i++) {
2809 if (stl_cd1400getreg(portp, CCR) == 0)
2813 kprintf("stl%d: cd1400 device not responding, panel=%d port=%d\n",
2814 portp->brdnr, portp->panelnr, portp->portnr);
2817 /*****************************************************************************/
2820 * Transmit interrupt handler. This has gotta be fast! Handling TX
2821 * chars is pretty simple, stuff as many as possible from the TX buffer
2822 * into the cd1400 FIFO. Must also handle TX breaks here, since they
2823 * are embedded as commands in the data stream. Oh no, had to use a goto!
2826 static __inline void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
2830 unsigned char ioack, srer;
2835 kprintf("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
2838 ioack = inb(ioaddr + EREG_TXACK);
2839 if (((ioack & panelp->ackmask) != 0) ||
2840 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
2841 kprintf("STALLION: bad TX interrupt ack value=%x\n",
2845 portp = panelp->ports[(ioack >> 3)];
2849 * Unfortunately we need to handle breaks in the data stream, since
2850 * this is the only way to generate them on the cd1400. Do it now if
2851 * a break is to be sent. Some special cases here: brklen is -1 then
2852 * start sending an un-timed break, if brklen is -2 then stop sending
2853 * an un-timed break, if brklen is -3 then we have just sent an
2854 * un-timed break and do not want any data to go out, if brklen is -4
2855 * then a break has just completed so clean up the port settings.
2857 if (portp->brklen != 0) {
2858 if (portp->brklen >= -1) {
2859 outb(ioaddr, (TDR + portp->uartaddr));
2860 outb((ioaddr + EREG_DATA), ETC_CMD);
2861 outb((ioaddr + EREG_DATA), ETC_STARTBREAK);
2862 if (portp->brklen > 0) {
2863 outb((ioaddr + EREG_DATA), ETC_CMD);
2864 outb((ioaddr + EREG_DATA), ETC_DELAY);
2865 outb((ioaddr + EREG_DATA), portp->brklen);
2866 outb((ioaddr + EREG_DATA), ETC_CMD);
2867 outb((ioaddr + EREG_DATA), ETC_STOPBREAK);
2872 } else if (portp->brklen == -2) {
2873 outb(ioaddr, (TDR + portp->uartaddr));
2874 outb((ioaddr + EREG_DATA), ETC_CMD);
2875 outb((ioaddr + EREG_DATA), ETC_STOPBREAK);
2877 } else if (portp->brklen == -3) {
2878 outb(ioaddr, (SRER + portp->uartaddr));
2879 srer = inb(ioaddr + EREG_DATA);
2880 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
2881 outb((ioaddr + EREG_DATA), srer);
2883 outb(ioaddr, (COR2 + portp->uartaddr));
2884 outb((ioaddr + EREG_DATA),
2885 (inb(ioaddr + EREG_DATA) & ~COR2_ETC));
2891 head = portp->tx.head;
2892 tail = portp->tx.tail;
2893 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
2894 if ((len == 0) || ((len < STL_TXBUFLOW) &&
2895 ((portp->state & ASY_TXLOW) == 0))) {
2896 portp->state |= ASY_TXLOW;
2901 outb(ioaddr, (SRER + portp->uartaddr));
2902 srer = inb(ioaddr + EREG_DATA);
2903 if (srer & SRER_TXDATA) {
2904 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
2906 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
2907 portp->state |= ASY_TXEMPTY;
2908 portp->state &= ~ASY_TXBUSY;
2910 outb((ioaddr + EREG_DATA), srer);
2912 len = MIN(len, CD1400_TXFIFOSIZE);
2913 portp->stats.txtotal += len;
2914 stlen = MIN(len, (portp->tx.endbuf - tail));
2915 outb(ioaddr, (TDR + portp->uartaddr));
2916 outsb((ioaddr + EREG_DATA), tail, stlen);
2919 if (tail >= portp->tx.endbuf)
2920 tail = portp->tx.buf;
2922 outsb((ioaddr + EREG_DATA), tail, len);
2925 portp->tx.tail = tail;
2929 outb(ioaddr, (EOSRR + portp->uartaddr));
2930 outb((ioaddr + EREG_DATA), 0);
2933 /*****************************************************************************/
2936 * Receive character interrupt handler. Determine if we have good chars
2937 * or bad chars and then process appropriately.
2940 static __inline void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
2944 unsigned int ioack, len, buflen, stlen;
2945 unsigned char status;
2950 kprintf("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
2953 ioack = inb(ioaddr + EREG_RXACK);
2954 if ((ioack & panelp->ackmask) != 0) {
2955 kprintf("STALLION: bad RX interrupt ack value=%x\n", ioack);
2958 portp = panelp->ports[(ioack >> 3)];
2962 * First up, calculate how much room there is in the RX ring queue.
2963 * We also want to keep track of the longest possible copy length,
2964 * this has to allow for the wrapping of the ring queue.
2966 head = portp->rx.head;
2967 tail = portp->rx.tail;
2969 buflen = STL_RXBUFSIZE - (head - tail) - 1;
2970 stlen = portp->rx.endbuf - head;
2972 buflen = tail - head - 1;
2977 * Check if the input buffer is near full. If so then we should take
2978 * some flow control action... It is very easy to do hardware and
2979 * software flow control from here since we have the port selected on
2982 if (buflen <= (STL_RXBUFSIZE - STL_RXBUFHIGH)) {
2983 if (((portp->state & ASY_RTSFLOW) == 0) &&
2984 (portp->state & ASY_RTSFLOWMODE)) {
2985 portp->state |= ASY_RTSFLOW;
2986 stl_cd1400setreg(portp, MCOR1,
2987 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
2988 stl_cd1400setreg(portp, MSVR2, 0);
2989 portp->stats.rxrtsoff++;
2994 * OK we are set, process good data... If the RX ring queue is full
2995 * just chuck the chars - don't leave them in the UART.
2997 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
2998 outb(ioaddr, (RDCR + portp->uartaddr));
2999 len = inb(ioaddr + EREG_DATA);
3001 outb(ioaddr, (RDSR + portp->uartaddr));
3002 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
3003 portp->stats.rxlost += len;
3004 portp->stats.rxtotal += len;
3006 len = MIN(len, buflen);
3007 portp->stats.rxtotal += len;
3008 stlen = MIN(len, stlen);
3010 outb(ioaddr, (RDSR + portp->uartaddr));
3011 insb((ioaddr + EREG_DATA), head, stlen);
3013 if (head >= portp->rx.endbuf) {
3014 head = portp->rx.buf;
3016 insb((ioaddr + EREG_DATA), head, len);
3021 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
3022 outb(ioaddr, (RDSR + portp->uartaddr));
3023 status = inb(ioaddr + EREG_DATA);
3024 ch = inb(ioaddr + EREG_DATA);
3025 if (status & ST_BREAK)
3026 portp->stats.rxbreaks++;
3027 if (status & ST_FRAMING)
3028 portp->stats.rxframing++;
3029 if (status & ST_PARITY)
3030 portp->stats.rxparity++;
3031 if (status & ST_OVERRUN)
3032 portp->stats.rxoverrun++;
3033 if (status & ST_SCHARMASK) {
3034 if ((status & ST_SCHARMASK) == ST_SCHAR1)
3035 portp->stats.txxon++;
3036 if ((status & ST_SCHARMASK) == ST_SCHAR2)
3037 portp->stats.txxoff++;
3040 if ((portp->rxignoremsk & status) == 0) {
3041 if ((tp->t_state & TS_CAN_BYPASS_L_RINT) &&
3042 ((status & ST_FRAMING) ||
3043 ((status & ST_PARITY) && (tp->t_iflag & INPCK))))
3045 if ((portp->rxmarkmsk & status) == 0)
3047 *(head + STL_RXBUFSIZE) = status;
3049 if (head >= portp->rx.endbuf)
3050 head = portp->rx.buf;
3053 kprintf("STALLION: bad RX interrupt ack value=%x\n", ioack);
3057 portp->rx.head = head;
3058 portp->state |= ASY_RXDATA;
3062 outb(ioaddr, (EOSRR + portp->uartaddr));
3063 outb((ioaddr + EREG_DATA), 0);
3066 /*****************************************************************************/
3069 * Modem interrupt handler. The is called when the modem signal line
3070 * (DCD) has changed state.
3073 static __inline void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
3080 kprintf("stl_cd1400mdmisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
3083 ioack = inb(ioaddr + EREG_MDACK);
3084 if (((ioack & panelp->ackmask) != 0) ||
3085 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
3086 kprintf("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
3089 portp = panelp->ports[(ioack >> 3)];
3091 outb(ioaddr, (MISR + portp->uartaddr));
3092 misr = inb(ioaddr + EREG_DATA);
3093 if (misr & MISR_DCD) {
3094 portp->state |= ASY_DCDCHANGE;
3095 portp->stats.modem++;
3099 outb(ioaddr, (EOSRR + portp->uartaddr));
3100 outb((ioaddr + EREG_DATA), 0);
3103 /*****************************************************************************/
3106 * Interrupt service routine for cd1400 EasyIO boards.
3109 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3111 unsigned char svrtype;
3114 kprintf("stl_cd1400eiointr(panelp=%x,iobase=%x)\n", (int) panelp,
3119 svrtype = inb(iobase + EREG_DATA);
3120 if (panelp->nrports > 4) {
3121 outb(iobase, (SVRR + 0x80));
3122 svrtype |= inb(iobase + EREG_DATA);
3125 kprintf("stl_cd1400eiointr(panelp=%x,iobase=%x): svrr=%x\n", (int) panelp, iobase, svrtype);
3128 if (svrtype & SVRR_RX)
3129 stl_cd1400rxisr(panelp, iobase);
3130 else if (svrtype & SVRR_TX)
3131 stl_cd1400txisr(panelp, iobase);
3132 else if (svrtype & SVRR_MDM)
3133 stl_cd1400mdmisr(panelp, iobase);
3136 /*****************************************************************************/
3139 * Interrupt service routine for cd1400 panels.
3142 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
3144 unsigned char svrtype;
3147 kprintf("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
3152 svrtype = inb(iobase + EREG_DATA);
3153 outb(iobase, (SVRR + 0x80));
3154 svrtype |= inb(iobase + EREG_DATA);
3155 if (svrtype & SVRR_RX)
3156 stl_cd1400rxisr(panelp, iobase);
3157 else if (svrtype & SVRR_TX)
3158 stl_cd1400txisr(panelp, iobase);
3159 else if (svrtype & SVRR_MDM)
3160 stl_cd1400mdmisr(panelp, iobase);
3163 /*****************************************************************************/
3166 * Set up the cd1400 registers for a port based on the termios port
3170 static int stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3172 unsigned int clkdiv;
3173 unsigned char cor1, cor2, cor3;
3174 unsigned char cor4, cor5, ccr;
3175 unsigned char srer, sreron, sreroff;
3176 unsigned char mcor1, mcor2, rtpr;
3177 unsigned char clk, div;
3180 kprintf("stl_cd1400setport(portp=%x,tiosp=%x): brdnr=%d portnr=%d\n",
3181 (int) portp, (int) tiosp, portp->brdnr, portp->portnr);
3199 * Set up the RX char ignore mask with those RX error types we
3200 * can ignore. We could have used some special modes of the cd1400
3201 * UART to help, but it is better this way because we can keep stats
3202 * on the number of each type of RX exception event.
3204 portp->rxignoremsk = 0;
3205 if (tiosp->c_iflag & IGNPAR)
3206 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
3207 if (tiosp->c_iflag & IGNBRK)
3208 portp->rxignoremsk |= ST_BREAK;
3210 portp->rxmarkmsk = ST_OVERRUN;
3211 if (tiosp->c_iflag & (INPCK | PARMRK))
3212 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3213 if (tiosp->c_iflag & BRKINT)
3214 portp->rxmarkmsk |= ST_BREAK;
3217 * Go through the char size, parity and stop bits and set all the
3218 * option registers appropriately.
3220 switch (tiosp->c_cflag & CSIZE) {
3235 if (tiosp->c_cflag & CSTOPB)
3240 if (tiosp->c_cflag & PARENB) {
3241 if (tiosp->c_cflag & PARODD)
3242 cor1 |= (COR1_PARENB | COR1_PARODD);
3244 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3246 cor1 |= COR1_PARNONE;
3250 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3251 * space for hardware flow control and the like. This should be set to
3252 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3253 * really be based on VTIME...
3255 cor3 |= FIFO_RXTHRESHOLD;
3259 * Calculate the baud rate timers. For now we will just assume that
3260 * the input and output baud are the same. Could have used a baud
3261 * table here, but this way we can generate virtually any baud rate
3264 if (tiosp->c_ispeed == 0)
3265 tiosp->c_ispeed = tiosp->c_ospeed;
3266 if ((tiosp->c_ospeed < 0) || (tiosp->c_ospeed > CD1400_MAXBAUD))
3269 if (tiosp->c_ospeed > 0) {
3270 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3271 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) /
3276 div = (unsigned char) clkdiv;
3280 * Check what form of modem signaling is required and set it up.
3282 if ((tiosp->c_cflag & CLOCAL) == 0) {
3285 sreron |= SRER_MODEM;
3289 * Setup cd1400 enhanced modes if we can. In particular we want to
3290 * handle as much of the flow control as possbile automatically. As
3291 * well as saving a few CPU cycles it will also greatly improve flow
3292 * control reliablilty.
3294 if (tiosp->c_iflag & IXON) {
3297 if (tiosp->c_iflag & IXANY)
3301 if (tiosp->c_cflag & CCTS_OFLOW)
3303 if (tiosp->c_cflag & CRTS_IFLOW)
3304 mcor1 |= FIFO_RTSTHRESHOLD;
3307 * All cd1400 register values calculated so go through and set them
3311 kprintf("SETPORT: portnr=%d panelnr=%d brdnr=%d\n", portp->portnr,
3312 portp->panelnr, portp->brdnr);
3313 kprintf(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n", cor1, cor2,
3315 kprintf(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3316 mcor1, mcor2, rtpr, sreron, sreroff);
3317 kprintf(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3318 kprintf(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3319 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP], tiosp->c_cc[VSTART],
3320 tiosp->c_cc[VSTOP]);
3324 BRDENABLE(portp->brdnr, portp->pagenr);
3325 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3326 srer = stl_cd1400getreg(portp, SRER);
3327 stl_cd1400setreg(portp, SRER, 0);
3328 ccr += stl_cd1400updatereg(portp, COR1, cor1);
3329 ccr += stl_cd1400updatereg(portp, COR2, cor2);
3330 ccr += stl_cd1400updatereg(portp, COR3, cor3);
3332 stl_cd1400ccrwait(portp);
3333 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3335 stl_cd1400setreg(portp, COR4, cor4);
3336 stl_cd1400setreg(portp, COR5, cor5);
3337 stl_cd1400setreg(portp, MCOR1, mcor1);
3338 stl_cd1400setreg(portp, MCOR2, mcor2);
3339 if (tiosp->c_ospeed == 0) {
3340 stl_cd1400setreg(portp, MSVR1, 0);
3342 stl_cd1400setreg(portp, MSVR1, MSVR1_DTR);
3343 stl_cd1400setreg(portp, TCOR, clk);
3344 stl_cd1400setreg(portp, TBPR, div);
3345 stl_cd1400setreg(portp, RCOR, clk);
3346 stl_cd1400setreg(portp, RBPR, div);
3348 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3349 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3350 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3351 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3352 stl_cd1400setreg(portp, RTPR, rtpr);
3353 mcor1 = stl_cd1400getreg(portp, MSVR1);
3354 if (mcor1 & MSVR1_DCD)
3355 portp->sigs |= TIOCM_CD;
3357 portp->sigs &= ~TIOCM_CD;
3358 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3359 BRDDISABLE(portp->brdnr);
3360 portp->state &= ~(ASY_RTSFLOWMODE | ASY_CTSFLOWMODE);
3361 portp->state |= ((tiosp->c_cflag & CRTS_IFLOW) ? ASY_RTSFLOWMODE : 0);
3362 portp->state |= ((tiosp->c_cflag & CCTS_OFLOW) ? ASY_CTSFLOWMODE : 0);
3363 stl_ttyoptim(portp, tiosp);
3369 /*****************************************************************************/
3372 * Action the flow control as required. The hw and sw args inform the
3373 * routine what flow control methods it should try.
3376 static void stl_cd1400sendflow(stlport_t *portp, int hw, int sw)
3380 kprintf("stl_cd1400sendflow(portp=%x,hw=%d,sw=%d)\n",
3381 (int) portp, hw, sw);
3385 BRDENABLE(portp->brdnr, portp->pagenr);
3386 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3389 stl_cd1400ccrwait(portp);
3391 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3392 portp->stats.rxxoff++;
3394 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3395 portp->stats.rxxon++;
3397 stl_cd1400ccrwait(portp);
3401 portp->state |= ASY_RTSFLOW;
3402 stl_cd1400setreg(portp, MCOR1,
3403 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3404 stl_cd1400setreg(portp, MSVR2, 0);
3405 portp->stats.rxrtsoff++;
3406 } else if (hw > 0) {
3407 portp->state &= ~ASY_RTSFLOW;
3408 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3409 stl_cd1400setreg(portp, MCOR1,
3410 (stl_cd1400getreg(portp, MCOR1) | FIFO_RTSTHRESHOLD));
3411 portp->stats.rxrtson++;
3414 BRDDISABLE(portp->brdnr);
3418 /*****************************************************************************/
3421 * Return the current state of data flow on this port. This is only
3422 * really interresting when determining if data has fully completed
3423 * transmission or not... This is easy for the cd1400, it accurately
3424 * maintains the busy port flag.
3427 static int stl_cd1400datastate(stlport_t *portp)
3430 kprintf("stl_cd1400datastate(portp=%x)\n", (int) portp);
3436 return((portp->state & ASY_TXBUSY) ? 1 : 0);
3439 /*****************************************************************************/
3442 * Set the state of the DTR and RTS signals. Got to do some extra
3443 * work here to deal hardware flow control.
3446 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3448 unsigned char msvr1, msvr2;
3451 kprintf("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n", (int) portp,
3463 BRDENABLE(portp->brdnr, portp->pagenr);
3464 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3466 if (portp->tty.t_cflag & CRTS_IFLOW) {
3468 stl_cd1400setreg(portp, MCOR1,
3469 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3470 portp->stats.rxrtsoff++;
3472 stl_cd1400setreg(portp, MCOR1,
3473 (stl_cd1400getreg(portp, MCOR1) |
3474 FIFO_RTSTHRESHOLD));
3475 portp->stats.rxrtson++;
3478 stl_cd1400setreg(portp, MSVR2, msvr2);
3481 stl_cd1400setreg(portp, MSVR1, msvr1);
3482 BRDDISABLE(portp->brdnr);
3486 /*****************************************************************************/
3489 * Get the state of the signals.
3492 static int stl_cd1400getsignals(stlport_t *portp)
3494 unsigned char msvr1, msvr2;
3498 kprintf("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3502 BRDENABLE(portp->brdnr, portp->pagenr);
3503 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3504 msvr1 = stl_cd1400getreg(portp, MSVR1);
3505 msvr2 = stl_cd1400getreg(portp, MSVR2);
3506 BRDDISABLE(portp->brdnr);
3510 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3511 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3512 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3513 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3515 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3516 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3523 /*****************************************************************************/
3526 * Enable or disable the Transmitter and/or Receiver.
3529 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3534 kprintf("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3535 (int) portp, rx, tx);
3540 ccr |= CCR_TXDISABLE;
3542 ccr |= CCR_TXENABLE;
3544 ccr |= CCR_RXDISABLE;
3546 ccr |= CCR_RXENABLE;
3549 BRDENABLE(portp->brdnr, portp->pagenr);
3550 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3551 stl_cd1400ccrwait(portp);
3552 stl_cd1400setreg(portp, CCR, ccr);
3553 stl_cd1400ccrwait(portp);
3554 BRDDISABLE(portp->brdnr);
3558 /*****************************************************************************/
3561 * Start or stop the Transmitter and/or Receiver.
3564 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3566 unsigned char sreron, sreroff;
3569 kprintf("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3570 (int) portp, rx, tx);
3576 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3578 sreron |= SRER_TXDATA;
3580 sreron |= SRER_TXEMPTY;
3582 sreroff |= SRER_RXDATA;
3584 sreron |= SRER_RXDATA;
3587 BRDENABLE(portp->brdnr, portp->pagenr);
3588 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3589 stl_cd1400setreg(portp, SRER,
3590 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3591 BRDDISABLE(portp->brdnr);
3593 portp->state |= ASY_TXBUSY;
3594 portp->tty.t_state |= TS_BUSY;
3599 /*****************************************************************************/
3602 * Disable all interrupts from this port.
3605 static void stl_cd1400disableintrs(stlport_t *portp)
3609 kprintf("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3613 BRDENABLE(portp->brdnr, portp->pagenr);
3614 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3615 stl_cd1400setreg(portp, SRER, 0);
3616 BRDDISABLE(portp->brdnr);
3620 /*****************************************************************************/
3622 static void stl_cd1400sendbreak(stlport_t *portp, long len)
3626 kprintf("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp,
3631 BRDENABLE(portp->brdnr, portp->pagenr);
3632 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3633 stl_cd1400setreg(portp, COR2,
3634 (stl_cd1400getreg(portp, COR2) | COR2_ETC));
3635 stl_cd1400setreg(portp, SRER,
3636 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3638 BRDDISABLE(portp->brdnr);
3641 portp->brklen = (len > 255) ? 255 : len;
3643 portp->brklen = len;
3646 portp->stats.txbreaks++;
3649 /*****************************************************************************/
3652 * Try and find and initialize all the ports on a panel. We don't care
3653 * what sort of board these ports are on - since the port io registers
3654 * are almost identical when dealing with ports.
3657 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3660 kprintf("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3661 (int) brdp, (int) panelp, (int) portp);
3664 if ((brdp == NULL) || (panelp == NULL) ||
3668 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3669 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3670 portp->uartaddr = (portp->portnr & 0x04) << 5;
3671 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3673 BRDENABLE(portp->brdnr, portp->pagenr);
3674 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3675 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3676 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3677 BRDDISABLE(portp->brdnr);
3680 /*****************************************************************************/
3683 * Inbitialize the UARTs in a panel. We don't care what sort of board
3684 * these ports are on - since the port io registers are almost
3685 * identical when dealing with ports.
3688 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3692 int nrchips, uartaddr, ioaddr;
3695 kprintf("stl_cd1400panelinit(brdp=%x,panelp=%x)\n", (int) brdp,
3699 BRDENABLE(panelp->brdnr, panelp->pagenr);
3702 * Check that each chip is present and started up OK.
3705 nrchips = panelp->nrports / CD1400_PORTS;
3706 for (i = 0; (i < nrchips); i++) {
3707 if (brdp->brdtype == BRD_ECHPCI) {
3708 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3709 ioaddr = panelp->iobase;
3711 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3713 uartaddr = (i & 0x01) ? 0x080 : 0;
3714 outb(ioaddr, (GFRCR + uartaddr));
3715 outb((ioaddr + EREG_DATA), 0);
3716 outb(ioaddr, (CCR + uartaddr));
3717 outb((ioaddr + EREG_DATA), CCR_RESETFULL);
3718 outb((ioaddr + EREG_DATA), CCR_RESETFULL);
3719 outb(ioaddr, (GFRCR + uartaddr));
3720 for (j = 0; (j < CCR_MAXWAIT); j++) {
3721 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3724 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3725 kprintf("STALLION: cd1400 not responding, "
3726 "board=%d panel=%d chip=%d\n", panelp->brdnr,
3727 panelp->panelnr, i);
3730 chipmask |= (0x1 << i);
3731 outb(ioaddr, (PPR + uartaddr));
3732 outb((ioaddr + EREG_DATA), PPR_SCALAR);
3736 BRDDISABLE(panelp->brdnr);
3740 /*****************************************************************************/
3741 /* SC26198 HARDWARE FUNCTIONS */
3742 /*****************************************************************************/
3745 * These functions get/set/update the registers of the sc26198 UARTs.
3746 * Access to the sc26198 registers is via an address/data io port pair.
3747 * (Maybe should make this inline...)
3750 static int stl_sc26198getreg(stlport_t *portp, int regnr)
3752 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3753 return(inb(portp->ioaddr + XP_DATA));
3756 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
3758 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3759 outb((portp->ioaddr + XP_DATA), value);
3762 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
3764 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3765 if (inb(portp->ioaddr + XP_DATA) != value) {
3766 outb((portp->ioaddr + XP_DATA), value);
3772 /*****************************************************************************/
3775 * Functions to get and set the sc26198 global registers.
3778 static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
3780 outb((portp->ioaddr + XP_ADDR), regnr);
3781 return(inb(portp->ioaddr + XP_DATA));
3785 static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
3787 outb((portp->ioaddr + XP_ADDR), regnr);
3788 outb((portp->ioaddr + XP_DATA), value);
3792 /*****************************************************************************/
3795 * Inbitialize the UARTs in a panel. We don't care what sort of board
3796 * these ports are on - since the port io registers are almost
3797 * identical when dealing with ports.
3800 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3803 int nrchips, ioaddr;
3806 kprintf("stl_sc26198panelinit(brdp=%x,panelp=%x)\n", (int) brdp,
3810 BRDENABLE(panelp->brdnr, panelp->pagenr);
3813 * Check that each chip is present and started up OK.
3816 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
3817 if (brdp->brdtype == BRD_ECHPCI)
3818 outb(brdp->ioctrl, panelp->pagenr);
3820 for (i = 0; (i < nrchips); i++) {
3821 ioaddr = panelp->iobase + (i * 4);
3822 outb((ioaddr + XP_ADDR), SCCR);
3823 outb((ioaddr + XP_DATA), CR_RESETALL);
3824 outb((ioaddr + XP_ADDR), TSTR);
3825 if (inb(ioaddr + XP_DATA) != 0) {
3826 kprintf("STALLION: sc26198 not responding, "
3827 "board=%d panel=%d chip=%d\n", panelp->brdnr,
3828 panelp->panelnr, i);
3831 chipmask |= (0x1 << i);
3832 outb((ioaddr + XP_ADDR), GCCR);
3833 outb((ioaddr + XP_DATA), GCCR_IVRTYPCHANACK);
3834 outb((ioaddr + XP_ADDR), WDTRCR);
3835 outb((ioaddr + XP_DATA), 0xff);
3838 BRDDISABLE(panelp->brdnr);
3842 /*****************************************************************************/
3845 * Initialize hardware specific port registers.
3848 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3851 kprintf("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
3852 (int) brdp, (int) panelp, (int) portp);
3855 if ((brdp == NULL) || (panelp == NULL) ||
3859 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
3860 portp->uartaddr = (portp->portnr & 0x07) << 4;
3861 portp->pagenr = panelp->pagenr;
3864 BRDENABLE(portp->brdnr, portp->pagenr);
3865 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
3866 BRDDISABLE(portp->brdnr);
3869 /*****************************************************************************/
3872 * Set up the sc26198 registers for a port based on the termios port
3876 static int stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
3878 unsigned char mr0, mr1, mr2, clk;
3879 unsigned char imron, imroff, iopr, ipr;
3882 kprintf("stl_sc26198setport(portp=%x,tiosp=%x): brdnr=%d portnr=%d\n",
3883 (int) portp, (int) tiosp, portp->brdnr, portp->portnr);
3895 * Set up the RX char ignore mask with those RX error types we
3898 portp->rxignoremsk = 0;
3899 if (tiosp->c_iflag & IGNPAR)
3900 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
3902 if (tiosp->c_iflag & IGNBRK)
3903 portp->rxignoremsk |= SR_RXBREAK;
3905 portp->rxmarkmsk = SR_RXOVERRUN;
3906 if (tiosp->c_iflag & (INPCK | PARMRK))
3907 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
3908 if (tiosp->c_iflag & BRKINT)
3909 portp->rxmarkmsk |= SR_RXBREAK;
3912 * Go through the char size, parity and stop bits and set all the
3913 * option registers appropriately.
3915 switch (tiosp->c_cflag & CSIZE) {
3930 if (tiosp->c_cflag & CSTOPB)
3935 if (tiosp->c_cflag & PARENB) {
3936 if (tiosp->c_cflag & PARODD)
3937 mr1 |= (MR1_PARENB | MR1_PARODD);
3939 mr1 |= (MR1_PARENB | MR1_PAREVEN);
3944 mr1 |= MR1_ERRBLOCK;
3947 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
3948 * space for hardware flow control and the like. This should be set to
3951 mr2 |= MR2_RXFIFOHALF;
3954 * Calculate the baud rate timers. For now we will just assume that
3955 * the input and output baud are the same. The sc26198 has a fixed
3956 * baud rate table, so only discrete baud rates possible.
3958 if (tiosp->c_ispeed == 0)
3959 tiosp->c_ispeed = tiosp->c_ospeed;
3960 if ((tiosp->c_ospeed < 0) || (tiosp->c_ospeed > SC26198_MAXBAUD))
3963 if (tiosp->c_ospeed > 0) {
3964 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
3965 if (tiosp->c_ospeed <= sc26198_baudtable[clk])
3971 * Check what form of modem signaling is required and set it up.
3973 if ((tiosp->c_cflag & CLOCAL) == 0) {
3974 iopr |= IOPR_DCDCOS;
3979 * Setup sc26198 enhanced modes if we can. In particular we want to
3980 * handle as much of the flow control as possible automatically. As
3981 * well as saving a few CPU cycles it will also greatly improve flow
3982 * control reliability.
3984 if (tiosp->c_iflag & IXON) {
3985 mr0 |= MR0_SWFTX | MR0_SWFT;
3986 imron |= IR_XONXOFF;
3988 imroff |= IR_XONXOFF;
3991 if (tiosp->c_iflag & IXOFF)
3995 if (tiosp->c_cflag & CCTS_OFLOW)
3997 if (tiosp->c_cflag & CRTS_IFLOW)
4001 * All sc26198 register values calculated so go through and set
4006 kprintf("SETPORT: portnr=%d panelnr=%d brdnr=%d\n", portp->portnr,
4007 portp->panelnr, portp->brdnr);
4008 kprintf(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4009 kprintf(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4010 kprintf(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4011 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4012 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4016 BRDENABLE(portp->brdnr, portp->pagenr);
4017 stl_sc26198setreg(portp, IMR, 0);
4018 stl_sc26198updatereg(portp, MR0, mr0);
4019 stl_sc26198updatereg(portp, MR1, mr1);
4020 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4021 stl_sc26198updatereg(portp, MR2, mr2);
4022 iopr = (stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr;
4023 if (tiosp->c_ospeed == 0) {
4027 stl_sc26198setreg(portp, TXCSR, clk);
4028 stl_sc26198setreg(portp, RXCSR, clk);
4030 stl_sc26198updatereg(portp, IOPIOR, iopr);
4031 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4032 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4033 ipr = stl_sc26198getreg(portp, IPR);
4035 portp->sigs &= ~TIOCM_CD;
4037 portp->sigs |= TIOCM_CD;
4038 portp->imr = (portp->imr & ~imroff) | imron;
4039 stl_sc26198setreg(portp, IMR, portp->imr);
4040 BRDDISABLE(portp->brdnr);
4041 portp->state &= ~(ASY_RTSFLOWMODE | ASY_CTSFLOWMODE);
4042 portp->state |= ((tiosp->c_cflag & CRTS_IFLOW) ? ASY_RTSFLOWMODE : 0);
4043 portp->state |= ((tiosp->c_cflag & CCTS_OFLOW) ? ASY_CTSFLOWMODE : 0);
4044 stl_ttyoptim(portp, tiosp);
4050 /*****************************************************************************/
4053 * Set the state of the DTR and RTS signals.
4056 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
4058 unsigned char iopioron, iopioroff;
4061 kprintf("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4062 (int) portp, dtr, rts);
4068 iopioroff |= IPR_DTR;
4070 iopioron |= IPR_DTR;
4072 iopioroff |= IPR_RTS;
4074 iopioron |= IPR_RTS;
4077 BRDENABLE(portp->brdnr, portp->pagenr);
4078 if ((rts >= 0) && (portp->tty.t_cflag & CRTS_IFLOW)) {
4080 stl_sc26198setreg(portp, MR1,
4081 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4082 portp->stats.rxrtsoff++;
4084 stl_sc26198setreg(portp, MR1,
4085 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4086 portp->stats.rxrtson++;
4089 stl_sc26198setreg(portp, IOPIOR,
4090 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4091 BRDDISABLE(portp->brdnr);
4095 /*****************************************************************************/
4098 * Return the state of the signals.
4101 static int stl_sc26198getsignals(stlport_t *portp)
4107 kprintf("stl_sc26198getsignals(portp=%x)\n", (int) portp);
4111 BRDENABLE(portp->brdnr, portp->pagenr);
4112 ipr = stl_sc26198getreg(portp, IPR);
4113 BRDDISABLE(portp->brdnr);
4117 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4118 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4119 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4120 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4124 /*****************************************************************************/
4127 * Enable/Disable the Transmitter and/or Receiver.
4130 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
4135 kprintf("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4136 (int) portp, rx, tx);
4139 ccr = portp->crenable;
4141 ccr &= ~CR_TXENABLE;
4145 ccr &= ~CR_RXENABLE;
4150 BRDENABLE(portp->brdnr, portp->pagenr);
4151 stl_sc26198setreg(portp, SCCR, ccr);
4152 BRDDISABLE(portp->brdnr);
4153 portp->crenable = ccr;
4157 /*****************************************************************************/
4160 * Start/stop the Transmitter and/or Receiver.
4163 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
4168 kprintf("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4169 (int) portp, rx, tx);
4178 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4180 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4183 BRDENABLE(portp->brdnr, portp->pagenr);
4184 stl_sc26198setreg(portp, IMR, imr);
4185 BRDDISABLE(portp->brdnr);
4188 portp->state |= ASY_TXBUSY;
4189 portp->tty.t_state |= TS_BUSY;
4194 /*****************************************************************************/
4197 * Disable all interrupts from this port.
4200 static void stl_sc26198disableintrs(stlport_t *portp)
4204 kprintf("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
4208 BRDENABLE(portp->brdnr, portp->pagenr);
4210 stl_sc26198setreg(portp, IMR, 0);
4211 BRDDISABLE(portp->brdnr);
4215 /*****************************************************************************/
4217 static void stl_sc26198sendbreak(stlport_t *portp, long len)
4221 kprintf("stl_sc26198sendbreak(portp=%x,len=%d)\n",
4222 (int) portp, (int) len);
4226 BRDENABLE(portp->brdnr, portp->pagenr);
4228 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4229 portp->stats.txbreaks++;
4231 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4233 BRDDISABLE(portp->brdnr);
4237 /*****************************************************************************/
4240 * Take flow control actions...
4243 static void stl_sc26198sendflow(stlport_t *portp, int hw, int sw)
4248 kprintf("stl_sc26198sendflow(portp=%x,hw=%d,sw=%d)\n",
4249 (int) portp, hw, sw);
4256 BRDENABLE(portp->brdnr, portp->pagenr);
4259 mr0 = stl_sc26198getreg(portp, MR0);
4260 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4262 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4264 portp->stats.rxxoff++;
4266 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4268 portp->stats.rxxon++;
4270 stl_sc26198wait(portp);
4271 stl_sc26198setreg(portp, MR0, mr0);
4275 portp->state |= ASY_RTSFLOW;
4276 stl_sc26198setreg(portp, MR1,
4277 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4278 stl_sc26198setreg(portp, IOPIOR,
4279 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4280 portp->stats.rxrtsoff++;
4281 } else if (hw > 0) {
4282 portp->state &= ~ASY_RTSFLOW;
4283 stl_sc26198setreg(portp, MR1,
4284 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4285 stl_sc26198setreg(portp, IOPIOR,
4286 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4287 portp->stats.rxrtson++;
4290 BRDDISABLE(portp->brdnr);
4294 /*****************************************************************************/
4297 * Return the current state of data flow on this port. This is only
4298 * really interresting when determining if data has fully completed
4299 * transmission or not... The sc26198 interrupt scheme cannot
4300 * determine when all data has actually drained, so we need to
4301 * check the port statusy register to be sure.
4304 static int stl_sc26198datastate(stlport_t *portp)
4309 kprintf("stl_sc26198datastate(portp=%x)\n", (int) portp);
4314 if (portp->state & ASY_TXBUSY)
4318 BRDENABLE(portp->brdnr, portp->pagenr);
4319 sr = stl_sc26198getreg(portp, SR);
4320 BRDDISABLE(portp->brdnr);
4323 return((sr & SR_TXEMPTY) ? 0 : 1);
4326 /*****************************************************************************/
4328 static void stl_sc26198flush(stlport_t *portp, int flag)
4332 kprintf("stl_sc26198flush(portp=%x,flag=%x)\n", (int) portp, flag);
4339 BRDENABLE(portp->brdnr, portp->pagenr);
4340 if (flag & FWRITE) {
4341 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4342 stl_sc26198setreg(portp, SCCR, portp->crenable);
4345 while (stl_sc26198getreg(portp, SR) & SR_RXRDY)
4346 stl_sc26198getreg(portp, RXFIFO);
4348 BRDDISABLE(portp->brdnr);
4352 /*****************************************************************************/
4355 * If we are TX flow controlled and in IXANY mode then we may
4356 * need to unflow control here. We gotta do this because of the
4357 * automatic flow control modes of the sc26198 - which downs't
4358 * support any concept of an IXANY mode.
4361 static void stl_sc26198txunflow(stlport_t *portp)
4365 mr0 = stl_sc26198getreg(portp, MR0);
4366 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4367 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4368 stl_sc26198setreg(portp, MR0, mr0);
4369 portp->state &= ~ASY_TXFLOWED;
4372 /*****************************************************************************/
4375 * Delay for a small amount of time, to give the sc26198 a chance
4376 * to process a command...
4379 static void stl_sc26198wait(stlport_t *portp)
4384 kprintf("stl_sc26198wait(portp=%x)\n", (int) portp);
4390 for (i = 0; (i < 20); i++)
4391 stl_sc26198getglobreg(portp, TSTR);
4394 /*****************************************************************************/
4397 * Transmit interrupt handler. This has gotta be fast! Handling TX
4398 * chars is pretty simple, stuff as many as possible from the TX buffer
4399 * into the sc26198 FIFO.
4402 static __inline void stl_sc26198txisr(stlport_t *portp)
4404 unsigned int ioaddr;
4410 kprintf("stl_sc26198txisr(portp=%x)\n", (int) portp);
4413 ioaddr = portp->ioaddr;
4415 head = portp->tx.head;
4416 tail = portp->tx.tail;
4417 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4418 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4419 ((portp->state & ASY_TXLOW) == 0))) {
4420 portp->state |= ASY_TXLOW;
4425 outb((ioaddr + XP_ADDR), (MR0 | portp->uartaddr));
4426 mr0 = inb(ioaddr + XP_DATA);
4427 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4428 portp->imr &= ~IR_TXRDY;
4429 outb((ioaddr + XP_ADDR), (IMR | portp->uartaddr));
4430 outb((ioaddr + XP_DATA), portp->imr);
4431 portp->state |= ASY_TXEMPTY;
4432 portp->state &= ~ASY_TXBUSY;
4434 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4435 outb((ioaddr + XP_DATA), mr0);
4438 len = MIN(len, SC26198_TXFIFOSIZE);
4439 portp->stats.txtotal += len;
4440 stlen = MIN(len, (portp->tx.endbuf - tail));
4441 outb((ioaddr + XP_ADDR), GTXFIFO);
4442 outsb((ioaddr + XP_DATA), tail, stlen);
4445 if (tail >= portp->tx.endbuf)
4446 tail = portp->tx.buf;
4448 outsb((ioaddr + XP_DATA), tail, len);
4451 portp->tx.tail = tail;
4455 /*****************************************************************************/
4458 * Receive character interrupt handler. Determine if we have good chars
4459 * or bad chars and then process appropriately. Good chars are easy
4460 * just shove the lot into the RX buffer and set all status byte to 0.
4461 * If a bad RX char then process as required. This routine needs to be
4465 static __inline void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
4468 kprintf("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
4471 if ((iack & IVR_TYPEMASK) == IVR_RXDATA)
4472 stl_sc26198rxgoodchars(portp);
4474 stl_sc26198rxbadchars(portp);
4477 * If we are TX flow controlled and in IXANY mode then we may need
4478 * to unflow control here. We gotta do this because of the automatic
4479 * flow control modes of the sc26198.
4481 if ((portp->state & ASY_TXFLOWED) && (portp->tty.t_iflag & IXANY))
4482 stl_sc26198txunflow(portp);
4485 /*****************************************************************************/
4488 * Process the good received characters from RX FIFO.
4491 static void stl_sc26198rxgoodchars(stlport_t *portp)
4493 unsigned int ioaddr, len, buflen, stlen;
4497 kprintf("stl_sc26198rxgoodchars(port=%x)\n", (int) portp);
4500 ioaddr = portp->ioaddr;
4503 * First up, calculate how much room there is in the RX ring queue.
4504 * We also want to keep track of the longest possible copy length,
4505 * this has to allow for the wrapping of the ring queue.
4507 head = portp->rx.head;
4508 tail = portp->rx.tail;
4510 buflen = STL_RXBUFSIZE - (head - tail) - 1;
4511 stlen = portp->rx.endbuf - head;
4513 buflen = tail - head - 1;
4518 * Check if the input buffer is near full. If so then we should take
4519 * some flow control action... It is very easy to do hardware and
4520 * software flow control from here since we have the port selected on
4523 if (buflen <= (STL_RXBUFSIZE - STL_RXBUFHIGH)) {
4524 if (((portp->state & ASY_RTSFLOW) == 0) &&
4525 (portp->state & ASY_RTSFLOWMODE)) {
4526 portp->state |= ASY_RTSFLOW;
4527 stl_sc26198setreg(portp, MR1,
4528 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4529 stl_sc26198setreg(portp, IOPIOR,
4530 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4531 portp->stats.rxrtsoff++;
4536 * OK we are set, process good data... If the RX ring queue is full
4537 * just chuck the chars - don't leave them in the UART.
4539 outb((ioaddr + XP_ADDR), GIBCR);
4540 len = inb(ioaddr + XP_DATA) + 1;
4542 outb((ioaddr + XP_ADDR), GRXFIFO);
4543 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4544 portp->stats.rxlost += len;
4545 portp->stats.rxtotal += len;
4547 len = MIN(len, buflen);
4548 portp->stats.rxtotal += len;
4549 stlen = MIN(len, stlen);
4551 outb((ioaddr + XP_ADDR), GRXFIFO);
4552 insb((ioaddr + XP_DATA), head, stlen);
4554 if (head >= portp->rx.endbuf) {
4555 head = portp->rx.buf;
4557 insb((ioaddr + XP_DATA), head, len);
4563 portp->rx.head = head;
4564 portp->state |= ASY_RXDATA;
4568 /*****************************************************************************/
4571 * Process all characters in the RX FIFO of the UART. Check all char
4572 * status bytes as well, and process as required. We need to check
4573 * all bytes in the FIFO, in case some more enter the FIFO while we
4574 * are here. To get the exact character error type we need to switch
4575 * into CHAR error mode (that is why we need to make sure we empty
4579 static void stl_sc26198rxbadchars(stlport_t *portp)
4582 unsigned int status;
4588 * First up, calculate how much room there is in the RX ring queue.
4589 * We also want to keep track of the longest possible copy length,
4590 * this has to allow for the wrapping of the ring queue.
4592 head = portp->rx.head;
4593 tail = portp->rx.tail;
4594 len = (head >= tail) ? (STL_RXBUFSIZE - (head - tail) - 1) :
4598 * To get the precise error type for each character we must switch
4599 * back into CHAR error mode.
4601 mr1 = stl_sc26198getreg(portp, MR1);
4602 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
4604 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
4605 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
4606 ch = stl_sc26198getreg(portp, RXFIFO);
4608 if (status & SR_RXBREAK)
4609 portp->stats.rxbreaks++;
4610 if (status & SR_RXFRAMING)
4611 portp->stats.rxframing++;
4612 if (status & SR_RXPARITY)
4613 portp->stats.rxparity++;
4614 if (status & SR_RXOVERRUN)
4615 portp->stats.rxoverrun++;
4616 if ((portp->rxignoremsk & status) == 0) {
4617 if ((portp->tty.t_state & TS_CAN_BYPASS_L_RINT) &&
4618 ((status & SR_RXFRAMING) ||
4619 ((status & SR_RXPARITY) &&
4620 (portp->tty.t_iflag & INPCK))))
4622 if ((portp->rxmarkmsk & status) == 0)
4625 *(head + STL_RXBUFSIZE) = status;
4627 if (head >= portp->rx.endbuf)
4628 head = portp->rx.buf;
4635 * To get correct interrupt class we must switch back into BLOCK
4638 stl_sc26198setreg(portp, MR1, mr1);
4640 portp->rx.head = head;
4641 portp->state |= ASY_RXDATA;
4645 /*****************************************************************************/
4648 * Other interrupt handler. This includes modem signals, flow
4649 * control actions, etc.
4652 static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
4654 unsigned char cir, ipr, xisr;
4657 kprintf("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
4660 cir = stl_sc26198getglobreg(portp, CIR);
4662 switch (cir & CIR_SUBTYPEMASK) {
4664 ipr = stl_sc26198getreg(portp, IPR);
4665 if (ipr & IPR_DCDCHANGE) {
4666 portp->state |= ASY_DCDCHANGE;
4667 portp->stats.modem++;
4671 case CIR_SUBXONXOFF:
4672 xisr = stl_sc26198getreg(portp, XISR);
4673 if (xisr & XISR_RXXONGOT) {
4674 portp->state |= ASY_TXFLOWED;
4675 portp->stats.txxoff++;
4677 if (xisr & XISR_RXXOFFGOT) {
4678 portp->state &= ~ASY_TXFLOWED;
4679 portp->stats.txxon++;
4683 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
4684 stl_sc26198rxbadchars(portp);
4691 /*****************************************************************************/
4694 * Interrupt service routine for sc26198 panels.
4697 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4703 * Work around bug in sc26198 chip... Cannot have A6 address
4704 * line of UART high, else iack will be returned as 0.
4706 outb((iobase + 1), 0);
4708 iack = inb(iobase + XP_IACK);
4710 kprintf("stl_sc26198intr(panelp=%p,iobase=%x): iack=%x\n", panelp, iobase, iack);
4712 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4714 if (iack & IVR_RXDATA)
4715 stl_sc26198rxisr(portp, iack);
4716 else if (iack & IVR_TXDATA)
4717 stl_sc26198txisr(portp);
4719 stl_sc26198otherisr(portp, iack);
4722 /*****************************************************************************/