Import 2.1.118
[davej-history.git] / drivers / char / stallion.c
blob81d389cad51669388710626016ad52245838bc1e
1 /*****************************************************************************/
3 /*
4 * stallion.c -- stallion multiport serial driver.
6 * Copyright (C) 1996-1998 Stallion Technologies (support@stallion.oz.au).
7 * Copyright (C) 1994-1996 Greg Ungerer (gerg@stallion.oz.au).
9 * This code is loosely based on the Linux serial driver, written by
10 * Linus Torvalds, Theodore T'so and others.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /*****************************************************************************/
29 #include <linux/module.h>
30 #include <linux/errno.h>
31 #include <linux/sched.h>
32 #include <linux/wait.h>
33 #include <linux/interrupt.h>
34 #include <linux/termios.h>
35 #include <linux/fcntl.h>
36 #include <linux/tty_driver.h>
37 #include <linux/tty.h>
38 #include <linux/tty_flip.h>
39 #include <linux/serial.h>
40 #include <linux/cd1400.h>
41 #include <linux/sc26198.h>
42 #include <linux/comstats.h>
43 #include <linux/stallion.h>
44 #include <linux/string.h>
45 #include <linux/malloc.h>
46 #include <linux/ioport.h>
47 #include <linux/config.h>
48 #include <linux/init.h>
49 #include <linux/smp_lock.h>
51 #include <asm/system.h>
52 #include <asm/io.h>
53 #include <asm/uaccess.h>
55 #ifdef CONFIG_PCI
56 #include <linux/pci.h>
57 #endif
59 /*****************************************************************************/
62 * Define different board types. Use the standard Stallion "assigned"
63 * board numbers. Boards supported in this driver are abbreviated as
64 * EIO = EasyIO and ECH = EasyConnection 8/32.
66 #define BRD_EASYIO 20
67 #define BRD_ECH 21
68 #define BRD_ECHMC 22
69 #define BRD_ECHPCI 26
70 #define BRD_ECH64PCI 27
71 #define BRD_EASYIOPCI 28
74 * Define a configuration structure to hold the board configuration.
75 * Need to set this up in the code (for now) with the boards that are
76 * to be configured into the system. This is what needs to be modified
77 * when adding/removing/modifying boards. Each line entry in the
78 * stl_brdconf[] array is a board. Each line contains io/irq/memory
79 * ranges for that board (as well as what type of board it is).
80 * Some examples:
81 * { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 }
82 * This line would configure an EasyIO board (4 or 8, no difference),
83 * at io address 2a0 and irq 10.
84 * Another example:
85 * { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
86 * This line will configure an EasyConnection 8/32 board at primary io
87 * address 2a8, secondary io address 280 and irq 12.
88 * Enter as many lines into this array as you want (only the first 4
89 * will actually be used!). Any combination of EasyIO and EasyConnection
90 * boards can be specified. EasyConnection 8/32 boards can share their
91 * secondary io addresses between each other.
93 * NOTE: there is no need to put any entries in this table for PCI
94 * boards. They will be found automatically by the driver - provided
95 * PCI BIOS32 support is compiled into the kernel.
98 typedef struct {
99 int brdtype;
100 int ioaddr1;
101 int ioaddr2;
102 unsigned long memaddr;
103 int irq;
104 int irqtype;
105 } stlconf_t;
107 static stlconf_t stl_brdconf[] = {
108 { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
111 static int stl_nrbrds = sizeof(stl_brdconf) / sizeof(stlconf_t);
113 /*****************************************************************************/
116 * Define some important driver characteristics. Device major numbers
117 * allocated as per Linux Device Registry.
119 #ifndef STL_SIOMEMMAJOR
120 #define STL_SIOMEMMAJOR 28
121 #endif
122 #ifndef STL_SERIALMAJOR
123 #define STL_SERIALMAJOR 24
124 #endif
125 #ifndef STL_CALLOUTMAJOR
126 #define STL_CALLOUTMAJOR 25
127 #endif
129 #define STL_DRVTYPSERIAL 1
130 #define STL_DRVTYPCALLOUT 2
133 * Set the TX buffer size. Bigger is better, but we don't want
134 * to chew too much memory with buffers!
136 #define STL_TXBUFLOW 512
137 #define STL_TXBUFSIZE 4096
139 /*****************************************************************************/
142 * Define our local driver identity first. Set up stuff to deal with
143 * all the local structures required by a serial tty driver.
145 static char *stl_drvtitle = "Stallion Multiport Serial Driver";
146 static char *stl_drvname = "stallion";
147 static char *stl_drvversion = "5.4.6";
148 static char *stl_serialname = "ttyE";
149 static char *stl_calloutname = "cue";
151 static struct tty_driver stl_serial;
152 static struct tty_driver stl_callout;
153 static struct tty_struct *stl_ttys[STL_MAXDEVS];
154 static struct termios *stl_termios[STL_MAXDEVS];
155 static struct termios *stl_termioslocked[STL_MAXDEVS];
156 static int stl_refcount = 0;
159 * We will need to allocate a temporary write buffer for chars that
160 * come direct from user space. The problem is that a copy from user
161 * space might cause a page fault (typically on a system that is
162 * swapping!). All ports will share one buffer - since if the system
163 * is already swapping a shared buffer won't make things any worse.
165 static char *stl_tmpwritebuf;
166 static struct semaphore stl_tmpwritesem = MUTEX;
169 * Define a local default termios struct. All ports will be created
170 * with this termios initially. Basically all it defines is a raw port
171 * at 9600, 8 data bits, 1 stop bit.
173 static struct termios stl_deftermios = {
176 (B9600 | CS8 | CREAD | HUPCL | CLOCAL),
179 INIT_C_CC
183 * Define global stats structures. Not used often, and can be
184 * re-used for each stats call.
186 static comstats_t stl_comstats;
187 static combrd_t stl_brdstats;
188 static stlbrd_t stl_dummybrd;
189 static stlport_t stl_dummyport;
192 * Define global place to put buffer overflow characters.
194 static char stl_unwanted[SC26198_RXFIFOSIZE];
197 * Keep track of what interrupts we have requested for us.
198 * We don't need to request an interrupt twice if it is being
199 * shared with another Stallion board.
201 static int stl_gotintrs[STL_MAXBRDS];
202 static int stl_numintrs = 0;
204 /*****************************************************************************/
206 static stlbrd_t *stl_brds[STL_MAXBRDS];
209 * Per board state flags. Used with the state field of the board struct.
210 * Not really much here!
212 #define BRD_FOUND 0x1
215 * Define the port structure istate flags. These set of flags are
216 * modified at interrupt time - so setting and reseting them needs
217 * to be atomic. Use the bit clear/setting routines for this.
219 #define ASYI_TXBUSY 1
220 #define ASYI_TXLOW 2
221 #define ASYI_DCDCHANGE 3
222 #define ASYI_TXFLOWED 4
225 * Define an array of board names as printable strings. Handy for
226 * referencing boards when printing trace and stuff.
228 static char *stl_brdnames[] = {
229 (char *) NULL,
230 (char *) NULL,
231 (char *) NULL,
232 (char *) NULL,
233 (char *) NULL,
234 (char *) NULL,
235 (char *) NULL,
236 (char *) NULL,
237 (char *) NULL,
238 (char *) NULL,
239 (char *) NULL,
240 (char *) NULL,
241 (char *) NULL,
242 (char *) NULL,
243 (char *) NULL,
244 (char *) NULL,
245 (char *) NULL,
246 (char *) NULL,
247 (char *) NULL,
248 (char *) NULL,
249 "EasyIO",
250 "EC8/32-AT",
251 "EC8/32-MC",
252 (char *) NULL,
253 (char *) NULL,
254 (char *) NULL,
255 "EC8/32-PCI",
256 "EC8/64-PCI",
257 "EasyIO-PCI",
260 /*****************************************************************************/
263 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
264 * to the directly accessible io ports of these boards (not the uarts -
265 * they are in cd1400.h and sc26198.h).
267 #define EIO_8PORTRS 0x04
268 #define EIO_4PORTRS 0x05
269 #define EIO_8PORTDI 0x00
270 #define EIO_8PORTM 0x06
271 #define EIO_MK3 0x03
272 #define EIO_IDBITMASK 0x07
274 #define EIO_BRDMASK 0xf0
275 #define ID_BRD4 0x10
276 #define ID_BRD8 0x20
277 #define ID_BRD16 0x30
279 #define EIO_INTRPEND 0x08
280 #define EIO_INTEDGE 0x00
281 #define EIO_INTLEVEL 0x08
282 #define EIO_0WS 0x10
284 #define ECH_ID 0xa0
285 #define ECH_IDBITMASK 0xe0
286 #define ECH_BRDENABLE 0x08
287 #define ECH_BRDDISABLE 0x00
288 #define ECH_INTENABLE 0x01
289 #define ECH_INTDISABLE 0x00
290 #define ECH_INTLEVEL 0x02
291 #define ECH_INTEDGE 0x00
292 #define ECH_INTRPEND 0x01
293 #define ECH_BRDRESET 0x01
295 #define ECHMC_INTENABLE 0x01
296 #define ECHMC_BRDRESET 0x02
298 #define ECH_PNLSTATUS 2
299 #define ECH_PNL16PORT 0x20
300 #define ECH_PNLIDMASK 0x07
301 #define ECH_PNLXPID 0x40
302 #define ECH_PNLINTRPEND 0x80
304 #define ECH_ADDR2MASK 0x1e0
307 * Define the vector mapping bits for the programmable interrupt board
308 * hardware. These bits encode the interrupt for the board to use - it
309 * is software selectable (except the EIO-8M).
311 static unsigned char stl_vecmap[] = {
312 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
313 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
317 * Set up enable and disable macros for the ECH boards. They require
318 * the secondary io address space to be activated and deactivated.
319 * This way all ECH boards can share their secondary io region.
320 * If this is an ECH-PCI board then also need to set the page pointer
321 * to point to the correct page.
323 #define BRDENABLE(brdnr,pagenr) \
324 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
325 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
326 stl_brds[(brdnr)]->ioctrl); \
327 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
328 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
330 #define BRDDISABLE(brdnr) \
331 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
332 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
333 stl_brds[(brdnr)]->ioctrl);
335 #define STL_CD1400MAXBAUD 230400
336 #define STL_SC26198MAXBAUD 460800
338 #define STL_BAUDBASE 115200
339 #define STL_CLOSEDELAY (5 * HZ / 10)
341 /*****************************************************************************/
343 #ifdef CONFIG_PCI
346 * Define the Stallion PCI vendor and device IDs.
348 #ifndef PCI_VENDOR_ID_STALLION
349 #define PCI_VENDOR_ID_STALLION 0x124d
350 #endif
351 #ifndef PCI_DEVICE_ID_ECHPCI832
352 #define PCI_DEVICE_ID_ECHPCI832 0x0000
353 #endif
354 #ifndef PCI_DEVICE_ID_ECHPCI864
355 #define PCI_DEVICE_ID_ECHPCI864 0x0002
356 #endif
357 #ifndef PCI_DEVICE_ID_EIOPCI
358 #define PCI_DEVICE_ID_EIOPCI 0x0003
359 #endif
362 * Define structure to hold all Stallion PCI boards.
364 typedef struct stlpcibrd {
365 unsigned short vendid;
366 unsigned short devid;
367 int brdtype;
368 } stlpcibrd_t;
370 static stlpcibrd_t stl_pcibrds[] = {
371 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI864, BRD_ECH64PCI },
372 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_EIOPCI, BRD_EASYIOPCI },
373 { PCI_VENDOR_ID_STALLION, PCI_DEVICE_ID_ECHPCI832, BRD_ECHPCI },
374 { PCI_VENDOR_ID_NS, PCI_DEVICE_ID_NS_87410, BRD_ECHPCI },
377 static int stl_nrpcibrds = sizeof(stl_pcibrds) / sizeof(stlpcibrd_t);
379 #endif
381 /*****************************************************************************/
384 * Define macros to extract a brd/port number from a minor number.
386 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
387 #define MINOR2PORT(min) ((min) & 0x3f)
390 * Define a baud rate table that converts termios baud rate selector
391 * into the actual baud rate value. All baud rate calculations are
392 * based on the actual baud rate required.
394 static unsigned int stl_baudrates[] = {
395 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
396 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
400 * Define some handy local macros...
402 #ifndef MIN
403 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
404 #endif
406 /*****************************************************************************/
409 * Declare all those functions in this driver!
412 #ifdef MODULE
413 int init_module(void);
414 void cleanup_module(void);
415 #endif
417 int stl_init(void);
418 static int stl_open(struct tty_struct *tty, struct file *filp);
419 static void stl_close(struct tty_struct *tty, struct file *filp);
420 static int stl_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count);
421 static void stl_putchar(struct tty_struct *tty, unsigned char ch);
422 static void stl_flushchars(struct tty_struct *tty);
423 static int stl_writeroom(struct tty_struct *tty);
424 static int stl_charsinbuffer(struct tty_struct *tty);
425 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg);
426 static void stl_settermios(struct tty_struct *tty, struct termios *old);
427 static void stl_throttle(struct tty_struct *tty);
428 static void stl_unthrottle(struct tty_struct *tty);
429 static void stl_stop(struct tty_struct *tty);
430 static void stl_start(struct tty_struct *tty);
431 static void stl_flushbuffer(struct tty_struct *tty);
432 static void stl_breakctl(struct tty_struct *tty, int state);
433 static void stl_waituntilsent(struct tty_struct *tty, int timeout);
434 static void stl_sendxchar(struct tty_struct *tty, char ch);
435 static void stl_hangup(struct tty_struct *tty);
436 static int stl_memopen(struct inode *ip, struct file *fp);
437 static int stl_memclose(struct inode *ip, struct file *fp);
438 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg);
439 static int stl_portinfo(stlport_t *portp, int portnr, char *pos);
440 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data);
442 static int stl_brdinit(stlbrd_t *brdp);
443 static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp);
444 static int stl_mapirq(int irq, char *name);
445 static void stl_getserial(stlport_t *portp, struct serial_struct *sp);
446 static int stl_setserial(stlport_t *portp, struct serial_struct *sp);
447 static int stl_getbrdstats(combrd_t *bp);
448 static int stl_getportstats(stlport_t *portp, comstats_t *cp);
449 static int stl_clrportstats(stlport_t *portp, comstats_t *cp);
450 static int stl_getportstruct(unsigned long arg);
451 static int stl_getbrdstruct(unsigned long arg);
452 static int stl_waitcarrier(stlport_t *portp, struct file *filp);
453 static void stl_delay(int len);
454 static void stl_intr(int irq, void *dev_id, struct pt_regs *regs);
455 static void stl_eiointr(stlbrd_t *brdp);
456 static void stl_echatintr(stlbrd_t *brdp);
457 static void stl_echmcaintr(stlbrd_t *brdp);
458 static void stl_echpciintr(stlbrd_t *brdp);
459 static void stl_echpci64intr(stlbrd_t *brdp);
460 static void stl_offintr(void *private);
461 static void *stl_memalloc(int len);
462 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr);
464 static inline int stl_initbrds(void);
465 static inline int stl_initeio(stlbrd_t *brdp);
466 static inline int stl_initech(stlbrd_t *brdp);
468 #ifdef CONFIG_PCI
469 static inline int stl_findpcibrds(void);
470 static inline int stl_initpcibrd(int brdtype, struct pci_dev *dev);
471 #endif
474 * CD1400 uart specific handling functions.
476 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value);
477 static int stl_cd1400getreg(stlport_t *portp, int regnr);
478 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value);
479 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
480 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
481 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp);
482 static int stl_cd1400getsignals(stlport_t *portp);
483 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts);
484 static void stl_cd1400ccrwait(stlport_t *portp);
485 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx);
486 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx);
487 static void stl_cd1400disableintrs(stlport_t *portp);
488 static void stl_cd1400sendbreak(stlport_t *portp, int len);
489 static void stl_cd1400flowctrl(stlport_t *portp, int state);
490 static void stl_cd1400sendflow(stlport_t *portp, int state);
491 static void stl_cd1400flush(stlport_t *portp);
492 static int stl_cd1400datastate(stlport_t *portp);
493 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase);
494 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase);
495 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr);
496 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr);
497 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr);
499 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr);
502 * SC26198 uart specific handling functions.
504 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value);
505 static int stl_sc26198getreg(stlport_t *portp, int regnr);
506 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value);
507 static int stl_sc26198getglobreg(stlport_t *portp, int regnr);
508 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp);
509 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
510 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp);
511 static int stl_sc26198getsignals(stlport_t *portp);
512 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts);
513 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx);
514 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx);
515 static void stl_sc26198disableintrs(stlport_t *portp);
516 static void stl_sc26198sendbreak(stlport_t *portp, int len);
517 static void stl_sc26198flowctrl(stlport_t *portp, int state);
518 static void stl_sc26198sendflow(stlport_t *portp, int state);
519 static void stl_sc26198flush(stlport_t *portp);
520 static int stl_sc26198datastate(stlport_t *portp);
521 static void stl_sc26198wait(stlport_t *portp);
522 static void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty);
523 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase);
524 static void stl_sc26198txisr(stlport_t *port);
525 static void stl_sc26198rxisr(stlport_t *port, unsigned int iack);
526 static void stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch);
527 static void stl_sc26198rxbadchars(stlport_t *portp);
528 static void stl_sc26198otherisr(stlport_t *port, unsigned int iack);
530 /*****************************************************************************/
533 * Generic UART support structure.
535 typedef struct uart {
536 int (*panelinit)(stlbrd_t *brdp, stlpanel_t *panelp);
537 void (*portinit)(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp);
538 void (*setport)(stlport_t *portp, struct termios *tiosp);
539 int (*getsignals)(stlport_t *portp);
540 void (*setsignals)(stlport_t *portp, int dtr, int rts);
541 void (*enablerxtx)(stlport_t *portp, int rx, int tx);
542 void (*startrxtx)(stlport_t *portp, int rx, int tx);
543 void (*disableintrs)(stlport_t *portp);
544 void (*sendbreak)(stlport_t *portp, int len);
545 void (*flowctrl)(stlport_t *portp, int state);
546 void (*sendflow)(stlport_t *portp, int state);
547 void (*flush)(stlport_t *portp);
548 int (*datastate)(stlport_t *portp);
549 void (*intr)(stlpanel_t *panelp, unsigned int iobase);
550 } uart_t;
553 * Define some macros to make calling these functions nice and clean.
555 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
556 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
557 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
558 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
559 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
560 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
561 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
562 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
563 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
564 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
565 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
566 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
567 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
569 /*****************************************************************************/
572 * CD1400 UART specific data initialization.
574 static uart_t stl_cd1400uart = {
575 stl_cd1400panelinit,
576 stl_cd1400portinit,
577 stl_cd1400setport,
578 stl_cd1400getsignals,
579 stl_cd1400setsignals,
580 stl_cd1400enablerxtx,
581 stl_cd1400startrxtx,
582 stl_cd1400disableintrs,
583 stl_cd1400sendbreak,
584 stl_cd1400flowctrl,
585 stl_cd1400sendflow,
586 stl_cd1400flush,
587 stl_cd1400datastate,
588 stl_cd1400eiointr
592 * Define the offsets within the register bank of a cd1400 based panel.
593 * These io address offsets are common to the EasyIO board as well.
595 #define EREG_ADDR 0
596 #define EREG_DATA 4
597 #define EREG_RXACK 5
598 #define EREG_TXACK 6
599 #define EREG_MDACK 7
601 #define EREG_BANKSIZE 8
603 #define CD1400_CLK 25000000
604 #define CD1400_CLK8M 20000000
607 * Define the cd1400 baud rate clocks. These are used when calculating
608 * what clock and divisor to use for the required baud rate. Also
609 * define the maximum baud rate allowed, and the default base baud.
611 static int stl_cd1400clkdivs[] = {
612 CD1400_CLK0, CD1400_CLK1, CD1400_CLK2, CD1400_CLK3, CD1400_CLK4
615 /*****************************************************************************/
618 * SC26198 UART specific data initization.
620 static uart_t stl_sc26198uart = {
621 stl_sc26198panelinit,
622 stl_sc26198portinit,
623 stl_sc26198setport,
624 stl_sc26198getsignals,
625 stl_sc26198setsignals,
626 stl_sc26198enablerxtx,
627 stl_sc26198startrxtx,
628 stl_sc26198disableintrs,
629 stl_sc26198sendbreak,
630 stl_sc26198flowctrl,
631 stl_sc26198sendflow,
632 stl_sc26198flush,
633 stl_sc26198datastate,
634 stl_sc26198intr
638 * Define the offsets within the register bank of a sc26198 based panel.
640 #define XP_DATA 0
641 #define XP_ADDR 1
642 #define XP_MODID 2
643 #define XP_STATUS 2
644 #define XP_IACK 3
646 #define XP_BANKSIZE 4
649 * Define the sc26198 baud rate table. Offsets within the table
650 * represent the actual baud rate selector of sc26198 registers.
652 static unsigned int sc26198_baudtable[] = {
653 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
654 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
655 230400, 460800, 921600
658 #define SC26198_NRBAUDS (sizeof(sc26198_baudtable) / sizeof(unsigned int))
660 /*****************************************************************************/
663 * Define the driver info for a user level control device. Used mainly
664 * to get at port stats - only not using the port device itself.
666 static struct file_operations stl_fsiomem = {
667 NULL,
668 NULL,
669 NULL,
670 NULL,
671 NULL,
672 stl_memioctl,
673 NULL,
674 stl_memopen,
675 NULL, /* flush */
676 stl_memclose,
677 NULL
680 /*****************************************************************************/
682 #ifdef MODULE
685 * Loadable module initialization stuff.
688 int init_module()
690 unsigned long flags;
692 #if DEBUG
693 printk("init_module()\n");
694 #endif
696 save_flags(flags);
697 cli();
698 stl_init();
699 restore_flags(flags);
701 return(0);
704 /*****************************************************************************/
706 void cleanup_module()
708 stlbrd_t *brdp;
709 stlpanel_t *panelp;
710 stlport_t *portp;
711 unsigned long flags;
712 int i, j, k;
714 #if DEBUG
715 printk("cleanup_module()\n");
716 #endif
718 printk(KERN_INFO "Unloading %s: version %s\n", stl_drvtitle,
719 stl_drvversion);
721 save_flags(flags);
722 cli();
725 * Free up all allocated resources used by the ports. This includes
726 * memory and interrupts. As part of this process we will also do
727 * a hangup on every open port - to try to flush out any processes
728 * hanging onto ports.
730 i = tty_unregister_driver(&stl_serial);
731 j = tty_unregister_driver(&stl_callout);
732 if (i || j) {
733 printk("STALLION: failed to un-register tty driver, "
734 "errno=%d,%d\n", -i, -j);
735 restore_flags(flags);
736 return;
738 if ((i = unregister_chrdev(STL_SIOMEMMAJOR, "staliomem")))
739 printk("STALLION: failed to un-register serial memory device, "
740 "errno=%d\n", -i);
742 if (stl_tmpwritebuf != (char *) NULL)
743 kfree_s(stl_tmpwritebuf, STL_TXBUFSIZE);
745 for (i = 0; (i < stl_nrbrds); i++) {
746 brdp = stl_brds[i];
747 for (j = 0; (j < STL_MAXPANELS); j++) {
748 panelp = brdp->panels[j];
749 if (panelp == (stlpanel_t *) NULL)
750 continue;
751 for (k = 0; (k < STL_PORTSPERPANEL); k++) {
752 portp = panelp->ports[k];
753 if (portp == (stlport_t *) NULL)
754 continue;
755 if (portp->tty != (struct tty_struct *) NULL)
756 stl_hangup(portp->tty);
757 if (portp->tx.buf != (char *) NULL)
758 kfree_s(portp->tx.buf, STL_TXBUFSIZE);
759 kfree_s(portp, sizeof(stlport_t));
761 kfree_s(panelp, sizeof(stlpanel_t));
764 release_region(brdp->ioaddr1, brdp->iosize1);
765 if (brdp->iosize2 > 0)
766 release_region(brdp->ioaddr2, brdp->iosize2);
768 kfree_s(brdp, sizeof(stlbrd_t));
769 stl_brds[i] = (stlbrd_t *) NULL;
772 for (i = 0; (i < stl_numintrs); i++)
773 free_irq(stl_gotintrs[i], NULL);
775 restore_flags(flags);
778 #endif
780 /*****************************************************************************/
783 * Local driver kernel memory allocation routine.
786 static void *stl_memalloc(int len)
788 return((void *) kmalloc(len, GFP_KERNEL));
791 /*****************************************************************************/
793 static int stl_open(struct tty_struct *tty, struct file *filp)
795 stlport_t *portp;
796 stlbrd_t *brdp;
797 unsigned int minordev;
798 int brdnr, panelnr, portnr, rc;
800 #if DEBUG
801 printk("stl_open(tty=%x,filp=%x): device=%x\n", (int) tty,
802 (int) filp, tty->device);
803 #endif
805 minordev = MINOR(tty->device);
806 brdnr = MINOR2BRD(minordev);
807 if (brdnr >= stl_nrbrds)
808 return(-ENODEV);
809 brdp = stl_brds[brdnr];
810 if (brdp == (stlbrd_t *) NULL)
811 return(-ENODEV);
812 minordev = MINOR2PORT(minordev);
813 for (portnr = -1, panelnr = 0; (panelnr < STL_MAXPANELS); panelnr++) {
814 if (brdp->panels[panelnr] == (stlpanel_t *) NULL)
815 break;
816 if (minordev < brdp->panels[panelnr]->nrports) {
817 portnr = minordev;
818 break;
820 minordev -= brdp->panels[panelnr]->nrports;
822 if (portnr < 0)
823 return(-ENODEV);
825 portp = brdp->panels[panelnr]->ports[portnr];
826 if (portp == (stlport_t *) NULL)
827 return(-ENODEV);
829 MOD_INC_USE_COUNT;
832 * On the first open of the device setup the port hardware, and
833 * initialize the per port data structure.
835 portp->tty = tty;
836 tty->driver_data = portp;
837 portp->refcount++;
839 if ((portp->flags & ASYNC_INITIALIZED) == 0) {
840 if (portp->tx.buf == (char *) NULL) {
841 portp->tx.buf = (char *) stl_memalloc(STL_TXBUFSIZE);
842 if (portp->tx.buf == (char *) NULL)
843 return(-ENOMEM);
844 portp->tx.head = portp->tx.buf;
845 portp->tx.tail = portp->tx.buf;
847 stl_setport(portp, tty->termios);
848 portp->sigs = stl_getsignals(portp);
849 stl_setsignals(portp, 1, 1);
850 stl_enablerxtx(portp, 1, 1);
851 stl_startrxtx(portp, 1, 0);
852 clear_bit(TTY_IO_ERROR, &tty->flags);
853 portp->flags |= ASYNC_INITIALIZED;
857 * Check if this port is in the middle of closing. If so then wait
858 * until it is closed then return error status, based on flag settings.
859 * The sleep here does not need interrupt protection since the wakeup
860 * for it is done with the same context.
862 if (portp->flags & ASYNC_CLOSING) {
863 interruptible_sleep_on(&portp->close_wait);
864 if (portp->flags & ASYNC_HUP_NOTIFY)
865 return(-EAGAIN);
866 return(-ERESTARTSYS);
870 * Based on type of open being done check if it can overlap with any
871 * previous opens still in effect. If we are a normal serial device
872 * then also we might have to wait for carrier.
874 if (tty->driver.subtype == STL_DRVTYPCALLOUT) {
875 if (portp->flags & ASYNC_NORMAL_ACTIVE)
876 return(-EBUSY);
877 if (portp->flags & ASYNC_CALLOUT_ACTIVE) {
878 if ((portp->flags & ASYNC_SESSION_LOCKOUT) &&
879 (portp->session != current->session))
880 return(-EBUSY);
881 if ((portp->flags & ASYNC_PGRP_LOCKOUT) &&
882 (portp->pgrp != current->pgrp))
883 return(-EBUSY);
885 portp->flags |= ASYNC_CALLOUT_ACTIVE;
886 } else {
887 if (filp->f_flags & O_NONBLOCK) {
888 if (portp->flags & ASYNC_CALLOUT_ACTIVE)
889 return(-EBUSY);
890 } else {
891 if ((rc = stl_waitcarrier(portp, filp)) != 0)
892 return(rc);
894 portp->flags |= ASYNC_NORMAL_ACTIVE;
897 if ((portp->refcount == 1) && (portp->flags & ASYNC_SPLIT_TERMIOS)) {
898 if (tty->driver.subtype == STL_DRVTYPSERIAL)
899 *tty->termios = portp->normaltermios;
900 else
901 *tty->termios = portp->callouttermios;
902 stl_setport(portp, tty->termios);
905 portp->session = current->session;
906 portp->pgrp = current->pgrp;
907 return(0);
910 /*****************************************************************************/
913 * Possibly need to wait for carrier (DCD signal) to come high. Say
914 * maybe because if we are clocal then we don't need to wait...
917 static int stl_waitcarrier(stlport_t *portp, struct file *filp)
919 unsigned long flags;
920 int rc, doclocal;
922 #if DEBUG
923 printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp, (int) filp);
924 #endif
926 rc = 0;
927 doclocal = 0;
929 if (portp->flags & ASYNC_CALLOUT_ACTIVE) {
930 if (portp->normaltermios.c_cflag & CLOCAL)
931 doclocal++;
932 } else {
933 if (portp->tty->termios->c_cflag & CLOCAL)
934 doclocal++;
937 save_flags(flags);
938 cli();
939 portp->openwaitcnt++;
940 if (! tty_hung_up_p(filp))
941 portp->refcount--;
943 for (;;) {
944 if ((portp->flags & ASYNC_CALLOUT_ACTIVE) == 0)
945 stl_setsignals(portp, 1, 1);
946 if (tty_hung_up_p(filp) ||
947 ((portp->flags & ASYNC_INITIALIZED) == 0)) {
948 if (portp->flags & ASYNC_HUP_NOTIFY)
949 rc = -EBUSY;
950 else
951 rc = -ERESTARTSYS;
952 break;
954 if (((portp->flags & ASYNC_CALLOUT_ACTIVE) == 0) &&
955 ((portp->flags & ASYNC_CLOSING) == 0) &&
956 (doclocal || (portp->sigs & TIOCM_CD))) {
957 break;
959 if (signal_pending(current)) {
960 rc = -ERESTARTSYS;
961 break;
963 interruptible_sleep_on(&portp->open_wait);
966 if (! tty_hung_up_p(filp))
967 portp->refcount++;
968 portp->openwaitcnt--;
969 restore_flags(flags);
971 return(rc);
974 /*****************************************************************************/
976 static void stl_close(struct tty_struct *tty, struct file *filp)
978 stlport_t *portp;
979 unsigned long flags;
981 #if DEBUG
982 printk("stl_close(tty=%x,filp=%x)\n", (int) tty, (int) filp);
983 #endif
985 portp = tty->driver_data;
986 if (portp == (stlport_t *) NULL)
987 return;
989 save_flags(flags);
990 cli();
991 if (tty_hung_up_p(filp)) {
992 MOD_DEC_USE_COUNT;
993 restore_flags(flags);
994 return;
996 if ((tty->count == 1) && (portp->refcount != 1))
997 portp->refcount = 1;
998 if (portp->refcount-- > 1) {
999 MOD_DEC_USE_COUNT;
1000 restore_flags(flags);
1001 return;
1004 portp->refcount = 0;
1005 portp->flags |= ASYNC_CLOSING;
1007 if (portp->flags & ASYNC_NORMAL_ACTIVE)
1008 portp->normaltermios = *tty->termios;
1009 if (portp->flags & ASYNC_CALLOUT_ACTIVE)
1010 portp->callouttermios = *tty->termios;
1013 * May want to wait for any data to drain before closing. The BUSY
1014 * flag keeps track of whether we are still sending or not - it is
1015 * very accurate for the cd1400, not quite so for the sc26198.
1016 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1018 tty->closing = 1;
1019 if (portp->closing_wait != ASYNC_CLOSING_WAIT_NONE)
1020 tty_wait_until_sent(tty, portp->closing_wait);
1021 stl_waituntilsent(tty, (HZ / 2));
1023 portp->flags &= ~ASYNC_INITIALIZED;
1024 stl_disableintrs(portp);
1025 if (tty->termios->c_cflag & HUPCL)
1026 stl_setsignals(portp, 0, 0);
1027 stl_enablerxtx(portp, 0, 0);
1028 stl_flushbuffer(tty);
1029 portp->istate = 0;
1030 if (portp->tx.buf != (char *) NULL) {
1031 kfree_s(portp->tx.buf, STL_TXBUFSIZE);
1032 portp->tx.buf = (char *) NULL;
1033 portp->tx.head = (char *) NULL;
1034 portp->tx.tail = (char *) NULL;
1036 set_bit(TTY_IO_ERROR, &tty->flags);
1037 if (tty->ldisc.flush_buffer)
1038 (tty->ldisc.flush_buffer)(tty);
1040 tty->closing = 0;
1041 portp->tty = (struct tty_struct *) NULL;
1043 if (portp->openwaitcnt) {
1044 if (portp->close_delay)
1045 stl_delay(portp->close_delay);
1046 wake_up_interruptible(&portp->open_wait);
1049 portp->flags &= ~(ASYNC_CALLOUT_ACTIVE | ASYNC_NORMAL_ACTIVE |
1050 ASYNC_CLOSING);
1051 wake_up_interruptible(&portp->close_wait);
1052 MOD_DEC_USE_COUNT;
1053 restore_flags(flags);
1056 /*****************************************************************************/
1059 * Wait for a specified delay period, this is not a busy-loop. It will
1060 * give up the processor while waiting. Unfortunately this has some
1061 * rather intimate knowledge of the process management stuff.
1064 static void stl_delay(int len)
1066 #if DEBUG
1067 printk("stl_delay(len=%d)\n", len);
1068 #endif
1069 if (len > 0) {
1070 current->state = TASK_INTERRUPTIBLE;
1071 current->timeout = jiffies + len;
1072 schedule();
1073 current->state = TASK_RUNNING;
1077 /*****************************************************************************/
1080 * Write routine. Take data and stuff it in to the TX ring queue.
1081 * If transmit interrupts are not running then start them.
1084 static int stl_write(struct tty_struct *tty, int from_user, const unsigned char *buf, int count)
1086 stlport_t *portp;
1087 unsigned int len, stlen;
1088 unsigned char *chbuf;
1089 char *head, *tail;
1091 #if DEBUG
1092 printk("stl_write(tty=%x,from_user=%d,buf=%x,count=%d)\n",
1093 (int) tty, from_user, (int) buf, count);
1094 #endif
1096 if ((tty == (struct tty_struct *) NULL) ||
1097 (stl_tmpwritebuf == (char *) NULL))
1098 return(0);
1099 portp = tty->driver_data;
1100 if (portp == (stlport_t *) NULL)
1101 return(0);
1102 if (portp->tx.buf == (char *) NULL)
1103 return(0);
1106 * If copying direct from user space we must cater for page faults,
1107 * causing us to "sleep" here for a while. To handle this copy in all
1108 * the data we need now, into a local buffer. Then when we got it all
1109 * copy it into the TX buffer.
1111 chbuf = (unsigned char *) buf;
1112 if (from_user) {
1113 head = portp->tx.head;
1114 tail = portp->tx.tail;
1115 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) :
1116 (tail - head - 1);
1117 count = MIN(len, count);
1119 down(&stl_tmpwritesem);
1120 copy_from_user(stl_tmpwritebuf, chbuf, count);
1121 up(&stl_tmpwritesem);
1122 chbuf = &stl_tmpwritebuf[0];
1125 head = portp->tx.head;
1126 tail = portp->tx.tail;
1127 if (head >= tail) {
1128 len = STL_TXBUFSIZE - (head - tail) - 1;
1129 stlen = STL_TXBUFSIZE - (head - portp->tx.buf);
1130 } else {
1131 len = tail - head - 1;
1132 stlen = len;
1135 len = MIN(len, count);
1136 count = 0;
1137 while (len > 0) {
1138 stlen = MIN(len, stlen);
1139 memcpy(head, chbuf, stlen);
1140 len -= stlen;
1141 chbuf += stlen;
1142 count += stlen;
1143 head += stlen;
1144 if (head >= (portp->tx.buf + STL_TXBUFSIZE)) {
1145 head = portp->tx.buf;
1146 stlen = tail - head;
1149 portp->tx.head = head;
1151 clear_bit(ASYI_TXLOW, &portp->istate);
1152 stl_startrxtx(portp, -1, 1);
1154 return(count);
1157 /*****************************************************************************/
1159 static void stl_putchar(struct tty_struct *tty, unsigned char ch)
1161 stlport_t *portp;
1162 unsigned int len;
1163 char *head, *tail;
1165 #if DEBUG
1166 printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty, (int) ch);
1167 #endif
1169 if (tty == (struct tty_struct *) NULL)
1170 return;
1171 portp = tty->driver_data;
1172 if (portp == (stlport_t *) NULL)
1173 return;
1174 if (portp->tx.buf == (char *) NULL)
1175 return;
1177 head = portp->tx.head;
1178 tail = portp->tx.tail;
1180 len = (head >= tail) ? (STL_TXBUFSIZE - (head - tail)) : (tail - head);
1181 len--;
1183 if (len > 0) {
1184 *head++ = ch;
1185 if (head >= (portp->tx.buf + STL_TXBUFSIZE))
1186 head = portp->tx.buf;
1188 portp->tx.head = head;
1191 /*****************************************************************************/
1194 * If there are any characters in the buffer then make sure that TX
1195 * interrupts are on and get'em out. Normally used after the putchar
1196 * routine has been called.
1199 static void stl_flushchars(struct tty_struct *tty)
1201 stlport_t *portp;
1203 #if DEBUG
1204 printk("stl_flushchars(tty=%x)\n", (int) tty);
1205 #endif
1207 if (tty == (struct tty_struct *) NULL)
1208 return;
1209 portp = tty->driver_data;
1210 if (portp == (stlport_t *) NULL)
1211 return;
1212 if (portp->tx.buf == (char *) NULL)
1213 return;
1215 #if 0
1216 if (tty->stopped || tty->hw_stopped ||
1217 (portp->tx.head == portp->tx.tail))
1218 return;
1219 #endif
1220 stl_startrxtx(portp, -1, 1);
1223 /*****************************************************************************/
1225 static int stl_writeroom(struct tty_struct *tty)
1227 stlport_t *portp;
1228 char *head, *tail;
1230 #if DEBUG
1231 printk("stl_writeroom(tty=%x)\n", (int) tty);
1232 #endif
1234 if (tty == (struct tty_struct *) NULL)
1235 return(0);
1236 portp = tty->driver_data;
1237 if (portp == (stlport_t *) NULL)
1238 return(0);
1239 if (portp->tx.buf == (char *) NULL)
1240 return(0);
1242 head = portp->tx.head;
1243 tail = portp->tx.tail;
1244 return((head >= tail) ? (STL_TXBUFSIZE - (head - tail) - 1) : (tail - head - 1));
1247 /*****************************************************************************/
1250 * Return number of chars in the TX buffer. Normally we would just
1251 * calculate the number of chars in the buffer and return that, but if
1252 * the buffer is empty and TX interrupts are still on then we return
1253 * that the buffer still has 1 char in it. This way whoever called us
1254 * will not think that ALL chars have drained - since the UART still
1255 * must have some chars in it (we are busy after all).
1258 static int stl_charsinbuffer(struct tty_struct *tty)
1260 stlport_t *portp;
1261 unsigned int size;
1262 char *head, *tail;
1264 #if DEBUG
1265 printk("stl_charsinbuffer(tty=%x)\n", (int) tty);
1266 #endif
1268 if (tty == (struct tty_struct *) NULL)
1269 return(0);
1270 portp = tty->driver_data;
1271 if (portp == (stlport_t *) NULL)
1272 return(0);
1273 if (portp->tx.buf == (char *) NULL)
1274 return(0);
1276 head = portp->tx.head;
1277 tail = portp->tx.tail;
1278 size = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
1279 if ((size == 0) && test_bit(ASYI_TXBUSY, &portp->istate))
1280 size = 1;
1281 return(size);
1284 /*****************************************************************************/
1287 * Generate the serial struct info.
1290 static void stl_getserial(stlport_t *portp, struct serial_struct *sp)
1292 struct serial_struct sio;
1293 stlbrd_t *brdp;
1295 #if DEBUG
1296 printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1297 #endif
1299 memset(&sio, 0, sizeof(struct serial_struct));
1300 sio.line = portp->portnr;
1301 sio.port = portp->ioaddr;
1302 sio.flags = portp->flags;
1303 sio.baud_base = portp->baud_base;
1304 sio.close_delay = portp->close_delay;
1305 sio.closing_wait = portp->closing_wait;
1306 sio.custom_divisor = portp->custom_divisor;
1307 sio.hub6 = 0;
1308 if (portp->uartp == &stl_cd1400uart) {
1309 sio.type = PORT_CIRRUS;
1310 sio.xmit_fifo_size = CD1400_TXFIFOSIZE;
1311 } else {
1312 sio.type = PORT_UNKNOWN;
1313 sio.xmit_fifo_size = SC26198_TXFIFOSIZE;
1316 brdp = stl_brds[portp->brdnr];
1317 if (brdp != (stlbrd_t *) NULL)
1318 sio.irq = brdp->irq;
1320 copy_to_user(sp, &sio, sizeof(struct serial_struct));
1323 /*****************************************************************************/
1326 * Set port according to the serial struct info.
1327 * At this point we do not do any auto-configure stuff, so we will
1328 * just quietly ignore any requests to change irq, etc.
1331 static int stl_setserial(stlport_t *portp, struct serial_struct *sp)
1333 struct serial_struct sio;
1335 #if DEBUG
1336 printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp, (int) sp);
1337 #endif
1339 copy_from_user(&sio, sp, sizeof(struct serial_struct));
1340 if (!capable(CAP_SYS_ADMIN)) {
1341 if ((sio.baud_base != portp->baud_base) ||
1342 (sio.close_delay != portp->close_delay) ||
1343 ((sio.flags & ~ASYNC_USR_MASK) !=
1344 (portp->flags & ~ASYNC_USR_MASK)))
1345 return(-EPERM);
1348 portp->flags = (portp->flags & ~ASYNC_USR_MASK) |
1349 (sio.flags & ASYNC_USR_MASK);
1350 portp->baud_base = sio.baud_base;
1351 portp->close_delay = sio.close_delay;
1352 portp->closing_wait = sio.closing_wait;
1353 portp->custom_divisor = sio.custom_divisor;
1354 stl_setport(portp, portp->tty->termios);
1355 return(0);
1358 /*****************************************************************************/
1360 static int stl_ioctl(struct tty_struct *tty, struct file *file, unsigned int cmd, unsigned long arg)
1362 stlport_t *portp;
1363 unsigned int ival;
1364 int rc;
1366 #if DEBUG
1367 printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
1368 (int) tty, (int) file, cmd, (int) arg);
1369 #endif
1371 if (tty == (struct tty_struct *) NULL)
1372 return(-ENODEV);
1373 portp = tty->driver_data;
1374 if (portp == (stlport_t *) NULL)
1375 return(-ENODEV);
1377 if ((cmd != TIOCGSERIAL) && (cmd != TIOCSSERIAL) &&
1378 (cmd != COM_GETPORTSTATS) && (cmd != COM_CLRPORTSTATS)) {
1379 if (tty->flags & (1 << TTY_IO_ERROR))
1380 return(-EIO);
1383 rc = 0;
1385 switch (cmd) {
1386 case TIOCGSOFTCAR:
1387 rc = put_user(((tty->termios->c_cflag & CLOCAL) ? 1 : 0),
1388 (unsigned int *) arg);
1389 break;
1390 case TIOCSSOFTCAR:
1391 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1392 sizeof(int))) == 0) {
1393 get_user(ival, (unsigned int *) arg);
1394 tty->termios->c_cflag =
1395 (tty->termios->c_cflag & ~CLOCAL) |
1396 (ival ? CLOCAL : 0);
1398 break;
1399 case TIOCMGET:
1400 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1401 sizeof(unsigned int))) == 0) {
1402 ival = stl_getsignals(portp);
1403 put_user(ival, (unsigned int *) arg);
1405 break;
1406 case TIOCMBIS:
1407 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1408 sizeof(unsigned int))) == 0) {
1409 get_user(ival, (unsigned int *) arg);
1410 stl_setsignals(portp, ((ival & TIOCM_DTR) ? 1 : -1),
1411 ((ival & TIOCM_RTS) ? 1 : -1));
1413 break;
1414 case TIOCMBIC:
1415 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1416 sizeof(unsigned int))) == 0) {
1417 get_user(ival, (unsigned int *) arg);
1418 stl_setsignals(portp, ((ival & TIOCM_DTR) ? 0 : -1),
1419 ((ival & TIOCM_RTS) ? 0 : -1));
1421 break;
1422 case TIOCMSET:
1423 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1424 sizeof(unsigned int))) == 0) {
1425 get_user(ival, (unsigned int *) arg);
1426 stl_setsignals(portp, ((ival & TIOCM_DTR) ? 1 : 0),
1427 ((ival & TIOCM_RTS) ? 1 : 0));
1429 break;
1430 case TIOCGSERIAL:
1431 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1432 sizeof(struct serial_struct))) == 0)
1433 stl_getserial(portp, (struct serial_struct *) arg);
1434 break;
1435 case TIOCSSERIAL:
1436 if ((rc = verify_area(VERIFY_READ, (void *) arg,
1437 sizeof(struct serial_struct))) == 0)
1438 rc = stl_setserial(portp, (struct serial_struct *) arg);
1439 break;
1440 case COM_GETPORTSTATS:
1441 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1442 sizeof(comstats_t))) == 0)
1443 rc = stl_getportstats(portp, (comstats_t *) arg);
1444 break;
1445 case COM_CLRPORTSTATS:
1446 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
1447 sizeof(comstats_t))) == 0)
1448 rc = stl_clrportstats(portp, (comstats_t *) arg);
1449 break;
1450 case TIOCSERCONFIG:
1451 case TIOCSERGWILD:
1452 case TIOCSERSWILD:
1453 case TIOCSERGETLSR:
1454 case TIOCSERGSTRUCT:
1455 case TIOCSERGETMULTI:
1456 case TIOCSERSETMULTI:
1457 default:
1458 rc = -ENOIOCTLCMD;
1459 break;
1462 return(rc);
1465 /*****************************************************************************/
1467 static void stl_settermios(struct tty_struct *tty, struct termios *old)
1469 stlport_t *portp;
1470 struct termios *tiosp;
1472 #if DEBUG
1473 printk("stl_settermios(tty=%x,old=%x)\n", (int) tty, (int) old);
1474 #endif
1476 if (tty == (struct tty_struct *) NULL)
1477 return;
1478 portp = tty->driver_data;
1479 if (portp == (stlport_t *) NULL)
1480 return;
1482 tiosp = tty->termios;
1483 if ((tiosp->c_cflag == old->c_cflag) &&
1484 (tiosp->c_iflag == old->c_iflag))
1485 return;
1487 stl_setport(portp, tiosp);
1488 stl_setsignals(portp, ((tiosp->c_cflag & (CBAUD & ~CBAUDEX)) ? 1 : 0),
1489 -1);
1490 if ((old->c_cflag & CRTSCTS) && ((tiosp->c_cflag & CRTSCTS) == 0)) {
1491 tty->hw_stopped = 0;
1492 stl_start(tty);
1494 if (((old->c_cflag & CLOCAL) == 0) && (tiosp->c_cflag & CLOCAL))
1495 wake_up_interruptible(&portp->open_wait);
1498 /*****************************************************************************/
1501 * Attempt to flow control who ever is sending us data. Based on termios
1502 * settings use software or/and hardware flow control.
1505 static void stl_throttle(struct tty_struct *tty)
1507 stlport_t *portp;
1509 #if DEBUG
1510 printk("stl_throttle(tty=%x)\n", (int) tty);
1511 #endif
1513 if (tty == (struct tty_struct *) NULL)
1514 return;
1515 portp = tty->driver_data;
1516 if (portp == (stlport_t *) NULL)
1517 return;
1518 stl_flowctrl(portp, 0);
1521 /*****************************************************************************/
1524 * Unflow control the device sending us data...
1527 static void stl_unthrottle(struct tty_struct *tty)
1529 stlport_t *portp;
1531 #if DEBUG
1532 printk("stl_unthrottle(tty=%x)\n", (int) tty);
1533 #endif
1535 if (tty == (struct tty_struct *) NULL)
1536 return;
1537 portp = tty->driver_data;
1538 if (portp == (stlport_t *) NULL)
1539 return;
1540 stl_flowctrl(portp, 1);
1543 /*****************************************************************************/
1546 * Stop the transmitter. Basically to do this we will just turn TX
1547 * interrupts off.
1550 static void stl_stop(struct tty_struct *tty)
1552 stlport_t *portp;
1554 #if DEBUG
1555 printk("stl_stop(tty=%x)\n", (int) tty);
1556 #endif
1558 if (tty == (struct tty_struct *) NULL)
1559 return;
1560 portp = tty->driver_data;
1561 if (portp == (stlport_t *) NULL)
1562 return;
1563 stl_startrxtx(portp, -1, 0);
1566 /*****************************************************************************/
1569 * Start the transmitter again. Just turn TX interrupts back on.
1572 static void stl_start(struct tty_struct *tty)
1574 stlport_t *portp;
1576 #if DEBUG
1577 printk("stl_start(tty=%x)\n", (int) tty);
1578 #endif
1580 if (tty == (struct tty_struct *) NULL)
1581 return;
1582 portp = tty->driver_data;
1583 if (portp == (stlport_t *) NULL)
1584 return;
1585 stl_startrxtx(portp, -1, 1);
1588 /*****************************************************************************/
1591 * Hangup this port. This is pretty much like closing the port, only
1592 * a little more brutal. No waiting for data to drain. Shutdown the
1593 * port and maybe drop signals.
1596 static void stl_hangup(struct tty_struct *tty)
1598 stlport_t *portp;
1600 #if DEBUG
1601 printk("stl_hangup(tty=%x)\n", (int) tty);
1602 #endif
1604 if (tty == (struct tty_struct *) NULL)
1605 return;
1606 portp = tty->driver_data;
1607 if (portp == (stlport_t *) NULL)
1608 return;
1610 portp->flags &= ~ASYNC_INITIALIZED;
1611 stl_disableintrs(portp);
1612 if (tty->termios->c_cflag & HUPCL)
1613 stl_setsignals(portp, 0, 0);
1614 stl_enablerxtx(portp, 0, 0);
1615 stl_flushbuffer(tty);
1616 portp->istate = 0;
1617 set_bit(TTY_IO_ERROR, &tty->flags);
1618 if (portp->tx.buf != (char *) NULL) {
1619 kfree_s(portp->tx.buf, STL_TXBUFSIZE);
1620 portp->tx.buf = (char *) NULL;
1621 portp->tx.head = (char *) NULL;
1622 portp->tx.tail = (char *) NULL;
1624 portp->tty = (struct tty_struct *) NULL;
1625 portp->flags &= ~(ASYNC_NORMAL_ACTIVE | ASYNC_CALLOUT_ACTIVE);
1626 portp->refcount = 0;
1627 wake_up_interruptible(&portp->open_wait);
1630 /*****************************************************************************/
1632 static void stl_flushbuffer(struct tty_struct *tty)
1634 stlport_t *portp;
1636 #if DEBUG
1637 printk("stl_flushbuffer(tty=%x)\n", (int) tty);
1638 #endif
1640 if (tty == (struct tty_struct *) NULL)
1641 return;
1642 portp = tty->driver_data;
1643 if (portp == (stlport_t *) NULL)
1644 return;
1646 stl_flush(portp);
1647 wake_up_interruptible(&tty->write_wait);
1648 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
1649 tty->ldisc.write_wakeup)
1650 (tty->ldisc.write_wakeup)(tty);
1653 /*****************************************************************************/
1655 static void stl_breakctl(struct tty_struct *tty, int state)
1657 stlport_t *portp;
1659 #if DEBUG
1660 printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty, state);
1661 #endif
1663 if (tty == (struct tty_struct *) NULL)
1664 return;
1665 portp = tty->driver_data;
1666 if (portp == (stlport_t *) NULL)
1667 return;
1669 stl_sendbreak(portp, ((state == -1) ? 1 : 2));
1672 /*****************************************************************************/
1674 static void stl_waituntilsent(struct tty_struct *tty, int timeout)
1676 stlport_t *portp;
1677 unsigned long tend;
1679 #if DEBUG
1680 printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty, timeout);
1681 #endif
1683 if (tty == (struct tty_struct *) NULL)
1684 return;
1685 portp = tty->driver_data;
1686 if (portp == (stlport_t *) NULL)
1687 return;
1689 if (timeout == 0)
1690 timeout = HZ;
1691 tend = jiffies + timeout;
1693 while (stl_datastate(portp)) {
1694 if (signal_pending(current))
1695 break;
1696 stl_delay(2);
1697 if (jiffies >= tend)
1698 break;
1702 /*****************************************************************************/
1704 static void stl_sendxchar(struct tty_struct *tty, char ch)
1706 stlport_t *portp;
1708 #if DEBUG
1709 printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty, ch);
1710 #endif
1712 if (tty == (struct tty_struct *) NULL)
1713 return;
1714 portp = tty->driver_data;
1715 if (portp == (stlport_t *) NULL)
1716 return;
1718 if (ch == STOP_CHAR(tty))
1719 stl_sendflow(portp, 0);
1720 else if (ch == START_CHAR(tty))
1721 stl_sendflow(portp, 1);
1722 else
1723 stl_putchar(tty, ch);
1726 /*****************************************************************************/
1728 #define MAXLINE 80
1731 * Format info for a specified port. The line is deliberately limited
1732 * to 80 characters. (If it is too long it will be truncated, if too
1733 * short then padded with spaces).
1736 static int stl_portinfo(stlport_t *portp, int portnr, char *pos)
1738 char *sp;
1739 int sigs, cnt;
1741 sp = pos;
1742 sp += sprintf(sp, "%d: uart:%s tx:%d rx:%d",
1743 portnr, (portp->hwid == 1) ? "SC26198" : "CD1400",
1744 (int) portp->stats.txtotal, (int) portp->stats.rxtotal);
1746 if (portp->stats.rxframing)
1747 sp += sprintf(sp, " fe:%d", (int) portp->stats.rxframing);
1748 if (portp->stats.rxparity)
1749 sp += sprintf(sp, " pe:%d", (int) portp->stats.rxparity);
1750 if (portp->stats.rxbreaks)
1751 sp += sprintf(sp, " brk:%d", (int) portp->stats.rxbreaks);
1752 if (portp->stats.rxoverrun)
1753 sp += sprintf(sp, " oe:%d", (int) portp->stats.rxoverrun);
1755 sigs = stl_getsignals(portp);
1756 cnt = sprintf(sp, "%s%s%s%s%s ",
1757 (sigs & TIOCM_RTS) ? "|RTS" : "",
1758 (sigs & TIOCM_CTS) ? "|CTS" : "",
1759 (sigs & TIOCM_DTR) ? "|DTR" : "",
1760 (sigs & TIOCM_CD) ? "|DCD" : "",
1761 (sigs & TIOCM_DSR) ? "|DSR" : "");
1762 *sp = ' ';
1763 sp += cnt;
1765 for (cnt = (sp - pos); (cnt < (MAXLINE - 1)); cnt++)
1766 *sp++ = ' ';
1767 if (cnt >= MAXLINE)
1768 pos[(MAXLINE - 2)] = '+';
1769 pos[(MAXLINE - 1)] = '\n';
1771 return(MAXLINE);
1774 /*****************************************************************************/
1777 * Port info, read from the /proc file system.
1780 static int stl_readproc(char *page, char **start, off_t off, int count, int *eof, void *data)
1782 stlbrd_t *brdp;
1783 stlpanel_t *panelp;
1784 stlport_t *portp;
1785 int brdnr, panelnr, portnr, totalport;
1786 int curoff, maxoff;
1787 char *pos;
1789 #if DEBUG
1790 printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
1791 "data=%x\n", (int) page, (int) start, (int) off, count,
1792 (int) eof, (int) data);
1793 #endif
1795 pos = page;
1796 totalport = 0;
1797 curoff = 0;
1799 if (off == 0) {
1800 pos += sprintf(pos, "%s: version %s", stl_drvtitle,
1801 stl_drvversion);
1802 while (pos < (page + MAXLINE - 1))
1803 *pos++ = ' ';
1804 *pos++ = '\n';
1806 curoff = MAXLINE;
1809 * We scan through for each board, panel and port. The offset is
1810 * calculated on the fly, and irrelevant ports are skipped.
1812 for (brdnr = 0; (brdnr < stl_nrbrds); brdnr++) {
1813 brdp = stl_brds[brdnr];
1814 if (brdp == (stlbrd_t *) NULL)
1815 continue;
1816 if (brdp->state == 0)
1817 continue;
1819 maxoff = curoff + (brdp->nrports * MAXLINE);
1820 if (off >= maxoff) {
1821 curoff = maxoff;
1822 continue;
1825 totalport = brdnr * STL_MAXPORTS;
1826 for (panelnr = 0; (panelnr < brdp->nrpanels); panelnr++) {
1827 panelp = brdp->panels[panelnr];
1828 if (panelp == (stlpanel_t *) NULL)
1829 continue;
1831 maxoff = curoff + (panelp->nrports * MAXLINE);
1832 if (off >= maxoff) {
1833 curoff = maxoff;
1834 totalport += panelp->nrports;
1835 continue;
1838 for (portnr = 0; (portnr < panelp->nrports); portnr++,
1839 totalport++) {
1840 portp = panelp->ports[portnr];
1841 if (portp == (stlport_t *) NULL)
1842 continue;
1843 if (off >= (curoff += MAXLINE))
1844 continue;
1845 if ((pos - page + MAXLINE) > count)
1846 goto stl_readdone;
1847 pos += stl_portinfo(portp, totalport, pos);
1852 *eof = 1;
1854 stl_readdone:
1855 *start = page;
1856 return(pos - page);
1859 /*****************************************************************************/
1862 * All board interrupts are vectored through here first. This code then
1863 * calls off to the approrpriate board interrupt handlers.
1866 static void stl_intr(int irq, void *dev_id, struct pt_regs *regs)
1868 stlbrd_t *brdp;
1869 int i;
1871 #if DEBUG
1872 printk("stl_intr(irq=%d,regs=%x)\n", irq, (int) regs);
1873 #endif
1875 for (i = 0; (i < stl_nrbrds); i++) {
1876 if ((brdp = stl_brds[i]) == (stlbrd_t *) NULL)
1877 continue;
1878 if (brdp->state == 0)
1879 continue;
1880 (* brdp->isr)(brdp);
1884 /*****************************************************************************/
1887 * Interrupt service routine for EasyIO board types.
1890 static void stl_eiointr(stlbrd_t *brdp)
1892 stlpanel_t *panelp;
1893 unsigned int iobase;
1895 panelp = brdp->panels[0];
1896 iobase = panelp->iobase;
1897 while (inb(brdp->iostatus) & EIO_INTRPEND)
1898 (* panelp->isr)(panelp, iobase);
1901 /*****************************************************************************/
1904 * Interrupt service routine for ECH-AT board types.
1907 static void stl_echatintr(stlbrd_t *brdp)
1909 stlpanel_t *panelp;
1910 unsigned int ioaddr;
1911 int bnknr;
1913 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
1915 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1916 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1917 ioaddr = brdp->bnkstataddr[bnknr];
1918 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1919 panelp = brdp->bnk2panel[bnknr];
1920 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1925 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
1928 /*****************************************************************************/
1931 * Interrupt service routine for ECH-MCA board types.
1934 static void stl_echmcaintr(stlbrd_t *brdp)
1936 stlpanel_t *panelp;
1937 unsigned int ioaddr;
1938 int bnknr;
1940 while (inb(brdp->iostatus) & ECH_INTRPEND) {
1941 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1942 ioaddr = brdp->bnkstataddr[bnknr];
1943 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1944 panelp = brdp->bnk2panel[bnknr];
1945 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1951 /*****************************************************************************/
1954 * Interrupt service routine for ECH-PCI board types.
1957 static void stl_echpciintr(stlbrd_t *brdp)
1959 stlpanel_t *panelp;
1960 unsigned int ioaddr;
1961 int bnknr, recheck;
1963 while (1) {
1964 recheck = 0;
1965 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1966 outb(brdp->bnkpageaddr[bnknr], brdp->ioctrl);
1967 ioaddr = brdp->bnkstataddr[bnknr];
1968 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1969 panelp = brdp->bnk2panel[bnknr];
1970 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
1971 recheck++;
1974 if (! recheck)
1975 break;
1979 /*****************************************************************************/
1982 * Interrupt service routine for ECH-8/64-PCI board types.
1985 static void stl_echpci64intr(stlbrd_t *brdp)
1987 stlpanel_t *panelp;
1988 unsigned int ioaddr;
1989 int bnknr;
1991 while (inb(brdp->ioctrl) & 0x1) {
1992 for (bnknr = 0; (bnknr < brdp->nrbnks); bnknr++) {
1993 ioaddr = brdp->bnkstataddr[bnknr];
1994 if (inb(ioaddr) & ECH_PNLINTRPEND) {
1995 panelp = brdp->bnk2panel[bnknr];
1996 (* panelp->isr)(panelp, (ioaddr & 0xfffc));
2002 /*****************************************************************************/
2005 * Service an off-level request for some channel.
2007 static void stl_offintr(void *private)
2009 stlport_t *portp;
2010 struct tty_struct *tty;
2011 unsigned int oldsigs;
2013 portp = private;
2015 #if DEBUG
2016 printk("stl_offintr(portp=%x)\n", (int) portp);
2017 #endif
2019 if (portp == (stlport_t *) NULL)
2020 return;
2022 tty = portp->tty;
2023 if (tty == (struct tty_struct *) NULL)
2024 return;
2026 lock_kernel();
2027 if (test_bit(ASYI_TXLOW, &portp->istate)) {
2028 if ((tty->flags & (1 << TTY_DO_WRITE_WAKEUP)) &&
2029 tty->ldisc.write_wakeup)
2030 (tty->ldisc.write_wakeup)(tty);
2031 wake_up_interruptible(&tty->write_wait);
2033 if (test_bit(ASYI_DCDCHANGE, &portp->istate)) {
2034 clear_bit(ASYI_DCDCHANGE, &portp->istate);
2035 oldsigs = portp->sigs;
2036 portp->sigs = stl_getsignals(portp);
2037 if ((portp->sigs & TIOCM_CD) && ((oldsigs & TIOCM_CD) == 0))
2038 wake_up_interruptible(&portp->open_wait);
2039 if ((oldsigs & TIOCM_CD) && ((portp->sigs & TIOCM_CD) == 0)) {
2040 if (portp->flags & ASYNC_CHECK_CD) {
2041 if (! ((portp->flags & ASYNC_CALLOUT_ACTIVE) &&
2042 (portp->flags & ASYNC_CALLOUT_NOHUP))) {
2043 tty_hangup(tty);
2048 unlock_kernel();
2051 /*****************************************************************************/
2054 * Map in interrupt vector to this driver. Check that we don't
2055 * already have this vector mapped, we might be sharing this
2056 * interrupt across multiple boards.
2059 __initfunc(static int stl_mapirq(int irq, char *name))
2061 int rc, i;
2063 #if DEBUG
2064 printk("stl_mapirq(irq=%d,name=%s)\n", irq, name);
2065 #endif
2067 rc = 0;
2068 for (i = 0; (i < stl_numintrs); i++) {
2069 if (stl_gotintrs[i] == irq)
2070 break;
2072 if (i >= stl_numintrs) {
2073 if (request_irq(irq, stl_intr, SA_INTERRUPT, name, NULL) != 0) {
2074 printk("STALLION: failed to register interrupt "
2075 "routine for %s irq=%d\n", name, irq);
2076 rc = -ENODEV;
2077 } else {
2078 stl_gotintrs[stl_numintrs++] = irq;
2081 return(rc);
2084 /*****************************************************************************/
2087 * Initialize all the ports on a panel.
2090 __initfunc(static int stl_initports(stlbrd_t *brdp, stlpanel_t *panelp))
2092 stlport_t *portp;
2093 int chipmask, i;
2095 #if DEBUG
2096 printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
2097 #endif
2099 chipmask = stl_panelinit(brdp, panelp);
2102 * All UART's are initialized (if found!). Now go through and setup
2103 * each ports data structures.
2105 for (i = 0; (i < panelp->nrports); i++) {
2106 portp = (stlport_t *) stl_memalloc(sizeof(stlport_t));
2107 if (portp == (stlport_t *) NULL) {
2108 printk("STALLION: failed to allocate memory "
2109 "(size=%d)\n", sizeof(stlport_t));
2110 break;
2112 memset(portp, 0, sizeof(stlport_t));
2114 portp->magic = STL_PORTMAGIC;
2115 portp->portnr = i;
2116 portp->brdnr = panelp->brdnr;
2117 portp->panelnr = panelp->panelnr;
2118 portp->uartp = panelp->uartp;
2119 portp->clk = brdp->clk;
2120 portp->baud_base = STL_BAUDBASE;
2121 portp->close_delay = STL_CLOSEDELAY;
2122 portp->closing_wait = 30 * HZ;
2123 portp->normaltermios = stl_deftermios;
2124 portp->callouttermios = stl_deftermios;
2125 portp->tqueue.routine = stl_offintr;
2126 portp->tqueue.data = portp;
2127 portp->stats.brd = portp->brdnr;
2128 portp->stats.panel = portp->panelnr;
2129 portp->stats.port = portp->portnr;
2130 panelp->ports[i] = portp;
2131 stl_portinit(brdp, panelp, portp);
2134 return(0);
2137 /*****************************************************************************/
2140 * Try to find and initialize an EasyIO board.
2143 static inline int stl_initeio(stlbrd_t *brdp)
2145 stlpanel_t *panelp;
2146 unsigned int status;
2147 char *name;
2148 int rc;
2150 #if DEBUG
2151 printk("stl_initeio(brdp=%x)\n", (int) brdp);
2152 #endif
2154 brdp->ioctrl = brdp->ioaddr1 + 1;
2155 brdp->iostatus = brdp->ioaddr1 + 2;
2157 status = inb(brdp->iostatus);
2158 if ((status & EIO_IDBITMASK) == EIO_MK3)
2159 brdp->ioctrl++;
2162 * Handle board specific stuff now. The real difference is PCI
2163 * or not PCI.
2165 if (brdp->brdtype == BRD_EASYIOPCI) {
2166 brdp->iosize1 = 0x80;
2167 brdp->iosize2 = 0x80;
2168 name = "serial(EIO-PCI)";
2169 outb(0x41, (brdp->ioaddr2 + 0x4c));
2170 } else {
2171 brdp->iosize1 = 8;
2172 name = "serial(EIO)";
2173 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2174 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2175 printk("STALLION: invalid irq=%d for brd=%d\n",
2176 brdp->irq, brdp->brdnr);
2177 return(-EINVAL);
2179 outb((stl_vecmap[brdp->irq] | EIO_0WS |
2180 ((brdp->irqtype) ? EIO_INTLEVEL : EIO_INTEDGE)),
2181 brdp->ioctrl);
2184 if (check_region(brdp->ioaddr1, brdp->iosize1)) {
2185 printk("STALLION: Warning, unit %d I/O address %x conflicts "
2186 "with another device\n", brdp->brdnr, brdp->ioaddr1);
2188 if (brdp->iosize2 > 0) {
2189 if (check_region(brdp->ioaddr2, brdp->iosize2)) {
2190 printk("STALLION: Warning, unit %d I/O address %x "
2191 "conflicts with another device\n",
2192 brdp->brdnr, brdp->ioaddr2);
2197 * Everything looks OK, so let's go ahead and probe for the hardware.
2199 brdp->clk = CD1400_CLK;
2200 brdp->isr = stl_eiointr;
2202 switch (status & EIO_IDBITMASK) {
2203 case EIO_8PORTM:
2204 brdp->clk = CD1400_CLK8M;
2205 /* fall thru */
2206 case EIO_8PORTRS:
2207 case EIO_8PORTDI:
2208 brdp->nrports = 8;
2209 break;
2210 case EIO_4PORTRS:
2211 brdp->nrports = 4;
2212 break;
2213 case EIO_MK3:
2214 switch (status & EIO_BRDMASK) {
2215 case ID_BRD4:
2216 brdp->nrports = 4;
2217 break;
2218 case ID_BRD8:
2219 brdp->nrports = 8;
2220 break;
2221 case ID_BRD16:
2222 brdp->nrports = 16;
2223 break;
2224 default:
2225 return(-ENODEV);
2227 break;
2228 default:
2229 return(-ENODEV);
2233 * We have verfied that the board is actually present, so now we
2234 * can complete the setup.
2236 request_region(brdp->ioaddr1, brdp->iosize1, name);
2237 if (brdp->iosize2 > 0)
2238 request_region(brdp->ioaddr2, brdp->iosize2, name);
2240 panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
2241 if (panelp == (stlpanel_t *) NULL) {
2242 printk("STALLION: failed to allocate memory (size=%d)\n",
2243 sizeof(stlpanel_t));
2244 return(-ENOMEM);
2246 memset(panelp, 0, sizeof(stlpanel_t));
2248 panelp->magic = STL_PANELMAGIC;
2249 panelp->brdnr = brdp->brdnr;
2250 panelp->panelnr = 0;
2251 panelp->nrports = brdp->nrports;
2252 panelp->iobase = brdp->ioaddr1;
2253 panelp->hwid = status;
2254 if ((status & EIO_IDBITMASK) == EIO_MK3) {
2255 panelp->uartp = (void *) &stl_sc26198uart;
2256 panelp->isr = stl_sc26198intr;
2257 } else {
2258 panelp->uartp = (void *) &stl_cd1400uart;
2259 panelp->isr = stl_cd1400eiointr;
2262 brdp->panels[0] = panelp;
2263 brdp->nrpanels = 1;
2264 brdp->state |= BRD_FOUND;
2265 brdp->hwid = status;
2266 rc = stl_mapirq(brdp->irq, name);
2267 return(rc);
2270 /*****************************************************************************/
2273 * Try to find an ECH board and initialize it. This code is capable of
2274 * dealing with all types of ECH board.
2277 static int inline stl_initech(stlbrd_t *brdp)
2279 stlpanel_t *panelp;
2280 unsigned int status, nxtid, ioaddr, conflict;
2281 int panelnr, banknr, i;
2282 char *name;
2284 #if DEBUG
2285 printk("stl_initech(brdp=%x)\n", (int) brdp);
2286 #endif
2288 status = 0;
2289 conflict = 0;
2292 * Set up the initial board register contents for boards. This varies a
2293 * bit between the different board types. So we need to handle each
2294 * separately. Also do a check that the supplied IRQ is good.
2296 switch (brdp->brdtype) {
2298 case BRD_ECH:
2299 brdp->isr = stl_echatintr;
2300 brdp->ioctrl = brdp->ioaddr1 + 1;
2301 brdp->iostatus = brdp->ioaddr1 + 1;
2302 status = inb(brdp->iostatus);
2303 if ((status & ECH_IDBITMASK) != ECH_ID)
2304 return(-ENODEV);
2305 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2306 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2307 printk("STALLION: invalid irq=%d for brd=%d\n",
2308 brdp->irq, brdp->brdnr);
2309 return(-EINVAL);
2311 status = ((brdp->ioaddr2 & ECH_ADDR2MASK) >> 1);
2312 status |= (stl_vecmap[brdp->irq] << 1);
2313 outb((status | ECH_BRDRESET), brdp->ioaddr1);
2314 brdp->ioctrlval = ECH_INTENABLE |
2315 ((brdp->irqtype) ? ECH_INTLEVEL : ECH_INTEDGE);
2316 for (i = 0; (i < 10); i++)
2317 outb((brdp->ioctrlval | ECH_BRDENABLE), brdp->ioctrl);
2318 brdp->iosize1 = 2;
2319 brdp->iosize2 = 32;
2320 name = "serial(EC8/32)";
2321 outb(status, brdp->ioaddr1);
2322 break;
2324 case BRD_ECHMC:
2325 brdp->isr = stl_echmcaintr;
2326 brdp->ioctrl = brdp->ioaddr1 + 0x20;
2327 brdp->iostatus = brdp->ioctrl;
2328 status = inb(brdp->iostatus);
2329 if ((status & ECH_IDBITMASK) != ECH_ID)
2330 return(-ENODEV);
2331 if ((brdp->irq < 0) || (brdp->irq > 15) ||
2332 (stl_vecmap[brdp->irq] == (unsigned char) 0xff)) {
2333 printk("STALLION: invalid irq=%d for brd=%d\n",
2334 brdp->irq, brdp->brdnr);
2335 return(-EINVAL);
2337 outb(ECHMC_BRDRESET, brdp->ioctrl);
2338 outb(ECHMC_INTENABLE, brdp->ioctrl);
2339 brdp->iosize1 = 64;
2340 name = "serial(EC8/32-MC)";
2341 break;
2343 case BRD_ECHPCI:
2344 brdp->isr = stl_echpciintr;
2345 brdp->ioctrl = brdp->ioaddr1 + 2;
2346 brdp->iosize1 = 4;
2347 brdp->iosize2 = 8;
2348 name = "serial(EC8/32-PCI)";
2349 break;
2351 case BRD_ECH64PCI:
2352 brdp->isr = stl_echpci64intr;
2353 brdp->ioctrl = brdp->ioaddr2 + 0x40;
2354 outb(0x43, (brdp->ioaddr1 + 0x4c));
2355 brdp->iosize1 = 0x80;
2356 brdp->iosize2 = 0x80;
2357 name = "serial(EC8/64-PCI)";
2358 break;
2360 default:
2361 printk("STALLION: unknown board type=%d\n", brdp->brdtype);
2362 return(-EINVAL);
2363 break;
2367 * Check boards for possible IO address conflicts. We won't actually
2368 * do anything about it here, just issue a warning...
2370 conflict = check_region(brdp->ioaddr1, brdp->iosize1) ?
2371 brdp->ioaddr1 : 0;
2372 if ((conflict == 0) && (brdp->iosize2 > 0))
2373 conflict = check_region(brdp->ioaddr2, brdp->iosize2) ?
2374 brdp->ioaddr2 : 0;
2375 if (conflict) {
2376 printk("STALLION: Warning, unit %d I/O address %x conflicts "
2377 "with another device\n", brdp->brdnr, conflict);
2380 request_region(brdp->ioaddr1, brdp->iosize1, name);
2381 if (brdp->iosize2 > 0)
2382 request_region(brdp->ioaddr2, brdp->iosize2, name);
2385 * Scan through the secondary io address space looking for panels.
2386 * As we find'em allocate and initialize panel structures for each.
2388 brdp->clk = CD1400_CLK;
2389 brdp->hwid = status;
2391 ioaddr = brdp->ioaddr2;
2392 banknr = 0;
2393 panelnr = 0;
2394 nxtid = 0;
2396 for (i = 0; (i < STL_MAXPANELS); i++) {
2397 if (brdp->brdtype == BRD_ECHPCI) {
2398 outb(nxtid, brdp->ioctrl);
2399 ioaddr = brdp->ioaddr2;
2401 status = inb(ioaddr + ECH_PNLSTATUS);
2402 if ((status & ECH_PNLIDMASK) != nxtid)
2403 break;
2404 panelp = (stlpanel_t *) stl_memalloc(sizeof(stlpanel_t));
2405 if (panelp == (stlpanel_t *) NULL) {
2406 printk("STALLION: failed to allocate memory "
2407 "(size=%d)\n", sizeof(stlpanel_t));
2408 break;
2410 memset(panelp, 0, sizeof(stlpanel_t));
2411 panelp->magic = STL_PANELMAGIC;
2412 panelp->brdnr = brdp->brdnr;
2413 panelp->panelnr = panelnr;
2414 panelp->iobase = ioaddr;
2415 panelp->pagenr = nxtid;
2416 panelp->hwid = status;
2417 brdp->bnk2panel[banknr] = panelp;
2418 brdp->bnkpageaddr[banknr] = nxtid;
2419 brdp->bnkstataddr[banknr++] = ioaddr + ECH_PNLSTATUS;
2421 if (status & ECH_PNLXPID) {
2422 panelp->uartp = (void *) &stl_sc26198uart;
2423 panelp->isr = stl_sc26198intr;
2424 if (status & ECH_PNL16PORT) {
2425 panelp->nrports = 16;
2426 brdp->bnk2panel[banknr] = panelp;
2427 brdp->bnkpageaddr[banknr] = nxtid;
2428 brdp->bnkstataddr[banknr++] = ioaddr + 4 +
2429 ECH_PNLSTATUS;
2430 } else {
2431 panelp->nrports = 8;
2433 } else {
2434 panelp->uartp = (void *) &stl_cd1400uart;
2435 panelp->isr = stl_cd1400echintr;
2436 if (status & ECH_PNL16PORT) {
2437 panelp->nrports = 16;
2438 panelp->ackmask = 0x80;
2439 if (brdp->brdtype != BRD_ECHPCI)
2440 ioaddr += EREG_BANKSIZE;
2441 brdp->bnk2panel[banknr] = panelp;
2442 brdp->bnkpageaddr[banknr] = ++nxtid;
2443 brdp->bnkstataddr[banknr++] = ioaddr +
2444 ECH_PNLSTATUS;
2445 } else {
2446 panelp->nrports = 8;
2447 panelp->ackmask = 0xc0;
2451 nxtid++;
2452 ioaddr += EREG_BANKSIZE;
2453 brdp->nrports += panelp->nrports;
2454 brdp->panels[panelnr++] = panelp;
2455 if ((brdp->brdtype != BRD_ECHPCI) &&
2456 (ioaddr >= (brdp->ioaddr2 + brdp->iosize2)))
2457 break;
2460 brdp->nrpanels = panelnr;
2461 brdp->nrbnks = banknr;
2462 if (brdp->brdtype == BRD_ECH)
2463 outb((brdp->ioctrlval | ECH_BRDDISABLE), brdp->ioctrl);
2465 brdp->state |= BRD_FOUND;
2466 i = stl_mapirq(brdp->irq, name);
2467 return(i);
2470 /*****************************************************************************/
2473 * Initialize and configure the specified board.
2474 * Scan through all the boards in the configuration and see what we
2475 * can find. Handle EIO and the ECH boards a little differently here
2476 * since the initial search and setup is very different.
2479 __initfunc(static int stl_brdinit(stlbrd_t *brdp))
2481 int i;
2483 #if DEBUG
2484 printk("stl_brdinit(brdp=%x)\n", (int) brdp);
2485 #endif
2487 switch (brdp->brdtype) {
2488 case BRD_EASYIO:
2489 case BRD_EASYIOPCI:
2490 stl_initeio(brdp);
2491 break;
2492 case BRD_ECH:
2493 case BRD_ECHMC:
2494 case BRD_ECHPCI:
2495 case BRD_ECH64PCI:
2496 stl_initech(brdp);
2497 break;
2498 default:
2499 printk("STALLION: unit=%d is unknown board type=%d\n",
2500 brdp->brdnr, brdp->brdtype);
2501 return(ENODEV);
2504 stl_brds[brdp->brdnr] = brdp;
2505 if ((brdp->state & BRD_FOUND) == 0) {
2506 printk("STALLION: %s board not found, unit=%d io=%x irq=%d\n",
2507 stl_brdnames[brdp->brdtype], brdp->brdnr,
2508 brdp->ioaddr1, brdp->irq);
2509 return(ENODEV);
2512 for (i = 0; (i < STL_MAXPANELS); i++)
2513 if (brdp->panels[i] != (stlpanel_t *) NULL)
2514 stl_initports(brdp, brdp->panels[i]);
2516 printk("STALLION: %s found, unit=%d io=%x irq=%d "
2517 "nrpanels=%d nrports=%d\n", stl_brdnames[brdp->brdtype],
2518 brdp->brdnr, brdp->ioaddr1, brdp->irq, brdp->nrpanels,
2519 brdp->nrports);
2520 return(0);
2523 /*****************************************************************************/
2525 #ifdef CONFIG_PCI
2528 * We have a Stallion board. Allocate a board structure and
2529 * initialize it. Read its IO and IRQ resources from PCI
2530 * configuration space.
2533 static inline int stl_initpcibrd(int brdtype, struct pci_dev *dev)
2535 unsigned int bar[4];
2536 stlbrd_t *brdp;
2537 int i;
2538 unsigned char irq;
2540 #if DEBUG
2541 printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n",
2542 brdtype, dev->bus->number, dev->devfn);
2543 #endif
2545 brdp = (stlbrd_t *) stl_memalloc(sizeof(stlbrd_t));
2546 if (brdp == (stlbrd_t *) NULL) {
2547 printk("STALLION: failed to allocate memory (size=%d)\n",
2548 sizeof(stlbrd_t));
2549 return(-ENOMEM);
2552 memset(brdp, 0, sizeof(stlbrd_t));
2553 brdp->magic = STL_BOARDMAGIC;
2554 brdp->brdnr = stl_nrbrds++;
2555 brdp->brdtype = brdtype;
2558 * Read in all the BAR registers from this board. Different Stallion
2559 * boards use these in different ways, so we just read in the whole
2560 * lot and then figure out what is what later.
2562 for (i = 0; (i < 4); i++)
2563 bar[i] = dev->base_address[i];
2564 irq = dev->irq;
2566 #if DEBUG
2567 printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__, __LINE__,
2568 bar[0], bar[1], bar[2], bar[3], irq);
2569 #endif
2572 * We have all resources from the board, so let's setup the actual
2573 * board structure now.
2575 switch (brdtype) {
2576 case BRD_ECHPCI:
2577 brdp->ioaddr2 = (bar[0] & PCI_BASE_ADDRESS_IO_MASK);
2578 brdp->ioaddr1 = (bar[1] & PCI_BASE_ADDRESS_IO_MASK);
2579 break;
2580 case BRD_ECH64PCI:
2581 brdp->ioaddr2 = (bar[2] & PCI_BASE_ADDRESS_IO_MASK);
2582 brdp->ioaddr1 = (bar[1] & PCI_BASE_ADDRESS_IO_MASK);
2583 break;
2584 case BRD_EASYIOPCI:
2585 brdp->ioaddr1 = (bar[2] & PCI_BASE_ADDRESS_IO_MASK);
2586 brdp->ioaddr2 = (bar[1] & PCI_BASE_ADDRESS_IO_MASK);
2587 break;
2588 default:
2589 printk("STALLION: unknown PCI board type=%d\n", brdtype);
2590 break;
2593 brdp->irq = irq;
2594 stl_brdinit(brdp);
2596 return(0);
2600 /*****************************************************************************/
2603 * Find all Stallion PCI boards that might be installed. Initialize each
2604 * one as it is found.
2608 static inline int stl_findpcibrds()
2610 struct pci_dev *dev = NULL;
2611 int i, rc;
2613 #if DEBUG
2614 printk("stl_findpcibrds()\n");
2615 #endif
2617 if (! pci_present())
2618 return(0);
2620 for (i = 0; (i < stl_nrpcibrds); i++)
2621 while ((dev = pci_find_device(stl_pcibrds[i].vendid, stl_pcibrds[i].devid, dev))) {
2624 * Check that we can handle more boards...
2626 if (stl_nrbrds >= STL_MAXBRDS) {
2627 printk("STALLION: too many boards found, "
2628 "maximum supported %d\n", STL_MAXBRDS);
2629 i = stl_nrpcibrds;
2630 break;
2634 * Found a device on the PCI bus that has our vendor and
2635 * device ID. Need to check now that it is really us.
2637 if ((dev->class >> 8) == PCI_CLASS_STORAGE_IDE)
2638 continue;
2640 rc = stl_initpcibrd(stl_pcibrds[i].brdtype, dev);
2641 if (rc)
2642 return(rc);
2645 return(0);
2648 #endif
2650 /*****************************************************************************/
2653 * Scan through all the boards in the configuration and see what we
2654 * can find. Handle EIO and the ECH boards a little differently here
2655 * since the initial search and setup is too different.
2658 static inline int stl_initbrds()
2660 stlbrd_t *brdp;
2661 stlconf_t *confp;
2662 int i;
2664 #if DEBUG
2665 printk("stl_initbrds()\n");
2666 #endif
2668 if (stl_nrbrds > STL_MAXBRDS) {
2669 printk("STALLION: too many boards in configuration table, "
2670 "truncating to %d\n", STL_MAXBRDS);
2671 stl_nrbrds = STL_MAXBRDS;
2675 * Firstly scan the list of static boards configured. Allocate
2676 * resources and initialize the boards as found.
2678 for (i = 0; (i < stl_nrbrds); i++) {
2679 confp = &stl_brdconf[i];
2680 brdp = (stlbrd_t *) stl_memalloc(sizeof(stlbrd_t));
2681 if (brdp == (stlbrd_t *) NULL) {
2682 printk("STALLION: failed to allocate memory "
2683 "(size=%d)\n", sizeof(stlbrd_t));
2684 return(-ENOMEM);
2686 memset(brdp, 0, sizeof(stlbrd_t));
2688 brdp->magic = STL_BOARDMAGIC;
2689 brdp->brdnr = i;
2690 brdp->brdtype = confp->brdtype;
2691 brdp->ioaddr1 = confp->ioaddr1;
2692 brdp->ioaddr2 = confp->ioaddr2;
2693 brdp->irq = confp->irq;
2694 brdp->irqtype = confp->irqtype;
2695 stl_brdinit(brdp);
2698 #ifdef CONFIG_PCI
2700 * If the PCI BIOS support is compiled in then let's go looking for
2701 * ECH-PCI boards.
2703 stl_findpcibrds();
2704 #endif
2706 return(0);
2709 /*****************************************************************************/
2712 * Return the board stats structure to user app.
2715 static int stl_getbrdstats(combrd_t *bp)
2717 stlbrd_t *brdp;
2718 stlpanel_t *panelp;
2719 int i;
2721 copy_from_user(&stl_brdstats, bp, sizeof(combrd_t));
2722 if (stl_brdstats.brd >= STL_MAXBRDS)
2723 return(-ENODEV);
2724 brdp = stl_brds[stl_brdstats.brd];
2725 if (brdp == (stlbrd_t *) NULL)
2726 return(-ENODEV);
2728 memset(&stl_brdstats, 0, sizeof(combrd_t));
2729 stl_brdstats.brd = brdp->brdnr;
2730 stl_brdstats.type = brdp->brdtype;
2731 stl_brdstats.hwid = brdp->hwid;
2732 stl_brdstats.state = brdp->state;
2733 stl_brdstats.ioaddr = brdp->ioaddr1;
2734 stl_brdstats.ioaddr2 = brdp->ioaddr2;
2735 stl_brdstats.irq = brdp->irq;
2736 stl_brdstats.nrpanels = brdp->nrpanels;
2737 stl_brdstats.nrports = brdp->nrports;
2738 for (i = 0; (i < brdp->nrpanels); i++) {
2739 panelp = brdp->panels[i];
2740 stl_brdstats.panels[i].panel = i;
2741 stl_brdstats.panels[i].hwid = panelp->hwid;
2742 stl_brdstats.panels[i].nrports = panelp->nrports;
2745 copy_to_user(bp, &stl_brdstats, sizeof(combrd_t));
2746 return(0);
2749 /*****************************************************************************/
2752 * Resolve the referenced port number into a port struct pointer.
2755 static stlport_t *stl_getport(int brdnr, int panelnr, int portnr)
2757 stlbrd_t *brdp;
2758 stlpanel_t *panelp;
2760 if ((brdnr < 0) || (brdnr >= STL_MAXBRDS))
2761 return((stlport_t *) NULL);
2762 brdp = stl_brds[brdnr];
2763 if (brdp == (stlbrd_t *) NULL)
2764 return((stlport_t *) NULL);
2765 if ((panelnr < 0) || (panelnr >= brdp->nrpanels))
2766 return((stlport_t *) NULL);
2767 panelp = brdp->panels[panelnr];
2768 if (panelp == (stlpanel_t *) NULL)
2769 return((stlport_t *) NULL);
2770 if ((portnr < 0) || (portnr >= panelp->nrports))
2771 return((stlport_t *) NULL);
2772 return(panelp->ports[portnr]);
2775 /*****************************************************************************/
2778 * Return the port stats structure to user app. A NULL port struct
2779 * pointer passed in means that we need to find out from the app
2780 * what port to get stats for (used through board control device).
2783 static int stl_getportstats(stlport_t *portp, comstats_t *cp)
2785 unsigned char *head, *tail;
2786 unsigned long flags;
2788 if (portp == (stlport_t *) NULL) {
2789 copy_from_user(&stl_comstats, cp, sizeof(comstats_t));
2790 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2791 stl_comstats.port);
2792 if (portp == (stlport_t *) NULL)
2793 return(-ENODEV);
2796 portp->stats.state = portp->istate;
2797 portp->stats.flags = portp->flags;
2798 portp->stats.hwid = portp->hwid;
2800 portp->stats.ttystate = 0;
2801 portp->stats.cflags = 0;
2802 portp->stats.iflags = 0;
2803 portp->stats.oflags = 0;
2804 portp->stats.lflags = 0;
2805 portp->stats.rxbuffered = 0;
2807 save_flags(flags);
2808 cli();
2809 if (portp->tty != (struct tty_struct *) NULL) {
2810 if (portp->tty->driver_data == portp) {
2811 portp->stats.ttystate = portp->tty->flags;
2812 portp->stats.rxbuffered = portp->tty->flip.count;
2813 if (portp->tty->termios != (struct termios *) NULL) {
2814 portp->stats.cflags = portp->tty->termios->c_cflag;
2815 portp->stats.iflags = portp->tty->termios->c_iflag;
2816 portp->stats.oflags = portp->tty->termios->c_oflag;
2817 portp->stats.lflags = portp->tty->termios->c_lflag;
2821 restore_flags(flags);
2823 head = portp->tx.head;
2824 tail = portp->tx.tail;
2825 portp->stats.txbuffered = ((head >= tail) ? (head - tail) :
2826 (STL_TXBUFSIZE - (tail - head)));
2828 portp->stats.signals = (unsigned long) stl_getsignals(portp);
2830 copy_to_user(cp, &portp->stats, sizeof(comstats_t));
2831 return(0);
2834 /*****************************************************************************/
2837 * Clear the port stats structure. We also return it zeroed out...
2840 static int stl_clrportstats(stlport_t *portp, comstats_t *cp)
2842 if (portp == (stlport_t *) NULL) {
2843 copy_from_user(&stl_comstats, cp, sizeof(comstats_t));
2844 portp = stl_getport(stl_comstats.brd, stl_comstats.panel,
2845 stl_comstats.port);
2846 if (portp == (stlport_t *) NULL)
2847 return(-ENODEV);
2850 memset(&portp->stats, 0, sizeof(comstats_t));
2851 portp->stats.brd = portp->brdnr;
2852 portp->stats.panel = portp->panelnr;
2853 portp->stats.port = portp->portnr;
2854 copy_to_user(cp, &portp->stats, sizeof(comstats_t));
2855 return(0);
2858 /*****************************************************************************/
2861 * Return the entire driver ports structure to a user app.
2864 static int stl_getportstruct(unsigned long arg)
2866 stlport_t *portp;
2868 copy_from_user(&stl_dummyport, (void *) arg, sizeof(stlport_t));
2869 portp = stl_getport(stl_dummyport.brdnr, stl_dummyport.panelnr,
2870 stl_dummyport.portnr);
2871 if (portp == (stlport_t *) NULL)
2872 return(-ENODEV);
2873 copy_to_user((void *) arg, portp, sizeof(stlport_t));
2874 return(0);
2877 /*****************************************************************************/
2880 * Return the entire driver board structure to a user app.
2883 static int stl_getbrdstruct(unsigned long arg)
2885 stlbrd_t *brdp;
2887 copy_from_user(&stl_dummybrd, (void *) arg, sizeof(stlbrd_t));
2888 if ((stl_dummybrd.brdnr < 0) || (stl_dummybrd.brdnr >= STL_MAXBRDS))
2889 return(-ENODEV);
2890 brdp = stl_brds[stl_dummybrd.brdnr];
2891 if (brdp == (stlbrd_t *) NULL)
2892 return(-ENODEV);
2893 copy_to_user((void *) arg, brdp, sizeof(stlbrd_t));
2894 return(0);
2897 /*****************************************************************************/
2900 * Memory device open code. Need to keep track of opens and close
2901 * for module handling.
2904 static int stl_memopen(struct inode *ip, struct file *fp)
2906 MOD_INC_USE_COUNT;
2907 return(0);
2910 /*****************************************************************************/
2912 static int stl_memclose(struct inode *ip, struct file *fp)
2914 MOD_DEC_USE_COUNT;
2915 return(0);
2918 /*****************************************************************************/
2921 * The "staliomem" device is also required to do some special operations
2922 * on the board and/or ports. In this driver it is mostly used for stats
2923 * collection.
2926 static int stl_memioctl(struct inode *ip, struct file *fp, unsigned int cmd, unsigned long arg)
2928 int brdnr, rc;
2930 #if DEBUG
2931 printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip,
2932 (int) fp, cmd, (int) arg);
2933 #endif
2935 brdnr = MINOR(ip->i_rdev);
2936 if (brdnr >= STL_MAXBRDS)
2937 return(-ENODEV);
2938 rc = 0;
2940 switch (cmd) {
2941 case COM_GETPORTSTATS:
2942 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
2943 sizeof(comstats_t))) == 0)
2944 rc = stl_getportstats((stlport_t *) NULL,
2945 (comstats_t *) arg);
2946 break;
2947 case COM_CLRPORTSTATS:
2948 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
2949 sizeof(comstats_t))) == 0)
2950 rc = stl_clrportstats((stlport_t *) NULL,
2951 (comstats_t *) arg);
2952 break;
2953 case COM_GETBRDSTATS:
2954 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
2955 sizeof(combrd_t))) == 0)
2956 rc = stl_getbrdstats((combrd_t *) arg);
2957 break;
2958 case COM_READPORT:
2959 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
2960 sizeof(stlport_t))) == 0)
2961 rc = stl_getportstruct(arg);
2962 break;
2963 case COM_READBOARD:
2964 if ((rc = verify_area(VERIFY_WRITE, (void *) arg,
2965 sizeof(stlbrd_t))) == 0)
2966 rc = stl_getbrdstruct(arg);
2967 break;
2968 default:
2969 rc = -ENOIOCTLCMD;
2970 break;
2973 return(rc);
2976 /*****************************************************************************/
2978 __initfunc(int stl_init(void))
2980 printk(KERN_INFO "%s: version %s\n", stl_drvtitle, stl_drvversion);
2982 stl_initbrds();
2985 * Allocate a temporary write buffer.
2987 stl_tmpwritebuf = (char *) stl_memalloc(STL_TXBUFSIZE);
2988 if (stl_tmpwritebuf == (char *) NULL)
2989 printk("STALLION: failed to allocate memory (size=%d)\n",
2990 STL_TXBUFSIZE);
2993 * Set up a character driver for per board stuff. This is mainly used
2994 * to do stats ioctls on the ports.
2996 if (register_chrdev(STL_SIOMEMMAJOR, "staliomem", &stl_fsiomem))
2997 printk("STALLION: failed to register serial board device\n");
3000 * Set up the tty driver structure and register us as a driver.
3001 * Also setup the callout tty device.
3003 memset(&stl_serial, 0, sizeof(struct tty_driver));
3004 stl_serial.magic = TTY_DRIVER_MAGIC;
3005 stl_serial.driver_name = stl_drvname;
3006 stl_serial.name = stl_serialname;
3007 stl_serial.major = STL_SERIALMAJOR;
3008 stl_serial.minor_start = 0;
3009 stl_serial.num = STL_MAXBRDS * STL_MAXPORTS;
3010 stl_serial.type = TTY_DRIVER_TYPE_SERIAL;
3011 stl_serial.subtype = STL_DRVTYPSERIAL;
3012 stl_serial.init_termios = stl_deftermios;
3013 stl_serial.flags = TTY_DRIVER_REAL_RAW;
3014 stl_serial.refcount = &stl_refcount;
3015 stl_serial.table = stl_ttys;
3016 stl_serial.termios = stl_termios;
3017 stl_serial.termios_locked = stl_termioslocked;
3019 stl_serial.open = stl_open;
3020 stl_serial.close = stl_close;
3021 stl_serial.write = stl_write;
3022 stl_serial.put_char = stl_putchar;
3023 stl_serial.flush_chars = stl_flushchars;
3024 stl_serial.write_room = stl_writeroom;
3025 stl_serial.chars_in_buffer = stl_charsinbuffer;
3026 stl_serial.ioctl = stl_ioctl;
3027 stl_serial.set_termios = stl_settermios;
3028 stl_serial.throttle = stl_throttle;
3029 stl_serial.unthrottle = stl_unthrottle;
3030 stl_serial.stop = stl_stop;
3031 stl_serial.start = stl_start;
3032 stl_serial.hangup = stl_hangup;
3033 stl_serial.flush_buffer = stl_flushbuffer;
3034 stl_serial.break_ctl = stl_breakctl;
3035 stl_serial.wait_until_sent = stl_waituntilsent;
3036 stl_serial.send_xchar = stl_sendxchar;
3037 stl_serial.read_proc = stl_readproc;
3039 stl_callout = stl_serial;
3040 stl_callout.name = stl_calloutname;
3041 stl_callout.major = STL_CALLOUTMAJOR;
3042 stl_callout.subtype = STL_DRVTYPCALLOUT;
3043 stl_callout.read_proc = 0;
3045 if (tty_register_driver(&stl_serial))
3046 printk("STALLION: failed to register serial driver\n");
3047 if (tty_register_driver(&stl_callout))
3048 printk("STALLION: failed to register callout driver\n");
3050 return(0);
3053 /*****************************************************************************/
3054 /* CD1400 HARDWARE FUNCTIONS */
3055 /*****************************************************************************/
3058 * These functions get/set/update the registers of the cd1400 UARTs.
3059 * Access to the cd1400 registers is via an address/data io port pair.
3060 * (Maybe should make this inline...)
3063 static int stl_cd1400getreg(stlport_t *portp, int regnr)
3065 outb((regnr + portp->uartaddr), portp->ioaddr);
3066 return(inb(portp->ioaddr + EREG_DATA));
3069 static void stl_cd1400setreg(stlport_t *portp, int regnr, int value)
3071 outb((regnr + portp->uartaddr), portp->ioaddr);
3072 outb(value, portp->ioaddr + EREG_DATA);
3075 static int stl_cd1400updatereg(stlport_t *portp, int regnr, int value)
3077 outb((regnr + portp->uartaddr), portp->ioaddr);
3078 if (inb(portp->ioaddr + EREG_DATA) != value) {
3079 outb(value, portp->ioaddr + EREG_DATA);
3080 return(1);
3082 return(0);
3085 /*****************************************************************************/
3088 * Inbitialize the UARTs in a panel. We don't care what sort of board
3089 * these ports are on - since the port io registers are almost
3090 * identical when dealing with ports.
3093 static int stl_cd1400panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
3095 unsigned int gfrcr;
3096 int chipmask, i, j;
3097 int nrchips, uartaddr, ioaddr;
3099 #if DEBUG
3100 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp, (int) panelp);
3101 #endif
3103 BRDENABLE(panelp->brdnr, panelp->pagenr);
3106 * Check that each chip is present and started up OK.
3108 chipmask = 0;
3109 nrchips = panelp->nrports / CD1400_PORTS;
3110 for (i = 0; (i < nrchips); i++) {
3111 if (brdp->brdtype == BRD_ECHPCI) {
3112 outb((panelp->pagenr + (i >> 1)), brdp->ioctrl);
3113 ioaddr = panelp->iobase;
3114 } else {
3115 ioaddr = panelp->iobase + (EREG_BANKSIZE * (i >> 1));
3117 uartaddr = (i & 0x01) ? 0x080 : 0;
3118 outb((GFRCR + uartaddr), ioaddr);
3119 outb(0, (ioaddr + EREG_DATA));
3120 outb((CCR + uartaddr), ioaddr);
3121 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3122 outb(CCR_RESETFULL, (ioaddr + EREG_DATA));
3123 outb((GFRCR + uartaddr), ioaddr);
3124 for (j = 0; (j < CCR_MAXWAIT); j++) {
3125 if ((gfrcr = inb(ioaddr + EREG_DATA)) != 0)
3126 break;
3128 if ((j >= CCR_MAXWAIT) || (gfrcr < 0x40) || (gfrcr > 0x60)) {
3129 printk("STALLION: cd1400 not responding, "
3130 "brd=%d panel=%d chip=%d\n",
3131 panelp->brdnr, panelp->panelnr, i);
3132 continue;
3134 chipmask |= (0x1 << i);
3135 outb((PPR + uartaddr), ioaddr);
3136 outb(PPR_SCALAR, (ioaddr + EREG_DATA));
3139 BRDDISABLE(panelp->brdnr);
3140 return(chipmask);
3143 /*****************************************************************************/
3146 * Initialize hardware specific port registers.
3149 static void stl_cd1400portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
3151 #if DEBUG
3152 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3153 (int) brdp, (int) panelp, (int) portp);
3154 #endif
3156 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
3157 (portp == (stlport_t *) NULL))
3158 return;
3160 portp->ioaddr = panelp->iobase + (((brdp->brdtype == BRD_ECHPCI) ||
3161 (portp->portnr < 8)) ? 0 : EREG_BANKSIZE);
3162 portp->uartaddr = (portp->portnr & 0x04) << 5;
3163 portp->pagenr = panelp->pagenr + (portp->portnr >> 3);
3165 BRDENABLE(portp->brdnr, portp->pagenr);
3166 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3167 stl_cd1400setreg(portp, LIVR, (portp->portnr << 3));
3168 portp->hwid = stl_cd1400getreg(portp, GFRCR);
3169 BRDDISABLE(portp->brdnr);
3172 /*****************************************************************************/
3175 * Wait for the command register to be ready. We will poll this,
3176 * since it won't usually take too long to be ready.
3179 static void stl_cd1400ccrwait(stlport_t *portp)
3181 int i;
3183 for (i = 0; (i < CCR_MAXWAIT); i++) {
3184 if (stl_cd1400getreg(portp, CCR) == 0) {
3185 return;
3189 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
3190 portp->portnr, portp->panelnr, portp->brdnr);
3193 /*****************************************************************************/
3196 * Set up the cd1400 registers for a port based on the termios port
3197 * settings.
3200 static void stl_cd1400setport(stlport_t *portp, struct termios *tiosp)
3202 stlbrd_t *brdp;
3203 unsigned long flags;
3204 unsigned int clkdiv, baudrate;
3205 unsigned char cor1, cor2, cor3;
3206 unsigned char cor4, cor5, ccr;
3207 unsigned char srer, sreron, sreroff;
3208 unsigned char mcor1, mcor2, rtpr;
3209 unsigned char clk, div;
3211 cor1 = 0;
3212 cor2 = 0;
3213 cor3 = 0;
3214 cor4 = 0;
3215 cor5 = 0;
3216 ccr = 0;
3217 rtpr = 0;
3218 clk = 0;
3219 div = 0;
3220 mcor1 = 0;
3221 mcor2 = 0;
3222 sreron = 0;
3223 sreroff = 0;
3225 brdp = stl_brds[portp->brdnr];
3226 if (brdp == (stlbrd_t *) NULL)
3227 return;
3230 * Set up the RX char ignore mask with those RX error types we
3231 * can ignore. We can get the cd1400 to help us out a little here,
3232 * it will ignore parity errors and breaks for us.
3234 portp->rxignoremsk = 0;
3235 if (tiosp->c_iflag & IGNPAR) {
3236 portp->rxignoremsk |= (ST_PARITY | ST_FRAMING | ST_OVERRUN);
3237 cor1 |= COR1_PARIGNORE;
3239 if (tiosp->c_iflag & IGNBRK) {
3240 portp->rxignoremsk |= ST_BREAK;
3241 cor4 |= COR4_IGNBRK;
3244 portp->rxmarkmsk = ST_OVERRUN;
3245 if (tiosp->c_iflag & (INPCK | PARMRK))
3246 portp->rxmarkmsk |= (ST_PARITY | ST_FRAMING);
3247 if (tiosp->c_iflag & BRKINT)
3248 portp->rxmarkmsk |= ST_BREAK;
3251 * Go through the char size, parity and stop bits and set all the
3252 * option register appropriately.
3254 switch (tiosp->c_cflag & CSIZE) {
3255 case CS5:
3256 cor1 |= COR1_CHL5;
3257 break;
3258 case CS6:
3259 cor1 |= COR1_CHL6;
3260 break;
3261 case CS7:
3262 cor1 |= COR1_CHL7;
3263 break;
3264 default:
3265 cor1 |= COR1_CHL8;
3266 break;
3269 if (tiosp->c_cflag & CSTOPB)
3270 cor1 |= COR1_STOP2;
3271 else
3272 cor1 |= COR1_STOP1;
3274 if (tiosp->c_cflag & PARENB) {
3275 if (tiosp->c_cflag & PARODD)
3276 cor1 |= (COR1_PARENB | COR1_PARODD);
3277 else
3278 cor1 |= (COR1_PARENB | COR1_PAREVEN);
3279 } else {
3280 cor1 |= COR1_PARNONE;
3284 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3285 * space for hardware flow control and the like. This should be set to
3286 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3287 * really be based on VTIME.
3289 cor3 |= FIFO_RXTHRESHOLD;
3290 rtpr = 2;
3293 * Calculate the baud rate timers. For now we will just assume that
3294 * the input and output baud are the same. Could have used a baud
3295 * table here, but this way we can generate virtually any baud rate
3296 * we like!
3298 baudrate = tiosp->c_cflag & CBAUD;
3299 if (baudrate & CBAUDEX) {
3300 baudrate &= ~CBAUDEX;
3301 if ((baudrate < 1) || (baudrate > 4))
3302 tiosp->c_cflag &= ~CBAUDEX;
3303 else
3304 baudrate += 15;
3306 baudrate = stl_baudrates[baudrate];
3307 if ((tiosp->c_cflag & CBAUD) == B38400) {
3308 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
3309 baudrate = 57600;
3310 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
3311 baudrate = 115200;
3312 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
3313 baudrate = 230400;
3314 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
3315 baudrate = 460800;
3316 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
3317 baudrate = (portp->baud_base / portp->custom_divisor);
3319 if (baudrate > STL_CD1400MAXBAUD)
3320 baudrate = STL_CD1400MAXBAUD;
3322 if (baudrate > 0) {
3323 for (clk = 0; (clk < CD1400_NUMCLKS); clk++) {
3324 clkdiv = ((portp->clk / stl_cd1400clkdivs[clk]) / baudrate);
3325 if (clkdiv < 0x100)
3326 break;
3328 div = (unsigned char) clkdiv;
3332 * Check what form of modem signaling is required and set it up.
3334 if ((tiosp->c_cflag & CLOCAL) == 0) {
3335 mcor1 |= MCOR1_DCD;
3336 mcor2 |= MCOR2_DCD;
3337 sreron |= SRER_MODEM;
3338 portp->flags |= ASYNC_CHECK_CD;
3339 } else {
3340 portp->flags &= ~ASYNC_CHECK_CD;
3344 * Setup cd1400 enhanced modes if we can. In particular we want to
3345 * handle as much of the flow control as possible automatically. As
3346 * well as saving a few CPU cycles it will also greatly improve flow
3347 * control reliability.
3349 if (tiosp->c_iflag & IXON) {
3350 cor2 |= COR2_TXIBE;
3351 cor3 |= COR3_SCD12;
3352 if (tiosp->c_iflag & IXANY)
3353 cor2 |= COR2_IXM;
3356 if (tiosp->c_cflag & CRTSCTS) {
3357 cor2 |= COR2_CTSAE;
3358 mcor1 |= FIFO_RTSTHRESHOLD;
3362 * All cd1400 register values calculated so go through and set
3363 * them all up.
3366 #if DEBUG
3367 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3368 portp->portnr, portp->panelnr, portp->brdnr);
3369 printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3370 cor1, cor2, cor3, cor4, cor5);
3371 printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3372 mcor1, mcor2, rtpr, sreron, sreroff);
3373 printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk, div, clk, div);
3374 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3375 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
3376 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
3377 #endif
3379 save_flags(flags);
3380 cli();
3381 BRDENABLE(portp->brdnr, portp->pagenr);
3382 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x3));
3383 srer = stl_cd1400getreg(portp, SRER);
3384 stl_cd1400setreg(portp, SRER, 0);
3385 if (stl_cd1400updatereg(portp, COR1, cor1))
3386 ccr = 1;
3387 if (stl_cd1400updatereg(portp, COR2, cor2))
3388 ccr = 1;
3389 if (stl_cd1400updatereg(portp, COR3, cor3))
3390 ccr = 1;
3391 if (ccr) {
3392 stl_cd1400ccrwait(portp);
3393 stl_cd1400setreg(portp, CCR, CCR_CORCHANGE);
3395 stl_cd1400setreg(portp, COR4, cor4);
3396 stl_cd1400setreg(portp, COR5, cor5);
3397 stl_cd1400setreg(portp, MCOR1, mcor1);
3398 stl_cd1400setreg(portp, MCOR2, mcor2);
3399 if (baudrate > 0) {
3400 stl_cd1400setreg(portp, TCOR, clk);
3401 stl_cd1400setreg(portp, TBPR, div);
3402 stl_cd1400setreg(portp, RCOR, clk);
3403 stl_cd1400setreg(portp, RBPR, div);
3405 stl_cd1400setreg(portp, SCHR1, tiosp->c_cc[VSTART]);
3406 stl_cd1400setreg(portp, SCHR2, tiosp->c_cc[VSTOP]);
3407 stl_cd1400setreg(portp, SCHR3, tiosp->c_cc[VSTART]);
3408 stl_cd1400setreg(portp, SCHR4, tiosp->c_cc[VSTOP]);
3409 stl_cd1400setreg(portp, RTPR, rtpr);
3410 mcor1 = stl_cd1400getreg(portp, MSVR1);
3411 if (mcor1 & MSVR1_DCD)
3412 portp->sigs |= TIOCM_CD;
3413 else
3414 portp->sigs &= ~TIOCM_CD;
3415 stl_cd1400setreg(portp, SRER, ((srer & ~sreroff) | sreron));
3416 BRDDISABLE(portp->brdnr);
3417 restore_flags(flags);
3420 /*****************************************************************************/
3423 * Set the state of the DTR and RTS signals.
3426 static void stl_cd1400setsignals(stlport_t *portp, int dtr, int rts)
3428 unsigned char msvr1, msvr2;
3429 unsigned long flags;
3431 #if DEBUG
3432 printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
3433 (int) portp, dtr, rts);
3434 #endif
3436 msvr1 = 0;
3437 msvr2 = 0;
3438 if (dtr > 0)
3439 msvr1 = MSVR1_DTR;
3440 if (rts > 0)
3441 msvr2 = MSVR2_RTS;
3443 save_flags(flags);
3444 cli();
3445 BRDENABLE(portp->brdnr, portp->pagenr);
3446 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3447 if (rts >= 0)
3448 stl_cd1400setreg(portp, MSVR2, msvr2);
3449 if (dtr >= 0)
3450 stl_cd1400setreg(portp, MSVR1, msvr1);
3451 BRDDISABLE(portp->brdnr);
3452 restore_flags(flags);
3455 /*****************************************************************************/
3458 * Return the state of the signals.
3461 static int stl_cd1400getsignals(stlport_t *portp)
3463 unsigned char msvr1, msvr2;
3464 unsigned long flags;
3465 int sigs;
3467 #if DEBUG
3468 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp);
3469 #endif
3471 save_flags(flags);
3472 cli();
3473 BRDENABLE(portp->brdnr, portp->pagenr);
3474 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3475 msvr1 = stl_cd1400getreg(portp, MSVR1);
3476 msvr2 = stl_cd1400getreg(portp, MSVR2);
3477 BRDDISABLE(portp->brdnr);
3478 restore_flags(flags);
3480 sigs = 0;
3481 sigs |= (msvr1 & MSVR1_DCD) ? TIOCM_CD : 0;
3482 sigs |= (msvr1 & MSVR1_CTS) ? TIOCM_CTS : 0;
3483 sigs |= (msvr1 & MSVR1_DTR) ? TIOCM_DTR : 0;
3484 sigs |= (msvr2 & MSVR2_RTS) ? TIOCM_RTS : 0;
3485 #if 0
3486 sigs |= (msvr1 & MSVR1_RI) ? TIOCM_RI : 0;
3487 sigs |= (msvr1 & MSVR1_DSR) ? TIOCM_DSR : 0;
3488 #else
3489 sigs |= TIOCM_DSR;
3490 #endif
3491 return(sigs);
3494 /*****************************************************************************/
3497 * Enable/Disable the Transmitter and/or Receiver.
3500 static void stl_cd1400enablerxtx(stlport_t *portp, int rx, int tx)
3502 unsigned char ccr;
3503 unsigned long flags;
3505 #if DEBUG
3506 printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3507 (int) portp, rx, tx);
3508 #endif
3509 ccr = 0;
3511 if (tx == 0)
3512 ccr |= CCR_TXDISABLE;
3513 else if (tx > 0)
3514 ccr |= CCR_TXENABLE;
3515 if (rx == 0)
3516 ccr |= CCR_RXDISABLE;
3517 else if (rx > 0)
3518 ccr |= CCR_RXENABLE;
3520 save_flags(flags);
3521 cli();
3522 BRDENABLE(portp->brdnr, portp->pagenr);
3523 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3524 stl_cd1400ccrwait(portp);
3525 stl_cd1400setreg(portp, CCR, ccr);
3526 stl_cd1400ccrwait(portp);
3527 BRDDISABLE(portp->brdnr);
3528 restore_flags(flags);
3531 /*****************************************************************************/
3534 * Start/stop the Transmitter and/or Receiver.
3537 static void stl_cd1400startrxtx(stlport_t *portp, int rx, int tx)
3539 unsigned char sreron, sreroff;
3540 unsigned long flags;
3542 #if DEBUG
3543 printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3544 (int) portp, rx, tx);
3545 #endif
3547 sreron = 0;
3548 sreroff = 0;
3549 if (tx == 0)
3550 sreroff |= (SRER_TXDATA | SRER_TXEMPTY);
3551 else if (tx == 1)
3552 sreron |= SRER_TXDATA;
3553 else if (tx >= 2)
3554 sreron |= SRER_TXEMPTY;
3555 if (rx == 0)
3556 sreroff |= SRER_RXDATA;
3557 else if (rx > 0)
3558 sreron |= SRER_RXDATA;
3560 save_flags(flags);
3561 cli();
3562 BRDENABLE(portp->brdnr, portp->pagenr);
3563 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3564 stl_cd1400setreg(portp, SRER,
3565 ((stl_cd1400getreg(portp, SRER) & ~sreroff) | sreron));
3566 BRDDISABLE(portp->brdnr);
3567 if (tx > 0)
3568 set_bit(ASYI_TXBUSY, &portp->istate);
3569 restore_flags(flags);
3572 /*****************************************************************************/
3575 * Disable all interrupts from this port.
3578 static void stl_cd1400disableintrs(stlport_t *portp)
3580 unsigned long flags;
3582 #if DEBUG
3583 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp);
3584 #endif
3585 save_flags(flags);
3586 cli();
3587 BRDENABLE(portp->brdnr, portp->pagenr);
3588 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3589 stl_cd1400setreg(portp, SRER, 0);
3590 BRDDISABLE(portp->brdnr);
3591 restore_flags(flags);
3594 /*****************************************************************************/
3596 static void stl_cd1400sendbreak(stlport_t *portp, int len)
3598 unsigned long flags;
3600 #if DEBUG
3601 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp, len);
3602 #endif
3604 save_flags(flags);
3605 cli();
3606 BRDENABLE(portp->brdnr, portp->pagenr);
3607 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3608 stl_cd1400setreg(portp, SRER,
3609 ((stl_cd1400getreg(portp, SRER) & ~SRER_TXDATA) |
3610 SRER_TXEMPTY));
3611 BRDDISABLE(portp->brdnr);
3612 portp->brklen = len;
3613 if (len == 1)
3614 portp->stats.txbreaks++;
3615 restore_flags(flags);
3618 /*****************************************************************************/
3621 * Take flow control actions...
3624 static void stl_cd1400flowctrl(stlport_t *portp, int state)
3626 struct tty_struct *tty;
3627 unsigned long flags;
3629 #if DEBUG
3630 printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp, state);
3631 #endif
3633 if (portp == (stlport_t *) NULL)
3634 return;
3635 tty = portp->tty;
3636 if (tty == (struct tty_struct *) NULL)
3637 return;
3639 save_flags(flags);
3640 cli();
3641 BRDENABLE(portp->brdnr, portp->pagenr);
3642 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3644 if (state) {
3645 if (tty->termios->c_iflag & IXOFF) {
3646 stl_cd1400ccrwait(portp);
3647 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3648 portp->stats.rxxon++;
3649 stl_cd1400ccrwait(portp);
3652 * Question: should we return RTS to what it was before? It may
3653 * have been set by an ioctl... Suppose not, since if you have
3654 * hardware flow control set then it is pretty silly to go and
3655 * set the RTS line by hand.
3657 if (tty->termios->c_cflag & CRTSCTS) {
3658 stl_cd1400setreg(portp, MCOR1,
3659 (stl_cd1400getreg(portp, MCOR1) |
3660 FIFO_RTSTHRESHOLD));
3661 stl_cd1400setreg(portp, MSVR2, MSVR2_RTS);
3662 portp->stats.rxrtson++;
3664 } else {
3665 if (tty->termios->c_iflag & IXOFF) {
3666 stl_cd1400ccrwait(portp);
3667 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3668 portp->stats.rxxoff++;
3669 stl_cd1400ccrwait(portp);
3671 if (tty->termios->c_cflag & CRTSCTS) {
3672 stl_cd1400setreg(portp, MCOR1,
3673 (stl_cd1400getreg(portp, MCOR1) & 0xf0));
3674 stl_cd1400setreg(portp, MSVR2, 0);
3675 portp->stats.rxrtsoff++;
3679 BRDDISABLE(portp->brdnr);
3680 restore_flags(flags);
3683 /*****************************************************************************/
3686 * Send a flow control character...
3689 static void stl_cd1400sendflow(stlport_t *portp, int state)
3691 struct tty_struct *tty;
3692 unsigned long flags;
3694 #if DEBUG
3695 printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp, state);
3696 #endif
3698 if (portp == (stlport_t *) NULL)
3699 return;
3700 tty = portp->tty;
3701 if (tty == (struct tty_struct *) NULL)
3702 return;
3704 save_flags(flags);
3705 cli();
3706 BRDENABLE(portp->brdnr, portp->pagenr);
3707 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3708 if (state) {
3709 stl_cd1400ccrwait(portp);
3710 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR1);
3711 portp->stats.rxxon++;
3712 stl_cd1400ccrwait(portp);
3713 } else {
3714 stl_cd1400ccrwait(portp);
3715 stl_cd1400setreg(portp, CCR, CCR_SENDSCHR2);
3716 portp->stats.rxxoff++;
3717 stl_cd1400ccrwait(portp);
3719 BRDDISABLE(portp->brdnr);
3720 restore_flags(flags);
3723 /*****************************************************************************/
3725 static void stl_cd1400flush(stlport_t *portp)
3727 unsigned long flags;
3729 #if DEBUG
3730 printk("stl_cd1400flush(portp=%x)\n", (int) portp);
3731 #endif
3733 if (portp == (stlport_t *) NULL)
3734 return;
3736 save_flags(flags);
3737 cli();
3738 BRDENABLE(portp->brdnr, portp->pagenr);
3739 stl_cd1400setreg(portp, CAR, (portp->portnr & 0x03));
3740 stl_cd1400ccrwait(portp);
3741 stl_cd1400setreg(portp, CCR, CCR_TXFLUSHFIFO);
3742 stl_cd1400ccrwait(portp);
3743 portp->tx.tail = portp->tx.head;
3744 BRDDISABLE(portp->brdnr);
3745 restore_flags(flags);
3748 /*****************************************************************************/
3751 * Return the current state of data flow on this port. This is only
3752 * really interresting when determining if data has fully completed
3753 * transmission or not... This is easy for the cd1400, it accurately
3754 * maintains the busy port flag.
3757 static int stl_cd1400datastate(stlport_t *portp)
3759 #if DEBUG
3760 printk("stl_cd1400datastate(portp=%x)\n", (int) portp);
3761 #endif
3763 if (portp == (stlport_t *) NULL)
3764 return(0);
3766 return(test_bit(ASYI_TXBUSY, &portp->istate) ? 1 : 0);
3769 /*****************************************************************************/
3772 * Interrupt service routine for cd1400 EasyIO boards.
3775 static void stl_cd1400eiointr(stlpanel_t *panelp, unsigned int iobase)
3777 unsigned char svrtype;
3779 #if DEBUG
3780 printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
3781 (int) panelp, iobase);
3782 #endif
3784 outb(SVRR, iobase);
3785 svrtype = inb(iobase + EREG_DATA);
3786 if (panelp->nrports > 4) {
3787 outb((SVRR + 0x80), iobase);
3788 svrtype |= inb(iobase + EREG_DATA);
3791 if (svrtype & SVRR_RX)
3792 stl_cd1400rxisr(panelp, iobase);
3793 else if (svrtype & SVRR_TX)
3794 stl_cd1400txisr(panelp, iobase);
3795 else if (svrtype & SVRR_MDM)
3796 stl_cd1400mdmisr(panelp, iobase);
3799 /*****************************************************************************/
3802 * Interrupt service routine for cd1400 panels.
3805 static void stl_cd1400echintr(stlpanel_t *panelp, unsigned int iobase)
3807 unsigned char svrtype;
3809 #if DEBUG
3810 printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp,
3811 iobase);
3812 #endif
3814 outb(SVRR, iobase);
3815 svrtype = inb(iobase + EREG_DATA);
3816 outb((SVRR + 0x80), iobase);
3817 svrtype |= inb(iobase + EREG_DATA);
3818 if (svrtype & SVRR_RX)
3819 stl_cd1400rxisr(panelp, iobase);
3820 else if (svrtype & SVRR_TX)
3821 stl_cd1400txisr(panelp, iobase);
3822 else if (svrtype & SVRR_MDM)
3823 stl_cd1400mdmisr(panelp, iobase);
3827 /*****************************************************************************/
3830 * Unfortunately we need to handle breaks in the TX data stream, since
3831 * this is the only way to generate them on the cd1400.
3834 static inline int stl_cd1400breakisr(stlport_t *portp, int ioaddr)
3836 if (portp->brklen == 1) {
3837 outb((COR2 + portp->uartaddr), ioaddr);
3838 outb((inb(ioaddr + EREG_DATA) | COR2_ETC),
3839 (ioaddr + EREG_DATA));
3840 outb((TDR + portp->uartaddr), ioaddr);
3841 outb(ETC_CMD, (ioaddr + EREG_DATA));
3842 outb(ETC_STARTBREAK, (ioaddr + EREG_DATA));
3843 outb((SRER + portp->uartaddr), ioaddr);
3844 outb((inb(ioaddr + EREG_DATA) & ~(SRER_TXDATA | SRER_TXEMPTY)),
3845 (ioaddr + EREG_DATA));
3846 return(1);
3847 } else if (portp->brklen > 1) {
3848 outb((TDR + portp->uartaddr), ioaddr);
3849 outb(ETC_CMD, (ioaddr + EREG_DATA));
3850 outb(ETC_STOPBREAK, (ioaddr + EREG_DATA));
3851 portp->brklen = -1;
3852 return(1);
3853 } else {
3854 outb((COR2 + portp->uartaddr), ioaddr);
3855 outb((inb(ioaddr + EREG_DATA) & ~COR2_ETC),
3856 (ioaddr + EREG_DATA));
3857 portp->brklen = 0;
3859 return(0);
3862 /*****************************************************************************/
3865 * Transmit interrupt handler. This has gotta be fast! Handling TX
3866 * chars is pretty simple, stuff as many as possible from the TX buffer
3867 * into the cd1400 FIFO. Must also handle TX breaks here, since they
3868 * are embedded as commands in the data stream. Oh no, had to use a goto!
3869 * This could be optimized more, will do when I get time...
3870 * In practice it is possible that interrupts are enabled but that the
3871 * port has been hung up. Need to handle not having any TX buffer here,
3872 * this is done by using the side effect that head and tail will also
3873 * be NULL if the buffer has been freed.
3876 static void stl_cd1400txisr(stlpanel_t *panelp, int ioaddr)
3878 stlport_t *portp;
3879 int len, stlen;
3880 char *head, *tail;
3881 unsigned char ioack, srer;
3883 #if DEBUG
3884 printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
3885 #endif
3887 ioack = inb(ioaddr + EREG_TXACK);
3888 if (((ioack & panelp->ackmask) != 0) ||
3889 ((ioack & ACK_TYPMASK) != ACK_TYPTX)) {
3890 printk("STALLION: bad TX interrupt ack value=%x\n", ioack);
3891 return;
3893 portp = panelp->ports[(ioack >> 3)];
3896 * Unfortunately we need to handle breaks in the data stream, since
3897 * this is the only way to generate them on the cd1400. Do it now if
3898 * a break is to be sent.
3900 if (portp->brklen != 0)
3901 if (stl_cd1400breakisr(portp, ioaddr))
3902 goto stl_txalldone;
3904 head = portp->tx.head;
3905 tail = portp->tx.tail;
3906 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
3907 if ((len == 0) || ((len < STL_TXBUFLOW) &&
3908 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
3909 set_bit(ASYI_TXLOW, &portp->istate);
3910 queue_task(&portp->tqueue, &tq_scheduler);
3913 if (len == 0) {
3914 outb((SRER + portp->uartaddr), ioaddr);
3915 srer = inb(ioaddr + EREG_DATA);
3916 if (srer & SRER_TXDATA) {
3917 srer = (srer & ~SRER_TXDATA) | SRER_TXEMPTY;
3918 } else {
3919 srer &= ~(SRER_TXDATA | SRER_TXEMPTY);
3920 clear_bit(ASYI_TXBUSY, &portp->istate);
3922 outb(srer, (ioaddr + EREG_DATA));
3923 } else {
3924 len = MIN(len, CD1400_TXFIFOSIZE);
3925 portp->stats.txtotal += len;
3926 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
3927 outb((TDR + portp->uartaddr), ioaddr);
3928 outsb((ioaddr + EREG_DATA), tail, stlen);
3929 len -= stlen;
3930 tail += stlen;
3931 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
3932 tail = portp->tx.buf;
3933 if (len > 0) {
3934 outsb((ioaddr + EREG_DATA), tail, len);
3935 tail += len;
3937 portp->tx.tail = tail;
3940 stl_txalldone:
3941 outb((EOSRR + portp->uartaddr), ioaddr);
3942 outb(0, (ioaddr + EREG_DATA));
3945 /*****************************************************************************/
3948 * Receive character interrupt handler. Determine if we have good chars
3949 * or bad chars and then process appropriately. Good chars are easy
3950 * just shove the lot into the RX buffer and set all status byte to 0.
3951 * If a bad RX char then process as required. This routine needs to be
3952 * fast! In practice it is possible that we get an interrupt on a port
3953 * that is closed. This can happen on hangups - since they completely
3954 * shutdown a port not in user context. Need to handle this case.
3957 static void stl_cd1400rxisr(stlpanel_t *panelp, int ioaddr)
3959 stlport_t *portp;
3960 struct tty_struct *tty;
3961 unsigned int ioack, len, buflen;
3962 unsigned char status;
3963 char ch;
3965 #if DEBUG
3966 printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp, ioaddr);
3967 #endif
3969 ioack = inb(ioaddr + EREG_RXACK);
3970 if ((ioack & panelp->ackmask) != 0) {
3971 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
3972 return;
3974 portp = panelp->ports[(ioack >> 3)];
3975 tty = portp->tty;
3977 if ((ioack & ACK_TYPMASK) == ACK_TYPRXGOOD) {
3978 outb((RDCR + portp->uartaddr), ioaddr);
3979 len = inb(ioaddr + EREG_DATA);
3980 if ((tty == (struct tty_struct *) NULL) ||
3981 (tty->flip.char_buf_ptr == (char *) NULL) ||
3982 ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
3983 outb((RDSR + portp->uartaddr), ioaddr);
3984 insb((ioaddr + EREG_DATA), &stl_unwanted[0], len);
3985 portp->stats.rxlost += len;
3986 portp->stats.rxtotal += len;
3987 } else {
3988 len = MIN(len, buflen);
3989 if (len > 0) {
3990 outb((RDSR + portp->uartaddr), ioaddr);
3991 insb((ioaddr + EREG_DATA), tty->flip.char_buf_ptr, len);
3992 memset(tty->flip.flag_buf_ptr, 0, len);
3993 tty->flip.flag_buf_ptr += len;
3994 tty->flip.char_buf_ptr += len;
3995 tty->flip.count += len;
3996 tty_schedule_flip(tty);
3997 portp->stats.rxtotal += len;
4000 } else if ((ioack & ACK_TYPMASK) == ACK_TYPRXBAD) {
4001 outb((RDSR + portp->uartaddr), ioaddr);
4002 status = inb(ioaddr + EREG_DATA);
4003 ch = inb(ioaddr + EREG_DATA);
4004 if (status & ST_PARITY)
4005 portp->stats.rxparity++;
4006 if (status & ST_FRAMING)
4007 portp->stats.rxframing++;
4008 if (status & ST_OVERRUN)
4009 portp->stats.rxoverrun++;
4010 if (status & ST_BREAK)
4011 portp->stats.rxbreaks++;
4012 if (status & ST_SCHARMASK) {
4013 if ((status & ST_SCHARMASK) == ST_SCHAR1)
4014 portp->stats.txxon++;
4015 if ((status & ST_SCHARMASK) == ST_SCHAR2)
4016 portp->stats.txxoff++;
4017 goto stl_rxalldone;
4019 if ((tty != (struct tty_struct *) NULL) &&
4020 ((portp->rxignoremsk & status) == 0)) {
4021 if (portp->rxmarkmsk & status) {
4022 if (status & ST_BREAK) {
4023 status = TTY_BREAK;
4024 if (portp->flags & ASYNC_SAK) {
4025 do_SAK(tty);
4026 BRDENABLE(portp->brdnr, portp->pagenr);
4028 } else if (status & ST_PARITY) {
4029 status = TTY_PARITY;
4030 } else if (status & ST_FRAMING) {
4031 status = TTY_FRAME;
4032 } else if(status & ST_OVERRUN) {
4033 status = TTY_OVERRUN;
4034 } else {
4035 status = 0;
4037 } else {
4038 status = 0;
4040 if (tty->flip.char_buf_ptr != (char *) NULL) {
4041 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
4042 *tty->flip.flag_buf_ptr++ = status;
4043 *tty->flip.char_buf_ptr++ = ch;
4044 tty->flip.count++;
4046 tty_schedule_flip(tty);
4049 } else {
4050 printk("STALLION: bad RX interrupt ack value=%x\n", ioack);
4051 return;
4054 stl_rxalldone:
4055 outb((EOSRR + portp->uartaddr), ioaddr);
4056 outb(0, (ioaddr + EREG_DATA));
4059 /*****************************************************************************/
4062 * Modem interrupt handler. The is called when the modem signal line
4063 * (DCD) has changed state. Leave most of the work to the off-level
4064 * processing routine.
4067 static void stl_cd1400mdmisr(stlpanel_t *panelp, int ioaddr)
4069 stlport_t *portp;
4070 unsigned int ioack;
4071 unsigned char misr;
4073 #if DEBUG
4074 printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp);
4075 #endif
4077 ioack = inb(ioaddr + EREG_MDACK);
4078 if (((ioack & panelp->ackmask) != 0) ||
4079 ((ioack & ACK_TYPMASK) != ACK_TYPMDM)) {
4080 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack);
4081 return;
4083 portp = panelp->ports[(ioack >> 3)];
4085 outb((MISR + portp->uartaddr), ioaddr);
4086 misr = inb(ioaddr + EREG_DATA);
4087 if (misr & MISR_DCD) {
4088 set_bit(ASYI_DCDCHANGE, &portp->istate);
4089 queue_task(&portp->tqueue, &tq_scheduler);
4090 portp->stats.modem++;
4093 outb((EOSRR + portp->uartaddr), ioaddr);
4094 outb(0, (ioaddr + EREG_DATA));
4097 /*****************************************************************************/
4098 /* SC26198 HARDWARE FUNCTIONS */
4099 /*****************************************************************************/
4102 * These functions get/set/update the registers of the sc26198 UARTs.
4103 * Access to the sc26198 registers is via an address/data io port pair.
4104 * (Maybe should make this inline...)
4107 static int stl_sc26198getreg(stlport_t *portp, int regnr)
4109 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4110 return(inb(portp->ioaddr + XP_DATA));
4113 static void stl_sc26198setreg(stlport_t *portp, int regnr, int value)
4115 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4116 outb(value, (portp->ioaddr + XP_DATA));
4119 static int stl_sc26198updatereg(stlport_t *portp, int regnr, int value)
4121 outb((regnr | portp->uartaddr), (portp->ioaddr + XP_ADDR));
4122 if (inb(portp->ioaddr + XP_DATA) != value) {
4123 outb(value, (portp->ioaddr + XP_DATA));
4124 return(1);
4126 return(0);
4129 /*****************************************************************************/
4132 * Functions to get and set the sc26198 global registers.
4135 static int stl_sc26198getglobreg(stlport_t *portp, int regnr)
4137 outb(regnr, (portp->ioaddr + XP_ADDR));
4138 return(inb(portp->ioaddr + XP_DATA));
4141 #if 0
4142 static void stl_sc26198setglobreg(stlport_t *portp, int regnr, int value)
4144 outb(regnr, (portp->ioaddr + XP_ADDR));
4145 outb(value, (portp->ioaddr + XP_DATA));
4147 #endif
4149 /*****************************************************************************/
4152 * Inbitialize the UARTs in a panel. We don't care what sort of board
4153 * these ports are on - since the port io registers are almost
4154 * identical when dealing with ports.
4157 static int stl_sc26198panelinit(stlbrd_t *brdp, stlpanel_t *panelp)
4159 int chipmask, i;
4160 int nrchips, ioaddr;
4162 #if DEBUG
4163 printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
4164 (int) brdp, (int) panelp);
4165 #endif
4167 BRDENABLE(panelp->brdnr, panelp->pagenr);
4170 * Check that each chip is present and started up OK.
4172 chipmask = 0;
4173 nrchips = (panelp->nrports + 4) / SC26198_PORTS;
4174 if (brdp->brdtype == BRD_ECHPCI)
4175 outb(panelp->pagenr, brdp->ioctrl);
4177 for (i = 0; (i < nrchips); i++) {
4178 ioaddr = panelp->iobase + (i * 4);
4179 outb(SCCR, (ioaddr + XP_ADDR));
4180 outb(CR_RESETALL, (ioaddr + XP_DATA));
4181 outb(TSTR, (ioaddr + XP_ADDR));
4182 if (inb(ioaddr + XP_DATA) != 0) {
4183 printk("STALLION: sc26198 not responding, "
4184 "brd=%d panel=%d chip=%d\n",
4185 panelp->brdnr, panelp->panelnr, i);
4186 continue;
4188 chipmask |= (0x1 << i);
4189 outb(GCCR, (ioaddr + XP_ADDR));
4190 outb(GCCR_IVRTYPCHANACK, (ioaddr + XP_DATA));
4191 outb(WDTRCR, (ioaddr + XP_ADDR));
4192 outb(0xff, (ioaddr + XP_DATA));
4195 BRDDISABLE(panelp->brdnr);
4196 return(chipmask);
4199 /*****************************************************************************/
4202 * Initialize hardware specific port registers.
4205 static void stl_sc26198portinit(stlbrd_t *brdp, stlpanel_t *panelp, stlport_t *portp)
4207 #if DEBUG
4208 printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
4209 (int) brdp, (int) panelp, (int) portp);
4210 #endif
4212 if ((brdp == (stlbrd_t *) NULL) || (panelp == (stlpanel_t *) NULL) ||
4213 (portp == (stlport_t *) NULL))
4214 return;
4216 portp->ioaddr = panelp->iobase + ((portp->portnr < 8) ? 0 : 4);
4217 portp->uartaddr = (portp->portnr & 0x07) << 4;
4218 portp->pagenr = panelp->pagenr;
4219 portp->hwid = 0x1;
4221 BRDENABLE(portp->brdnr, portp->pagenr);
4222 stl_sc26198setreg(portp, IOPCR, IOPCR_SETSIGS);
4223 BRDDISABLE(portp->brdnr);
4226 /*****************************************************************************/
4229 * Set up the sc26198 registers for a port based on the termios port
4230 * settings.
4233 static void stl_sc26198setport(stlport_t *portp, struct termios *tiosp)
4235 stlbrd_t *brdp;
4236 unsigned long flags;
4237 unsigned int baudrate;
4238 unsigned char mr0, mr1, mr2, clk;
4239 unsigned char imron, imroff, iopr, ipr;
4241 mr0 = 0;
4242 mr1 = 0;
4243 mr2 = 0;
4244 clk = 0;
4245 iopr = 0;
4246 imron = 0;
4247 imroff = 0;
4249 brdp = stl_brds[portp->brdnr];
4250 if (brdp == (stlbrd_t *) NULL)
4251 return;
4254 * Set up the RX char ignore mask with those RX error types we
4255 * can ignore.
4257 portp->rxignoremsk = 0;
4258 if (tiosp->c_iflag & IGNPAR)
4259 portp->rxignoremsk |= (SR_RXPARITY | SR_RXFRAMING |
4260 SR_RXOVERRUN);
4261 if (tiosp->c_iflag & IGNBRK)
4262 portp->rxignoremsk |= SR_RXBREAK;
4264 portp->rxmarkmsk = SR_RXOVERRUN;
4265 if (tiosp->c_iflag & (INPCK | PARMRK))
4266 portp->rxmarkmsk |= (SR_RXPARITY | SR_RXFRAMING);
4267 if (tiosp->c_iflag & BRKINT)
4268 portp->rxmarkmsk |= SR_RXBREAK;
4271 * Go through the char size, parity and stop bits and set all the
4272 * option register appropriately.
4274 switch (tiosp->c_cflag & CSIZE) {
4275 case CS5:
4276 mr1 |= MR1_CS5;
4277 break;
4278 case CS6:
4279 mr1 |= MR1_CS6;
4280 break;
4281 case CS7:
4282 mr1 |= MR1_CS7;
4283 break;
4284 default:
4285 mr1 |= MR1_CS8;
4286 break;
4289 if (tiosp->c_cflag & CSTOPB)
4290 mr2 |= MR2_STOP2;
4291 else
4292 mr2 |= MR2_STOP1;
4294 if (tiosp->c_cflag & PARENB) {
4295 if (tiosp->c_cflag & PARODD)
4296 mr1 |= (MR1_PARENB | MR1_PARODD);
4297 else
4298 mr1 |= (MR1_PARENB | MR1_PAREVEN);
4299 } else {
4300 mr1 |= MR1_PARNONE;
4303 mr1 |= MR1_ERRBLOCK;
4306 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4307 * space for hardware flow control and the like. This should be set to
4308 * VMIN.
4310 mr2 |= MR2_RXFIFOHALF;
4313 * Calculate the baud rate timers. For now we will just assume that
4314 * the input and output baud are the same. The sc26198 has a fixed
4315 * baud rate table, so only discrete baud rates possible.
4317 baudrate = tiosp->c_cflag & CBAUD;
4318 if (baudrate & CBAUDEX) {
4319 baudrate &= ~CBAUDEX;
4320 if ((baudrate < 1) || (baudrate > 4))
4321 tiosp->c_cflag &= ~CBAUDEX;
4322 else
4323 baudrate += 15;
4325 baudrate = stl_baudrates[baudrate];
4326 if ((tiosp->c_cflag & CBAUD) == B38400) {
4327 if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_HI)
4328 baudrate = 57600;
4329 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_VHI)
4330 baudrate = 115200;
4331 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_SHI)
4332 baudrate = 230400;
4333 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_WARP)
4334 baudrate = 460800;
4335 else if ((portp->flags & ASYNC_SPD_MASK) == ASYNC_SPD_CUST)
4336 baudrate = (portp->baud_base / portp->custom_divisor);
4338 if (baudrate > STL_SC26198MAXBAUD)
4339 baudrate = STL_SC26198MAXBAUD;
4341 if (baudrate > 0) {
4342 for (clk = 0; (clk < SC26198_NRBAUDS); clk++) {
4343 if (baudrate <= sc26198_baudtable[clk])
4344 break;
4349 * Check what form of modem signaling is required and set it up.
4351 if (tiosp->c_cflag & CLOCAL) {
4352 portp->flags &= ~ASYNC_CHECK_CD;
4353 } else {
4354 iopr |= IOPR_DCDCOS;
4355 imron |= IR_IOPORT;
4356 portp->flags |= ASYNC_CHECK_CD;
4360 * Setup sc26198 enhanced modes if we can. In particular we want to
4361 * handle as much of the flow control as possible automatically. As
4362 * well as saving a few CPU cycles it will also greatly improve flow
4363 * control reliability.
4365 if (tiosp->c_iflag & IXON) {
4366 mr0 |= MR0_SWFTX | MR0_SWFT;
4367 imron |= IR_XONXOFF;
4368 } else {
4369 imroff |= IR_XONXOFF;
4371 if (tiosp->c_iflag & IXOFF)
4372 mr0 |= MR0_SWFRX;
4374 if (tiosp->c_cflag & CRTSCTS) {
4375 mr2 |= MR2_AUTOCTS;
4376 mr1 |= MR1_AUTORTS;
4380 * All sc26198 register values calculated so go through and set
4381 * them all up.
4384 #if DEBUG
4385 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4386 portp->portnr, portp->panelnr, portp->brdnr);
4387 printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0, mr1, mr2, clk);
4388 printk(" iopr=%x imron=%x imroff=%x\n", iopr, imron, imroff);
4389 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4390 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP],
4391 tiosp->c_cc[VSTART], tiosp->c_cc[VSTOP]);
4392 #endif
4394 save_flags(flags);
4395 cli();
4396 BRDENABLE(portp->brdnr, portp->pagenr);
4397 stl_sc26198setreg(portp, IMR, 0);
4398 stl_sc26198updatereg(portp, MR0, mr0);
4399 stl_sc26198updatereg(portp, MR1, mr1);
4400 stl_sc26198setreg(portp, SCCR, CR_RXERRBLOCK);
4401 stl_sc26198updatereg(portp, MR2, mr2);
4402 stl_sc26198updatereg(portp, IOPIOR,
4403 ((stl_sc26198getreg(portp, IOPIOR) & ~IPR_CHANGEMASK) | iopr));
4405 if (baudrate > 0) {
4406 stl_sc26198setreg(portp, TXCSR, clk);
4407 stl_sc26198setreg(portp, RXCSR, clk);
4410 stl_sc26198setreg(portp, XONCR, tiosp->c_cc[VSTART]);
4411 stl_sc26198setreg(portp, XOFFCR, tiosp->c_cc[VSTOP]);
4413 ipr = stl_sc26198getreg(portp, IPR);
4414 if (ipr & IPR_DCD)
4415 portp->sigs &= ~TIOCM_CD;
4416 else
4417 portp->sigs |= TIOCM_CD;
4419 portp->imr = (portp->imr & ~imroff) | imron;
4420 stl_sc26198setreg(portp, IMR, portp->imr);
4421 BRDDISABLE(portp->brdnr);
4422 restore_flags(flags);
4425 /*****************************************************************************/
4428 * Set the state of the DTR and RTS signals.
4431 static void stl_sc26198setsignals(stlport_t *portp, int dtr, int rts)
4433 unsigned char iopioron, iopioroff;
4434 unsigned long flags;
4436 #if DEBUG
4437 printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4438 (int) portp, dtr, rts);
4439 #endif
4441 iopioron = 0;
4442 iopioroff = 0;
4443 if (dtr == 0)
4444 iopioroff |= IPR_DTR;
4445 else if (dtr > 0)
4446 iopioron |= IPR_DTR;
4447 if (rts == 0)
4448 iopioroff |= IPR_RTS;
4449 else if (rts > 0)
4450 iopioron |= IPR_RTS;
4452 save_flags(flags);
4453 cli();
4454 BRDENABLE(portp->brdnr, portp->pagenr);
4455 stl_sc26198setreg(portp, IOPIOR,
4456 ((stl_sc26198getreg(portp, IOPIOR) & ~iopioroff) | iopioron));
4457 BRDDISABLE(portp->brdnr);
4458 restore_flags(flags);
4461 /*****************************************************************************/
4464 * Return the state of the signals.
4467 static int stl_sc26198getsignals(stlport_t *portp)
4469 unsigned char ipr;
4470 unsigned long flags;
4471 int sigs;
4473 #if DEBUG
4474 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp);
4475 #endif
4477 save_flags(flags);
4478 cli();
4479 BRDENABLE(portp->brdnr, portp->pagenr);
4480 ipr = stl_sc26198getreg(portp, IPR);
4481 BRDDISABLE(portp->brdnr);
4482 restore_flags(flags);
4484 sigs = 0;
4485 sigs |= (ipr & IPR_DCD) ? 0 : TIOCM_CD;
4486 sigs |= (ipr & IPR_CTS) ? 0 : TIOCM_CTS;
4487 sigs |= (ipr & IPR_DTR) ? 0: TIOCM_DTR;
4488 sigs |= (ipr & IPR_RTS) ? 0: TIOCM_RTS;
4489 sigs |= TIOCM_DSR;
4490 return(sigs);
4493 /*****************************************************************************/
4496 * Enable/Disable the Transmitter and/or Receiver.
4499 static void stl_sc26198enablerxtx(stlport_t *portp, int rx, int tx)
4501 unsigned char ccr;
4502 unsigned long flags;
4504 #if DEBUG
4505 printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4506 (int) portp, rx, tx);
4507 #endif
4509 ccr = portp->crenable;
4510 if (tx == 0)
4511 ccr &= ~CR_TXENABLE;
4512 else if (tx > 0)
4513 ccr |= CR_TXENABLE;
4514 if (rx == 0)
4515 ccr &= ~CR_RXENABLE;
4516 else if (rx > 0)
4517 ccr |= CR_RXENABLE;
4519 save_flags(flags);
4520 cli();
4521 BRDENABLE(portp->brdnr, portp->pagenr);
4522 stl_sc26198setreg(portp, SCCR, ccr);
4523 BRDDISABLE(portp->brdnr);
4524 portp->crenable = ccr;
4525 restore_flags(flags);
4528 /*****************************************************************************/
4531 * Start/stop the Transmitter and/or Receiver.
4534 static void stl_sc26198startrxtx(stlport_t *portp, int rx, int tx)
4536 unsigned char imr;
4537 unsigned long flags;
4539 #if DEBUG
4540 printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4541 (int) portp, rx, tx);
4542 #endif
4544 imr = portp->imr;
4545 if (tx == 0)
4546 imr &= ~IR_TXRDY;
4547 else if (tx == 1)
4548 imr |= IR_TXRDY;
4549 if (rx == 0)
4550 imr &= ~(IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG);
4551 else if (rx > 0)
4552 imr |= IR_RXRDY | IR_RXBREAK | IR_RXWATCHDOG;
4554 save_flags(flags);
4555 cli();
4556 BRDENABLE(portp->brdnr, portp->pagenr);
4557 stl_sc26198setreg(portp, IMR, imr);
4558 BRDDISABLE(portp->brdnr);
4559 portp->imr = imr;
4560 if (tx > 0)
4561 set_bit(ASYI_TXBUSY, &portp->istate);
4562 restore_flags(flags);
4565 /*****************************************************************************/
4568 * Disable all interrupts from this port.
4571 static void stl_sc26198disableintrs(stlport_t *portp)
4573 unsigned long flags;
4575 #if DEBUG
4576 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp);
4577 #endif
4579 save_flags(flags);
4580 cli();
4581 BRDENABLE(portp->brdnr, portp->pagenr);
4582 portp->imr = 0;
4583 stl_sc26198setreg(portp, IMR, 0);
4584 BRDDISABLE(portp->brdnr);
4585 restore_flags(flags);
4588 /*****************************************************************************/
4590 static void stl_sc26198sendbreak(stlport_t *portp, int len)
4592 unsigned long flags;
4594 #if DEBUG
4595 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp, len);
4596 #endif
4598 save_flags(flags);
4599 cli();
4600 BRDENABLE(portp->brdnr, portp->pagenr);
4601 if (len == 1) {
4602 stl_sc26198setreg(portp, SCCR, CR_TXSTARTBREAK);
4603 portp->stats.txbreaks++;
4604 } else {
4605 stl_sc26198setreg(portp, SCCR, CR_TXSTOPBREAK);
4607 BRDDISABLE(portp->brdnr);
4608 restore_flags(flags);
4611 /*****************************************************************************/
4614 * Take flow control actions...
4617 static void stl_sc26198flowctrl(stlport_t *portp, int state)
4619 struct tty_struct *tty;
4620 unsigned long flags;
4621 unsigned char mr0;
4623 #if DEBUG
4624 printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp, state);
4625 #endif
4627 if (portp == (stlport_t *) NULL)
4628 return;
4629 tty = portp->tty;
4630 if (tty == (struct tty_struct *) NULL)
4631 return;
4633 save_flags(flags);
4634 cli();
4635 BRDENABLE(portp->brdnr, portp->pagenr);
4637 if (state) {
4638 if (tty->termios->c_iflag & IXOFF) {
4639 mr0 = stl_sc26198getreg(portp, MR0);
4640 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4641 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4642 mr0 |= MR0_SWFRX;
4643 portp->stats.rxxon++;
4644 stl_sc26198wait(portp);
4645 stl_sc26198setreg(portp, MR0, mr0);
4648 * Question: should we return RTS to what it was before? It may
4649 * have been set by an ioctl... Suppose not, since if you have
4650 * hardware flow control set then it is pretty silly to go and
4651 * set the RTS line by hand.
4653 if (tty->termios->c_cflag & CRTSCTS) {
4654 stl_sc26198setreg(portp, MR1,
4655 (stl_sc26198getreg(portp, MR1) | MR1_AUTORTS));
4656 stl_sc26198setreg(portp, IOPIOR,
4657 (stl_sc26198getreg(portp, IOPIOR) | IOPR_RTS));
4658 portp->stats.rxrtson++;
4660 } else {
4661 if (tty->termios->c_iflag & IXOFF) {
4662 mr0 = stl_sc26198getreg(portp, MR0);
4663 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4664 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4665 mr0 &= ~MR0_SWFRX;
4666 portp->stats.rxxoff++;
4667 stl_sc26198wait(portp);
4668 stl_sc26198setreg(portp, MR0, mr0);
4670 if (tty->termios->c_cflag & CRTSCTS) {
4671 stl_sc26198setreg(portp, MR1,
4672 (stl_sc26198getreg(portp, MR1) & ~MR1_AUTORTS));
4673 stl_sc26198setreg(portp, IOPIOR,
4674 (stl_sc26198getreg(portp, IOPIOR) & ~IOPR_RTS));
4675 portp->stats.rxrtsoff++;
4679 BRDDISABLE(portp->brdnr);
4680 restore_flags(flags);
4683 /*****************************************************************************/
4686 * Send a flow control character.
4689 static void stl_sc26198sendflow(stlport_t *portp, int state)
4691 struct tty_struct *tty;
4692 unsigned long flags;
4693 unsigned char mr0;
4695 #if DEBUG
4696 printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp, state);
4697 #endif
4699 if (portp == (stlport_t *) NULL)
4700 return;
4701 tty = portp->tty;
4702 if (tty == (struct tty_struct *) NULL)
4703 return;
4705 save_flags(flags);
4706 cli();
4707 BRDENABLE(portp->brdnr, portp->pagenr);
4708 if (state) {
4709 mr0 = stl_sc26198getreg(portp, MR0);
4710 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4711 stl_sc26198setreg(portp, SCCR, CR_TXSENDXON);
4712 mr0 |= MR0_SWFRX;
4713 portp->stats.rxxon++;
4714 stl_sc26198wait(portp);
4715 stl_sc26198setreg(portp, MR0, mr0);
4716 } else {
4717 mr0 = stl_sc26198getreg(portp, MR0);
4718 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4719 stl_sc26198setreg(portp, SCCR, CR_TXSENDXOFF);
4720 mr0 &= ~MR0_SWFRX;
4721 portp->stats.rxxoff++;
4722 stl_sc26198wait(portp);
4723 stl_sc26198setreg(portp, MR0, mr0);
4725 BRDDISABLE(portp->brdnr);
4726 restore_flags(flags);
4729 /*****************************************************************************/
4731 static void stl_sc26198flush(stlport_t *portp)
4733 unsigned long flags;
4735 #if DEBUG
4736 printk("stl_sc26198flush(portp=%x)\n", (int) portp);
4737 #endif
4739 if (portp == (stlport_t *) NULL)
4740 return;
4742 save_flags(flags);
4743 cli();
4744 BRDENABLE(portp->brdnr, portp->pagenr);
4745 stl_sc26198setreg(portp, SCCR, CR_TXRESET);
4746 stl_sc26198setreg(portp, SCCR, portp->crenable);
4747 BRDDISABLE(portp->brdnr);
4748 portp->tx.tail = portp->tx.head;
4749 restore_flags(flags);
4752 /*****************************************************************************/
4755 * Return the current state of data flow on this port. This is only
4756 * really interresting when determining if data has fully completed
4757 * transmission or not... The sc26198 interrupt scheme cannot
4758 * determine when all data has actually drained, so we need to
4759 * check the port statusy register to be sure.
4762 static int stl_sc26198datastate(stlport_t *portp)
4764 unsigned long flags;
4765 unsigned char sr;
4767 #if DEBUG
4768 printk("stl_sc26198datastate(portp=%x)\n", (int) portp);
4769 #endif
4771 if (portp == (stlport_t *) NULL)
4772 return(0);
4773 if (test_bit(ASYI_TXBUSY, &portp->istate))
4774 return(1);
4776 save_flags(flags);
4777 cli();
4778 BRDENABLE(portp->brdnr, portp->pagenr);
4779 sr = stl_sc26198getreg(portp, SR);
4780 BRDDISABLE(portp->brdnr);
4781 restore_flags(flags);
4783 return((sr & SR_TXEMPTY) ? 0 : 1);
4786 /*****************************************************************************/
4789 * Delay for a small amount of time, to give the sc26198 a chance
4790 * to process a command...
4793 static void stl_sc26198wait(stlport_t *portp)
4795 int i;
4797 #if DEBUG
4798 printk("stl_sc26198wait(portp=%x)\n", (int) portp);
4799 #endif
4801 if (portp == (stlport_t *) NULL)
4802 return;
4804 for (i = 0; (i < 20); i++)
4805 stl_sc26198getglobreg(portp, TSTR);
4808 /*****************************************************************************/
4811 * If we are TX flow controlled and in IXANY mode then we may
4812 * need to unflow control here. We gotta do this because of the
4813 * automatic flow control modes of the sc26198.
4816 static inline void stl_sc26198txunflow(stlport_t *portp, struct tty_struct *tty)
4818 unsigned char mr0;
4820 mr0 = stl_sc26198getreg(portp, MR0);
4821 stl_sc26198setreg(portp, MR0, (mr0 & ~MR0_SWFRXTX));
4822 stl_sc26198setreg(portp, SCCR, CR_HOSTXON);
4823 stl_sc26198wait(portp);
4824 stl_sc26198setreg(portp, MR0, mr0);
4825 clear_bit(ASYI_TXFLOWED, &portp->istate);
4828 /*****************************************************************************/
4831 * Interrupt service routine for sc26198 panels.
4834 static void stl_sc26198intr(stlpanel_t *panelp, unsigned int iobase)
4836 stlport_t *portp;
4837 unsigned int iack;
4840 * Work around bug in sc26198 chip... Cannot have A6 address
4841 * line of UART high, else iack will be returned as 0.
4843 outb(0, (iobase + 1));
4845 iack = inb(iobase + XP_IACK);
4846 portp = panelp->ports[(iack & IVR_CHANMASK) + ((iobase & 0x4) << 1)];
4848 if (iack & IVR_RXDATA)
4849 stl_sc26198rxisr(portp, iack);
4850 else if (iack & IVR_TXDATA)
4851 stl_sc26198txisr(portp);
4852 else
4853 stl_sc26198otherisr(portp, iack);
4856 /*****************************************************************************/
4859 * Transmit interrupt handler. This has gotta be fast! Handling TX
4860 * chars is pretty simple, stuff as many as possible from the TX buffer
4861 * into the sc26198 FIFO.
4862 * In practice it is possible that interrupts are enabled but that the
4863 * port has been hung up. Need to handle not having any TX buffer here,
4864 * this is done by using the side effect that head and tail will also
4865 * be NULL if the buffer has been freed.
4868 static void stl_sc26198txisr(stlport_t *portp)
4870 unsigned int ioaddr;
4871 unsigned char mr0;
4872 int len, stlen;
4873 char *head, *tail;
4875 #if DEBUG
4876 printk("stl_sc26198txisr(portp=%x)\n", (int) portp);
4877 #endif
4879 ioaddr = portp->ioaddr;
4880 head = portp->tx.head;
4881 tail = portp->tx.tail;
4882 len = (head >= tail) ? (head - tail) : (STL_TXBUFSIZE - (tail - head));
4883 if ((len == 0) || ((len < STL_TXBUFLOW) &&
4884 (test_bit(ASYI_TXLOW, &portp->istate) == 0))) {
4885 set_bit(ASYI_TXLOW, &portp->istate);
4886 queue_task(&portp->tqueue, &tq_scheduler);
4889 if (len == 0) {
4890 outb((MR0 | portp->uartaddr), (ioaddr + XP_ADDR));
4891 mr0 = inb(ioaddr + XP_DATA);
4892 if ((mr0 & MR0_TXMASK) == MR0_TXEMPTY) {
4893 portp->imr &= ~IR_TXRDY;
4894 outb((IMR | portp->uartaddr), (ioaddr + XP_ADDR));
4895 outb(portp->imr, (ioaddr + XP_DATA));
4896 clear_bit(ASYI_TXBUSY, &portp->istate);
4897 } else {
4898 mr0 |= ((mr0 & ~MR0_TXMASK) | MR0_TXEMPTY);
4899 outb(mr0, (ioaddr + XP_DATA));
4901 } else {
4902 len = MIN(len, SC26198_TXFIFOSIZE);
4903 portp->stats.txtotal += len;
4904 stlen = MIN(len, ((portp->tx.buf + STL_TXBUFSIZE) - tail));
4905 outb(GTXFIFO, (ioaddr + XP_ADDR));
4906 outsb((ioaddr + XP_DATA), tail, stlen);
4907 len -= stlen;
4908 tail += stlen;
4909 if (tail >= (portp->tx.buf + STL_TXBUFSIZE))
4910 tail = portp->tx.buf;
4911 if (len > 0) {
4912 outsb((ioaddr + XP_DATA), tail, len);
4913 tail += len;
4915 portp->tx.tail = tail;
4919 /*****************************************************************************/
4922 * Receive character interrupt handler. Determine if we have good chars
4923 * or bad chars and then process appropriately. Good chars are easy
4924 * just shove the lot into the RX buffer and set all status byte to 0.
4925 * If a bad RX char then process as required. This routine needs to be
4926 * fast! In practice it is possible that we get an interrupt on a port
4927 * that is closed. This can happen on hangups - since they completely
4928 * shutdown a port not in user context. Need to handle this case.
4931 static void stl_sc26198rxisr(stlport_t *portp, unsigned int iack)
4933 struct tty_struct *tty;
4934 unsigned int len, buflen, ioaddr;
4936 #if DEBUG
4937 printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp, iack);
4938 #endif
4940 tty = portp->tty;
4941 ioaddr = portp->ioaddr;
4942 outb(GIBCR, (ioaddr + XP_ADDR));
4943 len = inb(ioaddr + XP_DATA) + 1;
4945 if ((iack & IVR_TYPEMASK) == IVR_RXDATA) {
4946 if ((tty == (struct tty_struct *) NULL) ||
4947 (tty->flip.char_buf_ptr == (char *) NULL) ||
4948 ((buflen = TTY_FLIPBUF_SIZE - tty->flip.count) == 0)) {
4949 outb(GRXFIFO, (ioaddr + XP_ADDR));
4950 insb((ioaddr + XP_DATA), &stl_unwanted[0], len);
4951 portp->stats.rxlost += len;
4952 portp->stats.rxtotal += len;
4953 } else {
4954 len = MIN(len, buflen);
4955 if (len > 0) {
4956 outb(GRXFIFO, (ioaddr + XP_ADDR));
4957 insb((ioaddr + XP_DATA), tty->flip.char_buf_ptr, len);
4958 memset(tty->flip.flag_buf_ptr, 0, len);
4959 tty->flip.flag_buf_ptr += len;
4960 tty->flip.char_buf_ptr += len;
4961 tty->flip.count += len;
4962 tty_schedule_flip(tty);
4963 portp->stats.rxtotal += len;
4966 } else {
4967 stl_sc26198rxbadchars(portp);
4971 * If we are TX flow controlled and in IXANY mode then we may need
4972 * to unflow control here. We gotta do this because of the automatic
4973 * flow control modes of the sc26198.
4975 if (test_bit(ASYI_TXFLOWED, &portp->istate)) {
4976 if ((tty != (struct tty_struct *) NULL) &&
4977 (tty->termios != (struct termios *) NULL) &&
4978 (tty->termios->c_iflag & IXANY)) {
4979 stl_sc26198txunflow(portp, tty);
4984 /*****************************************************************************/
4987 * Process an RX bad character.
4990 static void inline stl_sc26198rxbadch(stlport_t *portp, unsigned char status, char ch)
4992 struct tty_struct *tty;
4993 unsigned int ioaddr;
4995 tty = portp->tty;
4996 ioaddr = portp->ioaddr;
4998 if (status & SR_RXPARITY)
4999 portp->stats.rxparity++;
5000 if (status & SR_RXFRAMING)
5001 portp->stats.rxframing++;
5002 if (status & SR_RXOVERRUN)
5003 portp->stats.rxoverrun++;
5004 if (status & SR_RXBREAK)
5005 portp->stats.rxbreaks++;
5007 if ((tty != (struct tty_struct *) NULL) &&
5008 ((portp->rxignoremsk & status) == 0)) {
5009 if (portp->rxmarkmsk & status) {
5010 if (status & SR_RXBREAK) {
5011 status = TTY_BREAK;
5012 if (portp->flags & ASYNC_SAK) {
5013 do_SAK(tty);
5014 BRDENABLE(portp->brdnr, portp->pagenr);
5016 } else if (status & SR_RXPARITY) {
5017 status = TTY_PARITY;
5018 } else if (status & SR_RXFRAMING) {
5019 status = TTY_FRAME;
5020 } else if(status & SR_RXOVERRUN) {
5021 status = TTY_OVERRUN;
5022 } else {
5023 status = 0;
5025 } else {
5026 status = 0;
5029 if (tty->flip.char_buf_ptr != (char *) NULL) {
5030 if (tty->flip.count < TTY_FLIPBUF_SIZE) {
5031 *tty->flip.flag_buf_ptr++ = status;
5032 *tty->flip.char_buf_ptr++ = ch;
5033 tty->flip.count++;
5035 tty_schedule_flip(tty);
5038 if (status == 0)
5039 portp->stats.rxtotal++;
5043 /*****************************************************************************/
5046 * Process all characters in the RX FIFO of the UART. Check all char
5047 * status bytes as well, and process as required. We need to check
5048 * all bytes in the FIFO, in case some more enter the FIFO while we
5049 * are here. To get the exact character error type we need to switch
5050 * into CHAR error mode (that is why we need to make sure we empty
5051 * the FIFO).
5054 static void stl_sc26198rxbadchars(stlport_t *portp)
5056 unsigned char status, mr1;
5057 char ch;
5060 * To get the precise error type for each character we must switch
5061 * back into CHAR error mode.
5063 mr1 = stl_sc26198getreg(portp, MR1);
5064 stl_sc26198setreg(portp, MR1, (mr1 & ~MR1_ERRBLOCK));
5066 while ((status = stl_sc26198getreg(portp, SR)) & SR_RXRDY) {
5067 stl_sc26198setreg(portp, SCCR, CR_CLEARRXERR);
5068 ch = stl_sc26198getreg(portp, RXFIFO);
5069 stl_sc26198rxbadch(portp, status, ch);
5073 * To get correct interrupt class we must switch back into BLOCK
5074 * error mode.
5076 stl_sc26198setreg(portp, MR1, mr1);
5079 /*****************************************************************************/
5082 * Other interrupt handler. This includes modem signals, flow
5083 * control actions, etc. Most stuff is left to off-level interrupt
5084 * processing time.
5087 static void stl_sc26198otherisr(stlport_t *portp, unsigned int iack)
5089 unsigned char cir, ipr, xisr;
5091 #if DEBUG
5092 printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp, iack);
5093 #endif
5095 cir = stl_sc26198getglobreg(portp, CIR);
5097 switch (cir & CIR_SUBTYPEMASK) {
5098 case CIR_SUBCOS:
5099 ipr = stl_sc26198getreg(portp, IPR);
5100 if (ipr & IPR_DCDCHANGE) {
5101 set_bit(ASYI_DCDCHANGE, &portp->istate);
5102 queue_task(&portp->tqueue, &tq_scheduler);
5103 portp->stats.modem++;
5105 break;
5106 case CIR_SUBXONXOFF:
5107 xisr = stl_sc26198getreg(portp, XISR);
5108 if (xisr & XISR_RXXONGOT) {
5109 set_bit(ASYI_TXFLOWED, &portp->istate);
5110 portp->stats.txxoff++;
5112 if (xisr & XISR_RXXOFFGOT) {
5113 clear_bit(ASYI_TXFLOWED, &portp->istate);
5114 portp->stats.txxon++;
5116 break;
5117 case CIR_SUBBREAK:
5118 stl_sc26198setreg(portp, SCCR, CR_BREAKRESET);
5119 stl_sc26198rxbadchars(portp);
5120 break;
5121 default:
5122 break;
5126 /*****************************************************************************/