1 /*****************************************************************************/
4 * stallion.c -- stallion multiport serial driver.
6 * Copyright (C) 1996-1999 Stallion Technologies (support@stallion.oz.au).
7 * Copyright (C) 1994-1996 Greg Ungerer (gerg@stallion.oz.au).
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/malloc.h>
31 #include <linux/interrupt.h>
32 #include <linux/tty_flip.h>
33 #include <linux/serial.h>
34 #include <linux/cd1400.h>
35 #include <linux/sc26198.h>
36 #include <linux/comstats.h>
37 #include <linux/stallion.h>
38 #include <linux/ioport.h>
39 #include <linux/init.h>
40 #include <linux/smp_lock.h>
43 #include <asm/uaccess.h>
46 #include <linux/pci.h>
49 /*****************************************************************************/
52 * Define different board types. Use the standard Stallion "assigned"
53 * board numbers. Boards supported in this driver are abbreviated as
54 * EIO = EasyIO and ECH = EasyConnection 8/32.
60 #define BRD_ECH64PCI 27
61 #define BRD_EASYIOPCI 28
64 * Define a configuration structure to hold the board configuration.
65 * Need to set this up in the code (for now) with the boards that are
66 * to be configured into the system. This is what needs to be modified
67 * when adding/removing/modifying boards. Each line entry in the
68 * stl_brdconf[] array is a board. Each line contains io/irq/memory
69 * ranges for that board (as well as what type of board it is).
71 * { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
72 * This line would configure an EasyIO board (4 or 8, no difference),
73 * at io address 2a0 and irq 10.
75 * { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
76 * This line will configure an EasyConnection 8/32 board at primary io
77 * address 2a8, secondary io address 280 and irq 12.
78 * Enter as many lines into this array as you want (only the first 4
79 * will actually be used!). Any combination of EasyIO and EasyConnection
80 * boards can be specified. EasyConnection 8/32 boards can share their
81 * secondary io addresses between each other.
83 * NOTE: there is no need to put any entries in this table for PCI
84 * boards. They will be found automatically by the driver - provided
85 * PCI BIOS32 support is compiled into the kernel.
92 unsigned long memaddr
;
97 static stlconf_t stl_brdconf
[] = {
98 /*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
101 static int stl_nrbrds
= sizeof(stl_brdconf
) / sizeof(stlconf_t
);
103 /*****************************************************************************/
106 * Define some important driver characteristics. Device major numbers
107 * allocated as per Linux Device Registry.
109 #ifndef STL_SIOMEMMAJOR
110 #define STL_SIOMEMMAJOR 28
112 #ifndef STL_SERIALMAJOR
113 #define STL_SERIALMAJOR 24
115 #ifndef STL_CALLOUTMAJOR
116 #define STL_CALLOUTMAJOR 25
119 #define STL_DRVTYPSERIAL 1
120 #define STL_DRVTYPCALLOUT 2
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.5.1";
138 static char *stl_serialname
= "ttyE";
139 static char *stl_calloutname
= "cue";
141 static struct tty_driver stl_serial
;
142 static struct tty_driver stl_callout
;
143 static struct tty_struct
*stl_ttys
[STL_MAXDEVS
];
144 static struct termios
*stl_termios
[STL_MAXDEVS
];
145 static struct termios
*stl_termioslocked
[STL_MAXDEVS
];
146 static int stl_refcount
= 0;
149 * We will need to allocate a temporary write buffer for chars that
150 * come direct from user space. The problem is that a copy from user
151 * space might cause a page fault (typically on a system that is
152 * swapping!). All ports will share one buffer - since if the system
153 * is already swapping a shared buffer won't make things any worse.
155 static char *stl_tmpwritebuf
;
156 static struct semaphore stl_tmpwritesem
= MUTEX
;
159 * Define a local default termios struct. All ports will be created
160 * with this termios initially. Basically all it defines is a raw port
161 * at 9600, 8 data bits, 1 stop bit.
163 static struct termios stl_deftermios
= {
166 (B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
),
173 * Define global stats structures. Not used often, and can be
174 * re-used for each stats call.
176 static comstats_t stl_comstats
;
177 static combrd_t stl_brdstats
;
178 static stlbrd_t stl_dummybrd
;
179 static stlport_t stl_dummyport
;
182 * Define global place to put buffer overflow characters.
184 static char stl_unwanted
[SC26198_RXFIFOSIZE
];
187 * Keep track of what interrupts we have requested for us.
188 * We don't need to request an interrupt twice if it is being
189 * shared with another Stallion board.
191 static int stl_gotintrs
[STL_MAXBRDS
];
192 static int stl_numintrs
= 0;
194 /*****************************************************************************/
196 static stlbrd_t
*stl_brds
[STL_MAXBRDS
];
199 * Per board state flags. Used with the state field of the board struct.
200 * Not really much here!
202 #define BRD_FOUND 0x1
205 * Define the port structure istate flags. These set of flags are
206 * modified at interrupt time - so setting and reseting them needs
207 * to be atomic. Use the bit clear/setting routines for this.
209 #define ASYI_TXBUSY 1
211 #define ASYI_DCDCHANGE 3
212 #define ASYI_TXFLOWED 4
215 * Define an array of board names as printable strings. Handy for
216 * referencing boards when printing trace and stuff.
218 static char *stl_brdnames
[] = {
250 /*****************************************************************************/
254 * Define some string labels for arguments passed from the module
255 * load line. These allow for easy board definitions, and easy
256 * modification of the io, memory and irq resoucres.
259 static char *board0
[4];
260 static char *board1
[4];
261 static char *board2
[4];
262 static char *board3
[4];
264 static char **stl_brdsp
[] = {
272 * Define a set of common board names, and types. This is used to
273 * parse any module arguments.
276 typedef struct stlbrdtype
{
281 static stlbrdtype_t stl_brdstr
[] = {
282 { "easyio", BRD_EASYIO
},
283 { "eio", BRD_EASYIO
},
284 { "20", BRD_EASYIO
},
285 { "ec8/32", BRD_ECH
},
286 { "ec8/32-at", BRD_ECH
},
287 { "ec8/32-isa", BRD_ECH
},
289 { "echat", BRD_ECH
},
291 { "ec8/32-mc", BRD_ECHMC
},
292 { "ec8/32-mca", BRD_ECHMC
},
293 { "echmc", BRD_ECHMC
},
294 { "echmca", BRD_ECHMC
},
296 { "ec8/32-pc", BRD_ECHPCI
},
297 { "ec8/32-pci", BRD_ECHPCI
},
298 { "26", BRD_ECHPCI
},
299 { "ec8/64-pc", BRD_ECH64PCI
},
300 { "ec8/64-pci", BRD_ECH64PCI
},
301 { "ech-pci", BRD_ECH64PCI
},
302 { "echpci", BRD_ECH64PCI
},
303 { "echpc", BRD_ECH64PCI
},
304 { "27", BRD_ECH64PCI
},
305 { "easyio-pc", BRD_EASYIOPCI
},
306 { "easyio-pci", BRD_EASYIOPCI
},
307 { "eio-pci", BRD_EASYIOPCI
},
308 { "eiopci", BRD_EASYIOPCI
},
309 { "28", BRD_EASYIOPCI
},
313 * Define the module agruments.
315 MODULE_AUTHOR("Greg Ungerer");
316 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
318 MODULE_PARM(board0
, "1-4s");
319 MODULE_PARM_DESC(board0
, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
320 MODULE_PARM(board1
, "1-4s");
321 MODULE_PARM_DESC(board1
, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
322 MODULE_PARM(board2
, "1-4s");
323 MODULE_PARM_DESC(board2
, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
324 MODULE_PARM(board3
, "1-4s");
325 MODULE_PARM_DESC(board3
, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
329 /*****************************************************************************/
332 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
333 * to the directly accessible io ports of these boards (not the uarts -
334 * they are in cd1400.h and sc26198.h).
336 #define EIO_8PORTRS 0x04
337 #define EIO_4PORTRS 0x05
338 #define EIO_8PORTDI 0x00
339 #define EIO_8PORTM 0x06
341 #define EIO_IDBITMASK 0x07
343 #define EIO_BRDMASK 0xf0
346 #define ID_BRD16 0x30
348 #define EIO_INTRPEND 0x08
349 #define EIO_INTEDGE 0x00
350 #define EIO_INTLEVEL 0x08
354 #define ECH_IDBITMASK 0xe0
355 #define ECH_BRDENABLE 0x08
356 #define ECH_BRDDISABLE 0x00
357 #define ECH_INTENABLE 0x01
358 #define ECH_INTDISABLE 0x00
359 #define ECH_INTLEVEL 0x02
360 #define ECH_INTEDGE 0x00
361 #define ECH_INTRPEND 0x01
362 #define ECH_BRDRESET 0x01
364 #define ECHMC_INTENABLE 0x01
365 #define ECHMC_BRDRESET 0x02
367 #define ECH_PNLSTATUS 2
368 #define ECH_PNL16PORT 0x20
369 #define ECH_PNLIDMASK 0x07
370 #define ECH_PNLXPID 0x40
371 #define ECH_PNLINTRPEND 0x80
373 #define ECH_ADDR2MASK 0x1e0
376 * Define the vector mapping bits for the programmable interrupt board
377 * hardware. These bits encode the interrupt for the board to use - it
378 * is software selectable (except the EIO-8M).
380 static unsigned char stl_vecmap
[] = {
381 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
382 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
386 * Set up enable and disable macros for the ECH boards. They require
387 * the secondary io address space to be activated and deactivated.
388 * This way all ECH boards can share their secondary io region.
389 * If this is an ECH-PCI board then also need to set the page pointer
390 * to point to the correct page.
392 #define BRDENABLE(brdnr,pagenr) \
393 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
394 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
395 stl_brds[(brdnr)]->ioctrl); \
396 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
397 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
399 #define BRDDISABLE(brdnr) \
400 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
401 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
402 stl_brds[(brdnr)]->ioctrl);
404 #define STL_CD1400MAXBAUD 230400
405 #define STL_SC26198MAXBAUD 460800
407 #define STL_BAUDBASE 115200
408 #define STL_CLOSEDELAY (5 * HZ / 10)
410 /*****************************************************************************/
415 * Define the Stallion PCI vendor and device IDs.
417 #ifndef PCI_VENDOR_ID_STALLION
418 #define PCI_VENDOR_ID_STALLION 0x124d
420 #ifndef PCI_DEVICE_ID_ECHPCI832
421 #define PCI_DEVICE_ID_ECHPCI832 0x0000
423 #ifndef PCI_DEVICE_ID_ECHPCI864
424 #define PCI_DEVICE_ID_ECHPCI864 0x0002
426 #ifndef PCI_DEVICE_ID_EIOPCI
427 #define PCI_DEVICE_ID_EIOPCI 0x0003
431 * Define structure to hold all Stallion PCI boards.
433 typedef struct stlpcibrd
{
434 unsigned short vendid
;
435 unsigned short devid
;
439 static stlpcibrd_t stl_pcibrds
[] = {
440 { PCI_VENDOR_ID_STALLION
, PCI_DEVICE_ID_ECHPCI864
, BRD_ECH64PCI
},
441 { PCI_VENDOR_ID_STALLION
, PCI_DEVICE_ID_EIOPCI
, BRD_EASYIOPCI
},
442 { PCI_VENDOR_ID_STALLION
, PCI_DEVICE_ID_ECHPCI832
, BRD_ECHPCI
},
443 { PCI_VENDOR_ID_NS
, PCI_DEVICE_ID_NS_87410
, BRD_ECHPCI
},
446 static int stl_nrpcibrds
= sizeof(stl_pcibrds
) / sizeof(stlpcibrd_t
);
450 /*****************************************************************************/
453 * Define macros to extract a brd/port number from a minor number.
455 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
456 #define MINOR2PORT(min) ((min) & 0x3f)
459 * Define a baud rate table that converts termios baud rate selector
460 * into the actual baud rate value. All baud rate calculations are
461 * based on the actual baud rate required.
463 static unsigned int stl_baudrates
[] = {
464 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
465 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
469 * Define some handy local macros...
472 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
475 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
477 /*****************************************************************************/
480 * Declare all those functions in this driver!
484 int init_module(void);
485 void cleanup_module(void);
486 static void stl_argbrds(void);
487 static int stl_parsebrd(stlconf_t
*confp
, char **argp
);
489 static unsigned long stl_atol(char *str
);
493 static int stl_open(struct tty_struct
*tty
, struct file
*filp
);
494 static void stl_close(struct tty_struct
*tty
, struct file
*filp
);
495 static int stl_write(struct tty_struct
*tty
, int from_user
, const unsigned char *buf
, int count
);
496 static void stl_putchar(struct tty_struct
*tty
, unsigned char ch
);
497 static void stl_flushchars(struct tty_struct
*tty
);
498 static int stl_writeroom(struct tty_struct
*tty
);
499 static int stl_charsinbuffer(struct tty_struct
*tty
);
500 static int stl_ioctl(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
);
501 static void stl_settermios(struct tty_struct
*tty
, struct termios
*old
);
502 static void stl_throttle(struct tty_struct
*tty
);
503 static void stl_unthrottle(struct tty_struct
*tty
);
504 static void stl_stop(struct tty_struct
*tty
);
505 static void stl_start(struct tty_struct
*tty
);
506 static void stl_flushbuffer(struct tty_struct
*tty
);
507 static void stl_breakctl(struct tty_struct
*tty
, int state
);
508 static void stl_waituntilsent(struct tty_struct
*tty
, int timeout
);
509 static void stl_sendxchar(struct tty_struct
*tty
, char ch
);
510 static void stl_hangup(struct tty_struct
*tty
);
511 static int stl_memopen(struct inode
*ip
, struct file
*fp
);
512 static int stl_memclose(struct inode
*ip
, struct file
*fp
);
513 static int stl_memioctl(struct inode
*ip
, struct file
*fp
, unsigned int cmd
, unsigned long arg
);
514 static int stl_portinfo(stlport_t
*portp
, int portnr
, char *pos
);
515 static int stl_readproc(char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
);
517 static int stl_brdinit(stlbrd_t
*brdp
);
518 static int stl_initports(stlbrd_t
*brdp
, stlpanel_t
*panelp
);
519 static int stl_mapirq(int irq
, char *name
);
520 static void stl_getserial(stlport_t
*portp
, struct serial_struct
*sp
);
521 static int stl_setserial(stlport_t
*portp
, struct serial_struct
*sp
);
522 static int stl_getbrdstats(combrd_t
*bp
);
523 static int stl_getportstats(stlport_t
*portp
, comstats_t
*cp
);
524 static int stl_clrportstats(stlport_t
*portp
, comstats_t
*cp
);
525 static int stl_getportstruct(unsigned long arg
);
526 static int stl_getbrdstruct(unsigned long arg
);
527 static int stl_waitcarrier(stlport_t
*portp
, struct file
*filp
);
528 static void stl_delay(int len
);
529 static void stl_intr(int irq
, void *dev_id
, struct pt_regs
*regs
);
530 static void stl_eiointr(stlbrd_t
*brdp
);
531 static void stl_echatintr(stlbrd_t
*brdp
);
532 static void stl_echmcaintr(stlbrd_t
*brdp
);
533 static void stl_echpciintr(stlbrd_t
*brdp
);
534 static void stl_echpci64intr(stlbrd_t
*brdp
);
535 static void stl_offintr(void *private);
536 static void *stl_memalloc(int len
);
537 static stlbrd_t
*stl_allocbrd(void);
538 static stlport_t
*stl_getport(int brdnr
, int panelnr
, int portnr
);
540 static inline int stl_initbrds(void);
541 static inline int stl_initeio(stlbrd_t
*brdp
);
542 static inline int stl_initech(stlbrd_t
*brdp
);
543 static inline int stl_getbrdnr(void);
546 static inline int stl_findpcibrds(void);
547 static inline int stl_initpcibrd(int brdtype
, struct pci_dev
*devp
);
551 * CD1400 uart specific handling functions.
553 static void stl_cd1400setreg(stlport_t
*portp
, int regnr
, int value
);
554 static int stl_cd1400getreg(stlport_t
*portp
, int regnr
);
555 static int stl_cd1400updatereg(stlport_t
*portp
, int regnr
, int value
);
556 static int stl_cd1400panelinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
);
557 static void stl_cd1400portinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
);
558 static void stl_cd1400setport(stlport_t
*portp
, struct termios
*tiosp
);
559 static int stl_cd1400getsignals(stlport_t
*portp
);
560 static void stl_cd1400setsignals(stlport_t
*portp
, int dtr
, int rts
);
561 static void stl_cd1400ccrwait(stlport_t
*portp
);
562 static void stl_cd1400enablerxtx(stlport_t
*portp
, int rx
, int tx
);
563 static void stl_cd1400startrxtx(stlport_t
*portp
, int rx
, int tx
);
564 static void stl_cd1400disableintrs(stlport_t
*portp
);
565 static void stl_cd1400sendbreak(stlport_t
*portp
, int len
);
566 static void stl_cd1400flowctrl(stlport_t
*portp
, int state
);
567 static void stl_cd1400sendflow(stlport_t
*portp
, int state
);
568 static void stl_cd1400flush(stlport_t
*portp
);
569 static int stl_cd1400datastate(stlport_t
*portp
);
570 static void stl_cd1400eiointr(stlpanel_t
*panelp
, unsigned int iobase
);
571 static void stl_cd1400echintr(stlpanel_t
*panelp
, unsigned int iobase
);
572 static void stl_cd1400txisr(stlpanel_t
*panelp
, int ioaddr
);
573 static void stl_cd1400rxisr(stlpanel_t
*panelp
, int ioaddr
);
574 static void stl_cd1400mdmisr(stlpanel_t
*panelp
, int ioaddr
);
576 static inline int stl_cd1400breakisr(stlport_t
*portp
, int ioaddr
);
579 * SC26198 uart specific handling functions.
581 static void stl_sc26198setreg(stlport_t
*portp
, int regnr
, int value
);
582 static int stl_sc26198getreg(stlport_t
*portp
, int regnr
);
583 static int stl_sc26198updatereg(stlport_t
*portp
, int regnr
, int value
);
584 static int stl_sc26198getglobreg(stlport_t
*portp
, int regnr
);
585 static int stl_sc26198panelinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
);
586 static void stl_sc26198portinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
);
587 static void stl_sc26198setport(stlport_t
*portp
, struct termios
*tiosp
);
588 static int stl_sc26198getsignals(stlport_t
*portp
);
589 static void stl_sc26198setsignals(stlport_t
*portp
, int dtr
, int rts
);
590 static void stl_sc26198enablerxtx(stlport_t
*portp
, int rx
, int tx
);
591 static void stl_sc26198startrxtx(stlport_t
*portp
, int rx
, int tx
);
592 static void stl_sc26198disableintrs(stlport_t
*portp
);
593 static void stl_sc26198sendbreak(stlport_t
*portp
, int len
);
594 static void stl_sc26198flowctrl(stlport_t
*portp
, int state
);
595 static void stl_sc26198sendflow(stlport_t
*portp
, int state
);
596 static void stl_sc26198flush(stlport_t
*portp
);
597 static int stl_sc26198datastate(stlport_t
*portp
);
598 static void stl_sc26198wait(stlport_t
*portp
);
599 static void stl_sc26198txunflow(stlport_t
*portp
, struct tty_struct
*tty
);
600 static void stl_sc26198intr(stlpanel_t
*panelp
, unsigned int iobase
);
601 static void stl_sc26198txisr(stlport_t
*port
);
602 static void stl_sc26198rxisr(stlport_t
*port
, unsigned int iack
);
603 static void stl_sc26198rxbadch(stlport_t
*portp
, unsigned char status
, char ch
);
604 static void stl_sc26198rxbadchars(stlport_t
*portp
);
605 static void stl_sc26198otherisr(stlport_t
*port
, unsigned int iack
);
607 /*****************************************************************************/
610 * Generic UART support structure.
612 typedef struct uart
{
613 int (*panelinit
)(stlbrd_t
*brdp
, stlpanel_t
*panelp
);
614 void (*portinit
)(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
);
615 void (*setport
)(stlport_t
*portp
, struct termios
*tiosp
);
616 int (*getsignals
)(stlport_t
*portp
);
617 void (*setsignals
)(stlport_t
*portp
, int dtr
, int rts
);
618 void (*enablerxtx
)(stlport_t
*portp
, int rx
, int tx
);
619 void (*startrxtx
)(stlport_t
*portp
, int rx
, int tx
);
620 void (*disableintrs
)(stlport_t
*portp
);
621 void (*sendbreak
)(stlport_t
*portp
, int len
);
622 void (*flowctrl
)(stlport_t
*portp
, int state
);
623 void (*sendflow
)(stlport_t
*portp
, int state
);
624 void (*flush
)(stlport_t
*portp
);
625 int (*datastate
)(stlport_t
*portp
);
626 void (*intr
)(stlpanel_t
*panelp
, unsigned int iobase
);
630 * Define some macros to make calling these functions nice and clean.
632 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
633 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
634 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
635 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
636 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
637 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
638 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
639 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
640 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
641 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
642 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
643 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
644 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
646 /*****************************************************************************/
649 * CD1400 UART specific data initialization.
651 static uart_t stl_cd1400uart
= {
655 stl_cd1400getsignals
,
656 stl_cd1400setsignals
,
657 stl_cd1400enablerxtx
,
659 stl_cd1400disableintrs
,
669 * Define the offsets within the register bank of a cd1400 based panel.
670 * These io address offsets are common to the EasyIO board as well.
678 #define EREG_BANKSIZE 8
680 #define CD1400_CLK 25000000
681 #define CD1400_CLK8M 20000000
684 * Define the cd1400 baud rate clocks. These are used when calculating
685 * what clock and divisor to use for the required baud rate. Also
686 * define the maximum baud rate allowed, and the default base baud.
688 static int stl_cd1400clkdivs
[] = {
689 CD1400_CLK0
, CD1400_CLK1
, CD1400_CLK2
, CD1400_CLK3
, CD1400_CLK4
692 /*****************************************************************************/
695 * SC26198 UART specific data initization.
697 static uart_t stl_sc26198uart
= {
698 stl_sc26198panelinit
,
701 stl_sc26198getsignals
,
702 stl_sc26198setsignals
,
703 stl_sc26198enablerxtx
,
704 stl_sc26198startrxtx
,
705 stl_sc26198disableintrs
,
706 stl_sc26198sendbreak
,
710 stl_sc26198datastate
,
715 * Define the offsets within the register bank of a sc26198 based panel.
723 #define XP_BANKSIZE 4
726 * Define the sc26198 baud rate table. Offsets within the table
727 * represent the actual baud rate selector of sc26198 registers.
729 static unsigned int sc26198_baudtable
[] = {
730 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
731 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
732 230400, 460800, 921600
735 #define SC26198_NRBAUDS (sizeof(sc26198_baudtable) / sizeof(unsigned int))
737 /*****************************************************************************/
740 * Define the driver info for a user level control device. Used mainly
741 * to get at port stats - only not using the port device itself.
743 static struct file_operations stl_fsiomem
= {
749 stl_memioctl
, /* ioctl */
751 stl_memopen
, /* open */
753 stl_memclose
, /* release */
756 NULL
, /* check_media_change */
757 NULL
, /* revalidate */
761 /*****************************************************************************/
766 * Loadable module initialization stuff.
774 printk("init_module()\n");
780 restore_flags(flags
);
785 /*****************************************************************************/
787 void cleanup_module()
796 printk("cleanup_module()\n");
799 printk(KERN_INFO
"Unloading %s: version %s\n", stl_drvtitle
,
806 * Free up all allocated resources used by the ports. This includes
807 * memory and interrupts. As part of this process we will also do
808 * a hangup on every open port - to try to flush out any processes
809 * hanging onto ports.
811 i
= tty_unregister_driver(&stl_serial
);
812 j
= tty_unregister_driver(&stl_callout
);
814 printk("STALLION: failed to un-register tty driver, "
815 "errno=%d,%d\n", -i
, -j
);
816 restore_flags(flags
);
819 if ((i
= unregister_chrdev(STL_SIOMEMMAJOR
, "staliomem")))
820 printk("STALLION: failed to un-register serial memory device, "
823 if (stl_tmpwritebuf
!= (char *) NULL
)
824 kfree_s(stl_tmpwritebuf
, STL_TXBUFSIZE
);
826 for (i
= 0; (i
< stl_nrbrds
); i
++) {
827 if ((brdp
= stl_brds
[i
]) == (stlbrd_t
*) NULL
)
829 for (j
= 0; (j
< STL_MAXPANELS
); j
++) {
830 panelp
= brdp
->panels
[j
];
831 if (panelp
== (stlpanel_t
*) NULL
)
833 for (k
= 0; (k
< STL_PORTSPERPANEL
); k
++) {
834 portp
= panelp
->ports
[k
];
835 if (portp
== (stlport_t
*) NULL
)
837 if (portp
->tty
!= (struct tty_struct
*) NULL
)
838 stl_hangup(portp
->tty
);
839 if (portp
->tx
.buf
!= (char *) NULL
)
840 kfree_s(portp
->tx
.buf
, STL_TXBUFSIZE
);
841 kfree_s(portp
, sizeof(stlport_t
));
843 kfree_s(panelp
, sizeof(stlpanel_t
));
846 release_region(brdp
->ioaddr1
, brdp
->iosize1
);
847 if (brdp
->iosize2
> 0)
848 release_region(brdp
->ioaddr2
, brdp
->iosize2
);
850 kfree_s(brdp
, sizeof(stlbrd_t
));
851 stl_brds
[i
] = (stlbrd_t
*) NULL
;
854 for (i
= 0; (i
< stl_numintrs
); i
++)
855 free_irq(stl_gotintrs
[i
], NULL
);
857 restore_flags(flags
);
860 /*****************************************************************************/
863 * Check for any arguments passed in on the module load command line.
866 static void stl_argbrds()
873 printk("stl_argbrds()\n");
876 nrargs
= sizeof(stl_brdsp
) / sizeof(char **);
878 for (i
= stl_nrbrds
; (i
< nrargs
); i
++) {
879 memset(&conf
, 0, sizeof(conf
));
880 if (stl_parsebrd(&conf
, stl_brdsp
[i
]) == 0)
882 if ((brdp
= stl_allocbrd()) == (stlbrd_t
*) NULL
)
886 brdp
->brdtype
= conf
.brdtype
;
887 brdp
->ioaddr1
= conf
.ioaddr1
;
888 brdp
->ioaddr2
= conf
.ioaddr2
;
889 brdp
->irq
= conf
.irq
;
890 brdp
->irqtype
= conf
.irqtype
;
895 /*****************************************************************************/
898 * Convert an ascii string number into an unsigned long.
901 static unsigned long stl_atol(char *str
)
909 if ((*sp
== '0') && (*(sp
+1) == 'x')) {
912 } else if (*sp
== '0') {
919 for (; (*sp
!= 0); sp
++) {
920 c
= (*sp
> '9') ? (TOLOWER(*sp
) - 'a' + 10) : (*sp
- '0');
921 if ((c
< 0) || (c
>= base
)) {
922 printk("STALLION: invalid argument %s\n", str
);
926 val
= (val
* base
) + c
;
931 /*****************************************************************************/
934 * Parse the supplied argument string, into the board conf struct.
937 static int stl_parsebrd(stlconf_t
*confp
, char **argp
)
943 printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp
, (int) argp
);
946 if ((argp
[0] == (char *) NULL
) || (*argp
[0] == 0))
949 for (sp
= argp
[0], i
= 0; ((*sp
!= 0) && (i
< 25)); sp
++, i
++)
952 nrbrdnames
= sizeof(stl_brdstr
) / sizeof(stlbrdtype_t
);
953 for (i
= 0; (i
< nrbrdnames
); i
++) {
954 if (strcmp(stl_brdstr
[i
].name
, argp
[0]) == 0)
957 if (i
>= nrbrdnames
) {
958 printk("STALLION: unknown board name, %s?\n", argp
[0]);
962 confp
->brdtype
= stl_brdstr
[i
].type
;
965 if ((argp
[i
] != (char *) NULL
) && (*argp
[i
] != 0))
966 confp
->ioaddr1
= stl_atol(argp
[i
]);
968 if (confp
->brdtype
== BRD_ECH
) {
969 if ((argp
[i
] != (char *) NULL
) && (*argp
[i
] != 0))
970 confp
->ioaddr2
= stl_atol(argp
[i
]);
973 if ((argp
[i
] != (char *) NULL
) && (*argp
[i
] != 0))
974 confp
->irq
= stl_atol(argp
[i
]);
980 /*****************************************************************************/
983 * Local driver kernel memory allocation routine.
986 static void *stl_memalloc(int len
)
988 return((void *) kmalloc(len
, GFP_KERNEL
));
991 /*****************************************************************************/
994 * Allocate a new board structure. Fill out the basic info in it.
997 static stlbrd_t
*stl_allocbrd()
1001 brdp
= (stlbrd_t
*) stl_memalloc(sizeof(stlbrd_t
));
1002 if (brdp
== (stlbrd_t
*) NULL
) {
1003 printk("STALLION: failed to allocate memory (size=%d)\n",
1005 return((stlbrd_t
*) NULL
);
1008 memset(brdp
, 0, sizeof(stlbrd_t
));
1009 brdp
->magic
= STL_BOARDMAGIC
;
1013 /*****************************************************************************/
1015 static int stl_open(struct tty_struct
*tty
, struct file
*filp
)
1019 unsigned int minordev
;
1020 int brdnr
, panelnr
, portnr
, rc
;
1023 printk("stl_open(tty=%x,filp=%x): device=%x\n", (int) tty
,
1024 (int) filp
, tty
->device
);
1027 minordev
= MINOR(tty
->device
);
1028 brdnr
= MINOR2BRD(minordev
);
1029 if (brdnr
>= stl_nrbrds
)
1031 brdp
= stl_brds
[brdnr
];
1032 if (brdp
== (stlbrd_t
*) NULL
)
1034 minordev
= MINOR2PORT(minordev
);
1035 for (portnr
= -1, panelnr
= 0; (panelnr
< STL_MAXPANELS
); panelnr
++) {
1036 if (brdp
->panels
[panelnr
] == (stlpanel_t
*) NULL
)
1038 if (minordev
< brdp
->panels
[panelnr
]->nrports
) {
1042 minordev
-= brdp
->panels
[panelnr
]->nrports
;
1047 portp
= brdp
->panels
[panelnr
]->ports
[portnr
];
1048 if (portp
== (stlport_t
*) NULL
)
1054 * On the first open of the device setup the port hardware, and
1055 * initialize the per port data structure.
1058 tty
->driver_data
= portp
;
1061 if ((portp
->flags
& ASYNC_INITIALIZED
) == 0) {
1062 if (portp
->tx
.buf
== (char *) NULL
) {
1063 portp
->tx
.buf
= (char *) stl_memalloc(STL_TXBUFSIZE
);
1064 if (portp
->tx
.buf
== (char *) NULL
)
1066 portp
->tx
.head
= portp
->tx
.buf
;
1067 portp
->tx
.tail
= portp
->tx
.buf
;
1069 stl_setport(portp
, tty
->termios
);
1070 portp
->sigs
= stl_getsignals(portp
);
1071 stl_setsignals(portp
, 1, 1);
1072 stl_enablerxtx(portp
, 1, 1);
1073 stl_startrxtx(portp
, 1, 0);
1074 clear_bit(TTY_IO_ERROR
, &tty
->flags
);
1075 portp
->flags
|= ASYNC_INITIALIZED
;
1079 * Check if this port is in the middle of closing. If so then wait
1080 * until it is closed then return error status, based on flag settings.
1081 * The sleep here does not need interrupt protection since the wakeup
1082 * for it is done with the same context.
1084 if (portp
->flags
& ASYNC_CLOSING
) {
1085 interruptible_sleep_on(&portp
->close_wait
);
1086 if (portp
->flags
& ASYNC_HUP_NOTIFY
)
1088 return(-ERESTARTSYS
);
1092 * Based on type of open being done check if it can overlap with any
1093 * previous opens still in effect. If we are a normal serial device
1094 * then also we might have to wait for carrier.
1096 if (tty
->driver
.subtype
== STL_DRVTYPCALLOUT
) {
1097 if (portp
->flags
& ASYNC_NORMAL_ACTIVE
)
1099 if (portp
->flags
& ASYNC_CALLOUT_ACTIVE
) {
1100 if ((portp
->flags
& ASYNC_SESSION_LOCKOUT
) &&
1101 (portp
->session
!= current
->session
))
1103 if ((portp
->flags
& ASYNC_PGRP_LOCKOUT
) &&
1104 (portp
->pgrp
!= current
->pgrp
))
1107 portp
->flags
|= ASYNC_CALLOUT_ACTIVE
;
1109 if (filp
->f_flags
& O_NONBLOCK
) {
1110 if (portp
->flags
& ASYNC_CALLOUT_ACTIVE
)
1113 if ((rc
= stl_waitcarrier(portp
, filp
)) != 0)
1116 portp
->flags
|= ASYNC_NORMAL_ACTIVE
;
1119 if ((portp
->refcount
== 1) && (portp
->flags
& ASYNC_SPLIT_TERMIOS
)) {
1120 if (tty
->driver
.subtype
== STL_DRVTYPSERIAL
)
1121 *tty
->termios
= portp
->normaltermios
;
1123 *tty
->termios
= portp
->callouttermios
;
1124 stl_setport(portp
, tty
->termios
);
1127 portp
->session
= current
->session
;
1128 portp
->pgrp
= current
->pgrp
;
1132 /*****************************************************************************/
1135 * Possibly need to wait for carrier (DCD signal) to come high. Say
1136 * maybe because if we are clocal then we don't need to wait...
1139 static int stl_waitcarrier(stlport_t
*portp
, struct file
*filp
)
1141 unsigned long flags
;
1145 printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp
, (int) filp
);
1151 if (portp
->flags
& ASYNC_CALLOUT_ACTIVE
) {
1152 if (portp
->normaltermios
.c_cflag
& CLOCAL
)
1155 if (portp
->tty
->termios
->c_cflag
& CLOCAL
)
1161 portp
->openwaitcnt
++;
1162 if (! tty_hung_up_p(filp
))
1166 if ((portp
->flags
& ASYNC_CALLOUT_ACTIVE
) == 0)
1167 stl_setsignals(portp
, 1, 1);
1168 if (tty_hung_up_p(filp
) ||
1169 ((portp
->flags
& ASYNC_INITIALIZED
) == 0)) {
1170 if (portp
->flags
& ASYNC_HUP_NOTIFY
)
1176 if (((portp
->flags
& ASYNC_CALLOUT_ACTIVE
) == 0) &&
1177 ((portp
->flags
& ASYNC_CLOSING
) == 0) &&
1178 (doclocal
|| (portp
->sigs
& TIOCM_CD
))) {
1181 if (signal_pending(current
)) {
1185 interruptible_sleep_on(&portp
->open_wait
);
1188 if (! tty_hung_up_p(filp
))
1190 portp
->openwaitcnt
--;
1191 restore_flags(flags
);
1196 /*****************************************************************************/
1198 static void stl_close(struct tty_struct
*tty
, struct file
*filp
)
1201 unsigned long flags
;
1204 printk("stl_close(tty=%x,filp=%x)\n", (int) tty
, (int) filp
);
1207 portp
= tty
->driver_data
;
1208 if (portp
== (stlport_t
*) NULL
)
1213 if (tty_hung_up_p(filp
)) {
1215 restore_flags(flags
);
1218 if ((tty
->count
== 1) && (portp
->refcount
!= 1))
1219 portp
->refcount
= 1;
1220 if (portp
->refcount
-- > 1) {
1222 restore_flags(flags
);
1226 portp
->refcount
= 0;
1227 portp
->flags
|= ASYNC_CLOSING
;
1229 if (portp
->flags
& ASYNC_NORMAL_ACTIVE
)
1230 portp
->normaltermios
= *tty
->termios
;
1231 if (portp
->flags
& ASYNC_CALLOUT_ACTIVE
)
1232 portp
->callouttermios
= *tty
->termios
;
1235 * May want to wait for any data to drain before closing. The BUSY
1236 * flag keeps track of whether we are still sending or not - it is
1237 * very accurate for the cd1400, not quite so for the sc26198.
1238 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1241 if (portp
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1242 tty_wait_until_sent(tty
, portp
->closing_wait
);
1243 stl_waituntilsent(tty
, (HZ
/ 2));
1245 portp
->flags
&= ~ASYNC_INITIALIZED
;
1246 stl_disableintrs(portp
);
1247 if (tty
->termios
->c_cflag
& HUPCL
)
1248 stl_setsignals(portp
, 0, 0);
1249 stl_enablerxtx(portp
, 0, 0);
1250 stl_flushbuffer(tty
);
1252 if (portp
->tx
.buf
!= (char *) NULL
) {
1253 kfree_s(portp
->tx
.buf
, STL_TXBUFSIZE
);
1254 portp
->tx
.buf
= (char *) NULL
;
1255 portp
->tx
.head
= (char *) NULL
;
1256 portp
->tx
.tail
= (char *) NULL
;
1258 set_bit(TTY_IO_ERROR
, &tty
->flags
);
1259 if (tty
->ldisc
.flush_buffer
)
1260 (tty
->ldisc
.flush_buffer
)(tty
);
1263 portp
->tty
= (struct tty_struct
*) NULL
;
1265 if (portp
->openwaitcnt
) {
1266 if (portp
->close_delay
)
1267 stl_delay(portp
->close_delay
);
1268 wake_up_interruptible(&portp
->open_wait
);
1271 portp
->flags
&= ~(ASYNC_CALLOUT_ACTIVE
| ASYNC_NORMAL_ACTIVE
|
1273 wake_up_interruptible(&portp
->close_wait
);
1275 restore_flags(flags
);
1278 /*****************************************************************************/
1281 * Wait for a specified delay period, this is not a busy-loop. It will
1282 * give up the processor while waiting. Unfortunately this has some
1283 * rather intimate knowledge of the process management stuff.
1286 static void stl_delay(int len
)
1289 printk("stl_delay(len=%d)\n", len
);
1292 current
->state
= TASK_INTERRUPTIBLE
;
1293 schedule_timeout(len
);
1294 current
->state
= TASK_RUNNING
;
1298 /*****************************************************************************/
1301 * Write routine. Take data and stuff it in to the TX ring queue.
1302 * If transmit interrupts are not running then start them.
1305 static int stl_write(struct tty_struct
*tty
, int from_user
, const unsigned char *buf
, int count
)
1308 unsigned int len
, stlen
;
1309 unsigned char *chbuf
;
1313 printk("stl_write(tty=%x,from_user=%d,buf=%x,count=%d)\n",
1314 (int) tty
, from_user
, (int) buf
, count
);
1317 if ((tty
== (struct tty_struct
*) NULL
) ||
1318 (stl_tmpwritebuf
== (char *) NULL
))
1320 portp
= tty
->driver_data
;
1321 if (portp
== (stlport_t
*) NULL
)
1323 if (portp
->tx
.buf
== (char *) NULL
)
1327 * If copying direct from user space we must cater for page faults,
1328 * causing us to "sleep" here for a while. To handle this copy in all
1329 * the data we need now, into a local buffer. Then when we got it all
1330 * copy it into the TX buffer.
1332 chbuf
= (unsigned char *) buf
;
1334 head
= portp
->tx
.head
;
1335 tail
= portp
->tx
.tail
;
1336 len
= (head
>= tail
) ? (STL_TXBUFSIZE
- (head
- tail
) - 1) :
1338 count
= MIN(len
, count
);
1340 down(&stl_tmpwritesem
);
1341 copy_from_user(stl_tmpwritebuf
, chbuf
, count
);
1342 chbuf
= &stl_tmpwritebuf
[0];
1345 head
= portp
->tx
.head
;
1346 tail
= portp
->tx
.tail
;
1348 len
= STL_TXBUFSIZE
- (head
- tail
) - 1;
1349 stlen
= STL_TXBUFSIZE
- (head
- portp
->tx
.buf
);
1351 len
= tail
- head
- 1;
1355 len
= MIN(len
, count
);
1358 stlen
= MIN(len
, stlen
);
1359 memcpy(head
, chbuf
, stlen
);
1364 if (head
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
)) {
1365 head
= portp
->tx
.buf
;
1366 stlen
= tail
- head
;
1369 portp
->tx
.head
= head
;
1371 clear_bit(ASYI_TXLOW
, &portp
->istate
);
1372 stl_startrxtx(portp
, -1, 1);
1375 up(&stl_tmpwritesem
);
1380 /*****************************************************************************/
1382 static void stl_putchar(struct tty_struct
*tty
, unsigned char ch
)
1389 printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty
, (int) ch
);
1392 if (tty
== (struct tty_struct
*) NULL
)
1394 portp
= tty
->driver_data
;
1395 if (portp
== (stlport_t
*) NULL
)
1397 if (portp
->tx
.buf
== (char *) NULL
)
1400 head
= portp
->tx
.head
;
1401 tail
= portp
->tx
.tail
;
1403 len
= (head
>= tail
) ? (STL_TXBUFSIZE
- (head
- tail
)) : (tail
- head
);
1408 if (head
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
))
1409 head
= portp
->tx
.buf
;
1411 portp
->tx
.head
= head
;
1414 /*****************************************************************************/
1417 * If there are any characters in the buffer then make sure that TX
1418 * interrupts are on and get'em out. Normally used after the putchar
1419 * routine has been called.
1422 static void stl_flushchars(struct tty_struct
*tty
)
1427 printk("stl_flushchars(tty=%x)\n", (int) tty
);
1430 if (tty
== (struct tty_struct
*) NULL
)
1432 portp
= tty
->driver_data
;
1433 if (portp
== (stlport_t
*) NULL
)
1435 if (portp
->tx
.buf
== (char *) NULL
)
1439 if (tty
->stopped
|| tty
->hw_stopped
||
1440 (portp
->tx
.head
== portp
->tx
.tail
))
1443 stl_startrxtx(portp
, -1, 1);
1446 /*****************************************************************************/
1448 static int stl_writeroom(struct tty_struct
*tty
)
1454 printk("stl_writeroom(tty=%x)\n", (int) tty
);
1457 if (tty
== (struct tty_struct
*) NULL
)
1459 portp
= tty
->driver_data
;
1460 if (portp
== (stlport_t
*) NULL
)
1462 if (portp
->tx
.buf
== (char *) NULL
)
1465 head
= portp
->tx
.head
;
1466 tail
= portp
->tx
.tail
;
1467 return((head
>= tail
) ? (STL_TXBUFSIZE
- (head
- tail
) - 1) : (tail
- head
- 1));
1470 /*****************************************************************************/
1473 * Return number of chars in the TX buffer. Normally we would just
1474 * calculate the number of chars in the buffer and return that, but if
1475 * the buffer is empty and TX interrupts are still on then we return
1476 * that the buffer still has 1 char in it. This way whoever called us
1477 * will not think that ALL chars have drained - since the UART still
1478 * must have some chars in it (we are busy after all).
1481 static int stl_charsinbuffer(struct tty_struct
*tty
)
1488 printk("stl_charsinbuffer(tty=%x)\n", (int) tty
);
1491 if (tty
== (struct tty_struct
*) NULL
)
1493 portp
= tty
->driver_data
;
1494 if (portp
== (stlport_t
*) NULL
)
1496 if (portp
->tx
.buf
== (char *) NULL
)
1499 head
= portp
->tx
.head
;
1500 tail
= portp
->tx
.tail
;
1501 size
= (head
>= tail
) ? (head
- tail
) : (STL_TXBUFSIZE
- (tail
- head
));
1502 if ((size
== 0) && test_bit(ASYI_TXBUSY
, &portp
->istate
))
1507 /*****************************************************************************/
1510 * Generate the serial struct info.
1513 static void stl_getserial(stlport_t
*portp
, struct serial_struct
*sp
)
1515 struct serial_struct sio
;
1519 printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp
, (int) sp
);
1522 memset(&sio
, 0, sizeof(struct serial_struct
));
1523 sio
.line
= portp
->portnr
;
1524 sio
.port
= portp
->ioaddr
;
1525 sio
.flags
= portp
->flags
;
1526 sio
.baud_base
= portp
->baud_base
;
1527 sio
.close_delay
= portp
->close_delay
;
1528 sio
.closing_wait
= portp
->closing_wait
;
1529 sio
.custom_divisor
= portp
->custom_divisor
;
1531 if (portp
->uartp
== &stl_cd1400uart
) {
1532 sio
.type
= PORT_CIRRUS
;
1533 sio
.xmit_fifo_size
= CD1400_TXFIFOSIZE
;
1535 sio
.type
= PORT_UNKNOWN
;
1536 sio
.xmit_fifo_size
= SC26198_TXFIFOSIZE
;
1539 brdp
= stl_brds
[portp
->brdnr
];
1540 if (brdp
!= (stlbrd_t
*) NULL
)
1541 sio
.irq
= brdp
->irq
;
1543 copy_to_user(sp
, &sio
, sizeof(struct serial_struct
));
1546 /*****************************************************************************/
1549 * Set port according to the serial struct info.
1550 * At this point we do not do any auto-configure stuff, so we will
1551 * just quietly ignore any requests to change irq, etc.
1554 static int stl_setserial(stlport_t
*portp
, struct serial_struct
*sp
)
1556 struct serial_struct sio
;
1559 printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp
, (int) sp
);
1562 copy_from_user(&sio
, sp
, sizeof(struct serial_struct
));
1563 if (!capable(CAP_SYS_ADMIN
)) {
1564 if ((sio
.baud_base
!= portp
->baud_base
) ||
1565 (sio
.close_delay
!= portp
->close_delay
) ||
1566 ((sio
.flags
& ~ASYNC_USR_MASK
) !=
1567 (portp
->flags
& ~ASYNC_USR_MASK
)))
1571 portp
->flags
= (portp
->flags
& ~ASYNC_USR_MASK
) |
1572 (sio
.flags
& ASYNC_USR_MASK
);
1573 portp
->baud_base
= sio
.baud_base
;
1574 portp
->close_delay
= sio
.close_delay
;
1575 portp
->closing_wait
= sio
.closing_wait
;
1576 portp
->custom_divisor
= sio
.custom_divisor
;
1577 stl_setport(portp
, portp
->tty
->termios
);
1581 /*****************************************************************************/
1583 static int stl_ioctl(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
1590 printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
1591 (int) tty
, (int) file
, cmd
, (int) arg
);
1594 if (tty
== (struct tty_struct
*) NULL
)
1596 portp
= tty
->driver_data
;
1597 if (portp
== (stlport_t
*) NULL
)
1600 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1601 (cmd
!= COM_GETPORTSTATS
) && (cmd
!= COM_CLRPORTSTATS
)) {
1602 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1610 rc
= put_user(((tty
->termios
->c_cflag
& CLOCAL
) ? 1 : 0),
1611 (unsigned int *) arg
);
1614 if ((rc
= verify_area(VERIFY_READ
, (void *) arg
,
1615 sizeof(int))) == 0) {
1616 get_user(ival
, (unsigned int *) arg
);
1617 tty
->termios
->c_cflag
=
1618 (tty
->termios
->c_cflag
& ~CLOCAL
) |
1619 (ival
? CLOCAL
: 0);
1623 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
1624 sizeof(unsigned int))) == 0) {
1625 ival
= stl_getsignals(portp
);
1626 put_user(ival
, (unsigned int *) arg
);
1630 if ((rc
= verify_area(VERIFY_READ
, (void *) arg
,
1631 sizeof(unsigned int))) == 0) {
1632 get_user(ival
, (unsigned int *) arg
);
1633 stl_setsignals(portp
, ((ival
& TIOCM_DTR
) ? 1 : -1),
1634 ((ival
& TIOCM_RTS
) ? 1 : -1));
1638 if ((rc
= verify_area(VERIFY_READ
, (void *) arg
,
1639 sizeof(unsigned int))) == 0) {
1640 get_user(ival
, (unsigned int *) arg
);
1641 stl_setsignals(portp
, ((ival
& TIOCM_DTR
) ? 0 : -1),
1642 ((ival
& TIOCM_RTS
) ? 0 : -1));
1646 if ((rc
= verify_area(VERIFY_READ
, (void *) arg
,
1647 sizeof(unsigned int))) == 0) {
1648 get_user(ival
, (unsigned int *) arg
);
1649 stl_setsignals(portp
, ((ival
& TIOCM_DTR
) ? 1 : 0),
1650 ((ival
& TIOCM_RTS
) ? 1 : 0));
1654 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
1655 sizeof(struct serial_struct
))) == 0)
1656 stl_getserial(portp
, (struct serial_struct
*) arg
);
1659 if ((rc
= verify_area(VERIFY_READ
, (void *) arg
,
1660 sizeof(struct serial_struct
))) == 0)
1661 rc
= stl_setserial(portp
, (struct serial_struct
*) arg
);
1663 case COM_GETPORTSTATS
:
1664 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
1665 sizeof(comstats_t
))) == 0)
1666 rc
= stl_getportstats(portp
, (comstats_t
*) arg
);
1668 case COM_CLRPORTSTATS
:
1669 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
1670 sizeof(comstats_t
))) == 0)
1671 rc
= stl_clrportstats(portp
, (comstats_t
*) arg
);
1677 case TIOCSERGSTRUCT
:
1678 case TIOCSERGETMULTI
:
1679 case TIOCSERSETMULTI
:
1688 /*****************************************************************************/
1690 static void stl_settermios(struct tty_struct
*tty
, struct termios
*old
)
1693 struct termios
*tiosp
;
1696 printk("stl_settermios(tty=%x,old=%x)\n", (int) tty
, (int) old
);
1699 if (tty
== (struct tty_struct
*) NULL
)
1701 portp
= tty
->driver_data
;
1702 if (portp
== (stlport_t
*) NULL
)
1705 tiosp
= tty
->termios
;
1706 if ((tiosp
->c_cflag
== old
->c_cflag
) &&
1707 (tiosp
->c_iflag
== old
->c_iflag
))
1710 stl_setport(portp
, tiosp
);
1711 stl_setsignals(portp
, ((tiosp
->c_cflag
& (CBAUD
& ~CBAUDEX
)) ? 1 : 0),
1713 if ((old
->c_cflag
& CRTSCTS
) && ((tiosp
->c_cflag
& CRTSCTS
) == 0)) {
1714 tty
->hw_stopped
= 0;
1717 if (((old
->c_cflag
& CLOCAL
) == 0) && (tiosp
->c_cflag
& CLOCAL
))
1718 wake_up_interruptible(&portp
->open_wait
);
1721 /*****************************************************************************/
1724 * Attempt to flow control who ever is sending us data. Based on termios
1725 * settings use software or/and hardware flow control.
1728 static void stl_throttle(struct tty_struct
*tty
)
1733 printk("stl_throttle(tty=%x)\n", (int) tty
);
1736 if (tty
== (struct tty_struct
*) NULL
)
1738 portp
= tty
->driver_data
;
1739 if (portp
== (stlport_t
*) NULL
)
1741 stl_flowctrl(portp
, 0);
1744 /*****************************************************************************/
1747 * Unflow control the device sending us data...
1750 static void stl_unthrottle(struct tty_struct
*tty
)
1755 printk("stl_unthrottle(tty=%x)\n", (int) tty
);
1758 if (tty
== (struct tty_struct
*) NULL
)
1760 portp
= tty
->driver_data
;
1761 if (portp
== (stlport_t
*) NULL
)
1763 stl_flowctrl(portp
, 1);
1766 /*****************************************************************************/
1769 * Stop the transmitter. Basically to do this we will just turn TX
1773 static void stl_stop(struct tty_struct
*tty
)
1778 printk("stl_stop(tty=%x)\n", (int) tty
);
1781 if (tty
== (struct tty_struct
*) NULL
)
1783 portp
= tty
->driver_data
;
1784 if (portp
== (stlport_t
*) NULL
)
1786 stl_startrxtx(portp
, -1, 0);
1789 /*****************************************************************************/
1792 * Start the transmitter again. Just turn TX interrupts back on.
1795 static void stl_start(struct tty_struct
*tty
)
1800 printk("stl_start(tty=%x)\n", (int) tty
);
1803 if (tty
== (struct tty_struct
*) NULL
)
1805 portp
= tty
->driver_data
;
1806 if (portp
== (stlport_t
*) NULL
)
1808 stl_startrxtx(portp
, -1, 1);
1811 /*****************************************************************************/
1814 * Hangup this port. This is pretty much like closing the port, only
1815 * a little more brutal. No waiting for data to drain. Shutdown the
1816 * port and maybe drop signals.
1819 static void stl_hangup(struct tty_struct
*tty
)
1824 printk("stl_hangup(tty=%x)\n", (int) tty
);
1827 if (tty
== (struct tty_struct
*) NULL
)
1829 portp
= tty
->driver_data
;
1830 if (portp
== (stlport_t
*) NULL
)
1833 portp
->flags
&= ~ASYNC_INITIALIZED
;
1834 stl_disableintrs(portp
);
1835 if (tty
->termios
->c_cflag
& HUPCL
)
1836 stl_setsignals(portp
, 0, 0);
1837 stl_enablerxtx(portp
, 0, 0);
1838 stl_flushbuffer(tty
);
1840 set_bit(TTY_IO_ERROR
, &tty
->flags
);
1841 if (portp
->tx
.buf
!= (char *) NULL
) {
1842 kfree_s(portp
->tx
.buf
, STL_TXBUFSIZE
);
1843 portp
->tx
.buf
= (char *) NULL
;
1844 portp
->tx
.head
= (char *) NULL
;
1845 portp
->tx
.tail
= (char *) NULL
;
1847 portp
->tty
= (struct tty_struct
*) NULL
;
1848 portp
->flags
&= ~(ASYNC_NORMAL_ACTIVE
| ASYNC_CALLOUT_ACTIVE
);
1849 portp
->refcount
= 0;
1850 wake_up_interruptible(&portp
->open_wait
);
1853 /*****************************************************************************/
1855 static void stl_flushbuffer(struct tty_struct
*tty
)
1860 printk("stl_flushbuffer(tty=%x)\n", (int) tty
);
1863 if (tty
== (struct tty_struct
*) NULL
)
1865 portp
= tty
->driver_data
;
1866 if (portp
== (stlport_t
*) NULL
)
1870 wake_up_interruptible(&tty
->write_wait
);
1871 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
1872 tty
->ldisc
.write_wakeup
)
1873 (tty
->ldisc
.write_wakeup
)(tty
);
1876 /*****************************************************************************/
1878 static void stl_breakctl(struct tty_struct
*tty
, int state
)
1883 printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty
, state
);
1886 if (tty
== (struct tty_struct
*) NULL
)
1888 portp
= tty
->driver_data
;
1889 if (portp
== (stlport_t
*) NULL
)
1892 stl_sendbreak(portp
, ((state
== -1) ? 1 : 2));
1895 /*****************************************************************************/
1897 static void stl_waituntilsent(struct tty_struct
*tty
, int timeout
)
1903 printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty
, timeout
);
1906 if (tty
== (struct tty_struct
*) NULL
)
1908 portp
= tty
->driver_data
;
1909 if (portp
== (stlport_t
*) NULL
)
1914 tend
= jiffies
+ timeout
;
1916 while (stl_datastate(portp
)) {
1917 if (signal_pending(current
))
1920 if (time_after_eq(jiffies
, tend
))
1925 /*****************************************************************************/
1927 static void stl_sendxchar(struct tty_struct
*tty
, char ch
)
1932 printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty
, ch
);
1935 if (tty
== (struct tty_struct
*) NULL
)
1937 portp
= tty
->driver_data
;
1938 if (portp
== (stlport_t
*) NULL
)
1941 if (ch
== STOP_CHAR(tty
))
1942 stl_sendflow(portp
, 0);
1943 else if (ch
== START_CHAR(tty
))
1944 stl_sendflow(portp
, 1);
1946 stl_putchar(tty
, ch
);
1949 /*****************************************************************************/
1954 * Format info for a specified port. The line is deliberately limited
1955 * to 80 characters. (If it is too long it will be truncated, if too
1956 * short then padded with spaces).
1959 static int stl_portinfo(stlport_t
*portp
, int portnr
, char *pos
)
1965 sp
+= sprintf(sp
, "%d: uart:%s tx:%d rx:%d",
1966 portnr
, (portp
->hwid
== 1) ? "SC26198" : "CD1400",
1967 (int) portp
->stats
.txtotal
, (int) portp
->stats
.rxtotal
);
1969 if (portp
->stats
.rxframing
)
1970 sp
+= sprintf(sp
, " fe:%d", (int) portp
->stats
.rxframing
);
1971 if (portp
->stats
.rxparity
)
1972 sp
+= sprintf(sp
, " pe:%d", (int) portp
->stats
.rxparity
);
1973 if (portp
->stats
.rxbreaks
)
1974 sp
+= sprintf(sp
, " brk:%d", (int) portp
->stats
.rxbreaks
);
1975 if (portp
->stats
.rxoverrun
)
1976 sp
+= sprintf(sp
, " oe:%d", (int) portp
->stats
.rxoverrun
);
1978 sigs
= stl_getsignals(portp
);
1979 cnt
= sprintf(sp
, "%s%s%s%s%s ",
1980 (sigs
& TIOCM_RTS
) ? "|RTS" : "",
1981 (sigs
& TIOCM_CTS
) ? "|CTS" : "",
1982 (sigs
& TIOCM_DTR
) ? "|DTR" : "",
1983 (sigs
& TIOCM_CD
) ? "|DCD" : "",
1984 (sigs
& TIOCM_DSR
) ? "|DSR" : "");
1988 for (cnt
= (sp
- pos
); (cnt
< (MAXLINE
- 1)); cnt
++)
1991 pos
[(MAXLINE
- 2)] = '+';
1992 pos
[(MAXLINE
- 1)] = '\n';
1997 /*****************************************************************************/
2000 * Port info, read from the /proc file system.
2003 static int stl_readproc(char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
2008 int brdnr
, panelnr
, portnr
, totalport
;
2013 printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
2014 "data=%x\n", (int) page
, (int) start
, (int) off
, count
,
2015 (int) eof
, (int) data
);
2023 pos
+= sprintf(pos
, "%s: version %s", stl_drvtitle
,
2025 while (pos
< (page
+ MAXLINE
- 1))
2032 * We scan through for each board, panel and port. The offset is
2033 * calculated on the fly, and irrelevant ports are skipped.
2035 for (brdnr
= 0; (brdnr
< stl_nrbrds
); brdnr
++) {
2036 brdp
= stl_brds
[brdnr
];
2037 if (brdp
== (stlbrd_t
*) NULL
)
2039 if (brdp
->state
== 0)
2042 maxoff
= curoff
+ (brdp
->nrports
* MAXLINE
);
2043 if (off
>= maxoff
) {
2048 totalport
= brdnr
* STL_MAXPORTS
;
2049 for (panelnr
= 0; (panelnr
< brdp
->nrpanels
); panelnr
++) {
2050 panelp
= brdp
->panels
[panelnr
];
2051 if (panelp
== (stlpanel_t
*) NULL
)
2054 maxoff
= curoff
+ (panelp
->nrports
* MAXLINE
);
2055 if (off
>= maxoff
) {
2057 totalport
+= panelp
->nrports
;
2061 for (portnr
= 0; (portnr
< panelp
->nrports
); portnr
++,
2063 portp
= panelp
->ports
[portnr
];
2064 if (portp
== (stlport_t
*) NULL
)
2066 if (off
>= (curoff
+= MAXLINE
))
2068 if ((pos
- page
+ MAXLINE
) > count
)
2070 pos
+= stl_portinfo(portp
, totalport
, pos
);
2082 /*****************************************************************************/
2085 * All board interrupts are vectored through here first. This code then
2086 * calls off to the approrpriate board interrupt handlers.
2089 static void stl_intr(int irq
, void *dev_id
, struct pt_regs
*regs
)
2095 printk("stl_intr(irq=%d,regs=%x)\n", irq
, (int) regs
);
2098 for (i
= 0; (i
< stl_nrbrds
); i
++) {
2099 if ((brdp
= stl_brds
[i
]) == (stlbrd_t
*) NULL
)
2101 if (brdp
->state
== 0)
2103 (* brdp
->isr
)(brdp
);
2107 /*****************************************************************************/
2110 * Interrupt service routine for EasyIO board types.
2113 static void stl_eiointr(stlbrd_t
*brdp
)
2116 unsigned int iobase
;
2118 panelp
= brdp
->panels
[0];
2119 iobase
= panelp
->iobase
;
2120 while (inb(brdp
->iostatus
) & EIO_INTRPEND
)
2121 (* panelp
->isr
)(panelp
, iobase
);
2124 /*****************************************************************************/
2127 * Interrupt service routine for ECH-AT board types.
2130 static void stl_echatintr(stlbrd_t
*brdp
)
2133 unsigned int ioaddr
;
2136 outb((brdp
->ioctrlval
| ECH_BRDENABLE
), brdp
->ioctrl
);
2138 while (inb(brdp
->iostatus
) & ECH_INTRPEND
) {
2139 for (bnknr
= 0; (bnknr
< brdp
->nrbnks
); bnknr
++) {
2140 ioaddr
= brdp
->bnkstataddr
[bnknr
];
2141 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
2142 panelp
= brdp
->bnk2panel
[bnknr
];
2143 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
2148 outb((brdp
->ioctrlval
| ECH_BRDDISABLE
), brdp
->ioctrl
);
2151 /*****************************************************************************/
2154 * Interrupt service routine for ECH-MCA board types.
2157 static void stl_echmcaintr(stlbrd_t
*brdp
)
2160 unsigned int ioaddr
;
2163 while (inb(brdp
->iostatus
) & ECH_INTRPEND
) {
2164 for (bnknr
= 0; (bnknr
< brdp
->nrbnks
); bnknr
++) {
2165 ioaddr
= brdp
->bnkstataddr
[bnknr
];
2166 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
2167 panelp
= brdp
->bnk2panel
[bnknr
];
2168 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
2174 /*****************************************************************************/
2177 * Interrupt service routine for ECH-PCI board types.
2180 static void stl_echpciintr(stlbrd_t
*brdp
)
2183 unsigned int ioaddr
;
2188 for (bnknr
= 0; (bnknr
< brdp
->nrbnks
); bnknr
++) {
2189 outb(brdp
->bnkpageaddr
[bnknr
], brdp
->ioctrl
);
2190 ioaddr
= brdp
->bnkstataddr
[bnknr
];
2191 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
2192 panelp
= brdp
->bnk2panel
[bnknr
];
2193 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
2202 /*****************************************************************************/
2205 * Interrupt service routine for ECH-8/64-PCI board types.
2208 static void stl_echpci64intr(stlbrd_t
*brdp
)
2211 unsigned int ioaddr
;
2214 while (inb(brdp
->ioctrl
) & 0x1) {
2215 for (bnknr
= 0; (bnknr
< brdp
->nrbnks
); bnknr
++) {
2216 ioaddr
= brdp
->bnkstataddr
[bnknr
];
2217 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
2218 panelp
= brdp
->bnk2panel
[bnknr
];
2219 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
2225 /*****************************************************************************/
2228 * Service an off-level request for some channel.
2230 static void stl_offintr(void *private)
2233 struct tty_struct
*tty
;
2234 unsigned int oldsigs
;
2239 printk("stl_offintr(portp=%x)\n", (int) portp
);
2242 if (portp
== (stlport_t
*) NULL
)
2246 if (tty
== (struct tty_struct
*) NULL
)
2250 if (test_bit(ASYI_TXLOW
, &portp
->istate
)) {
2251 if ((tty
->flags
& (1 << TTY_DO_WRITE_WAKEUP
)) &&
2252 tty
->ldisc
.write_wakeup
)
2253 (tty
->ldisc
.write_wakeup
)(tty
);
2254 wake_up_interruptible(&tty
->write_wait
);
2256 if (test_bit(ASYI_DCDCHANGE
, &portp
->istate
)) {
2257 clear_bit(ASYI_DCDCHANGE
, &portp
->istate
);
2258 oldsigs
= portp
->sigs
;
2259 portp
->sigs
= stl_getsignals(portp
);
2260 if ((portp
->sigs
& TIOCM_CD
) && ((oldsigs
& TIOCM_CD
) == 0))
2261 wake_up_interruptible(&portp
->open_wait
);
2262 if ((oldsigs
& TIOCM_CD
) && ((portp
->sigs
& TIOCM_CD
) == 0)) {
2263 if (portp
->flags
& ASYNC_CHECK_CD
) {
2264 if (! ((portp
->flags
& ASYNC_CALLOUT_ACTIVE
) &&
2265 (portp
->flags
& ASYNC_CALLOUT_NOHUP
))) {
2274 /*****************************************************************************/
2277 * Map in interrupt vector to this driver. Check that we don't
2278 * already have this vector mapped, we might be sharing this
2279 * interrupt across multiple boards.
2282 __initfunc(static int stl_mapirq(int irq
, char *name
))
2287 printk("stl_mapirq(irq=%d,name=%s)\n", irq
, name
);
2291 for (i
= 0; (i
< stl_numintrs
); i
++) {
2292 if (stl_gotintrs
[i
] == irq
)
2295 if (i
>= stl_numintrs
) {
2296 if (request_irq(irq
, stl_intr
, SA_INTERRUPT
, name
, NULL
) != 0) {
2297 printk("STALLION: failed to register interrupt "
2298 "routine for %s irq=%d\n", name
, irq
);
2301 stl_gotintrs
[stl_numintrs
++] = irq
;
2307 /*****************************************************************************/
2310 * Initialize all the ports on a panel.
2313 __initfunc(static int stl_initports(stlbrd_t
*brdp
, stlpanel_t
*panelp
))
2319 printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp
, (int) panelp
);
2322 chipmask
= stl_panelinit(brdp
, panelp
);
2325 * All UART's are initialized (if found!). Now go through and setup
2326 * each ports data structures.
2328 for (i
= 0; (i
< panelp
->nrports
); i
++) {
2329 portp
= (stlport_t
*) stl_memalloc(sizeof(stlport_t
));
2330 if (portp
== (stlport_t
*) NULL
) {
2331 printk("STALLION: failed to allocate memory "
2332 "(size=%d)\n", sizeof(stlport_t
));
2335 memset(portp
, 0, sizeof(stlport_t
));
2337 portp
->magic
= STL_PORTMAGIC
;
2339 portp
->brdnr
= panelp
->brdnr
;
2340 portp
->panelnr
= panelp
->panelnr
;
2341 portp
->uartp
= panelp
->uartp
;
2342 portp
->clk
= brdp
->clk
;
2343 portp
->baud_base
= STL_BAUDBASE
;
2344 portp
->close_delay
= STL_CLOSEDELAY
;
2345 portp
->closing_wait
= 30 * HZ
;
2346 portp
->normaltermios
= stl_deftermios
;
2347 portp
->callouttermios
= stl_deftermios
;
2348 portp
->tqueue
.routine
= stl_offintr
;
2349 portp
->tqueue
.data
= portp
;
2350 portp
->stats
.brd
= portp
->brdnr
;
2351 portp
->stats
.panel
= portp
->panelnr
;
2352 portp
->stats
.port
= portp
->portnr
;
2353 panelp
->ports
[i
] = portp
;
2354 stl_portinit(brdp
, panelp
, portp
);
2360 /*****************************************************************************/
2363 * Try to find and initialize an EasyIO board.
2366 static inline int stl_initeio(stlbrd_t
*brdp
)
2369 unsigned int status
;
2374 printk("stl_initeio(brdp=%x)\n", (int) brdp
);
2377 brdp
->ioctrl
= brdp
->ioaddr1
+ 1;
2378 brdp
->iostatus
= brdp
->ioaddr1
+ 2;
2380 status
= inb(brdp
->iostatus
);
2381 if ((status
& EIO_IDBITMASK
) == EIO_MK3
)
2385 * Handle board specific stuff now. The real difference is PCI
2388 if (brdp
->brdtype
== BRD_EASYIOPCI
) {
2389 brdp
->iosize1
= 0x80;
2390 brdp
->iosize2
= 0x80;
2391 name
= "serial(EIO-PCI)";
2392 outb(0x41, (brdp
->ioaddr2
+ 0x4c));
2395 name
= "serial(EIO)";
2396 if ((brdp
->irq
< 0) || (brdp
->irq
> 15) ||
2397 (stl_vecmap
[brdp
->irq
] == (unsigned char) 0xff)) {
2398 printk("STALLION: invalid irq=%d for brd=%d\n",
2399 brdp
->irq
, brdp
->brdnr
);
2402 outb((stl_vecmap
[brdp
->irq
] | EIO_0WS
|
2403 ((brdp
->irqtype
) ? EIO_INTLEVEL
: EIO_INTEDGE
)),
2407 if (check_region(brdp
->ioaddr1
, brdp
->iosize1
)) {
2408 printk("STALLION: Warning, board %d I/O address %x conflicts "
2409 "with another device\n", brdp
->brdnr
, brdp
->ioaddr1
);
2411 if (brdp
->iosize2
> 0) {
2412 if (check_region(brdp
->ioaddr2
, brdp
->iosize2
)) {
2413 printk("STALLION: Warning, board %d I/O address %x "
2414 "conflicts with another device\n",
2415 brdp
->brdnr
, brdp
->ioaddr2
);
2420 * Everything looks OK, so let's go ahead and probe for the hardware.
2422 brdp
->clk
= CD1400_CLK
;
2423 brdp
->isr
= stl_eiointr
;
2425 switch (status
& EIO_IDBITMASK
) {
2427 brdp
->clk
= CD1400_CLK8M
;
2437 switch (status
& EIO_BRDMASK
) {
2456 * We have verfied that the board is actually present, so now we
2457 * can complete the setup.
2459 request_region(brdp
->ioaddr1
, brdp
->iosize1
, name
);
2460 if (brdp
->iosize2
> 0)
2461 request_region(brdp
->ioaddr2
, brdp
->iosize2
, name
);
2463 panelp
= (stlpanel_t
*) stl_memalloc(sizeof(stlpanel_t
));
2464 if (panelp
== (stlpanel_t
*) NULL
) {
2465 printk("STALLION: failed to allocate memory (size=%d)\n",
2466 sizeof(stlpanel_t
));
2469 memset(panelp
, 0, sizeof(stlpanel_t
));
2471 panelp
->magic
= STL_PANELMAGIC
;
2472 panelp
->brdnr
= brdp
->brdnr
;
2473 panelp
->panelnr
= 0;
2474 panelp
->nrports
= brdp
->nrports
;
2475 panelp
->iobase
= brdp
->ioaddr1
;
2476 panelp
->hwid
= status
;
2477 if ((status
& EIO_IDBITMASK
) == EIO_MK3
) {
2478 panelp
->uartp
= (void *) &stl_sc26198uart
;
2479 panelp
->isr
= stl_sc26198intr
;
2481 panelp
->uartp
= (void *) &stl_cd1400uart
;
2482 panelp
->isr
= stl_cd1400eiointr
;
2485 brdp
->panels
[0] = panelp
;
2487 brdp
->state
|= BRD_FOUND
;
2488 brdp
->hwid
= status
;
2489 rc
= stl_mapirq(brdp
->irq
, name
);
2493 /*****************************************************************************/
2496 * Try to find an ECH board and initialize it. This code is capable of
2497 * dealing with all types of ECH board.
2500 static int inline stl_initech(stlbrd_t
*brdp
)
2503 unsigned int status
, nxtid
, ioaddr
, conflict
;
2504 int panelnr
, banknr
, i
;
2508 printk("stl_initech(brdp=%x)\n", (int) brdp
);
2515 * Set up the initial board register contents for boards. This varies a
2516 * bit between the different board types. So we need to handle each
2517 * separately. Also do a check that the supplied IRQ is good.
2519 switch (brdp
->brdtype
) {
2522 brdp
->isr
= stl_echatintr
;
2523 brdp
->ioctrl
= brdp
->ioaddr1
+ 1;
2524 brdp
->iostatus
= brdp
->ioaddr1
+ 1;
2525 status
= inb(brdp
->iostatus
);
2526 if ((status
& ECH_IDBITMASK
) != ECH_ID
)
2528 if ((brdp
->irq
< 0) || (brdp
->irq
> 15) ||
2529 (stl_vecmap
[brdp
->irq
] == (unsigned char) 0xff)) {
2530 printk("STALLION: invalid irq=%d for brd=%d\n",
2531 brdp
->irq
, brdp
->brdnr
);
2534 status
= ((brdp
->ioaddr2
& ECH_ADDR2MASK
) >> 1);
2535 status
|= (stl_vecmap
[brdp
->irq
] << 1);
2536 outb((status
| ECH_BRDRESET
), brdp
->ioaddr1
);
2537 brdp
->ioctrlval
= ECH_INTENABLE
|
2538 ((brdp
->irqtype
) ? ECH_INTLEVEL
: ECH_INTEDGE
);
2539 for (i
= 0; (i
< 10); i
++)
2540 outb((brdp
->ioctrlval
| ECH_BRDENABLE
), brdp
->ioctrl
);
2543 name
= "serial(EC8/32)";
2544 outb(status
, brdp
->ioaddr1
);
2548 brdp
->isr
= stl_echmcaintr
;
2549 brdp
->ioctrl
= brdp
->ioaddr1
+ 0x20;
2550 brdp
->iostatus
= brdp
->ioctrl
;
2551 status
= inb(brdp
->iostatus
);
2552 if ((status
& ECH_IDBITMASK
) != ECH_ID
)
2554 if ((brdp
->irq
< 0) || (brdp
->irq
> 15) ||
2555 (stl_vecmap
[brdp
->irq
] == (unsigned char) 0xff)) {
2556 printk("STALLION: invalid irq=%d for brd=%d\n",
2557 brdp
->irq
, brdp
->brdnr
);
2560 outb(ECHMC_BRDRESET
, brdp
->ioctrl
);
2561 outb(ECHMC_INTENABLE
, brdp
->ioctrl
);
2563 name
= "serial(EC8/32-MC)";
2567 brdp
->isr
= stl_echpciintr
;
2568 brdp
->ioctrl
= brdp
->ioaddr1
+ 2;
2571 name
= "serial(EC8/32-PCI)";
2575 brdp
->isr
= stl_echpci64intr
;
2576 brdp
->ioctrl
= brdp
->ioaddr2
+ 0x40;
2577 outb(0x43, (brdp
->ioaddr1
+ 0x4c));
2578 brdp
->iosize1
= 0x80;
2579 brdp
->iosize2
= 0x80;
2580 name
= "serial(EC8/64-PCI)";
2584 printk("STALLION: unknown board type=%d\n", brdp
->brdtype
);
2590 * Check boards for possible IO address conflicts. We won't actually
2591 * do anything about it here, just issue a warning...
2593 conflict
= check_region(brdp
->ioaddr1
, brdp
->iosize1
) ?
2595 if ((conflict
== 0) && (brdp
->iosize2
> 0))
2596 conflict
= check_region(brdp
->ioaddr2
, brdp
->iosize2
) ?
2599 printk("STALLION: Warning, board %d I/O address %x conflicts "
2600 "with another device\n", brdp
->brdnr
, conflict
);
2603 request_region(brdp
->ioaddr1
, brdp
->iosize1
, name
);
2604 if (brdp
->iosize2
> 0)
2605 request_region(brdp
->ioaddr2
, brdp
->iosize2
, name
);
2608 * Scan through the secondary io address space looking for panels.
2609 * As we find'em allocate and initialize panel structures for each.
2611 brdp
->clk
= CD1400_CLK
;
2612 brdp
->hwid
= status
;
2614 ioaddr
= brdp
->ioaddr2
;
2619 for (i
= 0; (i
< STL_MAXPANELS
); i
++) {
2620 if (brdp
->brdtype
== BRD_ECHPCI
) {
2621 outb(nxtid
, brdp
->ioctrl
);
2622 ioaddr
= brdp
->ioaddr2
;
2624 status
= inb(ioaddr
+ ECH_PNLSTATUS
);
2625 if ((status
& ECH_PNLIDMASK
) != nxtid
)
2627 panelp
= (stlpanel_t
*) stl_memalloc(sizeof(stlpanel_t
));
2628 if (panelp
== (stlpanel_t
*) NULL
) {
2629 printk("STALLION: failed to allocate memory "
2630 "(size=%d)\n", sizeof(stlpanel_t
));
2633 memset(panelp
, 0, sizeof(stlpanel_t
));
2634 panelp
->magic
= STL_PANELMAGIC
;
2635 panelp
->brdnr
= brdp
->brdnr
;
2636 panelp
->panelnr
= panelnr
;
2637 panelp
->iobase
= ioaddr
;
2638 panelp
->pagenr
= nxtid
;
2639 panelp
->hwid
= status
;
2640 brdp
->bnk2panel
[banknr
] = panelp
;
2641 brdp
->bnkpageaddr
[banknr
] = nxtid
;
2642 brdp
->bnkstataddr
[banknr
++] = ioaddr
+ ECH_PNLSTATUS
;
2644 if (status
& ECH_PNLXPID
) {
2645 panelp
->uartp
= (void *) &stl_sc26198uart
;
2646 panelp
->isr
= stl_sc26198intr
;
2647 if (status
& ECH_PNL16PORT
) {
2648 panelp
->nrports
= 16;
2649 brdp
->bnk2panel
[banknr
] = panelp
;
2650 brdp
->bnkpageaddr
[banknr
] = nxtid
;
2651 brdp
->bnkstataddr
[banknr
++] = ioaddr
+ 4 +
2654 panelp
->nrports
= 8;
2657 panelp
->uartp
= (void *) &stl_cd1400uart
;
2658 panelp
->isr
= stl_cd1400echintr
;
2659 if (status
& ECH_PNL16PORT
) {
2660 panelp
->nrports
= 16;
2661 panelp
->ackmask
= 0x80;
2662 if (brdp
->brdtype
!= BRD_ECHPCI
)
2663 ioaddr
+= EREG_BANKSIZE
;
2664 brdp
->bnk2panel
[banknr
] = panelp
;
2665 brdp
->bnkpageaddr
[banknr
] = ++nxtid
;
2666 brdp
->bnkstataddr
[banknr
++] = ioaddr
+
2669 panelp
->nrports
= 8;
2670 panelp
->ackmask
= 0xc0;
2675 ioaddr
+= EREG_BANKSIZE
;
2676 brdp
->nrports
+= panelp
->nrports
;
2677 brdp
->panels
[panelnr
++] = panelp
;
2678 if ((brdp
->brdtype
!= BRD_ECHPCI
) &&
2679 (ioaddr
>= (brdp
->ioaddr2
+ brdp
->iosize2
)))
2683 brdp
->nrpanels
= panelnr
;
2684 brdp
->nrbnks
= banknr
;
2685 if (brdp
->brdtype
== BRD_ECH
)
2686 outb((brdp
->ioctrlval
| ECH_BRDDISABLE
), brdp
->ioctrl
);
2688 brdp
->state
|= BRD_FOUND
;
2689 i
= stl_mapirq(brdp
->irq
, name
);
2693 /*****************************************************************************/
2696 * Initialize and configure the specified board.
2697 * Scan through all the boards in the configuration and see what we
2698 * can find. Handle EIO and the ECH boards a little differently here
2699 * since the initial search and setup is very different.
2702 __initfunc(static int stl_brdinit(stlbrd_t
*brdp
))
2707 printk("stl_brdinit(brdp=%x)\n", (int) brdp
);
2710 switch (brdp
->brdtype
) {
2722 printk("STALLION: board=%d is unknown board type=%d\n",
2723 brdp
->brdnr
, brdp
->brdtype
);
2727 stl_brds
[brdp
->brdnr
] = brdp
;
2728 if ((brdp
->state
& BRD_FOUND
) == 0) {
2729 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2730 stl_brdnames
[brdp
->brdtype
], brdp
->brdnr
,
2731 brdp
->ioaddr1
, brdp
->irq
);
2735 for (i
= 0; (i
< STL_MAXPANELS
); i
++)
2736 if (brdp
->panels
[i
] != (stlpanel_t
*) NULL
)
2737 stl_initports(brdp
, brdp
->panels
[i
]);
2739 printk("STALLION: %s found, board=%d io=%x irq=%d "
2740 "nrpanels=%d nrports=%d\n", stl_brdnames
[brdp
->brdtype
],
2741 brdp
->brdnr
, brdp
->ioaddr1
, brdp
->irq
, brdp
->nrpanels
,
2746 /*****************************************************************************/
2749 * Find the next available board number that is free.
2752 static inline int stl_getbrdnr()
2756 for (i
= 0; (i
< STL_MAXBRDS
); i
++) {
2757 if (stl_brds
[i
] == (stlbrd_t
*) NULL
) {
2758 if (i
>= stl_nrbrds
)
2766 /*****************************************************************************/
2771 * We have a Stallion board. Allocate a board structure and
2772 * initialize it. Read its IO and IRQ resources from PCI
2773 * configuration space.
2776 static inline int stl_initpcibrd(int brdtype
, struct pci_dev
*devp
)
2781 printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype
,
2782 dev
->bus
->number
, dev
->devfn
);
2785 if ((brdp
= stl_allocbrd()) == (stlbrd_t
*) NULL
)
2787 if ((brdp
->brdnr
= stl_getbrdnr()) < 0) {
2788 printk("STALLION: too many boards found, "
2789 "maximum supported %d\n", STL_MAXBRDS
);
2792 brdp
->brdtype
= brdtype
;
2795 * Different Stallion boards use the BAR registers in different ways,
2796 * so set up io addresses based on board type.
2799 printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__
, __LINE__
,
2800 devp
->base_address
[0], devp
->base_address
[1],
2801 devp
->base_address
[2], devp
->base_address
[3], devp
->irq
);
2805 * We have all resources from the board, so let's setup the actual
2806 * board structure now.
2810 brdp
->ioaddr2
= (devp
->base_address
[0] &
2811 PCI_BASE_ADDRESS_IO_MASK
);
2812 brdp
->ioaddr1
= (devp
->base_address
[1] &
2813 PCI_BASE_ADDRESS_IO_MASK
);
2816 brdp
->ioaddr2
= (devp
->base_address
[2] &
2817 PCI_BASE_ADDRESS_IO_MASK
);
2818 brdp
->ioaddr1
= (devp
->base_address
[1] &
2819 PCI_BASE_ADDRESS_IO_MASK
);
2822 brdp
->ioaddr1
= (devp
->base_address
[2] &
2823 PCI_BASE_ADDRESS_IO_MASK
);
2824 brdp
->ioaddr2
= (devp
->base_address
[1] &
2825 PCI_BASE_ADDRESS_IO_MASK
);
2828 printk("STALLION: unknown PCI board type=%d\n", brdtype
);
2832 brdp
->irq
= devp
->irq
;
2838 /*****************************************************************************/
2841 * Find all Stallion PCI boards that might be installed. Initialize each
2842 * one as it is found.
2846 static inline int stl_findpcibrds()
2848 struct pci_dev
*dev
= NULL
;
2852 printk("stl_findpcibrds()\n");
2855 if (! pci_present())
2858 for (i
= 0; (i
< stl_nrpcibrds
); i
++)
2859 while ((dev
= pci_find_device(stl_pcibrds
[i
].vendid
,
2860 stl_pcibrds
[i
].devid
, dev
))) {
2863 * Found a device on the PCI bus that has our vendor and
2864 * device ID. Need to check now that it is really us.
2866 if ((dev
->class >> 8) == PCI_CLASS_STORAGE_IDE
)
2869 rc
= stl_initpcibrd(stl_pcibrds
[i
].brdtype
, dev
);
2879 /*****************************************************************************/
2882 * Scan through all the boards in the configuration and see what we
2883 * can find. Handle EIO and the ECH boards a little differently here
2884 * since the initial search and setup is too different.
2887 static inline int stl_initbrds()
2894 printk("stl_initbrds()\n");
2897 if (stl_nrbrds
> STL_MAXBRDS
) {
2898 printk("STALLION: too many boards in configuration table, "
2899 "truncating to %d\n", STL_MAXBRDS
);
2900 stl_nrbrds
= STL_MAXBRDS
;
2904 * Firstly scan the list of static boards configured. Allocate
2905 * resources and initialize the boards as found.
2907 for (i
= 0; (i
< stl_nrbrds
); i
++) {
2908 confp
= &stl_brdconf
[i
];
2910 stl_parsebrd(confp
, stl_brdsp
[i
]);
2912 if ((brdp
= stl_allocbrd()) == (stlbrd_t
*) NULL
)
2915 brdp
->brdtype
= confp
->brdtype
;
2916 brdp
->ioaddr1
= confp
->ioaddr1
;
2917 brdp
->ioaddr2
= confp
->ioaddr2
;
2918 brdp
->irq
= confp
->irq
;
2919 brdp
->irqtype
= confp
->irqtype
;
2924 * Find any dynamically supported boards. That is via module load
2925 * line options or auto-detected on the PCI bus.
2937 /*****************************************************************************/
2940 * Return the board stats structure to user app.
2943 static int stl_getbrdstats(combrd_t
*bp
)
2949 copy_from_user(&stl_brdstats
, bp
, sizeof(combrd_t
));
2950 if (stl_brdstats
.brd
>= STL_MAXBRDS
)
2952 brdp
= stl_brds
[stl_brdstats
.brd
];
2953 if (brdp
== (stlbrd_t
*) NULL
)
2956 memset(&stl_brdstats
, 0, sizeof(combrd_t
));
2957 stl_brdstats
.brd
= brdp
->brdnr
;
2958 stl_brdstats
.type
= brdp
->brdtype
;
2959 stl_brdstats
.hwid
= brdp
->hwid
;
2960 stl_brdstats
.state
= brdp
->state
;
2961 stl_brdstats
.ioaddr
= brdp
->ioaddr1
;
2962 stl_brdstats
.ioaddr2
= brdp
->ioaddr2
;
2963 stl_brdstats
.irq
= brdp
->irq
;
2964 stl_brdstats
.nrpanels
= brdp
->nrpanels
;
2965 stl_brdstats
.nrports
= brdp
->nrports
;
2966 for (i
= 0; (i
< brdp
->nrpanels
); i
++) {
2967 panelp
= brdp
->panels
[i
];
2968 stl_brdstats
.panels
[i
].panel
= i
;
2969 stl_brdstats
.panels
[i
].hwid
= panelp
->hwid
;
2970 stl_brdstats
.panels
[i
].nrports
= panelp
->nrports
;
2973 copy_to_user(bp
, &stl_brdstats
, sizeof(combrd_t
));
2977 /*****************************************************************************/
2980 * Resolve the referenced port number into a port struct pointer.
2983 static stlport_t
*stl_getport(int brdnr
, int panelnr
, int portnr
)
2988 if ((brdnr
< 0) || (brdnr
>= STL_MAXBRDS
))
2989 return((stlport_t
*) NULL
);
2990 brdp
= stl_brds
[brdnr
];
2991 if (brdp
== (stlbrd_t
*) NULL
)
2992 return((stlport_t
*) NULL
);
2993 if ((panelnr
< 0) || (panelnr
>= brdp
->nrpanels
))
2994 return((stlport_t
*) NULL
);
2995 panelp
= brdp
->panels
[panelnr
];
2996 if (panelp
== (stlpanel_t
*) NULL
)
2997 return((stlport_t
*) NULL
);
2998 if ((portnr
< 0) || (portnr
>= panelp
->nrports
))
2999 return((stlport_t
*) NULL
);
3000 return(panelp
->ports
[portnr
]);
3003 /*****************************************************************************/
3006 * Return the port stats structure to user app. A NULL port struct
3007 * pointer passed in means that we need to find out from the app
3008 * what port to get stats for (used through board control device).
3011 static int stl_getportstats(stlport_t
*portp
, comstats_t
*cp
)
3013 unsigned char *head
, *tail
;
3014 unsigned long flags
;
3016 if (portp
== (stlport_t
*) NULL
) {
3017 copy_from_user(&stl_comstats
, cp
, sizeof(comstats_t
));
3018 portp
= stl_getport(stl_comstats
.brd
, stl_comstats
.panel
,
3020 if (portp
== (stlport_t
*) NULL
)
3024 portp
->stats
.state
= portp
->istate
;
3025 portp
->stats
.flags
= portp
->flags
;
3026 portp
->stats
.hwid
= portp
->hwid
;
3028 portp
->stats
.ttystate
= 0;
3029 portp
->stats
.cflags
= 0;
3030 portp
->stats
.iflags
= 0;
3031 portp
->stats
.oflags
= 0;
3032 portp
->stats
.lflags
= 0;
3033 portp
->stats
.rxbuffered
= 0;
3037 if (portp
->tty
!= (struct tty_struct
*) NULL
) {
3038 if (portp
->tty
->driver_data
== portp
) {
3039 portp
->stats
.ttystate
= portp
->tty
->flags
;
3040 portp
->stats
.rxbuffered
= portp
->tty
->flip
.count
;
3041 if (portp
->tty
->termios
!= (struct termios
*) NULL
) {
3042 portp
->stats
.cflags
= portp
->tty
->termios
->c_cflag
;
3043 portp
->stats
.iflags
= portp
->tty
->termios
->c_iflag
;
3044 portp
->stats
.oflags
= portp
->tty
->termios
->c_oflag
;
3045 portp
->stats
.lflags
= portp
->tty
->termios
->c_lflag
;
3049 restore_flags(flags
);
3051 head
= portp
->tx
.head
;
3052 tail
= portp
->tx
.tail
;
3053 portp
->stats
.txbuffered
= ((head
>= tail
) ? (head
- tail
) :
3054 (STL_TXBUFSIZE
- (tail
- head
)));
3056 portp
->stats
.signals
= (unsigned long) stl_getsignals(portp
);
3058 copy_to_user(cp
, &portp
->stats
, sizeof(comstats_t
));
3062 /*****************************************************************************/
3065 * Clear the port stats structure. We also return it zeroed out...
3068 static int stl_clrportstats(stlport_t
*portp
, comstats_t
*cp
)
3070 if (portp
== (stlport_t
*) NULL
) {
3071 copy_from_user(&stl_comstats
, cp
, sizeof(comstats_t
));
3072 portp
= stl_getport(stl_comstats
.brd
, stl_comstats
.panel
,
3074 if (portp
== (stlport_t
*) NULL
)
3078 memset(&portp
->stats
, 0, sizeof(comstats_t
));
3079 portp
->stats
.brd
= portp
->brdnr
;
3080 portp
->stats
.panel
= portp
->panelnr
;
3081 portp
->stats
.port
= portp
->portnr
;
3082 copy_to_user(cp
, &portp
->stats
, sizeof(comstats_t
));
3086 /*****************************************************************************/
3089 * Return the entire driver ports structure to a user app.
3092 static int stl_getportstruct(unsigned long arg
)
3096 copy_from_user(&stl_dummyport
, (void *) arg
, sizeof(stlport_t
));
3097 portp
= stl_getport(stl_dummyport
.brdnr
, stl_dummyport
.panelnr
,
3098 stl_dummyport
.portnr
);
3099 if (portp
== (stlport_t
*) NULL
)
3101 copy_to_user((void *) arg
, portp
, sizeof(stlport_t
));
3105 /*****************************************************************************/
3108 * Return the entire driver board structure to a user app.
3111 static int stl_getbrdstruct(unsigned long arg
)
3115 copy_from_user(&stl_dummybrd
, (void *) arg
, sizeof(stlbrd_t
));
3116 if ((stl_dummybrd
.brdnr
< 0) || (stl_dummybrd
.brdnr
>= STL_MAXBRDS
))
3118 brdp
= stl_brds
[stl_dummybrd
.brdnr
];
3119 if (brdp
== (stlbrd_t
*) NULL
)
3121 copy_to_user((void *) arg
, brdp
, sizeof(stlbrd_t
));
3125 /*****************************************************************************/
3128 * Memory device open code. Need to keep track of opens and close
3129 * for module handling.
3132 static int stl_memopen(struct inode
*ip
, struct file
*fp
)
3138 /*****************************************************************************/
3140 static int stl_memclose(struct inode
*ip
, struct file
*fp
)
3146 /*****************************************************************************/
3149 * The "staliomem" device is also required to do some special operations
3150 * on the board and/or ports. In this driver it is mostly used for stats
3154 static int stl_memioctl(struct inode
*ip
, struct file
*fp
, unsigned int cmd
, unsigned long arg
)
3159 printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip
,
3160 (int) fp
, cmd
, (int) arg
);
3163 brdnr
= MINOR(ip
->i_rdev
);
3164 if (brdnr
>= STL_MAXBRDS
)
3169 case COM_GETPORTSTATS
:
3170 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
3171 sizeof(comstats_t
))) == 0)
3172 rc
= stl_getportstats((stlport_t
*) NULL
,
3173 (comstats_t
*) arg
);
3175 case COM_CLRPORTSTATS
:
3176 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
3177 sizeof(comstats_t
))) == 0)
3178 rc
= stl_clrportstats((stlport_t
*) NULL
,
3179 (comstats_t
*) arg
);
3181 case COM_GETBRDSTATS
:
3182 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
3183 sizeof(combrd_t
))) == 0)
3184 rc
= stl_getbrdstats((combrd_t
*) arg
);
3187 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
3188 sizeof(stlport_t
))) == 0)
3189 rc
= stl_getportstruct(arg
);
3192 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
3193 sizeof(stlbrd_t
))) == 0)
3194 rc
= stl_getbrdstruct(arg
);
3204 /*****************************************************************************/
3206 __initfunc(int stl_init(void))
3208 printk(KERN_INFO
"%s: version %s\n", stl_drvtitle
, stl_drvversion
);
3213 * Allocate a temporary write buffer.
3215 stl_tmpwritebuf
= (char *) stl_memalloc(STL_TXBUFSIZE
);
3216 if (stl_tmpwritebuf
== (char *) NULL
)
3217 printk("STALLION: failed to allocate memory (size=%d)\n",
3221 * Set up a character driver for per board stuff. This is mainly used
3222 * to do stats ioctls on the ports.
3224 if (register_chrdev(STL_SIOMEMMAJOR
, "staliomem", &stl_fsiomem
))
3225 printk("STALLION: failed to register serial board device\n");
3228 * Set up the tty driver structure and register us as a driver.
3229 * Also setup the callout tty device.
3231 memset(&stl_serial
, 0, sizeof(struct tty_driver
));
3232 stl_serial
.magic
= TTY_DRIVER_MAGIC
;
3233 stl_serial
.driver_name
= stl_drvname
;
3234 stl_serial
.name
= stl_serialname
;
3235 stl_serial
.major
= STL_SERIALMAJOR
;
3236 stl_serial
.minor_start
= 0;
3237 stl_serial
.num
= STL_MAXBRDS
* STL_MAXPORTS
;
3238 stl_serial
.type
= TTY_DRIVER_TYPE_SERIAL
;
3239 stl_serial
.subtype
= STL_DRVTYPSERIAL
;
3240 stl_serial
.init_termios
= stl_deftermios
;
3241 stl_serial
.flags
= TTY_DRIVER_REAL_RAW
;
3242 stl_serial
.refcount
= &stl_refcount
;
3243 stl_serial
.table
= stl_ttys
;
3244 stl_serial
.termios
= stl_termios
;
3245 stl_serial
.termios_locked
= stl_termioslocked
;
3247 stl_serial
.open
= stl_open
;
3248 stl_serial
.close
= stl_close
;
3249 stl_serial
.write
= stl_write
;
3250 stl_serial
.put_char
= stl_putchar
;
3251 stl_serial
.flush_chars
= stl_flushchars
;
3252 stl_serial
.write_room
= stl_writeroom
;
3253 stl_serial
.chars_in_buffer
= stl_charsinbuffer
;
3254 stl_serial
.ioctl
= stl_ioctl
;
3255 stl_serial
.set_termios
= stl_settermios
;
3256 stl_serial
.throttle
= stl_throttle
;
3257 stl_serial
.unthrottle
= stl_unthrottle
;
3258 stl_serial
.stop
= stl_stop
;
3259 stl_serial
.start
= stl_start
;
3260 stl_serial
.hangup
= stl_hangup
;
3261 stl_serial
.flush_buffer
= stl_flushbuffer
;
3262 stl_serial
.break_ctl
= stl_breakctl
;
3263 stl_serial
.wait_until_sent
= stl_waituntilsent
;
3264 stl_serial
.send_xchar
= stl_sendxchar
;
3265 stl_serial
.read_proc
= stl_readproc
;
3267 stl_callout
= stl_serial
;
3268 stl_callout
.name
= stl_calloutname
;
3269 stl_callout
.major
= STL_CALLOUTMAJOR
;
3270 stl_callout
.subtype
= STL_DRVTYPCALLOUT
;
3271 stl_callout
.read_proc
= 0;
3273 if (tty_register_driver(&stl_serial
))
3274 printk("STALLION: failed to register serial driver\n");
3275 if (tty_register_driver(&stl_callout
))
3276 printk("STALLION: failed to register callout driver\n");
3281 /*****************************************************************************/
3282 /* CD1400 HARDWARE FUNCTIONS */
3283 /*****************************************************************************/
3286 * These functions get/set/update the registers of the cd1400 UARTs.
3287 * Access to the cd1400 registers is via an address/data io port pair.
3288 * (Maybe should make this inline...)
3291 static int stl_cd1400getreg(stlport_t
*portp
, int regnr
)
3293 outb((regnr
+ portp
->uartaddr
), portp
->ioaddr
);
3294 return(inb(portp
->ioaddr
+ EREG_DATA
));
3297 static void stl_cd1400setreg(stlport_t
*portp
, int regnr
, int value
)
3299 outb((regnr
+ portp
->uartaddr
), portp
->ioaddr
);
3300 outb(value
, portp
->ioaddr
+ EREG_DATA
);
3303 static int stl_cd1400updatereg(stlport_t
*portp
, int regnr
, int value
)
3305 outb((regnr
+ portp
->uartaddr
), portp
->ioaddr
);
3306 if (inb(portp
->ioaddr
+ EREG_DATA
) != value
) {
3307 outb(value
, portp
->ioaddr
+ EREG_DATA
);
3313 /*****************************************************************************/
3316 * Inbitialize the UARTs in a panel. We don't care what sort of board
3317 * these ports are on - since the port io registers are almost
3318 * identical when dealing with ports.
3321 static int stl_cd1400panelinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
)
3325 int nrchips
, uartaddr
, ioaddr
;
3328 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp
, (int) panelp
);
3331 BRDENABLE(panelp
->brdnr
, panelp
->pagenr
);
3334 * Check that each chip is present and started up OK.
3337 nrchips
= panelp
->nrports
/ CD1400_PORTS
;
3338 for (i
= 0; (i
< nrchips
); i
++) {
3339 if (brdp
->brdtype
== BRD_ECHPCI
) {
3340 outb((panelp
->pagenr
+ (i
>> 1)), brdp
->ioctrl
);
3341 ioaddr
= panelp
->iobase
;
3343 ioaddr
= panelp
->iobase
+ (EREG_BANKSIZE
* (i
>> 1));
3345 uartaddr
= (i
& 0x01) ? 0x080 : 0;
3346 outb((GFRCR
+ uartaddr
), ioaddr
);
3347 outb(0, (ioaddr
+ EREG_DATA
));
3348 outb((CCR
+ uartaddr
), ioaddr
);
3349 outb(CCR_RESETFULL
, (ioaddr
+ EREG_DATA
));
3350 outb(CCR_RESETFULL
, (ioaddr
+ EREG_DATA
));
3351 outb((GFRCR
+ uartaddr
), ioaddr
);
3352 for (j
= 0; (j
< CCR_MAXWAIT
); j
++) {
3353 if ((gfrcr
= inb(ioaddr
+ EREG_DATA
)) != 0)
3356 if ((j
>= CCR_MAXWAIT
) || (gfrcr
< 0x40) || (gfrcr
> 0x60)) {
3357 printk("STALLION: cd1400 not responding, "
3358 "brd=%d panel=%d chip=%d\n",
3359 panelp
->brdnr
, panelp
->panelnr
, i
);
3362 chipmask
|= (0x1 << i
);
3363 outb((PPR
+ uartaddr
), ioaddr
);
3364 outb(PPR_SCALAR
, (ioaddr
+ EREG_DATA
));
3367 BRDDISABLE(panelp
->brdnr
);
3371 /*****************************************************************************/
3374 * Initialize hardware specific port registers.
3377 static void stl_cd1400portinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
)
3380 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3381 (int) brdp
, (int) panelp
, (int) portp
);
3384 if ((brdp
== (stlbrd_t
*) NULL
) || (panelp
== (stlpanel_t
*) NULL
) ||
3385 (portp
== (stlport_t
*) NULL
))
3388 portp
->ioaddr
= panelp
->iobase
+ (((brdp
->brdtype
== BRD_ECHPCI
) ||
3389 (portp
->portnr
< 8)) ? 0 : EREG_BANKSIZE
);
3390 portp
->uartaddr
= (portp
->portnr
& 0x04) << 5;
3391 portp
->pagenr
= panelp
->pagenr
+ (portp
->portnr
>> 3);
3393 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3394 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3395 stl_cd1400setreg(portp
, LIVR
, (portp
->portnr
<< 3));
3396 portp
->hwid
= stl_cd1400getreg(portp
, GFRCR
);
3397 BRDDISABLE(portp
->brdnr
);
3400 /*****************************************************************************/
3403 * Wait for the command register to be ready. We will poll this,
3404 * since it won't usually take too long to be ready.
3407 static void stl_cd1400ccrwait(stlport_t
*portp
)
3411 for (i
= 0; (i
< CCR_MAXWAIT
); i
++) {
3412 if (stl_cd1400getreg(portp
, CCR
) == 0) {
3417 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
3418 portp
->portnr
, portp
->panelnr
, portp
->brdnr
);
3421 /*****************************************************************************/
3424 * Set up the cd1400 registers for a port based on the termios port
3428 static void stl_cd1400setport(stlport_t
*portp
, struct termios
*tiosp
)
3431 unsigned long flags
;
3432 unsigned int clkdiv
, baudrate
;
3433 unsigned char cor1
, cor2
, cor3
;
3434 unsigned char cor4
, cor5
, ccr
;
3435 unsigned char srer
, sreron
, sreroff
;
3436 unsigned char mcor1
, mcor2
, rtpr
;
3437 unsigned char clk
, div
;
3453 brdp
= stl_brds
[portp
->brdnr
];
3454 if (brdp
== (stlbrd_t
*) NULL
)
3458 * Set up the RX char ignore mask with those RX error types we
3459 * can ignore. We can get the cd1400 to help us out a little here,
3460 * it will ignore parity errors and breaks for us.
3462 portp
->rxignoremsk
= 0;
3463 if (tiosp
->c_iflag
& IGNPAR
) {
3464 portp
->rxignoremsk
|= (ST_PARITY
| ST_FRAMING
| ST_OVERRUN
);
3465 cor1
|= COR1_PARIGNORE
;
3467 if (tiosp
->c_iflag
& IGNBRK
) {
3468 portp
->rxignoremsk
|= ST_BREAK
;
3469 cor4
|= COR4_IGNBRK
;
3472 portp
->rxmarkmsk
= ST_OVERRUN
;
3473 if (tiosp
->c_iflag
& (INPCK
| PARMRK
))
3474 portp
->rxmarkmsk
|= (ST_PARITY
| ST_FRAMING
);
3475 if (tiosp
->c_iflag
& BRKINT
)
3476 portp
->rxmarkmsk
|= ST_BREAK
;
3479 * Go through the char size, parity and stop bits and set all the
3480 * option register appropriately.
3482 switch (tiosp
->c_cflag
& CSIZE
) {
3497 if (tiosp
->c_cflag
& CSTOPB
)
3502 if (tiosp
->c_cflag
& PARENB
) {
3503 if (tiosp
->c_cflag
& PARODD
)
3504 cor1
|= (COR1_PARENB
| COR1_PARODD
);
3506 cor1
|= (COR1_PARENB
| COR1_PAREVEN
);
3508 cor1
|= COR1_PARNONE
;
3512 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3513 * space for hardware flow control and the like. This should be set to
3514 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3515 * really be based on VTIME.
3517 cor3
|= FIFO_RXTHRESHOLD
;
3521 * Calculate the baud rate timers. For now we will just assume that
3522 * the input and output baud are the same. Could have used a baud
3523 * table here, but this way we can generate virtually any baud rate
3526 baudrate
= tiosp
->c_cflag
& CBAUD
;
3527 if (baudrate
& CBAUDEX
) {
3528 baudrate
&= ~CBAUDEX
;
3529 if ((baudrate
< 1) || (baudrate
> 4))
3530 tiosp
->c_cflag
&= ~CBAUDEX
;
3534 baudrate
= stl_baudrates
[baudrate
];
3535 if ((tiosp
->c_cflag
& CBAUD
) == B38400
) {
3536 if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
3538 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
3540 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
3542 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
3544 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)
3545 baudrate
= (portp
->baud_base
/ portp
->custom_divisor
);
3547 if (baudrate
> STL_CD1400MAXBAUD
)
3548 baudrate
= STL_CD1400MAXBAUD
;
3551 for (clk
= 0; (clk
< CD1400_NUMCLKS
); clk
++) {
3552 clkdiv
= ((portp
->clk
/ stl_cd1400clkdivs
[clk
]) / baudrate
);
3556 div
= (unsigned char) clkdiv
;
3560 * Check what form of modem signaling is required and set it up.
3562 if ((tiosp
->c_cflag
& CLOCAL
) == 0) {
3565 sreron
|= SRER_MODEM
;
3566 portp
->flags
|= ASYNC_CHECK_CD
;
3568 portp
->flags
&= ~ASYNC_CHECK_CD
;
3572 * Setup cd1400 enhanced modes if we can. In particular we want to
3573 * handle as much of the flow control as possible automatically. As
3574 * well as saving a few CPU cycles it will also greatly improve flow
3575 * control reliability.
3577 if (tiosp
->c_iflag
& IXON
) {
3580 if (tiosp
->c_iflag
& IXANY
)
3584 if (tiosp
->c_cflag
& CRTSCTS
) {
3586 mcor1
|= FIFO_RTSTHRESHOLD
;
3590 * All cd1400 register values calculated so go through and set
3595 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3596 portp
->portnr
, portp
->panelnr
, portp
->brdnr
);
3597 printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3598 cor1
, cor2
, cor3
, cor4
, cor5
);
3599 printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3600 mcor1
, mcor2
, rtpr
, sreron
, sreroff
);
3601 printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk
, div
, clk
, div
);
3602 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3603 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
],
3604 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
]);
3609 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3610 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x3));
3611 srer
= stl_cd1400getreg(portp
, SRER
);
3612 stl_cd1400setreg(portp
, SRER
, 0);
3613 if (stl_cd1400updatereg(portp
, COR1
, cor1
))
3615 if (stl_cd1400updatereg(portp
, COR2
, cor2
))
3617 if (stl_cd1400updatereg(portp
, COR3
, cor3
))
3620 stl_cd1400ccrwait(portp
);
3621 stl_cd1400setreg(portp
, CCR
, CCR_CORCHANGE
);
3623 stl_cd1400setreg(portp
, COR4
, cor4
);
3624 stl_cd1400setreg(portp
, COR5
, cor5
);
3625 stl_cd1400setreg(portp
, MCOR1
, mcor1
);
3626 stl_cd1400setreg(portp
, MCOR2
, mcor2
);
3628 stl_cd1400setreg(portp
, TCOR
, clk
);
3629 stl_cd1400setreg(portp
, TBPR
, div
);
3630 stl_cd1400setreg(portp
, RCOR
, clk
);
3631 stl_cd1400setreg(portp
, RBPR
, div
);
3633 stl_cd1400setreg(portp
, SCHR1
, tiosp
->c_cc
[VSTART
]);
3634 stl_cd1400setreg(portp
, SCHR2
, tiosp
->c_cc
[VSTOP
]);
3635 stl_cd1400setreg(portp
, SCHR3
, tiosp
->c_cc
[VSTART
]);
3636 stl_cd1400setreg(portp
, SCHR4
, tiosp
->c_cc
[VSTOP
]);
3637 stl_cd1400setreg(portp
, RTPR
, rtpr
);
3638 mcor1
= stl_cd1400getreg(portp
, MSVR1
);
3639 if (mcor1
& MSVR1_DCD
)
3640 portp
->sigs
|= TIOCM_CD
;
3642 portp
->sigs
&= ~TIOCM_CD
;
3643 stl_cd1400setreg(portp
, SRER
, ((srer
& ~sreroff
) | sreron
));
3644 BRDDISABLE(portp
->brdnr
);
3645 restore_flags(flags
);
3648 /*****************************************************************************/
3651 * Set the state of the DTR and RTS signals.
3654 static void stl_cd1400setsignals(stlport_t
*portp
, int dtr
, int rts
)
3656 unsigned char msvr1
, msvr2
;
3657 unsigned long flags
;
3660 printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
3661 (int) portp
, dtr
, rts
);
3673 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3674 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3676 stl_cd1400setreg(portp
, MSVR2
, msvr2
);
3678 stl_cd1400setreg(portp
, MSVR1
, msvr1
);
3679 BRDDISABLE(portp
->brdnr
);
3680 restore_flags(flags
);
3683 /*****************************************************************************/
3686 * Return the state of the signals.
3689 static int stl_cd1400getsignals(stlport_t
*portp
)
3691 unsigned char msvr1
, msvr2
;
3692 unsigned long flags
;
3696 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp
);
3701 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3702 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3703 msvr1
= stl_cd1400getreg(portp
, MSVR1
);
3704 msvr2
= stl_cd1400getreg(portp
, MSVR2
);
3705 BRDDISABLE(portp
->brdnr
);
3706 restore_flags(flags
);
3709 sigs
|= (msvr1
& MSVR1_DCD
) ? TIOCM_CD
: 0;
3710 sigs
|= (msvr1
& MSVR1_CTS
) ? TIOCM_CTS
: 0;
3711 sigs
|= (msvr1
& MSVR1_DTR
) ? TIOCM_DTR
: 0;
3712 sigs
|= (msvr2
& MSVR2_RTS
) ? TIOCM_RTS
: 0;
3714 sigs
|= (msvr1
& MSVR1_RI
) ? TIOCM_RI
: 0;
3715 sigs
|= (msvr1
& MSVR1_DSR
) ? TIOCM_DSR
: 0;
3722 /*****************************************************************************/
3725 * Enable/Disable the Transmitter and/or Receiver.
3728 static void stl_cd1400enablerxtx(stlport_t
*portp
, int rx
, int tx
)
3731 unsigned long flags
;
3734 printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3735 (int) portp
, rx
, tx
);
3740 ccr
|= CCR_TXDISABLE
;
3742 ccr
|= CCR_TXENABLE
;
3744 ccr
|= CCR_RXDISABLE
;
3746 ccr
|= CCR_RXENABLE
;
3750 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3751 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3752 stl_cd1400ccrwait(portp
);
3753 stl_cd1400setreg(portp
, CCR
, ccr
);
3754 stl_cd1400ccrwait(portp
);
3755 BRDDISABLE(portp
->brdnr
);
3756 restore_flags(flags
);
3759 /*****************************************************************************/
3762 * Start/stop the Transmitter and/or Receiver.
3765 static void stl_cd1400startrxtx(stlport_t
*portp
, int rx
, int tx
)
3767 unsigned char sreron
, sreroff
;
3768 unsigned long flags
;
3771 printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3772 (int) portp
, rx
, tx
);
3778 sreroff
|= (SRER_TXDATA
| SRER_TXEMPTY
);
3780 sreron
|= SRER_TXDATA
;
3782 sreron
|= SRER_TXEMPTY
;
3784 sreroff
|= SRER_RXDATA
;
3786 sreron
|= SRER_RXDATA
;
3790 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3791 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3792 stl_cd1400setreg(portp
, SRER
,
3793 ((stl_cd1400getreg(portp
, SRER
) & ~sreroff
) | sreron
));
3794 BRDDISABLE(portp
->brdnr
);
3796 set_bit(ASYI_TXBUSY
, &portp
->istate
);
3797 restore_flags(flags
);
3800 /*****************************************************************************/
3803 * Disable all interrupts from this port.
3806 static void stl_cd1400disableintrs(stlport_t
*portp
)
3808 unsigned long flags
;
3811 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp
);
3815 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3816 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3817 stl_cd1400setreg(portp
, SRER
, 0);
3818 BRDDISABLE(portp
->brdnr
);
3819 restore_flags(flags
);
3822 /*****************************************************************************/
3824 static void stl_cd1400sendbreak(stlport_t
*portp
, int len
)
3826 unsigned long flags
;
3829 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp
, len
);
3834 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3835 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3836 stl_cd1400setreg(portp
, SRER
,
3837 ((stl_cd1400getreg(portp
, SRER
) & ~SRER_TXDATA
) |
3839 BRDDISABLE(portp
->brdnr
);
3840 portp
->brklen
= len
;
3842 portp
->stats
.txbreaks
++;
3843 restore_flags(flags
);
3846 /*****************************************************************************/
3849 * Take flow control actions...
3852 static void stl_cd1400flowctrl(stlport_t
*portp
, int state
)
3854 struct tty_struct
*tty
;
3855 unsigned long flags
;
3858 printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp
, state
);
3861 if (portp
== (stlport_t
*) NULL
)
3864 if (tty
== (struct tty_struct
*) NULL
)
3869 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3870 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3873 if (tty
->termios
->c_iflag
& IXOFF
) {
3874 stl_cd1400ccrwait(portp
);
3875 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR1
);
3876 portp
->stats
.rxxon
++;
3877 stl_cd1400ccrwait(portp
);
3880 * Question: should we return RTS to what it was before? It may
3881 * have been set by an ioctl... Suppose not, since if you have
3882 * hardware flow control set then it is pretty silly to go and
3883 * set the RTS line by hand.
3885 if (tty
->termios
->c_cflag
& CRTSCTS
) {
3886 stl_cd1400setreg(portp
, MCOR1
,
3887 (stl_cd1400getreg(portp
, MCOR1
) |
3888 FIFO_RTSTHRESHOLD
));
3889 stl_cd1400setreg(portp
, MSVR2
, MSVR2_RTS
);
3890 portp
->stats
.rxrtson
++;
3893 if (tty
->termios
->c_iflag
& IXOFF
) {
3894 stl_cd1400ccrwait(portp
);
3895 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR2
);
3896 portp
->stats
.rxxoff
++;
3897 stl_cd1400ccrwait(portp
);
3899 if (tty
->termios
->c_cflag
& CRTSCTS
) {
3900 stl_cd1400setreg(portp
, MCOR1
,
3901 (stl_cd1400getreg(portp
, MCOR1
) & 0xf0));
3902 stl_cd1400setreg(portp
, MSVR2
, 0);
3903 portp
->stats
.rxrtsoff
++;
3907 BRDDISABLE(portp
->brdnr
);
3908 restore_flags(flags
);
3911 /*****************************************************************************/
3914 * Send a flow control character...
3917 static void stl_cd1400sendflow(stlport_t
*portp
, int state
)
3919 struct tty_struct
*tty
;
3920 unsigned long flags
;
3923 printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp
, state
);
3926 if (portp
== (stlport_t
*) NULL
)
3929 if (tty
== (struct tty_struct
*) NULL
)
3934 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3935 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3937 stl_cd1400ccrwait(portp
);
3938 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR1
);
3939 portp
->stats
.rxxon
++;
3940 stl_cd1400ccrwait(portp
);
3942 stl_cd1400ccrwait(portp
);
3943 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR2
);
3944 portp
->stats
.rxxoff
++;
3945 stl_cd1400ccrwait(portp
);
3947 BRDDISABLE(portp
->brdnr
);
3948 restore_flags(flags
);
3951 /*****************************************************************************/
3953 static void stl_cd1400flush(stlport_t
*portp
)
3955 unsigned long flags
;
3958 printk("stl_cd1400flush(portp=%x)\n", (int) portp
);
3961 if (portp
== (stlport_t
*) NULL
)
3966 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3967 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3968 stl_cd1400ccrwait(portp
);
3969 stl_cd1400setreg(portp
, CCR
, CCR_TXFLUSHFIFO
);
3970 stl_cd1400ccrwait(portp
);
3971 portp
->tx
.tail
= portp
->tx
.head
;
3972 BRDDISABLE(portp
->brdnr
);
3973 restore_flags(flags
);
3976 /*****************************************************************************/
3979 * Return the current state of data flow on this port. This is only
3980 * really interresting when determining if data has fully completed
3981 * transmission or not... This is easy for the cd1400, it accurately
3982 * maintains the busy port flag.
3985 static int stl_cd1400datastate(stlport_t
*portp
)
3988 printk("stl_cd1400datastate(portp=%x)\n", (int) portp
);
3991 if (portp
== (stlport_t
*) NULL
)
3994 return(test_bit(ASYI_TXBUSY
, &portp
->istate
) ? 1 : 0);
3997 /*****************************************************************************/
4000 * Interrupt service routine for cd1400 EasyIO boards.
4003 static void stl_cd1400eiointr(stlpanel_t
*panelp
, unsigned int iobase
)
4005 unsigned char svrtype
;
4008 printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
4009 (int) panelp
, iobase
);
4013 svrtype
= inb(iobase
+ EREG_DATA
);
4014 if (panelp
->nrports
> 4) {
4015 outb((SVRR
+ 0x80), iobase
);
4016 svrtype
|= inb(iobase
+ EREG_DATA
);
4019 if (svrtype
& SVRR_RX
)
4020 stl_cd1400rxisr(panelp
, iobase
);
4021 else if (svrtype
& SVRR_TX
)
4022 stl_cd1400txisr(panelp
, iobase
);
4023 else if (svrtype
& SVRR_MDM
)
4024 stl_cd1400mdmisr(panelp
, iobase
);
4027 /*****************************************************************************/
4030 * Interrupt service routine for cd1400 panels.
4033 static void stl_cd1400echintr(stlpanel_t
*panelp
, unsigned int iobase
)
4035 unsigned char svrtype
;
4038 printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp
,
4043 svrtype
= inb(iobase
+ EREG_DATA
);
4044 outb((SVRR
+ 0x80), iobase
);
4045 svrtype
|= inb(iobase
+ EREG_DATA
);
4046 if (svrtype
& SVRR_RX
)
4047 stl_cd1400rxisr(panelp
, iobase
);
4048 else if (svrtype
& SVRR_TX
)
4049 stl_cd1400txisr(panelp
, iobase
);
4050 else if (svrtype
& SVRR_MDM
)
4051 stl_cd1400mdmisr(panelp
, iobase
);
4055 /*****************************************************************************/
4058 * Unfortunately we need to handle breaks in the TX data stream, since
4059 * this is the only way to generate them on the cd1400.
4062 static inline int stl_cd1400breakisr(stlport_t
*portp
, int ioaddr
)
4064 if (portp
->brklen
== 1) {
4065 outb((COR2
+ portp
->uartaddr
), ioaddr
);
4066 outb((inb(ioaddr
+ EREG_DATA
) | COR2_ETC
),
4067 (ioaddr
+ EREG_DATA
));
4068 outb((TDR
+ portp
->uartaddr
), ioaddr
);
4069 outb(ETC_CMD
, (ioaddr
+ EREG_DATA
));
4070 outb(ETC_STARTBREAK
, (ioaddr
+ EREG_DATA
));
4071 outb((SRER
+ portp
->uartaddr
), ioaddr
);
4072 outb((inb(ioaddr
+ EREG_DATA
) & ~(SRER_TXDATA
| SRER_TXEMPTY
)),
4073 (ioaddr
+ EREG_DATA
));
4075 } else if (portp
->brklen
> 1) {
4076 outb((TDR
+ portp
->uartaddr
), ioaddr
);
4077 outb(ETC_CMD
, (ioaddr
+ EREG_DATA
));
4078 outb(ETC_STOPBREAK
, (ioaddr
+ EREG_DATA
));
4082 outb((COR2
+ portp
->uartaddr
), ioaddr
);
4083 outb((inb(ioaddr
+ EREG_DATA
) & ~COR2_ETC
),
4084 (ioaddr
+ EREG_DATA
));
4090 /*****************************************************************************/
4093 * Transmit interrupt handler. This has gotta be fast! Handling TX
4094 * chars is pretty simple, stuff as many as possible from the TX buffer
4095 * into the cd1400 FIFO. Must also handle TX breaks here, since they
4096 * are embedded as commands in the data stream. Oh no, had to use a goto!
4097 * This could be optimized more, will do when I get time...
4098 * In practice it is possible that interrupts are enabled but that the
4099 * port has been hung up. Need to handle not having any TX buffer here,
4100 * this is done by using the side effect that head and tail will also
4101 * be NULL if the buffer has been freed.
4104 static void stl_cd1400txisr(stlpanel_t
*panelp
, int ioaddr
)
4109 unsigned char ioack
, srer
;
4112 printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp
, ioaddr
);
4115 ioack
= inb(ioaddr
+ EREG_TXACK
);
4116 if (((ioack
& panelp
->ackmask
) != 0) ||
4117 ((ioack
& ACK_TYPMASK
) != ACK_TYPTX
)) {
4118 printk("STALLION: bad TX interrupt ack value=%x\n", ioack
);
4121 portp
= panelp
->ports
[(ioack
>> 3)];
4124 * Unfortunately we need to handle breaks in the data stream, since
4125 * this is the only way to generate them on the cd1400. Do it now if
4126 * a break is to be sent.
4128 if (portp
->brklen
!= 0)
4129 if (stl_cd1400breakisr(portp
, ioaddr
))
4132 head
= portp
->tx
.head
;
4133 tail
= portp
->tx
.tail
;
4134 len
= (head
>= tail
) ? (head
- tail
) : (STL_TXBUFSIZE
- (tail
- head
));
4135 if ((len
== 0) || ((len
< STL_TXBUFLOW
) &&
4136 (test_bit(ASYI_TXLOW
, &portp
->istate
) == 0))) {
4137 set_bit(ASYI_TXLOW
, &portp
->istate
);
4138 queue_task(&portp
->tqueue
, &tq_scheduler
);
4142 outb((SRER
+ portp
->uartaddr
), ioaddr
);
4143 srer
= inb(ioaddr
+ EREG_DATA
);
4144 if (srer
& SRER_TXDATA
) {
4145 srer
= (srer
& ~SRER_TXDATA
) | SRER_TXEMPTY
;
4147 srer
&= ~(SRER_TXDATA
| SRER_TXEMPTY
);
4148 clear_bit(ASYI_TXBUSY
, &portp
->istate
);
4150 outb(srer
, (ioaddr
+ EREG_DATA
));
4152 len
= MIN(len
, CD1400_TXFIFOSIZE
);
4153 portp
->stats
.txtotal
+= len
;
4154 stlen
= MIN(len
, ((portp
->tx
.buf
+ STL_TXBUFSIZE
) - tail
));
4155 outb((TDR
+ portp
->uartaddr
), ioaddr
);
4156 outsb((ioaddr
+ EREG_DATA
), tail
, stlen
);
4159 if (tail
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
))
4160 tail
= portp
->tx
.buf
;
4162 outsb((ioaddr
+ EREG_DATA
), tail
, len
);
4165 portp
->tx
.tail
= tail
;
4169 outb((EOSRR
+ portp
->uartaddr
), ioaddr
);
4170 outb(0, (ioaddr
+ EREG_DATA
));
4173 /*****************************************************************************/
4176 * Receive character interrupt handler. Determine if we have good chars
4177 * or bad chars and then process appropriately. Good chars are easy
4178 * just shove the lot into the RX buffer and set all status byte to 0.
4179 * If a bad RX char then process as required. This routine needs to be
4180 * fast! In practice it is possible that we get an interrupt on a port
4181 * that is closed. This can happen on hangups - since they completely
4182 * shutdown a port not in user context. Need to handle this case.
4185 static void stl_cd1400rxisr(stlpanel_t
*panelp
, int ioaddr
)
4188 struct tty_struct
*tty
;
4189 unsigned int ioack
, len
, buflen
;
4190 unsigned char status
;
4194 printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp
, ioaddr
);
4197 ioack
= inb(ioaddr
+ EREG_RXACK
);
4198 if ((ioack
& panelp
->ackmask
) != 0) {
4199 printk("STALLION: bad RX interrupt ack value=%x\n", ioack
);
4202 portp
= panelp
->ports
[(ioack
>> 3)];
4205 if ((ioack
& ACK_TYPMASK
) == ACK_TYPRXGOOD
) {
4206 outb((RDCR
+ portp
->uartaddr
), ioaddr
);
4207 len
= inb(ioaddr
+ EREG_DATA
);
4208 if ((tty
== (struct tty_struct
*) NULL
) ||
4209 (tty
->flip
.char_buf_ptr
== (char *) NULL
) ||
4210 ((buflen
= TTY_FLIPBUF_SIZE
- tty
->flip
.count
) == 0)) {
4211 outb((RDSR
+ portp
->uartaddr
), ioaddr
);
4212 insb((ioaddr
+ EREG_DATA
), &stl_unwanted
[0], len
);
4213 portp
->stats
.rxlost
+= len
;
4214 portp
->stats
.rxtotal
+= len
;
4216 len
= MIN(len
, buflen
);
4218 outb((RDSR
+ portp
->uartaddr
), ioaddr
);
4219 insb((ioaddr
+ EREG_DATA
), tty
->flip
.char_buf_ptr
, len
);
4220 memset(tty
->flip
.flag_buf_ptr
, 0, len
);
4221 tty
->flip
.flag_buf_ptr
+= len
;
4222 tty
->flip
.char_buf_ptr
+= len
;
4223 tty
->flip
.count
+= len
;
4224 tty_schedule_flip(tty
);
4225 portp
->stats
.rxtotal
+= len
;
4228 } else if ((ioack
& ACK_TYPMASK
) == ACK_TYPRXBAD
) {
4229 outb((RDSR
+ portp
->uartaddr
), ioaddr
);
4230 status
= inb(ioaddr
+ EREG_DATA
);
4231 ch
= inb(ioaddr
+ EREG_DATA
);
4232 if (status
& ST_PARITY
)
4233 portp
->stats
.rxparity
++;
4234 if (status
& ST_FRAMING
)
4235 portp
->stats
.rxframing
++;
4236 if (status
& ST_OVERRUN
)
4237 portp
->stats
.rxoverrun
++;
4238 if (status
& ST_BREAK
)
4239 portp
->stats
.rxbreaks
++;
4240 if (status
& ST_SCHARMASK
) {
4241 if ((status
& ST_SCHARMASK
) == ST_SCHAR1
)
4242 portp
->stats
.txxon
++;
4243 if ((status
& ST_SCHARMASK
) == ST_SCHAR2
)
4244 portp
->stats
.txxoff
++;
4247 if ((tty
!= (struct tty_struct
*) NULL
) &&
4248 ((portp
->rxignoremsk
& status
) == 0)) {
4249 if (portp
->rxmarkmsk
& status
) {
4250 if (status
& ST_BREAK
) {
4252 if (portp
->flags
& ASYNC_SAK
) {
4254 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4256 } else if (status
& ST_PARITY
) {
4257 status
= TTY_PARITY
;
4258 } else if (status
& ST_FRAMING
) {
4260 } else if(status
& ST_OVERRUN
) {
4261 status
= TTY_OVERRUN
;
4268 if (tty
->flip
.char_buf_ptr
!= (char *) NULL
) {
4269 if (tty
->flip
.count
< TTY_FLIPBUF_SIZE
) {
4270 *tty
->flip
.flag_buf_ptr
++ = status
;
4271 *tty
->flip
.char_buf_ptr
++ = ch
;
4274 tty_schedule_flip(tty
);
4278 printk("STALLION: bad RX interrupt ack value=%x\n", ioack
);
4283 outb((EOSRR
+ portp
->uartaddr
), ioaddr
);
4284 outb(0, (ioaddr
+ EREG_DATA
));
4287 /*****************************************************************************/
4290 * Modem interrupt handler. The is called when the modem signal line
4291 * (DCD) has changed state. Leave most of the work to the off-level
4292 * processing routine.
4295 static void stl_cd1400mdmisr(stlpanel_t
*panelp
, int ioaddr
)
4302 printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp
);
4305 ioack
= inb(ioaddr
+ EREG_MDACK
);
4306 if (((ioack
& panelp
->ackmask
) != 0) ||
4307 ((ioack
& ACK_TYPMASK
) != ACK_TYPMDM
)) {
4308 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack
);
4311 portp
= panelp
->ports
[(ioack
>> 3)];
4313 outb((MISR
+ portp
->uartaddr
), ioaddr
);
4314 misr
= inb(ioaddr
+ EREG_DATA
);
4315 if (misr
& MISR_DCD
) {
4316 set_bit(ASYI_DCDCHANGE
, &portp
->istate
);
4317 queue_task(&portp
->tqueue
, &tq_scheduler
);
4318 portp
->stats
.modem
++;
4321 outb((EOSRR
+ portp
->uartaddr
), ioaddr
);
4322 outb(0, (ioaddr
+ EREG_DATA
));
4325 /*****************************************************************************/
4326 /* SC26198 HARDWARE FUNCTIONS */
4327 /*****************************************************************************/
4330 * These functions get/set/update the registers of the sc26198 UARTs.
4331 * Access to the sc26198 registers is via an address/data io port pair.
4332 * (Maybe should make this inline...)
4335 static int stl_sc26198getreg(stlport_t
*portp
, int regnr
)
4337 outb((regnr
| portp
->uartaddr
), (portp
->ioaddr
+ XP_ADDR
));
4338 return(inb(portp
->ioaddr
+ XP_DATA
));
4341 static void stl_sc26198setreg(stlport_t
*portp
, int regnr
, int value
)
4343 outb((regnr
| portp
->uartaddr
), (portp
->ioaddr
+ XP_ADDR
));
4344 outb(value
, (portp
->ioaddr
+ XP_DATA
));
4347 static int stl_sc26198updatereg(stlport_t
*portp
, int regnr
, int value
)
4349 outb((regnr
| portp
->uartaddr
), (portp
->ioaddr
+ XP_ADDR
));
4350 if (inb(portp
->ioaddr
+ XP_DATA
) != value
) {
4351 outb(value
, (portp
->ioaddr
+ XP_DATA
));
4357 /*****************************************************************************/
4360 * Functions to get and set the sc26198 global registers.
4363 static int stl_sc26198getglobreg(stlport_t
*portp
, int regnr
)
4365 outb(regnr
, (portp
->ioaddr
+ XP_ADDR
));
4366 return(inb(portp
->ioaddr
+ XP_DATA
));
4370 static void stl_sc26198setglobreg(stlport_t
*portp
, int regnr
, int value
)
4372 outb(regnr
, (portp
->ioaddr
+ XP_ADDR
));
4373 outb(value
, (portp
->ioaddr
+ XP_DATA
));
4377 /*****************************************************************************/
4380 * Inbitialize the UARTs in a panel. We don't care what sort of board
4381 * these ports are on - since the port io registers are almost
4382 * identical when dealing with ports.
4385 static int stl_sc26198panelinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
)
4388 int nrchips
, ioaddr
;
4391 printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
4392 (int) brdp
, (int) panelp
);
4395 BRDENABLE(panelp
->brdnr
, panelp
->pagenr
);
4398 * Check that each chip is present and started up OK.
4401 nrchips
= (panelp
->nrports
+ 4) / SC26198_PORTS
;
4402 if (brdp
->brdtype
== BRD_ECHPCI
)
4403 outb(panelp
->pagenr
, brdp
->ioctrl
);
4405 for (i
= 0; (i
< nrchips
); i
++) {
4406 ioaddr
= panelp
->iobase
+ (i
* 4);
4407 outb(SCCR
, (ioaddr
+ XP_ADDR
));
4408 outb(CR_RESETALL
, (ioaddr
+ XP_DATA
));
4409 outb(TSTR
, (ioaddr
+ XP_ADDR
));
4410 if (inb(ioaddr
+ XP_DATA
) != 0) {
4411 printk("STALLION: sc26198 not responding, "
4412 "brd=%d panel=%d chip=%d\n",
4413 panelp
->brdnr
, panelp
->panelnr
, i
);
4416 chipmask
|= (0x1 << i
);
4417 outb(GCCR
, (ioaddr
+ XP_ADDR
));
4418 outb(GCCR_IVRTYPCHANACK
, (ioaddr
+ XP_DATA
));
4419 outb(WDTRCR
, (ioaddr
+ XP_ADDR
));
4420 outb(0xff, (ioaddr
+ XP_DATA
));
4423 BRDDISABLE(panelp
->brdnr
);
4427 /*****************************************************************************/
4430 * Initialize hardware specific port registers.
4433 static void stl_sc26198portinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
)
4436 printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
4437 (int) brdp
, (int) panelp
, (int) portp
);
4440 if ((brdp
== (stlbrd_t
*) NULL
) || (panelp
== (stlpanel_t
*) NULL
) ||
4441 (portp
== (stlport_t
*) NULL
))
4444 portp
->ioaddr
= panelp
->iobase
+ ((portp
->portnr
< 8) ? 0 : 4);
4445 portp
->uartaddr
= (portp
->portnr
& 0x07) << 4;
4446 portp
->pagenr
= panelp
->pagenr
;
4449 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4450 stl_sc26198setreg(portp
, IOPCR
, IOPCR_SETSIGS
);
4451 BRDDISABLE(portp
->brdnr
);
4454 /*****************************************************************************/
4457 * Set up the sc26198 registers for a port based on the termios port
4461 static void stl_sc26198setport(stlport_t
*portp
, struct termios
*tiosp
)
4464 unsigned long flags
;
4465 unsigned int baudrate
;
4466 unsigned char mr0
, mr1
, mr2
, clk
;
4467 unsigned char imron
, imroff
, iopr
, ipr
;
4477 brdp
= stl_brds
[portp
->brdnr
];
4478 if (brdp
== (stlbrd_t
*) NULL
)
4482 * Set up the RX char ignore mask with those RX error types we
4485 portp
->rxignoremsk
= 0;
4486 if (tiosp
->c_iflag
& IGNPAR
)
4487 portp
->rxignoremsk
|= (SR_RXPARITY
| SR_RXFRAMING
|
4489 if (tiosp
->c_iflag
& IGNBRK
)
4490 portp
->rxignoremsk
|= SR_RXBREAK
;
4492 portp
->rxmarkmsk
= SR_RXOVERRUN
;
4493 if (tiosp
->c_iflag
& (INPCK
| PARMRK
))
4494 portp
->rxmarkmsk
|= (SR_RXPARITY
| SR_RXFRAMING
);
4495 if (tiosp
->c_iflag
& BRKINT
)
4496 portp
->rxmarkmsk
|= SR_RXBREAK
;
4499 * Go through the char size, parity and stop bits and set all the
4500 * option register appropriately.
4502 switch (tiosp
->c_cflag
& CSIZE
) {
4517 if (tiosp
->c_cflag
& CSTOPB
)
4522 if (tiosp
->c_cflag
& PARENB
) {
4523 if (tiosp
->c_cflag
& PARODD
)
4524 mr1
|= (MR1_PARENB
| MR1_PARODD
);
4526 mr1
|= (MR1_PARENB
| MR1_PAREVEN
);
4531 mr1
|= MR1_ERRBLOCK
;
4534 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4535 * space for hardware flow control and the like. This should be set to
4538 mr2
|= MR2_RXFIFOHALF
;
4541 * Calculate the baud rate timers. For now we will just assume that
4542 * the input and output baud are the same. The sc26198 has a fixed
4543 * baud rate table, so only discrete baud rates possible.
4545 baudrate
= tiosp
->c_cflag
& CBAUD
;
4546 if (baudrate
& CBAUDEX
) {
4547 baudrate
&= ~CBAUDEX
;
4548 if ((baudrate
< 1) || (baudrate
> 4))
4549 tiosp
->c_cflag
&= ~CBAUDEX
;
4553 baudrate
= stl_baudrates
[baudrate
];
4554 if ((tiosp
->c_cflag
& CBAUD
) == B38400
) {
4555 if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
4557 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
4559 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
4561 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
4563 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)
4564 baudrate
= (portp
->baud_base
/ portp
->custom_divisor
);
4566 if (baudrate
> STL_SC26198MAXBAUD
)
4567 baudrate
= STL_SC26198MAXBAUD
;
4570 for (clk
= 0; (clk
< SC26198_NRBAUDS
); clk
++) {
4571 if (baudrate
<= sc26198_baudtable
[clk
])
4577 * Check what form of modem signaling is required and set it up.
4579 if (tiosp
->c_cflag
& CLOCAL
) {
4580 portp
->flags
&= ~ASYNC_CHECK_CD
;
4582 iopr
|= IOPR_DCDCOS
;
4584 portp
->flags
|= ASYNC_CHECK_CD
;
4588 * Setup sc26198 enhanced modes if we can. In particular we want to
4589 * handle as much of the flow control as possible automatically. As
4590 * well as saving a few CPU cycles it will also greatly improve flow
4591 * control reliability.
4593 if (tiosp
->c_iflag
& IXON
) {
4594 mr0
|= MR0_SWFTX
| MR0_SWFT
;
4595 imron
|= IR_XONXOFF
;
4597 imroff
|= IR_XONXOFF
;
4599 if (tiosp
->c_iflag
& IXOFF
)
4602 if (tiosp
->c_cflag
& CRTSCTS
) {
4608 * All sc26198 register values calculated so go through and set
4613 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4614 portp
->portnr
, portp
->panelnr
, portp
->brdnr
);
4615 printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0
, mr1
, mr2
, clk
);
4616 printk(" iopr=%x imron=%x imroff=%x\n", iopr
, imron
, imroff
);
4617 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4618 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
],
4619 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
]);
4624 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4625 stl_sc26198setreg(portp
, IMR
, 0);
4626 stl_sc26198updatereg(portp
, MR0
, mr0
);
4627 stl_sc26198updatereg(portp
, MR1
, mr1
);
4628 stl_sc26198setreg(portp
, SCCR
, CR_RXERRBLOCK
);
4629 stl_sc26198updatereg(portp
, MR2
, mr2
);
4630 stl_sc26198updatereg(portp
, IOPIOR
,
4631 ((stl_sc26198getreg(portp
, IOPIOR
) & ~IPR_CHANGEMASK
) | iopr
));
4634 stl_sc26198setreg(portp
, TXCSR
, clk
);
4635 stl_sc26198setreg(portp
, RXCSR
, clk
);
4638 stl_sc26198setreg(portp
, XONCR
, tiosp
->c_cc
[VSTART
]);
4639 stl_sc26198setreg(portp
, XOFFCR
, tiosp
->c_cc
[VSTOP
]);
4641 ipr
= stl_sc26198getreg(portp
, IPR
);
4643 portp
->sigs
&= ~TIOCM_CD
;
4645 portp
->sigs
|= TIOCM_CD
;
4647 portp
->imr
= (portp
->imr
& ~imroff
) | imron
;
4648 stl_sc26198setreg(portp
, IMR
, portp
->imr
);
4649 BRDDISABLE(portp
->brdnr
);
4650 restore_flags(flags
);
4653 /*****************************************************************************/
4656 * Set the state of the DTR and RTS signals.
4659 static void stl_sc26198setsignals(stlport_t
*portp
, int dtr
, int rts
)
4661 unsigned char iopioron
, iopioroff
;
4662 unsigned long flags
;
4665 printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4666 (int) portp
, dtr
, rts
);
4672 iopioroff
|= IPR_DTR
;
4674 iopioron
|= IPR_DTR
;
4676 iopioroff
|= IPR_RTS
;
4678 iopioron
|= IPR_RTS
;
4682 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4683 stl_sc26198setreg(portp
, IOPIOR
,
4684 ((stl_sc26198getreg(portp
, IOPIOR
) & ~iopioroff
) | iopioron
));
4685 BRDDISABLE(portp
->brdnr
);
4686 restore_flags(flags
);
4689 /*****************************************************************************/
4692 * Return the state of the signals.
4695 static int stl_sc26198getsignals(stlport_t
*portp
)
4698 unsigned long flags
;
4702 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp
);
4707 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4708 ipr
= stl_sc26198getreg(portp
, IPR
);
4709 BRDDISABLE(portp
->brdnr
);
4710 restore_flags(flags
);
4713 sigs
|= (ipr
& IPR_DCD
) ? 0 : TIOCM_CD
;
4714 sigs
|= (ipr
& IPR_CTS
) ? 0 : TIOCM_CTS
;
4715 sigs
|= (ipr
& IPR_DTR
) ? 0: TIOCM_DTR
;
4716 sigs
|= (ipr
& IPR_RTS
) ? 0: TIOCM_RTS
;
4721 /*****************************************************************************/
4724 * Enable/Disable the Transmitter and/or Receiver.
4727 static void stl_sc26198enablerxtx(stlport_t
*portp
, int rx
, int tx
)
4730 unsigned long flags
;
4733 printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4734 (int) portp
, rx
, tx
);
4737 ccr
= portp
->crenable
;
4739 ccr
&= ~CR_TXENABLE
;
4743 ccr
&= ~CR_RXENABLE
;
4749 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4750 stl_sc26198setreg(portp
, SCCR
, ccr
);
4751 BRDDISABLE(portp
->brdnr
);
4752 portp
->crenable
= ccr
;
4753 restore_flags(flags
);
4756 /*****************************************************************************/
4759 * Start/stop the Transmitter and/or Receiver.
4762 static void stl_sc26198startrxtx(stlport_t
*portp
, int rx
, int tx
)
4765 unsigned long flags
;
4768 printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4769 (int) portp
, rx
, tx
);
4778 imr
&= ~(IR_RXRDY
| IR_RXBREAK
| IR_RXWATCHDOG
);
4780 imr
|= IR_RXRDY
| IR_RXBREAK
| IR_RXWATCHDOG
;
4784 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4785 stl_sc26198setreg(portp
, IMR
, imr
);
4786 BRDDISABLE(portp
->brdnr
);
4789 set_bit(ASYI_TXBUSY
, &portp
->istate
);
4790 restore_flags(flags
);
4793 /*****************************************************************************/
4796 * Disable all interrupts from this port.
4799 static void stl_sc26198disableintrs(stlport_t
*portp
)
4801 unsigned long flags
;
4804 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp
);
4809 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4811 stl_sc26198setreg(portp
, IMR
, 0);
4812 BRDDISABLE(portp
->brdnr
);
4813 restore_flags(flags
);
4816 /*****************************************************************************/
4818 static void stl_sc26198sendbreak(stlport_t
*portp
, int len
)
4820 unsigned long flags
;
4823 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp
, len
);
4828 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4830 stl_sc26198setreg(portp
, SCCR
, CR_TXSTARTBREAK
);
4831 portp
->stats
.txbreaks
++;
4833 stl_sc26198setreg(portp
, SCCR
, CR_TXSTOPBREAK
);
4835 BRDDISABLE(portp
->brdnr
);
4836 restore_flags(flags
);
4839 /*****************************************************************************/
4842 * Take flow control actions...
4845 static void stl_sc26198flowctrl(stlport_t
*portp
, int state
)
4847 struct tty_struct
*tty
;
4848 unsigned long flags
;
4852 printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp
, state
);
4855 if (portp
== (stlport_t
*) NULL
)
4858 if (tty
== (struct tty_struct
*) NULL
)
4863 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4866 if (tty
->termios
->c_iflag
& IXOFF
) {
4867 mr0
= stl_sc26198getreg(portp
, MR0
);
4868 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4869 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXON
);
4871 portp
->stats
.rxxon
++;
4872 stl_sc26198wait(portp
);
4873 stl_sc26198setreg(portp
, MR0
, mr0
);
4876 * Question: should we return RTS to what it was before? It may
4877 * have been set by an ioctl... Suppose not, since if you have
4878 * hardware flow control set then it is pretty silly to go and
4879 * set the RTS line by hand.
4881 if (tty
->termios
->c_cflag
& CRTSCTS
) {
4882 stl_sc26198setreg(portp
, MR1
,
4883 (stl_sc26198getreg(portp
, MR1
) | MR1_AUTORTS
));
4884 stl_sc26198setreg(portp
, IOPIOR
,
4885 (stl_sc26198getreg(portp
, IOPIOR
) | IOPR_RTS
));
4886 portp
->stats
.rxrtson
++;
4889 if (tty
->termios
->c_iflag
& IXOFF
) {
4890 mr0
= stl_sc26198getreg(portp
, MR0
);
4891 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4892 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXOFF
);
4894 portp
->stats
.rxxoff
++;
4895 stl_sc26198wait(portp
);
4896 stl_sc26198setreg(portp
, MR0
, mr0
);
4898 if (tty
->termios
->c_cflag
& CRTSCTS
) {
4899 stl_sc26198setreg(portp
, MR1
,
4900 (stl_sc26198getreg(portp
, MR1
) & ~MR1_AUTORTS
));
4901 stl_sc26198setreg(portp
, IOPIOR
,
4902 (stl_sc26198getreg(portp
, IOPIOR
) & ~IOPR_RTS
));
4903 portp
->stats
.rxrtsoff
++;
4907 BRDDISABLE(portp
->brdnr
);
4908 restore_flags(flags
);
4911 /*****************************************************************************/
4914 * Send a flow control character.
4917 static void stl_sc26198sendflow(stlport_t
*portp
, int state
)
4919 struct tty_struct
*tty
;
4920 unsigned long flags
;
4924 printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp
, state
);
4927 if (portp
== (stlport_t
*) NULL
)
4930 if (tty
== (struct tty_struct
*) NULL
)
4935 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4937 mr0
= stl_sc26198getreg(portp
, MR0
);
4938 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4939 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXON
);
4941 portp
->stats
.rxxon
++;
4942 stl_sc26198wait(portp
);
4943 stl_sc26198setreg(portp
, MR0
, mr0
);
4945 mr0
= stl_sc26198getreg(portp
, MR0
);
4946 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4947 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXOFF
);
4949 portp
->stats
.rxxoff
++;
4950 stl_sc26198wait(portp
);
4951 stl_sc26198setreg(portp
, MR0
, mr0
);
4953 BRDDISABLE(portp
->brdnr
);
4954 restore_flags(flags
);
4957 /*****************************************************************************/
4959 static void stl_sc26198flush(stlport_t
*portp
)
4961 unsigned long flags
;
4964 printk("stl_sc26198flush(portp=%x)\n", (int) portp
);
4967 if (portp
== (stlport_t
*) NULL
)
4972 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4973 stl_sc26198setreg(portp
, SCCR
, CR_TXRESET
);
4974 stl_sc26198setreg(portp
, SCCR
, portp
->crenable
);
4975 BRDDISABLE(portp
->brdnr
);
4976 portp
->tx
.tail
= portp
->tx
.head
;
4977 restore_flags(flags
);
4980 /*****************************************************************************/
4983 * Return the current state of data flow on this port. This is only
4984 * really interresting when determining if data has fully completed
4985 * transmission or not... The sc26198 interrupt scheme cannot
4986 * determine when all data has actually drained, so we need to
4987 * check the port statusy register to be sure.
4990 static int stl_sc26198datastate(stlport_t
*portp
)
4992 unsigned long flags
;
4996 printk("stl_sc26198datastate(portp=%x)\n", (int) portp
);
4999 if (portp
== (stlport_t
*) NULL
)
5001 if (test_bit(ASYI_TXBUSY
, &portp
->istate
))
5006 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
5007 sr
= stl_sc26198getreg(portp
, SR
);
5008 BRDDISABLE(portp
->brdnr
);
5009 restore_flags(flags
);
5011 return((sr
& SR_TXEMPTY
) ? 0 : 1);
5014 /*****************************************************************************/
5017 * Delay for a small amount of time, to give the sc26198 a chance
5018 * to process a command...
5021 static void stl_sc26198wait(stlport_t
*portp
)
5026 printk("stl_sc26198wait(portp=%x)\n", (int) portp
);
5029 if (portp
== (stlport_t
*) NULL
)
5032 for (i
= 0; (i
< 20); i
++)
5033 stl_sc26198getglobreg(portp
, TSTR
);
5036 /*****************************************************************************/
5039 * If we are TX flow controlled and in IXANY mode then we may
5040 * need to unflow control here. We gotta do this because of the
5041 * automatic flow control modes of the sc26198.
5044 static inline void stl_sc26198txunflow(stlport_t
*portp
, struct tty_struct
*tty
)
5048 mr0
= stl_sc26198getreg(portp
, MR0
);
5049 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
5050 stl_sc26198setreg(portp
, SCCR
, CR_HOSTXON
);
5051 stl_sc26198wait(portp
);
5052 stl_sc26198setreg(portp
, MR0
, mr0
);
5053 clear_bit(ASYI_TXFLOWED
, &portp
->istate
);
5056 /*****************************************************************************/
5059 * Interrupt service routine for sc26198 panels.
5062 static void stl_sc26198intr(stlpanel_t
*panelp
, unsigned int iobase
)
5068 * Work around bug in sc26198 chip... Cannot have A6 address
5069 * line of UART high, else iack will be returned as 0.
5071 outb(0, (iobase
+ 1));
5073 iack
= inb(iobase
+ XP_IACK
);
5074 portp
= panelp
->ports
[(iack
& IVR_CHANMASK
) + ((iobase
& 0x4) << 1)];
5076 if (iack
& IVR_RXDATA
)
5077 stl_sc26198rxisr(portp
, iack
);
5078 else if (iack
& IVR_TXDATA
)
5079 stl_sc26198txisr(portp
);
5081 stl_sc26198otherisr(portp
, iack
);
5084 /*****************************************************************************/
5087 * Transmit interrupt handler. This has gotta be fast! Handling TX
5088 * chars is pretty simple, stuff as many as possible from the TX buffer
5089 * into the sc26198 FIFO.
5090 * In practice it is possible that interrupts are enabled but that the
5091 * port has been hung up. Need to handle not having any TX buffer here,
5092 * this is done by using the side effect that head and tail will also
5093 * be NULL if the buffer has been freed.
5096 static void stl_sc26198txisr(stlport_t
*portp
)
5098 unsigned int ioaddr
;
5104 printk("stl_sc26198txisr(portp=%x)\n", (int) portp
);
5107 ioaddr
= portp
->ioaddr
;
5108 head
= portp
->tx
.head
;
5109 tail
= portp
->tx
.tail
;
5110 len
= (head
>= tail
) ? (head
- tail
) : (STL_TXBUFSIZE
- (tail
- head
));
5111 if ((len
== 0) || ((len
< STL_TXBUFLOW
) &&
5112 (test_bit(ASYI_TXLOW
, &portp
->istate
) == 0))) {
5113 set_bit(ASYI_TXLOW
, &portp
->istate
);
5114 queue_task(&portp
->tqueue
, &tq_scheduler
);
5118 outb((MR0
| portp
->uartaddr
), (ioaddr
+ XP_ADDR
));
5119 mr0
= inb(ioaddr
+ XP_DATA
);
5120 if ((mr0
& MR0_TXMASK
) == MR0_TXEMPTY
) {
5121 portp
->imr
&= ~IR_TXRDY
;
5122 outb((IMR
| portp
->uartaddr
), (ioaddr
+ XP_ADDR
));
5123 outb(portp
->imr
, (ioaddr
+ XP_DATA
));
5124 clear_bit(ASYI_TXBUSY
, &portp
->istate
);
5126 mr0
|= ((mr0
& ~MR0_TXMASK
) | MR0_TXEMPTY
);
5127 outb(mr0
, (ioaddr
+ XP_DATA
));
5130 len
= MIN(len
, SC26198_TXFIFOSIZE
);
5131 portp
->stats
.txtotal
+= len
;
5132 stlen
= MIN(len
, ((portp
->tx
.buf
+ STL_TXBUFSIZE
) - tail
));
5133 outb(GTXFIFO
, (ioaddr
+ XP_ADDR
));
5134 outsb((ioaddr
+ XP_DATA
), tail
, stlen
);
5137 if (tail
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
))
5138 tail
= portp
->tx
.buf
;
5140 outsb((ioaddr
+ XP_DATA
), tail
, len
);
5143 portp
->tx
.tail
= tail
;
5147 /*****************************************************************************/
5150 * Receive character interrupt handler. Determine if we have good chars
5151 * or bad chars and then process appropriately. Good chars are easy
5152 * just shove the lot into the RX buffer and set all status byte to 0.
5153 * If a bad RX char then process as required. This routine needs to be
5154 * fast! In practice it is possible that we get an interrupt on a port
5155 * that is closed. This can happen on hangups - since they completely
5156 * shutdown a port not in user context. Need to handle this case.
5159 static void stl_sc26198rxisr(stlport_t
*portp
, unsigned int iack
)
5161 struct tty_struct
*tty
;
5162 unsigned int len
, buflen
, ioaddr
;
5165 printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp
, iack
);
5169 ioaddr
= portp
->ioaddr
;
5170 outb(GIBCR
, (ioaddr
+ XP_ADDR
));
5171 len
= inb(ioaddr
+ XP_DATA
) + 1;
5173 if ((iack
& IVR_TYPEMASK
) == IVR_RXDATA
) {
5174 if ((tty
== (struct tty_struct
*) NULL
) ||
5175 (tty
->flip
.char_buf_ptr
== (char *) NULL
) ||
5176 ((buflen
= TTY_FLIPBUF_SIZE
- tty
->flip
.count
) == 0)) {
5177 outb(GRXFIFO
, (ioaddr
+ XP_ADDR
));
5178 insb((ioaddr
+ XP_DATA
), &stl_unwanted
[0], len
);
5179 portp
->stats
.rxlost
+= len
;
5180 portp
->stats
.rxtotal
+= len
;
5182 len
= MIN(len
, buflen
);
5184 outb(GRXFIFO
, (ioaddr
+ XP_ADDR
));
5185 insb((ioaddr
+ XP_DATA
), tty
->flip
.char_buf_ptr
, len
);
5186 memset(tty
->flip
.flag_buf_ptr
, 0, len
);
5187 tty
->flip
.flag_buf_ptr
+= len
;
5188 tty
->flip
.char_buf_ptr
+= len
;
5189 tty
->flip
.count
+= len
;
5190 tty_schedule_flip(tty
);
5191 portp
->stats
.rxtotal
+= len
;
5195 stl_sc26198rxbadchars(portp
);
5199 * If we are TX flow controlled and in IXANY mode then we may need
5200 * to unflow control here. We gotta do this because of the automatic
5201 * flow control modes of the sc26198.
5203 if (test_bit(ASYI_TXFLOWED
, &portp
->istate
)) {
5204 if ((tty
!= (struct tty_struct
*) NULL
) &&
5205 (tty
->termios
!= (struct termios
*) NULL
) &&
5206 (tty
->termios
->c_iflag
& IXANY
)) {
5207 stl_sc26198txunflow(portp
, tty
);
5212 /*****************************************************************************/
5215 * Process an RX bad character.
5218 static void inline stl_sc26198rxbadch(stlport_t
*portp
, unsigned char status
, char ch
)
5220 struct tty_struct
*tty
;
5221 unsigned int ioaddr
;
5224 ioaddr
= portp
->ioaddr
;
5226 if (status
& SR_RXPARITY
)
5227 portp
->stats
.rxparity
++;
5228 if (status
& SR_RXFRAMING
)
5229 portp
->stats
.rxframing
++;
5230 if (status
& SR_RXOVERRUN
)
5231 portp
->stats
.rxoverrun
++;
5232 if (status
& SR_RXBREAK
)
5233 portp
->stats
.rxbreaks
++;
5235 if ((tty
!= (struct tty_struct
*) NULL
) &&
5236 ((portp
->rxignoremsk
& status
) == 0)) {
5237 if (portp
->rxmarkmsk
& status
) {
5238 if (status
& SR_RXBREAK
) {
5240 if (portp
->flags
& ASYNC_SAK
) {
5242 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
5244 } else if (status
& SR_RXPARITY
) {
5245 status
= TTY_PARITY
;
5246 } else if (status
& SR_RXFRAMING
) {
5248 } else if(status
& SR_RXOVERRUN
) {
5249 status
= TTY_OVERRUN
;
5257 if (tty
->flip
.char_buf_ptr
!= (char *) NULL
) {
5258 if (tty
->flip
.count
< TTY_FLIPBUF_SIZE
) {
5259 *tty
->flip
.flag_buf_ptr
++ = status
;
5260 *tty
->flip
.char_buf_ptr
++ = ch
;
5263 tty_schedule_flip(tty
);
5267 portp
->stats
.rxtotal
++;
5271 /*****************************************************************************/
5274 * Process all characters in the RX FIFO of the UART. Check all char
5275 * status bytes as well, and process as required. We need to check
5276 * all bytes in the FIFO, in case some more enter the FIFO while we
5277 * are here. To get the exact character error type we need to switch
5278 * into CHAR error mode (that is why we need to make sure we empty
5282 static void stl_sc26198rxbadchars(stlport_t
*portp
)
5284 unsigned char status
, mr1
;
5288 * To get the precise error type for each character we must switch
5289 * back into CHAR error mode.
5291 mr1
= stl_sc26198getreg(portp
, MR1
);
5292 stl_sc26198setreg(portp
, MR1
, (mr1
& ~MR1_ERRBLOCK
));
5294 while ((status
= stl_sc26198getreg(portp
, SR
)) & SR_RXRDY
) {
5295 stl_sc26198setreg(portp
, SCCR
, CR_CLEARRXERR
);
5296 ch
= stl_sc26198getreg(portp
, RXFIFO
);
5297 stl_sc26198rxbadch(portp
, status
, ch
);
5301 * To get correct interrupt class we must switch back into BLOCK
5304 stl_sc26198setreg(portp
, MR1
, mr1
);
5307 /*****************************************************************************/
5310 * Other interrupt handler. This includes modem signals, flow
5311 * control actions, etc. Most stuff is left to off-level interrupt
5315 static void stl_sc26198otherisr(stlport_t
*portp
, unsigned int iack
)
5317 unsigned char cir
, ipr
, xisr
;
5320 printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp
, iack
);
5323 cir
= stl_sc26198getglobreg(portp
, CIR
);
5325 switch (cir
& CIR_SUBTYPEMASK
) {
5327 ipr
= stl_sc26198getreg(portp
, IPR
);
5328 if (ipr
& IPR_DCDCHANGE
) {
5329 set_bit(ASYI_DCDCHANGE
, &portp
->istate
);
5330 queue_task(&portp
->tqueue
, &tq_scheduler
);
5331 portp
->stats
.modem
++;
5334 case CIR_SUBXONXOFF
:
5335 xisr
= stl_sc26198getreg(portp
, XISR
);
5336 if (xisr
& XISR_RXXONGOT
) {
5337 set_bit(ASYI_TXFLOWED
, &portp
->istate
);
5338 portp
->stats
.txxoff
++;
5340 if (xisr
& XISR_RXXOFFGOT
) {
5341 clear_bit(ASYI_TXFLOWED
, &portp
->istate
);
5342 portp
->stats
.txxon
++;
5346 stl_sc26198setreg(portp
, SCCR
, CR_BREAKRESET
);
5347 stl_sc26198rxbadchars(portp
);
5354 /*****************************************************************************/