1 /*****************************************************************************/
4 * stallion.c -- stallion multiport serial driver.
6 * Copyright (C) 1996-1999 Stallion Technologies
7 * Copyright (C) 1994-1996 Greg Ungerer.
9 * This code is loosely based on the Linux serial driver, written by
10 * Linus Torvalds, Theodore T'so and others.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; either version 2 of the License, or
15 * (at your option) any later version.
17 * This program is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU General Public License for more details.
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, write to the Free Software
24 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
27 /*****************************************************************************/
29 #include <linux/config.h>
30 #include <linux/module.h>
31 #include <linux/slab.h>
32 #include <linux/interrupt.h>
33 #include <linux/tty.h>
34 #include <linux/tty_flip.h>
35 #include <linux/serial.h>
36 #include <linux/cd1400.h>
37 #include <linux/sc26198.h>
38 #include <linux/comstats.h>
39 #include <linux/stallion.h>
40 #include <linux/ioport.h>
41 #include <linux/init.h>
42 #include <linux/smp_lock.h>
43 #include <linux/devfs_fs_kernel.h>
44 #include <linux/device.h>
45 #include <linux/delay.h>
48 #include <asm/uaccess.h>
51 #include <linux/pci.h>
54 /*****************************************************************************/
57 * Define different board types. Use the standard Stallion "assigned"
58 * board numbers. Boards supported in this driver are abbreviated as
59 * EIO = EasyIO and ECH = EasyConnection 8/32.
65 #define BRD_ECH64PCI 27
66 #define BRD_EASYIOPCI 28
69 * Define a configuration structure to hold the board configuration.
70 * Need to set this up in the code (for now) with the boards that are
71 * to be configured into the system. This is what needs to be modified
72 * when adding/removing/modifying boards. Each line entry in the
73 * stl_brdconf[] array is a board. Each line contains io/irq/memory
74 * ranges for that board (as well as what type of board it is).
76 * { BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },
77 * This line would configure an EasyIO board (4 or 8, no difference),
78 * at io address 2a0 and irq 10.
80 * { BRD_ECH, 0x2a8, 0x280, 0, 12, 0 },
81 * This line will configure an EasyConnection 8/32 board at primary io
82 * address 2a8, secondary io address 280 and irq 12.
83 * Enter as many lines into this array as you want (only the first 4
84 * will actually be used!). Any combination of EasyIO and EasyConnection
85 * boards can be specified. EasyConnection 8/32 boards can share their
86 * secondary io addresses between each other.
88 * NOTE: there is no need to put any entries in this table for PCI
89 * boards. They will be found automatically by the driver - provided
90 * PCI BIOS32 support is compiled into the kernel.
97 unsigned long memaddr
;
102 static stlconf_t stl_brdconf
[] = {
103 /*{ BRD_EASYIO, 0x2a0, 0, 0, 10, 0 },*/
106 static int stl_nrbrds
= ARRAY_SIZE(stl_brdconf
);
108 /*****************************************************************************/
111 * Define some important driver characteristics. Device major numbers
112 * allocated as per Linux Device Registry.
114 #ifndef STL_SIOMEMMAJOR
115 #define STL_SIOMEMMAJOR 28
117 #ifndef STL_SERIALMAJOR
118 #define STL_SERIALMAJOR 24
120 #ifndef STL_CALLOUTMAJOR
121 #define STL_CALLOUTMAJOR 25
125 * Set the TX buffer size. Bigger is better, but we don't want
126 * to chew too much memory with buffers!
128 #define STL_TXBUFLOW 512
129 #define STL_TXBUFSIZE 4096
131 /*****************************************************************************/
134 * Define our local driver identity first. Set up stuff to deal with
135 * all the local structures required by a serial tty driver.
137 static char *stl_drvtitle
= "Stallion Multiport Serial Driver";
138 static char *stl_drvname
= "stallion";
139 static char *stl_drvversion
= "5.6.0";
141 static struct tty_driver
*stl_serial
;
144 * Define a local default termios struct. All ports will be created
145 * with this termios initially. Basically all it defines is a raw port
146 * at 9600, 8 data bits, 1 stop bit.
148 static struct termios stl_deftermios
= {
149 .c_cflag
= (B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
),
154 * Define global stats structures. Not used often, and can be
155 * re-used for each stats call.
157 static comstats_t stl_comstats
;
158 static combrd_t stl_brdstats
;
159 static stlbrd_t stl_dummybrd
;
160 static stlport_t stl_dummyport
;
163 * Define global place to put buffer overflow characters.
165 static char stl_unwanted
[SC26198_RXFIFOSIZE
];
167 /*****************************************************************************/
169 static stlbrd_t
*stl_brds
[STL_MAXBRDS
];
172 * Per board state flags. Used with the state field of the board struct.
173 * Not really much here!
175 #define BRD_FOUND 0x1
178 * Define the port structure istate flags. These set of flags are
179 * modified at interrupt time - so setting and reseting them needs
180 * to be atomic. Use the bit clear/setting routines for this.
182 #define ASYI_TXBUSY 1
184 #define ASYI_DCDCHANGE 3
185 #define ASYI_TXFLOWED 4
188 * Define an array of board names as printable strings. Handy for
189 * referencing boards when printing trace and stuff.
191 static char *stl_brdnames
[] = {
223 /*****************************************************************************/
226 * Define some string labels for arguments passed from the module
227 * load line. These allow for easy board definitions, and easy
228 * modification of the io, memory and irq resoucres.
230 static int stl_nargs
= 0;
231 static char *board0
[4];
232 static char *board1
[4];
233 static char *board2
[4];
234 static char *board3
[4];
236 static char **stl_brdsp
[] = {
244 * Define a set of common board names, and types. This is used to
245 * parse any module arguments.
248 typedef struct stlbrdtype
{
253 static stlbrdtype_t stl_brdstr
[] = {
254 { "easyio", BRD_EASYIO
},
255 { "eio", BRD_EASYIO
},
256 { "20", BRD_EASYIO
},
257 { "ec8/32", BRD_ECH
},
258 { "ec8/32-at", BRD_ECH
},
259 { "ec8/32-isa", BRD_ECH
},
261 { "echat", BRD_ECH
},
263 { "ec8/32-mc", BRD_ECHMC
},
264 { "ec8/32-mca", BRD_ECHMC
},
265 { "echmc", BRD_ECHMC
},
266 { "echmca", BRD_ECHMC
},
268 { "ec8/32-pc", BRD_ECHPCI
},
269 { "ec8/32-pci", BRD_ECHPCI
},
270 { "26", BRD_ECHPCI
},
271 { "ec8/64-pc", BRD_ECH64PCI
},
272 { "ec8/64-pci", BRD_ECH64PCI
},
273 { "ech-pci", BRD_ECH64PCI
},
274 { "echpci", BRD_ECH64PCI
},
275 { "echpc", BRD_ECH64PCI
},
276 { "27", BRD_ECH64PCI
},
277 { "easyio-pc", BRD_EASYIOPCI
},
278 { "easyio-pci", BRD_EASYIOPCI
},
279 { "eio-pci", BRD_EASYIOPCI
},
280 { "eiopci", BRD_EASYIOPCI
},
281 { "28", BRD_EASYIOPCI
},
285 * Define the module agruments.
287 MODULE_AUTHOR("Greg Ungerer");
288 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
289 MODULE_LICENSE("GPL");
291 module_param_array(board0
, charp
, &stl_nargs
, 0);
292 MODULE_PARM_DESC(board0
, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
293 module_param_array(board1
, charp
, &stl_nargs
, 0);
294 MODULE_PARM_DESC(board1
, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
295 module_param_array(board2
, charp
, &stl_nargs
, 0);
296 MODULE_PARM_DESC(board2
, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
297 module_param_array(board3
, charp
, &stl_nargs
, 0);
298 MODULE_PARM_DESC(board3
, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
300 /*****************************************************************************/
303 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
304 * to the directly accessible io ports of these boards (not the uarts -
305 * they are in cd1400.h and sc26198.h).
307 #define EIO_8PORTRS 0x04
308 #define EIO_4PORTRS 0x05
309 #define EIO_8PORTDI 0x00
310 #define EIO_8PORTM 0x06
312 #define EIO_IDBITMASK 0x07
314 #define EIO_BRDMASK 0xf0
317 #define ID_BRD16 0x30
319 #define EIO_INTRPEND 0x08
320 #define EIO_INTEDGE 0x00
321 #define EIO_INTLEVEL 0x08
325 #define ECH_IDBITMASK 0xe0
326 #define ECH_BRDENABLE 0x08
327 #define ECH_BRDDISABLE 0x00
328 #define ECH_INTENABLE 0x01
329 #define ECH_INTDISABLE 0x00
330 #define ECH_INTLEVEL 0x02
331 #define ECH_INTEDGE 0x00
332 #define ECH_INTRPEND 0x01
333 #define ECH_BRDRESET 0x01
335 #define ECHMC_INTENABLE 0x01
336 #define ECHMC_BRDRESET 0x02
338 #define ECH_PNLSTATUS 2
339 #define ECH_PNL16PORT 0x20
340 #define ECH_PNLIDMASK 0x07
341 #define ECH_PNLXPID 0x40
342 #define ECH_PNLINTRPEND 0x80
344 #define ECH_ADDR2MASK 0x1e0
347 * Define the vector mapping bits for the programmable interrupt board
348 * hardware. These bits encode the interrupt for the board to use - it
349 * is software selectable (except the EIO-8M).
351 static unsigned char stl_vecmap
[] = {
352 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
353 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
357 * Lock ordering is that you may not take stallion_lock holding
361 static spinlock_t brd_lock
; /* Guard the board mapping */
362 static spinlock_t stallion_lock
; /* Guard the tty driver */
365 * Set up enable and disable macros for the ECH boards. They require
366 * the secondary io address space to be activated and deactivated.
367 * This way all ECH boards can share their secondary io region.
368 * If this is an ECH-PCI board then also need to set the page pointer
369 * to point to the correct page.
371 #define BRDENABLE(brdnr,pagenr) \
372 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
373 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
374 stl_brds[(brdnr)]->ioctrl); \
375 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
376 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
378 #define BRDDISABLE(brdnr) \
379 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
380 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
381 stl_brds[(brdnr)]->ioctrl);
383 #define STL_CD1400MAXBAUD 230400
384 #define STL_SC26198MAXBAUD 460800
386 #define STL_BAUDBASE 115200
387 #define STL_CLOSEDELAY (5 * HZ / 10)
389 /*****************************************************************************/
394 * Define the Stallion PCI vendor and device IDs.
396 #ifndef PCI_VENDOR_ID_STALLION
397 #define PCI_VENDOR_ID_STALLION 0x124d
399 #ifndef PCI_DEVICE_ID_ECHPCI832
400 #define PCI_DEVICE_ID_ECHPCI832 0x0000
402 #ifndef PCI_DEVICE_ID_ECHPCI864
403 #define PCI_DEVICE_ID_ECHPCI864 0x0002
405 #ifndef PCI_DEVICE_ID_EIOPCI
406 #define PCI_DEVICE_ID_EIOPCI 0x0003
410 * Define structure to hold all Stallion PCI boards.
412 typedef struct stlpcibrd
{
413 unsigned short vendid
;
414 unsigned short devid
;
418 static stlpcibrd_t stl_pcibrds
[] = {
419 { PCI_VENDOR_ID_STALLION
, PCI_DEVICE_ID_ECHPCI864
, BRD_ECH64PCI
},
420 { PCI_VENDOR_ID_STALLION
, PCI_DEVICE_ID_EIOPCI
, BRD_EASYIOPCI
},
421 { PCI_VENDOR_ID_STALLION
, PCI_DEVICE_ID_ECHPCI832
, BRD_ECHPCI
},
422 { PCI_VENDOR_ID_NS
, PCI_DEVICE_ID_NS_87410
, BRD_ECHPCI
},
425 static int stl_nrpcibrds
= ARRAY_SIZE(stl_pcibrds
);
429 /*****************************************************************************/
432 * Define macros to extract a brd/port number from a minor number.
434 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
435 #define MINOR2PORT(min) ((min) & 0x3f)
438 * Define a baud rate table that converts termios baud rate selector
439 * into the actual baud rate value. All baud rate calculations are
440 * based on the actual baud rate required.
442 static unsigned int stl_baudrates
[] = {
443 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
444 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
448 * Define some handy local macros...
451 #define MIN(a,b) (((a) <= (b)) ? (a) : (b))
454 #define TOLOWER(x) ((((x) >= 'A') && ((x) <= 'Z')) ? ((x) + 0x20) : (x))
456 /*****************************************************************************/
459 * Declare all those functions in this driver!
462 static void stl_argbrds(void);
463 static int stl_parsebrd(stlconf_t
*confp
, char **argp
);
465 static unsigned long stl_atol(char *str
);
467 static int stl_init(void);
468 static int stl_open(struct tty_struct
*tty
, struct file
*filp
);
469 static void stl_close(struct tty_struct
*tty
, struct file
*filp
);
470 static int stl_write(struct tty_struct
*tty
, const unsigned char *buf
, int count
);
471 static void stl_putchar(struct tty_struct
*tty
, unsigned char ch
);
472 static void stl_flushchars(struct tty_struct
*tty
);
473 static int stl_writeroom(struct tty_struct
*tty
);
474 static int stl_charsinbuffer(struct tty_struct
*tty
);
475 static int stl_ioctl(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
);
476 static void stl_settermios(struct tty_struct
*tty
, struct termios
*old
);
477 static void stl_throttle(struct tty_struct
*tty
);
478 static void stl_unthrottle(struct tty_struct
*tty
);
479 static void stl_stop(struct tty_struct
*tty
);
480 static void stl_start(struct tty_struct
*tty
);
481 static void stl_flushbuffer(struct tty_struct
*tty
);
482 static void stl_breakctl(struct tty_struct
*tty
, int state
);
483 static void stl_waituntilsent(struct tty_struct
*tty
, int timeout
);
484 static void stl_sendxchar(struct tty_struct
*tty
, char ch
);
485 static void stl_hangup(struct tty_struct
*tty
);
486 static int stl_memioctl(struct inode
*ip
, struct file
*fp
, unsigned int cmd
, unsigned long arg
);
487 static int stl_portinfo(stlport_t
*portp
, int portnr
, char *pos
);
488 static int stl_readproc(char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
);
490 static int stl_brdinit(stlbrd_t
*brdp
);
491 static int stl_initports(stlbrd_t
*brdp
, stlpanel_t
*panelp
);
492 static int stl_getserial(stlport_t
*portp
, struct serial_struct __user
*sp
);
493 static int stl_setserial(stlport_t
*portp
, struct serial_struct __user
*sp
);
494 static int stl_getbrdstats(combrd_t __user
*bp
);
495 static int stl_getportstats(stlport_t
*portp
, comstats_t __user
*cp
);
496 static int stl_clrportstats(stlport_t
*portp
, comstats_t __user
*cp
);
497 static int stl_getportstruct(stlport_t __user
*arg
);
498 static int stl_getbrdstruct(stlbrd_t __user
*arg
);
499 static int stl_waitcarrier(stlport_t
*portp
, struct file
*filp
);
500 static int stl_eiointr(stlbrd_t
*brdp
);
501 static int stl_echatintr(stlbrd_t
*brdp
);
502 static int stl_echmcaintr(stlbrd_t
*brdp
);
503 static int stl_echpciintr(stlbrd_t
*brdp
);
504 static int stl_echpci64intr(stlbrd_t
*brdp
);
505 static void stl_offintr(void *private);
506 static stlbrd_t
*stl_allocbrd(void);
507 static stlport_t
*stl_getport(int brdnr
, int panelnr
, int portnr
);
509 static inline int stl_initbrds(void);
510 static inline int stl_initeio(stlbrd_t
*brdp
);
511 static inline int stl_initech(stlbrd_t
*brdp
);
512 static inline int stl_getbrdnr(void);
515 static inline int stl_findpcibrds(void);
516 static inline int stl_initpcibrd(int brdtype
, struct pci_dev
*devp
);
520 * CD1400 uart specific handling functions.
522 static void stl_cd1400setreg(stlport_t
*portp
, int regnr
, int value
);
523 static int stl_cd1400getreg(stlport_t
*portp
, int regnr
);
524 static int stl_cd1400updatereg(stlport_t
*portp
, int regnr
, int value
);
525 static int stl_cd1400panelinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
);
526 static void stl_cd1400portinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
);
527 static void stl_cd1400setport(stlport_t
*portp
, struct termios
*tiosp
);
528 static int stl_cd1400getsignals(stlport_t
*portp
);
529 static void stl_cd1400setsignals(stlport_t
*portp
, int dtr
, int rts
);
530 static void stl_cd1400ccrwait(stlport_t
*portp
);
531 static void stl_cd1400enablerxtx(stlport_t
*portp
, int rx
, int tx
);
532 static void stl_cd1400startrxtx(stlport_t
*portp
, int rx
, int tx
);
533 static void stl_cd1400disableintrs(stlport_t
*portp
);
534 static void stl_cd1400sendbreak(stlport_t
*portp
, int len
);
535 static void stl_cd1400flowctrl(stlport_t
*portp
, int state
);
536 static void stl_cd1400sendflow(stlport_t
*portp
, int state
);
537 static void stl_cd1400flush(stlport_t
*portp
);
538 static int stl_cd1400datastate(stlport_t
*portp
);
539 static void stl_cd1400eiointr(stlpanel_t
*panelp
, unsigned int iobase
);
540 static void stl_cd1400echintr(stlpanel_t
*panelp
, unsigned int iobase
);
541 static void stl_cd1400txisr(stlpanel_t
*panelp
, int ioaddr
);
542 static void stl_cd1400rxisr(stlpanel_t
*panelp
, int ioaddr
);
543 static void stl_cd1400mdmisr(stlpanel_t
*panelp
, int ioaddr
);
545 static inline int stl_cd1400breakisr(stlport_t
*portp
, int ioaddr
);
548 * SC26198 uart specific handling functions.
550 static void stl_sc26198setreg(stlport_t
*portp
, int regnr
, int value
);
551 static int stl_sc26198getreg(stlport_t
*portp
, int regnr
);
552 static int stl_sc26198updatereg(stlport_t
*portp
, int regnr
, int value
);
553 static int stl_sc26198getglobreg(stlport_t
*portp
, int regnr
);
554 static int stl_sc26198panelinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
);
555 static void stl_sc26198portinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
);
556 static void stl_sc26198setport(stlport_t
*portp
, struct termios
*tiosp
);
557 static int stl_sc26198getsignals(stlport_t
*portp
);
558 static void stl_sc26198setsignals(stlport_t
*portp
, int dtr
, int rts
);
559 static void stl_sc26198enablerxtx(stlport_t
*portp
, int rx
, int tx
);
560 static void stl_sc26198startrxtx(stlport_t
*portp
, int rx
, int tx
);
561 static void stl_sc26198disableintrs(stlport_t
*portp
);
562 static void stl_sc26198sendbreak(stlport_t
*portp
, int len
);
563 static void stl_sc26198flowctrl(stlport_t
*portp
, int state
);
564 static void stl_sc26198sendflow(stlport_t
*portp
, int state
);
565 static void stl_sc26198flush(stlport_t
*portp
);
566 static int stl_sc26198datastate(stlport_t
*portp
);
567 static void stl_sc26198wait(stlport_t
*portp
);
568 static void stl_sc26198txunflow(stlport_t
*portp
, struct tty_struct
*tty
);
569 static void stl_sc26198intr(stlpanel_t
*panelp
, unsigned int iobase
);
570 static void stl_sc26198txisr(stlport_t
*port
);
571 static void stl_sc26198rxisr(stlport_t
*port
, unsigned int iack
);
572 static void stl_sc26198rxbadch(stlport_t
*portp
, unsigned char status
, char ch
);
573 static void stl_sc26198rxbadchars(stlport_t
*portp
);
574 static void stl_sc26198otherisr(stlport_t
*port
, unsigned int iack
);
576 /*****************************************************************************/
579 * Generic UART support structure.
581 typedef struct uart
{
582 int (*panelinit
)(stlbrd_t
*brdp
, stlpanel_t
*panelp
);
583 void (*portinit
)(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
);
584 void (*setport
)(stlport_t
*portp
, struct termios
*tiosp
);
585 int (*getsignals
)(stlport_t
*portp
);
586 void (*setsignals
)(stlport_t
*portp
, int dtr
, int rts
);
587 void (*enablerxtx
)(stlport_t
*portp
, int rx
, int tx
);
588 void (*startrxtx
)(stlport_t
*portp
, int rx
, int tx
);
589 void (*disableintrs
)(stlport_t
*portp
);
590 void (*sendbreak
)(stlport_t
*portp
, int len
);
591 void (*flowctrl
)(stlport_t
*portp
, int state
);
592 void (*sendflow
)(stlport_t
*portp
, int state
);
593 void (*flush
)(stlport_t
*portp
);
594 int (*datastate
)(stlport_t
*portp
);
595 void (*intr
)(stlpanel_t
*panelp
, unsigned int iobase
);
599 * Define some macros to make calling these functions nice and clean.
601 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
602 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
603 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
604 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
605 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
606 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
607 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
608 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
609 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
610 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
611 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
612 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
613 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
615 /*****************************************************************************/
618 * CD1400 UART specific data initialization.
620 static uart_t stl_cd1400uart
= {
624 stl_cd1400getsignals
,
625 stl_cd1400setsignals
,
626 stl_cd1400enablerxtx
,
628 stl_cd1400disableintrs
,
638 * Define the offsets within the register bank of a cd1400 based panel.
639 * These io address offsets are common to the EasyIO board as well.
647 #define EREG_BANKSIZE 8
649 #define CD1400_CLK 25000000
650 #define CD1400_CLK8M 20000000
653 * Define the cd1400 baud rate clocks. These are used when calculating
654 * what clock and divisor to use for the required baud rate. Also
655 * define the maximum baud rate allowed, and the default base baud.
657 static int stl_cd1400clkdivs
[] = {
658 CD1400_CLK0
, CD1400_CLK1
, CD1400_CLK2
, CD1400_CLK3
, CD1400_CLK4
661 /*****************************************************************************/
664 * SC26198 UART specific data initization.
666 static uart_t stl_sc26198uart
= {
667 stl_sc26198panelinit
,
670 stl_sc26198getsignals
,
671 stl_sc26198setsignals
,
672 stl_sc26198enablerxtx
,
673 stl_sc26198startrxtx
,
674 stl_sc26198disableintrs
,
675 stl_sc26198sendbreak
,
679 stl_sc26198datastate
,
684 * Define the offsets within the register bank of a sc26198 based panel.
692 #define XP_BANKSIZE 4
695 * Define the sc26198 baud rate table. Offsets within the table
696 * represent the actual baud rate selector of sc26198 registers.
698 static unsigned int sc26198_baudtable
[] = {
699 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
700 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
701 230400, 460800, 921600
704 #define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
706 /*****************************************************************************/
709 * Define the driver info for a user level control device. Used mainly
710 * to get at port stats - only not using the port device itself.
712 static struct file_operations stl_fsiomem
= {
713 .owner
= THIS_MODULE
,
714 .ioctl
= stl_memioctl
,
717 /*****************************************************************************/
719 static struct class *stallion_class
;
722 * Loadable module initialization stuff.
725 static int __init
stallion_module_init(void)
731 /*****************************************************************************/
733 static void __exit
stallion_module_exit(void)
741 printk("cleanup_module()\n");
744 printk(KERN_INFO
"Unloading %s: version %s\n", stl_drvtitle
,
748 * Free up all allocated resources used by the ports. This includes
749 * memory and interrupts. As part of this process we will also do
750 * a hangup on every open port - to try to flush out any processes
751 * hanging onto ports.
753 i
= tty_unregister_driver(stl_serial
);
754 put_tty_driver(stl_serial
);
756 printk("STALLION: failed to un-register tty driver, "
760 for (i
= 0; i
< 4; i
++) {
761 devfs_remove("staliomem/%d", i
);
762 class_device_destroy(stallion_class
, MKDEV(STL_SIOMEMMAJOR
, i
));
764 devfs_remove("staliomem");
765 if ((i
= unregister_chrdev(STL_SIOMEMMAJOR
, "staliomem")))
766 printk("STALLION: failed to un-register serial memory device, "
768 class_destroy(stallion_class
);
770 for (i
= 0; (i
< stl_nrbrds
); i
++) {
771 if ((brdp
= stl_brds
[i
]) == (stlbrd_t
*) NULL
)
774 free_irq(brdp
->irq
, brdp
);
776 for (j
= 0; (j
< STL_MAXPANELS
); j
++) {
777 panelp
= brdp
->panels
[j
];
778 if (panelp
== (stlpanel_t
*) NULL
)
780 for (k
= 0; (k
< STL_PORTSPERPANEL
); k
++) {
781 portp
= panelp
->ports
[k
];
782 if (portp
== (stlport_t
*) NULL
)
784 if (portp
->tty
!= (struct tty_struct
*) NULL
)
785 stl_hangup(portp
->tty
);
786 kfree(portp
->tx
.buf
);
792 release_region(brdp
->ioaddr1
, brdp
->iosize1
);
793 if (brdp
->iosize2
> 0)
794 release_region(brdp
->ioaddr2
, brdp
->iosize2
);
797 stl_brds
[i
] = (stlbrd_t
*) NULL
;
801 module_init(stallion_module_init
);
802 module_exit(stallion_module_exit
);
804 /*****************************************************************************/
807 * Check for any arguments passed in on the module load command line.
810 static void stl_argbrds(void)
817 printk("stl_argbrds()\n");
820 for (i
= stl_nrbrds
; (i
< stl_nargs
); i
++) {
821 memset(&conf
, 0, sizeof(conf
));
822 if (stl_parsebrd(&conf
, stl_brdsp
[i
]) == 0)
824 if ((brdp
= stl_allocbrd()) == (stlbrd_t
*) NULL
)
828 brdp
->brdtype
= conf
.brdtype
;
829 brdp
->ioaddr1
= conf
.ioaddr1
;
830 brdp
->ioaddr2
= conf
.ioaddr2
;
831 brdp
->irq
= conf
.irq
;
832 brdp
->irqtype
= conf
.irqtype
;
837 /*****************************************************************************/
840 * Convert an ascii string number into an unsigned long.
843 static unsigned long stl_atol(char *str
)
851 if ((*sp
== '0') && (*(sp
+1) == 'x')) {
854 } else if (*sp
== '0') {
861 for (; (*sp
!= 0); sp
++) {
862 c
= (*sp
> '9') ? (TOLOWER(*sp
) - 'a' + 10) : (*sp
- '0');
863 if ((c
< 0) || (c
>= base
)) {
864 printk("STALLION: invalid argument %s\n", str
);
868 val
= (val
* base
) + c
;
873 /*****************************************************************************/
876 * Parse the supplied argument string, into the board conf struct.
879 static int stl_parsebrd(stlconf_t
*confp
, char **argp
)
885 printk("stl_parsebrd(confp=%x,argp=%x)\n", (int) confp
, (int) argp
);
888 if ((argp
[0] == (char *) NULL
) || (*argp
[0] == 0))
891 for (sp
= argp
[0], i
= 0; ((*sp
!= 0) && (i
< 25)); sp
++, i
++)
894 for (i
= 0; i
< ARRAY_SIZE(stl_brdstr
); i
++) {
895 if (strcmp(stl_brdstr
[i
].name
, argp
[0]) == 0)
898 if (i
== ARRAY_SIZE(stl_brdstr
)) {
899 printk("STALLION: unknown board name, %s?\n", argp
[0]);
903 confp
->brdtype
= stl_brdstr
[i
].type
;
906 if ((argp
[i
] != (char *) NULL
) && (*argp
[i
] != 0))
907 confp
->ioaddr1
= stl_atol(argp
[i
]);
909 if (confp
->brdtype
== BRD_ECH
) {
910 if ((argp
[i
] != (char *) NULL
) && (*argp
[i
] != 0))
911 confp
->ioaddr2
= stl_atol(argp
[i
]);
914 if ((argp
[i
] != (char *) NULL
) && (*argp
[i
] != 0))
915 confp
->irq
= stl_atol(argp
[i
]);
919 /*****************************************************************************/
922 * Allocate a new board structure. Fill out the basic info in it.
925 static stlbrd_t
*stl_allocbrd(void)
929 brdp
= kzalloc(sizeof(stlbrd_t
), GFP_KERNEL
);
931 printk("STALLION: failed to allocate memory (size=%Zd)\n",
936 brdp
->magic
= STL_BOARDMAGIC
;
940 /*****************************************************************************/
942 static int stl_open(struct tty_struct
*tty
, struct file
*filp
)
946 unsigned int minordev
;
947 int brdnr
, panelnr
, portnr
, rc
;
950 printk("stl_open(tty=%x,filp=%x): device=%s\n", (int) tty
,
951 (int) filp
, tty
->name
);
954 minordev
= tty
->index
;
955 brdnr
= MINOR2BRD(minordev
);
956 if (brdnr
>= stl_nrbrds
)
958 brdp
= stl_brds
[brdnr
];
959 if (brdp
== (stlbrd_t
*) NULL
)
961 minordev
= MINOR2PORT(minordev
);
962 for (portnr
= -1, panelnr
= 0; (panelnr
< STL_MAXPANELS
); panelnr
++) {
963 if (brdp
->panels
[panelnr
] == (stlpanel_t
*) NULL
)
965 if (minordev
< brdp
->panels
[panelnr
]->nrports
) {
969 minordev
-= brdp
->panels
[panelnr
]->nrports
;
974 portp
= brdp
->panels
[panelnr
]->ports
[portnr
];
975 if (portp
== (stlport_t
*) NULL
)
979 * On the first open of the device setup the port hardware, and
980 * initialize the per port data structure.
983 tty
->driver_data
= portp
;
986 if ((portp
->flags
& ASYNC_INITIALIZED
) == 0) {
987 if (!portp
->tx
.buf
) {
988 portp
->tx
.buf
= kmalloc(STL_TXBUFSIZE
, GFP_KERNEL
);
991 portp
->tx
.head
= portp
->tx
.buf
;
992 portp
->tx
.tail
= portp
->tx
.buf
;
994 stl_setport(portp
, tty
->termios
);
995 portp
->sigs
= stl_getsignals(portp
);
996 stl_setsignals(portp
, 1, 1);
997 stl_enablerxtx(portp
, 1, 1);
998 stl_startrxtx(portp
, 1, 0);
999 clear_bit(TTY_IO_ERROR
, &tty
->flags
);
1000 portp
->flags
|= ASYNC_INITIALIZED
;
1004 * Check if this port is in the middle of closing. If so then wait
1005 * until it is closed then return error status, based on flag settings.
1006 * The sleep here does not need interrupt protection since the wakeup
1007 * for it is done with the same context.
1009 if (portp
->flags
& ASYNC_CLOSING
) {
1010 interruptible_sleep_on(&portp
->close_wait
);
1011 if (portp
->flags
& ASYNC_HUP_NOTIFY
)
1013 return -ERESTARTSYS
;
1017 * Based on type of open being done check if it can overlap with any
1018 * previous opens still in effect. If we are a normal serial device
1019 * then also we might have to wait for carrier.
1021 if (!(filp
->f_flags
& O_NONBLOCK
)) {
1022 if ((rc
= stl_waitcarrier(portp
, filp
)) != 0)
1025 portp
->flags
|= ASYNC_NORMAL_ACTIVE
;
1030 /*****************************************************************************/
1033 * Possibly need to wait for carrier (DCD signal) to come high. Say
1034 * maybe because if we are clocal then we don't need to wait...
1037 static int stl_waitcarrier(stlport_t
*portp
, struct file
*filp
)
1039 unsigned long flags
;
1043 printk("stl_waitcarrier(portp=%x,filp=%x)\n", (int) portp
, (int) filp
);
1049 spin_lock_irqsave(&stallion_lock
, flags
);
1051 if (portp
->tty
->termios
->c_cflag
& CLOCAL
)
1054 portp
->openwaitcnt
++;
1055 if (! tty_hung_up_p(filp
))
1059 /* Takes brd_lock internally */
1060 stl_setsignals(portp
, 1, 1);
1061 if (tty_hung_up_p(filp
) ||
1062 ((portp
->flags
& ASYNC_INITIALIZED
) == 0)) {
1063 if (portp
->flags
& ASYNC_HUP_NOTIFY
)
1069 if (((portp
->flags
& ASYNC_CLOSING
) == 0) &&
1070 (doclocal
|| (portp
->sigs
& TIOCM_CD
))) {
1073 if (signal_pending(current
)) {
1078 interruptible_sleep_on(&portp
->open_wait
);
1081 if (! tty_hung_up_p(filp
))
1083 portp
->openwaitcnt
--;
1084 spin_unlock_irqrestore(&stallion_lock
, flags
);
1089 /*****************************************************************************/
1091 static void stl_close(struct tty_struct
*tty
, struct file
*filp
)
1094 unsigned long flags
;
1097 printk("stl_close(tty=%x,filp=%x)\n", (int) tty
, (int) filp
);
1100 portp
= tty
->driver_data
;
1101 if (portp
== (stlport_t
*) NULL
)
1104 spin_lock_irqsave(&stallion_lock
, flags
);
1105 if (tty_hung_up_p(filp
)) {
1106 spin_unlock_irqrestore(&stallion_lock
, flags
);
1109 if ((tty
->count
== 1) && (portp
->refcount
!= 1))
1110 portp
->refcount
= 1;
1111 if (portp
->refcount
-- > 1) {
1112 spin_unlock_irqrestore(&stallion_lock
, flags
);
1116 portp
->refcount
= 0;
1117 portp
->flags
|= ASYNC_CLOSING
;
1120 * May want to wait for any data to drain before closing. The BUSY
1121 * flag keeps track of whether we are still sending or not - it is
1122 * very accurate for the cd1400, not quite so for the sc26198.
1123 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
1127 spin_unlock_irqrestore(&stallion_lock
, flags
);
1129 if (portp
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
1130 tty_wait_until_sent(tty
, portp
->closing_wait
);
1131 stl_waituntilsent(tty
, (HZ
/ 2));
1134 spin_lock_irqsave(&stallion_lock
, flags
);
1135 portp
->flags
&= ~ASYNC_INITIALIZED
;
1136 spin_unlock_irqrestore(&stallion_lock
, flags
);
1138 stl_disableintrs(portp
);
1139 if (tty
->termios
->c_cflag
& HUPCL
)
1140 stl_setsignals(portp
, 0, 0);
1141 stl_enablerxtx(portp
, 0, 0);
1142 stl_flushbuffer(tty
);
1144 if (portp
->tx
.buf
!= (char *) NULL
) {
1145 kfree(portp
->tx
.buf
);
1146 portp
->tx
.buf
= (char *) NULL
;
1147 portp
->tx
.head
= (char *) NULL
;
1148 portp
->tx
.tail
= (char *) NULL
;
1150 set_bit(TTY_IO_ERROR
, &tty
->flags
);
1151 tty_ldisc_flush(tty
);
1154 portp
->tty
= (struct tty_struct
*) NULL
;
1156 if (portp
->openwaitcnt
) {
1157 if (portp
->close_delay
)
1158 msleep_interruptible(jiffies_to_msecs(portp
->close_delay
));
1159 wake_up_interruptible(&portp
->open_wait
);
1162 portp
->flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
1163 wake_up_interruptible(&portp
->close_wait
);
1166 /*****************************************************************************/
1169 * Write routine. Take data and stuff it in to the TX ring queue.
1170 * If transmit interrupts are not running then start them.
1173 static int stl_write(struct tty_struct
*tty
, const unsigned char *buf
, int count
)
1176 unsigned int len
, stlen
;
1177 unsigned char *chbuf
;
1181 printk("stl_write(tty=%x,buf=%x,count=%d)\n",
1182 (int) tty
, (int) buf
, count
);
1185 portp
= tty
->driver_data
;
1186 if (portp
== (stlport_t
*) NULL
)
1188 if (portp
->tx
.buf
== (char *) NULL
)
1192 * If copying direct from user space we must cater for page faults,
1193 * causing us to "sleep" here for a while. To handle this copy in all
1194 * the data we need now, into a local buffer. Then when we got it all
1195 * copy it into the TX buffer.
1197 chbuf
= (unsigned char *) buf
;
1199 head
= portp
->tx
.head
;
1200 tail
= portp
->tx
.tail
;
1202 len
= STL_TXBUFSIZE
- (head
- tail
) - 1;
1203 stlen
= STL_TXBUFSIZE
- (head
- portp
->tx
.buf
);
1205 len
= tail
- head
- 1;
1209 len
= MIN(len
, count
);
1212 stlen
= MIN(len
, stlen
);
1213 memcpy(head
, chbuf
, stlen
);
1218 if (head
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
)) {
1219 head
= portp
->tx
.buf
;
1220 stlen
= tail
- head
;
1223 portp
->tx
.head
= head
;
1225 clear_bit(ASYI_TXLOW
, &portp
->istate
);
1226 stl_startrxtx(portp
, -1, 1);
1231 /*****************************************************************************/
1233 static void stl_putchar(struct tty_struct
*tty
, unsigned char ch
)
1240 printk("stl_putchar(tty=%x,ch=%x)\n", (int) tty
, (int) ch
);
1243 if (tty
== (struct tty_struct
*) NULL
)
1245 portp
= tty
->driver_data
;
1246 if (portp
== (stlport_t
*) NULL
)
1248 if (portp
->tx
.buf
== (char *) NULL
)
1251 head
= portp
->tx
.head
;
1252 tail
= portp
->tx
.tail
;
1254 len
= (head
>= tail
) ? (STL_TXBUFSIZE
- (head
- tail
)) : (tail
- head
);
1259 if (head
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
))
1260 head
= portp
->tx
.buf
;
1262 portp
->tx
.head
= head
;
1265 /*****************************************************************************/
1268 * If there are any characters in the buffer then make sure that TX
1269 * interrupts are on and get'em out. Normally used after the putchar
1270 * routine has been called.
1273 static void stl_flushchars(struct tty_struct
*tty
)
1278 printk("stl_flushchars(tty=%x)\n", (int) tty
);
1281 if (tty
== (struct tty_struct
*) NULL
)
1283 portp
= tty
->driver_data
;
1284 if (portp
== (stlport_t
*) NULL
)
1286 if (portp
->tx
.buf
== (char *) NULL
)
1289 stl_startrxtx(portp
, -1, 1);
1292 /*****************************************************************************/
1294 static int stl_writeroom(struct tty_struct
*tty
)
1300 printk("stl_writeroom(tty=%x)\n", (int) tty
);
1303 if (tty
== (struct tty_struct
*) NULL
)
1305 portp
= tty
->driver_data
;
1306 if (portp
== (stlport_t
*) NULL
)
1308 if (portp
->tx
.buf
== (char *) NULL
)
1311 head
= portp
->tx
.head
;
1312 tail
= portp
->tx
.tail
;
1313 return ((head
>= tail
) ? (STL_TXBUFSIZE
- (head
- tail
) - 1) : (tail
- head
- 1));
1316 /*****************************************************************************/
1319 * Return number of chars in the TX buffer. Normally we would just
1320 * calculate the number of chars in the buffer and return that, but if
1321 * the buffer is empty and TX interrupts are still on then we return
1322 * that the buffer still has 1 char in it. This way whoever called us
1323 * will not think that ALL chars have drained - since the UART still
1324 * must have some chars in it (we are busy after all).
1327 static int stl_charsinbuffer(struct tty_struct
*tty
)
1334 printk("stl_charsinbuffer(tty=%x)\n", (int) tty
);
1337 if (tty
== (struct tty_struct
*) NULL
)
1339 portp
= tty
->driver_data
;
1340 if (portp
== (stlport_t
*) NULL
)
1342 if (portp
->tx
.buf
== (char *) NULL
)
1345 head
= portp
->tx
.head
;
1346 tail
= portp
->tx
.tail
;
1347 size
= (head
>= tail
) ? (head
- tail
) : (STL_TXBUFSIZE
- (tail
- head
));
1348 if ((size
== 0) && test_bit(ASYI_TXBUSY
, &portp
->istate
))
1353 /*****************************************************************************/
1356 * Generate the serial struct info.
1359 static int stl_getserial(stlport_t
*portp
, struct serial_struct __user
*sp
)
1361 struct serial_struct sio
;
1365 printk("stl_getserial(portp=%x,sp=%x)\n", (int) portp
, (int) sp
);
1368 memset(&sio
, 0, sizeof(struct serial_struct
));
1369 sio
.line
= portp
->portnr
;
1370 sio
.port
= portp
->ioaddr
;
1371 sio
.flags
= portp
->flags
;
1372 sio
.baud_base
= portp
->baud_base
;
1373 sio
.close_delay
= portp
->close_delay
;
1374 sio
.closing_wait
= portp
->closing_wait
;
1375 sio
.custom_divisor
= portp
->custom_divisor
;
1377 if (portp
->uartp
== &stl_cd1400uart
) {
1378 sio
.type
= PORT_CIRRUS
;
1379 sio
.xmit_fifo_size
= CD1400_TXFIFOSIZE
;
1381 sio
.type
= PORT_UNKNOWN
;
1382 sio
.xmit_fifo_size
= SC26198_TXFIFOSIZE
;
1385 brdp
= stl_brds
[portp
->brdnr
];
1386 if (brdp
!= (stlbrd_t
*) NULL
)
1387 sio
.irq
= brdp
->irq
;
1389 return copy_to_user(sp
, &sio
, sizeof(struct serial_struct
)) ? -EFAULT
: 0;
1392 /*****************************************************************************/
1395 * Set port according to the serial struct info.
1396 * At this point we do not do any auto-configure stuff, so we will
1397 * just quietly ignore any requests to change irq, etc.
1400 static int stl_setserial(stlport_t
*portp
, struct serial_struct __user
*sp
)
1402 struct serial_struct sio
;
1405 printk("stl_setserial(portp=%x,sp=%x)\n", (int) portp
, (int) sp
);
1408 if (copy_from_user(&sio
, sp
, sizeof(struct serial_struct
)))
1410 if (!capable(CAP_SYS_ADMIN
)) {
1411 if ((sio
.baud_base
!= portp
->baud_base
) ||
1412 (sio
.close_delay
!= portp
->close_delay
) ||
1413 ((sio
.flags
& ~ASYNC_USR_MASK
) !=
1414 (portp
->flags
& ~ASYNC_USR_MASK
)))
1418 portp
->flags
= (portp
->flags
& ~ASYNC_USR_MASK
) |
1419 (sio
.flags
& ASYNC_USR_MASK
);
1420 portp
->baud_base
= sio
.baud_base
;
1421 portp
->close_delay
= sio
.close_delay
;
1422 portp
->closing_wait
= sio
.closing_wait
;
1423 portp
->custom_divisor
= sio
.custom_divisor
;
1424 stl_setport(portp
, portp
->tty
->termios
);
1428 /*****************************************************************************/
1430 static int stl_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1434 if (tty
== (struct tty_struct
*) NULL
)
1436 portp
= tty
->driver_data
;
1437 if (portp
== (stlport_t
*) NULL
)
1439 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1442 return stl_getsignals(portp
);
1445 static int stl_tiocmset(struct tty_struct
*tty
, struct file
*file
,
1446 unsigned int set
, unsigned int clear
)
1449 int rts
= -1, dtr
= -1;
1451 if (tty
== (struct tty_struct
*) NULL
)
1453 portp
= tty
->driver_data
;
1454 if (portp
== (stlport_t
*) NULL
)
1456 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1459 if (set
& TIOCM_RTS
)
1461 if (set
& TIOCM_DTR
)
1463 if (clear
& TIOCM_RTS
)
1465 if (clear
& TIOCM_DTR
)
1468 stl_setsignals(portp
, dtr
, rts
);
1472 static int stl_ioctl(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
1477 void __user
*argp
= (void __user
*)arg
;
1480 printk("stl_ioctl(tty=%x,file=%x,cmd=%x,arg=%x)\n",
1481 (int) tty
, (int) file
, cmd
, (int) arg
);
1484 if (tty
== (struct tty_struct
*) NULL
)
1486 portp
= tty
->driver_data
;
1487 if (portp
== (stlport_t
*) NULL
)
1490 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1491 (cmd
!= COM_GETPORTSTATS
) && (cmd
!= COM_CLRPORTSTATS
)) {
1492 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1500 rc
= put_user(((tty
->termios
->c_cflag
& CLOCAL
) ? 1 : 0),
1501 (unsigned __user
*) argp
);
1504 if (get_user(ival
, (unsigned int __user
*) arg
))
1506 tty
->termios
->c_cflag
=
1507 (tty
->termios
->c_cflag
& ~CLOCAL
) |
1508 (ival
? CLOCAL
: 0);
1511 rc
= stl_getserial(portp
, argp
);
1514 rc
= stl_setserial(portp
, argp
);
1516 case COM_GETPORTSTATS
:
1517 rc
= stl_getportstats(portp
, argp
);
1519 case COM_CLRPORTSTATS
:
1520 rc
= stl_clrportstats(portp
, argp
);
1526 case TIOCSERGSTRUCT
:
1527 case TIOCSERGETMULTI
:
1528 case TIOCSERSETMULTI
:
1537 /*****************************************************************************/
1539 static void stl_settermios(struct tty_struct
*tty
, struct termios
*old
)
1542 struct termios
*tiosp
;
1545 printk("stl_settermios(tty=%x,old=%x)\n", (int) tty
, (int) old
);
1548 if (tty
== (struct tty_struct
*) NULL
)
1550 portp
= tty
->driver_data
;
1551 if (portp
== (stlport_t
*) NULL
)
1554 tiosp
= tty
->termios
;
1555 if ((tiosp
->c_cflag
== old
->c_cflag
) &&
1556 (tiosp
->c_iflag
== old
->c_iflag
))
1559 stl_setport(portp
, tiosp
);
1560 stl_setsignals(portp
, ((tiosp
->c_cflag
& (CBAUD
& ~CBAUDEX
)) ? 1 : 0),
1562 if ((old
->c_cflag
& CRTSCTS
) && ((tiosp
->c_cflag
& CRTSCTS
) == 0)) {
1563 tty
->hw_stopped
= 0;
1566 if (((old
->c_cflag
& CLOCAL
) == 0) && (tiosp
->c_cflag
& CLOCAL
))
1567 wake_up_interruptible(&portp
->open_wait
);
1570 /*****************************************************************************/
1573 * Attempt to flow control who ever is sending us data. Based on termios
1574 * settings use software or/and hardware flow control.
1577 static void stl_throttle(struct tty_struct
*tty
)
1582 printk("stl_throttle(tty=%x)\n", (int) tty
);
1585 if (tty
== (struct tty_struct
*) NULL
)
1587 portp
= tty
->driver_data
;
1588 if (portp
== (stlport_t
*) NULL
)
1590 stl_flowctrl(portp
, 0);
1593 /*****************************************************************************/
1596 * Unflow control the device sending us data...
1599 static void stl_unthrottle(struct tty_struct
*tty
)
1604 printk("stl_unthrottle(tty=%x)\n", (int) tty
);
1607 if (tty
== (struct tty_struct
*) NULL
)
1609 portp
= tty
->driver_data
;
1610 if (portp
== (stlport_t
*) NULL
)
1612 stl_flowctrl(portp
, 1);
1615 /*****************************************************************************/
1618 * Stop the transmitter. Basically to do this we will just turn TX
1622 static void stl_stop(struct tty_struct
*tty
)
1627 printk("stl_stop(tty=%x)\n", (int) tty
);
1630 if (tty
== (struct tty_struct
*) NULL
)
1632 portp
= tty
->driver_data
;
1633 if (portp
== (stlport_t
*) NULL
)
1635 stl_startrxtx(portp
, -1, 0);
1638 /*****************************************************************************/
1641 * Start the transmitter again. Just turn TX interrupts back on.
1644 static void stl_start(struct tty_struct
*tty
)
1649 printk("stl_start(tty=%x)\n", (int) tty
);
1652 if (tty
== (struct tty_struct
*) NULL
)
1654 portp
= tty
->driver_data
;
1655 if (portp
== (stlport_t
*) NULL
)
1657 stl_startrxtx(portp
, -1, 1);
1660 /*****************************************************************************/
1663 * Hangup this port. This is pretty much like closing the port, only
1664 * a little more brutal. No waiting for data to drain. Shutdown the
1665 * port and maybe drop signals.
1668 static void stl_hangup(struct tty_struct
*tty
)
1673 printk("stl_hangup(tty=%x)\n", (int) tty
);
1676 if (tty
== (struct tty_struct
*) NULL
)
1678 portp
= tty
->driver_data
;
1679 if (portp
== (stlport_t
*) NULL
)
1682 portp
->flags
&= ~ASYNC_INITIALIZED
;
1683 stl_disableintrs(portp
);
1684 if (tty
->termios
->c_cflag
& HUPCL
)
1685 stl_setsignals(portp
, 0, 0);
1686 stl_enablerxtx(portp
, 0, 0);
1687 stl_flushbuffer(tty
);
1689 set_bit(TTY_IO_ERROR
, &tty
->flags
);
1690 if (portp
->tx
.buf
!= (char *) NULL
) {
1691 kfree(portp
->tx
.buf
);
1692 portp
->tx
.buf
= (char *) NULL
;
1693 portp
->tx
.head
= (char *) NULL
;
1694 portp
->tx
.tail
= (char *) NULL
;
1696 portp
->tty
= (struct tty_struct
*) NULL
;
1697 portp
->flags
&= ~ASYNC_NORMAL_ACTIVE
;
1698 portp
->refcount
= 0;
1699 wake_up_interruptible(&portp
->open_wait
);
1702 /*****************************************************************************/
1704 static void stl_flushbuffer(struct tty_struct
*tty
)
1709 printk("stl_flushbuffer(tty=%x)\n", (int) tty
);
1712 if (tty
== (struct tty_struct
*) NULL
)
1714 portp
= tty
->driver_data
;
1715 if (portp
== (stlport_t
*) NULL
)
1722 /*****************************************************************************/
1724 static void stl_breakctl(struct tty_struct
*tty
, int state
)
1729 printk("stl_breakctl(tty=%x,state=%d)\n", (int) tty
, state
);
1732 if (tty
== (struct tty_struct
*) NULL
)
1734 portp
= tty
->driver_data
;
1735 if (portp
== (stlport_t
*) NULL
)
1738 stl_sendbreak(portp
, ((state
== -1) ? 1 : 2));
1741 /*****************************************************************************/
1743 static void stl_waituntilsent(struct tty_struct
*tty
, int timeout
)
1749 printk("stl_waituntilsent(tty=%x,timeout=%d)\n", (int) tty
, timeout
);
1752 if (tty
== (struct tty_struct
*) NULL
)
1754 portp
= tty
->driver_data
;
1755 if (portp
== (stlport_t
*) NULL
)
1760 tend
= jiffies
+ timeout
;
1762 while (stl_datastate(portp
)) {
1763 if (signal_pending(current
))
1765 msleep_interruptible(20);
1766 if (time_after_eq(jiffies
, tend
))
1771 /*****************************************************************************/
1773 static void stl_sendxchar(struct tty_struct
*tty
, char ch
)
1778 printk("stl_sendxchar(tty=%x,ch=%x)\n", (int) tty
, ch
);
1781 if (tty
== (struct tty_struct
*) NULL
)
1783 portp
= tty
->driver_data
;
1784 if (portp
== (stlport_t
*) NULL
)
1787 if (ch
== STOP_CHAR(tty
))
1788 stl_sendflow(portp
, 0);
1789 else if (ch
== START_CHAR(tty
))
1790 stl_sendflow(portp
, 1);
1792 stl_putchar(tty
, ch
);
1795 /*****************************************************************************/
1800 * Format info for a specified port. The line is deliberately limited
1801 * to 80 characters. (If it is too long it will be truncated, if too
1802 * short then padded with spaces).
1805 static int stl_portinfo(stlport_t
*portp
, int portnr
, char *pos
)
1811 sp
+= sprintf(sp
, "%d: uart:%s tx:%d rx:%d",
1812 portnr
, (portp
->hwid
== 1) ? "SC26198" : "CD1400",
1813 (int) portp
->stats
.txtotal
, (int) portp
->stats
.rxtotal
);
1815 if (portp
->stats
.rxframing
)
1816 sp
+= sprintf(sp
, " fe:%d", (int) portp
->stats
.rxframing
);
1817 if (portp
->stats
.rxparity
)
1818 sp
+= sprintf(sp
, " pe:%d", (int) portp
->stats
.rxparity
);
1819 if (portp
->stats
.rxbreaks
)
1820 sp
+= sprintf(sp
, " brk:%d", (int) portp
->stats
.rxbreaks
);
1821 if (portp
->stats
.rxoverrun
)
1822 sp
+= sprintf(sp
, " oe:%d", (int) portp
->stats
.rxoverrun
);
1824 sigs
= stl_getsignals(portp
);
1825 cnt
= sprintf(sp
, "%s%s%s%s%s ",
1826 (sigs
& TIOCM_RTS
) ? "|RTS" : "",
1827 (sigs
& TIOCM_CTS
) ? "|CTS" : "",
1828 (sigs
& TIOCM_DTR
) ? "|DTR" : "",
1829 (sigs
& TIOCM_CD
) ? "|DCD" : "",
1830 (sigs
& TIOCM_DSR
) ? "|DSR" : "");
1834 for (cnt
= (sp
- pos
); (cnt
< (MAXLINE
- 1)); cnt
++)
1837 pos
[(MAXLINE
- 2)] = '+';
1838 pos
[(MAXLINE
- 1)] = '\n';
1843 /*****************************************************************************/
1846 * Port info, read from the /proc file system.
1849 static int stl_readproc(char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
1854 int brdnr
, panelnr
, portnr
, totalport
;
1859 printk("stl_readproc(page=%x,start=%x,off=%x,count=%d,eof=%x,"
1860 "data=%x\n", (int) page
, (int) start
, (int) off
, count
,
1861 (int) eof
, (int) data
);
1869 pos
+= sprintf(pos
, "%s: version %s", stl_drvtitle
,
1871 while (pos
< (page
+ MAXLINE
- 1))
1878 * We scan through for each board, panel and port. The offset is
1879 * calculated on the fly, and irrelevant ports are skipped.
1881 for (brdnr
= 0; (brdnr
< stl_nrbrds
); brdnr
++) {
1882 brdp
= stl_brds
[brdnr
];
1883 if (brdp
== (stlbrd_t
*) NULL
)
1885 if (brdp
->state
== 0)
1888 maxoff
= curoff
+ (brdp
->nrports
* MAXLINE
);
1889 if (off
>= maxoff
) {
1894 totalport
= brdnr
* STL_MAXPORTS
;
1895 for (panelnr
= 0; (panelnr
< brdp
->nrpanels
); panelnr
++) {
1896 panelp
= brdp
->panels
[panelnr
];
1897 if (panelp
== (stlpanel_t
*) NULL
)
1900 maxoff
= curoff
+ (panelp
->nrports
* MAXLINE
);
1901 if (off
>= maxoff
) {
1903 totalport
+= panelp
->nrports
;
1907 for (portnr
= 0; (portnr
< panelp
->nrports
); portnr
++,
1909 portp
= panelp
->ports
[portnr
];
1910 if (portp
== (stlport_t
*) NULL
)
1912 if (off
>= (curoff
+= MAXLINE
))
1914 if ((pos
- page
+ MAXLINE
) > count
)
1916 pos
+= stl_portinfo(portp
, totalport
, pos
);
1925 return (pos
- page
);
1928 /*****************************************************************************/
1931 * All board interrupts are vectored through here first. This code then
1932 * calls off to the approrpriate board interrupt handlers.
1935 static irqreturn_t
stl_intr(int irq
, void *dev_id
, struct pt_regs
*regs
)
1937 stlbrd_t
*brdp
= (stlbrd_t
*) dev_id
;
1940 printk("stl_intr(brdp=%x,irq=%d,regs=%x)\n", (int) brdp
, irq
,
1944 return IRQ_RETVAL((* brdp
->isr
)(brdp
));
1947 /*****************************************************************************/
1950 * Interrupt service routine for EasyIO board types.
1953 static int stl_eiointr(stlbrd_t
*brdp
)
1956 unsigned int iobase
;
1959 spin_lock(&brd_lock
);
1960 panelp
= brdp
->panels
[0];
1961 iobase
= panelp
->iobase
;
1962 while (inb(brdp
->iostatus
) & EIO_INTRPEND
) {
1964 (* panelp
->isr
)(panelp
, iobase
);
1966 spin_unlock(&brd_lock
);
1970 /*****************************************************************************/
1973 * Interrupt service routine for ECH-AT board types.
1976 static int stl_echatintr(stlbrd_t
*brdp
)
1979 unsigned int ioaddr
;
1983 outb((brdp
->ioctrlval
| ECH_BRDENABLE
), brdp
->ioctrl
);
1985 while (inb(brdp
->iostatus
) & ECH_INTRPEND
) {
1987 for (bnknr
= 0; (bnknr
< brdp
->nrbnks
); bnknr
++) {
1988 ioaddr
= brdp
->bnkstataddr
[bnknr
];
1989 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
1990 panelp
= brdp
->bnk2panel
[bnknr
];
1991 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
1996 outb((brdp
->ioctrlval
| ECH_BRDDISABLE
), brdp
->ioctrl
);
2001 /*****************************************************************************/
2004 * Interrupt service routine for ECH-MCA board types.
2007 static int stl_echmcaintr(stlbrd_t
*brdp
)
2010 unsigned int ioaddr
;
2014 while (inb(brdp
->iostatus
) & ECH_INTRPEND
) {
2016 for (bnknr
= 0; (bnknr
< brdp
->nrbnks
); bnknr
++) {
2017 ioaddr
= brdp
->bnkstataddr
[bnknr
];
2018 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
2019 panelp
= brdp
->bnk2panel
[bnknr
];
2020 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
2027 /*****************************************************************************/
2030 * Interrupt service routine for ECH-PCI board types.
2033 static int stl_echpciintr(stlbrd_t
*brdp
)
2036 unsigned int ioaddr
;
2042 for (bnknr
= 0; (bnknr
< brdp
->nrbnks
); bnknr
++) {
2043 outb(brdp
->bnkpageaddr
[bnknr
], brdp
->ioctrl
);
2044 ioaddr
= brdp
->bnkstataddr
[bnknr
];
2045 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
2046 panelp
= brdp
->bnk2panel
[bnknr
];
2047 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
2058 /*****************************************************************************/
2061 * Interrupt service routine for ECH-8/64-PCI board types.
2064 static int stl_echpci64intr(stlbrd_t
*brdp
)
2067 unsigned int ioaddr
;
2071 while (inb(brdp
->ioctrl
) & 0x1) {
2073 for (bnknr
= 0; (bnknr
< brdp
->nrbnks
); bnknr
++) {
2074 ioaddr
= brdp
->bnkstataddr
[bnknr
];
2075 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
2076 panelp
= brdp
->bnk2panel
[bnknr
];
2077 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
2085 /*****************************************************************************/
2088 * Service an off-level request for some channel.
2090 static void stl_offintr(void *private)
2093 struct tty_struct
*tty
;
2094 unsigned int oldsigs
;
2099 printk("stl_offintr(portp=%x)\n", (int) portp
);
2102 if (portp
== (stlport_t
*) NULL
)
2106 if (tty
== (struct tty_struct
*) NULL
)
2110 if (test_bit(ASYI_TXLOW
, &portp
->istate
)) {
2113 if (test_bit(ASYI_DCDCHANGE
, &portp
->istate
)) {
2114 clear_bit(ASYI_DCDCHANGE
, &portp
->istate
);
2115 oldsigs
= portp
->sigs
;
2116 portp
->sigs
= stl_getsignals(portp
);
2117 if ((portp
->sigs
& TIOCM_CD
) && ((oldsigs
& TIOCM_CD
) == 0))
2118 wake_up_interruptible(&portp
->open_wait
);
2119 if ((oldsigs
& TIOCM_CD
) && ((portp
->sigs
& TIOCM_CD
) == 0)) {
2120 if (portp
->flags
& ASYNC_CHECK_CD
)
2121 tty_hangup(tty
); /* FIXME: module removal race here - AKPM */
2127 /*****************************************************************************/
2130 * Initialize all the ports on a panel.
2133 static int __init
stl_initports(stlbrd_t
*brdp
, stlpanel_t
*panelp
)
2139 printk("stl_initports(brdp=%x,panelp=%x)\n", (int) brdp
, (int) panelp
);
2142 chipmask
= stl_panelinit(brdp
, panelp
);
2145 * All UART's are initialized (if found!). Now go through and setup
2146 * each ports data structures.
2148 for (i
= 0; (i
< panelp
->nrports
); i
++) {
2149 portp
= kzalloc(sizeof(stlport_t
), GFP_KERNEL
);
2151 printk("STALLION: failed to allocate memory "
2152 "(size=%Zd)\n", sizeof(stlport_t
));
2156 portp
->magic
= STL_PORTMAGIC
;
2158 portp
->brdnr
= panelp
->brdnr
;
2159 portp
->panelnr
= panelp
->panelnr
;
2160 portp
->uartp
= panelp
->uartp
;
2161 portp
->clk
= brdp
->clk
;
2162 portp
->baud_base
= STL_BAUDBASE
;
2163 portp
->close_delay
= STL_CLOSEDELAY
;
2164 portp
->closing_wait
= 30 * HZ
;
2165 INIT_WORK(&portp
->tqueue
, stl_offintr
, portp
);
2166 init_waitqueue_head(&portp
->open_wait
);
2167 init_waitqueue_head(&portp
->close_wait
);
2168 portp
->stats
.brd
= portp
->brdnr
;
2169 portp
->stats
.panel
= portp
->panelnr
;
2170 portp
->stats
.port
= portp
->portnr
;
2171 panelp
->ports
[i
] = portp
;
2172 stl_portinit(brdp
, panelp
, portp
);
2178 /*****************************************************************************/
2181 * Try to find and initialize an EasyIO board.
2184 static inline int stl_initeio(stlbrd_t
*brdp
)
2187 unsigned int status
;
2192 printk("stl_initeio(brdp=%x)\n", (int) brdp
);
2195 brdp
->ioctrl
= brdp
->ioaddr1
+ 1;
2196 brdp
->iostatus
= brdp
->ioaddr1
+ 2;
2198 status
= inb(brdp
->iostatus
);
2199 if ((status
& EIO_IDBITMASK
) == EIO_MK3
)
2203 * Handle board specific stuff now. The real difference is PCI
2206 if (brdp
->brdtype
== BRD_EASYIOPCI
) {
2207 brdp
->iosize1
= 0x80;
2208 brdp
->iosize2
= 0x80;
2209 name
= "serial(EIO-PCI)";
2210 outb(0x41, (brdp
->ioaddr2
+ 0x4c));
2213 name
= "serial(EIO)";
2214 if ((brdp
->irq
< 0) || (brdp
->irq
> 15) ||
2215 (stl_vecmap
[brdp
->irq
] == (unsigned char) 0xff)) {
2216 printk("STALLION: invalid irq=%d for brd=%d\n",
2217 brdp
->irq
, brdp
->brdnr
);
2220 outb((stl_vecmap
[brdp
->irq
] | EIO_0WS
|
2221 ((brdp
->irqtype
) ? EIO_INTLEVEL
: EIO_INTEDGE
)),
2225 if (!request_region(brdp
->ioaddr1
, brdp
->iosize1
, name
)) {
2226 printk(KERN_WARNING
"STALLION: Warning, board %d I/O address "
2227 "%x conflicts with another device\n", brdp
->brdnr
,
2232 if (brdp
->iosize2
> 0)
2233 if (!request_region(brdp
->ioaddr2
, brdp
->iosize2
, name
)) {
2234 printk(KERN_WARNING
"STALLION: Warning, board %d I/O "
2235 "address %x conflicts with another device\n",
2236 brdp
->brdnr
, brdp
->ioaddr2
);
2237 printk(KERN_WARNING
"STALLION: Warning, also "
2238 "releasing board %d I/O address %x \n",
2239 brdp
->brdnr
, brdp
->ioaddr1
);
2240 release_region(brdp
->ioaddr1
, brdp
->iosize1
);
2245 * Everything looks OK, so let's go ahead and probe for the hardware.
2247 brdp
->clk
= CD1400_CLK
;
2248 brdp
->isr
= stl_eiointr
;
2250 switch (status
& EIO_IDBITMASK
) {
2252 brdp
->clk
= CD1400_CLK8M
;
2262 switch (status
& EIO_BRDMASK
) {
2281 * We have verified that the board is actually present, so now we
2282 * can complete the setup.
2285 panelp
= kzalloc(sizeof(stlpanel_t
), GFP_KERNEL
);
2287 printk(KERN_WARNING
"STALLION: failed to allocate memory "
2288 "(size=%Zd)\n", sizeof(stlpanel_t
));
2292 panelp
->magic
= STL_PANELMAGIC
;
2293 panelp
->brdnr
= brdp
->brdnr
;
2294 panelp
->panelnr
= 0;
2295 panelp
->nrports
= brdp
->nrports
;
2296 panelp
->iobase
= brdp
->ioaddr1
;
2297 panelp
->hwid
= status
;
2298 if ((status
& EIO_IDBITMASK
) == EIO_MK3
) {
2299 panelp
->uartp
= (void *) &stl_sc26198uart
;
2300 panelp
->isr
= stl_sc26198intr
;
2302 panelp
->uartp
= (void *) &stl_cd1400uart
;
2303 panelp
->isr
= stl_cd1400eiointr
;
2306 brdp
->panels
[0] = panelp
;
2308 brdp
->state
|= BRD_FOUND
;
2309 brdp
->hwid
= status
;
2310 if (request_irq(brdp
->irq
, stl_intr
, SA_SHIRQ
, name
, brdp
) != 0) {
2311 printk("STALLION: failed to register interrupt "
2312 "routine for %s irq=%d\n", name
, brdp
->irq
);
2320 /*****************************************************************************/
2323 * Try to find an ECH board and initialize it. This code is capable of
2324 * dealing with all types of ECH board.
2327 static inline int stl_initech(stlbrd_t
*brdp
)
2330 unsigned int status
, nxtid
, ioaddr
, conflict
;
2331 int panelnr
, banknr
, i
;
2335 printk("stl_initech(brdp=%x)\n", (int) brdp
);
2342 * Set up the initial board register contents for boards. This varies a
2343 * bit between the different board types. So we need to handle each
2344 * separately. Also do a check that the supplied IRQ is good.
2346 switch (brdp
->brdtype
) {
2349 brdp
->isr
= stl_echatintr
;
2350 brdp
->ioctrl
= brdp
->ioaddr1
+ 1;
2351 brdp
->iostatus
= brdp
->ioaddr1
+ 1;
2352 status
= inb(brdp
->iostatus
);
2353 if ((status
& ECH_IDBITMASK
) != ECH_ID
)
2355 if ((brdp
->irq
< 0) || (brdp
->irq
> 15) ||
2356 (stl_vecmap
[brdp
->irq
] == (unsigned char) 0xff)) {
2357 printk("STALLION: invalid irq=%d for brd=%d\n",
2358 brdp
->irq
, brdp
->brdnr
);
2361 status
= ((brdp
->ioaddr2
& ECH_ADDR2MASK
) >> 1);
2362 status
|= (stl_vecmap
[brdp
->irq
] << 1);
2363 outb((status
| ECH_BRDRESET
), brdp
->ioaddr1
);
2364 brdp
->ioctrlval
= ECH_INTENABLE
|
2365 ((brdp
->irqtype
) ? ECH_INTLEVEL
: ECH_INTEDGE
);
2366 for (i
= 0; (i
< 10); i
++)
2367 outb((brdp
->ioctrlval
| ECH_BRDENABLE
), brdp
->ioctrl
);
2370 name
= "serial(EC8/32)";
2371 outb(status
, brdp
->ioaddr1
);
2375 brdp
->isr
= stl_echmcaintr
;
2376 brdp
->ioctrl
= brdp
->ioaddr1
+ 0x20;
2377 brdp
->iostatus
= brdp
->ioctrl
;
2378 status
= inb(brdp
->iostatus
);
2379 if ((status
& ECH_IDBITMASK
) != ECH_ID
)
2381 if ((brdp
->irq
< 0) || (brdp
->irq
> 15) ||
2382 (stl_vecmap
[brdp
->irq
] == (unsigned char) 0xff)) {
2383 printk("STALLION: invalid irq=%d for brd=%d\n",
2384 brdp
->irq
, brdp
->brdnr
);
2387 outb(ECHMC_BRDRESET
, brdp
->ioctrl
);
2388 outb(ECHMC_INTENABLE
, brdp
->ioctrl
);
2390 name
= "serial(EC8/32-MC)";
2394 brdp
->isr
= stl_echpciintr
;
2395 brdp
->ioctrl
= brdp
->ioaddr1
+ 2;
2398 name
= "serial(EC8/32-PCI)";
2402 brdp
->isr
= stl_echpci64intr
;
2403 brdp
->ioctrl
= brdp
->ioaddr2
+ 0x40;
2404 outb(0x43, (brdp
->ioaddr1
+ 0x4c));
2405 brdp
->iosize1
= 0x80;
2406 brdp
->iosize2
= 0x80;
2407 name
= "serial(EC8/64-PCI)";
2411 printk("STALLION: unknown board type=%d\n", brdp
->brdtype
);
2417 * Check boards for possible IO address conflicts and return fail status
2418 * if an IO conflict found.
2420 if (!request_region(brdp
->ioaddr1
, brdp
->iosize1
, name
)) {
2421 printk(KERN_WARNING
"STALLION: Warning, board %d I/O address "
2422 "%x conflicts with another device\n", brdp
->brdnr
,
2427 if (brdp
->iosize2
> 0)
2428 if (!request_region(brdp
->ioaddr2
, brdp
->iosize2
, name
)) {
2429 printk(KERN_WARNING
"STALLION: Warning, board %d I/O "
2430 "address %x conflicts with another device\n",
2431 brdp
->brdnr
, brdp
->ioaddr2
);
2432 printk(KERN_WARNING
"STALLION: Warning, also "
2433 "releasing board %d I/O address %x \n",
2434 brdp
->brdnr
, brdp
->ioaddr1
);
2435 release_region(brdp
->ioaddr1
, brdp
->iosize1
);
2440 * Scan through the secondary io address space looking for panels.
2441 * As we find'em allocate and initialize panel structures for each.
2443 brdp
->clk
= CD1400_CLK
;
2444 brdp
->hwid
= status
;
2446 ioaddr
= brdp
->ioaddr2
;
2451 for (i
= 0; (i
< STL_MAXPANELS
); i
++) {
2452 if (brdp
->brdtype
== BRD_ECHPCI
) {
2453 outb(nxtid
, brdp
->ioctrl
);
2454 ioaddr
= brdp
->ioaddr2
;
2456 status
= inb(ioaddr
+ ECH_PNLSTATUS
);
2457 if ((status
& ECH_PNLIDMASK
) != nxtid
)
2459 panelp
= kzalloc(sizeof(stlpanel_t
), GFP_KERNEL
);
2461 printk("STALLION: failed to allocate memory "
2462 "(size=%Zd)\n", sizeof(stlpanel_t
));
2465 panelp
->magic
= STL_PANELMAGIC
;
2466 panelp
->brdnr
= brdp
->brdnr
;
2467 panelp
->panelnr
= panelnr
;
2468 panelp
->iobase
= ioaddr
;
2469 panelp
->pagenr
= nxtid
;
2470 panelp
->hwid
= status
;
2471 brdp
->bnk2panel
[banknr
] = panelp
;
2472 brdp
->bnkpageaddr
[banknr
] = nxtid
;
2473 brdp
->bnkstataddr
[banknr
++] = ioaddr
+ ECH_PNLSTATUS
;
2475 if (status
& ECH_PNLXPID
) {
2476 panelp
->uartp
= (void *) &stl_sc26198uart
;
2477 panelp
->isr
= stl_sc26198intr
;
2478 if (status
& ECH_PNL16PORT
) {
2479 panelp
->nrports
= 16;
2480 brdp
->bnk2panel
[banknr
] = panelp
;
2481 brdp
->bnkpageaddr
[banknr
] = nxtid
;
2482 brdp
->bnkstataddr
[banknr
++] = ioaddr
+ 4 +
2485 panelp
->nrports
= 8;
2488 panelp
->uartp
= (void *) &stl_cd1400uart
;
2489 panelp
->isr
= stl_cd1400echintr
;
2490 if (status
& ECH_PNL16PORT
) {
2491 panelp
->nrports
= 16;
2492 panelp
->ackmask
= 0x80;
2493 if (brdp
->brdtype
!= BRD_ECHPCI
)
2494 ioaddr
+= EREG_BANKSIZE
;
2495 brdp
->bnk2panel
[banknr
] = panelp
;
2496 brdp
->bnkpageaddr
[banknr
] = ++nxtid
;
2497 brdp
->bnkstataddr
[banknr
++] = ioaddr
+
2500 panelp
->nrports
= 8;
2501 panelp
->ackmask
= 0xc0;
2506 ioaddr
+= EREG_BANKSIZE
;
2507 brdp
->nrports
+= panelp
->nrports
;
2508 brdp
->panels
[panelnr
++] = panelp
;
2509 if ((brdp
->brdtype
!= BRD_ECHPCI
) &&
2510 (ioaddr
>= (brdp
->ioaddr2
+ brdp
->iosize2
)))
2514 brdp
->nrpanels
= panelnr
;
2515 brdp
->nrbnks
= banknr
;
2516 if (brdp
->brdtype
== BRD_ECH
)
2517 outb((brdp
->ioctrlval
| ECH_BRDDISABLE
), brdp
->ioctrl
);
2519 brdp
->state
|= BRD_FOUND
;
2520 if (request_irq(brdp
->irq
, stl_intr
, SA_SHIRQ
, name
, brdp
) != 0) {
2521 printk("STALLION: failed to register interrupt "
2522 "routine for %s irq=%d\n", name
, brdp
->irq
);
2531 /*****************************************************************************/
2534 * Initialize and configure the specified board.
2535 * Scan through all the boards in the configuration and see what we
2536 * can find. Handle EIO and the ECH boards a little differently here
2537 * since the initial search and setup is very different.
2540 static int __init
stl_brdinit(stlbrd_t
*brdp
)
2545 printk("stl_brdinit(brdp=%x)\n", (int) brdp
);
2548 switch (brdp
->brdtype
) {
2560 printk("STALLION: board=%d is unknown board type=%d\n",
2561 brdp
->brdnr
, brdp
->brdtype
);
2565 stl_brds
[brdp
->brdnr
] = brdp
;
2566 if ((brdp
->state
& BRD_FOUND
) == 0) {
2567 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2568 stl_brdnames
[brdp
->brdtype
], brdp
->brdnr
,
2569 brdp
->ioaddr1
, brdp
->irq
);
2573 for (i
= 0; (i
< STL_MAXPANELS
); i
++)
2574 if (brdp
->panels
[i
] != (stlpanel_t
*) NULL
)
2575 stl_initports(brdp
, brdp
->panels
[i
]);
2577 printk("STALLION: %s found, board=%d io=%x irq=%d "
2578 "nrpanels=%d nrports=%d\n", stl_brdnames
[brdp
->brdtype
],
2579 brdp
->brdnr
, brdp
->ioaddr1
, brdp
->irq
, brdp
->nrpanels
,
2584 /*****************************************************************************/
2587 * Find the next available board number that is free.
2590 static inline int stl_getbrdnr(void)
2594 for (i
= 0; (i
< STL_MAXBRDS
); i
++) {
2595 if (stl_brds
[i
] == (stlbrd_t
*) NULL
) {
2596 if (i
>= stl_nrbrds
)
2604 /*****************************************************************************/
2609 * We have a Stallion board. Allocate a board structure and
2610 * initialize it. Read its IO and IRQ resources from PCI
2611 * configuration space.
2614 static inline int stl_initpcibrd(int brdtype
, struct pci_dev
*devp
)
2619 printk("stl_initpcibrd(brdtype=%d,busnr=%x,devnr=%x)\n", brdtype
,
2620 devp
->bus
->number
, devp
->devfn
);
2623 if (pci_enable_device(devp
))
2625 if ((brdp
= stl_allocbrd()) == (stlbrd_t
*) NULL
)
2627 if ((brdp
->brdnr
= stl_getbrdnr()) < 0) {
2628 printk("STALLION: too many boards found, "
2629 "maximum supported %d\n", STL_MAXBRDS
);
2632 brdp
->brdtype
= brdtype
;
2635 * Different Stallion boards use the BAR registers in different ways,
2636 * so set up io addresses based on board type.
2639 printk("%s(%d): BAR[]=%x,%x,%x,%x IRQ=%x\n", __FILE__
, __LINE__
,
2640 pci_resource_start(devp
, 0), pci_resource_start(devp
, 1),
2641 pci_resource_start(devp
, 2), pci_resource_start(devp
, 3), devp
->irq
);
2645 * We have all resources from the board, so let's setup the actual
2646 * board structure now.
2650 brdp
->ioaddr2
= pci_resource_start(devp
, 0);
2651 brdp
->ioaddr1
= pci_resource_start(devp
, 1);
2654 brdp
->ioaddr2
= pci_resource_start(devp
, 2);
2655 brdp
->ioaddr1
= pci_resource_start(devp
, 1);
2658 brdp
->ioaddr1
= pci_resource_start(devp
, 2);
2659 brdp
->ioaddr2
= pci_resource_start(devp
, 1);
2662 printk("STALLION: unknown PCI board type=%d\n", brdtype
);
2666 brdp
->irq
= devp
->irq
;
2672 /*****************************************************************************/
2675 * Find all Stallion PCI boards that might be installed. Initialize each
2676 * one as it is found.
2680 static inline int stl_findpcibrds(void)
2682 struct pci_dev
*dev
= NULL
;
2686 printk("stl_findpcibrds()\n");
2689 for (i
= 0; (i
< stl_nrpcibrds
); i
++)
2690 while ((dev
= pci_find_device(stl_pcibrds
[i
].vendid
,
2691 stl_pcibrds
[i
].devid
, dev
))) {
2694 * Found a device on the PCI bus that has our vendor and
2695 * device ID. Need to check now that it is really us.
2697 if ((dev
->class >> 8) == PCI_CLASS_STORAGE_IDE
)
2700 rc
= stl_initpcibrd(stl_pcibrds
[i
].brdtype
, dev
);
2710 /*****************************************************************************/
2713 * Scan through all the boards in the configuration and see what we
2714 * can find. Handle EIO and the ECH boards a little differently here
2715 * since the initial search and setup is too different.
2718 static inline int stl_initbrds(void)
2725 printk("stl_initbrds()\n");
2728 if (stl_nrbrds
> STL_MAXBRDS
) {
2729 printk("STALLION: too many boards in configuration table, "
2730 "truncating to %d\n", STL_MAXBRDS
);
2731 stl_nrbrds
= STL_MAXBRDS
;
2735 * Firstly scan the list of static boards configured. Allocate
2736 * resources and initialize the boards as found.
2738 for (i
= 0; (i
< stl_nrbrds
); i
++) {
2739 confp
= &stl_brdconf
[i
];
2740 stl_parsebrd(confp
, stl_brdsp
[i
]);
2741 if ((brdp
= stl_allocbrd()) == (stlbrd_t
*) NULL
)
2744 brdp
->brdtype
= confp
->brdtype
;
2745 brdp
->ioaddr1
= confp
->ioaddr1
;
2746 brdp
->ioaddr2
= confp
->ioaddr2
;
2747 brdp
->irq
= confp
->irq
;
2748 brdp
->irqtype
= confp
->irqtype
;
2753 * Find any dynamically supported boards. That is via module load
2754 * line options or auto-detected on the PCI bus.
2764 /*****************************************************************************/
2767 * Return the board stats structure to user app.
2770 static int stl_getbrdstats(combrd_t __user
*bp
)
2776 if (copy_from_user(&stl_brdstats
, bp
, sizeof(combrd_t
)))
2778 if (stl_brdstats
.brd
>= STL_MAXBRDS
)
2780 brdp
= stl_brds
[stl_brdstats
.brd
];
2781 if (brdp
== (stlbrd_t
*) NULL
)
2784 memset(&stl_brdstats
, 0, sizeof(combrd_t
));
2785 stl_brdstats
.brd
= brdp
->brdnr
;
2786 stl_brdstats
.type
= brdp
->brdtype
;
2787 stl_brdstats
.hwid
= brdp
->hwid
;
2788 stl_brdstats
.state
= brdp
->state
;
2789 stl_brdstats
.ioaddr
= brdp
->ioaddr1
;
2790 stl_brdstats
.ioaddr2
= brdp
->ioaddr2
;
2791 stl_brdstats
.irq
= brdp
->irq
;
2792 stl_brdstats
.nrpanels
= brdp
->nrpanels
;
2793 stl_brdstats
.nrports
= brdp
->nrports
;
2794 for (i
= 0; (i
< brdp
->nrpanels
); i
++) {
2795 panelp
= brdp
->panels
[i
];
2796 stl_brdstats
.panels
[i
].panel
= i
;
2797 stl_brdstats
.panels
[i
].hwid
= panelp
->hwid
;
2798 stl_brdstats
.panels
[i
].nrports
= panelp
->nrports
;
2801 return copy_to_user(bp
, &stl_brdstats
, sizeof(combrd_t
)) ? -EFAULT
: 0;
2804 /*****************************************************************************/
2807 * Resolve the referenced port number into a port struct pointer.
2810 static stlport_t
*stl_getport(int brdnr
, int panelnr
, int portnr
)
2815 if ((brdnr
< 0) || (brdnr
>= STL_MAXBRDS
))
2816 return((stlport_t
*) NULL
);
2817 brdp
= stl_brds
[brdnr
];
2818 if (brdp
== (stlbrd_t
*) NULL
)
2819 return((stlport_t
*) NULL
);
2820 if ((panelnr
< 0) || (panelnr
>= brdp
->nrpanels
))
2821 return((stlport_t
*) NULL
);
2822 panelp
= brdp
->panels
[panelnr
];
2823 if (panelp
== (stlpanel_t
*) NULL
)
2824 return((stlport_t
*) NULL
);
2825 if ((portnr
< 0) || (portnr
>= panelp
->nrports
))
2826 return((stlport_t
*) NULL
);
2827 return(panelp
->ports
[portnr
]);
2830 /*****************************************************************************/
2833 * Return the port stats structure to user app. A NULL port struct
2834 * pointer passed in means that we need to find out from the app
2835 * what port to get stats for (used through board control device).
2838 static int stl_getportstats(stlport_t
*portp
, comstats_t __user
*cp
)
2840 unsigned char *head
, *tail
;
2841 unsigned long flags
;
2844 if (copy_from_user(&stl_comstats
, cp
, sizeof(comstats_t
)))
2846 portp
= stl_getport(stl_comstats
.brd
, stl_comstats
.panel
,
2848 if (portp
== (stlport_t
*) NULL
)
2852 portp
->stats
.state
= portp
->istate
;
2853 portp
->stats
.flags
= portp
->flags
;
2854 portp
->stats
.hwid
= portp
->hwid
;
2856 portp
->stats
.ttystate
= 0;
2857 portp
->stats
.cflags
= 0;
2858 portp
->stats
.iflags
= 0;
2859 portp
->stats
.oflags
= 0;
2860 portp
->stats
.lflags
= 0;
2861 portp
->stats
.rxbuffered
= 0;
2863 spin_lock_irqsave(&stallion_lock
, flags
);
2864 if (portp
->tty
!= (struct tty_struct
*) NULL
) {
2865 if (portp
->tty
->driver_data
== portp
) {
2866 portp
->stats
.ttystate
= portp
->tty
->flags
;
2867 /* No longer available as a statistic */
2868 portp
->stats
.rxbuffered
= 1; /*portp->tty->flip.count; */
2869 if (portp
->tty
->termios
!= (struct termios
*) NULL
) {
2870 portp
->stats
.cflags
= portp
->tty
->termios
->c_cflag
;
2871 portp
->stats
.iflags
= portp
->tty
->termios
->c_iflag
;
2872 portp
->stats
.oflags
= portp
->tty
->termios
->c_oflag
;
2873 portp
->stats
.lflags
= portp
->tty
->termios
->c_lflag
;
2877 spin_unlock_irqrestore(&stallion_lock
, flags
);
2879 head
= portp
->tx
.head
;
2880 tail
= portp
->tx
.tail
;
2881 portp
->stats
.txbuffered
= ((head
>= tail
) ? (head
- tail
) :
2882 (STL_TXBUFSIZE
- (tail
- head
)));
2884 portp
->stats
.signals
= (unsigned long) stl_getsignals(portp
);
2886 return copy_to_user(cp
, &portp
->stats
,
2887 sizeof(comstats_t
)) ? -EFAULT
: 0;
2890 /*****************************************************************************/
2893 * Clear the port stats structure. We also return it zeroed out...
2896 static int stl_clrportstats(stlport_t
*portp
, comstats_t __user
*cp
)
2899 if (copy_from_user(&stl_comstats
, cp
, sizeof(comstats_t
)))
2901 portp
= stl_getport(stl_comstats
.brd
, stl_comstats
.panel
,
2903 if (portp
== (stlport_t
*) NULL
)
2907 memset(&portp
->stats
, 0, sizeof(comstats_t
));
2908 portp
->stats
.brd
= portp
->brdnr
;
2909 portp
->stats
.panel
= portp
->panelnr
;
2910 portp
->stats
.port
= portp
->portnr
;
2911 return copy_to_user(cp
, &portp
->stats
,
2912 sizeof(comstats_t
)) ? -EFAULT
: 0;
2915 /*****************************************************************************/
2918 * Return the entire driver ports structure to a user app.
2921 static int stl_getportstruct(stlport_t __user
*arg
)
2925 if (copy_from_user(&stl_dummyport
, arg
, sizeof(stlport_t
)))
2927 portp
= stl_getport(stl_dummyport
.brdnr
, stl_dummyport
.panelnr
,
2928 stl_dummyport
.portnr
);
2931 return copy_to_user(arg
, portp
, sizeof(stlport_t
)) ? -EFAULT
: 0;
2934 /*****************************************************************************/
2937 * Return the entire driver board structure to a user app.
2940 static int stl_getbrdstruct(stlbrd_t __user
*arg
)
2944 if (copy_from_user(&stl_dummybrd
, arg
, sizeof(stlbrd_t
)))
2946 if ((stl_dummybrd
.brdnr
< 0) || (stl_dummybrd
.brdnr
>= STL_MAXBRDS
))
2948 brdp
= stl_brds
[stl_dummybrd
.brdnr
];
2951 return copy_to_user(arg
, brdp
, sizeof(stlbrd_t
)) ? -EFAULT
: 0;
2954 /*****************************************************************************/
2957 * The "staliomem" device is also required to do some special operations
2958 * on the board and/or ports. In this driver it is mostly used for stats
2962 static int stl_memioctl(struct inode
*ip
, struct file
*fp
, unsigned int cmd
, unsigned long arg
)
2965 void __user
*argp
= (void __user
*)arg
;
2968 printk("stl_memioctl(ip=%x,fp=%x,cmd=%x,arg=%x)\n", (int) ip
,
2969 (int) fp
, cmd
, (int) arg
);
2973 if (brdnr
>= STL_MAXBRDS
)
2978 case COM_GETPORTSTATS
:
2979 rc
= stl_getportstats(NULL
, argp
);
2981 case COM_CLRPORTSTATS
:
2982 rc
= stl_clrportstats(NULL
, argp
);
2984 case COM_GETBRDSTATS
:
2985 rc
= stl_getbrdstats(argp
);
2988 rc
= stl_getportstruct(argp
);
2991 rc
= stl_getbrdstruct(argp
);
3001 static struct tty_operations stl_ops
= {
3005 .put_char
= stl_putchar
,
3006 .flush_chars
= stl_flushchars
,
3007 .write_room
= stl_writeroom
,
3008 .chars_in_buffer
= stl_charsinbuffer
,
3010 .set_termios
= stl_settermios
,
3011 .throttle
= stl_throttle
,
3012 .unthrottle
= stl_unthrottle
,
3015 .hangup
= stl_hangup
,
3016 .flush_buffer
= stl_flushbuffer
,
3017 .break_ctl
= stl_breakctl
,
3018 .wait_until_sent
= stl_waituntilsent
,
3019 .send_xchar
= stl_sendxchar
,
3020 .read_proc
= stl_readproc
,
3021 .tiocmget
= stl_tiocmget
,
3022 .tiocmset
= stl_tiocmset
,
3025 /*****************************************************************************/
3027 static int __init
stl_init(void)
3030 printk(KERN_INFO
"%s: version %s\n", stl_drvtitle
, stl_drvversion
);
3034 stl_serial
= alloc_tty_driver(STL_MAXBRDS
* STL_MAXPORTS
);
3039 * Set up a character driver for per board stuff. This is mainly used
3040 * to do stats ioctls on the ports.
3042 if (register_chrdev(STL_SIOMEMMAJOR
, "staliomem", &stl_fsiomem
))
3043 printk("STALLION: failed to register serial board device\n");
3044 devfs_mk_dir("staliomem");
3046 stallion_class
= class_create(THIS_MODULE
, "staliomem");
3047 for (i
= 0; i
< 4; i
++) {
3048 devfs_mk_cdev(MKDEV(STL_SIOMEMMAJOR
, i
),
3049 S_IFCHR
|S_IRUSR
|S_IWUSR
,
3051 class_device_create(stallion_class
, NULL
,
3052 MKDEV(STL_SIOMEMMAJOR
, i
), NULL
,
3056 stl_serial
->owner
= THIS_MODULE
;
3057 stl_serial
->driver_name
= stl_drvname
;
3058 stl_serial
->name
= "ttyE";
3059 stl_serial
->devfs_name
= "tts/E";
3060 stl_serial
->major
= STL_SERIALMAJOR
;
3061 stl_serial
->minor_start
= 0;
3062 stl_serial
->type
= TTY_DRIVER_TYPE_SERIAL
;
3063 stl_serial
->subtype
= SERIAL_TYPE_NORMAL
;
3064 stl_serial
->init_termios
= stl_deftermios
;
3065 stl_serial
->flags
= TTY_DRIVER_REAL_RAW
;
3066 tty_set_operations(stl_serial
, &stl_ops
);
3068 if (tty_register_driver(stl_serial
)) {
3069 put_tty_driver(stl_serial
);
3070 printk("STALLION: failed to register serial driver\n");
3077 /*****************************************************************************/
3078 /* CD1400 HARDWARE FUNCTIONS */
3079 /*****************************************************************************/
3082 * These functions get/set/update the registers of the cd1400 UARTs.
3083 * Access to the cd1400 registers is via an address/data io port pair.
3084 * (Maybe should make this inline...)
3087 static int stl_cd1400getreg(stlport_t
*portp
, int regnr
)
3089 outb((regnr
+ portp
->uartaddr
), portp
->ioaddr
);
3090 return inb(portp
->ioaddr
+ EREG_DATA
);
3093 static void stl_cd1400setreg(stlport_t
*portp
, int regnr
, int value
)
3095 outb((regnr
+ portp
->uartaddr
), portp
->ioaddr
);
3096 outb(value
, portp
->ioaddr
+ EREG_DATA
);
3099 static int stl_cd1400updatereg(stlport_t
*portp
, int regnr
, int value
)
3101 outb((regnr
+ portp
->uartaddr
), portp
->ioaddr
);
3102 if (inb(portp
->ioaddr
+ EREG_DATA
) != value
) {
3103 outb(value
, portp
->ioaddr
+ EREG_DATA
);
3109 /*****************************************************************************/
3112 * Inbitialize the UARTs in a panel. We don't care what sort of board
3113 * these ports are on - since the port io registers are almost
3114 * identical when dealing with ports.
3117 static int stl_cd1400panelinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
)
3121 int nrchips
, uartaddr
, ioaddr
;
3122 unsigned long flags
;
3125 printk("stl_panelinit(brdp=%x,panelp=%x)\n", (int) brdp
, (int) panelp
);
3128 spin_lock_irqsave(&brd_lock
, flags
);
3129 BRDENABLE(panelp
->brdnr
, panelp
->pagenr
);
3132 * Check that each chip is present and started up OK.
3135 nrchips
= panelp
->nrports
/ CD1400_PORTS
;
3136 for (i
= 0; (i
< nrchips
); i
++) {
3137 if (brdp
->brdtype
== BRD_ECHPCI
) {
3138 outb((panelp
->pagenr
+ (i
>> 1)), brdp
->ioctrl
);
3139 ioaddr
= panelp
->iobase
;
3141 ioaddr
= panelp
->iobase
+ (EREG_BANKSIZE
* (i
>> 1));
3143 uartaddr
= (i
& 0x01) ? 0x080 : 0;
3144 outb((GFRCR
+ uartaddr
), ioaddr
);
3145 outb(0, (ioaddr
+ EREG_DATA
));
3146 outb((CCR
+ uartaddr
), ioaddr
);
3147 outb(CCR_RESETFULL
, (ioaddr
+ EREG_DATA
));
3148 outb(CCR_RESETFULL
, (ioaddr
+ EREG_DATA
));
3149 outb((GFRCR
+ uartaddr
), ioaddr
);
3150 for (j
= 0; (j
< CCR_MAXWAIT
); j
++) {
3151 if ((gfrcr
= inb(ioaddr
+ EREG_DATA
)) != 0)
3154 if ((j
>= CCR_MAXWAIT
) || (gfrcr
< 0x40) || (gfrcr
> 0x60)) {
3155 printk("STALLION: cd1400 not responding, "
3156 "brd=%d panel=%d chip=%d\n",
3157 panelp
->brdnr
, panelp
->panelnr
, i
);
3160 chipmask
|= (0x1 << i
);
3161 outb((PPR
+ uartaddr
), ioaddr
);
3162 outb(PPR_SCALAR
, (ioaddr
+ EREG_DATA
));
3165 BRDDISABLE(panelp
->brdnr
);
3166 spin_unlock_irqrestore(&brd_lock
, flags
);
3170 /*****************************************************************************/
3173 * Initialize hardware specific port registers.
3176 static void stl_cd1400portinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
)
3178 unsigned long flags
;
3180 printk("stl_cd1400portinit(brdp=%x,panelp=%x,portp=%x)\n",
3181 (int) brdp
, (int) panelp
, (int) portp
);
3184 if ((brdp
== (stlbrd_t
*) NULL
) || (panelp
== (stlpanel_t
*) NULL
) ||
3185 (portp
== (stlport_t
*) NULL
))
3188 spin_lock_irqsave(&brd_lock
, flags
);
3189 portp
->ioaddr
= panelp
->iobase
+ (((brdp
->brdtype
== BRD_ECHPCI
) ||
3190 (portp
->portnr
< 8)) ? 0 : EREG_BANKSIZE
);
3191 portp
->uartaddr
= (portp
->portnr
& 0x04) << 5;
3192 portp
->pagenr
= panelp
->pagenr
+ (portp
->portnr
>> 3);
3194 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3195 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3196 stl_cd1400setreg(portp
, LIVR
, (portp
->portnr
<< 3));
3197 portp
->hwid
= stl_cd1400getreg(portp
, GFRCR
);
3198 BRDDISABLE(portp
->brdnr
);
3199 spin_unlock_irqrestore(&brd_lock
, flags
);
3202 /*****************************************************************************/
3205 * Wait for the command register to be ready. We will poll this,
3206 * since it won't usually take too long to be ready.
3209 static void stl_cd1400ccrwait(stlport_t
*portp
)
3213 for (i
= 0; (i
< CCR_MAXWAIT
); i
++) {
3214 if (stl_cd1400getreg(portp
, CCR
) == 0) {
3219 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
3220 portp
->portnr
, portp
->panelnr
, portp
->brdnr
);
3223 /*****************************************************************************/
3226 * Set up the cd1400 registers for a port based on the termios port
3230 static void stl_cd1400setport(stlport_t
*portp
, struct termios
*tiosp
)
3233 unsigned long flags
;
3234 unsigned int clkdiv
, baudrate
;
3235 unsigned char cor1
, cor2
, cor3
;
3236 unsigned char cor4
, cor5
, ccr
;
3237 unsigned char srer
, sreron
, sreroff
;
3238 unsigned char mcor1
, mcor2
, rtpr
;
3239 unsigned char clk
, div
;
3255 brdp
= stl_brds
[portp
->brdnr
];
3256 if (brdp
== (stlbrd_t
*) NULL
)
3260 * Set up the RX char ignore mask with those RX error types we
3261 * can ignore. We can get the cd1400 to help us out a little here,
3262 * it will ignore parity errors and breaks for us.
3264 portp
->rxignoremsk
= 0;
3265 if (tiosp
->c_iflag
& IGNPAR
) {
3266 portp
->rxignoremsk
|= (ST_PARITY
| ST_FRAMING
| ST_OVERRUN
);
3267 cor1
|= COR1_PARIGNORE
;
3269 if (tiosp
->c_iflag
& IGNBRK
) {
3270 portp
->rxignoremsk
|= ST_BREAK
;
3271 cor4
|= COR4_IGNBRK
;
3274 portp
->rxmarkmsk
= ST_OVERRUN
;
3275 if (tiosp
->c_iflag
& (INPCK
| PARMRK
))
3276 portp
->rxmarkmsk
|= (ST_PARITY
| ST_FRAMING
);
3277 if (tiosp
->c_iflag
& BRKINT
)
3278 portp
->rxmarkmsk
|= ST_BREAK
;
3281 * Go through the char size, parity and stop bits and set all the
3282 * option register appropriately.
3284 switch (tiosp
->c_cflag
& CSIZE
) {
3299 if (tiosp
->c_cflag
& CSTOPB
)
3304 if (tiosp
->c_cflag
& PARENB
) {
3305 if (tiosp
->c_cflag
& PARODD
)
3306 cor1
|= (COR1_PARENB
| COR1_PARODD
);
3308 cor1
|= (COR1_PARENB
| COR1_PAREVEN
);
3310 cor1
|= COR1_PARNONE
;
3314 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
3315 * space for hardware flow control and the like. This should be set to
3316 * VMIN. Also here we will set the RX data timeout to 10ms - this should
3317 * really be based on VTIME.
3319 cor3
|= FIFO_RXTHRESHOLD
;
3323 * Calculate the baud rate timers. For now we will just assume that
3324 * the input and output baud are the same. Could have used a baud
3325 * table here, but this way we can generate virtually any baud rate
3328 baudrate
= tiosp
->c_cflag
& CBAUD
;
3329 if (baudrate
& CBAUDEX
) {
3330 baudrate
&= ~CBAUDEX
;
3331 if ((baudrate
< 1) || (baudrate
> 4))
3332 tiosp
->c_cflag
&= ~CBAUDEX
;
3336 baudrate
= stl_baudrates
[baudrate
];
3337 if ((tiosp
->c_cflag
& CBAUD
) == B38400
) {
3338 if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
3340 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
3342 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
3344 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
3346 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)
3347 baudrate
= (portp
->baud_base
/ portp
->custom_divisor
);
3349 if (baudrate
> STL_CD1400MAXBAUD
)
3350 baudrate
= STL_CD1400MAXBAUD
;
3353 for (clk
= 0; (clk
< CD1400_NUMCLKS
); clk
++) {
3354 clkdiv
= ((portp
->clk
/ stl_cd1400clkdivs
[clk
]) / baudrate
);
3358 div
= (unsigned char) clkdiv
;
3362 * Check what form of modem signaling is required and set it up.
3364 if ((tiosp
->c_cflag
& CLOCAL
) == 0) {
3367 sreron
|= SRER_MODEM
;
3368 portp
->flags
|= ASYNC_CHECK_CD
;
3370 portp
->flags
&= ~ASYNC_CHECK_CD
;
3374 * Setup cd1400 enhanced modes if we can. In particular we want to
3375 * handle as much of the flow control as possible automatically. As
3376 * well as saving a few CPU cycles it will also greatly improve flow
3377 * control reliability.
3379 if (tiosp
->c_iflag
& IXON
) {
3382 if (tiosp
->c_iflag
& IXANY
)
3386 if (tiosp
->c_cflag
& CRTSCTS
) {
3388 mcor1
|= FIFO_RTSTHRESHOLD
;
3392 * All cd1400 register values calculated so go through and set
3397 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3398 portp
->portnr
, portp
->panelnr
, portp
->brdnr
);
3399 printk(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
3400 cor1
, cor2
, cor3
, cor4
, cor5
);
3401 printk(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
3402 mcor1
, mcor2
, rtpr
, sreron
, sreroff
);
3403 printk(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk
, div
, clk
, div
);
3404 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3405 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
],
3406 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
]);
3409 spin_lock_irqsave(&brd_lock
, flags
);
3410 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3411 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x3));
3412 srer
= stl_cd1400getreg(portp
, SRER
);
3413 stl_cd1400setreg(portp
, SRER
, 0);
3414 if (stl_cd1400updatereg(portp
, COR1
, cor1
))
3416 if (stl_cd1400updatereg(portp
, COR2
, cor2
))
3418 if (stl_cd1400updatereg(portp
, COR3
, cor3
))
3421 stl_cd1400ccrwait(portp
);
3422 stl_cd1400setreg(portp
, CCR
, CCR_CORCHANGE
);
3424 stl_cd1400setreg(portp
, COR4
, cor4
);
3425 stl_cd1400setreg(portp
, COR5
, cor5
);
3426 stl_cd1400setreg(portp
, MCOR1
, mcor1
);
3427 stl_cd1400setreg(portp
, MCOR2
, mcor2
);
3429 stl_cd1400setreg(portp
, TCOR
, clk
);
3430 stl_cd1400setreg(portp
, TBPR
, div
);
3431 stl_cd1400setreg(portp
, RCOR
, clk
);
3432 stl_cd1400setreg(portp
, RBPR
, div
);
3434 stl_cd1400setreg(portp
, SCHR1
, tiosp
->c_cc
[VSTART
]);
3435 stl_cd1400setreg(portp
, SCHR2
, tiosp
->c_cc
[VSTOP
]);
3436 stl_cd1400setreg(portp
, SCHR3
, tiosp
->c_cc
[VSTART
]);
3437 stl_cd1400setreg(portp
, SCHR4
, tiosp
->c_cc
[VSTOP
]);
3438 stl_cd1400setreg(portp
, RTPR
, rtpr
);
3439 mcor1
= stl_cd1400getreg(portp
, MSVR1
);
3440 if (mcor1
& MSVR1_DCD
)
3441 portp
->sigs
|= TIOCM_CD
;
3443 portp
->sigs
&= ~TIOCM_CD
;
3444 stl_cd1400setreg(portp
, SRER
, ((srer
& ~sreroff
) | sreron
));
3445 BRDDISABLE(portp
->brdnr
);
3446 spin_unlock_irqrestore(&brd_lock
, flags
);
3449 /*****************************************************************************/
3452 * Set the state of the DTR and RTS signals.
3455 static void stl_cd1400setsignals(stlport_t
*portp
, int dtr
, int rts
)
3457 unsigned char msvr1
, msvr2
;
3458 unsigned long flags
;
3461 printk("stl_cd1400setsignals(portp=%x,dtr=%d,rts=%d)\n",
3462 (int) portp
, dtr
, rts
);
3472 spin_lock_irqsave(&brd_lock
, flags
);
3473 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3474 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3476 stl_cd1400setreg(portp
, MSVR2
, msvr2
);
3478 stl_cd1400setreg(portp
, MSVR1
, msvr1
);
3479 BRDDISABLE(portp
->brdnr
);
3480 spin_unlock_irqrestore(&brd_lock
, flags
);
3483 /*****************************************************************************/
3486 * Return the state of the signals.
3489 static int stl_cd1400getsignals(stlport_t
*portp
)
3491 unsigned char msvr1
, msvr2
;
3492 unsigned long flags
;
3496 printk("stl_cd1400getsignals(portp=%x)\n", (int) portp
);
3499 spin_lock_irqsave(&brd_lock
, flags
);
3500 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3501 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3502 msvr1
= stl_cd1400getreg(portp
, MSVR1
);
3503 msvr2
= stl_cd1400getreg(portp
, MSVR2
);
3504 BRDDISABLE(portp
->brdnr
);
3505 spin_unlock_irqrestore(&brd_lock
, flags
);
3508 sigs
|= (msvr1
& MSVR1_DCD
) ? TIOCM_CD
: 0;
3509 sigs
|= (msvr1
& MSVR1_CTS
) ? TIOCM_CTS
: 0;
3510 sigs
|= (msvr1
& MSVR1_DTR
) ? TIOCM_DTR
: 0;
3511 sigs
|= (msvr2
& MSVR2_RTS
) ? TIOCM_RTS
: 0;
3513 sigs
|= (msvr1
& MSVR1_RI
) ? TIOCM_RI
: 0;
3514 sigs
|= (msvr1
& MSVR1_DSR
) ? TIOCM_DSR
: 0;
3521 /*****************************************************************************/
3524 * Enable/Disable the Transmitter and/or Receiver.
3527 static void stl_cd1400enablerxtx(stlport_t
*portp
, int rx
, int tx
)
3530 unsigned long flags
;
3533 printk("stl_cd1400enablerxtx(portp=%x,rx=%d,tx=%d)\n",
3534 (int) portp
, rx
, tx
);
3539 ccr
|= CCR_TXDISABLE
;
3541 ccr
|= CCR_TXENABLE
;
3543 ccr
|= CCR_RXDISABLE
;
3545 ccr
|= CCR_RXENABLE
;
3547 spin_lock_irqsave(&brd_lock
, flags
);
3548 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3549 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3550 stl_cd1400ccrwait(portp
);
3551 stl_cd1400setreg(portp
, CCR
, ccr
);
3552 stl_cd1400ccrwait(portp
);
3553 BRDDISABLE(portp
->brdnr
);
3554 spin_unlock_irqrestore(&brd_lock
, flags
);
3557 /*****************************************************************************/
3560 * Start/stop the Transmitter and/or Receiver.
3563 static void stl_cd1400startrxtx(stlport_t
*portp
, int rx
, int tx
)
3565 unsigned char sreron
, sreroff
;
3566 unsigned long flags
;
3569 printk("stl_cd1400startrxtx(portp=%x,rx=%d,tx=%d)\n",
3570 (int) portp
, rx
, tx
);
3576 sreroff
|= (SRER_TXDATA
| SRER_TXEMPTY
);
3578 sreron
|= SRER_TXDATA
;
3580 sreron
|= SRER_TXEMPTY
;
3582 sreroff
|= SRER_RXDATA
;
3584 sreron
|= SRER_RXDATA
;
3586 spin_lock_irqsave(&brd_lock
, flags
);
3587 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3588 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3589 stl_cd1400setreg(portp
, SRER
,
3590 ((stl_cd1400getreg(portp
, SRER
) & ~sreroff
) | sreron
));
3591 BRDDISABLE(portp
->brdnr
);
3593 set_bit(ASYI_TXBUSY
, &portp
->istate
);
3594 spin_unlock_irqrestore(&brd_lock
, flags
);
3597 /*****************************************************************************/
3600 * Disable all interrupts from this port.
3603 static void stl_cd1400disableintrs(stlport_t
*portp
)
3605 unsigned long flags
;
3608 printk("stl_cd1400disableintrs(portp=%x)\n", (int) portp
);
3610 spin_lock_irqsave(&brd_lock
, flags
);
3611 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3612 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3613 stl_cd1400setreg(portp
, SRER
, 0);
3614 BRDDISABLE(portp
->brdnr
);
3615 spin_unlock_irqrestore(&brd_lock
, flags
);
3618 /*****************************************************************************/
3620 static void stl_cd1400sendbreak(stlport_t
*portp
, int len
)
3622 unsigned long flags
;
3625 printk("stl_cd1400sendbreak(portp=%x,len=%d)\n", (int) portp
, len
);
3628 spin_lock_irqsave(&brd_lock
, flags
);
3629 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3630 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3631 stl_cd1400setreg(portp
, SRER
,
3632 ((stl_cd1400getreg(portp
, SRER
) & ~SRER_TXDATA
) |
3634 BRDDISABLE(portp
->brdnr
);
3635 portp
->brklen
= len
;
3637 portp
->stats
.txbreaks
++;
3638 spin_unlock_irqrestore(&brd_lock
, flags
);
3641 /*****************************************************************************/
3644 * Take flow control actions...
3647 static void stl_cd1400flowctrl(stlport_t
*portp
, int state
)
3649 struct tty_struct
*tty
;
3650 unsigned long flags
;
3653 printk("stl_cd1400flowctrl(portp=%x,state=%x)\n", (int) portp
, state
);
3656 if (portp
== (stlport_t
*) NULL
)
3659 if (tty
== (struct tty_struct
*) NULL
)
3662 spin_lock_irqsave(&brd_lock
, flags
);
3663 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3664 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3667 if (tty
->termios
->c_iflag
& IXOFF
) {
3668 stl_cd1400ccrwait(portp
);
3669 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR1
);
3670 portp
->stats
.rxxon
++;
3671 stl_cd1400ccrwait(portp
);
3674 * Question: should we return RTS to what it was before? It may
3675 * have been set by an ioctl... Suppose not, since if you have
3676 * hardware flow control set then it is pretty silly to go and
3677 * set the RTS line by hand.
3679 if (tty
->termios
->c_cflag
& CRTSCTS
) {
3680 stl_cd1400setreg(portp
, MCOR1
,
3681 (stl_cd1400getreg(portp
, MCOR1
) |
3682 FIFO_RTSTHRESHOLD
));
3683 stl_cd1400setreg(portp
, MSVR2
, MSVR2_RTS
);
3684 portp
->stats
.rxrtson
++;
3687 if (tty
->termios
->c_iflag
& IXOFF
) {
3688 stl_cd1400ccrwait(portp
);
3689 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR2
);
3690 portp
->stats
.rxxoff
++;
3691 stl_cd1400ccrwait(portp
);
3693 if (tty
->termios
->c_cflag
& CRTSCTS
) {
3694 stl_cd1400setreg(portp
, MCOR1
,
3695 (stl_cd1400getreg(portp
, MCOR1
) & 0xf0));
3696 stl_cd1400setreg(portp
, MSVR2
, 0);
3697 portp
->stats
.rxrtsoff
++;
3701 BRDDISABLE(portp
->brdnr
);
3702 spin_unlock_irqrestore(&brd_lock
, flags
);
3705 /*****************************************************************************/
3708 * Send a flow control character...
3711 static void stl_cd1400sendflow(stlport_t
*portp
, int state
)
3713 struct tty_struct
*tty
;
3714 unsigned long flags
;
3717 printk("stl_cd1400sendflow(portp=%x,state=%x)\n", (int) portp
, state
);
3720 if (portp
== (stlport_t
*) NULL
)
3723 if (tty
== (struct tty_struct
*) NULL
)
3726 spin_lock_irqsave(&brd_lock
, flags
);
3727 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3728 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3730 stl_cd1400ccrwait(portp
);
3731 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR1
);
3732 portp
->stats
.rxxon
++;
3733 stl_cd1400ccrwait(portp
);
3735 stl_cd1400ccrwait(portp
);
3736 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR2
);
3737 portp
->stats
.rxxoff
++;
3738 stl_cd1400ccrwait(portp
);
3740 BRDDISABLE(portp
->brdnr
);
3741 spin_unlock_irqrestore(&brd_lock
, flags
);
3744 /*****************************************************************************/
3746 static void stl_cd1400flush(stlport_t
*portp
)
3748 unsigned long flags
;
3751 printk("stl_cd1400flush(portp=%x)\n", (int) portp
);
3754 if (portp
== (stlport_t
*) NULL
)
3757 spin_lock_irqsave(&brd_lock
, flags
);
3758 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3759 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3760 stl_cd1400ccrwait(portp
);
3761 stl_cd1400setreg(portp
, CCR
, CCR_TXFLUSHFIFO
);
3762 stl_cd1400ccrwait(portp
);
3763 portp
->tx
.tail
= portp
->tx
.head
;
3764 BRDDISABLE(portp
->brdnr
);
3765 spin_unlock_irqrestore(&brd_lock
, flags
);
3768 /*****************************************************************************/
3771 * Return the current state of data flow on this port. This is only
3772 * really interresting when determining if data has fully completed
3773 * transmission or not... This is easy for the cd1400, it accurately
3774 * maintains the busy port flag.
3777 static int stl_cd1400datastate(stlport_t
*portp
)
3780 printk("stl_cd1400datastate(portp=%x)\n", (int) portp
);
3783 if (portp
== (stlport_t
*) NULL
)
3786 return test_bit(ASYI_TXBUSY
, &portp
->istate
) ? 1 : 0;
3789 /*****************************************************************************/
3792 * Interrupt service routine for cd1400 EasyIO boards.
3795 static void stl_cd1400eiointr(stlpanel_t
*panelp
, unsigned int iobase
)
3797 unsigned char svrtype
;
3800 printk("stl_cd1400eiointr(panelp=%x,iobase=%x)\n",
3801 (int) panelp
, iobase
);
3804 spin_lock(&brd_lock
);
3806 svrtype
= inb(iobase
+ EREG_DATA
);
3807 if (panelp
->nrports
> 4) {
3808 outb((SVRR
+ 0x80), iobase
);
3809 svrtype
|= inb(iobase
+ EREG_DATA
);
3812 if (svrtype
& SVRR_RX
)
3813 stl_cd1400rxisr(panelp
, iobase
);
3814 else if (svrtype
& SVRR_TX
)
3815 stl_cd1400txisr(panelp
, iobase
);
3816 else if (svrtype
& SVRR_MDM
)
3817 stl_cd1400mdmisr(panelp
, iobase
);
3819 spin_unlock(&brd_lock
);
3822 /*****************************************************************************/
3825 * Interrupt service routine for cd1400 panels.
3828 static void stl_cd1400echintr(stlpanel_t
*panelp
, unsigned int iobase
)
3830 unsigned char svrtype
;
3833 printk("stl_cd1400echintr(panelp=%x,iobase=%x)\n", (int) panelp
,
3838 svrtype
= inb(iobase
+ EREG_DATA
);
3839 outb((SVRR
+ 0x80), iobase
);
3840 svrtype
|= inb(iobase
+ EREG_DATA
);
3841 if (svrtype
& SVRR_RX
)
3842 stl_cd1400rxisr(panelp
, iobase
);
3843 else if (svrtype
& SVRR_TX
)
3844 stl_cd1400txisr(panelp
, iobase
);
3845 else if (svrtype
& SVRR_MDM
)
3846 stl_cd1400mdmisr(panelp
, iobase
);
3850 /*****************************************************************************/
3853 * Unfortunately we need to handle breaks in the TX data stream, since
3854 * this is the only way to generate them on the cd1400.
3857 static inline int stl_cd1400breakisr(stlport_t
*portp
, int ioaddr
)
3859 if (portp
->brklen
== 1) {
3860 outb((COR2
+ portp
->uartaddr
), ioaddr
);
3861 outb((inb(ioaddr
+ EREG_DATA
) | COR2_ETC
),
3862 (ioaddr
+ EREG_DATA
));
3863 outb((TDR
+ portp
->uartaddr
), ioaddr
);
3864 outb(ETC_CMD
, (ioaddr
+ EREG_DATA
));
3865 outb(ETC_STARTBREAK
, (ioaddr
+ EREG_DATA
));
3866 outb((SRER
+ portp
->uartaddr
), ioaddr
);
3867 outb((inb(ioaddr
+ EREG_DATA
) & ~(SRER_TXDATA
| SRER_TXEMPTY
)),
3868 (ioaddr
+ EREG_DATA
));
3870 } else if (portp
->brklen
> 1) {
3871 outb((TDR
+ portp
->uartaddr
), ioaddr
);
3872 outb(ETC_CMD
, (ioaddr
+ EREG_DATA
));
3873 outb(ETC_STOPBREAK
, (ioaddr
+ EREG_DATA
));
3877 outb((COR2
+ portp
->uartaddr
), ioaddr
);
3878 outb((inb(ioaddr
+ EREG_DATA
) & ~COR2_ETC
),
3879 (ioaddr
+ EREG_DATA
));
3885 /*****************************************************************************/
3888 * Transmit interrupt handler. This has gotta be fast! Handling TX
3889 * chars is pretty simple, stuff as many as possible from the TX buffer
3890 * into the cd1400 FIFO. Must also handle TX breaks here, since they
3891 * are embedded as commands in the data stream. Oh no, had to use a goto!
3892 * This could be optimized more, will do when I get time...
3893 * In practice it is possible that interrupts are enabled but that the
3894 * port has been hung up. Need to handle not having any TX buffer here,
3895 * this is done by using the side effect that head and tail will also
3896 * be NULL if the buffer has been freed.
3899 static void stl_cd1400txisr(stlpanel_t
*panelp
, int ioaddr
)
3904 unsigned char ioack
, srer
;
3907 printk("stl_cd1400txisr(panelp=%x,ioaddr=%x)\n", (int) panelp
, ioaddr
);
3910 ioack
= inb(ioaddr
+ EREG_TXACK
);
3911 if (((ioack
& panelp
->ackmask
) != 0) ||
3912 ((ioack
& ACK_TYPMASK
) != ACK_TYPTX
)) {
3913 printk("STALLION: bad TX interrupt ack value=%x\n", ioack
);
3916 portp
= panelp
->ports
[(ioack
>> 3)];
3919 * Unfortunately we need to handle breaks in the data stream, since
3920 * this is the only way to generate them on the cd1400. Do it now if
3921 * a break is to be sent.
3923 if (portp
->brklen
!= 0)
3924 if (stl_cd1400breakisr(portp
, ioaddr
))
3927 head
= portp
->tx
.head
;
3928 tail
= portp
->tx
.tail
;
3929 len
= (head
>= tail
) ? (head
- tail
) : (STL_TXBUFSIZE
- (tail
- head
));
3930 if ((len
== 0) || ((len
< STL_TXBUFLOW
) &&
3931 (test_bit(ASYI_TXLOW
, &portp
->istate
) == 0))) {
3932 set_bit(ASYI_TXLOW
, &portp
->istate
);
3933 schedule_work(&portp
->tqueue
);
3937 outb((SRER
+ portp
->uartaddr
), ioaddr
);
3938 srer
= inb(ioaddr
+ EREG_DATA
);
3939 if (srer
& SRER_TXDATA
) {
3940 srer
= (srer
& ~SRER_TXDATA
) | SRER_TXEMPTY
;
3942 srer
&= ~(SRER_TXDATA
| SRER_TXEMPTY
);
3943 clear_bit(ASYI_TXBUSY
, &portp
->istate
);
3945 outb(srer
, (ioaddr
+ EREG_DATA
));
3947 len
= MIN(len
, CD1400_TXFIFOSIZE
);
3948 portp
->stats
.txtotal
+= len
;
3949 stlen
= MIN(len
, ((portp
->tx
.buf
+ STL_TXBUFSIZE
) - tail
));
3950 outb((TDR
+ portp
->uartaddr
), ioaddr
);
3951 outsb((ioaddr
+ EREG_DATA
), tail
, stlen
);
3954 if (tail
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
))
3955 tail
= portp
->tx
.buf
;
3957 outsb((ioaddr
+ EREG_DATA
), tail
, len
);
3960 portp
->tx
.tail
= tail
;
3964 outb((EOSRR
+ portp
->uartaddr
), ioaddr
);
3965 outb(0, (ioaddr
+ EREG_DATA
));
3968 /*****************************************************************************/
3971 * Receive character interrupt handler. Determine if we have good chars
3972 * or bad chars and then process appropriately. Good chars are easy
3973 * just shove the lot into the RX buffer and set all status byte to 0.
3974 * If a bad RX char then process as required. This routine needs to be
3975 * fast! In practice it is possible that we get an interrupt on a port
3976 * that is closed. This can happen on hangups - since they completely
3977 * shutdown a port not in user context. Need to handle this case.
3980 static void stl_cd1400rxisr(stlpanel_t
*panelp
, int ioaddr
)
3983 struct tty_struct
*tty
;
3984 unsigned int ioack
, len
, buflen
;
3985 unsigned char status
;
3989 printk("stl_cd1400rxisr(panelp=%x,ioaddr=%x)\n", (int) panelp
, ioaddr
);
3992 ioack
= inb(ioaddr
+ EREG_RXACK
);
3993 if ((ioack
& panelp
->ackmask
) != 0) {
3994 printk("STALLION: bad RX interrupt ack value=%x\n", ioack
);
3997 portp
= panelp
->ports
[(ioack
>> 3)];
4000 if ((ioack
& ACK_TYPMASK
) == ACK_TYPRXGOOD
) {
4001 outb((RDCR
+ portp
->uartaddr
), ioaddr
);
4002 len
= inb(ioaddr
+ EREG_DATA
);
4003 if (tty
== NULL
|| (buflen
= tty_buffer_request_room(tty
, len
)) == 0) {
4004 len
= MIN(len
, sizeof(stl_unwanted
));
4005 outb((RDSR
+ portp
->uartaddr
), ioaddr
);
4006 insb((ioaddr
+ EREG_DATA
), &stl_unwanted
[0], len
);
4007 portp
->stats
.rxlost
+= len
;
4008 portp
->stats
.rxtotal
+= len
;
4010 len
= MIN(len
, buflen
);
4013 outb((RDSR
+ portp
->uartaddr
), ioaddr
);
4014 tty_prepare_flip_string(tty
, &ptr
, len
);
4015 insb((ioaddr
+ EREG_DATA
), ptr
, len
);
4016 tty_schedule_flip(tty
);
4017 portp
->stats
.rxtotal
+= len
;
4020 } else if ((ioack
& ACK_TYPMASK
) == ACK_TYPRXBAD
) {
4021 outb((RDSR
+ portp
->uartaddr
), ioaddr
);
4022 status
= inb(ioaddr
+ EREG_DATA
);
4023 ch
= inb(ioaddr
+ EREG_DATA
);
4024 if (status
& ST_PARITY
)
4025 portp
->stats
.rxparity
++;
4026 if (status
& ST_FRAMING
)
4027 portp
->stats
.rxframing
++;
4028 if (status
& ST_OVERRUN
)
4029 portp
->stats
.rxoverrun
++;
4030 if (status
& ST_BREAK
)
4031 portp
->stats
.rxbreaks
++;
4032 if (status
& ST_SCHARMASK
) {
4033 if ((status
& ST_SCHARMASK
) == ST_SCHAR1
)
4034 portp
->stats
.txxon
++;
4035 if ((status
& ST_SCHARMASK
) == ST_SCHAR2
)
4036 portp
->stats
.txxoff
++;
4039 if (tty
!= NULL
&& (portp
->rxignoremsk
& status
) == 0) {
4040 if (portp
->rxmarkmsk
& status
) {
4041 if (status
& ST_BREAK
) {
4043 if (portp
->flags
& ASYNC_SAK
) {
4045 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4047 } else if (status
& ST_PARITY
) {
4048 status
= TTY_PARITY
;
4049 } else if (status
& ST_FRAMING
) {
4051 } else if(status
& ST_OVERRUN
) {
4052 status
= TTY_OVERRUN
;
4059 tty_insert_flip_char(tty
, ch
, status
);
4060 tty_schedule_flip(tty
);
4063 printk("STALLION: bad RX interrupt ack value=%x\n", ioack
);
4068 outb((EOSRR
+ portp
->uartaddr
), ioaddr
);
4069 outb(0, (ioaddr
+ EREG_DATA
));
4072 /*****************************************************************************/
4075 * Modem interrupt handler. The is called when the modem signal line
4076 * (DCD) has changed state. Leave most of the work to the off-level
4077 * processing routine.
4080 static void stl_cd1400mdmisr(stlpanel_t
*panelp
, int ioaddr
)
4087 printk("stl_cd1400mdmisr(panelp=%x)\n", (int) panelp
);
4090 ioack
= inb(ioaddr
+ EREG_MDACK
);
4091 if (((ioack
& panelp
->ackmask
) != 0) ||
4092 ((ioack
& ACK_TYPMASK
) != ACK_TYPMDM
)) {
4093 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack
);
4096 portp
= panelp
->ports
[(ioack
>> 3)];
4098 outb((MISR
+ portp
->uartaddr
), ioaddr
);
4099 misr
= inb(ioaddr
+ EREG_DATA
);
4100 if (misr
& MISR_DCD
) {
4101 set_bit(ASYI_DCDCHANGE
, &portp
->istate
);
4102 schedule_work(&portp
->tqueue
);
4103 portp
->stats
.modem
++;
4106 outb((EOSRR
+ portp
->uartaddr
), ioaddr
);
4107 outb(0, (ioaddr
+ EREG_DATA
));
4110 /*****************************************************************************/
4111 /* SC26198 HARDWARE FUNCTIONS */
4112 /*****************************************************************************/
4115 * These functions get/set/update the registers of the sc26198 UARTs.
4116 * Access to the sc26198 registers is via an address/data io port pair.
4117 * (Maybe should make this inline...)
4120 static int stl_sc26198getreg(stlport_t
*portp
, int regnr
)
4122 outb((regnr
| portp
->uartaddr
), (portp
->ioaddr
+ XP_ADDR
));
4123 return inb(portp
->ioaddr
+ XP_DATA
);
4126 static void stl_sc26198setreg(stlport_t
*portp
, int regnr
, int value
)
4128 outb((regnr
| portp
->uartaddr
), (portp
->ioaddr
+ XP_ADDR
));
4129 outb(value
, (portp
->ioaddr
+ XP_DATA
));
4132 static int stl_sc26198updatereg(stlport_t
*portp
, int regnr
, int value
)
4134 outb((regnr
| portp
->uartaddr
), (portp
->ioaddr
+ XP_ADDR
));
4135 if (inb(portp
->ioaddr
+ XP_DATA
) != value
) {
4136 outb(value
, (portp
->ioaddr
+ XP_DATA
));
4142 /*****************************************************************************/
4145 * Functions to get and set the sc26198 global registers.
4148 static int stl_sc26198getglobreg(stlport_t
*portp
, int regnr
)
4150 outb(regnr
, (portp
->ioaddr
+ XP_ADDR
));
4151 return inb(portp
->ioaddr
+ XP_DATA
);
4155 static void stl_sc26198setglobreg(stlport_t
*portp
, int regnr
, int value
)
4157 outb(regnr
, (portp
->ioaddr
+ XP_ADDR
));
4158 outb(value
, (portp
->ioaddr
+ XP_DATA
));
4162 /*****************************************************************************/
4165 * Inbitialize the UARTs in a panel. We don't care what sort of board
4166 * these ports are on - since the port io registers are almost
4167 * identical when dealing with ports.
4170 static int stl_sc26198panelinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
)
4173 int nrchips
, ioaddr
;
4176 printk("stl_sc26198panelinit(brdp=%x,panelp=%x)\n",
4177 (int) brdp
, (int) panelp
);
4180 BRDENABLE(panelp
->brdnr
, panelp
->pagenr
);
4183 * Check that each chip is present and started up OK.
4186 nrchips
= (panelp
->nrports
+ 4) / SC26198_PORTS
;
4187 if (brdp
->brdtype
== BRD_ECHPCI
)
4188 outb(panelp
->pagenr
, brdp
->ioctrl
);
4190 for (i
= 0; (i
< nrchips
); i
++) {
4191 ioaddr
= panelp
->iobase
+ (i
* 4);
4192 outb(SCCR
, (ioaddr
+ XP_ADDR
));
4193 outb(CR_RESETALL
, (ioaddr
+ XP_DATA
));
4194 outb(TSTR
, (ioaddr
+ XP_ADDR
));
4195 if (inb(ioaddr
+ XP_DATA
) != 0) {
4196 printk("STALLION: sc26198 not responding, "
4197 "brd=%d panel=%d chip=%d\n",
4198 panelp
->brdnr
, panelp
->panelnr
, i
);
4201 chipmask
|= (0x1 << i
);
4202 outb(GCCR
, (ioaddr
+ XP_ADDR
));
4203 outb(GCCR_IVRTYPCHANACK
, (ioaddr
+ XP_DATA
));
4204 outb(WDTRCR
, (ioaddr
+ XP_ADDR
));
4205 outb(0xff, (ioaddr
+ XP_DATA
));
4208 BRDDISABLE(panelp
->brdnr
);
4212 /*****************************************************************************/
4215 * Initialize hardware specific port registers.
4218 static void stl_sc26198portinit(stlbrd_t
*brdp
, stlpanel_t
*panelp
, stlport_t
*portp
)
4221 printk("stl_sc26198portinit(brdp=%x,panelp=%x,portp=%x)\n",
4222 (int) brdp
, (int) panelp
, (int) portp
);
4225 if ((brdp
== (stlbrd_t
*) NULL
) || (panelp
== (stlpanel_t
*) NULL
) ||
4226 (portp
== (stlport_t
*) NULL
))
4229 portp
->ioaddr
= panelp
->iobase
+ ((portp
->portnr
< 8) ? 0 : 4);
4230 portp
->uartaddr
= (portp
->portnr
& 0x07) << 4;
4231 portp
->pagenr
= panelp
->pagenr
;
4234 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4235 stl_sc26198setreg(portp
, IOPCR
, IOPCR_SETSIGS
);
4236 BRDDISABLE(portp
->brdnr
);
4239 /*****************************************************************************/
4242 * Set up the sc26198 registers for a port based on the termios port
4246 static void stl_sc26198setport(stlport_t
*portp
, struct termios
*tiosp
)
4249 unsigned long flags
;
4250 unsigned int baudrate
;
4251 unsigned char mr0
, mr1
, mr2
, clk
;
4252 unsigned char imron
, imroff
, iopr
, ipr
;
4262 brdp
= stl_brds
[portp
->brdnr
];
4263 if (brdp
== (stlbrd_t
*) NULL
)
4267 * Set up the RX char ignore mask with those RX error types we
4270 portp
->rxignoremsk
= 0;
4271 if (tiosp
->c_iflag
& IGNPAR
)
4272 portp
->rxignoremsk
|= (SR_RXPARITY
| SR_RXFRAMING
|
4274 if (tiosp
->c_iflag
& IGNBRK
)
4275 portp
->rxignoremsk
|= SR_RXBREAK
;
4277 portp
->rxmarkmsk
= SR_RXOVERRUN
;
4278 if (tiosp
->c_iflag
& (INPCK
| PARMRK
))
4279 portp
->rxmarkmsk
|= (SR_RXPARITY
| SR_RXFRAMING
);
4280 if (tiosp
->c_iflag
& BRKINT
)
4281 portp
->rxmarkmsk
|= SR_RXBREAK
;
4284 * Go through the char size, parity and stop bits and set all the
4285 * option register appropriately.
4287 switch (tiosp
->c_cflag
& CSIZE
) {
4302 if (tiosp
->c_cflag
& CSTOPB
)
4307 if (tiosp
->c_cflag
& PARENB
) {
4308 if (tiosp
->c_cflag
& PARODD
)
4309 mr1
|= (MR1_PARENB
| MR1_PARODD
);
4311 mr1
|= (MR1_PARENB
| MR1_PAREVEN
);
4316 mr1
|= MR1_ERRBLOCK
;
4319 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
4320 * space for hardware flow control and the like. This should be set to
4323 mr2
|= MR2_RXFIFOHALF
;
4326 * Calculate the baud rate timers. For now we will just assume that
4327 * the input and output baud are the same. The sc26198 has a fixed
4328 * baud rate table, so only discrete baud rates possible.
4330 baudrate
= tiosp
->c_cflag
& CBAUD
;
4331 if (baudrate
& CBAUDEX
) {
4332 baudrate
&= ~CBAUDEX
;
4333 if ((baudrate
< 1) || (baudrate
> 4))
4334 tiosp
->c_cflag
&= ~CBAUDEX
;
4338 baudrate
= stl_baudrates
[baudrate
];
4339 if ((tiosp
->c_cflag
& CBAUD
) == B38400
) {
4340 if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
4342 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
4344 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
4346 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
4348 else if ((portp
->flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)
4349 baudrate
= (portp
->baud_base
/ portp
->custom_divisor
);
4351 if (baudrate
> STL_SC26198MAXBAUD
)
4352 baudrate
= STL_SC26198MAXBAUD
;
4355 for (clk
= 0; (clk
< SC26198_NRBAUDS
); clk
++) {
4356 if (baudrate
<= sc26198_baudtable
[clk
])
4362 * Check what form of modem signaling is required and set it up.
4364 if (tiosp
->c_cflag
& CLOCAL
) {
4365 portp
->flags
&= ~ASYNC_CHECK_CD
;
4367 iopr
|= IOPR_DCDCOS
;
4369 portp
->flags
|= ASYNC_CHECK_CD
;
4373 * Setup sc26198 enhanced modes if we can. In particular we want to
4374 * handle as much of the flow control as possible automatically. As
4375 * well as saving a few CPU cycles it will also greatly improve flow
4376 * control reliability.
4378 if (tiosp
->c_iflag
& IXON
) {
4379 mr0
|= MR0_SWFTX
| MR0_SWFT
;
4380 imron
|= IR_XONXOFF
;
4382 imroff
|= IR_XONXOFF
;
4384 if (tiosp
->c_iflag
& IXOFF
)
4387 if (tiosp
->c_cflag
& CRTSCTS
) {
4393 * All sc26198 register values calculated so go through and set
4398 printk("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
4399 portp
->portnr
, portp
->panelnr
, portp
->brdnr
);
4400 printk(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0
, mr1
, mr2
, clk
);
4401 printk(" iopr=%x imron=%x imroff=%x\n", iopr
, imron
, imroff
);
4402 printk(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
4403 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
],
4404 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
]);
4407 spin_lock_irqsave(&brd_lock
, flags
);
4408 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4409 stl_sc26198setreg(portp
, IMR
, 0);
4410 stl_sc26198updatereg(portp
, MR0
, mr0
);
4411 stl_sc26198updatereg(portp
, MR1
, mr1
);
4412 stl_sc26198setreg(portp
, SCCR
, CR_RXERRBLOCK
);
4413 stl_sc26198updatereg(portp
, MR2
, mr2
);
4414 stl_sc26198updatereg(portp
, IOPIOR
,
4415 ((stl_sc26198getreg(portp
, IOPIOR
) & ~IPR_CHANGEMASK
) | iopr
));
4418 stl_sc26198setreg(portp
, TXCSR
, clk
);
4419 stl_sc26198setreg(portp
, RXCSR
, clk
);
4422 stl_sc26198setreg(portp
, XONCR
, tiosp
->c_cc
[VSTART
]);
4423 stl_sc26198setreg(portp
, XOFFCR
, tiosp
->c_cc
[VSTOP
]);
4425 ipr
= stl_sc26198getreg(portp
, IPR
);
4427 portp
->sigs
&= ~TIOCM_CD
;
4429 portp
->sigs
|= TIOCM_CD
;
4431 portp
->imr
= (portp
->imr
& ~imroff
) | imron
;
4432 stl_sc26198setreg(portp
, IMR
, portp
->imr
);
4433 BRDDISABLE(portp
->brdnr
);
4434 spin_unlock_irqrestore(&brd_lock
, flags
);
4437 /*****************************************************************************/
4440 * Set the state of the DTR and RTS signals.
4443 static void stl_sc26198setsignals(stlport_t
*portp
, int dtr
, int rts
)
4445 unsigned char iopioron
, iopioroff
;
4446 unsigned long flags
;
4449 printk("stl_sc26198setsignals(portp=%x,dtr=%d,rts=%d)\n",
4450 (int) portp
, dtr
, rts
);
4456 iopioroff
|= IPR_DTR
;
4458 iopioron
|= IPR_DTR
;
4460 iopioroff
|= IPR_RTS
;
4462 iopioron
|= IPR_RTS
;
4464 spin_lock_irqsave(&brd_lock
, flags
);
4465 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4466 stl_sc26198setreg(portp
, IOPIOR
,
4467 ((stl_sc26198getreg(portp
, IOPIOR
) & ~iopioroff
) | iopioron
));
4468 BRDDISABLE(portp
->brdnr
);
4469 spin_unlock_irqrestore(&brd_lock
, flags
);
4472 /*****************************************************************************/
4475 * Return the state of the signals.
4478 static int stl_sc26198getsignals(stlport_t
*portp
)
4481 unsigned long flags
;
4485 printk("stl_sc26198getsignals(portp=%x)\n", (int) portp
);
4488 spin_lock_irqsave(&brd_lock
, flags
);
4489 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4490 ipr
= stl_sc26198getreg(portp
, IPR
);
4491 BRDDISABLE(portp
->brdnr
);
4492 spin_unlock_irqrestore(&brd_lock
, flags
);
4495 sigs
|= (ipr
& IPR_DCD
) ? 0 : TIOCM_CD
;
4496 sigs
|= (ipr
& IPR_CTS
) ? 0 : TIOCM_CTS
;
4497 sigs
|= (ipr
& IPR_DTR
) ? 0: TIOCM_DTR
;
4498 sigs
|= (ipr
& IPR_RTS
) ? 0: TIOCM_RTS
;
4503 /*****************************************************************************/
4506 * Enable/Disable the Transmitter and/or Receiver.
4509 static void stl_sc26198enablerxtx(stlport_t
*portp
, int rx
, int tx
)
4512 unsigned long flags
;
4515 printk("stl_sc26198enablerxtx(portp=%x,rx=%d,tx=%d)\n",
4516 (int) portp
, rx
, tx
);
4519 ccr
= portp
->crenable
;
4521 ccr
&= ~CR_TXENABLE
;
4525 ccr
&= ~CR_RXENABLE
;
4529 spin_lock_irqsave(&brd_lock
, flags
);
4530 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4531 stl_sc26198setreg(portp
, SCCR
, ccr
);
4532 BRDDISABLE(portp
->brdnr
);
4533 portp
->crenable
= ccr
;
4534 spin_unlock_irqrestore(&brd_lock
, flags
);
4537 /*****************************************************************************/
4540 * Start/stop the Transmitter and/or Receiver.
4543 static void stl_sc26198startrxtx(stlport_t
*portp
, int rx
, int tx
)
4546 unsigned long flags
;
4549 printk("stl_sc26198startrxtx(portp=%x,rx=%d,tx=%d)\n",
4550 (int) portp
, rx
, tx
);
4559 imr
&= ~(IR_RXRDY
| IR_RXBREAK
| IR_RXWATCHDOG
);
4561 imr
|= IR_RXRDY
| IR_RXBREAK
| IR_RXWATCHDOG
;
4563 spin_lock_irqsave(&brd_lock
, flags
);
4564 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4565 stl_sc26198setreg(portp
, IMR
, imr
);
4566 BRDDISABLE(portp
->brdnr
);
4569 set_bit(ASYI_TXBUSY
, &portp
->istate
);
4570 spin_unlock_irqrestore(&brd_lock
, flags
);
4573 /*****************************************************************************/
4576 * Disable all interrupts from this port.
4579 static void stl_sc26198disableintrs(stlport_t
*portp
)
4581 unsigned long flags
;
4584 printk("stl_sc26198disableintrs(portp=%x)\n", (int) portp
);
4587 spin_lock_irqsave(&brd_lock
, flags
);
4588 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4590 stl_sc26198setreg(portp
, IMR
, 0);
4591 BRDDISABLE(portp
->brdnr
);
4592 spin_unlock_irqrestore(&brd_lock
, flags
);
4595 /*****************************************************************************/
4597 static void stl_sc26198sendbreak(stlport_t
*portp
, int len
)
4599 unsigned long flags
;
4602 printk("stl_sc26198sendbreak(portp=%x,len=%d)\n", (int) portp
, len
);
4605 spin_lock_irqsave(&brd_lock
, flags
);
4606 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4608 stl_sc26198setreg(portp
, SCCR
, CR_TXSTARTBREAK
);
4609 portp
->stats
.txbreaks
++;
4611 stl_sc26198setreg(portp
, SCCR
, CR_TXSTOPBREAK
);
4613 BRDDISABLE(portp
->brdnr
);
4614 spin_unlock_irqrestore(&brd_lock
, flags
);
4617 /*****************************************************************************/
4620 * Take flow control actions...
4623 static void stl_sc26198flowctrl(stlport_t
*portp
, int state
)
4625 struct tty_struct
*tty
;
4626 unsigned long flags
;
4630 printk("stl_sc26198flowctrl(portp=%x,state=%x)\n", (int) portp
, state
);
4633 if (portp
== (stlport_t
*) NULL
)
4636 if (tty
== (struct tty_struct
*) NULL
)
4639 spin_lock_irqsave(&brd_lock
, flags
);
4640 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4643 if (tty
->termios
->c_iflag
& IXOFF
) {
4644 mr0
= stl_sc26198getreg(portp
, MR0
);
4645 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4646 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXON
);
4648 portp
->stats
.rxxon
++;
4649 stl_sc26198wait(portp
);
4650 stl_sc26198setreg(portp
, MR0
, mr0
);
4653 * Question: should we return RTS to what it was before? It may
4654 * have been set by an ioctl... Suppose not, since if you have
4655 * hardware flow control set then it is pretty silly to go and
4656 * set the RTS line by hand.
4658 if (tty
->termios
->c_cflag
& CRTSCTS
) {
4659 stl_sc26198setreg(portp
, MR1
,
4660 (stl_sc26198getreg(portp
, MR1
) | MR1_AUTORTS
));
4661 stl_sc26198setreg(portp
, IOPIOR
,
4662 (stl_sc26198getreg(portp
, IOPIOR
) | IOPR_RTS
));
4663 portp
->stats
.rxrtson
++;
4666 if (tty
->termios
->c_iflag
& IXOFF
) {
4667 mr0
= stl_sc26198getreg(portp
, MR0
);
4668 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4669 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXOFF
);
4671 portp
->stats
.rxxoff
++;
4672 stl_sc26198wait(portp
);
4673 stl_sc26198setreg(portp
, MR0
, mr0
);
4675 if (tty
->termios
->c_cflag
& CRTSCTS
) {
4676 stl_sc26198setreg(portp
, MR1
,
4677 (stl_sc26198getreg(portp
, MR1
) & ~MR1_AUTORTS
));
4678 stl_sc26198setreg(portp
, IOPIOR
,
4679 (stl_sc26198getreg(portp
, IOPIOR
) & ~IOPR_RTS
));
4680 portp
->stats
.rxrtsoff
++;
4684 BRDDISABLE(portp
->brdnr
);
4685 spin_unlock_irqrestore(&brd_lock
, flags
);
4688 /*****************************************************************************/
4691 * Send a flow control character.
4694 static void stl_sc26198sendflow(stlport_t
*portp
, int state
)
4696 struct tty_struct
*tty
;
4697 unsigned long flags
;
4701 printk("stl_sc26198sendflow(portp=%x,state=%x)\n", (int) portp
, state
);
4704 if (portp
== (stlport_t
*) NULL
)
4707 if (tty
== (struct tty_struct
*) NULL
)
4710 spin_lock_irqsave(&brd_lock
, flags
);
4711 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4713 mr0
= stl_sc26198getreg(portp
, MR0
);
4714 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4715 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXON
);
4717 portp
->stats
.rxxon
++;
4718 stl_sc26198wait(portp
);
4719 stl_sc26198setreg(portp
, MR0
, mr0
);
4721 mr0
= stl_sc26198getreg(portp
, MR0
);
4722 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4723 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXOFF
);
4725 portp
->stats
.rxxoff
++;
4726 stl_sc26198wait(portp
);
4727 stl_sc26198setreg(portp
, MR0
, mr0
);
4729 BRDDISABLE(portp
->brdnr
);
4730 spin_unlock_irqrestore(&brd_lock
, flags
);
4733 /*****************************************************************************/
4735 static void stl_sc26198flush(stlport_t
*portp
)
4737 unsigned long flags
;
4740 printk("stl_sc26198flush(portp=%x)\n", (int) portp
);
4743 if (portp
== (stlport_t
*) NULL
)
4746 spin_lock_irqsave(&brd_lock
, flags
);
4747 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4748 stl_sc26198setreg(portp
, SCCR
, CR_TXRESET
);
4749 stl_sc26198setreg(portp
, SCCR
, portp
->crenable
);
4750 BRDDISABLE(portp
->brdnr
);
4751 portp
->tx
.tail
= portp
->tx
.head
;
4752 spin_unlock_irqrestore(&brd_lock
, flags
);
4755 /*****************************************************************************/
4758 * Return the current state of data flow on this port. This is only
4759 * really interresting when determining if data has fully completed
4760 * transmission or not... The sc26198 interrupt scheme cannot
4761 * determine when all data has actually drained, so we need to
4762 * check the port statusy register to be sure.
4765 static int stl_sc26198datastate(stlport_t
*portp
)
4767 unsigned long flags
;
4771 printk("stl_sc26198datastate(portp=%x)\n", (int) portp
);
4774 if (portp
== (stlport_t
*) NULL
)
4776 if (test_bit(ASYI_TXBUSY
, &portp
->istate
))
4779 spin_lock_irqsave(&brd_lock
, flags
);
4780 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4781 sr
= stl_sc26198getreg(portp
, SR
);
4782 BRDDISABLE(portp
->brdnr
);
4783 spin_unlock_irqrestore(&brd_lock
, flags
);
4785 return (sr
& SR_TXEMPTY
) ? 0 : 1;
4788 /*****************************************************************************/
4791 * Delay for a small amount of time, to give the sc26198 a chance
4792 * to process a command...
4795 static void stl_sc26198wait(stlport_t
*portp
)
4800 printk("stl_sc26198wait(portp=%x)\n", (int) portp
);
4803 if (portp
== (stlport_t
*) NULL
)
4806 for (i
= 0; (i
< 20); i
++)
4807 stl_sc26198getglobreg(portp
, TSTR
);
4810 /*****************************************************************************/
4813 * If we are TX flow controlled and in IXANY mode then we may
4814 * need to unflow control here. We gotta do this because of the
4815 * automatic flow control modes of the sc26198.
4818 static inline void stl_sc26198txunflow(stlport_t
*portp
, struct tty_struct
*tty
)
4822 mr0
= stl_sc26198getreg(portp
, MR0
);
4823 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4824 stl_sc26198setreg(portp
, SCCR
, CR_HOSTXON
);
4825 stl_sc26198wait(portp
);
4826 stl_sc26198setreg(portp
, MR0
, mr0
);
4827 clear_bit(ASYI_TXFLOWED
, &portp
->istate
);
4830 /*****************************************************************************/
4833 * Interrupt service routine for sc26198 panels.
4836 static void stl_sc26198intr(stlpanel_t
*panelp
, unsigned int iobase
)
4841 spin_lock(&brd_lock
);
4844 * Work around bug in sc26198 chip... Cannot have A6 address
4845 * line of UART high, else iack will be returned as 0.
4847 outb(0, (iobase
+ 1));
4849 iack
= inb(iobase
+ XP_IACK
);
4850 portp
= panelp
->ports
[(iack
& IVR_CHANMASK
) + ((iobase
& 0x4) << 1)];
4852 if (iack
& IVR_RXDATA
)
4853 stl_sc26198rxisr(portp
, iack
);
4854 else if (iack
& IVR_TXDATA
)
4855 stl_sc26198txisr(portp
);
4857 stl_sc26198otherisr(portp
, iack
);
4859 spin_unlock(&brd_lock
);
4862 /*****************************************************************************/
4865 * Transmit interrupt handler. This has gotta be fast! Handling TX
4866 * chars is pretty simple, stuff as many as possible from the TX buffer
4867 * into the sc26198 FIFO.
4868 * In practice it is possible that interrupts are enabled but that the
4869 * port has been hung up. Need to handle not having any TX buffer here,
4870 * this is done by using the side effect that head and tail will also
4871 * be NULL if the buffer has been freed.
4874 static void stl_sc26198txisr(stlport_t
*portp
)
4876 unsigned int ioaddr
;
4882 printk("stl_sc26198txisr(portp=%x)\n", (int) portp
);
4885 ioaddr
= portp
->ioaddr
;
4886 head
= portp
->tx
.head
;
4887 tail
= portp
->tx
.tail
;
4888 len
= (head
>= tail
) ? (head
- tail
) : (STL_TXBUFSIZE
- (tail
- head
));
4889 if ((len
== 0) || ((len
< STL_TXBUFLOW
) &&
4890 (test_bit(ASYI_TXLOW
, &portp
->istate
) == 0))) {
4891 set_bit(ASYI_TXLOW
, &portp
->istate
);
4892 schedule_work(&portp
->tqueue
);
4896 outb((MR0
| portp
->uartaddr
), (ioaddr
+ XP_ADDR
));
4897 mr0
= inb(ioaddr
+ XP_DATA
);
4898 if ((mr0
& MR0_TXMASK
) == MR0_TXEMPTY
) {
4899 portp
->imr
&= ~IR_TXRDY
;
4900 outb((IMR
| portp
->uartaddr
), (ioaddr
+ XP_ADDR
));
4901 outb(portp
->imr
, (ioaddr
+ XP_DATA
));
4902 clear_bit(ASYI_TXBUSY
, &portp
->istate
);
4904 mr0
|= ((mr0
& ~MR0_TXMASK
) | MR0_TXEMPTY
);
4905 outb(mr0
, (ioaddr
+ XP_DATA
));
4908 len
= MIN(len
, SC26198_TXFIFOSIZE
);
4909 portp
->stats
.txtotal
+= len
;
4910 stlen
= MIN(len
, ((portp
->tx
.buf
+ STL_TXBUFSIZE
) - tail
));
4911 outb(GTXFIFO
, (ioaddr
+ XP_ADDR
));
4912 outsb((ioaddr
+ XP_DATA
), tail
, stlen
);
4915 if (tail
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
))
4916 tail
= portp
->tx
.buf
;
4918 outsb((ioaddr
+ XP_DATA
), tail
, len
);
4921 portp
->tx
.tail
= tail
;
4925 /*****************************************************************************/
4928 * Receive character interrupt handler. Determine if we have good chars
4929 * or bad chars and then process appropriately. Good chars are easy
4930 * just shove the lot into the RX buffer and set all status byte to 0.
4931 * If a bad RX char then process as required. This routine needs to be
4932 * fast! In practice it is possible that we get an interrupt on a port
4933 * that is closed. This can happen on hangups - since they completely
4934 * shutdown a port not in user context. Need to handle this case.
4937 static void stl_sc26198rxisr(stlport_t
*portp
, unsigned int iack
)
4939 struct tty_struct
*tty
;
4940 unsigned int len
, buflen
, ioaddr
;
4943 printk("stl_sc26198rxisr(portp=%x,iack=%x)\n", (int) portp
, iack
);
4947 ioaddr
= portp
->ioaddr
;
4948 outb(GIBCR
, (ioaddr
+ XP_ADDR
));
4949 len
= inb(ioaddr
+ XP_DATA
) + 1;
4951 if ((iack
& IVR_TYPEMASK
) == IVR_RXDATA
) {
4952 if (tty
== NULL
|| (buflen
= tty_buffer_request_room(tty
, len
)) == 0) {
4953 len
= MIN(len
, sizeof(stl_unwanted
));
4954 outb(GRXFIFO
, (ioaddr
+ XP_ADDR
));
4955 insb((ioaddr
+ XP_DATA
), &stl_unwanted
[0], len
);
4956 portp
->stats
.rxlost
+= len
;
4957 portp
->stats
.rxtotal
+= len
;
4959 len
= MIN(len
, buflen
);
4962 outb(GRXFIFO
, (ioaddr
+ XP_ADDR
));
4963 tty_prepare_flip_string(tty
, &ptr
, len
);
4964 insb((ioaddr
+ XP_DATA
), ptr
, len
);
4965 tty_schedule_flip(tty
);
4966 portp
->stats
.rxtotal
+= len
;
4970 stl_sc26198rxbadchars(portp
);
4974 * If we are TX flow controlled and in IXANY mode then we may need
4975 * to unflow control here. We gotta do this because of the automatic
4976 * flow control modes of the sc26198.
4978 if (test_bit(ASYI_TXFLOWED
, &portp
->istate
)) {
4979 if ((tty
!= (struct tty_struct
*) NULL
) &&
4980 (tty
->termios
!= (struct termios
*) NULL
) &&
4981 (tty
->termios
->c_iflag
& IXANY
)) {
4982 stl_sc26198txunflow(portp
, tty
);
4987 /*****************************************************************************/
4990 * Process an RX bad character.
4993 static inline void stl_sc26198rxbadch(stlport_t
*portp
, unsigned char status
, char ch
)
4995 struct tty_struct
*tty
;
4996 unsigned int ioaddr
;
4999 ioaddr
= portp
->ioaddr
;
5001 if (status
& SR_RXPARITY
)
5002 portp
->stats
.rxparity
++;
5003 if (status
& SR_RXFRAMING
)
5004 portp
->stats
.rxframing
++;
5005 if (status
& SR_RXOVERRUN
)
5006 portp
->stats
.rxoverrun
++;
5007 if (status
& SR_RXBREAK
)
5008 portp
->stats
.rxbreaks
++;
5010 if ((tty
!= (struct tty_struct
*) NULL
) &&
5011 ((portp
->rxignoremsk
& status
) == 0)) {
5012 if (portp
->rxmarkmsk
& status
) {
5013 if (status
& SR_RXBREAK
) {
5015 if (portp
->flags
& ASYNC_SAK
) {
5017 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
5019 } else if (status
& SR_RXPARITY
) {
5020 status
= TTY_PARITY
;
5021 } else if (status
& SR_RXFRAMING
) {
5023 } else if(status
& SR_RXOVERRUN
) {
5024 status
= TTY_OVERRUN
;
5032 tty_insert_flip_char(tty
, ch
, status
);
5033 tty_schedule_flip(tty
);
5036 portp
->stats
.rxtotal
++;
5040 /*****************************************************************************/
5043 * Process all characters in the RX FIFO of the UART. Check all char
5044 * status bytes as well, and process as required. We need to check
5045 * all bytes in the FIFO, in case some more enter the FIFO while we
5046 * are here. To get the exact character error type we need to switch
5047 * into CHAR error mode (that is why we need to make sure we empty
5051 static void stl_sc26198rxbadchars(stlport_t
*portp
)
5053 unsigned char status
, mr1
;
5057 * To get the precise error type for each character we must switch
5058 * back into CHAR error mode.
5060 mr1
= stl_sc26198getreg(portp
, MR1
);
5061 stl_sc26198setreg(portp
, MR1
, (mr1
& ~MR1_ERRBLOCK
));
5063 while ((status
= stl_sc26198getreg(portp
, SR
)) & SR_RXRDY
) {
5064 stl_sc26198setreg(portp
, SCCR
, CR_CLEARRXERR
);
5065 ch
= stl_sc26198getreg(portp
, RXFIFO
);
5066 stl_sc26198rxbadch(portp
, status
, ch
);
5070 * To get correct interrupt class we must switch back into BLOCK
5073 stl_sc26198setreg(portp
, MR1
, mr1
);
5076 /*****************************************************************************/
5079 * Other interrupt handler. This includes modem signals, flow
5080 * control actions, etc. Most stuff is left to off-level interrupt
5084 static void stl_sc26198otherisr(stlport_t
*portp
, unsigned int iack
)
5086 unsigned char cir
, ipr
, xisr
;
5089 printk("stl_sc26198otherisr(portp=%x,iack=%x)\n", (int) portp
, iack
);
5092 cir
= stl_sc26198getglobreg(portp
, CIR
);
5094 switch (cir
& CIR_SUBTYPEMASK
) {
5096 ipr
= stl_sc26198getreg(portp
, IPR
);
5097 if (ipr
& IPR_DCDCHANGE
) {
5098 set_bit(ASYI_DCDCHANGE
, &portp
->istate
);
5099 schedule_work(&portp
->tqueue
);
5100 portp
->stats
.modem
++;
5103 case CIR_SUBXONXOFF
:
5104 xisr
= stl_sc26198getreg(portp
, XISR
);
5105 if (xisr
& XISR_RXXONGOT
) {
5106 set_bit(ASYI_TXFLOWED
, &portp
->istate
);
5107 portp
->stats
.txxoff
++;
5109 if (xisr
& XISR_RXXOFFGOT
) {
5110 clear_bit(ASYI_TXFLOWED
, &portp
->istate
);
5111 portp
->stats
.txxon
++;
5115 stl_sc26198setreg(portp
, SCCR
, CR_BREAKRESET
);
5116 stl_sc26198rxbadchars(portp
);
5123 /*****************************************************************************/