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 = sizeof(stl_brdconf) / sizeof(stlconf_t);
108 /*****************************************************************************/
111 * Define some important driver characteristics. Device major numbers
112 * allocated as per Linux Device Registry.
114 #ifndef STL_SIOMEMMAJOR
115 #define STL_SIOMEMMAJOR 28
117 #ifndef STL_SERIALMAJOR
118 #define STL_SERIALMAJOR 24
120 #ifndef STL_CALLOUTMAJOR
121 #define STL_CALLOUTMAJOR 25
125 * Set the TX buffer size. Bigger is better, but we don't want
126 * to chew too much memory with buffers!
128 #define STL_TXBUFLOW 512
129 #define STL_TXBUFSIZE 4096
131 /*****************************************************************************/
134 * Define our local driver identity first. Set up stuff to deal with
135 * all the local structures required by a serial tty driver.
137 static char *stl_drvtitle = "Stallion Multiport Serial Driver";
138 static char *stl_drvname = "stallion";
139 static char *stl_drvversion = "5.6.0";
141 static struct tty_driver *stl_serial;
144 * We will need to allocate a temporary write buffer for chars that
145 * come direct from user space. The problem is that a copy from user
146 * space might cause a page fault (typically on a system that is
147 * swapping!). All ports will share one buffer - since if the system
148 * is already swapping a shared buffer won't make things any worse.
150 static char *stl_tmpwritebuf;
151 static DECLARE_MUTEX(stl_tmpwritesem);
154 * Define a local default termios struct. All ports will be created
155 * with this termios initially. Basically all it defines is a raw port
156 * at 9600, 8 data bits, 1 stop bit.
158 static struct termios stl_deftermios = {
159 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
164 * Define global stats structures. Not used often, and can be
165 * re-used for each stats call.
167 static comstats_t stl_comstats;
168 static combrd_t stl_brdstats;
169 static stlbrd_t stl_dummybrd;
170 static stlport_t stl_dummyport;
173 * Define global place to put buffer overflow characters.
175 static char stl_unwanted[SC26198_RXFIFOSIZE];
178 * Keep track of what interrupts we have requested for us.
179 * We don't need to request an interrupt twice if it is being
180 * shared with another Stallion board.
182 static int stl_gotintrs[STL_MAXBRDS];
183 static int stl_numintrs;
185 /*****************************************************************************/
187 static stlbrd_t *stl_brds[STL_MAXBRDS];
190 * Per board state flags. Used with the state field of the board struct.
191 * Not really much here!
193 #define BRD_FOUND 0x1
196 * Define the port structure istate flags. These set of flags are
197 * modified at interrupt time - so setting and reseting them needs
198 * to be atomic. Use the bit clear/setting routines for this.
200 #define ASYI_TXBUSY 1
202 #define ASYI_DCDCHANGE 3
203 #define ASYI_TXFLOWED 4
206 * Define an array of board names as printable strings. Handy for
207 * referencing boards when printing trace and stuff.
209 static char *stl_brdnames[] = {
241 /*****************************************************************************/
245 * Define some string labels for arguments passed from the module
246 * load line. These allow for easy board definitions, and easy
247 * modification of the io, memory and irq resoucres.
250 static char *board0[4];
251 static char *board1[4];
252 static char *board2[4];
253 static char *board3[4];
255 static char **stl_brdsp[] = {
263 * Define a set of common board names, and types. This is used to
264 * parse any module arguments.
267 typedef struct stlbrdtype {
272 static stlbrdtype_t stl_brdstr[] = {
273 { "easyio", BRD_EASYIO },
274 { "eio", BRD_EASYIO },
275 { "20", BRD_EASYIO },
276 { "ec8/32", BRD_ECH },
277 { "ec8/32-at", BRD_ECH },
278 { "ec8/32-isa", BRD_ECH },
280 { "echat", BRD_ECH },
282 { "ec8/32-mc", BRD_ECHMC },
283 { "ec8/32-mca", BRD_ECHMC },
284 { "echmc", BRD_ECHMC },
285 { "echmca", BRD_ECHMC },
287 { "ec8/32-pc", BRD_ECHPCI },
288 { "ec8/32-pci", BRD_ECHPCI },
289 { "26", BRD_ECHPCI },
290 { "ec8/64-pc", BRD_ECH64PCI },
291 { "ec8/64-pci", BRD_ECH64PCI },
292 { "ech-pci", BRD_ECH64PCI },
293 { "echpci", BRD_ECH64PCI },
294 { "echpc", BRD_ECH64PCI },
295 { "27", BRD_ECH64PCI },
296 { "easyio-pc", BRD_EASYIOPCI },
297 { "easyio-pci", BRD_EASYIOPCI },
298 { "eio-pci", BRD_EASYIOPCI },
299 { "eiopci", BRD_EASYIOPCI },
300 { "28", BRD_EASYIOPCI },
304 * Define the module agruments.
306 MODULE_AUTHOR("Greg Ungerer");
307 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
308 MODULE_LICENSE("GPL");
310 MODULE_PARM(board0, "1-4s");
311 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
312 MODULE_PARM(board1, "1-4s");
313 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
314 MODULE_PARM(board2, "1-4s");
315 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
316 MODULE_PARM(board3, "1-4s");
317 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
321 /*****************************************************************************/
324 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
325 * to the directly accessible io ports of these boards (not the uarts -
326 * they are in cd1400.h and sc26198.h).
328 #define EIO_8PORTRS 0x04
329 #define EIO_4PORTRS 0x05
330 #define EIO_8PORTDI 0x00
331 #define EIO_8PORTM 0x06
333 #define EIO_IDBITMASK 0x07
335 #define EIO_BRDMASK 0xf0
338 #define ID_BRD16 0x30
340 #define EIO_INTRPEND 0x08
341 #define EIO_INTEDGE 0x00
342 #define EIO_INTLEVEL 0x08
346 #define ECH_IDBITMASK 0xe0
347 #define ECH_BRDENABLE 0x08
348 #define ECH_BRDDISABLE 0x00
349 #define ECH_INTENABLE 0x01
350 #define ECH_INTDISABLE 0x00
351 #define ECH_INTLEVEL 0x02
352 #define ECH_INTEDGE 0x00
353 #define ECH_INTRPEND 0x01
354 #define ECH_BRDRESET 0x01
356 #define ECHMC_INTENABLE 0x01
357 #define ECHMC_BRDRESET 0x02
359 #define ECH_PNLSTATUS 2
360 #define ECH_PNL16PORT 0x20
361 #define ECH_PNLIDMASK 0x07
362 #define ECH_PNLXPID 0x40
363 #define ECH_PNLINTRPEND 0x80
365 #define ECH_ADDR2MASK 0x1e0
368 * Define the vector mapping bits for the programmable interrupt board
369 * hardware. These bits encode the interrupt for the board to use - it
370 * is software selectable (except the EIO-8M).
372 static unsigned char stl_vecmap[] = {
373 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
374 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
378 * Set up enable and disable macros for the ECH boards. They require
379 * the secondary io address space to be activated and deactivated.
380 * This way all ECH boards can share their secondary io region.
381 * If this is an ECH-PCI board then also need to set the page pointer
382 * to point to the correct page.
384 #define BRDENABLE(brdnr,pagenr) \
385 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
386 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
387 stl_brds[(brdnr)]->ioctrl); \
388 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
389 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
391 #define BRDDISABLE(brdnr) \
392 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
393 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
394 stl_brds[(brdnr)]->ioctrl);
396 #define STL_CD1400MAXBAUD 230400
397 #define STL_SC26198MAXBAUD 460800
399 #define STL_BAUDBASE 115200
400 #define STL_CLOSEDELAY (5 * HZ / 10)
402 /*****************************************************************************/
407 * Define the Stallion PCI vendor and device IDs.
409 #ifndef PCI_VENDOR_ID_STALLION
410 #define PCI_VENDOR_ID_STALLION 0x124d
412 #ifndef PCI_DEVICE_ID_ECHPCI832
413 #define PCI_DEVICE_ID_ECHPCI832 0x0000
415 #ifndef PCI_DEVICE_ID_ECHPCI864
416 #define PCI_DEVICE_ID_ECHPCI864 0x0002
418 #ifndef PCI_DEVICE_ID_EIOPCI
419 #define PCI_DEVICE_ID_EIOPCI 0x0003
423 * Define structure to hold all Stallion PCI boards.
425 typedef struct stlpcibrd {
426 unsigned short vendid;
427 unsigned short devid;
431 static stlpcibrd_t stl_pcibrds[] = {
432 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864, BRD_ECH64PCI },
433 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI, BRD_EASYIOPCI },
434 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832, BRD_ECHPCI },
435 { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
438 static int stl_nrpcibrds = sizeof(stl_pcibrds) / sizeof(stlpcibrd_t);
442 /*****************************************************************************/
445 * Define macros to extract a brd/port number from a minor number.
447 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
448 #define MINOR2PORT(min) ((min) & 0x3f)
451 * Define a baud rate table that converts termios baud rate selector
452 * into the actual baud rate value. All baud rate calculations are
453 * based on the actual baud rate required.
455 static unsigned int stl_baudrates[] = {
456 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
457 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
461 * Define some handy local macros...
464 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
467 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
469 /*****************************************************************************/
472 * Declare all those functions in this driver!
476 static void stl_argbrds(void);
477 static int stl_parsebrd(stlconf_t *confp, char **argp);
479 static unsigned long stl_atol(char *str);
483 static int stl_open(struct tty_struct *tty, struct file *filp);
484 static void stl_close(struct tty_struct *tty, struct file *filp);
485 static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count);
486 static void stl_putchar(struct tty_struct *tty, unsigned char ch);
487 static void stl_flushchars(struct tty_struct *tty);
488 static int stl_writeroom(struct tty_struct *tty);
489 static int stl_charsinbuffer(struct tty_struct *tty);
490 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
491 static void stl_settermios(struct tty_struct *tty, struct termios *old);
492 static void stl_throttle(struct tty_struct *tty);
493 static void stl_unthrottle(struct tty_struct *tty);
494 static void stl_stop(struct tty_struct *tty);
495 static void stl_start(struct tty_struct *tty);
496 static void stl_flushbuffer(struct tty_struct *tty);
497 static void stl_breakctl(struct tty_struct *tty, int state);
498 static void stl_waituntilsent(struct tty_struct *tty, int timeout);
499 static void stl_sendxchar(struct tty_struct *tty, char ch);
500 static void stl_hangup(struct tty_struct *tty);
501 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
502 static int stl_portinfo(stlport_t *portp, int portnr, char *pos);
503 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data);
505 static int stl_brdinit(stlbrd_t *brdp);
506 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
507 static int stl_mapirq(int irq, char *name);
508 static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp);
509 static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp);
510 static int stl_getbrdstats(combrd_t __user *bp);
511 static int stl_getportstats(stlport_t *portp, comstats_t __user *cp);
512 static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp);
513 static int stl_getportstruct(stlport_t __user *arg);
514 static int stl_getbrdstruct(stlbrd_t __user *arg);
515 static int stl_waitcarrier(stlport_t *portp, struct file *filp);
516 static void stl_eiointr(stlbrd_t *brdp);
517 static void stl_echatintr(stlbrd_t *brdp);
518 static void stl_echmcaintr(stlbrd_t *brdp);
519 static void stl_echpciintr(stlbrd_t *brdp);
520 static void stl_echpci64intr(stlbrd_t *brdp);
521 static void stl_offintr(void *private);
522 static void *stl_memalloc(int len);
523 static stlbrd_t *stl_allocbrd(void);
524 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
526 static inline int stl_initbrds(void);
527 static inline int stl_initeio(stlbrd_t *brdp);
528 static inline int stl_initech(stlbrd_t *brdp);
529 static inline int stl_getbrdnr(void);
532 static inline int stl_findpcibrds(void);
533 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp);
537 * CD1400 uart specific handling functions.
539 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value);
540 static int stl_cd1400getreg(stlport_t *portp, int regnr);
541 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value);
542 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
543 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
544 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp);
545 static int stl_cd1400getsignals(stlport_t *portp);
546 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts);
547 static void stl_cd1400ccrwait(stlport_t *portp);
548 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx);
549 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx);
550 static void stl_cd1400disableintrs(stlport_t *portp);
551 static void stl_cd1400sendbreak(stlport_t *portp, int len);
552 static void stl_cd1400flowctrl(stlport_t *portp, int state);
553 static void stl_cd1400sendflow(stlport_t *portp, int state);
554 static void stl_cd1400flush(stlport_t *portp);
555 static int stl_cd1400datastate(stlport_t *portp);
556 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase);
557 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase);
558 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr);
559 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr);
560 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr);
562 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr);
565 * SC26198 uart specific handling functions.
567 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value);
568 static int stl_sc26198getreg(stlport_t *portp, int regnr);
569 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value);
570 static int stl_sc26198getglobreg(stlport_t *portp, int regnr);
571 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
572 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
573 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp);
574 static int stl_sc26198getsignals(stlport_t *portp);
575 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts);
576 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx);
577 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx);
578 static void stl_sc26198disableintrs(stlport_t *portp);
579 static void stl_sc26198sendbreak(stlport_t *portp, int len);
580 static void stl_sc26198flowctrl(stlport_t *portp, int state);
581 static void stl_sc26198sendflow(stlport_t *portp, int state);
582 static void stl_sc26198flush(stlport_t *portp);
583 static int stl_sc26198datastate(stlport_t *portp);
584 static void stl_sc26198wait(stlport_t *portp);
585 static void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty);
586 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase);
587 static void stl_sc26198txisr(stlport_t *port);
588 static void stl_sc26198rxisr(stlport_t *port, unsigned int iack);
589 static void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch);
590 static void stl_sc26198rxbadchars(stlport_t *portp);
591 static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
593 /*****************************************************************************/
596 * Generic UART support structure.
598 typedef struct uart {
599 int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp);
600 void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
601 void (*setport)(stlport_t *portp, struct termios *tiosp);
602 int (*getsignals)(stlport_t *portp);
603 void (*setsignals)(stlport_t *portp, int dtr, int rts);
604 void (*enablerxtx)(stlport_t *portp, int rx, int tx);
605 void (*startrxtx)(stlport_t *portp, int rx, int tx);
606 void (*disableintrs)(stlport_t *portp);
607 void (*sendbreak)(stlport_t *portp, int len);
608 void (*flowctrl)(stlport_t *portp, int state);
609 void (*sendflow)(stlport_t *portp, int state);
610 void (*flush)(stlport_t *portp);
611 int (*datastate)(stlport_t *portp);
612 void (*intr)(stlpanel_t *panelp, unsigned int iobase);
616 * Define some macros to make calling these functions nice and clean.
618 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
619 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
620 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
621 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
622 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
623 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
624 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
625 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
626 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
627 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
628 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
629 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
630 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
632 /*****************************************************************************/
635 * CD1400 UART specific data initialization.
637 static uart_t stl_cd1400uart = {
641 stl_cd1400getsignals,
642 stl_cd1400setsignals,
643 stl_cd1400enablerxtx,
645 stl_cd1400disableintrs,
655 * Define the offsets within the register bank of a cd1400 based panel.
656 * These io address offsets are common to the EasyIO board as well.
664 #define EREG_BANKSIZE 8
666 #define CD1400_CLK 25000000
667 #define CD1400_CLK8M 20000000
670 * Define the cd1400 baud rate clocks. These are used when calculating
671 * what clock and divisor to use for the required baud rate. Also
672 * define the maximum baud rate allowed, and the default base baud.
674 static int stl_cd1400clkdivs[] = {
675 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
678 /*****************************************************************************/
681 * SC26198 UART specific data initization.
683 static uart_t stl_sc26198uart = {
684 stl_sc26198panelinit,
687 stl_sc26198getsignals,
688 stl_sc26198setsignals,
689 stl_sc26198enablerxtx,
690 stl_sc26198startrxtx,
691 stl_sc26198disableintrs,
692 stl_sc26198sendbreak,
696 stl_sc26198datastate,
701 * Define the offsets within the register bank of a sc26198 based panel.
709 #define XP_BANKSIZE 4
712 * Define the sc26198 baud rate table. Offsets within the table
713 * represent the actual baud rate selector of sc26198 registers.
715 static unsigned int sc26198_baudtable[] = {
716 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
717 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
718 230400, 460800, 921600
721 #define SC26198_NRBAUDS (sizeof(sc26198_baudtable) / sizeof(unsigned int))
723 /*****************************************************************************/
726 * Define the driver info for a user level control device. Used mainly
727 * to get at port stats - only not using the port device itself.
729 static struct file_operations stl_fsiomem = {
730 .owner = THIS_MODULE,
731 .ioctl = stl_memioctl,
734 /*****************************************************************************/
736 static struct class_simple *stallion_class;
741 * Loadable module initialization stuff.
744 static int __init stallion_module_init(void)
749 printk("init_module()\n");
755 restore_flags(flags);
760 /*****************************************************************************/
762 static void __exit stallion_module_exit(void)
771 printk("cleanup_module()\n");
774 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
781 * Free up all allocated resources used by the ports. This includes
782 * memory and interrupts. As part of this process we will also do
783 * a hangup on every open port - to try to flush out any processes
784 * hanging onto ports.
786 i = tty_unregister_driver(stl_serial);
787 put_tty_driver(stl_serial);
789 printk("STALLION: failed to un-register tty driver, "
791 restore_flags(flags);
794 for (i = 0; i < 4; i++) {
795 devfs_remove("staliomem/%d", i);
796 class_simple_device_remove(MKDEV(STL_SIOMEMMAJOR, i));
798 devfs_remove("staliomem");
799 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
800 printk("STALLION: failed to un-register serial memory device, "
802 class_simple_destroy(stallion_class);
804 if (stl_tmpwritebuf != (char *) NULL)
805 kfree(stl_tmpwritebuf);
807 for (i = 0; (i < stl_nrbrds); i++) {
808 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
810 for (j = 0; (j < STL_MAXPANELS); j++) {
811 panelp = brdp->panels[j];
812 if (panelp == (stlpanel_t *) NULL)
814 for (k = 0; (k < STL_PORTSPERPANEL); k++) {
815 portp = panelp->ports[k];
816 if (portp == (stlport_t *) NULL)
818 if (portp->tty != (struct tty_struct *) NULL)
819 stl_hangup(portp->tty);
820 if (portp->tx.buf != (char *) NULL)
821 kfree(portp->tx.buf);
827 release_region(brdp->ioaddr1, brdp->iosize1);
828 if (brdp->iosize2 > 0)
829 release_region(brdp->ioaddr2, brdp->iosize2);
832 stl_brds[i] = (stlbrd_t *) NULL;
835 for (i = 0; (i < stl_numintrs); i++)
836 free_irq(stl_gotintrs[i], NULL);
838 restore_flags(flags);
841 module_init(stallion_module_init);
842 module_exit(stallion_module_exit);
844 /*****************************************************************************/
847 * Check for any arguments passed in on the module load command line.
850 static void stl_argbrds(void)
857 printk("stl_argbrds()\n");
860 nrargs = sizeof(stl_brdsp) / sizeof(char **);
862 for (i = stl_nrbrds; (i < nrargs); i++) {
863 memset(&conf, 0, sizeof(conf));
864 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
866 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
870 brdp->brdtype = conf.brdtype;
871 brdp->ioaddr1 = conf.ioaddr1;
872 brdp->ioaddr2 = conf.ioaddr2;
873 brdp->irq = conf.irq;
874 brdp->irqtype = conf.irqtype;
879 /*****************************************************************************/
882 * Convert an ascii string number into an unsigned long.
885 static unsigned long stl_atol(char *str)
893 if ((*sp == '0') && (*(sp+1) == 'x')) {
896 } else if (*sp == '0') {
903 for (; (*sp != 0); sp++) {
904 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
905 if ((c < 0) || (c >= base)) {
906 printk("STALLION: invalid argument %s\n", str);
910 val = (val * base) + c;
915 /*****************************************************************************/
918 * Parse the supplied argument string, into the board conf struct.
921 static int stl_parsebrd(stlconf_t *confp, char **argp)
927 printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
930 if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
933 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
936 nrbrdnames = sizeof(stl_brdstr) / sizeof(stlbrdtype_t);
937 for (i = 0; (i < nrbrdnames); i++) {
938 if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
941 if (i >= nrbrdnames) {
942 printk("STALLION: unknown board name, %s?\n", argp[0]);
946 confp->brdtype = stl_brdstr[i].type;
949 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
950 confp->ioaddr1 = stl_atol(argp[i]);
952 if (confp->brdtype == BRD_ECH) {
953 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
954 confp->ioaddr2 = stl_atol(argp[i]);
957 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
958 confp->irq = stl_atol(argp[i]);
964 /*****************************************************************************/
967 * Local driver kernel memory allocation routine.
970 static void *stl_memalloc(int len)
972 return((void *) kmalloc(len, GFP_KERNEL));
975 /*****************************************************************************/
978 * Allocate a new board structure. Fill out the basic info in it.
981 static stlbrd_t *stl_allocbrd(void)
985 brdp = (stlbrd_t *) stl_memalloc(sizeof(stlbrd_t));
986 if (brdp == (stlbrd_t *) NULL) {
987 printk("STALLION: failed to allocate memory (size=%d)\n",
989 return((stlbrd_t *) NULL);
992 memset(brdp, 0, sizeof(stlbrd_t));
993 brdp->magic = STL_BOARDMAGIC;
997 /*****************************************************************************/
999 static int stl_open(struct tty_struct *tty, struct file *filp)
1003 unsigned int minordev;
1004 int brdnr, panelnr, portnr, rc;
1007 printk("stl_open(tty=%x,filp=%x): device=%s\n", (int) tty,
1008 (int) filp, tty->name);
1011 minordev = tty->index;
1012 brdnr = MINOR2BRD(minordev);
1013 if (brdnr >= stl_nrbrds)
1015 brdp = stl_brds[brdnr];
1016 if (brdp == (stlbrd_t *) NULL)
1018 minordev = MINOR2PORT(minordev);
1019 for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
1020 if (brdp->panels[panelnr] == (stlpanel_t *) NULL)
1022 if (minordev < brdp->panels[panelnr]->nrports) {
1026 minordev -= brdp->panels[panelnr]->nrports;
1031 portp = brdp->panels[panelnr]->ports[portnr];
1032 if (portp == (stlport_t *) NULL)
1036 * On the first open of the device setup the port hardware, and
1037 * initialize the per port data structure.
1040 tty->driver_data = portp;
1043 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
1044 if (portp->tx.buf == (char *) NULL) {
1045 portp->tx.buf = (char *) stl_memalloc(STL_TXBUFSIZE);
1046 if (portp->tx.buf == (char *) NULL)
1048 portp->tx.head = portp->tx.buf;
1049 portp->tx.tail = portp->tx.buf;
1051 stl_setport(portp, tty->termios);
1052 portp->sigs = stl_getsignals(portp);
1053 stl_setsignals(portp, 1, 1);
1054 stl_enablerxtx(portp, 1, 1);
1055 stl_startrxtx(portp, 1, 0);
1056 clear_bit(TTY_IO_ERROR, &tty->flags);
1057 portp->flags |= ASYNC_INITIALIZED;
1061 * Check if this port is in the middle of closing. If so then wait
1062 * until it is closed then return error status, based on flag settings.
1063 * The sleep here does not need interrupt protection since the wakeup
1064 * for it is done with the same context.
1066 if (portp->flags & ASYNC_CLOSING) {
1067 interruptible_sleep_on(&portp->close_wait);
1068 if (portp->flags & ASYNC_HUP_NOTIFY)
1070 return(-ERESTARTSYS);
1074 * Based on type of open being done check if it can overlap with any
1075 * previous opens still in effect. If we are a normal serial device
1076 * then also we might have to wait for carrier.
1078 if (!(filp->f_flags & O_NONBLOCK)) {
1079 if ((rc = stl_waitcarrier(portp, filp)) != 0)
1082 portp->flags |= ASYNC_NORMAL_ACTIVE;
1087 /*****************************************************************************/
1090 * Possibly need to wait for carrier (DCD signal) to come high. Say
1091 * maybe because if we are clocal then we don't need to wait...
1094 static int stl_waitcarrier(stlport_t *portp, struct file *filp)
1096 unsigned long flags;
1100 printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp, (int) filp);
1106 if (portp->tty->termios->c_cflag & CLOCAL)
1111 portp->openwaitcnt++;
1112 if (! tty_hung_up_p(filp))
1116 stl_setsignals(portp, 1, 1);
1117 if (tty_hung_up_p(filp) ||
1118 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1119 if (portp->flags & ASYNC_HUP_NOTIFY)
1125 if (((portp->flags & ASYNC_CLOSING) == 0) &&
1126 (doclocal || (portp->sigs & TIOCM_CD))) {
1129 if (signal_pending(current)) {
1133 interruptible_sleep_on(&portp->open_wait);
1136 if (! tty_hung_up_p(filp))
1138 portp->openwaitcnt--;
1139 restore_flags(flags);
1144 /*****************************************************************************/
1146 static void stl_close(struct tty_struct *tty, struct file *filp)
1149 unsigned long flags;
1152 printk("stl_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
1155 portp = tty->driver_data;
1156 if (portp == (stlport_t *) NULL)
1161 if (tty_hung_up_p(filp)) {
1162 restore_flags(flags);
1165 if ((tty->count == 1) && (portp->refcount != 1))
1166 portp->refcount = 1;
1167 if (portp->refcount-- > 1) {
1168 restore_flags(flags);
1172 portp->refcount = 0;
1173 portp->flags |= ASYNC_CLOSING;
1176 * May want to wait for any data to drain before closing. The BUSY
1177 * flag keeps track of whether we are still sending or not - it is
1178 * very accurate for the cd1400, not quite so for the sc26198.
1179 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1182 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1183 tty_wait_until_sent(tty, portp->closing_wait);
1184 stl_waituntilsent(tty, (HZ / 2));
1186 portp->flags &= ~ASYNC_INITIALIZED;
1187 stl_disableintrs(portp);
1188 if (tty->termios->c_cflag & HUPCL)
1189 stl_setsignals(portp, 0, 0);
1190 stl_enablerxtx(portp, 0, 0);
1191 stl_flushbuffer(tty);
1193 if (portp->tx.buf != (char *) NULL) {
1194 kfree(portp->tx.buf);
1195 portp->tx.buf = (char *) NULL;
1196 portp->tx.head = (char *) NULL;
1197 portp->tx.tail = (char *) NULL;
1199 set_bit(TTY_IO_ERROR, &tty->flags);
1200 tty_ldisc_flush(tty);
1203 portp->tty = (struct tty_struct *) NULL;
1205 if (portp->openwaitcnt) {
1206 if (portp->close_delay)
1207 msleep_interruptible(jiffies_to_msecs(portp->close_delay));
1208 wake_up_interruptible(&portp->open_wait);
1211 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1212 wake_up_interruptible(&portp->close_wait);
1213 restore_flags(flags);
1216 /*****************************************************************************/
1219 * Write routine. Take data and stuff it in to the TX ring queue.
1220 * If transmit interrupts are not running then start them.
1223 static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
1226 unsigned int len, stlen;
1227 unsigned char *chbuf;
1231 printk("stl_write(tty=%x,buf=%x,count=%d)\n",
1232 (int) tty, (int) buf, count);
1235 if ((tty == (struct tty_struct *) NULL) ||
1236 (stl_tmpwritebuf == (char *) NULL))
1238 portp = tty->driver_data;
1239 if (portp == (stlport_t *) NULL)
1241 if (portp->tx.buf == (char *) NULL)
1245 * If copying direct from user space we must cater for page faults,
1246 * causing us to "sleep" here for a while. To handle this copy in all
1247 * the data we need now, into a local buffer. Then when we got it all
1248 * copy it into the TX buffer.
1250 chbuf = (unsigned char *) buf;
1252 head = portp->tx.head;
1253 tail = portp->tx.tail;
1255 len = STL_TXBUFSIZE - (head - tail) - 1;
1256 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
1258 len = tail - head - 1;
1262 len = MIN(len, count);
1265 stlen = MIN(len, stlen);
1266 memcpy(head, chbuf, stlen);
1271 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
1272 head = portp->tx.buf;
1273 stlen = tail - head;
1276 portp->tx.head = head;
1278 clear_bit(ASYI_TXLOW, &portp->istate);
1279 stl_startrxtx(portp, -1, 1);
1284 /*****************************************************************************/
1286 static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1293 printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1296 if (tty == (struct tty_struct *) NULL)
1298 portp = tty->driver_data;
1299 if (portp == (stlport_t *) NULL)
1301 if (portp->tx.buf == (char *) NULL)
1304 head = portp->tx.head;
1305 tail = portp->tx.tail;
1307 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
1312 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
1313 head = portp->tx.buf;
1315 portp->tx.head = head;
1318 /*****************************************************************************/
1321 * If there are any characters in the buffer then make sure that TX
1322 * interrupts are on and get'em out. Normally used after the putchar
1323 * routine has been called.
1326 static void stl_flushchars(struct tty_struct *tty)
1331 printk("stl_flushchars(tty=%x)\n", (int) tty);
1334 if (tty == (struct tty_struct *) NULL)
1336 portp = tty->driver_data;
1337 if (portp == (stlport_t *) NULL)
1339 if (portp->tx.buf == (char *) NULL)
1343 if (tty->stopped || tty->hw_stopped ||
1344 (portp->tx.head == portp->tx.tail))
1347 stl_startrxtx(portp, -1, 1);
1350 /*****************************************************************************/
1352 static int stl_writeroom(struct tty_struct *tty)
1358 printk("stl_writeroom(tty=%x)\n", (int) tty);
1361 if (tty == (struct tty_struct *) NULL)
1363 portp = tty->driver_data;
1364 if (portp == (stlport_t *) NULL)
1366 if (portp->tx.buf == (char *) NULL)
1369 head = portp->tx.head;
1370 tail = portp->tx.tail;
1371 return((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
1374 /*****************************************************************************/
1377 * Return number of chars in the TX buffer. Normally we would just
1378 * calculate the number of chars in the buffer and return that, but if
1379 * the buffer is empty and TX interrupts are still on then we return
1380 * that the buffer still has 1 char in it. This way whoever called us
1381 * will not think that ALL chars have drained - since the UART still
1382 * must have some chars in it (we are busy after all).
1385 static int stl_charsinbuffer(struct tty_struct *tty)
1392 printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
1395 if (tty == (struct tty_struct *) NULL)
1397 portp = tty->driver_data;
1398 if (portp == (stlport_t *) NULL)
1400 if (portp->tx.buf == (char *) NULL)
1403 head = portp->tx.head;
1404 tail = portp->tx.tail;
1405 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1406 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1411 /*****************************************************************************/
1414 * Generate the serial struct info.
1417 static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp)
1419 struct serial_struct sio;
1423 printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1426 memset(&sio, 0, sizeof(struct serial_struct));
1427 sio.line = portp->portnr;
1428 sio.port = portp->ioaddr;
1429 sio.flags = portp->flags;
1430 sio.baud_base = portp->baud_base;
1431 sio.close_delay = portp->close_delay;
1432 sio.closing_wait = portp->closing_wait;
1433 sio.custom_divisor = portp->custom_divisor;
1435 if (portp->uartp == &stl_cd1400uart) {
1436 sio.type = PORT_CIRRUS;
1437 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1439 sio.type = PORT_UNKNOWN;
1440 sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1443 brdp = stl_brds[portp->brdnr];
1444 if (brdp != (stlbrd_t *) NULL)
1445 sio.irq = brdp->irq;
1447 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
1450 /*****************************************************************************/
1453 * Set port according to the serial struct info.
1454 * At this point we do not do any auto-configure stuff, so we will
1455 * just quietly ignore any requests to change irq, etc.
1458 static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp)
1460 struct serial_struct sio;
1463 printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1466 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1468 if (!capable(CAP_SYS_ADMIN)) {
1469 if ((sio.baud_base != portp->baud_base) ||
1470 (sio.close_delay != portp->close_delay) ||
1471 ((sio.flags & ~ASYNC_USR_MASK) !=
1472 (portp->flags & ~ASYNC_USR_MASK)))
1476 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1477 (sio.flags & ASYNC_USR_MASK);
1478 portp->baud_base = sio.baud_base;
1479 portp->close_delay = sio.close_delay;
1480 portp->closing_wait = sio.closing_wait;
1481 portp->custom_divisor = sio.custom_divisor;
1482 stl_setport(portp, portp->tty->termios);
1486 /*****************************************************************************/
1488 static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1492 if (tty == (struct tty_struct *) NULL)
1494 portp = tty->driver_data;
1495 if (portp == (stlport_t *) NULL)
1497 if (tty->flags & (1 << TTY_IO_ERROR))
1500 return stl_getsignals(portp);
1503 static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1504 unsigned int set, unsigned int clear)
1507 int rts = -1, dtr = -1;
1509 if (tty == (struct tty_struct *) NULL)
1511 portp = tty->driver_data;
1512 if (portp == (stlport_t *) NULL)
1514 if (tty->flags & (1 << TTY_IO_ERROR))
1517 if (set & TIOCM_RTS)
1519 if (set & TIOCM_DTR)
1521 if (clear & TIOCM_RTS)
1523 if (clear & TIOCM_DTR)
1526 stl_setsignals(portp, dtr, rts);
1530 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1535 void __user *argp = (void __user *)arg;
1538 printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
1539 (int) tty, (int) file, cmd, (int) arg);
1542 if (tty == (struct tty_struct *) NULL)
1544 portp = tty->driver_data;
1545 if (portp == (stlport_t *) NULL)
1548 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1549 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1550 if (tty->flags & (1 << TTY_IO_ERROR))
1558 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1559 (unsigned __user *) argp);
1562 if (get_user(ival, (unsigned int __user *) arg))
1564 tty->termios->c_cflag =
1565 (tty->termios->c_cflag & ~CLOCAL) |
1566 (ival ? CLOCAL : 0);
1569 rc = stl_getserial(portp, argp);
1572 rc = stl_setserial(portp, argp);
1574 case COM_GETPORTSTATS:
1575 rc = stl_getportstats(portp, argp);
1577 case COM_CLRPORTSTATS:
1578 rc = stl_clrportstats(portp, argp);
1584 case TIOCSERGSTRUCT:
1585 case TIOCSERGETMULTI:
1586 case TIOCSERSETMULTI:
1595 /*****************************************************************************/
1597 static void stl_settermios(struct tty_struct *tty, struct termios *old)
1600 struct termios *tiosp;
1603 printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
1606 if (tty == (struct tty_struct *) NULL)
1608 portp = tty->driver_data;
1609 if (portp == (stlport_t *) NULL)
1612 tiosp = tty->termios;
1613 if ((tiosp->c_cflag == old->c_cflag) &&
1614 (tiosp->c_iflag == old->c_iflag))
1617 stl_setport(portp, tiosp);
1618 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1620 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1621 tty->hw_stopped = 0;
1624 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1625 wake_up_interruptible(&portp->open_wait);
1628 /*****************************************************************************/
1631 * Attempt to flow control who ever is sending us data. Based on termios
1632 * settings use software or/and hardware flow control.
1635 static void stl_throttle(struct tty_struct *tty)
1640 printk("stl_throttle(tty=%x)\n", (int) tty);
1643 if (tty == (struct tty_struct *) NULL)
1645 portp = tty->driver_data;
1646 if (portp == (stlport_t *) NULL)
1648 stl_flowctrl(portp, 0);
1651 /*****************************************************************************/
1654 * Unflow control the device sending us data...
1657 static void stl_unthrottle(struct tty_struct *tty)
1662 printk("stl_unthrottle(tty=%x)\n", (int) tty);
1665 if (tty == (struct tty_struct *) NULL)
1667 portp = tty->driver_data;
1668 if (portp == (stlport_t *) NULL)
1670 stl_flowctrl(portp, 1);
1673 /*****************************************************************************/
1676 * Stop the transmitter. Basically to do this we will just turn TX
1680 static void stl_stop(struct tty_struct *tty)
1685 printk("stl_stop(tty=%x)\n", (int) tty);
1688 if (tty == (struct tty_struct *) NULL)
1690 portp = tty->driver_data;
1691 if (portp == (stlport_t *) NULL)
1693 stl_startrxtx(portp, -1, 0);
1696 /*****************************************************************************/
1699 * Start the transmitter again. Just turn TX interrupts back on.
1702 static void stl_start(struct tty_struct *tty)
1707 printk("stl_start(tty=%x)\n", (int) tty);
1710 if (tty == (struct tty_struct *) NULL)
1712 portp = tty->driver_data;
1713 if (portp == (stlport_t *) NULL)
1715 stl_startrxtx(portp, -1, 1);
1718 /*****************************************************************************/
1721 * Hangup this port. This is pretty much like closing the port, only
1722 * a little more brutal. No waiting for data to drain. Shutdown the
1723 * port and maybe drop signals.
1726 static void stl_hangup(struct tty_struct *tty)
1731 printk("stl_hangup(tty=%x)\n", (int) tty);
1734 if (tty == (struct tty_struct *) NULL)
1736 portp = tty->driver_data;
1737 if (portp == (stlport_t *) NULL)
1740 portp->flags &= ~ASYNC_INITIALIZED;
1741 stl_disableintrs(portp);
1742 if (tty->termios->c_cflag & HUPCL)
1743 stl_setsignals(portp, 0, 0);
1744 stl_enablerxtx(portp, 0, 0);
1745 stl_flushbuffer(tty);
1747 set_bit(TTY_IO_ERROR, &tty->flags);
1748 if (portp->tx.buf != (char *) NULL) {
1749 kfree(portp->tx.buf);
1750 portp->tx.buf = (char *) NULL;
1751 portp->tx.head = (char *) NULL;
1752 portp->tx.tail = (char *) NULL;
1754 portp->tty = (struct tty_struct *) NULL;
1755 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1756 portp->refcount = 0;
1757 wake_up_interruptible(&portp->open_wait);
1760 /*****************************************************************************/
1762 static void stl_flushbuffer(struct tty_struct *tty)
1767 printk("stl_flushbuffer(tty=%x)\n", (int) tty);
1770 if (tty == (struct tty_struct *) NULL)
1772 portp = tty->driver_data;
1773 if (portp == (stlport_t *) NULL)
1780 /*****************************************************************************/
1782 static void stl_breakctl(struct tty_struct *tty, int state)
1787 printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty, state);
1790 if (tty == (struct tty_struct *) NULL)
1792 portp = tty->driver_data;
1793 if (portp == (stlport_t *) NULL)
1796 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1799 /*****************************************************************************/
1801 static void stl_waituntilsent(struct tty_struct *tty, int timeout)
1807 printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty, timeout);
1810 if (tty == (struct tty_struct *) NULL)
1812 portp = tty->driver_data;
1813 if (portp == (stlport_t *) NULL)
1818 tend = jiffies + timeout;
1820 while (stl_datastate(portp)) {
1821 if (signal_pending(current))
1823 msleep_interruptible(20);
1824 if (time_after_eq(jiffies, tend))
1829 /*****************************************************************************/
1831 static void stl_sendxchar(struct tty_struct *tty, char ch)
1836 printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
1839 if (tty == (struct tty_struct *) NULL)
1841 portp = tty->driver_data;
1842 if (portp == (stlport_t *) NULL)
1845 if (ch == STOP_CHAR(tty))
1846 stl_sendflow(portp, 0);
1847 else if (ch == START_CHAR(tty))
1848 stl_sendflow(portp, 1);
1850 stl_putchar(tty, ch);
1853 /*****************************************************************************/
1858 * Format info for a specified port. The line is deliberately limited
1859 * to 80 characters. (If it is too long it will be truncated, if too
1860 * short then padded with spaces).
1863 static int stl_portinfo(stlport_t *portp, int portnr, char *pos)
1869 sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
1870 portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
1871 (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
1873 if (portp->stats.rxframing)
1874 sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
1875 if (portp->stats.rxparity)
1876 sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
1877 if (portp->stats.rxbreaks)
1878 sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
1879 if (portp->stats.rxoverrun)
1880 sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
1882 sigs = stl_getsignals(portp);
1883 cnt = sprintf(sp, "%s%s%s%s%s ",
1884 (sigs & TIOCM_RTS) ? "|RTS" : "",
1885 (sigs & TIOCM_CTS) ? "|CTS" : "",
1886 (sigs & TIOCM_DTR) ? "|DTR" : "",
1887 (sigs & TIOCM_CD) ? "|DCD" : "",
1888 (sigs & TIOCM_DSR) ? "|DSR" : "");
1892 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
1895 pos[(MAXLINE - 2)] = '+';
1896 pos[(MAXLINE - 1)] = '\n';
1901 /*****************************************************************************/
1904 * Port info, read from the /proc file system.
1907 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
1912 int brdnr, panelnr, portnr, totalport;
1917 printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
1918 "data=%x\n", (int) page, (int) start, (int) off, count,
1919 (int) eof, (int) data);
1927 pos += sprintf(pos, "%s: version %s", stl_drvtitle,
1929 while (pos < (page + MAXLINE - 1))
1936 * We scan through for each board, panel and port. The offset is
1937 * calculated on the fly, and irrelevant ports are skipped.
1939 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1940 brdp = stl_brds[brdnr];
1941 if (brdp == (stlbrd_t *) NULL)
1943 if (brdp->state == 0)
1946 maxoff = curoff + (brdp->nrports * MAXLINE);
1947 if (off >= maxoff) {
1952 totalport = brdnr * STL_MAXPORTS;
1953 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1954 panelp = brdp->panels[panelnr];
1955 if (panelp == (stlpanel_t *) NULL)
1958 maxoff = curoff + (panelp->nrports * MAXLINE);
1959 if (off >= maxoff) {
1961 totalport += panelp->nrports;
1965 for (portnr = 0; (portnr < panelp->nrports); portnr++,
1967 portp = panelp->ports[portnr];
1968 if (portp == (stlport_t *) NULL)
1970 if (off >= (curoff += MAXLINE))
1972 if ((pos - page + MAXLINE) > count)
1974 pos += stl_portinfo(portp, totalport, pos);
1986 /*****************************************************************************/
1989 * All board interrupts are vectored through here first. This code then
1990 * calls off to the approrpriate board interrupt handlers.
1993 static irqreturn_t stl_intr(int irq, void *dev_id, struct pt_regs *regs)
2000 printk("stl_intr(irq=%d,regs=%x)\n", irq, (int) regs);
2003 for (i = 0; (i < stl_nrbrds); i++) {
2004 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
2006 if (brdp->state == 0)
2009 (* brdp->isr)(brdp);
2011 return IRQ_RETVAL(handled);
2014 /*****************************************************************************/
2017 * Interrupt service routine for EasyIO board types.
2020 static void stl_eiointr(stlbrd_t *brdp)
2023 unsigned int iobase;
2025 panelp = brdp->panels[0];
2026 iobase = panelp->iobase;
2027 while (inb(brdp->iostatus) & EIO_INTRPEND)
2028 (* panelp->isr)(panelp, iobase);
2031 /*****************************************************************************/
2034 * Interrupt service routine for ECH-AT board types.
2037 static void stl_echatintr(stlbrd_t *brdp)
2040 unsigned int ioaddr;
2043 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2045 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2046 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2047 ioaddr = brdp->bnkstataddr[bnknr];
2048 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2049 panelp = brdp->bnk2panel[bnknr];
2050 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2055 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2058 /*****************************************************************************/
2061 * Interrupt service routine for ECH-MCA board types.
2064 static void stl_echmcaintr(stlbrd_t *brdp)
2067 unsigned int ioaddr;
2070 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2071 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2072 ioaddr = brdp->bnkstataddr[bnknr];
2073 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2074 panelp = brdp->bnk2panel[bnknr];
2075 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2081 /*****************************************************************************/
2084 * Interrupt service routine for ECH-PCI board types.
2087 static void stl_echpciintr(stlbrd_t *brdp)
2090 unsigned int ioaddr;
2095 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2096 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
2097 ioaddr = brdp->bnkstataddr[bnknr];
2098 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2099 panelp = brdp->bnk2panel[bnknr];
2100 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2109 /*****************************************************************************/
2112 * Interrupt service routine for ECH-8/64-PCI board types.
2115 static void stl_echpci64intr(stlbrd_t *brdp)
2118 unsigned int ioaddr;
2121 while (inb(brdp->ioctrl) & 0x1) {
2122 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2123 ioaddr = brdp->bnkstataddr[bnknr];
2124 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2125 panelp = brdp->bnk2panel[bnknr];
2126 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2132 /*****************************************************************************/
2135 * Service an off-level request for some channel.
2137 static void stl_offintr(void *private)
2140 struct tty_struct *tty;
2141 unsigned int oldsigs;
2146 printk("stl_offintr(portp=%x)\n", (int) portp);
2149 if (portp == (stlport_t *) NULL)
2153 if (tty == (struct tty_struct *) NULL)
2157 if (test_bit(ASYI_TXLOW, &portp->istate)) {
2160 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
2161 clear_bit(ASYI_DCDCHANGE, &portp->istate);
2162 oldsigs = portp->sigs;
2163 portp->sigs = stl_getsignals(portp);
2164 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
2165 wake_up_interruptible(&portp->open_wait);
2166 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
2167 if (portp->flags & ASYNC_CHECK_CD)
2168 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2174 /*****************************************************************************/
2177 * Map in interrupt vector to this driver. Check that we don't
2178 * already have this vector mapped, we might be sharing this
2179 * interrupt across multiple boards.
2182 static int __init stl_mapirq(int irq, char *name)
2187 printk("stl_mapirq(irq=%d,name=%s)\n", irq, name);
2191 for (i = 0; (i < stl_numintrs); i++) {
2192 if (stl_gotintrs[i] == irq)
2195 if (i >= stl_numintrs) {
2196 if (request_irq(irq, stl_intr, SA_SHIRQ, name, NULL) != 0) {
2197 printk("STALLION: failed to register interrupt "
2198 "routine for %s irq=%d\n", name, irq);
2201 stl_gotintrs[stl_numintrs++] = irq;
2207 /*****************************************************************************/
2210 * Initialize all the ports on a panel.
2213 static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2219 printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
2222 chipmask = stl_panelinit(brdp, panelp);
2225 * All UART's are initialized (if found!). Now go through and setup
2226 * each ports data structures.
2228 for (i = 0; (i < panelp->nrports); i++) {
2229 portp = (stlport_t *) stl_memalloc(sizeof(stlport_t));
2230 if (portp == (stlport_t *) NULL) {
2231 printk("STALLION: failed to allocate memory "
2232 "(size=%d)\n", sizeof(stlport_t));
2235 memset(portp, 0, sizeof(stlport_t));
2237 portp->magic = STL_PORTMAGIC;
2239 portp->brdnr = panelp->brdnr;
2240 portp->panelnr = panelp->panelnr;
2241 portp->uartp = panelp->uartp;
2242 portp->clk = brdp->clk;
2243 portp->baud_base = STL_BAUDBASE;
2244 portp->close_delay = STL_CLOSEDELAY;
2245 portp->closing_wait = 30 * HZ;
2246 INIT_WORK(&portp->tqueue, stl_offintr, portp);
2247 init_waitqueue_head(&portp->open_wait);
2248 init_waitqueue_head(&portp->close_wait);
2249 portp->stats.brd = portp->brdnr;
2250 portp->stats.panel = portp->panelnr;
2251 portp->stats.port = portp->portnr;
2252 panelp->ports[i] = portp;
2253 stl_portinit(brdp, panelp, portp);
2259 /*****************************************************************************/
2262 * Try to find and initialize an EasyIO board.
2265 static inline int stl_initeio(stlbrd_t *brdp)
2268 unsigned int status;
2273 printk("stl_initeio(brdp=%x)\n", (int) brdp);
2276 brdp->ioctrl = brdp->ioaddr1 + 1;
2277 brdp->iostatus = brdp->ioaddr1 + 2;
2279 status = inb(brdp->iostatus);
2280 if ((status & EIO_IDBITMASK) == EIO_MK3)
2284 * Handle board specific stuff now. The real difference is PCI
2287 if (brdp->brdtype == BRD_EASYIOPCI) {
2288 brdp->iosize1 = 0x80;
2289 brdp->iosize2 = 0x80;
2290 name = "serial(EIO-PCI)";
2291 outb(0x41, (brdp->ioaddr2 + 0x4c));
2294 name = "serial(EIO)";
2295 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2296 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2297 printk("STALLION: invalid irq=%d for brd=%d\n",
2298 brdp->irq, brdp->brdnr);
2301 outb((stl_vecmap[brdp->irq] | EIO_0WS |
2302 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
2306 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2307 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2308 "%x conflicts with another device\n", brdp->brdnr,
2313 if (brdp->iosize2 > 0)
2314 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2315 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2316 "address %x conflicts with another device\n",
2317 brdp->brdnr, brdp->ioaddr2);
2318 printk(KERN_WARNING "STALLION: Warning, also "
2319 "releasing board %d I/O address %x \n",
2320 brdp->brdnr, brdp->ioaddr1);
2321 release_region(brdp->ioaddr1, brdp->iosize1);
2326 * Everything looks OK, so let's go ahead and probe for the hardware.
2328 brdp->clk = CD1400_CLK;
2329 brdp->isr = stl_eiointr;
2331 switch (status & EIO_IDBITMASK) {
2333 brdp->clk = CD1400_CLK8M;
2343 switch (status & EIO_BRDMASK) {
2362 * We have verified that the board is actually present, so now we
2363 * can complete the setup.
2366 panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
2367 if (panelp == (stlpanel_t *) NULL) {
2368 printk(KERN_WARNING "STALLION: failed to allocate memory "
2369 "(size=%d)\n", sizeof(stlpanel_t));
2372 memset(panelp, 0, sizeof(stlpanel_t));
2374 panelp->magic = STL_PANELMAGIC;
2375 panelp->brdnr = brdp->brdnr;
2376 panelp->panelnr = 0;
2377 panelp->nrports = brdp->nrports;
2378 panelp->iobase = brdp->ioaddr1;
2379 panelp->hwid = status;
2380 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2381 panelp->uartp = (void *) &stl_sc26198uart;
2382 panelp->isr = stl_sc26198intr;
2384 panelp->uartp = (void *) &stl_cd1400uart;
2385 panelp->isr = stl_cd1400eiointr;
2388 brdp->panels[0] = panelp;
2390 brdp->state |= BRD_FOUND;
2391 brdp->hwid = status;
2392 rc = stl_mapirq(brdp->irq, name);
2396 /*****************************************************************************/
2399 * Try to find an ECH board and initialize it. This code is capable of
2400 * dealing with all types of ECH board.
2403 static inline int stl_initech(stlbrd_t *brdp)
2406 unsigned int status, nxtid, ioaddr, conflict;
2407 int panelnr, banknr, i;
2411 printk("stl_initech(brdp=%x)\n", (int) brdp);
2418 * Set up the initial board register contents for boards. This varies a
2419 * bit between the different board types. So we need to handle each
2420 * separately. Also do a check that the supplied IRQ is good.
2422 switch (brdp->brdtype) {
2425 brdp->isr = stl_echatintr;
2426 brdp->ioctrl = brdp->ioaddr1 + 1;
2427 brdp->iostatus = brdp->ioaddr1 + 1;
2428 status = inb(brdp->iostatus);
2429 if ((status & ECH_IDBITMASK) != ECH_ID)
2431 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2432 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2433 printk("STALLION: invalid irq=%d for brd=%d\n",
2434 brdp->irq, brdp->brdnr);
2437 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2438 status |= (stl_vecmap[brdp->irq] << 1);
2439 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2440 brdp->ioctrlval = ECH_INTENABLE |
2441 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2442 for (i = 0; (i < 10); i++)
2443 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2446 name = "serial(EC8/32)";
2447 outb(status, brdp->ioaddr1);
2451 brdp->isr = stl_echmcaintr;
2452 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2453 brdp->iostatus = brdp->ioctrl;
2454 status = inb(brdp->iostatus);
2455 if ((status & ECH_IDBITMASK) != ECH_ID)
2457 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2458 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2459 printk("STALLION: invalid irq=%d for brd=%d\n",
2460 brdp->irq, brdp->brdnr);
2463 outb(ECHMC_BRDRESET, brdp->ioctrl);
2464 outb(ECHMC_INTENABLE, brdp->ioctrl);
2466 name = "serial(EC8/32-MC)";
2470 brdp->isr = stl_echpciintr;
2471 brdp->ioctrl = brdp->ioaddr1 + 2;
2474 name = "serial(EC8/32-PCI)";
2478 brdp->isr = stl_echpci64intr;
2479 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2480 outb(0x43, (brdp->ioaddr1 + 0x4c));
2481 brdp->iosize1 = 0x80;
2482 brdp->iosize2 = 0x80;
2483 name = "serial(EC8/64-PCI)";
2487 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
2493 * Check boards for possible IO address conflicts and return fail status
2494 * if an IO conflict found.
2496 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2497 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2498 "%x conflicts with another device\n", brdp->brdnr,
2503 if (brdp->iosize2 > 0)
2504 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2505 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2506 "address %x conflicts with another device\n",
2507 brdp->brdnr, brdp->ioaddr2);
2508 printk(KERN_WARNING "STALLION: Warning, also "
2509 "releasing board %d I/O address %x \n",
2510 brdp->brdnr, brdp->ioaddr1);
2511 release_region(brdp->ioaddr1, brdp->iosize1);
2516 * Scan through the secondary io address space looking for panels.
2517 * As we find'em allocate and initialize panel structures for each.
2519 brdp->clk = CD1400_CLK;
2520 brdp->hwid = status;
2522 ioaddr = brdp->ioaddr2;
2527 for (i = 0; (i < STL_MAXPANELS); i++) {
2528 if (brdp->brdtype == BRD_ECHPCI) {
2529 outb(nxtid, brdp->ioctrl);
2530 ioaddr = brdp->ioaddr2;
2532 status = inb(ioaddr + ECH_PNLSTATUS);
2533 if ((status & ECH_PNLIDMASK) != nxtid)
2535 panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
2536 if (panelp == (stlpanel_t *) NULL) {
2537 printk("STALLION: failed to allocate memory "
2538 "(size=%d)\n", sizeof(stlpanel_t));
2541 memset(panelp, 0, sizeof(stlpanel_t));
2542 panelp->magic = STL_PANELMAGIC;
2543 panelp->brdnr = brdp->brdnr;
2544 panelp->panelnr = panelnr;
2545 panelp->iobase = ioaddr;
2546 panelp->pagenr = nxtid;
2547 panelp->hwid = status;
2548 brdp->bnk2panel[banknr] = panelp;
2549 brdp->bnkpageaddr[banknr] = nxtid;
2550 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2552 if (status & ECH_PNLXPID) {
2553 panelp->uartp = (void *) &stl_sc26198uart;
2554 panelp->isr = stl_sc26198intr;
2555 if (status & ECH_PNL16PORT) {
2556 panelp->nrports = 16;
2557 brdp->bnk2panel[banknr] = panelp;
2558 brdp->bnkpageaddr[banknr] = nxtid;
2559 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2562 panelp->nrports = 8;
2565 panelp->uartp = (void *) &stl_cd1400uart;
2566 panelp->isr = stl_cd1400echintr;
2567 if (status & ECH_PNL16PORT) {
2568 panelp->nrports = 16;
2569 panelp->ackmask = 0x80;
2570 if (brdp->brdtype != BRD_ECHPCI)
2571 ioaddr += EREG_BANKSIZE;
2572 brdp->bnk2panel[banknr] = panelp;
2573 brdp->bnkpageaddr[banknr] = ++nxtid;
2574 brdp->bnkstataddr[banknr++] = ioaddr +
2577 panelp->nrports = 8;
2578 panelp->ackmask = 0xc0;
2583 ioaddr += EREG_BANKSIZE;
2584 brdp->nrports += panelp->nrports;
2585 brdp->panels[panelnr++] = panelp;
2586 if ((brdp->brdtype != BRD_ECHPCI) &&
2587 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
2591 brdp->nrpanels = panelnr;
2592 brdp->nrbnks = banknr;
2593 if (brdp->brdtype == BRD_ECH)
2594 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2596 brdp->state |= BRD_FOUND;
2597 i = stl_mapirq(brdp->irq, name);
2601 /*****************************************************************************/
2604 * Initialize and configure the specified board.
2605 * Scan through all the boards in the configuration and see what we
2606 * can find. Handle EIO and the ECH boards a little differently here
2607 * since the initial search and setup is very different.
2610 static int __init stl_brdinit(stlbrd_t *brdp)
2615 printk("stl_brdinit(brdp=%x)\n", (int) brdp);
2618 switch (brdp->brdtype) {
2630 printk("STALLION: board=%d is unknown board type=%d\n",
2631 brdp->brdnr, brdp->brdtype);
2635 stl_brds[brdp->brdnr] = brdp;
2636 if ((brdp->state & BRD_FOUND) == 0) {
2637 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2638 stl_brdnames[brdp->brdtype], brdp->brdnr,
2639 brdp->ioaddr1, brdp->irq);
2643 for (i = 0; (i < STL_MAXPANELS); i++)
2644 if (brdp->panels[i] != (stlpanel_t *) NULL)
2645 stl_initports(brdp, brdp->panels[i]);
2647 printk("STALLION: %s found, board=%d io=%x irq=%d "
2648 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2649 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2654 /*****************************************************************************/
2657 * Find the next available board number that is free.
2660 static inline int stl_getbrdnr(void)
2664 for (i = 0; (i < STL_MAXBRDS); i++) {
2665 if (stl_brds[i] == (stlbrd_t *) NULL) {
2666 if (i >= stl_nrbrds)
2674 /*****************************************************************************/
2679 * We have a Stallion board. Allocate a board structure and
2680 * initialize it. Read its IO and IRQ resources from PCI
2681 * configuration space.
2684 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
2689 printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
2690 devp->bus->number, devp->devfn);
2693 if (pci_enable_device(devp))
2695 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2697 if ((brdp->brdnr = stl_getbrdnr()) < 0) {
2698 printk("STALLION: too many boards found, "
2699 "maximum supported %d\n", STL_MAXBRDS);
2702 brdp->brdtype = brdtype;
2705 * Different Stallion boards use the BAR registers in different ways,
2706 * so set up io addresses based on board type.
2709 printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__, __LINE__,
2710 pci_resource_start(devp, 0), pci_resource_start(devp, 1),
2711 pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
2715 * We have all resources from the board, so let's setup the actual
2716 * board structure now.
2720 brdp->ioaddr2 = pci_resource_start(devp, 0);
2721 brdp->ioaddr1 = pci_resource_start(devp, 1);
2724 brdp->ioaddr2 = pci_resource_start(devp, 2);
2725 brdp->ioaddr1 = pci_resource_start(devp, 1);
2728 brdp->ioaddr1 = pci_resource_start(devp, 2);
2729 brdp->ioaddr2 = pci_resource_start(devp, 1);
2732 printk("STALLION: unknown PCI board type=%d\n", brdtype);
2736 brdp->irq = devp->irq;
2742 /*****************************************************************************/
2745 * Find all Stallion PCI boards that might be installed. Initialize each
2746 * one as it is found.
2750 static inline int stl_findpcibrds(void)
2752 struct pci_dev *dev = NULL;
2756 printk("stl_findpcibrds()\n");
2759 for (i = 0; (i < stl_nrpcibrds); i++)
2760 while ((dev = pci_find_device(stl_pcibrds[i].vendid,
2761 stl_pcibrds[i].devid, dev))) {
2764 * Found a device on the PCI bus that has our vendor and
2765 * device ID. Need to check now that it is really us.
2767 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2770 rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
2780 /*****************************************************************************/
2783 * Scan through all the boards in the configuration and see what we
2784 * can find. Handle EIO and the ECH boards a little differently here
2785 * since the initial search and setup is too different.
2788 static inline int stl_initbrds(void)
2795 printk("stl_initbrds()\n");
2798 if (stl_nrbrds > STL_MAXBRDS) {
2799 printk("STALLION: too many boards in configuration table, "
2800 "truncating to %d\n", STL_MAXBRDS);
2801 stl_nrbrds = STL_MAXBRDS;
2805 * Firstly scan the list of static boards configured. Allocate
2806 * resources and initialize the boards as found.
2808 for (i = 0; (i < stl_nrbrds); i++) {
2809 confp = &stl_brdconf[i];
2811 stl_parsebrd(confp, stl_brdsp[i]);
2813 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2816 brdp->brdtype = confp->brdtype;
2817 brdp->ioaddr1 = confp->ioaddr1;
2818 brdp->ioaddr2 = confp->ioaddr2;
2819 brdp->irq = confp->irq;
2820 brdp->irqtype = confp->irqtype;
2825 * Find any dynamically supported boards. That is via module load
2826 * line options or auto-detected on the PCI bus.
2838 /*****************************************************************************/
2841 * Return the board stats structure to user app.
2844 static int stl_getbrdstats(combrd_t __user *bp)
2850 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2852 if (stl_brdstats.brd >= STL_MAXBRDS)
2854 brdp = stl_brds[stl_brdstats.brd];
2855 if (brdp == (stlbrd_t *) NULL)
2858 memset(&stl_brdstats, 0, sizeof(combrd_t));
2859 stl_brdstats.brd = brdp->brdnr;
2860 stl_brdstats.type = brdp->brdtype;
2861 stl_brdstats.hwid = brdp->hwid;
2862 stl_brdstats.state = brdp->state;
2863 stl_brdstats.ioaddr = brdp->ioaddr1;
2864 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2865 stl_brdstats.irq = brdp->irq;
2866 stl_brdstats.nrpanels = brdp->nrpanels;
2867 stl_brdstats.nrports = brdp->nrports;
2868 for (i = 0; (i < brdp->nrpanels); i++) {
2869 panelp = brdp->panels[i];
2870 stl_brdstats.panels[i].panel = i;
2871 stl_brdstats.panels[i].hwid = panelp->hwid;
2872 stl_brdstats.panels[i].nrports = panelp->nrports;
2875 return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
2878 /*****************************************************************************/
2881 * Resolve the referenced port number into a port struct pointer.
2884 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2889 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2890 return((stlport_t *) NULL);
2891 brdp = stl_brds[brdnr];
2892 if (brdp == (stlbrd_t *) NULL)
2893 return((stlport_t *) NULL);
2894 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2895 return((stlport_t *) NULL);
2896 panelp = brdp->panels[panelnr];
2897 if (panelp == (stlpanel_t *) NULL)
2898 return((stlport_t *) NULL);
2899 if ((portnr < 0) || (portnr >= panelp->nrports))
2900 return((stlport_t *) NULL);
2901 return(panelp->ports[portnr]);
2904 /*****************************************************************************/
2907 * Return the port stats structure to user app. A NULL port struct
2908 * pointer passed in means that we need to find out from the app
2909 * what port to get stats for (used through board control device).
2912 static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
2914 unsigned char *head, *tail;
2915 unsigned long flags;
2918 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2920 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2922 if (portp == (stlport_t *) NULL)
2926 portp->stats.state = portp->istate;
2927 portp->stats.flags = portp->flags;
2928 portp->stats.hwid = portp->hwid;
2930 portp->stats.ttystate = 0;
2931 portp->stats.cflags = 0;
2932 portp->stats.iflags = 0;
2933 portp->stats.oflags = 0;
2934 portp->stats.lflags = 0;
2935 portp->stats.rxbuffered = 0;
2939 if (portp->tty != (struct tty_struct *) NULL) {
2940 if (portp->tty->driver_data == portp) {
2941 portp->stats.ttystate = portp->tty->flags;
2942 portp->stats.rxbuffered = portp->tty->flip.count;
2943 if (portp->tty->termios != (struct termios *) NULL) {
2944 portp->stats.cflags = portp->tty->termios->c_cflag;
2945 portp->stats.iflags = portp->tty->termios->c_iflag;
2946 portp->stats.oflags = portp->tty->termios->c_oflag;
2947 portp->stats.lflags = portp->tty->termios->c_lflag;
2951 restore_flags(flags);
2953 head = portp->tx.head;
2954 tail = portp->tx.tail;
2955 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2956 (STL_TXBUFSIZE - (tail - head)));
2958 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2960 return copy_to_user(cp, &portp->stats,
2961 sizeof(comstats_t)) ? -EFAULT : 0;
2964 /*****************************************************************************/
2967 * Clear the port stats structure. We also return it zeroed out...
2970 static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp)
2973 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2975 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2977 if (portp == (stlport_t *) NULL)
2981 memset(&portp->stats, 0, sizeof(comstats_t));
2982 portp->stats.brd = portp->brdnr;
2983 portp->stats.panel = portp->panelnr;
2984 portp->stats.port = portp->portnr;
2985 return copy_to_user(cp, &portp->stats,
2986 sizeof(comstats_t)) ? -EFAULT : 0;
2989 /*****************************************************************************/
2992 * Return the entire driver ports structure to a user app.
2995 static int stl_getportstruct(stlport_t __user *arg)
2999 if (copy_from_user(&stl_dummyport, arg, sizeof(stlport_t)))
3001 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
3002 stl_dummyport.portnr);
3005 return copy_to_user(arg, portp, sizeof(stlport_t)) ? -EFAULT : 0;
3008 /*****************************************************************************/
3011 * Return the entire driver board structure to a user app.
3014 static int stl_getbrdstruct(stlbrd_t __user *arg)
3018 if (copy_from_user(&stl_dummybrd, arg, sizeof(stlbrd_t)))
3020 if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
3022 brdp = stl_brds[stl_dummybrd.brdnr];
3025 return copy_to_user(arg, brdp, sizeof(stlbrd_t)) ? -EFAULT : 0;
3028 /*****************************************************************************/
3031 * The "staliomem" device is also required to do some special operations
3032 * on the board and/or ports. In this driver it is mostly used for stats
3036 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
3039 void __user *argp = (void __user *)arg;
3042 printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
3043 (int) fp, cmd, (int) arg);
3047 if (brdnr >= STL_MAXBRDS)
3052 case COM_GETPORTSTATS:
3053 rc = stl_getportstats(NULL, argp);
3055 case COM_CLRPORTSTATS:
3056 rc = stl_clrportstats(NULL, argp);
3058 case COM_GETBRDSTATS:
3059 rc = stl_getbrdstats(argp);
3062 rc = stl_getportstruct(argp);
3065 rc = stl_getbrdstruct(argp);
3075 static struct tty_operations stl_ops = {
3079 .put_char = stl_putchar,
3080 .flush_chars = stl_flushchars,
3081 .write_room = stl_writeroom,
3082 .chars_in_buffer = stl_charsinbuffer,
3084 .set_termios = stl_settermios,
3085 .throttle = stl_throttle,
3086 .unthrottle = stl_unthrottle,
3089 .hangup = stl_hangup,
3090 .flush_buffer = stl_flushbuffer,
3091 .break_ctl = stl_breakctl,
3092 .wait_until_sent = stl_waituntilsent,
3093 .send_xchar = stl_sendxchar,
3094 .read_proc = stl_readproc,
3095 .tiocmget = stl_tiocmget,
3096 .tiocmset = stl_tiocmset,
3099 /*****************************************************************************/
3101 int __init stl_init(void)
3104 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
3108 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
3113 * Allocate a temporary write buffer.
3115 stl_tmpwritebuf = (char *) stl_memalloc(STL_TXBUFSIZE);
3116 if (stl_tmpwritebuf == (char *) NULL)
3117 printk("STALLION: failed to allocate memory (size=%d)\n",
3121 * Set up a character driver for per board stuff. This is mainly used
3122 * to do stats ioctls on the ports.
3124 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
3125 printk("STALLION: failed to register serial board device\n");
3126 devfs_mk_dir("staliomem");
3128 stallion_class = class_simple_create(THIS_MODULE, "staliomem");
3129 for (i = 0; i < 4; i++) {
3130 devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR, i),
3131 S_IFCHR|S_IRUSR|S_IWUSR,
3133 class_simple_device_add(stallion_class, MKDEV(STL_SIOMEMMAJOR, i), NULL, "staliomem%d", i);
3136 stl_serial->owner = THIS_MODULE;
3137 stl_serial->driver_name = stl_drvname;
3138 stl_serial->name = "ttyE";
3139 stl_serial->devfs_name = "tts/E";
3140 stl_serial->major = STL_SERIALMAJOR;
3141 stl_serial->minor_start = 0;
3142 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
3143 stl_serial->subtype = SERIAL_TYPE_NORMAL;
3144 stl_serial->init_termios = stl_deftermios;
3145 stl_serial->flags = TTY_DRIVER_REAL_RAW;
3146 tty_set_operations(stl_serial, &stl_ops);
3148 if (tty_register_driver(stl_serial)) {
3149 put_tty_driver(stl_serial);
3150 printk("STALLION: failed to register serial driver\n");
3157 /*****************************************************************************/
3158 /* CD1400 HARDWARE FUNCTIONS */
3159 /*****************************************************************************/
3162 * These functions get/set/update the registers of the cd1400 UARTs.
3163 * Access to the cd1400 registers is via an address/data io port pair.
3164 * (Maybe should make this inline...)
3167 static int stl_cd1400getreg(stlport_t *portp, int regnr)
3169 outb((regnr + portp->uartaddr), portp->ioaddr);
3170 return(inb(portp->ioaddr + EREG_DATA));
3173 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
3175 outb((regnr + portp->uartaddr), portp->ioaddr);
3176 outb(value, portp->ioaddr + EREG_DATA);
3179 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
3181 outb((regnr + portp->uartaddr), portp->ioaddr);
3182 if (inb(portp->ioaddr + EREG_DATA) != value) {
3183 outb(value, portp->ioaddr + EREG_DATA);
3189 /*****************************************************************************/
3192 * Inbitialize the UARTs in a panel. We don't care what sort of board
3193 * these ports are on - since the port io registers are almost
3194 * identical when dealing with ports.
3197 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3201 int nrchips, uartaddr, ioaddr;
3204 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
3207 BRDENABLE(panelp->brdnr, panelp->pagenr);
3210 * Check that each chip is present and started up OK.
3213 nrchips = panelp->nrports / CD1400_PORTS;
3214 for (i = 0; (i < nrchips); i++) {
3215 if (brdp->brdtype == BRD_ECHPCI) {
3216 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3217 ioaddr = panelp->iobase;
3219 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3221 uartaddr = (i & 0x01) ? 0x080 : 0;
3222 outb((GFRCR + uartaddr), ioaddr);
3223 outb(0, (ioaddr + EREG_DATA));
3224 outb((CCR + uartaddr), ioaddr);
3225 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3226 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3227 outb((GFRCR + uartaddr), ioaddr);
3228 for (j = 0; (j < CCR_MAXWAIT); j++) {
3229 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3232 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3233 printk("STALLION: cd1400 not responding, "
3234 "brd=%d panel=%d chip=%d\n",
3235 panelp->brdnr, panelp->panelnr, i);
3238 chipmask |= (0x1 << i);
3239 outb((PPR + uartaddr), ioaddr);
3240 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
3243 BRDDISABLE(panelp->brdnr);
3247 /*****************************************************************************/
3250 * Initialize hardware specific port registers.
3253 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3256 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3257 (int) brdp, (int) panelp, (int) portp);
3260 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
3261 (portp == (stlport_t *) NULL))
3264 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3265 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3266 portp->uartaddr = (portp->portnr & 0x04) << 5;
3267 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3269 BRDENABLE(portp->brdnr, portp->pagenr);
3270 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3271 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3272 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3273 BRDDISABLE(portp->brdnr);
3276 /*****************************************************************************/
3279 * Wait for the command register to be ready. We will poll this,
3280 * since it won't usually take too long to be ready.
3283 static void stl_cd1400ccrwait(stlport_t *portp)
3287 for (i = 0; (i < CCR_MAXWAIT); i++) {
3288 if (stl_cd1400getreg(portp, CCR) == 0) {
3293 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
3294 portp->portnr, portp->panelnr, portp->brdnr);
3297 /*****************************************************************************/
3300 * Set up the cd1400 registers for a port based on the termios port
3304 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3307 unsigned long flags;
3308 unsigned int clkdiv, baudrate;
3309 unsigned char cor1, cor2, cor3;
3310 unsigned char cor4, cor5, ccr;
3311 unsigned char srer, sreron, sreroff;
3312 unsigned char mcor1, mcor2, rtpr;
3313 unsigned char clk, div;
3329 brdp = stl_brds[portp->brdnr];
3330 if (brdp == (stlbrd_t *) NULL)
3334 * Set up the RX char ignore mask with those RX error types we
3335 * can ignore. We can get the cd1400 to help us out a little here,
3336 * it will ignore parity errors and breaks for us.
3338 portp->rxignoremsk = 0;
3339 if (tiosp->c_iflag & IGNPAR) {
3340 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
3341 cor1 |= COR1_PARIGNORE;
3343 if (tiosp->c_iflag & IGNBRK) {
3344 portp->rxignoremsk |= ST_BREAK;
3345 cor4 |= COR4_IGNBRK;
3348 portp->rxmarkmsk = ST_OVERRUN;
3349 if (tiosp->c_iflag & (INPCK | PARMRK))
3350 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3351 if (tiosp->c_iflag & BRKINT)
3352 portp->rxmarkmsk |= ST_BREAK;
3355 * Go through the char size, parity and stop bits and set all the
3356 * option register appropriately.
3358 switch (tiosp->c_cflag & CSIZE) {
3373 if (tiosp->c_cflag & CSTOPB)
3378 if (tiosp->c_cflag & PARENB) {
3379 if (tiosp->c_cflag & PARODD)
3380 cor1 |= (COR1_PARENB | COR1_PARODD);
3382 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3384 cor1 |= COR1_PARNONE;
3388 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3389 * space for hardware flow control and the like. This should be set to
3390 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3391 * really be based on VTIME.
3393 cor3 |= FIFO_RXTHRESHOLD;
3397 * Calculate the baud rate timers. For now we will just assume that
3398 * the input and output baud are the same. Could have used a baud
3399 * table here, but this way we can generate virtually any baud rate
3402 baudrate = tiosp->c_cflag & CBAUD;
3403 if (baudrate & CBAUDEX) {
3404 baudrate &= ~CBAUDEX;
3405 if ((baudrate < 1) || (baudrate > 4))
3406 tiosp->c_cflag &= ~CBAUDEX;
3410 baudrate = stl_baudrates[baudrate];
3411 if ((tiosp->c_cflag & CBAUD) == B38400) {
3412 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3414 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3416 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3418 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3420 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3421 baudrate = (portp->baud_base / portp->custom_divisor);
3423 if (baudrate > STL_CD1400MAXBAUD)
3424 baudrate = STL_CD1400MAXBAUD;
3427 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3428 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
3432 div = (unsigned char) clkdiv;
3436 * Check what form of modem signaling is required and set it up.
3438 if ((tiosp->c_cflag & CLOCAL) == 0) {
3441 sreron |= SRER_MODEM;
3442 portp->flags |= ASYNC_CHECK_CD;
3444 portp->flags &= ~ASYNC_CHECK_CD;
3448 * Setup cd1400 enhanced modes if we can. In particular we want to
3449 * handle as much of the flow control as possible automatically. As
3450 * well as saving a few CPU cycles it will also greatly improve flow
3451 * control reliability.
3453 if (tiosp->c_iflag & IXON) {
3456 if (tiosp->c_iflag & IXANY)
3460 if (tiosp->c_cflag & CRTSCTS) {
3462 mcor1 |= FIFO_RTSTHRESHOLD;
3466 * All cd1400 register values calculated so go through and set
3471 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3472 portp->portnr, portp->panelnr, portp->brdnr);
3473 printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3474 cor1, cor2, cor3, cor4, cor5);
3475 printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3476 mcor1, mcor2, rtpr, sreron, sreroff);
3477 printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3478 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3479 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3480 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3485 BRDENABLE(portp->brdnr, portp->pagenr);
3486 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3487 srer = stl_cd1400getreg(portp, SRER);
3488 stl_cd1400setreg(portp, SRER, 0);
3489 if (stl_cd1400updatereg(portp, COR1, cor1))
3491 if (stl_cd1400updatereg(portp, COR2, cor2))
3493 if (stl_cd1400updatereg(portp, COR3, cor3))
3496 stl_cd1400ccrwait(portp);
3497 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3499 stl_cd1400setreg(portp, COR4, cor4);
3500 stl_cd1400setreg(portp, COR5, cor5);
3501 stl_cd1400setreg(portp, MCOR1, mcor1);
3502 stl_cd1400setreg(portp, MCOR2, mcor2);
3504 stl_cd1400setreg(portp, TCOR, clk);
3505 stl_cd1400setreg(portp, TBPR, div);
3506 stl_cd1400setreg(portp, RCOR, clk);
3507 stl_cd1400setreg(portp, RBPR, div);
3509 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3510 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3511 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3512 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3513 stl_cd1400setreg(portp, RTPR, rtpr);
3514 mcor1 = stl_cd1400getreg(portp, MSVR1);
3515 if (mcor1 & MSVR1_DCD)
3516 portp->sigs |= TIOCM_CD;
3518 portp->sigs &= ~TIOCM_CD;
3519 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3520 BRDDISABLE(portp->brdnr);
3521 restore_flags(flags);
3524 /*****************************************************************************/
3527 * Set the state of the DTR and RTS signals.
3530 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3532 unsigned char msvr1, msvr2;
3533 unsigned long flags;
3536 printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
3537 (int) portp, dtr, rts);
3549 BRDENABLE(portp->brdnr, portp->pagenr);
3550 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3552 stl_cd1400setreg(portp, MSVR2, msvr2);
3554 stl_cd1400setreg(portp, MSVR1, msvr1);
3555 BRDDISABLE(portp->brdnr);
3556 restore_flags(flags);
3559 /*****************************************************************************/
3562 * Return the state of the signals.
3565 static int stl_cd1400getsignals(stlport_t *portp)
3567 unsigned char msvr1, msvr2;
3568 unsigned long flags;
3572 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3577 BRDENABLE(portp->brdnr, portp->pagenr);
3578 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3579 msvr1 = stl_cd1400getreg(portp, MSVR1);
3580 msvr2 = stl_cd1400getreg(portp, MSVR2);
3581 BRDDISABLE(portp->brdnr);
3582 restore_flags(flags);
3585 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3586 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3587 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3588 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3590 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3591 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3598 /*****************************************************************************/
3601 * Enable/Disable the Transmitter and/or Receiver.
3604 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3607 unsigned long flags;
3610 printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3611 (int) portp, rx, tx);
3616 ccr |= CCR_TXDISABLE;
3618 ccr |= CCR_TXENABLE;
3620 ccr |= CCR_RXDISABLE;
3622 ccr |= CCR_RXENABLE;
3626 BRDENABLE(portp->brdnr, portp->pagenr);
3627 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3628 stl_cd1400ccrwait(portp);
3629 stl_cd1400setreg(portp, CCR, ccr);
3630 stl_cd1400ccrwait(portp);
3631 BRDDISABLE(portp->brdnr);
3632 restore_flags(flags);
3635 /*****************************************************************************/
3638 * Start/stop the Transmitter and/or Receiver.
3641 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3643 unsigned char sreron, sreroff;
3644 unsigned long flags;
3647 printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3648 (int) portp, rx, tx);
3654 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3656 sreron |= SRER_TXDATA;
3658 sreron |= SRER_TXEMPTY;
3660 sreroff |= SRER_RXDATA;
3662 sreron |= SRER_RXDATA;
3666 BRDENABLE(portp->brdnr, portp->pagenr);
3667 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3668 stl_cd1400setreg(portp, SRER,
3669 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3670 BRDDISABLE(portp->brdnr);
3672 set_bit(ASYI_TXBUSY, &portp->istate);
3673 restore_flags(flags);
3676 /*****************************************************************************/
3679 * Disable all interrupts from this port.
3682 static void stl_cd1400disableintrs(stlport_t *portp)
3684 unsigned long flags;
3687 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3691 BRDENABLE(portp->brdnr, portp->pagenr);
3692 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3693 stl_cd1400setreg(portp, SRER, 0);
3694 BRDDISABLE(portp->brdnr);
3695 restore_flags(flags);
3698 /*****************************************************************************/
3700 static void stl_cd1400sendbreak(stlport_t *portp, int len)
3702 unsigned long flags;
3705 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
3710 BRDENABLE(portp->brdnr, portp->pagenr);
3711 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3712 stl_cd1400setreg(portp, SRER,
3713 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3715 BRDDISABLE(portp->brdnr);
3716 portp->brklen = len;
3718 portp->stats.txbreaks++;
3719 restore_flags(flags);
3722 /*****************************************************************************/
3725 * Take flow control actions...
3728 static void stl_cd1400flowctrl(stlport_t *portp, int state)
3730 struct tty_struct *tty;
3731 unsigned long flags;
3734 printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp, state);
3737 if (portp == (stlport_t *) NULL)
3740 if (tty == (struct tty_struct *) NULL)
3745 BRDENABLE(portp->brdnr, portp->pagenr);
3746 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3749 if (tty->termios->c_iflag & IXOFF) {
3750 stl_cd1400ccrwait(portp);
3751 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3752 portp->stats.rxxon++;
3753 stl_cd1400ccrwait(portp);
3756 * Question: should we return RTS to what it was before? It may
3757 * have been set by an ioctl... Suppose not, since if you have
3758 * hardware flow control set then it is pretty silly to go and
3759 * set the RTS line by hand.
3761 if (tty->termios->c_cflag & CRTSCTS) {
3762 stl_cd1400setreg(portp, MCOR1,
3763 (stl_cd1400getreg(portp, MCOR1) |
3764 FIFO_RTSTHRESHOLD));
3765 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3766 portp->stats.rxrtson++;
3769 if (tty->termios->c_iflag & IXOFF) {
3770 stl_cd1400ccrwait(portp);
3771 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3772 portp->stats.rxxoff++;
3773 stl_cd1400ccrwait(portp);
3775 if (tty->termios->c_cflag & CRTSCTS) {
3776 stl_cd1400setreg(portp, MCOR1,
3777 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3778 stl_cd1400setreg(portp, MSVR2, 0);
3779 portp->stats.rxrtsoff++;
3783 BRDDISABLE(portp->brdnr);
3784 restore_flags(flags);
3787 /*****************************************************************************/
3790 * Send a flow control character...
3793 static void stl_cd1400sendflow(stlport_t *portp, int state)
3795 struct tty_struct *tty;
3796 unsigned long flags;
3799 printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp, state);
3802 if (portp == (stlport_t *) NULL)
3805 if (tty == (struct tty_struct *) NULL)
3810 BRDENABLE(portp->brdnr, portp->pagenr);
3811 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3813 stl_cd1400ccrwait(portp);
3814 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3815 portp->stats.rxxon++;
3816 stl_cd1400ccrwait(portp);
3818 stl_cd1400ccrwait(portp);
3819 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3820 portp->stats.rxxoff++;
3821 stl_cd1400ccrwait(portp);
3823 BRDDISABLE(portp->brdnr);
3824 restore_flags(flags);
3827 /*****************************************************************************/
3829 static void stl_cd1400flush(stlport_t *portp)
3831 unsigned long flags;
3834 printk("stl_cd1400flush(portp=%x)\n", (int) portp);
3837 if (portp == (stlport_t *) NULL)
3842 BRDENABLE(portp->brdnr, portp->pagenr);
3843 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3844 stl_cd1400ccrwait(portp);
3845 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3846 stl_cd1400ccrwait(portp);
3847 portp->tx.tail = portp->tx.head;
3848 BRDDISABLE(portp->brdnr);
3849 restore_flags(flags);
3852 /*****************************************************************************/
3855 * Return the current state of data flow on this port. This is only
3856 * really interresting when determining if data has fully completed
3857 * transmission or not... This is easy for the cd1400, it accurately
3858 * maintains the busy port flag.
3861 static int stl_cd1400datastate(stlport_t *portp)
3864 printk("stl_cd1400datastate(portp=%x)\n", (int) portp);
3867 if (portp == (stlport_t *) NULL)
3870 return(test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0);
3873 /*****************************************************************************/
3876 * Interrupt service routine for cd1400 EasyIO boards.
3879 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3881 unsigned char svrtype;
3884 printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
3885 (int) panelp, iobase);
3889 svrtype = inb(iobase + EREG_DATA);
3890 if (panelp->nrports > 4) {
3891 outb((SVRR + 0x80), iobase);
3892 svrtype |= inb(iobase + EREG_DATA);
3895 if (svrtype & SVRR_RX)
3896 stl_cd1400rxisr(panelp, iobase);
3897 else if (svrtype & SVRR_TX)
3898 stl_cd1400txisr(panelp, iobase);
3899 else if (svrtype & SVRR_MDM)
3900 stl_cd1400mdmisr(panelp, iobase);
3903 /*****************************************************************************/
3906 * Interrupt service routine for cd1400 panels.
3909 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
3911 unsigned char svrtype;
3914 printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
3919 svrtype = inb(iobase + EREG_DATA);
3920 outb((SVRR + 0x80), iobase);
3921 svrtype |= inb(iobase + EREG_DATA);
3922 if (svrtype & SVRR_RX)
3923 stl_cd1400rxisr(panelp, iobase);
3924 else if (svrtype & SVRR_TX)
3925 stl_cd1400txisr(panelp, iobase);
3926 else if (svrtype & SVRR_MDM)
3927 stl_cd1400mdmisr(panelp, iobase);
3931 /*****************************************************************************/
3934 * Unfortunately we need to handle breaks in the TX data stream, since
3935 * this is the only way to generate them on the cd1400.
3938 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr)
3940 if (portp->brklen == 1) {
3941 outb((COR2 + portp->uartaddr), ioaddr);
3942 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
3943 (ioaddr + EREG_DATA));
3944 outb((TDR + portp->uartaddr), ioaddr);
3945 outb(ETC_CMD, (ioaddr + EREG_DATA));
3946 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
3947 outb((SRER + portp->uartaddr), ioaddr);
3948 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
3949 (ioaddr + EREG_DATA));
3951 } else if (portp->brklen > 1) {
3952 outb((TDR + portp->uartaddr), ioaddr);
3953 outb(ETC_CMD, (ioaddr + EREG_DATA));
3954 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
3958 outb((COR2 + portp->uartaddr), ioaddr);
3959 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
3960 (ioaddr + EREG_DATA));
3966 /*****************************************************************************/
3969 * Transmit interrupt handler. This has gotta be fast! Handling TX
3970 * chars is pretty simple, stuff as many as possible from the TX buffer
3971 * into the cd1400 FIFO. Must also handle TX breaks here, since they
3972 * are embedded as commands in the data stream. Oh no, had to use a goto!
3973 * This could be optimized more, will do when I get time...
3974 * In practice it is possible that interrupts are enabled but that the
3975 * port has been hung up. Need to handle not having any TX buffer here,
3976 * this is done by using the side effect that head and tail will also
3977 * be NULL if the buffer has been freed.
3980 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
3985 unsigned char ioack, srer;
3988 printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
3991 ioack = inb(ioaddr + EREG_TXACK);
3992 if (((ioack & panelp->ackmask) != 0) ||
3993 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
3994 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
3997 portp = panelp->ports[(ioack >> 3)];
4000 * Unfortunately we need to handle breaks in the data stream, since
4001 * this is the only way to generate them on the cd1400. Do it now if
4002 * a break is to be sent.
4004 if (portp->brklen != 0)
4005 if (stl_cd1400breakisr(portp, ioaddr))
4008 head = portp->tx.head;
4009 tail = portp->tx.tail;
4010 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4011 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4012 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4013 set_bit(ASYI_TXLOW, &portp->istate);
4014 schedule_work(&portp->tqueue);
4018 outb((SRER + portp->uartaddr), ioaddr);
4019 srer = inb(ioaddr + EREG_DATA);
4020 if (srer & SRER_TXDATA) {
4021 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
4023 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
4024 clear_bit(ASYI_TXBUSY, &portp->istate);
4026 outb(srer, (ioaddr + EREG_DATA));
4028 len = MIN(len, CD1400_TXFIFOSIZE);
4029 portp->stats.txtotal += len;
4030 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4031 outb((TDR + portp->uartaddr), ioaddr);
4032 outsb((ioaddr + EREG_DATA), tail, stlen);
4035 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4036 tail = portp->tx.buf;
4038 outsb((ioaddr + EREG_DATA), tail, len);
4041 portp->tx.tail = tail;
4045 outb((EOSRR + portp->uartaddr), ioaddr);
4046 outb(0, (ioaddr + EREG_DATA));
4049 /*****************************************************************************/
4052 * Receive character interrupt handler. Determine if we have good chars
4053 * or bad chars and then process appropriately. Good chars are easy
4054 * just shove the lot into the RX buffer and set all status byte to 0.
4055 * If a bad RX char then process as required. This routine needs to be
4056 * fast! In practice it is possible that we get an interrupt on a port
4057 * that is closed. This can happen on hangups - since they completely
4058 * shutdown a port not in user context. Need to handle this case.
4061 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
4064 struct tty_struct *tty;
4065 unsigned int ioack, len, buflen;
4066 unsigned char status;
4070 printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
4073 ioack = inb(ioaddr + EREG_RXACK);
4074 if ((ioack & panelp->ackmask) != 0) {
4075 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4078 portp = panelp->ports[(ioack >> 3)];
4081 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
4082 outb((RDCR + portp->uartaddr), ioaddr);
4083 len = inb(ioaddr + EREG_DATA);
4084 if ((tty == (struct tty_struct *) NULL) ||
4085 (tty->flip.char_buf_ptr == (char *) NULL) ||
4086 ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
4087 len = MIN(len, sizeof(stl_unwanted));
4088 outb((RDSR + portp->uartaddr), ioaddr);
4089 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
4090 portp->stats.rxlost += len;
4091 portp->stats.rxtotal += len;
4093 len = MIN(len, buflen);
4095 outb((RDSR + portp->uartaddr), ioaddr);
4096 insb((ioaddr + EREG_DATA), tty->flip.char_buf_ptr, len);
4097 memset(tty->flip.flag_buf_ptr, 0, len);
4098 tty->flip.flag_buf_ptr += len;
4099 tty->flip.char_buf_ptr += len;
4100 tty->flip.count += len;
4101 tty_schedule_flip(tty);
4102 portp->stats.rxtotal += len;
4105 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
4106 outb((RDSR + portp->uartaddr), ioaddr);
4107 status = inb(ioaddr + EREG_DATA);
4108 ch = inb(ioaddr + EREG_DATA);
4109 if (status & ST_PARITY)
4110 portp->stats.rxparity++;
4111 if (status & ST_FRAMING)
4112 portp->stats.rxframing++;
4113 if (status & ST_OVERRUN)
4114 portp->stats.rxoverrun++;
4115 if (status & ST_BREAK)
4116 portp->stats.rxbreaks++;
4117 if (status & ST_SCHARMASK) {
4118 if ((status & ST_SCHARMASK) == ST_SCHAR1)
4119 portp->stats.txxon++;
4120 if ((status & ST_SCHARMASK) == ST_SCHAR2)
4121 portp->stats.txxoff++;
4124 if ((tty != (struct tty_struct *) NULL) &&
4125 ((portp->rxignoremsk & status) == 0)) {
4126 if (portp->rxmarkmsk & status) {
4127 if (status & ST_BREAK) {
4129 if (portp->flags & ASYNC_SAK) {
4131 BRDENABLE(portp->brdnr, portp->pagenr);
4133 } else if (status & ST_PARITY) {
4134 status = TTY_PARITY;
4135 } else if (status & ST_FRAMING) {
4137 } else if(status & ST_OVERRUN) {
4138 status = TTY_OVERRUN;
4145 if (tty->flip.char_buf_ptr != (char *) NULL) {
4146 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
4147 *tty->flip.flag_buf_ptr++ = status;
4148 *tty->flip.char_buf_ptr++ = ch;
4151 tty_schedule_flip(tty);
4155 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4160 outb((EOSRR + portp->uartaddr), ioaddr);
4161 outb(0, (ioaddr + EREG_DATA));
4164 /*****************************************************************************/
4167 * Modem interrupt handler. The is called when the modem signal line
4168 * (DCD) has changed state. Leave most of the work to the off-level
4169 * processing routine.
4172 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
4179 printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp);
4182 ioack = inb(ioaddr + EREG_MDACK);
4183 if (((ioack & panelp->ackmask) != 0) ||
4184 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
4185 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
4188 portp = panelp->ports[(ioack >> 3)];
4190 outb((MISR + portp->uartaddr), ioaddr);
4191 misr = inb(ioaddr + EREG_DATA);
4192 if (misr & MISR_DCD) {
4193 set_bit(ASYI_DCDCHANGE, &portp->istate);
4194 schedule_work(&portp->tqueue);
4195 portp->stats.modem++;
4198 outb((EOSRR + portp->uartaddr), ioaddr);
4199 outb(0, (ioaddr + EREG_DATA));
4202 /*****************************************************************************/
4203 /* SC26198 HARDWARE FUNCTIONS */
4204 /*****************************************************************************/
4207 * These functions get/set/update the registers of the sc26198 UARTs.
4208 * Access to the sc26198 registers is via an address/data io port pair.
4209 * (Maybe should make this inline...)
4212 static int stl_sc26198getreg(stlport_t *portp, int regnr)
4214 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4215 return(inb(portp->ioaddr + XP_DATA));
4218 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
4220 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4221 outb(value, (portp->ioaddr + XP_DATA));
4224 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
4226 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4227 if (inb(portp->ioaddr + XP_DATA) != value) {
4228 outb(value, (portp->ioaddr + XP_DATA));
4234 /*****************************************************************************/
4237 * Functions to get and set the sc26198 global registers.
4240 static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
4242 outb(regnr, (portp->ioaddr + XP_ADDR));
4243 return(inb(portp->ioaddr + XP_DATA));
4247 static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
4249 outb(regnr, (portp->ioaddr + XP_ADDR));
4250 outb(value, (portp->ioaddr + XP_DATA));
4254 /*****************************************************************************/
4257 * Inbitialize the UARTs in a panel. We don't care what sort of board
4258 * these ports are on - since the port io registers are almost
4259 * identical when dealing with ports.
4262 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
4265 int nrchips, ioaddr;
4268 printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
4269 (int) brdp, (int) panelp);
4272 BRDENABLE(panelp->brdnr, panelp->pagenr);
4275 * Check that each chip is present and started up OK.
4278 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
4279 if (brdp->brdtype == BRD_ECHPCI)
4280 outb(panelp->pagenr, brdp->ioctrl);
4282 for (i = 0; (i < nrchips); i++) {
4283 ioaddr = panelp->iobase + (i * 4);
4284 outb(SCCR, (ioaddr + XP_ADDR));
4285 outb(CR_RESETALL, (ioaddr + XP_DATA));
4286 outb(TSTR, (ioaddr + XP_ADDR));
4287 if (inb(ioaddr + XP_DATA) != 0) {
4288 printk("STALLION: sc26198 not responding, "
4289 "brd=%d panel=%d chip=%d\n",
4290 panelp->brdnr, panelp->panelnr, i);
4293 chipmask |= (0x1 << i);
4294 outb(GCCR, (ioaddr + XP_ADDR));
4295 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
4296 outb(WDTRCR, (ioaddr + XP_ADDR));
4297 outb(0xff, (ioaddr + XP_DATA));
4300 BRDDISABLE(panelp->brdnr);
4304 /*****************************************************************************/
4307 * Initialize hardware specific port registers.
4310 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
4313 printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
4314 (int) brdp, (int) panelp, (int) portp);
4317 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
4318 (portp == (stlport_t *) NULL))
4321 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
4322 portp->uartaddr = (portp->portnr & 0x07) << 4;
4323 portp->pagenr = panelp->pagenr;
4326 BRDENABLE(portp->brdnr, portp->pagenr);
4327 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
4328 BRDDISABLE(portp->brdnr);
4331 /*****************************************************************************/
4334 * Set up the sc26198 registers for a port based on the termios port
4338 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4341 unsigned long flags;
4342 unsigned int baudrate;
4343 unsigned char mr0, mr1, mr2, clk;
4344 unsigned char imron, imroff, iopr, ipr;
4354 brdp = stl_brds[portp->brdnr];
4355 if (brdp == (stlbrd_t *) NULL)
4359 * Set up the RX char ignore mask with those RX error types we
4362 portp->rxignoremsk = 0;
4363 if (tiosp->c_iflag & IGNPAR)
4364 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
4366 if (tiosp->c_iflag & IGNBRK)
4367 portp->rxignoremsk |= SR_RXBREAK;
4369 portp->rxmarkmsk = SR_RXOVERRUN;
4370 if (tiosp->c_iflag & (INPCK | PARMRK))
4371 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
4372 if (tiosp->c_iflag & BRKINT)
4373 portp->rxmarkmsk |= SR_RXBREAK;
4376 * Go through the char size, parity and stop bits and set all the
4377 * option register appropriately.
4379 switch (tiosp->c_cflag & CSIZE) {
4394 if (tiosp->c_cflag & CSTOPB)
4399 if (tiosp->c_cflag & PARENB) {
4400 if (tiosp->c_cflag & PARODD)
4401 mr1 |= (MR1_PARENB | MR1_PARODD);
4403 mr1 |= (MR1_PARENB | MR1_PAREVEN);
4408 mr1 |= MR1_ERRBLOCK;
4411 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4412 * space for hardware flow control and the like. This should be set to
4415 mr2 |= MR2_RXFIFOHALF;
4418 * Calculate the baud rate timers. For now we will just assume that
4419 * the input and output baud are the same. The sc26198 has a fixed
4420 * baud rate table, so only discrete baud rates possible.
4422 baudrate = tiosp->c_cflag & CBAUD;
4423 if (baudrate & CBAUDEX) {
4424 baudrate &= ~CBAUDEX;
4425 if ((baudrate < 1) || (baudrate > 4))
4426 tiosp->c_cflag &= ~CBAUDEX;
4430 baudrate = stl_baudrates[baudrate];
4431 if ((tiosp->c_cflag & CBAUD) == B38400) {
4432 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
4434 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
4436 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
4438 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
4440 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
4441 baudrate = (portp->baud_base / portp->custom_divisor);
4443 if (baudrate > STL_SC26198MAXBAUD)
4444 baudrate = STL_SC26198MAXBAUD;
4447 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
4448 if (baudrate <= sc26198_baudtable[clk])
4454 * Check what form of modem signaling is required and set it up.
4456 if (tiosp->c_cflag & CLOCAL) {
4457 portp->flags &= ~ASYNC_CHECK_CD;
4459 iopr |= IOPR_DCDCOS;
4461 portp->flags |= ASYNC_CHECK_CD;
4465 * Setup sc26198 enhanced modes if we can. In particular we want to
4466 * handle as much of the flow control as possible automatically. As
4467 * well as saving a few CPU cycles it will also greatly improve flow
4468 * control reliability.
4470 if (tiosp->c_iflag & IXON) {
4471 mr0 |= MR0_SWFTX | MR0_SWFT;
4472 imron |= IR_XONXOFF;
4474 imroff |= IR_XONXOFF;
4476 if (tiosp->c_iflag & IXOFF)
4479 if (tiosp->c_cflag & CRTSCTS) {
4485 * All sc26198 register values calculated so go through and set
4490 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4491 portp->portnr, portp->panelnr, portp->brdnr);
4492 printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4493 printk(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4494 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4495 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4496 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4501 BRDENABLE(portp->brdnr, portp->pagenr);
4502 stl_sc26198setreg(portp, IMR, 0);
4503 stl_sc26198updatereg(portp, MR0, mr0);
4504 stl_sc26198updatereg(portp, MR1, mr1);
4505 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4506 stl_sc26198updatereg(portp, MR2, mr2);
4507 stl_sc26198updatereg(portp, IOPIOR,
4508 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
4511 stl_sc26198setreg(portp, TXCSR, clk);
4512 stl_sc26198setreg(portp, RXCSR, clk);
4515 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4516 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4518 ipr = stl_sc26198getreg(portp, IPR);
4520 portp->sigs &= ~TIOCM_CD;
4522 portp->sigs |= TIOCM_CD;
4524 portp->imr = (portp->imr & ~imroff) | imron;
4525 stl_sc26198setreg(portp, IMR, portp->imr);
4526 BRDDISABLE(portp->brdnr);
4527 restore_flags(flags);
4530 /*****************************************************************************/
4533 * Set the state of the DTR and RTS signals.
4536 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
4538 unsigned char iopioron, iopioroff;
4539 unsigned long flags;
4542 printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4543 (int) portp, dtr, rts);
4549 iopioroff |= IPR_DTR;
4551 iopioron |= IPR_DTR;
4553 iopioroff |= IPR_RTS;
4555 iopioron |= IPR_RTS;
4559 BRDENABLE(portp->brdnr, portp->pagenr);
4560 stl_sc26198setreg(portp, IOPIOR,
4561 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4562 BRDDISABLE(portp->brdnr);
4563 restore_flags(flags);
4566 /*****************************************************************************/
4569 * Return the state of the signals.
4572 static int stl_sc26198getsignals(stlport_t *portp)
4575 unsigned long flags;
4579 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
4584 BRDENABLE(portp->brdnr, portp->pagenr);
4585 ipr = stl_sc26198getreg(portp, IPR);
4586 BRDDISABLE(portp->brdnr);
4587 restore_flags(flags);
4590 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4591 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4592 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4593 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4598 /*****************************************************************************/
4601 * Enable/Disable the Transmitter and/or Receiver.
4604 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
4607 unsigned long flags;
4610 printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4611 (int) portp, rx, tx);
4614 ccr = portp->crenable;
4616 ccr &= ~CR_TXENABLE;
4620 ccr &= ~CR_RXENABLE;
4626 BRDENABLE(portp->brdnr, portp->pagenr);
4627 stl_sc26198setreg(portp, SCCR, ccr);
4628 BRDDISABLE(portp->brdnr);
4629 portp->crenable = ccr;
4630 restore_flags(flags);
4633 /*****************************************************************************/
4636 * Start/stop the Transmitter and/or Receiver.
4639 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
4642 unsigned long flags;
4645 printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4646 (int) portp, rx, tx);
4655 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4657 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4661 BRDENABLE(portp->brdnr, portp->pagenr);
4662 stl_sc26198setreg(portp, IMR, imr);
4663 BRDDISABLE(portp->brdnr);
4666 set_bit(ASYI_TXBUSY, &portp->istate);
4667 restore_flags(flags);
4670 /*****************************************************************************/
4673 * Disable all interrupts from this port.
4676 static void stl_sc26198disableintrs(stlport_t *portp)
4678 unsigned long flags;
4681 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
4686 BRDENABLE(portp->brdnr, portp->pagenr);
4688 stl_sc26198setreg(portp, IMR, 0);
4689 BRDDISABLE(portp->brdnr);
4690 restore_flags(flags);
4693 /*****************************************************************************/
4695 static void stl_sc26198sendbreak(stlport_t *portp, int len)
4697 unsigned long flags;
4700 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
4705 BRDENABLE(portp->brdnr, portp->pagenr);
4707 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4708 portp->stats.txbreaks++;
4710 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4712 BRDDISABLE(portp->brdnr);
4713 restore_flags(flags);
4716 /*****************************************************************************/
4719 * Take flow control actions...
4722 static void stl_sc26198flowctrl(stlport_t *portp, int state)
4724 struct tty_struct *tty;
4725 unsigned long flags;
4729 printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp, state);
4732 if (portp == (stlport_t *) NULL)
4735 if (tty == (struct tty_struct *) NULL)
4740 BRDENABLE(portp->brdnr, portp->pagenr);
4743 if (tty->termios->c_iflag & IXOFF) {
4744 mr0 = stl_sc26198getreg(portp, MR0);
4745 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4746 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4748 portp->stats.rxxon++;
4749 stl_sc26198wait(portp);
4750 stl_sc26198setreg(portp, MR0, mr0);
4753 * Question: should we return RTS to what it was before? It may
4754 * have been set by an ioctl... Suppose not, since if you have
4755 * hardware flow control set then it is pretty silly to go and
4756 * set the RTS line by hand.
4758 if (tty->termios->c_cflag & CRTSCTS) {
4759 stl_sc26198setreg(portp, MR1,
4760 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4761 stl_sc26198setreg(portp, IOPIOR,
4762 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4763 portp->stats.rxrtson++;
4766 if (tty->termios->c_iflag & IXOFF) {
4767 mr0 = stl_sc26198getreg(portp, MR0);
4768 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4769 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4771 portp->stats.rxxoff++;
4772 stl_sc26198wait(portp);
4773 stl_sc26198setreg(portp, MR0, mr0);
4775 if (tty->termios->c_cflag & CRTSCTS) {
4776 stl_sc26198setreg(portp, MR1,
4777 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4778 stl_sc26198setreg(portp, IOPIOR,
4779 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4780 portp->stats.rxrtsoff++;
4784 BRDDISABLE(portp->brdnr);
4785 restore_flags(flags);
4788 /*****************************************************************************/
4791 * Send a flow control character.
4794 static void stl_sc26198sendflow(stlport_t *portp, int state)
4796 struct tty_struct *tty;
4797 unsigned long flags;
4801 printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp, state);
4804 if (portp == (stlport_t *) NULL)
4807 if (tty == (struct tty_struct *) NULL)
4812 BRDENABLE(portp->brdnr, portp->pagenr);
4814 mr0 = stl_sc26198getreg(portp, MR0);
4815 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4816 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4818 portp->stats.rxxon++;
4819 stl_sc26198wait(portp);
4820 stl_sc26198setreg(portp, MR0, mr0);
4822 mr0 = stl_sc26198getreg(portp, MR0);
4823 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4824 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4826 portp->stats.rxxoff++;
4827 stl_sc26198wait(portp);
4828 stl_sc26198setreg(portp, MR0, mr0);
4830 BRDDISABLE(portp->brdnr);
4831 restore_flags(flags);
4834 /*****************************************************************************/
4836 static void stl_sc26198flush(stlport_t *portp)
4838 unsigned long flags;
4841 printk("stl_sc26198flush(portp=%x)\n", (int) portp);
4844 if (portp == (stlport_t *) NULL)
4849 BRDENABLE(portp->brdnr, portp->pagenr);
4850 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4851 stl_sc26198setreg(portp, SCCR, portp->crenable);
4852 BRDDISABLE(portp->brdnr);
4853 portp->tx.tail = portp->tx.head;
4854 restore_flags(flags);
4857 /*****************************************************************************/
4860 * Return the current state of data flow on this port. This is only
4861 * really interresting when determining if data has fully completed
4862 * transmission or not... The sc26198 interrupt scheme cannot
4863 * determine when all data has actually drained, so we need to
4864 * check the port statusy register to be sure.
4867 static int stl_sc26198datastate(stlport_t *portp)
4869 unsigned long flags;
4873 printk("stl_sc26198datastate(portp=%x)\n", (int) portp);
4876 if (portp == (stlport_t *) NULL)
4878 if (test_bit(ASYI_TXBUSY, &portp->istate))
4883 BRDENABLE(portp->brdnr, portp->pagenr);
4884 sr = stl_sc26198getreg(portp, SR);
4885 BRDDISABLE(portp->brdnr);
4886 restore_flags(flags);
4888 return((sr & SR_TXEMPTY) ? 0 : 1);
4891 /*****************************************************************************/
4894 * Delay for a small amount of time, to give the sc26198 a chance
4895 * to process a command...
4898 static void stl_sc26198wait(stlport_t *portp)
4903 printk("stl_sc26198wait(portp=%x)\n", (int) portp);
4906 if (portp == (stlport_t *) NULL)
4909 for (i = 0; (i < 20); i++)
4910 stl_sc26198getglobreg(portp, TSTR);
4913 /*****************************************************************************/
4916 * If we are TX flow controlled and in IXANY mode then we may
4917 * need to unflow control here. We gotta do this because of the
4918 * automatic flow control modes of the sc26198.
4921 static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty)
4925 mr0 = stl_sc26198getreg(portp, MR0);
4926 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4927 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4928 stl_sc26198wait(portp);
4929 stl_sc26198setreg(portp, MR0, mr0);
4930 clear_bit(ASYI_TXFLOWED, &portp->istate);
4933 /*****************************************************************************/
4936 * Interrupt service routine for sc26198 panels.
4939 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4945 * Work around bug in sc26198 chip... Cannot have A6 address
4946 * line of UART high, else iack will be returned as 0.
4948 outb(0, (iobase + 1));
4950 iack = inb(iobase + XP_IACK);
4951 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4953 if (iack & IVR_RXDATA)
4954 stl_sc26198rxisr(portp, iack);
4955 else if (iack & IVR_TXDATA)
4956 stl_sc26198txisr(portp);
4958 stl_sc26198otherisr(portp, iack);
4961 /*****************************************************************************/
4964 * Transmit interrupt handler. This has gotta be fast! Handling TX
4965 * chars is pretty simple, stuff as many as possible from the TX buffer
4966 * into the sc26198 FIFO.
4967 * In practice it is possible that interrupts are enabled but that the
4968 * port has been hung up. Need to handle not having any TX buffer here,
4969 * this is done by using the side effect that head and tail will also
4970 * be NULL if the buffer has been freed.
4973 static void stl_sc26198txisr(stlport_t *portp)
4975 unsigned int ioaddr;
4981 printk("stl_sc26198txisr(portp=%x)\n", (int) portp);
4984 ioaddr = portp->ioaddr;
4985 head = portp->tx.head;
4986 tail = portp->tx.tail;
4987 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4988 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4989 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4990 set_bit(ASYI_TXLOW, &portp->istate);
4991 schedule_work(&portp->tqueue);
4995 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
4996 mr0 = inb(ioaddr + XP_DATA);
4997 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4998 portp->imr &= ~IR_TXRDY;
4999 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
5000 outb(portp->imr, (ioaddr + XP_DATA));
5001 clear_bit(ASYI_TXBUSY, &portp->istate);
5003 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
5004 outb(mr0, (ioaddr + XP_DATA));
5007 len = MIN(len, SC26198_TXFIFOSIZE);
5008 portp->stats.txtotal += len;
5009 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
5010 outb(GTXFIFO, (ioaddr + XP_ADDR));
5011 outsb((ioaddr + XP_DATA), tail, stlen);
5014 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
5015 tail = portp->tx.buf;
5017 outsb((ioaddr + XP_DATA), tail, len);
5020 portp->tx.tail = tail;
5024 /*****************************************************************************/
5027 * Receive character interrupt handler. Determine if we have good chars
5028 * or bad chars and then process appropriately. Good chars are easy
5029 * just shove the lot into the RX buffer and set all status byte to 0.
5030 * If a bad RX char then process as required. This routine needs to be
5031 * fast! In practice it is possible that we get an interrupt on a port
5032 * that is closed. This can happen on hangups - since they completely
5033 * shutdown a port not in user context. Need to handle this case.
5036 static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
5038 struct tty_struct *tty;
5039 unsigned int len, buflen, ioaddr;
5042 printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
5046 ioaddr = portp->ioaddr;
5047 outb(GIBCR, (ioaddr + XP_ADDR));
5048 len = inb(ioaddr + XP_DATA) + 1;
5050 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
5051 if ((tty == (struct tty_struct *) NULL) ||
5052 (tty->flip.char_buf_ptr == (char *) NULL) ||
5053 ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
5054 len = MIN(len, sizeof(stl_unwanted));
5055 outb(GRXFIFO, (ioaddr + XP_ADDR));
5056 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
5057 portp->stats.rxlost += len;
5058 portp->stats.rxtotal += len;
5060 len = MIN(len, buflen);
5062 outb(GRXFIFO, (ioaddr + XP_ADDR));
5063 insb((ioaddr + XP_DATA), tty->flip.char_buf_ptr, len);
5064 memset(tty->flip.flag_buf_ptr, 0, len);
5065 tty->flip.flag_buf_ptr += len;
5066 tty->flip.char_buf_ptr += len;
5067 tty->flip.count += len;
5068 tty_schedule_flip(tty);
5069 portp->stats.rxtotal += len;
5073 stl_sc26198rxbadchars(portp);
5077 * If we are TX flow controlled and in IXANY mode then we may need
5078 * to unflow control here. We gotta do this because of the automatic
5079 * flow control modes of the sc26198.
5081 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
5082 if ((tty != (struct tty_struct *) NULL) &&
5083 (tty->termios != (struct termios *) NULL) &&
5084 (tty->termios->c_iflag & IXANY)) {
5085 stl_sc26198txunflow(portp, tty);
5090 /*****************************************************************************/
5093 * Process an RX bad character.
5096 static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch)
5098 struct tty_struct *tty;
5099 unsigned int ioaddr;
5102 ioaddr = portp->ioaddr;
5104 if (status & SR_RXPARITY)
5105 portp->stats.rxparity++;
5106 if (status & SR_RXFRAMING)
5107 portp->stats.rxframing++;
5108 if (status & SR_RXOVERRUN)
5109 portp->stats.rxoverrun++;
5110 if (status & SR_RXBREAK)
5111 portp->stats.rxbreaks++;
5113 if ((tty != (struct tty_struct *) NULL) &&
5114 ((portp->rxignoremsk & status) == 0)) {
5115 if (portp->rxmarkmsk & status) {
5116 if (status & SR_RXBREAK) {
5118 if (portp->flags & ASYNC_SAK) {
5120 BRDENABLE(portp->brdnr, portp->pagenr);
5122 } else if (status & SR_RXPARITY) {
5123 status = TTY_PARITY;
5124 } else if (status & SR_RXFRAMING) {
5126 } else if(status & SR_RXOVERRUN) {
5127 status = TTY_OVERRUN;
5135 if (tty->flip.char_buf_ptr != (char *) NULL) {
5136 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
5137 *tty->flip.flag_buf_ptr++ = status;
5138 *tty->flip.char_buf_ptr++ = ch;
5141 tty_schedule_flip(tty);
5145 portp->stats.rxtotal++;
5149 /*****************************************************************************/
5152 * Process all characters in the RX FIFO of the UART. Check all char
5153 * status bytes as well, and process as required. We need to check
5154 * all bytes in the FIFO, in case some more enter the FIFO while we
5155 * are here. To get the exact character error type we need to switch
5156 * into CHAR error mode (that is why we need to make sure we empty
5160 static void stl_sc26198rxbadchars(stlport_t *portp)
5162 unsigned char status, mr1;
5166 * To get the precise error type for each character we must switch
5167 * back into CHAR error mode.
5169 mr1 = stl_sc26198getreg(portp, MR1);
5170 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
5172 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
5173 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
5174 ch = stl_sc26198getreg(portp, RXFIFO);
5175 stl_sc26198rxbadch(portp, status, ch);
5179 * To get correct interrupt class we must switch back into BLOCK
5182 stl_sc26198setreg(portp, MR1, mr1);
5185 /*****************************************************************************/
5188 * Other interrupt handler. This includes modem signals, flow
5189 * control actions, etc. Most stuff is left to off-level interrupt
5193 static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
5195 unsigned char cir, ipr, xisr;
5198 printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
5201 cir = stl_sc26198getglobreg(portp, CIR);
5203 switch (cir & CIR_SUBTYPEMASK) {
5205 ipr = stl_sc26198getreg(portp, IPR);
5206 if (ipr & IPR_DCDCHANGE) {
5207 set_bit(ASYI_DCDCHANGE, &portp->istate);
5208 schedule_work(&portp->tqueue);
5209 portp->stats.modem++;
5212 case CIR_SUBXONXOFF:
5213 xisr = stl_sc26198getreg(portp, XISR);
5214 if (xisr & XISR_RXXONGOT) {
5215 set_bit(ASYI_TXFLOWED, &portp->istate);
5216 portp->stats.txxoff++;
5218 if (xisr & XISR_RXXOFFGOT) {
5219 clear_bit(ASYI_TXFLOWED, &portp->istate);
5220 portp->stats.txxon++;
5224 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
5225 stl_sc26198rxbadchars(portp);
5232 /*****************************************************************************/