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.8 2003/11/22 19:30:56 asmodai 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>
54 #include <sys/fcntl.h>
55 #include <bus/isa/i386/isa_device.h>
56 #include <i386/isa/ic/scd1400.h>
57 #include <i386/isa/ic/sc26198.h>
58 #include <machine/comstats.h>
61 #include <bus/pci/pcivar.h>
62 #include <bus/pci/pcireg.h>
67 /*****************************************************************************/
70 * Define the version level of the kernel - so we can compile in the
71 * appropriate bits of code. By default this will compile for a 2.1
82 /*****************************************************************************/
85 * Define different board types. At the moment I have only declared
86 * those boards that this driver supports. But I will use the standard
87 * "assigned" board numbers. In the future this driver will support
88 * some of the other Stallion boards. Currently supported boards are
89 * abbreviated as EIO = EasyIO and ECH = EasyConnection 8/32.
95 #define BRD_ECH64PCI 27
96 #define BRD_EASYIOPCI 28
99 * When using the BSD "config" stuff there is no easy way to specifiy
100 * a secondary IO address region. So it is hard wired here. Also the
101 * shared interrupt information is hard wired here...
103 static unsigned int stl_ioshared = 0x280;
104 static unsigned int stl_irqshared = 0;
106 /*****************************************************************************/
109 * Define important driver limitations.
111 #define STL_MAXBRDS 8
112 #define STL_MAXPANELS 4
113 #define STL_MAXBANKS 8
114 #define STL_PORTSPERPANEL 16
115 #define STL_PORTSPERBRD 64
118 * Define the important minor number break down bits. These have been
119 * chosen to be "compatible" with the standard sio driver minor numbers.
120 * Extra high bits are used to distinguish between boards.
122 #define STL_CALLOUTDEV 0x80
123 #define STL_CTRLLOCK 0x40
124 #define STL_CTRLINIT 0x20
125 #define STL_CTRLDEV (STL_CTRLLOCK | STL_CTRLINIT)
127 #define STL_MEMDEV 0x07000000
129 #define STL_DEFSPEED TTYDEF_SPEED
130 #define STL_DEFCFLAG (CS8 | CREAD | HUPCL)
133 * I haven't really decided (or measured) what buffer sizes give
134 * a good balance between performance and memory usage. These seem
135 * to work pretty well...
137 #define STL_RXBUFSIZE 2048
138 #define STL_TXBUFSIZE 2048
140 #define STL_TXBUFLOW (STL_TXBUFSIZE / 4)
141 #define STL_RXBUFHIGH (3 * STL_RXBUFSIZE / 4)
143 /*****************************************************************************/
146 * Define our local driver identity first. Set up stuff to deal with
147 * all the local structures required by a serial tty driver.
149 static const char stl_drvname[] = "stl";
150 static const char stl_longdrvname[] = "Stallion Multiport Serial Driver";
151 static const char stl_drvversion[] = "2.0.0";
152 static int stl_brdprobed[STL_MAXBRDS];
154 static int stl_nrbrds = 0;
155 static int stl_doingtimeout = 0;
157 static const char __file__[] = /*__FILE__*/ "stallion.c";
160 * Define global stats structures. Not used often, and can be
161 * re-used for each stats call.
163 static combrd_t stl_brdstats;
164 static comstats_t stl_comstats;
166 /*****************************************************************************/
169 * Define a set of structures to hold all the board/panel/port info
170 * for our ports. These will be dynamically allocated as required.
174 * Define a ring queue structure for each port. This will hold the
175 * TX data waiting to be output. Characters are fed into this buffer
176 * from the line discipline (or even direct from user space!) and
177 * then fed into the UARTs during interrupts. Will use a clasic ring
178 * queue here for this. The good thing about this type of ring queue
179 * is that the head and tail pointers can be updated without interrupt
180 * protection - since "write" code only needs to change the head, and
181 * interrupt code only needs to change the tail.
191 * Port, panel and board structures to hold status info about each.
192 * The board structure contains pointers to structures for each panel
193 * connected to it, and in turn each panel structure contains pointers
194 * for each port structure for each port on that panel. Note that
195 * the port structure also contains the board and panel number that it
196 * is associated with, this makes it (fairly) easy to get back to the
197 * board/panel info for a port. Also note that the tty struct is at
198 * the top of the structure, this is important, since the code uses
199 * this fact to get the port struct pointer from the tty struct
202 typedef struct stlport {
220 unsigned int rxignoremsk;
221 unsigned int rxmarkmsk;
222 unsigned int crenable;
225 struct termios initintios;
226 struct termios initouttios;
227 struct termios lockintios;
228 struct termios lockouttios;
229 struct timeval timestamp;
236 typedef struct stlpanel {
243 unsigned int ackmask;
244 void (*isr)(struct stlpanel *panelp, unsigned int iobase);
246 stlport_t *ports[STL_PORTSPERPANEL];
249 typedef struct stlbrd {
259 unsigned int ioaddr1;
260 unsigned int ioaddr2;
261 unsigned int iostatus;
263 unsigned int ioctrlval;
266 void (*isr)(struct stlbrd *brdp);
267 unsigned int bnkpageaddr[STL_MAXBANKS];
268 unsigned int bnkstataddr[STL_MAXBANKS];
269 stlpanel_t *bnk2panel[STL_MAXBANKS];
270 stlpanel_t *panels[STL_MAXPANELS];
271 stlport_t *ports[STL_PORTSPERBRD];
274 static stlbrd_t *stl_brds[STL_MAXBRDS];
277 * Per board state flags. Used with the state field of the board struct.
278 * Not really much here yet!
280 #define BRD_FOUND 0x1
283 * Define the port structure state flags. These set of flags are
284 * modified at interrupt time - so setting and reseting them needs
287 #define ASY_TXLOW 0x1
288 #define ASY_RXDATA 0x2
289 #define ASY_DCDCHANGE 0x4
290 #define ASY_DTRWAIT 0x8
291 #define ASY_RTSFLOW 0x10
292 #define ASY_RTSFLOWMODE 0x20
293 #define ASY_CTSFLOWMODE 0x40
294 #define ASY_TXFLOWED 0x80
295 #define ASY_TXBUSY 0x100
296 #define ASY_TXEMPTY 0x200
298 #define ASY_ACTIVE (ASY_TXLOW | ASY_RXDATA | ASY_DCDCHANGE)
301 * Define an array of board names as printable strings. Handy for
302 * referencing boards when printing trace and stuff.
304 static char *stl_brdnames[] = {
336 /*****************************************************************************/
339 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
340 * to the directly accessable io ports of these boards (not the cd1400
341 * uarts - they are in scd1400.h).
343 #define EIO_8PORTRS 0x04
344 #define EIO_4PORTRS 0x05
345 #define EIO_8PORTDI 0x00
346 #define EIO_8PORTM 0x06
348 #define EIO_IDBITMASK 0x07
350 #define EIO_BRDMASK 0xf0
353 #define ID_BRD16 0x30
355 #define EIO_INTRPEND 0x08
356 #define EIO_INTEDGE 0x00
357 #define EIO_INTLEVEL 0x08
360 #define ECH_IDBITMASK 0xe0
361 #define ECH_BRDENABLE 0x08
362 #define ECH_BRDDISABLE 0x00
363 #define ECH_INTENABLE 0x01
364 #define ECH_INTDISABLE 0x00
365 #define ECH_INTLEVEL 0x02
366 #define ECH_INTEDGE 0x00
367 #define ECH_INTRPEND 0x01
368 #define ECH_BRDRESET 0x01
370 #define ECHMC_INTENABLE 0x01
371 #define ECHMC_BRDRESET 0x02
373 #define ECH_PNLSTATUS 2
374 #define ECH_PNL16PORT 0x20
375 #define ECH_PNLIDMASK 0x07
376 #define ECH_PNLXPID 0x40
377 #define ECH_PNLINTRPEND 0x80
378 #define ECH_ADDR2MASK 0x1e0
380 #define EIO_CLK 25000000
381 #define EIO_CLK8M 20000000
382 #define ECH_CLK EIO_CLK
385 * Define the PCI vendor and device ID for Stallion PCI boards.
387 #define STL_PCINSVENDID 0x100b
388 #define STL_PCINSDEVID 0xd001
390 #define STL_PCIVENDID 0x124d
391 #define STL_PCI32DEVID 0x0000
392 #define STL_PCI64DEVID 0x0002
393 #define STL_PCIEIODEVID 0x0003
395 #define STL_PCIBADCLASS 0x0101
397 typedef struct stlpcibrd {
398 unsigned short vendid;
399 unsigned short devid;
403 static stlpcibrd_t stl_pcibrds[] = {
404 { STL_PCIVENDID, STL_PCI64DEVID, BRD_ECH64PCI },
405 { STL_PCIVENDID, STL_PCIEIODEVID, BRD_EASYIOPCI },
406 { STL_PCIVENDID, STL_PCI32DEVID, BRD_ECHPCI },
407 { STL_PCINSVENDID, STL_PCINSDEVID, BRD_ECHPCI },
410 static int stl_nrpcibrds = sizeof(stl_pcibrds) / sizeof(stlpcibrd_t);
412 /*****************************************************************************/
415 * Define the vector mapping bits for the programmable interrupt board
416 * hardware. These bits encode the interrupt for the board to use - it
417 * is software selectable (except the EIO-8M).
419 static unsigned char stl_vecmap[] = {
420 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
421 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
425 * Set up enable and disable macros for the ECH boards. They require
426 * the secondary io address space to be activated and deactivated.
427 * This way all ECH boards can share their secondary io region.
428 * If this is an ECH-PCI board then also need to set the page pointer
429 * to point to the correct page.
431 #define BRDENABLE(brdnr,pagenr) \
432 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
433 outb(stl_brds[(brdnr)]->ioctrl, \
434 (stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE));\
435 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
436 outb(stl_brds[(brdnr)]->ioctrl, (pagenr));
438 #define BRDDISABLE(brdnr) \
439 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
440 outb(stl_brds[(brdnr)]->ioctrl, \
441 (stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE));
444 * Define some spare buffer space for un-wanted received characters.
446 static char stl_unwanted[SC26198_RXFIFOSIZE];
448 /*****************************************************************************/
451 * Define macros to extract a brd and port number from a minor number.
452 * This uses the extended minor number range in the upper 2 bytes of
453 * the device number. This gives us plenty of minor numbers to play
456 #define MKDEV2BRD(m) ((minor(m) & 0x00700000) >> 20)
457 #define MKDEV2PORT(m) ((minor(m) & 0x1f) | ((minor(m) & 0x00010000) >> 11))
460 * Define some handy local macros...
463 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
466 /*****************************************************************************/
469 * Declare all those functions in this driver! First up is the set of
470 * externally visible functions.
473 static int stlprobe(struct isa_device *idp);
474 static int stlattach(struct isa_device *idp);
476 STATIC d_open_t stlopen;
477 STATIC d_close_t stlclose;
478 STATIC d_ioctl_t stlioctl;
481 * Internal function prototypes.
483 static stlport_t *stl_dev2port(dev_t dev);
484 static int stl_findfreeunit(void);
485 static int stl_rawopen(stlport_t *portp);
486 static int stl_rawclose(stlport_t *portp);
487 static void stl_flush(stlport_t *portp, int flag);
488 static int stl_param(struct tty *tp, struct termios *tiosp);
489 static void stl_start(struct tty *tp);
490 static void stl_stop(struct tty *tp, int);
491 static void stl_ttyoptim(stlport_t *portp, struct termios *tiosp);
492 static void stl_dotimeout(void);
493 static void stl_poll(void *arg);
494 static void stl_rxprocess(stlport_t *portp);
495 static void stl_flowcontrol(stlport_t *portp, int hw, int sw);
496 static void stl_dtrwakeup(void *arg);
497 static int stl_brdinit(stlbrd_t *brdp);
498 static int stl_initeio(stlbrd_t *brdp);
499 static int stl_initech(stlbrd_t *brdp);
500 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
501 static void stl_eiointr(stlbrd_t *brdp);
502 static void stl_echatintr(stlbrd_t *brdp);
503 static void stl_echmcaintr(stlbrd_t *brdp);
504 static void stl_echpciintr(stlbrd_t *brdp);
505 static void stl_echpci64intr(stlbrd_t *brdp);
506 static int stl_memioctl(dev_t dev, unsigned long cmd, caddr_t data,
507 int flag, struct thread *td);
508 static int stl_getbrdstats(caddr_t data);
509 static int stl_getportstats(stlport_t *portp, caddr_t data);
510 static int stl_clrportstats(stlport_t *portp, caddr_t data);
511 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
512 static ointhand2_t stlintr;
515 static const char *stlpciprobe(pcici_t tag, pcidi_t type);
516 static void stlpciattach(pcici_t tag, int unit);
517 static void stlpciintr(void * arg);
521 * CD1400 uart specific handling functions.
523 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value);
524 static int stl_cd1400getreg(stlport_t *portp, int regnr);
525 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value);
526 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
527 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
528 static int stl_cd1400setport(stlport_t *portp, struct termios *tiosp);
529 static int stl_cd1400getsignals(stlport_t *portp);
530 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts);
531 static void stl_cd1400ccrwait(stlport_t *portp);
532 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx);
533 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx);
534 static void stl_cd1400disableintrs(stlport_t *portp);
535 static void stl_cd1400sendbreak(stlport_t *portp, long len);
536 static void stl_cd1400sendflow(stlport_t *portp, int hw, int sw);
537 static int stl_cd1400datastate(stlport_t *portp);
538 static void stl_cd1400flush(stlport_t *portp, int flag);
539 static __inline void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr);
540 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr);
541 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr);
542 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase);
543 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase);
546 * SC26198 uart specific handling functions.
548 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value);
549 static int stl_sc26198getreg(stlport_t *portp, int regnr);
550 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value);
551 static int stl_sc26198getglobreg(stlport_t *portp, int regnr);
552 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
553 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
554 static int stl_sc26198setport(stlport_t *portp, struct termios *tiosp);
555 static int stl_sc26198getsignals(stlport_t *portp);
556 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts);
557 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx);
558 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx);
559 static void stl_sc26198disableintrs(stlport_t *portp);
560 static void stl_sc26198sendbreak(stlport_t *portp, long len);
561 static void stl_sc26198sendflow(stlport_t *portp, int hw, int sw);
562 static int stl_sc26198datastate(stlport_t *portp);
563 static void stl_sc26198flush(stlport_t *portp, int flag);
564 static void stl_sc26198txunflow(stlport_t *portp);
565 static void stl_sc26198wait(stlport_t *portp);
566 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase);
567 static void stl_sc26198txisr(stlport_t *port);
568 static void stl_sc26198rxisr(stlport_t *port, unsigned int iack);
569 static void stl_sc26198rxgoodchars(stlport_t *portp);
570 static void stl_sc26198rxbadchars(stlport_t *portp);
571 static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
573 /*****************************************************************************/
576 * Generic UART support structure.
578 typedef struct uart {
579 int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp);
580 void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
581 int (*setport)(stlport_t *portp, struct termios *tiosp);
582 int (*getsignals)(stlport_t *portp);
583 void (*setsignals)(stlport_t *portp, int dtr, int rts);
584 void (*enablerxtx)(stlport_t *portp, int rx, int tx);
585 void (*startrxtx)(stlport_t *portp, int rx, int tx);
586 void (*disableintrs)(stlport_t *portp);
587 void (*sendbreak)(stlport_t *portp, long len);
588 void (*sendflow)(stlport_t *portp, int hw, int sw);
589 void (*flush)(stlport_t *portp, int flag);
590 int (*datastate)(stlport_t *portp);
591 void (*intr)(stlpanel_t *panelp, unsigned int iobase);
595 * Define some macros to make calling these functions nice and clean.
597 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
598 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
599 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
600 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
601 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
602 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
603 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
604 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
605 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
606 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
607 #define stl_uartflush (* ((uart_t *) portp->uartp)->flush)
608 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
610 /*****************************************************************************/
613 * CD1400 UART specific data initialization.
615 static uart_t stl_cd1400uart = {
619 stl_cd1400getsignals,
620 stl_cd1400setsignals,
621 stl_cd1400enablerxtx,
623 stl_cd1400disableintrs,
632 * Define the offsets within the register bank of a cd1400 based panel.
633 * These io address offsets are common to the EasyIO board as well.
641 #define EREG_BANKSIZE 8
643 #define CD1400_CLK 25000000
644 #define CD1400_CLK8M 20000000
647 * Define the cd1400 baud rate clocks. These are used when calculating
648 * what clock and divisor to use for the required baud rate. Also
649 * define the maximum baud rate allowed, and the default base baud.
651 static int stl_cd1400clkdivs[] = {
652 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
656 * Define the maximum baud rate of the cd1400 devices.
658 #define CD1400_MAXBAUD 230400
660 /*****************************************************************************/
663 * SC26198 UART specific data initization.
665 static uart_t stl_sc26198uart = {
666 stl_sc26198panelinit,
669 stl_sc26198getsignals,
670 stl_sc26198setsignals,
671 stl_sc26198enablerxtx,
672 stl_sc26198startrxtx,
673 stl_sc26198disableintrs,
674 stl_sc26198sendbreak,
677 stl_sc26198datastate,
682 * Define the offsets within the register bank of a sc26198 based panel.
690 #define XP_BANKSIZE 4
693 * Define the sc26198 baud rate table. Offsets within the table
694 * represent the actual baud rate selector of sc26198 registers.
696 static unsigned int sc26198_baudtable[] = {
697 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
698 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
702 #define SC26198_NRBAUDS (sizeof(sc26198_baudtable) / sizeof(unsigned int))
705 * Define the maximum baud rate of the sc26198 devices.
707 #define SC26198_MAXBAUD 460800
709 /*****************************************************************************/
712 * Declare the driver isa structure.
714 struct isa_driver stldriver = {
715 stlprobe, stlattach, "stl"
718 /*****************************************************************************/
723 * Declare the driver pci structure.
725 static unsigned long stl_count;
727 static struct pci_device stlpcidriver = {
735 COMPAT_PCI_DRIVER (stlpci, stlpcidriver);
739 /*****************************************************************************/
744 * FreeBSD-2.2+ kernel linkage.
747 #define CDEV_MAJOR 72
748 static struct cdevsw stl_cdevsw = {
750 /* maj */ CDEV_MAJOR,
751 /* flags */ D_TTY | D_KQFILTER,
756 /* close */ stlclose,
758 /* write */ ttywrite,
759 /* ioctl */ stlioctl,
762 /* strategy */ nostrategy,
765 /* kqfilter */ ttykqfilter
768 static void stl_drvinit(void *unused)
771 cdevsw_add(&stl_cdevsw);
774 SYSINIT(sidev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,stl_drvinit,NULL)
778 /*****************************************************************************/
781 * Probe for some type of EasyIO or EasyConnection 8/32 board at
782 * the supplied address. All we do is check if we can find the
783 * board ID for the board... (Note, PCI boards not checked here,
784 * they are done in the stlpciprobe() routine).
787 static int stlprobe(struct isa_device *idp)
792 printf("stlprobe(idp=%x): unit=%d iobase=%x\n", (int) idp,
793 idp->id_unit, idp->id_iobase);
796 if (idp->id_unit > STL_MAXBRDS)
799 status = inb(idp->id_iobase + 1);
800 if ((status & ECH_IDBITMASK) == ECH_ID) {
801 stl_brdprobed[idp->id_unit] = BRD_ECH;
805 status = inb(idp->id_iobase + 2);
806 switch (status & EIO_IDBITMASK) {
812 stl_brdprobed[idp->id_unit] = BRD_EASYIO;
821 /*****************************************************************************/
824 * Find an available internal board number (unit number). The problem
825 * is that the same unit numbers can be assigned to different boards
826 * detected during the ISA and PCI initialization phases.
829 static int stl_findfreeunit()
833 for (i = 0; (i < STL_MAXBRDS); i++)
834 if (stl_brds[i] == (stlbrd_t *) NULL)
836 return((i >= STL_MAXBRDS) ? -1 : i);
839 /*****************************************************************************/
842 * Allocate resources for and initialize the specified board.
845 static int stlattach(struct isa_device *idp)
848 int boardnr, portnr, minor_dev;
851 printf("stlattach(idp=%p): unit=%d iobase=%x\n", (void *) idp,
852 idp->id_unit, idp->id_iobase);
855 /* idp->id_ointr = stlintr; */
857 brdp = (stlbrd_t *) malloc(sizeof(stlbrd_t), M_TTYS, M_NOWAIT);
858 if (brdp == (stlbrd_t *) NULL) {
859 printf("STALLION: failed to allocate memory (size=%d)\n",
863 bzero(brdp, sizeof(stlbrd_t));
865 if ((brdp->brdnr = stl_findfreeunit()) < 0) {
866 printf("STALLION: too many boards found, max=%d\n",
870 if (brdp->brdnr >= stl_nrbrds)
871 stl_nrbrds = brdp->brdnr + 1;
873 brdp->unitid = idp->id_unit;
874 brdp->brdtype = stl_brdprobed[idp->id_unit];
875 brdp->ioaddr1 = idp->id_iobase;
876 brdp->ioaddr2 = stl_ioshared;
877 brdp->irq = ffs(idp->id_irq) - 1;
878 brdp->irqtype = stl_irqshared;
881 /* register devices for DEVFS */
882 boardnr = brdp->brdnr;
883 make_dev(&stl_cdevsw, boardnr + 0x1000000, UID_ROOT, GID_WHEEL,
884 0600, "staliomem%d", boardnr);
886 for (portnr = 0, minor_dev = boardnr * 0x100000;
887 portnr < 32; portnr++, minor_dev++) {
889 make_dev(&stl_cdevsw, minor_dev,
890 UID_ROOT, GID_WHEEL, 0600,
891 "ttyE%d", portnr + (boardnr * 64));
892 make_dev(&stl_cdevsw, minor_dev + 32,
893 UID_ROOT, GID_WHEEL, 0600,
894 "ttyiE%d", portnr + (boardnr * 64));
895 make_dev(&stl_cdevsw, minor_dev + 64,
896 UID_ROOT, GID_WHEEL, 0600,
897 "ttylE%d", portnr + (boardnr * 64));
898 make_dev(&stl_cdevsw, minor_dev + 128,
899 UID_ROOT, GID_WHEEL, 0600,
900 "cue%d", portnr + (boardnr * 64));
901 make_dev(&stl_cdevsw, minor_dev + 160,
902 UID_ROOT, GID_WHEEL, 0600,
903 "cuie%d", portnr + (boardnr * 64));
904 make_dev(&stl_cdevsw, minor_dev + 192,
905 UID_ROOT, GID_WHEEL, 0600,
906 "cule%d", portnr + (boardnr * 64));
909 make_dev(&stl_cdevsw, minor_dev + 0x10000,
910 UID_ROOT, GID_WHEEL, 0600,
911 "ttyE%d", portnr + (boardnr * 64) + 32);
912 make_dev(&stl_cdevsw, minor_dev + 32 + 0x10000,
913 UID_ROOT, GID_WHEEL, 0600,
914 "ttyiE%d", portnr + (boardnr * 64) + 32);
915 make_dev(&stl_cdevsw, minor_dev + 64 + 0x10000,
916 UID_ROOT, GID_WHEEL, 0600,
917 "ttylE%d", portnr + (boardnr * 64) + 32);
918 make_dev(&stl_cdevsw, minor_dev + 128 + 0x10000,
919 UID_ROOT, GID_WHEEL, 0600,
920 "cue%d", portnr + (boardnr * 64) + 32);
921 make_dev(&stl_cdevsw, minor_dev + 160 + 0x10000,
922 UID_ROOT, GID_WHEEL, 0600,
923 "cuie%d", portnr + (boardnr * 64) + 32);
924 make_dev(&stl_cdevsw, minor_dev + 192 + 0x10000,
925 UID_ROOT, GID_WHEEL, 0600,
926 "cule%d", portnr + (boardnr * 64) + 32);
928 boardnr = brdp->brdnr;
929 make_dev(&stl_cdevsw, boardnr + 0x1000000, UID_ROOT, GID_WHEEL,
930 0600, "staliomem%d", boardnr);
932 for (portnr = 0, minor_dev = boardnr * 0x100000;
933 portnr < 32; portnr++, minor_dev++) {
935 make_dev(&stl_cdevsw, minor_dev,
936 UID_ROOT, GID_WHEEL, 0600,
937 "ttyE%d", portnr + (boardnr * 64));
938 make_dev(&stl_cdevsw, minor_dev + 32,
939 UID_ROOT, GID_WHEEL, 0600,
940 "ttyiE%d", portnr + (boardnr * 64));
941 make_dev(&stl_cdevsw, minor_dev + 64,
942 UID_ROOT, GID_WHEEL, 0600,
943 "ttylE%d", portnr + (boardnr * 64));
944 make_dev(&stl_cdevsw, minor_dev + 128,
945 UID_ROOT, GID_WHEEL, 0600,
946 "cue%d", portnr + (boardnr * 64));
947 make_dev(&stl_cdevsw, minor_dev + 160,
948 UID_ROOT, GID_WHEEL, 0600,
949 "cuie%d", portnr + (boardnr * 64));
950 make_dev(&stl_cdevsw, minor_dev + 192,
951 UID_ROOT, GID_WHEEL, 0600,
952 "cule%d", portnr + (boardnr * 64));
955 make_dev(&stl_cdevsw, minor_dev + 0x10000,
956 UID_ROOT, GID_WHEEL, 0600,
957 "ttyE%d", portnr + (boardnr * 64) + 32);
958 make_dev(&stl_cdevsw, minor_dev + 32 + 0x10000,
959 UID_ROOT, GID_WHEEL, 0600,
960 "ttyiE%d", portnr + (boardnr * 64) + 32);
961 make_dev(&stl_cdevsw, minor_dev + 64 + 0x10000,
962 UID_ROOT, GID_WHEEL, 0600,
963 "ttylE%d", portnr + (boardnr * 64) + 32);
964 make_dev(&stl_cdevsw, minor_dev + 128 + 0x10000,
965 UID_ROOT, GID_WHEEL, 0600,
966 "cue%d", portnr + (boardnr * 64) + 32);
967 make_dev(&stl_cdevsw, minor_dev + 160 + 0x10000,
968 UID_ROOT, GID_WHEEL, 0600,
969 "cuie%d", portnr + (boardnr * 64) + 32);
970 make_dev(&stl_cdevsw, minor_dev + 192 + 0x10000,
971 UID_ROOT, GID_WHEEL, 0600,
972 "cule%d", portnr + (boardnr * 64) + 32);
978 /*****************************************************************************/
983 * Probe specifically for the PCI boards. We need to be a little
984 * carefull here, since it looks sort like a Nat Semi IDE chip...
987 static const char *stlpciprobe(pcici_t tag, pcidi_t type)
993 printf("stlpciprobe(tag=%x,type=%x)\n", (int) &tag, (int) type);
997 for (i = 0; (i < stl_nrpcibrds); i++) {
998 if (((type & 0xffff) == stl_pcibrds[i].vendid) &&
999 (((type >> 16) & 0xffff) == stl_pcibrds[i].devid)) {
1000 brdtype = stl_pcibrds[i].brdtype;
1006 return((char *) NULL);
1008 class = pci_conf_read(tag, PCI_CLASS_REG);
1009 if ((class & PCI_CLASS_MASK) == PCI_CLASS_MASS_STORAGE)
1010 return((char *) NULL);
1012 return(stl_brdnames[brdtype]);
1015 /*****************************************************************************/
1018 * Allocate resources for and initialize the specified PCI board.
1021 void stlpciattach(pcici_t tag, int unit)
1024 unsigned int bar[4];
1027 int boardnr, portnr, minor_dev;
1030 printf("stlpciattach(tag=%x,unit=%x)\n", (int) &tag, unit);
1033 brdp = (stlbrd_t *) malloc(sizeof(stlbrd_t), M_TTYS, M_NOWAIT);
1034 if (brdp == (stlbrd_t *) NULL) {
1035 printf("STALLION: failed to allocate memory (size=%d)\n",
1039 bzero(brdp, sizeof(stlbrd_t));
1041 if ((unit < 0) || (unit > STL_MAXBRDS)) {
1042 printf("STALLION: bad PCI board unit number=%d\n", unit);
1047 * Allocate us a new driver unique unit number.
1049 if ((brdp->brdnr = stl_findfreeunit()) < 0) {
1050 printf("STALLION: too many boards found, max=%d\n",
1054 if (brdp->brdnr >= stl_nrbrds)
1055 stl_nrbrds = brdp->brdnr + 1;
1058 * Determine what type of PCI board this is...
1060 id = (unsigned int) pci_conf_read(tag, 0x0);
1061 for (i = 0; (i < stl_nrpcibrds); i++) {
1062 if (((id & 0xffff) == stl_pcibrds[i].vendid) &&
1063 (((id >> 16) & 0xffff) == stl_pcibrds[i].devid)) {
1064 brdp->brdtype = stl_pcibrds[i].brdtype;
1069 if (i >= stl_nrpcibrds) {
1070 printf("STALLION: probed PCI board unknown type=%x\n", id);
1074 for (i = 0; (i < 4); i++)
1075 bar[i] = (unsigned int) pci_conf_read(tag, 0x10 + (i * 4)) &
1078 switch (brdp->brdtype) {
1080 brdp->ioaddr1 = bar[1];
1081 brdp->ioaddr2 = bar[2];
1084 brdp->ioaddr1 = bar[2];
1085 brdp->ioaddr2 = bar[1];
1088 brdp->ioaddr1 = bar[1];
1089 brdp->ioaddr2 = bar[0];
1092 printf("STALLION: unknown PCI board type=%d\n", brdp->brdtype);
1097 brdp->unitid = brdp->brdnr; /* PCI units auto-assigned */
1098 brdp->irq = ((int) pci_conf_read(tag, 0x3c)) & 0xff;
1100 if (pci_map_int(tag, stlpciintr, (void *) NULL, &tty_imask) == 0) {
1101 printf("STALLION: failed to map interrupt irq=%d for unit=%d\n",
1102 brdp->irq, brdp->brdnr);
1108 /* register devices for DEVFS */
1109 boardnr = brdp->brdnr;
1110 make_dev(&stl_cdevsw, boardnr + 0x1000000, UID_ROOT, GID_WHEEL,
1111 0600, "staliomem%d", boardnr);
1113 for (portnr = 0, minor_dev = boardnr * 0x100000;
1114 portnr < 32; portnr++, minor_dev++) {
1116 make_dev(&stl_cdevsw, minor_dev,
1117 UID_ROOT, GID_WHEEL, 0600,
1118 "ttyE%d", portnr + (boardnr * 64));
1119 make_dev(&stl_cdevsw, minor_dev + 32,
1120 UID_ROOT, GID_WHEEL, 0600,
1121 "ttyiE%d", portnr + (boardnr * 64));
1122 make_dev(&stl_cdevsw, minor_dev + 64,
1123 UID_ROOT, GID_WHEEL, 0600,
1124 "ttylE%d", portnr + (boardnr * 64));
1125 make_dev(&stl_cdevsw, minor_dev + 128,
1126 UID_ROOT, GID_WHEEL, 0600,
1127 "cue%d", portnr + (boardnr * 64));
1128 make_dev(&stl_cdevsw, minor_dev + 160,
1129 UID_ROOT, GID_WHEEL, 0600,
1130 "cuie%d", portnr + (boardnr * 64));
1131 make_dev(&stl_cdevsw, minor_dev + 192,
1132 UID_ROOT, GID_WHEEL, 0600,
1133 "cule%d", portnr + (boardnr * 64));
1136 make_dev(&stl_cdevsw, minor_dev + 0x10000,
1137 UID_ROOT, GID_WHEEL, 0600,
1138 "ttyE%d", portnr + (boardnr * 64) + 32);
1139 make_dev(&stl_cdevsw, minor_dev + 32 + 0x10000,
1140 UID_ROOT, GID_WHEEL, 0600,
1141 "ttyiE%d", portnr + (boardnr * 64) + 32);
1142 make_dev(&stl_cdevsw, minor_dev + 64 + 0x10000,
1143 UID_ROOT, GID_WHEEL, 0600,
1144 "ttylE%d", portnr + (boardnr * 64) + 32);
1145 make_dev(&stl_cdevsw, minor_dev + 128 + 0x10000,
1146 UID_ROOT, GID_WHEEL, 0600,
1147 "cue%d", portnr + (boardnr * 64) + 32);
1148 make_dev(&stl_cdevsw, minor_dev + 160 + 0x10000,
1149 UID_ROOT, GID_WHEEL, 0600,
1150 "cuie%d", portnr + (boardnr * 64) + 32);
1151 make_dev(&stl_cdevsw, minor_dev + 192 + 0x10000,
1152 UID_ROOT, GID_WHEEL, 0600,
1153 "cule%d", portnr + (boardnr * 64) + 32);
1159 /*****************************************************************************/
1161 STATIC int stlopen(dev_t dev, int flag, int mode, struct thread *td)
1165 int error, callout, x;
1168 printf("stlopen(dev=%x,flag=%x,mode=%x,p=%x)\n", (int) dev, flag,
1173 * Firstly check if the supplied device number is a valid device.
1175 if (minor(dev) & STL_MEMDEV)
1178 portp = stl_dev2port(dev);
1179 if (portp == (stlport_t *) NULL)
1181 if (minor(dev) & STL_CTRLDEV)
1185 callout = minor(dev) & STL_CALLOUTDEV;
1192 * Wait here for the DTR drop timeout period to expire.
1194 while (portp->state & ASY_DTRWAIT) {
1195 error = tsleep(&portp->dtrwait, PCATCH, "stldtr", 0);
1201 * We have a valid device, so now we check if it is already open.
1202 * If not then initialize the port hardware and set up the tty
1203 * struct as required.
1205 if ((tp->t_state & TS_ISOPEN) == 0) {
1206 tp->t_oproc = stl_start;
1207 tp->t_stop = stl_stop;
1208 tp->t_param = stl_param;
1210 tp->t_termios = callout ? portp->initouttios :
1214 if ((portp->sigs & TIOCM_CD) || callout)
1215 (*linesw[tp->t_line].l_modem)(tp, 1);
1218 if (portp->callout == 0) {
1223 if (portp->callout != 0) {
1224 if (flag & O_NONBLOCK) {
1228 error = tsleep(&portp->callout,
1229 PCATCH, "stlcall", 0);
1232 goto stlopen_restart;
1235 if ((tp->t_state & TS_XCLUDE) && suser(td)) {
1242 * If this port is not the callout device and we do not have carrier
1243 * then we need to sleep, waiting for it to be asserted.
1245 if (((tp->t_state & TS_CARR_ON) == 0) && !callout &&
1246 ((tp->t_cflag & CLOCAL) == 0) &&
1247 ((flag & O_NONBLOCK) == 0)) {
1249 error = tsleep(TSA_CARR_ON(tp), PCATCH, "stldcd", 0);
1253 goto stlopen_restart;
1257 * Open the line discipline.
1259 error = (*linesw[tp->t_line].l_open)(dev, tp);
1260 stl_ttyoptim(portp, &tp->t_termios);
1261 if ((tp->t_state & TS_ISOPEN) && callout)
1265 * If for any reason we get to here and the port is not actually
1266 * open then close of the physical hardware - no point leaving it
1267 * active when the open failed...
1271 if (((tp->t_state & TS_ISOPEN) == 0) && (portp->waitopens == 0))
1272 stl_rawclose(portp);
1277 /*****************************************************************************/
1279 STATIC int stlclose(dev_t dev, int flag, int mode, struct thread *td)
1286 printf("stlclose(dev=%s,flag=%x,mode=%x,p=%p)\n", devtoname(dev),
1287 flag, mode, (void *) p);
1290 if (minor(dev) & STL_MEMDEV)
1292 if (minor(dev) & STL_CTRLDEV)
1295 portp = stl_dev2port(dev);
1296 if (portp == (stlport_t *) NULL)
1301 (*linesw[tp->t_line].l_close)(tp, flag);
1302 stl_ttyoptim(portp, &tp->t_termios);
1303 stl_rawclose(portp);
1309 /*****************************************************************************/
1313 STATIC void stl_stop(struct tty *tp, int rw)
1316 printf("stl_stop(tp=%x,rw=%x)\n", (int) tp, rw);
1319 stl_flush((stlport_t *) tp, rw);
1324 STATIC int stlstop(struct tty *tp, int rw)
1327 printf("stlstop(tp=%x,rw=%x)\n", (int) tp, rw);
1330 stl_flush((stlport_t *) tp, rw);
1336 /*****************************************************************************/
1338 STATIC int stlioctl(dev_t dev, unsigned long cmd, caddr_t data, int flag,
1341 struct termios *newtios, *localtios;
1347 printf("stlioctl(dev=%s,cmd=%lx,data=%p,flag=%x,p=%p)\n",
1348 devtoname(dev), cmd, (void *) data, flag, (void *) p);
1351 if (minor(dev) & STL_MEMDEV)
1352 return(stl_memioctl(dev, cmd, data, flag, td));
1354 portp = stl_dev2port(dev);
1355 if (portp == (stlport_t *) NULL)
1361 * First up handle ioctls on the control devices.
1363 if (minor(dev) & STL_CTRLDEV) {
1364 if ((minor(dev) & STL_CTRLDEV) == STL_CTRLINIT)
1365 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1366 &portp->initouttios : &portp->initintios;
1367 else if ((minor(dev) & STL_CTRLDEV) == STL_CTRLLOCK)
1368 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1369 &portp->lockouttios : &portp->lockintios;
1375 if ((error = suser(td)) == 0)
1376 *localtios = *((struct termios *) data);
1379 *((struct termios *) data) = *localtios;
1382 *((int *) data) = TTYDISC;
1385 bzero(data, sizeof(struct winsize));
1395 * Deal with 4.3 compatibility issues if we have too...
1397 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1399 struct termios tios;
1400 unsigned long oldcmd;
1402 tios = tp->t_termios;
1404 if ((error = ttsetcompat(tp, &cmd, data, &tios)))
1407 data = (caddr_t) &tios;
1412 * Carry out some pre-cmd processing work first...
1413 * Hmmm, not so sure we want this, disable for now...
1415 if ((cmd == TIOCSETA) || (cmd == TIOCSETAW) || (cmd == TIOCSETAF)) {
1416 newtios = (struct termios *) data;
1417 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1418 &portp->lockouttios : &portp->lockintios;
1420 newtios->c_iflag = (tp->t_iflag & localtios->c_iflag) |
1421 (newtios->c_iflag & ~localtios->c_iflag);
1422 newtios->c_oflag = (tp->t_oflag & localtios->c_oflag) |
1423 (newtios->c_oflag & ~localtios->c_oflag);
1424 newtios->c_cflag = (tp->t_cflag & localtios->c_cflag) |
1425 (newtios->c_cflag & ~localtios->c_cflag);
1426 newtios->c_lflag = (tp->t_lflag & localtios->c_lflag) |
1427 (newtios->c_lflag & ~localtios->c_lflag);
1428 for (i = 0; (i < NCCS); i++) {
1429 if (localtios->c_cc[i] != 0)
1430 newtios->c_cc[i] = tp->t_cc[i];
1432 if (localtios->c_ispeed != 0)
1433 newtios->c_ispeed = tp->t_ispeed;
1434 if (localtios->c_ospeed != 0)
1435 newtios->c_ospeed = tp->t_ospeed;
1439 * Call the line discipline and the common command processing to
1440 * process this command (if they can).
1442 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td);
1443 if (error != ENOIOCTL)
1447 error = ttioctl(tp, cmd, data, flag);
1448 stl_ttyoptim(portp, &tp->t_termios);
1449 if (error != ENOIOCTL) {
1457 * Process local commands here. These are all commands that only we
1458 * can take care of (they all rely on actually doing something special
1459 * to the actual hardware).
1463 stl_sendbreak(portp, -1);
1466 stl_sendbreak(portp, -2);
1469 stl_setsignals(portp, 1, -1);
1472 stl_setsignals(portp, 0, -1);
1475 i = *((int *) data);
1476 stl_setsignals(portp, ((i & TIOCM_DTR) ? 1 : 0),
1477 ((i & TIOCM_RTS) ? 1 : 0));
1480 i = *((int *) data);
1481 stl_setsignals(portp, ((i & TIOCM_DTR) ? 1 : -1),
1482 ((i & TIOCM_RTS) ? 1 : -1));
1485 i = *((int *) data);
1486 stl_setsignals(portp, ((i & TIOCM_DTR) ? 0 : -1),
1487 ((i & TIOCM_RTS) ? 0 : -1));
1490 *((int *) data) = (stl_getsignals(portp) | TIOCM_LE);
1493 if ((error = suser(td)) == 0)
1494 portp->dtrwait = *((int *) data) * hz / 100;
1497 *((int *) data) = portp->dtrwait * 100 / hz;
1500 portp->dotimestamp = 1;
1501 *((struct timeval *) data) = portp->timestamp;
1511 /*****************************************************************************/
1514 * Convert the specified minor device number into a port struct
1515 * pointer. Return NULL if the device number is not a valid port.
1518 STATIC stlport_t *stl_dev2port(dev_t dev)
1522 brdp = stl_brds[MKDEV2BRD(dev)];
1523 if (brdp == (stlbrd_t *) NULL)
1524 return((stlport_t *) NULL);
1525 return(brdp->ports[MKDEV2PORT(dev)]);
1528 /*****************************************************************************/
1531 * Initialize the port hardware. This involves enabling the transmitter
1532 * and receiver, setting the port configuration, and setting the initial
1536 static int stl_rawopen(stlport_t *portp)
1539 printf("stl_rawopen(portp=%p): brdnr=%d panelnr=%d portnr=%d\n",
1540 (void *) portp, portp->brdnr, portp->panelnr, portp->portnr);
1543 stl_setport(portp, &portp->tty.t_termios);
1544 portp->sigs = stl_getsignals(portp);
1545 stl_setsignals(portp, 1, 1);
1546 stl_enablerxtx(portp, 1, 1);
1547 stl_startrxtx(portp, 1, 0);
1551 /*****************************************************************************/
1554 * Shutdown the hardware of a port. Disable its transmitter and
1555 * receiver, and maybe drop signals if appropriate.
1558 static int stl_rawclose(stlport_t *portp)
1563 printf("stl_rawclose(portp=%p): brdnr=%d panelnr=%d portnr=%d\n",
1564 (void *) portp, portp->brdnr, portp->panelnr, portp->portnr);
1568 stl_disableintrs(portp);
1569 stl_enablerxtx(portp, 0, 0);
1570 stl_flush(portp, (FWRITE | FREAD));
1571 if (tp->t_cflag & HUPCL) {
1572 stl_setsignals(portp, 0, 0);
1573 if (portp->dtrwait != 0) {
1574 portp->state |= ASY_DTRWAIT;
1575 timeout(stl_dtrwakeup, portp, portp->dtrwait);
1580 portp->state &= ~(ASY_ACTIVE | ASY_RTSFLOW);
1581 wakeup(&portp->callout);
1582 wakeup(TSA_CARR_ON(tp));
1586 /*****************************************************************************/
1589 * Clear the DTR waiting flag, and wake up any sleepers waiting for
1590 * DTR wait period to finish.
1593 static void stl_dtrwakeup(void *arg)
1597 portp = (stlport_t *) arg;
1598 portp->state &= ~ASY_DTRWAIT;
1599 wakeup(&portp->dtrwait);
1602 /*****************************************************************************/
1605 * Start (or continue) the transfer of TX data on this port. If the
1606 * port is not currently busy then load up the interrupt ring queue
1607 * buffer and kick of the transmitter. If the port is running low on
1608 * TX data then refill the ring queue. This routine is also used to
1609 * activate input flow control!
1612 static void stl_start(struct tty *tp)
1615 unsigned int len, stlen;
1619 portp = (stlport_t *) tp;
1622 printf("stl_start(tp=%x): brdnr=%d portnr=%d\n", (int) tp,
1623 portp->brdnr, portp->portnr);
1629 * Check if the ports input has been blocked, and take appropriate action.
1630 * Not very often do we really need to do anything, so make it quick.
1632 if (tp->t_state & TS_TBLOCK) {
1633 if ((portp->state & ASY_RTSFLOWMODE) &&
1634 ((portp->state & ASY_RTSFLOW) == 0))
1635 stl_flowcontrol(portp, 0, -1);
1637 if (portp->state & ASY_RTSFLOW)
1638 stl_flowcontrol(portp, 1, -1);
1643 * Check if the output cooked clist buffers are near empty, wake up
1644 * the line discipline to fill it up.
1646 if (tp->t_outq.c_cc <= tp->t_lowat) {
1647 if (tp->t_state & TS_ASLEEP) {
1648 tp->t_state &= ~TS_ASLEEP;
1649 wakeup(&tp->t_outq);
1651 selwakeup(&tp->t_wsel);
1655 if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
1661 * Copy data from the clists into the interrupt ring queue. This will
1662 * require at most 2 copys... What we do is calculate how many chars
1663 * can fit into the ring queue, and how many can fit in 1 copy. If after
1664 * the first copy there is still more room then do the second copy.
1665 * The beauty of this type of ring queue is that we do not need to
1666 * spl protect our-selves, since we only ever update the head pointer,
1667 * and the interrupt routine only ever updates the tail pointer.
1669 if (tp->t_outq.c_cc != 0) {
1670 head = portp->tx.head;
1671 tail = portp->tx.tail;
1673 len = STL_TXBUFSIZE - (head - tail) - 1;
1674 stlen = portp->tx.endbuf - head;
1676 len = tail - head - 1;
1681 stlen = MIN(len, stlen);
1682 count = q_to_b(&tp->t_outq, head, stlen);
1685 if (head >= portp->tx.endbuf) {
1686 head = portp->tx.buf;
1688 stlen = q_to_b(&tp->t_outq, head, len);
1693 portp->tx.head = head;
1695 stl_startrxtx(portp, -1, 1);
1699 * If we sent something, make sure we are called again.
1701 tp->t_state |= TS_BUSY;
1706 * Do any writer wakeups.
1714 /*****************************************************************************/
1716 static void stl_flush(stlport_t *portp, int flag)
1722 printf("stl_flush(portp=%x,flag=%x)\n", (int) portp, flag);
1725 if (portp == (stlport_t *) NULL)
1730 if (flag & FWRITE) {
1731 stl_uartflush(portp, FWRITE);
1732 portp->tx.tail = portp->tx.head;
1736 * The only thing to watch out for when flushing the read side is
1737 * the RX status buffer. The interrupt code relys on the status
1738 * bytes as being zeroed all the time (it does not bother setting
1739 * a good char status to 0, it expects that it already will be).
1740 * We also need to un-flow the RX channel if flow control was
1744 head = portp->rx.head;
1745 tail = portp->rx.tail;
1750 len = portp->rx.endbuf - tail;
1751 bzero(portp->rxstatus.buf,
1752 (head - portp->rx.buf));
1754 bzero((tail + STL_RXBUFSIZE), len);
1755 portp->rx.tail = head;
1758 if ((portp->state & ASY_RTSFLOW) &&
1759 ((portp->tty.t_state & TS_TBLOCK) == 0))
1760 stl_flowcontrol(portp, 1, -1);
1766 /*****************************************************************************/
1769 * Interrupt handler for host based boards. Interrupts for all boards
1770 * are vectored through here.
1773 void stlintr(int unit)
1779 printf("stlintr(unit=%d)\n", unit);
1782 for (i = 0; (i < stl_nrbrds); i++) {
1783 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
1785 if (brdp->state == 0)
1787 (* brdp->isr)(brdp);
1791 /*****************************************************************************/
1795 static void stlpciintr(void *arg)
1802 /*****************************************************************************/
1805 * Interrupt service routine for EasyIO boards.
1808 static void stl_eiointr(stlbrd_t *brdp)
1814 printf("stl_eiointr(brdp=%p)\n", brdp);
1817 panelp = (stlpanel_t *) brdp->panels[0];
1818 iobase = panelp->iobase;
1819 while (inb(brdp->iostatus) & EIO_INTRPEND)
1820 (* panelp->isr)(panelp, iobase);
1824 * Interrupt service routine for ECH-AT board types.
1827 static void stl_echatintr(stlbrd_t *brdp)
1830 unsigned int ioaddr;
1833 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDENABLE));
1835 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1836 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1837 ioaddr = brdp->bnkstataddr[bnknr];
1838 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1839 panelp = brdp->bnk2panel[bnknr];
1840 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1845 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDDISABLE));
1848 /*****************************************************************************/
1851 * Interrupt service routine for ECH-MCA board types.
1854 static void stl_echmcaintr(stlbrd_t *brdp)
1857 unsigned int ioaddr;
1860 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1861 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1862 ioaddr = brdp->bnkstataddr[bnknr];
1863 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1864 panelp = brdp->bnk2panel[bnknr];
1865 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1871 /*****************************************************************************/
1874 * Interrupt service routine for ECH-PCI board types.
1877 static void stl_echpciintr(stlbrd_t *brdp)
1880 unsigned int ioaddr;
1884 printf("stl_echpciintr(brdp=%x)\n", (int) brdp);
1889 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1890 outb(brdp->ioctrl, brdp->bnkpageaddr[bnknr]);
1891 ioaddr = brdp->bnkstataddr[bnknr];
1892 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1893 panelp = brdp->bnk2panel[bnknr];
1894 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1903 /*****************************************************************************/
1906 * Interrupt service routine for EC8/64-PCI board types.
1909 static void stl_echpci64intr(stlbrd_t *brdp)
1912 unsigned int ioaddr;
1916 printf("stl_echpci64intr(brdp=%p)\n", brdp);
1919 while (inb(brdp->ioctrl) & 0x1) {
1920 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1921 ioaddr = brdp->bnkstataddr[bnknr];
1923 printf(" --> ioaddr=%x status=%x(%x)\n", ioaddr, inb(ioaddr) & ECH_PNLINTRPEND, inb(ioaddr));
1925 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1926 panelp = brdp->bnk2panel[bnknr];
1927 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1933 /*****************************************************************************/
1936 * If we haven't scheduled a timeout then do it, some port needs high
1940 static void stl_dotimeout()
1943 printf("stl_dotimeout()\n");
1946 if (stl_doingtimeout == 0) {
1947 timeout(stl_poll, 0, 1);
1952 /*****************************************************************************/
1955 * Service "software" level processing. Too slow or painfull to be done
1956 * at real hardware interrupt time. This way we might also be able to
1957 * do some service on other waiting ports as well...
1960 static void stl_poll(void *arg)
1965 int brdnr, portnr, rearm, x;
1968 printf("stl_poll()\n");
1971 stl_doingtimeout = 0;
1975 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1976 if ((brdp = stl_brds[brdnr]) == (stlbrd_t *) NULL)
1978 for (portnr = 0; (portnr < brdp->nrports); portnr++) {
1979 if ((portp = brdp->ports[portnr]) == (stlport_t *) NULL)
1981 if ((portp->state & ASY_ACTIVE) == 0)
1985 if (portp->state & ASY_RXDATA)
1986 stl_rxprocess(portp);
1987 if (portp->state & ASY_DCDCHANGE) {
1988 portp->state &= ~ASY_DCDCHANGE;
1989 portp->sigs = stl_getsignals(portp);
1990 (*linesw[tp->t_line].l_modem)(tp,
1991 (portp->sigs & TIOCM_CD));
1993 if (portp->state & ASY_TXEMPTY) {
1994 if (stl_datastate(portp) == 0) {
1995 portp->state &= ~ASY_TXEMPTY;
1996 tp->t_state &= ~TS_BUSY;
1997 (*linesw[tp->t_line].l_start)(tp);
2000 if (portp->state & ASY_TXLOW) {
2001 portp->state &= ~ASY_TXLOW;
2002 (*linesw[tp->t_line].l_start)(tp);
2005 if (portp->state & ASY_ACTIVE)
2015 /*****************************************************************************/
2018 * Process the RX data that has been buffered up in the RX ring queue.
2021 static void stl_rxprocess(stlport_t *portp)
2024 unsigned int len, stlen, lostlen;
2030 printf("stl_rxprocess(portp=%x): brdnr=%d portnr=%d\n", (int) portp,
2031 portp->brdnr, portp->portnr);
2035 portp->state &= ~ASY_RXDATA;
2037 if ((tp->t_state & TS_ISOPEN) == 0) {
2038 stl_flush(portp, FREAD);
2043 * Calculate the amount of data in the RX ring queue. Also calculate
2044 * the largest single copy size...
2046 head = portp->rx.head;
2047 tail = portp->rx.tail;
2052 len = STL_RXBUFSIZE - (tail - head);
2053 stlen = portp->rx.endbuf - tail;
2056 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
2058 if (((tp->t_rawq.c_cc + len) >= TTYHOG) &&
2059 ((portp->state & ASY_RTSFLOWMODE) ||
2060 (tp->t_iflag & IXOFF)) &&
2061 ((tp->t_state & TS_TBLOCK) == 0)) {
2062 ch = TTYHOG - tp->t_rawq.c_cc - 1;
2063 len = (ch > 0) ? ch : 0;
2064 stlen = MIN(stlen, len);
2067 lostlen = b_to_q(tail, stlen, &tp->t_rawq);
2070 if (tail >= portp->rx.endbuf) {
2071 tail = portp->rx.buf;
2072 lostlen += b_to_q(tail, len, &tp->t_rawq);
2075 portp->stats.rxlost += lostlen;
2077 portp->rx.tail = tail;
2080 while (portp->rx.tail != head) {
2081 ch = (unsigned char) *(portp->rx.tail);
2082 status = *(portp->rx.tail + STL_RXBUFSIZE);
2084 *(portp->rx.tail + STL_RXBUFSIZE) = 0;
2085 if (status & ST_BREAK)
2087 if (status & ST_FRAMING)
2089 if (status & ST_PARITY)
2091 if (status & ST_OVERRUN)
2094 (*linesw[tp->t_line].l_rint)(ch, tp);
2095 if (portp->rx.tail == head)
2098 if (++(portp->rx.tail) >= portp->rx.endbuf)
2099 portp->rx.tail = portp->rx.buf;
2103 if (head != portp->rx.tail)
2104 portp->state |= ASY_RXDATA;
2107 * If we were flow controled then maybe the buffer is low enough that
2108 * we can re-activate it.
2110 if ((portp->state & ASY_RTSFLOW) && ((tp->t_state & TS_TBLOCK) == 0))
2111 stl_flowcontrol(portp, 1, -1);
2114 /*****************************************************************************/
2116 static int stl_param(struct tty *tp, struct termios *tiosp)
2120 portp = (stlport_t *) tp;
2121 if (portp == (stlport_t *) NULL)
2124 return(stl_setport(portp, tiosp));
2127 /*****************************************************************************/
2130 * Action the flow control as required. The hw and sw args inform the
2131 * routine what flow control methods it should try.
2134 static void stl_flowcontrol(stlport_t *portp, int hw, int sw)
2136 unsigned char *head, *tail;
2140 printf("stl_flowcontrol(portp=%x,hw=%d,sw=%d)\n", (int) portp, hw, sw);
2145 if (portp->state & ASY_RTSFLOWMODE) {
2147 if ((portp->state & ASY_RTSFLOW) == 0)
2149 } else if (hw > 0) {
2150 if (portp->state & ASY_RTSFLOW) {
2151 head = portp->rx.head;
2152 tail = portp->rx.tail;
2153 len = (head >= tail) ? (head - tail) :
2154 (STL_RXBUFSIZE - (tail - head));
2155 if (len < STL_RXBUFHIGH)
2162 * We have worked out what to do, if anything. So now apply it to the
2165 stl_sendflow(portp, hwflow, sw);
2168 /*****************************************************************************/
2171 * Enable l_rint processing bypass mode if tty modes allow it.
2174 static void stl_ttyoptim(stlport_t *portp, struct termios *tiosp)
2179 if (((tiosp->c_iflag &
2180 (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP)) == 0) &&
2181 (((tiosp->c_iflag & BRKINT) == 0) || (tiosp->c_iflag & IGNBRK)) &&
2182 (((tiosp->c_iflag & PARMRK) == 0) ||
2183 ((tiosp->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))) &&
2184 ((tiosp->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN)) ==0) &&
2185 (linesw[tp->t_line].l_rint == ttyinput))
2186 tp->t_state |= TS_CAN_BYPASS_L_RINT;
2188 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
2189 portp->hotchar = linesw[tp->t_line].l_hotchar;
2192 /*****************************************************************************/
2195 * Try and find and initialize all the ports on a panel. We don't care
2196 * what sort of board these ports are on - since the port io registers
2197 * are almost identical when dealing with ports.
2200 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2203 unsigned int chipmask;
2207 printf("stl_initports(panelp=%x)\n", (int) panelp);
2210 chipmask = stl_panelinit(brdp, panelp);
2213 * All UART's are initialized if found. Now go through and setup
2214 * each ports data structures. Also initialize each individual
2217 for (i = 0; (i < panelp->nrports); i++) {
2218 portp = (stlport_t *) malloc(sizeof(stlport_t), M_TTYS,
2220 if (portp == (stlport_t *) NULL) {
2221 printf("STALLION: failed to allocate port memory "
2222 "(size=%d)\n", sizeof(stlport_t));
2225 bzero(portp, sizeof(stlport_t));
2228 portp->brdnr = panelp->brdnr;
2229 portp->panelnr = panelp->panelnr;
2230 portp->uartp = panelp->uartp;
2231 portp->clk = brdp->clk;
2232 panelp->ports[i] = portp;
2234 j = STL_TXBUFSIZE + (2 * STL_RXBUFSIZE);
2235 portp->tx.buf = (char *) malloc(j, M_TTYS, M_NOWAIT);
2236 if (portp->tx.buf == (char *) NULL) {
2237 printf("STALLION: failed to allocate buffer memory "
2241 portp->tx.endbuf = portp->tx.buf + STL_TXBUFSIZE;
2242 portp->tx.head = portp->tx.buf;
2243 portp->tx.tail = portp->tx.buf;
2244 portp->rx.buf = portp->tx.buf + STL_TXBUFSIZE;
2245 portp->rx.endbuf = portp->rx.buf + STL_RXBUFSIZE;
2246 portp->rx.head = portp->rx.buf;
2247 portp->rx.tail = portp->rx.buf;
2248 portp->rxstatus.buf = portp->rx.buf + STL_RXBUFSIZE;
2249 portp->rxstatus.endbuf = portp->rxstatus.buf + STL_RXBUFSIZE;
2250 portp->rxstatus.head = portp->rxstatus.buf;
2251 portp->rxstatus.tail = portp->rxstatus.buf;
2252 bzero(portp->rxstatus.head, STL_RXBUFSIZE);
2254 portp->initintios.c_ispeed = STL_DEFSPEED;
2255 portp->initintios.c_ospeed = STL_DEFSPEED;
2256 portp->initintios.c_cflag = STL_DEFCFLAG;
2257 portp->initintios.c_iflag = 0;
2258 portp->initintios.c_oflag = 0;
2259 portp->initintios.c_lflag = 0;
2260 bcopy(&ttydefchars[0], &portp->initintios.c_cc[0],
2261 sizeof(portp->initintios.c_cc));
2262 portp->initouttios = portp->initintios;
2263 portp->dtrwait = 3 * hz;
2265 stl_portinit(brdp, panelp, portp);
2271 /*****************************************************************************/
2274 * Try to find and initialize an EasyIO board.
2277 static int stl_initeio(stlbrd_t *brdp)
2280 unsigned int status;
2283 printf("stl_initeio(brdp=%x)\n", (int) brdp);
2286 brdp->ioctrl = brdp->ioaddr1 + 1;
2287 brdp->iostatus = brdp->ioaddr1 + 2;
2288 brdp->clk = EIO_CLK;
2289 brdp->isr = stl_eiointr;
2291 status = inb(brdp->iostatus);
2292 switch (status & EIO_IDBITMASK) {
2294 brdp->clk = EIO_CLK8M;
2304 switch (status & EIO_BRDMASK) {
2323 if (brdp->brdtype == BRD_EASYIOPCI) {
2324 outb((brdp->ioaddr2 + 0x4c), 0x41);
2327 * Check that the supplied IRQ is good and then use it to setup the
2328 * programmable interrupt bits on EIO board. Also set the edge/level
2329 * triggered interrupt bit.
2331 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2332 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2333 printf("STALLION: invalid irq=%d for brd=%d\n",
2334 brdp->irq, brdp->brdnr);
2337 outb(brdp->ioctrl, (stl_vecmap[brdp->irq] |
2338 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)));
2341 panelp = (stlpanel_t *) malloc(sizeof(stlpanel_t), M_TTYS, M_NOWAIT);
2342 if (panelp == (stlpanel_t *) NULL) {
2343 printf("STALLION: failed to allocate memory (size=%d)\n",
2344 sizeof(stlpanel_t));
2347 bzero(panelp, sizeof(stlpanel_t));
2349 panelp->brdnr = brdp->brdnr;
2350 panelp->panelnr = 0;
2351 panelp->nrports = brdp->nrports;
2352 panelp->iobase = brdp->ioaddr1;
2353 panelp->hwid = status;
2354 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2355 panelp->uartp = (void *) &stl_sc26198uart;
2356 panelp->isr = stl_sc26198intr;
2358 panelp->uartp = (void *) &stl_cd1400uart;
2359 panelp->isr = stl_cd1400eiointr;
2361 brdp->panels[0] = panelp;
2363 brdp->hwid = status;
2364 brdp->state |= BRD_FOUND;
2368 /*****************************************************************************/
2371 * Try to find an ECH board and initialize it. This code is capable of
2372 * dealing with all types of ECH board.
2375 static int stl_initech(stlbrd_t *brdp)
2378 unsigned int status, nxtid;
2379 int panelnr, ioaddr, banknr, i;
2382 printf("stl_initech(brdp=%x)\n", (int) brdp);
2386 * Set up the initial board register contents for boards. This varys a
2387 * bit between the different board types. So we need to handle each
2388 * separately. Also do a check that the supplied IRQ is good.
2390 switch (brdp->brdtype) {
2393 brdp->isr = stl_echatintr;
2394 brdp->ioctrl = brdp->ioaddr1 + 1;
2395 brdp->iostatus = brdp->ioaddr1 + 1;
2396 status = inb(brdp->iostatus);
2397 if ((status & ECH_IDBITMASK) != ECH_ID)
2399 brdp->hwid = status;
2401 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2402 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2403 printf("STALLION: invalid irq=%d for brd=%d\n",
2404 brdp->irq, brdp->brdnr);
2407 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2408 status |= (stl_vecmap[brdp->irq] << 1);
2409 outb(brdp->ioaddr1, (status | ECH_BRDRESET));
2410 brdp->ioctrlval = ECH_INTENABLE |
2411 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2412 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDENABLE));
2413 outb(brdp->ioaddr1, status);
2417 brdp->isr = stl_echmcaintr;
2418 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2419 brdp->iostatus = brdp->ioctrl;
2420 status = inb(brdp->iostatus);
2421 if ((status & ECH_IDBITMASK) != ECH_ID)
2423 brdp->hwid = status;
2425 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2426 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2427 printf("STALLION: invalid irq=%d for brd=%d\n",
2428 brdp->irq, brdp->brdnr);
2431 outb(brdp->ioctrl, ECHMC_BRDRESET);
2432 outb(brdp->ioctrl, ECHMC_INTENABLE);
2436 brdp->isr = stl_echpciintr;
2437 brdp->ioctrl = brdp->ioaddr1 + 2;
2441 brdp->isr = stl_echpci64intr;
2442 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2443 outb((brdp->ioaddr1 + 0x4c), 0x43);
2447 printf("STALLION: unknown board type=%d\n", brdp->brdtype);
2451 brdp->clk = ECH_CLK;
2454 * Scan through the secondary io address space looking for panels.
2455 * As we find'em allocate and initialize panel structures for each.
2457 ioaddr = brdp->ioaddr2;
2462 for (i = 0; (i < STL_MAXPANELS); i++) {
2463 if (brdp->brdtype == BRD_ECHPCI) {
2464 outb(brdp->ioctrl, nxtid);
2465 ioaddr = brdp->ioaddr2;
2467 status = inb(ioaddr + ECH_PNLSTATUS);
2468 if ((status & ECH_PNLIDMASK) != nxtid)
2470 panelp = (stlpanel_t *) malloc(sizeof(stlpanel_t), M_TTYS,
2472 if (panelp == (stlpanel_t *) NULL) {
2473 printf("STALLION: failed to allocate memory"
2474 "(size=%d)\n", sizeof(stlpanel_t));
2477 bzero(panelp, sizeof(stlpanel_t));
2478 panelp->brdnr = brdp->brdnr;
2479 panelp->panelnr = panelnr;
2480 panelp->iobase = ioaddr;
2481 panelp->pagenr = nxtid;
2482 panelp->hwid = status;
2483 brdp->bnk2panel[banknr] = panelp;
2484 brdp->bnkpageaddr[banknr] = nxtid;
2485 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2487 if (status & ECH_PNLXPID) {
2488 panelp->uartp = (void *) &stl_sc26198uart;
2489 panelp->isr = stl_sc26198intr;
2490 if (status & ECH_PNL16PORT) {
2491 panelp->nrports = 16;
2492 brdp->bnk2panel[banknr] = panelp;
2493 brdp->bnkpageaddr[banknr] = nxtid;
2494 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2497 panelp->nrports = 8;
2500 panelp->uartp = (void *) &stl_cd1400uart;
2501 panelp->isr = stl_cd1400echintr;
2502 if (status & ECH_PNL16PORT) {
2503 panelp->nrports = 16;
2504 panelp->ackmask = 0x80;
2505 if (brdp->brdtype != BRD_ECHPCI)
2506 ioaddr += EREG_BANKSIZE;
2507 brdp->bnk2panel[banknr] = panelp;
2508 brdp->bnkpageaddr[banknr] = ++nxtid;
2509 brdp->bnkstataddr[banknr++] = ioaddr +
2512 panelp->nrports = 8;
2513 panelp->ackmask = 0xc0;
2518 ioaddr += EREG_BANKSIZE;
2519 brdp->nrports += panelp->nrports;
2520 brdp->panels[panelnr++] = panelp;
2521 if ((brdp->brdtype == BRD_ECH) || (brdp->brdtype == BRD_ECHMC)){
2522 if (ioaddr >= (brdp->ioaddr2 + 0x20)) {
2523 printf("STALLION: too many ports attached "
2524 "to board %d, remove last module\n",
2531 brdp->nrpanels = panelnr;
2532 brdp->nrbnks = banknr;
2533 if (brdp->brdtype == BRD_ECH)
2534 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDDISABLE));
2536 brdp->state |= BRD_FOUND;
2540 /*****************************************************************************/
2543 * Initialize and configure the specified board. This firstly probes
2544 * for the board, if it is found then the board is initialized and
2545 * then all its ports are initialized as well.
2548 static int stl_brdinit(stlbrd_t *brdp)
2554 printf("stl_brdinit(brdp=%x): unit=%d type=%d io1=%x io2=%x irq=%d\n",
2555 (int) brdp, brdp->brdnr, brdp->brdtype, brdp->ioaddr1,
2556 brdp->ioaddr2, brdp->irq);
2559 switch (brdp->brdtype) {
2571 printf("STALLION: unit=%d is unknown board type=%d\n",
2572 brdp->brdnr, brdp->brdtype);
2576 stl_brds[brdp->brdnr] = brdp;
2577 if ((brdp->state & BRD_FOUND) == 0) {
2579 printf("STALLION: %s board not found, unit=%d io=%x irq=%d\n",
2580 stl_brdnames[brdp->brdtype], brdp->brdnr,
2581 brdp->ioaddr1, brdp->irq);
2586 for (i = 0, k = 0; (i < STL_MAXPANELS); i++) {
2587 panelp = brdp->panels[i];
2588 if (panelp != (stlpanel_t *) NULL) {
2589 stl_initports(brdp, panelp);
2590 for (j = 0; (j < panelp->nrports); j++)
2591 brdp->ports[k++] = panelp->ports[j];
2595 printf("stl%d: %s (driver version %s) unit=%d nrpanels=%d nrports=%d\n",
2596 brdp->unitid, stl_brdnames[brdp->brdtype], stl_drvversion,
2597 brdp->brdnr, brdp->nrpanels, brdp->nrports);
2601 /*****************************************************************************/
2604 * Return the board stats structure to user app.
2607 static int stl_getbrdstats(caddr_t data)
2613 stl_brdstats = *((combrd_t *) data);
2614 if (stl_brdstats.brd >= STL_MAXBRDS)
2616 brdp = stl_brds[stl_brdstats.brd];
2617 if (brdp == (stlbrd_t *) NULL)
2620 bzero(&stl_brdstats, sizeof(combrd_t));
2621 stl_brdstats.brd = brdp->brdnr;
2622 stl_brdstats.type = brdp->brdtype;
2623 stl_brdstats.hwid = brdp->hwid;
2624 stl_brdstats.state = brdp->state;
2625 stl_brdstats.ioaddr = brdp->ioaddr1;
2626 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2627 stl_brdstats.irq = brdp->irq;
2628 stl_brdstats.nrpanels = brdp->nrpanels;
2629 stl_brdstats.nrports = brdp->nrports;
2630 for (i = 0; (i < brdp->nrpanels); i++) {
2631 panelp = brdp->panels[i];
2632 stl_brdstats.panels[i].panel = i;
2633 stl_brdstats.panels[i].hwid = panelp->hwid;
2634 stl_brdstats.panels[i].nrports = panelp->nrports;
2637 *((combrd_t *) data) = stl_brdstats;;
2641 /*****************************************************************************/
2644 * Resolve the referenced port number into a port struct pointer.
2647 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2652 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2653 return((stlport_t *) NULL);
2654 brdp = stl_brds[brdnr];
2655 if (brdp == (stlbrd_t *) NULL)
2656 return((stlport_t *) NULL);
2657 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2658 return((stlport_t *) NULL);
2659 panelp = brdp->panels[panelnr];
2660 if (panelp == (stlpanel_t *) NULL)
2661 return((stlport_t *) NULL);
2662 if ((portnr < 0) || (portnr >= panelp->nrports))
2663 return((stlport_t *) NULL);
2664 return(panelp->ports[portnr]);
2667 /*****************************************************************************/
2670 * Return the port stats structure to user app. A NULL port struct
2671 * pointer passed in means that we need to find out from the app
2672 * what port to get stats for (used through board control device).
2675 static int stl_getportstats(stlport_t *portp, caddr_t data)
2677 unsigned char *head, *tail;
2679 if (portp == (stlport_t *) NULL) {
2680 stl_comstats = *((comstats_t *) data);
2681 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2683 if (portp == (stlport_t *) NULL)
2687 portp->stats.state = portp->state;
2688 /*portp->stats.flags = portp->flags;*/
2689 portp->stats.hwid = portp->hwid;
2690 portp->stats.ttystate = portp->tty.t_state;
2691 portp->stats.cflags = portp->tty.t_cflag;
2692 portp->stats.iflags = portp->tty.t_iflag;
2693 portp->stats.oflags = portp->tty.t_oflag;
2694 portp->stats.lflags = portp->tty.t_lflag;
2696 head = portp->tx.head;
2697 tail = portp->tx.tail;
2698 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2699 (STL_TXBUFSIZE - (tail - head)));
2701 head = portp->rx.head;
2702 tail = portp->rx.tail;
2703 portp->stats.rxbuffered = (head >= tail) ? (head - tail) :
2704 (STL_RXBUFSIZE - (tail - head));
2706 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2708 *((comstats_t *) data) = portp->stats;
2712 /*****************************************************************************/
2715 * Clear the port stats structure. We also return it zeroed out...
2718 static int stl_clrportstats(stlport_t *portp, caddr_t data)
2720 if (portp == (stlport_t *) NULL) {
2721 stl_comstats = *((comstats_t *) data);
2722 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2724 if (portp == (stlport_t *) NULL)
2728 bzero(&portp->stats, sizeof(comstats_t));
2729 portp->stats.brd = portp->brdnr;
2730 portp->stats.panel = portp->panelnr;
2731 portp->stats.port = portp->portnr;
2732 *((comstats_t *) data) = stl_comstats;
2736 /*****************************************************************************/
2739 * The "staliomem" device is used for stats collection in this driver.
2742 static int stl_memioctl(dev_t dev, unsigned long cmd, caddr_t data, int flag,
2748 printf("stl_memioctl(dev=%s,cmd=%lx,data=%p,flag=%x)\n",
2749 devtoname(dev), cmd, (void *) data, flag);
2755 case COM_GETPORTSTATS:
2756 rc = stl_getportstats((stlport_t *) NULL, data);
2758 case COM_CLRPORTSTATS:
2759 rc = stl_clrportstats((stlport_t *) NULL, data);
2761 case COM_GETBRDSTATS:
2762 rc = stl_getbrdstats(data);
2772 /*****************************************************************************/
2774 /*****************************************************************************/
2775 /* CD1400 UART CODE */
2776 /*****************************************************************************/
2779 * These functions get/set/update the registers of the cd1400 UARTs.
2780 * Access to the cd1400 registers is via an address/data io port pair.
2783 static int stl_cd1400getreg(stlport_t *portp, int regnr)
2785 outb(portp->ioaddr, (regnr + portp->uartaddr));
2786 return(inb(portp->ioaddr + EREG_DATA));
2789 /*****************************************************************************/
2791 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
2793 outb(portp->ioaddr, (regnr + portp->uartaddr));
2794 outb((portp->ioaddr + EREG_DATA), value);
2797 /*****************************************************************************/
2799 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
2801 outb(portp->ioaddr, (regnr + portp->uartaddr));
2802 if (inb(portp->ioaddr + EREG_DATA) != value) {
2803 outb((portp->ioaddr + EREG_DATA), value);
2809 /*****************************************************************************/
2811 static void stl_cd1400flush(stlport_t *portp, int flag)
2816 printf("stl_cd1400flush(portp=%x,flag=%x)\n", (int) portp, flag);
2819 if (portp == (stlport_t *) NULL)
2824 if (flag & FWRITE) {
2825 BRDENABLE(portp->brdnr, portp->pagenr);
2826 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2827 stl_cd1400ccrwait(portp);
2828 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
2829 stl_cd1400ccrwait(portp);
2830 BRDDISABLE(portp->brdnr);
2840 /*****************************************************************************/
2842 static void stl_cd1400ccrwait(stlport_t *portp)
2846 for (i = 0; (i < CCR_MAXWAIT); i++) {
2847 if (stl_cd1400getreg(portp, CCR) == 0)
2851 printf("stl%d: cd1400 device not responding, panel=%d port=%d\n",
2852 portp->brdnr, portp->panelnr, portp->portnr);
2855 /*****************************************************************************/
2858 * Transmit interrupt handler. This has gotta be fast! Handling TX
2859 * chars is pretty simple, stuff as many as possible from the TX buffer
2860 * into the cd1400 FIFO. Must also handle TX breaks here, since they
2861 * are embedded as commands in the data stream. Oh no, had to use a goto!
2864 static __inline void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
2868 unsigned char ioack, srer;
2873 printf("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
2876 ioack = inb(ioaddr + EREG_TXACK);
2877 if (((ioack & panelp->ackmask) != 0) ||
2878 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
2879 printf("STALLION: bad TX interrupt ack value=%x\n",
2883 portp = panelp->ports[(ioack >> 3)];
2887 * Unfortunately we need to handle breaks in the data stream, since
2888 * this is the only way to generate them on the cd1400. Do it now if
2889 * a break is to be sent. Some special cases here: brklen is -1 then
2890 * start sending an un-timed break, if brklen is -2 then stop sending
2891 * an un-timed break, if brklen is -3 then we have just sent an
2892 * un-timed break and do not want any data to go out, if brklen is -4
2893 * then a break has just completed so clean up the port settings.
2895 if (portp->brklen != 0) {
2896 if (portp->brklen >= -1) {
2897 outb(ioaddr, (TDR + portp->uartaddr));
2898 outb((ioaddr + EREG_DATA), ETC_CMD);
2899 outb((ioaddr + EREG_DATA), ETC_STARTBREAK);
2900 if (portp->brklen > 0) {
2901 outb((ioaddr + EREG_DATA), ETC_CMD);
2902 outb((ioaddr + EREG_DATA), ETC_DELAY);
2903 outb((ioaddr + EREG_DATA), portp->brklen);
2904 outb((ioaddr + EREG_DATA), ETC_CMD);
2905 outb((ioaddr + EREG_DATA), ETC_STOPBREAK);
2910 } else if (portp->brklen == -2) {
2911 outb(ioaddr, (TDR + portp->uartaddr));
2912 outb((ioaddr + EREG_DATA), ETC_CMD);
2913 outb((ioaddr + EREG_DATA), ETC_STOPBREAK);
2915 } else if (portp->brklen == -3) {
2916 outb(ioaddr, (SRER + portp->uartaddr));
2917 srer = inb(ioaddr + EREG_DATA);
2918 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
2919 outb((ioaddr + EREG_DATA), srer);
2921 outb(ioaddr, (COR2 + portp->uartaddr));
2922 outb((ioaddr + EREG_DATA),
2923 (inb(ioaddr + EREG_DATA) & ~COR2_ETC));
2929 head = portp->tx.head;
2930 tail = portp->tx.tail;
2931 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
2932 if ((len == 0) || ((len < STL_TXBUFLOW) &&
2933 ((portp->state & ASY_TXLOW) == 0))) {
2934 portp->state |= ASY_TXLOW;
2939 outb(ioaddr, (SRER + portp->uartaddr));
2940 srer = inb(ioaddr + EREG_DATA);
2941 if (srer & SRER_TXDATA) {
2942 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
2944 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
2945 portp->state |= ASY_TXEMPTY;
2946 portp->state &= ~ASY_TXBUSY;
2948 outb((ioaddr + EREG_DATA), srer);
2950 len = MIN(len, CD1400_TXFIFOSIZE);
2951 portp->stats.txtotal += len;
2952 stlen = MIN(len, (portp->tx.endbuf - tail));
2953 outb(ioaddr, (TDR + portp->uartaddr));
2954 outsb((ioaddr + EREG_DATA), tail, stlen);
2957 if (tail >= portp->tx.endbuf)
2958 tail = portp->tx.buf;
2960 outsb((ioaddr + EREG_DATA), tail, len);
2963 portp->tx.tail = tail;
2967 outb(ioaddr, (EOSRR + portp->uartaddr));
2968 outb((ioaddr + EREG_DATA), 0);
2971 /*****************************************************************************/
2974 * Receive character interrupt handler. Determine if we have good chars
2975 * or bad chars and then process appropriately.
2978 static __inline void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
2982 unsigned int ioack, len, buflen, stlen;
2983 unsigned char status;
2988 printf("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
2991 ioack = inb(ioaddr + EREG_RXACK);
2992 if ((ioack & panelp->ackmask) != 0) {
2993 printf("STALLION: bad RX interrupt ack value=%x\n", ioack);
2996 portp = panelp->ports[(ioack >> 3)];
3000 * First up, calculate how much room there is in the RX ring queue.
3001 * We also want to keep track of the longest possible copy length,
3002 * this has to allow for the wrapping of the ring queue.
3004 head = portp->rx.head;
3005 tail = portp->rx.tail;
3007 buflen = STL_RXBUFSIZE - (head - tail) - 1;
3008 stlen = portp->rx.endbuf - head;
3010 buflen = tail - head - 1;
3015 * Check if the input buffer is near full. If so then we should take
3016 * some flow control action... It is very easy to do hardware and
3017 * software flow control from here since we have the port selected on
3020 if (buflen <= (STL_RXBUFSIZE - STL_RXBUFHIGH)) {
3021 if (((portp->state & ASY_RTSFLOW) == 0) &&
3022 (portp->state & ASY_RTSFLOWMODE)) {
3023 portp->state |= ASY_RTSFLOW;
3024 stl_cd1400setreg(portp, MCOR1,
3025 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3026 stl_cd1400setreg(portp, MSVR2, 0);
3027 portp->stats.rxrtsoff++;
3032 * OK we are set, process good data... If the RX ring queue is full
3033 * just chuck the chars - don't leave them in the UART.
3035 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
3036 outb(ioaddr, (RDCR + portp->uartaddr));
3037 len = inb(ioaddr + EREG_DATA);
3039 outb(ioaddr, (RDSR + portp->uartaddr));
3040 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
3041 portp->stats.rxlost += len;
3042 portp->stats.rxtotal += len;
3044 len = MIN(len, buflen);
3045 portp->stats.rxtotal += len;
3046 stlen = MIN(len, stlen);
3048 outb(ioaddr, (RDSR + portp->uartaddr));
3049 insb((ioaddr + EREG_DATA), head, stlen);
3051 if (head >= portp->rx.endbuf) {
3052 head = portp->rx.buf;
3054 insb((ioaddr + EREG_DATA), head, len);
3059 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
3060 outb(ioaddr, (RDSR + portp->uartaddr));
3061 status = inb(ioaddr + EREG_DATA);
3062 ch = inb(ioaddr + EREG_DATA);
3063 if (status & ST_BREAK)
3064 portp->stats.rxbreaks++;
3065 if (status & ST_FRAMING)
3066 portp->stats.rxframing++;
3067 if (status & ST_PARITY)
3068 portp->stats.rxparity++;
3069 if (status & ST_OVERRUN)
3070 portp->stats.rxoverrun++;
3071 if (status & ST_SCHARMASK) {
3072 if ((status & ST_SCHARMASK) == ST_SCHAR1)
3073 portp->stats.txxon++;
3074 if ((status & ST_SCHARMASK) == ST_SCHAR2)
3075 portp->stats.txxoff++;
3078 if ((portp->rxignoremsk & status) == 0) {
3079 if ((tp->t_state & TS_CAN_BYPASS_L_RINT) &&
3080 ((status & ST_FRAMING) ||
3081 ((status & ST_PARITY) && (tp->t_iflag & INPCK))))
3083 if ((portp->rxmarkmsk & status) == 0)
3085 *(head + STL_RXBUFSIZE) = status;
3087 if (head >= portp->rx.endbuf)
3088 head = portp->rx.buf;
3091 printf("STALLION: bad RX interrupt ack value=%x\n", ioack);
3095 portp->rx.head = head;
3096 portp->state |= ASY_RXDATA;
3100 outb(ioaddr, (EOSRR + portp->uartaddr));
3101 outb((ioaddr + EREG_DATA), 0);
3104 /*****************************************************************************/
3107 * Modem interrupt handler. The is called when the modem signal line
3108 * (DCD) has changed state.
3111 static __inline void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
3118 printf("stl_cd1400mdmisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
3121 ioack = inb(ioaddr + EREG_MDACK);
3122 if (((ioack & panelp->ackmask) != 0) ||
3123 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
3124 printf("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
3127 portp = panelp->ports[(ioack >> 3)];
3129 outb(ioaddr, (MISR + portp->uartaddr));
3130 misr = inb(ioaddr + EREG_DATA);
3131 if (misr & MISR_DCD) {
3132 portp->state |= ASY_DCDCHANGE;
3133 portp->stats.modem++;
3137 outb(ioaddr, (EOSRR + portp->uartaddr));
3138 outb((ioaddr + EREG_DATA), 0);
3141 /*****************************************************************************/
3144 * Interrupt service routine for cd1400 EasyIO boards.
3147 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3149 unsigned char svrtype;
3152 printf("stl_cd1400eiointr(panelp=%x,iobase=%x)\n", (int) panelp,
3157 svrtype = inb(iobase + EREG_DATA);
3158 if (panelp->nrports > 4) {
3159 outb(iobase, (SVRR + 0x80));
3160 svrtype |= inb(iobase + EREG_DATA);
3163 printf("stl_cd1400eiointr(panelp=%x,iobase=%x): svrr=%x\n", (int) panelp, iobase, svrtype);
3166 if (svrtype & SVRR_RX)
3167 stl_cd1400rxisr(panelp, iobase);
3168 else if (svrtype & SVRR_TX)
3169 stl_cd1400txisr(panelp, iobase);
3170 else if (svrtype & SVRR_MDM)
3171 stl_cd1400mdmisr(panelp, iobase);
3174 /*****************************************************************************/
3177 * Interrupt service routine for cd1400 panels.
3180 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
3182 unsigned char svrtype;
3185 printf("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
3190 svrtype = inb(iobase + EREG_DATA);
3191 outb(iobase, (SVRR + 0x80));
3192 svrtype |= inb(iobase + EREG_DATA);
3193 if (svrtype & SVRR_RX)
3194 stl_cd1400rxisr(panelp, iobase);
3195 else if (svrtype & SVRR_TX)
3196 stl_cd1400txisr(panelp, iobase);
3197 else if (svrtype & SVRR_MDM)
3198 stl_cd1400mdmisr(panelp, iobase);
3201 /*****************************************************************************/
3204 * Set up the cd1400 registers for a port based on the termios port
3208 static int stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3210 unsigned int clkdiv;
3211 unsigned char cor1, cor2, cor3;
3212 unsigned char cor4, cor5, ccr;
3213 unsigned char srer, sreron, sreroff;
3214 unsigned char mcor1, mcor2, rtpr;
3215 unsigned char clk, div;
3219 printf("stl_cd1400setport(portp=%x,tiosp=%x): brdnr=%d portnr=%d\n",
3220 (int) portp, (int) tiosp, portp->brdnr, portp->portnr);
3238 * Set up the RX char ignore mask with those RX error types we
3239 * can ignore. We could have used some special modes of the cd1400
3240 * UART to help, but it is better this way because we can keep stats
3241 * on the number of each type of RX exception event.
3243 portp->rxignoremsk = 0;
3244 if (tiosp->c_iflag & IGNPAR)
3245 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
3246 if (tiosp->c_iflag & IGNBRK)
3247 portp->rxignoremsk |= ST_BREAK;
3249 portp->rxmarkmsk = ST_OVERRUN;
3250 if (tiosp->c_iflag & (INPCK | PARMRK))
3251 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3252 if (tiosp->c_iflag & BRKINT)
3253 portp->rxmarkmsk |= ST_BREAK;
3256 * Go through the char size, parity and stop bits and set all the
3257 * option registers appropriately.
3259 switch (tiosp->c_cflag & CSIZE) {
3274 if (tiosp->c_cflag & CSTOPB)
3279 if (tiosp->c_cflag & PARENB) {
3280 if (tiosp->c_cflag & PARODD)
3281 cor1 |= (COR1_PARENB | COR1_PARODD);
3283 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3285 cor1 |= COR1_PARNONE;
3289 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3290 * space for hardware flow control and the like. This should be set to
3291 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3292 * really be based on VTIME...
3294 cor3 |= FIFO_RXTHRESHOLD;
3298 * Calculate the baud rate timers. For now we will just assume that
3299 * the input and output baud are the same. Could have used a baud
3300 * table here, but this way we can generate virtually any baud rate
3303 if (tiosp->c_ispeed == 0)
3304 tiosp->c_ispeed = tiosp->c_ospeed;
3305 if ((tiosp->c_ospeed < 0) || (tiosp->c_ospeed > CD1400_MAXBAUD))
3308 if (tiosp->c_ospeed > 0) {
3309 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3310 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) /
3315 div = (unsigned char) clkdiv;
3319 * Check what form of modem signaling is required and set it up.
3321 if ((tiosp->c_cflag & CLOCAL) == 0) {
3324 sreron |= SRER_MODEM;
3328 * Setup cd1400 enhanced modes if we can. In particular we want to
3329 * handle as much of the flow control as possbile automatically. As
3330 * well as saving a few CPU cycles it will also greatly improve flow
3331 * control reliablilty.
3333 if (tiosp->c_iflag & IXON) {
3336 if (tiosp->c_iflag & IXANY)
3340 if (tiosp->c_cflag & CCTS_OFLOW)
3342 if (tiosp->c_cflag & CRTS_IFLOW)
3343 mcor1 |= FIFO_RTSTHRESHOLD;
3346 * All cd1400 register values calculated so go through and set them
3350 printf("SETPORT: portnr=%d panelnr=%d brdnr=%d\n", portp->portnr,
3351 portp->panelnr, portp->brdnr);
3352 printf(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n", cor1, cor2,
3354 printf(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3355 mcor1, mcor2, rtpr, sreron, sreroff);
3356 printf(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3357 printf(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3358 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP], tiosp->c_cc[VSTART],
3359 tiosp->c_cc[VSTOP]);
3363 BRDENABLE(portp->brdnr, portp->pagenr);
3364 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3365 srer = stl_cd1400getreg(portp, SRER);
3366 stl_cd1400setreg(portp, SRER, 0);
3367 ccr += stl_cd1400updatereg(portp, COR1, cor1);
3368 ccr += stl_cd1400updatereg(portp, COR2, cor2);
3369 ccr += stl_cd1400updatereg(portp, COR3, cor3);
3371 stl_cd1400ccrwait(portp);
3372 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3374 stl_cd1400setreg(portp, COR4, cor4);
3375 stl_cd1400setreg(portp, COR5, cor5);
3376 stl_cd1400setreg(portp, MCOR1, mcor1);
3377 stl_cd1400setreg(portp, MCOR2, mcor2);
3378 if (tiosp->c_ospeed == 0) {
3379 stl_cd1400setreg(portp, MSVR1, 0);
3381 stl_cd1400setreg(portp, MSVR1, MSVR1_DTR);
3382 stl_cd1400setreg(portp, TCOR, clk);
3383 stl_cd1400setreg(portp, TBPR, div);
3384 stl_cd1400setreg(portp, RCOR, clk);
3385 stl_cd1400setreg(portp, RBPR, div);
3387 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3388 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3389 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3390 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3391 stl_cd1400setreg(portp, RTPR, rtpr);
3392 mcor1 = stl_cd1400getreg(portp, MSVR1);
3393 if (mcor1 & MSVR1_DCD)
3394 portp->sigs |= TIOCM_CD;
3396 portp->sigs &= ~TIOCM_CD;
3397 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3398 BRDDISABLE(portp->brdnr);
3399 portp->state &= ~(ASY_RTSFLOWMODE | ASY_CTSFLOWMODE);
3400 portp->state |= ((tiosp->c_cflag & CRTS_IFLOW) ? ASY_RTSFLOWMODE : 0);
3401 portp->state |= ((tiosp->c_cflag & CCTS_OFLOW) ? ASY_CTSFLOWMODE : 0);
3402 stl_ttyoptim(portp, tiosp);
3408 /*****************************************************************************/
3411 * Action the flow control as required. The hw and sw args inform the
3412 * routine what flow control methods it should try.
3415 static void stl_cd1400sendflow(stlport_t *portp, int hw, int sw)
3420 printf("stl_cd1400sendflow(portp=%x,hw=%d,sw=%d)\n",
3421 (int) portp, hw, sw);
3425 BRDENABLE(portp->brdnr, portp->pagenr);
3426 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3429 stl_cd1400ccrwait(portp);
3431 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3432 portp->stats.rxxoff++;
3434 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3435 portp->stats.rxxon++;
3437 stl_cd1400ccrwait(portp);
3441 portp->state |= ASY_RTSFLOW;
3442 stl_cd1400setreg(portp, MCOR1,
3443 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3444 stl_cd1400setreg(portp, MSVR2, 0);
3445 portp->stats.rxrtsoff++;
3446 } else if (hw > 0) {
3447 portp->state &= ~ASY_RTSFLOW;
3448 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3449 stl_cd1400setreg(portp, MCOR1,
3450 (stl_cd1400getreg(portp, MCOR1) | FIFO_RTSTHRESHOLD));
3451 portp->stats.rxrtson++;
3454 BRDDISABLE(portp->brdnr);
3458 /*****************************************************************************/
3461 * Return the current state of data flow on this port. This is only
3462 * really interresting when determining if data has fully completed
3463 * transmission or not... This is easy for the cd1400, it accurately
3464 * maintains the busy port flag.
3467 static int stl_cd1400datastate(stlport_t *portp)
3470 printf("stl_cd1400datastate(portp=%x)\n", (int) portp);
3473 if (portp == (stlport_t *) NULL)
3476 return((portp->state & ASY_TXBUSY) ? 1 : 0);
3479 /*****************************************************************************/
3482 * Set the state of the DTR and RTS signals. Got to do some extra
3483 * work here to deal hardware flow control.
3486 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3488 unsigned char msvr1, msvr2;
3492 printf("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n", (int) portp,
3504 BRDENABLE(portp->brdnr, portp->pagenr);
3505 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3507 if (portp->tty.t_cflag & CRTS_IFLOW) {
3509 stl_cd1400setreg(portp, MCOR1,
3510 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3511 portp->stats.rxrtsoff++;
3513 stl_cd1400setreg(portp, MCOR1,
3514 (stl_cd1400getreg(portp, MCOR1) |
3515 FIFO_RTSTHRESHOLD));
3516 portp->stats.rxrtson++;
3519 stl_cd1400setreg(portp, MSVR2, msvr2);
3522 stl_cd1400setreg(portp, MSVR1, msvr1);
3523 BRDDISABLE(portp->brdnr);
3527 /*****************************************************************************/
3530 * Get the state of the signals.
3533 static int stl_cd1400getsignals(stlport_t *portp)
3535 unsigned char msvr1, msvr2;
3539 printf("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3543 BRDENABLE(portp->brdnr, portp->pagenr);
3544 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3545 msvr1 = stl_cd1400getreg(portp, MSVR1);
3546 msvr2 = stl_cd1400getreg(portp, MSVR2);
3547 BRDDISABLE(portp->brdnr);
3551 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3552 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3553 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3554 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3556 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3557 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3564 /*****************************************************************************/
3567 * Enable or disable the Transmitter and/or Receiver.
3570 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3576 printf("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3577 (int) portp, rx, tx);
3582 ccr |= CCR_TXDISABLE;
3584 ccr |= CCR_TXENABLE;
3586 ccr |= CCR_RXDISABLE;
3588 ccr |= CCR_RXENABLE;
3591 BRDENABLE(portp->brdnr, portp->pagenr);
3592 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3593 stl_cd1400ccrwait(portp);
3594 stl_cd1400setreg(portp, CCR, ccr);
3595 stl_cd1400ccrwait(portp);
3596 BRDDISABLE(portp->brdnr);
3600 /*****************************************************************************/
3603 * Start or stop the Transmitter and/or Receiver.
3606 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3608 unsigned char sreron, sreroff;
3612 printf("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3613 (int) portp, rx, tx);
3619 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3621 sreron |= SRER_TXDATA;
3623 sreron |= SRER_TXEMPTY;
3625 sreroff |= SRER_RXDATA;
3627 sreron |= SRER_RXDATA;
3630 BRDENABLE(portp->brdnr, portp->pagenr);
3631 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3632 stl_cd1400setreg(portp, SRER,
3633 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3634 BRDDISABLE(portp->brdnr);
3636 portp->state |= ASY_TXBUSY;
3637 portp->tty.t_state |= TS_BUSY;
3642 /*****************************************************************************/
3645 * Disable all interrupts from this port.
3648 static void stl_cd1400disableintrs(stlport_t *portp)
3653 printf("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3657 BRDENABLE(portp->brdnr, portp->pagenr);
3658 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3659 stl_cd1400setreg(portp, SRER, 0);
3660 BRDDISABLE(portp->brdnr);
3664 /*****************************************************************************/
3666 static void stl_cd1400sendbreak(stlport_t *portp, long len)
3671 printf("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp,
3676 BRDENABLE(portp->brdnr, portp->pagenr);
3677 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3678 stl_cd1400setreg(portp, COR2,
3679 (stl_cd1400getreg(portp, COR2) | COR2_ETC));
3680 stl_cd1400setreg(portp, SRER,
3681 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3683 BRDDISABLE(portp->brdnr);
3686 portp->brklen = (len > 255) ? 255 : len;
3688 portp->brklen = len;
3691 portp->stats.txbreaks++;
3694 /*****************************************************************************/
3697 * Try and find and initialize all the ports on a panel. We don't care
3698 * what sort of board these ports are on - since the port io registers
3699 * are almost identical when dealing with ports.
3702 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3705 printf("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3706 (int) brdp, (int) panelp, (int) portp);
3709 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
3710 (portp == (stlport_t *) NULL))
3713 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3714 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3715 portp->uartaddr = (portp->portnr & 0x04) << 5;
3716 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3718 BRDENABLE(portp->brdnr, portp->pagenr);
3719 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3720 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3721 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3722 BRDDISABLE(portp->brdnr);
3725 /*****************************************************************************/
3728 * Inbitialize the UARTs in a panel. We don't care what sort of board
3729 * these ports are on - since the port io registers are almost
3730 * identical when dealing with ports.
3733 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3737 int nrchips, uartaddr, ioaddr;
3740 printf("stl_cd1400panelinit(brdp=%x,panelp=%x)\n", (int) brdp,
3744 BRDENABLE(panelp->brdnr, panelp->pagenr);
3747 * Check that each chip is present and started up OK.
3750 nrchips = panelp->nrports / CD1400_PORTS;
3751 for (i = 0; (i < nrchips); i++) {
3752 if (brdp->brdtype == BRD_ECHPCI) {
3753 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3754 ioaddr = panelp->iobase;
3756 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3758 uartaddr = (i & 0x01) ? 0x080 : 0;
3759 outb(ioaddr, (GFRCR + uartaddr));
3760 outb((ioaddr + EREG_DATA), 0);
3761 outb(ioaddr, (CCR + uartaddr));
3762 outb((ioaddr + EREG_DATA), CCR_RESETFULL);
3763 outb((ioaddr + EREG_DATA), CCR_RESETFULL);
3764 outb(ioaddr, (GFRCR + uartaddr));
3765 for (j = 0; (j < CCR_MAXWAIT); j++) {
3766 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3769 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3770 printf("STALLION: cd1400 not responding, "
3771 "board=%d panel=%d chip=%d\n", panelp->brdnr,
3772 panelp->panelnr, i);
3775 chipmask |= (0x1 << i);
3776 outb(ioaddr, (PPR + uartaddr));
3777 outb((ioaddr + EREG_DATA), PPR_SCALAR);
3781 BRDDISABLE(panelp->brdnr);
3785 /*****************************************************************************/
3786 /* SC26198 HARDWARE FUNCTIONS */
3787 /*****************************************************************************/
3790 * These functions get/set/update the registers of the sc26198 UARTs.
3791 * Access to the sc26198 registers is via an address/data io port pair.
3792 * (Maybe should make this inline...)
3795 static int stl_sc26198getreg(stlport_t *portp, int regnr)
3797 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3798 return(inb(portp->ioaddr + XP_DATA));
3801 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
3803 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3804 outb((portp->ioaddr + XP_DATA), value);
3807 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
3809 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3810 if (inb(portp->ioaddr + XP_DATA) != value) {
3811 outb((portp->ioaddr + XP_DATA), value);
3817 /*****************************************************************************/
3820 * Functions to get and set the sc26198 global registers.
3823 static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
3825 outb((portp->ioaddr + XP_ADDR), regnr);
3826 return(inb(portp->ioaddr + XP_DATA));
3830 static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
3832 outb((portp->ioaddr + XP_ADDR), regnr);
3833 outb((portp->ioaddr + XP_DATA), value);
3837 /*****************************************************************************/
3840 * Inbitialize the UARTs in a panel. We don't care what sort of board
3841 * these ports are on - since the port io registers are almost
3842 * identical when dealing with ports.
3845 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3848 int nrchips, ioaddr;
3851 printf("stl_sc26198panelinit(brdp=%x,panelp=%x)\n", (int) brdp,
3855 BRDENABLE(panelp->brdnr, panelp->pagenr);
3858 * Check that each chip is present and started up OK.
3861 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
3862 if (brdp->brdtype == BRD_ECHPCI)
3863 outb(brdp->ioctrl, panelp->pagenr);
3865 for (i = 0; (i < nrchips); i++) {
3866 ioaddr = panelp->iobase + (i * 4);
3867 outb((ioaddr + XP_ADDR), SCCR);
3868 outb((ioaddr + XP_DATA), CR_RESETALL);
3869 outb((ioaddr + XP_ADDR), TSTR);
3870 if (inb(ioaddr + XP_DATA) != 0) {
3871 printf("STALLION: sc26198 not responding, "
3872 "board=%d panel=%d chip=%d\n", panelp->brdnr,
3873 panelp->panelnr, i);
3876 chipmask |= (0x1 << i);
3877 outb((ioaddr + XP_ADDR), GCCR);
3878 outb((ioaddr + XP_DATA), GCCR_IVRTYPCHANACK);
3879 outb((ioaddr + XP_ADDR), WDTRCR);
3880 outb((ioaddr + XP_DATA), 0xff);
3883 BRDDISABLE(panelp->brdnr);
3887 /*****************************************************************************/
3890 * Initialize hardware specific port registers.
3893 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3896 printf("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
3897 (int) brdp, (int) panelp, (int) portp);
3900 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
3901 (portp == (stlport_t *) NULL))
3904 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
3905 portp->uartaddr = (portp->portnr & 0x07) << 4;
3906 portp->pagenr = panelp->pagenr;
3909 BRDENABLE(portp->brdnr, portp->pagenr);
3910 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
3911 BRDDISABLE(portp->brdnr);
3914 /*****************************************************************************/
3917 * Set up the sc26198 registers for a port based on the termios port
3921 static int stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
3923 unsigned char mr0, mr1, mr2, clk;
3924 unsigned char imron, imroff, iopr, ipr;
3928 printf("stl_sc26198setport(portp=%x,tiosp=%x): brdnr=%d portnr=%d\n",
3929 (int) portp, (int) tiosp, portp->brdnr, portp->portnr);
3941 * Set up the RX char ignore mask with those RX error types we
3944 portp->rxignoremsk = 0;
3945 if (tiosp->c_iflag & IGNPAR)
3946 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
3948 if (tiosp->c_iflag & IGNBRK)
3949 portp->rxignoremsk |= SR_RXBREAK;
3951 portp->rxmarkmsk = SR_RXOVERRUN;
3952 if (tiosp->c_iflag & (INPCK | PARMRK))
3953 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
3954 if (tiosp->c_iflag & BRKINT)
3955 portp->rxmarkmsk |= SR_RXBREAK;
3958 * Go through the char size, parity and stop bits and set all the
3959 * option registers appropriately.
3961 switch (tiosp->c_cflag & CSIZE) {
3976 if (tiosp->c_cflag & CSTOPB)
3981 if (tiosp->c_cflag & PARENB) {
3982 if (tiosp->c_cflag & PARODD)
3983 mr1 |= (MR1_PARENB | MR1_PARODD);
3985 mr1 |= (MR1_PARENB | MR1_PAREVEN);
3990 mr1 |= MR1_ERRBLOCK;
3993 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
3994 * space for hardware flow control and the like. This should be set to
3997 mr2 |= MR2_RXFIFOHALF;
4000 * Calculate the baud rate timers. For now we will just assume that
4001 * the input and output baud are the same. The sc26198 has a fixed
4002 * baud rate table, so only discrete baud rates possible.
4004 if (tiosp->c_ispeed == 0)
4005 tiosp->c_ispeed = tiosp->c_ospeed;
4006 if ((tiosp->c_ospeed < 0) || (tiosp->c_ospeed > SC26198_MAXBAUD))
4009 if (tiosp->c_ospeed > 0) {
4010 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
4011 if (tiosp->c_ospeed <= sc26198_baudtable[clk])
4017 * Check what form of modem signaling is required and set it up.
4019 if ((tiosp->c_cflag & CLOCAL) == 0) {
4020 iopr |= IOPR_DCDCOS;
4025 * Setup sc26198 enhanced modes if we can. In particular we want to
4026 * handle as much of the flow control as possible automatically. As
4027 * well as saving a few CPU cycles it will also greatly improve flow
4028 * control reliability.
4030 if (tiosp->c_iflag & IXON) {
4031 mr0 |= MR0_SWFTX | MR0_SWFT;
4032 imron |= IR_XONXOFF;
4034 imroff |= IR_XONXOFF;
4037 if (tiosp->c_iflag & IXOFF)
4041 if (tiosp->c_cflag & CCTS_OFLOW)
4043 if (tiosp->c_cflag & CRTS_IFLOW)
4047 * All sc26198 register values calculated so go through and set
4052 printf("SETPORT: portnr=%d panelnr=%d brdnr=%d\n", portp->portnr,
4053 portp->panelnr, portp->brdnr);
4054 printf(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4055 printf(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4056 printf(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4057 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4058 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4062 BRDENABLE(portp->brdnr, portp->pagenr);
4063 stl_sc26198setreg(portp, IMR, 0);
4064 stl_sc26198updatereg(portp, MR0, mr0);
4065 stl_sc26198updatereg(portp, MR1, mr1);
4066 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4067 stl_sc26198updatereg(portp, MR2, mr2);
4068 iopr = (stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr;
4069 if (tiosp->c_ospeed == 0) {
4073 stl_sc26198setreg(portp, TXCSR, clk);
4074 stl_sc26198setreg(portp, RXCSR, clk);
4076 stl_sc26198updatereg(portp, IOPIOR, iopr);
4077 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4078 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4079 ipr = stl_sc26198getreg(portp, IPR);
4081 portp->sigs &= ~TIOCM_CD;
4083 portp->sigs |= TIOCM_CD;
4084 portp->imr = (portp->imr & ~imroff) | imron;
4085 stl_sc26198setreg(portp, IMR, portp->imr);
4086 BRDDISABLE(portp->brdnr);
4087 portp->state &= ~(ASY_RTSFLOWMODE | ASY_CTSFLOWMODE);
4088 portp->state |= ((tiosp->c_cflag & CRTS_IFLOW) ? ASY_RTSFLOWMODE : 0);
4089 portp->state |= ((tiosp->c_cflag & CCTS_OFLOW) ? ASY_CTSFLOWMODE : 0);
4090 stl_ttyoptim(portp, tiosp);
4096 /*****************************************************************************/
4099 * Set the state of the DTR and RTS signals.
4102 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
4104 unsigned char iopioron, iopioroff;
4108 printf("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4109 (int) portp, dtr, rts);
4115 iopioroff |= IPR_DTR;
4117 iopioron |= IPR_DTR;
4119 iopioroff |= IPR_RTS;
4121 iopioron |= IPR_RTS;
4124 BRDENABLE(portp->brdnr, portp->pagenr);
4125 if ((rts >= 0) && (portp->tty.t_cflag & CRTS_IFLOW)) {
4127 stl_sc26198setreg(portp, MR1,
4128 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4129 portp->stats.rxrtsoff++;
4131 stl_sc26198setreg(portp, MR1,
4132 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4133 portp->stats.rxrtson++;
4136 stl_sc26198setreg(portp, IOPIOR,
4137 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4138 BRDDISABLE(portp->brdnr);
4142 /*****************************************************************************/
4145 * Return the state of the signals.
4148 static int stl_sc26198getsignals(stlport_t *portp)
4154 printf("stl_sc26198getsignals(portp=%x)\n", (int) portp);
4158 BRDENABLE(portp->brdnr, portp->pagenr);
4159 ipr = stl_sc26198getreg(portp, IPR);
4160 BRDDISABLE(portp->brdnr);
4164 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4165 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4166 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4167 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4171 /*****************************************************************************/
4174 * Enable/Disable the Transmitter and/or Receiver.
4177 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
4183 printf("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4184 (int) portp, rx, tx);
4187 ccr = portp->crenable;
4189 ccr &= ~CR_TXENABLE;
4193 ccr &= ~CR_RXENABLE;
4198 BRDENABLE(portp->brdnr, portp->pagenr);
4199 stl_sc26198setreg(portp, SCCR, ccr);
4200 BRDDISABLE(portp->brdnr);
4201 portp->crenable = ccr;
4205 /*****************************************************************************/
4208 * Start/stop the Transmitter and/or Receiver.
4211 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
4217 printf("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4218 (int) portp, rx, tx);
4227 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4229 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4232 BRDENABLE(portp->brdnr, portp->pagenr);
4233 stl_sc26198setreg(portp, IMR, imr);
4234 BRDDISABLE(portp->brdnr);
4237 portp->state |= ASY_TXBUSY;
4238 portp->tty.t_state |= TS_BUSY;
4243 /*****************************************************************************/
4246 * Disable all interrupts from this port.
4249 static void stl_sc26198disableintrs(stlport_t *portp)
4254 printf("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
4258 BRDENABLE(portp->brdnr, portp->pagenr);
4260 stl_sc26198setreg(portp, IMR, 0);
4261 BRDDISABLE(portp->brdnr);
4265 /*****************************************************************************/
4267 static void stl_sc26198sendbreak(stlport_t *portp, long len)
4272 printf("stl_sc26198sendbreak(portp=%x,len=%d)\n",
4273 (int) portp, (int) len);
4277 BRDENABLE(portp->brdnr, portp->pagenr);
4279 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4280 portp->stats.txbreaks++;
4282 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4284 BRDDISABLE(portp->brdnr);
4288 /*****************************************************************************/
4291 * Take flow control actions...
4294 static void stl_sc26198sendflow(stlport_t *portp, int hw, int sw)
4300 printf("stl_sc26198sendflow(portp=%x,hw=%d,sw=%d)\n",
4301 (int) portp, hw, sw);
4304 if (portp == (stlport_t *) NULL)
4308 BRDENABLE(portp->brdnr, portp->pagenr);
4311 mr0 = stl_sc26198getreg(portp, MR0);
4312 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4314 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4316 portp->stats.rxxoff++;
4318 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4320 portp->stats.rxxon++;
4322 stl_sc26198wait(portp);
4323 stl_sc26198setreg(portp, MR0, mr0);
4327 portp->state |= ASY_RTSFLOW;
4328 stl_sc26198setreg(portp, MR1,
4329 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4330 stl_sc26198setreg(portp, IOPIOR,
4331 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4332 portp->stats.rxrtsoff++;
4333 } else if (hw > 0) {
4334 portp->state &= ~ASY_RTSFLOW;
4335 stl_sc26198setreg(portp, MR1,
4336 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4337 stl_sc26198setreg(portp, IOPIOR,
4338 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4339 portp->stats.rxrtson++;
4342 BRDDISABLE(portp->brdnr);
4346 /*****************************************************************************/
4349 * Return the current state of data flow on this port. This is only
4350 * really interresting when determining if data has fully completed
4351 * transmission or not... The sc26198 interrupt scheme cannot
4352 * determine when all data has actually drained, so we need to
4353 * check the port statusy register to be sure.
4356 static int stl_sc26198datastate(stlport_t *portp)
4362 printf("stl_sc26198datastate(portp=%x)\n", (int) portp);
4365 if (portp == (stlport_t *) NULL)
4367 if (portp->state & ASY_TXBUSY)
4371 BRDENABLE(portp->brdnr, portp->pagenr);
4372 sr = stl_sc26198getreg(portp, SR);
4373 BRDDISABLE(portp->brdnr);
4376 return((sr & SR_TXEMPTY) ? 0 : 1);
4379 /*****************************************************************************/
4381 static void stl_sc26198flush(stlport_t *portp, int flag)
4386 printf("stl_sc26198flush(portp=%x,flag=%x)\n", (int) portp, flag);
4389 if (portp == (stlport_t *) NULL)
4393 BRDENABLE(portp->brdnr, portp->pagenr);
4394 if (flag & FWRITE) {
4395 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4396 stl_sc26198setreg(portp, SCCR, portp->crenable);
4399 while (stl_sc26198getreg(portp, SR) & SR_RXRDY)
4400 stl_sc26198getreg(portp, RXFIFO);
4402 BRDDISABLE(portp->brdnr);
4406 /*****************************************************************************/
4409 * If we are TX flow controlled and in IXANY mode then we may
4410 * need to unflow control here. We gotta do this because of the
4411 * automatic flow control modes of the sc26198 - which downs't
4412 * support any concept of an IXANY mode.
4415 static void stl_sc26198txunflow(stlport_t *portp)
4419 mr0 = stl_sc26198getreg(portp, MR0);
4420 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4421 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4422 stl_sc26198setreg(portp, MR0, mr0);
4423 portp->state &= ~ASY_TXFLOWED;
4426 /*****************************************************************************/
4429 * Delay for a small amount of time, to give the sc26198 a chance
4430 * to process a command...
4433 static void stl_sc26198wait(stlport_t *portp)
4438 printf("stl_sc26198wait(portp=%x)\n", (int) portp);
4441 if (portp == (stlport_t *) NULL)
4444 for (i = 0; (i < 20); i++)
4445 stl_sc26198getglobreg(portp, TSTR);
4448 /*****************************************************************************/
4451 * Transmit interrupt handler. This has gotta be fast! Handling TX
4452 * chars is pretty simple, stuff as many as possible from the TX buffer
4453 * into the sc26198 FIFO.
4456 static __inline void stl_sc26198txisr(stlport_t *portp)
4458 unsigned int ioaddr;
4464 printf("stl_sc26198txisr(portp=%x)\n", (int) portp);
4467 ioaddr = portp->ioaddr;
4469 head = portp->tx.head;
4470 tail = portp->tx.tail;
4471 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4472 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4473 ((portp->state & ASY_TXLOW) == 0))) {
4474 portp->state |= ASY_TXLOW;
4479 outb((ioaddr + XP_ADDR), (MR0 | portp->uartaddr));
4480 mr0 = inb(ioaddr + XP_DATA);
4481 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4482 portp->imr &= ~IR_TXRDY;
4483 outb((ioaddr + XP_ADDR), (IMR | portp->uartaddr));
4484 outb((ioaddr + XP_DATA), portp->imr);
4485 portp->state |= ASY_TXEMPTY;
4486 portp->state &= ~ASY_TXBUSY;
4488 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4489 outb((ioaddr + XP_DATA), mr0);
4492 len = MIN(len, SC26198_TXFIFOSIZE);
4493 portp->stats.txtotal += len;
4494 stlen = MIN(len, (portp->tx.endbuf - tail));
4495 outb((ioaddr + XP_ADDR), GTXFIFO);
4496 outsb((ioaddr + XP_DATA), tail, stlen);
4499 if (tail >= portp->tx.endbuf)
4500 tail = portp->tx.buf;
4502 outsb((ioaddr + XP_DATA), tail, len);
4505 portp->tx.tail = tail;
4509 /*****************************************************************************/
4512 * Receive character interrupt handler. Determine if we have good chars
4513 * or bad chars and then process appropriately. Good chars are easy
4514 * just shove the lot into the RX buffer and set all status byte to 0.
4515 * If a bad RX char then process as required. This routine needs to be
4519 static __inline void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
4522 printf("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
4525 if ((iack & IVR_TYPEMASK) == IVR_RXDATA)
4526 stl_sc26198rxgoodchars(portp);
4528 stl_sc26198rxbadchars(portp);
4531 * If we are TX flow controlled and in IXANY mode then we may need
4532 * to unflow control here. We gotta do this because of the automatic
4533 * flow control modes of the sc26198.
4535 if ((portp->state & ASY_TXFLOWED) && (portp->tty.t_iflag & IXANY))
4536 stl_sc26198txunflow(portp);
4539 /*****************************************************************************/
4542 * Process the good received characters from RX FIFO.
4545 static void stl_sc26198rxgoodchars(stlport_t *portp)
4547 unsigned int ioaddr, len, buflen, stlen;
4551 printf("stl_sc26198rxgoodchars(port=%x)\n", (int) portp);
4554 ioaddr = portp->ioaddr;
4557 * First up, calculate how much room there is in the RX ring queue.
4558 * We also want to keep track of the longest possible copy length,
4559 * this has to allow for the wrapping of the ring queue.
4561 head = portp->rx.head;
4562 tail = portp->rx.tail;
4564 buflen = STL_RXBUFSIZE - (head - tail) - 1;
4565 stlen = portp->rx.endbuf - head;
4567 buflen = tail - head - 1;
4572 * Check if the input buffer is near full. If so then we should take
4573 * some flow control action... It is very easy to do hardware and
4574 * software flow control from here since we have the port selected on
4577 if (buflen <= (STL_RXBUFSIZE - STL_RXBUFHIGH)) {
4578 if (((portp->state & ASY_RTSFLOW) == 0) &&
4579 (portp->state & ASY_RTSFLOWMODE)) {
4580 portp->state |= ASY_RTSFLOW;
4581 stl_sc26198setreg(portp, MR1,
4582 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4583 stl_sc26198setreg(portp, IOPIOR,
4584 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4585 portp->stats.rxrtsoff++;
4590 * OK we are set, process good data... If the RX ring queue is full
4591 * just chuck the chars - don't leave them in the UART.
4593 outb((ioaddr + XP_ADDR), GIBCR);
4594 len = inb(ioaddr + XP_DATA) + 1;
4596 outb((ioaddr + XP_ADDR), GRXFIFO);
4597 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4598 portp->stats.rxlost += len;
4599 portp->stats.rxtotal += len;
4601 len = MIN(len, buflen);
4602 portp->stats.rxtotal += len;
4603 stlen = MIN(len, stlen);
4605 outb((ioaddr + XP_ADDR), GRXFIFO);
4606 insb((ioaddr + XP_DATA), head, stlen);
4608 if (head >= portp->rx.endbuf) {
4609 head = portp->rx.buf;
4611 insb((ioaddr + XP_DATA), head, len);
4617 portp->rx.head = head;
4618 portp->state |= ASY_RXDATA;
4622 /*****************************************************************************/
4625 * Process all characters in the RX FIFO of the UART. Check all char
4626 * status bytes as well, and process as required. We need to check
4627 * all bytes in the FIFO, in case some more enter the FIFO while we
4628 * are here. To get the exact character error type we need to switch
4629 * into CHAR error mode (that is why we need to make sure we empty
4633 static void stl_sc26198rxbadchars(stlport_t *portp)
4636 unsigned int status;
4642 * First up, calculate how much room there is in the RX ring queue.
4643 * We also want to keep track of the longest possible copy length,
4644 * this has to allow for the wrapping of the ring queue.
4646 head = portp->rx.head;
4647 tail = portp->rx.tail;
4648 len = (head >= tail) ? (STL_RXBUFSIZE - (head - tail) - 1) :
4652 * To get the precise error type for each character we must switch
4653 * back into CHAR error mode.
4655 mr1 = stl_sc26198getreg(portp, MR1);
4656 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
4658 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
4659 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
4660 ch = stl_sc26198getreg(portp, RXFIFO);
4662 if (status & SR_RXBREAK)
4663 portp->stats.rxbreaks++;
4664 if (status & SR_RXFRAMING)
4665 portp->stats.rxframing++;
4666 if (status & SR_RXPARITY)
4667 portp->stats.rxparity++;
4668 if (status & SR_RXOVERRUN)
4669 portp->stats.rxoverrun++;
4670 if ((portp->rxignoremsk & status) == 0) {
4671 if ((portp->tty.t_state & TS_CAN_BYPASS_L_RINT) &&
4672 ((status & SR_RXFRAMING) ||
4673 ((status & SR_RXPARITY) &&
4674 (portp->tty.t_iflag & INPCK))))
4676 if ((portp->rxmarkmsk & status) == 0)
4679 *(head + STL_RXBUFSIZE) = status;
4681 if (head >= portp->rx.endbuf)
4682 head = portp->rx.buf;
4689 * To get correct interrupt class we must switch back into BLOCK
4692 stl_sc26198setreg(portp, MR1, mr1);
4694 portp->rx.head = head;
4695 portp->state |= ASY_RXDATA;
4699 /*****************************************************************************/
4702 * Other interrupt handler. This includes modem signals, flow
4703 * control actions, etc.
4706 static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
4708 unsigned char cir, ipr, xisr;
4711 printf("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
4714 cir = stl_sc26198getglobreg(portp, CIR);
4716 switch (cir & CIR_SUBTYPEMASK) {
4718 ipr = stl_sc26198getreg(portp, IPR);
4719 if (ipr & IPR_DCDCHANGE) {
4720 portp->state |= ASY_DCDCHANGE;
4721 portp->stats.modem++;
4725 case CIR_SUBXONXOFF:
4726 xisr = stl_sc26198getreg(portp, XISR);
4727 if (xisr & XISR_RXXONGOT) {
4728 portp->state |= ASY_TXFLOWED;
4729 portp->stats.txxoff++;
4731 if (xisr & XISR_RXXOFFGOT) {
4732 portp->state &= ~ASY_TXFLOWED;
4733 portp->stats.txxon++;
4737 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
4738 stl_sc26198rxbadchars(portp);
4745 /*****************************************************************************/
4748 * Interrupt service routine for sc26198 panels.
4751 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4757 * Work around bug in sc26198 chip... Cannot have A6 address
4758 * line of UART high, else iack will be returned as 0.
4760 outb((iobase + 1), 0);
4762 iack = inb(iobase + XP_IACK);
4764 printf("stl_sc26198intr(panelp=%p,iobase=%x): iack=%x\n", panelp, iobase, iack);
4766 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4768 if (iack & IVR_RXDATA)
4769 stl_sc26198rxisr(portp, iack);
4770 else if (iack & IVR_TXDATA)
4771 stl_sc26198txisr(portp);
4773 stl_sc26198otherisr(portp, iack);
4776 /*****************************************************************************/