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/config.h>
30 #include <linux/module.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/cd1400.h>
37 #include <linux/sc26198.h>
38 #include <linux/comstats.h>
39 #include <linux/stallion.h>
40 #include <linux/ioport.h>
41 #include <linux/init.h>
42 #include <linux/smp_lock.h>
43 #include <linux/device.h>
44 #include <linux/delay.h>
47 #include <asm/uaccess.h>
50 #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
68 * Define a configuration structure to hold the board configuration.
69 * Need to set this up in the code (for now) with the boards that are
70 * to be configured into the system. This is what needs to be modified
71 * when adding/removing/modifying boards. Each line entry in the
72 * stl_brdconf[] array is a board. Each line contains io/irq/memory
73 * ranges for that board (as well as what type of board it is).
75 * { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
76 * This line would configure an EasyIO board (4 or 8, no difference),
77 * at io address 2a0 and irq 10.
79 * { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
80 * This line will configure an EasyConnection 8/32 board at primary io
81 * address 2a8, secondary io address 280 and irq 12.
82 * Enter as many lines into this array as you want (only the first 4
83 * will actually be used!). Any combination of EasyIO and EasyConnection
84 * boards can be specified. EasyConnection 8/32 boards can share their
85 * secondary io addresses between each other.
87 * NOTE: there is no need to put any entries in this table for PCI
88 * boards. They will be found automatically by the driver - provided
89 * PCI BIOS32 support is compiled into the kernel.
96 unsigned long memaddr;
101 static stlconf_t stl_brdconf[] = {
102 /*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
105 static int stl_nrbrds = ARRAY_SIZE(stl_brdconf);
107 /*****************************************************************************/
110 * Define some important driver characteristics. Device major numbers
111 * allocated as per Linux Device Registry.
113 #ifndef STL_SIOMEMMAJOR
114 #define STL_SIOMEMMAJOR 28
116 #ifndef STL_SERIALMAJOR
117 #define STL_SERIALMAJOR 24
119 #ifndef STL_CALLOUTMAJOR
120 #define STL_CALLOUTMAJOR 25
124 * Set the TX buffer size. Bigger is better, but we don't want
125 * to chew too much memory with buffers!
127 #define STL_TXBUFLOW 512
128 #define STL_TXBUFSIZE 4096
130 /*****************************************************************************/
133 * Define our local driver identity first. Set up stuff to deal with
134 * all the local structures required by a serial tty driver.
136 static char *stl_drvtitle = "Stallion Multiport Serial Driver";
137 static char *stl_drvname = "stallion";
138 static char *stl_drvversion = "5.6.0";
140 static struct tty_driver *stl_serial;
143 * We will need to allocate a temporary write buffer for chars that
144 * come direct from user space. The problem is that a copy from user
145 * space might cause a page fault (typically on a system that is
146 * swapping!). All ports will share one buffer - since if the system
147 * is already swapping a shared buffer won't make things any worse.
149 static char *stl_tmpwritebuf;
152 * Define a local default termios struct. All ports will be created
153 * with this termios initially. Basically all it defines is a raw port
154 * at 9600, 8 data bits, 1 stop bit.
156 static struct termios stl_deftermios = {
157 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
162 * Define global stats structures. Not used often, and can be
163 * re-used for each stats call.
165 static comstats_t stl_comstats;
166 static combrd_t stl_brdstats;
167 static stlbrd_t stl_dummybrd;
168 static stlport_t stl_dummyport;
171 * Define global place to put buffer overflow characters.
173 static char stl_unwanted[SC26198_RXFIFOSIZE];
175 /*****************************************************************************/
177 static stlbrd_t *stl_brds[STL_MAXBRDS];
180 * Per board state flags. Used with the state field of the board struct.
181 * Not really much here!
183 #define BRD_FOUND 0x1
186 * Define the port structure istate flags. These set of flags are
187 * modified at interrupt time - so setting and reseting them needs
188 * to be atomic. Use the bit clear/setting routines for this.
190 #define ASYI_TXBUSY 1
192 #define ASYI_DCDCHANGE 3
193 #define ASYI_TXFLOWED 4
196 * Define an array of board names as printable strings. Handy for
197 * referencing boards when printing trace and stuff.
199 static char *stl_brdnames[] = {
231 /*****************************************************************************/
234 * Define some string labels for arguments passed from the module
235 * load line. These allow for easy board definitions, and easy
236 * modification of the io, memory and irq resoucres.
238 static int stl_nargs = 0;
239 static char *board0[4];
240 static char *board1[4];
241 static char *board2[4];
242 static char *board3[4];
244 static char **stl_brdsp[] = {
252 * Define a set of common board names, and types. This is used to
253 * parse any module arguments.
256 typedef struct stlbrdtype {
261 static stlbrdtype_t stl_brdstr[] = {
262 { "easyio", BRD_EASYIO },
263 { "eio", BRD_EASYIO },
264 { "20", BRD_EASYIO },
265 { "ec8/32", BRD_ECH },
266 { "ec8/32-at", BRD_ECH },
267 { "ec8/32-isa", BRD_ECH },
269 { "echat", BRD_ECH },
271 { "ec8/32-mc", BRD_ECHMC },
272 { "ec8/32-mca", BRD_ECHMC },
273 { "echmc", BRD_ECHMC },
274 { "echmca", BRD_ECHMC },
276 { "ec8/32-pc", BRD_ECHPCI },
277 { "ec8/32-pci", BRD_ECHPCI },
278 { "26", BRD_ECHPCI },
279 { "ec8/64-pc", BRD_ECH64PCI },
280 { "ec8/64-pci", BRD_ECH64PCI },
281 { "ech-pci", BRD_ECH64PCI },
282 { "echpci", BRD_ECH64PCI },
283 { "echpc", BRD_ECH64PCI },
284 { "27", BRD_ECH64PCI },
285 { "easyio-pc", BRD_EASYIOPCI },
286 { "easyio-pci", BRD_EASYIOPCI },
287 { "eio-pci", BRD_EASYIOPCI },
288 { "eiopci", BRD_EASYIOPCI },
289 { "28", BRD_EASYIOPCI },
293 * Define the module agruments.
295 MODULE_AUTHOR("Greg Ungerer");
296 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
297 MODULE_LICENSE("GPL");
299 module_param_array(board0, charp, &stl_nargs, 0);
300 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
301 module_param_array(board1, charp, &stl_nargs, 0);
302 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
303 module_param_array(board2, charp, &stl_nargs, 0);
304 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
305 module_param_array(board3, charp, &stl_nargs, 0);
306 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
308 /*****************************************************************************/
311 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
312 * to the directly accessible io ports of these boards (not the uarts -
313 * they are in cd1400.h and sc26198.h).
315 #define EIO_8PORTRS 0x04
316 #define EIO_4PORTRS 0x05
317 #define EIO_8PORTDI 0x00
318 #define EIO_8PORTM 0x06
320 #define EIO_IDBITMASK 0x07
322 #define EIO_BRDMASK 0xf0
325 #define ID_BRD16 0x30
327 #define EIO_INTRPEND 0x08
328 #define EIO_INTEDGE 0x00
329 #define EIO_INTLEVEL 0x08
333 #define ECH_IDBITMASK 0xe0
334 #define ECH_BRDENABLE 0x08
335 #define ECH_BRDDISABLE 0x00
336 #define ECH_INTENABLE 0x01
337 #define ECH_INTDISABLE 0x00
338 #define ECH_INTLEVEL 0x02
339 #define ECH_INTEDGE 0x00
340 #define ECH_INTRPEND 0x01
341 #define ECH_BRDRESET 0x01
343 #define ECHMC_INTENABLE 0x01
344 #define ECHMC_BRDRESET 0x02
346 #define ECH_PNLSTATUS 2
347 #define ECH_PNL16PORT 0x20
348 #define ECH_PNLIDMASK 0x07
349 #define ECH_PNLXPID 0x40
350 #define ECH_PNLINTRPEND 0x80
352 #define ECH_ADDR2MASK 0x1e0
355 * Define the vector mapping bits for the programmable interrupt board
356 * hardware. These bits encode the interrupt for the board to use - it
357 * is software selectable (except the EIO-8M).
359 static unsigned char stl_vecmap[] = {
360 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
361 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
365 * Set up enable and disable macros for the ECH boards. They require
366 * the secondary io address space to be activated and deactivated.
367 * This way all ECH boards can share their secondary io region.
368 * If this is an ECH-PCI board then also need to set the page pointer
369 * to point to the correct page.
371 #define BRDENABLE(brdnr,pagenr) \
372 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
373 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
374 stl_brds[(brdnr)]->ioctrl); \
375 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
376 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
378 #define BRDDISABLE(brdnr) \
379 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
380 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
381 stl_brds[(brdnr)]->ioctrl);
383 #define STL_CD1400MAXBAUD 230400
384 #define STL_SC26198MAXBAUD 460800
386 #define STL_BAUDBASE 115200
387 #define STL_CLOSEDELAY (5 * HZ / 10)
389 /*****************************************************************************/
394 * Define the Stallion PCI vendor and device IDs.
396 #ifndef PCI_VENDOR_ID_STALLION
397 #define PCI_VENDOR_ID_STALLION 0x124d
399 #ifndef PCI_DEVICE_ID_ECHPCI832
400 #define PCI_DEVICE_ID_ECHPCI832 0x0000
402 #ifndef PCI_DEVICE_ID_ECHPCI864
403 #define PCI_DEVICE_ID_ECHPCI864 0x0002
405 #ifndef PCI_DEVICE_ID_EIOPCI
406 #define PCI_DEVICE_ID_EIOPCI 0x0003
410 * Define structure to hold all Stallion PCI boards.
412 typedef struct stlpcibrd {
413 unsigned short vendid;
414 unsigned short devid;
418 static stlpcibrd_t stl_pcibrds[] = {
419 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864, BRD_ECH64PCI },
420 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI, BRD_EASYIOPCI },
421 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832, BRD_ECHPCI },
422 { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
425 static int stl_nrpcibrds = ARRAY_SIZE(stl_pcibrds);
429 /*****************************************************************************/
432 * Define macros to extract a brd/port number from a minor number.
434 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
435 #define MINOR2PORT(min) ((min) & 0x3f)
438 * Define a baud rate table that converts termios baud rate selector
439 * into the actual baud rate value. All baud rate calculations are
440 * based on the actual baud rate required.
442 static unsigned int stl_baudrates[] = {
443 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
444 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
448 * Define some handy local macros...
451 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
454 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
456 /*****************************************************************************/
459 * Declare all those functions in this driver!
462 static void stl_argbrds(void);
463 static int stl_parsebrd(stlconf_t *confp, char **argp);
465 static unsigned long stl_atol(char *str);
467 static int stl_init(void);
468 static int stl_open(struct tty_struct *tty, struct file *filp);
469 static void stl_close(struct tty_struct *tty, struct file *filp);
470 static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count);
471 static void stl_putchar(struct tty_struct *tty, unsigned char ch);
472 static void stl_flushchars(struct tty_struct *tty);
473 static int stl_writeroom(struct tty_struct *tty);
474 static int stl_charsinbuffer(struct tty_struct *tty);
475 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
476 static void stl_settermios(struct tty_struct *tty, struct termios *old);
477 static void stl_throttle(struct tty_struct *tty);
478 static void stl_unthrottle(struct tty_struct *tty);
479 static void stl_stop(struct tty_struct *tty);
480 static void stl_start(struct tty_struct *tty);
481 static void stl_flushbuffer(struct tty_struct *tty);
482 static void stl_breakctl(struct tty_struct *tty, int state);
483 static void stl_waituntilsent(struct tty_struct *tty, int timeout);
484 static void stl_sendxchar(struct tty_struct *tty, char ch);
485 static void stl_hangup(struct tty_struct *tty);
486 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
487 static int stl_portinfo(stlport_t *portp, int portnr, char *pos);
488 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data);
490 static int stl_brdinit(stlbrd_t *brdp);
491 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
492 static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp);
493 static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp);
494 static int stl_getbrdstats(combrd_t __user *bp);
495 static int stl_getportstats(stlport_t *portp, comstats_t __user *cp);
496 static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp);
497 static int stl_getportstruct(stlport_t __user *arg);
498 static int stl_getbrdstruct(stlbrd_t __user *arg);
499 static int stl_waitcarrier(stlport_t *portp, struct file *filp);
500 static int stl_eiointr(stlbrd_t *brdp);
501 static int stl_echatintr(stlbrd_t *brdp);
502 static int stl_echmcaintr(stlbrd_t *brdp);
503 static int stl_echpciintr(stlbrd_t *brdp);
504 static int stl_echpci64intr(stlbrd_t *brdp);
505 static void stl_offintr(void *private);
506 static stlbrd_t *stl_allocbrd(void);
507 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
509 static inline int stl_initbrds(void);
510 static inline int stl_initeio(stlbrd_t *brdp);
511 static inline int stl_initech(stlbrd_t *brdp);
512 static inline int stl_getbrdnr(void);
515 static inline int stl_findpcibrds(void);
516 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp);
520 * CD1400 uart specific handling functions.
522 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value);
523 static int stl_cd1400getreg(stlport_t *portp, int regnr);
524 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value);
525 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
526 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
527 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp);
528 static int stl_cd1400getsignals(stlport_t *portp);
529 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts);
530 static void stl_cd1400ccrwait(stlport_t *portp);
531 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx);
532 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx);
533 static void stl_cd1400disableintrs(stlport_t *portp);
534 static void stl_cd1400sendbreak(stlport_t *portp, int len);
535 static void stl_cd1400flowctrl(stlport_t *portp, int state);
536 static void stl_cd1400sendflow(stlport_t *portp, int state);
537 static void stl_cd1400flush(stlport_t *portp);
538 static int stl_cd1400datastate(stlport_t *portp);
539 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase);
540 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase);
541 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr);
542 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr);
543 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr);
545 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr);
548 * SC26198 uart specific handling functions.
550 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value);
551 static int stl_sc26198getreg(stlport_t *portp, int regnr);
552 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value);
553 static int stl_sc26198getglobreg(stlport_t *portp, int regnr);
554 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
555 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
556 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp);
557 static int stl_sc26198getsignals(stlport_t *portp);
558 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts);
559 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx);
560 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx);
561 static void stl_sc26198disableintrs(stlport_t *portp);
562 static void stl_sc26198sendbreak(stlport_t *portp, int len);
563 static void stl_sc26198flowctrl(stlport_t *portp, int state);
564 static void stl_sc26198sendflow(stlport_t *portp, int state);
565 static void stl_sc26198flush(stlport_t *portp);
566 static int stl_sc26198datastate(stlport_t *portp);
567 static void stl_sc26198wait(stlport_t *portp);
568 static void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty);
569 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase);
570 static void stl_sc26198txisr(stlport_t *port);
571 static void stl_sc26198rxisr(stlport_t *port, unsigned int iack);
572 static void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch);
573 static void stl_sc26198rxbadchars(stlport_t *portp);
574 static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
576 /*****************************************************************************/
579 * Generic UART support structure.
581 typedef struct uart {
582 int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp);
583 void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
584 void (*setport)(stlport_t *portp, struct termios *tiosp);
585 int (*getsignals)(stlport_t *portp);
586 void (*setsignals)(stlport_t *portp, int dtr, int rts);
587 void (*enablerxtx)(stlport_t *portp, int rx, int tx);
588 void (*startrxtx)(stlport_t *portp, int rx, int tx);
589 void (*disableintrs)(stlport_t *portp);
590 void (*sendbreak)(stlport_t *portp, int len);
591 void (*flowctrl)(stlport_t *portp, int state);
592 void (*sendflow)(stlport_t *portp, int state);
593 void (*flush)(stlport_t *portp);
594 int (*datastate)(stlport_t *portp);
595 void (*intr)(stlpanel_t *panelp, unsigned int iobase);
599 * Define some macros to make calling these functions nice and clean.
601 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
602 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
603 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
604 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
605 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
606 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
607 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
608 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
609 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
610 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
611 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
612 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
613 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
615 /*****************************************************************************/
618 * CD1400 UART specific data initialization.
620 static uart_t stl_cd1400uart = {
624 stl_cd1400getsignals,
625 stl_cd1400setsignals,
626 stl_cd1400enablerxtx,
628 stl_cd1400disableintrs,
638 * Define the offsets within the register bank of a cd1400 based panel.
639 * These io address offsets are common to the EasyIO board as well.
647 #define EREG_BANKSIZE 8
649 #define CD1400_CLK 25000000
650 #define CD1400_CLK8M 20000000
653 * Define the cd1400 baud rate clocks. These are used when calculating
654 * what clock and divisor to use for the required baud rate. Also
655 * define the maximum baud rate allowed, and the default base baud.
657 static int stl_cd1400clkdivs[] = {
658 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
661 /*****************************************************************************/
664 * SC26198 UART specific data initization.
666 static uart_t stl_sc26198uart = {
667 stl_sc26198panelinit,
670 stl_sc26198getsignals,
671 stl_sc26198setsignals,
672 stl_sc26198enablerxtx,
673 stl_sc26198startrxtx,
674 stl_sc26198disableintrs,
675 stl_sc26198sendbreak,
679 stl_sc26198datastate,
684 * Define the offsets within the register bank of a sc26198 based panel.
692 #define XP_BANKSIZE 4
695 * Define the sc26198 baud rate table. Offsets within the table
696 * represent the actual baud rate selector of sc26198 registers.
698 static unsigned int sc26198_baudtable[] = {
699 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
700 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
701 230400, 460800, 921600
704 #define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
706 /*****************************************************************************/
709 * Define the driver info for a user level control device. Used mainly
710 * to get at port stats - only not using the port device itself.
712 static struct file_operations stl_fsiomem = {
713 .owner = THIS_MODULE,
714 .ioctl = stl_memioctl,
717 /*****************************************************************************/
719 static struct class *stallion_class;
722 * Loadable module initialization stuff.
725 static int __init stallion_module_init(void)
730 printk("init_module()\n");
736 restore_flags(flags);
741 /*****************************************************************************/
743 static void __exit stallion_module_exit(void)
752 printk("cleanup_module()\n");
755 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
762 * Free up all allocated resources used by the ports. This includes
763 * memory and interrupts. As part of this process we will also do
764 * a hangup on every open port - to try to flush out any processes
765 * hanging onto ports.
767 i = tty_unregister_driver(stl_serial);
768 put_tty_driver(stl_serial);
770 printk("STALLION: failed to un-register tty driver, "
772 restore_flags(flags);
775 for (i = 0; i < 4; i++)
776 class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
777 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
778 printk("STALLION: failed to un-register serial memory device, "
780 class_destroy(stallion_class);
782 kfree(stl_tmpwritebuf);
784 for (i = 0; (i < stl_nrbrds); i++) {
785 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
788 free_irq(brdp->irq, brdp);
790 for (j = 0; (j < STL_MAXPANELS); j++) {
791 panelp = brdp->panels[j];
792 if (panelp == (stlpanel_t *) NULL)
794 for (k = 0; (k < STL_PORTSPERPANEL); k++) {
795 portp = panelp->ports[k];
796 if (portp == (stlport_t *) NULL)
798 if (portp->tty != (struct tty_struct *) NULL)
799 stl_hangup(portp->tty);
800 kfree(portp->tx.buf);
806 release_region(brdp->ioaddr1, brdp->iosize1);
807 if (brdp->iosize2 > 0)
808 release_region(brdp->ioaddr2, brdp->iosize2);
811 stl_brds[i] = (stlbrd_t *) NULL;
814 restore_flags(flags);
817 module_init(stallion_module_init);
818 module_exit(stallion_module_exit);
820 /*****************************************************************************/
823 * Check for any arguments passed in on the module load command line.
826 static void stl_argbrds(void)
833 printk("stl_argbrds()\n");
836 for (i = stl_nrbrds; (i < stl_nargs); i++) {
837 memset(&conf, 0, sizeof(conf));
838 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
840 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
844 brdp->brdtype = conf.brdtype;
845 brdp->ioaddr1 = conf.ioaddr1;
846 brdp->ioaddr2 = conf.ioaddr2;
847 brdp->irq = conf.irq;
848 brdp->irqtype = conf.irqtype;
853 /*****************************************************************************/
856 * Convert an ascii string number into an unsigned long.
859 static unsigned long stl_atol(char *str)
867 if ((*sp == '0') && (*(sp+1) == 'x')) {
870 } else if (*sp == '0') {
877 for (; (*sp != 0); sp++) {
878 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
879 if ((c < 0) || (c >= base)) {
880 printk("STALLION: invalid argument %s\n", str);
884 val = (val * base) + c;
889 /*****************************************************************************/
892 * Parse the supplied argument string, into the board conf struct.
895 static int stl_parsebrd(stlconf_t *confp, char **argp)
901 printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
904 if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
907 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
910 for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++) {
911 if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
914 if (i == ARRAY_SIZE(stl_brdstr)) {
915 printk("STALLION: unknown board name, %s?\n", argp[0]);
919 confp->brdtype = stl_brdstr[i].type;
922 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
923 confp->ioaddr1 = stl_atol(argp[i]);
925 if (confp->brdtype == BRD_ECH) {
926 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
927 confp->ioaddr2 = stl_atol(argp[i]);
930 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
931 confp->irq = stl_atol(argp[i]);
935 /*****************************************************************************/
938 * Allocate a new board structure. Fill out the basic info in it.
941 static stlbrd_t *stl_allocbrd(void)
945 brdp = kzalloc(sizeof(stlbrd_t), GFP_KERNEL);
947 printk("STALLION: failed to allocate memory (size=%d)\n",
952 brdp->magic = STL_BOARDMAGIC;
956 /*****************************************************************************/
958 static int stl_open(struct tty_struct *tty, struct file *filp)
962 unsigned int minordev;
963 int brdnr, panelnr, portnr, rc;
966 printk("stl_open(tty=%x,filp=%x): device=%s\n", (int) tty,
967 (int) filp, tty->name);
970 minordev = tty->index;
971 brdnr = MINOR2BRD(minordev);
972 if (brdnr >= stl_nrbrds)
974 brdp = stl_brds[brdnr];
975 if (brdp == (stlbrd_t *) NULL)
977 minordev = MINOR2PORT(minordev);
978 for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
979 if (brdp->panels[panelnr] == (stlpanel_t *) NULL)
981 if (minordev < brdp->panels[panelnr]->nrports) {
985 minordev -= brdp->panels[panelnr]->nrports;
990 portp = brdp->panels[panelnr]->ports[portnr];
991 if (portp == (stlport_t *) NULL)
995 * On the first open of the device setup the port hardware, and
996 * initialize the per port data structure.
999 tty->driver_data = portp;
1002 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
1003 if (!portp->tx.buf) {
1004 portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
1007 portp->tx.head = portp->tx.buf;
1008 portp->tx.tail = portp->tx.buf;
1010 stl_setport(portp, tty->termios);
1011 portp->sigs = stl_getsignals(portp);
1012 stl_setsignals(portp, 1, 1);
1013 stl_enablerxtx(portp, 1, 1);
1014 stl_startrxtx(portp, 1, 0);
1015 clear_bit(TTY_IO_ERROR, &tty->flags);
1016 portp->flags |= ASYNC_INITIALIZED;
1020 * Check if this port is in the middle of closing. If so then wait
1021 * until it is closed then return error status, based on flag settings.
1022 * The sleep here does not need interrupt protection since the wakeup
1023 * for it is done with the same context.
1025 if (portp->flags & ASYNC_CLOSING) {
1026 interruptible_sleep_on(&portp->close_wait);
1027 if (portp->flags & ASYNC_HUP_NOTIFY)
1029 return -ERESTARTSYS;
1033 * Based on type of open being done check if it can overlap with any
1034 * previous opens still in effect. If we are a normal serial device
1035 * then also we might have to wait for carrier.
1037 if (!(filp->f_flags & O_NONBLOCK)) {
1038 if ((rc = stl_waitcarrier(portp, filp)) != 0)
1041 portp->flags |= ASYNC_NORMAL_ACTIVE;
1046 /*****************************************************************************/
1049 * Possibly need to wait for carrier (DCD signal) to come high. Say
1050 * maybe because if we are clocal then we don't need to wait...
1053 static int stl_waitcarrier(stlport_t *portp, struct file *filp)
1055 unsigned long flags;
1059 printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp, (int) filp);
1065 if (portp->tty->termios->c_cflag & CLOCAL)
1070 portp->openwaitcnt++;
1071 if (! tty_hung_up_p(filp))
1075 stl_setsignals(portp, 1, 1);
1076 if (tty_hung_up_p(filp) ||
1077 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1078 if (portp->flags & ASYNC_HUP_NOTIFY)
1084 if (((portp->flags & ASYNC_CLOSING) == 0) &&
1085 (doclocal || (portp->sigs & TIOCM_CD))) {
1088 if (signal_pending(current)) {
1092 interruptible_sleep_on(&portp->open_wait);
1095 if (! tty_hung_up_p(filp))
1097 portp->openwaitcnt--;
1098 restore_flags(flags);
1103 /*****************************************************************************/
1105 static void stl_close(struct tty_struct *tty, struct file *filp)
1108 unsigned long flags;
1111 printk("stl_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
1114 portp = tty->driver_data;
1115 if (portp == (stlport_t *) NULL)
1120 if (tty_hung_up_p(filp)) {
1121 restore_flags(flags);
1124 if ((tty->count == 1) && (portp->refcount != 1))
1125 portp->refcount = 1;
1126 if (portp->refcount-- > 1) {
1127 restore_flags(flags);
1131 portp->refcount = 0;
1132 portp->flags |= ASYNC_CLOSING;
1135 * May want to wait for any data to drain before closing. The BUSY
1136 * flag keeps track of whether we are still sending or not - it is
1137 * very accurate for the cd1400, not quite so for the sc26198.
1138 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1141 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1142 tty_wait_until_sent(tty, portp->closing_wait);
1143 stl_waituntilsent(tty, (HZ / 2));
1145 portp->flags &= ~ASYNC_INITIALIZED;
1146 stl_disableintrs(portp);
1147 if (tty->termios->c_cflag & HUPCL)
1148 stl_setsignals(portp, 0, 0);
1149 stl_enablerxtx(portp, 0, 0);
1150 stl_flushbuffer(tty);
1152 if (portp->tx.buf != (char *) NULL) {
1153 kfree(portp->tx.buf);
1154 portp->tx.buf = (char *) NULL;
1155 portp->tx.head = (char *) NULL;
1156 portp->tx.tail = (char *) NULL;
1158 set_bit(TTY_IO_ERROR, &tty->flags);
1159 tty_ldisc_flush(tty);
1162 portp->tty = (struct tty_struct *) NULL;
1164 if (portp->openwaitcnt) {
1165 if (portp->close_delay)
1166 msleep_interruptible(jiffies_to_msecs(portp->close_delay));
1167 wake_up_interruptible(&portp->open_wait);
1170 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1171 wake_up_interruptible(&portp->close_wait);
1172 restore_flags(flags);
1175 /*****************************************************************************/
1178 * Write routine. Take data and stuff it in to the TX ring queue.
1179 * If transmit interrupts are not running then start them.
1182 static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
1185 unsigned int len, stlen;
1186 unsigned char *chbuf;
1190 printk("stl_write(tty=%x,buf=%x,count=%d)\n",
1191 (int) tty, (int) buf, count);
1194 if ((tty == (struct tty_struct *) NULL) ||
1195 (stl_tmpwritebuf == (char *) NULL))
1197 portp = tty->driver_data;
1198 if (portp == (stlport_t *) NULL)
1200 if (portp->tx.buf == (char *) NULL)
1204 * If copying direct from user space we must cater for page faults,
1205 * causing us to "sleep" here for a while. To handle this copy in all
1206 * the data we need now, into a local buffer. Then when we got it all
1207 * copy it into the TX buffer.
1209 chbuf = (unsigned char *) buf;
1211 head = portp->tx.head;
1212 tail = portp->tx.tail;
1214 len = STL_TXBUFSIZE - (head - tail) - 1;
1215 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
1217 len = tail - head - 1;
1221 len = MIN(len, count);
1224 stlen = MIN(len, stlen);
1225 memcpy(head, chbuf, stlen);
1230 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
1231 head = portp->tx.buf;
1232 stlen = tail - head;
1235 portp->tx.head = head;
1237 clear_bit(ASYI_TXLOW, &portp->istate);
1238 stl_startrxtx(portp, -1, 1);
1243 /*****************************************************************************/
1245 static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1252 printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1255 if (tty == (struct tty_struct *) NULL)
1257 portp = tty->driver_data;
1258 if (portp == (stlport_t *) NULL)
1260 if (portp->tx.buf == (char *) NULL)
1263 head = portp->tx.head;
1264 tail = portp->tx.tail;
1266 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
1271 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
1272 head = portp->tx.buf;
1274 portp->tx.head = head;
1277 /*****************************************************************************/
1280 * If there are any characters in the buffer then make sure that TX
1281 * interrupts are on and get'em out. Normally used after the putchar
1282 * routine has been called.
1285 static void stl_flushchars(struct tty_struct *tty)
1290 printk("stl_flushchars(tty=%x)\n", (int) tty);
1293 if (tty == (struct tty_struct *) NULL)
1295 portp = tty->driver_data;
1296 if (portp == (stlport_t *) NULL)
1298 if (portp->tx.buf == (char *) NULL)
1302 if (tty->stopped || tty->hw_stopped ||
1303 (portp->tx.head == portp->tx.tail))
1306 stl_startrxtx(portp, -1, 1);
1309 /*****************************************************************************/
1311 static int stl_writeroom(struct tty_struct *tty)
1317 printk("stl_writeroom(tty=%x)\n", (int) tty);
1320 if (tty == (struct tty_struct *) NULL)
1322 portp = tty->driver_data;
1323 if (portp == (stlport_t *) NULL)
1325 if (portp->tx.buf == (char *) NULL)
1328 head = portp->tx.head;
1329 tail = portp->tx.tail;
1330 return ((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
1333 /*****************************************************************************/
1336 * Return number of chars in the TX buffer. Normally we would just
1337 * calculate the number of chars in the buffer and return that, but if
1338 * the buffer is empty and TX interrupts are still on then we return
1339 * that the buffer still has 1 char in it. This way whoever called us
1340 * will not think that ALL chars have drained - since the UART still
1341 * must have some chars in it (we are busy after all).
1344 static int stl_charsinbuffer(struct tty_struct *tty)
1351 printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
1354 if (tty == (struct tty_struct *) NULL)
1356 portp = tty->driver_data;
1357 if (portp == (stlport_t *) NULL)
1359 if (portp->tx.buf == (char *) NULL)
1362 head = portp->tx.head;
1363 tail = portp->tx.tail;
1364 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1365 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1370 /*****************************************************************************/
1373 * Generate the serial struct info.
1376 static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp)
1378 struct serial_struct sio;
1382 printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1385 memset(&sio, 0, sizeof(struct serial_struct));
1386 sio.line = portp->portnr;
1387 sio.port = portp->ioaddr;
1388 sio.flags = portp->flags;
1389 sio.baud_base = portp->baud_base;
1390 sio.close_delay = portp->close_delay;
1391 sio.closing_wait = portp->closing_wait;
1392 sio.custom_divisor = portp->custom_divisor;
1394 if (portp->uartp == &stl_cd1400uart) {
1395 sio.type = PORT_CIRRUS;
1396 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1398 sio.type = PORT_UNKNOWN;
1399 sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1402 brdp = stl_brds[portp->brdnr];
1403 if (brdp != (stlbrd_t *) NULL)
1404 sio.irq = brdp->irq;
1406 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
1409 /*****************************************************************************/
1412 * Set port according to the serial struct info.
1413 * At this point we do not do any auto-configure stuff, so we will
1414 * just quietly ignore any requests to change irq, etc.
1417 static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp)
1419 struct serial_struct sio;
1422 printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1425 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1427 if (!capable(CAP_SYS_ADMIN)) {
1428 if ((sio.baud_base != portp->baud_base) ||
1429 (sio.close_delay != portp->close_delay) ||
1430 ((sio.flags & ~ASYNC_USR_MASK) !=
1431 (portp->flags & ~ASYNC_USR_MASK)))
1435 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1436 (sio.flags & ASYNC_USR_MASK);
1437 portp->baud_base = sio.baud_base;
1438 portp->close_delay = sio.close_delay;
1439 portp->closing_wait = sio.closing_wait;
1440 portp->custom_divisor = sio.custom_divisor;
1441 stl_setport(portp, portp->tty->termios);
1445 /*****************************************************************************/
1447 static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1451 if (tty == (struct tty_struct *) NULL)
1453 portp = tty->driver_data;
1454 if (portp == (stlport_t *) NULL)
1456 if (tty->flags & (1 << TTY_IO_ERROR))
1459 return stl_getsignals(portp);
1462 static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1463 unsigned int set, unsigned int clear)
1466 int rts = -1, dtr = -1;
1468 if (tty == (struct tty_struct *) NULL)
1470 portp = tty->driver_data;
1471 if (portp == (stlport_t *) NULL)
1473 if (tty->flags & (1 << TTY_IO_ERROR))
1476 if (set & TIOCM_RTS)
1478 if (set & TIOCM_DTR)
1480 if (clear & TIOCM_RTS)
1482 if (clear & TIOCM_DTR)
1485 stl_setsignals(portp, dtr, rts);
1489 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1494 void __user *argp = (void __user *)arg;
1497 printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
1498 (int) tty, (int) file, cmd, (int) arg);
1501 if (tty == (struct tty_struct *) NULL)
1503 portp = tty->driver_data;
1504 if (portp == (stlport_t *) NULL)
1507 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1508 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1509 if (tty->flags & (1 << TTY_IO_ERROR))
1517 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1518 (unsigned __user *) argp);
1521 if (get_user(ival, (unsigned int __user *) arg))
1523 tty->termios->c_cflag =
1524 (tty->termios->c_cflag & ~CLOCAL) |
1525 (ival ? CLOCAL : 0);
1528 rc = stl_getserial(portp, argp);
1531 rc = stl_setserial(portp, argp);
1533 case COM_GETPORTSTATS:
1534 rc = stl_getportstats(portp, argp);
1536 case COM_CLRPORTSTATS:
1537 rc = stl_clrportstats(portp, argp);
1543 case TIOCSERGSTRUCT:
1544 case TIOCSERGETMULTI:
1545 case TIOCSERSETMULTI:
1554 /*****************************************************************************/
1556 static void stl_settermios(struct tty_struct *tty, struct termios *old)
1559 struct termios *tiosp;
1562 printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
1565 if (tty == (struct tty_struct *) NULL)
1567 portp = tty->driver_data;
1568 if (portp == (stlport_t *) NULL)
1571 tiosp = tty->termios;
1572 if ((tiosp->c_cflag == old->c_cflag) &&
1573 (tiosp->c_iflag == old->c_iflag))
1576 stl_setport(portp, tiosp);
1577 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1579 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1580 tty->hw_stopped = 0;
1583 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1584 wake_up_interruptible(&portp->open_wait);
1587 /*****************************************************************************/
1590 * Attempt to flow control who ever is sending us data. Based on termios
1591 * settings use software or/and hardware flow control.
1594 static void stl_throttle(struct tty_struct *tty)
1599 printk("stl_throttle(tty=%x)\n", (int) tty);
1602 if (tty == (struct tty_struct *) NULL)
1604 portp = tty->driver_data;
1605 if (portp == (stlport_t *) NULL)
1607 stl_flowctrl(portp, 0);
1610 /*****************************************************************************/
1613 * Unflow control the device sending us data...
1616 static void stl_unthrottle(struct tty_struct *tty)
1621 printk("stl_unthrottle(tty=%x)\n", (int) tty);
1624 if (tty == (struct tty_struct *) NULL)
1626 portp = tty->driver_data;
1627 if (portp == (stlport_t *) NULL)
1629 stl_flowctrl(portp, 1);
1632 /*****************************************************************************/
1635 * Stop the transmitter. Basically to do this we will just turn TX
1639 static void stl_stop(struct tty_struct *tty)
1644 printk("stl_stop(tty=%x)\n", (int) tty);
1647 if (tty == (struct tty_struct *) NULL)
1649 portp = tty->driver_data;
1650 if (portp == (stlport_t *) NULL)
1652 stl_startrxtx(portp, -1, 0);
1655 /*****************************************************************************/
1658 * Start the transmitter again. Just turn TX interrupts back on.
1661 static void stl_start(struct tty_struct *tty)
1666 printk("stl_start(tty=%x)\n", (int) tty);
1669 if (tty == (struct tty_struct *) NULL)
1671 portp = tty->driver_data;
1672 if (portp == (stlport_t *) NULL)
1674 stl_startrxtx(portp, -1, 1);
1677 /*****************************************************************************/
1680 * Hangup this port. This is pretty much like closing the port, only
1681 * a little more brutal. No waiting for data to drain. Shutdown the
1682 * port and maybe drop signals.
1685 static void stl_hangup(struct tty_struct *tty)
1690 printk("stl_hangup(tty=%x)\n", (int) tty);
1693 if (tty == (struct tty_struct *) NULL)
1695 portp = tty->driver_data;
1696 if (portp == (stlport_t *) NULL)
1699 portp->flags &= ~ASYNC_INITIALIZED;
1700 stl_disableintrs(portp);
1701 if (tty->termios->c_cflag & HUPCL)
1702 stl_setsignals(portp, 0, 0);
1703 stl_enablerxtx(portp, 0, 0);
1704 stl_flushbuffer(tty);
1706 set_bit(TTY_IO_ERROR, &tty->flags);
1707 if (portp->tx.buf != (char *) NULL) {
1708 kfree(portp->tx.buf);
1709 portp->tx.buf = (char *) NULL;
1710 portp->tx.head = (char *) NULL;
1711 portp->tx.tail = (char *) NULL;
1713 portp->tty = (struct tty_struct *) NULL;
1714 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1715 portp->refcount = 0;
1716 wake_up_interruptible(&portp->open_wait);
1719 /*****************************************************************************/
1721 static void stl_flushbuffer(struct tty_struct *tty)
1726 printk("stl_flushbuffer(tty=%x)\n", (int) tty);
1729 if (tty == (struct tty_struct *) NULL)
1731 portp = tty->driver_data;
1732 if (portp == (stlport_t *) NULL)
1739 /*****************************************************************************/
1741 static void stl_breakctl(struct tty_struct *tty, int state)
1746 printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty, state);
1749 if (tty == (struct tty_struct *) NULL)
1751 portp = tty->driver_data;
1752 if (portp == (stlport_t *) NULL)
1755 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1758 /*****************************************************************************/
1760 static void stl_waituntilsent(struct tty_struct *tty, int timeout)
1766 printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty, timeout);
1769 if (tty == (struct tty_struct *) NULL)
1771 portp = tty->driver_data;
1772 if (portp == (stlport_t *) NULL)
1777 tend = jiffies + timeout;
1779 while (stl_datastate(portp)) {
1780 if (signal_pending(current))
1782 msleep_interruptible(20);
1783 if (time_after_eq(jiffies, tend))
1788 /*****************************************************************************/
1790 static void stl_sendxchar(struct tty_struct *tty, char ch)
1795 printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
1798 if (tty == (struct tty_struct *) NULL)
1800 portp = tty->driver_data;
1801 if (portp == (stlport_t *) NULL)
1804 if (ch == STOP_CHAR(tty))
1805 stl_sendflow(portp, 0);
1806 else if (ch == START_CHAR(tty))
1807 stl_sendflow(portp, 1);
1809 stl_putchar(tty, ch);
1812 /*****************************************************************************/
1817 * Format info for a specified port. The line is deliberately limited
1818 * to 80 characters. (If it is too long it will be truncated, if too
1819 * short then padded with spaces).
1822 static int stl_portinfo(stlport_t *portp, int portnr, char *pos)
1828 sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
1829 portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
1830 (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
1832 if (portp->stats.rxframing)
1833 sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
1834 if (portp->stats.rxparity)
1835 sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
1836 if (portp->stats.rxbreaks)
1837 sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
1838 if (portp->stats.rxoverrun)
1839 sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
1841 sigs = stl_getsignals(portp);
1842 cnt = sprintf(sp, "%s%s%s%s%s ",
1843 (sigs & TIOCM_RTS) ? "|RTS" : "",
1844 (sigs & TIOCM_CTS) ? "|CTS" : "",
1845 (sigs & TIOCM_DTR) ? "|DTR" : "",
1846 (sigs & TIOCM_CD) ? "|DCD" : "",
1847 (sigs & TIOCM_DSR) ? "|DSR" : "");
1851 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
1854 pos[(MAXLINE - 2)] = '+';
1855 pos[(MAXLINE - 1)] = '\n';
1860 /*****************************************************************************/
1863 * Port info, read from the /proc file system.
1866 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
1871 int brdnr, panelnr, portnr, totalport;
1876 printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
1877 "data=%x\n", (int) page, (int) start, (int) off, count,
1878 (int) eof, (int) data);
1886 pos += sprintf(pos, "%s: version %s", stl_drvtitle,
1888 while (pos < (page + MAXLINE - 1))
1895 * We scan through for each board, panel and port. The offset is
1896 * calculated on the fly, and irrelevant ports are skipped.
1898 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1899 brdp = stl_brds[brdnr];
1900 if (brdp == (stlbrd_t *) NULL)
1902 if (brdp->state == 0)
1905 maxoff = curoff + (brdp->nrports * MAXLINE);
1906 if (off >= maxoff) {
1911 totalport = brdnr * STL_MAXPORTS;
1912 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1913 panelp = brdp->panels[panelnr];
1914 if (panelp == (stlpanel_t *) NULL)
1917 maxoff = curoff + (panelp->nrports * MAXLINE);
1918 if (off >= maxoff) {
1920 totalport += panelp->nrports;
1924 for (portnr = 0; (portnr < panelp->nrports); portnr++,
1926 portp = panelp->ports[portnr];
1927 if (portp == (stlport_t *) NULL)
1929 if (off >= (curoff += MAXLINE))
1931 if ((pos - page + MAXLINE) > count)
1933 pos += stl_portinfo(portp, totalport, pos);
1942 return (pos - page);
1945 /*****************************************************************************/
1948 * All board interrupts are vectored through here first. This code then
1949 * calls off to the approrpriate board interrupt handlers.
1952 static irqreturn_t stl_intr(int irq, void *dev_id, struct pt_regs *regs)
1954 stlbrd_t *brdp = (stlbrd_t *) dev_id;
1957 printk("stl_intr(brdp=%x,irq=%d,regs=%x)\n", (int) brdp, irq,
1961 return IRQ_RETVAL((* brdp->isr)(brdp));
1964 /*****************************************************************************/
1967 * Interrupt service routine for EasyIO board types.
1970 static int stl_eiointr(stlbrd_t *brdp)
1973 unsigned int iobase;
1976 panelp = brdp->panels[0];
1977 iobase = panelp->iobase;
1978 while (inb(brdp->iostatus) & EIO_INTRPEND) {
1980 (* panelp->isr)(panelp, iobase);
1985 /*****************************************************************************/
1988 * Interrupt service routine for ECH-AT board types.
1991 static int stl_echatintr(stlbrd_t *brdp)
1994 unsigned int ioaddr;
1998 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2000 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2002 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2003 ioaddr = brdp->bnkstataddr[bnknr];
2004 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2005 panelp = brdp->bnk2panel[bnknr];
2006 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2011 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2016 /*****************************************************************************/
2019 * Interrupt service routine for ECH-MCA board types.
2022 static int stl_echmcaintr(stlbrd_t *brdp)
2025 unsigned int ioaddr;
2029 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2031 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2032 ioaddr = brdp->bnkstataddr[bnknr];
2033 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2034 panelp = brdp->bnk2panel[bnknr];
2035 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2042 /*****************************************************************************/
2045 * Interrupt service routine for ECH-PCI board types.
2048 static int stl_echpciintr(stlbrd_t *brdp)
2051 unsigned int ioaddr;
2057 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2058 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
2059 ioaddr = brdp->bnkstataddr[bnknr];
2060 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2061 panelp = brdp->bnk2panel[bnknr];
2062 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2073 /*****************************************************************************/
2076 * Interrupt service routine for ECH-8/64-PCI board types.
2079 static int stl_echpci64intr(stlbrd_t *brdp)
2082 unsigned int ioaddr;
2086 while (inb(brdp->ioctrl) & 0x1) {
2088 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2089 ioaddr = brdp->bnkstataddr[bnknr];
2090 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2091 panelp = brdp->bnk2panel[bnknr];
2092 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2100 /*****************************************************************************/
2103 * Service an off-level request for some channel.
2105 static void stl_offintr(void *private)
2108 struct tty_struct *tty;
2109 unsigned int oldsigs;
2114 printk("stl_offintr(portp=%x)\n", (int) portp);
2117 if (portp == (stlport_t *) NULL)
2121 if (tty == (struct tty_struct *) NULL)
2125 if (test_bit(ASYI_TXLOW, &portp->istate)) {
2128 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
2129 clear_bit(ASYI_DCDCHANGE, &portp->istate);
2130 oldsigs = portp->sigs;
2131 portp->sigs = stl_getsignals(portp);
2132 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
2133 wake_up_interruptible(&portp->open_wait);
2134 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
2135 if (portp->flags & ASYNC_CHECK_CD)
2136 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2142 /*****************************************************************************/
2145 * Initialize all the ports on a panel.
2148 static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2154 printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
2157 chipmask = stl_panelinit(brdp, panelp);
2160 * All UART's are initialized (if found!). Now go through and setup
2161 * each ports data structures.
2163 for (i = 0; (i < panelp->nrports); i++) {
2164 portp = kzalloc(sizeof(stlport_t), GFP_KERNEL);
2166 printk("STALLION: failed to allocate memory "
2167 "(size=%d)\n", sizeof(stlport_t));
2171 portp->magic = STL_PORTMAGIC;
2173 portp->brdnr = panelp->brdnr;
2174 portp->panelnr = panelp->panelnr;
2175 portp->uartp = panelp->uartp;
2176 portp->clk = brdp->clk;
2177 portp->baud_base = STL_BAUDBASE;
2178 portp->close_delay = STL_CLOSEDELAY;
2179 portp->closing_wait = 30 * HZ;
2180 INIT_WORK(&portp->tqueue, stl_offintr, portp);
2181 init_waitqueue_head(&portp->open_wait);
2182 init_waitqueue_head(&portp->close_wait);
2183 portp->stats.brd = portp->brdnr;
2184 portp->stats.panel = portp->panelnr;
2185 portp->stats.port = portp->portnr;
2186 panelp->ports[i] = portp;
2187 stl_portinit(brdp, panelp, portp);
2193 /*****************************************************************************/
2196 * Try to find and initialize an EasyIO board.
2199 static inline int stl_initeio(stlbrd_t *brdp)
2202 unsigned int status;
2207 printk("stl_initeio(brdp=%x)\n", (int) brdp);
2210 brdp->ioctrl = brdp->ioaddr1 + 1;
2211 brdp->iostatus = brdp->ioaddr1 + 2;
2213 status = inb(brdp->iostatus);
2214 if ((status & EIO_IDBITMASK) == EIO_MK3)
2218 * Handle board specific stuff now. The real difference is PCI
2221 if (brdp->brdtype == BRD_EASYIOPCI) {
2222 brdp->iosize1 = 0x80;
2223 brdp->iosize2 = 0x80;
2224 name = "serial(EIO-PCI)";
2225 outb(0x41, (brdp->ioaddr2 + 0x4c));
2228 name = "serial(EIO)";
2229 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2230 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2231 printk("STALLION: invalid irq=%d for brd=%d\n",
2232 brdp->irq, brdp->brdnr);
2235 outb((stl_vecmap[brdp->irq] | EIO_0WS |
2236 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
2240 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2241 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2242 "%x conflicts with another device\n", brdp->brdnr,
2247 if (brdp->iosize2 > 0)
2248 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2249 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2250 "address %x conflicts with another device\n",
2251 brdp->brdnr, brdp->ioaddr2);
2252 printk(KERN_WARNING "STALLION: Warning, also "
2253 "releasing board %d I/O address %x \n",
2254 brdp->brdnr, brdp->ioaddr1);
2255 release_region(brdp->ioaddr1, brdp->iosize1);
2260 * Everything looks OK, so let's go ahead and probe for the hardware.
2262 brdp->clk = CD1400_CLK;
2263 brdp->isr = stl_eiointr;
2265 switch (status & EIO_IDBITMASK) {
2267 brdp->clk = CD1400_CLK8M;
2277 switch (status & EIO_BRDMASK) {
2296 * We have verified that the board is actually present, so now we
2297 * can complete the setup.
2300 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
2302 printk(KERN_WARNING "STALLION: failed to allocate memory "
2303 "(size=%d)\n", sizeof(stlpanel_t));
2307 panelp->magic = STL_PANELMAGIC;
2308 panelp->brdnr = brdp->brdnr;
2309 panelp->panelnr = 0;
2310 panelp->nrports = brdp->nrports;
2311 panelp->iobase = brdp->ioaddr1;
2312 panelp->hwid = status;
2313 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2314 panelp->uartp = (void *) &stl_sc26198uart;
2315 panelp->isr = stl_sc26198intr;
2317 panelp->uartp = (void *) &stl_cd1400uart;
2318 panelp->isr = stl_cd1400eiointr;
2321 brdp->panels[0] = panelp;
2323 brdp->state |= BRD_FOUND;
2324 brdp->hwid = status;
2325 if (request_irq(brdp->irq, stl_intr, SA_SHIRQ, name, brdp) != 0) {
2326 printk("STALLION: failed to register interrupt "
2327 "routine for %s irq=%d\n", name, brdp->irq);
2335 /*****************************************************************************/
2338 * Try to find an ECH board and initialize it. This code is capable of
2339 * dealing with all types of ECH board.
2342 static inline int stl_initech(stlbrd_t *brdp)
2345 unsigned int status, nxtid, ioaddr, conflict;
2346 int panelnr, banknr, i;
2350 printk("stl_initech(brdp=%x)\n", (int) brdp);
2357 * Set up the initial board register contents for boards. This varies a
2358 * bit between the different board types. So we need to handle each
2359 * separately. Also do a check that the supplied IRQ is good.
2361 switch (brdp->brdtype) {
2364 brdp->isr = stl_echatintr;
2365 brdp->ioctrl = brdp->ioaddr1 + 1;
2366 brdp->iostatus = brdp->ioaddr1 + 1;
2367 status = inb(brdp->iostatus);
2368 if ((status & ECH_IDBITMASK) != ECH_ID)
2370 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2371 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2372 printk("STALLION: invalid irq=%d for brd=%d\n",
2373 brdp->irq, brdp->brdnr);
2376 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2377 status |= (stl_vecmap[brdp->irq] << 1);
2378 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2379 brdp->ioctrlval = ECH_INTENABLE |
2380 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2381 for (i = 0; (i < 10); i++)
2382 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2385 name = "serial(EC8/32)";
2386 outb(status, brdp->ioaddr1);
2390 brdp->isr = stl_echmcaintr;
2391 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2392 brdp->iostatus = brdp->ioctrl;
2393 status = inb(brdp->iostatus);
2394 if ((status & ECH_IDBITMASK) != ECH_ID)
2396 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2397 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2398 printk("STALLION: invalid irq=%d for brd=%d\n",
2399 brdp->irq, brdp->brdnr);
2402 outb(ECHMC_BRDRESET, brdp->ioctrl);
2403 outb(ECHMC_INTENABLE, brdp->ioctrl);
2405 name = "serial(EC8/32-MC)";
2409 brdp->isr = stl_echpciintr;
2410 brdp->ioctrl = brdp->ioaddr1 + 2;
2413 name = "serial(EC8/32-PCI)";
2417 brdp->isr = stl_echpci64intr;
2418 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2419 outb(0x43, (brdp->ioaddr1 + 0x4c));
2420 brdp->iosize1 = 0x80;
2421 brdp->iosize2 = 0x80;
2422 name = "serial(EC8/64-PCI)";
2426 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
2432 * Check boards for possible IO address conflicts and return fail status
2433 * if an IO conflict found.
2435 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2436 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2437 "%x conflicts with another device\n", brdp->brdnr,
2442 if (brdp->iosize2 > 0)
2443 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2444 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2445 "address %x conflicts with another device\n",
2446 brdp->brdnr, brdp->ioaddr2);
2447 printk(KERN_WARNING "STALLION: Warning, also "
2448 "releasing board %d I/O address %x \n",
2449 brdp->brdnr, brdp->ioaddr1);
2450 release_region(brdp->ioaddr1, brdp->iosize1);
2455 * Scan through the secondary io address space looking for panels.
2456 * As we find'em allocate and initialize panel structures for each.
2458 brdp->clk = CD1400_CLK;
2459 brdp->hwid = status;
2461 ioaddr = brdp->ioaddr2;
2466 for (i = 0; (i < STL_MAXPANELS); i++) {
2467 if (brdp->brdtype == BRD_ECHPCI) {
2468 outb(nxtid, brdp->ioctrl);
2469 ioaddr = brdp->ioaddr2;
2471 status = inb(ioaddr + ECH_PNLSTATUS);
2472 if ((status & ECH_PNLIDMASK) != nxtid)
2474 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
2476 printk("STALLION: failed to allocate memory "
2477 "(size=%d)\n", sizeof(stlpanel_t));
2480 panelp->magic = STL_PANELMAGIC;
2481 panelp->brdnr = brdp->brdnr;
2482 panelp->panelnr = panelnr;
2483 panelp->iobase = ioaddr;
2484 panelp->pagenr = nxtid;
2485 panelp->hwid = status;
2486 brdp->bnk2panel[banknr] = panelp;
2487 brdp->bnkpageaddr[banknr] = nxtid;
2488 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2490 if (status & ECH_PNLXPID) {
2491 panelp->uartp = (void *) &stl_sc26198uart;
2492 panelp->isr = stl_sc26198intr;
2493 if (status & ECH_PNL16PORT) {
2494 panelp->nrports = 16;
2495 brdp->bnk2panel[banknr] = panelp;
2496 brdp->bnkpageaddr[banknr] = nxtid;
2497 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2500 panelp->nrports = 8;
2503 panelp->uartp = (void *) &stl_cd1400uart;
2504 panelp->isr = stl_cd1400echintr;
2505 if (status & ECH_PNL16PORT) {
2506 panelp->nrports = 16;
2507 panelp->ackmask = 0x80;
2508 if (brdp->brdtype != BRD_ECHPCI)
2509 ioaddr += EREG_BANKSIZE;
2510 brdp->bnk2panel[banknr] = panelp;
2511 brdp->bnkpageaddr[banknr] = ++nxtid;
2512 brdp->bnkstataddr[banknr++] = ioaddr +
2515 panelp->nrports = 8;
2516 panelp->ackmask = 0xc0;
2521 ioaddr += EREG_BANKSIZE;
2522 brdp->nrports += panelp->nrports;
2523 brdp->panels[panelnr++] = panelp;
2524 if ((brdp->brdtype != BRD_ECHPCI) &&
2525 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
2529 brdp->nrpanels = panelnr;
2530 brdp->nrbnks = banknr;
2531 if (brdp->brdtype == BRD_ECH)
2532 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2534 brdp->state |= BRD_FOUND;
2535 if (request_irq(brdp->irq, stl_intr, SA_SHIRQ, name, brdp) != 0) {
2536 printk("STALLION: failed to register interrupt "
2537 "routine for %s irq=%d\n", name, brdp->irq);
2546 /*****************************************************************************/
2549 * Initialize and configure the specified board.
2550 * Scan through all the boards in the configuration and see what we
2551 * can find. Handle EIO and the ECH boards a little differently here
2552 * since the initial search and setup is very different.
2555 static int __init stl_brdinit(stlbrd_t *brdp)
2560 printk("stl_brdinit(brdp=%x)\n", (int) brdp);
2563 switch (brdp->brdtype) {
2575 printk("STALLION: board=%d is unknown board type=%d\n",
2576 brdp->brdnr, brdp->brdtype);
2580 stl_brds[brdp->brdnr] = brdp;
2581 if ((brdp->state & BRD_FOUND) == 0) {
2582 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2583 stl_brdnames[brdp->brdtype], brdp->brdnr,
2584 brdp->ioaddr1, brdp->irq);
2588 for (i = 0; (i < STL_MAXPANELS); i++)
2589 if (brdp->panels[i] != (stlpanel_t *) NULL)
2590 stl_initports(brdp, brdp->panels[i]);
2592 printk("STALLION: %s found, board=%d io=%x irq=%d "
2593 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2594 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2599 /*****************************************************************************/
2602 * Find the next available board number that is free.
2605 static inline int stl_getbrdnr(void)
2609 for (i = 0; (i < STL_MAXBRDS); i++) {
2610 if (stl_brds[i] == (stlbrd_t *) NULL) {
2611 if (i >= stl_nrbrds)
2619 /*****************************************************************************/
2624 * We have a Stallion board. Allocate a board structure and
2625 * initialize it. Read its IO and IRQ resources from PCI
2626 * configuration space.
2629 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
2634 printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
2635 devp->bus->number, devp->devfn);
2638 if (pci_enable_device(devp))
2640 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2642 if ((brdp->brdnr = stl_getbrdnr()) < 0) {
2643 printk("STALLION: too many boards found, "
2644 "maximum supported %d\n", STL_MAXBRDS);
2647 brdp->brdtype = brdtype;
2650 * Different Stallion boards use the BAR registers in different ways,
2651 * so set up io addresses based on board type.
2654 printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__, __LINE__,
2655 pci_resource_start(devp, 0), pci_resource_start(devp, 1),
2656 pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
2660 * We have all resources from the board, so let's setup the actual
2661 * board structure now.
2665 brdp->ioaddr2 = pci_resource_start(devp, 0);
2666 brdp->ioaddr1 = pci_resource_start(devp, 1);
2669 brdp->ioaddr2 = pci_resource_start(devp, 2);
2670 brdp->ioaddr1 = pci_resource_start(devp, 1);
2673 brdp->ioaddr1 = pci_resource_start(devp, 2);
2674 brdp->ioaddr2 = pci_resource_start(devp, 1);
2677 printk("STALLION: unknown PCI board type=%d\n", brdtype);
2681 brdp->irq = devp->irq;
2687 /*****************************************************************************/
2690 * Find all Stallion PCI boards that might be installed. Initialize each
2691 * one as it is found.
2695 static inline int stl_findpcibrds(void)
2697 struct pci_dev *dev = NULL;
2701 printk("stl_findpcibrds()\n");
2704 for (i = 0; (i < stl_nrpcibrds); i++)
2705 while ((dev = pci_find_device(stl_pcibrds[i].vendid,
2706 stl_pcibrds[i].devid, dev))) {
2709 * Found a device on the PCI bus that has our vendor and
2710 * device ID. Need to check now that it is really us.
2712 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2715 rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
2725 /*****************************************************************************/
2728 * Scan through all the boards in the configuration and see what we
2729 * can find. Handle EIO and the ECH boards a little differently here
2730 * since the initial search and setup is too different.
2733 static inline int stl_initbrds(void)
2740 printk("stl_initbrds()\n");
2743 if (stl_nrbrds > STL_MAXBRDS) {
2744 printk("STALLION: too many boards in configuration table, "
2745 "truncating to %d\n", STL_MAXBRDS);
2746 stl_nrbrds = STL_MAXBRDS;
2750 * Firstly scan the list of static boards configured. Allocate
2751 * resources and initialize the boards as found.
2753 for (i = 0; (i < stl_nrbrds); i++) {
2754 confp = &stl_brdconf[i];
2755 stl_parsebrd(confp, stl_brdsp[i]);
2756 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2759 brdp->brdtype = confp->brdtype;
2760 brdp->ioaddr1 = confp->ioaddr1;
2761 brdp->ioaddr2 = confp->ioaddr2;
2762 brdp->irq = confp->irq;
2763 brdp->irqtype = confp->irqtype;
2768 * Find any dynamically supported boards. That is via module load
2769 * line options or auto-detected on the PCI bus.
2779 /*****************************************************************************/
2782 * Return the board stats structure to user app.
2785 static int stl_getbrdstats(combrd_t __user *bp)
2791 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2793 if (stl_brdstats.brd >= STL_MAXBRDS)
2795 brdp = stl_brds[stl_brdstats.brd];
2796 if (brdp == (stlbrd_t *) NULL)
2799 memset(&stl_brdstats, 0, sizeof(combrd_t));
2800 stl_brdstats.brd = brdp->brdnr;
2801 stl_brdstats.type = brdp->brdtype;
2802 stl_brdstats.hwid = brdp->hwid;
2803 stl_brdstats.state = brdp->state;
2804 stl_brdstats.ioaddr = brdp->ioaddr1;
2805 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2806 stl_brdstats.irq = brdp->irq;
2807 stl_brdstats.nrpanels = brdp->nrpanels;
2808 stl_brdstats.nrports = brdp->nrports;
2809 for (i = 0; (i < brdp->nrpanels); i++) {
2810 panelp = brdp->panels[i];
2811 stl_brdstats.panels[i].panel = i;
2812 stl_brdstats.panels[i].hwid = panelp->hwid;
2813 stl_brdstats.panels[i].nrports = panelp->nrports;
2816 return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
2819 /*****************************************************************************/
2822 * Resolve the referenced port number into a port struct pointer.
2825 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2830 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2831 return((stlport_t *) NULL);
2832 brdp = stl_brds[brdnr];
2833 if (brdp == (stlbrd_t *) NULL)
2834 return((stlport_t *) NULL);
2835 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2836 return((stlport_t *) NULL);
2837 panelp = brdp->panels[panelnr];
2838 if (panelp == (stlpanel_t *) NULL)
2839 return((stlport_t *) NULL);
2840 if ((portnr < 0) || (portnr >= panelp->nrports))
2841 return((stlport_t *) NULL);
2842 return(panelp->ports[portnr]);
2845 /*****************************************************************************/
2848 * Return the port stats structure to user app. A NULL port struct
2849 * pointer passed in means that we need to find out from the app
2850 * what port to get stats for (used through board control device).
2853 static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
2855 unsigned char *head, *tail;
2856 unsigned long flags;
2859 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2861 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2863 if (portp == (stlport_t *) NULL)
2867 portp->stats.state = portp->istate;
2868 portp->stats.flags = portp->flags;
2869 portp->stats.hwid = portp->hwid;
2871 portp->stats.ttystate = 0;
2872 portp->stats.cflags = 0;
2873 portp->stats.iflags = 0;
2874 portp->stats.oflags = 0;
2875 portp->stats.lflags = 0;
2876 portp->stats.rxbuffered = 0;
2880 if (portp->tty != (struct tty_struct *) NULL) {
2881 if (portp->tty->driver_data == portp) {
2882 portp->stats.ttystate = portp->tty->flags;
2883 /* No longer available as a statistic */
2884 portp->stats.rxbuffered = 1; /*portp->tty->flip.count; */
2885 if (portp->tty->termios != (struct termios *) NULL) {
2886 portp->stats.cflags = portp->tty->termios->c_cflag;
2887 portp->stats.iflags = portp->tty->termios->c_iflag;
2888 portp->stats.oflags = portp->tty->termios->c_oflag;
2889 portp->stats.lflags = portp->tty->termios->c_lflag;
2893 restore_flags(flags);
2895 head = portp->tx.head;
2896 tail = portp->tx.tail;
2897 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2898 (STL_TXBUFSIZE - (tail - head)));
2900 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2902 return copy_to_user(cp, &portp->stats,
2903 sizeof(comstats_t)) ? -EFAULT : 0;
2906 /*****************************************************************************/
2909 * Clear the port stats structure. We also return it zeroed out...
2912 static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp)
2915 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2917 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2919 if (portp == (stlport_t *) NULL)
2923 memset(&portp->stats, 0, sizeof(comstats_t));
2924 portp->stats.brd = portp->brdnr;
2925 portp->stats.panel = portp->panelnr;
2926 portp->stats.port = portp->portnr;
2927 return copy_to_user(cp, &portp->stats,
2928 sizeof(comstats_t)) ? -EFAULT : 0;
2931 /*****************************************************************************/
2934 * Return the entire driver ports structure to a user app.
2937 static int stl_getportstruct(stlport_t __user *arg)
2941 if (copy_from_user(&stl_dummyport, arg, sizeof(stlport_t)))
2943 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
2944 stl_dummyport.portnr);
2947 return copy_to_user(arg, portp, sizeof(stlport_t)) ? -EFAULT : 0;
2950 /*****************************************************************************/
2953 * Return the entire driver board structure to a user app.
2956 static int stl_getbrdstruct(stlbrd_t __user *arg)
2960 if (copy_from_user(&stl_dummybrd, arg, sizeof(stlbrd_t)))
2962 if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
2964 brdp = stl_brds[stl_dummybrd.brdnr];
2967 return copy_to_user(arg, brdp, sizeof(stlbrd_t)) ? -EFAULT : 0;
2970 /*****************************************************************************/
2973 * The "staliomem" device is also required to do some special operations
2974 * on the board and/or ports. In this driver it is mostly used for stats
2978 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
2981 void __user *argp = (void __user *)arg;
2984 printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
2985 (int) fp, cmd, (int) arg);
2989 if (brdnr >= STL_MAXBRDS)
2994 case COM_GETPORTSTATS:
2995 rc = stl_getportstats(NULL, argp);
2997 case COM_CLRPORTSTATS:
2998 rc = stl_clrportstats(NULL, argp);
3000 case COM_GETBRDSTATS:
3001 rc = stl_getbrdstats(argp);
3004 rc = stl_getportstruct(argp);
3007 rc = stl_getbrdstruct(argp);
3017 static struct tty_operations stl_ops = {
3021 .put_char = stl_putchar,
3022 .flush_chars = stl_flushchars,
3023 .write_room = stl_writeroom,
3024 .chars_in_buffer = stl_charsinbuffer,
3026 .set_termios = stl_settermios,
3027 .throttle = stl_throttle,
3028 .unthrottle = stl_unthrottle,
3031 .hangup = stl_hangup,
3032 .flush_buffer = stl_flushbuffer,
3033 .break_ctl = stl_breakctl,
3034 .wait_until_sent = stl_waituntilsent,
3035 .send_xchar = stl_sendxchar,
3036 .read_proc = stl_readproc,
3037 .tiocmget = stl_tiocmget,
3038 .tiocmset = stl_tiocmset,
3041 /*****************************************************************************/
3043 static int __init stl_init(void)
3046 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
3050 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
3055 * Allocate a temporary write buffer.
3057 stl_tmpwritebuf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
3058 if (!stl_tmpwritebuf)
3059 printk("STALLION: failed to allocate memory (size=%d)\n",
3063 * Set up a character driver for per board stuff. This is mainly used
3064 * to do stats ioctls on the ports.
3066 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
3067 printk("STALLION: failed to register serial board device\n");
3069 stallion_class = class_create(THIS_MODULE, "staliomem");
3070 for (i = 0; i < 4; i++)
3071 class_device_create(stallion_class, NULL,
3072 MKDEV(STL_SIOMEMMAJOR, i), NULL,
3075 stl_serial->owner = THIS_MODULE;
3076 stl_serial->driver_name = stl_drvname;
3077 stl_serial->name = "ttyE";
3078 stl_serial->major = STL_SERIALMAJOR;
3079 stl_serial->minor_start = 0;
3080 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
3081 stl_serial->subtype = SERIAL_TYPE_NORMAL;
3082 stl_serial->init_termios = stl_deftermios;
3083 stl_serial->flags = TTY_DRIVER_REAL_RAW;
3084 tty_set_operations(stl_serial, &stl_ops);
3086 if (tty_register_driver(stl_serial)) {
3087 put_tty_driver(stl_serial);
3088 printk("STALLION: failed to register serial driver\n");
3095 /*****************************************************************************/
3096 /* CD1400 HARDWARE FUNCTIONS */
3097 /*****************************************************************************/
3100 * These functions get/set/update the registers of the cd1400 UARTs.
3101 * Access to the cd1400 registers is via an address/data io port pair.
3102 * (Maybe should make this inline...)
3105 static int stl_cd1400getreg(stlport_t *portp, int regnr)
3107 outb((regnr + portp->uartaddr), portp->ioaddr);
3108 return inb(portp->ioaddr + EREG_DATA);
3111 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
3113 outb((regnr + portp->uartaddr), portp->ioaddr);
3114 outb(value, portp->ioaddr + EREG_DATA);
3117 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
3119 outb((regnr + portp->uartaddr), portp->ioaddr);
3120 if (inb(portp->ioaddr + EREG_DATA) != value) {
3121 outb(value, portp->ioaddr + EREG_DATA);
3127 /*****************************************************************************/
3130 * Inbitialize the UARTs in a panel. We don't care what sort of board
3131 * these ports are on - since the port io registers are almost
3132 * identical when dealing with ports.
3135 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3139 int nrchips, uartaddr, ioaddr;
3142 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
3145 BRDENABLE(panelp->brdnr, panelp->pagenr);
3148 * Check that each chip is present and started up OK.
3151 nrchips = panelp->nrports / CD1400_PORTS;
3152 for (i = 0; (i < nrchips); i++) {
3153 if (brdp->brdtype == BRD_ECHPCI) {
3154 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3155 ioaddr = panelp->iobase;
3157 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3159 uartaddr = (i & 0x01) ? 0x080 : 0;
3160 outb((GFRCR + uartaddr), ioaddr);
3161 outb(0, (ioaddr + EREG_DATA));
3162 outb((CCR + uartaddr), ioaddr);
3163 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3164 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3165 outb((GFRCR + uartaddr), ioaddr);
3166 for (j = 0; (j < CCR_MAXWAIT); j++) {
3167 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3170 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3171 printk("STALLION: cd1400 not responding, "
3172 "brd=%d panel=%d chip=%d\n",
3173 panelp->brdnr, panelp->panelnr, i);
3176 chipmask |= (0x1 << i);
3177 outb((PPR + uartaddr), ioaddr);
3178 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
3181 BRDDISABLE(panelp->brdnr);
3185 /*****************************************************************************/
3188 * Initialize hardware specific port registers.
3191 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3194 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3195 (int) brdp, (int) panelp, (int) portp);
3198 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
3199 (portp == (stlport_t *) NULL))
3202 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3203 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3204 portp->uartaddr = (portp->portnr & 0x04) << 5;
3205 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3207 BRDENABLE(portp->brdnr, portp->pagenr);
3208 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3209 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3210 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3211 BRDDISABLE(portp->brdnr);
3214 /*****************************************************************************/
3217 * Wait for the command register to be ready. We will poll this,
3218 * since it won't usually take too long to be ready.
3221 static void stl_cd1400ccrwait(stlport_t *portp)
3225 for (i = 0; (i < CCR_MAXWAIT); i++) {
3226 if (stl_cd1400getreg(portp, CCR) == 0) {
3231 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
3232 portp->portnr, portp->panelnr, portp->brdnr);
3235 /*****************************************************************************/
3238 * Set up the cd1400 registers for a port based on the termios port
3242 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3245 unsigned long flags;
3246 unsigned int clkdiv, baudrate;
3247 unsigned char cor1, cor2, cor3;
3248 unsigned char cor4, cor5, ccr;
3249 unsigned char srer, sreron, sreroff;
3250 unsigned char mcor1, mcor2, rtpr;
3251 unsigned char clk, div;
3267 brdp = stl_brds[portp->brdnr];
3268 if (brdp == (stlbrd_t *) NULL)
3272 * Set up the RX char ignore mask with those RX error types we
3273 * can ignore. We can get the cd1400 to help us out a little here,
3274 * it will ignore parity errors and breaks for us.
3276 portp->rxignoremsk = 0;
3277 if (tiosp->c_iflag & IGNPAR) {
3278 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
3279 cor1 |= COR1_PARIGNORE;
3281 if (tiosp->c_iflag & IGNBRK) {
3282 portp->rxignoremsk |= ST_BREAK;
3283 cor4 |= COR4_IGNBRK;
3286 portp->rxmarkmsk = ST_OVERRUN;
3287 if (tiosp->c_iflag & (INPCK | PARMRK))
3288 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3289 if (tiosp->c_iflag & BRKINT)
3290 portp->rxmarkmsk |= ST_BREAK;
3293 * Go through the char size, parity and stop bits and set all the
3294 * option register appropriately.
3296 switch (tiosp->c_cflag & CSIZE) {
3311 if (tiosp->c_cflag & CSTOPB)
3316 if (tiosp->c_cflag & PARENB) {
3317 if (tiosp->c_cflag & PARODD)
3318 cor1 |= (COR1_PARENB | COR1_PARODD);
3320 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3322 cor1 |= COR1_PARNONE;
3326 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3327 * space for hardware flow control and the like. This should be set to
3328 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3329 * really be based on VTIME.
3331 cor3 |= FIFO_RXTHRESHOLD;
3335 * Calculate the baud rate timers. For now we will just assume that
3336 * the input and output baud are the same. Could have used a baud
3337 * table here, but this way we can generate virtually any baud rate
3340 baudrate = tiosp->c_cflag & CBAUD;
3341 if (baudrate & CBAUDEX) {
3342 baudrate &= ~CBAUDEX;
3343 if ((baudrate < 1) || (baudrate > 4))
3344 tiosp->c_cflag &= ~CBAUDEX;
3348 baudrate = stl_baudrates[baudrate];
3349 if ((tiosp->c_cflag & CBAUD) == B38400) {
3350 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3352 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3354 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3356 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3358 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3359 baudrate = (portp->baud_base / portp->custom_divisor);
3361 if (baudrate > STL_CD1400MAXBAUD)
3362 baudrate = STL_CD1400MAXBAUD;
3365 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3366 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
3370 div = (unsigned char) clkdiv;
3374 * Check what form of modem signaling is required and set it up.
3376 if ((tiosp->c_cflag & CLOCAL) == 0) {
3379 sreron |= SRER_MODEM;
3380 portp->flags |= ASYNC_CHECK_CD;
3382 portp->flags &= ~ASYNC_CHECK_CD;
3386 * Setup cd1400 enhanced modes if we can. In particular we want to
3387 * handle as much of the flow control as possible automatically. As
3388 * well as saving a few CPU cycles it will also greatly improve flow
3389 * control reliability.
3391 if (tiosp->c_iflag & IXON) {
3394 if (tiosp->c_iflag & IXANY)
3398 if (tiosp->c_cflag & CRTSCTS) {
3400 mcor1 |= FIFO_RTSTHRESHOLD;
3404 * All cd1400 register values calculated so go through and set
3409 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3410 portp->portnr, portp->panelnr, portp->brdnr);
3411 printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3412 cor1, cor2, cor3, cor4, cor5);
3413 printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3414 mcor1, mcor2, rtpr, sreron, sreroff);
3415 printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3416 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3417 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3418 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3423 BRDENABLE(portp->brdnr, portp->pagenr);
3424 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3425 srer = stl_cd1400getreg(portp, SRER);
3426 stl_cd1400setreg(portp, SRER, 0);
3427 if (stl_cd1400updatereg(portp, COR1, cor1))
3429 if (stl_cd1400updatereg(portp, COR2, cor2))
3431 if (stl_cd1400updatereg(portp, COR3, cor3))
3434 stl_cd1400ccrwait(portp);
3435 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3437 stl_cd1400setreg(portp, COR4, cor4);
3438 stl_cd1400setreg(portp, COR5, cor5);
3439 stl_cd1400setreg(portp, MCOR1, mcor1);
3440 stl_cd1400setreg(portp, MCOR2, mcor2);
3442 stl_cd1400setreg(portp, TCOR, clk);
3443 stl_cd1400setreg(portp, TBPR, div);
3444 stl_cd1400setreg(portp, RCOR, clk);
3445 stl_cd1400setreg(portp, RBPR, div);
3447 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3448 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3449 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3450 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3451 stl_cd1400setreg(portp, RTPR, rtpr);
3452 mcor1 = stl_cd1400getreg(portp, MSVR1);
3453 if (mcor1 & MSVR1_DCD)
3454 portp->sigs |= TIOCM_CD;
3456 portp->sigs &= ~TIOCM_CD;
3457 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3458 BRDDISABLE(portp->brdnr);
3459 restore_flags(flags);
3462 /*****************************************************************************/
3465 * Set the state of the DTR and RTS signals.
3468 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3470 unsigned char msvr1, msvr2;
3471 unsigned long flags;
3474 printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
3475 (int) portp, dtr, rts);
3487 BRDENABLE(portp->brdnr, portp->pagenr);
3488 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3490 stl_cd1400setreg(portp, MSVR2, msvr2);
3492 stl_cd1400setreg(portp, MSVR1, msvr1);
3493 BRDDISABLE(portp->brdnr);
3494 restore_flags(flags);
3497 /*****************************************************************************/
3500 * Return the state of the signals.
3503 static int stl_cd1400getsignals(stlport_t *portp)
3505 unsigned char msvr1, msvr2;
3506 unsigned long flags;
3510 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3515 BRDENABLE(portp->brdnr, portp->pagenr);
3516 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3517 msvr1 = stl_cd1400getreg(portp, MSVR1);
3518 msvr2 = stl_cd1400getreg(portp, MSVR2);
3519 BRDDISABLE(portp->brdnr);
3520 restore_flags(flags);
3523 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3524 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3525 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3526 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3528 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3529 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3536 /*****************************************************************************/
3539 * Enable/Disable the Transmitter and/or Receiver.
3542 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3545 unsigned long flags;
3548 printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3549 (int) portp, rx, tx);
3554 ccr |= CCR_TXDISABLE;
3556 ccr |= CCR_TXENABLE;
3558 ccr |= CCR_RXDISABLE;
3560 ccr |= CCR_RXENABLE;
3564 BRDENABLE(portp->brdnr, portp->pagenr);
3565 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3566 stl_cd1400ccrwait(portp);
3567 stl_cd1400setreg(portp, CCR, ccr);
3568 stl_cd1400ccrwait(portp);
3569 BRDDISABLE(portp->brdnr);
3570 restore_flags(flags);
3573 /*****************************************************************************/
3576 * Start/stop the Transmitter and/or Receiver.
3579 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3581 unsigned char sreron, sreroff;
3582 unsigned long flags;
3585 printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3586 (int) portp, rx, tx);
3592 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3594 sreron |= SRER_TXDATA;
3596 sreron |= SRER_TXEMPTY;
3598 sreroff |= SRER_RXDATA;
3600 sreron |= SRER_RXDATA;
3604 BRDENABLE(portp->brdnr, portp->pagenr);
3605 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3606 stl_cd1400setreg(portp, SRER,
3607 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3608 BRDDISABLE(portp->brdnr);
3610 set_bit(ASYI_TXBUSY, &portp->istate);
3611 restore_flags(flags);
3614 /*****************************************************************************/
3617 * Disable all interrupts from this port.
3620 static void stl_cd1400disableintrs(stlport_t *portp)
3622 unsigned long flags;
3625 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3629 BRDENABLE(portp->brdnr, portp->pagenr);
3630 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3631 stl_cd1400setreg(portp, SRER, 0);
3632 BRDDISABLE(portp->brdnr);
3633 restore_flags(flags);
3636 /*****************************************************************************/
3638 static void stl_cd1400sendbreak(stlport_t *portp, int len)
3640 unsigned long flags;
3643 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
3648 BRDENABLE(portp->brdnr, portp->pagenr);
3649 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3650 stl_cd1400setreg(portp, SRER,
3651 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3653 BRDDISABLE(portp->brdnr);
3654 portp->brklen = len;
3656 portp->stats.txbreaks++;
3657 restore_flags(flags);
3660 /*****************************************************************************/
3663 * Take flow control actions...
3666 static void stl_cd1400flowctrl(stlport_t *portp, int state)
3668 struct tty_struct *tty;
3669 unsigned long flags;
3672 printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp, state);
3675 if (portp == (stlport_t *) NULL)
3678 if (tty == (struct tty_struct *) NULL)
3683 BRDENABLE(portp->brdnr, portp->pagenr);
3684 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3687 if (tty->termios->c_iflag & IXOFF) {
3688 stl_cd1400ccrwait(portp);
3689 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3690 portp->stats.rxxon++;
3691 stl_cd1400ccrwait(portp);
3694 * Question: should we return RTS to what it was before? It may
3695 * have been set by an ioctl... Suppose not, since if you have
3696 * hardware flow control set then it is pretty silly to go and
3697 * set the RTS line by hand.
3699 if (tty->termios->c_cflag & CRTSCTS) {
3700 stl_cd1400setreg(portp, MCOR1,
3701 (stl_cd1400getreg(portp, MCOR1) |
3702 FIFO_RTSTHRESHOLD));
3703 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3704 portp->stats.rxrtson++;
3707 if (tty->termios->c_iflag & IXOFF) {
3708 stl_cd1400ccrwait(portp);
3709 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3710 portp->stats.rxxoff++;
3711 stl_cd1400ccrwait(portp);
3713 if (tty->termios->c_cflag & CRTSCTS) {
3714 stl_cd1400setreg(portp, MCOR1,
3715 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3716 stl_cd1400setreg(portp, MSVR2, 0);
3717 portp->stats.rxrtsoff++;
3721 BRDDISABLE(portp->brdnr);
3722 restore_flags(flags);
3725 /*****************************************************************************/
3728 * Send a flow control character...
3731 static void stl_cd1400sendflow(stlport_t *portp, int state)
3733 struct tty_struct *tty;
3734 unsigned long flags;
3737 printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp, state);
3740 if (portp == (stlport_t *) NULL)
3743 if (tty == (struct tty_struct *) NULL)
3748 BRDENABLE(portp->brdnr, portp->pagenr);
3749 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3751 stl_cd1400ccrwait(portp);
3752 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3753 portp->stats.rxxon++;
3754 stl_cd1400ccrwait(portp);
3756 stl_cd1400ccrwait(portp);
3757 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3758 portp->stats.rxxoff++;
3759 stl_cd1400ccrwait(portp);
3761 BRDDISABLE(portp->brdnr);
3762 restore_flags(flags);
3765 /*****************************************************************************/
3767 static void stl_cd1400flush(stlport_t *portp)
3769 unsigned long flags;
3772 printk("stl_cd1400flush(portp=%x)\n", (int) portp);
3775 if (portp == (stlport_t *) NULL)
3780 BRDENABLE(portp->brdnr, portp->pagenr);
3781 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3782 stl_cd1400ccrwait(portp);
3783 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3784 stl_cd1400ccrwait(portp);
3785 portp->tx.tail = portp->tx.head;
3786 BRDDISABLE(portp->brdnr);
3787 restore_flags(flags);
3790 /*****************************************************************************/
3793 * Return the current state of data flow on this port. This is only
3794 * really interresting when determining if data has fully completed
3795 * transmission or not... This is easy for the cd1400, it accurately
3796 * maintains the busy port flag.
3799 static int stl_cd1400datastate(stlport_t *portp)
3802 printk("stl_cd1400datastate(portp=%x)\n", (int) portp);
3805 if (portp == (stlport_t *) NULL)
3808 return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
3811 /*****************************************************************************/
3814 * Interrupt service routine for cd1400 EasyIO boards.
3817 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3819 unsigned char svrtype;
3822 printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
3823 (int) panelp, iobase);
3827 svrtype = inb(iobase + EREG_DATA);
3828 if (panelp->nrports > 4) {
3829 outb((SVRR + 0x80), iobase);
3830 svrtype |= inb(iobase + EREG_DATA);
3833 if (svrtype & SVRR_RX)
3834 stl_cd1400rxisr(panelp, iobase);
3835 else if (svrtype & SVRR_TX)
3836 stl_cd1400txisr(panelp, iobase);
3837 else if (svrtype & SVRR_MDM)
3838 stl_cd1400mdmisr(panelp, iobase);
3841 /*****************************************************************************/
3844 * Interrupt service routine for cd1400 panels.
3847 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
3849 unsigned char svrtype;
3852 printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
3857 svrtype = inb(iobase + EREG_DATA);
3858 outb((SVRR + 0x80), iobase);
3859 svrtype |= inb(iobase + EREG_DATA);
3860 if (svrtype & SVRR_RX)
3861 stl_cd1400rxisr(panelp, iobase);
3862 else if (svrtype & SVRR_TX)
3863 stl_cd1400txisr(panelp, iobase);
3864 else if (svrtype & SVRR_MDM)
3865 stl_cd1400mdmisr(panelp, iobase);
3869 /*****************************************************************************/
3872 * Unfortunately we need to handle breaks in the TX data stream, since
3873 * this is the only way to generate them on the cd1400.
3876 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr)
3878 if (portp->brklen == 1) {
3879 outb((COR2 + portp->uartaddr), ioaddr);
3880 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
3881 (ioaddr + EREG_DATA));
3882 outb((TDR + portp->uartaddr), ioaddr);
3883 outb(ETC_CMD, (ioaddr + EREG_DATA));
3884 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
3885 outb((SRER + portp->uartaddr), ioaddr);
3886 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
3887 (ioaddr + EREG_DATA));
3889 } else if (portp->brklen > 1) {
3890 outb((TDR + portp->uartaddr), ioaddr);
3891 outb(ETC_CMD, (ioaddr + EREG_DATA));
3892 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
3896 outb((COR2 + portp->uartaddr), ioaddr);
3897 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
3898 (ioaddr + EREG_DATA));
3904 /*****************************************************************************/
3907 * Transmit interrupt handler. This has gotta be fast! Handling TX
3908 * chars is pretty simple, stuff as many as possible from the TX buffer
3909 * into the cd1400 FIFO. Must also handle TX breaks here, since they
3910 * are embedded as commands in the data stream. Oh no, had to use a goto!
3911 * This could be optimized more, will do when I get time...
3912 * In practice it is possible that interrupts are enabled but that the
3913 * port has been hung up. Need to handle not having any TX buffer here,
3914 * this is done by using the side effect that head and tail will also
3915 * be NULL if the buffer has been freed.
3918 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
3923 unsigned char ioack, srer;
3926 printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
3929 ioack = inb(ioaddr + EREG_TXACK);
3930 if (((ioack & panelp->ackmask) != 0) ||
3931 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
3932 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
3935 portp = panelp->ports[(ioack >> 3)];
3938 * Unfortunately we need to handle breaks in the data stream, since
3939 * this is the only way to generate them on the cd1400. Do it now if
3940 * a break is to be sent.
3942 if (portp->brklen != 0)
3943 if (stl_cd1400breakisr(portp, ioaddr))
3946 head = portp->tx.head;
3947 tail = portp->tx.tail;
3948 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
3949 if ((len == 0) || ((len < STL_TXBUFLOW) &&
3950 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
3951 set_bit(ASYI_TXLOW, &portp->istate);
3952 schedule_work(&portp->tqueue);
3956 outb((SRER + portp->uartaddr), ioaddr);
3957 srer = inb(ioaddr + EREG_DATA);
3958 if (srer & SRER_TXDATA) {
3959 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
3961 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
3962 clear_bit(ASYI_TXBUSY, &portp->istate);
3964 outb(srer, (ioaddr + EREG_DATA));
3966 len = MIN(len, CD1400_TXFIFOSIZE);
3967 portp->stats.txtotal += len;
3968 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
3969 outb((TDR + portp->uartaddr), ioaddr);
3970 outsb((ioaddr + EREG_DATA), tail, stlen);
3973 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
3974 tail = portp->tx.buf;
3976 outsb((ioaddr + EREG_DATA), tail, len);
3979 portp->tx.tail = tail;
3983 outb((EOSRR + portp->uartaddr), ioaddr);
3984 outb(0, (ioaddr + EREG_DATA));
3987 /*****************************************************************************/
3990 * Receive character interrupt handler. Determine if we have good chars
3991 * or bad chars and then process appropriately. Good chars are easy
3992 * just shove the lot into the RX buffer and set all status byte to 0.
3993 * If a bad RX char then process as required. This routine needs to be
3994 * fast! In practice it is possible that we get an interrupt on a port
3995 * that is closed. This can happen on hangups - since they completely
3996 * shutdown a port not in user context. Need to handle this case.
3999 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
4002 struct tty_struct *tty;
4003 unsigned int ioack, len, buflen;
4004 unsigned char status;
4008 printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
4011 ioack = inb(ioaddr + EREG_RXACK);
4012 if ((ioack & panelp->ackmask) != 0) {
4013 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4016 portp = panelp->ports[(ioack >> 3)];
4019 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
4020 outb((RDCR + portp->uartaddr), ioaddr);
4021 len = inb(ioaddr + EREG_DATA);
4022 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
4023 len = MIN(len, sizeof(stl_unwanted));
4024 outb((RDSR + portp->uartaddr), ioaddr);
4025 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
4026 portp->stats.rxlost += len;
4027 portp->stats.rxtotal += len;
4029 len = MIN(len, buflen);
4032 outb((RDSR + portp->uartaddr), ioaddr);
4033 tty_prepare_flip_string(tty, &ptr, len);
4034 insb((ioaddr + EREG_DATA), ptr, len);
4035 tty_schedule_flip(tty);
4036 portp->stats.rxtotal += len;
4039 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
4040 outb((RDSR + portp->uartaddr), ioaddr);
4041 status = inb(ioaddr + EREG_DATA);
4042 ch = inb(ioaddr + EREG_DATA);
4043 if (status & ST_PARITY)
4044 portp->stats.rxparity++;
4045 if (status & ST_FRAMING)
4046 portp->stats.rxframing++;
4047 if (status & ST_OVERRUN)
4048 portp->stats.rxoverrun++;
4049 if (status & ST_BREAK)
4050 portp->stats.rxbreaks++;
4051 if (status & ST_SCHARMASK) {
4052 if ((status & ST_SCHARMASK) == ST_SCHAR1)
4053 portp->stats.txxon++;
4054 if ((status & ST_SCHARMASK) == ST_SCHAR2)
4055 portp->stats.txxoff++;
4058 if (tty != NULL && (portp->rxignoremsk & status) == 0) {
4059 if (portp->rxmarkmsk & status) {
4060 if (status & ST_BREAK) {
4062 if (portp->flags & ASYNC_SAK) {
4064 BRDENABLE(portp->brdnr, portp->pagenr);
4066 } else if (status & ST_PARITY) {
4067 status = TTY_PARITY;
4068 } else if (status & ST_FRAMING) {
4070 } else if(status & ST_OVERRUN) {
4071 status = TTY_OVERRUN;
4078 tty_insert_flip_char(tty, ch, status);
4079 tty_schedule_flip(tty);
4082 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4087 outb((EOSRR + portp->uartaddr), ioaddr);
4088 outb(0, (ioaddr + EREG_DATA));
4091 /*****************************************************************************/
4094 * Modem interrupt handler. The is called when the modem signal line
4095 * (DCD) has changed state. Leave most of the work to the off-level
4096 * processing routine.
4099 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
4106 printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp);
4109 ioack = inb(ioaddr + EREG_MDACK);
4110 if (((ioack & panelp->ackmask) != 0) ||
4111 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
4112 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
4115 portp = panelp->ports[(ioack >> 3)];
4117 outb((MISR + portp->uartaddr), ioaddr);
4118 misr = inb(ioaddr + EREG_DATA);
4119 if (misr & MISR_DCD) {
4120 set_bit(ASYI_DCDCHANGE, &portp->istate);
4121 schedule_work(&portp->tqueue);
4122 portp->stats.modem++;
4125 outb((EOSRR + portp->uartaddr), ioaddr);
4126 outb(0, (ioaddr + EREG_DATA));
4129 /*****************************************************************************/
4130 /* SC26198 HARDWARE FUNCTIONS */
4131 /*****************************************************************************/
4134 * These functions get/set/update the registers of the sc26198 UARTs.
4135 * Access to the sc26198 registers is via an address/data io port pair.
4136 * (Maybe should make this inline...)
4139 static int stl_sc26198getreg(stlport_t *portp, int regnr)
4141 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4142 return inb(portp->ioaddr + XP_DATA);
4145 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
4147 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4148 outb(value, (portp->ioaddr + XP_DATA));
4151 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
4153 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4154 if (inb(portp->ioaddr + XP_DATA) != value) {
4155 outb(value, (portp->ioaddr + XP_DATA));
4161 /*****************************************************************************/
4164 * Functions to get and set the sc26198 global registers.
4167 static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
4169 outb(regnr, (portp->ioaddr + XP_ADDR));
4170 return inb(portp->ioaddr + XP_DATA);
4174 static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
4176 outb(regnr, (portp->ioaddr + XP_ADDR));
4177 outb(value, (portp->ioaddr + XP_DATA));
4181 /*****************************************************************************/
4184 * Inbitialize the UARTs in a panel. We don't care what sort of board
4185 * these ports are on - since the port io registers are almost
4186 * identical when dealing with ports.
4189 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
4192 int nrchips, ioaddr;
4195 printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
4196 (int) brdp, (int) panelp);
4199 BRDENABLE(panelp->brdnr, panelp->pagenr);
4202 * Check that each chip is present and started up OK.
4205 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
4206 if (brdp->brdtype == BRD_ECHPCI)
4207 outb(panelp->pagenr, brdp->ioctrl);
4209 for (i = 0; (i < nrchips); i++) {
4210 ioaddr = panelp->iobase + (i * 4);
4211 outb(SCCR, (ioaddr + XP_ADDR));
4212 outb(CR_RESETALL, (ioaddr + XP_DATA));
4213 outb(TSTR, (ioaddr + XP_ADDR));
4214 if (inb(ioaddr + XP_DATA) != 0) {
4215 printk("STALLION: sc26198 not responding, "
4216 "brd=%d panel=%d chip=%d\n",
4217 panelp->brdnr, panelp->panelnr, i);
4220 chipmask |= (0x1 << i);
4221 outb(GCCR, (ioaddr + XP_ADDR));
4222 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
4223 outb(WDTRCR, (ioaddr + XP_ADDR));
4224 outb(0xff, (ioaddr + XP_DATA));
4227 BRDDISABLE(panelp->brdnr);
4231 /*****************************************************************************/
4234 * Initialize hardware specific port registers.
4237 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
4240 printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
4241 (int) brdp, (int) panelp, (int) portp);
4244 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
4245 (portp == (stlport_t *) NULL))
4248 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
4249 portp->uartaddr = (portp->portnr & 0x07) << 4;
4250 portp->pagenr = panelp->pagenr;
4253 BRDENABLE(portp->brdnr, portp->pagenr);
4254 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
4255 BRDDISABLE(portp->brdnr);
4258 /*****************************************************************************/
4261 * Set up the sc26198 registers for a port based on the termios port
4265 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4268 unsigned long flags;
4269 unsigned int baudrate;
4270 unsigned char mr0, mr1, mr2, clk;
4271 unsigned char imron, imroff, iopr, ipr;
4281 brdp = stl_brds[portp->brdnr];
4282 if (brdp == (stlbrd_t *) NULL)
4286 * Set up the RX char ignore mask with those RX error types we
4289 portp->rxignoremsk = 0;
4290 if (tiosp->c_iflag & IGNPAR)
4291 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
4293 if (tiosp->c_iflag & IGNBRK)
4294 portp->rxignoremsk |= SR_RXBREAK;
4296 portp->rxmarkmsk = SR_RXOVERRUN;
4297 if (tiosp->c_iflag & (INPCK | PARMRK))
4298 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
4299 if (tiosp->c_iflag & BRKINT)
4300 portp->rxmarkmsk |= SR_RXBREAK;
4303 * Go through the char size, parity and stop bits and set all the
4304 * option register appropriately.
4306 switch (tiosp->c_cflag & CSIZE) {
4321 if (tiosp->c_cflag & CSTOPB)
4326 if (tiosp->c_cflag & PARENB) {
4327 if (tiosp->c_cflag & PARODD)
4328 mr1 |= (MR1_PARENB | MR1_PARODD);
4330 mr1 |= (MR1_PARENB | MR1_PAREVEN);
4335 mr1 |= MR1_ERRBLOCK;
4338 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4339 * space for hardware flow control and the like. This should be set to
4342 mr2 |= MR2_RXFIFOHALF;
4345 * Calculate the baud rate timers. For now we will just assume that
4346 * the input and output baud are the same. The sc26198 has a fixed
4347 * baud rate table, so only discrete baud rates possible.
4349 baudrate = tiosp->c_cflag & CBAUD;
4350 if (baudrate & CBAUDEX) {
4351 baudrate &= ~CBAUDEX;
4352 if ((baudrate < 1) || (baudrate > 4))
4353 tiosp->c_cflag &= ~CBAUDEX;
4357 baudrate = stl_baudrates[baudrate];
4358 if ((tiosp->c_cflag & CBAUD) == B38400) {
4359 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
4361 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
4363 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
4365 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
4367 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
4368 baudrate = (portp->baud_base / portp->custom_divisor);
4370 if (baudrate > STL_SC26198MAXBAUD)
4371 baudrate = STL_SC26198MAXBAUD;
4374 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
4375 if (baudrate <= sc26198_baudtable[clk])
4381 * Check what form of modem signaling is required and set it up.
4383 if (tiosp->c_cflag & CLOCAL) {
4384 portp->flags &= ~ASYNC_CHECK_CD;
4386 iopr |= IOPR_DCDCOS;
4388 portp->flags |= ASYNC_CHECK_CD;
4392 * Setup sc26198 enhanced modes if we can. In particular we want to
4393 * handle as much of the flow control as possible automatically. As
4394 * well as saving a few CPU cycles it will also greatly improve flow
4395 * control reliability.
4397 if (tiosp->c_iflag & IXON) {
4398 mr0 |= MR0_SWFTX | MR0_SWFT;
4399 imron |= IR_XONXOFF;
4401 imroff |= IR_XONXOFF;
4403 if (tiosp->c_iflag & IXOFF)
4406 if (tiosp->c_cflag & CRTSCTS) {
4412 * All sc26198 register values calculated so go through and set
4417 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4418 portp->portnr, portp->panelnr, portp->brdnr);
4419 printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4420 printk(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4421 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4422 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4423 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4428 BRDENABLE(portp->brdnr, portp->pagenr);
4429 stl_sc26198setreg(portp, IMR, 0);
4430 stl_sc26198updatereg(portp, MR0, mr0);
4431 stl_sc26198updatereg(portp, MR1, mr1);
4432 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4433 stl_sc26198updatereg(portp, MR2, mr2);
4434 stl_sc26198updatereg(portp, IOPIOR,
4435 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
4438 stl_sc26198setreg(portp, TXCSR, clk);
4439 stl_sc26198setreg(portp, RXCSR, clk);
4442 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4443 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4445 ipr = stl_sc26198getreg(portp, IPR);
4447 portp->sigs &= ~TIOCM_CD;
4449 portp->sigs |= TIOCM_CD;
4451 portp->imr = (portp->imr & ~imroff) | imron;
4452 stl_sc26198setreg(portp, IMR, portp->imr);
4453 BRDDISABLE(portp->brdnr);
4454 restore_flags(flags);
4457 /*****************************************************************************/
4460 * Set the state of the DTR and RTS signals.
4463 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
4465 unsigned char iopioron, iopioroff;
4466 unsigned long flags;
4469 printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4470 (int) portp, dtr, rts);
4476 iopioroff |= IPR_DTR;
4478 iopioron |= IPR_DTR;
4480 iopioroff |= IPR_RTS;
4482 iopioron |= IPR_RTS;
4486 BRDENABLE(portp->brdnr, portp->pagenr);
4487 stl_sc26198setreg(portp, IOPIOR,
4488 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4489 BRDDISABLE(portp->brdnr);
4490 restore_flags(flags);
4493 /*****************************************************************************/
4496 * Return the state of the signals.
4499 static int stl_sc26198getsignals(stlport_t *portp)
4502 unsigned long flags;
4506 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
4511 BRDENABLE(portp->brdnr, portp->pagenr);
4512 ipr = stl_sc26198getreg(portp, IPR);
4513 BRDDISABLE(portp->brdnr);
4514 restore_flags(flags);
4517 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4518 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4519 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4520 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4525 /*****************************************************************************/
4528 * Enable/Disable the Transmitter and/or Receiver.
4531 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
4534 unsigned long flags;
4537 printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4538 (int) portp, rx, tx);
4541 ccr = portp->crenable;
4543 ccr &= ~CR_TXENABLE;
4547 ccr &= ~CR_RXENABLE;
4553 BRDENABLE(portp->brdnr, portp->pagenr);
4554 stl_sc26198setreg(portp, SCCR, ccr);
4555 BRDDISABLE(portp->brdnr);
4556 portp->crenable = ccr;
4557 restore_flags(flags);
4560 /*****************************************************************************/
4563 * Start/stop the Transmitter and/or Receiver.
4566 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
4569 unsigned long flags;
4572 printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4573 (int) portp, rx, tx);
4582 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4584 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4588 BRDENABLE(portp->brdnr, portp->pagenr);
4589 stl_sc26198setreg(portp, IMR, imr);
4590 BRDDISABLE(portp->brdnr);
4593 set_bit(ASYI_TXBUSY, &portp->istate);
4594 restore_flags(flags);
4597 /*****************************************************************************/
4600 * Disable all interrupts from this port.
4603 static void stl_sc26198disableintrs(stlport_t *portp)
4605 unsigned long flags;
4608 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
4613 BRDENABLE(portp->brdnr, portp->pagenr);
4615 stl_sc26198setreg(portp, IMR, 0);
4616 BRDDISABLE(portp->brdnr);
4617 restore_flags(flags);
4620 /*****************************************************************************/
4622 static void stl_sc26198sendbreak(stlport_t *portp, int len)
4624 unsigned long flags;
4627 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
4632 BRDENABLE(portp->brdnr, portp->pagenr);
4634 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4635 portp->stats.txbreaks++;
4637 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4639 BRDDISABLE(portp->brdnr);
4640 restore_flags(flags);
4643 /*****************************************************************************/
4646 * Take flow control actions...
4649 static void stl_sc26198flowctrl(stlport_t *portp, int state)
4651 struct tty_struct *tty;
4652 unsigned long flags;
4656 printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp, state);
4659 if (portp == (stlport_t *) NULL)
4662 if (tty == (struct tty_struct *) NULL)
4667 BRDENABLE(portp->brdnr, portp->pagenr);
4670 if (tty->termios->c_iflag & IXOFF) {
4671 mr0 = stl_sc26198getreg(portp, MR0);
4672 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4673 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4675 portp->stats.rxxon++;
4676 stl_sc26198wait(portp);
4677 stl_sc26198setreg(portp, MR0, mr0);
4680 * Question: should we return RTS to what it was before? It may
4681 * have been set by an ioctl... Suppose not, since if you have
4682 * hardware flow control set then it is pretty silly to go and
4683 * set the RTS line by hand.
4685 if (tty->termios->c_cflag & CRTSCTS) {
4686 stl_sc26198setreg(portp, MR1,
4687 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4688 stl_sc26198setreg(portp, IOPIOR,
4689 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4690 portp->stats.rxrtson++;
4693 if (tty->termios->c_iflag & IXOFF) {
4694 mr0 = stl_sc26198getreg(portp, MR0);
4695 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4696 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4698 portp->stats.rxxoff++;
4699 stl_sc26198wait(portp);
4700 stl_sc26198setreg(portp, MR0, mr0);
4702 if (tty->termios->c_cflag & CRTSCTS) {
4703 stl_sc26198setreg(portp, MR1,
4704 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4705 stl_sc26198setreg(portp, IOPIOR,
4706 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4707 portp->stats.rxrtsoff++;
4711 BRDDISABLE(portp->brdnr);
4712 restore_flags(flags);
4715 /*****************************************************************************/
4718 * Send a flow control character.
4721 static void stl_sc26198sendflow(stlport_t *portp, int state)
4723 struct tty_struct *tty;
4724 unsigned long flags;
4728 printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp, state);
4731 if (portp == (stlport_t *) NULL)
4734 if (tty == (struct tty_struct *) NULL)
4739 BRDENABLE(portp->brdnr, portp->pagenr);
4741 mr0 = stl_sc26198getreg(portp, MR0);
4742 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4743 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4745 portp->stats.rxxon++;
4746 stl_sc26198wait(portp);
4747 stl_sc26198setreg(portp, MR0, mr0);
4749 mr0 = stl_sc26198getreg(portp, MR0);
4750 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4751 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4753 portp->stats.rxxoff++;
4754 stl_sc26198wait(portp);
4755 stl_sc26198setreg(portp, MR0, mr0);
4757 BRDDISABLE(portp->brdnr);
4758 restore_flags(flags);
4761 /*****************************************************************************/
4763 static void stl_sc26198flush(stlport_t *portp)
4765 unsigned long flags;
4768 printk("stl_sc26198flush(portp=%x)\n", (int) portp);
4771 if (portp == (stlport_t *) NULL)
4776 BRDENABLE(portp->brdnr, portp->pagenr);
4777 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4778 stl_sc26198setreg(portp, SCCR, portp->crenable);
4779 BRDDISABLE(portp->brdnr);
4780 portp->tx.tail = portp->tx.head;
4781 restore_flags(flags);
4784 /*****************************************************************************/
4787 * Return the current state of data flow on this port. This is only
4788 * really interresting when determining if data has fully completed
4789 * transmission or not... The sc26198 interrupt scheme cannot
4790 * determine when all data has actually drained, so we need to
4791 * check the port statusy register to be sure.
4794 static int stl_sc26198datastate(stlport_t *portp)
4796 unsigned long flags;
4800 printk("stl_sc26198datastate(portp=%x)\n", (int) portp);
4803 if (portp == (stlport_t *) NULL)
4805 if (test_bit(ASYI_TXBUSY, &portp->istate))
4810 BRDENABLE(portp->brdnr, portp->pagenr);
4811 sr = stl_sc26198getreg(portp, SR);
4812 BRDDISABLE(portp->brdnr);
4813 restore_flags(flags);
4815 return (sr & SR_TXEMPTY) ? 0 : 1;
4818 /*****************************************************************************/
4821 * Delay for a small amount of time, to give the sc26198 a chance
4822 * to process a command...
4825 static void stl_sc26198wait(stlport_t *portp)
4830 printk("stl_sc26198wait(portp=%x)\n", (int) portp);
4833 if (portp == (stlport_t *) NULL)
4836 for (i = 0; (i < 20); i++)
4837 stl_sc26198getglobreg(portp, TSTR);
4840 /*****************************************************************************/
4843 * If we are TX flow controlled and in IXANY mode then we may
4844 * need to unflow control here. We gotta do this because of the
4845 * automatic flow control modes of the sc26198.
4848 static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty)
4852 mr0 = stl_sc26198getreg(portp, MR0);
4853 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4854 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4855 stl_sc26198wait(portp);
4856 stl_sc26198setreg(portp, MR0, mr0);
4857 clear_bit(ASYI_TXFLOWED, &portp->istate);
4860 /*****************************************************************************/
4863 * Interrupt service routine for sc26198 panels.
4866 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4872 * Work around bug in sc26198 chip... Cannot have A6 address
4873 * line of UART high, else iack will be returned as 0.
4875 outb(0, (iobase + 1));
4877 iack = inb(iobase + XP_IACK);
4878 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4880 if (iack & IVR_RXDATA)
4881 stl_sc26198rxisr(portp, iack);
4882 else if (iack & IVR_TXDATA)
4883 stl_sc26198txisr(portp);
4885 stl_sc26198otherisr(portp, iack);
4888 /*****************************************************************************/
4891 * Transmit interrupt handler. This has gotta be fast! Handling TX
4892 * chars is pretty simple, stuff as many as possible from the TX buffer
4893 * into the sc26198 FIFO.
4894 * In practice it is possible that interrupts are enabled but that the
4895 * port has been hung up. Need to handle not having any TX buffer here,
4896 * this is done by using the side effect that head and tail will also
4897 * be NULL if the buffer has been freed.
4900 static void stl_sc26198txisr(stlport_t *portp)
4902 unsigned int ioaddr;
4908 printk("stl_sc26198txisr(portp=%x)\n", (int) portp);
4911 ioaddr = portp->ioaddr;
4912 head = portp->tx.head;
4913 tail = portp->tx.tail;
4914 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4915 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4916 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4917 set_bit(ASYI_TXLOW, &portp->istate);
4918 schedule_work(&portp->tqueue);
4922 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
4923 mr0 = inb(ioaddr + XP_DATA);
4924 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4925 portp->imr &= ~IR_TXRDY;
4926 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
4927 outb(portp->imr, (ioaddr + XP_DATA));
4928 clear_bit(ASYI_TXBUSY, &portp->istate);
4930 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4931 outb(mr0, (ioaddr + XP_DATA));
4934 len = MIN(len, SC26198_TXFIFOSIZE);
4935 portp->stats.txtotal += len;
4936 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4937 outb(GTXFIFO, (ioaddr + XP_ADDR));
4938 outsb((ioaddr + XP_DATA), tail, stlen);
4941 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4942 tail = portp->tx.buf;
4944 outsb((ioaddr + XP_DATA), tail, len);
4947 portp->tx.tail = tail;
4951 /*****************************************************************************/
4954 * Receive character interrupt handler. Determine if we have good chars
4955 * or bad chars and then process appropriately. Good chars are easy
4956 * just shove the lot into the RX buffer and set all status byte to 0.
4957 * If a bad RX char then process as required. This routine needs to be
4958 * fast! In practice it is possible that we get an interrupt on a port
4959 * that is closed. This can happen on hangups - since they completely
4960 * shutdown a port not in user context. Need to handle this case.
4963 static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
4965 struct tty_struct *tty;
4966 unsigned int len, buflen, ioaddr;
4969 printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
4973 ioaddr = portp->ioaddr;
4974 outb(GIBCR, (ioaddr + XP_ADDR));
4975 len = inb(ioaddr + XP_DATA) + 1;
4977 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
4978 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
4979 len = MIN(len, sizeof(stl_unwanted));
4980 outb(GRXFIFO, (ioaddr + XP_ADDR));
4981 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4982 portp->stats.rxlost += len;
4983 portp->stats.rxtotal += len;
4985 len = MIN(len, buflen);
4988 outb(GRXFIFO, (ioaddr + XP_ADDR));
4989 tty_prepare_flip_string(tty, &ptr, len);
4990 insb((ioaddr + XP_DATA), ptr, len);
4991 tty_schedule_flip(tty);
4992 portp->stats.rxtotal += len;
4996 stl_sc26198rxbadchars(portp);
5000 * If we are TX flow controlled and in IXANY mode then we may need
5001 * to unflow control here. We gotta do this because of the automatic
5002 * flow control modes of the sc26198.
5004 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
5005 if ((tty != (struct tty_struct *) NULL) &&
5006 (tty->termios != (struct termios *) NULL) &&
5007 (tty->termios->c_iflag & IXANY)) {
5008 stl_sc26198txunflow(portp, tty);
5013 /*****************************************************************************/
5016 * Process an RX bad character.
5019 static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch)
5021 struct tty_struct *tty;
5022 unsigned int ioaddr;
5025 ioaddr = portp->ioaddr;
5027 if (status & SR_RXPARITY)
5028 portp->stats.rxparity++;
5029 if (status & SR_RXFRAMING)
5030 portp->stats.rxframing++;
5031 if (status & SR_RXOVERRUN)
5032 portp->stats.rxoverrun++;
5033 if (status & SR_RXBREAK)
5034 portp->stats.rxbreaks++;
5036 if ((tty != (struct tty_struct *) NULL) &&
5037 ((portp->rxignoremsk & status) == 0)) {
5038 if (portp->rxmarkmsk & status) {
5039 if (status & SR_RXBREAK) {
5041 if (portp->flags & ASYNC_SAK) {
5043 BRDENABLE(portp->brdnr, portp->pagenr);
5045 } else if (status & SR_RXPARITY) {
5046 status = TTY_PARITY;
5047 } else if (status & SR_RXFRAMING) {
5049 } else if(status & SR_RXOVERRUN) {
5050 status = TTY_OVERRUN;
5058 tty_insert_flip_char(tty, ch, status);
5059 tty_schedule_flip(tty);
5062 portp->stats.rxtotal++;
5066 /*****************************************************************************/
5069 * Process all characters in the RX FIFO of the UART. Check all char
5070 * status bytes as well, and process as required. We need to check
5071 * all bytes in the FIFO, in case some more enter the FIFO while we
5072 * are here. To get the exact character error type we need to switch
5073 * into CHAR error mode (that is why we need to make sure we empty
5077 static void stl_sc26198rxbadchars(stlport_t *portp)
5079 unsigned char status, mr1;
5083 * To get the precise error type for each character we must switch
5084 * back into CHAR error mode.
5086 mr1 = stl_sc26198getreg(portp, MR1);
5087 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
5089 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
5090 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
5091 ch = stl_sc26198getreg(portp, RXFIFO);
5092 stl_sc26198rxbadch(portp, status, ch);
5096 * To get correct interrupt class we must switch back into BLOCK
5099 stl_sc26198setreg(portp, MR1, mr1);
5102 /*****************************************************************************/
5105 * Other interrupt handler. This includes modem signals, flow
5106 * control actions, etc. Most stuff is left to off-level interrupt
5110 static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
5112 unsigned char cir, ipr, xisr;
5115 printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
5118 cir = stl_sc26198getglobreg(portp, CIR);
5120 switch (cir & CIR_SUBTYPEMASK) {
5122 ipr = stl_sc26198getreg(portp, IPR);
5123 if (ipr & IPR_DCDCHANGE) {
5124 set_bit(ASYI_DCDCHANGE, &portp->istate);
5125 schedule_work(&portp->tqueue);
5126 portp->stats.modem++;
5129 case CIR_SUBXONXOFF:
5130 xisr = stl_sc26198getreg(portp, XISR);
5131 if (xisr & XISR_RXXONGOT) {
5132 set_bit(ASYI_TXFLOWED, &portp->istate);
5133 portp->stats.txxoff++;
5135 if (xisr & XISR_RXXOFFGOT) {
5136 clear_bit(ASYI_TXFLOWED, &portp->istate);
5137 portp->stats.txxon++;
5141 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
5142 stl_sc26198rxbadchars(portp);
5149 /*****************************************************************************/