1 /*****************************************************************************/
4 * stallion.c -- stallion multiport serial driver.
6 * Copyright (C) 1996-1999 Stallion Technologies
7 * Copyright (C) 1994-1996 Greg Ungerer.
9 * This code is loosely based on the Linux serial driver, written by
10 * Linus Torvalds, Theodore T'so and others.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /*****************************************************************************/
29 #include <linux/config.h>
30 #include <linux/module.h>
31 #include <linux/slab.h>
32 #include <linux/interrupt.h>
33 #include <linux/tty.h>
34 #include <linux/tty_flip.h>
35 #include <linux/serial.h>
36 #include <linux/cd1400.h>
37 #include <linux/sc26198.h>
38 #include <linux/comstats.h>
39 #include <linux/stallion.h>
40 #include <linux/ioport.h>
41 #include <linux/init.h>
42 #include <linux/smp_lock.h>
43 #include <linux/devfs_fs_kernel.h>
44 #include <linux/device.h>
45 #include <linux/delay.h>
48 #include <asm/uaccess.h>
51 #include <linux/pci.h>
54 /*****************************************************************************/
57 * Define different board types. Use the standard Stallion "assigned"
58 * board numbers. Boards supported in this driver are abbreviated as
59 * EIO = EasyIO and ECH = EasyConnection 8/32.
65 #define BRD_ECH64PCI 27
66 #define BRD_EASYIOPCI 28
69 * Define a configuration structure to hold the board configuration.
70 * Need to set this up in the code (for now) with the boards that are
71 * to be configured into the system. This is what needs to be modified
72 * when adding/removing/modifying boards. Each line entry in the
73 * stl_brdconf[] array is a board. Each line contains io/irq/memory
74 * ranges for that board (as well as what type of board it is).
76 * { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
77 * This line would configure an EasyIO board (4 or 8, no difference),
78 * at io address 2a0 and irq 10.
80 * { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
81 * This line will configure an EasyConnection 8/32 board at primary io
82 * address 2a8, secondary io address 280 and irq 12.
83 * Enter as many lines into this array as you want (only the first 4
84 * will actually be used!). Any combination of EasyIO and EasyConnection
85 * boards can be specified. EasyConnection 8/32 boards can share their
86 * secondary io addresses between each other.
88 * NOTE: there is no need to put any entries in this table for PCI
89 * boards. They will be found automatically by the driver - provided
90 * PCI BIOS32 support is compiled into the kernel.
97 unsigned long memaddr;
102 static stlconf_t stl_brdconf[] = {
103 /*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
106 static int stl_nrbrds = sizeof(stl_brdconf) / sizeof(stlconf_t);
108 /*****************************************************************************/
111 * Define some important driver characteristics. Device major numbers
112 * allocated as per Linux Device Registry.
114 #ifndef STL_SIOMEMMAJOR
115 #define STL_SIOMEMMAJOR 28
117 #ifndef STL_SERIALMAJOR
118 #define STL_SERIALMAJOR 24
120 #ifndef STL_CALLOUTMAJOR
121 #define STL_CALLOUTMAJOR 25
125 * Set the TX buffer size. Bigger is better, but we don't want
126 * to chew too much memory with buffers!
128 #define STL_TXBUFLOW 512
129 #define STL_TXBUFSIZE 4096
131 /*****************************************************************************/
134 * Define our local driver identity first. Set up stuff to deal with
135 * all the local structures required by a serial tty driver.
137 static char *stl_drvtitle = "Stallion Multiport Serial Driver";
138 static char *stl_drvname = "stallion";
139 static char *stl_drvversion = "5.6.0";
141 static struct tty_driver *stl_serial;
144 * We will need to allocate a temporary write buffer for chars that
145 * come direct from user space. The problem is that a copy from user
146 * space might cause a page fault (typically on a system that is
147 * swapping!). All ports will share one buffer - since if the system
148 * is already swapping a shared buffer won't make things any worse.
150 static char *stl_tmpwritebuf;
151 static DECLARE_MUTEX(stl_tmpwritesem);
154 * Define a local default termios struct. All ports will be created
155 * with this termios initially. Basically all it defines is a raw port
156 * at 9600, 8 data bits, 1 stop bit.
158 static struct termios stl_deftermios = {
159 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
164 * Define global stats structures. Not used often, and can be
165 * re-used for each stats call.
167 static comstats_t stl_comstats;
168 static combrd_t stl_brdstats;
169 static stlbrd_t stl_dummybrd;
170 static stlport_t stl_dummyport;
173 * Define global place to put buffer overflow characters.
175 static char stl_unwanted[SC26198_RXFIFOSIZE];
177 /*****************************************************************************/
179 static stlbrd_t *stl_brds[STL_MAXBRDS];
182 * Per board state flags. Used with the state field of the board struct.
183 * Not really much here!
185 #define BRD_FOUND 0x1
188 * Define the port structure istate flags. These set of flags are
189 * modified at interrupt time - so setting and reseting them needs
190 * to be atomic. Use the bit clear/setting routines for this.
192 #define ASYI_TXBUSY 1
194 #define ASYI_DCDCHANGE 3
195 #define ASYI_TXFLOWED 4
198 * Define an array of board names as printable strings. Handy for
199 * referencing boards when printing trace and stuff.
201 static char *stl_brdnames[] = {
233 /*****************************************************************************/
237 * Define some string labels for arguments passed from the module
238 * load line. These allow for easy board definitions, and easy
239 * modification of the io, memory and irq resoucres.
242 static char *board0[4];
243 static char *board1[4];
244 static char *board2[4];
245 static char *board3[4];
247 static char **stl_brdsp[] = {
255 * Define a set of common board names, and types. This is used to
256 * parse any module arguments.
259 typedef struct stlbrdtype {
264 static stlbrdtype_t stl_brdstr[] = {
265 { "easyio", BRD_EASYIO },
266 { "eio", BRD_EASYIO },
267 { "20", BRD_EASYIO },
268 { "ec8/32", BRD_ECH },
269 { "ec8/32-at", BRD_ECH },
270 { "ec8/32-isa", BRD_ECH },
272 { "echat", BRD_ECH },
274 { "ec8/32-mc", BRD_ECHMC },
275 { "ec8/32-mca", BRD_ECHMC },
276 { "echmc", BRD_ECHMC },
277 { "echmca", BRD_ECHMC },
279 { "ec8/32-pc", BRD_ECHPCI },
280 { "ec8/32-pci", BRD_ECHPCI },
281 { "26", BRD_ECHPCI },
282 { "ec8/64-pc", BRD_ECH64PCI },
283 { "ec8/64-pci", BRD_ECH64PCI },
284 { "ech-pci", BRD_ECH64PCI },
285 { "echpci", BRD_ECH64PCI },
286 { "echpc", BRD_ECH64PCI },
287 { "27", BRD_ECH64PCI },
288 { "easyio-pc", BRD_EASYIOPCI },
289 { "easyio-pci", BRD_EASYIOPCI },
290 { "eio-pci", BRD_EASYIOPCI },
291 { "eiopci", BRD_EASYIOPCI },
292 { "28", BRD_EASYIOPCI },
296 * Define the module agruments.
298 MODULE_AUTHOR("Greg Ungerer");
299 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
300 MODULE_LICENSE("GPL");
302 MODULE_PARM(board0, "1-4s");
303 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
304 MODULE_PARM(board1, "1-4s");
305 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
306 MODULE_PARM(board2, "1-4s");
307 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
308 MODULE_PARM(board3, "1-4s");
309 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
313 /*****************************************************************************/
316 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
317 * to the directly accessible io ports of these boards (not the uarts -
318 * they are in cd1400.h and sc26198.h).
320 #define EIO_8PORTRS 0x04
321 #define EIO_4PORTRS 0x05
322 #define EIO_8PORTDI 0x00
323 #define EIO_8PORTM 0x06
325 #define EIO_IDBITMASK 0x07
327 #define EIO_BRDMASK 0xf0
330 #define ID_BRD16 0x30
332 #define EIO_INTRPEND 0x08
333 #define EIO_INTEDGE 0x00
334 #define EIO_INTLEVEL 0x08
338 #define ECH_IDBITMASK 0xe0
339 #define ECH_BRDENABLE 0x08
340 #define ECH_BRDDISABLE 0x00
341 #define ECH_INTENABLE 0x01
342 #define ECH_INTDISABLE 0x00
343 #define ECH_INTLEVEL 0x02
344 #define ECH_INTEDGE 0x00
345 #define ECH_INTRPEND 0x01
346 #define ECH_BRDRESET 0x01
348 #define ECHMC_INTENABLE 0x01
349 #define ECHMC_BRDRESET 0x02
351 #define ECH_PNLSTATUS 2
352 #define ECH_PNL16PORT 0x20
353 #define ECH_PNLIDMASK 0x07
354 #define ECH_PNLXPID 0x40
355 #define ECH_PNLINTRPEND 0x80
357 #define ECH_ADDR2MASK 0x1e0
360 * Define the vector mapping bits for the programmable interrupt board
361 * hardware. These bits encode the interrupt for the board to use - it
362 * is software selectable (except the EIO-8M).
364 static unsigned char stl_vecmap[] = {
365 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
366 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
370 * Set up enable and disable macros for the ECH boards. They require
371 * the secondary io address space to be activated and deactivated.
372 * This way all ECH boards can share their secondary io region.
373 * If this is an ECH-PCI board then also need to set the page pointer
374 * to point to the correct page.
376 #define BRDENABLE(brdnr,pagenr) \
377 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
378 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
379 stl_brds[(brdnr)]->ioctrl); \
380 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
381 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
383 #define BRDDISABLE(brdnr) \
384 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
385 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
386 stl_brds[(brdnr)]->ioctrl);
388 #define STL_CD1400MAXBAUD 230400
389 #define STL_SC26198MAXBAUD 460800
391 #define STL_BAUDBASE 115200
392 #define STL_CLOSEDELAY (5 * HZ / 10)
394 /*****************************************************************************/
399 * Define the Stallion PCI vendor and device IDs.
401 #ifndef PCI_VENDOR_ID_STALLION
402 #define PCI_VENDOR_ID_STALLION 0x124d
404 #ifndef PCI_DEVICE_ID_ECHPCI832
405 #define PCI_DEVICE_ID_ECHPCI832 0x0000
407 #ifndef PCI_DEVICE_ID_ECHPCI864
408 #define PCI_DEVICE_ID_ECHPCI864 0x0002
410 #ifndef PCI_DEVICE_ID_EIOPCI
411 #define PCI_DEVICE_ID_EIOPCI 0x0003
415 * Define structure to hold all Stallion PCI boards.
417 typedef struct stlpcibrd {
418 unsigned short vendid;
419 unsigned short devid;
423 static stlpcibrd_t stl_pcibrds[] = {
424 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864, BRD_ECH64PCI },
425 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI, BRD_EASYIOPCI },
426 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832, BRD_ECHPCI },
427 { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
430 static int stl_nrpcibrds = sizeof(stl_pcibrds) / sizeof(stlpcibrd_t);
434 /*****************************************************************************/
437 * Define macros to extract a brd/port number from a minor number.
439 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
440 #define MINOR2PORT(min) ((min) & 0x3f)
443 * Define a baud rate table that converts termios baud rate selector
444 * into the actual baud rate value. All baud rate calculations are
445 * based on the actual baud rate required.
447 static unsigned int stl_baudrates[] = {
448 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
449 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
453 * Define some handy local macros...
456 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
459 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
461 /*****************************************************************************/
464 * Declare all those functions in this driver!
468 static void stl_argbrds(void);
469 static int stl_parsebrd(stlconf_t *confp, char **argp);
471 static unsigned long stl_atol(char *str);
475 static int stl_open(struct tty_struct *tty, struct file *filp);
476 static void stl_close(struct tty_struct *tty, struct file *filp);
477 static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count);
478 static void stl_putchar(struct tty_struct *tty, unsigned char ch);
479 static void stl_flushchars(struct tty_struct *tty);
480 static int stl_writeroom(struct tty_struct *tty);
481 static int stl_charsinbuffer(struct tty_struct *tty);
482 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
483 static void stl_settermios(struct tty_struct *tty, struct termios *old);
484 static void stl_throttle(struct tty_struct *tty);
485 static void stl_unthrottle(struct tty_struct *tty);
486 static void stl_stop(struct tty_struct *tty);
487 static void stl_start(struct tty_struct *tty);
488 static void stl_flushbuffer(struct tty_struct *tty);
489 static void stl_breakctl(struct tty_struct *tty, int state);
490 static void stl_waituntilsent(struct tty_struct *tty, int timeout);
491 static void stl_sendxchar(struct tty_struct *tty, char ch);
492 static void stl_hangup(struct tty_struct *tty);
493 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
494 static int stl_portinfo(stlport_t *portp, int portnr, char *pos);
495 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data);
497 static int stl_brdinit(stlbrd_t *brdp);
498 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
499 static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp);
500 static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp);
501 static int stl_getbrdstats(combrd_t __user *bp);
502 static int stl_getportstats(stlport_t *portp, comstats_t __user *cp);
503 static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp);
504 static int stl_getportstruct(stlport_t __user *arg);
505 static int stl_getbrdstruct(stlbrd_t __user *arg);
506 static int stl_waitcarrier(stlport_t *portp, struct file *filp);
507 static int stl_eiointr(stlbrd_t *brdp);
508 static int stl_echatintr(stlbrd_t *brdp);
509 static int stl_echmcaintr(stlbrd_t *brdp);
510 static int stl_echpciintr(stlbrd_t *brdp);
511 static int stl_echpci64intr(stlbrd_t *brdp);
512 static void stl_offintr(void *private);
513 static void *stl_memalloc(int len);
514 static stlbrd_t *stl_allocbrd(void);
515 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
517 static inline int stl_initbrds(void);
518 static inline int stl_initeio(stlbrd_t *brdp);
519 static inline int stl_initech(stlbrd_t *brdp);
520 static inline int stl_getbrdnr(void);
523 static inline int stl_findpcibrds(void);
524 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp);
528 * CD1400 uart specific handling functions.
530 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value);
531 static int stl_cd1400getreg(stlport_t *portp, int regnr);
532 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value);
533 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
534 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
535 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp);
536 static int stl_cd1400getsignals(stlport_t *portp);
537 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts);
538 static void stl_cd1400ccrwait(stlport_t *portp);
539 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx);
540 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx);
541 static void stl_cd1400disableintrs(stlport_t *portp);
542 static void stl_cd1400sendbreak(stlport_t *portp, int len);
543 static void stl_cd1400flowctrl(stlport_t *portp, int state);
544 static void stl_cd1400sendflow(stlport_t *portp, int state);
545 static void stl_cd1400flush(stlport_t *portp);
546 static int stl_cd1400datastate(stlport_t *portp);
547 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase);
548 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase);
549 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr);
550 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr);
551 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr);
553 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr);
556 * SC26198 uart specific handling functions.
558 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value);
559 static int stl_sc26198getreg(stlport_t *portp, int regnr);
560 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value);
561 static int stl_sc26198getglobreg(stlport_t *portp, int regnr);
562 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
563 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
564 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp);
565 static int stl_sc26198getsignals(stlport_t *portp);
566 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts);
567 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx);
568 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx);
569 static void stl_sc26198disableintrs(stlport_t *portp);
570 static void stl_sc26198sendbreak(stlport_t *portp, int len);
571 static void stl_sc26198flowctrl(stlport_t *portp, int state);
572 static void stl_sc26198sendflow(stlport_t *portp, int state);
573 static void stl_sc26198flush(stlport_t *portp);
574 static int stl_sc26198datastate(stlport_t *portp);
575 static void stl_sc26198wait(stlport_t *portp);
576 static void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty);
577 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase);
578 static void stl_sc26198txisr(stlport_t *port);
579 static void stl_sc26198rxisr(stlport_t *port, unsigned int iack);
580 static void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch);
581 static void stl_sc26198rxbadchars(stlport_t *portp);
582 static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
584 /*****************************************************************************/
587 * Generic UART support structure.
589 typedef struct uart {
590 int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp);
591 void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
592 void (*setport)(stlport_t *portp, struct termios *tiosp);
593 int (*getsignals)(stlport_t *portp);
594 void (*setsignals)(stlport_t *portp, int dtr, int rts);
595 void (*enablerxtx)(stlport_t *portp, int rx, int tx);
596 void (*startrxtx)(stlport_t *portp, int rx, int tx);
597 void (*disableintrs)(stlport_t *portp);
598 void (*sendbreak)(stlport_t *portp, int len);
599 void (*flowctrl)(stlport_t *portp, int state);
600 void (*sendflow)(stlport_t *portp, int state);
601 void (*flush)(stlport_t *portp);
602 int (*datastate)(stlport_t *portp);
603 void (*intr)(stlpanel_t *panelp, unsigned int iobase);
607 * Define some macros to make calling these functions nice and clean.
609 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
610 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
611 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
612 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
613 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
614 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
615 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
616 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
617 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
618 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
619 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
620 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
621 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
623 /*****************************************************************************/
626 * CD1400 UART specific data initialization.
628 static uart_t stl_cd1400uart = {
632 stl_cd1400getsignals,
633 stl_cd1400setsignals,
634 stl_cd1400enablerxtx,
636 stl_cd1400disableintrs,
646 * Define the offsets within the register bank of a cd1400 based panel.
647 * These io address offsets are common to the EasyIO board as well.
655 #define EREG_BANKSIZE 8
657 #define CD1400_CLK 25000000
658 #define CD1400_CLK8M 20000000
661 * Define the cd1400 baud rate clocks. These are used when calculating
662 * what clock and divisor to use for the required baud rate. Also
663 * define the maximum baud rate allowed, and the default base baud.
665 static int stl_cd1400clkdivs[] = {
666 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
669 /*****************************************************************************/
672 * SC26198 UART specific data initization.
674 static uart_t stl_sc26198uart = {
675 stl_sc26198panelinit,
678 stl_sc26198getsignals,
679 stl_sc26198setsignals,
680 stl_sc26198enablerxtx,
681 stl_sc26198startrxtx,
682 stl_sc26198disableintrs,
683 stl_sc26198sendbreak,
687 stl_sc26198datastate,
692 * Define the offsets within the register bank of a sc26198 based panel.
700 #define XP_BANKSIZE 4
703 * Define the sc26198 baud rate table. Offsets within the table
704 * represent the actual baud rate selector of sc26198 registers.
706 static unsigned int sc26198_baudtable[] = {
707 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
708 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
709 230400, 460800, 921600
712 #define SC26198_NRBAUDS (sizeof(sc26198_baudtable) / sizeof(unsigned int))
714 /*****************************************************************************/
717 * Define the driver info for a user level control device. Used mainly
718 * to get at port stats - only not using the port device itself.
720 static struct file_operations stl_fsiomem = {
721 .owner = THIS_MODULE,
722 .ioctl = stl_memioctl,
725 /*****************************************************************************/
727 static struct class_simple *stallion_class;
732 * Loadable module initialization stuff.
735 static int __init stallion_module_init(void)
740 printk("init_module()\n");
746 restore_flags(flags);
751 /*****************************************************************************/
753 static void __exit stallion_module_exit(void)
762 printk("cleanup_module()\n");
765 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
772 * Free up all allocated resources used by the ports. This includes
773 * memory and interrupts. As part of this process we will also do
774 * a hangup on every open port - to try to flush out any processes
775 * hanging onto ports.
777 i = tty_unregister_driver(stl_serial);
778 put_tty_driver(stl_serial);
780 printk("STALLION: failed to un-register tty driver, "
782 restore_flags(flags);
785 for (i = 0; i < 4; i++) {
786 devfs_remove("staliomem/%d", i);
787 class_simple_device_remove(MKDEV(STL_SIOMEMMAJOR, i));
789 devfs_remove("staliomem");
790 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
791 printk("STALLION: failed to un-register serial memory device, "
793 class_simple_destroy(stallion_class);
795 if (stl_tmpwritebuf != (char *) NULL)
796 kfree(stl_tmpwritebuf);
798 for (i = 0; (i < stl_nrbrds); i++) {
799 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
802 free_irq(brdp->irq, brdp);
804 for (j = 0; (j < STL_MAXPANELS); j++) {
805 panelp = brdp->panels[j];
806 if (panelp == (stlpanel_t *) NULL)
808 for (k = 0; (k < STL_PORTSPERPANEL); k++) {
809 portp = panelp->ports[k];
810 if (portp == (stlport_t *) NULL)
812 if (portp->tty != (struct tty_struct *) NULL)
813 stl_hangup(portp->tty);
814 if (portp->tx.buf != (char *) NULL)
815 kfree(portp->tx.buf);
821 release_region(brdp->ioaddr1, brdp->iosize1);
822 if (brdp->iosize2 > 0)
823 release_region(brdp->ioaddr2, brdp->iosize2);
826 stl_brds[i] = (stlbrd_t *) NULL;
829 restore_flags(flags);
832 module_init(stallion_module_init);
833 module_exit(stallion_module_exit);
835 /*****************************************************************************/
838 * Check for any arguments passed in on the module load command line.
841 static void stl_argbrds(void)
848 printk("stl_argbrds()\n");
851 nrargs = sizeof(stl_brdsp) / sizeof(char **);
853 for (i = stl_nrbrds; (i < nrargs); i++) {
854 memset(&conf, 0, sizeof(conf));
855 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
857 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
861 brdp->brdtype = conf.brdtype;
862 brdp->ioaddr1 = conf.ioaddr1;
863 brdp->ioaddr2 = conf.ioaddr2;
864 brdp->irq = conf.irq;
865 brdp->irqtype = conf.irqtype;
870 /*****************************************************************************/
873 * Convert an ascii string number into an unsigned long.
876 static unsigned long stl_atol(char *str)
884 if ((*sp == '0') && (*(sp+1) == 'x')) {
887 } else if (*sp == '0') {
894 for (; (*sp != 0); sp++) {
895 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
896 if ((c < 0) || (c >= base)) {
897 printk("STALLION: invalid argument %s\n", str);
901 val = (val * base) + c;
906 /*****************************************************************************/
909 * Parse the supplied argument string, into the board conf struct.
912 static int stl_parsebrd(stlconf_t *confp, char **argp)
918 printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
921 if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
924 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
927 nrbrdnames = sizeof(stl_brdstr) / sizeof(stlbrdtype_t);
928 for (i = 0; (i < nrbrdnames); i++) {
929 if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
932 if (i >= nrbrdnames) {
933 printk("STALLION: unknown board name, %s?\n", argp[0]);
937 confp->brdtype = stl_brdstr[i].type;
940 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
941 confp->ioaddr1 = stl_atol(argp[i]);
943 if (confp->brdtype == BRD_ECH) {
944 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
945 confp->ioaddr2 = stl_atol(argp[i]);
948 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
949 confp->irq = stl_atol(argp[i]);
955 /*****************************************************************************/
958 * Local driver kernel memory allocation routine.
961 static void *stl_memalloc(int len)
963 return((void *) kmalloc(len, GFP_KERNEL));
966 /*****************************************************************************/
969 * Allocate a new board structure. Fill out the basic info in it.
972 static stlbrd_t *stl_allocbrd(void)
976 brdp = (stlbrd_t *) stl_memalloc(sizeof(stlbrd_t));
977 if (brdp == (stlbrd_t *) NULL) {
978 printk("STALLION: failed to allocate memory (size=%d)\n",
980 return((stlbrd_t *) NULL);
983 memset(brdp, 0, sizeof(stlbrd_t));
984 brdp->magic = STL_BOARDMAGIC;
988 /*****************************************************************************/
990 static int stl_open(struct tty_struct *tty, struct file *filp)
994 unsigned int minordev;
995 int brdnr, panelnr, portnr, rc;
998 printk("stl_open(tty=%x,filp=%x): device=%s\n", (int) tty,
999 (int) filp, tty->name);
1002 minordev = tty->index;
1003 brdnr = MINOR2BRD(minordev);
1004 if (brdnr >= stl_nrbrds)
1006 brdp = stl_brds[brdnr];
1007 if (brdp == (stlbrd_t *) NULL)
1009 minordev = MINOR2PORT(minordev);
1010 for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
1011 if (brdp->panels[panelnr] == (stlpanel_t *) NULL)
1013 if (minordev < brdp->panels[panelnr]->nrports) {
1017 minordev -= brdp->panels[panelnr]->nrports;
1022 portp = brdp->panels[panelnr]->ports[portnr];
1023 if (portp == (stlport_t *) NULL)
1027 * On the first open of the device setup the port hardware, and
1028 * initialize the per port data structure.
1031 tty->driver_data = portp;
1034 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
1035 if (portp->tx.buf == (char *) NULL) {
1036 portp->tx.buf = (char *) stl_memalloc(STL_TXBUFSIZE);
1037 if (portp->tx.buf == (char *) NULL)
1039 portp->tx.head = portp->tx.buf;
1040 portp->tx.tail = portp->tx.buf;
1042 stl_setport(portp, tty->termios);
1043 portp->sigs = stl_getsignals(portp);
1044 stl_setsignals(portp, 1, 1);
1045 stl_enablerxtx(portp, 1, 1);
1046 stl_startrxtx(portp, 1, 0);
1047 clear_bit(TTY_IO_ERROR, &tty->flags);
1048 portp->flags |= ASYNC_INITIALIZED;
1052 * Check if this port is in the middle of closing. If so then wait
1053 * until it is closed then return error status, based on flag settings.
1054 * The sleep here does not need interrupt protection since the wakeup
1055 * for it is done with the same context.
1057 if (portp->flags & ASYNC_CLOSING) {
1058 interruptible_sleep_on(&portp->close_wait);
1059 if (portp->flags & ASYNC_HUP_NOTIFY)
1061 return(-ERESTARTSYS);
1065 * Based on type of open being done check if it can overlap with any
1066 * previous opens still in effect. If we are a normal serial device
1067 * then also we might have to wait for carrier.
1069 if (!(filp->f_flags & O_NONBLOCK)) {
1070 if ((rc = stl_waitcarrier(portp, filp)) != 0)
1073 portp->flags |= ASYNC_NORMAL_ACTIVE;
1078 /*****************************************************************************/
1081 * Possibly need to wait for carrier (DCD signal) to come high. Say
1082 * maybe because if we are clocal then we don't need to wait...
1085 static int stl_waitcarrier(stlport_t *portp, struct file *filp)
1087 unsigned long flags;
1091 printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp, (int) filp);
1097 if (portp->tty->termios->c_cflag & CLOCAL)
1102 portp->openwaitcnt++;
1103 if (! tty_hung_up_p(filp))
1107 stl_setsignals(portp, 1, 1);
1108 if (tty_hung_up_p(filp) ||
1109 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1110 if (portp->flags & ASYNC_HUP_NOTIFY)
1116 if (((portp->flags & ASYNC_CLOSING) == 0) &&
1117 (doclocal || (portp->sigs & TIOCM_CD))) {
1120 if (signal_pending(current)) {
1124 interruptible_sleep_on(&portp->open_wait);
1127 if (! tty_hung_up_p(filp))
1129 portp->openwaitcnt--;
1130 restore_flags(flags);
1135 /*****************************************************************************/
1137 static void stl_close(struct tty_struct *tty, struct file *filp)
1140 unsigned long flags;
1143 printk("stl_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
1146 portp = tty->driver_data;
1147 if (portp == (stlport_t *) NULL)
1152 if (tty_hung_up_p(filp)) {
1153 restore_flags(flags);
1156 if ((tty->count == 1) && (portp->refcount != 1))
1157 portp->refcount = 1;
1158 if (portp->refcount-- > 1) {
1159 restore_flags(flags);
1163 portp->refcount = 0;
1164 portp->flags |= ASYNC_CLOSING;
1167 * May want to wait for any data to drain before closing. The BUSY
1168 * flag keeps track of whether we are still sending or not - it is
1169 * very accurate for the cd1400, not quite so for the sc26198.
1170 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1173 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1174 tty_wait_until_sent(tty, portp->closing_wait);
1175 stl_waituntilsent(tty, (HZ / 2));
1177 portp->flags &= ~ASYNC_INITIALIZED;
1178 stl_disableintrs(portp);
1179 if (tty->termios->c_cflag & HUPCL)
1180 stl_setsignals(portp, 0, 0);
1181 stl_enablerxtx(portp, 0, 0);
1182 stl_flushbuffer(tty);
1184 if (portp->tx.buf != (char *) NULL) {
1185 kfree(portp->tx.buf);
1186 portp->tx.buf = (char *) NULL;
1187 portp->tx.head = (char *) NULL;
1188 portp->tx.tail = (char *) NULL;
1190 set_bit(TTY_IO_ERROR, &tty->flags);
1191 tty_ldisc_flush(tty);
1194 portp->tty = (struct tty_struct *) NULL;
1196 if (portp->openwaitcnt) {
1197 if (portp->close_delay)
1198 msleep_interruptible(jiffies_to_msecs(portp->close_delay));
1199 wake_up_interruptible(&portp->open_wait);
1202 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1203 wake_up_interruptible(&portp->close_wait);
1204 restore_flags(flags);
1207 /*****************************************************************************/
1210 * Write routine. Take data and stuff it in to the TX ring queue.
1211 * If transmit interrupts are not running then start them.
1214 static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
1217 unsigned int len, stlen;
1218 unsigned char *chbuf;
1222 printk("stl_write(tty=%x,buf=%x,count=%d)\n",
1223 (int) tty, (int) buf, count);
1226 if ((tty == (struct tty_struct *) NULL) ||
1227 (stl_tmpwritebuf == (char *) NULL))
1229 portp = tty->driver_data;
1230 if (portp == (stlport_t *) NULL)
1232 if (portp->tx.buf == (char *) NULL)
1236 * If copying direct from user space we must cater for page faults,
1237 * causing us to "sleep" here for a while. To handle this copy in all
1238 * the data we need now, into a local buffer. Then when we got it all
1239 * copy it into the TX buffer.
1241 chbuf = (unsigned char *) buf;
1243 head = portp->tx.head;
1244 tail = portp->tx.tail;
1246 len = STL_TXBUFSIZE - (head - tail) - 1;
1247 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
1249 len = tail - head - 1;
1253 len = MIN(len, count);
1256 stlen = MIN(len, stlen);
1257 memcpy(head, chbuf, stlen);
1262 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
1263 head = portp->tx.buf;
1264 stlen = tail - head;
1267 portp->tx.head = head;
1269 clear_bit(ASYI_TXLOW, &portp->istate);
1270 stl_startrxtx(portp, -1, 1);
1275 /*****************************************************************************/
1277 static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1284 printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1287 if (tty == (struct tty_struct *) NULL)
1289 portp = tty->driver_data;
1290 if (portp == (stlport_t *) NULL)
1292 if (portp->tx.buf == (char *) NULL)
1295 head = portp->tx.head;
1296 tail = portp->tx.tail;
1298 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
1303 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
1304 head = portp->tx.buf;
1306 portp->tx.head = head;
1309 /*****************************************************************************/
1312 * If there are any characters in the buffer then make sure that TX
1313 * interrupts are on and get'em out. Normally used after the putchar
1314 * routine has been called.
1317 static void stl_flushchars(struct tty_struct *tty)
1322 printk("stl_flushchars(tty=%x)\n", (int) tty);
1325 if (tty == (struct tty_struct *) NULL)
1327 portp = tty->driver_data;
1328 if (portp == (stlport_t *) NULL)
1330 if (portp->tx.buf == (char *) NULL)
1334 if (tty->stopped || tty->hw_stopped ||
1335 (portp->tx.head == portp->tx.tail))
1338 stl_startrxtx(portp, -1, 1);
1341 /*****************************************************************************/
1343 static int stl_writeroom(struct tty_struct *tty)
1349 printk("stl_writeroom(tty=%x)\n", (int) tty);
1352 if (tty == (struct tty_struct *) NULL)
1354 portp = tty->driver_data;
1355 if (portp == (stlport_t *) NULL)
1357 if (portp->tx.buf == (char *) NULL)
1360 head = portp->tx.head;
1361 tail = portp->tx.tail;
1362 return((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
1365 /*****************************************************************************/
1368 * Return number of chars in the TX buffer. Normally we would just
1369 * calculate the number of chars in the buffer and return that, but if
1370 * the buffer is empty and TX interrupts are still on then we return
1371 * that the buffer still has 1 char in it. This way whoever called us
1372 * will not think that ALL chars have drained - since the UART still
1373 * must have some chars in it (we are busy after all).
1376 static int stl_charsinbuffer(struct tty_struct *tty)
1383 printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
1386 if (tty == (struct tty_struct *) NULL)
1388 portp = tty->driver_data;
1389 if (portp == (stlport_t *) NULL)
1391 if (portp->tx.buf == (char *) NULL)
1394 head = portp->tx.head;
1395 tail = portp->tx.tail;
1396 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1397 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1402 /*****************************************************************************/
1405 * Generate the serial struct info.
1408 static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp)
1410 struct serial_struct sio;
1414 printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1417 memset(&sio, 0, sizeof(struct serial_struct));
1418 sio.line = portp->portnr;
1419 sio.port = portp->ioaddr;
1420 sio.flags = portp->flags;
1421 sio.baud_base = portp->baud_base;
1422 sio.close_delay = portp->close_delay;
1423 sio.closing_wait = portp->closing_wait;
1424 sio.custom_divisor = portp->custom_divisor;
1426 if (portp->uartp == &stl_cd1400uart) {
1427 sio.type = PORT_CIRRUS;
1428 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1430 sio.type = PORT_UNKNOWN;
1431 sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1434 brdp = stl_brds[portp->brdnr];
1435 if (brdp != (stlbrd_t *) NULL)
1436 sio.irq = brdp->irq;
1438 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
1441 /*****************************************************************************/
1444 * Set port according to the serial struct info.
1445 * At this point we do not do any auto-configure stuff, so we will
1446 * just quietly ignore any requests to change irq, etc.
1449 static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp)
1451 struct serial_struct sio;
1454 printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1457 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1459 if (!capable(CAP_SYS_ADMIN)) {
1460 if ((sio.baud_base != portp->baud_base) ||
1461 (sio.close_delay != portp->close_delay) ||
1462 ((sio.flags & ~ASYNC_USR_MASK) !=
1463 (portp->flags & ~ASYNC_USR_MASK)))
1467 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1468 (sio.flags & ASYNC_USR_MASK);
1469 portp->baud_base = sio.baud_base;
1470 portp->close_delay = sio.close_delay;
1471 portp->closing_wait = sio.closing_wait;
1472 portp->custom_divisor = sio.custom_divisor;
1473 stl_setport(portp, portp->tty->termios);
1477 /*****************************************************************************/
1479 static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1483 if (tty == (struct tty_struct *) NULL)
1485 portp = tty->driver_data;
1486 if (portp == (stlport_t *) NULL)
1488 if (tty->flags & (1 << TTY_IO_ERROR))
1491 return stl_getsignals(portp);
1494 static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1495 unsigned int set, unsigned int clear)
1498 int rts = -1, dtr = -1;
1500 if (tty == (struct tty_struct *) NULL)
1502 portp = tty->driver_data;
1503 if (portp == (stlport_t *) NULL)
1505 if (tty->flags & (1 << TTY_IO_ERROR))
1508 if (set & TIOCM_RTS)
1510 if (set & TIOCM_DTR)
1512 if (clear & TIOCM_RTS)
1514 if (clear & TIOCM_DTR)
1517 stl_setsignals(portp, dtr, rts);
1521 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1526 void __user *argp = (void __user *)arg;
1529 printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
1530 (int) tty, (int) file, cmd, (int) arg);
1533 if (tty == (struct tty_struct *) NULL)
1535 portp = tty->driver_data;
1536 if (portp == (stlport_t *) NULL)
1539 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1540 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1541 if (tty->flags & (1 << TTY_IO_ERROR))
1549 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1550 (unsigned __user *) argp);
1553 if (get_user(ival, (unsigned int __user *) arg))
1555 tty->termios->c_cflag =
1556 (tty->termios->c_cflag & ~CLOCAL) |
1557 (ival ? CLOCAL : 0);
1560 rc = stl_getserial(portp, argp);
1563 rc = stl_setserial(portp, argp);
1565 case COM_GETPORTSTATS:
1566 rc = stl_getportstats(portp, argp);
1568 case COM_CLRPORTSTATS:
1569 rc = stl_clrportstats(portp, argp);
1575 case TIOCSERGSTRUCT:
1576 case TIOCSERGETMULTI:
1577 case TIOCSERSETMULTI:
1586 /*****************************************************************************/
1588 static void stl_settermios(struct tty_struct *tty, struct termios *old)
1591 struct termios *tiosp;
1594 printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
1597 if (tty == (struct tty_struct *) NULL)
1599 portp = tty->driver_data;
1600 if (portp == (stlport_t *) NULL)
1603 tiosp = tty->termios;
1604 if ((tiosp->c_cflag == old->c_cflag) &&
1605 (tiosp->c_iflag == old->c_iflag))
1608 stl_setport(portp, tiosp);
1609 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1611 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1612 tty->hw_stopped = 0;
1615 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1616 wake_up_interruptible(&portp->open_wait);
1619 /*****************************************************************************/
1622 * Attempt to flow control who ever is sending us data. Based on termios
1623 * settings use software or/and hardware flow control.
1626 static void stl_throttle(struct tty_struct *tty)
1631 printk("stl_throttle(tty=%x)\n", (int) tty);
1634 if (tty == (struct tty_struct *) NULL)
1636 portp = tty->driver_data;
1637 if (portp == (stlport_t *) NULL)
1639 stl_flowctrl(portp, 0);
1642 /*****************************************************************************/
1645 * Unflow control the device sending us data...
1648 static void stl_unthrottle(struct tty_struct *tty)
1653 printk("stl_unthrottle(tty=%x)\n", (int) tty);
1656 if (tty == (struct tty_struct *) NULL)
1658 portp = tty->driver_data;
1659 if (portp == (stlport_t *) NULL)
1661 stl_flowctrl(portp, 1);
1664 /*****************************************************************************/
1667 * Stop the transmitter. Basically to do this we will just turn TX
1671 static void stl_stop(struct tty_struct *tty)
1676 printk("stl_stop(tty=%x)\n", (int) tty);
1679 if (tty == (struct tty_struct *) NULL)
1681 portp = tty->driver_data;
1682 if (portp == (stlport_t *) NULL)
1684 stl_startrxtx(portp, -1, 0);
1687 /*****************************************************************************/
1690 * Start the transmitter again. Just turn TX interrupts back on.
1693 static void stl_start(struct tty_struct *tty)
1698 printk("stl_start(tty=%x)\n", (int) tty);
1701 if (tty == (struct tty_struct *) NULL)
1703 portp = tty->driver_data;
1704 if (portp == (stlport_t *) NULL)
1706 stl_startrxtx(portp, -1, 1);
1709 /*****************************************************************************/
1712 * Hangup this port. This is pretty much like closing the port, only
1713 * a little more brutal. No waiting for data to drain. Shutdown the
1714 * port and maybe drop signals.
1717 static void stl_hangup(struct tty_struct *tty)
1722 printk("stl_hangup(tty=%x)\n", (int) tty);
1725 if (tty == (struct tty_struct *) NULL)
1727 portp = tty->driver_data;
1728 if (portp == (stlport_t *) NULL)
1731 portp->flags &= ~ASYNC_INITIALIZED;
1732 stl_disableintrs(portp);
1733 if (tty->termios->c_cflag & HUPCL)
1734 stl_setsignals(portp, 0, 0);
1735 stl_enablerxtx(portp, 0, 0);
1736 stl_flushbuffer(tty);
1738 set_bit(TTY_IO_ERROR, &tty->flags);
1739 if (portp->tx.buf != (char *) NULL) {
1740 kfree(portp->tx.buf);
1741 portp->tx.buf = (char *) NULL;
1742 portp->tx.head = (char *) NULL;
1743 portp->tx.tail = (char *) NULL;
1745 portp->tty = (struct tty_struct *) NULL;
1746 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1747 portp->refcount = 0;
1748 wake_up_interruptible(&portp->open_wait);
1751 /*****************************************************************************/
1753 static void stl_flushbuffer(struct tty_struct *tty)
1758 printk("stl_flushbuffer(tty=%x)\n", (int) tty);
1761 if (tty == (struct tty_struct *) NULL)
1763 portp = tty->driver_data;
1764 if (portp == (stlport_t *) NULL)
1771 /*****************************************************************************/
1773 static void stl_breakctl(struct tty_struct *tty, int state)
1778 printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty, state);
1781 if (tty == (struct tty_struct *) NULL)
1783 portp = tty->driver_data;
1784 if (portp == (stlport_t *) NULL)
1787 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1790 /*****************************************************************************/
1792 static void stl_waituntilsent(struct tty_struct *tty, int timeout)
1798 printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty, timeout);
1801 if (tty == (struct tty_struct *) NULL)
1803 portp = tty->driver_data;
1804 if (portp == (stlport_t *) NULL)
1809 tend = jiffies + timeout;
1811 while (stl_datastate(portp)) {
1812 if (signal_pending(current))
1814 msleep_interruptible(20);
1815 if (time_after_eq(jiffies, tend))
1820 /*****************************************************************************/
1822 static void stl_sendxchar(struct tty_struct *tty, char ch)
1827 printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
1830 if (tty == (struct tty_struct *) NULL)
1832 portp = tty->driver_data;
1833 if (portp == (stlport_t *) NULL)
1836 if (ch == STOP_CHAR(tty))
1837 stl_sendflow(portp, 0);
1838 else if (ch == START_CHAR(tty))
1839 stl_sendflow(portp, 1);
1841 stl_putchar(tty, ch);
1844 /*****************************************************************************/
1849 * Format info for a specified port. The line is deliberately limited
1850 * to 80 characters. (If it is too long it will be truncated, if too
1851 * short then padded with spaces).
1854 static int stl_portinfo(stlport_t *portp, int portnr, char *pos)
1860 sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
1861 portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
1862 (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
1864 if (portp->stats.rxframing)
1865 sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
1866 if (portp->stats.rxparity)
1867 sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
1868 if (portp->stats.rxbreaks)
1869 sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
1870 if (portp->stats.rxoverrun)
1871 sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
1873 sigs = stl_getsignals(portp);
1874 cnt = sprintf(sp, "%s%s%s%s%s ",
1875 (sigs & TIOCM_RTS) ? "|RTS" : "",
1876 (sigs & TIOCM_CTS) ? "|CTS" : "",
1877 (sigs & TIOCM_DTR) ? "|DTR" : "",
1878 (sigs & TIOCM_CD) ? "|DCD" : "",
1879 (sigs & TIOCM_DSR) ? "|DSR" : "");
1883 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
1886 pos[(MAXLINE - 2)] = '+';
1887 pos[(MAXLINE - 1)] = '\n';
1892 /*****************************************************************************/
1895 * Port info, read from the /proc file system.
1898 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
1903 int brdnr, panelnr, portnr, totalport;
1908 printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
1909 "data=%x\n", (int) page, (int) start, (int) off, count,
1910 (int) eof, (int) data);
1918 pos += sprintf(pos, "%s: version %s", stl_drvtitle,
1920 while (pos < (page + MAXLINE - 1))
1927 * We scan through for each board, panel and port. The offset is
1928 * calculated on the fly, and irrelevant ports are skipped.
1930 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1931 brdp = stl_brds[brdnr];
1932 if (brdp == (stlbrd_t *) NULL)
1934 if (brdp->state == 0)
1937 maxoff = curoff + (brdp->nrports * MAXLINE);
1938 if (off >= maxoff) {
1943 totalport = brdnr * STL_MAXPORTS;
1944 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1945 panelp = brdp->panels[panelnr];
1946 if (panelp == (stlpanel_t *) NULL)
1949 maxoff = curoff + (panelp->nrports * MAXLINE);
1950 if (off >= maxoff) {
1952 totalport += panelp->nrports;
1956 for (portnr = 0; (portnr < panelp->nrports); portnr++,
1958 portp = panelp->ports[portnr];
1959 if (portp == (stlport_t *) NULL)
1961 if (off >= (curoff += MAXLINE))
1963 if ((pos - page + MAXLINE) > count)
1965 pos += stl_portinfo(portp, totalport, pos);
1977 /*****************************************************************************/
1980 * All board interrupts are vectored through here first. This code then
1981 * calls off to the approrpriate board interrupt handlers.
1984 static irqreturn_t stl_intr(int irq, void *dev_id, struct pt_regs *regs)
1986 stlbrd_t *brdp = (stlbrd_t *) dev_id;
1989 printk("stl_intr(brdp=%x,irq=%d,regs=%x)\n", (int) brdp, irq,
1993 return IRQ_RETVAL((* brdp->isr)(brdp));
1996 /*****************************************************************************/
1999 * Interrupt service routine for EasyIO board types.
2002 static int stl_eiointr(stlbrd_t *brdp)
2005 unsigned int iobase;
2008 panelp = brdp->panels[0];
2009 iobase = panelp->iobase;
2010 while (inb(brdp->iostatus) & EIO_INTRPEND) {
2012 (* panelp->isr)(panelp, iobase);
2017 /*****************************************************************************/
2020 * Interrupt service routine for ECH-AT board types.
2023 static int stl_echatintr(stlbrd_t *brdp)
2026 unsigned int ioaddr;
2030 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2032 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2034 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2035 ioaddr = brdp->bnkstataddr[bnknr];
2036 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2037 panelp = brdp->bnk2panel[bnknr];
2038 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2043 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2048 /*****************************************************************************/
2051 * Interrupt service routine for ECH-MCA board types.
2054 static int stl_echmcaintr(stlbrd_t *brdp)
2057 unsigned int ioaddr;
2061 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2063 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2064 ioaddr = brdp->bnkstataddr[bnknr];
2065 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2066 panelp = brdp->bnk2panel[bnknr];
2067 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2074 /*****************************************************************************/
2077 * Interrupt service routine for ECH-PCI board types.
2080 static int stl_echpciintr(stlbrd_t *brdp)
2083 unsigned int ioaddr;
2089 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2090 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
2091 ioaddr = brdp->bnkstataddr[bnknr];
2092 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2093 panelp = brdp->bnk2panel[bnknr];
2094 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2105 /*****************************************************************************/
2108 * Interrupt service routine for ECH-8/64-PCI board types.
2111 static int stl_echpci64intr(stlbrd_t *brdp)
2114 unsigned int ioaddr;
2118 while (inb(brdp->ioctrl) & 0x1) {
2120 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2121 ioaddr = brdp->bnkstataddr[bnknr];
2122 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2123 panelp = brdp->bnk2panel[bnknr];
2124 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2132 /*****************************************************************************/
2135 * Service an off-level request for some channel.
2137 static void stl_offintr(void *private)
2140 struct tty_struct *tty;
2141 unsigned int oldsigs;
2146 printk("stl_offintr(portp=%x)\n", (int) portp);
2149 if (portp == (stlport_t *) NULL)
2153 if (tty == (struct tty_struct *) NULL)
2157 if (test_bit(ASYI_TXLOW, &portp->istate)) {
2160 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
2161 clear_bit(ASYI_DCDCHANGE, &portp->istate);
2162 oldsigs = portp->sigs;
2163 portp->sigs = stl_getsignals(portp);
2164 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
2165 wake_up_interruptible(&portp->open_wait);
2166 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
2167 if (portp->flags & ASYNC_CHECK_CD)
2168 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2174 /*****************************************************************************/
2177 * Initialize all the ports on a panel.
2180 static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2186 printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
2189 chipmask = stl_panelinit(brdp, panelp);
2192 * All UART's are initialized (if found!). Now go through and setup
2193 * each ports data structures.
2195 for (i = 0; (i < panelp->nrports); i++) {
2196 portp = (stlport_t *) stl_memalloc(sizeof(stlport_t));
2197 if (portp == (stlport_t *) NULL) {
2198 printk("STALLION: failed to allocate memory "
2199 "(size=%d)\n", sizeof(stlport_t));
2202 memset(portp, 0, sizeof(stlport_t));
2204 portp->magic = STL_PORTMAGIC;
2206 portp->brdnr = panelp->brdnr;
2207 portp->panelnr = panelp->panelnr;
2208 portp->uartp = panelp->uartp;
2209 portp->clk = brdp->clk;
2210 portp->baud_base = STL_BAUDBASE;
2211 portp->close_delay = STL_CLOSEDELAY;
2212 portp->closing_wait = 30 * HZ;
2213 INIT_WORK(&portp->tqueue, stl_offintr, portp);
2214 init_waitqueue_head(&portp->open_wait);
2215 init_waitqueue_head(&portp->close_wait);
2216 portp->stats.brd = portp->brdnr;
2217 portp->stats.panel = portp->panelnr;
2218 portp->stats.port = portp->portnr;
2219 panelp->ports[i] = portp;
2220 stl_portinit(brdp, panelp, portp);
2226 /*****************************************************************************/
2229 * Try to find and initialize an EasyIO board.
2232 static inline int stl_initeio(stlbrd_t *brdp)
2235 unsigned int status;
2240 printk("stl_initeio(brdp=%x)\n", (int) brdp);
2243 brdp->ioctrl = brdp->ioaddr1 + 1;
2244 brdp->iostatus = brdp->ioaddr1 + 2;
2246 status = inb(brdp->iostatus);
2247 if ((status & EIO_IDBITMASK) == EIO_MK3)
2251 * Handle board specific stuff now. The real difference is PCI
2254 if (brdp->brdtype == BRD_EASYIOPCI) {
2255 brdp->iosize1 = 0x80;
2256 brdp->iosize2 = 0x80;
2257 name = "serial(EIO-PCI)";
2258 outb(0x41, (brdp->ioaddr2 + 0x4c));
2261 name = "serial(EIO)";
2262 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2263 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2264 printk("STALLION: invalid irq=%d for brd=%d\n",
2265 brdp->irq, brdp->brdnr);
2268 outb((stl_vecmap[brdp->irq] | EIO_0WS |
2269 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
2273 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2274 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2275 "%x conflicts with another device\n", brdp->brdnr,
2280 if (brdp->iosize2 > 0)
2281 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2282 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2283 "address %x conflicts with another device\n",
2284 brdp->brdnr, brdp->ioaddr2);
2285 printk(KERN_WARNING "STALLION: Warning, also "
2286 "releasing board %d I/O address %x \n",
2287 brdp->brdnr, brdp->ioaddr1);
2288 release_region(brdp->ioaddr1, brdp->iosize1);
2293 * Everything looks OK, so let's go ahead and probe for the hardware.
2295 brdp->clk = CD1400_CLK;
2296 brdp->isr = stl_eiointr;
2298 switch (status & EIO_IDBITMASK) {
2300 brdp->clk = CD1400_CLK8M;
2310 switch (status & EIO_BRDMASK) {
2329 * We have verified that the board is actually present, so now we
2330 * can complete the setup.
2333 panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
2334 if (panelp == (stlpanel_t *) NULL) {
2335 printk(KERN_WARNING "STALLION: failed to allocate memory "
2336 "(size=%d)\n", sizeof(stlpanel_t));
2339 memset(panelp, 0, sizeof(stlpanel_t));
2341 panelp->magic = STL_PANELMAGIC;
2342 panelp->brdnr = brdp->brdnr;
2343 panelp->panelnr = 0;
2344 panelp->nrports = brdp->nrports;
2345 panelp->iobase = brdp->ioaddr1;
2346 panelp->hwid = status;
2347 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2348 panelp->uartp = (void *) &stl_sc26198uart;
2349 panelp->isr = stl_sc26198intr;
2351 panelp->uartp = (void *) &stl_cd1400uart;
2352 panelp->isr = stl_cd1400eiointr;
2355 brdp->panels[0] = panelp;
2357 brdp->state |= BRD_FOUND;
2358 brdp->hwid = status;
2359 if (request_irq(brdp->irq, stl_intr, SA_SHIRQ, name, brdp) != 0) {
2360 printk("STALLION: failed to register interrupt "
2361 "routine for %s irq=%d\n", name, brdp->irq);
2369 /*****************************************************************************/
2372 * Try to find an ECH board and initialize it. This code is capable of
2373 * dealing with all types of ECH board.
2376 static inline int stl_initech(stlbrd_t *brdp)
2379 unsigned int status, nxtid, ioaddr, conflict;
2380 int panelnr, banknr, i;
2384 printk("stl_initech(brdp=%x)\n", (int) brdp);
2391 * Set up the initial board register contents for boards. This varies a
2392 * bit between the different board types. So we need to handle each
2393 * separately. Also do a check that the supplied IRQ is good.
2395 switch (brdp->brdtype) {
2398 brdp->isr = stl_echatintr;
2399 brdp->ioctrl = brdp->ioaddr1 + 1;
2400 brdp->iostatus = brdp->ioaddr1 + 1;
2401 status = inb(brdp->iostatus);
2402 if ((status & ECH_IDBITMASK) != ECH_ID)
2404 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2405 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2406 printk("STALLION: invalid irq=%d for brd=%d\n",
2407 brdp->irq, brdp->brdnr);
2410 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2411 status |= (stl_vecmap[brdp->irq] << 1);
2412 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2413 brdp->ioctrlval = ECH_INTENABLE |
2414 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2415 for (i = 0; (i < 10); i++)
2416 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2419 name = "serial(EC8/32)";
2420 outb(status, brdp->ioaddr1);
2424 brdp->isr = stl_echmcaintr;
2425 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2426 brdp->iostatus = brdp->ioctrl;
2427 status = inb(brdp->iostatus);
2428 if ((status & ECH_IDBITMASK) != ECH_ID)
2430 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2431 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2432 printk("STALLION: invalid irq=%d for brd=%d\n",
2433 brdp->irq, brdp->brdnr);
2436 outb(ECHMC_BRDRESET, brdp->ioctrl);
2437 outb(ECHMC_INTENABLE, brdp->ioctrl);
2439 name = "serial(EC8/32-MC)";
2443 brdp->isr = stl_echpciintr;
2444 brdp->ioctrl = brdp->ioaddr1 + 2;
2447 name = "serial(EC8/32-PCI)";
2451 brdp->isr = stl_echpci64intr;
2452 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2453 outb(0x43, (brdp->ioaddr1 + 0x4c));
2454 brdp->iosize1 = 0x80;
2455 brdp->iosize2 = 0x80;
2456 name = "serial(EC8/64-PCI)";
2460 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
2466 * Check boards for possible IO address conflicts and return fail status
2467 * if an IO conflict found.
2469 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2470 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2471 "%x conflicts with another device\n", brdp->brdnr,
2476 if (brdp->iosize2 > 0)
2477 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2478 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2479 "address %x conflicts with another device\n",
2480 brdp->brdnr, brdp->ioaddr2);
2481 printk(KERN_WARNING "STALLION: Warning, also "
2482 "releasing board %d I/O address %x \n",
2483 brdp->brdnr, brdp->ioaddr1);
2484 release_region(brdp->ioaddr1, brdp->iosize1);
2489 * Scan through the secondary io address space looking for panels.
2490 * As we find'em allocate and initialize panel structures for each.
2492 brdp->clk = CD1400_CLK;
2493 brdp->hwid = status;
2495 ioaddr = brdp->ioaddr2;
2500 for (i = 0; (i < STL_MAXPANELS); i++) {
2501 if (brdp->brdtype == BRD_ECHPCI) {
2502 outb(nxtid, brdp->ioctrl);
2503 ioaddr = brdp->ioaddr2;
2505 status = inb(ioaddr + ECH_PNLSTATUS);
2506 if ((status & ECH_PNLIDMASK) != nxtid)
2508 panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
2509 if (panelp == (stlpanel_t *) NULL) {
2510 printk("STALLION: failed to allocate memory "
2511 "(size=%d)\n", sizeof(stlpanel_t));
2514 memset(panelp, 0, sizeof(stlpanel_t));
2515 panelp->magic = STL_PANELMAGIC;
2516 panelp->brdnr = brdp->brdnr;
2517 panelp->panelnr = panelnr;
2518 panelp->iobase = ioaddr;
2519 panelp->pagenr = nxtid;
2520 panelp->hwid = status;
2521 brdp->bnk2panel[banknr] = panelp;
2522 brdp->bnkpageaddr[banknr] = nxtid;
2523 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2525 if (status & ECH_PNLXPID) {
2526 panelp->uartp = (void *) &stl_sc26198uart;
2527 panelp->isr = stl_sc26198intr;
2528 if (status & ECH_PNL16PORT) {
2529 panelp->nrports = 16;
2530 brdp->bnk2panel[banknr] = panelp;
2531 brdp->bnkpageaddr[banknr] = nxtid;
2532 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2535 panelp->nrports = 8;
2538 panelp->uartp = (void *) &stl_cd1400uart;
2539 panelp->isr = stl_cd1400echintr;
2540 if (status & ECH_PNL16PORT) {
2541 panelp->nrports = 16;
2542 panelp->ackmask = 0x80;
2543 if (brdp->brdtype != BRD_ECHPCI)
2544 ioaddr += EREG_BANKSIZE;
2545 brdp->bnk2panel[banknr] = panelp;
2546 brdp->bnkpageaddr[banknr] = ++nxtid;
2547 brdp->bnkstataddr[banknr++] = ioaddr +
2550 panelp->nrports = 8;
2551 panelp->ackmask = 0xc0;
2556 ioaddr += EREG_BANKSIZE;
2557 brdp->nrports += panelp->nrports;
2558 brdp->panels[panelnr++] = panelp;
2559 if ((brdp->brdtype != BRD_ECHPCI) &&
2560 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
2564 brdp->nrpanels = panelnr;
2565 brdp->nrbnks = banknr;
2566 if (brdp->brdtype == BRD_ECH)
2567 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2569 brdp->state |= BRD_FOUND;
2570 if (request_irq(brdp->irq, stl_intr, SA_SHIRQ, name, brdp) != 0) {
2571 printk("STALLION: failed to register interrupt "
2572 "routine for %s irq=%d\n", name, brdp->irq);
2581 /*****************************************************************************/
2584 * Initialize and configure the specified board.
2585 * Scan through all the boards in the configuration and see what we
2586 * can find. Handle EIO and the ECH boards a little differently here
2587 * since the initial search and setup is very different.
2590 static int __init stl_brdinit(stlbrd_t *brdp)
2595 printk("stl_brdinit(brdp=%x)\n", (int) brdp);
2598 switch (brdp->brdtype) {
2610 printk("STALLION: board=%d is unknown board type=%d\n",
2611 brdp->brdnr, brdp->brdtype);
2615 stl_brds[brdp->brdnr] = brdp;
2616 if ((brdp->state & BRD_FOUND) == 0) {
2617 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2618 stl_brdnames[brdp->brdtype], brdp->brdnr,
2619 brdp->ioaddr1, brdp->irq);
2623 for (i = 0; (i < STL_MAXPANELS); i++)
2624 if (brdp->panels[i] != (stlpanel_t *) NULL)
2625 stl_initports(brdp, brdp->panels[i]);
2627 printk("STALLION: %s found, board=%d io=%x irq=%d "
2628 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2629 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2634 /*****************************************************************************/
2637 * Find the next available board number that is free.
2640 static inline int stl_getbrdnr(void)
2644 for (i = 0; (i < STL_MAXBRDS); i++) {
2645 if (stl_brds[i] == (stlbrd_t *) NULL) {
2646 if (i >= stl_nrbrds)
2654 /*****************************************************************************/
2659 * We have a Stallion board. Allocate a board structure and
2660 * initialize it. Read its IO and IRQ resources from PCI
2661 * configuration space.
2664 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
2669 printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
2670 devp->bus->number, devp->devfn);
2673 if (pci_enable_device(devp))
2675 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2677 if ((brdp->brdnr = stl_getbrdnr()) < 0) {
2678 printk("STALLION: too many boards found, "
2679 "maximum supported %d\n", STL_MAXBRDS);
2682 brdp->brdtype = brdtype;
2685 * Different Stallion boards use the BAR registers in different ways,
2686 * so set up io addresses based on board type.
2689 printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__, __LINE__,
2690 pci_resource_start(devp, 0), pci_resource_start(devp, 1),
2691 pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
2695 * We have all resources from the board, so let's setup the actual
2696 * board structure now.
2700 brdp->ioaddr2 = pci_resource_start(devp, 0);
2701 brdp->ioaddr1 = pci_resource_start(devp, 1);
2704 brdp->ioaddr2 = pci_resource_start(devp, 2);
2705 brdp->ioaddr1 = pci_resource_start(devp, 1);
2708 brdp->ioaddr1 = pci_resource_start(devp, 2);
2709 brdp->ioaddr2 = pci_resource_start(devp, 1);
2712 printk("STALLION: unknown PCI board type=%d\n", brdtype);
2716 brdp->irq = devp->irq;
2722 /*****************************************************************************/
2725 * Find all Stallion PCI boards that might be installed. Initialize each
2726 * one as it is found.
2730 static inline int stl_findpcibrds(void)
2732 struct pci_dev *dev = NULL;
2736 printk("stl_findpcibrds()\n");
2739 for (i = 0; (i < stl_nrpcibrds); i++)
2740 while ((dev = pci_find_device(stl_pcibrds[i].vendid,
2741 stl_pcibrds[i].devid, dev))) {
2744 * Found a device on the PCI bus that has our vendor and
2745 * device ID. Need to check now that it is really us.
2747 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2750 rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
2760 /*****************************************************************************/
2763 * Scan through all the boards in the configuration and see what we
2764 * can find. Handle EIO and the ECH boards a little differently here
2765 * since the initial search and setup is too different.
2768 static inline int stl_initbrds(void)
2775 printk("stl_initbrds()\n");
2778 if (stl_nrbrds > STL_MAXBRDS) {
2779 printk("STALLION: too many boards in configuration table, "
2780 "truncating to %d\n", STL_MAXBRDS);
2781 stl_nrbrds = STL_MAXBRDS;
2785 * Firstly scan the list of static boards configured. Allocate
2786 * resources and initialize the boards as found.
2788 for (i = 0; (i < stl_nrbrds); i++) {
2789 confp = &stl_brdconf[i];
2791 stl_parsebrd(confp, stl_brdsp[i]);
2793 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2796 brdp->brdtype = confp->brdtype;
2797 brdp->ioaddr1 = confp->ioaddr1;
2798 brdp->ioaddr2 = confp->ioaddr2;
2799 brdp->irq = confp->irq;
2800 brdp->irqtype = confp->irqtype;
2805 * Find any dynamically supported boards. That is via module load
2806 * line options or auto-detected on the PCI bus.
2818 /*****************************************************************************/
2821 * Return the board stats structure to user app.
2824 static int stl_getbrdstats(combrd_t __user *bp)
2830 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2832 if (stl_brdstats.brd >= STL_MAXBRDS)
2834 brdp = stl_brds[stl_brdstats.brd];
2835 if (brdp == (stlbrd_t *) NULL)
2838 memset(&stl_brdstats, 0, sizeof(combrd_t));
2839 stl_brdstats.brd = brdp->brdnr;
2840 stl_brdstats.type = brdp->brdtype;
2841 stl_brdstats.hwid = brdp->hwid;
2842 stl_brdstats.state = brdp->state;
2843 stl_brdstats.ioaddr = brdp->ioaddr1;
2844 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2845 stl_brdstats.irq = brdp->irq;
2846 stl_brdstats.nrpanels = brdp->nrpanels;
2847 stl_brdstats.nrports = brdp->nrports;
2848 for (i = 0; (i < brdp->nrpanels); i++) {
2849 panelp = brdp->panels[i];
2850 stl_brdstats.panels[i].panel = i;
2851 stl_brdstats.panels[i].hwid = panelp->hwid;
2852 stl_brdstats.panels[i].nrports = panelp->nrports;
2855 return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
2858 /*****************************************************************************/
2861 * Resolve the referenced port number into a port struct pointer.
2864 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2869 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2870 return((stlport_t *) NULL);
2871 brdp = stl_brds[brdnr];
2872 if (brdp == (stlbrd_t *) NULL)
2873 return((stlport_t *) NULL);
2874 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2875 return((stlport_t *) NULL);
2876 panelp = brdp->panels[panelnr];
2877 if (panelp == (stlpanel_t *) NULL)
2878 return((stlport_t *) NULL);
2879 if ((portnr < 0) || (portnr >= panelp->nrports))
2880 return((stlport_t *) NULL);
2881 return(panelp->ports[portnr]);
2884 /*****************************************************************************/
2887 * Return the port stats structure to user app. A NULL port struct
2888 * pointer passed in means that we need to find out from the app
2889 * what port to get stats for (used through board control device).
2892 static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
2894 unsigned char *head, *tail;
2895 unsigned long flags;
2898 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2900 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2902 if (portp == (stlport_t *) NULL)
2906 portp->stats.state = portp->istate;
2907 portp->stats.flags = portp->flags;
2908 portp->stats.hwid = portp->hwid;
2910 portp->stats.ttystate = 0;
2911 portp->stats.cflags = 0;
2912 portp->stats.iflags = 0;
2913 portp->stats.oflags = 0;
2914 portp->stats.lflags = 0;
2915 portp->stats.rxbuffered = 0;
2919 if (portp->tty != (struct tty_struct *) NULL) {
2920 if (portp->tty->driver_data == portp) {
2921 portp->stats.ttystate = portp->tty->flags;
2922 portp->stats.rxbuffered = portp->tty->flip.count;
2923 if (portp->tty->termios != (struct termios *) NULL) {
2924 portp->stats.cflags = portp->tty->termios->c_cflag;
2925 portp->stats.iflags = portp->tty->termios->c_iflag;
2926 portp->stats.oflags = portp->tty->termios->c_oflag;
2927 portp->stats.lflags = portp->tty->termios->c_lflag;
2931 restore_flags(flags);
2933 head = portp->tx.head;
2934 tail = portp->tx.tail;
2935 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2936 (STL_TXBUFSIZE - (tail - head)));
2938 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2940 return copy_to_user(cp, &portp->stats,
2941 sizeof(comstats_t)) ? -EFAULT : 0;
2944 /*****************************************************************************/
2947 * Clear the port stats structure. We also return it zeroed out...
2950 static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp)
2953 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2955 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2957 if (portp == (stlport_t *) NULL)
2961 memset(&portp->stats, 0, sizeof(comstats_t));
2962 portp->stats.brd = portp->brdnr;
2963 portp->stats.panel = portp->panelnr;
2964 portp->stats.port = portp->portnr;
2965 return copy_to_user(cp, &portp->stats,
2966 sizeof(comstats_t)) ? -EFAULT : 0;
2969 /*****************************************************************************/
2972 * Return the entire driver ports structure to a user app.
2975 static int stl_getportstruct(stlport_t __user *arg)
2979 if (copy_from_user(&stl_dummyport, arg, sizeof(stlport_t)))
2981 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
2982 stl_dummyport.portnr);
2985 return copy_to_user(arg, portp, sizeof(stlport_t)) ? -EFAULT : 0;
2988 /*****************************************************************************/
2991 * Return the entire driver board structure to a user app.
2994 static int stl_getbrdstruct(stlbrd_t __user *arg)
2998 if (copy_from_user(&stl_dummybrd, arg, sizeof(stlbrd_t)))
3000 if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
3002 brdp = stl_brds[stl_dummybrd.brdnr];
3005 return copy_to_user(arg, brdp, sizeof(stlbrd_t)) ? -EFAULT : 0;
3008 /*****************************************************************************/
3011 * The "staliomem" device is also required to do some special operations
3012 * on the board and/or ports. In this driver it is mostly used for stats
3016 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
3019 void __user *argp = (void __user *)arg;
3022 printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
3023 (int) fp, cmd, (int) arg);
3027 if (brdnr >= STL_MAXBRDS)
3032 case COM_GETPORTSTATS:
3033 rc = stl_getportstats(NULL, argp);
3035 case COM_CLRPORTSTATS:
3036 rc = stl_clrportstats(NULL, argp);
3038 case COM_GETBRDSTATS:
3039 rc = stl_getbrdstats(argp);
3042 rc = stl_getportstruct(argp);
3045 rc = stl_getbrdstruct(argp);
3055 static struct tty_operations stl_ops = {
3059 .put_char = stl_putchar,
3060 .flush_chars = stl_flushchars,
3061 .write_room = stl_writeroom,
3062 .chars_in_buffer = stl_charsinbuffer,
3064 .set_termios = stl_settermios,
3065 .throttle = stl_throttle,
3066 .unthrottle = stl_unthrottle,
3069 .hangup = stl_hangup,
3070 .flush_buffer = stl_flushbuffer,
3071 .break_ctl = stl_breakctl,
3072 .wait_until_sent = stl_waituntilsent,
3073 .send_xchar = stl_sendxchar,
3074 .read_proc = stl_readproc,
3075 .tiocmget = stl_tiocmget,
3076 .tiocmset = stl_tiocmset,
3079 /*****************************************************************************/
3081 int __init stl_init(void)
3084 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
3088 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
3093 * Allocate a temporary write buffer.
3095 stl_tmpwritebuf = (char *) stl_memalloc(STL_TXBUFSIZE);
3096 if (stl_tmpwritebuf == (char *) NULL)
3097 printk("STALLION: failed to allocate memory (size=%d)\n",
3101 * Set up a character driver for per board stuff. This is mainly used
3102 * to do stats ioctls on the ports.
3104 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
3105 printk("STALLION: failed to register serial board device\n");
3106 devfs_mk_dir("staliomem");
3108 stallion_class = class_simple_create(THIS_MODULE, "staliomem");
3109 for (i = 0; i < 4; i++) {
3110 devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR, i),
3111 S_IFCHR|S_IRUSR|S_IWUSR,
3113 class_simple_device_add(stallion_class, MKDEV(STL_SIOMEMMAJOR, i), NULL, "staliomem%d", i);
3116 stl_serial->owner = THIS_MODULE;
3117 stl_serial->driver_name = stl_drvname;
3118 stl_serial->name = "ttyE";
3119 stl_serial->devfs_name = "tts/E";
3120 stl_serial->major = STL_SERIALMAJOR;
3121 stl_serial->minor_start = 0;
3122 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
3123 stl_serial->subtype = SERIAL_TYPE_NORMAL;
3124 stl_serial->init_termios = stl_deftermios;
3125 stl_serial->flags = TTY_DRIVER_REAL_RAW;
3126 tty_set_operations(stl_serial, &stl_ops);
3128 if (tty_register_driver(stl_serial)) {
3129 put_tty_driver(stl_serial);
3130 printk("STALLION: failed to register serial driver\n");
3137 /*****************************************************************************/
3138 /* CD1400 HARDWARE FUNCTIONS */
3139 /*****************************************************************************/
3142 * These functions get/set/update the registers of the cd1400 UARTs.
3143 * Access to the cd1400 registers is via an address/data io port pair.
3144 * (Maybe should make this inline...)
3147 static int stl_cd1400getreg(stlport_t *portp, int regnr)
3149 outb((regnr + portp->uartaddr), portp->ioaddr);
3150 return(inb(portp->ioaddr + EREG_DATA));
3153 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
3155 outb((regnr + portp->uartaddr), portp->ioaddr);
3156 outb(value, portp->ioaddr + EREG_DATA);
3159 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
3161 outb((regnr + portp->uartaddr), portp->ioaddr);
3162 if (inb(portp->ioaddr + EREG_DATA) != value) {
3163 outb(value, portp->ioaddr + EREG_DATA);
3169 /*****************************************************************************/
3172 * Inbitialize the UARTs in a panel. We don't care what sort of board
3173 * these ports are on - since the port io registers are almost
3174 * identical when dealing with ports.
3177 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3181 int nrchips, uartaddr, ioaddr;
3184 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
3187 BRDENABLE(panelp->brdnr, panelp->pagenr);
3190 * Check that each chip is present and started up OK.
3193 nrchips = panelp->nrports / CD1400_PORTS;
3194 for (i = 0; (i < nrchips); i++) {
3195 if (brdp->brdtype == BRD_ECHPCI) {
3196 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3197 ioaddr = panelp->iobase;
3199 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3201 uartaddr = (i & 0x01) ? 0x080 : 0;
3202 outb((GFRCR + uartaddr), ioaddr);
3203 outb(0, (ioaddr + EREG_DATA));
3204 outb((CCR + uartaddr), ioaddr);
3205 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3206 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3207 outb((GFRCR + uartaddr), ioaddr);
3208 for (j = 0; (j < CCR_MAXWAIT); j++) {
3209 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3212 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3213 printk("STALLION: cd1400 not responding, "
3214 "brd=%d panel=%d chip=%d\n",
3215 panelp->brdnr, panelp->panelnr, i);
3218 chipmask |= (0x1 << i);
3219 outb((PPR + uartaddr), ioaddr);
3220 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
3223 BRDDISABLE(panelp->brdnr);
3227 /*****************************************************************************/
3230 * Initialize hardware specific port registers.
3233 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3236 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3237 (int) brdp, (int) panelp, (int) portp);
3240 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
3241 (portp == (stlport_t *) NULL))
3244 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3245 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3246 portp->uartaddr = (portp->portnr & 0x04) << 5;
3247 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3249 BRDENABLE(portp->brdnr, portp->pagenr);
3250 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3251 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3252 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3253 BRDDISABLE(portp->brdnr);
3256 /*****************************************************************************/
3259 * Wait for the command register to be ready. We will poll this,
3260 * since it won't usually take too long to be ready.
3263 static void stl_cd1400ccrwait(stlport_t *portp)
3267 for (i = 0; (i < CCR_MAXWAIT); i++) {
3268 if (stl_cd1400getreg(portp, CCR) == 0) {
3273 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
3274 portp->portnr, portp->panelnr, portp->brdnr);
3277 /*****************************************************************************/
3280 * Set up the cd1400 registers for a port based on the termios port
3284 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3287 unsigned long flags;
3288 unsigned int clkdiv, baudrate;
3289 unsigned char cor1, cor2, cor3;
3290 unsigned char cor4, cor5, ccr;
3291 unsigned char srer, sreron, sreroff;
3292 unsigned char mcor1, mcor2, rtpr;
3293 unsigned char clk, div;
3309 brdp = stl_brds[portp->brdnr];
3310 if (brdp == (stlbrd_t *) NULL)
3314 * Set up the RX char ignore mask with those RX error types we
3315 * can ignore. We can get the cd1400 to help us out a little here,
3316 * it will ignore parity errors and breaks for us.
3318 portp->rxignoremsk = 0;
3319 if (tiosp->c_iflag & IGNPAR) {
3320 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
3321 cor1 |= COR1_PARIGNORE;
3323 if (tiosp->c_iflag & IGNBRK) {
3324 portp->rxignoremsk |= ST_BREAK;
3325 cor4 |= COR4_IGNBRK;
3328 portp->rxmarkmsk = ST_OVERRUN;
3329 if (tiosp->c_iflag & (INPCK | PARMRK))
3330 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3331 if (tiosp->c_iflag & BRKINT)
3332 portp->rxmarkmsk |= ST_BREAK;
3335 * Go through the char size, parity and stop bits and set all the
3336 * option register appropriately.
3338 switch (tiosp->c_cflag & CSIZE) {
3353 if (tiosp->c_cflag & CSTOPB)
3358 if (tiosp->c_cflag & PARENB) {
3359 if (tiosp->c_cflag & PARODD)
3360 cor1 |= (COR1_PARENB | COR1_PARODD);
3362 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3364 cor1 |= COR1_PARNONE;
3368 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3369 * space for hardware flow control and the like. This should be set to
3370 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3371 * really be based on VTIME.
3373 cor3 |= FIFO_RXTHRESHOLD;
3377 * Calculate the baud rate timers. For now we will just assume that
3378 * the input and output baud are the same. Could have used a baud
3379 * table here, but this way we can generate virtually any baud rate
3382 baudrate = tiosp->c_cflag & CBAUD;
3383 if (baudrate & CBAUDEX) {
3384 baudrate &= ~CBAUDEX;
3385 if ((baudrate < 1) || (baudrate > 4))
3386 tiosp->c_cflag &= ~CBAUDEX;
3390 baudrate = stl_baudrates[baudrate];
3391 if ((tiosp->c_cflag & CBAUD) == B38400) {
3392 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3394 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3396 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3398 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3400 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3401 baudrate = (portp->baud_base / portp->custom_divisor);
3403 if (baudrate > STL_CD1400MAXBAUD)
3404 baudrate = STL_CD1400MAXBAUD;
3407 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3408 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
3412 div = (unsigned char) clkdiv;
3416 * Check what form of modem signaling is required and set it up.
3418 if ((tiosp->c_cflag & CLOCAL) == 0) {
3421 sreron |= SRER_MODEM;
3422 portp->flags |= ASYNC_CHECK_CD;
3424 portp->flags &= ~ASYNC_CHECK_CD;
3428 * Setup cd1400 enhanced modes if we can. In particular we want to
3429 * handle as much of the flow control as possible automatically. As
3430 * well as saving a few CPU cycles it will also greatly improve flow
3431 * control reliability.
3433 if (tiosp->c_iflag & IXON) {
3436 if (tiosp->c_iflag & IXANY)
3440 if (tiosp->c_cflag & CRTSCTS) {
3442 mcor1 |= FIFO_RTSTHRESHOLD;
3446 * All cd1400 register values calculated so go through and set
3451 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3452 portp->portnr, portp->panelnr, portp->brdnr);
3453 printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3454 cor1, cor2, cor3, cor4, cor5);
3455 printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3456 mcor1, mcor2, rtpr, sreron, sreroff);
3457 printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3458 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3459 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3460 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3465 BRDENABLE(portp->brdnr, portp->pagenr);
3466 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3467 srer = stl_cd1400getreg(portp, SRER);
3468 stl_cd1400setreg(portp, SRER, 0);
3469 if (stl_cd1400updatereg(portp, COR1, cor1))
3471 if (stl_cd1400updatereg(portp, COR2, cor2))
3473 if (stl_cd1400updatereg(portp, COR3, cor3))
3476 stl_cd1400ccrwait(portp);
3477 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3479 stl_cd1400setreg(portp, COR4, cor4);
3480 stl_cd1400setreg(portp, COR5, cor5);
3481 stl_cd1400setreg(portp, MCOR1, mcor1);
3482 stl_cd1400setreg(portp, MCOR2, mcor2);
3484 stl_cd1400setreg(portp, TCOR, clk);
3485 stl_cd1400setreg(portp, TBPR, div);
3486 stl_cd1400setreg(portp, RCOR, clk);
3487 stl_cd1400setreg(portp, RBPR, div);
3489 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3490 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3491 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3492 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3493 stl_cd1400setreg(portp, RTPR, rtpr);
3494 mcor1 = stl_cd1400getreg(portp, MSVR1);
3495 if (mcor1 & MSVR1_DCD)
3496 portp->sigs |= TIOCM_CD;
3498 portp->sigs &= ~TIOCM_CD;
3499 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3500 BRDDISABLE(portp->brdnr);
3501 restore_flags(flags);
3504 /*****************************************************************************/
3507 * Set the state of the DTR and RTS signals.
3510 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3512 unsigned char msvr1, msvr2;
3513 unsigned long flags;
3516 printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
3517 (int) portp, dtr, rts);
3529 BRDENABLE(portp->brdnr, portp->pagenr);
3530 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3532 stl_cd1400setreg(portp, MSVR2, msvr2);
3534 stl_cd1400setreg(portp, MSVR1, msvr1);
3535 BRDDISABLE(portp->brdnr);
3536 restore_flags(flags);
3539 /*****************************************************************************/
3542 * Return the state of the signals.
3545 static int stl_cd1400getsignals(stlport_t *portp)
3547 unsigned char msvr1, msvr2;
3548 unsigned long flags;
3552 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3557 BRDENABLE(portp->brdnr, portp->pagenr);
3558 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3559 msvr1 = stl_cd1400getreg(portp, MSVR1);
3560 msvr2 = stl_cd1400getreg(portp, MSVR2);
3561 BRDDISABLE(portp->brdnr);
3562 restore_flags(flags);
3565 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3566 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3567 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3568 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3570 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3571 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3578 /*****************************************************************************/
3581 * Enable/Disable the Transmitter and/or Receiver.
3584 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3587 unsigned long flags;
3590 printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3591 (int) portp, rx, tx);
3596 ccr |= CCR_TXDISABLE;
3598 ccr |= CCR_TXENABLE;
3600 ccr |= CCR_RXDISABLE;
3602 ccr |= CCR_RXENABLE;
3606 BRDENABLE(portp->brdnr, portp->pagenr);
3607 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3608 stl_cd1400ccrwait(portp);
3609 stl_cd1400setreg(portp, CCR, ccr);
3610 stl_cd1400ccrwait(portp);
3611 BRDDISABLE(portp->brdnr);
3612 restore_flags(flags);
3615 /*****************************************************************************/
3618 * Start/stop the Transmitter and/or Receiver.
3621 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3623 unsigned char sreron, sreroff;
3624 unsigned long flags;
3627 printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3628 (int) portp, rx, tx);
3634 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3636 sreron |= SRER_TXDATA;
3638 sreron |= SRER_TXEMPTY;
3640 sreroff |= SRER_RXDATA;
3642 sreron |= SRER_RXDATA;
3646 BRDENABLE(portp->brdnr, portp->pagenr);
3647 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3648 stl_cd1400setreg(portp, SRER,
3649 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3650 BRDDISABLE(portp->brdnr);
3652 set_bit(ASYI_TXBUSY, &portp->istate);
3653 restore_flags(flags);
3656 /*****************************************************************************/
3659 * Disable all interrupts from this port.
3662 static void stl_cd1400disableintrs(stlport_t *portp)
3664 unsigned long flags;
3667 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3671 BRDENABLE(portp->brdnr, portp->pagenr);
3672 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3673 stl_cd1400setreg(portp, SRER, 0);
3674 BRDDISABLE(portp->brdnr);
3675 restore_flags(flags);
3678 /*****************************************************************************/
3680 static void stl_cd1400sendbreak(stlport_t *portp, int len)
3682 unsigned long flags;
3685 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
3690 BRDENABLE(portp->brdnr, portp->pagenr);
3691 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3692 stl_cd1400setreg(portp, SRER,
3693 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3695 BRDDISABLE(portp->brdnr);
3696 portp->brklen = len;
3698 portp->stats.txbreaks++;
3699 restore_flags(flags);
3702 /*****************************************************************************/
3705 * Take flow control actions...
3708 static void stl_cd1400flowctrl(stlport_t *portp, int state)
3710 struct tty_struct *tty;
3711 unsigned long flags;
3714 printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp, state);
3717 if (portp == (stlport_t *) NULL)
3720 if (tty == (struct tty_struct *) NULL)
3725 BRDENABLE(portp->brdnr, portp->pagenr);
3726 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3729 if (tty->termios->c_iflag & IXOFF) {
3730 stl_cd1400ccrwait(portp);
3731 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3732 portp->stats.rxxon++;
3733 stl_cd1400ccrwait(portp);
3736 * Question: should we return RTS to what it was before? It may
3737 * have been set by an ioctl... Suppose not, since if you have
3738 * hardware flow control set then it is pretty silly to go and
3739 * set the RTS line by hand.
3741 if (tty->termios->c_cflag & CRTSCTS) {
3742 stl_cd1400setreg(portp, MCOR1,
3743 (stl_cd1400getreg(portp, MCOR1) |
3744 FIFO_RTSTHRESHOLD));
3745 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3746 portp->stats.rxrtson++;
3749 if (tty->termios->c_iflag & IXOFF) {
3750 stl_cd1400ccrwait(portp);
3751 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3752 portp->stats.rxxoff++;
3753 stl_cd1400ccrwait(portp);
3755 if (tty->termios->c_cflag & CRTSCTS) {
3756 stl_cd1400setreg(portp, MCOR1,
3757 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3758 stl_cd1400setreg(portp, MSVR2, 0);
3759 portp->stats.rxrtsoff++;
3763 BRDDISABLE(portp->brdnr);
3764 restore_flags(flags);
3767 /*****************************************************************************/
3770 * Send a flow control character...
3773 static void stl_cd1400sendflow(stlport_t *portp, int state)
3775 struct tty_struct *tty;
3776 unsigned long flags;
3779 printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp, state);
3782 if (portp == (stlport_t *) NULL)
3785 if (tty == (struct tty_struct *) NULL)
3790 BRDENABLE(portp->brdnr, portp->pagenr);
3791 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3793 stl_cd1400ccrwait(portp);
3794 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3795 portp->stats.rxxon++;
3796 stl_cd1400ccrwait(portp);
3798 stl_cd1400ccrwait(portp);
3799 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3800 portp->stats.rxxoff++;
3801 stl_cd1400ccrwait(portp);
3803 BRDDISABLE(portp->brdnr);
3804 restore_flags(flags);
3807 /*****************************************************************************/
3809 static void stl_cd1400flush(stlport_t *portp)
3811 unsigned long flags;
3814 printk("stl_cd1400flush(portp=%x)\n", (int) portp);
3817 if (portp == (stlport_t *) NULL)
3822 BRDENABLE(portp->brdnr, portp->pagenr);
3823 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3824 stl_cd1400ccrwait(portp);
3825 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3826 stl_cd1400ccrwait(portp);
3827 portp->tx.tail = portp->tx.head;
3828 BRDDISABLE(portp->brdnr);
3829 restore_flags(flags);
3832 /*****************************************************************************/
3835 * Return the current state of data flow on this port. This is only
3836 * really interresting when determining if data has fully completed
3837 * transmission or not... This is easy for the cd1400, it accurately
3838 * maintains the busy port flag.
3841 static int stl_cd1400datastate(stlport_t *portp)
3844 printk("stl_cd1400datastate(portp=%x)\n", (int) portp);
3847 if (portp == (stlport_t *) NULL)
3850 return(test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0);
3853 /*****************************************************************************/
3856 * Interrupt service routine for cd1400 EasyIO boards.
3859 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3861 unsigned char svrtype;
3864 printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
3865 (int) panelp, iobase);
3869 svrtype = inb(iobase + EREG_DATA);
3870 if (panelp->nrports > 4) {
3871 outb((SVRR + 0x80), iobase);
3872 svrtype |= inb(iobase + EREG_DATA);
3875 if (svrtype & SVRR_RX)
3876 stl_cd1400rxisr(panelp, iobase);
3877 else if (svrtype & SVRR_TX)
3878 stl_cd1400txisr(panelp, iobase);
3879 else if (svrtype & SVRR_MDM)
3880 stl_cd1400mdmisr(panelp, iobase);
3883 /*****************************************************************************/
3886 * Interrupt service routine for cd1400 panels.
3889 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
3891 unsigned char svrtype;
3894 printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
3899 svrtype = inb(iobase + EREG_DATA);
3900 outb((SVRR + 0x80), iobase);
3901 svrtype |= inb(iobase + EREG_DATA);
3902 if (svrtype & SVRR_RX)
3903 stl_cd1400rxisr(panelp, iobase);
3904 else if (svrtype & SVRR_TX)
3905 stl_cd1400txisr(panelp, iobase);
3906 else if (svrtype & SVRR_MDM)
3907 stl_cd1400mdmisr(panelp, iobase);
3911 /*****************************************************************************/
3914 * Unfortunately we need to handle breaks in the TX data stream, since
3915 * this is the only way to generate them on the cd1400.
3918 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr)
3920 if (portp->brklen == 1) {
3921 outb((COR2 + portp->uartaddr), ioaddr);
3922 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
3923 (ioaddr + EREG_DATA));
3924 outb((TDR + portp->uartaddr), ioaddr);
3925 outb(ETC_CMD, (ioaddr + EREG_DATA));
3926 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
3927 outb((SRER + portp->uartaddr), ioaddr);
3928 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
3929 (ioaddr + EREG_DATA));
3931 } else if (portp->brklen > 1) {
3932 outb((TDR + portp->uartaddr), ioaddr);
3933 outb(ETC_CMD, (ioaddr + EREG_DATA));
3934 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
3938 outb((COR2 + portp->uartaddr), ioaddr);
3939 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
3940 (ioaddr + EREG_DATA));
3946 /*****************************************************************************/
3949 * Transmit interrupt handler. This has gotta be fast! Handling TX
3950 * chars is pretty simple, stuff as many as possible from the TX buffer
3951 * into the cd1400 FIFO. Must also handle TX breaks here, since they
3952 * are embedded as commands in the data stream. Oh no, had to use a goto!
3953 * This could be optimized more, will do when I get time...
3954 * In practice it is possible that interrupts are enabled but that the
3955 * port has been hung up. Need to handle not having any TX buffer here,
3956 * this is done by using the side effect that head and tail will also
3957 * be NULL if the buffer has been freed.
3960 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
3965 unsigned char ioack, srer;
3968 printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
3971 ioack = inb(ioaddr + EREG_TXACK);
3972 if (((ioack & panelp->ackmask) != 0) ||
3973 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
3974 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
3977 portp = panelp->ports[(ioack >> 3)];
3980 * Unfortunately we need to handle breaks in the data stream, since
3981 * this is the only way to generate them on the cd1400. Do it now if
3982 * a break is to be sent.
3984 if (portp->brklen != 0)
3985 if (stl_cd1400breakisr(portp, ioaddr))
3988 head = portp->tx.head;
3989 tail = portp->tx.tail;
3990 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
3991 if ((len == 0) || ((len < STL_TXBUFLOW) &&
3992 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
3993 set_bit(ASYI_TXLOW, &portp->istate);
3994 schedule_work(&portp->tqueue);
3998 outb((SRER + portp->uartaddr), ioaddr);
3999 srer = inb(ioaddr + EREG_DATA);
4000 if (srer & SRER_TXDATA) {
4001 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
4003 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
4004 clear_bit(ASYI_TXBUSY, &portp->istate);
4006 outb(srer, (ioaddr + EREG_DATA));
4008 len = MIN(len, CD1400_TXFIFOSIZE);
4009 portp->stats.txtotal += len;
4010 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4011 outb((TDR + portp->uartaddr), ioaddr);
4012 outsb((ioaddr + EREG_DATA), tail, stlen);
4015 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4016 tail = portp->tx.buf;
4018 outsb((ioaddr + EREG_DATA), tail, len);
4021 portp->tx.tail = tail;
4025 outb((EOSRR + portp->uartaddr), ioaddr);
4026 outb(0, (ioaddr + EREG_DATA));
4029 /*****************************************************************************/
4032 * Receive character interrupt handler. Determine if we have good chars
4033 * or bad chars and then process appropriately. Good chars are easy
4034 * just shove the lot into the RX buffer and set all status byte to 0.
4035 * If a bad RX char then process as required. This routine needs to be
4036 * fast! In practice it is possible that we get an interrupt on a port
4037 * that is closed. This can happen on hangups - since they completely
4038 * shutdown a port not in user context. Need to handle this case.
4041 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
4044 struct tty_struct *tty;
4045 unsigned int ioack, len, buflen;
4046 unsigned char status;
4050 printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
4053 ioack = inb(ioaddr + EREG_RXACK);
4054 if ((ioack & panelp->ackmask) != 0) {
4055 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4058 portp = panelp->ports[(ioack >> 3)];
4061 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
4062 outb((RDCR + portp->uartaddr), ioaddr);
4063 len = inb(ioaddr + EREG_DATA);
4064 if ((tty == (struct tty_struct *) NULL) ||
4065 (tty->flip.char_buf_ptr == (char *) NULL) ||
4066 ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
4067 len = MIN(len, sizeof(stl_unwanted));
4068 outb((RDSR + portp->uartaddr), ioaddr);
4069 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
4070 portp->stats.rxlost += len;
4071 portp->stats.rxtotal += len;
4073 len = MIN(len, buflen);
4075 outb((RDSR + portp->uartaddr), ioaddr);
4076 insb((ioaddr + EREG_DATA), tty->flip.char_buf_ptr, len);
4077 memset(tty->flip.flag_buf_ptr, 0, len);
4078 tty->flip.flag_buf_ptr += len;
4079 tty->flip.char_buf_ptr += len;
4080 tty->flip.count += len;
4081 tty_schedule_flip(tty);
4082 portp->stats.rxtotal += len;
4085 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
4086 outb((RDSR + portp->uartaddr), ioaddr);
4087 status = inb(ioaddr + EREG_DATA);
4088 ch = inb(ioaddr + EREG_DATA);
4089 if (status & ST_PARITY)
4090 portp->stats.rxparity++;
4091 if (status & ST_FRAMING)
4092 portp->stats.rxframing++;
4093 if (status & ST_OVERRUN)
4094 portp->stats.rxoverrun++;
4095 if (status & ST_BREAK)
4096 portp->stats.rxbreaks++;
4097 if (status & ST_SCHARMASK) {
4098 if ((status & ST_SCHARMASK) == ST_SCHAR1)
4099 portp->stats.txxon++;
4100 if ((status & ST_SCHARMASK) == ST_SCHAR2)
4101 portp->stats.txxoff++;
4104 if ((tty != (struct tty_struct *) NULL) &&
4105 ((portp->rxignoremsk & status) == 0)) {
4106 if (portp->rxmarkmsk & status) {
4107 if (status & ST_BREAK) {
4109 if (portp->flags & ASYNC_SAK) {
4111 BRDENABLE(portp->brdnr, portp->pagenr);
4113 } else if (status & ST_PARITY) {
4114 status = TTY_PARITY;
4115 } else if (status & ST_FRAMING) {
4117 } else if(status & ST_OVERRUN) {
4118 status = TTY_OVERRUN;
4125 if (tty->flip.char_buf_ptr != (char *) NULL) {
4126 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
4127 *tty->flip.flag_buf_ptr++ = status;
4128 *tty->flip.char_buf_ptr++ = ch;
4131 tty_schedule_flip(tty);
4135 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4140 outb((EOSRR + portp->uartaddr), ioaddr);
4141 outb(0, (ioaddr + EREG_DATA));
4144 /*****************************************************************************/
4147 * Modem interrupt handler. The is called when the modem signal line
4148 * (DCD) has changed state. Leave most of the work to the off-level
4149 * processing routine.
4152 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
4159 printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp);
4162 ioack = inb(ioaddr + EREG_MDACK);
4163 if (((ioack & panelp->ackmask) != 0) ||
4164 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
4165 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
4168 portp = panelp->ports[(ioack >> 3)];
4170 outb((MISR + portp->uartaddr), ioaddr);
4171 misr = inb(ioaddr + EREG_DATA);
4172 if (misr & MISR_DCD) {
4173 set_bit(ASYI_DCDCHANGE, &portp->istate);
4174 schedule_work(&portp->tqueue);
4175 portp->stats.modem++;
4178 outb((EOSRR + portp->uartaddr), ioaddr);
4179 outb(0, (ioaddr + EREG_DATA));
4182 /*****************************************************************************/
4183 /* SC26198 HARDWARE FUNCTIONS */
4184 /*****************************************************************************/
4187 * These functions get/set/update the registers of the sc26198 UARTs.
4188 * Access to the sc26198 registers is via an address/data io port pair.
4189 * (Maybe should make this inline...)
4192 static int stl_sc26198getreg(stlport_t *portp, int regnr)
4194 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4195 return(inb(portp->ioaddr + XP_DATA));
4198 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
4200 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4201 outb(value, (portp->ioaddr + XP_DATA));
4204 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
4206 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4207 if (inb(portp->ioaddr + XP_DATA) != value) {
4208 outb(value, (portp->ioaddr + XP_DATA));
4214 /*****************************************************************************/
4217 * Functions to get and set the sc26198 global registers.
4220 static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
4222 outb(regnr, (portp->ioaddr + XP_ADDR));
4223 return(inb(portp->ioaddr + XP_DATA));
4227 static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
4229 outb(regnr, (portp->ioaddr + XP_ADDR));
4230 outb(value, (portp->ioaddr + XP_DATA));
4234 /*****************************************************************************/
4237 * Inbitialize the UARTs in a panel. We don't care what sort of board
4238 * these ports are on - since the port io registers are almost
4239 * identical when dealing with ports.
4242 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
4245 int nrchips, ioaddr;
4248 printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
4249 (int) brdp, (int) panelp);
4252 BRDENABLE(panelp->brdnr, panelp->pagenr);
4255 * Check that each chip is present and started up OK.
4258 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
4259 if (brdp->brdtype == BRD_ECHPCI)
4260 outb(panelp->pagenr, brdp->ioctrl);
4262 for (i = 0; (i < nrchips); i++) {
4263 ioaddr = panelp->iobase + (i * 4);
4264 outb(SCCR, (ioaddr + XP_ADDR));
4265 outb(CR_RESETALL, (ioaddr + XP_DATA));
4266 outb(TSTR, (ioaddr + XP_ADDR));
4267 if (inb(ioaddr + XP_DATA) != 0) {
4268 printk("STALLION: sc26198 not responding, "
4269 "brd=%d panel=%d chip=%d\n",
4270 panelp->brdnr, panelp->panelnr, i);
4273 chipmask |= (0x1 << i);
4274 outb(GCCR, (ioaddr + XP_ADDR));
4275 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
4276 outb(WDTRCR, (ioaddr + XP_ADDR));
4277 outb(0xff, (ioaddr + XP_DATA));
4280 BRDDISABLE(panelp->brdnr);
4284 /*****************************************************************************/
4287 * Initialize hardware specific port registers.
4290 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
4293 printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
4294 (int) brdp, (int) panelp, (int) portp);
4297 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
4298 (portp == (stlport_t *) NULL))
4301 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
4302 portp->uartaddr = (portp->portnr & 0x07) << 4;
4303 portp->pagenr = panelp->pagenr;
4306 BRDENABLE(portp->brdnr, portp->pagenr);
4307 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
4308 BRDDISABLE(portp->brdnr);
4311 /*****************************************************************************/
4314 * Set up the sc26198 registers for a port based on the termios port
4318 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4321 unsigned long flags;
4322 unsigned int baudrate;
4323 unsigned char mr0, mr1, mr2, clk;
4324 unsigned char imron, imroff, iopr, ipr;
4334 brdp = stl_brds[portp->brdnr];
4335 if (brdp == (stlbrd_t *) NULL)
4339 * Set up the RX char ignore mask with those RX error types we
4342 portp->rxignoremsk = 0;
4343 if (tiosp->c_iflag & IGNPAR)
4344 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
4346 if (tiosp->c_iflag & IGNBRK)
4347 portp->rxignoremsk |= SR_RXBREAK;
4349 portp->rxmarkmsk = SR_RXOVERRUN;
4350 if (tiosp->c_iflag & (INPCK | PARMRK))
4351 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
4352 if (tiosp->c_iflag & BRKINT)
4353 portp->rxmarkmsk |= SR_RXBREAK;
4356 * Go through the char size, parity and stop bits and set all the
4357 * option register appropriately.
4359 switch (tiosp->c_cflag & CSIZE) {
4374 if (tiosp->c_cflag & CSTOPB)
4379 if (tiosp->c_cflag & PARENB) {
4380 if (tiosp->c_cflag & PARODD)
4381 mr1 |= (MR1_PARENB | MR1_PARODD);
4383 mr1 |= (MR1_PARENB | MR1_PAREVEN);
4388 mr1 |= MR1_ERRBLOCK;
4391 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4392 * space for hardware flow control and the like. This should be set to
4395 mr2 |= MR2_RXFIFOHALF;
4398 * Calculate the baud rate timers. For now we will just assume that
4399 * the input and output baud are the same. The sc26198 has a fixed
4400 * baud rate table, so only discrete baud rates possible.
4402 baudrate = tiosp->c_cflag & CBAUD;
4403 if (baudrate & CBAUDEX) {
4404 baudrate &= ~CBAUDEX;
4405 if ((baudrate < 1) || (baudrate > 4))
4406 tiosp->c_cflag &= ~CBAUDEX;
4410 baudrate = stl_baudrates[baudrate];
4411 if ((tiosp->c_cflag & CBAUD) == B38400) {
4412 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
4414 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
4416 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
4418 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
4420 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
4421 baudrate = (portp->baud_base / portp->custom_divisor);
4423 if (baudrate > STL_SC26198MAXBAUD)
4424 baudrate = STL_SC26198MAXBAUD;
4427 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
4428 if (baudrate <= sc26198_baudtable[clk])
4434 * Check what form of modem signaling is required and set it up.
4436 if (tiosp->c_cflag & CLOCAL) {
4437 portp->flags &= ~ASYNC_CHECK_CD;
4439 iopr |= IOPR_DCDCOS;
4441 portp->flags |= ASYNC_CHECK_CD;
4445 * Setup sc26198 enhanced modes if we can. In particular we want to
4446 * handle as much of the flow control as possible automatically. As
4447 * well as saving a few CPU cycles it will also greatly improve flow
4448 * control reliability.
4450 if (tiosp->c_iflag & IXON) {
4451 mr0 |= MR0_SWFTX | MR0_SWFT;
4452 imron |= IR_XONXOFF;
4454 imroff |= IR_XONXOFF;
4456 if (tiosp->c_iflag & IXOFF)
4459 if (tiosp->c_cflag & CRTSCTS) {
4465 * All sc26198 register values calculated so go through and set
4470 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4471 portp->portnr, portp->panelnr, portp->brdnr);
4472 printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4473 printk(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4474 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4475 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4476 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4481 BRDENABLE(portp->brdnr, portp->pagenr);
4482 stl_sc26198setreg(portp, IMR, 0);
4483 stl_sc26198updatereg(portp, MR0, mr0);
4484 stl_sc26198updatereg(portp, MR1, mr1);
4485 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4486 stl_sc26198updatereg(portp, MR2, mr2);
4487 stl_sc26198updatereg(portp, IOPIOR,
4488 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
4491 stl_sc26198setreg(portp, TXCSR, clk);
4492 stl_sc26198setreg(portp, RXCSR, clk);
4495 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4496 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4498 ipr = stl_sc26198getreg(portp, IPR);
4500 portp->sigs &= ~TIOCM_CD;
4502 portp->sigs |= TIOCM_CD;
4504 portp->imr = (portp->imr & ~imroff) | imron;
4505 stl_sc26198setreg(portp, IMR, portp->imr);
4506 BRDDISABLE(portp->brdnr);
4507 restore_flags(flags);
4510 /*****************************************************************************/
4513 * Set the state of the DTR and RTS signals.
4516 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
4518 unsigned char iopioron, iopioroff;
4519 unsigned long flags;
4522 printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4523 (int) portp, dtr, rts);
4529 iopioroff |= IPR_DTR;
4531 iopioron |= IPR_DTR;
4533 iopioroff |= IPR_RTS;
4535 iopioron |= IPR_RTS;
4539 BRDENABLE(portp->brdnr, portp->pagenr);
4540 stl_sc26198setreg(portp, IOPIOR,
4541 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4542 BRDDISABLE(portp->brdnr);
4543 restore_flags(flags);
4546 /*****************************************************************************/
4549 * Return the state of the signals.
4552 static int stl_sc26198getsignals(stlport_t *portp)
4555 unsigned long flags;
4559 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
4564 BRDENABLE(portp->brdnr, portp->pagenr);
4565 ipr = stl_sc26198getreg(portp, IPR);
4566 BRDDISABLE(portp->brdnr);
4567 restore_flags(flags);
4570 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4571 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4572 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4573 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4578 /*****************************************************************************/
4581 * Enable/Disable the Transmitter and/or Receiver.
4584 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
4587 unsigned long flags;
4590 printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4591 (int) portp, rx, tx);
4594 ccr = portp->crenable;
4596 ccr &= ~CR_TXENABLE;
4600 ccr &= ~CR_RXENABLE;
4606 BRDENABLE(portp->brdnr, portp->pagenr);
4607 stl_sc26198setreg(portp, SCCR, ccr);
4608 BRDDISABLE(portp->brdnr);
4609 portp->crenable = ccr;
4610 restore_flags(flags);
4613 /*****************************************************************************/
4616 * Start/stop the Transmitter and/or Receiver.
4619 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
4622 unsigned long flags;
4625 printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4626 (int) portp, rx, tx);
4635 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4637 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4641 BRDENABLE(portp->brdnr, portp->pagenr);
4642 stl_sc26198setreg(portp, IMR, imr);
4643 BRDDISABLE(portp->brdnr);
4646 set_bit(ASYI_TXBUSY, &portp->istate);
4647 restore_flags(flags);
4650 /*****************************************************************************/
4653 * Disable all interrupts from this port.
4656 static void stl_sc26198disableintrs(stlport_t *portp)
4658 unsigned long flags;
4661 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
4666 BRDENABLE(portp->brdnr, portp->pagenr);
4668 stl_sc26198setreg(portp, IMR, 0);
4669 BRDDISABLE(portp->brdnr);
4670 restore_flags(flags);
4673 /*****************************************************************************/
4675 static void stl_sc26198sendbreak(stlport_t *portp, int len)
4677 unsigned long flags;
4680 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
4685 BRDENABLE(portp->brdnr, portp->pagenr);
4687 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4688 portp->stats.txbreaks++;
4690 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4692 BRDDISABLE(portp->brdnr);
4693 restore_flags(flags);
4696 /*****************************************************************************/
4699 * Take flow control actions...
4702 static void stl_sc26198flowctrl(stlport_t *portp, int state)
4704 struct tty_struct *tty;
4705 unsigned long flags;
4709 printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp, state);
4712 if (portp == (stlport_t *) NULL)
4715 if (tty == (struct tty_struct *) NULL)
4720 BRDENABLE(portp->brdnr, portp->pagenr);
4723 if (tty->termios->c_iflag & IXOFF) {
4724 mr0 = stl_sc26198getreg(portp, MR0);
4725 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4726 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4728 portp->stats.rxxon++;
4729 stl_sc26198wait(portp);
4730 stl_sc26198setreg(portp, MR0, mr0);
4733 * Question: should we return RTS to what it was before? It may
4734 * have been set by an ioctl... Suppose not, since if you have
4735 * hardware flow control set then it is pretty silly to go and
4736 * set the RTS line by hand.
4738 if (tty->termios->c_cflag & CRTSCTS) {
4739 stl_sc26198setreg(portp, MR1,
4740 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4741 stl_sc26198setreg(portp, IOPIOR,
4742 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4743 portp->stats.rxrtson++;
4746 if (tty->termios->c_iflag & IXOFF) {
4747 mr0 = stl_sc26198getreg(portp, MR0);
4748 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4749 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4751 portp->stats.rxxoff++;
4752 stl_sc26198wait(portp);
4753 stl_sc26198setreg(portp, MR0, mr0);
4755 if (tty->termios->c_cflag & CRTSCTS) {
4756 stl_sc26198setreg(portp, MR1,
4757 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4758 stl_sc26198setreg(portp, IOPIOR,
4759 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4760 portp->stats.rxrtsoff++;
4764 BRDDISABLE(portp->brdnr);
4765 restore_flags(flags);
4768 /*****************************************************************************/
4771 * Send a flow control character.
4774 static void stl_sc26198sendflow(stlport_t *portp, int state)
4776 struct tty_struct *tty;
4777 unsigned long flags;
4781 printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp, state);
4784 if (portp == (stlport_t *) NULL)
4787 if (tty == (struct tty_struct *) NULL)
4792 BRDENABLE(portp->brdnr, portp->pagenr);
4794 mr0 = stl_sc26198getreg(portp, MR0);
4795 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4796 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4798 portp->stats.rxxon++;
4799 stl_sc26198wait(portp);
4800 stl_sc26198setreg(portp, MR0, mr0);
4802 mr0 = stl_sc26198getreg(portp, MR0);
4803 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4804 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4806 portp->stats.rxxoff++;
4807 stl_sc26198wait(portp);
4808 stl_sc26198setreg(portp, MR0, mr0);
4810 BRDDISABLE(portp->brdnr);
4811 restore_flags(flags);
4814 /*****************************************************************************/
4816 static void stl_sc26198flush(stlport_t *portp)
4818 unsigned long flags;
4821 printk("stl_sc26198flush(portp=%x)\n", (int) portp);
4824 if (portp == (stlport_t *) NULL)
4829 BRDENABLE(portp->brdnr, portp->pagenr);
4830 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4831 stl_sc26198setreg(portp, SCCR, portp->crenable);
4832 BRDDISABLE(portp->brdnr);
4833 portp->tx.tail = portp->tx.head;
4834 restore_flags(flags);
4837 /*****************************************************************************/
4840 * Return the current state of data flow on this port. This is only
4841 * really interresting when determining if data has fully completed
4842 * transmission or not... The sc26198 interrupt scheme cannot
4843 * determine when all data has actually drained, so we need to
4844 * check the port statusy register to be sure.
4847 static int stl_sc26198datastate(stlport_t *portp)
4849 unsigned long flags;
4853 printk("stl_sc26198datastate(portp=%x)\n", (int) portp);
4856 if (portp == (stlport_t *) NULL)
4858 if (test_bit(ASYI_TXBUSY, &portp->istate))
4863 BRDENABLE(portp->brdnr, portp->pagenr);
4864 sr = stl_sc26198getreg(portp, SR);
4865 BRDDISABLE(portp->brdnr);
4866 restore_flags(flags);
4868 return((sr & SR_TXEMPTY) ? 0 : 1);
4871 /*****************************************************************************/
4874 * Delay for a small amount of time, to give the sc26198 a chance
4875 * to process a command...
4878 static void stl_sc26198wait(stlport_t *portp)
4883 printk("stl_sc26198wait(portp=%x)\n", (int) portp);
4886 if (portp == (stlport_t *) NULL)
4889 for (i = 0; (i < 20); i++)
4890 stl_sc26198getglobreg(portp, TSTR);
4893 /*****************************************************************************/
4896 * If we are TX flow controlled and in IXANY mode then we may
4897 * need to unflow control here. We gotta do this because of the
4898 * automatic flow control modes of the sc26198.
4901 static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty)
4905 mr0 = stl_sc26198getreg(portp, MR0);
4906 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4907 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4908 stl_sc26198wait(portp);
4909 stl_sc26198setreg(portp, MR0, mr0);
4910 clear_bit(ASYI_TXFLOWED, &portp->istate);
4913 /*****************************************************************************/
4916 * Interrupt service routine for sc26198 panels.
4919 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4925 * Work around bug in sc26198 chip... Cannot have A6 address
4926 * line of UART high, else iack will be returned as 0.
4928 outb(0, (iobase + 1));
4930 iack = inb(iobase + XP_IACK);
4931 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4933 if (iack & IVR_RXDATA)
4934 stl_sc26198rxisr(portp, iack);
4935 else if (iack & IVR_TXDATA)
4936 stl_sc26198txisr(portp);
4938 stl_sc26198otherisr(portp, iack);
4941 /*****************************************************************************/
4944 * Transmit interrupt handler. This has gotta be fast! Handling TX
4945 * chars is pretty simple, stuff as many as possible from the TX buffer
4946 * into the sc26198 FIFO.
4947 * In practice it is possible that interrupts are enabled but that the
4948 * port has been hung up. Need to handle not having any TX buffer here,
4949 * this is done by using the side effect that head and tail will also
4950 * be NULL if the buffer has been freed.
4953 static void stl_sc26198txisr(stlport_t *portp)
4955 unsigned int ioaddr;
4961 printk("stl_sc26198txisr(portp=%x)\n", (int) portp);
4964 ioaddr = portp->ioaddr;
4965 head = portp->tx.head;
4966 tail = portp->tx.tail;
4967 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4968 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4969 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4970 set_bit(ASYI_TXLOW, &portp->istate);
4971 schedule_work(&portp->tqueue);
4975 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
4976 mr0 = inb(ioaddr + XP_DATA);
4977 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4978 portp->imr &= ~IR_TXRDY;
4979 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
4980 outb(portp->imr, (ioaddr + XP_DATA));
4981 clear_bit(ASYI_TXBUSY, &portp->istate);
4983 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4984 outb(mr0, (ioaddr + XP_DATA));
4987 len = MIN(len, SC26198_TXFIFOSIZE);
4988 portp->stats.txtotal += len;
4989 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4990 outb(GTXFIFO, (ioaddr + XP_ADDR));
4991 outsb((ioaddr + XP_DATA), tail, stlen);
4994 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4995 tail = portp->tx.buf;
4997 outsb((ioaddr + XP_DATA), tail, len);
5000 portp->tx.tail = tail;
5004 /*****************************************************************************/
5007 * Receive character interrupt handler. Determine if we have good chars
5008 * or bad chars and then process appropriately. Good chars are easy
5009 * just shove the lot into the RX buffer and set all status byte to 0.
5010 * If a bad RX char then process as required. This routine needs to be
5011 * fast! In practice it is possible that we get an interrupt on a port
5012 * that is closed. This can happen on hangups - since they completely
5013 * shutdown a port not in user context. Need to handle this case.
5016 static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
5018 struct tty_struct *tty;
5019 unsigned int len, buflen, ioaddr;
5022 printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
5026 ioaddr = portp->ioaddr;
5027 outb(GIBCR, (ioaddr + XP_ADDR));
5028 len = inb(ioaddr + XP_DATA) + 1;
5030 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
5031 if ((tty == (struct tty_struct *) NULL) ||
5032 (tty->flip.char_buf_ptr == (char *) NULL) ||
5033 ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
5034 len = MIN(len, sizeof(stl_unwanted));
5035 outb(GRXFIFO, (ioaddr + XP_ADDR));
5036 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
5037 portp->stats.rxlost += len;
5038 portp->stats.rxtotal += len;
5040 len = MIN(len, buflen);
5042 outb(GRXFIFO, (ioaddr + XP_ADDR));
5043 insb((ioaddr + XP_DATA), tty->flip.char_buf_ptr, len);
5044 memset(tty->flip.flag_buf_ptr, 0, len);
5045 tty->flip.flag_buf_ptr += len;
5046 tty->flip.char_buf_ptr += len;
5047 tty->flip.count += len;
5048 tty_schedule_flip(tty);
5049 portp->stats.rxtotal += len;
5053 stl_sc26198rxbadchars(portp);
5057 * If we are TX flow controlled and in IXANY mode then we may need
5058 * to unflow control here. We gotta do this because of the automatic
5059 * flow control modes of the sc26198.
5061 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
5062 if ((tty != (struct tty_struct *) NULL) &&
5063 (tty->termios != (struct termios *) NULL) &&
5064 (tty->termios->c_iflag & IXANY)) {
5065 stl_sc26198txunflow(portp, tty);
5070 /*****************************************************************************/
5073 * Process an RX bad character.
5076 static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch)
5078 struct tty_struct *tty;
5079 unsigned int ioaddr;
5082 ioaddr = portp->ioaddr;
5084 if (status & SR_RXPARITY)
5085 portp->stats.rxparity++;
5086 if (status & SR_RXFRAMING)
5087 portp->stats.rxframing++;
5088 if (status & SR_RXOVERRUN)
5089 portp->stats.rxoverrun++;
5090 if (status & SR_RXBREAK)
5091 portp->stats.rxbreaks++;
5093 if ((tty != (struct tty_struct *) NULL) &&
5094 ((portp->rxignoremsk & status) == 0)) {
5095 if (portp->rxmarkmsk & status) {
5096 if (status & SR_RXBREAK) {
5098 if (portp->flags & ASYNC_SAK) {
5100 BRDENABLE(portp->brdnr, portp->pagenr);
5102 } else if (status & SR_RXPARITY) {
5103 status = TTY_PARITY;
5104 } else if (status & SR_RXFRAMING) {
5106 } else if(status & SR_RXOVERRUN) {
5107 status = TTY_OVERRUN;
5115 if (tty->flip.char_buf_ptr != (char *) NULL) {
5116 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
5117 *tty->flip.flag_buf_ptr++ = status;
5118 *tty->flip.char_buf_ptr++ = ch;
5121 tty_schedule_flip(tty);
5125 portp->stats.rxtotal++;
5129 /*****************************************************************************/
5132 * Process all characters in the RX FIFO of the UART. Check all char
5133 * status bytes as well, and process as required. We need to check
5134 * all bytes in the FIFO, in case some more enter the FIFO while we
5135 * are here. To get the exact character error type we need to switch
5136 * into CHAR error mode (that is why we need to make sure we empty
5140 static void stl_sc26198rxbadchars(stlport_t *portp)
5142 unsigned char status, mr1;
5146 * To get the precise error type for each character we must switch
5147 * back into CHAR error mode.
5149 mr1 = stl_sc26198getreg(portp, MR1);
5150 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
5152 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
5153 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
5154 ch = stl_sc26198getreg(portp, RXFIFO);
5155 stl_sc26198rxbadch(portp, status, ch);
5159 * To get correct interrupt class we must switch back into BLOCK
5162 stl_sc26198setreg(portp, MR1, mr1);
5165 /*****************************************************************************/
5168 * Other interrupt handler. This includes modem signals, flow
5169 * control actions, etc. Most stuff is left to off-level interrupt
5173 static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
5175 unsigned char cir, ipr, xisr;
5178 printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
5181 cir = stl_sc26198getglobreg(portp, CIR);
5183 switch (cir & CIR_SUBTYPEMASK) {
5185 ipr = stl_sc26198getreg(portp, IPR);
5186 if (ipr & IPR_DCDCHANGE) {
5187 set_bit(ASYI_DCDCHANGE, &portp->istate);
5188 schedule_work(&portp->tqueue);
5189 portp->stats.modem++;
5192 case CIR_SUBXONXOFF:
5193 xisr = stl_sc26198getreg(portp, XISR);
5194 if (xisr & XISR_RXXONGOT) {
5195 set_bit(ASYI_TXFLOWED, &portp->istate);
5196 portp->stats.txxoff++;
5198 if (xisr & XISR_RXXOFFGOT) {
5199 clear_bit(ASYI_TXFLOWED, &portp->istate);
5200 portp->stats.txxon++;
5204 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
5205 stl_sc26198rxbadchars(portp);
5212 /*****************************************************************************/