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>
47 #include <asm/uaccess.h>
50 #include <linux/pci.h>
53 /*****************************************************************************/
56 * Define different board types. Use the standard Stallion "assigned"
57 * board numbers. Boards supported in this driver are abbreviated as
58 * EIO = EasyIO and ECH = EasyConnection 8/32.
64 #define BRD_ECH64PCI 27
65 #define BRD_EASYIOPCI 28
68 * Define a configuration structure to hold the board configuration.
69 * Need to set this up in the code (for now) with the boards that are
70 * to be configured into the system. This is what needs to be modified
71 * when adding/removing/modifying boards. Each line entry in the
72 * stl_brdconf[] array is a board. Each line contains io/irq/memory
73 * ranges for that board (as well as what type of board it is).
75 * { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
76 * This line would configure an EasyIO board (4 or 8, no difference),
77 * at io address 2a0 and irq 10.
79 * { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
80 * This line will configure an EasyConnection 8/32 board at primary io
81 * address 2a8, secondary io address 280 and irq 12.
82 * Enter as many lines into this array as you want (only the first 4
83 * will actually be used!). Any combination of EasyIO and EasyConnection
84 * boards can be specified. EasyConnection 8/32 boards can share their
85 * secondary io addresses between each other.
87 * NOTE: there is no need to put any entries in this table for PCI
88 * boards. They will be found automatically by the driver - provided
89 * PCI BIOS32 support is compiled into the kernel.
96 unsigned long memaddr;
101 static stlconf_t stl_brdconf[] = {
102 /*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
105 static int stl_nrbrds = sizeof(stl_brdconf) / sizeof(stlconf_t);
107 /*****************************************************************************/
110 * Define some important driver characteristics. Device major numbers
111 * allocated as per Linux Device Registry.
113 #ifndef STL_SIOMEMMAJOR
114 #define STL_SIOMEMMAJOR 28
116 #ifndef STL_SERIALMAJOR
117 #define STL_SERIALMAJOR 24
119 #ifndef STL_CALLOUTMAJOR
120 #define STL_CALLOUTMAJOR 25
124 * Set the TX buffer size. Bigger is better, but we don't want
125 * to chew too much memory with buffers!
127 #define STL_TXBUFLOW 512
128 #define STL_TXBUFSIZE 4096
130 /*****************************************************************************/
133 * Define our local driver identity first. Set up stuff to deal with
134 * all the local structures required by a serial tty driver.
136 static char *stl_drvtitle = "Stallion Multiport Serial Driver";
137 static char *stl_drvname = "stallion";
138 static char *stl_drvversion = "5.6.0";
140 static struct tty_driver *stl_serial;
143 * We will need to allocate a temporary write buffer for chars that
144 * come direct from user space. The problem is that a copy from user
145 * space might cause a page fault (typically on a system that is
146 * swapping!). All ports will share one buffer - since if the system
147 * is already swapping a shared buffer won't make things any worse.
149 static char *stl_tmpwritebuf;
150 static DECLARE_MUTEX(stl_tmpwritesem);
153 * Define a local default termios struct. All ports will be created
154 * with this termios initially. Basically all it defines is a raw port
155 * at 9600, 8 data bits, 1 stop bit.
157 static struct termios stl_deftermios = {
158 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
163 * Define global stats structures. Not used often, and can be
164 * re-used for each stats call.
166 static comstats_t stl_comstats;
167 static combrd_t stl_brdstats;
168 static stlbrd_t stl_dummybrd;
169 static stlport_t stl_dummyport;
172 * Define global place to put buffer overflow characters.
174 static char stl_unwanted[SC26198_RXFIFOSIZE];
177 * Keep track of what interrupts we have requested for us.
178 * We don't need to request an interrupt twice if it is being
179 * shared with another Stallion board.
181 static int stl_gotintrs[STL_MAXBRDS];
182 static int stl_numintrs;
184 /*****************************************************************************/
186 static stlbrd_t *stl_brds[STL_MAXBRDS];
189 * Per board state flags. Used with the state field of the board struct.
190 * Not really much here!
192 #define BRD_FOUND 0x1
195 * Define the port structure istate flags. These set of flags are
196 * modified at interrupt time - so setting and reseting them needs
197 * to be atomic. Use the bit clear/setting routines for this.
199 #define ASYI_TXBUSY 1
201 #define ASYI_DCDCHANGE 3
202 #define ASYI_TXFLOWED 4
205 * Define an array of board names as printable strings. Handy for
206 * referencing boards when printing trace and stuff.
208 static char *stl_brdnames[] = {
240 /*****************************************************************************/
244 * Define some string labels for arguments passed from the module
245 * load line. These allow for easy board definitions, and easy
246 * modification of the io, memory and irq resoucres.
249 static char *board0[4];
250 static char *board1[4];
251 static char *board2[4];
252 static char *board3[4];
254 static char **stl_brdsp[] = {
262 * Define a set of common board names, and types. This is used to
263 * parse any module arguments.
266 typedef struct stlbrdtype {
271 static stlbrdtype_t stl_brdstr[] = {
272 { "easyio", BRD_EASYIO },
273 { "eio", BRD_EASYIO },
274 { "20", BRD_EASYIO },
275 { "ec8/32", BRD_ECH },
276 { "ec8/32-at", BRD_ECH },
277 { "ec8/32-isa", BRD_ECH },
279 { "echat", BRD_ECH },
281 { "ec8/32-mc", BRD_ECHMC },
282 { "ec8/32-mca", BRD_ECHMC },
283 { "echmc", BRD_ECHMC },
284 { "echmca", BRD_ECHMC },
286 { "ec8/32-pc", BRD_ECHPCI },
287 { "ec8/32-pci", BRD_ECHPCI },
288 { "26", BRD_ECHPCI },
289 { "ec8/64-pc", BRD_ECH64PCI },
290 { "ec8/64-pci", BRD_ECH64PCI },
291 { "ech-pci", BRD_ECH64PCI },
292 { "echpci", BRD_ECH64PCI },
293 { "echpc", BRD_ECH64PCI },
294 { "27", BRD_ECH64PCI },
295 { "easyio-pc", BRD_EASYIOPCI },
296 { "easyio-pci", BRD_EASYIOPCI },
297 { "eio-pci", BRD_EASYIOPCI },
298 { "eiopci", BRD_EASYIOPCI },
299 { "28", BRD_EASYIOPCI },
303 * Define the module agruments.
305 MODULE_AUTHOR("Greg Ungerer");
306 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
307 MODULE_LICENSE("GPL");
309 MODULE_PARM(board0, "1-4s");
310 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
311 MODULE_PARM(board1, "1-4s");
312 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
313 MODULE_PARM(board2, "1-4s");
314 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
315 MODULE_PARM(board3, "1-4s");
316 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
320 /*****************************************************************************/
323 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
324 * to the directly accessible io ports of these boards (not the uarts -
325 * they are in cd1400.h and sc26198.h).
327 #define EIO_8PORTRS 0x04
328 #define EIO_4PORTRS 0x05
329 #define EIO_8PORTDI 0x00
330 #define EIO_8PORTM 0x06
332 #define EIO_IDBITMASK 0x07
334 #define EIO_BRDMASK 0xf0
337 #define ID_BRD16 0x30
339 #define EIO_INTRPEND 0x08
340 #define EIO_INTEDGE 0x00
341 #define EIO_INTLEVEL 0x08
345 #define ECH_IDBITMASK 0xe0
346 #define ECH_BRDENABLE 0x08
347 #define ECH_BRDDISABLE 0x00
348 #define ECH_INTENABLE 0x01
349 #define ECH_INTDISABLE 0x00
350 #define ECH_INTLEVEL 0x02
351 #define ECH_INTEDGE 0x00
352 #define ECH_INTRPEND 0x01
353 #define ECH_BRDRESET 0x01
355 #define ECHMC_INTENABLE 0x01
356 #define ECHMC_BRDRESET 0x02
358 #define ECH_PNLSTATUS 2
359 #define ECH_PNL16PORT 0x20
360 #define ECH_PNLIDMASK 0x07
361 #define ECH_PNLXPID 0x40
362 #define ECH_PNLINTRPEND 0x80
364 #define ECH_ADDR2MASK 0x1e0
367 * Define the vector mapping bits for the programmable interrupt board
368 * hardware. These bits encode the interrupt for the board to use - it
369 * is software selectable (except the EIO-8M).
371 static unsigned char stl_vecmap[] = {
372 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
373 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
377 * Set up enable and disable macros for the ECH boards. They require
378 * the secondary io address space to be activated and deactivated.
379 * This way all ECH boards can share their secondary io region.
380 * If this is an ECH-PCI board then also need to set the page pointer
381 * to point to the correct page.
383 #define BRDENABLE(brdnr,pagenr) \
384 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
385 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
386 stl_brds[(brdnr)]->ioctrl); \
387 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
388 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
390 #define BRDDISABLE(brdnr) \
391 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
392 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
393 stl_brds[(brdnr)]->ioctrl);
395 #define STL_CD1400MAXBAUD 230400
396 #define STL_SC26198MAXBAUD 460800
398 #define STL_BAUDBASE 115200
399 #define STL_CLOSEDELAY (5 * HZ / 10)
401 /*****************************************************************************/
406 * Define the Stallion PCI vendor and device IDs.
408 #ifndef PCI_VENDOR_ID_STALLION
409 #define PCI_VENDOR_ID_STALLION 0x124d
411 #ifndef PCI_DEVICE_ID_ECHPCI832
412 #define PCI_DEVICE_ID_ECHPCI832 0x0000
414 #ifndef PCI_DEVICE_ID_ECHPCI864
415 #define PCI_DEVICE_ID_ECHPCI864 0x0002
417 #ifndef PCI_DEVICE_ID_EIOPCI
418 #define PCI_DEVICE_ID_EIOPCI 0x0003
422 * Define structure to hold all Stallion PCI boards.
424 typedef struct stlpcibrd {
425 unsigned short vendid;
426 unsigned short devid;
430 static stlpcibrd_t stl_pcibrds[] = {
431 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864, BRD_ECH64PCI },
432 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI, BRD_EASYIOPCI },
433 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832, BRD_ECHPCI },
434 { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
437 static int stl_nrpcibrds = sizeof(stl_pcibrds) / sizeof(stlpcibrd_t);
441 /*****************************************************************************/
444 * Define macros to extract a brd/port number from a minor number.
446 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
447 #define MINOR2PORT(min) ((min) & 0x3f)
450 * Define a baud rate table that converts termios baud rate selector
451 * into the actual baud rate value. All baud rate calculations are
452 * based on the actual baud rate required.
454 static unsigned int stl_baudrates[] = {
455 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
456 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
460 * Define some handy local macros...
463 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
466 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
468 /*****************************************************************************/
471 * Declare all those functions in this driver!
475 static void stl_argbrds(void);
476 static int stl_parsebrd(stlconf_t *confp, char **argp);
478 static unsigned long stl_atol(char *str);
482 static int stl_open(struct tty_struct *tty, struct file *filp);
483 static void stl_close(struct tty_struct *tty, struct file *filp);
484 static int stl_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count);
485 static void stl_putchar(struct tty_struct *tty, unsigned char ch);
486 static void stl_flushchars(struct tty_struct *tty);
487 static int stl_writeroom(struct tty_struct *tty);
488 static int stl_charsinbuffer(struct tty_struct *tty);
489 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
490 static void stl_settermios(struct tty_struct *tty, struct termios *old);
491 static void stl_throttle(struct tty_struct *tty);
492 static void stl_unthrottle(struct tty_struct *tty);
493 static void stl_stop(struct tty_struct *tty);
494 static void stl_start(struct tty_struct *tty);
495 static void stl_flushbuffer(struct tty_struct *tty);
496 static void stl_breakctl(struct tty_struct *tty, int state);
497 static void stl_waituntilsent(struct tty_struct *tty, int timeout);
498 static void stl_sendxchar(struct tty_struct *tty, char ch);
499 static void stl_hangup(struct tty_struct *tty);
500 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
501 static int stl_portinfo(stlport_t *portp, int portnr, char *pos);
502 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data);
504 static int stl_brdinit(stlbrd_t *brdp);
505 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
506 static int stl_mapirq(int irq, char *name);
507 static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp);
508 static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp);
509 static int stl_getbrdstats(combrd_t __user *bp);
510 static int stl_getportstats(stlport_t *portp, comstats_t __user *cp);
511 static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp);
512 static int stl_getportstruct(stlport_t __user *arg);
513 static int stl_getbrdstruct(stlbrd_t __user *arg);
514 static int stl_waitcarrier(stlport_t *portp, struct file *filp);
515 static void stl_delay(int len);
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 if (tty->ldisc.flush_buffer)
1201 (tty->ldisc.flush_buffer)(tty);
1204 portp->tty = (struct tty_struct *) NULL;
1206 if (portp->openwaitcnt) {
1207 if (portp->close_delay)
1208 stl_delay(portp->close_delay);
1209 wake_up_interruptible(&portp->open_wait);
1212 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1213 wake_up_interruptible(&portp->close_wait);
1214 restore_flags(flags);
1217 /*****************************************************************************/
1220 * Wait for a specified delay period, this is not a busy-loop. It will
1221 * give up the processor while waiting. Unfortunately this has some
1222 * rather intimate knowledge of the process management stuff.
1225 static void stl_delay(int len)
1228 printk("stl_delay(len=%d)\n", len);
1231 current->state = TASK_INTERRUPTIBLE;
1232 schedule_timeout(len);
1236 /*****************************************************************************/
1239 * Write routine. Take data and stuff it in to the TX ring queue.
1240 * If transmit interrupts are not running then start them.
1243 static int stl_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count)
1246 unsigned int len, stlen;
1247 unsigned char *chbuf;
1251 printk("stl_write(tty=%x,from_user=%d,buf=%x,count=%d)\n",
1252 (int) tty, from_user, (int) buf, count);
1255 if ((tty == (struct tty_struct *) NULL) ||
1256 (stl_tmpwritebuf == (char *) NULL))
1258 portp = tty->driver_data;
1259 if (portp == (stlport_t *) NULL)
1261 if (portp->tx.buf == (char *) NULL)
1265 * If copying direct from user space we must cater for page faults,
1266 * causing us to "sleep" here for a while. To handle this copy in all
1267 * the data we need now, into a local buffer. Then when we got it all
1268 * copy it into the TX buffer.
1270 chbuf = (unsigned char *) buf;
1272 head = portp->tx.head;
1273 tail = portp->tx.tail;
1274 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) :
1276 count = MIN(len, count);
1278 down(&stl_tmpwritesem);
1279 if (copy_from_user(stl_tmpwritebuf, chbuf, count))
1281 chbuf = &stl_tmpwritebuf[0];
1284 head = portp->tx.head;
1285 tail = portp->tx.tail;
1287 len = STL_TXBUFSIZE - (head - tail) - 1;
1288 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
1290 len = tail - head - 1;
1294 len = MIN(len, count);
1297 stlen = MIN(len, stlen);
1298 memcpy(head, chbuf, stlen);
1303 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
1304 head = portp->tx.buf;
1305 stlen = tail - head;
1308 portp->tx.head = head;
1310 clear_bit(ASYI_TXLOW, &portp->istate);
1311 stl_startrxtx(portp, -1, 1);
1314 up(&stl_tmpwritesem);
1319 /*****************************************************************************/
1321 static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1328 printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1331 if (tty == (struct tty_struct *) NULL)
1333 portp = tty->driver_data;
1334 if (portp == (stlport_t *) NULL)
1336 if (portp->tx.buf == (char *) NULL)
1339 head = portp->tx.head;
1340 tail = portp->tx.tail;
1342 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
1347 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
1348 head = portp->tx.buf;
1350 portp->tx.head = head;
1353 /*****************************************************************************/
1356 * If there are any characters in the buffer then make sure that TX
1357 * interrupts are on and get'em out. Normally used after the putchar
1358 * routine has been called.
1361 static void stl_flushchars(struct tty_struct *tty)
1366 printk("stl_flushchars(tty=%x)\n", (int) tty);
1369 if (tty == (struct tty_struct *) NULL)
1371 portp = tty->driver_data;
1372 if (portp == (stlport_t *) NULL)
1374 if (portp->tx.buf == (char *) NULL)
1378 if (tty->stopped || tty->hw_stopped ||
1379 (portp->tx.head == portp->tx.tail))
1382 stl_startrxtx(portp, -1, 1);
1385 /*****************************************************************************/
1387 static int stl_writeroom(struct tty_struct *tty)
1393 printk("stl_writeroom(tty=%x)\n", (int) tty);
1396 if (tty == (struct tty_struct *) NULL)
1398 portp = tty->driver_data;
1399 if (portp == (stlport_t *) NULL)
1401 if (portp->tx.buf == (char *) NULL)
1404 head = portp->tx.head;
1405 tail = portp->tx.tail;
1406 return((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
1409 /*****************************************************************************/
1412 * Return number of chars in the TX buffer. Normally we would just
1413 * calculate the number of chars in the buffer and return that, but if
1414 * the buffer is empty and TX interrupts are still on then we return
1415 * that the buffer still has 1 char in it. This way whoever called us
1416 * will not think that ALL chars have drained - since the UART still
1417 * must have some chars in it (we are busy after all).
1420 static int stl_charsinbuffer(struct tty_struct *tty)
1427 printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
1430 if (tty == (struct tty_struct *) NULL)
1432 portp = tty->driver_data;
1433 if (portp == (stlport_t *) NULL)
1435 if (portp->tx.buf == (char *) NULL)
1438 head = portp->tx.head;
1439 tail = portp->tx.tail;
1440 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1441 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1446 /*****************************************************************************/
1449 * Generate the serial struct info.
1452 static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp)
1454 struct serial_struct sio;
1458 printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1461 memset(&sio, 0, sizeof(struct serial_struct));
1462 sio.line = portp->portnr;
1463 sio.port = portp->ioaddr;
1464 sio.flags = portp->flags;
1465 sio.baud_base = portp->baud_base;
1466 sio.close_delay = portp->close_delay;
1467 sio.closing_wait = portp->closing_wait;
1468 sio.custom_divisor = portp->custom_divisor;
1470 if (portp->uartp == &stl_cd1400uart) {
1471 sio.type = PORT_CIRRUS;
1472 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1474 sio.type = PORT_UNKNOWN;
1475 sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1478 brdp = stl_brds[portp->brdnr];
1479 if (brdp != (stlbrd_t *) NULL)
1480 sio.irq = brdp->irq;
1482 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
1485 /*****************************************************************************/
1488 * Set port according to the serial struct info.
1489 * At this point we do not do any auto-configure stuff, so we will
1490 * just quietly ignore any requests to change irq, etc.
1493 static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp)
1495 struct serial_struct sio;
1498 printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1501 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1503 if (!capable(CAP_SYS_ADMIN)) {
1504 if ((sio.baud_base != portp->baud_base) ||
1505 (sio.close_delay != portp->close_delay) ||
1506 ((sio.flags & ~ASYNC_USR_MASK) !=
1507 (portp->flags & ~ASYNC_USR_MASK)))
1511 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1512 (sio.flags & ASYNC_USR_MASK);
1513 portp->baud_base = sio.baud_base;
1514 portp->close_delay = sio.close_delay;
1515 portp->closing_wait = sio.closing_wait;
1516 portp->custom_divisor = sio.custom_divisor;
1517 stl_setport(portp, portp->tty->termios);
1521 /*****************************************************************************/
1523 static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1527 if (tty == (struct tty_struct *) NULL)
1529 portp = tty->driver_data;
1530 if (portp == (stlport_t *) NULL)
1532 if (tty->flags & (1 << TTY_IO_ERROR))
1535 return stl_getsignals(portp);
1538 static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1539 unsigned int set, unsigned int clear)
1542 int rts = -1, dtr = -1;
1544 if (tty == (struct tty_struct *) NULL)
1546 portp = tty->driver_data;
1547 if (portp == (stlport_t *) NULL)
1549 if (tty->flags & (1 << TTY_IO_ERROR))
1552 if (set & TIOCM_RTS)
1554 if (set & TIOCM_DTR)
1556 if (clear & TIOCM_RTS)
1558 if (clear & TIOCM_DTR)
1561 stl_setsignals(portp, dtr, rts);
1565 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1570 void __user *argp = (void __user *)arg;
1573 printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
1574 (int) tty, (int) file, cmd, (int) arg);
1577 if (tty == (struct tty_struct *) NULL)
1579 portp = tty->driver_data;
1580 if (portp == (stlport_t *) NULL)
1583 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1584 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1585 if (tty->flags & (1 << TTY_IO_ERROR))
1593 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1594 (unsigned __user *) argp);
1597 if (get_user(ival, (unsigned int __user *) arg))
1599 tty->termios->c_cflag =
1600 (tty->termios->c_cflag & ~CLOCAL) |
1601 (ival ? CLOCAL : 0);
1604 rc = stl_getserial(portp, argp);
1607 rc = stl_setserial(portp, argp);
1609 case COM_GETPORTSTATS:
1610 rc = stl_getportstats(portp, argp);
1612 case COM_CLRPORTSTATS:
1613 rc = stl_clrportstats(portp, argp);
1619 case TIOCSERGSTRUCT:
1620 case TIOCSERGETMULTI:
1621 case TIOCSERSETMULTI:
1630 /*****************************************************************************/
1632 static void stl_settermios(struct tty_struct *tty, struct termios *old)
1635 struct termios *tiosp;
1638 printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
1641 if (tty == (struct tty_struct *) NULL)
1643 portp = tty->driver_data;
1644 if (portp == (stlport_t *) NULL)
1647 tiosp = tty->termios;
1648 if ((tiosp->c_cflag == old->c_cflag) &&
1649 (tiosp->c_iflag == old->c_iflag))
1652 stl_setport(portp, tiosp);
1653 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1655 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1656 tty->hw_stopped = 0;
1659 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1660 wake_up_interruptible(&portp->open_wait);
1663 /*****************************************************************************/
1666 * Attempt to flow control who ever is sending us data. Based on termios
1667 * settings use software or/and hardware flow control.
1670 static void stl_throttle(struct tty_struct *tty)
1675 printk("stl_throttle(tty=%x)\n", (int) tty);
1678 if (tty == (struct tty_struct *) NULL)
1680 portp = tty->driver_data;
1681 if (portp == (stlport_t *) NULL)
1683 stl_flowctrl(portp, 0);
1686 /*****************************************************************************/
1689 * Unflow control the device sending us data...
1692 static void stl_unthrottle(struct tty_struct *tty)
1697 printk("stl_unthrottle(tty=%x)\n", (int) tty);
1700 if (tty == (struct tty_struct *) NULL)
1702 portp = tty->driver_data;
1703 if (portp == (stlport_t *) NULL)
1705 stl_flowctrl(portp, 1);
1708 /*****************************************************************************/
1711 * Stop the transmitter. Basically to do this we will just turn TX
1715 static void stl_stop(struct tty_struct *tty)
1720 printk("stl_stop(tty=%x)\n", (int) tty);
1723 if (tty == (struct tty_struct *) NULL)
1725 portp = tty->driver_data;
1726 if (portp == (stlport_t *) NULL)
1728 stl_startrxtx(portp, -1, 0);
1731 /*****************************************************************************/
1734 * Start the transmitter again. Just turn TX interrupts back on.
1737 static void stl_start(struct tty_struct *tty)
1742 printk("stl_start(tty=%x)\n", (int) tty);
1745 if (tty == (struct tty_struct *) NULL)
1747 portp = tty->driver_data;
1748 if (portp == (stlport_t *) NULL)
1750 stl_startrxtx(portp, -1, 1);
1753 /*****************************************************************************/
1756 * Hangup this port. This is pretty much like closing the port, only
1757 * a little more brutal. No waiting for data to drain. Shutdown the
1758 * port and maybe drop signals.
1761 static void stl_hangup(struct tty_struct *tty)
1766 printk("stl_hangup(tty=%x)\n", (int) tty);
1769 if (tty == (struct tty_struct *) NULL)
1771 portp = tty->driver_data;
1772 if (portp == (stlport_t *) NULL)
1775 portp->flags &= ~ASYNC_INITIALIZED;
1776 stl_disableintrs(portp);
1777 if (tty->termios->c_cflag & HUPCL)
1778 stl_setsignals(portp, 0, 0);
1779 stl_enablerxtx(portp, 0, 0);
1780 stl_flushbuffer(tty);
1782 set_bit(TTY_IO_ERROR, &tty->flags);
1783 if (portp->tx.buf != (char *) NULL) {
1784 kfree(portp->tx.buf);
1785 portp->tx.buf = (char *) NULL;
1786 portp->tx.head = (char *) NULL;
1787 portp->tx.tail = (char *) NULL;
1789 portp->tty = (struct tty_struct *) NULL;
1790 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1791 portp->refcount = 0;
1792 wake_up_interruptible(&portp->open_wait);
1795 /*****************************************************************************/
1797 static void stl_flushbuffer(struct tty_struct *tty)
1802 printk("stl_flushbuffer(tty=%x)\n", (int) tty);
1805 if (tty == (struct tty_struct *) NULL)
1807 portp = tty->driver_data;
1808 if (portp == (stlport_t *) NULL)
1812 wake_up_interruptible(&tty->write_wait);
1813 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1814 tty->ldisc.write_wakeup)
1815 (tty->ldisc.write_wakeup)(tty);
1818 /*****************************************************************************/
1820 static void stl_breakctl(struct tty_struct *tty, int state)
1825 printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty, state);
1828 if (tty == (struct tty_struct *) NULL)
1830 portp = tty->driver_data;
1831 if (portp == (stlport_t *) NULL)
1834 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1837 /*****************************************************************************/
1839 static void stl_waituntilsent(struct tty_struct *tty, int timeout)
1845 printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty, timeout);
1848 if (tty == (struct tty_struct *) NULL)
1850 portp = tty->driver_data;
1851 if (portp == (stlport_t *) NULL)
1856 tend = jiffies + timeout;
1858 while (stl_datastate(portp)) {
1859 if (signal_pending(current))
1862 if (time_after_eq(jiffies, tend))
1867 /*****************************************************************************/
1869 static void stl_sendxchar(struct tty_struct *tty, char ch)
1874 printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
1877 if (tty == (struct tty_struct *) NULL)
1879 portp = tty->driver_data;
1880 if (portp == (stlport_t *) NULL)
1883 if (ch == STOP_CHAR(tty))
1884 stl_sendflow(portp, 0);
1885 else if (ch == START_CHAR(tty))
1886 stl_sendflow(portp, 1);
1888 stl_putchar(tty, ch);
1891 /*****************************************************************************/
1896 * Format info for a specified port. The line is deliberately limited
1897 * to 80 characters. (If it is too long it will be truncated, if too
1898 * short then padded with spaces).
1901 static int stl_portinfo(stlport_t *portp, int portnr, char *pos)
1907 sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
1908 portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
1909 (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
1911 if (portp->stats.rxframing)
1912 sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
1913 if (portp->stats.rxparity)
1914 sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
1915 if (portp->stats.rxbreaks)
1916 sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
1917 if (portp->stats.rxoverrun)
1918 sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
1920 sigs = stl_getsignals(portp);
1921 cnt = sprintf(sp, "%s%s%s%s%s ",
1922 (sigs & TIOCM_RTS) ? "|RTS" : "",
1923 (sigs & TIOCM_CTS) ? "|CTS" : "",
1924 (sigs & TIOCM_DTR) ? "|DTR" : "",
1925 (sigs & TIOCM_CD) ? "|DCD" : "",
1926 (sigs & TIOCM_DSR) ? "|DSR" : "");
1930 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
1933 pos[(MAXLINE - 2)] = '+';
1934 pos[(MAXLINE - 1)] = '\n';
1939 /*****************************************************************************/
1942 * Port info, read from the /proc file system.
1945 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
1950 int brdnr, panelnr, portnr, totalport;
1955 printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
1956 "data=%x\n", (int) page, (int) start, (int) off, count,
1957 (int) eof, (int) data);
1965 pos += sprintf(pos, "%s: version %s", stl_drvtitle,
1967 while (pos < (page + MAXLINE - 1))
1974 * We scan through for each board, panel and port. The offset is
1975 * calculated on the fly, and irrelevant ports are skipped.
1977 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1978 brdp = stl_brds[brdnr];
1979 if (brdp == (stlbrd_t *) NULL)
1981 if (brdp->state == 0)
1984 maxoff = curoff + (brdp->nrports * MAXLINE);
1985 if (off >= maxoff) {
1990 totalport = brdnr * STL_MAXPORTS;
1991 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1992 panelp = brdp->panels[panelnr];
1993 if (panelp == (stlpanel_t *) NULL)
1996 maxoff = curoff + (panelp->nrports * MAXLINE);
1997 if (off >= maxoff) {
1999 totalport += panelp->nrports;
2003 for (portnr = 0; (portnr < panelp->nrports); portnr++,
2005 portp = panelp->ports[portnr];
2006 if (portp == (stlport_t *) NULL)
2008 if (off >= (curoff += MAXLINE))
2010 if ((pos - page + MAXLINE) > count)
2012 pos += stl_portinfo(portp, totalport, pos);
2024 /*****************************************************************************/
2027 * All board interrupts are vectored through here first. This code then
2028 * calls off to the approrpriate board interrupt handlers.
2031 static irqreturn_t stl_intr(int irq, void *dev_id, struct pt_regs *regs)
2038 printk("stl_intr(irq=%d,regs=%x)\n", irq, (int) regs);
2041 for (i = 0; (i < stl_nrbrds); i++) {
2042 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
2044 if (brdp->state == 0)
2047 (* brdp->isr)(brdp);
2049 return IRQ_RETVAL(handled);
2052 /*****************************************************************************/
2055 * Interrupt service routine for EasyIO board types.
2058 static void stl_eiointr(stlbrd_t *brdp)
2061 unsigned int iobase;
2063 panelp = brdp->panels[0];
2064 iobase = panelp->iobase;
2065 while (inb(brdp->iostatus) & EIO_INTRPEND)
2066 (* panelp->isr)(panelp, iobase);
2069 /*****************************************************************************/
2072 * Interrupt service routine for ECH-AT board types.
2075 static void stl_echatintr(stlbrd_t *brdp)
2078 unsigned int ioaddr;
2081 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2083 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2084 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2085 ioaddr = brdp->bnkstataddr[bnknr];
2086 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2087 panelp = brdp->bnk2panel[bnknr];
2088 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2093 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2096 /*****************************************************************************/
2099 * Interrupt service routine for ECH-MCA board types.
2102 static void stl_echmcaintr(stlbrd_t *brdp)
2105 unsigned int ioaddr;
2108 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2109 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2110 ioaddr = brdp->bnkstataddr[bnknr];
2111 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2112 panelp = brdp->bnk2panel[bnknr];
2113 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2119 /*****************************************************************************/
2122 * Interrupt service routine for ECH-PCI board types.
2125 static void stl_echpciintr(stlbrd_t *brdp)
2128 unsigned int ioaddr;
2133 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2134 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
2135 ioaddr = brdp->bnkstataddr[bnknr];
2136 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2137 panelp = brdp->bnk2panel[bnknr];
2138 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2147 /*****************************************************************************/
2150 * Interrupt service routine for ECH-8/64-PCI board types.
2153 static void stl_echpci64intr(stlbrd_t *brdp)
2156 unsigned int ioaddr;
2159 while (inb(brdp->ioctrl) & 0x1) {
2160 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2161 ioaddr = brdp->bnkstataddr[bnknr];
2162 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2163 panelp = brdp->bnk2panel[bnknr];
2164 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2170 /*****************************************************************************/
2173 * Service an off-level request for some channel.
2175 static void stl_offintr(void *private)
2178 struct tty_struct *tty;
2179 unsigned int oldsigs;
2184 printk("stl_offintr(portp=%x)\n", (int) portp);
2187 if (portp == (stlport_t *) NULL)
2191 if (tty == (struct tty_struct *) NULL)
2195 if (test_bit(ASYI_TXLOW, &portp->istate)) {
2196 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2197 tty->ldisc.write_wakeup)
2198 (tty->ldisc.write_wakeup)(tty);
2199 wake_up_interruptible(&tty->write_wait);
2201 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
2202 clear_bit(ASYI_DCDCHANGE, &portp->istate);
2203 oldsigs = portp->sigs;
2204 portp->sigs = stl_getsignals(portp);
2205 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
2206 wake_up_interruptible(&portp->open_wait);
2207 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
2208 if (portp->flags & ASYNC_CHECK_CD)
2209 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2215 /*****************************************************************************/
2218 * Map in interrupt vector to this driver. Check that we don't
2219 * already have this vector mapped, we might be sharing this
2220 * interrupt across multiple boards.
2223 static int __init stl_mapirq(int irq, char *name)
2228 printk("stl_mapirq(irq=%d,name=%s)\n", irq, name);
2232 for (i = 0; (i < stl_numintrs); i++) {
2233 if (stl_gotintrs[i] == irq)
2236 if (i >= stl_numintrs) {
2237 if (request_irq(irq, stl_intr, SA_SHIRQ, name, NULL) != 0) {
2238 printk("STALLION: failed to register interrupt "
2239 "routine for %s irq=%d\n", name, irq);
2242 stl_gotintrs[stl_numintrs++] = irq;
2248 /*****************************************************************************/
2251 * Initialize all the ports on a panel.
2254 static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2260 printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
2263 chipmask = stl_panelinit(brdp, panelp);
2266 * All UART's are initialized (if found!). Now go through and setup
2267 * each ports data structures.
2269 for (i = 0; (i < panelp->nrports); i++) {
2270 portp = (stlport_t *) stl_memalloc(sizeof(stlport_t));
2271 if (portp == (stlport_t *) NULL) {
2272 printk("STALLION: failed to allocate memory "
2273 "(size=%d)\n", sizeof(stlport_t));
2276 memset(portp, 0, sizeof(stlport_t));
2278 portp->magic = STL_PORTMAGIC;
2280 portp->brdnr = panelp->brdnr;
2281 portp->panelnr = panelp->panelnr;
2282 portp->uartp = panelp->uartp;
2283 portp->clk = brdp->clk;
2284 portp->baud_base = STL_BAUDBASE;
2285 portp->close_delay = STL_CLOSEDELAY;
2286 portp->closing_wait = 30 * HZ;
2287 INIT_WORK(&portp->tqueue, stl_offintr, portp);
2288 init_waitqueue_head(&portp->open_wait);
2289 init_waitqueue_head(&portp->close_wait);
2290 portp->stats.brd = portp->brdnr;
2291 portp->stats.panel = portp->panelnr;
2292 portp->stats.port = portp->portnr;
2293 panelp->ports[i] = portp;
2294 stl_portinit(brdp, panelp, portp);
2300 /*****************************************************************************/
2303 * Try to find and initialize an EasyIO board.
2306 static inline int stl_initeio(stlbrd_t *brdp)
2309 unsigned int status;
2314 printk("stl_initeio(brdp=%x)\n", (int) brdp);
2317 brdp->ioctrl = brdp->ioaddr1 + 1;
2318 brdp->iostatus = brdp->ioaddr1 + 2;
2320 status = inb(brdp->iostatus);
2321 if ((status & EIO_IDBITMASK) == EIO_MK3)
2325 * Handle board specific stuff now. The real difference is PCI
2328 if (brdp->brdtype == BRD_EASYIOPCI) {
2329 brdp->iosize1 = 0x80;
2330 brdp->iosize2 = 0x80;
2331 name = "serial(EIO-PCI)";
2332 outb(0x41, (brdp->ioaddr2 + 0x4c));
2335 name = "serial(EIO)";
2336 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2337 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2338 printk("STALLION: invalid irq=%d for brd=%d\n",
2339 brdp->irq, brdp->brdnr);
2342 outb((stl_vecmap[brdp->irq] | EIO_0WS |
2343 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
2347 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2348 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2349 "%x conflicts with another device\n", brdp->brdnr,
2354 if (brdp->iosize2 > 0)
2355 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2356 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2357 "address %x conflicts with another device\n",
2358 brdp->brdnr, brdp->ioaddr2);
2359 printk(KERN_WARNING "STALLION: Warning, also "
2360 "releasing board %d I/O address %x \n",
2361 brdp->brdnr, brdp->ioaddr1);
2362 release_region(brdp->ioaddr1, brdp->iosize1);
2367 * Everything looks OK, so let's go ahead and probe for the hardware.
2369 brdp->clk = CD1400_CLK;
2370 brdp->isr = stl_eiointr;
2372 switch (status & EIO_IDBITMASK) {
2374 brdp->clk = CD1400_CLK8M;
2384 switch (status & EIO_BRDMASK) {
2403 * We have verified that the board is actually present, so now we
2404 * can complete the setup.
2407 panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
2408 if (panelp == (stlpanel_t *) NULL) {
2409 printk(KERN_WARNING "STALLION: failed to allocate memory "
2410 "(size=%d)\n", sizeof(stlpanel_t));
2413 memset(panelp, 0, sizeof(stlpanel_t));
2415 panelp->magic = STL_PANELMAGIC;
2416 panelp->brdnr = brdp->brdnr;
2417 panelp->panelnr = 0;
2418 panelp->nrports = brdp->nrports;
2419 panelp->iobase = brdp->ioaddr1;
2420 panelp->hwid = status;
2421 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2422 panelp->uartp = (void *) &stl_sc26198uart;
2423 panelp->isr = stl_sc26198intr;
2425 panelp->uartp = (void *) &stl_cd1400uart;
2426 panelp->isr = stl_cd1400eiointr;
2429 brdp->panels[0] = panelp;
2431 brdp->state |= BRD_FOUND;
2432 brdp->hwid = status;
2433 rc = stl_mapirq(brdp->irq, name);
2437 /*****************************************************************************/
2440 * Try to find an ECH board and initialize it. This code is capable of
2441 * dealing with all types of ECH board.
2444 static inline int stl_initech(stlbrd_t *brdp)
2447 unsigned int status, nxtid, ioaddr, conflict;
2448 int panelnr, banknr, i;
2452 printk("stl_initech(brdp=%x)\n", (int) brdp);
2459 * Set up the initial board register contents for boards. This varies a
2460 * bit between the different board types. So we need to handle each
2461 * separately. Also do a check that the supplied IRQ is good.
2463 switch (brdp->brdtype) {
2466 brdp->isr = stl_echatintr;
2467 brdp->ioctrl = brdp->ioaddr1 + 1;
2468 brdp->iostatus = brdp->ioaddr1 + 1;
2469 status = inb(brdp->iostatus);
2470 if ((status & ECH_IDBITMASK) != ECH_ID)
2472 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2473 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2474 printk("STALLION: invalid irq=%d for brd=%d\n",
2475 brdp->irq, brdp->brdnr);
2478 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2479 status |= (stl_vecmap[brdp->irq] << 1);
2480 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2481 brdp->ioctrlval = ECH_INTENABLE |
2482 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2483 for (i = 0; (i < 10); i++)
2484 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2487 name = "serial(EC8/32)";
2488 outb(status, brdp->ioaddr1);
2492 brdp->isr = stl_echmcaintr;
2493 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2494 brdp->iostatus = brdp->ioctrl;
2495 status = inb(brdp->iostatus);
2496 if ((status & ECH_IDBITMASK) != ECH_ID)
2498 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2499 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2500 printk("STALLION: invalid irq=%d for brd=%d\n",
2501 brdp->irq, brdp->brdnr);
2504 outb(ECHMC_BRDRESET, brdp->ioctrl);
2505 outb(ECHMC_INTENABLE, brdp->ioctrl);
2507 name = "serial(EC8/32-MC)";
2511 brdp->isr = stl_echpciintr;
2512 brdp->ioctrl = brdp->ioaddr1 + 2;
2515 name = "serial(EC8/32-PCI)";
2519 brdp->isr = stl_echpci64intr;
2520 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2521 outb(0x43, (brdp->ioaddr1 + 0x4c));
2522 brdp->iosize1 = 0x80;
2523 brdp->iosize2 = 0x80;
2524 name = "serial(EC8/64-PCI)";
2528 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
2534 * Check boards for possible IO address conflicts and return fail status
2535 * if an IO conflict found.
2537 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2538 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2539 "%x conflicts with another device\n", brdp->brdnr,
2544 if (brdp->iosize2 > 0)
2545 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2546 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2547 "address %x conflicts with another device\n",
2548 brdp->brdnr, brdp->ioaddr2);
2549 printk(KERN_WARNING "STALLION: Warning, also "
2550 "releasing board %d I/O address %x \n",
2551 brdp->brdnr, brdp->ioaddr1);
2552 release_region(brdp->ioaddr1, brdp->iosize1);
2557 * Scan through the secondary io address space looking for panels.
2558 * As we find'em allocate and initialize panel structures for each.
2560 brdp->clk = CD1400_CLK;
2561 brdp->hwid = status;
2563 ioaddr = brdp->ioaddr2;
2568 for (i = 0; (i < STL_MAXPANELS); i++) {
2569 if (brdp->brdtype == BRD_ECHPCI) {
2570 outb(nxtid, brdp->ioctrl);
2571 ioaddr = brdp->ioaddr2;
2573 status = inb(ioaddr + ECH_PNLSTATUS);
2574 if ((status & ECH_PNLIDMASK) != nxtid)
2576 panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
2577 if (panelp == (stlpanel_t *) NULL) {
2578 printk("STALLION: failed to allocate memory "
2579 "(size=%d)\n", sizeof(stlpanel_t));
2582 memset(panelp, 0, sizeof(stlpanel_t));
2583 panelp->magic = STL_PANELMAGIC;
2584 panelp->brdnr = brdp->brdnr;
2585 panelp->panelnr = panelnr;
2586 panelp->iobase = ioaddr;
2587 panelp->pagenr = nxtid;
2588 panelp->hwid = status;
2589 brdp->bnk2panel[banknr] = panelp;
2590 brdp->bnkpageaddr[banknr] = nxtid;
2591 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2593 if (status & ECH_PNLXPID) {
2594 panelp->uartp = (void *) &stl_sc26198uart;
2595 panelp->isr = stl_sc26198intr;
2596 if (status & ECH_PNL16PORT) {
2597 panelp->nrports = 16;
2598 brdp->bnk2panel[banknr] = panelp;
2599 brdp->bnkpageaddr[banknr] = nxtid;
2600 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2603 panelp->nrports = 8;
2606 panelp->uartp = (void *) &stl_cd1400uart;
2607 panelp->isr = stl_cd1400echintr;
2608 if (status & ECH_PNL16PORT) {
2609 panelp->nrports = 16;
2610 panelp->ackmask = 0x80;
2611 if (brdp->brdtype != BRD_ECHPCI)
2612 ioaddr += EREG_BANKSIZE;
2613 brdp->bnk2panel[banknr] = panelp;
2614 brdp->bnkpageaddr[banknr] = ++nxtid;
2615 brdp->bnkstataddr[banknr++] = ioaddr +
2618 panelp->nrports = 8;
2619 panelp->ackmask = 0xc0;
2624 ioaddr += EREG_BANKSIZE;
2625 brdp->nrports += panelp->nrports;
2626 brdp->panels[panelnr++] = panelp;
2627 if ((brdp->brdtype != BRD_ECHPCI) &&
2628 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
2632 brdp->nrpanels = panelnr;
2633 brdp->nrbnks = banknr;
2634 if (brdp->brdtype == BRD_ECH)
2635 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2637 brdp->state |= BRD_FOUND;
2638 i = stl_mapirq(brdp->irq, name);
2642 /*****************************************************************************/
2645 * Initialize and configure the specified board.
2646 * Scan through all the boards in the configuration and see what we
2647 * can find. Handle EIO and the ECH boards a little differently here
2648 * since the initial search and setup is very different.
2651 static int __init stl_brdinit(stlbrd_t *brdp)
2656 printk("stl_brdinit(brdp=%x)\n", (int) brdp);
2659 switch (brdp->brdtype) {
2671 printk("STALLION: board=%d is unknown board type=%d\n",
2672 brdp->brdnr, brdp->brdtype);
2676 stl_brds[brdp->brdnr] = brdp;
2677 if ((brdp->state & BRD_FOUND) == 0) {
2678 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2679 stl_brdnames[brdp->brdtype], brdp->brdnr,
2680 brdp->ioaddr1, brdp->irq);
2684 for (i = 0; (i < STL_MAXPANELS); i++)
2685 if (brdp->panels[i] != (stlpanel_t *) NULL)
2686 stl_initports(brdp, brdp->panels[i]);
2688 printk("STALLION: %s found, board=%d io=%x irq=%d "
2689 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2690 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2695 /*****************************************************************************/
2698 * Find the next available board number that is free.
2701 static inline int stl_getbrdnr(void)
2705 for (i = 0; (i < STL_MAXBRDS); i++) {
2706 if (stl_brds[i] == (stlbrd_t *) NULL) {
2707 if (i >= stl_nrbrds)
2715 /*****************************************************************************/
2720 * We have a Stallion board. Allocate a board structure and
2721 * initialize it. Read its IO and IRQ resources from PCI
2722 * configuration space.
2725 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
2730 printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
2731 devp->bus->number, devp->devfn);
2734 if (pci_enable_device(devp))
2736 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2738 if ((brdp->brdnr = stl_getbrdnr()) < 0) {
2739 printk("STALLION: too many boards found, "
2740 "maximum supported %d\n", STL_MAXBRDS);
2743 brdp->brdtype = brdtype;
2746 * Different Stallion boards use the BAR registers in different ways,
2747 * so set up io addresses based on board type.
2750 printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__, __LINE__,
2751 pci_resource_start(devp, 0), pci_resource_start(devp, 1),
2752 pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
2756 * We have all resources from the board, so let's setup the actual
2757 * board structure now.
2761 brdp->ioaddr2 = pci_resource_start(devp, 0);
2762 brdp->ioaddr1 = pci_resource_start(devp, 1);
2765 brdp->ioaddr2 = pci_resource_start(devp, 2);
2766 brdp->ioaddr1 = pci_resource_start(devp, 1);
2769 brdp->ioaddr1 = pci_resource_start(devp, 2);
2770 brdp->ioaddr2 = pci_resource_start(devp, 1);
2773 printk("STALLION: unknown PCI board type=%d\n", brdtype);
2777 brdp->irq = devp->irq;
2783 /*****************************************************************************/
2786 * Find all Stallion PCI boards that might be installed. Initialize each
2787 * one as it is found.
2791 static inline int stl_findpcibrds(void)
2793 struct pci_dev *dev = NULL;
2797 printk("stl_findpcibrds()\n");
2800 for (i = 0; (i < stl_nrpcibrds); i++)
2801 while ((dev = pci_find_device(stl_pcibrds[i].vendid,
2802 stl_pcibrds[i].devid, dev))) {
2805 * Found a device on the PCI bus that has our vendor and
2806 * device ID. Need to check now that it is really us.
2808 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2811 rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
2821 /*****************************************************************************/
2824 * Scan through all the boards in the configuration and see what we
2825 * can find. Handle EIO and the ECH boards a little differently here
2826 * since the initial search and setup is too different.
2829 static inline int stl_initbrds(void)
2836 printk("stl_initbrds()\n");
2839 if (stl_nrbrds > STL_MAXBRDS) {
2840 printk("STALLION: too many boards in configuration table, "
2841 "truncating to %d\n", STL_MAXBRDS);
2842 stl_nrbrds = STL_MAXBRDS;
2846 * Firstly scan the list of static boards configured. Allocate
2847 * resources and initialize the boards as found.
2849 for (i = 0; (i < stl_nrbrds); i++) {
2850 confp = &stl_brdconf[i];
2852 stl_parsebrd(confp, stl_brdsp[i]);
2854 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2857 brdp->brdtype = confp->brdtype;
2858 brdp->ioaddr1 = confp->ioaddr1;
2859 brdp->ioaddr2 = confp->ioaddr2;
2860 brdp->irq = confp->irq;
2861 brdp->irqtype = confp->irqtype;
2866 * Find any dynamically supported boards. That is via module load
2867 * line options or auto-detected on the PCI bus.
2879 /*****************************************************************************/
2882 * Return the board stats structure to user app.
2885 static int stl_getbrdstats(combrd_t __user *bp)
2891 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2893 if (stl_brdstats.brd >= STL_MAXBRDS)
2895 brdp = stl_brds[stl_brdstats.brd];
2896 if (brdp == (stlbrd_t *) NULL)
2899 memset(&stl_brdstats, 0, sizeof(combrd_t));
2900 stl_brdstats.brd = brdp->brdnr;
2901 stl_brdstats.type = brdp->brdtype;
2902 stl_brdstats.hwid = brdp->hwid;
2903 stl_brdstats.state = brdp->state;
2904 stl_brdstats.ioaddr = brdp->ioaddr1;
2905 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2906 stl_brdstats.irq = brdp->irq;
2907 stl_brdstats.nrpanels = brdp->nrpanels;
2908 stl_brdstats.nrports = brdp->nrports;
2909 for (i = 0; (i < brdp->nrpanels); i++) {
2910 panelp = brdp->panels[i];
2911 stl_brdstats.panels[i].panel = i;
2912 stl_brdstats.panels[i].hwid = panelp->hwid;
2913 stl_brdstats.panels[i].nrports = panelp->nrports;
2916 return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
2919 /*****************************************************************************/
2922 * Resolve the referenced port number into a port struct pointer.
2925 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2930 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2931 return((stlport_t *) NULL);
2932 brdp = stl_brds[brdnr];
2933 if (brdp == (stlbrd_t *) NULL)
2934 return((stlport_t *) NULL);
2935 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2936 return((stlport_t *) NULL);
2937 panelp = brdp->panels[panelnr];
2938 if (panelp == (stlpanel_t *) NULL)
2939 return((stlport_t *) NULL);
2940 if ((portnr < 0) || (portnr >= panelp->nrports))
2941 return((stlport_t *) NULL);
2942 return(panelp->ports[portnr]);
2945 /*****************************************************************************/
2948 * Return the port stats structure to user app. A NULL port struct
2949 * pointer passed in means that we need to find out from the app
2950 * what port to get stats for (used through board control device).
2953 static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
2955 unsigned char *head, *tail;
2956 unsigned long flags;
2959 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2961 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2963 if (portp == (stlport_t *) NULL)
2967 portp->stats.state = portp->istate;
2968 portp->stats.flags = portp->flags;
2969 portp->stats.hwid = portp->hwid;
2971 portp->stats.ttystate = 0;
2972 portp->stats.cflags = 0;
2973 portp->stats.iflags = 0;
2974 portp->stats.oflags = 0;
2975 portp->stats.lflags = 0;
2976 portp->stats.rxbuffered = 0;
2980 if (portp->tty != (struct tty_struct *) NULL) {
2981 if (portp->tty->driver_data == portp) {
2982 portp->stats.ttystate = portp->tty->flags;
2983 portp->stats.rxbuffered = portp->tty->flip.count;
2984 if (portp->tty->termios != (struct termios *) NULL) {
2985 portp->stats.cflags = portp->tty->termios->c_cflag;
2986 portp->stats.iflags = portp->tty->termios->c_iflag;
2987 portp->stats.oflags = portp->tty->termios->c_oflag;
2988 portp->stats.lflags = portp->tty->termios->c_lflag;
2992 restore_flags(flags);
2994 head = portp->tx.head;
2995 tail = portp->tx.tail;
2996 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2997 (STL_TXBUFSIZE - (tail - head)));
2999 portp->stats.signals = (unsigned long) stl_getsignals(portp);
3001 return copy_to_user(cp, &portp->stats,
3002 sizeof(comstats_t)) ? -EFAULT : 0;
3005 /*****************************************************************************/
3008 * Clear the port stats structure. We also return it zeroed out...
3011 static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp)
3014 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
3016 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
3018 if (portp == (stlport_t *) NULL)
3022 memset(&portp->stats, 0, sizeof(comstats_t));
3023 portp->stats.brd = portp->brdnr;
3024 portp->stats.panel = portp->panelnr;
3025 portp->stats.port = portp->portnr;
3026 return copy_to_user(cp, &portp->stats,
3027 sizeof(comstats_t)) ? -EFAULT : 0;
3030 /*****************************************************************************/
3033 * Return the entire driver ports structure to a user app.
3036 static int stl_getportstruct(stlport_t __user *arg)
3040 if (copy_from_user(&stl_dummyport, arg, sizeof(stlport_t)))
3042 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
3043 stl_dummyport.portnr);
3046 return copy_to_user(arg, portp, sizeof(stlport_t)) ? -EFAULT : 0;
3049 /*****************************************************************************/
3052 * Return the entire driver board structure to a user app.
3055 static int stl_getbrdstruct(stlbrd_t __user *arg)
3059 if (copy_from_user(&stl_dummybrd, arg, sizeof(stlbrd_t)))
3061 if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
3063 brdp = stl_brds[stl_dummybrd.brdnr];
3066 return copy_to_user(arg, brdp, sizeof(stlbrd_t)) ? -EFAULT : 0;
3069 /*****************************************************************************/
3072 * The "staliomem" device is also required to do some special operations
3073 * on the board and/or ports. In this driver it is mostly used for stats
3077 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
3080 void __user *argp = (void __user *)arg;
3083 printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
3084 (int) fp, cmd, (int) arg);
3088 if (brdnr >= STL_MAXBRDS)
3093 case COM_GETPORTSTATS:
3094 rc = stl_getportstats(NULL, argp);
3096 case COM_CLRPORTSTATS:
3097 rc = stl_clrportstats(NULL, argp);
3099 case COM_GETBRDSTATS:
3100 rc = stl_getbrdstats(argp);
3103 rc = stl_getportstruct(argp);
3106 rc = stl_getbrdstruct(argp);
3116 static struct tty_operations stl_ops = {
3120 .put_char = stl_putchar,
3121 .flush_chars = stl_flushchars,
3122 .write_room = stl_writeroom,
3123 .chars_in_buffer = stl_charsinbuffer,
3125 .set_termios = stl_settermios,
3126 .throttle = stl_throttle,
3127 .unthrottle = stl_unthrottle,
3130 .hangup = stl_hangup,
3131 .flush_buffer = stl_flushbuffer,
3132 .break_ctl = stl_breakctl,
3133 .wait_until_sent = stl_waituntilsent,
3134 .send_xchar = stl_sendxchar,
3135 .read_proc = stl_readproc,
3136 .tiocmget = stl_tiocmget,
3137 .tiocmset = stl_tiocmset,
3140 /*****************************************************************************/
3142 int __init stl_init(void)
3145 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
3149 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
3154 * Allocate a temporary write buffer.
3156 stl_tmpwritebuf = (char *) stl_memalloc(STL_TXBUFSIZE);
3157 if (stl_tmpwritebuf == (char *) NULL)
3158 printk("STALLION: failed to allocate memory (size=%d)\n",
3162 * Set up a character driver for per board stuff. This is mainly used
3163 * to do stats ioctls on the ports.
3165 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
3166 printk("STALLION: failed to register serial board device\n");
3167 devfs_mk_dir("staliomem");
3169 stallion_class = class_simple_create(THIS_MODULE, "staliomem");
3170 for (i = 0; i < 4; i++) {
3171 devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR, i),
3172 S_IFCHR|S_IRUSR|S_IWUSR,
3174 class_simple_device_add(stallion_class, MKDEV(STL_SIOMEMMAJOR, i), NULL, "staliomem%d", i);
3177 stl_serial->owner = THIS_MODULE;
3178 stl_serial->driver_name = stl_drvname;
3179 stl_serial->name = "ttyE";
3180 stl_serial->devfs_name = "tts/E";
3181 stl_serial->major = STL_SERIALMAJOR;
3182 stl_serial->minor_start = 0;
3183 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
3184 stl_serial->subtype = SERIAL_TYPE_NORMAL;
3185 stl_serial->init_termios = stl_deftermios;
3186 stl_serial->flags = TTY_DRIVER_REAL_RAW;
3187 tty_set_operations(stl_serial, &stl_ops);
3189 if (tty_register_driver(stl_serial)) {
3190 put_tty_driver(stl_serial);
3191 printk("STALLION: failed to register serial driver\n");
3198 /*****************************************************************************/
3199 /* CD1400 HARDWARE FUNCTIONS */
3200 /*****************************************************************************/
3203 * These functions get/set/update the registers of the cd1400 UARTs.
3204 * Access to the cd1400 registers is via an address/data io port pair.
3205 * (Maybe should make this inline...)
3208 static int stl_cd1400getreg(stlport_t *portp, int regnr)
3210 outb((regnr + portp->uartaddr), portp->ioaddr);
3211 return(inb(portp->ioaddr + EREG_DATA));
3214 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
3216 outb((regnr + portp->uartaddr), portp->ioaddr);
3217 outb(value, portp->ioaddr + EREG_DATA);
3220 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
3222 outb((regnr + portp->uartaddr), portp->ioaddr);
3223 if (inb(portp->ioaddr + EREG_DATA) != value) {
3224 outb(value, portp->ioaddr + EREG_DATA);
3230 /*****************************************************************************/
3233 * Inbitialize the UARTs in a panel. We don't care what sort of board
3234 * these ports are on - since the port io registers are almost
3235 * identical when dealing with ports.
3238 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3242 int nrchips, uartaddr, ioaddr;
3245 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
3248 BRDENABLE(panelp->brdnr, panelp->pagenr);
3251 * Check that each chip is present and started up OK.
3254 nrchips = panelp->nrports / CD1400_PORTS;
3255 for (i = 0; (i < nrchips); i++) {
3256 if (brdp->brdtype == BRD_ECHPCI) {
3257 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3258 ioaddr = panelp->iobase;
3260 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3262 uartaddr = (i & 0x01) ? 0x080 : 0;
3263 outb((GFRCR + uartaddr), ioaddr);
3264 outb(0, (ioaddr + EREG_DATA));
3265 outb((CCR + uartaddr), ioaddr);
3266 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3267 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3268 outb((GFRCR + uartaddr), ioaddr);
3269 for (j = 0; (j < CCR_MAXWAIT); j++) {
3270 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3273 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3274 printk("STALLION: cd1400 not responding, "
3275 "brd=%d panel=%d chip=%d\n",
3276 panelp->brdnr, panelp->panelnr, i);
3279 chipmask |= (0x1 << i);
3280 outb((PPR + uartaddr), ioaddr);
3281 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
3284 BRDDISABLE(panelp->brdnr);
3288 /*****************************************************************************/
3291 * Initialize hardware specific port registers.
3294 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3297 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3298 (int) brdp, (int) panelp, (int) portp);
3301 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
3302 (portp == (stlport_t *) NULL))
3305 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3306 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3307 portp->uartaddr = (portp->portnr & 0x04) << 5;
3308 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3310 BRDENABLE(portp->brdnr, portp->pagenr);
3311 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3312 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3313 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3314 BRDDISABLE(portp->brdnr);
3317 /*****************************************************************************/
3320 * Wait for the command register to be ready. We will poll this,
3321 * since it won't usually take too long to be ready.
3324 static void stl_cd1400ccrwait(stlport_t *portp)
3328 for (i = 0; (i < CCR_MAXWAIT); i++) {
3329 if (stl_cd1400getreg(portp, CCR) == 0) {
3334 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
3335 portp->portnr, portp->panelnr, portp->brdnr);
3338 /*****************************************************************************/
3341 * Set up the cd1400 registers for a port based on the termios port
3345 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3348 unsigned long flags;
3349 unsigned int clkdiv, baudrate;
3350 unsigned char cor1, cor2, cor3;
3351 unsigned char cor4, cor5, ccr;
3352 unsigned char srer, sreron, sreroff;
3353 unsigned char mcor1, mcor2, rtpr;
3354 unsigned char clk, div;
3370 brdp = stl_brds[portp->brdnr];
3371 if (brdp == (stlbrd_t *) NULL)
3375 * Set up the RX char ignore mask with those RX error types we
3376 * can ignore. We can get the cd1400 to help us out a little here,
3377 * it will ignore parity errors and breaks for us.
3379 portp->rxignoremsk = 0;
3380 if (tiosp->c_iflag & IGNPAR) {
3381 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
3382 cor1 |= COR1_PARIGNORE;
3384 if (tiosp->c_iflag & IGNBRK) {
3385 portp->rxignoremsk |= ST_BREAK;
3386 cor4 |= COR4_IGNBRK;
3389 portp->rxmarkmsk = ST_OVERRUN;
3390 if (tiosp->c_iflag & (INPCK | PARMRK))
3391 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3392 if (tiosp->c_iflag & BRKINT)
3393 portp->rxmarkmsk |= ST_BREAK;
3396 * Go through the char size, parity and stop bits and set all the
3397 * option register appropriately.
3399 switch (tiosp->c_cflag & CSIZE) {
3414 if (tiosp->c_cflag & CSTOPB)
3419 if (tiosp->c_cflag & PARENB) {
3420 if (tiosp->c_cflag & PARODD)
3421 cor1 |= (COR1_PARENB | COR1_PARODD);
3423 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3425 cor1 |= COR1_PARNONE;
3429 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3430 * space for hardware flow control and the like. This should be set to
3431 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3432 * really be based on VTIME.
3434 cor3 |= FIFO_RXTHRESHOLD;
3438 * Calculate the baud rate timers. For now we will just assume that
3439 * the input and output baud are the same. Could have used a baud
3440 * table here, but this way we can generate virtually any baud rate
3443 baudrate = tiosp->c_cflag & CBAUD;
3444 if (baudrate & CBAUDEX) {
3445 baudrate &= ~CBAUDEX;
3446 if ((baudrate < 1) || (baudrate > 4))
3447 tiosp->c_cflag &= ~CBAUDEX;
3451 baudrate = stl_baudrates[baudrate];
3452 if ((tiosp->c_cflag & CBAUD) == B38400) {
3453 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3455 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3457 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3459 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3461 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3462 baudrate = (portp->baud_base / portp->custom_divisor);
3464 if (baudrate > STL_CD1400MAXBAUD)
3465 baudrate = STL_CD1400MAXBAUD;
3468 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3469 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
3473 div = (unsigned char) clkdiv;
3477 * Check what form of modem signaling is required and set it up.
3479 if ((tiosp->c_cflag & CLOCAL) == 0) {
3482 sreron |= SRER_MODEM;
3483 portp->flags |= ASYNC_CHECK_CD;
3485 portp->flags &= ~ASYNC_CHECK_CD;
3489 * Setup cd1400 enhanced modes if we can. In particular we want to
3490 * handle as much of the flow control as possible automatically. As
3491 * well as saving a few CPU cycles it will also greatly improve flow
3492 * control reliability.
3494 if (tiosp->c_iflag & IXON) {
3497 if (tiosp->c_iflag & IXANY)
3501 if (tiosp->c_cflag & CRTSCTS) {
3503 mcor1 |= FIFO_RTSTHRESHOLD;
3507 * All cd1400 register values calculated so go through and set
3512 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3513 portp->portnr, portp->panelnr, portp->brdnr);
3514 printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3515 cor1, cor2, cor3, cor4, cor5);
3516 printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3517 mcor1, mcor2, rtpr, sreron, sreroff);
3518 printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3519 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3520 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3521 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3526 BRDENABLE(portp->brdnr, portp->pagenr);
3527 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3528 srer = stl_cd1400getreg(portp, SRER);
3529 stl_cd1400setreg(portp, SRER, 0);
3530 if (stl_cd1400updatereg(portp, COR1, cor1))
3532 if (stl_cd1400updatereg(portp, COR2, cor2))
3534 if (stl_cd1400updatereg(portp, COR3, cor3))
3537 stl_cd1400ccrwait(portp);
3538 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3540 stl_cd1400setreg(portp, COR4, cor4);
3541 stl_cd1400setreg(portp, COR5, cor5);
3542 stl_cd1400setreg(portp, MCOR1, mcor1);
3543 stl_cd1400setreg(portp, MCOR2, mcor2);
3545 stl_cd1400setreg(portp, TCOR, clk);
3546 stl_cd1400setreg(portp, TBPR, div);
3547 stl_cd1400setreg(portp, RCOR, clk);
3548 stl_cd1400setreg(portp, RBPR, div);
3550 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3551 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3552 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3553 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3554 stl_cd1400setreg(portp, RTPR, rtpr);
3555 mcor1 = stl_cd1400getreg(portp, MSVR1);
3556 if (mcor1 & MSVR1_DCD)
3557 portp->sigs |= TIOCM_CD;
3559 portp->sigs &= ~TIOCM_CD;
3560 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3561 BRDDISABLE(portp->brdnr);
3562 restore_flags(flags);
3565 /*****************************************************************************/
3568 * Set the state of the DTR and RTS signals.
3571 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3573 unsigned char msvr1, msvr2;
3574 unsigned long flags;
3577 printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
3578 (int) portp, dtr, rts);
3590 BRDENABLE(portp->brdnr, portp->pagenr);
3591 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3593 stl_cd1400setreg(portp, MSVR2, msvr2);
3595 stl_cd1400setreg(portp, MSVR1, msvr1);
3596 BRDDISABLE(portp->brdnr);
3597 restore_flags(flags);
3600 /*****************************************************************************/
3603 * Return the state of the signals.
3606 static int stl_cd1400getsignals(stlport_t *portp)
3608 unsigned char msvr1, msvr2;
3609 unsigned long flags;
3613 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3618 BRDENABLE(portp->brdnr, portp->pagenr);
3619 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3620 msvr1 = stl_cd1400getreg(portp, MSVR1);
3621 msvr2 = stl_cd1400getreg(portp, MSVR2);
3622 BRDDISABLE(portp->brdnr);
3623 restore_flags(flags);
3626 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3627 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3628 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3629 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3631 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3632 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3639 /*****************************************************************************/
3642 * Enable/Disable the Transmitter and/or Receiver.
3645 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3648 unsigned long flags;
3651 printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3652 (int) portp, rx, tx);
3657 ccr |= CCR_TXDISABLE;
3659 ccr |= CCR_TXENABLE;
3661 ccr |= CCR_RXDISABLE;
3663 ccr |= CCR_RXENABLE;
3667 BRDENABLE(portp->brdnr, portp->pagenr);
3668 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3669 stl_cd1400ccrwait(portp);
3670 stl_cd1400setreg(portp, CCR, ccr);
3671 stl_cd1400ccrwait(portp);
3672 BRDDISABLE(portp->brdnr);
3673 restore_flags(flags);
3676 /*****************************************************************************/
3679 * Start/stop the Transmitter and/or Receiver.
3682 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3684 unsigned char sreron, sreroff;
3685 unsigned long flags;
3688 printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3689 (int) portp, rx, tx);
3695 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3697 sreron |= SRER_TXDATA;
3699 sreron |= SRER_TXEMPTY;
3701 sreroff |= SRER_RXDATA;
3703 sreron |= SRER_RXDATA;
3707 BRDENABLE(portp->brdnr, portp->pagenr);
3708 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3709 stl_cd1400setreg(portp, SRER,
3710 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3711 BRDDISABLE(portp->brdnr);
3713 set_bit(ASYI_TXBUSY, &portp->istate);
3714 restore_flags(flags);
3717 /*****************************************************************************/
3720 * Disable all interrupts from this port.
3723 static void stl_cd1400disableintrs(stlport_t *portp)
3725 unsigned long flags;
3728 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3732 BRDENABLE(portp->brdnr, portp->pagenr);
3733 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3734 stl_cd1400setreg(portp, SRER, 0);
3735 BRDDISABLE(portp->brdnr);
3736 restore_flags(flags);
3739 /*****************************************************************************/
3741 static void stl_cd1400sendbreak(stlport_t *portp, int len)
3743 unsigned long flags;
3746 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
3751 BRDENABLE(portp->brdnr, portp->pagenr);
3752 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3753 stl_cd1400setreg(portp, SRER,
3754 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3756 BRDDISABLE(portp->brdnr);
3757 portp->brklen = len;
3759 portp->stats.txbreaks++;
3760 restore_flags(flags);
3763 /*****************************************************************************/
3766 * Take flow control actions...
3769 static void stl_cd1400flowctrl(stlport_t *portp, int state)
3771 struct tty_struct *tty;
3772 unsigned long flags;
3775 printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp, state);
3778 if (portp == (stlport_t *) NULL)
3781 if (tty == (struct tty_struct *) NULL)
3786 BRDENABLE(portp->brdnr, portp->pagenr);
3787 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3790 if (tty->termios->c_iflag & IXOFF) {
3791 stl_cd1400ccrwait(portp);
3792 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3793 portp->stats.rxxon++;
3794 stl_cd1400ccrwait(portp);
3797 * Question: should we return RTS to what it was before? It may
3798 * have been set by an ioctl... Suppose not, since if you have
3799 * hardware flow control set then it is pretty silly to go and
3800 * set the RTS line by hand.
3802 if (tty->termios->c_cflag & CRTSCTS) {
3803 stl_cd1400setreg(portp, MCOR1,
3804 (stl_cd1400getreg(portp, MCOR1) |
3805 FIFO_RTSTHRESHOLD));
3806 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3807 portp->stats.rxrtson++;
3810 if (tty->termios->c_iflag & IXOFF) {
3811 stl_cd1400ccrwait(portp);
3812 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3813 portp->stats.rxxoff++;
3814 stl_cd1400ccrwait(portp);
3816 if (tty->termios->c_cflag & CRTSCTS) {
3817 stl_cd1400setreg(portp, MCOR1,
3818 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3819 stl_cd1400setreg(portp, MSVR2, 0);
3820 portp->stats.rxrtsoff++;
3824 BRDDISABLE(portp->brdnr);
3825 restore_flags(flags);
3828 /*****************************************************************************/
3831 * Send a flow control character...
3834 static void stl_cd1400sendflow(stlport_t *portp, int state)
3836 struct tty_struct *tty;
3837 unsigned long flags;
3840 printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp, state);
3843 if (portp == (stlport_t *) NULL)
3846 if (tty == (struct tty_struct *) NULL)
3851 BRDENABLE(portp->brdnr, portp->pagenr);
3852 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3854 stl_cd1400ccrwait(portp);
3855 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3856 portp->stats.rxxon++;
3857 stl_cd1400ccrwait(portp);
3859 stl_cd1400ccrwait(portp);
3860 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3861 portp->stats.rxxoff++;
3862 stl_cd1400ccrwait(portp);
3864 BRDDISABLE(portp->brdnr);
3865 restore_flags(flags);
3868 /*****************************************************************************/
3870 static void stl_cd1400flush(stlport_t *portp)
3872 unsigned long flags;
3875 printk("stl_cd1400flush(portp=%x)\n", (int) portp);
3878 if (portp == (stlport_t *) NULL)
3883 BRDENABLE(portp->brdnr, portp->pagenr);
3884 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3885 stl_cd1400ccrwait(portp);
3886 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3887 stl_cd1400ccrwait(portp);
3888 portp->tx.tail = portp->tx.head;
3889 BRDDISABLE(portp->brdnr);
3890 restore_flags(flags);
3893 /*****************************************************************************/
3896 * Return the current state of data flow on this port. This is only
3897 * really interresting when determining if data has fully completed
3898 * transmission or not... This is easy for the cd1400, it accurately
3899 * maintains the busy port flag.
3902 static int stl_cd1400datastate(stlport_t *portp)
3905 printk("stl_cd1400datastate(portp=%x)\n", (int) portp);
3908 if (portp == (stlport_t *) NULL)
3911 return(test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0);
3914 /*****************************************************************************/
3917 * Interrupt service routine for cd1400 EasyIO boards.
3920 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3922 unsigned char svrtype;
3925 printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
3926 (int) panelp, iobase);
3930 svrtype = inb(iobase + EREG_DATA);
3931 if (panelp->nrports > 4) {
3932 outb((SVRR + 0x80), iobase);
3933 svrtype |= inb(iobase + EREG_DATA);
3936 if (svrtype & SVRR_RX)
3937 stl_cd1400rxisr(panelp, iobase);
3938 else if (svrtype & SVRR_TX)
3939 stl_cd1400txisr(panelp, iobase);
3940 else if (svrtype & SVRR_MDM)
3941 stl_cd1400mdmisr(panelp, iobase);
3944 /*****************************************************************************/
3947 * Interrupt service routine for cd1400 panels.
3950 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
3952 unsigned char svrtype;
3955 printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
3960 svrtype = inb(iobase + EREG_DATA);
3961 outb((SVRR + 0x80), iobase);
3962 svrtype |= inb(iobase + EREG_DATA);
3963 if (svrtype & SVRR_RX)
3964 stl_cd1400rxisr(panelp, iobase);
3965 else if (svrtype & SVRR_TX)
3966 stl_cd1400txisr(panelp, iobase);
3967 else if (svrtype & SVRR_MDM)
3968 stl_cd1400mdmisr(panelp, iobase);
3972 /*****************************************************************************/
3975 * Unfortunately we need to handle breaks in the TX data stream, since
3976 * this is the only way to generate them on the cd1400.
3979 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr)
3981 if (portp->brklen == 1) {
3982 outb((COR2 + portp->uartaddr), ioaddr);
3983 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
3984 (ioaddr + EREG_DATA));
3985 outb((TDR + portp->uartaddr), ioaddr);
3986 outb(ETC_CMD, (ioaddr + EREG_DATA));
3987 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
3988 outb((SRER + portp->uartaddr), ioaddr);
3989 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
3990 (ioaddr + EREG_DATA));
3992 } else if (portp->brklen > 1) {
3993 outb((TDR + portp->uartaddr), ioaddr);
3994 outb(ETC_CMD, (ioaddr + EREG_DATA));
3995 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
3999 outb((COR2 + portp->uartaddr), ioaddr);
4000 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
4001 (ioaddr + EREG_DATA));
4007 /*****************************************************************************/
4010 * Transmit interrupt handler. This has gotta be fast! Handling TX
4011 * chars is pretty simple, stuff as many as possible from the TX buffer
4012 * into the cd1400 FIFO. Must also handle TX breaks here, since they
4013 * are embedded as commands in the data stream. Oh no, had to use a goto!
4014 * This could be optimized more, will do when I get time...
4015 * In practice it is possible that interrupts are enabled but that the
4016 * port has been hung up. Need to handle not having any TX buffer here,
4017 * this is done by using the side effect that head and tail will also
4018 * be NULL if the buffer has been freed.
4021 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
4026 unsigned char ioack, srer;
4029 printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
4032 ioack = inb(ioaddr + EREG_TXACK);
4033 if (((ioack & panelp->ackmask) != 0) ||
4034 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
4035 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
4038 portp = panelp->ports[(ioack >> 3)];
4041 * Unfortunately we need to handle breaks in the data stream, since
4042 * this is the only way to generate them on the cd1400. Do it now if
4043 * a break is to be sent.
4045 if (portp->brklen != 0)
4046 if (stl_cd1400breakisr(portp, ioaddr))
4049 head = portp->tx.head;
4050 tail = portp->tx.tail;
4051 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4052 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4053 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4054 set_bit(ASYI_TXLOW, &portp->istate);
4055 schedule_work(&portp->tqueue);
4059 outb((SRER + portp->uartaddr), ioaddr);
4060 srer = inb(ioaddr + EREG_DATA);
4061 if (srer & SRER_TXDATA) {
4062 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
4064 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
4065 clear_bit(ASYI_TXBUSY, &portp->istate);
4067 outb(srer, (ioaddr + EREG_DATA));
4069 len = MIN(len, CD1400_TXFIFOSIZE);
4070 portp->stats.txtotal += len;
4071 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4072 outb((TDR + portp->uartaddr), ioaddr);
4073 outsb((ioaddr + EREG_DATA), tail, stlen);
4076 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4077 tail = portp->tx.buf;
4079 outsb((ioaddr + EREG_DATA), tail, len);
4082 portp->tx.tail = tail;
4086 outb((EOSRR + portp->uartaddr), ioaddr);
4087 outb(0, (ioaddr + EREG_DATA));
4090 /*****************************************************************************/
4093 * Receive character interrupt handler. Determine if we have good chars
4094 * or bad chars and then process appropriately. Good chars are easy
4095 * just shove the lot into the RX buffer and set all status byte to 0.
4096 * If a bad RX char then process as required. This routine needs to be
4097 * fast! In practice it is possible that we get an interrupt on a port
4098 * that is closed. This can happen on hangups - since they completely
4099 * shutdown a port not in user context. Need to handle this case.
4102 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
4105 struct tty_struct *tty;
4106 unsigned int ioack, len, buflen;
4107 unsigned char status;
4111 printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
4114 ioack = inb(ioaddr + EREG_RXACK);
4115 if ((ioack & panelp->ackmask) != 0) {
4116 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4119 portp = panelp->ports[(ioack >> 3)];
4122 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
4123 outb((RDCR + portp->uartaddr), ioaddr);
4124 len = inb(ioaddr + EREG_DATA);
4125 if ((tty == (struct tty_struct *) NULL) ||
4126 (tty->flip.char_buf_ptr == (char *) NULL) ||
4127 ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
4128 len = MIN(len, sizeof(stl_unwanted));
4129 outb((RDSR + portp->uartaddr), ioaddr);
4130 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
4131 portp->stats.rxlost += len;
4132 portp->stats.rxtotal += len;
4134 len = MIN(len, buflen);
4136 outb((RDSR + portp->uartaddr), ioaddr);
4137 insb((ioaddr + EREG_DATA), tty->flip.char_buf_ptr, len);
4138 memset(tty->flip.flag_buf_ptr, 0, len);
4139 tty->flip.flag_buf_ptr += len;
4140 tty->flip.char_buf_ptr += len;
4141 tty->flip.count += len;
4142 tty_schedule_flip(tty);
4143 portp->stats.rxtotal += len;
4146 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
4147 outb((RDSR + portp->uartaddr), ioaddr);
4148 status = inb(ioaddr + EREG_DATA);
4149 ch = inb(ioaddr + EREG_DATA);
4150 if (status & ST_PARITY)
4151 portp->stats.rxparity++;
4152 if (status & ST_FRAMING)
4153 portp->stats.rxframing++;
4154 if (status & ST_OVERRUN)
4155 portp->stats.rxoverrun++;
4156 if (status & ST_BREAK)
4157 portp->stats.rxbreaks++;
4158 if (status & ST_SCHARMASK) {
4159 if ((status & ST_SCHARMASK) == ST_SCHAR1)
4160 portp->stats.txxon++;
4161 if ((status & ST_SCHARMASK) == ST_SCHAR2)
4162 portp->stats.txxoff++;
4165 if ((tty != (struct tty_struct *) NULL) &&
4166 ((portp->rxignoremsk & status) == 0)) {
4167 if (portp->rxmarkmsk & status) {
4168 if (status & ST_BREAK) {
4170 if (portp->flags & ASYNC_SAK) {
4172 BRDENABLE(portp->brdnr, portp->pagenr);
4174 } else if (status & ST_PARITY) {
4175 status = TTY_PARITY;
4176 } else if (status & ST_FRAMING) {
4178 } else if(status & ST_OVERRUN) {
4179 status = TTY_OVERRUN;
4186 if (tty->flip.char_buf_ptr != (char *) NULL) {
4187 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
4188 *tty->flip.flag_buf_ptr++ = status;
4189 *tty->flip.char_buf_ptr++ = ch;
4192 tty_schedule_flip(tty);
4196 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4201 outb((EOSRR + portp->uartaddr), ioaddr);
4202 outb(0, (ioaddr + EREG_DATA));
4205 /*****************************************************************************/
4208 * Modem interrupt handler. The is called when the modem signal line
4209 * (DCD) has changed state. Leave most of the work to the off-level
4210 * processing routine.
4213 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
4220 printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp);
4223 ioack = inb(ioaddr + EREG_MDACK);
4224 if (((ioack & panelp->ackmask) != 0) ||
4225 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
4226 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
4229 portp = panelp->ports[(ioack >> 3)];
4231 outb((MISR + portp->uartaddr), ioaddr);
4232 misr = inb(ioaddr + EREG_DATA);
4233 if (misr & MISR_DCD) {
4234 set_bit(ASYI_DCDCHANGE, &portp->istate);
4235 schedule_work(&portp->tqueue);
4236 portp->stats.modem++;
4239 outb((EOSRR + portp->uartaddr), ioaddr);
4240 outb(0, (ioaddr + EREG_DATA));
4243 /*****************************************************************************/
4244 /* SC26198 HARDWARE FUNCTIONS */
4245 /*****************************************************************************/
4248 * These functions get/set/update the registers of the sc26198 UARTs.
4249 * Access to the sc26198 registers is via an address/data io port pair.
4250 * (Maybe should make this inline...)
4253 static int stl_sc26198getreg(stlport_t *portp, int regnr)
4255 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4256 return(inb(portp->ioaddr + XP_DATA));
4259 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
4261 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4262 outb(value, (portp->ioaddr + XP_DATA));
4265 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
4267 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4268 if (inb(portp->ioaddr + XP_DATA) != value) {
4269 outb(value, (portp->ioaddr + XP_DATA));
4275 /*****************************************************************************/
4278 * Functions to get and set the sc26198 global registers.
4281 static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
4283 outb(regnr, (portp->ioaddr + XP_ADDR));
4284 return(inb(portp->ioaddr + XP_DATA));
4288 static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
4290 outb(regnr, (portp->ioaddr + XP_ADDR));
4291 outb(value, (portp->ioaddr + XP_DATA));
4295 /*****************************************************************************/
4298 * Inbitialize the UARTs in a panel. We don't care what sort of board
4299 * these ports are on - since the port io registers are almost
4300 * identical when dealing with ports.
4303 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
4306 int nrchips, ioaddr;
4309 printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
4310 (int) brdp, (int) panelp);
4313 BRDENABLE(panelp->brdnr, panelp->pagenr);
4316 * Check that each chip is present and started up OK.
4319 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
4320 if (brdp->brdtype == BRD_ECHPCI)
4321 outb(panelp->pagenr, brdp->ioctrl);
4323 for (i = 0; (i < nrchips); i++) {
4324 ioaddr = panelp->iobase + (i * 4);
4325 outb(SCCR, (ioaddr + XP_ADDR));
4326 outb(CR_RESETALL, (ioaddr + XP_DATA));
4327 outb(TSTR, (ioaddr + XP_ADDR));
4328 if (inb(ioaddr + XP_DATA) != 0) {
4329 printk("STALLION: sc26198 not responding, "
4330 "brd=%d panel=%d chip=%d\n",
4331 panelp->brdnr, panelp->panelnr, i);
4334 chipmask |= (0x1 << i);
4335 outb(GCCR, (ioaddr + XP_ADDR));
4336 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
4337 outb(WDTRCR, (ioaddr + XP_ADDR));
4338 outb(0xff, (ioaddr + XP_DATA));
4341 BRDDISABLE(panelp->brdnr);
4345 /*****************************************************************************/
4348 * Initialize hardware specific port registers.
4351 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
4354 printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
4355 (int) brdp, (int) panelp, (int) portp);
4358 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
4359 (portp == (stlport_t *) NULL))
4362 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
4363 portp->uartaddr = (portp->portnr & 0x07) << 4;
4364 portp->pagenr = panelp->pagenr;
4367 BRDENABLE(portp->brdnr, portp->pagenr);
4368 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
4369 BRDDISABLE(portp->brdnr);
4372 /*****************************************************************************/
4375 * Set up the sc26198 registers for a port based on the termios port
4379 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4382 unsigned long flags;
4383 unsigned int baudrate;
4384 unsigned char mr0, mr1, mr2, clk;
4385 unsigned char imron, imroff, iopr, ipr;
4395 brdp = stl_brds[portp->brdnr];
4396 if (brdp == (stlbrd_t *) NULL)
4400 * Set up the RX char ignore mask with those RX error types we
4403 portp->rxignoremsk = 0;
4404 if (tiosp->c_iflag & IGNPAR)
4405 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
4407 if (tiosp->c_iflag & IGNBRK)
4408 portp->rxignoremsk |= SR_RXBREAK;
4410 portp->rxmarkmsk = SR_RXOVERRUN;
4411 if (tiosp->c_iflag & (INPCK | PARMRK))
4412 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
4413 if (tiosp->c_iflag & BRKINT)
4414 portp->rxmarkmsk |= SR_RXBREAK;
4417 * Go through the char size, parity and stop bits and set all the
4418 * option register appropriately.
4420 switch (tiosp->c_cflag & CSIZE) {
4435 if (tiosp->c_cflag & CSTOPB)
4440 if (tiosp->c_cflag & PARENB) {
4441 if (tiosp->c_cflag & PARODD)
4442 mr1 |= (MR1_PARENB | MR1_PARODD);
4444 mr1 |= (MR1_PARENB | MR1_PAREVEN);
4449 mr1 |= MR1_ERRBLOCK;
4452 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4453 * space for hardware flow control and the like. This should be set to
4456 mr2 |= MR2_RXFIFOHALF;
4459 * Calculate the baud rate timers. For now we will just assume that
4460 * the input and output baud are the same. The sc26198 has a fixed
4461 * baud rate table, so only discrete baud rates possible.
4463 baudrate = tiosp->c_cflag & CBAUD;
4464 if (baudrate & CBAUDEX) {
4465 baudrate &= ~CBAUDEX;
4466 if ((baudrate < 1) || (baudrate > 4))
4467 tiosp->c_cflag &= ~CBAUDEX;
4471 baudrate = stl_baudrates[baudrate];
4472 if ((tiosp->c_cflag & CBAUD) == B38400) {
4473 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
4475 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
4477 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
4479 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
4481 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
4482 baudrate = (portp->baud_base / portp->custom_divisor);
4484 if (baudrate > STL_SC26198MAXBAUD)
4485 baudrate = STL_SC26198MAXBAUD;
4488 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
4489 if (baudrate <= sc26198_baudtable[clk])
4495 * Check what form of modem signaling is required and set it up.
4497 if (tiosp->c_cflag & CLOCAL) {
4498 portp->flags &= ~ASYNC_CHECK_CD;
4500 iopr |= IOPR_DCDCOS;
4502 portp->flags |= ASYNC_CHECK_CD;
4506 * Setup sc26198 enhanced modes if we can. In particular we want to
4507 * handle as much of the flow control as possible automatically. As
4508 * well as saving a few CPU cycles it will also greatly improve flow
4509 * control reliability.
4511 if (tiosp->c_iflag & IXON) {
4512 mr0 |= MR0_SWFTX | MR0_SWFT;
4513 imron |= IR_XONXOFF;
4515 imroff |= IR_XONXOFF;
4517 if (tiosp->c_iflag & IXOFF)
4520 if (tiosp->c_cflag & CRTSCTS) {
4526 * All sc26198 register values calculated so go through and set
4531 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4532 portp->portnr, portp->panelnr, portp->brdnr);
4533 printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4534 printk(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4535 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4536 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4537 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4542 BRDENABLE(portp->brdnr, portp->pagenr);
4543 stl_sc26198setreg(portp, IMR, 0);
4544 stl_sc26198updatereg(portp, MR0, mr0);
4545 stl_sc26198updatereg(portp, MR1, mr1);
4546 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4547 stl_sc26198updatereg(portp, MR2, mr2);
4548 stl_sc26198updatereg(portp, IOPIOR,
4549 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
4552 stl_sc26198setreg(portp, TXCSR, clk);
4553 stl_sc26198setreg(portp, RXCSR, clk);
4556 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4557 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4559 ipr = stl_sc26198getreg(portp, IPR);
4561 portp->sigs &= ~TIOCM_CD;
4563 portp->sigs |= TIOCM_CD;
4565 portp->imr = (portp->imr & ~imroff) | imron;
4566 stl_sc26198setreg(portp, IMR, portp->imr);
4567 BRDDISABLE(portp->brdnr);
4568 restore_flags(flags);
4571 /*****************************************************************************/
4574 * Set the state of the DTR and RTS signals.
4577 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
4579 unsigned char iopioron, iopioroff;
4580 unsigned long flags;
4583 printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4584 (int) portp, dtr, rts);
4590 iopioroff |= IPR_DTR;
4592 iopioron |= IPR_DTR;
4594 iopioroff |= IPR_RTS;
4596 iopioron |= IPR_RTS;
4600 BRDENABLE(portp->brdnr, portp->pagenr);
4601 stl_sc26198setreg(portp, IOPIOR,
4602 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4603 BRDDISABLE(portp->brdnr);
4604 restore_flags(flags);
4607 /*****************************************************************************/
4610 * Return the state of the signals.
4613 static int stl_sc26198getsignals(stlport_t *portp)
4616 unsigned long flags;
4620 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
4625 BRDENABLE(portp->brdnr, portp->pagenr);
4626 ipr = stl_sc26198getreg(portp, IPR);
4627 BRDDISABLE(portp->brdnr);
4628 restore_flags(flags);
4631 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4632 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4633 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4634 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4639 /*****************************************************************************/
4642 * Enable/Disable the Transmitter and/or Receiver.
4645 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
4648 unsigned long flags;
4651 printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4652 (int) portp, rx, tx);
4655 ccr = portp->crenable;
4657 ccr &= ~CR_TXENABLE;
4661 ccr &= ~CR_RXENABLE;
4667 BRDENABLE(portp->brdnr, portp->pagenr);
4668 stl_sc26198setreg(portp, SCCR, ccr);
4669 BRDDISABLE(portp->brdnr);
4670 portp->crenable = ccr;
4671 restore_flags(flags);
4674 /*****************************************************************************/
4677 * Start/stop the Transmitter and/or Receiver.
4680 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
4683 unsigned long flags;
4686 printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4687 (int) portp, rx, tx);
4696 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4698 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4702 BRDENABLE(portp->brdnr, portp->pagenr);
4703 stl_sc26198setreg(portp, IMR, imr);
4704 BRDDISABLE(portp->brdnr);
4707 set_bit(ASYI_TXBUSY, &portp->istate);
4708 restore_flags(flags);
4711 /*****************************************************************************/
4714 * Disable all interrupts from this port.
4717 static void stl_sc26198disableintrs(stlport_t *portp)
4719 unsigned long flags;
4722 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
4727 BRDENABLE(portp->brdnr, portp->pagenr);
4729 stl_sc26198setreg(portp, IMR, 0);
4730 BRDDISABLE(portp->brdnr);
4731 restore_flags(flags);
4734 /*****************************************************************************/
4736 static void stl_sc26198sendbreak(stlport_t *portp, int len)
4738 unsigned long flags;
4741 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
4746 BRDENABLE(portp->brdnr, portp->pagenr);
4748 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4749 portp->stats.txbreaks++;
4751 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4753 BRDDISABLE(portp->brdnr);
4754 restore_flags(flags);
4757 /*****************************************************************************/
4760 * Take flow control actions...
4763 static void stl_sc26198flowctrl(stlport_t *portp, int state)
4765 struct tty_struct *tty;
4766 unsigned long flags;
4770 printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp, state);
4773 if (portp == (stlport_t *) NULL)
4776 if (tty == (struct tty_struct *) NULL)
4781 BRDENABLE(portp->brdnr, portp->pagenr);
4784 if (tty->termios->c_iflag & IXOFF) {
4785 mr0 = stl_sc26198getreg(portp, MR0);
4786 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4787 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4789 portp->stats.rxxon++;
4790 stl_sc26198wait(portp);
4791 stl_sc26198setreg(portp, MR0, mr0);
4794 * Question: should we return RTS to what it was before? It may
4795 * have been set by an ioctl... Suppose not, since if you have
4796 * hardware flow control set then it is pretty silly to go and
4797 * set the RTS line by hand.
4799 if (tty->termios->c_cflag & CRTSCTS) {
4800 stl_sc26198setreg(portp, MR1,
4801 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4802 stl_sc26198setreg(portp, IOPIOR,
4803 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4804 portp->stats.rxrtson++;
4807 if (tty->termios->c_iflag & IXOFF) {
4808 mr0 = stl_sc26198getreg(portp, MR0);
4809 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4810 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4812 portp->stats.rxxoff++;
4813 stl_sc26198wait(portp);
4814 stl_sc26198setreg(portp, MR0, mr0);
4816 if (tty->termios->c_cflag & CRTSCTS) {
4817 stl_sc26198setreg(portp, MR1,
4818 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4819 stl_sc26198setreg(portp, IOPIOR,
4820 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4821 portp->stats.rxrtsoff++;
4825 BRDDISABLE(portp->brdnr);
4826 restore_flags(flags);
4829 /*****************************************************************************/
4832 * Send a flow control character.
4835 static void stl_sc26198sendflow(stlport_t *portp, int state)
4837 struct tty_struct *tty;
4838 unsigned long flags;
4842 printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp, state);
4845 if (portp == (stlport_t *) NULL)
4848 if (tty == (struct tty_struct *) NULL)
4853 BRDENABLE(portp->brdnr, portp->pagenr);
4855 mr0 = stl_sc26198getreg(portp, MR0);
4856 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4857 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4859 portp->stats.rxxon++;
4860 stl_sc26198wait(portp);
4861 stl_sc26198setreg(portp, MR0, mr0);
4863 mr0 = stl_sc26198getreg(portp, MR0);
4864 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4865 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4867 portp->stats.rxxoff++;
4868 stl_sc26198wait(portp);
4869 stl_sc26198setreg(portp, MR0, mr0);
4871 BRDDISABLE(portp->brdnr);
4872 restore_flags(flags);
4875 /*****************************************************************************/
4877 static void stl_sc26198flush(stlport_t *portp)
4879 unsigned long flags;
4882 printk("stl_sc26198flush(portp=%x)\n", (int) portp);
4885 if (portp == (stlport_t *) NULL)
4890 BRDENABLE(portp->brdnr, portp->pagenr);
4891 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4892 stl_sc26198setreg(portp, SCCR, portp->crenable);
4893 BRDDISABLE(portp->brdnr);
4894 portp->tx.tail = portp->tx.head;
4895 restore_flags(flags);
4898 /*****************************************************************************/
4901 * Return the current state of data flow on this port. This is only
4902 * really interresting when determining if data has fully completed
4903 * transmission or not... The sc26198 interrupt scheme cannot
4904 * determine when all data has actually drained, so we need to
4905 * check the port statusy register to be sure.
4908 static int stl_sc26198datastate(stlport_t *portp)
4910 unsigned long flags;
4914 printk("stl_sc26198datastate(portp=%x)\n", (int) portp);
4917 if (portp == (stlport_t *) NULL)
4919 if (test_bit(ASYI_TXBUSY, &portp->istate))
4924 BRDENABLE(portp->brdnr, portp->pagenr);
4925 sr = stl_sc26198getreg(portp, SR);
4926 BRDDISABLE(portp->brdnr);
4927 restore_flags(flags);
4929 return((sr & SR_TXEMPTY) ? 0 : 1);
4932 /*****************************************************************************/
4935 * Delay for a small amount of time, to give the sc26198 a chance
4936 * to process a command...
4939 static void stl_sc26198wait(stlport_t *portp)
4944 printk("stl_sc26198wait(portp=%x)\n", (int) portp);
4947 if (portp == (stlport_t *) NULL)
4950 for (i = 0; (i < 20); i++)
4951 stl_sc26198getglobreg(portp, TSTR);
4954 /*****************************************************************************/
4957 * If we are TX flow controlled and in IXANY mode then we may
4958 * need to unflow control here. We gotta do this because of the
4959 * automatic flow control modes of the sc26198.
4962 static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty)
4966 mr0 = stl_sc26198getreg(portp, MR0);
4967 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4968 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4969 stl_sc26198wait(portp);
4970 stl_sc26198setreg(portp, MR0, mr0);
4971 clear_bit(ASYI_TXFLOWED, &portp->istate);
4974 /*****************************************************************************/
4977 * Interrupt service routine for sc26198 panels.
4980 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4986 * Work around bug in sc26198 chip... Cannot have A6 address
4987 * line of UART high, else iack will be returned as 0.
4989 outb(0, (iobase + 1));
4991 iack = inb(iobase + XP_IACK);
4992 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4994 if (iack & IVR_RXDATA)
4995 stl_sc26198rxisr(portp, iack);
4996 else if (iack & IVR_TXDATA)
4997 stl_sc26198txisr(portp);
4999 stl_sc26198otherisr(portp, iack);
5002 /*****************************************************************************/
5005 * Transmit interrupt handler. This has gotta be fast! Handling TX
5006 * chars is pretty simple, stuff as many as possible from the TX buffer
5007 * into the sc26198 FIFO.
5008 * In practice it is possible that interrupts are enabled but that the
5009 * port has been hung up. Need to handle not having any TX buffer here,
5010 * this is done by using the side effect that head and tail will also
5011 * be NULL if the buffer has been freed.
5014 static void stl_sc26198txisr(stlport_t *portp)
5016 unsigned int ioaddr;
5022 printk("stl_sc26198txisr(portp=%x)\n", (int) portp);
5025 ioaddr = portp->ioaddr;
5026 head = portp->tx.head;
5027 tail = portp->tx.tail;
5028 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
5029 if ((len == 0) || ((len < STL_TXBUFLOW) &&
5030 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
5031 set_bit(ASYI_TXLOW, &portp->istate);
5032 schedule_work(&portp->tqueue);
5036 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
5037 mr0 = inb(ioaddr + XP_DATA);
5038 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
5039 portp->imr &= ~IR_TXRDY;
5040 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
5041 outb(portp->imr, (ioaddr + XP_DATA));
5042 clear_bit(ASYI_TXBUSY, &portp->istate);
5044 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
5045 outb(mr0, (ioaddr + XP_DATA));
5048 len = MIN(len, SC26198_TXFIFOSIZE);
5049 portp->stats.txtotal += len;
5050 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
5051 outb(GTXFIFO, (ioaddr + XP_ADDR));
5052 outsb((ioaddr + XP_DATA), tail, stlen);
5055 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
5056 tail = portp->tx.buf;
5058 outsb((ioaddr + XP_DATA), tail, len);
5061 portp->tx.tail = tail;
5065 /*****************************************************************************/
5068 * Receive character interrupt handler. Determine if we have good chars
5069 * or bad chars and then process appropriately. Good chars are easy
5070 * just shove the lot into the RX buffer and set all status byte to 0.
5071 * If a bad RX char then process as required. This routine needs to be
5072 * fast! In practice it is possible that we get an interrupt on a port
5073 * that is closed. This can happen on hangups - since they completely
5074 * shutdown a port not in user context. Need to handle this case.
5077 static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
5079 struct tty_struct *tty;
5080 unsigned int len, buflen, ioaddr;
5083 printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
5087 ioaddr = portp->ioaddr;
5088 outb(GIBCR, (ioaddr + XP_ADDR));
5089 len = inb(ioaddr + XP_DATA) + 1;
5091 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
5092 if ((tty == (struct tty_struct *) NULL) ||
5093 (tty->flip.char_buf_ptr == (char *) NULL) ||
5094 ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
5095 len = MIN(len, sizeof(stl_unwanted));
5096 outb(GRXFIFO, (ioaddr + XP_ADDR));
5097 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
5098 portp->stats.rxlost += len;
5099 portp->stats.rxtotal += len;
5101 len = MIN(len, buflen);
5103 outb(GRXFIFO, (ioaddr + XP_ADDR));
5104 insb((ioaddr + XP_DATA), tty->flip.char_buf_ptr, len);
5105 memset(tty->flip.flag_buf_ptr, 0, len);
5106 tty->flip.flag_buf_ptr += len;
5107 tty->flip.char_buf_ptr += len;
5108 tty->flip.count += len;
5109 tty_schedule_flip(tty);
5110 portp->stats.rxtotal += len;
5114 stl_sc26198rxbadchars(portp);
5118 * If we are TX flow controlled and in IXANY mode then we may need
5119 * to unflow control here. We gotta do this because of the automatic
5120 * flow control modes of the sc26198.
5122 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
5123 if ((tty != (struct tty_struct *) NULL) &&
5124 (tty->termios != (struct termios *) NULL) &&
5125 (tty->termios->c_iflag & IXANY)) {
5126 stl_sc26198txunflow(portp, tty);
5131 /*****************************************************************************/
5134 * Process an RX bad character.
5137 static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch)
5139 struct tty_struct *tty;
5140 unsigned int ioaddr;
5143 ioaddr = portp->ioaddr;
5145 if (status & SR_RXPARITY)
5146 portp->stats.rxparity++;
5147 if (status & SR_RXFRAMING)
5148 portp->stats.rxframing++;
5149 if (status & SR_RXOVERRUN)
5150 portp->stats.rxoverrun++;
5151 if (status & SR_RXBREAK)
5152 portp->stats.rxbreaks++;
5154 if ((tty != (struct tty_struct *) NULL) &&
5155 ((portp->rxignoremsk & status) == 0)) {
5156 if (portp->rxmarkmsk & status) {
5157 if (status & SR_RXBREAK) {
5159 if (portp->flags & ASYNC_SAK) {
5161 BRDENABLE(portp->brdnr, portp->pagenr);
5163 } else if (status & SR_RXPARITY) {
5164 status = TTY_PARITY;
5165 } else if (status & SR_RXFRAMING) {
5167 } else if(status & SR_RXOVERRUN) {
5168 status = TTY_OVERRUN;
5176 if (tty->flip.char_buf_ptr != (char *) NULL) {
5177 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
5178 *tty->flip.flag_buf_ptr++ = status;
5179 *tty->flip.char_buf_ptr++ = ch;
5182 tty_schedule_flip(tty);
5186 portp->stats.rxtotal++;
5190 /*****************************************************************************/
5193 * Process all characters in the RX FIFO of the UART. Check all char
5194 * status bytes as well, and process as required. We need to check
5195 * all bytes in the FIFO, in case some more enter the FIFO while we
5196 * are here. To get the exact character error type we need to switch
5197 * into CHAR error mode (that is why we need to make sure we empty
5201 static void stl_sc26198rxbadchars(stlport_t *portp)
5203 unsigned char status, mr1;
5207 * To get the precise error type for each character we must switch
5208 * back into CHAR error mode.
5210 mr1 = stl_sc26198getreg(portp, MR1);
5211 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
5213 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
5214 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
5215 ch = stl_sc26198getreg(portp, RXFIFO);
5216 stl_sc26198rxbadch(portp, status, ch);
5220 * To get correct interrupt class we must switch back into BLOCK
5223 stl_sc26198setreg(portp, MR1, mr1);
5226 /*****************************************************************************/
5229 * Other interrupt handler. This includes modem signals, flow
5230 * control actions, etc. Most stuff is left to off-level interrupt
5234 static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
5236 unsigned char cir, ipr, xisr;
5239 printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
5242 cir = stl_sc26198getglobreg(portp, CIR);
5244 switch (cir & CIR_SUBTYPEMASK) {
5246 ipr = stl_sc26198getreg(portp, IPR);
5247 if (ipr & IPR_DCDCHANGE) {
5248 set_bit(ASYI_DCDCHANGE, &portp->istate);
5249 schedule_work(&portp->tqueue);
5250 portp->stats.modem++;
5253 case CIR_SUBXONXOFF:
5254 xisr = stl_sc26198getreg(portp, XISR);
5255 if (xisr & XISR_RXXONGOT) {
5256 set_bit(ASYI_TXFLOWED, &portp->istate);
5257 portp->stats.txxoff++;
5259 if (xisr & XISR_RXXOFFGOT) {
5260 clear_bit(ASYI_TXFLOWED, &portp->istate);
5261 portp->stats.txxon++;
5265 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
5266 stl_sc26198rxbadchars(portp);
5273 /*****************************************************************************/