Portability cleanup as required by Linus.
[linux-2.6/linux-mips.git] / drivers / char / stallion.c
blob9600c1bad455bdb4dc6c2a4fa20ceeb453003900
1 /*****************************************************************************/
3 /*
4 * stallion.c -- stallion multiport serial driver.
6 * Copyright (C) 1996-1999 Stallion Technologies (support@stallion.oz.au).
7 * Copyright (C) 1994-1996 Greg Ungerer.
9 * This code is loosely based on the Linux serial driver, written by
10 * Linus Torvalds, Theodore T'so and others.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /*****************************************************************************/
29 #include <linux/config.h>
30 #include <linux/module.h>
31 #include <linux/version.h> /* for linux/stallion.h */
32 #include <linux/malloc.h>
33 #include <linux/interrupt.h>
34 #include <linux/tty_flip.h>
35 #include <linux/serial.h>
36 #include <linux/cd1400.h>
37 #include <linux/sc26198.h>
38 #include <linux/comstats.h>
39 #include <linux/stallion.h>
40 #include <linux/ioport.h>
41 #include <linux/init.h>
42 #include <linux/smp_lock.h>
43 #include <linux/devfs_fs_kernel.h>
45 #include <asm/io.h>
46 #include <asm/uaccess.h>
48 #ifdef CONFIG_PCI
49 #include <linux/pci.h>
50 #endif
52 /*****************************************************************************/
55 * Define different board types. Use the standard Stallion "assigned"
56 * board numbers. Boards supported in this driver are abbreviated as
57 * EIO = EasyIO and ECH = EasyConnection 8/32.
59 #define BRD_EASYIO 20
60 #define BRD_ECH 21
61 #define BRD_ECHMC 22
62 #define BRD_ECHPCI 26
63 #define BRD_ECH64PCI 27
64 #define BRD_EASYIOPCI 28
67 * Define a configuration structure to hold the board configuration.
68 * Need to set this up in the code (for now) with the boards that are
69 * to be configured into the system. This is what needs to be modified
70 * when adding/removing/modifying boards. Each line entry in the
71 * stl_brdconf[] array is a board. Each line contains io/irq/memory
72 * ranges for that board (as well as what type of board it is).
73 * Some examples:
74 * { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
75 * This line would configure an EasyIO board (4 or 8, no difference),
76 * at io address 2a0 and irq 10.
77 * Another example:
78 * { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
79 * This line will configure an EasyConnection 8/32 board at primary io
80 * address 2a8, secondary io address 280 and irq 12.
81 * Enter as many lines into this array as you want (only the first 4
82 * will actually be used!). Any combination of EasyIO and EasyConnection
83 * boards can be specified. EasyConnection 8/32 boards can share their
84 * secondary io addresses between each other.
86 * NOTE: there is no need to put any entries in this table for PCI
87 * boards. They will be found automatically by the driver - provided
88 * PCI BIOS32 support is compiled into the kernel.
91 typedef struct {
92 int brdtype;
93 int ioaddr1;
94 int ioaddr2;
95 unsigned long memaddr;
96 int irq;
97 int irqtype;
98 } stlconf_t;
100 static stlconf_t stl_brdconf[] = {
101 /*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
104 static int stl_nrbrds = sizeof(stl_brdconf) / sizeof(stlconf_t);
106 /*****************************************************************************/
109 * Define some important driver characteristics. Device major numbers
110 * allocated as per Linux Device Registry.
112 #ifndef STL_SIOMEMMAJOR
113 #define STL_SIOMEMMAJOR 28
114 #endif
115 #ifndef STL_SERIALMAJOR
116 #define STL_SERIALMAJOR 24
117 #endif
118 #ifndef STL_CALLOUTMAJOR
119 #define STL_CALLOUTMAJOR 25
120 #endif
122 #define STL_DRVTYPSERIAL 1
123 #define STL_DRVTYPCALLOUT 2
126 * Set the TX buffer size. Bigger is better, but we don't want
127 * to chew too much memory with buffers!
129 #define STL_TXBUFLOW 512
130 #define STL_TXBUFSIZE 4096
132 /*****************************************************************************/
135 * Define our local driver identity first. Set up stuff to deal with
136 * all the local structures required by a serial tty driver.
138 static char *stl_drvtitle = "Stallion Multiport Serial Driver";
139 static char *stl_drvname = "stallion";
140 static char *stl_drvversion = "5.6.0";
141 static char *stl_serialname = "ttyE";
142 static char *stl_calloutname = "cue";
144 static struct tty_driver stl_serial;
145 static struct tty_driver stl_callout;
146 static struct tty_struct *stl_ttys[STL_MAXDEVS];
147 static struct termios *stl_termios[STL_MAXDEVS];
148 static struct termios *stl_termioslocked[STL_MAXDEVS];
149 static int stl_refcount = 0;
152 * We will need to allocate a temporary write buffer for chars that
153 * come direct from user space. The problem is that a copy from user
154 * space might cause a page fault (typically on a system that is
155 * swapping!). All ports will share one buffer - since if the system
156 * is already swapping a shared buffer won't make things any worse.
158 static char *stl_tmpwritebuf;
159 static DECLARE_MUTEX(stl_tmpwritesem);
162 * Define a local default termios struct. All ports will be created
163 * with this termios initially. Basically all it defines is a raw port
164 * at 9600, 8 data bits, 1 stop bit.
166 static struct termios stl_deftermios = {
169 (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
172 INIT_C_CC
176 * Define global stats structures. Not used often, and can be
177 * re-used for each stats call.
179 static comstats_t stl_comstats;
180 static combrd_t stl_brdstats;
181 static stlbrd_t stl_dummybrd;
182 static stlport_t stl_dummyport;
185 * Define global place to put buffer overflow characters.
187 static char stl_unwanted[SC26198_RXFIFOSIZE];
190 * Keep track of what interrupts we have requested for us.
191 * We don't need to request an interrupt twice if it is being
192 * shared with another Stallion board.
194 static int stl_gotintrs[STL_MAXBRDS];
195 static int stl_numintrs = 0;
197 /*****************************************************************************/
199 static stlbrd_t *stl_brds[STL_MAXBRDS];
202 * Per board state flags. Used with the state field of the board struct.
203 * Not really much here!
205 #define BRD_FOUND 0x1
208 * Define the port structure istate flags. These set of flags are
209 * modified at interrupt time - so setting and reseting them needs
210 * to be atomic. Use the bit clear/setting routines for this.
212 #define ASYI_TXBUSY 1
213 #define ASYI_TXLOW 2
214 #define ASYI_DCDCHANGE 3
215 #define ASYI_TXFLOWED 4
218 * Define an array of board names as printable strings. Handy for
219 * referencing boards when printing trace and stuff.
221 static char *stl_brdnames[] = {
222 (char *) NULL,
223 (char *) NULL,
224 (char *) NULL,
225 (char *) NULL,
226 (char *) NULL,
227 (char *) NULL,
228 (char *) NULL,
229 (char *) NULL,
230 (char *) NULL,
231 (char *) NULL,
232 (char *) NULL,
233 (char *) NULL,
234 (char *) NULL,
235 (char *) NULL,
236 (char *) NULL,
237 (char *) NULL,
238 (char *) NULL,
239 (char *) NULL,
240 (char *) NULL,
241 (char *) NULL,
242 "EasyIO",
243 "EC8/32-AT",
244 "EC8/32-MC",
245 (char *) NULL,
246 (char *) NULL,
247 (char *) NULL,
248 "EC8/32-PCI",
249 "EC8/64-PCI",
250 "EasyIO-PCI",
253 /*****************************************************************************/
255 #ifdef MODULE
257 * Define some string labels for arguments passed from the module
258 * load line. These allow for easy board definitions, and easy
259 * modification of the io, memory and irq resoucres.
262 static char *board0[4];
263 static char *board1[4];
264 static char *board2[4];
265 static char *board3[4];
267 static char **stl_brdsp[] = {
268 (char **) &board0,
269 (char **) &board1,
270 (char **) &board2,
271 (char **) &board3
275 * Define a set of common board names, and types. This is used to
276 * parse any module arguments.
279 typedef struct stlbrdtype {
280 char *name;
281 int type;
282 } stlbrdtype_t;
284 static stlbrdtype_t stl_brdstr[] = {
285 { "easyio", BRD_EASYIO },
286 { "eio", BRD_EASYIO },
287 { "20", BRD_EASYIO },
288 { "ec8/32", BRD_ECH },
289 { "ec8/32-at", BRD_ECH },
290 { "ec8/32-isa", BRD_ECH },
291 { "ech", BRD_ECH },
292 { "echat", BRD_ECH },
293 { "21", BRD_ECH },
294 { "ec8/32-mc", BRD_ECHMC },
295 { "ec8/32-mca", BRD_ECHMC },
296 { "echmc", BRD_ECHMC },
297 { "echmca", BRD_ECHMC },
298 { "22", BRD_ECHMC },
299 { "ec8/32-pc", BRD_ECHPCI },
300 { "ec8/32-pci", BRD_ECHPCI },
301 { "26", BRD_ECHPCI },
302 { "ec8/64-pc", BRD_ECH64PCI },
303 { "ec8/64-pci", BRD_ECH64PCI },
304 { "ech-pci", BRD_ECH64PCI },
305 { "echpci", BRD_ECH64PCI },
306 { "echpc", BRD_ECH64PCI },
307 { "27", BRD_ECH64PCI },
308 { "easyio-pc", BRD_EASYIOPCI },
309 { "easyio-pci", BRD_EASYIOPCI },
310 { "eio-pci", BRD_EASYIOPCI },
311 { "eiopci", BRD_EASYIOPCI },
312 { "28", BRD_EASYIOPCI },
316 * Define the module agruments.
318 MODULE_AUTHOR("Greg Ungerer");
319 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
321 MODULE_PARM(board0, "1-4s");
322 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
323 MODULE_PARM(board1, "1-4s");
324 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
325 MODULE_PARM(board2, "1-4s");
326 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
327 MODULE_PARM(board3, "1-4s");
328 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
330 #endif
332 /*****************************************************************************/
335 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
336 * to the directly accessible io ports of these boards (not the uarts -
337 * they are in cd1400.h and sc26198.h).
339 #define EIO_8PORTRS 0x04
340 #define EIO_4PORTRS 0x05
341 #define EIO_8PORTDI 0x00
342 #define EIO_8PORTM 0x06
343 #define EIO_MK3 0x03
344 #define EIO_IDBITMASK 0x07
346 #define EIO_BRDMASK 0xf0
347 #define ID_BRD4 0x10
348 #define ID_BRD8 0x20
349 #define ID_BRD16 0x30
351 #define EIO_INTRPEND 0x08
352 #define EIO_INTEDGE 0x00
353 #define EIO_INTLEVEL 0x08
354 #define EIO_0WS 0x10
356 #define ECH_ID 0xa0
357 #define ECH_IDBITMASK 0xe0
358 #define ECH_BRDENABLE 0x08
359 #define ECH_BRDDISABLE 0x00
360 #define ECH_INTENABLE 0x01
361 #define ECH_INTDISABLE 0x00
362 #define ECH_INTLEVEL 0x02
363 #define ECH_INTEDGE 0x00
364 #define ECH_INTRPEND 0x01
365 #define ECH_BRDRESET 0x01
367 #define ECHMC_INTENABLE 0x01
368 #define ECHMC_BRDRESET 0x02
370 #define ECH_PNLSTATUS 2
371 #define ECH_PNL16PORT 0x20
372 #define ECH_PNLIDMASK 0x07
373 #define ECH_PNLXPID 0x40
374 #define ECH_PNLINTRPEND 0x80
376 #define ECH_ADDR2MASK 0x1e0
379 * Define the vector mapping bits for the programmable interrupt board
380 * hardware. These bits encode the interrupt for the board to use - it
381 * is software selectable (except the EIO-8M).
383 static unsigned char stl_vecmap[] = {
384 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
385 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
389 * Set up enable and disable macros for the ECH boards. They require
390 * the secondary io address space to be activated and deactivated.
391 * This way all ECH boards can share their secondary io region.
392 * If this is an ECH-PCI board then also need to set the page pointer
393 * to point to the correct page.
395 #define BRDENABLE(brdnr,pagenr) \
396 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
397 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
398 stl_brds[(brdnr)]->ioctrl); \
399 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
400 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
402 #define BRDDISABLE(brdnr) \
403 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
404 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
405 stl_brds[(brdnr)]->ioctrl);
407 #define STL_CD1400MAXBAUD 230400
408 #define STL_SC26198MAXBAUD 460800
410 #define STL_BAUDBASE 115200
411 #define STL_CLOSEDELAY (5 * HZ / 10)
413 /*****************************************************************************/
415 #ifdef CONFIG_PCI
418 * Define the Stallion PCI vendor and device IDs.
420 #ifndef PCI_VENDOR_ID_STALLION
421 #define PCI_VENDOR_ID_STALLION 0x124d
422 #endif
423 #ifndef PCI_DEVICE_ID_ECHPCI832
424 #define PCI_DEVICE_ID_ECHPCI832 0x0000
425 #endif
426 #ifndef PCI_DEVICE_ID_ECHPCI864
427 #define PCI_DEVICE_ID_ECHPCI864 0x0002
428 #endif
429 #ifndef PCI_DEVICE_ID_EIOPCI
430 #define PCI_DEVICE_ID_EIOPCI 0x0003
431 #endif
434 * Define structure to hold all Stallion PCI boards.
436 typedef struct stlpcibrd {
437 unsigned short vendid;
438 unsigned short devid;
439 int brdtype;
440 } stlpcibrd_t;
442 static stlpcibrd_t stl_pcibrds[] = {
443 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864, BRD_ECH64PCI },
444 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI, BRD_EASYIOPCI },
445 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832, BRD_ECHPCI },
446 { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
449 static int stl_nrpcibrds = sizeof(stl_pcibrds) / sizeof(stlpcibrd_t);
451 #endif
453 /*****************************************************************************/
456 * Define macros to extract a brd/port number from a minor number.
458 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
459 #define MINOR2PORT(min) ((min) & 0x3f)
462 * Define a baud rate table that converts termios baud rate selector
463 * into the actual baud rate value. All baud rate calculations are
464 * based on the actual baud rate required.
466 static unsigned int stl_baudrates[] = {
467 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
468 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
472 * Define some handy local macros...
474 #undef MIN
475 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
477 #undef TOLOWER
478 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
480 /*****************************************************************************/
483 * Declare all those functions in this driver!
486 #ifdef MODULE
487 int init_module(void);
488 void cleanup_module(void);
489 static void stl_argbrds(void);
490 static int stl_parsebrd(stlconf_t *confp, char **argp);
492 static unsigned long stl_atol(char *str);
493 #endif
495 int stl_init(void);
496 static int stl_open(struct tty_struct *tty, struct file *filp);
497 static void stl_close(struct tty_struct *tty, struct file *filp);
498 static int stl_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count);
499 static void stl_putchar(struct tty_struct *tty, unsigned char ch);
500 static void stl_flushchars(struct tty_struct *tty);
501 static int stl_writeroom(struct tty_struct *tty);
502 static int stl_charsinbuffer(struct tty_struct *tty);
503 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
504 static void stl_settermios(struct tty_struct *tty, struct termios *old);
505 static void stl_throttle(struct tty_struct *tty);
506 static void stl_unthrottle(struct tty_struct *tty);
507 static void stl_stop(struct tty_struct *tty);
508 static void stl_start(struct tty_struct *tty);
509 static void stl_flushbuffer(struct tty_struct *tty);
510 static void stl_breakctl(struct tty_struct *tty, int state);
511 static void stl_waituntilsent(struct tty_struct *tty, int timeout);
512 static void stl_sendxchar(struct tty_struct *tty, char ch);
513 static void stl_hangup(struct tty_struct *tty);
514 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
515 static int stl_portinfo(stlport_t *portp, int portnr, char *pos);
516 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data);
518 static int stl_brdinit(stlbrd_t *brdp);
519 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
520 static int stl_mapirq(int irq, char *name);
521 static void stl_getserial(stlport_t *portp, struct serial_struct *sp);
522 static int stl_setserial(stlport_t *portp, struct serial_struct *sp);
523 static int stl_getbrdstats(combrd_t *bp);
524 static int stl_getportstats(stlport_t *portp, comstats_t *cp);
525 static int stl_clrportstats(stlport_t *portp, comstats_t *cp);
526 static int stl_getportstruct(unsigned long arg);
527 static int stl_getbrdstruct(unsigned long arg);
528 static int stl_waitcarrier(stlport_t *portp, struct file *filp);
529 static void stl_delay(int len);
530 static void stl_intr(int irq, void *dev_id, struct pt_regs *regs);
531 static void stl_eiointr(stlbrd_t *brdp);
532 static void stl_echatintr(stlbrd_t *brdp);
533 static void stl_echmcaintr(stlbrd_t *brdp);
534 static void stl_echpciintr(stlbrd_t *brdp);
535 static void stl_echpci64intr(stlbrd_t *brdp);
536 static void stl_offintr(void *private);
537 static void *stl_memalloc(int len);
538 static stlbrd_t *stl_allocbrd(void);
539 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
541 static inline int stl_initbrds(void);
542 static inline int stl_initeio(stlbrd_t *brdp);
543 static inline int stl_initech(stlbrd_t *brdp);
544 static inline int stl_getbrdnr(void);
546 #ifdef CONFIG_PCI
547 static inline int stl_findpcibrds(void);
548 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp);
549 #endif
552 * CD1400 uart specific handling functions.
554 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value);
555 static int stl_cd1400getreg(stlport_t *portp, int regnr);
556 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value);
557 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
558 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
559 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp);
560 static int stl_cd1400getsignals(stlport_t *portp);
561 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts);
562 static void stl_cd1400ccrwait(stlport_t *portp);
563 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx);
564 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx);
565 static void stl_cd1400disableintrs(stlport_t *portp);
566 static void stl_cd1400sendbreak(stlport_t *portp, int len);
567 static void stl_cd1400flowctrl(stlport_t *portp, int state);
568 static void stl_cd1400sendflow(stlport_t *portp, int state);
569 static void stl_cd1400flush(stlport_t *portp);
570 static int stl_cd1400datastate(stlport_t *portp);
571 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase);
572 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase);
573 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr);
574 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr);
575 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr);
577 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr);
580 * SC26198 uart specific handling functions.
582 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value);
583 static int stl_sc26198getreg(stlport_t *portp, int regnr);
584 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value);
585 static int stl_sc26198getglobreg(stlport_t *portp, int regnr);
586 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
587 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
588 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp);
589 static int stl_sc26198getsignals(stlport_t *portp);
590 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts);
591 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx);
592 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx);
593 static void stl_sc26198disableintrs(stlport_t *portp);
594 static void stl_sc26198sendbreak(stlport_t *portp, int len);
595 static void stl_sc26198flowctrl(stlport_t *portp, int state);
596 static void stl_sc26198sendflow(stlport_t *portp, int state);
597 static void stl_sc26198flush(stlport_t *portp);
598 static int stl_sc26198datastate(stlport_t *portp);
599 static void stl_sc26198wait(stlport_t *portp);
600 static void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty);
601 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase);
602 static void stl_sc26198txisr(stlport_t *port);
603 static void stl_sc26198rxisr(stlport_t *port, unsigned int iack);
604 static void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch);
605 static void stl_sc26198rxbadchars(stlport_t *portp);
606 static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
608 /*****************************************************************************/
611 * Generic UART support structure.
613 typedef struct uart {
614 int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp);
615 void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
616 void (*setport)(stlport_t *portp, struct termios *tiosp);
617 int (*getsignals)(stlport_t *portp);
618 void (*setsignals)(stlport_t *portp, int dtr, int rts);
619 void (*enablerxtx)(stlport_t *portp, int rx, int tx);
620 void (*startrxtx)(stlport_t *portp, int rx, int tx);
621 void (*disableintrs)(stlport_t *portp);
622 void (*sendbreak)(stlport_t *portp, int len);
623 void (*flowctrl)(stlport_t *portp, int state);
624 void (*sendflow)(stlport_t *portp, int state);
625 void (*flush)(stlport_t *portp);
626 int (*datastate)(stlport_t *portp);
627 void (*intr)(stlpanel_t *panelp, unsigned int iobase);
628 } uart_t;
631 * Define some macros to make calling these functions nice and clean.
633 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
634 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
635 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
636 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
637 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
638 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
639 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
640 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
641 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
642 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
643 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
644 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
645 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
647 /*****************************************************************************/
650 * CD1400 UART specific data initialization.
652 static uart_t stl_cd1400uart = {
653 stl_cd1400panelinit,
654 stl_cd1400portinit,
655 stl_cd1400setport,
656 stl_cd1400getsignals,
657 stl_cd1400setsignals,
658 stl_cd1400enablerxtx,
659 stl_cd1400startrxtx,
660 stl_cd1400disableintrs,
661 stl_cd1400sendbreak,
662 stl_cd1400flowctrl,
663 stl_cd1400sendflow,
664 stl_cd1400flush,
665 stl_cd1400datastate,
666 stl_cd1400eiointr
670 * Define the offsets within the register bank of a cd1400 based panel.
671 * These io address offsets are common to the EasyIO board as well.
673 #define EREG_ADDR 0
674 #define EREG_DATA 4
675 #define EREG_RXACK 5
676 #define EREG_TXACK 6
677 #define EREG_MDACK 7
679 #define EREG_BANKSIZE 8
681 #define CD1400_CLK 25000000
682 #define CD1400_CLK8M 20000000
685 * Define the cd1400 baud rate clocks. These are used when calculating
686 * what clock and divisor to use for the required baud rate. Also
687 * define the maximum baud rate allowed, and the default base baud.
689 static int stl_cd1400clkdivs[] = {
690 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
693 /*****************************************************************************/
696 * SC26198 UART specific data initization.
698 static uart_t stl_sc26198uart = {
699 stl_sc26198panelinit,
700 stl_sc26198portinit,
701 stl_sc26198setport,
702 stl_sc26198getsignals,
703 stl_sc26198setsignals,
704 stl_sc26198enablerxtx,
705 stl_sc26198startrxtx,
706 stl_sc26198disableintrs,
707 stl_sc26198sendbreak,
708 stl_sc26198flowctrl,
709 stl_sc26198sendflow,
710 stl_sc26198flush,
711 stl_sc26198datastate,
712 stl_sc26198intr
716 * Define the offsets within the register bank of a sc26198 based panel.
718 #define XP_DATA 0
719 #define XP_ADDR 1
720 #define XP_MODID 2
721 #define XP_STATUS 2
722 #define XP_IACK 3
724 #define XP_BANKSIZE 4
727 * Define the sc26198 baud rate table. Offsets within the table
728 * represent the actual baud rate selector of sc26198 registers.
730 static unsigned int sc26198_baudtable[] = {
731 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
732 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
733 230400, 460800, 921600
736 #define SC26198_NRBAUDS (sizeof(sc26198_baudtable) / sizeof(unsigned int))
738 /*****************************************************************************/
741 * Define the driver info for a user level control device. Used mainly
742 * to get at port stats - only not using the port device itself.
744 static struct file_operations stl_fsiomem = {
745 owner: THIS_MODULE,
746 ioctl: stl_memioctl,
749 /*****************************************************************************/
751 static devfs_handle_t devfs_handle = NULL;
753 #ifdef MODULE
756 * Loadable module initialization stuff.
759 int init_module()
761 unsigned long flags;
763 #if DEBUG
764 printk("init_module()\n");
765 #endif
767 save_flags(flags);
768 cli();
769 stl_init();
770 restore_flags(flags);
772 return(0);
775 /*****************************************************************************/
777 void cleanup_module()
779 stlbrd_t *brdp;
780 stlpanel_t *panelp;
781 stlport_t *portp;
782 unsigned long flags;
783 int i, j, k;
785 #if DEBUG
786 printk("cleanup_module()\n");
787 #endif
789 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
790 stl_drvversion);
792 save_flags(flags);
793 cli();
796 * Free up all allocated resources used by the ports. This includes
797 * memory and interrupts. As part of this process we will also do
798 * a hangup on every open port - to try to flush out any processes
799 * hanging onto ports.
801 i = tty_unregister_driver(&stl_serial);
802 j = tty_unregister_driver(&stl_callout);
803 if (i || j) {
804 printk("STALLION: failed to un-register tty driver, "
805 "errno=%d,%d\n", -i, -j);
806 restore_flags(flags);
807 return;
809 devfs_unregister (devfs_handle);
810 if ((i = devfs_unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
811 printk("STALLION: failed to un-register serial memory device, "
812 "errno=%d\n", -i);
814 if (stl_tmpwritebuf != (char *) NULL)
815 kfree_s(stl_tmpwritebuf, STL_TXBUFSIZE);
817 for (i = 0; (i < stl_nrbrds); i++) {
818 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
819 continue;
820 for (j = 0; (j < STL_MAXPANELS); j++) {
821 panelp = brdp->panels[j];
822 if (panelp == (stlpanel_t *) NULL)
823 continue;
824 for (k = 0; (k < STL_PORTSPERPANEL); k++) {
825 portp = panelp->ports[k];
826 if (portp == (stlport_t *) NULL)
827 continue;
828 if (portp->tty != (struct tty_struct *) NULL)
829 stl_hangup(portp->tty);
830 if (portp->tx.buf != (char *) NULL)
831 kfree_s(portp->tx.buf, STL_TXBUFSIZE);
832 kfree_s(portp, sizeof(stlport_t));
834 kfree_s(panelp, sizeof(stlpanel_t));
837 release_region(brdp->ioaddr1, brdp->iosize1);
838 if (brdp->iosize2 > 0)
839 release_region(brdp->ioaddr2, brdp->iosize2);
841 kfree_s(brdp, sizeof(stlbrd_t));
842 stl_brds[i] = (stlbrd_t *) NULL;
845 for (i = 0; (i < stl_numintrs); i++)
846 free_irq(stl_gotintrs[i], NULL);
848 restore_flags(flags);
851 /*****************************************************************************/
854 * Check for any arguments passed in on the module load command line.
857 static void stl_argbrds()
859 stlconf_t conf;
860 stlbrd_t *brdp;
861 int nrargs, i;
863 #if DEBUG
864 printk("stl_argbrds()\n");
865 #endif
867 nrargs = sizeof(stl_brdsp) / sizeof(char **);
869 for (i = stl_nrbrds; (i < nrargs); i++) {
870 memset(&conf, 0, sizeof(conf));
871 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
872 continue;
873 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
874 continue;
875 stl_nrbrds = i + 1;
876 brdp->brdnr = i;
877 brdp->brdtype = conf.brdtype;
878 brdp->ioaddr1 = conf.ioaddr1;
879 brdp->ioaddr2 = conf.ioaddr2;
880 brdp->irq = conf.irq;
881 brdp->irqtype = conf.irqtype;
882 stl_brdinit(brdp);
886 /*****************************************************************************/
889 * Convert an ascii string number into an unsigned long.
892 static unsigned long stl_atol(char *str)
894 unsigned long val;
895 int base, c;
896 char *sp;
898 val = 0;
899 sp = str;
900 if ((*sp == '0') && (*(sp+1) == 'x')) {
901 base = 16;
902 sp += 2;
903 } else if (*sp == '0') {
904 base = 8;
905 sp++;
906 } else {
907 base = 10;
910 for (; (*sp != 0); sp++) {
911 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
912 if ((c < 0) || (c >= base)) {
913 printk("STALLION: invalid argument %s\n", str);
914 val = 0;
915 break;
917 val = (val * base) + c;
919 return(val);
922 /*****************************************************************************/
925 * Parse the supplied argument string, into the board conf struct.
928 static int stl_parsebrd(stlconf_t *confp, char **argp)
930 char *sp;
931 int nrbrdnames, i;
933 #if DEBUG
934 printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
935 #endif
937 if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
938 return(0);
940 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
941 *sp = TOLOWER(*sp);
943 nrbrdnames = sizeof(stl_brdstr) / sizeof(stlbrdtype_t);
944 for (i = 0; (i < nrbrdnames); i++) {
945 if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
946 break;
948 if (i >= nrbrdnames) {
949 printk("STALLION: unknown board name, %s?\n", argp[0]);
950 return(0);
953 confp->brdtype = stl_brdstr[i].type;
955 i = 1;
956 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
957 confp->ioaddr1 = stl_atol(argp[i]);
958 i++;
959 if (confp->brdtype == BRD_ECH) {
960 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
961 confp->ioaddr2 = stl_atol(argp[i]);
962 i++;
964 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
965 confp->irq = stl_atol(argp[i]);
966 return(1);
969 #endif
971 /*****************************************************************************/
974 * Local driver kernel memory allocation routine.
977 static void *stl_memalloc(int len)
979 return((void *) kmalloc(len, GFP_KERNEL));
982 /*****************************************************************************/
985 * Allocate a new board structure. Fill out the basic info in it.
988 static stlbrd_t *stl_allocbrd()
990 stlbrd_t *brdp;
992 brdp = (stlbrd_t *) stl_memalloc(sizeof(stlbrd_t));
993 if (brdp == (stlbrd_t *) NULL) {
994 printk("STALLION: failed to allocate memory (size=%d)\n",
995 sizeof(stlbrd_t));
996 return((stlbrd_t *) NULL);
999 memset(brdp, 0, sizeof(stlbrd_t));
1000 brdp->magic = STL_BOARDMAGIC;
1001 return(brdp);
1004 /*****************************************************************************/
1006 static int stl_open(struct tty_struct *tty, struct file *filp)
1008 stlport_t *portp;
1009 stlbrd_t *brdp;
1010 unsigned int minordev;
1011 int brdnr, panelnr, portnr, rc;
1013 #if DEBUG
1014 printk("stl_open(tty=%x,filp=%x): device=%x\n", (int) tty,
1015 (int) filp, tty->device);
1016 #endif
1018 minordev = MINOR(tty->device);
1019 brdnr = MINOR2BRD(minordev);
1020 if (brdnr >= stl_nrbrds)
1021 return(-ENODEV);
1022 brdp = stl_brds[brdnr];
1023 if (brdp == (stlbrd_t *) NULL)
1024 return(-ENODEV);
1025 minordev = MINOR2PORT(minordev);
1026 for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
1027 if (brdp->panels[panelnr] == (stlpanel_t *) NULL)
1028 break;
1029 if (minordev < brdp->panels[panelnr]->nrports) {
1030 portnr = minordev;
1031 break;
1033 minordev -= brdp->panels[panelnr]->nrports;
1035 if (portnr < 0)
1036 return(-ENODEV);
1038 portp = brdp->panels[panelnr]->ports[portnr];
1039 if (portp == (stlport_t *) NULL)
1040 return(-ENODEV);
1042 MOD_INC_USE_COUNT;
1045 * On the first open of the device setup the port hardware, and
1046 * initialize the per port data structure.
1048 portp->tty = tty;
1049 tty->driver_data = portp;
1050 portp->refcount++;
1052 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
1053 if (portp->tx.buf == (char *) NULL) {
1054 portp->tx.buf = (char *) stl_memalloc(STL_TXBUFSIZE);
1055 if (portp->tx.buf == (char *) NULL)
1056 return(-ENOMEM);
1057 portp->tx.head = portp->tx.buf;
1058 portp->tx.tail = portp->tx.buf;
1060 stl_setport(portp, tty->termios);
1061 portp->sigs = stl_getsignals(portp);
1062 stl_setsignals(portp, 1, 1);
1063 stl_enablerxtx(portp, 1, 1);
1064 stl_startrxtx(portp, 1, 0);
1065 clear_bit(TTY_IO_ERROR, &tty->flags);
1066 portp->flags |= ASYNC_INITIALIZED;
1070 * Check if this port is in the middle of closing. If so then wait
1071 * until it is closed then return error status, based on flag settings.
1072 * The sleep here does not need interrupt protection since the wakeup
1073 * for it is done with the same context.
1075 if (portp->flags & ASYNC_CLOSING) {
1076 interruptible_sleep_on(&portp->close_wait);
1077 if (portp->flags & ASYNC_HUP_NOTIFY)
1078 return(-EAGAIN);
1079 return(-ERESTARTSYS);
1083 * Based on type of open being done check if it can overlap with any
1084 * previous opens still in effect. If we are a normal serial device
1085 * then also we might have to wait for carrier.
1087 if (tty->driver.subtype == STL_DRVTYPCALLOUT) {
1088 if (portp->flags & ASYNC_NORMAL_ACTIVE)
1089 return(-EBUSY);
1090 if (portp->flags & ASYNC_CALLOUT_ACTIVE) {
1091 if ((portp->flags & ASYNC_SESSION_LOCKOUT) &&
1092 (portp->session != current->session))
1093 return(-EBUSY);
1094 if ((portp->flags & ASYNC_PGRP_LOCKOUT) &&
1095 (portp->pgrp != current->pgrp))
1096 return(-EBUSY);
1098 portp->flags |= ASYNC_CALLOUT_ACTIVE;
1099 } else {
1100 if (filp->f_flags & O_NONBLOCK) {
1101 if (portp->flags & ASYNC_CALLOUT_ACTIVE)
1102 return(-EBUSY);
1103 } else {
1104 if ((rc = stl_waitcarrier(portp, filp)) != 0)
1105 return(rc);
1107 portp->flags |= ASYNC_NORMAL_ACTIVE;
1110 if ((portp->refcount == 1) && (portp->flags & ASYNC_SPLIT_TERMIOS)) {
1111 if (tty->driver.subtype == STL_DRVTYPSERIAL)
1112 *tty->termios = portp->normaltermios;
1113 else
1114 *tty->termios = portp->callouttermios;
1115 stl_setport(portp, tty->termios);
1118 portp->session = current->session;
1119 portp->pgrp = current->pgrp;
1120 return(0);
1123 /*****************************************************************************/
1126 * Possibly need to wait for carrier (DCD signal) to come high. Say
1127 * maybe because if we are clocal then we don't need to wait...
1130 static int stl_waitcarrier(stlport_t *portp, struct file *filp)
1132 unsigned long flags;
1133 int rc, doclocal;
1135 #if DEBUG
1136 printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp, (int) filp);
1137 #endif
1139 rc = 0;
1140 doclocal = 0;
1142 if (portp->flags & ASYNC_CALLOUT_ACTIVE) {
1143 if (portp->normaltermios.c_cflag & CLOCAL)
1144 doclocal++;
1145 } else {
1146 if (portp->tty->termios->c_cflag & CLOCAL)
1147 doclocal++;
1150 save_flags(flags);
1151 cli();
1152 portp->openwaitcnt++;
1153 if (! tty_hung_up_p(filp))
1154 portp->refcount--;
1156 for (;;) {
1157 if ((portp->flags & ASYNC_CALLOUT_ACTIVE) == 0)
1158 stl_setsignals(portp, 1, 1);
1159 if (tty_hung_up_p(filp) ||
1160 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1161 if (portp->flags & ASYNC_HUP_NOTIFY)
1162 rc = -EBUSY;
1163 else
1164 rc = -ERESTARTSYS;
1165 break;
1167 if (((portp->flags & ASYNC_CALLOUT_ACTIVE) == 0) &&
1168 ((portp->flags & ASYNC_CLOSING) == 0) &&
1169 (doclocal || (portp->sigs & TIOCM_CD))) {
1170 break;
1172 if (signal_pending(current)) {
1173 rc = -ERESTARTSYS;
1174 break;
1176 interruptible_sleep_on(&portp->open_wait);
1179 if (! tty_hung_up_p(filp))
1180 portp->refcount++;
1181 portp->openwaitcnt--;
1182 restore_flags(flags);
1184 return(rc);
1187 /*****************************************************************************/
1189 static void stl_close(struct tty_struct *tty, struct file *filp)
1191 stlport_t *portp;
1192 unsigned long flags;
1194 #if DEBUG
1195 printk("stl_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
1196 #endif
1198 portp = tty->driver_data;
1199 if (portp == (stlport_t *) NULL)
1200 return;
1202 save_flags(flags);
1203 cli();
1204 if (tty_hung_up_p(filp)) {
1205 MOD_DEC_USE_COUNT;
1206 restore_flags(flags);
1207 return;
1209 if ((tty->count == 1) && (portp->refcount != 1))
1210 portp->refcount = 1;
1211 if (portp->refcount-- > 1) {
1212 MOD_DEC_USE_COUNT;
1213 restore_flags(flags);
1214 return;
1217 portp->refcount = 0;
1218 portp->flags |= ASYNC_CLOSING;
1220 if (portp->flags & ASYNC_NORMAL_ACTIVE)
1221 portp->normaltermios = *tty->termios;
1222 if (portp->flags & ASYNC_CALLOUT_ACTIVE)
1223 portp->callouttermios = *tty->termios;
1226 * May want to wait for any data to drain before closing. The BUSY
1227 * flag keeps track of whether we are still sending or not - it is
1228 * very accurate for the cd1400, not quite so for the sc26198.
1229 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1231 tty->closing = 1;
1232 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1233 tty_wait_until_sent(tty, portp->closing_wait);
1234 stl_waituntilsent(tty, (HZ / 2));
1236 portp->flags &= ~ASYNC_INITIALIZED;
1237 stl_disableintrs(portp);
1238 if (tty->termios->c_cflag & HUPCL)
1239 stl_setsignals(portp, 0, 0);
1240 stl_enablerxtx(portp, 0, 0);
1241 stl_flushbuffer(tty);
1242 portp->istate = 0;
1243 if (portp->tx.buf != (char *) NULL) {
1244 kfree_s(portp->tx.buf, STL_TXBUFSIZE);
1245 portp->tx.buf = (char *) NULL;
1246 portp->tx.head = (char *) NULL;
1247 portp->tx.tail = (char *) NULL;
1249 set_bit(TTY_IO_ERROR, &tty->flags);
1250 if (tty->ldisc.flush_buffer)
1251 (tty->ldisc.flush_buffer)(tty);
1253 tty->closing = 0;
1254 portp->tty = (struct tty_struct *) NULL;
1256 if (portp->openwaitcnt) {
1257 if (portp->close_delay)
1258 stl_delay(portp->close_delay);
1259 wake_up_interruptible(&portp->open_wait);
1262 portp->flags &= ~(ASYNC_CALLOUT_ACTIVE | ASYNC_NORMAL_ACTIVE |
1263 ASYNC_CLOSING);
1264 wake_up_interruptible(&portp->close_wait);
1265 MOD_DEC_USE_COUNT;
1266 restore_flags(flags);
1269 /*****************************************************************************/
1272 * Wait for a specified delay period, this is not a busy-loop. It will
1273 * give up the processor while waiting. Unfortunately this has some
1274 * rather intimate knowledge of the process management stuff.
1277 static void stl_delay(int len)
1279 #if DEBUG
1280 printk("stl_delay(len=%d)\n", len);
1281 #endif
1282 if (len > 0) {
1283 current->state = TASK_INTERRUPTIBLE;
1284 schedule_timeout(len);
1285 current->state = TASK_RUNNING;
1289 /*****************************************************************************/
1292 * Write routine. Take data and stuff it in to the TX ring queue.
1293 * If transmit interrupts are not running then start them.
1296 static int stl_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count)
1298 stlport_t *portp;
1299 unsigned int len, stlen;
1300 unsigned char *chbuf;
1301 char *head, *tail;
1303 #if DEBUG
1304 printk("stl_write(tty=%x,from_user=%d,buf=%x,count=%d)\n",
1305 (int) tty, from_user, (int) buf, count);
1306 #endif
1308 if ((tty == (struct tty_struct *) NULL) ||
1309 (stl_tmpwritebuf == (char *) NULL))
1310 return(0);
1311 portp = tty->driver_data;
1312 if (portp == (stlport_t *) NULL)
1313 return(0);
1314 if (portp->tx.buf == (char *) NULL)
1315 return(0);
1318 * If copying direct from user space we must cater for page faults,
1319 * causing us to "sleep" here for a while. To handle this copy in all
1320 * the data we need now, into a local buffer. Then when we got it all
1321 * copy it into the TX buffer.
1323 chbuf = (unsigned char *) buf;
1324 if (from_user) {
1325 head = portp->tx.head;
1326 tail = portp->tx.tail;
1327 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) :
1328 (tail - head - 1);
1329 count = MIN(len, count);
1331 down(&stl_tmpwritesem);
1332 copy_from_user(stl_tmpwritebuf, chbuf, count);
1333 chbuf = &stl_tmpwritebuf[0];
1336 head = portp->tx.head;
1337 tail = portp->tx.tail;
1338 if (head >= tail) {
1339 len = STL_TXBUFSIZE - (head - tail) - 1;
1340 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
1341 } else {
1342 len = tail - head - 1;
1343 stlen = len;
1346 len = MIN(len, count);
1347 count = 0;
1348 while (len > 0) {
1349 stlen = MIN(len, stlen);
1350 memcpy(head, chbuf, stlen);
1351 len -= stlen;
1352 chbuf += stlen;
1353 count += stlen;
1354 head += stlen;
1355 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
1356 head = portp->tx.buf;
1357 stlen = tail - head;
1360 portp->tx.head = head;
1362 clear_bit(ASYI_TXLOW, &portp->istate);
1363 stl_startrxtx(portp, -1, 1);
1365 if (from_user)
1366 up(&stl_tmpwritesem);
1368 return(count);
1371 /*****************************************************************************/
1373 static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1375 stlport_t *portp;
1376 unsigned int len;
1377 char *head, *tail;
1379 #if DEBUG
1380 printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1381 #endif
1383 if (tty == (struct tty_struct *) NULL)
1384 return;
1385 portp = tty->driver_data;
1386 if (portp == (stlport_t *) NULL)
1387 return;
1388 if (portp->tx.buf == (char *) NULL)
1389 return;
1391 head = portp->tx.head;
1392 tail = portp->tx.tail;
1394 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
1395 len--;
1397 if (len > 0) {
1398 *head++ = ch;
1399 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
1400 head = portp->tx.buf;
1402 portp->tx.head = head;
1405 /*****************************************************************************/
1408 * If there are any characters in the buffer then make sure that TX
1409 * interrupts are on and get'em out. Normally used after the putchar
1410 * routine has been called.
1413 static void stl_flushchars(struct tty_struct *tty)
1415 stlport_t *portp;
1417 #if DEBUG
1418 printk("stl_flushchars(tty=%x)\n", (int) tty);
1419 #endif
1421 if (tty == (struct tty_struct *) NULL)
1422 return;
1423 portp = tty->driver_data;
1424 if (portp == (stlport_t *) NULL)
1425 return;
1426 if (portp->tx.buf == (char *) NULL)
1427 return;
1429 #if 0
1430 if (tty->stopped || tty->hw_stopped ||
1431 (portp->tx.head == portp->tx.tail))
1432 return;
1433 #endif
1434 stl_startrxtx(portp, -1, 1);
1437 /*****************************************************************************/
1439 static int stl_writeroom(struct tty_struct *tty)
1441 stlport_t *portp;
1442 char *head, *tail;
1444 #if DEBUG
1445 printk("stl_writeroom(tty=%x)\n", (int) tty);
1446 #endif
1448 if (tty == (struct tty_struct *) NULL)
1449 return(0);
1450 portp = tty->driver_data;
1451 if (portp == (stlport_t *) NULL)
1452 return(0);
1453 if (portp->tx.buf == (char *) NULL)
1454 return(0);
1456 head = portp->tx.head;
1457 tail = portp->tx.tail;
1458 return((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
1461 /*****************************************************************************/
1464 * Return number of chars in the TX buffer. Normally we would just
1465 * calculate the number of chars in the buffer and return that, but if
1466 * the buffer is empty and TX interrupts are still on then we return
1467 * that the buffer still has 1 char in it. This way whoever called us
1468 * will not think that ALL chars have drained - since the UART still
1469 * must have some chars in it (we are busy after all).
1472 static int stl_charsinbuffer(struct tty_struct *tty)
1474 stlport_t *portp;
1475 unsigned int size;
1476 char *head, *tail;
1478 #if DEBUG
1479 printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
1480 #endif
1482 if (tty == (struct tty_struct *) NULL)
1483 return(0);
1484 portp = tty->driver_data;
1485 if (portp == (stlport_t *) NULL)
1486 return(0);
1487 if (portp->tx.buf == (char *) NULL)
1488 return(0);
1490 head = portp->tx.head;
1491 tail = portp->tx.tail;
1492 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1493 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1494 size = 1;
1495 return(size);
1498 /*****************************************************************************/
1501 * Generate the serial struct info.
1504 static void stl_getserial(stlport_t *portp, struct serial_struct *sp)
1506 struct serial_struct sio;
1507 stlbrd_t *brdp;
1509 #if DEBUG
1510 printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1511 #endif
1513 memset(&sio, 0, sizeof(struct serial_struct));
1514 sio.line = portp->portnr;
1515 sio.port = portp->ioaddr;
1516 sio.flags = portp->flags;
1517 sio.baud_base = portp->baud_base;
1518 sio.close_delay = portp->close_delay;
1519 sio.closing_wait = portp->closing_wait;
1520 sio.custom_divisor = portp->custom_divisor;
1521 sio.hub6 = 0;
1522 if (portp->uartp == &stl_cd1400uart) {
1523 sio.type = PORT_CIRRUS;
1524 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1525 } else {
1526 sio.type = PORT_UNKNOWN;
1527 sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1530 brdp = stl_brds[portp->brdnr];
1531 if (brdp != (stlbrd_t *) NULL)
1532 sio.irq = brdp->irq;
1534 copy_to_user(sp, &sio, sizeof(struct serial_struct));
1537 /*****************************************************************************/
1540 * Set port according to the serial struct info.
1541 * At this point we do not do any auto-configure stuff, so we will
1542 * just quietly ignore any requests to change irq, etc.
1545 static int stl_setserial(stlport_t *portp, struct serial_struct *sp)
1547 struct serial_struct sio;
1549 #if DEBUG
1550 printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1551 #endif
1553 copy_from_user(&sio, sp, sizeof(struct serial_struct));
1554 if (!capable(CAP_SYS_ADMIN)) {
1555 if ((sio.baud_base != portp->baud_base) ||
1556 (sio.close_delay != portp->close_delay) ||
1557 ((sio.flags & ~ASYNC_USR_MASK) !=
1558 (portp->flags & ~ASYNC_USR_MASK)))
1559 return(-EPERM);
1562 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1563 (sio.flags & ASYNC_USR_MASK);
1564 portp->baud_base = sio.baud_base;
1565 portp->close_delay = sio.close_delay;
1566 portp->closing_wait = sio.closing_wait;
1567 portp->custom_divisor = sio.custom_divisor;
1568 stl_setport(portp, portp->tty->termios);
1569 return(0);
1572 /*****************************************************************************/
1574 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1576 stlport_t *portp;
1577 unsigned int ival;
1578 int rc;
1580 #if DEBUG
1581 printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
1582 (int) tty, (int) file, cmd, (int) arg);
1583 #endif
1585 if (tty == (struct tty_struct *) NULL)
1586 return(-ENODEV);
1587 portp = tty->driver_data;
1588 if (portp == (stlport_t *) NULL)
1589 return(-ENODEV);
1591 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1592 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1593 if (tty->flags & (1 << TTY_IO_ERROR))
1594 return(-EIO);
1597 rc = 0;
1599 switch (cmd) {
1600 case TIOCGSOFTCAR:
1601 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1602 (unsigned int *) arg);
1603 break;
1604 case TIOCSSOFTCAR:
1605 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1606 sizeof(int))) == 0) {
1607 get_user(ival, (unsigned int *) arg);
1608 tty->termios->c_cflag =
1609 (tty->termios->c_cflag & ~CLOCAL) |
1610 (ival ? CLOCAL : 0);
1612 break;
1613 case TIOCMGET:
1614 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1615 sizeof(unsigned int))) == 0) {
1616 ival = stl_getsignals(portp);
1617 put_user(ival, (unsigned int *) arg);
1619 break;
1620 case TIOCMBIS:
1621 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1622 sizeof(unsigned int))) == 0) {
1623 get_user(ival, (unsigned int *) arg);
1624 stl_setsignals(portp, ((ival & TIOCM_DTR) ? 1 : -1),
1625 ((ival & TIOCM_RTS) ? 1 : -1));
1627 break;
1628 case TIOCMBIC:
1629 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1630 sizeof(unsigned int))) == 0) {
1631 get_user(ival, (unsigned int *) arg);
1632 stl_setsignals(portp, ((ival & TIOCM_DTR) ? 0 : -1),
1633 ((ival & TIOCM_RTS) ? 0 : -1));
1635 break;
1636 case TIOCMSET:
1637 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1638 sizeof(unsigned int))) == 0) {
1639 get_user(ival, (unsigned int *) arg);
1640 stl_setsignals(portp, ((ival & TIOCM_DTR) ? 1 : 0),
1641 ((ival & TIOCM_RTS) ? 1 : 0));
1643 break;
1644 case TIOCGSERIAL:
1645 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1646 sizeof(struct serial_struct))) == 0)
1647 stl_getserial(portp, (struct serial_struct *) arg);
1648 break;
1649 case TIOCSSERIAL:
1650 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1651 sizeof(struct serial_struct))) == 0)
1652 rc = stl_setserial(portp, (struct serial_struct *) arg);
1653 break;
1654 case COM_GETPORTSTATS:
1655 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1656 sizeof(comstats_t))) == 0)
1657 rc = stl_getportstats(portp, (comstats_t *) arg);
1658 break;
1659 case COM_CLRPORTSTATS:
1660 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1661 sizeof(comstats_t))) == 0)
1662 rc = stl_clrportstats(portp, (comstats_t *) arg);
1663 break;
1664 case TIOCSERCONFIG:
1665 case TIOCSERGWILD:
1666 case TIOCSERSWILD:
1667 case TIOCSERGETLSR:
1668 case TIOCSERGSTRUCT:
1669 case TIOCSERGETMULTI:
1670 case TIOCSERSETMULTI:
1671 default:
1672 rc = -ENOIOCTLCMD;
1673 break;
1676 return(rc);
1679 /*****************************************************************************/
1681 static void stl_settermios(struct tty_struct *tty, struct termios *old)
1683 stlport_t *portp;
1684 struct termios *tiosp;
1686 #if DEBUG
1687 printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
1688 #endif
1690 if (tty == (struct tty_struct *) NULL)
1691 return;
1692 portp = tty->driver_data;
1693 if (portp == (stlport_t *) NULL)
1694 return;
1696 tiosp = tty->termios;
1697 if ((tiosp->c_cflag == old->c_cflag) &&
1698 (tiosp->c_iflag == old->c_iflag))
1699 return;
1701 stl_setport(portp, tiosp);
1702 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1703 -1);
1704 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1705 tty->hw_stopped = 0;
1706 stl_start(tty);
1708 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1709 wake_up_interruptible(&portp->open_wait);
1712 /*****************************************************************************/
1715 * Attempt to flow control who ever is sending us data. Based on termios
1716 * settings use software or/and hardware flow control.
1719 static void stl_throttle(struct tty_struct *tty)
1721 stlport_t *portp;
1723 #if DEBUG
1724 printk("stl_throttle(tty=%x)\n", (int) tty);
1725 #endif
1727 if (tty == (struct tty_struct *) NULL)
1728 return;
1729 portp = tty->driver_data;
1730 if (portp == (stlport_t *) NULL)
1731 return;
1732 stl_flowctrl(portp, 0);
1735 /*****************************************************************************/
1738 * Unflow control the device sending us data...
1741 static void stl_unthrottle(struct tty_struct *tty)
1743 stlport_t *portp;
1745 #if DEBUG
1746 printk("stl_unthrottle(tty=%x)\n", (int) tty);
1747 #endif
1749 if (tty == (struct tty_struct *) NULL)
1750 return;
1751 portp = tty->driver_data;
1752 if (portp == (stlport_t *) NULL)
1753 return;
1754 stl_flowctrl(portp, 1);
1757 /*****************************************************************************/
1760 * Stop the transmitter. Basically to do this we will just turn TX
1761 * interrupts off.
1764 static void stl_stop(struct tty_struct *tty)
1766 stlport_t *portp;
1768 #if DEBUG
1769 printk("stl_stop(tty=%x)\n", (int) tty);
1770 #endif
1772 if (tty == (struct tty_struct *) NULL)
1773 return;
1774 portp = tty->driver_data;
1775 if (portp == (stlport_t *) NULL)
1776 return;
1777 stl_startrxtx(portp, -1, 0);
1780 /*****************************************************************************/
1783 * Start the transmitter again. Just turn TX interrupts back on.
1786 static void stl_start(struct tty_struct *tty)
1788 stlport_t *portp;
1790 #if DEBUG
1791 printk("stl_start(tty=%x)\n", (int) tty);
1792 #endif
1794 if (tty == (struct tty_struct *) NULL)
1795 return;
1796 portp = tty->driver_data;
1797 if (portp == (stlport_t *) NULL)
1798 return;
1799 stl_startrxtx(portp, -1, 1);
1802 /*****************************************************************************/
1805 * Hangup this port. This is pretty much like closing the port, only
1806 * a little more brutal. No waiting for data to drain. Shutdown the
1807 * port and maybe drop signals.
1810 static void stl_hangup(struct tty_struct *tty)
1812 stlport_t *portp;
1814 #if DEBUG
1815 printk("stl_hangup(tty=%x)\n", (int) tty);
1816 #endif
1818 if (tty == (struct tty_struct *) NULL)
1819 return;
1820 portp = tty->driver_data;
1821 if (portp == (stlport_t *) NULL)
1822 return;
1824 portp->flags &= ~ASYNC_INITIALIZED;
1825 stl_disableintrs(portp);
1826 if (tty->termios->c_cflag & HUPCL)
1827 stl_setsignals(portp, 0, 0);
1828 stl_enablerxtx(portp, 0, 0);
1829 stl_flushbuffer(tty);
1830 portp->istate = 0;
1831 set_bit(TTY_IO_ERROR, &tty->flags);
1832 if (portp->tx.buf != (char *) NULL) {
1833 kfree_s(portp->tx.buf, STL_TXBUFSIZE);
1834 portp->tx.buf = (char *) NULL;
1835 portp->tx.head = (char *) NULL;
1836 portp->tx.tail = (char *) NULL;
1838 portp->tty = (struct tty_struct *) NULL;
1839 portp->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CALLOUT_ACTIVE);
1840 portp->refcount = 0;
1841 wake_up_interruptible(&portp->open_wait);
1844 /*****************************************************************************/
1846 static void stl_flushbuffer(struct tty_struct *tty)
1848 stlport_t *portp;
1850 #if DEBUG
1851 printk("stl_flushbuffer(tty=%x)\n", (int) tty);
1852 #endif
1854 if (tty == (struct tty_struct *) NULL)
1855 return;
1856 portp = tty->driver_data;
1857 if (portp == (stlport_t *) NULL)
1858 return;
1860 stl_flush(portp);
1861 wake_up_interruptible(&tty->write_wait);
1862 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1863 tty->ldisc.write_wakeup)
1864 (tty->ldisc.write_wakeup)(tty);
1867 /*****************************************************************************/
1869 static void stl_breakctl(struct tty_struct *tty, int state)
1871 stlport_t *portp;
1873 #if DEBUG
1874 printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty, state);
1875 #endif
1877 if (tty == (struct tty_struct *) NULL)
1878 return;
1879 portp = tty->driver_data;
1880 if (portp == (stlport_t *) NULL)
1881 return;
1883 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1886 /*****************************************************************************/
1888 static void stl_waituntilsent(struct tty_struct *tty, int timeout)
1890 stlport_t *portp;
1891 unsigned long tend;
1893 #if DEBUG
1894 printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty, timeout);
1895 #endif
1897 if (tty == (struct tty_struct *) NULL)
1898 return;
1899 portp = tty->driver_data;
1900 if (portp == (stlport_t *) NULL)
1901 return;
1903 if (timeout == 0)
1904 timeout = HZ;
1905 tend = jiffies + timeout;
1907 while (stl_datastate(portp)) {
1908 if (signal_pending(current))
1909 break;
1910 stl_delay(2);
1911 if (time_after_eq(jiffies, tend))
1912 break;
1916 /*****************************************************************************/
1918 static void stl_sendxchar(struct tty_struct *tty, char ch)
1920 stlport_t *portp;
1922 #if DEBUG
1923 printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
1924 #endif
1926 if (tty == (struct tty_struct *) NULL)
1927 return;
1928 portp = tty->driver_data;
1929 if (portp == (stlport_t *) NULL)
1930 return;
1932 if (ch == STOP_CHAR(tty))
1933 stl_sendflow(portp, 0);
1934 else if (ch == START_CHAR(tty))
1935 stl_sendflow(portp, 1);
1936 else
1937 stl_putchar(tty, ch);
1940 /*****************************************************************************/
1942 #define MAXLINE 80
1945 * Format info for a specified port. The line is deliberately limited
1946 * to 80 characters. (If it is too long it will be truncated, if too
1947 * short then padded with spaces).
1950 static int stl_portinfo(stlport_t *portp, int portnr, char *pos)
1952 char *sp;
1953 int sigs, cnt;
1955 sp = pos;
1956 sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
1957 portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
1958 (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
1960 if (portp->stats.rxframing)
1961 sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
1962 if (portp->stats.rxparity)
1963 sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
1964 if (portp->stats.rxbreaks)
1965 sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
1966 if (portp->stats.rxoverrun)
1967 sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
1969 sigs = stl_getsignals(portp);
1970 cnt = sprintf(sp, "%s%s%s%s%s ",
1971 (sigs & TIOCM_RTS) ? "|RTS" : "",
1972 (sigs & TIOCM_CTS) ? "|CTS" : "",
1973 (sigs & TIOCM_DTR) ? "|DTR" : "",
1974 (sigs & TIOCM_CD) ? "|DCD" : "",
1975 (sigs & TIOCM_DSR) ? "|DSR" : "");
1976 *sp = ' ';
1977 sp += cnt;
1979 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
1980 *sp++ = ' ';
1981 if (cnt >= MAXLINE)
1982 pos[(MAXLINE - 2)] = '+';
1983 pos[(MAXLINE - 1)] = '\n';
1985 return(MAXLINE);
1988 /*****************************************************************************/
1991 * Port info, read from the /proc file system.
1994 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
1996 stlbrd_t *brdp;
1997 stlpanel_t *panelp;
1998 stlport_t *portp;
1999 int brdnr, panelnr, portnr, totalport;
2000 int curoff, maxoff;
2001 char *pos;
2003 #if DEBUG
2004 printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
2005 "data=%x\n", (int) page, (int) start, (int) off, count,
2006 (int) eof, (int) data);
2007 #endif
2009 pos = page;
2010 totalport = 0;
2011 curoff = 0;
2013 if (off == 0) {
2014 pos += sprintf(pos, "%s: version %s", stl_drvtitle,
2015 stl_drvversion);
2016 while (pos < (page + MAXLINE - 1))
2017 *pos++ = ' ';
2018 *pos++ = '\n';
2020 curoff = MAXLINE;
2023 * We scan through for each board, panel and port. The offset is
2024 * calculated on the fly, and irrelevant ports are skipped.
2026 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
2027 brdp = stl_brds[brdnr];
2028 if (brdp == (stlbrd_t *) NULL)
2029 continue;
2030 if (brdp->state == 0)
2031 continue;
2033 maxoff = curoff + (brdp->nrports * MAXLINE);
2034 if (off >= maxoff) {
2035 curoff = maxoff;
2036 continue;
2039 totalport = brdnr * STL_MAXPORTS;
2040 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
2041 panelp = brdp->panels[panelnr];
2042 if (panelp == (stlpanel_t *) NULL)
2043 continue;
2045 maxoff = curoff + (panelp->nrports * MAXLINE);
2046 if (off >= maxoff) {
2047 curoff = maxoff;
2048 totalport += panelp->nrports;
2049 continue;
2052 for (portnr = 0; (portnr < panelp->nrports); portnr++,
2053 totalport++) {
2054 portp = panelp->ports[portnr];
2055 if (portp == (stlport_t *) NULL)
2056 continue;
2057 if (off >= (curoff += MAXLINE))
2058 continue;
2059 if ((pos - page + MAXLINE) > count)
2060 goto stl_readdone;
2061 pos += stl_portinfo(portp, totalport, pos);
2066 *eof = 1;
2068 stl_readdone:
2069 *start = page;
2070 return(pos - page);
2073 /*****************************************************************************/
2076 * All board interrupts are vectored through here first. This code then
2077 * calls off to the approrpriate board interrupt handlers.
2080 static void stl_intr(int irq, void *dev_id, struct pt_regs *regs)
2082 stlbrd_t *brdp;
2083 int i;
2085 #if DEBUG
2086 printk("stl_intr(irq=%d,regs=%x)\n", irq, (int) regs);
2087 #endif
2089 for (i = 0; (i < stl_nrbrds); i++) {
2090 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
2091 continue;
2092 if (brdp->state == 0)
2093 continue;
2094 (* brdp->isr)(brdp);
2098 /*****************************************************************************/
2101 * Interrupt service routine for EasyIO board types.
2104 static void stl_eiointr(stlbrd_t *brdp)
2106 stlpanel_t *panelp;
2107 unsigned int iobase;
2109 panelp = brdp->panels[0];
2110 iobase = panelp->iobase;
2111 while (inb(brdp->iostatus) & EIO_INTRPEND)
2112 (* panelp->isr)(panelp, iobase);
2115 /*****************************************************************************/
2118 * Interrupt service routine for ECH-AT board types.
2121 static void stl_echatintr(stlbrd_t *brdp)
2123 stlpanel_t *panelp;
2124 unsigned int ioaddr;
2125 int bnknr;
2127 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2129 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2130 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2131 ioaddr = brdp->bnkstataddr[bnknr];
2132 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2133 panelp = brdp->bnk2panel[bnknr];
2134 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2139 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2142 /*****************************************************************************/
2145 * Interrupt service routine for ECH-MCA board types.
2148 static void stl_echmcaintr(stlbrd_t *brdp)
2150 stlpanel_t *panelp;
2151 unsigned int ioaddr;
2152 int bnknr;
2154 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2155 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2156 ioaddr = brdp->bnkstataddr[bnknr];
2157 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2158 panelp = brdp->bnk2panel[bnknr];
2159 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2165 /*****************************************************************************/
2168 * Interrupt service routine for ECH-PCI board types.
2171 static void stl_echpciintr(stlbrd_t *brdp)
2173 stlpanel_t *panelp;
2174 unsigned int ioaddr;
2175 int bnknr, recheck;
2177 while (1) {
2178 recheck = 0;
2179 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2180 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
2181 ioaddr = brdp->bnkstataddr[bnknr];
2182 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2183 panelp = brdp->bnk2panel[bnknr];
2184 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2185 recheck++;
2188 if (! recheck)
2189 break;
2193 /*****************************************************************************/
2196 * Interrupt service routine for ECH-8/64-PCI board types.
2199 static void stl_echpci64intr(stlbrd_t *brdp)
2201 stlpanel_t *panelp;
2202 unsigned int ioaddr;
2203 int bnknr;
2205 while (inb(brdp->ioctrl) & 0x1) {
2206 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2207 ioaddr = brdp->bnkstataddr[bnknr];
2208 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2209 panelp = brdp->bnk2panel[bnknr];
2210 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2216 /*****************************************************************************/
2219 * Service an off-level request for some channel.
2221 static void stl_offintr(void *private)
2223 stlport_t *portp;
2224 struct tty_struct *tty;
2225 unsigned int oldsigs;
2227 portp = private;
2229 #if DEBUG
2230 printk("stl_offintr(portp=%x)\n", (int) portp);
2231 #endif
2233 if (portp == (stlport_t *) NULL)
2234 return;
2236 tty = portp->tty;
2237 if (tty == (struct tty_struct *) NULL)
2238 return;
2240 lock_kernel();
2241 if (test_bit(ASYI_TXLOW, &portp->istate)) {
2242 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2243 tty->ldisc.write_wakeup)
2244 (tty->ldisc.write_wakeup)(tty);
2245 wake_up_interruptible(&tty->write_wait);
2247 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
2248 clear_bit(ASYI_DCDCHANGE, &portp->istate);
2249 oldsigs = portp->sigs;
2250 portp->sigs = stl_getsignals(portp);
2251 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
2252 wake_up_interruptible(&portp->open_wait);
2253 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
2254 if (portp->flags & ASYNC_CHECK_CD) {
2255 if (! ((portp->flags & ASYNC_CALLOUT_ACTIVE) &&
2256 (portp->flags & ASYNC_CALLOUT_NOHUP))) {
2257 tty_hangup(tty);
2262 unlock_kernel();
2265 /*****************************************************************************/
2268 * Map in interrupt vector to this driver. Check that we don't
2269 * already have this vector mapped, we might be sharing this
2270 * interrupt across multiple boards.
2273 static int __init stl_mapirq(int irq, char *name)
2275 int rc, i;
2277 #if DEBUG
2278 printk("stl_mapirq(irq=%d,name=%s)\n", irq, name);
2279 #endif
2281 rc = 0;
2282 for (i = 0; (i < stl_numintrs); i++) {
2283 if (stl_gotintrs[i] == irq)
2284 break;
2286 if (i >= stl_numintrs) {
2287 if (request_irq(irq, stl_intr, SA_SHIRQ, name, NULL) != 0) {
2288 printk("STALLION: failed to register interrupt "
2289 "routine for %s irq=%d\n", name, irq);
2290 rc = -ENODEV;
2291 } else {
2292 stl_gotintrs[stl_numintrs++] = irq;
2295 return(rc);
2298 /*****************************************************************************/
2301 * Initialize all the ports on a panel.
2304 static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2306 stlport_t *portp;
2307 int chipmask, i;
2309 #if DEBUG
2310 printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
2311 #endif
2313 chipmask = stl_panelinit(brdp, panelp);
2316 * All UART's are initialized (if found!). Now go through and setup
2317 * each ports data structures.
2319 for (i = 0; (i < panelp->nrports); i++) {
2320 portp = (stlport_t *) stl_memalloc(sizeof(stlport_t));
2321 if (portp == (stlport_t *) NULL) {
2322 printk("STALLION: failed to allocate memory "
2323 "(size=%d)\n", sizeof(stlport_t));
2324 break;
2326 memset(portp, 0, sizeof(stlport_t));
2328 portp->magic = STL_PORTMAGIC;
2329 portp->portnr = i;
2330 portp->brdnr = panelp->brdnr;
2331 portp->panelnr = panelp->panelnr;
2332 portp->uartp = panelp->uartp;
2333 portp->clk = brdp->clk;
2334 portp->baud_base = STL_BAUDBASE;
2335 portp->close_delay = STL_CLOSEDELAY;
2336 portp->closing_wait = 30 * HZ;
2337 portp->normaltermios = stl_deftermios;
2338 portp->callouttermios = stl_deftermios;
2339 portp->tqueue.routine = stl_offintr;
2340 portp->tqueue.data = portp;
2341 init_waitqueue_head(&portp->open_wait);
2342 init_waitqueue_head(&portp->close_wait);
2343 portp->stats.brd = portp->brdnr;
2344 portp->stats.panel = portp->panelnr;
2345 portp->stats.port = portp->portnr;
2346 panelp->ports[i] = portp;
2347 stl_portinit(brdp, panelp, portp);
2350 return(0);
2353 /*****************************************************************************/
2356 * Try to find and initialize an EasyIO board.
2359 static inline int stl_initeio(stlbrd_t *brdp)
2361 stlpanel_t *panelp;
2362 unsigned int status;
2363 char *name;
2364 int rc;
2366 #if DEBUG
2367 printk("stl_initeio(brdp=%x)\n", (int) brdp);
2368 #endif
2370 brdp->ioctrl = brdp->ioaddr1 + 1;
2371 brdp->iostatus = brdp->ioaddr1 + 2;
2373 status = inb(brdp->iostatus);
2374 if ((status & EIO_IDBITMASK) == EIO_MK3)
2375 brdp->ioctrl++;
2378 * Handle board specific stuff now. The real difference is PCI
2379 * or not PCI.
2381 if (brdp->brdtype == BRD_EASYIOPCI) {
2382 brdp->iosize1 = 0x80;
2383 brdp->iosize2 = 0x80;
2384 name = "serial(EIO-PCI)";
2385 outb(0x41, (brdp->ioaddr2 + 0x4c));
2386 } else {
2387 brdp->iosize1 = 8;
2388 name = "serial(EIO)";
2389 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2390 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2391 printk("STALLION: invalid irq=%d for brd=%d\n",
2392 brdp->irq, brdp->brdnr);
2393 return(-EINVAL);
2395 outb((stl_vecmap[brdp->irq] | EIO_0WS |
2396 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
2397 brdp->ioctrl);
2400 if (check_region(brdp->ioaddr1, brdp->iosize1)) {
2401 printk("STALLION: Warning, board %d I/O address %x conflicts "
2402 "with another device\n", brdp->brdnr, brdp->ioaddr1);
2404 if (brdp->iosize2 > 0) {
2405 if (check_region(brdp->ioaddr2, brdp->iosize2)) {
2406 printk("STALLION: Warning, board %d I/O address %x "
2407 "conflicts with another device\n",
2408 brdp->brdnr, brdp->ioaddr2);
2413 * Everything looks OK, so let's go ahead and probe for the hardware.
2415 brdp->clk = CD1400_CLK;
2416 brdp->isr = stl_eiointr;
2418 switch (status & EIO_IDBITMASK) {
2419 case EIO_8PORTM:
2420 brdp->clk = CD1400_CLK8M;
2421 /* fall thru */
2422 case EIO_8PORTRS:
2423 case EIO_8PORTDI:
2424 brdp->nrports = 8;
2425 break;
2426 case EIO_4PORTRS:
2427 brdp->nrports = 4;
2428 break;
2429 case EIO_MK3:
2430 switch (status & EIO_BRDMASK) {
2431 case ID_BRD4:
2432 brdp->nrports = 4;
2433 break;
2434 case ID_BRD8:
2435 brdp->nrports = 8;
2436 break;
2437 case ID_BRD16:
2438 brdp->nrports = 16;
2439 break;
2440 default:
2441 return(-ENODEV);
2443 break;
2444 default:
2445 return(-ENODEV);
2449 * We have verfied that the board is actually present, so now we
2450 * can complete the setup.
2452 request_region(brdp->ioaddr1, brdp->iosize1, name);
2453 if (brdp->iosize2 > 0)
2454 request_region(brdp->ioaddr2, brdp->iosize2, name);
2456 panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
2457 if (panelp == (stlpanel_t *) NULL) {
2458 printk("STALLION: failed to allocate memory (size=%d)\n",
2459 sizeof(stlpanel_t));
2460 return(-ENOMEM);
2462 memset(panelp, 0, sizeof(stlpanel_t));
2464 panelp->magic = STL_PANELMAGIC;
2465 panelp->brdnr = brdp->brdnr;
2466 panelp->panelnr = 0;
2467 panelp->nrports = brdp->nrports;
2468 panelp->iobase = brdp->ioaddr1;
2469 panelp->hwid = status;
2470 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2471 panelp->uartp = (void *) &stl_sc26198uart;
2472 panelp->isr = stl_sc26198intr;
2473 } else {
2474 panelp->uartp = (void *) &stl_cd1400uart;
2475 panelp->isr = stl_cd1400eiointr;
2478 brdp->panels[0] = panelp;
2479 brdp->nrpanels = 1;
2480 brdp->state |= BRD_FOUND;
2481 brdp->hwid = status;
2482 rc = stl_mapirq(brdp->irq, name);
2483 return(rc);
2486 /*****************************************************************************/
2489 * Try to find an ECH board and initialize it. This code is capable of
2490 * dealing with all types of ECH board.
2493 static int inline stl_initech(stlbrd_t *brdp)
2495 stlpanel_t *panelp;
2496 unsigned int status, nxtid, ioaddr, conflict;
2497 int panelnr, banknr, i;
2498 char *name;
2500 #if DEBUG
2501 printk("stl_initech(brdp=%x)\n", (int) brdp);
2502 #endif
2504 status = 0;
2505 conflict = 0;
2508 * Set up the initial board register contents for boards. This varies a
2509 * bit between the different board types. So we need to handle each
2510 * separately. Also do a check that the supplied IRQ is good.
2512 switch (brdp->brdtype) {
2514 case BRD_ECH:
2515 brdp->isr = stl_echatintr;
2516 brdp->ioctrl = brdp->ioaddr1 + 1;
2517 brdp->iostatus = brdp->ioaddr1 + 1;
2518 status = inb(brdp->iostatus);
2519 if ((status & ECH_IDBITMASK) != ECH_ID)
2520 return(-ENODEV);
2521 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2522 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2523 printk("STALLION: invalid irq=%d for brd=%d\n",
2524 brdp->irq, brdp->brdnr);
2525 return(-EINVAL);
2527 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2528 status |= (stl_vecmap[brdp->irq] << 1);
2529 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2530 brdp->ioctrlval = ECH_INTENABLE |
2531 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2532 for (i = 0; (i < 10); i++)
2533 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2534 brdp->iosize1 = 2;
2535 brdp->iosize2 = 32;
2536 name = "serial(EC8/32)";
2537 outb(status, brdp->ioaddr1);
2538 break;
2540 case BRD_ECHMC:
2541 brdp->isr = stl_echmcaintr;
2542 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2543 brdp->iostatus = brdp->ioctrl;
2544 status = inb(brdp->iostatus);
2545 if ((status & ECH_IDBITMASK) != ECH_ID)
2546 return(-ENODEV);
2547 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2548 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2549 printk("STALLION: invalid irq=%d for brd=%d\n",
2550 brdp->irq, brdp->brdnr);
2551 return(-EINVAL);
2553 outb(ECHMC_BRDRESET, brdp->ioctrl);
2554 outb(ECHMC_INTENABLE, brdp->ioctrl);
2555 brdp->iosize1 = 64;
2556 name = "serial(EC8/32-MC)";
2557 break;
2559 case BRD_ECHPCI:
2560 brdp->isr = stl_echpciintr;
2561 brdp->ioctrl = brdp->ioaddr1 + 2;
2562 brdp->iosize1 = 4;
2563 brdp->iosize2 = 8;
2564 name = "serial(EC8/32-PCI)";
2565 break;
2567 case BRD_ECH64PCI:
2568 brdp->isr = stl_echpci64intr;
2569 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2570 outb(0x43, (brdp->ioaddr1 + 0x4c));
2571 brdp->iosize1 = 0x80;
2572 brdp->iosize2 = 0x80;
2573 name = "serial(EC8/64-PCI)";
2574 break;
2576 default:
2577 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
2578 return(-EINVAL);
2579 break;
2583 * Check boards for possible IO address conflicts. We won't actually
2584 * do anything about it here, just issue a warning...
2586 conflict = check_region(brdp->ioaddr1, brdp->iosize1) ?
2587 brdp->ioaddr1 : 0;
2588 if ((conflict == 0) && (brdp->iosize2 > 0))
2589 conflict = check_region(brdp->ioaddr2, brdp->iosize2) ?
2590 brdp->ioaddr2 : 0;
2591 if (conflict) {
2592 printk("STALLION: Warning, board %d I/O address %x conflicts "
2593 "with another device\n", brdp->brdnr, conflict);
2596 request_region(brdp->ioaddr1, brdp->iosize1, name);
2597 if (brdp->iosize2 > 0)
2598 request_region(brdp->ioaddr2, brdp->iosize2, name);
2601 * Scan through the secondary io address space looking for panels.
2602 * As we find'em allocate and initialize panel structures for each.
2604 brdp->clk = CD1400_CLK;
2605 brdp->hwid = status;
2607 ioaddr = brdp->ioaddr2;
2608 banknr = 0;
2609 panelnr = 0;
2610 nxtid = 0;
2612 for (i = 0; (i < STL_MAXPANELS); i++) {
2613 if (brdp->brdtype == BRD_ECHPCI) {
2614 outb(nxtid, brdp->ioctrl);
2615 ioaddr = brdp->ioaddr2;
2617 status = inb(ioaddr + ECH_PNLSTATUS);
2618 if ((status & ECH_PNLIDMASK) != nxtid)
2619 break;
2620 panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
2621 if (panelp == (stlpanel_t *) NULL) {
2622 printk("STALLION: failed to allocate memory "
2623 "(size=%d)\n", sizeof(stlpanel_t));
2624 break;
2626 memset(panelp, 0, sizeof(stlpanel_t));
2627 panelp->magic = STL_PANELMAGIC;
2628 panelp->brdnr = brdp->brdnr;
2629 panelp->panelnr = panelnr;
2630 panelp->iobase = ioaddr;
2631 panelp->pagenr = nxtid;
2632 panelp->hwid = status;
2633 brdp->bnk2panel[banknr] = panelp;
2634 brdp->bnkpageaddr[banknr] = nxtid;
2635 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2637 if (status & ECH_PNLXPID) {
2638 panelp->uartp = (void *) &stl_sc26198uart;
2639 panelp->isr = stl_sc26198intr;
2640 if (status & ECH_PNL16PORT) {
2641 panelp->nrports = 16;
2642 brdp->bnk2panel[banknr] = panelp;
2643 brdp->bnkpageaddr[banknr] = nxtid;
2644 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2645 ECH_PNLSTATUS;
2646 } else {
2647 panelp->nrports = 8;
2649 } else {
2650 panelp->uartp = (void *) &stl_cd1400uart;
2651 panelp->isr = stl_cd1400echintr;
2652 if (status & ECH_PNL16PORT) {
2653 panelp->nrports = 16;
2654 panelp->ackmask = 0x80;
2655 if (brdp->brdtype != BRD_ECHPCI)
2656 ioaddr += EREG_BANKSIZE;
2657 brdp->bnk2panel[banknr] = panelp;
2658 brdp->bnkpageaddr[banknr] = ++nxtid;
2659 brdp->bnkstataddr[banknr++] = ioaddr +
2660 ECH_PNLSTATUS;
2661 } else {
2662 panelp->nrports = 8;
2663 panelp->ackmask = 0xc0;
2667 nxtid++;
2668 ioaddr += EREG_BANKSIZE;
2669 brdp->nrports += panelp->nrports;
2670 brdp->panels[panelnr++] = panelp;
2671 if ((brdp->brdtype != BRD_ECHPCI) &&
2672 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
2673 break;
2676 brdp->nrpanels = panelnr;
2677 brdp->nrbnks = banknr;
2678 if (brdp->brdtype == BRD_ECH)
2679 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2681 brdp->state |= BRD_FOUND;
2682 i = stl_mapirq(brdp->irq, name);
2683 return(i);
2686 /*****************************************************************************/
2689 * Initialize and configure the specified board.
2690 * Scan through all the boards in the configuration and see what we
2691 * can find. Handle EIO and the ECH boards a little differently here
2692 * since the initial search and setup is very different.
2695 static int __init stl_brdinit(stlbrd_t *brdp)
2697 int i;
2699 #if DEBUG
2700 printk("stl_brdinit(brdp=%x)\n", (int) brdp);
2701 #endif
2703 switch (brdp->brdtype) {
2704 case BRD_EASYIO:
2705 case BRD_EASYIOPCI:
2706 stl_initeio(brdp);
2707 break;
2708 case BRD_ECH:
2709 case BRD_ECHMC:
2710 case BRD_ECHPCI:
2711 case BRD_ECH64PCI:
2712 stl_initech(brdp);
2713 break;
2714 default:
2715 printk("STALLION: board=%d is unknown board type=%d\n",
2716 brdp->brdnr, brdp->brdtype);
2717 return(ENODEV);
2720 stl_brds[brdp->brdnr] = brdp;
2721 if ((brdp->state & BRD_FOUND) == 0) {
2722 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2723 stl_brdnames[brdp->brdtype], brdp->brdnr,
2724 brdp->ioaddr1, brdp->irq);
2725 return(ENODEV);
2728 for (i = 0; (i < STL_MAXPANELS); i++)
2729 if (brdp->panels[i] != (stlpanel_t *) NULL)
2730 stl_initports(brdp, brdp->panels[i]);
2732 printk("STALLION: %s found, board=%d io=%x irq=%d "
2733 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2734 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2735 brdp->nrports);
2736 return(0);
2739 /*****************************************************************************/
2742 * Find the next available board number that is free.
2745 static inline int stl_getbrdnr()
2747 int i;
2749 for (i = 0; (i < STL_MAXBRDS); i++) {
2750 if (stl_brds[i] == (stlbrd_t *) NULL) {
2751 if (i >= stl_nrbrds)
2752 stl_nrbrds = i + 1;
2753 return(i);
2756 return(-1);
2759 /*****************************************************************************/
2761 #ifdef CONFIG_PCI
2764 * We have a Stallion board. Allocate a board structure and
2765 * initialize it. Read its IO and IRQ resources from PCI
2766 * configuration space.
2769 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
2771 stlbrd_t *brdp;
2773 #if DEBUG
2774 printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
2775 devp->bus->number, devp->devfn);
2776 #endif
2778 if (pci_enable_device(devp))
2779 return(-EIO);
2780 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2781 return(-ENOMEM);
2782 if ((brdp->brdnr = stl_getbrdnr()) < 0) {
2783 printk("STALLION: too many boards found, "
2784 "maximum supported %d\n", STL_MAXBRDS);
2785 return(0);
2787 brdp->brdtype = brdtype;
2790 * Different Stallion boards use the BAR registers in different ways,
2791 * so set up io addresses based on board type.
2793 #if DEBUG
2794 printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__, __LINE__,
2795 pci_resource_start(devp, 0), pci_resource_start(devp, 1),
2796 pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
2797 #endif
2800 * We have all resources from the board, so let's setup the actual
2801 * board structure now.
2803 switch (brdtype) {
2804 case BRD_ECHPCI:
2805 brdp->ioaddr2 = pci_resource_start(devp, 0);
2806 brdp->ioaddr1 = pci_resource_start(devp, 1);
2807 break;
2808 case BRD_ECH64PCI:
2809 brdp->ioaddr2 = pci_resource_start(devp, 2);
2810 brdp->ioaddr1 = pci_resource_start(devp, 1);
2811 break;
2812 case BRD_EASYIOPCI:
2813 brdp->ioaddr1 = pci_resource_start(devp, 2);
2814 brdp->ioaddr2 = pci_resource_start(devp, 1);
2815 break;
2816 default:
2817 printk("STALLION: unknown PCI board type=%d\n", brdtype);
2818 break;
2821 brdp->irq = devp->irq;
2822 stl_brdinit(brdp);
2824 return(0);
2827 /*****************************************************************************/
2830 * Find all Stallion PCI boards that might be installed. Initialize each
2831 * one as it is found.
2835 static inline int stl_findpcibrds()
2837 struct pci_dev *dev = NULL;
2838 int i, rc;
2840 #if DEBUG
2841 printk("stl_findpcibrds()\n");
2842 #endif
2844 if (! pci_present())
2845 return(0);
2847 for (i = 0; (i < stl_nrpcibrds); i++)
2848 while ((dev = pci_find_device(stl_pcibrds[i].vendid,
2849 stl_pcibrds[i].devid, dev))) {
2852 * Found a device on the PCI bus that has our vendor and
2853 * device ID. Need to check now that it is really us.
2855 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2856 continue;
2858 rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
2859 if (rc)
2860 return(rc);
2863 return(0);
2866 #endif
2868 /*****************************************************************************/
2871 * Scan through all the boards in the configuration and see what we
2872 * can find. Handle EIO and the ECH boards a little differently here
2873 * since the initial search and setup is too different.
2876 static inline int stl_initbrds()
2878 stlbrd_t *brdp;
2879 stlconf_t *confp;
2880 int i;
2882 #if DEBUG
2883 printk("stl_initbrds()\n");
2884 #endif
2886 if (stl_nrbrds > STL_MAXBRDS) {
2887 printk("STALLION: too many boards in configuration table, "
2888 "truncating to %d\n", STL_MAXBRDS);
2889 stl_nrbrds = STL_MAXBRDS;
2893 * Firstly scan the list of static boards configured. Allocate
2894 * resources and initialize the boards as found.
2896 for (i = 0; (i < stl_nrbrds); i++) {
2897 confp = &stl_brdconf[i];
2898 #ifdef MODULE
2899 stl_parsebrd(confp, stl_brdsp[i]);
2900 #endif
2901 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2902 return(-ENOMEM);
2903 brdp->brdnr = i;
2904 brdp->brdtype = confp->brdtype;
2905 brdp->ioaddr1 = confp->ioaddr1;
2906 brdp->ioaddr2 = confp->ioaddr2;
2907 brdp->irq = confp->irq;
2908 brdp->irqtype = confp->irqtype;
2909 stl_brdinit(brdp);
2913 * Find any dynamically supported boards. That is via module load
2914 * line options or auto-detected on the PCI bus.
2916 #ifdef MODULE
2917 stl_argbrds();
2918 #endif
2919 #ifdef CONFIG_PCI
2920 stl_findpcibrds();
2921 #endif
2923 return(0);
2926 /*****************************************************************************/
2929 * Return the board stats structure to user app.
2932 static int stl_getbrdstats(combrd_t *bp)
2934 stlbrd_t *brdp;
2935 stlpanel_t *panelp;
2936 int i;
2938 copy_from_user(&stl_brdstats, bp, sizeof(combrd_t));
2939 if (stl_brdstats.brd >= STL_MAXBRDS)
2940 return(-ENODEV);
2941 brdp = stl_brds[stl_brdstats.brd];
2942 if (brdp == (stlbrd_t *) NULL)
2943 return(-ENODEV);
2945 memset(&stl_brdstats, 0, sizeof(combrd_t));
2946 stl_brdstats.brd = brdp->brdnr;
2947 stl_brdstats.type = brdp->brdtype;
2948 stl_brdstats.hwid = brdp->hwid;
2949 stl_brdstats.state = brdp->state;
2950 stl_brdstats.ioaddr = brdp->ioaddr1;
2951 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2952 stl_brdstats.irq = brdp->irq;
2953 stl_brdstats.nrpanels = brdp->nrpanels;
2954 stl_brdstats.nrports = brdp->nrports;
2955 for (i = 0; (i < brdp->nrpanels); i++) {
2956 panelp = brdp->panels[i];
2957 stl_brdstats.panels[i].panel = i;
2958 stl_brdstats.panels[i].hwid = panelp->hwid;
2959 stl_brdstats.panels[i].nrports = panelp->nrports;
2962 copy_to_user(bp, &stl_brdstats, sizeof(combrd_t));
2963 return(0);
2966 /*****************************************************************************/
2969 * Resolve the referenced port number into a port struct pointer.
2972 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2974 stlbrd_t *brdp;
2975 stlpanel_t *panelp;
2977 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2978 return((stlport_t *) NULL);
2979 brdp = stl_brds[brdnr];
2980 if (brdp == (stlbrd_t *) NULL)
2981 return((stlport_t *) NULL);
2982 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2983 return((stlport_t *) NULL);
2984 panelp = brdp->panels[panelnr];
2985 if (panelp == (stlpanel_t *) NULL)
2986 return((stlport_t *) NULL);
2987 if ((portnr < 0) || (portnr >= panelp->nrports))
2988 return((stlport_t *) NULL);
2989 return(panelp->ports[portnr]);
2992 /*****************************************************************************/
2995 * Return the port stats structure to user app. A NULL port struct
2996 * pointer passed in means that we need to find out from the app
2997 * what port to get stats for (used through board control device).
3000 static int stl_getportstats(stlport_t *portp, comstats_t *cp)
3002 unsigned char *head, *tail;
3003 unsigned long flags;
3005 if (portp == (stlport_t *) NULL) {
3006 copy_from_user(&stl_comstats, cp, sizeof(comstats_t));
3007 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
3008 stl_comstats.port);
3009 if (portp == (stlport_t *) NULL)
3010 return(-ENODEV);
3013 portp->stats.state = portp->istate;
3014 portp->stats.flags = portp->flags;
3015 portp->stats.hwid = portp->hwid;
3017 portp->stats.ttystate = 0;
3018 portp->stats.cflags = 0;
3019 portp->stats.iflags = 0;
3020 portp->stats.oflags = 0;
3021 portp->stats.lflags = 0;
3022 portp->stats.rxbuffered = 0;
3024 save_flags(flags);
3025 cli();
3026 if (portp->tty != (struct tty_struct *) NULL) {
3027 if (portp->tty->driver_data == portp) {
3028 portp->stats.ttystate = portp->tty->flags;
3029 portp->stats.rxbuffered = portp->tty->flip.count;
3030 if (portp->tty->termios != (struct termios *) NULL) {
3031 portp->stats.cflags = portp->tty->termios->c_cflag;
3032 portp->stats.iflags = portp->tty->termios->c_iflag;
3033 portp->stats.oflags = portp->tty->termios->c_oflag;
3034 portp->stats.lflags = portp->tty->termios->c_lflag;
3038 restore_flags(flags);
3040 head = portp->tx.head;
3041 tail = portp->tx.tail;
3042 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
3043 (STL_TXBUFSIZE - (tail - head)));
3045 portp->stats.signals = (unsigned long) stl_getsignals(portp);
3047 copy_to_user(cp, &portp->stats, sizeof(comstats_t));
3048 return(0);
3051 /*****************************************************************************/
3054 * Clear the port stats structure. We also return it zeroed out...
3057 static int stl_clrportstats(stlport_t *portp, comstats_t *cp)
3059 if (portp == (stlport_t *) NULL) {
3060 copy_from_user(&stl_comstats, cp, sizeof(comstats_t));
3061 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
3062 stl_comstats.port);
3063 if (portp == (stlport_t *) NULL)
3064 return(-ENODEV);
3067 memset(&portp->stats, 0, sizeof(comstats_t));
3068 portp->stats.brd = portp->brdnr;
3069 portp->stats.panel = portp->panelnr;
3070 portp->stats.port = portp->portnr;
3071 copy_to_user(cp, &portp->stats, sizeof(comstats_t));
3072 return(0);
3075 /*****************************************************************************/
3078 * Return the entire driver ports structure to a user app.
3081 static int stl_getportstruct(unsigned long arg)
3083 stlport_t *portp;
3085 copy_from_user(&stl_dummyport, (void *) arg, sizeof(stlport_t));
3086 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
3087 stl_dummyport.portnr);
3088 if (portp == (stlport_t *) NULL)
3089 return(-ENODEV);
3090 copy_to_user((void *) arg, portp, sizeof(stlport_t));
3091 return(0);
3094 /*****************************************************************************/
3097 * Return the entire driver board structure to a user app.
3100 static int stl_getbrdstruct(unsigned long arg)
3102 stlbrd_t *brdp;
3104 copy_from_user(&stl_dummybrd, (void *) arg, sizeof(stlbrd_t));
3105 if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
3106 return(-ENODEV);
3107 brdp = stl_brds[stl_dummybrd.brdnr];
3108 if (brdp == (stlbrd_t *) NULL)
3109 return(-ENODEV);
3110 copy_to_user((void *) arg, brdp, sizeof(stlbrd_t));
3111 return(0);
3114 /*****************************************************************************/
3117 * The "staliomem" device is also required to do some special operations
3118 * on the board and/or ports. In this driver it is mostly used for stats
3119 * collection.
3122 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
3124 int brdnr, rc;
3126 #if DEBUG
3127 printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
3128 (int) fp, cmd, (int) arg);
3129 #endif
3131 brdnr = MINOR(ip->i_rdev);
3132 if (brdnr >= STL_MAXBRDS)
3133 return(-ENODEV);
3134 rc = 0;
3136 switch (cmd) {
3137 case COM_GETPORTSTATS:
3138 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
3139 sizeof(comstats_t))) == 0)
3140 rc = stl_getportstats((stlport_t *) NULL,
3141 (comstats_t *) arg);
3142 break;
3143 case COM_CLRPORTSTATS:
3144 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
3145 sizeof(comstats_t))) == 0)
3146 rc = stl_clrportstats((stlport_t *) NULL,
3147 (comstats_t *) arg);
3148 break;
3149 case COM_GETBRDSTATS:
3150 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
3151 sizeof(combrd_t))) == 0)
3152 rc = stl_getbrdstats((combrd_t *) arg);
3153 break;
3154 case COM_READPORT:
3155 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
3156 sizeof(stlport_t))) == 0)
3157 rc = stl_getportstruct(arg);
3158 break;
3159 case COM_READBOARD:
3160 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
3161 sizeof(stlbrd_t))) == 0)
3162 rc = stl_getbrdstruct(arg);
3163 break;
3164 default:
3165 rc = -ENOIOCTLCMD;
3166 break;
3169 return(rc);
3172 /*****************************************************************************/
3174 int __init stl_init(void)
3176 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
3178 stl_initbrds();
3181 * Allocate a temporary write buffer.
3183 stl_tmpwritebuf = (char *) stl_memalloc(STL_TXBUFSIZE);
3184 if (stl_tmpwritebuf == (char *) NULL)
3185 printk("STALLION: failed to allocate memory (size=%d)\n",
3186 STL_TXBUFSIZE);
3189 * Set up a character driver for per board stuff. This is mainly used
3190 * to do stats ioctls on the ports.
3192 if (devfs_register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
3193 printk("STALLION: failed to register serial board device\n");
3194 devfs_handle = devfs_mk_dir (NULL, "staliomem", NULL);
3195 devfs_register_series (devfs_handle, "%u", 4, DEVFS_FL_DEFAULT,
3196 STL_SIOMEMMAJOR, 0,
3197 S_IFCHR | S_IRUSR | S_IWUSR,
3198 &stl_fsiomem, NULL);
3201 * Set up the tty driver structure and register us as a driver.
3202 * Also setup the callout tty device.
3204 memset(&stl_serial, 0, sizeof(struct tty_driver));
3205 stl_serial.magic = TTY_DRIVER_MAGIC;
3206 stl_serial.driver_name = stl_drvname;
3207 stl_serial.name = stl_serialname;
3208 stl_serial.major = STL_SERIALMAJOR;
3209 stl_serial.minor_start = 0;
3210 stl_serial.num = STL_MAXBRDS * STL_MAXPORTS;
3211 stl_serial.type = TTY_DRIVER_TYPE_SERIAL;
3212 stl_serial.subtype = STL_DRVTYPSERIAL;
3213 stl_serial.init_termios = stl_deftermios;
3214 stl_serial.flags = TTY_DRIVER_REAL_RAW;
3215 stl_serial.refcount = &stl_refcount;
3216 stl_serial.table = stl_ttys;
3217 stl_serial.termios = stl_termios;
3218 stl_serial.termios_locked = stl_termioslocked;
3220 stl_serial.open = stl_open;
3221 stl_serial.close = stl_close;
3222 stl_serial.write = stl_write;
3223 stl_serial.put_char = stl_putchar;
3224 stl_serial.flush_chars = stl_flushchars;
3225 stl_serial.write_room = stl_writeroom;
3226 stl_serial.chars_in_buffer = stl_charsinbuffer;
3227 stl_serial.ioctl = stl_ioctl;
3228 stl_serial.set_termios = stl_settermios;
3229 stl_serial.throttle = stl_throttle;
3230 stl_serial.unthrottle = stl_unthrottle;
3231 stl_serial.stop = stl_stop;
3232 stl_serial.start = stl_start;
3233 stl_serial.hangup = stl_hangup;
3234 stl_serial.flush_buffer = stl_flushbuffer;
3235 stl_serial.break_ctl = stl_breakctl;
3236 stl_serial.wait_until_sent = stl_waituntilsent;
3237 stl_serial.send_xchar = stl_sendxchar;
3238 stl_serial.read_proc = stl_readproc;
3240 stl_callout = stl_serial;
3241 stl_callout.name = stl_calloutname;
3242 stl_callout.major = STL_CALLOUTMAJOR;
3243 stl_callout.subtype = STL_DRVTYPCALLOUT;
3244 stl_callout.read_proc = 0;
3246 if (tty_register_driver(&stl_serial))
3247 printk("STALLION: failed to register serial driver\n");
3248 if (tty_register_driver(&stl_callout))
3249 printk("STALLION: failed to register callout driver\n");
3251 return(0);
3254 /*****************************************************************************/
3255 /* CD1400 HARDWARE FUNCTIONS */
3256 /*****************************************************************************/
3259 * These functions get/set/update the registers of the cd1400 UARTs.
3260 * Access to the cd1400 registers is via an address/data io port pair.
3261 * (Maybe should make this inline...)
3264 static int stl_cd1400getreg(stlport_t *portp, int regnr)
3266 outb((regnr + portp->uartaddr), portp->ioaddr);
3267 return(inb(portp->ioaddr + EREG_DATA));
3270 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
3272 outb((regnr + portp->uartaddr), portp->ioaddr);
3273 outb(value, portp->ioaddr + EREG_DATA);
3276 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
3278 outb((regnr + portp->uartaddr), portp->ioaddr);
3279 if (inb(portp->ioaddr + EREG_DATA) != value) {
3280 outb(value, portp->ioaddr + EREG_DATA);
3281 return(1);
3283 return(0);
3286 /*****************************************************************************/
3289 * Inbitialize the UARTs in a panel. We don't care what sort of board
3290 * these ports are on - since the port io registers are almost
3291 * identical when dealing with ports.
3294 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3296 unsigned int gfrcr;
3297 int chipmask, i, j;
3298 int nrchips, uartaddr, ioaddr;
3300 #if DEBUG
3301 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
3302 #endif
3304 BRDENABLE(panelp->brdnr, panelp->pagenr);
3307 * Check that each chip is present and started up OK.
3309 chipmask = 0;
3310 nrchips = panelp->nrports / CD1400_PORTS;
3311 for (i = 0; (i < nrchips); i++) {
3312 if (brdp->brdtype == BRD_ECHPCI) {
3313 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3314 ioaddr = panelp->iobase;
3315 } else {
3316 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3318 uartaddr = (i & 0x01) ? 0x080 : 0;
3319 outb((GFRCR + uartaddr), ioaddr);
3320 outb(0, (ioaddr + EREG_DATA));
3321 outb((CCR + uartaddr), ioaddr);
3322 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3323 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3324 outb((GFRCR + uartaddr), ioaddr);
3325 for (j = 0; (j < CCR_MAXWAIT); j++) {
3326 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3327 break;
3329 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3330 printk("STALLION: cd1400 not responding, "
3331 "brd=%d panel=%d chip=%d\n",
3332 panelp->brdnr, panelp->panelnr, i);
3333 continue;
3335 chipmask |= (0x1 << i);
3336 outb((PPR + uartaddr), ioaddr);
3337 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
3340 BRDDISABLE(panelp->brdnr);
3341 return(chipmask);
3344 /*****************************************************************************/
3347 * Initialize hardware specific port registers.
3350 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3352 #if DEBUG
3353 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3354 (int) brdp, (int) panelp, (int) portp);
3355 #endif
3357 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
3358 (portp == (stlport_t *) NULL))
3359 return;
3361 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3362 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3363 portp->uartaddr = (portp->portnr & 0x04) << 5;
3364 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3366 BRDENABLE(portp->brdnr, portp->pagenr);
3367 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3368 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3369 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3370 BRDDISABLE(portp->brdnr);
3373 /*****************************************************************************/
3376 * Wait for the command register to be ready. We will poll this,
3377 * since it won't usually take too long to be ready.
3380 static void stl_cd1400ccrwait(stlport_t *portp)
3382 int i;
3384 for (i = 0; (i < CCR_MAXWAIT); i++) {
3385 if (stl_cd1400getreg(portp, CCR) == 0) {
3386 return;
3390 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
3391 portp->portnr, portp->panelnr, portp->brdnr);
3394 /*****************************************************************************/
3397 * Set up the cd1400 registers for a port based on the termios port
3398 * settings.
3401 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3403 stlbrd_t *brdp;
3404 unsigned long flags;
3405 unsigned int clkdiv, baudrate;
3406 unsigned char cor1, cor2, cor3;
3407 unsigned char cor4, cor5, ccr;
3408 unsigned char srer, sreron, sreroff;
3409 unsigned char mcor1, mcor2, rtpr;
3410 unsigned char clk, div;
3412 cor1 = 0;
3413 cor2 = 0;
3414 cor3 = 0;
3415 cor4 = 0;
3416 cor5 = 0;
3417 ccr = 0;
3418 rtpr = 0;
3419 clk = 0;
3420 div = 0;
3421 mcor1 = 0;
3422 mcor2 = 0;
3423 sreron = 0;
3424 sreroff = 0;
3426 brdp = stl_brds[portp->brdnr];
3427 if (brdp == (stlbrd_t *) NULL)
3428 return;
3431 * Set up the RX char ignore mask with those RX error types we
3432 * can ignore. We can get the cd1400 to help us out a little here,
3433 * it will ignore parity errors and breaks for us.
3435 portp->rxignoremsk = 0;
3436 if (tiosp->c_iflag & IGNPAR) {
3437 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
3438 cor1 |= COR1_PARIGNORE;
3440 if (tiosp->c_iflag & IGNBRK) {
3441 portp->rxignoremsk |= ST_BREAK;
3442 cor4 |= COR4_IGNBRK;
3445 portp->rxmarkmsk = ST_OVERRUN;
3446 if (tiosp->c_iflag & (INPCK | PARMRK))
3447 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3448 if (tiosp->c_iflag & BRKINT)
3449 portp->rxmarkmsk |= ST_BREAK;
3452 * Go through the char size, parity and stop bits and set all the
3453 * option register appropriately.
3455 switch (tiosp->c_cflag & CSIZE) {
3456 case CS5:
3457 cor1 |= COR1_CHL5;
3458 break;
3459 case CS6:
3460 cor1 |= COR1_CHL6;
3461 break;
3462 case CS7:
3463 cor1 |= COR1_CHL7;
3464 break;
3465 default:
3466 cor1 |= COR1_CHL8;
3467 break;
3470 if (tiosp->c_cflag & CSTOPB)
3471 cor1 |= COR1_STOP2;
3472 else
3473 cor1 |= COR1_STOP1;
3475 if (tiosp->c_cflag & PARENB) {
3476 if (tiosp->c_cflag & PARODD)
3477 cor1 |= (COR1_PARENB | COR1_PARODD);
3478 else
3479 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3480 } else {
3481 cor1 |= COR1_PARNONE;
3485 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3486 * space for hardware flow control and the like. This should be set to
3487 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3488 * really be based on VTIME.
3490 cor3 |= FIFO_RXTHRESHOLD;
3491 rtpr = 2;
3494 * Calculate the baud rate timers. For now we will just assume that
3495 * the input and output baud are the same. Could have used a baud
3496 * table here, but this way we can generate virtually any baud rate
3497 * we like!
3499 baudrate = tiosp->c_cflag & CBAUD;
3500 if (baudrate & CBAUDEX) {
3501 baudrate &= ~CBAUDEX;
3502 if ((baudrate < 1) || (baudrate > 4))
3503 tiosp->c_cflag &= ~CBAUDEX;
3504 else
3505 baudrate += 15;
3507 baudrate = stl_baudrates[baudrate];
3508 if ((tiosp->c_cflag & CBAUD) == B38400) {
3509 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3510 baudrate = 57600;
3511 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3512 baudrate = 115200;
3513 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3514 baudrate = 230400;
3515 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3516 baudrate = 460800;
3517 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3518 baudrate = (portp->baud_base / portp->custom_divisor);
3520 if (baudrate > STL_CD1400MAXBAUD)
3521 baudrate = STL_CD1400MAXBAUD;
3523 if (baudrate > 0) {
3524 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3525 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
3526 if (clkdiv < 0x100)
3527 break;
3529 div = (unsigned char) clkdiv;
3533 * Check what form of modem signaling is required and set it up.
3535 if ((tiosp->c_cflag & CLOCAL) == 0) {
3536 mcor1 |= MCOR1_DCD;
3537 mcor2 |= MCOR2_DCD;
3538 sreron |= SRER_MODEM;
3539 portp->flags |= ASYNC_CHECK_CD;
3540 } else {
3541 portp->flags &= ~ASYNC_CHECK_CD;
3545 * Setup cd1400 enhanced modes if we can. In particular we want to
3546 * handle as much of the flow control as possible automatically. As
3547 * well as saving a few CPU cycles it will also greatly improve flow
3548 * control reliability.
3550 if (tiosp->c_iflag & IXON) {
3551 cor2 |= COR2_TXIBE;
3552 cor3 |= COR3_SCD12;
3553 if (tiosp->c_iflag & IXANY)
3554 cor2 |= COR2_IXM;
3557 if (tiosp->c_cflag & CRTSCTS) {
3558 cor2 |= COR2_CTSAE;
3559 mcor1 |= FIFO_RTSTHRESHOLD;
3563 * All cd1400 register values calculated so go through and set
3564 * them all up.
3567 #if DEBUG
3568 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3569 portp->portnr, portp->panelnr, portp->brdnr);
3570 printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3571 cor1, cor2, cor3, cor4, cor5);
3572 printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3573 mcor1, mcor2, rtpr, sreron, sreroff);
3574 printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3575 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3576 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3577 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3578 #endif
3580 save_flags(flags);
3581 cli();
3582 BRDENABLE(portp->brdnr, portp->pagenr);
3583 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3584 srer = stl_cd1400getreg(portp, SRER);
3585 stl_cd1400setreg(portp, SRER, 0);
3586 if (stl_cd1400updatereg(portp, COR1, cor1))
3587 ccr = 1;
3588 if (stl_cd1400updatereg(portp, COR2, cor2))
3589 ccr = 1;
3590 if (stl_cd1400updatereg(portp, COR3, cor3))
3591 ccr = 1;
3592 if (ccr) {
3593 stl_cd1400ccrwait(portp);
3594 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3596 stl_cd1400setreg(portp, COR4, cor4);
3597 stl_cd1400setreg(portp, COR5, cor5);
3598 stl_cd1400setreg(portp, MCOR1, mcor1);
3599 stl_cd1400setreg(portp, MCOR2, mcor2);
3600 if (baudrate > 0) {
3601 stl_cd1400setreg(portp, TCOR, clk);
3602 stl_cd1400setreg(portp, TBPR, div);
3603 stl_cd1400setreg(portp, RCOR, clk);
3604 stl_cd1400setreg(portp, RBPR, div);
3606 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3607 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3608 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3609 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3610 stl_cd1400setreg(portp, RTPR, rtpr);
3611 mcor1 = stl_cd1400getreg(portp, MSVR1);
3612 if (mcor1 & MSVR1_DCD)
3613 portp->sigs |= TIOCM_CD;
3614 else
3615 portp->sigs &= ~TIOCM_CD;
3616 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3617 BRDDISABLE(portp->brdnr);
3618 restore_flags(flags);
3621 /*****************************************************************************/
3624 * Set the state of the DTR and RTS signals.
3627 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3629 unsigned char msvr1, msvr2;
3630 unsigned long flags;
3632 #if DEBUG
3633 printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
3634 (int) portp, dtr, rts);
3635 #endif
3637 msvr1 = 0;
3638 msvr2 = 0;
3639 if (dtr > 0)
3640 msvr1 = MSVR1_DTR;
3641 if (rts > 0)
3642 msvr2 = MSVR2_RTS;
3644 save_flags(flags);
3645 cli();
3646 BRDENABLE(portp->brdnr, portp->pagenr);
3647 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3648 if (rts >= 0)
3649 stl_cd1400setreg(portp, MSVR2, msvr2);
3650 if (dtr >= 0)
3651 stl_cd1400setreg(portp, MSVR1, msvr1);
3652 BRDDISABLE(portp->brdnr);
3653 restore_flags(flags);
3656 /*****************************************************************************/
3659 * Return the state of the signals.
3662 static int stl_cd1400getsignals(stlport_t *portp)
3664 unsigned char msvr1, msvr2;
3665 unsigned long flags;
3666 int sigs;
3668 #if DEBUG
3669 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3670 #endif
3672 save_flags(flags);
3673 cli();
3674 BRDENABLE(portp->brdnr, portp->pagenr);
3675 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3676 msvr1 = stl_cd1400getreg(portp, MSVR1);
3677 msvr2 = stl_cd1400getreg(portp, MSVR2);
3678 BRDDISABLE(portp->brdnr);
3679 restore_flags(flags);
3681 sigs = 0;
3682 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3683 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3684 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3685 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3686 #if 0
3687 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3688 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3689 #else
3690 sigs |= TIOCM_DSR;
3691 #endif
3692 return(sigs);
3695 /*****************************************************************************/
3698 * Enable/Disable the Transmitter and/or Receiver.
3701 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3703 unsigned char ccr;
3704 unsigned long flags;
3706 #if DEBUG
3707 printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3708 (int) portp, rx, tx);
3709 #endif
3710 ccr = 0;
3712 if (tx == 0)
3713 ccr |= CCR_TXDISABLE;
3714 else if (tx > 0)
3715 ccr |= CCR_TXENABLE;
3716 if (rx == 0)
3717 ccr |= CCR_RXDISABLE;
3718 else if (rx > 0)
3719 ccr |= CCR_RXENABLE;
3721 save_flags(flags);
3722 cli();
3723 BRDENABLE(portp->brdnr, portp->pagenr);
3724 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3725 stl_cd1400ccrwait(portp);
3726 stl_cd1400setreg(portp, CCR, ccr);
3727 stl_cd1400ccrwait(portp);
3728 BRDDISABLE(portp->brdnr);
3729 restore_flags(flags);
3732 /*****************************************************************************/
3735 * Start/stop the Transmitter and/or Receiver.
3738 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3740 unsigned char sreron, sreroff;
3741 unsigned long flags;
3743 #if DEBUG
3744 printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3745 (int) portp, rx, tx);
3746 #endif
3748 sreron = 0;
3749 sreroff = 0;
3750 if (tx == 0)
3751 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3752 else if (tx == 1)
3753 sreron |= SRER_TXDATA;
3754 else if (tx >= 2)
3755 sreron |= SRER_TXEMPTY;
3756 if (rx == 0)
3757 sreroff |= SRER_RXDATA;
3758 else if (rx > 0)
3759 sreron |= SRER_RXDATA;
3761 save_flags(flags);
3762 cli();
3763 BRDENABLE(portp->brdnr, portp->pagenr);
3764 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3765 stl_cd1400setreg(portp, SRER,
3766 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3767 BRDDISABLE(portp->brdnr);
3768 if (tx > 0)
3769 set_bit(ASYI_TXBUSY, &portp->istate);
3770 restore_flags(flags);
3773 /*****************************************************************************/
3776 * Disable all interrupts from this port.
3779 static void stl_cd1400disableintrs(stlport_t *portp)
3781 unsigned long flags;
3783 #if DEBUG
3784 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3785 #endif
3786 save_flags(flags);
3787 cli();
3788 BRDENABLE(portp->brdnr, portp->pagenr);
3789 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3790 stl_cd1400setreg(portp, SRER, 0);
3791 BRDDISABLE(portp->brdnr);
3792 restore_flags(flags);
3795 /*****************************************************************************/
3797 static void stl_cd1400sendbreak(stlport_t *portp, int len)
3799 unsigned long flags;
3801 #if DEBUG
3802 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
3803 #endif
3805 save_flags(flags);
3806 cli();
3807 BRDENABLE(portp->brdnr, portp->pagenr);
3808 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3809 stl_cd1400setreg(portp, SRER,
3810 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3811 SRER_TXEMPTY));
3812 BRDDISABLE(portp->brdnr);
3813 portp->brklen = len;
3814 if (len == 1)
3815 portp->stats.txbreaks++;
3816 restore_flags(flags);
3819 /*****************************************************************************/
3822 * Take flow control actions...
3825 static void stl_cd1400flowctrl(stlport_t *portp, int state)
3827 struct tty_struct *tty;
3828 unsigned long flags;
3830 #if DEBUG
3831 printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp, state);
3832 #endif
3834 if (portp == (stlport_t *) NULL)
3835 return;
3836 tty = portp->tty;
3837 if (tty == (struct tty_struct *) NULL)
3838 return;
3840 save_flags(flags);
3841 cli();
3842 BRDENABLE(portp->brdnr, portp->pagenr);
3843 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3845 if (state) {
3846 if (tty->termios->c_iflag & IXOFF) {
3847 stl_cd1400ccrwait(portp);
3848 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3849 portp->stats.rxxon++;
3850 stl_cd1400ccrwait(portp);
3853 * Question: should we return RTS to what it was before? It may
3854 * have been set by an ioctl... Suppose not, since if you have
3855 * hardware flow control set then it is pretty silly to go and
3856 * set the RTS line by hand.
3858 if (tty->termios->c_cflag & CRTSCTS) {
3859 stl_cd1400setreg(portp, MCOR1,
3860 (stl_cd1400getreg(portp, MCOR1) |
3861 FIFO_RTSTHRESHOLD));
3862 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3863 portp->stats.rxrtson++;
3865 } else {
3866 if (tty->termios->c_iflag & IXOFF) {
3867 stl_cd1400ccrwait(portp);
3868 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3869 portp->stats.rxxoff++;
3870 stl_cd1400ccrwait(portp);
3872 if (tty->termios->c_cflag & CRTSCTS) {
3873 stl_cd1400setreg(portp, MCOR1,
3874 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3875 stl_cd1400setreg(portp, MSVR2, 0);
3876 portp->stats.rxrtsoff++;
3880 BRDDISABLE(portp->brdnr);
3881 restore_flags(flags);
3884 /*****************************************************************************/
3887 * Send a flow control character...
3890 static void stl_cd1400sendflow(stlport_t *portp, int state)
3892 struct tty_struct *tty;
3893 unsigned long flags;
3895 #if DEBUG
3896 printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp, state);
3897 #endif
3899 if (portp == (stlport_t *) NULL)
3900 return;
3901 tty = portp->tty;
3902 if (tty == (struct tty_struct *) NULL)
3903 return;
3905 save_flags(flags);
3906 cli();
3907 BRDENABLE(portp->brdnr, portp->pagenr);
3908 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3909 if (state) {
3910 stl_cd1400ccrwait(portp);
3911 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3912 portp->stats.rxxon++;
3913 stl_cd1400ccrwait(portp);
3914 } else {
3915 stl_cd1400ccrwait(portp);
3916 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3917 portp->stats.rxxoff++;
3918 stl_cd1400ccrwait(portp);
3920 BRDDISABLE(portp->brdnr);
3921 restore_flags(flags);
3924 /*****************************************************************************/
3926 static void stl_cd1400flush(stlport_t *portp)
3928 unsigned long flags;
3930 #if DEBUG
3931 printk("stl_cd1400flush(portp=%x)\n", (int) portp);
3932 #endif
3934 if (portp == (stlport_t *) NULL)
3935 return;
3937 save_flags(flags);
3938 cli();
3939 BRDENABLE(portp->brdnr, portp->pagenr);
3940 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3941 stl_cd1400ccrwait(portp);
3942 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3943 stl_cd1400ccrwait(portp);
3944 portp->tx.tail = portp->tx.head;
3945 BRDDISABLE(portp->brdnr);
3946 restore_flags(flags);
3949 /*****************************************************************************/
3952 * Return the current state of data flow on this port. This is only
3953 * really interresting when determining if data has fully completed
3954 * transmission or not... This is easy for the cd1400, it accurately
3955 * maintains the busy port flag.
3958 static int stl_cd1400datastate(stlport_t *portp)
3960 #if DEBUG
3961 printk("stl_cd1400datastate(portp=%x)\n", (int) portp);
3962 #endif
3964 if (portp == (stlport_t *) NULL)
3965 return(0);
3967 return(test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0);
3970 /*****************************************************************************/
3973 * Interrupt service routine for cd1400 EasyIO boards.
3976 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3978 unsigned char svrtype;
3980 #if DEBUG
3981 printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
3982 (int) panelp, iobase);
3983 #endif
3985 outb(SVRR, iobase);
3986 svrtype = inb(iobase + EREG_DATA);
3987 if (panelp->nrports > 4) {
3988 outb((SVRR + 0x80), iobase);
3989 svrtype |= inb(iobase + EREG_DATA);
3992 if (svrtype & SVRR_RX)
3993 stl_cd1400rxisr(panelp, iobase);
3994 else if (svrtype & SVRR_TX)
3995 stl_cd1400txisr(panelp, iobase);
3996 else if (svrtype & SVRR_MDM)
3997 stl_cd1400mdmisr(panelp, iobase);
4000 /*****************************************************************************/
4003 * Interrupt service routine for cd1400 panels.
4006 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
4008 unsigned char svrtype;
4010 #if DEBUG
4011 printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
4012 iobase);
4013 #endif
4015 outb(SVRR, iobase);
4016 svrtype = inb(iobase + EREG_DATA);
4017 outb((SVRR + 0x80), iobase);
4018 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);
4028 /*****************************************************************************/
4031 * Unfortunately we need to handle breaks in the TX data stream, since
4032 * this is the only way to generate them on the cd1400.
4035 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr)
4037 if (portp->brklen == 1) {
4038 outb((COR2 + portp->uartaddr), ioaddr);
4039 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
4040 (ioaddr + EREG_DATA));
4041 outb((TDR + portp->uartaddr), ioaddr);
4042 outb(ETC_CMD, (ioaddr + EREG_DATA));
4043 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
4044 outb((SRER + portp->uartaddr), ioaddr);
4045 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
4046 (ioaddr + EREG_DATA));
4047 return(1);
4048 } else if (portp->brklen > 1) {
4049 outb((TDR + portp->uartaddr), ioaddr);
4050 outb(ETC_CMD, (ioaddr + EREG_DATA));
4051 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
4052 portp->brklen = -1;
4053 return(1);
4054 } else {
4055 outb((COR2 + portp->uartaddr), ioaddr);
4056 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
4057 (ioaddr + EREG_DATA));
4058 portp->brklen = 0;
4060 return(0);
4063 /*****************************************************************************/
4066 * Transmit interrupt handler. This has gotta be fast! Handling TX
4067 * chars is pretty simple, stuff as many as possible from the TX buffer
4068 * into the cd1400 FIFO. Must also handle TX breaks here, since they
4069 * are embedded as commands in the data stream. Oh no, had to use a goto!
4070 * This could be optimized more, will do when I get time...
4071 * In practice it is possible that interrupts are enabled but that the
4072 * port has been hung up. Need to handle not having any TX buffer here,
4073 * this is done by using the side effect that head and tail will also
4074 * be NULL if the buffer has been freed.
4077 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
4079 stlport_t *portp;
4080 int len, stlen;
4081 char *head, *tail;
4082 unsigned char ioack, srer;
4084 #if DEBUG
4085 printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
4086 #endif
4088 ioack = inb(ioaddr + EREG_TXACK);
4089 if (((ioack & panelp->ackmask) != 0) ||
4090 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
4091 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
4092 return;
4094 portp = panelp->ports[(ioack >> 3)];
4097 * Unfortunately we need to handle breaks in the data stream, since
4098 * this is the only way to generate them on the cd1400. Do it now if
4099 * a break is to be sent.
4101 if (portp->brklen != 0)
4102 if (stl_cd1400breakisr(portp, ioaddr))
4103 goto stl_txalldone;
4105 head = portp->tx.head;
4106 tail = portp->tx.tail;
4107 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4108 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4109 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4110 set_bit(ASYI_TXLOW, &portp->istate);
4111 queue_task(&portp->tqueue, &tq_scheduler);
4114 if (len == 0) {
4115 outb((SRER + portp->uartaddr), ioaddr);
4116 srer = inb(ioaddr + EREG_DATA);
4117 if (srer & SRER_TXDATA) {
4118 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
4119 } else {
4120 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
4121 clear_bit(ASYI_TXBUSY, &portp->istate);
4123 outb(srer, (ioaddr + EREG_DATA));
4124 } else {
4125 len = MIN(len, CD1400_TXFIFOSIZE);
4126 portp->stats.txtotal += len;
4127 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4128 outb((TDR + portp->uartaddr), ioaddr);
4129 outsb((ioaddr + EREG_DATA), tail, stlen);
4130 len -= stlen;
4131 tail += stlen;
4132 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4133 tail = portp->tx.buf;
4134 if (len > 0) {
4135 outsb((ioaddr + EREG_DATA), tail, len);
4136 tail += len;
4138 portp->tx.tail = tail;
4141 stl_txalldone:
4142 outb((EOSRR + portp->uartaddr), ioaddr);
4143 outb(0, (ioaddr + EREG_DATA));
4146 /*****************************************************************************/
4149 * Receive character interrupt handler. Determine if we have good chars
4150 * or bad chars and then process appropriately. Good chars are easy
4151 * just shove the lot into the RX buffer and set all status byte to 0.
4152 * If a bad RX char then process as required. This routine needs to be
4153 * fast! In practice it is possible that we get an interrupt on a port
4154 * that is closed. This can happen on hangups - since they completely
4155 * shutdown a port not in user context. Need to handle this case.
4158 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
4160 stlport_t *portp;
4161 struct tty_struct *tty;
4162 unsigned int ioack, len, buflen;
4163 unsigned char status;
4164 char ch;
4166 #if DEBUG
4167 printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
4168 #endif
4170 ioack = inb(ioaddr + EREG_RXACK);
4171 if ((ioack & panelp->ackmask) != 0) {
4172 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4173 return;
4175 portp = panelp->ports[(ioack >> 3)];
4176 tty = portp->tty;
4178 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
4179 outb((RDCR + portp->uartaddr), ioaddr);
4180 len = inb(ioaddr + EREG_DATA);
4181 if ((tty == (struct tty_struct *) NULL) ||
4182 (tty->flip.char_buf_ptr == (char *) NULL) ||
4183 ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
4184 len = MIN(len, sizeof(stl_unwanted));
4185 outb((RDSR + portp->uartaddr), ioaddr);
4186 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
4187 portp->stats.rxlost += len;
4188 portp->stats.rxtotal += len;
4189 } else {
4190 len = MIN(len, buflen);
4191 if (len > 0) {
4192 outb((RDSR + portp->uartaddr), ioaddr);
4193 insb((ioaddr + EREG_DATA), tty->flip.char_buf_ptr, len);
4194 memset(tty->flip.flag_buf_ptr, 0, len);
4195 tty->flip.flag_buf_ptr += len;
4196 tty->flip.char_buf_ptr += len;
4197 tty->flip.count += len;
4198 tty_schedule_flip(tty);
4199 portp->stats.rxtotal += len;
4202 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
4203 outb((RDSR + portp->uartaddr), ioaddr);
4204 status = inb(ioaddr + EREG_DATA);
4205 ch = inb(ioaddr + EREG_DATA);
4206 if (status & ST_PARITY)
4207 portp->stats.rxparity++;
4208 if (status & ST_FRAMING)
4209 portp->stats.rxframing++;
4210 if (status & ST_OVERRUN)
4211 portp->stats.rxoverrun++;
4212 if (status & ST_BREAK)
4213 portp->stats.rxbreaks++;
4214 if (status & ST_SCHARMASK) {
4215 if ((status & ST_SCHARMASK) == ST_SCHAR1)
4216 portp->stats.txxon++;
4217 if ((status & ST_SCHARMASK) == ST_SCHAR2)
4218 portp->stats.txxoff++;
4219 goto stl_rxalldone;
4221 if ((tty != (struct tty_struct *) NULL) &&
4222 ((portp->rxignoremsk & status) == 0)) {
4223 if (portp->rxmarkmsk & status) {
4224 if (status & ST_BREAK) {
4225 status = TTY_BREAK;
4226 if (portp->flags & ASYNC_SAK) {
4227 do_SAK(tty);
4228 BRDENABLE(portp->brdnr, portp->pagenr);
4230 } else if (status & ST_PARITY) {
4231 status = TTY_PARITY;
4232 } else if (status & ST_FRAMING) {
4233 status = TTY_FRAME;
4234 } else if(status & ST_OVERRUN) {
4235 status = TTY_OVERRUN;
4236 } else {
4237 status = 0;
4239 } else {
4240 status = 0;
4242 if (tty->flip.char_buf_ptr != (char *) NULL) {
4243 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
4244 *tty->flip.flag_buf_ptr++ = status;
4245 *tty->flip.char_buf_ptr++ = ch;
4246 tty->flip.count++;
4248 tty_schedule_flip(tty);
4251 } else {
4252 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4253 return;
4256 stl_rxalldone:
4257 outb((EOSRR + portp->uartaddr), ioaddr);
4258 outb(0, (ioaddr + EREG_DATA));
4261 /*****************************************************************************/
4264 * Modem interrupt handler. The is called when the modem signal line
4265 * (DCD) has changed state. Leave most of the work to the off-level
4266 * processing routine.
4269 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
4271 stlport_t *portp;
4272 unsigned int ioack;
4273 unsigned char misr;
4275 #if DEBUG
4276 printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp);
4277 #endif
4279 ioack = inb(ioaddr + EREG_MDACK);
4280 if (((ioack & panelp->ackmask) != 0) ||
4281 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
4282 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
4283 return;
4285 portp = panelp->ports[(ioack >> 3)];
4287 outb((MISR + portp->uartaddr), ioaddr);
4288 misr = inb(ioaddr + EREG_DATA);
4289 if (misr & MISR_DCD) {
4290 set_bit(ASYI_DCDCHANGE, &portp->istate);
4291 queue_task(&portp->tqueue, &tq_scheduler);
4292 portp->stats.modem++;
4295 outb((EOSRR + portp->uartaddr), ioaddr);
4296 outb(0, (ioaddr + EREG_DATA));
4299 /*****************************************************************************/
4300 /* SC26198 HARDWARE FUNCTIONS */
4301 /*****************************************************************************/
4304 * These functions get/set/update the registers of the sc26198 UARTs.
4305 * Access to the sc26198 registers is via an address/data io port pair.
4306 * (Maybe should make this inline...)
4309 static int stl_sc26198getreg(stlport_t *portp, int regnr)
4311 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4312 return(inb(portp->ioaddr + XP_DATA));
4315 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
4317 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4318 outb(value, (portp->ioaddr + XP_DATA));
4321 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
4323 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4324 if (inb(portp->ioaddr + XP_DATA) != value) {
4325 outb(value, (portp->ioaddr + XP_DATA));
4326 return(1);
4328 return(0);
4331 /*****************************************************************************/
4334 * Functions to get and set the sc26198 global registers.
4337 static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
4339 outb(regnr, (portp->ioaddr + XP_ADDR));
4340 return(inb(portp->ioaddr + XP_DATA));
4343 #if 0
4344 static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
4346 outb(regnr, (portp->ioaddr + XP_ADDR));
4347 outb(value, (portp->ioaddr + XP_DATA));
4349 #endif
4351 /*****************************************************************************/
4354 * Inbitialize the UARTs in a panel. We don't care what sort of board
4355 * these ports are on - since the port io registers are almost
4356 * identical when dealing with ports.
4359 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
4361 int chipmask, i;
4362 int nrchips, ioaddr;
4364 #if DEBUG
4365 printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
4366 (int) brdp, (int) panelp);
4367 #endif
4369 BRDENABLE(panelp->brdnr, panelp->pagenr);
4372 * Check that each chip is present and started up OK.
4374 chipmask = 0;
4375 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
4376 if (brdp->brdtype == BRD_ECHPCI)
4377 outb(panelp->pagenr, brdp->ioctrl);
4379 for (i = 0; (i < nrchips); i++) {
4380 ioaddr = panelp->iobase + (i * 4);
4381 outb(SCCR, (ioaddr + XP_ADDR));
4382 outb(CR_RESETALL, (ioaddr + XP_DATA));
4383 outb(TSTR, (ioaddr + XP_ADDR));
4384 if (inb(ioaddr + XP_DATA) != 0) {
4385 printk("STALLION: sc26198 not responding, "
4386 "brd=%d panel=%d chip=%d\n",
4387 panelp->brdnr, panelp->panelnr, i);
4388 continue;
4390 chipmask |= (0x1 << i);
4391 outb(GCCR, (ioaddr + XP_ADDR));
4392 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
4393 outb(WDTRCR, (ioaddr + XP_ADDR));
4394 outb(0xff, (ioaddr + XP_DATA));
4397 BRDDISABLE(panelp->brdnr);
4398 return(chipmask);
4401 /*****************************************************************************/
4404 * Initialize hardware specific port registers.
4407 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
4409 #if DEBUG
4410 printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
4411 (int) brdp, (int) panelp, (int) portp);
4412 #endif
4414 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
4415 (portp == (stlport_t *) NULL))
4416 return;
4418 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
4419 portp->uartaddr = (portp->portnr & 0x07) << 4;
4420 portp->pagenr = panelp->pagenr;
4421 portp->hwid = 0x1;
4423 BRDENABLE(portp->brdnr, portp->pagenr);
4424 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
4425 BRDDISABLE(portp->brdnr);
4428 /*****************************************************************************/
4431 * Set up the sc26198 registers for a port based on the termios port
4432 * settings.
4435 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4437 stlbrd_t *brdp;
4438 unsigned long flags;
4439 unsigned int baudrate;
4440 unsigned char mr0, mr1, mr2, clk;
4441 unsigned char imron, imroff, iopr, ipr;
4443 mr0 = 0;
4444 mr1 = 0;
4445 mr2 = 0;
4446 clk = 0;
4447 iopr = 0;
4448 imron = 0;
4449 imroff = 0;
4451 brdp = stl_brds[portp->brdnr];
4452 if (brdp == (stlbrd_t *) NULL)
4453 return;
4456 * Set up the RX char ignore mask with those RX error types we
4457 * can ignore.
4459 portp->rxignoremsk = 0;
4460 if (tiosp->c_iflag & IGNPAR)
4461 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
4462 SR_RXOVERRUN);
4463 if (tiosp->c_iflag & IGNBRK)
4464 portp->rxignoremsk |= SR_RXBREAK;
4466 portp->rxmarkmsk = SR_RXOVERRUN;
4467 if (tiosp->c_iflag & (INPCK | PARMRK))
4468 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
4469 if (tiosp->c_iflag & BRKINT)
4470 portp->rxmarkmsk |= SR_RXBREAK;
4473 * Go through the char size, parity and stop bits and set all the
4474 * option register appropriately.
4476 switch (tiosp->c_cflag & CSIZE) {
4477 case CS5:
4478 mr1 |= MR1_CS5;
4479 break;
4480 case CS6:
4481 mr1 |= MR1_CS6;
4482 break;
4483 case CS7:
4484 mr1 |= MR1_CS7;
4485 break;
4486 default:
4487 mr1 |= MR1_CS8;
4488 break;
4491 if (tiosp->c_cflag & CSTOPB)
4492 mr2 |= MR2_STOP2;
4493 else
4494 mr2 |= MR2_STOP1;
4496 if (tiosp->c_cflag & PARENB) {
4497 if (tiosp->c_cflag & PARODD)
4498 mr1 |= (MR1_PARENB | MR1_PARODD);
4499 else
4500 mr1 |= (MR1_PARENB | MR1_PAREVEN);
4501 } else {
4502 mr1 |= MR1_PARNONE;
4505 mr1 |= MR1_ERRBLOCK;
4508 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4509 * space for hardware flow control and the like. This should be set to
4510 * VMIN.
4512 mr2 |= MR2_RXFIFOHALF;
4515 * Calculate the baud rate timers. For now we will just assume that
4516 * the input and output baud are the same. The sc26198 has a fixed
4517 * baud rate table, so only discrete baud rates possible.
4519 baudrate = tiosp->c_cflag & CBAUD;
4520 if (baudrate & CBAUDEX) {
4521 baudrate &= ~CBAUDEX;
4522 if ((baudrate < 1) || (baudrate > 4))
4523 tiosp->c_cflag &= ~CBAUDEX;
4524 else
4525 baudrate += 15;
4527 baudrate = stl_baudrates[baudrate];
4528 if ((tiosp->c_cflag & CBAUD) == B38400) {
4529 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
4530 baudrate = 57600;
4531 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
4532 baudrate = 115200;
4533 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
4534 baudrate = 230400;
4535 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
4536 baudrate = 460800;
4537 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
4538 baudrate = (portp->baud_base / portp->custom_divisor);
4540 if (baudrate > STL_SC26198MAXBAUD)
4541 baudrate = STL_SC26198MAXBAUD;
4543 if (baudrate > 0) {
4544 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
4545 if (baudrate <= sc26198_baudtable[clk])
4546 break;
4551 * Check what form of modem signaling is required and set it up.
4553 if (tiosp->c_cflag & CLOCAL) {
4554 portp->flags &= ~ASYNC_CHECK_CD;
4555 } else {
4556 iopr |= IOPR_DCDCOS;
4557 imron |= IR_IOPORT;
4558 portp->flags |= ASYNC_CHECK_CD;
4562 * Setup sc26198 enhanced modes if we can. In particular we want to
4563 * handle as much of the flow control as possible automatically. As
4564 * well as saving a few CPU cycles it will also greatly improve flow
4565 * control reliability.
4567 if (tiosp->c_iflag & IXON) {
4568 mr0 |= MR0_SWFTX | MR0_SWFT;
4569 imron |= IR_XONXOFF;
4570 } else {
4571 imroff |= IR_XONXOFF;
4573 if (tiosp->c_iflag & IXOFF)
4574 mr0 |= MR0_SWFRX;
4576 if (tiosp->c_cflag & CRTSCTS) {
4577 mr2 |= MR2_AUTOCTS;
4578 mr1 |= MR1_AUTORTS;
4582 * All sc26198 register values calculated so go through and set
4583 * them all up.
4586 #if DEBUG
4587 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4588 portp->portnr, portp->panelnr, portp->brdnr);
4589 printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4590 printk(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4591 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4592 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4593 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4594 #endif
4596 save_flags(flags);
4597 cli();
4598 BRDENABLE(portp->brdnr, portp->pagenr);
4599 stl_sc26198setreg(portp, IMR, 0);
4600 stl_sc26198updatereg(portp, MR0, mr0);
4601 stl_sc26198updatereg(portp, MR1, mr1);
4602 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4603 stl_sc26198updatereg(portp, MR2, mr2);
4604 stl_sc26198updatereg(portp, IOPIOR,
4605 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
4607 if (baudrate > 0) {
4608 stl_sc26198setreg(portp, TXCSR, clk);
4609 stl_sc26198setreg(portp, RXCSR, clk);
4612 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4613 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4615 ipr = stl_sc26198getreg(portp, IPR);
4616 if (ipr & IPR_DCD)
4617 portp->sigs &= ~TIOCM_CD;
4618 else
4619 portp->sigs |= TIOCM_CD;
4621 portp->imr = (portp->imr & ~imroff) | imron;
4622 stl_sc26198setreg(portp, IMR, portp->imr);
4623 BRDDISABLE(portp->brdnr);
4624 restore_flags(flags);
4627 /*****************************************************************************/
4630 * Set the state of the DTR and RTS signals.
4633 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
4635 unsigned char iopioron, iopioroff;
4636 unsigned long flags;
4638 #if DEBUG
4639 printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4640 (int) portp, dtr, rts);
4641 #endif
4643 iopioron = 0;
4644 iopioroff = 0;
4645 if (dtr == 0)
4646 iopioroff |= IPR_DTR;
4647 else if (dtr > 0)
4648 iopioron |= IPR_DTR;
4649 if (rts == 0)
4650 iopioroff |= IPR_RTS;
4651 else if (rts > 0)
4652 iopioron |= IPR_RTS;
4654 save_flags(flags);
4655 cli();
4656 BRDENABLE(portp->brdnr, portp->pagenr);
4657 stl_sc26198setreg(portp, IOPIOR,
4658 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4659 BRDDISABLE(portp->brdnr);
4660 restore_flags(flags);
4663 /*****************************************************************************/
4666 * Return the state of the signals.
4669 static int stl_sc26198getsignals(stlport_t *portp)
4671 unsigned char ipr;
4672 unsigned long flags;
4673 int sigs;
4675 #if DEBUG
4676 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
4677 #endif
4679 save_flags(flags);
4680 cli();
4681 BRDENABLE(portp->brdnr, portp->pagenr);
4682 ipr = stl_sc26198getreg(portp, IPR);
4683 BRDDISABLE(portp->brdnr);
4684 restore_flags(flags);
4686 sigs = 0;
4687 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4688 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4689 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4690 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4691 sigs |= TIOCM_DSR;
4692 return(sigs);
4695 /*****************************************************************************/
4698 * Enable/Disable the Transmitter and/or Receiver.
4701 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
4703 unsigned char ccr;
4704 unsigned long flags;
4706 #if DEBUG
4707 printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4708 (int) portp, rx, tx);
4709 #endif
4711 ccr = portp->crenable;
4712 if (tx == 0)
4713 ccr &= ~CR_TXENABLE;
4714 else if (tx > 0)
4715 ccr |= CR_TXENABLE;
4716 if (rx == 0)
4717 ccr &= ~CR_RXENABLE;
4718 else if (rx > 0)
4719 ccr |= CR_RXENABLE;
4721 save_flags(flags);
4722 cli();
4723 BRDENABLE(portp->brdnr, portp->pagenr);
4724 stl_sc26198setreg(portp, SCCR, ccr);
4725 BRDDISABLE(portp->brdnr);
4726 portp->crenable = ccr;
4727 restore_flags(flags);
4730 /*****************************************************************************/
4733 * Start/stop the Transmitter and/or Receiver.
4736 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
4738 unsigned char imr;
4739 unsigned long flags;
4741 #if DEBUG
4742 printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4743 (int) portp, rx, tx);
4744 #endif
4746 imr = portp->imr;
4747 if (tx == 0)
4748 imr &= ~IR_TXRDY;
4749 else if (tx == 1)
4750 imr |= IR_TXRDY;
4751 if (rx == 0)
4752 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4753 else if (rx > 0)
4754 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4756 save_flags(flags);
4757 cli();
4758 BRDENABLE(portp->brdnr, portp->pagenr);
4759 stl_sc26198setreg(portp, IMR, imr);
4760 BRDDISABLE(portp->brdnr);
4761 portp->imr = imr;
4762 if (tx > 0)
4763 set_bit(ASYI_TXBUSY, &portp->istate);
4764 restore_flags(flags);
4767 /*****************************************************************************/
4770 * Disable all interrupts from this port.
4773 static void stl_sc26198disableintrs(stlport_t *portp)
4775 unsigned long flags;
4777 #if DEBUG
4778 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
4779 #endif
4781 save_flags(flags);
4782 cli();
4783 BRDENABLE(portp->brdnr, portp->pagenr);
4784 portp->imr = 0;
4785 stl_sc26198setreg(portp, IMR, 0);
4786 BRDDISABLE(portp->brdnr);
4787 restore_flags(flags);
4790 /*****************************************************************************/
4792 static void stl_sc26198sendbreak(stlport_t *portp, int len)
4794 unsigned long flags;
4796 #if DEBUG
4797 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
4798 #endif
4800 save_flags(flags);
4801 cli();
4802 BRDENABLE(portp->brdnr, portp->pagenr);
4803 if (len == 1) {
4804 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4805 portp->stats.txbreaks++;
4806 } else {
4807 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4809 BRDDISABLE(portp->brdnr);
4810 restore_flags(flags);
4813 /*****************************************************************************/
4816 * Take flow control actions...
4819 static void stl_sc26198flowctrl(stlport_t *portp, int state)
4821 struct tty_struct *tty;
4822 unsigned long flags;
4823 unsigned char mr0;
4825 #if DEBUG
4826 printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp, state);
4827 #endif
4829 if (portp == (stlport_t *) NULL)
4830 return;
4831 tty = portp->tty;
4832 if (tty == (struct tty_struct *) NULL)
4833 return;
4835 save_flags(flags);
4836 cli();
4837 BRDENABLE(portp->brdnr, portp->pagenr);
4839 if (state) {
4840 if (tty->termios->c_iflag & IXOFF) {
4841 mr0 = stl_sc26198getreg(portp, MR0);
4842 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4843 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4844 mr0 |= MR0_SWFRX;
4845 portp->stats.rxxon++;
4846 stl_sc26198wait(portp);
4847 stl_sc26198setreg(portp, MR0, mr0);
4850 * Question: should we return RTS to what it was before? It may
4851 * have been set by an ioctl... Suppose not, since if you have
4852 * hardware flow control set then it is pretty silly to go and
4853 * set the RTS line by hand.
4855 if (tty->termios->c_cflag & CRTSCTS) {
4856 stl_sc26198setreg(portp, MR1,
4857 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4858 stl_sc26198setreg(portp, IOPIOR,
4859 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4860 portp->stats.rxrtson++;
4862 } else {
4863 if (tty->termios->c_iflag & IXOFF) {
4864 mr0 = stl_sc26198getreg(portp, MR0);
4865 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4866 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4867 mr0 &= ~MR0_SWFRX;
4868 portp->stats.rxxoff++;
4869 stl_sc26198wait(portp);
4870 stl_sc26198setreg(portp, MR0, mr0);
4872 if (tty->termios->c_cflag & CRTSCTS) {
4873 stl_sc26198setreg(portp, MR1,
4874 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4875 stl_sc26198setreg(portp, IOPIOR,
4876 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4877 portp->stats.rxrtsoff++;
4881 BRDDISABLE(portp->brdnr);
4882 restore_flags(flags);
4885 /*****************************************************************************/
4888 * Send a flow control character.
4891 static void stl_sc26198sendflow(stlport_t *portp, int state)
4893 struct tty_struct *tty;
4894 unsigned long flags;
4895 unsigned char mr0;
4897 #if DEBUG
4898 printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp, state);
4899 #endif
4901 if (portp == (stlport_t *) NULL)
4902 return;
4903 tty = portp->tty;
4904 if (tty == (struct tty_struct *) NULL)
4905 return;
4907 save_flags(flags);
4908 cli();
4909 BRDENABLE(portp->brdnr, portp->pagenr);
4910 if (state) {
4911 mr0 = stl_sc26198getreg(portp, MR0);
4912 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4913 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4914 mr0 |= MR0_SWFRX;
4915 portp->stats.rxxon++;
4916 stl_sc26198wait(portp);
4917 stl_sc26198setreg(portp, MR0, mr0);
4918 } else {
4919 mr0 = stl_sc26198getreg(portp, MR0);
4920 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4921 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4922 mr0 &= ~MR0_SWFRX;
4923 portp->stats.rxxoff++;
4924 stl_sc26198wait(portp);
4925 stl_sc26198setreg(portp, MR0, mr0);
4927 BRDDISABLE(portp->brdnr);
4928 restore_flags(flags);
4931 /*****************************************************************************/
4933 static void stl_sc26198flush(stlport_t *portp)
4935 unsigned long flags;
4937 #if DEBUG
4938 printk("stl_sc26198flush(portp=%x)\n", (int) portp);
4939 #endif
4941 if (portp == (stlport_t *) NULL)
4942 return;
4944 save_flags(flags);
4945 cli();
4946 BRDENABLE(portp->brdnr, portp->pagenr);
4947 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4948 stl_sc26198setreg(portp, SCCR, portp->crenable);
4949 BRDDISABLE(portp->brdnr);
4950 portp->tx.tail = portp->tx.head;
4951 restore_flags(flags);
4954 /*****************************************************************************/
4957 * Return the current state of data flow on this port. This is only
4958 * really interresting when determining if data has fully completed
4959 * transmission or not... The sc26198 interrupt scheme cannot
4960 * determine when all data has actually drained, so we need to
4961 * check the port statusy register to be sure.
4964 static int stl_sc26198datastate(stlport_t *portp)
4966 unsigned long flags;
4967 unsigned char sr;
4969 #if DEBUG
4970 printk("stl_sc26198datastate(portp=%x)\n", (int) portp);
4971 #endif
4973 if (portp == (stlport_t *) NULL)
4974 return(0);
4975 if (test_bit(ASYI_TXBUSY, &portp->istate))
4976 return(1);
4978 save_flags(flags);
4979 cli();
4980 BRDENABLE(portp->brdnr, portp->pagenr);
4981 sr = stl_sc26198getreg(portp, SR);
4982 BRDDISABLE(portp->brdnr);
4983 restore_flags(flags);
4985 return((sr & SR_TXEMPTY) ? 0 : 1);
4988 /*****************************************************************************/
4991 * Delay for a small amount of time, to give the sc26198 a chance
4992 * to process a command...
4995 static void stl_sc26198wait(stlport_t *portp)
4997 int i;
4999 #if DEBUG
5000 printk("stl_sc26198wait(portp=%x)\n", (int) portp);
5001 #endif
5003 if (portp == (stlport_t *) NULL)
5004 return;
5006 for (i = 0; (i < 20); i++)
5007 stl_sc26198getglobreg(portp, TSTR);
5010 /*****************************************************************************/
5013 * If we are TX flow controlled and in IXANY mode then we may
5014 * need to unflow control here. We gotta do this because of the
5015 * automatic flow control modes of the sc26198.
5018 static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty)
5020 unsigned char mr0;
5022 mr0 = stl_sc26198getreg(portp, MR0);
5023 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
5024 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
5025 stl_sc26198wait(portp);
5026 stl_sc26198setreg(portp, MR0, mr0);
5027 clear_bit(ASYI_TXFLOWED, &portp->istate);
5030 /*****************************************************************************/
5033 * Interrupt service routine for sc26198 panels.
5036 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
5038 stlport_t *portp;
5039 unsigned int iack;
5042 * Work around bug in sc26198 chip... Cannot have A6 address
5043 * line of UART high, else iack will be returned as 0.
5045 outb(0, (iobase + 1));
5047 iack = inb(iobase + XP_IACK);
5048 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
5050 if (iack & IVR_RXDATA)
5051 stl_sc26198rxisr(portp, iack);
5052 else if (iack & IVR_TXDATA)
5053 stl_sc26198txisr(portp);
5054 else
5055 stl_sc26198otherisr(portp, iack);
5058 /*****************************************************************************/
5061 * Transmit interrupt handler. This has gotta be fast! Handling TX
5062 * chars is pretty simple, stuff as many as possible from the TX buffer
5063 * into the sc26198 FIFO.
5064 * In practice it is possible that interrupts are enabled but that the
5065 * port has been hung up. Need to handle not having any TX buffer here,
5066 * this is done by using the side effect that head and tail will also
5067 * be NULL if the buffer has been freed.
5070 static void stl_sc26198txisr(stlport_t *portp)
5072 unsigned int ioaddr;
5073 unsigned char mr0;
5074 int len, stlen;
5075 char *head, *tail;
5077 #if DEBUG
5078 printk("stl_sc26198txisr(portp=%x)\n", (int) portp);
5079 #endif
5081 ioaddr = portp->ioaddr;
5082 head = portp->tx.head;
5083 tail = portp->tx.tail;
5084 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
5085 if ((len == 0) || ((len < STL_TXBUFLOW) &&
5086 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
5087 set_bit(ASYI_TXLOW, &portp->istate);
5088 queue_task(&portp->tqueue, &tq_scheduler);
5091 if (len == 0) {
5092 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
5093 mr0 = inb(ioaddr + XP_DATA);
5094 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
5095 portp->imr &= ~IR_TXRDY;
5096 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
5097 outb(portp->imr, (ioaddr + XP_DATA));
5098 clear_bit(ASYI_TXBUSY, &portp->istate);
5099 } else {
5100 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
5101 outb(mr0, (ioaddr + XP_DATA));
5103 } else {
5104 len = MIN(len, SC26198_TXFIFOSIZE);
5105 portp->stats.txtotal += len;
5106 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
5107 outb(GTXFIFO, (ioaddr + XP_ADDR));
5108 outsb((ioaddr + XP_DATA), tail, stlen);
5109 len -= stlen;
5110 tail += stlen;
5111 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
5112 tail = portp->tx.buf;
5113 if (len > 0) {
5114 outsb((ioaddr + XP_DATA), tail, len);
5115 tail += len;
5117 portp->tx.tail = tail;
5121 /*****************************************************************************/
5124 * Receive character interrupt handler. Determine if we have good chars
5125 * or bad chars and then process appropriately. Good chars are easy
5126 * just shove the lot into the RX buffer and set all status byte to 0.
5127 * If a bad RX char then process as required. This routine needs to be
5128 * fast! In practice it is possible that we get an interrupt on a port
5129 * that is closed. This can happen on hangups - since they completely
5130 * shutdown a port not in user context. Need to handle this case.
5133 static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
5135 struct tty_struct *tty;
5136 unsigned int len, buflen, ioaddr;
5138 #if DEBUG
5139 printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
5140 #endif
5142 tty = portp->tty;
5143 ioaddr = portp->ioaddr;
5144 outb(GIBCR, (ioaddr + XP_ADDR));
5145 len = inb(ioaddr + XP_DATA) + 1;
5147 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
5148 if ((tty == (struct tty_struct *) NULL) ||
5149 (tty->flip.char_buf_ptr == (char *) NULL) ||
5150 ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
5151 len = MIN(len, sizeof(stl_unwanted));
5152 outb(GRXFIFO, (ioaddr + XP_ADDR));
5153 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
5154 portp->stats.rxlost += len;
5155 portp->stats.rxtotal += len;
5156 } else {
5157 len = MIN(len, buflen);
5158 if (len > 0) {
5159 outb(GRXFIFO, (ioaddr + XP_ADDR));
5160 insb((ioaddr + XP_DATA), tty->flip.char_buf_ptr, len);
5161 memset(tty->flip.flag_buf_ptr, 0, len);
5162 tty->flip.flag_buf_ptr += len;
5163 tty->flip.char_buf_ptr += len;
5164 tty->flip.count += len;
5165 tty_schedule_flip(tty);
5166 portp->stats.rxtotal += len;
5169 } else {
5170 stl_sc26198rxbadchars(portp);
5174 * If we are TX flow controlled and in IXANY mode then we may need
5175 * to unflow control here. We gotta do this because of the automatic
5176 * flow control modes of the sc26198.
5178 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
5179 if ((tty != (struct tty_struct *) NULL) &&
5180 (tty->termios != (struct termios *) NULL) &&
5181 (tty->termios->c_iflag & IXANY)) {
5182 stl_sc26198txunflow(portp, tty);
5187 /*****************************************************************************/
5190 * Process an RX bad character.
5193 static void inline stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch)
5195 struct tty_struct *tty;
5196 unsigned int ioaddr;
5198 tty = portp->tty;
5199 ioaddr = portp->ioaddr;
5201 if (status & SR_RXPARITY)
5202 portp->stats.rxparity++;
5203 if (status & SR_RXFRAMING)
5204 portp->stats.rxframing++;
5205 if (status & SR_RXOVERRUN)
5206 portp->stats.rxoverrun++;
5207 if (status & SR_RXBREAK)
5208 portp->stats.rxbreaks++;
5210 if ((tty != (struct tty_struct *) NULL) &&
5211 ((portp->rxignoremsk & status) == 0)) {
5212 if (portp->rxmarkmsk & status) {
5213 if (status & SR_RXBREAK) {
5214 status = TTY_BREAK;
5215 if (portp->flags & ASYNC_SAK) {
5216 do_SAK(tty);
5217 BRDENABLE(portp->brdnr, portp->pagenr);
5219 } else if (status & SR_RXPARITY) {
5220 status = TTY_PARITY;
5221 } else if (status & SR_RXFRAMING) {
5222 status = TTY_FRAME;
5223 } else if(status & SR_RXOVERRUN) {
5224 status = TTY_OVERRUN;
5225 } else {
5226 status = 0;
5228 } else {
5229 status = 0;
5232 if (tty->flip.char_buf_ptr != (char *) NULL) {
5233 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
5234 *tty->flip.flag_buf_ptr++ = status;
5235 *tty->flip.char_buf_ptr++ = ch;
5236 tty->flip.count++;
5238 tty_schedule_flip(tty);
5241 if (status == 0)
5242 portp->stats.rxtotal++;
5246 /*****************************************************************************/
5249 * Process all characters in the RX FIFO of the UART. Check all char
5250 * status bytes as well, and process as required. We need to check
5251 * all bytes in the FIFO, in case some more enter the FIFO while we
5252 * are here. To get the exact character error type we need to switch
5253 * into CHAR error mode (that is why we need to make sure we empty
5254 * the FIFO).
5257 static void stl_sc26198rxbadchars(stlport_t *portp)
5259 unsigned char status, mr1;
5260 char ch;
5263 * To get the precise error type for each character we must switch
5264 * back into CHAR error mode.
5266 mr1 = stl_sc26198getreg(portp, MR1);
5267 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
5269 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
5270 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
5271 ch = stl_sc26198getreg(portp, RXFIFO);
5272 stl_sc26198rxbadch(portp, status, ch);
5276 * To get correct interrupt class we must switch back into BLOCK
5277 * error mode.
5279 stl_sc26198setreg(portp, MR1, mr1);
5282 /*****************************************************************************/
5285 * Other interrupt handler. This includes modem signals, flow
5286 * control actions, etc. Most stuff is left to off-level interrupt
5287 * processing time.
5290 static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
5292 unsigned char cir, ipr, xisr;
5294 #if DEBUG
5295 printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
5296 #endif
5298 cir = stl_sc26198getglobreg(portp, CIR);
5300 switch (cir & CIR_SUBTYPEMASK) {
5301 case CIR_SUBCOS:
5302 ipr = stl_sc26198getreg(portp, IPR);
5303 if (ipr & IPR_DCDCHANGE) {
5304 set_bit(ASYI_DCDCHANGE, &portp->istate);
5305 queue_task(&portp->tqueue, &tq_scheduler);
5306 portp->stats.modem++;
5308 break;
5309 case CIR_SUBXONXOFF:
5310 xisr = stl_sc26198getreg(portp, XISR);
5311 if (xisr & XISR_RXXONGOT) {
5312 set_bit(ASYI_TXFLOWED, &portp->istate);
5313 portp->stats.txxoff++;
5315 if (xisr & XISR_RXXOFFGOT) {
5316 clear_bit(ASYI_TXFLOWED, &portp->istate);
5317 portp->stats.txxon++;
5319 break;
5320 case CIR_SUBBREAK:
5321 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
5322 stl_sc26198rxbadchars(portp);
5323 break;
5324 default:
5325 break;
5329 /*****************************************************************************/