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 unsigned int minordev, brdnr, panelnr;
730 pr_debug("stl_open(tty=%p,filp=%p): device=%s\n", tty, filp, tty->name);
732 minordev = tty->index;
733 brdnr = MINOR2BRD(minordev);
734 if (brdnr >= stl_nrbrds)
736 brdp = stl_brds[brdnr];
740 minordev = MINOR2PORT(minordev);
741 for (portnr = -1, panelnr = 0; panelnr < STL_MAXPANELS; panelnr++) {
742 if (brdp->panels[panelnr] == NULL)
744 if (minordev < brdp->panels[panelnr]->nrports) {
748 minordev -= brdp->panels[panelnr]->nrports;
753 portp = brdp->panels[panelnr]->ports[portnr];
757 tty->driver_data = portp;
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;
846 tty_port_close(&portp->port, tty, filp);
849 /*****************************************************************************/
852 * Write routine. Take data and stuff it in to the TX ring queue.
853 * If transmit interrupts are not running then start them.
856 static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
858 struct stlport *portp;
859 unsigned int len, stlen;
860 unsigned char *chbuf;
863 pr_debug("stl_write(tty=%p,buf=%p,count=%d)\n", tty, buf, count);
865 portp = tty->driver_data;
868 if (portp->tx.buf == NULL)
872 * If copying direct from user space we must cater for page faults,
873 * causing us to "sleep" here for a while. To handle this copy in all
874 * the data we need now, into a local buffer. Then when we got it all
875 * copy it into the TX buffer.
877 chbuf = (unsigned char *) buf;
879 head = portp->tx.head;
880 tail = portp->tx.tail;
882 len = STL_TXBUFSIZE - (head - tail) - 1;
883 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
885 len = tail - head - 1;
889 len = min(len, (unsigned int)count);
892 stlen = min(len, stlen);
893 memcpy(head, chbuf, stlen);
898 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
899 head = portp->tx.buf;
903 portp->tx.head = head;
905 clear_bit(ASYI_TXLOW, &portp->istate);
906 stl_startrxtx(portp, -1, 1);
911 /*****************************************************************************/
913 static int stl_putchar(struct tty_struct *tty, unsigned char ch)
915 struct stlport *portp;
919 pr_debug("stl_putchar(tty=%p,ch=%x)\n", tty, ch);
921 portp = tty->driver_data;
924 if (portp->tx.buf == NULL)
927 head = portp->tx.head;
928 tail = portp->tx.tail;
930 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
935 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
936 head = portp->tx.buf;
938 portp->tx.head = head;
942 /*****************************************************************************/
945 * If there are any characters in the buffer then make sure that TX
946 * interrupts are on and get'em out. Normally used after the putchar
947 * routine has been called.
950 static void stl_flushchars(struct tty_struct *tty)
952 struct stlport *portp;
954 pr_debug("stl_flushchars(tty=%p)\n", tty);
956 portp = tty->driver_data;
959 if (portp->tx.buf == NULL)
962 stl_startrxtx(portp, -1, 1);
965 /*****************************************************************************/
967 static int stl_writeroom(struct tty_struct *tty)
969 struct stlport *portp;
972 pr_debug("stl_writeroom(tty=%p)\n", tty);
974 portp = tty->driver_data;
977 if (portp->tx.buf == NULL)
980 head = portp->tx.head;
981 tail = portp->tx.tail;
982 return (head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1);
985 /*****************************************************************************/
988 * Return number of chars in the TX buffer. Normally we would just
989 * calculate the number of chars in the buffer and return that, but if
990 * the buffer is empty and TX interrupts are still on then we return
991 * that the buffer still has 1 char in it. This way whoever called us
992 * will not think that ALL chars have drained - since the UART still
993 * must have some chars in it (we are busy after all).
996 static int stl_charsinbuffer(struct tty_struct *tty)
998 struct stlport *portp;
1002 pr_debug("stl_charsinbuffer(tty=%p)\n", tty);
1004 portp = tty->driver_data;
1007 if (portp->tx.buf == NULL)
1010 head = portp->tx.head;
1011 tail = portp->tx.tail;
1012 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1013 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1018 /*****************************************************************************/
1021 * Generate the serial struct info.
1024 static int stl_getserial(struct stlport *portp, struct serial_struct __user *sp)
1026 struct serial_struct sio;
1027 struct stlbrd *brdp;
1029 pr_debug("stl_getserial(portp=%p,sp=%p)\n", portp, sp);
1031 memset(&sio, 0, sizeof(struct serial_struct));
1032 sio.line = portp->portnr;
1033 sio.port = portp->ioaddr;
1034 sio.flags = portp->port.flags;
1035 sio.baud_base = portp->baud_base;
1036 sio.close_delay = portp->close_delay;
1037 sio.closing_wait = portp->closing_wait;
1038 sio.custom_divisor = portp->custom_divisor;
1040 if (portp->uartp == &stl_cd1400uart) {
1041 sio.type = PORT_CIRRUS;
1042 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1044 sio.type = PORT_UNKNOWN;
1045 sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1048 brdp = stl_brds[portp->brdnr];
1050 sio.irq = brdp->irq;
1052 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
1055 /*****************************************************************************/
1058 * Set port according to the serial struct info.
1059 * At this point we do not do any auto-configure stuff, so we will
1060 * just quietly ignore any requests to change irq, etc.
1063 static int stl_setserial(struct tty_struct *tty, struct serial_struct __user *sp)
1065 struct stlport * portp = tty->driver_data;
1066 struct serial_struct sio;
1068 pr_debug("stl_setserial(portp=%p,sp=%p)\n", portp, sp);
1070 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1072 if (!capable(CAP_SYS_ADMIN)) {
1073 if ((sio.baud_base != portp->baud_base) ||
1074 (sio.close_delay != portp->close_delay) ||
1075 ((sio.flags & ~ASYNC_USR_MASK) !=
1076 (portp->port.flags & ~ASYNC_USR_MASK)))
1080 portp->port.flags = (portp->port.flags & ~ASYNC_USR_MASK) |
1081 (sio.flags & ASYNC_USR_MASK);
1082 portp->baud_base = sio.baud_base;
1083 portp->close_delay = sio.close_delay;
1084 portp->closing_wait = sio.closing_wait;
1085 portp->custom_divisor = sio.custom_divisor;
1086 stl_setport(portp, tty->termios);
1090 /*****************************************************************************/
1092 static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1094 struct stlport *portp;
1096 portp = tty->driver_data;
1099 if (tty->flags & (1 << TTY_IO_ERROR))
1102 return stl_getsignals(portp);
1105 static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1106 unsigned int set, unsigned int clear)
1108 struct stlport *portp;
1109 int rts = -1, dtr = -1;
1111 portp = tty->driver_data;
1114 if (tty->flags & (1 << TTY_IO_ERROR))
1117 if (set & TIOCM_RTS)
1119 if (set & TIOCM_DTR)
1121 if (clear & TIOCM_RTS)
1123 if (clear & TIOCM_DTR)
1126 stl_setsignals(portp, dtr, rts);
1130 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1132 struct stlport *portp;
1134 void __user *argp = (void __user *)arg;
1136 pr_debug("stl_ioctl(tty=%p,file=%p,cmd=%x,arg=%lx)\n", tty, file, cmd,
1139 portp = tty->driver_data;
1143 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1144 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS))
1145 if (tty->flags & (1 << TTY_IO_ERROR))
1154 rc = stl_getserial(portp, argp);
1157 rc = stl_setserial(tty, argp);
1159 case COM_GETPORTSTATS:
1160 rc = stl_getportstats(tty, portp, argp);
1162 case COM_CLRPORTSTATS:
1163 rc = stl_clrportstats(portp, argp);
1169 case TIOCSERGSTRUCT:
1170 case TIOCSERGETMULTI:
1171 case TIOCSERSETMULTI:
1180 /*****************************************************************************/
1183 * Start the transmitter again. Just turn TX interrupts back on.
1186 static void stl_start(struct tty_struct *tty)
1188 struct stlport *portp;
1190 pr_debug("stl_start(tty=%p)\n", tty);
1192 portp = tty->driver_data;
1195 stl_startrxtx(portp, -1, 1);
1198 /*****************************************************************************/
1200 static void stl_settermios(struct tty_struct *tty, struct ktermios *old)
1202 struct stlport *portp;
1203 struct ktermios *tiosp;
1205 pr_debug("stl_settermios(tty=%p,old=%p)\n", tty, old);
1207 portp = tty->driver_data;
1211 tiosp = tty->termios;
1212 if ((tiosp->c_cflag == old->c_cflag) &&
1213 (tiosp->c_iflag == old->c_iflag))
1216 stl_setport(portp, tiosp);
1217 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1219 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1220 tty->hw_stopped = 0;
1223 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1224 wake_up_interruptible(&portp->port.open_wait);
1227 /*****************************************************************************/
1230 * Attempt to flow control who ever is sending us data. Based on termios
1231 * settings use software or/and hardware flow control.
1234 static void stl_throttle(struct tty_struct *tty)
1236 struct stlport *portp;
1238 pr_debug("stl_throttle(tty=%p)\n", tty);
1240 portp = tty->driver_data;
1243 stl_flowctrl(portp, 0);
1246 /*****************************************************************************/
1249 * Unflow control the device sending us data...
1252 static void stl_unthrottle(struct tty_struct *tty)
1254 struct stlport *portp;
1256 pr_debug("stl_unthrottle(tty=%p)\n", tty);
1258 portp = tty->driver_data;
1261 stl_flowctrl(portp, 1);
1264 /*****************************************************************************/
1267 * Stop the transmitter. Basically to do this we will just turn TX
1271 static void stl_stop(struct tty_struct *tty)
1273 struct stlport *portp;
1275 pr_debug("stl_stop(tty=%p)\n", tty);
1277 portp = tty->driver_data;
1280 stl_startrxtx(portp, -1, 0);
1283 /*****************************************************************************/
1286 * Hangup this port. This is pretty much like closing the port, only
1287 * a little more brutal. No waiting for data to drain. Shutdown the
1288 * port and maybe drop signals.
1291 static void stl_hangup(struct tty_struct *tty)
1293 struct stlport *portp = tty->driver_data;
1294 pr_debug("stl_hangup(tty=%p)\n", tty);
1298 tty_port_hangup(&portp->port);
1301 /*****************************************************************************/
1303 static int stl_breakctl(struct tty_struct *tty, int state)
1305 struct stlport *portp;
1307 pr_debug("stl_breakctl(tty=%p,state=%d)\n", tty, state);
1309 portp = tty->driver_data;
1313 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1317 /*****************************************************************************/
1319 static void stl_sendxchar(struct tty_struct *tty, char ch)
1321 struct stlport *portp;
1323 pr_debug("stl_sendxchar(tty=%p,ch=%x)\n", tty, ch);
1325 portp = tty->driver_data;
1329 if (ch == STOP_CHAR(tty))
1330 stl_sendflow(portp, 0);
1331 else if (ch == START_CHAR(tty))
1332 stl_sendflow(portp, 1);
1334 stl_putchar(tty, ch);
1337 static void stl_portinfo(struct seq_file *m, struct stlport *portp, int portnr)
1342 seq_printf(m, "%d: uart:%s tx:%d rx:%d",
1343 portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
1344 (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
1346 if (portp->stats.rxframing)
1347 seq_printf(m, " fe:%d", (int) portp->stats.rxframing);
1348 if (portp->stats.rxparity)
1349 seq_printf(m, " pe:%d", (int) portp->stats.rxparity);
1350 if (portp->stats.rxbreaks)
1351 seq_printf(m, " brk:%d", (int) portp->stats.rxbreaks);
1352 if (portp->stats.rxoverrun)
1353 seq_printf(m, " oe:%d", (int) portp->stats.rxoverrun);
1355 sigs = stl_getsignals(portp);
1357 if (sigs & TIOCM_RTS) {
1358 seq_printf(m, "%c%s", sep, "RTS");
1361 if (sigs & TIOCM_CTS) {
1362 seq_printf(m, "%c%s", sep, "CTS");
1365 if (sigs & TIOCM_DTR) {
1366 seq_printf(m, "%c%s", sep, "DTR");
1369 if (sigs & TIOCM_CD) {
1370 seq_printf(m, "%c%s", sep, "DCD");
1373 if (sigs & TIOCM_DSR) {
1374 seq_printf(m, "%c%s", sep, "DSR");
1380 /*****************************************************************************/
1383 * Port info, read from the /proc file system.
1386 static int stl_proc_show(struct seq_file *m, void *v)
1388 struct stlbrd *brdp;
1389 struct stlpanel *panelp;
1390 struct stlport *portp;
1391 unsigned int brdnr, panelnr, portnr;
1396 seq_printf(m, "%s: version %s\n", stl_drvtitle, stl_drvversion);
1399 * We scan through for each board, panel and port. The offset is
1400 * calculated on the fly, and irrelevant ports are skipped.
1402 for (brdnr = 0; brdnr < stl_nrbrds; brdnr++) {
1403 brdp = stl_brds[brdnr];
1406 if (brdp->state == 0)
1409 totalport = brdnr * STL_MAXPORTS;
1410 for (panelnr = 0; panelnr < brdp->nrpanels; panelnr++) {
1411 panelp = brdp->panels[panelnr];
1415 for (portnr = 0; portnr < panelp->nrports; portnr++,
1417 portp = panelp->ports[portnr];
1420 stl_portinfo(m, portp, totalport);
1427 static int stl_proc_open(struct inode *inode, struct file *file)
1429 return single_open(file, stl_proc_show, NULL);
1432 static const struct file_operations stl_proc_fops = {
1433 .owner = THIS_MODULE,
1434 .open = stl_proc_open,
1436 .llseek = seq_lseek,
1437 .release = single_release,
1440 /*****************************************************************************/
1443 * All board interrupts are vectored through here first. This code then
1444 * calls off to the approrpriate board interrupt handlers.
1447 static irqreturn_t stl_intr(int irq, void *dev_id)
1449 struct stlbrd *brdp = dev_id;
1451 pr_debug("stl_intr(brdp=%p,irq=%d)\n", brdp, brdp->irq);
1453 return IRQ_RETVAL((* brdp->isr)(brdp));
1456 /*****************************************************************************/
1459 * Interrupt service routine for EasyIO board types.
1462 static int stl_eiointr(struct stlbrd *brdp)
1464 struct stlpanel *panelp;
1465 unsigned int iobase;
1468 spin_lock(&brd_lock);
1469 panelp = brdp->panels[0];
1470 iobase = panelp->iobase;
1471 while (inb(brdp->iostatus) & EIO_INTRPEND) {
1473 (* panelp->isr)(panelp, iobase);
1475 spin_unlock(&brd_lock);
1479 /*****************************************************************************/
1482 * Interrupt service routine for ECH-AT board types.
1485 static int stl_echatintr(struct stlbrd *brdp)
1487 struct stlpanel *panelp;
1488 unsigned int ioaddr, bnknr;
1491 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
1493 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1495 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
1496 ioaddr = brdp->bnkstataddr[bnknr];
1497 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1498 panelp = brdp->bnk2panel[bnknr];
1499 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1504 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
1509 /*****************************************************************************/
1512 * Interrupt service routine for ECH-MCA board types.
1515 static int stl_echmcaintr(struct stlbrd *brdp)
1517 struct stlpanel *panelp;
1518 unsigned int ioaddr, bnknr;
1521 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1523 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
1524 ioaddr = brdp->bnkstataddr[bnknr];
1525 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1526 panelp = brdp->bnk2panel[bnknr];
1527 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1534 /*****************************************************************************/
1537 * Interrupt service routine for ECH-PCI board types.
1540 static int stl_echpciintr(struct stlbrd *brdp)
1542 struct stlpanel *panelp;
1543 unsigned int ioaddr, bnknr, recheck;
1548 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
1549 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
1550 ioaddr = brdp->bnkstataddr[bnknr];
1551 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1552 panelp = brdp->bnk2panel[bnknr];
1553 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1564 /*****************************************************************************/
1567 * Interrupt service routine for ECH-8/64-PCI board types.
1570 static int stl_echpci64intr(struct stlbrd *brdp)
1572 struct stlpanel *panelp;
1573 unsigned int ioaddr, bnknr;
1576 while (inb(brdp->ioctrl) & 0x1) {
1578 for (bnknr = 0; bnknr < brdp->nrbnks; bnknr++) {
1579 ioaddr = brdp->bnkstataddr[bnknr];
1580 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1581 panelp = brdp->bnk2panel[bnknr];
1582 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1590 /*****************************************************************************/
1593 * Initialize all the ports on a panel.
1596 static int __devinit stl_initports(struct stlbrd *brdp, struct stlpanel *panelp)
1598 struct stlport *portp;
1602 pr_debug("stl_initports(brdp=%p,panelp=%p)\n", brdp, panelp);
1604 chipmask = stl_panelinit(brdp, panelp);
1607 * All UART's are initialized (if found!). Now go through and setup
1608 * each ports data structures.
1610 for (i = 0; i < panelp->nrports; i++) {
1611 portp = kzalloc(sizeof(struct stlport), GFP_KERNEL);
1613 printk("STALLION: failed to allocate memory "
1614 "(size=%Zd)\n", sizeof(struct stlport));
1617 tty_port_init(&portp->port);
1618 portp->port.ops = &stl_port_ops;
1619 portp->magic = STL_PORTMAGIC;
1621 portp->brdnr = panelp->brdnr;
1622 portp->panelnr = panelp->panelnr;
1623 portp->uartp = panelp->uartp;
1624 portp->clk = brdp->clk;
1625 portp->baud_base = STL_BAUDBASE;
1626 portp->close_delay = STL_CLOSEDELAY;
1627 portp->closing_wait = 30 * HZ;
1628 init_waitqueue_head(&portp->port.open_wait);
1629 init_waitqueue_head(&portp->port.close_wait);
1630 portp->stats.brd = portp->brdnr;
1631 portp->stats.panel = portp->panelnr;
1632 portp->stats.port = portp->portnr;
1633 panelp->ports[i] = portp;
1634 stl_portinit(brdp, panelp, portp);
1640 static void stl_cleanup_panels(struct stlbrd *brdp)
1642 struct stlpanel *panelp;
1643 struct stlport *portp;
1645 struct tty_struct *tty;
1647 for (j = 0; j < STL_MAXPANELS; j++) {
1648 panelp = brdp->panels[j];
1651 for (k = 0; k < STL_PORTSPERPANEL; k++) {
1652 portp = panelp->ports[k];
1655 tty = tty_port_tty_get(&portp->port);
1660 kfree(portp->tx.buf);
1667 /*****************************************************************************/
1670 * Try to find and initialize an EasyIO board.
1673 static int __devinit stl_initeio(struct stlbrd *brdp)
1675 struct stlpanel *panelp;
1676 unsigned int status;
1680 pr_debug("stl_initeio(brdp=%p)\n", brdp);
1682 brdp->ioctrl = brdp->ioaddr1 + 1;
1683 brdp->iostatus = brdp->ioaddr1 + 2;
1685 status = inb(brdp->iostatus);
1686 if ((status & EIO_IDBITMASK) == EIO_MK3)
1690 * Handle board specific stuff now. The real difference is PCI
1693 if (brdp->brdtype == BRD_EASYIOPCI) {
1694 brdp->iosize1 = 0x80;
1695 brdp->iosize2 = 0x80;
1696 name = "serial(EIO-PCI)";
1697 outb(0x41, (brdp->ioaddr2 + 0x4c));
1700 name = "serial(EIO)";
1701 if ((brdp->irq < 0) || (brdp->irq > 15) ||
1702 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
1703 printk("STALLION: invalid irq=%d for brd=%d\n",
1704 brdp->irq, brdp->brdnr);
1708 outb((stl_vecmap[brdp->irq] | EIO_0WS |
1709 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
1714 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
1715 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
1716 "%x conflicts with another device\n", brdp->brdnr,
1721 if (brdp->iosize2 > 0)
1722 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
1723 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
1724 "address %x conflicts with another device\n",
1725 brdp->brdnr, brdp->ioaddr2);
1726 printk(KERN_WARNING "STALLION: Warning, also "
1727 "releasing board %d I/O address %x \n",
1728 brdp->brdnr, brdp->ioaddr1);
1733 * Everything looks OK, so let's go ahead and probe for the hardware.
1735 brdp->clk = CD1400_CLK;
1736 brdp->isr = stl_eiointr;
1739 switch (status & EIO_IDBITMASK) {
1741 brdp->clk = CD1400_CLK8M;
1751 switch (status & EIO_BRDMASK) {
1770 * We have verified that the board is actually present, so now we
1771 * can complete the setup.
1774 panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
1776 printk(KERN_WARNING "STALLION: failed to allocate memory "
1777 "(size=%Zd)\n", sizeof(struct stlpanel));
1782 panelp->magic = STL_PANELMAGIC;
1783 panelp->brdnr = brdp->brdnr;
1784 panelp->panelnr = 0;
1785 panelp->nrports = brdp->nrports;
1786 panelp->iobase = brdp->ioaddr1;
1787 panelp->hwid = status;
1788 if ((status & EIO_IDBITMASK) == EIO_MK3) {
1789 panelp->uartp = &stl_sc26198uart;
1790 panelp->isr = stl_sc26198intr;
1792 panelp->uartp = &stl_cd1400uart;
1793 panelp->isr = stl_cd1400eiointr;
1796 brdp->panels[0] = panelp;
1798 brdp->state |= BRD_FOUND;
1799 brdp->hwid = status;
1800 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
1801 printk("STALLION: failed to register interrupt "
1802 "routine for %s irq=%d\n", name, brdp->irq);
1809 stl_cleanup_panels(brdp);
1811 if (brdp->iosize2 > 0)
1812 release_region(brdp->ioaddr2, brdp->iosize2);
1814 release_region(brdp->ioaddr1, brdp->iosize1);
1819 /*****************************************************************************/
1822 * Try to find an ECH board and initialize it. This code is capable of
1823 * dealing with all types of ECH board.
1826 static int __devinit stl_initech(struct stlbrd *brdp)
1828 struct stlpanel *panelp;
1829 unsigned int status, nxtid, ioaddr, conflict, panelnr, banknr, i;
1833 pr_debug("stl_initech(brdp=%p)\n", brdp);
1839 * Set up the initial board register contents for boards. This varies a
1840 * bit between the different board types. So we need to handle each
1841 * separately. Also do a check that the supplied IRQ is good.
1843 switch (brdp->brdtype) {
1846 brdp->isr = stl_echatintr;
1847 brdp->ioctrl = brdp->ioaddr1 + 1;
1848 brdp->iostatus = brdp->ioaddr1 + 1;
1849 status = inb(brdp->iostatus);
1850 if ((status & ECH_IDBITMASK) != ECH_ID) {
1854 if ((brdp->irq < 0) || (brdp->irq > 15) ||
1855 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
1856 printk("STALLION: invalid irq=%d for brd=%d\n",
1857 brdp->irq, brdp->brdnr);
1861 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
1862 status |= (stl_vecmap[brdp->irq] << 1);
1863 outb((status | ECH_BRDRESET), brdp->ioaddr1);
1864 brdp->ioctrlval = ECH_INTENABLE |
1865 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
1866 for (i = 0; i < 10; i++)
1867 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
1870 name = "serial(EC8/32)";
1871 outb(status, brdp->ioaddr1);
1875 brdp->isr = stl_echmcaintr;
1876 brdp->ioctrl = brdp->ioaddr1 + 0x20;
1877 brdp->iostatus = brdp->ioctrl;
1878 status = inb(brdp->iostatus);
1879 if ((status & ECH_IDBITMASK) != ECH_ID) {
1883 if ((brdp->irq < 0) || (brdp->irq > 15) ||
1884 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
1885 printk("STALLION: invalid irq=%d for brd=%d\n",
1886 brdp->irq, brdp->brdnr);
1890 outb(ECHMC_BRDRESET, brdp->ioctrl);
1891 outb(ECHMC_INTENABLE, brdp->ioctrl);
1893 name = "serial(EC8/32-MC)";
1897 brdp->isr = stl_echpciintr;
1898 brdp->ioctrl = brdp->ioaddr1 + 2;
1901 name = "serial(EC8/32-PCI)";
1905 brdp->isr = stl_echpci64intr;
1906 brdp->ioctrl = brdp->ioaddr2 + 0x40;
1907 outb(0x43, (brdp->ioaddr1 + 0x4c));
1908 brdp->iosize1 = 0x80;
1909 brdp->iosize2 = 0x80;
1910 name = "serial(EC8/64-PCI)";
1914 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
1920 * Check boards for possible IO address conflicts and return fail status
1921 * if an IO conflict found.
1924 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
1925 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
1926 "%x conflicts with another device\n", brdp->brdnr,
1931 if (brdp->iosize2 > 0)
1932 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
1933 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
1934 "address %x conflicts with another device\n",
1935 brdp->brdnr, brdp->ioaddr2);
1936 printk(KERN_WARNING "STALLION: Warning, also "
1937 "releasing board %d I/O address %x \n",
1938 brdp->brdnr, brdp->ioaddr1);
1943 * Scan through the secondary io address space looking for panels.
1944 * As we find'em allocate and initialize panel structures for each.
1946 brdp->clk = CD1400_CLK;
1947 brdp->hwid = status;
1949 ioaddr = brdp->ioaddr2;
1954 for (i = 0; i < STL_MAXPANELS; i++) {
1955 if (brdp->brdtype == BRD_ECHPCI) {
1956 outb(nxtid, brdp->ioctrl);
1957 ioaddr = brdp->ioaddr2;
1959 status = inb(ioaddr + ECH_PNLSTATUS);
1960 if ((status & ECH_PNLIDMASK) != nxtid)
1962 panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
1964 printk("STALLION: failed to allocate memory "
1965 "(size=%Zd)\n", sizeof(struct stlpanel));
1969 panelp->magic = STL_PANELMAGIC;
1970 panelp->brdnr = brdp->brdnr;
1971 panelp->panelnr = panelnr;
1972 panelp->iobase = ioaddr;
1973 panelp->pagenr = nxtid;
1974 panelp->hwid = status;
1975 brdp->bnk2panel[banknr] = panelp;
1976 brdp->bnkpageaddr[banknr] = nxtid;
1977 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
1979 if (status & ECH_PNLXPID) {
1980 panelp->uartp = &stl_sc26198uart;
1981 panelp->isr = stl_sc26198intr;
1982 if (status & ECH_PNL16PORT) {
1983 panelp->nrports = 16;
1984 brdp->bnk2panel[banknr] = panelp;
1985 brdp->bnkpageaddr[banknr] = nxtid;
1986 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
1989 panelp->nrports = 8;
1991 panelp->uartp = &stl_cd1400uart;
1992 panelp->isr = stl_cd1400echintr;
1993 if (status & ECH_PNL16PORT) {
1994 panelp->nrports = 16;
1995 panelp->ackmask = 0x80;
1996 if (brdp->brdtype != BRD_ECHPCI)
1997 ioaddr += EREG_BANKSIZE;
1998 brdp->bnk2panel[banknr] = panelp;
1999 brdp->bnkpageaddr[banknr] = ++nxtid;
2000 brdp->bnkstataddr[banknr++] = ioaddr +
2003 panelp->nrports = 8;
2004 panelp->ackmask = 0xc0;
2009 ioaddr += EREG_BANKSIZE;
2010 brdp->nrports += panelp->nrports;
2011 brdp->panels[panelnr++] = panelp;
2012 if ((brdp->brdtype != BRD_ECHPCI) &&
2013 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2))) {
2019 brdp->nrpanels = panelnr;
2020 brdp->nrbnks = banknr;
2021 if (brdp->brdtype == BRD_ECH)
2022 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2024 brdp->state |= BRD_FOUND;
2025 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
2026 printk("STALLION: failed to register interrupt "
2027 "routine for %s irq=%d\n", name, brdp->irq);
2034 stl_cleanup_panels(brdp);
2035 if (brdp->iosize2 > 0)
2036 release_region(brdp->ioaddr2, brdp->iosize2);
2038 release_region(brdp->ioaddr1, brdp->iosize1);
2043 /*****************************************************************************/
2046 * Initialize and configure the specified board.
2047 * Scan through all the boards in the configuration and see what we
2048 * can find. Handle EIO and the ECH boards a little differently here
2049 * since the initial search and setup is very different.
2052 static int __devinit stl_brdinit(struct stlbrd *brdp)
2056 pr_debug("stl_brdinit(brdp=%p)\n", brdp);
2058 switch (brdp->brdtype) {
2061 retval = stl_initeio(brdp);
2069 retval = stl_initech(brdp);
2074 printk("STALLION: board=%d is unknown board type=%d\n",
2075 brdp->brdnr, brdp->brdtype);
2080 if ((brdp->state & BRD_FOUND) == 0) {
2081 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2082 stl_brdnames[brdp->brdtype], brdp->brdnr,
2083 brdp->ioaddr1, brdp->irq);
2087 for (i = 0; i < STL_MAXPANELS; i++)
2088 if (brdp->panels[i] != NULL)
2089 stl_initports(brdp, brdp->panels[i]);
2091 printk("STALLION: %s found, board=%d io=%x irq=%d "
2092 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2093 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2098 free_irq(brdp->irq, brdp);
2100 stl_cleanup_panels(brdp);
2102 release_region(brdp->ioaddr1, brdp->iosize1);
2103 if (brdp->iosize2 > 0)
2104 release_region(brdp->ioaddr2, brdp->iosize2);
2109 /*****************************************************************************/
2112 * Find the next available board number that is free.
2115 static int __devinit stl_getbrdnr(void)
2119 for (i = 0; i < STL_MAXBRDS; i++)
2120 if (stl_brds[i] == NULL) {
2121 if (i >= stl_nrbrds)
2129 /*****************************************************************************/
2131 * We have a Stallion board. Allocate a board structure and
2132 * initialize it. Read its IO and IRQ resources from PCI
2133 * configuration space.
2136 static int __devinit stl_pciprobe(struct pci_dev *pdev,
2137 const struct pci_device_id *ent)
2139 struct stlbrd *brdp;
2140 unsigned int i, brdtype = ent->driver_data;
2141 int brdnr, retval = -ENODEV;
2143 if ((pdev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2146 retval = pci_enable_device(pdev);
2149 brdp = stl_allocbrd();
2154 mutex_lock(&stl_brdslock);
2155 brdnr = stl_getbrdnr();
2157 dev_err(&pdev->dev, "too many boards found, "
2158 "maximum supported %d\n", STL_MAXBRDS);
2159 mutex_unlock(&stl_brdslock);
2163 brdp->brdnr = (unsigned int)brdnr;
2164 stl_brds[brdp->brdnr] = brdp;
2165 mutex_unlock(&stl_brdslock);
2167 brdp->brdtype = brdtype;
2168 brdp->state |= STL_PROBED;
2171 * We have all resources from the board, so let's setup the actual
2172 * board structure now.
2176 brdp->ioaddr2 = pci_resource_start(pdev, 0);
2177 brdp->ioaddr1 = pci_resource_start(pdev, 1);
2180 brdp->ioaddr2 = pci_resource_start(pdev, 2);
2181 brdp->ioaddr1 = pci_resource_start(pdev, 1);
2184 brdp->ioaddr1 = pci_resource_start(pdev, 2);
2185 brdp->ioaddr2 = pci_resource_start(pdev, 1);
2188 dev_err(&pdev->dev, "unknown PCI board type=%u\n", brdtype);
2192 brdp->irq = pdev->irq;
2193 retval = stl_brdinit(brdp);
2197 pci_set_drvdata(pdev, brdp);
2199 for (i = 0; i < brdp->nrports; i++)
2200 tty_register_device(stl_serial,
2201 brdp->brdnr * STL_MAXPORTS + i, &pdev->dev);
2205 stl_brds[brdp->brdnr] = NULL;
2212 static void __devexit stl_pciremove(struct pci_dev *pdev)
2214 struct stlbrd *brdp = pci_get_drvdata(pdev);
2217 free_irq(brdp->irq, brdp);
2219 stl_cleanup_panels(brdp);
2221 release_region(brdp->ioaddr1, brdp->iosize1);
2222 if (brdp->iosize2 > 0)
2223 release_region(brdp->ioaddr2, brdp->iosize2);
2225 for (i = 0; i < brdp->nrports; i++)
2226 tty_unregister_device(stl_serial,
2227 brdp->brdnr * STL_MAXPORTS + i);
2229 stl_brds[brdp->brdnr] = NULL;
2233 static struct pci_driver stl_pcidriver = {
2235 .id_table = stl_pcibrds,
2236 .probe = stl_pciprobe,
2237 .remove = __devexit_p(stl_pciremove)
2240 /*****************************************************************************/
2243 * Return the board stats structure to user app.
2246 static int stl_getbrdstats(combrd_t __user *bp)
2248 combrd_t stl_brdstats;
2249 struct stlbrd *brdp;
2250 struct stlpanel *panelp;
2253 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2255 if (stl_brdstats.brd >= STL_MAXBRDS)
2257 brdp = stl_brds[stl_brdstats.brd];
2261 memset(&stl_brdstats, 0, sizeof(combrd_t));
2262 stl_brdstats.brd = brdp->brdnr;
2263 stl_brdstats.type = brdp->brdtype;
2264 stl_brdstats.hwid = brdp->hwid;
2265 stl_brdstats.state = brdp->state;
2266 stl_brdstats.ioaddr = brdp->ioaddr1;
2267 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2268 stl_brdstats.irq = brdp->irq;
2269 stl_brdstats.nrpanels = brdp->nrpanels;
2270 stl_brdstats.nrports = brdp->nrports;
2271 for (i = 0; i < brdp->nrpanels; i++) {
2272 panelp = brdp->panels[i];
2273 stl_brdstats.panels[i].panel = i;
2274 stl_brdstats.panels[i].hwid = panelp->hwid;
2275 stl_brdstats.panels[i].nrports = panelp->nrports;
2278 return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
2281 /*****************************************************************************/
2284 * Resolve the referenced port number into a port struct pointer.
2287 static struct stlport *stl_getport(int brdnr, int panelnr, int portnr)
2289 struct stlbrd *brdp;
2290 struct stlpanel *panelp;
2292 if (brdnr < 0 || brdnr >= STL_MAXBRDS)
2294 brdp = stl_brds[brdnr];
2297 if (panelnr < 0 || (unsigned int)panelnr >= brdp->nrpanels)
2299 panelp = brdp->panels[panelnr];
2302 if (portnr < 0 || (unsigned int)portnr >= panelp->nrports)
2304 return panelp->ports[portnr];
2307 /*****************************************************************************/
2310 * Return the port stats structure to user app. A NULL port struct
2311 * pointer passed in means that we need to find out from the app
2312 * what port to get stats for (used through board control device).
2315 static int stl_getportstats(struct tty_struct *tty, struct stlport *portp, comstats_t __user *cp)
2317 comstats_t stl_comstats;
2318 unsigned char *head, *tail;
2319 unsigned long flags;
2322 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2324 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2330 portp->stats.state = portp->istate;
2331 portp->stats.flags = portp->port.flags;
2332 portp->stats.hwid = portp->hwid;
2334 portp->stats.ttystate = 0;
2335 portp->stats.cflags = 0;
2336 portp->stats.iflags = 0;
2337 portp->stats.oflags = 0;
2338 portp->stats.lflags = 0;
2339 portp->stats.rxbuffered = 0;
2341 spin_lock_irqsave(&stallion_lock, flags);
2342 if (tty != NULL && portp->port.tty == tty) {
2343 portp->stats.ttystate = tty->flags;
2344 /* No longer available as a statistic */
2345 portp->stats.rxbuffered = 1; /*tty->flip.count; */
2346 if (tty->termios != NULL) {
2347 portp->stats.cflags = tty->termios->c_cflag;
2348 portp->stats.iflags = tty->termios->c_iflag;
2349 portp->stats.oflags = tty->termios->c_oflag;
2350 portp->stats.lflags = tty->termios->c_lflag;
2353 spin_unlock_irqrestore(&stallion_lock, flags);
2355 head = portp->tx.head;
2356 tail = portp->tx.tail;
2357 portp->stats.txbuffered = (head >= tail) ? (head - tail) :
2358 (STL_TXBUFSIZE - (tail - head));
2360 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2362 return copy_to_user(cp, &portp->stats,
2363 sizeof(comstats_t)) ? -EFAULT : 0;
2366 /*****************************************************************************/
2369 * Clear the port stats structure. We also return it zeroed out...
2372 static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp)
2374 comstats_t stl_comstats;
2377 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2379 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2385 memset(&portp->stats, 0, sizeof(comstats_t));
2386 portp->stats.brd = portp->brdnr;
2387 portp->stats.panel = portp->panelnr;
2388 portp->stats.port = portp->portnr;
2389 return copy_to_user(cp, &portp->stats,
2390 sizeof(comstats_t)) ? -EFAULT : 0;
2393 /*****************************************************************************/
2396 * Return the entire driver ports structure to a user app.
2399 static int stl_getportstruct(struct stlport __user *arg)
2401 struct stlport stl_dummyport;
2402 struct stlport *portp;
2404 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
2406 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
2407 stl_dummyport.portnr);
2410 return copy_to_user(arg, portp, sizeof(struct stlport)) ? -EFAULT : 0;
2413 /*****************************************************************************/
2416 * Return the entire driver board structure to a user app.
2419 static int stl_getbrdstruct(struct stlbrd __user *arg)
2421 struct stlbrd stl_dummybrd;
2422 struct stlbrd *brdp;
2424 if (copy_from_user(&stl_dummybrd, arg, sizeof(struct stlbrd)))
2426 if (stl_dummybrd.brdnr >= STL_MAXBRDS)
2428 brdp = stl_brds[stl_dummybrd.brdnr];
2431 return copy_to_user(arg, brdp, sizeof(struct stlbrd)) ? -EFAULT : 0;
2434 /*****************************************************************************/
2437 * The "staliomem" device is also required to do some special operations
2438 * on the board and/or ports. In this driver it is mostly used for stats
2442 static long stl_memioctl(struct file *fp, unsigned int cmd, unsigned long arg)
2445 void __user *argp = (void __user *)arg;
2447 pr_debug("stl_memioctl(fp=%p,cmd=%x,arg=%lx)\n", fp, cmd,arg);
2449 brdnr = iminor(fp->f_dentry->d_inode);
2450 if (brdnr >= STL_MAXBRDS)
2456 case COM_GETPORTSTATS:
2457 rc = stl_getportstats(NULL, NULL, argp);
2459 case COM_CLRPORTSTATS:
2460 rc = stl_clrportstats(NULL, argp);
2462 case COM_GETBRDSTATS:
2463 rc = stl_getbrdstats(argp);
2466 rc = stl_getportstruct(argp);
2469 rc = stl_getbrdstruct(argp);
2479 static const struct tty_operations stl_ops = {
2483 .put_char = stl_putchar,
2484 .flush_chars = stl_flushchars,
2485 .write_room = stl_writeroom,
2486 .chars_in_buffer = stl_charsinbuffer,
2488 .set_termios = stl_settermios,
2489 .throttle = stl_throttle,
2490 .unthrottle = stl_unthrottle,
2493 .hangup = stl_hangup,
2494 .flush_buffer = stl_flushbuffer,
2495 .break_ctl = stl_breakctl,
2496 .wait_until_sent = stl_waituntilsent,
2497 .send_xchar = stl_sendxchar,
2498 .tiocmget = stl_tiocmget,
2499 .tiocmset = stl_tiocmset,
2500 .proc_fops = &stl_proc_fops,
2503 static const struct tty_port_operations stl_port_ops = {
2504 .carrier_raised = stl_carrier_raised,
2505 .dtr_rts = stl_dtr_rts,
2506 .activate = stl_activate,
2507 .shutdown = stl_shutdown,
2510 /*****************************************************************************/
2511 /* CD1400 HARDWARE FUNCTIONS */
2512 /*****************************************************************************/
2515 * These functions get/set/update the registers of the cd1400 UARTs.
2516 * Access to the cd1400 registers is via an address/data io port pair.
2517 * (Maybe should make this inline...)
2520 static int stl_cd1400getreg(struct stlport *portp, int regnr)
2522 outb((regnr + portp->uartaddr), portp->ioaddr);
2523 return inb(portp->ioaddr + EREG_DATA);
2526 static void stl_cd1400setreg(struct stlport *portp, int regnr, int value)
2528 outb(regnr + portp->uartaddr, portp->ioaddr);
2529 outb(value, portp->ioaddr + EREG_DATA);
2532 static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value)
2534 outb(regnr + portp->uartaddr, portp->ioaddr);
2535 if (inb(portp->ioaddr + EREG_DATA) != value) {
2536 outb(value, portp->ioaddr + EREG_DATA);
2542 /*****************************************************************************/
2545 * Inbitialize the UARTs in a panel. We don't care what sort of board
2546 * these ports are on - since the port io registers are almost
2547 * identical when dealing with ports.
2550 static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
2554 int nrchips, uartaddr, ioaddr;
2555 unsigned long flags;
2557 pr_debug("stl_panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
2559 spin_lock_irqsave(&brd_lock, flags);
2560 BRDENABLE(panelp->brdnr, panelp->pagenr);
2563 * Check that each chip is present and started up OK.
2566 nrchips = panelp->nrports / CD1400_PORTS;
2567 for (i = 0; i < nrchips; i++) {
2568 if (brdp->brdtype == BRD_ECHPCI) {
2569 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
2570 ioaddr = panelp->iobase;
2572 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
2573 uartaddr = (i & 0x01) ? 0x080 : 0;
2574 outb((GFRCR + uartaddr), ioaddr);
2575 outb(0, (ioaddr + EREG_DATA));
2576 outb((CCR + uartaddr), ioaddr);
2577 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
2578 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
2579 outb((GFRCR + uartaddr), ioaddr);
2580 for (j = 0; j < CCR_MAXWAIT; j++)
2581 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
2584 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
2585 printk("STALLION: cd1400 not responding, "
2586 "brd=%d panel=%d chip=%d\n",
2587 panelp->brdnr, panelp->panelnr, i);
2590 chipmask |= (0x1 << i);
2591 outb((PPR + uartaddr), ioaddr);
2592 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
2595 BRDDISABLE(panelp->brdnr);
2596 spin_unlock_irqrestore(&brd_lock, flags);
2600 /*****************************************************************************/
2603 * Initialize hardware specific port registers.
2606 static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
2608 unsigned long flags;
2609 pr_debug("stl_cd1400portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
2612 if ((brdp == NULL) || (panelp == NULL) ||
2616 spin_lock_irqsave(&brd_lock, flags);
2617 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
2618 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
2619 portp->uartaddr = (portp->portnr & 0x04) << 5;
2620 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
2622 BRDENABLE(portp->brdnr, portp->pagenr);
2623 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2624 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
2625 portp->hwid = stl_cd1400getreg(portp, GFRCR);
2626 BRDDISABLE(portp->brdnr);
2627 spin_unlock_irqrestore(&brd_lock, flags);
2630 /*****************************************************************************/
2633 * Wait for the command register to be ready. We will poll this,
2634 * since it won't usually take too long to be ready.
2637 static void stl_cd1400ccrwait(struct stlport *portp)
2641 for (i = 0; i < CCR_MAXWAIT; i++)
2642 if (stl_cd1400getreg(portp, CCR) == 0)
2645 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
2646 portp->portnr, portp->panelnr, portp->brdnr);
2649 /*****************************************************************************/
2652 * Set up the cd1400 registers for a port based on the termios port
2656 static void stl_cd1400setport(struct stlport *portp, struct ktermios *tiosp)
2658 struct stlbrd *brdp;
2659 unsigned long flags;
2660 unsigned int clkdiv, baudrate;
2661 unsigned char cor1, cor2, cor3;
2662 unsigned char cor4, cor5, ccr;
2663 unsigned char srer, sreron, sreroff;
2664 unsigned char mcor1, mcor2, rtpr;
2665 unsigned char clk, div;
2681 brdp = stl_brds[portp->brdnr];
2686 * Set up the RX char ignore mask with those RX error types we
2687 * can ignore. We can get the cd1400 to help us out a little here,
2688 * it will ignore parity errors and breaks for us.
2690 portp->rxignoremsk = 0;
2691 if (tiosp->c_iflag & IGNPAR) {
2692 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
2693 cor1 |= COR1_PARIGNORE;
2695 if (tiosp->c_iflag & IGNBRK) {
2696 portp->rxignoremsk |= ST_BREAK;
2697 cor4 |= COR4_IGNBRK;
2700 portp->rxmarkmsk = ST_OVERRUN;
2701 if (tiosp->c_iflag & (INPCK | PARMRK))
2702 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
2703 if (tiosp->c_iflag & BRKINT)
2704 portp->rxmarkmsk |= ST_BREAK;
2707 * Go through the char size, parity and stop bits and set all the
2708 * option register appropriately.
2710 switch (tiosp->c_cflag & CSIZE) {
2725 if (tiosp->c_cflag & CSTOPB)
2730 if (tiosp->c_cflag & PARENB) {
2731 if (tiosp->c_cflag & PARODD)
2732 cor1 |= (COR1_PARENB | COR1_PARODD);
2734 cor1 |= (COR1_PARENB | COR1_PAREVEN);
2736 cor1 |= COR1_PARNONE;
2740 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
2741 * space for hardware flow control and the like. This should be set to
2742 * VMIN. Also here we will set the RX data timeout to 10ms - this should
2743 * really be based on VTIME.
2745 cor3 |= FIFO_RXTHRESHOLD;
2749 * Calculate the baud rate timers. For now we will just assume that
2750 * the input and output baud are the same. Could have used a baud
2751 * table here, but this way we can generate virtually any baud rate
2754 baudrate = tiosp->c_cflag & CBAUD;
2755 if (baudrate & CBAUDEX) {
2756 baudrate &= ~CBAUDEX;
2757 if ((baudrate < 1) || (baudrate > 4))
2758 tiosp->c_cflag &= ~CBAUDEX;
2762 baudrate = stl_baudrates[baudrate];
2763 if ((tiosp->c_cflag & CBAUD) == B38400) {
2764 if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
2766 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
2768 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
2770 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
2772 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
2773 baudrate = (portp->baud_base / portp->custom_divisor);
2775 if (baudrate > STL_CD1400MAXBAUD)
2776 baudrate = STL_CD1400MAXBAUD;
2779 for (clk = 0; clk < CD1400_NUMCLKS; clk++) {
2780 clkdiv = (portp->clk / stl_cd1400clkdivs[clk]) / baudrate;
2784 div = (unsigned char) clkdiv;
2788 * Check what form of modem signaling is required and set it up.
2790 if ((tiosp->c_cflag & CLOCAL) == 0) {
2793 sreron |= SRER_MODEM;
2794 portp->port.flags |= ASYNC_CHECK_CD;
2796 portp->port.flags &= ~ASYNC_CHECK_CD;
2799 * Setup cd1400 enhanced modes if we can. In particular we want to
2800 * handle as much of the flow control as possible automatically. As
2801 * well as saving a few CPU cycles it will also greatly improve flow
2802 * control reliability.
2804 if (tiosp->c_iflag & IXON) {
2807 if (tiosp->c_iflag & IXANY)
2811 if (tiosp->c_cflag & CRTSCTS) {
2813 mcor1 |= FIFO_RTSTHRESHOLD;
2817 * All cd1400 register values calculated so go through and set
2821 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
2822 portp->portnr, portp->panelnr, portp->brdnr);
2823 pr_debug(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
2824 cor1, cor2, cor3, cor4, cor5);
2825 pr_debug(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
2826 mcor1, mcor2, rtpr, sreron, sreroff);
2827 pr_debug(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
2828 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
2829 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
2830 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
2832 spin_lock_irqsave(&brd_lock, flags);
2833 BRDENABLE(portp->brdnr, portp->pagenr);
2834 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
2835 srer = stl_cd1400getreg(portp, SRER);
2836 stl_cd1400setreg(portp, SRER, 0);
2837 if (stl_cd1400updatereg(portp, COR1, cor1))
2839 if (stl_cd1400updatereg(portp, COR2, cor2))
2841 if (stl_cd1400updatereg(portp, COR3, cor3))
2844 stl_cd1400ccrwait(portp);
2845 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
2847 stl_cd1400setreg(portp, COR4, cor4);
2848 stl_cd1400setreg(portp, COR5, cor5);
2849 stl_cd1400setreg(portp, MCOR1, mcor1);
2850 stl_cd1400setreg(portp, MCOR2, mcor2);
2852 stl_cd1400setreg(portp, TCOR, clk);
2853 stl_cd1400setreg(portp, TBPR, div);
2854 stl_cd1400setreg(portp, RCOR, clk);
2855 stl_cd1400setreg(portp, RBPR, div);
2857 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
2858 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
2859 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
2860 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
2861 stl_cd1400setreg(portp, RTPR, rtpr);
2862 mcor1 = stl_cd1400getreg(portp, MSVR1);
2863 if (mcor1 & MSVR1_DCD)
2864 portp->sigs |= TIOCM_CD;
2866 portp->sigs &= ~TIOCM_CD;
2867 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
2868 BRDDISABLE(portp->brdnr);
2869 spin_unlock_irqrestore(&brd_lock, flags);
2872 /*****************************************************************************/
2875 * Set the state of the DTR and RTS signals.
2878 static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts)
2880 unsigned char msvr1, msvr2;
2881 unsigned long flags;
2883 pr_debug("stl_cd1400setsignals(portp=%p,dtr=%d,rts=%d)\n",
2893 spin_lock_irqsave(&brd_lock, flags);
2894 BRDENABLE(portp->brdnr, portp->pagenr);
2895 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2897 stl_cd1400setreg(portp, MSVR2, msvr2);
2899 stl_cd1400setreg(portp, MSVR1, msvr1);
2900 BRDDISABLE(portp->brdnr);
2901 spin_unlock_irqrestore(&brd_lock, flags);
2904 /*****************************************************************************/
2907 * Return the state of the signals.
2910 static int stl_cd1400getsignals(struct stlport *portp)
2912 unsigned char msvr1, msvr2;
2913 unsigned long flags;
2916 pr_debug("stl_cd1400getsignals(portp=%p)\n", portp);
2918 spin_lock_irqsave(&brd_lock, flags);
2919 BRDENABLE(portp->brdnr, portp->pagenr);
2920 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2921 msvr1 = stl_cd1400getreg(portp, MSVR1);
2922 msvr2 = stl_cd1400getreg(portp, MSVR2);
2923 BRDDISABLE(portp->brdnr);
2924 spin_unlock_irqrestore(&brd_lock, flags);
2927 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
2928 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
2929 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
2930 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
2932 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
2933 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
2940 /*****************************************************************************/
2943 * Enable/Disable the Transmitter and/or Receiver.
2946 static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx)
2949 unsigned long flags;
2951 pr_debug("stl_cd1400enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
2956 ccr |= CCR_TXDISABLE;
2958 ccr |= CCR_TXENABLE;
2960 ccr |= CCR_RXDISABLE;
2962 ccr |= CCR_RXENABLE;
2964 spin_lock_irqsave(&brd_lock, flags);
2965 BRDENABLE(portp->brdnr, portp->pagenr);
2966 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
2967 stl_cd1400ccrwait(portp);
2968 stl_cd1400setreg(portp, CCR, ccr);
2969 stl_cd1400ccrwait(portp);
2970 BRDDISABLE(portp->brdnr);
2971 spin_unlock_irqrestore(&brd_lock, flags);
2974 /*****************************************************************************/
2977 * Start/stop the Transmitter and/or Receiver.
2980 static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx)
2982 unsigned char sreron, sreroff;
2983 unsigned long flags;
2985 pr_debug("stl_cd1400startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
2990 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
2992 sreron |= SRER_TXDATA;
2994 sreron |= SRER_TXEMPTY;
2996 sreroff |= SRER_RXDATA;
2998 sreron |= SRER_RXDATA;
3000 spin_lock_irqsave(&brd_lock, flags);
3001 BRDENABLE(portp->brdnr, portp->pagenr);
3002 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3003 stl_cd1400setreg(portp, SRER,
3004 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3005 BRDDISABLE(portp->brdnr);
3007 set_bit(ASYI_TXBUSY, &portp->istate);
3008 spin_unlock_irqrestore(&brd_lock, flags);
3011 /*****************************************************************************/
3014 * Disable all interrupts from this port.
3017 static void stl_cd1400disableintrs(struct stlport *portp)
3019 unsigned long flags;
3021 pr_debug("stl_cd1400disableintrs(portp=%p)\n", portp);
3023 spin_lock_irqsave(&brd_lock, flags);
3024 BRDENABLE(portp->brdnr, portp->pagenr);
3025 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3026 stl_cd1400setreg(portp, SRER, 0);
3027 BRDDISABLE(portp->brdnr);
3028 spin_unlock_irqrestore(&brd_lock, flags);
3031 /*****************************************************************************/
3033 static void stl_cd1400sendbreak(struct stlport *portp, int len)
3035 unsigned long flags;
3037 pr_debug("stl_cd1400sendbreak(portp=%p,len=%d)\n", portp, len);
3039 spin_lock_irqsave(&brd_lock, flags);
3040 BRDENABLE(portp->brdnr, portp->pagenr);
3041 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3042 stl_cd1400setreg(portp, SRER,
3043 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3045 BRDDISABLE(portp->brdnr);
3046 portp->brklen = len;
3048 portp->stats.txbreaks++;
3049 spin_unlock_irqrestore(&brd_lock, flags);
3052 /*****************************************************************************/
3055 * Take flow control actions...
3058 static void stl_cd1400flowctrl(struct stlport *portp, int state)
3060 struct tty_struct *tty;
3061 unsigned long flags;
3063 pr_debug("stl_cd1400flowctrl(portp=%p,state=%x)\n", portp, state);
3067 tty = tty_port_tty_get(&portp->port);
3071 spin_lock_irqsave(&brd_lock, flags);
3072 BRDENABLE(portp->brdnr, portp->pagenr);
3073 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3076 if (tty->termios->c_iflag & IXOFF) {
3077 stl_cd1400ccrwait(portp);
3078 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3079 portp->stats.rxxon++;
3080 stl_cd1400ccrwait(portp);
3083 * Question: should we return RTS to what it was before? It may
3084 * have been set by an ioctl... Suppose not, since if you have
3085 * hardware flow control set then it is pretty silly to go and
3086 * set the RTS line by hand.
3088 if (tty->termios->c_cflag & CRTSCTS) {
3089 stl_cd1400setreg(portp, MCOR1,
3090 (stl_cd1400getreg(portp, MCOR1) |
3091 FIFO_RTSTHRESHOLD));
3092 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3093 portp->stats.rxrtson++;
3096 if (tty->termios->c_iflag & IXOFF) {
3097 stl_cd1400ccrwait(portp);
3098 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3099 portp->stats.rxxoff++;
3100 stl_cd1400ccrwait(portp);
3102 if (tty->termios->c_cflag & CRTSCTS) {
3103 stl_cd1400setreg(portp, MCOR1,
3104 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3105 stl_cd1400setreg(portp, MSVR2, 0);
3106 portp->stats.rxrtsoff++;
3110 BRDDISABLE(portp->brdnr);
3111 spin_unlock_irqrestore(&brd_lock, flags);
3115 /*****************************************************************************/
3118 * Send a flow control character...
3121 static void stl_cd1400sendflow(struct stlport *portp, int state)
3123 struct tty_struct *tty;
3124 unsigned long flags;
3126 pr_debug("stl_cd1400sendflow(portp=%p,state=%x)\n", portp, state);
3130 tty = tty_port_tty_get(&portp->port);
3134 spin_lock_irqsave(&brd_lock, flags);
3135 BRDENABLE(portp->brdnr, portp->pagenr);
3136 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3138 stl_cd1400ccrwait(portp);
3139 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3140 portp->stats.rxxon++;
3141 stl_cd1400ccrwait(portp);
3143 stl_cd1400ccrwait(portp);
3144 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3145 portp->stats.rxxoff++;
3146 stl_cd1400ccrwait(portp);
3148 BRDDISABLE(portp->brdnr);
3149 spin_unlock_irqrestore(&brd_lock, flags);
3153 /*****************************************************************************/
3155 static void stl_cd1400flush(struct stlport *portp)
3157 unsigned long flags;
3159 pr_debug("stl_cd1400flush(portp=%p)\n", portp);
3164 spin_lock_irqsave(&brd_lock, flags);
3165 BRDENABLE(portp->brdnr, portp->pagenr);
3166 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3167 stl_cd1400ccrwait(portp);
3168 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3169 stl_cd1400ccrwait(portp);
3170 portp->tx.tail = portp->tx.head;
3171 BRDDISABLE(portp->brdnr);
3172 spin_unlock_irqrestore(&brd_lock, flags);
3175 /*****************************************************************************/
3178 * Return the current state of data flow on this port. This is only
3179 * really interresting when determining if data has fully completed
3180 * transmission or not... This is easy for the cd1400, it accurately
3181 * maintains the busy port flag.
3184 static int stl_cd1400datastate(struct stlport *portp)
3186 pr_debug("stl_cd1400datastate(portp=%p)\n", portp);
3191 return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
3194 /*****************************************************************************/
3197 * Interrupt service routine for cd1400 EasyIO boards.
3200 static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase)
3202 unsigned char svrtype;
3204 pr_debug("stl_cd1400eiointr(panelp=%p,iobase=%x)\n", panelp, iobase);
3206 spin_lock(&brd_lock);
3208 svrtype = inb(iobase + EREG_DATA);
3209 if (panelp->nrports > 4) {
3210 outb((SVRR + 0x80), iobase);
3211 svrtype |= inb(iobase + EREG_DATA);
3214 if (svrtype & SVRR_RX)
3215 stl_cd1400rxisr(panelp, iobase);
3216 else if (svrtype & SVRR_TX)
3217 stl_cd1400txisr(panelp, iobase);
3218 else if (svrtype & SVRR_MDM)
3219 stl_cd1400mdmisr(panelp, iobase);
3221 spin_unlock(&brd_lock);
3224 /*****************************************************************************/
3227 * Interrupt service routine for cd1400 panels.
3230 static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase)
3232 unsigned char svrtype;
3234 pr_debug("stl_cd1400echintr(panelp=%p,iobase=%x)\n", panelp, iobase);
3237 svrtype = inb(iobase + EREG_DATA);
3238 outb((SVRR + 0x80), iobase);
3239 svrtype |= inb(iobase + EREG_DATA);
3240 if (svrtype & SVRR_RX)
3241 stl_cd1400rxisr(panelp, iobase);
3242 else if (svrtype & SVRR_TX)
3243 stl_cd1400txisr(panelp, iobase);
3244 else if (svrtype & SVRR_MDM)
3245 stl_cd1400mdmisr(panelp, iobase);
3249 /*****************************************************************************/
3252 * Unfortunately we need to handle breaks in the TX data stream, since
3253 * this is the only way to generate them on the cd1400.
3256 static int stl_cd1400breakisr(struct stlport *portp, int ioaddr)
3258 if (portp->brklen == 1) {
3259 outb((COR2 + portp->uartaddr), ioaddr);
3260 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
3261 (ioaddr + EREG_DATA));
3262 outb((TDR + portp->uartaddr), ioaddr);
3263 outb(ETC_CMD, (ioaddr + EREG_DATA));
3264 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
3265 outb((SRER + portp->uartaddr), ioaddr);
3266 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
3267 (ioaddr + EREG_DATA));
3269 } else if (portp->brklen > 1) {
3270 outb((TDR + portp->uartaddr), ioaddr);
3271 outb(ETC_CMD, (ioaddr + EREG_DATA));
3272 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
3276 outb((COR2 + portp->uartaddr), ioaddr);
3277 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
3278 (ioaddr + EREG_DATA));
3284 /*****************************************************************************/
3287 * Transmit interrupt handler. This has gotta be fast! Handling TX
3288 * chars is pretty simple, stuff as many as possible from the TX buffer
3289 * into the cd1400 FIFO. Must also handle TX breaks here, since they
3290 * are embedded as commands in the data stream. Oh no, had to use a goto!
3291 * This could be optimized more, will do when I get time...
3292 * In practice it is possible that interrupts are enabled but that the
3293 * port has been hung up. Need to handle not having any TX buffer here,
3294 * this is done by using the side effect that head and tail will also
3295 * be NULL if the buffer has been freed.
3298 static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr)
3300 struct stlport *portp;
3303 unsigned char ioack, srer;
3304 struct tty_struct *tty;
3306 pr_debug("stl_cd1400txisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3308 ioack = inb(ioaddr + EREG_TXACK);
3309 if (((ioack & panelp->ackmask) != 0) ||
3310 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
3311 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
3314 portp = panelp->ports[(ioack >> 3)];
3317 * Unfortunately we need to handle breaks in the data stream, since
3318 * this is the only way to generate them on the cd1400. Do it now if
3319 * a break is to be sent.
3321 if (portp->brklen != 0)
3322 if (stl_cd1400breakisr(portp, ioaddr))
3325 head = portp->tx.head;
3326 tail = portp->tx.tail;
3327 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
3328 if ((len == 0) || ((len < STL_TXBUFLOW) &&
3329 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
3330 set_bit(ASYI_TXLOW, &portp->istate);
3331 tty = tty_port_tty_get(&portp->port);
3339 outb((SRER + portp->uartaddr), ioaddr);
3340 srer = inb(ioaddr + EREG_DATA);
3341 if (srer & SRER_TXDATA) {
3342 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
3344 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
3345 clear_bit(ASYI_TXBUSY, &portp->istate);
3347 outb(srer, (ioaddr + EREG_DATA));
3349 len = min(len, CD1400_TXFIFOSIZE);
3350 portp->stats.txtotal += len;
3351 stlen = min_t(unsigned int, len,
3352 (portp->tx.buf + STL_TXBUFSIZE) - tail);
3353 outb((TDR + portp->uartaddr), ioaddr);
3354 outsb((ioaddr + EREG_DATA), tail, stlen);
3357 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
3358 tail = portp->tx.buf;
3360 outsb((ioaddr + EREG_DATA), tail, len);
3363 portp->tx.tail = tail;
3367 outb((EOSRR + portp->uartaddr), ioaddr);
3368 outb(0, (ioaddr + EREG_DATA));
3371 /*****************************************************************************/
3374 * Receive character interrupt handler. Determine if we have good chars
3375 * or bad chars and then process appropriately. Good chars are easy
3376 * just shove the lot into the RX buffer and set all status byte to 0.
3377 * If a bad RX char then process as required. This routine needs to be
3378 * fast! In practice it is possible that we get an interrupt on a port
3379 * that is closed. This can happen on hangups - since they completely
3380 * shutdown a port not in user context. Need to handle this case.
3383 static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr)
3385 struct stlport *portp;
3386 struct tty_struct *tty;
3387 unsigned int ioack, len, buflen;
3388 unsigned char status;
3391 pr_debug("stl_cd1400rxisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3393 ioack = inb(ioaddr + EREG_RXACK);
3394 if ((ioack & panelp->ackmask) != 0) {
3395 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
3398 portp = panelp->ports[(ioack >> 3)];
3399 tty = tty_port_tty_get(&portp->port);
3401 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
3402 outb((RDCR + portp->uartaddr), ioaddr);
3403 len = inb(ioaddr + EREG_DATA);
3404 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
3405 len = min_t(unsigned int, len, sizeof(stl_unwanted));
3406 outb((RDSR + portp->uartaddr), ioaddr);
3407 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
3408 portp->stats.rxlost += len;
3409 portp->stats.rxtotal += len;
3411 len = min(len, buflen);
3414 outb((RDSR + portp->uartaddr), ioaddr);
3415 tty_prepare_flip_string(tty, &ptr, len);
3416 insb((ioaddr + EREG_DATA), ptr, len);
3417 tty_schedule_flip(tty);
3418 portp->stats.rxtotal += len;
3421 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
3422 outb((RDSR + portp->uartaddr), ioaddr);
3423 status = inb(ioaddr + EREG_DATA);
3424 ch = inb(ioaddr + EREG_DATA);
3425 if (status & ST_PARITY)
3426 portp->stats.rxparity++;
3427 if (status & ST_FRAMING)
3428 portp->stats.rxframing++;
3429 if (status & ST_OVERRUN)
3430 portp->stats.rxoverrun++;
3431 if (status & ST_BREAK)
3432 portp->stats.rxbreaks++;
3433 if (status & ST_SCHARMASK) {
3434 if ((status & ST_SCHARMASK) == ST_SCHAR1)
3435 portp->stats.txxon++;
3436 if ((status & ST_SCHARMASK) == ST_SCHAR2)
3437 portp->stats.txxoff++;
3440 if (tty != NULL && (portp->rxignoremsk & status) == 0) {
3441 if (portp->rxmarkmsk & status) {
3442 if (status & ST_BREAK) {
3444 if (portp->port.flags & ASYNC_SAK) {
3446 BRDENABLE(portp->brdnr, portp->pagenr);
3448 } else if (status & ST_PARITY)
3449 status = TTY_PARITY;
3450 else if (status & ST_FRAMING)
3452 else if(status & ST_OVERRUN)
3453 status = TTY_OVERRUN;
3458 tty_insert_flip_char(tty, ch, status);
3459 tty_schedule_flip(tty);
3462 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
3469 outb((EOSRR + portp->uartaddr), ioaddr);
3470 outb(0, (ioaddr + EREG_DATA));
3473 /*****************************************************************************/
3476 * Modem interrupt handler. The is called when the modem signal line
3477 * (DCD) has changed state. Leave most of the work to the off-level
3478 * processing routine.
3481 static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr)
3483 struct stlport *portp;
3487 pr_debug("stl_cd1400mdmisr(panelp=%p)\n", panelp);
3489 ioack = inb(ioaddr + EREG_MDACK);
3490 if (((ioack & panelp->ackmask) != 0) ||
3491 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
3492 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
3495 portp = panelp->ports[(ioack >> 3)];
3497 outb((MISR + portp->uartaddr), ioaddr);
3498 misr = inb(ioaddr + EREG_DATA);
3499 if (misr & MISR_DCD) {
3500 stl_cd_change(portp);
3501 portp->stats.modem++;
3504 outb((EOSRR + portp->uartaddr), ioaddr);
3505 outb(0, (ioaddr + EREG_DATA));
3508 /*****************************************************************************/
3509 /* SC26198 HARDWARE FUNCTIONS */
3510 /*****************************************************************************/
3513 * These functions get/set/update the registers of the sc26198 UARTs.
3514 * Access to the sc26198 registers is via an address/data io port pair.
3515 * (Maybe should make this inline...)
3518 static int stl_sc26198getreg(struct stlport *portp, int regnr)
3520 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3521 return inb(portp->ioaddr + XP_DATA);
3524 static void stl_sc26198setreg(struct stlport *portp, int regnr, int value)
3526 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3527 outb(value, (portp->ioaddr + XP_DATA));
3530 static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value)
3532 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3533 if (inb(portp->ioaddr + XP_DATA) != value) {
3534 outb(value, (portp->ioaddr + XP_DATA));
3540 /*****************************************************************************/
3543 * Functions to get and set the sc26198 global registers.
3546 static int stl_sc26198getglobreg(struct stlport *portp, int regnr)
3548 outb(regnr, (portp->ioaddr + XP_ADDR));
3549 return inb(portp->ioaddr + XP_DATA);
3553 static void stl_sc26198setglobreg(struct stlport *portp, int regnr, int value)
3555 outb(regnr, (portp->ioaddr + XP_ADDR));
3556 outb(value, (portp->ioaddr + XP_DATA));
3560 /*****************************************************************************/
3563 * Inbitialize the UARTs in a panel. We don't care what sort of board
3564 * these ports are on - since the port io registers are almost
3565 * identical when dealing with ports.
3568 static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
3571 int nrchips, ioaddr;
3573 pr_debug("stl_sc26198panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
3575 BRDENABLE(panelp->brdnr, panelp->pagenr);
3578 * Check that each chip is present and started up OK.
3581 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
3582 if (brdp->brdtype == BRD_ECHPCI)
3583 outb(panelp->pagenr, brdp->ioctrl);
3585 for (i = 0; i < nrchips; i++) {
3586 ioaddr = panelp->iobase + (i * 4);
3587 outb(SCCR, (ioaddr + XP_ADDR));
3588 outb(CR_RESETALL, (ioaddr + XP_DATA));
3589 outb(TSTR, (ioaddr + XP_ADDR));
3590 if (inb(ioaddr + XP_DATA) != 0) {
3591 printk("STALLION: sc26198 not responding, "
3592 "brd=%d panel=%d chip=%d\n",
3593 panelp->brdnr, panelp->panelnr, i);
3596 chipmask |= (0x1 << i);
3597 outb(GCCR, (ioaddr + XP_ADDR));
3598 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
3599 outb(WDTRCR, (ioaddr + XP_ADDR));
3600 outb(0xff, (ioaddr + XP_DATA));
3603 BRDDISABLE(panelp->brdnr);
3607 /*****************************************************************************/
3610 * Initialize hardware specific port registers.
3613 static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
3615 pr_debug("stl_sc26198portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
3618 if ((brdp == NULL) || (panelp == NULL) ||
3622 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
3623 portp->uartaddr = (portp->portnr & 0x07) << 4;
3624 portp->pagenr = panelp->pagenr;
3627 BRDENABLE(portp->brdnr, portp->pagenr);
3628 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
3629 BRDDISABLE(portp->brdnr);
3632 /*****************************************************************************/
3635 * Set up the sc26198 registers for a port based on the termios port
3639 static void stl_sc26198setport(struct stlport *portp, struct ktermios *tiosp)
3641 struct stlbrd *brdp;
3642 unsigned long flags;
3643 unsigned int baudrate;
3644 unsigned char mr0, mr1, mr2, clk;
3645 unsigned char imron, imroff, iopr, ipr;
3655 brdp = stl_brds[portp->brdnr];
3660 * Set up the RX char ignore mask with those RX error types we
3663 portp->rxignoremsk = 0;
3664 if (tiosp->c_iflag & IGNPAR)
3665 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
3667 if (tiosp->c_iflag & IGNBRK)
3668 portp->rxignoremsk |= SR_RXBREAK;
3670 portp->rxmarkmsk = SR_RXOVERRUN;
3671 if (tiosp->c_iflag & (INPCK | PARMRK))
3672 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
3673 if (tiosp->c_iflag & BRKINT)
3674 portp->rxmarkmsk |= SR_RXBREAK;
3677 * Go through the char size, parity and stop bits and set all the
3678 * option register appropriately.
3680 switch (tiosp->c_cflag & CSIZE) {
3695 if (tiosp->c_cflag & CSTOPB)
3700 if (tiosp->c_cflag & PARENB) {
3701 if (tiosp->c_cflag & PARODD)
3702 mr1 |= (MR1_PARENB | MR1_PARODD);
3704 mr1 |= (MR1_PARENB | MR1_PAREVEN);
3708 mr1 |= MR1_ERRBLOCK;
3711 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
3712 * space for hardware flow control and the like. This should be set to
3715 mr2 |= MR2_RXFIFOHALF;
3718 * Calculate the baud rate timers. For now we will just assume that
3719 * the input and output baud are the same. The sc26198 has a fixed
3720 * baud rate table, so only discrete baud rates possible.
3722 baudrate = tiosp->c_cflag & CBAUD;
3723 if (baudrate & CBAUDEX) {
3724 baudrate &= ~CBAUDEX;
3725 if ((baudrate < 1) || (baudrate > 4))
3726 tiosp->c_cflag &= ~CBAUDEX;
3730 baudrate = stl_baudrates[baudrate];
3731 if ((tiosp->c_cflag & CBAUD) == B38400) {
3732 if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3734 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3736 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3738 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3740 else if ((portp->port.flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3741 baudrate = (portp->baud_base / portp->custom_divisor);
3743 if (baudrate > STL_SC26198MAXBAUD)
3744 baudrate = STL_SC26198MAXBAUD;
3747 for (clk = 0; clk < SC26198_NRBAUDS; clk++)
3748 if (baudrate <= sc26198_baudtable[clk])
3752 * Check what form of modem signaling is required and set it up.
3754 if (tiosp->c_cflag & CLOCAL) {
3755 portp->port.flags &= ~ASYNC_CHECK_CD;
3757 iopr |= IOPR_DCDCOS;
3759 portp->port.flags |= ASYNC_CHECK_CD;
3763 * Setup sc26198 enhanced modes if we can. In particular we want to
3764 * handle as much of the flow control as possible automatically. As
3765 * well as saving a few CPU cycles it will also greatly improve flow
3766 * control reliability.
3768 if (tiosp->c_iflag & IXON) {
3769 mr0 |= MR0_SWFTX | MR0_SWFT;
3770 imron |= IR_XONXOFF;
3772 imroff |= IR_XONXOFF;
3774 if (tiosp->c_iflag & IXOFF)
3777 if (tiosp->c_cflag & CRTSCTS) {
3783 * All sc26198 register values calculated so go through and set
3787 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3788 portp->portnr, portp->panelnr, portp->brdnr);
3789 pr_debug(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
3790 pr_debug(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
3791 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3792 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3793 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3795 spin_lock_irqsave(&brd_lock, flags);
3796 BRDENABLE(portp->brdnr, portp->pagenr);
3797 stl_sc26198setreg(portp, IMR, 0);
3798 stl_sc26198updatereg(portp, MR0, mr0);
3799 stl_sc26198updatereg(portp, MR1, mr1);
3800 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
3801 stl_sc26198updatereg(portp, MR2, mr2);
3802 stl_sc26198updatereg(portp, IOPIOR,
3803 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
3806 stl_sc26198setreg(portp, TXCSR, clk);
3807 stl_sc26198setreg(portp, RXCSR, clk);
3810 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
3811 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
3813 ipr = stl_sc26198getreg(portp, IPR);
3815 portp->sigs &= ~TIOCM_CD;
3817 portp->sigs |= TIOCM_CD;
3819 portp->imr = (portp->imr & ~imroff) | imron;
3820 stl_sc26198setreg(portp, IMR, portp->imr);
3821 BRDDISABLE(portp->brdnr);
3822 spin_unlock_irqrestore(&brd_lock, flags);
3825 /*****************************************************************************/
3828 * Set the state of the DTR and RTS signals.
3831 static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts)
3833 unsigned char iopioron, iopioroff;
3834 unsigned long flags;
3836 pr_debug("stl_sc26198setsignals(portp=%p,dtr=%d,rts=%d)\n", portp,
3842 iopioroff |= IPR_DTR;
3844 iopioron |= IPR_DTR;
3846 iopioroff |= IPR_RTS;
3848 iopioron |= IPR_RTS;
3850 spin_lock_irqsave(&brd_lock, flags);
3851 BRDENABLE(portp->brdnr, portp->pagenr);
3852 stl_sc26198setreg(portp, IOPIOR,
3853 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
3854 BRDDISABLE(portp->brdnr);
3855 spin_unlock_irqrestore(&brd_lock, flags);
3858 /*****************************************************************************/
3861 * Return the state of the signals.
3864 static int stl_sc26198getsignals(struct stlport *portp)
3867 unsigned long flags;
3870 pr_debug("stl_sc26198getsignals(portp=%p)\n", portp);
3872 spin_lock_irqsave(&brd_lock, flags);
3873 BRDENABLE(portp->brdnr, portp->pagenr);
3874 ipr = stl_sc26198getreg(portp, IPR);
3875 BRDDISABLE(portp->brdnr);
3876 spin_unlock_irqrestore(&brd_lock, flags);
3879 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
3880 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
3881 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
3882 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
3887 /*****************************************************************************/
3890 * Enable/Disable the Transmitter and/or Receiver.
3893 static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx)
3896 unsigned long flags;
3898 pr_debug("stl_sc26198enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx,tx);
3900 ccr = portp->crenable;
3902 ccr &= ~CR_TXENABLE;
3906 ccr &= ~CR_RXENABLE;
3910 spin_lock_irqsave(&brd_lock, flags);
3911 BRDENABLE(portp->brdnr, portp->pagenr);
3912 stl_sc26198setreg(portp, SCCR, ccr);
3913 BRDDISABLE(portp->brdnr);
3914 portp->crenable = ccr;
3915 spin_unlock_irqrestore(&brd_lock, flags);
3918 /*****************************************************************************/
3921 * Start/stop the Transmitter and/or Receiver.
3924 static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx)
3927 unsigned long flags;
3929 pr_debug("stl_sc26198startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
3937 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
3939 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
3941 spin_lock_irqsave(&brd_lock, flags);
3942 BRDENABLE(portp->brdnr, portp->pagenr);
3943 stl_sc26198setreg(portp, IMR, imr);
3944 BRDDISABLE(portp->brdnr);
3947 set_bit(ASYI_TXBUSY, &portp->istate);
3948 spin_unlock_irqrestore(&brd_lock, flags);
3951 /*****************************************************************************/
3954 * Disable all interrupts from this port.
3957 static void stl_sc26198disableintrs(struct stlport *portp)
3959 unsigned long flags;
3961 pr_debug("stl_sc26198disableintrs(portp=%p)\n", portp);
3963 spin_lock_irqsave(&brd_lock, flags);
3964 BRDENABLE(portp->brdnr, portp->pagenr);
3966 stl_sc26198setreg(portp, IMR, 0);
3967 BRDDISABLE(portp->brdnr);
3968 spin_unlock_irqrestore(&brd_lock, flags);
3971 /*****************************************************************************/
3973 static void stl_sc26198sendbreak(struct stlport *portp, int len)
3975 unsigned long flags;
3977 pr_debug("stl_sc26198sendbreak(portp=%p,len=%d)\n", portp, len);
3979 spin_lock_irqsave(&brd_lock, flags);
3980 BRDENABLE(portp->brdnr, portp->pagenr);
3982 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
3983 portp->stats.txbreaks++;
3985 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
3987 BRDDISABLE(portp->brdnr);
3988 spin_unlock_irqrestore(&brd_lock, flags);
3991 /*****************************************************************************/
3994 * Take flow control actions...
3997 static void stl_sc26198flowctrl(struct stlport *portp, int state)
3999 struct tty_struct *tty;
4000 unsigned long flags;
4003 pr_debug("stl_sc26198flowctrl(portp=%p,state=%x)\n", portp, state);
4007 tty = tty_port_tty_get(&portp->port);
4011 spin_lock_irqsave(&brd_lock, flags);
4012 BRDENABLE(portp->brdnr, portp->pagenr);
4015 if (tty->termios->c_iflag & IXOFF) {
4016 mr0 = stl_sc26198getreg(portp, MR0);
4017 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4018 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4020 portp->stats.rxxon++;
4021 stl_sc26198wait(portp);
4022 stl_sc26198setreg(portp, MR0, mr0);
4025 * Question: should we return RTS to what it was before? It may
4026 * have been set by an ioctl... Suppose not, since if you have
4027 * hardware flow control set then it is pretty silly to go and
4028 * set the RTS line by hand.
4030 if (tty->termios->c_cflag & CRTSCTS) {
4031 stl_sc26198setreg(portp, MR1,
4032 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4033 stl_sc26198setreg(portp, IOPIOR,
4034 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4035 portp->stats.rxrtson++;
4038 if (tty->termios->c_iflag & IXOFF) {
4039 mr0 = stl_sc26198getreg(portp, MR0);
4040 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4041 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4043 portp->stats.rxxoff++;
4044 stl_sc26198wait(portp);
4045 stl_sc26198setreg(portp, MR0, mr0);
4047 if (tty->termios->c_cflag & CRTSCTS) {
4048 stl_sc26198setreg(portp, MR1,
4049 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4050 stl_sc26198setreg(portp, IOPIOR,
4051 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4052 portp->stats.rxrtsoff++;
4056 BRDDISABLE(portp->brdnr);
4057 spin_unlock_irqrestore(&brd_lock, flags);
4061 /*****************************************************************************/
4064 * Send a flow control character.
4067 static void stl_sc26198sendflow(struct stlport *portp, int state)
4069 struct tty_struct *tty;
4070 unsigned long flags;
4073 pr_debug("stl_sc26198sendflow(portp=%p,state=%x)\n", portp, state);
4077 tty = tty_port_tty_get(&portp->port);
4081 spin_lock_irqsave(&brd_lock, flags);
4082 BRDENABLE(portp->brdnr, portp->pagenr);
4084 mr0 = stl_sc26198getreg(portp, MR0);
4085 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4086 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4088 portp->stats.rxxon++;
4089 stl_sc26198wait(portp);
4090 stl_sc26198setreg(portp, MR0, mr0);
4092 mr0 = stl_sc26198getreg(portp, MR0);
4093 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4094 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4096 portp->stats.rxxoff++;
4097 stl_sc26198wait(portp);
4098 stl_sc26198setreg(portp, MR0, mr0);
4100 BRDDISABLE(portp->brdnr);
4101 spin_unlock_irqrestore(&brd_lock, flags);
4105 /*****************************************************************************/
4107 static void stl_sc26198flush(struct stlport *portp)
4109 unsigned long flags;
4111 pr_debug("stl_sc26198flush(portp=%p)\n", portp);
4116 spin_lock_irqsave(&brd_lock, flags);
4117 BRDENABLE(portp->brdnr, portp->pagenr);
4118 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4119 stl_sc26198setreg(portp, SCCR, portp->crenable);
4120 BRDDISABLE(portp->brdnr);
4121 portp->tx.tail = portp->tx.head;
4122 spin_unlock_irqrestore(&brd_lock, flags);
4125 /*****************************************************************************/
4128 * Return the current state of data flow on this port. This is only
4129 * really interresting when determining if data has fully completed
4130 * transmission or not... The sc26198 interrupt scheme cannot
4131 * determine when all data has actually drained, so we need to
4132 * check the port statusy register to be sure.
4135 static int stl_sc26198datastate(struct stlport *portp)
4137 unsigned long flags;
4140 pr_debug("stl_sc26198datastate(portp=%p)\n", portp);
4144 if (test_bit(ASYI_TXBUSY, &portp->istate))
4147 spin_lock_irqsave(&brd_lock, flags);
4148 BRDENABLE(portp->brdnr, portp->pagenr);
4149 sr = stl_sc26198getreg(portp, SR);
4150 BRDDISABLE(portp->brdnr);
4151 spin_unlock_irqrestore(&brd_lock, flags);
4153 return (sr & SR_TXEMPTY) ? 0 : 1;
4156 /*****************************************************************************/
4159 * Delay for a small amount of time, to give the sc26198 a chance
4160 * to process a command...
4163 static void stl_sc26198wait(struct stlport *portp)
4167 pr_debug("stl_sc26198wait(portp=%p)\n", portp);
4172 for (i = 0; i < 20; i++)
4173 stl_sc26198getglobreg(portp, TSTR);
4176 /*****************************************************************************/
4179 * If we are TX flow controlled and in IXANY mode then we may
4180 * need to unflow control here. We gotta do this because of the
4181 * automatic flow control modes of the sc26198.
4184 static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty)
4188 mr0 = stl_sc26198getreg(portp, MR0);
4189 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4190 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4191 stl_sc26198wait(portp);
4192 stl_sc26198setreg(portp, MR0, mr0);
4193 clear_bit(ASYI_TXFLOWED, &portp->istate);
4196 /*****************************************************************************/
4199 * Interrupt service routine for sc26198 panels.
4202 static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase)
4204 struct stlport *portp;
4207 spin_lock(&brd_lock);
4210 * Work around bug in sc26198 chip... Cannot have A6 address
4211 * line of UART high, else iack will be returned as 0.
4213 outb(0, (iobase + 1));
4215 iack = inb(iobase + XP_IACK);
4216 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4218 if (iack & IVR_RXDATA)
4219 stl_sc26198rxisr(portp, iack);
4220 else if (iack & IVR_TXDATA)
4221 stl_sc26198txisr(portp);
4223 stl_sc26198otherisr(portp, iack);
4225 spin_unlock(&brd_lock);
4228 /*****************************************************************************/
4231 * Transmit interrupt handler. This has gotta be fast! Handling TX
4232 * chars is pretty simple, stuff as many as possible from the TX buffer
4233 * into the sc26198 FIFO.
4234 * In practice it is possible that interrupts are enabled but that the
4235 * port has been hung up. Need to handle not having any TX buffer here,
4236 * this is done by using the side effect that head and tail will also
4237 * be NULL if the buffer has been freed.
4240 static void stl_sc26198txisr(struct stlport *portp)
4242 struct tty_struct *tty;
4243 unsigned int ioaddr;
4248 pr_debug("stl_sc26198txisr(portp=%p)\n", portp);
4250 ioaddr = portp->ioaddr;
4251 head = portp->tx.head;
4252 tail = portp->tx.tail;
4253 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4254 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4255 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4256 set_bit(ASYI_TXLOW, &portp->istate);
4257 tty = tty_port_tty_get(&portp->port);
4265 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
4266 mr0 = inb(ioaddr + XP_DATA);
4267 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4268 portp->imr &= ~IR_TXRDY;
4269 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
4270 outb(portp->imr, (ioaddr + XP_DATA));
4271 clear_bit(ASYI_TXBUSY, &portp->istate);
4273 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4274 outb(mr0, (ioaddr + XP_DATA));
4277 len = min(len, SC26198_TXFIFOSIZE);
4278 portp->stats.txtotal += len;
4279 stlen = min_t(unsigned int, len,
4280 (portp->tx.buf + STL_TXBUFSIZE) - tail);
4281 outb(GTXFIFO, (ioaddr + XP_ADDR));
4282 outsb((ioaddr + XP_DATA), tail, stlen);
4285 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4286 tail = portp->tx.buf;
4288 outsb((ioaddr + XP_DATA), tail, len);
4291 portp->tx.tail = tail;
4295 /*****************************************************************************/
4298 * Receive character interrupt handler. Determine if we have good chars
4299 * or bad chars and then process appropriately. Good chars are easy
4300 * just shove the lot into the RX buffer and set all status byte to 0.
4301 * If a bad RX char then process as required. This routine needs to be
4302 * fast! In practice it is possible that we get an interrupt on a port
4303 * that is closed. This can happen on hangups - since they completely
4304 * shutdown a port not in user context. Need to handle this case.
4307 static void stl_sc26198rxisr(struct stlport *portp, unsigned int iack)
4309 struct tty_struct *tty;
4310 unsigned int len, buflen, ioaddr;
4312 pr_debug("stl_sc26198rxisr(portp=%p,iack=%x)\n", portp, iack);
4314 tty = tty_port_tty_get(&portp->port);
4315 ioaddr = portp->ioaddr;
4316 outb(GIBCR, (ioaddr + XP_ADDR));
4317 len = inb(ioaddr + XP_DATA) + 1;
4319 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
4320 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
4321 len = min_t(unsigned int, len, sizeof(stl_unwanted));
4322 outb(GRXFIFO, (ioaddr + XP_ADDR));
4323 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4324 portp->stats.rxlost += len;
4325 portp->stats.rxtotal += len;
4327 len = min(len, buflen);
4330 outb(GRXFIFO, (ioaddr + XP_ADDR));
4331 tty_prepare_flip_string(tty, &ptr, len);
4332 insb((ioaddr + XP_DATA), ptr, len);
4333 tty_schedule_flip(tty);
4334 portp->stats.rxtotal += len;
4338 stl_sc26198rxbadchars(portp);
4342 * If we are TX flow controlled and in IXANY mode then we may need
4343 * to unflow control here. We gotta do this because of the automatic
4344 * flow control modes of the sc26198.
4346 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
4347 if ((tty != NULL) &&
4348 (tty->termios != NULL) &&
4349 (tty->termios->c_iflag & IXANY)) {
4350 stl_sc26198txunflow(portp, tty);
4356 /*****************************************************************************/
4359 * Process an RX bad character.
4362 static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch)
4364 struct tty_struct *tty;
4365 unsigned int ioaddr;
4367 tty = tty_port_tty_get(&portp->port);
4368 ioaddr = portp->ioaddr;
4370 if (status & SR_RXPARITY)
4371 portp->stats.rxparity++;
4372 if (status & SR_RXFRAMING)
4373 portp->stats.rxframing++;
4374 if (status & SR_RXOVERRUN)
4375 portp->stats.rxoverrun++;
4376 if (status & SR_RXBREAK)
4377 portp->stats.rxbreaks++;
4379 if ((tty != NULL) &&
4380 ((portp->rxignoremsk & status) == 0)) {
4381 if (portp->rxmarkmsk & status) {
4382 if (status & SR_RXBREAK) {
4384 if (portp->port.flags & ASYNC_SAK) {
4386 BRDENABLE(portp->brdnr, portp->pagenr);
4388 } else if (status & SR_RXPARITY)
4389 status = TTY_PARITY;
4390 else if (status & SR_RXFRAMING)
4392 else if(status & SR_RXOVERRUN)
4393 status = TTY_OVERRUN;
4399 tty_insert_flip_char(tty, ch, status);
4400 tty_schedule_flip(tty);
4403 portp->stats.rxtotal++;
4408 /*****************************************************************************/
4411 * Process all characters in the RX FIFO of the UART. Check all char
4412 * status bytes as well, and process as required. We need to check
4413 * all bytes in the FIFO, in case some more enter the FIFO while we
4414 * are here. To get the exact character error type we need to switch
4415 * into CHAR error mode (that is why we need to make sure we empty
4419 static void stl_sc26198rxbadchars(struct stlport *portp)
4421 unsigned char status, mr1;
4425 * To get the precise error type for each character we must switch
4426 * back into CHAR error mode.
4428 mr1 = stl_sc26198getreg(portp, MR1);
4429 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
4431 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
4432 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
4433 ch = stl_sc26198getreg(portp, RXFIFO);
4434 stl_sc26198rxbadch(portp, status, ch);
4438 * To get correct interrupt class we must switch back into BLOCK
4441 stl_sc26198setreg(portp, MR1, mr1);
4444 /*****************************************************************************/
4447 * Other interrupt handler. This includes modem signals, flow
4448 * control actions, etc. Most stuff is left to off-level interrupt
4452 static void stl_sc26198otherisr(struct stlport *portp, unsigned int iack)
4454 unsigned char cir, ipr, xisr;
4456 pr_debug("stl_sc26198otherisr(portp=%p,iack=%x)\n", portp, iack);
4458 cir = stl_sc26198getglobreg(portp, CIR);
4460 switch (cir & CIR_SUBTYPEMASK) {
4462 ipr = stl_sc26198getreg(portp, IPR);
4463 if (ipr & IPR_DCDCHANGE) {
4464 stl_cd_change(portp);
4465 portp->stats.modem++;
4468 case CIR_SUBXONXOFF:
4469 xisr = stl_sc26198getreg(portp, XISR);
4470 if (xisr & XISR_RXXONGOT) {
4471 set_bit(ASYI_TXFLOWED, &portp->istate);
4472 portp->stats.txxoff++;
4474 if (xisr & XISR_RXXOFFGOT) {
4475 clear_bit(ASYI_TXFLOWED, &portp->istate);
4476 portp->stats.txxon++;
4480 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
4481 stl_sc26198rxbadchars(portp);
4488 static void stl_free_isabrds(void)
4490 struct stlbrd *brdp;
4493 for (i = 0; i < stl_nrbrds; i++) {
4494 if ((brdp = stl_brds[i]) == NULL || (brdp->state & STL_PROBED))
4497 free_irq(brdp->irq, brdp);
4499 stl_cleanup_panels(brdp);
4501 release_region(brdp->ioaddr1, brdp->iosize1);
4502 if (brdp->iosize2 > 0)
4503 release_region(brdp->ioaddr2, brdp->iosize2);
4511 * Loadable module initialization stuff.
4513 static int __init stallion_module_init(void)
4515 struct stlbrd *brdp;
4516 struct stlconf conf;
4520 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
4522 spin_lock_init(&stallion_lock);
4523 spin_lock_init(&brd_lock);
4525 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
4531 stl_serial->owner = THIS_MODULE;
4532 stl_serial->driver_name = stl_drvname;
4533 stl_serial->name = "ttyE";
4534 stl_serial->major = STL_SERIALMAJOR;
4535 stl_serial->minor_start = 0;
4536 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
4537 stl_serial->subtype = SERIAL_TYPE_NORMAL;
4538 stl_serial->init_termios = stl_deftermios;
4539 stl_serial->flags = TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV;
4540 tty_set_operations(stl_serial, &stl_ops);
4542 retval = tty_register_driver(stl_serial);
4544 printk("STALLION: failed to register serial driver\n");
4549 * Find any dynamically supported boards. That is via module load
4552 for (i = stl_nrbrds; i < stl_nargs; i++) {
4553 memset(&conf, 0, sizeof(conf));
4554 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
4556 if ((brdp = stl_allocbrd()) == NULL)
4559 brdp->brdtype = conf.brdtype;
4560 brdp->ioaddr1 = conf.ioaddr1;
4561 brdp->ioaddr2 = conf.ioaddr2;
4562 brdp->irq = conf.irq;
4563 brdp->irqtype = conf.irqtype;
4564 stl_brds[brdp->brdnr] = brdp;
4565 if (stl_brdinit(brdp)) {
4566 stl_brds[brdp->brdnr] = NULL;
4569 for (j = 0; j < brdp->nrports; j++)
4570 tty_register_device(stl_serial,
4571 brdp->brdnr * STL_MAXPORTS + j, NULL);
4576 /* this has to be _after_ isa finding because of locking */
4577 retval = pci_register_driver(&stl_pcidriver);
4578 if (retval && stl_nrbrds == 0) {
4579 printk(KERN_ERR "STALLION: can't register pci driver\n");
4584 * Set up a character driver for per board stuff. This is mainly used
4585 * to do stats ioctls on the ports.
4587 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
4588 printk("STALLION: failed to register serial board device\n");
4590 stallion_class = class_create(THIS_MODULE, "staliomem");
4591 if (IS_ERR(stallion_class))
4592 printk("STALLION: failed to create class\n");
4593 for (i = 0; i < 4; i++)
4594 device_create(stallion_class, NULL, MKDEV(STL_SIOMEMMAJOR, i),
4595 NULL, "staliomem%d", i);
4599 tty_unregister_driver(stl_serial);
4601 put_tty_driver(stl_serial);
4606 static void __exit stallion_module_exit(void)
4608 struct stlbrd *brdp;
4611 pr_debug("cleanup_module()\n");
4613 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
4617 * Free up all allocated resources used by the ports. This includes
4618 * memory and interrupts. As part of this process we will also do
4619 * a hangup on every open port - to try to flush out any processes
4620 * hanging onto ports.
4622 for (i = 0; i < stl_nrbrds; i++) {
4623 if ((brdp = stl_brds[i]) == NULL || (brdp->state & STL_PROBED))
4625 for (j = 0; j < brdp->nrports; j++)
4626 tty_unregister_device(stl_serial,
4627 brdp->brdnr * STL_MAXPORTS + j);
4630 for (i = 0; i < 4; i++)
4631 device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
4632 unregister_chrdev(STL_SIOMEMMAJOR, "staliomem");
4633 class_destroy(stallion_class);
4635 pci_unregister_driver(&stl_pcidriver);
4639 tty_unregister_driver(stl_serial);
4640 put_tty_driver(stl_serial);
4643 module_init(stallion_module_init);
4644 module_exit(stallion_module_exit);
4646 MODULE_AUTHOR("Greg Ungerer");
4647 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
4648 MODULE_LICENSE("GPL");