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/devfs_fs_kernel.h>
44 #include <linux/device.h>
45 #include <linux/delay.h>
48 #include <asm/uaccess.h>
51 #include <linux/pci.h>
54 /*****************************************************************************/
57 * Define different board types. Use the standard Stallion "assigned"
58 * board numbers. Boards supported in this driver are abbreviated as
59 * EIO = EasyIO and ECH = EasyConnection 8/32.
65 #define BRD_ECH64PCI 27
66 #define BRD_EASYIOPCI 28
69 * Define a configuration structure to hold the board configuration.
70 * Need to set this up in the code (for now) with the boards that are
71 * to be configured into the system. This is what needs to be modified
72 * when adding/removing/modifying boards. Each line entry in the
73 * stl_brdconf[] array is a board. Each line contains io/irq/memory
74 * ranges for that board (as well as what type of board it is).
76 * { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
77 * This line would configure an EasyIO board (4 or 8, no difference),
78 * at io address 2a0 and irq 10.
80 * { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
81 * This line will configure an EasyConnection 8/32 board at primary io
82 * address 2a8, secondary io address 280 and irq 12.
83 * Enter as many lines into this array as you want (only the first 4
84 * will actually be used!). Any combination of EasyIO and EasyConnection
85 * boards can be specified. EasyConnection 8/32 boards can share their
86 * secondary io addresses between each other.
88 * NOTE: there is no need to put any entries in this table for PCI
89 * boards. They will be found automatically by the driver - provided
90 * PCI BIOS32 support is compiled into the kernel.
97 unsigned long memaddr;
102 static stlconf_t stl_brdconf[] = {
103 /*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
106 static int stl_nrbrds = ARRAY_SIZE(stl_brdconf);
108 /*****************************************************************************/
111 * Define some important driver characteristics. Device major numbers
112 * allocated as per Linux Device Registry.
114 #ifndef STL_SIOMEMMAJOR
115 #define STL_SIOMEMMAJOR 28
117 #ifndef STL_SERIALMAJOR
118 #define STL_SERIALMAJOR 24
120 #ifndef STL_CALLOUTMAJOR
121 #define STL_CALLOUTMAJOR 25
125 * Set the TX buffer size. Bigger is better, but we don't want
126 * to chew too much memory with buffers!
128 #define STL_TXBUFLOW 512
129 #define STL_TXBUFSIZE 4096
131 /*****************************************************************************/
134 * Define our local driver identity first. Set up stuff to deal with
135 * all the local structures required by a serial tty driver.
137 static char *stl_drvtitle = "Stallion Multiport Serial Driver";
138 static char *stl_drvname = "stallion";
139 static char *stl_drvversion = "5.6.0";
141 static struct tty_driver *stl_serial;
144 * We will need to allocate a temporary write buffer for chars that
145 * come direct from user space. The problem is that a copy from user
146 * space might cause a page fault (typically on a system that is
147 * swapping!). All ports will share one buffer - since if the system
148 * is already swapping a shared buffer won't make things any worse.
150 static char *stl_tmpwritebuf;
153 * Define a local default termios struct. All ports will be created
154 * with this termios initially. Basically all it defines is a raw port
155 * at 9600, 8 data bits, 1 stop bit.
157 static struct termios stl_deftermios = {
158 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
163 * Define global stats structures. Not used often, and can be
164 * re-used for each stats call.
166 static comstats_t stl_comstats;
167 static combrd_t stl_brdstats;
168 static stlbrd_t stl_dummybrd;
169 static stlport_t stl_dummyport;
172 * Define global place to put buffer overflow characters.
174 static char stl_unwanted[SC26198_RXFIFOSIZE];
176 /*****************************************************************************/
178 static stlbrd_t *stl_brds[STL_MAXBRDS];
181 * Per board state flags. Used with the state field of the board struct.
182 * Not really much here!
184 #define BRD_FOUND 0x1
187 * Define the port structure istate flags. These set of flags are
188 * modified at interrupt time - so setting and reseting them needs
189 * to be atomic. Use the bit clear/setting routines for this.
191 #define ASYI_TXBUSY 1
193 #define ASYI_DCDCHANGE 3
194 #define ASYI_TXFLOWED 4
197 * Define an array of board names as printable strings. Handy for
198 * referencing boards when printing trace and stuff.
200 static char *stl_brdnames[] = {
232 /*****************************************************************************/
235 * Define some string labels for arguments passed from the module
236 * load line. These allow for easy board definitions, and easy
237 * modification of the io, memory and irq resoucres.
239 static int stl_nargs = 0;
240 static char *board0[4];
241 static char *board1[4];
242 static char *board2[4];
243 static char *board3[4];
245 static char **stl_brdsp[] = {
253 * Define a set of common board names, and types. This is used to
254 * parse any module arguments.
257 typedef struct stlbrdtype {
262 static stlbrdtype_t stl_brdstr[] = {
263 { "easyio", BRD_EASYIO },
264 { "eio", BRD_EASYIO },
265 { "20", BRD_EASYIO },
266 { "ec8/32", BRD_ECH },
267 { "ec8/32-at", BRD_ECH },
268 { "ec8/32-isa", BRD_ECH },
270 { "echat", BRD_ECH },
272 { "ec8/32-mc", BRD_ECHMC },
273 { "ec8/32-mca", BRD_ECHMC },
274 { "echmc", BRD_ECHMC },
275 { "echmca", BRD_ECHMC },
277 { "ec8/32-pc", BRD_ECHPCI },
278 { "ec8/32-pci", BRD_ECHPCI },
279 { "26", BRD_ECHPCI },
280 { "ec8/64-pc", BRD_ECH64PCI },
281 { "ec8/64-pci", BRD_ECH64PCI },
282 { "ech-pci", BRD_ECH64PCI },
283 { "echpci", BRD_ECH64PCI },
284 { "echpc", BRD_ECH64PCI },
285 { "27", BRD_ECH64PCI },
286 { "easyio-pc", BRD_EASYIOPCI },
287 { "easyio-pci", BRD_EASYIOPCI },
288 { "eio-pci", BRD_EASYIOPCI },
289 { "eiopci", BRD_EASYIOPCI },
290 { "28", BRD_EASYIOPCI },
294 * Define the module agruments.
296 MODULE_AUTHOR("Greg Ungerer");
297 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
298 MODULE_LICENSE("GPL");
300 module_param_array(board0, charp, &stl_nargs, 0);
301 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
302 module_param_array(board1, charp, &stl_nargs, 0);
303 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
304 module_param_array(board2, charp, &stl_nargs, 0);
305 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
306 module_param_array(board3, charp, &stl_nargs, 0);
307 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
309 /*****************************************************************************/
312 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
313 * to the directly accessible io ports of these boards (not the uarts -
314 * they are in cd1400.h and sc26198.h).
316 #define EIO_8PORTRS 0x04
317 #define EIO_4PORTRS 0x05
318 #define EIO_8PORTDI 0x00
319 #define EIO_8PORTM 0x06
321 #define EIO_IDBITMASK 0x07
323 #define EIO_BRDMASK 0xf0
326 #define ID_BRD16 0x30
328 #define EIO_INTRPEND 0x08
329 #define EIO_INTEDGE 0x00
330 #define EIO_INTLEVEL 0x08
334 #define ECH_IDBITMASK 0xe0
335 #define ECH_BRDENABLE 0x08
336 #define ECH_BRDDISABLE 0x00
337 #define ECH_INTENABLE 0x01
338 #define ECH_INTDISABLE 0x00
339 #define ECH_INTLEVEL 0x02
340 #define ECH_INTEDGE 0x00
341 #define ECH_INTRPEND 0x01
342 #define ECH_BRDRESET 0x01
344 #define ECHMC_INTENABLE 0x01
345 #define ECHMC_BRDRESET 0x02
347 #define ECH_PNLSTATUS 2
348 #define ECH_PNL16PORT 0x20
349 #define ECH_PNLIDMASK 0x07
350 #define ECH_PNLXPID 0x40
351 #define ECH_PNLINTRPEND 0x80
353 #define ECH_ADDR2MASK 0x1e0
356 * Define the vector mapping bits for the programmable interrupt board
357 * hardware. These bits encode the interrupt for the board to use - it
358 * is software selectable (except the EIO-8M).
360 static unsigned char stl_vecmap[] = {
361 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
362 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
366 * Set up enable and disable macros for the ECH boards. They require
367 * the secondary io address space to be activated and deactivated.
368 * This way all ECH boards can share their secondary io region.
369 * If this is an ECH-PCI board then also need to set the page pointer
370 * to point to the correct page.
372 #define BRDENABLE(brdnr,pagenr) \
373 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
374 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
375 stl_brds[(brdnr)]->ioctrl); \
376 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
377 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
379 #define BRDDISABLE(brdnr) \
380 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
381 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
382 stl_brds[(brdnr)]->ioctrl);
384 #define STL_CD1400MAXBAUD 230400
385 #define STL_SC26198MAXBAUD 460800
387 #define STL_BAUDBASE 115200
388 #define STL_CLOSEDELAY (5 * HZ / 10)
390 /*****************************************************************************/
395 * Define the Stallion PCI vendor and device IDs.
397 #ifndef PCI_VENDOR_ID_STALLION
398 #define PCI_VENDOR_ID_STALLION 0x124d
400 #ifndef PCI_DEVICE_ID_ECHPCI832
401 #define PCI_DEVICE_ID_ECHPCI832 0x0000
403 #ifndef PCI_DEVICE_ID_ECHPCI864
404 #define PCI_DEVICE_ID_ECHPCI864 0x0002
406 #ifndef PCI_DEVICE_ID_EIOPCI
407 #define PCI_DEVICE_ID_EIOPCI 0x0003
411 * Define structure to hold all Stallion PCI boards.
413 typedef struct stlpcibrd {
414 unsigned short vendid;
415 unsigned short devid;
419 static stlpcibrd_t stl_pcibrds[] = {
420 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864, BRD_ECH64PCI },
421 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI, BRD_EASYIOPCI },
422 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832, BRD_ECHPCI },
423 { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
426 static int stl_nrpcibrds = ARRAY_SIZE(stl_pcibrds);
430 /*****************************************************************************/
433 * Define macros to extract a brd/port number from a minor number.
435 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
436 #define MINOR2PORT(min) ((min) & 0x3f)
439 * Define a baud rate table that converts termios baud rate selector
440 * into the actual baud rate value. All baud rate calculations are
441 * based on the actual baud rate required.
443 static unsigned int stl_baudrates[] = {
444 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
445 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
449 * Define some handy local macros...
452 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
455 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
457 /*****************************************************************************/
460 * Declare all those functions in this driver!
463 static void stl_argbrds(void);
464 static int stl_parsebrd(stlconf_t *confp, char **argp);
466 static unsigned long stl_atol(char *str);
468 static int stl_init(void);
469 static int stl_open(struct tty_struct *tty, struct file *filp);
470 static void stl_close(struct tty_struct *tty, struct file *filp);
471 static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count);
472 static void stl_putchar(struct tty_struct *tty, unsigned char ch);
473 static void stl_flushchars(struct tty_struct *tty);
474 static int stl_writeroom(struct tty_struct *tty);
475 static int stl_charsinbuffer(struct tty_struct *tty);
476 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
477 static void stl_settermios(struct tty_struct *tty, struct termios *old);
478 static void stl_throttle(struct tty_struct *tty);
479 static void stl_unthrottle(struct tty_struct *tty);
480 static void stl_stop(struct tty_struct *tty);
481 static void stl_start(struct tty_struct *tty);
482 static void stl_flushbuffer(struct tty_struct *tty);
483 static void stl_breakctl(struct tty_struct *tty, int state);
484 static void stl_waituntilsent(struct tty_struct *tty, int timeout);
485 static void stl_sendxchar(struct tty_struct *tty, char ch);
486 static void stl_hangup(struct tty_struct *tty);
487 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
488 static int stl_portinfo(stlport_t *portp, int portnr, char *pos);
489 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data);
491 static int stl_brdinit(stlbrd_t *brdp);
492 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
493 static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp);
494 static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp);
495 static int stl_getbrdstats(combrd_t __user *bp);
496 static int stl_getportstats(stlport_t *portp, comstats_t __user *cp);
497 static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp);
498 static int stl_getportstruct(stlport_t __user *arg);
499 static int stl_getbrdstruct(stlbrd_t __user *arg);
500 static int stl_waitcarrier(stlport_t *portp, struct file *filp);
501 static int stl_eiointr(stlbrd_t *brdp);
502 static int stl_echatintr(stlbrd_t *brdp);
503 static int stl_echmcaintr(stlbrd_t *brdp);
504 static int stl_echpciintr(stlbrd_t *brdp);
505 static int stl_echpci64intr(stlbrd_t *brdp);
506 static void stl_offintr(void *private);
507 static stlbrd_t *stl_allocbrd(void);
508 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
510 static inline int stl_initbrds(void);
511 static inline int stl_initeio(stlbrd_t *brdp);
512 static inline int stl_initech(stlbrd_t *brdp);
513 static inline int stl_getbrdnr(void);
516 static inline int stl_findpcibrds(void);
517 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp);
521 * CD1400 uart specific handling functions.
523 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value);
524 static int stl_cd1400getreg(stlport_t *portp, int regnr);
525 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value);
526 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
527 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
528 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp);
529 static int stl_cd1400getsignals(stlport_t *portp);
530 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts);
531 static void stl_cd1400ccrwait(stlport_t *portp);
532 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx);
533 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx);
534 static void stl_cd1400disableintrs(stlport_t *portp);
535 static void stl_cd1400sendbreak(stlport_t *portp, int len);
536 static void stl_cd1400flowctrl(stlport_t *portp, int state);
537 static void stl_cd1400sendflow(stlport_t *portp, int state);
538 static void stl_cd1400flush(stlport_t *portp);
539 static int stl_cd1400datastate(stlport_t *portp);
540 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase);
541 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase);
542 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr);
543 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr);
544 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr);
546 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr);
549 * SC26198 uart specific handling functions.
551 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value);
552 static int stl_sc26198getreg(stlport_t *portp, int regnr);
553 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value);
554 static int stl_sc26198getglobreg(stlport_t *portp, int regnr);
555 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
556 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
557 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp);
558 static int stl_sc26198getsignals(stlport_t *portp);
559 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts);
560 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx);
561 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx);
562 static void stl_sc26198disableintrs(stlport_t *portp);
563 static void stl_sc26198sendbreak(stlport_t *portp, int len);
564 static void stl_sc26198flowctrl(stlport_t *portp, int state);
565 static void stl_sc26198sendflow(stlport_t *portp, int state);
566 static void stl_sc26198flush(stlport_t *portp);
567 static int stl_sc26198datastate(stlport_t *portp);
568 static void stl_sc26198wait(stlport_t *portp);
569 static void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty);
570 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase);
571 static void stl_sc26198txisr(stlport_t *port);
572 static void stl_sc26198rxisr(stlport_t *port, unsigned int iack);
573 static void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch);
574 static void stl_sc26198rxbadchars(stlport_t *portp);
575 static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
577 /*****************************************************************************/
580 * Generic UART support structure.
582 typedef struct uart {
583 int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp);
584 void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
585 void (*setport)(stlport_t *portp, struct termios *tiosp);
586 int (*getsignals)(stlport_t *portp);
587 void (*setsignals)(stlport_t *portp, int dtr, int rts);
588 void (*enablerxtx)(stlport_t *portp, int rx, int tx);
589 void (*startrxtx)(stlport_t *portp, int rx, int tx);
590 void (*disableintrs)(stlport_t *portp);
591 void (*sendbreak)(stlport_t *portp, int len);
592 void (*flowctrl)(stlport_t *portp, int state);
593 void (*sendflow)(stlport_t *portp, int state);
594 void (*flush)(stlport_t *portp);
595 int (*datastate)(stlport_t *portp);
596 void (*intr)(stlpanel_t *panelp, unsigned int iobase);
600 * Define some macros to make calling these functions nice and clean.
602 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
603 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
604 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
605 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
606 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
607 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
608 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
609 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
610 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
611 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
612 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
613 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
614 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
616 /*****************************************************************************/
619 * CD1400 UART specific data initialization.
621 static uart_t stl_cd1400uart = {
625 stl_cd1400getsignals,
626 stl_cd1400setsignals,
627 stl_cd1400enablerxtx,
629 stl_cd1400disableintrs,
639 * Define the offsets within the register bank of a cd1400 based panel.
640 * These io address offsets are common to the EasyIO board as well.
648 #define EREG_BANKSIZE 8
650 #define CD1400_CLK 25000000
651 #define CD1400_CLK8M 20000000
654 * Define the cd1400 baud rate clocks. These are used when calculating
655 * what clock and divisor to use for the required baud rate. Also
656 * define the maximum baud rate allowed, and the default base baud.
658 static int stl_cd1400clkdivs[] = {
659 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
662 /*****************************************************************************/
665 * SC26198 UART specific data initization.
667 static uart_t stl_sc26198uart = {
668 stl_sc26198panelinit,
671 stl_sc26198getsignals,
672 stl_sc26198setsignals,
673 stl_sc26198enablerxtx,
674 stl_sc26198startrxtx,
675 stl_sc26198disableintrs,
676 stl_sc26198sendbreak,
680 stl_sc26198datastate,
685 * Define the offsets within the register bank of a sc26198 based panel.
693 #define XP_BANKSIZE 4
696 * Define the sc26198 baud rate table. Offsets within the table
697 * represent the actual baud rate selector of sc26198 registers.
699 static unsigned int sc26198_baudtable[] = {
700 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
701 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
702 230400, 460800, 921600
705 #define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
707 /*****************************************************************************/
710 * Define the driver info for a user level control device. Used mainly
711 * to get at port stats - only not using the port device itself.
713 static struct file_operations stl_fsiomem = {
714 .owner = THIS_MODULE,
715 .ioctl = stl_memioctl,
718 /*****************************************************************************/
720 static struct class *stallion_class;
723 * Loadable module initialization stuff.
726 static int __init stallion_module_init(void)
731 printk("init_module()\n");
737 restore_flags(flags);
742 /*****************************************************************************/
744 static void __exit stallion_module_exit(void)
753 printk("cleanup_module()\n");
756 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
763 * Free up all allocated resources used by the ports. This includes
764 * memory and interrupts. As part of this process we will also do
765 * a hangup on every open port - to try to flush out any processes
766 * hanging onto ports.
768 i = tty_unregister_driver(stl_serial);
769 put_tty_driver(stl_serial);
771 printk("STALLION: failed to un-register tty driver, "
773 restore_flags(flags);
776 for (i = 0; i < 4; i++) {
777 devfs_remove("staliomem/%d", i);
778 class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
780 devfs_remove("staliomem");
781 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
782 printk("STALLION: failed to un-register serial memory device, "
784 class_destroy(stallion_class);
786 kfree(stl_tmpwritebuf);
788 for (i = 0; (i < stl_nrbrds); i++) {
789 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
792 free_irq(brdp->irq, brdp);
794 for (j = 0; (j < STL_MAXPANELS); j++) {
795 panelp = brdp->panels[j];
796 if (panelp == (stlpanel_t *) NULL)
798 for (k = 0; (k < STL_PORTSPERPANEL); k++) {
799 portp = panelp->ports[k];
800 if (portp == (stlport_t *) NULL)
802 if (portp->tty != (struct tty_struct *) NULL)
803 stl_hangup(portp->tty);
804 kfree(portp->tx.buf);
810 release_region(brdp->ioaddr1, brdp->iosize1);
811 if (brdp->iosize2 > 0)
812 release_region(brdp->ioaddr2, brdp->iosize2);
815 stl_brds[i] = (stlbrd_t *) NULL;
818 restore_flags(flags);
821 module_init(stallion_module_init);
822 module_exit(stallion_module_exit);
824 /*****************************************************************************/
827 * Check for any arguments passed in on the module load command line.
830 static void stl_argbrds(void)
837 printk("stl_argbrds()\n");
840 for (i = stl_nrbrds; (i < stl_nargs); i++) {
841 memset(&conf, 0, sizeof(conf));
842 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
844 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
848 brdp->brdtype = conf.brdtype;
849 brdp->ioaddr1 = conf.ioaddr1;
850 brdp->ioaddr2 = conf.ioaddr2;
851 brdp->irq = conf.irq;
852 brdp->irqtype = conf.irqtype;
857 /*****************************************************************************/
860 * Convert an ascii string number into an unsigned long.
863 static unsigned long stl_atol(char *str)
871 if ((*sp == '0') && (*(sp+1) == 'x')) {
874 } else if (*sp == '0') {
881 for (; (*sp != 0); sp++) {
882 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
883 if ((c < 0) || (c >= base)) {
884 printk("STALLION: invalid argument %s\n", str);
888 val = (val * base) + c;
893 /*****************************************************************************/
896 * Parse the supplied argument string, into the board conf struct.
899 static int stl_parsebrd(stlconf_t *confp, char **argp)
905 printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
908 if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
911 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
914 for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++) {
915 if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
918 if (i == ARRAY_SIZE(stl_brdstr)) {
919 printk("STALLION: unknown board name, %s?\n", argp[0]);
923 confp->brdtype = stl_brdstr[i].type;
926 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
927 confp->ioaddr1 = stl_atol(argp[i]);
929 if (confp->brdtype == BRD_ECH) {
930 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
931 confp->ioaddr2 = stl_atol(argp[i]);
934 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
935 confp->irq = stl_atol(argp[i]);
939 /*****************************************************************************/
942 * Allocate a new board structure. Fill out the basic info in it.
945 static stlbrd_t *stl_allocbrd(void)
949 brdp = kzalloc(sizeof(stlbrd_t), GFP_KERNEL);
951 printk("STALLION: failed to allocate memory (size=%d)\n",
956 brdp->magic = STL_BOARDMAGIC;
960 /*****************************************************************************/
962 static int stl_open(struct tty_struct *tty, struct file *filp)
966 unsigned int minordev;
967 int brdnr, panelnr, portnr, rc;
970 printk("stl_open(tty=%x,filp=%x): device=%s\n", (int) tty,
971 (int) filp, tty->name);
974 minordev = tty->index;
975 brdnr = MINOR2BRD(minordev);
976 if (brdnr >= stl_nrbrds)
978 brdp = stl_brds[brdnr];
979 if (brdp == (stlbrd_t *) NULL)
981 minordev = MINOR2PORT(minordev);
982 for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
983 if (brdp->panels[panelnr] == (stlpanel_t *) NULL)
985 if (minordev < brdp->panels[panelnr]->nrports) {
989 minordev -= brdp->panels[panelnr]->nrports;
994 portp = brdp->panels[panelnr]->ports[portnr];
995 if (portp == (stlport_t *) NULL)
999 * On the first open of the device setup the port hardware, and
1000 * initialize the per port data structure.
1003 tty->driver_data = portp;
1006 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
1007 if (!portp->tx.buf) {
1008 portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
1011 portp->tx.head = portp->tx.buf;
1012 portp->tx.tail = portp->tx.buf;
1014 stl_setport(portp, tty->termios);
1015 portp->sigs = stl_getsignals(portp);
1016 stl_setsignals(portp, 1, 1);
1017 stl_enablerxtx(portp, 1, 1);
1018 stl_startrxtx(portp, 1, 0);
1019 clear_bit(TTY_IO_ERROR, &tty->flags);
1020 portp->flags |= ASYNC_INITIALIZED;
1024 * Check if this port is in the middle of closing. If so then wait
1025 * until it is closed then return error status, based on flag settings.
1026 * The sleep here does not need interrupt protection since the wakeup
1027 * for it is done with the same context.
1029 if (portp->flags & ASYNC_CLOSING) {
1030 interruptible_sleep_on(&portp->close_wait);
1031 if (portp->flags & ASYNC_HUP_NOTIFY)
1033 return -ERESTARTSYS;
1037 * Based on type of open being done check if it can overlap with any
1038 * previous opens still in effect. If we are a normal serial device
1039 * then also we might have to wait for carrier.
1041 if (!(filp->f_flags & O_NONBLOCK)) {
1042 if ((rc = stl_waitcarrier(portp, filp)) != 0)
1045 portp->flags |= ASYNC_NORMAL_ACTIVE;
1050 /*****************************************************************************/
1053 * Possibly need to wait for carrier (DCD signal) to come high. Say
1054 * maybe because if we are clocal then we don't need to wait...
1057 static int stl_waitcarrier(stlport_t *portp, struct file *filp)
1059 unsigned long flags;
1063 printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp, (int) filp);
1069 if (portp->tty->termios->c_cflag & CLOCAL)
1074 portp->openwaitcnt++;
1075 if (! tty_hung_up_p(filp))
1079 stl_setsignals(portp, 1, 1);
1080 if (tty_hung_up_p(filp) ||
1081 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1082 if (portp->flags & ASYNC_HUP_NOTIFY)
1088 if (((portp->flags & ASYNC_CLOSING) == 0) &&
1089 (doclocal || (portp->sigs & TIOCM_CD))) {
1092 if (signal_pending(current)) {
1096 interruptible_sleep_on(&portp->open_wait);
1099 if (! tty_hung_up_p(filp))
1101 portp->openwaitcnt--;
1102 restore_flags(flags);
1107 /*****************************************************************************/
1109 static void stl_close(struct tty_struct *tty, struct file *filp)
1112 unsigned long flags;
1115 printk("stl_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
1118 portp = tty->driver_data;
1119 if (portp == (stlport_t *) NULL)
1124 if (tty_hung_up_p(filp)) {
1125 restore_flags(flags);
1128 if ((tty->count == 1) && (portp->refcount != 1))
1129 portp->refcount = 1;
1130 if (portp->refcount-- > 1) {
1131 restore_flags(flags);
1135 portp->refcount = 0;
1136 portp->flags |= ASYNC_CLOSING;
1139 * May want to wait for any data to drain before closing. The BUSY
1140 * flag keeps track of whether we are still sending or not - it is
1141 * very accurate for the cd1400, not quite so for the sc26198.
1142 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1145 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1146 tty_wait_until_sent(tty, portp->closing_wait);
1147 stl_waituntilsent(tty, (HZ / 2));
1149 portp->flags &= ~ASYNC_INITIALIZED;
1150 stl_disableintrs(portp);
1151 if (tty->termios->c_cflag & HUPCL)
1152 stl_setsignals(portp, 0, 0);
1153 stl_enablerxtx(portp, 0, 0);
1154 stl_flushbuffer(tty);
1156 if (portp->tx.buf != (char *) NULL) {
1157 kfree(portp->tx.buf);
1158 portp->tx.buf = (char *) NULL;
1159 portp->tx.head = (char *) NULL;
1160 portp->tx.tail = (char *) NULL;
1162 set_bit(TTY_IO_ERROR, &tty->flags);
1163 tty_ldisc_flush(tty);
1166 portp->tty = (struct tty_struct *) NULL;
1168 if (portp->openwaitcnt) {
1169 if (portp->close_delay)
1170 msleep_interruptible(jiffies_to_msecs(portp->close_delay));
1171 wake_up_interruptible(&portp->open_wait);
1174 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1175 wake_up_interruptible(&portp->close_wait);
1176 restore_flags(flags);
1179 /*****************************************************************************/
1182 * Write routine. Take data and stuff it in to the TX ring queue.
1183 * If transmit interrupts are not running then start them.
1186 static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
1189 unsigned int len, stlen;
1190 unsigned char *chbuf;
1194 printk("stl_write(tty=%x,buf=%x,count=%d)\n",
1195 (int) tty, (int) buf, count);
1198 if ((tty == (struct tty_struct *) NULL) ||
1199 (stl_tmpwritebuf == (char *) NULL))
1201 portp = tty->driver_data;
1202 if (portp == (stlport_t *) NULL)
1204 if (portp->tx.buf == (char *) NULL)
1208 * If copying direct from user space we must cater for page faults,
1209 * causing us to "sleep" here for a while. To handle this copy in all
1210 * the data we need now, into a local buffer. Then when we got it all
1211 * copy it into the TX buffer.
1213 chbuf = (unsigned char *) buf;
1215 head = portp->tx.head;
1216 tail = portp->tx.tail;
1218 len = STL_TXBUFSIZE - (head - tail) - 1;
1219 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
1221 len = tail - head - 1;
1225 len = MIN(len, count);
1228 stlen = MIN(len, stlen);
1229 memcpy(head, chbuf, stlen);
1234 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
1235 head = portp->tx.buf;
1236 stlen = tail - head;
1239 portp->tx.head = head;
1241 clear_bit(ASYI_TXLOW, &portp->istate);
1242 stl_startrxtx(portp, -1, 1);
1247 /*****************************************************************************/
1249 static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1256 printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1259 if (tty == (struct tty_struct *) NULL)
1261 portp = tty->driver_data;
1262 if (portp == (stlport_t *) NULL)
1264 if (portp->tx.buf == (char *) NULL)
1267 head = portp->tx.head;
1268 tail = portp->tx.tail;
1270 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
1275 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
1276 head = portp->tx.buf;
1278 portp->tx.head = head;
1281 /*****************************************************************************/
1284 * If there are any characters in the buffer then make sure that TX
1285 * interrupts are on and get'em out. Normally used after the putchar
1286 * routine has been called.
1289 static void stl_flushchars(struct tty_struct *tty)
1294 printk("stl_flushchars(tty=%x)\n", (int) tty);
1297 if (tty == (struct tty_struct *) NULL)
1299 portp = tty->driver_data;
1300 if (portp == (stlport_t *) NULL)
1302 if (portp->tx.buf == (char *) NULL)
1306 if (tty->stopped || tty->hw_stopped ||
1307 (portp->tx.head == portp->tx.tail))
1310 stl_startrxtx(portp, -1, 1);
1313 /*****************************************************************************/
1315 static int stl_writeroom(struct tty_struct *tty)
1321 printk("stl_writeroom(tty=%x)\n", (int) tty);
1324 if (tty == (struct tty_struct *) NULL)
1326 portp = tty->driver_data;
1327 if (portp == (stlport_t *) NULL)
1329 if (portp->tx.buf == (char *) NULL)
1332 head = portp->tx.head;
1333 tail = portp->tx.tail;
1334 return ((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
1337 /*****************************************************************************/
1340 * Return number of chars in the TX buffer. Normally we would just
1341 * calculate the number of chars in the buffer and return that, but if
1342 * the buffer is empty and TX interrupts are still on then we return
1343 * that the buffer still has 1 char in it. This way whoever called us
1344 * will not think that ALL chars have drained - since the UART still
1345 * must have some chars in it (we are busy after all).
1348 static int stl_charsinbuffer(struct tty_struct *tty)
1355 printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
1358 if (tty == (struct tty_struct *) NULL)
1360 portp = tty->driver_data;
1361 if (portp == (stlport_t *) NULL)
1363 if (portp->tx.buf == (char *) NULL)
1366 head = portp->tx.head;
1367 tail = portp->tx.tail;
1368 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1369 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1374 /*****************************************************************************/
1377 * Generate the serial struct info.
1380 static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp)
1382 struct serial_struct sio;
1386 printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1389 memset(&sio, 0, sizeof(struct serial_struct));
1390 sio.line = portp->portnr;
1391 sio.port = portp->ioaddr;
1392 sio.flags = portp->flags;
1393 sio.baud_base = portp->baud_base;
1394 sio.close_delay = portp->close_delay;
1395 sio.closing_wait = portp->closing_wait;
1396 sio.custom_divisor = portp->custom_divisor;
1398 if (portp->uartp == &stl_cd1400uart) {
1399 sio.type = PORT_CIRRUS;
1400 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1402 sio.type = PORT_UNKNOWN;
1403 sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1406 brdp = stl_brds[portp->brdnr];
1407 if (brdp != (stlbrd_t *) NULL)
1408 sio.irq = brdp->irq;
1410 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
1413 /*****************************************************************************/
1416 * Set port according to the serial struct info.
1417 * At this point we do not do any auto-configure stuff, so we will
1418 * just quietly ignore any requests to change irq, etc.
1421 static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp)
1423 struct serial_struct sio;
1426 printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1429 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1431 if (!capable(CAP_SYS_ADMIN)) {
1432 if ((sio.baud_base != portp->baud_base) ||
1433 (sio.close_delay != portp->close_delay) ||
1434 ((sio.flags & ~ASYNC_USR_MASK) !=
1435 (portp->flags & ~ASYNC_USR_MASK)))
1439 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1440 (sio.flags & ASYNC_USR_MASK);
1441 portp->baud_base = sio.baud_base;
1442 portp->close_delay = sio.close_delay;
1443 portp->closing_wait = sio.closing_wait;
1444 portp->custom_divisor = sio.custom_divisor;
1445 stl_setport(portp, portp->tty->termios);
1449 /*****************************************************************************/
1451 static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1455 if (tty == (struct tty_struct *) NULL)
1457 portp = tty->driver_data;
1458 if (portp == (stlport_t *) NULL)
1460 if (tty->flags & (1 << TTY_IO_ERROR))
1463 return stl_getsignals(portp);
1466 static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1467 unsigned int set, unsigned int clear)
1470 int rts = -1, dtr = -1;
1472 if (tty == (struct tty_struct *) NULL)
1474 portp = tty->driver_data;
1475 if (portp == (stlport_t *) NULL)
1477 if (tty->flags & (1 << TTY_IO_ERROR))
1480 if (set & TIOCM_RTS)
1482 if (set & TIOCM_DTR)
1484 if (clear & TIOCM_RTS)
1486 if (clear & TIOCM_DTR)
1489 stl_setsignals(portp, dtr, rts);
1493 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1498 void __user *argp = (void __user *)arg;
1501 printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
1502 (int) tty, (int) file, cmd, (int) arg);
1505 if (tty == (struct tty_struct *) NULL)
1507 portp = tty->driver_data;
1508 if (portp == (stlport_t *) NULL)
1511 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1512 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1513 if (tty->flags & (1 << TTY_IO_ERROR))
1521 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1522 (unsigned __user *) argp);
1525 if (get_user(ival, (unsigned int __user *) arg))
1527 tty->termios->c_cflag =
1528 (tty->termios->c_cflag & ~CLOCAL) |
1529 (ival ? CLOCAL : 0);
1532 rc = stl_getserial(portp, argp);
1535 rc = stl_setserial(portp, argp);
1537 case COM_GETPORTSTATS:
1538 rc = stl_getportstats(portp, argp);
1540 case COM_CLRPORTSTATS:
1541 rc = stl_clrportstats(portp, argp);
1547 case TIOCSERGSTRUCT:
1548 case TIOCSERGETMULTI:
1549 case TIOCSERSETMULTI:
1558 /*****************************************************************************/
1560 static void stl_settermios(struct tty_struct *tty, struct termios *old)
1563 struct termios *tiosp;
1566 printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
1569 if (tty == (struct tty_struct *) NULL)
1571 portp = tty->driver_data;
1572 if (portp == (stlport_t *) NULL)
1575 tiosp = tty->termios;
1576 if ((tiosp->c_cflag == old->c_cflag) &&
1577 (tiosp->c_iflag == old->c_iflag))
1580 stl_setport(portp, tiosp);
1581 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1583 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1584 tty->hw_stopped = 0;
1587 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1588 wake_up_interruptible(&portp->open_wait);
1591 /*****************************************************************************/
1594 * Attempt to flow control who ever is sending us data. Based on termios
1595 * settings use software or/and hardware flow control.
1598 static void stl_throttle(struct tty_struct *tty)
1603 printk("stl_throttle(tty=%x)\n", (int) tty);
1606 if (tty == (struct tty_struct *) NULL)
1608 portp = tty->driver_data;
1609 if (portp == (stlport_t *) NULL)
1611 stl_flowctrl(portp, 0);
1614 /*****************************************************************************/
1617 * Unflow control the device sending us data...
1620 static void stl_unthrottle(struct tty_struct *tty)
1625 printk("stl_unthrottle(tty=%x)\n", (int) tty);
1628 if (tty == (struct tty_struct *) NULL)
1630 portp = tty->driver_data;
1631 if (portp == (stlport_t *) NULL)
1633 stl_flowctrl(portp, 1);
1636 /*****************************************************************************/
1639 * Stop the transmitter. Basically to do this we will just turn TX
1643 static void stl_stop(struct tty_struct *tty)
1648 printk("stl_stop(tty=%x)\n", (int) tty);
1651 if (tty == (struct tty_struct *) NULL)
1653 portp = tty->driver_data;
1654 if (portp == (stlport_t *) NULL)
1656 stl_startrxtx(portp, -1, 0);
1659 /*****************************************************************************/
1662 * Start the transmitter again. Just turn TX interrupts back on.
1665 static void stl_start(struct tty_struct *tty)
1670 printk("stl_start(tty=%x)\n", (int) tty);
1673 if (tty == (struct tty_struct *) NULL)
1675 portp = tty->driver_data;
1676 if (portp == (stlport_t *) NULL)
1678 stl_startrxtx(portp, -1, 1);
1681 /*****************************************************************************/
1684 * Hangup this port. This is pretty much like closing the port, only
1685 * a little more brutal. No waiting for data to drain. Shutdown the
1686 * port and maybe drop signals.
1689 static void stl_hangup(struct tty_struct *tty)
1694 printk("stl_hangup(tty=%x)\n", (int) tty);
1697 if (tty == (struct tty_struct *) NULL)
1699 portp = tty->driver_data;
1700 if (portp == (stlport_t *) NULL)
1703 portp->flags &= ~ASYNC_INITIALIZED;
1704 stl_disableintrs(portp);
1705 if (tty->termios->c_cflag & HUPCL)
1706 stl_setsignals(portp, 0, 0);
1707 stl_enablerxtx(portp, 0, 0);
1708 stl_flushbuffer(tty);
1710 set_bit(TTY_IO_ERROR, &tty->flags);
1711 if (portp->tx.buf != (char *) NULL) {
1712 kfree(portp->tx.buf);
1713 portp->tx.buf = (char *) NULL;
1714 portp->tx.head = (char *) NULL;
1715 portp->tx.tail = (char *) NULL;
1717 portp->tty = (struct tty_struct *) NULL;
1718 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1719 portp->refcount = 0;
1720 wake_up_interruptible(&portp->open_wait);
1723 /*****************************************************************************/
1725 static void stl_flushbuffer(struct tty_struct *tty)
1730 printk("stl_flushbuffer(tty=%x)\n", (int) tty);
1733 if (tty == (struct tty_struct *) NULL)
1735 portp = tty->driver_data;
1736 if (portp == (stlport_t *) NULL)
1743 /*****************************************************************************/
1745 static void stl_breakctl(struct tty_struct *tty, int state)
1750 printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty, state);
1753 if (tty == (struct tty_struct *) NULL)
1755 portp = tty->driver_data;
1756 if (portp == (stlport_t *) NULL)
1759 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1762 /*****************************************************************************/
1764 static void stl_waituntilsent(struct tty_struct *tty, int timeout)
1770 printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty, timeout);
1773 if (tty == (struct tty_struct *) NULL)
1775 portp = tty->driver_data;
1776 if (portp == (stlport_t *) NULL)
1781 tend = jiffies + timeout;
1783 while (stl_datastate(portp)) {
1784 if (signal_pending(current))
1786 msleep_interruptible(20);
1787 if (time_after_eq(jiffies, tend))
1792 /*****************************************************************************/
1794 static void stl_sendxchar(struct tty_struct *tty, char ch)
1799 printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
1802 if (tty == (struct tty_struct *) NULL)
1804 portp = tty->driver_data;
1805 if (portp == (stlport_t *) NULL)
1808 if (ch == STOP_CHAR(tty))
1809 stl_sendflow(portp, 0);
1810 else if (ch == START_CHAR(tty))
1811 stl_sendflow(portp, 1);
1813 stl_putchar(tty, ch);
1816 /*****************************************************************************/
1821 * Format info for a specified port. The line is deliberately limited
1822 * to 80 characters. (If it is too long it will be truncated, if too
1823 * short then padded with spaces).
1826 static int stl_portinfo(stlport_t *portp, int portnr, char *pos)
1832 sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
1833 portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
1834 (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
1836 if (portp->stats.rxframing)
1837 sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
1838 if (portp->stats.rxparity)
1839 sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
1840 if (portp->stats.rxbreaks)
1841 sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
1842 if (portp->stats.rxoverrun)
1843 sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
1845 sigs = stl_getsignals(portp);
1846 cnt = sprintf(sp, "%s%s%s%s%s ",
1847 (sigs & TIOCM_RTS) ? "|RTS" : "",
1848 (sigs & TIOCM_CTS) ? "|CTS" : "",
1849 (sigs & TIOCM_DTR) ? "|DTR" : "",
1850 (sigs & TIOCM_CD) ? "|DCD" : "",
1851 (sigs & TIOCM_DSR) ? "|DSR" : "");
1855 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
1858 pos[(MAXLINE - 2)] = '+';
1859 pos[(MAXLINE - 1)] = '\n';
1864 /*****************************************************************************/
1867 * Port info, read from the /proc file system.
1870 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
1875 int brdnr, panelnr, portnr, totalport;
1880 printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
1881 "data=%x\n", (int) page, (int) start, (int) off, count,
1882 (int) eof, (int) data);
1890 pos += sprintf(pos, "%s: version %s", stl_drvtitle,
1892 while (pos < (page + MAXLINE - 1))
1899 * We scan through for each board, panel and port. The offset is
1900 * calculated on the fly, and irrelevant ports are skipped.
1902 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1903 brdp = stl_brds[brdnr];
1904 if (brdp == (stlbrd_t *) NULL)
1906 if (brdp->state == 0)
1909 maxoff = curoff + (brdp->nrports * MAXLINE);
1910 if (off >= maxoff) {
1915 totalport = brdnr * STL_MAXPORTS;
1916 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1917 panelp = brdp->panels[panelnr];
1918 if (panelp == (stlpanel_t *) NULL)
1921 maxoff = curoff + (panelp->nrports * MAXLINE);
1922 if (off >= maxoff) {
1924 totalport += panelp->nrports;
1928 for (portnr = 0; (portnr < panelp->nrports); portnr++,
1930 portp = panelp->ports[portnr];
1931 if (portp == (stlport_t *) NULL)
1933 if (off >= (curoff += MAXLINE))
1935 if ((pos - page + MAXLINE) > count)
1937 pos += stl_portinfo(portp, totalport, pos);
1946 return (pos - page);
1949 /*****************************************************************************/
1952 * All board interrupts are vectored through here first. This code then
1953 * calls off to the approrpriate board interrupt handlers.
1956 static irqreturn_t stl_intr(int irq, void *dev_id, struct pt_regs *regs)
1958 stlbrd_t *brdp = (stlbrd_t *) dev_id;
1961 printk("stl_intr(brdp=%x,irq=%d,regs=%x)\n", (int) brdp, irq,
1965 return IRQ_RETVAL((* brdp->isr)(brdp));
1968 /*****************************************************************************/
1971 * Interrupt service routine for EasyIO board types.
1974 static int stl_eiointr(stlbrd_t *brdp)
1977 unsigned int iobase;
1980 panelp = brdp->panels[0];
1981 iobase = panelp->iobase;
1982 while (inb(brdp->iostatus) & EIO_INTRPEND) {
1984 (* panelp->isr)(panelp, iobase);
1989 /*****************************************************************************/
1992 * Interrupt service routine for ECH-AT board types.
1995 static int stl_echatintr(stlbrd_t *brdp)
1998 unsigned int ioaddr;
2002 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2004 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2006 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2007 ioaddr = brdp->bnkstataddr[bnknr];
2008 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2009 panelp = brdp->bnk2panel[bnknr];
2010 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2015 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2020 /*****************************************************************************/
2023 * Interrupt service routine for ECH-MCA board types.
2026 static int stl_echmcaintr(stlbrd_t *brdp)
2029 unsigned int ioaddr;
2033 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2035 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2036 ioaddr = brdp->bnkstataddr[bnknr];
2037 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2038 panelp = brdp->bnk2panel[bnknr];
2039 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2046 /*****************************************************************************/
2049 * Interrupt service routine for ECH-PCI board types.
2052 static int stl_echpciintr(stlbrd_t *brdp)
2055 unsigned int ioaddr;
2061 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2062 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
2063 ioaddr = brdp->bnkstataddr[bnknr];
2064 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2065 panelp = brdp->bnk2panel[bnknr];
2066 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2077 /*****************************************************************************/
2080 * Interrupt service routine for ECH-8/64-PCI board types.
2083 static int stl_echpci64intr(stlbrd_t *brdp)
2086 unsigned int ioaddr;
2090 while (inb(brdp->ioctrl) & 0x1) {
2092 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2093 ioaddr = brdp->bnkstataddr[bnknr];
2094 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2095 panelp = brdp->bnk2panel[bnknr];
2096 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2104 /*****************************************************************************/
2107 * Service an off-level request for some channel.
2109 static void stl_offintr(void *private)
2112 struct tty_struct *tty;
2113 unsigned int oldsigs;
2118 printk("stl_offintr(portp=%x)\n", (int) portp);
2121 if (portp == (stlport_t *) NULL)
2125 if (tty == (struct tty_struct *) NULL)
2129 if (test_bit(ASYI_TXLOW, &portp->istate)) {
2132 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
2133 clear_bit(ASYI_DCDCHANGE, &portp->istate);
2134 oldsigs = portp->sigs;
2135 portp->sigs = stl_getsignals(portp);
2136 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
2137 wake_up_interruptible(&portp->open_wait);
2138 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
2139 if (portp->flags & ASYNC_CHECK_CD)
2140 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2146 /*****************************************************************************/
2149 * Initialize all the ports on a panel.
2152 static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2158 printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
2161 chipmask = stl_panelinit(brdp, panelp);
2164 * All UART's are initialized (if found!). Now go through and setup
2165 * each ports data structures.
2167 for (i = 0; (i < panelp->nrports); i++) {
2168 portp = kzalloc(sizeof(stlport_t), GFP_KERNEL);
2170 printk("STALLION: failed to allocate memory "
2171 "(size=%d)\n", sizeof(stlport_t));
2175 portp->magic = STL_PORTMAGIC;
2177 portp->brdnr = panelp->brdnr;
2178 portp->panelnr = panelp->panelnr;
2179 portp->uartp = panelp->uartp;
2180 portp->clk = brdp->clk;
2181 portp->baud_base = STL_BAUDBASE;
2182 portp->close_delay = STL_CLOSEDELAY;
2183 portp->closing_wait = 30 * HZ;
2184 INIT_WORK(&portp->tqueue, stl_offintr, portp);
2185 init_waitqueue_head(&portp->open_wait);
2186 init_waitqueue_head(&portp->close_wait);
2187 portp->stats.brd = portp->brdnr;
2188 portp->stats.panel = portp->panelnr;
2189 portp->stats.port = portp->portnr;
2190 panelp->ports[i] = portp;
2191 stl_portinit(brdp, panelp, portp);
2197 /*****************************************************************************/
2200 * Try to find and initialize an EasyIO board.
2203 static inline int stl_initeio(stlbrd_t *brdp)
2206 unsigned int status;
2211 printk("stl_initeio(brdp=%x)\n", (int) brdp);
2214 brdp->ioctrl = brdp->ioaddr1 + 1;
2215 brdp->iostatus = brdp->ioaddr1 + 2;
2217 status = inb(brdp->iostatus);
2218 if ((status & EIO_IDBITMASK) == EIO_MK3)
2222 * Handle board specific stuff now. The real difference is PCI
2225 if (brdp->brdtype == BRD_EASYIOPCI) {
2226 brdp->iosize1 = 0x80;
2227 brdp->iosize2 = 0x80;
2228 name = "serial(EIO-PCI)";
2229 outb(0x41, (brdp->ioaddr2 + 0x4c));
2232 name = "serial(EIO)";
2233 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2234 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2235 printk("STALLION: invalid irq=%d for brd=%d\n",
2236 brdp->irq, brdp->brdnr);
2239 outb((stl_vecmap[brdp->irq] | EIO_0WS |
2240 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
2244 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2245 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2246 "%x conflicts with another device\n", brdp->brdnr,
2251 if (brdp->iosize2 > 0)
2252 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2253 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2254 "address %x conflicts with another device\n",
2255 brdp->brdnr, brdp->ioaddr2);
2256 printk(KERN_WARNING "STALLION: Warning, also "
2257 "releasing board %d I/O address %x \n",
2258 brdp->brdnr, brdp->ioaddr1);
2259 release_region(brdp->ioaddr1, brdp->iosize1);
2264 * Everything looks OK, so let's go ahead and probe for the hardware.
2266 brdp->clk = CD1400_CLK;
2267 brdp->isr = stl_eiointr;
2269 switch (status & EIO_IDBITMASK) {
2271 brdp->clk = CD1400_CLK8M;
2281 switch (status & EIO_BRDMASK) {
2300 * We have verified that the board is actually present, so now we
2301 * can complete the setup.
2304 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
2306 printk(KERN_WARNING "STALLION: failed to allocate memory "
2307 "(size=%d)\n", sizeof(stlpanel_t));
2311 panelp->magic = STL_PANELMAGIC;
2312 panelp->brdnr = brdp->brdnr;
2313 panelp->panelnr = 0;
2314 panelp->nrports = brdp->nrports;
2315 panelp->iobase = brdp->ioaddr1;
2316 panelp->hwid = status;
2317 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2318 panelp->uartp = (void *) &stl_sc26198uart;
2319 panelp->isr = stl_sc26198intr;
2321 panelp->uartp = (void *) &stl_cd1400uart;
2322 panelp->isr = stl_cd1400eiointr;
2325 brdp->panels[0] = panelp;
2327 brdp->state |= BRD_FOUND;
2328 brdp->hwid = status;
2329 if (request_irq(brdp->irq, stl_intr, SA_SHIRQ, name, brdp) != 0) {
2330 printk("STALLION: failed to register interrupt "
2331 "routine for %s irq=%d\n", name, brdp->irq);
2339 /*****************************************************************************/
2342 * Try to find an ECH board and initialize it. This code is capable of
2343 * dealing with all types of ECH board.
2346 static inline int stl_initech(stlbrd_t *brdp)
2349 unsigned int status, nxtid, ioaddr, conflict;
2350 int panelnr, banknr, i;
2354 printk("stl_initech(brdp=%x)\n", (int) brdp);
2361 * Set up the initial board register contents for boards. This varies a
2362 * bit between the different board types. So we need to handle each
2363 * separately. Also do a check that the supplied IRQ is good.
2365 switch (brdp->brdtype) {
2368 brdp->isr = stl_echatintr;
2369 brdp->ioctrl = brdp->ioaddr1 + 1;
2370 brdp->iostatus = brdp->ioaddr1 + 1;
2371 status = inb(brdp->iostatus);
2372 if ((status & ECH_IDBITMASK) != ECH_ID)
2374 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2375 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2376 printk("STALLION: invalid irq=%d for brd=%d\n",
2377 brdp->irq, brdp->brdnr);
2380 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2381 status |= (stl_vecmap[brdp->irq] << 1);
2382 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2383 brdp->ioctrlval = ECH_INTENABLE |
2384 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2385 for (i = 0; (i < 10); i++)
2386 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2389 name = "serial(EC8/32)";
2390 outb(status, brdp->ioaddr1);
2394 brdp->isr = stl_echmcaintr;
2395 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2396 brdp->iostatus = brdp->ioctrl;
2397 status = inb(brdp->iostatus);
2398 if ((status & ECH_IDBITMASK) != ECH_ID)
2400 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2401 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2402 printk("STALLION: invalid irq=%d for brd=%d\n",
2403 brdp->irq, brdp->brdnr);
2406 outb(ECHMC_BRDRESET, brdp->ioctrl);
2407 outb(ECHMC_INTENABLE, brdp->ioctrl);
2409 name = "serial(EC8/32-MC)";
2413 brdp->isr = stl_echpciintr;
2414 brdp->ioctrl = brdp->ioaddr1 + 2;
2417 name = "serial(EC8/32-PCI)";
2421 brdp->isr = stl_echpci64intr;
2422 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2423 outb(0x43, (brdp->ioaddr1 + 0x4c));
2424 brdp->iosize1 = 0x80;
2425 brdp->iosize2 = 0x80;
2426 name = "serial(EC8/64-PCI)";
2430 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
2436 * Check boards for possible IO address conflicts and return fail status
2437 * if an IO conflict found.
2439 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2440 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2441 "%x conflicts with another device\n", brdp->brdnr,
2446 if (brdp->iosize2 > 0)
2447 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2448 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2449 "address %x conflicts with another device\n",
2450 brdp->brdnr, brdp->ioaddr2);
2451 printk(KERN_WARNING "STALLION: Warning, also "
2452 "releasing board %d I/O address %x \n",
2453 brdp->brdnr, brdp->ioaddr1);
2454 release_region(brdp->ioaddr1, brdp->iosize1);
2459 * Scan through the secondary io address space looking for panels.
2460 * As we find'em allocate and initialize panel structures for each.
2462 brdp->clk = CD1400_CLK;
2463 brdp->hwid = status;
2465 ioaddr = brdp->ioaddr2;
2470 for (i = 0; (i < STL_MAXPANELS); i++) {
2471 if (brdp->brdtype == BRD_ECHPCI) {
2472 outb(nxtid, brdp->ioctrl);
2473 ioaddr = brdp->ioaddr2;
2475 status = inb(ioaddr + ECH_PNLSTATUS);
2476 if ((status & ECH_PNLIDMASK) != nxtid)
2478 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
2480 printk("STALLION: failed to allocate memory "
2481 "(size=%d)\n", sizeof(stlpanel_t));
2484 panelp->magic = STL_PANELMAGIC;
2485 panelp->brdnr = brdp->brdnr;
2486 panelp->panelnr = panelnr;
2487 panelp->iobase = ioaddr;
2488 panelp->pagenr = nxtid;
2489 panelp->hwid = status;
2490 brdp->bnk2panel[banknr] = panelp;
2491 brdp->bnkpageaddr[banknr] = nxtid;
2492 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2494 if (status & ECH_PNLXPID) {
2495 panelp->uartp = (void *) &stl_sc26198uart;
2496 panelp->isr = stl_sc26198intr;
2497 if (status & ECH_PNL16PORT) {
2498 panelp->nrports = 16;
2499 brdp->bnk2panel[banknr] = panelp;
2500 brdp->bnkpageaddr[banknr] = nxtid;
2501 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2504 panelp->nrports = 8;
2507 panelp->uartp = (void *) &stl_cd1400uart;
2508 panelp->isr = stl_cd1400echintr;
2509 if (status & ECH_PNL16PORT) {
2510 panelp->nrports = 16;
2511 panelp->ackmask = 0x80;
2512 if (brdp->brdtype != BRD_ECHPCI)
2513 ioaddr += EREG_BANKSIZE;
2514 brdp->bnk2panel[banknr] = panelp;
2515 brdp->bnkpageaddr[banknr] = ++nxtid;
2516 brdp->bnkstataddr[banknr++] = ioaddr +
2519 panelp->nrports = 8;
2520 panelp->ackmask = 0xc0;
2525 ioaddr += EREG_BANKSIZE;
2526 brdp->nrports += panelp->nrports;
2527 brdp->panels[panelnr++] = panelp;
2528 if ((brdp->brdtype != BRD_ECHPCI) &&
2529 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
2533 brdp->nrpanels = panelnr;
2534 brdp->nrbnks = banknr;
2535 if (brdp->brdtype == BRD_ECH)
2536 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2538 brdp->state |= BRD_FOUND;
2539 if (request_irq(brdp->irq, stl_intr, SA_SHIRQ, name, brdp) != 0) {
2540 printk("STALLION: failed to register interrupt "
2541 "routine for %s irq=%d\n", name, brdp->irq);
2550 /*****************************************************************************/
2553 * Initialize and configure the specified board.
2554 * Scan through all the boards in the configuration and see what we
2555 * can find. Handle EIO and the ECH boards a little differently here
2556 * since the initial search and setup is very different.
2559 static int __init stl_brdinit(stlbrd_t *brdp)
2564 printk("stl_brdinit(brdp=%x)\n", (int) brdp);
2567 switch (brdp->brdtype) {
2579 printk("STALLION: board=%d is unknown board type=%d\n",
2580 brdp->brdnr, brdp->brdtype);
2584 stl_brds[brdp->brdnr] = brdp;
2585 if ((brdp->state & BRD_FOUND) == 0) {
2586 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2587 stl_brdnames[brdp->brdtype], brdp->brdnr,
2588 brdp->ioaddr1, brdp->irq);
2592 for (i = 0; (i < STL_MAXPANELS); i++)
2593 if (brdp->panels[i] != (stlpanel_t *) NULL)
2594 stl_initports(brdp, brdp->panels[i]);
2596 printk("STALLION: %s found, board=%d io=%x irq=%d "
2597 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2598 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2603 /*****************************************************************************/
2606 * Find the next available board number that is free.
2609 static inline int stl_getbrdnr(void)
2613 for (i = 0; (i < STL_MAXBRDS); i++) {
2614 if (stl_brds[i] == (stlbrd_t *) NULL) {
2615 if (i >= stl_nrbrds)
2623 /*****************************************************************************/
2628 * We have a Stallion board. Allocate a board structure and
2629 * initialize it. Read its IO and IRQ resources from PCI
2630 * configuration space.
2633 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
2638 printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
2639 devp->bus->number, devp->devfn);
2642 if (pci_enable_device(devp))
2644 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2646 if ((brdp->brdnr = stl_getbrdnr()) < 0) {
2647 printk("STALLION: too many boards found, "
2648 "maximum supported %d\n", STL_MAXBRDS);
2651 brdp->brdtype = brdtype;
2654 * Different Stallion boards use the BAR registers in different ways,
2655 * so set up io addresses based on board type.
2658 printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__, __LINE__,
2659 pci_resource_start(devp, 0), pci_resource_start(devp, 1),
2660 pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
2664 * We have all resources from the board, so let's setup the actual
2665 * board structure now.
2669 brdp->ioaddr2 = pci_resource_start(devp, 0);
2670 brdp->ioaddr1 = pci_resource_start(devp, 1);
2673 brdp->ioaddr2 = pci_resource_start(devp, 2);
2674 brdp->ioaddr1 = pci_resource_start(devp, 1);
2677 brdp->ioaddr1 = pci_resource_start(devp, 2);
2678 brdp->ioaddr2 = pci_resource_start(devp, 1);
2681 printk("STALLION: unknown PCI board type=%d\n", brdtype);
2685 brdp->irq = devp->irq;
2691 /*****************************************************************************/
2694 * Find all Stallion PCI boards that might be installed. Initialize each
2695 * one as it is found.
2699 static inline int stl_findpcibrds(void)
2701 struct pci_dev *dev = NULL;
2705 printk("stl_findpcibrds()\n");
2708 for (i = 0; (i < stl_nrpcibrds); i++)
2709 while ((dev = pci_find_device(stl_pcibrds[i].vendid,
2710 stl_pcibrds[i].devid, dev))) {
2713 * Found a device on the PCI bus that has our vendor and
2714 * device ID. Need to check now that it is really us.
2716 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2719 rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
2729 /*****************************************************************************/
2732 * Scan through all the boards in the configuration and see what we
2733 * can find. Handle EIO and the ECH boards a little differently here
2734 * since the initial search and setup is too different.
2737 static inline int stl_initbrds(void)
2744 printk("stl_initbrds()\n");
2747 if (stl_nrbrds > STL_MAXBRDS) {
2748 printk("STALLION: too many boards in configuration table, "
2749 "truncating to %d\n", STL_MAXBRDS);
2750 stl_nrbrds = STL_MAXBRDS;
2754 * Firstly scan the list of static boards configured. Allocate
2755 * resources and initialize the boards as found.
2757 for (i = 0; (i < stl_nrbrds); i++) {
2758 confp = &stl_brdconf[i];
2759 stl_parsebrd(confp, stl_brdsp[i]);
2760 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2763 brdp->brdtype = confp->brdtype;
2764 brdp->ioaddr1 = confp->ioaddr1;
2765 brdp->ioaddr2 = confp->ioaddr2;
2766 brdp->irq = confp->irq;
2767 brdp->irqtype = confp->irqtype;
2772 * Find any dynamically supported boards. That is via module load
2773 * line options or auto-detected on the PCI bus.
2783 /*****************************************************************************/
2786 * Return the board stats structure to user app.
2789 static int stl_getbrdstats(combrd_t __user *bp)
2795 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2797 if (stl_brdstats.brd >= STL_MAXBRDS)
2799 brdp = stl_brds[stl_brdstats.brd];
2800 if (brdp == (stlbrd_t *) NULL)
2803 memset(&stl_brdstats, 0, sizeof(combrd_t));
2804 stl_brdstats.brd = brdp->brdnr;
2805 stl_brdstats.type = brdp->brdtype;
2806 stl_brdstats.hwid = brdp->hwid;
2807 stl_brdstats.state = brdp->state;
2808 stl_brdstats.ioaddr = brdp->ioaddr1;
2809 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2810 stl_brdstats.irq = brdp->irq;
2811 stl_brdstats.nrpanels = brdp->nrpanels;
2812 stl_brdstats.nrports = brdp->nrports;
2813 for (i = 0; (i < brdp->nrpanels); i++) {
2814 panelp = brdp->panels[i];
2815 stl_brdstats.panels[i].panel = i;
2816 stl_brdstats.panels[i].hwid = panelp->hwid;
2817 stl_brdstats.panels[i].nrports = panelp->nrports;
2820 return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
2823 /*****************************************************************************/
2826 * Resolve the referenced port number into a port struct pointer.
2829 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2834 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2835 return((stlport_t *) NULL);
2836 brdp = stl_brds[brdnr];
2837 if (brdp == (stlbrd_t *) NULL)
2838 return((stlport_t *) NULL);
2839 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2840 return((stlport_t *) NULL);
2841 panelp = brdp->panels[panelnr];
2842 if (panelp == (stlpanel_t *) NULL)
2843 return((stlport_t *) NULL);
2844 if ((portnr < 0) || (portnr >= panelp->nrports))
2845 return((stlport_t *) NULL);
2846 return(panelp->ports[portnr]);
2849 /*****************************************************************************/
2852 * Return the port stats structure to user app. A NULL port struct
2853 * pointer passed in means that we need to find out from the app
2854 * what port to get stats for (used through board control device).
2857 static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
2859 unsigned char *head, *tail;
2860 unsigned long flags;
2863 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2865 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2867 if (portp == (stlport_t *) NULL)
2871 portp->stats.state = portp->istate;
2872 portp->stats.flags = portp->flags;
2873 portp->stats.hwid = portp->hwid;
2875 portp->stats.ttystate = 0;
2876 portp->stats.cflags = 0;
2877 portp->stats.iflags = 0;
2878 portp->stats.oflags = 0;
2879 portp->stats.lflags = 0;
2880 portp->stats.rxbuffered = 0;
2884 if (portp->tty != (struct tty_struct *) NULL) {
2885 if (portp->tty->driver_data == portp) {
2886 portp->stats.ttystate = portp->tty->flags;
2887 /* No longer available as a statistic */
2888 portp->stats.rxbuffered = 1; /*portp->tty->flip.count; */
2889 if (portp->tty->termios != (struct termios *) NULL) {
2890 portp->stats.cflags = portp->tty->termios->c_cflag;
2891 portp->stats.iflags = portp->tty->termios->c_iflag;
2892 portp->stats.oflags = portp->tty->termios->c_oflag;
2893 portp->stats.lflags = portp->tty->termios->c_lflag;
2897 restore_flags(flags);
2899 head = portp->tx.head;
2900 tail = portp->tx.tail;
2901 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2902 (STL_TXBUFSIZE - (tail - head)));
2904 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2906 return copy_to_user(cp, &portp->stats,
2907 sizeof(comstats_t)) ? -EFAULT : 0;
2910 /*****************************************************************************/
2913 * Clear the port stats structure. We also return it zeroed out...
2916 static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp)
2919 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2921 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2923 if (portp == (stlport_t *) NULL)
2927 memset(&portp->stats, 0, sizeof(comstats_t));
2928 portp->stats.brd = portp->brdnr;
2929 portp->stats.panel = portp->panelnr;
2930 portp->stats.port = portp->portnr;
2931 return copy_to_user(cp, &portp->stats,
2932 sizeof(comstats_t)) ? -EFAULT : 0;
2935 /*****************************************************************************/
2938 * Return the entire driver ports structure to a user app.
2941 static int stl_getportstruct(stlport_t __user *arg)
2945 if (copy_from_user(&stl_dummyport, arg, sizeof(stlport_t)))
2947 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
2948 stl_dummyport.portnr);
2951 return copy_to_user(arg, portp, sizeof(stlport_t)) ? -EFAULT : 0;
2954 /*****************************************************************************/
2957 * Return the entire driver board structure to a user app.
2960 static int stl_getbrdstruct(stlbrd_t __user *arg)
2964 if (copy_from_user(&stl_dummybrd, arg, sizeof(stlbrd_t)))
2966 if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
2968 brdp = stl_brds[stl_dummybrd.brdnr];
2971 return copy_to_user(arg, brdp, sizeof(stlbrd_t)) ? -EFAULT : 0;
2974 /*****************************************************************************/
2977 * The "staliomem" device is also required to do some special operations
2978 * on the board and/or ports. In this driver it is mostly used for stats
2982 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
2985 void __user *argp = (void __user *)arg;
2988 printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
2989 (int) fp, cmd, (int) arg);
2993 if (brdnr >= STL_MAXBRDS)
2998 case COM_GETPORTSTATS:
2999 rc = stl_getportstats(NULL, argp);
3001 case COM_CLRPORTSTATS:
3002 rc = stl_clrportstats(NULL, argp);
3004 case COM_GETBRDSTATS:
3005 rc = stl_getbrdstats(argp);
3008 rc = stl_getportstruct(argp);
3011 rc = stl_getbrdstruct(argp);
3021 static struct tty_operations stl_ops = {
3025 .put_char = stl_putchar,
3026 .flush_chars = stl_flushchars,
3027 .write_room = stl_writeroom,
3028 .chars_in_buffer = stl_charsinbuffer,
3030 .set_termios = stl_settermios,
3031 .throttle = stl_throttle,
3032 .unthrottle = stl_unthrottle,
3035 .hangup = stl_hangup,
3036 .flush_buffer = stl_flushbuffer,
3037 .break_ctl = stl_breakctl,
3038 .wait_until_sent = stl_waituntilsent,
3039 .send_xchar = stl_sendxchar,
3040 .read_proc = stl_readproc,
3041 .tiocmget = stl_tiocmget,
3042 .tiocmset = stl_tiocmset,
3045 /*****************************************************************************/
3047 static int __init stl_init(void)
3050 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
3054 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
3059 * Allocate a temporary write buffer.
3061 stl_tmpwritebuf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
3062 if (!stl_tmpwritebuf)
3063 printk("STALLION: failed to allocate memory (size=%d)\n",
3067 * Set up a character driver for per board stuff. This is mainly used
3068 * to do stats ioctls on the ports.
3070 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
3071 printk("STALLION: failed to register serial board device\n");
3073 stallion_class = class_create(THIS_MODULE, "staliomem");
3074 for (i = 0; i < 4; i++) {
3075 devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR, i),
3076 S_IFCHR|S_IRUSR|S_IWUSR,
3078 class_device_create(stallion_class, NULL,
3079 MKDEV(STL_SIOMEMMAJOR, i), NULL,
3083 stl_serial->owner = THIS_MODULE;
3084 stl_serial->driver_name = stl_drvname;
3085 stl_serial->name = "ttyE";
3086 stl_serial->devfs_name = "tts/E";
3087 stl_serial->major = STL_SERIALMAJOR;
3088 stl_serial->minor_start = 0;
3089 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
3090 stl_serial->subtype = SERIAL_TYPE_NORMAL;
3091 stl_serial->init_termios = stl_deftermios;
3092 stl_serial->flags = TTY_DRIVER_REAL_RAW;
3093 tty_set_operations(stl_serial, &stl_ops);
3095 if (tty_register_driver(stl_serial)) {
3096 put_tty_driver(stl_serial);
3097 printk("STALLION: failed to register serial driver\n");
3104 /*****************************************************************************/
3105 /* CD1400 HARDWARE FUNCTIONS */
3106 /*****************************************************************************/
3109 * These functions get/set/update the registers of the cd1400 UARTs.
3110 * Access to the cd1400 registers is via an address/data io port pair.
3111 * (Maybe should make this inline...)
3114 static int stl_cd1400getreg(stlport_t *portp, int regnr)
3116 outb((regnr + portp->uartaddr), portp->ioaddr);
3117 return inb(portp->ioaddr + EREG_DATA);
3120 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
3122 outb((regnr + portp->uartaddr), portp->ioaddr);
3123 outb(value, portp->ioaddr + EREG_DATA);
3126 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
3128 outb((regnr + portp->uartaddr), portp->ioaddr);
3129 if (inb(portp->ioaddr + EREG_DATA) != value) {
3130 outb(value, portp->ioaddr + EREG_DATA);
3136 /*****************************************************************************/
3139 * Inbitialize the UARTs in a panel. We don't care what sort of board
3140 * these ports are on - since the port io registers are almost
3141 * identical when dealing with ports.
3144 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3148 int nrchips, uartaddr, ioaddr;
3151 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
3154 BRDENABLE(panelp->brdnr, panelp->pagenr);
3157 * Check that each chip is present and started up OK.
3160 nrchips = panelp->nrports / CD1400_PORTS;
3161 for (i = 0; (i < nrchips); i++) {
3162 if (brdp->brdtype == BRD_ECHPCI) {
3163 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3164 ioaddr = panelp->iobase;
3166 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3168 uartaddr = (i & 0x01) ? 0x080 : 0;
3169 outb((GFRCR + uartaddr), ioaddr);
3170 outb(0, (ioaddr + EREG_DATA));
3171 outb((CCR + uartaddr), ioaddr);
3172 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3173 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3174 outb((GFRCR + uartaddr), ioaddr);
3175 for (j = 0; (j < CCR_MAXWAIT); j++) {
3176 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3179 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3180 printk("STALLION: cd1400 not responding, "
3181 "brd=%d panel=%d chip=%d\n",
3182 panelp->brdnr, panelp->panelnr, i);
3185 chipmask |= (0x1 << i);
3186 outb((PPR + uartaddr), ioaddr);
3187 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
3190 BRDDISABLE(panelp->brdnr);
3194 /*****************************************************************************/
3197 * Initialize hardware specific port registers.
3200 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3203 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3204 (int) brdp, (int) panelp, (int) portp);
3207 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
3208 (portp == (stlport_t *) NULL))
3211 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3212 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3213 portp->uartaddr = (portp->portnr & 0x04) << 5;
3214 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3216 BRDENABLE(portp->brdnr, portp->pagenr);
3217 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3218 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3219 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3220 BRDDISABLE(portp->brdnr);
3223 /*****************************************************************************/
3226 * Wait for the command register to be ready. We will poll this,
3227 * since it won't usually take too long to be ready.
3230 static void stl_cd1400ccrwait(stlport_t *portp)
3234 for (i = 0; (i < CCR_MAXWAIT); i++) {
3235 if (stl_cd1400getreg(portp, CCR) == 0) {
3240 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
3241 portp->portnr, portp->panelnr, portp->brdnr);
3244 /*****************************************************************************/
3247 * Set up the cd1400 registers for a port based on the termios port
3251 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3254 unsigned long flags;
3255 unsigned int clkdiv, baudrate;
3256 unsigned char cor1, cor2, cor3;
3257 unsigned char cor4, cor5, ccr;
3258 unsigned char srer, sreron, sreroff;
3259 unsigned char mcor1, mcor2, rtpr;
3260 unsigned char clk, div;
3276 brdp = stl_brds[portp->brdnr];
3277 if (brdp == (stlbrd_t *) NULL)
3281 * Set up the RX char ignore mask with those RX error types we
3282 * can ignore. We can get the cd1400 to help us out a little here,
3283 * it will ignore parity errors and breaks for us.
3285 portp->rxignoremsk = 0;
3286 if (tiosp->c_iflag & IGNPAR) {
3287 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
3288 cor1 |= COR1_PARIGNORE;
3290 if (tiosp->c_iflag & IGNBRK) {
3291 portp->rxignoremsk |= ST_BREAK;
3292 cor4 |= COR4_IGNBRK;
3295 portp->rxmarkmsk = ST_OVERRUN;
3296 if (tiosp->c_iflag & (INPCK | PARMRK))
3297 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3298 if (tiosp->c_iflag & BRKINT)
3299 portp->rxmarkmsk |= ST_BREAK;
3302 * Go through the char size, parity and stop bits and set all the
3303 * option register appropriately.
3305 switch (tiosp->c_cflag & CSIZE) {
3320 if (tiosp->c_cflag & CSTOPB)
3325 if (tiosp->c_cflag & PARENB) {
3326 if (tiosp->c_cflag & PARODD)
3327 cor1 |= (COR1_PARENB | COR1_PARODD);
3329 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3331 cor1 |= COR1_PARNONE;
3335 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3336 * space for hardware flow control and the like. This should be set to
3337 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3338 * really be based on VTIME.
3340 cor3 |= FIFO_RXTHRESHOLD;
3344 * Calculate the baud rate timers. For now we will just assume that
3345 * the input and output baud are the same. Could have used a baud
3346 * table here, but this way we can generate virtually any baud rate
3349 baudrate = tiosp->c_cflag & CBAUD;
3350 if (baudrate & CBAUDEX) {
3351 baudrate &= ~CBAUDEX;
3352 if ((baudrate < 1) || (baudrate > 4))
3353 tiosp->c_cflag &= ~CBAUDEX;
3357 baudrate = stl_baudrates[baudrate];
3358 if ((tiosp->c_cflag & CBAUD) == B38400) {
3359 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3361 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3363 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3365 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3367 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3368 baudrate = (portp->baud_base / portp->custom_divisor);
3370 if (baudrate > STL_CD1400MAXBAUD)
3371 baudrate = STL_CD1400MAXBAUD;
3374 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3375 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
3379 div = (unsigned char) clkdiv;
3383 * Check what form of modem signaling is required and set it up.
3385 if ((tiosp->c_cflag & CLOCAL) == 0) {
3388 sreron |= SRER_MODEM;
3389 portp->flags |= ASYNC_CHECK_CD;
3391 portp->flags &= ~ASYNC_CHECK_CD;
3395 * Setup cd1400 enhanced modes if we can. In particular we want to
3396 * handle as much of the flow control as possible automatically. As
3397 * well as saving a few CPU cycles it will also greatly improve flow
3398 * control reliability.
3400 if (tiosp->c_iflag & IXON) {
3403 if (tiosp->c_iflag & IXANY)
3407 if (tiosp->c_cflag & CRTSCTS) {
3409 mcor1 |= FIFO_RTSTHRESHOLD;
3413 * All cd1400 register values calculated so go through and set
3418 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3419 portp->portnr, portp->panelnr, portp->brdnr);
3420 printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3421 cor1, cor2, cor3, cor4, cor5);
3422 printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3423 mcor1, mcor2, rtpr, sreron, sreroff);
3424 printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3425 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3426 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3427 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3432 BRDENABLE(portp->brdnr, portp->pagenr);
3433 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3434 srer = stl_cd1400getreg(portp, SRER);
3435 stl_cd1400setreg(portp, SRER, 0);
3436 if (stl_cd1400updatereg(portp, COR1, cor1))
3438 if (stl_cd1400updatereg(portp, COR2, cor2))
3440 if (stl_cd1400updatereg(portp, COR3, cor3))
3443 stl_cd1400ccrwait(portp);
3444 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3446 stl_cd1400setreg(portp, COR4, cor4);
3447 stl_cd1400setreg(portp, COR5, cor5);
3448 stl_cd1400setreg(portp, MCOR1, mcor1);
3449 stl_cd1400setreg(portp, MCOR2, mcor2);
3451 stl_cd1400setreg(portp, TCOR, clk);
3452 stl_cd1400setreg(portp, TBPR, div);
3453 stl_cd1400setreg(portp, RCOR, clk);
3454 stl_cd1400setreg(portp, RBPR, div);
3456 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3457 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3458 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3459 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3460 stl_cd1400setreg(portp, RTPR, rtpr);
3461 mcor1 = stl_cd1400getreg(portp, MSVR1);
3462 if (mcor1 & MSVR1_DCD)
3463 portp->sigs |= TIOCM_CD;
3465 portp->sigs &= ~TIOCM_CD;
3466 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3467 BRDDISABLE(portp->brdnr);
3468 restore_flags(flags);
3471 /*****************************************************************************/
3474 * Set the state of the DTR and RTS signals.
3477 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3479 unsigned char msvr1, msvr2;
3480 unsigned long flags;
3483 printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
3484 (int) portp, dtr, rts);
3496 BRDENABLE(portp->brdnr, portp->pagenr);
3497 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3499 stl_cd1400setreg(portp, MSVR2, msvr2);
3501 stl_cd1400setreg(portp, MSVR1, msvr1);
3502 BRDDISABLE(portp->brdnr);
3503 restore_flags(flags);
3506 /*****************************************************************************/
3509 * Return the state of the signals.
3512 static int stl_cd1400getsignals(stlport_t *portp)
3514 unsigned char msvr1, msvr2;
3515 unsigned long flags;
3519 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3524 BRDENABLE(portp->brdnr, portp->pagenr);
3525 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3526 msvr1 = stl_cd1400getreg(portp, MSVR1);
3527 msvr2 = stl_cd1400getreg(portp, MSVR2);
3528 BRDDISABLE(portp->brdnr);
3529 restore_flags(flags);
3532 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3533 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3534 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3535 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3537 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3538 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3545 /*****************************************************************************/
3548 * Enable/Disable the Transmitter and/or Receiver.
3551 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3554 unsigned long flags;
3557 printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3558 (int) portp, rx, tx);
3563 ccr |= CCR_TXDISABLE;
3565 ccr |= CCR_TXENABLE;
3567 ccr |= CCR_RXDISABLE;
3569 ccr |= CCR_RXENABLE;
3573 BRDENABLE(portp->brdnr, portp->pagenr);
3574 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3575 stl_cd1400ccrwait(portp);
3576 stl_cd1400setreg(portp, CCR, ccr);
3577 stl_cd1400ccrwait(portp);
3578 BRDDISABLE(portp->brdnr);
3579 restore_flags(flags);
3582 /*****************************************************************************/
3585 * Start/stop the Transmitter and/or Receiver.
3588 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3590 unsigned char sreron, sreroff;
3591 unsigned long flags;
3594 printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3595 (int) portp, rx, tx);
3601 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3603 sreron |= SRER_TXDATA;
3605 sreron |= SRER_TXEMPTY;
3607 sreroff |= SRER_RXDATA;
3609 sreron |= SRER_RXDATA;
3613 BRDENABLE(portp->brdnr, portp->pagenr);
3614 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3615 stl_cd1400setreg(portp, SRER,
3616 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3617 BRDDISABLE(portp->brdnr);
3619 set_bit(ASYI_TXBUSY, &portp->istate);
3620 restore_flags(flags);
3623 /*****************************************************************************/
3626 * Disable all interrupts from this port.
3629 static void stl_cd1400disableintrs(stlport_t *portp)
3631 unsigned long flags;
3634 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3638 BRDENABLE(portp->brdnr, portp->pagenr);
3639 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3640 stl_cd1400setreg(portp, SRER, 0);
3641 BRDDISABLE(portp->brdnr);
3642 restore_flags(flags);
3645 /*****************************************************************************/
3647 static void stl_cd1400sendbreak(stlport_t *portp, int len)
3649 unsigned long flags;
3652 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
3657 BRDENABLE(portp->brdnr, portp->pagenr);
3658 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3659 stl_cd1400setreg(portp, SRER,
3660 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3662 BRDDISABLE(portp->brdnr);
3663 portp->brklen = len;
3665 portp->stats.txbreaks++;
3666 restore_flags(flags);
3669 /*****************************************************************************/
3672 * Take flow control actions...
3675 static void stl_cd1400flowctrl(stlport_t *portp, int state)
3677 struct tty_struct *tty;
3678 unsigned long flags;
3681 printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp, state);
3684 if (portp == (stlport_t *) NULL)
3687 if (tty == (struct tty_struct *) NULL)
3692 BRDENABLE(portp->brdnr, portp->pagenr);
3693 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3696 if (tty->termios->c_iflag & IXOFF) {
3697 stl_cd1400ccrwait(portp);
3698 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3699 portp->stats.rxxon++;
3700 stl_cd1400ccrwait(portp);
3703 * Question: should we return RTS to what it was before? It may
3704 * have been set by an ioctl... Suppose not, since if you have
3705 * hardware flow control set then it is pretty silly to go and
3706 * set the RTS line by hand.
3708 if (tty->termios->c_cflag & CRTSCTS) {
3709 stl_cd1400setreg(portp, MCOR1,
3710 (stl_cd1400getreg(portp, MCOR1) |
3711 FIFO_RTSTHRESHOLD));
3712 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3713 portp->stats.rxrtson++;
3716 if (tty->termios->c_iflag & IXOFF) {
3717 stl_cd1400ccrwait(portp);
3718 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3719 portp->stats.rxxoff++;
3720 stl_cd1400ccrwait(portp);
3722 if (tty->termios->c_cflag & CRTSCTS) {
3723 stl_cd1400setreg(portp, MCOR1,
3724 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3725 stl_cd1400setreg(portp, MSVR2, 0);
3726 portp->stats.rxrtsoff++;
3730 BRDDISABLE(portp->brdnr);
3731 restore_flags(flags);
3734 /*****************************************************************************/
3737 * Send a flow control character...
3740 static void stl_cd1400sendflow(stlport_t *portp, int state)
3742 struct tty_struct *tty;
3743 unsigned long flags;
3746 printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp, state);
3749 if (portp == (stlport_t *) NULL)
3752 if (tty == (struct tty_struct *) NULL)
3757 BRDENABLE(portp->brdnr, portp->pagenr);
3758 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3760 stl_cd1400ccrwait(portp);
3761 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3762 portp->stats.rxxon++;
3763 stl_cd1400ccrwait(portp);
3765 stl_cd1400ccrwait(portp);
3766 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3767 portp->stats.rxxoff++;
3768 stl_cd1400ccrwait(portp);
3770 BRDDISABLE(portp->brdnr);
3771 restore_flags(flags);
3774 /*****************************************************************************/
3776 static void stl_cd1400flush(stlport_t *portp)
3778 unsigned long flags;
3781 printk("stl_cd1400flush(portp=%x)\n", (int) portp);
3784 if (portp == (stlport_t *) NULL)
3789 BRDENABLE(portp->brdnr, portp->pagenr);
3790 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3791 stl_cd1400ccrwait(portp);
3792 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3793 stl_cd1400ccrwait(portp);
3794 portp->tx.tail = portp->tx.head;
3795 BRDDISABLE(portp->brdnr);
3796 restore_flags(flags);
3799 /*****************************************************************************/
3802 * Return the current state of data flow on this port. This is only
3803 * really interresting when determining if data has fully completed
3804 * transmission or not... This is easy for the cd1400, it accurately
3805 * maintains the busy port flag.
3808 static int stl_cd1400datastate(stlport_t *portp)
3811 printk("stl_cd1400datastate(portp=%x)\n", (int) portp);
3814 if (portp == (stlport_t *) NULL)
3817 return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
3820 /*****************************************************************************/
3823 * Interrupt service routine for cd1400 EasyIO boards.
3826 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3828 unsigned char svrtype;
3831 printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
3832 (int) panelp, iobase);
3836 svrtype = inb(iobase + EREG_DATA);
3837 if (panelp->nrports > 4) {
3838 outb((SVRR + 0x80), iobase);
3839 svrtype |= inb(iobase + EREG_DATA);
3842 if (svrtype & SVRR_RX)
3843 stl_cd1400rxisr(panelp, iobase);
3844 else if (svrtype & SVRR_TX)
3845 stl_cd1400txisr(panelp, iobase);
3846 else if (svrtype & SVRR_MDM)
3847 stl_cd1400mdmisr(panelp, iobase);
3850 /*****************************************************************************/
3853 * Interrupt service routine for cd1400 panels.
3856 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
3858 unsigned char svrtype;
3861 printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
3866 svrtype = inb(iobase + EREG_DATA);
3867 outb((SVRR + 0x80), iobase);
3868 svrtype |= inb(iobase + EREG_DATA);
3869 if (svrtype & SVRR_RX)
3870 stl_cd1400rxisr(panelp, iobase);
3871 else if (svrtype & SVRR_TX)
3872 stl_cd1400txisr(panelp, iobase);
3873 else if (svrtype & SVRR_MDM)
3874 stl_cd1400mdmisr(panelp, iobase);
3878 /*****************************************************************************/
3881 * Unfortunately we need to handle breaks in the TX data stream, since
3882 * this is the only way to generate them on the cd1400.
3885 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr)
3887 if (portp->brklen == 1) {
3888 outb((COR2 + portp->uartaddr), ioaddr);
3889 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
3890 (ioaddr + EREG_DATA));
3891 outb((TDR + portp->uartaddr), ioaddr);
3892 outb(ETC_CMD, (ioaddr + EREG_DATA));
3893 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
3894 outb((SRER + portp->uartaddr), ioaddr);
3895 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
3896 (ioaddr + EREG_DATA));
3898 } else if (portp->brklen > 1) {
3899 outb((TDR + portp->uartaddr), ioaddr);
3900 outb(ETC_CMD, (ioaddr + EREG_DATA));
3901 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
3905 outb((COR2 + portp->uartaddr), ioaddr);
3906 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
3907 (ioaddr + EREG_DATA));
3913 /*****************************************************************************/
3916 * Transmit interrupt handler. This has gotta be fast! Handling TX
3917 * chars is pretty simple, stuff as many as possible from the TX buffer
3918 * into the cd1400 FIFO. Must also handle TX breaks here, since they
3919 * are embedded as commands in the data stream. Oh no, had to use a goto!
3920 * This could be optimized more, will do when I get time...
3921 * In practice it is possible that interrupts are enabled but that the
3922 * port has been hung up. Need to handle not having any TX buffer here,
3923 * this is done by using the side effect that head and tail will also
3924 * be NULL if the buffer has been freed.
3927 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
3932 unsigned char ioack, srer;
3935 printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
3938 ioack = inb(ioaddr + EREG_TXACK);
3939 if (((ioack & panelp->ackmask) != 0) ||
3940 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
3941 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
3944 portp = panelp->ports[(ioack >> 3)];
3947 * Unfortunately we need to handle breaks in the data stream, since
3948 * this is the only way to generate them on the cd1400. Do it now if
3949 * a break is to be sent.
3951 if (portp->brklen != 0)
3952 if (stl_cd1400breakisr(portp, ioaddr))
3955 head = portp->tx.head;
3956 tail = portp->tx.tail;
3957 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
3958 if ((len == 0) || ((len < STL_TXBUFLOW) &&
3959 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
3960 set_bit(ASYI_TXLOW, &portp->istate);
3961 schedule_work(&portp->tqueue);
3965 outb((SRER + portp->uartaddr), ioaddr);
3966 srer = inb(ioaddr + EREG_DATA);
3967 if (srer & SRER_TXDATA) {
3968 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
3970 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
3971 clear_bit(ASYI_TXBUSY, &portp->istate);
3973 outb(srer, (ioaddr + EREG_DATA));
3975 len = MIN(len, CD1400_TXFIFOSIZE);
3976 portp->stats.txtotal += len;
3977 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
3978 outb((TDR + portp->uartaddr), ioaddr);
3979 outsb((ioaddr + EREG_DATA), tail, stlen);
3982 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
3983 tail = portp->tx.buf;
3985 outsb((ioaddr + EREG_DATA), tail, len);
3988 portp->tx.tail = tail;
3992 outb((EOSRR + portp->uartaddr), ioaddr);
3993 outb(0, (ioaddr + EREG_DATA));
3996 /*****************************************************************************/
3999 * Receive character interrupt handler. Determine if we have good chars
4000 * or bad chars and then process appropriately. Good chars are easy
4001 * just shove the lot into the RX buffer and set all status byte to 0.
4002 * If a bad RX char then process as required. This routine needs to be
4003 * fast! In practice it is possible that we get an interrupt on a port
4004 * that is closed. This can happen on hangups - since they completely
4005 * shutdown a port not in user context. Need to handle this case.
4008 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
4011 struct tty_struct *tty;
4012 unsigned int ioack, len, buflen;
4013 unsigned char status;
4017 printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
4020 ioack = inb(ioaddr + EREG_RXACK);
4021 if ((ioack & panelp->ackmask) != 0) {
4022 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4025 portp = panelp->ports[(ioack >> 3)];
4028 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
4029 outb((RDCR + portp->uartaddr), ioaddr);
4030 len = inb(ioaddr + EREG_DATA);
4031 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
4032 len = MIN(len, sizeof(stl_unwanted));
4033 outb((RDSR + portp->uartaddr), ioaddr);
4034 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
4035 portp->stats.rxlost += len;
4036 portp->stats.rxtotal += len;
4038 len = MIN(len, buflen);
4041 outb((RDSR + portp->uartaddr), ioaddr);
4042 tty_prepare_flip_string(tty, &ptr, len);
4043 insb((ioaddr + EREG_DATA), ptr, len);
4044 tty_schedule_flip(tty);
4045 portp->stats.rxtotal += len;
4048 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
4049 outb((RDSR + portp->uartaddr), ioaddr);
4050 status = inb(ioaddr + EREG_DATA);
4051 ch = inb(ioaddr + EREG_DATA);
4052 if (status & ST_PARITY)
4053 portp->stats.rxparity++;
4054 if (status & ST_FRAMING)
4055 portp->stats.rxframing++;
4056 if (status & ST_OVERRUN)
4057 portp->stats.rxoverrun++;
4058 if (status & ST_BREAK)
4059 portp->stats.rxbreaks++;
4060 if (status & ST_SCHARMASK) {
4061 if ((status & ST_SCHARMASK) == ST_SCHAR1)
4062 portp->stats.txxon++;
4063 if ((status & ST_SCHARMASK) == ST_SCHAR2)
4064 portp->stats.txxoff++;
4067 if (tty != NULL && (portp->rxignoremsk & status) == 0) {
4068 if (portp->rxmarkmsk & status) {
4069 if (status & ST_BREAK) {
4071 if (portp->flags & ASYNC_SAK) {
4073 BRDENABLE(portp->brdnr, portp->pagenr);
4075 } else if (status & ST_PARITY) {
4076 status = TTY_PARITY;
4077 } else if (status & ST_FRAMING) {
4079 } else if(status & ST_OVERRUN) {
4080 status = TTY_OVERRUN;
4087 tty_insert_flip_char(tty, ch, status);
4088 tty_schedule_flip(tty);
4091 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4096 outb((EOSRR + portp->uartaddr), ioaddr);
4097 outb(0, (ioaddr + EREG_DATA));
4100 /*****************************************************************************/
4103 * Modem interrupt handler. The is called when the modem signal line
4104 * (DCD) has changed state. Leave most of the work to the off-level
4105 * processing routine.
4108 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
4115 printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp);
4118 ioack = inb(ioaddr + EREG_MDACK);
4119 if (((ioack & panelp->ackmask) != 0) ||
4120 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
4121 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
4124 portp = panelp->ports[(ioack >> 3)];
4126 outb((MISR + portp->uartaddr), ioaddr);
4127 misr = inb(ioaddr + EREG_DATA);
4128 if (misr & MISR_DCD) {
4129 set_bit(ASYI_DCDCHANGE, &portp->istate);
4130 schedule_work(&portp->tqueue);
4131 portp->stats.modem++;
4134 outb((EOSRR + portp->uartaddr), ioaddr);
4135 outb(0, (ioaddr + EREG_DATA));
4138 /*****************************************************************************/
4139 /* SC26198 HARDWARE FUNCTIONS */
4140 /*****************************************************************************/
4143 * These functions get/set/update the registers of the sc26198 UARTs.
4144 * Access to the sc26198 registers is via an address/data io port pair.
4145 * (Maybe should make this inline...)
4148 static int stl_sc26198getreg(stlport_t *portp, int regnr)
4150 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4151 return inb(portp->ioaddr + XP_DATA);
4154 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
4156 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4157 outb(value, (portp->ioaddr + XP_DATA));
4160 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
4162 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4163 if (inb(portp->ioaddr + XP_DATA) != value) {
4164 outb(value, (portp->ioaddr + XP_DATA));
4170 /*****************************************************************************/
4173 * Functions to get and set the sc26198 global registers.
4176 static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
4178 outb(regnr, (portp->ioaddr + XP_ADDR));
4179 return inb(portp->ioaddr + XP_DATA);
4183 static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
4185 outb(regnr, (portp->ioaddr + XP_ADDR));
4186 outb(value, (portp->ioaddr + XP_DATA));
4190 /*****************************************************************************/
4193 * Inbitialize the UARTs in a panel. We don't care what sort of board
4194 * these ports are on - since the port io registers are almost
4195 * identical when dealing with ports.
4198 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
4201 int nrchips, ioaddr;
4204 printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
4205 (int) brdp, (int) panelp);
4208 BRDENABLE(panelp->brdnr, panelp->pagenr);
4211 * Check that each chip is present and started up OK.
4214 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
4215 if (brdp->brdtype == BRD_ECHPCI)
4216 outb(panelp->pagenr, brdp->ioctrl);
4218 for (i = 0; (i < nrchips); i++) {
4219 ioaddr = panelp->iobase + (i * 4);
4220 outb(SCCR, (ioaddr + XP_ADDR));
4221 outb(CR_RESETALL, (ioaddr + XP_DATA));
4222 outb(TSTR, (ioaddr + XP_ADDR));
4223 if (inb(ioaddr + XP_DATA) != 0) {
4224 printk("STALLION: sc26198 not responding, "
4225 "brd=%d panel=%d chip=%d\n",
4226 panelp->brdnr, panelp->panelnr, i);
4229 chipmask |= (0x1 << i);
4230 outb(GCCR, (ioaddr + XP_ADDR));
4231 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
4232 outb(WDTRCR, (ioaddr + XP_ADDR));
4233 outb(0xff, (ioaddr + XP_DATA));
4236 BRDDISABLE(panelp->brdnr);
4240 /*****************************************************************************/
4243 * Initialize hardware specific port registers.
4246 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
4249 printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
4250 (int) brdp, (int) panelp, (int) portp);
4253 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
4254 (portp == (stlport_t *) NULL))
4257 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
4258 portp->uartaddr = (portp->portnr & 0x07) << 4;
4259 portp->pagenr = panelp->pagenr;
4262 BRDENABLE(portp->brdnr, portp->pagenr);
4263 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
4264 BRDDISABLE(portp->brdnr);
4267 /*****************************************************************************/
4270 * Set up the sc26198 registers for a port based on the termios port
4274 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4277 unsigned long flags;
4278 unsigned int baudrate;
4279 unsigned char mr0, mr1, mr2, clk;
4280 unsigned char imron, imroff, iopr, ipr;
4290 brdp = stl_brds[portp->brdnr];
4291 if (brdp == (stlbrd_t *) NULL)
4295 * Set up the RX char ignore mask with those RX error types we
4298 portp->rxignoremsk = 0;
4299 if (tiosp->c_iflag & IGNPAR)
4300 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
4302 if (tiosp->c_iflag & IGNBRK)
4303 portp->rxignoremsk |= SR_RXBREAK;
4305 portp->rxmarkmsk = SR_RXOVERRUN;
4306 if (tiosp->c_iflag & (INPCK | PARMRK))
4307 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
4308 if (tiosp->c_iflag & BRKINT)
4309 portp->rxmarkmsk |= SR_RXBREAK;
4312 * Go through the char size, parity and stop bits and set all the
4313 * option register appropriately.
4315 switch (tiosp->c_cflag & CSIZE) {
4330 if (tiosp->c_cflag & CSTOPB)
4335 if (tiosp->c_cflag & PARENB) {
4336 if (tiosp->c_cflag & PARODD)
4337 mr1 |= (MR1_PARENB | MR1_PARODD);
4339 mr1 |= (MR1_PARENB | MR1_PAREVEN);
4344 mr1 |= MR1_ERRBLOCK;
4347 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4348 * space for hardware flow control and the like. This should be set to
4351 mr2 |= MR2_RXFIFOHALF;
4354 * Calculate the baud rate timers. For now we will just assume that
4355 * the input and output baud are the same. The sc26198 has a fixed
4356 * baud rate table, so only discrete baud rates possible.
4358 baudrate = tiosp->c_cflag & CBAUD;
4359 if (baudrate & CBAUDEX) {
4360 baudrate &= ~CBAUDEX;
4361 if ((baudrate < 1) || (baudrate > 4))
4362 tiosp->c_cflag &= ~CBAUDEX;
4366 baudrate = stl_baudrates[baudrate];
4367 if ((tiosp->c_cflag & CBAUD) == B38400) {
4368 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
4370 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
4372 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
4374 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
4376 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
4377 baudrate = (portp->baud_base / portp->custom_divisor);
4379 if (baudrate > STL_SC26198MAXBAUD)
4380 baudrate = STL_SC26198MAXBAUD;
4383 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
4384 if (baudrate <= sc26198_baudtable[clk])
4390 * Check what form of modem signaling is required and set it up.
4392 if (tiosp->c_cflag & CLOCAL) {
4393 portp->flags &= ~ASYNC_CHECK_CD;
4395 iopr |= IOPR_DCDCOS;
4397 portp->flags |= ASYNC_CHECK_CD;
4401 * Setup sc26198 enhanced modes if we can. In particular we want to
4402 * handle as much of the flow control as possible automatically. As
4403 * well as saving a few CPU cycles it will also greatly improve flow
4404 * control reliability.
4406 if (tiosp->c_iflag & IXON) {
4407 mr0 |= MR0_SWFTX | MR0_SWFT;
4408 imron |= IR_XONXOFF;
4410 imroff |= IR_XONXOFF;
4412 if (tiosp->c_iflag & IXOFF)
4415 if (tiosp->c_cflag & CRTSCTS) {
4421 * All sc26198 register values calculated so go through and set
4426 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4427 portp->portnr, portp->panelnr, portp->brdnr);
4428 printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4429 printk(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4430 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4431 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4432 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4437 BRDENABLE(portp->brdnr, portp->pagenr);
4438 stl_sc26198setreg(portp, IMR, 0);
4439 stl_sc26198updatereg(portp, MR0, mr0);
4440 stl_sc26198updatereg(portp, MR1, mr1);
4441 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4442 stl_sc26198updatereg(portp, MR2, mr2);
4443 stl_sc26198updatereg(portp, IOPIOR,
4444 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
4447 stl_sc26198setreg(portp, TXCSR, clk);
4448 stl_sc26198setreg(portp, RXCSR, clk);
4451 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4452 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4454 ipr = stl_sc26198getreg(portp, IPR);
4456 portp->sigs &= ~TIOCM_CD;
4458 portp->sigs |= TIOCM_CD;
4460 portp->imr = (portp->imr & ~imroff) | imron;
4461 stl_sc26198setreg(portp, IMR, portp->imr);
4462 BRDDISABLE(portp->brdnr);
4463 restore_flags(flags);
4466 /*****************************************************************************/
4469 * Set the state of the DTR and RTS signals.
4472 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
4474 unsigned char iopioron, iopioroff;
4475 unsigned long flags;
4478 printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4479 (int) portp, dtr, rts);
4485 iopioroff |= IPR_DTR;
4487 iopioron |= IPR_DTR;
4489 iopioroff |= IPR_RTS;
4491 iopioron |= IPR_RTS;
4495 BRDENABLE(portp->brdnr, portp->pagenr);
4496 stl_sc26198setreg(portp, IOPIOR,
4497 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4498 BRDDISABLE(portp->brdnr);
4499 restore_flags(flags);
4502 /*****************************************************************************/
4505 * Return the state of the signals.
4508 static int stl_sc26198getsignals(stlport_t *portp)
4511 unsigned long flags;
4515 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
4520 BRDENABLE(portp->brdnr, portp->pagenr);
4521 ipr = stl_sc26198getreg(portp, IPR);
4522 BRDDISABLE(portp->brdnr);
4523 restore_flags(flags);
4526 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4527 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4528 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4529 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4534 /*****************************************************************************/
4537 * Enable/Disable the Transmitter and/or Receiver.
4540 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
4543 unsigned long flags;
4546 printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4547 (int) portp, rx, tx);
4550 ccr = portp->crenable;
4552 ccr &= ~CR_TXENABLE;
4556 ccr &= ~CR_RXENABLE;
4562 BRDENABLE(portp->brdnr, portp->pagenr);
4563 stl_sc26198setreg(portp, SCCR, ccr);
4564 BRDDISABLE(portp->brdnr);
4565 portp->crenable = ccr;
4566 restore_flags(flags);
4569 /*****************************************************************************/
4572 * Start/stop the Transmitter and/or Receiver.
4575 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
4578 unsigned long flags;
4581 printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4582 (int) portp, rx, tx);
4591 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4593 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4597 BRDENABLE(portp->brdnr, portp->pagenr);
4598 stl_sc26198setreg(portp, IMR, imr);
4599 BRDDISABLE(portp->brdnr);
4602 set_bit(ASYI_TXBUSY, &portp->istate);
4603 restore_flags(flags);
4606 /*****************************************************************************/
4609 * Disable all interrupts from this port.
4612 static void stl_sc26198disableintrs(stlport_t *portp)
4614 unsigned long flags;
4617 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
4622 BRDENABLE(portp->brdnr, portp->pagenr);
4624 stl_sc26198setreg(portp, IMR, 0);
4625 BRDDISABLE(portp->brdnr);
4626 restore_flags(flags);
4629 /*****************************************************************************/
4631 static void stl_sc26198sendbreak(stlport_t *portp, int len)
4633 unsigned long flags;
4636 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
4641 BRDENABLE(portp->brdnr, portp->pagenr);
4643 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4644 portp->stats.txbreaks++;
4646 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4648 BRDDISABLE(portp->brdnr);
4649 restore_flags(flags);
4652 /*****************************************************************************/
4655 * Take flow control actions...
4658 static void stl_sc26198flowctrl(stlport_t *portp, int state)
4660 struct tty_struct *tty;
4661 unsigned long flags;
4665 printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp, state);
4668 if (portp == (stlport_t *) NULL)
4671 if (tty == (struct tty_struct *) NULL)
4676 BRDENABLE(portp->brdnr, portp->pagenr);
4679 if (tty->termios->c_iflag & IXOFF) {
4680 mr0 = stl_sc26198getreg(portp, MR0);
4681 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4682 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4684 portp->stats.rxxon++;
4685 stl_sc26198wait(portp);
4686 stl_sc26198setreg(portp, MR0, mr0);
4689 * Question: should we return RTS to what it was before? It may
4690 * have been set by an ioctl... Suppose not, since if you have
4691 * hardware flow control set then it is pretty silly to go and
4692 * set the RTS line by hand.
4694 if (tty->termios->c_cflag & CRTSCTS) {
4695 stl_sc26198setreg(portp, MR1,
4696 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4697 stl_sc26198setreg(portp, IOPIOR,
4698 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4699 portp->stats.rxrtson++;
4702 if (tty->termios->c_iflag & IXOFF) {
4703 mr0 = stl_sc26198getreg(portp, MR0);
4704 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4705 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4707 portp->stats.rxxoff++;
4708 stl_sc26198wait(portp);
4709 stl_sc26198setreg(portp, MR0, mr0);
4711 if (tty->termios->c_cflag & CRTSCTS) {
4712 stl_sc26198setreg(portp, MR1,
4713 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4714 stl_sc26198setreg(portp, IOPIOR,
4715 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4716 portp->stats.rxrtsoff++;
4720 BRDDISABLE(portp->brdnr);
4721 restore_flags(flags);
4724 /*****************************************************************************/
4727 * Send a flow control character.
4730 static void stl_sc26198sendflow(stlport_t *portp, int state)
4732 struct tty_struct *tty;
4733 unsigned long flags;
4737 printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp, state);
4740 if (portp == (stlport_t *) NULL)
4743 if (tty == (struct tty_struct *) NULL)
4748 BRDENABLE(portp->brdnr, portp->pagenr);
4750 mr0 = stl_sc26198getreg(portp, MR0);
4751 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4752 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4754 portp->stats.rxxon++;
4755 stl_sc26198wait(portp);
4756 stl_sc26198setreg(portp, MR0, mr0);
4758 mr0 = stl_sc26198getreg(portp, MR0);
4759 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4760 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4762 portp->stats.rxxoff++;
4763 stl_sc26198wait(portp);
4764 stl_sc26198setreg(portp, MR0, mr0);
4766 BRDDISABLE(portp->brdnr);
4767 restore_flags(flags);
4770 /*****************************************************************************/
4772 static void stl_sc26198flush(stlport_t *portp)
4774 unsigned long flags;
4777 printk("stl_sc26198flush(portp=%x)\n", (int) portp);
4780 if (portp == (stlport_t *) NULL)
4785 BRDENABLE(portp->brdnr, portp->pagenr);
4786 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4787 stl_sc26198setreg(portp, SCCR, portp->crenable);
4788 BRDDISABLE(portp->brdnr);
4789 portp->tx.tail = portp->tx.head;
4790 restore_flags(flags);
4793 /*****************************************************************************/
4796 * Return the current state of data flow on this port. This is only
4797 * really interresting when determining if data has fully completed
4798 * transmission or not... The sc26198 interrupt scheme cannot
4799 * determine when all data has actually drained, so we need to
4800 * check the port statusy register to be sure.
4803 static int stl_sc26198datastate(stlport_t *portp)
4805 unsigned long flags;
4809 printk("stl_sc26198datastate(portp=%x)\n", (int) portp);
4812 if (portp == (stlport_t *) NULL)
4814 if (test_bit(ASYI_TXBUSY, &portp->istate))
4819 BRDENABLE(portp->brdnr, portp->pagenr);
4820 sr = stl_sc26198getreg(portp, SR);
4821 BRDDISABLE(portp->brdnr);
4822 restore_flags(flags);
4824 return (sr & SR_TXEMPTY) ? 0 : 1;
4827 /*****************************************************************************/
4830 * Delay for a small amount of time, to give the sc26198 a chance
4831 * to process a command...
4834 static void stl_sc26198wait(stlport_t *portp)
4839 printk("stl_sc26198wait(portp=%x)\n", (int) portp);
4842 if (portp == (stlport_t *) NULL)
4845 for (i = 0; (i < 20); i++)
4846 stl_sc26198getglobreg(portp, TSTR);
4849 /*****************************************************************************/
4852 * If we are TX flow controlled and in IXANY mode then we may
4853 * need to unflow control here. We gotta do this because of the
4854 * automatic flow control modes of the sc26198.
4857 static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty)
4861 mr0 = stl_sc26198getreg(portp, MR0);
4862 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4863 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4864 stl_sc26198wait(portp);
4865 stl_sc26198setreg(portp, MR0, mr0);
4866 clear_bit(ASYI_TXFLOWED, &portp->istate);
4869 /*****************************************************************************/
4872 * Interrupt service routine for sc26198 panels.
4875 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4881 * Work around bug in sc26198 chip... Cannot have A6 address
4882 * line of UART high, else iack will be returned as 0.
4884 outb(0, (iobase + 1));
4886 iack = inb(iobase + XP_IACK);
4887 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4889 if (iack & IVR_RXDATA)
4890 stl_sc26198rxisr(portp, iack);
4891 else if (iack & IVR_TXDATA)
4892 stl_sc26198txisr(portp);
4894 stl_sc26198otherisr(portp, iack);
4897 /*****************************************************************************/
4900 * Transmit interrupt handler. This has gotta be fast! Handling TX
4901 * chars is pretty simple, stuff as many as possible from the TX buffer
4902 * into the sc26198 FIFO.
4903 * In practice it is possible that interrupts are enabled but that the
4904 * port has been hung up. Need to handle not having any TX buffer here,
4905 * this is done by using the side effect that head and tail will also
4906 * be NULL if the buffer has been freed.
4909 static void stl_sc26198txisr(stlport_t *portp)
4911 unsigned int ioaddr;
4917 printk("stl_sc26198txisr(portp=%x)\n", (int) portp);
4920 ioaddr = portp->ioaddr;
4921 head = portp->tx.head;
4922 tail = portp->tx.tail;
4923 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4924 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4925 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4926 set_bit(ASYI_TXLOW, &portp->istate);
4927 schedule_work(&portp->tqueue);
4931 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
4932 mr0 = inb(ioaddr + XP_DATA);
4933 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4934 portp->imr &= ~IR_TXRDY;
4935 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
4936 outb(portp->imr, (ioaddr + XP_DATA));
4937 clear_bit(ASYI_TXBUSY, &portp->istate);
4939 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4940 outb(mr0, (ioaddr + XP_DATA));
4943 len = MIN(len, SC26198_TXFIFOSIZE);
4944 portp->stats.txtotal += len;
4945 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4946 outb(GTXFIFO, (ioaddr + XP_ADDR));
4947 outsb((ioaddr + XP_DATA), tail, stlen);
4950 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4951 tail = portp->tx.buf;
4953 outsb((ioaddr + XP_DATA), tail, len);
4956 portp->tx.tail = tail;
4960 /*****************************************************************************/
4963 * Receive character interrupt handler. Determine if we have good chars
4964 * or bad chars and then process appropriately. Good chars are easy
4965 * just shove the lot into the RX buffer and set all status byte to 0.
4966 * If a bad RX char then process as required. This routine needs to be
4967 * fast! In practice it is possible that we get an interrupt on a port
4968 * that is closed. This can happen on hangups - since they completely
4969 * shutdown a port not in user context. Need to handle this case.
4972 static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
4974 struct tty_struct *tty;
4975 unsigned int len, buflen, ioaddr;
4978 printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
4982 ioaddr = portp->ioaddr;
4983 outb(GIBCR, (ioaddr + XP_ADDR));
4984 len = inb(ioaddr + XP_DATA) + 1;
4986 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
4987 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
4988 len = MIN(len, sizeof(stl_unwanted));
4989 outb(GRXFIFO, (ioaddr + XP_ADDR));
4990 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4991 portp->stats.rxlost += len;
4992 portp->stats.rxtotal += len;
4994 len = MIN(len, buflen);
4997 outb(GRXFIFO, (ioaddr + XP_ADDR));
4998 tty_prepare_flip_string(tty, &ptr, len);
4999 insb((ioaddr + XP_DATA), ptr, len);
5000 tty_schedule_flip(tty);
5001 portp->stats.rxtotal += len;
5005 stl_sc26198rxbadchars(portp);
5009 * If we are TX flow controlled and in IXANY mode then we may need
5010 * to unflow control here. We gotta do this because of the automatic
5011 * flow control modes of the sc26198.
5013 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
5014 if ((tty != (struct tty_struct *) NULL) &&
5015 (tty->termios != (struct termios *) NULL) &&
5016 (tty->termios->c_iflag & IXANY)) {
5017 stl_sc26198txunflow(portp, tty);
5022 /*****************************************************************************/
5025 * Process an RX bad character.
5028 static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch)
5030 struct tty_struct *tty;
5031 unsigned int ioaddr;
5034 ioaddr = portp->ioaddr;
5036 if (status & SR_RXPARITY)
5037 portp->stats.rxparity++;
5038 if (status & SR_RXFRAMING)
5039 portp->stats.rxframing++;
5040 if (status & SR_RXOVERRUN)
5041 portp->stats.rxoverrun++;
5042 if (status & SR_RXBREAK)
5043 portp->stats.rxbreaks++;
5045 if ((tty != (struct tty_struct *) NULL) &&
5046 ((portp->rxignoremsk & status) == 0)) {
5047 if (portp->rxmarkmsk & status) {
5048 if (status & SR_RXBREAK) {
5050 if (portp->flags & ASYNC_SAK) {
5052 BRDENABLE(portp->brdnr, portp->pagenr);
5054 } else if (status & SR_RXPARITY) {
5055 status = TTY_PARITY;
5056 } else if (status & SR_RXFRAMING) {
5058 } else if(status & SR_RXOVERRUN) {
5059 status = TTY_OVERRUN;
5067 tty_insert_flip_char(tty, ch, status);
5068 tty_schedule_flip(tty);
5071 portp->stats.rxtotal++;
5075 /*****************************************************************************/
5078 * Process all characters in the RX FIFO of the UART. Check all char
5079 * status bytes as well, and process as required. We need to check
5080 * all bytes in the FIFO, in case some more enter the FIFO while we
5081 * are here. To get the exact character error type we need to switch
5082 * into CHAR error mode (that is why we need to make sure we empty
5086 static void stl_sc26198rxbadchars(stlport_t *portp)
5088 unsigned char status, mr1;
5092 * To get the precise error type for each character we must switch
5093 * back into CHAR error mode.
5095 mr1 = stl_sc26198getreg(portp, MR1);
5096 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
5098 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
5099 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
5100 ch = stl_sc26198getreg(portp, RXFIFO);
5101 stl_sc26198rxbadch(portp, status, ch);
5105 * To get correct interrupt class we must switch back into BLOCK
5108 stl_sc26198setreg(portp, MR1, mr1);
5111 /*****************************************************************************/
5114 * Other interrupt handler. This includes modem signals, flow
5115 * control actions, etc. Most stuff is left to off-level interrupt
5119 static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
5121 unsigned char cir, ipr, xisr;
5124 printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
5127 cir = stl_sc26198getglobreg(portp, CIR);
5129 switch (cir & CIR_SUBTYPEMASK) {
5131 ipr = stl_sc26198getreg(portp, IPR);
5132 if (ipr & IPR_DCDCHANGE) {
5133 set_bit(ASYI_DCDCHANGE, &portp->istate);
5134 schedule_work(&portp->tqueue);
5135 portp->stats.modem++;
5138 case CIR_SUBXONXOFF:
5139 xisr = stl_sc26198getreg(portp, XISR);
5140 if (xisr & XISR_RXXONGOT) {
5141 set_bit(ASYI_TXFLOWED, &portp->istate);
5142 portp->stats.txxoff++;
5144 if (xisr & XISR_RXXOFFGOT) {
5145 clear_bit(ASYI_TXFLOWED, &portp->istate);
5146 portp->stats.txxon++;
5150 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
5151 stl_sc26198rxbadchars(portp);
5158 /*****************************************************************************/