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.10 2004/05/19 22:52:49 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 <bus/isa/i386/isa_device.h>
56 #include <i386/isa/ic/scd1400.h>
57 #include <i386/isa/ic/sc26198.h>
58 #include <machine/comstats.h>
61 #include <bus/pci/pcivar.h>
62 #include <bus/pci/pcireg.h>
67 /*****************************************************************************/
70 * Define the version level of the kernel - so we can compile in the
71 * appropriate bits of code. By default this will compile for a 2.1
82 /*****************************************************************************/
85 * Define different board types. At the moment I have only declared
86 * those boards that this driver supports. But I will use the standard
87 * "assigned" board numbers. In the future this driver will support
88 * some of the other Stallion boards. Currently supported boards are
89 * abbreviated as EIO = EasyIO and ECH = EasyConnection 8/32.
95 #define BRD_ECH64PCI 27
96 #define BRD_EASYIOPCI 28
99 * When using the BSD "config" stuff there is no easy way to specifiy
100 * a secondary IO address region. So it is hard wired here. Also the
101 * shared interrupt information is hard wired here...
103 static unsigned int stl_ioshared = 0x280;
104 static unsigned int stl_irqshared = 0;
106 /*****************************************************************************/
109 * Define important driver limitations.
111 #define STL_MAXBRDS 8
112 #define STL_MAXPANELS 4
113 #define STL_MAXBANKS 8
114 #define STL_PORTSPERPANEL 16
115 #define STL_PORTSPERBRD 64
118 * Define the important minor number break down bits. These have been
119 * chosen to be "compatible" with the standard sio driver minor numbers.
120 * Extra high bits are used to distinguish between boards.
122 #define STL_CALLOUTDEV 0x80
123 #define STL_CTRLLOCK 0x40
124 #define STL_CTRLINIT 0x20
125 #define STL_CTRLDEV (STL_CTRLLOCK | STL_CTRLINIT)
127 #define STL_MEMDEV 0x07000000
129 #define STL_DEFSPEED TTYDEF_SPEED
130 #define STL_DEFCFLAG (CS8 | CREAD | HUPCL)
133 * I haven't really decided (or measured) what buffer sizes give
134 * a good balance between performance and memory usage. These seem
135 * to work pretty well...
137 #define STL_RXBUFSIZE 2048
138 #define STL_TXBUFSIZE 2048
140 #define STL_TXBUFLOW (STL_TXBUFSIZE / 4)
141 #define STL_RXBUFHIGH (3 * STL_RXBUFSIZE / 4)
143 /*****************************************************************************/
146 * Define our local driver identity first. Set up stuff to deal with
147 * all the local structures required by a serial tty driver.
149 static const char stl_drvname[] = "stl";
150 static const char stl_longdrvname[] = "Stallion Multiport Serial Driver";
151 static const char stl_drvversion[] = "2.0.0";
152 static int stl_brdprobed[STL_MAXBRDS];
154 static int stl_nrbrds = 0;
155 static int stl_doingtimeout = 0;
157 static const char __file__[] = /*__FILE__*/ "stallion.c";
160 * Define global stats structures. Not used often, and can be
161 * re-used for each stats call.
163 static combrd_t stl_brdstats;
164 static comstats_t stl_comstats;
166 /*****************************************************************************/
169 * Define a set of structures to hold all the board/panel/port info
170 * for our ports. These will be dynamically allocated as required.
174 * Define a ring queue structure for each port. This will hold the
175 * TX data waiting to be output. Characters are fed into this buffer
176 * from the line discipline (or even direct from user space!) and
177 * then fed into the UARTs during interrupts. Will use a clasic ring
178 * queue here for this. The good thing about this type of ring queue
179 * is that the head and tail pointers can be updated without interrupt
180 * protection - since "write" code only needs to change the head, and
181 * interrupt code only needs to change the tail.
191 * Port, panel and board structures to hold status info about each.
192 * The board structure contains pointers to structures for each panel
193 * connected to it, and in turn each panel structure contains pointers
194 * for each port structure for each port on that panel. Note that
195 * the port structure also contains the board and panel number that it
196 * is associated with, this makes it (fairly) easy to get back to the
197 * board/panel info for a port. Also note that the tty struct is at
198 * the top of the structure, this is important, since the code uses
199 * this fact to get the port struct pointer from the tty struct
202 typedef struct stlport {
220 unsigned int rxignoremsk;
221 unsigned int rxmarkmsk;
222 unsigned int crenable;
225 struct termios initintios;
226 struct termios initouttios;
227 struct termios lockintios;
228 struct termios lockouttios;
229 struct timeval timestamp;
236 typedef struct stlpanel {
243 unsigned int ackmask;
244 void (*isr)(struct stlpanel *panelp, unsigned int iobase);
246 stlport_t *ports[STL_PORTSPERPANEL];
249 typedef struct stlbrd {
259 unsigned int ioaddr1;
260 unsigned int ioaddr2;
261 unsigned int iostatus;
263 unsigned int ioctrlval;
266 void (*isr)(struct stlbrd *brdp);
267 unsigned int bnkpageaddr[STL_MAXBANKS];
268 unsigned int bnkstataddr[STL_MAXBANKS];
269 stlpanel_t *bnk2panel[STL_MAXBANKS];
270 stlpanel_t *panels[STL_MAXPANELS];
271 stlport_t *ports[STL_PORTSPERBRD];
274 static stlbrd_t *stl_brds[STL_MAXBRDS];
277 * Per board state flags. Used with the state field of the board struct.
278 * Not really much here yet!
280 #define BRD_FOUND 0x1
283 * Define the port structure state flags. These set of flags are
284 * modified at interrupt time - so setting and reseting them needs
287 #define ASY_TXLOW 0x1
288 #define ASY_RXDATA 0x2
289 #define ASY_DCDCHANGE 0x4
290 #define ASY_DTRWAIT 0x8
291 #define ASY_RTSFLOW 0x10
292 #define ASY_RTSFLOWMODE 0x20
293 #define ASY_CTSFLOWMODE 0x40
294 #define ASY_TXFLOWED 0x80
295 #define ASY_TXBUSY 0x100
296 #define ASY_TXEMPTY 0x200
298 #define ASY_ACTIVE (ASY_TXLOW | ASY_RXDATA | ASY_DCDCHANGE)
301 * Define an array of board names as printable strings. Handy for
302 * referencing boards when printing trace and stuff.
304 static char *stl_brdnames[] = {
336 /*****************************************************************************/
339 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
340 * to the directly accessable io ports of these boards (not the cd1400
341 * uarts - they are in scd1400.h).
343 #define EIO_8PORTRS 0x04
344 #define EIO_4PORTRS 0x05
345 #define EIO_8PORTDI 0x00
346 #define EIO_8PORTM 0x06
348 #define EIO_IDBITMASK 0x07
350 #define EIO_BRDMASK 0xf0
353 #define ID_BRD16 0x30
355 #define EIO_INTRPEND 0x08
356 #define EIO_INTEDGE 0x00
357 #define EIO_INTLEVEL 0x08
360 #define ECH_IDBITMASK 0xe0
361 #define ECH_BRDENABLE 0x08
362 #define ECH_BRDDISABLE 0x00
363 #define ECH_INTENABLE 0x01
364 #define ECH_INTDISABLE 0x00
365 #define ECH_INTLEVEL 0x02
366 #define ECH_INTEDGE 0x00
367 #define ECH_INTRPEND 0x01
368 #define ECH_BRDRESET 0x01
370 #define ECHMC_INTENABLE 0x01
371 #define ECHMC_BRDRESET 0x02
373 #define ECH_PNLSTATUS 2
374 #define ECH_PNL16PORT 0x20
375 #define ECH_PNLIDMASK 0x07
376 #define ECH_PNLXPID 0x40
377 #define ECH_PNLINTRPEND 0x80
378 #define ECH_ADDR2MASK 0x1e0
380 #define EIO_CLK 25000000
381 #define EIO_CLK8M 20000000
382 #define ECH_CLK EIO_CLK
385 * Define the PCI vendor and device ID for Stallion PCI boards.
387 #define STL_PCINSVENDID 0x100b
388 #define STL_PCINSDEVID 0xd001
390 #define STL_PCIVENDID 0x124d
391 #define STL_PCI32DEVID 0x0000
392 #define STL_PCI64DEVID 0x0002
393 #define STL_PCIEIODEVID 0x0003
395 #define STL_PCIBADCLASS 0x0101
397 typedef struct stlpcibrd {
398 unsigned short vendid;
399 unsigned short devid;
403 static stlpcibrd_t stl_pcibrds[] = {
404 { STL_PCIVENDID, STL_PCI64DEVID, BRD_ECH64PCI },
405 { STL_PCIVENDID, STL_PCIEIODEVID, BRD_EASYIOPCI },
406 { STL_PCIVENDID, STL_PCI32DEVID, BRD_ECHPCI },
407 { STL_PCINSVENDID, STL_PCINSDEVID, BRD_ECHPCI },
410 static int stl_nrpcibrds = sizeof(stl_pcibrds) / sizeof(stlpcibrd_t);
412 /*****************************************************************************/
415 * Define the vector mapping bits for the programmable interrupt board
416 * hardware. These bits encode the interrupt for the board to use - it
417 * is software selectable (except the EIO-8M).
419 static unsigned char stl_vecmap[] = {
420 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
421 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
425 * Set up enable and disable macros for the ECH boards. They require
426 * the secondary io address space to be activated and deactivated.
427 * This way all ECH boards can share their secondary io region.
428 * If this is an ECH-PCI board then also need to set the page pointer
429 * to point to the correct page.
431 #define BRDENABLE(brdnr,pagenr) \
432 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
433 outb(stl_brds[(brdnr)]->ioctrl, \
434 (stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE));\
435 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
436 outb(stl_brds[(brdnr)]->ioctrl, (pagenr));
438 #define BRDDISABLE(brdnr) \
439 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
440 outb(stl_brds[(brdnr)]->ioctrl, \
441 (stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE));
444 * Define some spare buffer space for un-wanted received characters.
446 static char stl_unwanted[SC26198_RXFIFOSIZE];
448 /*****************************************************************************/
451 * Define macros to extract a brd and port number from a minor number.
452 * This uses the extended minor number range in the upper 2 bytes of
453 * the device number. This gives us plenty of minor numbers to play
456 #define MKDEV2BRD(m) ((minor(m) & 0x00700000) >> 20)
457 #define MKDEV2PORT(m) ((minor(m) & 0x1f) | ((minor(m) & 0x00010000) >> 11))
460 * Define some handy local macros...
463 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
466 /*****************************************************************************/
469 * Declare all those functions in this driver! First up is the set of
470 * externally visible functions.
473 static int stlprobe(struct isa_device *idp);
474 static int stlattach(struct isa_device *idp);
476 STATIC d_open_t stlopen;
477 STATIC d_close_t stlclose;
478 STATIC d_ioctl_t stlioctl;
481 * Internal function prototypes.
483 static stlport_t *stl_dev2port(dev_t dev);
484 static int stl_findfreeunit(void);
485 static int stl_rawopen(stlport_t *portp);
486 static int stl_rawclose(stlport_t *portp);
487 static void stl_flush(stlport_t *portp, int flag);
488 static int stl_param(struct tty *tp, struct termios *tiosp);
489 static void stl_start(struct tty *tp);
490 static void stl_stop(struct tty *tp, int);
491 static void stl_ttyoptim(stlport_t *portp, struct termios *tiosp);
492 static void stl_dotimeout(void);
493 static void stl_poll(void *arg);
494 static void stl_rxprocess(stlport_t *portp);
495 static void stl_flowcontrol(stlport_t *portp, int hw, int sw);
496 static void stl_dtrwakeup(void *arg);
497 static int stl_brdinit(stlbrd_t *brdp);
498 static int stl_initeio(stlbrd_t *brdp);
499 static int stl_initech(stlbrd_t *brdp);
500 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
501 static void stl_eiointr(stlbrd_t *brdp);
502 static void stl_echatintr(stlbrd_t *brdp);
503 static void stl_echmcaintr(stlbrd_t *brdp);
504 static void stl_echpciintr(stlbrd_t *brdp);
505 static void stl_echpci64intr(stlbrd_t *brdp);
506 static int stl_memioctl(dev_t dev, unsigned long cmd, caddr_t data,
507 int flag, struct thread *td);
508 static int stl_getbrdstats(caddr_t data);
509 static int stl_getportstats(stlport_t *portp, caddr_t data);
510 static int stl_clrportstats(stlport_t *portp, caddr_t data);
511 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
512 static ointhand2_t stlintr;
515 static const char *stlpciprobe(pcici_t tag, pcidi_t type);
516 static void stlpciattach(pcici_t tag, int unit);
517 static void stlpciintr(void * arg);
521 * CD1400 uart specific handling functions.
523 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value);
524 static int stl_cd1400getreg(stlport_t *portp, int regnr);
525 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value);
526 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
527 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
528 static int stl_cd1400setport(stlport_t *portp, struct termios *tiosp);
529 static int stl_cd1400getsignals(stlport_t *portp);
530 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts);
531 static void stl_cd1400ccrwait(stlport_t *portp);
532 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx);
533 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx);
534 static void stl_cd1400disableintrs(stlport_t *portp);
535 static void stl_cd1400sendbreak(stlport_t *portp, long len);
536 static void stl_cd1400sendflow(stlport_t *portp, int hw, int sw);
537 static int stl_cd1400datastate(stlport_t *portp);
538 static void stl_cd1400flush(stlport_t *portp, int flag);
539 static __inline void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr);
540 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr);
541 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr);
542 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase);
543 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase);
546 * SC26198 uart specific handling functions.
548 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value);
549 static int stl_sc26198getreg(stlport_t *portp, int regnr);
550 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value);
551 static int stl_sc26198getglobreg(stlport_t *portp, int regnr);
552 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
553 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
554 static int stl_sc26198setport(stlport_t *portp, struct termios *tiosp);
555 static int stl_sc26198getsignals(stlport_t *portp);
556 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts);
557 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx);
558 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx);
559 static void stl_sc26198disableintrs(stlport_t *portp);
560 static void stl_sc26198sendbreak(stlport_t *portp, long len);
561 static void stl_sc26198sendflow(stlport_t *portp, int hw, int sw);
562 static int stl_sc26198datastate(stlport_t *portp);
563 static void stl_sc26198flush(stlport_t *portp, int flag);
564 static void stl_sc26198txunflow(stlport_t *portp);
565 static void stl_sc26198wait(stlport_t *portp);
566 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase);
567 static void stl_sc26198txisr(stlport_t *port);
568 static void stl_sc26198rxisr(stlport_t *port, unsigned int iack);
569 static void stl_sc26198rxgoodchars(stlport_t *portp);
570 static void stl_sc26198rxbadchars(stlport_t *portp);
571 static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
573 /*****************************************************************************/
576 * Generic UART support structure.
578 typedef struct uart {
579 int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp);
580 void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
581 int (*setport)(stlport_t *portp, struct termios *tiosp);
582 int (*getsignals)(stlport_t *portp);
583 void (*setsignals)(stlport_t *portp, int dtr, int rts);
584 void (*enablerxtx)(stlport_t *portp, int rx, int tx);
585 void (*startrxtx)(stlport_t *portp, int rx, int tx);
586 void (*disableintrs)(stlport_t *portp);
587 void (*sendbreak)(stlport_t *portp, long len);
588 void (*sendflow)(stlport_t *portp, int hw, int sw);
589 void (*flush)(stlport_t *portp, int flag);
590 int (*datastate)(stlport_t *portp);
591 void (*intr)(stlpanel_t *panelp, unsigned int iobase);
595 * Define some macros to make calling these functions nice and clean.
597 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
598 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
599 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
600 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
601 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
602 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
603 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
604 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
605 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
606 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
607 #define stl_uartflush (* ((uart_t *) portp->uartp)->flush)
608 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
610 /*****************************************************************************/
613 * CD1400 UART specific data initialization.
615 static uart_t stl_cd1400uart = {
619 stl_cd1400getsignals,
620 stl_cd1400setsignals,
621 stl_cd1400enablerxtx,
623 stl_cd1400disableintrs,
632 * Define the offsets within the register bank of a cd1400 based panel.
633 * These io address offsets are common to the EasyIO board as well.
641 #define EREG_BANKSIZE 8
643 #define CD1400_CLK 25000000
644 #define CD1400_CLK8M 20000000
647 * Define the cd1400 baud rate clocks. These are used when calculating
648 * what clock and divisor to use for the required baud rate. Also
649 * define the maximum baud rate allowed, and the default base baud.
651 static int stl_cd1400clkdivs[] = {
652 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
656 * Define the maximum baud rate of the cd1400 devices.
658 #define CD1400_MAXBAUD 230400
660 /*****************************************************************************/
663 * SC26198 UART specific data initization.
665 static uart_t stl_sc26198uart = {
666 stl_sc26198panelinit,
669 stl_sc26198getsignals,
670 stl_sc26198setsignals,
671 stl_sc26198enablerxtx,
672 stl_sc26198startrxtx,
673 stl_sc26198disableintrs,
674 stl_sc26198sendbreak,
677 stl_sc26198datastate,
682 * Define the offsets within the register bank of a sc26198 based panel.
690 #define XP_BANKSIZE 4
693 * Define the sc26198 baud rate table. Offsets within the table
694 * represent the actual baud rate selector of sc26198 registers.
696 static unsigned int sc26198_baudtable[] = {
697 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
698 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
702 #define SC26198_NRBAUDS (sizeof(sc26198_baudtable) / sizeof(unsigned int))
705 * Define the maximum baud rate of the sc26198 devices.
707 #define SC26198_MAXBAUD 460800
709 /*****************************************************************************/
712 * Declare the driver isa structure.
714 struct isa_driver stldriver = {
715 stlprobe, stlattach, "stl"
718 /*****************************************************************************/
723 * Declare the driver pci structure.
725 static unsigned long stl_count;
727 static struct pci_device stlpcidriver = {
735 COMPAT_PCI_DRIVER (stlpci, stlpcidriver);
739 /*****************************************************************************/
744 * FreeBSD-2.2+ kernel linkage.
747 #define CDEV_MAJOR 72
748 static struct cdevsw stl_cdevsw = {
750 /* maj */ CDEV_MAJOR,
751 /* flags */ D_TTY | D_KQFILTER,
756 /* close */ stlclose,
758 /* write */ ttywrite,
759 /* ioctl */ stlioctl,
762 /* strategy */ nostrategy,
765 /* kqfilter */ ttykqfilter
768 static void stl_drvinit(void *unused)
772 SYSINIT(sidev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,stl_drvinit,NULL)
776 /*****************************************************************************/
779 * Probe for some type of EasyIO or EasyConnection 8/32 board at
780 * the supplied address. All we do is check if we can find the
781 * board ID for the board... (Note, PCI boards not checked here,
782 * they are done in the stlpciprobe() routine).
785 static int stlprobe(struct isa_device *idp)
790 printf("stlprobe(idp=%x): unit=%d iobase=%x\n", (int) idp,
791 idp->id_unit, idp->id_iobase);
794 if (idp->id_unit > STL_MAXBRDS)
797 status = inb(idp->id_iobase + 1);
798 if ((status & ECH_IDBITMASK) == ECH_ID) {
799 stl_brdprobed[idp->id_unit] = BRD_ECH;
803 status = inb(idp->id_iobase + 2);
804 switch (status & EIO_IDBITMASK) {
810 stl_brdprobed[idp->id_unit] = BRD_EASYIO;
819 /*****************************************************************************/
822 * Find an available internal board number (unit number). The problem
823 * is that the same unit numbers can be assigned to different boards
824 * detected during the ISA and PCI initialization phases.
827 static int stl_findfreeunit()
831 for (i = 0; (i < STL_MAXBRDS); i++)
832 if (stl_brds[i] == (stlbrd_t *) NULL)
834 return((i >= STL_MAXBRDS) ? -1 : i);
837 /*****************************************************************************/
840 * Allocate resources for and initialize the specified board.
843 static int stlattach(struct isa_device *idp)
846 int boardnr, portnr, minor_dev;
849 printf("stlattach(idp=%p): unit=%d iobase=%x\n", (void *) idp,
850 idp->id_unit, idp->id_iobase);
853 /* idp->id_ointr = stlintr; */
855 brdp = (stlbrd_t *) malloc(sizeof(stlbrd_t), M_TTYS, M_NOWAIT);
856 if (brdp == (stlbrd_t *) NULL) {
857 printf("STALLION: failed to allocate memory (size=%d)\n",
861 bzero(brdp, sizeof(stlbrd_t));
863 if ((brdp->brdnr = stl_findfreeunit()) < 0) {
864 printf("STALLION: too many boards found, max=%d\n",
868 if (brdp->brdnr >= stl_nrbrds)
869 stl_nrbrds = brdp->brdnr + 1;
871 brdp->unitid = idp->id_unit;
872 brdp->brdtype = stl_brdprobed[idp->id_unit];
873 brdp->ioaddr1 = idp->id_iobase;
874 brdp->ioaddr2 = stl_ioshared;
875 brdp->irq = ffs(idp->id_irq) - 1;
876 brdp->irqtype = stl_irqshared;
879 /* register devices for DEVFS */
880 boardnr = brdp->brdnr;
881 cdevsw_add(&stl_cdevsw, 31, boardnr);
882 make_dev(&stl_cdevsw, boardnr + 0x1000000, UID_ROOT, GID_WHEEL,
883 0600, "staliomem%d", boardnr);
885 for (portnr = 0, minor_dev = boardnr * 0x100000;
886 portnr < 32; portnr++, minor_dev++) {
888 make_dev(&stl_cdevsw, minor_dev,
889 UID_ROOT, GID_WHEEL, 0600,
890 "ttyE%d", portnr + (boardnr * 64));
891 make_dev(&stl_cdevsw, minor_dev + 32,
892 UID_ROOT, GID_WHEEL, 0600,
893 "ttyiE%d", portnr + (boardnr * 64));
894 make_dev(&stl_cdevsw, minor_dev + 64,
895 UID_ROOT, GID_WHEEL, 0600,
896 "ttylE%d", portnr + (boardnr * 64));
897 make_dev(&stl_cdevsw, minor_dev + 128,
898 UID_ROOT, GID_WHEEL, 0600,
899 "cue%d", portnr + (boardnr * 64));
900 make_dev(&stl_cdevsw, minor_dev + 160,
901 UID_ROOT, GID_WHEEL, 0600,
902 "cuie%d", portnr + (boardnr * 64));
903 make_dev(&stl_cdevsw, minor_dev + 192,
904 UID_ROOT, GID_WHEEL, 0600,
905 "cule%d", portnr + (boardnr * 64));
908 make_dev(&stl_cdevsw, minor_dev + 0x10000,
909 UID_ROOT, GID_WHEEL, 0600,
910 "ttyE%d", portnr + (boardnr * 64) + 32);
911 make_dev(&stl_cdevsw, minor_dev + 32 + 0x10000,
912 UID_ROOT, GID_WHEEL, 0600,
913 "ttyiE%d", portnr + (boardnr * 64) + 32);
914 make_dev(&stl_cdevsw, minor_dev + 64 + 0x10000,
915 UID_ROOT, GID_WHEEL, 0600,
916 "ttylE%d", portnr + (boardnr * 64) + 32);
917 make_dev(&stl_cdevsw, minor_dev + 128 + 0x10000,
918 UID_ROOT, GID_WHEEL, 0600,
919 "cue%d", portnr + (boardnr * 64) + 32);
920 make_dev(&stl_cdevsw, minor_dev + 160 + 0x10000,
921 UID_ROOT, GID_WHEEL, 0600,
922 "cuie%d", portnr + (boardnr * 64) + 32);
923 make_dev(&stl_cdevsw, minor_dev + 192 + 0x10000,
924 UID_ROOT, GID_WHEEL, 0600,
925 "cule%d", portnr + (boardnr * 64) + 32);
927 boardnr = brdp->brdnr;
928 make_dev(&stl_cdevsw, boardnr + 0x1000000, UID_ROOT, GID_WHEEL,
929 0600, "staliomem%d", boardnr);
931 for (portnr = 0, minor_dev = boardnr * 0x100000;
932 portnr < 32; portnr++, minor_dev++) {
934 make_dev(&stl_cdevsw, minor_dev,
935 UID_ROOT, GID_WHEEL, 0600,
936 "ttyE%d", portnr + (boardnr * 64));
937 make_dev(&stl_cdevsw, minor_dev + 32,
938 UID_ROOT, GID_WHEEL, 0600,
939 "ttyiE%d", portnr + (boardnr * 64));
940 make_dev(&stl_cdevsw, minor_dev + 64,
941 UID_ROOT, GID_WHEEL, 0600,
942 "ttylE%d", portnr + (boardnr * 64));
943 make_dev(&stl_cdevsw, minor_dev + 128,
944 UID_ROOT, GID_WHEEL, 0600,
945 "cue%d", portnr + (boardnr * 64));
946 make_dev(&stl_cdevsw, minor_dev + 160,
947 UID_ROOT, GID_WHEEL, 0600,
948 "cuie%d", portnr + (boardnr * 64));
949 make_dev(&stl_cdevsw, minor_dev + 192,
950 UID_ROOT, GID_WHEEL, 0600,
951 "cule%d", portnr + (boardnr * 64));
954 make_dev(&stl_cdevsw, minor_dev + 0x10000,
955 UID_ROOT, GID_WHEEL, 0600,
956 "ttyE%d", portnr + (boardnr * 64) + 32);
957 make_dev(&stl_cdevsw, minor_dev + 32 + 0x10000,
958 UID_ROOT, GID_WHEEL, 0600,
959 "ttyiE%d", portnr + (boardnr * 64) + 32);
960 make_dev(&stl_cdevsw, minor_dev + 64 + 0x10000,
961 UID_ROOT, GID_WHEEL, 0600,
962 "ttylE%d", portnr + (boardnr * 64) + 32);
963 make_dev(&stl_cdevsw, minor_dev + 128 + 0x10000,
964 UID_ROOT, GID_WHEEL, 0600,
965 "cue%d", portnr + (boardnr * 64) + 32);
966 make_dev(&stl_cdevsw, minor_dev + 160 + 0x10000,
967 UID_ROOT, GID_WHEEL, 0600,
968 "cuie%d", portnr + (boardnr * 64) + 32);
969 make_dev(&stl_cdevsw, minor_dev + 192 + 0x10000,
970 UID_ROOT, GID_WHEEL, 0600,
971 "cule%d", portnr + (boardnr * 64) + 32);
977 /*****************************************************************************/
982 * Probe specifically for the PCI boards. We need to be a little
983 * carefull here, since it looks sort like a Nat Semi IDE chip...
986 static const char *stlpciprobe(pcici_t tag, pcidi_t type)
992 printf("stlpciprobe(tag=%x,type=%x)\n", (int) &tag, (int) type);
996 for (i = 0; (i < stl_nrpcibrds); i++) {
997 if (((type & 0xffff) == stl_pcibrds[i].vendid) &&
998 (((type >> 16) & 0xffff) == stl_pcibrds[i].devid)) {
999 brdtype = stl_pcibrds[i].brdtype;
1005 return((char *) NULL);
1007 class = pci_conf_read(tag, PCI_CLASS_REG);
1008 if ((class & PCI_CLASS_MASK) == PCI_CLASS_MASS_STORAGE)
1009 return((char *) NULL);
1011 return(stl_brdnames[brdtype]);
1014 /*****************************************************************************/
1017 * Allocate resources for and initialize the specified PCI board.
1020 void stlpciattach(pcici_t tag, int unit)
1023 unsigned int bar[4];
1026 int boardnr, portnr, minor_dev;
1029 printf("stlpciattach(tag=%x,unit=%x)\n", (int) &tag, unit);
1032 brdp = (stlbrd_t *) malloc(sizeof(stlbrd_t), M_TTYS, M_NOWAIT);
1033 if (brdp == (stlbrd_t *) NULL) {
1034 printf("STALLION: failed to allocate memory (size=%d)\n",
1038 bzero(brdp, sizeof(stlbrd_t));
1040 if ((unit < 0) || (unit > STL_MAXBRDS)) {
1041 printf("STALLION: bad PCI board unit number=%d\n", unit);
1046 * Allocate us a new driver unique unit number.
1048 if ((brdp->brdnr = stl_findfreeunit()) < 0) {
1049 printf("STALLION: too many boards found, max=%d\n",
1053 if (brdp->brdnr >= stl_nrbrds)
1054 stl_nrbrds = brdp->brdnr + 1;
1057 * Determine what type of PCI board this is...
1059 id = (unsigned int) pci_conf_read(tag, 0x0);
1060 for (i = 0; (i < stl_nrpcibrds); i++) {
1061 if (((id & 0xffff) == stl_pcibrds[i].vendid) &&
1062 (((id >> 16) & 0xffff) == stl_pcibrds[i].devid)) {
1063 brdp->brdtype = stl_pcibrds[i].brdtype;
1068 if (i >= stl_nrpcibrds) {
1069 printf("STALLION: probed PCI board unknown type=%x\n", id);
1073 for (i = 0; (i < 4); i++)
1074 bar[i] = (unsigned int) pci_conf_read(tag, 0x10 + (i * 4)) &
1077 switch (brdp->brdtype) {
1079 brdp->ioaddr1 = bar[1];
1080 brdp->ioaddr2 = bar[2];
1083 brdp->ioaddr1 = bar[2];
1084 brdp->ioaddr2 = bar[1];
1087 brdp->ioaddr1 = bar[1];
1088 brdp->ioaddr2 = bar[0];
1091 printf("STALLION: unknown PCI board type=%d\n", brdp->brdtype);
1096 brdp->unitid = brdp->brdnr; /* PCI units auto-assigned */
1097 brdp->irq = ((int) pci_conf_read(tag, 0x3c)) & 0xff;
1099 if (pci_map_int(tag, stlpciintr, (void *) NULL, &tty_imask) == 0) {
1100 printf("STALLION: failed to map interrupt irq=%d for unit=%d\n",
1101 brdp->irq, brdp->brdnr);
1107 /* register devices for DEVFS */
1108 boardnr = brdp->brdnr;
1109 make_dev(&stl_cdevsw, boardnr + 0x1000000, UID_ROOT, GID_WHEEL,
1110 0600, "staliomem%d", boardnr);
1112 for (portnr = 0, minor_dev = boardnr * 0x100000;
1113 portnr < 32; portnr++, minor_dev++) {
1115 make_dev(&stl_cdevsw, minor_dev,
1116 UID_ROOT, GID_WHEEL, 0600,
1117 "ttyE%d", portnr + (boardnr * 64));
1118 make_dev(&stl_cdevsw, minor_dev + 32,
1119 UID_ROOT, GID_WHEEL, 0600,
1120 "ttyiE%d", portnr + (boardnr * 64));
1121 make_dev(&stl_cdevsw, minor_dev + 64,
1122 UID_ROOT, GID_WHEEL, 0600,
1123 "ttylE%d", portnr + (boardnr * 64));
1124 make_dev(&stl_cdevsw, minor_dev + 128,
1125 UID_ROOT, GID_WHEEL, 0600,
1126 "cue%d", portnr + (boardnr * 64));
1127 make_dev(&stl_cdevsw, minor_dev + 160,
1128 UID_ROOT, GID_WHEEL, 0600,
1129 "cuie%d", portnr + (boardnr * 64));
1130 make_dev(&stl_cdevsw, minor_dev + 192,
1131 UID_ROOT, GID_WHEEL, 0600,
1132 "cule%d", portnr + (boardnr * 64));
1135 make_dev(&stl_cdevsw, minor_dev + 0x10000,
1136 UID_ROOT, GID_WHEEL, 0600,
1137 "ttyE%d", portnr + (boardnr * 64) + 32);
1138 make_dev(&stl_cdevsw, minor_dev + 32 + 0x10000,
1139 UID_ROOT, GID_WHEEL, 0600,
1140 "ttyiE%d", portnr + (boardnr * 64) + 32);
1141 make_dev(&stl_cdevsw, minor_dev + 64 + 0x10000,
1142 UID_ROOT, GID_WHEEL, 0600,
1143 "ttylE%d", portnr + (boardnr * 64) + 32);
1144 make_dev(&stl_cdevsw, minor_dev + 128 + 0x10000,
1145 UID_ROOT, GID_WHEEL, 0600,
1146 "cue%d", portnr + (boardnr * 64) + 32);
1147 make_dev(&stl_cdevsw, minor_dev + 160 + 0x10000,
1148 UID_ROOT, GID_WHEEL, 0600,
1149 "cuie%d", portnr + (boardnr * 64) + 32);
1150 make_dev(&stl_cdevsw, minor_dev + 192 + 0x10000,
1151 UID_ROOT, GID_WHEEL, 0600,
1152 "cule%d", portnr + (boardnr * 64) + 32);
1158 /*****************************************************************************/
1160 STATIC int stlopen(dev_t dev, int flag, int mode, struct thread *td)
1164 int error, callout, x;
1167 printf("stlopen(dev=%x,flag=%x,mode=%x,p=%x)\n", (int) dev, flag,
1172 * Firstly check if the supplied device number is a valid device.
1174 if (minor(dev) & STL_MEMDEV)
1177 portp = stl_dev2port(dev);
1178 if (portp == (stlport_t *) NULL)
1180 if (minor(dev) & STL_CTRLDEV)
1184 callout = minor(dev) & STL_CALLOUTDEV;
1191 * Wait here for the DTR drop timeout period to expire.
1193 while (portp->state & ASY_DTRWAIT) {
1194 error = tsleep(&portp->dtrwait, PCATCH, "stldtr", 0);
1200 * We have a valid device, so now we check if it is already open.
1201 * If not then initialize the port hardware and set up the tty
1202 * struct as required.
1204 if ((tp->t_state & TS_ISOPEN) == 0) {
1205 tp->t_oproc = stl_start;
1206 tp->t_stop = stl_stop;
1207 tp->t_param = stl_param;
1209 tp->t_termios = callout ? portp->initouttios :
1213 if ((portp->sigs & TIOCM_CD) || callout)
1214 (*linesw[tp->t_line].l_modem)(tp, 1);
1217 if (portp->callout == 0) {
1222 if (portp->callout != 0) {
1223 if (flag & O_NONBLOCK) {
1227 error = tsleep(&portp->callout,
1228 PCATCH, "stlcall", 0);
1231 goto stlopen_restart;
1234 if ((tp->t_state & TS_XCLUDE) && suser(td)) {
1241 * If this port is not the callout device and we do not have carrier
1242 * then we need to sleep, waiting for it to be asserted.
1244 if (((tp->t_state & TS_CARR_ON) == 0) && !callout &&
1245 ((tp->t_cflag & CLOCAL) == 0) &&
1246 ((flag & O_NONBLOCK) == 0)) {
1248 error = tsleep(TSA_CARR_ON(tp), PCATCH, "stldcd", 0);
1252 goto stlopen_restart;
1256 * Open the line discipline.
1258 error = (*linesw[tp->t_line].l_open)(dev, tp);
1259 stl_ttyoptim(portp, &tp->t_termios);
1260 if ((tp->t_state & TS_ISOPEN) && callout)
1264 * If for any reason we get to here and the port is not actually
1265 * open then close of the physical hardware - no point leaving it
1266 * active when the open failed...
1270 if (((tp->t_state & TS_ISOPEN) == 0) && (portp->waitopens == 0))
1271 stl_rawclose(portp);
1276 /*****************************************************************************/
1278 STATIC int stlclose(dev_t dev, int flag, int mode, struct thread *td)
1285 printf("stlclose(dev=%s,flag=%x,mode=%x,p=%p)\n", devtoname(dev),
1286 flag, mode, (void *) p);
1289 if (minor(dev) & STL_MEMDEV)
1291 if (minor(dev) & STL_CTRLDEV)
1294 portp = stl_dev2port(dev);
1295 if (portp == (stlport_t *) NULL)
1300 (*linesw[tp->t_line].l_close)(tp, flag);
1301 stl_ttyoptim(portp, &tp->t_termios);
1302 stl_rawclose(portp);
1308 /*****************************************************************************/
1312 STATIC void stl_stop(struct tty *tp, int rw)
1315 printf("stl_stop(tp=%x,rw=%x)\n", (int) tp, rw);
1318 stl_flush((stlport_t *) tp, rw);
1323 STATIC int stlstop(struct tty *tp, int rw)
1326 printf("stlstop(tp=%x,rw=%x)\n", (int) tp, rw);
1329 stl_flush((stlport_t *) tp, rw);
1335 /*****************************************************************************/
1337 STATIC int stlioctl(dev_t dev, unsigned long cmd, caddr_t data, int flag,
1340 struct termios *newtios, *localtios;
1346 printf("stlioctl(dev=%s,cmd=%lx,data=%p,flag=%x,p=%p)\n",
1347 devtoname(dev), cmd, (void *) data, flag, (void *) p);
1350 if (minor(dev) & STL_MEMDEV)
1351 return(stl_memioctl(dev, cmd, data, flag, td));
1353 portp = stl_dev2port(dev);
1354 if (portp == (stlport_t *) NULL)
1360 * First up handle ioctls on the control devices.
1362 if (minor(dev) & STL_CTRLDEV) {
1363 if ((minor(dev) & STL_CTRLDEV) == STL_CTRLINIT)
1364 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1365 &portp->initouttios : &portp->initintios;
1366 else if ((minor(dev) & STL_CTRLDEV) == STL_CTRLLOCK)
1367 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1368 &portp->lockouttios : &portp->lockintios;
1374 if ((error = suser(td)) == 0)
1375 *localtios = *((struct termios *) data);
1378 *((struct termios *) data) = *localtios;
1381 *((int *) data) = TTYDISC;
1384 bzero(data, sizeof(struct winsize));
1394 * Deal with 4.3 compatibility issues if we have too...
1396 #if defined(COMPAT_43) || defined(COMPAT_SUNOS)
1398 struct termios tios;
1399 unsigned long oldcmd;
1401 tios = tp->t_termios;
1403 if ((error = ttsetcompat(tp, &cmd, data, &tios)))
1406 data = (caddr_t) &tios;
1411 * Carry out some pre-cmd processing work first...
1412 * Hmmm, not so sure we want this, disable for now...
1414 if ((cmd == TIOCSETA) || (cmd == TIOCSETAW) || (cmd == TIOCSETAF)) {
1415 newtios = (struct termios *) data;
1416 localtios = (minor(dev) & STL_CALLOUTDEV) ?
1417 &portp->lockouttios : &portp->lockintios;
1419 newtios->c_iflag = (tp->t_iflag & localtios->c_iflag) |
1420 (newtios->c_iflag & ~localtios->c_iflag);
1421 newtios->c_oflag = (tp->t_oflag & localtios->c_oflag) |
1422 (newtios->c_oflag & ~localtios->c_oflag);
1423 newtios->c_cflag = (tp->t_cflag & localtios->c_cflag) |
1424 (newtios->c_cflag & ~localtios->c_cflag);
1425 newtios->c_lflag = (tp->t_lflag & localtios->c_lflag) |
1426 (newtios->c_lflag & ~localtios->c_lflag);
1427 for (i = 0; (i < NCCS); i++) {
1428 if (localtios->c_cc[i] != 0)
1429 newtios->c_cc[i] = tp->t_cc[i];
1431 if (localtios->c_ispeed != 0)
1432 newtios->c_ispeed = tp->t_ispeed;
1433 if (localtios->c_ospeed != 0)
1434 newtios->c_ospeed = tp->t_ospeed;
1438 * Call the line discipline and the common command processing to
1439 * process this command (if they can).
1441 error = (*linesw[tp->t_line].l_ioctl)(tp, cmd, data, flag, td);
1442 if (error != ENOIOCTL)
1446 error = ttioctl(tp, cmd, data, flag);
1447 stl_ttyoptim(portp, &tp->t_termios);
1448 if (error != ENOIOCTL) {
1456 * Process local commands here. These are all commands that only we
1457 * can take care of (they all rely on actually doing something special
1458 * to the actual hardware).
1462 stl_sendbreak(portp, -1);
1465 stl_sendbreak(portp, -2);
1468 stl_setsignals(portp, 1, -1);
1471 stl_setsignals(portp, 0, -1);
1474 i = *((int *) data);
1475 stl_setsignals(portp, ((i & TIOCM_DTR) ? 1 : 0),
1476 ((i & TIOCM_RTS) ? 1 : 0));
1479 i = *((int *) data);
1480 stl_setsignals(portp, ((i & TIOCM_DTR) ? 1 : -1),
1481 ((i & TIOCM_RTS) ? 1 : -1));
1484 i = *((int *) data);
1485 stl_setsignals(portp, ((i & TIOCM_DTR) ? 0 : -1),
1486 ((i & TIOCM_RTS) ? 0 : -1));
1489 *((int *) data) = (stl_getsignals(portp) | TIOCM_LE);
1492 if ((error = suser(td)) == 0)
1493 portp->dtrwait = *((int *) data) * hz / 100;
1496 *((int *) data) = portp->dtrwait * 100 / hz;
1499 portp->dotimestamp = 1;
1500 *((struct timeval *) data) = portp->timestamp;
1510 /*****************************************************************************/
1513 * Convert the specified minor device number into a port struct
1514 * pointer. Return NULL if the device number is not a valid port.
1517 STATIC stlport_t *stl_dev2port(dev_t dev)
1521 brdp = stl_brds[MKDEV2BRD(dev)];
1522 if (brdp == (stlbrd_t *) NULL)
1523 return((stlport_t *) NULL);
1524 return(brdp->ports[MKDEV2PORT(dev)]);
1527 /*****************************************************************************/
1530 * Initialize the port hardware. This involves enabling the transmitter
1531 * and receiver, setting the port configuration, and setting the initial
1535 static int stl_rawopen(stlport_t *portp)
1538 printf("stl_rawopen(portp=%p): brdnr=%d panelnr=%d portnr=%d\n",
1539 (void *) portp, portp->brdnr, portp->panelnr, portp->portnr);
1542 stl_setport(portp, &portp->tty.t_termios);
1543 portp->sigs = stl_getsignals(portp);
1544 stl_setsignals(portp, 1, 1);
1545 stl_enablerxtx(portp, 1, 1);
1546 stl_startrxtx(portp, 1, 0);
1550 /*****************************************************************************/
1553 * Shutdown the hardware of a port. Disable its transmitter and
1554 * receiver, and maybe drop signals if appropriate.
1557 static int stl_rawclose(stlport_t *portp)
1562 printf("stl_rawclose(portp=%p): brdnr=%d panelnr=%d portnr=%d\n",
1563 (void *) portp, portp->brdnr, portp->panelnr, portp->portnr);
1567 stl_disableintrs(portp);
1568 stl_enablerxtx(portp, 0, 0);
1569 stl_flush(portp, (FWRITE | FREAD));
1570 if (tp->t_cflag & HUPCL) {
1571 stl_setsignals(portp, 0, 0);
1572 if (portp->dtrwait != 0) {
1573 portp->state |= ASY_DTRWAIT;
1574 timeout(stl_dtrwakeup, portp, portp->dtrwait);
1579 portp->state &= ~(ASY_ACTIVE | ASY_RTSFLOW);
1580 wakeup(&portp->callout);
1581 wakeup(TSA_CARR_ON(tp));
1585 /*****************************************************************************/
1588 * Clear the DTR waiting flag, and wake up any sleepers waiting for
1589 * DTR wait period to finish.
1592 static void stl_dtrwakeup(void *arg)
1596 portp = (stlport_t *) arg;
1597 portp->state &= ~ASY_DTRWAIT;
1598 wakeup(&portp->dtrwait);
1601 /*****************************************************************************/
1604 * Start (or continue) the transfer of TX data on this port. If the
1605 * port is not currently busy then load up the interrupt ring queue
1606 * buffer and kick of the transmitter. If the port is running low on
1607 * TX data then refill the ring queue. This routine is also used to
1608 * activate input flow control!
1611 static void stl_start(struct tty *tp)
1614 unsigned int len, stlen;
1618 portp = (stlport_t *) tp;
1621 printf("stl_start(tp=%x): brdnr=%d portnr=%d\n", (int) tp,
1622 portp->brdnr, portp->portnr);
1628 * Check if the ports input has been blocked, and take appropriate action.
1629 * Not very often do we really need to do anything, so make it quick.
1631 if (tp->t_state & TS_TBLOCK) {
1632 if ((portp->state & ASY_RTSFLOWMODE) &&
1633 ((portp->state & ASY_RTSFLOW) == 0))
1634 stl_flowcontrol(portp, 0, -1);
1636 if (portp->state & ASY_RTSFLOW)
1637 stl_flowcontrol(portp, 1, -1);
1642 * Check if the output cooked clist buffers are near empty, wake up
1643 * the line discipline to fill it up.
1645 if (tp->t_outq.c_cc <= tp->t_lowat) {
1646 if (tp->t_state & TS_ASLEEP) {
1647 tp->t_state &= ~TS_ASLEEP;
1648 wakeup(&tp->t_outq);
1650 selwakeup(&tp->t_wsel);
1654 if (tp->t_state & (TS_TIMEOUT | TS_TTSTOP)) {
1660 * Copy data from the clists into the interrupt ring queue. This will
1661 * require at most 2 copys... What we do is calculate how many chars
1662 * can fit into the ring queue, and how many can fit in 1 copy. If after
1663 * the first copy there is still more room then do the second copy.
1664 * The beauty of this type of ring queue is that we do not need to
1665 * spl protect our-selves, since we only ever update the head pointer,
1666 * and the interrupt routine only ever updates the tail pointer.
1668 if (tp->t_outq.c_cc != 0) {
1669 head = portp->tx.head;
1670 tail = portp->tx.tail;
1672 len = STL_TXBUFSIZE - (head - tail) - 1;
1673 stlen = portp->tx.endbuf - head;
1675 len = tail - head - 1;
1680 stlen = MIN(len, stlen);
1681 count = q_to_b(&tp->t_outq, head, stlen);
1684 if (head >= portp->tx.endbuf) {
1685 head = portp->tx.buf;
1687 stlen = q_to_b(&tp->t_outq, head, len);
1692 portp->tx.head = head;
1694 stl_startrxtx(portp, -1, 1);
1698 * If we sent something, make sure we are called again.
1700 tp->t_state |= TS_BUSY;
1705 * Do any writer wakeups.
1713 /*****************************************************************************/
1715 static void stl_flush(stlport_t *portp, int flag)
1721 printf("stl_flush(portp=%x,flag=%x)\n", (int) portp, flag);
1724 if (portp == (stlport_t *) NULL)
1729 if (flag & FWRITE) {
1730 stl_uartflush(portp, FWRITE);
1731 portp->tx.tail = portp->tx.head;
1735 * The only thing to watch out for when flushing the read side is
1736 * the RX status buffer. The interrupt code relys on the status
1737 * bytes as being zeroed all the time (it does not bother setting
1738 * a good char status to 0, it expects that it already will be).
1739 * We also need to un-flow the RX channel if flow control was
1743 head = portp->rx.head;
1744 tail = portp->rx.tail;
1749 len = portp->rx.endbuf - tail;
1750 bzero(portp->rxstatus.buf,
1751 (head - portp->rx.buf));
1753 bzero((tail + STL_RXBUFSIZE), len);
1754 portp->rx.tail = head;
1757 if ((portp->state & ASY_RTSFLOW) &&
1758 ((portp->tty.t_state & TS_TBLOCK) == 0))
1759 stl_flowcontrol(portp, 1, -1);
1765 /*****************************************************************************/
1768 * Interrupt handler for host based boards. Interrupts for all boards
1769 * are vectored through here.
1772 void stlintr(int unit)
1778 printf("stlintr(unit=%d)\n", unit);
1781 for (i = 0; (i < stl_nrbrds); i++) {
1782 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
1784 if (brdp->state == 0)
1786 (* brdp->isr)(brdp);
1790 /*****************************************************************************/
1794 static void stlpciintr(void *arg)
1801 /*****************************************************************************/
1804 * Interrupt service routine for EasyIO boards.
1807 static void stl_eiointr(stlbrd_t *brdp)
1813 printf("stl_eiointr(brdp=%p)\n", brdp);
1816 panelp = (stlpanel_t *) brdp->panels[0];
1817 iobase = panelp->iobase;
1818 while (inb(brdp->iostatus) & EIO_INTRPEND)
1819 (* panelp->isr)(panelp, iobase);
1823 * Interrupt service routine for ECH-AT board types.
1826 static void stl_echatintr(stlbrd_t *brdp)
1829 unsigned int ioaddr;
1832 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDENABLE));
1834 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1835 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1836 ioaddr = brdp->bnkstataddr[bnknr];
1837 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1838 panelp = brdp->bnk2panel[bnknr];
1839 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1844 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDDISABLE));
1847 /*****************************************************************************/
1850 * Interrupt service routine for ECH-MCA board types.
1853 static void stl_echmcaintr(stlbrd_t *brdp)
1856 unsigned int ioaddr;
1859 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1860 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1861 ioaddr = brdp->bnkstataddr[bnknr];
1862 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1863 panelp = brdp->bnk2panel[bnknr];
1864 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1870 /*****************************************************************************/
1873 * Interrupt service routine for ECH-PCI board types.
1876 static void stl_echpciintr(stlbrd_t *brdp)
1879 unsigned int ioaddr;
1883 printf("stl_echpciintr(brdp=%x)\n", (int) brdp);
1888 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1889 outb(brdp->ioctrl, brdp->bnkpageaddr[bnknr]);
1890 ioaddr = brdp->bnkstataddr[bnknr];
1891 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1892 panelp = brdp->bnk2panel[bnknr];
1893 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1902 /*****************************************************************************/
1905 * Interrupt service routine for EC8/64-PCI board types.
1908 static void stl_echpci64intr(stlbrd_t *brdp)
1911 unsigned int ioaddr;
1915 printf("stl_echpci64intr(brdp=%p)\n", brdp);
1918 while (inb(brdp->ioctrl) & 0x1) {
1919 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1920 ioaddr = brdp->bnkstataddr[bnknr];
1922 printf(" --> ioaddr=%x status=%x(%x)\n", ioaddr, inb(ioaddr) & ECH_PNLINTRPEND, inb(ioaddr));
1924 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1925 panelp = brdp->bnk2panel[bnknr];
1926 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1932 /*****************************************************************************/
1935 * If we haven't scheduled a timeout then do it, some port needs high
1939 static void stl_dotimeout()
1942 printf("stl_dotimeout()\n");
1945 if (stl_doingtimeout == 0) {
1946 timeout(stl_poll, 0, 1);
1951 /*****************************************************************************/
1954 * Service "software" level processing. Too slow or painfull to be done
1955 * at real hardware interrupt time. This way we might also be able to
1956 * do some service on other waiting ports as well...
1959 static void stl_poll(void *arg)
1964 int brdnr, portnr, rearm, x;
1967 printf("stl_poll()\n");
1970 stl_doingtimeout = 0;
1974 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1975 if ((brdp = stl_brds[brdnr]) == (stlbrd_t *) NULL)
1977 for (portnr = 0; (portnr < brdp->nrports); portnr++) {
1978 if ((portp = brdp->ports[portnr]) == (stlport_t *) NULL)
1980 if ((portp->state & ASY_ACTIVE) == 0)
1984 if (portp->state & ASY_RXDATA)
1985 stl_rxprocess(portp);
1986 if (portp->state & ASY_DCDCHANGE) {
1987 portp->state &= ~ASY_DCDCHANGE;
1988 portp->sigs = stl_getsignals(portp);
1989 (*linesw[tp->t_line].l_modem)(tp,
1990 (portp->sigs & TIOCM_CD));
1992 if (portp->state & ASY_TXEMPTY) {
1993 if (stl_datastate(portp) == 0) {
1994 portp->state &= ~ASY_TXEMPTY;
1995 tp->t_state &= ~TS_BUSY;
1996 (*linesw[tp->t_line].l_start)(tp);
1999 if (portp->state & ASY_TXLOW) {
2000 portp->state &= ~ASY_TXLOW;
2001 (*linesw[tp->t_line].l_start)(tp);
2004 if (portp->state & ASY_ACTIVE)
2014 /*****************************************************************************/
2017 * Process the RX data that has been buffered up in the RX ring queue.
2020 static void stl_rxprocess(stlport_t *portp)
2023 unsigned int len, stlen, lostlen;
2029 printf("stl_rxprocess(portp=%x): brdnr=%d portnr=%d\n", (int) portp,
2030 portp->brdnr, portp->portnr);
2034 portp->state &= ~ASY_RXDATA;
2036 if ((tp->t_state & TS_ISOPEN) == 0) {
2037 stl_flush(portp, FREAD);
2042 * Calculate the amount of data in the RX ring queue. Also calculate
2043 * the largest single copy size...
2045 head = portp->rx.head;
2046 tail = portp->rx.tail;
2051 len = STL_RXBUFSIZE - (tail - head);
2052 stlen = portp->rx.endbuf - tail;
2055 if (tp->t_state & TS_CAN_BYPASS_L_RINT) {
2057 if (((tp->t_rawq.c_cc + len) >= TTYHOG) &&
2058 ((portp->state & ASY_RTSFLOWMODE) ||
2059 (tp->t_iflag & IXOFF)) &&
2060 ((tp->t_state & TS_TBLOCK) == 0)) {
2061 ch = TTYHOG - tp->t_rawq.c_cc - 1;
2062 len = (ch > 0) ? ch : 0;
2063 stlen = MIN(stlen, len);
2066 lostlen = b_to_q(tail, stlen, &tp->t_rawq);
2069 if (tail >= portp->rx.endbuf) {
2070 tail = portp->rx.buf;
2071 lostlen += b_to_q(tail, len, &tp->t_rawq);
2074 portp->stats.rxlost += lostlen;
2076 portp->rx.tail = tail;
2079 while (portp->rx.tail != head) {
2080 ch = (unsigned char) *(portp->rx.tail);
2081 status = *(portp->rx.tail + STL_RXBUFSIZE);
2083 *(portp->rx.tail + STL_RXBUFSIZE) = 0;
2084 if (status & ST_BREAK)
2086 if (status & ST_FRAMING)
2088 if (status & ST_PARITY)
2090 if (status & ST_OVERRUN)
2093 (*linesw[tp->t_line].l_rint)(ch, tp);
2094 if (portp->rx.tail == head)
2097 if (++(portp->rx.tail) >= portp->rx.endbuf)
2098 portp->rx.tail = portp->rx.buf;
2102 if (head != portp->rx.tail)
2103 portp->state |= ASY_RXDATA;
2106 * If we were flow controled then maybe the buffer is low enough that
2107 * we can re-activate it.
2109 if ((portp->state & ASY_RTSFLOW) && ((tp->t_state & TS_TBLOCK) == 0))
2110 stl_flowcontrol(portp, 1, -1);
2113 /*****************************************************************************/
2115 static int stl_param(struct tty *tp, struct termios *tiosp)
2119 portp = (stlport_t *) tp;
2120 if (portp == (stlport_t *) NULL)
2123 return(stl_setport(portp, tiosp));
2126 /*****************************************************************************/
2129 * Action the flow control as required. The hw and sw args inform the
2130 * routine what flow control methods it should try.
2133 static void stl_flowcontrol(stlport_t *portp, int hw, int sw)
2135 unsigned char *head, *tail;
2139 printf("stl_flowcontrol(portp=%x,hw=%d,sw=%d)\n", (int) portp, hw, sw);
2144 if (portp->state & ASY_RTSFLOWMODE) {
2146 if ((portp->state & ASY_RTSFLOW) == 0)
2148 } else if (hw > 0) {
2149 if (portp->state & ASY_RTSFLOW) {
2150 head = portp->rx.head;
2151 tail = portp->rx.tail;
2152 len = (head >= tail) ? (head - tail) :
2153 (STL_RXBUFSIZE - (tail - head));
2154 if (len < STL_RXBUFHIGH)
2161 * We have worked out what to do, if anything. So now apply it to the
2164 stl_sendflow(portp, hwflow, sw);
2167 /*****************************************************************************/
2170 * Enable l_rint processing bypass mode if tty modes allow it.
2173 static void stl_ttyoptim(stlport_t *portp, struct termios *tiosp)
2178 if (((tiosp->c_iflag &
2179 (ICRNL | IGNCR | IMAXBEL | INLCR | ISTRIP)) == 0) &&
2180 (((tiosp->c_iflag & BRKINT) == 0) || (tiosp->c_iflag & IGNBRK)) &&
2181 (((tiosp->c_iflag & PARMRK) == 0) ||
2182 ((tiosp->c_iflag & (IGNPAR | IGNBRK)) == (IGNPAR | IGNBRK))) &&
2183 ((tiosp->c_lflag & (ECHO | ICANON | IEXTEN | ISIG | PENDIN)) ==0) &&
2184 (linesw[tp->t_line].l_rint == ttyinput))
2185 tp->t_state |= TS_CAN_BYPASS_L_RINT;
2187 tp->t_state &= ~TS_CAN_BYPASS_L_RINT;
2188 portp->hotchar = linesw[tp->t_line].l_hotchar;
2191 /*****************************************************************************/
2194 * Try and find and initialize all the ports on a panel. We don't care
2195 * what sort of board these ports are on - since the port io registers
2196 * are almost identical when dealing with ports.
2199 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2202 unsigned int chipmask;
2206 printf("stl_initports(panelp=%x)\n", (int) panelp);
2209 chipmask = stl_panelinit(brdp, panelp);
2212 * All UART's are initialized if found. Now go through and setup
2213 * each ports data structures. Also initialize each individual
2216 for (i = 0; (i < panelp->nrports); i++) {
2217 portp = (stlport_t *) malloc(sizeof(stlport_t), M_TTYS,
2219 if (portp == (stlport_t *) NULL) {
2220 printf("STALLION: failed to allocate port memory "
2221 "(size=%d)\n", sizeof(stlport_t));
2224 bzero(portp, sizeof(stlport_t));
2227 portp->brdnr = panelp->brdnr;
2228 portp->panelnr = panelp->panelnr;
2229 portp->uartp = panelp->uartp;
2230 portp->clk = brdp->clk;
2231 panelp->ports[i] = portp;
2233 j = STL_TXBUFSIZE + (2 * STL_RXBUFSIZE);
2234 portp->tx.buf = (char *) malloc(j, M_TTYS, M_NOWAIT);
2235 if (portp->tx.buf == (char *) NULL) {
2236 printf("STALLION: failed to allocate buffer memory "
2240 portp->tx.endbuf = portp->tx.buf + STL_TXBUFSIZE;
2241 portp->tx.head = portp->tx.buf;
2242 portp->tx.tail = portp->tx.buf;
2243 portp->rx.buf = portp->tx.buf + STL_TXBUFSIZE;
2244 portp->rx.endbuf = portp->rx.buf + STL_RXBUFSIZE;
2245 portp->rx.head = portp->rx.buf;
2246 portp->rx.tail = portp->rx.buf;
2247 portp->rxstatus.buf = portp->rx.buf + STL_RXBUFSIZE;
2248 portp->rxstatus.endbuf = portp->rxstatus.buf + STL_RXBUFSIZE;
2249 portp->rxstatus.head = portp->rxstatus.buf;
2250 portp->rxstatus.tail = portp->rxstatus.buf;
2251 bzero(portp->rxstatus.head, STL_RXBUFSIZE);
2253 portp->initintios.c_ispeed = STL_DEFSPEED;
2254 portp->initintios.c_ospeed = STL_DEFSPEED;
2255 portp->initintios.c_cflag = STL_DEFCFLAG;
2256 portp->initintios.c_iflag = 0;
2257 portp->initintios.c_oflag = 0;
2258 portp->initintios.c_lflag = 0;
2259 bcopy(&ttydefchars[0], &portp->initintios.c_cc[0],
2260 sizeof(portp->initintios.c_cc));
2261 portp->initouttios = portp->initintios;
2262 portp->dtrwait = 3 * hz;
2264 stl_portinit(brdp, panelp, portp);
2270 /*****************************************************************************/
2273 * Try to find and initialize an EasyIO board.
2276 static int stl_initeio(stlbrd_t *brdp)
2279 unsigned int status;
2282 printf("stl_initeio(brdp=%x)\n", (int) brdp);
2285 brdp->ioctrl = brdp->ioaddr1 + 1;
2286 brdp->iostatus = brdp->ioaddr1 + 2;
2287 brdp->clk = EIO_CLK;
2288 brdp->isr = stl_eiointr;
2290 status = inb(brdp->iostatus);
2291 switch (status & EIO_IDBITMASK) {
2293 brdp->clk = EIO_CLK8M;
2303 switch (status & EIO_BRDMASK) {
2322 if (brdp->brdtype == BRD_EASYIOPCI) {
2323 outb((brdp->ioaddr2 + 0x4c), 0x41);
2326 * Check that the supplied IRQ is good and then use it to setup the
2327 * programmable interrupt bits on EIO board. Also set the edge/level
2328 * triggered interrupt bit.
2330 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2331 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2332 printf("STALLION: invalid irq=%d for brd=%d\n",
2333 brdp->irq, brdp->brdnr);
2336 outb(brdp->ioctrl, (stl_vecmap[brdp->irq] |
2337 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)));
2340 panelp = (stlpanel_t *) malloc(sizeof(stlpanel_t), M_TTYS, M_NOWAIT);
2341 if (panelp == (stlpanel_t *) NULL) {
2342 printf("STALLION: failed to allocate memory (size=%d)\n",
2343 sizeof(stlpanel_t));
2346 bzero(panelp, sizeof(stlpanel_t));
2348 panelp->brdnr = brdp->brdnr;
2349 panelp->panelnr = 0;
2350 panelp->nrports = brdp->nrports;
2351 panelp->iobase = brdp->ioaddr1;
2352 panelp->hwid = status;
2353 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2354 panelp->uartp = (void *) &stl_sc26198uart;
2355 panelp->isr = stl_sc26198intr;
2357 panelp->uartp = (void *) &stl_cd1400uart;
2358 panelp->isr = stl_cd1400eiointr;
2360 brdp->panels[0] = panelp;
2362 brdp->hwid = status;
2363 brdp->state |= BRD_FOUND;
2367 /*****************************************************************************/
2370 * Try to find an ECH board and initialize it. This code is capable of
2371 * dealing with all types of ECH board.
2374 static int stl_initech(stlbrd_t *brdp)
2377 unsigned int status, nxtid;
2378 int panelnr, ioaddr, banknr, i;
2381 printf("stl_initech(brdp=%x)\n", (int) brdp);
2385 * Set up the initial board register contents for boards. This varys a
2386 * bit between the different board types. So we need to handle each
2387 * separately. Also do a check that the supplied IRQ is good.
2389 switch (brdp->brdtype) {
2392 brdp->isr = stl_echatintr;
2393 brdp->ioctrl = brdp->ioaddr1 + 1;
2394 brdp->iostatus = brdp->ioaddr1 + 1;
2395 status = inb(brdp->iostatus);
2396 if ((status & ECH_IDBITMASK) != ECH_ID)
2398 brdp->hwid = status;
2400 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2401 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2402 printf("STALLION: invalid irq=%d for brd=%d\n",
2403 brdp->irq, brdp->brdnr);
2406 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2407 status |= (stl_vecmap[brdp->irq] << 1);
2408 outb(brdp->ioaddr1, (status | ECH_BRDRESET));
2409 brdp->ioctrlval = ECH_INTENABLE |
2410 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2411 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDENABLE));
2412 outb(brdp->ioaddr1, status);
2416 brdp->isr = stl_echmcaintr;
2417 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2418 brdp->iostatus = brdp->ioctrl;
2419 status = inb(brdp->iostatus);
2420 if ((status & ECH_IDBITMASK) != ECH_ID)
2422 brdp->hwid = status;
2424 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2425 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2426 printf("STALLION: invalid irq=%d for brd=%d\n",
2427 brdp->irq, brdp->brdnr);
2430 outb(brdp->ioctrl, ECHMC_BRDRESET);
2431 outb(brdp->ioctrl, ECHMC_INTENABLE);
2435 brdp->isr = stl_echpciintr;
2436 brdp->ioctrl = brdp->ioaddr1 + 2;
2440 brdp->isr = stl_echpci64intr;
2441 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2442 outb((brdp->ioaddr1 + 0x4c), 0x43);
2446 printf("STALLION: unknown board type=%d\n", brdp->brdtype);
2450 brdp->clk = ECH_CLK;
2453 * Scan through the secondary io address space looking for panels.
2454 * As we find'em allocate and initialize panel structures for each.
2456 ioaddr = brdp->ioaddr2;
2461 for (i = 0; (i < STL_MAXPANELS); i++) {
2462 if (brdp->brdtype == BRD_ECHPCI) {
2463 outb(brdp->ioctrl, nxtid);
2464 ioaddr = brdp->ioaddr2;
2466 status = inb(ioaddr + ECH_PNLSTATUS);
2467 if ((status & ECH_PNLIDMASK) != nxtid)
2469 panelp = (stlpanel_t *) malloc(sizeof(stlpanel_t), M_TTYS,
2471 if (panelp == (stlpanel_t *) NULL) {
2472 printf("STALLION: failed to allocate memory"
2473 "(size=%d)\n", sizeof(stlpanel_t));
2476 bzero(panelp, sizeof(stlpanel_t));
2477 panelp->brdnr = brdp->brdnr;
2478 panelp->panelnr = panelnr;
2479 panelp->iobase = ioaddr;
2480 panelp->pagenr = nxtid;
2481 panelp->hwid = status;
2482 brdp->bnk2panel[banknr] = panelp;
2483 brdp->bnkpageaddr[banknr] = nxtid;
2484 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2486 if (status & ECH_PNLXPID) {
2487 panelp->uartp = (void *) &stl_sc26198uart;
2488 panelp->isr = stl_sc26198intr;
2489 if (status & ECH_PNL16PORT) {
2490 panelp->nrports = 16;
2491 brdp->bnk2panel[banknr] = panelp;
2492 brdp->bnkpageaddr[banknr] = nxtid;
2493 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2496 panelp->nrports = 8;
2499 panelp->uartp = (void *) &stl_cd1400uart;
2500 panelp->isr = stl_cd1400echintr;
2501 if (status & ECH_PNL16PORT) {
2502 panelp->nrports = 16;
2503 panelp->ackmask = 0x80;
2504 if (brdp->brdtype != BRD_ECHPCI)
2505 ioaddr += EREG_BANKSIZE;
2506 brdp->bnk2panel[banknr] = panelp;
2507 brdp->bnkpageaddr[banknr] = ++nxtid;
2508 brdp->bnkstataddr[banknr++] = ioaddr +
2511 panelp->nrports = 8;
2512 panelp->ackmask = 0xc0;
2517 ioaddr += EREG_BANKSIZE;
2518 brdp->nrports += panelp->nrports;
2519 brdp->panels[panelnr++] = panelp;
2520 if ((brdp->brdtype == BRD_ECH) || (brdp->brdtype == BRD_ECHMC)){
2521 if (ioaddr >= (brdp->ioaddr2 + 0x20)) {
2522 printf("STALLION: too many ports attached "
2523 "to board %d, remove last module\n",
2530 brdp->nrpanels = panelnr;
2531 brdp->nrbnks = banknr;
2532 if (brdp->brdtype == BRD_ECH)
2533 outb(brdp->ioctrl, (brdp->ioctrlval | ECH_BRDDISABLE));
2535 brdp->state |= BRD_FOUND;
2539 /*****************************************************************************/
2542 * Initialize and configure the specified board. This firstly probes
2543 * for the board, if it is found then the board is initialized and
2544 * then all its ports are initialized as well.
2547 static int stl_brdinit(stlbrd_t *brdp)
2553 printf("stl_brdinit(brdp=%x): unit=%d type=%d io1=%x io2=%x irq=%d\n",
2554 (int) brdp, brdp->brdnr, brdp->brdtype, brdp->ioaddr1,
2555 brdp->ioaddr2, brdp->irq);
2558 switch (brdp->brdtype) {
2570 printf("STALLION: unit=%d is unknown board type=%d\n",
2571 brdp->brdnr, brdp->brdtype);
2575 stl_brds[brdp->brdnr] = brdp;
2576 if ((brdp->state & BRD_FOUND) == 0) {
2578 printf("STALLION: %s board not found, unit=%d io=%x irq=%d\n",
2579 stl_brdnames[brdp->brdtype], brdp->brdnr,
2580 brdp->ioaddr1, brdp->irq);
2585 for (i = 0, k = 0; (i < STL_MAXPANELS); i++) {
2586 panelp = brdp->panels[i];
2587 if (panelp != (stlpanel_t *) NULL) {
2588 stl_initports(brdp, panelp);
2589 for (j = 0; (j < panelp->nrports); j++)
2590 brdp->ports[k++] = panelp->ports[j];
2594 printf("stl%d: %s (driver version %s) unit=%d nrpanels=%d nrports=%d\n",
2595 brdp->unitid, stl_brdnames[brdp->brdtype], stl_drvversion,
2596 brdp->brdnr, brdp->nrpanels, brdp->nrports);
2600 /*****************************************************************************/
2603 * Return the board stats structure to user app.
2606 static int stl_getbrdstats(caddr_t data)
2612 stl_brdstats = *((combrd_t *) data);
2613 if (stl_brdstats.brd >= STL_MAXBRDS)
2615 brdp = stl_brds[stl_brdstats.brd];
2616 if (brdp == (stlbrd_t *) NULL)
2619 bzero(&stl_brdstats, sizeof(combrd_t));
2620 stl_brdstats.brd = brdp->brdnr;
2621 stl_brdstats.type = brdp->brdtype;
2622 stl_brdstats.hwid = brdp->hwid;
2623 stl_brdstats.state = brdp->state;
2624 stl_brdstats.ioaddr = brdp->ioaddr1;
2625 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2626 stl_brdstats.irq = brdp->irq;
2627 stl_brdstats.nrpanels = brdp->nrpanels;
2628 stl_brdstats.nrports = brdp->nrports;
2629 for (i = 0; (i < brdp->nrpanels); i++) {
2630 panelp = brdp->panels[i];
2631 stl_brdstats.panels[i].panel = i;
2632 stl_brdstats.panels[i].hwid = panelp->hwid;
2633 stl_brdstats.panels[i].nrports = panelp->nrports;
2636 *((combrd_t *) data) = stl_brdstats;;
2640 /*****************************************************************************/
2643 * Resolve the referenced port number into a port struct pointer.
2646 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2651 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2652 return((stlport_t *) NULL);
2653 brdp = stl_brds[brdnr];
2654 if (brdp == (stlbrd_t *) NULL)
2655 return((stlport_t *) NULL);
2656 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2657 return((stlport_t *) NULL);
2658 panelp = brdp->panels[panelnr];
2659 if (panelp == (stlpanel_t *) NULL)
2660 return((stlport_t *) NULL);
2661 if ((portnr < 0) || (portnr >= panelp->nrports))
2662 return((stlport_t *) NULL);
2663 return(panelp->ports[portnr]);
2666 /*****************************************************************************/
2669 * Return the port stats structure to user app. A NULL port struct
2670 * pointer passed in means that we need to find out from the app
2671 * what port to get stats for (used through board control device).
2674 static int stl_getportstats(stlport_t *portp, caddr_t data)
2676 unsigned char *head, *tail;
2678 if (portp == (stlport_t *) NULL) {
2679 stl_comstats = *((comstats_t *) data);
2680 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2682 if (portp == (stlport_t *) NULL)
2686 portp->stats.state = portp->state;
2687 /*portp->stats.flags = portp->flags;*/
2688 portp->stats.hwid = portp->hwid;
2689 portp->stats.ttystate = portp->tty.t_state;
2690 portp->stats.cflags = portp->tty.t_cflag;
2691 portp->stats.iflags = portp->tty.t_iflag;
2692 portp->stats.oflags = portp->tty.t_oflag;
2693 portp->stats.lflags = portp->tty.t_lflag;
2695 head = portp->tx.head;
2696 tail = portp->tx.tail;
2697 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2698 (STL_TXBUFSIZE - (tail - head)));
2700 head = portp->rx.head;
2701 tail = portp->rx.tail;
2702 portp->stats.rxbuffered = (head >= tail) ? (head - tail) :
2703 (STL_RXBUFSIZE - (tail - head));
2705 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2707 *((comstats_t *) data) = portp->stats;
2711 /*****************************************************************************/
2714 * Clear the port stats structure. We also return it zeroed out...
2717 static int stl_clrportstats(stlport_t *portp, caddr_t data)
2719 if (portp == (stlport_t *) NULL) {
2720 stl_comstats = *((comstats_t *) data);
2721 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2723 if (portp == (stlport_t *) NULL)
2727 bzero(&portp->stats, sizeof(comstats_t));
2728 portp->stats.brd = portp->brdnr;
2729 portp->stats.panel = portp->panelnr;
2730 portp->stats.port = portp->portnr;
2731 *((comstats_t *) data) = stl_comstats;
2735 /*****************************************************************************/
2738 * The "staliomem" device is used for stats collection in this driver.
2741 static int stl_memioctl(dev_t dev, unsigned long cmd, caddr_t data, int flag,
2747 printf("stl_memioctl(dev=%s,cmd=%lx,data=%p,flag=%x)\n",
2748 devtoname(dev), cmd, (void *) data, flag);
2754 case COM_GETPORTSTATS:
2755 rc = stl_getportstats((stlport_t *) NULL, data);
2757 case COM_CLRPORTSTATS:
2758 rc = stl_clrportstats((stlport_t *) NULL, data);
2760 case COM_GETBRDSTATS:
2761 rc = stl_getbrdstats(data);
2771 /*****************************************************************************/
2773 /*****************************************************************************/
2774 /* CD1400 UART CODE */
2775 /*****************************************************************************/
2778 * These functions get/set/update the registers of the cd1400 UARTs.
2779 * Access to the cd1400 registers is via an address/data io port pair.
2782 static int stl_cd1400getreg(stlport_t *portp, int regnr)
2784 outb(portp->ioaddr, (regnr + portp->uartaddr));
2785 return(inb(portp->ioaddr + EREG_DATA));
2788 /*****************************************************************************/
2790 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
2792 outb(portp->ioaddr, (regnr + portp->uartaddr));
2793 outb((portp->ioaddr + EREG_DATA), value);
2796 /*****************************************************************************/
2798 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
2800 outb(portp->ioaddr, (regnr + portp->uartaddr));
2801 if (inb(portp->ioaddr + EREG_DATA) != value) {
2802 outb((portp->ioaddr + EREG_DATA), value);
2808 /*****************************************************************************/
2810 static void stl_cd1400flush(stlport_t *portp, int flag)
2815 printf("stl_cd1400flush(portp=%x,flag=%x)\n", (int) portp, flag);
2818 if (portp == (stlport_t *) NULL)
2823 if (flag & FWRITE) {
2824 BRDENABLE(portp->brdnr, portp->pagenr);
2825 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2826 stl_cd1400ccrwait(portp);
2827 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
2828 stl_cd1400ccrwait(portp);
2829 BRDDISABLE(portp->brdnr);
2839 /*****************************************************************************/
2841 static void stl_cd1400ccrwait(stlport_t *portp)
2845 for (i = 0; (i < CCR_MAXWAIT); i++) {
2846 if (stl_cd1400getreg(portp, CCR) == 0)
2850 printf("stl%d: cd1400 device not responding, panel=%d port=%d\n",
2851 portp->brdnr, portp->panelnr, portp->portnr);
2854 /*****************************************************************************/
2857 * Transmit interrupt handler. This has gotta be fast! Handling TX
2858 * chars is pretty simple, stuff as many as possible from the TX buffer
2859 * into the cd1400 FIFO. Must also handle TX breaks here, since they
2860 * are embedded as commands in the data stream. Oh no, had to use a goto!
2863 static __inline void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
2867 unsigned char ioack, srer;
2872 printf("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
2875 ioack = inb(ioaddr + EREG_TXACK);
2876 if (((ioack & panelp->ackmask) != 0) ||
2877 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
2878 printf("STALLION: bad TX interrupt ack value=%x\n",
2882 portp = panelp->ports[(ioack >> 3)];
2886 * Unfortunately we need to handle breaks in the data stream, since
2887 * this is the only way to generate them on the cd1400. Do it now if
2888 * a break is to be sent. Some special cases here: brklen is -1 then
2889 * start sending an un-timed break, if brklen is -2 then stop sending
2890 * an un-timed break, if brklen is -3 then we have just sent an
2891 * un-timed break and do not want any data to go out, if brklen is -4
2892 * then a break has just completed so clean up the port settings.
2894 if (portp->brklen != 0) {
2895 if (portp->brklen >= -1) {
2896 outb(ioaddr, (TDR + portp->uartaddr));
2897 outb((ioaddr + EREG_DATA), ETC_CMD);
2898 outb((ioaddr + EREG_DATA), ETC_STARTBREAK);
2899 if (portp->brklen > 0) {
2900 outb((ioaddr + EREG_DATA), ETC_CMD);
2901 outb((ioaddr + EREG_DATA), ETC_DELAY);
2902 outb((ioaddr + EREG_DATA), portp->brklen);
2903 outb((ioaddr + EREG_DATA), ETC_CMD);
2904 outb((ioaddr + EREG_DATA), ETC_STOPBREAK);
2909 } else if (portp->brklen == -2) {
2910 outb(ioaddr, (TDR + portp->uartaddr));
2911 outb((ioaddr + EREG_DATA), ETC_CMD);
2912 outb((ioaddr + EREG_DATA), ETC_STOPBREAK);
2914 } else if (portp->brklen == -3) {
2915 outb(ioaddr, (SRER + portp->uartaddr));
2916 srer = inb(ioaddr + EREG_DATA);
2917 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
2918 outb((ioaddr + EREG_DATA), srer);
2920 outb(ioaddr, (COR2 + portp->uartaddr));
2921 outb((ioaddr + EREG_DATA),
2922 (inb(ioaddr + EREG_DATA) & ~COR2_ETC));
2928 head = portp->tx.head;
2929 tail = portp->tx.tail;
2930 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
2931 if ((len == 0) || ((len < STL_TXBUFLOW) &&
2932 ((portp->state & ASY_TXLOW) == 0))) {
2933 portp->state |= ASY_TXLOW;
2938 outb(ioaddr, (SRER + portp->uartaddr));
2939 srer = inb(ioaddr + EREG_DATA);
2940 if (srer & SRER_TXDATA) {
2941 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
2943 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
2944 portp->state |= ASY_TXEMPTY;
2945 portp->state &= ~ASY_TXBUSY;
2947 outb((ioaddr + EREG_DATA), srer);
2949 len = MIN(len, CD1400_TXFIFOSIZE);
2950 portp->stats.txtotal += len;
2951 stlen = MIN(len, (portp->tx.endbuf - tail));
2952 outb(ioaddr, (TDR + portp->uartaddr));
2953 outsb((ioaddr + EREG_DATA), tail, stlen);
2956 if (tail >= portp->tx.endbuf)
2957 tail = portp->tx.buf;
2959 outsb((ioaddr + EREG_DATA), tail, len);
2962 portp->tx.tail = tail;
2966 outb(ioaddr, (EOSRR + portp->uartaddr));
2967 outb((ioaddr + EREG_DATA), 0);
2970 /*****************************************************************************/
2973 * Receive character interrupt handler. Determine if we have good chars
2974 * or bad chars and then process appropriately.
2977 static __inline void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
2981 unsigned int ioack, len, buflen, stlen;
2982 unsigned char status;
2987 printf("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
2990 ioack = inb(ioaddr + EREG_RXACK);
2991 if ((ioack & panelp->ackmask) != 0) {
2992 printf("STALLION: bad RX interrupt ack value=%x\n", ioack);
2995 portp = panelp->ports[(ioack >> 3)];
2999 * First up, calculate how much room there is in the RX ring queue.
3000 * We also want to keep track of the longest possible copy length,
3001 * this has to allow for the wrapping of the ring queue.
3003 head = portp->rx.head;
3004 tail = portp->rx.tail;
3006 buflen = STL_RXBUFSIZE - (head - tail) - 1;
3007 stlen = portp->rx.endbuf - head;
3009 buflen = tail - head - 1;
3014 * Check if the input buffer is near full. If so then we should take
3015 * some flow control action... It is very easy to do hardware and
3016 * software flow control from here since we have the port selected on
3019 if (buflen <= (STL_RXBUFSIZE - STL_RXBUFHIGH)) {
3020 if (((portp->state & ASY_RTSFLOW) == 0) &&
3021 (portp->state & ASY_RTSFLOWMODE)) {
3022 portp->state |= ASY_RTSFLOW;
3023 stl_cd1400setreg(portp, MCOR1,
3024 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3025 stl_cd1400setreg(portp, MSVR2, 0);
3026 portp->stats.rxrtsoff++;
3031 * OK we are set, process good data... If the RX ring queue is full
3032 * just chuck the chars - don't leave them in the UART.
3034 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
3035 outb(ioaddr, (RDCR + portp->uartaddr));
3036 len = inb(ioaddr + EREG_DATA);
3038 outb(ioaddr, (RDSR + portp->uartaddr));
3039 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
3040 portp->stats.rxlost += len;
3041 portp->stats.rxtotal += len;
3043 len = MIN(len, buflen);
3044 portp->stats.rxtotal += len;
3045 stlen = MIN(len, stlen);
3047 outb(ioaddr, (RDSR + portp->uartaddr));
3048 insb((ioaddr + EREG_DATA), head, stlen);
3050 if (head >= portp->rx.endbuf) {
3051 head = portp->rx.buf;
3053 insb((ioaddr + EREG_DATA), head, len);
3058 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
3059 outb(ioaddr, (RDSR + portp->uartaddr));
3060 status = inb(ioaddr + EREG_DATA);
3061 ch = inb(ioaddr + EREG_DATA);
3062 if (status & ST_BREAK)
3063 portp->stats.rxbreaks++;
3064 if (status & ST_FRAMING)
3065 portp->stats.rxframing++;
3066 if (status & ST_PARITY)
3067 portp->stats.rxparity++;
3068 if (status & ST_OVERRUN)
3069 portp->stats.rxoverrun++;
3070 if (status & ST_SCHARMASK) {
3071 if ((status & ST_SCHARMASK) == ST_SCHAR1)
3072 portp->stats.txxon++;
3073 if ((status & ST_SCHARMASK) == ST_SCHAR2)
3074 portp->stats.txxoff++;
3077 if ((portp->rxignoremsk & status) == 0) {
3078 if ((tp->t_state & TS_CAN_BYPASS_L_RINT) &&
3079 ((status & ST_FRAMING) ||
3080 ((status & ST_PARITY) && (tp->t_iflag & INPCK))))
3082 if ((portp->rxmarkmsk & status) == 0)
3084 *(head + STL_RXBUFSIZE) = status;
3086 if (head >= portp->rx.endbuf)
3087 head = portp->rx.buf;
3090 printf("STALLION: bad RX interrupt ack value=%x\n", ioack);
3094 portp->rx.head = head;
3095 portp->state |= ASY_RXDATA;
3099 outb(ioaddr, (EOSRR + portp->uartaddr));
3100 outb((ioaddr + EREG_DATA), 0);
3103 /*****************************************************************************/
3106 * Modem interrupt handler. The is called when the modem signal line
3107 * (DCD) has changed state.
3110 static __inline void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
3117 printf("stl_cd1400mdmisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
3120 ioack = inb(ioaddr + EREG_MDACK);
3121 if (((ioack & panelp->ackmask) != 0) ||
3122 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
3123 printf("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
3126 portp = panelp->ports[(ioack >> 3)];
3128 outb(ioaddr, (MISR + portp->uartaddr));
3129 misr = inb(ioaddr + EREG_DATA);
3130 if (misr & MISR_DCD) {
3131 portp->state |= ASY_DCDCHANGE;
3132 portp->stats.modem++;
3136 outb(ioaddr, (EOSRR + portp->uartaddr));
3137 outb((ioaddr + EREG_DATA), 0);
3140 /*****************************************************************************/
3143 * Interrupt service routine for cd1400 EasyIO boards.
3146 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3148 unsigned char svrtype;
3151 printf("stl_cd1400eiointr(panelp=%x,iobase=%x)\n", (int) panelp,
3156 svrtype = inb(iobase + EREG_DATA);
3157 if (panelp->nrports > 4) {
3158 outb(iobase, (SVRR + 0x80));
3159 svrtype |= inb(iobase + EREG_DATA);
3162 printf("stl_cd1400eiointr(panelp=%x,iobase=%x): svrr=%x\n", (int) panelp, iobase, svrtype);
3165 if (svrtype & SVRR_RX)
3166 stl_cd1400rxisr(panelp, iobase);
3167 else if (svrtype & SVRR_TX)
3168 stl_cd1400txisr(panelp, iobase);
3169 else if (svrtype & SVRR_MDM)
3170 stl_cd1400mdmisr(panelp, iobase);
3173 /*****************************************************************************/
3176 * Interrupt service routine for cd1400 panels.
3179 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
3181 unsigned char svrtype;
3184 printf("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
3189 svrtype = inb(iobase + EREG_DATA);
3190 outb(iobase, (SVRR + 0x80));
3191 svrtype |= inb(iobase + EREG_DATA);
3192 if (svrtype & SVRR_RX)
3193 stl_cd1400rxisr(panelp, iobase);
3194 else if (svrtype & SVRR_TX)
3195 stl_cd1400txisr(panelp, iobase);
3196 else if (svrtype & SVRR_MDM)
3197 stl_cd1400mdmisr(panelp, iobase);
3200 /*****************************************************************************/
3203 * Set up the cd1400 registers for a port based on the termios port
3207 static int stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3209 unsigned int clkdiv;
3210 unsigned char cor1, cor2, cor3;
3211 unsigned char cor4, cor5, ccr;
3212 unsigned char srer, sreron, sreroff;
3213 unsigned char mcor1, mcor2, rtpr;
3214 unsigned char clk, div;
3218 printf("stl_cd1400setport(portp=%x,tiosp=%x): brdnr=%d portnr=%d\n",
3219 (int) portp, (int) tiosp, portp->brdnr, portp->portnr);
3237 * Set up the RX char ignore mask with those RX error types we
3238 * can ignore. We could have used some special modes of the cd1400
3239 * UART to help, but it is better this way because we can keep stats
3240 * on the number of each type of RX exception event.
3242 portp->rxignoremsk = 0;
3243 if (tiosp->c_iflag & IGNPAR)
3244 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
3245 if (tiosp->c_iflag & IGNBRK)
3246 portp->rxignoremsk |= ST_BREAK;
3248 portp->rxmarkmsk = ST_OVERRUN;
3249 if (tiosp->c_iflag & (INPCK | PARMRK))
3250 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3251 if (tiosp->c_iflag & BRKINT)
3252 portp->rxmarkmsk |= ST_BREAK;
3255 * Go through the char size, parity and stop bits and set all the
3256 * option registers appropriately.
3258 switch (tiosp->c_cflag & CSIZE) {
3273 if (tiosp->c_cflag & CSTOPB)
3278 if (tiosp->c_cflag & PARENB) {
3279 if (tiosp->c_cflag & PARODD)
3280 cor1 |= (COR1_PARENB | COR1_PARODD);
3282 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3284 cor1 |= COR1_PARNONE;
3288 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3289 * space for hardware flow control and the like. This should be set to
3290 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3291 * really be based on VTIME...
3293 cor3 |= FIFO_RXTHRESHOLD;
3297 * Calculate the baud rate timers. For now we will just assume that
3298 * the input and output baud are the same. Could have used a baud
3299 * table here, but this way we can generate virtually any baud rate
3302 if (tiosp->c_ispeed == 0)
3303 tiosp->c_ispeed = tiosp->c_ospeed;
3304 if ((tiosp->c_ospeed < 0) || (tiosp->c_ospeed > CD1400_MAXBAUD))
3307 if (tiosp->c_ospeed > 0) {
3308 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3309 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) /
3314 div = (unsigned char) clkdiv;
3318 * Check what form of modem signaling is required and set it up.
3320 if ((tiosp->c_cflag & CLOCAL) == 0) {
3323 sreron |= SRER_MODEM;
3327 * Setup cd1400 enhanced modes if we can. In particular we want to
3328 * handle as much of the flow control as possbile automatically. As
3329 * well as saving a few CPU cycles it will also greatly improve flow
3330 * control reliablilty.
3332 if (tiosp->c_iflag & IXON) {
3335 if (tiosp->c_iflag & IXANY)
3339 if (tiosp->c_cflag & CCTS_OFLOW)
3341 if (tiosp->c_cflag & CRTS_IFLOW)
3342 mcor1 |= FIFO_RTSTHRESHOLD;
3345 * All cd1400 register values calculated so go through and set them
3349 printf("SETPORT: portnr=%d panelnr=%d brdnr=%d\n", portp->portnr,
3350 portp->panelnr, portp->brdnr);
3351 printf(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n", cor1, cor2,
3353 printf(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3354 mcor1, mcor2, rtpr, sreron, sreroff);
3355 printf(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3356 printf(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3357 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP], tiosp->c_cc[VSTART],
3358 tiosp->c_cc[VSTOP]);
3362 BRDENABLE(portp->brdnr, portp->pagenr);
3363 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3364 srer = stl_cd1400getreg(portp, SRER);
3365 stl_cd1400setreg(portp, SRER, 0);
3366 ccr += stl_cd1400updatereg(portp, COR1, cor1);
3367 ccr += stl_cd1400updatereg(portp, COR2, cor2);
3368 ccr += stl_cd1400updatereg(portp, COR3, cor3);
3370 stl_cd1400ccrwait(portp);
3371 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3373 stl_cd1400setreg(portp, COR4, cor4);
3374 stl_cd1400setreg(portp, COR5, cor5);
3375 stl_cd1400setreg(portp, MCOR1, mcor1);
3376 stl_cd1400setreg(portp, MCOR2, mcor2);
3377 if (tiosp->c_ospeed == 0) {
3378 stl_cd1400setreg(portp, MSVR1, 0);
3380 stl_cd1400setreg(portp, MSVR1, MSVR1_DTR);
3381 stl_cd1400setreg(portp, TCOR, clk);
3382 stl_cd1400setreg(portp, TBPR, div);
3383 stl_cd1400setreg(portp, RCOR, clk);
3384 stl_cd1400setreg(portp, RBPR, div);
3386 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3387 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3388 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3389 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3390 stl_cd1400setreg(portp, RTPR, rtpr);
3391 mcor1 = stl_cd1400getreg(portp, MSVR1);
3392 if (mcor1 & MSVR1_DCD)
3393 portp->sigs |= TIOCM_CD;
3395 portp->sigs &= ~TIOCM_CD;
3396 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3397 BRDDISABLE(portp->brdnr);
3398 portp->state &= ~(ASY_RTSFLOWMODE | ASY_CTSFLOWMODE);
3399 portp->state |= ((tiosp->c_cflag & CRTS_IFLOW) ? ASY_RTSFLOWMODE : 0);
3400 portp->state |= ((tiosp->c_cflag & CCTS_OFLOW) ? ASY_CTSFLOWMODE : 0);
3401 stl_ttyoptim(portp, tiosp);
3407 /*****************************************************************************/
3410 * Action the flow control as required. The hw and sw args inform the
3411 * routine what flow control methods it should try.
3414 static void stl_cd1400sendflow(stlport_t *portp, int hw, int sw)
3419 printf("stl_cd1400sendflow(portp=%x,hw=%d,sw=%d)\n",
3420 (int) portp, hw, sw);
3424 BRDENABLE(portp->brdnr, portp->pagenr);
3425 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3428 stl_cd1400ccrwait(portp);
3430 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3431 portp->stats.rxxoff++;
3433 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3434 portp->stats.rxxon++;
3436 stl_cd1400ccrwait(portp);
3440 portp->state |= ASY_RTSFLOW;
3441 stl_cd1400setreg(portp, MCOR1,
3442 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3443 stl_cd1400setreg(portp, MSVR2, 0);
3444 portp->stats.rxrtsoff++;
3445 } else if (hw > 0) {
3446 portp->state &= ~ASY_RTSFLOW;
3447 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3448 stl_cd1400setreg(portp, MCOR1,
3449 (stl_cd1400getreg(portp, MCOR1) | FIFO_RTSTHRESHOLD));
3450 portp->stats.rxrtson++;
3453 BRDDISABLE(portp->brdnr);
3457 /*****************************************************************************/
3460 * Return the current state of data flow on this port. This is only
3461 * really interresting when determining if data has fully completed
3462 * transmission or not... This is easy for the cd1400, it accurately
3463 * maintains the busy port flag.
3466 static int stl_cd1400datastate(stlport_t *portp)
3469 printf("stl_cd1400datastate(portp=%x)\n", (int) portp);
3472 if (portp == (stlport_t *) NULL)
3475 return((portp->state & ASY_TXBUSY) ? 1 : 0);
3478 /*****************************************************************************/
3481 * Set the state of the DTR and RTS signals. Got to do some extra
3482 * work here to deal hardware flow control.
3485 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3487 unsigned char msvr1, msvr2;
3491 printf("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n", (int) portp,
3503 BRDENABLE(portp->brdnr, portp->pagenr);
3504 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3506 if (portp->tty.t_cflag & CRTS_IFLOW) {
3508 stl_cd1400setreg(portp, MCOR1,
3509 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3510 portp->stats.rxrtsoff++;
3512 stl_cd1400setreg(portp, MCOR1,
3513 (stl_cd1400getreg(portp, MCOR1) |
3514 FIFO_RTSTHRESHOLD));
3515 portp->stats.rxrtson++;
3518 stl_cd1400setreg(portp, MSVR2, msvr2);
3521 stl_cd1400setreg(portp, MSVR1, msvr1);
3522 BRDDISABLE(portp->brdnr);
3526 /*****************************************************************************/
3529 * Get the state of the signals.
3532 static int stl_cd1400getsignals(stlport_t *portp)
3534 unsigned char msvr1, msvr2;
3538 printf("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3542 BRDENABLE(portp->brdnr, portp->pagenr);
3543 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3544 msvr1 = stl_cd1400getreg(portp, MSVR1);
3545 msvr2 = stl_cd1400getreg(portp, MSVR2);
3546 BRDDISABLE(portp->brdnr);
3550 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3551 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3552 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3553 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3555 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3556 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3563 /*****************************************************************************/
3566 * Enable or disable the Transmitter and/or Receiver.
3569 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3575 printf("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3576 (int) portp, rx, tx);
3581 ccr |= CCR_TXDISABLE;
3583 ccr |= CCR_TXENABLE;
3585 ccr |= CCR_RXDISABLE;
3587 ccr |= CCR_RXENABLE;
3590 BRDENABLE(portp->brdnr, portp->pagenr);
3591 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3592 stl_cd1400ccrwait(portp);
3593 stl_cd1400setreg(portp, CCR, ccr);
3594 stl_cd1400ccrwait(portp);
3595 BRDDISABLE(portp->brdnr);
3599 /*****************************************************************************/
3602 * Start or stop the Transmitter and/or Receiver.
3605 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3607 unsigned char sreron, sreroff;
3611 printf("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3612 (int) portp, rx, tx);
3618 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3620 sreron |= SRER_TXDATA;
3622 sreron |= SRER_TXEMPTY;
3624 sreroff |= SRER_RXDATA;
3626 sreron |= SRER_RXDATA;
3629 BRDENABLE(portp->brdnr, portp->pagenr);
3630 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3631 stl_cd1400setreg(portp, SRER,
3632 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3633 BRDDISABLE(portp->brdnr);
3635 portp->state |= ASY_TXBUSY;
3636 portp->tty.t_state |= TS_BUSY;
3641 /*****************************************************************************/
3644 * Disable all interrupts from this port.
3647 static void stl_cd1400disableintrs(stlport_t *portp)
3652 printf("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3656 BRDENABLE(portp->brdnr, portp->pagenr);
3657 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3658 stl_cd1400setreg(portp, SRER, 0);
3659 BRDDISABLE(portp->brdnr);
3663 /*****************************************************************************/
3665 static void stl_cd1400sendbreak(stlport_t *portp, long len)
3670 printf("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp,
3675 BRDENABLE(portp->brdnr, portp->pagenr);
3676 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3677 stl_cd1400setreg(portp, COR2,
3678 (stl_cd1400getreg(portp, COR2) | COR2_ETC));
3679 stl_cd1400setreg(portp, SRER,
3680 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3682 BRDDISABLE(portp->brdnr);
3685 portp->brklen = (len > 255) ? 255 : len;
3687 portp->brklen = len;
3690 portp->stats.txbreaks++;
3693 /*****************************************************************************/
3696 * Try and find and initialize all the ports on a panel. We don't care
3697 * what sort of board these ports are on - since the port io registers
3698 * are almost identical when dealing with ports.
3701 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3704 printf("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3705 (int) brdp, (int) panelp, (int) portp);
3708 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
3709 (portp == (stlport_t *) NULL))
3712 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3713 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3714 portp->uartaddr = (portp->portnr & 0x04) << 5;
3715 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3717 BRDENABLE(portp->brdnr, portp->pagenr);
3718 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3719 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3720 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3721 BRDDISABLE(portp->brdnr);
3724 /*****************************************************************************/
3727 * Inbitialize the UARTs in a panel. We don't care what sort of board
3728 * these ports are on - since the port io registers are almost
3729 * identical when dealing with ports.
3732 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3736 int nrchips, uartaddr, ioaddr;
3739 printf("stl_cd1400panelinit(brdp=%x,panelp=%x)\n", (int) brdp,
3743 BRDENABLE(panelp->brdnr, panelp->pagenr);
3746 * Check that each chip is present and started up OK.
3749 nrchips = panelp->nrports / CD1400_PORTS;
3750 for (i = 0; (i < nrchips); i++) {
3751 if (brdp->brdtype == BRD_ECHPCI) {
3752 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3753 ioaddr = panelp->iobase;
3755 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3757 uartaddr = (i & 0x01) ? 0x080 : 0;
3758 outb(ioaddr, (GFRCR + uartaddr));
3759 outb((ioaddr + EREG_DATA), 0);
3760 outb(ioaddr, (CCR + uartaddr));
3761 outb((ioaddr + EREG_DATA), CCR_RESETFULL);
3762 outb((ioaddr + EREG_DATA), CCR_RESETFULL);
3763 outb(ioaddr, (GFRCR + uartaddr));
3764 for (j = 0; (j < CCR_MAXWAIT); j++) {
3765 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3768 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3769 printf("STALLION: cd1400 not responding, "
3770 "board=%d panel=%d chip=%d\n", panelp->brdnr,
3771 panelp->panelnr, i);
3774 chipmask |= (0x1 << i);
3775 outb(ioaddr, (PPR + uartaddr));
3776 outb((ioaddr + EREG_DATA), PPR_SCALAR);
3780 BRDDISABLE(panelp->brdnr);
3784 /*****************************************************************************/
3785 /* SC26198 HARDWARE FUNCTIONS */
3786 /*****************************************************************************/
3789 * These functions get/set/update the registers of the sc26198 UARTs.
3790 * Access to the sc26198 registers is via an address/data io port pair.
3791 * (Maybe should make this inline...)
3794 static int stl_sc26198getreg(stlport_t *portp, int regnr)
3796 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3797 return(inb(portp->ioaddr + XP_DATA));
3800 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
3802 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3803 outb((portp->ioaddr + XP_DATA), value);
3806 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
3808 outb((portp->ioaddr + XP_ADDR), (regnr | portp->uartaddr));
3809 if (inb(portp->ioaddr + XP_DATA) != value) {
3810 outb((portp->ioaddr + XP_DATA), value);
3816 /*****************************************************************************/
3819 * Functions to get and set the sc26198 global registers.
3822 static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
3824 outb((portp->ioaddr + XP_ADDR), regnr);
3825 return(inb(portp->ioaddr + XP_DATA));
3829 static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
3831 outb((portp->ioaddr + XP_ADDR), regnr);
3832 outb((portp->ioaddr + XP_DATA), value);
3836 /*****************************************************************************/
3839 * Inbitialize the UARTs in a panel. We don't care what sort of board
3840 * these ports are on - since the port io registers are almost
3841 * identical when dealing with ports.
3844 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3847 int nrchips, ioaddr;
3850 printf("stl_sc26198panelinit(brdp=%x,panelp=%x)\n", (int) brdp,
3854 BRDENABLE(panelp->brdnr, panelp->pagenr);
3857 * Check that each chip is present and started up OK.
3860 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
3861 if (brdp->brdtype == BRD_ECHPCI)
3862 outb(brdp->ioctrl, panelp->pagenr);
3864 for (i = 0; (i < nrchips); i++) {
3865 ioaddr = panelp->iobase + (i * 4);
3866 outb((ioaddr + XP_ADDR), SCCR);
3867 outb((ioaddr + XP_DATA), CR_RESETALL);
3868 outb((ioaddr + XP_ADDR), TSTR);
3869 if (inb(ioaddr + XP_DATA) != 0) {
3870 printf("STALLION: sc26198 not responding, "
3871 "board=%d panel=%d chip=%d\n", panelp->brdnr,
3872 panelp->panelnr, i);
3875 chipmask |= (0x1 << i);
3876 outb((ioaddr + XP_ADDR), GCCR);
3877 outb((ioaddr + XP_DATA), GCCR_IVRTYPCHANACK);
3878 outb((ioaddr + XP_ADDR), WDTRCR);
3879 outb((ioaddr + XP_DATA), 0xff);
3882 BRDDISABLE(panelp->brdnr);
3886 /*****************************************************************************/
3889 * Initialize hardware specific port registers.
3892 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3895 printf("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
3896 (int) brdp, (int) panelp, (int) portp);
3899 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
3900 (portp == (stlport_t *) NULL))
3903 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
3904 portp->uartaddr = (portp->portnr & 0x07) << 4;
3905 portp->pagenr = panelp->pagenr;
3908 BRDENABLE(portp->brdnr, portp->pagenr);
3909 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
3910 BRDDISABLE(portp->brdnr);
3913 /*****************************************************************************/
3916 * Set up the sc26198 registers for a port based on the termios port
3920 static int stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
3922 unsigned char mr0, mr1, mr2, clk;
3923 unsigned char imron, imroff, iopr, ipr;
3927 printf("stl_sc26198setport(portp=%x,tiosp=%x): brdnr=%d portnr=%d\n",
3928 (int) portp, (int) tiosp, portp->brdnr, portp->portnr);
3940 * Set up the RX char ignore mask with those RX error types we
3943 portp->rxignoremsk = 0;
3944 if (tiosp->c_iflag & IGNPAR)
3945 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
3947 if (tiosp->c_iflag & IGNBRK)
3948 portp->rxignoremsk |= SR_RXBREAK;
3950 portp->rxmarkmsk = SR_RXOVERRUN;
3951 if (tiosp->c_iflag & (INPCK | PARMRK))
3952 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
3953 if (tiosp->c_iflag & BRKINT)
3954 portp->rxmarkmsk |= SR_RXBREAK;
3957 * Go through the char size, parity and stop bits and set all the
3958 * option registers appropriately.
3960 switch (tiosp->c_cflag & CSIZE) {
3975 if (tiosp->c_cflag & CSTOPB)
3980 if (tiosp->c_cflag & PARENB) {
3981 if (tiosp->c_cflag & PARODD)
3982 mr1 |= (MR1_PARENB | MR1_PARODD);
3984 mr1 |= (MR1_PARENB | MR1_PAREVEN);
3989 mr1 |= MR1_ERRBLOCK;
3992 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
3993 * space for hardware flow control and the like. This should be set to
3996 mr2 |= MR2_RXFIFOHALF;
3999 * Calculate the baud rate timers. For now we will just assume that
4000 * the input and output baud are the same. The sc26198 has a fixed
4001 * baud rate table, so only discrete baud rates possible.
4003 if (tiosp->c_ispeed == 0)
4004 tiosp->c_ispeed = tiosp->c_ospeed;
4005 if ((tiosp->c_ospeed < 0) || (tiosp->c_ospeed > SC26198_MAXBAUD))
4008 if (tiosp->c_ospeed > 0) {
4009 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
4010 if (tiosp->c_ospeed <= sc26198_baudtable[clk])
4016 * Check what form of modem signaling is required and set it up.
4018 if ((tiosp->c_cflag & CLOCAL) == 0) {
4019 iopr |= IOPR_DCDCOS;
4024 * Setup sc26198 enhanced modes if we can. In particular we want to
4025 * handle as much of the flow control as possible automatically. As
4026 * well as saving a few CPU cycles it will also greatly improve flow
4027 * control reliability.
4029 if (tiosp->c_iflag & IXON) {
4030 mr0 |= MR0_SWFTX | MR0_SWFT;
4031 imron |= IR_XONXOFF;
4033 imroff |= IR_XONXOFF;