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/module.h>
30 #include <linux/slab.h>
31 #include <linux/interrupt.h>
32 #include <linux/tty.h>
33 #include <linux/tty_flip.h>
34 #include <linux/serial.h>
35 #include <linux/cd1400.h>
36 #include <linux/sc26198.h>
37 #include <linux/comstats.h>
38 #include <linux/stallion.h>
39 #include <linux/ioport.h>
40 #include <linux/init.h>
41 #include <linux/smp_lock.h>
42 #include <linux/device.h>
43 #include <linux/delay.h>
44 #include <linux/ctype.h>
47 #include <asm/uaccess.h>
49 #include <linux/pci.h>
51 /*****************************************************************************/
54 * Define different board types. Use the standard Stallion "assigned"
55 * board numbers. Boards supported in this driver are abbreviated as
56 * EIO = EasyIO and ECH = EasyConnection 8/32.
62 #define BRD_ECH64PCI 27
63 #define BRD_EASYIOPCI 28
69 unsigned long memaddr
;
74 static unsigned int stl_nrbrds
;
76 /*****************************************************************************/
79 * Define some important driver characteristics. Device major numbers
80 * allocated as per Linux Device Registry.
82 #ifndef STL_SIOMEMMAJOR
83 #define STL_SIOMEMMAJOR 28
85 #ifndef STL_SERIALMAJOR
86 #define STL_SERIALMAJOR 24
88 #ifndef STL_CALLOUTMAJOR
89 #define STL_CALLOUTMAJOR 25
93 * Set the TX buffer size. Bigger is better, but we don't want
94 * to chew too much memory with buffers!
96 #define STL_TXBUFLOW 512
97 #define STL_TXBUFSIZE 4096
99 /*****************************************************************************/
102 * Define our local driver identity first. Set up stuff to deal with
103 * all the local structures required by a serial tty driver.
105 static char *stl_drvtitle
= "Stallion Multiport Serial Driver";
106 static char *stl_drvname
= "stallion";
107 static char *stl_drvversion
= "5.6.0";
109 static struct tty_driver
*stl_serial
;
112 * Define a local default termios struct. All ports will be created
113 * with this termios initially. Basically all it defines is a raw port
114 * at 9600, 8 data bits, 1 stop bit.
116 static struct ktermios stl_deftermios
= {
117 .c_cflag
= (B9600
| CS8
| CREAD
| HUPCL
| CLOCAL
),
124 * Define global place to put buffer overflow characters.
126 static char stl_unwanted
[SC26198_RXFIFOSIZE
];
128 /*****************************************************************************/
130 static DEFINE_MUTEX(stl_brdslock
);
131 static struct stlbrd
*stl_brds
[STL_MAXBRDS
];
134 * Per board state flags. Used with the state field of the board struct.
135 * Not really much here!
137 #define BRD_FOUND 0x1
138 #define STL_PROBED 0x2
142 * Define the port structure istate flags. These set of flags are
143 * modified at interrupt time - so setting and reseting them needs
144 * to be atomic. Use the bit clear/setting routines for this.
146 #define ASYI_TXBUSY 1
148 #define ASYI_TXFLOWED 3
151 * Define an array of board names as printable strings. Handy for
152 * referencing boards when printing trace and stuff.
154 static char *stl_brdnames
[] = {
186 /*****************************************************************************/
189 * Define some string labels for arguments passed from the module
190 * load line. These allow for easy board definitions, and easy
191 * modification of the io, memory and irq resoucres.
193 static unsigned int stl_nargs
;
194 static char *board0
[4];
195 static char *board1
[4];
196 static char *board2
[4];
197 static char *board3
[4];
199 static char **stl_brdsp
[] = {
207 * Define a set of common board names, and types. This is used to
208 * parse any module arguments.
215 { "easyio", BRD_EASYIO
},
216 { "eio", BRD_EASYIO
},
217 { "20", BRD_EASYIO
},
218 { "ec8/32", BRD_ECH
},
219 { "ec8/32-at", BRD_ECH
},
220 { "ec8/32-isa", BRD_ECH
},
222 { "echat", BRD_ECH
},
224 { "ec8/32-mc", BRD_ECHMC
},
225 { "ec8/32-mca", BRD_ECHMC
},
226 { "echmc", BRD_ECHMC
},
227 { "echmca", BRD_ECHMC
},
229 { "ec8/32-pc", BRD_ECHPCI
},
230 { "ec8/32-pci", BRD_ECHPCI
},
231 { "26", BRD_ECHPCI
},
232 { "ec8/64-pc", BRD_ECH64PCI
},
233 { "ec8/64-pci", BRD_ECH64PCI
},
234 { "ech-pci", BRD_ECH64PCI
},
235 { "echpci", BRD_ECH64PCI
},
236 { "echpc", BRD_ECH64PCI
},
237 { "27", BRD_ECH64PCI
},
238 { "easyio-pc", BRD_EASYIOPCI
},
239 { "easyio-pci", BRD_EASYIOPCI
},
240 { "eio-pci", BRD_EASYIOPCI
},
241 { "eiopci", BRD_EASYIOPCI
},
242 { "28", BRD_EASYIOPCI
},
246 * Define the module agruments.
249 module_param_array(board0
, charp
, &stl_nargs
, 0);
250 MODULE_PARM_DESC(board0
, "Board 0 config -> name[,ioaddr[,ioaddr2][,irq]]");
251 module_param_array(board1
, charp
, &stl_nargs
, 0);
252 MODULE_PARM_DESC(board1
, "Board 1 config -> name[,ioaddr[,ioaddr2][,irq]]");
253 module_param_array(board2
, charp
, &stl_nargs
, 0);
254 MODULE_PARM_DESC(board2
, "Board 2 config -> name[,ioaddr[,ioaddr2][,irq]]");
255 module_param_array(board3
, charp
, &stl_nargs
, 0);
256 MODULE_PARM_DESC(board3
, "Board 3 config -> name[,ioaddr[,ioaddr2][,irq]]");
258 /*****************************************************************************/
261 * Hardware ID bits for the EasyIO and ECH boards. These defines apply
262 * to the directly accessible io ports of these boards (not the uarts -
263 * they are in cd1400.h and sc26198.h).
265 #define EIO_8PORTRS 0x04
266 #define EIO_4PORTRS 0x05
267 #define EIO_8PORTDI 0x00
268 #define EIO_8PORTM 0x06
270 #define EIO_IDBITMASK 0x07
272 #define EIO_BRDMASK 0xf0
275 #define ID_BRD16 0x30
277 #define EIO_INTRPEND 0x08
278 #define EIO_INTEDGE 0x00
279 #define EIO_INTLEVEL 0x08
283 #define ECH_IDBITMASK 0xe0
284 #define ECH_BRDENABLE 0x08
285 #define ECH_BRDDISABLE 0x00
286 #define ECH_INTENABLE 0x01
287 #define ECH_INTDISABLE 0x00
288 #define ECH_INTLEVEL 0x02
289 #define ECH_INTEDGE 0x00
290 #define ECH_INTRPEND 0x01
291 #define ECH_BRDRESET 0x01
293 #define ECHMC_INTENABLE 0x01
294 #define ECHMC_BRDRESET 0x02
296 #define ECH_PNLSTATUS 2
297 #define ECH_PNL16PORT 0x20
298 #define ECH_PNLIDMASK 0x07
299 #define ECH_PNLXPID 0x40
300 #define ECH_PNLINTRPEND 0x80
302 #define ECH_ADDR2MASK 0x1e0
305 * Define the vector mapping bits for the programmable interrupt board
306 * hardware. These bits encode the interrupt for the board to use - it
307 * is software selectable (except the EIO-8M).
309 static unsigned char stl_vecmap
[] = {
310 0xff, 0xff, 0xff, 0x04, 0x06, 0x05, 0xff, 0x07,
311 0xff, 0xff, 0x00, 0x02, 0x01, 0xff, 0xff, 0x03
315 * Lock ordering is that you may not take stallion_lock holding
319 static spinlock_t brd_lock
; /* Guard the board mapping */
320 static spinlock_t stallion_lock
; /* Guard the tty driver */
323 * Set up enable and disable macros for the ECH boards. They require
324 * the secondary io address space to be activated and deactivated.
325 * This way all ECH boards can share their secondary io region.
326 * If this is an ECH-PCI board then also need to set the page pointer
327 * to point to the correct page.
329 #define BRDENABLE(brdnr,pagenr) \
330 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
331 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDENABLE), \
332 stl_brds[(brdnr)]->ioctrl); \
333 else if (stl_brds[(brdnr)]->brdtype == BRD_ECHPCI) \
334 outb((pagenr), stl_brds[(brdnr)]->ioctrl);
336 #define BRDDISABLE(brdnr) \
337 if (stl_brds[(brdnr)]->brdtype == BRD_ECH) \
338 outb((stl_brds[(brdnr)]->ioctrlval | ECH_BRDDISABLE), \
339 stl_brds[(brdnr)]->ioctrl);
341 #define STL_CD1400MAXBAUD 230400
342 #define STL_SC26198MAXBAUD 460800
344 #define STL_BAUDBASE 115200
345 #define STL_CLOSEDELAY (5 * HZ / 10)
347 /*****************************************************************************/
350 * Define the Stallion PCI vendor and device IDs.
352 #ifndef PCI_VENDOR_ID_STALLION
353 #define PCI_VENDOR_ID_STALLION 0x124d
355 #ifndef PCI_DEVICE_ID_ECHPCI832
356 #define PCI_DEVICE_ID_ECHPCI832 0x0000
358 #ifndef PCI_DEVICE_ID_ECHPCI864
359 #define PCI_DEVICE_ID_ECHPCI864 0x0002
361 #ifndef PCI_DEVICE_ID_EIOPCI
362 #define PCI_DEVICE_ID_EIOPCI 0x0003
366 * Define structure to hold all Stallion PCI boards.
369 static struct pci_device_id stl_pcibrds
[] = {
370 { PCI_DEVICE(PCI_VENDOR_ID_STALLION
, PCI_DEVICE_ID_ECHPCI864
),
371 .driver_data
= BRD_ECH64PCI
},
372 { PCI_DEVICE(PCI_VENDOR_ID_STALLION
, PCI_DEVICE_ID_EIOPCI
),
373 .driver_data
= BRD_EASYIOPCI
},
374 { PCI_DEVICE(PCI_VENDOR_ID_STALLION
, PCI_DEVICE_ID_ECHPCI832
),
375 .driver_data
= BRD_ECHPCI
},
376 { PCI_DEVICE(PCI_VENDOR_ID_NS
, PCI_DEVICE_ID_NS_87410
),
377 .driver_data
= BRD_ECHPCI
},
380 MODULE_DEVICE_TABLE(pci
, stl_pcibrds
);
382 /*****************************************************************************/
385 * Define macros to extract a brd/port number from a minor number.
387 #define MINOR2BRD(min) (((min) & 0xc0) >> 6)
388 #define MINOR2PORT(min) ((min) & 0x3f)
391 * Define a baud rate table that converts termios baud rate selector
392 * into the actual baud rate value. All baud rate calculations are
393 * based on the actual baud rate required.
395 static unsigned int stl_baudrates
[] = {
396 0, 50, 75, 110, 134, 150, 200, 300, 600, 1200, 1800, 2400, 4800,
397 9600, 19200, 38400, 57600, 115200, 230400, 460800, 921600
400 /*****************************************************************************/
403 * Declare all those functions in this driver!
406 static int stl_memioctl(struct inode
*ip
, struct file
*fp
, unsigned int cmd
, unsigned long arg
);
407 static int stl_brdinit(struct stlbrd
*brdp
);
408 static int stl_getportstats(struct tty_struct
*tty
, struct stlport
*portp
, comstats_t __user
*cp
);
409 static int stl_clrportstats(struct stlport
*portp
, comstats_t __user
*cp
);
410 static int stl_waitcarrier(struct tty_struct
*tty
, struct stlport
*portp
, struct file
*filp
);
413 * CD1400 uart specific handling functions.
415 static void stl_cd1400setreg(struct stlport
*portp
, int regnr
, int value
);
416 static int stl_cd1400getreg(struct stlport
*portp
, int regnr
);
417 static int stl_cd1400updatereg(struct stlport
*portp
, int regnr
, int value
);
418 static int stl_cd1400panelinit(struct stlbrd
*brdp
, struct stlpanel
*panelp
);
419 static void stl_cd1400portinit(struct stlbrd
*brdp
, struct stlpanel
*panelp
, struct stlport
*portp
);
420 static void stl_cd1400setport(struct stlport
*portp
, struct ktermios
*tiosp
);
421 static int stl_cd1400getsignals(struct stlport
*portp
);
422 static void stl_cd1400setsignals(struct stlport
*portp
, int dtr
, int rts
);
423 static void stl_cd1400ccrwait(struct stlport
*portp
);
424 static void stl_cd1400enablerxtx(struct stlport
*portp
, int rx
, int tx
);
425 static void stl_cd1400startrxtx(struct stlport
*portp
, int rx
, int tx
);
426 static void stl_cd1400disableintrs(struct stlport
*portp
);
427 static void stl_cd1400sendbreak(struct stlport
*portp
, int len
);
428 static void stl_cd1400flowctrl(struct stlport
*portp
, int state
);
429 static void stl_cd1400sendflow(struct stlport
*portp
, int state
);
430 static void stl_cd1400flush(struct stlport
*portp
);
431 static int stl_cd1400datastate(struct stlport
*portp
);
432 static void stl_cd1400eiointr(struct stlpanel
*panelp
, unsigned int iobase
);
433 static void stl_cd1400echintr(struct stlpanel
*panelp
, unsigned int iobase
);
434 static void stl_cd1400txisr(struct stlpanel
*panelp
, int ioaddr
);
435 static void stl_cd1400rxisr(struct stlpanel
*panelp
, int ioaddr
);
436 static void stl_cd1400mdmisr(struct stlpanel
*panelp
, int ioaddr
);
438 static inline int stl_cd1400breakisr(struct stlport
*portp
, int ioaddr
);
441 * SC26198 uart specific handling functions.
443 static void stl_sc26198setreg(struct stlport
*portp
, int regnr
, int value
);
444 static int stl_sc26198getreg(struct stlport
*portp
, int regnr
);
445 static int stl_sc26198updatereg(struct stlport
*portp
, int regnr
, int value
);
446 static int stl_sc26198getglobreg(struct stlport
*portp
, int regnr
);
447 static int stl_sc26198panelinit(struct stlbrd
*brdp
, struct stlpanel
*panelp
);
448 static void stl_sc26198portinit(struct stlbrd
*brdp
, struct stlpanel
*panelp
, struct stlport
*portp
);
449 static void stl_sc26198setport(struct stlport
*portp
, struct ktermios
*tiosp
);
450 static int stl_sc26198getsignals(struct stlport
*portp
);
451 static void stl_sc26198setsignals(struct stlport
*portp
, int dtr
, int rts
);
452 static void stl_sc26198enablerxtx(struct stlport
*portp
, int rx
, int tx
);
453 static void stl_sc26198startrxtx(struct stlport
*portp
, int rx
, int tx
);
454 static void stl_sc26198disableintrs(struct stlport
*portp
);
455 static void stl_sc26198sendbreak(struct stlport
*portp
, int len
);
456 static void stl_sc26198flowctrl(struct stlport
*portp
, int state
);
457 static void stl_sc26198sendflow(struct stlport
*portp
, int state
);
458 static void stl_sc26198flush(struct stlport
*portp
);
459 static int stl_sc26198datastate(struct stlport
*portp
);
460 static void stl_sc26198wait(struct stlport
*portp
);
461 static void stl_sc26198txunflow(struct stlport
*portp
, struct tty_struct
*tty
);
462 static void stl_sc26198intr(struct stlpanel
*panelp
, unsigned int iobase
);
463 static void stl_sc26198txisr(struct stlport
*port
);
464 static void stl_sc26198rxisr(struct stlport
*port
, unsigned int iack
);
465 static void stl_sc26198rxbadch(struct stlport
*portp
, unsigned char status
, char ch
);
466 static void stl_sc26198rxbadchars(struct stlport
*portp
);
467 static void stl_sc26198otherisr(struct stlport
*port
, unsigned int iack
);
469 /*****************************************************************************/
472 * Generic UART support structure.
474 typedef struct uart
{
475 int (*panelinit
)(struct stlbrd
*brdp
, struct stlpanel
*panelp
);
476 void (*portinit
)(struct stlbrd
*brdp
, struct stlpanel
*panelp
, struct stlport
*portp
);
477 void (*setport
)(struct stlport
*portp
, struct ktermios
*tiosp
);
478 int (*getsignals
)(struct stlport
*portp
);
479 void (*setsignals
)(struct stlport
*portp
, int dtr
, int rts
);
480 void (*enablerxtx
)(struct stlport
*portp
, int rx
, int tx
);
481 void (*startrxtx
)(struct stlport
*portp
, int rx
, int tx
);
482 void (*disableintrs
)(struct stlport
*portp
);
483 void (*sendbreak
)(struct stlport
*portp
, int len
);
484 void (*flowctrl
)(struct stlport
*portp
, int state
);
485 void (*sendflow
)(struct stlport
*portp
, int state
);
486 void (*flush
)(struct stlport
*portp
);
487 int (*datastate
)(struct stlport
*portp
);
488 void (*intr
)(struct stlpanel
*panelp
, unsigned int iobase
);
492 * Define some macros to make calling these functions nice and clean.
494 #define stl_panelinit (* ((uart_t *) panelp->uartp)->panelinit)
495 #define stl_portinit (* ((uart_t *) portp->uartp)->portinit)
496 #define stl_setport (* ((uart_t *) portp->uartp)->setport)
497 #define stl_getsignals (* ((uart_t *) portp->uartp)->getsignals)
498 #define stl_setsignals (* ((uart_t *) portp->uartp)->setsignals)
499 #define stl_enablerxtx (* ((uart_t *) portp->uartp)->enablerxtx)
500 #define stl_startrxtx (* ((uart_t *) portp->uartp)->startrxtx)
501 #define stl_disableintrs (* ((uart_t *) portp->uartp)->disableintrs)
502 #define stl_sendbreak (* ((uart_t *) portp->uartp)->sendbreak)
503 #define stl_flowctrl (* ((uart_t *) portp->uartp)->flowctrl)
504 #define stl_sendflow (* ((uart_t *) portp->uartp)->sendflow)
505 #define stl_flush (* ((uart_t *) portp->uartp)->flush)
506 #define stl_datastate (* ((uart_t *) portp->uartp)->datastate)
508 /*****************************************************************************/
511 * CD1400 UART specific data initialization.
513 static uart_t stl_cd1400uart
= {
517 stl_cd1400getsignals
,
518 stl_cd1400setsignals
,
519 stl_cd1400enablerxtx
,
521 stl_cd1400disableintrs
,
531 * Define the offsets within the register bank of a cd1400 based panel.
532 * These io address offsets are common to the EasyIO board as well.
540 #define EREG_BANKSIZE 8
542 #define CD1400_CLK 25000000
543 #define CD1400_CLK8M 20000000
546 * Define the cd1400 baud rate clocks. These are used when calculating
547 * what clock and divisor to use for the required baud rate. Also
548 * define the maximum baud rate allowed, and the default base baud.
550 static int stl_cd1400clkdivs
[] = {
551 CD1400_CLK0
, CD1400_CLK1
, CD1400_CLK2
, CD1400_CLK3
, CD1400_CLK4
554 /*****************************************************************************/
557 * SC26198 UART specific data initization.
559 static uart_t stl_sc26198uart
= {
560 stl_sc26198panelinit
,
563 stl_sc26198getsignals
,
564 stl_sc26198setsignals
,
565 stl_sc26198enablerxtx
,
566 stl_sc26198startrxtx
,
567 stl_sc26198disableintrs
,
568 stl_sc26198sendbreak
,
572 stl_sc26198datastate
,
577 * Define the offsets within the register bank of a sc26198 based panel.
585 #define XP_BANKSIZE 4
588 * Define the sc26198 baud rate table. Offsets within the table
589 * represent the actual baud rate selector of sc26198 registers.
591 static unsigned int sc26198_baudtable
[] = {
592 50, 75, 150, 200, 300, 450, 600, 900, 1200, 1800, 2400, 3600,
593 4800, 7200, 9600, 14400, 19200, 28800, 38400, 57600, 115200,
594 230400, 460800, 921600
597 #define SC26198_NRBAUDS ARRAY_SIZE(sc26198_baudtable)
599 /*****************************************************************************/
602 * Define the driver info for a user level control device. Used mainly
603 * to get at port stats - only not using the port device itself.
605 static const struct file_operations stl_fsiomem
= {
606 .owner
= THIS_MODULE
,
607 .ioctl
= stl_memioctl
,
610 static struct class *stallion_class
;
612 static void stl_cd_change(struct stlport
*portp
)
614 unsigned int oldsigs
= portp
->sigs
;
615 struct tty_struct
*tty
= tty_port_tty_get(&portp
->port
);
620 portp
->sigs
= stl_getsignals(portp
);
622 if ((portp
->sigs
& TIOCM_CD
) && ((oldsigs
& TIOCM_CD
) == 0))
623 wake_up_interruptible(&portp
->port
.open_wait
);
625 if ((oldsigs
& TIOCM_CD
) && ((portp
->sigs
& TIOCM_CD
) == 0))
626 if (portp
->port
.flags
& ASYNC_CHECK_CD
)
632 * Check for any arguments passed in on the module load command line.
635 /*****************************************************************************/
638 * Parse the supplied argument string, into the board conf struct.
641 static int __init
stl_parsebrd(struct stlconf
*confp
, char **argp
)
646 pr_debug("stl_parsebrd(confp=%p,argp=%p)\n", confp
, argp
);
648 if ((argp
[0] == NULL
) || (*argp
[0] == 0))
651 for (sp
= argp
[0], i
= 0; (*sp
!= 0) && (i
< 25); sp
++, i
++)
654 for (i
= 0; i
< ARRAY_SIZE(stl_brdstr
); i
++)
655 if (strcmp(stl_brdstr
[i
].name
, argp
[0]) == 0)
658 if (i
== ARRAY_SIZE(stl_brdstr
)) {
659 printk("STALLION: unknown board name, %s?\n", argp
[0]);
663 confp
->brdtype
= stl_brdstr
[i
].type
;
666 if ((argp
[i
] != NULL
) && (*argp
[i
] != 0))
667 confp
->ioaddr1
= simple_strtoul(argp
[i
], NULL
, 0);
669 if (confp
->brdtype
== BRD_ECH
) {
670 if ((argp
[i
] != NULL
) && (*argp
[i
] != 0))
671 confp
->ioaddr2
= simple_strtoul(argp
[i
], NULL
, 0);
674 if ((argp
[i
] != NULL
) && (*argp
[i
] != 0))
675 confp
->irq
= simple_strtoul(argp
[i
], NULL
, 0);
679 /*****************************************************************************/
682 * Allocate a new board structure. Fill out the basic info in it.
685 static struct stlbrd
*stl_allocbrd(void)
689 brdp
= kzalloc(sizeof(struct stlbrd
), GFP_KERNEL
);
691 printk("STALLION: failed to allocate memory (size=%Zd)\n",
692 sizeof(struct stlbrd
));
696 brdp
->magic
= STL_BOARDMAGIC
;
700 /*****************************************************************************/
702 static int stl_open(struct tty_struct
*tty
, struct file
*filp
)
704 struct stlport
*portp
;
706 unsigned int minordev
, brdnr
, panelnr
;
709 pr_debug("stl_open(tty=%p,filp=%p): device=%s\n", tty
, filp
, tty
->name
);
711 minordev
= tty
->index
;
712 brdnr
= MINOR2BRD(minordev
);
713 if (brdnr
>= stl_nrbrds
)
715 brdp
= stl_brds
[brdnr
];
718 minordev
= MINOR2PORT(minordev
);
719 for (portnr
= -1, panelnr
= 0; panelnr
< STL_MAXPANELS
; panelnr
++) {
720 if (brdp
->panels
[panelnr
] == NULL
)
722 if (minordev
< brdp
->panels
[panelnr
]->nrports
) {
726 minordev
-= brdp
->panels
[panelnr
]->nrports
;
731 portp
= brdp
->panels
[panelnr
]->ports
[portnr
];
736 * On the first open of the device setup the port hardware, and
737 * initialize the per port data structure.
739 tty_port_tty_set(&portp
->port
, tty
);
740 tty
->driver_data
= portp
;
743 if ((portp
->port
.flags
& ASYNC_INITIALIZED
) == 0) {
744 if (!portp
->tx
.buf
) {
745 portp
->tx
.buf
= kmalloc(STL_TXBUFSIZE
, GFP_KERNEL
);
748 portp
->tx
.head
= portp
->tx
.buf
;
749 portp
->tx
.tail
= portp
->tx
.buf
;
751 stl_setport(portp
, tty
->termios
);
752 portp
->sigs
= stl_getsignals(portp
);
753 stl_setsignals(portp
, 1, 1);
754 stl_enablerxtx(portp
, 1, 1);
755 stl_startrxtx(portp
, 1, 0);
756 clear_bit(TTY_IO_ERROR
, &tty
->flags
);
757 portp
->port
.flags
|= ASYNC_INITIALIZED
;
761 * Check if this port is in the middle of closing. If so then wait
762 * until it is closed then return error status, based on flag settings.
763 * The sleep here does not need interrupt protection since the wakeup
764 * for it is done with the same context.
766 if (portp
->port
.flags
& ASYNC_CLOSING
) {
767 interruptible_sleep_on(&portp
->port
.close_wait
);
768 if (portp
->port
.flags
& ASYNC_HUP_NOTIFY
)
774 * Based on type of open being done check if it can overlap with any
775 * previous opens still in effect. If we are a normal serial device
776 * then also we might have to wait for carrier.
778 if (!(filp
->f_flags
& O_NONBLOCK
))
779 if ((rc
= stl_waitcarrier(tty
, portp
, filp
)) != 0)
782 portp
->port
.flags
|= ASYNC_NORMAL_ACTIVE
;
787 /*****************************************************************************/
790 * Possibly need to wait for carrier (DCD signal) to come high. Say
791 * maybe because if we are clocal then we don't need to wait...
794 static int stl_waitcarrier(struct tty_struct
*tty
, struct stlport
*portp
,
800 pr_debug("stl_waitcarrier(portp=%p,filp=%p)\n", portp
, filp
);
805 spin_lock_irqsave(&stallion_lock
, flags
);
807 if (tty
->termios
->c_cflag
& CLOCAL
)
810 portp
->openwaitcnt
++;
811 if (! tty_hung_up_p(filp
))
815 /* Takes brd_lock internally */
816 stl_setsignals(portp
, 1, 1);
817 if (tty_hung_up_p(filp
) ||
818 ((portp
->port
.flags
& ASYNC_INITIALIZED
) == 0)) {
819 if (portp
->port
.flags
& ASYNC_HUP_NOTIFY
)
825 if (((portp
->port
.flags
& ASYNC_CLOSING
) == 0) &&
826 (doclocal
|| (portp
->sigs
& TIOCM_CD
)))
828 if (signal_pending(current
)) {
833 interruptible_sleep_on(&portp
->port
.open_wait
);
836 if (! tty_hung_up_p(filp
))
838 portp
->openwaitcnt
--;
839 spin_unlock_irqrestore(&stallion_lock
, flags
);
844 /*****************************************************************************/
846 static void stl_flushbuffer(struct tty_struct
*tty
)
848 struct stlport
*portp
;
850 pr_debug("stl_flushbuffer(tty=%p)\n", tty
);
852 portp
= tty
->driver_data
;
860 /*****************************************************************************/
862 static void stl_waituntilsent(struct tty_struct
*tty
, int timeout
)
864 struct stlport
*portp
;
867 pr_debug("stl_waituntilsent(tty=%p,timeout=%d)\n", tty
, timeout
);
869 portp
= tty
->driver_data
;
875 tend
= jiffies
+ timeout
;
878 while (stl_datastate(portp
)) {
879 if (signal_pending(current
))
881 msleep_interruptible(20);
882 if (time_after_eq(jiffies
, tend
))
888 /*****************************************************************************/
890 static void stl_close(struct tty_struct
*tty
, struct file
*filp
)
892 struct stlport
*portp
;
895 pr_debug("stl_close(tty=%p,filp=%p)\n", tty
, filp
);
897 portp
= tty
->driver_data
;
901 spin_lock_irqsave(&stallion_lock
, flags
);
902 if (tty_hung_up_p(filp
)) {
903 spin_unlock_irqrestore(&stallion_lock
, flags
);
906 if ((tty
->count
== 1) && (portp
->port
.count
!= 1))
907 portp
->port
.count
= 1;
908 if (portp
->port
.count
-- > 1) {
909 spin_unlock_irqrestore(&stallion_lock
, flags
);
913 portp
->port
.count
= 0;
914 portp
->port
.flags
|= ASYNC_CLOSING
;
917 * May want to wait for any data to drain before closing. The BUSY
918 * flag keeps track of whether we are still sending or not - it is
919 * very accurate for the cd1400, not quite so for the sc26198.
920 * (The sc26198 has no "end-of-data" interrupt only empty FIFO)
924 spin_unlock_irqrestore(&stallion_lock
, flags
);
926 if (portp
->closing_wait
!= ASYNC_CLOSING_WAIT_NONE
)
927 tty_wait_until_sent(tty
, portp
->closing_wait
);
928 stl_waituntilsent(tty
, (HZ
/ 2));
931 spin_lock_irqsave(&stallion_lock
, flags
);
932 portp
->port
.flags
&= ~ASYNC_INITIALIZED
;
933 spin_unlock_irqrestore(&stallion_lock
, flags
);
935 stl_disableintrs(portp
);
936 if (tty
->termios
->c_cflag
& HUPCL
)
937 stl_setsignals(portp
, 0, 0);
938 stl_enablerxtx(portp
, 0, 0);
939 stl_flushbuffer(tty
);
941 if (portp
->tx
.buf
!= NULL
) {
942 kfree(portp
->tx
.buf
);
943 portp
->tx
.buf
= NULL
;
944 portp
->tx
.head
= NULL
;
945 portp
->tx
.tail
= NULL
;
947 set_bit(TTY_IO_ERROR
, &tty
->flags
);
948 tty_ldisc_flush(tty
);
951 tty_port_tty_set(&portp
->port
, NULL
);
953 if (portp
->openwaitcnt
) {
954 if (portp
->close_delay
)
955 msleep_interruptible(jiffies_to_msecs(portp
->close_delay
));
956 wake_up_interruptible(&portp
->port
.open_wait
);
959 portp
->port
.flags
&= ~(ASYNC_NORMAL_ACTIVE
|ASYNC_CLOSING
);
960 wake_up_interruptible(&portp
->port
.close_wait
);
963 /*****************************************************************************/
966 * Write routine. Take data and stuff it in to the TX ring queue.
967 * If transmit interrupts are not running then start them.
970 static int stl_write(struct tty_struct
*tty
, const unsigned char *buf
, int count
)
972 struct stlport
*portp
;
973 unsigned int len
, stlen
;
974 unsigned char *chbuf
;
977 pr_debug("stl_write(tty=%p,buf=%p,count=%d)\n", tty
, buf
, count
);
979 portp
= tty
->driver_data
;
982 if (portp
->tx
.buf
== NULL
)
986 * If copying direct from user space we must cater for page faults,
987 * causing us to "sleep" here for a while. To handle this copy in all
988 * the data we need now, into a local buffer. Then when we got it all
989 * copy it into the TX buffer.
991 chbuf
= (unsigned char *) buf
;
993 head
= portp
->tx
.head
;
994 tail
= portp
->tx
.tail
;
996 len
= STL_TXBUFSIZE
- (head
- tail
) - 1;
997 stlen
= STL_TXBUFSIZE
- (head
- portp
->tx
.buf
);
999 len
= tail
- head
- 1;
1003 len
= min(len
, (unsigned int)count
);
1006 stlen
= min(len
, stlen
);
1007 memcpy(head
, chbuf
, stlen
);
1012 if (head
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
)) {
1013 head
= portp
->tx
.buf
;
1014 stlen
= tail
- head
;
1017 portp
->tx
.head
= head
;
1019 clear_bit(ASYI_TXLOW
, &portp
->istate
);
1020 stl_startrxtx(portp
, -1, 1);
1025 /*****************************************************************************/
1027 static int stl_putchar(struct tty_struct
*tty
, unsigned char ch
)
1029 struct stlport
*portp
;
1033 pr_debug("stl_putchar(tty=%p,ch=%x)\n", tty
, ch
);
1035 portp
= tty
->driver_data
;
1038 if (portp
->tx
.buf
== NULL
)
1041 head
= portp
->tx
.head
;
1042 tail
= portp
->tx
.tail
;
1044 len
= (head
>= tail
) ? (STL_TXBUFSIZE
- (head
- tail
)) : (tail
- head
);
1049 if (head
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
))
1050 head
= portp
->tx
.buf
;
1052 portp
->tx
.head
= head
;
1056 /*****************************************************************************/
1059 * If there are any characters in the buffer then make sure that TX
1060 * interrupts are on and get'em out. Normally used after the putchar
1061 * routine has been called.
1064 static void stl_flushchars(struct tty_struct
*tty
)
1066 struct stlport
*portp
;
1068 pr_debug("stl_flushchars(tty=%p)\n", tty
);
1070 portp
= tty
->driver_data
;
1073 if (portp
->tx
.buf
== NULL
)
1076 stl_startrxtx(portp
, -1, 1);
1079 /*****************************************************************************/
1081 static int stl_writeroom(struct tty_struct
*tty
)
1083 struct stlport
*portp
;
1086 pr_debug("stl_writeroom(tty=%p)\n", tty
);
1088 portp
= tty
->driver_data
;
1091 if (portp
->tx
.buf
== NULL
)
1094 head
= portp
->tx
.head
;
1095 tail
= portp
->tx
.tail
;
1096 return (head
>= tail
) ? (STL_TXBUFSIZE
- (head
- tail
) - 1) : (tail
- head
- 1);
1099 /*****************************************************************************/
1102 * Return number of chars in the TX buffer. Normally we would just
1103 * calculate the number of chars in the buffer and return that, but if
1104 * the buffer is empty and TX interrupts are still on then we return
1105 * that the buffer still has 1 char in it. This way whoever called us
1106 * will not think that ALL chars have drained - since the UART still
1107 * must have some chars in it (we are busy after all).
1110 static int stl_charsinbuffer(struct tty_struct
*tty
)
1112 struct stlport
*portp
;
1116 pr_debug("stl_charsinbuffer(tty=%p)\n", tty
);
1118 portp
= tty
->driver_data
;
1121 if (portp
->tx
.buf
== NULL
)
1124 head
= portp
->tx
.head
;
1125 tail
= portp
->tx
.tail
;
1126 size
= (head
>= tail
) ? (head
- tail
) : (STL_TXBUFSIZE
- (tail
- head
));
1127 if ((size
== 0) && test_bit(ASYI_TXBUSY
, &portp
->istate
))
1132 /*****************************************************************************/
1135 * Generate the serial struct info.
1138 static int stl_getserial(struct stlport
*portp
, struct serial_struct __user
*sp
)
1140 struct serial_struct sio
;
1141 struct stlbrd
*brdp
;
1143 pr_debug("stl_getserial(portp=%p,sp=%p)\n", portp
, sp
);
1145 memset(&sio
, 0, sizeof(struct serial_struct
));
1146 sio
.line
= portp
->portnr
;
1147 sio
.port
= portp
->ioaddr
;
1148 sio
.flags
= portp
->port
.flags
;
1149 sio
.baud_base
= portp
->baud_base
;
1150 sio
.close_delay
= portp
->close_delay
;
1151 sio
.closing_wait
= portp
->closing_wait
;
1152 sio
.custom_divisor
= portp
->custom_divisor
;
1154 if (portp
->uartp
== &stl_cd1400uart
) {
1155 sio
.type
= PORT_CIRRUS
;
1156 sio
.xmit_fifo_size
= CD1400_TXFIFOSIZE
;
1158 sio
.type
= PORT_UNKNOWN
;
1159 sio
.xmit_fifo_size
= SC26198_TXFIFOSIZE
;
1162 brdp
= stl_brds
[portp
->brdnr
];
1164 sio
.irq
= brdp
->irq
;
1166 return copy_to_user(sp
, &sio
, sizeof(struct serial_struct
)) ? -EFAULT
: 0;
1169 /*****************************************************************************/
1172 * Set port according to the serial struct info.
1173 * At this point we do not do any auto-configure stuff, so we will
1174 * just quietly ignore any requests to change irq, etc.
1177 static int stl_setserial(struct tty_struct
*tty
, struct serial_struct __user
*sp
)
1179 struct stlport
* portp
= tty
->driver_data
;
1180 struct serial_struct sio
;
1182 pr_debug("stl_setserial(portp=%p,sp=%p)\n", portp
, sp
);
1184 if (copy_from_user(&sio
, sp
, sizeof(struct serial_struct
)))
1186 if (!capable(CAP_SYS_ADMIN
)) {
1187 if ((sio
.baud_base
!= portp
->baud_base
) ||
1188 (sio
.close_delay
!= portp
->close_delay
) ||
1189 ((sio
.flags
& ~ASYNC_USR_MASK
) !=
1190 (portp
->port
.flags
& ~ASYNC_USR_MASK
)))
1194 portp
->port
.flags
= (portp
->port
.flags
& ~ASYNC_USR_MASK
) |
1195 (sio
.flags
& ASYNC_USR_MASK
);
1196 portp
->baud_base
= sio
.baud_base
;
1197 portp
->close_delay
= sio
.close_delay
;
1198 portp
->closing_wait
= sio
.closing_wait
;
1199 portp
->custom_divisor
= sio
.custom_divisor
;
1200 stl_setport(portp
, tty
->termios
);
1204 /*****************************************************************************/
1206 static int stl_tiocmget(struct tty_struct
*tty
, struct file
*file
)
1208 struct stlport
*portp
;
1210 portp
= tty
->driver_data
;
1213 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1216 return stl_getsignals(portp
);
1219 static int stl_tiocmset(struct tty_struct
*tty
, struct file
*file
,
1220 unsigned int set
, unsigned int clear
)
1222 struct stlport
*portp
;
1223 int rts
= -1, dtr
= -1;
1225 portp
= tty
->driver_data
;
1228 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1231 if (set
& TIOCM_RTS
)
1233 if (set
& TIOCM_DTR
)
1235 if (clear
& TIOCM_RTS
)
1237 if (clear
& TIOCM_DTR
)
1240 stl_setsignals(portp
, dtr
, rts
);
1244 static int stl_ioctl(struct tty_struct
*tty
, struct file
*file
, unsigned int cmd
, unsigned long arg
)
1246 struct stlport
*portp
;
1248 void __user
*argp
= (void __user
*)arg
;
1250 pr_debug("stl_ioctl(tty=%p,file=%p,cmd=%x,arg=%lx)\n", tty
, file
, cmd
,
1253 portp
= tty
->driver_data
;
1257 if ((cmd
!= TIOCGSERIAL
) && (cmd
!= TIOCSSERIAL
) &&
1258 (cmd
!= COM_GETPORTSTATS
) && (cmd
!= COM_CLRPORTSTATS
))
1259 if (tty
->flags
& (1 << TTY_IO_ERROR
))
1268 rc
= stl_getserial(portp
, argp
);
1271 rc
= stl_setserial(tty
, argp
);
1273 case COM_GETPORTSTATS
:
1274 rc
= stl_getportstats(tty
, portp
, argp
);
1276 case COM_CLRPORTSTATS
:
1277 rc
= stl_clrportstats(portp
, argp
);
1283 case TIOCSERGSTRUCT
:
1284 case TIOCSERGETMULTI
:
1285 case TIOCSERSETMULTI
:
1294 /*****************************************************************************/
1297 * Start the transmitter again. Just turn TX interrupts back on.
1300 static void stl_start(struct tty_struct
*tty
)
1302 struct stlport
*portp
;
1304 pr_debug("stl_start(tty=%p)\n", tty
);
1306 portp
= tty
->driver_data
;
1309 stl_startrxtx(portp
, -1, 1);
1312 /*****************************************************************************/
1314 static void stl_settermios(struct tty_struct
*tty
, struct ktermios
*old
)
1316 struct stlport
*portp
;
1317 struct ktermios
*tiosp
;
1319 pr_debug("stl_settermios(tty=%p,old=%p)\n", tty
, old
);
1321 portp
= tty
->driver_data
;
1325 tiosp
= tty
->termios
;
1326 if ((tiosp
->c_cflag
== old
->c_cflag
) &&
1327 (tiosp
->c_iflag
== old
->c_iflag
))
1330 stl_setport(portp
, tiosp
);
1331 stl_setsignals(portp
, ((tiosp
->c_cflag
& (CBAUD
& ~CBAUDEX
)) ? 1 : 0),
1333 if ((old
->c_cflag
& CRTSCTS
) && ((tiosp
->c_cflag
& CRTSCTS
) == 0)) {
1334 tty
->hw_stopped
= 0;
1337 if (((old
->c_cflag
& CLOCAL
) == 0) && (tiosp
->c_cflag
& CLOCAL
))
1338 wake_up_interruptible(&portp
->port
.open_wait
);
1341 /*****************************************************************************/
1344 * Attempt to flow control who ever is sending us data. Based on termios
1345 * settings use software or/and hardware flow control.
1348 static void stl_throttle(struct tty_struct
*tty
)
1350 struct stlport
*portp
;
1352 pr_debug("stl_throttle(tty=%p)\n", tty
);
1354 portp
= tty
->driver_data
;
1357 stl_flowctrl(portp
, 0);
1360 /*****************************************************************************/
1363 * Unflow control the device sending us data...
1366 static void stl_unthrottle(struct tty_struct
*tty
)
1368 struct stlport
*portp
;
1370 pr_debug("stl_unthrottle(tty=%p)\n", tty
);
1372 portp
= tty
->driver_data
;
1375 stl_flowctrl(portp
, 1);
1378 /*****************************************************************************/
1381 * Stop the transmitter. Basically to do this we will just turn TX
1385 static void stl_stop(struct tty_struct
*tty
)
1387 struct stlport
*portp
;
1389 pr_debug("stl_stop(tty=%p)\n", tty
);
1391 portp
= tty
->driver_data
;
1394 stl_startrxtx(portp
, -1, 0);
1397 /*****************************************************************************/
1400 * Hangup this port. This is pretty much like closing the port, only
1401 * a little more brutal. No waiting for data to drain. Shutdown the
1402 * port and maybe drop signals.
1405 static void stl_hangup(struct tty_struct
*tty
)
1407 struct stlport
*portp
;
1409 pr_debug("stl_hangup(tty=%p)\n", tty
);
1411 portp
= tty
->driver_data
;
1415 portp
->port
.flags
&= ~ASYNC_INITIALIZED
;
1416 stl_disableintrs(portp
);
1417 if (tty
->termios
->c_cflag
& HUPCL
)
1418 stl_setsignals(portp
, 0, 0);
1419 stl_enablerxtx(portp
, 0, 0);
1420 stl_flushbuffer(tty
);
1422 set_bit(TTY_IO_ERROR
, &tty
->flags
);
1423 if (portp
->tx
.buf
!= NULL
) {
1424 kfree(portp
->tx
.buf
);
1425 portp
->tx
.buf
= NULL
;
1426 portp
->tx
.head
= NULL
;
1427 portp
->tx
.tail
= NULL
;
1429 tty_port_tty_set(&portp
->port
, NULL
);
1430 portp
->port
.flags
&= ~ASYNC_NORMAL_ACTIVE
;
1431 portp
->port
.count
= 0;
1432 wake_up_interruptible(&portp
->port
.open_wait
);
1435 /*****************************************************************************/
1437 static int stl_breakctl(struct tty_struct
*tty
, int state
)
1439 struct stlport
*portp
;
1441 pr_debug("stl_breakctl(tty=%p,state=%d)\n", tty
, state
);
1443 portp
= tty
->driver_data
;
1447 stl_sendbreak(portp
, ((state
== -1) ? 1 : 2));
1451 /*****************************************************************************/
1453 static void stl_sendxchar(struct tty_struct
*tty
, char ch
)
1455 struct stlport
*portp
;
1457 pr_debug("stl_sendxchar(tty=%p,ch=%x)\n", tty
, ch
);
1459 portp
= tty
->driver_data
;
1463 if (ch
== STOP_CHAR(tty
))
1464 stl_sendflow(portp
, 0);
1465 else if (ch
== START_CHAR(tty
))
1466 stl_sendflow(portp
, 1);
1468 stl_putchar(tty
, ch
);
1471 /*****************************************************************************/
1476 * Format info for a specified port. The line is deliberately limited
1477 * to 80 characters. (If it is too long it will be truncated, if too
1478 * short then padded with spaces).
1481 static int stl_portinfo(struct stlport
*portp
, int portnr
, char *pos
)
1487 sp
+= sprintf(sp
, "%d: uart:%s tx:%d rx:%d",
1488 portnr
, (portp
->hwid
== 1) ? "SC26198" : "CD1400",
1489 (int) portp
->stats
.txtotal
, (int) portp
->stats
.rxtotal
);
1491 if (portp
->stats
.rxframing
)
1492 sp
+= sprintf(sp
, " fe:%d", (int) portp
->stats
.rxframing
);
1493 if (portp
->stats
.rxparity
)
1494 sp
+= sprintf(sp
, " pe:%d", (int) portp
->stats
.rxparity
);
1495 if (portp
->stats
.rxbreaks
)
1496 sp
+= sprintf(sp
, " brk:%d", (int) portp
->stats
.rxbreaks
);
1497 if (portp
->stats
.rxoverrun
)
1498 sp
+= sprintf(sp
, " oe:%d", (int) portp
->stats
.rxoverrun
);
1500 sigs
= stl_getsignals(portp
);
1501 cnt
= sprintf(sp
, "%s%s%s%s%s ",
1502 (sigs
& TIOCM_RTS
) ? "|RTS" : "",
1503 (sigs
& TIOCM_CTS
) ? "|CTS" : "",
1504 (sigs
& TIOCM_DTR
) ? "|DTR" : "",
1505 (sigs
& TIOCM_CD
) ? "|DCD" : "",
1506 (sigs
& TIOCM_DSR
) ? "|DSR" : "");
1510 for (cnt
= sp
- pos
; cnt
< (MAXLINE
- 1); cnt
++)
1513 pos
[(MAXLINE
- 2)] = '+';
1514 pos
[(MAXLINE
- 1)] = '\n';
1519 /*****************************************************************************/
1522 * Port info, read from the /proc file system.
1525 static int stl_readproc(char *page
, char **start
, off_t off
, int count
, int *eof
, void *data
)
1527 struct stlbrd
*brdp
;
1528 struct stlpanel
*panelp
;
1529 struct stlport
*portp
;
1530 unsigned int brdnr
, panelnr
, portnr
;
1531 int totalport
, curoff
, maxoff
;
1534 pr_debug("stl_readproc(page=%p,start=%p,off=%lx,count=%d,eof=%p,"
1535 "data=%p\n", page
, start
, off
, count
, eof
, data
);
1542 pos
+= sprintf(pos
, "%s: version %s", stl_drvtitle
,
1544 while (pos
< (page
+ MAXLINE
- 1))
1551 * We scan through for each board, panel and port. The offset is
1552 * calculated on the fly, and irrelevant ports are skipped.
1554 for (brdnr
= 0; brdnr
< stl_nrbrds
; brdnr
++) {
1555 brdp
= stl_brds
[brdnr
];
1558 if (brdp
->state
== 0)
1561 maxoff
= curoff
+ (brdp
->nrports
* MAXLINE
);
1562 if (off
>= maxoff
) {
1567 totalport
= brdnr
* STL_MAXPORTS
;
1568 for (panelnr
= 0; panelnr
< brdp
->nrpanels
; panelnr
++) {
1569 panelp
= brdp
->panels
[panelnr
];
1573 maxoff
= curoff
+ (panelp
->nrports
* MAXLINE
);
1574 if (off
>= maxoff
) {
1576 totalport
+= panelp
->nrports
;
1580 for (portnr
= 0; portnr
< panelp
->nrports
; portnr
++,
1582 portp
= panelp
->ports
[portnr
];
1585 if (off
>= (curoff
+= MAXLINE
))
1587 if ((pos
- page
+ MAXLINE
) > count
)
1589 pos
+= stl_portinfo(portp
, totalport
, pos
);
1601 /*****************************************************************************/
1604 * All board interrupts are vectored through here first. This code then
1605 * calls off to the approrpriate board interrupt handlers.
1608 static irqreturn_t
stl_intr(int irq
, void *dev_id
)
1610 struct stlbrd
*brdp
= dev_id
;
1612 pr_debug("stl_intr(brdp=%p,irq=%d)\n", brdp
, brdp
->irq
);
1614 return IRQ_RETVAL((* brdp
->isr
)(brdp
));
1617 /*****************************************************************************/
1620 * Interrupt service routine for EasyIO board types.
1623 static int stl_eiointr(struct stlbrd
*brdp
)
1625 struct stlpanel
*panelp
;
1626 unsigned int iobase
;
1629 spin_lock(&brd_lock
);
1630 panelp
= brdp
->panels
[0];
1631 iobase
= panelp
->iobase
;
1632 while (inb(brdp
->iostatus
) & EIO_INTRPEND
) {
1634 (* panelp
->isr
)(panelp
, iobase
);
1636 spin_unlock(&brd_lock
);
1640 /*****************************************************************************/
1643 * Interrupt service routine for ECH-AT board types.
1646 static int stl_echatintr(struct stlbrd
*brdp
)
1648 struct stlpanel
*panelp
;
1649 unsigned int ioaddr
, bnknr
;
1652 outb((brdp
->ioctrlval
| ECH_BRDENABLE
), brdp
->ioctrl
);
1654 while (inb(brdp
->iostatus
) & ECH_INTRPEND
) {
1656 for (bnknr
= 0; bnknr
< brdp
->nrbnks
; bnknr
++) {
1657 ioaddr
= brdp
->bnkstataddr
[bnknr
];
1658 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
1659 panelp
= brdp
->bnk2panel
[bnknr
];
1660 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
1665 outb((brdp
->ioctrlval
| ECH_BRDDISABLE
), brdp
->ioctrl
);
1670 /*****************************************************************************/
1673 * Interrupt service routine for ECH-MCA board types.
1676 static int stl_echmcaintr(struct stlbrd
*brdp
)
1678 struct stlpanel
*panelp
;
1679 unsigned int ioaddr
, bnknr
;
1682 while (inb(brdp
->iostatus
) & ECH_INTRPEND
) {
1684 for (bnknr
= 0; bnknr
< brdp
->nrbnks
; bnknr
++) {
1685 ioaddr
= brdp
->bnkstataddr
[bnknr
];
1686 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
1687 panelp
= brdp
->bnk2panel
[bnknr
];
1688 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
1695 /*****************************************************************************/
1698 * Interrupt service routine for ECH-PCI board types.
1701 static int stl_echpciintr(struct stlbrd
*brdp
)
1703 struct stlpanel
*panelp
;
1704 unsigned int ioaddr
, bnknr
, recheck
;
1709 for (bnknr
= 0; bnknr
< brdp
->nrbnks
; bnknr
++) {
1710 outb(brdp
->bnkpageaddr
[bnknr
], brdp
->ioctrl
);
1711 ioaddr
= brdp
->bnkstataddr
[bnknr
];
1712 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
1713 panelp
= brdp
->bnk2panel
[bnknr
];
1714 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
1725 /*****************************************************************************/
1728 * Interrupt service routine for ECH-8/64-PCI board types.
1731 static int stl_echpci64intr(struct stlbrd
*brdp
)
1733 struct stlpanel
*panelp
;
1734 unsigned int ioaddr
, bnknr
;
1737 while (inb(brdp
->ioctrl
) & 0x1) {
1739 for (bnknr
= 0; bnknr
< brdp
->nrbnks
; bnknr
++) {
1740 ioaddr
= brdp
->bnkstataddr
[bnknr
];
1741 if (inb(ioaddr
) & ECH_PNLINTRPEND
) {
1742 panelp
= brdp
->bnk2panel
[bnknr
];
1743 (* panelp
->isr
)(panelp
, (ioaddr
& 0xfffc));
1751 /*****************************************************************************/
1754 * Initialize all the ports on a panel.
1757 static int __devinit
stl_initports(struct stlbrd
*brdp
, struct stlpanel
*panelp
)
1759 struct stlport
*portp
;
1763 pr_debug("stl_initports(brdp=%p,panelp=%p)\n", brdp
, panelp
);
1765 chipmask
= stl_panelinit(brdp
, panelp
);
1768 * All UART's are initialized (if found!). Now go through and setup
1769 * each ports data structures.
1771 for (i
= 0; i
< panelp
->nrports
; i
++) {
1772 portp
= kzalloc(sizeof(struct stlport
), GFP_KERNEL
);
1774 printk("STALLION: failed to allocate memory "
1775 "(size=%Zd)\n", sizeof(struct stlport
));
1778 tty_port_init(&portp
->port
);
1779 portp
->magic
= STL_PORTMAGIC
;
1781 portp
->brdnr
= panelp
->brdnr
;
1782 portp
->panelnr
= panelp
->panelnr
;
1783 portp
->uartp
= panelp
->uartp
;
1784 portp
->clk
= brdp
->clk
;
1785 portp
->baud_base
= STL_BAUDBASE
;
1786 portp
->close_delay
= STL_CLOSEDELAY
;
1787 portp
->closing_wait
= 30 * HZ
;
1788 init_waitqueue_head(&portp
->port
.open_wait
);
1789 init_waitqueue_head(&portp
->port
.close_wait
);
1790 portp
->stats
.brd
= portp
->brdnr
;
1791 portp
->stats
.panel
= portp
->panelnr
;
1792 portp
->stats
.port
= portp
->portnr
;
1793 panelp
->ports
[i
] = portp
;
1794 stl_portinit(brdp
, panelp
, portp
);
1800 static void stl_cleanup_panels(struct stlbrd
*brdp
)
1802 struct stlpanel
*panelp
;
1803 struct stlport
*portp
;
1805 struct tty_struct
*tty
;
1807 for (j
= 0; j
< STL_MAXPANELS
; j
++) {
1808 panelp
= brdp
->panels
[j
];
1811 for (k
= 0; k
< STL_PORTSPERPANEL
; k
++) {
1812 portp
= panelp
->ports
[k
];
1815 tty
= tty_port_tty_get(&portp
->port
);
1820 kfree(portp
->tx
.buf
);
1827 /*****************************************************************************/
1830 * Try to find and initialize an EasyIO board.
1833 static int __devinit
stl_initeio(struct stlbrd
*brdp
)
1835 struct stlpanel
*panelp
;
1836 unsigned int status
;
1840 pr_debug("stl_initeio(brdp=%p)\n", brdp
);
1842 brdp
->ioctrl
= brdp
->ioaddr1
+ 1;
1843 brdp
->iostatus
= brdp
->ioaddr1
+ 2;
1845 status
= inb(brdp
->iostatus
);
1846 if ((status
& EIO_IDBITMASK
) == EIO_MK3
)
1850 * Handle board specific stuff now. The real difference is PCI
1853 if (brdp
->brdtype
== BRD_EASYIOPCI
) {
1854 brdp
->iosize1
= 0x80;
1855 brdp
->iosize2
= 0x80;
1856 name
= "serial(EIO-PCI)";
1857 outb(0x41, (brdp
->ioaddr2
+ 0x4c));
1860 name
= "serial(EIO)";
1861 if ((brdp
->irq
< 0) || (brdp
->irq
> 15) ||
1862 (stl_vecmap
[brdp
->irq
] == (unsigned char) 0xff)) {
1863 printk("STALLION: invalid irq=%d for brd=%d\n",
1864 brdp
->irq
, brdp
->brdnr
);
1868 outb((stl_vecmap
[brdp
->irq
] | EIO_0WS
|
1869 ((brdp
->irqtype
) ? EIO_INTLEVEL
: EIO_INTEDGE
)),
1874 if (!request_region(brdp
->ioaddr1
, brdp
->iosize1
, name
)) {
1875 printk(KERN_WARNING
"STALLION: Warning, board %d I/O address "
1876 "%x conflicts with another device\n", brdp
->brdnr
,
1881 if (brdp
->iosize2
> 0)
1882 if (!request_region(brdp
->ioaddr2
, brdp
->iosize2
, name
)) {
1883 printk(KERN_WARNING
"STALLION: Warning, board %d I/O "
1884 "address %x conflicts with another device\n",
1885 brdp
->brdnr
, brdp
->ioaddr2
);
1886 printk(KERN_WARNING
"STALLION: Warning, also "
1887 "releasing board %d I/O address %x \n",
1888 brdp
->brdnr
, brdp
->ioaddr1
);
1893 * Everything looks OK, so let's go ahead and probe for the hardware.
1895 brdp
->clk
= CD1400_CLK
;
1896 brdp
->isr
= stl_eiointr
;
1899 switch (status
& EIO_IDBITMASK
) {
1901 brdp
->clk
= CD1400_CLK8M
;
1911 switch (status
& EIO_BRDMASK
) {
1930 * We have verified that the board is actually present, so now we
1931 * can complete the setup.
1934 panelp
= kzalloc(sizeof(struct stlpanel
), GFP_KERNEL
);
1936 printk(KERN_WARNING
"STALLION: failed to allocate memory "
1937 "(size=%Zd)\n", sizeof(struct stlpanel
));
1942 panelp
->magic
= STL_PANELMAGIC
;
1943 panelp
->brdnr
= brdp
->brdnr
;
1944 panelp
->panelnr
= 0;
1945 panelp
->nrports
= brdp
->nrports
;
1946 panelp
->iobase
= brdp
->ioaddr1
;
1947 panelp
->hwid
= status
;
1948 if ((status
& EIO_IDBITMASK
) == EIO_MK3
) {
1949 panelp
->uartp
= &stl_sc26198uart
;
1950 panelp
->isr
= stl_sc26198intr
;
1952 panelp
->uartp
= &stl_cd1400uart
;
1953 panelp
->isr
= stl_cd1400eiointr
;
1956 brdp
->panels
[0] = panelp
;
1958 brdp
->state
|= BRD_FOUND
;
1959 brdp
->hwid
= status
;
1960 if (request_irq(brdp
->irq
, stl_intr
, IRQF_SHARED
, name
, brdp
) != 0) {
1961 printk("STALLION: failed to register interrupt "
1962 "routine for %s irq=%d\n", name
, brdp
->irq
);
1969 stl_cleanup_panels(brdp
);
1971 if (brdp
->iosize2
> 0)
1972 release_region(brdp
->ioaddr2
, brdp
->iosize2
);
1974 release_region(brdp
->ioaddr1
, brdp
->iosize1
);
1979 /*****************************************************************************/
1982 * Try to find an ECH board and initialize it. This code is capable of
1983 * dealing with all types of ECH board.
1986 static int __devinit
stl_initech(struct stlbrd
*brdp
)
1988 struct stlpanel
*panelp
;
1989 unsigned int status
, nxtid
, ioaddr
, conflict
, panelnr
, banknr
, i
;
1993 pr_debug("stl_initech(brdp=%p)\n", brdp
);
1999 * Set up the initial board register contents for boards. This varies a
2000 * bit between the different board types. So we need to handle each
2001 * separately. Also do a check that the supplied IRQ is good.
2003 switch (brdp
->brdtype
) {
2006 brdp
->isr
= stl_echatintr
;
2007 brdp
->ioctrl
= brdp
->ioaddr1
+ 1;
2008 brdp
->iostatus
= brdp
->ioaddr1
+ 1;
2009 status
= inb(brdp
->iostatus
);
2010 if ((status
& ECH_IDBITMASK
) != ECH_ID
) {
2014 if ((brdp
->irq
< 0) || (brdp
->irq
> 15) ||
2015 (stl_vecmap
[brdp
->irq
] == (unsigned char) 0xff)) {
2016 printk("STALLION: invalid irq=%d for brd=%d\n",
2017 brdp
->irq
, brdp
->brdnr
);
2021 status
= ((brdp
->ioaddr2
& ECH_ADDR2MASK
) >> 1);
2022 status
|= (stl_vecmap
[brdp
->irq
] << 1);
2023 outb((status
| ECH_BRDRESET
), brdp
->ioaddr1
);
2024 brdp
->ioctrlval
= ECH_INTENABLE
|
2025 ((brdp
->irqtype
) ? ECH_INTLEVEL
: ECH_INTEDGE
);
2026 for (i
= 0; i
< 10; i
++)
2027 outb((brdp
->ioctrlval
| ECH_BRDENABLE
), brdp
->ioctrl
);
2030 name
= "serial(EC8/32)";
2031 outb(status
, brdp
->ioaddr1
);
2035 brdp
->isr
= stl_echmcaintr
;
2036 brdp
->ioctrl
= brdp
->ioaddr1
+ 0x20;
2037 brdp
->iostatus
= brdp
->ioctrl
;
2038 status
= inb(brdp
->iostatus
);
2039 if ((status
& ECH_IDBITMASK
) != ECH_ID
) {
2043 if ((brdp
->irq
< 0) || (brdp
->irq
> 15) ||
2044 (stl_vecmap
[brdp
->irq
] == (unsigned char) 0xff)) {
2045 printk("STALLION: invalid irq=%d for brd=%d\n",
2046 brdp
->irq
, brdp
->brdnr
);
2050 outb(ECHMC_BRDRESET
, brdp
->ioctrl
);
2051 outb(ECHMC_INTENABLE
, brdp
->ioctrl
);
2053 name
= "serial(EC8/32-MC)";
2057 brdp
->isr
= stl_echpciintr
;
2058 brdp
->ioctrl
= brdp
->ioaddr1
+ 2;
2061 name
= "serial(EC8/32-PCI)";
2065 brdp
->isr
= stl_echpci64intr
;
2066 brdp
->ioctrl
= brdp
->ioaddr2
+ 0x40;
2067 outb(0x43, (brdp
->ioaddr1
+ 0x4c));
2068 brdp
->iosize1
= 0x80;
2069 brdp
->iosize2
= 0x80;
2070 name
= "serial(EC8/64-PCI)";
2074 printk("STALLION: unknown board type=%d\n", brdp
->brdtype
);
2080 * Check boards for possible IO address conflicts and return fail status
2081 * if an IO conflict found.
2084 if (!request_region(brdp
->ioaddr1
, brdp
->iosize1
, name
)) {
2085 printk(KERN_WARNING
"STALLION: Warning, board %d I/O address "
2086 "%x conflicts with another device\n", brdp
->brdnr
,
2091 if (brdp
->iosize2
> 0)
2092 if (!request_region(brdp
->ioaddr2
, brdp
->iosize2
, name
)) {
2093 printk(KERN_WARNING
"STALLION: Warning, board %d I/O "
2094 "address %x conflicts with another device\n",
2095 brdp
->brdnr
, brdp
->ioaddr2
);
2096 printk(KERN_WARNING
"STALLION: Warning, also "
2097 "releasing board %d I/O address %x \n",
2098 brdp
->brdnr
, brdp
->ioaddr1
);
2103 * Scan through the secondary io address space looking for panels.
2104 * As we find'em allocate and initialize panel structures for each.
2106 brdp
->clk
= CD1400_CLK
;
2107 brdp
->hwid
= status
;
2109 ioaddr
= brdp
->ioaddr2
;
2114 for (i
= 0; i
< STL_MAXPANELS
; i
++) {
2115 if (brdp
->brdtype
== BRD_ECHPCI
) {
2116 outb(nxtid
, brdp
->ioctrl
);
2117 ioaddr
= brdp
->ioaddr2
;
2119 status
= inb(ioaddr
+ ECH_PNLSTATUS
);
2120 if ((status
& ECH_PNLIDMASK
) != nxtid
)
2122 panelp
= kzalloc(sizeof(struct stlpanel
), GFP_KERNEL
);
2124 printk("STALLION: failed to allocate memory "
2125 "(size=%Zd)\n", sizeof(struct stlpanel
));
2129 panelp
->magic
= STL_PANELMAGIC
;
2130 panelp
->brdnr
= brdp
->brdnr
;
2131 panelp
->panelnr
= panelnr
;
2132 panelp
->iobase
= ioaddr
;
2133 panelp
->pagenr
= nxtid
;
2134 panelp
->hwid
= status
;
2135 brdp
->bnk2panel
[banknr
] = panelp
;
2136 brdp
->bnkpageaddr
[banknr
] = nxtid
;
2137 brdp
->bnkstataddr
[banknr
++] = ioaddr
+ ECH_PNLSTATUS
;
2139 if (status
& ECH_PNLXPID
) {
2140 panelp
->uartp
= &stl_sc26198uart
;
2141 panelp
->isr
= stl_sc26198intr
;
2142 if (status
& ECH_PNL16PORT
) {
2143 panelp
->nrports
= 16;
2144 brdp
->bnk2panel
[banknr
] = panelp
;
2145 brdp
->bnkpageaddr
[banknr
] = nxtid
;
2146 brdp
->bnkstataddr
[banknr
++] = ioaddr
+ 4 +
2149 panelp
->nrports
= 8;
2151 panelp
->uartp
= &stl_cd1400uart
;
2152 panelp
->isr
= stl_cd1400echintr
;
2153 if (status
& ECH_PNL16PORT
) {
2154 panelp
->nrports
= 16;
2155 panelp
->ackmask
= 0x80;
2156 if (brdp
->brdtype
!= BRD_ECHPCI
)
2157 ioaddr
+= EREG_BANKSIZE
;
2158 brdp
->bnk2panel
[banknr
] = panelp
;
2159 brdp
->bnkpageaddr
[banknr
] = ++nxtid
;
2160 brdp
->bnkstataddr
[banknr
++] = ioaddr
+
2163 panelp
->nrports
= 8;
2164 panelp
->ackmask
= 0xc0;
2169 ioaddr
+= EREG_BANKSIZE
;
2170 brdp
->nrports
+= panelp
->nrports
;
2171 brdp
->panels
[panelnr
++] = panelp
;
2172 if ((brdp
->brdtype
!= BRD_ECHPCI
) &&
2173 (ioaddr
>= (brdp
->ioaddr2
+ brdp
->iosize2
))) {
2179 brdp
->nrpanels
= panelnr
;
2180 brdp
->nrbnks
= banknr
;
2181 if (brdp
->brdtype
== BRD_ECH
)
2182 outb((brdp
->ioctrlval
| ECH_BRDDISABLE
), brdp
->ioctrl
);
2184 brdp
->state
|= BRD_FOUND
;
2185 if (request_irq(brdp
->irq
, stl_intr
, IRQF_SHARED
, name
, brdp
) != 0) {
2186 printk("STALLION: failed to register interrupt "
2187 "routine for %s irq=%d\n", name
, brdp
->irq
);
2194 stl_cleanup_panels(brdp
);
2195 if (brdp
->iosize2
> 0)
2196 release_region(brdp
->ioaddr2
, brdp
->iosize2
);
2198 release_region(brdp
->ioaddr1
, brdp
->iosize1
);
2203 /*****************************************************************************/
2206 * Initialize and configure the specified board.
2207 * Scan through all the boards in the configuration and see what we
2208 * can find. Handle EIO and the ECH boards a little differently here
2209 * since the initial search and setup is very different.
2212 static int __devinit
stl_brdinit(struct stlbrd
*brdp
)
2216 pr_debug("stl_brdinit(brdp=%p)\n", brdp
);
2218 switch (brdp
->brdtype
) {
2221 retval
= stl_initeio(brdp
);
2229 retval
= stl_initech(brdp
);
2234 printk("STALLION: board=%d is unknown board type=%d\n",
2235 brdp
->brdnr
, brdp
->brdtype
);
2240 if ((brdp
->state
& BRD_FOUND
) == 0) {
2241 printk("STALLION: %s board not found, board=%d io=%x irq=%d\n",
2242 stl_brdnames
[brdp
->brdtype
], brdp
->brdnr
,
2243 brdp
->ioaddr1
, brdp
->irq
);
2247 for (i
= 0; i
< STL_MAXPANELS
; i
++)
2248 if (brdp
->panels
[i
] != NULL
)
2249 stl_initports(brdp
, brdp
->panels
[i
]);
2251 printk("STALLION: %s found, board=%d io=%x irq=%d "
2252 "nrpanels=%d nrports=%d\n", stl_brdnames
[brdp
->brdtype
],
2253 brdp
->brdnr
, brdp
->ioaddr1
, brdp
->irq
, brdp
->nrpanels
,
2258 free_irq(brdp
->irq
, brdp
);
2260 stl_cleanup_panels(brdp
);
2262 release_region(brdp
->ioaddr1
, brdp
->iosize1
);
2263 if (brdp
->iosize2
> 0)
2264 release_region(brdp
->ioaddr2
, brdp
->iosize2
);
2269 /*****************************************************************************/
2272 * Find the next available board number that is free.
2275 static int __devinit
stl_getbrdnr(void)
2279 for (i
= 0; i
< STL_MAXBRDS
; i
++)
2280 if (stl_brds
[i
] == NULL
) {
2281 if (i
>= stl_nrbrds
)
2289 /*****************************************************************************/
2291 * We have a Stallion board. Allocate a board structure and
2292 * initialize it. Read its IO and IRQ resources from PCI
2293 * configuration space.
2296 static int __devinit
stl_pciprobe(struct pci_dev
*pdev
,
2297 const struct pci_device_id
*ent
)
2299 struct stlbrd
*brdp
;
2300 unsigned int i
, brdtype
= ent
->driver_data
;
2301 int brdnr
, retval
= -ENODEV
;
2303 if ((pdev
->class >> 8) == PCI_CLASS_STORAGE_IDE
)
2306 retval
= pci_enable_device(pdev
);
2309 brdp
= stl_allocbrd();
2314 mutex_lock(&stl_brdslock
);
2315 brdnr
= stl_getbrdnr();
2317 dev_err(&pdev
->dev
, "too many boards found, "
2318 "maximum supported %d\n", STL_MAXBRDS
);
2319 mutex_unlock(&stl_brdslock
);
2323 brdp
->brdnr
= (unsigned int)brdnr
;
2324 stl_brds
[brdp
->brdnr
] = brdp
;
2325 mutex_unlock(&stl_brdslock
);
2327 brdp
->brdtype
= brdtype
;
2328 brdp
->state
|= STL_PROBED
;
2331 * We have all resources from the board, so let's setup the actual
2332 * board structure now.
2336 brdp
->ioaddr2
= pci_resource_start(pdev
, 0);
2337 brdp
->ioaddr1
= pci_resource_start(pdev
, 1);
2340 brdp
->ioaddr2
= pci_resource_start(pdev
, 2);
2341 brdp
->ioaddr1
= pci_resource_start(pdev
, 1);
2344 brdp
->ioaddr1
= pci_resource_start(pdev
, 2);
2345 brdp
->ioaddr2
= pci_resource_start(pdev
, 1);
2348 dev_err(&pdev
->dev
, "unknown PCI board type=%u\n", brdtype
);
2352 brdp
->irq
= pdev
->irq
;
2353 retval
= stl_brdinit(brdp
);
2357 pci_set_drvdata(pdev
, brdp
);
2359 for (i
= 0; i
< brdp
->nrports
; i
++)
2360 tty_register_device(stl_serial
,
2361 brdp
->brdnr
* STL_MAXPORTS
+ i
, &pdev
->dev
);
2365 stl_brds
[brdp
->brdnr
] = NULL
;
2372 static void __devexit
stl_pciremove(struct pci_dev
*pdev
)
2374 struct stlbrd
*brdp
= pci_get_drvdata(pdev
);
2377 free_irq(brdp
->irq
, brdp
);
2379 stl_cleanup_panels(brdp
);
2381 release_region(brdp
->ioaddr1
, brdp
->iosize1
);
2382 if (brdp
->iosize2
> 0)
2383 release_region(brdp
->ioaddr2
, brdp
->iosize2
);
2385 for (i
= 0; i
< brdp
->nrports
; i
++)
2386 tty_unregister_device(stl_serial
,
2387 brdp
->brdnr
* STL_MAXPORTS
+ i
);
2389 stl_brds
[brdp
->brdnr
] = NULL
;
2393 static struct pci_driver stl_pcidriver
= {
2395 .id_table
= stl_pcibrds
,
2396 .probe
= stl_pciprobe
,
2397 .remove
= __devexit_p(stl_pciremove
)
2400 /*****************************************************************************/
2403 * Return the board stats structure to user app.
2406 static int stl_getbrdstats(combrd_t __user
*bp
)
2408 combrd_t stl_brdstats
;
2409 struct stlbrd
*brdp
;
2410 struct stlpanel
*panelp
;
2413 if (copy_from_user(&stl_brdstats
, bp
, sizeof(combrd_t
)))
2415 if (stl_brdstats
.brd
>= STL_MAXBRDS
)
2417 brdp
= stl_brds
[stl_brdstats
.brd
];
2421 memset(&stl_brdstats
, 0, sizeof(combrd_t
));
2422 stl_brdstats
.brd
= brdp
->brdnr
;
2423 stl_brdstats
.type
= brdp
->brdtype
;
2424 stl_brdstats
.hwid
= brdp
->hwid
;
2425 stl_brdstats
.state
= brdp
->state
;
2426 stl_brdstats
.ioaddr
= brdp
->ioaddr1
;
2427 stl_brdstats
.ioaddr2
= brdp
->ioaddr2
;
2428 stl_brdstats
.irq
= brdp
->irq
;
2429 stl_brdstats
.nrpanels
= brdp
->nrpanels
;
2430 stl_brdstats
.nrports
= brdp
->nrports
;
2431 for (i
= 0; i
< brdp
->nrpanels
; i
++) {
2432 panelp
= brdp
->panels
[i
];
2433 stl_brdstats
.panels
[i
].panel
= i
;
2434 stl_brdstats
.panels
[i
].hwid
= panelp
->hwid
;
2435 stl_brdstats
.panels
[i
].nrports
= panelp
->nrports
;
2438 return copy_to_user(bp
, &stl_brdstats
, sizeof(combrd_t
)) ? -EFAULT
: 0;
2441 /*****************************************************************************/
2444 * Resolve the referenced port number into a port struct pointer.
2447 static struct stlport
*stl_getport(int brdnr
, int panelnr
, int portnr
)
2449 struct stlbrd
*brdp
;
2450 struct stlpanel
*panelp
;
2452 if (brdnr
< 0 || brdnr
>= STL_MAXBRDS
)
2454 brdp
= stl_brds
[brdnr
];
2457 if (panelnr
< 0 || (unsigned int)panelnr
>= brdp
->nrpanels
)
2459 panelp
= brdp
->panels
[panelnr
];
2462 if (portnr
< 0 || (unsigned int)portnr
>= panelp
->nrports
)
2464 return panelp
->ports
[portnr
];
2467 /*****************************************************************************/
2470 * Return the port stats structure to user app. A NULL port struct
2471 * pointer passed in means that we need to find out from the app
2472 * what port to get stats for (used through board control device).
2475 static int stl_getportstats(struct tty_struct
*tty
, struct stlport
*portp
, comstats_t __user
*cp
)
2477 comstats_t stl_comstats
;
2478 unsigned char *head
, *tail
;
2479 unsigned long flags
;
2482 if (copy_from_user(&stl_comstats
, cp
, sizeof(comstats_t
)))
2484 portp
= stl_getport(stl_comstats
.brd
, stl_comstats
.panel
,
2490 portp
->stats
.state
= portp
->istate
;
2491 portp
->stats
.flags
= portp
->port
.flags
;
2492 portp
->stats
.hwid
= portp
->hwid
;
2494 portp
->stats
.ttystate
= 0;
2495 portp
->stats
.cflags
= 0;
2496 portp
->stats
.iflags
= 0;
2497 portp
->stats
.oflags
= 0;
2498 portp
->stats
.lflags
= 0;
2499 portp
->stats
.rxbuffered
= 0;
2501 spin_lock_irqsave(&stallion_lock
, flags
);
2502 if (tty
!= NULL
&& portp
->port
.tty
== tty
) {
2503 portp
->stats
.ttystate
= tty
->flags
;
2504 /* No longer available as a statistic */
2505 portp
->stats
.rxbuffered
= 1; /*tty->flip.count; */
2506 if (tty
->termios
!= NULL
) {
2507 portp
->stats
.cflags
= tty
->termios
->c_cflag
;
2508 portp
->stats
.iflags
= tty
->termios
->c_iflag
;
2509 portp
->stats
.oflags
= tty
->termios
->c_oflag
;
2510 portp
->stats
.lflags
= tty
->termios
->c_lflag
;
2513 spin_unlock_irqrestore(&stallion_lock
, flags
);
2515 head
= portp
->tx
.head
;
2516 tail
= portp
->tx
.tail
;
2517 portp
->stats
.txbuffered
= (head
>= tail
) ? (head
- tail
) :
2518 (STL_TXBUFSIZE
- (tail
- head
));
2520 portp
->stats
.signals
= (unsigned long) stl_getsignals(portp
);
2522 return copy_to_user(cp
, &portp
->stats
,
2523 sizeof(comstats_t
)) ? -EFAULT
: 0;
2526 /*****************************************************************************/
2529 * Clear the port stats structure. We also return it zeroed out...
2532 static int stl_clrportstats(struct stlport
*portp
, comstats_t __user
*cp
)
2534 comstats_t stl_comstats
;
2537 if (copy_from_user(&stl_comstats
, cp
, sizeof(comstats_t
)))
2539 portp
= stl_getport(stl_comstats
.brd
, stl_comstats
.panel
,
2545 memset(&portp
->stats
, 0, sizeof(comstats_t
));
2546 portp
->stats
.brd
= portp
->brdnr
;
2547 portp
->stats
.panel
= portp
->panelnr
;
2548 portp
->stats
.port
= portp
->portnr
;
2549 return copy_to_user(cp
, &portp
->stats
,
2550 sizeof(comstats_t
)) ? -EFAULT
: 0;
2553 /*****************************************************************************/
2556 * Return the entire driver ports structure to a user app.
2559 static int stl_getportstruct(struct stlport __user
*arg
)
2561 struct stlport stl_dummyport
;
2562 struct stlport
*portp
;
2564 if (copy_from_user(&stl_dummyport
, arg
, sizeof(struct stlport
)))
2566 portp
= stl_getport(stl_dummyport
.brdnr
, stl_dummyport
.panelnr
,
2567 stl_dummyport
.portnr
);
2570 return copy_to_user(arg
, portp
, sizeof(struct stlport
)) ? -EFAULT
: 0;
2573 /*****************************************************************************/
2576 * Return the entire driver board structure to a user app.
2579 static int stl_getbrdstruct(struct stlbrd __user
*arg
)
2581 struct stlbrd stl_dummybrd
;
2582 struct stlbrd
*brdp
;
2584 if (copy_from_user(&stl_dummybrd
, arg
, sizeof(struct stlbrd
)))
2586 if (stl_dummybrd
.brdnr
>= STL_MAXBRDS
)
2588 brdp
= stl_brds
[stl_dummybrd
.brdnr
];
2591 return copy_to_user(arg
, brdp
, sizeof(struct stlbrd
)) ? -EFAULT
: 0;
2594 /*****************************************************************************/
2597 * The "staliomem" device is also required to do some special operations
2598 * on the board and/or ports. In this driver it is mostly used for stats
2602 static int stl_memioctl(struct inode
*ip
, struct file
*fp
, unsigned int cmd
, unsigned long arg
)
2605 void __user
*argp
= (void __user
*)arg
;
2607 pr_debug("stl_memioctl(ip=%p,fp=%p,cmd=%x,arg=%lx)\n", ip
, fp
, cmd
,arg
);
2610 if (brdnr
>= STL_MAXBRDS
)
2615 case COM_GETPORTSTATS
:
2616 rc
= stl_getportstats(NULL
, NULL
, argp
);
2618 case COM_CLRPORTSTATS
:
2619 rc
= stl_clrportstats(NULL
, argp
);
2621 case COM_GETBRDSTATS
:
2622 rc
= stl_getbrdstats(argp
);
2625 rc
= stl_getportstruct(argp
);
2628 rc
= stl_getbrdstruct(argp
);
2638 static const struct tty_operations stl_ops
= {
2642 .put_char
= stl_putchar
,
2643 .flush_chars
= stl_flushchars
,
2644 .write_room
= stl_writeroom
,
2645 .chars_in_buffer
= stl_charsinbuffer
,
2647 .set_termios
= stl_settermios
,
2648 .throttle
= stl_throttle
,
2649 .unthrottle
= stl_unthrottle
,
2652 .hangup
= stl_hangup
,
2653 .flush_buffer
= stl_flushbuffer
,
2654 .break_ctl
= stl_breakctl
,
2655 .wait_until_sent
= stl_waituntilsent
,
2656 .send_xchar
= stl_sendxchar
,
2657 .read_proc
= stl_readproc
,
2658 .tiocmget
= stl_tiocmget
,
2659 .tiocmset
= stl_tiocmset
,
2662 /*****************************************************************************/
2663 /* CD1400 HARDWARE FUNCTIONS */
2664 /*****************************************************************************/
2667 * These functions get/set/update the registers of the cd1400 UARTs.
2668 * Access to the cd1400 registers is via an address/data io port pair.
2669 * (Maybe should make this inline...)
2672 static int stl_cd1400getreg(struct stlport
*portp
, int regnr
)
2674 outb((regnr
+ portp
->uartaddr
), portp
->ioaddr
);
2675 return inb(portp
->ioaddr
+ EREG_DATA
);
2678 static void stl_cd1400setreg(struct stlport
*portp
, int regnr
, int value
)
2680 outb(regnr
+ portp
->uartaddr
, portp
->ioaddr
);
2681 outb(value
, portp
->ioaddr
+ EREG_DATA
);
2684 static int stl_cd1400updatereg(struct stlport
*portp
, int regnr
, int value
)
2686 outb(regnr
+ portp
->uartaddr
, portp
->ioaddr
);
2687 if (inb(portp
->ioaddr
+ EREG_DATA
) != value
) {
2688 outb(value
, portp
->ioaddr
+ EREG_DATA
);
2694 /*****************************************************************************/
2697 * Inbitialize the UARTs in a panel. We don't care what sort of board
2698 * these ports are on - since the port io registers are almost
2699 * identical when dealing with ports.
2702 static int stl_cd1400panelinit(struct stlbrd
*brdp
, struct stlpanel
*panelp
)
2706 int nrchips
, uartaddr
, ioaddr
;
2707 unsigned long flags
;
2709 pr_debug("stl_panelinit(brdp=%p,panelp=%p)\n", brdp
, panelp
);
2711 spin_lock_irqsave(&brd_lock
, flags
);
2712 BRDENABLE(panelp
->brdnr
, panelp
->pagenr
);
2715 * Check that each chip is present and started up OK.
2718 nrchips
= panelp
->nrports
/ CD1400_PORTS
;
2719 for (i
= 0; i
< nrchips
; i
++) {
2720 if (brdp
->brdtype
== BRD_ECHPCI
) {
2721 outb((panelp
->pagenr
+ (i
>> 1)), brdp
->ioctrl
);
2722 ioaddr
= panelp
->iobase
;
2724 ioaddr
= panelp
->iobase
+ (EREG_BANKSIZE
* (i
>> 1));
2725 uartaddr
= (i
& 0x01) ? 0x080 : 0;
2726 outb((GFRCR
+ uartaddr
), ioaddr
);
2727 outb(0, (ioaddr
+ EREG_DATA
));
2728 outb((CCR
+ uartaddr
), ioaddr
);
2729 outb(CCR_RESETFULL
, (ioaddr
+ EREG_DATA
));
2730 outb(CCR_RESETFULL
, (ioaddr
+ EREG_DATA
));
2731 outb((GFRCR
+ uartaddr
), ioaddr
);
2732 for (j
= 0; j
< CCR_MAXWAIT
; j
++)
2733 if ((gfrcr
= inb(ioaddr
+ EREG_DATA
)) != 0)
2736 if ((j
>= CCR_MAXWAIT
) || (gfrcr
< 0x40) || (gfrcr
> 0x60)) {
2737 printk("STALLION: cd1400 not responding, "
2738 "brd=%d panel=%d chip=%d\n",
2739 panelp
->brdnr
, panelp
->panelnr
, i
);
2742 chipmask
|= (0x1 << i
);
2743 outb((PPR
+ uartaddr
), ioaddr
);
2744 outb(PPR_SCALAR
, (ioaddr
+ EREG_DATA
));
2747 BRDDISABLE(panelp
->brdnr
);
2748 spin_unlock_irqrestore(&brd_lock
, flags
);
2752 /*****************************************************************************/
2755 * Initialize hardware specific port registers.
2758 static void stl_cd1400portinit(struct stlbrd
*brdp
, struct stlpanel
*panelp
, struct stlport
*portp
)
2760 unsigned long flags
;
2761 pr_debug("stl_cd1400portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp
,
2764 if ((brdp
== NULL
) || (panelp
== NULL
) ||
2768 spin_lock_irqsave(&brd_lock
, flags
);
2769 portp
->ioaddr
= panelp
->iobase
+ (((brdp
->brdtype
== BRD_ECHPCI
) ||
2770 (portp
->portnr
< 8)) ? 0 : EREG_BANKSIZE
);
2771 portp
->uartaddr
= (portp
->portnr
& 0x04) << 5;
2772 portp
->pagenr
= panelp
->pagenr
+ (portp
->portnr
>> 3);
2774 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
2775 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
2776 stl_cd1400setreg(portp
, LIVR
, (portp
->portnr
<< 3));
2777 portp
->hwid
= stl_cd1400getreg(portp
, GFRCR
);
2778 BRDDISABLE(portp
->brdnr
);
2779 spin_unlock_irqrestore(&brd_lock
, flags
);
2782 /*****************************************************************************/
2785 * Wait for the command register to be ready. We will poll this,
2786 * since it won't usually take too long to be ready.
2789 static void stl_cd1400ccrwait(struct stlport
*portp
)
2793 for (i
= 0; i
< CCR_MAXWAIT
; i
++)
2794 if (stl_cd1400getreg(portp
, CCR
) == 0)
2797 printk("STALLION: cd1400 not responding, port=%d panel=%d brd=%d\n",
2798 portp
->portnr
, portp
->panelnr
, portp
->brdnr
);
2801 /*****************************************************************************/
2804 * Set up the cd1400 registers for a port based on the termios port
2808 static void stl_cd1400setport(struct stlport
*portp
, struct ktermios
*tiosp
)
2810 struct stlbrd
*brdp
;
2811 unsigned long flags
;
2812 unsigned int clkdiv
, baudrate
;
2813 unsigned char cor1
, cor2
, cor3
;
2814 unsigned char cor4
, cor5
, ccr
;
2815 unsigned char srer
, sreron
, sreroff
;
2816 unsigned char mcor1
, mcor2
, rtpr
;
2817 unsigned char clk
, div
;
2833 brdp
= stl_brds
[portp
->brdnr
];
2838 * Set up the RX char ignore mask with those RX error types we
2839 * can ignore. We can get the cd1400 to help us out a little here,
2840 * it will ignore parity errors and breaks for us.
2842 portp
->rxignoremsk
= 0;
2843 if (tiosp
->c_iflag
& IGNPAR
) {
2844 portp
->rxignoremsk
|= (ST_PARITY
| ST_FRAMING
| ST_OVERRUN
);
2845 cor1
|= COR1_PARIGNORE
;
2847 if (tiosp
->c_iflag
& IGNBRK
) {
2848 portp
->rxignoremsk
|= ST_BREAK
;
2849 cor4
|= COR4_IGNBRK
;
2852 portp
->rxmarkmsk
= ST_OVERRUN
;
2853 if (tiosp
->c_iflag
& (INPCK
| PARMRK
))
2854 portp
->rxmarkmsk
|= (ST_PARITY
| ST_FRAMING
);
2855 if (tiosp
->c_iflag
& BRKINT
)
2856 portp
->rxmarkmsk
|= ST_BREAK
;
2859 * Go through the char size, parity and stop bits and set all the
2860 * option register appropriately.
2862 switch (tiosp
->c_cflag
& CSIZE
) {
2877 if (tiosp
->c_cflag
& CSTOPB
)
2882 if (tiosp
->c_cflag
& PARENB
) {
2883 if (tiosp
->c_cflag
& PARODD
)
2884 cor1
|= (COR1_PARENB
| COR1_PARODD
);
2886 cor1
|= (COR1_PARENB
| COR1_PAREVEN
);
2888 cor1
|= COR1_PARNONE
;
2892 * Set the RX FIFO threshold at 6 chars. This gives a bit of breathing
2893 * space for hardware flow control and the like. This should be set to
2894 * VMIN. Also here we will set the RX data timeout to 10ms - this should
2895 * really be based on VTIME.
2897 cor3
|= FIFO_RXTHRESHOLD
;
2901 * Calculate the baud rate timers. For now we will just assume that
2902 * the input and output baud are the same. Could have used a baud
2903 * table here, but this way we can generate virtually any baud rate
2906 baudrate
= tiosp
->c_cflag
& CBAUD
;
2907 if (baudrate
& CBAUDEX
) {
2908 baudrate
&= ~CBAUDEX
;
2909 if ((baudrate
< 1) || (baudrate
> 4))
2910 tiosp
->c_cflag
&= ~CBAUDEX
;
2914 baudrate
= stl_baudrates
[baudrate
];
2915 if ((tiosp
->c_cflag
& CBAUD
) == B38400
) {
2916 if ((portp
->port
.flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
2918 else if ((portp
->port
.flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
2920 else if ((portp
->port
.flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
2922 else if ((portp
->port
.flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
2924 else if ((portp
->port
.flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)
2925 baudrate
= (portp
->baud_base
/ portp
->custom_divisor
);
2927 if (baudrate
> STL_CD1400MAXBAUD
)
2928 baudrate
= STL_CD1400MAXBAUD
;
2931 for (clk
= 0; clk
< CD1400_NUMCLKS
; clk
++) {
2932 clkdiv
= (portp
->clk
/ stl_cd1400clkdivs
[clk
]) / baudrate
;
2936 div
= (unsigned char) clkdiv
;
2940 * Check what form of modem signaling is required and set it up.
2942 if ((tiosp
->c_cflag
& CLOCAL
) == 0) {
2945 sreron
|= SRER_MODEM
;
2946 portp
->port
.flags
|= ASYNC_CHECK_CD
;
2948 portp
->port
.flags
&= ~ASYNC_CHECK_CD
;
2951 * Setup cd1400 enhanced modes if we can. In particular we want to
2952 * handle as much of the flow control as possible automatically. As
2953 * well as saving a few CPU cycles it will also greatly improve flow
2954 * control reliability.
2956 if (tiosp
->c_iflag
& IXON
) {
2959 if (tiosp
->c_iflag
& IXANY
)
2963 if (tiosp
->c_cflag
& CRTSCTS
) {
2965 mcor1
|= FIFO_RTSTHRESHOLD
;
2969 * All cd1400 register values calculated so go through and set
2973 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
2974 portp
->portnr
, portp
->panelnr
, portp
->brdnr
);
2975 pr_debug(" cor1=%x cor2=%x cor3=%x cor4=%x cor5=%x\n",
2976 cor1
, cor2
, cor3
, cor4
, cor5
);
2977 pr_debug(" mcor1=%x mcor2=%x rtpr=%x sreron=%x sreroff=%x\n",
2978 mcor1
, mcor2
, rtpr
, sreron
, sreroff
);
2979 pr_debug(" tcor=%x tbpr=%x rcor=%x rbpr=%x\n", clk
, div
, clk
, div
);
2980 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
2981 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
],
2982 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
]);
2984 spin_lock_irqsave(&brd_lock
, flags
);
2985 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
2986 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x3));
2987 srer
= stl_cd1400getreg(portp
, SRER
);
2988 stl_cd1400setreg(portp
, SRER
, 0);
2989 if (stl_cd1400updatereg(portp
, COR1
, cor1
))
2991 if (stl_cd1400updatereg(portp
, COR2
, cor2
))
2993 if (stl_cd1400updatereg(portp
, COR3
, cor3
))
2996 stl_cd1400ccrwait(portp
);
2997 stl_cd1400setreg(portp
, CCR
, CCR_CORCHANGE
);
2999 stl_cd1400setreg(portp
, COR4
, cor4
);
3000 stl_cd1400setreg(portp
, COR5
, cor5
);
3001 stl_cd1400setreg(portp
, MCOR1
, mcor1
);
3002 stl_cd1400setreg(portp
, MCOR2
, mcor2
);
3004 stl_cd1400setreg(portp
, TCOR
, clk
);
3005 stl_cd1400setreg(portp
, TBPR
, div
);
3006 stl_cd1400setreg(portp
, RCOR
, clk
);
3007 stl_cd1400setreg(portp
, RBPR
, div
);
3009 stl_cd1400setreg(portp
, SCHR1
, tiosp
->c_cc
[VSTART
]);
3010 stl_cd1400setreg(portp
, SCHR2
, tiosp
->c_cc
[VSTOP
]);
3011 stl_cd1400setreg(portp
, SCHR3
, tiosp
->c_cc
[VSTART
]);
3012 stl_cd1400setreg(portp
, SCHR4
, tiosp
->c_cc
[VSTOP
]);
3013 stl_cd1400setreg(portp
, RTPR
, rtpr
);
3014 mcor1
= stl_cd1400getreg(portp
, MSVR1
);
3015 if (mcor1
& MSVR1_DCD
)
3016 portp
->sigs
|= TIOCM_CD
;
3018 portp
->sigs
&= ~TIOCM_CD
;
3019 stl_cd1400setreg(portp
, SRER
, ((srer
& ~sreroff
) | sreron
));
3020 BRDDISABLE(portp
->brdnr
);
3021 spin_unlock_irqrestore(&brd_lock
, flags
);
3024 /*****************************************************************************/
3027 * Set the state of the DTR and RTS signals.
3030 static void stl_cd1400setsignals(struct stlport
*portp
, int dtr
, int rts
)
3032 unsigned char msvr1
, msvr2
;
3033 unsigned long flags
;
3035 pr_debug("stl_cd1400setsignals(portp=%p,dtr=%d,rts=%d)\n",
3045 spin_lock_irqsave(&brd_lock
, flags
);
3046 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3047 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3049 stl_cd1400setreg(portp
, MSVR2
, msvr2
);
3051 stl_cd1400setreg(portp
, MSVR1
, msvr1
);
3052 BRDDISABLE(portp
->brdnr
);
3053 spin_unlock_irqrestore(&brd_lock
, flags
);
3056 /*****************************************************************************/
3059 * Return the state of the signals.
3062 static int stl_cd1400getsignals(struct stlport
*portp
)
3064 unsigned char msvr1
, msvr2
;
3065 unsigned long flags
;
3068 pr_debug("stl_cd1400getsignals(portp=%p)\n", portp
);
3070 spin_lock_irqsave(&brd_lock
, flags
);
3071 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3072 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3073 msvr1
= stl_cd1400getreg(portp
, MSVR1
);
3074 msvr2
= stl_cd1400getreg(portp
, MSVR2
);
3075 BRDDISABLE(portp
->brdnr
);
3076 spin_unlock_irqrestore(&brd_lock
, flags
);
3079 sigs
|= (msvr1
& MSVR1_DCD
) ? TIOCM_CD
: 0;
3080 sigs
|= (msvr1
& MSVR1_CTS
) ? TIOCM_CTS
: 0;
3081 sigs
|= (msvr1
& MSVR1_DTR
) ? TIOCM_DTR
: 0;
3082 sigs
|= (msvr2
& MSVR2_RTS
) ? TIOCM_RTS
: 0;
3084 sigs
|= (msvr1
& MSVR1_RI
) ? TIOCM_RI
: 0;
3085 sigs
|= (msvr1
& MSVR1_DSR
) ? TIOCM_DSR
: 0;
3092 /*****************************************************************************/
3095 * Enable/Disable the Transmitter and/or Receiver.
3098 static void stl_cd1400enablerxtx(struct stlport
*portp
, int rx
, int tx
)
3101 unsigned long flags
;
3103 pr_debug("stl_cd1400enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp
, rx
, tx
);
3108 ccr
|= CCR_TXDISABLE
;
3110 ccr
|= CCR_TXENABLE
;
3112 ccr
|= CCR_RXDISABLE
;
3114 ccr
|= CCR_RXENABLE
;
3116 spin_lock_irqsave(&brd_lock
, flags
);
3117 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3118 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3119 stl_cd1400ccrwait(portp
);
3120 stl_cd1400setreg(portp
, CCR
, ccr
);
3121 stl_cd1400ccrwait(portp
);
3122 BRDDISABLE(portp
->brdnr
);
3123 spin_unlock_irqrestore(&brd_lock
, flags
);
3126 /*****************************************************************************/
3129 * Start/stop the Transmitter and/or Receiver.
3132 static void stl_cd1400startrxtx(struct stlport
*portp
, int rx
, int tx
)
3134 unsigned char sreron
, sreroff
;
3135 unsigned long flags
;
3137 pr_debug("stl_cd1400startrxtx(portp=%p,rx=%d,tx=%d)\n", portp
, rx
, tx
);
3142 sreroff
|= (SRER_TXDATA
| SRER_TXEMPTY
);
3144 sreron
|= SRER_TXDATA
;
3146 sreron
|= SRER_TXEMPTY
;
3148 sreroff
|= SRER_RXDATA
;
3150 sreron
|= SRER_RXDATA
;
3152 spin_lock_irqsave(&brd_lock
, flags
);
3153 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3154 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3155 stl_cd1400setreg(portp
, SRER
,
3156 ((stl_cd1400getreg(portp
, SRER
) & ~sreroff
) | sreron
));
3157 BRDDISABLE(portp
->brdnr
);
3159 set_bit(ASYI_TXBUSY
, &portp
->istate
);
3160 spin_unlock_irqrestore(&brd_lock
, flags
);
3163 /*****************************************************************************/
3166 * Disable all interrupts from this port.
3169 static void stl_cd1400disableintrs(struct stlport
*portp
)
3171 unsigned long flags
;
3173 pr_debug("stl_cd1400disableintrs(portp=%p)\n", portp
);
3175 spin_lock_irqsave(&brd_lock
, flags
);
3176 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3177 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3178 stl_cd1400setreg(portp
, SRER
, 0);
3179 BRDDISABLE(portp
->brdnr
);
3180 spin_unlock_irqrestore(&brd_lock
, flags
);
3183 /*****************************************************************************/
3185 static void stl_cd1400sendbreak(struct stlport
*portp
, int len
)
3187 unsigned long flags
;
3189 pr_debug("stl_cd1400sendbreak(portp=%p,len=%d)\n", portp
, len
);
3191 spin_lock_irqsave(&brd_lock
, flags
);
3192 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3193 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3194 stl_cd1400setreg(portp
, SRER
,
3195 ((stl_cd1400getreg(portp
, SRER
) & ~SRER_TXDATA
) |
3197 BRDDISABLE(portp
->brdnr
);
3198 portp
->brklen
= len
;
3200 portp
->stats
.txbreaks
++;
3201 spin_unlock_irqrestore(&brd_lock
, flags
);
3204 /*****************************************************************************/
3207 * Take flow control actions...
3210 static void stl_cd1400flowctrl(struct stlport
*portp
, int state
)
3212 struct tty_struct
*tty
;
3213 unsigned long flags
;
3215 pr_debug("stl_cd1400flowctrl(portp=%p,state=%x)\n", portp
, state
);
3219 tty
= tty_port_tty_get(&portp
->port
);
3223 spin_lock_irqsave(&brd_lock
, flags
);
3224 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3225 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3228 if (tty
->termios
->c_iflag
& IXOFF
) {
3229 stl_cd1400ccrwait(portp
);
3230 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR1
);
3231 portp
->stats
.rxxon
++;
3232 stl_cd1400ccrwait(portp
);
3235 * Question: should we return RTS to what it was before? It may
3236 * have been set by an ioctl... Suppose not, since if you have
3237 * hardware flow control set then it is pretty silly to go and
3238 * set the RTS line by hand.
3240 if (tty
->termios
->c_cflag
& CRTSCTS
) {
3241 stl_cd1400setreg(portp
, MCOR1
,
3242 (stl_cd1400getreg(portp
, MCOR1
) |
3243 FIFO_RTSTHRESHOLD
));
3244 stl_cd1400setreg(portp
, MSVR2
, MSVR2_RTS
);
3245 portp
->stats
.rxrtson
++;
3248 if (tty
->termios
->c_iflag
& IXOFF
) {
3249 stl_cd1400ccrwait(portp
);
3250 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR2
);
3251 portp
->stats
.rxxoff
++;
3252 stl_cd1400ccrwait(portp
);
3254 if (tty
->termios
->c_cflag
& CRTSCTS
) {
3255 stl_cd1400setreg(portp
, MCOR1
,
3256 (stl_cd1400getreg(portp
, MCOR1
) & 0xf0));
3257 stl_cd1400setreg(portp
, MSVR2
, 0);
3258 portp
->stats
.rxrtsoff
++;
3262 BRDDISABLE(portp
->brdnr
);
3263 spin_unlock_irqrestore(&brd_lock
, flags
);
3267 /*****************************************************************************/
3270 * Send a flow control character...
3273 static void stl_cd1400sendflow(struct stlport
*portp
, int state
)
3275 struct tty_struct
*tty
;
3276 unsigned long flags
;
3278 pr_debug("stl_cd1400sendflow(portp=%p,state=%x)\n", portp
, state
);
3282 tty
= tty_port_tty_get(&portp
->port
);
3286 spin_lock_irqsave(&brd_lock
, flags
);
3287 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3288 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3290 stl_cd1400ccrwait(portp
);
3291 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR1
);
3292 portp
->stats
.rxxon
++;
3293 stl_cd1400ccrwait(portp
);
3295 stl_cd1400ccrwait(portp
);
3296 stl_cd1400setreg(portp
, CCR
, CCR_SENDSCHR2
);
3297 portp
->stats
.rxxoff
++;
3298 stl_cd1400ccrwait(portp
);
3300 BRDDISABLE(portp
->brdnr
);
3301 spin_unlock_irqrestore(&brd_lock
, flags
);
3305 /*****************************************************************************/
3307 static void stl_cd1400flush(struct stlport
*portp
)
3309 unsigned long flags
;
3311 pr_debug("stl_cd1400flush(portp=%p)\n", portp
);
3316 spin_lock_irqsave(&brd_lock
, flags
);
3317 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3318 stl_cd1400setreg(portp
, CAR
, (portp
->portnr
& 0x03));
3319 stl_cd1400ccrwait(portp
);
3320 stl_cd1400setreg(portp
, CCR
, CCR_TXFLUSHFIFO
);
3321 stl_cd1400ccrwait(portp
);
3322 portp
->tx
.tail
= portp
->tx
.head
;
3323 BRDDISABLE(portp
->brdnr
);
3324 spin_unlock_irqrestore(&brd_lock
, flags
);
3327 /*****************************************************************************/
3330 * Return the current state of data flow on this port. This is only
3331 * really interresting when determining if data has fully completed
3332 * transmission or not... This is easy for the cd1400, it accurately
3333 * maintains the busy port flag.
3336 static int stl_cd1400datastate(struct stlport
*portp
)
3338 pr_debug("stl_cd1400datastate(portp=%p)\n", portp
);
3343 return test_bit(ASYI_TXBUSY
, &portp
->istate
) ? 1 : 0;
3346 /*****************************************************************************/
3349 * Interrupt service routine for cd1400 EasyIO boards.
3352 static void stl_cd1400eiointr(struct stlpanel
*panelp
, unsigned int iobase
)
3354 unsigned char svrtype
;
3356 pr_debug("stl_cd1400eiointr(panelp=%p,iobase=%x)\n", panelp
, iobase
);
3358 spin_lock(&brd_lock
);
3360 svrtype
= inb(iobase
+ EREG_DATA
);
3361 if (panelp
->nrports
> 4) {
3362 outb((SVRR
+ 0x80), iobase
);
3363 svrtype
|= inb(iobase
+ EREG_DATA
);
3366 if (svrtype
& SVRR_RX
)
3367 stl_cd1400rxisr(panelp
, iobase
);
3368 else if (svrtype
& SVRR_TX
)
3369 stl_cd1400txisr(panelp
, iobase
);
3370 else if (svrtype
& SVRR_MDM
)
3371 stl_cd1400mdmisr(panelp
, iobase
);
3373 spin_unlock(&brd_lock
);
3376 /*****************************************************************************/
3379 * Interrupt service routine for cd1400 panels.
3382 static void stl_cd1400echintr(struct stlpanel
*panelp
, unsigned int iobase
)
3384 unsigned char svrtype
;
3386 pr_debug("stl_cd1400echintr(panelp=%p,iobase=%x)\n", panelp
, iobase
);
3389 svrtype
= inb(iobase
+ EREG_DATA
);
3390 outb((SVRR
+ 0x80), iobase
);
3391 svrtype
|= inb(iobase
+ EREG_DATA
);
3392 if (svrtype
& SVRR_RX
)
3393 stl_cd1400rxisr(panelp
, iobase
);
3394 else if (svrtype
& SVRR_TX
)
3395 stl_cd1400txisr(panelp
, iobase
);
3396 else if (svrtype
& SVRR_MDM
)
3397 stl_cd1400mdmisr(panelp
, iobase
);
3401 /*****************************************************************************/
3404 * Unfortunately we need to handle breaks in the TX data stream, since
3405 * this is the only way to generate them on the cd1400.
3408 static int stl_cd1400breakisr(struct stlport
*portp
, int ioaddr
)
3410 if (portp
->brklen
== 1) {
3411 outb((COR2
+ portp
->uartaddr
), ioaddr
);
3412 outb((inb(ioaddr
+ EREG_DATA
) | COR2_ETC
),
3413 (ioaddr
+ EREG_DATA
));
3414 outb((TDR
+ portp
->uartaddr
), ioaddr
);
3415 outb(ETC_CMD
, (ioaddr
+ EREG_DATA
));
3416 outb(ETC_STARTBREAK
, (ioaddr
+ EREG_DATA
));
3417 outb((SRER
+ portp
->uartaddr
), ioaddr
);
3418 outb((inb(ioaddr
+ EREG_DATA
) & ~(SRER_TXDATA
| SRER_TXEMPTY
)),
3419 (ioaddr
+ EREG_DATA
));
3421 } else if (portp
->brklen
> 1) {
3422 outb((TDR
+ portp
->uartaddr
), ioaddr
);
3423 outb(ETC_CMD
, (ioaddr
+ EREG_DATA
));
3424 outb(ETC_STOPBREAK
, (ioaddr
+ EREG_DATA
));
3428 outb((COR2
+ portp
->uartaddr
), ioaddr
);
3429 outb((inb(ioaddr
+ EREG_DATA
) & ~COR2_ETC
),
3430 (ioaddr
+ EREG_DATA
));
3436 /*****************************************************************************/
3439 * Transmit interrupt handler. This has gotta be fast! Handling TX
3440 * chars is pretty simple, stuff as many as possible from the TX buffer
3441 * into the cd1400 FIFO. Must also handle TX breaks here, since they
3442 * are embedded as commands in the data stream. Oh no, had to use a goto!
3443 * This could be optimized more, will do when I get time...
3444 * In practice it is possible that interrupts are enabled but that the
3445 * port has been hung up. Need to handle not having any TX buffer here,
3446 * this is done by using the side effect that head and tail will also
3447 * be NULL if the buffer has been freed.
3450 static void stl_cd1400txisr(struct stlpanel
*panelp
, int ioaddr
)
3452 struct stlport
*portp
;
3455 unsigned char ioack
, srer
;
3456 struct tty_struct
*tty
;
3458 pr_debug("stl_cd1400txisr(panelp=%p,ioaddr=%x)\n", panelp
, ioaddr
);
3460 ioack
= inb(ioaddr
+ EREG_TXACK
);
3461 if (((ioack
& panelp
->ackmask
) != 0) ||
3462 ((ioack
& ACK_TYPMASK
) != ACK_TYPTX
)) {
3463 printk("STALLION: bad TX interrupt ack value=%x\n", ioack
);
3466 portp
= panelp
->ports
[(ioack
>> 3)];
3469 * Unfortunately we need to handle breaks in the data stream, since
3470 * this is the only way to generate them on the cd1400. Do it now if
3471 * a break is to be sent.
3473 if (portp
->brklen
!= 0)
3474 if (stl_cd1400breakisr(portp
, ioaddr
))
3477 head
= portp
->tx
.head
;
3478 tail
= portp
->tx
.tail
;
3479 len
= (head
>= tail
) ? (head
- tail
) : (STL_TXBUFSIZE
- (tail
- head
));
3480 if ((len
== 0) || ((len
< STL_TXBUFLOW
) &&
3481 (test_bit(ASYI_TXLOW
, &portp
->istate
) == 0))) {
3482 set_bit(ASYI_TXLOW
, &portp
->istate
);
3483 tty
= tty_port_tty_get(&portp
->port
);
3491 outb((SRER
+ portp
->uartaddr
), ioaddr
);
3492 srer
= inb(ioaddr
+ EREG_DATA
);
3493 if (srer
& SRER_TXDATA
) {
3494 srer
= (srer
& ~SRER_TXDATA
) | SRER_TXEMPTY
;
3496 srer
&= ~(SRER_TXDATA
| SRER_TXEMPTY
);
3497 clear_bit(ASYI_TXBUSY
, &portp
->istate
);
3499 outb(srer
, (ioaddr
+ EREG_DATA
));
3501 len
= min(len
, CD1400_TXFIFOSIZE
);
3502 portp
->stats
.txtotal
+= len
;
3503 stlen
= min_t(unsigned int, len
,
3504 (portp
->tx
.buf
+ STL_TXBUFSIZE
) - tail
);
3505 outb((TDR
+ portp
->uartaddr
), ioaddr
);
3506 outsb((ioaddr
+ EREG_DATA
), tail
, stlen
);
3509 if (tail
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
))
3510 tail
= portp
->tx
.buf
;
3512 outsb((ioaddr
+ EREG_DATA
), tail
, len
);
3515 portp
->tx
.tail
= tail
;
3519 outb((EOSRR
+ portp
->uartaddr
), ioaddr
);
3520 outb(0, (ioaddr
+ EREG_DATA
));
3523 /*****************************************************************************/
3526 * Receive character interrupt handler. Determine if we have good chars
3527 * or bad chars and then process appropriately. Good chars are easy
3528 * just shove the lot into the RX buffer and set all status byte to 0.
3529 * If a bad RX char then process as required. This routine needs to be
3530 * fast! In practice it is possible that we get an interrupt on a port
3531 * that is closed. This can happen on hangups - since they completely
3532 * shutdown a port not in user context. Need to handle this case.
3535 static void stl_cd1400rxisr(struct stlpanel
*panelp
, int ioaddr
)
3537 struct stlport
*portp
;
3538 struct tty_struct
*tty
;
3539 unsigned int ioack
, len
, buflen
;
3540 unsigned char status
;
3543 pr_debug("stl_cd1400rxisr(panelp=%p,ioaddr=%x)\n", panelp
, ioaddr
);
3545 ioack
= inb(ioaddr
+ EREG_RXACK
);
3546 if ((ioack
& panelp
->ackmask
) != 0) {
3547 printk("STALLION: bad RX interrupt ack value=%x\n", ioack
);
3550 portp
= panelp
->ports
[(ioack
>> 3)];
3551 tty
= tty_port_tty_get(&portp
->port
);
3553 if ((ioack
& ACK_TYPMASK
) == ACK_TYPRXGOOD
) {
3554 outb((RDCR
+ portp
->uartaddr
), ioaddr
);
3555 len
= inb(ioaddr
+ EREG_DATA
);
3556 if (tty
== NULL
|| (buflen
= tty_buffer_request_room(tty
, len
)) == 0) {
3557 len
= min_t(unsigned int, len
, sizeof(stl_unwanted
));
3558 outb((RDSR
+ portp
->uartaddr
), ioaddr
);
3559 insb((ioaddr
+ EREG_DATA
), &stl_unwanted
[0], len
);
3560 portp
->stats
.rxlost
+= len
;
3561 portp
->stats
.rxtotal
+= len
;
3563 len
= min(len
, buflen
);
3566 outb((RDSR
+ portp
->uartaddr
), ioaddr
);
3567 tty_prepare_flip_string(tty
, &ptr
, len
);
3568 insb((ioaddr
+ EREG_DATA
), ptr
, len
);
3569 tty_schedule_flip(tty
);
3570 portp
->stats
.rxtotal
+= len
;
3573 } else if ((ioack
& ACK_TYPMASK
) == ACK_TYPRXBAD
) {
3574 outb((RDSR
+ portp
->uartaddr
), ioaddr
);
3575 status
= inb(ioaddr
+ EREG_DATA
);
3576 ch
= inb(ioaddr
+ EREG_DATA
);
3577 if (status
& ST_PARITY
)
3578 portp
->stats
.rxparity
++;
3579 if (status
& ST_FRAMING
)
3580 portp
->stats
.rxframing
++;
3581 if (status
& ST_OVERRUN
)
3582 portp
->stats
.rxoverrun
++;
3583 if (status
& ST_BREAK
)
3584 portp
->stats
.rxbreaks
++;
3585 if (status
& ST_SCHARMASK
) {
3586 if ((status
& ST_SCHARMASK
) == ST_SCHAR1
)
3587 portp
->stats
.txxon
++;
3588 if ((status
& ST_SCHARMASK
) == ST_SCHAR2
)
3589 portp
->stats
.txxoff
++;
3592 if (tty
!= NULL
&& (portp
->rxignoremsk
& status
) == 0) {
3593 if (portp
->rxmarkmsk
& status
) {
3594 if (status
& ST_BREAK
) {
3596 if (portp
->port
.flags
& ASYNC_SAK
) {
3598 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3600 } else if (status
& ST_PARITY
)
3601 status
= TTY_PARITY
;
3602 else if (status
& ST_FRAMING
)
3604 else if(status
& ST_OVERRUN
)
3605 status
= TTY_OVERRUN
;
3610 tty_insert_flip_char(tty
, ch
, status
);
3611 tty_schedule_flip(tty
);
3614 printk("STALLION: bad RX interrupt ack value=%x\n", ioack
);
3621 outb((EOSRR
+ portp
->uartaddr
), ioaddr
);
3622 outb(0, (ioaddr
+ EREG_DATA
));
3625 /*****************************************************************************/
3628 * Modem interrupt handler. The is called when the modem signal line
3629 * (DCD) has changed state. Leave most of the work to the off-level
3630 * processing routine.
3633 static void stl_cd1400mdmisr(struct stlpanel
*panelp
, int ioaddr
)
3635 struct stlport
*portp
;
3639 pr_debug("stl_cd1400mdmisr(panelp=%p)\n", panelp
);
3641 ioack
= inb(ioaddr
+ EREG_MDACK
);
3642 if (((ioack
& panelp
->ackmask
) != 0) ||
3643 ((ioack
& ACK_TYPMASK
) != ACK_TYPMDM
)) {
3644 printk("STALLION: bad MODEM interrupt ack value=%x\n", ioack
);
3647 portp
= panelp
->ports
[(ioack
>> 3)];
3649 outb((MISR
+ portp
->uartaddr
), ioaddr
);
3650 misr
= inb(ioaddr
+ EREG_DATA
);
3651 if (misr
& MISR_DCD
) {
3652 stl_cd_change(portp
);
3653 portp
->stats
.modem
++;
3656 outb((EOSRR
+ portp
->uartaddr
), ioaddr
);
3657 outb(0, (ioaddr
+ EREG_DATA
));
3660 /*****************************************************************************/
3661 /* SC26198 HARDWARE FUNCTIONS */
3662 /*****************************************************************************/
3665 * These functions get/set/update the registers of the sc26198 UARTs.
3666 * Access to the sc26198 registers is via an address/data io port pair.
3667 * (Maybe should make this inline...)
3670 static int stl_sc26198getreg(struct stlport
*portp
, int regnr
)
3672 outb((regnr
| portp
->uartaddr
), (portp
->ioaddr
+ XP_ADDR
));
3673 return inb(portp
->ioaddr
+ XP_DATA
);
3676 static void stl_sc26198setreg(struct stlport
*portp
, int regnr
, int value
)
3678 outb((regnr
| portp
->uartaddr
), (portp
->ioaddr
+ XP_ADDR
));
3679 outb(value
, (portp
->ioaddr
+ XP_DATA
));
3682 static int stl_sc26198updatereg(struct stlport
*portp
, int regnr
, int value
)
3684 outb((regnr
| portp
->uartaddr
), (portp
->ioaddr
+ XP_ADDR
));
3685 if (inb(portp
->ioaddr
+ XP_DATA
) != value
) {
3686 outb(value
, (portp
->ioaddr
+ XP_DATA
));
3692 /*****************************************************************************/
3695 * Functions to get and set the sc26198 global registers.
3698 static int stl_sc26198getglobreg(struct stlport
*portp
, int regnr
)
3700 outb(regnr
, (portp
->ioaddr
+ XP_ADDR
));
3701 return inb(portp
->ioaddr
+ XP_DATA
);
3705 static void stl_sc26198setglobreg(struct stlport
*portp
, int regnr
, int value
)
3707 outb(regnr
, (portp
->ioaddr
+ XP_ADDR
));
3708 outb(value
, (portp
->ioaddr
+ XP_DATA
));
3712 /*****************************************************************************/
3715 * Inbitialize the UARTs in a panel. We don't care what sort of board
3716 * these ports are on - since the port io registers are almost
3717 * identical when dealing with ports.
3720 static int stl_sc26198panelinit(struct stlbrd
*brdp
, struct stlpanel
*panelp
)
3723 int nrchips
, ioaddr
;
3725 pr_debug("stl_sc26198panelinit(brdp=%p,panelp=%p)\n", brdp
, panelp
);
3727 BRDENABLE(panelp
->brdnr
, panelp
->pagenr
);
3730 * Check that each chip is present and started up OK.
3733 nrchips
= (panelp
->nrports
+ 4) / SC26198_PORTS
;
3734 if (brdp
->brdtype
== BRD_ECHPCI
)
3735 outb(panelp
->pagenr
, brdp
->ioctrl
);
3737 for (i
= 0; i
< nrchips
; i
++) {
3738 ioaddr
= panelp
->iobase
+ (i
* 4);
3739 outb(SCCR
, (ioaddr
+ XP_ADDR
));
3740 outb(CR_RESETALL
, (ioaddr
+ XP_DATA
));
3741 outb(TSTR
, (ioaddr
+ XP_ADDR
));
3742 if (inb(ioaddr
+ XP_DATA
) != 0) {
3743 printk("STALLION: sc26198 not responding, "
3744 "brd=%d panel=%d chip=%d\n",
3745 panelp
->brdnr
, panelp
->panelnr
, i
);
3748 chipmask
|= (0x1 << i
);
3749 outb(GCCR
, (ioaddr
+ XP_ADDR
));
3750 outb(GCCR_IVRTYPCHANACK
, (ioaddr
+ XP_DATA
));
3751 outb(WDTRCR
, (ioaddr
+ XP_ADDR
));
3752 outb(0xff, (ioaddr
+ XP_DATA
));
3755 BRDDISABLE(panelp
->brdnr
);
3759 /*****************************************************************************/
3762 * Initialize hardware specific port registers.
3765 static void stl_sc26198portinit(struct stlbrd
*brdp
, struct stlpanel
*panelp
, struct stlport
*portp
)
3767 pr_debug("stl_sc26198portinit(brdp=%p,panelp=%p,portp=%p)\n", brdp
,
3770 if ((brdp
== NULL
) || (panelp
== NULL
) ||
3774 portp
->ioaddr
= panelp
->iobase
+ ((portp
->portnr
< 8) ? 0 : 4);
3775 portp
->uartaddr
= (portp
->portnr
& 0x07) << 4;
3776 portp
->pagenr
= panelp
->pagenr
;
3779 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3780 stl_sc26198setreg(portp
, IOPCR
, IOPCR_SETSIGS
);
3781 BRDDISABLE(portp
->brdnr
);
3784 /*****************************************************************************/
3787 * Set up the sc26198 registers for a port based on the termios port
3791 static void stl_sc26198setport(struct stlport
*portp
, struct ktermios
*tiosp
)
3793 struct stlbrd
*brdp
;
3794 unsigned long flags
;
3795 unsigned int baudrate
;
3796 unsigned char mr0
, mr1
, mr2
, clk
;
3797 unsigned char imron
, imroff
, iopr
, ipr
;
3807 brdp
= stl_brds
[portp
->brdnr
];
3812 * Set up the RX char ignore mask with those RX error types we
3815 portp
->rxignoremsk
= 0;
3816 if (tiosp
->c_iflag
& IGNPAR
)
3817 portp
->rxignoremsk
|= (SR_RXPARITY
| SR_RXFRAMING
|
3819 if (tiosp
->c_iflag
& IGNBRK
)
3820 portp
->rxignoremsk
|= SR_RXBREAK
;
3822 portp
->rxmarkmsk
= SR_RXOVERRUN
;
3823 if (tiosp
->c_iflag
& (INPCK
| PARMRK
))
3824 portp
->rxmarkmsk
|= (SR_RXPARITY
| SR_RXFRAMING
);
3825 if (tiosp
->c_iflag
& BRKINT
)
3826 portp
->rxmarkmsk
|= SR_RXBREAK
;
3829 * Go through the char size, parity and stop bits and set all the
3830 * option register appropriately.
3832 switch (tiosp
->c_cflag
& CSIZE
) {
3847 if (tiosp
->c_cflag
& CSTOPB
)
3852 if (tiosp
->c_cflag
& PARENB
) {
3853 if (tiosp
->c_cflag
& PARODD
)
3854 mr1
|= (MR1_PARENB
| MR1_PARODD
);
3856 mr1
|= (MR1_PARENB
| MR1_PAREVEN
);
3860 mr1
|= MR1_ERRBLOCK
;
3863 * Set the RX FIFO threshold at 8 chars. This gives a bit of breathing
3864 * space for hardware flow control and the like. This should be set to
3867 mr2
|= MR2_RXFIFOHALF
;
3870 * Calculate the baud rate timers. For now we will just assume that
3871 * the input and output baud are the same. The sc26198 has a fixed
3872 * baud rate table, so only discrete baud rates possible.
3874 baudrate
= tiosp
->c_cflag
& CBAUD
;
3875 if (baudrate
& CBAUDEX
) {
3876 baudrate
&= ~CBAUDEX
;
3877 if ((baudrate
< 1) || (baudrate
> 4))
3878 tiosp
->c_cflag
&= ~CBAUDEX
;
3882 baudrate
= stl_baudrates
[baudrate
];
3883 if ((tiosp
->c_cflag
& CBAUD
) == B38400
) {
3884 if ((portp
->port
.flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_HI
)
3886 else if ((portp
->port
.flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_VHI
)
3888 else if ((portp
->port
.flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_SHI
)
3890 else if ((portp
->port
.flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_WARP
)
3892 else if ((portp
->port
.flags
& ASYNC_SPD_MASK
) == ASYNC_SPD_CUST
)
3893 baudrate
= (portp
->baud_base
/ portp
->custom_divisor
);
3895 if (baudrate
> STL_SC26198MAXBAUD
)
3896 baudrate
= STL_SC26198MAXBAUD
;
3899 for (clk
= 0; clk
< SC26198_NRBAUDS
; clk
++)
3900 if (baudrate
<= sc26198_baudtable
[clk
])
3904 * Check what form of modem signaling is required and set it up.
3906 if (tiosp
->c_cflag
& CLOCAL
) {
3907 portp
->port
.flags
&= ~ASYNC_CHECK_CD
;
3909 iopr
|= IOPR_DCDCOS
;
3911 portp
->port
.flags
|= ASYNC_CHECK_CD
;
3915 * Setup sc26198 enhanced modes if we can. In particular we want to
3916 * handle as much of the flow control as possible automatically. As
3917 * well as saving a few CPU cycles it will also greatly improve flow
3918 * control reliability.
3920 if (tiosp
->c_iflag
& IXON
) {
3921 mr0
|= MR0_SWFTX
| MR0_SWFT
;
3922 imron
|= IR_XONXOFF
;
3924 imroff
|= IR_XONXOFF
;
3926 if (tiosp
->c_iflag
& IXOFF
)
3929 if (tiosp
->c_cflag
& CRTSCTS
) {
3935 * All sc26198 register values calculated so go through and set
3939 pr_debug("SETPORT: portnr=%d panelnr=%d brdnr=%d\n",
3940 portp
->portnr
, portp
->panelnr
, portp
->brdnr
);
3941 pr_debug(" mr0=%x mr1=%x mr2=%x clk=%x\n", mr0
, mr1
, mr2
, clk
);
3942 pr_debug(" iopr=%x imron=%x imroff=%x\n", iopr
, imron
, imroff
);
3943 pr_debug(" schr1=%x schr2=%x schr3=%x schr4=%x\n",
3944 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
],
3945 tiosp
->c_cc
[VSTART
], tiosp
->c_cc
[VSTOP
]);
3947 spin_lock_irqsave(&brd_lock
, flags
);
3948 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
3949 stl_sc26198setreg(portp
, IMR
, 0);
3950 stl_sc26198updatereg(portp
, MR0
, mr0
);
3951 stl_sc26198updatereg(portp
, MR1
, mr1
);
3952 stl_sc26198setreg(portp
, SCCR
, CR_RXERRBLOCK
);
3953 stl_sc26198updatereg(portp
, MR2
, mr2
);
3954 stl_sc26198updatereg(portp
, IOPIOR
,
3955 ((stl_sc26198getreg(portp
, IOPIOR
) & ~IPR_CHANGEMASK
) | iopr
));
3958 stl_sc26198setreg(portp
, TXCSR
, clk
);
3959 stl_sc26198setreg(portp
, RXCSR
, clk
);
3962 stl_sc26198setreg(portp
, XONCR
, tiosp
->c_cc
[VSTART
]);
3963 stl_sc26198setreg(portp
, XOFFCR
, tiosp
->c_cc
[VSTOP
]);
3965 ipr
= stl_sc26198getreg(portp
, IPR
);
3967 portp
->sigs
&= ~TIOCM_CD
;
3969 portp
->sigs
|= TIOCM_CD
;
3971 portp
->imr
= (portp
->imr
& ~imroff
) | imron
;
3972 stl_sc26198setreg(portp
, IMR
, portp
->imr
);
3973 BRDDISABLE(portp
->brdnr
);
3974 spin_unlock_irqrestore(&brd_lock
, flags
);
3977 /*****************************************************************************/
3980 * Set the state of the DTR and RTS signals.
3983 static void stl_sc26198setsignals(struct stlport
*portp
, int dtr
, int rts
)
3985 unsigned char iopioron
, iopioroff
;
3986 unsigned long flags
;
3988 pr_debug("stl_sc26198setsignals(portp=%p,dtr=%d,rts=%d)\n", portp
,
3994 iopioroff
|= IPR_DTR
;
3996 iopioron
|= IPR_DTR
;
3998 iopioroff
|= IPR_RTS
;
4000 iopioron
|= IPR_RTS
;
4002 spin_lock_irqsave(&brd_lock
, flags
);
4003 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4004 stl_sc26198setreg(portp
, IOPIOR
,
4005 ((stl_sc26198getreg(portp
, IOPIOR
) & ~iopioroff
) | iopioron
));
4006 BRDDISABLE(portp
->brdnr
);
4007 spin_unlock_irqrestore(&brd_lock
, flags
);
4010 /*****************************************************************************/
4013 * Return the state of the signals.
4016 static int stl_sc26198getsignals(struct stlport
*portp
)
4019 unsigned long flags
;
4022 pr_debug("stl_sc26198getsignals(portp=%p)\n", portp
);
4024 spin_lock_irqsave(&brd_lock
, flags
);
4025 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4026 ipr
= stl_sc26198getreg(portp
, IPR
);
4027 BRDDISABLE(portp
->brdnr
);
4028 spin_unlock_irqrestore(&brd_lock
, flags
);
4031 sigs
|= (ipr
& IPR_DCD
) ? 0 : TIOCM_CD
;
4032 sigs
|= (ipr
& IPR_CTS
) ? 0 : TIOCM_CTS
;
4033 sigs
|= (ipr
& IPR_DTR
) ? 0: TIOCM_DTR
;
4034 sigs
|= (ipr
& IPR_RTS
) ? 0: TIOCM_RTS
;
4039 /*****************************************************************************/
4042 * Enable/Disable the Transmitter and/or Receiver.
4045 static void stl_sc26198enablerxtx(struct stlport
*portp
, int rx
, int tx
)
4048 unsigned long flags
;
4050 pr_debug("stl_sc26198enablerxtx(portp=%p,rx=%d,tx=%d)\n", portp
, rx
,tx
);
4052 ccr
= portp
->crenable
;
4054 ccr
&= ~CR_TXENABLE
;
4058 ccr
&= ~CR_RXENABLE
;
4062 spin_lock_irqsave(&brd_lock
, flags
);
4063 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4064 stl_sc26198setreg(portp
, SCCR
, ccr
);
4065 BRDDISABLE(portp
->brdnr
);
4066 portp
->crenable
= ccr
;
4067 spin_unlock_irqrestore(&brd_lock
, flags
);
4070 /*****************************************************************************/
4073 * Start/stop the Transmitter and/or Receiver.
4076 static void stl_sc26198startrxtx(struct stlport
*portp
, int rx
, int tx
)
4079 unsigned long flags
;
4081 pr_debug("stl_sc26198startrxtx(portp=%p,rx=%d,tx=%d)\n", portp
, rx
, tx
);
4089 imr
&= ~(IR_RXRDY
| IR_RXBREAK
| IR_RXWATCHDOG
);
4091 imr
|= IR_RXRDY
| IR_RXBREAK
| IR_RXWATCHDOG
;
4093 spin_lock_irqsave(&brd_lock
, flags
);
4094 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4095 stl_sc26198setreg(portp
, IMR
, imr
);
4096 BRDDISABLE(portp
->brdnr
);
4099 set_bit(ASYI_TXBUSY
, &portp
->istate
);
4100 spin_unlock_irqrestore(&brd_lock
, flags
);
4103 /*****************************************************************************/
4106 * Disable all interrupts from this port.
4109 static void stl_sc26198disableintrs(struct stlport
*portp
)
4111 unsigned long flags
;
4113 pr_debug("stl_sc26198disableintrs(portp=%p)\n", portp
);
4115 spin_lock_irqsave(&brd_lock
, flags
);
4116 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4118 stl_sc26198setreg(portp
, IMR
, 0);
4119 BRDDISABLE(portp
->brdnr
);
4120 spin_unlock_irqrestore(&brd_lock
, flags
);
4123 /*****************************************************************************/
4125 static void stl_sc26198sendbreak(struct stlport
*portp
, int len
)
4127 unsigned long flags
;
4129 pr_debug("stl_sc26198sendbreak(portp=%p,len=%d)\n", portp
, len
);
4131 spin_lock_irqsave(&brd_lock
, flags
);
4132 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4134 stl_sc26198setreg(portp
, SCCR
, CR_TXSTARTBREAK
);
4135 portp
->stats
.txbreaks
++;
4137 stl_sc26198setreg(portp
, SCCR
, CR_TXSTOPBREAK
);
4139 BRDDISABLE(portp
->brdnr
);
4140 spin_unlock_irqrestore(&brd_lock
, flags
);
4143 /*****************************************************************************/
4146 * Take flow control actions...
4149 static void stl_sc26198flowctrl(struct stlport
*portp
, int state
)
4151 struct tty_struct
*tty
;
4152 unsigned long flags
;
4155 pr_debug("stl_sc26198flowctrl(portp=%p,state=%x)\n", portp
, state
);
4159 tty
= tty_port_tty_get(&portp
->port
);
4163 spin_lock_irqsave(&brd_lock
, flags
);
4164 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4167 if (tty
->termios
->c_iflag
& IXOFF
) {
4168 mr0
= stl_sc26198getreg(portp
, MR0
);
4169 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4170 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXON
);
4172 portp
->stats
.rxxon
++;
4173 stl_sc26198wait(portp
);
4174 stl_sc26198setreg(portp
, MR0
, mr0
);
4177 * Question: should we return RTS to what it was before? It may
4178 * have been set by an ioctl... Suppose not, since if you have
4179 * hardware flow control set then it is pretty silly to go and
4180 * set the RTS line by hand.
4182 if (tty
->termios
->c_cflag
& CRTSCTS
) {
4183 stl_sc26198setreg(portp
, MR1
,
4184 (stl_sc26198getreg(portp
, MR1
) | MR1_AUTORTS
));
4185 stl_sc26198setreg(portp
, IOPIOR
,
4186 (stl_sc26198getreg(portp
, IOPIOR
) | IOPR_RTS
));
4187 portp
->stats
.rxrtson
++;
4190 if (tty
->termios
->c_iflag
& IXOFF
) {
4191 mr0
= stl_sc26198getreg(portp
, MR0
);
4192 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4193 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXOFF
);
4195 portp
->stats
.rxxoff
++;
4196 stl_sc26198wait(portp
);
4197 stl_sc26198setreg(portp
, MR0
, mr0
);
4199 if (tty
->termios
->c_cflag
& CRTSCTS
) {
4200 stl_sc26198setreg(portp
, MR1
,
4201 (stl_sc26198getreg(portp
, MR1
) & ~MR1_AUTORTS
));
4202 stl_sc26198setreg(portp
, IOPIOR
,
4203 (stl_sc26198getreg(portp
, IOPIOR
) & ~IOPR_RTS
));
4204 portp
->stats
.rxrtsoff
++;
4208 BRDDISABLE(portp
->brdnr
);
4209 spin_unlock_irqrestore(&brd_lock
, flags
);
4213 /*****************************************************************************/
4216 * Send a flow control character.
4219 static void stl_sc26198sendflow(struct stlport
*portp
, int state
)
4221 struct tty_struct
*tty
;
4222 unsigned long flags
;
4225 pr_debug("stl_sc26198sendflow(portp=%p,state=%x)\n", portp
, state
);
4229 tty
= tty_port_tty_get(&portp
->port
);
4233 spin_lock_irqsave(&brd_lock
, flags
);
4234 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4236 mr0
= stl_sc26198getreg(portp
, MR0
);
4237 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4238 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXON
);
4240 portp
->stats
.rxxon
++;
4241 stl_sc26198wait(portp
);
4242 stl_sc26198setreg(portp
, MR0
, mr0
);
4244 mr0
= stl_sc26198getreg(portp
, MR0
);
4245 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4246 stl_sc26198setreg(portp
, SCCR
, CR_TXSENDXOFF
);
4248 portp
->stats
.rxxoff
++;
4249 stl_sc26198wait(portp
);
4250 stl_sc26198setreg(portp
, MR0
, mr0
);
4252 BRDDISABLE(portp
->brdnr
);
4253 spin_unlock_irqrestore(&brd_lock
, flags
);
4257 /*****************************************************************************/
4259 static void stl_sc26198flush(struct stlport
*portp
)
4261 unsigned long flags
;
4263 pr_debug("stl_sc26198flush(portp=%p)\n", portp
);
4268 spin_lock_irqsave(&brd_lock
, flags
);
4269 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4270 stl_sc26198setreg(portp
, SCCR
, CR_TXRESET
);
4271 stl_sc26198setreg(portp
, SCCR
, portp
->crenable
);
4272 BRDDISABLE(portp
->brdnr
);
4273 portp
->tx
.tail
= portp
->tx
.head
;
4274 spin_unlock_irqrestore(&brd_lock
, flags
);
4277 /*****************************************************************************/
4280 * Return the current state of data flow on this port. This is only
4281 * really interresting when determining if data has fully completed
4282 * transmission or not... The sc26198 interrupt scheme cannot
4283 * determine when all data has actually drained, so we need to
4284 * check the port statusy register to be sure.
4287 static int stl_sc26198datastate(struct stlport
*portp
)
4289 unsigned long flags
;
4292 pr_debug("stl_sc26198datastate(portp=%p)\n", portp
);
4296 if (test_bit(ASYI_TXBUSY
, &portp
->istate
))
4299 spin_lock_irqsave(&brd_lock
, flags
);
4300 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4301 sr
= stl_sc26198getreg(portp
, SR
);
4302 BRDDISABLE(portp
->brdnr
);
4303 spin_unlock_irqrestore(&brd_lock
, flags
);
4305 return (sr
& SR_TXEMPTY
) ? 0 : 1;
4308 /*****************************************************************************/
4311 * Delay for a small amount of time, to give the sc26198 a chance
4312 * to process a command...
4315 static void stl_sc26198wait(struct stlport
*portp
)
4319 pr_debug("stl_sc26198wait(portp=%p)\n", portp
);
4324 for (i
= 0; i
< 20; i
++)
4325 stl_sc26198getglobreg(portp
, TSTR
);
4328 /*****************************************************************************/
4331 * If we are TX flow controlled and in IXANY mode then we may
4332 * need to unflow control here. We gotta do this because of the
4333 * automatic flow control modes of the sc26198.
4336 static void stl_sc26198txunflow(struct stlport
*portp
, struct tty_struct
*tty
)
4340 mr0
= stl_sc26198getreg(portp
, MR0
);
4341 stl_sc26198setreg(portp
, MR0
, (mr0
& ~MR0_SWFRXTX
));
4342 stl_sc26198setreg(portp
, SCCR
, CR_HOSTXON
);
4343 stl_sc26198wait(portp
);
4344 stl_sc26198setreg(portp
, MR0
, mr0
);
4345 clear_bit(ASYI_TXFLOWED
, &portp
->istate
);
4348 /*****************************************************************************/
4351 * Interrupt service routine for sc26198 panels.
4354 static void stl_sc26198intr(struct stlpanel
*panelp
, unsigned int iobase
)
4356 struct stlport
*portp
;
4359 spin_lock(&brd_lock
);
4362 * Work around bug in sc26198 chip... Cannot have A6 address
4363 * line of UART high, else iack will be returned as 0.
4365 outb(0, (iobase
+ 1));
4367 iack
= inb(iobase
+ XP_IACK
);
4368 portp
= panelp
->ports
[(iack
& IVR_CHANMASK
) + ((iobase
& 0x4) << 1)];
4370 if (iack
& IVR_RXDATA
)
4371 stl_sc26198rxisr(portp
, iack
);
4372 else if (iack
& IVR_TXDATA
)
4373 stl_sc26198txisr(portp
);
4375 stl_sc26198otherisr(portp
, iack
);
4377 spin_unlock(&brd_lock
);
4380 /*****************************************************************************/
4383 * Transmit interrupt handler. This has gotta be fast! Handling TX
4384 * chars is pretty simple, stuff as many as possible from the TX buffer
4385 * into the sc26198 FIFO.
4386 * In practice it is possible that interrupts are enabled but that the
4387 * port has been hung up. Need to handle not having any TX buffer here,
4388 * this is done by using the side effect that head and tail will also
4389 * be NULL if the buffer has been freed.
4392 static void stl_sc26198txisr(struct stlport
*portp
)
4394 struct tty_struct
*tty
;
4395 unsigned int ioaddr
;
4400 pr_debug("stl_sc26198txisr(portp=%p)\n", portp
);
4402 ioaddr
= portp
->ioaddr
;
4403 head
= portp
->tx
.head
;
4404 tail
= portp
->tx
.tail
;
4405 len
= (head
>= tail
) ? (head
- tail
) : (STL_TXBUFSIZE
- (tail
- head
));
4406 if ((len
== 0) || ((len
< STL_TXBUFLOW
) &&
4407 (test_bit(ASYI_TXLOW
, &portp
->istate
) == 0))) {
4408 set_bit(ASYI_TXLOW
, &portp
->istate
);
4409 tty
= tty_port_tty_get(&portp
->port
);
4417 outb((MR0
| portp
->uartaddr
), (ioaddr
+ XP_ADDR
));
4418 mr0
= inb(ioaddr
+ XP_DATA
);
4419 if ((mr0
& MR0_TXMASK
) == MR0_TXEMPTY
) {
4420 portp
->imr
&= ~IR_TXRDY
;
4421 outb((IMR
| portp
->uartaddr
), (ioaddr
+ XP_ADDR
));
4422 outb(portp
->imr
, (ioaddr
+ XP_DATA
));
4423 clear_bit(ASYI_TXBUSY
, &portp
->istate
);
4425 mr0
|= ((mr0
& ~MR0_TXMASK
) | MR0_TXEMPTY
);
4426 outb(mr0
, (ioaddr
+ XP_DATA
));
4429 len
= min(len
, SC26198_TXFIFOSIZE
);
4430 portp
->stats
.txtotal
+= len
;
4431 stlen
= min_t(unsigned int, len
,
4432 (portp
->tx
.buf
+ STL_TXBUFSIZE
) - tail
);
4433 outb(GTXFIFO
, (ioaddr
+ XP_ADDR
));
4434 outsb((ioaddr
+ XP_DATA
), tail
, stlen
);
4437 if (tail
>= (portp
->tx
.buf
+ STL_TXBUFSIZE
))
4438 tail
= portp
->tx
.buf
;
4440 outsb((ioaddr
+ XP_DATA
), tail
, len
);
4443 portp
->tx
.tail
= tail
;
4447 /*****************************************************************************/
4450 * Receive character interrupt handler. Determine if we have good chars
4451 * or bad chars and then process appropriately. Good chars are easy
4452 * just shove the lot into the RX buffer and set all status byte to 0.
4453 * If a bad RX char then process as required. This routine needs to be
4454 * fast! In practice it is possible that we get an interrupt on a port
4455 * that is closed. This can happen on hangups - since they completely
4456 * shutdown a port not in user context. Need to handle this case.
4459 static void stl_sc26198rxisr(struct stlport
*portp
, unsigned int iack
)
4461 struct tty_struct
*tty
;
4462 unsigned int len
, buflen
, ioaddr
;
4464 pr_debug("stl_sc26198rxisr(portp=%p,iack=%x)\n", portp
, iack
);
4466 tty
= tty_port_tty_get(&portp
->port
);
4467 ioaddr
= portp
->ioaddr
;
4468 outb(GIBCR
, (ioaddr
+ XP_ADDR
));
4469 len
= inb(ioaddr
+ XP_DATA
) + 1;
4471 if ((iack
& IVR_TYPEMASK
) == IVR_RXDATA
) {
4472 if (tty
== NULL
|| (buflen
= tty_buffer_request_room(tty
, len
)) == 0) {
4473 len
= min_t(unsigned int, len
, sizeof(stl_unwanted
));
4474 outb(GRXFIFO
, (ioaddr
+ XP_ADDR
));
4475 insb((ioaddr
+ XP_DATA
), &stl_unwanted
[0], len
);
4476 portp
->stats
.rxlost
+= len
;
4477 portp
->stats
.rxtotal
+= len
;
4479 len
= min(len
, buflen
);
4482 outb(GRXFIFO
, (ioaddr
+ XP_ADDR
));
4483 tty_prepare_flip_string(tty
, &ptr
, len
);
4484 insb((ioaddr
+ XP_DATA
), ptr
, len
);
4485 tty_schedule_flip(tty
);
4486 portp
->stats
.rxtotal
+= len
;
4490 stl_sc26198rxbadchars(portp
);
4494 * If we are TX flow controlled and in IXANY mode then we may need
4495 * to unflow control here. We gotta do this because of the automatic
4496 * flow control modes of the sc26198.
4498 if (test_bit(ASYI_TXFLOWED
, &portp
->istate
)) {
4499 if ((tty
!= NULL
) &&
4500 (tty
->termios
!= NULL
) &&
4501 (tty
->termios
->c_iflag
& IXANY
)) {
4502 stl_sc26198txunflow(portp
, tty
);
4508 /*****************************************************************************/
4511 * Process an RX bad character.
4514 static void stl_sc26198rxbadch(struct stlport
*portp
, unsigned char status
, char ch
)
4516 struct tty_struct
*tty
;
4517 unsigned int ioaddr
;
4519 tty
= tty_port_tty_get(&portp
->port
);
4520 ioaddr
= portp
->ioaddr
;
4522 if (status
& SR_RXPARITY
)
4523 portp
->stats
.rxparity
++;
4524 if (status
& SR_RXFRAMING
)
4525 portp
->stats
.rxframing
++;
4526 if (status
& SR_RXOVERRUN
)
4527 portp
->stats
.rxoverrun
++;
4528 if (status
& SR_RXBREAK
)
4529 portp
->stats
.rxbreaks
++;
4531 if ((tty
!= NULL
) &&
4532 ((portp
->rxignoremsk
& status
) == 0)) {
4533 if (portp
->rxmarkmsk
& status
) {
4534 if (status
& SR_RXBREAK
) {
4536 if (portp
->port
.flags
& ASYNC_SAK
) {
4538 BRDENABLE(portp
->brdnr
, portp
->pagenr
);
4540 } else if (status
& SR_RXPARITY
)
4541 status
= TTY_PARITY
;
4542 else if (status
& SR_RXFRAMING
)
4544 else if(status
& SR_RXOVERRUN
)
4545 status
= TTY_OVERRUN
;
4551 tty_insert_flip_char(tty
, ch
, status
);
4552 tty_schedule_flip(tty
);
4555 portp
->stats
.rxtotal
++;
4560 /*****************************************************************************/
4563 * Process all characters in the RX FIFO of the UART. Check all char
4564 * status bytes as well, and process as required. We need to check
4565 * all bytes in the FIFO, in case some more enter the FIFO while we
4566 * are here. To get the exact character error type we need to switch
4567 * into CHAR error mode (that is why we need to make sure we empty
4571 static void stl_sc26198rxbadchars(struct stlport
*portp
)
4573 unsigned char status
, mr1
;
4577 * To get the precise error type for each character we must switch
4578 * back into CHAR error mode.
4580 mr1
= stl_sc26198getreg(portp
, MR1
);
4581 stl_sc26198setreg(portp
, MR1
, (mr1
& ~MR1_ERRBLOCK
));
4583 while ((status
= stl_sc26198getreg(portp
, SR
)) & SR_RXRDY
) {
4584 stl_sc26198setreg(portp
, SCCR
, CR_CLEARRXERR
);
4585 ch
= stl_sc26198getreg(portp
, RXFIFO
);
4586 stl_sc26198rxbadch(portp
, status
, ch
);
4590 * To get correct interrupt class we must switch back into BLOCK
4593 stl_sc26198setreg(portp
, MR1
, mr1
);
4596 /*****************************************************************************/
4599 * Other interrupt handler. This includes modem signals, flow
4600 * control actions, etc. Most stuff is left to off-level interrupt
4604 static void stl_sc26198otherisr(struct stlport
*portp
, unsigned int iack
)
4606 unsigned char cir
, ipr
, xisr
;
4608 pr_debug("stl_sc26198otherisr(portp=%p,iack=%x)\n", portp
, iack
);
4610 cir
= stl_sc26198getglobreg(portp
, CIR
);
4612 switch (cir
& CIR_SUBTYPEMASK
) {
4614 ipr
= stl_sc26198getreg(portp
, IPR
);
4615 if (ipr
& IPR_DCDCHANGE
) {
4616 stl_cd_change(portp
);
4617 portp
->stats
.modem
++;
4620 case CIR_SUBXONXOFF
:
4621 xisr
= stl_sc26198getreg(portp
, XISR
);
4622 if (xisr
& XISR_RXXONGOT
) {
4623 set_bit(ASYI_TXFLOWED
, &portp
->istate
);
4624 portp
->stats
.txxoff
++;
4626 if (xisr
& XISR_RXXOFFGOT
) {
4627 clear_bit(ASYI_TXFLOWED
, &portp
->istate
);
4628 portp
->stats
.txxon
++;
4632 stl_sc26198setreg(portp
, SCCR
, CR_BREAKRESET
);
4633 stl_sc26198rxbadchars(portp
);
4640 static void stl_free_isabrds(void)
4642 struct stlbrd
*brdp
;
4645 for (i
= 0; i
< stl_nrbrds
; i
++) {
4646 if ((brdp
= stl_brds
[i
]) == NULL
|| (brdp
->state
& STL_PROBED
))
4649 free_irq(brdp
->irq
, brdp
);
4651 stl_cleanup_panels(brdp
);
4653 release_region(brdp
->ioaddr1
, brdp
->iosize1
);
4654 if (brdp
->iosize2
> 0)
4655 release_region(brdp
->ioaddr2
, brdp
->iosize2
);
4663 * Loadable module initialization stuff.
4665 static int __init
stallion_module_init(void)
4667 struct stlbrd
*brdp
;
4668 struct stlconf conf
;
4672 printk(KERN_INFO
"%s: version %s\n", stl_drvtitle
, stl_drvversion
);
4674 spin_lock_init(&stallion_lock
);
4675 spin_lock_init(&brd_lock
);
4677 stl_serial
= alloc_tty_driver(STL_MAXBRDS
* STL_MAXPORTS
);
4683 stl_serial
->owner
= THIS_MODULE
;
4684 stl_serial
->driver_name
= stl_drvname
;
4685 stl_serial
->name
= "ttyE";
4686 stl_serial
->major
= STL_SERIALMAJOR
;
4687 stl_serial
->minor_start
= 0;
4688 stl_serial
->type
= TTY_DRIVER_TYPE_SERIAL
;
4689 stl_serial
->subtype
= SERIAL_TYPE_NORMAL
;
4690 stl_serial
->init_termios
= stl_deftermios
;
4691 stl_serial
->flags
= TTY_DRIVER_REAL_RAW
| TTY_DRIVER_DYNAMIC_DEV
;
4692 tty_set_operations(stl_serial
, &stl_ops
);
4694 retval
= tty_register_driver(stl_serial
);
4696 printk("STALLION: failed to register serial driver\n");
4701 * Find any dynamically supported boards. That is via module load
4704 for (i
= stl_nrbrds
; i
< stl_nargs
; i
++) {
4705 memset(&conf
, 0, sizeof(conf
));
4706 if (stl_parsebrd(&conf
, stl_brdsp
[i
]) == 0)
4708 if ((brdp
= stl_allocbrd()) == NULL
)
4711 brdp
->brdtype
= conf
.brdtype
;
4712 brdp
->ioaddr1
= conf
.ioaddr1
;
4713 brdp
->ioaddr2
= conf
.ioaddr2
;
4714 brdp
->irq
= conf
.irq
;
4715 brdp
->irqtype
= conf
.irqtype
;
4716 stl_brds
[brdp
->brdnr
] = brdp
;
4717 if (stl_brdinit(brdp
)) {
4718 stl_brds
[brdp
->brdnr
] = NULL
;
4721 for (j
= 0; j
< brdp
->nrports
; j
++)
4722 tty_register_device(stl_serial
,
4723 brdp
->brdnr
* STL_MAXPORTS
+ j
, NULL
);
4728 /* this has to be _after_ isa finding because of locking */
4729 retval
= pci_register_driver(&stl_pcidriver
);
4730 if (retval
&& stl_nrbrds
== 0) {
4731 printk(KERN_ERR
"STALLION: can't register pci driver\n");
4736 * Set up a character driver for per board stuff. This is mainly used
4737 * to do stats ioctls on the ports.
4739 if (register_chrdev(STL_SIOMEMMAJOR
, "staliomem", &stl_fsiomem
))
4740 printk("STALLION: failed to register serial board device\n");
4742 stallion_class
= class_create(THIS_MODULE
, "staliomem");
4743 if (IS_ERR(stallion_class
))
4744 printk("STALLION: failed to create class\n");
4745 for (i
= 0; i
< 4; i
++)
4746 device_create(stallion_class
, NULL
, MKDEV(STL_SIOMEMMAJOR
, i
),
4747 NULL
, "staliomem%d", i
);
4751 tty_unregister_driver(stl_serial
);
4753 put_tty_driver(stl_serial
);
4758 static void __exit
stallion_module_exit(void)
4760 struct stlbrd
*brdp
;
4763 pr_debug("cleanup_module()\n");
4765 printk(KERN_INFO
"Unloading %s: version %s\n", stl_drvtitle
,
4769 * Free up all allocated resources used by the ports. This includes
4770 * memory and interrupts. As part of this process we will also do
4771 * a hangup on every open port - to try to flush out any processes
4772 * hanging onto ports.
4774 for (i
= 0; i
< stl_nrbrds
; i
++) {
4775 if ((brdp
= stl_brds
[i
]) == NULL
|| (brdp
->state
& STL_PROBED
))
4777 for (j
= 0; j
< brdp
->nrports
; j
++)
4778 tty_unregister_device(stl_serial
,
4779 brdp
->brdnr
* STL_MAXPORTS
+ j
);
4782 for (i
= 0; i
< 4; i
++)
4783 device_destroy(stallion_class
, MKDEV(STL_SIOMEMMAJOR
, i
));
4784 unregister_chrdev(STL_SIOMEMMAJOR
, "staliomem");
4785 class_destroy(stallion_class
);
4787 pci_unregister_driver(&stl_pcidriver
);
4791 tty_unregister_driver(stl_serial
);
4792 put_tty_driver(stl_serial
);
4795 module_init(stallion_module_init
);
4796 module_exit(stallion_module_exit
);
4798 MODULE_AUTHOR("Greg Ungerer");
4799 MODULE_DESCRIPTION("Stallion Multiport Serial Driver");
4800 MODULE_LICENSE("GPL");