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/slab.h>
32 #include <linux/interrupt.h>
33 #include <linux/tty.h>
34 #include <linux/tty_flip.h>
35 #include <linux/serial.h>
36 #include <linux/cd1400.h>
37 #include <linux/sc26198.h>
38 #include <linux/comstats.h>
39 #include <linux/stallion.h>
40 #include <linux/ioport.h>
41 #include <linux/init.h>
42 #include <linux/smp_lock.h>
43 #include <linux/devfs_fs_kernel.h>
44 #include <linux/device.h>
47 #include <asm/uaccess.h>
50 #include <linux/pci.h>
53 /*****************************************************************************/
56 * Define different board types. Use the standard Stallion "assigned"
57 * board numbers. Boards supported in this driver are abbreviated as
58 * EIO = EasyIO and ECH = EasyConnection 8/32.
64 #define BRD_ECH64PCI 27
65 #define BRD_EASYIOPCI 28
68 * Define a configuration structure to hold the board configuration.
69 * Need to set this up in the code (for now) with the boards that are
70 * to be configured into the system. This is what needs to be modified
71 * when adding/removing/modifying boards. Each line entry in the
72 * stl_brdconf[] array is a board. Each line contains io/irq/memory
73 * ranges for that board (as well as what type of board it is).
75 * { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
76 * This line would configure an EasyIO board (4 or 8, no difference),
77 * at io address 2a0 and irq 10.
79 * { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
80 * This line will configure an EasyConnection 8/32 board at primary io
81 * address 2a8, secondary io address 280 and irq 12.
82 * Enter as many lines into this array as you want (only the first 4
83 * will actually be used!). Any combination of EasyIO and EasyConnection
84 * boards can be specified. EasyConnection 8/32 boards can share their
85 * secondary io addresses between each other.
87 * NOTE: there is no need to put any entries in this table for PCI
88 * boards. They will be found automatically by the driver - provided
89 * PCI BIOS32 support is compiled into the kernel.
96 unsigned long memaddr;
101 static stlconf_t stl_brdconf[] = {
102 /*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
105 static int stl_nrbrds = sizeof(stl_brdconf) / sizeof(stlconf_t);
107 /*****************************************************************************/
110 * Define some important driver characteristics. Device major numbers
111 * allocated as per Linux Device Registry.
113 #ifndef STL_SIOMEMMAJOR
114 #define STL_SIOMEMMAJOR 28
116 #ifndef STL_SERIALMAJOR
117 #define STL_SERIALMAJOR 24
119 #ifndef STL_CALLOUTMAJOR
120 #define STL_CALLOUTMAJOR 25
124 * Set the TX buffer size. Bigger is better, but we don't want
125 * to chew too much memory with buffers!
127 #define STL_TXBUFLOW 512
128 #define STL_TXBUFSIZE 4096
130 /*****************************************************************************/
133 * Define our local driver identity first. Set up stuff to deal with
134 * all the local structures required by a serial tty driver.
136 static char *stl_drvtitle = "Stallion Multiport Serial Driver";
137 static char *stl_drvname = "stallion";
138 static char *stl_drvversion = "5.6.0";
140 static struct tty_driver *stl_serial;
143 * We will need to allocate a temporary write buffer for chars that
144 * come direct from user space. The problem is that a copy from user
145 * space might cause a page fault (typically on a system that is
146 * swapping!). All ports will share one buffer - since if the system
147 * is already swapping a shared buffer won't make things any worse.
149 static char *stl_tmpwritebuf;
150 static DECLARE_MUTEX(stl_tmpwritesem);
153 * Define a local default termios struct. All ports will be created
154 * with this termios initially. Basically all it defines is a raw port
155 * at 9600, 8 data bits, 1 stop bit.
157 static struct termios stl_deftermios = {
158 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
163 * Define global stats structures. Not used often, and can be
164 * re-used for each stats call.
166 static comstats_t stl_comstats;
167 static combrd_t stl_brdstats;
168 static stlbrd_t stl_dummybrd;
169 static stlport_t stl_dummyport;
172 * Define global place to put buffer overflow characters.
174 static char stl_unwanted[SC26198_RXFIFOSIZE];
177 * Keep track of what interrupts we have requested for us.
178 * We don't need to request an interrupt twice if it is being
179 * shared with another Stallion board.
181 static int stl_gotintrs[STL_MAXBRDS];
182 static int stl_numintrs;
184 /*****************************************************************************/
186 static stlbrd_t *stl_brds[STL_MAXBRDS];
189 * Per board state flags. Used with the state field of the board struct.
190 * Not really much here!
192 #define BRD_FOUND 0x1
195 * Define the port structure istate flags. These set of flags are
196 * modified at interrupt time - so setting and reseting them needs
197 * to be atomic. Use the bit clear/setting routines for this.
199 #define ASYI_TXBUSY 1
201 #define ASYI_DCDCHANGE 3
202 #define ASYI_TXFLOWED 4
205 * Define an array of board names as printable strings. Handy for
206 * referencing boards when printing trace and stuff.
208 static char *stl_brdnames[] = {
240 /*****************************************************************************/
244 * Define some string labels for arguments passed from the module
245 * load line. These allow for easy board definitions, and easy
246 * modification of the io, memory and irq resoucres.
249 static char *board0[4];
250 static char *board1[4];
251 static char *board2[4];
252 static char *board3[4];
254 static char **stl_brdsp[] = {
262 * Define a set of common board names, and types. This is used to
263 * parse any module arguments.
266 typedef struct stlbrdtype {
271 static stlbrdtype_t stl_brdstr[] = {
272 { "easyio", BRD_EASYIO },
273 { "eio", BRD_EASYIO },
274 { "20", BRD_EASYIO },
275 { "ec8/32", BRD_ECH },
276 { "ec8/32-at", BRD_ECH },
277 { "ec8/32-isa", BRD_ECH },
279 { "echat", BRD_ECH },
281 { "ec8/32-mc", BRD_ECHMC },
282 { "ec8/32-mca", BRD_ECHMC },
283 { "echmc", BRD_ECHMC },
284 { "echmca", BRD_ECHMC },
286 { "ec8/32-pc", BRD_ECHPCI },
287 { "ec8/32-pci", BRD_ECHPCI },
288 { "26", BRD_ECHPCI },
289 { "ec8/64-pc", BRD_ECH64PCI },
290 { "ec8/64-pci", BRD_ECH64PCI },
291 { "ech-pci", BRD_ECH64PCI },
292 { "echpci", BRD_ECH64PCI },
293 { "echpc", BRD_ECH64PCI },
294 { "27", BRD_ECH64PCI },
295 { "easyio-pc", BRD_EASYIOPCI },
296 { "easyio-pci", BRD_EASYIOPCI },
297 { "eio-pci", BRD_EASYIOPCI },
298 { "eiopci", BRD_EASYIOPCI },
299 { "28", BRD_EASYIOPCI },
303 * Define the module agruments.
305 MODULE_AUTHOR("Greg Ungerer");
306 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
307 MODULE_LICENSE("GPL");
309 MODULE_PARM(board0, "1-4s");
310 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
311 MODULE_PARM(board1, "1-4s");
312 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
313 MODULE_PARM(board2, "1-4s");
314 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
315 MODULE_PARM(board3, "1-4s");
316 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
320 /*****************************************************************************/
323 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
324 * to the directly accessible io ports of these boards (not the uarts -
325 * they are in cd1400.h and sc26198.h).
327 #define EIO_8PORTRS 0x04
328 #define EIO_4PORTRS 0x05
329 #define EIO_8PORTDI 0x00
330 #define EIO_8PORTM 0x06
332 #define EIO_IDBITMASK 0x07
334 #define EIO_BRDMASK 0xf0
337 #define ID_BRD16 0x30
339 #define EIO_INTRPEND 0x08
340 #define EIO_INTEDGE 0x00
341 #define EIO_INTLEVEL 0x08
345 #define ECH_IDBITMASK 0xe0
346 #define ECH_BRDENABLE 0x08
347 #define ECH_BRDDISABLE 0x00
348 #define ECH_INTENABLE 0x01
349 #define ECH_INTDISABLE 0x00
350 #define ECH_INTLEVEL 0x02
351 #define ECH_INTEDGE 0x00
352 #define ECH_INTRPEND 0x01
353 #define ECH_BRDRESET 0x01
355 #define ECHMC_INTENABLE 0x01
356 #define ECHMC_BRDRESET 0x02
358 #define ECH_PNLSTATUS 2
359 #define ECH_PNL16PORT 0x20
360 #define ECH_PNLIDMASK 0x07
361 #define ECH_PNLXPID 0x40
362 #define ECH_PNLINTRPEND 0x80
364 #define ECH_ADDR2MASK 0x1e0
367 * Define the vector mapping bits for the programmable interrupt board
368 * hardware. These bits encode the interrupt for the board to use - it
369 * is software selectable (except the EIO-8M).
371 static unsigned char stl_vecmap[] = {
372 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
373 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
377 * Set up enable and disable macros for the ECH boards. They require
378 * the secondary io address space to be activated and deactivated.
379 * This way all ECH boards can share their secondary io region.
380 * If this is an ECH-PCI board then also need to set the page pointer
381 * to point to the correct page.
383 #define BRDENABLE(brdnr,pagenr) \
384 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
385 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
386 stl_brds[(brdnr)]->ioctrl); \
387 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
388 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
390 #define BRDDISABLE(brdnr) \
391 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
392 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
393 stl_brds[(brdnr)]->ioctrl);
395 #define STL_CD1400MAXBAUD 230400
396 #define STL_SC26198MAXBAUD 460800
398 #define STL_BAUDBASE 115200
399 #define STL_CLOSEDELAY (5 * HZ / 10)
401 /*****************************************************************************/
406 * Define the Stallion PCI vendor and device IDs.
408 #ifndef PCI_VENDOR_ID_STALLION
409 #define PCI_VENDOR_ID_STALLION 0x124d
411 #ifndef PCI_DEVICE_ID_ECHPCI832
412 #define PCI_DEVICE_ID_ECHPCI832 0x0000
414 #ifndef PCI_DEVICE_ID_ECHPCI864
415 #define PCI_DEVICE_ID_ECHPCI864 0x0002
417 #ifndef PCI_DEVICE_ID_EIOPCI
418 #define PCI_DEVICE_ID_EIOPCI 0x0003
422 * Define structure to hold all Stallion PCI boards.
424 typedef struct stlpcibrd {
425 unsigned short vendid;
426 unsigned short devid;
430 static stlpcibrd_t stl_pcibrds[] = {
431 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864, BRD_ECH64PCI },
432 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI, BRD_EASYIOPCI },
433 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832, BRD_ECHPCI },
434 { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
437 static int stl_nrpcibrds = sizeof(stl_pcibrds) / sizeof(stlpcibrd_t);
441 /*****************************************************************************/
444 * Define macros to extract a brd/port number from a minor number.
446 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
447 #define MINOR2PORT(min) ((min) & 0x3f)
450 * Define a baud rate table that converts termios baud rate selector
451 * into the actual baud rate value. All baud rate calculations are
452 * based on the actual baud rate required.
454 static unsigned int stl_baudrates[] = {
455 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
456 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
460 * Define some handy local macros...
463 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
466 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
468 /*****************************************************************************/
471 * Declare all those functions in this driver!
475 static void stl_argbrds(void);
476 static int stl_parsebrd(stlconf_t *confp, char **argp);
478 static unsigned long stl_atol(char *str);
482 static int stl_open(struct tty_struct *tty, struct file *filp);
483 static void stl_close(struct tty_struct *tty, struct file *filp);
484 static int stl_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count);
485 static void stl_putchar(struct tty_struct *tty, unsigned char ch);
486 static void stl_flushchars(struct tty_struct *tty);
487 static int stl_writeroom(struct tty_struct *tty);
488 static int stl_charsinbuffer(struct tty_struct *tty);
489 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
490 static void stl_settermios(struct tty_struct *tty, struct termios *old);
491 static void stl_throttle(struct tty_struct *tty);
492 static void stl_unthrottle(struct tty_struct *tty);
493 static void stl_stop(struct tty_struct *tty);
494 static void stl_start(struct tty_struct *tty);
495 static void stl_flushbuffer(struct tty_struct *tty);
496 static void stl_breakctl(struct tty_struct *tty, int state);
497 static void stl_waituntilsent(struct tty_struct *tty, int timeout);
498 static void stl_sendxchar(struct tty_struct *tty, char ch);
499 static void stl_hangup(struct tty_struct *tty);
500 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
501 static int stl_portinfo(stlport_t *portp, int portnr, char *pos);
502 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data);
504 static int stl_brdinit(stlbrd_t *brdp);
505 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
506 static int stl_mapirq(int irq, char *name);
507 static int stl_getserial(stlport_t *portp, struct serial_struct *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 /*****************************************************************************/
736 static struct class_simple *stallion_class;
741 * Loadable module initialization stuff.
744 static int __init stallion_module_init(void)
749 printk("init_module()\n");
755 restore_flags(flags);
760 /*****************************************************************************/
762 static void __exit stallion_module_exit(void)
771 printk("cleanup_module()\n");
774 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
781 * Free up all allocated resources used by the ports. This includes
782 * memory and interrupts. As part of this process we will also do
783 * a hangup on every open port - to try to flush out any processes
784 * hanging onto ports.
786 i = tty_unregister_driver(stl_serial);
787 put_tty_driver(stl_serial);
789 printk("STALLION: failed to un-register tty driver, "
791 restore_flags(flags);
794 for (i = 0; i < 4; i++) {
795 devfs_remove("staliomem/%d", i);
796 class_simple_device_remove(MKDEV(STL_SIOMEMMAJOR, i));
798 devfs_remove("staliomem");
799 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
800 printk("STALLION: failed to un-register serial memory device, "
802 class_simple_destroy(stallion_class);
804 if (stl_tmpwritebuf != (char *) NULL)
805 kfree(stl_tmpwritebuf);
807 for (i = 0; (i < stl_nrbrds); i++) {
808 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
810 for (j = 0; (j < STL_MAXPANELS); j++) {
811 panelp = brdp->panels[j];
812 if (panelp == (stlpanel_t *) NULL)
814 for (k = 0; (k < STL_PORTSPERPANEL); k++) {
815 portp = panelp->ports[k];
816 if (portp == (stlport_t *) NULL)
818 if (portp->tty != (struct tty_struct *) NULL)
819 stl_hangup(portp->tty);
820 if (portp->tx.buf != (char *) NULL)
821 kfree(portp->tx.buf);
827 release_region(brdp->ioaddr1, brdp->iosize1);
828 if (brdp->iosize2 > 0)
829 release_region(brdp->ioaddr2, brdp->iosize2);
832 stl_brds[i] = (stlbrd_t *) NULL;
835 for (i = 0; (i < stl_numintrs); i++)
836 free_irq(stl_gotintrs[i], NULL);
838 restore_flags(flags);
841 module_init(stallion_module_init);
842 module_exit(stallion_module_exit);
844 /*****************************************************************************/
847 * Check for any arguments passed in on the module load command line.
850 static void stl_argbrds()
857 printk("stl_argbrds()\n");
860 nrargs = sizeof(stl_brdsp) / sizeof(char **);
862 for (i = stl_nrbrds; (i < nrargs); i++) {
863 memset(&conf, 0, sizeof(conf));
864 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
866 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
870 brdp->brdtype = conf.brdtype;
871 brdp->ioaddr1 = conf.ioaddr1;
872 brdp->ioaddr2 = conf.ioaddr2;
873 brdp->irq = conf.irq;
874 brdp->irqtype = conf.irqtype;
879 /*****************************************************************************/
882 * Convert an ascii string number into an unsigned long.
885 static unsigned long stl_atol(char *str)
893 if ((*sp == '0') && (*(sp+1) == 'x')) {
896 } else if (*sp == '0') {
903 for (; (*sp != 0); sp++) {
904 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
905 if ((c < 0) || (c >= base)) {
906 printk("STALLION: invalid argument %s\n", str);
910 val = (val * base) + c;
915 /*****************************************************************************/
918 * Parse the supplied argument string, into the board conf struct.
921 static int stl_parsebrd(stlconf_t *confp, char **argp)
927 printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
930 if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
933 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
936 nrbrdnames = sizeof(stl_brdstr) / sizeof(stlbrdtype_t);
937 for (i = 0; (i < nrbrdnames); i++) {
938 if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
941 if (i >= nrbrdnames) {
942 printk("STALLION: unknown board name, %s?\n", argp[0]);
946 confp->brdtype = stl_brdstr[i].type;
949 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
950 confp->ioaddr1 = stl_atol(argp[i]);
952 if (confp->brdtype == BRD_ECH) {
953 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
954 confp->ioaddr2 = stl_atol(argp[i]);
957 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
958 confp->irq = stl_atol(argp[i]);
964 /*****************************************************************************/
967 * Local driver kernel memory allocation routine.
970 static void *stl_memalloc(int len)
972 return((void *) kmalloc(len, GFP_KERNEL));
975 /*****************************************************************************/
978 * Allocate a new board structure. Fill out the basic info in it.
981 static stlbrd_t *stl_allocbrd()
985 brdp = (stlbrd_t *) stl_memalloc(sizeof(stlbrd_t));
986 if (brdp == (stlbrd_t *) NULL) {
987 printk("STALLION: failed to allocate memory (size=%d)\n",
989 return((stlbrd_t *) NULL);
992 memset(brdp, 0, sizeof(stlbrd_t));
993 brdp->magic = STL_BOARDMAGIC;
997 /*****************************************************************************/
999 static int stl_open(struct tty_struct *tty, struct file *filp)
1003 unsigned int minordev;
1004 int brdnr, panelnr, portnr, rc;
1007 printk("stl_open(tty=%x,filp=%x): device=%s\n", (int) tty,
1008 (int) filp, tty->name);
1011 minordev = tty->index;
1012 brdnr = MINOR2BRD(minordev);
1013 if (brdnr >= stl_nrbrds)
1015 brdp = stl_brds[brdnr];
1016 if (brdp == (stlbrd_t *) NULL)
1018 minordev = MINOR2PORT(minordev);
1019 for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
1020 if (brdp->panels[panelnr] == (stlpanel_t *) NULL)
1022 if (minordev < brdp->panels[panelnr]->nrports) {
1026 minordev -= brdp->panels[panelnr]->nrports;
1031 portp = brdp->panels[panelnr]->ports[portnr];
1032 if (portp == (stlport_t *) NULL)
1036 * On the first open of the device setup the port hardware, and
1037 * initialize the per port data structure.
1040 tty->driver_data = portp;
1043 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
1044 if (portp->tx.buf == (char *) NULL) {
1045 portp->tx.buf = (char *) stl_memalloc(STL_TXBUFSIZE);
1046 if (portp->tx.buf == (char *) NULL)
1048 portp->tx.head = portp->tx.buf;
1049 portp->tx.tail = portp->tx.buf;
1051 stl_setport(portp, tty->termios);
1052 portp->sigs = stl_getsignals(portp);
1053 stl_setsignals(portp, 1, 1);
1054 stl_enablerxtx(portp, 1, 1);
1055 stl_startrxtx(portp, 1, 0);
1056 clear_bit(TTY_IO_ERROR, &tty->flags);
1057 portp->flags |= ASYNC_INITIALIZED;
1061 * Check if this port is in the middle of closing. If so then wait
1062 * until it is closed then return error status, based on flag settings.
1063 * The sleep here does not need interrupt protection since the wakeup
1064 * for it is done with the same context.
1066 if (portp->flags & ASYNC_CLOSING) {
1067 interruptible_sleep_on(&portp->close_wait);
1068 if (portp->flags & ASYNC_HUP_NOTIFY)
1070 return(-ERESTARTSYS);
1074 * Based on type of open being done check if it can overlap with any
1075 * previous opens still in effect. If we are a normal serial device
1076 * then also we might have to wait for carrier.
1078 if (!(filp->f_flags & O_NONBLOCK)) {
1079 if ((rc = stl_waitcarrier(portp, filp)) != 0)
1082 portp->flags |= ASYNC_NORMAL_ACTIVE;
1087 /*****************************************************************************/
1090 * Possibly need to wait for carrier (DCD signal) to come high. Say
1091 * maybe because if we are clocal then we don't need to wait...
1094 static int stl_waitcarrier(stlport_t *portp, struct file *filp)
1096 unsigned long flags;
1100 printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp, (int) filp);
1106 if (portp->tty->termios->c_cflag & CLOCAL)
1111 portp->openwaitcnt++;
1112 if (! tty_hung_up_p(filp))
1116 stl_setsignals(portp, 1, 1);
1117 if (tty_hung_up_p(filp) ||
1118 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1119 if (portp->flags & ASYNC_HUP_NOTIFY)
1125 if (((portp->flags & ASYNC_CLOSING) == 0) &&
1126 (doclocal || (portp->sigs & TIOCM_CD))) {
1129 if (signal_pending(current)) {
1133 interruptible_sleep_on(&portp->open_wait);
1136 if (! tty_hung_up_p(filp))
1138 portp->openwaitcnt--;
1139 restore_flags(flags);
1144 /*****************************************************************************/
1146 static void stl_close(struct tty_struct *tty, struct file *filp)
1149 unsigned long flags;
1152 printk("stl_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
1155 portp = tty->driver_data;
1156 if (portp == (stlport_t *) NULL)
1161 if (tty_hung_up_p(filp)) {
1162 restore_flags(flags);
1165 if ((tty->count == 1) && (portp->refcount != 1))
1166 portp->refcount = 1;
1167 if (portp->refcount-- > 1) {
1168 restore_flags(flags);
1172 portp->refcount = 0;
1173 portp->flags |= ASYNC_CLOSING;
1176 * May want to wait for any data to drain before closing. The BUSY
1177 * flag keeps track of whether we are still sending or not - it is
1178 * very accurate for the cd1400, not quite so for the sc26198.
1179 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1182 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1183 tty_wait_until_sent(tty, portp->closing_wait);
1184 stl_waituntilsent(tty, (HZ / 2));
1186 portp->flags &= ~ASYNC_INITIALIZED;
1187 stl_disableintrs(portp);
1188 if (tty->termios->c_cflag & HUPCL)
1189 stl_setsignals(portp, 0, 0);
1190 stl_enablerxtx(portp, 0, 0);
1191 stl_flushbuffer(tty);
1193 if (portp->tx.buf != (char *) NULL) {
1194 kfree(portp->tx.buf);
1195 portp->tx.buf = (char *) NULL;
1196 portp->tx.head = (char *) NULL;
1197 portp->tx.tail = (char *) NULL;
1199 set_bit(TTY_IO_ERROR, &tty->flags);
1200 if (tty->ldisc.flush_buffer)
1201 (tty->ldisc.flush_buffer)(tty);
1204 portp->tty = (struct tty_struct *) NULL;
1206 if (portp->openwaitcnt) {
1207 if (portp->close_delay)
1208 stl_delay(portp->close_delay);
1209 wake_up_interruptible(&portp->open_wait);
1212 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1213 wake_up_interruptible(&portp->close_wait);
1214 restore_flags(flags);
1217 /*****************************************************************************/
1220 * Wait for a specified delay period, this is not a busy-loop. It will
1221 * give up the processor while waiting. Unfortunately this has some
1222 * rather intimate knowledge of the process management stuff.
1225 static void stl_delay(int len)
1228 printk("stl_delay(len=%d)\n", len);
1231 current->state = TASK_INTERRUPTIBLE;
1232 schedule_timeout(len);
1236 /*****************************************************************************/
1239 * Write routine. Take data and stuff it in to the TX ring queue.
1240 * If transmit interrupts are not running then start them.
1243 static int stl_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count)
1246 unsigned int len, stlen;
1247 unsigned char *chbuf;
1251 printk("stl_write(tty=%x,from_user=%d,buf=%x,count=%d)\n",
1252 (int) tty, from_user, (int) buf, count);
1255 if ((tty == (struct tty_struct *) NULL) ||
1256 (stl_tmpwritebuf == (char *) NULL))
1258 portp = tty->driver_data;
1259 if (portp == (stlport_t *) NULL)
1261 if (portp->tx.buf == (char *) NULL)
1265 * If copying direct from user space we must cater for page faults,
1266 * causing us to "sleep" here for a while. To handle this copy in all
1267 * the data we need now, into a local buffer. Then when we got it all
1268 * copy it into the TX buffer.
1270 chbuf = (unsigned char *) buf;
1272 head = portp->tx.head;
1273 tail = portp->tx.tail;
1274 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) :
1276 count = MIN(len, count);
1278 down(&stl_tmpwritesem);
1279 if (copy_from_user(stl_tmpwritebuf, chbuf, count))
1281 chbuf = &stl_tmpwritebuf[0];
1284 head = portp->tx.head;
1285 tail = portp->tx.tail;
1287 len = STL_TXBUFSIZE - (head - tail) - 1;
1288 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
1290 len = tail - head - 1;
1294 len = MIN(len, count);
1297 stlen = MIN(len, stlen);
1298 memcpy(head, chbuf, stlen);
1303 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
1304 head = portp->tx.buf;
1305 stlen = tail - head;
1308 portp->tx.head = head;
1310 clear_bit(ASYI_TXLOW, &portp->istate);
1311 stl_startrxtx(portp, -1, 1);
1314 up(&stl_tmpwritesem);
1319 /*****************************************************************************/
1321 static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1328 printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1331 if (tty == (struct tty_struct *) NULL)
1333 portp = tty->driver_data;
1334 if (portp == (stlport_t *) NULL)
1336 if (portp->tx.buf == (char *) NULL)
1339 head = portp->tx.head;
1340 tail = portp->tx.tail;
1342 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
1347 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
1348 head = portp->tx.buf;
1350 portp->tx.head = head;
1353 /*****************************************************************************/
1356 * If there are any characters in the buffer then make sure that TX
1357 * interrupts are on and get'em out. Normally used after the putchar
1358 * routine has been called.
1361 static void stl_flushchars(struct tty_struct *tty)
1366 printk("stl_flushchars(tty=%x)\n", (int) tty);
1369 if (tty == (struct tty_struct *) NULL)
1371 portp = tty->driver_data;
1372 if (portp == (stlport_t *) NULL)
1374 if (portp->tx.buf == (char *) NULL)
1378 if (tty->stopped || tty->hw_stopped ||
1379 (portp->tx.head == portp->tx.tail))
1382 stl_startrxtx(portp, -1, 1);
1385 /*****************************************************************************/
1387 static int stl_writeroom(struct tty_struct *tty)
1393 printk("stl_writeroom(tty=%x)\n", (int) tty);
1396 if (tty == (struct tty_struct *) NULL)
1398 portp = tty->driver_data;
1399 if (portp == (stlport_t *) NULL)
1401 if (portp->tx.buf == (char *) NULL)
1404 head = portp->tx.head;
1405 tail = portp->tx.tail;
1406 return((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
1409 /*****************************************************************************/
1412 * Return number of chars in the TX buffer. Normally we would just
1413 * calculate the number of chars in the buffer and return that, but if
1414 * the buffer is empty and TX interrupts are still on then we return
1415 * that the buffer still has 1 char in it. This way whoever called us
1416 * will not think that ALL chars have drained - since the UART still
1417 * must have some chars in it (we are busy after all).
1420 static int stl_charsinbuffer(struct tty_struct *tty)
1427 printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
1430 if (tty == (struct tty_struct *) NULL)
1432 portp = tty->driver_data;
1433 if (portp == (stlport_t *) NULL)
1435 if (portp->tx.buf == (char *) NULL)
1438 head = portp->tx.head;
1439 tail = portp->tx.tail;
1440 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1441 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1446 /*****************************************************************************/
1449 * Generate the serial struct info.
1452 static int stl_getserial(stlport_t *portp, struct serial_struct *sp)
1454 struct serial_struct sio;
1458 printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1461 memset(&sio, 0, sizeof(struct serial_struct));
1462 sio.line = portp->portnr;
1463 sio.port = portp->ioaddr;
1464 sio.flags = portp->flags;
1465 sio.baud_base = portp->baud_base;
1466 sio.close_delay = portp->close_delay;
1467 sio.closing_wait = portp->closing_wait;
1468 sio.custom_divisor = portp->custom_divisor;
1470 if (portp->uartp == &stl_cd1400uart) {
1471 sio.type = PORT_CIRRUS;
1472 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1474 sio.type = PORT_UNKNOWN;
1475 sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1478 brdp = stl_brds[portp->brdnr];
1479 if (brdp != (stlbrd_t *) NULL)
1480 sio.irq = brdp->irq;
1482 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
1485 /*****************************************************************************/
1488 * Set port according to the serial struct info.
1489 * At this point we do not do any auto-configure stuff, so we will
1490 * just quietly ignore any requests to change irq, etc.
1493 static int stl_setserial(stlport_t *portp, struct serial_struct *sp)
1495 struct serial_struct sio;
1498 printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1501 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1503 if (!capable(CAP_SYS_ADMIN)) {
1504 if ((sio.baud_base != portp->baud_base) ||
1505 (sio.close_delay != portp->close_delay) ||
1506 ((sio.flags & ~ASYNC_USR_MASK) !=
1507 (portp->flags & ~ASYNC_USR_MASK)))
1511 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1512 (sio.flags & ASYNC_USR_MASK);
1513 portp->baud_base = sio.baud_base;
1514 portp->close_delay = sio.close_delay;
1515 portp->closing_wait = sio.closing_wait;
1516 portp->custom_divisor = sio.custom_divisor;
1517 stl_setport(portp, portp->tty->termios);
1521 /*****************************************************************************/
1523 static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1527 if (tty == (struct tty_struct *) NULL)
1529 portp = tty->driver_data;
1530 if (portp == (stlport_t *) NULL)
1532 if (tty->flags & (1 << TTY_IO_ERROR))
1535 return stl_getsignals(portp);
1538 static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1539 unsigned int set, unsigned int clear)
1542 int rts = -1, dtr = -1;
1544 if (tty == (struct tty_struct *) NULL)
1546 portp = tty->driver_data;
1547 if (portp == (stlport_t *) NULL)
1549 if (tty->flags & (1 << TTY_IO_ERROR))
1552 if (set & TIOCM_RTS)
1554 if (set & TIOCM_DTR)
1556 if (clear & TIOCM_RTS)
1558 if (clear & TIOCM_DTR)
1561 stl_setsignals(portp, dtr, rts);
1565 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1572 printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
1573 (int) tty, (int) file, cmd, (int) arg);
1576 if (tty == (struct tty_struct *) NULL)
1578 portp = tty->driver_data;
1579 if (portp == (stlport_t *) NULL)
1582 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1583 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1584 if (tty->flags & (1 << TTY_IO_ERROR))
1592 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1593 (unsigned int *) arg);
1596 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1597 sizeof(int))) == 0) {
1598 get_user(ival, (unsigned int *) arg);
1599 tty->termios->c_cflag =
1600 (tty->termios->c_cflag & ~CLOCAL) |
1601 (ival ? CLOCAL : 0);
1605 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1606 sizeof(struct serial_struct))) == 0)
1607 rc = stl_getserial(portp, (struct serial_struct *) arg);
1610 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1611 sizeof(struct serial_struct))) == 0)
1612 rc = stl_setserial(portp, (struct serial_struct *) arg);
1614 case COM_GETPORTSTATS:
1615 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1616 sizeof(comstats_t))) == 0)
1617 rc = stl_getportstats(portp, (comstats_t *) arg);
1619 case COM_CLRPORTSTATS:
1620 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1621 sizeof(comstats_t))) == 0)
1622 rc = stl_clrportstats(portp, (comstats_t *) arg);
1628 case TIOCSERGSTRUCT:
1629 case TIOCSERGETMULTI:
1630 case TIOCSERSETMULTI:
1639 /*****************************************************************************/
1641 static void stl_settermios(struct tty_struct *tty, struct termios *old)
1644 struct termios *tiosp;
1647 printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
1650 if (tty == (struct tty_struct *) NULL)
1652 portp = tty->driver_data;
1653 if (portp == (stlport_t *) NULL)
1656 tiosp = tty->termios;
1657 if ((tiosp->c_cflag == old->c_cflag) &&
1658 (tiosp->c_iflag == old->c_iflag))
1661 stl_setport(portp, tiosp);
1662 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1664 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1665 tty->hw_stopped = 0;
1668 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1669 wake_up_interruptible(&portp->open_wait);
1672 /*****************************************************************************/
1675 * Attempt to flow control who ever is sending us data. Based on termios
1676 * settings use software or/and hardware flow control.
1679 static void stl_throttle(struct tty_struct *tty)
1684 printk("stl_throttle(tty=%x)\n", (int) tty);
1687 if (tty == (struct tty_struct *) NULL)
1689 portp = tty->driver_data;
1690 if (portp == (stlport_t *) NULL)
1692 stl_flowctrl(portp, 0);
1695 /*****************************************************************************/
1698 * Unflow control the device sending us data...
1701 static void stl_unthrottle(struct tty_struct *tty)
1706 printk("stl_unthrottle(tty=%x)\n", (int) tty);
1709 if (tty == (struct tty_struct *) NULL)
1711 portp = tty->driver_data;
1712 if (portp == (stlport_t *) NULL)
1714 stl_flowctrl(portp, 1);
1717 /*****************************************************************************/
1720 * Stop the transmitter. Basically to do this we will just turn TX
1724 static void stl_stop(struct tty_struct *tty)
1729 printk("stl_stop(tty=%x)\n", (int) tty);
1732 if (tty == (struct tty_struct *) NULL)
1734 portp = tty->driver_data;
1735 if (portp == (stlport_t *) NULL)
1737 stl_startrxtx(portp, -1, 0);
1740 /*****************************************************************************/
1743 * Start the transmitter again. Just turn TX interrupts back on.
1746 static void stl_start(struct tty_struct *tty)
1751 printk("stl_start(tty=%x)\n", (int) tty);
1754 if (tty == (struct tty_struct *) NULL)
1756 portp = tty->driver_data;
1757 if (portp == (stlport_t *) NULL)
1759 stl_startrxtx(portp, -1, 1);
1762 /*****************************************************************************/
1765 * Hangup this port. This is pretty much like closing the port, only
1766 * a little more brutal. No waiting for data to drain. Shutdown the
1767 * port and maybe drop signals.
1770 static void stl_hangup(struct tty_struct *tty)
1775 printk("stl_hangup(tty=%x)\n", (int) tty);
1778 if (tty == (struct tty_struct *) NULL)
1780 portp = tty->driver_data;
1781 if (portp == (stlport_t *) NULL)
1784 portp->flags &= ~ASYNC_INITIALIZED;
1785 stl_disableintrs(portp);
1786 if (tty->termios->c_cflag & HUPCL)
1787 stl_setsignals(portp, 0, 0);
1788 stl_enablerxtx(portp, 0, 0);
1789 stl_flushbuffer(tty);
1791 set_bit(TTY_IO_ERROR, &tty->flags);
1792 if (portp->tx.buf != (char *) NULL) {
1793 kfree(portp->tx.buf);
1794 portp->tx.buf = (char *) NULL;
1795 portp->tx.head = (char *) NULL;
1796 portp->tx.tail = (char *) NULL;
1798 portp->tty = (struct tty_struct *) NULL;
1799 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1800 portp->refcount = 0;
1801 wake_up_interruptible(&portp->open_wait);
1804 /*****************************************************************************/
1806 static void stl_flushbuffer(struct tty_struct *tty)
1811 printk("stl_flushbuffer(tty=%x)\n", (int) tty);
1814 if (tty == (struct tty_struct *) NULL)
1816 portp = tty->driver_data;
1817 if (portp == (stlport_t *) NULL)
1821 wake_up_interruptible(&tty->write_wait);
1822 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1823 tty->ldisc.write_wakeup)
1824 (tty->ldisc.write_wakeup)(tty);
1827 /*****************************************************************************/
1829 static void stl_breakctl(struct tty_struct *tty, int state)
1834 printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty, state);
1837 if (tty == (struct tty_struct *) NULL)
1839 portp = tty->driver_data;
1840 if (portp == (stlport_t *) NULL)
1843 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1846 /*****************************************************************************/
1848 static void stl_waituntilsent(struct tty_struct *tty, int timeout)
1854 printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty, timeout);
1857 if (tty == (struct tty_struct *) NULL)
1859 portp = tty->driver_data;
1860 if (portp == (stlport_t *) NULL)
1865 tend = jiffies + timeout;
1867 while (stl_datastate(portp)) {
1868 if (signal_pending(current))
1871 if (time_after_eq(jiffies, tend))
1876 /*****************************************************************************/
1878 static void stl_sendxchar(struct tty_struct *tty, char ch)
1883 printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
1886 if (tty == (struct tty_struct *) NULL)
1888 portp = tty->driver_data;
1889 if (portp == (stlport_t *) NULL)
1892 if (ch == STOP_CHAR(tty))
1893 stl_sendflow(portp, 0);
1894 else if (ch == START_CHAR(tty))
1895 stl_sendflow(portp, 1);
1897 stl_putchar(tty, ch);
1900 /*****************************************************************************/
1905 * Format info for a specified port. The line is deliberately limited
1906 * to 80 characters. (If it is too long it will be truncated, if too
1907 * short then padded with spaces).
1910 static int stl_portinfo(stlport_t *portp, int portnr, char *pos)
1916 sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
1917 portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
1918 (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
1920 if (portp->stats.rxframing)
1921 sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
1922 if (portp->stats.rxparity)
1923 sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
1924 if (portp->stats.rxbreaks)
1925 sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
1926 if (portp->stats.rxoverrun)
1927 sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
1929 sigs = stl_getsignals(portp);
1930 cnt = sprintf(sp, "%s%s%s%s%s ",
1931 (sigs & TIOCM_RTS) ? "|RTS" : "",
1932 (sigs & TIOCM_CTS) ? "|CTS" : "",
1933 (sigs & TIOCM_DTR) ? "|DTR" : "",
1934 (sigs & TIOCM_CD) ? "|DCD" : "",
1935 (sigs & TIOCM_DSR) ? "|DSR" : "");
1939 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
1942 pos[(MAXLINE - 2)] = '+';
1943 pos[(MAXLINE - 1)] = '\n';
1948 /*****************************************************************************/
1951 * Port info, read from the /proc file system.
1954 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
1959 int brdnr, panelnr, portnr, totalport;
1964 printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
1965 "data=%x\n", (int) page, (int) start, (int) off, count,
1966 (int) eof, (int) data);
1974 pos += sprintf(pos, "%s: version %s", stl_drvtitle,
1976 while (pos < (page + MAXLINE - 1))
1983 * We scan through for each board, panel and port. The offset is
1984 * calculated on the fly, and irrelevant ports are skipped.
1986 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1987 brdp = stl_brds[brdnr];
1988 if (brdp == (stlbrd_t *) NULL)
1990 if (brdp->state == 0)
1993 maxoff = curoff + (brdp->nrports * MAXLINE);
1994 if (off >= maxoff) {
1999 totalport = brdnr * STL_MAXPORTS;
2000 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
2001 panelp = brdp->panels[panelnr];
2002 if (panelp == (stlpanel_t *) NULL)
2005 maxoff = curoff + (panelp->nrports * MAXLINE);
2006 if (off >= maxoff) {
2008 totalport += panelp->nrports;
2012 for (portnr = 0; (portnr < panelp->nrports); portnr++,
2014 portp = panelp->ports[portnr];
2015 if (portp == (stlport_t *) NULL)
2017 if (off >= (curoff += MAXLINE))
2019 if ((pos - page + MAXLINE) > count)
2021 pos += stl_portinfo(portp, totalport, pos);
2033 /*****************************************************************************/
2036 * All board interrupts are vectored through here first. This code then
2037 * calls off to the approrpriate board interrupt handlers.
2040 static irqreturn_t stl_intr(int irq, void *dev_id, struct pt_regs *regs)
2047 printk("stl_intr(irq=%d,regs=%x)\n", irq, (int) regs);
2050 for (i = 0; (i < stl_nrbrds); i++) {
2051 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
2053 if (brdp->state == 0)
2056 (* brdp->isr)(brdp);
2058 return IRQ_RETVAL(handled);
2061 /*****************************************************************************/
2064 * Interrupt service routine for EasyIO board types.
2067 static void stl_eiointr(stlbrd_t *brdp)
2070 unsigned int iobase;
2072 panelp = brdp->panels[0];
2073 iobase = panelp->iobase;
2074 while (inb(brdp->iostatus) & EIO_INTRPEND)
2075 (* panelp->isr)(panelp, iobase);
2078 /*****************************************************************************/
2081 * Interrupt service routine for ECH-AT board types.
2084 static void stl_echatintr(stlbrd_t *brdp)
2087 unsigned int ioaddr;
2090 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2092 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2093 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2094 ioaddr = brdp->bnkstataddr[bnknr];
2095 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2096 panelp = brdp->bnk2panel[bnknr];
2097 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2102 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2105 /*****************************************************************************/
2108 * Interrupt service routine for ECH-MCA board types.
2111 static void stl_echmcaintr(stlbrd_t *brdp)
2114 unsigned int ioaddr;
2117 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2118 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2119 ioaddr = brdp->bnkstataddr[bnknr];
2120 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2121 panelp = brdp->bnk2panel[bnknr];
2122 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2128 /*****************************************************************************/
2131 * Interrupt service routine for ECH-PCI board types.
2134 static void stl_echpciintr(stlbrd_t *brdp)
2137 unsigned int ioaddr;
2142 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2143 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
2144 ioaddr = brdp->bnkstataddr[bnknr];
2145 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2146 panelp = brdp->bnk2panel[bnknr];
2147 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2156 /*****************************************************************************/
2159 * Interrupt service routine for ECH-8/64-PCI board types.
2162 static void stl_echpci64intr(stlbrd_t *brdp)
2165 unsigned int ioaddr;
2168 while (inb(brdp->ioctrl) & 0x1) {
2169 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2170 ioaddr = brdp->bnkstataddr[bnknr];
2171 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2172 panelp = brdp->bnk2panel[bnknr];
2173 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2179 /*****************************************************************************/
2182 * Service an off-level request for some channel.
2184 static void stl_offintr(void *private)
2187 struct tty_struct *tty;
2188 unsigned int oldsigs;
2193 printk("stl_offintr(portp=%x)\n", (int) portp);
2196 if (portp == (stlport_t *) NULL)
2200 if (tty == (struct tty_struct *) NULL)
2204 if (test_bit(ASYI_TXLOW, &portp->istate)) {
2205 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2206 tty->ldisc.write_wakeup)
2207 (tty->ldisc.write_wakeup)(tty);
2208 wake_up_interruptible(&tty->write_wait);
2210 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
2211 clear_bit(ASYI_DCDCHANGE, &portp->istate);
2212 oldsigs = portp->sigs;
2213 portp->sigs = stl_getsignals(portp);
2214 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
2215 wake_up_interruptible(&portp->open_wait);
2216 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
2217 if (portp->flags & ASYNC_CHECK_CD)
2218 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2224 /*****************************************************************************/
2227 * Map in interrupt vector to this driver. Check that we don't
2228 * already have this vector mapped, we might be sharing this
2229 * interrupt across multiple boards.
2232 static int __init stl_mapirq(int irq, char *name)
2237 printk("stl_mapirq(irq=%d,name=%s)\n", irq, name);
2241 for (i = 0; (i < stl_numintrs); i++) {
2242 if (stl_gotintrs[i] == irq)
2245 if (i >= stl_numintrs) {
2246 if (request_irq(irq, stl_intr, SA_SHIRQ, name, NULL) != 0) {
2247 printk("STALLION: failed to register interrupt "
2248 "routine for %s irq=%d\n", name, irq);
2251 stl_gotintrs[stl_numintrs++] = irq;
2257 /*****************************************************************************/
2260 * Initialize all the ports on a panel.
2263 static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2269 printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
2272 chipmask = stl_panelinit(brdp, panelp);
2275 * All UART's are initialized (if found!). Now go through and setup
2276 * each ports data structures.
2278 for (i = 0; (i < panelp->nrports); i++) {
2279 portp = (stlport_t *) stl_memalloc(sizeof(stlport_t));
2280 if (portp == (stlport_t *) NULL) {
2281 printk("STALLION: failed to allocate memory "
2282 "(size=%d)\n", sizeof(stlport_t));
2285 memset(portp, 0, sizeof(stlport_t));
2287 portp->magic = STL_PORTMAGIC;
2289 portp->brdnr = panelp->brdnr;
2290 portp->panelnr = panelp->panelnr;
2291 portp->uartp = panelp->uartp;
2292 portp->clk = brdp->clk;
2293 portp->baud_base = STL_BAUDBASE;
2294 portp->close_delay = STL_CLOSEDELAY;
2295 portp->closing_wait = 30 * HZ;
2296 INIT_WORK(&portp->tqueue, stl_offintr, portp);
2297 init_waitqueue_head(&portp->open_wait);
2298 init_waitqueue_head(&portp->close_wait);
2299 portp->stats.brd = portp->brdnr;
2300 portp->stats.panel = portp->panelnr;
2301 portp->stats.port = portp->portnr;
2302 panelp->ports[i] = portp;
2303 stl_portinit(brdp, panelp, portp);
2309 /*****************************************************************************/
2312 * Try to find and initialize an EasyIO board.
2315 static inline int stl_initeio(stlbrd_t *brdp)
2318 unsigned int status;
2323 printk("stl_initeio(brdp=%x)\n", (int) brdp);
2326 brdp->ioctrl = brdp->ioaddr1 + 1;
2327 brdp->iostatus = brdp->ioaddr1 + 2;
2329 status = inb(brdp->iostatus);
2330 if ((status & EIO_IDBITMASK) == EIO_MK3)
2334 * Handle board specific stuff now. The real difference is PCI
2337 if (brdp->brdtype == BRD_EASYIOPCI) {
2338 brdp->iosize1 = 0x80;
2339 brdp->iosize2 = 0x80;
2340 name = "serial(EIO-PCI)";
2341 outb(0x41, (brdp->ioaddr2 + 0x4c));
2344 name = "serial(EIO)";
2345 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2346 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2347 printk("STALLION: invalid irq=%d for brd=%d\n",
2348 brdp->irq, brdp->brdnr);
2351 outb((stl_vecmap[brdp->irq] | EIO_0WS |
2352 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
2356 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2357 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2358 "%x conflicts with another device\n", brdp->brdnr,
2363 if (brdp->iosize2 > 0)
2364 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2365 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2366 "address %x conflicts with another device\n",
2367 brdp->brdnr, brdp->ioaddr2);
2368 printk(KERN_WARNING "STALLION: Warning, also "
2369 "releasing board %d I/O address %x \n",
2370 brdp->brdnr, brdp->ioaddr1);
2371 release_region(brdp->ioaddr1, brdp->iosize1);
2376 * Everything looks OK, so let's go ahead and probe for the hardware.
2378 brdp->clk = CD1400_CLK;
2379 brdp->isr = stl_eiointr;
2381 switch (status & EIO_IDBITMASK) {
2383 brdp->clk = CD1400_CLK8M;
2393 switch (status & EIO_BRDMASK) {
2412 * We have verified that the board is actually present, so now we
2413 * can complete the setup.
2416 panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
2417 if (panelp == (stlpanel_t *) NULL) {
2418 printk(KERN_WARNING "STALLION: failed to allocate memory "
2419 "(size=%d)\n", sizeof(stlpanel_t));
2422 memset(panelp, 0, sizeof(stlpanel_t));
2424 panelp->magic = STL_PANELMAGIC;
2425 panelp->brdnr = brdp->brdnr;
2426 panelp->panelnr = 0;
2427 panelp->nrports = brdp->nrports;
2428 panelp->iobase = brdp->ioaddr1;
2429 panelp->hwid = status;
2430 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2431 panelp->uartp = (void *) &stl_sc26198uart;
2432 panelp->isr = stl_sc26198intr;
2434 panelp->uartp = (void *) &stl_cd1400uart;
2435 panelp->isr = stl_cd1400eiointr;
2438 brdp->panels[0] = panelp;
2440 brdp->state |= BRD_FOUND;
2441 brdp->hwid = status;
2442 rc = stl_mapirq(brdp->irq, name);
2446 /*****************************************************************************/
2449 * Try to find an ECH board and initialize it. This code is capable of
2450 * dealing with all types of ECH board.
2453 static inline int stl_initech(stlbrd_t *brdp)
2456 unsigned int status, nxtid, ioaddr, conflict;
2457 int panelnr, banknr, i;
2461 printk("stl_initech(brdp=%x)\n", (int) brdp);
2468 * Set up the initial board register contents for boards. This varies a
2469 * bit between the different board types. So we need to handle each
2470 * separately. Also do a check that the supplied IRQ is good.
2472 switch (brdp->brdtype) {
2475 brdp->isr = stl_echatintr;
2476 brdp->ioctrl = brdp->ioaddr1 + 1;
2477 brdp->iostatus = brdp->ioaddr1 + 1;
2478 status = inb(brdp->iostatus);
2479 if ((status & ECH_IDBITMASK) != ECH_ID)
2481 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2482 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2483 printk("STALLION: invalid irq=%d for brd=%d\n",
2484 brdp->irq, brdp->brdnr);
2487 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2488 status |= (stl_vecmap[brdp->irq] << 1);
2489 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2490 brdp->ioctrlval = ECH_INTENABLE |
2491 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2492 for (i = 0; (i < 10); i++)
2493 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2496 name = "serial(EC8/32)";
2497 outb(status, brdp->ioaddr1);
2501 brdp->isr = stl_echmcaintr;
2502 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2503 brdp->iostatus = brdp->ioctrl;
2504 status = inb(brdp->iostatus);
2505 if ((status & ECH_IDBITMASK) != ECH_ID)
2507 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2508 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2509 printk("STALLION: invalid irq=%d for brd=%d\n",
2510 brdp->irq, brdp->brdnr);
2513 outb(ECHMC_BRDRESET, brdp->ioctrl);
2514 outb(ECHMC_INTENABLE, brdp->ioctrl);
2516 name = "serial(EC8/32-MC)";
2520 brdp->isr = stl_echpciintr;
2521 brdp->ioctrl = brdp->ioaddr1 + 2;
2524 name = "serial(EC8/32-PCI)";
2528 brdp->isr = stl_echpci64intr;
2529 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2530 outb(0x43, (brdp->ioaddr1 + 0x4c));
2531 brdp->iosize1 = 0x80;
2532 brdp->iosize2 = 0x80;
2533 name = "serial(EC8/64-PCI)";
2537 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
2543 * Check boards for possible IO address conflicts and return fail status
2544 * if an IO conflict found.
2546 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2547 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2548 "%x conflicts with another device\n", brdp->brdnr,
2553 if (brdp->iosize2 > 0)
2554 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2555 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2556 "address %x conflicts with another device\n",
2557 brdp->brdnr, brdp->ioaddr2);
2558 printk(KERN_WARNING "STALLION: Warning, also "
2559 "releasing board %d I/O address %x \n",
2560 brdp->brdnr, brdp->ioaddr1);
2561 release_region(brdp->ioaddr1, brdp->iosize1);
2566 * Scan through the secondary io address space looking for panels.
2567 * As we find'em allocate and initialize panel structures for each.
2569 brdp->clk = CD1400_CLK;
2570 brdp->hwid = status;
2572 ioaddr = brdp->ioaddr2;
2577 for (i = 0; (i < STL_MAXPANELS); i++) {
2578 if (brdp->brdtype == BRD_ECHPCI) {
2579 outb(nxtid, brdp->ioctrl);
2580 ioaddr = brdp->ioaddr2;
2582 status = inb(ioaddr + ECH_PNLSTATUS);
2583 if ((status & ECH_PNLIDMASK) != nxtid)
2585 panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
2586 if (panelp == (stlpanel_t *) NULL) {
2587 printk("STALLION: failed to allocate memory "
2588 "(size=%d)\n", sizeof(stlpanel_t));
2591 memset(panelp, 0, sizeof(stlpanel_t));
2592 panelp->magic = STL_PANELMAGIC;
2593 panelp->brdnr = brdp->brdnr;
2594 panelp->panelnr = panelnr;
2595 panelp->iobase = ioaddr;
2596 panelp->pagenr = nxtid;
2597 panelp->hwid = status;
2598 brdp->bnk2panel[banknr] = panelp;
2599 brdp->bnkpageaddr[banknr] = nxtid;
2600 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2602 if (status & ECH_PNLXPID) {
2603 panelp->uartp = (void *) &stl_sc26198uart;
2604 panelp->isr = stl_sc26198intr;
2605 if (status & ECH_PNL16PORT) {
2606 panelp->nrports = 16;
2607 brdp->bnk2panel[banknr] = panelp;
2608 brdp->bnkpageaddr[banknr] = nxtid;
2609 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2612 panelp->nrports = 8;
2615 panelp->uartp = (void *) &stl_cd1400uart;
2616 panelp->isr = stl_cd1400echintr;
2617 if (status & ECH_PNL16PORT) {
2618 panelp->nrports = 16;
2619 panelp->ackmask = 0x80;
2620 if (brdp->brdtype != BRD_ECHPCI)
2621 ioaddr += EREG_BANKSIZE;
2622 brdp->bnk2panel[banknr] = panelp;
2623 brdp->bnkpageaddr[banknr] = ++nxtid;
2624 brdp->bnkstataddr[banknr++] = ioaddr +
2627 panelp->nrports = 8;
2628 panelp->ackmask = 0xc0;
2633 ioaddr += EREG_BANKSIZE;
2634 brdp->nrports += panelp->nrports;
2635 brdp->panels[panelnr++] = panelp;
2636 if ((brdp->brdtype != BRD_ECHPCI) &&
2637 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
2641 brdp->nrpanels = panelnr;
2642 brdp->nrbnks = banknr;
2643 if (brdp->brdtype == BRD_ECH)
2644 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2646 brdp->state |= BRD_FOUND;
2647 i = stl_mapirq(brdp->irq, name);
2651 /*****************************************************************************/
2654 * Initialize and configure the specified board.
2655 * Scan through all the boards in the configuration and see what we
2656 * can find. Handle EIO and the ECH boards a little differently here
2657 * since the initial search and setup is very different.
2660 static int __init stl_brdinit(stlbrd_t *brdp)
2665 printk("stl_brdinit(brdp=%x)\n", (int) brdp);
2668 switch (brdp->brdtype) {
2680 printk("STALLION: board=%d is unknown board type=%d\n",
2681 brdp->brdnr, brdp->brdtype);
2685 stl_brds[brdp->brdnr] = brdp;
2686 if ((brdp->state & BRD_FOUND) == 0) {
2687 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2688 stl_brdnames[brdp->brdtype], brdp->brdnr,
2689 brdp->ioaddr1, brdp->irq);
2693 for (i = 0; (i < STL_MAXPANELS); i++)
2694 if (brdp->panels[i] != (stlpanel_t *) NULL)
2695 stl_initports(brdp, brdp->panels[i]);
2697 printk("STALLION: %s found, board=%d io=%x irq=%d "
2698 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2699 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2704 /*****************************************************************************/
2707 * Find the next available board number that is free.
2710 static inline int stl_getbrdnr()
2714 for (i = 0; (i < STL_MAXBRDS); i++) {
2715 if (stl_brds[i] == (stlbrd_t *) NULL) {
2716 if (i >= stl_nrbrds)
2724 /*****************************************************************************/
2729 * We have a Stallion board. Allocate a board structure and
2730 * initialize it. Read its IO and IRQ resources from PCI
2731 * configuration space.
2734 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
2739 printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
2740 devp->bus->number, devp->devfn);
2743 if (pci_enable_device(devp))
2745 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2747 if ((brdp->brdnr = stl_getbrdnr()) < 0) {
2748 printk("STALLION: too many boards found, "
2749 "maximum supported %d\n", STL_MAXBRDS);
2752 brdp->brdtype = brdtype;
2755 * Different Stallion boards use the BAR registers in different ways,
2756 * so set up io addresses based on board type.
2759 printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__, __LINE__,
2760 pci_resource_start(devp, 0), pci_resource_start(devp, 1),
2761 pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
2765 * We have all resources from the board, so let's setup the actual
2766 * board structure now.
2770 brdp->ioaddr2 = pci_resource_start(devp, 0);
2771 brdp->ioaddr1 = pci_resource_start(devp, 1);
2774 brdp->ioaddr2 = pci_resource_start(devp, 2);
2775 brdp->ioaddr1 = pci_resource_start(devp, 1);
2778 brdp->ioaddr1 = pci_resource_start(devp, 2);
2779 brdp->ioaddr2 = pci_resource_start(devp, 1);
2782 printk("STALLION: unknown PCI board type=%d\n", brdtype);
2786 brdp->irq = devp->irq;
2792 /*****************************************************************************/
2795 * Find all Stallion PCI boards that might be installed. Initialize each
2796 * one as it is found.
2800 static inline int stl_findpcibrds()
2802 struct pci_dev *dev = NULL;
2806 printk("stl_findpcibrds()\n");
2809 for (i = 0; (i < stl_nrpcibrds); i++)
2810 while ((dev = pci_find_device(stl_pcibrds[i].vendid,
2811 stl_pcibrds[i].devid, dev))) {
2814 * Found a device on the PCI bus that has our vendor and
2815 * device ID. Need to check now that it is really us.
2817 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2820 rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
2830 /*****************************************************************************/
2833 * Scan through all the boards in the configuration and see what we
2834 * can find. Handle EIO and the ECH boards a little differently here
2835 * since the initial search and setup is too different.
2838 static inline int stl_initbrds()
2845 printk("stl_initbrds()\n");
2848 if (stl_nrbrds > STL_MAXBRDS) {
2849 printk("STALLION: too many boards in configuration table, "
2850 "truncating to %d\n", STL_MAXBRDS);
2851 stl_nrbrds = STL_MAXBRDS;
2855 * Firstly scan the list of static boards configured. Allocate
2856 * resources and initialize the boards as found.
2858 for (i = 0; (i < stl_nrbrds); i++) {
2859 confp = &stl_brdconf[i];
2861 stl_parsebrd(confp, stl_brdsp[i]);
2863 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2866 brdp->brdtype = confp->brdtype;
2867 brdp->ioaddr1 = confp->ioaddr1;
2868 brdp->ioaddr2 = confp->ioaddr2;
2869 brdp->irq = confp->irq;
2870 brdp->irqtype = confp->irqtype;
2875 * Find any dynamically supported boards. That is via module load
2876 * line options or auto-detected on the PCI bus.
2888 /*****************************************************************************/
2891 * Return the board stats structure to user app.
2894 static int stl_getbrdstats(combrd_t *bp)
2900 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2902 if (stl_brdstats.brd >= STL_MAXBRDS)
2904 brdp = stl_brds[stl_brdstats.brd];
2905 if (brdp == (stlbrd_t *) NULL)
2908 memset(&stl_brdstats, 0, sizeof(combrd_t));
2909 stl_brdstats.brd = brdp->brdnr;
2910 stl_brdstats.type = brdp->brdtype;
2911 stl_brdstats.hwid = brdp->hwid;
2912 stl_brdstats.state = brdp->state;
2913 stl_brdstats.ioaddr = brdp->ioaddr1;
2914 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2915 stl_brdstats.irq = brdp->irq;
2916 stl_brdstats.nrpanels = brdp->nrpanels;
2917 stl_brdstats.nrports = brdp->nrports;
2918 for (i = 0; (i < brdp->nrpanels); i++) {
2919 panelp = brdp->panels[i];
2920 stl_brdstats.panels[i].panel = i;
2921 stl_brdstats.panels[i].hwid = panelp->hwid;
2922 stl_brdstats.panels[i].nrports = panelp->nrports;
2925 return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
2928 /*****************************************************************************/
2931 * Resolve the referenced port number into a port struct pointer.
2934 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2939 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2940 return((stlport_t *) NULL);
2941 brdp = stl_brds[brdnr];
2942 if (brdp == (stlbrd_t *) NULL)
2943 return((stlport_t *) NULL);
2944 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2945 return((stlport_t *) NULL);
2946 panelp = brdp->panels[panelnr];
2947 if (panelp == (stlpanel_t *) NULL)
2948 return((stlport_t *) NULL);
2949 if ((portnr < 0) || (portnr >= panelp->nrports))
2950 return((stlport_t *) NULL);
2951 return(panelp->ports[portnr]);
2954 /*****************************************************************************/
2957 * Return the port stats structure to user app. A NULL port struct
2958 * pointer passed in means that we need to find out from the app
2959 * what port to get stats for (used through board control device).
2962 static int stl_getportstats(stlport_t *portp, comstats_t *cp)
2964 unsigned char *head, *tail;
2965 unsigned long flags;
2967 if (portp == (stlport_t *) NULL) {
2968 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2970 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2972 if (portp == (stlport_t *) NULL)
2976 portp->stats.state = portp->istate;
2977 portp->stats.flags = portp->flags;
2978 portp->stats.hwid = portp->hwid;
2980 portp->stats.ttystate = 0;
2981 portp->stats.cflags = 0;
2982 portp->stats.iflags = 0;
2983 portp->stats.oflags = 0;
2984 portp->stats.lflags = 0;
2985 portp->stats.rxbuffered = 0;
2989 if (portp->tty != (struct tty_struct *) NULL) {
2990 if (portp->tty->driver_data == portp) {
2991 portp->stats.ttystate = portp->tty->flags;
2992 portp->stats.rxbuffered = portp->tty->flip.count;
2993 if (portp->tty->termios != (struct termios *) NULL) {
2994 portp->stats.cflags = portp->tty->termios->c_cflag;
2995 portp->stats.iflags = portp->tty->termios->c_iflag;
2996 portp->stats.oflags = portp->tty->termios->c_oflag;
2997 portp->stats.lflags = portp->tty->termios->c_lflag;
3001 restore_flags(flags);
3003 head = portp->tx.head;
3004 tail = portp->tx.tail;
3005 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
3006 (STL_TXBUFSIZE - (tail - head)));
3008 portp->stats.signals = (unsigned long) stl_getsignals(portp);
3010 return copy_to_user(cp, &portp->stats,
3011 sizeof(comstats_t)) ? -EFAULT : 0;
3014 /*****************************************************************************/
3017 * Clear the port stats structure. We also return it zeroed out...
3020 static int stl_clrportstats(stlport_t *portp, comstats_t *cp)
3022 if (portp == (stlport_t *) NULL) {
3023 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
3025 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
3027 if (portp == (stlport_t *) NULL)
3031 memset(&portp->stats, 0, sizeof(comstats_t));
3032 portp->stats.brd = portp->brdnr;
3033 portp->stats.panel = portp->panelnr;
3034 portp->stats.port = portp->portnr;
3035 return copy_to_user(cp, &portp->stats,
3036 sizeof(comstats_t)) ? -EFAULT : 0;
3039 /*****************************************************************************/
3042 * Return the entire driver ports structure to a user app.
3045 static int stl_getportstruct(unsigned long arg)
3049 if (copy_from_user(&stl_dummyport, (void *) arg, sizeof(stlport_t)))
3051 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
3052 stl_dummyport.portnr);
3053 if (portp == (stlport_t *) NULL)
3055 return copy_to_user((void *)arg, portp,
3056 sizeof(stlport_t)) ? -EFAULT : 0;
3059 /*****************************************************************************/
3062 * Return the entire driver board structure to a user app.
3065 static int stl_getbrdstruct(unsigned long arg)
3069 if (copy_from_user(&stl_dummybrd, (void *) arg, sizeof(stlbrd_t)))
3071 if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
3073 brdp = stl_brds[stl_dummybrd.brdnr];
3074 if (brdp == (stlbrd_t *) NULL)
3076 return copy_to_user((void *)arg, brdp, sizeof(stlbrd_t)) ? -EFAULT : 0;
3079 /*****************************************************************************/
3082 * The "staliomem" device is also required to do some special operations
3083 * on the board and/or ports. In this driver it is mostly used for stats
3087 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
3092 printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
3093 (int) fp, cmd, (int) arg);
3097 if (brdnr >= STL_MAXBRDS)
3102 case COM_GETPORTSTATS:
3103 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
3104 sizeof(comstats_t))) == 0)
3105 rc = stl_getportstats((stlport_t *) NULL,
3106 (comstats_t *) arg);
3108 case COM_CLRPORTSTATS:
3109 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
3110 sizeof(comstats_t))) == 0)
3111 rc = stl_clrportstats((stlport_t *) NULL,
3112 (comstats_t *) arg);
3114 case COM_GETBRDSTATS:
3115 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
3116 sizeof(combrd_t))) == 0)
3117 rc = stl_getbrdstats((combrd_t *) arg);
3120 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
3121 sizeof(stlport_t))) == 0)
3122 rc = stl_getportstruct(arg);
3125 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
3126 sizeof(stlbrd_t))) == 0)
3127 rc = stl_getbrdstruct(arg);
3137 static struct tty_operations stl_ops = {
3141 .put_char = stl_putchar,
3142 .flush_chars = stl_flushchars,
3143 .write_room = stl_writeroom,
3144 .chars_in_buffer = stl_charsinbuffer,
3146 .set_termios = stl_settermios,
3147 .throttle = stl_throttle,
3148 .unthrottle = stl_unthrottle,
3151 .hangup = stl_hangup,
3152 .flush_buffer = stl_flushbuffer,
3153 .break_ctl = stl_breakctl,
3154 .wait_until_sent = stl_waituntilsent,
3155 .send_xchar = stl_sendxchar,
3156 .read_proc = stl_readproc,
3157 .tiocmget = stl_tiocmget,
3158 .tiocmset = stl_tiocmset,
3161 /*****************************************************************************/
3163 int __init stl_init(void)
3166 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
3170 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
3175 * Allocate a temporary write buffer.
3177 stl_tmpwritebuf = (char *) stl_memalloc(STL_TXBUFSIZE);
3178 if (stl_tmpwritebuf == (char *) NULL)
3179 printk("STALLION: failed to allocate memory (size=%d)\n",
3183 * Set up a character driver for per board stuff. This is mainly used
3184 * to do stats ioctls on the ports.
3186 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
3187 printk("STALLION: failed to register serial board device\n");
3188 devfs_mk_dir("staliomem");
3190 stallion_class = class_simple_create(THIS_MODULE, "staliomem");
3191 for (i = 0; i < 4; i++) {
3192 devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR, i),
3193 S_IFCHR|S_IRUSR|S_IWUSR,
3195 class_simple_device_add(stallion_class, MKDEV(STL_SIOMEMMAJOR, i), NULL, "staliomem%d", i);
3198 stl_serial->owner = THIS_MODULE;
3199 stl_serial->driver_name = stl_drvname;
3200 stl_serial->name = "ttyE";
3201 stl_serial->devfs_name = "tts/E";
3202 stl_serial->major = STL_SERIALMAJOR;
3203 stl_serial->minor_start = 0;
3204 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
3205 stl_serial->subtype = SERIAL_TYPE_NORMAL;
3206 stl_serial->init_termios = stl_deftermios;
3207 stl_serial->flags = TTY_DRIVER_REAL_RAW;
3208 tty_set_operations(stl_serial, &stl_ops);
3210 if (tty_register_driver(stl_serial)) {
3211 put_tty_driver(stl_serial);
3212 printk("STALLION: failed to register serial driver\n");
3219 /*****************************************************************************/
3220 /* CD1400 HARDWARE FUNCTIONS */
3221 /*****************************************************************************/
3224 * These functions get/set/update the registers of the cd1400 UARTs.
3225 * Access to the cd1400 registers is via an address/data io port pair.
3226 * (Maybe should make this inline...)
3229 static int stl_cd1400getreg(stlport_t *portp, int regnr)
3231 outb((regnr + portp->uartaddr), portp->ioaddr);
3232 return(inb(portp->ioaddr + EREG_DATA));
3235 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
3237 outb((regnr + portp->uartaddr), portp->ioaddr);
3238 outb(value, portp->ioaddr + EREG_DATA);
3241 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
3243 outb((regnr + portp->uartaddr), portp->ioaddr);
3244 if (inb(portp->ioaddr + EREG_DATA) != value) {
3245 outb(value, portp->ioaddr + EREG_DATA);
3251 /*****************************************************************************/
3254 * Inbitialize the UARTs in a panel. We don't care what sort of board
3255 * these ports are on - since the port io registers are almost
3256 * identical when dealing with ports.
3259 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3263 int nrchips, uartaddr, ioaddr;
3266 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
3269 BRDENABLE(panelp->brdnr, panelp->pagenr);
3272 * Check that each chip is present and started up OK.
3275 nrchips = panelp->nrports / CD1400_PORTS;
3276 for (i = 0; (i < nrchips); i++) {
3277 if (brdp->brdtype == BRD_ECHPCI) {
3278 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3279 ioaddr = panelp->iobase;
3281 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3283 uartaddr = (i & 0x01) ? 0x080 : 0;
3284 outb((GFRCR + uartaddr), ioaddr);
3285 outb(0, (ioaddr + EREG_DATA));
3286 outb((CCR + uartaddr), ioaddr);
3287 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3288 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3289 outb((GFRCR + uartaddr), ioaddr);
3290 for (j = 0; (j < CCR_MAXWAIT); j++) {
3291 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3294 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3295 printk("STALLION: cd1400 not responding, "
3296 "brd=%d panel=%d chip=%d\n",
3297 panelp->brdnr, panelp->panelnr, i);
3300 chipmask |= (0x1 << i);
3301 outb((PPR + uartaddr), ioaddr);
3302 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
3305 BRDDISABLE(panelp->brdnr);
3309 /*****************************************************************************/
3312 * Initialize hardware specific port registers.
3315 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3318 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3319 (int) brdp, (int) panelp, (int) portp);
3322 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
3323 (portp == (stlport_t *) NULL))
3326 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3327 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3328 portp->uartaddr = (portp->portnr & 0x04) << 5;
3329 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3331 BRDENABLE(portp->brdnr, portp->pagenr);
3332 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3333 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3334 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3335 BRDDISABLE(portp->brdnr);
3338 /*****************************************************************************/
3341 * Wait for the command register to be ready. We will poll this,
3342 * since it won't usually take too long to be ready.
3345 static void stl_cd1400ccrwait(stlport_t *portp)
3349 for (i = 0; (i < CCR_MAXWAIT); i++) {
3350 if (stl_cd1400getreg(portp, CCR) == 0) {
3355 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
3356 portp->portnr, portp->panelnr, portp->brdnr);
3359 /*****************************************************************************/
3362 * Set up the cd1400 registers for a port based on the termios port
3366 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3369 unsigned long flags;
3370 unsigned int clkdiv, baudrate;
3371 unsigned char cor1, cor2, cor3;
3372 unsigned char cor4, cor5, ccr;
3373 unsigned char srer, sreron, sreroff;
3374 unsigned char mcor1, mcor2, rtpr;
3375 unsigned char clk, div;
3391 brdp = stl_brds[portp->brdnr];
3392 if (brdp == (stlbrd_t *) NULL)
3396 * Set up the RX char ignore mask with those RX error types we
3397 * can ignore. We can get the cd1400 to help us out a little here,
3398 * it will ignore parity errors and breaks for us.
3400 portp->rxignoremsk = 0;
3401 if (tiosp->c_iflag & IGNPAR) {
3402 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
3403 cor1 |= COR1_PARIGNORE;
3405 if (tiosp->c_iflag & IGNBRK) {
3406 portp->rxignoremsk |= ST_BREAK;
3407 cor4 |= COR4_IGNBRK;
3410 portp->rxmarkmsk = ST_OVERRUN;
3411 if (tiosp->c_iflag & (INPCK | PARMRK))
3412 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3413 if (tiosp->c_iflag & BRKINT)
3414 portp->rxmarkmsk |= ST_BREAK;
3417 * Go through the char size, parity and stop bits and set all the
3418 * option register appropriately.
3420 switch (tiosp->c_cflag & CSIZE) {
3435 if (tiosp->c_cflag & CSTOPB)
3440 if (tiosp->c_cflag & PARENB) {
3441 if (tiosp->c_cflag & PARODD)
3442 cor1 |= (COR1_PARENB | COR1_PARODD);
3444 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3446 cor1 |= COR1_PARNONE;
3450 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3451 * space for hardware flow control and the like. This should be set to
3452 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3453 * really be based on VTIME.
3455 cor3 |= FIFO_RXTHRESHOLD;
3459 * Calculate the baud rate timers. For now we will just assume that
3460 * the input and output baud are the same. Could have used a baud
3461 * table here, but this way we can generate virtually any baud rate
3464 baudrate = tiosp->c_cflag & CBAUD;
3465 if (baudrate & CBAUDEX) {
3466 baudrate &= ~CBAUDEX;
3467 if ((baudrate < 1) || (baudrate > 4))
3468 tiosp->c_cflag &= ~CBAUDEX;
3472 baudrate = stl_baudrates[baudrate];
3473 if ((tiosp->c_cflag & CBAUD) == B38400) {
3474 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3476 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3478 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3480 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3482 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3483 baudrate = (portp->baud_base / portp->custom_divisor);
3485 if (baudrate > STL_CD1400MAXBAUD)
3486 baudrate = STL_CD1400MAXBAUD;
3489 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3490 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
3494 div = (unsigned char) clkdiv;
3498 * Check what form of modem signaling is required and set it up.
3500 if ((tiosp->c_cflag & CLOCAL) == 0) {
3503 sreron |= SRER_MODEM;
3504 portp->flags |= ASYNC_CHECK_CD;
3506 portp->flags &= ~ASYNC_CHECK_CD;
3510 * Setup cd1400 enhanced modes if we can. In particular we want to
3511 * handle as much of the flow control as possible automatically. As
3512 * well as saving a few CPU cycles it will also greatly improve flow
3513 * control reliability.
3515 if (tiosp->c_iflag & IXON) {
3518 if (tiosp->c_iflag & IXANY)
3522 if (tiosp->c_cflag & CRTSCTS) {
3524 mcor1 |= FIFO_RTSTHRESHOLD;
3528 * All cd1400 register values calculated so go through and set
3533 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3534 portp->portnr, portp->panelnr, portp->brdnr);
3535 printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3536 cor1, cor2, cor3, cor4, cor5);
3537 printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3538 mcor1, mcor2, rtpr, sreron, sreroff);
3539 printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3540 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3541 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3542 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3547 BRDENABLE(portp->brdnr, portp->pagenr);
3548 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3549 srer = stl_cd1400getreg(portp, SRER);
3550 stl_cd1400setreg(portp, SRER, 0);
3551 if (stl_cd1400updatereg(portp, COR1, cor1))
3553 if (stl_cd1400updatereg(portp, COR2, cor2))
3555 if (stl_cd1400updatereg(portp, COR3, cor3))
3558 stl_cd1400ccrwait(portp);
3559 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3561 stl_cd1400setreg(portp, COR4, cor4);
3562 stl_cd1400setreg(portp, COR5, cor5);
3563 stl_cd1400setreg(portp, MCOR1, mcor1);
3564 stl_cd1400setreg(portp, MCOR2, mcor2);
3566 stl_cd1400setreg(portp, TCOR, clk);
3567 stl_cd1400setreg(portp, TBPR, div);
3568 stl_cd1400setreg(portp, RCOR, clk);
3569 stl_cd1400setreg(portp, RBPR, div);
3571 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3572 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3573 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3574 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3575 stl_cd1400setreg(portp, RTPR, rtpr);
3576 mcor1 = stl_cd1400getreg(portp, MSVR1);
3577 if (mcor1 & MSVR1_DCD)
3578 portp->sigs |= TIOCM_CD;
3580 portp->sigs &= ~TIOCM_CD;
3581 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3582 BRDDISABLE(portp->brdnr);
3583 restore_flags(flags);
3586 /*****************************************************************************/
3589 * Set the state of the DTR and RTS signals.
3592 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3594 unsigned char msvr1, msvr2;
3595 unsigned long flags;
3598 printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
3599 (int) portp, dtr, rts);
3611 BRDENABLE(portp->brdnr, portp->pagenr);
3612 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3614 stl_cd1400setreg(portp, MSVR2, msvr2);
3616 stl_cd1400setreg(portp, MSVR1, msvr1);
3617 BRDDISABLE(portp->brdnr);
3618 restore_flags(flags);
3621 /*****************************************************************************/
3624 * Return the state of the signals.
3627 static int stl_cd1400getsignals(stlport_t *portp)
3629 unsigned char msvr1, msvr2;
3630 unsigned long flags;
3634 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3639 BRDENABLE(portp->brdnr, portp->pagenr);
3640 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3641 msvr1 = stl_cd1400getreg(portp, MSVR1);
3642 msvr2 = stl_cd1400getreg(portp, MSVR2);
3643 BRDDISABLE(portp->brdnr);
3644 restore_flags(flags);
3647 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3648 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3649 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3650 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3652 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3653 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3660 /*****************************************************************************/
3663 * Enable/Disable the Transmitter and/or Receiver.
3666 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3669 unsigned long flags;
3672 printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3673 (int) portp, rx, tx);
3678 ccr |= CCR_TXDISABLE;
3680 ccr |= CCR_TXENABLE;
3682 ccr |= CCR_RXDISABLE;
3684 ccr |= CCR_RXENABLE;
3688 BRDENABLE(portp->brdnr, portp->pagenr);
3689 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3690 stl_cd1400ccrwait(portp);
3691 stl_cd1400setreg(portp, CCR, ccr);
3692 stl_cd1400ccrwait(portp);
3693 BRDDISABLE(portp->brdnr);
3694 restore_flags(flags);
3697 /*****************************************************************************/
3700 * Start/stop the Transmitter and/or Receiver.
3703 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3705 unsigned char sreron, sreroff;
3706 unsigned long flags;
3709 printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3710 (int) portp, rx, tx);
3716 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3718 sreron |= SRER_TXDATA;
3720 sreron |= SRER_TXEMPTY;
3722 sreroff |= SRER_RXDATA;
3724 sreron |= SRER_RXDATA;
3728 BRDENABLE(portp->brdnr, portp->pagenr);
3729 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3730 stl_cd1400setreg(portp, SRER,
3731 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3732 BRDDISABLE(portp->brdnr);
3734 set_bit(ASYI_TXBUSY, &portp->istate);
3735 restore_flags(flags);
3738 /*****************************************************************************/
3741 * Disable all interrupts from this port.
3744 static void stl_cd1400disableintrs(stlport_t *portp)
3746 unsigned long flags;
3749 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3753 BRDENABLE(portp->brdnr, portp->pagenr);
3754 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3755 stl_cd1400setreg(portp, SRER, 0);
3756 BRDDISABLE(portp->brdnr);
3757 restore_flags(flags);
3760 /*****************************************************************************/
3762 static void stl_cd1400sendbreak(stlport_t *portp, int len)
3764 unsigned long flags;
3767 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
3772 BRDENABLE(portp->brdnr, portp->pagenr);
3773 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3774 stl_cd1400setreg(portp, SRER,
3775 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3777 BRDDISABLE(portp->brdnr);
3778 portp->brklen = len;
3780 portp->stats.txbreaks++;
3781 restore_flags(flags);
3784 /*****************************************************************************/
3787 * Take flow control actions...
3790 static void stl_cd1400flowctrl(stlport_t *portp, int state)
3792 struct tty_struct *tty;
3793 unsigned long flags;
3796 printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp, state);
3799 if (portp == (stlport_t *) NULL)
3802 if (tty == (struct tty_struct *) NULL)
3807 BRDENABLE(portp->brdnr, portp->pagenr);
3808 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3811 if (tty->termios->c_iflag & IXOFF) {
3812 stl_cd1400ccrwait(portp);
3813 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3814 portp->stats.rxxon++;
3815 stl_cd1400ccrwait(portp);
3818 * Question: should we return RTS to what it was before? It may
3819 * have been set by an ioctl... Suppose not, since if you have
3820 * hardware flow control set then it is pretty silly to go and
3821 * set the RTS line by hand.
3823 if (tty->termios->c_cflag & CRTSCTS) {
3824 stl_cd1400setreg(portp, MCOR1,
3825 (stl_cd1400getreg(portp, MCOR1) |
3826 FIFO_RTSTHRESHOLD));
3827 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3828 portp->stats.rxrtson++;
3831 if (tty->termios->c_iflag & IXOFF) {
3832 stl_cd1400ccrwait(portp);
3833 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3834 portp->stats.rxxoff++;
3835 stl_cd1400ccrwait(portp);
3837 if (tty->termios->c_cflag & CRTSCTS) {
3838 stl_cd1400setreg(portp, MCOR1,
3839 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3840 stl_cd1400setreg(portp, MSVR2, 0);
3841 portp->stats.rxrtsoff++;
3845 BRDDISABLE(portp->brdnr);
3846 restore_flags(flags);
3849 /*****************************************************************************/
3852 * Send a flow control character...
3855 static void stl_cd1400sendflow(stlport_t *portp, int state)
3857 struct tty_struct *tty;
3858 unsigned long flags;
3861 printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp, state);
3864 if (portp == (stlport_t *) NULL)
3867 if (tty == (struct tty_struct *) NULL)
3872 BRDENABLE(portp->brdnr, portp->pagenr);
3873 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3875 stl_cd1400ccrwait(portp);
3876 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3877 portp->stats.rxxon++;
3878 stl_cd1400ccrwait(portp);
3880 stl_cd1400ccrwait(portp);
3881 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3882 portp->stats.rxxoff++;
3883 stl_cd1400ccrwait(portp);
3885 BRDDISABLE(portp->brdnr);
3886 restore_flags(flags);
3889 /*****************************************************************************/
3891 static void stl_cd1400flush(stlport_t *portp)
3893 unsigned long flags;
3896 printk("stl_cd1400flush(portp=%x)\n", (int) portp);
3899 if (portp == (stlport_t *) NULL)
3904 BRDENABLE(portp->brdnr, portp->pagenr);
3905 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3906 stl_cd1400ccrwait(portp);
3907 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3908 stl_cd1400ccrwait(portp);
3909 portp->tx.tail = portp->tx.head;
3910 BRDDISABLE(portp->brdnr);
3911 restore_flags(flags);
3914 /*****************************************************************************/
3917 * Return the current state of data flow on this port. This is only
3918 * really interresting when determining if data has fully completed
3919 * transmission or not... This is easy for the cd1400, it accurately
3920 * maintains the busy port flag.
3923 static int stl_cd1400datastate(stlport_t *portp)
3926 printk("stl_cd1400datastate(portp=%x)\n", (int) portp);
3929 if (portp == (stlport_t *) NULL)
3932 return(test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0);
3935 /*****************************************************************************/
3938 * Interrupt service routine for cd1400 EasyIO boards.
3941 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3943 unsigned char svrtype;
3946 printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
3947 (int) panelp, iobase);
3951 svrtype = inb(iobase + EREG_DATA);
3952 if (panelp->nrports > 4) {
3953 outb((SVRR + 0x80), iobase);
3954 svrtype |= inb(iobase + EREG_DATA);
3957 if (svrtype & SVRR_RX)
3958 stl_cd1400rxisr(panelp, iobase);
3959 else if (svrtype & SVRR_TX)
3960 stl_cd1400txisr(panelp, iobase);
3961 else if (svrtype & SVRR_MDM)
3962 stl_cd1400mdmisr(panelp, iobase);
3965 /*****************************************************************************/
3968 * Interrupt service routine for cd1400 panels.
3971 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
3973 unsigned char svrtype;
3976 printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
3981 svrtype = inb(iobase + EREG_DATA);
3982 outb((SVRR + 0x80), iobase);
3983 svrtype |= inb(iobase + EREG_DATA);
3984 if (svrtype & SVRR_RX)
3985 stl_cd1400rxisr(panelp, iobase);
3986 else if (svrtype & SVRR_TX)
3987 stl_cd1400txisr(panelp, iobase);
3988 else if (svrtype & SVRR_MDM)
3989 stl_cd1400mdmisr(panelp, iobase);
3993 /*****************************************************************************/
3996 * Unfortunately we need to handle breaks in the TX data stream, since
3997 * this is the only way to generate them on the cd1400.
4000 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr)
4002 if (portp->brklen == 1) {
4003 outb((COR2 + portp->uartaddr), ioaddr);
4004 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
4005 (ioaddr + EREG_DATA));
4006 outb((TDR + portp->uartaddr), ioaddr);
4007 outb(ETC_CMD, (ioaddr + EREG_DATA));
4008 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
4009 outb((SRER + portp->uartaddr), ioaddr);
4010 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
4011 (ioaddr + EREG_DATA));
4013 } else if (portp->brklen > 1) {
4014 outb((TDR + portp->uartaddr), ioaddr);
4015 outb(ETC_CMD, (ioaddr + EREG_DATA));
4016 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
4020 outb((COR2 + portp->uartaddr), ioaddr);
4021 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
4022 (ioaddr + EREG_DATA));
4028 /*****************************************************************************/
4031 * Transmit interrupt handler. This has gotta be fast! Handling TX
4032 * chars is pretty simple, stuff as many as possible from the TX buffer
4033 * into the cd1400 FIFO. Must also handle TX breaks here, since they
4034 * are embedded as commands in the data stream. Oh no, had to use a goto!
4035 * This could be optimized more, will do when I get time...
4036 * In practice it is possible that interrupts are enabled but that the
4037 * port has been hung up. Need to handle not having any TX buffer here,
4038 * this is done by using the side effect that head and tail will also
4039 * be NULL if the buffer has been freed.
4042 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
4047 unsigned char ioack, srer;
4050 printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
4053 ioack = inb(ioaddr + EREG_TXACK);
4054 if (((ioack & panelp->ackmask) != 0) ||
4055 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
4056 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
4059 portp = panelp->ports[(ioack >> 3)];
4062 * Unfortunately we need to handle breaks in the data stream, since
4063 * this is the only way to generate them on the cd1400. Do it now if
4064 * a break is to be sent.
4066 if (portp->brklen != 0)
4067 if (stl_cd1400breakisr(portp, ioaddr))
4070 head = portp->tx.head;
4071 tail = portp->tx.tail;
4072 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4073 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4074 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4075 set_bit(ASYI_TXLOW, &portp->istate);
4076 schedule_work(&portp->tqueue);
4080 outb((SRER + portp->uartaddr), ioaddr);
4081 srer = inb(ioaddr + EREG_DATA);
4082 if (srer & SRER_TXDATA) {
4083 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
4085 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
4086 clear_bit(ASYI_TXBUSY, &portp->istate);
4088 outb(srer, (ioaddr + EREG_DATA));
4090 len = MIN(len, CD1400_TXFIFOSIZE);
4091 portp->stats.txtotal += len;
4092 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4093 outb((TDR + portp->uartaddr), ioaddr);
4094 outsb((ioaddr + EREG_DATA), tail, stlen);
4097 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4098 tail = portp->tx.buf;
4100 outsb((ioaddr + EREG_DATA), tail, len);
4103 portp->tx.tail = tail;
4107 outb((EOSRR + portp->uartaddr), ioaddr);
4108 outb(0, (ioaddr + EREG_DATA));
4111 /*****************************************************************************/
4114 * Receive character interrupt handler. Determine if we have good chars
4115 * or bad chars and then process appropriately. Good chars are easy
4116 * just shove the lot into the RX buffer and set all status byte to 0.
4117 * If a bad RX char then process as required. This routine needs to be
4118 * fast! In practice it is possible that we get an interrupt on a port
4119 * that is closed. This can happen on hangups - since they completely
4120 * shutdown a port not in user context. Need to handle this case.
4123 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
4126 struct tty_struct *tty;
4127 unsigned int ioack, len, buflen;
4128 unsigned char status;
4132 printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
4135 ioack = inb(ioaddr + EREG_RXACK);
4136 if ((ioack & panelp->ackmask) != 0) {
4137 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4140 portp = panelp->ports[(ioack >> 3)];
4143 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
4144 outb((RDCR + portp->uartaddr), ioaddr);
4145 len = inb(ioaddr + EREG_DATA);
4146 if ((tty == (struct tty_struct *) NULL) ||
4147 (tty->flip.char_buf_ptr == (char *) NULL) ||
4148 ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
4149 len = MIN(len, sizeof(stl_unwanted));
4150 outb((RDSR + portp->uartaddr), ioaddr);
4151 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
4152 portp->stats.rxlost += len;
4153 portp->stats.rxtotal += len;
4155 len = MIN(len, buflen);
4157 outb((RDSR + portp->uartaddr), ioaddr);
4158 insb((ioaddr + EREG_DATA), tty->flip.char_buf_ptr, len);
4159 memset(tty->flip.flag_buf_ptr, 0, len);
4160 tty->flip.flag_buf_ptr += len;
4161 tty->flip.char_buf_ptr += len;
4162 tty->flip.count += len;
4163 tty_schedule_flip(tty);
4164 portp->stats.rxtotal += len;
4167 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
4168 outb((RDSR + portp->uartaddr), ioaddr);
4169 status = inb(ioaddr + EREG_DATA);
4170 ch = inb(ioaddr + EREG_DATA);
4171 if (status & ST_PARITY)
4172 portp->stats.rxparity++;
4173 if (status & ST_FRAMING)
4174 portp->stats.rxframing++;
4175 if (status & ST_OVERRUN)
4176 portp->stats.rxoverrun++;
4177 if (status & ST_BREAK)
4178 portp->stats.rxbreaks++;
4179 if (status & ST_SCHARMASK) {
4180 if ((status & ST_SCHARMASK) == ST_SCHAR1)
4181 portp->stats.txxon++;
4182 if ((status & ST_SCHARMASK) == ST_SCHAR2)
4183 portp->stats.txxoff++;
4186 if ((tty != (struct tty_struct *) NULL) &&
4187 ((portp->rxignoremsk & status) == 0)) {
4188 if (portp->rxmarkmsk & status) {
4189 if (status & ST_BREAK) {
4191 if (portp->flags & ASYNC_SAK) {
4193 BRDENABLE(portp->brdnr, portp->pagenr);
4195 } else if (status & ST_PARITY) {
4196 status = TTY_PARITY;
4197 } else if (status & ST_FRAMING) {
4199 } else if(status & ST_OVERRUN) {
4200 status = TTY_OVERRUN;
4207 if (tty->flip.char_buf_ptr != (char *) NULL) {
4208 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
4209 *tty->flip.flag_buf_ptr++ = status;
4210 *tty->flip.char_buf_ptr++ = ch;
4213 tty_schedule_flip(tty);
4217 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4222 outb((EOSRR + portp->uartaddr), ioaddr);
4223 outb(0, (ioaddr + EREG_DATA));
4226 /*****************************************************************************/
4229 * Modem interrupt handler. The is called when the modem signal line
4230 * (DCD) has changed state. Leave most of the work to the off-level
4231 * processing routine.
4234 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
4241 printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp);
4244 ioack = inb(ioaddr + EREG_MDACK);
4245 if (((ioack & panelp->ackmask) != 0) ||
4246 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
4247 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
4250 portp = panelp->ports[(ioack >> 3)];
4252 outb((MISR + portp->uartaddr), ioaddr);
4253 misr = inb(ioaddr + EREG_DATA);
4254 if (misr & MISR_DCD) {
4255 set_bit(ASYI_DCDCHANGE, &portp->istate);
4256 schedule_work(&portp->tqueue);
4257 portp->stats.modem++;
4260 outb((EOSRR + portp->uartaddr), ioaddr);
4261 outb(0, (ioaddr + EREG_DATA));
4264 /*****************************************************************************/
4265 /* SC26198 HARDWARE FUNCTIONS */
4266 /*****************************************************************************/
4269 * These functions get/set/update the registers of the sc26198 UARTs.
4270 * Access to the sc26198 registers is via an address/data io port pair.
4271 * (Maybe should make this inline...)
4274 static int stl_sc26198getreg(stlport_t *portp, int regnr)
4276 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4277 return(inb(portp->ioaddr + XP_DATA));
4280 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
4282 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4283 outb(value, (portp->ioaddr + XP_DATA));
4286 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
4288 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4289 if (inb(portp->ioaddr + XP_DATA) != value) {
4290 outb(value, (portp->ioaddr + XP_DATA));
4296 /*****************************************************************************/
4299 * Functions to get and set the sc26198 global registers.
4302 static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
4304 outb(regnr, (portp->ioaddr + XP_ADDR));
4305 return(inb(portp->ioaddr + XP_DATA));
4309 static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
4311 outb(regnr, (portp->ioaddr + XP_ADDR));
4312 outb(value, (portp->ioaddr + XP_DATA));
4316 /*****************************************************************************/
4319 * Inbitialize the UARTs in a panel. We don't care what sort of board
4320 * these ports are on - since the port io registers are almost
4321 * identical when dealing with ports.
4324 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
4327 int nrchips, ioaddr;
4330 printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
4331 (int) brdp, (int) panelp);
4334 BRDENABLE(panelp->brdnr, panelp->pagenr);
4337 * Check that each chip is present and started up OK.
4340 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
4341 if (brdp->brdtype == BRD_ECHPCI)
4342 outb(panelp->pagenr, brdp->ioctrl);
4344 for (i = 0; (i < nrchips); i++) {
4345 ioaddr = panelp->iobase + (i * 4);
4346 outb(SCCR, (ioaddr + XP_ADDR));
4347 outb(CR_RESETALL, (ioaddr + XP_DATA));
4348 outb(TSTR, (ioaddr + XP_ADDR));
4349 if (inb(ioaddr + XP_DATA) != 0) {
4350 printk("STALLION: sc26198 not responding, "
4351 "brd=%d panel=%d chip=%d\n",
4352 panelp->brdnr, panelp->panelnr, i);
4355 chipmask |= (0x1 << i);
4356 outb(GCCR, (ioaddr + XP_ADDR));
4357 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
4358 outb(WDTRCR, (ioaddr + XP_ADDR));
4359 outb(0xff, (ioaddr + XP_DATA));
4362 BRDDISABLE(panelp->brdnr);
4366 /*****************************************************************************/
4369 * Initialize hardware specific port registers.
4372 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
4375 printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
4376 (int) brdp, (int) panelp, (int) portp);
4379 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
4380 (portp == (stlport_t *) NULL))
4383 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
4384 portp->uartaddr = (portp->portnr & 0x07) << 4;
4385 portp->pagenr = panelp->pagenr;
4388 BRDENABLE(portp->brdnr, portp->pagenr);
4389 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
4390 BRDDISABLE(portp->brdnr);
4393 /*****************************************************************************/
4396 * Set up the sc26198 registers for a port based on the termios port
4400 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4403 unsigned long flags;
4404 unsigned int baudrate;
4405 unsigned char mr0, mr1, mr2, clk;
4406 unsigned char imron, imroff, iopr, ipr;
4416 brdp = stl_brds[portp->brdnr];
4417 if (brdp == (stlbrd_t *) NULL)
4421 * Set up the RX char ignore mask with those RX error types we
4424 portp->rxignoremsk = 0;
4425 if (tiosp->c_iflag & IGNPAR)
4426 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
4428 if (tiosp->c_iflag & IGNBRK)
4429 portp->rxignoremsk |= SR_RXBREAK;
4431 portp->rxmarkmsk = SR_RXOVERRUN;
4432 if (tiosp->c_iflag & (INPCK | PARMRK))
4433 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
4434 if (tiosp->c_iflag & BRKINT)
4435 portp->rxmarkmsk |= SR_RXBREAK;
4438 * Go through the char size, parity and stop bits and set all the
4439 * option register appropriately.
4441 switch (tiosp->c_cflag & CSIZE) {
4456 if (tiosp->c_cflag & CSTOPB)
4461 if (tiosp->c_cflag & PARENB) {
4462 if (tiosp->c_cflag & PARODD)
4463 mr1 |= (MR1_PARENB | MR1_PARODD);
4465 mr1 |= (MR1_PARENB | MR1_PAREVEN);
4470 mr1 |= MR1_ERRBLOCK;
4473 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4474 * space for hardware flow control and the like. This should be set to
4477 mr2 |= MR2_RXFIFOHALF;
4480 * Calculate the baud rate timers. For now we will just assume that
4481 * the input and output baud are the same. The sc26198 has a fixed
4482 * baud rate table, so only discrete baud rates possible.
4484 baudrate = tiosp->c_cflag & CBAUD;
4485 if (baudrate & CBAUDEX) {
4486 baudrate &= ~CBAUDEX;
4487 if ((baudrate < 1) || (baudrate > 4))
4488 tiosp->c_cflag &= ~CBAUDEX;
4492 baudrate = stl_baudrates[baudrate];
4493 if ((tiosp->c_cflag & CBAUD) == B38400) {
4494 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
4496 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
4498 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
4500 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
4502 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
4503 baudrate = (portp->baud_base / portp->custom_divisor);
4505 if (baudrate > STL_SC26198MAXBAUD)
4506 baudrate = STL_SC26198MAXBAUD;
4509 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
4510 if (baudrate <= sc26198_baudtable[clk])
4516 * Check what form of modem signaling is required and set it up.
4518 if (tiosp->c_cflag & CLOCAL) {
4519 portp->flags &= ~ASYNC_CHECK_CD;
4521 iopr |= IOPR_DCDCOS;
4523 portp->flags |= ASYNC_CHECK_CD;
4527 * Setup sc26198 enhanced modes if we can. In particular we want to
4528 * handle as much of the flow control as possible automatically. As
4529 * well as saving a few CPU cycles it will also greatly improve flow
4530 * control reliability.
4532 if (tiosp->c_iflag & IXON) {
4533 mr0 |= MR0_SWFTX | MR0_SWFT;
4534 imron |= IR_XONXOFF;
4536 imroff |= IR_XONXOFF;
4538 if (tiosp->c_iflag & IXOFF)
4541 if (tiosp->c_cflag & CRTSCTS) {
4547 * All sc26198 register values calculated so go through and set
4552 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4553 portp->portnr, portp->panelnr, portp->brdnr);
4554 printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4555 printk(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4556 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4557 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4558 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4563 BRDENABLE(portp->brdnr, portp->pagenr);
4564 stl_sc26198setreg(portp, IMR, 0);
4565 stl_sc26198updatereg(portp, MR0, mr0);
4566 stl_sc26198updatereg(portp, MR1, mr1);
4567 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4568 stl_sc26198updatereg(portp, MR2, mr2);
4569 stl_sc26198updatereg(portp, IOPIOR,
4570 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
4573 stl_sc26198setreg(portp, TXCSR, clk);
4574 stl_sc26198setreg(portp, RXCSR, clk);
4577 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4578 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4580 ipr = stl_sc26198getreg(portp, IPR);
4582 portp->sigs &= ~TIOCM_CD;
4584 portp->sigs |= TIOCM_CD;
4586 portp->imr = (portp->imr & ~imroff) | imron;
4587 stl_sc26198setreg(portp, IMR, portp->imr);
4588 BRDDISABLE(portp->brdnr);
4589 restore_flags(flags);
4592 /*****************************************************************************/
4595 * Set the state of the DTR and RTS signals.
4598 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
4600 unsigned char iopioron, iopioroff;
4601 unsigned long flags;
4604 printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4605 (int) portp, dtr, rts);
4611 iopioroff |= IPR_DTR;
4613 iopioron |= IPR_DTR;
4615 iopioroff |= IPR_RTS;
4617 iopioron |= IPR_RTS;
4621 BRDENABLE(portp->brdnr, portp->pagenr);
4622 stl_sc26198setreg(portp, IOPIOR,
4623 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4624 BRDDISABLE(portp->brdnr);
4625 restore_flags(flags);
4628 /*****************************************************************************/
4631 * Return the state of the signals.
4634 static int stl_sc26198getsignals(stlport_t *portp)
4637 unsigned long flags;
4641 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
4646 BRDENABLE(portp->brdnr, portp->pagenr);
4647 ipr = stl_sc26198getreg(portp, IPR);
4648 BRDDISABLE(portp->brdnr);
4649 restore_flags(flags);
4652 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4653 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4654 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4655 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4660 /*****************************************************************************/
4663 * Enable/Disable the Transmitter and/or Receiver.
4666 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
4669 unsigned long flags;
4672 printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4673 (int) portp, rx, tx);
4676 ccr = portp->crenable;
4678 ccr &= ~CR_TXENABLE;
4682 ccr &= ~CR_RXENABLE;
4688 BRDENABLE(portp->brdnr, portp->pagenr);
4689 stl_sc26198setreg(portp, SCCR, ccr);
4690 BRDDISABLE(portp->brdnr);
4691 portp->crenable = ccr;
4692 restore_flags(flags);
4695 /*****************************************************************************/
4698 * Start/stop the Transmitter and/or Receiver.
4701 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
4704 unsigned long flags;
4707 printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4708 (int) portp, rx, tx);
4717 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4719 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4723 BRDENABLE(portp->brdnr, portp->pagenr);
4724 stl_sc26198setreg(portp, IMR, imr);
4725 BRDDISABLE(portp->brdnr);
4728 set_bit(ASYI_TXBUSY, &portp->istate);
4729 restore_flags(flags);
4732 /*****************************************************************************/
4735 * Disable all interrupts from this port.
4738 static void stl_sc26198disableintrs(stlport_t *portp)
4740 unsigned long flags;
4743 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
4748 BRDENABLE(portp->brdnr, portp->pagenr);
4750 stl_sc26198setreg(portp, IMR, 0);
4751 BRDDISABLE(portp->brdnr);
4752 restore_flags(flags);
4755 /*****************************************************************************/
4757 static void stl_sc26198sendbreak(stlport_t *portp, int len)
4759 unsigned long flags;
4762 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
4767 BRDENABLE(portp->brdnr, portp->pagenr);
4769 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4770 portp->stats.txbreaks++;
4772 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4774 BRDDISABLE(portp->brdnr);
4775 restore_flags(flags);
4778 /*****************************************************************************/
4781 * Take flow control actions...
4784 static void stl_sc26198flowctrl(stlport_t *portp, int state)
4786 struct tty_struct *tty;
4787 unsigned long flags;
4791 printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp, state);
4794 if (portp == (stlport_t *) NULL)
4797 if (tty == (struct tty_struct *) NULL)
4802 BRDENABLE(portp->brdnr, portp->pagenr);
4805 if (tty->termios->c_iflag & IXOFF) {
4806 mr0 = stl_sc26198getreg(portp, MR0);
4807 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4808 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4810 portp->stats.rxxon++;
4811 stl_sc26198wait(portp);
4812 stl_sc26198setreg(portp, MR0, mr0);
4815 * Question: should we return RTS to what it was before? It may
4816 * have been set by an ioctl... Suppose not, since if you have
4817 * hardware flow control set then it is pretty silly to go and
4818 * set the RTS line by hand.
4820 if (tty->termios->c_cflag & CRTSCTS) {
4821 stl_sc26198setreg(portp, MR1,
4822 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4823 stl_sc26198setreg(portp, IOPIOR,
4824 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4825 portp->stats.rxrtson++;
4828 if (tty->termios->c_iflag & IXOFF) {
4829 mr0 = stl_sc26198getreg(portp, MR0);
4830 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4831 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4833 portp->stats.rxxoff++;
4834 stl_sc26198wait(portp);
4835 stl_sc26198setreg(portp, MR0, mr0);
4837 if (tty->termios->c_cflag & CRTSCTS) {
4838 stl_sc26198setreg(portp, MR1,
4839 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4840 stl_sc26198setreg(portp, IOPIOR,
4841 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4842 portp->stats.rxrtsoff++;
4846 BRDDISABLE(portp->brdnr);
4847 restore_flags(flags);
4850 /*****************************************************************************/
4853 * Send a flow control character.
4856 static void stl_sc26198sendflow(stlport_t *portp, int state)
4858 struct tty_struct *tty;
4859 unsigned long flags;
4863 printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp, state);
4866 if (portp == (stlport_t *) NULL)
4869 if (tty == (struct tty_struct *) NULL)
4874 BRDENABLE(portp->brdnr, portp->pagenr);
4876 mr0 = stl_sc26198getreg(portp, MR0);
4877 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4878 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4880 portp->stats.rxxon++;
4881 stl_sc26198wait(portp);
4882 stl_sc26198setreg(portp, MR0, mr0);
4884 mr0 = stl_sc26198getreg(portp, MR0);
4885 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4886 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4888 portp->stats.rxxoff++;
4889 stl_sc26198wait(portp);
4890 stl_sc26198setreg(portp, MR0, mr0);
4892 BRDDISABLE(portp->brdnr);
4893 restore_flags(flags);
4896 /*****************************************************************************/
4898 static void stl_sc26198flush(stlport_t *portp)
4900 unsigned long flags;
4903 printk("stl_sc26198flush(portp=%x)\n", (int) portp);
4906 if (portp == (stlport_t *) NULL)
4911 BRDENABLE(portp->brdnr, portp->pagenr);
4912 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4913 stl_sc26198setreg(portp, SCCR, portp->crenable);
4914 BRDDISABLE(portp->brdnr);
4915 portp->tx.tail = portp->tx.head;
4916 restore_flags(flags);
4919 /*****************************************************************************/
4922 * Return the current state of data flow on this port. This is only
4923 * really interresting when determining if data has fully completed
4924 * transmission or not... The sc26198 interrupt scheme cannot
4925 * determine when all data has actually drained, so we need to
4926 * check the port statusy register to be sure.
4929 static int stl_sc26198datastate(stlport_t *portp)
4931 unsigned long flags;
4935 printk("stl_sc26198datastate(portp=%x)\n", (int) portp);
4938 if (portp == (stlport_t *) NULL)
4940 if (test_bit(ASYI_TXBUSY, &portp->istate))
4945 BRDENABLE(portp->brdnr, portp->pagenr);
4946 sr = stl_sc26198getreg(portp, SR);
4947 BRDDISABLE(portp->brdnr);
4948 restore_flags(flags);
4950 return((sr & SR_TXEMPTY) ? 0 : 1);
4953 /*****************************************************************************/
4956 * Delay for a small amount of time, to give the sc26198 a chance
4957 * to process a command...
4960 static void stl_sc26198wait(stlport_t *portp)
4965 printk("stl_sc26198wait(portp=%x)\n", (int) portp);
4968 if (portp == (stlport_t *) NULL)
4971 for (i = 0; (i < 20); i++)
4972 stl_sc26198getglobreg(portp, TSTR);
4975 /*****************************************************************************/
4978 * If we are TX flow controlled and in IXANY mode then we may
4979 * need to unflow control here. We gotta do this because of the
4980 * automatic flow control modes of the sc26198.
4983 static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty)
4987 mr0 = stl_sc26198getreg(portp, MR0);
4988 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4989 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4990 stl_sc26198wait(portp);
4991 stl_sc26198setreg(portp, MR0, mr0);
4992 clear_bit(ASYI_TXFLOWED, &portp->istate);
4995 /*****************************************************************************/
4998 * Interrupt service routine for sc26198 panels.
5001 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
5007 * Work around bug in sc26198 chip... Cannot have A6 address
5008 * line of UART high, else iack will be returned as 0.
5010 outb(0, (iobase + 1));
5012 iack = inb(iobase + XP_IACK);
5013 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
5015 if (iack & IVR_RXDATA)
5016 stl_sc26198rxisr(portp, iack);
5017 else if (iack & IVR_TXDATA)
5018 stl_sc26198txisr(portp);
5020 stl_sc26198otherisr(portp, iack);
5023 /*****************************************************************************/
5026 * Transmit interrupt handler. This has gotta be fast! Handling TX
5027 * chars is pretty simple, stuff as many as possible from the TX buffer
5028 * into the sc26198 FIFO.
5029 * In practice it is possible that interrupts are enabled but that the
5030 * port has been hung up. Need to handle not having any TX buffer here,
5031 * this is done by using the side effect that head and tail will also
5032 * be NULL if the buffer has been freed.
5035 static void stl_sc26198txisr(stlport_t *portp)
5037 unsigned int ioaddr;
5043 printk("stl_sc26198txisr(portp=%x)\n", (int) portp);
5046 ioaddr = portp->ioaddr;
5047 head = portp->tx.head;
5048 tail = portp->tx.tail;
5049 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
5050 if ((len == 0) || ((len < STL_TXBUFLOW) &&
5051 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
5052 set_bit(ASYI_TXLOW, &portp->istate);
5053 schedule_work(&portp->tqueue);
5057 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
5058 mr0 = inb(ioaddr + XP_DATA);
5059 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
5060 portp->imr &= ~IR_TXRDY;
5061 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
5062 outb(portp->imr, (ioaddr + XP_DATA));
5063 clear_bit(ASYI_TXBUSY, &portp->istate);
5065 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
5066 outb(mr0, (ioaddr + XP_DATA));
5069 len = MIN(len, SC26198_TXFIFOSIZE);
5070 portp->stats.txtotal += len;
5071 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
5072 outb(GTXFIFO, (ioaddr + XP_ADDR));
5073 outsb((ioaddr + XP_DATA), tail, stlen);
5076 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
5077 tail = portp->tx.buf;
5079 outsb((ioaddr + XP_DATA), tail, len);
5082 portp->tx.tail = tail;
5086 /*****************************************************************************/
5089 * Receive character interrupt handler. Determine if we have good chars
5090 * or bad chars and then process appropriately. Good chars are easy
5091 * just shove the lot into the RX buffer and set all status byte to 0.
5092 * If a bad RX char then process as required. This routine needs to be
5093 * fast! In practice it is possible that we get an interrupt on a port
5094 * that is closed. This can happen on hangups - since they completely
5095 * shutdown a port not in user context. Need to handle this case.
5098 static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
5100 struct tty_struct *tty;
5101 unsigned int len, buflen, ioaddr;
5104 printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
5108 ioaddr = portp->ioaddr;
5109 outb(GIBCR, (ioaddr + XP_ADDR));
5110 len = inb(ioaddr + XP_DATA) + 1;
5112 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
5113 if ((tty == (struct tty_struct *) NULL) ||
5114 (tty->flip.char_buf_ptr == (char *) NULL) ||
5115 ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
5116 len = MIN(len, sizeof(stl_unwanted));
5117 outb(GRXFIFO, (ioaddr + XP_ADDR));
5118 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
5119 portp->stats.rxlost += len;
5120 portp->stats.rxtotal += len;
5122 len = MIN(len, buflen);
5124 outb(GRXFIFO, (ioaddr + XP_ADDR));
5125 insb((ioaddr + XP_DATA), tty->flip.char_buf_ptr, len);
5126 memset(tty->flip.flag_buf_ptr, 0, len);
5127 tty->flip.flag_buf_ptr += len;
5128 tty->flip.char_buf_ptr += len;
5129 tty->flip.count += len;
5130 tty_schedule_flip(tty);
5131 portp->stats.rxtotal += len;
5135 stl_sc26198rxbadchars(portp);
5139 * If we are TX flow controlled and in IXANY mode then we may need
5140 * to unflow control here. We gotta do this because of the automatic
5141 * flow control modes of the sc26198.
5143 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
5144 if ((tty != (struct tty_struct *) NULL) &&
5145 (tty->termios != (struct termios *) NULL) &&
5146 (tty->termios->c_iflag & IXANY)) {
5147 stl_sc26198txunflow(portp, tty);
5152 /*****************************************************************************/
5155 * Process an RX bad character.
5158 static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch)
5160 struct tty_struct *tty;
5161 unsigned int ioaddr;
5164 ioaddr = portp->ioaddr;
5166 if (status & SR_RXPARITY)
5167 portp->stats.rxparity++;
5168 if (status & SR_RXFRAMING)
5169 portp->stats.rxframing++;
5170 if (status & SR_RXOVERRUN)
5171 portp->stats.rxoverrun++;
5172 if (status & SR_RXBREAK)
5173 portp->stats.rxbreaks++;
5175 if ((tty != (struct tty_struct *) NULL) &&
5176 ((portp->rxignoremsk & status) == 0)) {
5177 if (portp->rxmarkmsk & status) {
5178 if (status & SR_RXBREAK) {
5180 if (portp->flags & ASYNC_SAK) {
5182 BRDENABLE(portp->brdnr, portp->pagenr);
5184 } else if (status & SR_RXPARITY) {
5185 status = TTY_PARITY;
5186 } else if (status & SR_RXFRAMING) {
5188 } else if(status & SR_RXOVERRUN) {
5189 status = TTY_OVERRUN;
5197 if (tty->flip.char_buf_ptr != (char *) NULL) {
5198 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
5199 *tty->flip.flag_buf_ptr++ = status;
5200 *tty->flip.char_buf_ptr++ = ch;
5203 tty_schedule_flip(tty);
5207 portp->stats.rxtotal++;
5211 /*****************************************************************************/
5214 * Process all characters in the RX FIFO of the UART. Check all char
5215 * status bytes as well, and process as required. We need to check
5216 * all bytes in the FIFO, in case some more enter the FIFO while we
5217 * are here. To get the exact character error type we need to switch
5218 * into CHAR error mode (that is why we need to make sure we empty
5222 static void stl_sc26198rxbadchars(stlport_t *portp)
5224 unsigned char status, mr1;
5228 * To get the precise error type for each character we must switch
5229 * back into CHAR error mode.
5231 mr1 = stl_sc26198getreg(portp, MR1);
5232 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
5234 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
5235 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
5236 ch = stl_sc26198getreg(portp, RXFIFO);
5237 stl_sc26198rxbadch(portp, status, ch);
5241 * To get correct interrupt class we must switch back into BLOCK
5244 stl_sc26198setreg(portp, MR1, mr1);
5247 /*****************************************************************************/
5250 * Other interrupt handler. This includes modem signals, flow
5251 * control actions, etc. Most stuff is left to off-level interrupt
5255 static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
5257 unsigned char cir, ipr, xisr;
5260 printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
5263 cir = stl_sc26198getglobreg(portp, CIR);
5265 switch (cir & CIR_SUBTYPEMASK) {
5267 ipr = stl_sc26198getreg(portp, IPR);
5268 if (ipr & IPR_DCDCHANGE) {
5269 set_bit(ASYI_DCDCHANGE, &portp->istate);
5270 schedule_work(&portp->tqueue);
5271 portp->stats.modem++;
5274 case CIR_SUBXONXOFF:
5275 xisr = stl_sc26198getreg(portp, XISR);
5276 if (xisr & XISR_RXXONGOT) {
5277 set_bit(ASYI_TXFLOWED, &portp->istate);
5278 portp->stats.txxoff++;
5280 if (xisr & XISR_RXXOFFGOT) {
5281 clear_bit(ASYI_TXFLOWED, &portp->istate);
5282 portp->stats.txxon++;
5286 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
5287 stl_sc26198rxbadchars(portp);
5294 /*****************************************************************************/