Coarsly sort out 32-bit-only, 64-bit-only and ``portable'' MIPS lib/
[linux-2.6/linux-mips.git] / drivers / char / stallion.c
blobcc443e25168e69b00685278846f7156dc567cbc3
1 /*****************************************************************************/
3 /*
4 * stallion.c -- stallion multiport serial driver.
6 * Copyright (C) 1996-1999 Stallion Technologies (support@stallion.oz.au).
7 * Copyright (C) 1994-1996 Greg Ungerer.
9 * This code is loosely based on the Linux serial driver, written by
10 * Linus Torvalds, Theodore T'so and others.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /*****************************************************************************/
29 #include <linux/config.h>
30 #include <linux/module.h>
31 #include <linux/version.h> /* for linux/stallion.h */
32 #include <linux/slab.h>
33 #include <linux/interrupt.h>
34 #include <linux/tty.h>
35 #include <linux/tty_flip.h>
36 #include <linux/serial.h>
37 #include <linux/cd1400.h>
38 #include <linux/sc26198.h>
39 #include <linux/comstats.h>
40 #include <linux/stallion.h>
41 #include <linux/ioport.h>
42 #include <linux/init.h>
43 #include <linux/smp_lock.h>
44 #include <linux/devfs_fs_kernel.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 int init_module(void);
476 void cleanup_module(void);
477 static void stl_argbrds(void);
478 static int stl_parsebrd(stlconf_t *confp, char **argp);
480 static unsigned long stl_atol(char *str);
481 #endif
483 int stl_init(void);
484 static int stl_open(struct tty_struct *tty, struct file *filp);
485 static void stl_close(struct tty_struct *tty, struct file *filp);
486 static int stl_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count);
487 static void stl_putchar(struct tty_struct *tty, unsigned char ch);
488 static void stl_flushchars(struct tty_struct *tty);
489 static int stl_writeroom(struct tty_struct *tty);
490 static int stl_charsinbuffer(struct tty_struct *tty);
491 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
492 static void stl_settermios(struct tty_struct *tty, struct termios *old);
493 static void stl_throttle(struct tty_struct *tty);
494 static void stl_unthrottle(struct tty_struct *tty);
495 static void stl_stop(struct tty_struct *tty);
496 static void stl_start(struct tty_struct *tty);
497 static void stl_flushbuffer(struct tty_struct *tty);
498 static void stl_breakctl(struct tty_struct *tty, int state);
499 static void stl_waituntilsent(struct tty_struct *tty, int timeout);
500 static void stl_sendxchar(struct tty_struct *tty, char ch);
501 static void stl_hangup(struct tty_struct *tty);
502 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
503 static int stl_portinfo(stlport_t *portp, int portnr, char *pos);
504 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data);
506 static int stl_brdinit(stlbrd_t *brdp);
507 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
508 static int stl_mapirq(int irq, char *name);
509 static int stl_getserial(stlport_t *portp, struct serial_struct *sp);
510 static int stl_setserial(stlport_t *portp, struct serial_struct *sp);
511 static int stl_getbrdstats(combrd_t *bp);
512 static int stl_getportstats(stlport_t *portp, comstats_t *cp);
513 static int stl_clrportstats(stlport_t *portp, comstats_t *cp);
514 static int stl_getportstruct(unsigned long arg);
515 static int stl_getbrdstruct(unsigned long arg);
516 static int stl_waitcarrier(stlport_t *portp, struct file *filp);
517 static void stl_delay(int len);
518 static void stl_eiointr(stlbrd_t *brdp);
519 static void stl_echatintr(stlbrd_t *brdp);
520 static void stl_echmcaintr(stlbrd_t *brdp);
521 static void stl_echpciintr(stlbrd_t *brdp);
522 static void stl_echpci64intr(stlbrd_t *brdp);
523 static void stl_offintr(void *private);
524 static void *stl_memalloc(int len);
525 static stlbrd_t *stl_allocbrd(void);
526 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
528 static inline int stl_initbrds(void);
529 static inline int stl_initeio(stlbrd_t *brdp);
530 static inline int stl_initech(stlbrd_t *brdp);
531 static inline int stl_getbrdnr(void);
533 #ifdef CONFIG_PCI
534 static inline int stl_findpcibrds(void);
535 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp);
536 #endif
539 * CD1400 uart specific handling functions.
541 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value);
542 static int stl_cd1400getreg(stlport_t *portp, int regnr);
543 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value);
544 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
545 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
546 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp);
547 static int stl_cd1400getsignals(stlport_t *portp);
548 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts);
549 static void stl_cd1400ccrwait(stlport_t *portp);
550 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx);
551 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx);
552 static void stl_cd1400disableintrs(stlport_t *portp);
553 static void stl_cd1400sendbreak(stlport_t *portp, int len);
554 static void stl_cd1400flowctrl(stlport_t *portp, int state);
555 static void stl_cd1400sendflow(stlport_t *portp, int state);
556 static void stl_cd1400flush(stlport_t *portp);
557 static int stl_cd1400datastate(stlport_t *portp);
558 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase);
559 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase);
560 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr);
561 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr);
562 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr);
564 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr);
567 * SC26198 uart specific handling functions.
569 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value);
570 static int stl_sc26198getreg(stlport_t *portp, int regnr);
571 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value);
572 static int stl_sc26198getglobreg(stlport_t *portp, int regnr);
573 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
574 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
575 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp);
576 static int stl_sc26198getsignals(stlport_t *portp);
577 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts);
578 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx);
579 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx);
580 static void stl_sc26198disableintrs(stlport_t *portp);
581 static void stl_sc26198sendbreak(stlport_t *portp, int len);
582 static void stl_sc26198flowctrl(stlport_t *portp, int state);
583 static void stl_sc26198sendflow(stlport_t *portp, int state);
584 static void stl_sc26198flush(stlport_t *portp);
585 static int stl_sc26198datastate(stlport_t *portp);
586 static void stl_sc26198wait(stlport_t *portp);
587 static void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty);
588 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase);
589 static void stl_sc26198txisr(stlport_t *port);
590 static void stl_sc26198rxisr(stlport_t *port, unsigned int iack);
591 static void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch);
592 static void stl_sc26198rxbadchars(stlport_t *portp);
593 static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
595 /*****************************************************************************/
598 * Generic UART support structure.
600 typedef struct uart {
601 int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp);
602 void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
603 void (*setport)(stlport_t *portp, struct termios *tiosp);
604 int (*getsignals)(stlport_t *portp);
605 void (*setsignals)(stlport_t *portp, int dtr, int rts);
606 void (*enablerxtx)(stlport_t *portp, int rx, int tx);
607 void (*startrxtx)(stlport_t *portp, int rx, int tx);
608 void (*disableintrs)(stlport_t *portp);
609 void (*sendbreak)(stlport_t *portp, int len);
610 void (*flowctrl)(stlport_t *portp, int state);
611 void (*sendflow)(stlport_t *portp, int state);
612 void (*flush)(stlport_t *portp);
613 int (*datastate)(stlport_t *portp);
614 void (*intr)(stlpanel_t *panelp, unsigned int iobase);
615 } uart_t;
618 * Define some macros to make calling these functions nice and clean.
620 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
621 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
622 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
623 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
624 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
625 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
626 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
627 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
628 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
629 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
630 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
631 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
632 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
634 /*****************************************************************************/
637 * CD1400 UART specific data initialization.
639 static uart_t stl_cd1400uart = {
640 stl_cd1400panelinit,
641 stl_cd1400portinit,
642 stl_cd1400setport,
643 stl_cd1400getsignals,
644 stl_cd1400setsignals,
645 stl_cd1400enablerxtx,
646 stl_cd1400startrxtx,
647 stl_cd1400disableintrs,
648 stl_cd1400sendbreak,
649 stl_cd1400flowctrl,
650 stl_cd1400sendflow,
651 stl_cd1400flush,
652 stl_cd1400datastate,
653 stl_cd1400eiointr
657 * Define the offsets within the register bank of a cd1400 based panel.
658 * These io address offsets are common to the EasyIO board as well.
660 #define EREG_ADDR 0
661 #define EREG_DATA 4
662 #define EREG_RXACK 5
663 #define EREG_TXACK 6
664 #define EREG_MDACK 7
666 #define EREG_BANKSIZE 8
668 #define CD1400_CLK 25000000
669 #define CD1400_CLK8M 20000000
672 * Define the cd1400 baud rate clocks. These are used when calculating
673 * what clock and divisor to use for the required baud rate. Also
674 * define the maximum baud rate allowed, and the default base baud.
676 static int stl_cd1400clkdivs[] = {
677 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
680 /*****************************************************************************/
683 * SC26198 UART specific data initization.
685 static uart_t stl_sc26198uart = {
686 stl_sc26198panelinit,
687 stl_sc26198portinit,
688 stl_sc26198setport,
689 stl_sc26198getsignals,
690 stl_sc26198setsignals,
691 stl_sc26198enablerxtx,
692 stl_sc26198startrxtx,
693 stl_sc26198disableintrs,
694 stl_sc26198sendbreak,
695 stl_sc26198flowctrl,
696 stl_sc26198sendflow,
697 stl_sc26198flush,
698 stl_sc26198datastate,
699 stl_sc26198intr
703 * Define the offsets within the register bank of a sc26198 based panel.
705 #define XP_DATA 0
706 #define XP_ADDR 1
707 #define XP_MODID 2
708 #define XP_STATUS 2
709 #define XP_IACK 3
711 #define XP_BANKSIZE 4
714 * Define the sc26198 baud rate table. Offsets within the table
715 * represent the actual baud rate selector of sc26198 registers.
717 static unsigned int sc26198_baudtable[] = {
718 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
719 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
720 230400, 460800, 921600
723 #define SC26198_NRBAUDS (sizeof(sc26198_baudtable) / sizeof(unsigned int))
725 /*****************************************************************************/
728 * Define the driver info for a user level control device. Used mainly
729 * to get at port stats - only not using the port device itself.
731 static struct file_operations stl_fsiomem = {
732 .owner = THIS_MODULE,
733 .ioctl = stl_memioctl,
736 /*****************************************************************************/
738 #ifdef MODULE
741 * Loadable module initialization stuff.
744 static int __init stallion_module_init(void)
746 unsigned long flags;
748 #if 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 #if 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 devfs_remove("staliomem");
797 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
798 printk("STALLION: failed to un-register serial memory device, "
799 "errno=%d\n", -i);
801 if (stl_tmpwritebuf != (char *) NULL)
802 kfree(stl_tmpwritebuf);
804 for (i = 0; (i < stl_nrbrds); i++) {
805 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
806 continue;
807 for (j = 0; (j < STL_MAXPANELS); j++) {
808 panelp = brdp->panels[j];
809 if (panelp == (stlpanel_t *) NULL)
810 continue;
811 for (k = 0; (k < STL_PORTSPERPANEL); k++) {
812 portp = panelp->ports[k];
813 if (portp == (stlport_t *) NULL)
814 continue;
815 if (portp->tty != (struct tty_struct *) NULL)
816 stl_hangup(portp->tty);
817 if (portp->tx.buf != (char *) NULL)
818 kfree(portp->tx.buf);
819 kfree(portp);
821 kfree(panelp);
824 release_region(brdp->ioaddr1, brdp->iosize1);
825 if (brdp->iosize2 > 0)
826 release_region(brdp->ioaddr2, brdp->iosize2);
828 kfree(brdp);
829 stl_brds[i] = (stlbrd_t *) NULL;
832 for (i = 0; (i < stl_numintrs); i++)
833 free_irq(stl_gotintrs[i], NULL);
835 restore_flags(flags);
838 module_init(stallion_module_init);
839 module_exit(stallion_module_exit);
841 /*****************************************************************************/
844 * Check for any arguments passed in on the module load command line.
847 static void stl_argbrds()
849 stlconf_t conf;
850 stlbrd_t *brdp;
851 int nrargs, i;
853 #if DEBUG
854 printk("stl_argbrds()\n");
855 #endif
857 nrargs = sizeof(stl_brdsp) / sizeof(char **);
859 for (i = stl_nrbrds; (i < nrargs); i++) {
860 memset(&conf, 0, sizeof(conf));
861 if (stl_parsebrd(&conf, stl_brdsp[i]) == 0)
862 continue;
863 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
864 continue;
865 stl_nrbrds = i + 1;
866 brdp->brdnr = i;
867 brdp->brdtype = conf.brdtype;
868 brdp->ioaddr1 = conf.ioaddr1;
869 brdp->ioaddr2 = conf.ioaddr2;
870 brdp->irq = conf.irq;
871 brdp->irqtype = conf.irqtype;
872 stl_brdinit(brdp);
876 /*****************************************************************************/
879 * Convert an ascii string number into an unsigned long.
882 static unsigned long stl_atol(char *str)
884 unsigned long val;
885 int base, c;
886 char *sp;
888 val = 0;
889 sp = str;
890 if ((*sp == '0') && (*(sp+1) == 'x')) {
891 base = 16;
892 sp += 2;
893 } else if (*sp == '0') {
894 base = 8;
895 sp++;
896 } else {
897 base = 10;
900 for (; (*sp != 0); sp++) {
901 c = (*sp > '9') ? (TOLOWER(*sp) - 'a' + 10) : (*sp - '0');
902 if ((c < 0) || (c >= base)) {
903 printk("STALLION: invalid argument %s\n", str);
904 val = 0;
905 break;
907 val = (val * base) + c;
909 return(val);
912 /*****************************************************************************/
915 * Parse the supplied argument string, into the board conf struct.
918 static int stl_parsebrd(stlconf_t *confp, char **argp)
920 char *sp;
921 int nrbrdnames, i;
923 #if DEBUG
924 printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp, (int) argp);
925 #endif
927 if ((argp[0] == (char *) NULL) || (*argp[0] == 0))
928 return(0);
930 for (sp = argp[0], i = 0; ((*sp != 0) && (i < 25)); sp++, i++)
931 *sp = TOLOWER(*sp);
933 nrbrdnames = sizeof(stl_brdstr) / sizeof(stlbrdtype_t);
934 for (i = 0; (i < nrbrdnames); i++) {
935 if (strcmp(stl_brdstr[i].name, argp[0]) == 0)
936 break;
938 if (i >= nrbrdnames) {
939 printk("STALLION: unknown board name, %s?\n", argp[0]);
940 return(0);
943 confp->brdtype = stl_brdstr[i].type;
945 i = 1;
946 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
947 confp->ioaddr1 = stl_atol(argp[i]);
948 i++;
949 if (confp->brdtype == BRD_ECH) {
950 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
951 confp->ioaddr2 = stl_atol(argp[i]);
952 i++;
954 if ((argp[i] != (char *) NULL) && (*argp[i] != 0))
955 confp->irq = stl_atol(argp[i]);
956 return(1);
959 #endif
961 /*****************************************************************************/
964 * Local driver kernel memory allocation routine.
967 static void *stl_memalloc(int len)
969 return((void *) kmalloc(len, GFP_KERNEL));
972 /*****************************************************************************/
975 * Allocate a new board structure. Fill out the basic info in it.
978 static stlbrd_t *stl_allocbrd()
980 stlbrd_t *brdp;
982 brdp = (stlbrd_t *) stl_memalloc(sizeof(stlbrd_t));
983 if (brdp == (stlbrd_t *) NULL) {
984 printk("STALLION: failed to allocate memory (size=%d)\n",
985 sizeof(stlbrd_t));
986 return((stlbrd_t *) NULL);
989 memset(brdp, 0, sizeof(stlbrd_t));
990 brdp->magic = STL_BOARDMAGIC;
991 return(brdp);
994 /*****************************************************************************/
996 static int stl_open(struct tty_struct *tty, struct file *filp)
998 stlport_t *portp;
999 stlbrd_t *brdp;
1000 unsigned int minordev;
1001 int brdnr, panelnr, portnr, rc;
1003 #if DEBUG
1004 printk("stl_open(tty=%x,filp=%x): device=%s\n", (int) tty,
1005 (int) filp, tty->name);
1006 #endif
1008 minordev = tty->index;
1009 brdnr = MINOR2BRD(minordev);
1010 if (brdnr >= stl_nrbrds)
1011 return(-ENODEV);
1012 brdp = stl_brds[brdnr];
1013 if (brdp == (stlbrd_t *) NULL)
1014 return(-ENODEV);
1015 minordev = MINOR2PORT(minordev);
1016 for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
1017 if (brdp->panels[panelnr] == (stlpanel_t *) NULL)
1018 break;
1019 if (minordev < brdp->panels[panelnr]->nrports) {
1020 portnr = minordev;
1021 break;
1023 minordev -= brdp->panels[panelnr]->nrports;
1025 if (portnr < 0)
1026 return(-ENODEV);
1028 portp = brdp->panels[panelnr]->ports[portnr];
1029 if (portp == (stlport_t *) NULL)
1030 return(-ENODEV);
1033 * On the first open of the device setup the port hardware, and
1034 * initialize the per port data structure.
1036 portp->tty = tty;
1037 tty->driver_data = portp;
1038 portp->refcount++;
1040 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
1041 if (portp->tx.buf == (char *) NULL) {
1042 portp->tx.buf = (char *) stl_memalloc(STL_TXBUFSIZE);
1043 if (portp->tx.buf == (char *) NULL)
1044 return(-ENOMEM);
1045 portp->tx.head = portp->tx.buf;
1046 portp->tx.tail = portp->tx.buf;
1048 stl_setport(portp, tty->termios);
1049 portp->sigs = stl_getsignals(portp);
1050 stl_setsignals(portp, 1, 1);
1051 stl_enablerxtx(portp, 1, 1);
1052 stl_startrxtx(portp, 1, 0);
1053 clear_bit(TTY_IO_ERROR, &tty->flags);
1054 portp->flags |= ASYNC_INITIALIZED;
1058 * Check if this port is in the middle of closing. If so then wait
1059 * until it is closed then return error status, based on flag settings.
1060 * The sleep here does not need interrupt protection since the wakeup
1061 * for it is done with the same context.
1063 if (portp->flags & ASYNC_CLOSING) {
1064 interruptible_sleep_on(&portp->close_wait);
1065 if (portp->flags & ASYNC_HUP_NOTIFY)
1066 return(-EAGAIN);
1067 return(-ERESTARTSYS);
1071 * Based on type of open being done check if it can overlap with any
1072 * previous opens still in effect. If we are a normal serial device
1073 * then also we might have to wait for carrier.
1075 if (!(filp->f_flags & O_NONBLOCK)) {
1076 if ((rc = stl_waitcarrier(portp, filp)) != 0)
1077 return(rc);
1079 portp->flags |= ASYNC_NORMAL_ACTIVE;
1081 return(0);
1084 /*****************************************************************************/
1087 * Possibly need to wait for carrier (DCD signal) to come high. Say
1088 * maybe because if we are clocal then we don't need to wait...
1091 static int stl_waitcarrier(stlport_t *portp, struct file *filp)
1093 unsigned long flags;
1094 int rc, doclocal;
1096 #if DEBUG
1097 printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp, (int) filp);
1098 #endif
1100 rc = 0;
1101 doclocal = 0;
1103 if (portp->tty->termios->c_cflag & CLOCAL)
1104 doclocal++;
1106 save_flags(flags);
1107 cli();
1108 portp->openwaitcnt++;
1109 if (! tty_hung_up_p(filp))
1110 portp->refcount--;
1112 for (;;) {
1113 stl_setsignals(portp, 1, 1);
1114 if (tty_hung_up_p(filp) ||
1115 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
1116 if (portp->flags & ASYNC_HUP_NOTIFY)
1117 rc = -EBUSY;
1118 else
1119 rc = -ERESTARTSYS;
1120 break;
1122 if (((portp->flags & ASYNC_CLOSING) == 0) &&
1123 (doclocal || (portp->sigs & TIOCM_CD))) {
1124 break;
1126 if (signal_pending(current)) {
1127 rc = -ERESTARTSYS;
1128 break;
1130 interruptible_sleep_on(&portp->open_wait);
1133 if (! tty_hung_up_p(filp))
1134 portp->refcount++;
1135 portp->openwaitcnt--;
1136 restore_flags(flags);
1138 return(rc);
1141 /*****************************************************************************/
1143 static void stl_close(struct tty_struct *tty, struct file *filp)
1145 stlport_t *portp;
1146 unsigned long flags;
1148 #if DEBUG
1149 printk("stl_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
1150 #endif
1152 portp = tty->driver_data;
1153 if (portp == (stlport_t *) NULL)
1154 return;
1156 save_flags(flags);
1157 cli();
1158 if (tty_hung_up_p(filp)) {
1159 restore_flags(flags);
1160 return;
1162 if ((tty->count == 1) && (portp->refcount != 1))
1163 portp->refcount = 1;
1164 if (portp->refcount-- > 1) {
1165 restore_flags(flags);
1166 return;
1169 portp->refcount = 0;
1170 portp->flags |= ASYNC_CLOSING;
1173 * May want to wait for any data to drain before closing. The BUSY
1174 * flag keeps track of whether we are still sending or not - it is
1175 * very accurate for the cd1400, not quite so for the sc26198.
1176 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1178 tty->closing = 1;
1179 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1180 tty_wait_until_sent(tty, portp->closing_wait);
1181 stl_waituntilsent(tty, (HZ / 2));
1183 portp->flags &= ~ASYNC_INITIALIZED;
1184 stl_disableintrs(portp);
1185 if (tty->termios->c_cflag & HUPCL)
1186 stl_setsignals(portp, 0, 0);
1187 stl_enablerxtx(portp, 0, 0);
1188 stl_flushbuffer(tty);
1189 portp->istate = 0;
1190 if (portp->tx.buf != (char *) NULL) {
1191 kfree(portp->tx.buf);
1192 portp->tx.buf = (char *) NULL;
1193 portp->tx.head = (char *) NULL;
1194 portp->tx.tail = (char *) NULL;
1196 set_bit(TTY_IO_ERROR, &tty->flags);
1197 if (tty->ldisc.flush_buffer)
1198 (tty->ldisc.flush_buffer)(tty);
1200 tty->closing = 0;
1201 portp->tty = (struct tty_struct *) NULL;
1203 if (portp->openwaitcnt) {
1204 if (portp->close_delay)
1205 stl_delay(portp->close_delay);
1206 wake_up_interruptible(&portp->open_wait);
1209 portp->flags &= ~(ASYNC_NORMAL_ACTIVE|ASYNC_CLOSING);
1210 wake_up_interruptible(&portp->close_wait);
1211 restore_flags(flags);
1214 /*****************************************************************************/
1217 * Wait for a specified delay period, this is not a busy-loop. It will
1218 * give up the processor while waiting. Unfortunately this has some
1219 * rather intimate knowledge of the process management stuff.
1222 static void stl_delay(int len)
1224 #if DEBUG
1225 printk("stl_delay(len=%d)\n", len);
1226 #endif
1227 if (len > 0) {
1228 current->state = TASK_INTERRUPTIBLE;
1229 schedule_timeout(len);
1230 current->state = TASK_RUNNING;
1234 /*****************************************************************************/
1237 * Write routine. Take data and stuff it in to the TX ring queue.
1238 * If transmit interrupts are not running then start them.
1241 static int stl_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count)
1243 stlport_t *portp;
1244 unsigned int len, stlen;
1245 unsigned char *chbuf;
1246 char *head, *tail;
1248 #if DEBUG
1249 printk("stl_write(tty=%x,from_user=%d,buf=%x,count=%d)\n",
1250 (int) tty, from_user, (int) buf, count);
1251 #endif
1253 if ((tty == (struct tty_struct *) NULL) ||
1254 (stl_tmpwritebuf == (char *) NULL))
1255 return(0);
1256 portp = tty->driver_data;
1257 if (portp == (stlport_t *) NULL)
1258 return(0);
1259 if (portp->tx.buf == (char *) NULL)
1260 return(0);
1263 * If copying direct from user space we must cater for page faults,
1264 * causing us to "sleep" here for a while. To handle this copy in all
1265 * the data we need now, into a local buffer. Then when we got it all
1266 * copy it into the TX buffer.
1268 chbuf = (unsigned char *) buf;
1269 if (from_user) {
1270 head = portp->tx.head;
1271 tail = portp->tx.tail;
1272 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) :
1273 (tail - head - 1);
1274 count = MIN(len, count);
1276 down(&stl_tmpwritesem);
1277 if (copy_from_user(stl_tmpwritebuf, chbuf, count))
1278 return -EFAULT;
1279 chbuf = &stl_tmpwritebuf[0];
1282 head = portp->tx.head;
1283 tail = portp->tx.tail;
1284 if (head >= tail) {
1285 len = STL_TXBUFSIZE - (head - tail) - 1;
1286 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
1287 } else {
1288 len = tail - head - 1;
1289 stlen = len;
1292 len = MIN(len, count);
1293 count = 0;
1294 while (len > 0) {
1295 stlen = MIN(len, stlen);
1296 memcpy(head, chbuf, stlen);
1297 len -= stlen;
1298 chbuf += stlen;
1299 count += stlen;
1300 head += stlen;
1301 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
1302 head = portp->tx.buf;
1303 stlen = tail - head;
1306 portp->tx.head = head;
1308 clear_bit(ASYI_TXLOW, &portp->istate);
1309 stl_startrxtx(portp, -1, 1);
1311 if (from_user)
1312 up(&stl_tmpwritesem);
1314 return(count);
1317 /*****************************************************************************/
1319 static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1321 stlport_t *portp;
1322 unsigned int len;
1323 char *head, *tail;
1325 #if DEBUG
1326 printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1327 #endif
1329 if (tty == (struct tty_struct *) NULL)
1330 return;
1331 portp = tty->driver_data;
1332 if (portp == (stlport_t *) NULL)
1333 return;
1334 if (portp->tx.buf == (char *) NULL)
1335 return;
1337 head = portp->tx.head;
1338 tail = portp->tx.tail;
1340 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
1341 len--;
1343 if (len > 0) {
1344 *head++ = ch;
1345 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
1346 head = portp->tx.buf;
1348 portp->tx.head = head;
1351 /*****************************************************************************/
1354 * If there are any characters in the buffer then make sure that TX
1355 * interrupts are on and get'em out. Normally used after the putchar
1356 * routine has been called.
1359 static void stl_flushchars(struct tty_struct *tty)
1361 stlport_t *portp;
1363 #if DEBUG
1364 printk("stl_flushchars(tty=%x)\n", (int) tty);
1365 #endif
1367 if (tty == (struct tty_struct *) NULL)
1368 return;
1369 portp = tty->driver_data;
1370 if (portp == (stlport_t *) NULL)
1371 return;
1372 if (portp->tx.buf == (char *) NULL)
1373 return;
1375 #if 0
1376 if (tty->stopped || tty->hw_stopped ||
1377 (portp->tx.head == portp->tx.tail))
1378 return;
1379 #endif
1380 stl_startrxtx(portp, -1, 1);
1383 /*****************************************************************************/
1385 static int stl_writeroom(struct tty_struct *tty)
1387 stlport_t *portp;
1388 char *head, *tail;
1390 #if DEBUG
1391 printk("stl_writeroom(tty=%x)\n", (int) tty);
1392 #endif
1394 if (tty == (struct tty_struct *) NULL)
1395 return(0);
1396 portp = tty->driver_data;
1397 if (portp == (stlport_t *) NULL)
1398 return(0);
1399 if (portp->tx.buf == (char *) NULL)
1400 return(0);
1402 head = portp->tx.head;
1403 tail = portp->tx.tail;
1404 return((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
1407 /*****************************************************************************/
1410 * Return number of chars in the TX buffer. Normally we would just
1411 * calculate the number of chars in the buffer and return that, but if
1412 * the buffer is empty and TX interrupts are still on then we return
1413 * that the buffer still has 1 char in it. This way whoever called us
1414 * will not think that ALL chars have drained - since the UART still
1415 * must have some chars in it (we are busy after all).
1418 static int stl_charsinbuffer(struct tty_struct *tty)
1420 stlport_t *portp;
1421 unsigned int size;
1422 char *head, *tail;
1424 #if DEBUG
1425 printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
1426 #endif
1428 if (tty == (struct tty_struct *) NULL)
1429 return(0);
1430 portp = tty->driver_data;
1431 if (portp == (stlport_t *) NULL)
1432 return(0);
1433 if (portp->tx.buf == (char *) NULL)
1434 return(0);
1436 head = portp->tx.head;
1437 tail = portp->tx.tail;
1438 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1439 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1440 size = 1;
1441 return(size);
1444 /*****************************************************************************/
1447 * Generate the serial struct info.
1450 static int stl_getserial(stlport_t *portp, struct serial_struct *sp)
1452 struct serial_struct sio;
1453 stlbrd_t *brdp;
1455 #if DEBUG
1456 printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1457 #endif
1459 memset(&sio, 0, sizeof(struct serial_struct));
1460 sio.line = portp->portnr;
1461 sio.port = portp->ioaddr;
1462 sio.flags = portp->flags;
1463 sio.baud_base = portp->baud_base;
1464 sio.close_delay = portp->close_delay;
1465 sio.closing_wait = portp->closing_wait;
1466 sio.custom_divisor = portp->custom_divisor;
1467 sio.hub6 = 0;
1468 if (portp->uartp == &stl_cd1400uart) {
1469 sio.type = PORT_CIRRUS;
1470 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1471 } else {
1472 sio.type = PORT_UNKNOWN;
1473 sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1476 brdp = stl_brds[portp->brdnr];
1477 if (brdp != (stlbrd_t *) NULL)
1478 sio.irq = brdp->irq;
1480 return copy_to_user(sp, &sio, sizeof(struct serial_struct)) ? -EFAULT : 0;
1483 /*****************************************************************************/
1486 * Set port according to the serial struct info.
1487 * At this point we do not do any auto-configure stuff, so we will
1488 * just quietly ignore any requests to change irq, etc.
1491 static int stl_setserial(stlport_t *portp, struct serial_struct *sp)
1493 struct serial_struct sio;
1495 #if DEBUG
1496 printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1497 #endif
1499 if (copy_from_user(&sio, sp, sizeof(struct serial_struct)))
1500 return -EFAULT;
1501 if (!capable(CAP_SYS_ADMIN)) {
1502 if ((sio.baud_base != portp->baud_base) ||
1503 (sio.close_delay != portp->close_delay) ||
1504 ((sio.flags & ~ASYNC_USR_MASK) !=
1505 (portp->flags & ~ASYNC_USR_MASK)))
1506 return(-EPERM);
1509 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1510 (sio.flags & ASYNC_USR_MASK);
1511 portp->baud_base = sio.baud_base;
1512 portp->close_delay = sio.close_delay;
1513 portp->closing_wait = sio.closing_wait;
1514 portp->custom_divisor = sio.custom_divisor;
1515 stl_setport(portp, portp->tty->termios);
1516 return(0);
1519 /*****************************************************************************/
1521 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1523 stlport_t *portp;
1524 unsigned int ival;
1525 int rc;
1527 #if DEBUG
1528 printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
1529 (int) tty, (int) file, cmd, (int) arg);
1530 #endif
1532 if (tty == (struct tty_struct *) NULL)
1533 return(-ENODEV);
1534 portp = tty->driver_data;
1535 if (portp == (stlport_t *) NULL)
1536 return(-ENODEV);
1538 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1539 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1540 if (tty->flags & (1 << TTY_IO_ERROR))
1541 return(-EIO);
1544 rc = 0;
1546 switch (cmd) {
1547 case TIOCGSOFTCAR:
1548 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1549 (unsigned int *) arg);
1550 break;
1551 case TIOCSSOFTCAR:
1552 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1553 sizeof(int))) == 0) {
1554 get_user(ival, (unsigned int *) arg);
1555 tty->termios->c_cflag =
1556 (tty->termios->c_cflag & ~CLOCAL) |
1557 (ival ? CLOCAL : 0);
1559 break;
1560 case TIOCMGET:
1561 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1562 sizeof(unsigned int))) == 0) {
1563 ival = stl_getsignals(portp);
1564 put_user(ival, (unsigned int *) arg);
1566 break;
1567 case TIOCMBIS:
1568 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1569 sizeof(unsigned int))) == 0) {
1570 get_user(ival, (unsigned int *) arg);
1571 stl_setsignals(portp, ((ival & TIOCM_DTR) ? 1 : -1),
1572 ((ival & TIOCM_RTS) ? 1 : -1));
1574 break;
1575 case TIOCMBIC:
1576 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1577 sizeof(unsigned int))) == 0) {
1578 get_user(ival, (unsigned int *) arg);
1579 stl_setsignals(portp, ((ival & TIOCM_DTR) ? 0 : -1),
1580 ((ival & TIOCM_RTS) ? 0 : -1));
1582 break;
1583 case TIOCMSET:
1584 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1585 sizeof(unsigned int))) == 0) {
1586 get_user(ival, (unsigned int *) arg);
1587 stl_setsignals(portp, ((ival & TIOCM_DTR) ? 1 : 0),
1588 ((ival & TIOCM_RTS) ? 1 : 0));
1590 break;
1591 case TIOCGSERIAL:
1592 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1593 sizeof(struct serial_struct))) == 0)
1594 rc = stl_getserial(portp, (struct serial_struct *) arg);
1595 break;
1596 case TIOCSSERIAL:
1597 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1598 sizeof(struct serial_struct))) == 0)
1599 rc = stl_setserial(portp, (struct serial_struct *) arg);
1600 break;
1601 case COM_GETPORTSTATS:
1602 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1603 sizeof(comstats_t))) == 0)
1604 rc = stl_getportstats(portp, (comstats_t *) arg);
1605 break;
1606 case COM_CLRPORTSTATS:
1607 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1608 sizeof(comstats_t))) == 0)
1609 rc = stl_clrportstats(portp, (comstats_t *) arg);
1610 break;
1611 case TIOCSERCONFIG:
1612 case TIOCSERGWILD:
1613 case TIOCSERSWILD:
1614 case TIOCSERGETLSR:
1615 case TIOCSERGSTRUCT:
1616 case TIOCSERGETMULTI:
1617 case TIOCSERSETMULTI:
1618 default:
1619 rc = -ENOIOCTLCMD;
1620 break;
1623 return(rc);
1626 /*****************************************************************************/
1628 static void stl_settermios(struct tty_struct *tty, struct termios *old)
1630 stlport_t *portp;
1631 struct termios *tiosp;
1633 #if DEBUG
1634 printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
1635 #endif
1637 if (tty == (struct tty_struct *) NULL)
1638 return;
1639 portp = tty->driver_data;
1640 if (portp == (stlport_t *) NULL)
1641 return;
1643 tiosp = tty->termios;
1644 if ((tiosp->c_cflag == old->c_cflag) &&
1645 (tiosp->c_iflag == old->c_iflag))
1646 return;
1648 stl_setport(portp, tiosp);
1649 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1650 -1);
1651 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1652 tty->hw_stopped = 0;
1653 stl_start(tty);
1655 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1656 wake_up_interruptible(&portp->open_wait);
1659 /*****************************************************************************/
1662 * Attempt to flow control who ever is sending us data. Based on termios
1663 * settings use software or/and hardware flow control.
1666 static void stl_throttle(struct tty_struct *tty)
1668 stlport_t *portp;
1670 #if DEBUG
1671 printk("stl_throttle(tty=%x)\n", (int) tty);
1672 #endif
1674 if (tty == (struct tty_struct *) NULL)
1675 return;
1676 portp = tty->driver_data;
1677 if (portp == (stlport_t *) NULL)
1678 return;
1679 stl_flowctrl(portp, 0);
1682 /*****************************************************************************/
1685 * Unflow control the device sending us data...
1688 static void stl_unthrottle(struct tty_struct *tty)
1690 stlport_t *portp;
1692 #if DEBUG
1693 printk("stl_unthrottle(tty=%x)\n", (int) tty);
1694 #endif
1696 if (tty == (struct tty_struct *) NULL)
1697 return;
1698 portp = tty->driver_data;
1699 if (portp == (stlport_t *) NULL)
1700 return;
1701 stl_flowctrl(portp, 1);
1704 /*****************************************************************************/
1707 * Stop the transmitter. Basically to do this we will just turn TX
1708 * interrupts off.
1711 static void stl_stop(struct tty_struct *tty)
1713 stlport_t *portp;
1715 #if DEBUG
1716 printk("stl_stop(tty=%x)\n", (int) tty);
1717 #endif
1719 if (tty == (struct tty_struct *) NULL)
1720 return;
1721 portp = tty->driver_data;
1722 if (portp == (stlport_t *) NULL)
1723 return;
1724 stl_startrxtx(portp, -1, 0);
1727 /*****************************************************************************/
1730 * Start the transmitter again. Just turn TX interrupts back on.
1733 static void stl_start(struct tty_struct *tty)
1735 stlport_t *portp;
1737 #if DEBUG
1738 printk("stl_start(tty=%x)\n", (int) tty);
1739 #endif
1741 if (tty == (struct tty_struct *) NULL)
1742 return;
1743 portp = tty->driver_data;
1744 if (portp == (stlport_t *) NULL)
1745 return;
1746 stl_startrxtx(portp, -1, 1);
1749 /*****************************************************************************/
1752 * Hangup this port. This is pretty much like closing the port, only
1753 * a little more brutal. No waiting for data to drain. Shutdown the
1754 * port and maybe drop signals.
1757 static void stl_hangup(struct tty_struct *tty)
1759 stlport_t *portp;
1761 #if DEBUG
1762 printk("stl_hangup(tty=%x)\n", (int) tty);
1763 #endif
1765 if (tty == (struct tty_struct *) NULL)
1766 return;
1767 portp = tty->driver_data;
1768 if (portp == (stlport_t *) NULL)
1769 return;
1771 portp->flags &= ~ASYNC_INITIALIZED;
1772 stl_disableintrs(portp);
1773 if (tty->termios->c_cflag & HUPCL)
1774 stl_setsignals(portp, 0, 0);
1775 stl_enablerxtx(portp, 0, 0);
1776 stl_flushbuffer(tty);
1777 portp->istate = 0;
1778 set_bit(TTY_IO_ERROR, &tty->flags);
1779 if (portp->tx.buf != (char *) NULL) {
1780 kfree(portp->tx.buf);
1781 portp->tx.buf = (char *) NULL;
1782 portp->tx.head = (char *) NULL;
1783 portp->tx.tail = (char *) NULL;
1785 portp->tty = (struct tty_struct *) NULL;
1786 portp->flags &= ~ASYNC_NORMAL_ACTIVE;
1787 portp->refcount = 0;
1788 wake_up_interruptible(&portp->open_wait);
1791 /*****************************************************************************/
1793 static void stl_flushbuffer(struct tty_struct *tty)
1795 stlport_t *portp;
1797 #if DEBUG
1798 printk("stl_flushbuffer(tty=%x)\n", (int) tty);
1799 #endif
1801 if (tty == (struct tty_struct *) NULL)
1802 return;
1803 portp = tty->driver_data;
1804 if (portp == (stlport_t *) NULL)
1805 return;
1807 stl_flush(portp);
1808 wake_up_interruptible(&tty->write_wait);
1809 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1810 tty->ldisc.write_wakeup)
1811 (tty->ldisc.write_wakeup)(tty);
1814 /*****************************************************************************/
1816 static void stl_breakctl(struct tty_struct *tty, int state)
1818 stlport_t *portp;
1820 #if 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 #if 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 #if 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 #if 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 #if 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 #if 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 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2193 tty->ldisc.write_wakeup)
2194 (tty->ldisc.write_wakeup)(tty);
2195 wake_up_interruptible(&tty->write_wait);
2197 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
2198 clear_bit(ASYI_DCDCHANGE, &portp->istate);
2199 oldsigs = portp->sigs;
2200 portp->sigs = stl_getsignals(portp);
2201 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
2202 wake_up_interruptible(&portp->open_wait);
2203 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
2204 if (portp->flags & ASYNC_CHECK_CD)
2205 tty_hangup(tty); /* FIXME: module removal race here - AKPM */
2208 unlock_kernel();
2211 /*****************************************************************************/
2214 * Map in interrupt vector to this driver. Check that we don't
2215 * already have this vector mapped, we might be sharing this
2216 * interrupt across multiple boards.
2219 static int __init stl_mapirq(int irq, char *name)
2221 int rc, i;
2223 #if DEBUG
2224 printk("stl_mapirq(irq=%d,name=%s)\n", irq, name);
2225 #endif
2227 rc = 0;
2228 for (i = 0; (i < stl_numintrs); i++) {
2229 if (stl_gotintrs[i] == irq)
2230 break;
2232 if (i >= stl_numintrs) {
2233 if (request_irq(irq, stl_intr, SA_SHIRQ, name, NULL) != 0) {
2234 printk("STALLION: failed to register interrupt "
2235 "routine for %s irq=%d\n", name, irq);
2236 rc = -ENODEV;
2237 } else {
2238 stl_gotintrs[stl_numintrs++] = irq;
2241 return(rc);
2244 /*****************************************************************************/
2247 * Initialize all the ports on a panel.
2250 static int __init stl_initports(stlbrd_t *brdp, stlpanel_t *panelp)
2252 stlport_t *portp;
2253 int chipmask, i;
2255 #if DEBUG
2256 printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
2257 #endif
2259 chipmask = stl_panelinit(brdp, panelp);
2262 * All UART's are initialized (if found!). Now go through and setup
2263 * each ports data structures.
2265 for (i = 0; (i < panelp->nrports); i++) {
2266 portp = (stlport_t *) stl_memalloc(sizeof(stlport_t));
2267 if (portp == (stlport_t *) NULL) {
2268 printk("STALLION: failed to allocate memory "
2269 "(size=%d)\n", sizeof(stlport_t));
2270 break;
2272 memset(portp, 0, sizeof(stlport_t));
2274 portp->magic = STL_PORTMAGIC;
2275 portp->portnr = i;
2276 portp->brdnr = panelp->brdnr;
2277 portp->panelnr = panelp->panelnr;
2278 portp->uartp = panelp->uartp;
2279 portp->clk = brdp->clk;
2280 portp->baud_base = STL_BAUDBASE;
2281 portp->close_delay = STL_CLOSEDELAY;
2282 portp->closing_wait = 30 * HZ;
2283 INIT_WORK(&portp->tqueue, stl_offintr, portp);
2284 init_waitqueue_head(&portp->open_wait);
2285 init_waitqueue_head(&portp->close_wait);
2286 portp->stats.brd = portp->brdnr;
2287 portp->stats.panel = portp->panelnr;
2288 portp->stats.port = portp->portnr;
2289 panelp->ports[i] = portp;
2290 stl_portinit(brdp, panelp, portp);
2293 return(0);
2296 /*****************************************************************************/
2299 * Try to find and initialize an EasyIO board.
2302 static inline int stl_initeio(stlbrd_t *brdp)
2304 stlpanel_t *panelp;
2305 unsigned int status;
2306 char *name;
2307 int rc;
2309 #if DEBUG
2310 printk("stl_initeio(brdp=%x)\n", (int) brdp);
2311 #endif
2313 brdp->ioctrl = brdp->ioaddr1 + 1;
2314 brdp->iostatus = brdp->ioaddr1 + 2;
2316 status = inb(brdp->iostatus);
2317 if ((status & EIO_IDBITMASK) == EIO_MK3)
2318 brdp->ioctrl++;
2321 * Handle board specific stuff now. The real difference is PCI
2322 * or not PCI.
2324 if (brdp->brdtype == BRD_EASYIOPCI) {
2325 brdp->iosize1 = 0x80;
2326 brdp->iosize2 = 0x80;
2327 name = "serial(EIO-PCI)";
2328 outb(0x41, (brdp->ioaddr2 + 0x4c));
2329 } else {
2330 brdp->iosize1 = 8;
2331 name = "serial(EIO)";
2332 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2333 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2334 printk("STALLION: invalid irq=%d for brd=%d\n",
2335 brdp->irq, brdp->brdnr);
2336 return(-EINVAL);
2338 outb((stl_vecmap[brdp->irq] | EIO_0WS |
2339 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
2340 brdp->ioctrl);
2343 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2344 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2345 "%x conflicts with another device\n", brdp->brdnr,
2346 brdp->ioaddr1);
2347 return(-EBUSY);
2350 if (brdp->iosize2 > 0)
2351 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2352 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2353 "address %x conflicts with another device\n",
2354 brdp->brdnr, brdp->ioaddr2);
2355 printk(KERN_WARNING "STALLION: Warning, also "
2356 "releasing board %d I/O address %x \n",
2357 brdp->brdnr, brdp->ioaddr1);
2358 release_region(brdp->ioaddr1, brdp->iosize1);
2359 return(-EBUSY);
2363 * Everything looks OK, so let's go ahead and probe for the hardware.
2365 brdp->clk = CD1400_CLK;
2366 brdp->isr = stl_eiointr;
2368 switch (status & EIO_IDBITMASK) {
2369 case EIO_8PORTM:
2370 brdp->clk = CD1400_CLK8M;
2371 /* fall thru */
2372 case EIO_8PORTRS:
2373 case EIO_8PORTDI:
2374 brdp->nrports = 8;
2375 break;
2376 case EIO_4PORTRS:
2377 brdp->nrports = 4;
2378 break;
2379 case EIO_MK3:
2380 switch (status & EIO_BRDMASK) {
2381 case ID_BRD4:
2382 brdp->nrports = 4;
2383 break;
2384 case ID_BRD8:
2385 brdp->nrports = 8;
2386 break;
2387 case ID_BRD16:
2388 brdp->nrports = 16;
2389 break;
2390 default:
2391 return(-ENODEV);
2393 break;
2394 default:
2395 return(-ENODEV);
2399 * We have verified that the board is actually present, so now we
2400 * can complete the setup.
2403 panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
2404 if (panelp == (stlpanel_t *) NULL) {
2405 printk(KERN_WARNING "STALLION: failed to allocate memory "
2406 "(size=%d)\n", sizeof(stlpanel_t));
2407 return(-ENOMEM);
2409 memset(panelp, 0, sizeof(stlpanel_t));
2411 panelp->magic = STL_PANELMAGIC;
2412 panelp->brdnr = brdp->brdnr;
2413 panelp->panelnr = 0;
2414 panelp->nrports = brdp->nrports;
2415 panelp->iobase = brdp->ioaddr1;
2416 panelp->hwid = status;
2417 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2418 panelp->uartp = (void *) &stl_sc26198uart;
2419 panelp->isr = stl_sc26198intr;
2420 } else {
2421 panelp->uartp = (void *) &stl_cd1400uart;
2422 panelp->isr = stl_cd1400eiointr;
2425 brdp->panels[0] = panelp;
2426 brdp->nrpanels = 1;
2427 brdp->state |= BRD_FOUND;
2428 brdp->hwid = status;
2429 rc = stl_mapirq(brdp->irq, name);
2430 return(rc);
2433 /*****************************************************************************/
2436 * Try to find an ECH board and initialize it. This code is capable of
2437 * dealing with all types of ECH board.
2440 static inline int stl_initech(stlbrd_t *brdp)
2442 stlpanel_t *panelp;
2443 unsigned int status, nxtid, ioaddr, conflict;
2444 int panelnr, banknr, i;
2445 char *name;
2447 #if DEBUG
2448 printk("stl_initech(brdp=%x)\n", (int) brdp);
2449 #endif
2451 status = 0;
2452 conflict = 0;
2455 * Set up the initial board register contents for boards. This varies a
2456 * bit between the different board types. So we need to handle each
2457 * separately. Also do a check that the supplied IRQ is good.
2459 switch (brdp->brdtype) {
2461 case BRD_ECH:
2462 brdp->isr = stl_echatintr;
2463 brdp->ioctrl = brdp->ioaddr1 + 1;
2464 brdp->iostatus = brdp->ioaddr1 + 1;
2465 status = inb(brdp->iostatus);
2466 if ((status & ECH_IDBITMASK) != ECH_ID)
2467 return(-ENODEV);
2468 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2469 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2470 printk("STALLION: invalid irq=%d for brd=%d\n",
2471 brdp->irq, brdp->brdnr);
2472 return(-EINVAL);
2474 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2475 status |= (stl_vecmap[brdp->irq] << 1);
2476 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2477 brdp->ioctrlval = ECH_INTENABLE |
2478 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2479 for (i = 0; (i < 10); i++)
2480 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2481 brdp->iosize1 = 2;
2482 brdp->iosize2 = 32;
2483 name = "serial(EC8/32)";
2484 outb(status, brdp->ioaddr1);
2485 break;
2487 case BRD_ECHMC:
2488 brdp->isr = stl_echmcaintr;
2489 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2490 brdp->iostatus = brdp->ioctrl;
2491 status = inb(brdp->iostatus);
2492 if ((status & ECH_IDBITMASK) != ECH_ID)
2493 return(-ENODEV);
2494 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2495 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2496 printk("STALLION: invalid irq=%d for brd=%d\n",
2497 brdp->irq, brdp->brdnr);
2498 return(-EINVAL);
2500 outb(ECHMC_BRDRESET, brdp->ioctrl);
2501 outb(ECHMC_INTENABLE, brdp->ioctrl);
2502 brdp->iosize1 = 64;
2503 name = "serial(EC8/32-MC)";
2504 break;
2506 case BRD_ECHPCI:
2507 brdp->isr = stl_echpciintr;
2508 brdp->ioctrl = brdp->ioaddr1 + 2;
2509 brdp->iosize1 = 4;
2510 brdp->iosize2 = 8;
2511 name = "serial(EC8/32-PCI)";
2512 break;
2514 case BRD_ECH64PCI:
2515 brdp->isr = stl_echpci64intr;
2516 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2517 outb(0x43, (brdp->ioaddr1 + 0x4c));
2518 brdp->iosize1 = 0x80;
2519 brdp->iosize2 = 0x80;
2520 name = "serial(EC8/64-PCI)";
2521 break;
2523 default:
2524 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
2525 return(-EINVAL);
2526 break;
2530 * Check boards for possible IO address conflicts and return fail status
2531 * if an IO conflict found.
2533 if (!request_region(brdp->ioaddr1, brdp->iosize1, name)) {
2534 printk(KERN_WARNING "STALLION: Warning, board %d I/O address "
2535 "%x conflicts with another device\n", brdp->brdnr,
2536 brdp->ioaddr1);
2537 return(-EBUSY);
2540 if (brdp->iosize2 > 0)
2541 if (!request_region(brdp->ioaddr2, brdp->iosize2, name)) {
2542 printk(KERN_WARNING "STALLION: Warning, board %d I/O "
2543 "address %x conflicts with another device\n",
2544 brdp->brdnr, brdp->ioaddr2);
2545 printk(KERN_WARNING "STALLION: Warning, also "
2546 "releasing board %d I/O address %x \n",
2547 brdp->brdnr, brdp->ioaddr1);
2548 release_region(brdp->ioaddr1, brdp->iosize1);
2549 return(-EBUSY);
2553 * Scan through the secondary io address space looking for panels.
2554 * As we find'em allocate and initialize panel structures for each.
2556 brdp->clk = CD1400_CLK;
2557 brdp->hwid = status;
2559 ioaddr = brdp->ioaddr2;
2560 banknr = 0;
2561 panelnr = 0;
2562 nxtid = 0;
2564 for (i = 0; (i < STL_MAXPANELS); i++) {
2565 if (brdp->brdtype == BRD_ECHPCI) {
2566 outb(nxtid, brdp->ioctrl);
2567 ioaddr = brdp->ioaddr2;
2569 status = inb(ioaddr + ECH_PNLSTATUS);
2570 if ((status & ECH_PNLIDMASK) != nxtid)
2571 break;
2572 panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
2573 if (panelp == (stlpanel_t *) NULL) {
2574 printk("STALLION: failed to allocate memory "
2575 "(size=%d)\n", sizeof(stlpanel_t));
2576 break;
2578 memset(panelp, 0, sizeof(stlpanel_t));
2579 panelp->magic = STL_PANELMAGIC;
2580 panelp->brdnr = brdp->brdnr;
2581 panelp->panelnr = panelnr;
2582 panelp->iobase = ioaddr;
2583 panelp->pagenr = nxtid;
2584 panelp->hwid = status;
2585 brdp->bnk2panel[banknr] = panelp;
2586 brdp->bnkpageaddr[banknr] = nxtid;
2587 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2589 if (status & ECH_PNLXPID) {
2590 panelp->uartp = (void *) &stl_sc26198uart;
2591 panelp->isr = stl_sc26198intr;
2592 if (status & ECH_PNL16PORT) {
2593 panelp->nrports = 16;
2594 brdp->bnk2panel[banknr] = panelp;
2595 brdp->bnkpageaddr[banknr] = nxtid;
2596 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2597 ECH_PNLSTATUS;
2598 } else {
2599 panelp->nrports = 8;
2601 } else {
2602 panelp->uartp = (void *) &stl_cd1400uart;
2603 panelp->isr = stl_cd1400echintr;
2604 if (status & ECH_PNL16PORT) {
2605 panelp->nrports = 16;
2606 panelp->ackmask = 0x80;
2607 if (brdp->brdtype != BRD_ECHPCI)
2608 ioaddr += EREG_BANKSIZE;
2609 brdp->bnk2panel[banknr] = panelp;
2610 brdp->bnkpageaddr[banknr] = ++nxtid;
2611 brdp->bnkstataddr[banknr++] = ioaddr +
2612 ECH_PNLSTATUS;
2613 } else {
2614 panelp->nrports = 8;
2615 panelp->ackmask = 0xc0;
2619 nxtid++;
2620 ioaddr += EREG_BANKSIZE;
2621 brdp->nrports += panelp->nrports;
2622 brdp->panels[panelnr++] = panelp;
2623 if ((brdp->brdtype != BRD_ECHPCI) &&
2624 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
2625 break;
2628 brdp->nrpanels = panelnr;
2629 brdp->nrbnks = banknr;
2630 if (brdp->brdtype == BRD_ECH)
2631 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2633 brdp->state |= BRD_FOUND;
2634 i = stl_mapirq(brdp->irq, name);
2635 return(i);
2638 /*****************************************************************************/
2641 * Initialize and configure the specified board.
2642 * Scan through all the boards in the configuration and see what we
2643 * can find. Handle EIO and the ECH boards a little differently here
2644 * since the initial search and setup is very different.
2647 static int __init stl_brdinit(stlbrd_t *brdp)
2649 int i;
2651 #if DEBUG
2652 printk("stl_brdinit(brdp=%x)\n", (int) brdp);
2653 #endif
2655 switch (brdp->brdtype) {
2656 case BRD_EASYIO:
2657 case BRD_EASYIOPCI:
2658 stl_initeio(brdp);
2659 break;
2660 case BRD_ECH:
2661 case BRD_ECHMC:
2662 case BRD_ECHPCI:
2663 case BRD_ECH64PCI:
2664 stl_initech(brdp);
2665 break;
2666 default:
2667 printk("STALLION: board=%d is unknown board type=%d\n",
2668 brdp->brdnr, brdp->brdtype);
2669 return(ENODEV);
2672 stl_brds[brdp->brdnr] = brdp;
2673 if ((brdp->state & BRD_FOUND) == 0) {
2674 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2675 stl_brdnames[brdp->brdtype], brdp->brdnr,
2676 brdp->ioaddr1, brdp->irq);
2677 return(ENODEV);
2680 for (i = 0; (i < STL_MAXPANELS); i++)
2681 if (brdp->panels[i] != (stlpanel_t *) NULL)
2682 stl_initports(brdp, brdp->panels[i]);
2684 printk("STALLION: %s found, board=%d io=%x irq=%d "
2685 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2686 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2687 brdp->nrports);
2688 return(0);
2691 /*****************************************************************************/
2694 * Find the next available board number that is free.
2697 static inline int stl_getbrdnr()
2699 int i;
2701 for (i = 0; (i < STL_MAXBRDS); i++) {
2702 if (stl_brds[i] == (stlbrd_t *) NULL) {
2703 if (i >= stl_nrbrds)
2704 stl_nrbrds = i + 1;
2705 return(i);
2708 return(-1);
2711 /*****************************************************************************/
2713 #ifdef CONFIG_PCI
2716 * We have a Stallion board. Allocate a board structure and
2717 * initialize it. Read its IO and IRQ resources from PCI
2718 * configuration space.
2721 static inline int stl_initpcibrd(int brdtype, struct pci_dev *devp)
2723 stlbrd_t *brdp;
2725 #if DEBUG
2726 printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype,
2727 devp->bus->number, devp->devfn);
2728 #endif
2730 if (pci_enable_device(devp))
2731 return(-EIO);
2732 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2733 return(-ENOMEM);
2734 if ((brdp->brdnr = stl_getbrdnr()) < 0) {
2735 printk("STALLION: too many boards found, "
2736 "maximum supported %d\n", STL_MAXBRDS);
2737 return(0);
2739 brdp->brdtype = brdtype;
2742 * Different Stallion boards use the BAR registers in different ways,
2743 * so set up io addresses based on board type.
2745 #if DEBUG
2746 printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__, __LINE__,
2747 pci_resource_start(devp, 0), pci_resource_start(devp, 1),
2748 pci_resource_start(devp, 2), pci_resource_start(devp, 3), devp->irq);
2749 #endif
2752 * We have all resources from the board, so let's setup the actual
2753 * board structure now.
2755 switch (brdtype) {
2756 case BRD_ECHPCI:
2757 brdp->ioaddr2 = pci_resource_start(devp, 0);
2758 brdp->ioaddr1 = pci_resource_start(devp, 1);
2759 break;
2760 case BRD_ECH64PCI:
2761 brdp->ioaddr2 = pci_resource_start(devp, 2);
2762 brdp->ioaddr1 = pci_resource_start(devp, 1);
2763 break;
2764 case BRD_EASYIOPCI:
2765 brdp->ioaddr1 = pci_resource_start(devp, 2);
2766 brdp->ioaddr2 = pci_resource_start(devp, 1);
2767 break;
2768 default:
2769 printk("STALLION: unknown PCI board type=%d\n", brdtype);
2770 break;
2773 brdp->irq = devp->irq;
2774 stl_brdinit(brdp);
2776 return(0);
2779 /*****************************************************************************/
2782 * Find all Stallion PCI boards that might be installed. Initialize each
2783 * one as it is found.
2787 static inline int stl_findpcibrds()
2789 struct pci_dev *dev = NULL;
2790 int i, rc;
2792 #if DEBUG
2793 printk("stl_findpcibrds()\n");
2794 #endif
2796 for (i = 0; (i < stl_nrpcibrds); i++)
2797 while ((dev = pci_find_device(stl_pcibrds[i].vendid,
2798 stl_pcibrds[i].devid, dev))) {
2801 * Found a device on the PCI bus that has our vendor and
2802 * device ID. Need to check now that it is really us.
2804 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2805 continue;
2807 rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
2808 if (rc)
2809 return(rc);
2812 return(0);
2815 #endif
2817 /*****************************************************************************/
2820 * Scan through all the boards in the configuration and see what we
2821 * can find. Handle EIO and the ECH boards a little differently here
2822 * since the initial search and setup is too different.
2825 static inline int stl_initbrds()
2827 stlbrd_t *brdp;
2828 stlconf_t *confp;
2829 int i;
2831 #if DEBUG
2832 printk("stl_initbrds()\n");
2833 #endif
2835 if (stl_nrbrds > STL_MAXBRDS) {
2836 printk("STALLION: too many boards in configuration table, "
2837 "truncating to %d\n", STL_MAXBRDS);
2838 stl_nrbrds = STL_MAXBRDS;
2842 * Firstly scan the list of static boards configured. Allocate
2843 * resources and initialize the boards as found.
2845 for (i = 0; (i < stl_nrbrds); i++) {
2846 confp = &stl_brdconf[i];
2847 #ifdef MODULE
2848 stl_parsebrd(confp, stl_brdsp[i]);
2849 #endif
2850 if ((brdp = stl_allocbrd()) == (stlbrd_t *) NULL)
2851 return(-ENOMEM);
2852 brdp->brdnr = i;
2853 brdp->brdtype = confp->brdtype;
2854 brdp->ioaddr1 = confp->ioaddr1;
2855 brdp->ioaddr2 = confp->ioaddr2;
2856 brdp->irq = confp->irq;
2857 brdp->irqtype = confp->irqtype;
2858 stl_brdinit(brdp);
2862 * Find any dynamically supported boards. That is via module load
2863 * line options or auto-detected on the PCI bus.
2865 #ifdef MODULE
2866 stl_argbrds();
2867 #endif
2868 #ifdef CONFIG_PCI
2869 stl_findpcibrds();
2870 #endif
2872 return(0);
2875 /*****************************************************************************/
2878 * Return the board stats structure to user app.
2881 static int stl_getbrdstats(combrd_t *bp)
2883 stlbrd_t *brdp;
2884 stlpanel_t *panelp;
2885 int i;
2887 if (copy_from_user(&stl_brdstats, bp, sizeof(combrd_t)))
2888 return -EFAULT;
2889 if (stl_brdstats.brd >= STL_MAXBRDS)
2890 return(-ENODEV);
2891 brdp = stl_brds[stl_brdstats.brd];
2892 if (brdp == (stlbrd_t *) NULL)
2893 return(-ENODEV);
2895 memset(&stl_brdstats, 0, sizeof(combrd_t));
2896 stl_brdstats.brd = brdp->brdnr;
2897 stl_brdstats.type = brdp->brdtype;
2898 stl_brdstats.hwid = brdp->hwid;
2899 stl_brdstats.state = brdp->state;
2900 stl_brdstats.ioaddr = brdp->ioaddr1;
2901 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2902 stl_brdstats.irq = brdp->irq;
2903 stl_brdstats.nrpanels = brdp->nrpanels;
2904 stl_brdstats.nrports = brdp->nrports;
2905 for (i = 0; (i < brdp->nrpanels); i++) {
2906 panelp = brdp->panels[i];
2907 stl_brdstats.panels[i].panel = i;
2908 stl_brdstats.panels[i].hwid = panelp->hwid;
2909 stl_brdstats.panels[i].nrports = panelp->nrports;
2912 return copy_to_user(bp, &stl_brdstats, sizeof(combrd_t)) ? -EFAULT : 0;
2915 /*****************************************************************************/
2918 * Resolve the referenced port number into a port struct pointer.
2921 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2923 stlbrd_t *brdp;
2924 stlpanel_t *panelp;
2926 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2927 return((stlport_t *) NULL);
2928 brdp = stl_brds[brdnr];
2929 if (brdp == (stlbrd_t *) NULL)
2930 return((stlport_t *) NULL);
2931 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2932 return((stlport_t *) NULL);
2933 panelp = brdp->panels[panelnr];
2934 if (panelp == (stlpanel_t *) NULL)
2935 return((stlport_t *) NULL);
2936 if ((portnr < 0) || (portnr >= panelp->nrports))
2937 return((stlport_t *) NULL);
2938 return(panelp->ports[portnr]);
2941 /*****************************************************************************/
2944 * Return the port stats structure to user app. A NULL port struct
2945 * pointer passed in means that we need to find out from the app
2946 * what port to get stats for (used through board control device).
2949 static int stl_getportstats(stlport_t *portp, comstats_t *cp)
2951 unsigned char *head, *tail;
2952 unsigned long flags;
2954 if (portp == (stlport_t *) NULL) {
2955 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
2956 return -EFAULT;
2957 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2958 stl_comstats.port);
2959 if (portp == (stlport_t *) NULL)
2960 return(-ENODEV);
2963 portp->stats.state = portp->istate;
2964 portp->stats.flags = portp->flags;
2965 portp->stats.hwid = portp->hwid;
2967 portp->stats.ttystate = 0;
2968 portp->stats.cflags = 0;
2969 portp->stats.iflags = 0;
2970 portp->stats.oflags = 0;
2971 portp->stats.lflags = 0;
2972 portp->stats.rxbuffered = 0;
2974 save_flags(flags);
2975 cli();
2976 if (portp->tty != (struct tty_struct *) NULL) {
2977 if (portp->tty->driver_data == portp) {
2978 portp->stats.ttystate = portp->tty->flags;
2979 portp->stats.rxbuffered = portp->tty->flip.count;
2980 if (portp->tty->termios != (struct termios *) NULL) {
2981 portp->stats.cflags = portp->tty->termios->c_cflag;
2982 portp->stats.iflags = portp->tty->termios->c_iflag;
2983 portp->stats.oflags = portp->tty->termios->c_oflag;
2984 portp->stats.lflags = portp->tty->termios->c_lflag;
2988 restore_flags(flags);
2990 head = portp->tx.head;
2991 tail = portp->tx.tail;
2992 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2993 (STL_TXBUFSIZE - (tail - head)));
2995 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2997 return copy_to_user(cp, &portp->stats,
2998 sizeof(comstats_t)) ? -EFAULT : 0;
3001 /*****************************************************************************/
3004 * Clear the port stats structure. We also return it zeroed out...
3007 static int stl_clrportstats(stlport_t *portp, comstats_t *cp)
3009 if (portp == (stlport_t *) NULL) {
3010 if (copy_from_user(&stl_comstats, cp, sizeof(comstats_t)))
3011 return -EFAULT;
3012 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
3013 stl_comstats.port);
3014 if (portp == (stlport_t *) NULL)
3015 return(-ENODEV);
3018 memset(&portp->stats, 0, sizeof(comstats_t));
3019 portp->stats.brd = portp->brdnr;
3020 portp->stats.panel = portp->panelnr;
3021 portp->stats.port = portp->portnr;
3022 return copy_to_user(cp, &portp->stats,
3023 sizeof(comstats_t)) ? -EFAULT : 0;
3026 /*****************************************************************************/
3029 * Return the entire driver ports structure to a user app.
3032 static int stl_getportstruct(unsigned long arg)
3034 stlport_t *portp;
3036 if (copy_from_user(&stl_dummyport, (void *) arg, sizeof(stlport_t)))
3037 return -EFAULT;
3038 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
3039 stl_dummyport.portnr);
3040 if (portp == (stlport_t *) NULL)
3041 return(-ENODEV);
3042 return copy_to_user((void *)arg, portp,
3043 sizeof(stlport_t)) ? -EFAULT : 0;
3046 /*****************************************************************************/
3049 * Return the entire driver board structure to a user app.
3052 static int stl_getbrdstruct(unsigned long arg)
3054 stlbrd_t *brdp;
3056 if (copy_from_user(&stl_dummybrd, (void *) arg, sizeof(stlbrd_t)))
3057 return -EFAULT;
3058 if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
3059 return(-ENODEV);
3060 brdp = stl_brds[stl_dummybrd.brdnr];
3061 if (brdp == (stlbrd_t *) NULL)
3062 return(-ENODEV);
3063 return copy_to_user((void *)arg, brdp, sizeof(stlbrd_t)) ? -EFAULT : 0;
3066 /*****************************************************************************/
3069 * The "staliomem" device is also required to do some special operations
3070 * on the board and/or ports. In this driver it is mostly used for stats
3071 * collection.
3074 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
3076 int brdnr, rc;
3078 #if DEBUG
3079 printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
3080 (int) fp, cmd, (int) arg);
3081 #endif
3083 brdnr = minor(ip->i_rdev);
3084 if (brdnr >= STL_MAXBRDS)
3085 return(-ENODEV);
3086 rc = 0;
3088 switch (cmd) {
3089 case COM_GETPORTSTATS:
3090 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
3091 sizeof(comstats_t))) == 0)
3092 rc = stl_getportstats((stlport_t *) NULL,
3093 (comstats_t *) arg);
3094 break;
3095 case COM_CLRPORTSTATS:
3096 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
3097 sizeof(comstats_t))) == 0)
3098 rc = stl_clrportstats((stlport_t *) NULL,
3099 (comstats_t *) arg);
3100 break;
3101 case COM_GETBRDSTATS:
3102 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
3103 sizeof(combrd_t))) == 0)
3104 rc = stl_getbrdstats((combrd_t *) arg);
3105 break;
3106 case COM_READPORT:
3107 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
3108 sizeof(stlport_t))) == 0)
3109 rc = stl_getportstruct(arg);
3110 break;
3111 case COM_READBOARD:
3112 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
3113 sizeof(stlbrd_t))) == 0)
3114 rc = stl_getbrdstruct(arg);
3115 break;
3116 default:
3117 rc = -ENOIOCTLCMD;
3118 break;
3121 return(rc);
3124 static struct tty_operations stl_ops = {
3125 .open = stl_open,
3126 .close = stl_close,
3127 .write = stl_write,
3128 .put_char = stl_putchar,
3129 .flush_chars = stl_flushchars,
3130 .write_room = stl_writeroom,
3131 .chars_in_buffer = stl_charsinbuffer,
3132 .ioctl = stl_ioctl,
3133 .set_termios = stl_settermios,
3134 .throttle = stl_throttle,
3135 .unthrottle = stl_unthrottle,
3136 .stop = stl_stop,
3137 .start = stl_start,
3138 .hangup = stl_hangup,
3139 .flush_buffer = stl_flushbuffer,
3140 .break_ctl = stl_breakctl,
3141 .wait_until_sent = stl_waituntilsent,
3142 .send_xchar = stl_sendxchar,
3143 .read_proc = stl_readproc,
3146 /*****************************************************************************/
3148 int __init stl_init(void)
3150 int i;
3151 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
3153 stl_initbrds();
3155 stl_serial = alloc_tty_driver(STL_MAXBRDS * STL_MAXPORTS);
3156 if (!stl_serial)
3157 return -1;
3160 * Allocate a temporary write buffer.
3162 stl_tmpwritebuf = (char *) stl_memalloc(STL_TXBUFSIZE);
3163 if (stl_tmpwritebuf == (char *) NULL)
3164 printk("STALLION: failed to allocate memory (size=%d)\n",
3165 STL_TXBUFSIZE);
3168 * Set up a character driver for per board stuff. This is mainly used
3169 * to do stats ioctls on the ports.
3171 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
3172 printk("STALLION: failed to register serial board device\n");
3173 devfs_mk_dir("staliomem");
3175 for (i = 0; i < 4; i++) {
3176 devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR, i),
3177 S_IFCHR|S_IRUSR|S_IWUSR,
3178 &stl_fsiomem, NULL, "staliomem/%d", i);
3181 stl_serial->owner = THIS_MODULE;
3182 stl_serial->driver_name = stl_drvname;
3183 stl_serial->name = "ttyE";
3184 stl_serial->devfs_name = "tts/E";
3185 stl_serial->major = STL_SERIALMAJOR;
3186 stl_serial->minor_start = 0;
3187 stl_serial->type = TTY_DRIVER_TYPE_SERIAL;
3188 stl_serial->subtype = SERIAL_TYPE_NORMAL;
3189 stl_serial->init_termios = stl_deftermios;
3190 stl_serial->flags = TTY_DRIVER_REAL_RAW;
3191 tty_set_operations(stl_serial, &stl_ops);
3193 if (tty_register_driver(stl_serial)) {
3194 put_tty_driver(stl_serial);
3195 printk("STALLION: failed to register serial driver\n");
3196 return -1;
3199 return(0);
3202 /*****************************************************************************/
3203 /* CD1400 HARDWARE FUNCTIONS */
3204 /*****************************************************************************/
3207 * These functions get/set/update the registers of the cd1400 UARTs.
3208 * Access to the cd1400 registers is via an address/data io port pair.
3209 * (Maybe should make this inline...)
3212 static int stl_cd1400getreg(stlport_t *portp, int regnr)
3214 outb((regnr + portp->uartaddr), portp->ioaddr);
3215 return(inb(portp->ioaddr + EREG_DATA));
3218 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
3220 outb((regnr + portp->uartaddr), portp->ioaddr);
3221 outb(value, portp->ioaddr + EREG_DATA);
3224 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
3226 outb((regnr + portp->uartaddr), portp->ioaddr);
3227 if (inb(portp->ioaddr + EREG_DATA) != value) {
3228 outb(value, portp->ioaddr + EREG_DATA);
3229 return(1);
3231 return(0);
3234 /*****************************************************************************/
3237 * Inbitialize the UARTs in a panel. We don't care what sort of board
3238 * these ports are on - since the port io registers are almost
3239 * identical when dealing with ports.
3242 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3244 unsigned int gfrcr;
3245 int chipmask, i, j;
3246 int nrchips, uartaddr, ioaddr;
3248 #if DEBUG
3249 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
3250 #endif
3252 BRDENABLE(panelp->brdnr, panelp->pagenr);
3255 * Check that each chip is present and started up OK.
3257 chipmask = 0;
3258 nrchips = panelp->nrports / CD1400_PORTS;
3259 for (i = 0; (i < nrchips); i++) {
3260 if (brdp->brdtype == BRD_ECHPCI) {
3261 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3262 ioaddr = panelp->iobase;
3263 } else {
3264 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3266 uartaddr = (i & 0x01) ? 0x080 : 0;
3267 outb((GFRCR + uartaddr), ioaddr);
3268 outb(0, (ioaddr + EREG_DATA));
3269 outb((CCR + uartaddr), ioaddr);
3270 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3271 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3272 outb((GFRCR + uartaddr), ioaddr);
3273 for (j = 0; (j < CCR_MAXWAIT); j++) {
3274 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3275 break;
3277 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3278 printk("STALLION: cd1400 not responding, "
3279 "brd=%d panel=%d chip=%d\n",
3280 panelp->brdnr, panelp->panelnr, i);
3281 continue;
3283 chipmask |= (0x1 << i);
3284 outb((PPR + uartaddr), ioaddr);
3285 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
3288 BRDDISABLE(panelp->brdnr);
3289 return(chipmask);
3292 /*****************************************************************************/
3295 * Initialize hardware specific port registers.
3298 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3300 #if DEBUG
3301 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3302 (int) brdp, (int) panelp, (int) portp);
3303 #endif
3305 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
3306 (portp == (stlport_t *) NULL))
3307 return;
3309 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3310 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3311 portp->uartaddr = (portp->portnr & 0x04) << 5;
3312 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3314 BRDENABLE(portp->brdnr, portp->pagenr);
3315 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3316 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3317 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3318 BRDDISABLE(portp->brdnr);
3321 /*****************************************************************************/
3324 * Wait for the command register to be ready. We will poll this,
3325 * since it won't usually take too long to be ready.
3328 static void stl_cd1400ccrwait(stlport_t *portp)
3330 int i;
3332 for (i = 0; (i < CCR_MAXWAIT); i++) {
3333 if (stl_cd1400getreg(portp, CCR) == 0) {
3334 return;
3338 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
3339 portp->portnr, portp->panelnr, portp->brdnr);
3342 /*****************************************************************************/
3345 * Set up the cd1400 registers for a port based on the termios port
3346 * settings.
3349 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3351 stlbrd_t *brdp;
3352 unsigned long flags;
3353 unsigned int clkdiv, baudrate;
3354 unsigned char cor1, cor2, cor3;
3355 unsigned char cor4, cor5, ccr;
3356 unsigned char srer, sreron, sreroff;
3357 unsigned char mcor1, mcor2, rtpr;
3358 unsigned char clk, div;
3360 cor1 = 0;
3361 cor2 = 0;
3362 cor3 = 0;
3363 cor4 = 0;
3364 cor5 = 0;
3365 ccr = 0;
3366 rtpr = 0;
3367 clk = 0;
3368 div = 0;
3369 mcor1 = 0;
3370 mcor2 = 0;
3371 sreron = 0;
3372 sreroff = 0;
3374 brdp = stl_brds[portp->brdnr];
3375 if (brdp == (stlbrd_t *) NULL)
3376 return;
3379 * Set up the RX char ignore mask with those RX error types we
3380 * can ignore. We can get the cd1400 to help us out a little here,
3381 * it will ignore parity errors and breaks for us.
3383 portp->rxignoremsk = 0;
3384 if (tiosp->c_iflag & IGNPAR) {
3385 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
3386 cor1 |= COR1_PARIGNORE;
3388 if (tiosp->c_iflag & IGNBRK) {
3389 portp->rxignoremsk |= ST_BREAK;
3390 cor4 |= COR4_IGNBRK;
3393 portp->rxmarkmsk = ST_OVERRUN;
3394 if (tiosp->c_iflag & (INPCK | PARMRK))
3395 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3396 if (tiosp->c_iflag & BRKINT)
3397 portp->rxmarkmsk |= ST_BREAK;
3400 * Go through the char size, parity and stop bits and set all the
3401 * option register appropriately.
3403 switch (tiosp->c_cflag & CSIZE) {
3404 case CS5:
3405 cor1 |= COR1_CHL5;
3406 break;
3407 case CS6:
3408 cor1 |= COR1_CHL6;
3409 break;
3410 case CS7:
3411 cor1 |= COR1_CHL7;
3412 break;
3413 default:
3414 cor1 |= COR1_CHL8;
3415 break;
3418 if (tiosp->c_cflag & CSTOPB)
3419 cor1 |= COR1_STOP2;
3420 else
3421 cor1 |= COR1_STOP1;
3423 if (tiosp->c_cflag & PARENB) {
3424 if (tiosp->c_cflag & PARODD)
3425 cor1 |= (COR1_PARENB | COR1_PARODD);
3426 else
3427 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3428 } else {
3429 cor1 |= COR1_PARNONE;
3433 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3434 * space for hardware flow control and the like. This should be set to
3435 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3436 * really be based on VTIME.
3438 cor3 |= FIFO_RXTHRESHOLD;
3439 rtpr = 2;
3442 * Calculate the baud rate timers. For now we will just assume that
3443 * the input and output baud are the same. Could have used a baud
3444 * table here, but this way we can generate virtually any baud rate
3445 * we like!
3447 baudrate = tiosp->c_cflag & CBAUD;
3448 if (baudrate & CBAUDEX) {
3449 baudrate &= ~CBAUDEX;
3450 if ((baudrate < 1) || (baudrate > 4))
3451 tiosp->c_cflag &= ~CBAUDEX;
3452 else
3453 baudrate += 15;
3455 baudrate = stl_baudrates[baudrate];
3456 if ((tiosp->c_cflag & CBAUD) == B38400) {
3457 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3458 baudrate = 57600;
3459 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3460 baudrate = 115200;
3461 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3462 baudrate = 230400;
3463 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3464 baudrate = 460800;
3465 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3466 baudrate = (portp->baud_base / portp->custom_divisor);
3468 if (baudrate > STL_CD1400MAXBAUD)
3469 baudrate = STL_CD1400MAXBAUD;
3471 if (baudrate > 0) {
3472 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3473 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
3474 if (clkdiv < 0x100)
3475 break;
3477 div = (unsigned char) clkdiv;
3481 * Check what form of modem signaling is required and set it up.
3483 if ((tiosp->c_cflag & CLOCAL) == 0) {
3484 mcor1 |= MCOR1_DCD;
3485 mcor2 |= MCOR2_DCD;
3486 sreron |= SRER_MODEM;
3487 portp->flags |= ASYNC_CHECK_CD;
3488 } else {
3489 portp->flags &= ~ASYNC_CHECK_CD;
3493 * Setup cd1400 enhanced modes if we can. In particular we want to
3494 * handle as much of the flow control as possible automatically. As
3495 * well as saving a few CPU cycles it will also greatly improve flow
3496 * control reliability.
3498 if (tiosp->c_iflag & IXON) {
3499 cor2 |= COR2_TXIBE;
3500 cor3 |= COR3_SCD12;
3501 if (tiosp->c_iflag & IXANY)
3502 cor2 |= COR2_IXM;
3505 if (tiosp->c_cflag & CRTSCTS) {
3506 cor2 |= COR2_CTSAE;
3507 mcor1 |= FIFO_RTSTHRESHOLD;
3511 * All cd1400 register values calculated so go through and set
3512 * them all up.
3515 #if DEBUG
3516 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3517 portp->portnr, portp->panelnr, portp->brdnr);
3518 printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3519 cor1, cor2, cor3, cor4, cor5);
3520 printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3521 mcor1, mcor2, rtpr, sreron, sreroff);
3522 printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3523 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3524 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3525 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3526 #endif
3528 save_flags(flags);
3529 cli();
3530 BRDENABLE(portp->brdnr, portp->pagenr);
3531 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3532 srer = stl_cd1400getreg(portp, SRER);
3533 stl_cd1400setreg(portp, SRER, 0);
3534 if (stl_cd1400updatereg(portp, COR1, cor1))
3535 ccr = 1;
3536 if (stl_cd1400updatereg(portp, COR2, cor2))
3537 ccr = 1;
3538 if (stl_cd1400updatereg(portp, COR3, cor3))
3539 ccr = 1;
3540 if (ccr) {
3541 stl_cd1400ccrwait(portp);
3542 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3544 stl_cd1400setreg(portp, COR4, cor4);
3545 stl_cd1400setreg(portp, COR5, cor5);
3546 stl_cd1400setreg(portp, MCOR1, mcor1);
3547 stl_cd1400setreg(portp, MCOR2, mcor2);
3548 if (baudrate > 0) {
3549 stl_cd1400setreg(portp, TCOR, clk);
3550 stl_cd1400setreg(portp, TBPR, div);
3551 stl_cd1400setreg(portp, RCOR, clk);
3552 stl_cd1400setreg(portp, RBPR, div);
3554 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3555 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3556 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3557 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3558 stl_cd1400setreg(portp, RTPR, rtpr);
3559 mcor1 = stl_cd1400getreg(portp, MSVR1);
3560 if (mcor1 & MSVR1_DCD)
3561 portp->sigs |= TIOCM_CD;
3562 else
3563 portp->sigs &= ~TIOCM_CD;
3564 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3565 BRDDISABLE(portp->brdnr);
3566 restore_flags(flags);
3569 /*****************************************************************************/
3572 * Set the state of the DTR and RTS signals.
3575 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3577 unsigned char msvr1, msvr2;
3578 unsigned long flags;
3580 #if DEBUG
3581 printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
3582 (int) portp, dtr, rts);
3583 #endif
3585 msvr1 = 0;
3586 msvr2 = 0;
3587 if (dtr > 0)
3588 msvr1 = MSVR1_DTR;
3589 if (rts > 0)
3590 msvr2 = MSVR2_RTS;
3592 save_flags(flags);
3593 cli();
3594 BRDENABLE(portp->brdnr, portp->pagenr);
3595 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3596 if (rts >= 0)
3597 stl_cd1400setreg(portp, MSVR2, msvr2);
3598 if (dtr >= 0)
3599 stl_cd1400setreg(portp, MSVR1, msvr1);
3600 BRDDISABLE(portp->brdnr);
3601 restore_flags(flags);
3604 /*****************************************************************************/
3607 * Return the state of the signals.
3610 static int stl_cd1400getsignals(stlport_t *portp)
3612 unsigned char msvr1, msvr2;
3613 unsigned long flags;
3614 int sigs;
3616 #if DEBUG
3617 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3618 #endif
3620 save_flags(flags);
3621 cli();
3622 BRDENABLE(portp->brdnr, portp->pagenr);
3623 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3624 msvr1 = stl_cd1400getreg(portp, MSVR1);
3625 msvr2 = stl_cd1400getreg(portp, MSVR2);
3626 BRDDISABLE(portp->brdnr);
3627 restore_flags(flags);
3629 sigs = 0;
3630 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3631 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3632 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3633 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3634 #if 0
3635 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3636 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3637 #else
3638 sigs |= TIOCM_DSR;
3639 #endif
3640 return(sigs);
3643 /*****************************************************************************/
3646 * Enable/Disable the Transmitter and/or Receiver.
3649 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3651 unsigned char ccr;
3652 unsigned long flags;
3654 #if DEBUG
3655 printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3656 (int) portp, rx, tx);
3657 #endif
3658 ccr = 0;
3660 if (tx == 0)
3661 ccr |= CCR_TXDISABLE;
3662 else if (tx > 0)
3663 ccr |= CCR_TXENABLE;
3664 if (rx == 0)
3665 ccr |= CCR_RXDISABLE;
3666 else if (rx > 0)
3667 ccr |= CCR_RXENABLE;
3669 save_flags(flags);
3670 cli();
3671 BRDENABLE(portp->brdnr, portp->pagenr);
3672 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3673 stl_cd1400ccrwait(portp);
3674 stl_cd1400setreg(portp, CCR, ccr);
3675 stl_cd1400ccrwait(portp);
3676 BRDDISABLE(portp->brdnr);
3677 restore_flags(flags);
3680 /*****************************************************************************/
3683 * Start/stop the Transmitter and/or Receiver.
3686 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3688 unsigned char sreron, sreroff;
3689 unsigned long flags;
3691 #if DEBUG
3692 printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3693 (int) portp, rx, tx);
3694 #endif
3696 sreron = 0;
3697 sreroff = 0;
3698 if (tx == 0)
3699 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3700 else if (tx == 1)
3701 sreron |= SRER_TXDATA;
3702 else if (tx >= 2)
3703 sreron |= SRER_TXEMPTY;
3704 if (rx == 0)
3705 sreroff |= SRER_RXDATA;
3706 else if (rx > 0)
3707 sreron |= SRER_RXDATA;
3709 save_flags(flags);
3710 cli();
3711 BRDENABLE(portp->brdnr, portp->pagenr);
3712 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3713 stl_cd1400setreg(portp, SRER,
3714 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3715 BRDDISABLE(portp->brdnr);
3716 if (tx > 0)
3717 set_bit(ASYI_TXBUSY, &portp->istate);
3718 restore_flags(flags);
3721 /*****************************************************************************/
3724 * Disable all interrupts from this port.
3727 static void stl_cd1400disableintrs(stlport_t *portp)
3729 unsigned long flags;
3731 #if DEBUG
3732 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3733 #endif
3734 save_flags(flags);
3735 cli();
3736 BRDENABLE(portp->brdnr, portp->pagenr);
3737 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3738 stl_cd1400setreg(portp, SRER, 0);
3739 BRDDISABLE(portp->brdnr);
3740 restore_flags(flags);
3743 /*****************************************************************************/
3745 static void stl_cd1400sendbreak(stlport_t *portp, int len)
3747 unsigned long flags;
3749 #if DEBUG
3750 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
3751 #endif
3753 save_flags(flags);
3754 cli();
3755 BRDENABLE(portp->brdnr, portp->pagenr);
3756 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3757 stl_cd1400setreg(portp, SRER,
3758 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3759 SRER_TXEMPTY));
3760 BRDDISABLE(portp->brdnr);
3761 portp->brklen = len;
3762 if (len == 1)
3763 portp->stats.txbreaks++;
3764 restore_flags(flags);
3767 /*****************************************************************************/
3770 * Take flow control actions...
3773 static void stl_cd1400flowctrl(stlport_t *portp, int state)
3775 struct tty_struct *tty;
3776 unsigned long flags;
3778 #if DEBUG
3779 printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp, state);
3780 #endif
3782 if (portp == (stlport_t *) NULL)
3783 return;
3784 tty = portp->tty;
3785 if (tty == (struct tty_struct *) NULL)
3786 return;
3788 save_flags(flags);
3789 cli();
3790 BRDENABLE(portp->brdnr, portp->pagenr);
3791 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3793 if (state) {
3794 if (tty->termios->c_iflag & IXOFF) {
3795 stl_cd1400ccrwait(portp);
3796 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3797 portp->stats.rxxon++;
3798 stl_cd1400ccrwait(portp);
3801 * Question: should we return RTS to what it was before? It may
3802 * have been set by an ioctl... Suppose not, since if you have
3803 * hardware flow control set then it is pretty silly to go and
3804 * set the RTS line by hand.
3806 if (tty->termios->c_cflag & CRTSCTS) {
3807 stl_cd1400setreg(portp, MCOR1,
3808 (stl_cd1400getreg(portp, MCOR1) |
3809 FIFO_RTSTHRESHOLD));
3810 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3811 portp->stats.rxrtson++;
3813 } else {
3814 if (tty->termios->c_iflag & IXOFF) {
3815 stl_cd1400ccrwait(portp);
3816 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3817 portp->stats.rxxoff++;
3818 stl_cd1400ccrwait(portp);
3820 if (tty->termios->c_cflag & CRTSCTS) {
3821 stl_cd1400setreg(portp, MCOR1,
3822 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3823 stl_cd1400setreg(portp, MSVR2, 0);
3824 portp->stats.rxrtsoff++;
3828 BRDDISABLE(portp->brdnr);
3829 restore_flags(flags);
3832 /*****************************************************************************/
3835 * Send a flow control character...
3838 static void stl_cd1400sendflow(stlport_t *portp, int state)
3840 struct tty_struct *tty;
3841 unsigned long flags;
3843 #if DEBUG
3844 printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp, state);
3845 #endif
3847 if (portp == (stlport_t *) NULL)
3848 return;
3849 tty = portp->tty;
3850 if (tty == (struct tty_struct *) NULL)
3851 return;
3853 save_flags(flags);
3854 cli();
3855 BRDENABLE(portp->brdnr, portp->pagenr);
3856 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3857 if (state) {
3858 stl_cd1400ccrwait(portp);
3859 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3860 portp->stats.rxxon++;
3861 stl_cd1400ccrwait(portp);
3862 } else {
3863 stl_cd1400ccrwait(portp);
3864 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3865 portp->stats.rxxoff++;
3866 stl_cd1400ccrwait(portp);
3868 BRDDISABLE(portp->brdnr);
3869 restore_flags(flags);
3872 /*****************************************************************************/
3874 static void stl_cd1400flush(stlport_t *portp)
3876 unsigned long flags;
3878 #if DEBUG
3879 printk("stl_cd1400flush(portp=%x)\n", (int) portp);
3880 #endif
3882 if (portp == (stlport_t *) NULL)
3883 return;
3885 save_flags(flags);
3886 cli();
3887 BRDENABLE(portp->brdnr, portp->pagenr);
3888 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3889 stl_cd1400ccrwait(portp);
3890 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3891 stl_cd1400ccrwait(portp);
3892 portp->tx.tail = portp->tx.head;
3893 BRDDISABLE(portp->brdnr);
3894 restore_flags(flags);
3897 /*****************************************************************************/
3900 * Return the current state of data flow on this port. This is only
3901 * really interresting when determining if data has fully completed
3902 * transmission or not... This is easy for the cd1400, it accurately
3903 * maintains the busy port flag.
3906 static int stl_cd1400datastate(stlport_t *portp)
3908 #if DEBUG
3909 printk("stl_cd1400datastate(portp=%x)\n", (int) portp);
3910 #endif
3912 if (portp == (stlport_t *) NULL)
3913 return(0);
3915 return(test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0);
3918 /*****************************************************************************/
3921 * Interrupt service routine for cd1400 EasyIO boards.
3924 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3926 unsigned char svrtype;
3928 #if DEBUG
3929 printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
3930 (int) panelp, iobase);
3931 #endif
3933 outb(SVRR, iobase);
3934 svrtype = inb(iobase + EREG_DATA);
3935 if (panelp->nrports > 4) {
3936 outb((SVRR + 0x80), iobase);
3937 svrtype |= inb(iobase + EREG_DATA);
3940 if (svrtype & SVRR_RX)
3941 stl_cd1400rxisr(panelp, iobase);
3942 else if (svrtype & SVRR_TX)
3943 stl_cd1400txisr(panelp, iobase);
3944 else if (svrtype & SVRR_MDM)
3945 stl_cd1400mdmisr(panelp, iobase);
3948 /*****************************************************************************/
3951 * Interrupt service routine for cd1400 panels.
3954 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
3956 unsigned char svrtype;
3958 #if DEBUG
3959 printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
3960 iobase);
3961 #endif
3963 outb(SVRR, iobase);
3964 svrtype = inb(iobase + EREG_DATA);
3965 outb((SVRR + 0x80), iobase);
3966 svrtype |= inb(iobase + EREG_DATA);
3967 if (svrtype & SVRR_RX)
3968 stl_cd1400rxisr(panelp, iobase);
3969 else if (svrtype & SVRR_TX)
3970 stl_cd1400txisr(panelp, iobase);
3971 else if (svrtype & SVRR_MDM)
3972 stl_cd1400mdmisr(panelp, iobase);
3976 /*****************************************************************************/
3979 * Unfortunately we need to handle breaks in the TX data stream, since
3980 * this is the only way to generate them on the cd1400.
3983 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr)
3985 if (portp->brklen == 1) {
3986 outb((COR2 + portp->uartaddr), ioaddr);
3987 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
3988 (ioaddr + EREG_DATA));
3989 outb((TDR + portp->uartaddr), ioaddr);
3990 outb(ETC_CMD, (ioaddr + EREG_DATA));
3991 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
3992 outb((SRER + portp->uartaddr), ioaddr);
3993 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
3994 (ioaddr + EREG_DATA));
3995 return(1);
3996 } else if (portp->brklen > 1) {
3997 outb((TDR + portp->uartaddr), ioaddr);
3998 outb(ETC_CMD, (ioaddr + EREG_DATA));
3999 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
4000 portp->brklen = -1;
4001 return(1);
4002 } else {
4003 outb((COR2 + portp->uartaddr), ioaddr);
4004 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
4005 (ioaddr + EREG_DATA));
4006 portp->brklen = 0;
4008 return(0);
4011 /*****************************************************************************/
4014 * Transmit interrupt handler. This has gotta be fast! Handling TX
4015 * chars is pretty simple, stuff as many as possible from the TX buffer
4016 * into the cd1400 FIFO. Must also handle TX breaks here, since they
4017 * are embedded as commands in the data stream. Oh no, had to use a goto!
4018 * This could be optimized more, will do when I get time...
4019 * In practice it is possible that interrupts are enabled but that the
4020 * port has been hung up. Need to handle not having any TX buffer here,
4021 * this is done by using the side effect that head and tail will also
4022 * be NULL if the buffer has been freed.
4025 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
4027 stlport_t *portp;
4028 int len, stlen;
4029 char *head, *tail;
4030 unsigned char ioack, srer;
4032 #if DEBUG
4033 printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
4034 #endif
4036 ioack = inb(ioaddr + EREG_TXACK);
4037 if (((ioack & panelp->ackmask) != 0) ||
4038 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
4039 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
4040 return;
4042 portp = panelp->ports[(ioack >> 3)];
4045 * Unfortunately we need to handle breaks in the data stream, since
4046 * this is the only way to generate them on the cd1400. Do it now if
4047 * a break is to be sent.
4049 if (portp->brklen != 0)
4050 if (stl_cd1400breakisr(portp, ioaddr))
4051 goto stl_txalldone;
4053 head = portp->tx.head;
4054 tail = portp->tx.tail;
4055 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4056 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4057 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4058 set_bit(ASYI_TXLOW, &portp->istate);
4059 schedule_work(&portp->tqueue);
4062 if (len == 0) {
4063 outb((SRER + portp->uartaddr), ioaddr);
4064 srer = inb(ioaddr + EREG_DATA);
4065 if (srer & SRER_TXDATA) {
4066 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
4067 } else {
4068 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
4069 clear_bit(ASYI_TXBUSY, &portp->istate);
4071 outb(srer, (ioaddr + EREG_DATA));
4072 } else {
4073 len = MIN(len, CD1400_TXFIFOSIZE);
4074 portp->stats.txtotal += len;
4075 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4076 outb((TDR + portp->uartaddr), ioaddr);
4077 outsb((ioaddr + EREG_DATA), tail, stlen);
4078 len -= stlen;
4079 tail += stlen;
4080 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4081 tail = portp->tx.buf;
4082 if (len > 0) {
4083 outsb((ioaddr + EREG_DATA), tail, len);
4084 tail += len;
4086 portp->tx.tail = tail;
4089 stl_txalldone:
4090 outb((EOSRR + portp->uartaddr), ioaddr);
4091 outb(0, (ioaddr + EREG_DATA));
4094 /*****************************************************************************/
4097 * Receive character interrupt handler. Determine if we have good chars
4098 * or bad chars and then process appropriately. Good chars are easy
4099 * just shove the lot into the RX buffer and set all status byte to 0.
4100 * If a bad RX char then process as required. This routine needs to be
4101 * fast! In practice it is possible that we get an interrupt on a port
4102 * that is closed. This can happen on hangups - since they completely
4103 * shutdown a port not in user context. Need to handle this case.
4106 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
4108 stlport_t *portp;
4109 struct tty_struct *tty;
4110 unsigned int ioack, len, buflen;
4111 unsigned char status;
4112 char ch;
4114 #if DEBUG
4115 printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
4116 #endif
4118 ioack = inb(ioaddr + EREG_RXACK);
4119 if ((ioack & panelp->ackmask) != 0) {
4120 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4121 return;
4123 portp = panelp->ports[(ioack >> 3)];
4124 tty = portp->tty;
4126 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
4127 outb((RDCR + portp->uartaddr), ioaddr);
4128 len = inb(ioaddr + EREG_DATA);
4129 if ((tty == (struct tty_struct *) NULL) ||
4130 (tty->flip.char_buf_ptr == (char *) NULL) ||
4131 ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
4132 len = MIN(len, sizeof(stl_unwanted));
4133 outb((RDSR + portp->uartaddr), ioaddr);
4134 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
4135 portp->stats.rxlost += len;
4136 portp->stats.rxtotal += len;
4137 } else {
4138 len = MIN(len, buflen);
4139 if (len > 0) {
4140 outb((RDSR + portp->uartaddr), ioaddr);
4141 insb((ioaddr + EREG_DATA), tty->flip.char_buf_ptr, len);
4142 memset(tty->flip.flag_buf_ptr, 0, len);
4143 tty->flip.flag_buf_ptr += len;
4144 tty->flip.char_buf_ptr += len;
4145 tty->flip.count += len;
4146 tty_schedule_flip(tty);
4147 portp->stats.rxtotal += len;
4150 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
4151 outb((RDSR + portp->uartaddr), ioaddr);
4152 status = inb(ioaddr + EREG_DATA);
4153 ch = inb(ioaddr + EREG_DATA);
4154 if (status & ST_PARITY)
4155 portp->stats.rxparity++;
4156 if (status & ST_FRAMING)
4157 portp->stats.rxframing++;
4158 if (status & ST_OVERRUN)
4159 portp->stats.rxoverrun++;
4160 if (status & ST_BREAK)
4161 portp->stats.rxbreaks++;
4162 if (status & ST_SCHARMASK) {
4163 if ((status & ST_SCHARMASK) == ST_SCHAR1)
4164 portp->stats.txxon++;
4165 if ((status & ST_SCHARMASK) == ST_SCHAR2)
4166 portp->stats.txxoff++;
4167 goto stl_rxalldone;
4169 if ((tty != (struct tty_struct *) NULL) &&
4170 ((portp->rxignoremsk & status) == 0)) {
4171 if (portp->rxmarkmsk & status) {
4172 if (status & ST_BREAK) {
4173 status = TTY_BREAK;
4174 if (portp->flags & ASYNC_SAK) {
4175 do_SAK(tty);
4176 BRDENABLE(portp->brdnr, portp->pagenr);
4178 } else if (status & ST_PARITY) {
4179 status = TTY_PARITY;
4180 } else if (status & ST_FRAMING) {
4181 status = TTY_FRAME;
4182 } else if(status & ST_OVERRUN) {
4183 status = TTY_OVERRUN;
4184 } else {
4185 status = 0;
4187 } else {
4188 status = 0;
4190 if (tty->flip.char_buf_ptr != (char *) NULL) {
4191 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
4192 *tty->flip.flag_buf_ptr++ = status;
4193 *tty->flip.char_buf_ptr++ = ch;
4194 tty->flip.count++;
4196 tty_schedule_flip(tty);
4199 } else {
4200 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4201 return;
4204 stl_rxalldone:
4205 outb((EOSRR + portp->uartaddr), ioaddr);
4206 outb(0, (ioaddr + EREG_DATA));
4209 /*****************************************************************************/
4212 * Modem interrupt handler. The is called when the modem signal line
4213 * (DCD) has changed state. Leave most of the work to the off-level
4214 * processing routine.
4217 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
4219 stlport_t *portp;
4220 unsigned int ioack;
4221 unsigned char misr;
4223 #if DEBUG
4224 printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp);
4225 #endif
4227 ioack = inb(ioaddr + EREG_MDACK);
4228 if (((ioack & panelp->ackmask) != 0) ||
4229 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
4230 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
4231 return;
4233 portp = panelp->ports[(ioack >> 3)];
4235 outb((MISR + portp->uartaddr), ioaddr);
4236 misr = inb(ioaddr + EREG_DATA);
4237 if (misr & MISR_DCD) {
4238 set_bit(ASYI_DCDCHANGE, &portp->istate);
4239 schedule_task(&portp->tqueue);
4240 portp->stats.modem++;
4243 outb((EOSRR + portp->uartaddr), ioaddr);
4244 outb(0, (ioaddr + EREG_DATA));
4247 /*****************************************************************************/
4248 /* SC26198 HARDWARE FUNCTIONS */
4249 /*****************************************************************************/
4252 * These functions get/set/update the registers of the sc26198 UARTs.
4253 * Access to the sc26198 registers is via an address/data io port pair.
4254 * (Maybe should make this inline...)
4257 static int stl_sc26198getreg(stlport_t *portp, int regnr)
4259 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4260 return(inb(portp->ioaddr + XP_DATA));
4263 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
4265 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4266 outb(value, (portp->ioaddr + XP_DATA));
4269 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
4271 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4272 if (inb(portp->ioaddr + XP_DATA) != value) {
4273 outb(value, (portp->ioaddr + XP_DATA));
4274 return(1);
4276 return(0);
4279 /*****************************************************************************/
4282 * Functions to get and set the sc26198 global registers.
4285 static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
4287 outb(regnr, (portp->ioaddr + XP_ADDR));
4288 return(inb(portp->ioaddr + XP_DATA));
4291 #if 0
4292 static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
4294 outb(regnr, (portp->ioaddr + XP_ADDR));
4295 outb(value, (portp->ioaddr + XP_DATA));
4297 #endif
4299 /*****************************************************************************/
4302 * Inbitialize the UARTs in a panel. We don't care what sort of board
4303 * these ports are on - since the port io registers are almost
4304 * identical when dealing with ports.
4307 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
4309 int chipmask, i;
4310 int nrchips, ioaddr;
4312 #if DEBUG
4313 printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
4314 (int) brdp, (int) panelp);
4315 #endif
4317 BRDENABLE(panelp->brdnr, panelp->pagenr);
4320 * Check that each chip is present and started up OK.
4322 chipmask = 0;
4323 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
4324 if (brdp->brdtype == BRD_ECHPCI)
4325 outb(panelp->pagenr, brdp->ioctrl);
4327 for (i = 0; (i < nrchips); i++) {
4328 ioaddr = panelp->iobase + (i * 4);
4329 outb(SCCR, (ioaddr + XP_ADDR));
4330 outb(CR_RESETALL, (ioaddr + XP_DATA));
4331 outb(TSTR, (ioaddr + XP_ADDR));
4332 if (inb(ioaddr + XP_DATA) != 0) {
4333 printk("STALLION: sc26198 not responding, "
4334 "brd=%d panel=%d chip=%d\n",
4335 panelp->brdnr, panelp->panelnr, i);
4336 continue;
4338 chipmask |= (0x1 << i);
4339 outb(GCCR, (ioaddr + XP_ADDR));
4340 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
4341 outb(WDTRCR, (ioaddr + XP_ADDR));
4342 outb(0xff, (ioaddr + XP_DATA));
4345 BRDDISABLE(panelp->brdnr);
4346 return(chipmask);
4349 /*****************************************************************************/
4352 * Initialize hardware specific port registers.
4355 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
4357 #if DEBUG
4358 printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
4359 (int) brdp, (int) panelp, (int) portp);
4360 #endif
4362 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
4363 (portp == (stlport_t *) NULL))
4364 return;
4366 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
4367 portp->uartaddr = (portp->portnr & 0x07) << 4;
4368 portp->pagenr = panelp->pagenr;
4369 portp->hwid = 0x1;
4371 BRDENABLE(portp->brdnr, portp->pagenr);
4372 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
4373 BRDDISABLE(portp->brdnr);
4376 /*****************************************************************************/
4379 * Set up the sc26198 registers for a port based on the termios port
4380 * settings.
4383 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4385 stlbrd_t *brdp;
4386 unsigned long flags;
4387 unsigned int baudrate;
4388 unsigned char mr0, mr1, mr2, clk;
4389 unsigned char imron, imroff, iopr, ipr;
4391 mr0 = 0;
4392 mr1 = 0;
4393 mr2 = 0;
4394 clk = 0;
4395 iopr = 0;
4396 imron = 0;
4397 imroff = 0;
4399 brdp = stl_brds[portp->brdnr];
4400 if (brdp == (stlbrd_t *) NULL)
4401 return;
4404 * Set up the RX char ignore mask with those RX error types we
4405 * can ignore.
4407 portp->rxignoremsk = 0;
4408 if (tiosp->c_iflag & IGNPAR)
4409 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
4410 SR_RXOVERRUN);
4411 if (tiosp->c_iflag & IGNBRK)
4412 portp->rxignoremsk |= SR_RXBREAK;
4414 portp->rxmarkmsk = SR_RXOVERRUN;
4415 if (tiosp->c_iflag & (INPCK | PARMRK))
4416 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
4417 if (tiosp->c_iflag & BRKINT)
4418 portp->rxmarkmsk |= SR_RXBREAK;
4421 * Go through the char size, parity and stop bits and set all the
4422 * option register appropriately.
4424 switch (tiosp->c_cflag & CSIZE) {
4425 case CS5:
4426 mr1 |= MR1_CS5;
4427 break;
4428 case CS6:
4429 mr1 |= MR1_CS6;
4430 break;
4431 case CS7:
4432 mr1 |= MR1_CS7;
4433 break;
4434 default:
4435 mr1 |= MR1_CS8;
4436 break;
4439 if (tiosp->c_cflag & CSTOPB)
4440 mr2 |= MR2_STOP2;
4441 else
4442 mr2 |= MR2_STOP1;
4444 if (tiosp->c_cflag & PARENB) {
4445 if (tiosp->c_cflag & PARODD)
4446 mr1 |= (MR1_PARENB | MR1_PARODD);
4447 else
4448 mr1 |= (MR1_PARENB | MR1_PAREVEN);
4449 } else {
4450 mr1 |= MR1_PARNONE;
4453 mr1 |= MR1_ERRBLOCK;
4456 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4457 * space for hardware flow control and the like. This should be set to
4458 * VMIN.
4460 mr2 |= MR2_RXFIFOHALF;
4463 * Calculate the baud rate timers. For now we will just assume that
4464 * the input and output baud are the same. The sc26198 has a fixed
4465 * baud rate table, so only discrete baud rates possible.
4467 baudrate = tiosp->c_cflag & CBAUD;
4468 if (baudrate & CBAUDEX) {
4469 baudrate &= ~CBAUDEX;
4470 if ((baudrate < 1) || (baudrate > 4))
4471 tiosp->c_cflag &= ~CBAUDEX;
4472 else
4473 baudrate += 15;
4475 baudrate = stl_baudrates[baudrate];
4476 if ((tiosp->c_cflag & CBAUD) == B38400) {
4477 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
4478 baudrate = 57600;
4479 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
4480 baudrate = 115200;
4481 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
4482 baudrate = 230400;
4483 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
4484 baudrate = 460800;
4485 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
4486 baudrate = (portp->baud_base / portp->custom_divisor);
4488 if (baudrate > STL_SC26198MAXBAUD)
4489 baudrate = STL_SC26198MAXBAUD;
4491 if (baudrate > 0) {
4492 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
4493 if (baudrate <= sc26198_baudtable[clk])
4494 break;
4499 * Check what form of modem signaling is required and set it up.
4501 if (tiosp->c_cflag & CLOCAL) {
4502 portp->flags &= ~ASYNC_CHECK_CD;
4503 } else {
4504 iopr |= IOPR_DCDCOS;
4505 imron |= IR_IOPORT;
4506 portp->flags |= ASYNC_CHECK_CD;
4510 * Setup sc26198 enhanced modes if we can. In particular we want to
4511 * handle as much of the flow control as possible automatically. As
4512 * well as saving a few CPU cycles it will also greatly improve flow
4513 * control reliability.
4515 if (tiosp->c_iflag & IXON) {
4516 mr0 |= MR0_SWFTX | MR0_SWFT;
4517 imron |= IR_XONXOFF;
4518 } else {
4519 imroff |= IR_XONXOFF;
4521 if (tiosp->c_iflag & IXOFF)
4522 mr0 |= MR0_SWFRX;
4524 if (tiosp->c_cflag & CRTSCTS) {
4525 mr2 |= MR2_AUTOCTS;
4526 mr1 |= MR1_AUTORTS;
4530 * All sc26198 register values calculated so go through and set
4531 * them all up.
4534 #if DEBUG
4535 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4536 portp->portnr, portp->panelnr, portp->brdnr);
4537 printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4538 printk(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4539 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4540 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4541 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4542 #endif
4544 save_flags(flags);
4545 cli();
4546 BRDENABLE(portp->brdnr, portp->pagenr);
4547 stl_sc26198setreg(portp, IMR, 0);
4548 stl_sc26198updatereg(portp, MR0, mr0);
4549 stl_sc26198updatereg(portp, MR1, mr1);
4550 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4551 stl_sc26198updatereg(portp, MR2, mr2);
4552 stl_sc26198updatereg(portp, IOPIOR,
4553 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
4555 if (baudrate > 0) {
4556 stl_sc26198setreg(portp, TXCSR, clk);
4557 stl_sc26198setreg(portp, RXCSR, clk);
4560 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4561 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4563 ipr = stl_sc26198getreg(portp, IPR);
4564 if (ipr & IPR_DCD)
4565 portp->sigs &= ~TIOCM_CD;
4566 else
4567 portp->sigs |= TIOCM_CD;
4569 portp->imr = (portp->imr & ~imroff) | imron;
4570 stl_sc26198setreg(portp, IMR, portp->imr);
4571 BRDDISABLE(portp->brdnr);
4572 restore_flags(flags);
4575 /*****************************************************************************/
4578 * Set the state of the DTR and RTS signals.
4581 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
4583 unsigned char iopioron, iopioroff;
4584 unsigned long flags;
4586 #if DEBUG
4587 printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4588 (int) portp, dtr, rts);
4589 #endif
4591 iopioron = 0;
4592 iopioroff = 0;
4593 if (dtr == 0)
4594 iopioroff |= IPR_DTR;
4595 else if (dtr > 0)
4596 iopioron |= IPR_DTR;
4597 if (rts == 0)
4598 iopioroff |= IPR_RTS;
4599 else if (rts > 0)
4600 iopioron |= IPR_RTS;
4602 save_flags(flags);
4603 cli();
4604 BRDENABLE(portp->brdnr, portp->pagenr);
4605 stl_sc26198setreg(portp, IOPIOR,
4606 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4607 BRDDISABLE(portp->brdnr);
4608 restore_flags(flags);
4611 /*****************************************************************************/
4614 * Return the state of the signals.
4617 static int stl_sc26198getsignals(stlport_t *portp)
4619 unsigned char ipr;
4620 unsigned long flags;
4621 int sigs;
4623 #if DEBUG
4624 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
4625 #endif
4627 save_flags(flags);
4628 cli();
4629 BRDENABLE(portp->brdnr, portp->pagenr);
4630 ipr = stl_sc26198getreg(portp, IPR);
4631 BRDDISABLE(portp->brdnr);
4632 restore_flags(flags);
4634 sigs = 0;
4635 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4636 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4637 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4638 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4639 sigs |= TIOCM_DSR;
4640 return(sigs);
4643 /*****************************************************************************/
4646 * Enable/Disable the Transmitter and/or Receiver.
4649 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
4651 unsigned char ccr;
4652 unsigned long flags;
4654 #if DEBUG
4655 printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4656 (int) portp, rx, tx);
4657 #endif
4659 ccr = portp->crenable;
4660 if (tx == 0)
4661 ccr &= ~CR_TXENABLE;
4662 else if (tx > 0)
4663 ccr |= CR_TXENABLE;
4664 if (rx == 0)
4665 ccr &= ~CR_RXENABLE;
4666 else if (rx > 0)
4667 ccr |= CR_RXENABLE;
4669 save_flags(flags);
4670 cli();
4671 BRDENABLE(portp->brdnr, portp->pagenr);
4672 stl_sc26198setreg(portp, SCCR, ccr);
4673 BRDDISABLE(portp->brdnr);
4674 portp->crenable = ccr;
4675 restore_flags(flags);
4678 /*****************************************************************************/
4681 * Start/stop the Transmitter and/or Receiver.
4684 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
4686 unsigned char imr;
4687 unsigned long flags;
4689 #if DEBUG
4690 printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4691 (int) portp, rx, tx);
4692 #endif
4694 imr = portp->imr;
4695 if (tx == 0)
4696 imr &= ~IR_TXRDY;
4697 else if (tx == 1)
4698 imr |= IR_TXRDY;
4699 if (rx == 0)
4700 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4701 else if (rx > 0)
4702 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4704 save_flags(flags);
4705 cli();
4706 BRDENABLE(portp->brdnr, portp->pagenr);
4707 stl_sc26198setreg(portp, IMR, imr);
4708 BRDDISABLE(portp->brdnr);
4709 portp->imr = imr;
4710 if (tx > 0)
4711 set_bit(ASYI_TXBUSY, &portp->istate);
4712 restore_flags(flags);
4715 /*****************************************************************************/
4718 * Disable all interrupts from this port.
4721 static void stl_sc26198disableintrs(stlport_t *portp)
4723 unsigned long flags;
4725 #if DEBUG
4726 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
4727 #endif
4729 save_flags(flags);
4730 cli();
4731 BRDENABLE(portp->brdnr, portp->pagenr);
4732 portp->imr = 0;
4733 stl_sc26198setreg(portp, IMR, 0);
4734 BRDDISABLE(portp->brdnr);
4735 restore_flags(flags);
4738 /*****************************************************************************/
4740 static void stl_sc26198sendbreak(stlport_t *portp, int len)
4742 unsigned long flags;
4744 #if DEBUG
4745 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
4746 #endif
4748 save_flags(flags);
4749 cli();
4750 BRDENABLE(portp->brdnr, portp->pagenr);
4751 if (len == 1) {
4752 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4753 portp->stats.txbreaks++;
4754 } else {
4755 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4757 BRDDISABLE(portp->brdnr);
4758 restore_flags(flags);
4761 /*****************************************************************************/
4764 * Take flow control actions...
4767 static void stl_sc26198flowctrl(stlport_t *portp, int state)
4769 struct tty_struct *tty;
4770 unsigned long flags;
4771 unsigned char mr0;
4773 #if DEBUG
4774 printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp, state);
4775 #endif
4777 if (portp == (stlport_t *) NULL)
4778 return;
4779 tty = portp->tty;
4780 if (tty == (struct tty_struct *) NULL)
4781 return;
4783 save_flags(flags);
4784 cli();
4785 BRDENABLE(portp->brdnr, portp->pagenr);
4787 if (state) {
4788 if (tty->termios->c_iflag & IXOFF) {
4789 mr0 = stl_sc26198getreg(portp, MR0);
4790 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4791 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4792 mr0 |= MR0_SWFRX;
4793 portp->stats.rxxon++;
4794 stl_sc26198wait(portp);
4795 stl_sc26198setreg(portp, MR0, mr0);
4798 * Question: should we return RTS to what it was before? It may
4799 * have been set by an ioctl... Suppose not, since if you have
4800 * hardware flow control set then it is pretty silly to go and
4801 * set the RTS line by hand.
4803 if (tty->termios->c_cflag & CRTSCTS) {
4804 stl_sc26198setreg(portp, MR1,
4805 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4806 stl_sc26198setreg(portp, IOPIOR,
4807 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4808 portp->stats.rxrtson++;
4810 } else {
4811 if (tty->termios->c_iflag & IXOFF) {
4812 mr0 = stl_sc26198getreg(portp, MR0);
4813 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4814 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4815 mr0 &= ~MR0_SWFRX;
4816 portp->stats.rxxoff++;
4817 stl_sc26198wait(portp);
4818 stl_sc26198setreg(portp, MR0, mr0);
4820 if (tty->termios->c_cflag & CRTSCTS) {
4821 stl_sc26198setreg(portp, MR1,
4822 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4823 stl_sc26198setreg(portp, IOPIOR,
4824 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4825 portp->stats.rxrtsoff++;
4829 BRDDISABLE(portp->brdnr);
4830 restore_flags(flags);
4833 /*****************************************************************************/
4836 * Send a flow control character.
4839 static void stl_sc26198sendflow(stlport_t *portp, int state)
4841 struct tty_struct *tty;
4842 unsigned long flags;
4843 unsigned char mr0;
4845 #if DEBUG
4846 printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp, state);
4847 #endif
4849 if (portp == (stlport_t *) NULL)
4850 return;
4851 tty = portp->tty;
4852 if (tty == (struct tty_struct *) NULL)
4853 return;
4855 save_flags(flags);
4856 cli();
4857 BRDENABLE(portp->brdnr, portp->pagenr);
4858 if (state) {
4859 mr0 = stl_sc26198getreg(portp, MR0);
4860 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4861 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4862 mr0 |= MR0_SWFRX;
4863 portp->stats.rxxon++;
4864 stl_sc26198wait(portp);
4865 stl_sc26198setreg(portp, MR0, mr0);
4866 } else {
4867 mr0 = stl_sc26198getreg(portp, MR0);
4868 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4869 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4870 mr0 &= ~MR0_SWFRX;
4871 portp->stats.rxxoff++;
4872 stl_sc26198wait(portp);
4873 stl_sc26198setreg(portp, MR0, mr0);
4875 BRDDISABLE(portp->brdnr);
4876 restore_flags(flags);
4879 /*****************************************************************************/
4881 static void stl_sc26198flush(stlport_t *portp)
4883 unsigned long flags;
4885 #if DEBUG
4886 printk("stl_sc26198flush(portp=%x)\n", (int) portp);
4887 #endif
4889 if (portp == (stlport_t *) NULL)
4890 return;
4892 save_flags(flags);
4893 cli();
4894 BRDENABLE(portp->brdnr, portp->pagenr);
4895 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4896 stl_sc26198setreg(portp, SCCR, portp->crenable);
4897 BRDDISABLE(portp->brdnr);
4898 portp->tx.tail = portp->tx.head;
4899 restore_flags(flags);
4902 /*****************************************************************************/
4905 * Return the current state of data flow on this port. This is only
4906 * really interresting when determining if data has fully completed
4907 * transmission or not... The sc26198 interrupt scheme cannot
4908 * determine when all data has actually drained, so we need to
4909 * check the port statusy register to be sure.
4912 static int stl_sc26198datastate(stlport_t *portp)
4914 unsigned long flags;
4915 unsigned char sr;
4917 #if DEBUG
4918 printk("stl_sc26198datastate(portp=%x)\n", (int) portp);
4919 #endif
4921 if (portp == (stlport_t *) NULL)
4922 return(0);
4923 if (test_bit(ASYI_TXBUSY, &portp->istate))
4924 return(1);
4926 save_flags(flags);
4927 cli();
4928 BRDENABLE(portp->brdnr, portp->pagenr);
4929 sr = stl_sc26198getreg(portp, SR);
4930 BRDDISABLE(portp->brdnr);
4931 restore_flags(flags);
4933 return((sr & SR_TXEMPTY) ? 0 : 1);
4936 /*****************************************************************************/
4939 * Delay for a small amount of time, to give the sc26198 a chance
4940 * to process a command...
4943 static void stl_sc26198wait(stlport_t *portp)
4945 int i;
4947 #if DEBUG
4948 printk("stl_sc26198wait(portp=%x)\n", (int) portp);
4949 #endif
4951 if (portp == (stlport_t *) NULL)
4952 return;
4954 for (i = 0; (i < 20); i++)
4955 stl_sc26198getglobreg(portp, TSTR);
4958 /*****************************************************************************/
4961 * If we are TX flow controlled and in IXANY mode then we may
4962 * need to unflow control here. We gotta do this because of the
4963 * automatic flow control modes of the sc26198.
4966 static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty)
4968 unsigned char mr0;
4970 mr0 = stl_sc26198getreg(portp, MR0);
4971 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4972 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4973 stl_sc26198wait(portp);
4974 stl_sc26198setreg(portp, MR0, mr0);
4975 clear_bit(ASYI_TXFLOWED, &portp->istate);
4978 /*****************************************************************************/
4981 * Interrupt service routine for sc26198 panels.
4984 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4986 stlport_t *portp;
4987 unsigned int iack;
4990 * Work around bug in sc26198 chip... Cannot have A6 address
4991 * line of UART high, else iack will be returned as 0.
4993 outb(0, (iobase + 1));
4995 iack = inb(iobase + XP_IACK);
4996 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4998 if (iack & IVR_RXDATA)
4999 stl_sc26198rxisr(portp, iack);
5000 else if (iack & IVR_TXDATA)
5001 stl_sc26198txisr(portp);
5002 else
5003 stl_sc26198otherisr(portp, iack);
5006 /*****************************************************************************/
5009 * Transmit interrupt handler. This has gotta be fast! Handling TX
5010 * chars is pretty simple, stuff as many as possible from the TX buffer
5011 * into the sc26198 FIFO.
5012 * In practice it is possible that interrupts are enabled but that the
5013 * port has been hung up. Need to handle not having any TX buffer here,
5014 * this is done by using the side effect that head and tail will also
5015 * be NULL if the buffer has been freed.
5018 static void stl_sc26198txisr(stlport_t *portp)
5020 unsigned int ioaddr;
5021 unsigned char mr0;
5022 int len, stlen;
5023 char *head, *tail;
5025 #if DEBUG
5026 printk("stl_sc26198txisr(portp=%x)\n", (int) portp);
5027 #endif
5029 ioaddr = portp->ioaddr;
5030 head = portp->tx.head;
5031 tail = portp->tx.tail;
5032 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
5033 if ((len == 0) || ((len < STL_TXBUFLOW) &&
5034 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
5035 set_bit(ASYI_TXLOW, &portp->istate);
5036 schedule_task(&portp->tqueue);
5039 if (len == 0) {
5040 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
5041 mr0 = inb(ioaddr + XP_DATA);
5042 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
5043 portp->imr &= ~IR_TXRDY;
5044 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
5045 outb(portp->imr, (ioaddr + XP_DATA));
5046 clear_bit(ASYI_TXBUSY, &portp->istate);
5047 } else {
5048 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
5049 outb(mr0, (ioaddr + XP_DATA));
5051 } else {
5052 len = MIN(len, SC26198_TXFIFOSIZE);
5053 portp->stats.txtotal += len;
5054 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
5055 outb(GTXFIFO, (ioaddr + XP_ADDR));
5056 outsb((ioaddr + XP_DATA), tail, stlen);
5057 len -= stlen;
5058 tail += stlen;
5059 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
5060 tail = portp->tx.buf;
5061 if (len > 0) {
5062 outsb((ioaddr + XP_DATA), tail, len);
5063 tail += len;
5065 portp->tx.tail = tail;
5069 /*****************************************************************************/
5072 * Receive character interrupt handler. Determine if we have good chars
5073 * or bad chars and then process appropriately. Good chars are easy
5074 * just shove the lot into the RX buffer and set all status byte to 0.
5075 * If a bad RX char then process as required. This routine needs to be
5076 * fast! In practice it is possible that we get an interrupt on a port
5077 * that is closed. This can happen on hangups - since they completely
5078 * shutdown a port not in user context. Need to handle this case.
5081 static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
5083 struct tty_struct *tty;
5084 unsigned int len, buflen, ioaddr;
5086 #if DEBUG
5087 printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
5088 #endif
5090 tty = portp->tty;
5091 ioaddr = portp->ioaddr;
5092 outb(GIBCR, (ioaddr + XP_ADDR));
5093 len = inb(ioaddr + XP_DATA) + 1;
5095 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
5096 if ((tty == (struct tty_struct *) NULL) ||
5097 (tty->flip.char_buf_ptr == (char *) NULL) ||
5098 ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
5099 len = MIN(len, sizeof(stl_unwanted));
5100 outb(GRXFIFO, (ioaddr + XP_ADDR));
5101 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
5102 portp->stats.rxlost += len;
5103 portp->stats.rxtotal += len;
5104 } else {
5105 len = MIN(len, buflen);
5106 if (len > 0) {
5107 outb(GRXFIFO, (ioaddr + XP_ADDR));
5108 insb((ioaddr + XP_DATA), tty->flip.char_buf_ptr, len);
5109 memset(tty->flip.flag_buf_ptr, 0, len);
5110 tty->flip.flag_buf_ptr += len;
5111 tty->flip.char_buf_ptr += len;
5112 tty->flip.count += len;
5113 tty_schedule_flip(tty);
5114 portp->stats.rxtotal += len;
5117 } else {
5118 stl_sc26198rxbadchars(portp);
5122 * If we are TX flow controlled and in IXANY mode then we may need
5123 * to unflow control here. We gotta do this because of the automatic
5124 * flow control modes of the sc26198.
5126 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
5127 if ((tty != (struct tty_struct *) NULL) &&
5128 (tty->termios != (struct termios *) NULL) &&
5129 (tty->termios->c_iflag & IXANY)) {
5130 stl_sc26198txunflow(portp, tty);
5135 /*****************************************************************************/
5138 * Process an RX bad character.
5141 static inline void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch)
5143 struct tty_struct *tty;
5144 unsigned int ioaddr;
5146 tty = portp->tty;
5147 ioaddr = portp->ioaddr;
5149 if (status & SR_RXPARITY)
5150 portp->stats.rxparity++;
5151 if (status & SR_RXFRAMING)
5152 portp->stats.rxframing++;
5153 if (status & SR_RXOVERRUN)
5154 portp->stats.rxoverrun++;
5155 if (status & SR_RXBREAK)
5156 portp->stats.rxbreaks++;
5158 if ((tty != (struct tty_struct *) NULL) &&
5159 ((portp->rxignoremsk & status) == 0)) {
5160 if (portp->rxmarkmsk & status) {
5161 if (status & SR_RXBREAK) {
5162 status = TTY_BREAK;
5163 if (portp->flags & ASYNC_SAK) {
5164 do_SAK(tty);
5165 BRDENABLE(portp->brdnr, portp->pagenr);
5167 } else if (status & SR_RXPARITY) {
5168 status = TTY_PARITY;
5169 } else if (status & SR_RXFRAMING) {
5170 status = TTY_FRAME;
5171 } else if(status & SR_RXOVERRUN) {
5172 status = TTY_OVERRUN;
5173 } else {
5174 status = 0;
5176 } else {
5177 status = 0;
5180 if (tty->flip.char_buf_ptr != (char *) NULL) {
5181 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
5182 *tty->flip.flag_buf_ptr++ = status;
5183 *tty->flip.char_buf_ptr++ = ch;
5184 tty->flip.count++;
5186 tty_schedule_flip(tty);
5189 if (status == 0)
5190 portp->stats.rxtotal++;
5194 /*****************************************************************************/
5197 * Process all characters in the RX FIFO of the UART. Check all char
5198 * status bytes as well, and process as required. We need to check
5199 * all bytes in the FIFO, in case some more enter the FIFO while we
5200 * are here. To get the exact character error type we need to switch
5201 * into CHAR error mode (that is why we need to make sure we empty
5202 * the FIFO).
5205 static void stl_sc26198rxbadchars(stlport_t *portp)
5207 unsigned char status, mr1;
5208 char ch;
5211 * To get the precise error type for each character we must switch
5212 * back into CHAR error mode.
5214 mr1 = stl_sc26198getreg(portp, MR1);
5215 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
5217 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
5218 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
5219 ch = stl_sc26198getreg(portp, RXFIFO);
5220 stl_sc26198rxbadch(portp, status, ch);
5224 * To get correct interrupt class we must switch back into BLOCK
5225 * error mode.
5227 stl_sc26198setreg(portp, MR1, mr1);
5230 /*****************************************************************************/
5233 * Other interrupt handler. This includes modem signals, flow
5234 * control actions, etc. Most stuff is left to off-level interrupt
5235 * processing time.
5238 static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
5240 unsigned char cir, ipr, xisr;
5242 #if DEBUG
5243 printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
5244 #endif
5246 cir = stl_sc26198getglobreg(portp, CIR);
5248 switch (cir & CIR_SUBTYPEMASK) {
5249 case CIR_SUBCOS:
5250 ipr = stl_sc26198getreg(portp, IPR);
5251 if (ipr & IPR_DCDCHANGE) {
5252 set_bit(ASYI_DCDCHANGE, &portp->istate);
5253 schedule_task(&portp->tqueue);
5254 portp->stats.modem++;
5256 break;
5257 case CIR_SUBXONXOFF:
5258 xisr = stl_sc26198getreg(portp, XISR);
5259 if (xisr & XISR_RXXONGOT) {
5260 set_bit(ASYI_TXFLOWED, &portp->istate);
5261 portp->stats.txxoff++;
5263 if (xisr & XISR_RXXOFFGOT) {
5264 clear_bit(ASYI_TXFLOWED, &portp->istate);
5265 portp->stats.txxon++;
5267 break;
5268 case CIR_SUBBREAK:
5269 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
5270 stl_sc26198rxbadchars(portp);
5271 break;
5272 default:
5273 break;
5277 /*****************************************************************************/