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.14 2005/06/16 21:12:42 dillon Exp $
40 /*****************************************************************************/
45 #include "opt_compat.h"
47 #include <sys/param.h>
48 #include <sys/systm.h>
49 #include <sys/kernel.h>
50 #include <sys/malloc.h>
54 #include <sys/fcntl.h>
55 #include <sys/thread2.h>
56 #include <bus/isa/i386/isa_device.h>
57 #include <i386/isa/ic/scd1400.h>
58 #include <i386/isa/ic/sc26198.h>
59 #include <machine/comstats.h>
62 #include <bus/pci/pcivar.h>
63 #include <bus/pci/pcireg.h>
68 /*****************************************************************************/
71 * Define the version level of the kernel - so we can compile in the
72 * appropriate bits of code. By default this will compile for a 2.1
83 /*****************************************************************************/
86 * Define different board types. At the moment I have only declared
87 * those boards that this driver supports. But I will use the standard
88 * "assigned" board numbers. In the future this driver will support
89 * some of the other Stallion boards. Currently supported boards are
90 * abbreviated as EIO = EasyIO and ECH = EasyConnection 8/32.
96 #define BRD_ECH64PCI 27
97 #define BRD_EASYIOPCI 28
100 * When using the BSD "config" stuff there is no easy way to specifiy
101 * a secondary IO address region. So it is hard wired here. Also the
102 * shared interrupt information is hard wired here...
104 static unsigned int stl_ioshared = 0x280;
105 static unsigned int stl_irqshared = 0;
107 /*****************************************************************************/
110 * Define important driver limitations.
112 #define STL_MAXBRDS 8
113 #define STL_MAXPANELS 4
114 #define STL_MAXBANKS 8
115 #define STL_PORTSPERPANEL 16
116 #define STL_PORTSPERBRD 64
119 * Define the important minor number break down bits. These have been
120 * chosen to be "compatible" with the standard sio driver minor numbers.
121 * Extra high bits are used to distinguish between boards.
123 #define STL_CALLOUTDEV 0x80
124 #define STL_CTRLLOCK 0x40
125 #define STL_CTRLINIT 0x20
126 #define STL_CTRLDEV (STL_CTRLLOCK | STL_CTRLINIT)
128 #define STL_MEMDEV 0x07000000
130 #define STL_DEFSPEED TTYDEF_SPEED
131 #define STL_DEFCFLAG (CS8 | CREAD | HUPCL)
134 * I haven't really decided (or measured) what buffer sizes give
135 * a good balance between performance and memory usage. These seem
136 * to work pretty well...
138 #define STL_RXBUFSIZE 2048
139 #define STL_TXBUFSIZE 2048
141 #define STL_TXBUFLOW (STL_TXBUFSIZE / 4)
142 #define STL_RXBUFHIGH (3 * STL_RXBUFSIZE / 4)
144 /*****************************************************************************/
147 * Define our local driver identity first. Set up stuff to deal with
148 * all the local structures required by a serial tty driver.
150 static const char stl_drvname[] = "stl";
151 static const char stl_longdrvname[] = "Stallion Multiport Serial Driver";
152 static const char stl_drvversion[] = "2.0.0";
153 static int stl_brdprobed[STL_MAXBRDS];
155 static int stl_nrbrds = 0;
156 static int stl_doingtimeout = 0;
157 static struct callout stl_poll_ch;
159 static const char __file__[] = /*__FILE__*/ "stallion.c";
162 * Define global stats structures. Not used often, and can be
163 * re-used for each stats call.
165 static combrd_t stl_brdstats;
166 static comstats_t stl_comstats;
168 /*****************************************************************************/
171 * Define a set of structures to hold all the board/panel/port info
172 * for our ports. These will be dynamically allocated as required.
176 * Define a ring queue structure for each port. This will hold the
177 * TX data waiting to be output. Characters are fed into this buffer
178 * from the line discipline (or even direct from user space!) and
179 * then fed into the UARTs during interrupts. Will use a clasic ring
180 * queue here for this. The good thing about this type of ring queue
181 * is that the head and tail pointers can be updated without interrupt
182 * protection - since "write" code only needs to change the head, and
183 * interrupt code only needs to change the tail.
193 * Port, panel and board structures to hold status info about each.
194 * The board structure contains pointers to structures for each panel
195 * connected to it, and in turn each panel structure contains pointers
196 * for each port structure for each port on that panel. Note that
197 * the port structure also contains the board and panel number that it
198 * is associated with, this makes it (fairly) easy to get back to the
199 * board/panel info for a port. Also note that the tty struct is at
200 * the top of the structure, this is important, since the code uses
201 * this fact to get the port struct pointer from the tty struct
204 typedef struct stlport {
222 unsigned int rxignoremsk;
223 unsigned int rxmarkmsk;
224 unsigned int crenable;
227 struct termios initintios;
228 struct termios initouttios;
229 struct termios lockintios;
230 struct termios lockouttios;
231 struct timeval timestamp;
236 struct callout dtr_ch;
239 typedef struct stlpanel {
246 unsigned int ackmask;
247 void (*isr)(struct stlpanel *panelp, unsigned int iobase);
249 stlport_t *ports[STL_PORTSPERPANEL];
252 typedef struct stlbrd {
262 unsigned int ioaddr1;
263 unsigned int ioaddr2;
264 unsigned int iostatus;
266 unsigned int ioctrlval;
269 void (*isr)(struct stlbrd *brdp);
270 unsigned int bnkpageaddr[STL_MAXBANKS];
271 unsigned int bnkstataddr[STL_MAXBANKS];
272 stlpanel_t *bnk2panel[STL_MAXBANKS];
273 stlpanel_t *panels[STL_MAXPANELS];
274 stlport_t *ports[STL_PORTSPERBRD];
277 static stlbrd_t *stl_brds[STL_MAXBRDS];
280 * Per board state flags. Used with the state field of the board struct.
281 * Not really much here yet!
283 #define BRD_FOUND 0x1
286 * Define the port structure state flags. These set of flags are
287 * modified at interrupt time - so setting and reseting them needs
290 #define ASY_TXLOW 0x1
291 #define ASY_RXDATA 0x2
292 #define ASY_DCDCHANGE 0x4
293 #define ASY_DTRWAIT 0x8
294 #define ASY_RTSFLOW 0x10
295 #define ASY_RTSFLOWMODE 0x20
296 #define ASY_CTSFLOWMODE 0x40
297 #define ASY_TXFLOWED 0x80
298 #define ASY_TXBUSY 0x100
299 #define ASY_TXEMPTY 0x200
301 #define ASY_ACTIVE (ASY_TXLOW | ASY_RXDATA | ASY_DCDCHANGE)
304 * Define an array of board names as printable strings. Handy for
305 * referencing boards when printing trace and stuff.
307 static char *stl_brdnames[] = {
339 /*****************************************************************************/
342 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
343 * to the directly accessable io ports of these boards (not the cd1400
344 * uarts - they are in scd1400.h).
346 #define EIO_8PORTRS 0x04
347 #define EIO_4PORTRS 0x05
348 #define EIO_8PORTDI 0x00
349 #define EIO_8PORTM 0x06
351 #define EIO_IDBITMASK 0x07
353 #define EIO_BRDMASK 0xf0
356 #define ID_BRD16 0x30
358 #define EIO_INTRPEND 0x08
359 #define EIO_INTEDGE 0x00
360 #define EIO_INTLEVEL 0x08
363 #define ECH_IDBITMASK 0xe0
364 #define ECH_BRDENABLE 0x08
365 #define ECH_BRDDISABLE 0x00
366 #define ECH_INTENABLE 0x01
367 #define ECH_INTDISABLE 0x00
368 #define ECH_INTLEVEL 0x02
369 #define ECH_INTEDGE 0x00
370 #define ECH_INTRPEND 0x01
371 #define ECH_BRDRESET 0x01
373 #define ECHMC_INTENABLE 0x01
374 #define ECHMC_BRDRESET 0x02
376 #define ECH_PNLSTATUS 2
377 #define ECH_PNL16PORT 0x20
378 #define ECH_PNLIDMASK 0x07
379 #define ECH_PNLXPID 0x40
380 #define ECH_PNLINTRPEND 0x80
381 #define ECH_ADDR2MASK 0x1e0
383 #define EIO_CLK 25000000
384 #define EIO_CLK8M 20000000
385 #define ECH_CLK EIO_CLK
388 * Define the PCI vendor and device ID for Stallion PCI boards.
390 #define STL_PCINSVENDID 0x100b
391 #define STL_PCINSDEVID 0xd001
393 #define STL_PCIVENDID 0x124d
394 #define STL_PCI32DEVID 0x0000
395 #define STL_PCI64DEVID 0x0002
396 #define STL_PCIEIODEVID 0x0003
398 #define STL_PCIBADCLASS 0x0101
400 typedef struct stlpcibrd {
401 unsigned short vendid;
402 unsigned short devid;
406 static stlpcibrd_t stl_pcibrds[] = {
407 { STL_PCIVENDID, STL_PCI64DEVID, BRD_ECH64PCI },
408 { STL_PCIVENDID, STL_PCIEIODEVID, BRD_EASYIOPCI },
409 { STL_PCIVENDID, STL_PCI32DEVID, BRD_ECHPCI },
410 { STL_PCINSVENDID, STL_PCINSDEVID, BRD_ECHPCI },
413 static int stl_nrpcibrds = sizeof(stl_pcibrds) / sizeof(stlpcibrd_t);
415 /*****************************************************************************/
418 * Define the vector mapping bits for the programmable interrupt board
419 * hardware. These bits encode the interrupt for the board to use - it
420 * is software selectable (except the EIO-8M).
422 static unsigned char stl_vecmap[] = {
423 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
424 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
428 * Set up enable and disable macros for the ECH boards. They require
429 * the secondary io address space to be activated and deactivated.
430 * This way all ECH boards can share their secondary io region.
431 * If this is an ECH-PCI board then also need to set the page pointer
432 * to point to the correct page.
434 #define BRDENABLE(brdnr,pagenr) \
435 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
436 outb(stl_brds[(brdnr)]->ioctrl, \
437 (stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE));\
438 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
439 outb(stl_brds[(brdnr)]->ioctrl, (pagenr));
441 #define BRDDISABLE(brdnr) \
442 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
443 outb(stl_brds[(brdnr)]->ioctrl, \
444 (stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE));
447 * Define some spare buffer space for un-wanted received characters.
449 static char stl_unwanted[SC26198_RXFIFOSIZE];
451 /*****************************************************************************/
454 * Define macros to extract a brd and port number from a minor number.
455 * This uses the extended minor number range in the upper 2 bytes of
456 * the device number. This gives us plenty of minor numbers to play
459 #define MKDEV2BRD(m) ((minor(m) & 0x00700000) >> 20)
460 #define MKDEV2PORT(m) ((minor(m) & 0x1f) | ((minor(m) & 0x00010000) >> 11))
463 * Define some handy local macros...
466 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
469 /*****************************************************************************/
472 * Declare all those functions in this driver! First up is the set of
473 * externally visible functions.
476 static int stlprobe(struct isa_device *idp);
477 static int stlattach(struct isa_device *idp);
479 STATIC d_open_t stlopen;
480 STATIC d_close_t stlclose;
481 STATIC d_ioctl_t stlioctl;
484 * Internal function prototypes.
486 static stlport_t *stl_dev2port(dev_t dev);
487 static int stl_findfreeunit(void);
488 static int stl_rawopen(stlport_t *portp);
489 static int stl_rawclose(stlport_t *portp);
490 static void stl_flush(stlport_t *portp, int flag);
491 static int stl_param(struct tty *tp, struct termios *tiosp);
492 static void stl_start(struct tty *tp);
493 static void stl_stop(struct tty *tp, int);
494 static void stl_ttyoptim(stlport_t *portp, struct termios *tiosp);
495 static void stl_dotimeout(void);
496 static void stl_poll(void *arg);
497 static void stl_rxprocess(stlport_t *portp);
498 static void stl_flowcontrol(stlport_t *portp, int hw, int sw);
499 static void stl_dtrwakeup(void *arg);
500 static int stl_brdinit(stlbrd_t *brdp);
501 static int stl_initeio(stlbrd_t *brdp);
502 static int stl_initech(stlbrd_t *brdp);
503 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
504 static void stl_eiointr(stlbrd_t *brdp);
505 static void stl_echatintr(stlbrd_t *brdp);
506 static void stl_echmcaintr(stlbrd_t *brdp);
507 static void stl_echpciintr(stlbrd_t *brdp);
508 static void stl_echpci64intr(stlbrd_t *brdp);
509 static int stl_memioctl(dev_t dev, unsigned long cmd, caddr_t data,
510 int flag, struct thread *td);
511 static int stl_getbrdstats(caddr_t data);
512 static int stl_getportstats(stlport_t *portp, caddr_t data);
513 static int stl_clrportstats(stlport_t *portp, caddr_t data);
514 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
515 static ointhand2_t stlintr;
518 static const char *stlpciprobe(pcici_t tag, pcidi_t type);
519 static void stlpciattach(pcici_t tag, int unit);
520 static void stlpciintr(void * arg);
524 * CD1400 uart specific handling functions.
526 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value);
527 static int stl_cd1400getreg(stlport_t *portp, int regnr);
528 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value);
529 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
530 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
531 static int stl_cd1400setport(stlport_t *portp, struct termios *tiosp);
532 static int stl_cd1400getsignals(stlport_t *portp);
533 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts);
534 static void stl_cd1400ccrwait(stlport_t *portp);
535 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx);
536 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx);
537 static void stl_cd1400disableintrs(stlport_t *portp);
538 static void stl_cd1400sendbreak(stlport_t *portp, long len);
539 static void stl_cd1400sendflow(stlport_t *portp, int hw, int sw);
540 static int stl_cd1400datastate(stlport_t *portp);
541 static void stl_cd1400flush(stlport_t *portp, int flag);
542 static __inline void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr);
543 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr);
544 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr);
545 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase);
546 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase);
549 * SC26198 uart specific handling functions.
551 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value);
552 static int stl_sc26198getreg(stlport_t *portp, int regnr);
553 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value);
554 static int stl_sc26198getglobreg(stlport_t *portp, int regnr);
555 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
556 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
557 static int stl_sc26198setport(stlport_t *portp, struct termios *tiosp);
558 static int stl_sc26198getsignals(stlport_t *portp);
559 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts);
560 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx);
561 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx);
562 static void stl_sc26198disableintrs(stlport_t *portp);
563 static void stl_sc26198sendbreak(stlport_t *portp, long len);
564 static void stl_sc26198sendflow(stlport_t *portp, int hw, int sw);
565 static int stl_sc26198datastate(stlport_t *portp);
566 static void stl_sc26198flush(stlport_t *portp, int flag);
567 static void stl_sc26198txunflow(stlport_t *portp);
568 static void stl_sc26198wait(stlport_t *portp);
569 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase);
570 static void stl_sc26198txisr(stlport_t *port);
571 static void stl_sc26198rxisr(stlport_t *port, unsigned int iack);
572 static void stl_sc26198rxgoodchars(stlport_t *portp);
573 static void stl_sc26198rxbadchars(stlport_t *portp);
574 static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
576 /*****************************************************************************/
579 * Generic UART support structure.
581 typedef struct uart {
582 int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp);
583 void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
584 int (*setport)(stlport_t *portp, struct termios *tiosp);
585 int (*getsignals)(stlport_t *portp);
586 void (*setsignals)(stlport_t *portp, int dtr, int rts);
587 void (*enablerxtx)(stlport_t *portp, int rx, int tx);
588 void (*startrxtx)(stlport_t *portp, int rx, int tx);
589 void (*disableintrs)(stlport_t *portp);
590 void (*sendbreak)(stlport_t *portp, long len);
591 void (*sendflow)(stlport_t *portp, int hw, int sw);
592 void (*flush)(stlport_t *portp, int flag);
593 int (*datastate)(stlport_t *portp);
594 void (*intr)(stlpanel_t *panelp, unsigned int iobase);
598 * Define some macros to make calling these functions nice and clean.
600 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
601 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
602 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
603 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
604 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
605 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
606 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
607 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
608 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
609 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
610 #define stl_uartflush (* ((uart_t *) portp->uartp)->flush)
611 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
613 /*****************************************************************************/
616 * CD1400 UART specific data initialization.
618 static uart_t stl_cd1400uart = {
622 stl_cd1400getsignals,
623 stl_cd1400setsignals,
624 stl_cd1400enablerxtx,
626 stl_cd1400disableintrs,
635 * Define the offsets within the register bank of a cd1400 based panel.
636 * These io address offsets are common to the EasyIO board as well.
644 #define EREG_BANKSIZE 8
646 #define CD1400_CLK 25000000
647 #define CD1400_CLK8M 20000000
650 * Define the cd1400 baud rate clocks. These are used when calculating
651 * what clock and divisor to use for the required baud rate. Also
652 * define the maximum baud rate allowed, and the default base baud.
654 static int stl_cd1400clkdivs[] = {
655 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
659 * Define the maximum baud rate of the cd1400 devices.
661 #define CD1400_MAXBAUD 230400
663 /*****************************************************************************/
666 * SC26198 UART specific data initization.
668 static uart_t stl_sc26198uart = {
669 stl_sc26198panelinit,
672 stl_sc26198getsignals,
673 stl_sc26198setsignals,
674 stl_sc26198enablerxtx,
675 stl_sc26198startrxtx,
676 stl_sc26198disableintrs,
677 stl_sc26198sendbreak,
680 stl_sc26198datastate,
685 * Define the offsets within the register bank of a sc26198 based panel.
693 #define XP_BANKSIZE 4
696 * Define the sc26198 baud rate table. Offsets within the table
697 * represent the actual baud rate selector of sc26198 registers.
699 static unsigned int sc26198_baudtable[] = {
700 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
701 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
705 #define SC26198_NRBAUDS (sizeof(sc26198_baudtable) / sizeof(unsigned int))
708 * Define the maximum baud rate of the sc26198 devices.
710 #define SC26198_MAXBAUD 460800
712 /*****************************************************************************/
715 * Declare the driver isa structure.
717 struct isa_driver stldriver = {
718 stlprobe, stlattach, "stl"
721 /*****************************************************************************/
726 * Declare the driver pci structure.
728 static unsigned long stl_count;
730 static struct pci_device stlpcidriver = {
738 COMPAT_PCI_DRIVER (stlpci, stlpcidriver);
742 /*****************************************************************************/
747 * FreeBSD-2.2+ kernel linkage.
750 #define CDEV_MAJOR 72
751 static struct cdevsw stl_cdevsw = {
753 /* maj */ CDEV_MAJOR,
754 /* flags */ D_TTY | D_KQFILTER,
759 /* close */ stlclose,
761 /* write */ ttywrite,
762 /* ioctl */ stlioctl,
765 /* strategy */ nostrategy,
768 /* kqfilter */ ttykqfilter
771 static void stl_drvinit(void *unused)
775 SYSINIT(sidev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,stl_drvinit,NULL)
779 /*****************************************************************************/
782 * Probe for some type of EasyIO or EasyConnection 8/32 board at
783 * the supplied address. All we do is check if we can find the
784 * board ID for the board... (Note, PCI boards not checked here,
785 * they are done in the stlpciprobe() routine).
788 static int stlprobe(struct isa_device *idp)
793 printf("stlprobe(idp=%x): unit=%d iobase=%x\n", (int) idp,
794 idp->id_unit, idp->id_iobase);
797 if (idp->id_unit > STL_MAXBRDS)
800 status = inb(idp->id_iobase + 1);
801 if ((status & ECH_IDBITMASK) == ECH_ID) {
802 stl_brdprobed[idp->id_unit] = BRD_ECH;
806 status = inb(idp->id_iobase + 2);
807 switch (status & EIO_IDBITMASK) {
813 stl_brdprobed[idp->id_unit] = BRD_EASYIO;
822 /*****************************************************************************/
825 * Find an available internal board number (unit number). The problem
826 * is that the same unit numbers can be assigned to different boards
827 * detected during the ISA and PCI initialization phases.
830 static int stl_findfreeunit()
834 for (i = 0; (i < STL_MAXBRDS); i++)
835 if (stl_brds[i] == (stlbrd_t *) NULL)
837 return((i >= STL_MAXBRDS) ? -1 : i);
840 /*****************************************************************************/
843 * Allocate resources for and initialize the specified board.
846 static int stlattach(struct isa_device *idp)
849 int boardnr, portnr, minor_dev;
852 printf("stlattach(idp=%p): unit=%d iobase=%x\n", (void *) idp,
853 idp->id_unit, idp->id_iobase);
856 /* idp->id_ointr = stlintr; */
858 brdp = malloc(sizeof(stlbrd_t), M_TTYS, M_WAITOK | M_ZERO);
860 if ((brdp->brdnr = stl_findfreeunit()) < 0) {
861 printf("STALLION: too many boards found, max=%d\n",
865 if (brdp->brdnr >= stl_nrbrds)
866 stl_nrbrds = brdp->brdnr + 1;
868 brdp->unitid = idp->id_unit;
869 brdp->brdtype = stl_brdprobed[idp->id_unit];
870 brdp->ioaddr1 = idp->id_iobase;
871 brdp->ioaddr2 = stl_ioshared;
872 brdp->irq = ffs(idp->id_irq) - 1;
873 brdp->irqtype = stl_irqshared;
876 /* register devices for DEVFS */
877 boardnr = brdp->brdnr;
878 cdevsw_add(&stl_cdevsw, 31, boardnr);
879 make_dev(&stl_cdevsw, boardnr + 0x1000000, UID_ROOT, GID_WHEEL,
880 0600, "staliomem%d", boardnr);
882 for (portnr = 0, minor_dev = boardnr * 0x100000;
883 portnr < 32; portnr++, minor_dev++) {
885 make_dev(&stl_cdevsw, minor_dev,
886 UID_ROOT, GID_WHEEL, 0600,
887 "ttyE%d", portnr + (boardnr * 64));
888 make_dev(&stl_cdevsw, minor_dev + 32,
889 UID_ROOT, GID_WHEEL, 0600,
890 "ttyiE%d", portnr + (boardnr * 64));
891 make_dev(&stl_cdevsw, minor_dev + 64,
892 UID_ROOT, GID_WHEEL, 0600,
893 "ttylE%d", portnr + (boardnr * 64));
894 make_dev(&stl_cdevsw, minor_dev + 128,
895 UID_ROOT, GID_WHEEL, 0600,
896 "cue%d", portnr + (boardnr * 64));
897 make_dev(&stl_cdevsw, minor_dev + 160,
898 UID_ROOT, GID_WHEEL, 0600,
899 "cuie%d", portnr + (boardnr * 64));
900 make_dev(&stl_cdevsw, minor_dev + 192,
901 UID_ROOT, GID_WHEEL, 0600,
902 "cule%d", portnr + (boardnr * 64));
905 make_dev(&stl_cdevsw, minor_dev + 0x10000,
906 UID_ROOT, GID_WHEEL, 0600,
907 "ttyE%d", portnr + (boardnr * 64) + 32);
908 make_dev(&stl_cdevsw, minor_dev + 32 + 0x10000,
909 UID_ROOT, GID_WHEEL, 0600,
910 "ttyiE%d", portnr + (boardnr * 64) + 32);
911 make_dev(&stl_cdevsw, minor_dev + 64 + 0x10000,
912 UID_ROOT, GID_WHEEL, 0600,
913 "ttylE%d", portnr + (boardnr * 64) + 32);
914 make_dev(&stl_cdevsw, minor_dev + 128 + 0x10000,
915 UID_ROOT, GID_WHEEL, 0600,
916 "cue%d", portnr + (boardnr * 64) + 32);
917 make_dev(&stl_cdevsw, minor_dev + 160 + 0x10000,
918 UID_ROOT, GID_WHEEL, 0600,
919 "cuie%d", portnr + (boardnr * 64) + 32);
920 make_dev(&stl_cdevsw, minor_dev + 192 + 0x10000,
921 UID_ROOT, GID_WHEEL, 0600,
922 "cule%d", portnr + (boardnr * 64) + 32);
924 boardnr = brdp->brdnr;
925 make_dev(&stl_cdevsw, boardnr + 0x1000000, UID_ROOT, GID_WHEEL,
926 0600, "staliomem%d", boardnr);
928 for (portnr = 0, minor_dev = boardnr * 0x100000;
929 portnr < 32; portnr++, minor_dev++) {
931 make_dev(&stl_cdevsw, minor_dev,
932 UID_ROOT, GID_WHEEL, 0600,
933 "ttyE%d", portnr + (boardnr * 64));
934 make_dev(&stl_cdevsw, minor_dev + 32,
935 UID_ROOT, GID_WHEEL, 0600,
936 "ttyiE%d", portnr + (boardnr * 64));
937 make_dev(&stl_cdevsw, minor_dev + 64,
938 UID_ROOT, GID_WHEEL, 0600,
939 "ttylE%d", portnr + (boardnr * 64));
940 make_dev(&stl_cdevsw, minor_dev + 128,
941 UID_ROOT, GID_WHEEL, 0600,
942 "cue%d", portnr + (boardnr * 64));
943 make_dev(&stl_cdevsw, minor_dev + 160,
944 UID_ROOT, GID_WHEEL, 0600,
945 "cuie%d", portnr + (boardnr * 64));
946 make_dev(&stl_cdevsw, minor_dev + 192,
947 UID_ROOT, GID_WHEEL, 0600,
948 "cule%d", portnr + (boardnr * 64));
951 make_dev(&stl_cdevsw, minor_dev + 0x10000,
952 UID_ROOT, GID_WHEEL, 0600,
953 "ttyE%d", portnr + (boardnr * 64) + 32);
954 make_dev(&stl_cdevsw, minor_dev + 32 + 0x10000,
955 UID_ROOT, GID_WHEEL, 0600,
956 "ttyiE%d", portnr + (boardnr * 64) + 32);
957 make_dev(&stl_cdevsw, minor_dev + 64 + 0x10000,
958 UID_ROOT, GID_WHEEL, 0600,
959 "ttylE%d", portnr + (boardnr * 64) + 32);
960 make_dev(&stl_cdevsw, minor_dev + 128 + 0x10000,
961 UID_ROOT, GID_WHEEL, 0600,
962 "cue%d", portnr + (boardnr * 64) + 32);
963 make_dev(&stl_cdevsw, minor_dev + 160 + 0x10000,
964 UID_ROOT, GID_WHEEL, 0600,
965 "cuie%d", portnr + (boardnr * 64) + 32);
966 make_dev(&stl_cdevsw, minor_dev + 192 + 0x10000,
967 UID_ROOT, GID_WHEEL, 0600,
968 "cule%d", portnr + (boardnr * 64) + 32);
974 /*****************************************************************************/
979 * Probe specifically for the PCI boards. We need to be a little
980 * carefull here, since it looks sort like a Nat Semi IDE chip...
983 static const char *stlpciprobe(pcici_t tag, pcidi_t type)
989 printf("stlpciprobe(tag=%x,type=%x)\n", (int) &tag, (int) type);
993 for (i = 0; (i < stl_nrpcibrds); i++) {
994 if (((type & 0xffff) == stl_pcibrds[i].vendid) &&
995 (((type >> 16) & 0xffff) == stl_pcibrds[i].devid)) {
996 brdtype = stl_pcibrds[i].brdtype;
1002 return((char *) NULL);
1004 class = pci_conf_read(tag, PCI_CLASS_REG);
1005 if ((class & PCI_CLASS_MASK) == PCI_CLASS_MASS_STORAGE)
1006 return((char *) NULL);
1008 return(stl_brdnames[brdtype]);
1011 /*****************************************************************************/
1014 * Allocate resources for and initialize the specified PCI board.
1017 void stlpciattach(pcici_t tag, int unit)
1020 unsigned int bar[4];
1023 int boardnr, portnr, minor_dev;
1026 printf("stlpciattach(tag=%x,unit=%x)\n", (int) &tag, unit);
1029 brdp = malloc(sizeof(stlbrd_t), M_TTYS, M_WAITOK | M_ZERO);
1031 if ((unit < 0) || (unit > STL_MAXBRDS)) {
1032 printf("STALLION: bad PCI board unit number=%d\n", unit);
1037 * Allocate us a new driver unique unit number.
1039 if ((brdp->brdnr = stl_findfreeunit()) < 0) {
1040 printf("STALLION: too many boards found, max=%d\n",
1044 if (brdp->brdnr >= stl_nrbrds)
1045 stl_nrbrds = brdp->brdnr + 1;
1048 * Determine what type of PCI board this is...
1050 id = (unsigned int) pci_conf_read(tag, 0x0);
1051 for (i = 0; (i < stl_nrpcibrds); i++) {
1052 if (((id & 0xffff) == stl_pcibrds[i].vendid) &&
1053 (((id >> 16) & 0xffff) == stl_pcibrds[i].devid)) {
1054 brdp->brdtype = stl_pcibrds[i].brdtype;
1059 if (i >= stl_nrpcibrds) {
1060 printf("STALLION: probed PCI board unknown type=%x\n", id);
1064 for (i = 0; (i < 4); i++)
1065 bar[i] = (unsigned int) pci_conf_read(tag, 0x10 + (i * 4)) &
1068 switch (brdp->brdtype) {
1070 brdp->ioaddr1 = bar[1];
1071 brdp->ioaddr2 = bar[2];
1074 brdp->ioaddr1 = bar[2];
1075 brdp->ioaddr2 = bar[1];
1078 brdp->ioaddr1 = bar[1];
1079 brdp->ioaddr2 = bar[0];
1082 printf("STALLION: unknown PCI board type=%d\n", brdp->brdtype);
1087 brdp->unitid = brdp->brdnr; /* PCI units auto-assigned */
1088 brdp->irq = ((int) pci_conf_read(tag, 0x3c)) & 0xff;
1090 if (pci_map_int(tag, stlpciintr, (void *) NULL) == 0) {
1091 printf("STALLION: failed to map interrupt irq=%d for unit=%d\n",
1092 brdp->irq, brdp->brdnr);
1098 /* register devices for DEVFS */
1099 boardnr = brdp->brdnr;
1100 make_dev(&stl_cdevsw, boardnr + 0x1000000, UID_ROOT, GID_WHEEL,
1101 0600, "staliomem%d", boardnr);
1103 for (portnr = 0, minor_dev = boardnr * 0x100000;
1104 portnr < 32; portnr++, minor_dev++) {
1106 make_dev(&stl_cdevsw, minor_dev,
1107 UID_ROOT, GID_WHEEL, 0600,
1108 "ttyE%d", portnr + (boardnr * 64));
1109 make_dev(&stl_cdevsw, minor_dev + 32,
1110 UID_ROOT, GID_WHEEL, 0600,
1111 "ttyiE%d", portnr + (boardnr * 64));
1112 make_dev(&stl_cdevsw, minor_dev + 64,
1113 UID_ROOT, GID_WHEEL, 0600,
1114 "ttylE%d", portnr + (boardnr * 64));
1115 make_dev(&stl_cdevsw, minor_dev + 128,
1116 UID_ROOT, GID_WHEEL, 0600,
1117 "cue%d", portnr + (boardnr * 64));
1118 make_dev(&stl_cdevsw, minor_dev + 160,
1119 UID_ROOT, GID_WHEEL, 0600,
1120 "cuie%d", portnr + (boardnr * 64));
1121 make_dev(&stl_cdevsw, minor_dev + 192,
1122 UID_ROOT, GID_WHEEL, 0600,
1123 "cule%d", portnr + (boardnr * 64));
1126 make_dev(&stl_cdevsw, minor_dev + 0x10000,
1127 UID_ROOT, GID_WHEEL, 0600,
1128 "ttyE%d", portnr + (boardnr * 64) + 32);
1129 make_dev(&stl_cdevsw, minor_dev + 32 + 0x10000,
1130 UID_ROOT, GID_WHEEL, 0600,
1131 "ttyiE%d", portnr + (boardnr * 64) + 32);
1132 make_dev(&stl_cdevsw, minor_dev + 64 + 0x10000,
1133 UID_ROOT, GID_WHEEL, 0600,
1134 "ttylE%d", portnr + (boardnr * 64) + 32);
1135 make_dev(&stl_cdevsw, minor_dev + 128 + 0x10000,
1136 UID_ROOT, GID_WHEEL, 0600,
1137 "cue%d", portnr + (boardnr * 64) + 32);
1138 make_dev(&stl_cdevsw, minor_dev + 160 + 0x10000,
1139 UID_ROOT, GID_WHEEL, 0600,
1140 "cuie%d", portnr + (boardnr * 64) + 32);
1141 make_dev(&stl_cdevsw, minor_dev + 192 + 0x10000,
1142 UID_ROOT, GID_WHEEL, 0600,
1143 "cule%d", portnr + (boardnr * 64) + 32);
1149 /*****************************************************************************/
1151 STATIC int stlopen(dev_t dev, int flag, int mode, struct thread *td)
1158 printf("stlopen(dev=%x,flag=%x,mode=%x,p=%x)\n", (int) dev, flag,
1163 * Firstly check if the supplied device number is a valid device.
1165 if (minor(dev) & STL_MEMDEV)
1168 portp = stl_dev2port(dev);
1169 if (portp == (stlport_t *) NULL)
1171 if (minor(dev) & STL_CTRLDEV)
1175 callout = minor(dev) & STL_CALLOUTDEV;
1182 * Wait here for the DTR drop timeout period to expire.
1184 while (portp->state & ASY_DTRWAIT) {
1185 error = tsleep(&portp->dtrwait, PCATCH, "stldtr", 0);
1191 * We have a valid device, so now we check if it is already open.
1192 * If not then initialize the port hardware and set up the tty
1193 * struct as required.
1195 if ((tp->t_state & TS_ISOPEN) == 0) {
1196 tp->t_oproc = stl_start;
1197 tp->t_stop = stl_stop;
1198 tp->t_param = stl_param;
1200 tp->t_termios = callout ? portp->initouttios :
1204 if ((portp->sigs & TIOCM_CD) || callout)
1205 (*linesw[tp->t_line].l_modem)(tp, 1);
1208 if (portp->callout == 0) {
1213 if (portp->callout != 0) {
1214 if (flag & O_NONBLOCK) {
1218 error = tsleep(&portp->callout,
1219 PCATCH, "stlcall", 0);
1222 goto stlopen_restart;
1225 if ((tp->t_state & TS_XCLUDE) && suser(td)) {
1232 * If this port is not the callout device and we do not have carrier
1233 * then we need to sleep, waiting for it to be asserted.
1235 if (((tp->t_state & TS_CARR_ON) == 0) && !callout &&
1236 ((tp->t_cflag & CLOCAL) == 0) &&
1237 ((flag & O_NONBLOCK) == 0)) {
1239 error = tsleep(TSA_CARR_ON(tp), PCATCH, "stldcd", 0);
1243 goto stlopen_restart;
1247 * Open the line discipline.
1249 error = (*linesw[tp->t_line].l_open)(dev, tp);
1250 stl_ttyoptim(portp, &tp->t_termios);
1251 if ((tp->t_state & TS_ISOPEN) && callout)
1255 * If for any reason we get to here and the port is not actually
1256 * open then close of the physical hardware - no point leaving it
1257 * active when the open failed...
1261 if (((tp->t_state & TS_ISOPEN) == 0) && (portp->waitopens == 0))
1262 stl_rawclose(portp);
1267 /*****************************************************************************/
1269 STATIC int stlclose(dev_t dev, int flag, int mode, struct thread *td)
1275 printf("stlclose(dev=%s,flag=%x,mode=%x,p=%p)\n", devtoname(dev),
1276 flag, mode, (void *) p);
1279 if (minor(dev) & STL_MEMDEV)
1281 if (minor(dev) & STL_CTRLDEV)
1284 portp = stl_dev2port(dev);
1285 if (portp == (stlport_t *) NULL)
1290 (*linesw[tp->t_line].l_close)(tp, flag);
1291 stl_ttyoptim(portp, &tp->t_termios);
1292 stl_rawclose(portp);
1298 /*****************************************************************************/
1302 STATIC void stl_stop(struct tty *tp, int rw)
1305 printf("stl_stop(tp=%x,rw=%x)\n", (int) tp, rw);
1308 stl_flush((stlport_t *) tp, rw);
1313 STATIC int stlstop(struct tty *tp, int rw)
1316 printf("stlstop(tp=%x,rw=%x)\n", (int) tp, rw);
1319 stl_flush((stlport_t *) tp, rw);
1325 /*****************************************************************************/
1327 STATIC int stlioctl(dev_t dev, unsigned long cmd, caddr_t data, int flag,
1330 struct termios *newtios, *localtios;
1336 printf("stlioctl(dev=%s,cmd=%lx,data=%p,flag=%x,p=%p)\n",
1337 devtoname(dev), cmd, (void *) data, flag, (void *) p);
1340 if (minor(dev) & STL_MEMDEV)
1341 return(stl_memioctl(dev, cmd, data, flag, td));
1343 portp = stl_dev2port(dev);
1344 if (portp == (stlport_t *) NULL)
1350 * First up handle ioctls on the control devices.
1352 if (minor(dev) & STL_CTRLDEV) {
1353 if ((minor(dev) & STL_CTRLDEV) == STL_CTRLINIT)
1354 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1355 &portp->initouttios : &portp->initintios;
1356 else if ((minor(dev) & STL_CTRLDEV) == STL_CTRLLOCK)
1357 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1358 &portp->lockouttios : &portp->lockintios;
1364 if ((error = suser(td)) == 0)
1365 *localtios = *((struct termios *) data);
1368 *((struct termios *) data) = *localtios;
1371 *((int *) data) = TTYDISC;
1374 bzero(data, sizeof(struct winsize));
1384 * Deal with 4.3 compatibility issues if we have too...
1386 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1388 struct termios tios;
1389 unsigned long oldcmd;
1391 tios = tp->t_termios;
1393 if ((error = ttsetcompat(tp, &cmd, data, &tios)))
1396 data = (caddr_t) &tios;
1401 * Carry out some pre-cmd processing work first...
1402 * Hmmm, not so sure we want this, disable for now...
1404 if ((cmd == TIOCSETA) || (cmd == TIOCSETAW) || (cmd == TIOCSETAF)) {
1405 newtios = (struct termios *) data;
1406 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1407 &portp->lockouttios : &portp->lockintios;
1409 newtios->c_iflag = (tp->t_iflag & localtios->c_iflag) |
1410 (newtios->c_iflag & ~localtios->c_iflag);
1411 newtios->c_oflag = (tp->t_oflag & localtios->c_oflag) |
1412 (newtios->c_oflag & ~localtios->c_oflag);
1413 newtios->c_cflag = (tp->t_cflag & localtios->c_cflag) |
1414 (newtios->c_cflag & ~localtios->c_cflag);
1415 newtios->c_lflag = (tp->t_lflag & localtios->c_lflag) |
1416 (newtios->c_lflag & ~localtios->c_lflag);
1417 for (i = 0; (i < NCCS); i++) {
1418 if (localtios->c_cc[i] != 0)
1419 newtios->c_cc[i] = tp->t_cc[i];
1421 if (localtios->c_ispeed != 0)
1422 newtios->c_ispeed = tp->t_ispeed;
1423 if (localtios->c_ospeed != 0)
1424 newtios->c_ospeed = tp->t_ospeed;
1428 * Call the line discipline and the common command processing to
1429 * process this command (if they can).
1431 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td);
1432 if (error != ENOIOCTL)
1436 error = ttioctl(tp, cmd, data, flag);
1437 stl_ttyoptim(portp, &tp->t_termios);
1438 if (error != ENOIOCTL) {
1446 * Process local commands here. These are all commands that only we
1447 * can take care of (they all rely on actually doing something special
1448 * to the actual hardware).
1452 stl_sendbreak(portp, -1);
1455 stl_sendbreak(portp, -2);
1458 stl_setsignals(portp, 1, -1);
1461 stl_setsignals(portp, 0, -1);
1464 i = *((int *) data);
1465 stl_setsignals(portp, ((i & TIOCM_DTR) ? 1 : 0),
1466 ((i & TIOCM_RTS) ? 1 : 0));
1469 i = *((int *) data);
1470 stl_setsignals(portp, ((i & TIOCM_DTR) ? 1 : -1),
1471 ((i & TIOCM_RTS) ? 1 : -1));
1474 i = *((int *) data);
1475 stl_setsignals(portp, ((i & TIOCM_DTR) ? 0 : -1),
1476 ((i & TIOCM_RTS) ? 0 : -1));
1479 *((int *) data) = (stl_getsignals(portp) | TIOCM_LE);
1482 if ((error = suser(td)) == 0)
1483 portp->dtrwait = *((int *) data) * hz / 100;
1486 *((int *) data) = portp->dtrwait * 100 / hz;
1489 portp->dotimestamp = 1;
1490 *((struct timeval *) data) = portp->timestamp;
1500 /*****************************************************************************/
1503 * Convert the specified minor device number into a port struct
1504 * pointer. Return NULL if the device number is not a valid port.
1507 STATIC stlport_t *stl_dev2port(dev_t dev)
1511 brdp = stl_brds[MKDEV2BRD(dev)];
1512 if (brdp == (stlbrd_t *) NULL)
1513 return((stlport_t *) NULL);
1514 return(brdp->ports[MKDEV2PORT(dev)]);
1517 /*****************************************************************************/
1520 * Initialize the port hardware. This involves enabling the transmitter
1521 * and receiver, setting the port configuration, and setting the initial
1525 static int stl_rawopen(stlport_t *portp)
1528 printf("stl_rawopen(portp=%p): brdnr=%d panelnr=%d portnr=%d\n",
1529 (void *) portp, portp->brdnr, portp->panelnr, portp->portnr);
1532 stl_setport(portp, &portp->tty.t_termios);
1533 portp->sigs = stl_getsignals(portp);
1534 stl_setsignals(portp, 1, 1);
1535 stl_enablerxtx(portp, 1, 1);
1536 stl_startrxtx(portp, 1, 0);
1540 /*****************************************************************************/
1543 * Shutdown the hardware of a port. Disable its transmitter and
1544 * receiver, and maybe drop signals if appropriate.
1547 static int stl_rawclose(stlport_t *portp)
1552 printf("stl_rawclose(portp=%p): brdnr=%d panelnr=%d portnr=%d\n",
1553 (void *) portp, portp->brdnr, portp->panelnr, portp->portnr);
1557 stl_disableintrs(portp);
1558 stl_enablerxtx(portp, 0, 0);
1559 stl_flush(portp, (FWRITE | FREAD));
1560 if (tp->t_cflag & HUPCL) {
1561 stl_setsignals(portp, 0, 0);
1562 if (portp->dtrwait != 0) {
1563 portp->state |= ASY_DTRWAIT;
1564 callout_reset(&portp->dtr_ch, portp->dtrwait,
1565 stl_dtrwakeup, portp);
1570 portp->state &= ~(ASY_ACTIVE | ASY_RTSFLOW);
1571 wakeup(&portp->callout);
1572 wakeup(TSA_CARR_ON(tp));
1576 /*****************************************************************************/
1579 * Clear the DTR waiting flag, and wake up any sleepers waiting for
1580 * DTR wait period to finish.
1583 static void stl_dtrwakeup(void *arg)
1587 portp = (stlport_t *) arg;
1588 portp->state &= ~ASY_DTRWAIT;
1589 wakeup(&portp->dtrwait);
1592 /*****************************************************************************/
1595 * Start (or continue) the transfer of TX data on this port. If the
1596 * port is not currently busy then load up the interrupt ring queue
1597 * buffer and kick of the transmitter. If the port is running low on
1598 * TX data then refill the ring queue. This routine is also used to
1599 * activate input flow control!
1602 static void stl_start(struct tty *tp)
1605 unsigned int len, stlen;
1609 portp = (stlport_t *) tp;
1612 printf("stl_start(tp=%x): brdnr=%d portnr=%d\n", (int) tp,
1613 portp->brdnr, portp->portnr);
1619 * Check if the ports input has been blocked, and take appropriate action.
1620 * Not very often do we really need to do anything, so make it quick.
1622 if (tp->t_state & TS_TBLOCK) {
1623 if ((portp->state & ASY_RTSFLOWMODE) &&
1624 ((portp->state & ASY_RTSFLOW) == 0))
1625 stl_flowcontrol(portp, 0, -1);
1627 if (portp->state & ASY_RTSFLOW)
1628 stl_flowcontrol(portp, 1, -1);
1633 * Check if the output cooked clist buffers are near empty, wake up
1634 * the line discipline to fill it up.
1636 if (tp->t_outq.c_cc <= tp->t_lowat) {
1637 if (tp->t_state & TS_ASLEEP) {
1638 tp->t_state &= ~TS_ASLEEP;
1639 wakeup(&tp->t_outq);
1641 selwakeup(&tp->t_wsel);
1645 if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
1651 * Copy data from the clists into the interrupt ring queue. This will
1652 * require at most 2 copys... What we do is calculate how many chars
1653 * can fit into the ring queue, and how many can fit in 1 copy. If after
1654 * the first copy there is still more room then do the second copy.
1655 * The beauty of this type of ring queue is that we do not need to
1656 * spl protect our-selves, since we only ever update the head pointer,
1657 * and the interrupt routine only ever updates the tail pointer.
1659 if (tp->t_outq.c_cc != 0) {
1660 head = portp->tx.head;
1661 tail = portp->tx.tail;
1663 len = STL_TXBUFSIZE - (head - tail) - 1;
1664 stlen = portp->tx.endbuf - head;
1666 len = tail - head - 1;
1671 stlen = MIN(len, stlen);
1672 count = q_to_b(&tp->t_outq, head, stlen);
1675 if (head >= portp->tx.endbuf) {
1676 head = portp->tx.buf;
1678 stlen = q_to_b(&tp->t_outq, head, len);
1683 portp->tx.head = head;
1685 stl_startrxtx(portp, -1, 1);
1689 * If we sent something, make sure we are called again.
1691 tp->t_state |= TS_BUSY;
1696 * Do any writer wakeups.
1704 /*****************************************************************************/
1706 static void stl_flush(stlport_t *portp, int flag)
1712 printf("stl_flush(portp=%x,flag=%x)\n", (int) portp, flag);
1715 if (portp == (stlport_t *) NULL)
1720 if (flag & FWRITE) {
1721 stl_uartflush(portp, FWRITE);
1722 portp->tx.tail = portp->tx.head;
1726 * The only thing to watch out for when flushing the read side is
1727 * the RX status buffer. The interrupt code relys on the status
1728 * bytes as being zeroed all the time (it does not bother setting
1729 * a good char status to 0, it expects that it already will be).
1730 * We also need to un-flow the RX channel if flow control was
1734 head = portp->rx.head;
1735 tail = portp->rx.tail;
1740 len = portp->rx.endbuf - tail;
1741 bzero(portp->rxstatus.buf,
1742 (head - portp->rx.buf));
1744 bzero((tail + STL_RXBUFSIZE), len);
1745 portp->rx.tail = head;
1748 if ((portp->state & ASY_RTSFLOW) &&
1749 ((portp->tty.t_state & TS_TBLOCK) == 0))
1750 stl_flowcontrol(portp, 1, -1);
1756 /*****************************************************************************/
1759 * Interrupt handler for host based boards. Interrupts for all boards
1760 * are vectored through here.
1763 void stlintr(int unit)
1769 printf("stlintr(unit=%d)\n", unit);
1772 for (i = 0; (i < stl_nrbrds); i++) {
1773 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
1775 if (brdp->state == 0)
1777 (* brdp->isr)(brdp);
1781 /*****************************************************************************/
1785 static void stlpciintr(void *arg)
1792 /*****************************************************************************/
1795 * Interrupt service routine for EasyIO boards.
1798 static void stl_eiointr(stlbrd_t *brdp)
1804 printf("stl_eiointr(brdp=%p)\n", brdp);
1807 panelp = (stlpanel_t *) brdp->panels[0];
1808 iobase = panelp->iobase;
1809 while (inb(brdp->iostatus) & EIO_INTRPEND)
1810 (* panelp->isr)(panelp, iobase);
1814 * Interrupt service routine for ECH-AT board types.
1817 static void stl_echatintr(stlbrd_t *brdp)
1820 unsigned int ioaddr;
1823 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDENABLE));
1825 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1826 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1827 ioaddr = brdp->bnkstataddr[bnknr];
1828 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1829 panelp = brdp->bnk2panel[bnknr];
1830 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1835 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDDISABLE));
1838 /*****************************************************************************/
1841 * Interrupt service routine for ECH-MCA board types.
1844 static void stl_echmcaintr(stlbrd_t *brdp)
1847 unsigned int ioaddr;
1850 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1851 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1852 ioaddr = brdp->bnkstataddr[bnknr];
1853 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1854 panelp = brdp->bnk2panel[bnknr];
1855 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1861 /*****************************************************************************/
1864 * Interrupt service routine for ECH-PCI board types.
1867 static void stl_echpciintr(stlbrd_t *brdp)
1870 unsigned int ioaddr;
1874 printf("stl_echpciintr(brdp=%x)\n", (int) brdp);
1879 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1880 outb(brdp->ioctrl, brdp->bnkpageaddr[bnknr]);
1881 ioaddr = brdp->bnkstataddr[bnknr];
1882 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1883 panelp = brdp->bnk2panel[bnknr];
1884 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1893 /*****************************************************************************/
1896 * Interrupt service routine for EC8/64-PCI board types.
1899 static void stl_echpci64intr(stlbrd_t *brdp)
1902 unsigned int ioaddr;
1906 printf("stl_echpci64intr(brdp=%p)\n", brdp);
1909 while (inb(brdp->ioctrl) & 0x1) {
1910 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1911 ioaddr = brdp->bnkstataddr[bnknr];
1913 printf(" --> ioaddr=%x status=%x(%x)\n", ioaddr, inb(ioaddr) & ECH_PNLINTRPEND, inb(ioaddr));
1915 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1916 panelp = brdp->bnk2panel[bnknr];
1917 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1923 /*****************************************************************************/
1926 * If we haven't scheduled a timeout then do it, some port needs high
1930 static void stl_dotimeout()
1933 printf("stl_dotimeout()\n");
1935 if (stl_doingtimeout == 0) {
1936 if ((stl_poll_ch.c_flags & CALLOUT_DID_INIT) == 0)
1937 callout_init(&stl_poll_ch);
1938 callout_reset(&stl_poll_ch, 1, stl_poll, NULL);
1943 /*****************************************************************************/
1946 * Service "software" level processing. Too slow or painfull to be done
1947 * at real hardware interrupt time. This way we might also be able to
1948 * do some service on other waiting ports as well...
1951 static void stl_poll(void *arg)
1956 int brdnr, portnr, rearm;
1959 printf("stl_poll()\n");
1962 stl_doingtimeout = 0;
1966 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1967 if ((brdp = stl_brds[brdnr]) == (stlbrd_t *) NULL)
1969 for (portnr = 0; (portnr < brdp->nrports); portnr++) {
1970 if ((portp = brdp->ports[portnr]) == (stlport_t *) NULL)
1972 if ((portp->state & ASY_ACTIVE) == 0)
1976 if (portp->state & ASY_RXDATA)
1977 stl_rxprocess(portp);
1978 if (portp->state & ASY_DCDCHANGE) {
1979 portp->state &= ~ASY_DCDCHANGE;
1980 portp->sigs = stl_getsignals(portp);
1981 (*linesw[tp->t_line].l_modem)(tp,
1982 (portp->sigs & TIOCM_CD));
1984 if (portp->state & ASY_TXEMPTY) {
1985 if (stl_datastate(portp) == 0) {
1986 portp->state &= ~ASY_TXEMPTY;
1987 tp->t_state &= ~TS_BUSY;
1988 (*linesw[tp->t_line].l_start)(tp);
1991 if (portp->state & ASY_TXLOW) {
1992 portp->state &= ~ASY_TXLOW;
1993 (*linesw[tp->t_line].l_start)(tp);
1996 if (portp->state & ASY_ACTIVE)
2006 /*****************************************************************************/
2009 * Process the RX data that has been buffered up in the RX ring queue.
2012 static void stl_rxprocess(stlport_t *portp)
2015 unsigned int len, stlen, lostlen;
2021 printf("stl_rxprocess(portp=%x): brdnr=%d portnr=%d\n", (int) portp,
2022 portp->brdnr, portp->portnr);
2026 portp->state &= ~ASY_RXDATA;
2028 if ((tp->t_state & TS_ISOPEN) == 0) {
2029 stl_flush(portp, FREAD);
2034 * Calculate the amount of data in the RX ring queue. Also calculate
2035 * the largest single copy size...
2037 head = portp->rx.head;
2038 tail = portp->rx.tail;
2043 len = STL_RXBUFSIZE - (tail - head);
2044 stlen = portp->rx.endbuf - tail;
2047 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
2049 if (((tp->t_rawq.c_cc + len) >= TTYHOG) &&
2050 ((portp->state & ASY_RTSFLOWMODE) ||
2051 (tp->t_iflag & IXOFF)) &&
2052 ((tp->t_state & TS_TBLOCK) == 0)) {
2053 ch = TTYHOG - tp->t_rawq.c_cc - 1;
2054 len = (ch > 0) ? ch : 0;
2055 stlen = MIN(stlen, len);
2058 lostlen = b_to_q(tail, stlen, &tp->t_rawq);
2061 if (tail >= portp->rx.endbuf) {
2062 tail = portp->rx.buf;
2063 lostlen += b_to_q(tail, len, &tp->t_rawq);
2066 portp->stats.rxlost += lostlen;
2068 portp->rx.tail = tail;
2071 while (portp->rx.tail != head) {
2072 ch = (unsigned char) *(portp->rx.tail);
2073 status = *(portp->rx.tail + STL_RXBUFSIZE);
2075 *(portp->rx.tail + STL_RXBUFSIZE) = 0;
2076 if (status & ST_BREAK)
2078 if (status & ST_FRAMING)
2080 if (status & ST_PARITY)
2082 if (status & ST_OVERRUN)
2085 (*linesw[tp->t_line].l_rint)(ch, tp);
2086 if (portp->rx.tail == head)
2089 if (++(portp->rx.tail) >= portp->rx.endbuf)
2090 portp->rx.tail = portp->rx.buf;
2094 if (head != portp->rx.tail)
2095 portp->state |= ASY_RXDATA;
2098 * If we were flow controled then maybe the buffer is low enough that
2099 * we can re-activate it.
2101 if ((portp->state & ASY_RTSFLOW) && ((tp->t_state & TS_TBLOCK) == 0))
2102 stl_flowcontrol(portp, 1, -1);
2105 /*****************************************************************************/
2107 static int stl_param(struct tty *tp, struct termios *tiosp)
2111 portp = (stlport_t *) tp;
2112 if (portp == (stlport_t *) NULL)
2115 return(stl_setport(portp, tiosp));
2118 /*****************************************************************************/
2121 * Action the flow control as required. The hw and sw args inform the
2122 * routine what flow control methods it should try.
2125 static void stl_flowcontrol(stlport_t *portp, int hw, int sw)
2127 unsigned char *head, *tail;
2131 printf("stl_flowcontrol(portp=%x,hw=%d,sw=%d)\n", (int) portp, hw, sw);
2136 if (portp->state & ASY_RTSFLOWMODE) {
2138 if ((portp->state & ASY_RTSFLOW) == 0)
2140 } else if (hw > 0) {
2141 if (portp->state & ASY_RTSFLOW) {
2142 head = portp->rx.head;
2143 tail = portp->rx.tail;
2144 len = (head >= tail) ? (head - tail) :
2145 (STL_RXBUFSIZE - (tail - head));
2146 if (len < STL_RXBUFHIGH)
2153 * We have worked out what to do, if anything. So now apply it to the
2156 stl_sendflow(portp, hwflow, sw);
2159 /*****************************************************************************/
2162 * Enable l_rint processing bypass mode if tty modes allow it.
2165 static void stl_ttyoptim(stlport_t *portp, struct termios *tiosp)
2170 if (((tiosp->c_iflag &
2171 (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP)) == 0) &&
2172 (((tiosp->c_iflag & BRKINT) == 0) || (tiosp->c_iflag & IGNBRK)) &&
2173 (((tiosp->c_iflag & PARMRK) == 0) ||
2174 ((tiosp->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))) &&
2175 ((tiosp->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN)) ==0) &&
2176 (linesw[tp->t_line].l_rint == ttyinput))
2177 tp->t_state |= TS_CAN_BYPASS_L_RINT;
2179 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
2180 portp->hotchar = linesw[tp->t_line].l_hotchar;
2183 /*****************************************************************************/
2186 * Try and find and initialize all the ports on a panel. We don't care
2187 * what sort of board these ports are on - since the port io registers
2188 * are almost identical when dealing with ports.
2191 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2194 unsigned int chipmask;
2198 printf("stl_initports(panelp=%x)\n", (int) panelp);
2201 chipmask = stl_panelinit(brdp, panelp);
2204 * All UART's are initialized if found. Now go through and setup
2205 * each ports data structures. Also initialize each individual
2208 for (i = 0; (i < panelp->nrports); i++) {
2209 portp = malloc(sizeof(stlport_t), M_TTYS, M_WAITOK | M_ZERO);
2212 portp->brdnr = panelp->brdnr;
2213 portp->panelnr = panelp->panelnr;
2214 portp->uartp = panelp->uartp;
2215 portp->clk = brdp->clk;
2216 panelp->ports[i] = portp;
2218 j = STL_TXBUFSIZE + (2 * STL_RXBUFSIZE);
2219 portp->tx.buf = malloc(j, M_TTYS, M_WAITOK);
2220 portp->tx.endbuf = portp->tx.buf + STL_TXBUFSIZE;
2221 portp->tx.head = portp->tx.buf;
2222 portp->tx.tail = portp->tx.buf;
2223 portp->rx.buf = portp->tx.buf + STL_TXBUFSIZE;
2224 portp->rx.endbuf = portp->rx.buf + STL_RXBUFSIZE;
2225 portp->rx.head = portp->rx.buf;
2226 portp->rx.tail = portp->rx.buf;
2227 portp->rxstatus.buf = portp->rx.buf + STL_RXBUFSIZE;
2228 portp->rxstatus.endbuf = portp->rxstatus.buf + STL_RXBUFSIZE;
2229 portp->rxstatus.head = portp->rxstatus.buf;
2230 portp->rxstatus.tail = portp->rxstatus.buf;
2231 bzero(portp->rxstatus.head, STL_RXBUFSIZE);
2233 portp->initintios.c_ispeed = STL_DEFSPEED;
2234 portp->initintios.c_ospeed = STL_DEFSPEED;
2235 portp->initintios.c_cflag = STL_DEFCFLAG;
2236 portp->initintios.c_iflag = 0;
2237 portp->initintios.c_oflag = 0;
2238 portp->initintios.c_lflag = 0;
2239 bcopy(&ttydefchars[0], &portp->initintios.c_cc[0],
2240 sizeof(portp->initintios.c_cc));
2241 portp->initouttios = portp->initintios;
2242 portp->dtrwait = 3 * hz;
2243 callout_init(&portp->dtr_ch);
2245 stl_portinit(brdp, panelp, portp);
2251 /*****************************************************************************/
2254 * Try to find and initialize an EasyIO board.
2257 static int stl_initeio(stlbrd_t *brdp)
2260 unsigned int status;
2263 printf("stl_initeio(brdp=%x)\n", (int) brdp);
2266 brdp->ioctrl = brdp->ioaddr1 + 1;
2267 brdp->iostatus = brdp->ioaddr1 + 2;
2268 brdp->clk = EIO_CLK;
2269 brdp->isr = stl_eiointr;
2271 status = inb(brdp->iostatus);
2272 switch (status & EIO_IDBITMASK) {
2274 brdp->clk = EIO_CLK8M;
2284 switch (status & EIO_BRDMASK) {
2303 if (brdp->brdtype == BRD_EASYIOPCI) {
2304 outb((brdp->ioaddr2 + 0x4c), 0x41);
2307 * Check that the supplied IRQ is good and then use it to setup the
2308 * programmable interrupt bits on EIO board. Also set the edge/level
2309 * triggered interrupt bit.
2311 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2312 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2313 printf("STALLION: invalid irq=%d for brd=%d\n",
2314 brdp->irq, brdp->brdnr);
2317 outb(brdp->ioctrl, (stl_vecmap[brdp->irq] |
2318 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)));
2321 panelp = malloc(sizeof(stlpanel_t), M_TTYS, M_WAITOK | M_ZERO);
2322 panelp->brdnr = brdp->brdnr;
2323 panelp->panelnr = 0;
2324 panelp->nrports = brdp->nrports;
2325 panelp->iobase = brdp->ioaddr1;
2326 panelp->hwid = status;
2327 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2328 panelp->uartp = (void *) &stl_sc26198uart;
2329 panelp->isr = stl_sc26198intr;
2331 panelp->uartp = (void *) &stl_cd1400uart;
2332 panelp->isr = stl_cd1400eiointr;
2334 brdp->panels[0] = panelp;
2336 brdp->hwid = status;
2337 brdp->state |= BRD_FOUND;
2341 /*****************************************************************************/
2344 * Try to find an ECH board and initialize it. This code is capable of
2345 * dealing with all types of ECH board.
2348 static int stl_initech(stlbrd_t *brdp)
2351 unsigned int status, nxtid;
2352 int panelnr, ioaddr, banknr, i;
2355 printf("stl_initech(brdp=%x)\n", (int) brdp);
2359 * Set up the initial board register contents for boards. This varys a
2360 * bit between the different board types. So we need to handle each
2361 * separately. Also do a check that the supplied IRQ is good.
2363 switch (brdp->brdtype) {
2366 brdp->isr = stl_echatintr;
2367 brdp->ioctrl = brdp->ioaddr1 + 1;
2368 brdp->iostatus = brdp->ioaddr1 + 1;
2369 status = inb(brdp->iostatus);
2370 if ((status & ECH_IDBITMASK) != ECH_ID)
2372 brdp->hwid = status;
2374 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2375 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2376 printf("STALLION: invalid irq=%d for brd=%d\n",
2377 brdp->irq, brdp->brdnr);
2380 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2381 status |= (stl_vecmap[brdp->irq] << 1);
2382 outb(brdp->ioaddr1, (status | ECH_BRDRESET));
2383 brdp->ioctrlval = ECH_INTENABLE |
2384 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2385 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDENABLE));
2386 outb(brdp->ioaddr1, status);
2390 brdp->isr = stl_echmcaintr;
2391 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2392 brdp->iostatus = brdp->ioctrl;
2393 status = inb(brdp->iostatus);
2394 if ((status & ECH_IDBITMASK) != ECH_ID)
2396 brdp->hwid = status;
2398 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2399 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2400 printf("STALLION: invalid irq=%d for brd=%d\n",
2401 brdp->irq, brdp->brdnr);
2404 outb(brdp->ioctrl, ECHMC_BRDRESET);
2405 outb(brdp->ioctrl, ECHMC_INTENABLE);
2409 brdp->isr = stl_echpciintr;
2410 brdp->ioctrl = brdp->ioaddr1 + 2;
2414 brdp->isr = stl_echpci64intr;
2415 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2416 outb((brdp->ioaddr1 + 0x4c), 0x43);
2420 printf("STALLION: unknown board type=%d\n", brdp->brdtype);
2424 brdp->clk = ECH_CLK;
2427 * Scan through the secondary io address space looking for panels.
2428 * As we find'em allocate and initialize panel structures for each.
2430 ioaddr = brdp->ioaddr2;
2435 for (i = 0; (i < STL_MAXPANELS); i++) {
2436 if (brdp->brdtype == BRD_ECHPCI) {
2437 outb(brdp->ioctrl, nxtid);
2438 ioaddr = brdp->ioaddr2;
2440 status = inb(ioaddr + ECH_PNLSTATUS);
2441 if ((status & ECH_PNLIDMASK) != nxtid)
2443 panelp = malloc(sizeof(stlpanel_t), M_TTYS, M_WAITOK | M_ZERO);
2444 panelp->brdnr = brdp->brdnr;
2445 panelp->panelnr = panelnr;
2446 panelp->iobase = ioaddr;
2447 panelp->pagenr = nxtid;
2448 panelp->hwid = status;
2449 brdp->bnk2panel[banknr] = panelp;
2450 brdp->bnkpageaddr[banknr] = nxtid;
2451 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2453 if (status & ECH_PNLXPID) {
2454 panelp->uartp = (void *) &stl_sc26198uart;
2455 panelp->isr = stl_sc26198intr;
2456 if (status & ECH_PNL16PORT) {
2457 panelp->nrports = 16;
2458 brdp->bnk2panel[banknr] = panelp;
2459 brdp->bnkpageaddr[banknr] = nxtid;
2460 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2463 panelp->nrports = 8;
2466 panelp->uartp = (void *) &stl_cd1400uart;
2467 panelp->isr = stl_cd1400echintr;
2468 if (status & ECH_PNL16PORT) {
2469 panelp->nrports = 16;
2470 panelp->ackmask = 0x80;
2471 if (brdp->brdtype != BRD_ECHPCI)
2472 ioaddr += EREG_BANKSIZE;
2473 brdp->bnk2panel[banknr] = panelp;
2474 brdp->bnkpageaddr[banknr] = ++nxtid;
2475 brdp->bnkstataddr[banknr++] = ioaddr +
2478 panelp->nrports = 8;
2479 panelp->ackmask = 0xc0;
2484 ioaddr += EREG_BANKSIZE;
2485 brdp->nrports += panelp->nrports;
2486 brdp->panels[panelnr++] = panelp;
2487 if ((brdp->brdtype == BRD_ECH) || (brdp->brdtype == BRD_ECHMC)){
2488 if (ioaddr >= (brdp->ioaddr2 + 0x20)) {
2489 printf("STALLION: too many ports attached "
2490 "to board %d, remove last module\n",
2497 brdp->nrpanels = panelnr;
2498 brdp->nrbnks = banknr;
2499 if (brdp->brdtype == BRD_ECH)
2500 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDDISABLE));
2502 brdp->state |= BRD_FOUND;
2506 /*****************************************************************************/
2509 * Initialize and configure the specified board. This firstly probes
2510 * for the board, if it is found then the board is initialized and
2511 * then all its ports are initialized as well.
2514 static int stl_brdinit(stlbrd_t *brdp)
2520 printf("stl_brdinit(brdp=%x): unit=%d type=%d io1=%x io2=%x irq=%d\n",
2521 (int) brdp, brdp->brdnr, brdp->brdtype, brdp->ioaddr1,
2522 brdp->ioaddr2, brdp->irq);
2525 switch (brdp->brdtype) {
2537 printf("STALLION: unit=%d is unknown board type=%d\n",
2538 brdp->brdnr, brdp->brdtype);
2542 stl_brds[brdp->brdnr] = brdp;
2543 if ((brdp->state & BRD_FOUND) == 0) {
2545 printf("STALLION: %s board not found, unit=%d io=%x irq=%d\n",
2546 stl_brdnames[brdp->brdtype], brdp->brdnr,
2547 brdp->ioaddr1, brdp->irq);
2552 for (i = 0, k = 0; (i < STL_MAXPANELS); i++) {
2553 panelp = brdp->panels[i];
2554 if (panelp != (stlpanel_t *) NULL) {
2555 stl_initports(brdp, panelp);
2556 for (j = 0; (j < panelp->nrports); j++)
2557 brdp->ports[k++] = panelp->ports[j];
2561 printf("stl%d: %s (driver version %s) unit=%d nrpanels=%d nrports=%d\n",
2562 brdp->unitid, stl_brdnames[brdp->brdtype], stl_drvversion,
2563 brdp->brdnr, brdp->nrpanels, brdp->nrports);
2567 /*****************************************************************************/
2570 * Return the board stats structure to user app.
2573 static int stl_getbrdstats(caddr_t data)
2579 stl_brdstats = *((combrd_t *) data);
2580 if (stl_brdstats.brd >= STL_MAXBRDS)
2582 brdp = stl_brds[stl_brdstats.brd];
2583 if (brdp == (stlbrd_t *) NULL)
2586 bzero(&stl_brdstats, sizeof(combrd_t));
2587 stl_brdstats.brd = brdp->brdnr;
2588 stl_brdstats.type = brdp->brdtype;
2589 stl_brdstats.hwid = brdp->hwid;
2590 stl_brdstats.state = brdp->state;
2591 stl_brdstats.ioaddr = brdp->ioaddr1;
2592 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2593 stl_brdstats.irq = brdp->irq;
2594 stl_brdstats.nrpanels = brdp->nrpanels;
2595 stl_brdstats.nrports = brdp->nrports;
2596 for (i = 0; (i < brdp->nrpanels); i++) {
2597 panelp = brdp->panels[i];
2598 stl_brdstats.panels[i].panel = i;
2599 stl_brdstats.panels[i].hwid = panelp->hwid;
2600 stl_brdstats.panels[i].nrports = panelp->nrports;
2603 *((combrd_t *) data) = stl_brdstats;;
2607 /*****************************************************************************/
2610 * Resolve the referenced port number into a port struct pointer.
2613 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2618 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2619 return((stlport_t *) NULL);
2620 brdp = stl_brds[brdnr];
2621 if (brdp == (stlbrd_t *) NULL)
2622 return((stlport_t *) NULL);
2623 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2624 return((stlport_t *) NULL);
2625 panelp = brdp->panels[panelnr];
2626 if (panelp == (stlpanel_t *) NULL)
2627 return((stlport_t *) NULL);
2628 if ((portnr < 0) || (portnr >= panelp->nrports))
2629 return((stlport_t *) NULL);
2630 return(panelp->ports[portnr]);
2633 /*****************************************************************************/
2636 * Return the port stats structure to user app. A NULL port struct
2637 * pointer passed in means that we need to find out from the app
2638 * what port to get stats for (used through board control device).
2641 static int stl_getportstats(stlport_t *portp, caddr_t data)
2643 unsigned char *head, *tail;
2645 if (portp == (stlport_t *) NULL) {
2646 stl_comstats = *((comstats_t *) data);
2647 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2649 if (portp == (stlport_t *) NULL)
2653 portp->stats.state = portp->state;
2654 /*portp->stats.flags = portp->flags;*/
2655 portp->stats.hwid = portp->hwid;
2656 portp->stats.ttystate = portp->tty.t_state;
2657 portp->stats.cflags = portp->tty.t_cflag;
2658 portp->stats.iflags = portp->tty.t_iflag;
2659 portp->stats.oflags = portp->tty.t_oflag;
2660 portp->stats.lflags = portp->tty.t_lflag;
2662 head = portp->tx.head;
2663 tail = portp->tx.tail;
2664 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2665 (STL_TXBUFSIZE - (tail - head)));
2667 head = portp->rx.head;
2668 tail = portp->rx.tail;
2669 portp->stats.rxbuffered = (head >= tail) ? (head - tail) :
2670 (STL_RXBUFSIZE - (tail - head));
2672 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2674 *((comstats_t *) data) = portp->stats;
2678 /*****************************************************************************/
2681 * Clear the port stats structure. We also return it zeroed out...
2684 static int stl_clrportstats(stlport_t *portp, caddr_t data)
2686 if (portp == (stlport_t *) NULL) {
2687 stl_comstats = *((comstats_t *) data);
2688 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2690 if (portp == (stlport_t *) NULL)
2694 bzero(&portp->stats, sizeof(comstats_t));
2695 portp->stats.brd = portp->brdnr;
2696 portp->stats.panel = portp->panelnr;
2697 portp->stats.port = portp->portnr;
2698 *((comstats_t *) data) = stl_comstats;
2702 /*****************************************************************************/
2705 * The "staliomem" device is used for stats collection in this driver.
2708 static int stl_memioctl(dev_t dev, unsigned long cmd, caddr_t data, int flag,
2714 printf("stl_memioctl(dev=%s,cmd=%lx,data=%p,flag=%x)\n",
2715 devtoname(dev), cmd, (void *) data, flag);
2721 case COM_GETPORTSTATS:
2722 rc = stl_getportstats((stlport_t *) NULL, data);
2724 case COM_CLRPORTSTATS:
2725 rc = stl_clrportstats((stlport_t *) NULL, data);
2727 case COM_GETBRDSTATS:
2728 rc = stl_getbrdstats(data);
2738 /*****************************************************************************/
2740 /*****************************************************************************/
2741 /* CD1400 UART CODE */
2742 /*****************************************************************************/
2745 * These functions get/set/update the registers of the cd1400 UARTs.
2746 * Access to the cd1400 registers is via an address/data io port pair.
2749 static int stl_cd1400getreg(stlport_t *portp, int regnr)
2751 outb(portp->ioaddr, (regnr + portp->uartaddr));
2752 return(inb(portp->ioaddr + EREG_DATA));
2755 /*****************************************************************************/
2757 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
2759 outb(portp->ioaddr, (regnr + portp->uartaddr));
2760 outb((portp->ioaddr + EREG_DATA), value);
2763 /*****************************************************************************/
2765 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
2767 outb(portp->ioaddr, (regnr + portp->uartaddr));
2768 if (inb(portp->ioaddr + EREG_DATA) != value) {
2769 outb((portp->ioaddr + EREG_DATA), value);
2775 /*****************************************************************************/
2777 static void stl_cd1400flush(stlport_t *portp, int flag)
2781 printf("stl_cd1400flush(portp=%x,flag=%x)\n", (int) portp, flag);
2784 if (portp == (stlport_t *) NULL)
2789 if (flag & FWRITE) {
2790 BRDENABLE(portp->brdnr, portp->pagenr);
2791 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2792 stl_cd1400ccrwait(portp);
2793 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
2794 stl_cd1400ccrwait(portp);
2795 BRDDISABLE(portp->brdnr);
2805 /*****************************************************************************/
2807 static void stl_cd1400ccrwait(stlport_t *portp)
2811 for (i = 0; (i < CCR_MAXWAIT); i++) {
2812 if (stl_cd1400getreg(portp, CCR) == 0)
2816 printf("stl%d: cd1400 device not responding, panel=%d port=%d\n",
2817 portp->brdnr, portp->panelnr, portp->portnr);
2820 /*****************************************************************************/
2823 * Transmit interrupt handler. This has gotta be fast! Handling TX
2824 * chars is pretty simple, stuff as many as possible from the TX buffer
2825 * into the cd1400 FIFO. Must also handle TX breaks here, since they
2826 * are embedded as commands in the data stream. Oh no, had to use a goto!
2829 static __inline void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
2833 unsigned char ioack, srer;
2838 printf("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
2841 ioack = inb(ioaddr + EREG_TXACK);
2842 if (((ioack & panelp->ackmask) != 0) ||
2843 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
2844 printf("STALLION: bad TX interrupt ack value=%x\n",
2848 portp = panelp->ports[(ioack >> 3)];
2852 * Unfortunately we need to handle breaks in the data stream, since
2853 * this is the only way to generate them on the cd1400. Do it now if
2854 * a break is to be sent. Some special cases here: brklen is -1 then
2855 * start sending an un-timed break, if brklen is -2 then stop sending
2856 * an un-timed break, if brklen is -3 then we have just sent an
2857 * un-timed break and do not want any data to go out, if brklen is -4
2858 * then a break has just completed so clean up the port settings.
2860 if (portp->brklen != 0) {
2861 if (portp->brklen >= -1) {
2862 outb(ioaddr, (TDR + portp->uartaddr));
2863 outb((ioaddr + EREG_DATA), ETC_CMD);
2864 outb((ioaddr + EREG_DATA), ETC_STARTBREAK);
2865 if (portp->brklen > 0) {
2866 outb((ioaddr + EREG_DATA), ETC_CMD);
2867 outb((ioaddr + EREG_DATA), ETC_DELAY);
2868 outb((ioaddr + EREG_DATA), portp->brklen);
2869 outb((ioaddr + EREG_DATA), ETC_CMD);
2870 outb((ioaddr + EREG_DATA), ETC_STOPBREAK);
2875 } else if (portp->brklen == -2) {
2876 outb(ioaddr, (TDR + portp->uartaddr));
2877 outb((ioaddr + EREG_DATA), ETC_CMD);
2878 outb((ioaddr + EREG_DATA), ETC_STOPBREAK);
2880 } else if (portp->brklen == -3) {
2881 outb(ioaddr, (SRER + portp->uartaddr));
2882 srer = inb(ioaddr + EREG_DATA);
2883 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
2884 outb((ioaddr + EREG_DATA), srer);
2886 outb(ioaddr, (COR2 + portp->uartaddr));
2887 outb((ioaddr + EREG_DATA),
2888 (inb(ioaddr + EREG_DATA) & ~COR2_ETC));
2894 head = portp->tx.head;
2895 tail = portp->tx.tail;
2896 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
2897 if ((len == 0) || ((len < STL_TXBUFLOW) &&
2898 ((portp->state & ASY_TXLOW) == 0))) {
2899 portp->state |= ASY_TXLOW;
2904 outb(ioaddr, (SRER + portp->uartaddr));
2905 srer = inb(ioaddr + EREG_DATA);
2906 if (srer & SRER_TXDATA) {
2907 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
2909 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
2910 portp->state |= ASY_TXEMPTY;
2911 portp->state &= ~ASY_TXBUSY;
2913 outb((ioaddr + EREG_DATA), srer);
2915 len = MIN(len, CD1400_TXFIFOSIZE);
2916 portp->stats.txtotal += len;
2917 stlen = MIN(len, (portp->tx.endbuf - tail));
2918 outb(ioaddr, (TDR + portp->uartaddr));
2919 outsb((ioaddr + EREG_DATA), tail, stlen);
2922 if (tail >= portp->tx.endbuf)
2923 tail = portp->tx.buf;
2925 outsb((ioaddr + EREG_DATA), tail, len);
2928 portp->tx.tail = tail;
2932 outb(ioaddr, (EOSRR + portp->uartaddr));
2933 outb((ioaddr + EREG_DATA), 0);
2936 /*****************************************************************************/
2939 * Receive character interrupt handler. Determine if we have good chars
2940 * or bad chars and then process appropriately.
2943 static __inline void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
2947 unsigned int ioack, len, buflen, stlen;
2948 unsigned char status;
2953 printf("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
2956 ioack = inb(ioaddr + EREG_RXACK);
2957 if ((ioack & panelp->ackmask) != 0) {
2958 printf("STALLION: bad RX interrupt ack value=%x\n", ioack);
2961 portp = panelp->ports[(ioack >> 3)];
2965 * First up, calculate how much room there is in the RX ring queue.
2966 * We also want to keep track of the longest possible copy length,
2967 * this has to allow for the wrapping of the ring queue.
2969 head = portp->rx.head;
2970 tail = portp->rx.tail;
2972 buflen = STL_RXBUFSIZE - (head - tail) - 1;
2973 stlen = portp->rx.endbuf - head;
2975 buflen = tail - head - 1;
2980 * Check if the input buffer is near full. If so then we should take
2981 * some flow control action... It is very easy to do hardware and
2982 * software flow control from here since we have the port selected on
2985 if (buflen <= (STL_RXBUFSIZE - STL_RXBUFHIGH)) {
2986 if (((portp->state & ASY_RTSFLOW) == 0) &&
2987 (portp->state & ASY_RTSFLOWMODE)) {
2988 portp->state |= ASY_RTSFLOW;
2989 stl_cd1400setreg(portp, MCOR1,
2990 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
2991 stl_cd1400setreg(portp, MSVR2, 0);
2992 portp->stats.rxrtsoff++;
2997 * OK we are set, process good data... If the RX ring queue is full
2998 * just chuck the chars - don't leave them in the UART.
3000 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
3001 outb(ioaddr, (RDCR + portp->uartaddr));
3002 len = inb(ioaddr + EREG_DATA);
3004 outb(ioaddr, (RDSR + portp->uartaddr));
3005 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
3006 portp->stats.rxlost += len;
3007 portp->stats.rxtotal += len;
3009 len = MIN(len, buflen);
3010 portp->stats.rxtotal += len;
3011 stlen = MIN(len, stlen);
3013 outb(ioaddr, (RDSR + portp->uartaddr));
3014 insb((ioaddr + EREG_DATA), head, stlen);
3016 if (head >= portp->rx.endbuf) {
3017 head = portp->rx.buf;
3019 insb((ioaddr + EREG_DATA), head, len);
3024 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
3025 outb(ioaddr, (RDSR + portp->uartaddr));
3026 status = inb(ioaddr + EREG_DATA);
3027 ch = inb(ioaddr + EREG_DATA);
3028 if (status & ST_BREAK)
3029 portp->stats.rxbreaks++;
3030 if (status & ST_FRAMING)
3031 portp->stats.rxframing++;
3032 if (status & ST_PARITY)
3033 portp->stats.rxparity++;
3034 if (status & ST_OVERRUN)
3035 portp->stats.rxoverrun++;
3036 if (status & ST_SCHARMASK) {
3037 if ((status & ST_SCHARMASK) == ST_SCHAR1)
3038 portp->stats.txxon++;
3039 if ((status & ST_SCHARMASK) == ST_SCHAR2)
3040 portp->stats.txxoff++;
3043 if ((portp->rxignoremsk & status) == 0) {
3044 if ((tp->t_state & TS_CAN_BYPASS_L_RINT) &&
3045 ((status & ST_FRAMING) ||
3046 ((status & ST_PARITY) && (tp->t_iflag & INPCK))))
3048 if ((portp->rxmarkmsk & status) == 0)
3050 *(head + STL_RXBUFSIZE) = status;
3052 if (head >= portp->rx.endbuf)
3053 head = portp->rx.buf;
3056 printf("STALLION: bad RX interrupt ack value=%x\n", ioack);
3060 portp->rx.head = head;
3061 portp->state |= ASY_RXDATA;
3065 outb(ioaddr, (EOSRR + portp->uartaddr));
3066 outb((ioaddr + EREG_DATA), 0);
3069 /*****************************************************************************/
3072 * Modem interrupt handler. The is called when the modem signal line
3073 * (DCD) has changed state.
3076 static __inline void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
3083 printf("stl_cd1400mdmisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
3086 ioack = inb(ioaddr + EREG_MDACK);
3087 if (((ioack & panelp->ackmask) != 0) ||
3088 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
3089 printf("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
3092 portp = panelp->ports[(ioack >> 3)];
3094 outb(ioaddr, (MISR + portp->uartaddr));
3095 misr = inb(ioaddr + EREG_DATA);
3096 if (misr & MISR_DCD) {
3097 portp->state |= ASY_DCDCHANGE;
3098 portp->stats.modem++;
3102 outb(ioaddr, (EOSRR + portp->uartaddr));
3103 outb((ioaddr + EREG_DATA), 0);
3106 /*****************************************************************************/
3109 * Interrupt service routine for cd1400 EasyIO boards.
3112 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3114 unsigned char svrtype;
3117 printf("stl_cd1400eiointr(panelp=%x,iobase=%x)\n", (int) panelp,
3122 svrtype = inb(iobase + EREG_DATA);
3123 if (panelp->nrports > 4) {
3124 outb(iobase, (SVRR + 0x80));
3125 svrtype |= inb(iobase + EREG_DATA);
3128 printf("stl_cd1400eiointr(panelp=%x,iobase=%x): svrr=%x\n", (int) panelp, iobase, svrtype);
3131 if (svrtype & SVRR_RX)
3132 stl_cd1400rxisr(panelp, iobase);
3133 else if (svrtype & SVRR_TX)
3134 stl_cd1400txisr(panelp, iobase);
3135 else if (svrtype & SVRR_MDM)
3136 stl_cd1400mdmisr(panelp, iobase);
3139 /*****************************************************************************/
3142 * Interrupt service routine for cd1400 panels.
3145 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
3147 unsigned char svrtype;
3150 printf("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
3155 svrtype = inb(iobase + EREG_DATA);
3156 outb(iobase, (SVRR + 0x80));
3157 svrtype |= inb(iobase + EREG_DATA);
3158 if (svrtype & SVRR_RX)
3159 stl_cd1400rxisr(panelp, iobase);
3160 else if (svrtype & SVRR_TX)
3161 stl_cd1400txisr(panelp, iobase);
3162 else if (svrtype & SVRR_MDM)
3163 stl_cd1400mdmisr(panelp, iobase);
3166 /*****************************************************************************/
3169 * Set up the cd1400 registers for a port based on the termios port
3173 static int stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3175 unsigned int clkdiv;
3176 unsigned char cor1, cor2, cor3;
3177 unsigned char cor4, cor5, ccr;
3178 unsigned char srer, sreron, sreroff;
3179 unsigned char mcor1, mcor2, rtpr;
3180 unsigned char clk, div;
3183 printf("stl_cd1400setport(portp=%x,tiosp=%x): brdnr=%d portnr=%d\n",
3184 (int) portp, (int) tiosp, portp->brdnr, portp->portnr);
3202 * Set up the RX char ignore mask with those RX error types we
3203 * can ignore. We could have used some special modes of the cd1400
3204 * UART to help, but it is better this way because we can keep stats
3205 * on the number of each type of RX exception event.
3207 portp->rxignoremsk = 0;
3208 if (tiosp->c_iflag & IGNPAR)
3209 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
3210 if (tiosp->c_iflag & IGNBRK)
3211 portp->rxignoremsk |= ST_BREAK;
3213 portp->rxmarkmsk = ST_OVERRUN;
3214 if (tiosp->c_iflag & (INPCK | PARMRK))
3215 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3216 if (tiosp->c_iflag & BRKINT)
3217 portp->rxmarkmsk |= ST_BREAK;
3220 * Go through the char size, parity and stop bits and set all the
3221 * option registers appropriately.
3223 switch (tiosp->c_cflag & CSIZE) {
3238 if (tiosp->c_cflag & CSTOPB)
3243 if (tiosp->c_cflag & PARENB) {
3244 if (tiosp->c_cflag & PARODD)
3245 cor1 |= (COR1_PARENB | COR1_PARODD);
3247 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3249 cor1 |= COR1_PARNONE;
3253 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3254 * space for hardware flow control and the like. This should be set to
3255 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3256 * really be based on VTIME...
3258 cor3 |= FIFO_RXTHRESHOLD;
3262 * Calculate the baud rate timers. For now we will just assume that
3263 * the input and output baud are the same. Could have used a baud
3264 * table here, but this way we can generate virtually any baud rate
3267 if (tiosp->c_ispeed == 0)
3268 tiosp->c_ispeed = tiosp->c_ospeed;
3269 if ((tiosp->c_ospeed < 0) || (tiosp->c_ospeed > CD1400_MAXBAUD))
3272 if (tiosp->c_ospeed > 0) {
3273 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3274 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) /
3279 div = (unsigned char) clkdiv;
3283 * Check what form of modem signaling is required and set it up.
3285 if ((tiosp->c_cflag & CLOCAL) == 0) {
3288 sreron |= SRER_MODEM;
3292 * Setup cd1400 enhanced modes if we can. In particular we want to
3293 * handle as much of the flow control as possbile automatically. As
3294 * well as saving a few CPU cycles it will also greatly improve flow
3295 * control reliablilty.
3297 if (tiosp->c_iflag & IXON) {
3300 if (tiosp->c_iflag & IXANY)
3304 if (tiosp->c_cflag & CCTS_OFLOW)
3306 if (tiosp->c_cflag & CRTS_IFLOW)
3307 mcor1 |= FIFO_RTSTHRESHOLD;
3310 * All cd1400 register values calculated so go through and set them
3314 printf("SETPORT: portnr=%d panelnr=%d brdnr=%d\n", portp->portnr,
3315 portp->panelnr, portp->brdnr);
3316 printf(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n", cor1, cor2,
3318 printf(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3319 mcor1, mcor2, rtpr, sreron, sreroff);
3320 printf(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3321 printf(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3322 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP], tiosp->c_cc[VSTART],
3323 tiosp->c_cc[VSTOP]);
3327 BRDENABLE(portp->brdnr, portp->pagenr);
3328 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3329 srer = stl_cd1400getreg(portp, SRER);
3330 stl_cd1400setreg(portp, SRER, 0);
3331 ccr += stl_cd1400updatereg(portp, COR1, cor1);
3332 ccr += stl_cd1400updatereg(portp, COR2, cor2);
3333 ccr += stl_cd1400updatereg(portp, COR3, cor3);
3335 stl_cd1400ccrwait(portp);
3336 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3338 stl_cd1400setreg(portp, COR4, cor4);
3339 stl_cd1400setreg(portp, COR5, cor5);
3340 stl_cd1400setreg(portp, MCOR1, mcor1);
3341 stl_cd1400setreg(portp, MCOR2, mcor2);
3342 if (tiosp->c_ospeed == 0) {
3343 stl_cd1400setreg(portp, MSVR1, 0);
3345 stl_cd1400setreg(portp, MSVR1, MSVR1_DTR);
3346 stl_cd1400setreg(portp, TCOR, clk);
3347 stl_cd1400setreg(portp, TBPR, div);
3348 stl_cd1400setreg(portp, RCOR, clk);
3349 stl_cd1400setreg(portp, RBPR, div);
3351 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3352 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3353 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3354 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3355 stl_cd1400setreg(portp, RTPR, rtpr);
3356 mcor1 = stl_cd1400getreg(portp, MSVR1);
3357 if (mcor1 & MSVR1_DCD)
3358 portp->sigs |= TIOCM_CD;
3360 portp->sigs &= ~TIOCM_CD;
3361 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3362 BRDDISABLE(portp->brdnr);
3363 portp->state &= ~(ASY_RTSFLOWMODE | ASY_CTSFLOWMODE);
3364 portp->state |= ((tiosp->c_cflag & CRTS_IFLOW) ? ASY_RTSFLOWMODE : 0);
3365 portp->state |= ((tiosp->c_cflag & CCTS_OFLOW) ? ASY_CTSFLOWMODE : 0);
3366 stl_ttyoptim(portp, tiosp);
3372 /*****************************************************************************/
3375 * Action the flow control as required. The hw and sw args inform the
3376 * routine what flow control methods it should try.
3379 static void stl_cd1400sendflow(stlport_t *portp, int hw, int sw)
3383 printf("stl_cd1400sendflow(portp=%x,hw=%d,sw=%d)\n",
3384 (int) portp, hw, sw);
3388 BRDENABLE(portp->brdnr, portp->pagenr);
3389 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3392 stl_cd1400ccrwait(portp);
3394 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3395 portp->stats.rxxoff++;
3397 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3398 portp->stats.rxxon++;
3400 stl_cd1400ccrwait(portp);
3404 portp->state |= ASY_RTSFLOW;
3405 stl_cd1400setreg(portp, MCOR1,
3406 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3407 stl_cd1400setreg(portp, MSVR2, 0);
3408 portp->stats.rxrtsoff++;
3409 } else if (hw > 0) {
3410 portp->state &= ~ASY_RTSFLOW;
3411 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3412 stl_cd1400setreg(portp, MCOR1,
3413 (stl_cd1400getreg(portp, MCOR1) | FIFO_RTSTHRESHOLD));
3414 portp->stats.rxrtson++;
3417 BRDDISABLE(portp->brdnr);
3421 /*****************************************************************************/
3424 * Return the current state of data flow on this port. This is only
3425 * really interresting when determining if data has fully completed
3426 * transmission or not... This is easy for the cd1400, it accurately
3427 * maintains the busy port flag.
3430 static int stl_cd1400datastate(stlport_t *portp)
3433 printf("stl_cd1400datastate(portp=%x)\n", (int) portp);
3436 if (portp == (stlport_t *) NULL)
3439 return((portp->state & ASY_TXBUSY) ? 1 : 0);
3442 /*****************************************************************************/
3445 * Set the state of the DTR and RTS signals. Got to do some extra
3446 * work here to deal hardware flow control.
3449 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3451 unsigned char msvr1, msvr2;
3454 printf("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n", (int) portp,
3466 BRDENABLE(portp->brdnr, portp->pagenr);
3467 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3469 if (portp->tty.t_cflag & CRTS_IFLOW) {
3471 stl_cd1400setreg(portp, MCOR1,
3472 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3473 portp->stats.rxrtsoff++;
3475 stl_cd1400setreg(portp, MCOR1,
3476 (stl_cd1400getreg(portp, MCOR1) |
3477 FIFO_RTSTHRESHOLD));
3478 portp->stats.rxrtson++;
3481 stl_cd1400setreg(portp, MSVR2, msvr2);
3484 stl_cd1400setreg(portp, MSVR1, msvr1);
3485 BRDDISABLE(portp->brdnr);
3489 /*****************************************************************************/
3492 * Get the state of the signals.
3495 static int stl_cd1400getsignals(stlport_t *portp)
3497 unsigned char msvr1, msvr2;
3501 printf("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3505 BRDENABLE(portp->brdnr, portp->pagenr);
3506 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3507 msvr1 = stl_cd1400getreg(portp, MSVR1);
3508 msvr2 = stl_cd1400getreg(portp, MSVR2);
3509 BRDDISABLE(portp->brdnr);
3513 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3514 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3515 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3516 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3518 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3519 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3526 /*****************************************************************************/
3529 * Enable or disable the Transmitter and/or Receiver.
3532 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3537 printf("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3538 (int) portp, rx, tx);
3543 ccr |= CCR_TXDISABLE;
3545 ccr |= CCR_TXENABLE;
3547 ccr |= CCR_RXDISABLE;
3549 ccr |= CCR_RXENABLE;
3552 BRDENABLE(portp->brdnr, portp->pagenr);
3553 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3554 stl_cd1400ccrwait(portp);
3555 stl_cd1400setreg(portp, CCR, ccr);
3556 stl_cd1400ccrwait(portp);
3557 BRDDISABLE(portp->brdnr);
3561 /*****************************************************************************/
3564 * Start or stop the Transmitter and/or Receiver.
3567 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3569 unsigned char sreron, sreroff;
3572 printf("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3573 (int) portp, rx, tx);
3579 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3581 sreron |= SRER_TXDATA;
3583 sreron |= SRER_TXEMPTY;
3585 sreroff |= SRER_RXDATA;
3587 sreron |= SRER_RXDATA;
3590 BRDENABLE(portp->brdnr, portp->pagenr);
3591 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3592 stl_cd1400setreg(portp, SRER,
3593 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3594 BRDDISABLE(portp->brdnr);
3596 portp->state |= ASY_TXBUSY;
3597 portp->tty.t_state |= TS_BUSY;
3602 /*****************************************************************************/
3605 * Disable all interrupts from this port.
3608 static void stl_cd1400disableintrs(stlport_t *portp)
3612 printf("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3616 BRDENABLE(portp->brdnr, portp->pagenr);
3617 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3618 stl_cd1400setreg(portp, SRER, 0);
3619 BRDDISABLE(portp->brdnr);
3623 /*****************************************************************************/
3625 static void stl_cd1400sendbreak(stlport_t *portp, long len)
3629 printf("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp,
3634 BRDENABLE(portp->brdnr, portp->pagenr);
3635 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3636 stl_cd1400setreg(portp, COR2,
3637 (stl_cd1400getreg(portp, COR2) | COR2_ETC));
3638 stl_cd1400setreg(portp, SRER,
3639 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3641 BRDDISABLE(portp->brdnr);
3644 portp->brklen = (len > 255) ? 255 : len;
3646 portp->brklen = len;
3649 portp->stats.txbreaks++;
3652 /*****************************************************************************/
3655 * Try and find and initialize all the ports on a panel. We don't care
3656 * what sort of board these ports are on - since the port io registers
3657 * are almost identical when dealing with ports.
3660 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3663 printf("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3664 (int) brdp, (int) panelp, (int) portp);
3667 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
3668 (portp == (stlport_t *) NULL))
3671 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3672 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3673 portp->uartaddr = (portp->portnr & 0x04) << 5;
3674 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3676 BRDENABLE(portp->brdnr, portp->pagenr);
3677 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3678 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3679 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3680 BRDDISABLE(portp->brdnr);
3683 /*****************************************************************************/
3686 * Inbitialize the UARTs in a panel. We don't care what sort of board
3687 * these ports are on - since the port io registers are almost
3688 * identical when dealing with ports.
3691 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3695 int nrchips, uartaddr, ioaddr;
3698 printf("stl_cd1400panelinit(brdp=%x,panelp=%x)\n", (int) brdp,
3702 BRDENABLE(panelp->brdnr, panelp->pagenr);
3705 * Check that each chip is present and started up OK.
3708 nrchips = panelp->nrports / CD1400_PORTS;
3709 for (i = 0; (i < nrchips); i++) {
3710 if (brdp->brdtype == BRD_ECHPCI) {
3711 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3712 ioaddr = panelp->iobase;
3714 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3716 uartaddr = (i & 0x01) ? 0x080 : 0;
3717 outb(ioaddr, (GFRCR + uartaddr));
3718 outb((ioaddr + EREG_DATA), 0);
3719 outb(ioaddr, (CCR + uartaddr));
3720 outb((ioaddr + EREG_DATA), CCR_RESETFULL);
3721 outb((ioaddr + EREG_DATA), CCR_RESETFULL);
3722 outb(ioaddr, (GFRCR + uartaddr));
3723 for (j = 0; (j < CCR_MAXWAIT); j++) {
3724 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3727 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3728 printf("STALLION: cd1400 not responding, "
3729 "board=%d panel=%d chip=%d\n", panelp->brdnr,
3730 panelp->panelnr, i);
3733 chipmask |= (0x1 << i);
3734 outb(ioaddr, (PPR + uartaddr));
3735 outb((ioaddr + EREG_DATA), PPR_SCALAR);
3739 BRDDISABLE(panelp->brdnr);
3743 /*****************************************************************************/
3744 /* SC26198 HARDWARE FUNCTIONS */
3745 /*****************************************************************************/
3748 * These functions get/set/update the registers of the sc26198 UARTs.
3749 * Access to the sc26198 registers is via an address/data io port pair.
3750 * (Maybe should make this inline...)
3753 static int stl_sc26198getreg(stlport_t *portp, int regnr)
3755 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3756 return(inb(portp->ioaddr + XP_DATA));
3759 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
3761 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3762 outb((portp->ioaddr + XP_DATA), value);
3765 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
3767 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3768 if (inb(portp->ioaddr + XP_DATA) != value) {
3769 outb((portp->ioaddr + XP_DATA), value);
3775 /*****************************************************************************/
3778 * Functions to get and set the sc26198 global registers.
3781 static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
3783 outb((portp->ioaddr + XP_ADDR), regnr);
3784 return(inb(portp->ioaddr + XP_DATA));
3788 static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
3790 outb((portp->ioaddr + XP_ADDR), regnr);
3791 outb((portp->ioaddr + XP_DATA), value);
3795 /*****************************************************************************/
3798 * Inbitialize the UARTs in a panel. We don't care what sort of board
3799 * these ports are on - since the port io registers are almost
3800 * identical when dealing with ports.
3803 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3806 int nrchips, ioaddr;
3809 printf("stl_sc26198panelinit(brdp=%x,panelp=%x)\n", (int) brdp,
3813 BRDENABLE(panelp->brdnr, panelp->pagenr);
3816 * Check that each chip is present and started up OK.
3819 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
3820 if (brdp->brdtype == BRD_ECHPCI)
3821 outb(brdp->ioctrl, panelp->pagenr);
3823 for (i = 0; (i < nrchips); i++) {
3824 ioaddr = panelp->iobase + (i * 4);
3825 outb((ioaddr + XP_ADDR), SCCR);
3826 outb((ioaddr + XP_DATA), CR_RESETALL);
3827 outb((ioaddr + XP_ADDR), TSTR);
3828 if (inb(ioaddr + XP_DATA) != 0) {
3829 printf("STALLION: sc26198 not responding, "
3830 "board=%d panel=%d chip=%d\n", panelp->brdnr,
3831 panelp->panelnr, i);
3834 chipmask |= (0x1 << i);
3835 outb((ioaddr + XP_ADDR), GCCR);
3836 outb((ioaddr + XP_DATA), GCCR_IVRTYPCHANACK);
3837 outb((ioaddr + XP_ADDR), WDTRCR);
3838 outb((ioaddr + XP_DATA), 0xff);
3841 BRDDISABLE(panelp->brdnr);
3845 /*****************************************************************************/
3848 * Initialize hardware specific port registers.
3851 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3854 printf("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
3855 (int) brdp, (int) panelp, (int) portp);
3858 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
3859 (portp == (stlport_t *) NULL))
3862 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
3863 portp->uartaddr = (portp->portnr & 0x07) << 4;
3864 portp->pagenr = panelp->pagenr;
3867 BRDENABLE(portp->brdnr, portp->pagenr);
3868 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
3869 BRDDISABLE(portp->brdnr);
3872 /*****************************************************************************/
3875 * Set up the sc26198 registers for a port based on the termios port
3879 static int stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
3881 unsigned char mr0, mr1, mr2, clk;
3882 unsigned char imron, imroff, iopr, ipr;
3885 printf("stl_sc26198setport(portp=%x,tiosp=%x): brdnr=%d portnr=%d\n",
3886 (int) portp, (int) tiosp, portp->brdnr, portp->portnr);
3898 * Set up the RX char ignore mask with those RX error types we
3901 portp->rxignoremsk = 0;
3902 if (tiosp->c_iflag & IGNPAR)
3903 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
3905 if (tiosp->c_iflag & IGNBRK)
3906 portp->rxignoremsk |= SR_RXBREAK;
3908 portp->rxmarkmsk = SR_RXOVERRUN;
3909 if (tiosp->c_iflag & (INPCK | PARMRK))
3910 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
3911 if (tiosp->c_iflag & BRKINT)
3912 portp->rxmarkmsk |= SR_RXBREAK;
3915 * Go through the char size, parity and stop bits and set all the
3916 * option registers appropriately.
3918 switch (tiosp->c_cflag & CSIZE) {
3933 if (tiosp->c_cflag & CSTOPB)
3938 if (tiosp->c_cflag & PARENB) {
3939 if (tiosp->c_cflag & PARODD)
3940 mr1 |= (MR1_PARENB | MR1_PARODD);
3942 mr1 |= (MR1_PARENB | MR1_PAREVEN);
3947 mr1 |= MR1_ERRBLOCK;
3950 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
3951 * space for hardware flow control and the like. This should be set to
3954 mr2 |= MR2_RXFIFOHALF;
3957 * Calculate the baud rate timers. For now we will just assume that
3958 * the input and output baud are the same. The sc26198 has a fixed
3959 * baud rate table, so only discrete baud rates possible.
3961 if (tiosp->c_ispeed == 0)
3962 tiosp->c_ispeed = tiosp->c_ospeed;
3963 if ((tiosp->c_ospeed < 0) || (tiosp->c_ospeed > SC26198_MAXBAUD))
3966 if (tiosp->c_ospeed > 0) {
3967 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
3968 if (tiosp->c_ospeed <= sc26198_baudtable[clk])
3974 * Check what form of modem signaling is required and set it up.
3976 if ((tiosp->c_cflag & CLOCAL) == 0) {
3977 iopr |= IOPR_DCDCOS;
3982 * Setup sc26198 enhanced modes if we can. In particular we want to
3983 * handle as much of the flow control as possible automatically. As
3984 * well as saving a few CPU cycles it will also greatly improve flow
3985 * control reliability.
3987 if (tiosp->c_iflag & IXON) {
3988 mr0 |= MR0_SWFTX | MR0_SWFT;
3989 imron |= IR_XONXOFF;
3991 imroff |= IR_XONXOFF;
3994 if (tiosp->c_iflag & IXOFF)
3998 if (tiosp->c_cflag & CCTS_OFLOW)
4000 if (tiosp->c_cflag & CRTS_IFLOW)
4004 * All sc26198 register values calculated so go through and set
4009 printf("SETPORT: portnr=%d panelnr=%d brdnr=%d\n", portp->portnr,
4010 portp->panelnr, portp->brdnr);
4011 printf(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4012 printf(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4013 printf(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4014 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4015 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4019 BRDENABLE(portp->brdnr, portp->pagenr);
4020 stl_sc26198setreg(portp, IMR, 0);
4021 stl_sc26198updatereg(portp, MR0, mr0);
4022 stl_sc26198updatereg(portp, MR1, mr1);
4023 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4024 stl_sc26198updatereg(portp, MR2, mr2);
4025 iopr = (stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr;
4026 if (tiosp->c_ospeed == 0) {
4030 stl_sc26198setreg(portp, TXCSR, clk);
4031 stl_sc26198setreg(portp, RXCSR, clk);
4033 stl_sc26198updatereg(portp, IOPIOR, iopr);
4034 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4035 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4036 ipr = stl_sc26198getreg(portp, IPR);
4038 portp->sigs &= ~TIOCM_CD;
4040 portp->sigs |= TIOCM_CD;
4041 portp->imr = (portp->imr & ~imroff) | imron;
4042 stl_sc26198setreg(portp, IMR, portp->imr);
4043 BRDDISABLE(portp->brdnr);
4044 portp->state &= ~(ASY_RTSFLOWMODE | ASY_CTSFLOWMODE);
4045 portp->state |= ((tiosp->c_cflag & CRTS_IFLOW) ? ASY_RTSFLOWMODE : 0);
4046 portp->state |= ((tiosp->c_cflag & CCTS_OFLOW) ? ASY_CTSFLOWMODE : 0);
4047 stl_ttyoptim(portp, tiosp);
4053 /*****************************************************************************/
4056 * Set the state of the DTR and RTS signals.
4059 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
4061 unsigned char iopioron, iopioroff;
4064 printf("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4065 (int) portp, dtr, rts);
4071 iopioroff |= IPR_DTR;
4073 iopioron |= IPR_DTR;
4075 iopioroff |= IPR_RTS;
4077 iopioron |= IPR_RTS;
4080 BRDENABLE(portp->brdnr, portp->pagenr);
4081 if ((rts >= 0) && (portp->tty.t_cflag & CRTS_IFLOW)) {
4083 stl_sc26198setreg(portp, MR1,
4084 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4085 portp->stats.rxrtsoff++;
4087 stl_sc26198setreg(portp, MR1,
4088 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4089 portp->stats.rxrtson++;
4092 stl_sc26198setreg(portp, IOPIOR,
4093 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4094 BRDDISABLE(portp->brdnr);
4098 /*****************************************************************************/
4101 * Return the state of the signals.
4104 static int stl_sc26198getsignals(stlport_t *portp)
4110 printf("stl_sc26198getsignals(portp=%x)\n", (int) portp);
4114 BRDENABLE(portp->brdnr, portp->pagenr);
4115 ipr = stl_sc26198getreg(portp, IPR);
4116 BRDDISABLE(portp->brdnr);
4120 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4121 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4122 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4123 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4127 /*****************************************************************************/
4130 * Enable/Disable the Transmitter and/or Receiver.
4133 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
4138 printf("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4139 (int) portp, rx, tx);
4142 ccr = portp->crenable;
4144 ccr &= ~CR_TXENABLE;
4148 ccr &= ~CR_RXENABLE;
4153 BRDENABLE(portp->brdnr, portp->pagenr);
4154 stl_sc26198setreg(portp, SCCR, ccr);
4155 BRDDISABLE(portp->brdnr);
4156 portp->crenable = ccr;
4160 /*****************************************************************************/
4163 * Start/stop the Transmitter and/or Receiver.
4166 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
4171 printf("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4172 (int) portp, rx, tx);
4181 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4183 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4186 BRDENABLE(portp->brdnr, portp->pagenr);
4187 stl_sc26198setreg(portp, IMR, imr);
4188 BRDDISABLE(portp->brdnr);
4191 portp->state |= ASY_TXBUSY;
4192 portp->tty.t_state |= TS_BUSY;
4197 /*****************************************************************************/
4200 * Disable all interrupts from this port.
4203 static void stl_sc26198disableintrs(stlport_t *portp)
4207 printf("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
4211 BRDENABLE(portp->brdnr, portp->pagenr);
4213 stl_sc26198setreg(portp, IMR, 0);
4214 BRDDISABLE(portp->brdnr);
4218 /*****************************************************************************/
4220 static void stl_sc26198sendbreak(stlport_t *portp, long len)
4224 printf("stl_sc26198sendbreak(portp=%x,len=%d)\n",
4225 (int) portp, (int) len);
4229 BRDENABLE(portp->brdnr, portp->pagenr);
4231 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4232 portp->stats.txbreaks++;
4234 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4236 BRDDISABLE(portp->brdnr);
4240 /*****************************************************************************/
4243 * Take flow control actions...
4246 static void stl_sc26198sendflow(stlport_t *portp, int hw, int sw)
4251 printf("stl_sc26198sendflow(portp=%x,hw=%d,sw=%d)\n",
4252 (int) portp, hw, sw);
4255 if (portp == (stlport_t *) NULL)
4259 BRDENABLE(portp->brdnr, portp->pagenr);
4262 mr0 = stl_sc26198getreg(portp, MR0);
4263 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4265 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4267 portp->stats.rxxoff++;
4269 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4271 portp->stats.rxxon++;
4273 stl_sc26198wait(portp);
4274 stl_sc26198setreg(portp, MR0, mr0);
4278 portp->state |= ASY_RTSFLOW;
4279 stl_sc26198setreg(portp, MR1,
4280 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4281 stl_sc26198setreg(portp, IOPIOR,
4282 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4283 portp->stats.rxrtsoff++;
4284 } else if (hw > 0) {
4285 portp->state &= ~ASY_RTSFLOW;
4286 stl_sc26198setreg(portp, MR1,
4287 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4288 stl_sc26198setreg(portp, IOPIOR,
4289 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4290 portp->stats.rxrtson++;
4293 BRDDISABLE(portp->brdnr);
4297 /*****************************************************************************/
4300 * Return the current state of data flow on this port. This is only
4301 * really interresting when determining if data has fully completed
4302 * transmission or not... The sc26198 interrupt scheme cannot
4303 * determine when all data has actually drained, so we need to
4304 * check the port statusy register to be sure.
4307 static int stl_sc26198datastate(stlport_t *portp)
4312 printf("stl_sc26198datastate(portp=%x)\n", (int) portp);
4315 if (portp == (stlport_t *) NULL)
4317 if (portp->state & ASY_TXBUSY)
4321 BRDENABLE(portp->brdnr, portp->pagenr);
4322 sr = stl_sc26198getreg(portp, SR);
4323 BRDDISABLE(portp->brdnr);
4326 return((sr & SR_TXEMPTY) ? 0 : 1);
4329 /*****************************************************************************/
4331 static void stl_sc26198flush(stlport_t *portp, int flag)
4335 printf("stl_sc26198flush(portp=%x,flag=%x)\n", (int) portp, flag);
4338 if (portp == (stlport_t *) NULL)
4342 BRDENABLE(portp->brdnr, portp->pagenr);
4343 if (flag & FWRITE) {
4344 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4345 stl_sc26198setreg(portp, SCCR, portp->crenable);
4348 while (stl_sc26198getreg(portp, SR) & SR_RXRDY)
4349 stl_sc26198getreg(portp, RXFIFO);
4351 BRDDISABLE(portp->brdnr);
4355 /*****************************************************************************/
4358 * If we are TX flow controlled and in IXANY mode then we may
4359 * need to unflow control here. We gotta do this because of the
4360 * automatic flow control modes of the sc26198 - which downs't
4361 * support any concept of an IXANY mode.
4364 static void stl_sc26198txunflow(stlport_t *portp)
4368 mr0 = stl_sc26198getreg(portp, MR0);
4369 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4370 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4371 stl_sc26198setreg(portp, MR0, mr0);
4372 portp->state &= ~ASY_TXFLOWED;
4375 /*****************************************************************************/
4378 * Delay for a small amount of time, to give the sc26198 a chance
4379 * to process a command...
4382 static void stl_sc26198wait(stlport_t *portp)
4387 printf("stl_sc26198wait(portp=%x)\n", (int) portp);
4390 if (portp == (stlport_t *) NULL)
4393 for (i = 0; (i < 20); i++)
4394 stl_sc26198getglobreg(portp, TSTR);
4397 /*****************************************************************************/
4400 * Transmit interrupt handler. This has gotta be fast! Handling TX
4401 * chars is pretty simple, stuff as many as possible from the TX buffer
4402 * into the sc26198 FIFO.
4405 static __inline void stl_sc26198txisr(stlport_t *portp)
4407 unsigned int ioaddr;
4413 printf("stl_sc26198txisr(portp=%x)\n", (int) portp);
4416 ioaddr = portp->ioaddr;
4418 head = portp->tx.head;
4419 tail = portp->tx.tail;
4420 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4421 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4422 ((portp->state & ASY_TXLOW) == 0))) {
4423 portp->state |= ASY_TXLOW;
4428 outb((ioaddr + XP_ADDR), (MR0 | portp->uartaddr));
4429 mr0 = inb(ioaddr + XP_DATA);
4430 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4431 portp->imr &= ~IR_TXRDY;
4432 outb((ioaddr + XP_ADDR), (IMR | portp->uartaddr));
4433 outb((ioaddr + XP_DATA), portp->imr);
4434 portp->state |= ASY_TXEMPTY;
4435 portp->state &= ~ASY_TXBUSY;
4437 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4438 outb((ioaddr + XP_DATA), mr0);
4441 len = MIN(len, SC26198_TXFIFOSIZE);
4442 portp->stats.txtotal += len;
4443 stlen = MIN(len, (portp->tx.endbuf - tail));
4444 outb((ioaddr + XP_ADDR), GTXFIFO);
4445 outsb((ioaddr + XP_DATA), tail, stlen);
4448 if (tail >= portp->tx.endbuf)
4449 tail = portp->tx.buf;
4451 outsb((ioaddr + XP_DATA), tail, len);
4454 portp->tx.tail = tail;
4458 /*****************************************************************************/
4461 * Receive character interrupt handler. Determine if we have good chars
4462 * or bad chars and then process appropriately. Good chars are easy
4463 * just shove the lot into the RX buffer and set all status byte to 0.
4464 * If a bad RX char then process as required. This routine needs to be
4468 static __inline void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
4471 printf("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
4474 if ((iack & IVR_TYPEMASK) == IVR_RXDATA)
4475 stl_sc26198rxgoodchars(portp);
4477 stl_sc26198rxbadchars(portp);
4480 * If we are TX flow controlled and in IXANY mode then we may need
4481 * to unflow control here. We gotta do this because of the automatic
4482 * flow control modes of the sc26198.
4484 if ((portp->state & ASY_TXFLOWED) && (portp->tty.t_iflag & IXANY))
4485 stl_sc26198txunflow(portp);
4488 /*****************************************************************************/
4491 * Process the good received characters from RX FIFO.
4494 static void stl_sc26198rxgoodchars(stlport_t *portp)
4496 unsigned int ioaddr, len, buflen, stlen;
4500 printf("stl_sc26198rxgoodchars(port=%x)\n", (int) portp);
4503 ioaddr = portp->ioaddr;
4506 * First up, calculate how much room there is in the RX ring queue.
4507 * We also want to keep track of the longest possible copy length,
4508 * this has to allow for the wrapping of the ring queue.
4510 head = portp->rx.head;
4511 tail = portp->rx.tail;
4513 buflen = STL_RXBUFSIZE - (head - tail) - 1;
4514 stlen = portp->rx.endbuf - head;
4516 buflen = tail - head - 1;
4521 * Check if the input buffer is near full. If so then we should take
4522 * some flow control action... It is very easy to do hardware and
4523 * software flow control from here since we have the port selected on
4526 if (buflen <= (STL_RXBUFSIZE - STL_RXBUFHIGH)) {
4527 if (((portp->state & ASY_RTSFLOW) == 0) &&
4528 (portp->state & ASY_RTSFLOWMODE)) {
4529 portp->state |= ASY_RTSFLOW;
4530 stl_sc26198setreg(portp, MR1,
4531 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4532 stl_sc26198setreg(portp, IOPIOR,
4533 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4534 portp->stats.rxrtsoff++;
4539 * OK we are set, process good data... If the RX ring queue is full
4540 * just chuck the chars - don't leave them in the UART.
4542 outb((ioaddr + XP_ADDR), GIBCR);
4543 len = inb(ioaddr + XP_DATA) + 1;
4545 outb((ioaddr + XP_ADDR), GRXFIFO);
4546 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4547 portp->stats.rxlost += len;
4548 portp->stats.rxtotal += len;
4550 len = MIN(len, buflen);
4551 portp->stats.rxtotal += len;
4552 stlen = MIN(len, stlen);
4554 outb((ioaddr + XP_ADDR), GRXFIFO);
4555 insb((ioaddr + XP_DATA), head, stlen);
4557 if (head >= portp->rx.endbuf) {
4558 head = portp->rx.buf;
4560 insb((ioaddr + XP_DATA), head, len);
4566 portp->rx.head = head;
4567 portp->state |= ASY_RXDATA;
4571 /*****************************************************************************/
4574 * Process all characters in the RX FIFO of the UART. Check all char
4575 * status bytes as well, and process as required. We need to check
4576 * all bytes in the FIFO, in case some more enter the FIFO while we
4577 * are here. To get the exact character error type we need to switch
4578 * into CHAR error mode (that is why we need to make sure we empty
4582 static void stl_sc26198rxbadchars(stlport_t *portp)
4585 unsigned int status;
4591 * First up, calculate how much room there is in the RX ring queue.
4592 * We also want to keep track of the longest possible copy length,
4593 * this has to allow for the wrapping of the ring queue.
4595 head = portp->rx.head;
4596 tail = portp->rx.tail;
4597 len = (head >= tail) ? (STL_RXBUFSIZE - (head - tail) - 1) :
4601 * To get the precise error type for each character we must switch
4602 * back into CHAR error mode.
4604 mr1 = stl_sc26198getreg(portp, MR1);
4605 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
4607 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
4608 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
4609 ch = stl_sc26198getreg(portp, RXFIFO);
4611 if (status & SR_RXBREAK)
4612 portp->stats.rxbreaks++;
4613 if (status & SR_RXFRAMING)
4614 portp->stats.rxframing++;
4615 if (status & SR_RXPARITY)
4616 portp->stats.rxparity++;
4617 if (status & SR_RXOVERRUN)
4618 portp->stats.rxoverrun++;
4619 if ((portp->rxignoremsk & status) == 0) {
4620 if ((portp->tty.t_state & TS_CAN_BYPASS_L_RINT) &&
4621 ((status & SR_RXFRAMING) ||
4622 ((status & SR_RXPARITY) &&
4623 (portp->tty.t_iflag & INPCK))))
4625 if ((portp->rxmarkmsk & status) == 0)
4628 *(head + STL_RXBUFSIZE) = status;
4630 if (head >= portp->rx.endbuf)
4631 head = portp->rx.buf;
4638 * To get correct interrupt class we must switch back into BLOCK
4641 stl_sc26198setreg(portp, MR1, mr1);
4643 portp->rx.head = head;
4644 portp->state |= ASY_RXDATA;
4648 /*****************************************************************************/
4651 * Other interrupt handler. This includes modem signals, flow
4652 * control actions, etc.
4655 static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
4657 unsigned char cir, ipr, xisr;
4660 printf("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
4663 cir = stl_sc26198getglobreg(portp, CIR);
4665 switch (cir & CIR_SUBTYPEMASK) {
4667 ipr = stl_sc26198getreg(portp, IPR);
4668 if (ipr & IPR_DCDCHANGE) {
4669 portp->state |= ASY_DCDCHANGE;
4670 portp->stats.modem++;
4674 case CIR_SUBXONXOFF:
4675 xisr = stl_sc26198getreg(portp, XISR);
4676 if (xisr & XISR_RXXONGOT) {
4677 portp->state |= ASY_TXFLOWED;
4678 portp->stats.txxoff++;
4680 if (xisr & XISR_RXXOFFGOT) {
4681 portp->state &= ~ASY_TXFLOWED;
4682 portp->stats.txxon++;
4686 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
4687 stl_sc26198rxbadchars(portp);
4694 /*****************************************************************************/
4697 * Interrupt service routine for sc26198 panels.
4700 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4706 * Work around bug in sc26198 chip... Cannot have A6 address
4707 * line of UART high, else iack will be returned as 0.
4709 outb((iobase + 1), 0);
4711 iack = inb(iobase + XP_IACK);
4713 printf("stl_sc26198intr(panelp=%p,iobase=%x): iack=%x\n", panelp, iobase, iack);
4715 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4717 if (iack & IVR_RXDATA)
4718 stl_sc26198rxisr(portp, iack);
4719 else if (iack & IVR_TXDATA)
4720 stl_sc26198txisr(portp);
4722 stl_sc26198otherisr(portp, iack);
4725 /*****************************************************************************/