1 /*****************************************************************************/
4 * stallion.c -- stallion multiport serial driver.
6 * Copyright (C) 1996-1999 Stallion Technologies
7 * Copyright (C) 1994-1996 Greg Ungerer.
9 * This code is loosely based on the Linux serial driver, written by
10 * Linus Torvalds, Theodore T'so and others.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /*****************************************************************************/
29 #include <linux/module.h>
30 #include <linux/slab.h>
31 #include <linux/interrupt.h>
32 #include <linux/tty.h>
33 #include <linux/tty_flip.h>
34 #include <linux/serial.h>
35 #include <linux/cd1400.h>
36 #include <linux/sc26198.h>
37 #include <linux/comstats.h>
38 #include <linux/stallion.h>
39 #include <linux/ioport.h>
40 #include <linux/init.h>
41 #include <linux/smp_lock.h>
42 #include <linux/device.h>
43 #include <linux/delay.h>
46 #include <asm/uaccess.h>
49 #include <linux/pci.h>
52 /*****************************************************************************/
55 * Define different board types. Use the standard Stallion "assigned"
56 * board numbers. Boards supported in this driver are abbreviated as
57 * EIO = EasyIO and ECH = EasyConnection 8/32.
63 #define BRD_ECH64PCI 27
64 #define BRD_EASYIOPCI 28
67 * Define a configuration structure to hold the board configuration.
68 * Need to set this up in the code (for now) with the boards that are
69 * to be configured into the system. This is what needs to be modified
70 * when adding/removing/modifying boards. Each line entry in the
71 * stl_brdconf[] array is a board. Each line contains io/irq/memory
72 * ranges for that board (as well as what type of board it is).
74 * { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
75 * This line would configure an EasyIO board (4 or 8, no difference),
76 * at io address 2a0 and irq 10.
78 * { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
79 * This line will configure an EasyConnection 8/32 board at primary io
80 * address 2a8, secondary io address 280 and irq 12.
81 * Enter as many lines into this array as you want (only the first 4
82 * will actually be used!). Any combination of EasyIO and EasyConnection
83 * boards can be specified. EasyConnection 8/32 boards can share their
84 * secondary io addresses between each other.
86 * NOTE: there is no need to put any entries in this table for PCI
87 * boards. They will be found automatically by the driver - provided
88 * PCI BIOS32 support is compiled into the kernel.
91 static struct stlconf {
95 unsigned long memaddr;
99 /*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
102 static int stl_nrbrds = ARRAY_SIZE(stl_brdconf);
104 /*****************************************************************************/
107 * Define some important driver characteristics. Device major numbers
108 * allocated as per Linux Device Registry.
110 #ifndef STL_SIOMEMMAJOR
111 #define STL_SIOMEMMAJOR 28
113 #ifndef STL_SERIALMAJOR
114 #define STL_SERIALMAJOR 24
116 #ifndef STL_CALLOUTMAJOR
117 #define STL_CALLOUTMAJOR 25
121 * Set the TX buffer size. Bigger is better, but we don't want
122 * to chew too much memory with buffers!
124 #define STL_TXBUFLOW 512
125 #define STL_TXBUFSIZE 4096
127 /*****************************************************************************/
130 * Define our local driver identity first. Set up stuff to deal with
131 * all the local structures required by a serial tty driver.
133 static char *stl_drvtitle = "Stallion Multiport Serial Driver";
134 static char *stl_drvname = "stallion";
135 static char *stl_drvversion = "5.6.0";
137 static struct tty_driver *stl_serial;
140 * Define a local default termios struct. All ports will be created
141 * with this termios initially. Basically all it defines is a raw port
142 * at 9600, 8 data bits, 1 stop bit.
144 static struct termios stl_deftermios = {
145 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
150 * Define global stats structures. Not used often, and can be
151 * re-used for each stats call.
153 static comstats_t stl_comstats;
154 static combrd_t stl_brdstats;
155 static struct stlbrd stl_dummybrd;
156 static struct stlport stl_dummyport;
159 * Define global place to put buffer overflow characters.
161 static char stl_unwanted[SC26198_RXFIFOSIZE];
163 /*****************************************************************************/
165 static struct stlbrd *stl_brds[STL_MAXBRDS];
168 * Per board state flags. Used with the state field of the board struct.
169 * Not really much here!
171 #define BRD_FOUND 0x1
174 * Define the port structure istate flags. These set of flags are
175 * modified at interrupt time - so setting and reseting them needs
176 * to be atomic. Use the bit clear/setting routines for this.
178 #define ASYI_TXBUSY 1
180 #define ASYI_DCDCHANGE 3
181 #define ASYI_TXFLOWED 4
184 * Define an array of board names as printable strings. Handy for
185 * referencing boards when printing trace and stuff.
187 static char *stl_brdnames[] = {
219 /*****************************************************************************/
222 * Define some string labels for arguments passed from the module
223 * load line. These allow for easy board definitions, and easy
224 * modification of the io, memory and irq resoucres.
226 static int stl_nargs = 0;
227 static char *board0[4];
228 static char *board1[4];
229 static char *board2[4];
230 static char *board3[4];
232 static char **stl_brdsp[] = {
240 * Define a set of common board names, and types. This is used to
241 * parse any module arguments.
248 { "easyio", BRD_EASYIO },
249 { "eio", BRD_EASYIO },
250 { "20", BRD_EASYIO },
251 { "ec8/32", BRD_ECH },
252 { "ec8/32-at", BRD_ECH },
253 { "ec8/32-isa", BRD_ECH },
255 { "echat", BRD_ECH },
257 { "ec8/32-mc", BRD_ECHMC },
258 { "ec8/32-mca", BRD_ECHMC },
259 { "echmc", BRD_ECHMC },
260 { "echmca", BRD_ECHMC },
262 { "ec8/32-pc", BRD_ECHPCI },
263 { "ec8/32-pci", BRD_ECHPCI },
264 { "26", BRD_ECHPCI },
265 { "ec8/64-pc", BRD_ECH64PCI },
266 { "ec8/64-pci", BRD_ECH64PCI },
267 { "ech-pci", BRD_ECH64PCI },
268 { "echpci", BRD_ECH64PCI },
269 { "echpc", BRD_ECH64PCI },
270 { "27", BRD_ECH64PCI },
271 { "easyio-pc", BRD_EASYIOPCI },
272 { "easyio-pci", BRD_EASYIOPCI },
273 { "eio-pci", BRD_EASYIOPCI },
274 { "eiopci", BRD_EASYIOPCI },
275 { "28", BRD_EASYIOPCI },
279 * Define the module agruments.
281 MODULE_AUTHOR("Greg Ungerer");
282 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
283 MODULE_LICENSE("GPL");
285 module_param_array(board0, charp, &stl_nargs, 0);
286 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
287 module_param_array(board1, charp, &stl_nargs, 0);
288 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
289 module_param_array(board2, charp, &stl_nargs, 0);
290 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
291 module_param_array(board3, charp, &stl_nargs, 0);
292 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
294 /*****************************************************************************/
297 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
298 * to the directly accessible io ports of these boards (not the uarts -
299 * they are in cd1400.h and sc26198.h).
301 #define EIO_8PORTRS 0x04
302 #define EIO_4PORTRS 0x05
303 #define EIO_8PORTDI 0x00
304 #define EIO_8PORTM 0x06
306 #define EIO_IDBITMASK 0x07
308 #define EIO_BRDMASK 0xf0
311 #define ID_BRD16 0x30
313 #define EIO_INTRPEND 0x08
314 #define EIO_INTEDGE 0x00
315 #define EIO_INTLEVEL 0x08
319 #define ECH_IDBITMASK 0xe0
320 #define ECH_BRDENABLE 0x08
321 #define ECH_BRDDISABLE 0x00
322 #define ECH_INTENABLE 0x01
323 #define ECH_INTDISABLE 0x00
324 #define ECH_INTLEVEL 0x02
325 #define ECH_INTEDGE 0x00
326 #define ECH_INTRPEND 0x01
327 #define ECH_BRDRESET 0x01
329 #define ECHMC_INTENABLE 0x01
330 #define ECHMC_BRDRESET 0x02
332 #define ECH_PNLSTATUS 2
333 #define ECH_PNL16PORT 0x20
334 #define ECH_PNLIDMASK 0x07
335 #define ECH_PNLXPID 0x40
336 #define ECH_PNLINTRPEND 0x80
338 #define ECH_ADDR2MASK 0x1e0
341 * Define the vector mapping bits for the programmable interrupt board
342 * hardware. These bits encode the interrupt for the board to use - it
343 * is software selectable (except the EIO-8M).
345 static unsigned char stl_vecmap[] = {
346 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
347 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
351 * Lock ordering is that you may not take stallion_lock holding
355 static spinlock_t brd_lock; /* Guard the board mapping */
356 static spinlock_t stallion_lock; /* Guard the tty driver */
359 * Set up enable and disable macros for the ECH boards. They require
360 * the secondary io address space to be activated and deactivated.
361 * This way all ECH boards can share their secondary io region.
362 * If this is an ECH-PCI board then also need to set the page pointer
363 * to point to the correct page.
365 #define BRDENABLE(brdnr,pagenr) \
366 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
367 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
368 stl_brds[(brdnr)]->ioctrl); \
369 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
370 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
372 #define BRDDISABLE(brdnr) \
373 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
374 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
375 stl_brds[(brdnr)]->ioctrl);
377 #define STL_CD1400MAXBAUD 230400
378 #define STL_SC26198MAXBAUD 460800
380 #define STL_BAUDBASE 115200
381 #define STL_CLOSEDELAY (5 * HZ / 10)
383 /*****************************************************************************/
388 * Define the Stallion PCI vendor and device IDs.
390 #ifndef PCI_VENDOR_ID_STALLION
391 #define PCI_VENDOR_ID_STALLION 0x124d
393 #ifndef PCI_DEVICE_ID_ECHPCI832
394 #define PCI_DEVICE_ID_ECHPCI832 0x0000
396 #ifndef PCI_DEVICE_ID_ECHPCI864
397 #define PCI_DEVICE_ID_ECHPCI864 0x0002
399 #ifndef PCI_DEVICE_ID_EIOPCI
400 #define PCI_DEVICE_ID_EIOPCI 0x0003
404 * Define structure to hold all Stallion PCI boards.
406 typedef struct stlpcibrd {
407 unsigned short vendid;
408 unsigned short devid;
412 static stlpcibrd_t stl_pcibrds[] = {
413 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864, BRD_ECH64PCI },
414 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI, BRD_EASYIOPCI },
415 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832, BRD_ECHPCI },
416 { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
419 static int stl_nrpcibrds = ARRAY_SIZE(stl_pcibrds);
423 /*****************************************************************************/
426 * Define macros to extract a brd/port number from a minor number.
428 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
429 #define MINOR2PORT(min) ((min) & 0x3f)
432 * Define a baud rate table that converts termios baud rate selector
433 * into the actual baud rate value. All baud rate calculations are
434 * based on the actual baud rate required.
436 static unsigned int stl_baudrates[] = {
437 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
438 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
442 * Define some handy local macros...
445 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
448 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
450 /*****************************************************************************/
453 * Declare all those functions in this driver!
456 static void stl_argbrds(void);
457 static int stl_parsebrd(struct stlconf *confp, char **argp);
459 static unsigned long stl_atol(char *str);
461 static int stl_init(void);
462 static int stl_open(struct tty_struct *tty, struct file *filp);
463 static void stl_close(struct tty_struct *tty, struct file *filp);
464 static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count);
465 static void stl_putchar(struct tty_struct *tty, unsigned char ch);
466 static void stl_flushchars(struct tty_struct *tty);
467 static int stl_writeroom(struct tty_struct *tty);
468 static int stl_charsinbuffer(struct tty_struct *tty);
469 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
470 static void stl_settermios(struct tty_struct *tty, struct termios *old);
471 static void stl_throttle(struct tty_struct *tty);
472 static void stl_unthrottle(struct tty_struct *tty);
473 static void stl_stop(struct tty_struct *tty);
474 static void stl_start(struct tty_struct *tty);
475 static void stl_flushbuffer(struct tty_struct *tty);
476 static void stl_breakctl(struct tty_struct *tty, int state);
477 static void stl_waituntilsent(struct tty_struct *tty, int timeout);
478 static void stl_sendxchar(struct tty_struct *tty, char ch);
479 static void stl_hangup(struct tty_struct *tty);
480 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
481 static int stl_portinfo(struct stlport *portp, int portnr, char *pos);
482 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data);
484 static int stl_brdinit(struct stlbrd *brdp);
485 static int stl_initports(struct stlbrd *brdp, struct stlpanel *panelp);
486 static int stl_getserial(struct stlport *portp, struct serial_struct __user *sp);
487 static int stl_setserial(struct stlport *portp, struct serial_struct __user *sp);
488 static int stl_getbrdstats(combrd_t __user *bp);
489 static int stl_getportstats(struct stlport *portp, comstats_t __user *cp);
490 static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp);
491 static int stl_getportstruct(struct stlport __user *arg);
492 static int stl_getbrdstruct(struct stlbrd __user *arg);
493 static int stl_waitcarrier(struct stlport *portp, struct file *filp);
494 static int stl_eiointr(struct stlbrd *brdp);
495 static int stl_echatintr(struct stlbrd *brdp);
496 static int stl_echmcaintr(struct stlbrd *brdp);
497 static int stl_echpciintr(struct stlbrd *brdp);
498 static int stl_echpci64intr(struct stlbrd *brdp);
499 static void stl_offintr(struct work_struct *);
500 static struct stlbrd *stl_allocbrd(void);
501 static struct stlport *stl_getport(int brdnr, int panelnr, int portnr);
503 static inline int stl_initbrds(void);
504 static inline int stl_initeio(struct stlbrd *brdp);
505 static inline int stl_initech(struct stlbrd *brdp);
506 static inline int stl_getbrdnr(void);
509 static inline int stl_findpcibrds(void);
510 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp);
514 * CD1400 uart specific handling functions.
516 static void stl_cd1400setreg(struct stlport *portp, int regnr, int value);
517 static int stl_cd1400getreg(struct stlport *portp, int regnr);
518 static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value);
519 static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
520 static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
521 static void stl_cd1400setport(struct stlport *portp, struct termios *tiosp);
522 static int stl_cd1400getsignals(struct stlport *portp);
523 static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts);
524 static void stl_cd1400ccrwait(struct stlport *portp);
525 static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx);
526 static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx);
527 static void stl_cd1400disableintrs(struct stlport *portp);
528 static void stl_cd1400sendbreak(struct stlport *portp, int len);
529 static void stl_cd1400flowctrl(struct stlport *portp, int state);
530 static void stl_cd1400sendflow(struct stlport *portp, int state);
531 static void stl_cd1400flush(struct stlport *portp);
532 static int stl_cd1400datastate(struct stlport *portp);
533 static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase);
534 static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase);
535 static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr);
536 static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr);
537 static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr);
539 static inline int stl_cd1400breakisr(struct stlport *portp, int ioaddr);
542 * SC26198 uart specific handling functions.
544 static void stl_sc26198setreg(struct stlport *portp, int regnr, int value);
545 static int stl_sc26198getreg(struct stlport *portp, int regnr);
546 static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value);
547 static int stl_sc26198getglobreg(struct stlport *portp, int regnr);
548 static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp);
549 static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
550 static void stl_sc26198setport(struct stlport *portp, struct termios *tiosp);
551 static int stl_sc26198getsignals(struct stlport *portp);
552 static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts);
553 static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx);
554 static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx);
555 static void stl_sc26198disableintrs(struct stlport *portp);
556 static void stl_sc26198sendbreak(struct stlport *portp, int len);
557 static void stl_sc26198flowctrl(struct stlport *portp, int state);
558 static void stl_sc26198sendflow(struct stlport *portp, int state);
559 static void stl_sc26198flush(struct stlport *portp);
560 static int stl_sc26198datastate(struct stlport *portp);
561 static void stl_sc26198wait(struct stlport *portp);
562 static void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty);
563 static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase);
564 static void stl_sc26198txisr(struct stlport *port);
565 static void stl_sc26198rxisr(struct stlport *port, unsigned int iack);
566 static void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch);
567 static void stl_sc26198rxbadchars(struct stlport *portp);
568 static void stl_sc26198otherisr(struct stlport *port, unsigned int iack);
570 /*****************************************************************************/
573 * Generic UART support structure.
575 typedef struct uart {
576 int (*panelinit)(struct stlbrd *brdp, struct stlpanel *panelp);
577 void (*portinit)(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp);
578 void (*setport)(struct stlport *portp, struct termios *tiosp);
579 int (*getsignals)(struct stlport *portp);
580 void (*setsignals)(struct stlport *portp, int dtr, int rts);
581 void (*enablerxtx)(struct stlport *portp, int rx, int tx);
582 void (*startrxtx)(struct stlport *portp, int rx, int tx);
583 void (*disableintrs)(struct stlport *portp);
584 void (*sendbreak)(struct stlport *portp, int len);
585 void (*flowctrl)(struct stlport *portp, int state);
586 void (*sendflow)(struct stlport *portp, int state);
587 void (*flush)(struct stlport *portp);
588 int (*datastate)(struct stlport *portp);
589 void (*intr)(struct stlpanel *panelp, unsigned int iobase);
593 * Define some macros to make calling these functions nice and clean.
595 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
596 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
597 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
598 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
599 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
600 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
601 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
602 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
603 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
604 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
605 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
606 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
607 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
609 /*****************************************************************************/
612 * CD1400 UART specific data initialization.
614 static uart_t stl_cd1400uart = {
618 stl_cd1400getsignals,
619 stl_cd1400setsignals,
620 stl_cd1400enablerxtx,
622 stl_cd1400disableintrs,
632 * Define the offsets within the register bank of a cd1400 based panel.
633 * These io address offsets are common to the EasyIO board as well.
641 #define EREG_BANKSIZE 8
643 #define CD1400_CLK 25000000
644 #define CD1400_CLK8M 20000000
647 * Define the cd1400 baud rate clocks. These are used when calculating
648 * what clock and divisor to use for the required baud rate. Also
649 * define the maximum baud rate allowed, and the default base baud.
651 static int stl_cd1400clkdivs[] = {
652 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
655 /*****************************************************************************/
658 * SC26198 UART specific data initization.
660 static uart_t stl_sc26198uart = {
661 stl_sc26198panelinit,
664 stl_sc26198getsignals,
665 stl_sc26198setsignals,
666 stl_sc26198enablerxtx,
667 stl_sc26198startrxtx,
668 stl_sc26198disableintrs,
669 stl_sc26198sendbreak,
673 stl_sc26198datastate,
678 * Define the offsets within the register bank of a sc26198 based panel.
686 #define XP_BANKSIZE 4
689 * Define the sc26198 baud rate table. Offsets within the table
690 * represent the actual baud rate selector of sc26198 registers.
692 static unsigned int sc26198_baudtable[] = {
693 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
694 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
695 230400, 460800, 921600
698 #define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
700 /*****************************************************************************/
703 * Define the driver info for a user level control device. Used mainly
704 * to get at port stats - only not using the port device itself.
706 static const struct file_operations stl_fsiomem = {
707 .owner = THIS_MODULE,
708 .ioctl = stl_memioctl,
711 /*****************************************************************************/
713 static struct class *stallion_class;
716 * Loadable module initialization stuff.
719 static int __init stallion_module_init(void)
725 /*****************************************************************************/
727 static void __exit stallion_module_exit(void)
730 struct stlpanel *panelp;
731 struct stlport *portp;
734 pr_debug("cleanup_module()\n");
736 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
740 * Free up all allocated resources used by the ports. This includes
741 * memory and interrupts. As part of this process we will also do
742 * a hangup on every open port - to try to flush out any processes
743 * hanging onto ports.
745 i = tty_unregister_driver(stl_serial);
746 put_tty_driver(stl_serial);
748 printk("STALLION: failed to un-register tty driver, "
752 for (i = 0; i < 4; i++)
753 class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
754 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
755 printk("STALLION: failed to un-register serial memory device, "
757 class_destroy(stallion_class);
759 for (i = 0; (i < stl_nrbrds); i++) {
760 if ((brdp = stl_brds[i]) == NULL)
763 free_irq(brdp->irq, brdp);
765 for (j = 0; (j < STL_MAXPANELS); j++) {
766 panelp = brdp->panels[j];
769 for (k = 0; (k < STL_PORTSPERPANEL); k++) {
770 portp = panelp->ports[k];
773 if (portp->tty != NULL)
774 stl_hangup(portp->tty);
775 kfree(portp->tx.buf);
781 release_region(brdp->ioaddr1, brdp->iosize1);
782 if (brdp->iosize2 > 0)
783 release_region(brdp->ioaddr2, brdp->iosize2);
790 module_init(stallion_module_init);
791 module_exit(stallion_module_exit);
793 /*****************************************************************************/
796 * Check for any arguments passed in on the module load command line.
799 static void stl_argbrds(void)
805 pr_debug("stl_argbrds()\n");
807 for (i = stl_nrbrds; (i < stl_nargs); i++) {
808 memset(&conf, 0, sizeof(conf));
809 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
811 if ((brdp = stl_allocbrd()) == NULL)
815 brdp->brdtype = conf.brdtype;
816 brdp->ioaddr1 = conf.ioaddr1;
817 brdp->ioaddr2 = conf.ioaddr2;
818 brdp->irq = conf.irq;
819 brdp->irqtype = conf.irqtype;
824 /*****************************************************************************/
827 * Convert an ascii string number into an unsigned long.
830 static unsigned long stl_atol(char *str)
838 if ((*sp == '0') && (*(sp+1) == 'x')) {
841 } else if (*sp == '0') {
848 for (; (*sp != 0); sp++) {
849 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
850 if ((c < 0) || (c >= base)) {
851 printk("STALLION: invalid argument %s\n", str);
855 val = (val * base) + c;
860 /*****************************************************************************/
863 * Parse the supplied argument string, into the board conf struct.
866 static int stl_parsebrd(struct stlconf *confp, char **argp)
871 pr_debug("stl_parsebrd(confp=%p,argp=%p)\n", confp, argp);
873 if ((argp[0] == NULL) || (*argp[0] == 0))
876 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
879 for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++) {
880 if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
883 if (i == ARRAY_SIZE(stl_brdstr)) {
884 printk("STALLION: unknown board name, %s?\n", argp[0]);
888 confp->brdtype = stl_brdstr[i].type;
891 if ((argp[i] != NULL) && (*argp[i] != 0))
892 confp->ioaddr1 = stl_atol(argp[i]);
894 if (confp->brdtype == BRD_ECH) {
895 if ((argp[i] != NULL) && (*argp[i] != 0))
896 confp->ioaddr2 = stl_atol(argp[i]);
899 if ((argp[i] != NULL) && (*argp[i] != 0))
900 confp->irq = stl_atol(argp[i]);
904 /*****************************************************************************/
907 * Allocate a new board structure. Fill out the basic info in it.
910 static struct stlbrd *stl_allocbrd(void)
914 brdp = kzalloc(sizeof(struct stlbrd), GFP_KERNEL);
916 printk("STALLION: failed to allocate memory (size=%Zd)\n",
917 sizeof(struct stlbrd));
921 brdp->magic = STL_BOARDMAGIC;
925 /*****************************************************************************/
927 static int stl_open(struct tty_struct *tty, struct file *filp)
929 struct stlport *portp;
931 unsigned int minordev;
932 int brdnr, panelnr, portnr, rc;
934 pr_debug("stl_open(tty=%p,filp=%p): device=%s\n", tty, filp, tty->name);
936 minordev = tty->index;
937 brdnr = MINOR2BRD(minordev);
938 if (brdnr >= stl_nrbrds)
940 brdp = stl_brds[brdnr];
943 minordev = MINOR2PORT(minordev);
944 for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
945 if (brdp->panels[panelnr] == NULL)
947 if (minordev < brdp->panels[panelnr]->nrports) {
951 minordev -= brdp->panels[panelnr]->nrports;
956 portp = brdp->panels[panelnr]->ports[portnr];
961 * On the first open of the device setup the port hardware, and
962 * initialize the per port data structure.
965 tty->driver_data = portp;
968 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
969 if (!portp->tx.buf) {
970 portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
973 portp->tx.head = portp->tx.buf;
974 portp->tx.tail = portp->tx.buf;
976 stl_setport(portp, tty->termios);
977 portp->sigs = stl_getsignals(portp);
978 stl_setsignals(portp, 1, 1);
979 stl_enablerxtx(portp, 1, 1);
980 stl_startrxtx(portp, 1, 0);
981 clear_bit(TTY_IO_ERROR, &tty->flags);
982 portp->flags |= ASYNC_INITIALIZED;
986 * Check if this port is in the middle of closing. If so then wait
987 * until it is closed then return error status, based on flag settings.
988 * The sleep here does not need interrupt protection since the wakeup
989 * for it is done with the same context.
991 if (portp->flags & ASYNC_CLOSING) {
992 interruptible_sleep_on(&portp->close_wait);
993 if (portp->flags & ASYNC_HUP_NOTIFY)
999 * Based on type of open being done check if it can overlap with any
1000 * previous opens still in effect. If we are a normal serial device
1001 * then also we might have to wait for carrier.
1003 if (!(filp->f_flags & O_NONBLOCK)) {
1004 if ((rc = stl_waitcarrier(portp, filp)) != 0)
1007 portp->flags |= ASYNC_NORMAL_ACTIVE;
1012 /*****************************************************************************/
1015 * Possibly need to wait for carrier (DCD signal) to come high. Say
1016 * maybe because if we are clocal then we don't need to wait...
1019 static int stl_waitcarrier(struct stlport *portp, struct file *filp)
1021 unsigned long flags;
1024 pr_debug("stl_waitcarrier(portp=%p,filp=%p)\n", portp, filp);
1029 spin_lock_irqsave(&stallion_lock, flags);
1031 if (portp->tty->termios->c_cflag & CLOCAL)
1034 portp->openwaitcnt++;
1035 if (! tty_hung_up_p(filp))
1039 /* Takes brd_lock internally */
1040 stl_setsignals(portp, 1, 1);
1041 if (tty_hung_up_p(filp) ||
1042 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1043 if (portp->flags & ASYNC_HUP_NOTIFY)
1049 if (((portp->flags & ASYNC_CLOSING) == 0) &&
1050 (doclocal || (portp->sigs & TIOCM_CD))) {
1053 if (signal_pending(current)) {
1058 interruptible_sleep_on(&portp->open_wait);
1061 if (! tty_hung_up_p(filp))
1063 portp->openwaitcnt--;
1064 spin_unlock_irqrestore(&stallion_lock, flags);
1069 /*****************************************************************************/
1071 static void stl_close(struct tty_struct *tty, struct file *filp)
1073 struct stlport *portp;
1074 unsigned long flags;
1076 pr_debug("stl_close(tty=%p,filp=%p)\n", tty, filp);
1078 portp = tty->driver_data;
1082 spin_lock_irqsave(&stallion_lock, flags);
1083 if (tty_hung_up_p(filp)) {
1084 spin_unlock_irqrestore(&stallion_lock, flags);
1087 if ((tty->count == 1) && (portp->refcount != 1))
1088 portp->refcount = 1;
1089 if (portp->refcount-- > 1) {
1090 spin_unlock_irqrestore(&stallion_lock, flags);
1094 portp->refcount = 0;
1095 portp->flags |= ASYNC_CLOSING;
1098 * May want to wait for any data to drain before closing. The BUSY
1099 * flag keeps track of whether we are still sending or not - it is
1100 * very accurate for the cd1400, not quite so for the sc26198.
1101 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1105 spin_unlock_irqrestore(&stallion_lock, flags);
1107 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1108 tty_wait_until_sent(tty, portp->closing_wait);
1109 stl_waituntilsent(tty, (HZ / 2));
1112 spin_lock_irqsave(&stallion_lock, flags);
1113 portp->flags &= ~ASYNC_INITIALIZED;
1114 spin_unlock_irqrestore(&stallion_lock, flags);
1116 stl_disableintrs(portp);
1117 if (tty->termios->c_cflag & HUPCL)
1118 stl_setsignals(portp, 0, 0);
1119 stl_enablerxtx(portp, 0, 0);
1120 stl_flushbuffer(tty);
1122 if (portp->tx.buf != NULL) {
1123 kfree(portp->tx.buf);
1124 portp->tx.buf = NULL;
1125 portp->tx.head = NULL;
1126 portp->tx.tail = NULL;
1128 set_bit(TTY_IO_ERROR, &tty->flags);
1129 tty_ldisc_flush(tty);
1134 if (portp->openwaitcnt) {
1135 if (portp->close_delay)
1136 msleep_interruptible(jiffies_to_msecs(portp->close_delay));
1137 wake_up_interruptible(&portp->open_wait);
1140 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1141 wake_up_interruptible(&portp->close_wait);
1144 /*****************************************************************************/
1147 * Write routine. Take data and stuff it in to the TX ring queue.
1148 * If transmit interrupts are not running then start them.
1151 static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
1153 struct stlport *portp;
1154 unsigned int len, stlen;
1155 unsigned char *chbuf;
1158 pr_debug("stl_write(tty=%p,buf=%p,count=%d)\n", tty, buf, count);
1160 portp = tty->driver_data;
1163 if (portp->tx.buf == NULL)
1167 * If copying direct from user space we must cater for page faults,
1168 * causing us to "sleep" here for a while. To handle this copy in all
1169 * the data we need now, into a local buffer. Then when we got it all
1170 * copy it into the TX buffer.
1172 chbuf = (unsigned char *) buf;
1174 head = portp->tx.head;
1175 tail = portp->tx.tail;
1177 len = STL_TXBUFSIZE - (head - tail) - 1;
1178 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
1180 len = tail - head - 1;
1184 len = MIN(len, count);
1187 stlen = MIN(len, stlen);
1188 memcpy(head, chbuf, stlen);
1193 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
1194 head = portp->tx.buf;
1195 stlen = tail - head;
1198 portp->tx.head = head;
1200 clear_bit(ASYI_TXLOW, &portp->istate);
1201 stl_startrxtx(portp, -1, 1);
1206 /*****************************************************************************/
1208 static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1210 struct stlport *portp;
1214 pr_debug("stl_putchar(tty=%p,ch=%x)\n", tty, ch);
1218 portp = tty->driver_data;
1221 if (portp->tx.buf == NULL)
1224 head = portp->tx.head;
1225 tail = portp->tx.tail;
1227 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
1232 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
1233 head = portp->tx.buf;
1235 portp->tx.head = head;
1238 /*****************************************************************************/
1241 * If there are any characters in the buffer then make sure that TX
1242 * interrupts are on and get'em out. Normally used after the putchar
1243 * routine has been called.
1246 static void stl_flushchars(struct tty_struct *tty)
1248 struct stlport *portp;
1250 pr_debug("stl_flushchars(tty=%p)\n", tty);
1254 portp = tty->driver_data;
1257 if (portp->tx.buf == NULL)
1260 stl_startrxtx(portp, -1, 1);
1263 /*****************************************************************************/
1265 static int stl_writeroom(struct tty_struct *tty)
1267 struct stlport *portp;
1270 pr_debug("stl_writeroom(tty=%p)\n", tty);
1274 portp = tty->driver_data;
1277 if (portp->tx.buf == NULL)
1280 head = portp->tx.head;
1281 tail = portp->tx.tail;
1282 return ((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
1285 /*****************************************************************************/
1288 * Return number of chars in the TX buffer. Normally we would just
1289 * calculate the number of chars in the buffer and return that, but if
1290 * the buffer is empty and TX interrupts are still on then we return
1291 * that the buffer still has 1 char in it. This way whoever called us
1292 * will not think that ALL chars have drained - since the UART still
1293 * must have some chars in it (we are busy after all).
1296 static int stl_charsinbuffer(struct tty_struct *tty)
1298 struct stlport *portp;
1302 pr_debug("stl_charsinbuffer(tty=%p)\n", tty);
1306 portp = tty->driver_data;
1309 if (portp->tx.buf == NULL)
1312 head = portp->tx.head;
1313 tail = portp->tx.tail;
1314 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1315 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1320 /*****************************************************************************/
1323 * Generate the serial struct info.
1326 static int stl_getserial(struct stlport *portp, struct serial_struct __user *sp)
1328 struct serial_struct sio;
1329 struct stlbrd *brdp;
1331 pr_debug("stl_getserial(portp=%p,sp=%p)\n", portp, sp);
1333 memset(&sio, 0, sizeof(struct serial_struct));
1334 sio.line = portp->portnr;
1335 sio.port = portp->ioaddr;
1336 sio.flags = portp->flags;
1337 sio.baud_base = portp->baud_base;
1338 sio.close_delay = portp->close_delay;
1339 sio.closing_wait = portp->closing_wait;
1340 sio.custom_divisor = portp->custom_divisor;
1342 if (portp->uartp == &stl_cd1400uart) {
1343 sio.type = PORT_CIRRUS;
1344 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1346 sio.type = PORT_UNKNOWN;
1347 sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1350 brdp = stl_brds[portp->brdnr];
1352 sio.irq = brdp->irq;
1354 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
1357 /*****************************************************************************/
1360 * Set port according to the serial struct info.
1361 * At this point we do not do any auto-configure stuff, so we will
1362 * just quietly ignore any requests to change irq, etc.
1365 static int stl_setserial(struct stlport *portp, struct serial_struct __user *sp)
1367 struct serial_struct sio;
1369 pr_debug("stl_setserial(portp=%p,sp=%p)\n", portp, sp);
1371 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1373 if (!capable(CAP_SYS_ADMIN)) {
1374 if ((sio.baud_base != portp->baud_base) ||
1375 (sio.close_delay != portp->close_delay) ||
1376 ((sio.flags & ~ASYNC_USR_MASK) !=
1377 (portp->flags & ~ASYNC_USR_MASK)))
1381 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1382 (sio.flags & ASYNC_USR_MASK);
1383 portp->baud_base = sio.baud_base;
1384 portp->close_delay = sio.close_delay;
1385 portp->closing_wait = sio.closing_wait;
1386 portp->custom_divisor = sio.custom_divisor;
1387 stl_setport(portp, portp->tty->termios);
1391 /*****************************************************************************/
1393 static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1395 struct stlport *portp;
1399 portp = tty->driver_data;
1402 if (tty->flags & (1 << TTY_IO_ERROR))
1405 return stl_getsignals(portp);
1408 static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1409 unsigned int set, unsigned int clear)
1411 struct stlport *portp;
1412 int rts = -1, dtr = -1;
1416 portp = tty->driver_data;
1419 if (tty->flags & (1 << TTY_IO_ERROR))
1422 if (set & TIOCM_RTS)
1424 if (set & TIOCM_DTR)
1426 if (clear & TIOCM_RTS)
1428 if (clear & TIOCM_DTR)
1431 stl_setsignals(portp, dtr, rts);
1435 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1437 struct stlport *portp;
1440 void __user *argp = (void __user *)arg;
1442 pr_debug("stl_ioctl(tty=%p,file=%p,cmd=%x,arg=%lx)\n", tty, file, cmd,
1447 portp = tty->driver_data;
1451 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1452 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1453 if (tty->flags & (1 << TTY_IO_ERROR))
1461 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1462 (unsigned __user *) argp);
1465 if (get_user(ival, (unsigned int __user *) arg))
1467 tty->termios->c_cflag =
1468 (tty->termios->c_cflag & ~CLOCAL) |
1469 (ival ? CLOCAL : 0);
1472 rc = stl_getserial(portp, argp);
1475 rc = stl_setserial(portp, argp);
1477 case COM_GETPORTSTATS:
1478 rc = stl_getportstats(portp, argp);
1480 case COM_CLRPORTSTATS:
1481 rc = stl_clrportstats(portp, argp);
1487 case TIOCSERGSTRUCT:
1488 case TIOCSERGETMULTI:
1489 case TIOCSERSETMULTI:
1498 /*****************************************************************************/
1500 static void stl_settermios(struct tty_struct *tty, struct termios *old)
1502 struct stlport *portp;
1503 struct termios *tiosp;
1505 pr_debug("stl_settermios(tty=%p,old=%p)\n", tty, old);
1509 portp = tty->driver_data;
1513 tiosp = tty->termios;
1514 if ((tiosp->c_cflag == old->c_cflag) &&
1515 (tiosp->c_iflag == old->c_iflag))
1518 stl_setport(portp, tiosp);
1519 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1521 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1522 tty->hw_stopped = 0;
1525 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1526 wake_up_interruptible(&portp->open_wait);
1529 /*****************************************************************************/
1532 * Attempt to flow control who ever is sending us data. Based on termios
1533 * settings use software or/and hardware flow control.
1536 static void stl_throttle(struct tty_struct *tty)
1538 struct stlport *portp;
1540 pr_debug("stl_throttle(tty=%p)\n", tty);
1544 portp = tty->driver_data;
1547 stl_flowctrl(portp, 0);
1550 /*****************************************************************************/
1553 * Unflow control the device sending us data...
1556 static void stl_unthrottle(struct tty_struct *tty)
1558 struct stlport *portp;
1560 pr_debug("stl_unthrottle(tty=%p)\n", tty);
1564 portp = tty->driver_data;
1567 stl_flowctrl(portp, 1);
1570 /*****************************************************************************/
1573 * Stop the transmitter. Basically to do this we will just turn TX
1577 static void stl_stop(struct tty_struct *tty)
1579 struct stlport *portp;
1581 pr_debug("stl_stop(tty=%p)\n", tty);
1585 portp = tty->driver_data;
1588 stl_startrxtx(portp, -1, 0);
1591 /*****************************************************************************/
1594 * Start the transmitter again. Just turn TX interrupts back on.
1597 static void stl_start(struct tty_struct *tty)
1599 struct stlport *portp;
1601 pr_debug("stl_start(tty=%p)\n", tty);
1605 portp = tty->driver_data;
1608 stl_startrxtx(portp, -1, 1);
1611 /*****************************************************************************/
1614 * Hangup this port. This is pretty much like closing the port, only
1615 * a little more brutal. No waiting for data to drain. Shutdown the
1616 * port and maybe drop signals.
1619 static void stl_hangup(struct tty_struct *tty)
1621 struct stlport *portp;
1623 pr_debug("stl_hangup(tty=%p)\n", tty);
1627 portp = tty->driver_data;
1631 portp->flags &= ~ASYNC_INITIALIZED;
1632 stl_disableintrs(portp);
1633 if (tty->termios->c_cflag & HUPCL)
1634 stl_setsignals(portp, 0, 0);
1635 stl_enablerxtx(portp, 0, 0);
1636 stl_flushbuffer(tty);
1638 set_bit(TTY_IO_ERROR, &tty->flags);
1639 if (portp->tx.buf != NULL) {
1640 kfree(portp->tx.buf);
1641 portp->tx.buf = NULL;
1642 portp->tx.head = NULL;
1643 portp->tx.tail = NULL;
1646 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1647 portp->refcount = 0;
1648 wake_up_interruptible(&portp->open_wait);
1651 /*****************************************************************************/
1653 static void stl_flushbuffer(struct tty_struct *tty)
1655 struct stlport *portp;
1657 pr_debug("stl_flushbuffer(tty=%p)\n", tty);
1661 portp = tty->driver_data;
1669 /*****************************************************************************/
1671 static void stl_breakctl(struct tty_struct *tty, int state)
1673 struct stlport *portp;
1675 pr_debug("stl_breakctl(tty=%p,state=%d)\n", tty, state);
1679 portp = tty->driver_data;
1683 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1686 /*****************************************************************************/
1688 static void stl_waituntilsent(struct tty_struct *tty, int timeout)
1690 struct stlport *portp;
1693 pr_debug("stl_waituntilsent(tty=%p,timeout=%d)\n", tty, timeout);
1697 portp = tty->driver_data;
1703 tend = jiffies + timeout;
1705 while (stl_datastate(portp)) {
1706 if (signal_pending(current))
1708 msleep_interruptible(20);
1709 if (time_after_eq(jiffies, tend))
1714 /*****************************************************************************/
1716 static void stl_sendxchar(struct tty_struct *tty, char ch)
1718 struct stlport *portp;
1720 pr_debug("stl_sendxchar(tty=%p,ch=%x)\n", tty, ch);
1724 portp = tty->driver_data;
1728 if (ch == STOP_CHAR(tty))
1729 stl_sendflow(portp, 0);
1730 else if (ch == START_CHAR(tty))
1731 stl_sendflow(portp, 1);
1733 stl_putchar(tty, ch);
1736 /*****************************************************************************/
1741 * Format info for a specified port. The line is deliberately limited
1742 * to 80 characters. (If it is too long it will be truncated, if too
1743 * short then padded with spaces).
1746 static int stl_portinfo(struct stlport *portp, int portnr, char *pos)
1752 sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
1753 portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
1754 (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
1756 if (portp->stats.rxframing)
1757 sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
1758 if (portp->stats.rxparity)
1759 sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
1760 if (portp->stats.rxbreaks)
1761 sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
1762 if (portp->stats.rxoverrun)
1763 sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
1765 sigs = stl_getsignals(portp);
1766 cnt = sprintf(sp, "%s%s%s%s%s ",
1767 (sigs & TIOCM_RTS) ? "|RTS" : "",
1768 (sigs & TIOCM_CTS) ? "|CTS" : "",
1769 (sigs & TIOCM_DTR) ? "|DTR" : "",
1770 (sigs & TIOCM_CD) ? "|DCD" : "",
1771 (sigs & TIOCM_DSR) ? "|DSR" : "");
1775 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
1778 pos[(MAXLINE - 2)] = '+';
1779 pos[(MAXLINE - 1)] = '\n';
1784 /*****************************************************************************/
1787 * Port info, read from the /proc file system.
1790 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
1792 struct stlbrd *brdp;
1793 struct stlpanel *panelp;
1794 struct stlport *portp;
1795 int brdnr, panelnr, portnr, totalport;
1799 pr_debug("stl_readproc(page=%p,start=%p,off=%lx,count=%d,eof=%p,"
1800 "data=%p\n", page, start, off, count, eof, data);
1807 pos += sprintf(pos, "%s: version %s", stl_drvtitle,
1809 while (pos < (page + MAXLINE - 1))
1816 * We scan through for each board, panel and port. The offset is
1817 * calculated on the fly, and irrelevant ports are skipped.
1819 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1820 brdp = stl_brds[brdnr];
1823 if (brdp->state == 0)
1826 maxoff = curoff + (brdp->nrports * MAXLINE);
1827 if (off >= maxoff) {
1832 totalport = brdnr * STL_MAXPORTS;
1833 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1834 panelp = brdp->panels[panelnr];
1838 maxoff = curoff + (panelp->nrports * MAXLINE);
1839 if (off >= maxoff) {
1841 totalport += panelp->nrports;
1845 for (portnr = 0; (portnr < panelp->nrports); portnr++,
1847 portp = panelp->ports[portnr];
1850 if (off >= (curoff += MAXLINE))
1852 if ((pos - page + MAXLINE) > count)
1854 pos += stl_portinfo(portp, totalport, pos);
1863 return (pos - page);
1866 /*****************************************************************************/
1869 * All board interrupts are vectored through here first. This code then
1870 * calls off to the approrpriate board interrupt handlers.
1873 static irqreturn_t stl_intr(int irq, void *dev_id)
1875 struct stlbrd *brdp = dev_id;
1877 pr_debug("stl_intr(brdp=%p,irq=%d)\n", brdp, irq);
1879 return IRQ_RETVAL((* brdp->isr)(brdp));
1882 /*****************************************************************************/
1885 * Interrupt service routine for EasyIO board types.
1888 static int stl_eiointr(struct stlbrd *brdp)
1890 struct stlpanel *panelp;
1891 unsigned int iobase;
1894 spin_lock(&brd_lock);
1895 panelp = brdp->panels[0];
1896 iobase = panelp->iobase;
1897 while (inb(brdp->iostatus) & EIO_INTRPEND) {
1899 (* panelp->isr)(panelp, iobase);
1901 spin_unlock(&brd_lock);
1905 /*****************************************************************************/
1908 * Interrupt service routine for ECH-AT board types.
1911 static int stl_echatintr(struct stlbrd *brdp)
1913 struct stlpanel *panelp;
1914 unsigned int ioaddr;
1918 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
1920 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1922 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1923 ioaddr = brdp->bnkstataddr[bnknr];
1924 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1925 panelp = brdp->bnk2panel[bnknr];
1926 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1931 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
1936 /*****************************************************************************/
1939 * Interrupt service routine for ECH-MCA board types.
1942 static int stl_echmcaintr(struct stlbrd *brdp)
1944 struct stlpanel *panelp;
1945 unsigned int ioaddr;
1949 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1951 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1952 ioaddr = brdp->bnkstataddr[bnknr];
1953 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1954 panelp = brdp->bnk2panel[bnknr];
1955 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1962 /*****************************************************************************/
1965 * Interrupt service routine for ECH-PCI board types.
1968 static int stl_echpciintr(struct stlbrd *brdp)
1970 struct stlpanel *panelp;
1971 unsigned int ioaddr;
1977 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1978 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
1979 ioaddr = brdp->bnkstataddr[bnknr];
1980 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1981 panelp = brdp->bnk2panel[bnknr];
1982 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1993 /*****************************************************************************/
1996 * Interrupt service routine for ECH-8/64-PCI board types.
1999 static int stl_echpci64intr(struct stlbrd *brdp)
2001 struct stlpanel *panelp;
2002 unsigned int ioaddr;
2006 while (inb(brdp->ioctrl) & 0x1) {
2008 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2009 ioaddr = brdp->bnkstataddr[bnknr];
2010 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2011 panelp = brdp->bnk2panel[bnknr];
2012 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2020 /*****************************************************************************/
2023 * Service an off-level request for some channel.
2025 static void stl_offintr(struct work_struct *work)
2027 struct stlport *portp = container_of(work, struct stlport, tqueue);
2028 struct tty_struct *tty;
2029 unsigned int oldsigs;
2031 pr_debug("stl_offintr(portp=%p)\n", portp);
2041 if (test_bit(ASYI_TXLOW, &portp->istate)) {
2044 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
2045 clear_bit(ASYI_DCDCHANGE, &portp->istate);
2046 oldsigs = portp->sigs;
2047 portp->sigs = stl_getsignals(portp);
2048 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
2049 wake_up_interruptible(&portp->open_wait);
2050 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
2051 if (portp->flags & ASYNC_CHECK_CD)
2052 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2058 /*****************************************************************************/
2061 * Initialize all the ports on a panel.
2064 static int __init stl_initports(struct stlbrd *brdp, struct stlpanel *panelp)
2066 struct stlport *portp;
2069 pr_debug("stl_initports(brdp=%p,panelp=%p)\n", brdp, panelp);
2071 chipmask = stl_panelinit(brdp, panelp);
2074 * All UART's are initialized (if found!). Now go through and setup
2075 * each ports data structures.
2077 for (i = 0; (i < panelp->nrports); i++) {
2078 portp = kzalloc(sizeof(struct stlport), GFP_KERNEL);
2080 printk("STALLION: failed to allocate memory "
2081 "(size=%Zd)\n", sizeof(struct stlport));
2085 portp->magic = STL_PORTMAGIC;
2087 portp->brdnr = panelp->brdnr;
2088 portp->panelnr = panelp->panelnr;
2089 portp->uartp = panelp->uartp;
2090 portp->clk = brdp->clk;
2091 portp->baud_base = STL_BAUDBASE;
2092 portp->close_delay = STL_CLOSEDELAY;
2093 portp->closing_wait = 30 * HZ;
2094 INIT_WORK(&portp->tqueue, stl_offintr);
2095 init_waitqueue_head(&portp->open_wait);
2096 init_waitqueue_head(&portp->close_wait);
2097 portp->stats.brd = portp->brdnr;
2098 portp->stats.panel = portp->panelnr;
2099 portp->stats.port = portp->portnr;
2100 panelp->ports[i] = portp;
2101 stl_portinit(brdp, panelp, portp);
2107 /*****************************************************************************/
2110 * Try to find and initialize an EasyIO board.
2113 static inline int stl_initeio(struct stlbrd *brdp)
2115 struct stlpanel *panelp;
2116 unsigned int status;
2120 pr_debug("stl_initeio(brdp=%p)\n", brdp);
2122 brdp->ioctrl = brdp->ioaddr1 + 1;
2123 brdp->iostatus = brdp->ioaddr1 + 2;
2125 status = inb(brdp->iostatus);
2126 if ((status & EIO_IDBITMASK) == EIO_MK3)
2130 * Handle board specific stuff now. The real difference is PCI
2133 if (brdp->brdtype == BRD_EASYIOPCI) {
2134 brdp->iosize1 = 0x80;
2135 brdp->iosize2 = 0x80;
2136 name = "serial(EIO-PCI)";
2137 outb(0x41, (brdp->ioaddr2 + 0x4c));
2140 name = "serial(EIO)";
2141 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2142 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2143 printk("STALLION: invalid irq=%d for brd=%d\n",
2144 brdp->irq, brdp->brdnr);
2147 outb((stl_vecmap[brdp->irq] | EIO_0WS |
2148 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
2152 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2153 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2154 "%x conflicts with another device\n", brdp->brdnr,
2159 if (brdp->iosize2 > 0)
2160 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2161 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2162 "address %x conflicts with another device\n",
2163 brdp->brdnr, brdp->ioaddr2);
2164 printk(KERN_WARNING "STALLION: Warning, also "
2165 "releasing board %d I/O address %x \n",
2166 brdp->brdnr, brdp->ioaddr1);
2167 release_region(brdp->ioaddr1, brdp->iosize1);
2172 * Everything looks OK, so let's go ahead and probe for the hardware.
2174 brdp->clk = CD1400_CLK;
2175 brdp->isr = stl_eiointr;
2177 switch (status & EIO_IDBITMASK) {
2179 brdp->clk = CD1400_CLK8M;
2189 switch (status & EIO_BRDMASK) {
2208 * We have verified that the board is actually present, so now we
2209 * can complete the setup.
2212 panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
2214 printk(KERN_WARNING "STALLION: failed to allocate memory "
2215 "(size=%Zd)\n", sizeof(struct stlpanel));
2219 panelp->magic = STL_PANELMAGIC;
2220 panelp->brdnr = brdp->brdnr;
2221 panelp->panelnr = 0;
2222 panelp->nrports = brdp->nrports;
2223 panelp->iobase = brdp->ioaddr1;
2224 panelp->hwid = status;
2225 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2226 panelp->uartp = &stl_sc26198uart;
2227 panelp->isr = stl_sc26198intr;
2229 panelp->uartp = &stl_cd1400uart;
2230 panelp->isr = stl_cd1400eiointr;
2233 brdp->panels[0] = panelp;
2235 brdp->state |= BRD_FOUND;
2236 brdp->hwid = status;
2237 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
2238 printk("STALLION: failed to register interrupt "
2239 "routine for %s irq=%d\n", name, brdp->irq);
2247 /*****************************************************************************/
2250 * Try to find an ECH board and initialize it. This code is capable of
2251 * dealing with all types of ECH board.
2254 static inline int stl_initech(struct stlbrd *brdp)
2256 struct stlpanel *panelp;
2257 unsigned int status, nxtid, ioaddr, conflict;
2258 int panelnr, banknr, i;
2261 pr_debug("stl_initech(brdp=%p)\n", brdp);
2267 * Set up the initial board register contents for boards. This varies a
2268 * bit between the different board types. So we need to handle each
2269 * separately. Also do a check that the supplied IRQ is good.
2271 switch (brdp->brdtype) {
2274 brdp->isr = stl_echatintr;
2275 brdp->ioctrl = brdp->ioaddr1 + 1;
2276 brdp->iostatus = brdp->ioaddr1 + 1;
2277 status = inb(brdp->iostatus);
2278 if ((status & ECH_IDBITMASK) != ECH_ID)
2280 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2281 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2282 printk("STALLION: invalid irq=%d for brd=%d\n",
2283 brdp->irq, brdp->brdnr);
2286 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2287 status |= (stl_vecmap[brdp->irq] << 1);
2288 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2289 brdp->ioctrlval = ECH_INTENABLE |
2290 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2291 for (i = 0; (i < 10); i++)
2292 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2295 name = "serial(EC8/32)";
2296 outb(status, brdp->ioaddr1);
2300 brdp->isr = stl_echmcaintr;
2301 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2302 brdp->iostatus = brdp->ioctrl;
2303 status = inb(brdp->iostatus);
2304 if ((status & ECH_IDBITMASK) != ECH_ID)
2306 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2307 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2308 printk("STALLION: invalid irq=%d for brd=%d\n",
2309 brdp->irq, brdp->brdnr);
2312 outb(ECHMC_BRDRESET, brdp->ioctrl);
2313 outb(ECHMC_INTENABLE, brdp->ioctrl);
2315 name = "serial(EC8/32-MC)";
2319 brdp->isr = stl_echpciintr;
2320 brdp->ioctrl = brdp->ioaddr1 + 2;
2323 name = "serial(EC8/32-PCI)";
2327 brdp->isr = stl_echpci64intr;
2328 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2329 outb(0x43, (brdp->ioaddr1 + 0x4c));
2330 brdp->iosize1 = 0x80;
2331 brdp->iosize2 = 0x80;
2332 name = "serial(EC8/64-PCI)";
2336 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
2342 * Check boards for possible IO address conflicts and return fail status
2343 * if an IO conflict found.
2345 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2346 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2347 "%x conflicts with another device\n", brdp->brdnr,
2352 if (brdp->iosize2 > 0)
2353 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2354 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2355 "address %x conflicts with another device\n",
2356 brdp->brdnr, brdp->ioaddr2);
2357 printk(KERN_WARNING "STALLION: Warning, also "
2358 "releasing board %d I/O address %x \n",
2359 brdp->brdnr, brdp->ioaddr1);
2360 release_region(brdp->ioaddr1, brdp->iosize1);
2365 * Scan through the secondary io address space looking for panels.
2366 * As we find'em allocate and initialize panel structures for each.
2368 brdp->clk = CD1400_CLK;
2369 brdp->hwid = status;
2371 ioaddr = brdp->ioaddr2;
2376 for (i = 0; (i < STL_MAXPANELS); i++) {
2377 if (brdp->brdtype == BRD_ECHPCI) {
2378 outb(nxtid, brdp->ioctrl);
2379 ioaddr = brdp->ioaddr2;
2381 status = inb(ioaddr + ECH_PNLSTATUS);
2382 if ((status & ECH_PNLIDMASK) != nxtid)
2384 panelp = kzalloc(sizeof(struct stlpanel), GFP_KERNEL);
2386 printk("STALLION: failed to allocate memory "
2387 "(size=%Zd)\n", sizeof(struct stlpanel));
2390 panelp->magic = STL_PANELMAGIC;
2391 panelp->brdnr = brdp->brdnr;
2392 panelp->panelnr = panelnr;
2393 panelp->iobase = ioaddr;
2394 panelp->pagenr = nxtid;
2395 panelp->hwid = status;
2396 brdp->bnk2panel[banknr] = panelp;
2397 brdp->bnkpageaddr[banknr] = nxtid;
2398 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2400 if (status & ECH_PNLXPID) {
2401 panelp->uartp = &stl_sc26198uart;
2402 panelp->isr = stl_sc26198intr;
2403 if (status & ECH_PNL16PORT) {
2404 panelp->nrports = 16;
2405 brdp->bnk2panel[banknr] = panelp;
2406 brdp->bnkpageaddr[banknr] = nxtid;
2407 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2410 panelp->nrports = 8;
2413 panelp->uartp = &stl_cd1400uart;
2414 panelp->isr = stl_cd1400echintr;
2415 if (status & ECH_PNL16PORT) {
2416 panelp->nrports = 16;
2417 panelp->ackmask = 0x80;
2418 if (brdp->brdtype != BRD_ECHPCI)
2419 ioaddr += EREG_BANKSIZE;
2420 brdp->bnk2panel[banknr] = panelp;
2421 brdp->bnkpageaddr[banknr] = ++nxtid;
2422 brdp->bnkstataddr[banknr++] = ioaddr +
2425 panelp->nrports = 8;
2426 panelp->ackmask = 0xc0;
2431 ioaddr += EREG_BANKSIZE;
2432 brdp->nrports += panelp->nrports;
2433 brdp->panels[panelnr++] = panelp;
2434 if ((brdp->brdtype != BRD_ECHPCI) &&
2435 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
2439 brdp->nrpanels = panelnr;
2440 brdp->nrbnks = banknr;
2441 if (brdp->brdtype == BRD_ECH)
2442 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2444 brdp->state |= BRD_FOUND;
2445 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
2446 printk("STALLION: failed to register interrupt "
2447 "routine for %s irq=%d\n", name, brdp->irq);
2456 /*****************************************************************************/
2459 * Initialize and configure the specified board.
2460 * Scan through all the boards in the configuration and see what we
2461 * can find. Handle EIO and the ECH boards a little differently here
2462 * since the initial search and setup is very different.
2465 static int __init stl_brdinit(struct stlbrd *brdp)
2469 pr_debug("stl_brdinit(brdp=%p)\n", brdp);
2471 switch (brdp->brdtype) {
2483 printk("STALLION: board=%d is unknown board type=%d\n",
2484 brdp->brdnr, brdp->brdtype);
2488 stl_brds[brdp->brdnr] = brdp;
2489 if ((brdp->state & BRD_FOUND) == 0) {
2490 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2491 stl_brdnames[brdp->brdtype], brdp->brdnr,
2492 brdp->ioaddr1, brdp->irq);
2496 for (i = 0; (i < STL_MAXPANELS); i++)
2497 if (brdp->panels[i] != NULL)
2498 stl_initports(brdp, brdp->panels[i]);
2500 printk("STALLION: %s found, board=%d io=%x irq=%d "
2501 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2502 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2507 /*****************************************************************************/
2510 * Find the next available board number that is free.
2513 static inline int stl_getbrdnr(void)
2517 for (i = 0; (i < STL_MAXBRDS); i++) {
2518 if (stl_brds[i] == NULL) {
2519 if (i >= stl_nrbrds)
2527 /*****************************************************************************/
2532 * We have a Stallion board. Allocate a board structure and
2533 * initialize it. Read its IO and IRQ resources from PCI
2534 * configuration space.
2537 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
2539 struct stlbrd *brdp;
2541 pr_debug("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
2542 devp->bus->number, devp->devfn);
2544 if (pci_enable_device(devp))
2546 if ((brdp = stl_allocbrd()) == NULL)
2548 if ((brdp->brdnr = stl_getbrdnr()) < 0) {
2549 printk("STALLION: too many boards found, "
2550 "maximum supported %d\n", STL_MAXBRDS);
2553 brdp->brdtype = brdtype;
2556 * Different Stallion boards use the BAR registers in different ways,
2557 * so set up io addresses based on board type.
2559 pr_debug("%s(%d): BAR[]=%Lx,%Lx,%Lx,%Lx IRQ=%x\n", __FILE__, __LINE__,
2560 pci_resource_start(devp, 0), pci_resource_start(devp, 1),
2561 pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
2564 * We have all resources from the board, so let's setup the actual
2565 * board structure now.
2569 brdp->ioaddr2 = pci_resource_start(devp, 0);
2570 brdp->ioaddr1 = pci_resource_start(devp, 1);
2573 brdp->ioaddr2 = pci_resource_start(devp, 2);
2574 brdp->ioaddr1 = pci_resource_start(devp, 1);
2577 brdp->ioaddr1 = pci_resource_start(devp, 2);
2578 brdp->ioaddr2 = pci_resource_start(devp, 1);
2581 printk("STALLION: unknown PCI board type=%d\n", brdtype);
2585 brdp->irq = devp->irq;
2591 /*****************************************************************************/
2594 * Find all Stallion PCI boards that might be installed. Initialize each
2595 * one as it is found.
2599 static inline int stl_findpcibrds(void)
2601 struct pci_dev *dev = NULL;
2604 pr_debug("stl_findpcibrds()\n");
2606 for (i = 0; (i < stl_nrpcibrds); i++)
2607 while ((dev = pci_find_device(stl_pcibrds[i].vendid,
2608 stl_pcibrds[i].devid, dev))) {
2611 * Found a device on the PCI bus that has our vendor and
2612 * device ID. Need to check now that it is really us.
2614 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2617 rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
2627 /*****************************************************************************/
2630 * Scan through all the boards in the configuration and see what we
2631 * can find. Handle EIO and the ECH boards a little differently here
2632 * since the initial search and setup is too different.
2635 static inline int stl_initbrds(void)
2637 struct stlbrd *brdp;
2638 struct stlconf *confp;
2641 pr_debug("stl_initbrds()\n");
2643 if (stl_nrbrds > STL_MAXBRDS) {
2644 printk("STALLION: too many boards in configuration table, "
2645 "truncating to %d\n", STL_MAXBRDS);
2646 stl_nrbrds = STL_MAXBRDS;
2650 * Firstly scan the list of static boards configured. Allocate
2651 * resources and initialize the boards as found.
2653 for (i = 0; (i < stl_nrbrds); i++) {
2654 confp = &stl_brdconf[i];
2655 stl_parsebrd(confp, stl_brdsp[i]);
2656 if ((brdp = stl_allocbrd()) == NULL)
2659 brdp->brdtype = confp->brdtype;
2660 brdp->ioaddr1 = confp->ioaddr1;
2661 brdp->ioaddr2 = confp->ioaddr2;
2662 brdp->irq = confp->irq;
2663 brdp->irqtype = confp->irqtype;
2668 * Find any dynamically supported boards. That is via module load
2669 * line options or auto-detected on the PCI bus.
2679 /*****************************************************************************/
2682 * Return the board stats structure to user app.
2685 static int stl_getbrdstats(combrd_t __user *bp)
2687 struct stlbrd *brdp;
2688 struct stlpanel *panelp;
2691 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2693 if (stl_brdstats.brd >= STL_MAXBRDS)
2695 brdp = stl_brds[stl_brdstats.brd];
2699 memset(&stl_brdstats, 0, sizeof(combrd_t));
2700 stl_brdstats.brd = brdp->brdnr;
2701 stl_brdstats.type = brdp->brdtype;
2702 stl_brdstats.hwid = brdp->hwid;
2703 stl_brdstats.state = brdp->state;
2704 stl_brdstats.ioaddr = brdp->ioaddr1;
2705 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2706 stl_brdstats.irq = brdp->irq;
2707 stl_brdstats.nrpanels = brdp->nrpanels;
2708 stl_brdstats.nrports = brdp->nrports;
2709 for (i = 0; (i < brdp->nrpanels); i++) {
2710 panelp = brdp->panels[i];
2711 stl_brdstats.panels[i].panel = i;
2712 stl_brdstats.panels[i].hwid = panelp->hwid;
2713 stl_brdstats.panels[i].nrports = panelp->nrports;
2716 return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
2719 /*****************************************************************************/
2722 * Resolve the referenced port number into a port struct pointer.
2725 static struct stlport *stl_getport(int brdnr, int panelnr, int portnr)
2727 struct stlbrd *brdp;
2728 struct stlpanel *panelp;
2730 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2732 brdp = stl_brds[brdnr];
2735 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2737 panelp = brdp->panels[panelnr];
2740 if ((portnr < 0) || (portnr >= panelp->nrports))
2742 return(panelp->ports[portnr]);
2745 /*****************************************************************************/
2748 * Return the port stats structure to user app. A NULL port struct
2749 * pointer passed in means that we need to find out from the app
2750 * what port to get stats for (used through board control device).
2753 static int stl_getportstats(struct stlport *portp, comstats_t __user *cp)
2755 unsigned char *head, *tail;
2756 unsigned long flags;
2759 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2761 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2767 portp->stats.state = portp->istate;
2768 portp->stats.flags = portp->flags;
2769 portp->stats.hwid = portp->hwid;
2771 portp->stats.ttystate = 0;
2772 portp->stats.cflags = 0;
2773 portp->stats.iflags = 0;
2774 portp->stats.oflags = 0;
2775 portp->stats.lflags = 0;
2776 portp->stats.rxbuffered = 0;
2778 spin_lock_irqsave(&stallion_lock, flags);
2779 if (portp->tty != NULL) {
2780 if (portp->tty->driver_data == portp) {
2781 portp->stats.ttystate = portp->tty->flags;
2782 /* No longer available as a statistic */
2783 portp->stats.rxbuffered = 1; /*portp->tty->flip.count; */
2784 if (portp->tty->termios != NULL) {
2785 portp->stats.cflags = portp->tty->termios->c_cflag;
2786 portp->stats.iflags = portp->tty->termios->c_iflag;
2787 portp->stats.oflags = portp->tty->termios->c_oflag;
2788 portp->stats.lflags = portp->tty->termios->c_lflag;
2792 spin_unlock_irqrestore(&stallion_lock, flags);
2794 head = portp->tx.head;
2795 tail = portp->tx.tail;
2796 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2797 (STL_TXBUFSIZE - (tail - head)));
2799 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2801 return copy_to_user(cp, &portp->stats,
2802 sizeof(comstats_t)) ? -EFAULT : 0;
2805 /*****************************************************************************/
2808 * Clear the port stats structure. We also return it zeroed out...
2811 static int stl_clrportstats(struct stlport *portp, comstats_t __user *cp)
2814 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2816 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2822 memset(&portp->stats, 0, sizeof(comstats_t));
2823 portp->stats.brd = portp->brdnr;
2824 portp->stats.panel = portp->panelnr;
2825 portp->stats.port = portp->portnr;
2826 return copy_to_user(cp, &portp->stats,
2827 sizeof(comstats_t)) ? -EFAULT : 0;
2830 /*****************************************************************************/
2833 * Return the entire driver ports structure to a user app.
2836 static int stl_getportstruct(struct stlport __user *arg)
2838 struct stlport *portp;
2840 if (copy_from_user(&stl_dummyport, arg, sizeof(struct stlport)))
2842 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
2843 stl_dummyport.portnr);
2846 return copy_to_user(arg, portp, sizeof(struct stlport)) ? -EFAULT : 0;
2849 /*****************************************************************************/
2852 * Return the entire driver board structure to a user app.
2855 static int stl_getbrdstruct(struct stlbrd __user *arg)
2857 struct stlbrd *brdp;
2859 if (copy_from_user(&stl_dummybrd, arg, sizeof(struct stlbrd)))
2861 if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
2863 brdp = stl_brds[stl_dummybrd.brdnr];
2866 return copy_to_user(arg, brdp, sizeof(struct stlbrd)) ? -EFAULT : 0;
2869 /*****************************************************************************/
2872 * The "staliomem" device is also required to do some special operations
2873 * on the board and/or ports. In this driver it is mostly used for stats
2877 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
2880 void __user *argp = (void __user *)arg;
2882 pr_debug("stl_memioctl(ip=%p,fp=%p,cmd=%x,arg=%lx)\n", ip, fp, cmd,arg);
2885 if (brdnr >= STL_MAXBRDS)
2890 case COM_GETPORTSTATS:
2891 rc = stl_getportstats(NULL, argp);
2893 case COM_CLRPORTSTATS:
2894 rc = stl_clrportstats(NULL, argp);
2896 case COM_GETBRDSTATS:
2897 rc = stl_getbrdstats(argp);
2900 rc = stl_getportstruct(argp);
2903 rc = stl_getbrdstruct(argp);
2913 static const struct tty_operations stl_ops = {
2917 .put_char = stl_putchar,
2918 .flush_chars = stl_flushchars,
2919 .write_room = stl_writeroom,
2920 .chars_in_buffer = stl_charsinbuffer,
2922 .set_termios = stl_settermios,
2923 .throttle = stl_throttle,
2924 .unthrottle = stl_unthrottle,
2927 .hangup = stl_hangup,
2928 .flush_buffer = stl_flushbuffer,
2929 .break_ctl = stl_breakctl,
2930 .wait_until_sent = stl_waituntilsent,
2931 .send_xchar = stl_sendxchar,
2932 .read_proc = stl_readproc,
2933 .tiocmget = stl_tiocmget,
2934 .tiocmset = stl_tiocmset,
2937 /*****************************************************************************/
2939 static int __init stl_init(void)
2942 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
2944 spin_lock_init(&stallion_lock);
2945 spin_lock_init(&brd_lock);
2949 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
2954 * Set up a character driver for per board stuff. This is mainly used
2955 * to do stats ioctls on the ports.
2957 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
2958 printk("STALLION: failed to register serial board device\n");
2960 stallion_class = class_create(THIS_MODULE, "staliomem");
2961 for (i = 0; i < 4; i++)
2962 class_device_create(stallion_class, NULL,
2963 MKDEV(STL_SIOMEMMAJOR, i), NULL,
2966 stl_serial->owner = THIS_MODULE;
2967 stl_serial->driver_name = stl_drvname;
2968 stl_serial->name = "ttyE";
2969 stl_serial->major = STL_SERIALMAJOR;
2970 stl_serial->minor_start = 0;
2971 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
2972 stl_serial->subtype = SERIAL_TYPE_NORMAL;
2973 stl_serial->init_termios = stl_deftermios;
2974 stl_serial->flags = TTY_DRIVER_REAL_RAW;
2975 tty_set_operations(stl_serial, &stl_ops);
2977 if (tty_register_driver(stl_serial)) {
2978 put_tty_driver(stl_serial);
2979 printk("STALLION: failed to register serial driver\n");
2986 /*****************************************************************************/
2987 /* CD1400 HARDWARE FUNCTIONS */
2988 /*****************************************************************************/
2991 * These functions get/set/update the registers of the cd1400 UARTs.
2992 * Access to the cd1400 registers is via an address/data io port pair.
2993 * (Maybe should make this inline...)
2996 static int stl_cd1400getreg(struct stlport *portp, int regnr)
2998 outb((regnr + portp->uartaddr), portp->ioaddr);
2999 return inb(portp->ioaddr + EREG_DATA);
3002 static void stl_cd1400setreg(struct stlport *portp, int regnr, int value)
3004 outb((regnr + portp->uartaddr), portp->ioaddr);
3005 outb(value, portp->ioaddr + EREG_DATA);
3008 static int stl_cd1400updatereg(struct stlport *portp, int regnr, int value)
3010 outb((regnr + portp->uartaddr), portp->ioaddr);
3011 if (inb(portp->ioaddr + EREG_DATA) != value) {
3012 outb(value, portp->ioaddr + EREG_DATA);
3018 /*****************************************************************************/
3021 * Inbitialize the UARTs in a panel. We don't care what sort of board
3022 * these ports are on - since the port io registers are almost
3023 * identical when dealing with ports.
3026 static int stl_cd1400panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
3030 int nrchips, uartaddr, ioaddr;
3031 unsigned long flags;
3033 pr_debug("stl_panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
3035 spin_lock_irqsave(&brd_lock, flags);
3036 BRDENABLE(panelp->brdnr, panelp->pagenr);
3039 * Check that each chip is present and started up OK.
3042 nrchips = panelp->nrports / CD1400_PORTS;
3043 for (i = 0; (i < nrchips); i++) {
3044 if (brdp->brdtype == BRD_ECHPCI) {
3045 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3046 ioaddr = panelp->iobase;
3048 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3050 uartaddr = (i & 0x01) ? 0x080 : 0;
3051 outb((GFRCR + uartaddr), ioaddr);
3052 outb(0, (ioaddr + EREG_DATA));
3053 outb((CCR + uartaddr), ioaddr);
3054 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3055 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3056 outb((GFRCR + uartaddr), ioaddr);
3057 for (j = 0; (j < CCR_MAXWAIT); j++) {
3058 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3061 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3062 printk("STALLION: cd1400 not responding, "
3063 "brd=%d panel=%d chip=%d\n",
3064 panelp->brdnr, panelp->panelnr, i);
3067 chipmask |= (0x1 << i);
3068 outb((PPR + uartaddr), ioaddr);
3069 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
3072 BRDDISABLE(panelp->brdnr);
3073 spin_unlock_irqrestore(&brd_lock, flags);
3077 /*****************************************************************************/
3080 * Initialize hardware specific port registers.
3083 static void stl_cd1400portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
3085 unsigned long flags;
3086 pr_debug("stl_cd1400portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
3089 if ((brdp == NULL) || (panelp == NULL) ||
3093 spin_lock_irqsave(&brd_lock, flags);
3094 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3095 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3096 portp->uartaddr = (portp->portnr & 0x04) << 5;
3097 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3099 BRDENABLE(portp->brdnr, portp->pagenr);
3100 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3101 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3102 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3103 BRDDISABLE(portp->brdnr);
3104 spin_unlock_irqrestore(&brd_lock, flags);
3107 /*****************************************************************************/
3110 * Wait for the command register to be ready. We will poll this,
3111 * since it won't usually take too long to be ready.
3114 static void stl_cd1400ccrwait(struct stlport *portp)
3118 for (i = 0; (i < CCR_MAXWAIT); i++) {
3119 if (stl_cd1400getreg(portp, CCR) == 0) {
3124 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
3125 portp->portnr, portp->panelnr, portp->brdnr);
3128 /*****************************************************************************/
3131 * Set up the cd1400 registers for a port based on the termios port
3135 static void stl_cd1400setport(struct stlport *portp, struct termios *tiosp)
3137 struct stlbrd *brdp;
3138 unsigned long flags;
3139 unsigned int clkdiv, baudrate;
3140 unsigned char cor1, cor2, cor3;
3141 unsigned char cor4, cor5, ccr;
3142 unsigned char srer, sreron, sreroff;
3143 unsigned char mcor1, mcor2, rtpr;
3144 unsigned char clk, div;
3160 brdp = stl_brds[portp->brdnr];
3165 * Set up the RX char ignore mask with those RX error types we
3166 * can ignore. We can get the cd1400 to help us out a little here,
3167 * it will ignore parity errors and breaks for us.
3169 portp->rxignoremsk = 0;
3170 if (tiosp->c_iflag & IGNPAR) {
3171 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
3172 cor1 |= COR1_PARIGNORE;
3174 if (tiosp->c_iflag & IGNBRK) {
3175 portp->rxignoremsk |= ST_BREAK;
3176 cor4 |= COR4_IGNBRK;
3179 portp->rxmarkmsk = ST_OVERRUN;
3180 if (tiosp->c_iflag & (INPCK | PARMRK))
3181 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3182 if (tiosp->c_iflag & BRKINT)
3183 portp->rxmarkmsk |= ST_BREAK;
3186 * Go through the char size, parity and stop bits and set all the
3187 * option register appropriately.
3189 switch (tiosp->c_cflag & CSIZE) {
3204 if (tiosp->c_cflag & CSTOPB)
3209 if (tiosp->c_cflag & PARENB) {
3210 if (tiosp->c_cflag & PARODD)
3211 cor1 |= (COR1_PARENB | COR1_PARODD);
3213 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3215 cor1 |= COR1_PARNONE;
3219 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3220 * space for hardware flow control and the like. This should be set to
3221 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3222 * really be based on VTIME.
3224 cor3 |= FIFO_RXTHRESHOLD;
3228 * Calculate the baud rate timers. For now we will just assume that
3229 * the input and output baud are the same. Could have used a baud
3230 * table here, but this way we can generate virtually any baud rate
3233 baudrate = tiosp->c_cflag & CBAUD;
3234 if (baudrate & CBAUDEX) {
3235 baudrate &= ~CBAUDEX;
3236 if ((baudrate < 1) || (baudrate > 4))
3237 tiosp->c_cflag &= ~CBAUDEX;
3241 baudrate = stl_baudrates[baudrate];
3242 if ((tiosp->c_cflag & CBAUD) == B38400) {
3243 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3245 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3247 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3249 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3251 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3252 baudrate = (portp->baud_base / portp->custom_divisor);
3254 if (baudrate > STL_CD1400MAXBAUD)
3255 baudrate = STL_CD1400MAXBAUD;
3258 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3259 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
3263 div = (unsigned char) clkdiv;
3267 * Check what form of modem signaling is required and set it up.
3269 if ((tiosp->c_cflag & CLOCAL) == 0) {
3272 sreron |= SRER_MODEM;
3273 portp->flags |= ASYNC_CHECK_CD;
3275 portp->flags &= ~ASYNC_CHECK_CD;
3279 * Setup cd1400 enhanced modes if we can. In particular we want to
3280 * handle as much of the flow control as possible automatically. As
3281 * well as saving a few CPU cycles it will also greatly improve flow
3282 * control reliability.
3284 if (tiosp->c_iflag & IXON) {
3287 if (tiosp->c_iflag & IXANY)
3291 if (tiosp->c_cflag & CRTSCTS) {
3293 mcor1 |= FIFO_RTSTHRESHOLD;
3297 * All cd1400 register values calculated so go through and set
3301 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3302 portp->portnr, portp->panelnr, portp->brdnr);
3303 pr_debug(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3304 cor1, cor2, cor3, cor4, cor5);
3305 pr_debug(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3306 mcor1, mcor2, rtpr, sreron, sreroff);
3307 pr_debug(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3308 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3309 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3310 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3312 spin_lock_irqsave(&brd_lock, flags);
3313 BRDENABLE(portp->brdnr, portp->pagenr);
3314 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3315 srer = stl_cd1400getreg(portp, SRER);
3316 stl_cd1400setreg(portp, SRER, 0);
3317 if (stl_cd1400updatereg(portp, COR1, cor1))
3319 if (stl_cd1400updatereg(portp, COR2, cor2))
3321 if (stl_cd1400updatereg(portp, COR3, cor3))
3324 stl_cd1400ccrwait(portp);
3325 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3327 stl_cd1400setreg(portp, COR4, cor4);
3328 stl_cd1400setreg(portp, COR5, cor5);
3329 stl_cd1400setreg(portp, MCOR1, mcor1);
3330 stl_cd1400setreg(portp, MCOR2, mcor2);
3332 stl_cd1400setreg(portp, TCOR, clk);
3333 stl_cd1400setreg(portp, TBPR, div);
3334 stl_cd1400setreg(portp, RCOR, clk);
3335 stl_cd1400setreg(portp, RBPR, div);
3337 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3338 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3339 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3340 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3341 stl_cd1400setreg(portp, RTPR, rtpr);
3342 mcor1 = stl_cd1400getreg(portp, MSVR1);
3343 if (mcor1 & MSVR1_DCD)
3344 portp->sigs |= TIOCM_CD;
3346 portp->sigs &= ~TIOCM_CD;
3347 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3348 BRDDISABLE(portp->brdnr);
3349 spin_unlock_irqrestore(&brd_lock, flags);
3352 /*****************************************************************************/
3355 * Set the state of the DTR and RTS signals.
3358 static void stl_cd1400setsignals(struct stlport *portp, int dtr, int rts)
3360 unsigned char msvr1, msvr2;
3361 unsigned long flags;
3363 pr_debug("stl_cd1400setsignals(portp=%p,dtr=%d,rts=%d)\n",
3373 spin_lock_irqsave(&brd_lock, flags);
3374 BRDENABLE(portp->brdnr, portp->pagenr);
3375 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3377 stl_cd1400setreg(portp, MSVR2, msvr2);
3379 stl_cd1400setreg(portp, MSVR1, msvr1);
3380 BRDDISABLE(portp->brdnr);
3381 spin_unlock_irqrestore(&brd_lock, flags);
3384 /*****************************************************************************/
3387 * Return the state of the signals.
3390 static int stl_cd1400getsignals(struct stlport *portp)
3392 unsigned char msvr1, msvr2;
3393 unsigned long flags;
3396 pr_debug("stl_cd1400getsignals(portp=%p)\n", portp);
3398 spin_lock_irqsave(&brd_lock, flags);
3399 BRDENABLE(portp->brdnr, portp->pagenr);
3400 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3401 msvr1 = stl_cd1400getreg(portp, MSVR1);
3402 msvr2 = stl_cd1400getreg(portp, MSVR2);
3403 BRDDISABLE(portp->brdnr);
3404 spin_unlock_irqrestore(&brd_lock, flags);
3407 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3408 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3409 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3410 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3412 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3413 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3420 /*****************************************************************************/
3423 * Enable/Disable the Transmitter and/or Receiver.
3426 static void stl_cd1400enablerxtx(struct stlport *portp, int rx, int tx)
3429 unsigned long flags;
3431 pr_debug("stl_cd1400enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
3436 ccr |= CCR_TXDISABLE;
3438 ccr |= CCR_TXENABLE;
3440 ccr |= CCR_RXDISABLE;
3442 ccr |= CCR_RXENABLE;
3444 spin_lock_irqsave(&brd_lock, flags);
3445 BRDENABLE(portp->brdnr, portp->pagenr);
3446 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3447 stl_cd1400ccrwait(portp);
3448 stl_cd1400setreg(portp, CCR, ccr);
3449 stl_cd1400ccrwait(portp);
3450 BRDDISABLE(portp->brdnr);
3451 spin_unlock_irqrestore(&brd_lock, flags);
3454 /*****************************************************************************/
3457 * Start/stop the Transmitter and/or Receiver.
3460 static void stl_cd1400startrxtx(struct stlport *portp, int rx, int tx)
3462 unsigned char sreron, sreroff;
3463 unsigned long flags;
3465 pr_debug("stl_cd1400startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
3470 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3472 sreron |= SRER_TXDATA;
3474 sreron |= SRER_TXEMPTY;
3476 sreroff |= SRER_RXDATA;
3478 sreron |= SRER_RXDATA;
3480 spin_lock_irqsave(&brd_lock, flags);
3481 BRDENABLE(portp->brdnr, portp->pagenr);
3482 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3483 stl_cd1400setreg(portp, SRER,
3484 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3485 BRDDISABLE(portp->brdnr);
3487 set_bit(ASYI_TXBUSY, &portp->istate);
3488 spin_unlock_irqrestore(&brd_lock, flags);
3491 /*****************************************************************************/
3494 * Disable all interrupts from this port.
3497 static void stl_cd1400disableintrs(struct stlport *portp)
3499 unsigned long flags;
3501 pr_debug("stl_cd1400disableintrs(portp=%p)\n", portp);
3503 spin_lock_irqsave(&brd_lock, flags);
3504 BRDENABLE(portp->brdnr, portp->pagenr);
3505 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3506 stl_cd1400setreg(portp, SRER, 0);
3507 BRDDISABLE(portp->brdnr);
3508 spin_unlock_irqrestore(&brd_lock, flags);
3511 /*****************************************************************************/
3513 static void stl_cd1400sendbreak(struct stlport *portp, int len)
3515 unsigned long flags;
3517 pr_debug("stl_cd1400sendbreak(portp=%p,len=%d)\n", portp, len);
3519 spin_lock_irqsave(&brd_lock, flags);
3520 BRDENABLE(portp->brdnr, portp->pagenr);
3521 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3522 stl_cd1400setreg(portp, SRER,
3523 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3525 BRDDISABLE(portp->brdnr);
3526 portp->brklen = len;
3528 portp->stats.txbreaks++;
3529 spin_unlock_irqrestore(&brd_lock, flags);
3532 /*****************************************************************************/
3535 * Take flow control actions...
3538 static void stl_cd1400flowctrl(struct stlport *portp, int state)
3540 struct tty_struct *tty;
3541 unsigned long flags;
3543 pr_debug("stl_cd1400flowctrl(portp=%p,state=%x)\n", portp, state);
3551 spin_lock_irqsave(&brd_lock, flags);
3552 BRDENABLE(portp->brdnr, portp->pagenr);
3553 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3556 if (tty->termios->c_iflag & IXOFF) {
3557 stl_cd1400ccrwait(portp);
3558 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3559 portp->stats.rxxon++;
3560 stl_cd1400ccrwait(portp);
3563 * Question: should we return RTS to what it was before? It may
3564 * have been set by an ioctl... Suppose not, since if you have
3565 * hardware flow control set then it is pretty silly to go and
3566 * set the RTS line by hand.
3568 if (tty->termios->c_cflag & CRTSCTS) {
3569 stl_cd1400setreg(portp, MCOR1,
3570 (stl_cd1400getreg(portp, MCOR1) |
3571 FIFO_RTSTHRESHOLD));
3572 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3573 portp->stats.rxrtson++;
3576 if (tty->termios->c_iflag & IXOFF) {
3577 stl_cd1400ccrwait(portp);
3578 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3579 portp->stats.rxxoff++;
3580 stl_cd1400ccrwait(portp);
3582 if (tty->termios->c_cflag & CRTSCTS) {
3583 stl_cd1400setreg(portp, MCOR1,
3584 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3585 stl_cd1400setreg(portp, MSVR2, 0);
3586 portp->stats.rxrtsoff++;
3590 BRDDISABLE(portp->brdnr);
3591 spin_unlock_irqrestore(&brd_lock, flags);
3594 /*****************************************************************************/
3597 * Send a flow control character...
3600 static void stl_cd1400sendflow(struct stlport *portp, int state)
3602 struct tty_struct *tty;
3603 unsigned long flags;
3605 pr_debug("stl_cd1400sendflow(portp=%p,state=%x)\n", portp, state);
3613 spin_lock_irqsave(&brd_lock, flags);
3614 BRDENABLE(portp->brdnr, portp->pagenr);
3615 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3617 stl_cd1400ccrwait(portp);
3618 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3619 portp->stats.rxxon++;
3620 stl_cd1400ccrwait(portp);
3622 stl_cd1400ccrwait(portp);
3623 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3624 portp->stats.rxxoff++;
3625 stl_cd1400ccrwait(portp);
3627 BRDDISABLE(portp->brdnr);
3628 spin_unlock_irqrestore(&brd_lock, flags);
3631 /*****************************************************************************/
3633 static void stl_cd1400flush(struct stlport *portp)
3635 unsigned long flags;
3637 pr_debug("stl_cd1400flush(portp=%p)\n", portp);
3642 spin_lock_irqsave(&brd_lock, flags);
3643 BRDENABLE(portp->brdnr, portp->pagenr);
3644 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3645 stl_cd1400ccrwait(portp);
3646 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3647 stl_cd1400ccrwait(portp);
3648 portp->tx.tail = portp->tx.head;
3649 BRDDISABLE(portp->brdnr);
3650 spin_unlock_irqrestore(&brd_lock, flags);
3653 /*****************************************************************************/
3656 * Return the current state of data flow on this port. This is only
3657 * really interresting when determining if data has fully completed
3658 * transmission or not... This is easy for the cd1400, it accurately
3659 * maintains the busy port flag.
3662 static int stl_cd1400datastate(struct stlport *portp)
3664 pr_debug("stl_cd1400datastate(portp=%p)\n", portp);
3669 return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
3672 /*****************************************************************************/
3675 * Interrupt service routine for cd1400 EasyIO boards.
3678 static void stl_cd1400eiointr(struct stlpanel *panelp, unsigned int iobase)
3680 unsigned char svrtype;
3682 pr_debug("stl_cd1400eiointr(panelp=%p,iobase=%x)\n", panelp, iobase);
3684 spin_lock(&brd_lock);
3686 svrtype = inb(iobase + EREG_DATA);
3687 if (panelp->nrports > 4) {
3688 outb((SVRR + 0x80), iobase);
3689 svrtype |= inb(iobase + EREG_DATA);
3692 if (svrtype & SVRR_RX)
3693 stl_cd1400rxisr(panelp, iobase);
3694 else if (svrtype & SVRR_TX)
3695 stl_cd1400txisr(panelp, iobase);
3696 else if (svrtype & SVRR_MDM)
3697 stl_cd1400mdmisr(panelp, iobase);
3699 spin_unlock(&brd_lock);
3702 /*****************************************************************************/
3705 * Interrupt service routine for cd1400 panels.
3708 static void stl_cd1400echintr(struct stlpanel *panelp, unsigned int iobase)
3710 unsigned char svrtype;
3712 pr_debug("stl_cd1400echintr(panelp=%p,iobase=%x)\n", panelp, iobase);
3715 svrtype = inb(iobase + EREG_DATA);
3716 outb((SVRR + 0x80), iobase);
3717 svrtype |= inb(iobase + EREG_DATA);
3718 if (svrtype & SVRR_RX)
3719 stl_cd1400rxisr(panelp, iobase);
3720 else if (svrtype & SVRR_TX)
3721 stl_cd1400txisr(panelp, iobase);
3722 else if (svrtype & SVRR_MDM)
3723 stl_cd1400mdmisr(panelp, iobase);
3727 /*****************************************************************************/
3730 * Unfortunately we need to handle breaks in the TX data stream, since
3731 * this is the only way to generate them on the cd1400.
3734 static inline int stl_cd1400breakisr(struct stlport *portp, int ioaddr)
3736 if (portp->brklen == 1) {
3737 outb((COR2 + portp->uartaddr), ioaddr);
3738 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
3739 (ioaddr + EREG_DATA));
3740 outb((TDR + portp->uartaddr), ioaddr);
3741 outb(ETC_CMD, (ioaddr + EREG_DATA));
3742 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
3743 outb((SRER + portp->uartaddr), ioaddr);
3744 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
3745 (ioaddr + EREG_DATA));
3747 } else if (portp->brklen > 1) {
3748 outb((TDR + portp->uartaddr), ioaddr);
3749 outb(ETC_CMD, (ioaddr + EREG_DATA));
3750 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
3754 outb((COR2 + portp->uartaddr), ioaddr);
3755 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
3756 (ioaddr + EREG_DATA));
3762 /*****************************************************************************/
3765 * Transmit interrupt handler. This has gotta be fast! Handling TX
3766 * chars is pretty simple, stuff as many as possible from the TX buffer
3767 * into the cd1400 FIFO. Must also handle TX breaks here, since they
3768 * are embedded as commands in the data stream. Oh no, had to use a goto!
3769 * This could be optimized more, will do when I get time...
3770 * In practice it is possible that interrupts are enabled but that the
3771 * port has been hung up. Need to handle not having any TX buffer here,
3772 * this is done by using the side effect that head and tail will also
3773 * be NULL if the buffer has been freed.
3776 static void stl_cd1400txisr(struct stlpanel *panelp, int ioaddr)
3778 struct stlport *portp;
3781 unsigned char ioack, srer;
3783 pr_debug("stl_cd1400txisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3785 ioack = inb(ioaddr + EREG_TXACK);
3786 if (((ioack & panelp->ackmask) != 0) ||
3787 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
3788 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
3791 portp = panelp->ports[(ioack >> 3)];
3794 * Unfortunately we need to handle breaks in the data stream, since
3795 * this is the only way to generate them on the cd1400. Do it now if
3796 * a break is to be sent.
3798 if (portp->brklen != 0)
3799 if (stl_cd1400breakisr(portp, ioaddr))
3802 head = portp->tx.head;
3803 tail = portp->tx.tail;
3804 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
3805 if ((len == 0) || ((len < STL_TXBUFLOW) &&
3806 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
3807 set_bit(ASYI_TXLOW, &portp->istate);
3808 schedule_work(&portp->tqueue);
3812 outb((SRER + portp->uartaddr), ioaddr);
3813 srer = inb(ioaddr + EREG_DATA);
3814 if (srer & SRER_TXDATA) {
3815 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
3817 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
3818 clear_bit(ASYI_TXBUSY, &portp->istate);
3820 outb(srer, (ioaddr + EREG_DATA));
3822 len = MIN(len, CD1400_TXFIFOSIZE);
3823 portp->stats.txtotal += len;
3824 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
3825 outb((TDR + portp->uartaddr), ioaddr);
3826 outsb((ioaddr + EREG_DATA), tail, stlen);
3829 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
3830 tail = portp->tx.buf;
3832 outsb((ioaddr + EREG_DATA), tail, len);
3835 portp->tx.tail = tail;
3839 outb((EOSRR + portp->uartaddr), ioaddr);
3840 outb(0, (ioaddr + EREG_DATA));
3843 /*****************************************************************************/
3846 * Receive character interrupt handler. Determine if we have good chars
3847 * or bad chars and then process appropriately. Good chars are easy
3848 * just shove the lot into the RX buffer and set all status byte to 0.
3849 * If a bad RX char then process as required. This routine needs to be
3850 * fast! In practice it is possible that we get an interrupt on a port
3851 * that is closed. This can happen on hangups - since they completely
3852 * shutdown a port not in user context. Need to handle this case.
3855 static void stl_cd1400rxisr(struct stlpanel *panelp, int ioaddr)
3857 struct stlport *portp;
3858 struct tty_struct *tty;
3859 unsigned int ioack, len, buflen;
3860 unsigned char status;
3863 pr_debug("stl_cd1400rxisr(panelp=%p,ioaddr=%x)\n", panelp, ioaddr);
3865 ioack = inb(ioaddr + EREG_RXACK);
3866 if ((ioack & panelp->ackmask) != 0) {
3867 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
3870 portp = panelp->ports[(ioack >> 3)];
3873 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
3874 outb((RDCR + portp->uartaddr), ioaddr);
3875 len = inb(ioaddr + EREG_DATA);
3876 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
3877 len = MIN(len, sizeof(stl_unwanted));
3878 outb((RDSR + portp->uartaddr), ioaddr);
3879 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
3880 portp->stats.rxlost += len;
3881 portp->stats.rxtotal += len;
3883 len = MIN(len, buflen);
3886 outb((RDSR + portp->uartaddr), ioaddr);
3887 tty_prepare_flip_string(tty, &ptr, len);
3888 insb((ioaddr + EREG_DATA), ptr, len);
3889 tty_schedule_flip(tty);
3890 portp->stats.rxtotal += len;
3893 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
3894 outb((RDSR + portp->uartaddr), ioaddr);
3895 status = inb(ioaddr + EREG_DATA);
3896 ch = inb(ioaddr + EREG_DATA);
3897 if (status & ST_PARITY)
3898 portp->stats.rxparity++;
3899 if (status & ST_FRAMING)
3900 portp->stats.rxframing++;
3901 if (status & ST_OVERRUN)
3902 portp->stats.rxoverrun++;
3903 if (status & ST_BREAK)
3904 portp->stats.rxbreaks++;
3905 if (status & ST_SCHARMASK) {
3906 if ((status & ST_SCHARMASK) == ST_SCHAR1)
3907 portp->stats.txxon++;
3908 if ((status & ST_SCHARMASK) == ST_SCHAR2)
3909 portp->stats.txxoff++;
3912 if (tty != NULL && (portp->rxignoremsk & status) == 0) {
3913 if (portp->rxmarkmsk & status) {
3914 if (status & ST_BREAK) {
3916 if (portp->flags & ASYNC_SAK) {
3918 BRDENABLE(portp->brdnr, portp->pagenr);
3920 } else if (status & ST_PARITY) {
3921 status = TTY_PARITY;
3922 } else if (status & ST_FRAMING) {
3924 } else if(status & ST_OVERRUN) {
3925 status = TTY_OVERRUN;
3932 tty_insert_flip_char(tty, ch, status);
3933 tty_schedule_flip(tty);
3936 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
3941 outb((EOSRR + portp->uartaddr), ioaddr);
3942 outb(0, (ioaddr + EREG_DATA));
3945 /*****************************************************************************/
3948 * Modem interrupt handler. The is called when the modem signal line
3949 * (DCD) has changed state. Leave most of the work to the off-level
3950 * processing routine.
3953 static void stl_cd1400mdmisr(struct stlpanel *panelp, int ioaddr)
3955 struct stlport *portp;
3959 pr_debug("stl_cd1400mdmisr(panelp=%p)\n", panelp);
3961 ioack = inb(ioaddr + EREG_MDACK);
3962 if (((ioack & panelp->ackmask) != 0) ||
3963 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
3964 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
3967 portp = panelp->ports[(ioack >> 3)];
3969 outb((MISR + portp->uartaddr), ioaddr);
3970 misr = inb(ioaddr + EREG_DATA);
3971 if (misr & MISR_DCD) {
3972 set_bit(ASYI_DCDCHANGE, &portp->istate);
3973 schedule_work(&portp->tqueue);
3974 portp->stats.modem++;
3977 outb((EOSRR + portp->uartaddr), ioaddr);
3978 outb(0, (ioaddr + EREG_DATA));
3981 /*****************************************************************************/
3982 /* SC26198 HARDWARE FUNCTIONS */
3983 /*****************************************************************************/
3986 * These functions get/set/update the registers of the sc26198 UARTs.
3987 * Access to the sc26198 registers is via an address/data io port pair.
3988 * (Maybe should make this inline...)
3991 static int stl_sc26198getreg(struct stlport *portp, int regnr)
3993 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
3994 return inb(portp->ioaddr + XP_DATA);
3997 static void stl_sc26198setreg(struct stlport *portp, int regnr, int value)
3999 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4000 outb(value, (portp->ioaddr + XP_DATA));
4003 static int stl_sc26198updatereg(struct stlport *portp, int regnr, int value)
4005 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4006 if (inb(portp->ioaddr + XP_DATA) != value) {
4007 outb(value, (portp->ioaddr + XP_DATA));
4013 /*****************************************************************************/
4016 * Functions to get and set the sc26198 global registers.
4019 static int stl_sc26198getglobreg(struct stlport *portp, int regnr)
4021 outb(regnr, (portp->ioaddr + XP_ADDR));
4022 return inb(portp->ioaddr + XP_DATA);
4026 static void stl_sc26198setglobreg(struct stlport *portp, int regnr, int value)
4028 outb(regnr, (portp->ioaddr + XP_ADDR));
4029 outb(value, (portp->ioaddr + XP_DATA));
4033 /*****************************************************************************/
4036 * Inbitialize the UARTs in a panel. We don't care what sort of board
4037 * these ports are on - since the port io registers are almost
4038 * identical when dealing with ports.
4041 static int stl_sc26198panelinit(struct stlbrd *brdp, struct stlpanel *panelp)
4044 int nrchips, ioaddr;
4046 pr_debug("stl_sc26198panelinit(brdp=%p,panelp=%p)\n", brdp, panelp);
4048 BRDENABLE(panelp->brdnr, panelp->pagenr);
4051 * Check that each chip is present and started up OK.
4054 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
4055 if (brdp->brdtype == BRD_ECHPCI)
4056 outb(panelp->pagenr, brdp->ioctrl);
4058 for (i = 0; (i < nrchips); i++) {
4059 ioaddr = panelp->iobase + (i * 4);
4060 outb(SCCR, (ioaddr + XP_ADDR));
4061 outb(CR_RESETALL, (ioaddr + XP_DATA));
4062 outb(TSTR, (ioaddr + XP_ADDR));
4063 if (inb(ioaddr + XP_DATA) != 0) {
4064 printk("STALLION: sc26198 not responding, "
4065 "brd=%d panel=%d chip=%d\n",
4066 panelp->brdnr, panelp->panelnr, i);
4069 chipmask |= (0x1 << i);
4070 outb(GCCR, (ioaddr + XP_ADDR));
4071 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
4072 outb(WDTRCR, (ioaddr + XP_ADDR));
4073 outb(0xff, (ioaddr + XP_DATA));
4076 BRDDISABLE(panelp->brdnr);
4080 /*****************************************************************************/
4083 * Initialize hardware specific port registers.
4086 static void stl_sc26198portinit(struct stlbrd *brdp, struct stlpanel *panelp, struct stlport *portp)
4088 pr_debug("stl_sc26198portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp,
4091 if ((brdp == NULL) || (panelp == NULL) ||
4095 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
4096 portp->uartaddr = (portp->portnr & 0x07) << 4;
4097 portp->pagenr = panelp->pagenr;
4100 BRDENABLE(portp->brdnr, portp->pagenr);
4101 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
4102 BRDDISABLE(portp->brdnr);
4105 /*****************************************************************************/
4108 * Set up the sc26198 registers for a port based on the termios port
4112 static void stl_sc26198setport(struct stlport *portp, struct termios *tiosp)
4114 struct stlbrd *brdp;
4115 unsigned long flags;
4116 unsigned int baudrate;
4117 unsigned char mr0, mr1, mr2, clk;
4118 unsigned char imron, imroff, iopr, ipr;
4128 brdp = stl_brds[portp->brdnr];
4133 * Set up the RX char ignore mask with those RX error types we
4136 portp->rxignoremsk = 0;
4137 if (tiosp->c_iflag & IGNPAR)
4138 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
4140 if (tiosp->c_iflag & IGNBRK)
4141 portp->rxignoremsk |= SR_RXBREAK;
4143 portp->rxmarkmsk = SR_RXOVERRUN;
4144 if (tiosp->c_iflag & (INPCK | PARMRK))
4145 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
4146 if (tiosp->c_iflag & BRKINT)
4147 portp->rxmarkmsk |= SR_RXBREAK;
4150 * Go through the char size, parity and stop bits and set all the
4151 * option register appropriately.
4153 switch (tiosp->c_cflag & CSIZE) {
4168 if (tiosp->c_cflag & CSTOPB)
4173 if (tiosp->c_cflag & PARENB) {
4174 if (tiosp->c_cflag & PARODD)
4175 mr1 |= (MR1_PARENB | MR1_PARODD);
4177 mr1 |= (MR1_PARENB | MR1_PAREVEN);
4182 mr1 |= MR1_ERRBLOCK;
4185 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4186 * space for hardware flow control and the like. This should be set to
4189 mr2 |= MR2_RXFIFOHALF;
4192 * Calculate the baud rate timers. For now we will just assume that
4193 * the input and output baud are the same. The sc26198 has a fixed
4194 * baud rate table, so only discrete baud rates possible.
4196 baudrate = tiosp->c_cflag & CBAUD;
4197 if (baudrate & CBAUDEX) {
4198 baudrate &= ~CBAUDEX;
4199 if ((baudrate < 1) || (baudrate > 4))
4200 tiosp->c_cflag &= ~CBAUDEX;
4204 baudrate = stl_baudrates[baudrate];
4205 if ((tiosp->c_cflag & CBAUD) == B38400) {
4206 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
4208 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
4210 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
4212 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
4214 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
4215 baudrate = (portp->baud_base / portp->custom_divisor);
4217 if (baudrate > STL_SC26198MAXBAUD)
4218 baudrate = STL_SC26198MAXBAUD;
4221 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
4222 if (baudrate <= sc26198_baudtable[clk])
4228 * Check what form of modem signaling is required and set it up.
4230 if (tiosp->c_cflag & CLOCAL) {
4231 portp->flags &= ~ASYNC_CHECK_CD;
4233 iopr |= IOPR_DCDCOS;
4235 portp->flags |= ASYNC_CHECK_CD;
4239 * Setup sc26198 enhanced modes if we can. In particular we want to
4240 * handle as much of the flow control as possible automatically. As
4241 * well as saving a few CPU cycles it will also greatly improve flow
4242 * control reliability.
4244 if (tiosp->c_iflag & IXON) {
4245 mr0 |= MR0_SWFTX | MR0_SWFT;
4246 imron |= IR_XONXOFF;
4248 imroff |= IR_XONXOFF;
4250 if (tiosp->c_iflag & IXOFF)
4253 if (tiosp->c_cflag & CRTSCTS) {
4259 * All sc26198 register values calculated so go through and set
4263 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4264 portp->portnr, portp->panelnr, portp->brdnr);
4265 pr_debug(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4266 pr_debug(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4267 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4268 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4269 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4271 spin_lock_irqsave(&brd_lock, flags);
4272 BRDENABLE(portp->brdnr, portp->pagenr);
4273 stl_sc26198setreg(portp, IMR, 0);
4274 stl_sc26198updatereg(portp, MR0, mr0);
4275 stl_sc26198updatereg(portp, MR1, mr1);
4276 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4277 stl_sc26198updatereg(portp, MR2, mr2);
4278 stl_sc26198updatereg(portp, IOPIOR,
4279 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
4282 stl_sc26198setreg(portp, TXCSR, clk);
4283 stl_sc26198setreg(portp, RXCSR, clk);
4286 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4287 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4289 ipr = stl_sc26198getreg(portp, IPR);
4291 portp->sigs &= ~TIOCM_CD;
4293 portp->sigs |= TIOCM_CD;
4295 portp->imr = (portp->imr & ~imroff) | imron;
4296 stl_sc26198setreg(portp, IMR, portp->imr);
4297 BRDDISABLE(portp->brdnr);
4298 spin_unlock_irqrestore(&brd_lock, flags);
4301 /*****************************************************************************/
4304 * Set the state of the DTR and RTS signals.
4307 static void stl_sc26198setsignals(struct stlport *portp, int dtr, int rts)
4309 unsigned char iopioron, iopioroff;
4310 unsigned long flags;
4312 pr_debug("stl_sc26198setsignals(portp=%p,dtr=%d,rts=%d)\n", portp,
4318 iopioroff |= IPR_DTR;
4320 iopioron |= IPR_DTR;
4322 iopioroff |= IPR_RTS;
4324 iopioron |= IPR_RTS;
4326 spin_lock_irqsave(&brd_lock, flags);
4327 BRDENABLE(portp->brdnr, portp->pagenr);
4328 stl_sc26198setreg(portp, IOPIOR,
4329 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4330 BRDDISABLE(portp->brdnr);
4331 spin_unlock_irqrestore(&brd_lock, flags);
4334 /*****************************************************************************/
4337 * Return the state of the signals.
4340 static int stl_sc26198getsignals(struct stlport *portp)
4343 unsigned long flags;
4346 pr_debug("stl_sc26198getsignals(portp=%p)\n", portp);
4348 spin_lock_irqsave(&brd_lock, flags);
4349 BRDENABLE(portp->brdnr, portp->pagenr);
4350 ipr = stl_sc26198getreg(portp, IPR);
4351 BRDDISABLE(portp->brdnr);
4352 spin_unlock_irqrestore(&brd_lock, flags);
4355 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4356 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4357 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4358 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4363 /*****************************************************************************/
4366 * Enable/Disable the Transmitter and/or Receiver.
4369 static void stl_sc26198enablerxtx(struct stlport *portp, int rx, int tx)
4372 unsigned long flags;
4374 pr_debug("stl_sc26198enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx,tx);
4376 ccr = portp->crenable;
4378 ccr &= ~CR_TXENABLE;
4382 ccr &= ~CR_RXENABLE;
4386 spin_lock_irqsave(&brd_lock, flags);
4387 BRDENABLE(portp->brdnr, portp->pagenr);
4388 stl_sc26198setreg(portp, SCCR, ccr);
4389 BRDDISABLE(portp->brdnr);
4390 portp->crenable = ccr;
4391 spin_unlock_irqrestore(&brd_lock, flags);
4394 /*****************************************************************************/
4397 * Start/stop the Transmitter and/or Receiver.
4400 static void stl_sc26198startrxtx(struct stlport *portp, int rx, int tx)
4403 unsigned long flags;
4405 pr_debug("stl_sc26198startrxtx(portp=%p,rx=%d,tx=%d)\n", portp, rx, tx);
4413 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4415 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4417 spin_lock_irqsave(&brd_lock, flags);
4418 BRDENABLE(portp->brdnr, portp->pagenr);
4419 stl_sc26198setreg(portp, IMR, imr);
4420 BRDDISABLE(portp->brdnr);
4423 set_bit(ASYI_TXBUSY, &portp->istate);
4424 spin_unlock_irqrestore(&brd_lock, flags);
4427 /*****************************************************************************/
4430 * Disable all interrupts from this port.
4433 static void stl_sc26198disableintrs(struct stlport *portp)
4435 unsigned long flags;
4437 pr_debug("stl_sc26198disableintrs(portp=%p)\n", portp);
4439 spin_lock_irqsave(&brd_lock, flags);
4440 BRDENABLE(portp->brdnr, portp->pagenr);
4442 stl_sc26198setreg(portp, IMR, 0);
4443 BRDDISABLE(portp->brdnr);
4444 spin_unlock_irqrestore(&brd_lock, flags);
4447 /*****************************************************************************/
4449 static void stl_sc26198sendbreak(struct stlport *portp, int len)
4451 unsigned long flags;
4453 pr_debug("stl_sc26198sendbreak(portp=%p,len=%d)\n", portp, len);
4455 spin_lock_irqsave(&brd_lock, flags);
4456 BRDENABLE(portp->brdnr, portp->pagenr);
4458 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4459 portp->stats.txbreaks++;
4461 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4463 BRDDISABLE(portp->brdnr);
4464 spin_unlock_irqrestore(&brd_lock, flags);
4467 /*****************************************************************************/
4470 * Take flow control actions...
4473 static void stl_sc26198flowctrl(struct stlport *portp, int state)
4475 struct tty_struct *tty;
4476 unsigned long flags;
4479 pr_debug("stl_sc26198flowctrl(portp=%p,state=%x)\n", portp, state);
4487 spin_lock_irqsave(&brd_lock, flags);
4488 BRDENABLE(portp->brdnr, portp->pagenr);
4491 if (tty->termios->c_iflag & IXOFF) {
4492 mr0 = stl_sc26198getreg(portp, MR0);
4493 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4494 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4496 portp->stats.rxxon++;
4497 stl_sc26198wait(portp);
4498 stl_sc26198setreg(portp, MR0, mr0);
4501 * Question: should we return RTS to what it was before? It may
4502 * have been set by an ioctl... Suppose not, since if you have
4503 * hardware flow control set then it is pretty silly to go and
4504 * set the RTS line by hand.
4506 if (tty->termios->c_cflag & CRTSCTS) {
4507 stl_sc26198setreg(portp, MR1,
4508 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4509 stl_sc26198setreg(portp, IOPIOR,
4510 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4511 portp->stats.rxrtson++;
4514 if (tty->termios->c_iflag & IXOFF) {
4515 mr0 = stl_sc26198getreg(portp, MR0);
4516 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4517 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4519 portp->stats.rxxoff++;
4520 stl_sc26198wait(portp);
4521 stl_sc26198setreg(portp, MR0, mr0);
4523 if (tty->termios->c_cflag & CRTSCTS) {
4524 stl_sc26198setreg(portp, MR1,
4525 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4526 stl_sc26198setreg(portp, IOPIOR,
4527 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4528 portp->stats.rxrtsoff++;
4532 BRDDISABLE(portp->brdnr);
4533 spin_unlock_irqrestore(&brd_lock, flags);
4536 /*****************************************************************************/
4539 * Send a flow control character.
4542 static void stl_sc26198sendflow(struct stlport *portp, int state)
4544 struct tty_struct *tty;
4545 unsigned long flags;
4548 pr_debug("stl_sc26198sendflow(portp=%p,state=%x)\n", portp, state);
4556 spin_lock_irqsave(&brd_lock, flags);
4557 BRDENABLE(portp->brdnr, portp->pagenr);
4559 mr0 = stl_sc26198getreg(portp, MR0);
4560 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4561 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4563 portp->stats.rxxon++;
4564 stl_sc26198wait(portp);
4565 stl_sc26198setreg(portp, MR0, mr0);
4567 mr0 = stl_sc26198getreg(portp, MR0);
4568 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4569 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4571 portp->stats.rxxoff++;
4572 stl_sc26198wait(portp);
4573 stl_sc26198setreg(portp, MR0, mr0);
4575 BRDDISABLE(portp->brdnr);
4576 spin_unlock_irqrestore(&brd_lock, flags);
4579 /*****************************************************************************/
4581 static void stl_sc26198flush(struct stlport *portp)
4583 unsigned long flags;
4585 pr_debug("stl_sc26198flush(portp=%p)\n", portp);
4590 spin_lock_irqsave(&brd_lock, flags);
4591 BRDENABLE(portp->brdnr, portp->pagenr);
4592 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4593 stl_sc26198setreg(portp, SCCR, portp->crenable);
4594 BRDDISABLE(portp->brdnr);
4595 portp->tx.tail = portp->tx.head;
4596 spin_unlock_irqrestore(&brd_lock, flags);
4599 /*****************************************************************************/
4602 * Return the current state of data flow on this port. This is only
4603 * really interresting when determining if data has fully completed
4604 * transmission or not... The sc26198 interrupt scheme cannot
4605 * determine when all data has actually drained, so we need to
4606 * check the port statusy register to be sure.
4609 static int stl_sc26198datastate(struct stlport *portp)
4611 unsigned long flags;
4614 pr_debug("stl_sc26198datastate(portp=%p)\n", portp);
4618 if (test_bit(ASYI_TXBUSY, &portp->istate))
4621 spin_lock_irqsave(&brd_lock, flags);
4622 BRDENABLE(portp->brdnr, portp->pagenr);
4623 sr = stl_sc26198getreg(portp, SR);
4624 BRDDISABLE(portp->brdnr);
4625 spin_unlock_irqrestore(&brd_lock, flags);
4627 return (sr & SR_TXEMPTY) ? 0 : 1;
4630 /*****************************************************************************/
4633 * Delay for a small amount of time, to give the sc26198 a chance
4634 * to process a command...
4637 static void stl_sc26198wait(struct stlport *portp)
4641 pr_debug("stl_sc26198wait(portp=%p)\n", portp);
4646 for (i = 0; (i < 20); i++)
4647 stl_sc26198getglobreg(portp, TSTR);
4650 /*****************************************************************************/
4653 * If we are TX flow controlled and in IXANY mode then we may
4654 * need to unflow control here. We gotta do this because of the
4655 * automatic flow control modes of the sc26198.
4658 static inline void stl_sc26198txunflow(struct stlport *portp, struct tty_struct *tty)
4662 mr0 = stl_sc26198getreg(portp, MR0);
4663 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4664 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4665 stl_sc26198wait(portp);
4666 stl_sc26198setreg(portp, MR0, mr0);
4667 clear_bit(ASYI_TXFLOWED, &portp->istate);
4670 /*****************************************************************************/
4673 * Interrupt service routine for sc26198 panels.
4676 static void stl_sc26198intr(struct stlpanel *panelp, unsigned int iobase)
4678 struct stlport *portp;
4681 spin_lock(&brd_lock);
4684 * Work around bug in sc26198 chip... Cannot have A6 address
4685 * line of UART high, else iack will be returned as 0.
4687 outb(0, (iobase + 1));
4689 iack = inb(iobase + XP_IACK);
4690 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4692 if (iack & IVR_RXDATA)
4693 stl_sc26198rxisr(portp, iack);
4694 else if (iack & IVR_TXDATA)
4695 stl_sc26198txisr(portp);
4697 stl_sc26198otherisr(portp, iack);
4699 spin_unlock(&brd_lock);
4702 /*****************************************************************************/
4705 * Transmit interrupt handler. This has gotta be fast! Handling TX
4706 * chars is pretty simple, stuff as many as possible from the TX buffer
4707 * into the sc26198 FIFO.
4708 * In practice it is possible that interrupts are enabled but that the
4709 * port has been hung up. Need to handle not having any TX buffer here,
4710 * this is done by using the side effect that head and tail will also
4711 * be NULL if the buffer has been freed.
4714 static void stl_sc26198txisr(struct stlport *portp)
4716 unsigned int ioaddr;
4721 pr_debug("stl_sc26198txisr(portp=%p)\n", portp);
4723 ioaddr = portp->ioaddr;
4724 head = portp->tx.head;
4725 tail = portp->tx.tail;
4726 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4727 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4728 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4729 set_bit(ASYI_TXLOW, &portp->istate);
4730 schedule_work(&portp->tqueue);
4734 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
4735 mr0 = inb(ioaddr + XP_DATA);
4736 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4737 portp->imr &= ~IR_TXRDY;
4738 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
4739 outb(portp->imr, (ioaddr + XP_DATA));
4740 clear_bit(ASYI_TXBUSY, &portp->istate);
4742 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4743 outb(mr0, (ioaddr + XP_DATA));
4746 len = MIN(len, SC26198_TXFIFOSIZE);
4747 portp->stats.txtotal += len;
4748 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4749 outb(GTXFIFO, (ioaddr + XP_ADDR));
4750 outsb((ioaddr + XP_DATA), tail, stlen);
4753 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4754 tail = portp->tx.buf;
4756 outsb((ioaddr + XP_DATA), tail, len);
4759 portp->tx.tail = tail;
4763 /*****************************************************************************/
4766 * Receive character interrupt handler. Determine if we have good chars
4767 * or bad chars and then process appropriately. Good chars are easy
4768 * just shove the lot into the RX buffer and set all status byte to 0.
4769 * If a bad RX char then process as required. This routine needs to be
4770 * fast! In practice it is possible that we get an interrupt on a port
4771 * that is closed. This can happen on hangups - since they completely
4772 * shutdown a port not in user context. Need to handle this case.
4775 static void stl_sc26198rxisr(struct stlport *portp, unsigned int iack)
4777 struct tty_struct *tty;
4778 unsigned int len, buflen, ioaddr;
4780 pr_debug("stl_sc26198rxisr(portp=%p,iack=%x)\n", portp, iack);
4783 ioaddr = portp->ioaddr;
4784 outb(GIBCR, (ioaddr + XP_ADDR));
4785 len = inb(ioaddr + XP_DATA) + 1;
4787 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
4788 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
4789 len = MIN(len, sizeof(stl_unwanted));
4790 outb(GRXFIFO, (ioaddr + XP_ADDR));
4791 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4792 portp->stats.rxlost += len;
4793 portp->stats.rxtotal += len;
4795 len = MIN(len, buflen);
4798 outb(GRXFIFO, (ioaddr + XP_ADDR));
4799 tty_prepare_flip_string(tty, &ptr, len);
4800 insb((ioaddr + XP_DATA), ptr, len);
4801 tty_schedule_flip(tty);
4802 portp->stats.rxtotal += len;
4806 stl_sc26198rxbadchars(portp);
4810 * If we are TX flow controlled and in IXANY mode then we may need
4811 * to unflow control here. We gotta do this because of the automatic
4812 * flow control modes of the sc26198.
4814 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
4815 if ((tty != NULL) &&
4816 (tty->termios != NULL) &&
4817 (tty->termios->c_iflag & IXANY)) {
4818 stl_sc26198txunflow(portp, tty);
4823 /*****************************************************************************/
4826 * Process an RX bad character.
4829 static inline void stl_sc26198rxbadch(struct stlport *portp, unsigned char status, char ch)
4831 struct tty_struct *tty;
4832 unsigned int ioaddr;
4835 ioaddr = portp->ioaddr;
4837 if (status & SR_RXPARITY)
4838 portp->stats.rxparity++;
4839 if (status & SR_RXFRAMING)
4840 portp->stats.rxframing++;
4841 if (status & SR_RXOVERRUN)
4842 portp->stats.rxoverrun++;
4843 if (status & SR_RXBREAK)
4844 portp->stats.rxbreaks++;
4846 if ((tty != NULL) &&
4847 ((portp->rxignoremsk & status) == 0)) {
4848 if (portp->rxmarkmsk & status) {
4849 if (status & SR_RXBREAK) {
4851 if (portp->flags & ASYNC_SAK) {
4853 BRDENABLE(portp->brdnr, portp->pagenr);
4855 } else if (status & SR_RXPARITY) {
4856 status = TTY_PARITY;
4857 } else if (status & SR_RXFRAMING) {
4859 } else if(status & SR_RXOVERRUN) {
4860 status = TTY_OVERRUN;
4868 tty_insert_flip_char(tty, ch, status);
4869 tty_schedule_flip(tty);
4872 portp->stats.rxtotal++;
4876 /*****************************************************************************/
4879 * Process all characters in the RX FIFO of the UART. Check all char
4880 * status bytes as well, and process as required. We need to check
4881 * all bytes in the FIFO, in case some more enter the FIFO while we
4882 * are here. To get the exact character error type we need to switch
4883 * into CHAR error mode (that is why we need to make sure we empty
4887 static void stl_sc26198rxbadchars(struct stlport *portp)
4889 unsigned char status, mr1;
4893 * To get the precise error type for each character we must switch
4894 * back into CHAR error mode.
4896 mr1 = stl_sc26198getreg(portp, MR1);
4897 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
4899 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
4900 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
4901 ch = stl_sc26198getreg(portp, RXFIFO);
4902 stl_sc26198rxbadch(portp, status, ch);
4906 * To get correct interrupt class we must switch back into BLOCK
4909 stl_sc26198setreg(portp, MR1, mr1);
4912 /*****************************************************************************/
4915 * Other interrupt handler. This includes modem signals, flow
4916 * control actions, etc. Most stuff is left to off-level interrupt
4920 static void stl_sc26198otherisr(struct stlport *portp, unsigned int iack)
4922 unsigned char cir, ipr, xisr;
4924 pr_debug("stl_sc26198otherisr(portp=%p,iack=%x)\n", portp, iack);
4926 cir = stl_sc26198getglobreg(portp, CIR);
4928 switch (cir & CIR_SUBTYPEMASK) {
4930 ipr = stl_sc26198getreg(portp, IPR);
4931 if (ipr & IPR_DCDCHANGE) {
4932 set_bit(ASYI_DCDCHANGE, &portp->istate);
4933 schedule_work(&portp->tqueue);
4934 portp->stats.modem++;
4937 case CIR_SUBXONXOFF:
4938 xisr = stl_sc26198getreg(portp, XISR);
4939 if (xisr & XISR_RXXONGOT) {
4940 set_bit(ASYI_TXFLOWED, &portp->istate);
4941 portp->stats.txxoff++;
4943 if (xisr & XISR_RXXOFFGOT) {
4944 clear_bit(ASYI_TXFLOWED, &portp->istate);
4945 portp->stats.txxon++;
4949 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
4950 stl_sc26198rxbadchars(portp);
4957 /*****************************************************************************/