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.4 2003/07/19 21:14:34 dillon Exp $
40 /*****************************************************************************/
44 #include "opt_compat.h"
46 #include <sys/param.h>
47 #include <sys/systm.h>
48 #include <sys/kernel.h>
49 #include <sys/malloc.h>
53 #include <sys/fcntl.h>
54 #include <i386/isa/isa_device.h>
55 #include <i386/isa/ic/scd1400.h>
56 #include <i386/isa/ic/sc26198.h>
57 #include <machine/comstats.h>
61 #include <pci/pcivar.h>
62 #include <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 "compatable" 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 proc *p);
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 /* close */ stlclose,
752 /* write */ ttywrite,
753 /* ioctl */ stlioctl,
756 /* strategy */ nostrategy,
758 /* maj */ CDEV_MAJOR,
761 /* flags */ D_TTY | D_KQFILTER,
763 /* kqfilter */ ttykqfilter,
766 static void stl_drvinit(void *unused)
769 cdevsw_add(&stl_cdevsw);
772 SYSINIT(sidev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,stl_drvinit,NULL)
776 /*****************************************************************************/
779 * Probe for some type of EasyIO or EasyConnection 8/32 board at
780 * the supplied address. All we do is check if we can find the
781 * board ID for the board... (Note, PCI boards not checked here,
782 * they are done in the stlpciprobe() routine).
785 static int stlprobe(struct isa_device *idp)
790 printf("stlprobe(idp=%x): unit=%d iobase=%x\n", (int) idp,
791 idp->id_unit, idp->id_iobase);
794 if (idp->id_unit > STL_MAXBRDS)
797 status = inb(idp->id_iobase + 1);
798 if ((status & ECH_IDBITMASK) == ECH_ID) {
799 stl_brdprobed[idp->id_unit] = BRD_ECH;
803 status = inb(idp->id_iobase + 2);
804 switch (status & EIO_IDBITMASK) {
810 stl_brdprobed[idp->id_unit] = BRD_EASYIO;
819 /*****************************************************************************/
822 * Find an available internal board number (unit number). The problem
823 * is that the same unit numbers can be assigned to different boards
824 * detected during the ISA and PCI initialization phases.
827 static int stl_findfreeunit()
831 for (i = 0; (i < STL_MAXBRDS); i++)
832 if (stl_brds[i] == (stlbrd_t *) NULL)
834 return((i >= STL_MAXBRDS) ? -1 : i);
837 /*****************************************************************************/
840 * Allocate resources for and initialize the specified board.
843 static int stlattach(struct isa_device *idp)
846 int boardnr, portnr, minor_dev;
849 printf("stlattach(idp=%p): unit=%d iobase=%x\n", (void *) idp,
850 idp->id_unit, idp->id_iobase);
853 /* idp->id_ointr = stlintr; */
855 brdp = (stlbrd_t *) malloc(sizeof(stlbrd_t), M_TTYS, M_NOWAIT);
856 if (brdp == (stlbrd_t *) NULL) {
857 printf("STALLION: failed to allocate memory (size=%d)\n",
861 bzero(brdp, sizeof(stlbrd_t));
863 if ((brdp->brdnr = stl_findfreeunit()) < 0) {
864 printf("STALLION: too many boards found, max=%d\n",
868 if (brdp->brdnr >= stl_nrbrds)
869 stl_nrbrds = brdp->brdnr + 1;
871 brdp->unitid = idp->id_unit;
872 brdp->brdtype = stl_brdprobed[idp->id_unit];
873 brdp->ioaddr1 = idp->id_iobase;
874 brdp->ioaddr2 = stl_ioshared;
875 brdp->irq = ffs(idp->id_irq) - 1;
876 brdp->irqtype = stl_irqshared;
879 /* register devices for DEVFS */
880 boardnr = brdp->brdnr;
881 make_dev(&stl_cdevsw, boardnr + 0x1000000, UID_ROOT, GID_WHEEL,
882 0600, "staliomem%d", boardnr);
884 for (portnr = 0, minor_dev = boardnr * 0x100000;
885 portnr < 32; portnr++, minor_dev++) {
887 make_dev(&stl_cdevsw, minor_dev,
888 UID_ROOT, GID_WHEEL, 0600,
889 "ttyE%d", portnr + (boardnr * 64));
890 make_dev(&stl_cdevsw, minor_dev + 32,
891 UID_ROOT, GID_WHEEL, 0600,
892 "ttyiE%d", portnr + (boardnr * 64));
893 make_dev(&stl_cdevsw, minor_dev + 64,
894 UID_ROOT, GID_WHEEL, 0600,
895 "ttylE%d", portnr + (boardnr * 64));
896 make_dev(&stl_cdevsw, minor_dev + 128,
897 UID_ROOT, GID_WHEEL, 0600,
898 "cue%d", portnr + (boardnr * 64));
899 make_dev(&stl_cdevsw, minor_dev + 160,
900 UID_ROOT, GID_WHEEL, 0600,
901 "cuie%d", portnr + (boardnr * 64));
902 make_dev(&stl_cdevsw, minor_dev + 192,
903 UID_ROOT, GID_WHEEL, 0600,
904 "cule%d", portnr + (boardnr * 64));
907 make_dev(&stl_cdevsw, minor_dev + 0x10000,
908 UID_ROOT, GID_WHEEL, 0600,
909 "ttyE%d", portnr + (boardnr * 64) + 32);
910 make_dev(&stl_cdevsw, minor_dev + 32 + 0x10000,
911 UID_ROOT, GID_WHEEL, 0600,
912 "ttyiE%d", portnr + (boardnr * 64) + 32);
913 make_dev(&stl_cdevsw, minor_dev + 64 + 0x10000,
914 UID_ROOT, GID_WHEEL, 0600,
915 "ttylE%d", portnr + (boardnr * 64) + 32);
916 make_dev(&stl_cdevsw, minor_dev + 128 + 0x10000,
917 UID_ROOT, GID_WHEEL, 0600,
918 "cue%d", portnr + (boardnr * 64) + 32);
919 make_dev(&stl_cdevsw, minor_dev + 160 + 0x10000,
920 UID_ROOT, GID_WHEEL, 0600,
921 "cuie%d", portnr + (boardnr * 64) + 32);
922 make_dev(&stl_cdevsw, minor_dev + 192 + 0x10000,
923 UID_ROOT, GID_WHEEL, 0600,
924 "cule%d", portnr + (boardnr * 64) + 32);
926 boardnr = brdp->brdnr;
927 make_dev(&stl_cdevsw, boardnr + 0x1000000, UID_ROOT, GID_WHEEL,
928 0600, "staliomem%d", boardnr);
930 for (portnr = 0, minor_dev = boardnr * 0x100000;
931 portnr < 32; portnr++, minor_dev++) {
933 make_dev(&stl_cdevsw, minor_dev,
934 UID_ROOT, GID_WHEEL, 0600,
935 "ttyE%d", portnr + (boardnr * 64));
936 make_dev(&stl_cdevsw, minor_dev + 32,
937 UID_ROOT, GID_WHEEL, 0600,
938 "ttyiE%d", portnr + (boardnr * 64));
939 make_dev(&stl_cdevsw, minor_dev + 64,
940 UID_ROOT, GID_WHEEL, 0600,
941 "ttylE%d", portnr + (boardnr * 64));
942 make_dev(&stl_cdevsw, minor_dev + 128,
943 UID_ROOT, GID_WHEEL, 0600,
944 "cue%d", portnr + (boardnr * 64));
945 make_dev(&stl_cdevsw, minor_dev + 160,
946 UID_ROOT, GID_WHEEL, 0600,
947 "cuie%d", portnr + (boardnr * 64));
948 make_dev(&stl_cdevsw, minor_dev + 192,
949 UID_ROOT, GID_WHEEL, 0600,
950 "cule%d", portnr + (boardnr * 64));
953 make_dev(&stl_cdevsw, minor_dev + 0x10000,
954 UID_ROOT, GID_WHEEL, 0600,
955 "ttyE%d", portnr + (boardnr * 64) + 32);
956 make_dev(&stl_cdevsw, minor_dev + 32 + 0x10000,
957 UID_ROOT, GID_WHEEL, 0600,
958 "ttyiE%d", portnr + (boardnr * 64) + 32);
959 make_dev(&stl_cdevsw, minor_dev + 64 + 0x10000,
960 UID_ROOT, GID_WHEEL, 0600,
961 "ttylE%d", portnr + (boardnr * 64) + 32);
962 make_dev(&stl_cdevsw, minor_dev + 128 + 0x10000,
963 UID_ROOT, GID_WHEEL, 0600,
964 "cue%d", portnr + (boardnr * 64) + 32);
965 make_dev(&stl_cdevsw, minor_dev + 160 + 0x10000,
966 UID_ROOT, GID_WHEEL, 0600,
967 "cuie%d", portnr + (boardnr * 64) + 32);
968 make_dev(&stl_cdevsw, minor_dev + 192 + 0x10000,
969 UID_ROOT, GID_WHEEL, 0600,
970 "cule%d", portnr + (boardnr * 64) + 32);
976 /*****************************************************************************/
981 * Probe specifically for the PCI boards. We need to be a little
982 * carefull here, since it looks sort like a Nat Semi IDE chip...
985 static const char *stlpciprobe(pcici_t tag, pcidi_t type)
991 printf("stlpciprobe(tag=%x,type=%x)\n", (int) &tag, (int) type);
995 for (i = 0; (i < stl_nrpcibrds); i++) {
996 if (((type & 0xffff) == stl_pcibrds[i].vendid) &&
997 (((type >> 16) & 0xffff) == stl_pcibrds[i].devid)) {
998 brdtype = stl_pcibrds[i].brdtype;
1004 return((char *) NULL);
1006 class = pci_conf_read(tag, PCI_CLASS_REG);
1007 if ((class & PCI_CLASS_MASK) == PCI_CLASS_MASS_STORAGE)
1008 return((char *) NULL);
1010 return(stl_brdnames[brdtype]);
1013 /*****************************************************************************/
1016 * Allocate resources for and initialize the specified PCI board.
1019 void stlpciattach(pcici_t tag, int unit)
1022 unsigned int bar[4];
1025 int boardnr, portnr, minor_dev;
1028 printf("stlpciattach(tag=%x,unit=%x)\n", (int) &tag, unit);
1031 brdp = (stlbrd_t *) malloc(sizeof(stlbrd_t), M_TTYS, M_NOWAIT);
1032 if (brdp == (stlbrd_t *) NULL) {
1033 printf("STALLION: failed to allocate memory (size=%d)\n",
1037 bzero(brdp, sizeof(stlbrd_t));
1039 if ((unit < 0) || (unit > STL_MAXBRDS)) {
1040 printf("STALLION: bad PCI board unit number=%d\n", unit);
1045 * Allocate us a new driver unique unit number.
1047 if ((brdp->brdnr = stl_findfreeunit()) < 0) {
1048 printf("STALLION: too many boards found, max=%d\n",
1052 if (brdp->brdnr >= stl_nrbrds)
1053 stl_nrbrds = brdp->brdnr + 1;
1056 * Determine what type of PCI board this is...
1058 id = (unsigned int) pci_conf_read(tag, 0x0);
1059 for (i = 0; (i < stl_nrpcibrds); i++) {
1060 if (((id & 0xffff) == stl_pcibrds[i].vendid) &&
1061 (((id >> 16) & 0xffff) == stl_pcibrds[i].devid)) {
1062 brdp->brdtype = stl_pcibrds[i].brdtype;
1067 if (i >= stl_nrpcibrds) {
1068 printf("STALLION: probed PCI board unknown type=%x\n", id);
1072 for (i = 0; (i < 4); i++)
1073 bar[i] = (unsigned int) pci_conf_read(tag, 0x10 + (i * 4)) &
1076 switch (brdp->brdtype) {
1078 brdp->ioaddr1 = bar[1];
1079 brdp->ioaddr2 = bar[2];
1082 brdp->ioaddr1 = bar[2];
1083 brdp->ioaddr2 = bar[1];
1086 brdp->ioaddr1 = bar[1];
1087 brdp->ioaddr2 = bar[0];
1090 printf("STALLION: unknown PCI board type=%d\n", brdp->brdtype);
1095 brdp->unitid = brdp->brdnr; /* PCI units auto-assigned */
1096 brdp->irq = ((int) pci_conf_read(tag, 0x3c)) & 0xff;
1098 if (pci_map_int(tag, stlpciintr, (void *) NULL, &tty_imask) == 0) {
1099 printf("STALLION: failed to map interrupt irq=%d for unit=%d\n",
1100 brdp->irq, brdp->brdnr);
1106 /* register devices for DEVFS */
1107 boardnr = brdp->brdnr;
1108 make_dev(&stl_cdevsw, boardnr + 0x1000000, UID_ROOT, GID_WHEEL,
1109 0600, "staliomem%d", boardnr);
1111 for (portnr = 0, minor_dev = boardnr * 0x100000;
1112 portnr < 32; portnr++, minor_dev++) {
1114 make_dev(&stl_cdevsw, minor_dev,
1115 UID_ROOT, GID_WHEEL, 0600,
1116 "ttyE%d", portnr + (boardnr * 64));
1117 make_dev(&stl_cdevsw, minor_dev + 32,
1118 UID_ROOT, GID_WHEEL, 0600,
1119 "ttyiE%d", portnr + (boardnr * 64));
1120 make_dev(&stl_cdevsw, minor_dev + 64,
1121 UID_ROOT, GID_WHEEL, 0600,
1122 "ttylE%d", portnr + (boardnr * 64));
1123 make_dev(&stl_cdevsw, minor_dev + 128,
1124 UID_ROOT, GID_WHEEL, 0600,
1125 "cue%d", portnr + (boardnr * 64));
1126 make_dev(&stl_cdevsw, minor_dev + 160,
1127 UID_ROOT, GID_WHEEL, 0600,
1128 "cuie%d", portnr + (boardnr * 64));
1129 make_dev(&stl_cdevsw, minor_dev + 192,
1130 UID_ROOT, GID_WHEEL, 0600,
1131 "cule%d", portnr + (boardnr * 64));
1134 make_dev(&stl_cdevsw, minor_dev + 0x10000,
1135 UID_ROOT, GID_WHEEL, 0600,
1136 "ttyE%d", portnr + (boardnr * 64) + 32);
1137 make_dev(&stl_cdevsw, minor_dev + 32 + 0x10000,
1138 UID_ROOT, GID_WHEEL, 0600,
1139 "ttyiE%d", portnr + (boardnr * 64) + 32);
1140 make_dev(&stl_cdevsw, minor_dev + 64 + 0x10000,
1141 UID_ROOT, GID_WHEEL, 0600,
1142 "ttylE%d", portnr + (boardnr * 64) + 32);
1143 make_dev(&stl_cdevsw, minor_dev + 128 + 0x10000,
1144 UID_ROOT, GID_WHEEL, 0600,
1145 "cue%d", portnr + (boardnr * 64) + 32);
1146 make_dev(&stl_cdevsw, minor_dev + 160 + 0x10000,
1147 UID_ROOT, GID_WHEEL, 0600,
1148 "cuie%d", portnr + (boardnr * 64) + 32);
1149 make_dev(&stl_cdevsw, minor_dev + 192 + 0x10000,
1150 UID_ROOT, GID_WHEEL, 0600,
1151 "cule%d", portnr + (boardnr * 64) + 32);
1157 /*****************************************************************************/
1159 STATIC int stlopen(dev_t dev, int flag, int mode, struct proc *p)
1163 int error, callout, x;
1166 printf("stlopen(dev=%x,flag=%x,mode=%x,p=%x)\n", (int) dev, flag,
1171 * Firstly check if the supplied device number is a valid device.
1173 if (minor(dev) & STL_MEMDEV)
1176 portp = stl_dev2port(dev);
1177 if (portp == (stlport_t *) NULL)
1179 if (minor(dev) & STL_CTRLDEV)
1183 callout = minor(dev) & STL_CALLOUTDEV;
1190 * Wait here for the DTR drop timeout period to expire.
1192 while (portp->state & ASY_DTRWAIT) {
1193 error = tsleep(&portp->dtrwait, PCATCH, "stldtr", 0);
1199 * We have a valid device, so now we check if it is already open.
1200 * If not then initialize the port hardware and set up the tty
1201 * struct as required.
1203 if ((tp->t_state & TS_ISOPEN) == 0) {
1204 tp->t_oproc = stl_start;
1205 tp->t_stop = stl_stop;
1206 tp->t_param = stl_param;
1208 tp->t_termios = callout ? portp->initouttios :
1212 if ((portp->sigs & TIOCM_CD) || callout)
1213 (*linesw[tp->t_line].l_modem)(tp, 1);
1216 if (portp->callout == 0) {
1221 if (portp->callout != 0) {
1222 if (flag & O_NONBLOCK) {
1226 error = tsleep(&portp->callout,
1227 PCATCH, "stlcall", 0);
1230 goto stlopen_restart;
1233 if ((tp->t_state & TS_XCLUDE) && suser(td)) {
1240 * If this port is not the callout device and we do not have carrier
1241 * then we need to sleep, waiting for it to be asserted.
1243 if (((tp->t_state & TS_CARR_ON) == 0) && !callout &&
1244 ((tp->t_cflag & CLOCAL) == 0) &&
1245 ((flag & O_NONBLOCK) == 0)) {
1247 error = tsleep(TSA_CARR_ON(tp), PCATCH, "stldcd", 0);
1251 goto stlopen_restart;
1255 * Open the line discipline.
1257 error = (*linesw[tp->t_line].l_open)(dev, tp);
1258 stl_ttyoptim(portp, &tp->t_termios);
1259 if ((tp->t_state & TS_ISOPEN) && callout)
1263 * If for any reason we get to here and the port is not actually
1264 * open then close of the physical hardware - no point leaving it
1265 * active when the open failed...
1269 if (((tp->t_state & TS_ISOPEN) == 0) && (portp->waitopens == 0))
1270 stl_rawclose(portp);
1275 /*****************************************************************************/
1277 STATIC int stlclose(dev_t dev, int flag, int mode, struct proc *p)
1284 printf("stlclose(dev=%s,flag=%x,mode=%x,p=%p)\n", devtoname(dev),
1285 flag, mode, (void *) p);
1288 if (minor(dev) & STL_MEMDEV)
1290 if (minor(dev) & STL_CTRLDEV)
1293 portp = stl_dev2port(dev);
1294 if (portp == (stlport_t *) NULL)
1299 (*linesw[tp->t_line].l_close)(tp, flag);
1300 stl_ttyoptim(portp, &tp->t_termios);
1301 stl_rawclose(portp);
1307 /*****************************************************************************/
1311 STATIC void stl_stop(struct tty *tp, int rw)
1314 printf("stl_stop(tp=%x,rw=%x)\n", (int) tp, rw);
1317 stl_flush((stlport_t *) tp, rw);
1322 STATIC int stlstop(struct tty *tp, int rw)
1325 printf("stlstop(tp=%x,rw=%x)\n", (int) tp, rw);
1328 stl_flush((stlport_t *) tp, rw);
1334 /*****************************************************************************/
1336 STATIC int stlioctl(dev_t dev, unsigned long cmd, caddr_t data, int flag,
1339 struct termios *newtios, *localtios;
1345 printf("stlioctl(dev=%s,cmd=%lx,data=%p,flag=%x,p=%p)\n",
1346 devtoname(dev), cmd, (void *) data, flag, (void *) p);
1349 if (minor(dev) & STL_MEMDEV)
1350 return(stl_memioctl(dev, cmd, data, flag, p));
1352 portp = stl_dev2port(dev);
1353 if (portp == (stlport_t *) NULL)
1359 * First up handle ioctls on the control devices.
1361 if (minor(dev) & STL_CTRLDEV) {
1362 if ((minor(dev) & STL_CTRLDEV) == STL_CTRLINIT)
1363 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1364 &portp->initouttios : &portp->initintios;
1365 else if ((minor(dev) & STL_CTRLDEV) == STL_CTRLLOCK)
1366 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1367 &portp->lockouttios : &portp->lockintios;
1373 if ((error = suser(td)) == 0)
1374 *localtios = *((struct termios *) data);
1377 *((struct termios *) data) = *localtios;
1380 *((int *) data) = TTYDISC;
1383 bzero(data, sizeof(struct winsize));
1393 * Deal with 4.3 compatability issues if we have too...
1395 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1397 struct termios tios;
1398 unsigned long oldcmd;
1400 tios = tp->t_termios;
1402 if ((error = ttsetcompat(tp, &cmd, data, &tios)))
1405 data = (caddr_t) &tios;
1410 * Carry out some pre-cmd processing work first...
1411 * Hmmm, not so sure we want this, disable for now...
1413 if ((cmd == TIOCSETA) || (cmd == TIOCSETAW) || (cmd == TIOCSETAF)) {
1414 newtios = (struct termios *) data;
1415 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1416 &portp->lockouttios : &portp->lockintios;
1418 newtios->c_iflag = (tp->t_iflag & localtios->c_iflag) |
1419 (newtios->c_iflag & ~localtios->c_iflag);
1420 newtios->c_oflag = (tp->t_oflag & localtios->c_oflag) |
1421 (newtios->c_oflag & ~localtios->c_oflag);
1422 newtios->c_cflag = (tp->t_cflag & localtios->c_cflag) |
1423 (newtios->c_cflag & ~localtios->c_cflag);
1424 newtios->c_lflag = (tp->t_lflag & localtios->c_lflag) |
1425 (newtios->c_lflag & ~localtios->c_lflag);
1426 for (i = 0; (i < NCCS); i++) {
1427 if (localtios->c_cc[i] != 0)
1428 newtios->c_cc[i] = tp->t_cc[i];
1430 if (localtios->c_ispeed != 0)
1431 newtios->c_ispeed = tp->t_ispeed;
1432 if (localtios->c_ospeed != 0)
1433 newtios->c_ospeed = tp->t_ospeed;
1437 * Call the line discipline and the common command processing to
1438 * process this command (if they can).
1440 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, p);
1441 if (error != ENOIOCTL)
1445 error = ttioctl(tp, cmd, data, flag);
1446 stl_ttyoptim(portp, &tp->t_termios);
1447 if (error != ENOIOCTL) {
1455 * Process local commands here. These are all commands that only we
1456 * can take care of (they all rely on actually doing something special
1457 * to the actual hardware).
1461 stl_sendbreak(portp, -1);
1464 stl_sendbreak(portp, -2);
1467 stl_setsignals(portp, 1, -1);
1470 stl_setsignals(portp, 0, -1);
1473 i = *((int *) data);
1474 stl_setsignals(portp, ((i & TIOCM_DTR) ? 1 : 0),
1475 ((i & TIOCM_RTS) ? 1 : 0));
1478 i = *((int *) data);
1479 stl_setsignals(portp, ((i & TIOCM_DTR) ? 1 : -1),
1480 ((i & TIOCM_RTS) ? 1 : -1));
1483 i = *((int *) data);
1484 stl_setsignals(portp, ((i & TIOCM_DTR) ? 0 : -1),
1485 ((i & TIOCM_RTS) ? 0 : -1));
1488 *((int *) data) = (stl_getsignals(portp) | TIOCM_LE);
1491 if ((error = suser(td)) == 0)
1492 portp->dtrwait = *((int *) data) * hz / 100;
1495 *((int *) data) = portp->dtrwait * 100 / hz;
1498 portp->dotimestamp = 1;
1499 *((struct timeval *) data) = portp->timestamp;
1509 /*****************************************************************************/
1512 * Convert the specified minor device number into a port struct
1513 * pointer. Return NULL if the device number is not a valid port.
1516 STATIC stlport_t *stl_dev2port(dev_t dev)
1520 brdp = stl_brds[MKDEV2BRD(dev)];
1521 if (brdp == (stlbrd_t *) NULL)
1522 return((stlport_t *) NULL);
1523 return(brdp->ports[MKDEV2PORT(dev)]);
1526 /*****************************************************************************/
1529 * Initialize the port hardware. This involves enabling the transmitter
1530 * and receiver, setting the port configuration, and setting the initial
1534 static int stl_rawopen(stlport_t *portp)
1537 printf("stl_rawopen(portp=%p): brdnr=%d panelnr=%d portnr=%d\n",
1538 (void *) portp, portp->brdnr, portp->panelnr, portp->portnr);
1541 stl_setport(portp, &portp->tty.t_termios);
1542 portp->sigs = stl_getsignals(portp);
1543 stl_setsignals(portp, 1, 1);
1544 stl_enablerxtx(portp, 1, 1);
1545 stl_startrxtx(portp, 1, 0);
1549 /*****************************************************************************/
1552 * Shutdown the hardware of a port. Disable its transmitter and
1553 * receiver, and maybe drop signals if appropriate.
1556 static int stl_rawclose(stlport_t *portp)
1561 printf("stl_rawclose(portp=%p): brdnr=%d panelnr=%d portnr=%d\n",
1562 (void *) portp, portp->brdnr, portp->panelnr, portp->portnr);
1566 stl_disableintrs(portp);
1567 stl_enablerxtx(portp, 0, 0);
1568 stl_flush(portp, (FWRITE | FREAD));
1569 if (tp->t_cflag & HUPCL) {
1570 stl_setsignals(portp, 0, 0);
1571 if (portp->dtrwait != 0) {
1572 portp->state |= ASY_DTRWAIT;
1573 timeout(stl_dtrwakeup, portp, portp->dtrwait);
1578 portp->state &= ~(ASY_ACTIVE | ASY_RTSFLOW);
1579 wakeup(&portp->callout);
1580 wakeup(TSA_CARR_ON(tp));
1584 /*****************************************************************************/
1587 * Clear the DTR waiting flag, and wake up any sleepers waiting for
1588 * DTR wait period to finish.
1591 static void stl_dtrwakeup(void *arg)
1595 portp = (stlport_t *) arg;
1596 portp->state &= ~ASY_DTRWAIT;
1597 wakeup(&portp->dtrwait);
1600 /*****************************************************************************/
1603 * Start (or continue) the transfer of TX data on this port. If the
1604 * port is not currently busy then load up the interrupt ring queue
1605 * buffer and kick of the transmitter. If the port is running low on
1606 * TX data then refill the ring queue. This routine is also used to
1607 * activate input flow control!
1610 static void stl_start(struct tty *tp)
1613 unsigned int len, stlen;
1617 portp = (stlport_t *) tp;
1620 printf("stl_start(tp=%x): brdnr=%d portnr=%d\n", (int) tp,
1621 portp->brdnr, portp->portnr);
1627 * Check if the ports input has been blocked, and take appropriate action.
1628 * Not very often do we really need to do anything, so make it quick.
1630 if (tp->t_state & TS_TBLOCK) {
1631 if ((portp->state & ASY_RTSFLOWMODE) &&
1632 ((portp->state & ASY_RTSFLOW) == 0))
1633 stl_flowcontrol(portp, 0, -1);
1635 if (portp->state & ASY_RTSFLOW)
1636 stl_flowcontrol(portp, 1, -1);
1641 * Check if the output cooked clist buffers are near empty, wake up
1642 * the line discipline to fill it up.
1644 if (tp->t_outq.c_cc <= tp->t_lowat) {
1645 if (tp->t_state & TS_ASLEEP) {
1646 tp->t_state &= ~TS_ASLEEP;
1647 wakeup(&tp->t_outq);
1649 selwakeup(&tp->t_wsel);
1653 if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
1659 * Copy data from the clists into the interrupt ring queue. This will
1660 * require at most 2 copys... What we do is calculate how many chars
1661 * can fit into the ring queue, and how many can fit in 1 copy. If after
1662 * the first copy there is still more room then do the second copy.
1663 * The beauty of this type of ring queue is that we do not need to
1664 * spl protect our-selves, since we only ever update the head pointer,
1665 * and the interrupt routine only ever updates the tail pointer.
1667 if (tp->t_outq.c_cc != 0) {
1668 head = portp->tx.head;
1669 tail = portp->tx.tail;
1671 len = STL_TXBUFSIZE - (head - tail) - 1;
1672 stlen = portp->tx.endbuf - head;
1674 len = tail - head - 1;
1679 stlen = MIN(len, stlen);
1680 count = q_to_b(&tp->t_outq, head, stlen);
1683 if (head >= portp->tx.endbuf) {
1684 head = portp->tx.buf;
1686 stlen = q_to_b(&tp->t_outq, head, len);
1691 portp->tx.head = head;
1693 stl_startrxtx(portp, -1, 1);
1697 * If we sent something, make sure we are called again.
1699 tp->t_state |= TS_BUSY;
1704 * Do any writer wakeups.
1712 /*****************************************************************************/
1714 static void stl_flush(stlport_t *portp, int flag)
1720 printf("stl_flush(portp=%x,flag=%x)\n", (int) portp, flag);
1723 if (portp == (stlport_t *) NULL)
1728 if (flag & FWRITE) {
1729 stl_uartflush(portp, FWRITE);
1730 portp->tx.tail = portp->tx.head;
1734 * The only thing to watch out for when flushing the read side is
1735 * the RX status buffer. The interrupt code relys on the status
1736 * bytes as being zeroed all the time (it does not bother setting
1737 * a good char status to 0, it expects that it already will be).
1738 * We also need to un-flow the RX channel if flow control was
1742 head = portp->rx.head;
1743 tail = portp->rx.tail;
1748 len = portp->rx.endbuf - tail;
1749 bzero(portp->rxstatus.buf,
1750 (head - portp->rx.buf));
1752 bzero((tail + STL_RXBUFSIZE), len);
1753 portp->rx.tail = head;
1756 if ((portp->state & ASY_RTSFLOW) &&
1757 ((portp->tty.t_state & TS_TBLOCK) == 0))
1758 stl_flowcontrol(portp, 1, -1);
1764 /*****************************************************************************/
1767 * Interrupt handler for host based boards. Interrupts for all boards
1768 * are vectored through here.
1771 void stlintr(int unit)
1777 printf("stlintr(unit=%d)\n", unit);
1780 for (i = 0; (i < stl_nrbrds); i++) {
1781 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
1783 if (brdp->state == 0)
1785 (* brdp->isr)(brdp);
1789 /*****************************************************************************/
1793 static void stlpciintr(void *arg)
1800 /*****************************************************************************/
1803 * Interrupt service routine for EasyIO boards.
1806 static void stl_eiointr(stlbrd_t *brdp)
1812 printf("stl_eiointr(brdp=%p)\n", brdp);
1815 panelp = (stlpanel_t *) brdp->panels[0];
1816 iobase = panelp->iobase;
1817 while (inb(brdp->iostatus) & EIO_INTRPEND)
1818 (* panelp->isr)(panelp, iobase);
1822 * Interrupt service routine for ECH-AT board types.
1825 static void stl_echatintr(stlbrd_t *brdp)
1828 unsigned int ioaddr;
1831 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDENABLE));
1833 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1834 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1835 ioaddr = brdp->bnkstataddr[bnknr];
1836 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1837 panelp = brdp->bnk2panel[bnknr];
1838 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1843 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDDISABLE));
1846 /*****************************************************************************/
1849 * Interrupt service routine for ECH-MCA board types.
1852 static void stl_echmcaintr(stlbrd_t *brdp)
1855 unsigned int ioaddr;
1858 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1859 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1860 ioaddr = brdp->bnkstataddr[bnknr];
1861 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1862 panelp = brdp->bnk2panel[bnknr];
1863 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1869 /*****************************************************************************/
1872 * Interrupt service routine for ECH-PCI board types.
1875 static void stl_echpciintr(stlbrd_t *brdp)
1878 unsigned int ioaddr;
1882 printf("stl_echpciintr(brdp=%x)\n", (int) brdp);
1887 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1888 outb(brdp->ioctrl, brdp->bnkpageaddr[bnknr]);
1889 ioaddr = brdp->bnkstataddr[bnknr];
1890 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1891 panelp = brdp->bnk2panel[bnknr];
1892 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1901 /*****************************************************************************/
1904 * Interrupt service routine for EC8/64-PCI board types.
1907 static void stl_echpci64intr(stlbrd_t *brdp)
1910 unsigned int ioaddr;
1914 printf("stl_echpci64intr(brdp=%p)\n", brdp);
1917 while (inb(brdp->ioctrl) & 0x1) {
1918 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1919 ioaddr = brdp->bnkstataddr[bnknr];
1921 printf(" --> ioaddr=%x status=%x(%x)\n", ioaddr, inb(ioaddr) & ECH_PNLINTRPEND, inb(ioaddr));
1923 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1924 panelp = brdp->bnk2panel[bnknr];
1925 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1931 /*****************************************************************************/
1934 * If we haven't scheduled a timeout then do it, some port needs high
1938 static void stl_dotimeout()
1941 printf("stl_dotimeout()\n");
1944 if (stl_doingtimeout == 0) {
1945 timeout(stl_poll, 0, 1);
1950 /*****************************************************************************/
1953 * Service "software" level processing. Too slow or painfull to be done
1954 * at real hardware interrupt time. This way we might also be able to
1955 * do some service on other waiting ports as well...
1958 static void stl_poll(void *arg)
1963 int brdnr, portnr, rearm, x;
1966 printf("stl_poll()\n");
1969 stl_doingtimeout = 0;
1973 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1974 if ((brdp = stl_brds[brdnr]) == (stlbrd_t *) NULL)
1976 for (portnr = 0; (portnr < brdp->nrports); portnr++) {
1977 if ((portp = brdp->ports[portnr]) == (stlport_t *) NULL)
1979 if ((portp->state & ASY_ACTIVE) == 0)
1983 if (portp->state & ASY_RXDATA)
1984 stl_rxprocess(portp);
1985 if (portp->state & ASY_DCDCHANGE) {
1986 portp->state &= ~ASY_DCDCHANGE;
1987 portp->sigs = stl_getsignals(portp);
1988 (*linesw[tp->t_line].l_modem)(tp,
1989 (portp->sigs & TIOCM_CD));
1991 if (portp->state & ASY_TXEMPTY) {
1992 if (stl_datastate(portp) == 0) {
1993 portp->state &= ~ASY_TXEMPTY;
1994 tp->t_state &= ~TS_BUSY;
1995 (*linesw[tp->t_line].l_start)(tp);
1998 if (portp->state & ASY_TXLOW) {
1999 portp->state &= ~ASY_TXLOW;
2000 (*linesw[tp->t_line].l_start)(tp);
2003 if (portp->state & ASY_ACTIVE)
2013 /*****************************************************************************/
2016 * Process the RX data that has been buffered up in the RX ring queue.
2019 static void stl_rxprocess(stlport_t *portp)
2022 unsigned int len, stlen, lostlen;
2028 printf("stl_rxprocess(portp=%x): brdnr=%d portnr=%d\n", (int) portp,
2029 portp->brdnr, portp->portnr);
2033 portp->state &= ~ASY_RXDATA;
2035 if ((tp->t_state & TS_ISOPEN) == 0) {
2036 stl_flush(portp, FREAD);
2041 * Calculate the amount of data in the RX ring queue. Also calculate
2042 * the largest single copy size...
2044 head = portp->rx.head;
2045 tail = portp->rx.tail;
2050 len = STL_RXBUFSIZE - (tail - head);
2051 stlen = portp->rx.endbuf - tail;
2054 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
2056 if (((tp->t_rawq.c_cc + len) >= TTYHOG) &&
2057 ((portp->state & ASY_RTSFLOWMODE) ||
2058 (tp->t_iflag & IXOFF)) &&
2059 ((tp->t_state & TS_TBLOCK) == 0)) {
2060 ch = TTYHOG - tp->t_rawq.c_cc - 1;
2061 len = (ch > 0) ? ch : 0;
2062 stlen = MIN(stlen, len);
2065 lostlen = b_to_q(tail, stlen, &tp->t_rawq);
2068 if (tail >= portp->rx.endbuf) {
2069 tail = portp->rx.buf;
2070 lostlen += b_to_q(tail, len, &tp->t_rawq);
2073 portp->stats.rxlost += lostlen;
2075 portp->rx.tail = tail;
2078 while (portp->rx.tail != head) {
2079 ch = (unsigned char) *(portp->rx.tail);
2080 status = *(portp->rx.tail + STL_RXBUFSIZE);
2082 *(portp->rx.tail + STL_RXBUFSIZE) = 0;
2083 if (status & ST_BREAK)
2085 if (status & ST_FRAMING)
2087 if (status & ST_PARITY)
2089 if (status & ST_OVERRUN)
2092 (*linesw[tp->t_line].l_rint)(ch, tp);
2093 if (portp->rx.tail == head)
2096 if (++(portp->rx.tail) >= portp->rx.endbuf)
2097 portp->rx.tail = portp->rx.buf;
2101 if (head != portp->rx.tail)
2102 portp->state |= ASY_RXDATA;
2105 * If we were flow controled then maybe the buffer is low enough that
2106 * we can re-activate it.
2108 if ((portp->state & ASY_RTSFLOW) && ((tp->t_state & TS_TBLOCK) == 0))
2109 stl_flowcontrol(portp, 1, -1);
2112 /*****************************************************************************/
2114 static int stl_param(struct tty *tp, struct termios *tiosp)
2118 portp = (stlport_t *) tp;
2119 if (portp == (stlport_t *) NULL)
2122 return(stl_setport(portp, tiosp));
2125 /*****************************************************************************/
2128 * Action the flow control as required. The hw and sw args inform the
2129 * routine what flow control methods it should try.
2132 static void stl_flowcontrol(stlport_t *portp, int hw, int sw)
2134 unsigned char *head, *tail;
2138 printf("stl_flowcontrol(portp=%x,hw=%d,sw=%d)\n", (int) portp, hw, sw);
2143 if (portp->state & ASY_RTSFLOWMODE) {
2145 if ((portp->state & ASY_RTSFLOW) == 0)
2147 } else if (hw > 0) {
2148 if (portp->state & ASY_RTSFLOW) {
2149 head = portp->rx.head;
2150 tail = portp->rx.tail;
2151 len = (head >= tail) ? (head - tail) :
2152 (STL_RXBUFSIZE - (tail - head));
2153 if (len < STL_RXBUFHIGH)
2160 * We have worked out what to do, if anything. So now apply it to the
2163 stl_sendflow(portp, hwflow, sw);
2166 /*****************************************************************************/
2169 * Enable l_rint processing bypass mode if tty modes allow it.
2172 static void stl_ttyoptim(stlport_t *portp, struct termios *tiosp)
2177 if (((tiosp->c_iflag &
2178 (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP)) == 0) &&
2179 (((tiosp->c_iflag & BRKINT) == 0) || (tiosp->c_iflag & IGNBRK)) &&
2180 (((tiosp->c_iflag & PARMRK) == 0) ||
2181 ((tiosp->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))) &&
2182 ((tiosp->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN)) ==0) &&
2183 (linesw[tp->t_line].l_rint == ttyinput))
2184 tp->t_state |= TS_CAN_BYPASS_L_RINT;
2186 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
2187 portp->hotchar = linesw[tp->t_line].l_hotchar;
2190 /*****************************************************************************/
2193 * Try and find and initialize all the ports on a panel. We don't care
2194 * what sort of board these ports are on - since the port io registers
2195 * are almost identical when dealing with ports.
2198 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2201 unsigned int chipmask;
2205 printf("stl_initports(panelp=%x)\n", (int) panelp);
2208 chipmask = stl_panelinit(brdp, panelp);
2211 * All UART's are initialized if found. Now go through and setup
2212 * each ports data structures. Also initialize each individual
2215 for (i = 0; (i < panelp->nrports); i++) {
2216 portp = (stlport_t *) malloc(sizeof(stlport_t), M_TTYS,
2218 if (portp == (stlport_t *) NULL) {
2219 printf("STALLION: failed to allocate port memory "
2220 "(size=%d)\n", sizeof(stlport_t));
2223 bzero(portp, sizeof(stlport_t));
2226 portp->brdnr = panelp->brdnr;
2227 portp->panelnr = panelp->panelnr;
2228 portp->uartp = panelp->uartp;
2229 portp->clk = brdp->clk;
2230 panelp->ports[i] = portp;
2232 j = STL_TXBUFSIZE + (2 * STL_RXBUFSIZE);
2233 portp->tx.buf = (char *) malloc(j, M_TTYS, M_NOWAIT);
2234 if (portp->tx.buf == (char *) NULL) {
2235 printf("STALLION: failed to allocate buffer memory "
2239 portp->tx.endbuf = portp->tx.buf + STL_TXBUFSIZE;
2240 portp->tx.head = portp->tx.buf;
2241 portp->tx.tail = portp->tx.buf;
2242 portp->rx.buf = portp->tx.buf + STL_TXBUFSIZE;
2243 portp->rx.endbuf = portp->rx.buf + STL_RXBUFSIZE;
2244 portp->rx.head = portp->rx.buf;
2245 portp->rx.tail = portp->rx.buf;
2246 portp->rxstatus.buf = portp->rx.buf + STL_RXBUFSIZE;
2247 portp->rxstatus.endbuf = portp->rxstatus.buf + STL_RXBUFSIZE;
2248 portp->rxstatus.head = portp->rxstatus.buf;
2249 portp->rxstatus.tail = portp->rxstatus.buf;
2250 bzero(portp->rxstatus.head, STL_RXBUFSIZE);
2252 portp->initintios.c_ispeed = STL_DEFSPEED;
2253 portp->initintios.c_ospeed = STL_DEFSPEED;
2254 portp->initintios.c_cflag = STL_DEFCFLAG;
2255 portp->initintios.c_iflag = 0;
2256 portp->initintios.c_oflag = 0;
2257 portp->initintios.c_lflag = 0;
2258 bcopy(&ttydefchars[0], &portp->initintios.c_cc[0],
2259 sizeof(portp->initintios.c_cc));
2260 portp->initouttios = portp->initintios;
2261 portp->dtrwait = 3 * hz;
2263 stl_portinit(brdp, panelp, portp);
2269 /*****************************************************************************/
2272 * Try to find and initialize an EasyIO board.
2275 static int stl_initeio(stlbrd_t *brdp)
2278 unsigned int status;
2281 printf("stl_initeio(brdp=%x)\n", (int) brdp);
2284 brdp->ioctrl = brdp->ioaddr1 + 1;
2285 brdp->iostatus = brdp->ioaddr1 + 2;
2286 brdp->clk = EIO_CLK;
2287 brdp->isr = stl_eiointr;
2289 status = inb(brdp->iostatus);
2290 switch (status & EIO_IDBITMASK) {
2292 brdp->clk = EIO_CLK8M;
2302 switch (status & EIO_BRDMASK) {
2321 if (brdp->brdtype == BRD_EASYIOPCI) {
2322 outb((brdp->ioaddr2 + 0x4c), 0x41);
2325 * Check that the supplied IRQ is good and then use it to setup the
2326 * programmable interrupt bits on EIO board. Also set the edge/level
2327 * triggered interrupt bit.
2329 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2330 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2331 printf("STALLION: invalid irq=%d for brd=%d\n",
2332 brdp->irq, brdp->brdnr);
2335 outb(brdp->ioctrl, (stl_vecmap[brdp->irq] |
2336 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)));
2339 panelp = (stlpanel_t *) malloc(sizeof(stlpanel_t), M_TTYS, M_NOWAIT);
2340 if (panelp == (stlpanel_t *) NULL) {
2341 printf("STALLION: failed to allocate memory (size=%d)\n",
2342 sizeof(stlpanel_t));
2345 bzero(panelp, sizeof(stlpanel_t));
2347 panelp->brdnr = brdp->brdnr;
2348 panelp->panelnr = 0;
2349 panelp->nrports = brdp->nrports;
2350 panelp->iobase = brdp->ioaddr1;
2351 panelp->hwid = status;
2352 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2353 panelp->uartp = (void *) &stl_sc26198uart;
2354 panelp->isr = stl_sc26198intr;
2356 panelp->uartp = (void *) &stl_cd1400uart;
2357 panelp->isr = stl_cd1400eiointr;
2359 brdp->panels[0] = panelp;
2361 brdp->hwid = status;
2362 brdp->state |= BRD_FOUND;
2366 /*****************************************************************************/
2369 * Try to find an ECH board and initialize it. This code is capable of
2370 * dealing with all types of ECH board.
2373 static int stl_initech(stlbrd_t *brdp)
2376 unsigned int status, nxtid;
2377 int panelnr, ioaddr, banknr, i;
2380 printf("stl_initech(brdp=%x)\n", (int) brdp);
2384 * Set up the initial board register contents for boards. This varys a
2385 * bit between the different board types. So we need to handle each
2386 * separately. Also do a check that the supplied IRQ is good.
2388 switch (brdp->brdtype) {
2391 brdp->isr = stl_echatintr;
2392 brdp->ioctrl = brdp->ioaddr1 + 1;
2393 brdp->iostatus = brdp->ioaddr1 + 1;
2394 status = inb(brdp->iostatus);
2395 if ((status & ECH_IDBITMASK) != ECH_ID)
2397 brdp->hwid = status;
2399 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2400 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2401 printf("STALLION: invalid irq=%d for brd=%d\n",
2402 brdp->irq, brdp->brdnr);
2405 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2406 status |= (stl_vecmap[brdp->irq] << 1);
2407 outb(brdp->ioaddr1, (status | ECH_BRDRESET));
2408 brdp->ioctrlval = ECH_INTENABLE |
2409 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2410 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDENABLE));
2411 outb(brdp->ioaddr1, status);
2415 brdp->isr = stl_echmcaintr;
2416 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2417 brdp->iostatus = brdp->ioctrl;
2418 status = inb(brdp->iostatus);
2419 if ((status & ECH_IDBITMASK) != ECH_ID)
2421 brdp->hwid = status;
2423 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2424 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2425 printf("STALLION: invalid irq=%d for brd=%d\n",
2426 brdp->irq, brdp->brdnr);
2429 outb(brdp->ioctrl, ECHMC_BRDRESET);
2430 outb(brdp->ioctrl, ECHMC_INTENABLE);
2434 brdp->isr = stl_echpciintr;
2435 brdp->ioctrl = brdp->ioaddr1 + 2;
2439 brdp->isr = stl_echpci64intr;
2440 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2441 outb((brdp->ioaddr1 + 0x4c), 0x43);
2445 printf("STALLION: unknown board type=%d\n", brdp->brdtype);
2449 brdp->clk = ECH_CLK;
2452 * Scan through the secondary io address space looking for panels.
2453 * As we find'em allocate and initialize panel structures for each.
2455 ioaddr = brdp->ioaddr2;
2460 for (i = 0; (i < STL_MAXPANELS); i++) {
2461 if (brdp->brdtype == BRD_ECHPCI) {
2462 outb(brdp->ioctrl, nxtid);
2463 ioaddr = brdp->ioaddr2;
2465 status = inb(ioaddr + ECH_PNLSTATUS);
2466 if ((status & ECH_PNLIDMASK) != nxtid)
2468 panelp = (stlpanel_t *) malloc(sizeof(stlpanel_t), M_TTYS,
2470 if (panelp == (stlpanel_t *) NULL) {
2471 printf("STALLION: failed to allocate memory"
2472 "(size=%d)\n", sizeof(stlpanel_t));
2475 bzero(panelp, sizeof(stlpanel_t));
2476 panelp->brdnr = brdp->brdnr;
2477 panelp->panelnr = panelnr;
2478 panelp->iobase = ioaddr;
2479 panelp->pagenr = nxtid;
2480 panelp->hwid = status;
2481 brdp->bnk2panel[banknr] = panelp;
2482 brdp->bnkpageaddr[banknr] = nxtid;
2483 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2485 if (status & ECH_PNLXPID) {
2486 panelp->uartp = (void *) &stl_sc26198uart;
2487 panelp->isr = stl_sc26198intr;
2488 if (status & ECH_PNL16PORT) {
2489 panelp->nrports = 16;
2490 brdp->bnk2panel[banknr] = panelp;
2491 brdp->bnkpageaddr[banknr] = nxtid;
2492 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2495 panelp->nrports = 8;
2498 panelp->uartp = (void *) &stl_cd1400uart;
2499 panelp->isr = stl_cd1400echintr;
2500 if (status & ECH_PNL16PORT) {
2501 panelp->nrports = 16;
2502 panelp->ackmask = 0x80;
2503 if (brdp->brdtype != BRD_ECHPCI)
2504 ioaddr += EREG_BANKSIZE;
2505 brdp->bnk2panel[banknr] = panelp;
2506 brdp->bnkpageaddr[banknr] = ++nxtid;
2507 brdp->bnkstataddr[banknr++] = ioaddr +
2510 panelp->nrports = 8;
2511 panelp->ackmask = 0xc0;
2516 ioaddr += EREG_BANKSIZE;
2517 brdp->nrports += panelp->nrports;
2518 brdp->panels[panelnr++] = panelp;
2519 if ((brdp->brdtype == BRD_ECH) || (brdp->brdtype == BRD_ECHMC)){
2520 if (ioaddr >= (brdp->ioaddr2 + 0x20)) {
2521 printf("STALLION: too many ports attached "
2522 "to board %d, remove last module\n",
2529 brdp->nrpanels = panelnr;
2530 brdp->nrbnks = banknr;
2531 if (brdp->brdtype == BRD_ECH)
2532 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDDISABLE));
2534 brdp->state |= BRD_FOUND;
2538 /*****************************************************************************/
2541 * Initialize and configure the specified board. This firstly probes
2542 * for the board, if it is found then the board is initialized and
2543 * then all its ports are initialized as well.
2546 static int stl_brdinit(stlbrd_t *brdp)
2552 printf("stl_brdinit(brdp=%x): unit=%d type=%d io1=%x io2=%x irq=%d\n",
2553 (int) brdp, brdp->brdnr, brdp->brdtype, brdp->ioaddr1,
2554 brdp->ioaddr2, brdp->irq);
2557 switch (brdp->brdtype) {
2569 printf("STALLION: unit=%d is unknown board type=%d\n",
2570 brdp->brdnr, brdp->brdtype);
2574 stl_brds[brdp->brdnr] = brdp;
2575 if ((brdp->state & BRD_FOUND) == 0) {
2577 printf("STALLION: %s board not found, unit=%d io=%x irq=%d\n",
2578 stl_brdnames[brdp->brdtype], brdp->brdnr,
2579 brdp->ioaddr1, brdp->irq);
2584 for (i = 0, k = 0; (i < STL_MAXPANELS); i++) {
2585 panelp = brdp->panels[i];
2586 if (panelp != (stlpanel_t *) NULL) {
2587 stl_initports(brdp, panelp);
2588 for (j = 0; (j < panelp->nrports); j++)
2589 brdp->ports[k++] = panelp->ports[j];
2593 printf("stl%d: %s (driver version %s) unit=%d nrpanels=%d nrports=%d\n",
2594 brdp->unitid, stl_brdnames[brdp->brdtype], stl_drvversion,
2595 brdp->brdnr, brdp->nrpanels, brdp->nrports);
2599 /*****************************************************************************/
2602 * Return the board stats structure to user app.
2605 static int stl_getbrdstats(caddr_t data)
2611 stl_brdstats = *((combrd_t *) data);
2612 if (stl_brdstats.brd >= STL_MAXBRDS)
2614 brdp = stl_brds[stl_brdstats.brd];
2615 if (brdp == (stlbrd_t *) NULL)
2618 bzero(&stl_brdstats, sizeof(combrd_t));
2619 stl_brdstats.brd = brdp->brdnr;
2620 stl_brdstats.type = brdp->brdtype;
2621 stl_brdstats.hwid = brdp->hwid;
2622 stl_brdstats.state = brdp->state;
2623 stl_brdstats.ioaddr = brdp->ioaddr1;
2624 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2625 stl_brdstats.irq = brdp->irq;
2626 stl_brdstats.nrpanels = brdp->nrpanels;
2627 stl_brdstats.nrports = brdp->nrports;
2628 for (i = 0; (i < brdp->nrpanels); i++) {
2629 panelp = brdp->panels[i];
2630 stl_brdstats.panels[i].panel = i;
2631 stl_brdstats.panels[i].hwid = panelp->hwid;
2632 stl_brdstats.panels[i].nrports = panelp->nrports;
2635 *((combrd_t *) data) = stl_brdstats;;
2639 /*****************************************************************************/
2642 * Resolve the referenced port number into a port struct pointer.
2645 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2650 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2651 return((stlport_t *) NULL);
2652 brdp = stl_brds[brdnr];
2653 if (brdp == (stlbrd_t *) NULL)
2654 return((stlport_t *) NULL);
2655 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2656 return((stlport_t *) NULL);
2657 panelp = brdp->panels[panelnr];
2658 if (panelp == (stlpanel_t *) NULL)
2659 return((stlport_t *) NULL);
2660 if ((portnr < 0) || (portnr >= panelp->nrports))
2661 return((stlport_t *) NULL);
2662 return(panelp->ports[portnr]);
2665 /*****************************************************************************/
2668 * Return the port stats structure to user app. A NULL port struct
2669 * pointer passed in means that we need to find out from the app
2670 * what port to get stats for (used through board control device).
2673 static int stl_getportstats(stlport_t *portp, caddr_t data)
2675 unsigned char *head, *tail;
2677 if (portp == (stlport_t *) NULL) {
2678 stl_comstats = *((comstats_t *) data);
2679 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2681 if (portp == (stlport_t *) NULL)
2685 portp->stats.state = portp->state;
2686 /*portp->stats.flags = portp->flags;*/
2687 portp->stats.hwid = portp->hwid;
2688 portp->stats.ttystate = portp->tty.t_state;
2689 portp->stats.cflags = portp->tty.t_cflag;
2690 portp->stats.iflags = portp->tty.t_iflag;
2691 portp->stats.oflags = portp->tty.t_oflag;
2692 portp->stats.lflags = portp->tty.t_lflag;
2694 head = portp->tx.head;
2695 tail = portp->tx.tail;
2696 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2697 (STL_TXBUFSIZE - (tail - head)));
2699 head = portp->rx.head;
2700 tail = portp->rx.tail;
2701 portp->stats.rxbuffered = (head >= tail) ? (head - tail) :
2702 (STL_RXBUFSIZE - (tail - head));
2704 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2706 *((comstats_t *) data) = portp->stats;
2710 /*****************************************************************************/
2713 * Clear the port stats structure. We also return it zeroed out...
2716 static int stl_clrportstats(stlport_t *portp, caddr_t data)
2718 if (portp == (stlport_t *) NULL) {
2719 stl_comstats = *((comstats_t *) data);
2720 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2722 if (portp == (stlport_t *) NULL)
2726 bzero(&portp->stats, sizeof(comstats_t));
2727 portp->stats.brd = portp->brdnr;
2728 portp->stats.panel = portp->panelnr;
2729 portp->stats.port = portp->portnr;
2730 *((comstats_t *) data) = stl_comstats;
2734 /*****************************************************************************/
2737 * The "staliomem" device is used for stats collection in this driver.
2740 static int stl_memioctl(dev_t dev, unsigned long cmd, caddr_t data, int flag,
2746 printf("stl_memioctl(dev=%s,cmd=%lx,data=%p,flag=%x)\n",
2747 devtoname(dev), cmd, (void *) data, flag);
2753 case COM_GETPORTSTATS:
2754 rc = stl_getportstats((stlport_t *) NULL, data);
2756 case COM_CLRPORTSTATS:
2757 rc = stl_clrportstats((stlport_t *) NULL, data);
2759 case COM_GETBRDSTATS:
2760 rc = stl_getbrdstats(data);
2770 /*****************************************************************************/
2772 /*****************************************************************************/
2773 /* CD1400 UART CODE */
2774 /*****************************************************************************/
2777 * These functions get/set/update the registers of the cd1400 UARTs.
2778 * Access to the cd1400 registers is via an address/data io port pair.
2781 static int stl_cd1400getreg(stlport_t *portp, int regnr)
2783 outb(portp->ioaddr, (regnr + portp->uartaddr));
2784 return(inb(portp->ioaddr + EREG_DATA));
2787 /*****************************************************************************/
2789 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
2791 outb(portp->ioaddr, (regnr + portp->uartaddr));
2792 outb((portp->ioaddr + EREG_DATA), value);
2795 /*****************************************************************************/
2797 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
2799 outb(portp->ioaddr, (regnr + portp->uartaddr));
2800 if (inb(portp->ioaddr + EREG_DATA) != value) {
2801 outb((portp->ioaddr + EREG_DATA), value);
2807 /*****************************************************************************/
2809 static void stl_cd1400flush(stlport_t *portp, int flag)
2814 printf("stl_cd1400flush(portp=%x,flag=%x)\n", (int) portp, flag);
2817 if (portp == (stlport_t *) NULL)
2822 if (flag & FWRITE) {
2823 BRDENABLE(portp->brdnr, portp->pagenr);
2824 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2825 stl_cd1400ccrwait(portp);
2826 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
2827 stl_cd1400ccrwait(portp);
2828 BRDDISABLE(portp->brdnr);
2838 /*****************************************************************************/
2840 static void stl_cd1400ccrwait(stlport_t *portp)
2844 for (i = 0; (i < CCR_MAXWAIT); i++) {
2845 if (stl_cd1400getreg(portp, CCR) == 0)
2849 printf("stl%d: cd1400 device not responding, panel=%d port=%d\n",
2850 portp->brdnr, portp->panelnr, portp->portnr);
2853 /*****************************************************************************/
2856 * Transmit interrupt handler. This has gotta be fast! Handling TX
2857 * chars is pretty simple, stuff as many as possible from the TX buffer
2858 * into the cd1400 FIFO. Must also handle TX breaks here, since they
2859 * are embedded as commands in the data stream. Oh no, had to use a goto!
2862 static __inline void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
2866 unsigned char ioack, srer;
2871 printf("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
2874 ioack = inb(ioaddr + EREG_TXACK);
2875 if (((ioack & panelp->ackmask) != 0) ||
2876 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
2877 printf("STALLION: bad TX interrupt ack value=%x\n",
2881 portp = panelp->ports[(ioack >> 3)];
2885 * Unfortunately we need to handle breaks in the data stream, since
2886 * this is the only way to generate them on the cd1400. Do it now if
2887 * a break is to be sent. Some special cases here: brklen is -1 then
2888 * start sending an un-timed break, if brklen is -2 then stop sending
2889 * an un-timed break, if brklen is -3 then we have just sent an
2890 * un-timed break and do not want any data to go out, if brklen is -4
2891 * then a break has just completed so clean up the port settings.
2893 if (portp->brklen != 0) {
2894 if (portp->brklen >= -1) {
2895 outb(ioaddr, (TDR + portp->uartaddr));
2896 outb((ioaddr + EREG_DATA), ETC_CMD);
2897 outb((ioaddr + EREG_DATA), ETC_STARTBREAK);
2898 if (portp->brklen > 0) {
2899 outb((ioaddr + EREG_DATA), ETC_CMD);
2900 outb((ioaddr + EREG_DATA), ETC_DELAY);
2901 outb((ioaddr + EREG_DATA), portp->brklen);
2902 outb((ioaddr + EREG_DATA), ETC_CMD);
2903 outb((ioaddr + EREG_DATA), ETC_STOPBREAK);
2908 } else if (portp->brklen == -2) {
2909 outb(ioaddr, (TDR + portp->uartaddr));
2910 outb((ioaddr + EREG_DATA), ETC_CMD);
2911 outb((ioaddr + EREG_DATA), ETC_STOPBREAK);
2913 } else if (portp->brklen == -3) {
2914 outb(ioaddr, (SRER + portp->uartaddr));
2915 srer = inb(ioaddr + EREG_DATA);
2916 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
2917 outb((ioaddr + EREG_DATA), srer);
2919 outb(ioaddr, (COR2 + portp->uartaddr));
2920 outb((ioaddr + EREG_DATA),
2921 (inb(ioaddr + EREG_DATA) & ~COR2_ETC));
2927 head = portp->tx.head;
2928 tail = portp->tx.tail;
2929 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
2930 if ((len == 0) || ((len < STL_TXBUFLOW) &&
2931 ((portp->state & ASY_TXLOW) == 0))) {
2932 portp->state |= ASY_TXLOW;
2937 outb(ioaddr, (SRER + portp->uartaddr));
2938 srer = inb(ioaddr + EREG_DATA);
2939 if (srer & SRER_TXDATA) {
2940 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
2942 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
2943 portp->state |= ASY_TXEMPTY;
2944 portp->state &= ~ASY_TXBUSY;
2946 outb((ioaddr + EREG_DATA), srer);
2948 len = MIN(len, CD1400_TXFIFOSIZE);
2949 portp->stats.txtotal += len;
2950 stlen = MIN(len, (portp->tx.endbuf - tail));
2951 outb(ioaddr, (TDR + portp->uartaddr));
2952 outsb((ioaddr + EREG_DATA), tail, stlen);
2955 if (tail >= portp->tx.endbuf)
2956 tail = portp->tx.buf;
2958 outsb((ioaddr + EREG_DATA), tail, len);
2961 portp->tx.tail = tail;
2965 outb(ioaddr, (EOSRR + portp->uartaddr));
2966 outb((ioaddr + EREG_DATA), 0);
2969 /*****************************************************************************/
2972 * Receive character interrupt handler. Determine if we have good chars
2973 * or bad chars and then process appropriately.
2976 static __inline void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
2980 unsigned int ioack, len, buflen, stlen;
2981 unsigned char status;
2986 printf("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
2989 ioack = inb(ioaddr + EREG_RXACK);
2990 if ((ioack & panelp->ackmask) != 0) {
2991 printf("STALLION: bad RX interrupt ack value=%x\n", ioack);
2994 portp = panelp->ports[(ioack >> 3)];
2998 * First up, calculate how much room there is in the RX ring queue.
2999 * We also want to keep track of the longest possible copy length,
3000 * this has to allow for the wrapping of the ring queue.
3002 head = portp->rx.head;
3003 tail = portp->rx.tail;
3005 buflen = STL_RXBUFSIZE - (head - tail) - 1;
3006 stlen = portp->rx.endbuf - head;
3008 buflen = tail - head - 1;
3013 * Check if the input buffer is near full. If so then we should take
3014 * some flow control action... It is very easy to do hardware and
3015 * software flow control from here since we have the port selected on
3018 if (buflen <= (STL_RXBUFSIZE - STL_RXBUFHIGH)) {
3019 if (((portp->state & ASY_RTSFLOW) == 0) &&
3020 (portp->state & ASY_RTSFLOWMODE)) {
3021 portp->state |= ASY_RTSFLOW;
3022 stl_cd1400setreg(portp, MCOR1,
3023 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3024 stl_cd1400setreg(portp, MSVR2, 0);
3025 portp->stats.rxrtsoff++;
3030 * OK we are set, process good data... If the RX ring queue is full
3031 * just chuck the chars - don't leave them in the UART.
3033 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
3034 outb(ioaddr, (RDCR + portp->uartaddr));
3035 len = inb(ioaddr + EREG_DATA);
3037 outb(ioaddr, (RDSR + portp->uartaddr));
3038 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
3039 portp->stats.rxlost += len;
3040 portp->stats.rxtotal += len;
3042 len = MIN(len, buflen);
3043 portp->stats.rxtotal += len;
3044 stlen = MIN(len, stlen);
3046 outb(ioaddr, (RDSR + portp->uartaddr));
3047 insb((ioaddr + EREG_DATA), head, stlen);
3049 if (head >= portp->rx.endbuf) {
3050 head = portp->rx.buf;
3052 insb((ioaddr + EREG_DATA), head, len);
3057 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
3058 outb(ioaddr, (RDSR + portp->uartaddr));
3059 status = inb(ioaddr + EREG_DATA);
3060 ch = inb(ioaddr + EREG_DATA);
3061 if (status & ST_BREAK)
3062 portp->stats.rxbreaks++;
3063 if (status & ST_FRAMING)
3064 portp->stats.rxframing++;
3065 if (status & ST_PARITY)
3066 portp->stats.rxparity++;
3067 if (status & ST_OVERRUN)
3068 portp->stats.rxoverrun++;
3069 if (status & ST_SCHARMASK) {
3070 if ((status & ST_SCHARMASK) == ST_SCHAR1)
3071 portp->stats.txxon++;
3072 if ((status & ST_SCHARMASK) == ST_SCHAR2)
3073 portp->stats.txxoff++;
3076 if ((portp->rxignoremsk & status) == 0) {
3077 if ((tp->t_state & TS_CAN_BYPASS_L_RINT) &&
3078 ((status & ST_FRAMING) ||
3079 ((status & ST_PARITY) && (tp->t_iflag & INPCK))))
3081 if ((portp->rxmarkmsk & status) == 0)
3083 *(head + STL_RXBUFSIZE) = status;
3085 if (head >= portp->rx.endbuf)
3086 head = portp->rx.buf;
3089 printf("STALLION: bad RX interrupt ack value=%x\n", ioack);
3093 portp->rx.head = head;
3094 portp->state |= ASY_RXDATA;
3098 outb(ioaddr, (EOSRR + portp->uartaddr));
3099 outb((ioaddr + EREG_DATA), 0);
3102 /*****************************************************************************/
3105 * Modem interrupt handler. The is called when the modem signal line
3106 * (DCD) has changed state.
3109 static __inline void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
3116 printf("stl_cd1400mdmisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
3119 ioack = inb(ioaddr + EREG_MDACK);
3120 if (((ioack & panelp->ackmask) != 0) ||
3121 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
3122 printf("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
3125 portp = panelp->ports[(ioack >> 3)];
3127 outb(ioaddr, (MISR + portp->uartaddr));
3128 misr = inb(ioaddr + EREG_DATA);
3129 if (misr & MISR_DCD) {
3130 portp->state |= ASY_DCDCHANGE;
3131 portp->stats.modem++;
3135 outb(ioaddr, (EOSRR + portp->uartaddr));
3136 outb((ioaddr + EREG_DATA), 0);
3139 /*****************************************************************************/
3142 * Interrupt service routine for cd1400 EasyIO boards.
3145 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3147 unsigned char svrtype;
3150 printf("stl_cd1400eiointr(panelp=%x,iobase=%x)\n", (int) panelp,
3155 svrtype = inb(iobase + EREG_DATA);
3156 if (panelp->nrports > 4) {
3157 outb(iobase, (SVRR + 0x80));
3158 svrtype |= inb(iobase + EREG_DATA);
3161 printf("stl_cd1400eiointr(panelp=%x,iobase=%x): svrr=%x\n", (int) panelp, iobase, svrtype);
3164 if (svrtype & SVRR_RX)
3165 stl_cd1400rxisr(panelp, iobase);
3166 else if (svrtype & SVRR_TX)
3167 stl_cd1400txisr(panelp, iobase);
3168 else if (svrtype & SVRR_MDM)
3169 stl_cd1400mdmisr(panelp, iobase);
3172 /*****************************************************************************/
3175 * Interrupt service routine for cd1400 panels.
3178 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
3180 unsigned char svrtype;
3183 printf("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
3188 svrtype = inb(iobase + EREG_DATA);
3189 outb(iobase, (SVRR + 0x80));
3190 svrtype |= inb(iobase + EREG_DATA);
3191 if (svrtype & SVRR_RX)
3192 stl_cd1400rxisr(panelp, iobase);
3193 else if (svrtype & SVRR_TX)
3194 stl_cd1400txisr(panelp, iobase);
3195 else if (svrtype & SVRR_MDM)
3196 stl_cd1400mdmisr(panelp, iobase);
3199 /*****************************************************************************/
3202 * Set up the cd1400 registers for a port based on the termios port
3206 static int stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3208 unsigned int clkdiv;
3209 unsigned char cor1, cor2, cor3;
3210 unsigned char cor4, cor5, ccr;
3211 unsigned char srer, sreron, sreroff;
3212 unsigned char mcor1, mcor2, rtpr;
3213 unsigned char clk, div;
3217 printf("stl_cd1400setport(portp=%x,tiosp=%x): brdnr=%d portnr=%d\n",
3218 (int) portp, (int) tiosp, portp->brdnr, portp->portnr);
3236 * Set up the RX char ignore mask with those RX error types we
3237 * can ignore. We could have used some special modes of the cd1400
3238 * UART to help, but it is better this way because we can keep stats
3239 * on the number of each type of RX exception event.
3241 portp->rxignoremsk = 0;
3242 if (tiosp->c_iflag & IGNPAR)
3243 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
3244 if (tiosp->c_iflag & IGNBRK)
3245 portp->rxignoremsk |= ST_BREAK;
3247 portp->rxmarkmsk = ST_OVERRUN;
3248 if (tiosp->c_iflag & (INPCK | PARMRK))
3249 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3250 if (tiosp->c_iflag & BRKINT)
3251 portp->rxmarkmsk |= ST_BREAK;
3254 * Go through the char size, parity and stop bits and set all the
3255 * option registers appropriately.
3257 switch (tiosp->c_cflag & CSIZE) {
3272 if (tiosp->c_cflag & CSTOPB)
3277 if (tiosp->c_cflag & PARENB) {
3278 if (tiosp->c_cflag & PARODD)
3279 cor1 |= (COR1_PARENB | COR1_PARODD);
3281 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3283 cor1 |= COR1_PARNONE;
3287 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3288 * space for hardware flow control and the like. This should be set to
3289 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3290 * really be based on VTIME...
3292 cor3 |= FIFO_RXTHRESHOLD;
3296 * Calculate the baud rate timers. For now we will just assume that
3297 * the input and output baud are the same. Could have used a baud
3298 * table here, but this way we can generate virtually any baud rate
3301 if (tiosp->c_ispeed == 0)
3302 tiosp->c_ispeed = tiosp->c_ospeed;
3303 if ((tiosp->c_ospeed < 0) || (tiosp->c_ospeed > CD1400_MAXBAUD))
3306 if (tiosp->c_ospeed > 0) {
3307 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3308 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) /
3313 div = (unsigned char) clkdiv;
3317 * Check what form of modem signaling is required and set it up.
3319 if ((tiosp->c_cflag & CLOCAL) == 0) {
3322 sreron |= SRER_MODEM;
3326 * Setup cd1400 enhanced modes if we can. In particular we want to
3327 * handle as much of the flow control as possbile automatically. As
3328 * well as saving a few CPU cycles it will also greatly improve flow
3329 * control reliablilty.
3331 if (tiosp->c_iflag & IXON) {
3334 if (tiosp->c_iflag & IXANY)
3338 if (tiosp->c_cflag & CCTS_OFLOW)
3340 if (tiosp->c_cflag & CRTS_IFLOW)
3341 mcor1 |= FIFO_RTSTHRESHOLD;
3344 * All cd1400 register values calculated so go through and set them
3348 printf("SETPORT: portnr=%d panelnr=%d brdnr=%d\n", portp->portnr,
3349 portp->panelnr, portp->brdnr);
3350 printf(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n", cor1, cor2,
3352 printf(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3353 mcor1, mcor2, rtpr, sreron, sreroff);
3354 printf(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3355 printf(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3356 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP], tiosp->c_cc[VSTART],
3357 tiosp->c_cc[VSTOP]);
3361 BRDENABLE(portp->brdnr, portp->pagenr);
3362 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3363 srer = stl_cd1400getreg(portp, SRER);
3364 stl_cd1400setreg(portp, SRER, 0);
3365 ccr += stl_cd1400updatereg(portp, COR1, cor1);
3366 ccr += stl_cd1400updatereg(portp, COR2, cor2);
3367 ccr += stl_cd1400updatereg(portp, COR3, cor3);
3369 stl_cd1400ccrwait(portp);
3370 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3372 stl_cd1400setreg(portp, COR4, cor4);
3373 stl_cd1400setreg(portp, COR5, cor5);
3374 stl_cd1400setreg(portp, MCOR1, mcor1);
3375 stl_cd1400setreg(portp, MCOR2, mcor2);
3376 if (tiosp->c_ospeed == 0) {
3377 stl_cd1400setreg(portp, MSVR1, 0);
3379 stl_cd1400setreg(portp, MSVR1, MSVR1_DTR);
3380 stl_cd1400setreg(portp, TCOR, clk);
3381 stl_cd1400setreg(portp, TBPR, div);
3382 stl_cd1400setreg(portp, RCOR, clk);
3383 stl_cd1400setreg(portp, RBPR, div);
3385 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3386 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3387 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3388 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3389 stl_cd1400setreg(portp, RTPR, rtpr);
3390 mcor1 = stl_cd1400getreg(portp, MSVR1);
3391 if (mcor1 & MSVR1_DCD)
3392 portp->sigs |= TIOCM_CD;
3394 portp->sigs &= ~TIOCM_CD;
3395 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3396 BRDDISABLE(portp->brdnr);
3397 portp->state &= ~(ASY_RTSFLOWMODE | ASY_CTSFLOWMODE);
3398 portp->state |= ((tiosp->c_cflag & CRTS_IFLOW) ? ASY_RTSFLOWMODE : 0);
3399 portp->state |= ((tiosp->c_cflag & CCTS_OFLOW) ? ASY_CTSFLOWMODE : 0);
3400 stl_ttyoptim(portp, tiosp);
3406 /*****************************************************************************/
3409 * Action the flow control as required. The hw and sw args inform the
3410 * routine what flow control methods it should try.
3413 static void stl_cd1400sendflow(stlport_t *portp, int hw, int sw)
3418 printf("stl_cd1400sendflow(portp=%x,hw=%d,sw=%d)\n",
3419 (int) portp, hw, sw);
3423 BRDENABLE(portp->brdnr, portp->pagenr);
3424 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3427 stl_cd1400ccrwait(portp);
3429 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3430 portp->stats.rxxoff++;
3432 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3433 portp->stats.rxxon++;
3435 stl_cd1400ccrwait(portp);
3439 portp->state |= ASY_RTSFLOW;
3440 stl_cd1400setreg(portp, MCOR1,
3441 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3442 stl_cd1400setreg(portp, MSVR2, 0);
3443 portp->stats.rxrtsoff++;
3444 } else if (hw > 0) {
3445 portp->state &= ~ASY_RTSFLOW;
3446 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3447 stl_cd1400setreg(portp, MCOR1,
3448 (stl_cd1400getreg(portp, MCOR1) | FIFO_RTSTHRESHOLD));
3449 portp->stats.rxrtson++;
3452 BRDDISABLE(portp->brdnr);
3456 /*****************************************************************************/
3459 * Return the current state of data flow on this port. This is only
3460 * really interresting when determining if data has fully completed
3461 * transmission or not... This is easy for the cd1400, it accurately
3462 * maintains the busy port flag.
3465 static int stl_cd1400datastate(stlport_t *portp)
3468 printf("stl_cd1400datastate(portp=%x)\n", (int) portp);
3471 if (portp == (stlport_t *) NULL)
3474 return((portp->state & ASY_TXBUSY) ? 1 : 0);
3477 /*****************************************************************************/
3480 * Set the state of the DTR and RTS signals. Got to do some extra
3481 * work here to deal hardware flow control.
3484 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3486 unsigned char msvr1, msvr2;
3490 printf("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n", (int) portp,
3502 BRDENABLE(portp->brdnr, portp->pagenr);
3503 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3505 if (portp->tty.t_cflag & CRTS_IFLOW) {
3507 stl_cd1400setreg(portp, MCOR1,
3508 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3509 portp->stats.rxrtsoff++;
3511 stl_cd1400setreg(portp, MCOR1,
3512 (stl_cd1400getreg(portp, MCOR1) |
3513 FIFO_RTSTHRESHOLD));
3514 portp->stats.rxrtson++;
3517 stl_cd1400setreg(portp, MSVR2, msvr2);
3520 stl_cd1400setreg(portp, MSVR1, msvr1);
3521 BRDDISABLE(portp->brdnr);
3525 /*****************************************************************************/
3528 * Get the state of the signals.
3531 static int stl_cd1400getsignals(stlport_t *portp)
3533 unsigned char msvr1, msvr2;
3537 printf("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3541 BRDENABLE(portp->brdnr, portp->pagenr);
3542 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3543 msvr1 = stl_cd1400getreg(portp, MSVR1);
3544 msvr2 = stl_cd1400getreg(portp, MSVR2);
3545 BRDDISABLE(portp->brdnr);
3549 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3550 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3551 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3552 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3554 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3555 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3562 /*****************************************************************************/
3565 * Enable or disable the Transmitter and/or Receiver.
3568 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3574 printf("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3575 (int) portp, rx, tx);
3580 ccr |= CCR_TXDISABLE;
3582 ccr |= CCR_TXENABLE;
3584 ccr |= CCR_RXDISABLE;
3586 ccr |= CCR_RXENABLE;
3589 BRDENABLE(portp->brdnr, portp->pagenr);
3590 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3591 stl_cd1400ccrwait(portp);
3592 stl_cd1400setreg(portp, CCR, ccr);
3593 stl_cd1400ccrwait(portp);
3594 BRDDISABLE(portp->brdnr);
3598 /*****************************************************************************/
3601 * Start or stop the Transmitter and/or Receiver.
3604 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3606 unsigned char sreron, sreroff;
3610 printf("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3611 (int) portp, rx, tx);
3617 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3619 sreron |= SRER_TXDATA;
3621 sreron |= SRER_TXEMPTY;
3623 sreroff |= SRER_RXDATA;
3625 sreron |= SRER_RXDATA;
3628 BRDENABLE(portp->brdnr, portp->pagenr);
3629 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3630 stl_cd1400setreg(portp, SRER,
3631 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3632 BRDDISABLE(portp->brdnr);
3634 portp->state |= ASY_TXBUSY;
3635 portp->tty.t_state |= TS_BUSY;
3640 /*****************************************************************************/
3643 * Disable all interrupts from this port.
3646 static void stl_cd1400disableintrs(stlport_t *portp)
3651 printf("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3655 BRDENABLE(portp->brdnr, portp->pagenr);
3656 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3657 stl_cd1400setreg(portp, SRER, 0);
3658 BRDDISABLE(portp->brdnr);
3662 /*****************************************************************************/
3664 static void stl_cd1400sendbreak(stlport_t *portp, long len)
3669 printf("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp,
3674 BRDENABLE(portp->brdnr, portp->pagenr);
3675 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3676 stl_cd1400setreg(portp, COR2,
3677 (stl_cd1400getreg(portp, COR2) | COR2_ETC));
3678 stl_cd1400setreg(portp, SRER,
3679 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3681 BRDDISABLE(portp->brdnr);
3684 portp->brklen = (len > 255) ? 255 : len;
3686 portp->brklen = len;
3689 portp->stats.txbreaks++;
3692 /*****************************************************************************/
3695 * Try and find and initialize all the ports on a panel. We don't care
3696 * what sort of board these ports are on - since the port io registers
3697 * are almost identical when dealing with ports.
3700 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3703 printf("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3704 (int) brdp, (int) panelp, (int) portp);
3707 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
3708 (portp == (stlport_t *) NULL))
3711 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3712 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3713 portp->uartaddr = (portp->portnr & 0x04) << 5;
3714 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3716 BRDENABLE(portp->brdnr, portp->pagenr);
3717 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3718 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3719 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3720 BRDDISABLE(portp->brdnr);
3723 /*****************************************************************************/
3726 * Inbitialize the UARTs in a panel. We don't care what sort of board
3727 * these ports are on - since the port io registers are almost
3728 * identical when dealing with ports.
3731 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3735 int nrchips, uartaddr, ioaddr;
3738 printf("stl_cd1400panelinit(brdp=%x,panelp=%x)\n", (int) brdp,
3742 BRDENABLE(panelp->brdnr, panelp->pagenr);
3745 * Check that each chip is present and started up OK.
3748 nrchips = panelp->nrports / CD1400_PORTS;
3749 for (i = 0; (i < nrchips); i++) {
3750 if (brdp->brdtype == BRD_ECHPCI) {
3751 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3752 ioaddr = panelp->iobase;
3754 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3756 uartaddr = (i & 0x01) ? 0x080 : 0;
3757 outb(ioaddr, (GFRCR + uartaddr));
3758 outb((ioaddr + EREG_DATA), 0);
3759 outb(ioaddr, (CCR + uartaddr));
3760 outb((ioaddr + EREG_DATA), CCR_RESETFULL);
3761 outb((ioaddr + EREG_DATA), CCR_RESETFULL);
3762 outb(ioaddr, (GFRCR + uartaddr));
3763 for (j = 0; (j < CCR_MAXWAIT); j++) {
3764 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3767 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3768 printf("STALLION: cd1400 not responding, "
3769 "board=%d panel=%d chip=%d\n", panelp->brdnr,
3770 panelp->panelnr, i);
3773 chipmask |= (0x1 << i);
3774 outb(ioaddr, (PPR + uartaddr));
3775 outb((ioaddr + EREG_DATA), PPR_SCALAR);
3779 BRDDISABLE(panelp->brdnr);
3783 /*****************************************************************************/
3784 /* SC26198 HARDWARE FUNCTIONS */
3785 /*****************************************************************************/
3788 * These functions get/set/update the registers of the sc26198 UARTs.
3789 * Access to the sc26198 registers is via an address/data io port pair.
3790 * (Maybe should make this inline...)
3793 static int stl_sc26198getreg(stlport_t *portp, int regnr)
3795 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3796 return(inb(portp->ioaddr + XP_DATA));
3799 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
3801 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3802 outb((portp->ioaddr + XP_DATA), value);
3805 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
3807 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3808 if (inb(portp->ioaddr + XP_DATA) != value) {
3809 outb((portp->ioaddr + XP_DATA), value);
3815 /*****************************************************************************/
3818 * Functions to get and set the sc26198 global registers.
3821 static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
3823 outb((portp->ioaddr + XP_ADDR), regnr);
3824 return(inb(portp->ioaddr + XP_DATA));
3828 static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
3830 outb((portp->ioaddr + XP_ADDR), regnr);
3831 outb((portp->ioaddr + XP_DATA), value);
3835 /*****************************************************************************/
3838 * Inbitialize the UARTs in a panel. We don't care what sort of board
3839 * these ports are on - since the port io registers are almost
3840 * identical when dealing with ports.
3843 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3846 int nrchips, ioaddr;
3849 printf("stl_sc26198panelinit(brdp=%x,panelp=%x)\n", (int) brdp,
3853 BRDENABLE(panelp->brdnr, panelp->pagenr);
3856 * Check that each chip is present and started up OK.
3859 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
3860 if (brdp->brdtype == BRD_ECHPCI)
3861 outb(brdp->ioctrl, panelp->pagenr);
3863 for (i = 0; (i < nrchips); i++) {
3864 ioaddr = panelp->iobase + (i * 4);
3865 outb((ioaddr + XP_ADDR), SCCR);
3866 outb((ioaddr + XP_DATA), CR_RESETALL);
3867 outb((ioaddr + XP_ADDR), TSTR);
3868 if (inb(ioaddr + XP_DATA) != 0) {
3869 printf("STALLION: sc26198 not responding, "
3870 "board=%d panel=%d chip=%d\n", panelp->brdnr,
3871 panelp->panelnr, i);
3874 chipmask |= (0x1 << i);
3875 outb((ioaddr + XP_ADDR), GCCR);
3876 outb((ioaddr + XP_DATA), GCCR_IVRTYPCHANACK);
3877 outb((ioaddr + XP_ADDR), WDTRCR);
3878 outb((ioaddr + XP_DATA), 0xff);
3881 BRDDISABLE(panelp->brdnr);
3885 /*****************************************************************************/
3888 * Initialize hardware specific port registers.
3891 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3894 printf("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
3895 (int) brdp, (int) panelp, (int) portp);
3898 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
3899 (portp == (stlport_t *) NULL))
3902 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
3903 portp->uartaddr = (portp->portnr & 0x07) << 4;
3904 portp->pagenr = panelp->pagenr;
3907 BRDENABLE(portp->brdnr, portp->pagenr);
3908 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
3909 BRDDISABLE(portp->brdnr);
3912 /*****************************************************************************/
3915 * Set up the sc26198 registers for a port based on the termios port
3919 static int stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
3921 unsigned char mr0, mr1, mr2, clk;
3922 unsigned char imron, imroff, iopr, ipr;
3926 printf("stl_sc26198setport(portp=%x,tiosp=%x): brdnr=%d portnr=%d\n",
3927 (int) portp, (int) tiosp, portp->brdnr, portp->portnr);
3939 * Set up the RX char ignore mask with those RX error types we
3942 portp->rxignoremsk = 0;
3943 if (tiosp->c_iflag & IGNPAR)
3944 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
3946 if (tiosp->c_iflag & IGNBRK)
3947 portp->rxignoremsk |= SR_RXBREAK;
3949 portp->rxmarkmsk = SR_RXOVERRUN;
3950 if (tiosp->c_iflag & (INPCK | PARMRK))
3951 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
3952 if (tiosp->c_iflag & BRKINT)
3953 portp->rxmarkmsk |= SR_RXBREAK;
3956 * Go through the char size, parity and stop bits and set all the
3957 * option registers appropriately.
3959 switch (tiosp->c_cflag & CSIZE) {
3974 if (tiosp->c_cflag & CSTOPB)
3979 if (tiosp->c_cflag & PARENB) {
3980 if (tiosp->c_cflag & PARODD)
3981 mr1 |= (MR1_PARENB | MR1_PARODD);
3983 mr1 |= (MR1_PARENB | MR1_PAREVEN);
3988 mr1 |= MR1_ERRBLOCK;
3991 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
3992 * space for hardware flow control and the like. This should be set to
3995 mr2 |= MR2_RXFIFOHALF;
3998 * Calculate the baud rate timers. For now we will just assume that
3999 * the input and output baud are the same. The sc26198 has a fixed
4000 * baud rate table, so only discrete baud rates possible.
4002 if (tiosp->c_ispeed == 0)
4003 tiosp->c_ispeed = tiosp->c_ospeed;
4004 if ((tiosp->c_ospeed < 0) || (tiosp->c_ospeed > SC26198_MAXBAUD))
4007 if (tiosp->c_ospeed > 0) {
4008 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
4009 if (tiosp->c_ospeed <= sc26198_baudtable[clk])
4015 * Check what form of modem signaling is required and set it up.
4017 if ((tiosp->c_cflag & CLOCAL) == 0) {
4018 iopr |= IOPR_DCDCOS;
4023 * Setup sc26198 enhanced modes if we can. In particular we want to
4024 * handle as much of the flow control as possible automatically. As
4025 * well as saving a few CPU cycles it will also greatly improve flow
4026 * control reliability.
4028 if (tiosp->c_iflag & IXON) {
4029 mr0 |= MR0_SWFTX | MR0_SWFT;
4030 imron |= IR_XONXOFF;
4032 imroff |= IR_XONXOFF;
4035 if (tiosp->c_iflag & IXOFF)
4039 if (tiosp->c_cflag & CCTS_OFLOW)
4041 if (tiosp->c_cflag & CRTS_IFLOW)
4045 * All sc26198 register values calculated so go through and set
4050 printf("SETPORT: portnr=%d panelnr=%d brdnr=%d\n", portp->portnr,
4051 portp->panelnr, portp->brdnr);
4052 printf(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4053 printf(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4054 printf(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4055 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4056 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4060 BRDENABLE(portp->brdnr, portp->pagenr);
4061 stl_sc26198setreg(portp, IMR, 0);
4062 stl_sc26198updatereg(portp, MR0, mr0);
4063 stl_sc26198updatereg(portp, MR1, mr1);
4064 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4065 stl_sc26198updatereg(portp, MR2, mr2);
4066 iopr = (stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr;
4067 if (tiosp->c_ospeed == 0) {
4071 stl_sc26198setreg(portp, TXCSR, clk);
4072 stl_sc26198setreg(portp, RXCSR, clk);
4074 stl_sc26198updatereg(portp, IOPIOR, iopr);
4075 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4076 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4077 ipr = stl_sc26198getreg(portp, IPR);
4079 portp->sigs &= ~TIOCM_CD;
4081 portp->sigs |= TIOCM_CD;
4082 portp->imr = (portp->imr & ~imroff) | imron;
4083 stl_sc26198setreg(portp, IMR, portp->imr);
4084 BRDDISABLE(portp->brdnr);
4085 portp->state &= ~(ASY_RTSFLOWMODE | ASY_CTSFLOWMODE);
4086 portp->state |= ((tiosp->c_cflag & CRTS_IFLOW) ? ASY_RTSFLOWMODE : 0);
4087 portp->state |= ((tiosp->c_cflag & CCTS_OFLOW) ? ASY_CTSFLOWMODE : 0);
4088 stl_ttyoptim(portp, tiosp);
4094 /*****************************************************************************/
4097 * Set the state of the DTR and RTS signals.
4100 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
4102 unsigned char iopioron, iopioroff;
4106 printf("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4107 (int) portp, dtr, rts);
4113 iopioroff |= IPR_DTR;
4115 iopioron |= IPR_DTR;
4117 iopioroff |= IPR_RTS;
4119 iopioron |= IPR_RTS;
4122 BRDENABLE(portp->brdnr, portp->pagenr);
4123 if ((rts >= 0) && (portp->tty.t_cflag & CRTS_IFLOW)) {
4125 stl_sc26198setreg(portp, MR1,
4126 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4127 portp->stats.rxrtsoff++;
4129 stl_sc26198setreg(portp, MR1,
4130 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4131 portp->stats.rxrtson++;
4134 stl_sc26198setreg(portp, IOPIOR,
4135 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4136 BRDDISABLE(portp->brdnr);
4140 /*****************************************************************************/
4143 * Return the state of the signals.
4146 static int stl_sc26198getsignals(stlport_t *portp)
4152 printf("stl_sc26198getsignals(portp=%x)\n", (int) portp);
4156 BRDENABLE(portp->brdnr, portp->pagenr);
4157 ipr = stl_sc26198getreg(portp, IPR);
4158 BRDDISABLE(portp->brdnr);
4162 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4163 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4164 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4165 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4169 /*****************************************************************************/
4172 * Enable/Disable the Transmitter and/or Receiver.
4175 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
4181 printf("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4182 (int) portp, rx, tx);
4185 ccr = portp->crenable;
4187 ccr &= ~CR_TXENABLE;
4191 ccr &= ~CR_RXENABLE;
4196 BRDENABLE(portp->brdnr, portp->pagenr);
4197 stl_sc26198setreg(portp, SCCR, ccr);
4198 BRDDISABLE(portp->brdnr);
4199 portp->crenable = ccr;
4203 /*****************************************************************************/
4206 * Start/stop the Transmitter and/or Receiver.
4209 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
4215 printf("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4216 (int) portp, rx, tx);
4225 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4227 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4230 BRDENABLE(portp->brdnr, portp->pagenr);
4231 stl_sc26198setreg(portp, IMR, imr);
4232 BRDDISABLE(portp->brdnr);
4235 portp->state |= ASY_TXBUSY;
4236 portp->tty.t_state |= TS_BUSY;
4241 /*****************************************************************************/
4244 * Disable all interrupts from this port.
4247 static void stl_sc26198disableintrs(stlport_t *portp)
4252 printf("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
4256 BRDENABLE(portp->brdnr, portp->pagenr);
4258 stl_sc26198setreg(portp, IMR, 0);
4259 BRDDISABLE(portp->brdnr);
4263 /*****************************************************************************/
4265 static void stl_sc26198sendbreak(stlport_t *portp, long len)
4270 printf("stl_sc26198sendbreak(portp=%x,len=%d)\n",
4271 (int) portp, (int) len);
4275 BRDENABLE(portp->brdnr, portp->pagenr);
4277 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4278 portp->stats.txbreaks++;
4280 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4282 BRDDISABLE(portp->brdnr);
4286 /*****************************************************************************/
4289 * Take flow control actions...
4292 static void stl_sc26198sendflow(stlport_t *portp, int hw, int sw)
4298 printf("stl_sc26198sendflow(portp=%x,hw=%d,sw=%d)\n",
4299 (int) portp, hw, sw);
4302 if (portp == (stlport_t *) NULL)
4306 BRDENABLE(portp->brdnr, portp->pagenr);
4309 mr0 = stl_sc26198getreg(portp, MR0);
4310 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4312 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4314 portp->stats.rxxoff++;
4316 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4318 portp->stats.rxxon++;
4320 stl_sc26198wait(portp);
4321 stl_sc26198setreg(portp, MR0, mr0);
4325 portp->state |= ASY_RTSFLOW;
4326 stl_sc26198setreg(portp, MR1,
4327 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4328 stl_sc26198setreg(portp, IOPIOR,
4329 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4330 portp->stats.rxrtsoff++;
4331 } else if (hw > 0) {
4332 portp->state &= ~ASY_RTSFLOW;
4333 stl_sc26198setreg(portp, MR1,
4334 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4335 stl_sc26198setreg(portp, IOPIOR,
4336 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4337 portp->stats.rxrtson++;
4340 BRDDISABLE(portp->brdnr);
4344 /*****************************************************************************/
4347 * Return the current state of data flow on this port. This is only
4348 * really interresting when determining if data has fully completed
4349 * transmission or not... The sc26198 interrupt scheme cannot
4350 * determine when all data has actually drained, so we need to
4351 * check the port statusy register to be sure.
4354 static int stl_sc26198datastate(stlport_t *portp)
4360 printf("stl_sc26198datastate(portp=%x)\n", (int) portp);
4363 if (portp == (stlport_t *) NULL)
4365 if (portp->state & ASY_TXBUSY)
4369 BRDENABLE(portp->brdnr, portp->pagenr);
4370 sr = stl_sc26198getreg(portp, SR);
4371 BRDDISABLE(portp->brdnr);
4374 return((sr & SR_TXEMPTY) ? 0 : 1);
4377 /*****************************************************************************/
4379 static void stl_sc26198flush(stlport_t *portp, int flag)
4384 printf("stl_sc26198flush(portp=%x,flag=%x)\n", (int) portp, flag);
4387 if (portp == (stlport_t *) NULL)
4391 BRDENABLE(portp->brdnr, portp->pagenr);
4392 if (flag & FWRITE) {
4393 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4394 stl_sc26198setreg(portp, SCCR, portp->crenable);
4397 while (stl_sc26198getreg(portp, SR) & SR_RXRDY)
4398 stl_sc26198getreg(portp, RXFIFO);
4400 BRDDISABLE(portp->brdnr);
4404 /*****************************************************************************/
4407 * If we are TX flow controlled and in IXANY mode then we may
4408 * need to unflow control here. We gotta do this because of the
4409 * automatic flow control modes of the sc26198 - which downs't
4410 * support any concept of an IXANY mode.
4413 static void stl_sc26198txunflow(stlport_t *portp)
4417 mr0 = stl_sc26198getreg(portp, MR0);
4418 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4419 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4420 stl_sc26198setreg(portp, MR0, mr0);
4421 portp->state &= ~ASY_TXFLOWED;
4424 /*****************************************************************************/
4427 * Delay for a small amount of time, to give the sc26198 a chance
4428 * to process a command...
4431 static void stl_sc26198wait(stlport_t *portp)
4436 printf("stl_sc26198wait(portp=%x)\n", (int) portp);
4439 if (portp == (stlport_t *) NULL)
4442 for (i = 0; (i < 20); i++)
4443 stl_sc26198getglobreg(portp, TSTR);
4446 /*****************************************************************************/
4449 * Transmit interrupt handler. This has gotta be fast! Handling TX
4450 * chars is pretty simple, stuff as many as possible from the TX buffer
4451 * into the sc26198 FIFO.
4454 static __inline void stl_sc26198txisr(stlport_t *portp)
4456 unsigned int ioaddr;
4462 printf("stl_sc26198txisr(portp=%x)\n", (int) portp);
4465 ioaddr = portp->ioaddr;
4467 head = portp->tx.head;
4468 tail = portp->tx.tail;
4469 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4470 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4471 ((portp->state & ASY_TXLOW) == 0))) {
4472 portp->state |= ASY_TXLOW;
4477 outb((ioaddr + XP_ADDR), (MR0 | portp->uartaddr));
4478 mr0 = inb(ioaddr + XP_DATA);
4479 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4480 portp->imr &= ~IR_TXRDY;
4481 outb((ioaddr + XP_ADDR), (IMR | portp->uartaddr));
4482 outb((ioaddr + XP_DATA), portp->imr);
4483 portp->state |= ASY_TXEMPTY;
4484 portp->state &= ~ASY_TXBUSY;
4486 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4487 outb((ioaddr + XP_DATA), mr0);
4490 len = MIN(len, SC26198_TXFIFOSIZE);
4491 portp->stats.txtotal += len;
4492 stlen = MIN(len, (portp->tx.endbuf - tail));
4493 outb((ioaddr + XP_ADDR), GTXFIFO);
4494 outsb((ioaddr + XP_DATA), tail, stlen);
4497 if (tail >= portp->tx.endbuf)
4498 tail = portp->tx.buf;
4500 outsb((ioaddr + XP_DATA), tail, len);
4503 portp->tx.tail = tail;
4507 /*****************************************************************************/
4510 * Receive character interrupt handler. Determine if we have good chars
4511 * or bad chars and then process appropriately. Good chars are easy
4512 * just shove the lot into the RX buffer and set all status byte to 0.
4513 * If a bad RX char then process as required. This routine needs to be
4517 static __inline void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
4520 printf("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
4523 if ((iack & IVR_TYPEMASK) == IVR_RXDATA)
4524 stl_sc26198rxgoodchars(portp);
4526 stl_sc26198rxbadchars(portp);
4529 * If we are TX flow controlled and in IXANY mode then we may need
4530 * to unflow control here. We gotta do this because of the automatic
4531 * flow control modes of the sc26198.
4533 if ((portp->state & ASY_TXFLOWED) && (portp->tty.t_iflag & IXANY))
4534 stl_sc26198txunflow(portp);
4537 /*****************************************************************************/
4540 * Process the good received characters from RX FIFO.
4543 static void stl_sc26198rxgoodchars(stlport_t *portp)
4545 unsigned int ioaddr, len, buflen, stlen;
4549 printf("stl_sc26198rxgoodchars(port=%x)\n", (int) portp);
4552 ioaddr = portp->ioaddr;
4555 * First up, calculate how much room there is in the RX ring queue.
4556 * We also want to keep track of the longest possible copy length,
4557 * this has to allow for the wrapping of the ring queue.
4559 head = portp->rx.head;
4560 tail = portp->rx.tail;
4562 buflen = STL_RXBUFSIZE - (head - tail) - 1;
4563 stlen = portp->rx.endbuf - head;
4565 buflen = tail - head - 1;
4570 * Check if the input buffer is near full. If so then we should take
4571 * some flow control action... It is very easy to do hardware and
4572 * software flow control from here since we have the port selected on
4575 if (buflen <= (STL_RXBUFSIZE - STL_RXBUFHIGH)) {
4576 if (((portp->state & ASY_RTSFLOW) == 0) &&
4577 (portp->state & ASY_RTSFLOWMODE)) {
4578 portp->state |= ASY_RTSFLOW;
4579 stl_sc26198setreg(portp, MR1,
4580 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4581 stl_sc26198setreg(portp, IOPIOR,
4582 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4583 portp->stats.rxrtsoff++;
4588 * OK we are set, process good data... If the RX ring queue is full
4589 * just chuck the chars - don't leave them in the UART.
4591 outb((ioaddr + XP_ADDR), GIBCR);
4592 len = inb(ioaddr + XP_DATA) + 1;
4594 outb((ioaddr + XP_ADDR), GRXFIFO);
4595 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4596 portp->stats.rxlost += len;
4597 portp->stats.rxtotal += len;
4599 len = MIN(len, buflen);
4600 portp->stats.rxtotal += len;
4601 stlen = MIN(len, stlen);
4603 outb((ioaddr + XP_ADDR), GRXFIFO);
4604 insb((ioaddr + XP_DATA), head, stlen);
4606 if (head >= portp->rx.endbuf) {
4607 head = portp->rx.buf;
4609 insb((ioaddr + XP_DATA), head, len);
4615 portp->rx.head = head;
4616 portp->state |= ASY_RXDATA;
4620 /*****************************************************************************/
4623 * Process all characters in the RX FIFO of the UART. Check all char
4624 * status bytes as well, and process as required. We need to check
4625 * all bytes in the FIFO, in case some more enter the FIFO while we
4626 * are here. To get the exact character error type we need to switch
4627 * into CHAR error mode (that is why we need to make sure we empty
4631 static void stl_sc26198rxbadchars(stlport_t *portp)
4634 unsigned int status;
4640 * First up, calculate how much room there is in the RX ring queue.
4641 * We also want to keep track of the longest possible copy length,
4642 * this has to allow for the wrapping of the ring queue.
4644 head = portp->rx.head;
4645 tail = portp->rx.tail;
4646 len = (head >= tail) ? (STL_RXBUFSIZE - (head - tail) - 1) :
4650 * To get the precise error type for each character we must switch
4651 * back into CHAR error mode.
4653 mr1 = stl_sc26198getreg(portp, MR1);
4654 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
4656 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
4657 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
4658 ch = stl_sc26198getreg(portp, RXFIFO);
4660 if (status & SR_RXBREAK)
4661 portp->stats.rxbreaks++;
4662 if (status & SR_RXFRAMING)
4663 portp->stats.rxframing++;
4664 if (status & SR_RXPARITY)
4665 portp->stats.rxparity++;
4666 if (status & SR_RXOVERRUN)
4667 portp->stats.rxoverrun++;
4668 if ((portp->rxignoremsk & status) == 0) {
4669 if ((portp->tty.t_state & TS_CAN_BYPASS_L_RINT) &&
4670 ((status & SR_RXFRAMING) ||
4671 ((status & SR_RXPARITY) &&
4672 (portp->tty.t_iflag & INPCK))))
4674 if ((portp->rxmarkmsk & status) == 0)
4677 *(head + STL_RXBUFSIZE) = status;
4679 if (head >= portp->rx.endbuf)
4680 head = portp->rx.buf;
4687 * To get correct interrupt class we must switch back into BLOCK
4690 stl_sc26198setreg(portp, MR1, mr1);
4692 portp->rx.head = head;
4693 portp->state |= ASY_RXDATA;
4697 /*****************************************************************************/
4700 * Other interrupt handler. This includes modem signals, flow
4701 * control actions, etc.
4704 static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
4706 unsigned char cir, ipr, xisr;
4709 printf("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
4712 cir = stl_sc26198getglobreg(portp, CIR);
4714 switch (cir & CIR_SUBTYPEMASK) {
4716 ipr = stl_sc26198getreg(portp, IPR);
4717 if (ipr & IPR_DCDCHANGE) {
4718 portp->state |= ASY_DCDCHANGE;
4719 portp->stats.modem++;
4723 case CIR_SUBXONXOFF:
4724 xisr = stl_sc26198getreg(portp, XISR);
4725 if (xisr & XISR_RXXONGOT) {
4726 portp->state |= ASY_TXFLOWED;
4727 portp->stats.txxoff++;
4729 if (xisr & XISR_RXXOFFGOT) {
4730 portp->state &= ~ASY_TXFLOWED;
4731 portp->stats.txxon++;
4735 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
4736 stl_sc26198rxbadchars(portp);
4743 /*****************************************************************************/
4746 * Interrupt service routine for sc26198 panels.
4749 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4755 * Work around bug in sc26198 chip... Cannot have A6 address
4756 * line of UART high, else iack will be returned as 0.
4758 outb((iobase + 1), 0);
4760 iack = inb(iobase + XP_IACK);
4762 printf("stl_sc26198intr(panelp=%p,iobase=%x): iack=%x\n", panelp, iobase, iack);
4764 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4766 if (iack & IVR_RXDATA)
4767 stl_sc26198rxisr(portp, iack);
4768 else if (iack & IVR_TXDATA)
4769 stl_sc26198txisr(portp);
4771 stl_sc26198otherisr(portp, iack);
4774 /*****************************************************************************/