1 /*****************************************************************************/
4 * stallion.c -- stallion multiport serial driver.
6 * Copyright (C) 1996-1999 Stallion Technologies (support@stallion.oz.au).
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/version.h> /* for linux/stallion.h */
32 #include <linux/slab.h>
33 #include <linux/interrupt.h>
34 #include <linux/tty.h>
35 #include <linux/tty_flip.h>
36 #include <linux/serial.h>
37 #include <linux/cd1400.h>
38 #include <linux/sc26198.h>
39 #include <linux/comstats.h>
40 #include <linux/stallion.h>
41 #include <linux/ioport.h>
42 #include <linux/init.h>
43 #include <linux/smp_lock.h>
44 #include <linux/devfs_fs_kernel.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 *sp);
508 static int stl_setserial(stlport_t *portp, struct serial_struct *sp);
509 static int stl_getbrdstats(combrd_t *bp);
510 static int stl_getportstats(stlport_t *portp, comstats_t *cp);
511 static int stl_clrportstats(stlport_t *portp, comstats_t *cp);
512 static int stl_getportstruct(unsigned long arg);
513 static int stl_getbrdstruct(unsigned long 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 /*****************************************************************************/
739 * Loadable module initialization stuff.
742 static int __init stallion_module_init(void)
747 printk("init_module()\n");
753 restore_flags(flags);
758 /*****************************************************************************/
760 static void __exit stallion_module_exit(void)
769 printk("cleanup_module()\n");
772 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
779 * Free up all allocated resources used by the ports. This includes
780 * memory and interrupts. As part of this process we will also do
781 * a hangup on every open port - to try to flush out any processes
782 * hanging onto ports.
784 i = tty_unregister_driver(stl_serial);
785 put_tty_driver(stl_serial);
787 printk("STALLION: failed to un-register tty driver, "
789 restore_flags(flags);
792 for (i = 0; i < 4; i++)
793 devfs_remove("staliomem/%d", i);
794 devfs_remove("staliomem");
795 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
796 printk("STALLION: failed to un-register serial memory device, "
799 if (stl_tmpwritebuf != (char *) NULL)
800 kfree(stl_tmpwritebuf);
802 for (i = 0; (i < stl_nrbrds); i++) {
803 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
805 for (j = 0; (j < STL_MAXPANELS); j++) {
806 panelp = brdp->panels[j];
807 if (panelp == (stlpanel_t *) NULL)
809 for (k = 0; (k < STL_PORTSPERPANEL); k++) {
810 portp = panelp->ports[k];
811 if (portp == (stlport_t *) NULL)
813 if (portp->tty != (struct tty_struct *) NULL)
814 stl_hangup(portp->tty);
815 if (portp->tx.buf != (char *) NULL)
816 kfree(portp->tx.buf);
822 release_region(brdp->ioaddr1, brdp->iosize1);
823 if (brdp->iosize2 > 0)
824 release_region(brdp->ioaddr2, brdp->iosize2);
827 stl_brds[i] = (stlbrd_t *) NULL;
830 for (i = 0; (i < stl_numintrs); i++)
831 free_irq(stl_gotintrs[i], NULL);
833 restore_flags(flags);
836 module_init(stallion_module_init);
837 module_exit(stallion_module_exit);
839 /*****************************************************************************/
842 * Check for any arguments passed in on the module load command line.
845 static void stl_argbrds()
852 printk("stl_argbrds()\n");
855 nrargs = sizeof(stl_brdsp) / sizeof(char **);
857 for (i = stl_nrbrds; (i < nrargs); i++) {
858 memset(&conf, 0, sizeof(conf));
859 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
861 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
865 brdp->brdtype = conf.brdtype;
866 brdp->ioaddr1 = conf.ioaddr1;
867 brdp->ioaddr2 = conf.ioaddr2;
868 brdp->irq = conf.irq;
869 brdp->irqtype = conf.irqtype;
874 /*****************************************************************************/
877 * Convert an ascii string number into an unsigned long.
880 static unsigned long stl_atol(char *str)
888 if ((*sp == '0') && (*(sp+1) == 'x')) {
891 } else if (*sp == '0') {
898 for (; (*sp != 0); sp++) {
899 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
900 if ((c < 0) || (c >= base)) {
901 printk("STALLION: invalid argument %s\n", str);
905 val = (val * base) + c;
910 /*****************************************************************************/
913 * Parse the supplied argument string, into the board conf struct.
916 static int stl_parsebrd(stlconf_t *confp, char **argp)
922 printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
925 if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
928 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
931 nrbrdnames = sizeof(stl_brdstr) / sizeof(stlbrdtype_t);
932 for (i = 0; (i < nrbrdnames); i++) {
933 if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
936 if (i >= nrbrdnames) {
937 printk("STALLION: unknown board name, %s?\n", argp[0]);
941 confp->brdtype = stl_brdstr[i].type;
944 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
945 confp->ioaddr1 = stl_atol(argp[i]);
947 if (confp->brdtype == BRD_ECH) {
948 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
949 confp->ioaddr2 = stl_atol(argp[i]);
952 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
953 confp->irq = stl_atol(argp[i]);
959 /*****************************************************************************/
962 * Local driver kernel memory allocation routine.
965 static void *stl_memalloc(int len)
967 return((void *) kmalloc(len, GFP_KERNEL));
970 /*****************************************************************************/
973 * Allocate a new board structure. Fill out the basic info in it.
976 static stlbrd_t *stl_allocbrd()
980 brdp = (stlbrd_t *) stl_memalloc(sizeof(stlbrd_t));
981 if (brdp == (stlbrd_t *) NULL) {
982 printk("STALLION: failed to allocate memory (size=%d)\n",
984 return((stlbrd_t *) NULL);
987 memset(brdp, 0, sizeof(stlbrd_t));
988 brdp->magic = STL_BOARDMAGIC;
992 /*****************************************************************************/
994 static int stl_open(struct tty_struct *tty, struct file *filp)
998 unsigned int minordev;
999 int brdnr, panelnr, portnr, rc;
1002 printk("stl_open(tty=%x,filp=%x): device=%s\n", (int) tty,
1003 (int) filp, tty->name);
1006 minordev = tty->index;
1007 brdnr = MINOR2BRD(minordev);
1008 if (brdnr >= stl_nrbrds)
1010 brdp = stl_brds[brdnr];
1011 if (brdp == (stlbrd_t *) NULL)
1013 minordev = MINOR2PORT(minordev);
1014 for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
1015 if (brdp->panels[panelnr] == (stlpanel_t *) NULL)
1017 if (minordev < brdp->panels[panelnr]->nrports) {
1021 minordev -= brdp->panels[panelnr]->nrports;
1026 portp = brdp->panels[panelnr]->ports[portnr];
1027 if (portp == (stlport_t *) NULL)
1031 * On the first open of the device setup the port hardware, and
1032 * initialize the per port data structure.
1035 tty->driver_data = portp;
1038 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
1039 if (portp->tx.buf == (char *) NULL) {
1040 portp->tx.buf = (char *) stl_memalloc(STL_TXBUFSIZE);
1041 if (portp->tx.buf == (char *) NULL)
1043 portp->tx.head = portp->tx.buf;
1044 portp->tx.tail = portp->tx.buf;
1046 stl_setport(portp, tty->termios);
1047 portp->sigs = stl_getsignals(portp);
1048 stl_setsignals(portp, 1, 1);
1049 stl_enablerxtx(portp, 1, 1);
1050 stl_startrxtx(portp, 1, 0);
1051 clear_bit(TTY_IO_ERROR, &tty->flags);
1052 portp->flags |= ASYNC_INITIALIZED;
1056 * Check if this port is in the middle of closing. If so then wait
1057 * until it is closed then return error status, based on flag settings.
1058 * The sleep here does not need interrupt protection since the wakeup
1059 * for it is done with the same context.
1061 if (portp->flags & ASYNC_CLOSING) {
1062 interruptible_sleep_on(&portp->close_wait);
1063 if (portp->flags & ASYNC_HUP_NOTIFY)
1065 return(-ERESTARTSYS);
1069 * Based on type of open being done check if it can overlap with any
1070 * previous opens still in effect. If we are a normal serial device
1071 * then also we might have to wait for carrier.
1073 if (!(filp->f_flags & O_NONBLOCK)) {
1074 if ((rc = stl_waitcarrier(portp, filp)) != 0)
1077 portp->flags |= ASYNC_NORMAL_ACTIVE;
1082 /*****************************************************************************/
1085 * Possibly need to wait for carrier (DCD signal) to come high. Say
1086 * maybe because if we are clocal then we don't need to wait...
1089 static int stl_waitcarrier(stlport_t *portp, struct file *filp)
1091 unsigned long flags;
1095 printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp, (int) filp);
1101 if (portp->tty->termios->c_cflag & CLOCAL)
1106 portp->openwaitcnt++;
1107 if (! tty_hung_up_p(filp))
1111 stl_setsignals(portp, 1, 1);
1112 if (tty_hung_up_p(filp) ||
1113 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1114 if (portp->flags & ASYNC_HUP_NOTIFY)
1120 if (((portp->flags & ASYNC_CLOSING) == 0) &&
1121 (doclocal || (portp->sigs & TIOCM_CD))) {
1124 if (signal_pending(current)) {
1128 interruptible_sleep_on(&portp->open_wait);
1131 if (! tty_hung_up_p(filp))
1133 portp->openwaitcnt--;
1134 restore_flags(flags);
1139 /*****************************************************************************/
1141 static void stl_close(struct tty_struct *tty, struct file *filp)
1144 unsigned long flags;
1147 printk("stl_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
1150 portp = tty->driver_data;
1151 if (portp == (stlport_t *) NULL)
1156 if (tty_hung_up_p(filp)) {
1157 restore_flags(flags);
1160 if ((tty->count == 1) && (portp->refcount != 1))
1161 portp->refcount = 1;
1162 if (portp->refcount-- > 1) {
1163 restore_flags(flags);
1167 portp->refcount = 0;
1168 portp->flags |= ASYNC_CLOSING;
1171 * May want to wait for any data to drain before closing. The BUSY
1172 * flag keeps track of whether we are still sending or not - it is
1173 * very accurate for the cd1400, not quite so for the sc26198.
1174 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1177 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1178 tty_wait_until_sent(tty, portp->closing_wait);
1179 stl_waituntilsent(tty, (HZ / 2));
1181 portp->flags &= ~ASYNC_INITIALIZED;
1182 stl_disableintrs(portp);
1183 if (tty->termios->c_cflag & HUPCL)
1184 stl_setsignals(portp, 0, 0);
1185 stl_enablerxtx(portp, 0, 0);
1186 stl_flushbuffer(tty);
1188 if (portp->tx.buf != (char *) NULL) {
1189 kfree(portp->tx.buf);
1190 portp->tx.buf = (char *) NULL;
1191 portp->tx.head = (char *) NULL;
1192 portp->tx.tail = (char *) NULL;
1194 set_bit(TTY_IO_ERROR, &tty->flags);
1195 if (tty->ldisc.flush_buffer)
1196 (tty->ldisc.flush_buffer)(tty);
1199 portp->tty = (struct tty_struct *) NULL;
1201 if (portp->openwaitcnt) {
1202 if (portp->close_delay)
1203 stl_delay(portp->close_delay);
1204 wake_up_interruptible(&portp->open_wait);
1207 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1208 wake_up_interruptible(&portp->close_wait);
1209 restore_flags(flags);
1212 /*****************************************************************************/
1215 * Wait for a specified delay period, this is not a busy-loop. It will
1216 * give up the processor while waiting. Unfortunately this has some
1217 * rather intimate knowledge of the process management stuff.
1220 static void stl_delay(int len)
1223 printk("stl_delay(len=%d)\n", len);
1226 current->state = TASK_INTERRUPTIBLE;
1227 schedule_timeout(len);
1228 current->state = TASK_RUNNING;
1232 /*****************************************************************************/
1235 * Write routine. Take data and stuff it in to the TX ring queue.
1236 * If transmit interrupts are not running then start them.
1239 static int stl_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count)
1242 unsigned int len, stlen;
1243 unsigned char *chbuf;
1247 printk("stl_write(tty=%x,from_user=%d,buf=%x,count=%d)\n",
1248 (int) tty, from_user, (int) buf, count);
1251 if ((tty == (struct tty_struct *) NULL) ||
1252 (stl_tmpwritebuf == (char *) NULL))
1254 portp = tty->driver_data;
1255 if (portp == (stlport_t *) NULL)
1257 if (portp->tx.buf == (char *) NULL)
1261 * If copying direct from user space we must cater for page faults,
1262 * causing us to "sleep" here for a while. To handle this copy in all
1263 * the data we need now, into a local buffer. Then when we got it all
1264 * copy it into the TX buffer.
1266 chbuf = (unsigned char *) buf;
1268 head = portp->tx.head;
1269 tail = portp->tx.tail;
1270 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) :
1272 count = MIN(len, count);
1274 down(&stl_tmpwritesem);
1275 if (copy_from_user(stl_tmpwritebuf, chbuf, count))
1277 chbuf = &stl_tmpwritebuf[0];
1280 head = portp->tx.head;
1281 tail = portp->tx.tail;
1283 len = STL_TXBUFSIZE - (head - tail) - 1;
1284 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
1286 len = tail - head - 1;
1290 len = MIN(len, count);
1293 stlen = MIN(len, stlen);
1294 memcpy(head, chbuf, stlen);
1299 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
1300 head = portp->tx.buf;
1301 stlen = tail - head;
1304 portp->tx.head = head;
1306 clear_bit(ASYI_TXLOW, &portp->istate);
1307 stl_startrxtx(portp, -1, 1);
1310 up(&stl_tmpwritesem);
1315 /*****************************************************************************/
1317 static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1324 printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1327 if (tty == (struct tty_struct *) NULL)
1329 portp = tty->driver_data;
1330 if (portp == (stlport_t *) NULL)
1332 if (portp->tx.buf == (char *) NULL)
1335 head = portp->tx.head;
1336 tail = portp->tx.tail;
1338 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
1343 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
1344 head = portp->tx.buf;
1346 portp->tx.head = head;
1349 /*****************************************************************************/
1352 * If there are any characters in the buffer then make sure that TX
1353 * interrupts are on and get'em out. Normally used after the putchar
1354 * routine has been called.
1357 static void stl_flushchars(struct tty_struct *tty)
1362 printk("stl_flushchars(tty=%x)\n", (int) tty);
1365 if (tty == (struct tty_struct *) NULL)
1367 portp = tty->driver_data;
1368 if (portp == (stlport_t *) NULL)
1370 if (portp->tx.buf == (char *) NULL)
1374 if (tty->stopped || tty->hw_stopped ||
1375 (portp->tx.head == portp->tx.tail))
1378 stl_startrxtx(portp, -1, 1);
1381 /*****************************************************************************/
1383 static int stl_writeroom(struct tty_struct *tty)
1389 printk("stl_writeroom(tty=%x)\n", (int) tty);
1392 if (tty == (struct tty_struct *) NULL)
1394 portp = tty->driver_data;
1395 if (portp == (stlport_t *) NULL)
1397 if (portp->tx.buf == (char *) NULL)
1400 head = portp->tx.head;
1401 tail = portp->tx.tail;
1402 return((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
1405 /*****************************************************************************/
1408 * Return number of chars in the TX buffer. Normally we would just
1409 * calculate the number of chars in the buffer and return that, but if
1410 * the buffer is empty and TX interrupts are still on then we return
1411 * that the buffer still has 1 char in it. This way whoever called us
1412 * will not think that ALL chars have drained - since the UART still
1413 * must have some chars in it (we are busy after all).
1416 static int stl_charsinbuffer(struct tty_struct *tty)
1423 printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
1426 if (tty == (struct tty_struct *) NULL)
1428 portp = tty->driver_data;
1429 if (portp == (stlport_t *) NULL)
1431 if (portp->tx.buf == (char *) NULL)
1434 head = portp->tx.head;
1435 tail = portp->tx.tail;
1436 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1437 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1442 /*****************************************************************************/
1445 * Generate the serial struct info.
1448 static int stl_getserial(stlport_t *portp, struct serial_struct *sp)
1450 struct serial_struct sio;
1454 printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1457 memset(&sio, 0, sizeof(struct serial_struct));
1458 sio.line = portp->portnr;
1459 sio.port = portp->ioaddr;
1460 sio.flags = portp->flags;
1461 sio.baud_base = portp->baud_base;
1462 sio.close_delay = portp->close_delay;
1463 sio.closing_wait = portp->closing_wait;
1464 sio.custom_divisor = portp->custom_divisor;
1466 if (portp->uartp == &stl_cd1400uart) {
1467 sio.type = PORT_CIRRUS;
1468 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1470 sio.type = PORT_UNKNOWN;
1471 sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1474 brdp = stl_brds[portp->brdnr];
1475 if (brdp != (stlbrd_t *) NULL)
1476 sio.irq = brdp->irq;
1478 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
1481 /*****************************************************************************/
1484 * Set port according to the serial struct info.
1485 * At this point we do not do any auto-configure stuff, so we will
1486 * just quietly ignore any requests to change irq, etc.
1489 static int stl_setserial(stlport_t *portp, struct serial_struct *sp)
1491 struct serial_struct sio;
1494 printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1497 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1499 if (!capable(CAP_SYS_ADMIN)) {
1500 if ((sio.baud_base != portp->baud_base) ||
1501 (sio.close_delay != portp->close_delay) ||
1502 ((sio.flags & ~ASYNC_USR_MASK) !=
1503 (portp->flags & ~ASYNC_USR_MASK)))
1507 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1508 (sio.flags & ASYNC_USR_MASK);
1509 portp->baud_base = sio.baud_base;
1510 portp->close_delay = sio.close_delay;
1511 portp->closing_wait = sio.closing_wait;
1512 portp->custom_divisor = sio.custom_divisor;
1513 stl_setport(portp, portp->tty->termios);
1517 /*****************************************************************************/
1519 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1526 printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
1527 (int) tty, (int) file, cmd, (int) arg);
1530 if (tty == (struct tty_struct *) NULL)
1532 portp = tty->driver_data;
1533 if (portp == (stlport_t *) NULL)
1536 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1537 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1538 if (tty->flags & (1 << TTY_IO_ERROR))
1546 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1547 (unsigned int *) arg);
1550 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1551 sizeof(int))) == 0) {
1552 get_user(ival, (unsigned int *) arg);
1553 tty->termios->c_cflag =
1554 (tty->termios->c_cflag & ~CLOCAL) |
1555 (ival ? CLOCAL : 0);
1559 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1560 sizeof(unsigned int))) == 0) {
1561 ival = stl_getsignals(portp);
1562 put_user(ival, (unsigned int *) arg);
1566 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1567 sizeof(unsigned int))) == 0) {
1568 get_user(ival, (unsigned int *) arg);
1569 stl_setsignals(portp, ((ival & TIOCM_DTR) ? 1 : -1),
1570 ((ival & TIOCM_RTS) ? 1 : -1));
1574 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1575 sizeof(unsigned int))) == 0) {
1576 get_user(ival, (unsigned int *) arg);
1577 stl_setsignals(portp, ((ival & TIOCM_DTR) ? 0 : -1),
1578 ((ival & TIOCM_RTS) ? 0 : -1));
1582 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1583 sizeof(unsigned int))) == 0) {
1584 get_user(ival, (unsigned int *) arg);
1585 stl_setsignals(portp, ((ival & TIOCM_DTR) ? 1 : 0),
1586 ((ival & TIOCM_RTS) ? 1 : 0));
1590 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1591 sizeof(struct serial_struct))) == 0)
1592 rc = stl_getserial(portp, (struct serial_struct *) arg);
1595 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1596 sizeof(struct serial_struct))) == 0)
1597 rc = stl_setserial(portp, (struct serial_struct *) arg);
1599 case COM_GETPORTSTATS:
1600 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1601 sizeof(comstats_t))) == 0)
1602 rc = stl_getportstats(portp, (comstats_t *) arg);
1604 case COM_CLRPORTSTATS:
1605 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1606 sizeof(comstats_t))) == 0)
1607 rc = stl_clrportstats(portp, (comstats_t *) arg);
1613 case TIOCSERGSTRUCT:
1614 case TIOCSERGETMULTI:
1615 case TIOCSERSETMULTI:
1624 /*****************************************************************************/
1626 static void stl_settermios(struct tty_struct *tty, struct termios *old)
1629 struct termios *tiosp;
1632 printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
1635 if (tty == (struct tty_struct *) NULL)
1637 portp = tty->driver_data;
1638 if (portp == (stlport_t *) NULL)
1641 tiosp = tty->termios;
1642 if ((tiosp->c_cflag == old->c_cflag) &&
1643 (tiosp->c_iflag == old->c_iflag))
1646 stl_setport(portp, tiosp);
1647 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1649 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1650 tty->hw_stopped = 0;
1653 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1654 wake_up_interruptible(&portp->open_wait);
1657 /*****************************************************************************/
1660 * Attempt to flow control who ever is sending us data. Based on termios
1661 * settings use software or/and hardware flow control.
1664 static void stl_throttle(struct tty_struct *tty)
1669 printk("stl_throttle(tty=%x)\n", (int) tty);
1672 if (tty == (struct tty_struct *) NULL)
1674 portp = tty->driver_data;
1675 if (portp == (stlport_t *) NULL)
1677 stl_flowctrl(portp, 0);
1680 /*****************************************************************************/
1683 * Unflow control the device sending us data...
1686 static void stl_unthrottle(struct tty_struct *tty)
1691 printk("stl_unthrottle(tty=%x)\n", (int) tty);
1694 if (tty == (struct tty_struct *) NULL)
1696 portp = tty->driver_data;
1697 if (portp == (stlport_t *) NULL)
1699 stl_flowctrl(portp, 1);
1702 /*****************************************************************************/
1705 * Stop the transmitter. Basically to do this we will just turn TX
1709 static void stl_stop(struct tty_struct *tty)
1714 printk("stl_stop(tty=%x)\n", (int) tty);
1717 if (tty == (struct tty_struct *) NULL)
1719 portp = tty->driver_data;
1720 if (portp == (stlport_t *) NULL)
1722 stl_startrxtx(portp, -1, 0);
1725 /*****************************************************************************/
1728 * Start the transmitter again. Just turn TX interrupts back on.
1731 static void stl_start(struct tty_struct *tty)
1736 printk("stl_start(tty=%x)\n", (int) tty);
1739 if (tty == (struct tty_struct *) NULL)
1741 portp = tty->driver_data;
1742 if (portp == (stlport_t *) NULL)
1744 stl_startrxtx(portp, -1, 1);
1747 /*****************************************************************************/
1750 * Hangup this port. This is pretty much like closing the port, only
1751 * a little more brutal. No waiting for data to drain. Shutdown the
1752 * port and maybe drop signals.
1755 static void stl_hangup(struct tty_struct *tty)
1760 printk("stl_hangup(tty=%x)\n", (int) tty);
1763 if (tty == (struct tty_struct *) NULL)
1765 portp = tty->driver_data;
1766 if (portp == (stlport_t *) NULL)
1769 portp->flags &= ~ASYNC_INITIALIZED;
1770 stl_disableintrs(portp);
1771 if (tty->termios->c_cflag & HUPCL)
1772 stl_setsignals(portp, 0, 0);
1773 stl_enablerxtx(portp, 0, 0);
1774 stl_flushbuffer(tty);
1776 set_bit(TTY_IO_ERROR, &tty->flags);
1777 if (portp->tx.buf != (char *) NULL) {
1778 kfree(portp->tx.buf);
1779 portp->tx.buf = (char *) NULL;
1780 portp->tx.head = (char *) NULL;
1781 portp->tx.tail = (char *) NULL;
1783 portp->tty = (struct tty_struct *) NULL;
1784 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1785 portp->refcount = 0;
1786 wake_up_interruptible(&portp->open_wait);
1789 /*****************************************************************************/
1791 static void stl_flushbuffer(struct tty_struct *tty)
1796 printk("stl_flushbuffer(tty=%x)\n", (int) tty);
1799 if (tty == (struct tty_struct *) NULL)
1801 portp = tty->driver_data;
1802 if (portp == (stlport_t *) NULL)
1806 wake_up_interruptible(&tty->write_wait);
1807 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1808 tty->ldisc.write_wakeup)
1809 (tty->ldisc.write_wakeup)(tty);
1812 /*****************************************************************************/
1814 static void stl_breakctl(struct tty_struct *tty, int state)
1819 printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty, state);
1822 if (tty == (struct tty_struct *) NULL)
1824 portp = tty->driver_data;
1825 if (portp == (stlport_t *) NULL)
1828 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1831 /*****************************************************************************/
1833 static void stl_waituntilsent(struct tty_struct *tty, int timeout)
1839 printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty, timeout);
1842 if (tty == (struct tty_struct *) NULL)
1844 portp = tty->driver_data;
1845 if (portp == (stlport_t *) NULL)
1850 tend = jiffies + timeout;
1852 while (stl_datastate(portp)) {
1853 if (signal_pending(current))
1856 if (time_after_eq(jiffies, tend))
1861 /*****************************************************************************/
1863 static void stl_sendxchar(struct tty_struct *tty, char ch)
1868 printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
1871 if (tty == (struct tty_struct *) NULL)
1873 portp = tty->driver_data;
1874 if (portp == (stlport_t *) NULL)
1877 if (ch == STOP_CHAR(tty))
1878 stl_sendflow(portp, 0);
1879 else if (ch == START_CHAR(tty))
1880 stl_sendflow(portp, 1);
1882 stl_putchar(tty, ch);
1885 /*****************************************************************************/
1890 * Format info for a specified port. The line is deliberately limited
1891 * to 80 characters. (If it is too long it will be truncated, if too
1892 * short then padded with spaces).
1895 static int stl_portinfo(stlport_t *portp, int portnr, char *pos)
1901 sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
1902 portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
1903 (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
1905 if (portp->stats.rxframing)
1906 sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
1907 if (portp->stats.rxparity)
1908 sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
1909 if (portp->stats.rxbreaks)
1910 sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
1911 if (portp->stats.rxoverrun)
1912 sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
1914 sigs = stl_getsignals(portp);
1915 cnt = sprintf(sp, "%s%s%s%s%s ",
1916 (sigs & TIOCM_RTS) ? "|RTS" : "",
1917 (sigs & TIOCM_CTS) ? "|CTS" : "",
1918 (sigs & TIOCM_DTR) ? "|DTR" : "",
1919 (sigs & TIOCM_CD) ? "|DCD" : "",
1920 (sigs & TIOCM_DSR) ? "|DSR" : "");
1924 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
1927 pos[(MAXLINE - 2)] = '+';
1928 pos[(MAXLINE - 1)] = '\n';
1933 /*****************************************************************************/
1936 * Port info, read from the /proc file system.
1939 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
1944 int brdnr, panelnr, portnr, totalport;
1949 printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
1950 "data=%x\n", (int) page, (int) start, (int) off, count,
1951 (int) eof, (int) data);
1959 pos += sprintf(pos, "%s: version %s", stl_drvtitle,
1961 while (pos < (page + MAXLINE - 1))
1968 * We scan through for each board, panel and port. The offset is
1969 * calculated on the fly, and irrelevant ports are skipped.
1971 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1972 brdp = stl_brds[brdnr];
1973 if (brdp == (stlbrd_t *) NULL)
1975 if (brdp->state == 0)
1978 maxoff = curoff + (brdp->nrports * MAXLINE);
1979 if (off >= maxoff) {
1984 totalport = brdnr * STL_MAXPORTS;
1985 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1986 panelp = brdp->panels[panelnr];
1987 if (panelp == (stlpanel_t *) NULL)
1990 maxoff = curoff + (panelp->nrports * MAXLINE);
1991 if (off >= maxoff) {
1993 totalport += panelp->nrports;
1997 for (portnr = 0; (portnr < panelp->nrports); portnr++,
1999 portp = panelp->ports[portnr];
2000 if (portp == (stlport_t *) NULL)
2002 if (off >= (curoff += MAXLINE))
2004 if ((pos - page + MAXLINE) > count)
2006 pos += stl_portinfo(portp, totalport, pos);
2018 /*****************************************************************************/
2021 * All board interrupts are vectored through here first. This code then
2022 * calls off to the approrpriate board interrupt handlers.
2025 static irqreturn_t stl_intr(int irq, void *dev_id, struct pt_regs *regs)
2032 printk("stl_intr(irq=%d,regs=%x)\n", irq, (int) regs);
2035 for (i = 0; (i < stl_nrbrds); i++) {
2036 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
2038 if (brdp->state == 0)
2041 (* brdp->isr)(brdp);
2043 return IRQ_RETVAL(handled);
2046 /*****************************************************************************/
2049 * Interrupt service routine for EasyIO board types.
2052 static void stl_eiointr(stlbrd_t *brdp)
2055 unsigned int iobase;
2057 panelp = brdp->panels[0];
2058 iobase = panelp->iobase;
2059 while (inb(brdp->iostatus) & EIO_INTRPEND)
2060 (* panelp->isr)(panelp, iobase);
2063 /*****************************************************************************/
2066 * Interrupt service routine for ECH-AT board types.
2069 static void stl_echatintr(stlbrd_t *brdp)
2072 unsigned int ioaddr;
2075 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2077 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2078 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2079 ioaddr = brdp->bnkstataddr[bnknr];
2080 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2081 panelp = brdp->bnk2panel[bnknr];
2082 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2087 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2090 /*****************************************************************************/
2093 * Interrupt service routine for ECH-MCA board types.
2096 static void stl_echmcaintr(stlbrd_t *brdp)
2099 unsigned int ioaddr;
2102 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2103 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2104 ioaddr = brdp->bnkstataddr[bnknr];
2105 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2106 panelp = brdp->bnk2panel[bnknr];
2107 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2113 /*****************************************************************************/
2116 * Interrupt service routine for ECH-PCI board types.
2119 static void stl_echpciintr(stlbrd_t *brdp)
2122 unsigned int ioaddr;
2127 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2128 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
2129 ioaddr = brdp->bnkstataddr[bnknr];
2130 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2131 panelp = brdp->bnk2panel[bnknr];
2132 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2141 /*****************************************************************************/
2144 * Interrupt service routine for ECH-8/64-PCI board types.
2147 static void stl_echpci64intr(stlbrd_t *brdp)
2150 unsigned int ioaddr;
2153 while (inb(brdp->ioctrl) & 0x1) {
2154 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2155 ioaddr = brdp->bnkstataddr[bnknr];
2156 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2157 panelp = brdp->bnk2panel[bnknr];
2158 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2164 /*****************************************************************************/
2167 * Service an off-level request for some channel.
2169 static void stl_offintr(void *private)
2172 struct tty_struct *tty;
2173 unsigned int oldsigs;
2178 printk("stl_offintr(portp=%x)\n", (int) portp);
2181 if (portp == (stlport_t *) NULL)
2185 if (tty == (struct tty_struct *) NULL)
2189 if (test_bit(ASYI_TXLOW, &portp->istate)) {
2190 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2191 tty->ldisc.write_wakeup)
2192 (tty->ldisc.write_wakeup)(tty);
2193 wake_up_interruptible(&tty->write_wait);
2195 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
2196 clear_bit(ASYI_DCDCHANGE, &portp->istate);
2197 oldsigs = portp->sigs;
2198 portp->sigs = stl_getsignals(portp);
2199 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
2200 wake_up_interruptible(&portp->open_wait);
2201 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
2202 if (portp->flags & ASYNC_CHECK_CD)
2203 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2209 /*****************************************************************************/
2212 * Map in interrupt vector to this driver. Check that we don't
2213 * already have this vector mapped, we might be sharing this
2214 * interrupt across multiple boards.
2217 static int __init stl_mapirq(int irq, char *name)
2222 printk("stl_mapirq(irq=%d,name=%s)\n", irq, name);
2226 for (i = 0; (i < stl_numintrs); i++) {
2227 if (stl_gotintrs[i] == irq)
2230 if (i >= stl_numintrs) {
2231 if (request_irq(irq, stl_intr, SA_SHIRQ, name, NULL) != 0) {
2232 printk("STALLION: failed to register interrupt "
2233 "routine for %s irq=%d\n", name, irq);
2236 stl_gotintrs[stl_numintrs++] = irq;
2242 /*****************************************************************************/
2245 * Initialize all the ports on a panel.
2248 static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2254 printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
2257 chipmask = stl_panelinit(brdp, panelp);
2260 * All UART's are initialized (if found!). Now go through and setup
2261 * each ports data structures.
2263 for (i = 0; (i < panelp->nrports); i++) {
2264 portp = (stlport_t *) stl_memalloc(sizeof(stlport_t));
2265 if (portp == (stlport_t *) NULL) {
2266 printk("STALLION: failed to allocate memory "
2267 "(size=%d)\n", sizeof(stlport_t));
2270 memset(portp, 0, sizeof(stlport_t));
2272 portp->magic = STL_PORTMAGIC;
2274 portp->brdnr = panelp->brdnr;
2275 portp->panelnr = panelp->panelnr;
2276 portp->uartp = panelp->uartp;
2277 portp->clk = brdp->clk;
2278 portp->baud_base = STL_BAUDBASE;
2279 portp->close_delay = STL_CLOSEDELAY;
2280 portp->closing_wait = 30 * HZ;
2281 INIT_WORK(&portp->tqueue, stl_offintr, portp);
2282 init_waitqueue_head(&portp->open_wait);
2283 init_waitqueue_head(&portp->close_wait);
2284 portp->stats.brd = portp->brdnr;
2285 portp->stats.panel = portp->panelnr;
2286 portp->stats.port = portp->portnr;
2287 panelp->ports[i] = portp;
2288 stl_portinit(brdp, panelp, portp);
2294 /*****************************************************************************/
2297 * Try to find and initialize an EasyIO board.
2300 static inline int stl_initeio(stlbrd_t *brdp)
2303 unsigned int status;
2308 printk("stl_initeio(brdp=%x)\n", (int) brdp);
2311 brdp->ioctrl = brdp->ioaddr1 + 1;
2312 brdp->iostatus = brdp->ioaddr1 + 2;
2314 status = inb(brdp->iostatus);
2315 if ((status & EIO_IDBITMASK) == EIO_MK3)
2319 * Handle board specific stuff now. The real difference is PCI
2322 if (brdp->brdtype == BRD_EASYIOPCI) {
2323 brdp->iosize1 = 0x80;
2324 brdp->iosize2 = 0x80;
2325 name = "serial(EIO-PCI)";
2326 outb(0x41, (brdp->ioaddr2 + 0x4c));
2329 name = "serial(EIO)";
2330 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2331 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2332 printk("STALLION: invalid irq=%d for brd=%d\n",
2333 brdp->irq, brdp->brdnr);
2336 outb((stl_vecmap[brdp->irq] | EIO_0WS |
2337 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
2341 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2342 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2343 "%x conflicts with another device\n", brdp->brdnr,
2348 if (brdp->iosize2 > 0)
2349 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2350 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2351 "address %x conflicts with another device\n",
2352 brdp->brdnr, brdp->ioaddr2);
2353 printk(KERN_WARNING "STALLION: Warning, also "
2354 "releasing board %d I/O address %x \n",
2355 brdp->brdnr, brdp->ioaddr1);
2356 release_region(brdp->ioaddr1, brdp->iosize1);
2361 * Everything looks OK, so let's go ahead and probe for the hardware.
2363 brdp->clk = CD1400_CLK;
2364 brdp->isr = stl_eiointr;
2366 switch (status & EIO_IDBITMASK) {
2368 brdp->clk = CD1400_CLK8M;
2378 switch (status & EIO_BRDMASK) {
2397 * We have verified that the board is actually present, so now we
2398 * can complete the setup.
2401 panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
2402 if (panelp == (stlpanel_t *) NULL) {
2403 printk(KERN_WARNING "STALLION: failed to allocate memory "
2404 "(size=%d)\n", sizeof(stlpanel_t));
2407 memset(panelp, 0, sizeof(stlpanel_t));
2409 panelp->magic = STL_PANELMAGIC;
2410 panelp->brdnr = brdp->brdnr;
2411 panelp->panelnr = 0;
2412 panelp->nrports = brdp->nrports;
2413 panelp->iobase = brdp->ioaddr1;
2414 panelp->hwid = status;
2415 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2416 panelp->uartp = (void *) &stl_sc26198uart;
2417 panelp->isr = stl_sc26198intr;
2419 panelp->uartp = (void *) &stl_cd1400uart;
2420 panelp->isr = stl_cd1400eiointr;
2423 brdp->panels[0] = panelp;
2425 brdp->state |= BRD_FOUND;
2426 brdp->hwid = status;
2427 rc = stl_mapirq(brdp->irq, name);
2431 /*****************************************************************************/
2434 * Try to find an ECH board and initialize it. This code is capable of
2435 * dealing with all types of ECH board.
2438 static inline int stl_initech(stlbrd_t *brdp)
2441 unsigned int status, nxtid, ioaddr, conflict;
2442 int panelnr, banknr, i;
2446 printk("stl_initech(brdp=%x)\n", (int) brdp);
2453 * Set up the initial board register contents for boards. This varies a
2454 * bit between the different board types. So we need to handle each
2455 * separately. Also do a check that the supplied IRQ is good.
2457 switch (brdp->brdtype) {
2460 brdp->isr = stl_echatintr;
2461 brdp->ioctrl = brdp->ioaddr1 + 1;
2462 brdp->iostatus = brdp->ioaddr1 + 1;
2463 status = inb(brdp->iostatus);
2464 if ((status & ECH_IDBITMASK) != ECH_ID)
2466 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2467 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2468 printk("STALLION: invalid irq=%d for brd=%d\n",
2469 brdp->irq, brdp->brdnr);
2472 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2473 status |= (stl_vecmap[brdp->irq] << 1);
2474 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2475 brdp->ioctrlval = ECH_INTENABLE |
2476 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2477 for (i = 0; (i < 10); i++)
2478 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2481 name = "serial(EC8/32)";
2482 outb(status, brdp->ioaddr1);
2486 brdp->isr = stl_echmcaintr;
2487 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2488 brdp->iostatus = brdp->ioctrl;
2489 status = inb(brdp->iostatus);
2490 if ((status & ECH_IDBITMASK) != ECH_ID)
2492 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2493 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2494 printk("STALLION: invalid irq=%d for brd=%d\n",
2495 brdp->irq, brdp->brdnr);
2498 outb(ECHMC_BRDRESET, brdp->ioctrl);
2499 outb(ECHMC_INTENABLE, brdp->ioctrl);
2501 name = "serial(EC8/32-MC)";
2505 brdp->isr = stl_echpciintr;
2506 brdp->ioctrl = brdp->ioaddr1 + 2;
2509 name = "serial(EC8/32-PCI)";
2513 brdp->isr = stl_echpci64intr;
2514 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2515 outb(0x43, (brdp->ioaddr1 + 0x4c));
2516 brdp->iosize1 = 0x80;
2517 brdp->iosize2 = 0x80;
2518 name = "serial(EC8/64-PCI)";
2522 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
2528 * Check boards for possible IO address conflicts and return fail status
2529 * if an IO conflict found.
2531 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2532 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2533 "%x conflicts with another device\n", brdp->brdnr,
2538 if (brdp->iosize2 > 0)
2539 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2540 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2541 "address %x conflicts with another device\n",
2542 brdp->brdnr, brdp->ioaddr2);
2543 printk(KERN_WARNING "STALLION: Warning, also "
2544 "releasing board %d I/O address %x \n",
2545 brdp->brdnr, brdp->ioaddr1);
2546 release_region(brdp->ioaddr1, brdp->iosize1);
2551 * Scan through the secondary io address space looking for panels.
2552 * As we find'em allocate and initialize panel structures for each.
2554 brdp->clk = CD1400_CLK;
2555 brdp->hwid = status;
2557 ioaddr = brdp->ioaddr2;
2562 for (i = 0; (i < STL_MAXPANELS); i++) {
2563 if (brdp->brdtype == BRD_ECHPCI) {
2564 outb(nxtid, brdp->ioctrl);
2565 ioaddr = brdp->ioaddr2;
2567 status = inb(ioaddr + ECH_PNLSTATUS);
2568 if ((status & ECH_PNLIDMASK) != nxtid)
2570 panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
2571 if (panelp == (stlpanel_t *) NULL) {
2572 printk("STALLION: failed to allocate memory "
2573 "(size=%d)\n", sizeof(stlpanel_t));
2576 memset(panelp, 0, sizeof(stlpanel_t));
2577 panelp->magic = STL_PANELMAGIC;
2578 panelp->brdnr = brdp->brdnr;
2579 panelp->panelnr = panelnr;
2580 panelp->iobase = ioaddr;
2581 panelp->pagenr = nxtid;
2582 panelp->hwid = status;
2583 brdp->bnk2panel[banknr] = panelp;
2584 brdp->bnkpageaddr[banknr] = nxtid;
2585 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2587 if (status & ECH_PNLXPID) {
2588 panelp->uartp = (void *) &stl_sc26198uart;
2589 panelp->isr = stl_sc26198intr;
2590 if (status & ECH_PNL16PORT) {
2591 panelp->nrports = 16;
2592 brdp->bnk2panel[banknr] = panelp;
2593 brdp->bnkpageaddr[banknr] = nxtid;
2594 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2597 panelp->nrports = 8;
2600 panelp->uartp = (void *) &stl_cd1400uart;
2601 panelp->isr = stl_cd1400echintr;
2602 if (status & ECH_PNL16PORT) {
2603 panelp->nrports = 16;
2604 panelp->ackmask = 0x80;
2605 if (brdp->brdtype != BRD_ECHPCI)
2606 ioaddr += EREG_BANKSIZE;
2607 brdp->bnk2panel[banknr] = panelp;
2608 brdp->bnkpageaddr[banknr] = ++nxtid;
2609 brdp->bnkstataddr[banknr++] = ioaddr +
2612 panelp->nrports = 8;
2613 panelp->ackmask = 0xc0;
2618 ioaddr += EREG_BANKSIZE;
2619 brdp->nrports += panelp->nrports;
2620 brdp->panels[panelnr++] = panelp;
2621 if ((brdp->brdtype != BRD_ECHPCI) &&
2622 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
2626 brdp->nrpanels = panelnr;
2627 brdp->nrbnks = banknr;
2628 if (brdp->brdtype == BRD_ECH)
2629 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2631 brdp->state |= BRD_FOUND;
2632 i = stl_mapirq(brdp->irq, name);
2636 /*****************************************************************************/
2639 * Initialize and configure the specified board.
2640 * Scan through all the boards in the configuration and see what we
2641 * can find. Handle EIO and the ECH boards a little differently here
2642 * since the initial search and setup is very different.
2645 static int __init stl_brdinit(stlbrd_t *brdp)
2650 printk("stl_brdinit(brdp=%x)\n", (int) brdp);
2653 switch (brdp->brdtype) {
2665 printk("STALLION: board=%d is unknown board type=%d\n",
2666 brdp->brdnr, brdp->brdtype);
2670 stl_brds[brdp->brdnr] = brdp;
2671 if ((brdp->state & BRD_FOUND) == 0) {
2672 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2673 stl_brdnames[brdp->brdtype], brdp->brdnr,
2674 brdp->ioaddr1, brdp->irq);
2678 for (i = 0; (i < STL_MAXPANELS); i++)
2679 if (brdp->panels[i] != (stlpanel_t *) NULL)
2680 stl_initports(brdp, brdp->panels[i]);
2682 printk("STALLION: %s found, board=%d io=%x irq=%d "
2683 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2684 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2689 /*****************************************************************************/
2692 * Find the next available board number that is free.
2695 static inline int stl_getbrdnr()
2699 for (i = 0; (i < STL_MAXBRDS); i++) {
2700 if (stl_brds[i] == (stlbrd_t *) NULL) {
2701 if (i >= stl_nrbrds)
2709 /*****************************************************************************/
2714 * We have a Stallion board. Allocate a board structure and
2715 * initialize it. Read its IO and IRQ resources from PCI
2716 * configuration space.
2719 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
2724 printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
2725 devp->bus->number, devp->devfn);
2728 if (pci_enable_device(devp))
2730 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2732 if ((brdp->brdnr = stl_getbrdnr()) < 0) {
2733 printk("STALLION: too many boards found, "
2734 "maximum supported %d\n", STL_MAXBRDS);
2737 brdp->brdtype = brdtype;
2740 * Different Stallion boards use the BAR registers in different ways,
2741 * so set up io addresses based on board type.
2744 printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__, __LINE__,
2745 pci_resource_start(devp, 0), pci_resource_start(devp, 1),
2746 pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
2750 * We have all resources from the board, so let's setup the actual
2751 * board structure now.
2755 brdp->ioaddr2 = pci_resource_start(devp, 0);
2756 brdp->ioaddr1 = pci_resource_start(devp, 1);
2759 brdp->ioaddr2 = pci_resource_start(devp, 2);
2760 brdp->ioaddr1 = pci_resource_start(devp, 1);
2763 brdp->ioaddr1 = pci_resource_start(devp, 2);
2764 brdp->ioaddr2 = pci_resource_start(devp, 1);
2767 printk("STALLION: unknown PCI board type=%d\n", brdtype);
2771 brdp->irq = devp->irq;
2777 /*****************************************************************************/
2780 * Find all Stallion PCI boards that might be installed. Initialize each
2781 * one as it is found.
2785 static inline int stl_findpcibrds()
2787 struct pci_dev *dev = NULL;
2791 printk("stl_findpcibrds()\n");
2794 for (i = 0; (i < stl_nrpcibrds); i++)
2795 while ((dev = pci_find_device(stl_pcibrds[i].vendid,
2796 stl_pcibrds[i].devid, dev))) {
2799 * Found a device on the PCI bus that has our vendor and
2800 * device ID. Need to check now that it is really us.
2802 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2805 rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
2815 /*****************************************************************************/
2818 * Scan through all the boards in the configuration and see what we
2819 * can find. Handle EIO and the ECH boards a little differently here
2820 * since the initial search and setup is too different.
2823 static inline int stl_initbrds()
2830 printk("stl_initbrds()\n");
2833 if (stl_nrbrds > STL_MAXBRDS) {
2834 printk("STALLION: too many boards in configuration table, "
2835 "truncating to %d\n", STL_MAXBRDS);
2836 stl_nrbrds = STL_MAXBRDS;
2840 * Firstly scan the list of static boards configured. Allocate
2841 * resources and initialize the boards as found.
2843 for (i = 0; (i < stl_nrbrds); i++) {
2844 confp = &stl_brdconf[i];
2846 stl_parsebrd(confp, stl_brdsp[i]);
2848 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2851 brdp->brdtype = confp->brdtype;
2852 brdp->ioaddr1 = confp->ioaddr1;
2853 brdp->ioaddr2 = confp->ioaddr2;
2854 brdp->irq = confp->irq;
2855 brdp->irqtype = confp->irqtype;
2860 * Find any dynamically supported boards. That is via module load
2861 * line options or auto-detected on the PCI bus.
2873 /*****************************************************************************/
2876 * Return the board stats structure to user app.
2879 static int stl_getbrdstats(combrd_t *bp)
2885 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2887 if (stl_brdstats.brd >= STL_MAXBRDS)
2889 brdp = stl_brds[stl_brdstats.brd];
2890 if (brdp == (stlbrd_t *) NULL)
2893 memset(&stl_brdstats, 0, sizeof(combrd_t));
2894 stl_brdstats.brd = brdp->brdnr;
2895 stl_brdstats.type = brdp->brdtype;
2896 stl_brdstats.hwid = brdp->hwid;
2897 stl_brdstats.state = brdp->state;
2898 stl_brdstats.ioaddr = brdp->ioaddr1;
2899 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2900 stl_brdstats.irq = brdp->irq;
2901 stl_brdstats.nrpanels = brdp->nrpanels;
2902 stl_brdstats.nrports = brdp->nrports;
2903 for (i = 0; (i < brdp->nrpanels); i++) {
2904 panelp = brdp->panels[i];
2905 stl_brdstats.panels[i].panel = i;
2906 stl_brdstats.panels[i].hwid = panelp->hwid;
2907 stl_brdstats.panels[i].nrports = panelp->nrports;
2910 return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
2913 /*****************************************************************************/
2916 * Resolve the referenced port number into a port struct pointer.
2919 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2924 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2925 return((stlport_t *) NULL);
2926 brdp = stl_brds[brdnr];
2927 if (brdp == (stlbrd_t *) NULL)
2928 return((stlport_t *) NULL);
2929 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2930 return((stlport_t *) NULL);
2931 panelp = brdp->panels[panelnr];
2932 if (panelp == (stlpanel_t *) NULL)
2933 return((stlport_t *) NULL);
2934 if ((portnr < 0) || (portnr >= panelp->nrports))
2935 return((stlport_t *) NULL);
2936 return(panelp->ports[portnr]);
2939 /*****************************************************************************/
2942 * Return the port stats structure to user app. A NULL port struct
2943 * pointer passed in means that we need to find out from the app
2944 * what port to get stats for (used through board control device).
2947 static int stl_getportstats(stlport_t *portp, comstats_t *cp)
2949 unsigned char *head, *tail;
2950 unsigned long flags;
2952 if (portp == (stlport_t *) NULL) {
2953 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2955 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2957 if (portp == (stlport_t *) NULL)
2961 portp->stats.state = portp->istate;
2962 portp->stats.flags = portp->flags;
2963 portp->stats.hwid = portp->hwid;
2965 portp->stats.ttystate = 0;
2966 portp->stats.cflags = 0;
2967 portp->stats.iflags = 0;
2968 portp->stats.oflags = 0;
2969 portp->stats.lflags = 0;
2970 portp->stats.rxbuffered = 0;
2974 if (portp->tty != (struct tty_struct *) NULL) {
2975 if (portp->tty->driver_data == portp) {
2976 portp->stats.ttystate = portp->tty->flags;
2977 portp->stats.rxbuffered = portp->tty->flip.count;
2978 if (portp->tty->termios != (struct termios *) NULL) {
2979 portp->stats.cflags = portp->tty->termios->c_cflag;
2980 portp->stats.iflags = portp->tty->termios->c_iflag;
2981 portp->stats.oflags = portp->tty->termios->c_oflag;
2982 portp->stats.lflags = portp->tty->termios->c_lflag;
2986 restore_flags(flags);
2988 head = portp->tx.head;
2989 tail = portp->tx.tail;
2990 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2991 (STL_TXBUFSIZE - (tail - head)));
2993 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2995 return copy_to_user(cp, &portp->stats,
2996 sizeof(comstats_t)) ? -EFAULT : 0;
2999 /*****************************************************************************/
3002 * Clear the port stats structure. We also return it zeroed out...
3005 static int stl_clrportstats(stlport_t *portp, comstats_t *cp)
3007 if (portp == (stlport_t *) NULL) {
3008 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
3010 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
3012 if (portp == (stlport_t *) NULL)
3016 memset(&portp->stats, 0, sizeof(comstats_t));
3017 portp->stats.brd = portp->brdnr;
3018 portp->stats.panel = portp->panelnr;
3019 portp->stats.port = portp->portnr;
3020 return copy_to_user(cp, &portp->stats,
3021 sizeof(comstats_t)) ? -EFAULT : 0;
3024 /*****************************************************************************/
3027 * Return the entire driver ports structure to a user app.
3030 static int stl_getportstruct(unsigned long arg)
3034 if (copy_from_user(&stl_dummyport, (void *) arg, sizeof(stlport_t)))
3036 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
3037 stl_dummyport.portnr);
3038 if (portp == (stlport_t *) NULL)
3040 return copy_to_user((void *)arg, portp,
3041 sizeof(stlport_t)) ? -EFAULT : 0;
3044 /*****************************************************************************/
3047 * Return the entire driver board structure to a user app.
3050 static int stl_getbrdstruct(unsigned long arg)
3054 if (copy_from_user(&stl_dummybrd, (void *) arg, sizeof(stlbrd_t)))
3056 if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
3058 brdp = stl_brds[stl_dummybrd.brdnr];
3059 if (brdp == (stlbrd_t *) NULL)
3061 return copy_to_user((void *)arg, brdp, sizeof(stlbrd_t)) ? -EFAULT : 0;
3064 /*****************************************************************************/
3067 * The "staliomem" device is also required to do some special operations
3068 * on the board and/or ports. In this driver it is mostly used for stats
3072 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
3077 printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
3078 (int) fp, cmd, (int) arg);
3081 brdnr = minor(ip->i_rdev);
3082 if (brdnr >= STL_MAXBRDS)
3087 case COM_GETPORTSTATS:
3088 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
3089 sizeof(comstats_t))) == 0)
3090 rc = stl_getportstats((stlport_t *) NULL,
3091 (comstats_t *) arg);
3093 case COM_CLRPORTSTATS:
3094 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
3095 sizeof(comstats_t))) == 0)
3096 rc = stl_clrportstats((stlport_t *) NULL,
3097 (comstats_t *) arg);
3099 case COM_GETBRDSTATS:
3100 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
3101 sizeof(combrd_t))) == 0)
3102 rc = stl_getbrdstats((combrd_t *) arg);
3105 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
3106 sizeof(stlport_t))) == 0)
3107 rc = stl_getportstruct(arg);
3110 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
3111 sizeof(stlbrd_t))) == 0)
3112 rc = stl_getbrdstruct(arg);
3122 static struct tty_operations stl_ops = {
3126 .put_char = stl_putchar,
3127 .flush_chars = stl_flushchars,
3128 .write_room = stl_writeroom,
3129 .chars_in_buffer = stl_charsinbuffer,
3131 .set_termios = stl_settermios,
3132 .throttle = stl_throttle,
3133 .unthrottle = stl_unthrottle,
3136 .hangup = stl_hangup,
3137 .flush_buffer = stl_flushbuffer,
3138 .break_ctl = stl_breakctl,
3139 .wait_until_sent = stl_waituntilsent,
3140 .send_xchar = stl_sendxchar,
3141 .read_proc = stl_readproc,
3144 /*****************************************************************************/
3146 int __init stl_init(void)
3149 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
3153 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
3158 * Allocate a temporary write buffer.
3160 stl_tmpwritebuf = (char *) stl_memalloc(STL_TXBUFSIZE);
3161 if (stl_tmpwritebuf == (char *) NULL)
3162 printk("STALLION: failed to allocate memory (size=%d)\n",
3166 * Set up a character driver for per board stuff. This is mainly used
3167 * to do stats ioctls on the ports.
3169 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
3170 printk("STALLION: failed to register serial board device\n");
3171 devfs_mk_dir("staliomem");
3173 for (i = 0; i < 4; i++) {
3174 devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR, i),
3175 S_IFCHR|S_IRUSR|S_IWUSR,
3176 &stl_fsiomem, NULL, "staliomem/%d", i);
3179 stl_serial->owner = THIS_MODULE;
3180 stl_serial->driver_name = stl_drvname;
3181 stl_serial->name = "ttyE";
3182 stl_serial->devfs_name = "tts/E";
3183 stl_serial->major = STL_SERIALMAJOR;
3184 stl_serial->minor_start = 0;
3185 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
3186 stl_serial->subtype = SERIAL_TYPE_NORMAL;
3187 stl_serial->init_termios = stl_deftermios;
3188 stl_serial->flags = TTY_DRIVER_REAL_RAW;
3189 tty_set_operations(stl_serial, &stl_ops);
3191 if (tty_register_driver(stl_serial)) {
3192 put_tty_driver(stl_serial);
3193 printk("STALLION: failed to register serial driver\n");
3200 /*****************************************************************************/
3201 /* CD1400 HARDWARE FUNCTIONS */
3202 /*****************************************************************************/
3205 * These functions get/set/update the registers of the cd1400 UARTs.
3206 * Access to the cd1400 registers is via an address/data io port pair.
3207 * (Maybe should make this inline...)
3210 static int stl_cd1400getreg(stlport_t *portp, int regnr)
3212 outb((regnr + portp->uartaddr), portp->ioaddr);
3213 return(inb(portp->ioaddr + EREG_DATA));
3216 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
3218 outb((regnr + portp->uartaddr), portp->ioaddr);
3219 outb(value, portp->ioaddr + EREG_DATA);
3222 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
3224 outb((regnr + portp->uartaddr), portp->ioaddr);
3225 if (inb(portp->ioaddr + EREG_DATA) != value) {
3226 outb(value, portp->ioaddr + EREG_DATA);
3232 /*****************************************************************************/
3235 * Inbitialize the UARTs in a panel. We don't care what sort of board
3236 * these ports are on - since the port io registers are almost
3237 * identical when dealing with ports.
3240 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3244 int nrchips, uartaddr, ioaddr;
3247 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
3250 BRDENABLE(panelp->brdnr, panelp->pagenr);
3253 * Check that each chip is present and started up OK.
3256 nrchips = panelp->nrports / CD1400_PORTS;
3257 for (i = 0; (i < nrchips); i++) {
3258 if (brdp->brdtype == BRD_ECHPCI) {
3259 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3260 ioaddr = panelp->iobase;
3262 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3264 uartaddr = (i & 0x01) ? 0x080 : 0;
3265 outb((GFRCR + uartaddr), ioaddr);
3266 outb(0, (ioaddr + EREG_DATA));
3267 outb((CCR + uartaddr), ioaddr);
3268 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3269 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3270 outb((GFRCR + uartaddr), ioaddr);
3271 for (j = 0; (j < CCR_MAXWAIT); j++) {
3272 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3275 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3276 printk("STALLION: cd1400 not responding, "
3277 "brd=%d panel=%d chip=%d\n",
3278 panelp->brdnr, panelp->panelnr, i);
3281 chipmask |= (0x1 << i);
3282 outb((PPR + uartaddr), ioaddr);
3283 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
3286 BRDDISABLE(panelp->brdnr);
3290 /*****************************************************************************/
3293 * Initialize hardware specific port registers.
3296 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3299 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3300 (int) brdp, (int) panelp, (int) portp);
3303 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
3304 (portp == (stlport_t *) NULL))
3307 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3308 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3309 portp->uartaddr = (portp->portnr & 0x04) << 5;
3310 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3312 BRDENABLE(portp->brdnr, portp->pagenr);
3313 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3314 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3315 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3316 BRDDISABLE(portp->brdnr);
3319 /*****************************************************************************/
3322 * Wait for the command register to be ready. We will poll this,
3323 * since it won't usually take too long to be ready.
3326 static void stl_cd1400ccrwait(stlport_t *portp)
3330 for (i = 0; (i < CCR_MAXWAIT); i++) {
3331 if (stl_cd1400getreg(portp, CCR) == 0) {
3336 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
3337 portp->portnr, portp->panelnr, portp->brdnr);
3340 /*****************************************************************************/
3343 * Set up the cd1400 registers for a port based on the termios port
3347 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3350 unsigned long flags;
3351 unsigned int clkdiv, baudrate;
3352 unsigned char cor1, cor2, cor3;
3353 unsigned char cor4, cor5, ccr;
3354 unsigned char srer, sreron, sreroff;
3355 unsigned char mcor1, mcor2, rtpr;
3356 unsigned char clk, div;
3372 brdp = stl_brds[portp->brdnr];
3373 if (brdp == (stlbrd_t *) NULL)
3377 * Set up the RX char ignore mask with those RX error types we
3378 * can ignore. We can get the cd1400 to help us out a little here,
3379 * it will ignore parity errors and breaks for us.
3381 portp->rxignoremsk = 0;
3382 if (tiosp->c_iflag & IGNPAR) {
3383 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
3384 cor1 |= COR1_PARIGNORE;
3386 if (tiosp->c_iflag & IGNBRK) {
3387 portp->rxignoremsk |= ST_BREAK;
3388 cor4 |= COR4_IGNBRK;
3391 portp->rxmarkmsk = ST_OVERRUN;
3392 if (tiosp->c_iflag & (INPCK | PARMRK))
3393 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3394 if (tiosp->c_iflag & BRKINT)
3395 portp->rxmarkmsk |= ST_BREAK;
3398 * Go through the char size, parity and stop bits and set all the
3399 * option register appropriately.
3401 switch (tiosp->c_cflag & CSIZE) {
3416 if (tiosp->c_cflag & CSTOPB)
3421 if (tiosp->c_cflag & PARENB) {
3422 if (tiosp->c_cflag & PARODD)
3423 cor1 |= (COR1_PARENB | COR1_PARODD);
3425 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3427 cor1 |= COR1_PARNONE;
3431 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3432 * space for hardware flow control and the like. This should be set to
3433 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3434 * really be based on VTIME.
3436 cor3 |= FIFO_RXTHRESHOLD;
3440 * Calculate the baud rate timers. For now we will just assume that
3441 * the input and output baud are the same. Could have used a baud
3442 * table here, but this way we can generate virtually any baud rate
3445 baudrate = tiosp->c_cflag & CBAUD;
3446 if (baudrate & CBAUDEX) {
3447 baudrate &= ~CBAUDEX;
3448 if ((baudrate < 1) || (baudrate > 4))
3449 tiosp->c_cflag &= ~CBAUDEX;
3453 baudrate = stl_baudrates[baudrate];
3454 if ((tiosp->c_cflag & CBAUD) == B38400) {
3455 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3457 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3459 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3461 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3463 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3464 baudrate = (portp->baud_base / portp->custom_divisor);
3466 if (baudrate > STL_CD1400MAXBAUD)
3467 baudrate = STL_CD1400MAXBAUD;
3470 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3471 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
3475 div = (unsigned char) clkdiv;
3479 * Check what form of modem signaling is required and set it up.
3481 if ((tiosp->c_cflag & CLOCAL) == 0) {
3484 sreron |= SRER_MODEM;
3485 portp->flags |= ASYNC_CHECK_CD;
3487 portp->flags &= ~ASYNC_CHECK_CD;
3491 * Setup cd1400 enhanced modes if we can. In particular we want to
3492 * handle as much of the flow control as possible automatically. As
3493 * well as saving a few CPU cycles it will also greatly improve flow
3494 * control reliability.
3496 if (tiosp->c_iflag & IXON) {
3499 if (tiosp->c_iflag & IXANY)
3503 if (tiosp->c_cflag & CRTSCTS) {
3505 mcor1 |= FIFO_RTSTHRESHOLD;
3509 * All cd1400 register values calculated so go through and set
3514 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3515 portp->portnr, portp->panelnr, portp->brdnr);
3516 printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3517 cor1, cor2, cor3, cor4, cor5);
3518 printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3519 mcor1, mcor2, rtpr, sreron, sreroff);
3520 printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3521 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3522 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3523 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3528 BRDENABLE(portp->brdnr, portp->pagenr);
3529 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3530 srer = stl_cd1400getreg(portp, SRER);
3531 stl_cd1400setreg(portp, SRER, 0);
3532 if (stl_cd1400updatereg(portp, COR1, cor1))
3534 if (stl_cd1400updatereg(portp, COR2, cor2))
3536 if (stl_cd1400updatereg(portp, COR3, cor3))
3539 stl_cd1400ccrwait(portp);
3540 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3542 stl_cd1400setreg(portp, COR4, cor4);
3543 stl_cd1400setreg(portp, COR5, cor5);
3544 stl_cd1400setreg(portp, MCOR1, mcor1);
3545 stl_cd1400setreg(portp, MCOR2, mcor2);
3547 stl_cd1400setreg(portp, TCOR, clk);
3548 stl_cd1400setreg(portp, TBPR, div);
3549 stl_cd1400setreg(portp, RCOR, clk);
3550 stl_cd1400setreg(portp, RBPR, div);
3552 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3553 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3554 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3555 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3556 stl_cd1400setreg(portp, RTPR, rtpr);
3557 mcor1 = stl_cd1400getreg(portp, MSVR1);
3558 if (mcor1 & MSVR1_DCD)
3559 portp->sigs |= TIOCM_CD;
3561 portp->sigs &= ~TIOCM_CD;
3562 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3563 BRDDISABLE(portp->brdnr);
3564 restore_flags(flags);
3567 /*****************************************************************************/
3570 * Set the state of the DTR and RTS signals.
3573 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3575 unsigned char msvr1, msvr2;
3576 unsigned long flags;
3579 printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
3580 (int) portp, dtr, rts);
3592 BRDENABLE(portp->brdnr, portp->pagenr);
3593 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3595 stl_cd1400setreg(portp, MSVR2, msvr2);
3597 stl_cd1400setreg(portp, MSVR1, msvr1);
3598 BRDDISABLE(portp->brdnr);
3599 restore_flags(flags);
3602 /*****************************************************************************/
3605 * Return the state of the signals.
3608 static int stl_cd1400getsignals(stlport_t *portp)
3610 unsigned char msvr1, msvr2;
3611 unsigned long flags;
3615 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3620 BRDENABLE(portp->brdnr, portp->pagenr);
3621 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3622 msvr1 = stl_cd1400getreg(portp, MSVR1);
3623 msvr2 = stl_cd1400getreg(portp, MSVR2);
3624 BRDDISABLE(portp->brdnr);
3625 restore_flags(flags);
3628 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3629 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3630 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3631 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3633 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3634 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3641 /*****************************************************************************/
3644 * Enable/Disable the Transmitter and/or Receiver.
3647 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3650 unsigned long flags;
3653 printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3654 (int) portp, rx, tx);
3659 ccr |= CCR_TXDISABLE;
3661 ccr |= CCR_TXENABLE;
3663 ccr |= CCR_RXDISABLE;
3665 ccr |= CCR_RXENABLE;
3669 BRDENABLE(portp->brdnr, portp->pagenr);
3670 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3671 stl_cd1400ccrwait(portp);
3672 stl_cd1400setreg(portp, CCR, ccr);
3673 stl_cd1400ccrwait(portp);
3674 BRDDISABLE(portp->brdnr);
3675 restore_flags(flags);
3678 /*****************************************************************************/
3681 * Start/stop the Transmitter and/or Receiver.
3684 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3686 unsigned char sreron, sreroff;
3687 unsigned long flags;
3690 printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3691 (int) portp, rx, tx);
3697 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3699 sreron |= SRER_TXDATA;
3701 sreron |= SRER_TXEMPTY;
3703 sreroff |= SRER_RXDATA;
3705 sreron |= SRER_RXDATA;
3709 BRDENABLE(portp->brdnr, portp->pagenr);
3710 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3711 stl_cd1400setreg(portp, SRER,
3712 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3713 BRDDISABLE(portp->brdnr);
3715 set_bit(ASYI_TXBUSY, &portp->istate);
3716 restore_flags(flags);
3719 /*****************************************************************************/
3722 * Disable all interrupts from this port.
3725 static void stl_cd1400disableintrs(stlport_t *portp)
3727 unsigned long flags;
3730 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3734 BRDENABLE(portp->brdnr, portp->pagenr);
3735 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3736 stl_cd1400setreg(portp, SRER, 0);
3737 BRDDISABLE(portp->brdnr);
3738 restore_flags(flags);
3741 /*****************************************************************************/
3743 static void stl_cd1400sendbreak(stlport_t *portp, int len)
3745 unsigned long flags;
3748 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
3753 BRDENABLE(portp->brdnr, portp->pagenr);
3754 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3755 stl_cd1400setreg(portp, SRER,
3756 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3758 BRDDISABLE(portp->brdnr);
3759 portp->brklen = len;
3761 portp->stats.txbreaks++;
3762 restore_flags(flags);
3765 /*****************************************************************************/
3768 * Take flow control actions...
3771 static void stl_cd1400flowctrl(stlport_t *portp, int state)
3773 struct tty_struct *tty;
3774 unsigned long flags;
3777 printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp, state);
3780 if (portp == (stlport_t *) NULL)
3783 if (tty == (struct tty_struct *) NULL)
3788 BRDENABLE(portp->brdnr, portp->pagenr);
3789 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3792 if (tty->termios->c_iflag & IXOFF) {
3793 stl_cd1400ccrwait(portp);
3794 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3795 portp->stats.rxxon++;
3796 stl_cd1400ccrwait(portp);
3799 * Question: should we return RTS to what it was before? It may
3800 * have been set by an ioctl... Suppose not, since if you have
3801 * hardware flow control set then it is pretty silly to go and
3802 * set the RTS line by hand.
3804 if (tty->termios->c_cflag & CRTSCTS) {
3805 stl_cd1400setreg(portp, MCOR1,
3806 (stl_cd1400getreg(portp, MCOR1) |
3807 FIFO_RTSTHRESHOLD));
3808 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3809 portp->stats.rxrtson++;
3812 if (tty->termios->c_iflag & IXOFF) {
3813 stl_cd1400ccrwait(portp);
3814 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3815 portp->stats.rxxoff++;
3816 stl_cd1400ccrwait(portp);
3818 if (tty->termios->c_cflag & CRTSCTS) {
3819 stl_cd1400setreg(portp, MCOR1,
3820 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3821 stl_cd1400setreg(portp, MSVR2, 0);
3822 portp->stats.rxrtsoff++;
3826 BRDDISABLE(portp->brdnr);
3827 restore_flags(flags);
3830 /*****************************************************************************/
3833 * Send a flow control character...
3836 static void stl_cd1400sendflow(stlport_t *portp, int state)
3838 struct tty_struct *tty;
3839 unsigned long flags;
3842 printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp, state);
3845 if (portp == (stlport_t *) NULL)
3848 if (tty == (struct tty_struct *) NULL)
3853 BRDENABLE(portp->brdnr, portp->pagenr);
3854 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3856 stl_cd1400ccrwait(portp);
3857 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3858 portp->stats.rxxon++;
3859 stl_cd1400ccrwait(portp);
3861 stl_cd1400ccrwait(portp);
3862 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3863 portp->stats.rxxoff++;
3864 stl_cd1400ccrwait(portp);
3866 BRDDISABLE(portp->brdnr);
3867 restore_flags(flags);
3870 /*****************************************************************************/
3872 static void stl_cd1400flush(stlport_t *portp)
3874 unsigned long flags;
3877 printk("stl_cd1400flush(portp=%x)\n", (int) portp);
3880 if (portp == (stlport_t *) NULL)
3885 BRDENABLE(portp->brdnr, portp->pagenr);
3886 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3887 stl_cd1400ccrwait(portp);
3888 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3889 stl_cd1400ccrwait(portp);
3890 portp->tx.tail = portp->tx.head;
3891 BRDDISABLE(portp->brdnr);
3892 restore_flags(flags);
3895 /*****************************************************************************/
3898 * Return the current state of data flow on this port. This is only
3899 * really interresting when determining if data has fully completed
3900 * transmission or not... This is easy for the cd1400, it accurately
3901 * maintains the busy port flag.
3904 static int stl_cd1400datastate(stlport_t *portp)
3907 printk("stl_cd1400datastate(portp=%x)\n", (int) portp);
3910 if (portp == (stlport_t *) NULL)
3913 return(test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0);
3916 /*****************************************************************************/
3919 * Interrupt service routine for cd1400 EasyIO boards.
3922 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3924 unsigned char svrtype;
3927 printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
3928 (int) panelp, iobase);
3932 svrtype = inb(iobase + EREG_DATA);
3933 if (panelp->nrports > 4) {
3934 outb((SVRR + 0x80), iobase);
3935 svrtype |= inb(iobase + EREG_DATA);
3938 if (svrtype & SVRR_RX)
3939 stl_cd1400rxisr(panelp, iobase);
3940 else if (svrtype & SVRR_TX)
3941 stl_cd1400txisr(panelp, iobase);
3942 else if (svrtype & SVRR_MDM)
3943 stl_cd1400mdmisr(panelp, iobase);
3946 /*****************************************************************************/
3949 * Interrupt service routine for cd1400 panels.
3952 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
3954 unsigned char svrtype;
3957 printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
3962 svrtype = inb(iobase + EREG_DATA);
3963 outb((SVRR + 0x80), iobase);
3964 svrtype |= inb(iobase + EREG_DATA);
3965 if (svrtype & SVRR_RX)
3966 stl_cd1400rxisr(panelp, iobase);
3967 else if (svrtype & SVRR_TX)
3968 stl_cd1400txisr(panelp, iobase);
3969 else if (svrtype & SVRR_MDM)
3970 stl_cd1400mdmisr(panelp, iobase);
3974 /*****************************************************************************/
3977 * Unfortunately we need to handle breaks in the TX data stream, since
3978 * this is the only way to generate them on the cd1400.
3981 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr)
3983 if (portp->brklen == 1) {
3984 outb((COR2 + portp->uartaddr), ioaddr);
3985 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
3986 (ioaddr + EREG_DATA));
3987 outb((TDR + portp->uartaddr), ioaddr);
3988 outb(ETC_CMD, (ioaddr + EREG_DATA));
3989 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
3990 outb((SRER + portp->uartaddr), ioaddr);
3991 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
3992 (ioaddr + EREG_DATA));
3994 } else if (portp->brklen > 1) {
3995 outb((TDR + portp->uartaddr), ioaddr);
3996 outb(ETC_CMD, (ioaddr + EREG_DATA));
3997 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
4001 outb((COR2 + portp->uartaddr), ioaddr);
4002 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
4003 (ioaddr + EREG_DATA));
4009 /*****************************************************************************/
4012 * Transmit interrupt handler. This has gotta be fast! Handling TX
4013 * chars is pretty simple, stuff as many as possible from the TX buffer
4014 * into the cd1400 FIFO. Must also handle TX breaks here, since they
4015 * are embedded as commands in the data stream. Oh no, had to use a goto!
4016 * This could be optimized more, will do when I get time...
4017 * In practice it is possible that interrupts are enabled but that the
4018 * port has been hung up. Need to handle not having any TX buffer here,
4019 * this is done by using the side effect that head and tail will also
4020 * be NULL if the buffer has been freed.
4023 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
4028 unsigned char ioack, srer;
4031 printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
4034 ioack = inb(ioaddr + EREG_TXACK);
4035 if (((ioack & panelp->ackmask) != 0) ||
4036 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
4037 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
4040 portp = panelp->ports[(ioack >> 3)];
4043 * Unfortunately we need to handle breaks in the data stream, since
4044 * this is the only way to generate them on the cd1400. Do it now if
4045 * a break is to be sent.
4047 if (portp->brklen != 0)
4048 if (stl_cd1400breakisr(portp, ioaddr))
4051 head = portp->tx.head;
4052 tail = portp->tx.tail;
4053 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4054 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4055 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4056 set_bit(ASYI_TXLOW, &portp->istate);
4057 schedule_work(&portp->tqueue);
4061 outb((SRER + portp->uartaddr), ioaddr);
4062 srer = inb(ioaddr + EREG_DATA);
4063 if (srer & SRER_TXDATA) {
4064 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
4066 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
4067 clear_bit(ASYI_TXBUSY, &portp->istate);
4069 outb(srer, (ioaddr + EREG_DATA));
4071 len = MIN(len, CD1400_TXFIFOSIZE);
4072 portp->stats.txtotal += len;
4073 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4074 outb((TDR + portp->uartaddr), ioaddr);
4075 outsb((ioaddr + EREG_DATA), tail, stlen);
4078 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4079 tail = portp->tx.buf;
4081 outsb((ioaddr + EREG_DATA), tail, len);
4084 portp->tx.tail = tail;
4088 outb((EOSRR + portp->uartaddr), ioaddr);
4089 outb(0, (ioaddr + EREG_DATA));
4092 /*****************************************************************************/
4095 * Receive character interrupt handler. Determine if we have good chars
4096 * or bad chars and then process appropriately. Good chars are easy
4097 * just shove the lot into the RX buffer and set all status byte to 0.
4098 * If a bad RX char then process as required. This routine needs to be
4099 * fast! In practice it is possible that we get an interrupt on a port
4100 * that is closed. This can happen on hangups - since they completely
4101 * shutdown a port not in user context. Need to handle this case.
4104 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
4107 struct tty_struct *tty;
4108 unsigned int ioack, len, buflen;
4109 unsigned char status;
4113 printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
4116 ioack = inb(ioaddr + EREG_RXACK);
4117 if ((ioack & panelp->ackmask) != 0) {
4118 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4121 portp = panelp->ports[(ioack >> 3)];
4124 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
4125 outb((RDCR + portp->uartaddr), ioaddr);
4126 len = inb(ioaddr + EREG_DATA);
4127 if ((tty == (struct tty_struct *) NULL) ||
4128 (tty->flip.char_buf_ptr == (char *) NULL) ||
4129 ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
4130 len = MIN(len, sizeof(stl_unwanted));
4131 outb((RDSR + portp->uartaddr), ioaddr);
4132 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
4133 portp->stats.rxlost += len;
4134 portp->stats.rxtotal += len;
4136 len = MIN(len, buflen);
4138 outb((RDSR + portp->uartaddr), ioaddr);
4139 insb((ioaddr + EREG_DATA), tty->flip.char_buf_ptr, len);
4140 memset(tty->flip.flag_buf_ptr, 0, len);
4141 tty->flip.flag_buf_ptr += len;
4142 tty->flip.char_buf_ptr += len;
4143 tty->flip.count += len;
4144 tty_schedule_flip(tty);
4145 portp->stats.rxtotal += len;
4148 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
4149 outb((RDSR + portp->uartaddr), ioaddr);
4150 status = inb(ioaddr + EREG_DATA);
4151 ch = inb(ioaddr + EREG_DATA);
4152 if (status & ST_PARITY)
4153 portp->stats.rxparity++;
4154 if (status & ST_FRAMING)
4155 portp->stats.rxframing++;
4156 if (status & ST_OVERRUN)
4157 portp->stats.rxoverrun++;
4158 if (status & ST_BREAK)
4159 portp->stats.rxbreaks++;
4160 if (status & ST_SCHARMASK) {
4161 if ((status & ST_SCHARMASK) == ST_SCHAR1)
4162 portp->stats.txxon++;
4163 if ((status & ST_SCHARMASK) == ST_SCHAR2)
4164 portp->stats.txxoff++;
4167 if ((tty != (struct tty_struct *) NULL) &&
4168 ((portp->rxignoremsk & status) == 0)) {
4169 if (portp->rxmarkmsk & status) {
4170 if (status & ST_BREAK) {
4172 if (portp->flags & ASYNC_SAK) {
4174 BRDENABLE(portp->brdnr, portp->pagenr);
4176 } else if (status & ST_PARITY) {
4177 status = TTY_PARITY;
4178 } else if (status & ST_FRAMING) {
4180 } else if(status & ST_OVERRUN) {
4181 status = TTY_OVERRUN;
4188 if (tty->flip.char_buf_ptr != (char *) NULL) {
4189 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
4190 *tty->flip.flag_buf_ptr++ = status;
4191 *tty->flip.char_buf_ptr++ = ch;
4194 tty_schedule_flip(tty);
4198 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4203 outb((EOSRR + portp->uartaddr), ioaddr);
4204 outb(0, (ioaddr + EREG_DATA));
4207 /*****************************************************************************/
4210 * Modem interrupt handler. The is called when the modem signal line
4211 * (DCD) has changed state. Leave most of the work to the off-level
4212 * processing routine.
4215 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
4222 printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp);
4225 ioack = inb(ioaddr + EREG_MDACK);
4226 if (((ioack & panelp->ackmask) != 0) ||
4227 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
4228 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
4231 portp = panelp->ports[(ioack >> 3)];
4233 outb((MISR + portp->uartaddr), ioaddr);
4234 misr = inb(ioaddr + EREG_DATA);
4235 if (misr & MISR_DCD) {
4236 set_bit(ASYI_DCDCHANGE, &portp->istate);
4237 schedule_task(&portp->tqueue);
4238 portp->stats.modem++;
4241 outb((EOSRR + portp->uartaddr), ioaddr);
4242 outb(0, (ioaddr + EREG_DATA));
4245 /*****************************************************************************/
4246 /* SC26198 HARDWARE FUNCTIONS */
4247 /*****************************************************************************/
4250 * These functions get/set/update the registers of the sc26198 UARTs.
4251 * Access to the sc26198 registers is via an address/data io port pair.
4252 * (Maybe should make this inline...)
4255 static int stl_sc26198getreg(stlport_t *portp, int regnr)
4257 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4258 return(inb(portp->ioaddr + XP_DATA));
4261 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
4263 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4264 outb(value, (portp->ioaddr + XP_DATA));
4267 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
4269 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4270 if (inb(portp->ioaddr + XP_DATA) != value) {
4271 outb(value, (portp->ioaddr + XP_DATA));
4277 /*****************************************************************************/
4280 * Functions to get and set the sc26198 global registers.
4283 static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
4285 outb(regnr, (portp->ioaddr + XP_ADDR));
4286 return(inb(portp->ioaddr + XP_DATA));
4290 static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
4292 outb(regnr, (portp->ioaddr + XP_ADDR));
4293 outb(value, (portp->ioaddr + XP_DATA));
4297 /*****************************************************************************/
4300 * Inbitialize the UARTs in a panel. We don't care what sort of board
4301 * these ports are on - since the port io registers are almost
4302 * identical when dealing with ports.
4305 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
4308 int nrchips, ioaddr;
4311 printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
4312 (int) brdp, (int) panelp);
4315 BRDENABLE(panelp->brdnr, panelp->pagenr);
4318 * Check that each chip is present and started up OK.
4321 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
4322 if (brdp->brdtype == BRD_ECHPCI)
4323 outb(panelp->pagenr, brdp->ioctrl);
4325 for (i = 0; (i < nrchips); i++) {
4326 ioaddr = panelp->iobase + (i * 4);
4327 outb(SCCR, (ioaddr + XP_ADDR));
4328 outb(CR_RESETALL, (ioaddr + XP_DATA));
4329 outb(TSTR, (ioaddr + XP_ADDR));
4330 if (inb(ioaddr + XP_DATA) != 0) {
4331 printk("STALLION: sc26198 not responding, "
4332 "brd=%d panel=%d chip=%d\n",
4333 panelp->brdnr, panelp->panelnr, i);
4336 chipmask |= (0x1 << i);
4337 outb(GCCR, (ioaddr + XP_ADDR));
4338 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
4339 outb(WDTRCR, (ioaddr + XP_ADDR));
4340 outb(0xff, (ioaddr + XP_DATA));
4343 BRDDISABLE(panelp->brdnr);
4347 /*****************************************************************************/
4350 * Initialize hardware specific port registers.
4353 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
4356 printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
4357 (int) brdp, (int) panelp, (int) portp);
4360 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
4361 (portp == (stlport_t *) NULL))
4364 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
4365 portp->uartaddr = (portp->portnr & 0x07) << 4;
4366 portp->pagenr = panelp->pagenr;
4369 BRDENABLE(portp->brdnr, portp->pagenr);
4370 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
4371 BRDDISABLE(portp->brdnr);
4374 /*****************************************************************************/
4377 * Set up the sc26198 registers for a port based on the termios port
4381 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4384 unsigned long flags;
4385 unsigned int baudrate;
4386 unsigned char mr0, mr1, mr2, clk;
4387 unsigned char imron, imroff, iopr, ipr;
4397 brdp = stl_brds[portp->brdnr];
4398 if (brdp == (stlbrd_t *) NULL)
4402 * Set up the RX char ignore mask with those RX error types we
4405 portp->rxignoremsk = 0;
4406 if (tiosp->c_iflag & IGNPAR)
4407 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
4409 if (tiosp->c_iflag & IGNBRK)
4410 portp->rxignoremsk |= SR_RXBREAK;
4412 portp->rxmarkmsk = SR_RXOVERRUN;
4413 if (tiosp->c_iflag & (INPCK | PARMRK))
4414 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
4415 if (tiosp->c_iflag & BRKINT)
4416 portp->rxmarkmsk |= SR_RXBREAK;
4419 * Go through the char size, parity and stop bits and set all the
4420 * option register appropriately.
4422 switch (tiosp->c_cflag & CSIZE) {
4437 if (tiosp->c_cflag & CSTOPB)
4442 if (tiosp->c_cflag & PARENB) {
4443 if (tiosp->c_cflag & PARODD)
4444 mr1 |= (MR1_PARENB | MR1_PARODD);
4446 mr1 |= (MR1_PARENB | MR1_PAREVEN);
4451 mr1 |= MR1_ERRBLOCK;
4454 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4455 * space for hardware flow control and the like. This should be set to
4458 mr2 |= MR2_RXFIFOHALF;
4461 * Calculate the baud rate timers. For now we will just assume that
4462 * the input and output baud are the same. The sc26198 has a fixed
4463 * baud rate table, so only discrete baud rates possible.
4465 baudrate = tiosp->c_cflag & CBAUD;
4466 if (baudrate & CBAUDEX) {
4467 baudrate &= ~CBAUDEX;
4468 if ((baudrate < 1) || (baudrate > 4))
4469 tiosp->c_cflag &= ~CBAUDEX;
4473 baudrate = stl_baudrates[baudrate];
4474 if ((tiosp->c_cflag & CBAUD) == B38400) {
4475 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
4477 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
4479 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
4481 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
4483 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
4484 baudrate = (portp->baud_base / portp->custom_divisor);
4486 if (baudrate > STL_SC26198MAXBAUD)
4487 baudrate = STL_SC26198MAXBAUD;
4490 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
4491 if (baudrate <= sc26198_baudtable[clk])
4497 * Check what form of modem signaling is required and set it up.
4499 if (tiosp->c_cflag & CLOCAL) {
4500 portp->flags &= ~ASYNC_CHECK_CD;
4502 iopr |= IOPR_DCDCOS;
4504 portp->flags |= ASYNC_CHECK_CD;
4508 * Setup sc26198 enhanced modes if we can. In particular we want to
4509 * handle as much of the flow control as possible automatically. As
4510 * well as saving a few CPU cycles it will also greatly improve flow
4511 * control reliability.
4513 if (tiosp->c_iflag & IXON) {
4514 mr0 |= MR0_SWFTX | MR0_SWFT;
4515 imron |= IR_XONXOFF;
4517 imroff |= IR_XONXOFF;
4519 if (tiosp->c_iflag & IXOFF)
4522 if (tiosp->c_cflag & CRTSCTS) {
4528 * All sc26198 register values calculated so go through and set
4533 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4534 portp->portnr, portp->panelnr, portp->brdnr);
4535 printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4536 printk(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4537 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4538 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4539 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4544 BRDENABLE(portp->brdnr, portp->pagenr);
4545 stl_sc26198setreg(portp, IMR, 0);
4546 stl_sc26198updatereg(portp, MR0, mr0);
4547 stl_sc26198updatereg(portp, MR1, mr1);
4548 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4549 stl_sc26198updatereg(portp, MR2, mr2);
4550 stl_sc26198updatereg(portp, IOPIOR,
4551 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
4554 stl_sc26198setreg(portp, TXCSR, clk);
4555 stl_sc26198setreg(portp, RXCSR, clk);
4558 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4559 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4561 ipr = stl_sc26198getreg(portp, IPR);
4563 portp->sigs &= ~TIOCM_CD;
4565 portp->sigs |= TIOCM_CD;
4567 portp->imr = (portp->imr & ~imroff) | imron;
4568 stl_sc26198setreg(portp, IMR, portp->imr);
4569 BRDDISABLE(portp->brdnr);
4570 restore_flags(flags);
4573 /*****************************************************************************/
4576 * Set the state of the DTR and RTS signals.
4579 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
4581 unsigned char iopioron, iopioroff;
4582 unsigned long flags;
4585 printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4586 (int) portp, dtr, rts);
4592 iopioroff |= IPR_DTR;
4594 iopioron |= IPR_DTR;
4596 iopioroff |= IPR_RTS;
4598 iopioron |= IPR_RTS;
4602 BRDENABLE(portp->brdnr, portp->pagenr);
4603 stl_sc26198setreg(portp, IOPIOR,
4604 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4605 BRDDISABLE(portp->brdnr);
4606 restore_flags(flags);
4609 /*****************************************************************************/
4612 * Return the state of the signals.
4615 static int stl_sc26198getsignals(stlport_t *portp)
4618 unsigned long flags;
4622 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
4627 BRDENABLE(portp->brdnr, portp->pagenr);
4628 ipr = stl_sc26198getreg(portp, IPR);
4629 BRDDISABLE(portp->brdnr);
4630 restore_flags(flags);
4633 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4634 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4635 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4636 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4641 /*****************************************************************************/
4644 * Enable/Disable the Transmitter and/or Receiver.
4647 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
4650 unsigned long flags;
4653 printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4654 (int) portp, rx, tx);
4657 ccr = portp->crenable;
4659 ccr &= ~CR_TXENABLE;
4663 ccr &= ~CR_RXENABLE;
4669 BRDENABLE(portp->brdnr, portp->pagenr);
4670 stl_sc26198setreg(portp, SCCR, ccr);
4671 BRDDISABLE(portp->brdnr);
4672 portp->crenable = ccr;
4673 restore_flags(flags);
4676 /*****************************************************************************/
4679 * Start/stop the Transmitter and/or Receiver.
4682 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
4685 unsigned long flags;
4688 printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4689 (int) portp, rx, tx);
4698 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4700 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4704 BRDENABLE(portp->brdnr, portp->pagenr);
4705 stl_sc26198setreg(portp, IMR, imr);
4706 BRDDISABLE(portp->brdnr);
4709 set_bit(ASYI_TXBUSY, &portp->istate);
4710 restore_flags(flags);
4713 /*****************************************************************************/
4716 * Disable all interrupts from this port.
4719 static void stl_sc26198disableintrs(stlport_t *portp)
4721 unsigned long flags;
4724 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
4729 BRDENABLE(portp->brdnr, portp->pagenr);
4731 stl_sc26198setreg(portp, IMR, 0);
4732 BRDDISABLE(portp->brdnr);
4733 restore_flags(flags);
4736 /*****************************************************************************/
4738 static void stl_sc26198sendbreak(stlport_t *portp, int len)
4740 unsigned long flags;
4743 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
4748 BRDENABLE(portp->brdnr, portp->pagenr);
4750 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4751 portp->stats.txbreaks++;
4753 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4755 BRDDISABLE(portp->brdnr);
4756 restore_flags(flags);
4759 /*****************************************************************************/
4762 * Take flow control actions...
4765 static void stl_sc26198flowctrl(stlport_t *portp, int state)
4767 struct tty_struct *tty;
4768 unsigned long flags;
4772 printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp, state);
4775 if (portp == (stlport_t *) NULL)
4778 if (tty == (struct tty_struct *) NULL)
4783 BRDENABLE(portp->brdnr, portp->pagenr);
4786 if (tty->termios->c_iflag & IXOFF) {
4787 mr0 = stl_sc26198getreg(portp, MR0);
4788 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4789 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4791 portp->stats.rxxon++;
4792 stl_sc26198wait(portp);
4793 stl_sc26198setreg(portp, MR0, mr0);
4796 * Question: should we return RTS to what it was before? It may
4797 * have been set by an ioctl... Suppose not, since if you have
4798 * hardware flow control set then it is pretty silly to go and
4799 * set the RTS line by hand.
4801 if (tty->termios->c_cflag & CRTSCTS) {
4802 stl_sc26198setreg(portp, MR1,
4803 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4804 stl_sc26198setreg(portp, IOPIOR,
4805 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4806 portp->stats.rxrtson++;
4809 if (tty->termios->c_iflag & IXOFF) {
4810 mr0 = stl_sc26198getreg(portp, MR0);
4811 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4812 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4814 portp->stats.rxxoff++;
4815 stl_sc26198wait(portp);
4816 stl_sc26198setreg(portp, MR0, mr0);
4818 if (tty->termios->c_cflag & CRTSCTS) {
4819 stl_sc26198setreg(portp, MR1,
4820 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4821 stl_sc26198setreg(portp, IOPIOR,
4822 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4823 portp->stats.rxrtsoff++;
4827 BRDDISABLE(portp->brdnr);
4828 restore_flags(flags);
4831 /*****************************************************************************/
4834 * Send a flow control character.
4837 static void stl_sc26198sendflow(stlport_t *portp, int state)
4839 struct tty_struct *tty;
4840 unsigned long flags;
4844 printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp, state);
4847 if (portp == (stlport_t *) NULL)
4850 if (tty == (struct tty_struct *) NULL)
4855 BRDENABLE(portp->brdnr, portp->pagenr);
4857 mr0 = stl_sc26198getreg(portp, MR0);
4858 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4859 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4861 portp->stats.rxxon++;
4862 stl_sc26198wait(portp);
4863 stl_sc26198setreg(portp, MR0, mr0);
4865 mr0 = stl_sc26198getreg(portp, MR0);
4866 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4867 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4869 portp->stats.rxxoff++;
4870 stl_sc26198wait(portp);
4871 stl_sc26198setreg(portp, MR0, mr0);
4873 BRDDISABLE(portp->brdnr);
4874 restore_flags(flags);
4877 /*****************************************************************************/
4879 static void stl_sc26198flush(stlport_t *portp)
4881 unsigned long flags;
4884 printk("stl_sc26198flush(portp=%x)\n", (int) portp);
4887 if (portp == (stlport_t *) NULL)
4892 BRDENABLE(portp->brdnr, portp->pagenr);
4893 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4894 stl_sc26198setreg(portp, SCCR, portp->crenable);
4895 BRDDISABLE(portp->brdnr);
4896 portp->tx.tail = portp->tx.head;
4897 restore_flags(flags);
4900 /*****************************************************************************/
4903 * Return the current state of data flow on this port. This is only
4904 * really interresting when determining if data has fully completed
4905 * transmission or not... The sc26198 interrupt scheme cannot
4906 * determine when all data has actually drained, so we need to
4907 * check the port statusy register to be sure.
4910 static int stl_sc26198datastate(stlport_t *portp)
4912 unsigned long flags;
4916 printk("stl_sc26198datastate(portp=%x)\n", (int) portp);
4919 if (portp == (stlport_t *) NULL)
4921 if (test_bit(ASYI_TXBUSY, &portp->istate))
4926 BRDENABLE(portp->brdnr, portp->pagenr);
4927 sr = stl_sc26198getreg(portp, SR);
4928 BRDDISABLE(portp->brdnr);
4929 restore_flags(flags);
4931 return((sr & SR_TXEMPTY) ? 0 : 1);
4934 /*****************************************************************************/
4937 * Delay for a small amount of time, to give the sc26198 a chance
4938 * to process a command...
4941 static void stl_sc26198wait(stlport_t *portp)
4946 printk("stl_sc26198wait(portp=%x)\n", (int) portp);
4949 if (portp == (stlport_t *) NULL)
4952 for (i = 0; (i < 20); i++)
4953 stl_sc26198getglobreg(portp, TSTR);
4956 /*****************************************************************************/
4959 * If we are TX flow controlled and in IXANY mode then we may
4960 * need to unflow control here. We gotta do this because of the
4961 * automatic flow control modes of the sc26198.
4964 static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty)
4968 mr0 = stl_sc26198getreg(portp, MR0);
4969 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4970 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4971 stl_sc26198wait(portp);
4972 stl_sc26198setreg(portp, MR0, mr0);
4973 clear_bit(ASYI_TXFLOWED, &portp->istate);
4976 /*****************************************************************************/
4979 * Interrupt service routine for sc26198 panels.
4982 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4988 * Work around bug in sc26198 chip... Cannot have A6 address
4989 * line of UART high, else iack will be returned as 0.
4991 outb(0, (iobase + 1));
4993 iack = inb(iobase + XP_IACK);
4994 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4996 if (iack & IVR_RXDATA)
4997 stl_sc26198rxisr(portp, iack);
4998 else if (iack & IVR_TXDATA)
4999 stl_sc26198txisr(portp);
5001 stl_sc26198otherisr(portp, iack);
5004 /*****************************************************************************/
5007 * Transmit interrupt handler. This has gotta be fast! Handling TX
5008 * chars is pretty simple, stuff as many as possible from the TX buffer
5009 * into the sc26198 FIFO.
5010 * In practice it is possible that interrupts are enabled but that the
5011 * port has been hung up. Need to handle not having any TX buffer here,
5012 * this is done by using the side effect that head and tail will also
5013 * be NULL if the buffer has been freed.
5016 static void stl_sc26198txisr(stlport_t *portp)
5018 unsigned int ioaddr;
5024 printk("stl_sc26198txisr(portp=%x)\n", (int) portp);
5027 ioaddr = portp->ioaddr;
5028 head = portp->tx.head;
5029 tail = portp->tx.tail;
5030 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
5031 if ((len == 0) || ((len < STL_TXBUFLOW) &&
5032 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
5033 set_bit(ASYI_TXLOW, &portp->istate);
5034 schedule_task(&portp->tqueue);
5038 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
5039 mr0 = inb(ioaddr + XP_DATA);
5040 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
5041 portp->imr &= ~IR_TXRDY;
5042 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
5043 outb(portp->imr, (ioaddr + XP_DATA));
5044 clear_bit(ASYI_TXBUSY, &portp->istate);
5046 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
5047 outb(mr0, (ioaddr + XP_DATA));
5050 len = MIN(len, SC26198_TXFIFOSIZE);
5051 portp->stats.txtotal += len;
5052 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
5053 outb(GTXFIFO, (ioaddr + XP_ADDR));
5054 outsb((ioaddr + XP_DATA), tail, stlen);
5057 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
5058 tail = portp->tx.buf;
5060 outsb((ioaddr + XP_DATA), tail, len);
5063 portp->tx.tail = tail;
5067 /*****************************************************************************/
5070 * Receive character interrupt handler. Determine if we have good chars
5071 * or bad chars and then process appropriately. Good chars are easy
5072 * just shove the lot into the RX buffer and set all status byte to 0.
5073 * If a bad RX char then process as required. This routine needs to be
5074 * fast! In practice it is possible that we get an interrupt on a port
5075 * that is closed. This can happen on hangups - since they completely
5076 * shutdown a port not in user context. Need to handle this case.
5079 static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
5081 struct tty_struct *tty;
5082 unsigned int len, buflen, ioaddr;
5085 printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
5089 ioaddr = portp->ioaddr;
5090 outb(GIBCR, (ioaddr + XP_ADDR));
5091 len = inb(ioaddr + XP_DATA) + 1;
5093 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
5094 if ((tty == (struct tty_struct *) NULL) ||
5095 (tty->flip.char_buf_ptr == (char *) NULL) ||
5096 ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
5097 len = MIN(len, sizeof(stl_unwanted));
5098 outb(GRXFIFO, (ioaddr + XP_ADDR));
5099 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
5100 portp->stats.rxlost += len;
5101 portp->stats.rxtotal += len;
5103 len = MIN(len, buflen);
5105 outb(GRXFIFO, (ioaddr + XP_ADDR));
5106 insb((ioaddr + XP_DATA), tty->flip.char_buf_ptr, len);
5107 memset(tty->flip.flag_buf_ptr, 0, len);
5108 tty->flip.flag_buf_ptr += len;
5109 tty->flip.char_buf_ptr += len;
5110 tty->flip.count += len;
5111 tty_schedule_flip(tty);
5112 portp->stats.rxtotal += len;
5116 stl_sc26198rxbadchars(portp);
5120 * If we are TX flow controlled and in IXANY mode then we may need
5121 * to unflow control here. We gotta do this because of the automatic
5122 * flow control modes of the sc26198.
5124 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
5125 if ((tty != (struct tty_struct *) NULL) &&
5126 (tty->termios != (struct termios *) NULL) &&
5127 (tty->termios->c_iflag & IXANY)) {
5128 stl_sc26198txunflow(portp, tty);
5133 /*****************************************************************************/
5136 * Process an RX bad character.
5139 static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch)
5141 struct tty_struct *tty;
5142 unsigned int ioaddr;
5145 ioaddr = portp->ioaddr;
5147 if (status & SR_RXPARITY)
5148 portp->stats.rxparity++;
5149 if (status & SR_RXFRAMING)
5150 portp->stats.rxframing++;
5151 if (status & SR_RXOVERRUN)
5152 portp->stats.rxoverrun++;
5153 if (status & SR_RXBREAK)
5154 portp->stats.rxbreaks++;
5156 if ((tty != (struct tty_struct *) NULL) &&
5157 ((portp->rxignoremsk & status) == 0)) {
5158 if (portp->rxmarkmsk & status) {
5159 if (status & SR_RXBREAK) {
5161 if (portp->flags & ASYNC_SAK) {
5163 BRDENABLE(portp->brdnr, portp->pagenr);
5165 } else if (status & SR_RXPARITY) {
5166 status = TTY_PARITY;
5167 } else if (status & SR_RXFRAMING) {
5169 } else if(status & SR_RXOVERRUN) {
5170 status = TTY_OVERRUN;
5178 if (tty->flip.char_buf_ptr != (char *) NULL) {
5179 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
5180 *tty->flip.flag_buf_ptr++ = status;
5181 *tty->flip.char_buf_ptr++ = ch;
5184 tty_schedule_flip(tty);
5188 portp->stats.rxtotal++;
5192 /*****************************************************************************/
5195 * Process all characters in the RX FIFO of the UART. Check all char
5196 * status bytes as well, and process as required. We need to check
5197 * all bytes in the FIFO, in case some more enter the FIFO while we
5198 * are here. To get the exact character error type we need to switch
5199 * into CHAR error mode (that is why we need to make sure we empty
5203 static void stl_sc26198rxbadchars(stlport_t *portp)
5205 unsigned char status, mr1;
5209 * To get the precise error type for each character we must switch
5210 * back into CHAR error mode.
5212 mr1 = stl_sc26198getreg(portp, MR1);
5213 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
5215 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
5216 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
5217 ch = stl_sc26198getreg(portp, RXFIFO);
5218 stl_sc26198rxbadch(portp, status, ch);
5222 * To get correct interrupt class we must switch back into BLOCK
5225 stl_sc26198setreg(portp, MR1, mr1);
5228 /*****************************************************************************/
5231 * Other interrupt handler. This includes modem signals, flow
5232 * control actions, etc. Most stuff is left to off-level interrupt
5236 static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
5238 unsigned char cir, ipr, xisr;
5241 printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
5244 cir = stl_sc26198getglobreg(portp, CIR);
5246 switch (cir & CIR_SUBTYPEMASK) {
5248 ipr = stl_sc26198getreg(portp, IPR);
5249 if (ipr & IPR_DCDCHANGE) {
5250 set_bit(ASYI_DCDCHANGE, &portp->istate);
5251 schedule_task(&portp->tqueue);
5252 portp->stats.modem++;
5255 case CIR_SUBXONXOFF:
5256 xisr = stl_sc26198getreg(portp, XISR);
5257 if (xisr & XISR_RXXONGOT) {
5258 set_bit(ASYI_TXFLOWED, &portp->istate);
5259 portp->stats.txxoff++;
5261 if (xisr & XISR_RXXOFFGOT) {
5262 clear_bit(ASYI_TXFLOWED, &portp->istate);
5263 portp->stats.txxon++;
5267 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
5268 stl_sc26198rxbadchars(portp);
5275 /*****************************************************************************/