1 /*****************************************************************************/
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>
53 #include <asm/uaccess.h>
56 #include <linux/pci.h>
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.
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).
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.
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.
102 unsigned long memaddr
;
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
122 #ifndef STL_SERIALMAJOR
123 #define STL_SERIALMAJOR 24
125 #ifndef STL_CALLOUTMAJOR
126 #define STL_CALLOUTMAJOR 25
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
),
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
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
[] = {
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
272 #define EIO_IDBITMASK 0x07
274 #define EIO_BRDMASK 0xf0
277 #define ID_BRD16 0x30
279 #define EIO_INTRPEND 0x08
280 #define EIO_INTEDGE 0x00
281 #define EIO_INTLEVEL 0x08
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 /*****************************************************************************/
346 * Define the Stallion PCI vendor and device IDs.
348 #ifndef PCI_VENDOR_ID_STALLION
349 #define PCI_VENDOR_ID_STALLION 0x124d
351 #ifndef PCI_DEVICE_ID_ECHPCI832
352 #define PCI_DEVICE_ID_ECHPCI832 0x0000
354 #ifndef PCI_DEVICE_ID_ECHPCI864
355 #define PCI_DEVICE_ID_ECHPCI864 0x0002
357 #ifndef PCI_DEVICE_ID_EIOPCI
358 #define PCI_DEVICE_ID_EIOPCI 0x0003
362 * Define structure to hold all Stallion PCI boards.
364 typedef struct stlpcibrd
{
365 unsigned short vendid
;
366 unsigned short devid
;
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
);
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...
403 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
406 /*****************************************************************************/
409 * Declare all those functions in this driver!
413 int init_module(void);
414 void cleanup_module(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
);
469 static inline int stl_findpcibrds(void);
470 static inline int stl_initpcibrd(int brdtype
, struct pci_dev
*dev
);
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
);
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
= {
578 stl_cd1400getsignals
,
579 stl_cd1400setsignals
,
580 stl_cd1400enablerxtx
,
582 stl_cd1400disableintrs
,
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.
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
,
624 stl_sc26198getsignals
,
625 stl_sc26198setsignals
,
626 stl_sc26198enablerxtx
,
627 stl_sc26198startrxtx
,
628 stl_sc26198disableintrs
,
629 stl_sc26198sendbreak
,
633 stl_sc26198datastate
,
638 * Define the offsets within the register bank of a sc26198 based panel.
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
= {
680 /*****************************************************************************/
685 * Loadable module initialization stuff.
693 printk("init_module()\n");
699 restore_flags(flags
);
704 /*****************************************************************************/
706 void cleanup_module()
715 printk("cleanup_module()\n");
718 printk(KERN_INFO
"Unloading %s: version %s\n", stl_drvtitle
,
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
);
733 printk("STALLION: failed to un-register tty driver, "
734 "errno=%d,%d\n", -i
, -j
);
735 restore_flags(flags
);
738 if ((i
= unregister_chrdev(STL_SIOMEMMAJOR
, "staliomem")))
739 printk("STALLION: failed to un-register serial memory device, "
742 if (stl_tmpwritebuf
!= (char *) NULL
)
743 kfree_s(stl_tmpwritebuf
, STL_TXBUFSIZE
);
745 for (i
= 0; (i
< stl_nrbrds
); i
++) {
747 for (j
= 0; (j
< STL_MAXPANELS
); j
++) {
748 panelp
= brdp
->panels
[j
];
749 if (panelp
== (stlpanel_t
*) NULL
)
751 for (k
= 0; (k
< STL_PORTSPERPANEL
); k
++) {
752 portp
= panelp
->ports
[k
];
753 if (portp
== (stlport_t
*) NULL
)
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
);
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
)
797 unsigned int minordev
;
798 int brdnr
, panelnr
, portnr
, rc
;
801 printk("stl_open(tty=%x,filp=%x): device=%x\n", (int) tty
,
802 (int) filp
, tty
->device
);
805 minordev
= MINOR(tty
->device
);
806 brdnr
= MINOR2BRD(minordev
);
807 if (brdnr
>= stl_nrbrds
)
809 brdp
= stl_brds
[brdnr
];
810 if (brdp
== (stlbrd_t
*) NULL
)
812 minordev
= MINOR2PORT(minordev
);
813 for (portnr
= -1, panelnr
= 0; (panelnr
< STL_MAXPANELS
); panelnr
++) {
814 if (brdp
->panels
[panelnr
] == (stlpanel_t
*) NULL
)
816 if (minordev
< brdp
->panels
[panelnr
]->nrports
) {
820 minordev
-= brdp
->panels
[panelnr
]->nrports
;
825 portp
= brdp
->panels
[panelnr
]->ports
[portnr
];
826 if (portp
== (stlport_t
*) NULL
)
832 * On the first open of the device setup the port hardware, and
833 * initialize the per port data structure.
836 tty
->driver_data
= portp
;
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
)
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
)
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
)
877 if (portp
->flags
& ASYNC_CALLOUT_ACTIVE
) {
878 if ((portp
->flags
& ASYNC_SESSION_LOCKOUT
) &&
879 (portp
->session
!= current
->session
))
881 if ((portp
->flags
& ASYNC_PGRP_LOCKOUT
) &&
882 (portp
->pgrp
!= current
->pgrp
))
885 portp
->flags
|= ASYNC_CALLOUT_ACTIVE
;
887 if (filp
->f_flags
& O_NONBLOCK
) {
888 if (portp
->flags
& ASYNC_CALLOUT_ACTIVE
)
891 if ((rc
= stl_waitcarrier(portp
, filp
)) != 0)
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
;
901 *tty
->termios
= portp
->callouttermios
;
902 stl_setport(portp
, tty
->termios
);
905 portp
->session
= current
->session
;
906 portp
->pgrp
= current
->pgrp
;
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
)
923 printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp
, (int) filp
);
929 if (portp
->flags
& ASYNC_CALLOUT_ACTIVE
) {
930 if (portp
->normaltermios
.c_cflag
& CLOCAL
)
933 if (portp
->tty
->termios
->c_cflag
& CLOCAL
)
939 portp
->openwaitcnt
++;
940 if (! tty_hung_up_p(filp
))
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
)
954 if (((portp
->flags
& ASYNC_CALLOUT_ACTIVE
) == 0) &&
955 ((portp
->flags
& ASYNC_CLOSING
) == 0) &&
956 (doclocal
|| (portp
->sigs
& TIOCM_CD
))) {
959 if (signal_pending(current
)) {
963 interruptible_sleep_on(&portp
->open_wait
);
966 if (! tty_hung_up_p(filp
))
968 portp
->openwaitcnt
--;
969 restore_flags(flags
);
974 /*****************************************************************************/
976 static void stl_close(struct tty_struct
*tty
, struct file
*filp
)
982 printk("stl_close(tty=%x,filp=%x)\n", (int) tty
, (int) filp
);
985 portp
= tty
->driver_data
;
986 if (portp
== (stlport_t
*) NULL
)
991 if (tty_hung_up_p(filp
)) {
993 restore_flags(flags
);
996 if ((tty
->count
== 1) && (portp
->refcount
!= 1))
998 if (portp
->refcount
-- > 1) {
1000 restore_flags(flags
);
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)
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
);
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
);
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
|
1051 wake_up_interruptible(&portp
->close_wait
);
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
)
1067 printk("stl_delay(len=%d)\n", len
);
1070 current
->state
= TASK_INTERRUPTIBLE
;
1071 current
->timeout
= jiffies
+ len
;
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
)
1087 unsigned int len
, stlen
;
1088 unsigned char *chbuf
;
1092 printk("stl_write(tty=%x,from_user=%d,buf=%x,count=%d)\n",
1093 (int) tty
, from_user
, (int) buf
, count
);
1096 if ((tty
== (struct tty_struct
*) NULL
) ||
1097 (stl_tmpwritebuf
== (char *) NULL
))
1099 portp
= tty
->driver_data
;
1100 if (portp
== (stlport_t
*) NULL
)
1102 if (portp
->tx
.buf
== (char *) NULL
)
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
;
1113 head
= portp
->tx
.head
;
1114 tail
= portp
->tx
.tail
;
1115 len
= (head
>= tail
) ? (STL_TXBUFSIZE
- (head
- tail
) - 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
;
1128 len
= STL_TXBUFSIZE
- (head
- tail
) - 1;
1129 stlen
= STL_TXBUFSIZE
- (head
- portp
->tx
.buf
);
1131 len
= tail
- head
- 1;
1135 len
= MIN(len
, count
);
1138 stlen
= MIN(len
, stlen
);
1139 memcpy(head
, chbuf
, 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);
1157 /*****************************************************************************/
1159 static void stl_putchar(struct tty_struct
*tty
, unsigned char ch
)
1166 printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty
, (int) ch
);
1169 if (tty
== (struct tty_struct
*) NULL
)
1171 portp
= tty
->driver_data
;
1172 if (portp
== (stlport_t
*) NULL
)
1174 if (portp
->tx
.buf
== (char *) NULL
)
1177 head
= portp
->tx
.head
;
1178 tail
= portp
->tx
.tail
;
1180 len
= (head
>= tail
) ? (STL_TXBUFSIZE
- (head
- tail
)) : (tail
- head
);
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
)
1204 printk("stl_flushchars(tty=%x)\n", (int) tty
);
1207 if (tty
== (struct tty_struct
*) NULL
)
1209 portp
= tty
->driver_data
;
1210 if (portp
== (stlport_t
*) NULL
)
1212 if (portp
->tx
.buf
== (char *) NULL
)
1216 if (tty
->stopped
|| tty
->hw_stopped
||
1217 (portp
->tx
.head
== portp
->tx
.tail
))
1220 stl_startrxtx(portp
, -1, 1);
1223 /*****************************************************************************/
1225 static int stl_writeroom(struct tty_struct
*tty
)
1231 printk("stl_writeroom(tty=%x)\n", (int) tty
);
1234 if (tty
== (struct tty_struct
*) NULL
)
1236 portp
= tty
->driver_data
;
1237 if (portp
== (stlport_t
*) NULL
)
1239 if (portp
->tx
.buf
== (char *) NULL
)
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
)
1265 printk("stl_charsinbuffer(tty=%x)\n", (int) tty
);
1268 if (tty
== (struct tty_struct
*) NULL
)
1270 portp
= tty
->driver_data
;
1271 if (portp
== (stlport_t
*) NULL
)
1273 if (portp
->tx
.buf
== (char *) NULL
)
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
))
1284 /*****************************************************************************/
1287 * Generate the serial struct info.
1290 static void stl_getserial(stlport_t
*portp
, struct serial_struct
*sp
)
1292 struct serial_struct sio
;
1296 printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp
, (int) sp
);
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
;
1308 if (portp
->uartp
== &stl_cd1400uart
) {
1309 sio
.type
= PORT_CIRRUS
;
1310 sio
.xmit_fifo_size
= CD1400_TXFIFOSIZE
;
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
;
1336 printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp
, (int) sp
);
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
)))
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
);
1358 /*****************************************************************************/
1360 static int stl_ioctl(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
1367 printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
1368 (int) tty
, (int) file
, cmd
, (int) arg
);
1371 if (tty
== (struct tty_struct
*) NULL
)
1373 portp
= tty
->driver_data
;
1374 if (portp
== (stlport_t
*) NULL
)
1377 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1378 (cmd
!= COM_GETPORTSTATS
) && (cmd
!= COM_CLRPORTSTATS
)) {
1379 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1387 rc
= put_user(((tty
->termios
->c_cflag
& CLOCAL
) ? 1 : 0),
1388 (unsigned int *) arg
);
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);
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
);
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));
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));
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));
1431 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
1432 sizeof(struct serial_struct
))) == 0)
1433 stl_getserial(portp
, (struct serial_struct
*) arg
);
1436 if ((rc
= verify_area(VERIFY_READ
, (void *) arg
,
1437 sizeof(struct serial_struct
))) == 0)
1438 rc
= stl_setserial(portp
, (struct serial_struct
*) arg
);
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
);
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
);
1454 case TIOCSERGSTRUCT
:
1455 case TIOCSERGETMULTI
:
1456 case TIOCSERSETMULTI
:
1465 /*****************************************************************************/
1467 static void stl_settermios(struct tty_struct
*tty
, struct termios
*old
)
1470 struct termios
*tiosp
;
1473 printk("stl_settermios(tty=%x,old=%x)\n", (int) tty
, (int) old
);
1476 if (tty
== (struct tty_struct
*) NULL
)
1478 portp
= tty
->driver_data
;
1479 if (portp
== (stlport_t
*) NULL
)
1482 tiosp
= tty
->termios
;
1483 if ((tiosp
->c_cflag
== old
->c_cflag
) &&
1484 (tiosp
->c_iflag
== old
->c_iflag
))
1487 stl_setport(portp
, tiosp
);
1488 stl_setsignals(portp
, ((tiosp
->c_cflag
& (CBAUD
& ~CBAUDEX
)) ? 1 : 0),
1490 if ((old
->c_cflag
& CRTSCTS
) && ((tiosp
->c_cflag
& CRTSCTS
) == 0)) {
1491 tty
->hw_stopped
= 0;
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
)
1510 printk("stl_throttle(tty=%x)\n", (int) tty
);
1513 if (tty
== (struct tty_struct
*) NULL
)
1515 portp
= tty
->driver_data
;
1516 if (portp
== (stlport_t
*) NULL
)
1518 stl_flowctrl(portp
, 0);
1521 /*****************************************************************************/
1524 * Unflow control the device sending us data...
1527 static void stl_unthrottle(struct tty_struct
*tty
)
1532 printk("stl_unthrottle(tty=%x)\n", (int) tty
);
1535 if (tty
== (struct tty_struct
*) NULL
)
1537 portp
= tty
->driver_data
;
1538 if (portp
== (stlport_t
*) NULL
)
1540 stl_flowctrl(portp
, 1);
1543 /*****************************************************************************/
1546 * Stop the transmitter. Basically to do this we will just turn TX
1550 static void stl_stop(struct tty_struct
*tty
)
1555 printk("stl_stop(tty=%x)\n", (int) tty
);
1558 if (tty
== (struct tty_struct
*) NULL
)
1560 portp
= tty
->driver_data
;
1561 if (portp
== (stlport_t
*) NULL
)
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
)
1577 printk("stl_start(tty=%x)\n", (int) tty
);
1580 if (tty
== (struct tty_struct
*) NULL
)
1582 portp
= tty
->driver_data
;
1583 if (portp
== (stlport_t
*) NULL
)
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
)
1601 printk("stl_hangup(tty=%x)\n", (int) tty
);
1604 if (tty
== (struct tty_struct
*) NULL
)
1606 portp
= tty
->driver_data
;
1607 if (portp
== (stlport_t
*) NULL
)
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
);
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
)
1637 printk("stl_flushbuffer(tty=%x)\n", (int) tty
);
1640 if (tty
== (struct tty_struct
*) NULL
)
1642 portp
= tty
->driver_data
;
1643 if (portp
== (stlport_t
*) NULL
)
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
)
1660 printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty
, state
);
1663 if (tty
== (struct tty_struct
*) NULL
)
1665 portp
= tty
->driver_data
;
1666 if (portp
== (stlport_t
*) NULL
)
1669 stl_sendbreak(portp
, ((state
== -1) ? 1 : 2));
1672 /*****************************************************************************/
1674 static void stl_waituntilsent(struct tty_struct
*tty
, int timeout
)
1680 printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty
, timeout
);
1683 if (tty
== (struct tty_struct
*) NULL
)
1685 portp
= tty
->driver_data
;
1686 if (portp
== (stlport_t
*) NULL
)
1691 tend
= jiffies
+ timeout
;
1693 while (stl_datastate(portp
)) {
1694 if (signal_pending(current
))
1697 if (jiffies
>= tend
)
1702 /*****************************************************************************/
1704 static void stl_sendxchar(struct tty_struct
*tty
, char ch
)
1709 printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty
, ch
);
1712 if (tty
== (struct tty_struct
*) NULL
)
1714 portp
= tty
->driver_data
;
1715 if (portp
== (stlport_t
*) NULL
)
1718 if (ch
== STOP_CHAR(tty
))
1719 stl_sendflow(portp
, 0);
1720 else if (ch
== START_CHAR(tty
))
1721 stl_sendflow(portp
, 1);
1723 stl_putchar(tty
, ch
);
1726 /*****************************************************************************/
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
)
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" : "");
1765 for (cnt
= (sp
- pos
); (cnt
< (MAXLINE
- 1)); cnt
++)
1768 pos
[(MAXLINE
- 2)] = '+';
1769 pos
[(MAXLINE
- 1)] = '\n';
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
)
1785 int brdnr
, panelnr
, portnr
, totalport
;
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
);
1800 pos
+= sprintf(pos
, "%s: version %s", stl_drvtitle
,
1802 while (pos
< (page
+ MAXLINE
- 1))
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
)
1816 if (brdp
->state
== 0)
1819 maxoff
= curoff
+ (brdp
->nrports
* MAXLINE
);
1820 if (off
>= maxoff
) {
1825 totalport
= brdnr
* STL_MAXPORTS
;
1826 for (panelnr
= 0; (panelnr
< brdp
->nrpanels
); panelnr
++) {
1827 panelp
= brdp
->panels
[panelnr
];
1828 if (panelp
== (stlpanel_t
*) NULL
)
1831 maxoff
= curoff
+ (panelp
->nrports
* MAXLINE
);
1832 if (off
>= maxoff
) {
1834 totalport
+= panelp
->nrports
;
1838 for (portnr
= 0; (portnr
< panelp
->nrports
); portnr
++,
1840 portp
= panelp
->ports
[portnr
];
1841 if (portp
== (stlport_t
*) NULL
)
1843 if (off
>= (curoff
+= MAXLINE
))
1845 if ((pos
- page
+ MAXLINE
) > count
)
1847 pos
+= stl_portinfo(portp
, totalport
, pos
);
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
)
1872 printk("stl_intr(irq=%d,regs=%x)\n", irq
, (int) regs
);
1875 for (i
= 0; (i
< stl_nrbrds
); i
++) {
1876 if ((brdp
= stl_brds
[i
]) == (stlbrd_t
*) NULL
)
1878 if (brdp
->state
== 0)
1880 (* brdp
->isr
)(brdp
);
1884 /*****************************************************************************/
1887 * Interrupt service routine for EasyIO board types.
1890 static void stl_eiointr(stlbrd_t
*brdp
)
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
)
1910 unsigned int ioaddr
;
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
)
1937 unsigned int ioaddr
;
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
)
1960 unsigned int ioaddr
;
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));
1979 /*****************************************************************************/
1982 * Interrupt service routine for ECH-8/64-PCI board types.
1985 static void stl_echpci64intr(stlbrd_t
*brdp
)
1988 unsigned int ioaddr
;
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)
2010 struct tty_struct
*tty
;
2011 unsigned int oldsigs
;
2016 printk("stl_offintr(portp=%x)\n", (int) portp
);
2019 if (portp
== (stlport_t
*) NULL
)
2023 if (tty
== (struct tty_struct
*) NULL
)
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
))) {
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
))
2064 printk("stl_mapirq(irq=%d,name=%s)\n", irq
, name
);
2068 for (i
= 0; (i
< stl_numintrs
); i
++) {
2069 if (stl_gotintrs
[i
] == irq
)
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
);
2078 stl_gotintrs
[stl_numintrs
++] = irq
;
2084 /*****************************************************************************/
2087 * Initialize all the ports on a panel.
2090 __initfunc(static int stl_initports(stlbrd_t
*brdp
, stlpanel_t
*panelp
))
2096 printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp
, (int) panelp
);
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
));
2112 memset(portp
, 0, sizeof(stlport_t
));
2114 portp
->magic
= STL_PORTMAGIC
;
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
);
2137 /*****************************************************************************/
2140 * Try to find and initialize an EasyIO board.
2143 static inline int stl_initeio(stlbrd_t
*brdp
)
2146 unsigned int status
;
2151 printk("stl_initeio(brdp=%x)\n", (int) brdp
);
2154 brdp
->ioctrl
= brdp
->ioaddr1
+ 1;
2155 brdp
->iostatus
= brdp
->ioaddr1
+ 2;
2157 status
= inb(brdp
->iostatus
);
2158 if ((status
& EIO_IDBITMASK
) == EIO_MK3
)
2162 * Handle board specific stuff now. The real difference is 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));
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
);
2179 outb((stl_vecmap
[brdp
->irq
] | EIO_0WS
|
2180 ((brdp
->irqtype
) ? EIO_INTLEVEL
: EIO_INTEDGE
)),
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
) {
2204 brdp
->clk
= CD1400_CLK8M
;
2214 switch (status
& EIO_BRDMASK
) {
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
));
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
;
2258 panelp
->uartp
= (void *) &stl_cd1400uart
;
2259 panelp
->isr
= stl_cd1400eiointr
;
2262 brdp
->panels
[0] = panelp
;
2264 brdp
->state
|= BRD_FOUND
;
2265 brdp
->hwid
= status
;
2266 rc
= stl_mapirq(brdp
->irq
, name
);
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
)
2280 unsigned int status
, nxtid
, ioaddr
, conflict
;
2281 int panelnr
, banknr
, i
;
2285 printk("stl_initech(brdp=%x)\n", (int) brdp
);
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
) {
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
)
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
);
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
);
2320 name
= "serial(EC8/32)";
2321 outb(status
, brdp
->ioaddr1
);
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
)
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
);
2337 outb(ECHMC_BRDRESET
, brdp
->ioctrl
);
2338 outb(ECHMC_INTENABLE
, brdp
->ioctrl
);
2340 name
= "serial(EC8/32-MC)";
2344 brdp
->isr
= stl_echpciintr
;
2345 brdp
->ioctrl
= brdp
->ioaddr1
+ 2;
2348 name
= "serial(EC8/32-PCI)";
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)";
2361 printk("STALLION: unknown board type=%d\n", brdp
->brdtype
);
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
) ?
2372 if ((conflict
== 0) && (brdp
->iosize2
> 0))
2373 conflict
= check_region(brdp
->ioaddr2
, brdp
->iosize2
) ?
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
;
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
)
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
));
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 +
2431 panelp
->nrports
= 8;
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
+
2446 panelp
->nrports
= 8;
2447 panelp
->ackmask
= 0xc0;
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
)))
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
);
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
))
2484 printk("stl_brdinit(brdp=%x)\n", (int) brdp
);
2487 switch (brdp
->brdtype
) {
2499 printk("STALLION: unit=%d is unknown board type=%d\n",
2500 brdp
->brdnr
, brdp
->brdtype
);
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
);
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
,
2523 /*****************************************************************************/
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];
2541 printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n",
2542 brdtype
, dev
->bus
->number
, dev
->devfn
);
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",
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
];
2567 printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__
, __LINE__
,
2568 bar
[0], bar
[1], bar
[2], bar
[3], irq
);
2572 * We have all resources from the board, so let's setup the actual
2573 * board structure now.
2577 brdp
->ioaddr2
= (bar
[0] & PCI_BASE_ADDRESS_IO_MASK
);
2578 brdp
->ioaddr1
= (bar
[1] & PCI_BASE_ADDRESS_IO_MASK
);
2581 brdp
->ioaddr2
= (bar
[2] & PCI_BASE_ADDRESS_IO_MASK
);
2582 brdp
->ioaddr1
= (bar
[1] & PCI_BASE_ADDRESS_IO_MASK
);
2585 brdp
->ioaddr1
= (bar
[2] & PCI_BASE_ADDRESS_IO_MASK
);
2586 brdp
->ioaddr2
= (bar
[1] & PCI_BASE_ADDRESS_IO_MASK
);
2589 printk("STALLION: unknown PCI board type=%d\n", brdtype
);
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
;
2614 printk("stl_findpcibrds()\n");
2617 if (! pci_present())
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
);
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
)
2640 rc
= stl_initpcibrd(stl_pcibrds
[i
].brdtype
, dev
);
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()
2665 printk("stl_initbrds()\n");
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
));
2686 memset(brdp
, 0, sizeof(stlbrd_t
));
2688 brdp
->magic
= STL_BOARDMAGIC
;
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
;
2700 * If the PCI BIOS support is compiled in then let's go looking for
2709 /*****************************************************************************/
2712 * Return the board stats structure to user app.
2715 static int stl_getbrdstats(combrd_t
*bp
)
2721 copy_from_user(&stl_brdstats
, bp
, sizeof(combrd_t
));
2722 if (stl_brdstats
.brd
>= STL_MAXBRDS
)
2724 brdp
= stl_brds
[stl_brdstats
.brd
];
2725 if (brdp
== (stlbrd_t
*) NULL
)
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
));
2749 /*****************************************************************************/
2752 * Resolve the referenced port number into a port struct pointer.
2755 static stlport_t
*stl_getport(int brdnr
, int panelnr
, int portnr
)
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
,
2792 if (portp
== (stlport_t
*) NULL
)
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;
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
));
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
,
2846 if (portp
== (stlport_t
*) NULL
)
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
));
2858 /*****************************************************************************/
2861 * Return the entire driver ports structure to a user app.
2864 static int stl_getportstruct(unsigned long arg
)
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
)
2873 copy_to_user((void *) arg
, portp
, sizeof(stlport_t
));
2877 /*****************************************************************************/
2880 * Return the entire driver board structure to a user app.
2883 static int stl_getbrdstruct(unsigned long arg
)
2887 copy_from_user(&stl_dummybrd
, (void *) arg
, sizeof(stlbrd_t
));
2888 if ((stl_dummybrd
.brdnr
< 0) || (stl_dummybrd
.brdnr
>= STL_MAXBRDS
))
2890 brdp
= stl_brds
[stl_dummybrd
.brdnr
];
2891 if (brdp
== (stlbrd_t
*) NULL
)
2893 copy_to_user((void *) arg
, brdp
, sizeof(stlbrd_t
));
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
)
2910 /*****************************************************************************/
2912 static int stl_memclose(struct inode
*ip
, struct file
*fp
)
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
2926 static int stl_memioctl(struct inode
*ip
, struct file
*fp
, unsigned int cmd
, unsigned long arg
)
2931 printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip
,
2932 (int) fp
, cmd
, (int) arg
);
2935 brdnr
= MINOR(ip
->i_rdev
);
2936 if (brdnr
>= STL_MAXBRDS
)
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
);
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
);
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
);
2959 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
2960 sizeof(stlport_t
))) == 0)
2961 rc
= stl_getportstruct(arg
);
2964 if ((rc
= verify_area(VERIFY_WRITE
, (void *) arg
,
2965 sizeof(stlbrd_t
))) == 0)
2966 rc
= stl_getbrdstruct(arg
);
2976 /*****************************************************************************/
2978 __initfunc(int stl_init(void))
2980 printk(KERN_INFO
"%s: version %s\n", stl_drvtitle
, stl_drvversion
);
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",
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");
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
);
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
)
3097 int nrchips
, uartaddr
, ioaddr
;
3100 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp
, (int) panelp
);
3103 BRDENABLE(panelp
->brdnr
, panelp
->pagenr
);
3106 * Check that each chip is present and started up OK.
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
;
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)
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
);
3134 chipmask
|= (0x1 << i
);
3135 outb((PPR
+ uartaddr
), ioaddr
);
3136 outb(PPR_SCALAR
, (ioaddr
+ EREG_DATA
));
3139 BRDDISABLE(panelp
->brdnr
);
3143 /*****************************************************************************/
3146 * Initialize hardware specific port registers.
3149 static void stl_cd1400portinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
)
3152 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3153 (int) brdp
, (int) panelp
, (int) portp
);
3156 if ((brdp
== (stlbrd_t
*) NULL
) || (panelp
== (stlpanel_t
*) NULL
) ||
3157 (portp
== (stlport_t
*) NULL
))
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
)
3183 for (i
= 0; (i
< CCR_MAXWAIT
); i
++) {
3184 if (stl_cd1400getreg(portp
, CCR
) == 0) {
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
3200 static void stl_cd1400setport(stlport_t
*portp
, struct termios
*tiosp
)
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
;
3225 brdp
= stl_brds
[portp
->brdnr
];
3226 if (brdp
== (stlbrd_t
*) NULL
)
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
) {
3269 if (tiosp
->c_cflag
& CSTOPB
)
3274 if (tiosp
->c_cflag
& PARENB
) {
3275 if (tiosp
->c_cflag
& PARODD
)
3276 cor1
|= (COR1_PARENB
| COR1_PARODD
);
3278 cor1
|= (COR1_PARENB
| COR1_PAREVEN
);
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
;
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
3298 baudrate
= tiosp
->c_cflag
& CBAUD
;
3299 if (baudrate
& CBAUDEX
) {
3300 baudrate
&= ~CBAUDEX
;
3301 if ((baudrate
< 1) || (baudrate
> 4))
3302 tiosp
->c_cflag
&= ~CBAUDEX
;
3306 baudrate
= stl_baudrates
[baudrate
];
3307 if ((tiosp
->c_cflag
& CBAUD
) == B38400
) {
3308 if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
3310 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
3312 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
3314 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
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
;
3323 for (clk
= 0; (clk
< CD1400_NUMCLKS
); clk
++) {
3324 clkdiv
= ((portp
->clk
/ stl_cd1400clkdivs
[clk
]) / baudrate
);
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) {
3337 sreron
|= SRER_MODEM
;
3338 portp
->flags
|= ASYNC_CHECK_CD
;
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
) {
3352 if (tiosp
->c_iflag
& IXANY
)
3356 if (tiosp
->c_cflag
& CRTSCTS
) {
3358 mcor1
|= FIFO_RTSTHRESHOLD
;
3362 * All cd1400 register values calculated so go through and set
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
]);
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
))
3387 if (stl_cd1400updatereg(portp
, COR2
, cor2
))
3389 if (stl_cd1400updatereg(portp
, COR3
, cor3
))
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
);
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
;
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
;
3432 printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
3433 (int) portp
, dtr
, rts
);
3445 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3446 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3448 stl_cd1400setreg(portp
, MSVR2
, msvr2
);
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
;
3468 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp
);
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
);
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;
3486 sigs
|= (msvr1
& MSVR1_RI
) ? TIOCM_RI
: 0;
3487 sigs
|= (msvr1
& MSVR1_DSR
) ? TIOCM_DSR
: 0;
3494 /*****************************************************************************/
3497 * Enable/Disable the Transmitter and/or Receiver.
3500 static void stl_cd1400enablerxtx(stlport_t
*portp
, int rx
, int tx
)
3503 unsigned long flags
;
3506 printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3507 (int) portp
, rx
, tx
);
3512 ccr
|= CCR_TXDISABLE
;
3514 ccr
|= CCR_TXENABLE
;
3516 ccr
|= CCR_RXDISABLE
;
3518 ccr
|= CCR_RXENABLE
;
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
;
3543 printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3544 (int) portp
, rx
, tx
);
3550 sreroff
|= (SRER_TXDATA
| SRER_TXEMPTY
);
3552 sreron
|= SRER_TXDATA
;
3554 sreron
|= SRER_TXEMPTY
;
3556 sreroff
|= SRER_RXDATA
;
3558 sreron
|= SRER_RXDATA
;
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
);
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
;
3583 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp
);
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
;
3601 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp
, len
);
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
) |
3611 BRDDISABLE(portp
->brdnr
);
3612 portp
->brklen
= len
;
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
;
3630 printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp
, state
);
3633 if (portp
== (stlport_t
*) NULL
)
3636 if (tty
== (struct tty_struct
*) NULL
)
3641 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3642 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
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
++;
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
;
3695 printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp
, state
);
3698 if (portp
== (stlport_t
*) NULL
)
3701 if (tty
== (struct tty_struct
*) NULL
)
3706 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3707 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3709 stl_cd1400ccrwait(portp
);
3710 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR1
);
3711 portp
->stats
.rxxon
++;
3712 stl_cd1400ccrwait(portp
);
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
;
3730 printk("stl_cd1400flush(portp=%x)\n", (int) portp
);
3733 if (portp
== (stlport_t
*) NULL
)
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
)
3760 printk("stl_cd1400datastate(portp=%x)\n", (int) portp
);
3763 if (portp
== (stlport_t
*) NULL
)
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
;
3780 printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
3781 (int) panelp
, 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
;
3810 printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp
,
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
));
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
));
3854 outb((COR2
+ portp
->uartaddr
), ioaddr
);
3855 outb((inb(ioaddr
+ EREG_DATA
) & ~COR2_ETC
),
3856 (ioaddr
+ EREG_DATA
));
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
)
3881 unsigned char ioack
, srer
;
3884 printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp
, ioaddr
);
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
);
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
))
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
);
3914 outb((SRER
+ portp
->uartaddr
), ioaddr
);
3915 srer
= inb(ioaddr
+ EREG_DATA
);
3916 if (srer
& SRER_TXDATA
) {
3917 srer
= (srer
& ~SRER_TXDATA
) | SRER_TXEMPTY
;
3919 srer
&= ~(SRER_TXDATA
| SRER_TXEMPTY
);
3920 clear_bit(ASYI_TXBUSY
, &portp
->istate
);
3922 outb(srer
, (ioaddr
+ EREG_DATA
));
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
);
3931 if (tail
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
))
3932 tail
= portp
->tx
.buf
;
3934 outsb((ioaddr
+ EREG_DATA
), tail
, len
);
3937 portp
->tx
.tail
= tail
;
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
)
3960 struct tty_struct
*tty
;
3961 unsigned int ioack
, len
, buflen
;
3962 unsigned char status
;
3966 printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp
, ioaddr
);
3969 ioack
= inb(ioaddr
+ EREG_RXACK
);
3970 if ((ioack
& panelp
->ackmask
) != 0) {
3971 printk("STALLION: bad RX interrupt ack value=%x\n", ioack
);
3974 portp
= panelp
->ports
[(ioack
>> 3)];
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
;
3988 len
= MIN(len
, buflen
);
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
++;
4019 if ((tty
!= (struct tty_struct
*) NULL
) &&
4020 ((portp
->rxignoremsk
& status
) == 0)) {
4021 if (portp
->rxmarkmsk
& status
) {
4022 if (status
& ST_BREAK
) {
4024 if (portp
->flags
& ASYNC_SAK
) {
4026 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4028 } else if (status
& ST_PARITY
) {
4029 status
= TTY_PARITY
;
4030 } else if (status
& ST_FRAMING
) {
4032 } else if(status
& ST_OVERRUN
) {
4033 status
= TTY_OVERRUN
;
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
;
4046 tty_schedule_flip(tty
);
4050 printk("STALLION: bad RX interrupt ack value=%x\n", ioack
);
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
)
4074 printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp
);
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
);
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
));
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
));
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
));
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
)
4160 int nrchips
, ioaddr
;
4163 printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
4164 (int) brdp
, (int) panelp
);
4167 BRDENABLE(panelp
->brdnr
, panelp
->pagenr
);
4170 * Check that each chip is present and started up OK.
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
);
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
);
4199 /*****************************************************************************/
4202 * Initialize hardware specific port registers.
4205 static void stl_sc26198portinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
)
4208 printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
4209 (int) brdp
, (int) panelp
, (int) portp
);
4212 if ((brdp
== (stlbrd_t
*) NULL
) || (panelp
== (stlpanel_t
*) NULL
) ||
4213 (portp
== (stlport_t
*) NULL
))
4216 portp
->ioaddr
= panelp
->iobase
+ ((portp
->portnr
< 8) ? 0 : 4);
4217 portp
->uartaddr
= (portp
->portnr
& 0x07) << 4;
4218 portp
->pagenr
= panelp
->pagenr
;
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
4233 static void stl_sc26198setport(stlport_t
*portp
, struct termios
*tiosp
)
4236 unsigned long flags
;
4237 unsigned int baudrate
;
4238 unsigned char mr0
, mr1
, mr2
, clk
;
4239 unsigned char imron
, imroff
, iopr
, ipr
;
4249 brdp
= stl_brds
[portp
->brdnr
];
4250 if (brdp
== (stlbrd_t
*) NULL
)
4254 * Set up the RX char ignore mask with those RX error types we
4257 portp
->rxignoremsk
= 0;
4258 if (tiosp
->c_iflag
& IGNPAR
)
4259 portp
->rxignoremsk
|= (SR_RXPARITY
| SR_RXFRAMING
|
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
) {
4289 if (tiosp
->c_cflag
& CSTOPB
)
4294 if (tiosp
->c_cflag
& PARENB
) {
4295 if (tiosp
->c_cflag
& PARODD
)
4296 mr1
|= (MR1_PARENB
| MR1_PARODD
);
4298 mr1
|= (MR1_PARENB
| MR1_PAREVEN
);
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
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
;
4325 baudrate
= stl_baudrates
[baudrate
];
4326 if ((tiosp
->c_cflag
& CBAUD
) == B38400
) {
4327 if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
4329 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
4331 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
4333 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
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
;
4342 for (clk
= 0; (clk
< SC26198_NRBAUDS
); clk
++) {
4343 if (baudrate
<= sc26198_baudtable
[clk
])
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
;
4354 iopr
|= IOPR_DCDCOS
;
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
;
4369 imroff
|= IR_XONXOFF
;
4371 if (tiosp
->c_iflag
& IXOFF
)
4374 if (tiosp
->c_cflag
& CRTSCTS
) {
4380 * All sc26198 register values calculated so go through and set
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
]);
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
));
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
);
4415 portp
->sigs
&= ~TIOCM_CD
;
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
;
4437 printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4438 (int) portp
, dtr
, rts
);
4444 iopioroff
|= IPR_DTR
;
4446 iopioron
|= IPR_DTR
;
4448 iopioroff
|= IPR_RTS
;
4450 iopioron
|= IPR_RTS
;
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
)
4470 unsigned long flags
;
4474 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp
);
4479 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4480 ipr
= stl_sc26198getreg(portp
, IPR
);
4481 BRDDISABLE(portp
->brdnr
);
4482 restore_flags(flags
);
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
;
4493 /*****************************************************************************/
4496 * Enable/Disable the Transmitter and/or Receiver.
4499 static void stl_sc26198enablerxtx(stlport_t
*portp
, int rx
, int tx
)
4502 unsigned long flags
;
4505 printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4506 (int) portp
, rx
, tx
);
4509 ccr
= portp
->crenable
;
4511 ccr
&= ~CR_TXENABLE
;
4515 ccr
&= ~CR_RXENABLE
;
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
)
4537 unsigned long flags
;
4540 printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4541 (int) portp
, rx
, tx
);
4550 imr
&= ~(IR_RXRDY
| IR_RXBREAK
| IR_RXWATCHDOG
);
4552 imr
|= IR_RXRDY
| IR_RXBREAK
| IR_RXWATCHDOG
;
4556 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4557 stl_sc26198setreg(portp
, IMR
, imr
);
4558 BRDDISABLE(portp
->brdnr
);
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
;
4576 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp
);
4581 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
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
;
4595 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp
, len
);
4600 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4602 stl_sc26198setreg(portp
, SCCR
, CR_TXSTARTBREAK
);
4603 portp
->stats
.txbreaks
++;
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
;
4624 printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp
, state
);
4627 if (portp
== (stlport_t
*) NULL
)
4630 if (tty
== (struct tty_struct
*) NULL
)
4635 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
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
);
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
++;
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
);
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
;
4696 printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp
, state
);
4699 if (portp
== (stlport_t
*) NULL
)
4702 if (tty
== (struct tty_struct
*) NULL
)
4707 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4709 mr0
= stl_sc26198getreg(portp
, MR0
);
4710 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4711 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXON
);
4713 portp
->stats
.rxxon
++;
4714 stl_sc26198wait(portp
);
4715 stl_sc26198setreg(portp
, MR0
, mr0
);
4717 mr0
= stl_sc26198getreg(portp
, MR0
);
4718 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4719 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXOFF
);
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
;
4736 printk("stl_sc26198flush(portp=%x)\n", (int) portp
);
4739 if (portp
== (stlport_t
*) NULL
)
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
;
4768 printk("stl_sc26198datastate(portp=%x)\n", (int) portp
);
4771 if (portp
== (stlport_t
*) NULL
)
4773 if (test_bit(ASYI_TXBUSY
, &portp
->istate
))
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
)
4798 printk("stl_sc26198wait(portp=%x)\n", (int) portp
);
4801 if (portp
== (stlport_t
*) NULL
)
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
)
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
)
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
);
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
;
4876 printk("stl_sc26198txisr(portp=%x)\n", (int) portp
);
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
);
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
);
4898 mr0
|= ((mr0
& ~MR0_TXMASK
) | MR0_TXEMPTY
);
4899 outb(mr0
, (ioaddr
+ XP_DATA
));
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
);
4909 if (tail
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
))
4910 tail
= portp
->tx
.buf
;
4912 outsb((ioaddr
+ XP_DATA
), 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
;
4937 printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp
, iack
);
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
;
4954 len
= MIN(len
, buflen
);
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
;
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
;
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
) {
5012 if (portp
->flags
& ASYNC_SAK
) {
5014 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
5016 } else if (status
& SR_RXPARITY
) {
5017 status
= TTY_PARITY
;
5018 } else if (status
& SR_RXFRAMING
) {
5020 } else if(status
& SR_RXOVERRUN
) {
5021 status
= TTY_OVERRUN
;
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
;
5035 tty_schedule_flip(tty
);
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
5054 static void stl_sc26198rxbadchars(stlport_t
*portp
)
5056 unsigned char status
, mr1
;
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
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
5087 static void stl_sc26198otherisr(stlport_t
*portp
, unsigned int iack
)
5089 unsigned char cir
, ipr
, xisr
;
5092 printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp
, iack
);
5095 cir
= stl_sc26198getglobreg(portp
, CIR
);
5097 switch (cir
& CIR_SUBTYPEMASK
) {
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
++;
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
++;
5118 stl_sc26198setreg(portp
, SCCR
, CR_BREAKRESET
);
5119 stl_sc26198rxbadchars(portp
);
5126 /*****************************************************************************/