1 /*****************************************************************************/
4 * stallion.c -- stallion multiport serial driver.
6 * Copyright (C) 1996-1999 Stallion Technologies
7 * Copyright (C) 1994-1996 Greg Ungerer.
9 * This code is loosely based on the Linux serial driver, written by
10 * Linus Torvalds, Theodore T'so and others.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /*****************************************************************************/
29 #include <linux/module.h>
30 #include <linux/slab.h>
31 #include <linux/interrupt.h>
32 #include <linux/tty.h>
33 #include <linux/tty_flip.h>
34 #include <linux/serial.h>
35 #include <linux/cd1400.h>
36 #include <linux/sc26198.h>
37 #include <linux/comstats.h>
38 #include <linux/stallion.h>
39 #include <linux/ioport.h>
40 #include <linux/init.h>
41 #include <linux/smp_lock.h>
42 #include <linux/device.h>
43 #include <linux/delay.h>
46 #include <asm/uaccess.h>
49 #include <linux/pci.h>
52 /*****************************************************************************/
55 * Define different board types. Use the standard Stallion "assigned"
56 * board numbers. Boards supported in this driver are abbreviated as
57 * EIO = EasyIO and ECH = EasyConnection 8/32.
63 #define BRD_ECH64PCI 27
64 #define BRD_EASYIOPCI 28
67 * Define a configuration structure to hold the board configuration.
68 * Need to set this up in the code (for now) with the boards that are
69 * to be configured into the system. This is what needs to be modified
70 * when adding/removing/modifying boards. Each line entry in the
71 * stl_brdconf[] array is a board. Each line contains io/irq/memory
72 * ranges for that board (as well as what type of board it is).
74 * { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
75 * This line would configure an EasyIO board (4 or 8, no difference),
76 * at io address 2a0 and irq 10.
78 * { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
79 * This line will configure an EasyConnection 8/32 board at primary io
80 * address 2a8, secondary io address 280 and irq 12.
81 * Enter as many lines into this array as you want (only the first 4
82 * will actually be used!). Any combination of EasyIO and EasyConnection
83 * boards can be specified. EasyConnection 8/32 boards can share their
84 * secondary io addresses between each other.
86 * NOTE: there is no need to put any entries in this table for PCI
87 * boards. They will be found automatically by the driver - provided
88 * PCI BIOS32 support is compiled into the kernel.
95 unsigned long memaddr;
100 static stlconf_t stl_brdconf[] = {
101 /*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
104 static int stl_nrbrds = ARRAY_SIZE(stl_brdconf);
106 /*****************************************************************************/
109 * Define some important driver characteristics. Device major numbers
110 * allocated as per Linux Device Registry.
112 #ifndef STL_SIOMEMMAJOR
113 #define STL_SIOMEMMAJOR 28
115 #ifndef STL_SERIALMAJOR
116 #define STL_SERIALMAJOR 24
118 #ifndef STL_CALLOUTMAJOR
119 #define STL_CALLOUTMAJOR 25
123 * Set the TX buffer size. Bigger is better, but we don't want
124 * to chew too much memory with buffers!
126 #define STL_TXBUFLOW 512
127 #define STL_TXBUFSIZE 4096
129 /*****************************************************************************/
132 * Define our local driver identity first. Set up stuff to deal with
133 * all the local structures required by a serial tty driver.
135 static char *stl_drvtitle = "Stallion Multiport Serial Driver";
136 static char *stl_drvname = "stallion";
137 static char *stl_drvversion = "5.6.0";
139 static struct tty_driver *stl_serial;
142 * Define a local default termios struct. All ports will be created
143 * with this termios initially. Basically all it defines is a raw port
144 * at 9600, 8 data bits, 1 stop bit.
146 static struct termios stl_deftermios = {
147 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
152 * Define global stats structures. Not used often, and can be
153 * re-used for each stats call.
155 static comstats_t stl_comstats;
156 static combrd_t stl_brdstats;
157 static stlbrd_t stl_dummybrd;
158 static stlport_t stl_dummyport;
161 * Define global place to put buffer overflow characters.
163 static char stl_unwanted[SC26198_RXFIFOSIZE];
165 /*****************************************************************************/
167 static stlbrd_t *stl_brds[STL_MAXBRDS];
170 * Per board state flags. Used with the state field of the board struct.
171 * Not really much here!
173 #define BRD_FOUND 0x1
176 * Define the port structure istate flags. These set of flags are
177 * modified at interrupt time - so setting and reseting them needs
178 * to be atomic. Use the bit clear/setting routines for this.
180 #define ASYI_TXBUSY 1
182 #define ASYI_DCDCHANGE 3
183 #define ASYI_TXFLOWED 4
186 * Define an array of board names as printable strings. Handy for
187 * referencing boards when printing trace and stuff.
189 static char *stl_brdnames[] = {
221 /*****************************************************************************/
224 * Define some string labels for arguments passed from the module
225 * load line. These allow for easy board definitions, and easy
226 * modification of the io, memory and irq resoucres.
228 static int stl_nargs = 0;
229 static char *board0[4];
230 static char *board1[4];
231 static char *board2[4];
232 static char *board3[4];
234 static char **stl_brdsp[] = {
242 * Define a set of common board names, and types. This is used to
243 * parse any module arguments.
246 typedef struct stlbrdtype {
251 static stlbrdtype_t stl_brdstr[] = {
252 { "easyio", BRD_EASYIO },
253 { "eio", BRD_EASYIO },
254 { "20", BRD_EASYIO },
255 { "ec8/32", BRD_ECH },
256 { "ec8/32-at", BRD_ECH },
257 { "ec8/32-isa", BRD_ECH },
259 { "echat", BRD_ECH },
261 { "ec8/32-mc", BRD_ECHMC },
262 { "ec8/32-mca", BRD_ECHMC },
263 { "echmc", BRD_ECHMC },
264 { "echmca", BRD_ECHMC },
266 { "ec8/32-pc", BRD_ECHPCI },
267 { "ec8/32-pci", BRD_ECHPCI },
268 { "26", BRD_ECHPCI },
269 { "ec8/64-pc", BRD_ECH64PCI },
270 { "ec8/64-pci", BRD_ECH64PCI },
271 { "ech-pci", BRD_ECH64PCI },
272 { "echpci", BRD_ECH64PCI },
273 { "echpc", BRD_ECH64PCI },
274 { "27", BRD_ECH64PCI },
275 { "easyio-pc", BRD_EASYIOPCI },
276 { "easyio-pci", BRD_EASYIOPCI },
277 { "eio-pci", BRD_EASYIOPCI },
278 { "eiopci", BRD_EASYIOPCI },
279 { "28", BRD_EASYIOPCI },
283 * Define the module agruments.
285 MODULE_AUTHOR("Greg Ungerer");
286 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
287 MODULE_LICENSE("GPL");
289 module_param_array(board0, charp, &stl_nargs, 0);
290 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
291 module_param_array(board1, charp, &stl_nargs, 0);
292 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
293 module_param_array(board2, charp, &stl_nargs, 0);
294 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
295 module_param_array(board3, charp, &stl_nargs, 0);
296 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
298 /*****************************************************************************/
301 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
302 * to the directly accessible io ports of these boards (not the uarts -
303 * they are in cd1400.h and sc26198.h).
305 #define EIO_8PORTRS 0x04
306 #define EIO_4PORTRS 0x05
307 #define EIO_8PORTDI 0x00
308 #define EIO_8PORTM 0x06
310 #define EIO_IDBITMASK 0x07
312 #define EIO_BRDMASK 0xf0
315 #define ID_BRD16 0x30
317 #define EIO_INTRPEND 0x08
318 #define EIO_INTEDGE 0x00
319 #define EIO_INTLEVEL 0x08
323 #define ECH_IDBITMASK 0xe0
324 #define ECH_BRDENABLE 0x08
325 #define ECH_BRDDISABLE 0x00
326 #define ECH_INTENABLE 0x01
327 #define ECH_INTDISABLE 0x00
328 #define ECH_INTLEVEL 0x02
329 #define ECH_INTEDGE 0x00
330 #define ECH_INTRPEND 0x01
331 #define ECH_BRDRESET 0x01
333 #define ECHMC_INTENABLE 0x01
334 #define ECHMC_BRDRESET 0x02
336 #define ECH_PNLSTATUS 2
337 #define ECH_PNL16PORT 0x20
338 #define ECH_PNLIDMASK 0x07
339 #define ECH_PNLXPID 0x40
340 #define ECH_PNLINTRPEND 0x80
342 #define ECH_ADDR2MASK 0x1e0
345 * Define the vector mapping bits for the programmable interrupt board
346 * hardware. These bits encode the interrupt for the board to use - it
347 * is software selectable (except the EIO-8M).
349 static unsigned char stl_vecmap[] = {
350 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
351 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
355 * Lock ordering is that you may not take stallion_lock holding
359 static spinlock_t brd_lock; /* Guard the board mapping */
360 static spinlock_t stallion_lock; /* Guard the tty driver */
363 * Set up enable and disable macros for the ECH boards. They require
364 * the secondary io address space to be activated and deactivated.
365 * This way all ECH boards can share their secondary io region.
366 * If this is an ECH-PCI board then also need to set the page pointer
367 * to point to the correct page.
369 #define BRDENABLE(brdnr,pagenr) \
370 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
371 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
372 stl_brds[(brdnr)]->ioctrl); \
373 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
374 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
376 #define BRDDISABLE(brdnr) \
377 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
378 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
379 stl_brds[(brdnr)]->ioctrl);
381 #define STL_CD1400MAXBAUD 230400
382 #define STL_SC26198MAXBAUD 460800
384 #define STL_BAUDBASE 115200
385 #define STL_CLOSEDELAY (5 * HZ / 10)
387 /*****************************************************************************/
392 * Define the Stallion PCI vendor and device IDs.
394 #ifndef PCI_VENDOR_ID_STALLION
395 #define PCI_VENDOR_ID_STALLION 0x124d
397 #ifndef PCI_DEVICE_ID_ECHPCI832
398 #define PCI_DEVICE_ID_ECHPCI832 0x0000
400 #ifndef PCI_DEVICE_ID_ECHPCI864
401 #define PCI_DEVICE_ID_ECHPCI864 0x0002
403 #ifndef PCI_DEVICE_ID_EIOPCI
404 #define PCI_DEVICE_ID_EIOPCI 0x0003
408 * Define structure to hold all Stallion PCI boards.
410 typedef struct stlpcibrd {
411 unsigned short vendid;
412 unsigned short devid;
416 static stlpcibrd_t stl_pcibrds[] = {
417 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864, BRD_ECH64PCI },
418 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI, BRD_EASYIOPCI },
419 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832, BRD_ECHPCI },
420 { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
423 static int stl_nrpcibrds = ARRAY_SIZE(stl_pcibrds);
427 /*****************************************************************************/
430 * Define macros to extract a brd/port number from a minor number.
432 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
433 #define MINOR2PORT(min) ((min) & 0x3f)
436 * Define a baud rate table that converts termios baud rate selector
437 * into the actual baud rate value. All baud rate calculations are
438 * based on the actual baud rate required.
440 static unsigned int stl_baudrates[] = {
441 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
442 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
446 * Define some handy local macros...
449 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
452 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
454 /*****************************************************************************/
457 * Declare all those functions in this driver!
460 static void stl_argbrds(void);
461 static int stl_parsebrd(stlconf_t *confp, char **argp);
463 static unsigned long stl_atol(char *str);
465 static int stl_init(void);
466 static int stl_open(struct tty_struct *tty, struct file *filp);
467 static void stl_close(struct tty_struct *tty, struct file *filp);
468 static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count);
469 static void stl_putchar(struct tty_struct *tty, unsigned char ch);
470 static void stl_flushchars(struct tty_struct *tty);
471 static int stl_writeroom(struct tty_struct *tty);
472 static int stl_charsinbuffer(struct tty_struct *tty);
473 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
474 static void stl_settermios(struct tty_struct *tty, struct termios *old);
475 static void stl_throttle(struct tty_struct *tty);
476 static void stl_unthrottle(struct tty_struct *tty);
477 static void stl_stop(struct tty_struct *tty);
478 static void stl_start(struct tty_struct *tty);
479 static void stl_flushbuffer(struct tty_struct *tty);
480 static void stl_breakctl(struct tty_struct *tty, int state);
481 static void stl_waituntilsent(struct tty_struct *tty, int timeout);
482 static void stl_sendxchar(struct tty_struct *tty, char ch);
483 static void stl_hangup(struct tty_struct *tty);
484 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
485 static int stl_portinfo(stlport_t *portp, int portnr, char *pos);
486 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data);
488 static int stl_brdinit(stlbrd_t *brdp);
489 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
490 static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp);
491 static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp);
492 static int stl_getbrdstats(combrd_t __user *bp);
493 static int stl_getportstats(stlport_t *portp, comstats_t __user *cp);
494 static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp);
495 static int stl_getportstruct(stlport_t __user *arg);
496 static int stl_getbrdstruct(stlbrd_t __user *arg);
497 static int stl_waitcarrier(stlport_t *portp, struct file *filp);
498 static int stl_eiointr(stlbrd_t *brdp);
499 static int stl_echatintr(stlbrd_t *brdp);
500 static int stl_echmcaintr(stlbrd_t *brdp);
501 static int stl_echpciintr(stlbrd_t *brdp);
502 static int stl_echpci64intr(stlbrd_t *brdp);
503 static void stl_offintr(struct work_struct *);
504 static stlbrd_t *stl_allocbrd(void);
505 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
507 static inline int stl_initbrds(void);
508 static inline int stl_initeio(stlbrd_t *brdp);
509 static inline int stl_initech(stlbrd_t *brdp);
510 static inline int stl_getbrdnr(void);
513 static inline int stl_findpcibrds(void);
514 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp);
518 * CD1400 uart specific handling functions.
520 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value);
521 static int stl_cd1400getreg(stlport_t *portp, int regnr);
522 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value);
523 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
524 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
525 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp);
526 static int stl_cd1400getsignals(stlport_t *portp);
527 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts);
528 static void stl_cd1400ccrwait(stlport_t *portp);
529 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx);
530 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx);
531 static void stl_cd1400disableintrs(stlport_t *portp);
532 static void stl_cd1400sendbreak(stlport_t *portp, int len);
533 static void stl_cd1400flowctrl(stlport_t *portp, int state);
534 static void stl_cd1400sendflow(stlport_t *portp, int state);
535 static void stl_cd1400flush(stlport_t *portp);
536 static int stl_cd1400datastate(stlport_t *portp);
537 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase);
538 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase);
539 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr);
540 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr);
541 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr);
543 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr);
546 * SC26198 uart specific handling functions.
548 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value);
549 static int stl_sc26198getreg(stlport_t *portp, int regnr);
550 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value);
551 static int stl_sc26198getglobreg(stlport_t *portp, int regnr);
552 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
553 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
554 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp);
555 static int stl_sc26198getsignals(stlport_t *portp);
556 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts);
557 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx);
558 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx);
559 static void stl_sc26198disableintrs(stlport_t *portp);
560 static void stl_sc26198sendbreak(stlport_t *portp, int len);
561 static void stl_sc26198flowctrl(stlport_t *portp, int state);
562 static void stl_sc26198sendflow(stlport_t *portp, int state);
563 static void stl_sc26198flush(stlport_t *portp);
564 static int stl_sc26198datastate(stlport_t *portp);
565 static void stl_sc26198wait(stlport_t *portp);
566 static void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty);
567 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase);
568 static void stl_sc26198txisr(stlport_t *port);
569 static void stl_sc26198rxisr(stlport_t *port, unsigned int iack);
570 static void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch);
571 static void stl_sc26198rxbadchars(stlport_t *portp);
572 static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
574 /*****************************************************************************/
577 * Generic UART support structure.
579 typedef struct uart {
580 int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp);
581 void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
582 void (*setport)(stlport_t *portp, struct termios *tiosp);
583 int (*getsignals)(stlport_t *portp);
584 void (*setsignals)(stlport_t *portp, int dtr, int rts);
585 void (*enablerxtx)(stlport_t *portp, int rx, int tx);
586 void (*startrxtx)(stlport_t *portp, int rx, int tx);
587 void (*disableintrs)(stlport_t *portp);
588 void (*sendbreak)(stlport_t *portp, int len);
589 void (*flowctrl)(stlport_t *portp, int state);
590 void (*sendflow)(stlport_t *portp, int state);
591 void (*flush)(stlport_t *portp);
592 int (*datastate)(stlport_t *portp);
593 void (*intr)(stlpanel_t *panelp, unsigned int iobase);
597 * Define some macros to make calling these functions nice and clean.
599 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
600 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
601 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
602 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
603 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
604 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
605 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
606 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
607 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
608 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
609 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
610 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
611 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
613 /*****************************************************************************/
616 * CD1400 UART specific data initialization.
618 static uart_t stl_cd1400uart = {
622 stl_cd1400getsignals,
623 stl_cd1400setsignals,
624 stl_cd1400enablerxtx,
626 stl_cd1400disableintrs,
636 * Define the offsets within the register bank of a cd1400 based panel.
637 * These io address offsets are common to the EasyIO board as well.
645 #define EREG_BANKSIZE 8
647 #define CD1400_CLK 25000000
648 #define CD1400_CLK8M 20000000
651 * Define the cd1400 baud rate clocks. These are used when calculating
652 * what clock and divisor to use for the required baud rate. Also
653 * define the maximum baud rate allowed, and the default base baud.
655 static int stl_cd1400clkdivs[] = {
656 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
659 /*****************************************************************************/
662 * SC26198 UART specific data initization.
664 static uart_t stl_sc26198uart = {
665 stl_sc26198panelinit,
668 stl_sc26198getsignals,
669 stl_sc26198setsignals,
670 stl_sc26198enablerxtx,
671 stl_sc26198startrxtx,
672 stl_sc26198disableintrs,
673 stl_sc26198sendbreak,
677 stl_sc26198datastate,
682 * Define the offsets within the register bank of a sc26198 based panel.
690 #define XP_BANKSIZE 4
693 * Define the sc26198 baud rate table. Offsets within the table
694 * represent the actual baud rate selector of sc26198 registers.
696 static unsigned int sc26198_baudtable[] = {
697 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
698 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
699 230400, 460800, 921600
702 #define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
704 /*****************************************************************************/
707 * Define the driver info for a user level control device. Used mainly
708 * to get at port stats - only not using the port device itself.
710 static const struct file_operations stl_fsiomem = {
711 .owner = THIS_MODULE,
712 .ioctl = stl_memioctl,
715 /*****************************************************************************/
717 static struct class *stallion_class;
720 * Loadable module initialization stuff.
723 static int __init stallion_module_init(void)
729 /*****************************************************************************/
731 static void __exit stallion_module_exit(void)
739 printk("cleanup_module()\n");
742 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
746 * Free up all allocated resources used by the ports. This includes
747 * memory and interrupts. As part of this process we will also do
748 * a hangup on every open port - to try to flush out any processes
749 * hanging onto ports.
751 i = tty_unregister_driver(stl_serial);
752 put_tty_driver(stl_serial);
754 printk("STALLION: failed to un-register tty driver, "
758 for (i = 0; i < 4; i++)
759 class_device_destroy(stallion_class, MKDEV(STL_SIOMEMMAJOR, i));
760 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
761 printk("STALLION: failed to un-register serial memory device, "
763 class_destroy(stallion_class);
765 for (i = 0; (i < stl_nrbrds); i++) {
766 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
769 free_irq(brdp->irq, brdp);
771 for (j = 0; (j < STL_MAXPANELS); j++) {
772 panelp = brdp->panels[j];
773 if (panelp == (stlpanel_t *) NULL)
775 for (k = 0; (k < STL_PORTSPERPANEL); k++) {
776 portp = panelp->ports[k];
777 if (portp == (stlport_t *) NULL)
779 if (portp->tty != (struct tty_struct *) NULL)
780 stl_hangup(portp->tty);
781 kfree(portp->tx.buf);
787 release_region(brdp->ioaddr1, brdp->iosize1);
788 if (brdp->iosize2 > 0)
789 release_region(brdp->ioaddr2, brdp->iosize2);
792 stl_brds[i] = (stlbrd_t *) NULL;
796 module_init(stallion_module_init);
797 module_exit(stallion_module_exit);
799 /*****************************************************************************/
802 * Check for any arguments passed in on the module load command line.
805 static void stl_argbrds(void)
812 printk("stl_argbrds()\n");
815 for (i = stl_nrbrds; (i < stl_nargs); i++) {
816 memset(&conf, 0, sizeof(conf));
817 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
819 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
823 brdp->brdtype = conf.brdtype;
824 brdp->ioaddr1 = conf.ioaddr1;
825 brdp->ioaddr2 = conf.ioaddr2;
826 brdp->irq = conf.irq;
827 brdp->irqtype = conf.irqtype;
832 /*****************************************************************************/
835 * Convert an ascii string number into an unsigned long.
838 static unsigned long stl_atol(char *str)
846 if ((*sp == '0') && (*(sp+1) == 'x')) {
849 } else if (*sp == '0') {
856 for (; (*sp != 0); sp++) {
857 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
858 if ((c < 0) || (c >= base)) {
859 printk("STALLION: invalid argument %s\n", str);
863 val = (val * base) + c;
868 /*****************************************************************************/
871 * Parse the supplied argument string, into the board conf struct.
874 static int stl_parsebrd(stlconf_t *confp, char **argp)
880 printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
883 if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
886 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
889 for (i = 0; i < ARRAY_SIZE(stl_brdstr); i++) {
890 if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
893 if (i == ARRAY_SIZE(stl_brdstr)) {
894 printk("STALLION: unknown board name, %s?\n", argp[0]);
898 confp->brdtype = stl_brdstr[i].type;
901 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
902 confp->ioaddr1 = stl_atol(argp[i]);
904 if (confp->brdtype == BRD_ECH) {
905 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
906 confp->ioaddr2 = stl_atol(argp[i]);
909 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
910 confp->irq = stl_atol(argp[i]);
914 /*****************************************************************************/
917 * Allocate a new board structure. Fill out the basic info in it.
920 static stlbrd_t *stl_allocbrd(void)
924 brdp = kzalloc(sizeof(stlbrd_t), GFP_KERNEL);
926 printk("STALLION: failed to allocate memory (size=%Zd)\n",
931 brdp->magic = STL_BOARDMAGIC;
935 /*****************************************************************************/
937 static int stl_open(struct tty_struct *tty, struct file *filp)
941 unsigned int minordev;
942 int brdnr, panelnr, portnr, rc;
945 printk("stl_open(tty=%x,filp=%x): device=%s\n", (int) tty,
946 (int) filp, tty->name);
949 minordev = tty->index;
950 brdnr = MINOR2BRD(minordev);
951 if (brdnr >= stl_nrbrds)
953 brdp = stl_brds[brdnr];
954 if (brdp == (stlbrd_t *) NULL)
956 minordev = MINOR2PORT(minordev);
957 for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
958 if (brdp->panels[panelnr] == (stlpanel_t *) NULL)
960 if (minordev < brdp->panels[panelnr]->nrports) {
964 minordev -= brdp->panels[panelnr]->nrports;
969 portp = brdp->panels[panelnr]->ports[portnr];
970 if (portp == (stlport_t *) NULL)
974 * On the first open of the device setup the port hardware, and
975 * initialize the per port data structure.
978 tty->driver_data = portp;
981 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
982 if (!portp->tx.buf) {
983 portp->tx.buf = kmalloc(STL_TXBUFSIZE, GFP_KERNEL);
986 portp->tx.head = portp->tx.buf;
987 portp->tx.tail = portp->tx.buf;
989 stl_setport(portp, tty->termios);
990 portp->sigs = stl_getsignals(portp);
991 stl_setsignals(portp, 1, 1);
992 stl_enablerxtx(portp, 1, 1);
993 stl_startrxtx(portp, 1, 0);
994 clear_bit(TTY_IO_ERROR, &tty->flags);
995 portp->flags |= ASYNC_INITIALIZED;
999 * Check if this port is in the middle of closing. If so then wait
1000 * until it is closed then return error status, based on flag settings.
1001 * The sleep here does not need interrupt protection since the wakeup
1002 * for it is done with the same context.
1004 if (portp->flags & ASYNC_CLOSING) {
1005 interruptible_sleep_on(&portp->close_wait);
1006 if (portp->flags & ASYNC_HUP_NOTIFY)
1008 return -ERESTARTSYS;
1012 * Based on type of open being done check if it can overlap with any
1013 * previous opens still in effect. If we are a normal serial device
1014 * then also we might have to wait for carrier.
1016 if (!(filp->f_flags & O_NONBLOCK)) {
1017 if ((rc = stl_waitcarrier(portp, filp)) != 0)
1020 portp->flags |= ASYNC_NORMAL_ACTIVE;
1025 /*****************************************************************************/
1028 * Possibly need to wait for carrier (DCD signal) to come high. Say
1029 * maybe because if we are clocal then we don't need to wait...
1032 static int stl_waitcarrier(stlport_t *portp, struct file *filp)
1034 unsigned long flags;
1038 printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp, (int) filp);
1044 spin_lock_irqsave(&stallion_lock, flags);
1046 if (portp->tty->termios->c_cflag & CLOCAL)
1049 portp->openwaitcnt++;
1050 if (! tty_hung_up_p(filp))
1054 /* Takes brd_lock internally */
1055 stl_setsignals(portp, 1, 1);
1056 if (tty_hung_up_p(filp) ||
1057 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1058 if (portp->flags & ASYNC_HUP_NOTIFY)
1064 if (((portp->flags & ASYNC_CLOSING) == 0) &&
1065 (doclocal || (portp->sigs & TIOCM_CD))) {
1068 if (signal_pending(current)) {
1073 interruptible_sleep_on(&portp->open_wait);
1076 if (! tty_hung_up_p(filp))
1078 portp->openwaitcnt--;
1079 spin_unlock_irqrestore(&stallion_lock, flags);
1084 /*****************************************************************************/
1086 static void stl_close(struct tty_struct *tty, struct file *filp)
1089 unsigned long flags;
1092 printk("stl_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
1095 portp = tty->driver_data;
1096 if (portp == (stlport_t *) NULL)
1099 spin_lock_irqsave(&stallion_lock, flags);
1100 if (tty_hung_up_p(filp)) {
1101 spin_unlock_irqrestore(&stallion_lock, flags);
1104 if ((tty->count == 1) && (portp->refcount != 1))
1105 portp->refcount = 1;
1106 if (portp->refcount-- > 1) {
1107 spin_unlock_irqrestore(&stallion_lock, flags);
1111 portp->refcount = 0;
1112 portp->flags |= ASYNC_CLOSING;
1115 * May want to wait for any data to drain before closing. The BUSY
1116 * flag keeps track of whether we are still sending or not - it is
1117 * very accurate for the cd1400, not quite so for the sc26198.
1118 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1122 spin_unlock_irqrestore(&stallion_lock, flags);
1124 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1125 tty_wait_until_sent(tty, portp->closing_wait);
1126 stl_waituntilsent(tty, (HZ / 2));
1129 spin_lock_irqsave(&stallion_lock, flags);
1130 portp->flags &= ~ASYNC_INITIALIZED;
1131 spin_unlock_irqrestore(&stallion_lock, flags);
1133 stl_disableintrs(portp);
1134 if (tty->termios->c_cflag & HUPCL)
1135 stl_setsignals(portp, 0, 0);
1136 stl_enablerxtx(portp, 0, 0);
1137 stl_flushbuffer(tty);
1139 if (portp->tx.buf != (char *) NULL) {
1140 kfree(portp->tx.buf);
1141 portp->tx.buf = (char *) NULL;
1142 portp->tx.head = (char *) NULL;
1143 portp->tx.tail = (char *) NULL;
1145 set_bit(TTY_IO_ERROR, &tty->flags);
1146 tty_ldisc_flush(tty);
1149 portp->tty = (struct tty_struct *) NULL;
1151 if (portp->openwaitcnt) {
1152 if (portp->close_delay)
1153 msleep_interruptible(jiffies_to_msecs(portp->close_delay));
1154 wake_up_interruptible(&portp->open_wait);
1157 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1158 wake_up_interruptible(&portp->close_wait);
1161 /*****************************************************************************/
1164 * Write routine. Take data and stuff it in to the TX ring queue.
1165 * If transmit interrupts are not running then start them.
1168 static int stl_write(struct tty_struct *tty, const unsigned char *buf, int count)
1171 unsigned int len, stlen;
1172 unsigned char *chbuf;
1176 printk("stl_write(tty=%x,buf=%x,count=%d)\n",
1177 (int) tty, (int) buf, count);
1180 portp = tty->driver_data;
1181 if (portp == (stlport_t *) NULL)
1183 if (portp->tx.buf == (char *) NULL)
1187 * If copying direct from user space we must cater for page faults,
1188 * causing us to "sleep" here for a while. To handle this copy in all
1189 * the data we need now, into a local buffer. Then when we got it all
1190 * copy it into the TX buffer.
1192 chbuf = (unsigned char *) buf;
1194 head = portp->tx.head;
1195 tail = portp->tx.tail;
1197 len = STL_TXBUFSIZE - (head - tail) - 1;
1198 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
1200 len = tail - head - 1;
1204 len = MIN(len, count);
1207 stlen = MIN(len, stlen);
1208 memcpy(head, chbuf, stlen);
1213 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
1214 head = portp->tx.buf;
1215 stlen = tail - head;
1218 portp->tx.head = head;
1220 clear_bit(ASYI_TXLOW, &portp->istate);
1221 stl_startrxtx(portp, -1, 1);
1226 /*****************************************************************************/
1228 static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1235 printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1238 if (tty == (struct tty_struct *) NULL)
1240 portp = tty->driver_data;
1241 if (portp == (stlport_t *) NULL)
1243 if (portp->tx.buf == (char *) NULL)
1246 head = portp->tx.head;
1247 tail = portp->tx.tail;
1249 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
1254 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
1255 head = portp->tx.buf;
1257 portp->tx.head = head;
1260 /*****************************************************************************/
1263 * If there are any characters in the buffer then make sure that TX
1264 * interrupts are on and get'em out. Normally used after the putchar
1265 * routine has been called.
1268 static void stl_flushchars(struct tty_struct *tty)
1273 printk("stl_flushchars(tty=%x)\n", (int) tty);
1276 if (tty == (struct tty_struct *) NULL)
1278 portp = tty->driver_data;
1279 if (portp == (stlport_t *) NULL)
1281 if (portp->tx.buf == (char *) NULL)
1284 stl_startrxtx(portp, -1, 1);
1287 /*****************************************************************************/
1289 static int stl_writeroom(struct tty_struct *tty)
1295 printk("stl_writeroom(tty=%x)\n", (int) tty);
1298 if (tty == (struct tty_struct *) NULL)
1300 portp = tty->driver_data;
1301 if (portp == (stlport_t *) NULL)
1303 if (portp->tx.buf == (char *) NULL)
1306 head = portp->tx.head;
1307 tail = portp->tx.tail;
1308 return ((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
1311 /*****************************************************************************/
1314 * Return number of chars in the TX buffer. Normally we would just
1315 * calculate the number of chars in the buffer and return that, but if
1316 * the buffer is empty and TX interrupts are still on then we return
1317 * that the buffer still has 1 char in it. This way whoever called us
1318 * will not think that ALL chars have drained - since the UART still
1319 * must have some chars in it (we are busy after all).
1322 static int stl_charsinbuffer(struct tty_struct *tty)
1329 printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
1332 if (tty == (struct tty_struct *) NULL)
1334 portp = tty->driver_data;
1335 if (portp == (stlport_t *) NULL)
1337 if (portp->tx.buf == (char *) NULL)
1340 head = portp->tx.head;
1341 tail = portp->tx.tail;
1342 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1343 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1348 /*****************************************************************************/
1351 * Generate the serial struct info.
1354 static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp)
1356 struct serial_struct sio;
1360 printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1363 memset(&sio, 0, sizeof(struct serial_struct));
1364 sio.line = portp->portnr;
1365 sio.port = portp->ioaddr;
1366 sio.flags = portp->flags;
1367 sio.baud_base = portp->baud_base;
1368 sio.close_delay = portp->close_delay;
1369 sio.closing_wait = portp->closing_wait;
1370 sio.custom_divisor = portp->custom_divisor;
1372 if (portp->uartp == &stl_cd1400uart) {
1373 sio.type = PORT_CIRRUS;
1374 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1376 sio.type = PORT_UNKNOWN;
1377 sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1380 brdp = stl_brds[portp->brdnr];
1381 if (brdp != (stlbrd_t *) NULL)
1382 sio.irq = brdp->irq;
1384 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
1387 /*****************************************************************************/
1390 * Set port according to the serial struct info.
1391 * At this point we do not do any auto-configure stuff, so we will
1392 * just quietly ignore any requests to change irq, etc.
1395 static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp)
1397 struct serial_struct sio;
1400 printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1403 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1405 if (!capable(CAP_SYS_ADMIN)) {
1406 if ((sio.baud_base != portp->baud_base) ||
1407 (sio.close_delay != portp->close_delay) ||
1408 ((sio.flags & ~ASYNC_USR_MASK) !=
1409 (portp->flags & ~ASYNC_USR_MASK)))
1413 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1414 (sio.flags & ASYNC_USR_MASK);
1415 portp->baud_base = sio.baud_base;
1416 portp->close_delay = sio.close_delay;
1417 portp->closing_wait = sio.closing_wait;
1418 portp->custom_divisor = sio.custom_divisor;
1419 stl_setport(portp, portp->tty->termios);
1423 /*****************************************************************************/
1425 static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1429 if (tty == (struct tty_struct *) NULL)
1431 portp = tty->driver_data;
1432 if (portp == (stlport_t *) NULL)
1434 if (tty->flags & (1 << TTY_IO_ERROR))
1437 return stl_getsignals(portp);
1440 static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1441 unsigned int set, unsigned int clear)
1444 int rts = -1, dtr = -1;
1446 if (tty == (struct tty_struct *) NULL)
1448 portp = tty->driver_data;
1449 if (portp == (stlport_t *) NULL)
1451 if (tty->flags & (1 << TTY_IO_ERROR))
1454 if (set & TIOCM_RTS)
1456 if (set & TIOCM_DTR)
1458 if (clear & TIOCM_RTS)
1460 if (clear & TIOCM_DTR)
1463 stl_setsignals(portp, dtr, rts);
1467 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1472 void __user *argp = (void __user *)arg;
1475 printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
1476 (int) tty, (int) file, cmd, (int) arg);
1479 if (tty == (struct tty_struct *) NULL)
1481 portp = tty->driver_data;
1482 if (portp == (stlport_t *) NULL)
1485 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1486 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1487 if (tty->flags & (1 << TTY_IO_ERROR))
1495 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1496 (unsigned __user *) argp);
1499 if (get_user(ival, (unsigned int __user *) arg))
1501 tty->termios->c_cflag =
1502 (tty->termios->c_cflag & ~CLOCAL) |
1503 (ival ? CLOCAL : 0);
1506 rc = stl_getserial(portp, argp);
1509 rc = stl_setserial(portp, argp);
1511 case COM_GETPORTSTATS:
1512 rc = stl_getportstats(portp, argp);
1514 case COM_CLRPORTSTATS:
1515 rc = stl_clrportstats(portp, argp);
1521 case TIOCSERGSTRUCT:
1522 case TIOCSERGETMULTI:
1523 case TIOCSERSETMULTI:
1532 /*****************************************************************************/
1534 static void stl_settermios(struct tty_struct *tty, struct termios *old)
1537 struct termios *tiosp;
1540 printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
1543 if (tty == (struct tty_struct *) NULL)
1545 portp = tty->driver_data;
1546 if (portp == (stlport_t *) NULL)
1549 tiosp = tty->termios;
1550 if ((tiosp->c_cflag == old->c_cflag) &&
1551 (tiosp->c_iflag == old->c_iflag))
1554 stl_setport(portp, tiosp);
1555 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1557 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1558 tty->hw_stopped = 0;
1561 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1562 wake_up_interruptible(&portp->open_wait);
1565 /*****************************************************************************/
1568 * Attempt to flow control who ever is sending us data. Based on termios
1569 * settings use software or/and hardware flow control.
1572 static void stl_throttle(struct tty_struct *tty)
1577 printk("stl_throttle(tty=%x)\n", (int) tty);
1580 if (tty == (struct tty_struct *) NULL)
1582 portp = tty->driver_data;
1583 if (portp == (stlport_t *) NULL)
1585 stl_flowctrl(portp, 0);
1588 /*****************************************************************************/
1591 * Unflow control the device sending us data...
1594 static void stl_unthrottle(struct tty_struct *tty)
1599 printk("stl_unthrottle(tty=%x)\n", (int) tty);
1602 if (tty == (struct tty_struct *) NULL)
1604 portp = tty->driver_data;
1605 if (portp == (stlport_t *) NULL)
1607 stl_flowctrl(portp, 1);
1610 /*****************************************************************************/
1613 * Stop the transmitter. Basically to do this we will just turn TX
1617 static void stl_stop(struct tty_struct *tty)
1622 printk("stl_stop(tty=%x)\n", (int) tty);
1625 if (tty == (struct tty_struct *) NULL)
1627 portp = tty->driver_data;
1628 if (portp == (stlport_t *) NULL)
1630 stl_startrxtx(portp, -1, 0);
1633 /*****************************************************************************/
1636 * Start the transmitter again. Just turn TX interrupts back on.
1639 static void stl_start(struct tty_struct *tty)
1644 printk("stl_start(tty=%x)\n", (int) tty);
1647 if (tty == (struct tty_struct *) NULL)
1649 portp = tty->driver_data;
1650 if (portp == (stlport_t *) NULL)
1652 stl_startrxtx(portp, -1, 1);
1655 /*****************************************************************************/
1658 * Hangup this port. This is pretty much like closing the port, only
1659 * a little more brutal. No waiting for data to drain. Shutdown the
1660 * port and maybe drop signals.
1663 static void stl_hangup(struct tty_struct *tty)
1668 printk("stl_hangup(tty=%x)\n", (int) tty);
1671 if (tty == (struct tty_struct *) NULL)
1673 portp = tty->driver_data;
1674 if (portp == (stlport_t *) NULL)
1677 portp->flags &= ~ASYNC_INITIALIZED;
1678 stl_disableintrs(portp);
1679 if (tty->termios->c_cflag & HUPCL)
1680 stl_setsignals(portp, 0, 0);
1681 stl_enablerxtx(portp, 0, 0);
1682 stl_flushbuffer(tty);
1684 set_bit(TTY_IO_ERROR, &tty->flags);
1685 if (portp->tx.buf != (char *) NULL) {
1686 kfree(portp->tx.buf);
1687 portp->tx.buf = (char *) NULL;
1688 portp->tx.head = (char *) NULL;
1689 portp->tx.tail = (char *) NULL;
1691 portp->tty = (struct tty_struct *) NULL;
1692 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1693 portp->refcount = 0;
1694 wake_up_interruptible(&portp->open_wait);
1697 /*****************************************************************************/
1699 static void stl_flushbuffer(struct tty_struct *tty)
1704 printk("stl_flushbuffer(tty=%x)\n", (int) tty);
1707 if (tty == (struct tty_struct *) NULL)
1709 portp = tty->driver_data;
1710 if (portp == (stlport_t *) NULL)
1717 /*****************************************************************************/
1719 static void stl_breakctl(struct tty_struct *tty, int state)
1724 printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty, state);
1727 if (tty == (struct tty_struct *) NULL)
1729 portp = tty->driver_data;
1730 if (portp == (stlport_t *) NULL)
1733 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1736 /*****************************************************************************/
1738 static void stl_waituntilsent(struct tty_struct *tty, int timeout)
1744 printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty, timeout);
1747 if (tty == (struct tty_struct *) NULL)
1749 portp = tty->driver_data;
1750 if (portp == (stlport_t *) NULL)
1755 tend = jiffies + timeout;
1757 while (stl_datastate(portp)) {
1758 if (signal_pending(current))
1760 msleep_interruptible(20);
1761 if (time_after_eq(jiffies, tend))
1766 /*****************************************************************************/
1768 static void stl_sendxchar(struct tty_struct *tty, char ch)
1773 printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
1776 if (tty == (struct tty_struct *) NULL)
1778 portp = tty->driver_data;
1779 if (portp == (stlport_t *) NULL)
1782 if (ch == STOP_CHAR(tty))
1783 stl_sendflow(portp, 0);
1784 else if (ch == START_CHAR(tty))
1785 stl_sendflow(portp, 1);
1787 stl_putchar(tty, ch);
1790 /*****************************************************************************/
1795 * Format info for a specified port. The line is deliberately limited
1796 * to 80 characters. (If it is too long it will be truncated, if too
1797 * short then padded with spaces).
1800 static int stl_portinfo(stlport_t *portp, int portnr, char *pos)
1806 sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
1807 portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
1808 (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
1810 if (portp->stats.rxframing)
1811 sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
1812 if (portp->stats.rxparity)
1813 sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
1814 if (portp->stats.rxbreaks)
1815 sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
1816 if (portp->stats.rxoverrun)
1817 sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
1819 sigs = stl_getsignals(portp);
1820 cnt = sprintf(sp, "%s%s%s%s%s ",
1821 (sigs & TIOCM_RTS) ? "|RTS" : "",
1822 (sigs & TIOCM_CTS) ? "|CTS" : "",
1823 (sigs & TIOCM_DTR) ? "|DTR" : "",
1824 (sigs & TIOCM_CD) ? "|DCD" : "",
1825 (sigs & TIOCM_DSR) ? "|DSR" : "");
1829 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
1832 pos[(MAXLINE - 2)] = '+';
1833 pos[(MAXLINE - 1)] = '\n';
1838 /*****************************************************************************/
1841 * Port info, read from the /proc file system.
1844 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
1849 int brdnr, panelnr, portnr, totalport;
1854 printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
1855 "data=%x\n", (int) page, (int) start, (int) off, count,
1856 (int) eof, (int) data);
1864 pos += sprintf(pos, "%s: version %s", stl_drvtitle,
1866 while (pos < (page + MAXLINE - 1))
1873 * We scan through for each board, panel and port. The offset is
1874 * calculated on the fly, and irrelevant ports are skipped.
1876 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1877 brdp = stl_brds[brdnr];
1878 if (brdp == (stlbrd_t *) NULL)
1880 if (brdp->state == 0)
1883 maxoff = curoff + (brdp->nrports * MAXLINE);
1884 if (off >= maxoff) {
1889 totalport = brdnr * STL_MAXPORTS;
1890 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1891 panelp = brdp->panels[panelnr];
1892 if (panelp == (stlpanel_t *) NULL)
1895 maxoff = curoff + (panelp->nrports * MAXLINE);
1896 if (off >= maxoff) {
1898 totalport += panelp->nrports;
1902 for (portnr = 0; (portnr < panelp->nrports); portnr++,
1904 portp = panelp->ports[portnr];
1905 if (portp == (stlport_t *) NULL)
1907 if (off >= (curoff += MAXLINE))
1909 if ((pos - page + MAXLINE) > count)
1911 pos += stl_portinfo(portp, totalport, pos);
1920 return (pos - page);
1923 /*****************************************************************************/
1926 * All board interrupts are vectored through here first. This code then
1927 * calls off to the approrpriate board interrupt handlers.
1930 static irqreturn_t stl_intr(int irq, void *dev_id)
1932 stlbrd_t *brdp = (stlbrd_t *) dev_id;
1935 printk("stl_intr(brdp=%x,irq=%d)\n", (int) brdp, irq);
1938 return IRQ_RETVAL((* brdp->isr)(brdp));
1941 /*****************************************************************************/
1944 * Interrupt service routine for EasyIO board types.
1947 static int stl_eiointr(stlbrd_t *brdp)
1950 unsigned int iobase;
1953 spin_lock(&brd_lock);
1954 panelp = brdp->panels[0];
1955 iobase = panelp->iobase;
1956 while (inb(brdp->iostatus) & EIO_INTRPEND) {
1958 (* panelp->isr)(panelp, iobase);
1960 spin_unlock(&brd_lock);
1964 /*****************************************************************************/
1967 * Interrupt service routine for ECH-AT board types.
1970 static int stl_echatintr(stlbrd_t *brdp)
1973 unsigned int ioaddr;
1977 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
1979 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1981 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1982 ioaddr = brdp->bnkstataddr[bnknr];
1983 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1984 panelp = brdp->bnk2panel[bnknr];
1985 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1990 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
1995 /*****************************************************************************/
1998 * Interrupt service routine for ECH-MCA board types.
2001 static int stl_echmcaintr(stlbrd_t *brdp)
2004 unsigned int ioaddr;
2008 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2010 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2011 ioaddr = brdp->bnkstataddr[bnknr];
2012 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2013 panelp = brdp->bnk2panel[bnknr];
2014 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2021 /*****************************************************************************/
2024 * Interrupt service routine for ECH-PCI board types.
2027 static int stl_echpciintr(stlbrd_t *brdp)
2030 unsigned int ioaddr;
2036 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2037 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
2038 ioaddr = brdp->bnkstataddr[bnknr];
2039 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2040 panelp = brdp->bnk2panel[bnknr];
2041 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2052 /*****************************************************************************/
2055 * Interrupt service routine for ECH-8/64-PCI board types.
2058 static int stl_echpci64intr(stlbrd_t *brdp)
2061 unsigned int ioaddr;
2065 while (inb(brdp->ioctrl) & 0x1) {
2067 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2068 ioaddr = brdp->bnkstataddr[bnknr];
2069 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2070 panelp = brdp->bnk2panel[bnknr];
2071 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2079 /*****************************************************************************/
2082 * Service an off-level request for some channel.
2084 static void stl_offintr(struct work_struct *work)
2086 stlport_t *portp = container_of(work, stlport_t, tqueue);
2087 struct tty_struct *tty;
2088 unsigned int oldsigs;
2091 printk("stl_offintr(portp=%x)\n", (int) portp);
2094 if (portp == (stlport_t *) NULL)
2098 if (tty == (struct tty_struct *) NULL)
2102 if (test_bit(ASYI_TXLOW, &portp->istate)) {
2105 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
2106 clear_bit(ASYI_DCDCHANGE, &portp->istate);
2107 oldsigs = portp->sigs;
2108 portp->sigs = stl_getsignals(portp);
2109 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
2110 wake_up_interruptible(&portp->open_wait);
2111 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
2112 if (portp->flags & ASYNC_CHECK_CD)
2113 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2119 /*****************************************************************************/
2122 * Initialize all the ports on a panel.
2125 static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2131 printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
2134 chipmask = stl_panelinit(brdp, panelp);
2137 * All UART's are initialized (if found!). Now go through and setup
2138 * each ports data structures.
2140 for (i = 0; (i < panelp->nrports); i++) {
2141 portp = kzalloc(sizeof(stlport_t), GFP_KERNEL);
2143 printk("STALLION: failed to allocate memory "
2144 "(size=%Zd)\n", sizeof(stlport_t));
2148 portp->magic = STL_PORTMAGIC;
2150 portp->brdnr = panelp->brdnr;
2151 portp->panelnr = panelp->panelnr;
2152 portp->uartp = panelp->uartp;
2153 portp->clk = brdp->clk;
2154 portp->baud_base = STL_BAUDBASE;
2155 portp->close_delay = STL_CLOSEDELAY;
2156 portp->closing_wait = 30 * HZ;
2157 INIT_WORK(&portp->tqueue, stl_offintr);
2158 init_waitqueue_head(&portp->open_wait);
2159 init_waitqueue_head(&portp->close_wait);
2160 portp->stats.brd = portp->brdnr;
2161 portp->stats.panel = portp->panelnr;
2162 portp->stats.port = portp->portnr;
2163 panelp->ports[i] = portp;
2164 stl_portinit(brdp, panelp, portp);
2170 /*****************************************************************************/
2173 * Try to find and initialize an EasyIO board.
2176 static inline int stl_initeio(stlbrd_t *brdp)
2179 unsigned int status;
2184 printk("stl_initeio(brdp=%x)\n", (int) brdp);
2187 brdp->ioctrl = brdp->ioaddr1 + 1;
2188 brdp->iostatus = brdp->ioaddr1 + 2;
2190 status = inb(brdp->iostatus);
2191 if ((status & EIO_IDBITMASK) == EIO_MK3)
2195 * Handle board specific stuff now. The real difference is PCI
2198 if (brdp->brdtype == BRD_EASYIOPCI) {
2199 brdp->iosize1 = 0x80;
2200 brdp->iosize2 = 0x80;
2201 name = "serial(EIO-PCI)";
2202 outb(0x41, (brdp->ioaddr2 + 0x4c));
2205 name = "serial(EIO)";
2206 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2207 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2208 printk("STALLION: invalid irq=%d for brd=%d\n",
2209 brdp->irq, brdp->brdnr);
2212 outb((stl_vecmap[brdp->irq] | EIO_0WS |
2213 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
2217 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2218 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2219 "%x conflicts with another device\n", brdp->brdnr,
2224 if (brdp->iosize2 > 0)
2225 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2226 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2227 "address %x conflicts with another device\n",
2228 brdp->brdnr, brdp->ioaddr2);
2229 printk(KERN_WARNING "STALLION: Warning, also "
2230 "releasing board %d I/O address %x \n",
2231 brdp->brdnr, brdp->ioaddr1);
2232 release_region(brdp->ioaddr1, brdp->iosize1);
2237 * Everything looks OK, so let's go ahead and probe for the hardware.
2239 brdp->clk = CD1400_CLK;
2240 brdp->isr = stl_eiointr;
2242 switch (status & EIO_IDBITMASK) {
2244 brdp->clk = CD1400_CLK8M;
2254 switch (status & EIO_BRDMASK) {
2273 * We have verified that the board is actually present, so now we
2274 * can complete the setup.
2277 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
2279 printk(KERN_WARNING "STALLION: failed to allocate memory "
2280 "(size=%Zd)\n", sizeof(stlpanel_t));
2284 panelp->magic = STL_PANELMAGIC;
2285 panelp->brdnr = brdp->brdnr;
2286 panelp->panelnr = 0;
2287 panelp->nrports = brdp->nrports;
2288 panelp->iobase = brdp->ioaddr1;
2289 panelp->hwid = status;
2290 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2291 panelp->uartp = (void *) &stl_sc26198uart;
2292 panelp->isr = stl_sc26198intr;
2294 panelp->uartp = (void *) &stl_cd1400uart;
2295 panelp->isr = stl_cd1400eiointr;
2298 brdp->panels[0] = panelp;
2300 brdp->state |= BRD_FOUND;
2301 brdp->hwid = status;
2302 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
2303 printk("STALLION: failed to register interrupt "
2304 "routine for %s irq=%d\n", name, brdp->irq);
2312 /*****************************************************************************/
2315 * Try to find an ECH board and initialize it. This code is capable of
2316 * dealing with all types of ECH board.
2319 static inline int stl_initech(stlbrd_t *brdp)
2322 unsigned int status, nxtid, ioaddr, conflict;
2323 int panelnr, banknr, i;
2327 printk("stl_initech(brdp=%x)\n", (int) brdp);
2334 * Set up the initial board register contents for boards. This varies a
2335 * bit between the different board types. So we need to handle each
2336 * separately. Also do a check that the supplied IRQ is good.
2338 switch (brdp->brdtype) {
2341 brdp->isr = stl_echatintr;
2342 brdp->ioctrl = brdp->ioaddr1 + 1;
2343 brdp->iostatus = brdp->ioaddr1 + 1;
2344 status = inb(brdp->iostatus);
2345 if ((status & ECH_IDBITMASK) != ECH_ID)
2347 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2348 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2349 printk("STALLION: invalid irq=%d for brd=%d\n",
2350 brdp->irq, brdp->brdnr);
2353 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2354 status |= (stl_vecmap[brdp->irq] << 1);
2355 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2356 brdp->ioctrlval = ECH_INTENABLE |
2357 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2358 for (i = 0; (i < 10); i++)
2359 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2362 name = "serial(EC8/32)";
2363 outb(status, brdp->ioaddr1);
2367 brdp->isr = stl_echmcaintr;
2368 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2369 brdp->iostatus = brdp->ioctrl;
2370 status = inb(brdp->iostatus);
2371 if ((status & ECH_IDBITMASK) != ECH_ID)
2373 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2374 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2375 printk("STALLION: invalid irq=%d for brd=%d\n",
2376 brdp->irq, brdp->brdnr);
2379 outb(ECHMC_BRDRESET, brdp->ioctrl);
2380 outb(ECHMC_INTENABLE, brdp->ioctrl);
2382 name = "serial(EC8/32-MC)";
2386 brdp->isr = stl_echpciintr;
2387 brdp->ioctrl = brdp->ioaddr1 + 2;
2390 name = "serial(EC8/32-PCI)";
2394 brdp->isr = stl_echpci64intr;
2395 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2396 outb(0x43, (brdp->ioaddr1 + 0x4c));
2397 brdp->iosize1 = 0x80;
2398 brdp->iosize2 = 0x80;
2399 name = "serial(EC8/64-PCI)";
2403 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
2409 * Check boards for possible IO address conflicts and return fail status
2410 * if an IO conflict found.
2412 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2413 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2414 "%x conflicts with another device\n", brdp->brdnr,
2419 if (brdp->iosize2 > 0)
2420 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2421 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2422 "address %x conflicts with another device\n",
2423 brdp->brdnr, brdp->ioaddr2);
2424 printk(KERN_WARNING "STALLION: Warning, also "
2425 "releasing board %d I/O address %x \n",
2426 brdp->brdnr, brdp->ioaddr1);
2427 release_region(brdp->ioaddr1, brdp->iosize1);
2432 * Scan through the secondary io address space looking for panels.
2433 * As we find'em allocate and initialize panel structures for each.
2435 brdp->clk = CD1400_CLK;
2436 brdp->hwid = status;
2438 ioaddr = brdp->ioaddr2;
2443 for (i = 0; (i < STL_MAXPANELS); i++) {
2444 if (brdp->brdtype == BRD_ECHPCI) {
2445 outb(nxtid, brdp->ioctrl);
2446 ioaddr = brdp->ioaddr2;
2448 status = inb(ioaddr + ECH_PNLSTATUS);
2449 if ((status & ECH_PNLIDMASK) != nxtid)
2451 panelp = kzalloc(sizeof(stlpanel_t), GFP_KERNEL);
2453 printk("STALLION: failed to allocate memory "
2454 "(size=%Zd)\n", sizeof(stlpanel_t));
2457 panelp->magic = STL_PANELMAGIC;
2458 panelp->brdnr = brdp->brdnr;
2459 panelp->panelnr = panelnr;
2460 panelp->iobase = ioaddr;
2461 panelp->pagenr = nxtid;
2462 panelp->hwid = status;
2463 brdp->bnk2panel[banknr] = panelp;
2464 brdp->bnkpageaddr[banknr] = nxtid;
2465 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2467 if (status & ECH_PNLXPID) {
2468 panelp->uartp = (void *) &stl_sc26198uart;
2469 panelp->isr = stl_sc26198intr;
2470 if (status & ECH_PNL16PORT) {
2471 panelp->nrports = 16;
2472 brdp->bnk2panel[banknr] = panelp;
2473 brdp->bnkpageaddr[banknr] = nxtid;
2474 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2477 panelp->nrports = 8;
2480 panelp->uartp = (void *) &stl_cd1400uart;
2481 panelp->isr = stl_cd1400echintr;
2482 if (status & ECH_PNL16PORT) {
2483 panelp->nrports = 16;
2484 panelp->ackmask = 0x80;
2485 if (brdp->brdtype != BRD_ECHPCI)
2486 ioaddr += EREG_BANKSIZE;
2487 brdp->bnk2panel[banknr] = panelp;
2488 brdp->bnkpageaddr[banknr] = ++nxtid;
2489 brdp->bnkstataddr[banknr++] = ioaddr +
2492 panelp->nrports = 8;
2493 panelp->ackmask = 0xc0;
2498 ioaddr += EREG_BANKSIZE;
2499 brdp->nrports += panelp->nrports;
2500 brdp->panels[panelnr++] = panelp;
2501 if ((brdp->brdtype != BRD_ECHPCI) &&
2502 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
2506 brdp->nrpanels = panelnr;
2507 brdp->nrbnks = banknr;
2508 if (brdp->brdtype == BRD_ECH)
2509 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2511 brdp->state |= BRD_FOUND;
2512 if (request_irq(brdp->irq, stl_intr, IRQF_SHARED, name, brdp) != 0) {
2513 printk("STALLION: failed to register interrupt "
2514 "routine for %s irq=%d\n", name, brdp->irq);
2523 /*****************************************************************************/
2526 * Initialize and configure the specified board.
2527 * Scan through all the boards in the configuration and see what we
2528 * can find. Handle EIO and the ECH boards a little differently here
2529 * since the initial search and setup is very different.
2532 static int __init stl_brdinit(stlbrd_t *brdp)
2537 printk("stl_brdinit(brdp=%x)\n", (int) brdp);
2540 switch (brdp->brdtype) {
2552 printk("STALLION: board=%d is unknown board type=%d\n",
2553 brdp->brdnr, brdp->brdtype);
2557 stl_brds[brdp->brdnr] = brdp;
2558 if ((brdp->state & BRD_FOUND) == 0) {
2559 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2560 stl_brdnames[brdp->brdtype], brdp->brdnr,
2561 brdp->ioaddr1, brdp->irq);
2565 for (i = 0; (i < STL_MAXPANELS); i++)
2566 if (brdp->panels[i] != (stlpanel_t *) NULL)
2567 stl_initports(brdp, brdp->panels[i]);
2569 printk("STALLION: %s found, board=%d io=%x irq=%d "
2570 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2571 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2576 /*****************************************************************************/
2579 * Find the next available board number that is free.
2582 static inline int stl_getbrdnr(void)
2586 for (i = 0; (i < STL_MAXBRDS); i++) {
2587 if (stl_brds[i] == (stlbrd_t *) NULL) {
2588 if (i >= stl_nrbrds)
2596 /*****************************************************************************/
2601 * We have a Stallion board. Allocate a board structure and
2602 * initialize it. Read its IO and IRQ resources from PCI
2603 * configuration space.
2606 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
2611 printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
2612 devp->bus->number, devp->devfn);
2615 if (pci_enable_device(devp))
2617 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2619 if ((brdp->brdnr = stl_getbrdnr()) < 0) {
2620 printk("STALLION: too many boards found, "
2621 "maximum supported %d\n", STL_MAXBRDS);
2624 brdp->brdtype = brdtype;
2627 * Different Stallion boards use the BAR registers in different ways,
2628 * so set up io addresses based on board type.
2631 printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__, __LINE__,
2632 pci_resource_start(devp, 0), pci_resource_start(devp, 1),
2633 pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
2637 * We have all resources from the board, so let's setup the actual
2638 * board structure now.
2642 brdp->ioaddr2 = pci_resource_start(devp, 0);
2643 brdp->ioaddr1 = pci_resource_start(devp, 1);
2646 brdp->ioaddr2 = pci_resource_start(devp, 2);
2647 brdp->ioaddr1 = pci_resource_start(devp, 1);
2650 brdp->ioaddr1 = pci_resource_start(devp, 2);
2651 brdp->ioaddr2 = pci_resource_start(devp, 1);
2654 printk("STALLION: unknown PCI board type=%d\n", brdtype);
2658 brdp->irq = devp->irq;
2664 /*****************************************************************************/
2667 * Find all Stallion PCI boards that might be installed. Initialize each
2668 * one as it is found.
2672 static inline int stl_findpcibrds(void)
2674 struct pci_dev *dev = NULL;
2678 printk("stl_findpcibrds()\n");
2681 for (i = 0; (i < stl_nrpcibrds); i++)
2682 while ((dev = pci_find_device(stl_pcibrds[i].vendid,
2683 stl_pcibrds[i].devid, dev))) {
2686 * Found a device on the PCI bus that has our vendor and
2687 * device ID. Need to check now that it is really us.
2689 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2692 rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
2702 /*****************************************************************************/
2705 * Scan through all the boards in the configuration and see what we
2706 * can find. Handle EIO and the ECH boards a little differently here
2707 * since the initial search and setup is too different.
2710 static inline int stl_initbrds(void)
2717 printk("stl_initbrds()\n");
2720 if (stl_nrbrds > STL_MAXBRDS) {
2721 printk("STALLION: too many boards in configuration table, "
2722 "truncating to %d\n", STL_MAXBRDS);
2723 stl_nrbrds = STL_MAXBRDS;
2727 * Firstly scan the list of static boards configured. Allocate
2728 * resources and initialize the boards as found.
2730 for (i = 0; (i < stl_nrbrds); i++) {
2731 confp = &stl_brdconf[i];
2732 stl_parsebrd(confp, stl_brdsp[i]);
2733 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2736 brdp->brdtype = confp->brdtype;
2737 brdp->ioaddr1 = confp->ioaddr1;
2738 brdp->ioaddr2 = confp->ioaddr2;
2739 brdp->irq = confp->irq;
2740 brdp->irqtype = confp->irqtype;
2745 * Find any dynamically supported boards. That is via module load
2746 * line options or auto-detected on the PCI bus.
2756 /*****************************************************************************/
2759 * Return the board stats structure to user app.
2762 static int stl_getbrdstats(combrd_t __user *bp)
2768 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2770 if (stl_brdstats.brd >= STL_MAXBRDS)
2772 brdp = stl_brds[stl_brdstats.brd];
2773 if (brdp == (stlbrd_t *) NULL)
2776 memset(&stl_brdstats, 0, sizeof(combrd_t));
2777 stl_brdstats.brd = brdp->brdnr;
2778 stl_brdstats.type = brdp->brdtype;
2779 stl_brdstats.hwid = brdp->hwid;
2780 stl_brdstats.state = brdp->state;
2781 stl_brdstats.ioaddr = brdp->ioaddr1;
2782 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2783 stl_brdstats.irq = brdp->irq;
2784 stl_brdstats.nrpanels = brdp->nrpanels;
2785 stl_brdstats.nrports = brdp->nrports;
2786 for (i = 0; (i < brdp->nrpanels); i++) {
2787 panelp = brdp->panels[i];
2788 stl_brdstats.panels[i].panel = i;
2789 stl_brdstats.panels[i].hwid = panelp->hwid;
2790 stl_brdstats.panels[i].nrports = panelp->nrports;
2793 return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
2796 /*****************************************************************************/
2799 * Resolve the referenced port number into a port struct pointer.
2802 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2807 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2808 return((stlport_t *) NULL);
2809 brdp = stl_brds[brdnr];
2810 if (brdp == (stlbrd_t *) NULL)
2811 return((stlport_t *) NULL);
2812 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2813 return((stlport_t *) NULL);
2814 panelp = brdp->panels[panelnr];
2815 if (panelp == (stlpanel_t *) NULL)
2816 return((stlport_t *) NULL);
2817 if ((portnr < 0) || (portnr >= panelp->nrports))
2818 return((stlport_t *) NULL);
2819 return(panelp->ports[portnr]);
2822 /*****************************************************************************/
2825 * Return the port stats structure to user app. A NULL port struct
2826 * pointer passed in means that we need to find out from the app
2827 * what port to get stats for (used through board control device).
2830 static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
2832 unsigned char *head, *tail;
2833 unsigned long flags;
2836 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2838 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2840 if (portp == (stlport_t *) NULL)
2844 portp->stats.state = portp->istate;
2845 portp->stats.flags = portp->flags;
2846 portp->stats.hwid = portp->hwid;
2848 portp->stats.ttystate = 0;
2849 portp->stats.cflags = 0;
2850 portp->stats.iflags = 0;
2851 portp->stats.oflags = 0;
2852 portp->stats.lflags = 0;
2853 portp->stats.rxbuffered = 0;
2855 spin_lock_irqsave(&stallion_lock, flags);
2856 if (portp->tty != (struct tty_struct *) NULL) {
2857 if (portp->tty->driver_data == portp) {
2858 portp->stats.ttystate = portp->tty->flags;
2859 /* No longer available as a statistic */
2860 portp->stats.rxbuffered = 1; /*portp->tty->flip.count; */
2861 if (portp->tty->termios != (struct termios *) NULL) {
2862 portp->stats.cflags = portp->tty->termios->c_cflag;
2863 portp->stats.iflags = portp->tty->termios->c_iflag;
2864 portp->stats.oflags = portp->tty->termios->c_oflag;
2865 portp->stats.lflags = portp->tty->termios->c_lflag;
2869 spin_unlock_irqrestore(&stallion_lock, flags);
2871 head = portp->tx.head;
2872 tail = portp->tx.tail;
2873 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2874 (STL_TXBUFSIZE - (tail - head)));
2876 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2878 return copy_to_user(cp, &portp->stats,
2879 sizeof(comstats_t)) ? -EFAULT : 0;
2882 /*****************************************************************************/
2885 * Clear the port stats structure. We also return it zeroed out...
2888 static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp)
2891 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2893 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2895 if (portp == (stlport_t *) NULL)
2899 memset(&portp->stats, 0, sizeof(comstats_t));
2900 portp->stats.brd = portp->brdnr;
2901 portp->stats.panel = portp->panelnr;
2902 portp->stats.port = portp->portnr;
2903 return copy_to_user(cp, &portp->stats,
2904 sizeof(comstats_t)) ? -EFAULT : 0;
2907 /*****************************************************************************/
2910 * Return the entire driver ports structure to a user app.
2913 static int stl_getportstruct(stlport_t __user *arg)
2917 if (copy_from_user(&stl_dummyport, arg, sizeof(stlport_t)))
2919 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
2920 stl_dummyport.portnr);
2923 return copy_to_user(arg, portp, sizeof(stlport_t)) ? -EFAULT : 0;
2926 /*****************************************************************************/
2929 * Return the entire driver board structure to a user app.
2932 static int stl_getbrdstruct(stlbrd_t __user *arg)
2936 if (copy_from_user(&stl_dummybrd, arg, sizeof(stlbrd_t)))
2938 if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
2940 brdp = stl_brds[stl_dummybrd.brdnr];
2943 return copy_to_user(arg, brdp, sizeof(stlbrd_t)) ? -EFAULT : 0;
2946 /*****************************************************************************/
2949 * The "staliomem" device is also required to do some special operations
2950 * on the board and/or ports. In this driver it is mostly used for stats
2954 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
2957 void __user *argp = (void __user *)arg;
2960 printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
2961 (int) fp, cmd, (int) arg);
2965 if (brdnr >= STL_MAXBRDS)
2970 case COM_GETPORTSTATS:
2971 rc = stl_getportstats(NULL, argp);
2973 case COM_CLRPORTSTATS:
2974 rc = stl_clrportstats(NULL, argp);
2976 case COM_GETBRDSTATS:
2977 rc = stl_getbrdstats(argp);
2980 rc = stl_getportstruct(argp);
2983 rc = stl_getbrdstruct(argp);
2993 static const struct tty_operations stl_ops = {
2997 .put_char = stl_putchar,
2998 .flush_chars = stl_flushchars,
2999 .write_room = stl_writeroom,
3000 .chars_in_buffer = stl_charsinbuffer,
3002 .set_termios = stl_settermios,
3003 .throttle = stl_throttle,
3004 .unthrottle = stl_unthrottle,
3007 .hangup = stl_hangup,
3008 .flush_buffer = stl_flushbuffer,
3009 .break_ctl = stl_breakctl,
3010 .wait_until_sent = stl_waituntilsent,
3011 .send_xchar = stl_sendxchar,
3012 .read_proc = stl_readproc,
3013 .tiocmget = stl_tiocmget,
3014 .tiocmset = stl_tiocmset,
3017 /*****************************************************************************/
3019 static int __init stl_init(void)
3022 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
3024 spin_lock_init(&stallion_lock);
3025 spin_lock_init(&brd_lock);
3029 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
3034 * Set up a character driver for per board stuff. This is mainly used
3035 * to do stats ioctls on the ports.
3037 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
3038 printk("STALLION: failed to register serial board device\n");
3040 stallion_class = class_create(THIS_MODULE, "staliomem");
3041 for (i = 0; i < 4; i++)
3042 class_device_create(stallion_class, NULL,
3043 MKDEV(STL_SIOMEMMAJOR, i), NULL,
3046 stl_serial->owner = THIS_MODULE;
3047 stl_serial->driver_name = stl_drvname;
3048 stl_serial->name = "ttyE";
3049 stl_serial->major = STL_SERIALMAJOR;
3050 stl_serial->minor_start = 0;
3051 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
3052 stl_serial->subtype = SERIAL_TYPE_NORMAL;
3053 stl_serial->init_termios = stl_deftermios;
3054 stl_serial->flags = TTY_DRIVER_REAL_RAW;
3055 tty_set_operations(stl_serial, &stl_ops);
3057 if (tty_register_driver(stl_serial)) {
3058 put_tty_driver(stl_serial);
3059 printk("STALLION: failed to register serial driver\n");
3066 /*****************************************************************************/
3067 /* CD1400 HARDWARE FUNCTIONS */
3068 /*****************************************************************************/
3071 * These functions get/set/update the registers of the cd1400 UARTs.
3072 * Access to the cd1400 registers is via an address/data io port pair.
3073 * (Maybe should make this inline...)
3076 static int stl_cd1400getreg(stlport_t *portp, int regnr)
3078 outb((regnr + portp->uartaddr), portp->ioaddr);
3079 return inb(portp->ioaddr + EREG_DATA);
3082 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
3084 outb((regnr + portp->uartaddr), portp->ioaddr);
3085 outb(value, portp->ioaddr + EREG_DATA);
3088 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
3090 outb((regnr + portp->uartaddr), portp->ioaddr);
3091 if (inb(portp->ioaddr + EREG_DATA) != value) {
3092 outb(value, portp->ioaddr + EREG_DATA);
3098 /*****************************************************************************/
3101 * Inbitialize the UARTs in a panel. We don't care what sort of board
3102 * these ports are on - since the port io registers are almost
3103 * identical when dealing with ports.
3106 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3110 int nrchips, uartaddr, ioaddr;
3111 unsigned long flags;
3114 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
3117 spin_lock_irqsave(&brd_lock, flags);
3118 BRDENABLE(panelp->brdnr, panelp->pagenr);
3121 * Check that each chip is present and started up OK.
3124 nrchips = panelp->nrports / CD1400_PORTS;
3125 for (i = 0; (i < nrchips); i++) {
3126 if (brdp->brdtype == BRD_ECHPCI) {
3127 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3128 ioaddr = panelp->iobase;
3130 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3132 uartaddr = (i & 0x01) ? 0x080 : 0;
3133 outb((GFRCR + uartaddr), ioaddr);
3134 outb(0, (ioaddr + EREG_DATA));
3135 outb((CCR + uartaddr), ioaddr);
3136 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3137 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3138 outb((GFRCR + uartaddr), ioaddr);
3139 for (j = 0; (j < CCR_MAXWAIT); j++) {
3140 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3143 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3144 printk("STALLION: cd1400 not responding, "
3145 "brd=%d panel=%d chip=%d\n",
3146 panelp->brdnr, panelp->panelnr, i);
3149 chipmask |= (0x1 << i);
3150 outb((PPR + uartaddr), ioaddr);
3151 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
3154 BRDDISABLE(panelp->brdnr);
3155 spin_unlock_irqrestore(&brd_lock, flags);
3159 /*****************************************************************************/
3162 * Initialize hardware specific port registers.
3165 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3167 unsigned long flags;
3169 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3170 (int) brdp, (int) panelp, (int) portp);
3173 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
3174 (portp == (stlport_t *) NULL))
3177 spin_lock_irqsave(&brd_lock, flags);
3178 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3179 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3180 portp->uartaddr = (portp->portnr & 0x04) << 5;
3181 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3183 BRDENABLE(portp->brdnr, portp->pagenr);
3184 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3185 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3186 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3187 BRDDISABLE(portp->brdnr);
3188 spin_unlock_irqrestore(&brd_lock, flags);
3191 /*****************************************************************************/
3194 * Wait for the command register to be ready. We will poll this,
3195 * since it won't usually take too long to be ready.
3198 static void stl_cd1400ccrwait(stlport_t *portp)
3202 for (i = 0; (i < CCR_MAXWAIT); i++) {
3203 if (stl_cd1400getreg(portp, CCR) == 0) {
3208 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
3209 portp->portnr, portp->panelnr, portp->brdnr);
3212 /*****************************************************************************/
3215 * Set up the cd1400 registers for a port based on the termios port
3219 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3222 unsigned long flags;
3223 unsigned int clkdiv, baudrate;
3224 unsigned char cor1, cor2, cor3;
3225 unsigned char cor4, cor5, ccr;
3226 unsigned char srer, sreron, sreroff;
3227 unsigned char mcor1, mcor2, rtpr;
3228 unsigned char clk, div;
3244 brdp = stl_brds[portp->brdnr];
3245 if (brdp == (stlbrd_t *) NULL)
3249 * Set up the RX char ignore mask with those RX error types we
3250 * can ignore. We can get the cd1400 to help us out a little here,
3251 * it will ignore parity errors and breaks for us.
3253 portp->rxignoremsk = 0;
3254 if (tiosp->c_iflag & IGNPAR) {
3255 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
3256 cor1 |= COR1_PARIGNORE;
3258 if (tiosp->c_iflag & IGNBRK) {
3259 portp->rxignoremsk |= ST_BREAK;
3260 cor4 |= COR4_IGNBRK;
3263 portp->rxmarkmsk = ST_OVERRUN;
3264 if (tiosp->c_iflag & (INPCK | PARMRK))
3265 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3266 if (tiosp->c_iflag & BRKINT)
3267 portp->rxmarkmsk |= ST_BREAK;
3270 * Go through the char size, parity and stop bits and set all the
3271 * option register appropriately.
3273 switch (tiosp->c_cflag & CSIZE) {
3288 if (tiosp->c_cflag & CSTOPB)
3293 if (tiosp->c_cflag & PARENB) {
3294 if (tiosp->c_cflag & PARODD)
3295 cor1 |= (COR1_PARENB | COR1_PARODD);
3297 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3299 cor1 |= COR1_PARNONE;
3303 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3304 * space for hardware flow control and the like. This should be set to
3305 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3306 * really be based on VTIME.
3308 cor3 |= FIFO_RXTHRESHOLD;
3312 * Calculate the baud rate timers. For now we will just assume that
3313 * the input and output baud are the same. Could have used a baud
3314 * table here, but this way we can generate virtually any baud rate
3317 baudrate = tiosp->c_cflag & CBAUD;
3318 if (baudrate & CBAUDEX) {
3319 baudrate &= ~CBAUDEX;
3320 if ((baudrate < 1) || (baudrate > 4))
3321 tiosp->c_cflag &= ~CBAUDEX;
3325 baudrate = stl_baudrates[baudrate];
3326 if ((tiosp->c_cflag & CBAUD) == B38400) {
3327 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3329 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3331 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3333 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3335 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3336 baudrate = (portp->baud_base / portp->custom_divisor);
3338 if (baudrate > STL_CD1400MAXBAUD)
3339 baudrate = STL_CD1400MAXBAUD;
3342 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3343 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
3347 div = (unsigned char) clkdiv;
3351 * Check what form of modem signaling is required and set it up.
3353 if ((tiosp->c_cflag & CLOCAL) == 0) {
3356 sreron |= SRER_MODEM;
3357 portp->flags |= ASYNC_CHECK_CD;
3359 portp->flags &= ~ASYNC_CHECK_CD;
3363 * Setup cd1400 enhanced modes if we can. In particular we want to
3364 * handle as much of the flow control as possible automatically. As
3365 * well as saving a few CPU cycles it will also greatly improve flow
3366 * control reliability.
3368 if (tiosp->c_iflag & IXON) {
3371 if (tiosp->c_iflag & IXANY)
3375 if (tiosp->c_cflag & CRTSCTS) {
3377 mcor1 |= FIFO_RTSTHRESHOLD;
3381 * All cd1400 register values calculated so go through and set
3386 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3387 portp->portnr, portp->panelnr, portp->brdnr);
3388 printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3389 cor1, cor2, cor3, cor4, cor5);
3390 printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3391 mcor1, mcor2, rtpr, sreron, sreroff);
3392 printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3393 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3394 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3395 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3398 spin_lock_irqsave(&brd_lock, flags);
3399 BRDENABLE(portp->brdnr, portp->pagenr);
3400 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3401 srer = stl_cd1400getreg(portp, SRER);
3402 stl_cd1400setreg(portp, SRER, 0);
3403 if (stl_cd1400updatereg(portp, COR1, cor1))
3405 if (stl_cd1400updatereg(portp, COR2, cor2))
3407 if (stl_cd1400updatereg(portp, COR3, cor3))
3410 stl_cd1400ccrwait(portp);
3411 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3413 stl_cd1400setreg(portp, COR4, cor4);
3414 stl_cd1400setreg(portp, COR5, cor5);
3415 stl_cd1400setreg(portp, MCOR1, mcor1);
3416 stl_cd1400setreg(portp, MCOR2, mcor2);
3418 stl_cd1400setreg(portp, TCOR, clk);
3419 stl_cd1400setreg(portp, TBPR, div);
3420 stl_cd1400setreg(portp, RCOR, clk);
3421 stl_cd1400setreg(portp, RBPR, div);
3423 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3424 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3425 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3426 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3427 stl_cd1400setreg(portp, RTPR, rtpr);
3428 mcor1 = stl_cd1400getreg(portp, MSVR1);
3429 if (mcor1 & MSVR1_DCD)
3430 portp->sigs |= TIOCM_CD;
3432 portp->sigs &= ~TIOCM_CD;
3433 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3434 BRDDISABLE(portp->brdnr);
3435 spin_unlock_irqrestore(&brd_lock, flags);
3438 /*****************************************************************************/
3441 * Set the state of the DTR and RTS signals.
3444 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3446 unsigned char msvr1, msvr2;
3447 unsigned long flags;
3450 printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
3451 (int) portp, dtr, rts);
3461 spin_lock_irqsave(&brd_lock, flags);
3462 BRDENABLE(portp->brdnr, portp->pagenr);
3463 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3465 stl_cd1400setreg(portp, MSVR2, msvr2);
3467 stl_cd1400setreg(portp, MSVR1, msvr1);
3468 BRDDISABLE(portp->brdnr);
3469 spin_unlock_irqrestore(&brd_lock, flags);
3472 /*****************************************************************************/
3475 * Return the state of the signals.
3478 static int stl_cd1400getsignals(stlport_t *portp)
3480 unsigned char msvr1, msvr2;
3481 unsigned long flags;
3485 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3488 spin_lock_irqsave(&brd_lock, flags);
3489 BRDENABLE(portp->brdnr, portp->pagenr);
3490 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3491 msvr1 = stl_cd1400getreg(portp, MSVR1);
3492 msvr2 = stl_cd1400getreg(portp, MSVR2);
3493 BRDDISABLE(portp->brdnr);
3494 spin_unlock_irqrestore(&brd_lock, flags);
3497 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3498 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3499 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3500 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3502 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3503 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3510 /*****************************************************************************/
3513 * Enable/Disable the Transmitter and/or Receiver.
3516 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3519 unsigned long flags;
3522 printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3523 (int) portp, rx, tx);
3528 ccr |= CCR_TXDISABLE;
3530 ccr |= CCR_TXENABLE;
3532 ccr |= CCR_RXDISABLE;
3534 ccr |= CCR_RXENABLE;
3536 spin_lock_irqsave(&brd_lock, flags);
3537 BRDENABLE(portp->brdnr, portp->pagenr);
3538 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3539 stl_cd1400ccrwait(portp);
3540 stl_cd1400setreg(portp, CCR, ccr);
3541 stl_cd1400ccrwait(portp);
3542 BRDDISABLE(portp->brdnr);
3543 spin_unlock_irqrestore(&brd_lock, flags);
3546 /*****************************************************************************/
3549 * Start/stop the Transmitter and/or Receiver.
3552 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3554 unsigned char sreron, sreroff;
3555 unsigned long flags;
3558 printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3559 (int) portp, rx, tx);
3565 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3567 sreron |= SRER_TXDATA;
3569 sreron |= SRER_TXEMPTY;
3571 sreroff |= SRER_RXDATA;
3573 sreron |= SRER_RXDATA;
3575 spin_lock_irqsave(&brd_lock, flags);
3576 BRDENABLE(portp->brdnr, portp->pagenr);
3577 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3578 stl_cd1400setreg(portp, SRER,
3579 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3580 BRDDISABLE(portp->brdnr);
3582 set_bit(ASYI_TXBUSY, &portp->istate);
3583 spin_unlock_irqrestore(&brd_lock, flags);
3586 /*****************************************************************************/
3589 * Disable all interrupts from this port.
3592 static void stl_cd1400disableintrs(stlport_t *portp)
3594 unsigned long flags;
3597 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3599 spin_lock_irqsave(&brd_lock, flags);
3600 BRDENABLE(portp->brdnr, portp->pagenr);
3601 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3602 stl_cd1400setreg(portp, SRER, 0);
3603 BRDDISABLE(portp->brdnr);
3604 spin_unlock_irqrestore(&brd_lock, flags);
3607 /*****************************************************************************/
3609 static void stl_cd1400sendbreak(stlport_t *portp, int len)
3611 unsigned long flags;
3614 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
3617 spin_lock_irqsave(&brd_lock, flags);
3618 BRDENABLE(portp->brdnr, portp->pagenr);
3619 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3620 stl_cd1400setreg(portp, SRER,
3621 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3623 BRDDISABLE(portp->brdnr);
3624 portp->brklen = len;
3626 portp->stats.txbreaks++;
3627 spin_unlock_irqrestore(&brd_lock, flags);
3630 /*****************************************************************************/
3633 * Take flow control actions...
3636 static void stl_cd1400flowctrl(stlport_t *portp, int state)
3638 struct tty_struct *tty;
3639 unsigned long flags;
3642 printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp, state);
3645 if (portp == (stlport_t *) NULL)
3648 if (tty == (struct tty_struct *) NULL)
3651 spin_lock_irqsave(&brd_lock, flags);
3652 BRDENABLE(portp->brdnr, portp->pagenr);
3653 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3656 if (tty->termios->c_iflag & IXOFF) {
3657 stl_cd1400ccrwait(portp);
3658 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3659 portp->stats.rxxon++;
3660 stl_cd1400ccrwait(portp);
3663 * Question: should we return RTS to what it was before? It may
3664 * have been set by an ioctl... Suppose not, since if you have
3665 * hardware flow control set then it is pretty silly to go and
3666 * set the RTS line by hand.
3668 if (tty->termios->c_cflag & CRTSCTS) {
3669 stl_cd1400setreg(portp, MCOR1,
3670 (stl_cd1400getreg(portp, MCOR1) |
3671 FIFO_RTSTHRESHOLD));
3672 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3673 portp->stats.rxrtson++;
3676 if (tty->termios->c_iflag & IXOFF) {
3677 stl_cd1400ccrwait(portp);
3678 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3679 portp->stats.rxxoff++;
3680 stl_cd1400ccrwait(portp);
3682 if (tty->termios->c_cflag & CRTSCTS) {
3683 stl_cd1400setreg(portp, MCOR1,
3684 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3685 stl_cd1400setreg(portp, MSVR2, 0);
3686 portp->stats.rxrtsoff++;
3690 BRDDISABLE(portp->brdnr);
3691 spin_unlock_irqrestore(&brd_lock, flags);
3694 /*****************************************************************************/
3697 * Send a flow control character...
3700 static void stl_cd1400sendflow(stlport_t *portp, int state)
3702 struct tty_struct *tty;
3703 unsigned long flags;
3706 printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp, state);
3709 if (portp == (stlport_t *) NULL)
3712 if (tty == (struct tty_struct *) NULL)
3715 spin_lock_irqsave(&brd_lock, flags);
3716 BRDENABLE(portp->brdnr, portp->pagenr);
3717 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3719 stl_cd1400ccrwait(portp);
3720 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3721 portp->stats.rxxon++;
3722 stl_cd1400ccrwait(portp);
3724 stl_cd1400ccrwait(portp);
3725 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3726 portp->stats.rxxoff++;
3727 stl_cd1400ccrwait(portp);
3729 BRDDISABLE(portp->brdnr);
3730 spin_unlock_irqrestore(&brd_lock, flags);
3733 /*****************************************************************************/
3735 static void stl_cd1400flush(stlport_t *portp)
3737 unsigned long flags;
3740 printk("stl_cd1400flush(portp=%x)\n", (int) portp);
3743 if (portp == (stlport_t *) NULL)
3746 spin_lock_irqsave(&brd_lock, flags);
3747 BRDENABLE(portp->brdnr, portp->pagenr);
3748 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3749 stl_cd1400ccrwait(portp);
3750 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3751 stl_cd1400ccrwait(portp);
3752 portp->tx.tail = portp->tx.head;
3753 BRDDISABLE(portp->brdnr);
3754 spin_unlock_irqrestore(&brd_lock, flags);
3757 /*****************************************************************************/
3760 * Return the current state of data flow on this port. This is only
3761 * really interresting when determining if data has fully completed
3762 * transmission or not... This is easy for the cd1400, it accurately
3763 * maintains the busy port flag.
3766 static int stl_cd1400datastate(stlport_t *portp)
3769 printk("stl_cd1400datastate(portp=%x)\n", (int) portp);
3772 if (portp == (stlport_t *) NULL)
3775 return test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0;
3778 /*****************************************************************************/
3781 * Interrupt service routine for cd1400 EasyIO boards.
3784 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3786 unsigned char svrtype;
3789 printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
3790 (int) panelp, iobase);
3793 spin_lock(&brd_lock);
3795 svrtype = inb(iobase + EREG_DATA);
3796 if (panelp->nrports > 4) {
3797 outb((SVRR + 0x80), iobase);
3798 svrtype |= inb(iobase + EREG_DATA);
3801 if (svrtype & SVRR_RX)
3802 stl_cd1400rxisr(panelp, iobase);
3803 else if (svrtype & SVRR_TX)
3804 stl_cd1400txisr(panelp, iobase);
3805 else if (svrtype & SVRR_MDM)
3806 stl_cd1400mdmisr(panelp, iobase);
3808 spin_unlock(&brd_lock);
3811 /*****************************************************************************/
3814 * Interrupt service routine for cd1400 panels.
3817 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
3819 unsigned char svrtype;
3822 printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
3827 svrtype = inb(iobase + EREG_DATA);
3828 outb((SVRR + 0x80), iobase);
3829 svrtype |= inb(iobase + EREG_DATA);
3830 if (svrtype & SVRR_RX)
3831 stl_cd1400rxisr(panelp, iobase);
3832 else if (svrtype & SVRR_TX)
3833 stl_cd1400txisr(panelp, iobase);
3834 else if (svrtype & SVRR_MDM)
3835 stl_cd1400mdmisr(panelp, iobase);
3839 /*****************************************************************************/
3842 * Unfortunately we need to handle breaks in the TX data stream, since
3843 * this is the only way to generate them on the cd1400.
3846 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr)
3848 if (portp->brklen == 1) {
3849 outb((COR2 + portp->uartaddr), ioaddr);
3850 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
3851 (ioaddr + EREG_DATA));
3852 outb((TDR + portp->uartaddr), ioaddr);
3853 outb(ETC_CMD, (ioaddr + EREG_DATA));
3854 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
3855 outb((SRER + portp->uartaddr), ioaddr);
3856 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
3857 (ioaddr + EREG_DATA));
3859 } else if (portp->brklen > 1) {
3860 outb((TDR + portp->uartaddr), ioaddr);
3861 outb(ETC_CMD, (ioaddr + EREG_DATA));
3862 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
3866 outb((COR2 + portp->uartaddr), ioaddr);
3867 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
3868 (ioaddr + EREG_DATA));
3874 /*****************************************************************************/
3877 * Transmit interrupt handler. This has gotta be fast! Handling TX
3878 * chars is pretty simple, stuff as many as possible from the TX buffer
3879 * into the cd1400 FIFO. Must also handle TX breaks here, since they
3880 * are embedded as commands in the data stream. Oh no, had to use a goto!
3881 * This could be optimized more, will do when I get time...
3882 * In practice it is possible that interrupts are enabled but that the
3883 * port has been hung up. Need to handle not having any TX buffer here,
3884 * this is done by using the side effect that head and tail will also
3885 * be NULL if the buffer has been freed.
3888 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
3893 unsigned char ioack, srer;
3896 printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
3899 ioack = inb(ioaddr + EREG_TXACK);
3900 if (((ioack & panelp->ackmask) != 0) ||
3901 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
3902 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
3905 portp = panelp->ports[(ioack >> 3)];
3908 * Unfortunately we need to handle breaks in the data stream, since
3909 * this is the only way to generate them on the cd1400. Do it now if
3910 * a break is to be sent.
3912 if (portp->brklen != 0)
3913 if (stl_cd1400breakisr(portp, ioaddr))
3916 head = portp->tx.head;
3917 tail = portp->tx.tail;
3918 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
3919 if ((len == 0) || ((len < STL_TXBUFLOW) &&
3920 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
3921 set_bit(ASYI_TXLOW, &portp->istate);
3922 schedule_work(&portp->tqueue);
3926 outb((SRER + portp->uartaddr), ioaddr);
3927 srer = inb(ioaddr + EREG_DATA);
3928 if (srer & SRER_TXDATA) {
3929 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
3931 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
3932 clear_bit(ASYI_TXBUSY, &portp->istate);
3934 outb(srer, (ioaddr + EREG_DATA));
3936 len = MIN(len, CD1400_TXFIFOSIZE);
3937 portp->stats.txtotal += len;
3938 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
3939 outb((TDR + portp->uartaddr), ioaddr);
3940 outsb((ioaddr + EREG_DATA), tail, stlen);
3943 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
3944 tail = portp->tx.buf;
3946 outsb((ioaddr + EREG_DATA), tail, len);
3949 portp->tx.tail = tail;
3953 outb((EOSRR + portp->uartaddr), ioaddr);
3954 outb(0, (ioaddr + EREG_DATA));
3957 /*****************************************************************************/
3960 * Receive character interrupt handler. Determine if we have good chars
3961 * or bad chars and then process appropriately. Good chars are easy
3962 * just shove the lot into the RX buffer and set all status byte to 0.
3963 * If a bad RX char then process as required. This routine needs to be
3964 * fast! In practice it is possible that we get an interrupt on a port
3965 * that is closed. This can happen on hangups - since they completely
3966 * shutdown a port not in user context. Need to handle this case.
3969 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
3972 struct tty_struct *tty;
3973 unsigned int ioack, len, buflen;
3974 unsigned char status;
3978 printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
3981 ioack = inb(ioaddr + EREG_RXACK);
3982 if ((ioack & panelp->ackmask) != 0) {
3983 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
3986 portp = panelp->ports[(ioack >> 3)];
3989 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
3990 outb((RDCR + portp->uartaddr), ioaddr);
3991 len = inb(ioaddr + EREG_DATA);
3992 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
3993 len = MIN(len, sizeof(stl_unwanted));
3994 outb((RDSR + portp->uartaddr), ioaddr);
3995 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
3996 portp->stats.rxlost += len;
3997 portp->stats.rxtotal += len;
3999 len = MIN(len, buflen);
4002 outb((RDSR + portp->uartaddr), ioaddr);
4003 tty_prepare_flip_string(tty, &ptr, len);
4004 insb((ioaddr + EREG_DATA), ptr, len);
4005 tty_schedule_flip(tty);
4006 portp->stats.rxtotal += len;
4009 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
4010 outb((RDSR + portp->uartaddr), ioaddr);
4011 status = inb(ioaddr + EREG_DATA);
4012 ch = inb(ioaddr + EREG_DATA);
4013 if (status & ST_PARITY)
4014 portp->stats.rxparity++;
4015 if (status & ST_FRAMING)
4016 portp->stats.rxframing++;
4017 if (status & ST_OVERRUN)
4018 portp->stats.rxoverrun++;
4019 if (status & ST_BREAK)
4020 portp->stats.rxbreaks++;
4021 if (status & ST_SCHARMASK) {
4022 if ((status & ST_SCHARMASK) == ST_SCHAR1)
4023 portp->stats.txxon++;
4024 if ((status & ST_SCHARMASK) == ST_SCHAR2)
4025 portp->stats.txxoff++;
4028 if (tty != NULL && (portp->rxignoremsk & status) == 0) {
4029 if (portp->rxmarkmsk & status) {
4030 if (status & ST_BREAK) {
4032 if (portp->flags & ASYNC_SAK) {
4034 BRDENABLE(portp->brdnr, portp->pagenr);
4036 } else if (status & ST_PARITY) {
4037 status = TTY_PARITY;
4038 } else if (status & ST_FRAMING) {
4040 } else if(status & ST_OVERRUN) {
4041 status = TTY_OVERRUN;
4048 tty_insert_flip_char(tty, ch, status);
4049 tty_schedule_flip(tty);
4052 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4057 outb((EOSRR + portp->uartaddr), ioaddr);
4058 outb(0, (ioaddr + EREG_DATA));
4061 /*****************************************************************************/
4064 * Modem interrupt handler. The is called when the modem signal line
4065 * (DCD) has changed state. Leave most of the work to the off-level
4066 * processing routine.
4069 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
4076 printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp);
4079 ioack = inb(ioaddr + EREG_MDACK);
4080 if (((ioack & panelp->ackmask) != 0) ||
4081 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
4082 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
4085 portp = panelp->ports[(ioack >> 3)];
4087 outb((MISR + portp->uartaddr), ioaddr);
4088 misr = inb(ioaddr + EREG_DATA);
4089 if (misr & MISR_DCD) {
4090 set_bit(ASYI_DCDCHANGE, &portp->istate);
4091 schedule_work(&portp->tqueue);
4092 portp->stats.modem++;
4095 outb((EOSRR + portp->uartaddr), ioaddr);
4096 outb(0, (ioaddr + EREG_DATA));
4099 /*****************************************************************************/
4100 /* SC26198 HARDWARE FUNCTIONS */
4101 /*****************************************************************************/
4104 * These functions get/set/update the registers of the sc26198 UARTs.
4105 * Access to the sc26198 registers is via an address/data io port pair.
4106 * (Maybe should make this inline...)
4109 static int stl_sc26198getreg(stlport_t *portp, int regnr)
4111 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4112 return inb(portp->ioaddr + XP_DATA);
4115 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
4117 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4118 outb(value, (portp->ioaddr + XP_DATA));
4121 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
4123 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4124 if (inb(portp->ioaddr + XP_DATA) != value) {
4125 outb(value, (portp->ioaddr + XP_DATA));
4131 /*****************************************************************************/
4134 * Functions to get and set the sc26198 global registers.
4137 static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
4139 outb(regnr, (portp->ioaddr + XP_ADDR));
4140 return inb(portp->ioaddr + XP_DATA);
4144 static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
4146 outb(regnr, (portp->ioaddr + XP_ADDR));
4147 outb(value, (portp->ioaddr + XP_DATA));
4151 /*****************************************************************************/
4154 * Inbitialize the UARTs in a panel. We don't care what sort of board
4155 * these ports are on - since the port io registers are almost
4156 * identical when dealing with ports.
4159 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
4162 int nrchips, ioaddr;
4165 printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
4166 (int) brdp, (int) panelp);
4169 BRDENABLE(panelp->brdnr, panelp->pagenr);
4172 * Check that each chip is present and started up OK.
4175 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
4176 if (brdp->brdtype == BRD_ECHPCI)
4177 outb(panelp->pagenr, brdp->ioctrl);
4179 for (i = 0; (i < nrchips); i++) {
4180 ioaddr = panelp->iobase + (i * 4);
4181 outb(SCCR, (ioaddr + XP_ADDR));
4182 outb(CR_RESETALL, (ioaddr + XP_DATA));
4183 outb(TSTR, (ioaddr + XP_ADDR));
4184 if (inb(ioaddr + XP_DATA) != 0) {
4185 printk("STALLION: sc26198 not responding, "
4186 "brd=%d panel=%d chip=%d\n",
4187 panelp->brdnr, panelp->panelnr, i);
4190 chipmask |= (0x1 << i);
4191 outb(GCCR, (ioaddr + XP_ADDR));
4192 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
4193 outb(WDTRCR, (ioaddr + XP_ADDR));
4194 outb(0xff, (ioaddr + XP_DATA));
4197 BRDDISABLE(panelp->brdnr);
4201 /*****************************************************************************/
4204 * Initialize hardware specific port registers.
4207 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
4210 printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
4211 (int) brdp, (int) panelp, (int) portp);
4214 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
4215 (portp == (stlport_t *) NULL))
4218 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
4219 portp->uartaddr = (portp->portnr & 0x07) << 4;
4220 portp->pagenr = panelp->pagenr;
4223 BRDENABLE(portp->brdnr, portp->pagenr);
4224 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
4225 BRDDISABLE(portp->brdnr);
4228 /*****************************************************************************/
4231 * Set up the sc26198 registers for a port based on the termios port
4235 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4238 unsigned long flags;
4239 unsigned int baudrate;
4240 unsigned char mr0, mr1, mr2, clk;
4241 unsigned char imron, imroff, iopr, ipr;
4251 brdp = stl_brds[portp->brdnr];
4252 if (brdp == (stlbrd_t *) NULL)
4256 * Set up the RX char ignore mask with those RX error types we
4259 portp->rxignoremsk = 0;
4260 if (tiosp->c_iflag & IGNPAR)
4261 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
4263 if (tiosp->c_iflag & IGNBRK)
4264 portp->rxignoremsk |= SR_RXBREAK;
4266 portp->rxmarkmsk = SR_RXOVERRUN;
4267 if (tiosp->c_iflag & (INPCK | PARMRK))
4268 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
4269 if (tiosp->c_iflag & BRKINT)
4270 portp->rxmarkmsk |= SR_RXBREAK;
4273 * Go through the char size, parity and stop bits and set all the
4274 * option register appropriately.
4276 switch (tiosp->c_cflag & CSIZE) {
4291 if (tiosp->c_cflag & CSTOPB)
4296 if (tiosp->c_cflag & PARENB) {
4297 if (tiosp->c_cflag & PARODD)
4298 mr1 |= (MR1_PARENB | MR1_PARODD);
4300 mr1 |= (MR1_PARENB | MR1_PAREVEN);
4305 mr1 |= MR1_ERRBLOCK;
4308 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4309 * space for hardware flow control and the like. This should be set to
4312 mr2 |= MR2_RXFIFOHALF;
4315 * Calculate the baud rate timers. For now we will just assume that
4316 * the input and output baud are the same. The sc26198 has a fixed
4317 * baud rate table, so only discrete baud rates possible.
4319 baudrate = tiosp->c_cflag & CBAUD;
4320 if (baudrate & CBAUDEX) {
4321 baudrate &= ~CBAUDEX;
4322 if ((baudrate < 1) || (baudrate > 4))
4323 tiosp->c_cflag &= ~CBAUDEX;
4327 baudrate = stl_baudrates[baudrate];
4328 if ((tiosp->c_cflag & CBAUD) == B38400) {
4329 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
4331 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
4333 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
4335 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
4337 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
4338 baudrate = (portp->baud_base / portp->custom_divisor);
4340 if (baudrate > STL_SC26198MAXBAUD)
4341 baudrate = STL_SC26198MAXBAUD;
4344 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
4345 if (baudrate <= sc26198_baudtable[clk])
4351 * Check what form of modem signaling is required and set it up.
4353 if (tiosp->c_cflag & CLOCAL) {
4354 portp->flags &= ~ASYNC_CHECK_CD;
4356 iopr |= IOPR_DCDCOS;
4358 portp->flags |= ASYNC_CHECK_CD;
4362 * Setup sc26198 enhanced modes if we can. In particular we want to
4363 * handle as much of the flow control as possible automatically. As
4364 * well as saving a few CPU cycles it will also greatly improve flow
4365 * control reliability.
4367 if (tiosp->c_iflag & IXON) {
4368 mr0 |= MR0_SWFTX | MR0_SWFT;
4369 imron |= IR_XONXOFF;
4371 imroff |= IR_XONXOFF;
4373 if (tiosp->c_iflag & IXOFF)
4376 if (tiosp->c_cflag & CRTSCTS) {
4382 * All sc26198 register values calculated so go through and set
4387 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4388 portp->portnr, portp->panelnr, portp->brdnr);
4389 printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4390 printk(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4391 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4392 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4393 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4396 spin_lock_irqsave(&brd_lock, flags);
4397 BRDENABLE(portp->brdnr, portp->pagenr);
4398 stl_sc26198setreg(portp, IMR, 0);
4399 stl_sc26198updatereg(portp, MR0, mr0);
4400 stl_sc26198updatereg(portp, MR1, mr1);
4401 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4402 stl_sc26198updatereg(portp, MR2, mr2);
4403 stl_sc26198updatereg(portp, IOPIOR,
4404 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
4407 stl_sc26198setreg(portp, TXCSR, clk);
4408 stl_sc26198setreg(portp, RXCSR, clk);
4411 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4412 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4414 ipr = stl_sc26198getreg(portp, IPR);
4416 portp->sigs &= ~TIOCM_CD;
4418 portp->sigs |= TIOCM_CD;
4420 portp->imr = (portp->imr & ~imroff) | imron;
4421 stl_sc26198setreg(portp, IMR, portp->imr);
4422 BRDDISABLE(portp->brdnr);
4423 spin_unlock_irqrestore(&brd_lock, flags);
4426 /*****************************************************************************/
4429 * Set the state of the DTR and RTS signals.
4432 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
4434 unsigned char iopioron, iopioroff;
4435 unsigned long flags;
4438 printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4439 (int) portp, dtr, rts);
4445 iopioroff |= IPR_DTR;
4447 iopioron |= IPR_DTR;
4449 iopioroff |= IPR_RTS;
4451 iopioron |= IPR_RTS;
4453 spin_lock_irqsave(&brd_lock, flags);
4454 BRDENABLE(portp->brdnr, portp->pagenr);
4455 stl_sc26198setreg(portp, IOPIOR,
4456 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4457 BRDDISABLE(portp->brdnr);
4458 spin_unlock_irqrestore(&brd_lock, flags);
4461 /*****************************************************************************/
4464 * Return the state of the signals.
4467 static int stl_sc26198getsignals(stlport_t *portp)
4470 unsigned long flags;
4474 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
4477 spin_lock_irqsave(&brd_lock, flags);
4478 BRDENABLE(portp->brdnr, portp->pagenr);
4479 ipr = stl_sc26198getreg(portp, IPR);
4480 BRDDISABLE(portp->brdnr);
4481 spin_unlock_irqrestore(&brd_lock, flags);
4484 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4485 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4486 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4487 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4492 /*****************************************************************************/
4495 * Enable/Disable the Transmitter and/or Receiver.
4498 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
4501 unsigned long flags;
4504 printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4505 (int) portp, rx, tx);
4508 ccr = portp->crenable;
4510 ccr &= ~CR_TXENABLE;
4514 ccr &= ~CR_RXENABLE;
4518 spin_lock_irqsave(&brd_lock, flags);
4519 BRDENABLE(portp->brdnr, portp->pagenr);
4520 stl_sc26198setreg(portp, SCCR, ccr);
4521 BRDDISABLE(portp->brdnr);
4522 portp->crenable = ccr;
4523 spin_unlock_irqrestore(&brd_lock, flags);
4526 /*****************************************************************************/
4529 * Start/stop the Transmitter and/or Receiver.
4532 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
4535 unsigned long flags;
4538 printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4539 (int) portp, rx, tx);
4548 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4550 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4552 spin_lock_irqsave(&brd_lock, flags);
4553 BRDENABLE(portp->brdnr, portp->pagenr);
4554 stl_sc26198setreg(portp, IMR, imr);
4555 BRDDISABLE(portp->brdnr);
4558 set_bit(ASYI_TXBUSY, &portp->istate);
4559 spin_unlock_irqrestore(&brd_lock, flags);
4562 /*****************************************************************************/
4565 * Disable all interrupts from this port.
4568 static void stl_sc26198disableintrs(stlport_t *portp)
4570 unsigned long flags;
4573 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
4576 spin_lock_irqsave(&brd_lock, flags);
4577 BRDENABLE(portp->brdnr, portp->pagenr);
4579 stl_sc26198setreg(portp, IMR, 0);
4580 BRDDISABLE(portp->brdnr);
4581 spin_unlock_irqrestore(&brd_lock, flags);
4584 /*****************************************************************************/
4586 static void stl_sc26198sendbreak(stlport_t *portp, int len)
4588 unsigned long flags;
4591 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
4594 spin_lock_irqsave(&brd_lock, flags);
4595 BRDENABLE(portp->brdnr, portp->pagenr);
4597 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4598 portp->stats.txbreaks++;
4600 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4602 BRDDISABLE(portp->brdnr);
4603 spin_unlock_irqrestore(&brd_lock, flags);
4606 /*****************************************************************************/
4609 * Take flow control actions...
4612 static void stl_sc26198flowctrl(stlport_t *portp, int state)
4614 struct tty_struct *tty;
4615 unsigned long flags;
4619 printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp, state);
4622 if (portp == (stlport_t *) NULL)
4625 if (tty == (struct tty_struct *) NULL)
4628 spin_lock_irqsave(&brd_lock, flags);
4629 BRDENABLE(portp->brdnr, portp->pagenr);
4632 if (tty->termios->c_iflag & IXOFF) {
4633 mr0 = stl_sc26198getreg(portp, MR0);
4634 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4635 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4637 portp->stats.rxxon++;
4638 stl_sc26198wait(portp);
4639 stl_sc26198setreg(portp, MR0, mr0);
4642 * Question: should we return RTS to what it was before? It may
4643 * have been set by an ioctl... Suppose not, since if you have
4644 * hardware flow control set then it is pretty silly to go and
4645 * set the RTS line by hand.
4647 if (tty->termios->c_cflag & CRTSCTS) {
4648 stl_sc26198setreg(portp, MR1,
4649 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4650 stl_sc26198setreg(portp, IOPIOR,
4651 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4652 portp->stats.rxrtson++;
4655 if (tty->termios->c_iflag & IXOFF) {
4656 mr0 = stl_sc26198getreg(portp, MR0);
4657 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4658 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4660 portp->stats.rxxoff++;
4661 stl_sc26198wait(portp);
4662 stl_sc26198setreg(portp, MR0, mr0);
4664 if (tty->termios->c_cflag & CRTSCTS) {
4665 stl_sc26198setreg(portp, MR1,
4666 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4667 stl_sc26198setreg(portp, IOPIOR,
4668 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4669 portp->stats.rxrtsoff++;
4673 BRDDISABLE(portp->brdnr);
4674 spin_unlock_irqrestore(&brd_lock, flags);
4677 /*****************************************************************************/
4680 * Send a flow control character.
4683 static void stl_sc26198sendflow(stlport_t *portp, int state)
4685 struct tty_struct *tty;
4686 unsigned long flags;
4690 printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp, state);
4693 if (portp == (stlport_t *) NULL)
4696 if (tty == (struct tty_struct *) NULL)
4699 spin_lock_irqsave(&brd_lock, flags);
4700 BRDENABLE(portp->brdnr, portp->pagenr);
4702 mr0 = stl_sc26198getreg(portp, MR0);
4703 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4704 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4706 portp->stats.rxxon++;
4707 stl_sc26198wait(portp);
4708 stl_sc26198setreg(portp, MR0, mr0);
4710 mr0 = stl_sc26198getreg(portp, MR0);
4711 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4712 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4714 portp->stats.rxxoff++;
4715 stl_sc26198wait(portp);
4716 stl_sc26198setreg(portp, MR0, mr0);
4718 BRDDISABLE(portp->brdnr);
4719 spin_unlock_irqrestore(&brd_lock, flags);
4722 /*****************************************************************************/
4724 static void stl_sc26198flush(stlport_t *portp)
4726 unsigned long flags;
4729 printk("stl_sc26198flush(portp=%x)\n", (int) portp);
4732 if (portp == (stlport_t *) NULL)
4735 spin_lock_irqsave(&brd_lock, flags);
4736 BRDENABLE(portp->brdnr, portp->pagenr);
4737 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4738 stl_sc26198setreg(portp, SCCR, portp->crenable);
4739 BRDDISABLE(portp->brdnr);
4740 portp->tx.tail = portp->tx.head;
4741 spin_unlock_irqrestore(&brd_lock, flags);
4744 /*****************************************************************************/
4747 * Return the current state of data flow on this port. This is only
4748 * really interresting when determining if data has fully completed
4749 * transmission or not... The sc26198 interrupt scheme cannot
4750 * determine when all data has actually drained, so we need to
4751 * check the port statusy register to be sure.
4754 static int stl_sc26198datastate(stlport_t *portp)
4756 unsigned long flags;
4760 printk("stl_sc26198datastate(portp=%x)\n", (int) portp);
4763 if (portp == (stlport_t *) NULL)
4765 if (test_bit(ASYI_TXBUSY, &portp->istate))
4768 spin_lock_irqsave(&brd_lock, flags);
4769 BRDENABLE(portp->brdnr, portp->pagenr);
4770 sr = stl_sc26198getreg(portp, SR);
4771 BRDDISABLE(portp->brdnr);
4772 spin_unlock_irqrestore(&brd_lock, flags);
4774 return (sr & SR_TXEMPTY) ? 0 : 1;
4777 /*****************************************************************************/
4780 * Delay for a small amount of time, to give the sc26198 a chance
4781 * to process a command...
4784 static void stl_sc26198wait(stlport_t *portp)
4789 printk("stl_sc26198wait(portp=%x)\n", (int) portp);
4792 if (portp == (stlport_t *) NULL)
4795 for (i = 0; (i < 20); i++)
4796 stl_sc26198getglobreg(portp, TSTR);
4799 /*****************************************************************************/
4802 * If we are TX flow controlled and in IXANY mode then we may
4803 * need to unflow control here. We gotta do this because of the
4804 * automatic flow control modes of the sc26198.
4807 static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty)
4811 mr0 = stl_sc26198getreg(portp, MR0);
4812 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4813 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4814 stl_sc26198wait(portp);
4815 stl_sc26198setreg(portp, MR0, mr0);
4816 clear_bit(ASYI_TXFLOWED, &portp->istate);
4819 /*****************************************************************************/
4822 * Interrupt service routine for sc26198 panels.
4825 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4830 spin_lock(&brd_lock);
4833 * Work around bug in sc26198 chip... Cannot have A6 address
4834 * line of UART high, else iack will be returned as 0.
4836 outb(0, (iobase + 1));
4838 iack = inb(iobase + XP_IACK);
4839 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4841 if (iack & IVR_RXDATA)
4842 stl_sc26198rxisr(portp, iack);
4843 else if (iack & IVR_TXDATA)
4844 stl_sc26198txisr(portp);
4846 stl_sc26198otherisr(portp, iack);
4848 spin_unlock(&brd_lock);
4851 /*****************************************************************************/
4854 * Transmit interrupt handler. This has gotta be fast! Handling TX
4855 * chars is pretty simple, stuff as many as possible from the TX buffer
4856 * into the sc26198 FIFO.
4857 * In practice it is possible that interrupts are enabled but that the
4858 * port has been hung up. Need to handle not having any TX buffer here,
4859 * this is done by using the side effect that head and tail will also
4860 * be NULL if the buffer has been freed.
4863 static void stl_sc26198txisr(stlport_t *portp)
4865 unsigned int ioaddr;
4871 printk("stl_sc26198txisr(portp=%x)\n", (int) portp);
4874 ioaddr = portp->ioaddr;
4875 head = portp->tx.head;
4876 tail = portp->tx.tail;
4877 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4878 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4879 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4880 set_bit(ASYI_TXLOW, &portp->istate);
4881 schedule_work(&portp->tqueue);
4885 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
4886 mr0 = inb(ioaddr + XP_DATA);
4887 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4888 portp->imr &= ~IR_TXRDY;
4889 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
4890 outb(portp->imr, (ioaddr + XP_DATA));
4891 clear_bit(ASYI_TXBUSY, &portp->istate);
4893 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4894 outb(mr0, (ioaddr + XP_DATA));
4897 len = MIN(len, SC26198_TXFIFOSIZE);
4898 portp->stats.txtotal += len;
4899 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4900 outb(GTXFIFO, (ioaddr + XP_ADDR));
4901 outsb((ioaddr + XP_DATA), tail, stlen);
4904 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4905 tail = portp->tx.buf;
4907 outsb((ioaddr + XP_DATA), tail, len);
4910 portp->tx.tail = tail;
4914 /*****************************************************************************/
4917 * Receive character interrupt handler. Determine if we have good chars
4918 * or bad chars and then process appropriately. Good chars are easy
4919 * just shove the lot into the RX buffer and set all status byte to 0.
4920 * If a bad RX char then process as required. This routine needs to be
4921 * fast! In practice it is possible that we get an interrupt on a port
4922 * that is closed. This can happen on hangups - since they completely
4923 * shutdown a port not in user context. Need to handle this case.
4926 static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
4928 struct tty_struct *tty;
4929 unsigned int len, buflen, ioaddr;
4932 printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
4936 ioaddr = portp->ioaddr;
4937 outb(GIBCR, (ioaddr + XP_ADDR));
4938 len = inb(ioaddr + XP_DATA) + 1;
4940 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
4941 if (tty == NULL || (buflen = tty_buffer_request_room(tty, len)) == 0) {
4942 len = MIN(len, sizeof(stl_unwanted));
4943 outb(GRXFIFO, (ioaddr + XP_ADDR));
4944 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4945 portp->stats.rxlost += len;
4946 portp->stats.rxtotal += len;
4948 len = MIN(len, buflen);
4951 outb(GRXFIFO, (ioaddr + XP_ADDR));
4952 tty_prepare_flip_string(tty, &ptr, len);
4953 insb((ioaddr + XP_DATA), ptr, len);
4954 tty_schedule_flip(tty);
4955 portp->stats.rxtotal += len;
4959 stl_sc26198rxbadchars(portp);
4963 * If we are TX flow controlled and in IXANY mode then we may need
4964 * to unflow control here. We gotta do this because of the automatic
4965 * flow control modes of the sc26198.
4967 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
4968 if ((tty != (struct tty_struct *) NULL) &&
4969 (tty->termios != (struct termios *) NULL) &&
4970 (tty->termios->c_iflag & IXANY)) {
4971 stl_sc26198txunflow(portp, tty);
4976 /*****************************************************************************/
4979 * Process an RX bad character.
4982 static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch)
4984 struct tty_struct *tty;
4985 unsigned int ioaddr;
4988 ioaddr = portp->ioaddr;
4990 if (status & SR_RXPARITY)
4991 portp->stats.rxparity++;
4992 if (status & SR_RXFRAMING)
4993 portp->stats.rxframing++;
4994 if (status & SR_RXOVERRUN)
4995 portp->stats.rxoverrun++;
4996 if (status & SR_RXBREAK)
4997 portp->stats.rxbreaks++;
4999 if ((tty != (struct tty_struct *) NULL) &&
5000 ((portp->rxignoremsk & status) == 0)) {
5001 if (portp->rxmarkmsk & status) {
5002 if (status & SR_RXBREAK) {
5004 if (portp->flags & ASYNC_SAK) {
5006 BRDENABLE(portp->brdnr, portp->pagenr);
5008 } else if (status & SR_RXPARITY) {
5009 status = TTY_PARITY;
5010 } else if (status & SR_RXFRAMING) {
5012 } else if(status & SR_RXOVERRUN) {
5013 status = TTY_OVERRUN;
5021 tty_insert_flip_char(tty, ch, status);
5022 tty_schedule_flip(tty);
5025 portp->stats.rxtotal++;
5029 /*****************************************************************************/
5032 * Process all characters in the RX FIFO of the UART. Check all char
5033 * status bytes as well, and process as required. We need to check
5034 * all bytes in the FIFO, in case some more enter the FIFO while we
5035 * are here. To get the exact character error type we need to switch
5036 * into CHAR error mode (that is why we need to make sure we empty
5040 static void stl_sc26198rxbadchars(stlport_t *portp)
5042 unsigned char status, mr1;
5046 * To get the precise error type for each character we must switch
5047 * back into CHAR error mode.
5049 mr1 = stl_sc26198getreg(portp, MR1);
5050 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
5052 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
5053 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
5054 ch = stl_sc26198getreg(portp, RXFIFO);
5055 stl_sc26198rxbadch(portp, status, ch);
5059 * To get correct interrupt class we must switch back into BLOCK
5062 stl_sc26198setreg(portp, MR1, mr1);
5065 /*****************************************************************************/
5068 * Other interrupt handler. This includes modem signals, flow
5069 * control actions, etc. Most stuff is left to off-level interrupt
5073 static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
5075 unsigned char cir, ipr, xisr;
5078 printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
5081 cir = stl_sc26198getglobreg(portp, CIR);
5083 switch (cir & CIR_SUBTYPEMASK) {
5085 ipr = stl_sc26198getreg(portp, IPR);
5086 if (ipr & IPR_DCDCHANGE) {
5087 set_bit(ASYI_DCDCHANGE, &portp->istate);
5088 schedule_work(&portp->tqueue);
5089 portp->stats.modem++;
5092 case CIR_SUBXONXOFF:
5093 xisr = stl_sc26198getreg(portp, XISR);
5094 if (xisr & XISR_RXXONGOT) {
5095 set_bit(ASYI_TXFLOWED, &portp->istate);
5096 portp->stats.txxoff++;
5098 if (xisr & XISR_RXXOFFGOT) {
5099 clear_bit(ASYI_TXFLOWED, &portp->istate);
5100 portp->stats.txxon++;
5104 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
5105 stl_sc26198rxbadchars(portp);
5112 /*****************************************************************************/