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 * Define a local default termios struct. All ports will be created
145 * with this termios initially. Basically all it defines is a raw port
146 * at 9600, 8 data bits, 1 stop bit.
148 static struct termios stl_deftermios = {
149 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
154 * Define global stats structures. Not used often, and can be
155 * re-used for each stats call.
157 static comstats_t stl_comstats;
158 static combrd_t stl_brdstats;
159 static stlbrd_t stl_dummybrd;
160 static stlport_t stl_dummyport;
163 * Define global place to put buffer overflow characters.
165 static char stl_unwanted[SC26198_RXFIFOSIZE];
167 /*****************************************************************************/
169 static stlbrd_t *stl_brds[STL_MAXBRDS];
172 * Per board state flags. Used with the state field of the board struct.
173 * Not really much here!
175 #define BRD_FOUND 0x1
178 * Define the port structure istate flags. These set of flags are
179 * modified at interrupt time - so setting and reseting them needs
180 * to be atomic. Use the bit clear/setting routines for this.
182 #define ASYI_TXBUSY 1
184 #define ASYI_DCDCHANGE 3
185 #define ASYI_TXFLOWED 4
188 * Define an array of board names as printable strings. Handy for
189 * referencing boards when printing trace and stuff.
191 static char *stl_brdnames[] = {
223 /*****************************************************************************/
226 * Define some string labels for arguments passed from the module
227 * load line. These allow for easy board definitions, and easy
228 * modification of the io, memory and irq resoucres.
230 static int stl_nargs = 0;
231 static char *board0[4];
232 static char *board1[4];
233 static char *board2[4];
234 static char *board3[4];
236 static char **stl_brdsp[] = {
244 * Define a set of common board names, and types. This is used to
245 * parse any module arguments.
248 typedef struct stlbrdtype {
253 static stlbrdtype_t stl_brdstr[] = {
254 { "easyio", BRD_EASYIO },
255 { "eio", BRD_EASYIO },
256 { "20", BRD_EASYIO },
257 { "ec8/32", BRD_ECH },
258 { "ec8/32-at", BRD_ECH },
259 { "ec8/32-isa", BRD_ECH },
261 { "echat", BRD_ECH },
263 { "ec8/32-mc", BRD_ECHMC },
264 { "ec8/32-mca", BRD_ECHMC },
265 { "echmc", BRD_ECHMC },
266 { "echmca", BRD_ECHMC },
268 { "ec8/32-pc", BRD_ECHPCI },
269 { "ec8/32-pci", BRD_ECHPCI },
270 { "26", BRD_ECHPCI },
271 { "ec8/64-pc", BRD_ECH64PCI },
272 { "ec8/64-pci", BRD_ECH64PCI },
273 { "ech-pci", BRD_ECH64PCI },
274 { "echpci", BRD_ECH64PCI },
275 { "echpc", BRD_ECH64PCI },
276 { "27", BRD_ECH64PCI },
277 { "easyio-pc", BRD_EASYIOPCI },
278 { "easyio-pci", BRD_EASYIOPCI },
279 { "eio-pci", BRD_EASYIOPCI },
280 { "eiopci", BRD_EASYIOPCI },
281 { "28", BRD_EASYIOPCI },
285 * Define the module agruments.
287 MODULE_AUTHOR("Greg Ungerer");
288 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
289 MODULE_LICENSE("GPL");
291 module_param_array(board0, charp, &stl_nargs, 0);
292 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
293 module_param_array(board1, charp, &stl_nargs, 0);
294 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
295 module_param_array(board2, charp, &stl_nargs, 0);
296 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
297 module_param_array(board3, charp, &stl_nargs, 0);
298 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
300 /*****************************************************************************/
303 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
304 * to the directly accessible io ports of these boards (not the uarts -
305 * they are in cd1400.h and sc26198.h).
307 #define EIO_8PORTRS 0x04
308 #define EIO_4PORTRS 0x05
309 #define EIO_8PORTDI 0x00
310 #define EIO_8PORTM 0x06
312 #define EIO_IDBITMASK 0x07
314 #define EIO_BRDMASK 0xf0
317 #define ID_BRD16 0x30
319 #define EIO_INTRPEND 0x08
320 #define EIO_INTEDGE 0x00
321 #define EIO_INTLEVEL 0x08
325 #define ECH_IDBITMASK 0xe0
326 #define ECH_BRDENABLE 0x08
327 #define ECH_BRDDISABLE 0x00
328 #define ECH_INTENABLE 0x01
329 #define ECH_INTDISABLE 0x00
330 #define ECH_INTLEVEL 0x02
331 #define ECH_INTEDGE 0x00
332 #define ECH_INTRPEND 0x01
333 #define ECH_BRDRESET 0x01
335 #define ECHMC_INTENABLE 0x01
336 #define ECHMC_BRDRESET 0x02
338 #define ECH_PNLSTATUS 2
339 #define ECH_PNL16PORT 0x20
340 #define ECH_PNLIDMASK 0x07
341 #define ECH_PNLXPID 0x40
342 #define ECH_PNLINTRPEND 0x80
344 #define ECH_ADDR2MASK 0x1e0
347 * Define the vector mapping bits for the programmable interrupt board
348 * hardware. These bits encode the interrupt for the board to use - it
349 * is software selectable (except the EIO-8M).
351 static unsigned char stl_vecmap[] = {
352 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
353 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
357 * Lock ordering is that you may not take stallion_lock holding
361 static spinlock_t brd_lock; /* Guard the board mapping */
362 static spinlock_t stallion_lock; /* Guard the tty driver */
365 * Set up enable and disable macros for the ECH boards. They require
366 * the secondary io address space to be activated and deactivated.
367 * This way all ECH boards can share their secondary io region.
368 * If this is an ECH-PCI board then also need to set the page pointer
369 * to point to the correct page.
371 #define BRDENABLE(brdnr,pagenr) \
372 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
373 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
374 stl_brds[(brdnr)]->ioctrl); \
375 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
376 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
378 #define BRDDISABLE(brdnr) \
379 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
380 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
381 stl_brds[(brdnr)]->ioctrl);
383 #define STL_CD1400MAXBAUD 230400
384 #define STL_SC26198MAXBAUD 460800
386 #define STL_BAUDBASE 115200
387 #define STL_CLOSEDELAY (5 * HZ / 10)
389 /*****************************************************************************/
394 * Define the Stallion PCI vendor and device IDs.
396 #ifndef PCI_VENDOR_ID_STALLION
397 #define PCI_VENDOR_ID_STALLION 0x124d
399 #ifndef PCI_DEVICE_ID_ECHPCI832
400 #define PCI_DEVICE_ID_ECHPCI832 0x0000
402 #ifndef PCI_DEVICE_ID_ECHPCI864
403 #define PCI_DEVICE_ID_ECHPCI864 0x0002
405 #ifndef PCI_DEVICE_ID_EIOPCI
406 #define PCI_DEVICE_ID_EIOPCI 0x0003
410 * Define structure to hold all Stallion PCI boards.
412 typedef struct stlpcibrd {
413 unsigned short vendid;
414 unsigned short devid;
418 static stlpcibrd_t stl_pcibrds[] = {
419 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864, BRD_ECH64PCI },
420 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI, BRD_EASYIOPCI },
421 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832, BRD_ECHPCI },
422 { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
425 static int stl_nrpcibrds = ARRAY_SIZE(stl_pcibrds);
429 /*****************************************************************************/
432 * Define macros to extract a brd/port number from a minor number.
434 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
435 #define MINOR2PORT(min) ((min) & 0x3f)
438 * Define a baud rate table that converts termios baud rate selector
439 * into the actual baud rate value. All baud rate calculations are
440 * based on the actual baud rate required.
442 static unsigned int stl_baudrates[] = {
443 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
444 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
448 * Define some handy local macros...
451 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
454 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
456 /*****************************************************************************/
459 * Declare all those functions in this driver!
462 static void stl_argbrds(void);
463 static int stl_parsebrd(stlconf_t *confp, char **argp);
465 static unsigned long stl_atol(char *str);
467 static int stl_init(void);
468 static int stl_open(struct tty_struct *tty, struct file *filp);
469 static void stl_close(struct tty_struct *tty, struct file *filp);
470 static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count);
471 static void stl_putchar(struct tty_struct *tty, unsigned char ch);
472 static void stl_flushchars(struct tty_struct *tty);
473 static int stl_writeroom(struct tty_struct *tty);
474 static int stl_charsinbuffer(struct tty_struct *tty);
475 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
476 static void stl_settermios(struct tty_struct *tty, struct termios *old);
477 static void stl_throttle(struct tty_struct *tty);
478 static void stl_unthrottle(struct tty_struct *tty);
479 static void stl_stop(struct tty_struct *tty);
480 static void stl_start(struct tty_struct *tty);
481 static void stl_flushbuffer(struct tty_struct *tty);
482 static void stl_breakctl(struct tty_struct *tty, int state);
483 static void stl_waituntilsent(struct tty_struct *tty, int timeout);
484 static void stl_sendxchar(struct tty_struct *tty, char ch);
485 static void stl_hangup(struct tty_struct *tty);
486 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
487 static int stl_portinfo(stlport_t *portp, int portnr, char *pos);
488 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data);
490 static int stl_brdinit(stlbrd_t *brdp);
491 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
492 static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp);
493 static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp);
494 static int stl_getbrdstats(combrd_t __user *bp);
495 static int stl_getportstats(stlport_t *portp, comstats_t __user *cp);
496 static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp);
497 static int stl_getportstruct(stlport_t __user *arg);
498 static int stl_getbrdstruct(stlbrd_t __user *arg);
499 static int stl_waitcarrier(stlport_t *portp, struct file *filp);
500 static int stl_eiointr(stlbrd_t *brdp);
501 static int stl_echatintr(stlbrd_t *brdp);
502 static int stl_echmcaintr(stlbrd_t *brdp);
503 static int stl_echpciintr(stlbrd_t *brdp);
504 static int stl_echpci64intr(stlbrd_t *brdp);
505 static void stl_offintr(void *private);
506 static stlbrd_t *stl_allocbrd(void);
507 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
509 static inline int stl_initbrds(void);
510 static inline int stl_initeio(stlbrd_t *brdp);
511 static inline int stl_initech(stlbrd_t *brdp);
512 static inline int stl_getbrdnr(void);
515 static inline int stl_findpcibrds(void);
516 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp);
520 * CD1400 uart specific handling functions.
522 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value);
523 static int stl_cd1400getreg(stlport_t *portp, int regnr);
524 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value);
525 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
526 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
527 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp);
528 static int stl_cd1400getsignals(stlport_t *portp);
529 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts);
530 static void stl_cd1400ccrwait(stlport_t *portp);
531 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx);
532 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx);
533 static void stl_cd1400disableintrs(stlport_t *portp);
534 static void stl_cd1400sendbreak(stlport_t *portp, int len);
535 static void stl_cd1400flowctrl(stlport_t *portp, int state);
536 static void stl_cd1400sendflow(stlport_t *portp, int state);
537 static void stl_cd1400flush(stlport_t *portp);
538 static int stl_cd1400datastate(stlport_t *portp);
539 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase);
540 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase);
541 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr);
542 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr);
543 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr);
545 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr);
548 * SC26198 uart specific handling functions.
550 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value);
551 static int stl_sc26198getreg(stlport_t *portp, int regnr);
552 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value);
553 static int stl_sc26198getglobreg(stlport_t *portp, int regnr);
554 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
555 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
556 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp);
557 static int stl_sc26198getsignals(stlport_t *portp);
558 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts);
559 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx);
560 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx);
561 static void stl_sc26198disableintrs(stlport_t *portp);
562 static void stl_sc26198sendbreak(stlport_t *portp, int len);
563 static void stl_sc26198flowctrl(stlport_t *portp, int state);
564 static void stl_sc26198sendflow(stlport_t *portp, int state);
565 static void stl_sc26198flush(stlport_t *portp);
566 static int stl_sc26198datastate(stlport_t *portp);
567 static void stl_sc26198wait(stlport_t *portp);
568 static void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty);
569 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase);
570 static void stl_sc26198txisr(stlport_t *port);
571 static void stl_sc26198rxisr(stlport_t *port, unsigned int iack);
572 static void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch);
573 static void stl_sc26198rxbadchars(stlport_t *portp);
574 static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
576 /*****************************************************************************/
579 * Generic UART support structure.
581 typedef struct uart {
582 int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp);
583 void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
584 void (*setport)(stlport_t *portp, struct termios *tiosp);
585 int (*getsignals)(stlport_t *portp);
586 void (*setsignals)(stlport_t *portp, int dtr, int rts);
587 void (*enablerxtx)(stlport_t *portp, int rx, int tx);
588 void (*startrxtx)(stlport_t *portp, int rx, int tx);
589 void (*disableintrs)(stlport_t *portp);
590 void (*sendbreak)(stlport_t *portp, int len);
591 void (*flowctrl)(stlport_t *portp, int state);
592 void (*sendflow)(stlport_t *portp, int state);
593 void (*flush)(stlport_t *portp);
594 int (*datastate)(stlport_t *portp);
595 void (*intr)(stlpanel_t *panelp, unsigned int iobase);
599 * Define some macros to make calling these functions nice and clean.
601 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
602 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
603 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
604 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
605 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
606 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
607 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
608 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
609 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
610 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
611 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
612 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
613 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
615 /*****************************************************************************/
618 * CD1400 UART specific data initialization.
620 static uart_t stl_cd1400uart = {
624 stl_cd1400getsignals,
625 stl_cd1400setsignals,
626 stl_cd1400enablerxtx,
628 stl_cd1400disableintrs,
638 * Define the offsets within the register bank of a cd1400 based panel.
639 * These io address offsets are common to the EasyIO board as well.
647 #define EREG_BANKSIZE 8
649 #define CD1400_CLK 25000000
650 #define CD1400_CLK8M 20000000
653 * Define the cd1400 baud rate clocks. These are used when calculating
654 * what clock and divisor to use for the required baud rate. Also
655 * define the maximum baud rate allowed, and the default base baud.
657 static int stl_cd1400clkdivs[] = {
658 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
661 /*****************************************************************************/
664 * SC26198 UART specific data initization.
666 static uart_t stl_sc26198uart = {
667 stl_sc26198panelinit,
670 stl_sc26198getsignals,
671 stl_sc26198setsignals,
672 stl_sc26198enablerxtx,
673 stl_sc26198startrxtx,
674 stl_sc26198disableintrs,
675 stl_sc26198sendbreak,
679 stl_sc26198datastate,
684 * Define the offsets within the register bank of a sc26198 based panel.
692 #define XP_BANKSIZE 4
695 * Define the sc26198 baud rate table. Offsets within the table
696 * represent the actual baud rate selector of sc26198 registers.
698 static unsigned int sc26198_baudtable[] = {
699 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
700 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
701 230400, 460800, 921600
704 #define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
706 /*****************************************************************************/
709 * Define the driver info for a user level control device. Used mainly
710 * to get at port stats - only not using the port device itself.
712 static struct file_operations stl_fsiomem = {
713 .owner = THIS_MODULE,
714 .ioctl = stl_memioctl,
717 /*****************************************************************************/
719 static struct class *stallion_class;
722 * Loadable module initialization stuff.
725 static int __init stallion_module_init(void)
731 /*****************************************************************************/
733 static void __exit stallion_module_exit(void)
741 printk("cleanup_module()\n");
744 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
748 * Free up all allocated resources used by the ports. This includes
749 * memory and interrupts. As part of this process we will also do
750 * a hangup on every open port - to try to flush out any processes
751 * hanging onto ports.
753 i = tty_unregister_driver(stl_serial);
754 put_tty_driver(stl_serial);
756 printk("STALLION: failed to un-register tty driver, "
760 for (i = 0; i < 4; i++) {
761 devfs_remove("staliomem/%d", i);
762 class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
764 devfs_remove("staliomem");
765 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
766 printk("STALLION: failed to un-register serial memory device, "
768 class_destroy(stallion_class);
770 for (i = 0; (i < stl_nrbrds); i++) {
771 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
774 free_irq(brdp->irq, brdp);
776 for (j = 0; (j < STL_MAXPANELS); j++) {
777 panelp = brdp->panels[j];
778 if (panelp == (stlpanel_t *) NULL)
780 for (k = 0; (k < STL_PORTSPERPANEL); k++) {
781 portp = panelp->ports[k];
782 if (portp == (stlport_t *) NULL)
784 if (portp->tty != (struct tty_struct *) NULL)
785 stl_hangup(portp->tty);
786 kfree(portp->tx.buf);
792 release_region(brdp->ioaddr1, brdp->iosize1);
793 if (brdp->iosize2 > 0)
794 release_region(brdp->ioaddr2, brdp->iosize2);
797 stl_brds[i] = (stlbrd_t *) NULL;
801 module_init(stallion_module_init);
802 module_exit(stallion_module_exit);
804 /*****************************************************************************/
807 * Check for any arguments passed in on the module load command line.
810 static void stl_argbrds(void)
817 printk("stl_argbrds()\n");
820 for (i = stl_nrbrds; (i < stl_nargs); i++) {
821 memset(&conf, 0, sizeof(conf));
822 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
824 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
828 brdp->brdtype = conf.brdtype;
829 brdp->ioaddr1 = conf.ioaddr1;
830 brdp->ioaddr2 = conf.ioaddr2;
831 brdp->irq = conf.irq;
832 brdp->irqtype = conf.irqtype;
837 /*****************************************************************************/
840 * Convert an ascii string number into an unsigned long.
843 static unsigned long stl_atol(char *str)
851 if ((*sp == '0') && (*(sp+1) == 'x')) {
854 } else if (*sp == '0') {
861 for (; (*sp != 0); sp++) {
862 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
863 if ((c < 0) || (c >= base)) {
864 printk("STALLION: invalid argument %s\n", str);
868 val = (val * base) + c;
873 /*****************************************************************************/
876 * Parse the supplied argument string, into the board conf struct.
879 static int stl_parsebrd(stlconf_t *confp, char **argp)
885 printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
888 if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
891 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
894 for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++) {
895 if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
898 if (i == ARRAY_SIZE(stl_brdstr)) {
899 printk("STALLION: unknown board name, %s?\n", argp[0]);
903 confp->brdtype = stl_brdstr[i].type;
906 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
907 confp->ioaddr1 = stl_atol(argp[i]);
909 if (confp->brdtype == BRD_ECH) {
910 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
911 confp->ioaddr2 = stl_atol(argp[i]);
914 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
915 confp->irq = stl_atol(argp[i]);
919 /*****************************************************************************/
922 * Allocate a new board structure. Fill out the basic info in it.
925 static stlbrd_t *stl_allocbrd(void)
929 brdp = kzalloc(sizeof(stlbrd_t), GFP_KERNEL);
931 printk("STALLION: failed to allocate memory (size=%Zd)\n",
936 brdp->magic = STL_BOARDMAGIC;
940 /*****************************************************************************/
942 static int stl_open(struct tty_struct *tty, struct file *filp)
946 unsigned int minordev;
947 int brdnr, panelnr, portnr, rc;
950 printk("stl_open(tty=%x,filp=%x): device=%s\n", (int) tty,
951 (int) filp, tty->name);
954 minordev = tty->index;
955 brdnr = MINOR2BRD(minordev);
956 if (brdnr >= stl_nrbrds)
958 brdp = stl_brds[brdnr];
959 if (brdp == (stlbrd_t *) NULL)
961 minordev = MINOR2PORT(minordev);
962 for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
963 if (brdp->panels[panelnr] == (stlpanel_t *) NULL)
965 if (minordev < brdp->panels[panelnr]->nrports) {
969 minordev -= brdp->panels[panelnr]->nrports;
974 portp = brdp->panels[panelnr]->ports[portnr];
975 if (portp == (stlport_t *) NULL)
979 * On the first open of the device setup the port hardware, and
980 * initialize the per port data structure.
983 tty->driver_data = portp;
986 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
987 if (!portp->tx.buf) {
988 portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
991 portp->tx.head = portp->tx.buf;
992 portp->tx.tail = portp->tx.buf;
994 stl_setport(portp, tty->termios);
995 portp->sigs = stl_getsignals(portp);
996 stl_setsignals(portp, 1, 1);
997 stl_enablerxtx(portp, 1, 1);
998 stl_startrxtx(portp, 1, 0);
999 clear_bit(TTY_IO_ERROR, &tty->flags);
1000 portp->flags |= ASYNC_INITIALIZED;
1004 * Check if this port is in the middle of closing. If so then wait
1005 * until it is closed then return error status, based on flag settings.
1006 * The sleep here does not need interrupt protection since the wakeup
1007 * for it is done with the same context.
1009 if (portp->flags & ASYNC_CLOSING) {
1010 interruptible_sleep_on(&portp->close_wait);
1011 if (portp->flags & ASYNC_HUP_NOTIFY)
1013 return -ERESTARTSYS;
1017 * Based on type of open being done check if it can overlap with any
1018 * previous opens still in effect. If we are a normal serial device
1019 * then also we might have to wait for carrier.
1021 if (!(filp->f_flags & O_NONBLOCK)) {
1022 if ((rc = stl_waitcarrier(portp, filp)) != 0)
1025 portp->flags |= ASYNC_NORMAL_ACTIVE;
1030 /*****************************************************************************/
1033 * Possibly need to wait for carrier (DCD signal) to come high. Say
1034 * maybe because if we are clocal then we don't need to wait...
1037 static int stl_waitcarrier(stlport_t *portp, struct file *filp)
1039 unsigned long flags;
1043 printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp, (int) filp);
1049 spin_lock_irqsave(&stallion_lock, flags);
1051 if (portp->tty->termios->c_cflag & CLOCAL)
1054 portp->openwaitcnt++;
1055 if (! tty_hung_up_p(filp))
1059 /* Takes brd_lock internally */
1060 stl_setsignals(portp, 1, 1);
1061 if (tty_hung_up_p(filp) ||
1062 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1063 if (portp->flags & ASYNC_HUP_NOTIFY)
1069 if (((portp->flags & ASYNC_CLOSING) == 0) &&
1070 (doclocal || (portp->sigs & TIOCM_CD))) {
1073 if (signal_pending(current)) {
1078 interruptible_sleep_on(&portp->open_wait);
1081 if (! tty_hung_up_p(filp))
1083 portp->openwaitcnt--;
1084 spin_unlock_irqrestore(&stallion_lock, flags);
1089 /*****************************************************************************/
1091 static void stl_close(struct tty_struct *tty, struct file *filp)
1094 unsigned long flags;
1097 printk("stl_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
1100 portp = tty->driver_data;
1101 if (portp == (stlport_t *) NULL)
1104 spin_lock_irqsave(&stallion_lock, flags);
1105 if (tty_hung_up_p(filp)) {
1106 spin_unlock_irqrestore(&stallion_lock, flags);
1109 if ((tty->count == 1) && (portp->refcount != 1))
1110 portp->refcount = 1;
1111 if (portp->refcount-- > 1) {
1112 spin_unlock_irqrestore(&stallion_lock, flags);
1116 portp->refcount = 0;
1117 portp->flags |= ASYNC_CLOSING;
1120 * May want to wait for any data to drain before closing. The BUSY
1121 * flag keeps track of whether we are still sending or not - it is
1122 * very accurate for the cd1400, not quite so for the sc26198.
1123 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1127 spin_unlock_irqrestore(&stallion_lock, flags);
1129 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1130 tty_wait_until_sent(tty, portp->closing_wait);
1131 stl_waituntilsent(tty, (HZ / 2));
1134 spin_lock_irqsave(&stallion_lock, flags);
1135 portp->flags &= ~ASYNC_INITIALIZED;
1136 spin_unlock_irqrestore(&stallion_lock, flags);
1138 stl_disableintrs(portp);
1139 if (tty->termios->c_cflag & HUPCL)
1140 stl_setsignals(portp, 0, 0);
1141 stl_enablerxtx(portp, 0, 0);
1142 stl_flushbuffer(tty);
1144 if (portp->tx.buf != (char *) NULL) {
1145 kfree(portp->tx.buf);
1146 portp->tx.buf = (char *) NULL;
1147 portp->tx.head = (char *) NULL;
1148 portp->tx.tail = (char *) NULL;
1150 set_bit(TTY_IO_ERROR, &tty->flags);
1151 tty_ldisc_flush(tty);
1154 portp->tty = (struct tty_struct *) NULL;
1156 if (portp->openwaitcnt) {
1157 if (portp->close_delay)
1158 msleep_interruptible(jiffies_to_msecs(portp->close_delay));
1159 wake_up_interruptible(&portp->open_wait);
1162 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1163 wake_up_interruptible(&portp->close_wait);
1166 /*****************************************************************************/
1169 * Write routine. Take data and stuff it in to the TX ring queue.
1170 * If transmit interrupts are not running then start them.
1173 static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
1176 unsigned int len, stlen;
1177 unsigned char *chbuf;
1181 printk("stl_write(tty=%x,buf=%x,count=%d)\n",
1182 (int) tty, (int) buf, count);
1185 portp = tty->driver_data;
1186 if (portp == (stlport_t *) NULL)
1188 if (portp->tx.buf == (char *) NULL)
1192 * If copying direct from user space we must cater for page faults,
1193 * causing us to "sleep" here for a while. To handle this copy in all
1194 * the data we need now, into a local buffer. Then when we got it all
1195 * copy it into the TX buffer.
1197 chbuf = (unsigned char *) buf;
1199 head = portp->tx.head;
1200 tail = portp->tx.tail;
1202 len = STL_TXBUFSIZE - (head - tail) - 1;
1203 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
1205 len = tail - head - 1;
1209 len = MIN(len, count);
1212 stlen = MIN(len, stlen);
1213 memcpy(head, chbuf, stlen);
1218 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
1219 head = portp->tx.buf;
1220 stlen = tail - head;
1223 portp->tx.head = head;
1225 clear_bit(ASYI_TXLOW, &portp->istate);
1226 stl_startrxtx(portp, -1, 1);
1231 /*****************************************************************************/
1233 static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1240 printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1243 if (tty == (struct tty_struct *) NULL)
1245 portp = tty->driver_data;
1246 if (portp == (stlport_t *) NULL)
1248 if (portp->tx.buf == (char *) NULL)
1251 head = portp->tx.head;
1252 tail = portp->tx.tail;
1254 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
1259 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
1260 head = portp->tx.buf;
1262 portp->tx.head = head;
1265 /*****************************************************************************/
1268 * If there are any characters in the buffer then make sure that TX
1269 * interrupts are on and get'em out. Normally used after the putchar
1270 * routine has been called.
1273 static void stl_flushchars(struct tty_struct *tty)
1278 printk("stl_flushchars(tty=%x)\n", (int) tty);
1281 if (tty == (struct tty_struct *) NULL)
1283 portp = tty->driver_data;
1284 if (portp == (stlport_t *) NULL)
1286 if (portp->tx.buf == (char *) NULL)
1289 stl_startrxtx(portp, -1, 1);
1292 /*****************************************************************************/
1294 static int stl_writeroom(struct tty_struct *tty)
1300 printk("stl_writeroom(tty=%x)\n", (int) tty);
1303 if (tty == (struct tty_struct *) NULL)
1305 portp = tty->driver_data;
1306 if (portp == (stlport_t *) NULL)
1308 if (portp->tx.buf == (char *) NULL)
1311 head = portp->tx.head;
1312 tail = portp->tx.tail;
1313 return ((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
1316 /*****************************************************************************/
1319 * Return number of chars in the TX buffer. Normally we would just
1320 * calculate the number of chars in the buffer and return that, but if
1321 * the buffer is empty and TX interrupts are still on then we return
1322 * that the buffer still has 1 char in it. This way whoever called us
1323 * will not think that ALL chars have drained - since the UART still
1324 * must have some chars in it (we are busy after all).
1327 static int stl_charsinbuffer(struct tty_struct *tty)
1334 printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
1337 if (tty == (struct tty_struct *) NULL)
1339 portp = tty->driver_data;
1340 if (portp == (stlport_t *) NULL)
1342 if (portp->tx.buf == (char *) NULL)
1345 head = portp->tx.head;
1346 tail = portp->tx.tail;
1347 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1348 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1353 /*****************************************************************************/
1356 * Generate the serial struct info.
1359 static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp)
1361 struct serial_struct sio;
1365 printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1368 memset(&sio, 0, sizeof(struct serial_struct));
1369 sio.line = portp->portnr;
1370 sio.port = portp->ioaddr;
1371 sio.flags = portp->flags;
1372 sio.baud_base = portp->baud_base;
1373 sio.close_delay = portp->close_delay;
1374 sio.closing_wait = portp->closing_wait;
1375 sio.custom_divisor = portp->custom_divisor;
1377 if (portp->uartp == &stl_cd1400uart) {
1378 sio.type = PORT_CIRRUS;
1379 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1381 sio.type = PORT_UNKNOWN;
1382 sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1385 brdp = stl_brds[portp->brdnr];
1386 if (brdp != (stlbrd_t *) NULL)
1387 sio.irq = brdp->irq;
1389 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
1392 /*****************************************************************************/
1395 * Set port according to the serial struct info.
1396 * At this point we do not do any auto-configure stuff, so we will
1397 * just quietly ignore any requests to change irq, etc.
1400 static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp)
1402 struct serial_struct sio;
1405 printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1408 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1410 if (!capable(CAP_SYS_ADMIN)) {
1411 if ((sio.baud_base != portp->baud_base) ||
1412 (sio.close_delay != portp->close_delay) ||
1413 ((sio.flags & ~ASYNC_USR_MASK) !=
1414 (portp->flags & ~ASYNC_USR_MASK)))
1418 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1419 (sio.flags & ASYNC_USR_MASK);
1420 portp->baud_base = sio.baud_base;
1421 portp->close_delay = sio.close_delay;
1422 portp->closing_wait = sio.closing_wait;
1423 portp->custom_divisor = sio.custom_divisor;
1424 stl_setport(portp, portp->tty->termios);
1428 /*****************************************************************************/
1430 static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1434 if (tty == (struct tty_struct *) NULL)
1436 portp = tty->driver_data;
1437 if (portp == (stlport_t *) NULL)
1439 if (tty->flags & (1 << TTY_IO_ERROR))
1442 return stl_getsignals(portp);
1445 static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1446 unsigned int set, unsigned int clear)
1449 int rts = -1, dtr = -1;
1451 if (tty == (struct tty_struct *) NULL)
1453 portp = tty->driver_data;
1454 if (portp == (stlport_t *) NULL)
1456 if (tty->flags & (1 << TTY_IO_ERROR))
1459 if (set & TIOCM_RTS)
1461 if (set & TIOCM_DTR)
1463 if (clear & TIOCM_RTS)
1465 if (clear & TIOCM_DTR)
1468 stl_setsignals(portp, dtr, rts);
1472 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1477 void __user *argp = (void __user *)arg;
1480 printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
1481 (int) tty, (int) file, cmd, (int) arg);
1484 if (tty == (struct tty_struct *) NULL)
1486 portp = tty->driver_data;
1487 if (portp == (stlport_t *) NULL)
1490 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1491 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1492 if (tty->flags & (1 << TTY_IO_ERROR))
1500 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1501 (unsigned __user *) argp);
1504 if (get_user(ival, (unsigned int __user *) arg))
1506 tty->termios->c_cflag =
1507 (tty->termios->c_cflag & ~CLOCAL) |
1508 (ival ? CLOCAL : 0);
1511 rc = stl_getserial(portp, argp);
1514 rc = stl_setserial(portp, argp);
1516 case COM_GETPORTSTATS:
1517 rc = stl_getportstats(portp, argp);
1519 case COM_CLRPORTSTATS:
1520 rc = stl_clrportstats(portp, argp);
1526 case TIOCSERGSTRUCT:
1527 case TIOCSERGETMULTI:
1528 case TIOCSERSETMULTI:
1537 /*****************************************************************************/
1539 static void stl_settermios(struct tty_struct *tty, struct termios *old)
1542 struct termios *tiosp;
1545 printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
1548 if (tty == (struct tty_struct *) NULL)
1550 portp = tty->driver_data;
1551 if (portp == (stlport_t *) NULL)
1554 tiosp = tty->termios;
1555 if ((tiosp->c_cflag == old->c_cflag) &&
1556 (tiosp->c_iflag == old->c_iflag))
1559 stl_setport(portp, tiosp);
1560 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1562 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1563 tty->hw_stopped = 0;
1566 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1567 wake_up_interruptible(&portp->open_wait);
1570 /*****************************************************************************/
1573 * Attempt to flow control who ever is sending us data. Based on termios
1574 * settings use software or/and hardware flow control.
1577 static void stl_throttle(struct tty_struct *tty)
1582 printk("stl_throttle(tty=%x)\n", (int) tty);
1585 if (tty == (struct tty_struct *) NULL)
1587 portp = tty->driver_data;
1588 if (portp == (stlport_t *) NULL)
1590 stl_flowctrl(portp, 0);
1593 /*****************************************************************************/
1596 * Unflow control the device sending us data...
1599 static void stl_unthrottle(struct tty_struct *tty)
1604 printk("stl_unthrottle(tty=%x)\n", (int) tty);
1607 if (tty == (struct tty_struct *) NULL)
1609 portp = tty->driver_data;
1610 if (portp == (stlport_t *) NULL)
1612 stl_flowctrl(portp, 1);
1615 /*****************************************************************************/
1618 * Stop the transmitter. Basically to do this we will just turn TX
1622 static void stl_stop(struct tty_struct *tty)
1627 printk("stl_stop(tty=%x)\n", (int) tty);
1630 if (tty == (struct tty_struct *) NULL)
1632 portp = tty->driver_data;
1633 if (portp == (stlport_t *) NULL)
1635 stl_startrxtx(portp, -1, 0);
1638 /*****************************************************************************/
1641 * Start the transmitter again. Just turn TX interrupts back on.
1644 static void stl_start(struct tty_struct *tty)
1649 printk("stl_start(tty=%x)\n", (int) tty);
1652 if (tty == (struct tty_struct *) NULL)
1654 portp = tty->driver_data;
1655 if (portp == (stlport_t *) NULL)
1657 stl_startrxtx(portp, -1, 1);
1660 /*****************************************************************************/
1663 * Hangup this port. This is pretty much like closing the port, only
1664 * a little more brutal. No waiting for data to drain. Shutdown the
1665 * port and maybe drop signals.
1668 static void stl_hangup(struct tty_struct *tty)
1673 printk("stl_hangup(tty=%x)\n", (int) tty);
1676 if (tty == (struct tty_struct *) NULL)
1678 portp = tty->driver_data;
1679 if (portp == (stlport_t *) NULL)
1682 portp->flags &= ~ASYNC_INITIALIZED;
1683 stl_disableintrs(portp);
1684 if (tty->termios->c_cflag & HUPCL)
1685 stl_setsignals(portp, 0, 0);
1686 stl_enablerxtx(portp, 0, 0);
1687 stl_flushbuffer(tty);
1689 set_bit(TTY_IO_ERROR, &tty->flags);
1690 if (portp->tx.buf != (char *) NULL) {
1691 kfree(portp->tx.buf);
1692 portp->tx.buf = (char *) NULL;
1693 portp->tx.head = (char *) NULL;
1694 portp->tx.tail = (char *) NULL;
1696 portp->tty = (struct tty_struct *) NULL;
1697 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1698 portp->refcount = 0;
1699 wake_up_interruptible(&portp->open_wait);
1702 /*****************************************************************************/
1704 static void stl_flushbuffer(struct tty_struct *tty)
1709 printk("stl_flushbuffer(tty=%x)\n", (int) tty);
1712 if (tty == (struct tty_struct *) NULL)
1714 portp = tty->driver_data;
1715 if (portp == (stlport_t *) NULL)
1722 /*****************************************************************************/
1724 static void stl_breakctl(struct tty_struct *tty, int state)
1729 printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty, state);
1732 if (tty == (struct tty_struct *) NULL)
1734 portp = tty->driver_data;
1735 if (portp == (stlport_t *) NULL)
1738 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1741 /*****************************************************************************/
1743 static void stl_waituntilsent(struct tty_struct *tty, int timeout)
1749 printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty, timeout);
1752 if (tty == (struct tty_struct *) NULL)
1754 portp = tty->driver_data;
1755 if (portp == (stlport_t *) NULL)
1760 tend = jiffies + timeout;
1762 while (stl_datastate(portp)) {
1763 if (signal_pending(current))
1765 msleep_interruptible(20);
1766 if (time_after_eq(jiffies, tend))
1771 /*****************************************************************************/
1773 static void stl_sendxchar(struct tty_struct *tty, char ch)
1778 printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
1781 if (tty == (struct tty_struct *) NULL)
1783 portp = tty->driver_data;
1784 if (portp == (stlport_t *) NULL)
1787 if (ch == STOP_CHAR(tty))
1788 stl_sendflow(portp, 0);
1789 else if (ch == START_CHAR(tty))
1790 stl_sendflow(portp, 1);
1792 stl_putchar(tty, ch);
1795 /*****************************************************************************/
1800 * Format info for a specified port. The line is deliberately limited
1801 * to 80 characters. (If it is too long it will be truncated, if too
1802 * short then padded with spaces).
1805 static int stl_portinfo(stlport_t *portp, int portnr, char *pos)
1811 sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
1812 portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
1813 (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
1815 if (portp->stats.rxframing)
1816 sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
1817 if (portp->stats.rxparity)
1818 sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
1819 if (portp->stats.rxbreaks)
1820 sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
1821 if (portp->stats.rxoverrun)
1822 sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
1824 sigs = stl_getsignals(portp);
1825 cnt = sprintf(sp, "%s%s%s%s%s ",
1826 (sigs & TIOCM_RTS) ? "|RTS" : "",
1827 (sigs & TIOCM_CTS) ? "|CTS" : "",
1828 (sigs & TIOCM_DTR) ? "|DTR" : "",
1829 (sigs & TIOCM_CD) ? "|DCD" : "",
1830 (sigs & TIOCM_DSR) ? "|DSR" : "");
1834 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
1837 pos[(MAXLINE - 2)] = '+';
1838 pos[(MAXLINE - 1)] = '\n';
1843 /*****************************************************************************/
1846 * Port info, read from the /proc file system.
1849 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
1854 int brdnr, panelnr, portnr, totalport;
1859 printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
1860 "data=%x\n", (int) page, (int) start, (int) off, count,
1861 (int) eof, (int) data);
1869 pos += sprintf(pos, "%s: version %s", stl_drvtitle,
1871 while (pos < (page + MAXLINE - 1))
1878 * We scan through for each board, panel and port. The offset is
1879 * calculated on the fly, and irrelevant ports are skipped.
1881 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1882 brdp = stl_brds[brdnr];
1883 if (brdp == (stlbrd_t *) NULL)
1885 if (brdp->state == 0)
1888 maxoff = curoff + (brdp->nrports * MAXLINE);
1889 if (off >= maxoff) {
1894 totalport = brdnr * STL_MAXPORTS;
1895 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1896 panelp = brdp->panels[panelnr];
1897 if (panelp == (stlpanel_t *) NULL)
1900 maxoff = curoff + (panelp->nrports * MAXLINE);
1901 if (off >= maxoff) {
1903 totalport += panelp->nrports;
1907 for (portnr = 0; (portnr < panelp->nrports); portnr++,
1909 portp = panelp->ports[portnr];
1910 if (portp == (stlport_t *) NULL)
1912 if (off >= (curoff += MAXLINE))
1914 if ((pos - page + MAXLINE) > count)
1916 pos += stl_portinfo(portp, totalport, pos);
1925 return (pos - page);
1928 /*****************************************************************************/
1931 * All board interrupts are vectored through here first. This code then
1932 * calls off to the approrpriate board interrupt handlers.
1935 static irqreturn_t stl_intr(int irq, void *dev_id, struct pt_regs *regs)
1937 stlbrd_t *brdp = (stlbrd_t *) dev_id;
1940 printk("stl_intr(brdp=%x,irq=%d,regs=%x)\n", (int) brdp, irq,
1944 return IRQ_RETVAL((* brdp->isr)(brdp));
1947 /*****************************************************************************/
1950 * Interrupt service routine for EasyIO board types.
1953 static int stl_eiointr(stlbrd_t *brdp)
1956 unsigned int iobase;
1959 spin_lock(&brd_lock);
1960 panelp = brdp->panels[0];
1961 iobase = panelp->iobase;
1962 while (inb(brdp->iostatus) & EIO_INTRPEND) {
1964 (* panelp->isr)(panelp, iobase);
1966 spin_unlock(&brd_lock);
1970 /*****************************************************************************/
1973 * Interrupt service routine for ECH-AT board types.
1976 static int stl_echatintr(stlbrd_t *brdp)
1979 unsigned int ioaddr;
1983 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
1985 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1987 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1988 ioaddr = brdp->bnkstataddr[bnknr];
1989 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1990 panelp = brdp->bnk2panel[bnknr];
1991 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1996 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2001 /*****************************************************************************/
2004 * Interrupt service routine for ECH-MCA board types.
2007 static int stl_echmcaintr(stlbrd_t *brdp)
2010 unsigned int ioaddr;
2014 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2016 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2017 ioaddr = brdp->bnkstataddr[bnknr];
2018 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2019 panelp = brdp->bnk2panel[bnknr];
2020 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2027 /*****************************************************************************/
2030 * Interrupt service routine for ECH-PCI board types.
2033 static int stl_echpciintr(stlbrd_t *brdp)
2036 unsigned int ioaddr;
2042 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2043 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
2044 ioaddr = brdp->bnkstataddr[bnknr];
2045 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2046 panelp = brdp->bnk2panel[bnknr];
2047 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2058 /*****************************************************************************/
2061 * Interrupt service routine for ECH-8/64-PCI board types.
2064 static int stl_echpci64intr(stlbrd_t *brdp)
2067 unsigned int ioaddr;
2071 while (inb(brdp->ioctrl) & 0x1) {
2073 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2074 ioaddr = brdp->bnkstataddr[bnknr];
2075 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2076 panelp = brdp->bnk2panel[bnknr];
2077 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2085 /*****************************************************************************/
2088 * Service an off-level request for some channel.
2090 static void stl_offintr(void *private)
2093 struct tty_struct *tty;
2094 unsigned int oldsigs;
2099 printk("stl_offintr(portp=%x)\n", (int) portp);
2102 if (portp == (stlport_t *) NULL)
2106 if (tty == (struct tty_struct *) NULL)
2110 if (test_bit(ASYI_TXLOW, &portp->istate)) {
2113 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
2114 clear_bit(ASYI_DCDCHANGE, &portp->istate);
2115 oldsigs = portp->sigs;
2116 portp->sigs = stl_getsignals(portp);
2117 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
2118 wake_up_interruptible(&portp->open_wait);
2119 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
2120 if (portp->flags & ASYNC_CHECK_CD)
2121 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2127 /*****************************************************************************/
2130 * Initialize all the ports on a panel.
2133 static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2139 printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
2142 chipmask = stl_panelinit(brdp, panelp);
2145 * All UART's are initialized (if found!). Now go through and setup
2146 * each ports data structures.
2148 for (i = 0; (i < panelp->nrports); i++) {
2149 portp = kzalloc(sizeof(stlport_t), GFP_KERNEL);
2151 printk("STALLION: failed to allocate memory "
2152 "(size=%Zd)\n", sizeof(stlport_t));
2156 portp->magic = STL_PORTMAGIC;
2158 portp->brdnr = panelp->brdnr;
2159 portp->panelnr = panelp->panelnr;
2160 portp->uartp = panelp->uartp;
2161 portp->clk = brdp->clk;
2162 portp->baud_base = STL_BAUDBASE;
2163 portp->close_delay = STL_CLOSEDELAY;
2164 portp->closing_wait = 30 * HZ;
2165 INIT_WORK(&portp->tqueue, stl_offintr, portp);
2166 init_waitqueue_head(&portp->open_wait);
2167 init_waitqueue_head(&portp->close_wait);
2168 portp->stats.brd = portp->brdnr;
2169 portp->stats.panel = portp->panelnr;
2170 portp->stats.port = portp->portnr;
2171 panelp->ports[i] = portp;
2172 stl_portinit(brdp, panelp, portp);
2178 /*****************************************************************************/
2181 * Try to find and initialize an EasyIO board.
2184 static inline int stl_initeio(stlbrd_t *brdp)
2187 unsigned int status;
2192 printk("stl_initeio(brdp=%x)\n", (int) brdp);
2195 brdp->ioctrl = brdp->ioaddr1 + 1;
2196 brdp->iostatus = brdp->ioaddr1 + 2;
2198 status = inb(brdp->iostatus);
2199 if ((status & EIO_IDBITMASK) == EIO_MK3)
2203 * Handle board specific stuff now. The real difference is PCI
2206 if (brdp->brdtype == BRD_EASYIOPCI) {
2207 brdp->iosize1 = 0x80;
2208 brdp->iosize2 = 0x80;
2209 name = "serial(EIO-PCI)";
2210 outb(0x41, (brdp->ioaddr2 + 0x4c));
2213 name = "serial(EIO)";
2214 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2215 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2216 printk("STALLION: invalid irq=%d for brd=%d\n",
2217 brdp->irq, brdp->brdnr);
2220 outb((stl_vecmap[brdp->irq] | EIO_0WS |
2221 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
2225 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2226 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2227 "%x conflicts with another device\n", brdp->brdnr,
2232 if (brdp->iosize2 > 0)
2233 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2234 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2235 "address %x conflicts with another device\n",
2236 brdp->brdnr, brdp->ioaddr2);
2237 printk(KERN_WARNING "STALLION: Warning, also "
2238 "releasing board %d I/O address %x \n",
2239 brdp->brdnr, brdp->ioaddr1);
2240 release_region(brdp->ioaddr1, brdp->iosize1);
2245 * Everything looks OK, so let's go ahead and probe for the hardware.
2247 brdp->clk = CD1400_CLK;
2248 brdp->isr = stl_eiointr;
2250 switch (status & EIO_IDBITMASK) {
2252 brdp->clk = CD1400_CLK8M;
2262 switch (status & EIO_BRDMASK) {
2281 * We have verified that the board is actually present, so now we
2282 * can complete the setup.
2285 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
2287 printk(KERN_WARNING "STALLION: failed to allocate memory "
2288 "(size=%Zd)\n", sizeof(stlpanel_t));
2292 panelp->magic = STL_PANELMAGIC;
2293 panelp->brdnr = brdp->brdnr;
2294 panelp->panelnr = 0;
2295 panelp->nrports = brdp->nrports;
2296 panelp->iobase = brdp->ioaddr1;
2297 panelp->hwid = status;
2298 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2299 panelp->uartp = (void *) &stl_sc26198uart;
2300 panelp->isr = stl_sc26198intr;
2302 panelp->uartp = (void *) &stl_cd1400uart;
2303 panelp->isr = stl_cd1400eiointr;
2306 brdp->panels[0] = panelp;
2308 brdp->state |= BRD_FOUND;
2309 brdp->hwid = status;
2310 if (request_irq(brdp->irq, stl_intr, SA_SHIRQ, name, brdp) != 0) {
2311 printk("STALLION: failed to register interrupt "
2312 "routine for %s irq=%d\n", name, brdp->irq);
2320 /*****************************************************************************/
2323 * Try to find an ECH board and initialize it. This code is capable of
2324 * dealing with all types of ECH board.
2327 static inline int stl_initech(stlbrd_t *brdp)
2330 unsigned int status, nxtid, ioaddr, conflict;
2331 int panelnr, banknr, i;
2335 printk("stl_initech(brdp=%x)\n", (int) brdp);
2342 * Set up the initial board register contents for boards. This varies a
2343 * bit between the different board types. So we need to handle each
2344 * separately. Also do a check that the supplied IRQ is good.
2346 switch (brdp->brdtype) {
2349 brdp->isr = stl_echatintr;
2350 brdp->ioctrl = brdp->ioaddr1 + 1;
2351 brdp->iostatus = brdp->ioaddr1 + 1;
2352 status = inb(brdp->iostatus);
2353 if ((status & ECH_IDBITMASK) != ECH_ID)
2355 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2356 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2357 printk("STALLION: invalid irq=%d for brd=%d\n",
2358 brdp->irq, brdp->brdnr);
2361 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2362 status |= (stl_vecmap[brdp->irq] << 1);
2363 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2364 brdp->ioctrlval = ECH_INTENABLE |
2365 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2366 for (i = 0; (i < 10); i++)
2367 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2370 name = "serial(EC8/32)";
2371 outb(status, brdp->ioaddr1);
2375 brdp->isr = stl_echmcaintr;
2376 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2377 brdp->iostatus = brdp->ioctrl;
2378 status = inb(brdp->iostatus);
2379 if ((status & ECH_IDBITMASK) != ECH_ID)
2381 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2382 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2383 printk("STALLION: invalid irq=%d for brd=%d\n",
2384 brdp->irq, brdp->brdnr);
2387 outb(ECHMC_BRDRESET, brdp->ioctrl);
2388 outb(ECHMC_INTENABLE, brdp->ioctrl);
2390 name = "serial(EC8/32-MC)";
2394 brdp->isr = stl_echpciintr;
2395 brdp->ioctrl = brdp->ioaddr1 + 2;
2398 name = "serial(EC8/32-PCI)";
2402 brdp->isr = stl_echpci64intr;
2403 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2404 outb(0x43, (brdp->ioaddr1 + 0x4c));
2405 brdp->iosize1 = 0x80;
2406 brdp->iosize2 = 0x80;
2407 name = "serial(EC8/64-PCI)";
2411 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
2417 * Check boards for possible IO address conflicts and return fail status
2418 * if an IO conflict found.
2420 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2421 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2422 "%x conflicts with another device\n", brdp->brdnr,
2427 if (brdp->iosize2 > 0)
2428 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2429 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2430 "address %x conflicts with another device\n",
2431 brdp->brdnr, brdp->ioaddr2);
2432 printk(KERN_WARNING "STALLION: Warning, also "
2433 "releasing board %d I/O address %x \n",
2434 brdp->brdnr, brdp->ioaddr1);
2435 release_region(brdp->ioaddr1, brdp->iosize1);
2440 * Scan through the secondary io address space looking for panels.
2441 * As we find'em allocate and initialize panel structures for each.
2443 brdp->clk = CD1400_CLK;
2444 brdp->hwid = status;
2446 ioaddr = brdp->ioaddr2;
2451 for (i = 0; (i < STL_MAXPANELS); i++) {
2452 if (brdp->brdtype == BRD_ECHPCI) {
2453 outb(nxtid, brdp->ioctrl);
2454 ioaddr = brdp->ioaddr2;
2456 status = inb(ioaddr + ECH_PNLSTATUS);
2457 if ((status & ECH_PNLIDMASK) != nxtid)
2459 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
2461 printk("STALLION: failed to allocate memory "
2462 "(size=%Zd)\n", sizeof(stlpanel_t));
2465 panelp->magic = STL_PANELMAGIC;
2466 panelp->brdnr = brdp->brdnr;
2467 panelp->panelnr = panelnr;
2468 panelp->iobase = ioaddr;
2469 panelp->pagenr = nxtid;
2470 panelp->hwid = status;
2471 brdp->bnk2panel[banknr] = panelp;
2472 brdp->bnkpageaddr[banknr] = nxtid;
2473 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2475 if (status & ECH_PNLXPID) {
2476 panelp->uartp = (void *) &stl_sc26198uart;
2477 panelp->isr = stl_sc26198intr;
2478 if (status & ECH_PNL16PORT) {
2479 panelp->nrports = 16;
2480 brdp->bnk2panel[banknr] = panelp;
2481 brdp->bnkpageaddr[banknr] = nxtid;
2482 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2485 panelp->nrports = 8;
2488 panelp->uartp = (void *) &stl_cd1400uart;
2489 panelp->isr = stl_cd1400echintr;
2490 if (status & ECH_PNL16PORT) {
2491 panelp->nrports = 16;
2492 panelp->ackmask = 0x80;
2493 if (brdp->brdtype != BRD_ECHPCI)
2494 ioaddr += EREG_BANKSIZE;
2495 brdp->bnk2panel[banknr] = panelp;
2496 brdp->bnkpageaddr[banknr] = ++nxtid;
2497 brdp->bnkstataddr[banknr++] = ioaddr +
2500 panelp->nrports = 8;
2501 panelp->ackmask = 0xc0;
2506 ioaddr += EREG_BANKSIZE;
2507 brdp->nrports += panelp->nrports;
2508 brdp->panels[panelnr++] = panelp;
2509 if ((brdp->brdtype != BRD_ECHPCI) &&
2510 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
2514 brdp->nrpanels = panelnr;
2515 brdp->nrbnks = banknr;
2516 if (brdp->brdtype == BRD_ECH)
2517 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2519 brdp->state |= BRD_FOUND;
2520 if (request_irq(brdp->irq, stl_intr, SA_SHIRQ, name, brdp) != 0) {
2521 printk("STALLION: failed to register interrupt "
2522 "routine for %s irq=%d\n", name, brdp->irq);
2531 /*****************************************************************************/
2534 * Initialize and configure the specified board.
2535 * Scan through all the boards in the configuration and see what we
2536 * can find. Handle EIO and the ECH boards a little differently here
2537 * since the initial search and setup is very different.
2540 static int __init stl_brdinit(stlbrd_t *brdp)
2545 printk("stl_brdinit(brdp=%x)\n", (int) brdp);
2548 switch (brdp->brdtype) {
2560 printk("STALLION: board=%d is unknown board type=%d\n",
2561 brdp->brdnr, brdp->brdtype);
2565 stl_brds[brdp->brdnr] = brdp;
2566 if ((brdp->state & BRD_FOUND) == 0) {
2567 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2568 stl_brdnames[brdp->brdtype], brdp->brdnr,
2569 brdp->ioaddr1, brdp->irq);
2573 for (i = 0; (i < STL_MAXPANELS); i++)
2574 if (brdp->panels[i] != (stlpanel_t *) NULL)
2575 stl_initports(brdp, brdp->panels[i]);
2577 printk("STALLION: %s found, board=%d io=%x irq=%d "
2578 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2579 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2584 /*****************************************************************************/
2587 * Find the next available board number that is free.
2590 static inline int stl_getbrdnr(void)
2594 for (i = 0; (i < STL_MAXBRDS); i++) {
2595 if (stl_brds[i] == (stlbrd_t *) NULL) {
2596 if (i >= stl_nrbrds)
2604 /*****************************************************************************/
2609 * We have a Stallion board. Allocate a board structure and
2610 * initialize it. Read its IO and IRQ resources from PCI
2611 * configuration space.
2614 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
2619 printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
2620 devp->bus->number, devp->devfn);
2623 if (pci_enable_device(devp))
2625 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2627 if ((brdp->brdnr = stl_getbrdnr()) < 0) {
2628 printk("STALLION: too many boards found, "
2629 "maximum supported %d\n", STL_MAXBRDS);
2632 brdp->brdtype = brdtype;
2635 * Different Stallion boards use the BAR registers in different ways,
2636 * so set up io addresses based on board type.
2639 printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__, __LINE__,
2640 pci_resource_start(devp, 0), pci_resource_start(devp, 1),
2641 pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
2645 * We have all resources from the board, so let's setup the actual
2646 * board structure now.
2650 brdp->ioaddr2 = pci_resource_start(devp, 0);
2651 brdp->ioaddr1 = pci_resource_start(devp, 1);
2654 brdp->ioaddr2 = pci_resource_start(devp, 2);
2655 brdp->ioaddr1 = pci_resource_start(devp, 1);
2658 brdp->ioaddr1 = pci_resource_start(devp, 2);
2659 brdp->ioaddr2 = pci_resource_start(devp, 1);
2662 printk("STALLION: unknown PCI board type=%d\n", brdtype);
2666 brdp->irq = devp->irq;
2672 /*****************************************************************************/
2675 * Find all Stallion PCI boards that might be installed. Initialize each
2676 * one as it is found.
2680 static inline int stl_findpcibrds(void)
2682 struct pci_dev *dev = NULL;
2686 printk("stl_findpcibrds()\n");
2689 for (i = 0; (i < stl_nrpcibrds); i++)
2690 while ((dev = pci_find_device(stl_pcibrds[i].vendid,
2691 stl_pcibrds[i].devid, dev))) {
2694 * Found a device on the PCI bus that has our vendor and
2695 * device ID. Need to check now that it is really us.
2697 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2700 rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
2710 /*****************************************************************************/
2713 * Scan through all the boards in the configuration and see what we
2714 * can find. Handle EIO and the ECH boards a little differently here
2715 * since the initial search and setup is too different.
2718 static inline int stl_initbrds(void)
2725 printk("stl_initbrds()\n");
2728 if (stl_nrbrds > STL_MAXBRDS) {
2729 printk("STALLION: too many boards in configuration table, "
2730 "truncating to %d\n", STL_MAXBRDS);
2731 stl_nrbrds = STL_MAXBRDS;
2735 * Firstly scan the list of static boards configured. Allocate
2736 * resources and initialize the boards as found.
2738 for (i = 0; (i < stl_nrbrds); i++) {
2739 confp = &stl_brdconf[i];
2740 stl_parsebrd(confp, stl_brdsp[i]);
2741 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2744 brdp->brdtype = confp->brdtype;
2745 brdp->ioaddr1 = confp->ioaddr1;
2746 brdp->ioaddr2 = confp->ioaddr2;
2747 brdp->irq = confp->irq;
2748 brdp->irqtype = confp->irqtype;
2753 * Find any dynamically supported boards. That is via module load
2754 * line options or auto-detected on the PCI bus.
2764 /*****************************************************************************/
2767 * Return the board stats structure to user app.
2770 static int stl_getbrdstats(combrd_t __user *bp)
2776 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2778 if (stl_brdstats.brd >= STL_MAXBRDS)
2780 brdp = stl_brds[stl_brdstats.brd];
2781 if (brdp == (stlbrd_t *) NULL)
2784 memset(&stl_brdstats, 0, sizeof(combrd_t));
2785 stl_brdstats.brd = brdp->brdnr;
2786 stl_brdstats.type = brdp->brdtype;
2787 stl_brdstats.hwid = brdp->hwid;
2788 stl_brdstats.state = brdp->state;
2789 stl_brdstats.ioaddr = brdp->ioaddr1;
2790 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2791 stl_brdstats.irq = brdp->irq;
2792 stl_brdstats.nrpanels = brdp->nrpanels;
2793 stl_brdstats.nrports = brdp->nrports;
2794 for (i = 0; (i < brdp->nrpanels); i++) {
2795 panelp = brdp->panels[i];
2796 stl_brdstats.panels[i].panel = i;
2797 stl_brdstats.panels[i].hwid = panelp->hwid;
2798 stl_brdstats.panels[i].nrports = panelp->nrports;
2801 return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
2804 /*****************************************************************************/
2807 * Resolve the referenced port number into a port struct pointer.
2810 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2815 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2816 return((stlport_t *) NULL);
2817 brdp = stl_brds[brdnr];
2818 if (brdp == (stlbrd_t *) NULL)
2819 return((stlport_t *) NULL);
2820 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2821 return((stlport_t *) NULL);
2822 panelp = brdp->panels[panelnr];
2823 if (panelp == (stlpanel_t *) NULL)
2824 return((stlport_t *) NULL);
2825 if ((portnr < 0) || (portnr >= panelp->nrports))
2826 return((stlport_t *) NULL);
2827 return(panelp->ports[portnr]);
2830 /*****************************************************************************/
2833 * Return the port stats structure to user app. A NULL port struct
2834 * pointer passed in means that we need to find out from the app
2835 * what port to get stats for (used through board control device).
2838 static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
2840 unsigned char *head, *tail;
2841 unsigned long flags;
2844 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2846 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2848 if (portp == (stlport_t *) NULL)
2852 portp->stats.state = portp->istate;
2853 portp->stats.flags = portp->flags;
2854 portp->stats.hwid = portp->hwid;
2856 portp->stats.ttystate = 0;
2857 portp->stats.cflags = 0;
2858 portp->stats.iflags = 0;
2859 portp->stats.oflags = 0;
2860 portp->stats.lflags = 0;
2861 portp->stats.rxbuffered = 0;
2863 spin_lock_irqsave(&stallion_lock, flags);
2864 if (portp->tty != (struct tty_struct *) NULL) {
2865 if (portp->tty->driver_data == portp) {
2866 portp->stats.ttystate = portp->tty->flags;
2867 /* No longer available as a statistic */
2868 portp->stats.rxbuffered = 1; /*portp->tty->flip.count; */
2869 if (portp->tty->termios != (struct termios *) NULL) {
2870 portp->stats.cflags = portp->tty->termios->c_cflag;
2871 portp->stats.iflags = portp->tty->termios->c_iflag;
2872 portp->stats.oflags = portp->tty->termios->c_oflag;
2873 portp->stats.lflags = portp->tty->termios->c_lflag;
2877 spin_unlock_irqrestore(&stallion_lock, flags);
2879 head = portp->tx.head;
2880 tail = portp->tx.tail;
2881 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2882 (STL_TXBUFSIZE - (tail - head)));
2884 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2886 return copy_to_user(cp, &portp->stats,
2887 sizeof(comstats_t)) ? -EFAULT : 0;
2890 /*****************************************************************************/
2893 * Clear the port stats structure. We also return it zeroed out...
2896 static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp)
2899 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2901 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2903 if (portp == (stlport_t *) NULL)
2907 memset(&portp->stats, 0, sizeof(comstats_t));
2908 portp->stats.brd = portp->brdnr;
2909 portp->stats.panel = portp->panelnr;
2910 portp->stats.port = portp->portnr;
2911 return copy_to_user(cp, &portp->stats,
2912 sizeof(comstats_t)) ? -EFAULT : 0;
2915 /*****************************************************************************/
2918 * Return the entire driver ports structure to a user app.
2921 static int stl_getportstruct(stlport_t __user *arg)
2925 if (copy_from_user(&stl_dummyport, arg, sizeof(stlport_t)))
2927 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
2928 stl_dummyport.portnr);
2931 return copy_to_user(arg, portp, sizeof(stlport_t)) ? -EFAULT : 0;
2934 /*****************************************************************************/
2937 * Return the entire driver board structure to a user app.
2940 static int stl_getbrdstruct(stlbrd_t __user *arg)
2944 if (copy_from_user(&stl_dummybrd, arg, sizeof(stlbrd_t)))
2946 if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
2948 brdp = stl_brds[stl_dummybrd.brdnr];
2951 return copy_to_user(arg, brdp, sizeof(stlbrd_t)) ? -EFAULT : 0;
2954 /*****************************************************************************/
2957 * The "staliomem" device is also required to do some special operations
2958 * on the board and/or ports. In this driver it is mostly used for stats
2962 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
2965 void __user *argp = (void __user *)arg;
2968 printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
2969 (int) fp, cmd, (int) arg);
2973 if (brdnr >= STL_MAXBRDS)
2978 case COM_GETPORTSTATS:
2979 rc = stl_getportstats(NULL, argp);
2981 case COM_CLRPORTSTATS:
2982 rc = stl_clrportstats(NULL, argp);
2984 case COM_GETBRDSTATS:
2985 rc = stl_getbrdstats(argp);
2988 rc = stl_getportstruct(argp);
2991 rc = stl_getbrdstruct(argp);
3001 static struct tty_operations stl_ops = {
3005 .put_char = stl_putchar,
3006 .flush_chars = stl_flushchars,
3007 .write_room = stl_writeroom,
3008 .chars_in_buffer = stl_charsinbuffer,
3010 .set_termios = stl_settermios,
3011 .throttle = stl_throttle,
3012 .unthrottle = stl_unthrottle,
3015 .hangup = stl_hangup,
3016 .flush_buffer = stl_flushbuffer,
3017 .break_ctl = stl_breakctl,
3018 .wait_until_sent = stl_waituntilsent,
3019 .send_xchar = stl_sendxchar,
3020 .read_proc = stl_readproc,
3021 .tiocmget = stl_tiocmget,
3022 .tiocmset = stl_tiocmset,
3025 /*****************************************************************************/
3027 static int __init stl_init(void)
3030 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
3032 spin_lock_init(&stallion_lock);
3033 spin_lock_init(&brd_lock);
3037 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
3042 * Set up a character driver for per board stuff. This is mainly used
3043 * to do stats ioctls on the ports.
3045 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
3046 printk("STALLION: failed to register serial board device\n");
3047 devfs_mk_dir("staliomem");
3049 stallion_class = class_create(THIS_MODULE, "staliomem");
3050 for (i = 0; i < 4; i++) {
3051 devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR, i),
3052 S_IFCHR|S_IRUSR|S_IWUSR,
3054 class_device_create(stallion_class, NULL,
3055 MKDEV(STL_SIOMEMMAJOR, i), NULL,
3059 stl_serial->owner = THIS_MODULE;
3060 stl_serial->driver_name = stl_drvname;
3061 stl_serial->name = "ttyE";
3062 stl_serial->devfs_name = "tts/E";
3063 stl_serial->major = STL_SERIALMAJOR;
3064 stl_serial->minor_start = 0;
3065 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
3066 stl_serial->subtype = SERIAL_TYPE_NORMAL;
3067 stl_serial->init_termios = stl_deftermios;
3068 stl_serial->flags = TTY_DRIVER_REAL_RAW;
3069 tty_set_operations(stl_serial, &stl_ops);
3071 if (tty_register_driver(stl_serial)) {
3072 put_tty_driver(stl_serial);
3073 printk("STALLION: failed to register serial driver\n");
3080 /*****************************************************************************/
3081 /* CD1400 HARDWARE FUNCTIONS */
3082 /*****************************************************************************/
3085 * These functions get/set/update the registers of the cd1400 UARTs.
3086 * Access to the cd1400 registers is via an address/data io port pair.
3087 * (Maybe should make this inline...)
3090 static int stl_cd1400getreg(stlport_t *portp, int regnr)
3092 outb((regnr + portp->uartaddr), portp->ioaddr);
3093 return inb(portp->ioaddr + EREG_DATA);
3096 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
3098 outb((regnr + portp->uartaddr), portp->ioaddr);
3099 outb(value, portp->ioaddr + EREG_DATA);
3102 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
3104 outb((regnr + portp->uartaddr), portp->ioaddr);
3105 if (inb(portp->ioaddr + EREG_DATA) != value) {
3106 outb(value, portp->ioaddr + EREG_DATA);
3112 /*****************************************************************************/
3115 * Inbitialize the UARTs in a panel. We don't care what sort of board
3116 * these ports are on - since the port io registers are almost
3117 * identical when dealing with ports.
3120 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3124 int nrchips, uartaddr, ioaddr;
3125 unsigned long flags;
3128 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
3131 spin_lock_irqsave(&brd_lock, flags);
3132 BRDENABLE(panelp->brdnr, panelp->pagenr);
3135 * Check that each chip is present and started up OK.
3138 nrchips = panelp->nrports / CD1400_PORTS;
3139 for (i = 0; (i < nrchips); i++) {
3140 if (brdp->brdtype == BRD_ECHPCI) {
3141 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3142 ioaddr = panelp->iobase;
3144 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3146 uartaddr = (i & 0x01) ? 0x080 : 0;
3147 outb((GFRCR + uartaddr), ioaddr);
3148 outb(0, (ioaddr + EREG_DATA));
3149 outb((CCR + uartaddr), ioaddr);
3150 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3151 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3152 outb((GFRCR + uartaddr), ioaddr);
3153 for (j = 0; (j < CCR_MAXWAIT); j++) {
3154 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3157 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3158 printk("STALLION: cd1400 not responding, "
3159 "brd=%d panel=%d chip=%d\n",
3160 panelp->brdnr, panelp->panelnr, i);
3163 chipmask |= (0x1 << i);
3164 outb((PPR + uartaddr), ioaddr);
3165 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
3168 BRDDISABLE(panelp->brdnr);
3169 spin_unlock_irqrestore(&brd_lock, flags);
3173 /*****************************************************************************/
3176 * Initialize hardware specific port registers.
3179 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3181 unsigned long flags;
3183 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3184 (int) brdp, (int) panelp, (int) portp);
3187 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
3188 (portp == (stlport_t *) NULL))
3191 spin_lock_irqsave(&brd_lock, flags);
3192 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3193 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3194 portp->uartaddr = (portp->portnr & 0x04) << 5;
3195 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3197 BRDENABLE(portp->brdnr, portp->pagenr);
3198 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3199 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3200 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3201 BRDDISABLE(portp->brdnr);
3202 spin_unlock_irqrestore(&brd_lock, flags);
3205 /*****************************************************************************/
3208 * Wait for the command register to be ready. We will poll this,
3209 * since it won't usually take too long to be ready.
3212 static void stl_cd1400ccrwait(stlport_t *portp)
3216 for (i = 0; (i < CCR_MAXWAIT); i++) {
3217 if (stl_cd1400getreg(portp, CCR) == 0) {
3222 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
3223 portp->portnr, portp->panelnr, portp->brdnr);
3226 /*****************************************************************************/
3229 * Set up the cd1400 registers for a port based on the termios port
3233 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3236 unsigned long flags;
3237 unsigned int clkdiv, baudrate;
3238 unsigned char cor1, cor2, cor3;
3239 unsigned char cor4, cor5, ccr;
3240 unsigned char srer, sreron, sreroff;
3241 unsigned char mcor1, mcor2, rtpr;
3242 unsigned char clk, div;
3258 brdp = stl_brds[portp->brdnr];
3259 if (brdp == (stlbrd_t *) NULL)
3263 * Set up the RX char ignore mask with those RX error types we
3264 * can ignore. We can get the cd1400 to help us out a little here,
3265 * it will ignore parity errors and breaks for us.
3267 portp->rxignoremsk = 0;
3268 if (tiosp->c_iflag & IGNPAR) {
3269 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
3270 cor1 |= COR1_PARIGNORE;
3272 if (tiosp->c_iflag & IGNBRK) {
3273 portp->rxignoremsk |= ST_BREAK;
3274 cor4 |= COR4_IGNBRK;
3277 portp->rxmarkmsk = ST_OVERRUN;
3278 if (tiosp->c_iflag & (INPCK | PARMRK))
3279 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3280 if (tiosp->c_iflag & BRKINT)
3281 portp->rxmarkmsk |= ST_BREAK;
3284 * Go through the char size, parity and stop bits and set all the
3285 * option register appropriately.
3287 switch (tiosp->c_cflag & CSIZE) {
3302 if (tiosp->c_cflag & CSTOPB)
3307 if (tiosp->c_cflag & PARENB) {
3308 if (tiosp->c_cflag & PARODD)
3309 cor1 |= (COR1_PARENB | COR1_PARODD);
3311 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3313 cor1 |= COR1_PARNONE;
3317 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3318 * space for hardware flow control and the like. This should be set to
3319 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3320 * really be based on VTIME.
3322 cor3 |= FIFO_RXTHRESHOLD;
3326 * Calculate the baud rate timers. For now we will just assume that
3327 * the input and output baud are the same. Could have used a baud
3328 * table here, but this way we can generate virtually any baud rate
3331 baudrate = tiosp->c_cflag & CBAUD;
3332 if (baudrate & CBAUDEX) {
3333 baudrate &= ~CBAUDEX;
3334 if ((baudrate < 1) || (baudrate > 4))
3335 tiosp->c_cflag &= ~CBAUDEX;
3339 baudrate = stl_baudrates[baudrate];
3340 if ((tiosp->c_cflag & CBAUD) == B38400) {
3341 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3343 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3345 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3347 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3349 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3350 baudrate = (portp->baud_base / portp->custom_divisor);
3352 if (baudrate > STL_CD1400MAXBAUD)
3353 baudrate = STL_CD1400MAXBAUD;
3356 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3357 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
3361 div = (unsigned char) clkdiv;
3365 * Check what form of modem signaling is required and set it up.
3367 if ((tiosp->c_cflag & CLOCAL) == 0) {
3370 sreron |= SRER_MODEM;
3371 portp->flags |= ASYNC_CHECK_CD;
3373 portp->flags &= ~ASYNC_CHECK_CD;
3377 * Setup cd1400 enhanced modes if we can. In particular we want to
3378 * handle as much of the flow control as possible automatically. As
3379 * well as saving a few CPU cycles it will also greatly improve flow
3380 * control reliability.
3382 if (tiosp->c_iflag & IXON) {
3385 if (tiosp->c_iflag & IXANY)
3389 if (tiosp->c_cflag & CRTSCTS) {
3391 mcor1 |= FIFO_RTSTHRESHOLD;
3395 * All cd1400 register values calculated so go through and set
3400 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3401 portp->portnr, portp->panelnr, portp->brdnr);
3402 printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3403 cor1, cor2, cor3, cor4, cor5);
3404 printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3405 mcor1, mcor2, rtpr, sreron, sreroff);
3406 printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3407 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3408 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3409 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3412 spin_lock_irqsave(&brd_lock, flags);
3413 BRDENABLE(portp->brdnr, portp->pagenr);
3414 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3415 srer = stl_cd1400getreg(portp, SRER);
3416 stl_cd1400setreg(portp, SRER, 0);
3417 if (stl_cd1400updatereg(portp, COR1, cor1))
3419 if (stl_cd1400updatereg(portp, COR2, cor2))
3421 if (stl_cd1400updatereg(portp, COR3, cor3))
3424 stl_cd1400ccrwait(portp);
3425 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3427 stl_cd1400setreg(portp, COR4, cor4);
3428 stl_cd1400setreg(portp, COR5, cor5);
3429 stl_cd1400setreg(portp, MCOR1, mcor1);
3430 stl_cd1400setreg(portp, MCOR2, mcor2);
3432 stl_cd1400setreg(portp, TCOR, clk);
3433 stl_cd1400setreg(portp, TBPR, div);
3434 stl_cd1400setreg(portp, RCOR, clk);
3435 stl_cd1400setreg(portp, RBPR, div);
3437 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3438 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3439 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3440 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3441 stl_cd1400setreg(portp, RTPR, rtpr);
3442 mcor1 = stl_cd1400getreg(portp, MSVR1);
3443 if (mcor1 & MSVR1_DCD)
3444 portp->sigs |= TIOCM_CD;
3446 portp->sigs &= ~TIOCM_CD;
3447 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3448 BRDDISABLE(portp->brdnr);
3449 spin_unlock_irqrestore(&brd_lock, flags);
3452 /*****************************************************************************/
3455 * Set the state of the DTR and RTS signals.
3458 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3460 unsigned char msvr1, msvr2;
3461 unsigned long flags;
3464 printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
3465 (int) portp, dtr, rts);
3475 spin_lock_irqsave(&brd_lock, flags);
3476 BRDENABLE(portp->brdnr, portp->pagenr);
3477 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3479 stl_cd1400setreg(portp, MSVR2, msvr2);
3481 stl_cd1400setreg(portp, MSVR1, msvr1);
3482 BRDDISABLE(portp->brdnr);
3483 spin_unlock_irqrestore(&brd_lock, flags);
3486 /*****************************************************************************/
3489 * Return the state of the signals.
3492 static int stl_cd1400getsignals(stlport_t *portp)
3494 unsigned char msvr1, msvr2;
3495 unsigned long flags;
3499 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3502 spin_lock_irqsave(&brd_lock, flags);
3503 BRDENABLE(portp->brdnr, portp->pagenr);
3504 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3505 msvr1 = stl_cd1400getreg(portp, MSVR1);
3506 msvr2 = stl_cd1400getreg(portp, MSVR2);
3507 BRDDISABLE(portp->brdnr);
3508 spin_unlock_irqrestore(&brd_lock, flags);
3511 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3512 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3513 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3514 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3516 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3517 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3524 /*****************************************************************************/
3527 * Enable/Disable the Transmitter and/or Receiver.
3530 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3533 unsigned long flags;
3536 printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3537 (int) portp, rx, tx);
3542 ccr |= CCR_TXDISABLE;
3544 ccr |= CCR_TXENABLE;
3546 ccr |= CCR_RXDISABLE;
3548 ccr |= CCR_RXENABLE;
3550 spin_lock_irqsave(&brd_lock, flags);
3551 BRDENABLE(portp->brdnr, portp->pagenr);
3552 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3553 stl_cd1400ccrwait(portp);
3554 stl_cd1400setreg(portp, CCR, ccr);
3555 stl_cd1400ccrwait(portp);
3556 BRDDISABLE(portp->brdnr);
3557 spin_unlock_irqrestore(&brd_lock, flags);
3560 /*****************************************************************************/
3563 * Start/stop the Transmitter and/or Receiver.
3566 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3568 unsigned char sreron, sreroff;
3569 unsigned long flags;
3572 printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3573 (int) portp, rx, tx);
3579 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3581 sreron |= SRER_TXDATA;
3583 sreron |= SRER_TXEMPTY;
3585 sreroff |= SRER_RXDATA;
3587 sreron |= SRER_RXDATA;
3589 spin_lock_irqsave(&brd_lock, flags);
3590 BRDENABLE(portp->brdnr, portp->pagenr);
3591 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3592 stl_cd1400setreg(portp, SRER,
3593 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3594 BRDDISABLE(portp->brdnr);
3596 set_bit(ASYI_TXBUSY, &portp->istate);
3597 spin_unlock_irqrestore(&brd_lock, flags);
3600 /*****************************************************************************/
3603 * Disable all interrupts from this port.
3606 static void stl_cd1400disableintrs(stlport_t *portp)
3608 unsigned long flags;
3611 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3613 spin_lock_irqsave(&brd_lock, flags);
3614 BRDENABLE(portp->brdnr, portp->pagenr);
3615 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3616 stl_cd1400setreg(portp, SRER, 0);
3617 BRDDISABLE(portp->brdnr);
3618 spin_unlock_irqrestore(&brd_lock, flags);
3621 /*****************************************************************************/
3623 static void stl_cd1400sendbreak(stlport_t *portp, int len)
3625 unsigned long flags;
3628 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
3631 spin_lock_irqsave(&brd_lock, flags);
3632 BRDENABLE(portp->brdnr, portp->pagenr);
3633 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3634 stl_cd1400setreg(portp, SRER,
3635 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3637 BRDDISABLE(portp->brdnr);
3638 portp->brklen = len;
3640 portp->stats.txbreaks++;
3641 spin_unlock_irqrestore(&brd_lock, flags);
3644 /*****************************************************************************/
3647 * Take flow control actions...
3650 static void stl_cd1400flowctrl(stlport_t *portp, int state)
3652 struct tty_struct *tty;
3653 unsigned long flags;
3656 printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp, state);
3659 if (portp == (stlport_t *) NULL)
3662 if (tty == (struct tty_struct *) NULL)
3665 spin_lock_irqsave(&brd_lock, flags);
3666 BRDENABLE(portp->brdnr, portp->pagenr);
3667 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3670 if (tty->termios->c_iflag & IXOFF) {
3671 stl_cd1400ccrwait(portp);
3672 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3673 portp->stats.rxxon++;
3674 stl_cd1400ccrwait(portp);
3677 * Question: should we return RTS to what it was before? It may
3678 * have been set by an ioctl... Suppose not, since if you have
3679 * hardware flow control set then it is pretty silly to go and
3680 * set the RTS line by hand.
3682 if (tty->termios->c_cflag & CRTSCTS) {
3683 stl_cd1400setreg(portp, MCOR1,
3684 (stl_cd1400getreg(portp, MCOR1) |
3685 FIFO_RTSTHRESHOLD));
3686 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3687 portp->stats.rxrtson++;
3690 if (tty->termios->c_iflag & IXOFF) {
3691 stl_cd1400ccrwait(portp);
3692 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3693 portp->stats.rxxoff++;
3694 stl_cd1400ccrwait(portp);
3696 if (tty->termios->c_cflag & CRTSCTS) {
3697 stl_cd1400setreg(portp, MCOR1,
3698 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3699 stl_cd1400setreg(portp, MSVR2, 0);
3700 portp->stats.rxrtsoff++;
3704 BRDDISABLE(portp->brdnr);
3705 spin_unlock_irqrestore(&brd_lock, flags);
3708 /*****************************************************************************/
3711 * Send a flow control character...
3714 static void stl_cd1400sendflow(stlport_t *portp, int state)
3716 struct tty_struct *tty;
3717 unsigned long flags;
3720 printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp, state);
3723 if (portp == (stlport_t *) NULL)
3726 if (tty == (struct tty_struct *) NULL)
3729 spin_lock_irqsave(&brd_lock, flags);
3730 BRDENABLE(portp->brdnr, portp->pagenr);
3731 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3733 stl_cd1400ccrwait(portp);
3734 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3735 portp->stats.rxxon++;
3736 stl_cd1400ccrwait(portp);
3738 stl_cd1400ccrwait(portp);
3739 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3740 portp->stats.rxxoff++;
3741 stl_cd1400ccrwait(portp);
3743 BRDDISABLE(portp->brdnr);
3744 spin_unlock_irqrestore(&brd_lock, flags);
3747 /*****************************************************************************/
3749 static void stl_cd1400flush(stlport_t *portp)
3751 unsigned long flags;
3754 printk("stl_cd1400flush(portp=%x)\n", (int) portp);
3757 if (portp == (stlport_t *) NULL)
3760 spin_lock_irqsave(&brd_lock, flags);
3761 BRDENABLE(portp->brdnr, portp->pagenr);
3762 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3763 stl_cd1400ccrwait(portp);
3764 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3765 stl_cd1400ccrwait(portp);
3766 portp->tx.tail = portp->tx.head;
3767 BRDDISABLE(portp->brdnr);
3768 spin_unlock_irqrestore(&brd_lock, flags);
3771 /*****************************************************************************/
3774 * Return the current state of data flow on this port. This is only
3775 * really interresting when determining if data has fully completed
3776 * transmission or not... This is easy for the cd1400, it accurately
3777 * maintains the busy port flag.
3780 static int stl_cd1400datastate(stlport_t *portp)
3783 printk("stl_cd1400datastate(portp=%x)\n", (int) portp);
3786 if (portp == (stlport_t *) NULL)
3789 return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
3792 /*****************************************************************************/
3795 * Interrupt service routine for cd1400 EasyIO boards.
3798 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3800 unsigned char svrtype;
3803 printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
3804 (int) panelp, iobase);
3807 spin_lock(&brd_lock);
3809 svrtype = inb(iobase + EREG_DATA);
3810 if (panelp->nrports > 4) {
3811 outb((SVRR + 0x80), iobase);
3812 svrtype |= inb(iobase + EREG_DATA);
3815 if (svrtype & SVRR_RX)
3816 stl_cd1400rxisr(panelp, iobase);
3817 else if (svrtype & SVRR_TX)
3818 stl_cd1400txisr(panelp, iobase);
3819 else if (svrtype & SVRR_MDM)
3820 stl_cd1400mdmisr(panelp, iobase);
3822 spin_unlock(&brd_lock);
3825 /*****************************************************************************/
3828 * Interrupt service routine for cd1400 panels.
3831 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
3833 unsigned char svrtype;
3836 printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
3841 svrtype = inb(iobase + EREG_DATA);
3842 outb((SVRR + 0x80), iobase);
3843 svrtype |= inb(iobase + EREG_DATA);
3844 if (svrtype & SVRR_RX)
3845 stl_cd1400rxisr(panelp, iobase);
3846 else if (svrtype & SVRR_TX)
3847 stl_cd1400txisr(panelp, iobase);
3848 else if (svrtype & SVRR_MDM)
3849 stl_cd1400mdmisr(panelp, iobase);
3853 /*****************************************************************************/
3856 * Unfortunately we need to handle breaks in the TX data stream, since
3857 * this is the only way to generate them on the cd1400.
3860 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr)
3862 if (portp->brklen == 1) {
3863 outb((COR2 + portp->uartaddr), ioaddr);
3864 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
3865 (ioaddr + EREG_DATA));
3866 outb((TDR + portp->uartaddr), ioaddr);
3867 outb(ETC_CMD, (ioaddr + EREG_DATA));
3868 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
3869 outb((SRER + portp->uartaddr), ioaddr);
3870 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
3871 (ioaddr + EREG_DATA));
3873 } else if (portp->brklen > 1) {
3874 outb((TDR + portp->uartaddr), ioaddr);
3875 outb(ETC_CMD, (ioaddr + EREG_DATA));
3876 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
3880 outb((COR2 + portp->uartaddr), ioaddr);
3881 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
3882 (ioaddr + EREG_DATA));
3888 /*****************************************************************************/
3891 * Transmit interrupt handler. This has gotta be fast! Handling TX
3892 * chars is pretty simple, stuff as many as possible from the TX buffer
3893 * into the cd1400 FIFO. Must also handle TX breaks here, since they
3894 * are embedded as commands in the data stream. Oh no, had to use a goto!
3895 * This could be optimized more, will do when I get time...
3896 * In practice it is possible that interrupts are enabled but that the
3897 * port has been hung up. Need to handle not having any TX buffer here,
3898 * this is done by using the side effect that head and tail will also
3899 * be NULL if the buffer has been freed.
3902 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
3907 unsigned char ioack, srer;
3910 printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
3913 ioack = inb(ioaddr + EREG_TXACK);
3914 if (((ioack & panelp->ackmask) != 0) ||
3915 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
3916 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
3919 portp = panelp->ports[(ioack >> 3)];
3922 * Unfortunately we need to handle breaks in the data stream, since
3923 * this is the only way to generate them on the cd1400. Do it now if
3924 * a break is to be sent.
3926 if (portp->brklen != 0)
3927 if (stl_cd1400breakisr(portp, ioaddr))
3930 head = portp->tx.head;
3931 tail = portp->tx.tail;
3932 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
3933 if ((len == 0) || ((len < STL_TXBUFLOW) &&
3934 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
3935 set_bit(ASYI_TXLOW, &portp->istate);
3936 schedule_work(&portp->tqueue);
3940 outb((SRER + portp->uartaddr), ioaddr);
3941 srer = inb(ioaddr + EREG_DATA);
3942 if (srer & SRER_TXDATA) {
3943 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
3945 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
3946 clear_bit(ASYI_TXBUSY, &portp->istate);
3948 outb(srer, (ioaddr + EREG_DATA));
3950 len = MIN(len, CD1400_TXFIFOSIZE);
3951 portp->stats.txtotal += len;
3952 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
3953 outb((TDR + portp->uartaddr), ioaddr);
3954 outsb((ioaddr + EREG_DATA), tail, stlen);
3957 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
3958 tail = portp->tx.buf;
3960 outsb((ioaddr + EREG_DATA), tail, len);
3963 portp->tx.tail = tail;
3967 outb((EOSRR + portp->uartaddr), ioaddr);
3968 outb(0, (ioaddr + EREG_DATA));
3971 /*****************************************************************************/
3974 * Receive character interrupt handler. Determine if we have good chars
3975 * or bad chars and then process appropriately. Good chars are easy
3976 * just shove the lot into the RX buffer and set all status byte to 0.
3977 * If a bad RX char then process as required. This routine needs to be
3978 * fast! In practice it is possible that we get an interrupt on a port
3979 * that is closed. This can happen on hangups - since they completely
3980 * shutdown a port not in user context. Need to handle this case.
3983 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
3986 struct tty_struct *tty;
3987 unsigned int ioack, len, buflen;
3988 unsigned char status;
3992 printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
3995 ioack = inb(ioaddr + EREG_RXACK);
3996 if ((ioack & panelp->ackmask) != 0) {
3997 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4000 portp = panelp->ports[(ioack >> 3)];
4003 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
4004 outb((RDCR + portp->uartaddr), ioaddr);
4005 len = inb(ioaddr + EREG_DATA);
4006 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
4007 len = MIN(len, sizeof(stl_unwanted));
4008 outb((RDSR + portp->uartaddr), ioaddr);
4009 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
4010 portp->stats.rxlost += len;
4011 portp->stats.rxtotal += len;
4013 len = MIN(len, buflen);
4016 outb((RDSR + portp->uartaddr), ioaddr);
4017 tty_prepare_flip_string(tty, &ptr, len);
4018 insb((ioaddr + EREG_DATA), ptr, len);
4019 tty_schedule_flip(tty);
4020 portp->stats.rxtotal += len;
4023 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
4024 outb((RDSR + portp->uartaddr), ioaddr);
4025 status = inb(ioaddr + EREG_DATA);
4026 ch = inb(ioaddr + EREG_DATA);
4027 if (status & ST_PARITY)
4028 portp->stats.rxparity++;
4029 if (status & ST_FRAMING)
4030 portp->stats.rxframing++;
4031 if (status & ST_OVERRUN)
4032 portp->stats.rxoverrun++;
4033 if (status & ST_BREAK)
4034 portp->stats.rxbreaks++;
4035 if (status & ST_SCHARMASK) {
4036 if ((status & ST_SCHARMASK) == ST_SCHAR1)
4037 portp->stats.txxon++;
4038 if ((status & ST_SCHARMASK) == ST_SCHAR2)
4039 portp->stats.txxoff++;
4042 if (tty != NULL && (portp->rxignoremsk & status) == 0) {
4043 if (portp->rxmarkmsk & status) {
4044 if (status & ST_BREAK) {
4046 if (portp->flags & ASYNC_SAK) {
4048 BRDENABLE(portp->brdnr, portp->pagenr);
4050 } else if (status & ST_PARITY) {
4051 status = TTY_PARITY;
4052 } else if (status & ST_FRAMING) {
4054 } else if(status & ST_OVERRUN) {
4055 status = TTY_OVERRUN;
4062 tty_insert_flip_char(tty, ch, status);
4063 tty_schedule_flip(tty);
4066 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4071 outb((EOSRR + portp->uartaddr), ioaddr);
4072 outb(0, (ioaddr + EREG_DATA));
4075 /*****************************************************************************/
4078 * Modem interrupt handler. The is called when the modem signal line
4079 * (DCD) has changed state. Leave most of the work to the off-level
4080 * processing routine.
4083 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
4090 printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp);
4093 ioack = inb(ioaddr + EREG_MDACK);
4094 if (((ioack & panelp->ackmask) != 0) ||
4095 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
4096 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
4099 portp = panelp->ports[(ioack >> 3)];
4101 outb((MISR + portp->uartaddr), ioaddr);
4102 misr = inb(ioaddr + EREG_DATA);
4103 if (misr & MISR_DCD) {
4104 set_bit(ASYI_DCDCHANGE, &portp->istate);
4105 schedule_work(&portp->tqueue);
4106 portp->stats.modem++;
4109 outb((EOSRR + portp->uartaddr), ioaddr);
4110 outb(0, (ioaddr + EREG_DATA));
4113 /*****************************************************************************/
4114 /* SC26198 HARDWARE FUNCTIONS */
4115 /*****************************************************************************/
4118 * These functions get/set/update the registers of the sc26198 UARTs.
4119 * Access to the sc26198 registers is via an address/data io port pair.
4120 * (Maybe should make this inline...)
4123 static int stl_sc26198getreg(stlport_t *portp, int regnr)
4125 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4126 return inb(portp->ioaddr + XP_DATA);
4129 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
4131 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4132 outb(value, (portp->ioaddr + XP_DATA));
4135 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
4137 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4138 if (inb(portp->ioaddr + XP_DATA) != value) {
4139 outb(value, (portp->ioaddr + XP_DATA));
4145 /*****************************************************************************/
4148 * Functions to get and set the sc26198 global registers.
4151 static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
4153 outb(regnr, (portp->ioaddr + XP_ADDR));
4154 return inb(portp->ioaddr + XP_DATA);
4158 static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
4160 outb(regnr, (portp->ioaddr + XP_ADDR));
4161 outb(value, (portp->ioaddr + XP_DATA));
4165 /*****************************************************************************/
4168 * Inbitialize the UARTs in a panel. We don't care what sort of board
4169 * these ports are on - since the port io registers are almost
4170 * identical when dealing with ports.
4173 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
4176 int nrchips, ioaddr;
4179 printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
4180 (int) brdp, (int) panelp);
4183 BRDENABLE(panelp->brdnr, panelp->pagenr);
4186 * Check that each chip is present and started up OK.
4189 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
4190 if (brdp->brdtype == BRD_ECHPCI)
4191 outb(panelp->pagenr, brdp->ioctrl);
4193 for (i = 0; (i < nrchips); i++) {
4194 ioaddr = panelp->iobase + (i * 4);
4195 outb(SCCR, (ioaddr + XP_ADDR));
4196 outb(CR_RESETALL, (ioaddr + XP_DATA));
4197 outb(TSTR, (ioaddr + XP_ADDR));
4198 if (inb(ioaddr + XP_DATA) != 0) {
4199 printk("STALLION: sc26198 not responding, "
4200 "brd=%d panel=%d chip=%d\n",
4201 panelp->brdnr, panelp->panelnr, i);
4204 chipmask |= (0x1 << i);
4205 outb(GCCR, (ioaddr + XP_ADDR));
4206 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
4207 outb(WDTRCR, (ioaddr + XP_ADDR));
4208 outb(0xff, (ioaddr + XP_DATA));
4211 BRDDISABLE(panelp->brdnr);
4215 /*****************************************************************************/
4218 * Initialize hardware specific port registers.
4221 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
4224 printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
4225 (int) brdp, (int) panelp, (int) portp);
4228 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
4229 (portp == (stlport_t *) NULL))
4232 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
4233 portp->uartaddr = (portp->portnr & 0x07) << 4;
4234 portp->pagenr = panelp->pagenr;
4237 BRDENABLE(portp->brdnr, portp->pagenr);
4238 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
4239 BRDDISABLE(portp->brdnr);
4242 /*****************************************************************************/
4245 * Set up the sc26198 registers for a port based on the termios port
4249 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4252 unsigned long flags;
4253 unsigned int baudrate;
4254 unsigned char mr0, mr1, mr2, clk;
4255 unsigned char imron, imroff, iopr, ipr;
4265 brdp = stl_brds[portp->brdnr];
4266 if (brdp == (stlbrd_t *) NULL)
4270 * Set up the RX char ignore mask with those RX error types we
4273 portp->rxignoremsk = 0;
4274 if (tiosp->c_iflag & IGNPAR)
4275 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
4277 if (tiosp->c_iflag & IGNBRK)
4278 portp->rxignoremsk |= SR_RXBREAK;
4280 portp->rxmarkmsk = SR_RXOVERRUN;
4281 if (tiosp->c_iflag & (INPCK | PARMRK))
4282 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
4283 if (tiosp->c_iflag & BRKINT)
4284 portp->rxmarkmsk |= SR_RXBREAK;
4287 * Go through the char size, parity and stop bits and set all the
4288 * option register appropriately.
4290 switch (tiosp->c_cflag & CSIZE) {
4305 if (tiosp->c_cflag & CSTOPB)
4310 if (tiosp->c_cflag & PARENB) {
4311 if (tiosp->c_cflag & PARODD)
4312 mr1 |= (MR1_PARENB | MR1_PARODD);
4314 mr1 |= (MR1_PARENB | MR1_PAREVEN);
4319 mr1 |= MR1_ERRBLOCK;
4322 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4323 * space for hardware flow control and the like. This should be set to
4326 mr2 |= MR2_RXFIFOHALF;
4329 * Calculate the baud rate timers. For now we will just assume that
4330 * the input and output baud are the same. The sc26198 has a fixed
4331 * baud rate table, so only discrete baud rates possible.
4333 baudrate = tiosp->c_cflag & CBAUD;
4334 if (baudrate & CBAUDEX) {
4335 baudrate &= ~CBAUDEX;
4336 if ((baudrate < 1) || (baudrate > 4))
4337 tiosp->c_cflag &= ~CBAUDEX;
4341 baudrate = stl_baudrates[baudrate];
4342 if ((tiosp->c_cflag & CBAUD) == B38400) {
4343 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
4345 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
4347 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
4349 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
4351 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
4352 baudrate = (portp->baud_base / portp->custom_divisor);
4354 if (baudrate > STL_SC26198MAXBAUD)
4355 baudrate = STL_SC26198MAXBAUD;
4358 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
4359 if (baudrate <= sc26198_baudtable[clk])
4365 * Check what form of modem signaling is required and set it up.
4367 if (tiosp->c_cflag & CLOCAL) {
4368 portp->flags &= ~ASYNC_CHECK_CD;
4370 iopr |= IOPR_DCDCOS;
4372 portp->flags |= ASYNC_CHECK_CD;
4376 * Setup sc26198 enhanced modes if we can. In particular we want to
4377 * handle as much of the flow control as possible automatically. As
4378 * well as saving a few CPU cycles it will also greatly improve flow
4379 * control reliability.
4381 if (tiosp->c_iflag & IXON) {
4382 mr0 |= MR0_SWFTX | MR0_SWFT;
4383 imron |= IR_XONXOFF;
4385 imroff |= IR_XONXOFF;
4387 if (tiosp->c_iflag & IXOFF)
4390 if (tiosp->c_cflag & CRTSCTS) {
4396 * All sc26198 register values calculated so go through and set
4401 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4402 portp->portnr, portp->panelnr, portp->brdnr);
4403 printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4404 printk(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4405 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4406 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4407 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4410 spin_lock_irqsave(&brd_lock, flags);
4411 BRDENABLE(portp->brdnr, portp->pagenr);
4412 stl_sc26198setreg(portp, IMR, 0);
4413 stl_sc26198updatereg(portp, MR0, mr0);
4414 stl_sc26198updatereg(portp, MR1, mr1);
4415 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4416 stl_sc26198updatereg(portp, MR2, mr2);
4417 stl_sc26198updatereg(portp, IOPIOR,
4418 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
4421 stl_sc26198setreg(portp, TXCSR, clk);
4422 stl_sc26198setreg(portp, RXCSR, clk);
4425 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4426 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4428 ipr = stl_sc26198getreg(portp, IPR);
4430 portp->sigs &= ~TIOCM_CD;
4432 portp->sigs |= TIOCM_CD;
4434 portp->imr = (portp->imr & ~imroff) | imron;
4435 stl_sc26198setreg(portp, IMR, portp->imr);
4436 BRDDISABLE(portp->brdnr);
4437 spin_unlock_irqrestore(&brd_lock, flags);
4440 /*****************************************************************************/
4443 * Set the state of the DTR and RTS signals.
4446 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
4448 unsigned char iopioron, iopioroff;
4449 unsigned long flags;
4452 printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4453 (int) portp, dtr, rts);
4459 iopioroff |= IPR_DTR;
4461 iopioron |= IPR_DTR;
4463 iopioroff |= IPR_RTS;
4465 iopioron |= IPR_RTS;
4467 spin_lock_irqsave(&brd_lock, flags);
4468 BRDENABLE(portp->brdnr, portp->pagenr);
4469 stl_sc26198setreg(portp, IOPIOR,
4470 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4471 BRDDISABLE(portp->brdnr);
4472 spin_unlock_irqrestore(&brd_lock, flags);
4475 /*****************************************************************************/
4478 * Return the state of the signals.
4481 static int stl_sc26198getsignals(stlport_t *portp)
4484 unsigned long flags;
4488 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
4491 spin_lock_irqsave(&brd_lock, flags);
4492 BRDENABLE(portp->brdnr, portp->pagenr);
4493 ipr = stl_sc26198getreg(portp, IPR);
4494 BRDDISABLE(portp->brdnr);
4495 spin_unlock_irqrestore(&brd_lock, flags);
4498 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4499 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4500 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4501 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4506 /*****************************************************************************/
4509 * Enable/Disable the Transmitter and/or Receiver.
4512 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
4515 unsigned long flags;
4518 printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4519 (int) portp, rx, tx);
4522 ccr = portp->crenable;
4524 ccr &= ~CR_TXENABLE;
4528 ccr &= ~CR_RXENABLE;
4532 spin_lock_irqsave(&brd_lock, flags);
4533 BRDENABLE(portp->brdnr, portp->pagenr);
4534 stl_sc26198setreg(portp, SCCR, ccr);
4535 BRDDISABLE(portp->brdnr);
4536 portp->crenable = ccr;
4537 spin_unlock_irqrestore(&brd_lock, flags);
4540 /*****************************************************************************/
4543 * Start/stop the Transmitter and/or Receiver.
4546 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
4549 unsigned long flags;
4552 printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4553 (int) portp, rx, tx);
4562 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4564 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4566 spin_lock_irqsave(&brd_lock, flags);
4567 BRDENABLE(portp->brdnr, portp->pagenr);
4568 stl_sc26198setreg(portp, IMR, imr);
4569 BRDDISABLE(portp->brdnr);
4572 set_bit(ASYI_TXBUSY, &portp->istate);
4573 spin_unlock_irqrestore(&brd_lock, flags);
4576 /*****************************************************************************/
4579 * Disable all interrupts from this port.
4582 static void stl_sc26198disableintrs(stlport_t *portp)
4584 unsigned long flags;
4587 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
4590 spin_lock_irqsave(&brd_lock, flags);
4591 BRDENABLE(portp->brdnr, portp->pagenr);
4593 stl_sc26198setreg(portp, IMR, 0);
4594 BRDDISABLE(portp->brdnr);
4595 spin_unlock_irqrestore(&brd_lock, flags);
4598 /*****************************************************************************/
4600 static void stl_sc26198sendbreak(stlport_t *portp, int len)
4602 unsigned long flags;
4605 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
4608 spin_lock_irqsave(&brd_lock, flags);
4609 BRDENABLE(portp->brdnr, portp->pagenr);
4611 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4612 portp->stats.txbreaks++;
4614 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4616 BRDDISABLE(portp->brdnr);
4617 spin_unlock_irqrestore(&brd_lock, flags);
4620 /*****************************************************************************/
4623 * Take flow control actions...
4626 static void stl_sc26198flowctrl(stlport_t *portp, int state)
4628 struct tty_struct *tty;
4629 unsigned long flags;
4633 printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp, state);
4636 if (portp == (stlport_t *) NULL)
4639 if (tty == (struct tty_struct *) NULL)
4642 spin_lock_irqsave(&brd_lock, flags);
4643 BRDENABLE(portp->brdnr, portp->pagenr);
4646 if (tty->termios->c_iflag & IXOFF) {
4647 mr0 = stl_sc26198getreg(portp, MR0);
4648 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4649 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4651 portp->stats.rxxon++;
4652 stl_sc26198wait(portp);
4653 stl_sc26198setreg(portp, MR0, mr0);
4656 * Question: should we return RTS to what it was before? It may
4657 * have been set by an ioctl... Suppose not, since if you have
4658 * hardware flow control set then it is pretty silly to go and
4659 * set the RTS line by hand.
4661 if (tty->termios->c_cflag & CRTSCTS) {
4662 stl_sc26198setreg(portp, MR1,
4663 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4664 stl_sc26198setreg(portp, IOPIOR,
4665 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4666 portp->stats.rxrtson++;
4669 if (tty->termios->c_iflag & IXOFF) {
4670 mr0 = stl_sc26198getreg(portp, MR0);
4671 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4672 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4674 portp->stats.rxxoff++;
4675 stl_sc26198wait(portp);
4676 stl_sc26198setreg(portp, MR0, mr0);
4678 if (tty->termios->c_cflag & CRTSCTS) {
4679 stl_sc26198setreg(portp, MR1,
4680 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4681 stl_sc26198setreg(portp, IOPIOR,
4682 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4683 portp->stats.rxrtsoff++;
4687 BRDDISABLE(portp->brdnr);
4688 spin_unlock_irqrestore(&brd_lock, flags);
4691 /*****************************************************************************/
4694 * Send a flow control character.
4697 static void stl_sc26198sendflow(stlport_t *portp, int state)
4699 struct tty_struct *tty;
4700 unsigned long flags;
4704 printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp, state);
4707 if (portp == (stlport_t *) NULL)
4710 if (tty == (struct tty_struct *) NULL)
4713 spin_lock_irqsave(&brd_lock, flags);
4714 BRDENABLE(portp->brdnr, portp->pagenr);
4716 mr0 = stl_sc26198getreg(portp, MR0);
4717 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4718 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4720 portp->stats.rxxon++;
4721 stl_sc26198wait(portp);
4722 stl_sc26198setreg(portp, MR0, mr0);
4724 mr0 = stl_sc26198getreg(portp, MR0);
4725 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4726 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4728 portp->stats.rxxoff++;
4729 stl_sc26198wait(portp);
4730 stl_sc26198setreg(portp, MR0, mr0);
4732 BRDDISABLE(portp->brdnr);
4733 spin_unlock_irqrestore(&brd_lock, flags);
4736 /*****************************************************************************/
4738 static void stl_sc26198flush(stlport_t *portp)
4740 unsigned long flags;
4743 printk("stl_sc26198flush(portp=%x)\n", (int) portp);
4746 if (portp == (stlport_t *) NULL)
4749 spin_lock_irqsave(&brd_lock, flags);
4750 BRDENABLE(portp->brdnr, portp->pagenr);
4751 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4752 stl_sc26198setreg(portp, SCCR, portp->crenable);
4753 BRDDISABLE(portp->brdnr);
4754 portp->tx.tail = portp->tx.head;
4755 spin_unlock_irqrestore(&brd_lock, flags);
4758 /*****************************************************************************/
4761 * Return the current state of data flow on this port. This is only
4762 * really interresting when determining if data has fully completed
4763 * transmission or not... The sc26198 interrupt scheme cannot
4764 * determine when all data has actually drained, so we need to
4765 * check the port statusy register to be sure.
4768 static int stl_sc26198datastate(stlport_t *portp)
4770 unsigned long flags;
4774 printk("stl_sc26198datastate(portp=%x)\n", (int) portp);
4777 if (portp == (stlport_t *) NULL)
4779 if (test_bit(ASYI_TXBUSY, &portp->istate))
4782 spin_lock_irqsave(&brd_lock, flags);
4783 BRDENABLE(portp->brdnr, portp->pagenr);
4784 sr = stl_sc26198getreg(portp, SR);
4785 BRDDISABLE(portp->brdnr);
4786 spin_unlock_irqrestore(&brd_lock, flags);
4788 return (sr & SR_TXEMPTY) ? 0 : 1;
4791 /*****************************************************************************/
4794 * Delay for a small amount of time, to give the sc26198 a chance
4795 * to process a command...
4798 static void stl_sc26198wait(stlport_t *portp)
4803 printk("stl_sc26198wait(portp=%x)\n", (int) portp);
4806 if (portp == (stlport_t *) NULL)
4809 for (i = 0; (i < 20); i++)
4810 stl_sc26198getglobreg(portp, TSTR);
4813 /*****************************************************************************/
4816 * If we are TX flow controlled and in IXANY mode then we may
4817 * need to unflow control here. We gotta do this because of the
4818 * automatic flow control modes of the sc26198.
4821 static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty)
4825 mr0 = stl_sc26198getreg(portp, MR0);
4826 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4827 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4828 stl_sc26198wait(portp);
4829 stl_sc26198setreg(portp, MR0, mr0);
4830 clear_bit(ASYI_TXFLOWED, &portp->istate);
4833 /*****************************************************************************/
4836 * Interrupt service routine for sc26198 panels.
4839 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4844 spin_lock(&brd_lock);
4847 * Work around bug in sc26198 chip... Cannot have A6 address
4848 * line of UART high, else iack will be returned as 0.
4850 outb(0, (iobase + 1));
4852 iack = inb(iobase + XP_IACK);
4853 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4855 if (iack & IVR_RXDATA)
4856 stl_sc26198rxisr(portp, iack);
4857 else if (iack & IVR_TXDATA)
4858 stl_sc26198txisr(portp);
4860 stl_sc26198otherisr(portp, iack);
4862 spin_unlock(&brd_lock);
4865 /*****************************************************************************/
4868 * Transmit interrupt handler. This has gotta be fast! Handling TX
4869 * chars is pretty simple, stuff as many as possible from the TX buffer
4870 * into the sc26198 FIFO.
4871 * In practice it is possible that interrupts are enabled but that the
4872 * port has been hung up. Need to handle not having any TX buffer here,
4873 * this is done by using the side effect that head and tail will also
4874 * be NULL if the buffer has been freed.
4877 static void stl_sc26198txisr(stlport_t *portp)
4879 unsigned int ioaddr;
4885 printk("stl_sc26198txisr(portp=%x)\n", (int) portp);
4888 ioaddr = portp->ioaddr;
4889 head = portp->tx.head;
4890 tail = portp->tx.tail;
4891 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4892 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4893 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4894 set_bit(ASYI_TXLOW, &portp->istate);
4895 schedule_work(&portp->tqueue);
4899 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
4900 mr0 = inb(ioaddr + XP_DATA);
4901 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4902 portp->imr &= ~IR_TXRDY;
4903 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
4904 outb(portp->imr, (ioaddr + XP_DATA));
4905 clear_bit(ASYI_TXBUSY, &portp->istate);
4907 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4908 outb(mr0, (ioaddr + XP_DATA));
4911 len = MIN(len, SC26198_TXFIFOSIZE);
4912 portp->stats.txtotal += len;
4913 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4914 outb(GTXFIFO, (ioaddr + XP_ADDR));
4915 outsb((ioaddr + XP_DATA), tail, stlen);
4918 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4919 tail = portp->tx.buf;
4921 outsb((ioaddr + XP_DATA), tail, len);
4924 portp->tx.tail = tail;
4928 /*****************************************************************************/
4931 * Receive character interrupt handler. Determine if we have good chars
4932 * or bad chars and then process appropriately. Good chars are easy
4933 * just shove the lot into the RX buffer and set all status byte to 0.
4934 * If a bad RX char then process as required. This routine needs to be
4935 * fast! In practice it is possible that we get an interrupt on a port
4936 * that is closed. This can happen on hangups - since they completely
4937 * shutdown a port not in user context. Need to handle this case.
4940 static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
4942 struct tty_struct *tty;
4943 unsigned int len, buflen, ioaddr;
4946 printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
4950 ioaddr = portp->ioaddr;
4951 outb(GIBCR, (ioaddr + XP_ADDR));
4952 len = inb(ioaddr + XP_DATA) + 1;
4954 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
4955 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
4956 len = MIN(len, sizeof(stl_unwanted));
4957 outb(GRXFIFO, (ioaddr + XP_ADDR));
4958 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4959 portp->stats.rxlost += len;
4960 portp->stats.rxtotal += len;
4962 len = MIN(len, buflen);
4965 outb(GRXFIFO, (ioaddr + XP_ADDR));
4966 tty_prepare_flip_string(tty, &ptr, len);
4967 insb((ioaddr + XP_DATA), ptr, len);
4968 tty_schedule_flip(tty);
4969 portp->stats.rxtotal += len;
4973 stl_sc26198rxbadchars(portp);
4977 * If we are TX flow controlled and in IXANY mode then we may need
4978 * to unflow control here. We gotta do this because of the automatic
4979 * flow control modes of the sc26198.
4981 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
4982 if ((tty != (struct tty_struct *) NULL) &&
4983 (tty->termios != (struct termios *) NULL) &&
4984 (tty->termios->c_iflag & IXANY)) {
4985 stl_sc26198txunflow(portp, tty);
4990 /*****************************************************************************/
4993 * Process an RX bad character.
4996 static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch)
4998 struct tty_struct *tty;
4999 unsigned int ioaddr;
5002 ioaddr = portp->ioaddr;
5004 if (status & SR_RXPARITY)
5005 portp->stats.rxparity++;
5006 if (status & SR_RXFRAMING)
5007 portp->stats.rxframing++;
5008 if (status & SR_RXOVERRUN)
5009 portp->stats.rxoverrun++;
5010 if (status & SR_RXBREAK)
5011 portp->stats.rxbreaks++;
5013 if ((tty != (struct tty_struct *) NULL) &&
5014 ((portp->rxignoremsk & status) == 0)) {
5015 if (portp->rxmarkmsk & status) {
5016 if (status & SR_RXBREAK) {
5018 if (portp->flags & ASYNC_SAK) {
5020 BRDENABLE(portp->brdnr, portp->pagenr);
5022 } else if (status & SR_RXPARITY) {
5023 status = TTY_PARITY;
5024 } else if (status & SR_RXFRAMING) {
5026 } else if(status & SR_RXOVERRUN) {
5027 status = TTY_OVERRUN;
5035 tty_insert_flip_char(tty, ch, status);
5036 tty_schedule_flip(tty);
5039 portp->stats.rxtotal++;
5043 /*****************************************************************************/
5046 * Process all characters in the RX FIFO of the UART. Check all char
5047 * status bytes as well, and process as required. We need to check
5048 * all bytes in the FIFO, in case some more enter the FIFO while we
5049 * are here. To get the exact character error type we need to switch
5050 * into CHAR error mode (that is why we need to make sure we empty
5054 static void stl_sc26198rxbadchars(stlport_t *portp)
5056 unsigned char status, mr1;
5060 * To get the precise error type for each character we must switch
5061 * back into CHAR error mode.
5063 mr1 = stl_sc26198getreg(portp, MR1);
5064 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
5066 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
5067 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
5068 ch = stl_sc26198getreg(portp, RXFIFO);
5069 stl_sc26198rxbadch(portp, status, ch);
5073 * To get correct interrupt class we must switch back into BLOCK
5076 stl_sc26198setreg(portp, MR1, mr1);
5079 /*****************************************************************************/
5082 * Other interrupt handler. This includes modem signals, flow
5083 * control actions, etc. Most stuff is left to off-level interrupt
5087 static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
5089 unsigned char cir, ipr, xisr;
5092 printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
5095 cir = stl_sc26198getglobreg(portp, CIR);
5097 switch (cir & CIR_SUBTYPEMASK) {
5099 ipr = stl_sc26198getreg(portp, IPR);
5100 if (ipr & IPR_DCDCHANGE) {
5101 set_bit(ASYI_DCDCHANGE, &portp->istate);
5102 schedule_work(&portp->tqueue);
5103 portp->stats.modem++;
5106 case CIR_SUBXONXOFF:
5107 xisr = stl_sc26198getreg(portp, XISR);
5108 if (xisr & XISR_RXXONGOT) {
5109 set_bit(ASYI_TXFLOWED, &portp->istate);
5110 portp->stats.txxoff++;
5112 if (xisr & XISR_RXXOFFGOT) {
5113 clear_bit(ASYI_TXFLOWED, &portp->istate);
5114 portp->stats.txxon++;
5118 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
5119 stl_sc26198rxbadchars(portp);
5126 /*****************************************************************************/