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->devfs_name = "tts/E";
3079 stl_serial->major = STL_SERIALMAJOR;
3080 stl_serial->minor_start = 0;
3081 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
3082 stl_serial->subtype = SERIAL_TYPE_NORMAL;
3083 stl_serial->init_termios = stl_deftermios;
3084 stl_serial->flags = TTY_DRIVER_REAL_RAW;
3085 tty_set_operations(stl_serial, &stl_ops);
3087 if (tty_register_driver(stl_serial)) {
3088 put_tty_driver(stl_serial);
3089 printk("STALLION: failed to register serial driver\n");
3096 /*****************************************************************************/
3097 /* CD1400 HARDWARE FUNCTIONS */
3098 /*****************************************************************************/
3101 * These functions get/set/update the registers of the cd1400 UARTs.
3102 * Access to the cd1400 registers is via an address/data io port pair.
3103 * (Maybe should make this inline...)
3106 static int stl_cd1400getreg(stlport_t *portp, int regnr)
3108 outb((regnr + portp->uartaddr), portp->ioaddr);
3109 return inb(portp->ioaddr + EREG_DATA);
3112 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
3114 outb((regnr + portp->uartaddr), portp->ioaddr);
3115 outb(value, portp->ioaddr + EREG_DATA);
3118 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
3120 outb((regnr + portp->uartaddr), portp->ioaddr);
3121 if (inb(portp->ioaddr + EREG_DATA) != value) {
3122 outb(value, portp->ioaddr + EREG_DATA);
3128 /*****************************************************************************/
3131 * Inbitialize the UARTs in a panel. We don't care what sort of board
3132 * these ports are on - since the port io registers are almost
3133 * identical when dealing with ports.
3136 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3140 int nrchips, uartaddr, ioaddr;
3143 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
3146 BRDENABLE(panelp->brdnr, panelp->pagenr);
3149 * Check that each chip is present and started up OK.
3152 nrchips = panelp->nrports / CD1400_PORTS;
3153 for (i = 0; (i < nrchips); i++) {
3154 if (brdp->brdtype == BRD_ECHPCI) {
3155 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3156 ioaddr = panelp->iobase;
3158 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3160 uartaddr = (i & 0x01) ? 0x080 : 0;
3161 outb((GFRCR + uartaddr), ioaddr);
3162 outb(0, (ioaddr + EREG_DATA));
3163 outb((CCR + uartaddr), ioaddr);
3164 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3165 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3166 outb((GFRCR + uartaddr), ioaddr);
3167 for (j = 0; (j < CCR_MAXWAIT); j++) {
3168 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3171 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3172 printk("STALLION: cd1400 not responding, "
3173 "brd=%d panel=%d chip=%d\n",
3174 panelp->brdnr, panelp->panelnr, i);
3177 chipmask |= (0x1 << i);
3178 outb((PPR + uartaddr), ioaddr);
3179 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
3182 BRDDISABLE(panelp->brdnr);
3186 /*****************************************************************************/
3189 * Initialize hardware specific port registers.
3192 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3195 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3196 (int) brdp, (int) panelp, (int) portp);
3199 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
3200 (portp == (stlport_t *) NULL))
3203 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3204 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3205 portp->uartaddr = (portp->portnr & 0x04) << 5;
3206 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3208 BRDENABLE(portp->brdnr, portp->pagenr);
3209 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3210 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3211 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3212 BRDDISABLE(portp->brdnr);
3215 /*****************************************************************************/
3218 * Wait for the command register to be ready. We will poll this,
3219 * since it won't usually take too long to be ready.
3222 static void stl_cd1400ccrwait(stlport_t *portp)
3226 for (i = 0; (i < CCR_MAXWAIT); i++) {
3227 if (stl_cd1400getreg(portp, CCR) == 0) {
3232 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
3233 portp->portnr, portp->panelnr, portp->brdnr);
3236 /*****************************************************************************/
3239 * Set up the cd1400 registers for a port based on the termios port
3243 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3246 unsigned long flags;
3247 unsigned int clkdiv, baudrate;
3248 unsigned char cor1, cor2, cor3;
3249 unsigned char cor4, cor5, ccr;
3250 unsigned char srer, sreron, sreroff;
3251 unsigned char mcor1, mcor2, rtpr;
3252 unsigned char clk, div;
3268 brdp = stl_brds[portp->brdnr];
3269 if (brdp == (stlbrd_t *) NULL)
3273 * Set up the RX char ignore mask with those RX error types we
3274 * can ignore. We can get the cd1400 to help us out a little here,
3275 * it will ignore parity errors and breaks for us.
3277 portp->rxignoremsk = 0;
3278 if (tiosp->c_iflag & IGNPAR) {
3279 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
3280 cor1 |= COR1_PARIGNORE;
3282 if (tiosp->c_iflag & IGNBRK) {
3283 portp->rxignoremsk |= ST_BREAK;
3284 cor4 |= COR4_IGNBRK;
3287 portp->rxmarkmsk = ST_OVERRUN;
3288 if (tiosp->c_iflag & (INPCK | PARMRK))
3289 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3290 if (tiosp->c_iflag & BRKINT)
3291 portp->rxmarkmsk |= ST_BREAK;
3294 * Go through the char size, parity and stop bits and set all the
3295 * option register appropriately.
3297 switch (tiosp->c_cflag & CSIZE) {
3312 if (tiosp->c_cflag & CSTOPB)
3317 if (tiosp->c_cflag & PARENB) {
3318 if (tiosp->c_cflag & PARODD)
3319 cor1 |= (COR1_PARENB | COR1_PARODD);
3321 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3323 cor1 |= COR1_PARNONE;
3327 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3328 * space for hardware flow control and the like. This should be set to
3329 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3330 * really be based on VTIME.
3332 cor3 |= FIFO_RXTHRESHOLD;
3336 * Calculate the baud rate timers. For now we will just assume that
3337 * the input and output baud are the same. Could have used a baud
3338 * table here, but this way we can generate virtually any baud rate
3341 baudrate = tiosp->c_cflag & CBAUD;
3342 if (baudrate & CBAUDEX) {
3343 baudrate &= ~CBAUDEX;
3344 if ((baudrate < 1) || (baudrate > 4))
3345 tiosp->c_cflag &= ~CBAUDEX;
3349 baudrate = stl_baudrates[baudrate];
3350 if ((tiosp->c_cflag & CBAUD) == B38400) {
3351 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3353 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3355 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3357 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3359 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3360 baudrate = (portp->baud_base / portp->custom_divisor);
3362 if (baudrate > STL_CD1400MAXBAUD)
3363 baudrate = STL_CD1400MAXBAUD;
3366 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3367 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
3371 div = (unsigned char) clkdiv;
3375 * Check what form of modem signaling is required and set it up.
3377 if ((tiosp->c_cflag & CLOCAL) == 0) {
3380 sreron |= SRER_MODEM;
3381 portp->flags |= ASYNC_CHECK_CD;
3383 portp->flags &= ~ASYNC_CHECK_CD;
3387 * Setup cd1400 enhanced modes if we can. In particular we want to
3388 * handle as much of the flow control as possible automatically. As
3389 * well as saving a few CPU cycles it will also greatly improve flow
3390 * control reliability.
3392 if (tiosp->c_iflag & IXON) {
3395 if (tiosp->c_iflag & IXANY)
3399 if (tiosp->c_cflag & CRTSCTS) {
3401 mcor1 |= FIFO_RTSTHRESHOLD;
3405 * All cd1400 register values calculated so go through and set
3410 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3411 portp->portnr, portp->panelnr, portp->brdnr);
3412 printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3413 cor1, cor2, cor3, cor4, cor5);
3414 printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3415 mcor1, mcor2, rtpr, sreron, sreroff);
3416 printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3417 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3418 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3419 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3424 BRDENABLE(portp->brdnr, portp->pagenr);
3425 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3426 srer = stl_cd1400getreg(portp, SRER);
3427 stl_cd1400setreg(portp, SRER, 0);
3428 if (stl_cd1400updatereg(portp, COR1, cor1))
3430 if (stl_cd1400updatereg(portp, COR2, cor2))
3432 if (stl_cd1400updatereg(portp, COR3, cor3))
3435 stl_cd1400ccrwait(portp);
3436 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3438 stl_cd1400setreg(portp, COR4, cor4);
3439 stl_cd1400setreg(portp, COR5, cor5);
3440 stl_cd1400setreg(portp, MCOR1, mcor1);
3441 stl_cd1400setreg(portp, MCOR2, mcor2);
3443 stl_cd1400setreg(portp, TCOR, clk);
3444 stl_cd1400setreg(portp, TBPR, div);
3445 stl_cd1400setreg(portp, RCOR, clk);
3446 stl_cd1400setreg(portp, RBPR, div);
3448 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3449 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3450 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3451 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3452 stl_cd1400setreg(portp, RTPR, rtpr);
3453 mcor1 = stl_cd1400getreg(portp, MSVR1);
3454 if (mcor1 & MSVR1_DCD)
3455 portp->sigs |= TIOCM_CD;
3457 portp->sigs &= ~TIOCM_CD;
3458 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3459 BRDDISABLE(portp->brdnr);
3460 restore_flags(flags);
3463 /*****************************************************************************/
3466 * Set the state of the DTR and RTS signals.
3469 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3471 unsigned char msvr1, msvr2;
3472 unsigned long flags;
3475 printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
3476 (int) portp, dtr, rts);
3488 BRDENABLE(portp->brdnr, portp->pagenr);
3489 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3491 stl_cd1400setreg(portp, MSVR2, msvr2);
3493 stl_cd1400setreg(portp, MSVR1, msvr1);
3494 BRDDISABLE(portp->brdnr);
3495 restore_flags(flags);
3498 /*****************************************************************************/
3501 * Return the state of the signals.
3504 static int stl_cd1400getsignals(stlport_t *portp)
3506 unsigned char msvr1, msvr2;
3507 unsigned long flags;
3511 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3516 BRDENABLE(portp->brdnr, portp->pagenr);
3517 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3518 msvr1 = stl_cd1400getreg(portp, MSVR1);
3519 msvr2 = stl_cd1400getreg(portp, MSVR2);
3520 BRDDISABLE(portp->brdnr);
3521 restore_flags(flags);
3524 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3525 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3526 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3527 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3529 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3530 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3537 /*****************************************************************************/
3540 * Enable/Disable the Transmitter and/or Receiver.
3543 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3546 unsigned long flags;
3549 printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3550 (int) portp, rx, tx);
3555 ccr |= CCR_TXDISABLE;
3557 ccr |= CCR_TXENABLE;
3559 ccr |= CCR_RXDISABLE;
3561 ccr |= CCR_RXENABLE;
3565 BRDENABLE(portp->brdnr, portp->pagenr);
3566 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3567 stl_cd1400ccrwait(portp);
3568 stl_cd1400setreg(portp, CCR, ccr);
3569 stl_cd1400ccrwait(portp);
3570 BRDDISABLE(portp->brdnr);
3571 restore_flags(flags);
3574 /*****************************************************************************/
3577 * Start/stop the Transmitter and/or Receiver.
3580 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3582 unsigned char sreron, sreroff;
3583 unsigned long flags;
3586 printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3587 (int) portp, rx, tx);
3593 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3595 sreron |= SRER_TXDATA;
3597 sreron |= SRER_TXEMPTY;
3599 sreroff |= SRER_RXDATA;
3601 sreron |= SRER_RXDATA;
3605 BRDENABLE(portp->brdnr, portp->pagenr);
3606 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3607 stl_cd1400setreg(portp, SRER,
3608 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3609 BRDDISABLE(portp->brdnr);
3611 set_bit(ASYI_TXBUSY, &portp->istate);
3612 restore_flags(flags);
3615 /*****************************************************************************/
3618 * Disable all interrupts from this port.
3621 static void stl_cd1400disableintrs(stlport_t *portp)
3623 unsigned long flags;
3626 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3630 BRDENABLE(portp->brdnr, portp->pagenr);
3631 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3632 stl_cd1400setreg(portp, SRER, 0);
3633 BRDDISABLE(portp->brdnr);
3634 restore_flags(flags);
3637 /*****************************************************************************/
3639 static void stl_cd1400sendbreak(stlport_t *portp, int len)
3641 unsigned long flags;
3644 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
3649 BRDENABLE(portp->brdnr, portp->pagenr);
3650 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3651 stl_cd1400setreg(portp, SRER,
3652 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3654 BRDDISABLE(portp->brdnr);
3655 portp->brklen = len;
3657 portp->stats.txbreaks++;
3658 restore_flags(flags);
3661 /*****************************************************************************/
3664 * Take flow control actions...
3667 static void stl_cd1400flowctrl(stlport_t *portp, int state)
3669 struct tty_struct *tty;
3670 unsigned long flags;
3673 printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp, state);
3676 if (portp == (stlport_t *) NULL)
3679 if (tty == (struct tty_struct *) NULL)
3684 BRDENABLE(portp->brdnr, portp->pagenr);
3685 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3688 if (tty->termios->c_iflag & IXOFF) {
3689 stl_cd1400ccrwait(portp);
3690 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3691 portp->stats.rxxon++;
3692 stl_cd1400ccrwait(portp);
3695 * Question: should we return RTS to what it was before? It may
3696 * have been set by an ioctl... Suppose not, since if you have
3697 * hardware flow control set then it is pretty silly to go and
3698 * set the RTS line by hand.
3700 if (tty->termios->c_cflag & CRTSCTS) {
3701 stl_cd1400setreg(portp, MCOR1,
3702 (stl_cd1400getreg(portp, MCOR1) |
3703 FIFO_RTSTHRESHOLD));
3704 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3705 portp->stats.rxrtson++;
3708 if (tty->termios->c_iflag & IXOFF) {
3709 stl_cd1400ccrwait(portp);
3710 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3711 portp->stats.rxxoff++;
3712 stl_cd1400ccrwait(portp);
3714 if (tty->termios->c_cflag & CRTSCTS) {
3715 stl_cd1400setreg(portp, MCOR1,
3716 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3717 stl_cd1400setreg(portp, MSVR2, 0);
3718 portp->stats.rxrtsoff++;
3722 BRDDISABLE(portp->brdnr);
3723 restore_flags(flags);
3726 /*****************************************************************************/
3729 * Send a flow control character...
3732 static void stl_cd1400sendflow(stlport_t *portp, int state)
3734 struct tty_struct *tty;
3735 unsigned long flags;
3738 printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp, state);
3741 if (portp == (stlport_t *) NULL)
3744 if (tty == (struct tty_struct *) NULL)
3749 BRDENABLE(portp->brdnr, portp->pagenr);
3750 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3752 stl_cd1400ccrwait(portp);
3753 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3754 portp->stats.rxxon++;
3755 stl_cd1400ccrwait(portp);
3757 stl_cd1400ccrwait(portp);
3758 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3759 portp->stats.rxxoff++;
3760 stl_cd1400ccrwait(portp);
3762 BRDDISABLE(portp->brdnr);
3763 restore_flags(flags);
3766 /*****************************************************************************/
3768 static void stl_cd1400flush(stlport_t *portp)
3770 unsigned long flags;
3773 printk("stl_cd1400flush(portp=%x)\n", (int) portp);
3776 if (portp == (stlport_t *) NULL)
3781 BRDENABLE(portp->brdnr, portp->pagenr);
3782 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3783 stl_cd1400ccrwait(portp);
3784 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3785 stl_cd1400ccrwait(portp);
3786 portp->tx.tail = portp->tx.head;
3787 BRDDISABLE(portp->brdnr);
3788 restore_flags(flags);
3791 /*****************************************************************************/
3794 * Return the current state of data flow on this port. This is only
3795 * really interresting when determining if data has fully completed
3796 * transmission or not... This is easy for the cd1400, it accurately
3797 * maintains the busy port flag.
3800 static int stl_cd1400datastate(stlport_t *portp)
3803 printk("stl_cd1400datastate(portp=%x)\n", (int) portp);
3806 if (portp == (stlport_t *) NULL)
3809 return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
3812 /*****************************************************************************/
3815 * Interrupt service routine for cd1400 EasyIO boards.
3818 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3820 unsigned char svrtype;
3823 printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
3824 (int) panelp, iobase);
3828 svrtype = inb(iobase + EREG_DATA);
3829 if (panelp->nrports > 4) {
3830 outb((SVRR + 0x80), iobase);
3831 svrtype |= inb(iobase + EREG_DATA);
3834 if (svrtype & SVRR_RX)
3835 stl_cd1400rxisr(panelp, iobase);
3836 else if (svrtype & SVRR_TX)
3837 stl_cd1400txisr(panelp, iobase);
3838 else if (svrtype & SVRR_MDM)
3839 stl_cd1400mdmisr(panelp, iobase);
3842 /*****************************************************************************/
3845 * Interrupt service routine for cd1400 panels.
3848 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
3850 unsigned char svrtype;
3853 printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
3858 svrtype = inb(iobase + EREG_DATA);
3859 outb((SVRR + 0x80), iobase);
3860 svrtype |= inb(iobase + EREG_DATA);
3861 if (svrtype & SVRR_RX)
3862 stl_cd1400rxisr(panelp, iobase);
3863 else if (svrtype & SVRR_TX)
3864 stl_cd1400txisr(panelp, iobase);
3865 else if (svrtype & SVRR_MDM)
3866 stl_cd1400mdmisr(panelp, iobase);
3870 /*****************************************************************************/
3873 * Unfortunately we need to handle breaks in the TX data stream, since
3874 * this is the only way to generate them on the cd1400.
3877 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr)
3879 if (portp->brklen == 1) {
3880 outb((COR2 + portp->uartaddr), ioaddr);
3881 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
3882 (ioaddr + EREG_DATA));
3883 outb((TDR + portp->uartaddr), ioaddr);
3884 outb(ETC_CMD, (ioaddr + EREG_DATA));
3885 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
3886 outb((SRER + portp->uartaddr), ioaddr);
3887 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
3888 (ioaddr + EREG_DATA));
3890 } else if (portp->brklen > 1) {
3891 outb((TDR + portp->uartaddr), ioaddr);
3892 outb(ETC_CMD, (ioaddr + EREG_DATA));
3893 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
3897 outb((COR2 + portp->uartaddr), ioaddr);
3898 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
3899 (ioaddr + EREG_DATA));
3905 /*****************************************************************************/
3908 * Transmit interrupt handler. This has gotta be fast! Handling TX
3909 * chars is pretty simple, stuff as many as possible from the TX buffer
3910 * into the cd1400 FIFO. Must also handle TX breaks here, since they
3911 * are embedded as commands in the data stream. Oh no, had to use a goto!
3912 * This could be optimized more, will do when I get time...
3913 * In practice it is possible that interrupts are enabled but that the
3914 * port has been hung up. Need to handle not having any TX buffer here,
3915 * this is done by using the side effect that head and tail will also
3916 * be NULL if the buffer has been freed.
3919 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
3924 unsigned char ioack, srer;
3927 printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
3930 ioack = inb(ioaddr + EREG_TXACK);
3931 if (((ioack & panelp->ackmask) != 0) ||
3932 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
3933 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
3936 portp = panelp->ports[(ioack >> 3)];
3939 * Unfortunately we need to handle breaks in the data stream, since
3940 * this is the only way to generate them on the cd1400. Do it now if
3941 * a break is to be sent.
3943 if (portp->brklen != 0)
3944 if (stl_cd1400breakisr(portp, ioaddr))
3947 head = portp->tx.head;
3948 tail = portp->tx.tail;
3949 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
3950 if ((len == 0) || ((len < STL_TXBUFLOW) &&
3951 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
3952 set_bit(ASYI_TXLOW, &portp->istate);
3953 schedule_work(&portp->tqueue);
3957 outb((SRER + portp->uartaddr), ioaddr);
3958 srer = inb(ioaddr + EREG_DATA);
3959 if (srer & SRER_TXDATA) {
3960 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
3962 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
3963 clear_bit(ASYI_TXBUSY, &portp->istate);
3965 outb(srer, (ioaddr + EREG_DATA));
3967 len = MIN(len, CD1400_TXFIFOSIZE);
3968 portp->stats.txtotal += len;
3969 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
3970 outb((TDR + portp->uartaddr), ioaddr);
3971 outsb((ioaddr + EREG_DATA), tail, stlen);
3974 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
3975 tail = portp->tx.buf;
3977 outsb((ioaddr + EREG_DATA), tail, len);
3980 portp->tx.tail = tail;
3984 outb((EOSRR + portp->uartaddr), ioaddr);
3985 outb(0, (ioaddr + EREG_DATA));
3988 /*****************************************************************************/
3991 * Receive character interrupt handler. Determine if we have good chars
3992 * or bad chars and then process appropriately. Good chars are easy
3993 * just shove the lot into the RX buffer and set all status byte to 0.
3994 * If a bad RX char then process as required. This routine needs to be
3995 * fast! In practice it is possible that we get an interrupt on a port
3996 * that is closed. This can happen on hangups - since they completely
3997 * shutdown a port not in user context. Need to handle this case.
4000 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
4003 struct tty_struct *tty;
4004 unsigned int ioack, len, buflen;
4005 unsigned char status;
4009 printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
4012 ioack = inb(ioaddr + EREG_RXACK);
4013 if ((ioack & panelp->ackmask) != 0) {
4014 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4017 portp = panelp->ports[(ioack >> 3)];
4020 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
4021 outb((RDCR + portp->uartaddr), ioaddr);
4022 len = inb(ioaddr + EREG_DATA);
4023 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
4024 len = MIN(len, sizeof(stl_unwanted));
4025 outb((RDSR + portp->uartaddr), ioaddr);
4026 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
4027 portp->stats.rxlost += len;
4028 portp->stats.rxtotal += len;
4030 len = MIN(len, buflen);
4033 outb((RDSR + portp->uartaddr), ioaddr);
4034 tty_prepare_flip_string(tty, &ptr, len);
4035 insb((ioaddr + EREG_DATA), ptr, len);
4036 tty_schedule_flip(tty);
4037 portp->stats.rxtotal += len;
4040 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
4041 outb((RDSR + portp->uartaddr), ioaddr);
4042 status = inb(ioaddr + EREG_DATA);
4043 ch = inb(ioaddr + EREG_DATA);
4044 if (status & ST_PARITY)
4045 portp->stats.rxparity++;
4046 if (status & ST_FRAMING)
4047 portp->stats.rxframing++;
4048 if (status & ST_OVERRUN)
4049 portp->stats.rxoverrun++;
4050 if (status & ST_BREAK)
4051 portp->stats.rxbreaks++;
4052 if (status & ST_SCHARMASK) {
4053 if ((status & ST_SCHARMASK) == ST_SCHAR1)
4054 portp->stats.txxon++;
4055 if ((status & ST_SCHARMASK) == ST_SCHAR2)
4056 portp->stats.txxoff++;
4059 if (tty != NULL && (portp->rxignoremsk & status) == 0) {
4060 if (portp->rxmarkmsk & status) {
4061 if (status & ST_BREAK) {
4063 if (portp->flags & ASYNC_SAK) {
4065 BRDENABLE(portp->brdnr, portp->pagenr);
4067 } else if (status & ST_PARITY) {
4068 status = TTY_PARITY;
4069 } else if (status & ST_FRAMING) {
4071 } else if(status & ST_OVERRUN) {
4072 status = TTY_OVERRUN;
4079 tty_insert_flip_char(tty, ch, status);
4080 tty_schedule_flip(tty);
4083 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4088 outb((EOSRR + portp->uartaddr), ioaddr);
4089 outb(0, (ioaddr + EREG_DATA));
4092 /*****************************************************************************/
4095 * Modem interrupt handler. The is called when the modem signal line
4096 * (DCD) has changed state. Leave most of the work to the off-level
4097 * processing routine.
4100 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
4107 printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp);
4110 ioack = inb(ioaddr + EREG_MDACK);
4111 if (((ioack & panelp->ackmask) != 0) ||
4112 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
4113 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
4116 portp = panelp->ports[(ioack >> 3)];
4118 outb((MISR + portp->uartaddr), ioaddr);
4119 misr = inb(ioaddr + EREG_DATA);
4120 if (misr & MISR_DCD) {
4121 set_bit(ASYI_DCDCHANGE, &portp->istate);
4122 schedule_work(&portp->tqueue);
4123 portp->stats.modem++;
4126 outb((EOSRR + portp->uartaddr), ioaddr);
4127 outb(0, (ioaddr + EREG_DATA));
4130 /*****************************************************************************/
4131 /* SC26198 HARDWARE FUNCTIONS */
4132 /*****************************************************************************/
4135 * These functions get/set/update the registers of the sc26198 UARTs.
4136 * Access to the sc26198 registers is via an address/data io port pair.
4137 * (Maybe should make this inline...)
4140 static int stl_sc26198getreg(stlport_t *portp, int regnr)
4142 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4143 return inb(portp->ioaddr + XP_DATA);
4146 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
4148 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4149 outb(value, (portp->ioaddr + XP_DATA));
4152 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
4154 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4155 if (inb(portp->ioaddr + XP_DATA) != value) {
4156 outb(value, (portp->ioaddr + XP_DATA));
4162 /*****************************************************************************/
4165 * Functions to get and set the sc26198 global registers.
4168 static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
4170 outb(regnr, (portp->ioaddr + XP_ADDR));
4171 return inb(portp->ioaddr + XP_DATA);
4175 static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
4177 outb(regnr, (portp->ioaddr + XP_ADDR));
4178 outb(value, (portp->ioaddr + XP_DATA));
4182 /*****************************************************************************/
4185 * Inbitialize the UARTs in a panel. We don't care what sort of board
4186 * these ports are on - since the port io registers are almost
4187 * identical when dealing with ports.
4190 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
4193 int nrchips, ioaddr;
4196 printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
4197 (int) brdp, (int) panelp);
4200 BRDENABLE(panelp->brdnr, panelp->pagenr);
4203 * Check that each chip is present and started up OK.
4206 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
4207 if (brdp->brdtype == BRD_ECHPCI)
4208 outb(panelp->pagenr, brdp->ioctrl);
4210 for (i = 0; (i < nrchips); i++) {
4211 ioaddr = panelp->iobase + (i * 4);
4212 outb(SCCR, (ioaddr + XP_ADDR));
4213 outb(CR_RESETALL, (ioaddr + XP_DATA));
4214 outb(TSTR, (ioaddr + XP_ADDR));
4215 if (inb(ioaddr + XP_DATA) != 0) {
4216 printk("STALLION: sc26198 not responding, "
4217 "brd=%d panel=%d chip=%d\n",
4218 panelp->brdnr, panelp->panelnr, i);
4221 chipmask |= (0x1 << i);
4222 outb(GCCR, (ioaddr + XP_ADDR));
4223 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
4224 outb(WDTRCR, (ioaddr + XP_ADDR));
4225 outb(0xff, (ioaddr + XP_DATA));
4228 BRDDISABLE(panelp->brdnr);
4232 /*****************************************************************************/
4235 * Initialize hardware specific port registers.
4238 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
4241 printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
4242 (int) brdp, (int) panelp, (int) portp);
4245 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
4246 (portp == (stlport_t *) NULL))
4249 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
4250 portp->uartaddr = (portp->portnr & 0x07) << 4;
4251 portp->pagenr = panelp->pagenr;
4254 BRDENABLE(portp->brdnr, portp->pagenr);
4255 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
4256 BRDDISABLE(portp->brdnr);
4259 /*****************************************************************************/
4262 * Set up the sc26198 registers for a port based on the termios port
4266 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4269 unsigned long flags;
4270 unsigned int baudrate;
4271 unsigned char mr0, mr1, mr2, clk;
4272 unsigned char imron, imroff, iopr, ipr;
4282 brdp = stl_brds[portp->brdnr];
4283 if (brdp == (stlbrd_t *) NULL)
4287 * Set up the RX char ignore mask with those RX error types we
4290 portp->rxignoremsk = 0;
4291 if (tiosp->c_iflag & IGNPAR)
4292 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
4294 if (tiosp->c_iflag & IGNBRK)
4295 portp->rxignoremsk |= SR_RXBREAK;
4297 portp->rxmarkmsk = SR_RXOVERRUN;
4298 if (tiosp->c_iflag & (INPCK | PARMRK))
4299 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
4300 if (tiosp->c_iflag & BRKINT)
4301 portp->rxmarkmsk |= SR_RXBREAK;
4304 * Go through the char size, parity and stop bits and set all the
4305 * option register appropriately.
4307 switch (tiosp->c_cflag & CSIZE) {
4322 if (tiosp->c_cflag & CSTOPB)
4327 if (tiosp->c_cflag & PARENB) {
4328 if (tiosp->c_cflag & PARODD)
4329 mr1 |= (MR1_PARENB | MR1_PARODD);
4331 mr1 |= (MR1_PARENB | MR1_PAREVEN);
4336 mr1 |= MR1_ERRBLOCK;
4339 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4340 * space for hardware flow control and the like. This should be set to
4343 mr2 |= MR2_RXFIFOHALF;
4346 * Calculate the baud rate timers. For now we will just assume that
4347 * the input and output baud are the same. The sc26198 has a fixed
4348 * baud rate table, so only discrete baud rates possible.
4350 baudrate = tiosp->c_cflag & CBAUD;
4351 if (baudrate & CBAUDEX) {
4352 baudrate &= ~CBAUDEX;
4353 if ((baudrate < 1) || (baudrate > 4))
4354 tiosp->c_cflag &= ~CBAUDEX;
4358 baudrate = stl_baudrates[baudrate];
4359 if ((tiosp->c_cflag & CBAUD) == B38400) {
4360 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
4362 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
4364 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
4366 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
4368 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
4369 baudrate = (portp->baud_base / portp->custom_divisor);
4371 if (baudrate > STL_SC26198MAXBAUD)
4372 baudrate = STL_SC26198MAXBAUD;
4375 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
4376 if (baudrate <= sc26198_baudtable[clk])
4382 * Check what form of modem signaling is required and set it up.
4384 if (tiosp->c_cflag & CLOCAL) {
4385 portp->flags &= ~ASYNC_CHECK_CD;
4387 iopr |= IOPR_DCDCOS;
4389 portp->flags |= ASYNC_CHECK_CD;
4393 * Setup sc26198 enhanced modes if we can. In particular we want to
4394 * handle as much of the flow control as possible automatically. As
4395 * well as saving a few CPU cycles it will also greatly improve flow
4396 * control reliability.
4398 if (tiosp->c_iflag & IXON) {
4399 mr0 |= MR0_SWFTX | MR0_SWFT;
4400 imron |= IR_XONXOFF;
4402 imroff |= IR_XONXOFF;
4404 if (tiosp->c_iflag & IXOFF)
4407 if (tiosp->c_cflag & CRTSCTS) {
4413 * All sc26198 register values calculated so go through and set
4418 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4419 portp->portnr, portp->panelnr, portp->brdnr);
4420 printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4421 printk(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4422 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4423 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4424 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4429 BRDENABLE(portp->brdnr, portp->pagenr);
4430 stl_sc26198setreg(portp, IMR, 0);
4431 stl_sc26198updatereg(portp, MR0, mr0);
4432 stl_sc26198updatereg(portp, MR1, mr1);
4433 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4434 stl_sc26198updatereg(portp, MR2, mr2);
4435 stl_sc26198updatereg(portp, IOPIOR,
4436 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
4439 stl_sc26198setreg(portp, TXCSR, clk);
4440 stl_sc26198setreg(portp, RXCSR, clk);
4443 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4444 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4446 ipr = stl_sc26198getreg(portp, IPR);
4448 portp->sigs &= ~TIOCM_CD;
4450 portp->sigs |= TIOCM_CD;
4452 portp->imr = (portp->imr & ~imroff) | imron;
4453 stl_sc26198setreg(portp, IMR, portp->imr);
4454 BRDDISABLE(portp->brdnr);
4455 restore_flags(flags);
4458 /*****************************************************************************/
4461 * Set the state of the DTR and RTS signals.
4464 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
4466 unsigned char iopioron, iopioroff;
4467 unsigned long flags;
4470 printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4471 (int) portp, dtr, rts);
4477 iopioroff |= IPR_DTR;
4479 iopioron |= IPR_DTR;
4481 iopioroff |= IPR_RTS;
4483 iopioron |= IPR_RTS;
4487 BRDENABLE(portp->brdnr, portp->pagenr);
4488 stl_sc26198setreg(portp, IOPIOR,
4489 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4490 BRDDISABLE(portp->brdnr);
4491 restore_flags(flags);
4494 /*****************************************************************************/
4497 * Return the state of the signals.
4500 static int stl_sc26198getsignals(stlport_t *portp)
4503 unsigned long flags;
4507 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
4512 BRDENABLE(portp->brdnr, portp->pagenr);
4513 ipr = stl_sc26198getreg(portp, IPR);
4514 BRDDISABLE(portp->brdnr);
4515 restore_flags(flags);
4518 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4519 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4520 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4521 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4526 /*****************************************************************************/
4529 * Enable/Disable the Transmitter and/or Receiver.
4532 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
4535 unsigned long flags;
4538 printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4539 (int) portp, rx, tx);
4542 ccr = portp->crenable;
4544 ccr &= ~CR_TXENABLE;
4548 ccr &= ~CR_RXENABLE;
4554 BRDENABLE(portp->brdnr, portp->pagenr);
4555 stl_sc26198setreg(portp, SCCR, ccr);
4556 BRDDISABLE(portp->brdnr);
4557 portp->crenable = ccr;
4558 restore_flags(flags);
4561 /*****************************************************************************/
4564 * Start/stop the Transmitter and/or Receiver.
4567 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
4570 unsigned long flags;
4573 printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4574 (int) portp, rx, tx);
4583 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4585 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4589 BRDENABLE(portp->brdnr, portp->pagenr);
4590 stl_sc26198setreg(portp, IMR, imr);
4591 BRDDISABLE(portp->brdnr);
4594 set_bit(ASYI_TXBUSY, &portp->istate);
4595 restore_flags(flags);
4598 /*****************************************************************************/
4601 * Disable all interrupts from this port.
4604 static void stl_sc26198disableintrs(stlport_t *portp)
4606 unsigned long flags;
4609 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
4614 BRDENABLE(portp->brdnr, portp->pagenr);
4616 stl_sc26198setreg(portp, IMR, 0);
4617 BRDDISABLE(portp->brdnr);
4618 restore_flags(flags);
4621 /*****************************************************************************/
4623 static void stl_sc26198sendbreak(stlport_t *portp, int len)
4625 unsigned long flags;
4628 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
4633 BRDENABLE(portp->brdnr, portp->pagenr);
4635 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4636 portp->stats.txbreaks++;
4638 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4640 BRDDISABLE(portp->brdnr);
4641 restore_flags(flags);
4644 /*****************************************************************************/
4647 * Take flow control actions...
4650 static void stl_sc26198flowctrl(stlport_t *portp, int state)
4652 struct tty_struct *tty;
4653 unsigned long flags;
4657 printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp, state);
4660 if (portp == (stlport_t *) NULL)
4663 if (tty == (struct tty_struct *) NULL)
4668 BRDENABLE(portp->brdnr, portp->pagenr);
4671 if (tty->termios->c_iflag & IXOFF) {
4672 mr0 = stl_sc26198getreg(portp, MR0);
4673 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4674 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4676 portp->stats.rxxon++;
4677 stl_sc26198wait(portp);
4678 stl_sc26198setreg(portp, MR0, mr0);
4681 * Question: should we return RTS to what it was before? It may
4682 * have been set by an ioctl... Suppose not, since if you have
4683 * hardware flow control set then it is pretty silly to go and
4684 * set the RTS line by hand.
4686 if (tty->termios->c_cflag & CRTSCTS) {
4687 stl_sc26198setreg(portp, MR1,
4688 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4689 stl_sc26198setreg(portp, IOPIOR,
4690 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4691 portp->stats.rxrtson++;
4694 if (tty->termios->c_iflag & IXOFF) {
4695 mr0 = stl_sc26198getreg(portp, MR0);
4696 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4697 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4699 portp->stats.rxxoff++;
4700 stl_sc26198wait(portp);
4701 stl_sc26198setreg(portp, MR0, mr0);
4703 if (tty->termios->c_cflag & CRTSCTS) {
4704 stl_sc26198setreg(portp, MR1,
4705 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4706 stl_sc26198setreg(portp, IOPIOR,
4707 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4708 portp->stats.rxrtsoff++;
4712 BRDDISABLE(portp->brdnr);
4713 restore_flags(flags);
4716 /*****************************************************************************/
4719 * Send a flow control character.
4722 static void stl_sc26198sendflow(stlport_t *portp, int state)
4724 struct tty_struct *tty;
4725 unsigned long flags;
4729 printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp, state);
4732 if (portp == (stlport_t *) NULL)
4735 if (tty == (struct tty_struct *) NULL)
4740 BRDENABLE(portp->brdnr, portp->pagenr);
4742 mr0 = stl_sc26198getreg(portp, MR0);
4743 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4744 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4746 portp->stats.rxxon++;
4747 stl_sc26198wait(portp);
4748 stl_sc26198setreg(portp, MR0, mr0);
4750 mr0 = stl_sc26198getreg(portp, MR0);
4751 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4752 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4754 portp->stats.rxxoff++;
4755 stl_sc26198wait(portp);
4756 stl_sc26198setreg(portp, MR0, mr0);
4758 BRDDISABLE(portp->brdnr);
4759 restore_flags(flags);
4762 /*****************************************************************************/
4764 static void stl_sc26198flush(stlport_t *portp)
4766 unsigned long flags;
4769 printk("stl_sc26198flush(portp=%x)\n", (int) portp);
4772 if (portp == (stlport_t *) NULL)
4777 BRDENABLE(portp->brdnr, portp->pagenr);
4778 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4779 stl_sc26198setreg(portp, SCCR, portp->crenable);
4780 BRDDISABLE(portp->brdnr);
4781 portp->tx.tail = portp->tx.head;
4782 restore_flags(flags);
4785 /*****************************************************************************/
4788 * Return the current state of data flow on this port. This is only
4789 * really interresting when determining if data has fully completed
4790 * transmission or not... The sc26198 interrupt scheme cannot
4791 * determine when all data has actually drained, so we need to
4792 * check the port statusy register to be sure.
4795 static int stl_sc26198datastate(stlport_t *portp)
4797 unsigned long flags;
4801 printk("stl_sc26198datastate(portp=%x)\n", (int) portp);
4804 if (portp == (stlport_t *) NULL)
4806 if (test_bit(ASYI_TXBUSY, &portp->istate))
4811 BRDENABLE(portp->brdnr, portp->pagenr);
4812 sr = stl_sc26198getreg(portp, SR);
4813 BRDDISABLE(portp->brdnr);
4814 restore_flags(flags);
4816 return (sr & SR_TXEMPTY) ? 0 : 1;
4819 /*****************************************************************************/
4822 * Delay for a small amount of time, to give the sc26198 a chance
4823 * to process a command...
4826 static void stl_sc26198wait(stlport_t *portp)
4831 printk("stl_sc26198wait(portp=%x)\n", (int) portp);
4834 if (portp == (stlport_t *) NULL)
4837 for (i = 0; (i < 20); i++)
4838 stl_sc26198getglobreg(portp, TSTR);
4841 /*****************************************************************************/
4844 * If we are TX flow controlled and in IXANY mode then we may
4845 * need to unflow control here. We gotta do this because of the
4846 * automatic flow control modes of the sc26198.
4849 static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty)
4853 mr0 = stl_sc26198getreg(portp, MR0);
4854 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4855 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4856 stl_sc26198wait(portp);
4857 stl_sc26198setreg(portp, MR0, mr0);
4858 clear_bit(ASYI_TXFLOWED, &portp->istate);
4861 /*****************************************************************************/
4864 * Interrupt service routine for sc26198 panels.
4867 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4873 * Work around bug in sc26198 chip... Cannot have A6 address
4874 * line of UART high, else iack will be returned as 0.
4876 outb(0, (iobase + 1));
4878 iack = inb(iobase + XP_IACK);
4879 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4881 if (iack & IVR_RXDATA)
4882 stl_sc26198rxisr(portp, iack);
4883 else if (iack & IVR_TXDATA)
4884 stl_sc26198txisr(portp);
4886 stl_sc26198otherisr(portp, iack);
4889 /*****************************************************************************/
4892 * Transmit interrupt handler. This has gotta be fast! Handling TX
4893 * chars is pretty simple, stuff as many as possible from the TX buffer
4894 * into the sc26198 FIFO.
4895 * In practice it is possible that interrupts are enabled but that the
4896 * port has been hung up. Need to handle not having any TX buffer here,
4897 * this is done by using the side effect that head and tail will also
4898 * be NULL if the buffer has been freed.
4901 static void stl_sc26198txisr(stlport_t *portp)
4903 unsigned int ioaddr;
4909 printk("stl_sc26198txisr(portp=%x)\n", (int) portp);
4912 ioaddr = portp->ioaddr;
4913 head = portp->tx.head;
4914 tail = portp->tx.tail;
4915 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4916 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4917 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4918 set_bit(ASYI_TXLOW, &portp->istate);
4919 schedule_work(&portp->tqueue);
4923 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
4924 mr0 = inb(ioaddr + XP_DATA);
4925 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4926 portp->imr &= ~IR_TXRDY;
4927 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
4928 outb(portp->imr, (ioaddr + XP_DATA));
4929 clear_bit(ASYI_TXBUSY, &portp->istate);
4931 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4932 outb(mr0, (ioaddr + XP_DATA));
4935 len = MIN(len, SC26198_TXFIFOSIZE);
4936 portp->stats.txtotal += len;
4937 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4938 outb(GTXFIFO, (ioaddr + XP_ADDR));
4939 outsb((ioaddr + XP_DATA), tail, stlen);
4942 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4943 tail = portp->tx.buf;
4945 outsb((ioaddr + XP_DATA), tail, len);
4948 portp->tx.tail = tail;
4952 /*****************************************************************************/
4955 * Receive character interrupt handler. Determine if we have good chars
4956 * or bad chars and then process appropriately. Good chars are easy
4957 * just shove the lot into the RX buffer and set all status byte to 0.
4958 * If a bad RX char then process as required. This routine needs to be
4959 * fast! In practice it is possible that we get an interrupt on a port
4960 * that is closed. This can happen on hangups - since they completely
4961 * shutdown a port not in user context. Need to handle this case.
4964 static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
4966 struct tty_struct *tty;
4967 unsigned int len, buflen, ioaddr;
4970 printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
4974 ioaddr = portp->ioaddr;
4975 outb(GIBCR, (ioaddr + XP_ADDR));
4976 len = inb(ioaddr + XP_DATA) + 1;
4978 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
4979 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
4980 len = MIN(len, sizeof(stl_unwanted));
4981 outb(GRXFIFO, (ioaddr + XP_ADDR));
4982 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4983 portp->stats.rxlost += len;
4984 portp->stats.rxtotal += len;
4986 len = MIN(len, buflen);
4989 outb(GRXFIFO, (ioaddr + XP_ADDR));
4990 tty_prepare_flip_string(tty, &ptr, len);
4991 insb((ioaddr + XP_DATA), ptr, len);
4992 tty_schedule_flip(tty);
4993 portp->stats.rxtotal += len;
4997 stl_sc26198rxbadchars(portp);
5001 * If we are TX flow controlled and in IXANY mode then we may need
5002 * to unflow control here. We gotta do this because of the automatic
5003 * flow control modes of the sc26198.
5005 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
5006 if ((tty != (struct tty_struct *) NULL) &&
5007 (tty->termios != (struct termios *) NULL) &&
5008 (tty->termios->c_iflag & IXANY)) {
5009 stl_sc26198txunflow(portp, tty);
5014 /*****************************************************************************/
5017 * Process an RX bad character.
5020 static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch)
5022 struct tty_struct *tty;
5023 unsigned int ioaddr;
5026 ioaddr = portp->ioaddr;
5028 if (status & SR_RXPARITY)
5029 portp->stats.rxparity++;
5030 if (status & SR_RXFRAMING)
5031 portp->stats.rxframing++;
5032 if (status & SR_RXOVERRUN)
5033 portp->stats.rxoverrun++;
5034 if (status & SR_RXBREAK)
5035 portp->stats.rxbreaks++;
5037 if ((tty != (struct tty_struct *) NULL) &&
5038 ((portp->rxignoremsk & status) == 0)) {
5039 if (portp->rxmarkmsk & status) {
5040 if (status & SR_RXBREAK) {
5042 if (portp->flags & ASYNC_SAK) {
5044 BRDENABLE(portp->brdnr, portp->pagenr);
5046 } else if (status & SR_RXPARITY) {
5047 status = TTY_PARITY;
5048 } else if (status & SR_RXFRAMING) {
5050 } else if(status & SR_RXOVERRUN) {
5051 status = TTY_OVERRUN;
5059 tty_insert_flip_char(tty, ch, status);
5060 tty_schedule_flip(tty);
5063 portp->stats.rxtotal++;
5067 /*****************************************************************************/
5070 * Process all characters in the RX FIFO of the UART. Check all char
5071 * status bytes as well, and process as required. We need to check
5072 * all bytes in the FIFO, in case some more enter the FIFO while we
5073 * are here. To get the exact character error type we need to switch
5074 * into CHAR error mode (that is why we need to make sure we empty
5078 static void stl_sc26198rxbadchars(stlport_t *portp)
5080 unsigned char status, mr1;
5084 * To get the precise error type for each character we must switch
5085 * back into CHAR error mode.
5087 mr1 = stl_sc26198getreg(portp, MR1);
5088 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
5090 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
5091 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
5092 ch = stl_sc26198getreg(portp, RXFIFO);
5093 stl_sc26198rxbadch(portp, status, ch);
5097 * To get correct interrupt class we must switch back into BLOCK
5100 stl_sc26198setreg(portp, MR1, mr1);
5103 /*****************************************************************************/
5106 * Other interrupt handler. This includes modem signals, flow
5107 * control actions, etc. Most stuff is left to off-level interrupt
5111 static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
5113 unsigned char cir, ipr, xisr;
5116 printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
5119 cir = stl_sc26198getglobreg(portp, CIR);
5121 switch (cir & CIR_SUBTYPEMASK) {
5123 ipr = stl_sc26198getreg(portp, IPR);
5124 if (ipr & IPR_DCDCHANGE) {
5125 set_bit(ASYI_DCDCHANGE, &portp->istate);
5126 schedule_work(&portp->tqueue);
5127 portp->stats.modem++;
5130 case CIR_SUBXONXOFF:
5131 xisr = stl_sc26198getreg(portp, XISR);
5132 if (xisr & XISR_RXXONGOT) {
5133 set_bit(ASYI_TXFLOWED, &portp->istate);
5134 portp->stats.txxoff++;
5136 if (xisr & XISR_RXXOFFGOT) {
5137 clear_bit(ASYI_TXFLOWED, &portp->istate);
5138 portp->stats.txxon++;
5142 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
5143 stl_sc26198rxbadchars(portp);
5150 /*****************************************************************************/