MOXA linux-2.6.x / linux-2.6.9-uc0 from sdlinux-moxaart.tgz
[linux-2.6.9-moxart.git] / drivers / char / stallion.c
blob90018ce17c57fd3bffea7a94786bc3465188cc6d
1 /*****************************************************************************/
3 /*
4 * stallion.c -- stallion multiport serial driver.
6 * Copyright (C) 1996-1999 Stallion Technologies
7 * Copyright (C) 1994-1996 Greg Ungerer.
9 * This code is loosely based on the Linux serial driver, written by
10 * Linus Torvalds, Theodore T'so and others.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /*****************************************************************************/
29 #include <linux/config.h>
30 #include <linux/module.h>
31 #include <linux/slab.h>
32 #include <linux/interrupt.h>
33 #include <linux/tty.h>
34 #include <linux/tty_flip.h>
35 #include <linux/serial.h>
36 #include <linux/cd1400.h>
37 #include <linux/sc26198.h>
38 #include <linux/comstats.h>
39 #include <linux/stallion.h>
40 #include <linux/ioport.h>
41 #include <linux/init.h>
42 #include <linux/smp_lock.h>
43 #include <linux/devfs_fs_kernel.h>
44 #include <linux/device.h>
46 #include <asm/io.h>
47 #include <asm/uaccess.h>
49 #ifdef CONFIG_PCI
50 #include <linux/pci.h>
51 #endif
53 /*****************************************************************************/
56 * Define different board types. Use the standard Stallion "assigned"
57 * board numbers. Boards supported in this driver are abbreviated as
58 * EIO = EasyIO and ECH = EasyConnection 8/32.
60 #define BRD_EASYIO 20
61 #define BRD_ECH 21
62 #define BRD_ECHMC 22
63 #define BRD_ECHPCI 26
64 #define BRD_ECH64PCI 27
65 #define BRD_EASYIOPCI 28
68 * Define a configuration structure to hold the board configuration.
69 * Need to set this up in the code (for now) with the boards that are
70 * to be configured into the system. This is what needs to be modified
71 * when adding/removing/modifying boards. Each line entry in the
72 * stl_brdconf[] array is a board. Each line contains io/irq/memory
73 * ranges for that board (as well as what type of board it is).
74 * Some examples:
75 * { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
76 * This line would configure an EasyIO board (4 or 8, no difference),
77 * at io address 2a0 and irq 10.
78 * Another example:
79 * { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
80 * This line will configure an EasyConnection 8/32 board at primary io
81 * address 2a8, secondary io address 280 and irq 12.
82 * Enter as many lines into this array as you want (only the first 4
83 * will actually be used!). Any combination of EasyIO and EasyConnection
84 * boards can be specified. EasyConnection 8/32 boards can share their
85 * secondary io addresses between each other.
87 * NOTE: there is no need to put any entries in this table for PCI
88 * boards. They will be found automatically by the driver - provided
89 * PCI BIOS32 support is compiled into the kernel.
92 typedef struct {
93 int brdtype;
94 int ioaddr1;
95 int ioaddr2;
96 unsigned long memaddr;
97 int irq;
98 int irqtype;
99 } stlconf_t;
101 static stlconf_t stl_brdconf[] = {
102 /*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
105 static int stl_nrbrds = sizeof(stl_brdconf) / sizeof(stlconf_t);
107 /*****************************************************************************/
110 * Define some important driver characteristics. Device major numbers
111 * allocated as per Linux Device Registry.
113 #ifndef STL_SIOMEMMAJOR
114 #define STL_SIOMEMMAJOR 28
115 #endif
116 #ifndef STL_SERIALMAJOR
117 #define STL_SERIALMAJOR 24
118 #endif
119 #ifndef STL_CALLOUTMAJOR
120 #define STL_CALLOUTMAJOR 25
121 #endif
124 * Set the TX buffer size. Bigger is better, but we don't want
125 * to chew too much memory with buffers!
127 #define STL_TXBUFLOW 512
128 #define STL_TXBUFSIZE 4096
130 /*****************************************************************************/
133 * Define our local driver identity first. Set up stuff to deal with
134 * all the local structures required by a serial tty driver.
136 static char *stl_drvtitle = "Stallion Multiport Serial Driver";
137 static char *stl_drvname = "stallion";
138 static char *stl_drvversion = "5.6.0";
140 static struct tty_driver *stl_serial;
143 * We will need to allocate a temporary write buffer for chars that
144 * come direct from user space. The problem is that a copy from user
145 * space might cause a page fault (typically on a system that is
146 * swapping!). All ports will share one buffer - since if the system
147 * is already swapping a shared buffer won't make things any worse.
149 static char *stl_tmpwritebuf;
150 static DECLARE_MUTEX(stl_tmpwritesem);
153 * Define a local default termios struct. All ports will be created
154 * with this termios initially. Basically all it defines is a raw port
155 * at 9600, 8 data bits, 1 stop bit.
157 static struct termios stl_deftermios = {
158 .c_cflag = (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
159 .c_cc = INIT_C_CC,
163 * Define global stats structures. Not used often, and can be
164 * re-used for each stats call.
166 static comstats_t stl_comstats;
167 static combrd_t stl_brdstats;
168 static stlbrd_t stl_dummybrd;
169 static stlport_t stl_dummyport;
172 * Define global place to put buffer overflow characters.
174 static char stl_unwanted[SC26198_RXFIFOSIZE];
177 * Keep track of what interrupts we have requested for us.
178 * We don't need to request an interrupt twice if it is being
179 * shared with another Stallion board.
181 static int stl_gotintrs[STL_MAXBRDS];
182 static int stl_numintrs;
184 /*****************************************************************************/
186 static stlbrd_t *stl_brds[STL_MAXBRDS];
189 * Per board state flags. Used with the state field of the board struct.
190 * Not really much here!
192 #define BRD_FOUND 0x1
195 * Define the port structure istate flags. These set of flags are
196 * modified at interrupt time - so setting and reseting them needs
197 * to be atomic. Use the bit clear/setting routines for this.
199 #define ASYI_TXBUSY 1
200 #define ASYI_TXLOW 2
201 #define ASYI_DCDCHANGE 3
202 #define ASYI_TXFLOWED 4
205 * Define an array of board names as printable strings. Handy for
206 * referencing boards when printing trace and stuff.
208 static char *stl_brdnames[] = {
209 (char *) NULL,
210 (char *) NULL,
211 (char *) NULL,
212 (char *) NULL,
213 (char *) NULL,
214 (char *) NULL,
215 (char *) NULL,
216 (char *) NULL,
217 (char *) NULL,
218 (char *) NULL,
219 (char *) NULL,
220 (char *) NULL,
221 (char *) NULL,
222 (char *) NULL,
223 (char *) NULL,
224 (char *) NULL,
225 (char *) NULL,
226 (char *) NULL,
227 (char *) NULL,
228 (char *) NULL,
229 "EasyIO",
230 "EC8/32-AT",
231 "EC8/32-MC",
232 (char *) NULL,
233 (char *) NULL,
234 (char *) NULL,
235 "EC8/32-PCI",
236 "EC8/64-PCI",
237 "EasyIO-PCI",
240 /*****************************************************************************/
242 #ifdef MODULE
244 * Define some string labels for arguments passed from the module
245 * load line. These allow for easy board definitions, and easy
246 * modification of the io, memory and irq resoucres.
249 static char *board0[4];
250 static char *board1[4];
251 static char *board2[4];
252 static char *board3[4];
254 static char **stl_brdsp[] = {
255 (char **) &board0,
256 (char **) &board1,
257 (char **) &board2,
258 (char **) &board3
262 * Define a set of common board names, and types. This is used to
263 * parse any module arguments.
266 typedef struct stlbrdtype {
267 char *name;
268 int type;
269 } stlbrdtype_t;
271 static stlbrdtype_t stl_brdstr[] = {
272 { "easyio", BRD_EASYIO },
273 { "eio", BRD_EASYIO },
274 { "20", BRD_EASYIO },
275 { "ec8/32", BRD_ECH },
276 { "ec8/32-at", BRD_ECH },
277 { "ec8/32-isa", BRD_ECH },
278 { "ech", BRD_ECH },
279 { "echat", BRD_ECH },
280 { "21", BRD_ECH },
281 { "ec8/32-mc", BRD_ECHMC },
282 { "ec8/32-mca", BRD_ECHMC },
283 { "echmc", BRD_ECHMC },
284 { "echmca", BRD_ECHMC },
285 { "22", BRD_ECHMC },
286 { "ec8/32-pc", BRD_ECHPCI },
287 { "ec8/32-pci", BRD_ECHPCI },
288 { "26", BRD_ECHPCI },
289 { "ec8/64-pc", BRD_ECH64PCI },
290 { "ec8/64-pci", BRD_ECH64PCI },
291 { "ech-pci", BRD_ECH64PCI },
292 { "echpci", BRD_ECH64PCI },
293 { "echpc", BRD_ECH64PCI },
294 { "27", BRD_ECH64PCI },
295 { "easyio-pc", BRD_EASYIOPCI },
296 { "easyio-pci", BRD_EASYIOPCI },
297 { "eio-pci", BRD_EASYIOPCI },
298 { "eiopci", BRD_EASYIOPCI },
299 { "28", BRD_EASYIOPCI },
303 * Define the module agruments.
305 MODULE_AUTHOR("Greg Ungerer");
306 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
307 MODULE_LICENSE("GPL");
309 MODULE_PARM(board0, "1-4s");
310 MODULE_PARM_DESC(board0, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
311 MODULE_PARM(board1, "1-4s");
312 MODULE_PARM_DESC(board1, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
313 MODULE_PARM(board2, "1-4s");
314 MODULE_PARM_DESC(board2, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
315 MODULE_PARM(board3, "1-4s");
316 MODULE_PARM_DESC(board3, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
318 #endif
320 /*****************************************************************************/
323 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
324 * to the directly accessible io ports of these boards (not the uarts -
325 * they are in cd1400.h and sc26198.h).
327 #define EIO_8PORTRS 0x04
328 #define EIO_4PORTRS 0x05
329 #define EIO_8PORTDI 0x00
330 #define EIO_8PORTM 0x06
331 #define EIO_MK3 0x03
332 #define EIO_IDBITMASK 0x07
334 #define EIO_BRDMASK 0xf0
335 #define ID_BRD4 0x10
336 #define ID_BRD8 0x20
337 #define ID_BRD16 0x30
339 #define EIO_INTRPEND 0x08
340 #define EIO_INTEDGE 0x00
341 #define EIO_INTLEVEL 0x08
342 #define EIO_0WS 0x10
344 #define ECH_ID 0xa0
345 #define ECH_IDBITMASK 0xe0
346 #define ECH_BRDENABLE 0x08
347 #define ECH_BRDDISABLE 0x00
348 #define ECH_INTENABLE 0x01
349 #define ECH_INTDISABLE 0x00
350 #define ECH_INTLEVEL 0x02
351 #define ECH_INTEDGE 0x00
352 #define ECH_INTRPEND 0x01
353 #define ECH_BRDRESET 0x01
355 #define ECHMC_INTENABLE 0x01
356 #define ECHMC_BRDRESET 0x02
358 #define ECH_PNLSTATUS 2
359 #define ECH_PNL16PORT 0x20
360 #define ECH_PNLIDMASK 0x07
361 #define ECH_PNLXPID 0x40
362 #define ECH_PNLINTRPEND 0x80
364 #define ECH_ADDR2MASK 0x1e0
367 * Define the vector mapping bits for the programmable interrupt board
368 * hardware. These bits encode the interrupt for the board to use - it
369 * is software selectable (except the EIO-8M).
371 static unsigned char stl_vecmap[] = {
372 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
373 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
377 * Set up enable and disable macros for the ECH boards. They require
378 * the secondary io address space to be activated and deactivated.
379 * This way all ECH boards can share their secondary io region.
380 * If this is an ECH-PCI board then also need to set the page pointer
381 * to point to the correct page.
383 #define BRDENABLE(brdnr,pagenr) \
384 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
385 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
386 stl_brds[(brdnr)]->ioctrl); \
387 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
388 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
390 #define BRDDISABLE(brdnr) \
391 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
392 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
393 stl_brds[(brdnr)]->ioctrl);
395 #define STL_CD1400MAXBAUD 230400
396 #define STL_SC26198MAXBAUD 460800
398 #define STL_BAUDBASE 115200
399 #define STL_CLOSEDELAY (5 * HZ / 10)
401 /*****************************************************************************/
403 #ifdef CONFIG_PCI
406 * Define the Stallion PCI vendor and device IDs.
408 #ifndef PCI_VENDOR_ID_STALLION
409 #define PCI_VENDOR_ID_STALLION 0x124d
410 #endif
411 #ifndef PCI_DEVICE_ID_ECHPCI832
412 #define PCI_DEVICE_ID_ECHPCI832 0x0000
413 #endif
414 #ifndef PCI_DEVICE_ID_ECHPCI864
415 #define PCI_DEVICE_ID_ECHPCI864 0x0002
416 #endif
417 #ifndef PCI_DEVICE_ID_EIOPCI
418 #define PCI_DEVICE_ID_EIOPCI 0x0003
419 #endif
422 * Define structure to hold all Stallion PCI boards.
424 typedef struct stlpcibrd {
425 unsigned short vendid;
426 unsigned short devid;
427 int brdtype;
428 } stlpcibrd_t;
430 static stlpcibrd_t stl_pcibrds[] = {
431 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864, BRD_ECH64PCI },
432 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI, BRD_EASYIOPCI },
433 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832, BRD_ECHPCI },
434 { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
437 static int stl_nrpcibrds = sizeof(stl_pcibrds) / sizeof(stlpcibrd_t);
439 #endif
441 /*****************************************************************************/
444 * Define macros to extract a brd/port number from a minor number.
446 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
447 #define MINOR2PORT(min) ((min) & 0x3f)
450 * Define a baud rate table that converts termios baud rate selector
451 * into the actual baud rate value. All baud rate calculations are
452 * based on the actual baud rate required.
454 static unsigned int stl_baudrates[] = {
455 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
456 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
460 * Define some handy local macros...
462 #undef MIN
463 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
465 #undef TOLOWER
466 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
468 /*****************************************************************************/
471 * Declare all those functions in this driver!
474 #ifdef MODULE
475 static void stl_argbrds(void);
476 static int stl_parsebrd(stlconf_t *confp, char **argp);
478 static unsigned long stl_atol(char *str);
479 #endif
481 int stl_init(void);
482 static int stl_open(struct tty_struct *tty, struct file *filp);
483 static void stl_close(struct tty_struct *tty, struct file *filp);
484 static int stl_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count);
485 static void stl_putchar(struct tty_struct *tty, unsigned char ch);
486 static void stl_flushchars(struct tty_struct *tty);
487 static int stl_writeroom(struct tty_struct *tty);
488 static int stl_charsinbuffer(struct tty_struct *tty);
489 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
490 static void stl_settermios(struct tty_struct *tty, struct termios *old);
491 static void stl_throttle(struct tty_struct *tty);
492 static void stl_unthrottle(struct tty_struct *tty);
493 static void stl_stop(struct tty_struct *tty);
494 static void stl_start(struct tty_struct *tty);
495 static void stl_flushbuffer(struct tty_struct *tty);
496 static void stl_breakctl(struct tty_struct *tty, int state);
497 static void stl_waituntilsent(struct tty_struct *tty, int timeout);
498 static void stl_sendxchar(struct tty_struct *tty, char ch);
499 static void stl_hangup(struct tty_struct *tty);
500 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
501 static int stl_portinfo(stlport_t *portp, int portnr, char *pos);
502 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data);
504 static int stl_brdinit(stlbrd_t *brdp);
505 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
506 static int stl_mapirq(int irq, char *name);
507 static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp);
508 static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp);
509 static int stl_getbrdstats(combrd_t __user *bp);
510 static int stl_getportstats(stlport_t *portp, comstats_t __user *cp);
511 static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp);
512 static int stl_getportstruct(stlport_t __user *arg);
513 static int stl_getbrdstruct(stlbrd_t __user *arg);
514 static int stl_waitcarrier(stlport_t *portp, struct file *filp);
515 static void stl_delay(int len);
516 static void stl_eiointr(stlbrd_t *brdp);
517 static void stl_echatintr(stlbrd_t *brdp);
518 static void stl_echmcaintr(stlbrd_t *brdp);
519 static void stl_echpciintr(stlbrd_t *brdp);
520 static void stl_echpci64intr(stlbrd_t *brdp);
521 static void stl_offintr(void *private);
522 static void *stl_memalloc(int len);
523 static stlbrd_t *stl_allocbrd(void);
524 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
526 static inline int stl_initbrds(void);
527 static inline int stl_initeio(stlbrd_t *brdp);
528 static inline int stl_initech(stlbrd_t *brdp);
529 static inline int stl_getbrdnr(void);
531 #ifdef CONFIG_PCI
532 static inline int stl_findpcibrds(void);
533 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp);
534 #endif
537 * CD1400 uart specific handling functions.
539 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value);
540 static int stl_cd1400getreg(stlport_t *portp, int regnr);
541 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value);
542 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
543 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
544 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp);
545 static int stl_cd1400getsignals(stlport_t *portp);
546 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts);
547 static void stl_cd1400ccrwait(stlport_t *portp);
548 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx);
549 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx);
550 static void stl_cd1400disableintrs(stlport_t *portp);
551 static void stl_cd1400sendbreak(stlport_t *portp, int len);
552 static void stl_cd1400flowctrl(stlport_t *portp, int state);
553 static void stl_cd1400sendflow(stlport_t *portp, int state);
554 static void stl_cd1400flush(stlport_t *portp);
555 static int stl_cd1400datastate(stlport_t *portp);
556 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase);
557 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase);
558 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr);
559 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr);
560 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr);
562 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr);
565 * SC26198 uart specific handling functions.
567 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value);
568 static int stl_sc26198getreg(stlport_t *portp, int regnr);
569 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value);
570 static int stl_sc26198getglobreg(stlport_t *portp, int regnr);
571 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
572 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
573 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp);
574 static int stl_sc26198getsignals(stlport_t *portp);
575 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts);
576 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx);
577 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx);
578 static void stl_sc26198disableintrs(stlport_t *portp);
579 static void stl_sc26198sendbreak(stlport_t *portp, int len);
580 static void stl_sc26198flowctrl(stlport_t *portp, int state);
581 static void stl_sc26198sendflow(stlport_t *portp, int state);
582 static void stl_sc26198flush(stlport_t *portp);
583 static int stl_sc26198datastate(stlport_t *portp);
584 static void stl_sc26198wait(stlport_t *portp);
585 static void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty);
586 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase);
587 static void stl_sc26198txisr(stlport_t *port);
588 static void stl_sc26198rxisr(stlport_t *port, unsigned int iack);
589 static void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch);
590 static void stl_sc26198rxbadchars(stlport_t *portp);
591 static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
593 /*****************************************************************************/
596 * Generic UART support structure.
598 typedef struct uart {
599 int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp);
600 void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
601 void (*setport)(stlport_t *portp, struct termios *tiosp);
602 int (*getsignals)(stlport_t *portp);
603 void (*setsignals)(stlport_t *portp, int dtr, int rts);
604 void (*enablerxtx)(stlport_t *portp, int rx, int tx);
605 void (*startrxtx)(stlport_t *portp, int rx, int tx);
606 void (*disableintrs)(stlport_t *portp);
607 void (*sendbreak)(stlport_t *portp, int len);
608 void (*flowctrl)(stlport_t *portp, int state);
609 void (*sendflow)(stlport_t *portp, int state);
610 void (*flush)(stlport_t *portp);
611 int (*datastate)(stlport_t *portp);
612 void (*intr)(stlpanel_t *panelp, unsigned int iobase);
613 } uart_t;
616 * Define some macros to make calling these functions nice and clean.
618 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
619 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
620 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
621 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
622 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
623 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
624 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
625 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
626 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
627 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
628 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
629 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
630 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
632 /*****************************************************************************/
635 * CD1400 UART specific data initialization.
637 static uart_t stl_cd1400uart = {
638 stl_cd1400panelinit,
639 stl_cd1400portinit,
640 stl_cd1400setport,
641 stl_cd1400getsignals,
642 stl_cd1400setsignals,
643 stl_cd1400enablerxtx,
644 stl_cd1400startrxtx,
645 stl_cd1400disableintrs,
646 stl_cd1400sendbreak,
647 stl_cd1400flowctrl,
648 stl_cd1400sendflow,
649 stl_cd1400flush,
650 stl_cd1400datastate,
651 stl_cd1400eiointr
655 * Define the offsets within the register bank of a cd1400 based panel.
656 * These io address offsets are common to the EasyIO board as well.
658 #define EREG_ADDR 0
659 #define EREG_DATA 4
660 #define EREG_RXACK 5
661 #define EREG_TXACK 6
662 #define EREG_MDACK 7
664 #define EREG_BANKSIZE 8
666 #define CD1400_CLK 25000000
667 #define CD1400_CLK8M 20000000
670 * Define the cd1400 baud rate clocks. These are used when calculating
671 * what clock and divisor to use for the required baud rate. Also
672 * define the maximum baud rate allowed, and the default base baud.
674 static int stl_cd1400clkdivs[] = {
675 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
678 /*****************************************************************************/
681 * SC26198 UART specific data initization.
683 static uart_t stl_sc26198uart = {
684 stl_sc26198panelinit,
685 stl_sc26198portinit,
686 stl_sc26198setport,
687 stl_sc26198getsignals,
688 stl_sc26198setsignals,
689 stl_sc26198enablerxtx,
690 stl_sc26198startrxtx,
691 stl_sc26198disableintrs,
692 stl_sc26198sendbreak,
693 stl_sc26198flowctrl,
694 stl_sc26198sendflow,
695 stl_sc26198flush,
696 stl_sc26198datastate,
697 stl_sc26198intr
701 * Define the offsets within the register bank of a sc26198 based panel.
703 #define XP_DATA 0
704 #define XP_ADDR 1
705 #define XP_MODID 2
706 #define XP_STATUS 2
707 #define XP_IACK 3
709 #define XP_BANKSIZE 4
712 * Define the sc26198 baud rate table. Offsets within the table
713 * represent the actual baud rate selector of sc26198 registers.
715 static unsigned int sc26198_baudtable[] = {
716 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
717 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
718 230400, 460800, 921600
721 #define SC26198_NRBAUDS (sizeof(sc26198_baudtable) / sizeof(unsigned int))
723 /*****************************************************************************/
726 * Define the driver info for a user level control device. Used mainly
727 * to get at port stats - only not using the port device itself.
729 static struct file_operations stl_fsiomem = {
730 .owner = THIS_MODULE,
731 .ioctl = stl_memioctl,
734 /*****************************************************************************/
736 static struct class_simple *stallion_class;
738 #ifdef MODULE
741 * Loadable module initialization stuff.
744 static int __init stallion_module_init(void)
746 unsigned long flags;
748 #ifdef DEBUG
749 printk("init_module()\n");
750 #endif
752 save_flags(flags);
753 cli();
754 stl_init();
755 restore_flags(flags);
757 return(0);
760 /*****************************************************************************/
762 static void __exit stallion_module_exit(void)
764 stlbrd_t *brdp;
765 stlpanel_t *panelp;
766 stlport_t *portp;
767 unsigned long flags;
768 int i, j, k;
770 #ifdef DEBUG
771 printk("cleanup_module()\n");
772 #endif
774 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
775 stl_drvversion);
777 save_flags(flags);
778 cli();
781 * Free up all allocated resources used by the ports. This includes
782 * memory and interrupts. As part of this process we will also do
783 * a hangup on every open port - to try to flush out any processes
784 * hanging onto ports.
786 i = tty_unregister_driver(stl_serial);
787 put_tty_driver(stl_serial);
788 if (i) {
789 printk("STALLION: failed to un-register tty driver, "
790 "errno=%d\n", -i);
791 restore_flags(flags);
792 return;
794 for (i = 0; i < 4; i++) {
795 devfs_remove("staliomem/%d", i);
796 class_simple_device_remove(MKDEV(STL_SIOMEMMAJOR, i));
798 devfs_remove("staliomem");
799 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
800 printk("STALLION: failed to un-register serial memory device, "
801 "errno=%d\n", -i);
802 class_simple_destroy(stallion_class);
804 if (stl_tmpwritebuf != (char *) NULL)
805 kfree(stl_tmpwritebuf);
807 for (i = 0; (i < stl_nrbrds); i++) {
808 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
809 continue;
810 for (j = 0; (j < STL_MAXPANELS); j++) {
811 panelp = brdp->panels[j];
812 if (panelp == (stlpanel_t *) NULL)
813 continue;
814 for (k = 0; (k < STL_PORTSPERPANEL); k++) {
815 portp = panelp->ports[k];
816 if (portp == (stlport_t *) NULL)
817 continue;
818 if (portp->tty != (struct tty_struct *) NULL)
819 stl_hangup(portp->tty);
820 if (portp->tx.buf != (char *) NULL)
821 kfree(portp->tx.buf);
822 kfree(portp);
824 kfree(panelp);
827 release_region(brdp->ioaddr1, brdp->iosize1);
828 if (brdp->iosize2 > 0)
829 release_region(brdp->ioaddr2, brdp->iosize2);
831 kfree(brdp);
832 stl_brds[i] = (stlbrd_t *) NULL;
835 for (i = 0; (i < stl_numintrs); i++)
836 free_irq(stl_gotintrs[i], NULL);
838 restore_flags(flags);
841 module_init(stallion_module_init);
842 module_exit(stallion_module_exit);
844 /*****************************************************************************/
847 * Check for any arguments passed in on the module load command line.
850 static void stl_argbrds(void)
852 stlconf_t conf;
853 stlbrd_t *brdp;
854 int nrargs, i;
856 #ifdef DEBUG
857 printk("stl_argbrds()\n");
858 #endif
860 nrargs = sizeof(stl_brdsp) / sizeof(char **);
862 for (i = stl_nrbrds; (i < nrargs); i++) {
863 memset(&conf, 0, sizeof(conf));
864 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
865 continue;
866 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
867 continue;
868 stl_nrbrds = i + 1;
869 brdp->brdnr = i;
870 brdp->brdtype = conf.brdtype;
871 brdp->ioaddr1 = conf.ioaddr1;
872 brdp->ioaddr2 = conf.ioaddr2;
873 brdp->irq = conf.irq;
874 brdp->irqtype = conf.irqtype;
875 stl_brdinit(brdp);
879 /*****************************************************************************/
882 * Convert an ascii string number into an unsigned long.
885 static unsigned long stl_atol(char *str)
887 unsigned long val;
888 int base, c;
889 char *sp;
891 val = 0;
892 sp = str;
893 if ((*sp == '0') && (*(sp+1) == 'x')) {
894 base = 16;
895 sp += 2;
896 } else if (*sp == '0') {
897 base = 8;
898 sp++;
899 } else {
900 base = 10;
903 for (; (*sp != 0); sp++) {
904 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
905 if ((c < 0) || (c >= base)) {
906 printk("STALLION: invalid argument %s\n", str);
907 val = 0;
908 break;
910 val = (val * base) + c;
912 return(val);
915 /*****************************************************************************/
918 * Parse the supplied argument string, into the board conf struct.
921 static int stl_parsebrd(stlconf_t *confp, char **argp)
923 char *sp;
924 int nrbrdnames, i;
926 #ifdef DEBUG
927 printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
928 #endif
930 if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
931 return(0);
933 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
934 *sp = TOLOWER(*sp);
936 nrbrdnames = sizeof(stl_brdstr) / sizeof(stlbrdtype_t);
937 for (i = 0; (i < nrbrdnames); i++) {
938 if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
939 break;
941 if (i >= nrbrdnames) {
942 printk("STALLION: unknown board name, %s?\n", argp[0]);
943 return(0);
946 confp->brdtype = stl_brdstr[i].type;
948 i = 1;
949 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
950 confp->ioaddr1 = stl_atol(argp[i]);
951 i++;
952 if (confp->brdtype == BRD_ECH) {
953 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
954 confp->ioaddr2 = stl_atol(argp[i]);
955 i++;
957 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
958 confp->irq = stl_atol(argp[i]);
959 return(1);
962 #endif
964 /*****************************************************************************/
967 * Local driver kernel memory allocation routine.
970 static void *stl_memalloc(int len)
972 return((void *) kmalloc(len, GFP_KERNEL));
975 /*****************************************************************************/
978 * Allocate a new board structure. Fill out the basic info in it.
981 static stlbrd_t *stl_allocbrd(void)
983 stlbrd_t *brdp;
985 brdp = (stlbrd_t *) stl_memalloc(sizeof(stlbrd_t));
986 if (brdp == (stlbrd_t *) NULL) {
987 printk("STALLION: failed to allocate memory (size=%d)\n",
988 sizeof(stlbrd_t));
989 return((stlbrd_t *) NULL);
992 memset(brdp, 0, sizeof(stlbrd_t));
993 brdp->magic = STL_BOARDMAGIC;
994 return(brdp);
997 /*****************************************************************************/
999 static int stl_open(struct tty_struct *tty, struct file *filp)
1001 stlport_t *portp;
1002 stlbrd_t *brdp;
1003 unsigned int minordev;
1004 int brdnr, panelnr, portnr, rc;
1006 #ifdef DEBUG
1007 printk("stl_open(tty=%x,filp=%x): device=%s\n", (int) tty,
1008 (int) filp, tty->name);
1009 #endif
1011 minordev = tty->index;
1012 brdnr = MINOR2BRD(minordev);
1013 if (brdnr >= stl_nrbrds)
1014 return(-ENODEV);
1015 brdp = stl_brds[brdnr];
1016 if (brdp == (stlbrd_t *) NULL)
1017 return(-ENODEV);
1018 minordev = MINOR2PORT(minordev);
1019 for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
1020 if (brdp->panels[panelnr] == (stlpanel_t *) NULL)
1021 break;
1022 if (minordev < brdp->panels[panelnr]->nrports) {
1023 portnr = minordev;
1024 break;
1026 minordev -= brdp->panels[panelnr]->nrports;
1028 if (portnr < 0)
1029 return(-ENODEV);
1031 portp = brdp->panels[panelnr]->ports[portnr];
1032 if (portp == (stlport_t *) NULL)
1033 return(-ENODEV);
1036 * On the first open of the device setup the port hardware, and
1037 * initialize the per port data structure.
1039 portp->tty = tty;
1040 tty->driver_data = portp;
1041 portp->refcount++;
1043 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
1044 if (portp->tx.buf == (char *) NULL) {
1045 portp->tx.buf = (char *) stl_memalloc(STL_TXBUFSIZE);
1046 if (portp->tx.buf == (char *) NULL)
1047 return(-ENOMEM);
1048 portp->tx.head = portp->tx.buf;
1049 portp->tx.tail = portp->tx.buf;
1051 stl_setport(portp, tty->termios);
1052 portp->sigs = stl_getsignals(portp);
1053 stl_setsignals(portp, 1, 1);
1054 stl_enablerxtx(portp, 1, 1);
1055 stl_startrxtx(portp, 1, 0);
1056 clear_bit(TTY_IO_ERROR, &tty->flags);
1057 portp->flags |= ASYNC_INITIALIZED;
1061 * Check if this port is in the middle of closing. If so then wait
1062 * until it is closed then return error status, based on flag settings.
1063 * The sleep here does not need interrupt protection since the wakeup
1064 * for it is done with the same context.
1066 if (portp->flags & ASYNC_CLOSING) {
1067 interruptible_sleep_on(&portp->close_wait);
1068 if (portp->flags & ASYNC_HUP_NOTIFY)
1069 return(-EAGAIN);
1070 return(-ERESTARTSYS);
1074 * Based on type of open being done check if it can overlap with any
1075 * previous opens still in effect. If we are a normal serial device
1076 * then also we might have to wait for carrier.
1078 if (!(filp->f_flags & O_NONBLOCK)) {
1079 if ((rc = stl_waitcarrier(portp, filp)) != 0)
1080 return(rc);
1082 portp->flags |= ASYNC_NORMAL_ACTIVE;
1084 return(0);
1087 /*****************************************************************************/
1090 * Possibly need to wait for carrier (DCD signal) to come high. Say
1091 * maybe because if we are clocal then we don't need to wait...
1094 static int stl_waitcarrier(stlport_t *portp, struct file *filp)
1096 unsigned long flags;
1097 int rc, doclocal;
1099 #ifdef DEBUG
1100 printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp, (int) filp);
1101 #endif
1103 rc = 0;
1104 doclocal = 0;
1106 if (portp->tty->termios->c_cflag & CLOCAL)
1107 doclocal++;
1109 save_flags(flags);
1110 cli();
1111 portp->openwaitcnt++;
1112 if (! tty_hung_up_p(filp))
1113 portp->refcount--;
1115 for (;;) {
1116 stl_setsignals(portp, 1, 1);
1117 if (tty_hung_up_p(filp) ||
1118 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1119 if (portp->flags & ASYNC_HUP_NOTIFY)
1120 rc = -EBUSY;
1121 else
1122 rc = -ERESTARTSYS;
1123 break;
1125 if (((portp->flags & ASYNC_CLOSING) == 0) &&
1126 (doclocal || (portp->sigs & TIOCM_CD))) {
1127 break;
1129 if (signal_pending(current)) {
1130 rc = -ERESTARTSYS;
1131 break;
1133 interruptible_sleep_on(&portp->open_wait);
1136 if (! tty_hung_up_p(filp))
1137 portp->refcount++;
1138 portp->openwaitcnt--;
1139 restore_flags(flags);
1141 return(rc);
1144 /*****************************************************************************/
1146 static void stl_close(struct tty_struct *tty, struct file *filp)
1148 stlport_t *portp;
1149 unsigned long flags;
1151 #ifdef DEBUG
1152 printk("stl_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
1153 #endif
1155 portp = tty->driver_data;
1156 if (portp == (stlport_t *) NULL)
1157 return;
1159 save_flags(flags);
1160 cli();
1161 if (tty_hung_up_p(filp)) {
1162 restore_flags(flags);
1163 return;
1165 if ((tty->count == 1) && (portp->refcount != 1))
1166 portp->refcount = 1;
1167 if (portp->refcount-- > 1) {
1168 restore_flags(flags);
1169 return;
1172 portp->refcount = 0;
1173 portp->flags |= ASYNC_CLOSING;
1176 * May want to wait for any data to drain before closing. The BUSY
1177 * flag keeps track of whether we are still sending or not - it is
1178 * very accurate for the cd1400, not quite so for the sc26198.
1179 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1181 tty->closing = 1;
1182 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1183 tty_wait_until_sent(tty, portp->closing_wait);
1184 stl_waituntilsent(tty, (HZ / 2));
1186 portp->flags &= ~ASYNC_INITIALIZED;
1187 stl_disableintrs(portp);
1188 if (tty->termios->c_cflag & HUPCL)
1189 stl_setsignals(portp, 0, 0);
1190 stl_enablerxtx(portp, 0, 0);
1191 stl_flushbuffer(tty);
1192 portp->istate = 0;
1193 if (portp->tx.buf != (char *) NULL) {
1194 kfree(portp->tx.buf);
1195 portp->tx.buf = (char *) NULL;
1196 portp->tx.head = (char *) NULL;
1197 portp->tx.tail = (char *) NULL;
1199 set_bit(TTY_IO_ERROR, &tty->flags);
1200 tty_ldisc_flush(tty);
1202 tty->closing = 0;
1203 portp->tty = (struct tty_struct *) NULL;
1205 if (portp->openwaitcnt) {
1206 if (portp->close_delay)
1207 stl_delay(portp->close_delay);
1208 wake_up_interruptible(&portp->open_wait);
1211 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1212 wake_up_interruptible(&portp->close_wait);
1213 restore_flags(flags);
1216 /*****************************************************************************/
1219 * Wait for a specified delay period, this is not a busy-loop. It will
1220 * give up the processor while waiting. Unfortunately this has some
1221 * rather intimate knowledge of the process management stuff.
1224 static void stl_delay(int len)
1226 #ifdef DEBUG
1227 printk("stl_delay(len=%d)\n", len);
1228 #endif
1229 if (len > 0) {
1230 current->state = TASK_INTERRUPTIBLE;
1231 schedule_timeout(len);
1235 /*****************************************************************************/
1238 * Write routine. Take data and stuff it in to the TX ring queue.
1239 * If transmit interrupts are not running then start them.
1242 static int stl_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count)
1244 stlport_t *portp;
1245 unsigned int len, stlen;
1246 unsigned char *chbuf;
1247 char *head, *tail;
1249 #ifdef DEBUG
1250 printk("stl_write(tty=%x,from_user=%d,buf=%x,count=%d)\n",
1251 (int) tty, from_user, (int) buf, count);
1252 #endif
1254 if ((tty == (struct tty_struct *) NULL) ||
1255 (stl_tmpwritebuf == (char *) NULL))
1256 return(0);
1257 portp = tty->driver_data;
1258 if (portp == (stlport_t *) NULL)
1259 return(0);
1260 if (portp->tx.buf == (char *) NULL)
1261 return(0);
1264 * If copying direct from user space we must cater for page faults,
1265 * causing us to "sleep" here for a while. To handle this copy in all
1266 * the data we need now, into a local buffer. Then when we got it all
1267 * copy it into the TX buffer.
1269 chbuf = (unsigned char *) buf;
1270 if (from_user) {
1271 head = portp->tx.head;
1272 tail = portp->tx.tail;
1273 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) :
1274 (tail - head - 1);
1275 count = MIN(len, count);
1277 down(&stl_tmpwritesem);
1278 if (copy_from_user(stl_tmpwritebuf, chbuf, count))
1279 return -EFAULT;
1280 chbuf = &stl_tmpwritebuf[0];
1283 head = portp->tx.head;
1284 tail = portp->tx.tail;
1285 if (head >= tail) {
1286 len = STL_TXBUFSIZE - (head - tail) - 1;
1287 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
1288 } else {
1289 len = tail - head - 1;
1290 stlen = len;
1293 len = MIN(len, count);
1294 count = 0;
1295 while (len > 0) {
1296 stlen = MIN(len, stlen);
1297 memcpy(head, chbuf, stlen);
1298 len -= stlen;
1299 chbuf += stlen;
1300 count += stlen;
1301 head += stlen;
1302 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
1303 head = portp->tx.buf;
1304 stlen = tail - head;
1307 portp->tx.head = head;
1309 clear_bit(ASYI_TXLOW, &portp->istate);
1310 stl_startrxtx(portp, -1, 1);
1312 if (from_user)
1313 up(&stl_tmpwritesem);
1315 return(count);
1318 /*****************************************************************************/
1320 static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1322 stlport_t *portp;
1323 unsigned int len;
1324 char *head, *tail;
1326 #ifdef DEBUG
1327 printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1328 #endif
1330 if (tty == (struct tty_struct *) NULL)
1331 return;
1332 portp = tty->driver_data;
1333 if (portp == (stlport_t *) NULL)
1334 return;
1335 if (portp->tx.buf == (char *) NULL)
1336 return;
1338 head = portp->tx.head;
1339 tail = portp->tx.tail;
1341 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
1342 len--;
1344 if (len > 0) {
1345 *head++ = ch;
1346 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
1347 head = portp->tx.buf;
1349 portp->tx.head = head;
1352 /*****************************************************************************/
1355 * If there are any characters in the buffer then make sure that TX
1356 * interrupts are on and get'em out. Normally used after the putchar
1357 * routine has been called.
1360 static void stl_flushchars(struct tty_struct *tty)
1362 stlport_t *portp;
1364 #ifdef DEBUG
1365 printk("stl_flushchars(tty=%x)\n", (int) tty);
1366 #endif
1368 if (tty == (struct tty_struct *) NULL)
1369 return;
1370 portp = tty->driver_data;
1371 if (portp == (stlport_t *) NULL)
1372 return;
1373 if (portp->tx.buf == (char *) NULL)
1374 return;
1376 #if 0
1377 if (tty->stopped || tty->hw_stopped ||
1378 (portp->tx.head == portp->tx.tail))
1379 return;
1380 #endif
1381 stl_startrxtx(portp, -1, 1);
1384 /*****************************************************************************/
1386 static int stl_writeroom(struct tty_struct *tty)
1388 stlport_t *portp;
1389 char *head, *tail;
1391 #ifdef DEBUG
1392 printk("stl_writeroom(tty=%x)\n", (int) tty);
1393 #endif
1395 if (tty == (struct tty_struct *) NULL)
1396 return(0);
1397 portp = tty->driver_data;
1398 if (portp == (stlport_t *) NULL)
1399 return(0);
1400 if (portp->tx.buf == (char *) NULL)
1401 return(0);
1403 head = portp->tx.head;
1404 tail = portp->tx.tail;
1405 return((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
1408 /*****************************************************************************/
1411 * Return number of chars in the TX buffer. Normally we would just
1412 * calculate the number of chars in the buffer and return that, but if
1413 * the buffer is empty and TX interrupts are still on then we return
1414 * that the buffer still has 1 char in it. This way whoever called us
1415 * will not think that ALL chars have drained - since the UART still
1416 * must have some chars in it (we are busy after all).
1419 static int stl_charsinbuffer(struct tty_struct *tty)
1421 stlport_t *portp;
1422 unsigned int size;
1423 char *head, *tail;
1425 #ifdef DEBUG
1426 printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
1427 #endif
1429 if (tty == (struct tty_struct *) NULL)
1430 return(0);
1431 portp = tty->driver_data;
1432 if (portp == (stlport_t *) NULL)
1433 return(0);
1434 if (portp->tx.buf == (char *) NULL)
1435 return(0);
1437 head = portp->tx.head;
1438 tail = portp->tx.tail;
1439 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1440 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1441 size = 1;
1442 return(size);
1445 /*****************************************************************************/
1448 * Generate the serial struct info.
1451 static int stl_getserial(stlport_t *portp, struct serial_struct __user *sp)
1453 struct serial_struct sio;
1454 stlbrd_t *brdp;
1456 #ifdef DEBUG
1457 printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1458 #endif
1460 memset(&sio, 0, sizeof(struct serial_struct));
1461 sio.line = portp->portnr;
1462 sio.port = portp->ioaddr;
1463 sio.flags = portp->flags;
1464 sio.baud_base = portp->baud_base;
1465 sio.close_delay = portp->close_delay;
1466 sio.closing_wait = portp->closing_wait;
1467 sio.custom_divisor = portp->custom_divisor;
1468 sio.hub6 = 0;
1469 if (portp->uartp == &stl_cd1400uart) {
1470 sio.type = PORT_CIRRUS;
1471 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1472 } else {
1473 sio.type = PORT_UNKNOWN;
1474 sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1477 brdp = stl_brds[portp->brdnr];
1478 if (brdp != (stlbrd_t *) NULL)
1479 sio.irq = brdp->irq;
1481 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
1484 /*****************************************************************************/
1487 * Set port according to the serial struct info.
1488 * At this point we do not do any auto-configure stuff, so we will
1489 * just quietly ignore any requests to change irq, etc.
1492 static int stl_setserial(stlport_t *portp, struct serial_struct __user *sp)
1494 struct serial_struct sio;
1496 #ifdef DEBUG
1497 printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1498 #endif
1500 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1501 return -EFAULT;
1502 if (!capable(CAP_SYS_ADMIN)) {
1503 if ((sio.baud_base != portp->baud_base) ||
1504 (sio.close_delay != portp->close_delay) ||
1505 ((sio.flags & ~ASYNC_USR_MASK) !=
1506 (portp->flags & ~ASYNC_USR_MASK)))
1507 return(-EPERM);
1510 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1511 (sio.flags & ASYNC_USR_MASK);
1512 portp->baud_base = sio.baud_base;
1513 portp->close_delay = sio.close_delay;
1514 portp->closing_wait = sio.closing_wait;
1515 portp->custom_divisor = sio.custom_divisor;
1516 stl_setport(portp, portp->tty->termios);
1517 return(0);
1520 /*****************************************************************************/
1522 static int stl_tiocmget(struct tty_struct *tty, struct file *file)
1524 stlport_t *portp;
1526 if (tty == (struct tty_struct *) NULL)
1527 return(-ENODEV);
1528 portp = tty->driver_data;
1529 if (portp == (stlport_t *) NULL)
1530 return(-ENODEV);
1531 if (tty->flags & (1 << TTY_IO_ERROR))
1532 return(-EIO);
1534 return stl_getsignals(portp);
1537 static int stl_tiocmset(struct tty_struct *tty, struct file *file,
1538 unsigned int set, unsigned int clear)
1540 stlport_t *portp;
1541 int rts = -1, dtr = -1;
1543 if (tty == (struct tty_struct *) NULL)
1544 return(-ENODEV);
1545 portp = tty->driver_data;
1546 if (portp == (stlport_t *) NULL)
1547 return(-ENODEV);
1548 if (tty->flags & (1 << TTY_IO_ERROR))
1549 return(-EIO);
1551 if (set & TIOCM_RTS)
1552 rts = 1;
1553 if (set & TIOCM_DTR)
1554 dtr = 1;
1555 if (clear & TIOCM_RTS)
1556 rts = 0;
1557 if (clear & TIOCM_DTR)
1558 dtr = 0;
1560 stl_setsignals(portp, dtr, rts);
1561 return 0;
1564 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1566 stlport_t *portp;
1567 unsigned int ival;
1568 int rc;
1569 void __user *argp = (void __user *)arg;
1571 #ifdef DEBUG
1572 printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
1573 (int) tty, (int) file, cmd, (int) arg);
1574 #endif
1576 if (tty == (struct tty_struct *) NULL)
1577 return(-ENODEV);
1578 portp = tty->driver_data;
1579 if (portp == (stlport_t *) NULL)
1580 return(-ENODEV);
1582 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1583 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1584 if (tty->flags & (1 << TTY_IO_ERROR))
1585 return(-EIO);
1588 rc = 0;
1590 switch (cmd) {
1591 case TIOCGSOFTCAR:
1592 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1593 (unsigned __user *) argp);
1594 break;
1595 case TIOCSSOFTCAR:
1596 if (get_user(ival, (unsigned int __user *) arg))
1597 return -EFAULT;
1598 tty->termios->c_cflag =
1599 (tty->termios->c_cflag & ~CLOCAL) |
1600 (ival ? CLOCAL : 0);
1601 break;
1602 case TIOCGSERIAL:
1603 rc = stl_getserial(portp, argp);
1604 break;
1605 case TIOCSSERIAL:
1606 rc = stl_setserial(portp, argp);
1607 break;
1608 case COM_GETPORTSTATS:
1609 rc = stl_getportstats(portp, argp);
1610 break;
1611 case COM_CLRPORTSTATS:
1612 rc = stl_clrportstats(portp, argp);
1613 break;
1614 case TIOCSERCONFIG:
1615 case TIOCSERGWILD:
1616 case TIOCSERSWILD:
1617 case TIOCSERGETLSR:
1618 case TIOCSERGSTRUCT:
1619 case TIOCSERGETMULTI:
1620 case TIOCSERSETMULTI:
1621 default:
1622 rc = -ENOIOCTLCMD;
1623 break;
1626 return(rc);
1629 /*****************************************************************************/
1631 static void stl_settermios(struct tty_struct *tty, struct termios *old)
1633 stlport_t *portp;
1634 struct termios *tiosp;
1636 #ifdef DEBUG
1637 printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
1638 #endif
1640 if (tty == (struct tty_struct *) NULL)
1641 return;
1642 portp = tty->driver_data;
1643 if (portp == (stlport_t *) NULL)
1644 return;
1646 tiosp = tty->termios;
1647 if ((tiosp->c_cflag == old->c_cflag) &&
1648 (tiosp->c_iflag == old->c_iflag))
1649 return;
1651 stl_setport(portp, tiosp);
1652 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1653 -1);
1654 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1655 tty->hw_stopped = 0;
1656 stl_start(tty);
1658 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1659 wake_up_interruptible(&portp->open_wait);
1662 /*****************************************************************************/
1665 * Attempt to flow control who ever is sending us data. Based on termios
1666 * settings use software or/and hardware flow control.
1669 static void stl_throttle(struct tty_struct *tty)
1671 stlport_t *portp;
1673 #ifdef DEBUG
1674 printk("stl_throttle(tty=%x)\n", (int) tty);
1675 #endif
1677 if (tty == (struct tty_struct *) NULL)
1678 return;
1679 portp = tty->driver_data;
1680 if (portp == (stlport_t *) NULL)
1681 return;
1682 stl_flowctrl(portp, 0);
1685 /*****************************************************************************/
1688 * Unflow control the device sending us data...
1691 static void stl_unthrottle(struct tty_struct *tty)
1693 stlport_t *portp;
1695 #ifdef DEBUG
1696 printk("stl_unthrottle(tty=%x)\n", (int) tty);
1697 #endif
1699 if (tty == (struct tty_struct *) NULL)
1700 return;
1701 portp = tty->driver_data;
1702 if (portp == (stlport_t *) NULL)
1703 return;
1704 stl_flowctrl(portp, 1);
1707 /*****************************************************************************/
1710 * Stop the transmitter. Basically to do this we will just turn TX
1711 * interrupts off.
1714 static void stl_stop(struct tty_struct *tty)
1716 stlport_t *portp;
1718 #ifdef DEBUG
1719 printk("stl_stop(tty=%x)\n", (int) tty);
1720 #endif
1722 if (tty == (struct tty_struct *) NULL)
1723 return;
1724 portp = tty->driver_data;
1725 if (portp == (stlport_t *) NULL)
1726 return;
1727 stl_startrxtx(portp, -1, 0);
1730 /*****************************************************************************/
1733 * Start the transmitter again. Just turn TX interrupts back on.
1736 static void stl_start(struct tty_struct *tty)
1738 stlport_t *portp;
1740 #ifdef DEBUG
1741 printk("stl_start(tty=%x)\n", (int) tty);
1742 #endif
1744 if (tty == (struct tty_struct *) NULL)
1745 return;
1746 portp = tty->driver_data;
1747 if (portp == (stlport_t *) NULL)
1748 return;
1749 stl_startrxtx(portp, -1, 1);
1752 /*****************************************************************************/
1755 * Hangup this port. This is pretty much like closing the port, only
1756 * a little more brutal. No waiting for data to drain. Shutdown the
1757 * port and maybe drop signals.
1760 static void stl_hangup(struct tty_struct *tty)
1762 stlport_t *portp;
1764 #ifdef DEBUG
1765 printk("stl_hangup(tty=%x)\n", (int) tty);
1766 #endif
1768 if (tty == (struct tty_struct *) NULL)
1769 return;
1770 portp = tty->driver_data;
1771 if (portp == (stlport_t *) NULL)
1772 return;
1774 portp->flags &= ~ASYNC_INITIALIZED;
1775 stl_disableintrs(portp);
1776 if (tty->termios->c_cflag & HUPCL)
1777 stl_setsignals(portp, 0, 0);
1778 stl_enablerxtx(portp, 0, 0);
1779 stl_flushbuffer(tty);
1780 portp->istate = 0;
1781 set_bit(TTY_IO_ERROR, &tty->flags);
1782 if (portp->tx.buf != (char *) NULL) {
1783 kfree(portp->tx.buf);
1784 portp->tx.buf = (char *) NULL;
1785 portp->tx.head = (char *) NULL;
1786 portp->tx.tail = (char *) NULL;
1788 portp->tty = (struct tty_struct *) NULL;
1789 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1790 portp->refcount = 0;
1791 wake_up_interruptible(&portp->open_wait);
1794 /*****************************************************************************/
1796 static void stl_flushbuffer(struct tty_struct *tty)
1798 stlport_t *portp;
1800 #ifdef DEBUG
1801 printk("stl_flushbuffer(tty=%x)\n", (int) tty);
1802 #endif
1804 if (tty == (struct tty_struct *) NULL)
1805 return;
1806 portp = tty->driver_data;
1807 if (portp == (stlport_t *) NULL)
1808 return;
1810 stl_flush(portp);
1811 tty_wakeup(tty);
1814 /*****************************************************************************/
1816 static void stl_breakctl(struct tty_struct *tty, int state)
1818 stlport_t *portp;
1820 #ifdef DEBUG
1821 printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty, state);
1822 #endif
1824 if (tty == (struct tty_struct *) NULL)
1825 return;
1826 portp = tty->driver_data;
1827 if (portp == (stlport_t *) NULL)
1828 return;
1830 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1833 /*****************************************************************************/
1835 static void stl_waituntilsent(struct tty_struct *tty, int timeout)
1837 stlport_t *portp;
1838 unsigned long tend;
1840 #ifdef DEBUG
1841 printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty, timeout);
1842 #endif
1844 if (tty == (struct tty_struct *) NULL)
1845 return;
1846 portp = tty->driver_data;
1847 if (portp == (stlport_t *) NULL)
1848 return;
1850 if (timeout == 0)
1851 timeout = HZ;
1852 tend = jiffies + timeout;
1854 while (stl_datastate(portp)) {
1855 if (signal_pending(current))
1856 break;
1857 stl_delay(2);
1858 if (time_after_eq(jiffies, tend))
1859 break;
1863 /*****************************************************************************/
1865 static void stl_sendxchar(struct tty_struct *tty, char ch)
1867 stlport_t *portp;
1869 #ifdef DEBUG
1870 printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
1871 #endif
1873 if (tty == (struct tty_struct *) NULL)
1874 return;
1875 portp = tty->driver_data;
1876 if (portp == (stlport_t *) NULL)
1877 return;
1879 if (ch == STOP_CHAR(tty))
1880 stl_sendflow(portp, 0);
1881 else if (ch == START_CHAR(tty))
1882 stl_sendflow(portp, 1);
1883 else
1884 stl_putchar(tty, ch);
1887 /*****************************************************************************/
1889 #define MAXLINE 80
1892 * Format info for a specified port. The line is deliberately limited
1893 * to 80 characters. (If it is too long it will be truncated, if too
1894 * short then padded with spaces).
1897 static int stl_portinfo(stlport_t *portp, int portnr, char *pos)
1899 char *sp;
1900 int sigs, cnt;
1902 sp = pos;
1903 sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
1904 portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
1905 (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
1907 if (portp->stats.rxframing)
1908 sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
1909 if (portp->stats.rxparity)
1910 sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
1911 if (portp->stats.rxbreaks)
1912 sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
1913 if (portp->stats.rxoverrun)
1914 sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
1916 sigs = stl_getsignals(portp);
1917 cnt = sprintf(sp, "%s%s%s%s%s ",
1918 (sigs & TIOCM_RTS) ? "|RTS" : "",
1919 (sigs & TIOCM_CTS) ? "|CTS" : "",
1920 (sigs & TIOCM_DTR) ? "|DTR" : "",
1921 (sigs & TIOCM_CD) ? "|DCD" : "",
1922 (sigs & TIOCM_DSR) ? "|DSR" : "");
1923 *sp = ' ';
1924 sp += cnt;
1926 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
1927 *sp++ = ' ';
1928 if (cnt >= MAXLINE)
1929 pos[(MAXLINE - 2)] = '+';
1930 pos[(MAXLINE - 1)] = '\n';
1932 return(MAXLINE);
1935 /*****************************************************************************/
1938 * Port info, read from the /proc file system.
1941 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
1943 stlbrd_t *brdp;
1944 stlpanel_t *panelp;
1945 stlport_t *portp;
1946 int brdnr, panelnr, portnr, totalport;
1947 int curoff, maxoff;
1948 char *pos;
1950 #ifdef DEBUG
1951 printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
1952 "data=%x\n", (int) page, (int) start, (int) off, count,
1953 (int) eof, (int) data);
1954 #endif
1956 pos = page;
1957 totalport = 0;
1958 curoff = 0;
1960 if (off == 0) {
1961 pos += sprintf(pos, "%s: version %s", stl_drvtitle,
1962 stl_drvversion);
1963 while (pos < (page + MAXLINE - 1))
1964 *pos++ = ' ';
1965 *pos++ = '\n';
1967 curoff = MAXLINE;
1970 * We scan through for each board, panel and port. The offset is
1971 * calculated on the fly, and irrelevant ports are skipped.
1973 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1974 brdp = stl_brds[brdnr];
1975 if (brdp == (stlbrd_t *) NULL)
1976 continue;
1977 if (brdp->state == 0)
1978 continue;
1980 maxoff = curoff + (brdp->nrports * MAXLINE);
1981 if (off >= maxoff) {
1982 curoff = maxoff;
1983 continue;
1986 totalport = brdnr * STL_MAXPORTS;
1987 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1988 panelp = brdp->panels[panelnr];
1989 if (panelp == (stlpanel_t *) NULL)
1990 continue;
1992 maxoff = curoff + (panelp->nrports * MAXLINE);
1993 if (off >= maxoff) {
1994 curoff = maxoff;
1995 totalport += panelp->nrports;
1996 continue;
1999 for (portnr = 0; (portnr < panelp->nrports); portnr++,
2000 totalport++) {
2001 portp = panelp->ports[portnr];
2002 if (portp == (stlport_t *) NULL)
2003 continue;
2004 if (off >= (curoff += MAXLINE))
2005 continue;
2006 if ((pos - page + MAXLINE) > count)
2007 goto stl_readdone;
2008 pos += stl_portinfo(portp, totalport, pos);
2013 *eof = 1;
2015 stl_readdone:
2016 *start = page;
2017 return(pos - page);
2020 /*****************************************************************************/
2023 * All board interrupts are vectored through here first. This code then
2024 * calls off to the approrpriate board interrupt handlers.
2027 static irqreturn_t stl_intr(int irq, void *dev_id, struct pt_regs *regs)
2029 stlbrd_t *brdp;
2030 int i;
2031 int handled = 0;
2033 #ifdef DEBUG
2034 printk("stl_intr(irq=%d,regs=%x)\n", irq, (int) regs);
2035 #endif
2037 for (i = 0; (i < stl_nrbrds); i++) {
2038 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
2039 continue;
2040 if (brdp->state == 0)
2041 continue;
2042 handled = 1;
2043 (* brdp->isr)(brdp);
2045 return IRQ_RETVAL(handled);
2048 /*****************************************************************************/
2051 * Interrupt service routine for EasyIO board types.
2054 static void stl_eiointr(stlbrd_t *brdp)
2056 stlpanel_t *panelp;
2057 unsigned int iobase;
2059 panelp = brdp->panels[0];
2060 iobase = panelp->iobase;
2061 while (inb(brdp->iostatus) & EIO_INTRPEND)
2062 (* panelp->isr)(panelp, iobase);
2065 /*****************************************************************************/
2068 * Interrupt service routine for ECH-AT board types.
2071 static void stl_echatintr(stlbrd_t *brdp)
2073 stlpanel_t *panelp;
2074 unsigned int ioaddr;
2075 int bnknr;
2077 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2079 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2080 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2081 ioaddr = brdp->bnkstataddr[bnknr];
2082 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2083 panelp = brdp->bnk2panel[bnknr];
2084 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2089 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2092 /*****************************************************************************/
2095 * Interrupt service routine for ECH-MCA board types.
2098 static void stl_echmcaintr(stlbrd_t *brdp)
2100 stlpanel_t *panelp;
2101 unsigned int ioaddr;
2102 int bnknr;
2104 while (inb(brdp->iostatus) & ECH_INTRPEND) {
2105 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2106 ioaddr = brdp->bnkstataddr[bnknr];
2107 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2108 panelp = brdp->bnk2panel[bnknr];
2109 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2115 /*****************************************************************************/
2118 * Interrupt service routine for ECH-PCI board types.
2121 static void stl_echpciintr(stlbrd_t *brdp)
2123 stlpanel_t *panelp;
2124 unsigned int ioaddr;
2125 int bnknr, recheck;
2127 while (1) {
2128 recheck = 0;
2129 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2130 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
2131 ioaddr = brdp->bnkstataddr[bnknr];
2132 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2133 panelp = brdp->bnk2panel[bnknr];
2134 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2135 recheck++;
2138 if (! recheck)
2139 break;
2143 /*****************************************************************************/
2146 * Interrupt service routine for ECH-8/64-PCI board types.
2149 static void stl_echpci64intr(stlbrd_t *brdp)
2151 stlpanel_t *panelp;
2152 unsigned int ioaddr;
2153 int bnknr;
2155 while (inb(brdp->ioctrl) & 0x1) {
2156 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
2157 ioaddr = brdp->bnkstataddr[bnknr];
2158 if (inb(ioaddr) & ECH_PNLINTRPEND) {
2159 panelp = brdp->bnk2panel[bnknr];
2160 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2166 /*****************************************************************************/
2169 * Service an off-level request for some channel.
2171 static void stl_offintr(void *private)
2173 stlport_t *portp;
2174 struct tty_struct *tty;
2175 unsigned int oldsigs;
2177 portp = private;
2179 #ifdef DEBUG
2180 printk("stl_offintr(portp=%x)\n", (int) portp);
2181 #endif
2183 if (portp == (stlport_t *) NULL)
2184 return;
2186 tty = portp->tty;
2187 if (tty == (struct tty_struct *) NULL)
2188 return;
2190 lock_kernel();
2191 if (test_bit(ASYI_TXLOW, &portp->istate)) {
2192 tty_wakeup(tty);
2194 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
2195 clear_bit(ASYI_DCDCHANGE, &portp->istate);
2196 oldsigs = portp->sigs;
2197 portp->sigs = stl_getsignals(portp);
2198 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
2199 wake_up_interruptible(&portp->open_wait);
2200 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
2201 if (portp->flags & ASYNC_CHECK_CD)
2202 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2205 unlock_kernel();
2208 /*****************************************************************************/
2211 * Map in interrupt vector to this driver. Check that we don't
2212 * already have this vector mapped, we might be sharing this
2213 * interrupt across multiple boards.
2216 static int __init stl_mapirq(int irq, char *name)
2218 int rc, i;
2220 #ifdef DEBUG
2221 printk("stl_mapirq(irq=%d,name=%s)\n", irq, name);
2222 #endif
2224 rc = 0;
2225 for (i = 0; (i < stl_numintrs); i++) {
2226 if (stl_gotintrs[i] == irq)
2227 break;
2229 if (i >= stl_numintrs) {
2230 if (request_irq(irq, stl_intr, SA_SHIRQ, name, NULL) != 0) {
2231 printk("STALLION: failed to register interrupt "
2232 "routine for %s irq=%d\n", name, irq);
2233 rc = -ENODEV;
2234 } else {
2235 stl_gotintrs[stl_numintrs++] = irq;
2238 return(rc);
2241 /*****************************************************************************/
2244 * Initialize all the ports on a panel.
2247 static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2249 stlport_t *portp;
2250 int chipmask, i;
2252 #ifdef DEBUG
2253 printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
2254 #endif
2256 chipmask = stl_panelinit(brdp, panelp);
2259 * All UART's are initialized (if found!). Now go through and setup
2260 * each ports data structures.
2262 for (i = 0; (i < panelp->nrports); i++) {
2263 portp = (stlport_t *) stl_memalloc(sizeof(stlport_t));
2264 if (portp == (stlport_t *) NULL) {
2265 printk("STALLION: failed to allocate memory "
2266 "(size=%d)\n", sizeof(stlport_t));
2267 break;
2269 memset(portp, 0, sizeof(stlport_t));
2271 portp->magic = STL_PORTMAGIC;
2272 portp->portnr = i;
2273 portp->brdnr = panelp->brdnr;
2274 portp->panelnr = panelp->panelnr;
2275 portp->uartp = panelp->uartp;
2276 portp->clk = brdp->clk;
2277 portp->baud_base = STL_BAUDBASE;
2278 portp->close_delay = STL_CLOSEDELAY;
2279 portp->closing_wait = 30 * HZ;
2280 INIT_WORK(&portp->tqueue, stl_offintr, portp);
2281 init_waitqueue_head(&portp->open_wait);
2282 init_waitqueue_head(&portp->close_wait);
2283 portp->stats.brd = portp->brdnr;
2284 portp->stats.panel = portp->panelnr;
2285 portp->stats.port = portp->portnr;
2286 panelp->ports[i] = portp;
2287 stl_portinit(brdp, panelp, portp);
2290 return(0);
2293 /*****************************************************************************/
2296 * Try to find and initialize an EasyIO board.
2299 static inline int stl_initeio(stlbrd_t *brdp)
2301 stlpanel_t *panelp;
2302 unsigned int status;
2303 char *name;
2304 int rc;
2306 #ifdef DEBUG
2307 printk("stl_initeio(brdp=%x)\n", (int) brdp);
2308 #endif
2310 brdp->ioctrl = brdp->ioaddr1 + 1;
2311 brdp->iostatus = brdp->ioaddr1 + 2;
2313 status = inb(brdp->iostatus);
2314 if ((status & EIO_IDBITMASK) == EIO_MK3)
2315 brdp->ioctrl++;
2318 * Handle board specific stuff now. The real difference is PCI
2319 * or not PCI.
2321 if (brdp->brdtype == BRD_EASYIOPCI) {
2322 brdp->iosize1 = 0x80;
2323 brdp->iosize2 = 0x80;
2324 name = "serial(EIO-PCI)";
2325 outb(0x41, (brdp->ioaddr2 + 0x4c));
2326 } else {
2327 brdp->iosize1 = 8;
2328 name = "serial(EIO)";
2329 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2330 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2331 printk("STALLION: invalid irq=%d for brd=%d\n",
2332 brdp->irq, brdp->brdnr);
2333 return(-EINVAL);
2335 outb((stl_vecmap[brdp->irq] | EIO_0WS |
2336 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
2337 brdp->ioctrl);
2340 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2341 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2342 "%x conflicts with another device\n", brdp->brdnr,
2343 brdp->ioaddr1);
2344 return(-EBUSY);
2347 if (brdp->iosize2 > 0)
2348 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2349 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2350 "address %x conflicts with another device\n",
2351 brdp->brdnr, brdp->ioaddr2);
2352 printk(KERN_WARNING "STALLION: Warning, also "
2353 "releasing board %d I/O address %x \n",
2354 brdp->brdnr, brdp->ioaddr1);
2355 release_region(brdp->ioaddr1, brdp->iosize1);
2356 return(-EBUSY);
2360 * Everything looks OK, so let's go ahead and probe for the hardware.
2362 brdp->clk = CD1400_CLK;
2363 brdp->isr = stl_eiointr;
2365 switch (status & EIO_IDBITMASK) {
2366 case EIO_8PORTM:
2367 brdp->clk = CD1400_CLK8M;
2368 /* fall thru */
2369 case EIO_8PORTRS:
2370 case EIO_8PORTDI:
2371 brdp->nrports = 8;
2372 break;
2373 case EIO_4PORTRS:
2374 brdp->nrports = 4;
2375 break;
2376 case EIO_MK3:
2377 switch (status & EIO_BRDMASK) {
2378 case ID_BRD4:
2379 brdp->nrports = 4;
2380 break;
2381 case ID_BRD8:
2382 brdp->nrports = 8;
2383 break;
2384 case ID_BRD16:
2385 brdp->nrports = 16;
2386 break;
2387 default:
2388 return(-ENODEV);
2390 break;
2391 default:
2392 return(-ENODEV);
2396 * We have verified that the board is actually present, so now we
2397 * can complete the setup.
2400 panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
2401 if (panelp == (stlpanel_t *) NULL) {
2402 printk(KERN_WARNING "STALLION: failed to allocate memory "
2403 "(size=%d)\n", sizeof(stlpanel_t));
2404 return(-ENOMEM);
2406 memset(panelp, 0, sizeof(stlpanel_t));
2408 panelp->magic = STL_PANELMAGIC;
2409 panelp->brdnr = brdp->brdnr;
2410 panelp->panelnr = 0;
2411 panelp->nrports = brdp->nrports;
2412 panelp->iobase = brdp->ioaddr1;
2413 panelp->hwid = status;
2414 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2415 panelp->uartp = (void *) &stl_sc26198uart;
2416 panelp->isr = stl_sc26198intr;
2417 } else {
2418 panelp->uartp = (void *) &stl_cd1400uart;
2419 panelp->isr = stl_cd1400eiointr;
2422 brdp->panels[0] = panelp;
2423 brdp->nrpanels = 1;
2424 brdp->state |= BRD_FOUND;
2425 brdp->hwid = status;
2426 rc = stl_mapirq(brdp->irq, name);
2427 return(rc);
2430 /*****************************************************************************/
2433 * Try to find an ECH board and initialize it. This code is capable of
2434 * dealing with all types of ECH board.
2437 static inline int stl_initech(stlbrd_t *brdp)
2439 stlpanel_t *panelp;
2440 unsigned int status, nxtid, ioaddr, conflict;
2441 int panelnr, banknr, i;
2442 char *name;
2444 #ifdef DEBUG
2445 printk("stl_initech(brdp=%x)\n", (int) brdp);
2446 #endif
2448 status = 0;
2449 conflict = 0;
2452 * Set up the initial board register contents for boards. This varies a
2453 * bit between the different board types. So we need to handle each
2454 * separately. Also do a check that the supplied IRQ is good.
2456 switch (brdp->brdtype) {
2458 case BRD_ECH:
2459 brdp->isr = stl_echatintr;
2460 brdp->ioctrl = brdp->ioaddr1 + 1;
2461 brdp->iostatus = brdp->ioaddr1 + 1;
2462 status = inb(brdp->iostatus);
2463 if ((status & ECH_IDBITMASK) != ECH_ID)
2464 return(-ENODEV);
2465 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2466 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2467 printk("STALLION: invalid irq=%d for brd=%d\n",
2468 brdp->irq, brdp->brdnr);
2469 return(-EINVAL);
2471 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2472 status |= (stl_vecmap[brdp->irq] << 1);
2473 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2474 brdp->ioctrlval = ECH_INTENABLE |
2475 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2476 for (i = 0; (i < 10); i++)
2477 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2478 brdp->iosize1 = 2;
2479 brdp->iosize2 = 32;
2480 name = "serial(EC8/32)";
2481 outb(status, brdp->ioaddr1);
2482 break;
2484 case BRD_ECHMC:
2485 brdp->isr = stl_echmcaintr;
2486 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2487 brdp->iostatus = brdp->ioctrl;
2488 status = inb(brdp->iostatus);
2489 if ((status & ECH_IDBITMASK) != ECH_ID)
2490 return(-ENODEV);
2491 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2492 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2493 printk("STALLION: invalid irq=%d for brd=%d\n",
2494 brdp->irq, brdp->brdnr);
2495 return(-EINVAL);
2497 outb(ECHMC_BRDRESET, brdp->ioctrl);
2498 outb(ECHMC_INTENABLE, brdp->ioctrl);
2499 brdp->iosize1 = 64;
2500 name = "serial(EC8/32-MC)";
2501 break;
2503 case BRD_ECHPCI:
2504 brdp->isr = stl_echpciintr;
2505 brdp->ioctrl = brdp->ioaddr1 + 2;
2506 brdp->iosize1 = 4;
2507 brdp->iosize2 = 8;
2508 name = "serial(EC8/32-PCI)";
2509 break;
2511 case BRD_ECH64PCI:
2512 brdp->isr = stl_echpci64intr;
2513 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2514 outb(0x43, (brdp->ioaddr1 + 0x4c));
2515 brdp->iosize1 = 0x80;
2516 brdp->iosize2 = 0x80;
2517 name = "serial(EC8/64-PCI)";
2518 break;
2520 default:
2521 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
2522 return(-EINVAL);
2523 break;
2527 * Check boards for possible IO address conflicts and return fail status
2528 * if an IO conflict found.
2530 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2531 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2532 "%x conflicts with another device\n", brdp->brdnr,
2533 brdp->ioaddr1);
2534 return(-EBUSY);
2537 if (brdp->iosize2 > 0)
2538 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2539 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2540 "address %x conflicts with another device\n",
2541 brdp->brdnr, brdp->ioaddr2);
2542 printk(KERN_WARNING "STALLION: Warning, also "
2543 "releasing board %d I/O address %x \n",
2544 brdp->brdnr, brdp->ioaddr1);
2545 release_region(brdp->ioaddr1, brdp->iosize1);
2546 return(-EBUSY);
2550 * Scan through the secondary io address space looking for panels.
2551 * As we find'em allocate and initialize panel structures for each.
2553 brdp->clk = CD1400_CLK;
2554 brdp->hwid = status;
2556 ioaddr = brdp->ioaddr2;
2557 banknr = 0;
2558 panelnr = 0;
2559 nxtid = 0;
2561 for (i = 0; (i < STL_MAXPANELS); i++) {
2562 if (brdp->brdtype == BRD_ECHPCI) {
2563 outb(nxtid, brdp->ioctrl);
2564 ioaddr = brdp->ioaddr2;
2566 status = inb(ioaddr + ECH_PNLSTATUS);
2567 if ((status & ECH_PNLIDMASK) != nxtid)
2568 break;
2569 panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
2570 if (panelp == (stlpanel_t *) NULL) {
2571 printk("STALLION: failed to allocate memory "
2572 "(size=%d)\n", sizeof(stlpanel_t));
2573 break;
2575 memset(panelp, 0, sizeof(stlpanel_t));
2576 panelp->magic = STL_PANELMAGIC;
2577 panelp->brdnr = brdp->brdnr;
2578 panelp->panelnr = panelnr;
2579 panelp->iobase = ioaddr;
2580 panelp->pagenr = nxtid;
2581 panelp->hwid = status;
2582 brdp->bnk2panel[banknr] = panelp;
2583 brdp->bnkpageaddr[banknr] = nxtid;
2584 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2586 if (status & ECH_PNLXPID) {
2587 panelp->uartp = (void *) &stl_sc26198uart;
2588 panelp->isr = stl_sc26198intr;
2589 if (status & ECH_PNL16PORT) {
2590 panelp->nrports = 16;
2591 brdp->bnk2panel[banknr] = panelp;
2592 brdp->bnkpageaddr[banknr] = nxtid;
2593 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2594 ECH_PNLSTATUS;
2595 } else {
2596 panelp->nrports = 8;
2598 } else {
2599 panelp->uartp = (void *) &stl_cd1400uart;
2600 panelp->isr = stl_cd1400echintr;
2601 if (status & ECH_PNL16PORT) {
2602 panelp->nrports = 16;
2603 panelp->ackmask = 0x80;
2604 if (brdp->brdtype != BRD_ECHPCI)
2605 ioaddr += EREG_BANKSIZE;
2606 brdp->bnk2panel[banknr] = panelp;
2607 brdp->bnkpageaddr[banknr] = ++nxtid;
2608 brdp->bnkstataddr[banknr++] = ioaddr +
2609 ECH_PNLSTATUS;
2610 } else {
2611 panelp->nrports = 8;
2612 panelp->ackmask = 0xc0;
2616 nxtid++;
2617 ioaddr += EREG_BANKSIZE;
2618 brdp->nrports += panelp->nrports;
2619 brdp->panels[panelnr++] = panelp;
2620 if ((brdp->brdtype != BRD_ECHPCI) &&
2621 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
2622 break;
2625 brdp->nrpanels = panelnr;
2626 brdp->nrbnks = banknr;
2627 if (brdp->brdtype == BRD_ECH)
2628 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2630 brdp->state |= BRD_FOUND;
2631 i = stl_mapirq(brdp->irq, name);
2632 return(i);
2635 /*****************************************************************************/
2638 * Initialize and configure the specified board.
2639 * Scan through all the boards in the configuration and see what we
2640 * can find. Handle EIO and the ECH boards a little differently here
2641 * since the initial search and setup is very different.
2644 static int __init stl_brdinit(stlbrd_t *brdp)
2646 int i;
2648 #ifdef DEBUG
2649 printk("stl_brdinit(brdp=%x)\n", (int) brdp);
2650 #endif
2652 switch (brdp->brdtype) {
2653 case BRD_EASYIO:
2654 case BRD_EASYIOPCI:
2655 stl_initeio(brdp);
2656 break;
2657 case BRD_ECH:
2658 case BRD_ECHMC:
2659 case BRD_ECHPCI:
2660 case BRD_ECH64PCI:
2661 stl_initech(brdp);
2662 break;
2663 default:
2664 printk("STALLION: board=%d is unknown board type=%d\n",
2665 brdp->brdnr, brdp->brdtype);
2666 return(ENODEV);
2669 stl_brds[brdp->brdnr] = brdp;
2670 if ((brdp->state & BRD_FOUND) == 0) {
2671 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2672 stl_brdnames[brdp->brdtype], brdp->brdnr,
2673 brdp->ioaddr1, brdp->irq);
2674 return(ENODEV);
2677 for (i = 0; (i < STL_MAXPANELS); i++)
2678 if (brdp->panels[i] != (stlpanel_t *) NULL)
2679 stl_initports(brdp, brdp->panels[i]);
2681 printk("STALLION: %s found, board=%d io=%x irq=%d "
2682 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2683 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2684 brdp->nrports);
2685 return(0);
2688 /*****************************************************************************/
2691 * Find the next available board number that is free.
2694 static inline int stl_getbrdnr(void)
2696 int i;
2698 for (i = 0; (i < STL_MAXBRDS); i++) {
2699 if (stl_brds[i] == (stlbrd_t *) NULL) {
2700 if (i >= stl_nrbrds)
2701 stl_nrbrds = i + 1;
2702 return(i);
2705 return(-1);
2708 /*****************************************************************************/
2710 #ifdef CONFIG_PCI
2713 * We have a Stallion board. Allocate a board structure and
2714 * initialize it. Read its IO and IRQ resources from PCI
2715 * configuration space.
2718 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
2720 stlbrd_t *brdp;
2722 #ifdef DEBUG
2723 printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
2724 devp->bus->number, devp->devfn);
2725 #endif
2727 if (pci_enable_device(devp))
2728 return(-EIO);
2729 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2730 return(-ENOMEM);
2731 if ((brdp->brdnr = stl_getbrdnr()) < 0) {
2732 printk("STALLION: too many boards found, "
2733 "maximum supported %d\n", STL_MAXBRDS);
2734 return(0);
2736 brdp->brdtype = brdtype;
2739 * Different Stallion boards use the BAR registers in different ways,
2740 * so set up io addresses based on board type.
2742 #ifdef DEBUG
2743 printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__, __LINE__,
2744 pci_resource_start(devp, 0), pci_resource_start(devp, 1),
2745 pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
2746 #endif
2749 * We have all resources from the board, so let's setup the actual
2750 * board structure now.
2752 switch (brdtype) {
2753 case BRD_ECHPCI:
2754 brdp->ioaddr2 = pci_resource_start(devp, 0);
2755 brdp->ioaddr1 = pci_resource_start(devp, 1);
2756 break;
2757 case BRD_ECH64PCI:
2758 brdp->ioaddr2 = pci_resource_start(devp, 2);
2759 brdp->ioaddr1 = pci_resource_start(devp, 1);
2760 break;
2761 case BRD_EASYIOPCI:
2762 brdp->ioaddr1 = pci_resource_start(devp, 2);
2763 brdp->ioaddr2 = pci_resource_start(devp, 1);
2764 break;
2765 default:
2766 printk("STALLION: unknown PCI board type=%d\n", brdtype);
2767 break;
2770 brdp->irq = devp->irq;
2771 stl_brdinit(brdp);
2773 return(0);
2776 /*****************************************************************************/
2779 * Find all Stallion PCI boards that might be installed. Initialize each
2780 * one as it is found.
2784 static inline int stl_findpcibrds(void)
2786 struct pci_dev *dev = NULL;
2787 int i, rc;
2789 #ifdef DEBUG
2790 printk("stl_findpcibrds()\n");
2791 #endif
2793 for (i = 0; (i < stl_nrpcibrds); i++)
2794 while ((dev = pci_find_device(stl_pcibrds[i].vendid,
2795 stl_pcibrds[i].devid, dev))) {
2798 * Found a device on the PCI bus that has our vendor and
2799 * device ID. Need to check now that it is really us.
2801 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2802 continue;
2804 rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
2805 if (rc)
2806 return(rc);
2809 return(0);
2812 #endif
2814 /*****************************************************************************/
2817 * Scan through all the boards in the configuration and see what we
2818 * can find. Handle EIO and the ECH boards a little differently here
2819 * since the initial search and setup is too different.
2822 static inline int stl_initbrds(void)
2824 stlbrd_t *brdp;
2825 stlconf_t *confp;
2826 int i;
2828 #ifdef DEBUG
2829 printk("stl_initbrds()\n");
2830 #endif
2832 if (stl_nrbrds > STL_MAXBRDS) {
2833 printk("STALLION: too many boards in configuration table, "
2834 "truncating to %d\n", STL_MAXBRDS);
2835 stl_nrbrds = STL_MAXBRDS;
2839 * Firstly scan the list of static boards configured. Allocate
2840 * resources and initialize the boards as found.
2842 for (i = 0; (i < stl_nrbrds); i++) {
2843 confp = &stl_brdconf[i];
2844 #ifdef MODULE
2845 stl_parsebrd(confp, stl_brdsp[i]);
2846 #endif
2847 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2848 return(-ENOMEM);
2849 brdp->brdnr = i;
2850 brdp->brdtype = confp->brdtype;
2851 brdp->ioaddr1 = confp->ioaddr1;
2852 brdp->ioaddr2 = confp->ioaddr2;
2853 brdp->irq = confp->irq;
2854 brdp->irqtype = confp->irqtype;
2855 stl_brdinit(brdp);
2859 * Find any dynamically supported boards. That is via module load
2860 * line options or auto-detected on the PCI bus.
2862 #ifdef MODULE
2863 stl_argbrds();
2864 #endif
2865 #ifdef CONFIG_PCI
2866 stl_findpcibrds();
2867 #endif
2869 return(0);
2872 /*****************************************************************************/
2875 * Return the board stats structure to user app.
2878 static int stl_getbrdstats(combrd_t __user *bp)
2880 stlbrd_t *brdp;
2881 stlpanel_t *panelp;
2882 int i;
2884 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2885 return -EFAULT;
2886 if (stl_brdstats.brd >= STL_MAXBRDS)
2887 return(-ENODEV);
2888 brdp = stl_brds[stl_brdstats.brd];
2889 if (brdp == (stlbrd_t *) NULL)
2890 return(-ENODEV);
2892 memset(&stl_brdstats, 0, sizeof(combrd_t));
2893 stl_brdstats.brd = brdp->brdnr;
2894 stl_brdstats.type = brdp->brdtype;
2895 stl_brdstats.hwid = brdp->hwid;
2896 stl_brdstats.state = brdp->state;
2897 stl_brdstats.ioaddr = brdp->ioaddr1;
2898 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2899 stl_brdstats.irq = brdp->irq;
2900 stl_brdstats.nrpanels = brdp->nrpanels;
2901 stl_brdstats.nrports = brdp->nrports;
2902 for (i = 0; (i < brdp->nrpanels); i++) {
2903 panelp = brdp->panels[i];
2904 stl_brdstats.panels[i].panel = i;
2905 stl_brdstats.panels[i].hwid = panelp->hwid;
2906 stl_brdstats.panels[i].nrports = panelp->nrports;
2909 return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
2912 /*****************************************************************************/
2915 * Resolve the referenced port number into a port struct pointer.
2918 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2920 stlbrd_t *brdp;
2921 stlpanel_t *panelp;
2923 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2924 return((stlport_t *) NULL);
2925 brdp = stl_brds[brdnr];
2926 if (brdp == (stlbrd_t *) NULL)
2927 return((stlport_t *) NULL);
2928 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2929 return((stlport_t *) NULL);
2930 panelp = brdp->panels[panelnr];
2931 if (panelp == (stlpanel_t *) NULL)
2932 return((stlport_t *) NULL);
2933 if ((portnr < 0) || (portnr >= panelp->nrports))
2934 return((stlport_t *) NULL);
2935 return(panelp->ports[portnr]);
2938 /*****************************************************************************/
2941 * Return the port stats structure to user app. A NULL port struct
2942 * pointer passed in means that we need to find out from the app
2943 * what port to get stats for (used through board control device).
2946 static int stl_getportstats(stlport_t *portp, comstats_t __user *cp)
2948 unsigned char *head, *tail;
2949 unsigned long flags;
2951 if (!portp) {
2952 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2953 return -EFAULT;
2954 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2955 stl_comstats.port);
2956 if (portp == (stlport_t *) NULL)
2957 return(-ENODEV);
2960 portp->stats.state = portp->istate;
2961 portp->stats.flags = portp->flags;
2962 portp->stats.hwid = portp->hwid;
2964 portp->stats.ttystate = 0;
2965 portp->stats.cflags = 0;
2966 portp->stats.iflags = 0;
2967 portp->stats.oflags = 0;
2968 portp->stats.lflags = 0;
2969 portp->stats.rxbuffered = 0;
2971 save_flags(flags);
2972 cli();
2973 if (portp->tty != (struct tty_struct *) NULL) {
2974 if (portp->tty->driver_data == portp) {
2975 portp->stats.ttystate = portp->tty->flags;
2976 portp->stats.rxbuffered = portp->tty->flip.count;
2977 if (portp->tty->termios != (struct termios *) NULL) {
2978 portp->stats.cflags = portp->tty->termios->c_cflag;
2979 portp->stats.iflags = portp->tty->termios->c_iflag;
2980 portp->stats.oflags = portp->tty->termios->c_oflag;
2981 portp->stats.lflags = portp->tty->termios->c_lflag;
2985 restore_flags(flags);
2987 head = portp->tx.head;
2988 tail = portp->tx.tail;
2989 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2990 (STL_TXBUFSIZE - (tail - head)));
2992 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2994 return copy_to_user(cp, &portp->stats,
2995 sizeof(comstats_t)) ? -EFAULT : 0;
2998 /*****************************************************************************/
3001 * Clear the port stats structure. We also return it zeroed out...
3004 static int stl_clrportstats(stlport_t *portp, comstats_t __user *cp)
3006 if (!portp) {
3007 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
3008 return -EFAULT;
3009 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
3010 stl_comstats.port);
3011 if (portp == (stlport_t *) NULL)
3012 return(-ENODEV);
3015 memset(&portp->stats, 0, sizeof(comstats_t));
3016 portp->stats.brd = portp->brdnr;
3017 portp->stats.panel = portp->panelnr;
3018 portp->stats.port = portp->portnr;
3019 return copy_to_user(cp, &portp->stats,
3020 sizeof(comstats_t)) ? -EFAULT : 0;
3023 /*****************************************************************************/
3026 * Return the entire driver ports structure to a user app.
3029 static int stl_getportstruct(stlport_t __user *arg)
3031 stlport_t *portp;
3033 if (copy_from_user(&stl_dummyport, arg, sizeof(stlport_t)))
3034 return -EFAULT;
3035 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
3036 stl_dummyport.portnr);
3037 if (!portp)
3038 return -ENODEV;
3039 return copy_to_user(arg, portp, sizeof(stlport_t)) ? -EFAULT : 0;
3042 /*****************************************************************************/
3045 * Return the entire driver board structure to a user app.
3048 static int stl_getbrdstruct(stlbrd_t __user *arg)
3050 stlbrd_t *brdp;
3052 if (copy_from_user(&stl_dummybrd, arg, sizeof(stlbrd_t)))
3053 return -EFAULT;
3054 if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
3055 return -ENODEV;
3056 brdp = stl_brds[stl_dummybrd.brdnr];
3057 if (!brdp)
3058 return(-ENODEV);
3059 return copy_to_user(arg, brdp, sizeof(stlbrd_t)) ? -EFAULT : 0;
3062 /*****************************************************************************/
3065 * The "staliomem" device is also required to do some special operations
3066 * on the board and/or ports. In this driver it is mostly used for stats
3067 * collection.
3070 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
3072 int brdnr, rc;
3073 void __user *argp = (void __user *)arg;
3075 #ifdef DEBUG
3076 printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
3077 (int) fp, cmd, (int) arg);
3078 #endif
3080 brdnr = iminor(ip);
3081 if (brdnr >= STL_MAXBRDS)
3082 return(-ENODEV);
3083 rc = 0;
3085 switch (cmd) {
3086 case COM_GETPORTSTATS:
3087 rc = stl_getportstats(NULL, argp);
3088 break;
3089 case COM_CLRPORTSTATS:
3090 rc = stl_clrportstats(NULL, argp);
3091 break;
3092 case COM_GETBRDSTATS:
3093 rc = stl_getbrdstats(argp);
3094 break;
3095 case COM_READPORT:
3096 rc = stl_getportstruct(argp);
3097 break;
3098 case COM_READBOARD:
3099 rc = stl_getbrdstruct(argp);
3100 break;
3101 default:
3102 rc = -ENOIOCTLCMD;
3103 break;
3106 return(rc);
3109 static struct tty_operations stl_ops = {
3110 .open = stl_open,
3111 .close = stl_close,
3112 .write = stl_write,
3113 .put_char = stl_putchar,
3114 .flush_chars = stl_flushchars,
3115 .write_room = stl_writeroom,
3116 .chars_in_buffer = stl_charsinbuffer,
3117 .ioctl = stl_ioctl,
3118 .set_termios = stl_settermios,
3119 .throttle = stl_throttle,
3120 .unthrottle = stl_unthrottle,
3121 .stop = stl_stop,
3122 .start = stl_start,
3123 .hangup = stl_hangup,
3124 .flush_buffer = stl_flushbuffer,
3125 .break_ctl = stl_breakctl,
3126 .wait_until_sent = stl_waituntilsent,
3127 .send_xchar = stl_sendxchar,
3128 .read_proc = stl_readproc,
3129 .tiocmget = stl_tiocmget,
3130 .tiocmset = stl_tiocmset,
3133 /*****************************************************************************/
3135 int __init stl_init(void)
3137 int i;
3138 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
3140 stl_initbrds();
3142 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
3143 if (!stl_serial)
3144 return -1;
3147 * Allocate a temporary write buffer.
3149 stl_tmpwritebuf = (char *) stl_memalloc(STL_TXBUFSIZE);
3150 if (stl_tmpwritebuf == (char *) NULL)
3151 printk("STALLION: failed to allocate memory (size=%d)\n",
3152 STL_TXBUFSIZE);
3155 * Set up a character driver for per board stuff. This is mainly used
3156 * to do stats ioctls on the ports.
3158 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
3159 printk("STALLION: failed to register serial board device\n");
3160 devfs_mk_dir("staliomem");
3162 stallion_class = class_simple_create(THIS_MODULE, "staliomem");
3163 for (i = 0; i < 4; i++) {
3164 devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR, i),
3165 S_IFCHR|S_IRUSR|S_IWUSR,
3166 "staliomem/%d", i);
3167 class_simple_device_add(stallion_class, MKDEV(STL_SIOMEMMAJOR, i), NULL, "staliomem%d", i);
3170 stl_serial->owner = THIS_MODULE;
3171 stl_serial->driver_name = stl_drvname;
3172 stl_serial->name = "ttyE";
3173 stl_serial->devfs_name = "tts/E";
3174 stl_serial->major = STL_SERIALMAJOR;
3175 stl_serial->minor_start = 0;
3176 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
3177 stl_serial->subtype = SERIAL_TYPE_NORMAL;
3178 stl_serial->init_termios = stl_deftermios;
3179 stl_serial->flags = TTY_DRIVER_REAL_RAW;
3180 tty_set_operations(stl_serial, &stl_ops);
3182 if (tty_register_driver(stl_serial)) {
3183 put_tty_driver(stl_serial);
3184 printk("STALLION: failed to register serial driver\n");
3185 return -1;
3188 return(0);
3191 /*****************************************************************************/
3192 /* CD1400 HARDWARE FUNCTIONS */
3193 /*****************************************************************************/
3196 * These functions get/set/update the registers of the cd1400 UARTs.
3197 * Access to the cd1400 registers is via an address/data io port pair.
3198 * (Maybe should make this inline...)
3201 static int stl_cd1400getreg(stlport_t *portp, int regnr)
3203 outb((regnr + portp->uartaddr), portp->ioaddr);
3204 return(inb(portp->ioaddr + EREG_DATA));
3207 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
3209 outb((regnr + portp->uartaddr), portp->ioaddr);
3210 outb(value, portp->ioaddr + EREG_DATA);
3213 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
3215 outb((regnr + portp->uartaddr), portp->ioaddr);
3216 if (inb(portp->ioaddr + EREG_DATA) != value) {
3217 outb(value, portp->ioaddr + EREG_DATA);
3218 return(1);
3220 return(0);
3223 /*****************************************************************************/
3226 * Inbitialize the UARTs in a panel. We don't care what sort of board
3227 * these ports are on - since the port io registers are almost
3228 * identical when dealing with ports.
3231 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3233 unsigned int gfrcr;
3234 int chipmask, i, j;
3235 int nrchips, uartaddr, ioaddr;
3237 #ifdef DEBUG
3238 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
3239 #endif
3241 BRDENABLE(panelp->brdnr, panelp->pagenr);
3244 * Check that each chip is present and started up OK.
3246 chipmask = 0;
3247 nrchips = panelp->nrports / CD1400_PORTS;
3248 for (i = 0; (i < nrchips); i++) {
3249 if (brdp->brdtype == BRD_ECHPCI) {
3250 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3251 ioaddr = panelp->iobase;
3252 } else {
3253 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3255 uartaddr = (i & 0x01) ? 0x080 : 0;
3256 outb((GFRCR + uartaddr), ioaddr);
3257 outb(0, (ioaddr + EREG_DATA));
3258 outb((CCR + uartaddr), ioaddr);
3259 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3260 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3261 outb((GFRCR + uartaddr), ioaddr);
3262 for (j = 0; (j < CCR_MAXWAIT); j++) {
3263 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3264 break;
3266 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3267 printk("STALLION: cd1400 not responding, "
3268 "brd=%d panel=%d chip=%d\n",
3269 panelp->brdnr, panelp->panelnr, i);
3270 continue;
3272 chipmask |= (0x1 << i);
3273 outb((PPR + uartaddr), ioaddr);
3274 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
3277 BRDDISABLE(panelp->brdnr);
3278 return(chipmask);
3281 /*****************************************************************************/
3284 * Initialize hardware specific port registers.
3287 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3289 #ifdef DEBUG
3290 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3291 (int) brdp, (int) panelp, (int) portp);
3292 #endif
3294 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
3295 (portp == (stlport_t *) NULL))
3296 return;
3298 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3299 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3300 portp->uartaddr = (portp->portnr & 0x04) << 5;
3301 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3303 BRDENABLE(portp->brdnr, portp->pagenr);
3304 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3305 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3306 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3307 BRDDISABLE(portp->brdnr);
3310 /*****************************************************************************/
3313 * Wait for the command register to be ready. We will poll this,
3314 * since it won't usually take too long to be ready.
3317 static void stl_cd1400ccrwait(stlport_t *portp)
3319 int i;
3321 for (i = 0; (i < CCR_MAXWAIT); i++) {
3322 if (stl_cd1400getreg(portp, CCR) == 0) {
3323 return;
3327 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
3328 portp->portnr, portp->panelnr, portp->brdnr);
3331 /*****************************************************************************/
3334 * Set up the cd1400 registers for a port based on the termios port
3335 * settings.
3338 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3340 stlbrd_t *brdp;
3341 unsigned long flags;
3342 unsigned int clkdiv, baudrate;
3343 unsigned char cor1, cor2, cor3;
3344 unsigned char cor4, cor5, ccr;
3345 unsigned char srer, sreron, sreroff;
3346 unsigned char mcor1, mcor2, rtpr;
3347 unsigned char clk, div;
3349 cor1 = 0;
3350 cor2 = 0;
3351 cor3 = 0;
3352 cor4 = 0;
3353 cor5 = 0;
3354 ccr = 0;
3355 rtpr = 0;
3356 clk = 0;
3357 div = 0;
3358 mcor1 = 0;
3359 mcor2 = 0;
3360 sreron = 0;
3361 sreroff = 0;
3363 brdp = stl_brds[portp->brdnr];
3364 if (brdp == (stlbrd_t *) NULL)
3365 return;
3368 * Set up the RX char ignore mask with those RX error types we
3369 * can ignore. We can get the cd1400 to help us out a little here,
3370 * it will ignore parity errors and breaks for us.
3372 portp->rxignoremsk = 0;
3373 if (tiosp->c_iflag & IGNPAR) {
3374 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
3375 cor1 |= COR1_PARIGNORE;
3377 if (tiosp->c_iflag & IGNBRK) {
3378 portp->rxignoremsk |= ST_BREAK;
3379 cor4 |= COR4_IGNBRK;
3382 portp->rxmarkmsk = ST_OVERRUN;
3383 if (tiosp->c_iflag & (INPCK | PARMRK))
3384 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3385 if (tiosp->c_iflag & BRKINT)
3386 portp->rxmarkmsk |= ST_BREAK;
3389 * Go through the char size, parity and stop bits and set all the
3390 * option register appropriately.
3392 switch (tiosp->c_cflag & CSIZE) {
3393 case CS5:
3394 cor1 |= COR1_CHL5;
3395 break;
3396 case CS6:
3397 cor1 |= COR1_CHL6;
3398 break;
3399 case CS7:
3400 cor1 |= COR1_CHL7;
3401 break;
3402 default:
3403 cor1 |= COR1_CHL8;
3404 break;
3407 if (tiosp->c_cflag & CSTOPB)
3408 cor1 |= COR1_STOP2;
3409 else
3410 cor1 |= COR1_STOP1;
3412 if (tiosp->c_cflag & PARENB) {
3413 if (tiosp->c_cflag & PARODD)
3414 cor1 |= (COR1_PARENB | COR1_PARODD);
3415 else
3416 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3417 } else {
3418 cor1 |= COR1_PARNONE;
3422 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3423 * space for hardware flow control and the like. This should be set to
3424 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3425 * really be based on VTIME.
3427 cor3 |= FIFO_RXTHRESHOLD;
3428 rtpr = 2;
3431 * Calculate the baud rate timers. For now we will just assume that
3432 * the input and output baud are the same. Could have used a baud
3433 * table here, but this way we can generate virtually any baud rate
3434 * we like!
3436 baudrate = tiosp->c_cflag & CBAUD;
3437 if (baudrate & CBAUDEX) {
3438 baudrate &= ~CBAUDEX;
3439 if ((baudrate < 1) || (baudrate > 4))
3440 tiosp->c_cflag &= ~CBAUDEX;
3441 else
3442 baudrate += 15;
3444 baudrate = stl_baudrates[baudrate];
3445 if ((tiosp->c_cflag & CBAUD) == B38400) {
3446 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3447 baudrate = 57600;
3448 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3449 baudrate = 115200;
3450 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3451 baudrate = 230400;
3452 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3453 baudrate = 460800;
3454 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3455 baudrate = (portp->baud_base / portp->custom_divisor);
3457 if (baudrate > STL_CD1400MAXBAUD)
3458 baudrate = STL_CD1400MAXBAUD;
3460 if (baudrate > 0) {
3461 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3462 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
3463 if (clkdiv < 0x100)
3464 break;
3466 div = (unsigned char) clkdiv;
3470 * Check what form of modem signaling is required and set it up.
3472 if ((tiosp->c_cflag & CLOCAL) == 0) {
3473 mcor1 |= MCOR1_DCD;
3474 mcor2 |= MCOR2_DCD;
3475 sreron |= SRER_MODEM;
3476 portp->flags |= ASYNC_CHECK_CD;
3477 } else {
3478 portp->flags &= ~ASYNC_CHECK_CD;
3482 * Setup cd1400 enhanced modes if we can. In particular we want to
3483 * handle as much of the flow control as possible automatically. As
3484 * well as saving a few CPU cycles it will also greatly improve flow
3485 * control reliability.
3487 if (tiosp->c_iflag & IXON) {
3488 cor2 |= COR2_TXIBE;
3489 cor3 |= COR3_SCD12;
3490 if (tiosp->c_iflag & IXANY)
3491 cor2 |= COR2_IXM;
3494 if (tiosp->c_cflag & CRTSCTS) {
3495 cor2 |= COR2_CTSAE;
3496 mcor1 |= FIFO_RTSTHRESHOLD;
3500 * All cd1400 register values calculated so go through and set
3501 * them all up.
3504 #ifdef DEBUG
3505 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3506 portp->portnr, portp->panelnr, portp->brdnr);
3507 printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3508 cor1, cor2, cor3, cor4, cor5);
3509 printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3510 mcor1, mcor2, rtpr, sreron, sreroff);
3511 printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3512 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3513 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3514 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3515 #endif
3517 save_flags(flags);
3518 cli();
3519 BRDENABLE(portp->brdnr, portp->pagenr);
3520 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3521 srer = stl_cd1400getreg(portp, SRER);
3522 stl_cd1400setreg(portp, SRER, 0);
3523 if (stl_cd1400updatereg(portp, COR1, cor1))
3524 ccr = 1;
3525 if (stl_cd1400updatereg(portp, COR2, cor2))
3526 ccr = 1;
3527 if (stl_cd1400updatereg(portp, COR3, cor3))
3528 ccr = 1;
3529 if (ccr) {
3530 stl_cd1400ccrwait(portp);
3531 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3533 stl_cd1400setreg(portp, COR4, cor4);
3534 stl_cd1400setreg(portp, COR5, cor5);
3535 stl_cd1400setreg(portp, MCOR1, mcor1);
3536 stl_cd1400setreg(portp, MCOR2, mcor2);
3537 if (baudrate > 0) {
3538 stl_cd1400setreg(portp, TCOR, clk);
3539 stl_cd1400setreg(portp, TBPR, div);
3540 stl_cd1400setreg(portp, RCOR, clk);
3541 stl_cd1400setreg(portp, RBPR, div);
3543 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3544 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3545 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3546 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3547 stl_cd1400setreg(portp, RTPR, rtpr);
3548 mcor1 = stl_cd1400getreg(portp, MSVR1);
3549 if (mcor1 & MSVR1_DCD)
3550 portp->sigs |= TIOCM_CD;
3551 else
3552 portp->sigs &= ~TIOCM_CD;
3553 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3554 BRDDISABLE(portp->brdnr);
3555 restore_flags(flags);
3558 /*****************************************************************************/
3561 * Set the state of the DTR and RTS signals.
3564 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3566 unsigned char msvr1, msvr2;
3567 unsigned long flags;
3569 #ifdef DEBUG
3570 printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
3571 (int) portp, dtr, rts);
3572 #endif
3574 msvr1 = 0;
3575 msvr2 = 0;
3576 if (dtr > 0)
3577 msvr1 = MSVR1_DTR;
3578 if (rts > 0)
3579 msvr2 = MSVR2_RTS;
3581 save_flags(flags);
3582 cli();
3583 BRDENABLE(portp->brdnr, portp->pagenr);
3584 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3585 if (rts >= 0)
3586 stl_cd1400setreg(portp, MSVR2, msvr2);
3587 if (dtr >= 0)
3588 stl_cd1400setreg(portp, MSVR1, msvr1);
3589 BRDDISABLE(portp->brdnr);
3590 restore_flags(flags);
3593 /*****************************************************************************/
3596 * Return the state of the signals.
3599 static int stl_cd1400getsignals(stlport_t *portp)
3601 unsigned char msvr1, msvr2;
3602 unsigned long flags;
3603 int sigs;
3605 #ifdef DEBUG
3606 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3607 #endif
3609 save_flags(flags);
3610 cli();
3611 BRDENABLE(portp->brdnr, portp->pagenr);
3612 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3613 msvr1 = stl_cd1400getreg(portp, MSVR1);
3614 msvr2 = stl_cd1400getreg(portp, MSVR2);
3615 BRDDISABLE(portp->brdnr);
3616 restore_flags(flags);
3618 sigs = 0;
3619 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3620 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3621 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3622 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3623 #if 0
3624 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3625 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3626 #else
3627 sigs |= TIOCM_DSR;
3628 #endif
3629 return(sigs);
3632 /*****************************************************************************/
3635 * Enable/Disable the Transmitter and/or Receiver.
3638 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3640 unsigned char ccr;
3641 unsigned long flags;
3643 #ifdef DEBUG
3644 printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3645 (int) portp, rx, tx);
3646 #endif
3647 ccr = 0;
3649 if (tx == 0)
3650 ccr |= CCR_TXDISABLE;
3651 else if (tx > 0)
3652 ccr |= CCR_TXENABLE;
3653 if (rx == 0)
3654 ccr |= CCR_RXDISABLE;
3655 else if (rx > 0)
3656 ccr |= CCR_RXENABLE;
3658 save_flags(flags);
3659 cli();
3660 BRDENABLE(portp->brdnr, portp->pagenr);
3661 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3662 stl_cd1400ccrwait(portp);
3663 stl_cd1400setreg(portp, CCR, ccr);
3664 stl_cd1400ccrwait(portp);
3665 BRDDISABLE(portp->brdnr);
3666 restore_flags(flags);
3669 /*****************************************************************************/
3672 * Start/stop the Transmitter and/or Receiver.
3675 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3677 unsigned char sreron, sreroff;
3678 unsigned long flags;
3680 #ifdef DEBUG
3681 printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3682 (int) portp, rx, tx);
3683 #endif
3685 sreron = 0;
3686 sreroff = 0;
3687 if (tx == 0)
3688 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3689 else if (tx == 1)
3690 sreron |= SRER_TXDATA;
3691 else if (tx >= 2)
3692 sreron |= SRER_TXEMPTY;
3693 if (rx == 0)
3694 sreroff |= SRER_RXDATA;
3695 else if (rx > 0)
3696 sreron |= SRER_RXDATA;
3698 save_flags(flags);
3699 cli();
3700 BRDENABLE(portp->brdnr, portp->pagenr);
3701 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3702 stl_cd1400setreg(portp, SRER,
3703 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3704 BRDDISABLE(portp->brdnr);
3705 if (tx > 0)
3706 set_bit(ASYI_TXBUSY, &portp->istate);
3707 restore_flags(flags);
3710 /*****************************************************************************/
3713 * Disable all interrupts from this port.
3716 static void stl_cd1400disableintrs(stlport_t *portp)
3718 unsigned long flags;
3720 #ifdef DEBUG
3721 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3722 #endif
3723 save_flags(flags);
3724 cli();
3725 BRDENABLE(portp->brdnr, portp->pagenr);
3726 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3727 stl_cd1400setreg(portp, SRER, 0);
3728 BRDDISABLE(portp->brdnr);
3729 restore_flags(flags);
3732 /*****************************************************************************/
3734 static void stl_cd1400sendbreak(stlport_t *portp, int len)
3736 unsigned long flags;
3738 #ifdef DEBUG
3739 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
3740 #endif
3742 save_flags(flags);
3743 cli();
3744 BRDENABLE(portp->brdnr, portp->pagenr);
3745 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3746 stl_cd1400setreg(portp, SRER,
3747 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3748 SRER_TXEMPTY));
3749 BRDDISABLE(portp->brdnr);
3750 portp->brklen = len;
3751 if (len == 1)
3752 portp->stats.txbreaks++;
3753 restore_flags(flags);
3756 /*****************************************************************************/
3759 * Take flow control actions...
3762 static void stl_cd1400flowctrl(stlport_t *portp, int state)
3764 struct tty_struct *tty;
3765 unsigned long flags;
3767 #ifdef DEBUG
3768 printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp, state);
3769 #endif
3771 if (portp == (stlport_t *) NULL)
3772 return;
3773 tty = portp->tty;
3774 if (tty == (struct tty_struct *) NULL)
3775 return;
3777 save_flags(flags);
3778 cli();
3779 BRDENABLE(portp->brdnr, portp->pagenr);
3780 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3782 if (state) {
3783 if (tty->termios->c_iflag & IXOFF) {
3784 stl_cd1400ccrwait(portp);
3785 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3786 portp->stats.rxxon++;
3787 stl_cd1400ccrwait(portp);
3790 * Question: should we return RTS to what it was before? It may
3791 * have been set by an ioctl... Suppose not, since if you have
3792 * hardware flow control set then it is pretty silly to go and
3793 * set the RTS line by hand.
3795 if (tty->termios->c_cflag & CRTSCTS) {
3796 stl_cd1400setreg(portp, MCOR1,
3797 (stl_cd1400getreg(portp, MCOR1) |
3798 FIFO_RTSTHRESHOLD));
3799 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3800 portp->stats.rxrtson++;
3802 } else {
3803 if (tty->termios->c_iflag & IXOFF) {
3804 stl_cd1400ccrwait(portp);
3805 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3806 portp->stats.rxxoff++;
3807 stl_cd1400ccrwait(portp);
3809 if (tty->termios->c_cflag & CRTSCTS) {
3810 stl_cd1400setreg(portp, MCOR1,
3811 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3812 stl_cd1400setreg(portp, MSVR2, 0);
3813 portp->stats.rxrtsoff++;
3817 BRDDISABLE(portp->brdnr);
3818 restore_flags(flags);
3821 /*****************************************************************************/
3824 * Send a flow control character...
3827 static void stl_cd1400sendflow(stlport_t *portp, int state)
3829 struct tty_struct *tty;
3830 unsigned long flags;
3832 #ifdef DEBUG
3833 printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp, state);
3834 #endif
3836 if (portp == (stlport_t *) NULL)
3837 return;
3838 tty = portp->tty;
3839 if (tty == (struct tty_struct *) NULL)
3840 return;
3842 save_flags(flags);
3843 cli();
3844 BRDENABLE(portp->brdnr, portp->pagenr);
3845 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3846 if (state) {
3847 stl_cd1400ccrwait(portp);
3848 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3849 portp->stats.rxxon++;
3850 stl_cd1400ccrwait(portp);
3851 } else {
3852 stl_cd1400ccrwait(portp);
3853 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3854 portp->stats.rxxoff++;
3855 stl_cd1400ccrwait(portp);
3857 BRDDISABLE(portp->brdnr);
3858 restore_flags(flags);
3861 /*****************************************************************************/
3863 static void stl_cd1400flush(stlport_t *portp)
3865 unsigned long flags;
3867 #ifdef DEBUG
3868 printk("stl_cd1400flush(portp=%x)\n", (int) portp);
3869 #endif
3871 if (portp == (stlport_t *) NULL)
3872 return;
3874 save_flags(flags);
3875 cli();
3876 BRDENABLE(portp->brdnr, portp->pagenr);
3877 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3878 stl_cd1400ccrwait(portp);
3879 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3880 stl_cd1400ccrwait(portp);
3881 portp->tx.tail = portp->tx.head;
3882 BRDDISABLE(portp->brdnr);
3883 restore_flags(flags);
3886 /*****************************************************************************/
3889 * Return the current state of data flow on this port. This is only
3890 * really interresting when determining if data has fully completed
3891 * transmission or not... This is easy for the cd1400, it accurately
3892 * maintains the busy port flag.
3895 static int stl_cd1400datastate(stlport_t *portp)
3897 #ifdef DEBUG
3898 printk("stl_cd1400datastate(portp=%x)\n", (int) portp);
3899 #endif
3901 if (portp == (stlport_t *) NULL)
3902 return(0);
3904 return(test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0);
3907 /*****************************************************************************/
3910 * Interrupt service routine for cd1400 EasyIO boards.
3913 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3915 unsigned char svrtype;
3917 #ifdef DEBUG
3918 printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
3919 (int) panelp, iobase);
3920 #endif
3922 outb(SVRR, iobase);
3923 svrtype = inb(iobase + EREG_DATA);
3924 if (panelp->nrports > 4) {
3925 outb((SVRR + 0x80), iobase);
3926 svrtype |= inb(iobase + EREG_DATA);
3929 if (svrtype & SVRR_RX)
3930 stl_cd1400rxisr(panelp, iobase);
3931 else if (svrtype & SVRR_TX)
3932 stl_cd1400txisr(panelp, iobase);
3933 else if (svrtype & SVRR_MDM)
3934 stl_cd1400mdmisr(panelp, iobase);
3937 /*****************************************************************************/
3940 * Interrupt service routine for cd1400 panels.
3943 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
3945 unsigned char svrtype;
3947 #ifdef DEBUG
3948 printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
3949 iobase);
3950 #endif
3952 outb(SVRR, iobase);
3953 svrtype = inb(iobase + EREG_DATA);
3954 outb((SVRR + 0x80), iobase);
3955 svrtype |= inb(iobase + EREG_DATA);
3956 if (svrtype & SVRR_RX)
3957 stl_cd1400rxisr(panelp, iobase);
3958 else if (svrtype & SVRR_TX)
3959 stl_cd1400txisr(panelp, iobase);
3960 else if (svrtype & SVRR_MDM)
3961 stl_cd1400mdmisr(panelp, iobase);
3965 /*****************************************************************************/
3968 * Unfortunately we need to handle breaks in the TX data stream, since
3969 * this is the only way to generate them on the cd1400.
3972 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr)
3974 if (portp->brklen == 1) {
3975 outb((COR2 + portp->uartaddr), ioaddr);
3976 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
3977 (ioaddr + EREG_DATA));
3978 outb((TDR + portp->uartaddr), ioaddr);
3979 outb(ETC_CMD, (ioaddr + EREG_DATA));
3980 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
3981 outb((SRER + portp->uartaddr), ioaddr);
3982 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
3983 (ioaddr + EREG_DATA));
3984 return(1);
3985 } else if (portp->brklen > 1) {
3986 outb((TDR + portp->uartaddr), ioaddr);
3987 outb(ETC_CMD, (ioaddr + EREG_DATA));
3988 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
3989 portp->brklen = -1;
3990 return(1);
3991 } else {
3992 outb((COR2 + portp->uartaddr), ioaddr);
3993 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
3994 (ioaddr + EREG_DATA));
3995 portp->brklen = 0;
3997 return(0);
4000 /*****************************************************************************/
4003 * Transmit interrupt handler. This has gotta be fast! Handling TX
4004 * chars is pretty simple, stuff as many as possible from the TX buffer
4005 * into the cd1400 FIFO. Must also handle TX breaks here, since they
4006 * are embedded as commands in the data stream. Oh no, had to use a goto!
4007 * This could be optimized more, will do when I get time...
4008 * In practice it is possible that interrupts are enabled but that the
4009 * port has been hung up. Need to handle not having any TX buffer here,
4010 * this is done by using the side effect that head and tail will also
4011 * be NULL if the buffer has been freed.
4014 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
4016 stlport_t *portp;
4017 int len, stlen;
4018 char *head, *tail;
4019 unsigned char ioack, srer;
4021 #ifdef DEBUG
4022 printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
4023 #endif
4025 ioack = inb(ioaddr + EREG_TXACK);
4026 if (((ioack & panelp->ackmask) != 0) ||
4027 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
4028 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
4029 return;
4031 portp = panelp->ports[(ioack >> 3)];
4034 * Unfortunately we need to handle breaks in the data stream, since
4035 * this is the only way to generate them on the cd1400. Do it now if
4036 * a break is to be sent.
4038 if (portp->brklen != 0)
4039 if (stl_cd1400breakisr(portp, ioaddr))
4040 goto stl_txalldone;
4042 head = portp->tx.head;
4043 tail = portp->tx.tail;
4044 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4045 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4046 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4047 set_bit(ASYI_TXLOW, &portp->istate);
4048 schedule_work(&portp->tqueue);
4051 if (len == 0) {
4052 outb((SRER + portp->uartaddr), ioaddr);
4053 srer = inb(ioaddr + EREG_DATA);
4054 if (srer & SRER_TXDATA) {
4055 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
4056 } else {
4057 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
4058 clear_bit(ASYI_TXBUSY, &portp->istate);
4060 outb(srer, (ioaddr + EREG_DATA));
4061 } else {
4062 len = MIN(len, CD1400_TXFIFOSIZE);
4063 portp->stats.txtotal += len;
4064 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4065 outb((TDR + portp->uartaddr), ioaddr);
4066 outsb((ioaddr + EREG_DATA), tail, stlen);
4067 len -= stlen;
4068 tail += stlen;
4069 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4070 tail = portp->tx.buf;
4071 if (len > 0) {
4072 outsb((ioaddr + EREG_DATA), tail, len);
4073 tail += len;
4075 portp->tx.tail = tail;
4078 stl_txalldone:
4079 outb((EOSRR + portp->uartaddr), ioaddr);
4080 outb(0, (ioaddr + EREG_DATA));
4083 /*****************************************************************************/
4086 * Receive character interrupt handler. Determine if we have good chars
4087 * or bad chars and then process appropriately. Good chars are easy
4088 * just shove the lot into the RX buffer and set all status byte to 0.
4089 * If a bad RX char then process as required. This routine needs to be
4090 * fast! In practice it is possible that we get an interrupt on a port
4091 * that is closed. This can happen on hangups - since they completely
4092 * shutdown a port not in user context. Need to handle this case.
4095 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
4097 stlport_t *portp;
4098 struct tty_struct *tty;
4099 unsigned int ioack, len, buflen;
4100 unsigned char status;
4101 char ch;
4103 #ifdef DEBUG
4104 printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
4105 #endif
4107 ioack = inb(ioaddr + EREG_RXACK);
4108 if ((ioack & panelp->ackmask) != 0) {
4109 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4110 return;
4112 portp = panelp->ports[(ioack >> 3)];
4113 tty = portp->tty;
4115 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
4116 outb((RDCR + portp->uartaddr), ioaddr);
4117 len = inb(ioaddr + EREG_DATA);
4118 if ((tty == (struct tty_struct *) NULL) ||
4119 (tty->flip.char_buf_ptr == (char *) NULL) ||
4120 ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
4121 len = MIN(len, sizeof(stl_unwanted));
4122 outb((RDSR + portp->uartaddr), ioaddr);
4123 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
4124 portp->stats.rxlost += len;
4125 portp->stats.rxtotal += len;
4126 } else {
4127 len = MIN(len, buflen);
4128 if (len > 0) {
4129 outb((RDSR + portp->uartaddr), ioaddr);
4130 insb((ioaddr + EREG_DATA), tty->flip.char_buf_ptr, len);
4131 memset(tty->flip.flag_buf_ptr, 0, len);
4132 tty->flip.flag_buf_ptr += len;
4133 tty->flip.char_buf_ptr += len;
4134 tty->flip.count += len;
4135 tty_schedule_flip(tty);
4136 portp->stats.rxtotal += len;
4139 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
4140 outb((RDSR + portp->uartaddr), ioaddr);
4141 status = inb(ioaddr + EREG_DATA);
4142 ch = inb(ioaddr + EREG_DATA);
4143 if (status & ST_PARITY)
4144 portp->stats.rxparity++;
4145 if (status & ST_FRAMING)
4146 portp->stats.rxframing++;
4147 if (status & ST_OVERRUN)
4148 portp->stats.rxoverrun++;
4149 if (status & ST_BREAK)
4150 portp->stats.rxbreaks++;
4151 if (status & ST_SCHARMASK) {
4152 if ((status & ST_SCHARMASK) == ST_SCHAR1)
4153 portp->stats.txxon++;
4154 if ((status & ST_SCHARMASK) == ST_SCHAR2)
4155 portp->stats.txxoff++;
4156 goto stl_rxalldone;
4158 if ((tty != (struct tty_struct *) NULL) &&
4159 ((portp->rxignoremsk & status) == 0)) {
4160 if (portp->rxmarkmsk & status) {
4161 if (status & ST_BREAK) {
4162 status = TTY_BREAK;
4163 if (portp->flags & ASYNC_SAK) {
4164 do_SAK(tty);
4165 BRDENABLE(portp->brdnr, portp->pagenr);
4167 } else if (status & ST_PARITY) {
4168 status = TTY_PARITY;
4169 } else if (status & ST_FRAMING) {
4170 status = TTY_FRAME;
4171 } else if(status & ST_OVERRUN) {
4172 status = TTY_OVERRUN;
4173 } else {
4174 status = 0;
4176 } else {
4177 status = 0;
4179 if (tty->flip.char_buf_ptr != (char *) NULL) {
4180 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
4181 *tty->flip.flag_buf_ptr++ = status;
4182 *tty->flip.char_buf_ptr++ = ch;
4183 tty->flip.count++;
4185 tty_schedule_flip(tty);
4188 } else {
4189 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4190 return;
4193 stl_rxalldone:
4194 outb((EOSRR + portp->uartaddr), ioaddr);
4195 outb(0, (ioaddr + EREG_DATA));
4198 /*****************************************************************************/
4201 * Modem interrupt handler. The is called when the modem signal line
4202 * (DCD) has changed state. Leave most of the work to the off-level
4203 * processing routine.
4206 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
4208 stlport_t *portp;
4209 unsigned int ioack;
4210 unsigned char misr;
4212 #ifdef DEBUG
4213 printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp);
4214 #endif
4216 ioack = inb(ioaddr + EREG_MDACK);
4217 if (((ioack & panelp->ackmask) != 0) ||
4218 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
4219 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
4220 return;
4222 portp = panelp->ports[(ioack >> 3)];
4224 outb((MISR + portp->uartaddr), ioaddr);
4225 misr = inb(ioaddr + EREG_DATA);
4226 if (misr & MISR_DCD) {
4227 set_bit(ASYI_DCDCHANGE, &portp->istate);
4228 schedule_work(&portp->tqueue);
4229 portp->stats.modem++;
4232 outb((EOSRR + portp->uartaddr), ioaddr);
4233 outb(0, (ioaddr + EREG_DATA));
4236 /*****************************************************************************/
4237 /* SC26198 HARDWARE FUNCTIONS */
4238 /*****************************************************************************/
4241 * These functions get/set/update the registers of the sc26198 UARTs.
4242 * Access to the sc26198 registers is via an address/data io port pair.
4243 * (Maybe should make this inline...)
4246 static int stl_sc26198getreg(stlport_t *portp, int regnr)
4248 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4249 return(inb(portp->ioaddr + XP_DATA));
4252 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
4254 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4255 outb(value, (portp->ioaddr + XP_DATA));
4258 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
4260 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4261 if (inb(portp->ioaddr + XP_DATA) != value) {
4262 outb(value, (portp->ioaddr + XP_DATA));
4263 return(1);
4265 return(0);
4268 /*****************************************************************************/
4271 * Functions to get and set the sc26198 global registers.
4274 static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
4276 outb(regnr, (portp->ioaddr + XP_ADDR));
4277 return(inb(portp->ioaddr + XP_DATA));
4280 #if 0
4281 static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
4283 outb(regnr, (portp->ioaddr + XP_ADDR));
4284 outb(value, (portp->ioaddr + XP_DATA));
4286 #endif
4288 /*****************************************************************************/
4291 * Inbitialize the UARTs in a panel. We don't care what sort of board
4292 * these ports are on - since the port io registers are almost
4293 * identical when dealing with ports.
4296 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
4298 int chipmask, i;
4299 int nrchips, ioaddr;
4301 #ifdef DEBUG
4302 printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
4303 (int) brdp, (int) panelp);
4304 #endif
4306 BRDENABLE(panelp->brdnr, panelp->pagenr);
4309 * Check that each chip is present and started up OK.
4311 chipmask = 0;
4312 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
4313 if (brdp->brdtype == BRD_ECHPCI)
4314 outb(panelp->pagenr, brdp->ioctrl);
4316 for (i = 0; (i < nrchips); i++) {
4317 ioaddr = panelp->iobase + (i * 4);
4318 outb(SCCR, (ioaddr + XP_ADDR));
4319 outb(CR_RESETALL, (ioaddr + XP_DATA));
4320 outb(TSTR, (ioaddr + XP_ADDR));
4321 if (inb(ioaddr + XP_DATA) != 0) {
4322 printk("STALLION: sc26198 not responding, "
4323 "brd=%d panel=%d chip=%d\n",
4324 panelp->brdnr, panelp->panelnr, i);
4325 continue;
4327 chipmask |= (0x1 << i);
4328 outb(GCCR, (ioaddr + XP_ADDR));
4329 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
4330 outb(WDTRCR, (ioaddr + XP_ADDR));
4331 outb(0xff, (ioaddr + XP_DATA));
4334 BRDDISABLE(panelp->brdnr);
4335 return(chipmask);
4338 /*****************************************************************************/
4341 * Initialize hardware specific port registers.
4344 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
4346 #ifdef DEBUG
4347 printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
4348 (int) brdp, (int) panelp, (int) portp);
4349 #endif
4351 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
4352 (portp == (stlport_t *) NULL))
4353 return;
4355 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
4356 portp->uartaddr = (portp->portnr & 0x07) << 4;
4357 portp->pagenr = panelp->pagenr;
4358 portp->hwid = 0x1;
4360 BRDENABLE(portp->brdnr, portp->pagenr);
4361 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
4362 BRDDISABLE(portp->brdnr);
4365 /*****************************************************************************/
4368 * Set up the sc26198 registers for a port based on the termios port
4369 * settings.
4372 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4374 stlbrd_t *brdp;
4375 unsigned long flags;
4376 unsigned int baudrate;
4377 unsigned char mr0, mr1, mr2, clk;
4378 unsigned char imron, imroff, iopr, ipr;
4380 mr0 = 0;
4381 mr1 = 0;
4382 mr2 = 0;
4383 clk = 0;
4384 iopr = 0;
4385 imron = 0;
4386 imroff = 0;
4388 brdp = stl_brds[portp->brdnr];
4389 if (brdp == (stlbrd_t *) NULL)
4390 return;
4393 * Set up the RX char ignore mask with those RX error types we
4394 * can ignore.
4396 portp->rxignoremsk = 0;
4397 if (tiosp->c_iflag & IGNPAR)
4398 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
4399 SR_RXOVERRUN);
4400 if (tiosp->c_iflag & IGNBRK)
4401 portp->rxignoremsk |= SR_RXBREAK;
4403 portp->rxmarkmsk = SR_RXOVERRUN;
4404 if (tiosp->c_iflag & (INPCK | PARMRK))
4405 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
4406 if (tiosp->c_iflag & BRKINT)
4407 portp->rxmarkmsk |= SR_RXBREAK;
4410 * Go through the char size, parity and stop bits and set all the
4411 * option register appropriately.
4413 switch (tiosp->c_cflag & CSIZE) {
4414 case CS5:
4415 mr1 |= MR1_CS5;
4416 break;
4417 case CS6:
4418 mr1 |= MR1_CS6;
4419 break;
4420 case CS7:
4421 mr1 |= MR1_CS7;
4422 break;
4423 default:
4424 mr1 |= MR1_CS8;
4425 break;
4428 if (tiosp->c_cflag & CSTOPB)
4429 mr2 |= MR2_STOP2;
4430 else
4431 mr2 |= MR2_STOP1;
4433 if (tiosp->c_cflag & PARENB) {
4434 if (tiosp->c_cflag & PARODD)
4435 mr1 |= (MR1_PARENB | MR1_PARODD);
4436 else
4437 mr1 |= (MR1_PARENB | MR1_PAREVEN);
4438 } else {
4439 mr1 |= MR1_PARNONE;
4442 mr1 |= MR1_ERRBLOCK;
4445 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4446 * space for hardware flow control and the like. This should be set to
4447 * VMIN.
4449 mr2 |= MR2_RXFIFOHALF;
4452 * Calculate the baud rate timers. For now we will just assume that
4453 * the input and output baud are the same. The sc26198 has a fixed
4454 * baud rate table, so only discrete baud rates possible.
4456 baudrate = tiosp->c_cflag & CBAUD;
4457 if (baudrate & CBAUDEX) {
4458 baudrate &= ~CBAUDEX;
4459 if ((baudrate < 1) || (baudrate > 4))
4460 tiosp->c_cflag &= ~CBAUDEX;
4461 else
4462 baudrate += 15;
4464 baudrate = stl_baudrates[baudrate];
4465 if ((tiosp->c_cflag & CBAUD) == B38400) {
4466 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
4467 baudrate = 57600;
4468 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
4469 baudrate = 115200;
4470 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
4471 baudrate = 230400;
4472 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
4473 baudrate = 460800;
4474 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
4475 baudrate = (portp->baud_base / portp->custom_divisor);
4477 if (baudrate > STL_SC26198MAXBAUD)
4478 baudrate = STL_SC26198MAXBAUD;
4480 if (baudrate > 0) {
4481 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
4482 if (baudrate <= sc26198_baudtable[clk])
4483 break;
4488 * Check what form of modem signaling is required and set it up.
4490 if (tiosp->c_cflag & CLOCAL) {
4491 portp->flags &= ~ASYNC_CHECK_CD;
4492 } else {
4493 iopr |= IOPR_DCDCOS;
4494 imron |= IR_IOPORT;
4495 portp->flags |= ASYNC_CHECK_CD;
4499 * Setup sc26198 enhanced modes if we can. In particular we want to
4500 * handle as much of the flow control as possible automatically. As
4501 * well as saving a few CPU cycles it will also greatly improve flow
4502 * control reliability.
4504 if (tiosp->c_iflag & IXON) {
4505 mr0 |= MR0_SWFTX | MR0_SWFT;
4506 imron |= IR_XONXOFF;
4507 } else {
4508 imroff |= IR_XONXOFF;
4510 if (tiosp->c_iflag & IXOFF)
4511 mr0 |= MR0_SWFRX;
4513 if (tiosp->c_cflag & CRTSCTS) {
4514 mr2 |= MR2_AUTOCTS;
4515 mr1 |= MR1_AUTORTS;
4519 * All sc26198 register values calculated so go through and set
4520 * them all up.
4523 #ifdef DEBUG
4524 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4525 portp->portnr, portp->panelnr, portp->brdnr);
4526 printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4527 printk(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4528 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4529 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4530 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4531 #endif
4533 save_flags(flags);
4534 cli();
4535 BRDENABLE(portp->brdnr, portp->pagenr);
4536 stl_sc26198setreg(portp, IMR, 0);
4537 stl_sc26198updatereg(portp, MR0, mr0);
4538 stl_sc26198updatereg(portp, MR1, mr1);
4539 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4540 stl_sc26198updatereg(portp, MR2, mr2);
4541 stl_sc26198updatereg(portp, IOPIOR,
4542 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
4544 if (baudrate > 0) {
4545 stl_sc26198setreg(portp, TXCSR, clk);
4546 stl_sc26198setreg(portp, RXCSR, clk);
4549 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4550 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4552 ipr = stl_sc26198getreg(portp, IPR);
4553 if (ipr & IPR_DCD)
4554 portp->sigs &= ~TIOCM_CD;
4555 else
4556 portp->sigs |= TIOCM_CD;
4558 portp->imr = (portp->imr & ~imroff) | imron;
4559 stl_sc26198setreg(portp, IMR, portp->imr);
4560 BRDDISABLE(portp->brdnr);
4561 restore_flags(flags);
4564 /*****************************************************************************/
4567 * Set the state of the DTR and RTS signals.
4570 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
4572 unsigned char iopioron, iopioroff;
4573 unsigned long flags;
4575 #ifdef DEBUG
4576 printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4577 (int) portp, dtr, rts);
4578 #endif
4580 iopioron = 0;
4581 iopioroff = 0;
4582 if (dtr == 0)
4583 iopioroff |= IPR_DTR;
4584 else if (dtr > 0)
4585 iopioron |= IPR_DTR;
4586 if (rts == 0)
4587 iopioroff |= IPR_RTS;
4588 else if (rts > 0)
4589 iopioron |= IPR_RTS;
4591 save_flags(flags);
4592 cli();
4593 BRDENABLE(portp->brdnr, portp->pagenr);
4594 stl_sc26198setreg(portp, IOPIOR,
4595 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4596 BRDDISABLE(portp->brdnr);
4597 restore_flags(flags);
4600 /*****************************************************************************/
4603 * Return the state of the signals.
4606 static int stl_sc26198getsignals(stlport_t *portp)
4608 unsigned char ipr;
4609 unsigned long flags;
4610 int sigs;
4612 #ifdef DEBUG
4613 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
4614 #endif
4616 save_flags(flags);
4617 cli();
4618 BRDENABLE(portp->brdnr, portp->pagenr);
4619 ipr = stl_sc26198getreg(portp, IPR);
4620 BRDDISABLE(portp->brdnr);
4621 restore_flags(flags);
4623 sigs = 0;
4624 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4625 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4626 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4627 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4628 sigs |= TIOCM_DSR;
4629 return(sigs);
4632 /*****************************************************************************/
4635 * Enable/Disable the Transmitter and/or Receiver.
4638 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
4640 unsigned char ccr;
4641 unsigned long flags;
4643 #ifdef DEBUG
4644 printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4645 (int) portp, rx, tx);
4646 #endif
4648 ccr = portp->crenable;
4649 if (tx == 0)
4650 ccr &= ~CR_TXENABLE;
4651 else if (tx > 0)
4652 ccr |= CR_TXENABLE;
4653 if (rx == 0)
4654 ccr &= ~CR_RXENABLE;
4655 else if (rx > 0)
4656 ccr |= CR_RXENABLE;
4658 save_flags(flags);
4659 cli();
4660 BRDENABLE(portp->brdnr, portp->pagenr);
4661 stl_sc26198setreg(portp, SCCR, ccr);
4662 BRDDISABLE(portp->brdnr);
4663 portp->crenable = ccr;
4664 restore_flags(flags);
4667 /*****************************************************************************/
4670 * Start/stop the Transmitter and/or Receiver.
4673 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
4675 unsigned char imr;
4676 unsigned long flags;
4678 #ifdef DEBUG
4679 printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4680 (int) portp, rx, tx);
4681 #endif
4683 imr = portp->imr;
4684 if (tx == 0)
4685 imr &= ~IR_TXRDY;
4686 else if (tx == 1)
4687 imr |= IR_TXRDY;
4688 if (rx == 0)
4689 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4690 else if (rx > 0)
4691 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4693 save_flags(flags);
4694 cli();
4695 BRDENABLE(portp->brdnr, portp->pagenr);
4696 stl_sc26198setreg(portp, IMR, imr);
4697 BRDDISABLE(portp->brdnr);
4698 portp->imr = imr;
4699 if (tx > 0)
4700 set_bit(ASYI_TXBUSY, &portp->istate);
4701 restore_flags(flags);
4704 /*****************************************************************************/
4707 * Disable all interrupts from this port.
4710 static void stl_sc26198disableintrs(stlport_t *portp)
4712 unsigned long flags;
4714 #ifdef DEBUG
4715 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
4716 #endif
4718 save_flags(flags);
4719 cli();
4720 BRDENABLE(portp->brdnr, portp->pagenr);
4721 portp->imr = 0;
4722 stl_sc26198setreg(portp, IMR, 0);
4723 BRDDISABLE(portp->brdnr);
4724 restore_flags(flags);
4727 /*****************************************************************************/
4729 static void stl_sc26198sendbreak(stlport_t *portp, int len)
4731 unsigned long flags;
4733 #ifdef DEBUG
4734 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
4735 #endif
4737 save_flags(flags);
4738 cli();
4739 BRDENABLE(portp->brdnr, portp->pagenr);
4740 if (len == 1) {
4741 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4742 portp->stats.txbreaks++;
4743 } else {
4744 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4746 BRDDISABLE(portp->brdnr);
4747 restore_flags(flags);
4750 /*****************************************************************************/
4753 * Take flow control actions...
4756 static void stl_sc26198flowctrl(stlport_t *portp, int state)
4758 struct tty_struct *tty;
4759 unsigned long flags;
4760 unsigned char mr0;
4762 #ifdef DEBUG
4763 printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp, state);
4764 #endif
4766 if (portp == (stlport_t *) NULL)
4767 return;
4768 tty = portp->tty;
4769 if (tty == (struct tty_struct *) NULL)
4770 return;
4772 save_flags(flags);
4773 cli();
4774 BRDENABLE(portp->brdnr, portp->pagenr);
4776 if (state) {
4777 if (tty->termios->c_iflag & IXOFF) {
4778 mr0 = stl_sc26198getreg(portp, MR0);
4779 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4780 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4781 mr0 |= MR0_SWFRX;
4782 portp->stats.rxxon++;
4783 stl_sc26198wait(portp);
4784 stl_sc26198setreg(portp, MR0, mr0);
4787 * Question: should we return RTS to what it was before? It may
4788 * have been set by an ioctl... Suppose not, since if you have
4789 * hardware flow control set then it is pretty silly to go and
4790 * set the RTS line by hand.
4792 if (tty->termios->c_cflag & CRTSCTS) {
4793 stl_sc26198setreg(portp, MR1,
4794 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4795 stl_sc26198setreg(portp, IOPIOR,
4796 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4797 portp->stats.rxrtson++;
4799 } else {
4800 if (tty->termios->c_iflag & IXOFF) {
4801 mr0 = stl_sc26198getreg(portp, MR0);
4802 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4803 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4804 mr0 &= ~MR0_SWFRX;
4805 portp->stats.rxxoff++;
4806 stl_sc26198wait(portp);
4807 stl_sc26198setreg(portp, MR0, mr0);
4809 if (tty->termios->c_cflag & CRTSCTS) {
4810 stl_sc26198setreg(portp, MR1,
4811 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4812 stl_sc26198setreg(portp, IOPIOR,
4813 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4814 portp->stats.rxrtsoff++;
4818 BRDDISABLE(portp->brdnr);
4819 restore_flags(flags);
4822 /*****************************************************************************/
4825 * Send a flow control character.
4828 static void stl_sc26198sendflow(stlport_t *portp, int state)
4830 struct tty_struct *tty;
4831 unsigned long flags;
4832 unsigned char mr0;
4834 #ifdef DEBUG
4835 printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp, state);
4836 #endif
4838 if (portp == (stlport_t *) NULL)
4839 return;
4840 tty = portp->tty;
4841 if (tty == (struct tty_struct *) NULL)
4842 return;
4844 save_flags(flags);
4845 cli();
4846 BRDENABLE(portp->brdnr, portp->pagenr);
4847 if (state) {
4848 mr0 = stl_sc26198getreg(portp, MR0);
4849 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4850 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4851 mr0 |= MR0_SWFRX;
4852 portp->stats.rxxon++;
4853 stl_sc26198wait(portp);
4854 stl_sc26198setreg(portp, MR0, mr0);
4855 } else {
4856 mr0 = stl_sc26198getreg(portp, MR0);
4857 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4858 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4859 mr0 &= ~MR0_SWFRX;
4860 portp->stats.rxxoff++;
4861 stl_sc26198wait(portp);
4862 stl_sc26198setreg(portp, MR0, mr0);
4864 BRDDISABLE(portp->brdnr);
4865 restore_flags(flags);
4868 /*****************************************************************************/
4870 static void stl_sc26198flush(stlport_t *portp)
4872 unsigned long flags;
4874 #ifdef DEBUG
4875 printk("stl_sc26198flush(portp=%x)\n", (int) portp);
4876 #endif
4878 if (portp == (stlport_t *) NULL)
4879 return;
4881 save_flags(flags);
4882 cli();
4883 BRDENABLE(portp->brdnr, portp->pagenr);
4884 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4885 stl_sc26198setreg(portp, SCCR, portp->crenable);
4886 BRDDISABLE(portp->brdnr);
4887 portp->tx.tail = portp->tx.head;
4888 restore_flags(flags);
4891 /*****************************************************************************/
4894 * Return the current state of data flow on this port. This is only
4895 * really interresting when determining if data has fully completed
4896 * transmission or not... The sc26198 interrupt scheme cannot
4897 * determine when all data has actually drained, so we need to
4898 * check the port statusy register to be sure.
4901 static int stl_sc26198datastate(stlport_t *portp)
4903 unsigned long flags;
4904 unsigned char sr;
4906 #ifdef DEBUG
4907 printk("stl_sc26198datastate(portp=%x)\n", (int) portp);
4908 #endif
4910 if (portp == (stlport_t *) NULL)
4911 return(0);
4912 if (test_bit(ASYI_TXBUSY, &portp->istate))
4913 return(1);
4915 save_flags(flags);
4916 cli();
4917 BRDENABLE(portp->brdnr, portp->pagenr);
4918 sr = stl_sc26198getreg(portp, SR);
4919 BRDDISABLE(portp->brdnr);
4920 restore_flags(flags);
4922 return((sr & SR_TXEMPTY) ? 0 : 1);
4925 /*****************************************************************************/
4928 * Delay for a small amount of time, to give the sc26198 a chance
4929 * to process a command...
4932 static void stl_sc26198wait(stlport_t *portp)
4934 int i;
4936 #ifdef DEBUG
4937 printk("stl_sc26198wait(portp=%x)\n", (int) portp);
4938 #endif
4940 if (portp == (stlport_t *) NULL)
4941 return;
4943 for (i = 0; (i < 20); i++)
4944 stl_sc26198getglobreg(portp, TSTR);
4947 /*****************************************************************************/
4950 * If we are TX flow controlled and in IXANY mode then we may
4951 * need to unflow control here. We gotta do this because of the
4952 * automatic flow control modes of the sc26198.
4955 static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty)
4957 unsigned char mr0;
4959 mr0 = stl_sc26198getreg(portp, MR0);
4960 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4961 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4962 stl_sc26198wait(portp);
4963 stl_sc26198setreg(portp, MR0, mr0);
4964 clear_bit(ASYI_TXFLOWED, &portp->istate);
4967 /*****************************************************************************/
4970 * Interrupt service routine for sc26198 panels.
4973 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4975 stlport_t *portp;
4976 unsigned int iack;
4979 * Work around bug in sc26198 chip... Cannot have A6 address
4980 * line of UART high, else iack will be returned as 0.
4982 outb(0, (iobase + 1));
4984 iack = inb(iobase + XP_IACK);
4985 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4987 if (iack & IVR_RXDATA)
4988 stl_sc26198rxisr(portp, iack);
4989 else if (iack & IVR_TXDATA)
4990 stl_sc26198txisr(portp);
4991 else
4992 stl_sc26198otherisr(portp, iack);
4995 /*****************************************************************************/
4998 * Transmit interrupt handler. This has gotta be fast! Handling TX
4999 * chars is pretty simple, stuff as many as possible from the TX buffer
5000 * into the sc26198 FIFO.
5001 * In practice it is possible that interrupts are enabled but that the
5002 * port has been hung up. Need to handle not having any TX buffer here,
5003 * this is done by using the side effect that head and tail will also
5004 * be NULL if the buffer has been freed.
5007 static void stl_sc26198txisr(stlport_t *portp)
5009 unsigned int ioaddr;
5010 unsigned char mr0;
5011 int len, stlen;
5012 char *head, *tail;
5014 #ifdef DEBUG
5015 printk("stl_sc26198txisr(portp=%x)\n", (int) portp);
5016 #endif
5018 ioaddr = portp->ioaddr;
5019 head = portp->tx.head;
5020 tail = portp->tx.tail;
5021 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
5022 if ((len == 0) || ((len < STL_TXBUFLOW) &&
5023 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
5024 set_bit(ASYI_TXLOW, &portp->istate);
5025 schedule_work(&portp->tqueue);
5028 if (len == 0) {
5029 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
5030 mr0 = inb(ioaddr + XP_DATA);
5031 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
5032 portp->imr &= ~IR_TXRDY;
5033 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
5034 outb(portp->imr, (ioaddr + XP_DATA));
5035 clear_bit(ASYI_TXBUSY, &portp->istate);
5036 } else {
5037 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
5038 outb(mr0, (ioaddr + XP_DATA));
5040 } else {
5041 len = MIN(len, SC26198_TXFIFOSIZE);
5042 portp->stats.txtotal += len;
5043 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
5044 outb(GTXFIFO, (ioaddr + XP_ADDR));
5045 outsb((ioaddr + XP_DATA), tail, stlen);
5046 len -= stlen;
5047 tail += stlen;
5048 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
5049 tail = portp->tx.buf;
5050 if (len > 0) {
5051 outsb((ioaddr + XP_DATA), tail, len);
5052 tail += len;
5054 portp->tx.tail = tail;
5058 /*****************************************************************************/
5061 * Receive character interrupt handler. Determine if we have good chars
5062 * or bad chars and then process appropriately. Good chars are easy
5063 * just shove the lot into the RX buffer and set all status byte to 0.
5064 * If a bad RX char then process as required. This routine needs to be
5065 * fast! In practice it is possible that we get an interrupt on a port
5066 * that is closed. This can happen on hangups - since they completely
5067 * shutdown a port not in user context. Need to handle this case.
5070 static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
5072 struct tty_struct *tty;
5073 unsigned int len, buflen, ioaddr;
5075 #ifdef DEBUG
5076 printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
5077 #endif
5079 tty = portp->tty;
5080 ioaddr = portp->ioaddr;
5081 outb(GIBCR, (ioaddr + XP_ADDR));
5082 len = inb(ioaddr + XP_DATA) + 1;
5084 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
5085 if ((tty == (struct tty_struct *) NULL) ||
5086 (tty->flip.char_buf_ptr == (char *) NULL) ||
5087 ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
5088 len = MIN(len, sizeof(stl_unwanted));
5089 outb(GRXFIFO, (ioaddr + XP_ADDR));
5090 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
5091 portp->stats.rxlost += len;
5092 portp->stats.rxtotal += len;
5093 } else {
5094 len = MIN(len, buflen);
5095 if (len > 0) {
5096 outb(GRXFIFO, (ioaddr + XP_ADDR));
5097 insb((ioaddr + XP_DATA), tty->flip.char_buf_ptr, len);
5098 memset(tty->flip.flag_buf_ptr, 0, len);
5099 tty->flip.flag_buf_ptr += len;
5100 tty->flip.char_buf_ptr += len;
5101 tty->flip.count += len;
5102 tty_schedule_flip(tty);
5103 portp->stats.rxtotal += len;
5106 } else {
5107 stl_sc26198rxbadchars(portp);
5111 * If we are TX flow controlled and in IXANY mode then we may need
5112 * to unflow control here. We gotta do this because of the automatic
5113 * flow control modes of the sc26198.
5115 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
5116 if ((tty != (struct tty_struct *) NULL) &&
5117 (tty->termios != (struct termios *) NULL) &&
5118 (tty->termios->c_iflag & IXANY)) {
5119 stl_sc26198txunflow(portp, tty);
5124 /*****************************************************************************/
5127 * Process an RX bad character.
5130 static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch)
5132 struct tty_struct *tty;
5133 unsigned int ioaddr;
5135 tty = portp->tty;
5136 ioaddr = portp->ioaddr;
5138 if (status & SR_RXPARITY)
5139 portp->stats.rxparity++;
5140 if (status & SR_RXFRAMING)
5141 portp->stats.rxframing++;
5142 if (status & SR_RXOVERRUN)
5143 portp->stats.rxoverrun++;
5144 if (status & SR_RXBREAK)
5145 portp->stats.rxbreaks++;
5147 if ((tty != (struct tty_struct *) NULL) &&
5148 ((portp->rxignoremsk & status) == 0)) {
5149 if (portp->rxmarkmsk & status) {
5150 if (status & SR_RXBREAK) {
5151 status = TTY_BREAK;
5152 if (portp->flags & ASYNC_SAK) {
5153 do_SAK(tty);
5154 BRDENABLE(portp->brdnr, portp->pagenr);
5156 } else if (status & SR_RXPARITY) {
5157 status = TTY_PARITY;
5158 } else if (status & SR_RXFRAMING) {
5159 status = TTY_FRAME;
5160 } else if(status & SR_RXOVERRUN) {
5161 status = TTY_OVERRUN;
5162 } else {
5163 status = 0;
5165 } else {
5166 status = 0;
5169 if (tty->flip.char_buf_ptr != (char *) NULL) {
5170 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
5171 *tty->flip.flag_buf_ptr++ = status;
5172 *tty->flip.char_buf_ptr++ = ch;
5173 tty->flip.count++;
5175 tty_schedule_flip(tty);
5178 if (status == 0)
5179 portp->stats.rxtotal++;
5183 /*****************************************************************************/
5186 * Process all characters in the RX FIFO of the UART. Check all char
5187 * status bytes as well, and process as required. We need to check
5188 * all bytes in the FIFO, in case some more enter the FIFO while we
5189 * are here. To get the exact character error type we need to switch
5190 * into CHAR error mode (that is why we need to make sure we empty
5191 * the FIFO).
5194 static void stl_sc26198rxbadchars(stlport_t *portp)
5196 unsigned char status, mr1;
5197 char ch;
5200 * To get the precise error type for each character we must switch
5201 * back into CHAR error mode.
5203 mr1 = stl_sc26198getreg(portp, MR1);
5204 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
5206 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
5207 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
5208 ch = stl_sc26198getreg(portp, RXFIFO);
5209 stl_sc26198rxbadch(portp, status, ch);
5213 * To get correct interrupt class we must switch back into BLOCK
5214 * error mode.
5216 stl_sc26198setreg(portp, MR1, mr1);
5219 /*****************************************************************************/
5222 * Other interrupt handler. This includes modem signals, flow
5223 * control actions, etc. Most stuff is left to off-level interrupt
5224 * processing time.
5227 static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
5229 unsigned char cir, ipr, xisr;
5231 #ifdef DEBUG
5232 printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
5233 #endif
5235 cir = stl_sc26198getglobreg(portp, CIR);
5237 switch (cir & CIR_SUBTYPEMASK) {
5238 case CIR_SUBCOS:
5239 ipr = stl_sc26198getreg(portp, IPR);
5240 if (ipr & IPR_DCDCHANGE) {
5241 set_bit(ASYI_DCDCHANGE, &portp->istate);
5242 schedule_work(&portp->tqueue);
5243 portp->stats.modem++;
5245 break;
5246 case CIR_SUBXONXOFF:
5247 xisr = stl_sc26198getreg(portp, XISR);
5248 if (xisr & XISR_RXXONGOT) {
5249 set_bit(ASYI_TXFLOWED, &portp->istate);
5250 portp->stats.txxoff++;
5252 if (xisr & XISR_RXXOFFGOT) {
5253 clear_bit(ASYI_TXFLOWED, &portp->istate);
5254 portp->stats.txxon++;
5256 break;
5257 case CIR_SUBBREAK:
5258 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
5259 stl_sc26198rxbadchars(portp);
5260 break;
5261 default:
5262 break;
5266 /*****************************************************************************/