1 /*****************************************************************************/
4 * stallion.c -- stallion multiport serial driver.
6 * Copyright (C) 1996-1999 Stallion Technologies
7 * Copyright (C) 1994-1996 Greg Ungerer.
9 * This code is loosely based on the Linux serial driver, written by
10 * Linus Torvalds, Theodore T'so and others.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /*****************************************************************************/
29 #include <linux/module.h>
30 #include <linux/sched.h>
31 #include <linux/slab.h>
32 #include <linux/interrupt.h>
33 #include <linux/tty.h>
34 #include <linux/tty_flip.h>
35 #include <linux/serial.h>
36 #include <linux/seq_file.h>
37 #include <linux/cd1400.h>
38 #include <linux/sc26198.h>
39 #include <linux/comstats.h>
40 #include <linux/stallion.h>
41 #include <linux/ioport.h>
42 #include <linux/init.h>
43 #include <linux/smp_lock.h>
44 #include <linux/device.h>
45 #include <linux/delay.h>
46 #include <linux/ctype.h>
49 #include <asm/uaccess.h>
51 #include <linux/pci.h>
53 /*****************************************************************************/
56 * Define different board types. Use the standard Stallion "assigned"
57 * board numbers. Boards supported in this driver are abbreviated as
58 * EIO = EasyIO and ECH = EasyConnection 8/32.
64 #define BRD_ECH64PCI 27
65 #define BRD_EASYIOPCI 28
71 unsigned long memaddr;
76 static unsigned int stl_nrbrds;
78 /*****************************************************************************/
81 * Define some important driver characteristics. Device major numbers
82 * allocated as per Linux Device Registry.
84 #ifndef STL_SIOMEMMAJOR
85 #define STL_SIOMEMMAJOR 28
87 #ifndef STL_SERIALMAJOR
88 #define STL_SERIALMAJOR 24
90 #ifndef STL_CALLOUTMAJOR
91 #define STL_CALLOUTMAJOR 25
95 * Set the TX buffer size. Bigger is better, but we don't want
96 * to chew too much memory with buffers!
98 #define STL_TXBUFLOW 512
99 #define STL_TXBUFSIZE 4096
101 /*****************************************************************************/
104 * Define our local driver identity first. Set up stuff to deal with
105 * all the local structures required by a serial tty driver.
107 static char *stl_drvtitle = "Stallion Multiport Serial Driver";
108 static char *stl_drvname = "stallion";
109 static char *stl_drvversion = "5.6.0";
111 static struct tty_driver *stl_serial;
114 * Define a local default termios struct. All ports will be created
115 * with this termios initially. Basically all it defines is a raw port
116 * at 9600, 8 data bits, 1 stop bit.
118 static struct ktermios stl_deftermios = {
119 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
126 * Define global place to put buffer overflow characters.
128 static char stl_unwanted[SC26198_RXFIFOSIZE];
130 /*****************************************************************************/
132 static DEFINE_MUTEX(stl_brdslock);
133 static struct stlbrd *stl_brds[STL_MAXBRDS];
135 static const struct tty_port_operations stl_port_ops;
138 * Per board state flags. Used with the state field of the board struct.
139 * Not really much here!
141 #define BRD_FOUND 0x1
142 #define STL_PROBED 0x2
146 * Define the port structure istate flags. These set of flags are
147 * modified at interrupt time - so setting and reseting them needs
148 * to be atomic. Use the bit clear/setting routines for this.
150 #define ASYI_TXBUSY 1
152 #define ASYI_TXFLOWED 3
155 * Define an array of board names as printable strings. Handy for
156 * referencing boards when printing trace and stuff.
158 static char *stl_brdnames[] = {
190 /*****************************************************************************/
193 * Define some string labels for arguments passed from the module
194 * load line. These allow for easy board definitions, and easy
195 * modification of the io, memory and irq resoucres.
197 static unsigned int stl_nargs;
198 static char *board0[4];
199 static char *board1[4];
200 static char *board2[4];
201 static char *board3[4];
203 static char **stl_brdsp[] = {
211 * Define a set of common board names, and types. This is used to
212 * parse any module arguments.
219 { "easyio", BRD_EASYIO },
220 { "eio", BRD_EASYIO },
221 { "20", BRD_EASYIO },
222 { "ec8/32", BRD_ECH },
223 { "ec8/32-at", BRD_ECH },
224 { "ec8/32-isa", BRD_ECH },
226 { "echat", BRD_ECH },
228 { "ec8/32-mc", BRD_ECHMC },
229 { "ec8/32-mca", BRD_ECHMC },
230 { "echmc", BRD_ECHMC },
231 { "echmca", BRD_ECHMC },
233 { "ec8/32-pc", BRD_ECHPCI },
234 { "ec8/32-pci", BRD_ECHPCI },
235 { "26", BRD_ECHPCI },
236 { "ec8/64-pc", BRD_ECH64PCI },
237 { "ec8/64-pci", BRD_ECH64PCI },
238 { "ech-pci", BRD_ECH64PCI },
239 { "echpci", BRD_ECH64PCI },
240 { "echpc", BRD_ECH64PCI },
241 { "27", BRD_ECH64PCI },
242 { "easyio-pc", BRD_EASYIOPCI },
243 { "easyio-pci", BRD_EASYIOPCI },
244 { "eio-pci", BRD_EASYIOPCI },
245 { "eiopci", BRD_EASYIOPCI },
246 { "28", BRD_EASYIOPCI },
250 * Define the module agruments.
253 module_param_array(board0, charp, &stl_nargs, 0);
254 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
255 module_param_array(board1, charp, &stl_nargs, 0);
256 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
257 module_param_array(board2, charp, &stl_nargs, 0);
258 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
259 module_param_array(board3, charp, &stl_nargs, 0);
260 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
262 /*****************************************************************************/
265 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
266 * to the directly accessible io ports of these boards (not the uarts -
267 * they are in cd1400.h and sc26198.h).
269 #define EIO_8PORTRS 0x04
270 #define EIO_4PORTRS 0x05
271 #define EIO_8PORTDI 0x00
272 #define EIO_8PORTM 0x06
274 #define EIO_IDBITMASK 0x07
276 #define EIO_BRDMASK 0xf0
279 #define ID_BRD16 0x30
281 #define EIO_INTRPEND 0x08
282 #define EIO_INTEDGE 0x00
283 #define EIO_INTLEVEL 0x08
287 #define ECH_IDBITMASK 0xe0
288 #define ECH_BRDENABLE 0x08
289 #define ECH_BRDDISABLE 0x00
290 #define ECH_INTENABLE 0x01
291 #define ECH_INTDISABLE 0x00
292 #define ECH_INTLEVEL 0x02
293 #define ECH_INTEDGE 0x00
294 #define ECH_INTRPEND 0x01
295 #define ECH_BRDRESET 0x01
297 #define ECHMC_INTENABLE 0x01
298 #define ECHMC_BRDRESET 0x02
300 #define ECH_PNLSTATUS 2
301 #define ECH_PNL16PORT 0x20
302 #define ECH_PNLIDMASK 0x07
303 #define ECH_PNLXPID 0x40
304 #define ECH_PNLINTRPEND 0x80
306 #define ECH_ADDR2MASK 0x1e0
309 * Define the vector mapping bits for the programmable interrupt board
310 * hardware. These bits encode the interrupt for the board to use - it
311 * is software selectable (except the EIO-8M).
313 static unsigned char stl_vecmap[] = {
314 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
315 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
319 * Lock ordering is that you may not take stallion_lock holding
323 static spinlock_t brd_lock; /* Guard the board mapping */
324 static spinlock_t stallion_lock; /* Guard the tty driver */
327 * Set up enable and disable macros for the ECH boards. They require
328 * the secondary io address space to be activated and deactivated.
329 * This way all ECH boards can share their secondary io region.
330 * If this is an ECH-PCI board then also need to set the page pointer
331 * to point to the correct page.
333 #define BRDENABLE(brdnr,pagenr) \
334 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
335 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
336 stl_brds[(brdnr)]->ioctrl); \
337 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
338 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
340 #define BRDDISABLE(brdnr) \
341 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
342 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
343 stl_brds[(brdnr)]->ioctrl);
345 #define STL_CD1400MAXBAUD 230400
346 #define STL_SC26198MAXBAUD 460800
348 #define STL_BAUDBASE 115200
349 #define STL_CLOSEDELAY (5 * HZ / 10)
351 /*****************************************************************************/
354 * Define the Stallion PCI vendor and device IDs.
356 #ifndef PCI_VENDOR_ID_STALLION
357 #define PCI_VENDOR_ID_STALLION 0x124d
359 #ifndef PCI_DEVICE_ID_ECHPCI832
360 #define PCI_DEVICE_ID_ECHPCI832 0x0000
362 #ifndef PCI_DEVICE_ID_ECHPCI864
363 #define PCI_DEVICE_ID_ECHPCI864 0x0002
365 #ifndef PCI_DEVICE_ID_EIOPCI
366 #define PCI_DEVICE_ID_EIOPCI 0x0003
370 * Define structure to hold all Stallion PCI boards.
373 static struct pci_device_id stl_pcibrds[] = {
374 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864),
375 .driver_data = BRD_ECH64PCI },
376 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI),
377 .driver_data = BRD_EASYIOPCI },
378 { PCI_DEVICE(PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832),
379 .driver_data = BRD_ECHPCI },
380 { PCI_DEVICE(PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410),
381 .driver_data = BRD_ECHPCI },
384 MODULE_DEVICE_TABLE(pci, stl_pcibrds);
386 /*****************************************************************************/
389 * Define macros to extract a brd/port number from a minor number.
391 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
392 #define MINOR2PORT(min) ((min) & 0x3f)
395 * Define a baud rate table that converts termios baud rate selector
396 * into the actual baud rate value. All baud rate calculations are
397 * based on the actual baud rate required.
399 static unsigned int stl_baudrates[] = {
400 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
401 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
404 /*****************************************************************************/
407 * Declare all those functions in this driver!
410 static long stl_memioctl(struct file *fp, unsigned int cmd, unsigned long arg);
411 static int stl_brdinit(struct stlbrd *brdp);
412 static int stl_getportstats(struct tty_struct *tty, struct stlport *portp, comstats_t __user *cp);
413 static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp);
416 * CD1400 uart specific handling functions.
418 static void stl_cd1400setreg(struct stlport *portp, int regnr, int value);
419 static int stl_cd1400getreg(struct stlport *portp, int regnr);
420 static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value);
421 static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
422 static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
423 static void stl_cd1400setport(struct stlport *portp, struct ktermios *tiosp);
424 static int stl_cd1400getsignals(struct stlport *portp);
425 static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts);
426 static void stl_cd1400ccrwait(struct stlport *portp);
427 static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx);
428 static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx);
429 static void stl_cd1400disableintrs(struct stlport *portp);
430 static void stl_cd1400sendbreak(struct stlport *portp, int len);
431 static void stl_cd1400flowctrl(struct stlport *portp, int state);
432 static void stl_cd1400sendflow(struct stlport *portp, int state);
433 static void stl_cd1400flush(struct stlport *portp);
434 static int stl_cd1400datastate(struct stlport *portp);
435 static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase);
436 static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase);
437 static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr);
438 static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr);
439 static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr);
441 static inline int stl_cd1400breakisr(struct stlport *portp, int ioaddr);
444 * SC26198 uart specific handling functions.
446 static void stl_sc26198setreg(struct stlport *portp, int regnr, int value);
447 static int stl_sc26198getreg(struct stlport *portp, int regnr);
448 static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value);
449 static int stl_sc26198getglobreg(struct stlport *portp, int regnr);
450 static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
451 static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
452 static void stl_sc26198setport(struct stlport *portp, struct ktermios *tiosp);
453 static int stl_sc26198getsignals(struct stlport *portp);
454 static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts);
455 static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx);
456 static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx);
457 static void stl_sc26198disableintrs(struct stlport *portp);
458 static void stl_sc26198sendbreak(struct stlport *portp, int len);
459 static void stl_sc26198flowctrl(struct stlport *portp, int state);
460 static void stl_sc26198sendflow(struct stlport *portp, int state);
461 static void stl_sc26198flush(struct stlport *portp);
462 static int stl_sc26198datastate(struct stlport *portp);
463 static void stl_sc26198wait(struct stlport *portp);
464 static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty);
465 static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase);
466 static void stl_sc26198txisr(struct stlport *port);
467 static void stl_sc26198rxisr(struct stlport *port, unsigned int iack);
468 static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch);
469 static void stl_sc26198rxbadchars(struct stlport *portp);
470 static void stl_sc26198otherisr(struct stlport *port, unsigned int iack);
472 /*****************************************************************************/
475 * Generic UART support structure.
477 typedef struct uart {
478 int (*panelinit)(struct stlbrd *brdp, struct stlpanel *panelp);
479 void (*portinit)(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
480 void (*setport)(struct stlport *portp, struct ktermios *tiosp);
481 int (*getsignals)(struct stlport *portp);
482 void (*setsignals)(struct stlport *portp, int dtr, int rts);
483 void (*enablerxtx)(struct stlport *portp, int rx, int tx);
484 void (*startrxtx)(struct stlport *portp, int rx, int tx);
485 void (*disableintrs)(struct stlport *portp);
486 void (*sendbreak)(struct stlport *portp, int len);
487 void (*flowctrl)(struct stlport *portp, int state);
488 void (*sendflow)(struct stlport *portp, int state);
489 void (*flush)(struct stlport *portp);
490 int (*datastate)(struct stlport *portp);
491 void (*intr)(struct stlpanel *panelp, unsigned int iobase);
495 * Define some macros to make calling these functions nice and clean.
497 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
498 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
499 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
500 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
501 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
502 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
503 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
504 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
505 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
506 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
507 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
508 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
509 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
511 /*****************************************************************************/
514 * CD1400 UART specific data initialization.
516 static uart_t stl_cd1400uart = {
520 stl_cd1400getsignals,
521 stl_cd1400setsignals,
522 stl_cd1400enablerxtx,
524 stl_cd1400disableintrs,
534 * Define the offsets within the register bank of a cd1400 based panel.
535 * These io address offsets are common to the EasyIO board as well.
543 #define EREG_BANKSIZE 8
545 #define CD1400_CLK 25000000
546 #define CD1400_CLK8M 20000000
549 * Define the cd1400 baud rate clocks. These are used when calculating
550 * what clock and divisor to use for the required baud rate. Also
551 * define the maximum baud rate allowed, and the default base baud.
553 static int stl_cd1400clkdivs[] = {
554 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
557 /*****************************************************************************/
560 * SC26198 UART specific data initization.
562 static uart_t stl_sc26198uart = {
563 stl_sc26198panelinit,
566 stl_sc26198getsignals,
567 stl_sc26198setsignals,
568 stl_sc26198enablerxtx,
569 stl_sc26198startrxtx,
570 stl_sc26198disableintrs,
571 stl_sc26198sendbreak,
575 stl_sc26198datastate,
580 * Define the offsets within the register bank of a sc26198 based panel.
588 #define XP_BANKSIZE 4
591 * Define the sc26198 baud rate table. Offsets within the table
592 * represent the actual baud rate selector of sc26198 registers.
594 static unsigned int sc26198_baudtable[] = {
595 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
596 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
597 230400, 460800, 921600
600 #define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
602 /*****************************************************************************/
605 * Define the driver info for a user level control device. Used mainly
606 * to get at port stats - only not using the port device itself.
608 static const struct file_operations stl_fsiomem = {
609 .owner = THIS_MODULE,
610 .unlocked_ioctl = stl_memioctl,
613 static struct class *stallion_class;
615 static void stl_cd_change(struct stlport *portp)
617 unsigned int oldsigs = portp->sigs;
618 struct tty_struct *tty = tty_port_tty_get(&portp->port);
623 portp->sigs = stl_getsignals(portp);
625 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
626 wake_up_interruptible(&portp->port.open_wait);
628 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0))
629 if (portp->port.flags & ASYNC_CHECK_CD)
635 * Check for any arguments passed in on the module load command line.
638 /*****************************************************************************/
641 * Parse the supplied argument string, into the board conf struct.
644 static int __init stl_parsebrd(struct stlconf *confp, char **argp)
649 pr_debug("stl_parsebrd(confp=%p,argp=%p)\n", confp, argp);
651 if ((argp[0] == NULL) || (*argp[0] == 0))
654 for (sp = argp[0], i = 0; (*sp != 0) && (i < 25); sp++, i++)
657 for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++)
658 if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
661 if (i == ARRAY_SIZE(stl_brdstr)) {
662 printk("STALLION: unknown board name, %s?\n", argp[0]);
666 confp->brdtype = stl_brdstr[i].type;
669 if ((argp[i] != NULL) && (*argp[i] != 0))
670 confp->ioaddr1 = simple_strtoul(argp[i], NULL, 0);
672 if (confp->brdtype == BRD_ECH) {
673 if ((argp[i] != NULL) && (*argp[i] != 0))
674 confp->ioaddr2 = simple_strtoul(argp[i], NULL, 0);
677 if ((argp[i] != NULL) && (*argp[i] != 0))
678 confp->irq = simple_strtoul(argp[i], NULL, 0);
682 /*****************************************************************************/
685 * Allocate a new board structure. Fill out the basic info in it.
688 static struct stlbrd *stl_allocbrd(void)
692 brdp = kzalloc(sizeof(struct stlbrd), GFP_KERNEL);
694 printk("STALLION: failed to allocate memory (size=%Zd)\n",
695 sizeof(struct stlbrd));
699 brdp->magic = STL_BOARDMAGIC;
703 /*****************************************************************************/
705 static int stl_activate(struct tty_port *port, struct tty_struct *tty)
707 struct stlport *portp = container_of(port, struct stlport, port);
708 if (!portp->tx.buf) {
709 portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
712 portp->tx.head = portp->tx.buf;
713 portp->tx.tail = portp->tx.buf;
715 stl_setport(portp, tty->termios);
716 portp->sigs = stl_getsignals(portp);
717 stl_setsignals(portp, 1, 1);
718 stl_enablerxtx(portp, 1, 1);
719 stl_startrxtx(portp, 1, 0);
723 static int stl_open(struct tty_struct *tty, struct file *filp)
725 struct stlport *portp;
727 struct tty_port *port;
728 unsigned int minordev, brdnr, panelnr;
731 pr_debug("stl_open(tty=%p,filp=%p): device=%s\n", tty, filp, tty->name);
733 minordev = tty->index;
734 brdnr = MINOR2BRD(minordev);
735 if (brdnr >= stl_nrbrds)
737 brdp = stl_brds[brdnr];
741 minordev = MINOR2PORT(minordev);
742 for (portnr = -1, panelnr = 0; panelnr < STL_MAXPANELS; panelnr++) {
743 if (brdp->panels[panelnr] == NULL)
745 if (minordev < brdp->panels[panelnr]->nrports) {
749 minordev -= brdp->panels[panelnr]->nrports;
754 portp = brdp->panels[panelnr]->ports[portnr];
758 return tty_port_open(&portp->port, tty, filp);
762 /*****************************************************************************/
764 static int stl_carrier_raised(struct tty_port *port)
766 struct stlport *portp = container_of(port, struct stlport, port);
767 return (portp->sigs & TIOCM_CD) ? 1 : 0;
770 static void stl_dtr_rts(struct tty_port *port, int on)
772 struct stlport *portp = container_of(port, struct stlport, port);
773 /* Takes brd_lock internally */
774 stl_setsignals(portp, on, on);
777 /*****************************************************************************/
779 static void stl_flushbuffer(struct tty_struct *tty)
781 struct stlport *portp;
783 pr_debug("stl_flushbuffer(tty=%p)\n", tty);
785 portp = tty->driver_data;
793 /*****************************************************************************/
795 static void stl_waituntilsent(struct tty_struct *tty, int timeout)
797 struct stlport *portp;
800 pr_debug("stl_waituntilsent(tty=%p,timeout=%d)\n", tty, timeout);
802 portp = tty->driver_data;
808 tend = jiffies + timeout;
811 while (stl_datastate(portp)) {
812 if (signal_pending(current))
814 msleep_interruptible(20);
815 if (time_after_eq(jiffies, tend))
821 /*****************************************************************************/
823 static void stl_shutdown(struct tty_port *port)
825 struct stlport *portp = container_of(port, struct stlport, port);
826 stl_disableintrs(portp);
827 stl_enablerxtx(portp, 0, 0);
830 if (portp->tx.buf != NULL) {
831 kfree(portp->tx.buf);
832 portp->tx.buf = NULL;
833 portp->tx.head = NULL;
834 portp->tx.tail = NULL;
838 static void stl_close(struct tty_struct *tty, struct file *filp)
840 struct stlport*portp;
841 pr_debug("stl_close(tty=%p,filp=%p)\n", tty, filp);
843 portp = tty->driver_data;
844 BUG_ON(portp == NULL);
845 tty_port_close(&portp->port, tty, filp);
848 /*****************************************************************************/
851 * Write routine. Take data and stuff it in to the TX ring queue.
852 * If transmit interrupts are not running then start them.
855 static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
857 struct stlport *portp;
858 unsigned int len, stlen;
859 unsigned char *chbuf;
862 pr_debug("stl_write(tty=%p,buf=%p,count=%d)\n", tty, buf, count);
864 portp = tty->driver_data;
867 if (portp->tx.buf == NULL)
871 * If copying direct from user space we must cater for page faults,
872 * causing us to "sleep" here for a while. To handle this copy in all
873 * the data we need now, into a local buffer. Then when we got it all
874 * copy it into the TX buffer.
876 chbuf = (unsigned char *) buf;
878 head = portp->tx.head;
879 tail = portp->tx.tail;
881 len = STL_TXBUFSIZE - (head - tail) - 1;
882 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
884 len = tail - head - 1;
888 len = min(len, (unsigned int)count);
891 stlen = min(len, stlen);
892 memcpy(head, chbuf, stlen);
897 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
898 head = portp->tx.buf;
902 portp->tx.head = head;
904 clear_bit(ASYI_TXLOW, &portp->istate);
905 stl_startrxtx(portp, -1, 1);
910 /*****************************************************************************/
912 static int stl_putchar(struct tty_struct *tty, unsigned char ch)
914 struct stlport *portp;
918 pr_debug("stl_putchar(tty=%p,ch=%x)\n", tty, ch);
920 portp = tty->driver_data;
923 if (portp->tx.buf == NULL)
926 head = portp->tx.head;
927 tail = portp->tx.tail;
929 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
934 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
935 head = portp->tx.buf;
937 portp->tx.head = head;
941 /*****************************************************************************/
944 * If there are any characters in the buffer then make sure that TX
945 * interrupts are on and get'em out. Normally used after the putchar
946 * routine has been called.
949 static void stl_flushchars(struct tty_struct *tty)
951 struct stlport *portp;
953 pr_debug("stl_flushchars(tty=%p)\n", tty);
955 portp = tty->driver_data;
958 if (portp->tx.buf == NULL)
961 stl_startrxtx(portp, -1, 1);
964 /*****************************************************************************/
966 static int stl_writeroom(struct tty_struct *tty)
968 struct stlport *portp;
971 pr_debug("stl_writeroom(tty=%p)\n", tty);
973 portp = tty->driver_data;
976 if (portp->tx.buf == NULL)
979 head = portp->tx.head;
980 tail = portp->tx.tail;
981 return (head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1);
984 /*****************************************************************************/
987 * Return number of chars in the TX buffer. Normally we would just
988 * calculate the number of chars in the buffer and return that, but if
989 * the buffer is empty and TX interrupts are still on then we return
990 * that the buffer still has 1 char in it. This way whoever called us
991 * will not think that ALL chars have drained - since the UART still
992 * must have some chars in it (we are busy after all).
995 static int stl_charsinbuffer(struct tty_struct *tty)
997 struct stlport *portp;
1001 pr_debug("stl_charsinbuffer(tty=%p)\n", tty);
1003 portp = tty->driver_data;
1006 if (portp->tx.buf == NULL)
1009 head = portp->tx.head;
1010 tail = portp->tx.tail;
1011 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1012 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1017 /*****************************************************************************/
1020 * Generate the serial struct info.
1023 static int stl_getserial(struct stlport *portp, struct serial_struct __user *sp)
1025 struct serial_struct sio;
1026 struct stlbrd *brdp;
1028 pr_debug("stl_getserial(portp=%p,sp=%p)\n", portp, sp);
1030 memset(&sio, 0, sizeof(struct serial_struct));
1031 sio.line = portp->portnr;
1032 sio.port = portp->ioaddr;
1033 sio.flags = portp->port.flags;
1034 sio.baud_base = portp->baud_base;
1035 sio.close_delay = portp->close_delay;
1036 sio.closing_wait = portp->closing_wait;
1037 sio.custom_divisor = portp->custom_divisor;
1039 if (portp->uartp == &stl_cd1400uart) {
1040 sio.type = PORT_CIRRUS;
1041 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1043 sio.type = PORT_UNKNOWN;
1044 sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1047 brdp = stl_brds[portp->brdnr];
1049 sio.irq = brdp->irq;
1051 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
1054 /*****************************************************************************/
1057 * Set port according to the serial struct info.
1058 * At this point we do not do any auto-configure stuff, so we will
1059 * just quietly ignore any requests to change irq, etc.
1062 static int stl_setserial(struct tty_struct *tty, struct serial_struct __user *sp)
1064 struct stlport * portp = tty->driver_data;
1065 struct serial_struct sio;
1067 pr_debug("stl_setserial(portp=%p,sp=%p)\n", portp, sp);
1069 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1071 if (!capable(CAP_SYS_ADMIN)) {
1072 if ((sio.baud_base != portp->baud_base) ||
1073 (sio.close_delay != portp->close_delay) ||
1074 ((sio.flags & ~ASYNC_USR_MASK) !=
1075 (portp->port.flags & ~ASYNC_USR_MASK)))
1079 portp->port.flags = (portp->port.flags & ~ASYNC_USR_MASK) |
1080 (sio.flags & ASYNC_USR_MASK);
1081 portp->baud_base = sio.baud_base;
1082 portp->close_delay = sio.close_delay;
1083 portp->closing_wait = sio.closing_wait;
1084 portp->custom_divisor = sio.custom_divisor;
1085 stl_setport(portp, tty->termios);
1089 /*****************************************************************************/
1091 static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1093 struct stlport *portp;
1095 portp = tty->driver_data;
1098 if (tty->flags & (1 << TTY_IO_ERROR))
1101 return stl_getsignals(portp);
1104 static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1105 unsigned int set, unsigned int clear)
1107 struct stlport *portp;
1108 int rts = -1, dtr = -1;
1110 portp = tty->driver_data;
1113 if (tty->flags & (1 << TTY_IO_ERROR))
1116 if (set & TIOCM_RTS)
1118 if (set & TIOCM_DTR)
1120 if (clear & TIOCM_RTS)
1122 if (clear & TIOCM_DTR)
1125 stl_setsignals(portp, dtr, rts);
1129 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1131 struct stlport *portp;
1133 void __user *argp = (void __user *)arg;
1135 pr_debug("stl_ioctl(tty=%p,file=%p,cmd=%x,arg=%lx)\n", tty, file, cmd,
1138 portp = tty->driver_data;
1142 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1143 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS))
1144 if (tty->flags & (1 << TTY_IO_ERROR))
1153 rc = stl_getserial(portp, argp);
1156 rc = stl_setserial(tty, argp);
1158 case COM_GETPORTSTATS:
1159 rc = stl_getportstats(tty, portp, argp);
1161 case COM_CLRPORTSTATS:
1162 rc = stl_clrportstats(portp, argp);
1168 case TIOCSERGSTRUCT:
1169 case TIOCSERGETMULTI:
1170 case TIOCSERSETMULTI:
1179 /*****************************************************************************/
1182 * Start the transmitter again. Just turn TX interrupts back on.
1185 static void stl_start(struct tty_struct *tty)
1187 struct stlport *portp;
1189 pr_debug("stl_start(tty=%p)\n", tty);
1191 portp = tty->driver_data;
1194 stl_startrxtx(portp, -1, 1);
1197 /*****************************************************************************/
1199 static void stl_settermios(struct tty_struct *tty, struct ktermios *old)
1201 struct stlport *portp;
1202 struct ktermios *tiosp;
1204 pr_debug("stl_settermios(tty=%p,old=%p)\n", tty, old);
1206 portp = tty->driver_data;
1210 tiosp = tty->termios;
1211 if ((tiosp->c_cflag == old->c_cflag) &&
1212 (tiosp->c_iflag == old->c_iflag))
1215 stl_setport(portp, tiosp);
1216 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1218 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1219 tty->hw_stopped = 0;
1222 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1223 wake_up_interruptible(&portp->port.open_wait);
1226 /*****************************************************************************/
1229 * Attempt to flow control who ever is sending us data. Based on termios
1230 * settings use software or/and hardware flow control.
1233 static void stl_throttle(struct tty_struct *tty)
1235 struct stlport *portp;
1237 pr_debug("stl_throttle(tty=%p)\n", tty);
1239 portp = tty->driver_data;
1242 stl_flowctrl(portp, 0);
1245 /*****************************************************************************/
1248 * Unflow control the device sending us data...
1251 static void stl_unthrottle(struct tty_struct *tty)
1253 struct stlport *portp;
1255 pr_debug("stl_unthrottle(tty=%p)\n", tty);
1257 portp = tty->driver_data;
1260 stl_flowctrl(portp, 1);
1263 /*****************************************************************************/
1266 * Stop the transmitter. Basically to do this we will just turn TX
1270 static void stl_stop(struct tty_struct *tty)
1272 struct stlport *portp;
1274 pr_debug("stl_stop(tty=%p)\n", tty);
1276 portp = tty->driver_data;
1279 stl_startrxtx(portp, -1, 0);
1282 /*****************************************************************************/
1285 * Hangup this port. This is pretty much like closing the port, only
1286 * a little more brutal. No waiting for data to drain. Shutdown the
1287 * port and maybe drop signals.
1290 static void stl_hangup(struct tty_struct *tty)
1292 struct stlport *portp = tty->driver_data;
1293 pr_debug("stl_hangup(tty=%p)\n", tty);
1297 tty_port_hangup(&portp->port);
1300 /*****************************************************************************/
1302 static int stl_breakctl(struct tty_struct *tty, int state)
1304 struct stlport *portp;
1306 pr_debug("stl_breakctl(tty=%p,state=%d)\n", tty, state);
1308 portp = tty->driver_data;
1312 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1316 /*****************************************************************************/
1318 static void stl_sendxchar(struct tty_struct *tty, char ch)
1320 struct stlport *portp;
1322 pr_debug("stl_sendxchar(tty=%p,ch=%x)\n", tty, ch);
1324 portp = tty->driver_data;
1328 if (ch == STOP_CHAR(tty))
1329 stl_sendflow(portp, 0);
1330 else if (ch == START_CHAR(tty))
1331 stl_sendflow(portp, 1);
1333 stl_putchar(tty, ch);
1336 static void stl_portinfo(struct seq_file *m, struct stlport *portp, int portnr)
1341 seq_printf(m, "%d: uart:%s tx:%d rx:%d",
1342 portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
1343 (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
1345 if (portp->stats.rxframing)
1346 seq_printf(m, " fe:%d", (int) portp->stats.rxframing);
1347 if (portp->stats.rxparity)
1348 seq_printf(m, " pe:%d", (int) portp->stats.rxparity);
1349 if (portp->stats.rxbreaks)
1350 seq_printf(m, " brk:%d", (int) portp->stats.rxbreaks);
1351 if (portp->stats.rxoverrun)
1352 seq_printf(m, " oe:%d", (int) portp->stats.rxoverrun);
1354 sigs = stl_getsignals(portp);
1356 if (sigs & TIOCM_RTS) {
1357 seq_printf(m, "%c%s", sep, "RTS");
1360 if (sigs & TIOCM_CTS) {
1361 seq_printf(m, "%c%s", sep, "CTS");
1364 if (sigs & TIOCM_DTR) {
1365 seq_printf(m, "%c%s", sep, "DTR");
1368 if (sigs & TIOCM_CD) {
1369 seq_printf(m, "%c%s", sep, "DCD");
1372 if (sigs & TIOCM_DSR) {
1373 seq_printf(m, "%c%s", sep, "DSR");
1379 /*****************************************************************************/
1382 * Port info, read from the /proc file system.
1385 static int stl_proc_show(struct seq_file *m, void *v)
1387 struct stlbrd *brdp;
1388 struct stlpanel *panelp;
1389 struct stlport *portp;
1390 unsigned int brdnr, panelnr, portnr;
1395 seq_printf(m, "%s: version %s\n", stl_drvtitle, stl_drvversion);
1398 * We scan through for each board, panel and port. The offset is
1399 * calculated on the fly, and irrelevant ports are skipped.
1401 for (brdnr = 0; brdnr < stl_nrbrds; brdnr++) {
1402 brdp = stl_brds[brdnr];
1405 if (brdp->state == 0)
1408 totalport = brdnr * STL_MAXPORTS;
1409 for (panelnr = 0; panelnr < brdp->nrpanels; panelnr++) {
1410 panelp = brdp->panels[panelnr];
1414 for (portnr = 0; portnr < panelp->nrports; portnr++,
1416 portp = panelp->ports[portnr];
1419 stl_portinfo(m, portp, totalport);
1426 static int stl_proc_open(struct inode *inode, struct file *file)
1428 return single_open(file, stl_proc_show, NULL);
1431 static const struct file_operations stl_proc_fops = {
1432 .owner = THIS_MODULE,
1433 .open = stl_proc_open,
1435 .llseek = seq_lseek,
1436 .release = single_release,
1439 /*****************************************************************************/
1442 * All board interrupts are vectored through here first. This code then
1443 * calls off to the approrpriate board interrupt handlers.
1446 static irqreturn_t stl_intr(int irq, void *dev_id)
1448 struct stlbrd *brdp = dev_id;
1450 pr_debug("stl_intr(brdp=%p,irq=%d)\n", brdp, brdp->irq);
1452 return IRQ_RETVAL((* brdp->isr)(brdp));
1455 /*****************************************************************************/
1458 * Interrupt service routine for EasyIO board types.
1461 static int stl_eiointr(struct stlbrd *brdp)
1463 struct stlpanel *panelp;
1464 unsigned int iobase;
1467 spin_lock(&brd_lock);
1468 panelp = brdp->panels[0];
1469 iobase = panelp->iobase;
1470 while (inb(brdp->iostatus) & EIO_INTRPEND) {
1472 (* panelp->isr)(panelp, iobase);
1474 spin_unlock(&brd_lock);
1478 /*****************************************************************************/
1481 * Interrupt service routine for ECH-AT board types.
1484 static int stl_echatintr(struct stlbrd *brdp)
1486 struct stlpanel *panelp;
1487 unsigned int ioaddr, bnknr;
1490 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
1492 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1494 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
1495 ioaddr = brdp->bnkstataddr[bnknr];
1496 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1497 panelp = brdp->bnk2panel[bnknr];
1498 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1503 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
1508 /*****************************************************************************/
1511 * Interrupt service routine for ECH-MCA board types.
1514 static int stl_echmcaintr(struct stlbrd *brdp)
1516 struct stlpanel *panelp;
1517 unsigned int ioaddr, bnknr;
1520 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1522 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
1523 ioaddr = brdp->bnkstataddr[bnknr];
1524 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1525 panelp = brdp->bnk2panel[bnknr];
1526 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1533 /*****************************************************************************/
1536 * Interrupt service routine for ECH-PCI board types.
1539 static int stl_echpciintr(struct stlbrd *brdp)
1541 struct stlpanel *panelp;
1542 unsigned int ioaddr, bnknr, recheck;
1547 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
1548 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
1549 ioaddr = brdp->bnkstataddr[bnknr];
1550 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1551 panelp = brdp->bnk2panel[bnknr];
1552 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1563 /*****************************************************************************/
1566 * Interrupt service routine for ECH-8/64-PCI board types.
1569 static int stl_echpci64intr(struct stlbrd *brdp)
1571 struct stlpanel *panelp;
1572 unsigned int ioaddr, bnknr;
1575 while (inb(brdp->ioctrl) & 0x1) {
1577 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
1578 ioaddr = brdp->bnkstataddr[bnknr];
1579 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1580 panelp = brdp->bnk2panel[bnknr];
1581 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1589 /*****************************************************************************/
1592 * Initialize all the ports on a panel.
1595 static int __devinit stl_initports(struct stlbrd *brdp, struct stlpanel *panelp)
1597 struct stlport *portp;
1601 pr_debug("stl_initports(brdp=%p,panelp=%p)\n", brdp, panelp);
1603 chipmask = stl_panelinit(brdp, panelp);
1606 * All UART's are initialized (if found!). Now go through and setup
1607 * each ports data structures.
1609 for (i = 0; i < panelp->nrports; i++) {
1610 portp = kzalloc(sizeof(struct stlport), GFP_KERNEL);
1612 printk("STALLION: failed to allocate memory "
1613 "(size=%Zd)\n", sizeof(struct stlport));
1616 tty_port_init(&portp->port);
1617 portp->port.ops = &stl_port_ops;
1618 portp->magic = STL_PORTMAGIC;
1620 portp->brdnr = panelp->brdnr;
1621 portp->panelnr = panelp->panelnr;
1622 portp->uartp = panelp->uartp;
1623 portp->clk = brdp->clk;
1624 portp->baud_base = STL_BAUDBASE;
1625 portp->close_delay = STL_CLOSEDELAY;
1626 portp->closing_wait = 30 * HZ;
1627 init_waitqueue_head(&portp->port.open_wait);
1628 init_waitqueue_head(&portp->port.close_wait);
1629 portp->stats.brd = portp->brdnr;
1630 portp->stats.panel = portp->panelnr;
1631 portp->stats.port = portp->portnr;
1632 panelp->ports[i] = portp;
1633 stl_portinit(brdp, panelp, portp);
1639 static void stl_cleanup_panels(struct stlbrd *brdp)
1641 struct stlpanel *panelp;
1642 struct stlport *portp;
1644 struct tty_struct *tty;
1646 for (j = 0; j < STL_MAXPANELS; j++) {
1647 panelp = brdp->panels[j];
1650 for (k = 0; k < STL_PORTSPERPANEL; k++) {
1651 portp = panelp->ports[k];
1654 tty = tty_port_tty_get(&portp->port);
1659 kfree(portp->tx.buf);
1666 /*****************************************************************************/
1669 * Try to find and initialize an EasyIO board.
1672 static int __devinit stl_initeio(struct stlbrd *brdp)
1674 struct stlpanel *panelp;
1675 unsigned int status;
1679 pr_debug("stl_initeio(brdp=%p)\n", brdp);
1681 brdp->ioctrl = brdp->ioaddr1 + 1;
1682 brdp->iostatus = brdp->ioaddr1 + 2;
1684 status = inb(brdp->iostatus);
1685 if ((status & EIO_IDBITMASK) == EIO_MK3)
1689 * Handle board specific stuff now. The real difference is PCI
1692 if (brdp->brdtype == BRD_EASYIOPCI) {
1693 brdp->iosize1 = 0x80;
1694 brdp->iosize2 = 0x80;
1695 name = "serial(EIO-PCI)";
1696 outb(0x41, (brdp->ioaddr2 + 0x4c));
1699 name = "serial(EIO)";
1700 if ((brdp->irq < 0) || (brdp->irq > 15) ||
1701 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
1702 printk("STALLION: invalid irq=%d for brd=%d\n",
1703 brdp->irq, brdp->brdnr);
1707 outb((stl_vecmap[brdp->irq] | EIO_0WS |
1708 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
1713 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
1714 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
1715 "%x conflicts with another device\n", brdp->brdnr,
1720 if (brdp->iosize2 > 0)
1721 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
1722 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
1723 "address %x conflicts with another device\n",
1724 brdp->brdnr, brdp->ioaddr2);
1725 printk(KERN_WARNING "STALLION: Warning, also "
1726 "releasing board %d I/O address %x \n",
1727 brdp->brdnr, brdp->ioaddr1);
1732 * Everything looks OK, so let's go ahead and probe for the hardware.
1734 brdp->clk = CD1400_CLK;
1735 brdp->isr = stl_eiointr;
1738 switch (status & EIO_IDBITMASK) {
1740 brdp->clk = CD1400_CLK8M;
1750 switch (status & EIO_BRDMASK) {
1769 * We have verified that the board is actually present, so now we
1770 * can complete the setup.
1773 panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
1775 printk(KERN_WARNING "STALLION: failed to allocate memory "
1776 "(size=%Zd)\n", sizeof(struct stlpanel));
1781 panelp->magic = STL_PANELMAGIC;
1782 panelp->brdnr = brdp->brdnr;
1783 panelp->panelnr = 0;
1784 panelp->nrports = brdp->nrports;
1785 panelp->iobase = brdp->ioaddr1;
1786 panelp->hwid = status;
1787 if ((status & EIO_IDBITMASK) == EIO_MK3) {
1788 panelp->uartp = &stl_sc26198uart;
1789 panelp->isr = stl_sc26198intr;
1791 panelp->uartp = &stl_cd1400uart;
1792 panelp->isr = stl_cd1400eiointr;
1795 brdp->panels[0] = panelp;
1797 brdp->state |= BRD_FOUND;
1798 brdp->hwid = status;
1799 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
1800 printk("STALLION: failed to register interrupt "
1801 "routine for %s irq=%d\n", name, brdp->irq);
1808 stl_cleanup_panels(brdp);
1810 if (brdp->iosize2 > 0)
1811 release_region(brdp->ioaddr2, brdp->iosize2);
1813 release_region(brdp->ioaddr1, brdp->iosize1);
1818 /*****************************************************************************/
1821 * Try to find an ECH board and initialize it. This code is capable of
1822 * dealing with all types of ECH board.
1825 static int __devinit stl_initech(struct stlbrd *brdp)
1827 struct stlpanel *panelp;
1828 unsigned int status, nxtid, ioaddr, conflict, panelnr, banknr, i;
1832 pr_debug("stl_initech(brdp=%p)\n", brdp);
1838 * Set up the initial board register contents for boards. This varies a
1839 * bit between the different board types. So we need to handle each
1840 * separately. Also do a check that the supplied IRQ is good.
1842 switch (brdp->brdtype) {
1845 brdp->isr = stl_echatintr;
1846 brdp->ioctrl = brdp->ioaddr1 + 1;
1847 brdp->iostatus = brdp->ioaddr1 + 1;
1848 status = inb(brdp->iostatus);
1849 if ((status & ECH_IDBITMASK) != ECH_ID) {
1853 if ((brdp->irq < 0) || (brdp->irq > 15) ||
1854 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
1855 printk("STALLION: invalid irq=%d for brd=%d\n",
1856 brdp->irq, brdp->brdnr);
1860 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
1861 status |= (stl_vecmap[brdp->irq] << 1);
1862 outb((status | ECH_BRDRESET), brdp->ioaddr1);
1863 brdp->ioctrlval = ECH_INTENABLE |
1864 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
1865 for (i = 0; i < 10; i++)
1866 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
1869 name = "serial(EC8/32)";
1870 outb(status, brdp->ioaddr1);
1874 brdp->isr = stl_echmcaintr;
1875 brdp->ioctrl = brdp->ioaddr1 + 0x20;
1876 brdp->iostatus = brdp->ioctrl;
1877 status = inb(brdp->iostatus);
1878 if ((status & ECH_IDBITMASK) != ECH_ID) {
1882 if ((brdp->irq < 0) || (brdp->irq > 15) ||
1883 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
1884 printk("STALLION: invalid irq=%d for brd=%d\n",
1885 brdp->irq, brdp->brdnr);
1889 outb(ECHMC_BRDRESET, brdp->ioctrl);
1890 outb(ECHMC_INTENABLE, brdp->ioctrl);
1892 name = "serial(EC8/32-MC)";
1896 brdp->isr = stl_echpciintr;
1897 brdp->ioctrl = brdp->ioaddr1 + 2;
1900 name = "serial(EC8/32-PCI)";
1904 brdp->isr = stl_echpci64intr;
1905 brdp->ioctrl = brdp->ioaddr2 + 0x40;
1906 outb(0x43, (brdp->ioaddr1 + 0x4c));
1907 brdp->iosize1 = 0x80;
1908 brdp->iosize2 = 0x80;
1909 name = "serial(EC8/64-PCI)";
1913 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
1919 * Check boards for possible IO address conflicts and return fail status
1920 * if an IO conflict found.
1923 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
1924 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
1925 "%x conflicts with another device\n", brdp->brdnr,
1930 if (brdp->iosize2 > 0)
1931 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
1932 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
1933 "address %x conflicts with another device\n",
1934 brdp->brdnr, brdp->ioaddr2);
1935 printk(KERN_WARNING "STALLION: Warning, also "
1936 "releasing board %d I/O address %x \n",
1937 brdp->brdnr, brdp->ioaddr1);
1942 * Scan through the secondary io address space looking for panels.
1943 * As we find'em allocate and initialize panel structures for each.
1945 brdp->clk = CD1400_CLK;
1946 brdp->hwid = status;
1948 ioaddr = brdp->ioaddr2;
1953 for (i = 0; i < STL_MAXPANELS; i++) {
1954 if (brdp->brdtype == BRD_ECHPCI) {
1955 outb(nxtid, brdp->ioctrl);
1956 ioaddr = brdp->ioaddr2;
1958 status = inb(ioaddr + ECH_PNLSTATUS);
1959 if ((status & ECH_PNLIDMASK) != nxtid)
1961 panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
1963 printk("STALLION: failed to allocate memory "
1964 "(size=%Zd)\n", sizeof(struct stlpanel));
1968 panelp->magic = STL_PANELMAGIC;
1969 panelp->brdnr = brdp->brdnr;
1970 panelp->panelnr = panelnr;
1971 panelp->iobase = ioaddr;
1972 panelp->pagenr = nxtid;
1973 panelp->hwid = status;
1974 brdp->bnk2panel[banknr] = panelp;
1975 brdp->bnkpageaddr[banknr] = nxtid;
1976 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
1978 if (status & ECH_PNLXPID) {
1979 panelp->uartp = &stl_sc26198uart;
1980 panelp->isr = stl_sc26198intr;
1981 if (status & ECH_PNL16PORT) {
1982 panelp->nrports = 16;
1983 brdp->bnk2panel[banknr] = panelp;
1984 brdp->bnkpageaddr[banknr] = nxtid;
1985 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
1988 panelp->nrports = 8;
1990 panelp->uartp = &stl_cd1400uart;
1991 panelp->isr = stl_cd1400echintr;
1992 if (status & ECH_PNL16PORT) {
1993 panelp->nrports = 16;
1994 panelp->ackmask = 0x80;
1995 if (brdp->brdtype != BRD_ECHPCI)
1996 ioaddr += EREG_BANKSIZE;
1997 brdp->bnk2panel[banknr] = panelp;
1998 brdp->bnkpageaddr[banknr] = ++nxtid;
1999 brdp->bnkstataddr[banknr++] = ioaddr +
2002 panelp->nrports = 8;
2003 panelp->ackmask = 0xc0;
2008 ioaddr += EREG_BANKSIZE;
2009 brdp->nrports += panelp->nrports;
2010 brdp->panels[panelnr++] = panelp;
2011 if ((brdp->brdtype != BRD_ECHPCI) &&
2012 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2))) {
2018 brdp->nrpanels = panelnr;
2019 brdp->nrbnks = banknr;
2020 if (brdp->brdtype == BRD_ECH)
2021 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2023 brdp->state |= BRD_FOUND;
2024 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
2025 printk("STALLION: failed to register interrupt "
2026 "routine for %s irq=%d\n", name, brdp->irq);
2033 stl_cleanup_panels(brdp);
2034 if (brdp->iosize2 > 0)
2035 release_region(brdp->ioaddr2, brdp->iosize2);
2037 release_region(brdp->ioaddr1, brdp->iosize1);
2042 /*****************************************************************************/
2045 * Initialize and configure the specified board.
2046 * Scan through all the boards in the configuration and see what we
2047 * can find. Handle EIO and the ECH boards a little differently here
2048 * since the initial search and setup is very different.
2051 static int __devinit stl_brdinit(struct stlbrd *brdp)
2055 pr_debug("stl_brdinit(brdp=%p)\n", brdp);
2057 switch (brdp->brdtype) {
2060 retval = stl_initeio(brdp);
2068 retval = stl_initech(brdp);
2073 printk("STALLION: board=%d is unknown board type=%d\n",
2074 brdp->brdnr, brdp->brdtype);
2079 if ((brdp->state & BRD_FOUND) == 0) {
2080 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2081 stl_brdnames[brdp->brdtype], brdp->brdnr,
2082 brdp->ioaddr1, brdp->irq);
2086 for (i = 0; i < STL_MAXPANELS; i++)
2087 if (brdp->panels[i] != NULL)
2088 stl_initports(brdp, brdp->panels[i]);
2090 printk("STALLION: %s found, board=%d io=%x irq=%d "
2091 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2092 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2097 free_irq(brdp->irq, brdp);
2099 stl_cleanup_panels(brdp);
2101 release_region(brdp->ioaddr1, brdp->iosize1);
2102 if (brdp->iosize2 > 0)
2103 release_region(brdp->ioaddr2, brdp->iosize2);
2108 /*****************************************************************************/
2111 * Find the next available board number that is free.
2114 static int __devinit stl_getbrdnr(void)
2118 for (i = 0; i < STL_MAXBRDS; i++)
2119 if (stl_brds[i] == NULL) {
2120 if (i >= stl_nrbrds)
2128 /*****************************************************************************/
2130 * We have a Stallion board. Allocate a board structure and
2131 * initialize it. Read its IO and IRQ resources from PCI
2132 * configuration space.
2135 static int __devinit stl_pciprobe(struct pci_dev *pdev,
2136 const struct pci_device_id *ent)
2138 struct stlbrd *brdp;
2139 unsigned int i, brdtype = ent->driver_data;
2140 int brdnr, retval = -ENODEV;
2142 if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2145 retval = pci_enable_device(pdev);
2148 brdp = stl_allocbrd();
2153 mutex_lock(&stl_brdslock);
2154 brdnr = stl_getbrdnr();
2156 dev_err(&pdev->dev, "too many boards found, "
2157 "maximum supported %d\n", STL_MAXBRDS);
2158 mutex_unlock(&stl_brdslock);
2162 brdp->brdnr = (unsigned int)brdnr;
2163 stl_brds[brdp->brdnr] = brdp;
2164 mutex_unlock(&stl_brdslock);
2166 brdp->brdtype = brdtype;
2167 brdp->state |= STL_PROBED;
2170 * We have all resources from the board, so let's setup the actual
2171 * board structure now.
2175 brdp->ioaddr2 = pci_resource_start(pdev, 0);
2176 brdp->ioaddr1 = pci_resource_start(pdev, 1);
2179 brdp->ioaddr2 = pci_resource_start(pdev, 2);
2180 brdp->ioaddr1 = pci_resource_start(pdev, 1);
2183 brdp->ioaddr1 = pci_resource_start(pdev, 2);
2184 brdp->ioaddr2 = pci_resource_start(pdev, 1);
2187 dev_err(&pdev->dev, "unknown PCI board type=%u\n", brdtype);
2191 brdp->irq = pdev->irq;
2192 retval = stl_brdinit(brdp);
2196 pci_set_drvdata(pdev, brdp);
2198 for (i = 0; i < brdp->nrports; i++)
2199 tty_register_device(stl_serial,
2200 brdp->brdnr * STL_MAXPORTS + i, &pdev->dev);
2204 stl_brds[brdp->brdnr] = NULL;
2211 static void __devexit stl_pciremove(struct pci_dev *pdev)
2213 struct stlbrd *brdp = pci_get_drvdata(pdev);
2216 free_irq(brdp->irq, brdp);
2218 stl_cleanup_panels(brdp);
2220 release_region(brdp->ioaddr1, brdp->iosize1);
2221 if (brdp->iosize2 > 0)
2222 release_region(brdp->ioaddr2, brdp->iosize2);
2224 for (i = 0; i < brdp->nrports; i++)
2225 tty_unregister_device(stl_serial,
2226 brdp->brdnr * STL_MAXPORTS + i);
2228 stl_brds[brdp->brdnr] = NULL;
2232 static struct pci_driver stl_pcidriver = {
2234 .id_table = stl_pcibrds,
2235 .probe = stl_pciprobe,
2236 .remove = __devexit_p(stl_pciremove)
2239 /*****************************************************************************/
2242 * Return the board stats structure to user app.
2245 static int stl_getbrdstats(combrd_t __user *bp)
2247 combrd_t stl_brdstats;
2248 struct stlbrd *brdp;
2249 struct stlpanel *panelp;
2252 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2254 if (stl_brdstats.brd >= STL_MAXBRDS)
2256 brdp = stl_brds[stl_brdstats.brd];
2260 memset(&stl_brdstats, 0, sizeof(combrd_t));
2261 stl_brdstats.brd = brdp->brdnr;
2262 stl_brdstats.type = brdp->brdtype;
2263 stl_brdstats.hwid = brdp->hwid;
2264 stl_brdstats.state = brdp->state;
2265 stl_brdstats.ioaddr = brdp->ioaddr1;
2266 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2267 stl_brdstats.irq = brdp->irq;
2268 stl_brdstats.nrpanels = brdp->nrpanels;
2269 stl_brdstats.nrports = brdp->nrports;
2270 for (i = 0; i < brdp->nrpanels; i++) {
2271 panelp = brdp->panels[i];
2272 stl_brdstats.panels[i].panel = i;
2273 stl_brdstats.panels[i].hwid = panelp->hwid;
2274 stl_brdstats.panels[i].nrports = panelp->nrports;
2277 return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
2280 /*****************************************************************************/
2283 * Resolve the referenced port number into a port struct pointer.
2286 static struct stlport *stl_getport(int brdnr, int panelnr, int portnr)
2288 struct stlbrd *brdp;
2289 struct stlpanel *panelp;
2291 if (brdnr < 0 || brdnr >= STL_MAXBRDS)
2293 brdp = stl_brds[brdnr];
2296 if (panelnr < 0 || (unsigned int)panelnr >= brdp->nrpanels)
2298 panelp = brdp->panels[panelnr];
2301 if (portnr < 0 || (unsigned int)portnr >= panelp->nrports)
2303 return panelp->ports[portnr];
2306 /*****************************************************************************/
2309 * Return the port stats structure to user app. A NULL port struct
2310 * pointer passed in means that we need to find out from the app
2311 * what port to get stats for (used through board control device).
2314 static int stl_getportstats(struct tty_struct *tty, struct stlport *portp, comstats_t __user *cp)
2316 comstats_t stl_comstats;
2317 unsigned char *head, *tail;
2318 unsigned long flags;
2321 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2323 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2329 portp->stats.state = portp->istate;
2330 portp->stats.flags = portp->port.flags;
2331 portp->stats.hwid = portp->hwid;
2333 portp->stats.ttystate = 0;
2334 portp->stats.cflags = 0;
2335 portp->stats.iflags = 0;
2336 portp->stats.oflags = 0;
2337 portp->stats.lflags = 0;
2338 portp->stats.rxbuffered = 0;
2340 spin_lock_irqsave(&stallion_lock, flags);
2341 if (tty != NULL && portp->port.tty == tty) {
2342 portp->stats.ttystate = tty->flags;
2343 /* No longer available as a statistic */
2344 portp->stats.rxbuffered = 1; /*tty->flip.count; */
2345 if (tty->termios != NULL) {
2346 portp->stats.cflags = tty->termios->c_cflag;
2347 portp->stats.iflags = tty->termios->c_iflag;
2348 portp->stats.oflags = tty->termios->c_oflag;
2349 portp->stats.lflags = tty->termios->c_lflag;
2352 spin_unlock_irqrestore(&stallion_lock, flags);
2354 head = portp->tx.head;
2355 tail = portp->tx.tail;
2356 portp->stats.txbuffered = (head >= tail) ? (head - tail) :
2357 (STL_TXBUFSIZE - (tail - head));
2359 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2361 return copy_to_user(cp, &portp->stats,
2362 sizeof(comstats_t)) ? -EFAULT : 0;
2365 /*****************************************************************************/
2368 * Clear the port stats structure. We also return it zeroed out...
2371 static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp)
2373 comstats_t stl_comstats;
2376 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2378 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2384 memset(&portp->stats, 0, sizeof(comstats_t));
2385 portp->stats.brd = portp->brdnr;
2386 portp->stats.panel = portp->panelnr;
2387 portp->stats.port = portp->portnr;
2388 return copy_to_user(cp, &portp->stats,
2389 sizeof(comstats_t)) ? -EFAULT : 0;
2392 /*****************************************************************************/
2395 * Return the entire driver ports structure to a user app.
2398 static int stl_getportstruct(struct stlport __user *arg)
2400 struct stlport stl_dummyport;
2401 struct stlport *portp;
2403 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
2405 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
2406 stl_dummyport.portnr);
2409 return copy_to_user(arg, portp, sizeof(struct stlport)) ? -EFAULT : 0;
2412 /*****************************************************************************/
2415 * Return the entire driver board structure to a user app.
2418 static int stl_getbrdstruct(struct stlbrd __user *arg)
2420 struct stlbrd stl_dummybrd;
2421 struct stlbrd *brdp;
2423 if (copy_from_user(&stl_dummybrd, arg, sizeof(struct stlbrd)))
2425 if (stl_dummybrd.brdnr >= STL_MAXBRDS)
2427 brdp = stl_brds[stl_dummybrd.brdnr];
2430 return copy_to_user(arg, brdp, sizeof(struct stlbrd)) ? -EFAULT : 0;
2433 /*****************************************************************************/
2436 * The "staliomem" device is also required to do some special operations
2437 * on the board and/or ports. In this driver it is mostly used for stats
2441 static long stl_memioctl(struct file *fp, unsigned int cmd, unsigned long arg)
2444 void __user *argp = (void __user *)arg;
2446 pr_debug("stl_memioctl(fp=%p,cmd=%x,arg=%lx)\n", fp, cmd,arg);
2448 brdnr = iminor(fp->f_dentry->d_inode);
2449 if (brdnr >= STL_MAXBRDS)
2455 case COM_GETPORTSTATS:
2456 rc = stl_getportstats(NULL, NULL, argp);
2458 case COM_CLRPORTSTATS:
2459 rc = stl_clrportstats(NULL, argp);
2461 case COM_GETBRDSTATS:
2462 rc = stl_getbrdstats(argp);
2465 rc = stl_getportstruct(argp);
2468 rc = stl_getbrdstruct(argp);
2478 static const struct tty_operations stl_ops = {
2482 .put_char = stl_putchar,
2483 .flush_chars = stl_flushchars,
2484 .write_room = stl_writeroom,
2485 .chars_in_buffer = stl_charsinbuffer,
2487 .set_termios = stl_settermios,
2488 .throttle = stl_throttle,
2489 .unthrottle = stl_unthrottle,
2492 .hangup = stl_hangup,
2493 .flush_buffer = stl_flushbuffer,
2494 .break_ctl = stl_breakctl,
2495 .wait_until_sent = stl_waituntilsent,
2496 .send_xchar = stl_sendxchar,
2497 .tiocmget = stl_tiocmget,
2498 .tiocmset = stl_tiocmset,
2499 .proc_fops = &stl_proc_fops,
2502 static const struct tty_port_operations stl_port_ops = {
2503 .carrier_raised = stl_carrier_raised,
2504 .dtr_rts = stl_dtr_rts,
2505 .activate = stl_activate,
2506 .shutdown = stl_shutdown,
2509 /*****************************************************************************/
2510 /* CD1400 HARDWARE FUNCTIONS */
2511 /*****************************************************************************/
2514 * These functions get/set/update the registers of the cd1400 UARTs.
2515 * Access to the cd1400 registers is via an address/data io port pair.
2516 * (Maybe should make this inline...)
2519 static int stl_cd1400getreg(struct stlport *portp, int regnr)
2521 outb((regnr + portp->uartaddr), portp->ioaddr);
2522 return inb(portp->ioaddr + EREG_DATA);
2525 static void stl_cd1400setreg(struct stlport *portp, int regnr, int value)
2527 outb(regnr + portp->uartaddr, portp->ioaddr);
2528 outb(value, portp->ioaddr + EREG_DATA);
2531 static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value)
2533 outb(regnr + portp->uartaddr, portp->ioaddr);
2534 if (inb(portp->ioaddr + EREG_DATA) != value) {
2535 outb(value, portp->ioaddr + EREG_DATA);
2541 /*****************************************************************************/
2544 * Inbitialize the UARTs in a panel. We don't care what sort of board
2545 * these ports are on - since the port io registers are almost
2546 * identical when dealing with ports.
2549 static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
2553 int nrchips, uartaddr, ioaddr;
2554 unsigned long flags;
2556 pr_debug("stl_panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
2558 spin_lock_irqsave(&brd_lock, flags);
2559 BRDENABLE(panelp->brdnr, panelp->pagenr);
2562 * Check that each chip is present and started up OK.
2565 nrchips = panelp->nrports / CD1400_PORTS;
2566 for (i = 0; i < nrchips; i++) {
2567 if (brdp->brdtype == BRD_ECHPCI) {
2568 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
2569 ioaddr = panelp->iobase;
2571 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
2572 uartaddr = (i & 0x01) ? 0x080 : 0;
2573 outb((GFRCR + uartaddr), ioaddr);
2574 outb(0, (ioaddr + EREG_DATA));
2575 outb((CCR + uartaddr), ioaddr);
2576 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
2577 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
2578 outb((GFRCR + uartaddr), ioaddr);
2579 for (j = 0; j < CCR_MAXWAIT; j++)
2580 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
2583 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
2584 printk("STALLION: cd1400 not responding, "
2585 "brd=%d panel=%d chip=%d\n",
2586 panelp->brdnr, panelp->panelnr, i);
2589 chipmask |= (0x1 << i);
2590 outb((PPR + uartaddr), ioaddr);
2591 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
2594 BRDDISABLE(panelp->brdnr);
2595 spin_unlock_irqrestore(&brd_lock, flags);
2599 /*****************************************************************************/
2602 * Initialize hardware specific port registers.
2605 static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
2607 unsigned long flags;
2608 pr_debug("stl_cd1400portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
2611 if ((brdp == NULL) || (panelp == NULL) ||
2615 spin_lock_irqsave(&brd_lock, flags);
2616 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
2617 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
2618 portp->uartaddr = (portp->portnr & 0x04) << 5;
2619 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
2621 BRDENABLE(portp->brdnr, portp->pagenr);
2622 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2623 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
2624 portp->hwid = stl_cd1400getreg(portp, GFRCR);
2625 BRDDISABLE(portp->brdnr);
2626 spin_unlock_irqrestore(&brd_lock, flags);
2629 /*****************************************************************************/
2632 * Wait for the command register to be ready. We will poll this,
2633 * since it won't usually take too long to be ready.
2636 static void stl_cd1400ccrwait(struct stlport *portp)
2640 for (i = 0; i < CCR_MAXWAIT; i++)
2641 if (stl_cd1400getreg(portp, CCR) == 0)
2644 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
2645 portp->portnr, portp->panelnr, portp->brdnr);
2648 /*****************************************************************************/
2651 * Set up the cd1400 registers for a port based on the termios port
2655 static void stl_cd1400setport(struct stlport *portp, struct ktermios *tiosp)
2657 struct stlbrd *brdp;
2658 unsigned long flags;
2659 unsigned int clkdiv, baudrate;
2660 unsigned char cor1, cor2, cor3;
2661 unsigned char cor4, cor5, ccr;
2662 unsigned char srer, sreron, sreroff;
2663 unsigned char mcor1, mcor2, rtpr;
2664 unsigned char clk, div;
2680 brdp = stl_brds[portp->brdnr];
2685 * Set up the RX char ignore mask with those RX error types we
2686 * can ignore. We can get the cd1400 to help us out a little here,
2687 * it will ignore parity errors and breaks for us.
2689 portp->rxignoremsk = 0;
2690 if (tiosp->c_iflag & IGNPAR) {
2691 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
2692 cor1 |= COR1_PARIGNORE;
2694 if (tiosp->c_iflag & IGNBRK) {
2695 portp->rxignoremsk |= ST_BREAK;
2696 cor4 |= COR4_IGNBRK;
2699 portp->rxmarkmsk = ST_OVERRUN;
2700 if (tiosp->c_iflag & (INPCK | PARMRK))
2701 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
2702 if (tiosp->c_iflag & BRKINT)
2703 portp->rxmarkmsk |= ST_BREAK;
2706 * Go through the char size, parity and stop bits and set all the
2707 * option register appropriately.
2709 switch (tiosp->c_cflag & CSIZE) {
2724 if (tiosp->c_cflag & CSTOPB)
2729 if (tiosp->c_cflag & PARENB) {
2730 if (tiosp->c_cflag & PARODD)
2731 cor1 |= (COR1_PARENB | COR1_PARODD);
2733 cor1 |= (COR1_PARENB | COR1_PAREVEN);
2735 cor1 |= COR1_PARNONE;
2739 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
2740 * space for hardware flow control and the like. This should be set to
2741 * VMIN. Also here we will set the RX data timeout to 10ms - this should
2742 * really be based on VTIME.
2744 cor3 |= FIFO_RXTHRESHOLD;
2748 * Calculate the baud rate timers. For now we will just assume that
2749 * the input and output baud are the same. Could have used a baud
2750 * table here, but this way we can generate virtually any baud rate
2753 baudrate = tiosp->c_cflag & CBAUD;
2754 if (baudrate & CBAUDEX) {
2755 baudrate &= ~CBAUDEX;
2756 if ((baudrate < 1) || (baudrate > 4))
2757 tiosp->c_cflag &= ~CBAUDEX;
2761 baudrate = stl_baudrates[baudrate];
2762 if ((tiosp->c_cflag & CBAUD) == B38400) {
2763 if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
2765 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
2767 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
2769 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
2771 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
2772 baudrate = (portp->baud_base / portp->custom_divisor);
2774 if (baudrate > STL_CD1400MAXBAUD)
2775 baudrate = STL_CD1400MAXBAUD;
2778 for (clk = 0; clk < CD1400_NUMCLKS; clk++) {
2779 clkdiv = (portp->clk / stl_cd1400clkdivs[clk]) / baudrate;
2783 div = (unsigned char) clkdiv;
2787 * Check what form of modem signaling is required and set it up.
2789 if ((tiosp->c_cflag & CLOCAL) == 0) {
2792 sreron |= SRER_MODEM;
2793 portp->port.flags |= ASYNC_CHECK_CD;
2795 portp->port.flags &= ~ASYNC_CHECK_CD;
2798 * Setup cd1400 enhanced modes if we can. In particular we want to
2799 * handle as much of the flow control as possible automatically. As
2800 * well as saving a few CPU cycles it will also greatly improve flow
2801 * control reliability.
2803 if (tiosp->c_iflag & IXON) {
2806 if (tiosp->c_iflag & IXANY)
2810 if (tiosp->c_cflag & CRTSCTS) {
2812 mcor1 |= FIFO_RTSTHRESHOLD;
2816 * All cd1400 register values calculated so go through and set
2820 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
2821 portp->portnr, portp->panelnr, portp->brdnr);
2822 pr_debug(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
2823 cor1, cor2, cor3, cor4, cor5);
2824 pr_debug(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
2825 mcor1, mcor2, rtpr, sreron, sreroff);
2826 pr_debug(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
2827 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
2828 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
2829 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
2831 spin_lock_irqsave(&brd_lock, flags);
2832 BRDENABLE(portp->brdnr, portp->pagenr);
2833 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
2834 srer = stl_cd1400getreg(portp, SRER);
2835 stl_cd1400setreg(portp, SRER, 0);
2836 if (stl_cd1400updatereg(portp, COR1, cor1))
2838 if (stl_cd1400updatereg(portp, COR2, cor2))
2840 if (stl_cd1400updatereg(portp, COR3, cor3))
2843 stl_cd1400ccrwait(portp);
2844 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
2846 stl_cd1400setreg(portp, COR4, cor4);
2847 stl_cd1400setreg(portp, COR5, cor5);
2848 stl_cd1400setreg(portp, MCOR1, mcor1);
2849 stl_cd1400setreg(portp, MCOR2, mcor2);
2851 stl_cd1400setreg(portp, TCOR, clk);
2852 stl_cd1400setreg(portp, TBPR, div);
2853 stl_cd1400setreg(portp, RCOR, clk);
2854 stl_cd1400setreg(portp, RBPR, div);
2856 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
2857 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
2858 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
2859 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
2860 stl_cd1400setreg(portp, RTPR, rtpr);
2861 mcor1 = stl_cd1400getreg(portp, MSVR1);
2862 if (mcor1 & MSVR1_DCD)
2863 portp->sigs |= TIOCM_CD;
2865 portp->sigs &= ~TIOCM_CD;
2866 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
2867 BRDDISABLE(portp->brdnr);
2868 spin_unlock_irqrestore(&brd_lock, flags);
2871 /*****************************************************************************/
2874 * Set the state of the DTR and RTS signals.
2877 static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts)
2879 unsigned char msvr1, msvr2;
2880 unsigned long flags;
2882 pr_debug("stl_cd1400setsignals(portp=%p,dtr=%d,rts=%d)\n",
2892 spin_lock_irqsave(&brd_lock, flags);
2893 BRDENABLE(portp->brdnr, portp->pagenr);
2894 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2896 stl_cd1400setreg(portp, MSVR2, msvr2);
2898 stl_cd1400setreg(portp, MSVR1, msvr1);
2899 BRDDISABLE(portp->brdnr);
2900 spin_unlock_irqrestore(&brd_lock, flags);
2903 /*****************************************************************************/
2906 * Return the state of the signals.
2909 static int stl_cd1400getsignals(struct stlport *portp)
2911 unsigned char msvr1, msvr2;
2912 unsigned long flags;
2915 pr_debug("stl_cd1400getsignals(portp=%p)\n", portp);
2917 spin_lock_irqsave(&brd_lock, flags);
2918 BRDENABLE(portp->brdnr, portp->pagenr);
2919 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2920 msvr1 = stl_cd1400getreg(portp, MSVR1);
2921 msvr2 = stl_cd1400getreg(portp, MSVR2);
2922 BRDDISABLE(portp->brdnr);
2923 spin_unlock_irqrestore(&brd_lock, flags);
2926 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
2927 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
2928 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
2929 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
2931 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
2932 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
2939 /*****************************************************************************/
2942 * Enable/Disable the Transmitter and/or Receiver.
2945 static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx)
2948 unsigned long flags;
2950 pr_debug("stl_cd1400enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
2955 ccr |= CCR_TXDISABLE;
2957 ccr |= CCR_TXENABLE;
2959 ccr |= CCR_RXDISABLE;
2961 ccr |= CCR_RXENABLE;
2963 spin_lock_irqsave(&brd_lock, flags);
2964 BRDENABLE(portp->brdnr, portp->pagenr);
2965 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2966 stl_cd1400ccrwait(portp);
2967 stl_cd1400setreg(portp, CCR, ccr);
2968 stl_cd1400ccrwait(portp);
2969 BRDDISABLE(portp->brdnr);
2970 spin_unlock_irqrestore(&brd_lock, flags);
2973 /*****************************************************************************/
2976 * Start/stop the Transmitter and/or Receiver.
2979 static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx)
2981 unsigned char sreron, sreroff;
2982 unsigned long flags;
2984 pr_debug("stl_cd1400startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
2989 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
2991 sreron |= SRER_TXDATA;
2993 sreron |= SRER_TXEMPTY;
2995 sreroff |= SRER_RXDATA;
2997 sreron |= SRER_RXDATA;
2999 spin_lock_irqsave(&brd_lock, flags);
3000 BRDENABLE(portp->brdnr, portp->pagenr);
3001 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3002 stl_cd1400setreg(portp, SRER,
3003 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3004 BRDDISABLE(portp->brdnr);
3006 set_bit(ASYI_TXBUSY, &portp->istate);
3007 spin_unlock_irqrestore(&brd_lock, flags);
3010 /*****************************************************************************/
3013 * Disable all interrupts from this port.
3016 static void stl_cd1400disableintrs(struct stlport *portp)
3018 unsigned long flags;
3020 pr_debug("stl_cd1400disableintrs(portp=%p)\n", portp);
3022 spin_lock_irqsave(&brd_lock, flags);
3023 BRDENABLE(portp->brdnr, portp->pagenr);
3024 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3025 stl_cd1400setreg(portp, SRER, 0);
3026 BRDDISABLE(portp->brdnr);
3027 spin_unlock_irqrestore(&brd_lock, flags);
3030 /*****************************************************************************/
3032 static void stl_cd1400sendbreak(struct stlport *portp, int len)
3034 unsigned long flags;
3036 pr_debug("stl_cd1400sendbreak(portp=%p,len=%d)\n", portp, len);
3038 spin_lock_irqsave(&brd_lock, flags);
3039 BRDENABLE(portp->brdnr, portp->pagenr);
3040 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3041 stl_cd1400setreg(portp, SRER,
3042 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3044 BRDDISABLE(portp->brdnr);
3045 portp->brklen = len;
3047 portp->stats.txbreaks++;
3048 spin_unlock_irqrestore(&brd_lock, flags);
3051 /*****************************************************************************/
3054 * Take flow control actions...
3057 static void stl_cd1400flowctrl(struct stlport *portp, int state)
3059 struct tty_struct *tty;
3060 unsigned long flags;
3062 pr_debug("stl_cd1400flowctrl(portp=%p,state=%x)\n", portp, state);
3066 tty = tty_port_tty_get(&portp->port);
3070 spin_lock_irqsave(&brd_lock, flags);
3071 BRDENABLE(portp->brdnr, portp->pagenr);
3072 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3075 if (tty->termios->c_iflag & IXOFF) {
3076 stl_cd1400ccrwait(portp);
3077 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3078 portp->stats.rxxon++;
3079 stl_cd1400ccrwait(portp);
3082 * Question: should we return RTS to what it was before? It may
3083 * have been set by an ioctl... Suppose not, since if you have
3084 * hardware flow control set then it is pretty silly to go and
3085 * set the RTS line by hand.
3087 if (tty->termios->c_cflag & CRTSCTS) {
3088 stl_cd1400setreg(portp, MCOR1,
3089 (stl_cd1400getreg(portp, MCOR1) |
3090 FIFO_RTSTHRESHOLD));
3091 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3092 portp->stats.rxrtson++;
3095 if (tty->termios->c_iflag & IXOFF) {
3096 stl_cd1400ccrwait(portp);
3097 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3098 portp->stats.rxxoff++;
3099 stl_cd1400ccrwait(portp);
3101 if (tty->termios->c_cflag & CRTSCTS) {
3102 stl_cd1400setreg(portp, MCOR1,
3103 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3104 stl_cd1400setreg(portp, MSVR2, 0);
3105 portp->stats.rxrtsoff++;
3109 BRDDISABLE(portp->brdnr);
3110 spin_unlock_irqrestore(&brd_lock, flags);
3114 /*****************************************************************************/
3117 * Send a flow control character...
3120 static void stl_cd1400sendflow(struct stlport *portp, int state)
3122 struct tty_struct *tty;
3123 unsigned long flags;
3125 pr_debug("stl_cd1400sendflow(portp=%p,state=%x)\n", portp, state);
3129 tty = tty_port_tty_get(&portp->port);
3133 spin_lock_irqsave(&brd_lock, flags);
3134 BRDENABLE(portp->brdnr, portp->pagenr);
3135 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3137 stl_cd1400ccrwait(portp);
3138 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3139 portp->stats.rxxon++;
3140 stl_cd1400ccrwait(portp);
3142 stl_cd1400ccrwait(portp);
3143 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3144 portp->stats.rxxoff++;
3145 stl_cd1400ccrwait(portp);
3147 BRDDISABLE(portp->brdnr);
3148 spin_unlock_irqrestore(&brd_lock, flags);
3152 /*****************************************************************************/
3154 static void stl_cd1400flush(struct stlport *portp)
3156 unsigned long flags;
3158 pr_debug("stl_cd1400flush(portp=%p)\n", portp);
3163 spin_lock_irqsave(&brd_lock, flags);
3164 BRDENABLE(portp->brdnr, portp->pagenr);
3165 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3166 stl_cd1400ccrwait(portp);
3167 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3168 stl_cd1400ccrwait(portp);
3169 portp->tx.tail = portp->tx.head;
3170 BRDDISABLE(portp->brdnr);
3171 spin_unlock_irqrestore(&brd_lock, flags);
3174 /*****************************************************************************/
3177 * Return the current state of data flow on this port. This is only
3178 * really interresting when determining if data has fully completed
3179 * transmission or not... This is easy for the cd1400, it accurately
3180 * maintains the busy port flag.
3183 static int stl_cd1400datastate(struct stlport *portp)
3185 pr_debug("stl_cd1400datastate(portp=%p)\n", portp);
3190 return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
3193 /*****************************************************************************/
3196 * Interrupt service routine for cd1400 EasyIO boards.
3199 static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase)
3201 unsigned char svrtype;
3203 pr_debug("stl_cd1400eiointr(panelp=%p,iobase=%x)\n", panelp, iobase);
3205 spin_lock(&brd_lock);
3207 svrtype = inb(iobase + EREG_DATA);
3208 if (panelp->nrports > 4) {
3209 outb((SVRR + 0x80), iobase);
3210 svrtype |= inb(iobase + EREG_DATA);
3213 if (svrtype & SVRR_RX)
3214 stl_cd1400rxisr(panelp, iobase);
3215 else if (svrtype & SVRR_TX)
3216 stl_cd1400txisr(panelp, iobase);
3217 else if (svrtype & SVRR_MDM)
3218 stl_cd1400mdmisr(panelp, iobase);
3220 spin_unlock(&brd_lock);
3223 /*****************************************************************************/
3226 * Interrupt service routine for cd1400 panels.
3229 static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase)
3231 unsigned char svrtype;
3233 pr_debug("stl_cd1400echintr(panelp=%p,iobase=%x)\n", panelp, iobase);
3236 svrtype = inb(iobase + EREG_DATA);
3237 outb((SVRR + 0x80), iobase);
3238 svrtype |= inb(iobase + EREG_DATA);
3239 if (svrtype & SVRR_RX)
3240 stl_cd1400rxisr(panelp, iobase);
3241 else if (svrtype & SVRR_TX)
3242 stl_cd1400txisr(panelp, iobase);
3243 else if (svrtype & SVRR_MDM)
3244 stl_cd1400mdmisr(panelp, iobase);
3248 /*****************************************************************************/
3251 * Unfortunately we need to handle breaks in the TX data stream, since
3252 * this is the only way to generate them on the cd1400.
3255 static int stl_cd1400breakisr(struct stlport *portp, int ioaddr)
3257 if (portp->brklen == 1) {
3258 outb((COR2 + portp->uartaddr), ioaddr);
3259 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
3260 (ioaddr + EREG_DATA));
3261 outb((TDR + portp->uartaddr), ioaddr);
3262 outb(ETC_CMD, (ioaddr + EREG_DATA));
3263 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
3264 outb((SRER + portp->uartaddr), ioaddr);
3265 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
3266 (ioaddr + EREG_DATA));
3268 } else if (portp->brklen > 1) {
3269 outb((TDR + portp->uartaddr), ioaddr);
3270 outb(ETC_CMD, (ioaddr + EREG_DATA));
3271 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
3275 outb((COR2 + portp->uartaddr), ioaddr);
3276 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
3277 (ioaddr + EREG_DATA));
3283 /*****************************************************************************/
3286 * Transmit interrupt handler. This has gotta be fast! Handling TX
3287 * chars is pretty simple, stuff as many as possible from the TX buffer
3288 * into the cd1400 FIFO. Must also handle TX breaks here, since they
3289 * are embedded as commands in the data stream. Oh no, had to use a goto!
3290 * This could be optimized more, will do when I get time...
3291 * In practice it is possible that interrupts are enabled but that the
3292 * port has been hung up. Need to handle not having any TX buffer here,
3293 * this is done by using the side effect that head and tail will also
3294 * be NULL if the buffer has been freed.
3297 static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr)
3299 struct stlport *portp;
3302 unsigned char ioack, srer;
3303 struct tty_struct *tty;
3305 pr_debug("stl_cd1400txisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3307 ioack = inb(ioaddr + EREG_TXACK);
3308 if (((ioack & panelp->ackmask) != 0) ||
3309 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
3310 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
3313 portp = panelp->ports[(ioack >> 3)];
3316 * Unfortunately we need to handle breaks in the data stream, since
3317 * this is the only way to generate them on the cd1400. Do it now if
3318 * a break is to be sent.
3320 if (portp->brklen != 0)
3321 if (stl_cd1400breakisr(portp, ioaddr))
3324 head = portp->tx.head;
3325 tail = portp->tx.tail;
3326 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
3327 if ((len == 0) || ((len < STL_TXBUFLOW) &&
3328 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
3329 set_bit(ASYI_TXLOW, &portp->istate);
3330 tty = tty_port_tty_get(&portp->port);
3338 outb((SRER + portp->uartaddr), ioaddr);
3339 srer = inb(ioaddr + EREG_DATA);
3340 if (srer & SRER_TXDATA) {
3341 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
3343 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
3344 clear_bit(ASYI_TXBUSY, &portp->istate);
3346 outb(srer, (ioaddr + EREG_DATA));
3348 len = min(len, CD1400_TXFIFOSIZE);
3349 portp->stats.txtotal += len;
3350 stlen = min_t(unsigned int, len,
3351 (portp->tx.buf + STL_TXBUFSIZE) - tail);
3352 outb((TDR + portp->uartaddr), ioaddr);
3353 outsb((ioaddr + EREG_DATA), tail, stlen);
3356 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
3357 tail = portp->tx.buf;
3359 outsb((ioaddr + EREG_DATA), tail, len);
3362 portp->tx.tail = tail;
3366 outb((EOSRR + portp->uartaddr), ioaddr);
3367 outb(0, (ioaddr + EREG_DATA));
3370 /*****************************************************************************/
3373 * Receive character interrupt handler. Determine if we have good chars
3374 * or bad chars and then process appropriately. Good chars are easy
3375 * just shove the lot into the RX buffer and set all status byte to 0.
3376 * If a bad RX char then process as required. This routine needs to be
3377 * fast! In practice it is possible that we get an interrupt on a port
3378 * that is closed. This can happen on hangups - since they completely
3379 * shutdown a port not in user context. Need to handle this case.
3382 static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr)
3384 struct stlport *portp;
3385 struct tty_struct *tty;
3386 unsigned int ioack, len, buflen;
3387 unsigned char status;
3390 pr_debug("stl_cd1400rxisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3392 ioack = inb(ioaddr + EREG_RXACK);
3393 if ((ioack & panelp->ackmask) != 0) {
3394 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
3397 portp = panelp->ports[(ioack >> 3)];
3398 tty = tty_port_tty_get(&portp->port);
3400 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
3401 outb((RDCR + portp->uartaddr), ioaddr);
3402 len = inb(ioaddr + EREG_DATA);
3403 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
3404 len = min_t(unsigned int, len, sizeof(stl_unwanted));
3405 outb((RDSR + portp->uartaddr), ioaddr);
3406 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
3407 portp->stats.rxlost += len;
3408 portp->stats.rxtotal += len;
3410 len = min(len, buflen);
3413 outb((RDSR + portp->uartaddr), ioaddr);
3414 tty_prepare_flip_string(tty, &ptr, len);
3415 insb((ioaddr + EREG_DATA), ptr, len);
3416 tty_schedule_flip(tty);
3417 portp->stats.rxtotal += len;
3420 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
3421 outb((RDSR + portp->uartaddr), ioaddr);
3422 status = inb(ioaddr + EREG_DATA);
3423 ch = inb(ioaddr + EREG_DATA);
3424 if (status & ST_PARITY)
3425 portp->stats.rxparity++;
3426 if (status & ST_FRAMING)
3427 portp->stats.rxframing++;
3428 if (status & ST_OVERRUN)
3429 portp->stats.rxoverrun++;
3430 if (status & ST_BREAK)
3431 portp->stats.rxbreaks++;
3432 if (status & ST_SCHARMASK) {
3433 if ((status & ST_SCHARMASK) == ST_SCHAR1)
3434 portp->stats.txxon++;
3435 if ((status & ST_SCHARMASK) == ST_SCHAR2)
3436 portp->stats.txxoff++;
3439 if (tty != NULL && (portp->rxignoremsk & status) == 0) {
3440 if (portp->rxmarkmsk & status) {
3441 if (status & ST_BREAK) {
3443 if (portp->port.flags & ASYNC_SAK) {
3445 BRDENABLE(portp->brdnr, portp->pagenr);
3447 } else if (status & ST_PARITY)
3448 status = TTY_PARITY;
3449 else if (status & ST_FRAMING)
3451 else if(status & ST_OVERRUN)
3452 status = TTY_OVERRUN;
3457 tty_insert_flip_char(tty, ch, status);
3458 tty_schedule_flip(tty);
3461 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
3468 outb((EOSRR + portp->uartaddr), ioaddr);
3469 outb(0, (ioaddr + EREG_DATA));
3472 /*****************************************************************************/
3475 * Modem interrupt handler. The is called when the modem signal line
3476 * (DCD) has changed state. Leave most of the work to the off-level
3477 * processing routine.
3480 static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr)
3482 struct stlport *portp;
3486 pr_debug("stl_cd1400mdmisr(panelp=%p)\n", panelp);
3488 ioack = inb(ioaddr + EREG_MDACK);
3489 if (((ioack & panelp->ackmask) != 0) ||
3490 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
3491 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
3494 portp = panelp->ports[(ioack >> 3)];
3496 outb((MISR + portp->uartaddr), ioaddr);
3497 misr = inb(ioaddr + EREG_DATA);
3498 if (misr & MISR_DCD) {
3499 stl_cd_change(portp);
3500 portp->stats.modem++;
3503 outb((EOSRR + portp->uartaddr), ioaddr);
3504 outb(0, (ioaddr + EREG_DATA));
3507 /*****************************************************************************/
3508 /* SC26198 HARDWARE FUNCTIONS */
3509 /*****************************************************************************/
3512 * These functions get/set/update the registers of the sc26198 UARTs.
3513 * Access to the sc26198 registers is via an address/data io port pair.
3514 * (Maybe should make this inline...)
3517 static int stl_sc26198getreg(struct stlport *portp, int regnr)
3519 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3520 return inb(portp->ioaddr + XP_DATA);
3523 static void stl_sc26198setreg(struct stlport *portp, int regnr, int value)
3525 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3526 outb(value, (portp->ioaddr + XP_DATA));
3529 static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value)
3531 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3532 if (inb(portp->ioaddr + XP_DATA) != value) {
3533 outb(value, (portp->ioaddr + XP_DATA));
3539 /*****************************************************************************/
3542 * Functions to get and set the sc26198 global registers.
3545 static int stl_sc26198getglobreg(struct stlport *portp, int regnr)
3547 outb(regnr, (portp->ioaddr + XP_ADDR));
3548 return inb(portp->ioaddr + XP_DATA);
3552 static void stl_sc26198setglobreg(struct stlport *portp, int regnr, int value)
3554 outb(regnr, (portp->ioaddr + XP_ADDR));
3555 outb(value, (portp->ioaddr + XP_DATA));
3559 /*****************************************************************************/
3562 * Inbitialize the UARTs in a panel. We don't care what sort of board
3563 * these ports are on - since the port io registers are almost
3564 * identical when dealing with ports.
3567 static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
3570 int nrchips, ioaddr;
3572 pr_debug("stl_sc26198panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
3574 BRDENABLE(panelp->brdnr, panelp->pagenr);
3577 * Check that each chip is present and started up OK.
3580 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
3581 if (brdp->brdtype == BRD_ECHPCI)
3582 outb(panelp->pagenr, brdp->ioctrl);
3584 for (i = 0; i < nrchips; i++) {
3585 ioaddr = panelp->iobase + (i * 4);
3586 outb(SCCR, (ioaddr + XP_ADDR));
3587 outb(CR_RESETALL, (ioaddr + XP_DATA));
3588 outb(TSTR, (ioaddr + XP_ADDR));
3589 if (inb(ioaddr + XP_DATA) != 0) {
3590 printk("STALLION: sc26198 not responding, "
3591 "brd=%d panel=%d chip=%d\n",
3592 panelp->brdnr, panelp->panelnr, i);
3595 chipmask |= (0x1 << i);
3596 outb(GCCR, (ioaddr + XP_ADDR));
3597 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
3598 outb(WDTRCR, (ioaddr + XP_ADDR));
3599 outb(0xff, (ioaddr + XP_DATA));
3602 BRDDISABLE(panelp->brdnr);
3606 /*****************************************************************************/
3609 * Initialize hardware specific port registers.
3612 static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
3614 pr_debug("stl_sc26198portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
3617 if ((brdp == NULL) || (panelp == NULL) ||
3621 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
3622 portp->uartaddr = (portp->portnr & 0x07) << 4;
3623 portp->pagenr = panelp->pagenr;
3626 BRDENABLE(portp->brdnr, portp->pagenr);
3627 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
3628 BRDDISABLE(portp->brdnr);
3631 /*****************************************************************************/
3634 * Set up the sc26198 registers for a port based on the termios port
3638 static void stl_sc26198setport(struct stlport *portp, struct ktermios *tiosp)
3640 struct stlbrd *brdp;
3641 unsigned long flags;
3642 unsigned int baudrate;
3643 unsigned char mr0, mr1, mr2, clk;
3644 unsigned char imron, imroff, iopr, ipr;
3654 brdp = stl_brds[portp->brdnr];
3659 * Set up the RX char ignore mask with those RX error types we
3662 portp->rxignoremsk = 0;
3663 if (tiosp->c_iflag & IGNPAR)
3664 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
3666 if (tiosp->c_iflag & IGNBRK)
3667 portp->rxignoremsk |= SR_RXBREAK;
3669 portp->rxmarkmsk = SR_RXOVERRUN;
3670 if (tiosp->c_iflag & (INPCK | PARMRK))
3671 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
3672 if (tiosp->c_iflag & BRKINT)
3673 portp->rxmarkmsk |= SR_RXBREAK;
3676 * Go through the char size, parity and stop bits and set all the
3677 * option register appropriately.
3679 switch (tiosp->c_cflag & CSIZE) {
3694 if (tiosp->c_cflag & CSTOPB)
3699 if (tiosp->c_cflag & PARENB) {
3700 if (tiosp->c_cflag & PARODD)
3701 mr1 |= (MR1_PARENB | MR1_PARODD);
3703 mr1 |= (MR1_PARENB | MR1_PAREVEN);
3707 mr1 |= MR1_ERRBLOCK;
3710 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
3711 * space for hardware flow control and the like. This should be set to
3714 mr2 |= MR2_RXFIFOHALF;
3717 * Calculate the baud rate timers. For now we will just assume that
3718 * the input and output baud are the same. The sc26198 has a fixed
3719 * baud rate table, so only discrete baud rates possible.
3721 baudrate = tiosp->c_cflag & CBAUD;
3722 if (baudrate & CBAUDEX) {
3723 baudrate &= ~CBAUDEX;
3724 if ((baudrate < 1) || (baudrate > 4))
3725 tiosp->c_cflag &= ~CBAUDEX;
3729 baudrate = stl_baudrates[baudrate];
3730 if ((tiosp->c_cflag & CBAUD) == B38400) {
3731 if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3733 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3735 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3737 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3739 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3740 baudrate = (portp->baud_base / portp->custom_divisor);
3742 if (baudrate > STL_SC26198MAXBAUD)
3743 baudrate = STL_SC26198MAXBAUD;
3746 for (clk = 0; clk < SC26198_NRBAUDS; clk++)
3747 if (baudrate <= sc26198_baudtable[clk])
3751 * Check what form of modem signaling is required and set it up.
3753 if (tiosp->c_cflag & CLOCAL) {
3754 portp->port.flags &= ~ASYNC_CHECK_CD;
3756 iopr |= IOPR_DCDCOS;
3758 portp->port.flags |= ASYNC_CHECK_CD;
3762 * Setup sc26198 enhanced modes if we can. In particular we want to
3763 * handle as much of the flow control as possible automatically. As
3764 * well as saving a few CPU cycles it will also greatly improve flow
3765 * control reliability.
3767 if (tiosp->c_iflag & IXON) {
3768 mr0 |= MR0_SWFTX | MR0_SWFT;
3769 imron |= IR_XONXOFF;
3771 imroff |= IR_XONXOFF;
3773 if (tiosp->c_iflag & IXOFF)
3776 if (tiosp->c_cflag & CRTSCTS) {
3782 * All sc26198 register values calculated so go through and set
3786 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3787 portp->portnr, portp->panelnr, portp->brdnr);
3788 pr_debug(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
3789 pr_debug(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
3790 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3791 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3792 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3794 spin_lock_irqsave(&brd_lock, flags);
3795 BRDENABLE(portp->brdnr, portp->pagenr);
3796 stl_sc26198setreg(portp, IMR, 0);
3797 stl_sc26198updatereg(portp, MR0, mr0);
3798 stl_sc26198updatereg(portp, MR1, mr1);
3799 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
3800 stl_sc26198updatereg(portp, MR2, mr2);
3801 stl_sc26198updatereg(portp, IOPIOR,
3802 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
3805 stl_sc26198setreg(portp, TXCSR, clk);
3806 stl_sc26198setreg(portp, RXCSR, clk);
3809 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
3810 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
3812 ipr = stl_sc26198getreg(portp, IPR);
3814 portp->sigs &= ~TIOCM_CD;
3816 portp->sigs |= TIOCM_CD;
3818 portp->imr = (portp->imr & ~imroff) | imron;
3819 stl_sc26198setreg(portp, IMR, portp->imr);
3820 BRDDISABLE(portp->brdnr);
3821 spin_unlock_irqrestore(&brd_lock, flags);
3824 /*****************************************************************************/
3827 * Set the state of the DTR and RTS signals.
3830 static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts)
3832 unsigned char iopioron, iopioroff;
3833 unsigned long flags;
3835 pr_debug("stl_sc26198setsignals(portp=%p,dtr=%d,rts=%d)\n", portp,
3841 iopioroff |= IPR_DTR;
3843 iopioron |= IPR_DTR;
3845 iopioroff |= IPR_RTS;
3847 iopioron |= IPR_RTS;
3849 spin_lock_irqsave(&brd_lock, flags);
3850 BRDENABLE(portp->brdnr, portp->pagenr);
3851 stl_sc26198setreg(portp, IOPIOR,
3852 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
3853 BRDDISABLE(portp->brdnr);
3854 spin_unlock_irqrestore(&brd_lock, flags);
3857 /*****************************************************************************/
3860 * Return the state of the signals.
3863 static int stl_sc26198getsignals(struct stlport *portp)
3866 unsigned long flags;
3869 pr_debug("stl_sc26198getsignals(portp=%p)\n", portp);
3871 spin_lock_irqsave(&brd_lock, flags);
3872 BRDENABLE(portp->brdnr, portp->pagenr);
3873 ipr = stl_sc26198getreg(portp, IPR);
3874 BRDDISABLE(portp->brdnr);
3875 spin_unlock_irqrestore(&brd_lock, flags);
3878 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
3879 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
3880 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
3881 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
3886 /*****************************************************************************/
3889 * Enable/Disable the Transmitter and/or Receiver.
3892 static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx)
3895 unsigned long flags;
3897 pr_debug("stl_sc26198enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx,tx);
3899 ccr = portp->crenable;
3901 ccr &= ~CR_TXENABLE;
3905 ccr &= ~CR_RXENABLE;
3909 spin_lock_irqsave(&brd_lock, flags);
3910 BRDENABLE(portp->brdnr, portp->pagenr);
3911 stl_sc26198setreg(portp, SCCR, ccr);
3912 BRDDISABLE(portp->brdnr);
3913 portp->crenable = ccr;
3914 spin_unlock_irqrestore(&brd_lock, flags);
3917 /*****************************************************************************/
3920 * Start/stop the Transmitter and/or Receiver.
3923 static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx)
3926 unsigned long flags;
3928 pr_debug("stl_sc26198startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
3936 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
3938 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
3940 spin_lock_irqsave(&brd_lock, flags);
3941 BRDENABLE(portp->brdnr, portp->pagenr);
3942 stl_sc26198setreg(portp, IMR, imr);
3943 BRDDISABLE(portp->brdnr);
3946 set_bit(ASYI_TXBUSY, &portp->istate);
3947 spin_unlock_irqrestore(&brd_lock, flags);
3950 /*****************************************************************************/
3953 * Disable all interrupts from this port.
3956 static void stl_sc26198disableintrs(struct stlport *portp)
3958 unsigned long flags;
3960 pr_debug("stl_sc26198disableintrs(portp=%p)\n", portp);
3962 spin_lock_irqsave(&brd_lock, flags);
3963 BRDENABLE(portp->brdnr, portp->pagenr);
3965 stl_sc26198setreg(portp, IMR, 0);
3966 BRDDISABLE(portp->brdnr);
3967 spin_unlock_irqrestore(&brd_lock, flags);
3970 /*****************************************************************************/
3972 static void stl_sc26198sendbreak(struct stlport *portp, int len)
3974 unsigned long flags;
3976 pr_debug("stl_sc26198sendbreak(portp=%p,len=%d)\n", portp, len);
3978 spin_lock_irqsave(&brd_lock, flags);
3979 BRDENABLE(portp->brdnr, portp->pagenr);
3981 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
3982 portp->stats.txbreaks++;
3984 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
3986 BRDDISABLE(portp->brdnr);
3987 spin_unlock_irqrestore(&brd_lock, flags);
3990 /*****************************************************************************/
3993 * Take flow control actions...
3996 static void stl_sc26198flowctrl(struct stlport *portp, int state)
3998 struct tty_struct *tty;
3999 unsigned long flags;
4002 pr_debug("stl_sc26198flowctrl(portp=%p,state=%x)\n", portp, state);
4006 tty = tty_port_tty_get(&portp->port);
4010 spin_lock_irqsave(&brd_lock, flags);
4011 BRDENABLE(portp->brdnr, portp->pagenr);
4014 if (tty->termios->c_iflag & IXOFF) {
4015 mr0 = stl_sc26198getreg(portp, MR0);
4016 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4017 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4019 portp->stats.rxxon++;
4020 stl_sc26198wait(portp);
4021 stl_sc26198setreg(portp, MR0, mr0);
4024 * Question: should we return RTS to what it was before? It may
4025 * have been set by an ioctl... Suppose not, since if you have
4026 * hardware flow control set then it is pretty silly to go and
4027 * set the RTS line by hand.
4029 if (tty->termios->c_cflag & CRTSCTS) {
4030 stl_sc26198setreg(portp, MR1,
4031 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4032 stl_sc26198setreg(portp, IOPIOR,
4033 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4034 portp->stats.rxrtson++;
4037 if (tty->termios->c_iflag & IXOFF) {
4038 mr0 = stl_sc26198getreg(portp, MR0);
4039 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4040 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4042 portp->stats.rxxoff++;
4043 stl_sc26198wait(portp);
4044 stl_sc26198setreg(portp, MR0, mr0);
4046 if (tty->termios->c_cflag & CRTSCTS) {
4047 stl_sc26198setreg(portp, MR1,
4048 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4049 stl_sc26198setreg(portp, IOPIOR,
4050 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4051 portp->stats.rxrtsoff++;
4055 BRDDISABLE(portp->brdnr);
4056 spin_unlock_irqrestore(&brd_lock, flags);
4060 /*****************************************************************************/
4063 * Send a flow control character.
4066 static void stl_sc26198sendflow(struct stlport *portp, int state)
4068 struct tty_struct *tty;
4069 unsigned long flags;
4072 pr_debug("stl_sc26198sendflow(portp=%p,state=%x)\n", portp, state);
4076 tty = tty_port_tty_get(&portp->port);
4080 spin_lock_irqsave(&brd_lock, flags);
4081 BRDENABLE(portp->brdnr, portp->pagenr);
4083 mr0 = stl_sc26198getreg(portp, MR0);
4084 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4085 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4087 portp->stats.rxxon++;
4088 stl_sc26198wait(portp);
4089 stl_sc26198setreg(portp, MR0, mr0);
4091 mr0 = stl_sc26198getreg(portp, MR0);
4092 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4093 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4095 portp->stats.rxxoff++;
4096 stl_sc26198wait(portp);
4097 stl_sc26198setreg(portp, MR0, mr0);
4099 BRDDISABLE(portp->brdnr);
4100 spin_unlock_irqrestore(&brd_lock, flags);
4104 /*****************************************************************************/
4106 static void stl_sc26198flush(struct stlport *portp)
4108 unsigned long flags;
4110 pr_debug("stl_sc26198flush(portp=%p)\n", portp);
4115 spin_lock_irqsave(&brd_lock, flags);
4116 BRDENABLE(portp->brdnr, portp->pagenr);
4117 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4118 stl_sc26198setreg(portp, SCCR, portp->crenable);
4119 BRDDISABLE(portp->brdnr);
4120 portp->tx.tail = portp->tx.head;
4121 spin_unlock_irqrestore(&brd_lock, flags);
4124 /*****************************************************************************/
4127 * Return the current state of data flow on this port. This is only
4128 * really interresting when determining if data has fully completed
4129 * transmission or not... The sc26198 interrupt scheme cannot
4130 * determine when all data has actually drained, so we need to
4131 * check the port statusy register to be sure.
4134 static int stl_sc26198datastate(struct stlport *portp)
4136 unsigned long flags;
4139 pr_debug("stl_sc26198datastate(portp=%p)\n", portp);
4143 if (test_bit(ASYI_TXBUSY, &portp->istate))
4146 spin_lock_irqsave(&brd_lock, flags);
4147 BRDENABLE(portp->brdnr, portp->pagenr);
4148 sr = stl_sc26198getreg(portp, SR);
4149 BRDDISABLE(portp->brdnr);
4150 spin_unlock_irqrestore(&brd_lock, flags);
4152 return (sr & SR_TXEMPTY) ? 0 : 1;
4155 /*****************************************************************************/
4158 * Delay for a small amount of time, to give the sc26198 a chance
4159 * to process a command...
4162 static void stl_sc26198wait(struct stlport *portp)
4166 pr_debug("stl_sc26198wait(portp=%p)\n", portp);
4171 for (i = 0; i < 20; i++)
4172 stl_sc26198getglobreg(portp, TSTR);
4175 /*****************************************************************************/
4178 * If we are TX flow controlled and in IXANY mode then we may
4179 * need to unflow control here. We gotta do this because of the
4180 * automatic flow control modes of the sc26198.
4183 static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty)
4187 mr0 = stl_sc26198getreg(portp, MR0);
4188 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4189 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4190 stl_sc26198wait(portp);
4191 stl_sc26198setreg(portp, MR0, mr0);
4192 clear_bit(ASYI_TXFLOWED, &portp->istate);
4195 /*****************************************************************************/
4198 * Interrupt service routine for sc26198 panels.
4201 static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase)
4203 struct stlport *portp;
4206 spin_lock(&brd_lock);
4209 * Work around bug in sc26198 chip... Cannot have A6 address
4210 * line of UART high, else iack will be returned as 0.
4212 outb(0, (iobase + 1));
4214 iack = inb(iobase + XP_IACK);
4215 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4217 if (iack & IVR_RXDATA)
4218 stl_sc26198rxisr(portp, iack);
4219 else if (iack & IVR_TXDATA)
4220 stl_sc26198txisr(portp);
4222 stl_sc26198otherisr(portp, iack);
4224 spin_unlock(&brd_lock);
4227 /*****************************************************************************/
4230 * Transmit interrupt handler. This has gotta be fast! Handling TX
4231 * chars is pretty simple, stuff as many as possible from the TX buffer
4232 * into the sc26198 FIFO.
4233 * In practice it is possible that interrupts are enabled but that the
4234 * port has been hung up. Need to handle not having any TX buffer here,
4235 * this is done by using the side effect that head and tail will also
4236 * be NULL if the buffer has been freed.
4239 static void stl_sc26198txisr(struct stlport *portp)
4241 struct tty_struct *tty;
4242 unsigned int ioaddr;
4247 pr_debug("stl_sc26198txisr(portp=%p)\n", portp);
4249 ioaddr = portp->ioaddr;
4250 head = portp->tx.head;
4251 tail = portp->tx.tail;
4252 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4253 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4254 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4255 set_bit(ASYI_TXLOW, &portp->istate);
4256 tty = tty_port_tty_get(&portp->port);
4264 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
4265 mr0 = inb(ioaddr + XP_DATA);
4266 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4267 portp->imr &= ~IR_TXRDY;
4268 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
4269 outb(portp->imr, (ioaddr + XP_DATA));
4270 clear_bit(ASYI_TXBUSY, &portp->istate);
4272 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4273 outb(mr0, (ioaddr + XP_DATA));
4276 len = min(len, SC26198_TXFIFOSIZE);
4277 portp->stats.txtotal += len;
4278 stlen = min_t(unsigned int, len,
4279 (portp->tx.buf + STL_TXBUFSIZE) - tail);
4280 outb(GTXFIFO, (ioaddr + XP_ADDR));
4281 outsb((ioaddr + XP_DATA), tail, stlen);
4284 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4285 tail = portp->tx.buf;
4287 outsb((ioaddr + XP_DATA), tail, len);
4290 portp->tx.tail = tail;
4294 /*****************************************************************************/
4297 * Receive character interrupt handler. Determine if we have good chars
4298 * or bad chars and then process appropriately. Good chars are easy
4299 * just shove the lot into the RX buffer and set all status byte to 0.
4300 * If a bad RX char then process as required. This routine needs to be
4301 * fast! In practice it is possible that we get an interrupt on a port
4302 * that is closed. This can happen on hangups - since they completely
4303 * shutdown a port not in user context. Need to handle this case.
4306 static void stl_sc26198rxisr(struct stlport *portp, unsigned int iack)
4308 struct tty_struct *tty;
4309 unsigned int len, buflen, ioaddr;
4311 pr_debug("stl_sc26198rxisr(portp=%p,iack=%x)\n", portp, iack);
4313 tty = tty_port_tty_get(&portp->port);
4314 ioaddr = portp->ioaddr;
4315 outb(GIBCR, (ioaddr + XP_ADDR));
4316 len = inb(ioaddr + XP_DATA) + 1;
4318 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
4319 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
4320 len = min_t(unsigned int, len, sizeof(stl_unwanted));
4321 outb(GRXFIFO, (ioaddr + XP_ADDR));
4322 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4323 portp->stats.rxlost += len;
4324 portp->stats.rxtotal += len;
4326 len = min(len, buflen);
4329 outb(GRXFIFO, (ioaddr + XP_ADDR));
4330 tty_prepare_flip_string(tty, &ptr, len);
4331 insb((ioaddr + XP_DATA), ptr, len);
4332 tty_schedule_flip(tty);
4333 portp->stats.rxtotal += len;
4337 stl_sc26198rxbadchars(portp);
4341 * If we are TX flow controlled and in IXANY mode then we may need
4342 * to unflow control here. We gotta do this because of the automatic
4343 * flow control modes of the sc26198.
4345 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
4346 if ((tty != NULL) &&
4347 (tty->termios != NULL) &&
4348 (tty->termios->c_iflag & IXANY)) {
4349 stl_sc26198txunflow(portp, tty);
4355 /*****************************************************************************/
4358 * Process an RX bad character.
4361 static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch)
4363 struct tty_struct *tty;
4364 unsigned int ioaddr;
4366 tty = tty_port_tty_get(&portp->port);
4367 ioaddr = portp->ioaddr;
4369 if (status & SR_RXPARITY)
4370 portp->stats.rxparity++;
4371 if (status & SR_RXFRAMING)
4372 portp->stats.rxframing++;
4373 if (status & SR_RXOVERRUN)
4374 portp->stats.rxoverrun++;
4375 if (status & SR_RXBREAK)
4376 portp->stats.rxbreaks++;
4378 if ((tty != NULL) &&
4379 ((portp->rxignoremsk & status) == 0)) {
4380 if (portp->rxmarkmsk & status) {
4381 if (status & SR_RXBREAK) {
4383 if (portp->port.flags & ASYNC_SAK) {
4385 BRDENABLE(portp->brdnr, portp->pagenr);
4387 } else if (status & SR_RXPARITY)
4388 status = TTY_PARITY;
4389 else if (status & SR_RXFRAMING)
4391 else if(status & SR_RXOVERRUN)
4392 status = TTY_OVERRUN;
4398 tty_insert_flip_char(tty, ch, status);
4399 tty_schedule_flip(tty);
4402 portp->stats.rxtotal++;
4407 /*****************************************************************************/
4410 * Process all characters in the RX FIFO of the UART. Check all char
4411 * status bytes as well, and process as required. We need to check
4412 * all bytes in the FIFO, in case some more enter the FIFO while we
4413 * are here. To get the exact character error type we need to switch
4414 * into CHAR error mode (that is why we need to make sure we empty
4418 static void stl_sc26198rxbadchars(struct stlport *portp)
4420 unsigned char status, mr1;
4424 * To get the precise error type for each character we must switch
4425 * back into CHAR error mode.
4427 mr1 = stl_sc26198getreg(portp, MR1);
4428 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
4430 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
4431 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
4432 ch = stl_sc26198getreg(portp, RXFIFO);
4433 stl_sc26198rxbadch(portp, status, ch);
4437 * To get correct interrupt class we must switch back into BLOCK
4440 stl_sc26198setreg(portp, MR1, mr1);
4443 /*****************************************************************************/
4446 * Other interrupt handler. This includes modem signals, flow
4447 * control actions, etc. Most stuff is left to off-level interrupt
4451 static void stl_sc26198otherisr(struct stlport *portp, unsigned int iack)
4453 unsigned char cir, ipr, xisr;
4455 pr_debug("stl_sc26198otherisr(portp=%p,iack=%x)\n", portp, iack);
4457 cir = stl_sc26198getglobreg(portp, CIR);
4459 switch (cir & CIR_SUBTYPEMASK) {
4461 ipr = stl_sc26198getreg(portp, IPR);
4462 if (ipr & IPR_DCDCHANGE) {
4463 stl_cd_change(portp);
4464 portp->stats.modem++;
4467 case CIR_SUBXONXOFF:
4468 xisr = stl_sc26198getreg(portp, XISR);
4469 if (xisr & XISR_RXXONGOT) {
4470 set_bit(ASYI_TXFLOWED, &portp->istate);
4471 portp->stats.txxoff++;
4473 if (xisr & XISR_RXXOFFGOT) {
4474 clear_bit(ASYI_TXFLOWED, &portp->istate);
4475 portp->stats.txxon++;
4479 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
4480 stl_sc26198rxbadchars(portp);
4487 static void stl_free_isabrds(void)
4489 struct stlbrd *brdp;
4492 for (i = 0; i < stl_nrbrds; i++) {
4493 if ((brdp = stl_brds[i]) == NULL || (brdp->state & STL_PROBED))
4496 free_irq(brdp->irq, brdp);
4498 stl_cleanup_panels(brdp);
4500 release_region(brdp->ioaddr1, brdp->iosize1);
4501 if (brdp->iosize2 > 0)
4502 release_region(brdp->ioaddr2, brdp->iosize2);
4510 * Loadable module initialization stuff.
4512 static int __init stallion_module_init(void)
4514 struct stlbrd *brdp;
4515 struct stlconf conf;
4519 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
4521 spin_lock_init(&stallion_lock);
4522 spin_lock_init(&brd_lock);
4524 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
4530 stl_serial->owner = THIS_MODULE;
4531 stl_serial->driver_name = stl_drvname;
4532 stl_serial->name = "ttyE";
4533 stl_serial->major = STL_SERIALMAJOR;
4534 stl_serial->minor_start = 0;
4535 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
4536 stl_serial->subtype = SERIAL_TYPE_NORMAL;
4537 stl_serial->init_termios = stl_deftermios;
4538 stl_serial->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
4539 tty_set_operations(stl_serial, &stl_ops);
4541 retval = tty_register_driver(stl_serial);
4543 printk("STALLION: failed to register serial driver\n");
4548 * Find any dynamically supported boards. That is via module load
4551 for (i = stl_nrbrds; i < stl_nargs; i++) {
4552 memset(&conf, 0, sizeof(conf));
4553 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
4555 if ((brdp = stl_allocbrd()) == NULL)
4558 brdp->brdtype = conf.brdtype;
4559 brdp->ioaddr1 = conf.ioaddr1;
4560 brdp->ioaddr2 = conf.ioaddr2;
4561 brdp->irq = conf.irq;
4562 brdp->irqtype = conf.irqtype;
4563 stl_brds[brdp->brdnr] = brdp;
4564 if (stl_brdinit(brdp)) {
4565 stl_brds[brdp->brdnr] = NULL;
4568 for (j = 0; j < brdp->nrports; j++)
4569 tty_register_device(stl_serial,
4570 brdp->brdnr * STL_MAXPORTS + j, NULL);
4575 /* this has to be _after_ isa finding because of locking */
4576 retval = pci_register_driver(&stl_pcidriver);
4577 if (retval && stl_nrbrds == 0) {
4578 printk(KERN_ERR "STALLION: can't register pci driver\n");
4583 * Set up a character driver for per board stuff. This is mainly used
4584 * to do stats ioctls on the ports.
4586 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
4587 printk("STALLION: failed to register serial board device\n");
4589 stallion_class = class_create(THIS_MODULE, "staliomem");
4590 if (IS_ERR(stallion_class))
4591 printk("STALLION: failed to create class\n");
4592 for (i = 0; i < 4; i++)
4593 device_create(stallion_class, NULL, MKDEV(STL_SIOMEMMAJOR, i),
4594 NULL, "staliomem%d", i);
4598 tty_unregister_driver(stl_serial);
4600 put_tty_driver(stl_serial);
4605 static void __exit stallion_module_exit(void)
4607 struct stlbrd *brdp;
4610 pr_debug("cleanup_module()\n");
4612 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
4616 * Free up all allocated resources used by the ports. This includes
4617 * memory and interrupts. As part of this process we will also do
4618 * a hangup on every open port - to try to flush out any processes
4619 * hanging onto ports.
4621 for (i = 0; i < stl_nrbrds; i++) {
4622 if ((brdp = stl_brds[i]) == NULL || (brdp->state & STL_PROBED))
4624 for (j = 0; j < brdp->nrports; j++)
4625 tty_unregister_device(stl_serial,
4626 brdp->brdnr * STL_MAXPORTS + j);
4629 for (i = 0; i < 4; i++)
4630 device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
4631 unregister_chrdev(STL_SIOMEMMAJOR, "staliomem");
4632 class_destroy(stallion_class);
4634 pci_unregister_driver(&stl_pcidriver);
4638 tty_unregister_driver(stl_serial);
4639 put_tty_driver(stl_serial);
4642 module_init(stallion_module_init);
4643 module_exit(stallion_module_exit);
4645 MODULE_AUTHOR("Greg Ungerer");
4646 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
4647 MODULE_LICENSE("GPL");